All files / json-patch-ot/transforms xMove.ts

91.66% Statements 11/12
50% Branches 1/2
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 171x   1x   1x 4x   4x 2x 2x 2x 2x     2x    
import {operationToOp} from '../../json-patch/codec/json';
import type {OpMove, Op} from '../../json-patch/op';
import {isRoot, isChild} from '@jsonjoy.com/json-pointer';
 
export const xMove = (move: OpMove, op: Op): null | Op | Op[] => {
  Iif (isRoot(move.path)) return op;
 
  if (isChild(move.from, op.path)) {
    const pointer = [...move.path, ...op.path.slice(move.path.length)];
    const operation = op.toJson();
    (operation as any).path = pointer;
    return operationToOp(operation, {});
  }
 
  return op;
};