@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.
Files changed (246) hide show
  1. package/README.md +39 -3
  2. package/lib/abstract-logger.d.ts +5 -0
  3. package/lib/abstract-logger.d.ts.map +1 -1
  4. package/lib/abstract-logger.js +7 -0
  5. package/lib/abstract-logger.js.map +1 -1
  6. package/lib/client/data-connection.d.ts +157 -0
  7. package/lib/client/data-connection.d.ts.map +1 -0
  8. package/lib/client/data-connection.js +237 -0
  9. package/lib/client/data-connection.js.map +1 -0
  10. package/lib/client/data-events.d.ts +13 -1
  11. package/lib/client/data-events.d.ts.map +1 -1
  12. package/lib/client/data-events.js +21 -0
  13. package/lib/client/data-events.js.map +1 -1
  14. package/lib/client/data-port.d.ts +24 -22
  15. package/lib/client/data-port.d.ts.map +1 -1
  16. package/lib/client/data-session.d.ts +471 -81
  17. package/lib/client/data-session.d.ts.map +1 -1
  18. package/lib/client/data-session.js +738 -108
  19. package/lib/client/data-session.js.map +1 -1
  20. package/lib/client/index.d.ts +14 -9
  21. package/lib/client/index.d.ts.map +1 -1
  22. package/lib/client/index.js +14 -9
  23. package/lib/client/index.js.map +1 -1
  24. package/lib/client/message-relay.d.ts +9 -3
  25. package/lib/client/message-relay.d.ts.map +1 -1
  26. package/lib/client/message-relay.js +11 -5
  27. package/lib/client/message-relay.js.map +1 -1
  28. package/lib/client/post-message-transport.d.ts +64 -3
  29. package/lib/client/post-message-transport.d.ts.map +1 -1
  30. package/lib/client/post-message-transport.js +175 -1
  31. package/lib/client/post-message-transport.js.map +1 -1
  32. package/lib/client/rpc-connection.d.ts +149 -0
  33. package/lib/client/rpc-connection.d.ts.map +1 -0
  34. package/lib/client/rpc-connection.js +202 -0
  35. package/lib/client/rpc-connection.js.map +1 -0
  36. package/lib/client-ids.d.ts +45 -0
  37. package/lib/client-ids.d.ts.map +1 -0
  38. package/lib/client-ids.js +48 -0
  39. package/lib/client-ids.js.map +1 -0
  40. package/lib/clock.d.ts +38 -0
  41. package/lib/clock.d.ts.map +1 -1
  42. package/lib/clock.js +36 -1
  43. package/lib/clock.js.map +1 -1
  44. package/lib/console-logger.d.ts +23 -0
  45. package/lib/console-logger.d.ts.map +1 -0
  46. package/lib/console-logger.js +39 -0
  47. package/lib/console-logger.js.map +1 -0
  48. package/lib/data/data-protocol-methods.d.ts +4 -4
  49. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  50. package/lib/data/data-protocol-methods.js +12 -1
  51. package/lib/data/data-protocol-methods.js.map +1 -1
  52. package/lib/data/data-server-protocol.d.ts +132 -41
  53. package/lib/data/data-server-protocol.d.ts.map +1 -1
  54. package/lib/data/events.d.ts +117 -21
  55. package/lib/data/events.d.ts.map +1 -1
  56. package/lib/data/requests.d.ts +69 -11
  57. package/lib/data/requests.d.ts.map +1 -1
  58. package/lib/debouncer.d.ts.map +1 -1
  59. package/lib/debouncer.js.map +1 -1
  60. package/lib/errors.d.ts +187 -29
  61. package/lib/errors.d.ts.map +1 -1
  62. package/lib/errors.js +270 -29
  63. package/lib/errors.js.map +1 -1
  64. package/lib/glsp-request-model-args.d.ts +16 -0
  65. package/lib/glsp-request-model-args.d.ts.map +1 -0
  66. package/lib/glsp-request-model-args.js +19 -0
  67. package/lib/glsp-request-model-args.js.map +1 -0
  68. package/lib/glsp-save-model-actions.d.ts +50 -0
  69. package/lib/glsp-save-model-actions.d.ts.map +1 -0
  70. package/lib/glsp-save-model-actions.js +28 -0
  71. package/lib/glsp-save-model-actions.js.map +1 -0
  72. package/lib/index.d.ts +7 -0
  73. package/lib/index.d.ts.map +1 -1
  74. package/lib/index.js +10 -0
  75. package/lib/index.js.map +1 -1
  76. package/lib/latency-collector.d.ts +8 -4
  77. package/lib/latency-collector.d.ts.map +1 -1
  78. package/lib/latency-collector.js.map +1 -1
  79. package/lib/logger.d.ts +22 -1
  80. package/lib/logger.d.ts.map +1 -1
  81. package/lib/logger.js +31 -3
  82. package/lib/logger.js.map +1 -1
  83. package/lib/messages/index.d.ts +29 -0
  84. package/lib/messages/index.d.ts.map +1 -0
  85. package/lib/messages/index.js +59 -0
  86. package/lib/messages/index.js.map +1 -0
  87. package/lib/messages/primitives.d.ts +188 -0
  88. package/lib/messages/primitives.d.ts.map +1 -0
  89. package/lib/messages/primitives.js +161 -0
  90. package/lib/messages/primitives.js.map +1 -0
  91. package/lib/model-server.d.ts +60 -13
  92. package/lib/model-server.d.ts.map +1 -1
  93. package/lib/model-server.js +4 -2
  94. package/lib/model-server.js.map +1 -1
  95. package/lib/model-service/base-version.d.ts +64 -0
  96. package/lib/model-service/base-version.d.ts.map +1 -0
  97. package/lib/model-service/base-version.js +43 -0
  98. package/lib/model-service/base-version.js.map +1 -0
  99. package/lib/model-service/index.d.ts +1 -1
  100. package/lib/model-service/index.d.ts.map +1 -1
  101. package/lib/model-service/index.js +4 -5
  102. package/lib/model-service/index.js.map +1 -1
  103. package/lib/model-service/reference-candidate.d.ts +5 -3
  104. package/lib/model-service/reference-candidate.d.ts.map +1 -1
  105. package/lib/{model-service/args.js → node/index.d.ts} +2 -3
  106. package/lib/node/index.d.ts.map +1 -0
  107. package/lib/node/index.js +29 -0
  108. package/lib/node/index.js.map +1 -0
  109. package/lib/node/process-memory.d.ts +66 -0
  110. package/lib/node/process-memory.d.ts.map +1 -0
  111. package/lib/node/process-memory.js +291 -0
  112. package/lib/node/process-memory.js.map +1 -0
  113. package/lib/noop-logger.d.ts.map +1 -1
  114. package/lib/noop-logger.js.map +1 -1
  115. package/lib/observable-value.js.map +1 -1
  116. package/lib/patch-merge.d.ts +35 -32
  117. package/lib/patch-merge.d.ts.map +1 -1
  118. package/lib/patch-merge.js +67 -23
  119. package/lib/patch-merge.js.map +1 -1
  120. package/lib/profile-session.d.ts +8 -4
  121. package/lib/profile-session.d.ts.map +1 -1
  122. package/lib/profile-session.js.map +1 -1
  123. package/lib/random-uuid.d.ts +14 -0
  124. package/lib/random-uuid.d.ts.map +1 -0
  125. package/lib/random-uuid.js +24 -0
  126. package/lib/random-uuid.js.map +1 -0
  127. package/lib/reconcile-write.d.ts +65 -0
  128. package/lib/reconcile-write.d.ts.map +1 -0
  129. package/lib/reconcile-write.js +67 -0
  130. package/lib/reconcile-write.js.map +1 -0
  131. package/lib/rpc/bind-rpc-methods.d.ts +33 -3
  132. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  133. package/lib/rpc/bind-rpc-methods.js +32 -3
  134. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  135. package/lib/rpc/create-rpc-proxy.d.ts +10 -0
  136. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  137. package/lib/rpc/create-rpc-proxy.js +12 -2
  138. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  139. package/lib/rpc/index.d.ts +1 -0
  140. package/lib/rpc/index.d.ts.map +1 -1
  141. package/lib/rpc/index.js +1 -0
  142. package/lib/rpc/index.js.map +1 -1
  143. package/lib/rpc/send-by-method-name.d.ts +76 -0
  144. package/lib/rpc/send-by-method-name.d.ts.map +1 -0
  145. package/lib/rpc/send-by-method-name.js +120 -0
  146. package/lib/rpc/send-by-method-name.js.map +1 -0
  147. package/lib/rpc/wire-prefix.js.map +1 -1
  148. package/lib/testing/catalogue-audit.d.ts +80 -0
  149. package/lib/testing/catalogue-audit.d.ts.map +1 -0
  150. package/lib/testing/catalogue-audit.js +94 -0
  151. package/lib/testing/catalogue-audit.js.map +1 -0
  152. package/lib/testing/data-doubles.d.ts +39 -15
  153. package/lib/testing/data-doubles.d.ts.map +1 -1
  154. package/lib/testing/data-doubles.js +57 -10
  155. package/lib/testing/data-doubles.js.map +1 -1
  156. package/lib/testing/fake-clock.d.ts +9 -1
  157. package/lib/testing/fake-clock.d.ts.map +1 -1
  158. package/lib/testing/fake-clock.js +54 -45
  159. package/lib/testing/fake-clock.js.map +1 -1
  160. package/lib/testing/index.d.ts +1 -0
  161. package/lib/testing/index.d.ts.map +1 -1
  162. package/lib/testing/index.js +5 -2
  163. package/lib/testing/index.js.map +1 -1
  164. package/lib/testing/node/duplex-connection.d.ts.map +1 -1
  165. package/lib/testing/node/duplex-connection.js +3 -2
  166. package/lib/testing/node/duplex-connection.js.map +1 -1
  167. package/lib/testing/node/duplex-stream.js.map +1 -1
  168. package/lib/testing/node/index.d.ts +1 -0
  169. package/lib/testing/node/index.d.ts.map +1 -1
  170. package/lib/testing/node/index.js +2 -2
  171. package/lib/testing/node/index.js.map +1 -1
  172. package/lib/testing/node/message-port-pair.d.ts +25 -0
  173. package/lib/testing/node/message-port-pair.d.ts.map +1 -0
  174. package/lib/testing/node/message-port-pair.js +26 -0
  175. package/lib/testing/node/message-port-pair.js.map +1 -0
  176. package/lib/testing/wait-for.js.map +1 -1
  177. package/lib/tracer.d.ts.map +1 -1
  178. package/lib/tracer.js.map +1 -1
  179. package/lib/transfer-diagnostic.d.ts +33 -0
  180. package/lib/transfer-diagnostic.d.ts.map +1 -1
  181. package/lib/transfer-diagnostic.js +23 -0
  182. package/lib/transfer-diagnostic.js.map +1 -1
  183. package/lib/transfer-document.d.ts +70 -32
  184. package/lib/transfer-document.d.ts.map +1 -1
  185. package/lib/transfer-document.js +17 -9
  186. package/lib/transfer-document.js.map +1 -1
  187. package/lib/uri.d.ts.map +1 -1
  188. package/lib/uri.js.map +1 -1
  189. package/lib/util.d.ts +8 -0
  190. package/lib/util.d.ts.map +1 -1
  191. package/lib/util.js +32 -0
  192. package/lib/util.js.map +1 -1
  193. package/package.json +29 -37
  194. package/src/abstract-logger.ts +8 -0
  195. package/src/client/data-connection.ts +315 -0
  196. package/src/client/data-events.ts +33 -1
  197. package/src/client/data-port.ts +25 -23
  198. package/src/client/data-session.ts +946 -126
  199. package/src/client/index.ts +14 -9
  200. package/src/client/message-relay.ts +29 -7
  201. package/src/client/post-message-transport.ts +219 -4
  202. package/src/client/rpc-connection.ts +268 -0
  203. package/src/client-ids.ts +49 -0
  204. package/src/clock.ts +56 -0
  205. package/src/console-logger.ts +39 -0
  206. package/src/data/data-protocol-methods.ts +13 -4
  207. package/src/data/data-server-protocol.ts +157 -41
  208. package/src/data/events.ts +123 -21
  209. package/src/data/requests.ts +74 -11
  210. package/src/errors.ts +322 -36
  211. package/src/glsp-request-model-args.ts +16 -0
  212. package/src/glsp-save-model-actions.ts +59 -0
  213. package/src/index.ts +10 -0
  214. package/src/latency-collector.ts +8 -3
  215. package/src/logger.ts +28 -2
  216. package/src/messages/index.ts +36 -0
  217. package/src/messages/primitives.ts +271 -0
  218. package/src/model-server.ts +63 -18
  219. package/src/model-service/base-version.ts +72 -0
  220. package/src/model-service/index.ts +4 -5
  221. package/src/model-service/reference-candidate.ts +5 -3
  222. package/src/node/index.ts +14 -0
  223. package/src/node/process-memory.ts +299 -0
  224. package/src/patch-merge.ts +97 -42
  225. package/src/profile-session.ts +9 -4
  226. package/src/random-uuid.ts +21 -0
  227. package/src/reconcile-write.ts +124 -0
  228. package/src/rpc/README.md +2 -3
  229. package/src/rpc/bind-rpc-methods.ts +59 -4
  230. package/src/rpc/create-rpc-proxy.ts +20 -2
  231. package/src/rpc/index.ts +1 -0
  232. package/src/rpc/send-by-method-name.ts +140 -0
  233. package/src/testing/catalogue-audit.ts +111 -0
  234. package/src/testing/data-doubles.ts +141 -25
  235. package/src/testing/fake-clock.ts +62 -47
  236. package/src/testing/index.ts +5 -2
  237. package/src/testing/node/duplex-connection.ts +3 -2
  238. package/src/testing/node/index.ts +2 -2
  239. package/src/testing/node/message-port-pair.ts +40 -0
  240. package/src/transfer-diagnostic.ts +40 -0
  241. package/src/transfer-document.ts +87 -34
  242. package/src/util.ts +33 -0
  243. package/lib/model-service/args.d.ts +0 -64
  244. package/lib/model-service/args.d.ts.map +0 -1
  245. package/lib/model-service/args.js.map +0 -1
  246. package/src/model-service/args.ts +0 -67
