@hydranium/protocol 1.0.0-next.35 → 1.0.0-next.350

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 (285) hide show
  1. package/README.md +44 -83
  2. package/lib/abstract-logger.d.ts +5 -0
  3. package/lib/abstract-logger.d.ts.map +1 -1
  4. package/lib/abstract-logger.js +7 -0
  5. package/lib/abstract-logger.js.map +1 -1
  6. package/lib/client/data-connection.d.ts +302 -0
  7. package/lib/client/data-connection.d.ts.map +1 -0
  8. package/lib/client/data-connection.js +533 -0
  9. package/lib/client/data-connection.js.map +1 -0
  10. package/lib/client/data-events.d.ts +17 -1
  11. package/lib/client/data-events.d.ts.map +1 -1
  12. package/lib/client/data-events.js +25 -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 +684 -89
  17. package/lib/client/data-session.d.ts.map +1 -1
  18. package/lib/client/data-session.js +1148 -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 +4 -4
  25. package/lib/client/message-relay.js +4 -4
  26. package/lib/client/message-relay.js.map +1 -1
  27. package/lib/client/post-message-transport.d.ts +64 -3
  28. package/lib/client/post-message-transport.d.ts.map +1 -1
  29. package/lib/client/post-message-transport.js +175 -1
  30. package/lib/client/post-message-transport.js.map +1 -1
  31. package/lib/client/rpc-connection.d.ts +157 -0
  32. package/lib/client/rpc-connection.d.ts.map +1 -0
  33. package/lib/client/rpc-connection.js +214 -0
  34. package/lib/client/rpc-connection.js.map +1 -0
  35. package/lib/client/worker-handshake.d.ts +86 -0
  36. package/lib/client/worker-handshake.d.ts.map +1 -0
  37. package/lib/client/worker-handshake.js +51 -0
  38. package/lib/client/worker-handshake.js.map +1 -0
  39. package/lib/client-ids.d.ts +45 -0
  40. package/lib/client-ids.d.ts.map +1 -0
  41. package/lib/client-ids.js +48 -0
  42. package/lib/client-ids.js.map +1 -0
  43. package/lib/clock.d.ts +50 -10
  44. package/lib/clock.d.ts.map +1 -1
  45. package/lib/clock.js +36 -1
  46. package/lib/clock.js.map +1 -1
  47. package/lib/console-logger.d.ts +23 -0
  48. package/lib/console-logger.d.ts.map +1 -0
  49. package/lib/console-logger.js +39 -0
  50. package/lib/console-logger.js.map +1 -0
  51. package/lib/data/data-protocol-methods.d.ts +4 -4
  52. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  53. package/lib/data/data-protocol-methods.js +13 -1
  54. package/lib/data/data-protocol-methods.js.map +1 -1
  55. package/lib/data/data-server-protocol.d.ts +170 -48
  56. package/lib/data/data-server-protocol.d.ts.map +1 -1
  57. package/lib/data/events.d.ts +137 -21
  58. package/lib/data/events.d.ts.map +1 -1
  59. package/lib/data/requests.d.ts +71 -11
  60. package/lib/data/requests.d.ts.map +1 -1
  61. package/lib/debouncer.d.ts +3 -3
  62. package/lib/debouncer.d.ts.map +1 -1
  63. package/lib/debouncer.js +6 -9
  64. package/lib/debouncer.js.map +1 -1
  65. package/lib/errors.d.ts +183 -30
  66. package/lib/errors.d.ts.map +1 -1
  67. package/lib/errors.js +268 -32
  68. package/lib/errors.js.map +1 -1
  69. package/lib/glsp-edits-settled-actions.d.ts +52 -0
  70. package/lib/glsp-edits-settled-actions.d.ts.map +1 -0
  71. package/lib/glsp-edits-settled-actions.js +28 -0
  72. package/lib/glsp-edits-settled-actions.js.map +1 -0
  73. package/lib/glsp-request-model-args.d.ts +16 -0
  74. package/lib/glsp-request-model-args.d.ts.map +1 -0
  75. package/lib/glsp-request-model-args.js +19 -0
  76. package/lib/glsp-request-model-args.js.map +1 -0
  77. package/lib/glsp-save-model-actions.d.ts +50 -0
  78. package/lib/glsp-save-model-actions.d.ts.map +1 -0
  79. package/lib/glsp-save-model-actions.js +28 -0
  80. package/lib/glsp-save-model-actions.js.map +1 -0
  81. package/lib/index.d.ts +10 -0
  82. package/lib/index.d.ts.map +1 -1
  83. package/lib/index.js +10 -0
  84. package/lib/index.js.map +1 -1
  85. package/lib/latency-collector.d.ts +8 -4
  86. package/lib/latency-collector.d.ts.map +1 -1
  87. package/lib/latency-collector.js.map +1 -1
  88. package/lib/logger.d.ts +38 -7
  89. package/lib/logger.d.ts.map +1 -1
  90. package/lib/logger.js +42 -4
  91. package/lib/logger.js.map +1 -1
  92. package/lib/messages/index.d.ts +4 -2
  93. package/lib/messages/index.d.ts.map +1 -1
  94. package/lib/messages/index.js +15 -4
  95. package/lib/messages/index.js.map +1 -1
  96. package/lib/messages/primitives.d.ts +59 -4
  97. package/lib/messages/primitives.d.ts.map +1 -1
  98. package/lib/messages/primitives.js +97 -4
  99. package/lib/messages/primitives.js.map +1 -1
  100. package/lib/model-server.d.ts +60 -13
  101. package/lib/model-server.d.ts.map +1 -1
  102. package/lib/model-server.js +4 -2
  103. package/lib/model-server.js.map +1 -1
  104. package/lib/model-service/base-version.d.ts +67 -0
  105. package/lib/model-service/base-version.d.ts.map +1 -0
  106. package/lib/model-service/base-version.js +44 -0
  107. package/lib/model-service/base-version.js.map +1 -0
  108. package/lib/model-service/index.d.ts +1 -1
  109. package/lib/model-service/index.d.ts.map +1 -1
  110. package/lib/model-service/index.js +4 -5
  111. package/lib/model-service/index.js.map +1 -1
  112. package/lib/model-service/reference-candidate.d.ts +5 -3
  113. package/lib/model-service/reference-candidate.d.ts.map +1 -1
  114. package/lib/node/index.d.ts +10 -0
  115. package/lib/node/index.d.ts.map +1 -0
  116. package/lib/node/index.js +29 -0
  117. package/lib/node/index.js.map +1 -0
  118. package/lib/node/process-memory.d.ts +66 -0
  119. package/lib/node/process-memory.d.ts.map +1 -0
  120. package/lib/node/process-memory.js +291 -0
  121. package/lib/node/process-memory.js.map +1 -0
  122. package/lib/noop-logger.d.ts.map +1 -1
  123. package/lib/noop-logger.js.map +1 -1
  124. package/lib/observable-value.js.map +1 -1
  125. package/lib/patch-merge.d.ts +63 -35
  126. package/lib/patch-merge.d.ts.map +1 -1
  127. package/lib/patch-merge.js +171 -25
  128. package/lib/patch-merge.js.map +1 -1
  129. package/lib/pending-work-tracker.d.ts +29 -0
  130. package/lib/pending-work-tracker.d.ts.map +1 -0
  131. package/lib/pending-work-tracker.js +46 -0
  132. package/lib/pending-work-tracker.js.map +1 -0
  133. package/lib/profile-session.d.ts +8 -4
  134. package/lib/profile-session.d.ts.map +1 -1
  135. package/lib/profile-session.js.map +1 -1
  136. package/lib/project.d.ts +4 -1
  137. package/lib/project.d.ts.map +1 -1
  138. package/lib/project.js.map +1 -1
  139. package/lib/random-uuid.d.ts +14 -0
  140. package/lib/random-uuid.d.ts.map +1 -0
  141. package/lib/random-uuid.js +24 -0
  142. package/lib/random-uuid.js.map +1 -0
  143. package/lib/reconcile-write.d.ts +67 -0
  144. package/lib/reconcile-write.d.ts.map +1 -0
  145. package/lib/reconcile-write.js +69 -0
  146. package/lib/reconcile-write.js.map +1 -0
  147. package/lib/rpc/bind-rpc-methods.d.ts +6 -2
  148. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  149. package/lib/rpc/bind-rpc-methods.js +17 -7
  150. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  151. package/lib/rpc/create-rpc-proxy.d.ts +3 -0
  152. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  153. package/lib/rpc/create-rpc-proxy.js +6 -1
  154. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  155. package/lib/rpc/index.d.ts +1 -0
  156. package/lib/rpc/index.d.ts.map +1 -1
  157. package/lib/rpc/index.js +1 -0
  158. package/lib/rpc/index.js.map +1 -1
  159. package/lib/rpc/send-by-method-name.d.ts +76 -0
  160. package/lib/rpc/send-by-method-name.d.ts.map +1 -0
  161. package/lib/rpc/send-by-method-name.js +120 -0
  162. package/lib/rpc/send-by-method-name.js.map +1 -0
  163. package/lib/rpc/wire-prefix.js.map +1 -1
  164. package/lib/save-text-document.d.ts +40 -0
  165. package/lib/save-text-document.d.ts.map +1 -0
  166. package/lib/save-text-document.js +34 -0
  167. package/lib/save-text-document.js.map +1 -0
  168. package/lib/testing/catalogue-audit.d.ts +1 -1
  169. package/lib/testing/catalogue-audit.js +1 -1
  170. package/lib/testing/catalogue-audit.js.map +1 -1
  171. package/lib/testing/data-doubles.d.ts +41 -12
  172. package/lib/testing/data-doubles.d.ts.map +1 -1
  173. package/lib/testing/data-doubles.js +56 -8
  174. package/lib/testing/data-doubles.js.map +1 -1
  175. package/lib/testing/fake-clock.d.ts +17 -2
  176. package/lib/testing/fake-clock.d.ts.map +1 -1
  177. package/lib/testing/fake-clock.js +61 -46
  178. package/lib/testing/fake-clock.js.map +1 -1
  179. package/lib/testing/index.d.ts +1 -0
  180. package/lib/testing/index.d.ts.map +1 -1
  181. package/lib/testing/index.js +4 -3
  182. package/lib/testing/index.js.map +1 -1
  183. package/lib/testing/node/duplex-connection.d.ts.map +1 -1
  184. package/lib/testing/node/duplex-connection.js +3 -2
  185. package/lib/testing/node/duplex-connection.js.map +1 -1
  186. package/lib/testing/node/duplex-stream.js.map +1 -1
  187. package/lib/testing/node/index.d.ts +1 -0
  188. package/lib/testing/node/index.d.ts.map +1 -1
  189. package/lib/testing/node/index.js +2 -2
  190. package/lib/testing/node/index.js.map +1 -1
  191. package/lib/testing/node/message-port-pair.d.ts +25 -0
  192. package/lib/testing/node/message-port-pair.d.ts.map +1 -0
  193. package/lib/testing/node/message-port-pair.js +26 -0
  194. package/lib/testing/node/message-port-pair.js.map +1 -0
  195. package/lib/testing/transfer-node-builder.d.ts +81 -0
  196. package/lib/testing/transfer-node-builder.d.ts.map +1 -0
  197. package/lib/testing/transfer-node-builder.js +47 -0
  198. package/lib/testing/transfer-node-builder.js.map +1 -0
  199. package/lib/testing/wait-for.d.ts +9 -3
  200. package/lib/testing/wait-for.d.ts.map +1 -1
  201. package/lib/testing/wait-for.js +57 -11
  202. package/lib/testing/wait-for.js.map +1 -1
  203. package/lib/tracer.d.ts.map +1 -1
  204. package/lib/tracer.js +5 -9
  205. package/lib/tracer.js.map +1 -1
  206. package/lib/transfer-diagnostic.js.map +1 -1
  207. package/lib/transfer-document.d.ts +95 -32
  208. package/lib/transfer-document.d.ts.map +1 -1
  209. package/lib/transfer-document.js +17 -9
  210. package/lib/transfer-document.js.map +1 -1
  211. package/lib/transfer-element.d.ts +4 -4
  212. package/lib/types.d.ts +32 -0
  213. package/lib/types.d.ts.map +1 -0
  214. package/lib/{model-service/args.js → types.js} +2 -2
  215. package/lib/types.js.map +1 -0
  216. package/lib/uri.d.ts.map +1 -1
  217. package/lib/uri.js.map +1 -1
  218. package/lib/util.d.ts +8 -2
  219. package/lib/util.d.ts.map +1 -1
  220. package/lib/util.js +32 -4
  221. package/lib/util.js.map +1 -1
  222. package/package.json +24 -40
  223. package/src/abstract-logger.ts +8 -0
  224. package/src/client/data-connection.ts +653 -0
  225. package/src/client/data-events.ts +37 -1
  226. package/src/client/data-port.ts +36 -25
  227. package/src/client/data-session.ts +1469 -137
  228. package/src/client/index.ts +15 -9
  229. package/src/client/message-relay.ts +4 -4
  230. package/src/client/post-message-transport.ts +219 -4
  231. package/src/client/rpc-connection.ts +281 -0
  232. package/src/client/worker-handshake.ts +113 -0
  233. package/src/client-ids.ts +49 -0
  234. package/src/clock.ts +68 -10
  235. package/src/console-logger.ts +39 -0
  236. package/src/data/data-protocol-methods.ts +14 -4
  237. package/src/data/data-server-protocol.ts +197 -48
  238. package/src/data/events.ts +143 -21
  239. package/src/data/requests.ts +77 -11
  240. package/src/debouncer.ts +7 -10
  241. package/src/errors.ts +326 -40
  242. package/src/glsp-edits-settled-actions.ts +60 -0
  243. package/src/glsp-request-model-args.ts +16 -0
  244. package/src/glsp-save-model-actions.ts +59 -0
  245. package/src/index.ts +10 -0
  246. package/src/latency-collector.ts +8 -3
  247. package/src/logger.ts +44 -8
  248. package/src/messages/index.ts +4 -2
  249. package/src/messages/primitives.ts +129 -5
  250. package/src/model-server.ts +64 -19
  251. package/src/model-service/base-version.ts +75 -0
  252. package/src/model-service/index.ts +4 -5
  253. package/src/model-service/reference-candidate.ts +5 -3
  254. package/src/node/index.ts +14 -0
  255. package/src/node/process-memory.ts +299 -0
  256. package/src/patch-merge.ts +230 -45
  257. package/src/pending-work-tracker.ts +46 -0
  258. package/src/profile-session.ts +9 -4
  259. package/src/project.ts +4 -1
  260. package/src/random-uuid.ts +21 -0
  261. package/src/reconcile-write.ts +128 -0
  262. package/src/rpc/README.md +6 -6
  263. package/src/rpc/bind-rpc-methods.ts +18 -8
  264. package/src/rpc/create-rpc-proxy.ts +6 -1
  265. package/src/rpc/index.ts +1 -0
  266. package/src/rpc/send-by-method-name.ts +140 -0
  267. package/src/save-text-document.ts +39 -0
  268. package/src/testing/catalogue-audit.ts +1 -1
  269. package/src/testing/data-doubles.ts +141 -19
  270. package/src/testing/fake-clock.ts +76 -48
  271. package/src/testing/index.ts +4 -3
  272. package/src/testing/node/duplex-connection.ts +3 -2
  273. package/src/testing/node/index.ts +2 -2
  274. package/src/testing/node/message-port-pair.ts +40 -0
  275. package/src/testing/transfer-node-builder.ts +107 -0
  276. package/src/testing/wait-for.ts +61 -13
  277. package/src/tracer.ts +5 -9
  278. package/src/transfer-document.ts +115 -34
  279. package/src/transfer-element.ts +4 -4
  280. package/src/types.ts +30 -0
  281. package/src/util.ts +33 -6
  282. package/lib/model-service/args.d.ts +0 -64
  283. package/lib/model-service/args.d.ts.map +0 -1
  284. package/lib/model-service/args.js.map +0 -1
  285. package/src/model-service/args.ts +0 -67
