@hydranium/protocol 1.0.0-next.22 → 1.0.0-next.220
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 +39 -3
- 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 +157 -0
- package/lib/client/data-connection.d.ts.map +1 -0
- package/lib/client/data-connection.js +237 -0
- package/lib/client/data-connection.js.map +1 -0
- package/lib/client/data-events.d.ts +13 -1
- package/lib/client/data-events.d.ts.map +1 -1
- package/lib/client/data-events.js +21 -0
- package/lib/client/data-events.js.map +1 -1
- package/lib/client/data-port.d.ts +24 -22
- package/lib/client/data-port.d.ts.map +1 -1
- package/lib/client/data-session.d.ts +471 -81
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +738 -108
- package/lib/client/data-session.js.map +1 -1
- package/lib/client/index.d.ts +14 -9
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +14 -9
- package/lib/client/index.js.map +1 -1
- package/lib/client/message-relay.d.ts +9 -3
- package/lib/client/message-relay.d.ts.map +1 -1
- package/lib/client/message-relay.js +11 -5
- 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 +149 -0
- package/lib/client/rpc-connection.d.ts.map +1 -0
- package/lib/client/rpc-connection.js +202 -0
- package/lib/client/rpc-connection.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 +38 -0
- 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 +12 -1
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +132 -41
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/events.d.ts +117 -21
- package/lib/data/events.d.ts.map +1 -1
- package/lib/data/requests.d.ts +69 -11
- package/lib/data/requests.d.ts.map +1 -1
- package/lib/debouncer.d.ts.map +1 -1
- package/lib/debouncer.js.map +1 -1
- package/lib/errors.d.ts +187 -29
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +270 -29
- 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 +7 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +10 -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 +22 -1
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +31 -3
- package/lib/logger.js.map +1 -1
- package/lib/messages/index.d.ts +29 -0
- package/lib/messages/index.d.ts.map +1 -0
- package/lib/messages/index.js +59 -0
- package/lib/messages/index.js.map +1 -0
- package/lib/messages/primitives.d.ts +188 -0
- package/lib/messages/primitives.d.ts.map +1 -0
- package/lib/messages/primitives.js +161 -0
- package/lib/messages/primitives.js.map +1 -0
- 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 +64 -0
- package/lib/model-service/base-version.d.ts.map +1 -0
- package/lib/model-service/base-version.js +43 -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 +35 -32
- package/lib/patch-merge.d.ts.map +1 -1
- package/lib/patch-merge.js +67 -23
- 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/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 +65 -0
- package/lib/reconcile-write.d.ts.map +1 -0
- package/lib/reconcile-write.js +67 -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 +39 -15
- package/lib/testing/data-doubles.d.ts.map +1 -1
- package/lib/testing/data-doubles.js +57 -10
- package/lib/testing/data-doubles.js.map +1 -1
- package/lib/testing/fake-clock.d.ts +9 -1
- package/lib/testing/fake-clock.d.ts.map +1 -1
- package/lib/testing/fake-clock.js +54 -45
- 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.js.map +1 -1
- package/lib/tracer.d.ts.map +1 -1
- package/lib/tracer.js.map +1 -1
- package/lib/transfer-diagnostic.d.ts +33 -0
- package/lib/transfer-diagnostic.d.ts.map +1 -1
- package/lib/transfer-diagnostic.js +23 -0
- package/lib/transfer-diagnostic.js.map +1 -1
- package/lib/transfer-document.d.ts +70 -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 -0
- package/lib/util.d.ts.map +1 -1
- package/lib/util.js +32 -0
- package/lib/util.js.map +1 -1
- package/package.json +29 -37
- package/src/abstract-logger.ts +8 -0
- package/src/client/data-connection.ts +315 -0
- package/src/client/data-events.ts +33 -1
- package/src/client/data-port.ts +25 -23
- package/src/client/data-session.ts +946 -126
- package/src/client/index.ts +14 -9
- package/src/client/message-relay.ts +29 -7
- package/src/client/post-message-transport.ts +219 -4
- package/src/client/rpc-connection.ts +268 -0
- package/src/client-ids.ts +49 -0
- package/src/clock.ts +56 -0
- package/src/console-logger.ts +39 -0
- package/src/data/data-protocol-methods.ts +13 -4
- package/src/data/data-server-protocol.ts +157 -41
- package/src/data/events.ts +123 -21
- package/src/data/requests.ts +74 -11
- package/src/errors.ts +322 -36
- package/src/glsp-request-model-args.ts +16 -0
- package/src/glsp-save-model-actions.ts +59 -0
- package/src/index.ts +10 -0
- package/src/latency-collector.ts +8 -3
- package/src/logger.ts +28 -2
- package/src/messages/index.ts +36 -0
- package/src/messages/primitives.ts +271 -0
- package/src/model-server.ts +63 -18
- package/src/model-service/base-version.ts +72 -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 +97 -42
- package/src/profile-session.ts +9 -4
- package/src/random-uuid.ts +21 -0
- package/src/reconcile-write.ts +124 -0
- package/src/rpc/README.md +2 -3
- 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 -25
- package/src/testing/fake-clock.ts +62 -47
- 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/transfer-diagnostic.ts +40 -0
- package/src/transfer-document.ts +87 -34
- package/src/util.ts +33 -0
- 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,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
|
-
*
|
|
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
|
* - `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;;;;;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,IA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AO,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,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,cAAc;IAC5B;;;;;;;OAOG;IACH,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvD,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAErC;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,EAAE,YAAY,GAAG,IA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SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAEjC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM;IARxC,6FAA6F;IAC7F,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,SAAS,CAAC;IAC/C,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,iBAAiB,EAAE,CAAM;IACnD,SAAS,CAAC,QAAQ,CAAC,OAAO,wBAA+B;IAEzD,YACsB,MAAM,EAAE,MAAM,EACjC,KAAK,EAAE,KAAK,EACO,UAAU,EAAE,MAAM,EAGvC;IAED,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvD,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IA2BrC,qFAAqF;IACrF,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAcnD;IAED,OAAO,IAAI,SAAS,aAAa,EAAE,CAQlC;IAED,MAAM,CAAC,QAAQ,GAAE,YAAsB,GAAG,IAAI,CAgB7C;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile-session.js","sourceRoot":"","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,EAC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eAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1D,OAAO;QACV,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC;QAChD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC5B,IAAI,CAAC,YAAY,IAAI,CAAC,UAAU,KAAK,MAAM,CAAC,EAAE,KAAK,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,eAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACtI,CAAC;QACD,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC5E,MAAM,aAAa,GAAG,OAAO,GAAG,WAAW,CAAC;QAC5C,IAAI,aAAa,IAAI,GAAG,EAAE,CAAC;YACxB,MAAM,GAAG,GAAG,OAAO,GAAG,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"}
|
|
@@ -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,65 @@
|
|
|
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. `unchanged`: the edit was empty, so the
|
|
50
|
+
* caller is behind the server. `conflict`: the resolver found a same-path
|
|
51
|
+
* collision. `dropped`: the writes ran out. `unavailable`: the refetch
|
|
52
|
+
* produced nothing and {@link ReconcileWriteHooks.onUnavailable} ran.
|
|
53
|
+
*/
|
|
54
|
+
readonly status: 'merged' | 'unchanged' | 'conflict' | 'dropped' | 'unavailable';
|
|
55
|
+
readonly conflict: ConflictError;
|
|
56
|
+
readonly writes: number;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Persist `model`, and on a `ConflictError` reconcile the user's `base → model`
|
|
60
|
+
* intent onto the refetched server model and write the merge, gated on the
|
|
61
|
+
* refetch's version, again on each conflict up to `maxWrites` writes. A
|
|
62
|
+
* non-conflict error is re-thrown.
|
|
63
|
+
*/
|
|
64
|
+
export declare function reconcileWrite<TModel extends object>(model: TModel, baseVersion: BaseVersion, hooks: ReconcileWriteHooks<TModel>): Promise<ReconcileWriteOutcome>;
|
|
65
|
+
//# 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;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,aAAa,CAAC;IACjF,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,CAiChC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
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 'no-op':
|
|
45
|
+
return { status: 'unchanged', conflict, writes };
|
|
46
|
+
case 'conflict':
|
|
47
|
+
return { status: 'conflict', conflict, writes };
|
|
48
|
+
case 'unavailable':
|
|
49
|
+
await hooks.onUnavailable?.(model, conflict);
|
|
50
|
+
return { status: 'unavailable', conflict, writes };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** The `ConflictError` the write raised, or `undefined` when it landed. */
|
|
55
|
+
async function persistOrConflict(hooks, model, baseVersion) {
|
|
56
|
+
try {
|
|
57
|
+
await hooks.persist(model, baseVersion);
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (!(0, errors_1.isConflictError)(err)) {
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
return err;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=reconcile-write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile-write.js","sourceRoot":"","sources":["../src/reconcile-write.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAElF,qCAA+D;AAI/D,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAkD7B;;;;;GAKG;AACI,KAAK,yBACT,KAAa,EACb,WAAwB,EACxB,KAAkC;IAElC,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,oBAAoB,GAAG,WAAW,CAAC;IACvC,IAAI,QAAmC,CAAC;IACxC,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,kBAAkB,CAAC;IACxD,KAAK,IAAI,MAAM,GAAG,CAAC,GAAI,MAAM,EAAE,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,oBAAoB,CAAC,CAAC;QACjF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC,CAAC,C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,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,OAAO,CAAC;IAE9B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAE1E;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC;CAC1E;AAeD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC5C,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,EAC1D,MAAM,EAAE,CAAC,EACT,WAAW,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,EAC1C,OAAO,GAAE,qBAA0B,GACnC,UAAU,CA6EZ"}
|
|
@@ -9,9 +9,23 @@
|
|
|
9
9
|
********************************************************************************/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.bindRpcMethods = bindRpcMethods;
|
|
12
|
+
const vscode_jsonrpc_1 = require("vscode-jsonrpc");
|
|
13
|
+
const errors_1 = require("../errors");
|
|
12
14
|
const util_1 = require("../util");
|
|
13
15
|
const create_rpc_proxy_1 = require("./create-rpc-proxy");
|
|
14
16
|
const wire_prefix_1 = require("./wire-prefix");
|
|
17
|
+
/**
|
|
18
|
+
* The rejection to throw in place of `err`. A `ResponseError` from another copy
|
|
19
|
+
* of `vscode-jsonrpc` is rebuilt on this package's, since a connection keeps the
|
|
20
|
+
* code only of its own copy's errors; one from this copy is thrown as is, so a
|
|
21
|
+
* subclass keeps its `toJson`, unless `render` rewrites its message.
|
|
22
|
+
*/
|
|
23
|
+
function renderRejection(err, render) {
|
|
24
|
+
if (!(0, errors_1.isResponseError)(err) || (!render && err instanceof vscode_jsonrpc_1.ResponseError)) {
|
|
25
|
+
return err;
|
|
26
|
+
}
|
|
27
|
+
return new vscode_jsonrpc_1.ResponseError(err.code, render ? render(err) : err.message, err.data);
|
|
28
|
+
}
|
|
15
29
|
/**
|
|
16
30
|
* Register each named method on `target` as a handler on `connection`
|
|
17
31
|
* under the wire-name `<prefix><methodName>`. Notification methods (by
|
|
@@ -31,8 +45,14 @@ const wire_prefix_1 = require("./wire-prefix");
|
|
|
31
45
|
*
|
|
32
46
|
* Errors thrown synchronously from a request handler — or surfaced as a
|
|
33
47
|
* rejected promise — propagate back to the caller through vscode-jsonrpc's
|
|
34
|
-
* standard error envelope
|
|
35
|
-
*
|
|
48
|
+
* standard error envelope, its message rendered when
|
|
49
|
+
* {@link BindRpcMethodsOptions.renderErrorMessage} is supplied. A
|
|
50
|
+
* `ResponseError` from another copy of `vscode-jsonrpc` is rebuilt on this
|
|
51
|
+
* package's copy, so its code and data reach the caller when `connection` comes
|
|
52
|
+
* from that copy too, as the framework's own connections do; over a connection
|
|
53
|
+
* from another copy the caller receives a generic `InternalError`. Errors from a
|
|
54
|
+
* notification handler cannot propagate, and are routed to
|
|
55
|
+
* {@link BindRpcMethodsOptions.onNotificationError} instead.
|
|
36
56
|
*
|
|
37
57
|
* Accepts either a ready connection or a `Promise<MessageConnection>` —
|
|
38
58
|
* registrations queue until the connection resolves, then attach. The
|
|
@@ -84,7 +104,16 @@ function bindRpcMethods(connection, target, methodNames, options = {}) {
|
|
|
84
104
|
}));
|
|
85
105
|
}
|
|
86
106
|
else {
|
|
87
|
-
|
|
107
|
+
const render = options.renderErrorMessage;
|
|
108
|
+
disposables.push(resolved.onRequest(wireName, async (params) => {
|
|
109
|
+
try {
|
|
110
|
+
// Awaited inside the try, or a rejected promise escapes it.
|
|
111
|
+
return await dispatch(params);
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
throw renderRejection(err, render);
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
88
117
|
}
|
|
89
118
|
}
|
|
90
119
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind-rpc-methods.js","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF
|
|
1
|
+
{"version":3,"file":"bind-rpc-methods.js","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAElF,mDAAuE;AACvE,sCAA4C;AAE5C,kCAAgE;AAChE,yDAA2D;AAC3D,+CAA2D;AAsF3D;;;;;GAKG;AACH,SAAS,eAAe,CAAC,GAAY,EAAE,MAAkD;IACtF,IAAI,CAAC,IAAA,wBAAe,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,YAAY,8BAAa,CAAC,EAAE,CAAC;QACtE,OAAO,GAAG,CAAC;IACd,CAAC;IACD,OAAO,IAAI,8BAAa,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC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AC;IACT,CAAC;SAAM,CAAC;QACL,MAAM,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;IAED,OAAO;QACJ,OAAO;YACJ,SAAS,GAAG,IAAI,CAAC;YACjB,WAAW,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;KACH,CAAC;AACL,CAAC"}
|
|
@@ -127,6 +127,13 @@ export interface CreateRpcProxyOptions<TLocal extends object = never> {
|
|
|
127
127
|
* `bindRpcMethods` call) still capture per-method latency. Absent by default.
|
|
128
128
|
*/
|
|
129
129
|
readonly latency?: BindRpcMethodsOptions['latency'];
|
|
130
|
+
/**
|
|
131
|
+
* Forwarded to the inbound {@link localTarget} binding: renders the message
|
|
132
|
+
* an outgoing rejection carries. Only the inbound direction has rejections
|
|
133
|
+
* to render — the outbound proxy is this side making requests, and a
|
|
134
|
+
* rejection it receives was rendered by whoever answered.
|
|
135
|
+
*/
|
|
136
|
+
readonly renderErrorMessage?: BindRpcMethodsOptions['renderErrorMessage'];
|
|
130
137
|
}
|
|
131
138
|
/**
|
|
132
139
|
* Default notification discriminator — `on`-followed-by-an-uppercase-letter
|
|
@@ -162,6 +169,9 @@ export declare function defaultIsNotification(methodName: string): boolean;
|
|
|
162
169
|
* params, results and errors, and a second layer here would double every
|
|
163
170
|
* traced line.
|
|
164
171
|
*
|
|
172
|
+
* A rejection whose code names one of the framework's typed errors is rethrown
|
|
173
|
+
* as that class, through {@link reviveProtocolError}.
|
|
174
|
+
*
|
|
165
175
|
* Accepts either a ready connection or a `Promise<MessageConnection>` —
|
|
166
176
|
* proxy methods called before the promise resolves queue until it does,
|
|
167
177
|
* then dispatch, so adopters can wire the proxy before its underlying
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-rpc-proxy.d.ts","sourceRoot":"","sources":["../../src/rpc/create-rpc-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAW,KAAK,KAAK,EAAE,KAAK,iBAAiB,EAAE,MAAM,gB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