@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
package/lib/errors.js CHANGED
@@ -8,48 +8,90 @@
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.SaveFailedError = exports.SAVE_FAILED = exports.ReservedClientIdError = exports.DuplicateClientIdError = exports.DUPLICATE_CLIENT_ID = exports.DocumentNotOpenError = exports.DOCUMENT_NOT_OPEN = exports.SessionClosedError = exports.SESSION_CLOSED = exports.SAVE_FAILED_ERROR_CODE = 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.reviveProtocolErrorJson = reviveProtocolErrorJson;
15
+ exports.isSessionClosedError = isSessionClosedError;
16
+ exports.isDocumentNotOpenError = isDocumentNotOpenError;
17
+ exports.isDuplicateClientIdError = isDuplicateClientIdError;
18
+ exports.isReservedClientIdError = isReservedClientIdError;
19
+ exports.isSaveFailedError = isSaveFailedError;
12
20
  exports.isConflictError = isConflictError;
13
21
  const vscode_jsonrpc_1 = require("vscode-jsonrpc");
14
22
  const primitives_1 = require("./messages/primitives");
23
+ const base_version_1 = require("./model-service/base-version");
24
+ /*
25
+ * Every error here is a typed error: a caller reacts to it, so it has a class,
26
+ * a JSON-RPC code and an `is*` guard, and an English message. A typed error
27
+ * also carries a message identity where the framework can write an end-user
28
+ * sentence that needs no context. A URI may stay in that sentence; a client id
29
+ * or a raw version stays out of it, worded or left to `data`.
30
+ *
31
+ * An error nothing reacts to does not belong here: it stays a plain `Error`, or
32
+ * a named subclass without a code, at its throw site, since a code and a guard
33
+ * are public API that no caller would use.
34
+ */
35
+ /**
36
+ * The catalogue declaration behind {@link ConflictError}'s sentence. It words
37
+ * the version mismatch rather than stating it: the two numbers mean nothing to
38
+ * an end user, and they stay in {@link ConflictErrorData}.
39
+ */
40
+ 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.');
41
+ /**
42
+ * {@link STALE_BASE_VERSION_UPDATE}'s counterpart for an editor's save the
43
+ * server refused, since the editor's buffer is not the text it holds.
44
+ */
45
+ 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.');
15
46
  /**
16
- * The catalogue declaration behind {@link ConflictError}'s sentence.
47
+ * Every JSON-RPC error code the framework raises, from any package, keyed by
48
+ * the error it identifies.
17
49
  *
18
- * Its English must keep containing {@link CONFLICT_ERROR_MESSAGE_MARKER}: the
19
- * marker is tier 3 of {@link isConflictError}'s ladder, and it matches on text.
20
- * That tier only ever works untranslated, which is why it is the last resort
21
- * behind the numeric code rather than the primary check.
50
+ * The framework reserves the block 42000 to 42999 for these, and an adopter's
51
+ * own codes stay outside it: after an RPC the proxy revives an error by its
52
+ * code, so an adopter's error carrying one of these can read as the
53
+ * framework's. A new code takes the next unused number in the block, whichever
54
+ * package raises it, and is declared here, where tests hold every code distinct
55
+ * and inside the block.
56
+ * The block sits clear of the range JSON-RPC 2.0 reserves for itself, -32768
57
+ * to -32000.
22
58
  */
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}');
59
+ exports.HYDRANIUM_ERROR_CODES = {
60
+ conflict: 42001,
61
+ noActiveProfile: 42002,
62
+ referenceSettleTimeout: 42003,
63
+ sessionClosed: 42004,
64
+ documentNotOpen: 42005,
65
+ duplicateClientId: 42006,
66
+ reservedClientId: 42007,
67
+ saveFailed: 42008
68
+ };
24
69
  /**
25
- * Application-specific JSON-RPC error code for {@link ConflictError}.
26
- * Outside the reserved range (-32768 .. -32000) per JSON-RPC 2.0.
70
+ * JSON-RPC error code for {@link ConflictError}.
27
71
  *
28
72
  * The code is the load-bearing identifier across realm boundaries —
29
73
  * `code` is a first-class field on the JSON-RPC error envelope and
30
74
  * survives wire reconstruction; the custom `Error` subclass name does
31
75
  * not.
32
76
  */