package/lib/errors.d.ts CHANGED
@@ -8,55 +8,78 @@
8
8
  ********************************************************************************/
9
9
  import { ResponseError } from 'vscode-jsonrpc';
10
10
  import { type HydraniumMessageData } from './messages/primitives';
11
+ import { type ModelVersion, type TextVersion } from './model-service/base-version';
11
12
  /**
12
- * The catalogue declaration behind {@link ConflictError}'s sentence.
13
+ * The catalogue declaration behind {@link ConflictError}'s sentence. It words
14
+ * the version mismatch rather than stating it: the two numbers mean nothing to
15
+ * an end user, and they stay in {@link ConflictErrorData}.
13
16
  *
14
17
  * Its English must keep containing {@link CONFLICT_ERROR_MESSAGE_MARKER}: the
15
18
  * marker is tier 3 of {@link isConflictError}'s ladder, and it matches on text.
16
19
  * That tier only ever works untranslated, which is why it is the last resort
17
20
  * behind the numeric code rather than the primary check.
18
21
  */
19
- export declare const STALE_BASED_UPDATE: import("./messages/primitives").MessageDefinition<"Stale-based update for {uri}: expected v{expected}, server is at v{actual}">;
22
+ export declare const STALE_BASE_VERSION_UPDATE: import("./messages/primitives").MessageDefinition<"The edit to {uri} was not applied: it was made to an older version of the document.">;
20
23
  /**
21
- * Application-specific JSON-RPC error code for {@link ConflictError}.
22
- * Outside the reserved range (-32768 .. -32000) per JSON-RPC 2.0.
24
+ * {@link STALE_BASE_VERSION_UPDATE}'s counterpart for an editor's save the
25
+ * server refused, since the editor's buffer is not the text it holds. Its
26
+ * English keeps the same marker.
27
+ */
28
+ export declare const STALE_BASE_VERSION_SAVE: import("./messages/primitives").MessageDefinition<"The save of {uri} was not applied: it was made to an older version of the document.">;
29
+ /**
30
+ * Every JSON-RPC error code the framework raises, from any package, keyed by
31
+ * the error it identifies.
32
+ *
33
+ * The framework reserves the block 42000 to 42999 for these, and an adopter's
34
+ * own codes stay outside it: after an RPC a guard matches on the code alone, so
35
+ * an adopter's error carrying one of these reads as the framework's. A new code
36
+ * takes the next unused number in the block, whichever package raises it, and
37
+ * is declared here, where tests hold every code distinct and inside the block.
38
+ * The block sits clear of the range JSON-RPC 2.0 reserves for itself, -32768
39
+ * to -32000.
40
+ */
41
+ export declare const HYDRANIUM_ERROR_CODES: {
42
+ readonly conflict: 42001;
43
+ readonly noActiveProfile: 42002;
44
+ readonly referenceSettleTimeout: 42003;
45
+ readonly sessionClosed: 42004;
46
+ readonly documentNotOpen: 42005;
47
+ readonly duplicateClientId: 42006;
48
+ readonly reservedClientId: 42007;
49
+ };
50
+ /**
51
+ * JSON-RPC error code for {@link ConflictError}.
23
52
  *
24
53
  * The code is the load-bearing identifier across realm boundaries —
25
54
  * `code` is a first-class field on the JSON-RPC error envelope and
26
55
  * survives wire reconstruction; the custom `Error` subclass name does
27
56
  * not.
28
57
  */