@@ -10,30 +10,36 @@
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 URI appeared in `DocumentBuilder.onUpdate`'s
20
- * `changed` list. The framework's underlying primitive is "this URI was
21
- * passed to `documentBuilder.update(changed, deleted)`", which spans
22
- * `didChange` text-document events, `notifyDidChangeTextDocument` calls,
23
- * and any programmatic `documentBuilder.update([uri], [])` invocation.
24
- * The name matches Langium's own `changed` parameter — it's vague-on-
25
- * purpose because the underlying primitive is.
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
- * - `'deleted'` — the URI appeared in `DocumentBuilder.onUpdate`'s
34
- * `deleted` list. The backing file was removed.
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
+ *
36
+ * Deletion is deliberately NOT a member. An update event carries a built
37
+ * document, which a deleted one has none of, and the phase-driven path that
38
+ * produces these events never runs for a deleted URI — the builder drops the
39
+ * document before deriving the rebuild set. It travels as
40
+ * {@link TransferDocumentDeletedEvent} on its own channel instead.
35
41
  */
36
- export type TransferDocumentUpdateReason = 'changed' | 'rebuilt' | 'saved' | 'deleted';
42
+ export type TransferDocumentUpdateReason = 'changed' | 'rebuilt' | 'saved';
37
43
 
