@hydranium/protocol 1.0.0-next.29 → 1.0.0-next.299
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/README.md +44 -49
- package/lib/abstract-logger.d.ts +5 -0
- package/lib/abstract-logger.d.ts.map +1 -1
- package/lib/abstract-logger.js +7 -0
- package/lib/abstract-logger.js.map +1 -1
- package/lib/client/data-connection.d.ts +302 -0
- package/lib/client/data-connection.d.ts.map +1 -0
- package/lib/client/data-connection.js +533 -0
- package/lib/client/data-connection.js.map +1 -0
- package/lib/client/data-events.d.ts +17 -1
- package/lib/client/data-events.d.ts.map +1 -1
- package/lib/client/data-events.js +25 -0
- package/lib/client/data-events.js.map +1 -1
- package/lib/client/data-port.d.ts +34 -24
- package/lib/client/data-port.d.ts.map +1 -1
- package/lib/client/data-session.d.ts +657 -89
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +1113 -115
- package/lib/client/data-session.js.map +1 -1
- package/lib/client/index.d.ts +15 -9
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +15 -9
- package/lib/client/index.js.map +1 -1
- package/lib/client/message-relay.d.ts +4 -4
- package/lib/client/message-relay.js +4 -4
- package/lib/client/message-relay.js.map +1 -1
- package/lib/client/post-message-transport.d.ts +64 -3
- package/lib/client/post-message-transport.d.ts.map +1 -1
- package/lib/client/post-message-transport.js +175 -1
- package/lib/client/post-message-transport.js.map +1 -1
- package/lib/client/rpc-connection.d.ts +157 -0
- package/lib/client/rpc-connection.d.ts.map +1 -0
- package/lib/client/rpc-connection.js +214 -0
- package/lib/client/rpc-connection.js.map +1 -0
- package/lib/client/worker-handshake.d.ts +72 -0
- package/lib/client/worker-handshake.d.ts.map +1 -0
- package/lib/client/worker-handshake.js +51 -0
- package/lib/client/worker-handshake.js.map +1 -0
- package/lib/client-ids.d.ts +45 -0
- package/lib/client-ids.d.ts.map +1 -0
- package/lib/client-ids.js +48 -0
- package/lib/client-ids.js.map +1 -0
- package/lib/clock.d.ts +50 -10
- package/lib/clock.d.ts.map +1 -1
- package/lib/clock.js +36 -1
- package/lib/clock.js.map +1 -1
- package/lib/console-logger.d.ts +23 -0
- package/lib/console-logger.d.ts.map +1 -0
- package/lib/console-logger.js +39 -0
- package/lib/console-logger.js.map +1 -0
- package/lib/data/data-protocol-methods.d.ts +4 -4
- package/lib/data/data-protocol-methods.d.ts.map +1 -1
- package/lib/data/data-protocol-methods.js +13 -1
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +165 -48
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/events.d.ts +137 -21
- package/lib/data/events.d.ts.map +1 -1
- package/lib/data/requests.d.ts +71 -11
- package/lib/data/requests.d.ts.map +1 -1
- package/lib/debouncer.d.ts +3 -3
- package/lib/debouncer.d.ts.map +1 -1
- package/lib/debouncer.js +6 -9
- package/lib/debouncer.js.map +1 -1
- package/lib/errors.d.ts +175 -30
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +260 -32
- package/lib/errors.js.map +1 -1
- package/lib/glsp-request-model-args.d.ts +16 -0
- package/lib/glsp-request-model-args.d.ts.map +1 -0
- package/lib/glsp-request-model-args.js +19 -0
- package/lib/glsp-request-model-args.js.map +1 -0
- package/lib/glsp-save-model-actions.d.ts +50 -0
- package/lib/glsp-save-model-actions.d.ts.map +1 -0
- package/lib/glsp-save-model-actions.js +28 -0
- package/lib/glsp-save-model-actions.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/latency-collector.d.ts +8 -4
- package/lib/latency-collector.d.ts.map +1 -1
- package/lib/latency-collector.js.map +1 -1
- package/lib/logger.d.ts +38 -7
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +42 -4
- package/lib/logger.js.map +1 -1
- package/lib/messages/index.d.ts +4 -2
- package/lib/messages/index.d.ts.map +1 -1
- package/lib/messages/index.js +14 -4
- package/lib/messages/index.js.map +1 -1
- package/lib/messages/primitives.d.ts +71 -10
- package/lib/messages/primitives.d.ts.map +1 -1
- package/lib/messages/primitives.js +55 -3
- package/lib/messages/primitives.js.map +1 -1
- package/lib/model-server.d.ts +60 -13
- package/lib/model-server.d.ts.map +1 -1
- package/lib/model-server.js +4 -2
- package/lib/model-server.js.map +1 -1
- package/lib/model-service/base-version.d.ts +67 -0
- package/lib/model-service/base-version.d.ts.map +1 -0
- package/lib/model-service/base-version.js +44 -0
- package/lib/model-service/base-version.js.map +1 -0
- package/lib/model-service/index.d.ts +1 -1
- package/lib/model-service/index.d.ts.map +1 -1
- package/lib/model-service/index.js +4 -5
- package/lib/model-service/index.js.map +1 -1
- package/lib/model-service/reference-candidate.d.ts +5 -3
- package/lib/model-service/reference-candidate.d.ts.map +1 -1
- package/lib/{model-service/args.js → node/index.d.ts} +2 -3
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +29 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/process-memory.d.ts +66 -0
- package/lib/node/process-memory.d.ts.map +1 -0
- package/lib/node/process-memory.js +291 -0
- package/lib/node/process-memory.js.map +1 -0
- package/lib/noop-logger.d.ts.map +1 -1
- package/lib/noop-logger.js.map +1 -1
- package/lib/observable-value.js.map +1 -1
- package/lib/patch-merge.d.ts +63 -35
- package/lib/patch-merge.d.ts.map +1 -1
- package/lib/patch-merge.js +171 -25
- package/lib/patch-merge.js.map +1 -1
- package/lib/profile-session.d.ts +8 -4
- package/lib/profile-session.d.ts.map +1 -1
- package/lib/profile-session.js.map +1 -1
- package/lib/project.d.ts +4 -1
- package/lib/project.d.ts.map +1 -1
- package/lib/project.js.map +1 -1
- package/lib/random-uuid.d.ts +14 -0
- package/lib/random-uuid.d.ts.map +1 -0
- package/lib/random-uuid.js +24 -0
- package/lib/random-uuid.js.map +1 -0
- package/lib/reconcile-write.d.ts +67 -0
- package/lib/reconcile-write.d.ts.map +1 -0
- package/lib/reconcile-write.js +69 -0
- package/lib/reconcile-write.js.map +1 -0
- package/lib/rpc/bind-rpc-methods.d.ts +33 -3
- package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
- package/lib/rpc/bind-rpc-methods.js +32 -3
- package/lib/rpc/bind-rpc-methods.js.map +1 -1
- package/lib/rpc/create-rpc-proxy.d.ts +10 -0
- package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
- package/lib/rpc/create-rpc-proxy.js +12 -2
- package/lib/rpc/create-rpc-proxy.js.map +1 -1
- package/lib/rpc/index.d.ts +1 -0
- package/lib/rpc/index.d.ts.map +1 -1
- package/lib/rpc/index.js +1 -0
- package/lib/rpc/index.js.map +1 -1
- package/lib/rpc/send-by-method-name.d.ts +76 -0
- package/lib/rpc/send-by-method-name.d.ts.map +1 -0
- package/lib/rpc/send-by-method-name.js +120 -0
- package/lib/rpc/send-by-method-name.js.map +1 -0
- package/lib/rpc/wire-prefix.js.map +1 -1
- package/lib/testing/catalogue-audit.d.ts +80 -0
- package/lib/testing/catalogue-audit.d.ts.map +1 -0
- package/lib/testing/catalogue-audit.js +94 -0
- package/lib/testing/catalogue-audit.js.map +1 -0
- package/lib/testing/data-doubles.d.ts +41 -12
- package/lib/testing/data-doubles.d.ts.map +1 -1
- package/lib/testing/data-doubles.js +56 -8
- package/lib/testing/data-doubles.js.map +1 -1
- package/lib/testing/fake-clock.d.ts +17 -2
- package/lib/testing/fake-clock.d.ts.map +1 -1
- package/lib/testing/fake-clock.js +61 -46
- package/lib/testing/fake-clock.js.map +1 -1
- package/lib/testing/index.d.ts +1 -0
- package/lib/testing/index.d.ts.map +1 -1
- package/lib/testing/index.js +5 -2
- package/lib/testing/index.js.map +1 -1
- package/lib/testing/node/duplex-connection.d.ts.map +1 -1
- package/lib/testing/node/duplex-connection.js +3 -2
- package/lib/testing/node/duplex-connection.js.map +1 -1
- package/lib/testing/node/duplex-stream.js.map +1 -1
- package/lib/testing/node/index.d.ts +1 -0
- package/lib/testing/node/index.d.ts.map +1 -1
- package/lib/testing/node/index.js +2 -2
- package/lib/testing/node/index.js.map +1 -1
- package/lib/testing/node/message-port-pair.d.ts +25 -0
- package/lib/testing/node/message-port-pair.d.ts.map +1 -0
- package/lib/testing/node/message-port-pair.js +26 -0
- package/lib/testing/node/message-port-pair.js.map +1 -0
- package/lib/testing/wait-for.d.ts +9 -3
- package/lib/testing/wait-for.d.ts.map +1 -1
- package/lib/testing/wait-for.js +57 -11
- package/lib/testing/wait-for.js.map +1 -1
- package/lib/tracer.d.ts.map +1 -1
- package/lib/tracer.js +5 -9
- package/lib/tracer.js.map +1 -1
- package/lib/transfer-diagnostic.js.map +1 -1
- package/lib/transfer-document.d.ts +95 -32
- package/lib/transfer-document.d.ts.map +1 -1
- package/lib/transfer-document.js +17 -9
- package/lib/transfer-document.js.map +1 -1
- package/lib/uri.d.ts.map +1 -1
- package/lib/uri.js.map +1 -1
- package/lib/util.d.ts +8 -2
- package/lib/util.d.ts.map +1 -1
- package/lib/util.js +32 -4
- package/lib/util.js.map +1 -1
- package/package.json +24 -40
- package/src/abstract-logger.ts +8 -0
- package/src/client/data-connection.ts +653 -0
- package/src/client/data-events.ts +37 -1
- package/src/client/data-port.ts +36 -25
- package/src/client/data-session.ts +1427 -137
- package/src/client/index.ts +15 -9
- package/src/client/message-relay.ts +4 -4
- package/src/client/post-message-transport.ts +219 -4
- package/src/client/rpc-connection.ts +281 -0
- package/src/client/worker-handshake.ts +98 -0
- package/src/client-ids.ts +49 -0
- package/src/clock.ts +68 -10
- package/src/console-logger.ts +39 -0
- package/src/data/data-protocol-methods.ts +14 -4
- package/src/data/data-server-protocol.ts +192 -48
- package/src/data/events.ts +143 -21
- package/src/data/requests.ts +77 -11
- package/src/debouncer.ts +7 -10
- package/src/errors.ts +309 -40
- package/src/glsp-request-model-args.ts +16 -0
- package/src/glsp-save-model-actions.ts +59 -0
- package/src/index.ts +6 -0
- package/src/latency-collector.ts +8 -3
- package/src/logger.ts +44 -8
- package/src/messages/index.ts +4 -2
- package/src/messages/primitives.ts +102 -10
- package/src/model-server.ts +64 -19
- package/src/model-service/base-version.ts +75 -0
- package/src/model-service/index.ts +4 -5
- package/src/model-service/reference-candidate.ts +5 -3
- package/src/node/index.ts +14 -0
- package/src/node/process-memory.ts +299 -0
- package/src/patch-merge.ts +230 -45
- package/src/profile-session.ts +9 -4
- package/src/project.ts +4 -1
- package/src/random-uuid.ts +21 -0
- package/src/reconcile-write.ts +128 -0
- package/src/rpc/README.md +6 -6
- package/src/rpc/bind-rpc-methods.ts +59 -4
- package/src/rpc/create-rpc-proxy.ts +20 -2
- package/src/rpc/index.ts +1 -0
- package/src/rpc/send-by-method-name.ts +140 -0
- package/src/testing/catalogue-audit.ts +111 -0
- package/src/testing/data-doubles.ts +141 -19
- package/src/testing/fake-clock.ts +76 -48
- package/src/testing/index.ts +5 -2
- package/src/testing/node/duplex-connection.ts +3 -2
- package/src/testing/node/index.ts +2 -2
- package/src/testing/node/message-port-pair.ts +40 -0
- package/src/testing/wait-for.ts +61 -13
- package/src/tracer.ts +5 -9
- package/src/transfer-document.ts +115 -34
- package/src/util.ts +33 -6
- package/lib/model-service/args.d.ts +0 -64
- package/lib/model-service/args.d.ts.map +0 -1
- package/lib/model-service/args.js.map +0 -1
- package/src/model-service/args.ts +0 -67
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,181 @@ 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
|
-
*
|
|
52
|
+
* - `no-op` — the user's root equals the base: nothing to replay, and no
|
|
53
|
+
* refetch; the caller's document is behind the server's.
|
|
53
54
|
* - `unavailable` — the refetch produced nothing; caller falls back.
|
|
54
|
-
* - `
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
55
|
+
* - `already-applied` — the refetch already holds the user's value at every
|
|
56
|
+
* path the user changed, and the user's whole array for a path through
|
|
57
|
+
* one; nothing is replayed.
|
|
58
|
+
* - `merged` — the foreign writer touched only paths the user did not, or
|
|
59
|
+
* made the user's change itself at a path through no array; the merged
|
|
60
|
+
* root carries both intents.
|
|
61
|
+
* - `conflict` — a same-path divergence tripped a `test` op, including the
|
|
62
|
+
* user's own value inside an array the refetch holds otherwise than the
|
|
63
|
+
* user; or an `add` collides with one the foreign writer made; or the
|
|
64
|
+
* foreign writer removed or replaced what the user edited inside. The
|
|
65
|
+
* caller drops the write and surfaces `theirs`.
|
|
58
66
|
*
|
|
59
67
|
* I/O is the caller's: `refetch` supplies the current root, and applying the
|
|
60
|
-
* `merged` result (update vs save,
|
|
68
|
+
* `merged` result (update vs save, new base, UI refresh) stays at the call
|
|
61
69
|
* site so form and GLSP paths keep their own persistence semantics.
|
|
62
70
|
*/
|
|
63
|
-
async function reconcileByPatchReplay(
|
|
64
|
-
const userPatch = (0, fast_json_patch_1.compare)(
|
|
71
|
+
async function reconcileByPatchReplay(base, ours, refetch) {
|
|
72
|
+
const userPatch = (0, fast_json_patch_1.compare)(base, ours);
|
|
65
73
|
if (userPatch.length === 0) {
|
|
66
74
|
return { status: 'no-op' };
|
|
67
75
|
}
|
|
68
|
-
const
|
|
69
|
-
if (!
|
|
76
|
+
const theirs = await refetch();
|
|
77
|
+
if (!theirs) {
|
|
70
78
|
return { status: 'unavailable' };
|
|
71
79
|
}
|
|
80
|
+
const comparable = toJson(theirs);
|
|
81
|
+
const pending = withoutAgreed(base, ours, comparable, userPatch);
|
|
82
|
+
if (pending.length === 0) {
|
|
83
|
+
return { status: 'already-applied', theirs };
|
|
84
|
+
}
|
|
85
|
+
if (addsCollide(base, comparable, pending)) {
|
|
86
|
+
return { status: 'conflict', theirs };
|
|
87
|
+
}
|
|
72
88
|
try {
|
|
73
|
-
const merged = (0, fast_json_patch_1.applyPatch)((0, fast_json_patch_1.deepClone)(
|
|
89
|
+
const merged = (0, fast_json_patch_1.applyPatch)((0, fast_json_patch_1.deepClone)(theirs), augmentWithTestOps(base, pending), true).newDocument;
|
|
74
90
|
return { status: 'merged', merged };
|
|
75
91
|
}
|
|
76
92
|
catch {
|
|
77
|
-
return { status: 'conflict',
|
|
93
|
+
return { status: 'conflict', theirs };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* `userPatch` without the ops `theirs` already agrees with: a `replace` or
|
|
98
|
+
* object-key `add` whose key the object at its parent path holds at the
|
|
99
|
+
* user's value, a `remove` whose key that object lacks. A parent that is
|
|
100
|
+
* absent or no object agrees with nothing: a foreign writer deleted or
|
|
101
|
+
* replaced what the user edited inside, or a refetch omitted a document it
|
|
102
|
+
* could not read.
|
|
103
|
+
*
|
|
104
|
+
* Ops address array elements by index, so an op through an array agrees only
|
|
105
|
+
* when that array, the outermost on its path, equals the user's: matching one
|
|
106
|
+
* index of an array that shifted would drop the user's edit to another
|
|
107
|
+
* element. An insert never agrees, as {@link addsCollide} keeps two equal
|
|
108
|
+
* additions apart, and neither does any op through its array, or replaying
|
|
109
|
+
* the insert alone would add its element a second time. Each array is
|
|
110
|
+
* compared once, however many ops run through it and however many arrays the
|
|
111
|
+
* patch inserts into, so a bulk edit stays linear.
|
|
112
|
+
*
|
|
113
|
+
* `theirs` is the refetch through {@link toJson}.
|
|
114
|
+
*/
|
|
115
|
+
function withoutAgreed(base, ours, theirs, userPatch) {
|
|
116
|
+
const jsonOurs = toJson(ours);
|
|
117
|
+
// An insert is keyed by the outermost array on its path, as every op is looked up, so one set answers for every array.
|
|
118
|
+
const insertedArrays = new Set(userPatch
|
|
119
|
+
.filter(op => op.op === 'add' && Array.isArray(valueAt(base, op.path.slice(0, op.path.lastIndexOf('/')))))
|
|
120
|
+
.map(op => outermostArrayOn(jsonOurs, op.path)));
|
|
121
|
+
const arrayAgrees = new Map();
|
|
122
|
+
return userPatch.filter(op => {
|
|
123
|
+
const array = outermostArrayOn(jsonOurs, op.path);
|
|
124
|
+
if (array !== undefined) {
|
|
125
|
+
let agrees = arrayAgrees.get(array);
|
|
126
|
+
if (agrees === undefined) {
|
|
127
|
+
agrees = !insertedArrays.has(array) && (0, fast_json_patch_1._areEquals)(valueAt(theirs, array), valueAt(jsonOurs, array));
|
|
128
|
+
arrayAgrees.set(array, agrees);
|
|
129
|
+
}
|
|
130
|
+
return !agrees;
|
|
131
|
+
}
|
|
132
|
+
const cut = op.path.lastIndexOf('/');
|
|
133
|
+
const parent = valueAt(theirs, op.path.slice(0, cut));
|
|
134
|
+
if (typeof parent !== 'object' || parent === null || Array.isArray(parent)) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
const key = (0, fast_json_patch_1.unescapePathComponent)(op.path.slice(cut + 1));
|
|
138
|
+
if (op.op === 'remove') {
|
|
139
|
+
return Object.hasOwn(parent, key);
|
|
140
|
+
}
|
|
141
|
+
if (op.op !== 'replace' && op.op !== 'add') {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
return !Object.hasOwn(parent, key) || !(0, fast_json_patch_1._areEquals)(Reflect.get(parent, key), op.value);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** The outermost array a step of `pointer` before its last runs through in `document`, as a pointer; `undefined` for none. */
|
|
148
|
+
function outermostArrayOn(document, pointer) {
|
|
149
|
+
const steps = pointer.split('/');
|
|
150
|
+
for (let i = 1; i < steps.length; i++) {
|
|
151
|
+
const prefix = steps.slice(0, i).join('/');
|
|
152
|
+
if (Array.isArray(valueAt(document, prefix))) {
|
|
153
|
+
return prefix;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* `value` through JSON, as `compare` clones the values it diffs: an
|
|
160
|
+
* undefined-valued key would otherwise make two equal values differ.
|
|
161
|
+
*/
|
|
162
|
+
function toJson(value) {
|
|
163
|
+
return JSON.parse(JSON.stringify(value));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Whether an `add` of `userPatch` collides with one the foreign writer made:
|
|
167
|
+
* it inserts a value into an array that `theirs` holds more often than
|
|
168
|
+
* `base` did, or it adds an object key that `theirs` already holds, at
|
|
169
|
+
* another value once `withoutAgreed` has dropped the equal ones.
|
|
170
|
+
*
|
|
171
|
+
* Replayed, the first inserts the value a second time and the second replaces
|
|
172
|
+
* the foreign value. Identical array elements conflict rather than being
|
|
173
|
+
* skipped: skipping drops one of two insertions that merely happen to be
|
|
174
|
+
* equal. `theirs` is the refetch through {@link toJson}.
|
|
175
|
+
*/
|
|
176
|
+
function addsCollide(base, theirs, userPatch) {
|
|
177
|
+
// Each array's elements are counted once, however many ops insert into it, so a bulk insert stays linear.
|
|
178
|
+
const tallies = new Map();
|
|
179
|
+
return userPatch.some(op => {
|
|
180
|
+
if (op.op !== 'add') {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
const cut = op.path.lastIndexOf('/');
|
|
184
|
+
const parent = op.path.slice(0, cut);
|
|
185
|
+
const before = valueAt(base, parent);
|
|
186
|
+
const now = valueAt(theirs, parent);
|
|
187
|
+
if (Array.isArray(before)) {
|
|
188
|
+
if (!Array.isArray(now)) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
let tally = tallies.get(parent);
|
|
192
|
+
if (!tally) {
|
|
193
|
+
tally = { before: tallyElements(before), now: tallyElements(now) };
|
|
194
|
+
tallies.set(parent, tally);
|
|
195
|
+
}
|
|
196
|
+
const key = canonicalJson(op.value);
|
|
197
|
+
return (tally.now.get(key) ?? 0) > (tally.before.get(key) ?? 0);
|
|
198
|
+
}
|
|
199
|
+
return typeof now === 'object' && now !== null && Object.hasOwn(now, (0, fast_json_patch_1.unescapePathComponent)(op.path.slice(cut + 1)));
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/** How many elements of `array` there are of each value, keyed by {@link canonicalJson}. */
|
|
203
|
+
function tallyElements(array) {
|
|
204
|
+
const tally = new Map();
|
|
205
|
+
for (const element of array) {
|
|
206
|
+
const key = canonicalJson(element);
|
|
207
|
+
tally.set(key, (tally.get(key) ?? 0) + 1);
|
|
208
|
+
}
|
|
209
|
+
return tally;
|
|
210
|
+
}
|
|
211
|
+
/** `value` as JSON with every object's keys sorted, so two deeply equal values give one string whatever their key order. */
|
|
212
|
+
function canonicalJson(value) {
|
|
213
|
+
return JSON.stringify(value, (_key, nested) => typeof nested === 'object' && nested !== null && !Array.isArray(nested)
|
|
214
|
+
? Object.fromEntries(Object.entries(nested).sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0)))
|
|
215
|
+
: nested);
|
|
216
|
+
}
|
|
217
|
+
/** The value at `pointer`, or `undefined` when a step of it is missing. */
|
|
218
|
+
function valueAt(document, pointer) {
|
|
219
|
+
try {
|
|
220
|
+
return (0, fast_json_patch_1.getValueByPointer)(document, pointer);
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
return undefined;
|
|
78
224
|
}
|
|
79
225
|
}
|
|
80
226
|
/**
|
|
@@ -84,20 +230,20 @@ async function reconcileByPatchReplay(baseline, attempted, refetch) {
|
|
|
84
230
|
* clobbered.
|
|
85
231
|
*/
|
|
86
232
|
class ReconcilingConflictResolver {
|
|
87
|
-
resolve(
|
|
88
|
-
return reconcileByPatchReplay(
|
|
233
|
+
resolve(base, ours, refetch) {
|
|
234
|
+
return reconcileByPatchReplay(base, ours, refetch);
|
|
89
235
|
}
|
|
90
236
|
}
|
|
91
237
|
exports.ReconcilingConflictResolver = ReconcilingConflictResolver;
|
|
92
238
|
/**
|
|
93
|
-
* Last-writer-wins {@link ConflictResolver}: always reports the `
|
|
239
|
+
* Last-writer-wins {@link ConflictResolver}: always reports the `ours`
|
|
94
240
|
* state as merged, without refetching or guarding. Suitable for single-client
|
|
95
241
|
* tools or always-regenerated artifacts where a concurrent foreign edit may be
|
|
96
242
|
* overwritten. A foreign edit to any field is clobbered.
|
|
97
243
|
*/
|
|
98
244
|
class ForceConflictResolver {
|
|
99
|
-
async resolve(
|
|
100
|
-
return { status: 'merged', merged:
|
|
245
|
+
async resolve(_base, ours, _refetch) {
|
|
246
|
+
return { status: 'merged', merged: ours };
|
|
101
247
|
}
|
|
102
248
|
}
|
|
103
249
|
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;;;;;AAElF,qDAQyB;AAEzB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,4BAAmC,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,KAAK,EAAE,IAAA,mCAAiB,EAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1F,CAAC;QACD,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC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CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAClH,CAAC,CAAC,MAAM,CACb,CAAC;AACL,CAAC;AAED,2EAA2E;AAC3E,SAAS,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;IACG,OAAO,CAAmB,IAAO,EAAE,IAAO,EAAE,OAAqC;QAC9E,OAAO,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;CACH;;AAED;;;;;GAKG;AACH;IACG,KAAK,CAAC,OAAO,CAAmB,KAAQ,EAAE,IAAO,EAAE,QAAsC;QACtF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC7C,CAAC;CACH"}
|
package/lib/profile-session.d.ts
CHANGED
|
@@ -56,7 +56,12 @@ export interface ProfileSession {
|
|
|
56
56
|
/** The same aggregate as structured records, for tests / programmatic use. */
|
|
57
57
|
records(): readonly ProfileRecord[];
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
/**
|
|
60
|
+
* One in-flight {@link ProfileSession.scope} call. Held on the `protected`
|
|
61
|
+
* {@link DefaultProfileSession.stack} and named by
|
|
62
|
+
* {@link DefaultProfileSession.closeFrame}, so a subclass has to name it too.
|
|
63
|
+
*/
|
|
64
|
+
export interface ProfileScopeFrame {
|
|
60
65
|
readonly id: string;
|
|
61
66
|
/** Session-stopwatch reading when this scope began. */
|
|
62
67
|
readonly start: number;
|
|
@@ -73,15 +78,14 @@ export declare class DefaultProfileSession implements ProfileSession {
|
|
|
73
78
|
protected readonly identifier: string;
|
|
74
79
|
/** Single monotonic timeline for the whole session; per-scope readings are deltas off it. */
|
|
75
80
|
protected readonly sessionStopwatch: Stopwatch;
|
|
76
|
-
protected readonly stack:
|
|
81
|
+
protected readonly stack: ProfileScopeFrame[];
|
|
77
82
|
protected readonly entries: Map<string, number[]>;
|
|
78
83
|
constructor(logger: Logger, clock: Clock, identifier: string);
|
|
79
84
|
scope<T>(id: string, fn: () => Promise<T>): Promise<T>;
|
|
80
85
|
scope<T>(id: string, fn: () => T): T;
|
|
81
86
|
/** Pop `frame`, charge its full duration to the parent, and record its self-time. */
|
|
82
|
-
protected closeFrame(frame:
|
|
87
|
+
protected closeFrame(frame: ProfileScopeFrame): void;
|
|
83
88
|
records(): readonly ProfileRecord[];
|
|
84
89
|
report(logLevel?: LogThreshold): void;
|
|
85
90
|
}
|
|
86
|
-
export {};
|
|
87
91
|
//# sourceMappingURL=profile-session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile-session.d.ts","sourceRoot":"","sources":["../src/profile-session.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAU,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7D,iFAAiF;AACjF,MAAM,WAAW,aAAa;IAC3B,2DAA2D;IAC3D,EAAE,EAAE,MAAM,CAAC;IACX,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,OAAO,EA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ot":"","sources":["../src/profile-session.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAGlF,qCAA6D;
|
|
1
|
+
{"version":3,"file":"profile-session.js","sourceRoot":"","sources":["../src/profile-session.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAGlF,qCAA6D;AAmE7D;;;;GAIG;AACH;IAOyB,MAAM;IAEN,UAAU;IARhC,6FAA6F;IAC1E,gBAAgB,CAAY;IAC5B,KAAK,GAAwB,EAAE,CAAC;IAChC,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEzD,YACsB,MAAc,EACjC,KAAY,EACO,UAAkB;sBAFlB,MAAM;0BAEN,UAAU;QAE7B,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;IAC7C,CAAC;IAID,KAAK,CAAI,EAAU,EAAE,EAAwB;QAC1C,MAAM,KAAK,GAAsB,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;QAC5F,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,IAAI,MAAsB,CAAC;QAC3B,IAAI,CAAC;YACF,MAAM,GAAG,EAAE,EAAE,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACd,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACvB,MAAM,KAAK,CAAC;QACf,CAAC;QACD,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;YAC7B,OAAO,MAAM,CAAC,IAAI,CACf,KAAK,CAAC,EAAE;gBACL,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;gBACvB,OAAO,KAAK,CAAC;YAChB,CAAC,EACD,KAAK,CAAC,EAAE;gBACL,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;gBACvB,MAAM,KAAK,CAAC;YACf,CAAC,CACH,CAAC;QACL,C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AAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,aAAa,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1E,IAAI,CAAC,YAAY,IAAI,CAAC,UAAU,mBAAmB,GAAG,KAAK,eAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QAC/F,CAAC;IACJ,CAAC;CACH"}
|
package/lib/project.d.ts
CHANGED
|
@@ -39,7 +39,10 @@
|
|
|
39
39
|
* adopter-specific extension carried transparently through the typed
|
|
40
40
|
* surface. The framework imposes no format on extension fields — they
|
|
41
41
|
* ride on the JSON-RPC envelope as additional properties when crossing
|
|
42
|
-
* the wire.
|
|
42
|
+
* the wire. A client receives a project's own enumerable fields as JSON: a
|
|
43
|
+
* getter or a method does not cross, and a class instance in a field arrives
|
|
44
|
+
* as a plain object, so the project type a client protocol declares holds the
|
|
45
|
+
* data fields alone.
|
|
43
46
|
*/
|
|
44
47
|
export interface Project {
|
|
45
48
|
/**
|
package/lib/project.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,WAAW,OAAO;IACrB;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAE/B;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;;;;OAOG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,6BAA6B,KAAK,CAAC"}
|
package/lib/project.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAmGlF;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,6BAA6B,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
/**
|
|
10
|
+
* A random v4 UUID. Not `crypto.randomUUID`: a browser offers it only in a
|
|
11
|
+
* secure context, and a client may be served over plain HTTP.
|
|
12
|
+
*/
|
|
13
|
+
export declare function randomUuid(): string;
|
|
14
|
+
//# sourceMappingURL=random-uuid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-uuid.d.ts","sourceRoot":"","sources":["../src/random-uuid.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAOnC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the MIT License which is available in the project root.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
********************************************************************************/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.randomUuid = randomUuid;
|
|
12
|
+
/**
|
|
13
|
+
* A random v4 UUID. Not `crypto.randomUUID`: a browser offers it only in a
|
|
14
|
+
* secure context, and a client may be served over plain HTTP.
|
|
15
|
+
*/
|
|
16
|
+
function randomUuid() {
|
|
17
|
+
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
|
|
18
|
+
// Version 4, RFC 4122 variant.
|
|
19
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
20
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
21
|
+
const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('');
|
|
22
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=random-uuid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-uuid.js","sourceRoot":"","sources":["../src/random-uuid.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAElF;;;GAGG;AACH;IACG,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IACpE,+BAA+B;IAC/B,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACpC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACpC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnF,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;AAC9G,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
import { type ConflictError } from './errors';
|
|
10
|
+
import { type BaseVersion, type ModelVersion } from './model-service/base-version';
|
|
11
|
+
import { type ConflictResolver } from './patch-merge';
|
|
12
|
+
/** A model and the version of the text it was read from, which a write based on it names. */
|
|
13
|
+
export interface VersionedModel<TModel> {
|
|
14
|
+
readonly model: TModel;
|
|
15
|
+
readonly baseVersion: ModelVersion;
|
|
16
|
+
}
|
|
17
|
+
/** The I/O and policy a {@link reconcileWrite} call needs. */
|
|
18
|
+
export interface ReconcileWriteHooks<TModel> {
|
|
19
|
+
/**
|
|
20
|
+
* Write `model`. Called with the caller's own `baseVersion` first, with the
|
|
21
|
+
* refetch's on a merged write, and with `'any'` for a merge that refetched
|
|
22
|
+
* nothing, where the resolver has already decided to win.
|
|
23
|
+
*/
|
|
24
|
+
persist(model: TModel, baseVersion: BaseVersion): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Current server-side model, or `undefined` when unavailable. Its version is
|
|
27
|
+
* read in the tick its text is: a later one lets a merged write overwrite an
|
|
28
|
+
* edit the merge never saw.
|
|
29
|
+
*/
|
|
30
|
+
refetch(): Promise<VersionedModel<TModel> | undefined>;
|
|
31
|
+
/** The last in-sync model the user's intent is measured against. */
|
|
32
|
+
readonly base: TModel;
|
|
33
|
+
readonly conflictResolver: ConflictResolver;
|
|
34
|
+
/** Writes, the first included, after which a still-conflicting edit is dropped; 3 when absent. */
|
|
35
|
+
readonly maxWrites?: number;
|
|
36
|
+
/** Runs when the refetch is unavailable; absent, the edit is left unwritten. */
|
|
37
|
+
onUnavailable?(model: TModel, conflict: ConflictError): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What {@link reconcileWrite} did. Every status but `persisted` follows a
|
|
41
|
+
* conflict, and carries the last one and the writes made, the first included.
|
|
42
|
+
*/
|
|
43
|
+
export type ReconcileWriteOutcome =
|
|
44
|
+
/** The first write landed. */
|
|
45
|
+
{
|
|
46
|
+
readonly status: 'persisted';
|
|
47
|
+
} | {
|
|
48
|
+
/**
|
|
49
|
+
* `merged`: a merged write landed. `already-applied`: the refetch
|
|
50
|
+
* already held the edit, so nothing more was written. `unchanged`: the
|
|
51
|
+
* edit was empty, so the caller is behind the server. `conflict`: the
|
|
52
|
+
* resolver found a same-path collision. `dropped`: the writes ran out.
|
|
53
|
+
* `unavailable`: the refetch produced nothing and
|
|
54
|
+
* {@link ReconcileWriteHooks.onUnavailable} ran.
|
|
55
|
+
*/
|
|
56
|
+
readonly status: 'merged' | 'already-applied' | 'unchanged' | 'conflict' | 'dropped' | 'unavailable';
|
|
57
|
+
readonly conflict: ConflictError;
|
|
58
|
+
readonly writes: number;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Persist `model`, and on a `ConflictError` reconcile the user's `base → model`
|
|
62
|
+
* intent onto the refetched server model and write the merge, gated on the
|
|
63
|
+
* refetch's version, again on each conflict up to `maxWrites` writes. A
|
|
64
|
+
* non-conflict error is re-thrown.
|
|
65
|
+
*/
|
|
66
|
+
export declare function reconcileWrite<TModel extends object>(model: TModel, baseVersion: BaseVersion, hooks: ReconcileWriteHooks<TModel>): Promise<ReconcileWriteOutcome>;
|
|
67
|
+
//# sourceMappingURL=reconcile-write.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile-write.d.ts","sourceRoot":"","sources":["../src/reconcile-write.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAItD,6FAA6F;AAC7F,MAAM,WAAW,cAAc,CAAC,MAAM;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;CACrC;AAED,8DAA8D;AAC9D,MAAM,WAAW,mBAAmB,CAAC,MAAM;IACxC;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE;;;;OAIG;IACH,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC;IACvD,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,kGAAkG;IAClG,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,gFAAgF;IAChF,aAAa,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxE;AAED;;;GAGG;AACH,MAAM,MAAM,qBAAqB;AAC9B,8BAA8B;AAC5B;IAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GAChC;IACG;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,iBAAiB,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,aAAa,CAAC;IACrG,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEP;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,MAAM,SAAS,MAAM,EACvD,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAClC,OAAO,CAAC,qBAAqB,CAAC,CAmChC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the MIT License which is available in the project root.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
********************************************************************************/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.reconcileWrite = reconcileWrite;
|
|
12
|
+
const errors_1 = require("./errors");
|
|
13
|
+
const DEFAULT_MAX_WRITES = 3;
|
|
14
|
+
/**
|
|
15
|
+
* Persist `model`, and on a `ConflictError` reconcile the user's `base → model`
|
|
16
|
+
* intent onto the refetched server model and write the merge, gated on the
|
|
17
|
+
* refetch's version, again on each conflict up to `maxWrites` writes. A
|
|
18
|
+
* non-conflict error is re-thrown.
|
|
19
|
+
*/
|
|
20
|
+
async function reconcileWrite(model, baseVersion, hooks) {
|
|
21
|
+
let candidate = model;
|
|
22
|
+
let candidateBaseVersion = baseVersion;
|
|
23
|
+
let previous;
|
|
24
|
+
const maxWrites = hooks.maxWrites ?? DEFAULT_MAX_WRITES;
|
|
25
|
+
for (let writes = 1;; writes++) {
|
|
26
|
+
const conflict = await persistOrConflict(hooks, candidate, candidateBaseVersion);
|
|
27
|
+
if (!conflict) {
|
|
28
|
+
return previous ? { status: 'merged', conflict: previous, writes } : { status: 'persisted' };
|
|
29
|
+
}
|
|
30
|
+
previous = conflict;
|
|
31
|
+
if (writes >= maxWrites) {
|
|
32
|
+
return { status: 'dropped', conflict, writes };
|
|
33
|
+
}
|
|
34
|
+
let refetched;
|
|
35
|
+
const outcome = await hooks.conflictResolver.resolve(hooks.base, model, async () => {
|
|
36
|
+
refetched = await hooks.refetch();
|
|
37
|
+
return refetched?.model;
|
|
38
|
+
});
|
|
39
|
+
switch (outcome.status) {
|
|
40
|
+
case 'merged':
|
|
41
|
+
candidate = outcome.merged;
|
|
42
|
+
candidateBaseVersion = refetched?.baseVersion ?? 'any';
|
|
43
|
+
continue;
|
|
44
|
+
case 'already-applied':
|
|
45
|
+
return { status: 'already-applied', conflict, writes };
|
|
46
|
+
case 'no-op':
|
|
47
|
+
return { status: 'unchanged', conflict, writes };
|
|
48
|
+
case 'conflict':
|
|
49
|
+
return { status: 'conflict', conflict, writes };
|
|
50
|
+
case 'unavailable':
|
|
51
|
+
await hooks.onUnavailable?.(model, conflict);
|
|
52
|
+
return { status: 'unavailable', conflict, writes };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** The `ConflictError` the write raised, or `undefined` when it landed. */
|
|
57
|
+
async function persistOrConflict(hooks, model, baseVersion) {
|
|
58
|
+
try {
|
|
59
|
+
await hooks.persist(model, baseVersion);
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
if (!(0, errors_1.isConflictError)(err)) {
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
return err;
|
|
67
|
+
}
|
|
68
|
+
}
|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CAAC;QACH,QAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;YACtB,KAAK,QAAQ;gBACV,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;gBAC3B,oBAAoB,GAAG,SAAS,EAAE,WAAW,IAAI,KAAK,CAAC;gBACvD,SAAS;YACZ,KAAK,iBAAiB;gBACnB,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;YAC1D,KAAK,OAAO;gBACT,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;YACpD,KAAK,UAAU;gBACZ,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;YACnD,KAAK,aAAa;gBACf,MAAM,KAAK,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;gBAC7C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;QACzD,CAAC;IACJ,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,KAAK,UAAU,iBAAiB,CAC7B,KAAkC,EAClC,KAAa,EACb,WAAwB;IAExB,IAAI,CAAC;QACF,MAAM,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACxC,OAAO,SAAS,CAAC;IACpB,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACrB,IAAI,CAAC,IAAA,wBAAe,EAAC,GAAG,CAAC,EAAE,CAAC;YACzB,MAAM,GAAG,CAAC;QACb,CAAC;QACD,OAAO,GAAG,CAAC;IACd,CAAC;AACJ,CAAC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
|
-
import type
|
|
9
|
+
import { ResponseError, type MessageConnection } from 'vscode-jsonrpc';
|
|
10
10
|
import type { LatencyCollector } from '../latency-collector';
|
|
11
11
|
import { type Disposable } from '../util';
|
|
12
12
|
/**
|
|
@@ -62,6 +62,30 @@ export interface BindRpcMethodsOptions {
|
|
|
62
62
|
* Requests and notifications are both timed. Absent by default (no overhead).
|
|
63
63
|
*/
|
|
64
64
|
readonly latency?: LatencyCollector;
|
|
65
|
+
/**
|
|
66
|
+
* Produce the `message` an outgoing rejection carries, so a user-facing
|
|
67
|
+
* error is rendered by the side that knows the reading user's language.
|
|
68
|
+
* Applied at this one chokepoint, which is what covers a caller's
|
|
69
|
+
* additional methods as well as the framework's own.
|
|
70
|
+
*
|
|
71
|
+
* Only a `ResponseError` is routed through it — a plain `Error` carries no
|
|
72
|
+
* identity to render from, and rewriting its message would relabel a
|
|
73
|
+
* developer-facing failure as a translated one. The rejection is
|
|
74
|
+
* RECONSTRUCTED rather than mutated, because the thrown value may be a
|
|
75
|
+
* shared constant; nothing is lost, since only `code`, `message` and `data`
|
|
76
|
+
* cross the wire and `instanceof` does not survive reconstruction anyway.
|
|
77
|
+
*
|
|
78
|
+
* Notifications are not covered, and "they have no reply channel" is only
|
|
79
|
+
* half the reason — a notification's own PAYLOAD can carry prose. What makes
|
|
80
|
+
* this sound is where that prose comes from: the only user-facing text on
|
|
81
|
+
* the data head's client surface is the diagnostics riding the
|
|
82
|
+
* document-updated and document-saved events, and those are read off
|
|
83
|
+
* `LangiumDocument.diagnostics`, which the document builder has already
|
|
84
|
+
* rendered at `Validated`. So they arrive rendered rather than escaping
|
|
85
|
+
* unrendered. A notification that ever carries prose of its OWN needs its
|
|
86
|
+
* own render at the raise site, as GLSP's actions do.
|
|
87
|
+
*/
|
|
88
|
+
readonly renderErrorMessage?: (error: ResponseError<unknown>) => string;
|
|
65
89
|
}
|
|
66
90
|
/**
|
|
67
91
|
* Register each named method on `target` as a handler on `connection`
|
|
@@ -82,8 +106,14 @@ export interface BindRpcMethodsOptions {
|
|
|
82
106
|
*
|
|
83
107
|
* Errors thrown synchronously from a request handler — or surfaced as a
|
|
84
108
|
* rejected promise — propagate back to the caller through vscode-jsonrpc's
|
|
85
|
-
* standard error envelope
|
|
86
|
-
*
|
|
109
|
+
* standard error envelope, its message rendered when
|
|
110
|
+
* {@link BindRpcMethodsOptions.renderErrorMessage} is supplied. A
|
|
111
|
+
* `ResponseError` from another copy of `vscode-jsonrpc` is rebuilt on this
|
|
112
|
+
* package's copy, so its code and data reach the caller when `connection` comes
|
|
113
|
+
* from that copy too, as the framework's own connections do; over a connection
|
|
114
|
+
* from another copy the caller receives a generic `InternalError`. Errors from a
|
|
115
|
+
* notification handler cannot propagate, and are routed to
|
|
116
|
+
* {@link BindRpcMethodsOptions.onNotificationError} instead.
|
|
87
117
|
*
|
|
88
118
|
* Accepts either a ready connection or a `Promise<MessageConnection>` —
|
|
89
119
|
* registrations queue until the connection resolves, then attach. The
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind-rpc-methods.d.ts","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,
|
|
1
|
+
{"version":3,"file":"bind-rpc-methods.d.ts","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,KAAK,UAAU,EAAwB,MAAM,SAAS,CAAC;AAIhE;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAqB;IACnC;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAElC;;;;;;OAMG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;IAE1D;;;;;;;;;OASG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,O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