@hydranium/protocol 1.0.0-next.37 → 1.0.0-next.371

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 (294) hide show
  1. package/README.md +44 -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 +18 -1
  11. package/lib/client/data-events.d.ts.map +1 -1
  12. package/lib/client/data-events.js +26 -0
  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 +691 -89
  17. package/lib/client/data-session.d.ts.map +1 -1
  18. package/lib/client/data-session.js +1155 -115
  19. package/lib/client/data-session.js.map +1 -1
  20. package/lib/client/index.d.ts +15 -9
  21. package/lib/client/index.d.ts.map +1 -1
  22. package/lib/client/index.js +15 -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-ids.d.ts +45 -0
  41. package/lib/client-ids.d.ts.map +1 -0
  42. package/lib/client-ids.js +48 -0
  43. package/lib/client-ids.js.map +1 -0
  44. package/lib/clock.d.ts +50 -10
  45. package/lib/clock.d.ts.map +1 -1
  46. package/lib/clock.js +36 -1
  47. package/lib/clock.js.map +1 -1
  48. package/lib/console-logger.d.ts +23 -0
  49. package/lib/console-logger.d.ts.map +1 -0
  50. package/lib/console-logger.js +39 -0
  51. package/lib/console-logger.js.map +1 -0
  52. package/lib/data/data-protocol-methods.d.ts +4 -4
  53. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  54. package/lib/data/data-protocol-methods.js +13 -1
  55. package/lib/data/data-protocol-methods.js.map +1 -1
  56. package/lib/data/data-server-protocol.d.ts +171 -48
  57. package/lib/data/data-server-protocol.d.ts.map +1 -1
  58. package/lib/data/events.d.ts +144 -33
  59. package/lib/data/events.d.ts.map +1 -1
  60. package/lib/data/requests.d.ts +76 -11
  61. package/lib/data/requests.d.ts.map +1 -1
  62. package/lib/debouncer.d.ts +7 -4
  63. package/lib/debouncer.d.ts.map +1 -1
  64. package/lib/debouncer.js +10 -10
  65. package/lib/debouncer.js.map +1 -1
  66. package/lib/errors.d.ts +218 -41
  67. package/lib/errors.d.ts.map +1 -1
  68. package/lib/errors.js +364 -55
  69. package/lib/errors.js.map +1 -1
  70. package/lib/format-log-arg.d.ts +33 -0
  71. package/lib/format-log-arg.d.ts.map +1 -0
  72. package/lib/format-log-arg.js +158 -0
  73. package/lib/format-log-arg.js.map +1 -0
  74. package/lib/glsp-edits-settled-actions.d.ts +54 -0
  75. package/lib/glsp-edits-settled-actions.d.ts.map +1 -0
  76. package/lib/glsp-edits-settled-actions.js +28 -0
  77. package/lib/glsp-edits-settled-actions.js.map +1 -0
  78. package/lib/glsp-request-model-args.d.ts +16 -0
  79. package/lib/glsp-request-model-args.d.ts.map +1 -0
  80. package/lib/glsp-request-model-args.js +19 -0
  81. package/lib/glsp-request-model-args.js.map +1 -0
  82. package/lib/glsp-save-model-actions.d.ts +55 -0
  83. package/lib/glsp-save-model-actions.d.ts.map +1 -0
  84. package/lib/glsp-save-model-actions.js +28 -0
  85. package/lib/glsp-save-model-actions.js.map +1 -0
  86. package/lib/index.d.ts +11 -0
  87. package/lib/index.d.ts.map +1 -1
  88. package/lib/index.js +11 -0
  89. package/lib/index.js.map +1 -1
  90. package/lib/latency-collector.d.ts +10 -4
  91. package/lib/latency-collector.d.ts.map +1 -1
  92. package/lib/latency-collector.js +2 -0
  93. package/lib/latency-collector.js.map +1 -1
  94. package/lib/logger.d.ts +38 -7
  95. package/lib/logger.d.ts.map +1 -1
  96. package/lib/logger.js +42 -4
  97. package/lib/logger.js.map +1 -1
  98. package/lib/messages/index.d.ts +4 -2
  99. package/lib/messages/index.d.ts.map +1 -1
  100. package/lib/messages/index.js +16 -4
  101. package/lib/messages/index.js.map +1 -1
  102. package/lib/messages/primitives.d.ts +59 -4
  103. package/lib/messages/primitives.d.ts.map +1 -1
  104. package/lib/messages/primitives.js +97 -4
  105. package/lib/messages/primitives.js.map +1 -1
  106. package/lib/model-server.d.ts +60 -13
  107. package/lib/model-server.d.ts.map +1 -1
  108. package/lib/model-server.js +4 -2
  109. package/lib/model-server.js.map +1 -1
  110. package/lib/model-service/base-version.d.ts +67 -0
  111. package/lib/model-service/base-version.d.ts.map +1 -0
  112. package/lib/model-service/base-version.js +44 -0
  113. package/lib/model-service/base-version.js.map +1 -0
  114. package/lib/model-service/index.d.ts +1 -1
  115. package/lib/model-service/index.d.ts.map +1 -1
  116. package/lib/model-service/index.js +4 -5
  117. package/lib/model-service/index.js.map +1 -1
  118. package/lib/model-service/reference-candidate.d.ts +5 -3
  119. package/lib/model-service/reference-candidate.d.ts.map +1 -1
  120. package/lib/node/index.d.ts +10 -0
  121. package/lib/node/index.d.ts.map +1 -0
  122. package/lib/node/index.js +29 -0
  123. package/lib/node/index.js.map +1 -0
  124. package/lib/node/process-memory.d.ts +66 -0
  125. package/lib/node/process-memory.d.ts.map +1 -0
  126. package/lib/node/process-memory.js +291 -0
  127. package/lib/node/process-memory.js.map +1 -0
  128. package/lib/noop-logger.d.ts.map +1 -1
  129. package/lib/noop-logger.js.map +1 -1
  130. package/lib/observable-value.js.map +1 -1
  131. package/lib/patch-merge.d.ts +63 -35
  132. package/lib/patch-merge.d.ts.map +1 -1
  133. package/lib/patch-merge.js +171 -25
  134. package/lib/patch-merge.js.map +1 -1
  135. package/lib/pending-work-tracker.d.ts +30 -0
  136. package/lib/pending-work-tracker.d.ts.map +1 -0
  137. package/lib/pending-work-tracker.js +47 -0
  138. package/lib/pending-work-tracker.js.map +1 -0
  139. package/lib/profile-session.d.ts +24 -8
  140. package/lib/profile-session.d.ts.map +1 -1
  141. package/lib/profile-session.js +13 -4
  142. package/lib/profile-session.js.map +1 -1
  143. package/lib/profiling.d.ts +15 -2
  144. package/lib/profiling.d.ts.map +1 -1
  145. package/lib/profiling.js.map +1 -1
  146. package/lib/project.d.ts +6 -2
  147. package/lib/project.d.ts.map +1 -1
  148. package/lib/project.js.map +1 -1
  149. package/lib/random-uuid.d.ts +14 -0
  150. package/lib/random-uuid.d.ts.map +1 -0
  151. package/lib/random-uuid.js +24 -0
  152. package/lib/random-uuid.js.map +1 -0
  153. package/lib/reconcile-write.d.ts +70 -0
  154. package/lib/reconcile-write.d.ts.map +1 -0
  155. package/lib/reconcile-write.js +69 -0
  156. package/lib/reconcile-write.js.map +1 -0
  157. package/lib/rpc/bind-rpc-methods.d.ts +6 -2
  158. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  159. package/lib/rpc/bind-rpc-methods.js +17 -7
  160. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  161. package/lib/rpc/create-rpc-proxy.d.ts +3 -0
  162. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  163. package/lib/rpc/create-rpc-proxy.js +6 -1
  164. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  165. package/lib/rpc/index.d.ts +1 -0
  166. package/lib/rpc/index.d.ts.map +1 -1
  167. package/lib/rpc/index.js +1 -0
  168. package/lib/rpc/index.js.map +1 -1
  169. package/lib/rpc/send-by-method-name.d.ts +76 -0
  170. package/lib/rpc/send-by-method-name.d.ts.map +1 -0
  171. package/lib/rpc/send-by-method-name.js +120 -0
  172. package/lib/rpc/send-by-method-name.js.map +1 -0
  173. package/lib/rpc/wire-prefix.js.map +1 -1
  174. package/lib/save-text-document.d.ts +40 -0
  175. package/lib/save-text-document.d.ts.map +1 -0
  176. package/lib/save-text-document.js +34 -0
  177. package/lib/save-text-document.js.map +1 -0
  178. package/lib/testing/catalogue-audit.js.map +1 -1
  179. package/lib/testing/data-doubles.d.ts +41 -12
  180. package/lib/testing/data-doubles.d.ts.map +1 -1
  181. package/lib/testing/data-doubles.js +56 -8
  182. package/lib/testing/data-doubles.js.map +1 -1
  183. package/lib/testing/fake-clock.d.ts +17 -2
  184. package/lib/testing/fake-clock.d.ts.map +1 -1
  185. package/lib/testing/fake-clock.js +61 -46
  186. package/lib/testing/fake-clock.js.map +1 -1
  187. package/lib/testing/index.d.ts +1 -0
  188. package/lib/testing/index.d.ts.map +1 -1
  189. package/lib/testing/index.js +4 -3
  190. package/lib/testing/index.js.map +1 -1
  191. package/lib/testing/node/duplex-connection.d.ts.map +1 -1
  192. package/lib/testing/node/duplex-connection.js +3 -2
  193. package/lib/testing/node/duplex-connection.js.map +1 -1
  194. package/lib/testing/node/duplex-stream.js.map +1 -1
  195. package/lib/testing/node/index.d.ts +1 -0
  196. package/lib/testing/node/index.d.ts.map +1 -1
  197. package/lib/testing/node/index.js +2 -2
  198. package/lib/testing/node/index.js.map +1 -1
  199. package/lib/testing/node/message-port-pair.d.ts +25 -0
  200. package/lib/testing/node/message-port-pair.d.ts.map +1 -0
  201. package/lib/testing/node/message-port-pair.js +26 -0
  202. package/lib/testing/node/message-port-pair.js.map +1 -0
  203. package/lib/testing/transfer-node-builder.d.ts +81 -0
  204. package/lib/testing/transfer-node-builder.d.ts.map +1 -0
  205. package/lib/testing/transfer-node-builder.js +47 -0
  206. package/lib/testing/transfer-node-builder.js.map +1 -0
  207. package/lib/testing/wait-for.d.ts +9 -3
  208. package/lib/testing/wait-for.d.ts.map +1 -1
  209. package/lib/testing/wait-for.js +57 -11
  210. package/lib/testing/wait-for.js.map +1 -1
  211. package/lib/tracer.d.ts.map +1 -1
  212. package/lib/tracer.js +5 -9
  213. package/lib/tracer.js.map +1 -1
  214. package/lib/transfer-diagnostic.js.map +1 -1
  215. package/lib/transfer-document.d.ts +96 -32
  216. package/lib/transfer-document.d.ts.map +1 -1
  217. package/lib/transfer-document.js +17 -9
  218. package/lib/transfer-document.js.map +1 -1
  219. package/lib/transfer-element.d.ts +4 -4
  220. package/lib/types.d.ts +32 -0
  221. package/lib/types.d.ts.map +1 -0
  222. package/lib/{model-service/args.js → types.js} +2 -2
  223. package/lib/types.js.map +1 -0
  224. package/lib/uri.d.ts.map +1 -1
  225. package/lib/uri.js.map +1 -1
  226. package/lib/util.d.ts +8 -2
  227. package/lib/util.d.ts.map +1 -1
  228. package/lib/util.js +32 -4
  229. package/lib/util.js.map +1 -1
  230. package/package.json +24 -40
  231. package/src/abstract-logger.ts +18 -0
  232. package/src/client/data-connection.ts +654 -0
  233. package/src/client/data-events.ts +38 -1
  234. package/src/client/data-port.ts +36 -25
  235. package/src/client/data-session.ts +1476 -137
  236. package/src/client/index.ts +15 -9
  237. package/src/client/message-relay.ts +6 -4
  238. package/src/client/post-message-transport.ts +224 -4
  239. package/src/client/rpc-connection.ts +302 -0
  240. package/src/client/worker-handshake.ts +121 -0
  241. package/src/client-ids.ts +49 -0
  242. package/src/clock.ts +68 -10
  243. package/src/console-logger.ts +39 -0
  244. package/src/data/data-protocol-methods.ts +14 -4
  245. package/src/data/data-server-protocol.ts +198 -48
  246. package/src/data/events.ts +150 -33
  247. package/src/data/requests.ts +82 -11
  248. package/src/debouncer.ts +11 -11
  249. package/src/errors.ts +453 -65
  250. package/src/format-log-arg.ts +176 -0
  251. package/src/glsp-edits-settled-actions.ts +62 -0
  252. package/src/glsp-request-model-args.ts +16 -0
  253. package/src/glsp-save-model-actions.ts +64 -0
  254. package/src/index.ts +11 -0
  255. package/src/latency-collector.ts +10 -3
  256. package/src/logger.ts +44 -8
  257. package/src/messages/index.ts +11 -2
  258. package/src/messages/primitives.ts +129 -5
  259. package/src/model-server.ts +64 -19
  260. package/src/model-service/base-version.ts +75 -0
  261. package/src/model-service/index.ts +4 -5
  262. package/src/model-service/reference-candidate.ts +5 -3
  263. package/src/node/index.ts +14 -0
  264. package/src/node/process-memory.ts +299 -0
  265. package/src/patch-merge.ts +230 -45
  266. package/src/pending-work-tracker.ts +47 -0
  267. package/src/profile-session.ts +31 -11
  268. package/src/profiling.ts +15 -2
  269. package/src/project.ts +6 -2
  270. package/src/random-uuid.ts +21 -0
  271. package/src/reconcile-write.ts +131 -0
  272. package/src/rpc/README.md +6 -6
  273. package/src/rpc/bind-rpc-methods.ts +18 -8
  274. package/src/rpc/create-rpc-proxy.ts +6 -1
  275. package/src/rpc/index.ts +1 -0
  276. package/src/rpc/send-by-method-name.ts +140 -0
  277. package/src/save-text-document.ts +39 -0
  278. package/src/testing/data-doubles.ts +141 -19
  279. package/src/testing/fake-clock.ts +76 -48
  280. package/src/testing/index.ts +4 -3
  281. package/src/testing/node/duplex-connection.ts +3 -2
  282. package/src/testing/node/index.ts +2 -2
  283. package/src/testing/node/message-port-pair.ts +40 -0
  284. package/src/testing/transfer-node-builder.ts +107 -0
  285. package/src/testing/wait-for.ts +61 -13
  286. package/src/tracer.ts +5 -9
  287. package/src/transfer-document.ts +116 -34
  288. package/src/transfer-element.ts +4 -4
  289. package/src/types.ts +30 -0
  290. package/src/util.ts +33 -6
  291. package/lib/model-service/args.d.ts +0 -64
  292. package/lib/model-service/args.d.ts.map +0 -1
  293. package/lib/model-service/args.js.map +0 -1
  294. package/src/model-service/args.ts +0 -67
