@hydranium/protocol 1.0.0-next.12 → 1.0.0-next.123

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 (142) hide show
  1. package/README.md +35 -1
  2. package/lib/client/data-connection.d.ts +114 -0
  3. package/lib/client/data-connection.d.ts.map +1 -0
  4. package/lib/client/data-connection.js +143 -0
  5. package/lib/client/data-connection.js.map +1 -0
  6. package/lib/client/data-events.d.ts +9 -1
  7. package/lib/client/data-events.d.ts.map +1 -1
  8. package/lib/client/data-events.js +14 -0
  9. package/lib/client/data-events.js.map +1 -1
  10. package/lib/client/data-port.d.ts +17 -22
  11. package/lib/client/data-port.d.ts.map +1 -1
  12. package/lib/client/data-session.d.ts +235 -82
  13. package/lib/client/data-session.d.ts.map +1 -1
  14. package/lib/client/data-session.js +337 -108
  15. package/lib/client/data-session.js.map +1 -1
  16. package/lib/client/index.d.ts +10 -7
  17. package/lib/client/index.d.ts.map +1 -1
  18. package/lib/client/index.js +10 -7
  19. package/lib/client/index.js.map +1 -1
  20. package/lib/client/message-relay.d.ts +8 -2
  21. package/lib/client/message-relay.d.ts.map +1 -1
  22. package/lib/client/message-relay.js +10 -4
  23. package/lib/client/message-relay.js.map +1 -1
  24. package/lib/client/rpc-connection.d.ts +143 -0
  25. package/lib/client/rpc-connection.d.ts.map +1 -0
  26. package/lib/client/rpc-connection.js +171 -0
  27. package/lib/client/rpc-connection.js.map +1 -0
  28. package/lib/client-ids.d.ts +41 -0
  29. package/lib/client-ids.d.ts.map +1 -0
  30. package/lib/client-ids.js +44 -0
  31. package/lib/client-ids.js.map +1 -0
  32. package/lib/data/data-protocol-methods.d.ts +4 -4
  33. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  34. package/lib/data/data-protocol-methods.js +10 -1
  35. package/lib/data/data-protocol-methods.js.map +1 -1
  36. package/lib/data/data-server-protocol.d.ts +100 -31
  37. package/lib/data/data-server-protocol.d.ts.map +1 -1
  38. package/lib/data/events.d.ts +70 -3
  39. package/lib/data/events.d.ts.map +1 -1
  40. package/lib/data/requests.d.ts +67 -11
  41. package/lib/data/requests.d.ts.map +1 -1
  42. package/lib/errors.d.ts +91 -12
  43. package/lib/errors.d.ts.map +1 -1
  44. package/lib/errors.js +127 -18
  45. package/lib/errors.js.map +1 -1
  46. package/lib/index.d.ts +2 -0
  47. package/lib/index.d.ts.map +1 -1
  48. package/lib/index.js +5 -0
  49. package/lib/index.js.map +1 -1
  50. package/lib/latency-collector.d.ts +8 -4
  51. package/lib/latency-collector.d.ts.map +1 -1
  52. package/lib/latency-collector.js.map +1 -1
  53. package/lib/messages/index.d.ts +29 -0
  54. package/lib/messages/index.d.ts.map +1 -0
  55. package/lib/messages/index.js +55 -0
  56. package/lib/messages/index.js.map +1 -0
  57. package/lib/messages/primitives.d.ts +188 -0
  58. package/lib/messages/primitives.d.ts.map +1 -0
  59. package/lib/messages/primitives.js +161 -0
  60. package/lib/messages/primitives.js.map +1 -0
  61. package/lib/model-server.d.ts +44 -13
  62. package/lib/model-server.d.ts.map +1 -1
  63. package/lib/model-server.js +4 -2
  64. package/lib/model-server.js.map +1 -1
  65. package/lib/model-service/based-on.d.ts +57 -0
  66. package/lib/model-service/based-on.d.ts.map +1 -0
  67. package/lib/model-service/based-on.js +37 -0
  68. package/lib/model-service/based-on.js.map +1 -0
  69. package/lib/model-service/index.d.ts +1 -1
  70. package/lib/model-service/index.d.ts.map +1 -1
  71. package/lib/model-service/index.js +4 -5
  72. package/lib/model-service/index.js.map +1 -1
  73. package/lib/patch-merge.d.ts +28 -27
  74. package/lib/patch-merge.d.ts.map +1 -1
  75. package/lib/patch-merge.js +66 -22
  76. package/lib/patch-merge.js.map +1 -1
  77. package/lib/profile-session.d.ts +8 -4
  78. package/lib/profile-session.d.ts.map +1 -1
  79. package/lib/profile-session.js.map +1 -1
  80. package/lib/rpc/bind-rpc-methods.d.ts +29 -3
  81. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  82. package/lib/rpc/bind-rpc-methods.js +22 -3
  83. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  84. package/lib/rpc/create-rpc-proxy.d.ts +7 -0
  85. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  86. package/lib/rpc/create-rpc-proxy.js +6 -1
  87. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  88. package/lib/testing/catalogue-audit.d.ts +80 -0
  89. package/lib/testing/catalogue-audit.d.ts.map +1 -0
  90. package/lib/testing/catalogue-audit.js +94 -0
  91. package/lib/testing/catalogue-audit.js.map +1 -0
  92. package/lib/testing/data-doubles.d.ts +11 -12
  93. package/lib/testing/data-doubles.d.ts.map +1 -1
  94. package/lib/testing/data-doubles.js +14 -5
  95. package/lib/testing/data-doubles.js.map +1 -1
  96. package/lib/testing/index.d.ts +1 -0
  97. package/lib/testing/index.d.ts.map +1 -1
  98. package/lib/testing/index.js +4 -1
  99. package/lib/testing/index.js.map +1 -1
  100. package/lib/transfer-diagnostic.d.ts +33 -0
  101. package/lib/transfer-diagnostic.d.ts.map +1 -1
  102. package/lib/transfer-diagnostic.js +23 -0
  103. package/lib/transfer-diagnostic.js.map +1 -1
  104. package/lib/transfer-document.d.ts +14 -5
  105. package/lib/transfer-document.d.ts.map +1 -1
  106. package/lib/transfer-document.js +14 -1
  107. package/lib/transfer-document.js.map +1 -1
  108. package/package.json +11 -2
  109. package/src/client/data-connection.ts +216 -0
  110. package/src/client/data-events.ts +24 -1
  111. package/src/client/data-port.ts +17 -23
  112. package/src/client/data-session.ts +447 -128
  113. package/src/client/index.ts +10 -7
  114. package/src/client/message-relay.ts +28 -6
  115. package/src/client/rpc-connection.ts +235 -0
  116. package/src/client-ids.ts +45 -0
  117. package/src/data/data-protocol-methods.ts +10 -3
  118. package/src/data/data-server-protocol.ts +119 -31
  119. package/src/data/events.ts +74 -3
  120. package/src/data/requests.ts +71 -11
  121. package/src/errors.ts +139 -20
  122. package/src/index.ts +5 -0
  123. package/src/latency-collector.ts +8 -3
  124. package/src/messages/index.ts +36 -0
  125. package/src/messages/primitives.ts +271 -0
  126. package/src/model-server.ts +47 -18
  127. package/src/model-service/based-on.ts +63 -0
  128. package/src/model-service/index.ts +4 -5
  129. package/src/patch-merge.ts +90 -37
  130. package/src/profile-session.ts +9 -4
  131. package/src/rpc/bind-rpc-methods.ts +49 -4
  132. package/src/rpc/create-rpc-proxy.ts +14 -1
  133. package/src/testing/catalogue-audit.ts +111 -0
  134. package/src/testing/data-doubles.ts +33 -17
  135. package/src/testing/index.ts +4 -1
  136. package/src/transfer-diagnostic.ts +40 -0
  137. package/src/transfer-document.ts +21 -6
  138. package/lib/model-service/args.d.ts +0 -64
  139. package/lib/model-service/args.d.ts.map +0 -1
  140. package/lib/model-service/args.js +0 -11
  141. package/lib/model-service/args.js.map +0 -1
  142. package/src/model-service/args.ts +0 -67