38
44
  /**
39
45
  * Delivered on the data-server when a document's content (or existence)
@@ -47,7 +53,13 @@ export interface TransferDocumentUpdatedEvent<
47
53
  TDiagnostic extends TransferDiagnostic = TransferDiagnostic
48
54
  > {
49
55
  document: TransferDocument<TTransfer, TDiagnostic>;
50
- /** Stable identifier of the client that triggered the update. */
56
+ /**
57
+ * The client whose write this event echoes: the author of the version on a
58
+ * `'changed'`, and the unknown-client id on a `'rebuilt'`, which echoes no
59
+ * write. A recipient compares it against its own id to recognise its echo.
60
+ * The build that follows a document's release names the release id
61
+ * instead.
62
+ */
51
63
  sourceClientId: string;
52
64
  reason: TransferDocumentUpdateReason;
53
65
  }
@@ -60,8 +72,8 @@ export type TransferDocumentUpdatedListener<
60
72
 
61
73
  /**
62
74
  * Delivered on the data-server when a document was persisted to disk via
63
- * `DataServerProtocol.saveModelDocument`. Distinct from
64
- * {@link TransferDocumentUpdatedEvent}: subscribers that only care about
75
+ * `DataServerProtocol.saveModelDocument` or `persistModelDocument`. Distinct
76
+ * from {@link TransferDocumentUpdatedEvent}: subscribers that only care about
65
77
  * persistence (external sync, editor "saved" indicators, dirty-flag
66
78
  * clear) listen for this event family instead of filtering an update
67
79
  * stream for `reason: 'saved'`.
@@ -77,10 +89,11 @@ export interface TransferDocumentSavedEvent<
77
89
  > {
78
90
  document: TransferDocument<TTransfer, TDiagnostic>;
79
91
  /**
80
- * The client whose `saveModelDocument` call produced this. Every subscriber
81
- * receives the event including the originator, which already had the same
82
- * state as the RPC response — compare against your own id to drop the echo
83
- * rather than re-rendering from it.
92
+ * The client whose `saveModelDocument` or `persistModelDocument` call
93
+ * produced this, also when another client wrote the persisted text. Every
94
+ * subscriber receives the event including the originator, which already had
95
+ * the same state as the RPC response — compare against your own id to drop
96
+ * the echo rather than re-rendering from it.
84
97
  */