@@ -9,11 +9,11 @@
9
9
  import type { TransferDiagnostic } from '../transfer-diagnostic';
10
10
  import type { TransferElement } from '../transfer-element';
11
11
  import type { Project } from '../project';
12
- import type { TransferDocument } from '../transfer-document';
12
+ import type { TransferCreatedDocument, TransferDocument, TransferSavedDocument, TransferWatchedDocument } from '../transfer-document';
13
13
  import type { CloseModelArgs, FindNextNameArgs, OpenModelArgs, ReferenceContext, ReferenceRequest } from '../model-server';
14
14
  import type { ReferenceCandidate, ReferenceTarget } from '../model-service/reference-candidate';
15
- import type { ProjectsChangedEvent, TransferDocumentSavedEvent, TransferDocumentUpdatedEvent } from './events';
16
- import type { GetModelDocumentArgs, GetProjectForUriArgs, TransferSaveDocumentArgs, WatchModelDocumentArgs, TransferUpdateDocumentArgs } from './requests';
15
+ import type { ProjectsChangedEvent, TransferDocumentDeletedEvent, TransferDocumentDirtyChangedEvent, TransferDocumentSavedEvent, TransferDocumentsBuiltEvent, TransferDocumentUpdatedEvent } from './events';
16
+ import type { CloseSessionArgs, CreateModelDocumentArgs, CreateSessionArgs, GetModelDocumentArgs, GetProjectForUriArgs, TransferDeleteDocumentArgs, TransferPersistDocumentArgs, TransferSaveDocumentArgs, WatchModelDocumentArgs, TransferUpdateDocumentArgs, TransferUpdateDocumentsArgs } from './requests';
17
17
  /**
18
18
  * Document-scoped slice of the data-server wire contract: the per-document
19
19
  * lifecycle (get / update / save), the per-`(uri, clientId)` watch
@@ -32,34 +32,75 @@ import type { GetModelDocumentArgs, GetProjectForUriArgs, TransferSaveDocumentAr
32
32
  */