@@ -7,6 +7,8 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
+ import { type MessageParams, type ResolvedMessage } from './messages/primitives';
11
+
10
12
  /**
11
13
  * Generic, transport-friendly diagnostic shape used by the model-server protocol.
12
14
  *
@@ -56,6 +58,21 @@ export interface TransferDiagnostic {
56
58
  * is not usable as a rule identity on its own.
57
59
  */
58
60
  code?: number | string;
61
+ /**
62
+ * Substitutions for the placeholders in the message this {@link code} names,
63
+ * present only for a diagnostic raised from a framework message declaration.
64
+ *
65
+ * Without them a translated template renders with its `{name}` tokens left
66
+ * standing, because substitution leaves an unmatched token in place rather
67
+ * than raising — so a surface that translates from {@link code} alone is
68
+ * correct for a parameterless sentence and visibly wrong for a parameterised
69
+ * one. This is the field that makes the second case work; the LSP carrier has
70
+ * always moved the params, and no carrier below it did.
71
+ *
72
+ * Prefer {@link TransferDiagnostic.resolved} over reading this: it decides
73
+ * whether an identity is present at all, which a lone `params` cannot.
74
+ */
75
+ params?: MessageParams;
59
76
  }
60
77
 
61
78
  export namespace TransferDiagnostic {
@@ -74,6 +91,29 @@ export namespace TransferDiagnostic {
74
91
  return diagnostic.type === 'parsing-error';
75
92
  }
76
93
 
94
+ /**
95
+ * The diagnostic as a renderable message, for a surface that translates.
96
+ * `undefined` when it carries no framework identity — a syntactic error, an
97
+ * adopter's own check, a linker failure — which is the case a caller must
98
+ * distinguish rather than render.
99
+ *
100
+ * Hand the result to `renderFrameworkMessage` with whatever catalogue the
101
+ * host has loaded. The `text` is the server's English, so a code the
102
+ * catalogue does not carry still yields a complete sentence.
103
+ *
104
+ * `code` alone does not establish an identity: it also holds Langium's
105
+ * internal code and an adopter's own, and either would be looked up against a
106
+ * catalogue that cannot have it. Requiring `params` is what discriminates,
107
+ * and it is why a parameterless framework message still populates the field
108
+ * with an empty object rather than omitting it.
109
+ */
110
+ export function resolved(diagnostic: TransferDiagnostic): ResolvedMessage | undefined {
111
+ if (typeof diagnostic.code !== 'string' || diagnostic.params === undefined) {
112
+ return undefined;
113
+ }
114
+ return { code: diagnostic.code, params: diagnostic.params, text: diagnostic.message };
115
+ }
116
+
77
117
  export function getPath(diagnostic: TransferDiagnostic): string {
78
118
  return diagnostic.property ? `${diagnostic.element}${ELEMENT_PROPERTY_SEPARATOR}${diagnostic.property}` : diagnostic.element;
79
119
  }
@@ -9,6 +9,7 @@
9
9
 
10
10
  import type { TransferDiagnostic } from './transfer-diagnostic';
11
11
  import type { TransferElement } from './transfer-element';
12
+ import { asSnapshotVersion, type SnapshotVersion } from './model-service/based-on';
12
13
 
13
14
  /**
14
15
  * Wire envelope exchanged between the model-server's data-server head and
@@ -27,14 +28,13 @@ export interface TransferDocument<TTransfer extends TransferElement, TDiagnostic
27
28
  uri: string;
28
29
  /**
29
30
  * The document version this snapshot was taken at — sourced from the
30
- * server's text-document version counter. Callers that mutate the
31
- * document subsequently pass this value back as `TransferUpdateArgs.baseVersion`
32
- * (or `TransferSaveArgs.baseVersion`) so the server can detect stale-based
33
- * updates and reject them with `ConflictError`.
31
+ * server's text-document version counter. A caller that mutates the document
32
+ * subsequently sends this straight back as `TransferUpdateDocumentArgs.basedOn`, and
33
+ * the server rejects a stale-based update with `ConflictError`.
34
34
  *
35
35
  * See `@hydranium/protocol#errors` for the conflict-detection contract.
36
36
  */
37
- version: number;
37
+ version: SnapshotVersion;
38
38
  /**
39
39
  * Absent when the document does not exist — the server answers an unknown URI
40
40
  * with a shaped envelope rather than an error, so absence is an ordinary
@@ -82,6 +82,21 @@ export namespace TransferDocument {
82
82
  return document;
83
83
  }
84
84
 
85
+ /**
86
+ * The envelope for a document the server does not have — `root` absent, and
87
+ * the version a read of a URI the store never saw reports.
88
+ *
89
+ * Exists so the absent branch is built the same way the present one is: both
90
+ * doors mark the version as coming from a read, and neither asks a caller to
91
+ * do it.
92
+ */
93
+ export function absent<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(
94
+ uri: string,
95
+ diagnostics: TDiagnostic[] = []
96
+ ): TransferDocument<TTransfer, TDiagnostic> {
97
+ return { uri, version: asSnapshotVersion(0), root: undefined, diagnostics };
98
+ }
99
+
85
100
  /**
86
101
  * Construct a {@link TransferDocument} envelope. `diagnostics` defaults
87
102
  * to `[]` so test fixtures, fake protocol implementations, and the
@@ -94,6 +109,6 @@ export namespace TransferDocument {
94
109
  root: TTransfer,
95
110
  diagnostics: TDiagnostic[] = []
96
111
  ): TransferDocument<TTransfer, TDiagnostic> {
97
- return { uri, version, root, diagnostics };
112
+ return { uri, version: asSnapshotVersion(version), root, diagnostics };
98
113
  }
99
114
  }
@@ -1,64 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the MIT License which is available in the project root.
6
- *
7
- * SPDX-License-Identifier: MIT
8
- ********************************************************************************/
9
- /**
10
- * Argument shapes for the in-process `ModelService` facade — the
11
- * canonical home for the lifecycle operation signatures. Implementation
12
- * lives in `@hydranium/core/langium/model-service`; this protocol
13
- * package owns the types so wire-side projections (the data-server
14
- * protocol in `./data`) can structurally extend them rather than
15
- * mirroring them by hand.
16
- *
17
- * `./model-server.ts` re-exports them, so an import from either path
18
- * resolves.
19
- */
20
- /** Identifies a client-document binding. Every facade operation carries these fields. */
21
- export interface TransferClientArgs {
22
- /** Document URI. */
23
- uri: string;
24
- /** Stable identifier for the client invoking the operation. */
25
- clientId: string;
26
- }
27
- /**
28
- * Update a document's content via the in-process facade. `model` may be
29
- * the structured (transfer-model or AST) root or its serialised textual
30
- * form — implementations decide which is faster on their transport.
31
- * Generic over `T` so adopters parameterise the structured shape against
32
- * their grammar's transfer-model overlay; passing a string is always
33
- * allowed.
34
- */
35
- export interface TransferUpdateArgs<T> extends TransferClientArgs {
36
- /** Structured model root or its serialised textual form. */
37
- model: T | string;
38
- /**
39
- * Optional based-on version: the text-document version this update
40
- * was authored against. When set, the server compares against its
41
- * current text-document version for `uri` and throws
42
- * `ConflictError` on mismatch. Omit to opt out of the gate — mirrors
43
- * LSP's `OptionalVersionedTextDocumentIdentifier` posture, intended
44
- * for headless / CLI / batch tooling without a meaningful based-on
45
- * version.
46
- */
47
- baseVersion?: number;
48
- }
49
- /**
50
- * Persist a document to disk via the in-process facade. Same `model`
51
- * shape as {@link TransferUpdateArgs}.
52
- */
53
- export interface TransferSaveArgs<T> extends TransferClientArgs {
54
- /** Structured model root or its serialised textual form. */
55
- model: T | string;
56
- /**
57
- * Optional based-on version — same semantics as
58
- * {@link TransferUpdateArgs.baseVersion}. `save` delegates the gating
59
- * check to its inner `update`, so this field threads through to the
60
- * same `ConflictError` site.
61
- */
62
- baseVersion?: number;
63
- }
64
- //# sourceMappingURL=args.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/model-service/args.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;;;;;GAUG;AAEH,yFAAyF;AACzF,MAAM,WAAW,kBAAkB;IAChC,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,CAAE,SAAQ,kBAAkB;IAC9D,4DAA4D;IAC5D,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;IAClB;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,CAAE,SAAQ,kBAAkB;IAC5D,4DAA4D;IAC5D,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;IAClB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACvB"}
@@ -1,11 +0,0 @@
1
- "use strict";
2
- /********************************************************************************
3
- * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the MIT License which is available in the project root.
7
- *
8
- * SPDX-License-Identifier: MIT
9
- ********************************************************************************/
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- //# sourceMappingURL=args.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/model-service/args.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF"}
@@ -1,67 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the MIT License which is available in the project root.
6
- *
7
- * SPDX-License-Identifier: MIT
8
- ********************************************************************************/
9
-
10
- /**
11
- * Argument shapes for the in-process `ModelService` facade — the
12
- * canonical home for the lifecycle operation signatures. Implementation
13
- * lives in `@hydranium/core/langium/model-service`; this protocol
14
- * package owns the types so wire-side projections (the data-server
15
- * protocol in `./data`) can structurally extend them rather than
16
- * mirroring them by hand.
17
- *
18
- * `./model-server.ts` re-exports them, so an import from either path
19
- * resolves.
20
- */
21
-
22
- /** Identifies a client-document binding. Every facade operation carries these fields. */
23
- export interface TransferClientArgs {
24
- /** Document URI. */
25
- uri: string;
26
- /** Stable identifier for the client invoking the operation. */
27
- clientId: string;
28
- }
29
-
30
- /**
31
- * Update a document's content via the in-process facade. `model` may be
32
- * the structured (transfer-model or AST) root or its serialised textual
33
- * form — implementations decide which is faster on their transport.
34
- * Generic over `T` so adopters parameterise the structured shape against
35
- * their grammar's transfer-model overlay; passing a string is always
36
- * allowed.
37
- */
38
- export interface TransferUpdateArgs<T> extends TransferClientArgs {
39
- /** Structured model root or its serialised textual form. */
40
- model: T | string;
41
- /**
42
- * Optional based-on version: the text-document version this update
43
- * was authored against. When set, the server compares against its
44
- * current text-document version for `uri` and throws
45
- * `ConflictError` on mismatch. Omit to opt out of the gate — mirrors
46
- * LSP's `OptionalVersionedTextDocumentIdentifier` posture, intended
47
- * for headless / CLI / batch tooling without a meaningful based-on
48
- * version.
49
- */
50
- baseVersion?: number;
51
- }
52
-
53
- /**
54
- * Persist a document to disk via the in-process facade. Same `model`
55
- * shape as {@link TransferUpdateArgs}.
56
- */
57
- export interface TransferSaveArgs<T> extends TransferClientArgs {
58
- /** Structured model root or its serialised textual form. */
59
- model: T | string;
60
- /**
61
- * Optional based-on version — same semantics as
62
- * {@link TransferUpdateArgs.baseVersion}. `save` delegates the gating
63
- * check to its inner `update`, so this field threads through to the
64
- * same `ConflictError` site.
65
- */
66
- baseVersion?: number;
67
- }