29
- export declare const CONFLICT_ERROR_CODE = 1001;
30
- /**
31
- * Structured payload carried in {@link ConflictError.data}, and the only place
32
- * a post-RPC caller can read the version mismatch from.
33
- */
58
+ export declare const CONFLICT_ERROR_CODE: 42001;
59
+ /** Structured payload carried in {@link ConflictError.data}. */
34
60
  export interface ConflictErrorData extends HydraniumMessageData {
35
61
  readonly uri: string;
36
- /** The based-on version the caller authored against. */
37
- readonly expected: number;
62
+ /** The base version the caller authored against. */
63
+ readonly baseVersion: ModelVersion;
38
64
  /** The server's current text-document version at the time of the throw. */
39
- readonly actual: number;
65
+ readonly actualVersion: TextVersion;
40
66
  }
41
67
  /**
42
- * Thrown by `ModelService.update` / `ModelService.save` when the caller-
43
- * supplied based-on version no longer matches the server's current text-
68
+ * Thrown by a client session's `update` / `save` when the caller-
69
+ * supplied base version no longer matches the server's current text-
44
70
  * document version for the same URI — i.e. the snapshot the caller
45
71
  * authored against has been superseded by an intervening edit.
46
72
  *
47
73
  * Extends vscode-jsonrpc's {@link ResponseError} so the typed
48
74
  * {@link ConflictErrorData} payload rides on the standard JSON-RPC
49
75
  * error envelope (`code`, `message`, `data`) — all three fields are
50
- * preserved by RPC reconstruction. Adopters that catch the error on
51
- * the receiving side of an RPC call read the version mismatch from
52
- * `err.data` (the instance is reconstructed as a generic
53
- * `ResponseError`, so subclass getters / fields do not survive).
76
+ * preserved by RPC reconstruction. `createRpcProxy` revives it into
77
+ * this class on the receiving side; a path that does not leaves a
78
+ * plain `ResponseError`, readable through `err.data` only.
54
79
  *
55
- * Detection is opt-in via the optional `baseVersion` field on
56
- * `TransferUpdateArgs` / `TransferSaveArgs`; callers that omit the field get
57
- * no gating. This mirrors LSP's `OptionalVersionedTextDocumentIdentifier`
58
- * posture, so headless / CLI / batch tooling with no meaningful based-on
59
- * version can opt out explicitly.
80
+ * Detection is driven by the required `baseVersion` field of every write
81
+ * request; a caller with no meaningful base version passes
82
+ * `'any'` and gets no gating.
60
83
  *
61
84
  * Three reasonable adopter recovery strategies:
62
85
  *
@@ -70,11 +93,139 @@ export interface ConflictErrorData extends HydraniumMessageData {
70
93
  * No auto-retry or auto-merge ships by default.
71
94
  */
