3.5 KiB
OpenSpec Change: enterprise-diff
- Change ID: enterprise-diff
- Package:
@suaveplan/diff - Category: universal
- Target path:
universal/primitives/diff - Status: PROPOSED
- Date: 2026-04-19
- Reference spec:
/mnt/s/web/suaveplan/enterprise/diff.md
Summary
Greenfield implementation of @suaveplan/diff for the genesis branch. Ships a zero-dependency RFC 6902 JSON Patch engine with structural diffing, patch application/inversion, a linear history manager (undo/redo with branch handling), a sync manager for optimistic concurrency, and a rich path utility module. The package is a leaf — no @suaveplan/* workspace deps — so it unblocks @suaveplan/undo, @suaveplan/crdt, and event-sourcing packages downstream.
Current-state audit (genesis)
Package does not exist on genesis yet — fresh build.
Dependencies
- Workspace: none (leaf)
- External (via catalog):
zod→catalog:forms(for wire-format schemas);tslib→catalog:build;@opentelemetry/api→catalog:observability - Dev (via catalog):
vitest,@vitest/coverage-istanbul,fast-check,mitata→catalog:testing
Preserved public API surface (from main)
Core
diff(left, right, options?)— structural diff producing an RFC 6902PatchapplyPatch(doc, patch, options?)— returnsPatchResultwith transformed documentrevertPatch(doc, patch)— reverts a previously applied patchinvertPatch(patch),invertOperation(op)
Operations
createAdd,createCopy,createMove,createRemove,createReplace,createTestoperationsConflict(a, b),validateOperation(op),validatePatch(patch)
History / sync
createHistory(options?), classHistory— linear undo/redo with branch truncationcreateSync(options?), classSyncManager— push/pull deltas with conflict resolution
Path utilities
parsePath,formatPath,appendPath,concatPaths,comparePaths,pathEquals,isPrefix,parentPath,lastSegment,escapeSegment,unescapeSegment
Utility functions
deepClone,deepEqual,hashValue,stringify,isObject,isPrimitivegetValueAtPath,setValueAtPath,setValueAtPathMut,insertValueAtPath,insertValueAtPathMut,deleteValueAtPath,deleteValueAtPathMut
Types
AddOperation, CopyOperation, MoveOperation, RemoveOperation, ReplaceOperation, TestOperation, BaseOperation, Operation, OperationType, Patch, PatchOptions, PatchResult, PatchError, DiffOptions, ArrayStrategy, Path, PathSegment, JsonPrimitive, JsonValue, HistoryEntry, HistoryState, HistoryOptions, SyncDelta, SyncState, SyncListener, SyncOptions
New genesis additions
- Structured errors:
DiffErrorbase extendsSuaveplanError; codes viadefineCodesunderDIFF.*(DIFF.INVALID_PATCH,DIFF.TEST_FAILED,DIFF.PATH_INVALID,DIFF.APPLY_FAILED,DIFF.INVERT_FAILED). - Zod schemas for every operation type,
Patch,PatchOptions,DiffOptions,HistoryState,SyncDelta(*.schemas.tssiblings). - OTel counters
diff.apply.total,diff.apply.failed, histogramdiff.apply.duration_ms;diff.diff.duration_msfor diff computation. - Property-based tests (fast-check):
applyPatch(doc, diff(a, b)) === b;revertPatch(applyPatch(doc, p), p) === doc;invertPatch(invertPatch(p)) === p. - mitata benchmarks for
diff,applyPatch,revertPatch,SyncManager.push.
Impact
- Adds one new package:
universal/primitives/diff - Adds one new spec capability:
diff - Unblocks Tier C:
undo,crdt,event-sourcing