@hydranium/protocol 1.0.0-next.117 → 1.0.0-next.123
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/lib/client/data-connection.d.ts +28 -66
- package/lib/client/data-connection.d.ts.map +1 -1
- package/lib/client/data-connection.js +41 -112
- package/lib/client/data-connection.js.map +1 -1
- package/lib/client/data-session.d.ts +168 -93
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +291 -147
- package/lib/client/data-session.js.map +1 -1
- package/lib/data/data-protocol-methods.d.ts +2 -2
- package/lib/data/data-protocol-methods.d.ts.map +1 -1
- package/lib/data/data-protocol-methods.js +4 -0
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +66 -30
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/requests.d.ts +67 -11
- package/lib/data/requests.d.ts.map +1 -1
- package/lib/errors.d.ts +66 -4
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +96 -5
- package/lib/errors.js.map +1 -1
- package/lib/messages/index.d.ts +1 -0
- package/lib/messages/index.d.ts.map +1 -1
- package/lib/messages/index.js +4 -1
- package/lib/messages/index.js.map +1 -1
- package/lib/model-server.d.ts +13 -1
- package/lib/model-server.d.ts.map +1 -1
- package/lib/model-server.js.map +1 -1
- package/lib/model-service/based-on.d.ts +2 -0
- package/lib/model-service/based-on.d.ts.map +1 -1
- package/lib/model-service/based-on.js +3 -0
- package/lib/model-service/based-on.js.map +1 -1
- package/lib/model-service/index.d.ts +0 -1
- package/lib/model-service/index.d.ts.map +1 -1
- package/lib/model-service/index.js +3 -5
- package/lib/model-service/index.js.map +1 -1
- package/lib/patch-merge.d.ts +28 -27
- package/lib/patch-merge.d.ts.map +1 -1
- package/lib/patch-merge.js +66 -22
- package/lib/patch-merge.js.map +1 -1
- package/lib/transfer-document.d.ts +2 -3
- package/lib/transfer-document.d.ts.map +1 -1
- package/lib/transfer-document.js.map +1 -1
- package/package.json +1 -1
- package/src/client/data-connection.ts +69 -119
- package/src/client/data-session.ts +348 -177
- package/src/data/data-protocol-methods.ts +4 -0
- package/src/data/data-server-protocol.ts +74 -30
- package/src/data/requests.ts +71 -11
- package/src/errors.ts +101 -4
- package/src/messages/index.ts +1 -0
- package/src/model-server.ts +13 -5
- package/src/model-service/based-on.ts +3 -0
- package/src/model-service/index.ts +3 -5
- package/src/patch-merge.ts +90 -37
- package/src/transfer-document.ts +2 -3
- package/lib/model-service/args.d.ts +0 -65
- package/lib/model-service/args.d.ts.map +0 -1
- package/lib/model-service/args.js +0 -11
- package/lib/model-service/args.js.map +0 -1
- package/src/model-service/args.ts +0 -69
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* SPDX-License-Identifier: MIT
|
|
9
9
|
********************************************************************************/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.NO_MATCHING_VERSION = void 0;
|
|
11
12
|
exports.isSnapshotVersion = isSnapshotVersion;
|
|
12
13
|
exports.asSnapshotVersion = asSnapshotVersion;
|
|
13
14
|
/**
|
|
@@ -31,4 +32,6 @@ function isSnapshotVersion(basedOn) {
|
|
|
31
32
|
function asSnapshotVersion(version) {
|
|
32
33
|
return version;
|
|
33
34
|
}
|
|
35
|
+
/** A snapshot version no write can match, so a write based on it conflicts. */
|
|
36
|
+
exports.NO_MATCHING_VERSION = asSnapshotVersion(-1);
|
|
34
37
|
//# sourceMappingURL=based-on.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"based-on.js","sourceRoot":"","sources":["../../src/model-service/based-on.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF
|
|
1
|
+
{"version":3,"file":"based-on.js","sourceRoot":"","sources":["../../src/model-service/based-on.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAqClF,8CAEC;AAWD,8CAEC;AArBD;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,OAAgB;IAC/C,OAAO,OAAO,OAAO,KAAK,QAAQ,CAAC;AACtC,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAAC,OAAe;IAC9C,OAAO,OAA0B,CAAC;AACrC,CAAC;AAED,+EAA+E;AAClE,QAAA,mBAAmB,GAAoB,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model-service/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model-service/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAMlF,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC"}
|
|
@@ -22,11 +22,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
22
22
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
// protocol can structurally agree on the lifecycle shape.
|
|
29
|
-
__exportStar(require("./args"), exports);
|
|
25
|
+
// Generic payload types the data protocol shares with core: the based-on
|
|
26
|
+
// version, which the server's model service checks writes against, and the
|
|
27
|
+
// reference candidates, which core's scope and completion code produce.
|
|
30
28
|
__exportStar(require("./based-on"), exports);
|
|
31
29
|
__exportStar(require("./reference-candidate"), exports);
|
|
32
30
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model-service/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model-service/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,yEAAyE;AACzE,2EAA2E;AAC3E,wEAAwE;AAExE,6CAA2B;AAC3B,wDAAsC"}
|
package/lib/patch-merge.d.ts
CHANGED
|
@@ -8,58 +8,58 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
import { type Operation as JsonPatchOperation } from 'fast-json-patch';
|
|
10
10
|
/**
|
|
11
|
-
* Augment a user-intent JSON patch (computed `
|
|
11
|
+
* Augment a user-intent JSON patch (computed `base → ours`) with
|
|
12
12
|
* `test` ops so a strict `applyPatch` against freshly-fetched server state
|
|
13
13
|
* fails loudly when a foreign writer changed a path the user also changed.
|
|
14
14
|
*
|
|
15
15
|
* `fast-json-patch`'s `validateOperation: true` validates op structure and
|
|
16
16
|
* path resolvability but NOT the pre-existing value — a plain `replace` /
|
|
17
17
|
* `remove` silently overwrites whatever the foreign writer put there. For each
|
|
18
|
-
* `replace` / `remove` op we prepend a `test` op carrying the
|
|
18
|
+
* `replace` / `remove` op we prepend a `test` op carrying the base value at
|
|
19
19
|
* that path, so a same-path divergence becomes a `TEST_OPERATION_FAILED` throw.
|
|
20
20
|
* The caller treats that as a real field-level conflict (drop + refetch) rather
|
|
21
21
|
* than silently clobbering the foreign edit.
|
|
22
22
|
*
|
|
23
|
-
* `add` ops
|
|
24
|
-
* to test
|
|
23
|
+
* `add` ops get no `test` op: the path is new, so there is no base value
|
|
24
|
+
* to test. {@link reconcileByPatchReplay} checks them against theirs
|
|
25
|
+
* instead; a caller applying this patch itself does not get that check.
|
|
25
26
|
*
|
|
26
27
|
* Used behind the framework's `ConflictError` contract by every reconcile
|
|
27
28
|
* path — the GLSP recording command's undo/redo and forward-write, via
|
|
28
29
|
* {@link ReconcilingConflictResolver}, and an adopter's form-widget save — so
|
|
29
30
|
* they share one collision-detection rule.
|
|
30
31
|
*/
|
|
31
|
-
export declare function augmentWithTestOps(
|
|
32
|
+
export declare function augmentWithTestOps(base: object, userPatch: ReadonlyArray<JsonPatchOperation>): JsonPatchOperation[];
|
|
32
33
|
/**
|
|
33
|
-
* Outcome of {@link reconcileByPatchReplay}. The caller persists
|
|
34
|
-
*
|
|
35
|
-
* own fallback (e.g. force-retry) on `no-op` / `unavailable`.
|
|
34
|
+
* Outcome of {@link reconcileByPatchReplay}. The caller persists `merged` and
|
|
35
|
+
* takes it as the new base, drops + surfaces the `theirs` root on `conflict`, and
|
|
36
|
+
* decides its own fallback (e.g. force-retry) on `no-op` / `unavailable`.
|
|
36
37
|
*/
|
|
37
38
|
export type ReconcileOutcome<T> = {
|
|
38
39
|
/** The replay succeeded: the foreign writer touched no path the user did. */
|
|
39
40
|
status: 'merged';
|
|
40
41
|
/**
|
|
41
|
-
* A
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* had.
|
|
42
|
+
* A new root built on theirs, carrying both intents. It is NOT the
|
|
43
|
+
* caller's `ours` root — take this value as the new base, or the next
|
|
44
|
+
* write diffs against state the server never had.
|
|
45
45
|
*/
|
|
46
46
|
merged: T;
|
|
47
47
|
} | {
|
|
48
48
|
/**
|
|
49
|
-
* The user's root already equalled the
|
|
49
|
+
* The user's root already equalled the base, so the version gate
|
|
50
50
|
* fired on drift that changed nothing. No refetch was performed and
|
|
51
51
|
* there is nothing to persist — retrying the same write reproduces it.
|
|
52
52
|
*/
|
|
53
53
|
status: 'no-op';
|
|
54
54
|
} | {
|
|
55
|
-
/**
|
|
55
|
+
/** User and foreign writer changed one path, or both added the same element or key. */
|
|
56
56
|
status: 'conflict';
|
|
57
57
|
/**
|
|
58
58
|
* The server's current root, refetched and unmodified — the user's
|
|
59
59
|
* intent was NOT applied to it. Surface it and drop the write; treating
|
|
60
60
|
* it as a merge result silently discards what the user typed.
|
|
61
61
|
*/
|
|
62
|
-
|
|
62
|
+
theirs: T;
|
|
63
63
|
} | {
|
|
64
64
|
/**
|
|
65
65
|
* The refetch produced nothing, so reconciliation could not be
|
|
@@ -70,22 +70,23 @@ export type ReconcileOutcome<T> = {
|
|
|
70
70
|
};
|
|
71
71
|
/**
|
|
72
72
|
* Shared three-way reconcile for a `ConflictError`: diff the user's intent
|
|
73
|
-
* (`
|
|
73
|
+
* (`base → ours`), refetch the server's current root (theirs), and replay the
|
|
74
74
|
* intent on top under strict, {@link augmentWithTestOps}-guarded `applyPatch`.
|
|
75
75
|
*
|
|
76
|
-
* - `no-op` — the user's root equals the
|
|
76
|
+
* - `no-op` — the user's root equals the base, so the gate fired on a
|
|
77
77
|
* benign version drift; nothing to replay (refetch is skipped).
|
|
78
78
|
* - `unavailable` — the refetch produced nothing; caller falls back.
|
|
79
79
|
* - `merged` — the foreign writer touched only paths the user did not; the
|
|
80
80
|
* merged root carries both intents.
|
|
81
|
-
* - `conflict` — a same-path divergence tripped a `test` op
|
|
82
|
-
* write and
|
|
81
|
+
* - `conflict` — a same-path divergence tripped a `test` op, or an `add`
|
|
82
|
+
* collides with one the foreign writer made; caller drops the write and
|
|
83
|
+
* surfaces `theirs`.
|
|
83
84
|
*
|
|
84
85
|
* I/O is the caller's: `refetch` supplies the current root, and applying the
|
|
85
|
-
* `merged` result (update vs save,
|
|
86
|
+
* `merged` result (update vs save, new base, UI refresh) stays at the call
|
|
86
87
|
* site so form and GLSP paths keep their own persistence semantics.
|
|
87
88
|
*/
|
|
88
|
-
export declare function reconcileByPatchReplay<T extends object>(
|
|
89
|
+
export declare function reconcileByPatchReplay<T extends object>(base: T, ours: T, refetch: () => Promise<T | undefined>): Promise<ReconcileOutcome<T>>;
|
|
89
90
|
/**
|
|
90
91
|
* Strategy for resolving a write that raced a foreign edit. One declarative
|
|
91
92
|
* choice covers every conflict site — `execute` forward-write `(before,
|
|
@@ -95,12 +96,12 @@ export declare function reconcileByPatchReplay<T extends object>(baseline: T, at
|
|
|
95
96
|
*/
|
|
96
97
|
export interface ConflictResolver {
|
|
97
98
|
/**
|
|
98
|
-
* Reconcile the user's `
|
|
99
|
-
* server state (`refetch`), returning a {@link ReconcileOutcome} the caller
|
|
99
|
+
* Reconcile the user's `base → ours` intent against the current
|
|
100
|
+
* server state (theirs, from `refetch`), returning a {@link ReconcileOutcome} the caller
|
|
100
101
|
* acts on (persist `merged`, drop on `conflict`, fall back on `no-op` /
|
|
101
102
|
* `unavailable`).
|
|
102
103
|
*/
|
|
103
|
-
resolve<T extends object>(
|
|
104
|
+
resolve<T extends object>(base: T, ours: T, refetch: () => Promise<T | undefined>): Promise<ReconcileOutcome<T>>;
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
106
107
|
* Default {@link ConflictResolver}: field-level three-way merge via
|
|
@@ -109,15 +110,15 @@ export interface ConflictResolver {
|
|
|
109
110
|
* clobbered.
|
|
110
111
|
*/
|
|
111
112
|
export declare class ReconcilingConflictResolver implements ConflictResolver {
|
|
112
|
-
resolve<T extends object>(
|
|
113
|
+
resolve<T extends object>(base: T, ours: T, refetch: () => Promise<T | undefined>): Promise<ReconcileOutcome<T>>;
|
|
113
114
|
}
|
|
114
115
|
/**
|
|
115
|
-
* Last-writer-wins {@link ConflictResolver}: always reports the `
|
|
116
|
+
* Last-writer-wins {@link ConflictResolver}: always reports the `ours`
|
|
116
117
|
* state as merged, without refetching or guarding. Suitable for single-client
|
|
117
118
|
* tools or always-regenerated artifacts where a concurrent foreign edit may be
|
|
118
119
|
* overwritten. A foreign edit to any field is clobbered.
|
|
119
120
|
*/
|
|
120
121
|
export declare class ForceConflictResolver implements ConflictResolver {
|
|
121
|
-
resolve<T extends object>(
|
|
122
|
+
resolve<T extends object>(_base: T, ours: T, _refetch: () => Promise<T | undefined>): Promise<ReconcileOutcome<T>>;
|
|
122
123
|
}
|
|
123
124
|
//# sourceMappingURL=patch-merge.d.ts.map
|
package/lib/patch-merge.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch-merge.d.ts","sourceRoot":"","sources":["../src/patch-merge.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,
|
|
1
|
+
{"version":3,"file":"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AAgB;IACjE,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;CAGlH;AAED;;;;;GAKG;AACH,qBAAa,qBAAsB,YAAW,gBAAgB;IACrD,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;CAG1H"}
|
package/lib/patch-merge.js
CHANGED
|
@@ -13,31 +13,32 @@ exports.augmentWithTestOps = augmentWithTestOps;
|
|
|
13
13
|
exports.reconcileByPatchReplay = reconcileByPatchReplay;
|
|
14
14
|
const fast_json_patch_1 = require("fast-json-patch");
|
|
15
15
|
/**
|
|
16
|
-
* Augment a user-intent JSON patch (computed `
|
|
16
|
+
* Augment a user-intent JSON patch (computed `base → ours`) with
|
|
17
17
|
* `test` ops so a strict `applyPatch` against freshly-fetched server state
|
|
18
18
|
* fails loudly when a foreign writer changed a path the user also changed.
|
|
19
19
|
*
|
|
20
20
|
* `fast-json-patch`'s `validateOperation: true` validates op structure and
|
|
21
21
|
* path resolvability but NOT the pre-existing value — a plain `replace` /
|
|
22
22
|
* `remove` silently overwrites whatever the foreign writer put there. For each
|
|
23
|
-
* `replace` / `remove` op we prepend a `test` op carrying the
|
|
23
|
+
* `replace` / `remove` op we prepend a `test` op carrying the base value at
|
|
24
24
|
* that path, so a same-path divergence becomes a `TEST_OPERATION_FAILED` throw.
|
|
25
25
|
* The caller treats that as a real field-level conflict (drop + refetch) rather
|
|
26
26
|
* than silently clobbering the foreign edit.
|
|
27
27
|
*
|
|
28
|
-
* `add` ops
|
|
29
|
-
* to test
|
|
28
|
+
* `add` ops get no `test` op: the path is new, so there is no base value
|
|
29
|
+
* to test. {@link reconcileByPatchReplay} checks them against theirs
|
|
30
|
+
* instead; a caller applying this patch itself does not get that check.
|
|
30
31
|
*
|
|
31
32
|
* Used behind the framework's `ConflictError` contract by every reconcile
|
|
32
33
|
* path — the GLSP recording command's undo/redo and forward-write, via
|
|
33
34
|
* {@link ReconcilingConflictResolver}, and an adopter's form-widget save — so
|
|
34
35
|
* they share one collision-detection rule.
|
|
35
36
|
*/
|
|
36
|
-
function augmentWithTestOps(
|
|
37
|
+
function augmentWithTestOps(base, userPatch) {
|
|
37
38
|
const augmented = [];
|
|
38
39
|
for (const op of userPatch) {
|
|
39
40
|
if (op.op === 'replace' || op.op === 'remove') {
|
|
40
|
-
augmented.push({ op: 'test', path: op.path, value: (0, fast_json_patch_1.getValueByPointer)(
|
|
41
|
+
augmented.push({ op: 'test', path: op.path, value: (0, fast_json_patch_1.getValueByPointer)(base, op.path) });
|
|
41
42
|
}
|
|
42
43
|
augmented.push(op);
|
|
43
44
|
}
|
|
@@ -45,36 +46,79 @@ function augmentWithTestOps(baseline, userPatch) {
|
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Shared three-way reconcile for a `ConflictError`: diff the user's intent
|
|
48
|
-
* (`
|
|
49
|
+
* (`base → ours`), refetch the server's current root (theirs), and replay the
|
|
49
50
|
* intent on top under strict, {@link augmentWithTestOps}-guarded `applyPatch`.
|
|
50
51
|
*
|
|
51
|
-
* - `no-op` — the user's root equals the
|
|
52
|
+
* - `no-op` — the user's root equals the base, so the gate fired on a
|
|
52
53
|
* benign version drift; nothing to replay (refetch is skipped).
|
|
53
54
|
* - `unavailable` — the refetch produced nothing; caller falls back.
|
|
54
55
|
* - `merged` — the foreign writer touched only paths the user did not; the
|
|
55
56
|
* merged root carries both intents.
|
|
56
|
-
* - `conflict` — a same-path divergence tripped a `test` op
|
|
57
|
-
* write and
|
|
57
|
+
* - `conflict` — a same-path divergence tripped a `test` op, or an `add`
|
|
58
|
+
* collides with one the foreign writer made; caller drops the write and
|
|
59
|
+
* surfaces `theirs`.
|
|
58
60
|
*
|
|
59
61
|
* I/O is the caller's: `refetch` supplies the current root, and applying the
|
|
60
|
-
* `merged` result (update vs save,
|
|
62
|
+
* `merged` result (update vs save, new base, UI refresh) stays at the call
|
|
61
63
|
* site so form and GLSP paths keep their own persistence semantics.
|
|
62
64
|
*/
|
|
63
|
-
async function reconcileByPatchReplay(
|
|
64
|
-
const userPatch = (0, fast_json_patch_1.compare)(
|
|
65
|
+
async function reconcileByPatchReplay(base, ours, refetch) {
|
|
66
|
+
const userPatch = (0, fast_json_patch_1.compare)(base, ours);
|
|
65
67
|
if (userPatch.length === 0) {
|
|
66
68
|
return { status: 'no-op' };
|
|
67
69
|
}
|
|
68
|
-
const
|
|
69
|
-
if (!
|
|
70
|
+
const theirs = await refetch();
|
|
71
|
+
if (!theirs) {
|
|
70
72
|
return { status: 'unavailable' };
|
|
71
73
|
}
|
|
74
|
+
if (addsCollide(base, theirs, userPatch)) {
|
|
75
|
+
return { status: 'conflict', theirs };
|
|
76
|
+
}
|
|
72
77
|
try {
|
|
73
|
-
const merged = (0, fast_json_patch_1.applyPatch)((0, fast_json_patch_1.deepClone)(
|
|
78
|
+
const merged = (0, fast_json_patch_1.applyPatch)((0, fast_json_patch_1.deepClone)(theirs), augmentWithTestOps(base, userPatch), true).newDocument;
|
|
74
79
|
return { status: 'merged', merged };
|
|
75
80
|
}
|
|
76
81
|
catch {
|
|
77
|
-
return { status: 'conflict',
|
|
82
|
+
return { status: 'conflict', theirs };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Whether an `add` of `userPatch` collides with one the foreign writer made:
|
|
87
|
+
* it inserts a value into an array that `theirs` holds more often than
|
|
88
|
+
* `base` did, or it adds an object key that `theirs` already holds.
|
|
89
|
+
*
|
|
90
|
+
* Replayed, the first inserts the value a second time and the second replaces
|
|
91
|
+
* the foreign value. Identical values conflict rather than being skipped:
|
|
92
|
+
* skipping drops one of two additions that merely happen to be equal.
|
|
93
|
+
*/
|
|
94
|
+
function addsCollide(base, theirs, userPatch) {
|
|
95
|
+
// Through JSON, as `compare` clones the add values: an undefined-valued key
|
|
96
|
+
// in `theirs` would otherwise make an equal element count as another.
|
|
97
|
+
const comparable = JSON.parse(JSON.stringify(theirs));
|
|
98
|
+
return userPatch.some(op => {
|
|
99
|
+
if (op.op !== 'add') {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
const cut = op.path.lastIndexOf('/');
|
|
103
|
+
const before = valueAt(base, op.path.slice(0, cut));
|
|
104
|
+
const now = valueAt(comparable, op.path.slice(0, cut));
|
|
105
|
+
if (Array.isArray(before)) {
|
|
106
|
+
return Array.isArray(now) && occurrences(now, op.value) > occurrences(before, op.value);
|
|
107
|
+
}
|
|
108
|
+
return typeof now === 'object' && now !== null && Object.hasOwn(now, (0, fast_json_patch_1.unescapePathComponent)(op.path.slice(cut + 1)));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** How many elements of `array` deeply equal `value`, whatever their key order. */
|
|
112
|
+
function occurrences(array, value) {
|
|
113
|
+
return array.filter(element => (0, fast_json_patch_1._areEquals)(element, value)).length;
|
|
114
|
+
}
|
|
115
|
+
/** The value at `pointer`, or `undefined` when a step of it is missing. */
|
|
116
|
+
function valueAt(document, pointer) {
|
|
117
|
+
try {
|
|
118
|
+
return (0, fast_json_patch_1.getValueByPointer)(document, pointer);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return undefined;
|
|
78
122
|
}
|
|
79
123
|
}
|
|
80
124
|
/**
|
|
@@ -84,20 +128,20 @@ async function reconcileByPatchReplay(baseline, attempted, refetch) {
|
|
|
84
128
|
* clobbered.
|
|
85
129
|
*/
|
|
86
130
|
class ReconcilingConflictResolver {
|
|
87
|
-
resolve(
|
|
88
|
-
return reconcileByPatchReplay(
|
|
131
|
+
resolve(base, ours, refetch) {
|
|
132
|
+
return reconcileByPatchReplay(base, ours, refetch);
|
|
89
133
|
}
|
|
90
134
|
}
|
|
91
135
|
exports.ReconcilingConflictResolver = ReconcilingConflictResolver;
|
|
92
136
|
/**
|
|
93
|
-
* Last-writer-wins {@link ConflictResolver}: always reports the `
|
|
137
|
+
* Last-writer-wins {@link ConflictResolver}: always reports the `ours`
|
|
94
138
|
* state as merged, without refetching or guarding. Suitable for single-client
|
|
95
139
|
* tools or always-regenerated artifacts where a concurrent foreign edit may be
|
|
96
140
|
* overwritten. A foreign edit to any field is clobbered.
|
|
97
141
|
*/
|
|
98
142
|
class ForceConflictResolver {
|
|
99
|
-
async resolve(
|
|
100
|
-
return { status: 'merged', merged:
|
|
143
|
+
async resolve(_base, ours, _refetch) {
|
|
144
|
+
return { status: 'merged', merged: ours };
|
|
101
145
|
}
|
|
102
146
|
}
|
|
103
147
|
exports.ForceConflictResolver = ForceConflictResolver;
|
package/lib/patch-merge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch-merge.js","sourceRoot":"","sources":["../src/patch-merge.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;
|
|
1
|
+
{"version":3,"file":"patch-merge.js","sourceRoot":"","sources":["../src/patch-merge.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAkClF,gDASC;AA+DD,wDAsBC;AA9HD,qDAQyB;AAEzB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,kBAAkB,CAAC,IAAY,EAAE,SAA4C;IAC1F,MAAM,SAAS,GAAyB,EAAE,CAAC;IAC3C,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;QAC1B,IAAI,EAAE,CAAC,EAAE,KAAK,SAAS,IAAI,EAAE,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;YAC7C,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,K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,OAAO,CAAC,QAAgB,EAAE,OAAe;IAC/C,IAAI,CAAC;QACF,OAAO,IAAA,mCAAiB,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACpB,CAAC;AACJ,CAAC;AAmBD;;;;;GAKG;AACH,MAAa,2BAA2B;IACrC,OAAO,CAAmB,IAAO,EAAE,IAAO,EAAE,OAAqC;QAC9E,OAAO,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;CACH;AAJD,kEAIC;AAED;;;;;GAKG;AACH,MAAa,qBAAqB;IAC/B,KAAK,CAAC,OAAO,CAAmB,KAAQ,EAAE,IAAO,EAAE,QAAsC;QACtF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC7C,CAAC;CACH;AAJD,sDAIC"}
|
|
@@ -27,9 +27,8 @@ export interface TransferDocument<TTransfer extends TransferElement, TDiagnostic
|
|
|
27
27
|
/**
|
|
28
28
|
* The document version this snapshot was taken at — sourced from the
|
|
29
29
|
* server's text-document version counter. A caller that mutates the document
|
|
30
|
-
* subsequently sends this straight back as `
|
|
31
|
-
*
|
|
32
|
-
* with `ConflictError`.
|
|
30
|
+
* subsequently sends this straight back as `TransferUpdateDocumentArgs.basedOn`, and
|
|
31
|
+
* the server rejects a stale-based update with `ConflictError`.
|
|
33
32
|
*
|
|
34
33
|
* See `@hydranium/protocol#errors` for the conflict-detection contract.
|
|
35
34
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer-document.d.ts","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,E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kB,EAC7F,QAAQ,EAAE,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,GAClD,sBAAsB,CAAC,SAAS,EAAE,WAAW,CAAC,CAKhD;IAED;;;;;;;OAOG;IACH,SAAgB,MAAM,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EACvF,GAAG,EAAE,MAAM,EACX,WAAW,GAAE,WAAW,EAAO,GAC/B,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAE1C;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EACvF,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,EACf,WAAW,GAAE,WAAW,EAAO,GAC/B,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAE1C;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer-document.js","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAIlF,uDAAmF;
|
|
1
|
+
{"version":3,"file":"transfer-document.js","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAIlF,uDAAmF;AA+CnF,IAAiB,gBAAgB,CAuDhC;AAvDD,WAAiB,gBAAgB;IAC9B;;;OAGG;IACH,SAAgB,QAAQ,CACrB,QAAkD;QAElD,OAAO,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC;IACtC,CAAC;IAJe,yBAAQ,WAIvB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,YAAY,CACzB,QAAkD;QAElD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,QAAQ,CAAC;IACnB,CAAC;IAPe,6BAAY,eAO3B,CAAA;IAED;;;;;;;OAOG;IACH,SAAgB,MAAM,CACnB,GAAW,EACX,cAA6B,EAAE;QAE/B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAA,4BAAiB,EAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;IAC/E,CAAC;IALe,uBAAM,SAKrB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CACnB,GAAW,EACX,OAAe,EACf,IAAe,EACf,cAA6B,EAAE;QAE/B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAA,4BAAiB,EAAC,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC1E,CAAC;IAPe,uBAAM,SAOrB,CAAA;AACJ,CAAC,EAvDgB,gBAAgB,gCAAhB,gBAAgB,QAuDhC"}
|
package/package.json
CHANGED