@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
@@ -9,53 +9,138 @@
9
9
 
10
10
  import type { TransferDiagnostic } from './transfer-diagnostic';
11
11
  import type { TransferElement } from './transfer-element';
12
+ import { asModelVersion, type ModelVersion, type TextVersion } from './model-service/base-version';
13
+
14
+ /** The model a data server built for a document, encoded for the wire. */
15
+ export interface TransferModelSnapshot<TRoot extends TransferElement, TDiagnostic = TransferDiagnostic> {
16
+ root: TRoot;
17
+ /** Absent until the document is validated; `[]` once it is and nothing was found. */
18
+ diagnostics?: TDiagnostic[];
19
+ /**
20
+ * The version of the text `root` was parsed from. A caller that mutates the
21
+ * model sends this back as the `baseVersion` of its write, and the server
22
+ * rejects the write with `ConflictError` once its text has moved past it.
23
+ */
24
+ version: ModelVersion;
25
+ /**
26
+ * The data server's fingerprint of `root` and `diagnostics`, or under its
27
+ * `'text-diagnostics'` strategy of the text `root` was parsed from and
28
+ * `diagnostics`.
29
+ * Independent of `version`; an equal hash also means equally validated.
30
+ */
31
+ hash: string;
32
+ }
33
+
34
+ /** The text a data server held for a document when it sent it. */
35
+ export interface TextState {
36
+ /**
37
+ * The server's version of that text. A `TransferModelSnapshot.version` below it
38
+ * means the model was parsed from older text, and an update at this version
39
+ * or a later one follows.
40
+ */
41
+ version: TextVersion;
42
+ /**
43
+ * What `textHash` makes of the text alone: equal texts hash equal whatever
44
+ * their version or dirty state, across a revert or a server restart that
45
+ * numbers versions afresh.
46
+ */
47
+ hash: string;
48
+ /**
49
+ * Whether the text differs from the file, as the server last knew the file.
50
+ * A later change arrives as `onDocumentDirtyChanged` to a client watching
51
+ * the document.
52
+ */
53
+ dirty: boolean;
54
+ }
12
55
 
13
56
  /**
14
57
  * Wire envelope exchanged between the model-server's data-server head and
15
- * its clients. Carries a transfer-shaped root — never an AST root — plus
16
- * the document's diagnostics in the adopter's wire-diagnostic shape.
58
+ * its clients: the server's model of a document and the text it holds for it,
59
+ * each absent where the server has none.
17
60
  *
18
61
  * The constraint `TTransfer extends TransferElement` pins the type system
19
62
  * to the wire data shape (no `$container` cycles, references as strings;
20
- * see {@link TransferElement}). The paired server-internal envelope is
21
- * `AstDocument<TAst extends AstNode, TDiagnostic>` in
22
- * `@hydranium/core` — same structural shape, different generic
23
- * constraint, used at the AST layer before the `TransferEncoder`
24
- * translation produces a {@link TransferDocument}.
63
+ * see {@link TransferElement}).
25
64
  */
26
65
  export interface TransferDocument<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic> {
66
+ /** Need not be spelled as the request named it. */
27
67
  uri: string;
28
68
  /**
29
- * The document version this snapshot was taken at — sourced from the
30
- * server's text-document version counter. Callers that mutate the
31
- * document subsequently pass this value back as `TransferUpdateArgs.baseVersion`
32
- * (or `TransferSaveArgs.baseVersion`) so the server can detect stale-based
33
- * updates and reject them with `ConflictError`.
34
- *
35
- * See `@hydranium/protocol#errors` for the conflict-detection contract.
36
- */
37
- version: number;
38
- /**
39
- * Absent when the document does not exist — the server answers an unknown URI
40
- * with a shaped envelope rather than an error, so absence is an ordinary
41
- * branch and not a catch. Declared required it reads as a guarantee, and
42
- * every `root.x` compiles into a throw.
69
+ * Absent when the document does not exist: the server answers an unknown
70
+ * URI with a shaped envelope rather than an error, so absence is an
71
+ * ordinary branch and not a catch.
43
72
  */
44
- root?: TTransfer;
45
- diagnostics: TDiagnostic[];
73
+ model?: TransferModelSnapshot<TTransfer, TDiagnostic>;
74
+ /** Absent when the server holds no text for the document. */
75
+ text?: TextState;
46
76
  }