33
- exports.CONFLICT_ERROR_CODE = 1001;
77
+ exports.CONFLICT_ERROR_CODE = exports.HYDRANIUM_ERROR_CODES.conflict;
34
78
  /**
35
- * Thrown by `ModelService.update` / `ModelService.save` when the caller-
36
- * supplied based-on version no longer matches the server's current text-
79
+ * Thrown by a client session's `update` / `save` when the caller-
80
+ * supplied base version no longer matches the server's current text-
37
81
  * document version for the same URI — i.e. the snapshot the caller
38
82
  * authored against has been superseded by an intervening edit.
39
83
  *
40
84
  * Extends vscode-jsonrpc's {@link ResponseError} so the typed
41
85
  * {@link ConflictErrorData} payload rides on the standard JSON-RPC
42
86
  * 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).
87
+ * preserved by RPC reconstruction. `createRpcProxy` revives it into
88
+ * this class on the receiving side; a path that does not leaves a
89
+ * plain `ResponseError`, readable through `err.data` only and refused
90
+ * by {@link isConflictError}.
47
91
  *
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.
92
+ * Detection is driven by the required `baseVersion` field of every write
93
+ * request; a caller with no meaningful base version passes
94
+ * `'any'` and gets no gating.
53
95
  *
54
96
  * Three reasonable adopter recovery strategies:
55
97
  *
@@ -63,61 +105,328 @@ exports.CONFLICT_ERROR_CODE = 1001;
63
105
  * No auto-retry or auto-merge ships by default.
64
106
  */
