UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

38 lines 1.02 kB
import { AbstractOp } from './AbstractOp'; import { OpRemove } from './OpRemove'; import { OpAdd } from './OpAdd'; import { toPath, formatJsonPointer } from '@jsonjoy.com/json-pointer'; import { OPCODE } from '../constants'; /** * @category JSON Patch */ export class OpMove extends AbstractOp { from; constructor(path, from) { super(path); this.from = from; } op() { return 'move'; } code() { return OPCODE.move; } apply(doc) { const remove = new OpRemove(toPath(this.from), undefined).apply(doc); const add = new OpAdd(this.path, remove.old).apply(remove.doc); return add; } toJson(parent) { return { op: 'move', path: formatJsonPointer(this.path), from: formatJsonPointer(this.from), }; } toCompact(parent, verbose) { const opcode = verbose ? 'move' : OPCODE.move; return [opcode, this.path, this.from]; } } //# sourceMappingURL=OpMove.js.map