UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

45 lines 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OpAnd = void 0; const AbstractSecondOrderPredicateOp_1 = require("./AbstractSecondOrderPredicateOp"); const constants_1 = require("../constants"); const json_pointer_1 = require("@jsonjoy.com/json-pointer"); /** * @category JSON Predicate */ class OpAnd extends AbstractSecondOrderPredicateOp_1.AbstractSecondOrderPredicateOp { constructor(path, ops) { super(path, ops); this.ops = ops; } op() { return 'and'; } code() { return constants_1.OPCODE.and; } test(doc) { for (const op of this.ops) if (!op.test(doc)) return false; return true; } toJson(parent) { const op = { op: 'and', path: (0, json_pointer_1.formatJsonPointer)(parent ? this.path.slice(parent.path.length) : this.path), apply: this.ops.map((op) => op.toJson(this)), }; return op; } toCompact(parent, verbose) { const opcode = verbose ? 'and' : constants_1.OPCODE.and; return [ opcode, parent ? this.path.slice(parent.path.length) : this.path, this.ops.map((op) => op.toCompact(this, verbose)), ]; } } exports.OpAnd = OpAnd; //# sourceMappingURL=OpAnd.js.map