@vielzeug/patchwork 0.0.0-stage → 26.11.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +44 -2
- package/dist/_equality.cjs +2 -0
- package/dist/_equality.cjs.map +1 -0
- package/dist/_equality.d.ts +9 -0
- package/dist/_equality.d.ts.map +1 -0
- package/dist/_equality.js +16 -0
- package/dist/_equality.js.map +1 -0
- package/dist/errors.cjs +2 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +20 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +14 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/merge.cjs +2 -0
- package/dist/merge.cjs.map +1 -0
- package/dist/merge.d.ts +37 -0
- package/dist/merge.d.ts.map +1 -0
- package/dist/merge.js +57 -0
- package/dist/merge.js.map +1 -0
- package/dist/patch.cjs +2 -0
- package/dist/patch.cjs.map +1 -0
- package/dist/patch.d.ts +28 -0
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js +241 -0
- package/dist/patch.js.map +1 -0
- package/dist/patchwork.cjs +2 -0
- package/dist/patchwork.cjs.map +1 -0
- package/dist/patchwork.iife.js +2 -0
- package/dist/patchwork.iife.js.map +1 -0
- package/dist/patchwork.js +263 -0
- package/dist/patchwork.js.map +1 -0
- package/dist/types.d.ts +59 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Helmuth Saatkamp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vielzeug/patchwork
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> RFC 6902 JSON Patch: structural diff, immutable apply, and guarded tryApply for sync protocols.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @vielzeug/patchwork
|
|
9
|
+
npm install @vielzeug/patchwork
|
|
10
|
+
yarn add @vielzeug/patchwork
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { apply, diff, tryApply } from '@vielzeug/patchwork';
|
|
17
|
+
|
|
18
|
+
const doc = { items: ['a'], title: 'Cart' };
|
|
19
|
+
const patch = diff(doc, { items: ['a', 'b'], title: 'Wagen' });
|
|
20
|
+
// [{ op: 'add', path: '/items/-', value: 'b' }, { op: 'replace', path: '/title', value: 'Wagen' }]
|
|
21
|
+
|
|
22
|
+
const next = apply(doc, patch); // doc untouched; untouched subtrees keep their identity
|
|
23
|
+
|
|
24
|
+
tryApply(doc, [{ op: 'test', path: '/title', value: 'Other' }]);
|
|
25
|
+
// { ok: false, error: { index: 0, path: '/title', reason: 'test', message: … } }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Zero runtime dependencies. `apply` is copy-on-write, so memoized selectors recompute only
|
|
29
|
+
over the branches a patch actually touched; `tryApply` turns a failed `test` into data you
|
|
30
|
+
can log and reply to, which is what conflict handling in sync protocols needs. The optional
|
|
31
|
+
`@vielzeug/patchwork/merge` subpath adds three-way, field-level reconciliation
|
|
32
|
+
(`merge(base, local, remote)` → `{ doc, conflicts }`) while the core entry point stays
|
|
33
|
+
RFC 6902-only.
|
|
34
|
+
|
|
35
|
+
## Documentation
|
|
36
|
+
|
|
37
|
+
- [Overview](https://vielzeug.dev/patchwork/)
|
|
38
|
+
- [Usage Guide](https://vielzeug.dev/patchwork/usage)
|
|
39
|
+
- [API Reference](https://vielzeug.dev/patchwork/api)
|
|
40
|
+
- [Examples](https://vielzeug.dev/patchwork/examples)
|
|
41
|
+
- [Migration Guide](https://vielzeug.dev/patchwork/migration)
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT © [Helmuth Saatkamp](https://github.com/helmuthdu): part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function isPlainObject(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function deepEqual(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((e,n)=>deepEqual(e,t[n]));if(isPlainObject(e)&&isPlainObject(t)){let n=Object.keys(e),r=Object.keys(t);return n.length===r.length&&n.every(n=>Object.hasOwn(t,n)&&deepEqual(e[n],t[n]))}return!1}exports.deepEqual=deepEqual,exports.isPlainObject=isPlainObject;
|
|
2
|
+
//# sourceMappingURL=_equality.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_equality.cjs","names":["value","a","b","item","index","aKeys","bKeys","key"],"sources":["../src/_equality.ts"],"sourcesContent":["/**\n * Internal JSON-domain helpers shared by the patch engine and the merge module.\n * Never re-exported from the package barrel.\n */\nimport type { JsonObject, JsonValue } from './types';\n\nexport function isPlainObject(value: JsonValue | undefined): value is JsonObject {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** Structural equality over the JSON domain: no NaN/undefined/prototype concerns. */\nexport function deepEqual(a: JsonValue, b: JsonValue): boolean {\n if (a === b) return true;\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((item, index) => deepEqual(item, b[index] as JsonValue));\n }\n if (isPlainObject(a) && isPlainObject(b)) {\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n return (\n aKeys.length === bKeys.length &&\n aKeys.every((key) => Object.hasOwn(b, key) && deepEqual(a[key] as JsonValue, b[key] as JsonValue))\n );\n }\n return false;\n}\n"],"mappings":"AAMA,SAAgB,cAAc,EAAmD,CAC/E,OAAO,OAAOA,GAAU,YAAYA,GAAkB,CAAC,MAAM,QAAQA,CAAK,CAC5E,CAGA,SAAgB,UAAU,EAAc,EAAuB,CAC7D,GAAIC,IAAMC,EAAG,MAAO,GACpB,GAAI,MAAM,QAAQD,CAAC,GAAK,MAAM,QAAQC,CAAC,EACrC,OAAOD,EAAE,SAAWC,EAAE,QAAUD,EAAE,OAAO,EAAM,IAAU,UAAUE,EAAMD,EAAEE,EAAmB,CAAC,EAEjG,GAAI,cAAcH,CAAC,GAAK,cAAcC,CAAC,EAAG,CACxC,IAAMG,EAAQ,OAAO,KAAKJ,CAAC,EACrBK,EAAQ,OAAO,KAAKJ,CAAC,EAC3B,OACEG,EAAM,SAAWC,EAAM,QACvBD,EAAM,MAAO,GAAQ,OAAO,OAAOH,EAAGK,CAAG,GAAK,UAAUN,EAAEM,GAAmBL,EAAEK,EAAiB,CAAC,CAErG,CACA,MAAO,EACT,C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal JSON-domain helpers shared by the patch engine and the merge module.
|
|
3
|
+
* Never re-exported from the package barrel.
|
|
4
|
+
*/
|
|
5
|
+
import type { JsonObject, JsonValue } from './types';
|
|
6
|
+
export declare function isPlainObject(value: JsonValue | undefined): value is JsonObject;
|
|
7
|
+
/** Structural equality over the JSON domain: no NaN/undefined/prototype concerns. */
|
|
8
|
+
export declare function deepEqual(a: JsonValue, b: JsonValue): boolean;
|
|
9
|
+
//# sourceMappingURL=_equality.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_equality.d.ts","sourceRoot":"","sources":["../src/_equality.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAErD,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,KAAK,IAAI,UAAU,CAE/E;AAED,qFAAqF;AACrF,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,OAAO,CAc7D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/_equality.ts
|
|
2
|
+
function isPlainObject(e) {
|
|
3
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
4
|
+
}
|
|
5
|
+
function deepEqual(e, t) {
|
|
6
|
+
if (e === t) return !0;
|
|
7
|
+
if (Array.isArray(e) && Array.isArray(t)) return e.length === t.length && e.every((e, n) => deepEqual(e, t[n]));
|
|
8
|
+
if (isPlainObject(e) && isPlainObject(t)) {
|
|
9
|
+
let n = Object.keys(e), r = Object.keys(t);
|
|
10
|
+
return n.length === r.length && n.every((n) => Object.hasOwn(t, n) && deepEqual(e[n], t[n]));
|
|
11
|
+
}
|
|
12
|
+
return !1;
|
|
13
|
+
}
|
|
14
|
+
export { deepEqual, isPlainObject };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=_equality.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_equality.js","names":["value","a","b","item","index","aKeys","bKeys","key"],"sources":["../src/_equality.ts"],"sourcesContent":["/**\n * Internal JSON-domain helpers shared by the patch engine and the merge module.\n * Never re-exported from the package barrel.\n */\nimport type { JsonObject, JsonValue } from './types';\n\nexport function isPlainObject(value: JsonValue | undefined): value is JsonObject {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** Structural equality over the JSON domain: no NaN/undefined/prototype concerns. */\nexport function deepEqual(a: JsonValue, b: JsonValue): boolean {\n if (a === b) return true;\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((item, index) => deepEqual(item, b[index] as JsonValue));\n }\n if (isPlainObject(a) && isPlainObject(b)) {\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n return (\n aKeys.length === bKeys.length &&\n aKeys.every((key) => Object.hasOwn(b, key) && deepEqual(a[key] as JsonValue, b[key] as JsonValue))\n );\n }\n return false;\n}\n"],"mappings":";AAMA,SAAgB,cAAc,GAAmD;CAC/E,OAAO,OAAOA,KAAU,cAAYA,KAAkB,CAAC,MAAM,QAAQA,CAAK;AAC5E;AAGA,SAAgB,UAAU,GAAc,GAAuB;CAC7D,IAAIC,MAAMC,GAAG,OAAO;CACpB,IAAI,MAAM,QAAQD,CAAC,KAAK,MAAM,QAAQC,CAAC,GACrC,OAAOD,EAAE,WAAWC,EAAE,UAAUD,EAAE,OAAO,GAAM,MAAU,UAAUE,GAAMD,EAAEE,EAAmB,CAAC;CAEjG,IAAI,cAAcH,CAAC,KAAK,cAAcC,CAAC,GAAG;EACxC,IAAMG,IAAQ,OAAO,KAAKJ,CAAC,GACrBK,IAAQ,OAAO,KAAKJ,CAAC;EAC3B,OACEG,EAAM,WAAWC,EAAM,UACvBD,EAAM,OAAO,MAAQ,OAAO,OAAOH,GAAGK,CAAG,KAAK,UAAUN,EAAEM,IAAmBL,EAAEK,EAAiB,CAAC;CAErG;CACA,OAAO;AACT"}
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var PatchError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},PatchPathError=class extends PatchError{pointer;constructor(e,t){super(e,t),this.pointer=t?.pointer}},PatchTestError=class extends PatchError{};exports.PatchError=PatchError,exports.PatchPathError=PatchPathError,exports.PatchTestError=PatchTestError;
|
|
2
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":["message","options"],"sources":["../src/errors.ts"],"sourcesContent":["import type { JsonPointer } from './types';\n\n/** Base class for all patchwork errors. */\nexport class PatchError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * The document could not be patched because a pointer did not resolve. `pointer` names the\n * offending pointer when the library can attribute one (the failing `path` of a `move` is\n * not its `from`).\n */\nexport class PatchPathError extends PatchError {\n readonly pointer: JsonPointer | undefined;\n\n constructor(message: string, options?: ErrorOptions & { pointer?: JsonPointer }) {\n super(message, options);\n this.pointer = options?.pointer;\n }\n}\n\n/** A `test` operation did not match the document. */\nexport class PatchTestError extends PatchError {}\n"],"mappings":"AAGA,IAAa,WAAb,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAwB,CACnD,MAAMA,EAASC,CAAO,EACtB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAOa,eAAb,cAAoC,UAAW,CAC7C,QAEA,YAAY,EAAiB,EAAoD,CAC/E,MAAMD,EAASC,CAAO,EACtB,KAAK,QAAUA,GAAS,OAC1B,CACF,EAGa,eAAb,cAAoC,UAAW,CAAC,E"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { JsonPointer } from './types';
|
|
2
|
+
/** Base class for all patchwork errors. */
|
|
3
|
+
export declare class PatchError extends Error {
|
|
4
|
+
constructor(message: string, options?: ErrorOptions);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The document could not be patched because a pointer did not resolve. `pointer` names the
|
|
8
|
+
* offending pointer when the library can attribute one (the failing `path` of a `move` is
|
|
9
|
+
* not its `from`).
|
|
10
|
+
*/
|
|
11
|
+
export declare class PatchPathError extends PatchError {
|
|
12
|
+
readonly pointer: JsonPointer | undefined;
|
|
13
|
+
constructor(message: string, options?: ErrorOptions & {
|
|
14
|
+
pointer?: JsonPointer;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/** A `test` operation did not match the document. */
|
|
18
|
+
export declare class PatchTestError extends PatchError {
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,2CAA2C;AAC3C,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAKpD;AAED;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAC5C,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC;gBAE9B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG;QAAE,OAAO,CAAC,EAAE,WAAW,CAAA;KAAE;CAIhF;AAED,qDAAqD;AACrD,qBAAa,cAAe,SAAQ,UAAU;CAAG"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var PatchError = class extends Error {
|
|
3
|
+
constructor(e, t) {
|
|
4
|
+
super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
|
|
5
|
+
}
|
|
6
|
+
}, PatchPathError = class extends PatchError {
|
|
7
|
+
pointer;
|
|
8
|
+
constructor(e, t) {
|
|
9
|
+
super(e, t), this.pointer = t?.pointer;
|
|
10
|
+
}
|
|
11
|
+
}, PatchTestError = class extends PatchError {};
|
|
12
|
+
export { PatchError, PatchPathError, PatchTestError };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","names":["message","options"],"sources":["../src/errors.ts"],"sourcesContent":["import type { JsonPointer } from './types';\n\n/** Base class for all patchwork errors. */\nexport class PatchError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * The document could not be patched because a pointer did not resolve. `pointer` names the\n * offending pointer when the library can attribute one (the failing `path` of a `move` is\n * not its `from`).\n */\nexport class PatchPathError extends PatchError {\n readonly pointer: JsonPointer | undefined;\n\n constructor(message: string, options?: ErrorOptions & { pointer?: JsonPointer }) {\n super(message, options);\n this.pointer = options?.pointer;\n }\n}\n\n/** A `test` operation did not match the document. */\nexport class PatchTestError extends PatchError {}\n"],"mappings":";AAGA,IAAa,aAAb,cAAgC,MAAM;CACpC,YAAY,GAAiB,GAAwB;EAGnD,AAFA,MAAMA,GAASC,CAAO,GACtB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAOa,iBAAb,cAAoC,WAAW;CAC7C;CAEA,YAAY,GAAiB,GAAoD;EAE/E,AADA,MAAMD,GAASC,CAAO,GACtB,KAAK,UAAUA,GAAS;CAC1B;AACF,GAGa,iBAAb,cAAoC,WAAW,CAAC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./patch.cjs");exports.PatchError=e.PatchError,exports.PatchPathError=e.PatchPathError,exports.PatchTestError=e.PatchTestError,exports.apply=t.apply,exports.diff=t.diff,exports.formatPointer=t.formatPointer,exports.getIn=t.getIn,exports.parsePointer=t.parsePointer,exports.tryApply=t.tryApply;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { PatchError, PatchPathError, PatchTestError } from './errors';
|
|
2
|
+
export { apply, diff, formatPointer, getIn, parsePointer, tryApply } from './patch';
|
|
3
|
+
export type { AddOperation, ApplyResult, CopyOperation, JsonObject, JsonPatch, JsonPointer, JsonValue, MoveOperation, PatchErrorInfo, PatchOperation, RemoveOperation, ReplaceOperation, TestOperation, } from './types';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACpF,YAAY,EACV,YAAY,EACZ,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,aAAa,GACd,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { PatchError as e, PatchPathError as t, PatchTestError as n } from "./errors.js";
|
|
2
|
+
import { apply as r, diff as i, formatPointer as a, getIn as o, parsePointer as s, tryApply as c } from "./patch.js";
|
|
3
|
+
export { e as PatchError, t as PatchPathError, n as PatchTestError, r as apply, i as diff, a as formatPointer, o as getIn, s as parsePointer, c as tryApply };
|
package/dist/merge.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./_equality.cjs"),t=require("./patch.cjs");function merge(n,r,i,a={}){let o=[],s=a.resolution===`local`,report=(e,t,n,r)=>{o.push({base:t,local:n,path:e,remote:r})},conflict=(e,t,n,r)=>(report(e,t,n,r),s?n:r),mergeNode=(n,r,i,a)=>{if(e.deepEqual(i,a))return i;if(e.deepEqual(r,i))return a;if(e.deepEqual(r,a))return i;if(e.isPlainObject(r)&&e.isPlainObject(i)&&e.isPlainObject(a)){let o={},c=new Set([...Object.keys(r),...Object.keys(i),...Object.keys(a)]);for(let l of c){let c=`${n}${t.formatPointer([l])}`,u=Object.hasOwn(r,l),d=Object.hasOwn(i,l),f=Object.hasOwn(a,l);if(d&&f&&u)o[l]=mergeNode(c,r[l],i[l],a[l]);else if(d&&f){let t=i[l],n=a[l];o[l]=e.deepEqual(t,n)?t:conflict(c,void 0,t,n)}else if(d&&u){if(e.deepEqual(i[l],r[l]))continue;report(c,r[l],i[l],a[l]),s&&(o[l]=i[l])}else if(f&&u){if(e.deepEqual(a[l],r[l]))continue;report(c,r[l],i[l],a[l]),s||(o[l]=a[l])}else d?o[l]=i[l]:f&&(o[l]=a[l])}return o}if(Array.isArray(r)&&Array.isArray(i)&&Array.isArray(a)){let e=mergeArrays(r,i,a);return e===null?conflict(n,r,i,a):e}return conflict(n,r,i,a)};return{conflicts:o,doc:mergeNode(``,n,r,i)}}function mergeArrays(e,t,n){return isPrefixOf(e,t)&&isPrefixOf(e,n)?[...t,...n.slice(e.length)]:isPrefixOf(t,e)&&isPrefixOf(n,e)?[...t.length<=n.length?t:n]:null}function isPrefixOf(t,n){return t.length<=n.length&&t.every((t,r)=>e.deepEqual(t,n[r]))}exports.merge=merge;
|
|
2
|
+
//# sourceMappingURL=merge.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.cjs","names":["deepEqual","isPlainObject","formatPointer","require__equality","require_patch","conflicts","localWins","options","fromBase","left","right","path","out","keys","key","childPath","inBase","inLeft","inRight","addedLeft","addedRight","merged","base","local","remote","prefix","other","item","index"],"sources":["../src/merge.ts"],"sourcesContent":["/**\n * Three-way JSON merge for `@vielzeug/patchwork/merge`: two diverged copies of a shared\n * base document reconcile field-by-field instead of overwriting each other wholesale.\n * This module is policy, not RFC 6902 spec — the conflict rules below are deliberate\n * choices and the core `./patchwork` entry point stays spec-only.\n */\nimport { deepEqual, isPlainObject } from './_equality';\nimport { formatPointer } from './patch';\nimport type { JsonValue } from './types';\n\n/** One location where local and remote changed the base incompatibly. */\nexport type MergeConflict = {\n /** The common ancestor's value; `undefined` when the key is new in both copies. */\n readonly base: JsonValue | undefined;\n /** The local side's value; `undefined` when local deleted the key (delete/modify conflict). */\n readonly local: JsonValue | undefined;\n readonly path: string;\n /** The remote side's value; `undefined` when remote deleted the key. */\n readonly remote: JsonValue | undefined;\n};\n\nexport type MergeOptions = {\n /**\n * Who wins a conflict. `'remote'` (default) treats the server copy as authoritative;\n * `'local'` keeps the editing copy. Either way the conflict is still reported.\n */\n readonly resolution?: 'local' | 'remote';\n};\n\nexport type MergeResult = {\n /** Conflicts in document order; empty when the merge was clean. */\n readonly conflicts: readonly MergeConflict[];\n /** The merged document: both sides applied where they do not collide. */\n readonly doc: JsonValue;\n};\n\n/**\n * Merge `local` and `remote`, both derived from `base`, without either side losing\n * unrelated edits. Objects merge key-by-key to any depth; a value only conflicts when\n * *both* sides changed it from the base to different values.\n *\n * Arrays follow the document-level policy: a side that kept the base array untouched\n * defers to the other; when both sides only appended, the additions concatenate\n * (local first); when both only truncated the tail, the shorter result wins (union of\n * removals). Any other array divergence — an insert, a mid-list edit, append vs\n * truncate — conflicts as a whole array rather than guessing a positional splice.\n */\nexport function merge(base: JsonValue, local: JsonValue, remote: JsonValue, options: MergeOptions = {}): MergeResult {\n const conflicts: MergeConflict[] = [];\n const localWins = options.resolution === 'local';\n const report = (path: string, fromBase: JsonValue | undefined, left: JsonValue, right: JsonValue): void => {\n conflicts.push({ base: fromBase, local: left, path, remote: right });\n };\n const conflict = (path: string, fromBase: JsonValue | undefined, left: JsonValue, right: JsonValue): JsonValue => {\n report(path, fromBase, left, right);\n return localWins ? left : right;\n };\n\n const mergeNode = (path: string, fromBase: JsonValue, left: JsonValue, right: JsonValue): JsonValue => {\n if (deepEqual(left, right)) return left;\n if (deepEqual(fromBase, left)) return right;\n if (deepEqual(fromBase, right)) return left;\n\n if (isPlainObject(fromBase) && isPlainObject(left) && isPlainObject(right)) {\n const out: Record<string, JsonValue> = {};\n const keys = new Set([...Object.keys(fromBase), ...Object.keys(left), ...Object.keys(right)]);\n for (const key of keys) {\n const childPath = `${path}${formatPointer([key])}`;\n const inBase = Object.hasOwn(fromBase, key);\n const inLeft = Object.hasOwn(left, key);\n const inRight = Object.hasOwn(right, key);\n if (inLeft && inRight && inBase) {\n out[key] = mergeNode(childPath, fromBase[key] as JsonValue, left[key] as JsonValue, right[key] as JsonValue);\n } else if (inLeft && inRight) {\n // Both sides added the same key: equal additions merge, different ones conflict\n // (there is no ancestor to fall back on).\n const addedLeft = left[key] as JsonValue;\n const addedRight = right[key] as JsonValue;\n out[key] = deepEqual(addedLeft, addedRight)\n ? addedLeft\n : conflict(childPath, undefined, addedLeft, addedRight);\n } else if (inLeft && inBase) {\n // remote deleted: an untouched local copy defers to the delete; a real edit conflicts.\n if (deepEqual(left[key] as JsonValue, fromBase[key] as JsonValue)) continue;\n report(childPath, fromBase[key] as JsonValue, left[key] as JsonValue, right[key] as JsonValue);\n if (localWins) out[key] = left[key] as JsonValue; // else the delete stands\n } else if (inRight && inBase) {\n if (deepEqual(right[key] as JsonValue, fromBase[key] as JsonValue)) continue;\n report(childPath, fromBase[key] as JsonValue, left[key] as JsonValue, right[key] as JsonValue);\n if (!localWins) out[key] = right[key] as JsonValue; // else the delete stands\n } else if (inLeft) {\n out[key] = left[key] as JsonValue; // added by local only\n } else if (inRight) {\n out[key] = right[key] as JsonValue; // added by remote only\n }\n // in neither: absent everywhere, nothing to carry.\n }\n return out;\n }\n\n if (Array.isArray(fromBase) && Array.isArray(left) && Array.isArray(right)) {\n const merged = mergeArrays(fromBase, left, right);\n if (merged !== null) return merged;\n return conflict(path, fromBase, left, right);\n }\n\n return conflict(path, fromBase, left, right);\n };\n\n return { conflicts, doc: mergeNode('', base, local, remote) };\n}\n\n/** The array policy: concat pure appends, keep the shorter of pure truncations, else null. */\nfunction mergeArrays(\n base: readonly JsonValue[],\n local: readonly JsonValue[],\n remote: readonly JsonValue[],\n): JsonValue[] | null {\n if (isPrefixOf(base, local) && isPrefixOf(base, remote)) {\n return [...local, ...remote.slice(base.length)];\n }\n if (isPrefixOf(local, base) && isPrefixOf(remote, base)) {\n return [...(local.length <= remote.length ? local : remote)];\n }\n return null;\n}\n\nfunction isPrefixOf(prefix: readonly JsonValue[], other: readonly JsonValue[]): boolean {\n return prefix.length <= other.length && prefix.every((item, index) => deepEqual(item, other[index] as JsonValue));\n}\n"],"mappings":"A,+HA+CA,SAAgB,MAAM,EAAiB,EAAkB,EAAmB,EAAwB,CAAC,EAAgB,CACnH,IAAMK,EAA6B,CAAC,EAC9BC,EAAYC,EAAQ,aAAe,QACnC,QAAU,EAAc,EAAiC,EAAiB,IAA2B,CACzGF,EAAU,KAAK,CAAE,KAAMG,EAAU,MAAOC,EAAM,OAAM,OAAQC,CAAM,CAAC,CACrE,EACM,UAAY,EAAc,EAAiC,EAAiB,KAChF,OAAOC,EAAMH,EAAUC,EAAMC,CAAK,EAC3BJ,EAAYG,EAAOC,GAGtB,WAAa,EAAc,EAAqB,EAAiB,IAAgC,CACrG,GAAIV,EAAAA,UAAUS,EAAMC,CAAK,EAAG,OAAOD,EACnC,GAAIT,EAAAA,UAAUQ,EAAUC,CAAI,EAAG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,MAAWG,EACT,EAAIH,GAAOL,EAAKK,GACPI,IACT,EAAIJ,GAAOJ,EAAMI,GAGrB,CACA,OAAOF,CACT,CAEA,GAAI,MAAM,QAAQJ,CAAQ,GAAK,MAAM,QAAQC,CAAI,GAAK,MAAM,QAAQC,CAAK,EAAG,CAC1E,IAAMW,EAAS,YAAYb,EAAUC,EAAMC,CAAK,EAEhD,OADIW,IAAW,KACR,SAASV,EAAMH,EAAUC,EAAMC,CAAK,EADfW,CAE9B,CAEA,OAAO,SAASV,EAAMH,EAAUC,EAAMC,CAAK,CAC7C,EAEA,MAAO,CAAE,YAAW,IAAK,UAAU,GAAIY,EAAMC,EAAOC,CAAM,CAAE,CAC9D,CAGA,SAAS,YACP,EACA,EACA,EACoB,CAOpB,OANI,WAAWF,EAAMC,CAAK,GAAK,WAAWD,EAAME,CAAM,EAC7C,CAAC,GAAGD,EAAO,GAAGC,EAAO,MAAMF,EAAK,MAAM,CAAC,EAE5C,WAAWC,EAAOD,CAAI,GAAK,WAAWE,EAAQF,CAAI,EAC7C,CAAC,GAAIC,EAAM,QAAUC,EAAO,OAASD,EAAQC,CAAO,EAEtD,IACT,CAEA,SAAS,WAAW,EAA8B,EAAsC,CACtF,OAAOC,EAAO,QAAUC,EAAM,QAAUD,EAAO,OAAO,EAAM,IAAUzB,EAAAA,UAAU2B,EAAMD,EAAME,EAAmB,CAAC,CAClH,C"}
|
package/dist/merge.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { JsonValue } from './types';
|
|
2
|
+
/** One location where local and remote changed the base incompatibly. */
|
|
3
|
+
export type MergeConflict = {
|
|
4
|
+
/** The common ancestor's value; `undefined` when the key is new in both copies. */
|
|
5
|
+
readonly base: JsonValue | undefined;
|
|
6
|
+
/** The local side's value; `undefined` when local deleted the key (delete/modify conflict). */
|
|
7
|
+
readonly local: JsonValue | undefined;
|
|
8
|
+
readonly path: string;
|
|
9
|
+
/** The remote side's value; `undefined` when remote deleted the key. */
|
|
10
|
+
readonly remote: JsonValue | undefined;
|
|
11
|
+
};
|
|
12
|
+
export type MergeOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* Who wins a conflict. `'remote'` (default) treats the server copy as authoritative;
|
|
15
|
+
* `'local'` keeps the editing copy. Either way the conflict is still reported.
|
|
16
|
+
*/
|
|
17
|
+
readonly resolution?: 'local' | 'remote';
|
|
18
|
+
};
|
|
19
|
+
export type MergeResult = {
|
|
20
|
+
/** Conflicts in document order; empty when the merge was clean. */
|
|
21
|
+
readonly conflicts: readonly MergeConflict[];
|
|
22
|
+
/** The merged document: both sides applied where they do not collide. */
|
|
23
|
+
readonly doc: JsonValue;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Merge `local` and `remote`, both derived from `base`, without either side losing
|
|
27
|
+
* unrelated edits. Objects merge key-by-key to any depth; a value only conflicts when
|
|
28
|
+
* *both* sides changed it from the base to different values.
|
|
29
|
+
*
|
|
30
|
+
* Arrays follow the document-level policy: a side that kept the base array untouched
|
|
31
|
+
* defers to the other; when both sides only appended, the additions concatenate
|
|
32
|
+
* (local first); when both only truncated the tail, the shorter result wins (union of
|
|
33
|
+
* removals). Any other array divergence — an insert, a mid-list edit, append vs
|
|
34
|
+
* truncate — conflicts as a whole array rather than guessing a positional splice.
|
|
35
|
+
*/
|
|
36
|
+
export declare function merge(base: JsonValue, local: JsonValue, remote: JsonValue, options?: MergeOptions): MergeResult;
|
|
37
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../src/merge.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,yEAAyE;AACzE,MAAM,MAAM,aAAa,GAAG;IAC1B,mFAAmF;IACnF,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IACrC,+FAA+F;IAC/F,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,SAAS,aAAa,EAAE,CAAC;IAC7C,yEAAyE;IACzE,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAE,YAAiB,GAAG,WAAW,CA+DnH"}
|
package/dist/merge.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { deepEqual as e, isPlainObject as t } from "./_equality.js";
|
|
2
|
+
import { formatPointer as n } from "./patch.js";
|
|
3
|
+
// src/merge.ts
|
|
4
|
+
function merge(r, i, a, o = {}) {
|
|
5
|
+
let s = [], c = o.resolution === "local", report = (e, t, n, r) => {
|
|
6
|
+
s.push({
|
|
7
|
+
base: t,
|
|
8
|
+
local: n,
|
|
9
|
+
path: e,
|
|
10
|
+
remote: r
|
|
11
|
+
});
|
|
12
|
+
}, conflict = (e, t, n, r) => (report(e, t, n, r), c ? n : r), mergeNode = (r, i, a, o) => {
|
|
13
|
+
if (e(a, o)) return a;
|
|
14
|
+
if (e(i, a)) return o;
|
|
15
|
+
if (e(i, o)) return a;
|
|
16
|
+
if (t(i) && t(a) && t(o)) {
|
|
17
|
+
let t = {}, s = /* @__PURE__ */ new Set([
|
|
18
|
+
...Object.keys(i),
|
|
19
|
+
...Object.keys(a),
|
|
20
|
+
...Object.keys(o)
|
|
21
|
+
]);
|
|
22
|
+
for (let l of s) {
|
|
23
|
+
let s = `${r}${n([l])}`, u = Object.hasOwn(i, l), d = Object.hasOwn(a, l), f = Object.hasOwn(o, l);
|
|
24
|
+
if (d && f && u) t[l] = mergeNode(s, i[l], a[l], o[l]);
|
|
25
|
+
else if (d && f) {
|
|
26
|
+
let n = a[l], r = o[l];
|
|
27
|
+
t[l] = e(n, r) ? n : conflict(s, void 0, n, r);
|
|
28
|
+
} else if (d && u) {
|
|
29
|
+
if (e(a[l], i[l])) continue;
|
|
30
|
+
report(s, i[l], a[l], o[l]), c && (t[l] = a[l]);
|
|
31
|
+
} else if (f && u) {
|
|
32
|
+
if (e(o[l], i[l])) continue;
|
|
33
|
+
report(s, i[l], a[l], o[l]), c || (t[l] = o[l]);
|
|
34
|
+
} else d ? t[l] = a[l] : f && (t[l] = o[l]);
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(i) && Array.isArray(a) && Array.isArray(o)) {
|
|
39
|
+
let e = mergeArrays(i, a, o);
|
|
40
|
+
return e === null ? conflict(r, i, a, o) : e;
|
|
41
|
+
}
|
|
42
|
+
return conflict(r, i, a, o);
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
conflicts: s,
|
|
46
|
+
doc: mergeNode("", r, i, a)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function mergeArrays(e, t, n) {
|
|
50
|
+
return isPrefixOf(e, t) && isPrefixOf(e, n) ? [...t, ...n.slice(e.length)] : isPrefixOf(t, e) && isPrefixOf(n, e) ? [...t.length <= n.length ? t : n] : null;
|
|
51
|
+
}
|
|
52
|
+
function isPrefixOf(t, n) {
|
|
53
|
+
return t.length <= n.length && t.every((t, r) => e(t, n[r]));
|
|
54
|
+
}
|
|
55
|
+
export { merge };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","names":["conflicts","localWins","options","fromBase","left","right","path","deepEqual","isPlainObject","out","keys","key","childPath","formatPointer","inBase","inLeft","inRight","addedLeft","addedRight","merged","base","local","remote","prefix","other","item","index"],"sources":["../src/merge.ts"],"sourcesContent":["/**\n * Three-way JSON merge for `@vielzeug/patchwork/merge`: two diverged copies of a shared\n * base document reconcile field-by-field instead of overwriting each other wholesale.\n * This module is policy, not RFC 6902 spec — the conflict rules below are deliberate\n * choices and the core `./patchwork` entry point stays spec-only.\n */\nimport { deepEqual, isPlainObject } from './_equality';\nimport { formatPointer } from './patch';\nimport type { JsonValue } from './types';\n\n/** One location where local and remote changed the base incompatibly. */\nexport type MergeConflict = {\n /** The common ancestor's value; `undefined` when the key is new in both copies. */\n readonly base: JsonValue | undefined;\n /** The local side's value; `undefined` when local deleted the key (delete/modify conflict). */\n readonly local: JsonValue | undefined;\n readonly path: string;\n /** The remote side's value; `undefined` when remote deleted the key. */\n readonly remote: JsonValue | undefined;\n};\n\nexport type MergeOptions = {\n /**\n * Who wins a conflict. `'remote'` (default) treats the server copy as authoritative;\n * `'local'` keeps the editing copy. Either way the conflict is still reported.\n */\n readonly resolution?: 'local' | 'remote';\n};\n\nexport type MergeResult = {\n /** Conflicts in document order; empty when the merge was clean. */\n readonly conflicts: readonly MergeConflict[];\n /** The merged document: both sides applied where they do not collide. */\n readonly doc: JsonValue;\n};\n\n/**\n * Merge `local` and `remote`, both derived from `base`, without either side losing\n * unrelated edits. Objects merge key-by-key to any depth; a value only conflicts when\n * *both* sides changed it from the base to different values.\n *\n * Arrays follow the document-level policy: a side that kept the base array untouched\n * defers to the other; when both sides only appended, the additions concatenate\n * (local first); when both only truncated the tail, the shorter result wins (union of\n * removals). Any other array divergence — an insert, a mid-list edit, append vs\n * truncate — conflicts as a whole array rather than guessing a positional splice.\n */\nexport function merge(base: JsonValue, local: JsonValue, remote: JsonValue, options: MergeOptions = {}): MergeResult {\n const conflicts: MergeConflict[] = [];\n const localWins = options.resolution === 'local';\n const report = (path: string, fromBase: JsonValue | undefined, left: JsonValue, right: JsonValue): void => {\n conflicts.push({ base: fromBase, local: left, path, remote: right });\n };\n const conflict = (path: string, fromBase: JsonValue | undefined, left: JsonValue, right: JsonValue): JsonValue => {\n report(path, fromBase, left, right);\n return localWins ? left : right;\n };\n\n const mergeNode = (path: string, fromBase: JsonValue, left: JsonValue, right: JsonValue): JsonValue => {\n if (deepEqual(left, right)) return left;\n if (deepEqual(fromBase, left)) return right;\n if (deepEqual(fromBase, right)) return left;\n\n if (isPlainObject(fromBase) && isPlainObject(left) && isPlainObject(right)) {\n const out: Record<string, JsonValue> = {};\n const keys = new Set([...Object.keys(fromBase), ...Object.keys(left), ...Object.keys(right)]);\n for (const key of keys) {\n const childPath = `${path}${formatPointer([key])}`;\n const inBase = Object.hasOwn(fromBase, key);\n const inLeft = Object.hasOwn(left, key);\n const inRight = Object.hasOwn(right, key);\n if (inLeft && inRight && inBase) {\n out[key] = mergeNode(childPath, fromBase[key] as JsonValue, left[key] as JsonValue, right[key] as JsonValue);\n } else if (inLeft && inRight) {\n // Both sides added the same key: equal additions merge, different ones conflict\n // (there is no ancestor to fall back on).\n const addedLeft = left[key] as JsonValue;\n const addedRight = right[key] as JsonValue;\n out[key] = deepEqual(addedLeft, addedRight)\n ? addedLeft\n : conflict(childPath, undefined, addedLeft, addedRight);\n } else if (inLeft && inBase) {\n // remote deleted: an untouched local copy defers to the delete; a real edit conflicts.\n if (deepEqual(left[key] as JsonValue, fromBase[key] as JsonValue)) continue;\n report(childPath, fromBase[key] as JsonValue, left[key] as JsonValue, right[key] as JsonValue);\n if (localWins) out[key] = left[key] as JsonValue; // else the delete stands\n } else if (inRight && inBase) {\n if (deepEqual(right[key] as JsonValue, fromBase[key] as JsonValue)) continue;\n report(childPath, fromBase[key] as JsonValue, left[key] as JsonValue, right[key] as JsonValue);\n if (!localWins) out[key] = right[key] as JsonValue; // else the delete stands\n } else if (inLeft) {\n out[key] = left[key] as JsonValue; // added by local only\n } else if (inRight) {\n out[key] = right[key] as JsonValue; // added by remote only\n }\n // in neither: absent everywhere, nothing to carry.\n }\n return out;\n }\n\n if (Array.isArray(fromBase) && Array.isArray(left) && Array.isArray(right)) {\n const merged = mergeArrays(fromBase, left, right);\n if (merged !== null) return merged;\n return conflict(path, fromBase, left, right);\n }\n\n return conflict(path, fromBase, left, right);\n };\n\n return { conflicts, doc: mergeNode('', base, local, remote) };\n}\n\n/** The array policy: concat pure appends, keep the shorter of pure truncations, else null. */\nfunction mergeArrays(\n base: readonly JsonValue[],\n local: readonly JsonValue[],\n remote: readonly JsonValue[],\n): JsonValue[] | null {\n if (isPrefixOf(base, local) && isPrefixOf(base, remote)) {\n return [...local, ...remote.slice(base.length)];\n }\n if (isPrefixOf(local, base) && isPrefixOf(remote, base)) {\n return [...(local.length <= remote.length ? local : remote)];\n }\n return null;\n}\n\nfunction isPrefixOf(prefix: readonly JsonValue[], other: readonly JsonValue[]): boolean {\n return prefix.length <= other.length && prefix.every((item, index) => deepEqual(item, other[index] as JsonValue));\n}\n"],"mappings":";;;AA+CA,SAAgB,MAAM,GAAiB,GAAkB,GAAmB,IAAwB,CAAC,GAAgB;CACnH,IAAMA,IAA6B,CAAC,GAC9BC,IAAYC,EAAQ,eAAe,SACnC,UAAU,GAAc,GAAiC,GAAiB,MAA2B;EACzG,EAAU,KAAK;GAAE,MAAMC;GAAU,OAAOC;GAAM;GAAM,QAAQC;EAAM,CAAC;CACrE,GACM,YAAY,GAAc,GAAiC,GAAiB,OAChF,OAAOC,GAAMH,GAAUC,GAAMC,CAAK,GAC3BJ,IAAYG,IAAOC,IAGtB,aAAa,GAAc,GAAqB,GAAiB,MAAgC;EACrG,IAAIE,EAAUH,GAAMC,CAAK,GAAG,OAAOD;EACnC,IAAIG,EAAUJ,GAAUC,CAAI,GAAG,OAAOC;EACtC,IAAIE,EAAUJ,GAAUE,CAAK,GAAG,OAAOD;EAEvC,IAAII,EAAcL,CAAQ,KAAKK,EA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,CAAI,KAAK,MAAM,QAAQC,CAAK,GAAG;GAC1E,IAAMc,IAAS,YAAYhB,GAAUC,GAAMC,CAAK;GAEhD,OADIc,MAAW,OACR,SAASb,GAAMH,GAAUC,GAAMC,CAAK,IADfc;EAE9B;EAEA,OAAO,SAASb,GAAMH,GAAUC,GAAMC,CAAK;CAC7C;CAEA,OAAO;EAAE;EAAW,KAAK,UAAU,IAAIe,GAAMC,GAAOC,CAAM;CAAE;AAC9D;AAGA,SAAS,YACP,GACA,GACA,GACoB;CAOpB,OANI,WAAWF,GAAMC,CAAK,KAAK,WAAWD,GAAME,CAAM,IAC7C,CAAC,GAAGD,GAAO,GAAGC,EAAO,MAAMF,EAAK,MAAM,CAAC,IAE5C,WAAWC,GAAOD,CAAI,KAAK,WAAWE,GAAQF,CAAI,IAC7C,CAAC,GAAIC,EAAM,UAAUC,EAAO,SAASD,IAAQC,CAAO,IAEtD;AACT;AAEA,SAAS,WAAW,GAA8B,GAAsC;CACtF,OAAOC,EAAO,UAAUC,EAAM,UAAUD,EAAO,OAAO,GAAM,MAAUhB,EAAUkB,GAAMD,EAAME,EAAmB,CAAC;AAClH"}
|
package/dist/patch.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./_equality.cjs"),t=require("./errors.cjs");function parsePointer(e){if(e===``)return[];if(!e.startsWith(`/`))throw new t.PatchPathError(`pointer "${e}" must start with "/"`);return e.slice(1).split(`/`).map(e=>e.replaceAll(`~1`,`/`).replaceAll(`~0`,`~`))}function formatPointer(e){return e.map(e=>`/${e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}`).join(``)}function isArrayIndex(e){if(/^(0|[1-9]\d*)$/.test(e)){let t=Number(e);return t<=2**53-1?t:-1}return-1}function resolve(t,n){let r=t;for(let t of n){if(Array.isArray(r)){let e=isArrayIndex(t);r=e>=0&&e<r.length?r[e]:void 0}else if(e.isPlainObject(r))r=Object.hasOwn(r,t)?r[t]:void 0;else return{exists:!1};if(r===void 0)return{exists:!1}}return{exists:!0,value:r}}function getIn(e,t){return resolve(e,parsePointer(t)).value}function descendArray(e,n,r){let i=isArrayIndex(n);if(i<0||i>=e.length)throw new t.PatchPathError(`cannot ${r} at "/${n}": index out of bounds`);return i}function addIn(n,r,i){let[a=``,...o]=r;if(r.length===0)return i;if(Array.isArray(n)){if(a===`-`){if(o.length>0)throw new t.PatchPathError(`cannot add "/-": "-" must be the final token`);return[...n,i]}let e=isArrayIndex(a);if(e<0||e>n.length)throw new t.PatchPathError(`cannot add "/${a}": index out of bounds`);if(o.length>0){if(e===n.length)throw new t.PatchPathError(`cannot add "/${a}": index out of bounds`);return[...n.slice(0,e),addIn(n[e],o,i),...n.slice(e+1)]}return[...n.slice(0,e),i,...n.slice(e)]}if(e.isPlainObject(n)){if(o.length>0){if(!Object.hasOwn(n,a))throw new t.PatchPathError(`cannot add "/${a}": member does not exist`);return{...n,[a]:addIn(n[a],o,i)}}return Object.hasOwn(n,a)&&e.deepEqual(n[a],i)?n:{...n,[a]:i}}throw new t.PatchPathError(`cannot descend into a ${typeof n}`)}function replaceIn(n,r,i){let[a=``,...o]=r;if(r.length===0)return i;if(Array.isArray(n)){let t=descendArray(n,a,`replace`);return o.length===0?e.deepEqual(n[t],i)?n:[...n.slice(0,t),i,...n.slice(t+1)]:[...n.slice(0,t),replaceIn(n[t],o,i),...n.slice(t+1)]}if(e.isPlainObject(n)){if(!Object.hasOwn(n,a))throw new t.PatchPathError(`cannot replace "/${a}": member does not exist`);return o.length===0?e.deepEqual(n[a],i)?n:{...n,[a]:i}:{...n,[a]:replaceIn(n[a],o,i)}}throw new t.PatchPathError(`cannot descend into a ${typeof n}`)}function removeIn(n,r){let[i=``,...a]=r;if(r.length===0)return null;if(Array.isArray(n)){let e=descendArray(n,i,`remove`);return a.length===0?[...n.slice(0,e),...n.slice(e+1)]:[...n.slice(0,e),removeIn(n[e],a),...n.slice(e+1)]}if(e.isPlainObject(n)){if(!Object.hasOwn(n,i))throw new t.PatchPathError(`cannot remove "/${i}": member does not exist`);if(a.length===0){let e={...n};return delete e[i],e}return{...n,[i]:removeIn(n[i],a)}}throw new t.PatchPathError(`cannot descend into a ${typeof n}`)}function requireValue(e,n,r){let i=resolve(e,n);if(!i.exists)throw new t.PatchPathError(`pointer "${r}" does not resolve`,{pointer:r});return i.value}function at(e,n){try{return n()}catch(n){throw n instanceof t.PatchPathError&&n.pointer===void 0?new t.PatchPathError(n.message,{cause:n,pointer:e}):n}}function applyOperation(n,r){switch(r.op){case`add`:return at(r.path,()=>addIn(n,parsePointer(r.path),structuredClone(r.value)));case`remove`:return at(r.path,()=>removeIn(n,parsePointer(r.path)));case`replace`:return at(r.path,()=>replaceIn(n,parsePointer(r.path),structuredClone(r.value)));case`move`:{let e=at(r.from,()=>requireValue(n,parsePointer(r.from),r.from)),t=at(r.from,()=>removeIn(n,parsePointer(r.from)));return at(r.path,()=>addIn(t,parsePointer(r.path),e))}case`copy`:{let e=at(r.from,()=>requireValue(n,parsePointer(r.from),r.from));return at(r.path,()=>addIn(n,parsePointer(r.path),structuredClone(e)))}case`test`:{let i=resolve(n,parsePointer(r.path));if(!i.exists||!e.deepEqual(i.value,r.value))throw new t.PatchTestError(`test failed at "${r.path}"`);return n}}}function apply(e,t){let n=e;for(let e of t)n=applyOperation(n,e);return n}function tryApply(e,n){let r=e;for(let e=0;e<n.length;e+=1){let i=n[e];try{r=applyOperation(r,i)}catch(n){let r=n instanceof t.PatchTestError?`test`:`path`,a=n instanceof t.PatchPathError?n.pointer??i.path:i.path;return{error:{index:e,message:n.message,path:a,reason:r},ok:!1}}}return{doc:r,ok:!0}}function diffNode(t,n,r,i){if(!e.deepEqual(n,r)){if(Array.isArray(n)&&Array.isArray(r)){let a=Math.min(n.length,r.length),o=0;for(;o<a&&e.deepEqual(n[o],r[o]);)o+=1;let s=0;for(;s<a-o&&e.deepEqual(n[n.length-1-s],r[r.length-1-s]);)s+=1;let c=n.length-s,l=r.length-s,u=Math.min(c,l)-o;for(let e=o;e<o+u;e+=1)diffNode(`${t}/${e}`,n[e],r[e],i);for(let e=c-1;e>=o+u;--e)i.push({op:`remove`,path:`${t}/${e}`});let d=s===0;for(let e=o+u;e<l;e+=1)i.push({op:`add`,path:d?`${t}/-`:`${t}/${e}`,value:r[e]})}else if(e.isPlainObject(n)&&e.isPlainObject(r)){for(let e of Object.keys(n))Object.hasOwn(r,e)||i.push({op:`remove`,path:`${t}${formatPointer([e])}`});for(let e of Object.keys(r)){let a=`${t}${formatPointer([e])}`,o=r[e];Object.hasOwn(n,e)?diffNode(a,n[e],o,i):i.push({op:`add`,path:a,value:o})}}else i.push({op:`replace`,path:t,value:r})}}function diff(e,t){let n=[];return diffNode(``,e,t,n),n}exports.apply=apply,exports.diff=diff,exports.formatPointer=formatPointer,exports.getIn=getIn,exports.parsePointer=parsePointer,exports.tryApply=tryApply;
|
|
2
|
+
//# sourceMappingURL=patch.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.cjs","names":["PatchPathError","isPlainObject","deepEqual","PatchTestError","require__equality","require_errors","pointer","token","tokens","index","current","doc","action","rest","value","next","found","run","error","operation","removed","patch","reason","path","from","to","shared","head","tail","fromMiddle","toMiddle","overlap","i","ops","appends","key","childPath","toValue"],"sources":["../src/patch.ts"],"sourcesContent":["import { deepEqual, isPlainObject } from './_equality';\nimport { PatchPathError, PatchTestError } from './errors';\nimport type { ApplyResult, JsonObject, JsonPatch, JsonPointer, JsonValue, PatchOperation } from './types';\n\n// ---------------------------------------------------------------------------\n// RFC 6901 pointers\n// ---------------------------------------------------------------------------\n\n/** Split a JSON Pointer into decoded reference tokens (`~1` → `/`, `~0` → `~`). */\nexport function parsePointer(pointer: JsonPointer): string[] {\n if (pointer === '') return [];\n if (!pointer.startsWith('/')) throw new PatchPathError(`pointer \"${pointer}\" must start with \"/\"`);\n return pointer\n .slice(1)\n .split('/')\n .map((token) => token.replaceAll('~1', '/').replaceAll('~0', '~'));\n}\n\n/** Escape and join reference tokens into a JSON Pointer. */\nexport function formatPointer(tokens: readonly string[]): JsonPointer {\n return tokens.map((token) => `/${token.replaceAll('~', '~0').replaceAll('/', '~1')}`).join('');\n}\n\nfunction isArrayIndex(token: string): number {\n if (/^(0|[1-9]\\d*)$/.test(token)) {\n const index = Number(token);\n return index <= Number.MAX_SAFE_INTEGER ? index : -1;\n }\n return -1;\n}\n\n/** Resolve a pointer, distinguishing \"targets null\" from \"does not exist\". */\nfunction resolve(doc: JsonValue, tokens: readonly string[]): { exists: boolean; value?: JsonValue } {\n let current: JsonValue | undefined = doc;\n for (const token of tokens) {\n if (Array.isArray(current)) {\n const index = isArrayIndex(token);\n current = index >= 0 && index < current.length ? current[index] : undefined;\n } else if (isPlainObject(current)) {\n current = Object.hasOwn(current, token) ? current[token] : undefined;\n } else {\n return { exists: false };\n }\n if (current === undefined) return { exists: false };\n }\n return { exists: true, value: current };\n}\n\n/** Read the value a pointer targets; returns `undefined` when it does not resolve. */\nexport function getIn(doc: JsonValue, pointer: JsonPointer): JsonValue | undefined {\n return resolve(doc, parsePointer(pointer)).value;\n}\n\n// ---------------------------------------------------------------------------\n// Copy-on-write path updates (untouched subtrees keep their identity)\n// ---------------------------------------------------------------------------\n\nfunction descendArray(doc: readonly JsonValue[], token: string, action: string): number {\n const index = isArrayIndex(token);\n if (index < 0 || index >= doc.length) {\n throw new PatchPathError(`cannot ${action} at \"/${token}\": index out of bounds`);\n }\n return index;\n}\n\n/** Insert (arrays) or set (objects); `add` semantics: index may equal the array length. */\nfunction addIn(doc: JsonValue, tokens: readonly string[], value: JsonValue): JsonValue {\n const [token = '', ...rest] = tokens;\n if (tokens.length === 0) return value;\n if (Array.isArray(doc)) {\n if (token === '-') {\n if (rest.length > 0) throw new PatchPathError(`cannot add \"/-\": \"-\" must be the final token`);\n return [...doc, value];\n }\n const index = isArrayIndex(token);\n if (index < 0 || index > doc.length) {\n throw new PatchPathError(`cannot add \"/${token}\": index out of bounds`);\n }\n if (rest.length > 0) {\n if (index === doc.length) throw new PatchPathError(`cannot add \"/${token}\": index out of bounds`);\n return [...doc.slice(0, index), addIn(doc[index] as JsonValue, rest, value), ...doc.slice(index + 1)];\n }\n return [...doc.slice(0, index), value, ...doc.slice(index)];\n }\n if (isPlainObject(doc)) {\n if (rest.length > 0) {\n if (!Object.hasOwn(doc, token)) throw new PatchPathError(`cannot add \"/${token}\": member does not exist`);\n return { ...doc, [token]: addIn(doc[token] as JsonValue, rest, value) };\n }\n if (Object.hasOwn(doc, token) && deepEqual(doc[token] as JsonValue, value)) return doc;\n return { ...doc, [token]: value };\n }\n throw new PatchPathError(`cannot descend into a ${typeof doc}`);\n}\n\n/** Replace in place; the target location must already exist (RFC 6902). */\nfunction replaceIn(doc: JsonValue, tokens: readonly string[], value: JsonValue): JsonValue {\n const [token = '', ...rest] = tokens;\n if (tokens.length === 0) return value;\n if (Array.isArray(doc)) {\n const index = descendArray(doc, token, 'replace');\n if (rest.length === 0) {\n if (deepEqual(doc[index] as JsonValue, value)) return doc;\n return [...doc.slice(0, index), value, ...doc.slice(index + 1)];\n }\n return [...doc.slice(0, index), replaceIn(doc[index] as JsonValue, rest, value), ...doc.slice(index + 1)];\n }\n if (isPlainObject(doc)) {\n if (!Object.hasOwn(doc, token)) throw new PatchPathError(`cannot replace \"/${token}\": member does not exist`);\n if (rest.length === 0) {\n if (deepEqual(doc[token] as JsonValue, value)) return doc;\n return { ...doc, [token]: value };\n }\n return { ...doc, [token]: replaceIn(doc[token] as JsonValue, rest, value) };\n }\n throw new PatchPathError(`cannot descend into a ${typeof doc}`);\n}\n\n/** Remove the member/index the pointer targets; it must exist. */\nfunction removeIn(doc: JsonValue, tokens: readonly string[]): JsonValue {\n const [token = '', ...rest] = tokens;\n if (tokens.length === 0) return null;\n if (Array.isArray(doc)) {\n const index = descendArray(doc, token, 'remove');\n if (rest.length === 0) return [...doc.slice(0, index), ...doc.slice(index + 1)];\n return [...doc.slice(0, index), removeIn(doc[index] as JsonValue, rest), ...doc.slice(index + 1)];\n }\n if (isPlainObject(doc)) {\n if (!Object.hasOwn(doc, token)) throw new PatchPathError(`cannot remove \"/${token}\": member does not exist`);\n if (rest.length === 0) {\n const next: JsonObject = { ...doc };\n delete next[token];\n return next;\n }\n return { ...doc, [token]: removeIn(doc[token] as JsonValue, rest) };\n }\n throw new PatchPathError(`cannot descend into a ${typeof doc}`);\n}\n\nfunction requireValue(doc: JsonValue, tokens: readonly string[], pointer: JsonPointer): JsonValue {\n const found = resolve(doc, tokens);\n if (!found.exists) throw new PatchPathError(`pointer \"${pointer}\" does not resolve`, { pointer });\n return found.value as JsonValue;\n}\n\n/** Attributes path failures thrown inside `run` to `pointer` (the caller's full pointer). */\nfunction at<T>(pointer: JsonPointer, run: () => T): T {\n try {\n return run();\n } catch (error) {\n if (error instanceof PatchPathError && error.pointer === undefined) {\n throw new PatchPathError(error.message, { cause: error, pointer });\n }\n throw error;\n }\n}\n\n// ---------------------------------------------------------------------------\n// RFC 6902 apply / tryApply\n// ---------------------------------------------------------------------------\n\nfunction applyOperation(doc: JsonValue, operation: PatchOperation): JsonValue {\n switch (operation.op) {\n case 'add':\n return at(operation.path, () => addIn(doc, parsePointer(operation.path), structuredClone(operation.value)));\n case 'remove':\n return at(operation.path, () => removeIn(doc, parsePointer(operation.path)));\n case 'replace':\n return at(operation.path, () => replaceIn(doc, parsePointer(operation.path), structuredClone(operation.value)));\n case 'move': {\n const value = at(operation.from, () => requireValue(doc, parsePointer(operation.from), operation.from));\n const removed = at(operation.from, () => removeIn(doc, parsePointer(operation.from)));\n return at(operation.path, () => addIn(removed, parsePointer(operation.path), value));\n }\n case 'copy': {\n const value = at(operation.from, () => requireValue(doc, parsePointer(operation.from), operation.from));\n return at(operation.path, () => addIn(doc, parsePointer(operation.path), structuredClone(value)));\n }\n case 'test': {\n const found = resolve(doc, parsePointer(operation.path));\n if (!found.exists || !deepEqual(found.value as JsonValue, operation.value)) {\n throw new PatchTestError(`test failed at \"${operation.path}\"`);\n }\n return doc;\n }\n }\n}\n\n/**\n * Apply an RFC 6902 patch immutably: untouched subtrees keep their identity,\n * so consumers can diff by reference afterwards. Throws {@link PatchPathError}\n * when a pointer does not resolve and {@link PatchTestError} when a `test`\n * operation does not match — use {@link tryApply} in protocol code where a\n * rejection is an ordinary answer rather than an exception.\n */\nexport function apply<T extends JsonValue>(doc: T, patch: JsonPatch): T {\n let current: JsonValue = doc;\n for (const operation of patch) current = applyOperation(current, operation);\n return current as T;\n}\n\n/** Non-throwing {@link apply}: returns the patched doc or a structured rejection with the failing index. */\nexport function tryApply(doc: JsonValue, patch: JsonPatch): ApplyResult {\n let current: JsonValue = doc;\n for (let index = 0; index < patch.length; index += 1) {\n const operation = patch[index] as PatchOperation;\n try {\n current = applyOperation(current, operation);\n } catch (error) {\n const reason = error instanceof PatchTestError ? 'test' : 'path';\n const path = error instanceof PatchPathError ? (error.pointer ?? operation.path) : operation.path;\n return { error: { index, message: (error as Error).message, path, reason }, ok: false };\n }\n }\n return { doc: current, ok: true };\n}\n\n// ---------------------------------------------------------------------------\n// diff\n// ---------------------------------------------------------------------------\n\nfunction diffNode(path: string, from: JsonValue, to: JsonValue, ops: PatchOperation[]): void {\n if (deepEqual(from, to)) return;\n if (Array.isArray(from) && Array.isArray(to)) {\n // Align on the common prefix and (non-overlapping) common suffix, recurse positionally\n // through the middle, then let surplus removals fall off the middle's tail (descending)\n // and surplus inserts land in ascending index order. True appends keep the `-` token.\n const shared = Math.min(from.length, to.length);\n let head = 0;\n while (head < shared && deepEqual(from[head] as JsonValue, to[head] as JsonValue)) head += 1;\n let tail = 0;\n while (\n tail < shared - head &&\n deepEqual(from[from.length - 1 - tail] as JsonValue, to[to.length - 1 - tail] as JsonValue)\n ) {\n tail += 1;\n }\n const fromMiddle = from.length - tail; // exclusive end of from's middle\n const toMiddle = to.length - tail; // exclusive end of to's middle\n const overlap = Math.min(fromMiddle, toMiddle) - head;\n for (let i = head; i < head + overlap; i += 1) {\n diffNode(`${path}/${i}`, from[i] as JsonValue, to[i] as JsonValue, ops);\n }\n for (let i = fromMiddle - 1; i >= head + overlap; i -= 1) {\n ops.push({ op: 'remove', path: `${path}/${i}` });\n }\n const appends = tail === 0; // surplus only ever lands at the end when no tail is shared\n for (let i = head + overlap; i < toMiddle; i += 1) {\n ops.push({ op: 'add', path: appends ? `${path}/-` : `${path}/${i}`, value: to[i] as JsonValue });\n }\n return;\n }\n if (isPlainObject(from) && isPlainObject(to)) {\n for (const key of Object.keys(from)) {\n if (!Object.hasOwn(to, key)) ops.push({ op: 'remove', path: `${path}${formatPointer([key])}` });\n }\n for (const key of Object.keys(to)) {\n const childPath = `${path}${formatPointer([key])}`;\n const toValue = to[key] as JsonValue;\n if (!Object.hasOwn(from, key)) {\n ops.push({ op: 'add', path: childPath, value: toValue });\n } else {\n diffNode(childPath, from[key] as JsonValue, toValue, ops);\n }\n }\n return;\n }\n ops.push({ op: 'replace', path, value: to });\n}\n\n/**\n * Compute an RFC 6902 patch that transforms `from` into `to`. Object keys\n * diff field-by-field (the payload win sync protocols want); arrays align\n * on their common prefix and suffix and emit ordered removals and indexed\n * inserts around a positionally diffed middle, so appends, prepends, and\n * middle inserts each stay one operation. Not minimal-edit: a reorder\n * diffs positionally. The result always round-trips:\n * `apply(from, diff(from, to))` deep-equals `to`.\n */\nexport function diff(from: JsonValue, to: JsonValue): JsonPatch {\n const ops: PatchOperation[] = [];\n diffNode('', from, to, ops);\n return ops;\n}\n"],"mappings":"A,6DASA,SAAgB,aAAa,EAAgC,CAC3D,GAAIM,IAAY,GAAI,MAAO,CAAC,EAC5B,GAAI,CAACA,EAAQ,WAAW,GAAG,EAAG,MAAM,IAAIN,EAAAA,eAAe,YAAYM,EAAQ,sBAAsB,EACjG,OAAOA,EACJ,MAAM,CAAC,CAAC,CACR,MAAM,GAAG,CAAC,CACV,IAAK,GAAUC,EAAM,WAAW,KAAM,GAAG,CAAC,CAAC,WAAW,KAAM,GAAG,CAAC,CACrE,CAGA,SAAgB,cAAc,EAAwC,CACpE,OAAOC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,KAAO,OAAO,KAAKX,CAAI,EAC3B,OAAO,OAAOC,EAAIU,CAAG,GAAGF,EAAI,KAAK,CAAE,GAAI,SAAU,KAAM,GAAGV,IAAO,cAAc,CAACY,CAAG,CAAC,GAAI,CAAC,EAEhG,IAAK,IAAMA,KAAO,OAAO,KAAKV,CAAE,EAAG,CACjC,IAAMW,EAAY,GAAGb,IAAO,cAAc,CAACY,CAAG,CAAC,IACzCE,EAAUZ,EAAGU,GACd,OAAO,OAAOX,EAAMW,CAAG,EAG1B,SAASC,EAAWZ,EAAKW,GAAmBE,EAASJ,CAAG,EAFxDA,EAAI,KAAK,CAAE,GAAI,MAAO,KAAMG,EAAW,MAAOC,CAAQ,CAAC,CAI3D,CAEF,MACAJ,EAAI,KAAK,CAAE,GAAI,UAAW,OAAM,MAAOR,CAAG,CAAC,CAhB3C,CAiBF,CAWA,SAAgB,KAAK,EAAiB,EAA0B,CAC9D,IAAMQ,EAAwB,CAAC,EAE/B,OADA,SAAS,GAAIT,EAAMC,EAAIQ,CAAG,EACnBA,CACT,C"}
|
package/dist/patch.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ApplyResult, JsonPatch, JsonPointer, JsonValue } from './types';
|
|
2
|
+
/** Split a JSON Pointer into decoded reference tokens (`~1` → `/`, `~0` → `~`). */
|
|
3
|
+
export declare function parsePointer(pointer: JsonPointer): string[];
|
|
4
|
+
/** Escape and join reference tokens into a JSON Pointer. */
|
|
5
|
+
export declare function formatPointer(tokens: readonly string[]): JsonPointer;
|
|
6
|
+
/** Read the value a pointer targets; returns `undefined` when it does not resolve. */
|
|
7
|
+
export declare function getIn(doc: JsonValue, pointer: JsonPointer): JsonValue | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Apply an RFC 6902 patch immutably: untouched subtrees keep their identity,
|
|
10
|
+
* so consumers can diff by reference afterwards. Throws {@link PatchPathError}
|
|
11
|
+
* when a pointer does not resolve and {@link PatchTestError} when a `test`
|
|
12
|
+
* operation does not match — use {@link tryApply} in protocol code where a
|
|
13
|
+
* rejection is an ordinary answer rather than an exception.
|
|
14
|
+
*/
|
|
15
|
+
export declare function apply<T extends JsonValue>(doc: T, patch: JsonPatch): T;
|
|
16
|
+
/** Non-throwing {@link apply}: returns the patched doc or a structured rejection with the failing index. */
|
|
17
|
+
export declare function tryApply(doc: JsonValue, patch: JsonPatch): ApplyResult;
|
|
18
|
+
/**
|
|
19
|
+
* Compute an RFC 6902 patch that transforms `from` into `to`. Object keys
|
|
20
|
+
* diff field-by-field (the payload win sync protocols want); arrays align
|
|
21
|
+
* on their common prefix and suffix and emit ordered removals and indexed
|
|
22
|
+
* inserts around a positionally diffed middle, so appends, prepends, and
|
|
23
|
+
* middle inserts each stay one operation. Not minimal-edit: a reorder
|
|
24
|
+
* diffs positionally. The result always round-trips:
|
|
25
|
+
* `apply(from, diff(from, to))` deep-equals `to`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function diff(from: JsonValue, to: JsonValue): JsonPatch;
|
|
28
|
+
//# sourceMappingURL=patch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../src/patch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAc,SAAS,EAAE,WAAW,EAAE,SAAS,EAAkB,MAAM,SAAS,CAAC;AAM1G,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,EAAE,CAO3D;AAED,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,WAAW,CAEpE;AA2BD,sFAAsF;AACtF,wBAAgB,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,SAAS,CAEjF;AAyID;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,GAAG,CAAC,CAItE;AAED,4GAA4G;AAC5G,wBAAgB,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,WAAW,CAatE;AAuDD;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,GAAG,SAAS,CAI9D"}
|