mongo-dot-notation
Version:
Transform objects to MongoDB update instructions
44 lines (43 loc) • 1.44 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.$bit = exports.$xor = exports.$or = exports.$and = void 0;
const operator_1 = require("./operator");
/**
* Uses a bitwise _and_ operation to update a field.
* Alias for `$bit().$and()`.
* @see https://www.mongodb.com/docs/manual/reference/operator/update/bit/#bitwise-and
*/
const $and = (value) => (0, operator_1.create)('$bit', { and: value });
exports.$and = $and;
/**
* Uses a bitwise `or` operation to update a field.
* Alias for `$bit().$or()`.
* @see https://www.mongodb.com/docs/manual/reference/operator/update/bit/#bitwise-or
*/
const $or = (value) => (0, operator_1.create)('$bit', { or: value });
exports.$or = $or;
/**
* Uses a bitwise `xor` operation to update a field.
* Alias for `$bit().$xor()`.
* @see https://www.mongodb.com/docs/manual/reference/operator/update/bit/#bitwise-xor
*/
const $xor = (value) => (0, operator_1.create)('$bit', { xor: value });
exports.$xor = $xor;
/**
* Performs a bitwise update of a field.
* Should be chained with a logical operator.
* @see https://docs.mongodb.com/manual/reference/operator/update/#bitwise
*
* @example
* ```ts
* flatten({ permissions: $bit().$and(4) });
* // same as:
* flatten({ permissions: $and(4) })
* ```
*/
const $bit = () => (0, operator_1.create)('', undefined, {
$and: exports.$and,
$or: exports.$or,
$xor: exports.$xor,
});
exports.$bit = $bit;