@hydranium/protocol 1.0.0-next.19 → 1.0.0-next.192

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