import { AbstractPredicateOp } from './AbstractPredicateOp';
import { find, formatJsonPointer } from '@jsonjoy.com/json-pointer';
import { OPCODE } from '../constants';
/**
 * @category JSON Predicate
 */
export class OpDefined extends AbstractPredicateOp {
    op() {
        return 'defined';
    }
    code() {
        return OPCODE.defined;
    }
    test(doc) {
        const { val } = find(doc, this.path);
        const test = val !== undefined;
        return test;
    }
    toJson(parent) {
        const op = {
            op: 'defined',
            path: formatJsonPointer(parent ? this.path.slice(parent.path.length) : this.path),
        };
        return op;
    }
    toCompact(parent, verbose) {
        const opcode = verbose ? 'defined' : OPCODE.defined;
        return [opcode, parent ? this.path.slice(parent.path.length) : this.path];
    }
}
//# sourceMappingURL=OpDefined.js.map