85
98
  sourceClientId: string;
86
99
  }
@@ -91,6 +104,95 @@ export type TransferDocumentSavedListener<
91
104
  TDiagnostic extends TransferDiagnostic = TransferDiagnostic
92
105
  > = (event: TransferDocumentSavedEvent<TTransfer, TDiagnostic>) => void;
93
106
 
107
+ /**
108
+ * Delivered on the data-server when a watched document's text starts or stops
109
+ * differing from its file, as the server last knew the file. The current
110
+ * answer rides on every transfer document the server sends as `text.dirty`;
111
+ * this carries only its changes, so a client that follows it needs no rebuild
112
+ * to learn of a save.
113
+ */
114
+ export interface TransferDocumentDirtyChangedEvent {
115
+ /** Canonical URI, keyed as the subscription is. */
116
+ readonly uri: string;
117
+ /**
118
+ * The text the answer was decided on. It is sent before that text is
119
+ * built, so a `text.version` ahead of the model a client holds means an
120
+ * update at this version or a later one follows. Absent when the document
121
+ * no longer exists, or when the build that follows its release failed.
122
+ */
123
+ readonly text?: TextState;
124
+ }
125
+
126
+ /** Callback shape for `DataClientProtocol.onDocumentDirtyChanged`. */
127
+ export type TransferDocumentDirtyChangedListener = (event: TransferDocumentDirtyChangedEvent) => void;
128
+
129
+ /**
130
+ * Delivered on the data-server when a document's backing file was removed.
131
+ * Carries no document, and cannot: the state a
132
+ * {@link TransferDocumentUpdatedEvent} would have to carry no longer exists by
133
+ * the time anyone can be told. That is also why deletion is not a `reason` on
134
+ * the update stream — `DocumentBuilder.update` drops the document before
135
+ * deriving the rebuild set, so the phase-driven path that produces update
136
+ * events never runs for it.
137
+ *
138
+ * **Delivered for EVERY document, not only watched ones**, unlike
139
+ * `onDocumentUpdated` and `onDocumentSaved`. The test that decides which
140
+ * channels are gated is whether any OTHER source can observe the fact on the
141
+ * least capable host: a browser-hosted client's workspace lives behind the
142
+ * head, so nothing there can see a file disappear, and gating the notification
143
+ * would leave it blind. (A Theia frontend's filesystem watcher would cover it,
144
+ * which is why this is a host argument and not a structure-versus-content one.)
145
+ * A watcher is told about its own document's deletion here too, the update
146
+ * channel being silent for deletions by construction. Filter on {@link uri} if
147
+ * the receiver only cares about documents it opened.
148
+ *
149
+ * A watch survives the deletion, so a file that comes back resumes delivering
150
+ * `onDocumentUpdated` to the same subscribers with no re-subscription. A
151
+ * client that responds by closing its editor releases the watch through
152
+ * `closeModelDocument` as usual.
153
+ */
154
+ export interface TransferDocumentDeletedEvent {
155
+ /** Canonical URI of the removed document, keyed as the subscription is. */
156
+ readonly uri: string;
157
+ }
158
+
159
+ /** Callback shape for `DataClientProtocol.onDocumentDeleted`. */
160
+ export type TransferDocumentDeletedListener = (event: TransferDocumentDeletedEvent) => void;
161
+
162
+ /**
163
+ * Delivered on the data-server once per build, naming the documents that reached
164
+ * the configured subscription phase (`DataServerOptions.subscriptionPhase`,
165
+ * `Validated` by default) and that NO client on the connection is watching. Not
166
+ * the integrity-settled landmark, which is a different point and a different
167
+ * word in this framework.
168
+ *
169
+ * The complement of {@link TransferDocumentUpdatedEvent}, which is gated per
170
+ * URI: together the two cover every document a build touched. This one exists
171
+ * for the case no source outside the server can observe — a document rebuilt
172
+ * because something it DEPENDS ON changed. Its own file never changed, so a
173
+ * filesystem watcher cannot see it, and it has no subscriber, so the update
174
+ * channel does not report it. A consumer showing data derived from such a
175
+ * document (a tree label, a decorator) would otherwise hold a stale value with
176
+ * nothing to invalidate it.
177
+ *
178
+ * Carries URIs and no documents: a recipient re-reads what it displays, through
179
+ * `getModelDocument` or its own request. That keeps the bandwidth property the
180
+ * per-URI subscription exists for, without gating the message.
181
+ *
182
+ * Not sent when the set is empty, which is the normal case while editing — the
183
+ * document being edited is watched by its own editor and therefore excluded.
184
+ * Workspace initialisation sends nothing either: it does not build to the
185
+ * subscription phase. The largest message a workspace can produce is therefore
186
+ * a whole-workspace rebuild at that phase, which is one message of URIs.
187
+ */
188
+ export interface TransferDocumentsBuiltEvent {
189
+ /** Canonical URIs, keyed as subscriptions are. Never empty. */
190
+ readonly uris: readonly string[];
191
+ }
192
+
193
+ /** Callback shape for `DataClientProtocol.onDocumentsBuilt`. */
194
+ export type TransferDocumentsBuiltListener = (event: TransferDocumentsBuiltEvent) => void;
195
+
94
196
  /**
95
197
  * Why a project-change event fired. `added` — the project was newly
96
198
  * registered (descriptor discovered); `updated` — the project's
@@ -7,7 +7,7 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
- import type { TransferSaveArgs, TransferUpdateArgs } from '../model-service/args';
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,24 +41,87 @@ export interface GetProjectForUriArgs {
41
41
  }
42
42
 
43
43
  /**
44
- * Update a document's content. Wire-side projection of the facade's
45
- * {@link TransferUpdateArgs}; structurally identical so the data-server RPC
46
- * handler can forward straight to the in-process `ModelService.update`
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 type TransferUpdateDocumentArgs<TTransfer> = TransferUpdateArgs<TTransfer>;
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
+ }
50
67
 
51
- /** Persist a document to disk. Wire-side projection of {@link TransferSaveArgs}. */
52
- export type TransferSaveDocumentArgs<TTransfer> = TransferSaveArgs<TTransfer>;
68
+ /** Update a document the session `clientId` has open, then persist it to disk. */
69
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
70
+ export interface TransferSaveDocumentArgs<TTransfer> extends TransferUpdateDocumentArgs<TTransfer> {}
71
+
72
+ /** Persist the text the server holds for a document the session `clientId` has open, without writing a model. */
73
+ export type TransferPersistDocumentArgs = Omit<TransferUpdateDocumentArgs<never>, 'model'>;
74
+
75
+ /** Register a client session on the connection. */
76
+ export interface CreateSessionArgs {
77
+ /** The session's id, minted by the client; unique in the server process while the session is live. */
78
+ clientId: string;
79
+ /** What the participant is; kept as the server session's `label`. */
80
+ label?: string;
81
+ /**
82
+ * A token the client keeps for the session's lifetime. It is no secret: the
83
+ * wire carries no authentication. A later `createSession` for the same id
84
+ * carrying the same token, from any connection, ends the session it names
85
+ * and registers the id afresh, so a client whose connection dropped before
86
+ * the server noticed can register again. Without it the id stays refused
87
+ * until the server notices.
88
+ */
89
+ resumeToken?: string;
90
+ }
91
+
92
+ /** End a client session registered on the connection. */
93
+ export interface CloseSessionArgs {
94
+ clientId: string;
95
+ }
96
+
97
+ /** Create a document that exists nowhere yet, open for the session creating it. */
98
+ export interface CreateModelDocumentArgs {
99
+ uri: string;
100
+ /** The id of a live session registered on this connection. */
101
+ clientId: string;
102
+ /** The document's initial content; it reaches disk with the first save. */
103
+ text: string;
104
+ }
105
+
106
+ /**
107
+ * Write several documents a session has open, all or none. `clientId` is on
108
+ * the set rather than on each update: an id per update would allow a set
109
+ * mixing clients, which the server would have to refuse.
110
+ */
111
+ export interface TransferUpdateDocumentsArgs<TTransfer> {
112
+ /** The id of a live session registered on this connection. */
113
+ clientId: string;
114
+ updates: Omit<TransferUpdateDocumentArgs<TTransfer>, 'clientId'>[];
115
+ }
53
116
 
54
117
  /**
55
118
  * Identifies a per-document watch on the data server. Shared by both
56
119
  * `watchModelDocument` and `unwatchModelDocument` — the `(uri, clientId)`
57
120
  * pair is the watch key, so unwatching names the same watch that was
58
121
  * started. The `clientId` identifies the originator the same way it does
59
- * on facade-side mutations (`TransferUpdateArgs.clientId`,
60
- * `TransferSaveArgs.clientId`): it keys the per-`(uri, clientId)` watch
61
- * bucket so multiple watchers on the same wire stay distinct, AND it lets
122
+ * on the document writes (`TransferUpdateDocumentArgs.clientId`,
123
+ * `TransferSaveDocumentArgs.clientId`): it keys the per-`(uri, clientId)`
124
+ * watch bucket so multiple watchers on the same wire stay distinct, AND it lets
62
125
  * each watcher recognise its own echo on inbound `onDocumentUpdated` events
63
126
  * (the wire shape's `sourceClientId` carries the originating mutation's
64
127
  * `clientId`).