@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.
Files changed (311) hide show
  1. package/README.md +46 -83
  2. package/lib/abstract-logger.d.ts +11 -0
  3. package/lib/abstract-logger.d.ts.map +1 -1
  4. package/lib/abstract-logger.js +16 -0
  5. package/lib/abstract-logger.js.map +1 -1
  6. package/lib/client/data-connection.d.ts +303 -0
  7. package/lib/client/data-connection.d.ts.map +1 -0
  8. package/lib/client/data-connection.js +534 -0
  9. package/lib/client/data-connection.js.map +1 -0
  10. package/lib/client/data-events.d.ts +11 -2
  11. package/lib/client/data-events.d.ts.map +1 -1
  12. package/lib/client/data-events.js +13 -1
  13. package/lib/client/data-events.js.map +1 -1
  14. package/lib/client/data-port.d.ts +34 -24
  15. package/lib/client/data-port.d.ts.map +1 -1
  16. package/lib/client/data-session.d.ts +762 -89
  17. package/lib/client/data-session.d.ts.map +1 -1
  18. package/lib/client/data-session.js +1253 -115
  19. package/lib/client/data-session.js.map +1 -1
  20. package/lib/client/index.d.ts +16 -9
  21. package/lib/client/index.d.ts.map +1 -1
  22. package/lib/client/index.js +16 -9
  23. package/lib/client/index.js.map +1 -1
  24. package/lib/client/message-relay.d.ts +6 -4
  25. package/lib/client/message-relay.d.ts.map +1 -1
  26. package/lib/client/message-relay.js +4 -4
  27. package/lib/client/message-relay.js.map +1 -1
  28. package/lib/client/post-message-transport.d.ts +69 -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 +173 -0
  33. package/lib/client/rpc-connection.d.ts.map +1 -0
  34. package/lib/client/rpc-connection.js +225 -0
  35. package/lib/client/rpc-connection.js.map +1 -0
  36. package/lib/client/worker-handshake.d.ts +94 -0
  37. package/lib/client/worker-handshake.d.ts.map +1 -0
  38. package/lib/client/worker-handshake.js +51 -0
  39. package/lib/client/worker-handshake.js.map +1 -0
  40. package/lib/client/working-copy.d.ts +420 -0
  41. package/lib/client/working-copy.d.ts.map +1 -0
  42. package/lib/client/working-copy.js +958 -0
  43. package/lib/client/working-copy.js.map +1 -0
  44. package/lib/client-ids.d.ts +45 -0
  45. package/lib/client-ids.d.ts.map +1 -0
  46. package/lib/client-ids.js +48 -0
  47. package/lib/client-ids.js.map +1 -0
  48. package/lib/clock.d.ts +50 -10
  49. package/lib/clock.d.ts.map +1 -1
  50. package/lib/clock.js +36 -1
  51. package/lib/clock.js.map +1 -1
  52. package/lib/console-logger.d.ts +23 -0
  53. package/lib/console-logger.d.ts.map +1 -0
  54. package/lib/console-logger.js +39 -0
  55. package/lib/console-logger.js.map +1 -0
  56. package/lib/data/data-protocol-methods.d.ts +4 -4
  57. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  58. package/lib/data/data-protocol-methods.js +7 -0
  59. package/lib/data/data-protocol-methods.js.map +1 -1
  60. package/lib/data/data-server-protocol.d.ts +160 -50
  61. package/lib/data/data-server-protocol.d.ts.map +1 -1
  62. package/lib/data/events.d.ts +75 -31
  63. package/lib/data/events.d.ts.map +1 -1
  64. package/lib/data/requests.d.ts +84 -11
  65. package/lib/data/requests.d.ts.map +1 -1
  66. package/lib/debouncer.d.ts +7 -4
  67. package/lib/debouncer.d.ts.map +1 -1
  68. package/lib/debouncer.js +10 -10
  69. package/lib/debouncer.js.map +1 -1
  70. package/lib/errors.d.ts +241 -48
  71. package/lib/errors.d.ts.map +1 -1
  72. package/lib/errors.js +395 -60
  73. package/lib/errors.js.map +1 -1
  74. package/lib/format-log-arg.d.ts +33 -0
  75. package/lib/format-log-arg.d.ts.map +1 -0
  76. package/lib/format-log-arg.js +158 -0
  77. package/lib/format-log-arg.js.map +1 -0
  78. package/lib/glsp-edits-settled-actions.d.ts +54 -0
  79. package/lib/glsp-edits-settled-actions.d.ts.map +1 -0
  80. package/lib/glsp-edits-settled-actions.js +28 -0
  81. package/lib/glsp-edits-settled-actions.js.map +1 -0
  82. package/lib/glsp-request-model-args.d.ts +16 -0
  83. package/lib/glsp-request-model-args.d.ts.map +1 -0
  84. package/lib/glsp-request-model-args.js +19 -0
  85. package/lib/glsp-request-model-args.js.map +1 -0
  86. package/lib/glsp-save-model-actions.d.ts +55 -0
  87. package/lib/glsp-save-model-actions.d.ts.map +1 -0
  88. package/lib/glsp-save-model-actions.js +28 -0
  89. package/lib/glsp-save-model-actions.js.map +1 -0
  90. package/lib/index.d.ts +11 -0
  91. package/lib/index.d.ts.map +1 -1
  92. package/lib/index.js +11 -0
  93. package/lib/index.js.map +1 -1
  94. package/lib/latency-collector.d.ts +10 -4
  95. package/lib/latency-collector.d.ts.map +1 -1
  96. package/lib/latency-collector.js +2 -0
  97. package/lib/latency-collector.js.map +1 -1
  98. package/lib/logger.d.ts +38 -7
  99. package/lib/logger.d.ts.map +1 -1
  100. package/lib/logger.js +42 -4
  101. package/lib/logger.js.map +1 -1
  102. package/lib/messages/index.d.ts +4 -2
  103. package/lib/messages/index.d.ts.map +1 -1
  104. package/lib/messages/index.js +17 -4
  105. package/lib/messages/index.js.map +1 -1
  106. package/lib/messages/primitives.d.ts +59 -4
  107. package/lib/messages/primitives.d.ts.map +1 -1
  108. package/lib/messages/primitives.js +97 -4
  109. package/lib/messages/primitives.js.map +1 -1
  110. package/lib/model-server.d.ts +58 -11
  111. package/lib/model-server.d.ts.map +1 -1
  112. package/lib/model-server.js +4 -2
  113. package/lib/model-server.js.map +1 -1
  114. package/lib/model-service/base-version.d.ts +67 -0
  115. package/lib/model-service/base-version.d.ts.map +1 -0
  116. package/lib/model-service/base-version.js +44 -0
  117. package/lib/model-service/base-version.js.map +1 -0
  118. package/lib/model-service/index.d.ts +1 -1
  119. package/lib/model-service/index.d.ts.map +1 -1
  120. package/lib/model-service/index.js +4 -5
  121. package/lib/model-service/index.js.map +1 -1
  122. package/lib/model-service/reference-candidate.d.ts +5 -3
  123. package/lib/model-service/reference-candidate.d.ts.map +1 -1
  124. package/lib/node/index.d.ts +10 -0
  125. package/lib/node/index.d.ts.map +1 -0
  126. package/lib/node/index.js +29 -0
  127. package/lib/node/index.js.map +1 -0
  128. package/lib/node/process-memory.d.ts +66 -0
  129. package/lib/node/process-memory.d.ts.map +1 -0
  130. package/lib/node/process-memory.js +291 -0
  131. package/lib/node/process-memory.js.map +1 -0
  132. package/lib/noop-logger.d.ts.map +1 -1
  133. package/lib/noop-logger.js.map +1 -1
  134. package/lib/observable-value.js.map +1 -1
  135. package/lib/patch-merge.d.ts +63 -35
  136. package/lib/patch-merge.d.ts.map +1 -1
  137. package/lib/patch-merge.js +171 -25
  138. package/lib/patch-merge.js.map +1 -1
  139. package/lib/pending-work-tracker.d.ts +33 -0
  140. package/lib/pending-work-tracker.d.ts.map +1 -0
  141. package/lib/pending-work-tracker.js +48 -0
  142. package/lib/pending-work-tracker.js.map +1 -0
  143. package/lib/profile-session.d.ts +24 -8
  144. package/lib/profile-session.d.ts.map +1 -1
  145. package/lib/profile-session.js +13 -4
  146. package/lib/profile-session.js.map +1 -1
  147. package/lib/profiling.d.ts +15 -2
  148. package/lib/profiling.d.ts.map +1 -1
  149. package/lib/profiling.js.map +1 -1
  150. package/lib/project.d.ts +6 -2
  151. package/lib/project.d.ts.map +1 -1
  152. package/lib/project.js.map +1 -1
  153. package/lib/random-uuid.d.ts +14 -0
  154. package/lib/random-uuid.d.ts.map +1 -0
  155. package/lib/random-uuid.js +24 -0
  156. package/lib/random-uuid.js.map +1 -0
  157. package/lib/reconcile-write.d.ts +70 -0
  158. package/lib/reconcile-write.d.ts.map +1 -0
  159. package/lib/reconcile-write.js +69 -0
  160. package/lib/reconcile-write.js.map +1 -0
  161. package/lib/rpc/bind-rpc-methods.d.ts +6 -2
  162. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  163. package/lib/rpc/bind-rpc-methods.js +17 -7
  164. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  165. package/lib/rpc/create-rpc-proxy.d.ts +3 -0
  166. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  167. package/lib/rpc/create-rpc-proxy.js +6 -1
  168. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  169. package/lib/rpc/index.d.ts +1 -0
  170. package/lib/rpc/index.d.ts.map +1 -1
  171. package/lib/rpc/index.js +1 -0
  172. package/lib/rpc/index.js.map +1 -1
  173. package/lib/rpc/send-by-method-name.d.ts +76 -0
  174. package/lib/rpc/send-by-method-name.d.ts.map +1 -0
  175. package/lib/rpc/send-by-method-name.js +120 -0
  176. package/lib/rpc/send-by-method-name.js.map +1 -0
  177. package/lib/rpc/wire-prefix.js.map +1 -1
  178. package/lib/save-text-document.d.ts +40 -0
  179. package/lib/save-text-document.d.ts.map +1 -0
  180. package/lib/save-text-document.js +34 -0
  181. package/lib/save-text-document.js.map +1 -0
  182. package/lib/testing/catalogue-audit.js.map +1 -1
  183. package/lib/testing/data-doubles.d.ts +36 -11
  184. package/lib/testing/data-doubles.d.ts.map +1 -1
  185. package/lib/testing/data-doubles.js +47 -9
  186. package/lib/testing/data-doubles.js.map +1 -1
  187. package/lib/testing/fake-clock.d.ts +17 -2
  188. package/lib/testing/fake-clock.d.ts.map +1 -1
  189. package/lib/testing/fake-clock.js +61 -46
  190. package/lib/testing/fake-clock.js.map +1 -1
  191. package/lib/testing/harness.d.ts +9 -0
  192. package/lib/testing/harness.d.ts.map +1 -1
  193. package/lib/testing/index.d.ts +1 -0
  194. package/lib/testing/index.d.ts.map +1 -1
  195. package/lib/testing/index.js +4 -3
  196. package/lib/testing/index.js.map +1 -1
  197. package/lib/testing/node/duplex-connection.d.ts.map +1 -1
  198. package/lib/testing/node/duplex-connection.js +3 -2
  199. package/lib/testing/node/duplex-connection.js.map +1 -1
  200. package/lib/testing/node/duplex-stream.js.map +1 -1
  201. package/lib/testing/node/index.d.ts +2 -0
  202. package/lib/testing/node/index.d.ts.map +1 -1
  203. package/lib/testing/node/index.js +3 -2
  204. package/lib/testing/node/index.js.map +1 -1
  205. package/lib/testing/node/message-port-pair.d.ts +25 -0
  206. package/lib/testing/node/message-port-pair.d.ts.map +1 -0
  207. package/lib/testing/node/message-port-pair.js +26 -0
  208. package/lib/testing/node/message-port-pair.js.map +1 -0
  209. package/lib/testing/node/unhandled-rejections.d.ts +20 -0
  210. package/lib/testing/node/unhandled-rejections.d.ts.map +1 -0
  211. package/lib/testing/node/unhandled-rejections.js +35 -0
  212. package/lib/testing/node/unhandled-rejections.js.map +1 -0
  213. package/lib/testing/transfer-node-builder.d.ts +81 -0
  214. package/lib/testing/transfer-node-builder.d.ts.map +1 -0
  215. package/lib/testing/transfer-node-builder.js +47 -0
  216. package/lib/testing/transfer-node-builder.js.map +1 -0
  217. package/lib/testing/wait-for.d.ts +9 -3
  218. package/lib/testing/wait-for.d.ts.map +1 -1
  219. package/lib/testing/wait-for.js +57 -11
  220. package/lib/testing/wait-for.js.map +1 -1
  221. package/lib/tracer.d.ts.map +1 -1
  222. package/lib/tracer.js +5 -9
  223. package/lib/tracer.js.map +1 -1
  224. package/lib/transfer-diagnostic.d.ts +11 -0
  225. package/lib/transfer-diagnostic.d.ts.map +1 -1
  226. package/lib/transfer-diagnostic.js +17 -0
  227. package/lib/transfer-diagnostic.js.map +1 -1
  228. package/lib/transfer-document.d.ts +108 -32
  229. package/lib/transfer-document.d.ts.map +1 -1
  230. package/lib/transfer-document.js +17 -9
  231. package/lib/transfer-document.js.map +1 -1
  232. package/lib/transfer-element.d.ts +4 -4
  233. package/lib/types.d.ts +32 -0
  234. package/lib/types.d.ts.map +1 -0
  235. package/lib/{model-service/args.js → types.js} +2 -2
  236. package/lib/types.js.map +1 -0
  237. package/lib/uri.d.ts.map +1 -1
  238. package/lib/uri.js.map +1 -1
  239. package/lib/util.d.ts +8 -2
  240. package/lib/util.d.ts.map +1 -1
  241. package/lib/util.js +32 -4
  242. package/lib/util.js.map +1 -1
  243. package/package.json +24 -40
  244. package/src/abstract-logger.ts +18 -0
  245. package/src/client/data-connection.ts +654 -0
  246. package/src/client/data-events.ts +15 -1
  247. package/src/client/data-port.ts +36 -25
  248. package/src/client/data-session.ts +1606 -137
  249. package/src/client/index.ts +16 -9
  250. package/src/client/message-relay.ts +6 -4
  251. package/src/client/post-message-transport.ts +224 -4
  252. package/src/client/rpc-connection.ts +302 -0
  253. package/src/client/worker-handshake.ts +121 -0
  254. package/src/client/working-copy.ts +1116 -0
  255. package/src/client-ids.ts +49 -0
  256. package/src/clock.ts +68 -10
  257. package/src/console-logger.ts +39 -0
  258. package/src/data/data-protocol-methods.ts +8 -1
  259. package/src/data/data-server-protocol.ts +184 -49
  260. package/src/data/events.ts +77 -31
  261. package/src/data/requests.ts +90 -11
  262. package/src/debouncer.ts +11 -11
  263. package/src/errors.ts +496 -71
  264. package/src/format-log-arg.ts +176 -0
  265. package/src/glsp-edits-settled-actions.ts +62 -0
  266. package/src/glsp-request-model-args.ts +16 -0
  267. package/src/glsp-save-model-actions.ts +64 -0
  268. package/src/index.ts +11 -0
  269. package/src/latency-collector.ts +10 -3
  270. package/src/logger.ts +44 -8
  271. package/src/messages/index.ts +12 -2
  272. package/src/messages/primitives.ts +129 -5
  273. package/src/model-server.ts +62 -17
  274. package/src/model-service/base-version.ts +75 -0
  275. package/src/model-service/index.ts +4 -5
  276. package/src/model-service/reference-candidate.ts +5 -3
  277. package/src/node/index.ts +14 -0
  278. package/src/node/process-memory.ts +299 -0
  279. package/src/patch-merge.ts +230 -45
  280. package/src/pending-work-tracker.ts +48 -0
  281. package/src/profile-session.ts +31 -11
  282. package/src/profiling.ts +15 -2
  283. package/src/project.ts +6 -2
  284. package/src/random-uuid.ts +21 -0
  285. package/src/reconcile-write.ts +131 -0
  286. package/src/rpc/README.md +6 -6
  287. package/src/rpc/bind-rpc-methods.ts +18 -8
  288. package/src/rpc/create-rpc-proxy.ts +6 -1
  289. package/src/rpc/index.ts +1 -0
  290. package/src/rpc/send-by-method-name.ts +140 -0
  291. package/src/save-text-document.ts +39 -0
  292. package/src/testing/data-doubles.ts +119 -19
  293. package/src/testing/fake-clock.ts +76 -48
  294. package/src/testing/harness.ts +10 -0
  295. package/src/testing/index.ts +4 -3
  296. package/src/testing/node/duplex-connection.ts +3 -2
  297. package/src/testing/node/index.ts +3 -2
  298. package/src/testing/node/message-port-pair.ts +40 -0
  299. package/src/testing/node/unhandled-rejections.ts +31 -0
  300. package/src/testing/transfer-node-builder.ts +107 -0
  301. package/src/testing/wait-for.ts +61 -13
  302. package/src/tracer.ts +5 -9
  303. package/src/transfer-diagnostic.ts +17 -0
  304. package/src/transfer-document.ts +130 -34
  305. package/src/transfer-element.ts +4 -4
  306. package/src/types.ts +30 -0
  307. package/src/util.ts +33 -6
  308. package/lib/model-service/args.d.ts +0 -64
  309. package/lib/model-service/args.d.ts.map +0 -1
  310. package/lib/model-service/args.js.map +0 -1
  311. package/src/model-service/args.ts +0 -67