72
95
  export declare class ConflictError extends ResponseError<ConflictErrorData> {
73
- constructor(uri: string, expected: number, actual: number);
96
+ /** `message` words what was refused: an edit, or with {@link STALE_BASE_VERSION_SAVE} a save. */
97
+ constructor(uri: string, baseVersion: ModelVersion, actualVersion: TextVersion, message?: typeof STALE_BASE_VERSION_UPDATE | typeof STALE_BASE_VERSION_SAVE);
74
98
  get uri(): string;
75
- get expected(): number;
76
- get actual(): number;
99
+ /**
100
+ * The base version the caller authored against. Not `expected`, and its
101
+ * sibling not `actual`: a test reporter reads that pair as an assertion
102
+ * failure and reports nothing of the real one.
103
+ */
104
+ get baseVersion(): ModelVersion;
105
+ /** The server's version at the time of the throw. Not `actual`, see {@link baseVersion}. */
106
+ get actualVersion(): TextVersion;
77
107
  }
108
+ /**
109
+ * JSON-RPC code for {@link SessionClosedError}, beside {@link CONFLICT_ERROR_CODE}
110
+ * and for the same reason: the code survives reconstruction, the class does not.
111
+ */
112
+ export declare const SESSION_CLOSED_ERROR_CODE: 42004;
113
+ /** JSON-RPC code for {@link DocumentNotOpenError}. */
114
+ export declare const DOCUMENT_NOT_OPEN_ERROR_CODE: 42005;
115
+ /** JSON-RPC code for {@link DuplicateClientIdError}. */
116
+ export declare const DUPLICATE_CLIENT_ID_ERROR_CODE: 42006;
117
+ /** JSON-RPC code for {@link ReservedClientIdError}. */
118
+ export declare const RESERVED_CLIENT_ID_ERROR_CODE: 42007;
119
+ /**
120
+ * The catalogue declaration behind {@link SessionClosedError}'s default
121
+ * sentence. It names no client id: the sentence can reach an end user, and the
122
+ * id stays in {@link SessionClosedErrorData.clientId} for whoever needs it.
123
+ */
124
+ export declare const SESSION_CLOSED: import("./messages/primitives").MessageDefinition<"The editing session has ended.">;
125
+ /** Structured payload carried in {@link SessionClosedError.data}. */
126
+ export interface SessionClosedErrorData extends HydraniumMessageData {
127
+ readonly clientId: string;
128
+ }
129
+ /**
130
+ * Thrown by every call on a client session after it ended, and by an open that
131
+ * was still in flight when its session ended: by the server for its sessions,
132
+ * and by a client-side `DataSession` once disposed, so a caller handles both
133
+ * the same way. A caller recognises it with {@link isSessionClosedError}, never
134
+ * by its sentence.
135
+ */
136
+ export declare class SessionClosedError extends ResponseError<SessionClosedErrorData> {
137
+ /**
138
+ * `message` replaces the default English, for a caller that knows more than
139
+ * that the session is gone. The identity stays {@link SESSION_CLOSED}'s, so a
140
+ * translating renderer renders the catalogue sentence in its place.
141
+ */
142
+ constructor(clientId: string, message?: string);
143
+ get clientId(): string;
144
+ }
145
+ /**
146
+ * The catalogue declaration behind {@link DocumentNotOpenError}'s sentence. The
147
+ * client id stays in {@link DocumentNotOpenErrorData.clientId}.
148
+ */
149
+ export declare const DOCUMENT_NOT_OPEN: import("./messages/primitives").MessageDefinition<"The document {uri} is not open in this editing session.">;
150
+ /** Structured payload carried in {@link DocumentNotOpenError.data}. */
151
+ export interface DocumentNotOpenErrorData extends HydraniumMessageData {
152
+ readonly uri: string;
153
+ readonly clientId: string;
154
+ }
155
+ /**
156
+ * Thrown when a client session writes a document it does not have open.
157
+ *
158
+ * A session writes only what it has open, so this is the answer both to a write
159
+ * that never opened and to one whose open was closed underneath it — by the
160
+ * session itself, or by the document being deleted.
161
+ */
162
+ export declare class DocumentNotOpenError extends ResponseError<DocumentNotOpenErrorData> {
163
+ constructor(uri: string, clientId: string);
164
+ get uri(): string;
165
+ get clientId(): string;
166
+ }
167
+ /**
168
+ * The catalogue declaration behind {@link DuplicateClientIdError}'s sentence.
169
+ * The client id stays in {@link DuplicateClientIdErrorData.clientId}.
170
+ */
171
+ export declare const DUPLICATE_CLIENT_ID: import("./messages/primitives").MessageDefinition<"Could not start an editing session: its identifier is still in use by another editor.">;
172
+ /** Structured payload carried in {@link DuplicateClientIdError.data}. */
173
+ export interface DuplicateClientIdErrorData extends HydraniumMessageData {
174
+ readonly clientId: string;
175
+ }
176
+ /**
177
+ * Thrown when a client session is started under an id that is already live in
178
+ * the process. The id frees up once its holder ends or closes its last
179
+ * document, so a caller may retry.
180
+ *
181
+ * Ids are unique process-wide because the id is also the author label on every
182
+ * version and the key a client recognises its own echoes by; two participants
183
+ * sharing one would each take the other's writes for their own.
184
+ */
185
+ export declare class DuplicateClientIdError extends ResponseError<DuplicateClientIdErrorData> {
186
+ constructor(clientId: string);
187
+ get clientId(): string;
188
+ }
189
+ /**
190
+ * Thrown when a client session is started under an id the framework reserves
191
+ * for one of its own participants. A reserved id never frees up, so a caller
192
+ * that retries on {@link DuplicateClientIdError} stops on this one.
193
+ *
194
+ * It carries no message identity: a host that picks a reserved id has a bug,
195
+ * and no sentence addressed to an end user is true for it.
196
+ */
197
+ export declare class ReservedClientIdError extends ResponseError<{
198
+ readonly clientId: string;
199
+ }> {
200
+ constructor(clientId: string);
201
+ get clientId(): string;
202
+ }
203
+ /**
204
+ * Whether `error` is a `ResponseError` from any copy of `vscode-jsonrpc`. An
205
+ * install holds several copies, and `instanceof` recognises only its own. An
206
+ * error that merely carries an integer `code` has no `toJson`, and is not one.
207
+ */
208
+ export declare function isResponseError(error: unknown): error is ResponseError<unknown>;
209
+ /**
210
+ * `error` as an instance of the typed error class its code names, with its
211
+ * message, data and stack kept, or `error` itself when its code names none or
212
+ * its data lacks the fields that class reads.
213
+ * An RPC reconstructs every rejection as a plain `ResponseError`, which has
214
+ * none of the class getters.
215
+ */
216
+ export declare function reviveProtocolError(error: unknown): unknown;
217
+ /**
218
+ * Whether `error` is a {@link SessionClosedError}: by name in-process, by code
219
+ * when it arrives as a plain `ResponseError`, through a path that does not
220
+ * {@link reviveProtocolError revive} it.
221
+ */
222
+ export declare function isSessionClosedError(error: unknown): error is SessionClosedError;
223
+ /** Whether `error` is a {@link DocumentNotOpenError}; see {@link isSessionClosedError}. */
224
+ export declare function isDocumentNotOpenError(error: unknown): error is DocumentNotOpenError;
225
+ /** Whether `error` is a {@link DuplicateClientIdError}; see {@link isSessionClosedError}. */
226
+ export declare function isDuplicateClientIdError(error: unknown): error is DuplicateClientIdError;
227
+ /** Whether `error` is a {@link ReservedClientIdError}; see {@link isSessionClosedError}. */
228
+ export declare function isReservedClientIdError(error: unknown): error is ReservedClientIdError;
78
229
  /**
79
230
  * Type guard for {@link ConflictError}. Detection ladder:
80
231
  *
@@ -84,11 +235,13 @@ export declare class ConflictError extends ResponseError<ConflictErrorData> {
84
235
  * canonical wire-side check; the JSON-RPC `code` field is preserved
85
236
  * across reconstruction, so any adopter catching after an RPC call
86
237
  * hits this branch.
87
- * 3. `error.message.includes('Stale-based update for ')` — fallback
88
- * for transports that re-wrap the message and drop the code (rare).
238
+ * 3. `error.message` contains the marker the English of
239
+ * {@link STALE_BASE_VERSION_UPDATE} and
240
+ * {@link STALE_BASE_VERSION_SAVE} carries — fallback for transports
241
+ * that re-wrap the message and drop the code (rare).
89
242
  *
90
- * `instanceof ConflictError` alone would silently return `false` on the
91
- * reconstructed shape, so callers do not use it.
243
+ * `instanceof ConflictError` alone returns `false` on a rejection that was
244
+ * not {@link reviveProtocolError revived}, so callers do not use it.
92
245
  */
