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