@@ -194,6 +194,138 @@ module.exports = function(AV) {
194194 return new AV . Op . Increment ( json . amount ) ;
195195 } ) ;
196196
197+ /**
198+ * @private
199+ * @class
200+ * BitAnd is an atomic operation where the given value will be bit and to the
201+ * value than is stored in this field.
202+ */
203+ AV . Op . BitAnd = AV . Op . _extend ( /** @lends AV.Op.BitAnd.prototype */ {
204+ _initialize ( value ) {
205+ this . _value = value ;
206+ } ,
207+
208+ value ( ) {
209+ return this . _value ;
210+ } ,
211+
212+ /**
213+ * Returns a JSON version of the operation suitable for sending to AV.
214+ * @return {Object }
215+ */
216+ toJSON ( ) {
217+ return { __op : 'BitAnd' , value : this . value ( ) } ;
218+ } ,
219+
220+ _mergeWithPrevious ( previous ) {
221+ if ( ! previous ) {
222+ return this ;
223+ } else if ( previous instanceof AV . Op . Unset ) {
224+ return new AV . Op . Set ( 0 ) ;
225+ } else if ( previous instanceof AV . Op . Set ) {
226+ return new AV . Op . Set ( previous . value ( ) & this . value ( ) ) ;
227+ } else {
228+ throw new Error ( 'Op is invalid after previous op.' ) ;
229+ }
230+ } ,
231+
232+ _estimate ( oldValue ) {
233+ return oldValue & this . value ( ) ;
234+ } ,
235+ } ) ;
236+
237+ AV . Op . _registerDecoder ( 'BitAnd' , function ( json ) {
238+ return new AV . Op . BitAnd ( json . value ) ;
239+ } ) ;
240+
241+ /**
242+ * @private
243+ * @class
244+ * BitOr is an atomic operation where the given value will be bit and to the
245+ * value than is stored in this field.
246+ */
247+ AV . Op . BitOr = AV . Op . _extend ( /** @lends AV.Op.BitOr.prototype */ {
248+ _initialize ( value ) {
249+ this . _value = value ;
250+ } ,
251+
252+ value ( ) {
253+ return this . _value ;
254+ } ,
255+
256+ /**
257+ * Returns a JSON version of the operation suitable for sending to AV.
258+ * @return {Object }
259+ */
260+ toJSON ( ) {
261+ return { __op : 'BitOr' , value : this . value ( ) } ;
262+ } ,
263+
264+ _mergeWithPrevious ( previous ) {
265+ if ( ! previous ) {
266+ return this ;
267+ } else if ( previous instanceof AV . Op . Unset ) {
268+ return new AV . Op . Set ( this . value ( ) ) ;
269+ } else if ( previous instanceof AV . Op . Set ) {
270+ return new AV . Op . Set ( previous . value ( ) | this . value ( ) ) ;
271+ } else {
272+ throw new Error ( 'Op is invalid after previous op.' ) ;
273+ }
274+ } ,
275+
276+ _estimate ( oldValue ) {
277+ return oldValue | this . value ( ) ;
278+ } ,
279+ } ) ;
280+
281+ AV . Op . _registerDecoder ( 'BitOr' , function ( json ) {
282+ return new AV . Op . BitOr ( json . value ) ;
283+ } ) ;
284+
285+ /**
286+ * @private
287+ * @class
288+ * BitXor is an atomic operation where the given value will be bit and to the
289+ * value than is stored in this field.
290+ */
291+ AV . Op . BitXor = AV . Op . _extend ( /** @lends AV.Op.BitXor.prototype */ {
292+ _initialize ( value ) {
293+ this . _value = value ;
294+ } ,
295+
296+ value ( ) {
297+ return this . _value ;
298+ } ,
299+
300+ /**
301+ * Returns a JSON version of the operation suitable for sending to AV.
302+ * @return {Object }
303+ */
304+ toJSON ( ) {
305+ return { __op : 'BitXor' , value : this . value ( ) } ;
306+ } ,
307+
308+ _mergeWithPrevious ( previous ) {
309+ if ( ! previous ) {
310+ return this ;
311+ } else if ( previous instanceof AV . Op . Unset ) {
312+ return new AV . Op . Set ( this . value ( ) ) ;
313+ } else if ( previous instanceof AV . Op . Set ) {
314+ return new AV . Op . Set ( previous . value ( ) ^ this . value ( ) ) ;
315+ } else {
316+ throw new Error ( 'Op is invalid after previous op.' ) ;
317+ }
318+ } ,
319+
320+ _estimate ( oldValue ) {
321+ return oldValue ^ this . value ( ) ;
322+ } ,
323+ } ) ;
324+
325+ AV . Op . _registerDecoder ( 'BitXor' , function ( json ) {
326+ return new AV . Op . BitXor ( json . value ) ;
327+ } ) ;
328+
197329 /**
198330 * @private
199331 * @class
0 commit comments