93
246
  export declare function isConflictError(error: unknown): error is ConflictError;
94
247
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAiB,KAAK,oBAAoB,EAAe,MAAM,uBAAuB,CAAC;AAE9F;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,iIAG9B,CAAC;AAEF;;;;;;;;GAQ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E,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAEhF;AAED,2FAA2F;AAC3F,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,oBAAoB,CAEpF;AAED,6FAA6F;AAC7F,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,sBAAsB,CAExF;AAED,4FAA4F;AAC5F,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,qBAAqB,CAEtF;AAWD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAYtE"}
package/lib/errors.js CHANGED
@@ -8,48 +8,91 @@
8
8
  * SPDX-License-Identifier: MIT
9
9
  ********************************************************************************/
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.ConflictError = exports.CONFLICT_ERROR_CODE = exports.STALE_BASED_UPDATE = void 0;
11
+ exports.ReservedClientIdError = exports.DuplicateClientIdError = exports.DUPLICATE_CLIENT_ID = exports.DocumentNotOpenError = exports.DOCUMENT_NOT_OPEN = exports.SessionClosedError = exports.SESSION_CLOSED = exports.RESERVED_CLIENT_ID_ERROR_CODE = exports.DUPLICATE_CLIENT_ID_ERROR_CODE = exports.DOCUMENT_NOT_OPEN_ERROR_CODE = exports.SESSION_CLOSED_ERROR_CODE = exports.ConflictError = exports.CONFLICT_ERROR_CODE = exports.HYDRANIUM_ERROR_CODES = exports.STALE_BASE_VERSION_SAVE = exports.STALE_BASE_VERSION_UPDATE = void 0;
12
+ exports.isResponseError = isResponseError;
13
+ exports.reviveProtocolError = reviveProtocolError;
14
+ exports.isSessionClosedError = isSessionClosedError;
15
+ exports.isDocumentNotOpenError = isDocumentNotOpenError;
16
+ exports.isDuplicateClientIdError = isDuplicateClientIdError;
17
+ exports.isReservedClientIdError = isReservedClientIdError;
12
18
  exports.isConflictError = isConflictError;
13
19
  const vscode_jsonrpc_1 = require("vscode-jsonrpc");
14
20
  const primitives_1 = require("./messages/primitives");
