@hydranium/protocol 1.0.0-next.39 → 1.0.0-next.391
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 +46 -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 +11 -2
- package/lib/client/data-events.d.ts.map +1 -1
- package/lib/client/data-events.js +13 -1
- 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 +762 -89
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +1253 -115
- package/lib/client/data-session.js.map +1 -1
- package/lib/client/index.d.ts +16 -9
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +16 -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/working-copy.d.ts +420 -0
- package/lib/client/working-copy.d.ts.map +1 -0
- package/lib/client/working-copy.js +958 -0
- package/lib/client/working-copy.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 +7 -0
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +160 -50
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/events.d.ts +75 -31
- package/lib/data/events.d.ts.map +1 -1
- package/lib/data/requests.d.ts +84 -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 +241 -48
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +395 -60
- 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 +17 -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 +58 -11
- 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 +33 -0
- package/lib/pending-work-tracker.d.ts.map +1 -0
- package/lib/pending-work-tracker.js +48 -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 +6 -2
- 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.js.map +1 -1
- package/lib/testing/data-doubles.d.ts +36 -11
- package/lib/testing/data-doubles.d.ts.map +1 -1
- package/lib/testing/data-doubles.js +47 -9
- 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/harness.d.ts +9 -0
- package/lib/testing/harness.d.ts.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 +2 -0
- package/lib/testing/node/index.d.ts.map +1 -1
- package/lib/testing/node/index.js +3 -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/node/unhandled-rejections.d.ts +20 -0
- package/lib/testing/node/unhandled-rejections.d.ts.map +1 -0
- package/lib/testing/node/unhandled-rejections.js +35 -0
- package/lib/testing/node/unhandled-rejections.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.d.ts +11 -0
- package/lib/transfer-diagnostic.d.ts.map +1 -1
- package/lib/transfer-diagnostic.js +17 -0
- package/lib/transfer-diagnostic.js.map +1 -1
- package/lib/transfer-document.d.ts +108 -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 +15 -1
- package/src/client/data-port.ts +36 -25
- package/src/client/data-session.ts +1606 -137
- package/src/client/index.ts +16 -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/working-copy.ts +1116 -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 +8 -1
- package/src/data/data-server-protocol.ts +184 -49
- package/src/data/events.ts +77 -31
- package/src/data/requests.ts +90 -11
- package/src/debouncer.ts +11 -11
- package/src/errors.ts +496 -71
- 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 +12 -2
- package/src/messages/primitives.ts +129 -5
- package/src/model-server.ts +62 -17
- 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 +48 -0
- package/src/profile-session.ts +31 -11
- package/src/profiling.ts +15 -2
- package/src/project.ts +6 -2
- 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/data-doubles.ts +119 -19
- package/src/testing/fake-clock.ts +76 -48
- package/src/testing/harness.ts +10 -0
- package/src/testing/index.ts +4 -3
- package/src/testing/node/duplex-connection.ts +3 -2
- package/src/testing/node/index.ts +3 -2
- package/src/testing/node/message-port-pair.ts +40 -0
- package/src/testing/node/unhandled-rejections.ts +31 -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-diagnostic.ts +17 -0
- package/src/transfer-document.ts +130 -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/data/events.ts
CHANGED
|
@@ -10,27 +10,29 @@
|
|
|
10
10
|
import type { TransferDiagnostic } from '../transfer-diagnostic';
|
|
11
11
|
import type { TransferElement } from '../transfer-element';
|
|
12
12
|
import type { Project } from '../project';
|
|
13
|
-
import type { TransferDocument } from '../transfer-document';
|
|
13
|
+
import type { TextState, TransferDocument } from '../transfer-document';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Why an update event fired. Subscribers filter on reason for behaviour
|
|
17
17
|
* decisions (e.g. dirty-flag handling, undo-history grouping, telemetry):
|
|
18
18
|
*
|
|
19
|
-
* - `'changed'` — the
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* - `'rebuilt'` — the URI was rebuilt as a cascade from another URI's
|
|
27
|
-
* build (dependency graph re-derivation), without itself being passed to
|
|
28
|
-
* `documentBuilder.update`. The complement of `'changed'`.
|
|
19
|
+
* - `'changed'` — the server's first update event for the document's current
|
|
20
|
+
* version: its content changed since the last one. A write whose build a
|
|
21
|
+
* later write cancelled is still `'changed'` in the build that takes over.
|
|
22
|
+
* - `'rebuilt'` — a later event for a version the server already delivered,
|
|
23
|
+
* whether or not any client watched it then: something the document depends
|
|
24
|
+
* on changed, or the document was built again with the same content. The
|
|
25
|
+
* complement of `'changed'`.
|
|
29
26
|
* - `'saved'` — emitted by adopters that synthesise a unified update stream
|
|
30
27
|
* from both `onDocumentUpdated` and `onDocumentSaved`. The framework's own
|
|
31
28
|
* `dispatchPhaseEvent` does NOT emit `'saved'` — saves take the dedicated
|
|
32
29
|
* `DataClientProtocol.onDocumentSaved` channel.
|
|
33
30
|
*
|
|
31
|
+
* The version rule needs a version the server keeps and builds that validate.
|
|
32
|
+
* For a document no client has opened, or when rebuilds do not validate,
|
|
33
|
+
* `'changed'` means the URI was passed to `DocumentBuilder.update` for this
|
|
34
|
+
* build. A document that a validating build skips is `'changed'` every time.
|
|
35
|
+
*
|
|
34
36
|
* Deletion is deliberately NOT a member. An update event carries a built
|
|
35
37
|
* document, which a deleted one has none of, and the phase-driven path that
|
|
36
38
|
* produces these events never runs for a deleted URI — the builder drops the
|
|
@@ -42,18 +44,29 @@ export type TransferDocumentUpdateReason = 'changed' | 'rebuilt' | 'saved';
|
|
|
42
44
|
/**
|
|
43
45
|
* Delivered on the data-server when a document's content (or existence)
|
|
44
46
|
* changed. Subscribers receive this via `DocumentServerProtocol.watchModelDocument`.
|
|
45
|
-
*
|
|
46
|
-
* The `document` field carries the latest built state — diagnostics + root
|
|
47
|
-
* are coherent with each other at the time the event fired.
|
|
48
47
|
*/
|
|
49
48
|
export interface TransferDocumentUpdatedEvent<
|
|
50
49
|
TTransfer extends TransferElement,
|
|
51
50
|
TDiagnostic extends TransferDiagnostic = TransferDiagnostic
|
|
52
51
|
> {
|
|
52
|
+
/** The latest built state: diagnostics and root are coherent with each other at the time the event fired. */
|
|
53
53
|
document: TransferDocument<TTransfer, TDiagnostic>;
|
|
54
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* The client whose write this event echoes: the author of the version on a
|
|
56
|
+
* `'changed'`, and the unknown-client id on a `'rebuilt'`, which echoes no
|
|
57
|
+
* write. A recipient compares it against its own id to recognise its echo.
|
|
58
|
+
* The build that follows a document's release names the release id
|
|
59
|
+
* instead.
|
|
60
|
+
*/
|
|
55
61
|
sourceClientId: string;
|
|
62
|
+
/** See {@link TransferDocumentUpdateReason} for which reasons the framework sends. */
|
|
56
63
|
reason: TransferDocumentUpdateReason;
|
|
64
|
+
/**
|
|
65
|
+
* The position of this event among the update and deletion events the
|
|
66
|
+
* server sent on this connection, which a watch's answer carries as of
|
|
67
|
+
* the moment it was taken: a greater one was sent later.
|
|
68
|
+
*/
|
|
69
|
+
sequence: number;
|
|
57
70
|
}
|
|
58
71
|
|
|
59
72
|
/** Callback shape for `DataClientProtocol.onDocumentUpdated`. */
|
|
@@ -63,28 +76,25 @@ export type TransferDocumentUpdatedListener<
|
|
|
63
76
|
> = (event: TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>) => void;
|
|
64
77
|
|
|
65
78
|
/**
|
|
66
|
-
* Delivered on the data-server when a document was
|
|
67
|
-
*
|
|
68
|
-
* {@link TransferDocumentUpdatedEvent}: subscribers that only
|
|
69
|
-
* persistence (external sync, editor "saved" indicators,
|
|
70
|
-
* clear) listen for this event family instead of filtering an
|
|
71
|
-
* stream for `reason: 'saved'`.
|
|
72
|
-
*
|
|
73
|
-
* The `document` field carries the post-save built state — same shape
|
|
74
|
-
* the synchronous `saveModelDocument` RPC response returns, delivered
|
|
75
|
-
* to subscribers (`DataClientProtocol.onDocumentSaved`) so non-caller
|
|
76
|
-
* clients see the persistence event too.
|
|
79
|
+
* Delivered on the data-server when a subscribed document was saved to disk,
|
|
80
|
+
* whichever client saved it, an editor's save through the LSP head included.
|
|
81
|
+
* Distinct from {@link TransferDocumentUpdatedEvent}: subscribers that only
|
|
82
|
+
* care about persistence (external sync, editor "saved" indicators,
|
|
83
|
+
* dirty-flag clear) listen for this event family instead of filtering an
|
|
84
|
+
* update stream for `reason: 'saved'`.
|
|
77
85
|
*/
|
|
78
86
|
export interface TransferDocumentSavedEvent<
|
|
79
87
|
TTransfer extends TransferElement,
|
|
80
88
|
TDiagnostic extends TransferDiagnostic = TransferDiagnostic
|
|
81
89
|
> {
|
|
90
|
+
/** The latest built state, taken after the save. */
|
|
82
91
|
document: TransferDocument<TTransfer, TDiagnostic>;
|
|
83
92
|
/**
|
|
84
|
-
* The client whose
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
93
|
+
* The client whose save produced this, also when another client wrote the
|
|
94
|
+
* persisted text: the caller of `saveModelDocument` or
|
|
95
|
+
* `persistModelDocument`, or `LANGUAGE_CLIENT_ID` for an editor's save
|
|
96
|
+
* through the LSP head. Every subscriber receives the event, the saving
|
|
97
|
+
* client included, so compare against your own id to drop the echo.
|
|
88
98
|
*/
|
|
89
99
|
sourceClientId: string;
|
|
90
100
|
}
|
|
@@ -95,6 +105,28 @@ export type TransferDocumentSavedListener<
|
|
|
95
105
|
TDiagnostic extends TransferDiagnostic = TransferDiagnostic
|
|
96
106
|
> = (event: TransferDocumentSavedEvent<TTransfer, TDiagnostic>) => void;
|
|
97
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Delivered on the data-server when a watched document's text starts or stops
|
|
110
|
+
* differing from its file, as the server last knew the file. The current
|
|
111
|
+
* answer rides on every transfer document the server sends as `text.dirty`;
|
|
112
|
+
* this carries only its changes, so a client that follows it needs no rebuild
|
|
113
|
+
* to learn of a save.
|
|
114
|
+
*/
|
|
115
|
+
export interface TransferDocumentDirtyChangedEvent {
|
|
116
|
+
/** Canonical URI, keyed as the subscription is. */
|
|
117
|
+
readonly uri: string;
|
|
118
|
+
/**
|
|
119
|
+
* The text the answer was decided on. It is sent before that text is
|
|
120
|
+
* built, so a `text.version` ahead of the model a client holds means an
|
|
121
|
+
* update at this version or a later one follows. Absent when the document
|
|
122
|
+
* no longer exists, or when the build that follows its release failed.
|
|
123
|
+
*/
|
|
124
|
+
readonly text?: TextState;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Callback shape for `DataClientProtocol.onDocumentDirtyChanged`. */
|
|
128
|
+
export type TransferDocumentDirtyChangedListener = (event: TransferDocumentDirtyChangedEvent) => void;
|
|
129
|
+
|
|
98
130
|
/**
|
|
99
131
|
* Delivered on the data-server when a document's backing file was removed.
|
|
100
132
|
* Carries no document, and cannot: the state a
|
|
@@ -118,11 +150,25 @@ export type TransferDocumentSavedListener<
|
|
|
118
150
|
* A watch survives the deletion, so a file that comes back resumes delivering
|
|
119
151
|
* `onDocumentUpdated` to the same subscribers with no re-subscription. A
|
|
120
152
|
* client that responds by closing its editor releases the watch through
|
|
121
|
-
* `closeModelDocument` as usual
|
|
153
|
+
* `closeModelDocument` as usual, and `deleteModelDocument` releases the
|
|
154
|
+
* deleting session's own.
|
|
122
155
|
*/
|
|
123
156
|
export interface TransferDocumentDeletedEvent {
|
|
124
157
|
/** Canonical URI of the removed document, keyed as the subscription is. */
|
|
125
158
|
readonly uri: string;
|
|
159
|
+
/**
|
|
160
|
+
* The session whose `deleteModelDocument` removed the file, so it can tell
|
|
161
|
+
* its own deletion from another's; the unknown-client id for a file
|
|
162
|
+
* removed outside any session, as a file watcher reports one, and for one
|
|
163
|
+
* a `DataConnection` found gone after a reconnect, which no event named.
|
|
164
|
+
*/
|
|
165
|
+
readonly sourceClientId: string;
|
|
166
|
+
/**
|
|
167
|
+
* The position of this event among the update and deletion events the
|
|
168
|
+
* server sent on this connection, as on an update; absent on a deletion a
|
|
169
|
+
* `DataConnection` found after a reconnect, which the server never sent.
|
|
170
|
+
*/
|
|
171
|
+
readonly sequence?: number;
|
|
126
172
|
}
|
|
127
173
|
|
|
128
174
|
/** Callback shape for `DataClientProtocol.onDocumentDeleted`. */
|
package/src/data/requests.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import type {
|
|
10
|
+
import type { BaseVersion } from '../model-service/base-version';
|
|
11
11
|
|
|
12
12
|
/** Get the current state of a single document. The server returns the latest built version. */
|
|
13
13
|
export interface GetModelDocumentArgs {
|
|
@@ -41,29 +41,108 @@ export interface GetProjectForUriArgs {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* Update a document
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* without an args mapping.
|
|
44
|
+
* Update a document the session `clientId` has open. Generic over `TTransfer`
|
|
45
|
+
* so adopters parameterise the structured shape against their grammar's
|
|
46
|
+
* transfer-model overlay; passing a string is always allowed.
|
|
48
47
|
*/
|
|
49
|
-
export
|
|
48
|
+
export interface TransferUpdateDocumentArgs<TTransfer> {
|
|
49
|
+
/** Document URI. */
|
|
50
|
+
uri: string;
|
|
51
|
+
/** The id of a live session registered on this connection. */
|
|
52
|
+
clientId: string;
|
|
53
|
+
/** The whole structured model root, or its serialised textual form. */
|
|
54
|
+
model: TTransfer | string;
|
|
55
|
+
/**
|
|
56
|
+
* What this write was authored against. A `ModelVersion` is compared
|
|
57
|
+
* against the server's current text-document version for `uri` and throws
|
|
58
|
+
* `ConflictError` on mismatch; `'any'` writes unconditionally.
|
|
59
|
+
*
|
|
60
|
+
* **Required so that an ungated write is a decision rather than an
|
|
61
|
+
* omission.** An optional gate is indistinguishable from a forgotten one at
|
|
62
|
+
* the call site, and a file of twenty writes hides the one that lost the
|
|
63
|
+
* field. Nothing else here can see that, since the defect is an absence.
|
|
64
|
+
*/
|
|
65
|
+
baseVersion: BaseVersion;
|
|
66
|
+
/**
|
|
67
|
+
* Set by a session's restore after a reconnect, which sends its last write
|
|
68
|
+
* again. A model the server took was written over text that parsed, so it
|
|
69
|
+
* is written even over text that does not, as it was before the
|
|
70
|
+
* reconnect. Any other model write over such text is refused with
|
|
71
|
+
* `DocumentSyntaxError`, a save's even when it sets this.
|
|
72
|
+
*/
|
|
73
|
+
restore?: boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Update a document the session `clientId` has open, then persist it to disk. */
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type -- save names its own args; it adds no field to update's
|
|
78
|
+
export interface TransferSaveDocumentArgs<TTransfer> extends Omit<TransferUpdateDocumentArgs<TTransfer>, 'restore'> {}
|
|
79
|
+
|
|
80
|
+
/** Persist the text the server holds for a document the session `clientId` has open, without writing a model. */
|
|
81
|
+
export type TransferPersistDocumentArgs = Omit<TransferUpdateDocumentArgs<never>, 'model' | 'restore'>;
|
|
82
|
+
|
|
83
|
+
/** Delete a document the session `clientId` has open: its file, then the document. */
|
|
84
|
+
export type TransferDeleteDocumentArgs = Omit<TransferUpdateDocumentArgs<never>, 'model' | 'restore'>;
|
|
85
|
+
|
|
86
|
+
/** Register a client session on the connection. */
|
|
87
|
+
export interface CreateSessionArgs {
|
|
88
|
+
/** The session's id, minted by the client; unique in the server process while the session is live. */
|
|
89
|
+
clientId: string;
|
|
90
|
+
/** What the participant is; kept as the server session's `label`. */
|
|
91
|
+
label?: string;
|
|
92
|
+
/**
|
|
93
|
+
* A token the client keeps for the session's lifetime. It is no secret: the
|
|
94
|
+
* wire carries no authentication. A later `createSession` for the same id
|
|
95
|
+
* carrying the same token, from any connection, ends the session it names
|
|
96
|
+
* and registers the id afresh, so a client whose connection dropped before
|
|
97
|
+
* the server noticed can register again. Without it the id stays refused
|
|
98
|
+
* until the server notices.
|
|
99
|
+
*/
|
|
100
|
+
resumeToken?: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** End a client session registered on the connection. */
|
|
104
|
+
export interface CloseSessionArgs {
|
|
105
|
+
clientId: string;
|
|
106
|
+
}
|
|
50
107
|
|
|
51
|
-
/**
|
|
52
|
-
export
|
|
108
|
+
/** Create a document that exists nowhere yet, open for the session creating it. */
|
|
109
|
+
export interface CreateModelDocumentArgs {
|
|
110
|
+
uri: string;
|
|
111
|
+
/** The id of a live session registered on this connection. */
|
|
112
|
+
clientId: string;
|
|
113
|
+
/** The document's initial content; it reaches disk with the first save. */
|
|
114
|
+
text: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Write several documents a session has open, all or none. `clientId` is on
|
|
119
|
+
* the set rather than on each update: an id per update would allow a set
|
|
120
|
+
* mixing clients, which the server would have to refuse.
|
|
121
|
+
*/
|
|
122
|
+
export interface TransferUpdateDocumentsArgs<TTransfer> {
|
|
123
|
+
/** The id of a live session registered on this connection. */
|
|
124
|
+
clientId: string;
|
|
125
|
+
/**
|
|
126
|
+
* One entry per document: a set naming one twice, by any spellings that
|
|
127
|
+
* share its canonical URI, is refused.
|
|
128
|
+
*/
|
|
129
|
+
updates: Omit<TransferUpdateDocumentArgs<TTransfer>, 'clientId'>[];
|
|
130
|
+
}
|
|
53
131
|
|
|
54
132
|
/**
|
|
55
133
|
* Identifies a per-document watch on the data server. Shared by both
|
|
56
134
|
* `watchModelDocument` and `unwatchModelDocument` — the `(uri, clientId)`
|
|
57
135
|
* pair is the watch key, so unwatching names the same watch that was
|
|
58
136
|
* started. The `clientId` identifies the originator the same way it does
|
|
59
|
-
* on
|
|
60
|
-
* `
|
|
61
|
-
* bucket so multiple watchers on the same wire stay distinct, AND it lets
|
|
137
|
+
* on the document writes (`TransferUpdateDocumentArgs.clientId`,
|
|
138
|
+
* `TransferSaveDocumentArgs.clientId`): it keys the per-`(uri, clientId)`
|
|
139
|
+
* watch bucket so multiple watchers on the same wire stay distinct, AND it lets
|
|
62
140
|
* each watcher recognise its own echo on inbound `onDocumentUpdated` events
|
|
63
141
|
* (the wire shape's `sourceClientId` carries the originating mutation's
|
|
64
142
|
* `clientId`).
|
|
65
143
|
*/
|
|
66
144
|
export interface WatchModelDocumentArgs {
|
|
145
|
+
/** Any spelling that the document URI policy maps to the document. */
|
|
67
146
|
uri: string;
|
|
68
147
|
/** Stable identifier for the watching client. */
|
|
69
148
|
clientId: string;
|
package/src/debouncer.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import { type Clock } from './clock';
|
|
10
|
+
import { type Clock, type Stopwatch } from './clock';
|
|
11
11
|
import { ObservableValue, type MaybeObservableValue } from './observable-value';
|
|
12
12
|
import { type Disposable } from './util';
|
|
13
13
|
|
|
@@ -50,11 +50,13 @@ export interface DebouncerOptions {
|
|
|
50
50
|
* than a breaking change.
|
|
51
51
|
*/
|
|
52
52
|
export class Debouncer implements Disposable {
|
|
53
|
+
/** {@link DebouncerOptions.delayMs}, read at each {@link schedule}. An armed timer keeps the delay it was armed with. */
|
|
53
54
|
protected readonly delay: ObservableValue<number>;
|
|
55
|
+
/** {@link DebouncerOptions.maxWaitMs}, fixed at construction unlike {@link delay}. */
|
|
54
56
|
protected readonly maxWaitMs?: number;
|
|
55
57
|
protected timer?: Disposable;
|
|
56
|
-
/**
|
|
57
|
-
protected
|
|
58
|
+
/** Running since the first {@link schedule} of the current pending window; drives {@link DebouncerOptions.maxWaitMs}. */
|
|
59
|
+
protected sinceFirstSchedule?: Stopwatch;
|
|
58
60
|
|
|
59
61
|
constructor(
|
|
60
62
|
protected readonly clock: Clock,
|
|
@@ -77,20 +79,17 @@ export class Debouncer implements Disposable {
|
|
|
77
79
|
* elapses since the first pending call.
|
|
78
80
|
*/
|
|
79
81
|
schedule(): void {
|
|
80
|
-
|
|
81
|
-
if (this.firstScheduledAt === undefined) {
|
|
82
|
-
this.firstScheduledAt = now;
|
|
83
|
-
}
|
|
82
|
+
this.sinceFirstSchedule ??= this.clock.stopwatch();
|
|
84
83
|
let wait = Math.max(0, this.delay.value);
|
|
85
84
|
if (this.maxWaitMs !== undefined) {
|
|
86
|
-
const untilCeiling = this.
|
|
85
|
+
const untilCeiling = this.maxWaitMs - this.sinceFirstSchedule.elapsedMs;
|
|
87
86
|
wait = Math.min(wait, Math.max(0, untilCeiling));
|
|
88
87
|
}
|
|
89
88
|
this.timer?.dispose();
|
|
90
89
|
this.timer = this.clock.setTimer(() => this.fire(), wait);
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
/**
|
|
92
|
+
/** Run {@link fn} now if a fire is pending, clearing the window first, and do nothing otherwise. */
|
|
94
93
|
flush(): void {
|
|
95
94
|
if (this.timer !== undefined) {
|
|
96
95
|
this.fire();
|
|
@@ -101,7 +100,7 @@ export class Debouncer implements Disposable {
|
|
|
101
100
|
cancel(): void {
|
|
102
101
|
this.timer?.dispose();
|
|
103
102
|
this.timer = undefined;
|
|
104
|
-
this.
|
|
103
|
+
this.sinceFirstSchedule = undefined;
|
|
105
104
|
}
|
|
106
105
|
|
|
107
106
|
/** Cancel any pending fire and release. */
|
|
@@ -109,10 +108,11 @@ export class Debouncer implements Disposable {
|
|
|
109
108
|
this.cancel();
|
|
110
109
|
}
|
|
111
110
|
|
|
111
|
+
/** Clears the window before it runs {@link fn}, so a {@link schedule} from inside `fn` opens a new one. */
|
|
112
112
|
protected fire(): void {
|
|
113
113
|
this.timer?.dispose();
|
|
114
114
|
this.timer = undefined;
|
|
115
|
-
this.
|
|
115
|
+
this.sinceFirstSchedule = undefined;
|
|
116
116
|
this.fn();
|
|
117
117
|
}
|
|
118
118
|
}
|