33
33
  export interface DocumentServerProtocol<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic> {
34
34
  /**
35
- * Open a document for an editor session and return its current state.
36
- * Registers `(uri, clientId)` with the multi-client document manager
37
- * (so concurrent editors share one built document) and returns the
38
- * document at the server's configured target phase — the same shape
39
- * {@link getModelDocument} returns, except that `version` is taken from
40
- * the text-document store so the caller's first `baseVersion` write
41
- * cannot self-conflict. Idempotent in registration terms: opening an
42
- * already-open document refreshes the client registration. Note it does
43
- * NOT avoid a rebuild — a second client attaching triggers
44
- * `refreshContent`, which fires a change event, so mounting a form on a
45
- * document already open in a text editor rebuilds it.
35
+ * Register `args.clientId` as a client session owned by this connection.
36
+ * Rejects with a `DuplicateClientIdError` code when the id is live anywhere
37
+ * in the server process, and with a `ReservedClientIdError` code when the
38
+ * framework reserves it.
46
39
  *
47
- * The default `DataServer` impl delegates to `ModelService.open` then
48
- * reads the built state. Pair with {@link watchModelDocument} to receive
49
- * subsequent build-phase events (open returns a one-shot snapshot;
50
- * later validation diagnostics arrive on the watch channel).
40
+ * A request carrying a registered id acts as that session: it writes only
41
+ * what the session has open, failing with a `DocumentNotOpenError` code
42
+ * otherwise, and opens nothing implicitly; its open reads the file and takes
43
+ * no `languageId`, `version` or `text` seed. The session ends with
44
+ * {@link closeSession} or when the connection closes, and either closes
45
+ * every document it has open.
46
+ *
47
+ * A registration carrying the `resumeToken` an earlier registration of the
48
+ * same id carried ends that session first, from any connection, so a client
49
+ * whose connection dropped can register again before the server notices.
50
+ */
51
+ createSession(args: CreateSessionArgs): Promise<void>;
52
+ /**
53
+ * End a session this connection registered: close every document it has
54
+ * open, drop its watches, and free its id. A no-op for an id this
55
+ * connection did not register.
51
56
  */
52
- openModelDocument(args: OpenModelArgs): Promise<TransferDocument<TTransfer, TDiagnostic>>;
57
+ closeSession(args: CloseSessionArgs): Promise<void>;
53
58
  /**
54
- * Close an editor session for `(uri, clientId)`. Counterpart to
55
- * {@link openModelDocument}; the underlying document stays built until
56
- * every registered client has closed. The default `DataServer` impl
57
- * delegates to `ModelService.close` and ALSO releases any watch for the
58
- * same `(uri, clientId)` (closing a session frees its own watch — a
59
- * forgotten {@link unwatchModelDocument} would otherwise leak dispatch;
60
- * the implicit unwatch is idempotent). `watchModelDocument` is NOT
61
- * coupled the other way: opening does not force a watch, so a snapshot
62
- * reader can open without streaming.
59
+ * Create a document with `args.text`, open for the session, and return it
60
+ * as {@link openModelDocument} does, with the version the create made in
61
+ * `created`. The answer is read after the create, so it can already hold
62
+ * another client's write or an integrity repair; a write based on
63
+ * `created.version` then conflicts. It reaches disk with the first save.
64
+ * Fails when the file exists, any client has the URI open, or a lost
65
+ * client's unsaved text is held for it, and with a
66
+ * `SessionClosedError` code when `args.clientId` is not a session
67
+ * registered on this connection.
68
+ */
69
+ createModelDocument(args: CreateModelDocumentArgs): Promise<TransferCreatedDocument<TTransfer, TDiagnostic>>;
70
+ /**
71
+ * Write several documents the session has open, all or none: a conflict or
72
+ * a document not open fails the whole set before any text applies.
73
+ * Resolves to the documents in the order given, once the language client
74
+ * has answered the push of each, or the server-side bound on that wait
75
+ * passes, as {@link updateModelDocument} does. Only for a session
76
+ * registered on this connection.
77
+ */
78
+ updateModelDocuments(args: TransferUpdateDocumentsArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>[]>;
79
+ /**
80
+ * Open a document for the client session `clientId` and return its current
81
+ * state. `clientId` must be a session this connection registered with
82
+ * {@link createSession}; any other id fails with the closed-session code,
83
+ * as every document request here does. The document is read from disk
84
+ * unless a client has it open already, so the request carries no
85
+ * `languageId`, `version` or `text` seed. Returns the document at
86
+ * the server's configured target phase, as {@link getModelDocument} does.
87
+ * A repeat open changes nothing.
88
+ *
89
+ * Pair with {@link watchModelDocument} to receive subsequent build-phase
90
+ * events (open returns a one-shot snapshot; later validation diagnostics
91
+ * arrive on the watch channel).
92
+ */
93
+ openModelDocument(args: Pick<OpenModelArgs, 'uri' | 'clientId' | 'options'>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
94
+ /**
95
+ * Close the session's open of `uri`. Counterpart to
96
+ * {@link openModelDocument}; the document stays open until every client
97
+ * has closed it, and then the server releases it, by default reverting it
98
+ * to disk. The default
99
+ * `DataServer` impl ALSO releases any watch for the same
100
+ * `(uri, clientId)` (a forgotten {@link unwatchModelDocument} would
101
+ * otherwise leak dispatch; the implicit unwatch is idempotent).
102
+ * `watchModelDocument` is NOT coupled the other way: opening does not force
103
+ * a watch, so a snapshot reader can open without streaming.
63
104
  */
64
105
  closeModelDocument(args: CloseModelArgs): Promise<void>;
65
106
  /**
@@ -70,32 +111,68 @@ export interface DocumentServerProtocol<TTransfer extends TransferElement, TDiag
70
111
  */
71
112
  getModelDocument(args: GetModelDocumentArgs): Promise<TransferDocument<TTransfer, TDiagnostic>>;
72
113
  /**
73
- * Update a document's content. The response carries the latest built
74
- * state including diagnostics; callers observe convergence via that
75
- * response.
114
+ * Update a document's content as the session `clientId`, which must have
115
+ * it open. The response carries the latest built state including
116
+ * diagnostics; callers observe convergence via that response. It is sent
117
+ * once the language client has answered the push of the text, or the
118
+ * server-side bound on that wait passes, as {@link saveModelDocument}'s
119
+ * is, so an editor already shows the write when it arrives.
76
120
  */
77
121
  updateModelDocument(args: TransferUpdateDocumentArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
78
122
  /**
79
- * Persist a document to disk. The response is the post-save document
80
- * state (matches the file on disk). Save semantics depend on the
81
- * filesystem-provider wiring; rejection paths surface as awaited
123
+ * Write a document as the session `clientId`, which must have it open, and
124
+ * persist it to disk. The response is the build of the text written, with
125
+ * its version in `persisted`, sent once the language client has answered
126
+ * the push of that text, applied or refused, or a server-side bound on
127
+ * that wait passes; it does not wait again for a push that wait already
128
+ * gave up on and the client has not answered since. Save semantics depend
129
+ * on the filesystem-provider wiring; rejection paths surface as awaited
82
130
  * promise rejections.
83
131
  */
84
- saveModelDocument(args: TransferSaveDocumentArgs<TTransfer>): Promise<TransferDocument<TTransfer, TDiagnostic>>;
132
+ saveModelDocument(args: TransferSaveDocumentArgs<TTransfer>): Promise<TransferSavedDocument<TTransfer, TDiagnostic>>;
133
+ /**
134
+ * Persist the text the server holds for a document the session `clientId`
135
+ * has open, as it is: no update and no serialisation, so another client's
136
+ * unsaved text keeps its formatting. `baseVersion` is checked in the step
137
+ * that takes the text, so text that moved on fails with a `ConflictError`
138
+ * code. The saved event names this session, whoever wrote the text.
139
+ * Answers after the same language-client wait as {@link saveModelDocument},
140
+ * with the document's latest build, read after that wait, so another
141
+ * session's write during it shows; `persisted` carries the version written.
142
+ */
143
+ persistModelDocument(args: TransferPersistDocumentArgs): Promise<TransferSavedDocument<TTransfer, TDiagnostic>>;
144
+ /**
145
+ * Delete a document the session `clientId` has open, at once: its file,
146
+ * then the document, as a deletion a file watcher reports removes it. Every
147
+ * session's open of it closes and every client hears
148
+ * {@link DocumentClientProtocol.onDocumentDeleted} naming this session; the
149
+ * session's own watch is released, as {@link closeModelDocument} releases
150
+ * it. `baseVersion` is checked in the step that marks the document for
151
+ * deletion, so text that moved on fails with a `ConflictError` code. A file
152
+ * already gone deletes only the document; a file that cannot be removed
153
+ * fails the call and changes nothing. Resolves once the build that removes
154
+ * the document has run; a read then answers the URI without a model, unless
155
+ * an editor still has it open, whose buffer the document is built from.
156
+ */
157
+ deleteModelDocument(args: TransferDeleteDocumentArgs): Promise<void>;
85
158
  /**
86
159
  * Start watching `(uri, clientId)`. The server starts dispatching
87
160
  * {@link DocumentClientProtocol.onDocumentUpdated} on the paired wire
88
161
  * for every build-phase event on `uri`.
89
162
  *
90
- * Returns `Promise<void>` — the bidirectional pattern means the event
91
- * channel is the client interface, not a returned handle. Callers fan
92
- * out a single inbound `onDocumentUpdated` to multiple local listeners
93
- * with their own `Emitter<T>` (matching Theia's pattern). Pair every
94
- * `watchModelDocument` with {@link unwatchModelDocument} when no longer
95
- * needed; the server holds the watch record until the matching unwatch
96
- * lands.
163
+ * Answers with the key the watch's events name the document by, whether
164
+ * a document exists, taken once the watch is in place and the document
165
+ * is loaded as a read loads it, the text held at that moment, and the
166
+ * position of the last update or deletion event sent as of it, so an event
167
+ * the client heard while the watch was in flight tells by its own position
168
+ * whether it is newer than the answer. No handle: the event channel is the
169
+ * client interface. Callers fan out a single inbound `onDocumentUpdated` to
170
+ * multiple local listeners with their own `Emitter<T>` (matching Theia's
171
+ * pattern). Pair every `watchModelDocument` with
172
+ * {@link unwatchModelDocument} when no longer needed; the server holds the
173
+ * watch record until the matching unwatch lands.
97
174
  */
98
- watchModelDocument(args: WatchModelDocumentArgs): Promise<void>;
175
+ watchModelDocument(args: WatchModelDocumentArgs): Promise<TransferWatchedDocument>;
99
176
  /**
100
177
  * Stop watching `(uri, clientId)` previously started by
101
178
  * {@link watchModelDocument}. Idempotent — unwatching twice is a no-op.
@@ -171,6 +248,19 @@ export interface ProjectServerProtocol<TProject extends Project = Project> {
171
248
  */
172
249
  export interface DataServerProtocol<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic, TProject extends Project = Project> extends DocumentServerProtocol<TTransfer, TDiagnostic>, ProjectServerProtocol<TProject> {
173
250
  }
251
+ /**
252
+ * The diagnostic shape a server answers with, read back off its own
253
+ * declaration.
254
+ *
255
+ * This is what lets a client tier stay generic over the server alone and still
256
+ * describe what it hands back. Both parameters must be inferred: naming
257
+ * {@link TransferElement} for the transfer instead fails to match while that
258
+ * parameter is still generic, and a default declared against the constraint
259
+ * then stops satisfying it.
260
+ */
261
+ export type DiagnosticOf<TServer> = TServer extends DocumentServerProtocol<infer _TTransfer, infer TDiagnostic> ? TDiagnostic : TransferDiagnostic;
262
+ /** The project shape a server answers with, read back off its own declaration. */
263
+ export type ProjectOf<TServer> = TServer extends ProjectServerProtocol<infer TProject> ? TProject : Project;
174
264
  /**
175
265
  * Cross-reference / naming slice of the server surface — scope-aware
176
266
  * queries that resolve against the language's reference services. NOT part
@@ -181,11 +271,11 @@ export interface DataServerProtocol<TTransfer extends TransferElement, TDiagnost
181
271
  * source/URI (an `ElementSource` with no URI resolves to the sole
182
272
  * registered language; a multi-language workspace overrides).
183
273
  *
184
- * Generic over the transfer root type only — the resolution result
185
- * ({@link ReferenceTarget}) carries the resolved node's encoded subtree;
186
- * candidates and names are diagnostic-free.
274
+ * Not generic over a server's root type: {@link resolveReference} answers with
275
+ * a node a reference names, which is no document root, and candidates and
276
+ * names are diagnostic-free.
187
277
  */
188
- export interface ReferenceServerProtocol<TTransfer extends TransferElement> {
278
+ export interface ReferenceServerProtocol {
189
279
  /**
190
280
  * List the reference candidates reachable for the property named in `ctx`
191
281
  * from its (possibly synthetic) source. Backed by the language's
@@ -197,8 +287,11 @@ export interface ReferenceServerProtocol<TTransfer extends TransferElement> {
197
287
  * target's document URI, display fields, and the resolved node's encoded
198
288
  * transfer subtree. Resolves via the language's reference services;
199
289
  * `undefined` when the reference does not resolve.
290
+ *
291
+ * `TElement` is the caller's claim about the target node's type; nothing
292
+ * checks it, so leave it at the default unless the reference names one type.
200
293
  */
201
- resolveReference(ref: ReferenceRequest): Promise<ReferenceTarget<TTransfer> | undefined>;
294
+ resolveReference<TElement extends TransferElement = TransferElement>(ref: ReferenceRequest): Promise<ReferenceTarget<TElement> | undefined>;
202
295
  /**
203
296
  * Compute the next free name for a new element of `args.type` based on
204
297
  * `args.proposal`, unique within the `args.tier` scope (default
@@ -235,6 +328,36 @@ export interface DocumentClientProtocol<TTransfer extends TransferElement, TDiag
235
328
  * codepath, not a subscription codepath).
236
329
  */
237
330
  onDocumentSaved(event: TransferDocumentSavedEvent<TTransfer, TDiagnostic>): void;
331
+ /**
332
+ * Delivered when a subscribed document's text starts or stops differing
333
+ * from its file, as the server last knew it. Gated like
334
+ * {@link onDocumentSaved}; the answer at any one moment is the `dirty` of
335
+ * the documents the server sends. After a reconnect, a `DataSession`
336
+ * delivers here the answer of each document it restored, when that differs
337
+ * from the last this client was told: the flips while the connection was
338
+ * down reached no one.
339
+ */
340
+ onDocumentDirtyChanged(event: TransferDocumentDirtyChangedEvent): void;
341
+ /**
342
+ * Delivered when a document's backing file was removed. Separate from
343
+ * {@link onDocumentUpdated} for the same reason as {@link onDocumentSaved},
344
+ * and more strongly: there is no built state to deliver, and the build-phase
345
+ * path cannot report a deletion at all.
346
+ *
347
+ * Ungated, because on a browser host — where the workspace lives behind the
348
+ * head — no other source can observe a file disappearing. Recipients that
349
+ * only care about their own documents filter by URI.
350
+ */
351
+ onDocumentDeleted(event: TransferDocumentDeletedEvent): void;
352
+ /**
353
+ * Delivered once per build, naming the documents that reached the
354
+ * subscription phase and that
355
+ * nobody on this connection watches — chiefly the ones rebuilt as a cascade
356
+ * from a dependency's change, which no filesystem watcher can see because
357
+ * their own files did not change. The complement of
358
+ * {@link onDocumentUpdated}; carries URIs and no documents.
359
+ */
360
+ onDocumentsBuilt(event: TransferDocumentsBuiltEvent): void;
238
361
  }
239
362
  /**
240
363
  * Project-scoped slice of the client surface — the project-registry change
@@ -1 +1 @@
1
- {"version":3,"file":"data-server-protocol.d.ts","sourceRoot":"","sources":["../../src/data/data-server-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC3H,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAChG,OAAO,KAAK,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAC/G,OAAO,KAAK,EACT,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,EAC5B,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,sBAAsB,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,SAAS,kBAAkB,GAAG,kBAAkB;IACnI;;;;;;;;;;;;;;;;;OAiBG;IACH,iBAAiB,CAAC,IAAI,EAAE,aAAa,GAAG,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,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE,qBAAqB,CAAC,QAAQ,CAAC;CAAG"}
@@ -9,69 +9,180 @@
9
9
  import type { TransferDiagnostic } from '../transfer-diagnostic';
10
10
  import type { TransferElement } from '../transfer-element';
11
11
  import type { Project } from '../project';
12
- import type { TransferDocument } from '../transfer-document';
12
+ import type { TextState, TransferDocument } from '../transfer-document';
13
13
  /**
14
14
  * Why an update event fired. Subscribers filter on reason for behaviour
15
15
  * decisions (e.g. dirty-flag handling, undo-history grouping, telemetry):
16
16
  *
17
- * - `'changed'` — the URI appeared in `DocumentBuilder.onUpdate`'s
18
- * `changed` list. The framework's underlying primitive is "this URI was
19
- * passed to `documentBuilder.update(changed, deleted)`", which spans
20
- * `didChange` text-document events, `notifyDidChangeTextDocument` calls,
21
- * and any programmatic `documentBuilder.update([uri], [])` invocation.
22
- * The name matches Langium's own `changed` parameter — it's vague-on-
23
- * purpose because the underlying primitive is.
24
- * - `'rebuilt'` — the URI was rebuilt as a cascade from another URI's
25
- * build (dependency graph re-derivation), without itself being passed to
26
- * `documentBuilder.update`. The complement of `'changed'`.
17
+ * - `'changed'` — the server's first update event for the document's current
18
+ * version: its content changed since the last one. A write whose build a
19
+ * later write cancelled is still `'changed'` in the build that takes over.
20
+ * - `'rebuilt'` — a later event for a version the server already delivered,
21
+ * whether or not any client watched it then: something the document depends
22
+ * on changed, or the document was built again with the same content. The
23
+ * complement of `'changed'`.
27
24
  * - `'saved'` — emitted by adopters that synthesise a unified update stream
28
25
  * from both `onDocumentUpdated` and `onDocumentSaved`. The framework's own
29
26
  * `dispatchPhaseEvent` does NOT emit `'saved'` — saves take the dedicated
30
27
  * `DataClientProtocol.onDocumentSaved` channel.
31
- * - `'deleted'` — the URI appeared in `DocumentBuilder.onUpdate`'s
32
- * `deleted` list. The backing file was removed.
28
+ *
29
+ * The version rule needs a version the server keeps and builds that validate.
30
+ * For a document no client has opened, or when rebuilds do not validate,
31
+ * `'changed'` means the URI was passed to `DocumentBuilder.update` for this
32
+ * build. A document that a validating build skips is `'changed'` every time.
33
+ *
34
+ * Deletion is deliberately NOT a member. An update event carries a built
35
+ * document, which a deleted one has none of, and the phase-driven path that
36
+ * produces these events never runs for a deleted URI — the builder drops the
37
+ * document before deriving the rebuild set. It travels as
38
+ * {@link TransferDocumentDeletedEvent} on its own channel instead.
33
39
  */
34
- export type TransferDocumentUpdateReason = 'changed' | 'rebuilt' | 'saved' | 'deleted';
40
+ export type TransferDocumentUpdateReason = 'changed' | 'rebuilt' | 'saved';
35
41
  /**
36
42
  * Delivered on the data-server when a document's content (or existence)
37
43
  * changed. Subscribers receive this via `DocumentServerProtocol.watchModelDocument`.
38
- *
39
- * The `document` field carries the latest built state — diagnostics + root
40
- * are coherent with each other at the time the event fired.
41
44
  */
42
45
  export interface TransferDocumentUpdatedEvent<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic> {
46
+ /** The latest built state: diagnostics and root are coherent with each other at the time the event fired. */
43
47
  document: TransferDocument<TTransfer, TDiagnostic>;
44
- /** Stable identifier of the client that triggered the update. */
48
+ /**
49
+ * The client whose write this event echoes: the author of the version on a
50
+ * `'changed'`, and the unknown-client id on a `'rebuilt'`, which echoes no
51
+ * write. A recipient compares it against its own id to recognise its echo.
52
+ * The build that follows a document's release names the release id
53
+ * instead.
54
+ */
45
55
  sourceClientId: string;
56
+ /** See {@link TransferDocumentUpdateReason} for which reasons the framework sends. */
46
57
  reason: TransferDocumentUpdateReason;
58
+ /**
59
+ * The position of this event among the update and deletion events the
60
+ * server sent on this connection, which a watch's answer carries as of
61
+ * the moment it was taken: a greater one was sent later.
62
+ */
63
+ sequence: number;
47
64
  }
48
65
  /** Callback shape for `DataClientProtocol.onDocumentUpdated`. */
49
66
  export type TransferDocumentUpdatedListener<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic> = (event: TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>) => void;
50
67
  /**
51
- * Delivered on the data-server when a document was persisted to disk via
52
- * `DataServerProtocol.saveModelDocument`. Distinct from
53
- * {@link TransferDocumentUpdatedEvent}: subscribers that only care about
54
- * persistence (external sync, editor "saved" indicators, dirty-flag
55
- * clear) listen for this event family instead of filtering an update
56
- * stream for `reason: 'saved'`.
57
- *
58
- * The `document` field carries the post-save built state — same shape
59
- * the synchronous `saveModelDocument` RPC response returns, delivered
60
- * to subscribers (`DataClientProtocol.onDocumentSaved`) so non-caller
61
- * clients see the persistence event too.
68
+ * Delivered on the data-server when a subscribed document was saved to disk,
69
+ * whichever client saved it, an editor's save through the LSP head included.
70
+ * Distinct from {@link TransferDocumentUpdatedEvent}: subscribers that only
71
+ * care about persistence (external sync, editor "saved" indicators,
72
+ * dirty-flag clear) listen for this event family instead of filtering an
73
+ * update stream for `reason: 'saved'`.
62
74
  */
63
75
  export interface TransferDocumentSavedEvent<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic> {
76
+ /** The latest built state, taken after the save. */
64
77
  document: TransferDocument<TTransfer, TDiagnostic>;
65
78
  /**
66
- * The client whose `saveModelDocument` call produced this. Every subscriber
67
- * receives the event including the originator, which already had the same
68
- * state as the RPC response — compare against your own id to drop the echo
69
- * rather than re-rendering from it.
79
+ * The client whose save produced this, also when another client wrote the
80
+ * persisted text: the caller of `saveModelDocument` or
81
+ * `persistModelDocument`, or `LANGUAGE_CLIENT_ID` for an editor's save
82
+ * through the LSP head. Every subscriber receives the event, the saving
83
+ * client included, so compare against your own id to drop the echo.
70
84
  */
71
85
  sourceClientId: string;
72
86
  }
73
87
  /** Callback shape for `DataClientProtocol.onDocumentSaved`. */
74
88
  export type TransferDocumentSavedListener<TTransfer extends TransferElement, TDiagnostic extends TransferDiagnostic = TransferDiagnostic> = (event: TransferDocumentSavedEvent<TTransfer, TDiagnostic>) => void;
89
+ /**
90
+ * Delivered on the data-server when a watched document's text starts or stops
91
+ * differing from its file, as the server last knew the file. The current
92
+ * answer rides on every transfer document the server sends as `text.dirty`;
93
+ * this carries only its changes, so a client that follows it needs no rebuild
94
+ * to learn of a save.
95
+ */
96
+ export interface TransferDocumentDirtyChangedEvent {
97
+ /** Canonical URI, keyed as the subscription is. */
98
+ readonly uri: string;
99
+ /**
100
+ * The text the answer was decided on. It is sent before that text is
101
+ * built, so a `text.version` ahead of the model a client holds means an
102
+ * update at this version or a later one follows. Absent when the document
103
+ * no longer exists, or when the build that follows its release failed.
104
+ */
105
+ readonly text?: TextState;
106
+ }
107
+ /** Callback shape for `DataClientProtocol.onDocumentDirtyChanged`. */
108
+ export type TransferDocumentDirtyChangedListener = (event: TransferDocumentDirtyChangedEvent) => void;
109
+ /**
110
+ * Delivered on the data-server when a document's backing file was removed.
111
+ * Carries no document, and cannot: the state a
112
+ * {@link TransferDocumentUpdatedEvent} would have to carry no longer exists by
113
+ * the time anyone can be told. That is also why deletion is not a `reason` on
114
+ * the update stream — `DocumentBuilder.update` drops the document before
115
+ * deriving the rebuild set, so the phase-driven path that produces update
116
+ * events never runs for it.
117
+ *
118
+ * **Delivered for EVERY document, not only watched ones**, unlike
119
+ * `onDocumentUpdated` and `onDocumentSaved`. The test that decides which
120
+ * channels are gated is whether any OTHER source can observe the fact on the
121
+ * least capable host: a browser-hosted client's workspace lives behind the
122
+ * head, so nothing there can see a file disappear, and gating the notification
123
+ * would leave it blind. (A Theia frontend's filesystem watcher would cover it,
124
+ * which is why this is a host argument and not a structure-versus-content one.)
125
+ * A watcher is told about its own document's deletion here too, the update
126
+ * channel being silent for deletions by construction. Filter on {@link uri} if
127
+ * the receiver only cares about documents it opened.
128
+ *
129
+ * A watch survives the deletion, so a file that comes back resumes delivering
130
+ * `onDocumentUpdated` to the same subscribers with no re-subscription. A
131
+ * client that responds by closing its editor releases the watch through
132
+ * `closeModelDocument` as usual, and `deleteModelDocument` releases the
133
+ * deleting session's own.
134
+ */
135
+ export interface TransferDocumentDeletedEvent {
136
+ /** Canonical URI of the removed document, keyed as the subscription is. */
137
+ readonly uri: string;
138
+ /**
139
+ * The session whose `deleteModelDocument` removed the file, so it can tell
140
+ * its own deletion from another's; the unknown-client id for a file
141
+ * removed outside any session, as a file watcher reports one, and for one
142
+ * a `DataConnection` found gone after a reconnect, which no event named.
143
+ */
144
+ readonly sourceClientId: string;
145
+ /**
146
+ * The position of this event among the update and deletion events the
147
+ * server sent on this connection, as on an update; absent on a deletion a
148
+ * `DataConnection` found after a reconnect, which the server never sent.
149
+ */
150
+ readonly sequence?: number;
151
+ }
152
+ /** Callback shape for `DataClientProtocol.onDocumentDeleted`. */
153
+ export type TransferDocumentDeletedListener = (event: TransferDocumentDeletedEvent) => void;
154
+ /**
155
+ * Delivered on the data-server once per build, naming the documents that reached
156
+ * the configured subscription phase (`DataServerOptions.subscriptionPhase`,
157
+ * `Validated` by default) and that NO client on the connection is watching. Not
158
+ * the integrity-settled landmark, which is a different point and a different
159
+ * word in this framework.
160
+ *
161
+ * The complement of {@link TransferDocumentUpdatedEvent}, which is gated per
162
+ * URI: together the two cover every document a build touched. This one exists
163
+ * for the case no source outside the server can observe — a document rebuilt
164
+ * because something it DEPENDS ON changed. Its own file never changed, so a
165
+ * filesystem watcher cannot see it, and it has no subscriber, so the update
166
+ * channel does not report it. A consumer showing data derived from such a
167
+ * document (a tree label, a decorator) would otherwise hold a stale value with
168
+ * nothing to invalidate it.
169
+ *
170
+ * Carries URIs and no documents: a recipient re-reads what it displays, through
171
+ * `getModelDocument` or its own request. That keeps the bandwidth property the
172
+ * per-URI subscription exists for, without gating the message.
173
+ *
174
+ * Not sent when the set is empty, which is the normal case while editing — the
175
+ * document being edited is watched by its own editor and therefore excluded.
176
+ * Workspace initialisation sends nothing either: it does not build to the
177
+ * subscription phase. The largest message a workspace can produce is therefore
178
+ * a whole-workspace rebuild at that phase, which is one message of URIs.
179
+ */
180
+ export interface TransferDocumentsBuiltEvent {
181
+ /** Canonical URIs, keyed as subscriptions are. Never empty. */
182
+ readonly uris: readonly string[];
183
+ }
184
+ /** Callback shape for `DataClientProtocol.onDocumentsBuilt`. */
185
+ export type TransferDocumentsBuiltListener = (event: TransferDocumentsBuiltEvent) => void;
75
186
  /**
76
187
  * Why a project-change event fired. `added` — the project was newly
77
188
  * registered (descriptor discovered); `updated` — the project's
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/data/events.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,4BAA4B,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAEvF;;;;;;GAMG;AACH,MAAM,WAAW,4BAA4B,CAC1C,SAAS,SAAS,eAAe,EACjC,WAAW,SAAS,kBAAkB,GAAG,kBAAkB;IAE3D,QAAQ,EAAE,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACnD,iEAAiE;IACjE,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,4BAA4B,CAAC;CACvC;AAED,iEAAiE;AACjE,MAAM,MAAM,+BAA+B,CACxC,SAAS,SAAS,eAAe,EACjC,WAAW,SAAS,kBAAkB,GAAG,kBAAkB,IAC1D,CAAC,KAAK,EAAE,4BAA4B,CAAC,SAAS,EAAE,WAAW,CAAC,KAAK,IAAI,CAAC;AAE1E;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,0BAA0B,CACxC,SAAS,SAAS,eAAe,EACjC,WAAW,SAAS,kBAAkB,GAAG,kBAAkB;IAE3D,QAAQ,EAAE,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACnD;;;;;OA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