47
77
 
48
78
  /**
49
- * A {@link TransferDocument} the server actually had, so `root` is present.
79
+ * A {@link TransferDocument} the server actually had, so `model` is present.
50
80
  * Narrowed to by {@link TransferDocument.isLoaded} / {@link TransferDocument.assertLoaded}.
51
81
  */
52
82
  export type LoadedTransferDocument<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic> = TransferDocument<
53
83
  TTransfer,
54
84
  TDiagnostic
55
85
  > & {
56
- root: TTransfer;
86
+ model: TransferModelSnapshot<TTransfer, TDiagnostic>;
87
+ };
88
+
89
+ /**
90
+ * What a save or a persist answers: the document, and in `persisted` the
91
+ * version of the text it wrote to the file. That can differ from
92
+ * `model.version` either way, since writes land between the build and the
93
+ * take, so a client marking a version saved takes it from here.
94
+ */
95
+ export type TransferSavedDocument<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic> = TransferDocument<
96
+ TTransfer,
97
+ TDiagnostic
98
+ > & {
99
+ persisted: { version: TextVersion };
57
100
  };
58
101
 
102
+ /**
103
+ * What an update answers: the document, and in `written` the version its text
104
+ * took. A `model.version` past it means the document was built from a later
105
+ * text, which holds a later write or an integrity repair too. A text
106
+ * version, not a model version, because the server may have normalized the
107
+ * text, so the writer does not hold the text at that version.
108
+ */
109
+ export type TransferWrittenDocument<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic> = TransferDocument<
110
+ TTransfer,
111
+ TDiagnostic
112
+ > & {
113
+ written: { version: TextVersion };
114
+ };
115
+
116
+ /**
117
+ * What a create answers: the document as a read after the create finds it,
118
+ * and in `created` the version the create's text took. Another client's write
119
+ * or an integrity repair can land between the create and that read, so
120
+ * `model.version` can be past it, and a write based on it would carry that
121
+ * text as the creator's; a write based on `created.version` conflicts instead.
122
+ * A model version, not a text version, because the creator holds the text at
123
+ * that version: it sent it.
124
+ */
125
+ export type TransferCreatedDocument<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic> = TransferDocument<
126
+ TTransfer,
127
+ TDiagnostic
128
+ > & {
129
+ created: { version: ModelVersion };
130
+ };
131
+
132
+ /** What a watch answers, once it is in place. */
133
+ export interface TransferWatchedDocument {
134
+ /** The key the watch's events name the document by, which need not be the spelling the watch was asked with. */
135
+ readonly uri: string;
136
+ /** Whether a document exists there; one the server fails to load counts, only a missing one does not. */
137
+ readonly exists: boolean;
138
+ /** The position of the last update or deletion event sent before `exists` was taken; an event past it was sent after. */
139
+ readonly sequence: number;
140
+ /** The text the server held when `exists` was taken, as a read answers it; absent when it held none. */
141
+ readonly text?: TextState;
142
+ }
143
+
59
144
  export namespace TransferDocument {
60
145
  /**
61
146
  * Whether the server had this document. Branch on it where absence is an
@@ -64,13 +149,13 @@ export namespace TransferDocument {
64
149
  export function isLoaded<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(
65
150
  document: TransferDocument<TTransfer, TDiagnostic>
66
151
  ): document is LoadedTransferDocument<TTransfer, TDiagnostic> {
67
- return document.root !== undefined;
152
+ return document.model !== undefined;
68
153
  }
69
154
 
70
155
  /**
71
- * The same document with `root` no longer optional, or a throw. For call
156
+ * The same document with `model` no longer optional, or a throw. For call
72
157
  * sites where absence is a bug rather than a branch; the whole envelope is
73
- * returned because a caller needing `root` usually needs `uri` or `version`
158
+ * returned because a caller needing `model` usually needs `uri` or `text`
74
159
  * with it.
75
160
  */
76
161
  export function assertLoaded<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(
@@ -82,18 +167,29 @@ export namespace TransferDocument {
82
167
  return document;
83
168
  }
84
169
 
170
+ /** The envelope for a document the server does not have. */
171
+ export function absent<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(
172
+ uri: string
173
+ ): TransferDocument<TTransfer, TDiagnostic> {
174
+ return { uri };
175
+ }
176
+
85
177
  /**
86
- * Construct a {@link TransferDocument} envelope. `diagnostics` defaults
87
- * to `[]` so test fixtures, fake protocol implementations, and the
88
- * "no diagnostics yet" code paths don't need to repeat the empty array
89
- * at every call site.
178
+ * Construct a {@link TransferDocument} envelope with a model, its version
179
+ * marked as coming from a read. `diagnostics` absent means not validated.
90
180
  */
91
181
  export function create<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(
92
182
  uri: string,
93
183
  version: number,
94
184
  root: TTransfer,
95
- diagnostics: TDiagnostic[] = []
185
+ hash: string,
186
+ diagnostics?: TDiagnostic[],
187
+ text?: TextState
96
188
  ): TransferDocument<TTransfer, TDiagnostic> {
97
- return { uri, version, root, diagnostics };
189
+ return {
190
+ uri,
191
+ model: { root, version: asModelVersion(version), hash, ...(diagnostics === undefined ? {} : { diagnostics }) },
192
+ ...(text === undefined ? {} : { text })
193
+ };
98
194
  }
99
195
  }
@@ -29,10 +29,10 @@ export interface TransferElement {
29
29
  * declared wire shape — or fall back to the structural base
30
30
  * {@link TransferElement} when no entry is declared.
31
31
  *
32
- * Adopters declare the overlay by interface merging or by generating an
33
- * interface keyed on those `$type` strings. Types not in the overlay resolve to
34
- * `TransferElement` — the framework default behaves correctly without an
35
- * overlay (no autocomplete, but no compile error either).
32
+ * The transfer-model generator emits the overlay as `<LanguageId>TransferTypes`;
33
+ * an encoder that relabels a type overrides that entry. Types not in the
34
+ * overlay resolve to `TransferElement` — the framework default behaves
35
+ * correctly without an overlay (no autocomplete, but no compile error either).
36
36
  *
37
37
  * The lookup is compile-time only; no runtime cost.
38
38
  */
package/src/types.ts ADDED
@@ -0,0 +1,30 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+
10
+ /**
11
+ * The keys of a type map, Langium's `<LanguageName>AstType` or the generated
12
+ * `<LanguageId>TransferTypes`, that a node can carry as its `$type`: those
13
+ * listed in their own type's `$type`. A union, or an abstract type whose
14
+ * `$type` names only its subtypes, has a constant too, but building one would
15
+ * yield a node that no guard accepts. A concrete type with subtypes lists its
16
+ * own name beside theirs, as Langium writes it, and stays buildable.
17
+ */
18
+ export type ConcreteTypeName<TMap> = {
19
+ [K in keyof TMap]: K extends (TMap[K] extends { readonly $type: infer TType } ? TType : never) ? K : never;
20
+ }[keyof TMap] &
21
+ string;
22
+
23
+ type IsUnion<T, TAll = T> = T extends unknown ? ([TAll] extends [T] ? false : true) : never;
24
+
25
+ /**
26
+ * Intersected onto a builder's type-constant parameter, refuses a constant
27
+ * typed by a union of type names: the init would hold only the members' common
28
+ * fields, so either type could be built incomplete.
29
+ */
30
+ export type SingleTypeName<TType> = true extends IsUnion<TType> ? { readonly $type: never } : unknown;
package/src/util.ts CHANGED
@@ -146,12 +146,6 @@ export function asMutable<T>(item: T): Mutable<T> {
146
146
  return item;
147
147
  }
148
148
 
149
- /** Type-guard variant: narrows `item` to `Mutable<T> | undefined` if `guard` accepts it. */
150
- export function toMutable<T>(item: unknown, guard: TypeGuard<T>): item is Mutable<T> | undefined;
151
- export function toMutable<T>(item: unknown, guard?: TypeGuard<T>): item is Mutable<T> | undefined {
152
- return guard ? guard(item) : true;
153
- }
154
-
155
149
  /**
156
150
  * Wrap `text` in `quoteChar`, escaping interior occurrences with `replaceChar`.
157
151
  *
@@ -248,3 +242,36 @@ export function getAt<T = unknown>(obj: unknown, path: string[]): T | undefined
248
242
  }
249
243
  return cur as T;
250
244
  }
245
+
246
+ /**
247
+ * A stable, non-cryptographic digest of `text`, equal on every host for equal
248
+ * text: the `TextState.hash` a data server stamps, so a client can
249
+ * hash text of its own to compare. An array is read as its elements joined, so
250
+ * a large text is hashed in parts without concatenating it. It tells whether a
251
+ * text changed, not who could forge one.
252
+ */
253
+ export function textHash(text: string | readonly string[]): string {
254
+ const { high, low } = cyrb53(typeof text === 'string' ? [text] : text);
255
+ return high.toString(16).padStart(8, '0') + low.toString(16).padStart(8, '0');
256
+ }
257
+
258
+ /**
259
+ * The two 32-bit words cyrb53 ends on, each unsigned, for `parts` read as one
260
+ * string. It needs no `node:*` module, so every host runs it.
261
+ */
262
+ function cyrb53(parts: readonly string[]): { readonly high: number; readonly low: number } {
263
+ let h1 = 0xdeadbeef;
264
+ let h2 = 0x41c6ce57;
265
+ for (const part of parts) {
266
+ for (let i = 0; i < part.length; i++) {
267
+ const code = part.charCodeAt(i);
268
+ h1 = Math.imul(h1 ^ code, 2654435761);
269
+ h2 = Math.imul(h2 ^ code, 1597334677);
270
+ }
271
+ }
272
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
273
+ h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
274
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
275
+ h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
276
+ return { high: h2 >>> 0, low: h1 >>> 0 };
277
+ }
@@ -1,64 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the MIT License which is available in the project root.
6
- *
7
- * SPDX-License-Identifier: MIT
8
- ********************************************************************************/
9
- /**
10
- * Argument shapes for the in-process `ModelService` facade — the
11
- * canonical home for the lifecycle operation signatures. Implementation
12
- * lives in `@hydranium/core/langium/model-service`; this protocol
13
- * package owns the types so wire-side projections (the data-server
14
- * protocol in `./data`) can structurally extend them rather than
15
- * mirroring them by hand.
16
- *
17
- * `./model-server.ts` re-exports them, so an import from either path
18
- * resolves.
19
- */
20
- /** Identifies a client-document binding. Every facade operation carries these fields. */
21
- export interface TransferClientArgs {
22
- /** Document URI. */
23
- uri: string;
24
- /** Stable identifier for the client invoking the operation. */
25
- clientId: string;
26
- }
27
- /**
28
- * Update a document's content via the in-process facade. `model` may be
29
- * the structured (transfer-model or AST) root or its serialised textual
30
- * form — implementations decide which is faster on their transport.
31
- * Generic over `T` so adopters parameterise the structured shape against
32
- * their grammar's transfer-model overlay; passing a string is always
33
- * allowed.
34
- */
35
- export interface TransferUpdateArgs<T> extends TransferClientArgs {
36
- /** Structured model root or its serialised textual form. */
37
- model: T | string;
38
- /**
39
- * Optional based-on version: the text-document version this update
40
- * was authored against. When set, the server compares against its
41
- * current text-document version for `uri` and throws
42
- * `ConflictError` on mismatch. Omit to opt out of the gate — mirrors
43
- * LSP's `OptionalVersionedTextDocumentIdentifier` posture, intended
44
- * for headless / CLI / batch tooling without a meaningful based-on
45
- * version.
46
- */
47
- baseVersion?: number;
48
- }
49
- /**
50
- * Persist a document to disk via the in-process facade. Same `model`
51
- * shape as {@link TransferUpdateArgs}.
52
- */
53
- export interface TransferSaveArgs<T> extends TransferClientArgs {
54
- /** Structured model root or its serialised textual form. */
55
- model: T | string;
56
- /**
57
- * Optional based-on version — same semantics as
58
- * {@link TransferUpdateArgs.baseVersion}. `save` delegates the gating
59
- * check to its inner `update`, so this field threads through to the
60
- * same `ConflictError` site.
61
- */
62
- baseVersion?: number;
63
- }
64
- //# sourceMappingURL=args.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/model-service/args.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;;;;;GAUG;AAEH,yFAAyF;AACzF,MAAM,WAAW,kBAAkB;IAChC,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,CAAE,SAAQ,kBAAkB;IAC9D,4DAA4D;IAC5D,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;IAClB;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,CAAE,SAAQ,kBAAkB;IAC5D,4DAA4D;IAC5D,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;IAClB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACvB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/model-service/args.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF"}
@@ -1,67 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the MIT License which is available in the project root.
6
- *
7
- * SPDX-License-Identifier: MIT
8
- ********************************************************************************/
9
-
10
- /**
11
- * Argument shapes for the in-process `ModelService` facade — the
12
- * canonical home for the lifecycle operation signatures. Implementation
13
- * lives in `@hydranium/core/langium/model-service`; this protocol
14
- * package owns the types so wire-side projections (the data-server
15
- * protocol in `./data`) can structurally extend them rather than
16
- * mirroring them by hand.
17
- *
18
- * `./model-server.ts` re-exports them, so an import from either path
19
- * resolves.
20
- */
21
-
22
- /** Identifies a client-document binding. Every facade operation carries these fields. */
23
- export interface TransferClientArgs {
24
- /** Document URI. */
25
- uri: string;
26
- /** Stable identifier for the client invoking the operation. */
27
- clientId: string;
28
- }
29
-
30
- /**
31
- * Update a document's content via the in-process facade. `model` may be
32
- * the structured (transfer-model or AST) root or its serialised textual
33
- * form — implementations decide which is faster on their transport.
34
- * Generic over `T` so adopters parameterise the structured shape against
35
- * their grammar's transfer-model overlay; passing a string is always
36
- * allowed.
37
- */
38
- export interface TransferUpdateArgs<T> extends TransferClientArgs {
39
- /** Structured model root or its serialised textual form. */
40
- model: T | string;
41
- /**
42
- * Optional based-on version: the text-document version this update
43
- * was authored against. When set, the server compares against its
44
- * current text-document version for `uri` and throws
45
- * `ConflictError` on mismatch. Omit to opt out of the gate — mirrors
46
- * LSP's `OptionalVersionedTextDocumentIdentifier` posture, intended
47
- * for headless / CLI / batch tooling without a meaningful based-on
48
- * version.
49
- */
50
- baseVersion?: number;
51
- }
52
-
53
- /**
54
- * Persist a document to disk via the in-process facade. Same `model`
55
- * shape as {@link TransferUpdateArgs}.
56
- */
57
- export interface TransferSaveArgs<T> extends TransferClientArgs {
58
- /** Structured model root or its serialised textual form. */
59
- model: T | string;
60
- /**
61
- * Optional based-on version — same semantics as
62
- * {@link TransferUpdateArgs.baseVersion}. `save` delegates the gating
63
- * check to its inner `update`, so this field threads through to the
64
- * same `ConflictError` site.
65
- */
66
- baseVersion?: number;
67
- }