@hydranium/protocol 1.0.0-next.36 → 1.0.0-next.361
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 -83
- package/lib/abstract-logger.d.ts +11 -0
- package/lib/abstract-logger.d.ts.map +1 -1
- package/lib/abstract-logger.js +16 -0
- package/lib/abstract-logger.js.map +1 -1
- package/lib/client/data-connection.d.ts +303 -0
- package/lib/client/data-connection.d.ts.map +1 -0
- package/lib/client/data-connection.js +534 -0
- package/lib/client/data-connection.js.map +1 -0
- package/lib/client/data-events.d.ts +18 -1
- package/lib/client/data-events.d.ts.map +1 -1
- package/lib/client/data-events.js +26 -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 +691 -89
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +1155 -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 +6 -4
- package/lib/client/message-relay.d.ts.map +1 -1
- 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 +69 -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 +173 -0
- package/lib/client/rpc-connection.d.ts.map +1 -0
- package/lib/client/rpc-connection.js +225 -0
- package/lib/client/rpc-connection.js.map +1 -0
- package/lib/client/worker-handshake.d.ts +94 -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 +171 -48
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/events.d.ts +144 -33
- package/lib/data/events.d.ts.map +1 -1
- package/lib/data/requests.d.ts +76 -11
- package/lib/data/requests.d.ts.map +1 -1
- package/lib/debouncer.d.ts +7 -4
- package/lib/debouncer.d.ts.map +1 -1
- package/lib/debouncer.js +10 -10
- package/lib/debouncer.js.map +1 -1
- package/lib/errors.d.ts +188 -30
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +269 -32
- package/lib/errors.js.map +1 -1
- package/lib/format-log-arg.d.ts +33 -0
- package/lib/format-log-arg.d.ts.map +1 -0
- package/lib/format-log-arg.js +158 -0
- package/lib/format-log-arg.js.map +1 -0
- package/lib/glsp-edits-settled-actions.d.ts +54 -0
- package/lib/glsp-edits-settled-actions.d.ts.map +1 -0
- package/lib/glsp-edits-settled-actions.js +28 -0
- package/lib/glsp-edits-settled-actions.js.map +1 -0
- 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 +55 -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 +11 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -1
- package/lib/latency-collector.d.ts +10 -4
- package/lib/latency-collector.d.ts.map +1 -1
- package/lib/latency-collector.js +2 -0
- 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 +15 -4
- package/lib/messages/index.js.map +1 -1
- package/lib/messages/primitives.d.ts +59 -4
- package/lib/messages/primitives.d.ts.map +1 -1
- package/lib/messages/primitives.js +97 -4
- 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/node/index.d.ts +10 -0
- 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/pending-work-tracker.d.ts +30 -0
- package/lib/pending-work-tracker.d.ts.map +1 -0
- package/lib/pending-work-tracker.js +47 -0
- package/lib/pending-work-tracker.js.map +1 -0
- package/lib/profile-session.d.ts +24 -8
- package/lib/profile-session.d.ts.map +1 -1
- package/lib/profile-session.js +13 -4
- package/lib/profile-session.js.map +1 -1
- package/lib/profiling.d.ts +15 -2
- package/lib/profiling.d.ts.map +1 -1
- package/lib/profiling.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 +70 -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 +6 -2
- package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
- package/lib/rpc/bind-rpc-methods.js +17 -7
- package/lib/rpc/bind-rpc-methods.js.map +1 -1
- package/lib/rpc/create-rpc-proxy.d.ts +3 -0
- package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
- package/lib/rpc/create-rpc-proxy.js +6 -1
- 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/save-text-document.d.ts +40 -0
- package/lib/save-text-document.d.ts.map +1 -0
- package/lib/save-text-document.js +34 -0
- package/lib/save-text-document.js.map +1 -0
- package/lib/testing/catalogue-audit.d.ts +1 -1
- package/lib/testing/catalogue-audit.js +1 -1
- package/lib/testing/catalogue-audit.js.map +1 -1
- 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 +4 -3
- 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/transfer-node-builder.d.ts +81 -0
- package/lib/testing/transfer-node-builder.d.ts.map +1 -0
- package/lib/testing/transfer-node-builder.js +47 -0
- package/lib/testing/transfer-node-builder.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 +96 -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/transfer-element.d.ts +4 -4
- package/lib/types.d.ts +32 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/{model-service/args.js → types.js} +2 -2
- package/lib/types.js.map +1 -0
- 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 +18 -0
- package/src/client/data-connection.ts +654 -0
- package/src/client/data-events.ts +38 -1
- package/src/client/data-port.ts +36 -25
- package/src/client/data-session.ts +1476 -137
- package/src/client/index.ts +15 -9
- package/src/client/message-relay.ts +6 -4
- package/src/client/post-message-transport.ts +224 -4
- package/src/client/rpc-connection.ts +302 -0
- package/src/client/worker-handshake.ts +121 -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 +198 -48
- package/src/data/events.ts +150 -33
- package/src/data/requests.ts +82 -11
- package/src/debouncer.ts +11 -11
- package/src/errors.ts +331 -40
- package/src/format-log-arg.ts +176 -0
- package/src/glsp-edits-settled-actions.ts +62 -0
- package/src/glsp-request-model-args.ts +16 -0
- package/src/glsp-save-model-actions.ts +64 -0
- package/src/index.ts +11 -0
- package/src/latency-collector.ts +10 -3
- package/src/logger.ts +44 -8
- package/src/messages/index.ts +4 -2
- package/src/messages/primitives.ts +129 -5
- 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/pending-work-tracker.ts +47 -0
- package/src/profile-session.ts +31 -11
- package/src/profiling.ts +15 -2
- package/src/project.ts +4 -1
- package/src/random-uuid.ts +21 -0
- package/src/reconcile-write.ts +131 -0
- package/src/rpc/README.md +6 -6
- package/src/rpc/bind-rpc-methods.ts +18 -8
- package/src/rpc/create-rpc-proxy.ts +6 -1
- package/src/rpc/index.ts +1 -0
- package/src/rpc/send-by-method-name.ts +140 -0
- package/src/save-text-document.ts +39 -0
- package/src/testing/catalogue-audit.ts +1 -1
- package/src/testing/data-doubles.ts +141 -19
- package/src/testing/fake-clock.ts +76 -48
- package/src/testing/index.ts +4 -3
- 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/transfer-node-builder.ts +107 -0
- package/src/testing/wait-for.ts +61 -13
- package/src/tracer.ts +5 -9
- package/src/transfer-document.ts +116 -34
- package/src/transfer-element.ts +4 -4
- package/src/types.ts +30 -0
- 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/src/patch-merge.ts
CHANGED
|
@@ -7,34 +7,43 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
_areEquals,
|
|
12
|
+
applyPatch,
|
|
13
|
+
compare,
|
|
14
|
+
deepClone,
|
|
15
|
+
getValueByPointer,
|
|
16
|
+
type Operation as JsonPatchOperation,
|
|
17
|
+
unescapePathComponent
|
|
18
|
+
} from 'fast-json-patch';
|
|
11
19
|
|
|
12
20
|
/**
|
|
13
|
-
* Augment a user-intent JSON patch (computed `
|
|
21
|
+
* Augment a user-intent JSON patch (computed `base → ours`) with
|
|
14
22
|
* `test` ops so a strict `applyPatch` against freshly-fetched server state
|
|
15
23
|
* fails loudly when a foreign writer changed a path the user also changed.
|
|
16
24
|
*
|
|
17
25
|
* `fast-json-patch`'s `validateOperation: true` validates op structure and
|
|
18
26
|
* path resolvability but NOT the pre-existing value — a plain `replace` /
|
|
19
27
|
* `remove` silently overwrites whatever the foreign writer put there. For each
|
|
20
|
-
* `replace` / `remove` op we prepend a `test` op carrying the
|
|
28
|
+
* `replace` / `remove` op we prepend a `test` op carrying the base value at
|
|
21
29
|
* that path, so a same-path divergence becomes a `TEST_OPERATION_FAILED` throw.
|
|
22
30
|
* The caller treats that as a real field-level conflict (drop + refetch) rather
|
|
23
31
|
* than silently clobbering the foreign edit.
|
|
24
32
|
*
|
|
25
|
-
* `add` ops
|
|
26
|
-
* to test
|
|
33
|
+
* `add` ops get no `test` op: the path is new, so there is no base value
|
|
34
|
+
* to test. {@link reconcileByPatchReplay} checks them against theirs
|
|
35
|
+
* instead; a caller applying this patch itself does not get that check.
|
|
27
36
|
*
|
|
28
37
|
* Used behind the framework's `ConflictError` contract by every reconcile
|
|
29
38
|
* path — the GLSP recording command's undo/redo and forward-write, via
|
|
30
39
|
* {@link ReconcilingConflictResolver}, and an adopter's form-widget save — so
|
|
31
40
|
* they share one collision-detection rule.
|
|
32
41
|
*/
|
|
33
|
-
export function augmentWithTestOps(
|
|
42
|
+
export function augmentWithTestOps(base: object, userPatch: ReadonlyArray<JsonPatchOperation>): JsonPatchOperation[] {
|
|
34
43
|
const augmented: JsonPatchOperation[] = [];
|
|
35
44
|
for (const op of userPatch) {
|
|
36
45
|
if (op.op === 'replace' || op.op === 'remove') {
|
|
37
|
-
augmented.push({ op: 'test', path: op.path, value: getValueByPointer(
|
|
46
|
+
augmented.push({ op: 'test', path: op.path, value: getValueByPointer(base, op.path) });
|
|
38
47
|
}
|
|
39
48
|
augmented.push(op);
|
|
40
49
|
}
|
|
@@ -42,39 +51,60 @@ export function augmentWithTestOps(baseline: object, userPatch: ReadonlyArray<Js
|
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
/**
|
|
45
|
-
* Outcome of {@link reconcileByPatchReplay}. The caller persists
|
|
46
|
-
*
|
|
47
|
-
*
|
|
54
|
+
* Outcome of {@link reconcileByPatchReplay}. The caller persists `merged` and
|
|
55
|
+
* takes it as the new base, takes `theirs` as the new base on
|
|
56
|
+
* `already-applied`, drops + surfaces the `theirs` root on `conflict`,
|
|
57
|
+
* catches up with the server on `no-op`, and decides its own fallback (e.g.
|
|
58
|
+
* force-retry) on `unavailable`.
|
|
48
59
|
*/
|
|
49
60
|
export type ReconcileOutcome<T> =
|
|
50
61
|
| {
|
|
51
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* The replay succeeded: the foreign writer touched no path the user
|
|
64
|
+
* did, or wrote the user's value at one that runs through no array.
|
|
65
|
+
*/
|
|
52
66
|
status: 'merged';
|
|
53
67
|
/**
|
|
54
|
-
* A
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* had.
|
|
68
|
+
* A new root built on theirs, carrying both intents. It is NOT the
|
|
69
|
+
* caller's `ours` root — take this value as the new base, or the next
|
|
70
|
+
* write diffs against state the server never had.
|
|
58
71
|
*/
|
|
59
72
|
merged: T;
|
|
60
73
|
}
|
|
61
74
|
| {
|
|
62
75
|
/**
|
|
63
|
-
* The user's root
|
|
64
|
-
*
|
|
65
|
-
*
|
|
76
|
+
* The user's root equalled the base, so the gate fired on another writer's
|
|
77
|
+
* change and the caller is behind the server (`ConflictError.actualVersion`).
|
|
78
|
+
* Nothing was refetched. Catch up from the update at that version or a later
|
|
79
|
+
* one, or refetch; forcing the write overwrites the other writer's change.
|
|
66
80
|
*/
|
|
67
81
|
status: 'no-op';
|
|
68
82
|
}
|
|
69
83
|
| {
|
|
70
|
-
/**
|
|
84
|
+
/** The refetch already holds every path the user changed at the user's value: nothing is left to write. */
|
|
85
|
+
status: 'already-applied';
|
|
86
|
+
/**
|
|
87
|
+
* The server's current root, refetched and unmodified. Take it as the
|
|
88
|
+
* new base, not `ours`: it can also hold another writer's edit to a
|
|
89
|
+
* path the user did not change.
|
|
90
|
+
*/
|
|
91
|
+
theirs: T;
|
|
92
|
+
}
|
|
93
|
+
| {
|
|
94
|
+
/**
|
|
95
|
+
* User and foreign writer changed one path to different values, or
|
|
96
|
+
* both changed one inside an array the refetch holds otherwise than
|
|
97
|
+
* the user, even to the same value; both inserted the same array
|
|
98
|
+
* element; or the foreign writer removed or replaced what the user
|
|
99
|
+
* edited inside.
|
|
100
|
+
*/
|
|
71
101
|
status: 'conflict';
|
|
72
102
|
/**
|
|
73
103
|
* The server's current root, refetched and unmodified — the user's
|
|
74
104
|
* intent was NOT applied to it. Surface it and drop the write; treating
|
|
75
105
|
* it as a merge result silently discards what the user typed.
|
|
76
106
|
*/
|
|
77
|
-
|
|
107
|
+
theirs: T;
|
|
78
108
|
}
|
|
79
109
|
| {
|
|
80
110
|
/**
|
|
@@ -87,39 +117,194 @@ export type ReconcileOutcome<T> =
|
|
|
87
117
|
|
|
88
118
|
/**
|
|
89
119
|
* Shared three-way reconcile for a `ConflictError`: diff the user's intent
|
|
90
|
-
* (`
|
|
120
|
+
* (`base → ours`), refetch the server's current root (theirs), and replay the
|
|
91
121
|
* intent on top under strict, {@link augmentWithTestOps}-guarded `applyPatch`.
|
|
92
122
|
*
|
|
93
|
-
* - `no-op` — the user's root equals the
|
|
94
|
-
*
|
|
123
|
+
* - `no-op` — the user's root equals the base: nothing to replay, and no
|
|
124
|
+
* refetch; the caller's document is behind the server's.
|
|
95
125
|
* - `unavailable` — the refetch produced nothing; caller falls back.
|
|
96
|
-
* - `
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
126
|
+
* - `already-applied` — the refetch already holds the user's value at every
|
|
127
|
+
* path the user changed, and the user's whole array for a path through
|
|
128
|
+
* one; nothing is replayed.
|
|
129
|
+
* - `merged` — the foreign writer touched only paths the user did not, or
|
|
130
|
+
* made the user's change itself at a path through no array; the merged
|
|
131
|
+
* root carries both intents.
|
|
132
|
+
* - `conflict` — a same-path divergence tripped a `test` op, including the
|
|
133
|
+
* user's own value inside an array the refetch holds otherwise than the
|
|
134
|
+
* user; or an `add` collides with one the foreign writer made; or the
|
|
135
|
+
* foreign writer removed or replaced what the user edited inside. The
|
|
136
|
+
* caller drops the write and surfaces `theirs`.
|
|
100
137
|
*
|
|
101
138
|
* I/O is the caller's: `refetch` supplies the current root, and applying the
|
|
102
|
-
* `merged` result (update vs save,
|
|
139
|
+
* `merged` result (update vs save, new base, UI refresh) stays at the call
|
|
103
140
|
* site so form and GLSP paths keep their own persistence semantics.
|
|
104
141
|
*/
|
|
105
142
|
export async function reconcileByPatchReplay<T extends object>(
|
|
106
|
-
|
|
107
|
-
|
|
143
|
+
base: T,
|
|
144
|
+
ours: T,
|
|
108
145
|
refetch: () => Promise<T | undefined>
|
|
109
146
|
): Promise<ReconcileOutcome<T>> {
|
|
110
|
-
const userPatch = compare(
|
|
147
|
+
const userPatch = compare(base, ours);
|
|
111
148
|
if (userPatch.length === 0) {
|
|
112
149
|
return { status: 'no-op' };
|
|
113
150
|
}
|
|
114
|
-
const
|
|
115
|
-
if (!
|
|
151
|
+
const theirs = await refetch();
|
|
152
|
+
if (!theirs) {
|
|
116
153
|
return { status: 'unavailable' };
|
|
117
154
|
}
|
|
155
|
+
const comparable = toJson(theirs);
|
|
156
|
+
const pending = withoutAgreed(base, ours, comparable, userPatch);
|
|
157
|
+
if (pending.length === 0) {
|
|
158
|
+
return { status: 'already-applied', theirs };
|
|
159
|
+
}
|
|
160
|
+
if (addsCollide(base, comparable, pending)) {
|
|
161
|
+
return { status: 'conflict', theirs };
|
|
162
|
+
}
|
|
118
163
|
try {
|
|
119
|
-
const merged = applyPatch(deepClone(
|
|
164
|
+
const merged = applyPatch(deepClone(theirs), augmentWithTestOps(base, pending), true).newDocument;
|
|
120
165
|
return { status: 'merged', merged };
|
|
121
166
|
} catch {
|
|
122
|
-
return { status: 'conflict',
|
|
167
|
+
return { status: 'conflict', theirs };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* `userPatch` without the ops `theirs` already agrees with: a `replace` or
|
|
173
|
+
* object-key `add` whose key the object at its parent path holds at the
|
|
174
|
+
* user's value, a `remove` whose key that object lacks. A parent that is
|
|
175
|
+
* absent or no object agrees with nothing: a foreign writer deleted or
|
|
176
|
+
* replaced what the user edited inside, or a refetch omitted a document it
|
|
177
|
+
* could not read.
|
|
178
|
+
*
|
|
179
|
+
* Ops address array elements by index, so an op through an array agrees only
|
|
180
|
+
* when that array, the outermost on its path, equals the user's: matching one
|
|
181
|
+
* index of an array that shifted would drop the user's edit to another
|
|
182
|
+
* element. An insert never agrees, as {@link addsCollide} keeps two equal
|
|
183
|
+
* additions apart, and neither does any op through its array, or replaying
|
|
184
|
+
* the insert alone would add its element a second time. Each array is
|
|
185
|
+
* compared once, however many ops run through it and however many arrays the
|
|
186
|
+
* patch inserts into, so a bulk edit stays linear.
|
|
187
|
+
*
|
|
188
|
+
* `theirs` is the refetch through {@link toJson}.
|
|
189
|
+
*/
|
|
190
|
+
function withoutAgreed(base: object, ours: object, theirs: object, userPatch: readonly JsonPatchOperation[]): JsonPatchOperation[] {
|
|
191
|
+
const jsonOurs = toJson(ours);
|
|
192
|
+
// An insert is keyed by the outermost array on its path, as every op is looked up, so one set answers for every array.
|
|
193
|
+
const insertedArrays = new Set(
|
|
194
|
+
userPatch
|
|
195
|
+
.filter(op => op.op === 'add' && Array.isArray(valueAt(base, op.path.slice(0, op.path.lastIndexOf('/')))))
|
|
196
|
+
.map(op => outermostArrayOn(jsonOurs, op.path))
|
|
197
|
+
);
|
|
198
|
+
const arrayAgrees = new Map<string, boolean>();
|
|
199
|
+
return userPatch.filter(op => {
|
|
200
|
+
const array = outermostArrayOn(jsonOurs, op.path);
|
|
201
|
+
if (array !== undefined) {
|
|
202
|
+
let agrees = arrayAgrees.get(array);
|
|
203
|
+
if (agrees === undefined) {
|
|
204
|
+
agrees = !insertedArrays.has(array) && _areEquals(valueAt(theirs, array), valueAt(jsonOurs, array));
|
|
205
|
+
arrayAgrees.set(array, agrees);
|
|
206
|
+
}
|
|
207
|
+
return !agrees;
|
|
208
|
+
}
|
|
209
|
+
const cut = op.path.lastIndexOf('/');
|
|
210
|
+
const parent = valueAt(theirs, op.path.slice(0, cut));
|
|
211
|
+
if (typeof parent !== 'object' || parent === null || Array.isArray(parent)) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
const key = unescapePathComponent(op.path.slice(cut + 1));
|
|
215
|
+
if (op.op === 'remove') {
|
|
216
|
+
return Object.hasOwn(parent, key);
|
|
217
|
+
}
|
|
218
|
+
if (op.op !== 'replace' && op.op !== 'add') {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
return !Object.hasOwn(parent, key) || !_areEquals(Reflect.get(parent, key), op.value);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** The outermost array a step of `pointer` before its last runs through in `document`, as a pointer; `undefined` for none. */
|
|
226
|
+
function outermostArrayOn(document: object, pointer: string): string | undefined {
|
|
227
|
+
const steps = pointer.split('/');
|
|
228
|
+
for (let i = 1; i < steps.length; i++) {
|
|
229
|
+
const prefix = steps.slice(0, i).join('/');
|
|
230
|
+
if (Array.isArray(valueAt(document, prefix))) {
|
|
231
|
+
return prefix;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* `value` through JSON, as `compare` clones the values it diffs: an
|
|
239
|
+
* undefined-valued key would otherwise make two equal values differ.
|
|
240
|
+
*/
|
|
241
|
+
function toJson<T>(value: T): T {
|
|
242
|
+
return JSON.parse(JSON.stringify(value)) as T;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Whether an `add` of `userPatch` collides with one the foreign writer made:
|
|
247
|
+
* it inserts a value into an array that `theirs` holds more often than
|
|
248
|
+
* `base` did, or it adds an object key that `theirs` already holds, at
|
|
249
|
+
* another value once `withoutAgreed` has dropped the equal ones.
|
|
250
|
+
*
|
|
251
|
+
* Replayed, the first inserts the value a second time and the second replaces
|
|
252
|
+
* the foreign value. Identical array elements conflict rather than being
|
|
253
|
+
* skipped: skipping drops one of two insertions that merely happen to be
|
|
254
|
+
* equal. `theirs` is the refetch through {@link toJson}.
|
|
255
|
+
*/
|
|
256
|
+
function addsCollide(base: object, theirs: object, userPatch: readonly JsonPatchOperation[]): boolean {
|
|
257
|
+
// Each array's elements are counted once, however many ops insert into it, so a bulk insert stays linear.
|
|
258
|
+
const tallies = new Map<string, { readonly before: ReadonlyMap<string, number>; readonly now: ReadonlyMap<string, number> }>();
|
|
259
|
+
return userPatch.some(op => {
|
|
260
|
+
if (op.op !== 'add') {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
const cut = op.path.lastIndexOf('/');
|
|
264
|
+
const parent = op.path.slice(0, cut);
|
|
265
|
+
const before = valueAt(base, parent);
|
|
266
|
+
const now = valueAt(theirs, parent);
|
|
267
|
+
if (Array.isArray(before)) {
|
|
268
|
+
if (!Array.isArray(now)) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
let tally = tallies.get(parent);
|
|
272
|
+
if (!tally) {
|
|
273
|
+
tally = { before: tallyElements(before), now: tallyElements(now) };
|
|
274
|
+
tallies.set(parent, tally);
|
|
275
|
+
}
|
|
276
|
+
const key = canonicalJson(op.value);
|
|
277
|
+
return (tally.now.get(key) ?? 0) > (tally.before.get(key) ?? 0);
|
|
278
|
+
}
|
|
279
|
+
return typeof now === 'object' && now !== null && Object.hasOwn(now, unescapePathComponent(op.path.slice(cut + 1)));
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** How many elements of `array` there are of each value, keyed by {@link canonicalJson}. */
|
|
284
|
+
function tallyElements(array: readonly unknown[]): ReadonlyMap<string, number> {
|
|
285
|
+
const tally = new Map<string, number>();
|
|
286
|
+
for (const element of array) {
|
|
287
|
+
const key = canonicalJson(element);
|
|
288
|
+
tally.set(key, (tally.get(key) ?? 0) + 1);
|
|
289
|
+
}
|
|
290
|
+
return tally;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** `value` as JSON with every object's keys sorted, so two deeply equal values give one string whatever their key order. */
|
|
294
|
+
function canonicalJson(value: unknown): string {
|
|
295
|
+
return JSON.stringify(value, (_key, nested: unknown) =>
|
|
296
|
+
typeof nested === 'object' && nested !== null && !Array.isArray(nested)
|
|
297
|
+
? Object.fromEntries(Object.entries(nested).sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0)))
|
|
298
|
+
: nested
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** The value at `pointer`, or `undefined` when a step of it is missing. */
|
|
303
|
+
function valueAt(document: object, pointer: string): unknown {
|
|
304
|
+
try {
|
|
305
|
+
return getValueByPointer(document, pointer);
|
|
306
|
+
} catch {
|
|
307
|
+
return undefined;
|
|
123
308
|
}
|
|
124
309
|
}
|
|
125
310
|
|
|
@@ -132,12 +317,12 @@ export async function reconcileByPatchReplay<T extends object>(
|
|
|
132
317
|
*/
|
|
133
318
|
export interface ConflictResolver {
|
|
134
319
|
/**
|
|
135
|
-
* Reconcile the user's `
|
|
136
|
-
* server state (`refetch`), returning a {@link ReconcileOutcome} the caller
|
|
137
|
-
* acts on (persist `merged`,
|
|
138
|
-
* `unavailable`).
|
|
320
|
+
* Reconcile the user's `base → ours` intent against the current
|
|
321
|
+
* server state (theirs, from `refetch`), returning a {@link ReconcileOutcome} the caller
|
|
322
|
+
* acts on (persist `merged`, write nothing on `already-applied`, drop on
|
|
323
|
+
* `conflict`, catch up on `no-op`, fall back on `unavailable`).
|
|
139
324
|
*/
|
|
140
|
-
resolve<T extends object>(
|
|
325
|
+
resolve<T extends object>(base: T, ours: T, refetch: () => Promise<T | undefined>): Promise<ReconcileOutcome<T>>;
|
|
141
326
|
}
|
|
142
327
|
|
|
143
328
|
/**
|
|
@@ -147,19 +332,19 @@ export interface ConflictResolver {
|
|
|
147
332
|
* clobbered.
|
|
148
333
|
*/
|
|
149
334
|
export class ReconcilingConflictResolver implements ConflictResolver {
|
|
150
|
-
resolve<T extends object>(
|
|
151
|
-
return reconcileByPatchReplay(
|
|
335
|
+
resolve<T extends object>(base: T, ours: T, refetch: () => Promise<T | undefined>): Promise<ReconcileOutcome<T>> {
|
|
336
|
+
return reconcileByPatchReplay(base, ours, refetch);
|
|
152
337
|
}
|
|
153
338
|
}
|
|
154
339
|
|
|
155
340
|
/**
|
|
156
|
-
* Last-writer-wins {@link ConflictResolver}: always reports the `
|
|
341
|
+
* Last-writer-wins {@link ConflictResolver}: always reports the `ours`
|
|
157
342
|
* state as merged, without refetching or guarding. Suitable for single-client
|
|
158
343
|
* tools or always-regenerated artifacts where a concurrent foreign edit may be
|
|
159
344
|
* overwritten. A foreign edit to any field is clobbered.
|
|
160
345
|
*/
|
|
161
346
|
export class ForceConflictResolver implements ConflictResolver {
|
|
162
|
-
async resolve<T extends object>(
|
|
163
|
-
return { status: 'merged', merged:
|
|
347
|
+
async resolve<T extends object>(_base: T, ours: T, _refetch: () => Promise<T | undefined>): Promise<ReconcileOutcome<T>> {
|
|
348
|
+
return { status: 'merged', merged: ours };
|
|
164
349
|
}
|
|
165
350
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 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
|
+
/**
|
|
11
|
+
* Watches work started elsewhere until it settles, so a caller can ask whether
|
|
12
|
+
* any is still pending and wait for what is pending now. It starts, orders and
|
|
13
|
+
* limits nothing, and keeps no clock: a caller that must not wait for good
|
|
14
|
+
* races {@link whenSettled} against its own bound.
|
|
15
|
+
*/
|
|
16
|
+
export class PendingWorkTracker {
|
|
17
|
+
/** The tracked work. {@link track} removes each entry once it settles. */
|
|
18
|
+
protected readonly pending = new Set<Promise<unknown>>();
|
|
19
|
+
|
|
20
|
+
/** Watch `work` until it settles, and hand it back. */
|
|
21
|
+
track<T>(work: Promise<T>): Promise<T> {
|
|
22
|
+
this.pending.add(work);
|
|
23
|
+
const done = (): void => {
|
|
24
|
+
this.pending.delete(work);
|
|
25
|
+
};
|
|
26
|
+
work.then(done, done);
|
|
27
|
+
return work;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** How much of the tracked work has not settled yet. */
|
|
31
|
+
get size(): number {
|
|
32
|
+
return this.pending.size;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether all tracked work has settled. Synchronous, for a check that must decide within the tick. */
|
|
36
|
+
get isIdle(): boolean {
|
|
37
|
+
return this.pending.size === 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Resolves once the work pending now has settled; work tracked later is not
|
|
42
|
+
* waited for. Never rejects, since failed work has settled too.
|
|
43
|
+
*/
|
|
44
|
+
async whenSettled(): Promise<void> {
|
|
45
|
+
await Promise.allSettled([...this.pending]);
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/profile-session.ts
CHANGED
|
@@ -18,7 +18,11 @@ export interface ProfileRecord {
|
|
|
18
18
|
count: number;
|
|
19
19
|
/** Summed self-time across those runs (wall-clock minus nested scopes). */
|
|
20
20
|
selfMs: number;
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Self-time as a percentage of the session's total wall-clock. Overlapping
|
|
23
|
+
* scopes each count their own wall time, so the percentages can add up to
|
|
24
|
+
* more than 100.
|
|
25
|
+
*/
|
|
22
26
|
selfPct: number;
|
|
23
27
|
}
|
|
24
28
|
|
|
@@ -53,8 +57,9 @@ export interface ProfileSession {
|
|
|
53
57
|
/**
|
|
54
58
|
* Emit the aggregate through the bound {@link Logger}: one line per id,
|
|
55
59
|
* sorted by self-time descending, plus an "unaccounted" remainder (the
|
|
56
|
-
* session wall-clock not attributed to any top-level scope).
|
|
57
|
-
*
|
|
60
|
+
* session wall-clock not attributed to any top-level scope). The remainder
|
|
61
|
+
* is left out when overlapping scopes account for more than the wall-clock.
|
|
62
|
+
* No-op when `logLevel` is suppressed by the global threshold (incl. `'off'`).
|
|
58
63
|
*/
|
|
59
64
|
report(logLevel?: LogThreshold): void;
|
|
60
65
|
|
|
@@ -62,7 +67,13 @@ export interface ProfileSession {
|
|
|
62
67
|
records(): readonly ProfileRecord[];
|
|
63
68
|
}
|
|
64
69
|
|
|
65
|
-
|
|
70
|
+
/**
|
|
71
|
+
* One in-flight {@link ProfileSession.scope} call. Held on the `protected`
|
|
72
|
+
* {@link DefaultProfileSession.stack} and named by
|
|
73
|
+
* {@link DefaultProfileSession.closeFrame}, so a subclass has to name it too.
|
|
74
|
+
*/
|
|
75
|
+
export interface ProfileScopeFrame {
|
|
76
|
+
/** The {@link ProfileSession.scope} id, under which frames sharing it aggregate into one record. */
|
|
66
77
|
readonly id: string;
|
|
67
78
|
/** Session-stopwatch reading when this scope began. */
|
|
68
79
|
readonly start: number;
|
|
@@ -78,7 +89,9 @@ interface ScopeFrame {
|
|
|
78
89
|
export class DefaultProfileSession implements ProfileSession {
|
|
79
90
|
/** Single monotonic timeline for the whole session; per-scope readings are deltas off it. */
|
|
80
91
|
protected readonly sessionStopwatch: Stopwatch;
|
|
81
|
-
|
|
92
|
+
/** The scopes in flight, in the order they started. */
|
|
93
|
+
protected readonly stack: ProfileScopeFrame[] = [];
|
|
94
|
+
/** Self-time in milliseconds per id, one sample per closed scope, which {@link records} sums. */
|
|
82
95
|
protected readonly entries = new Map<string, number[]>();
|
|
83
96
|
|
|
84
97
|
constructor(
|
|
@@ -92,7 +105,7 @@ export class DefaultProfileSession implements ProfileSession {
|
|
|
92
105
|
scope<T>(id: string, fn: () => Promise<T>): Promise<T>;
|
|
93
106
|
scope<T>(id: string, fn: () => T): T;
|
|
94
107
|
scope<T>(id: string, fn: () => T | Promise<T>): T | Promise<T> {
|
|
95
|
-
const frame:
|
|
108
|
+
const frame: ProfileScopeFrame = { id, start: this.sessionStopwatch.elapsedMs, childMs: 0 };
|
|
96
109
|
this.stack.push(frame);
|
|
97
110
|
let result: T | Promise<T>;
|
|
98
111
|
try {
|
|
@@ -117,15 +130,22 @@ export class DefaultProfileSession implements ProfileSession {
|
|
|
117
130
|
return result;
|
|
118
131
|
}
|
|
119
132
|
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Remove `frame`, charge its full duration to the frame below it, and record
|
|
135
|
+
* its self-time. Overlapping scopes can together outlast the one below
|
|
136
|
+
* them, whose self-time is then zero rather than negative.
|
|
137
|
+
*/
|
|
138
|
+
protected closeFrame(frame: ProfileScopeFrame): void {
|
|
139
|
+
const index = this.stack.lastIndexOf(frame);
|
|
140
|
+
if (index >= 0) {
|
|
141
|
+
this.stack.splice(index, 1);
|
|
142
|
+
}
|
|
123
143
|
const duration = this.sessionStopwatch.elapsedMs - frame.start;
|
|
124
|
-
const parent = this.stack[
|
|
144
|
+
const parent = index > 0 ? this.stack[index - 1] : undefined;
|
|
125
145
|
if (parent) {
|
|
126
146
|
parent.childMs += duration;
|
|
127
147
|
}
|
|
128
|
-
const selfMs = duration - frame.childMs;
|
|
148
|
+
const selfMs = Math.max(0, duration - frame.childMs);
|
|
129
149
|
const samples = this.entries.get(frame.id);
|
|
130
150
|
if (samples) {
|
|
131
151
|
samples.push(selfMs);
|
package/src/profiling.ts
CHANGED
|
@@ -17,15 +17,23 @@
|
|
|
17
17
|
|
|
18
18
|
/** Which dimensions to capture, and the two sampling knobs. All off by default. */
|
|
19
19
|
export interface ProfileCaptureOptions {
|
|
20
|
+
/** Sample the CPU at {@link cpuIntervalMicros} into a `server-cpu` artefact. */
|
|
20
21
|
cpu?: boolean;
|
|
22
|
+
/** Sample allocations at {@link allocationIntervalBytes} into a `server-alloc` artefact. */
|
|
21
23
|
allocation?: boolean;
|
|
24
|
+
/** Record every GC pause, summed by kind in `server-summary` rather than as its own artefact. */
|
|
22
25
|
gc?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Sample event-loop delay, summarised as mean, p50, p99 and max in
|
|
28
|
+
* `server-summary` rather than as its own artefact. Absent there when the
|
|
29
|
+
* sampler recorded nothing.
|
|
30
|
+
*/
|
|
23
31
|
eventLoopDelay?: boolean;
|
|
24
32
|
/** Also drop a retained `.heapsnapshot` at stop (for the memory analyzer). */
|
|
25
33
|
heapSnapshot?: boolean;
|
|
26
|
-
/** CPU sampling interval in µs (implementation default
|
|
34
|
+
/** CPU sampling interval in µs (implementation default `DEFAULT_CPU_INTERVAL_MICROS`). */
|
|
27
35
|
cpuIntervalMicros?: number;
|
|
28
|
-
/** Allocation sampling interval in bytes (implementation default
|
|
36
|
+
/** Allocation sampling interval in bytes (implementation default `DEFAULT_ALLOCATION_INTERVAL_BYTES`). */
|
|
29
37
|
allocationIntervalBytes?: number;
|
|
30
38
|
}
|
|
31
39
|
|
|
@@ -72,12 +80,17 @@ export interface ProfilingArtifact {
|
|
|
72
80
|
|
|
73
81
|
/** What a skill reads to know what to expect from a run (browser entries only in `app` mode, etc.). */
|
|
74
82
|
export interface ProfilingEnvironment {
|
|
83
|
+
/** `harness` for a headless run, `app` for one that drove the real app. */
|
|
75
84
|
mode: 'harness' | 'app';
|
|
76
85
|
/** Whether a cgroup memory controller is present (running in a pod) vs local. */
|
|
77
86
|
container: boolean;
|
|
87
|
+
/** The commit the run reflects, which a finding's `file:line` is read against. Absent when the caller named none. */
|
|
78
88
|
commit?: string;
|
|
89
|
+
/** The workspace under test as the caller named it. Absent when it named none. */
|
|
79
90
|
workspace?: string;
|
|
91
|
+
/** The `process.version` of the process that wrote the manifest, which for an e2e run is the test runner, not the server. */
|
|
80
92
|
node: string;
|
|
93
|
+
/** Captured windows in capture order, each with its duration in milliseconds. */
|
|
81
94
|
windows: { label: string; ms: number }[];
|
|
82
95
|
}
|
|
83
96
|
|
package/src/project.ts
CHANGED
|
@@ -40,7 +40,10 @@
|
|
|
40
40
|
* adopter-specific extension carried transparently through the typed
|
|
41
41
|
* surface. The framework imposes no format on extension fields — they
|
|
42
42
|
* ride on the JSON-RPC envelope as additional properties when crossing
|
|
43
|
-
* the wire.
|
|
43
|
+
* the wire. A client receives a project's own enumerable fields as JSON: a
|
|
44
|
+
* getter or a method does not cross, and a class instance in a field arrives
|
|
45
|
+
* as a plain object, so the project type a client protocol declares holds the
|
|
46
|
+
* data fields alone.
|
|
44
47
|
*/
|
|
45
48
|
export interface Project {
|
|
46
49
|
/**
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* A random v4 UUID. Not `crypto.randomUUID`: a browser offers it only in a
|
|
12
|
+
* secure context, and a client may be served over plain HTTP.
|
|
13
|
+
*/
|
|
14
|
+
export function randomUuid(): string {
|
|
15
|
+
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
|
|
16
|
+
// Version 4, RFC 4122 variant.
|
|
17
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
18
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
19
|
+
const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('');
|
|
20
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
21
|
+
}
|