@@ -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 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
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
- /** Stable identifier of the client that triggered the update. */
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 persisted to disk via
67
- * `DataServerProtocol.saveModelDocument`. Distinct from
68
- * {@link TransferDocumentUpdatedEvent}: subscribers that only care about
69
- * persistence (external sync, editor "saved" indicators, dirty-flag
70
- * clear) listen for this event family instead of filtering an update
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 `saveModelDocument` call produced this. Every subscriber
85
- * receives the event including the originator, which already had the same
86
- * state as the RPC response — compare against your own id to drop the echo
87
- * rather than re-rendering from it.
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`. */
@@ -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,29 +41,108 @@ 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
+ /**
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
- /** Persist a document to disk. Wire-side projection of {@link TransferSaveArgs}. */
52
- export type TransferSaveDocumentArgs<TTransfer> = TransferSaveArgs<TTransfer>;
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 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
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
- /** Virtual time of the first {@link schedule} of the current pending window; drives {@link DebouncerOptions.maxWaitMs}. */
57
- protected firstScheduledAt?: number;
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
- const now = this.clock.now();
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.firstScheduledAt + this.maxWaitMs - now;
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
- /** If a fire is pending, run {@link fn} now and clear the window; otherwise a no-op. */
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.firstScheduledAt = undefined;
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.firstScheduledAt = undefined;
115
+ this.sinceFirstSchedule = undefined;
116
116
  this.fn();
117
117
  }
118
118
  }