65
107
  class ConflictError extends vscode_jsonrpc_1.ResponseError {
66
- constructor(uri, expected, actual) {
67
- const params = { uri, expected, actual };
108
+ /** `message` words what was refused: an edit, or with {@link STALE_BASE_VERSION_SAVE} a save. */
109
+ constructor(uri, baseVersion, actualVersion, message = exports.STALE_BASE_VERSION_UPDATE) {
68
110
  // 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) });
111
+ // it. The getters, the guard and the reviver read the payload's fields,
112
+ // so adding the identity widens the payload rather than reshaping it.
113
+ super(exports.CONFLICT_ERROR_CODE, message.format({ uri }), {
114
+ uri,
115
+ baseVersion,
116
+ actualVersion,
117
+ ...(0, primitives_1.messageData)(message, { uri })
118
+ });
72
119
  this.name = 'ConflictError';
73
120
  // ResponseError's constructor calls `Object.setPrototypeOf(this,
74
121
  // ResponseError.prototype)` to keep its own prototype chain intact across
75
122
  // transpilation targets; that resets us to ResponseError, hiding the
76
123
  // ConflictError-specific getters. Restore the prototype here so
77
- // `err.uri` / `.expected` / `.actual` resolve through this class.
124
+ // `err.uri` / `.baseVersion` / `.actualVersion` resolve through this
125
+ // class.
78
126
  Object.setPrototypeOf(this, ConflictError.prototype);
79
127
  }
128
+ /** The document whose version moved, see {@link ConflictErrorData.uri}. */
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;
91
- /** Marker substring present in every {@link ConflictError} message, used by
92
- * {@link isConflictError} as a fallback when a transport re-wraps the error
93
- * and drops the JSON-RPC code. */
94
- const CONFLICT_ERROR_MESSAGE_MARKER = 'Stale-based update for ';
95
146
  /**
96
- * Type guard for {@link ConflictError}. Detection ladder:
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
+ /** JSON-RPC code for {@link SaveFailedError}. */
158
+ exports.SAVE_FAILED_ERROR_CODE = exports.HYDRANIUM_ERROR_CODES.saveFailed;
159
+ /**
160
+ * The catalogue declaration behind {@link SessionClosedError}'s default
161
+ * sentence. It names no client id: the sentence can reach an end user, and the
162
+ * id stays in {@link SessionClosedErrorData.clientId} for whoever needs it.
163
+ */
164
+ exports.SESSION_CLOSED = (0, primitives_1.defineMessage)('hydranium/protocol/session-closed', 'The editing session has ended.');
165
+ /**
166
+ * Thrown by every call on a client session after it ended, and by an open that
167
+ * was still in flight when its session ended: by the server for its sessions,
168
+ * and by a client-side `DataSession` once disposed, so a caller handles both
169
+ * the same way. A caller recognises it with {@link isSessionClosedError}, never
170
+ * by its sentence.
171
+ */
172
+ class SessionClosedError extends vscode_jsonrpc_1.ResponseError {
173
+ /**
174
+ * `message` replaces the default English, for a caller that knows more than
175
+ * that the session is gone. The identity stays {@link SESSION_CLOSED}'s, so a
176
+ * translating renderer renders the catalogue sentence in its place.
177
+ */
178
+ constructor(clientId, message = exports.SESSION_CLOSED.format()) {
179
+ super(exports.SESSION_CLOSED_ERROR_CODE, message, { clientId, ...(0, primitives_1.messageData)(exports.SESSION_CLOSED) });
180
+ this.name = 'SessionClosedError';
181
+ // `ResponseError` resets the prototype to its own; see `ConflictError`.
182
+ Object.setPrototypeOf(this, SessionClosedError.prototype);
183
+ }
184
+ get clientId() {
185
+ return this.data.clientId;
186
+ }
187
+ }
188
+ exports.SessionClosedError = SessionClosedError;
189
+ /**
190
+ * The catalogue declaration behind {@link DocumentNotOpenError}'s sentence. The
191
+ * client id stays in {@link DocumentNotOpenErrorData.clientId}.
192
+ */
193
+ exports.DOCUMENT_NOT_OPEN = (0, primitives_1.defineMessage)('hydranium/protocol/document-not-open', 'The document {uri} is not open in this editing session.');
194
+ /**
195
+ * Thrown when a client session writes a document it does not have open.
196
+ *
197
+ * A session writes only what it has open, so this is the answer both to a write
198
+ * that never opened and to one whose open was closed underneath it — by the
199
+ * session itself, or by the document being deleted.
200
+ */
201
+ class DocumentNotOpenError extends vscode_jsonrpc_1.ResponseError {
202
+ constructor(uri, clientId) {
203
+ super(exports.DOCUMENT_NOT_OPEN_ERROR_CODE, exports.DOCUMENT_NOT_OPEN.format({ uri }), {
204
+ uri,
205
+ clientId,
206
+ ...(0, primitives_1.messageData)(exports.DOCUMENT_NOT_OPEN, { uri })
207
+ });
208
+ this.name = 'DocumentNotOpenError';
209
+ Object.setPrototypeOf(this, DocumentNotOpenError.prototype);
210
+ }
211
+ get uri() {
212
+ return this.data.uri;
213
+ }
214
+ get clientId() {
215
+ return this.data.clientId;
216
+ }
217
+ }
218
+ exports.DocumentNotOpenError = DocumentNotOpenError;
219
+ /**
220
+ * The catalogue declaration behind {@link DuplicateClientIdError}'s sentence.
221
+ * The client id stays in {@link DuplicateClientIdErrorData.clientId}.
222
+ */
223
+ 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.');
224
+ /**
225
+ * Thrown when a client session is started under an id that is already live in
226
+ * the process. The id frees up once its holder ends or closes its last
227
+ * document, so a caller may retry.
97
228
  *
98
- * 1. `error.name === 'ConflictError'` — direct in-process throw, no
99
- * RPC round-trip.
100
- * 2. `(error as ResponseError).code === CONFLICT_ERROR_CODE` — the
101
- * canonical wire-side check; the JSON-RPC `code` field is preserved
102
- * across reconstruction, so any adopter catching after an RPC call
103
- * 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).
229
+ * Ids are unique process-wide because the id is also the author label on every
230
+ * version and the key a client recognises its own echoes by; two participants
231
+ * sharing one would each take the other's writes for their own.
232
+ */
233
+ class DuplicateClientIdError extends vscode_jsonrpc_1.ResponseError {
234
+ constructor(clientId) {
235
+ super(exports.DUPLICATE_CLIENT_ID_ERROR_CODE, exports.DUPLICATE_CLIENT_ID.format(), { clientId, ...(0, primitives_1.messageData)(exports.DUPLICATE_CLIENT_ID) });
236
+ this.name = 'DuplicateClientIdError';
237
+ Object.setPrototypeOf(this, DuplicateClientIdError.prototype);
238
+ }
239
+ get clientId() {
240
+ return this.data.clientId;
241
+ }
242
+ }
243
+ exports.DuplicateClientIdError = DuplicateClientIdError;
244
+ /**
245
+ * Thrown when a client session is started under an id the framework reserves
246
+ * for one of its own participants. A reserved id never frees up, so a caller
247
+ * that retries on {@link DuplicateClientIdError} stops on this one.
106
248
  *
107
- * `instanceof ConflictError` alone would silently return `false` on the
108
- * reconstructed shape, so callers do not use it.
249
+ * It carries no message identity: a host that picks a reserved id has a bug,
250
+ * and no sentence addressed to an end user is true for it.
109
251
  */
110
- function isConflictError(error) {
111
- if (!(error instanceof Error)) {
112
- return false;
252
+ class ReservedClientIdError extends vscode_jsonrpc_1.ResponseError {
253
+ constructor(clientId) {
254
+ super(exports.RESERVED_CLIENT_ID_ERROR_CODE, `Client id ${clientId} is reserved for a framework participant`, { clientId });
255
+ this.name = 'ReservedClientIdError';
256
+ Object.setPrototypeOf(this, ReservedClientIdError.prototype);
257
+ }
258
+ get clientId() {
259
+ return this.data.clientId;
260
+ }
261
+ }
262
+ exports.ReservedClientIdError = ReservedClientIdError;
263
+ /**
264
+ * The catalogue declaration behind {@link SaveFailedError}'s message. Its
265
+ * `failures` names each document with the writer's own reason, which stays as
266
+ * written.
267
+ */
268
+ exports.SAVE_FAILED = (0, primitives_1.defineMessage)('hydranium/protocol/save-failed', 'Could not save {failures}.');
269
+ /**
270
+ * Thrown by a save that could not write one or more of its documents. A save
271
+ * of several documents writes the others, so the files on disk can be a mix
272
+ * until a later save succeeds.
273
+ */
274
+ class SaveFailedError extends vscode_jsonrpc_1.ResponseError {
275
+ constructor(failures) {
276
+ const named = failures.map(failure => `${failure.uri} (${failure.reason})`).join(', ');
277
+ super(exports.SAVE_FAILED_ERROR_CODE, exports.SAVE_FAILED.format({ failures: named }), {
278
+ failures,
279
+ ...(0, primitives_1.messageData)(exports.SAVE_FAILED, { failures: named })
280
+ });
281
+ this.name = 'SaveFailedError';
282
+ Object.setPrototypeOf(this, SaveFailedError.prototype);
283
+ }
284
+ get failures() {
285
+ return this.data.failures;
286
+ }
287
+ }
288
+ exports.SaveFailedError = SaveFailedError;
289
+ /** One entry per typed error class, keyed by its code; a class without one reaches a caller as a plain `ResponseError`. */
290
+ const PROTOCOL_ERROR_REVIVERS = new Map([
291
+ [
292
+ exports.CONFLICT_ERROR_CODE,
293
+ data => (hasConflictFields(data) ? new ConflictError(data.uri, (0, base_version_1.asModelVersion)(data.baseVersion), data.actualVersion) : undefined)
294
+ ],
295
+ [exports.SESSION_CLOSED_ERROR_CODE, data => (hasClientId(data) ? new SessionClosedError(data.clientId) : undefined)],
296
+ [exports.DOCUMENT_NOT_OPEN_ERROR_CODE, data => (hasDocumentNotOpenFields(data) ? new DocumentNotOpenError(data.uri, data.clientId) : undefined)],
297
+ [exports.DUPLICATE_CLIENT_ID_ERROR_CODE, data => (hasClientId(data) ? new DuplicateClientIdError(data.clientId) : undefined)],
298
+ [exports.RESERVED_CLIENT_ID_ERROR_CODE, data => (hasClientId(data) ? new ReservedClientIdError(data.clientId) : undefined)],
299
+ [exports.SAVE_FAILED_ERROR_CODE, data => (hasSaveFailures(data) ? new SaveFailedError(data.failures) : undefined)]
300
+ ]);
301
+ // One check per class of the fields its getters read, run by its reviver on
302
+ // `data` and by its guard on the error, through the getters.
303
+ function hasConflictFields(value) {
304
+ return (isRecord(value) && typeof value.uri === 'string' && typeof value.baseVersion === 'number' && typeof value.actualVersion === 'number');
305
+ }
306
+ function hasClientId(value) {
307
+ return isRecord(value) && typeof value.clientId === 'string';
308
+ }
309
+ function hasDocumentNotOpenFields(value) {
310
+ return isRecord(value) && typeof value.uri === 'string' && typeof value.clientId === 'string';
311
+ }
312
+ function hasSaveFailures(value) {
313
+ return isRecord(value) && isSaveFailureList(value.failures);
314
+ }
315
+ function isRecord(value) {
316
+ return typeof value === 'object' && value !== null;
317
+ }
318
+ function isSaveFailureList(value) {
319
+ return (Array.isArray(value) &&
320
+ value.every((failure) => typeof failure === 'object' &&
321
+ failure !== null &&
322
+ 'uri' in failure &&
323
+ typeof failure.uri === 'string' &&
324
+ 'reason' in failure &&
325
+ typeof failure.reason === 'string'));
326
+ }
327
+ /**
328
+ * Whether `error` is a `ResponseError` from any copy of `vscode-jsonrpc`. An
329
+ * install holds several copies, and `instanceof` recognises only its own. An
330
+ * error that merely carries an integer `code` has no `toJson`, and is not one.
331
+ */
332
+ function isResponseError(error) {
333
+ return (error instanceof Error && 'code' in error && Number.isInteger(error.code) && 'toJson' in error && typeof error.toJson === 'function');
334
+ }
335
+ /**
336
+ * `error` as an instance of the typed error class its code names, with its
337
+ * message, data and stack kept, or `error` itself when its code names none or
338
+ * its data lacks the fields that class reads.
339
+ * An RPC reconstructs every rejection as a plain `ResponseError`, which has
340
+ * none of the class getters.
341
+ */
342
+ function reviveProtocolError(error) {
343
+ if (!isResponseError(error) || error.data === null || typeof error.data !== 'object') {
344
+ return error;
345
+ }
346
+ const revived = PROTOCOL_ERROR_REVIVERS.get(error.code)?.({ ...error.data });
347
+ if (!revived) {
348
+ return error;
349
+ }
350
+ return Object.assign(revived, { message: error.message, data: error.data, stack: error.stack });
351
+ }
352
+ /**
353
+ * The error the JSON text `json` describes, as `JSON.stringify(error.toJson())`
354
+ * writes it, revived to its typed class as {@link reviveProtocolError} does, or
355
+ * `undefined` when `json` is not a JSON-RPC error envelope. For a transport
356
+ * that carries the error as text, such as a GLSP `RejectAction`'s `detail`.
357
+ */
358
+ function reviveProtocolErrorJson(json) {
359
+ let envelope;
360
+ try {
361
+ envelope = JSON.parse(json);
113
362
  }
114
- if (error.name === 'ConflictError') {
115
- return true;
363
+ catch {
364
+ return undefined;
116
365
  }
117
- const code = error.code;
118
- if (code === exports.CONFLICT_ERROR_CODE) {
119
- return true;
366
+ if (typeof envelope !== 'object' || envelope === null || !('code' in envelope) || !('message' in envelope)) {
367
+ return undefined;
120
368
  }
121
- return typeof error.message === 'string' && error.message.includes(CONFLICT_ERROR_MESSAGE_MARKER);
369
+ const { code, message } = envelope;
370
+ if (typeof code !== 'number' || !Number.isInteger(code) || typeof message !== 'string') {
371
+ return undefined;
372
+ }
373
+ const revived = reviveProtocolError(new vscode_jsonrpc_1.ResponseError(code, message, 'data' in envelope ? envelope.data : undefined));
374
+ return isResponseError(revived) ? revived : undefined;
375
+ }
376
+ /**
377
+ * Mark `errorClass`'s prototype with a brand its guard checks, so every
378
+ * instance and every subclass carries it, and nothing else does. `Symbol.for`
379
+ * gives each copy of this package the same symbol, which `instanceof` does
380
+ * not, so the key must stay the same across releases.
381
+ */
382
+ function brand(errorClass, name) {
383
+ const key = Symbol.for(`hydranium/protocol/${name}`);
384
+ Object.defineProperty(errorClass.prototype, key, { value: true });
385
+ return key;
386
+ }
387
+ const CONFLICT_BRAND = brand(ConflictError, 'ConflictError');
388
+ const SESSION_CLOSED_BRAND = brand(SessionClosedError, 'SessionClosedError');
389
+ const DOCUMENT_NOT_OPEN_BRAND = brand(DocumentNotOpenError, 'DocumentNotOpenError');
390
+ const DUPLICATE_CLIENT_ID_BRAND = brand(DuplicateClientIdError, 'DuplicateClientIdError');
391
+ const RESERVED_CLIENT_ID_BRAND = brand(ReservedClientIdError, 'ReservedClientIdError');
392
+ const SAVE_FAILED_BRAND = brand(SaveFailedError, 'SaveFailedError');
393
+ /**
394
+ * Whether `error` is a {@link SessionClosedError} whose getters read valid
395
+ * fields: one thrown, or one {@link reviveProtocolError revived}, from any
396
+ * copy of this package, or a subclass. A bare `ResponseError` is not one,
397
+ * whatever its name and fields, since it lacks the class's brand.
398
+ * `createRpcProxy` revives every rejection, so only a caller on a connection
399
+ * of its own needs to revive first. Each guard below works the same way.
400
+ */
401
+ function isSessionClosedError(error) {
402
+ return hasBrand(error, SESSION_CLOSED_BRAND) && hasClientId(error);
403
+ }
404
+ /** Whether `error` is a {@link DocumentNotOpenError}. See {@link isSessionClosedError}. */
405
+ function isDocumentNotOpenError(error) {
406
+ return hasBrand(error, DOCUMENT_NOT_OPEN_BRAND) && hasDocumentNotOpenFields(error);
407
+ }
408
+ /** Whether `error` is a {@link DuplicateClientIdError}. See {@link isSessionClosedError}. */
409
+ function isDuplicateClientIdError(error) {
410
+ return hasBrand(error, DUPLICATE_CLIENT_ID_BRAND) && hasClientId(error);
411
+ }
412
+ /** Whether `error` is a {@link ReservedClientIdError}. See {@link isSessionClosedError}. */
413
+ function isReservedClientIdError(error) {
414
+ return hasBrand(error, RESERVED_CLIENT_ID_BRAND) && hasClientId(error);
415
+ }
416
+ /** Whether `error` is a {@link SaveFailedError}. See {@link isSessionClosedError}. */
417
+ function isSaveFailedError(error) {
418
+ return hasBrand(error, SAVE_FAILED_BRAND) && hasSaveFailures(error);
419
+ }
420
+ /** Whether `error` is a {@link ConflictError}. See {@link isSessionClosedError}. */
421
+ function isConflictError(error) {
422
+ return hasBrand(error, CONFLICT_BRAND) && hasConflictFields(error);
423
+ }
424
+ /**
425
+ * Whether `error` carries the brand `key` and the `data` record its getters
426
+ * read, so a guard can check the fields through them. A copy whose class
427
+ * lacks a getter fails that check, since the brand alone is public.
428
+ */
429
+ function hasBrand(error, key) {
430
+ return isResponseError(error) && Reflect.get(error, key) === true && isRecord(error.data);
122
431
  }
123
432
  //# sourceMappingURL=errors.js.map
package/lib/errors.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAyHlF,0CAYC;AAnID,mDAA+C;AAC/C,sDAA8F;AAE9F;;;;;;;GAOG;AACU,QAAA,kBAAkB,GAAG,IAAA,0BAAa,EAC5C,uCAAuC,EACvC,4EAA4E,CAC9E,CAAC;AAEF;;;;;;;;GAQG;AACU,QAAA,mBAAmB,GAAG,IAAI,CAAC;AAcxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAa,aAAc,SAAQ,8BAAgC;IAChE,YAAY,GAAW,EAAE,QAAgB,EAAE,MAAc;QACtD,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;QACzC,uEAAuE;QACvE,0EAA0E;QAC1E,yEAAyE;QACzE,KAAK,CAAC,2BAAmB,EAAE,0BAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,IAAA,wBAAW,EAAC,0BAAkB,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QACzH,IAAI,CAAC,IAAI,GAAG,eAAe,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AwB,CAAC,KAAK,CAAC,CAAC;AACtF,CAAC;AAED,6FAA6F;AAC7F,kCAAyC,KAAc;IACpD,OAAO,QAAQ,CAAC,KAAK,EAAE,yBAAyB,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED,4FAA4F;AAC5F,iCAAwC,KAAc;IACnD,OAAO,QAAQ,CAAC,KAAK,EAAE,wBAAwB,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;AAC1E,CAAC;AAED,sFAAsF;AACtF,2BAAkC,KAAc;IAC7C,OAAO,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC;AAED,oFAAoF;AACpF,yBAAgC,KAAc;IAC3C,OAAO,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC;AACtE,CAAC;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,KAAc,EAAE,GAAW;IAC1C,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC7F,CAAC"}
@@ -0,0 +1,33 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+ /** Options of {@link formatLogArg}. An object, so that a `map` index cannot be passed as one. */
10
+ export interface FormatLogArgOptions {
11
+ /** The `space` argument of `JSON.stringify`; compact where omitted. */
12
+ readonly indent?: number;
13
+ }
14
+ /**
15
+ * Render a log argument as text for a log line:
16
+ * - a string as it is;
17
+ * - an error by its stack and causes;
18
+ * - another object as JSON, cut to a bounded size;
19
+ * - anything else by its description, as is an object JSON renders as nothing
20
+ * or cannot render.
21
+ *
22
+ * The cut is needed because the log call serialises synchronously and every
23
+ * Langium AST node is cyclic. The JSON stops at `LOG_ARG_DEPTH` levels,
24
+ * `LOG_ARG_ITEMS` items or keys and `LOG_ARG_STRING_LENGTH` characters per
25
+ * string or key, and at about `LOG_ARG_LENGTH` in all. A reference back to an
26
+ * object that contains it reads `[Circular]`, and a BigInt its digits; the
27
+ * markers are JSON strings. `util.inspect` would cut too, but is Node-only.
28
+ *
29
+ * Never throws, since a log call that throws loses the line and interrupts its
30
+ * caller. A `%s`-style specifier is not substituted.
31
+ */
32
+ export declare function formatLogArg(value: unknown, options?: FormatLogArgOptions): string;
33
+ //# sourceMappingURL=format-log-arg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-log-arg.d.ts","sourceRoot":"","sources":["../src/format-log-arg.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAgBlF,iGAAiG;AACjG,MAAM,WAAW,mBAAmB;IACjC,uEAAuE;IACvE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAiBtF"}