21
+ const base_version_1 = require("./model-service/base-version");
22
+ /*
23
+ * Every error here is a typed error: a caller reacts to it, so it has a class,
24
+ * a JSON-RPC code and an `is*` guard, and an English message. A typed error
25
+ * also carries a message identity where the framework can write an end-user
26
+ * sentence that needs no context. A URI may stay in that sentence; a client id
27
+ * or a raw version stays out of it, worded or left to `data`.
28
+ *
29
+ * An error nothing reacts to does not belong here: it stays a plain `Error`, or
30
+ * a named subclass without a code, at its throw site, since a code and a guard
31
+ * are public API that no caller would use.
32
+ */
15
33
  /**
16
- * The catalogue declaration behind {@link ConflictError}'s sentence.
34
+ * The catalogue declaration behind {@link ConflictError}'s sentence. It words
35
+ * the version mismatch rather than stating it: the two numbers mean nothing to
36
+ * an end user, and they stay in {@link ConflictErrorData}.
17
37
  *
18
38
  * Its English must keep containing {@link CONFLICT_ERROR_MESSAGE_MARKER}: the
19
39
  * marker is tier 3 of {@link isConflictError}'s ladder, and it matches on text.
20
40
  * That tier only ever works untranslated, which is why it is the last resort
21
41
  * behind the numeric code rather than the primary check.
22
42
  */
23
- exports.STALE_BASED_UPDATE = (0, primitives_1.defineMessage)('hydranium/protocol/stale-based-update', 'Stale-based update for {uri}: expected v{expected}, server is at v{actual}');
43
+ exports.STALE_BASE_VERSION_UPDATE = (0, primitives_1.defineMessage)('hydranium/protocol/stale-base-version-update', 'The edit to {uri} was not applied: it was made to an older version of the document.');
44
+ /**
45
+ * {@link STALE_BASE_VERSION_UPDATE}'s counterpart for an editor's save the
46
+ * server refused, since the editor's buffer is not the text it holds. Its
47
+ * English keeps the same marker.
48
+ */
49
+ exports.STALE_BASE_VERSION_SAVE = (0, primitives_1.defineMessage)('hydranium/protocol/stale-base-version-save', 'The save of {uri} was not applied: it was made to an older version of the document.');
50
+ /**
51
+ * Every JSON-RPC error code the framework raises, from any package, keyed by
52
+ * the error it identifies.
53
+ *
54
+ * The framework reserves the block 42000 to 42999 for these, and an adopter's
55
+ * own codes stay outside it: after an RPC a guard matches on the code alone, so
56
+ * an adopter's error carrying one of these reads as the framework's. A new code
57
+ * takes the next unused number in the block, whichever package raises it, and
58
+ * is declared here, where tests hold every code distinct and inside the block.
59
+ * The block sits clear of the range JSON-RPC 2.0 reserves for itself, -32768
60
+ * to -32000.
61
+ */
62
+ exports.HYDRANIUM_ERROR_CODES = {
63
+ conflict: 42001,
64
+ noActiveProfile: 42002,
65
+ referenceSettleTimeout: 42003,
66
+ sessionClosed: 42004,
67
+ documentNotOpen: 42005,
68
+ duplicateClientId: 42006,
69
+ reservedClientId: 42007
70
+ };
24
71
  /**
25
- * Application-specific JSON-RPC error code for {@link ConflictError}.
26
- * Outside the reserved range (-32768 .. -32000) per JSON-RPC 2.0.
72
+ * JSON-RPC error code for {@link ConflictError}.
27
73
  *
28
74
  * The code is the load-bearing identifier across realm boundaries —
29
75
  * `code` is a first-class field on the JSON-RPC error envelope and
30
76
  * survives wire reconstruction; the custom `Error` subclass name does
31
77
  * not.
32
78
  */
33
- exports.CONFLICT_ERROR_CODE = 1001;
79
+ exports.CONFLICT_ERROR_CODE = exports.HYDRANIUM_ERROR_CODES.conflict;
34
80
  /**
35
- * Thrown by `ModelService.update` / `ModelService.save` when the caller-
36
- * supplied based-on version no longer matches the server's current text-
81
+ * Thrown by a client session's `update` / `save` when the caller-
82
+ * supplied base version no longer matches the server's current text-
37
83
  * document version for the same URI — i.e. the snapshot the caller
38
84
  * authored against has been superseded by an intervening edit.
39
85
  *
40
86
  * Extends vscode-jsonrpc's {@link ResponseError} so the typed
41
87
  * {@link ConflictErrorData} payload rides on the standard JSON-RPC
42
88
  * error envelope (`code`, `message`, `data`) — all three fields are
43
- * preserved by RPC reconstruction. Adopters that catch the error on
44
- * the receiving side of an RPC call read the version mismatch from
45
- * `err.data` (the instance is reconstructed as a generic
46
- * `ResponseError`, so subclass getters / fields do not survive).
89
+ * preserved by RPC reconstruction. `createRpcProxy` revives it into
90
+ * this class on the receiving side; a path that does not leaves a
91
+ * plain `ResponseError`, readable through `err.data` only.
47
92
  *
48
- * Detection is opt-in via the optional `baseVersion` field on
49
- * `TransferUpdateArgs` / `TransferSaveArgs`; callers that omit the field get
50
- * no gating. This mirrors LSP's `OptionalVersionedTextDocumentIdentifier`
51
- * posture, so headless / CLI / batch tooling with no meaningful based-on
52
- * version can opt out explicitly.
93
+ * Detection is driven by the required `baseVersion` field of every write
94
+ * request; a caller with no meaningful base version passes
95
+ * `'any'` and gets no gating.
53
96
  *
54
97
  * Three reasonable adopter recovery strategies:
55
98
  *
@@ -63,35 +106,226 @@ exports.CONFLICT_ERROR_CODE = 1001;
63
106
  * No auto-retry or auto-merge ships by default.
64
107
  */
