"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpUndefined = 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 OpUndefined extends AbstractPredicateOp_1.AbstractPredicateOp {
    op() {
        return 'undefined';
    }
    code() {
        return constants_1.OPCODE.undefined;
    }
    test(doc) {
        try {
            const { val } = (0, json_pointer_1.find)(doc, this.path);
            const test = val === undefined;
            return test;
        }
        catch (error) {
            if (error.message === 'NOT_FOUND')
                return true;
            throw error;
        }
    }
    toJson(parent) {
        const op = {
            op: 'undefined',
            path: (0, json_pointer_1.formatJsonPointer)(parent ? this.path.slice(parent.path.length) : this.path),
        };
        return op;
    }
    toCompact(parent, verbose) {
        const opcode = verbose ? 'undefined' : constants_1.OPCODE.undefined;
        return [opcode, parent ? this.path.slice(parent.path.length) : this.path];
    }
}
exports.OpUndefined = OpUndefined;
//# sourceMappingURL=OpUndefined.js.map