"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpDefined = void 0;
const AbstractPredicateOp_1 = require("./AbstractPredicateOp");
const json_pointer_1 = require("@jsonjoy.com/json-pointer");
const constants_1 = require("../constants");
/**
 * @category JSON Predicate
 */
class OpDefined extends AbstractPredicateOp_1.AbstractPredicateOp {
    op() {
        return 'defined';
    }
    code() {
        return constants_1.OPCODE.defined;
    }
    test(doc) {
        const { val } = (0, json_pointer_1.find)(doc, this.path);
        const test = val !== undefined;
        return test;
    }
    toJson(parent) {
        const op = {
            op: 'defined',
            path: (0, json_pointer_1.formatJsonPointer)(parent ? this.path.slice(parent.path.length) : this.path),
        };
        return op;
    }
    toCompact(parent, verbose) {
        const opcode = verbose ? 'defined' : constants_1.OPCODE.defined;
        return [opcode, parent ? this.path.slice(parent.path.length) : this.path];
    }
}
exports.OpDefined = OpDefined;
//# sourceMappingURL=OpDefined.js.map