65
108
  class ConflictError extends vscode_jsonrpc_1.ResponseError {
66
- constructor(uri, expected, actual) {
67
- const params = { uri, expected, actual };
109
+ /** `message` words what was refused: an edit, or with {@link STALE_BASE_VERSION_SAVE} a save. */
110
+ constructor(uri, baseVersion, actualVersion, message = exports.STALE_BASE_VERSION_UPDATE) {
68
111
  // The identity rides alongside the typed payload rather than replacing
69
- // it: this class's getters and `isConflictError`'s name check are surface
70
- // an adopter may bind, so the payload widens rather than changing shape.
71
- super(exports.CONFLICT_ERROR_CODE, exports.STALE_BASED_UPDATE.format(params), { ...params, ...(0, primitives_1.messageData)(exports.STALE_BASED_UPDATE, params) });
112
+ // it: `isConflictError`'s name check is surface an adopter may bind, so
113
+ // adding the identity widens the payload rather than reshaping it.
114
+ super(exports.CONFLICT_ERROR_CODE, message.format({ uri }), {
115
+ uri,
116
+ baseVersion,
117
+ actualVersion,
118
+ ...(0, primitives_1.messageData)(message, { uri })
119
+ });
72
120
  this.name = 'ConflictError';
73
121
  // ResponseError's constructor calls `Object.setPrototypeOf(this,
74
122
  // ResponseError.prototype)` to keep its own prototype chain intact across
75
123
  // transpilation targets; that resets us to ResponseError, hiding the
76
124
  // ConflictError-specific getters. Restore the prototype here so
77
- // `err.uri` / `.expected` / `.actual` resolve through this class.
125
+ // `err.uri` / `.baseVersion` / `.actualVersion` resolve through this
126
+ // class.
78
127
  Object.setPrototypeOf(this, ConflictError.prototype);
79
128
  }
80
129
  get uri() {
81
130
  return this.data.uri;
82
131
  }
83
- get expected() {
84
- return this.data.expected;
132
+ /**
133
+ * The base version the caller authored against. Not `expected`, and its
134
+ * sibling not `actual`: a test reporter reads that pair as an assertion
135
+ * failure and reports nothing of the real one.
136
+ */
137
+ get baseVersion() {
138
+ return this.data.baseVersion;
85
139
  }
86
- get actual() {
87
- return this.data.actual;
140
+ /** The server's version at the time of the throw. Not `actual`, see {@link baseVersion}. */
141
+ get actualVersion() {
142
+ return this.data.actualVersion;
88
143
  }
89
144
  }
90
145
  exports.ConflictError = ConflictError;
146
+ /**
147
+ * JSON-RPC code for {@link SessionClosedError}, beside {@link CONFLICT_ERROR_CODE}
148
+ * and for the same reason: the code survives reconstruction, the class does not.
149
+ */
150
+ exports.SESSION_CLOSED_ERROR_CODE = exports.HYDRANIUM_ERROR_CODES.sessionClosed;
151
+ /** JSON-RPC code for {@link DocumentNotOpenError}. */
152
+ exports.DOCUMENT_NOT_OPEN_ERROR_CODE = exports.HYDRANIUM_ERROR_CODES.documentNotOpen;
153
+ /** JSON-RPC code for {@link DuplicateClientIdError}. */
154
+ exports.DUPLICATE_CLIENT_ID_ERROR_CODE = exports.HYDRANIUM_ERROR_CODES.duplicateClientId;
155
+ /** JSON-RPC code for {@link ReservedClientIdError}. */
156
+ exports.RESERVED_CLIENT_ID_ERROR_CODE = exports.HYDRANIUM_ERROR_CODES.reservedClientId;
157
+ /**
158
+ * The catalogue declaration behind {@link SessionClosedError}'s default
159
+ * sentence. It names no client id: the sentence can reach an end user, and the
160
+ * id stays in {@link SessionClosedErrorData.clientId} for whoever needs it.
161
+ */
162
+ exports.SESSION_CLOSED = (0, primitives_1.defineMessage)('hydranium/protocol/session-closed', 'The editing session has ended.');
163
+ /**
164
+ * Thrown by every call on a client session after it ended, and by an open that
165
+ * was still in flight when its session ended: by the server for its sessions,
166
+ * and by a client-side `DataSession` once disposed, so a caller handles both
167
+ * the same way. A caller recognises it with {@link isSessionClosedError}, never
168
+ * by its sentence.
169
+ */
170
+ class SessionClosedError extends vscode_jsonrpc_1.ResponseError {
171
+ /**
172
+ * `message` replaces the default English, for a caller that knows more than
173
+ * that the session is gone. The identity stays {@link SESSION_CLOSED}'s, so a
174
+ * translating renderer renders the catalogue sentence in its place.
175
+ */
176
+ constructor(clientId, message = exports.SESSION_CLOSED.format()) {
177
+ super(exports.SESSION_CLOSED_ERROR_CODE, message, { clientId, ...(0, primitives_1.messageData)(exports.SESSION_CLOSED) });
178
+ this.name = 'SessionClosedError';
179
+ // `ResponseError` resets the prototype to its own; see `ConflictError`.
180
+ Object.setPrototypeOf(this, SessionClosedError.prototype);
181
+ }
182
+ get clientId() {
183
+ return this.data.clientId;
184
+ }
185
+ }
186
+ exports.SessionClosedError = SessionClosedError;
187
+ /**
188
+ * The catalogue declaration behind {@link DocumentNotOpenError}'s sentence. The
189
+ * client id stays in {@link DocumentNotOpenErrorData.clientId}.
190
+ */
191
+ exports.DOCUMENT_NOT_OPEN = (0, primitives_1.defineMessage)('hydranium/protocol/document-not-open', 'The document {uri} is not open in this editing session.');
192
+ /**
193
+ * Thrown when a client session writes a document it does not have open.
194
+ *
195
+ * A session writes only what it has open, so this is the answer both to a write
196
+ * that never opened and to one whose open was closed underneath it — by the
197
+ * session itself, or by the document being deleted.
198
+ */
199
+ class DocumentNotOpenError extends vscode_jsonrpc_1.ResponseError {
200
+ constructor(uri, clientId) {
201
+ super(exports.DOCUMENT_NOT_OPEN_ERROR_CODE, exports.DOCUMENT_NOT_OPEN.format({ uri }), {
202
+ uri,
203
+ clientId,
204
+ ...(0, primitives_1.messageData)(exports.DOCUMENT_NOT_OPEN, { uri })
205
+ });
206
+ this.name = 'DocumentNotOpenError';
207
+ Object.setPrototypeOf(this, DocumentNotOpenError.prototype);
208
+ }
209
+ get uri() {
210
+ return this.data.uri;
211
+ }
212
+ get clientId() {
213
+ return this.data.clientId;
214
+ }
215
+ }
216
+ exports.DocumentNotOpenError = DocumentNotOpenError;
217
+ /**
218
+ * The catalogue declaration behind {@link DuplicateClientIdError}'s sentence.
219
+ * The client id stays in {@link DuplicateClientIdErrorData.clientId}.
220
+ */
221
+ exports.DUPLICATE_CLIENT_ID = (0, primitives_1.defineMessage)('hydranium/protocol/duplicate-client-id', 'Could not start an editing session: its identifier is still in use by another editor.');
222
+ /**
223
+ * Thrown when a client session is started under an id that is already live in
224
+ * the process. The id frees up once its holder ends or closes its last
225
+ * document, so a caller may retry.
226
+ *
227
+ * Ids are unique process-wide because the id is also the author label on every
228
+ * version and the key a client recognises its own echoes by; two participants
229
+ * sharing one would each take the other's writes for their own.
230
+ */
231
+ class DuplicateClientIdError extends vscode_jsonrpc_1.ResponseError {
232
+ constructor(clientId) {
233
+ super(exports.DUPLICATE_CLIENT_ID_ERROR_CODE, exports.DUPLICATE_CLIENT_ID.format(), { clientId, ...(0, primitives_1.messageData)(exports.DUPLICATE_CLIENT_ID) });
234
+ this.name = 'DuplicateClientIdError';
235
+ Object.setPrototypeOf(this, DuplicateClientIdError.prototype);
236
+ }
237
+ get clientId() {
238
+ return this.data.clientId;
239
+ }
240
+ }
241
+ exports.DuplicateClientIdError = DuplicateClientIdError;
242
+ /**
243
+ * Thrown when a client session is started under an id the framework reserves
244
+ * for one of its own participants. A reserved id never frees up, so a caller
245
+ * that retries on {@link DuplicateClientIdError} stops on this one.
246
+ *
247
+ * It carries no message identity: a host that picks a reserved id has a bug,
248
+ * and no sentence addressed to an end user is true for it.
249
+ */
250
+ class ReservedClientIdError extends vscode_jsonrpc_1.ResponseError {
251
+ constructor(clientId) {
252
+ super(exports.RESERVED_CLIENT_ID_ERROR_CODE, `Client id ${clientId} is reserved for a framework participant`, { clientId });
253
+ this.name = 'ReservedClientIdError';
254
+ Object.setPrototypeOf(this, ReservedClientIdError.prototype);
255
+ }
256
+ get clientId() {
257
+ return this.data.clientId;
258
+ }
259
+ }
260
+ exports.ReservedClientIdError = ReservedClientIdError;
261
+ /** One entry per typed error class, keyed by its code; a class without one reaches a caller as a plain `ResponseError`. */
262
+ const PROTOCOL_ERROR_REVIVERS = new Map([
263
+ [
264
+ exports.CONFLICT_ERROR_CODE,
265
+ ({ uri, baseVersion, actualVersion }) => typeof uri === 'string' && typeof baseVersion === 'number' && typeof actualVersion === 'number'
266
+ ? new ConflictError(uri, (0, base_version_1.asModelVersion)(baseVersion), actualVersion)
267
+ : undefined
268
+ ],
269
+ [exports.SESSION_CLOSED_ERROR_CODE, ({ clientId }) => (typeof clientId === 'string' ? new SessionClosedError(clientId) : undefined)],
270
+ [
271
+ exports.DOCUMENT_NOT_OPEN_ERROR_CODE,
272
+ ({ uri, clientId }) => (typeof uri === 'string' && typeof clientId === 'string' ? new DocumentNotOpenError(uri, clientId) : undefined)
273
+ ],
274
+ [exports.DUPLICATE_CLIENT_ID_ERROR_CODE, ({ clientId }) => (typeof clientId === 'string' ? new DuplicateClientIdError(clientId) : undefined)],
275
+ [exports.RESERVED_CLIENT_ID_ERROR_CODE, ({ clientId }) => (typeof clientId === 'string' ? new ReservedClientIdError(clientId) : undefined)]
276
+ ]);
277
+ /**
278
+ * Whether `error` is a `ResponseError` from any copy of `vscode-jsonrpc`. An
279
+ * install holds several copies, and `instanceof` recognises only its own. An
280
+ * error that merely carries an integer `code` has no `toJson`, and is not one.
281
+ */
282
+ function isResponseError(error) {
283
+ return (error instanceof Error && 'code' in error && Number.isInteger(error.code) && 'toJson' in error && typeof error.toJson === 'function');
284
+ }
285
+ /**
286
+ * `error` as an instance of the typed error class its code names, with its
287
+ * message, data and stack kept, or `error` itself when its code names none or
288
+ * its data lacks the fields that class reads.
289
+ * An RPC reconstructs every rejection as a plain `ResponseError`, which has
290
+ * none of the class getters.
291
+ */
292
+ function reviveProtocolError(error) {
293
+ if (!isResponseError(error) || error.data === null || typeof error.data !== 'object') {
294
+ return error;
295
+ }
296
+ const revived = PROTOCOL_ERROR_REVIVERS.get(error.code)?.({ ...error.data });
297
+ if (!revived) {
298
+ return error;
299
+ }
300
+ return Object.assign(revived, { message: error.message, data: error.data, stack: error.stack });
301
+ }
302
+ /**
303
+ * Whether `error` is a {@link SessionClosedError}: by name in-process, by code
304
+ * when it arrives as a plain `ResponseError`, through a path that does not
305
+ * {@link reviveProtocolError revive} it.
306
+ */
307
+ function isSessionClosedError(error) {
308
+ return hasErrorIdentity(error, 'SessionClosedError', exports.SESSION_CLOSED_ERROR_CODE);
309
+ }
310
+ /** Whether `error` is a {@link DocumentNotOpenError}; see {@link isSessionClosedError}. */
311
+ function isDocumentNotOpenError(error) {
312
+ return hasErrorIdentity(error, 'DocumentNotOpenError', exports.DOCUMENT_NOT_OPEN_ERROR_CODE);
313
+ }
314
+ /** Whether `error` is a {@link DuplicateClientIdError}; see {@link isSessionClosedError}. */
315
+ function isDuplicateClientIdError(error) {
316
+ return hasErrorIdentity(error, 'DuplicateClientIdError', exports.DUPLICATE_CLIENT_ID_ERROR_CODE);
317
+ }
318
+ /** Whether `error` is a {@link ReservedClientIdError}; see {@link isSessionClosedError}. */
319
+ function isReservedClientIdError(error) {
320
+ return hasErrorIdentity(error, 'ReservedClientIdError', exports.RESERVED_CLIENT_ID_ERROR_CODE);
321
+ }
322
+ function hasErrorIdentity(error, name, code) {
323
+ return error instanceof Error && (error.name === name || error.code === code);
324
+ }
91
325
  /** Marker substring present in every {@link ConflictError} message, used by
92
326
  * {@link isConflictError} as a fallback when a transport re-wraps the error
93
327
  * and drops the JSON-RPC code. */
94
- const CONFLICT_ERROR_MESSAGE_MARKER = 'Stale-based update for ';
328
+ const CONFLICT_ERROR_MESSAGE_MARKER = ': it was made to an older version of the document';
95
329
  /**
96
330
  * Type guard for {@link ConflictError}. Detection ladder:
97
331
  *
@@ -101,11 +335,13 @@ const CONFLICT_ERROR_MESSAGE_MARKER = 'Stale-based update for ';
101
335
  * canonical wire-side check; the JSON-RPC `code` field is preserved
102
336
  * across reconstruction, so any adopter catching after an RPC call
103
337
  * hits this branch.
104
- * 3. `error.message.includes('Stale-based update for ')` — fallback
105
- * for transports that re-wrap the message and drop the code (rare).
338
+ * 3. `error.message` contains the marker the English of
339
+ * {@link STALE_BASE_VERSION_UPDATE} and
340
+ * {@link STALE_BASE_VERSION_SAVE} carries — fallback for transports
341
+ * that re-wrap the message and drop the code (rare).
106
342
  *
107
- * `instanceof ConflictError` alone would silently return `false` on the
108
- * reconstructed shape, so callers do not use it.
343
+ * `instanceof ConflictError` alone returns `false` on a rejection that was
344
+ * not {@link reviveProtocolError revived}, so callers do not use it.
109
345
  */
110
346
  function isConflictError(error) {
111
347
  if (!(error instanceof Error)) {