@hydranium/protocol 1.0.0-next.8 → 1.0.0-next.86

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 (124) 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 +128 -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 +95 -78
  13. package/lib/client/data-session.d.ts.map +1 -1
  14. package/lib/client/data-session.js +115 -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 +139 -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 +2 -2
  33. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  34. package/lib/data/data-protocol-methods.js +6 -1
  35. package/lib/data/data-protocol-methods.js.map +1 -1
  36. package/lib/data/data-server-protocol.d.ts +35 -2
  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/errors.d.ts +28 -11
  41. package/lib/errors.d.ts.map +1 -1
  42. package/lib/errors.js +35 -17
  43. package/lib/errors.js.map +1 -1
  44. package/lib/index.d.ts +2 -0
  45. package/lib/index.d.ts.map +1 -1
  46. package/lib/index.js +5 -0
  47. package/lib/index.js.map +1 -1
  48. package/lib/messages/index.d.ts +28 -0
  49. package/lib/messages/index.d.ts.map +1 -0
  50. package/lib/messages/index.js +52 -0
  51. package/lib/messages/index.js.map +1 -0
  52. package/lib/messages/primitives.d.ts +141 -0
  53. package/lib/messages/primitives.d.ts.map +1 -0
  54. package/lib/messages/primitives.js +138 -0
  55. package/lib/messages/primitives.js.map +1 -0
  56. package/lib/model-server.d.ts +27 -10
  57. package/lib/model-server.d.ts.map +1 -1
  58. package/lib/model-server.js +4 -2
  59. package/lib/model-server.js.map +1 -1
  60. package/lib/model-service/args.d.ts +14 -13
  61. package/lib/model-service/args.d.ts.map +1 -1
  62. package/lib/model-service/based-on.d.ts +55 -0
  63. package/lib/model-service/based-on.d.ts.map +1 -0
  64. package/lib/model-service/based-on.js +34 -0
  65. package/lib/model-service/based-on.js.map +1 -0
  66. package/lib/model-service/index.d.ts +1 -0
  67. package/lib/model-service/index.d.ts.map +1 -1
  68. package/lib/model-service/index.js +1 -0
  69. package/lib/model-service/index.js.map +1 -1
  70. package/lib/rpc/bind-rpc-methods.d.ts +29 -3
  71. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  72. package/lib/rpc/bind-rpc-methods.js +22 -3
  73. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  74. package/lib/rpc/create-rpc-proxy.d.ts +7 -0
  75. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  76. package/lib/rpc/create-rpc-proxy.js +6 -1
  77. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  78. package/lib/testing/catalogue-audit.d.ts +80 -0
  79. package/lib/testing/catalogue-audit.d.ts.map +1 -0
  80. package/lib/testing/catalogue-audit.js +94 -0
  81. package/lib/testing/catalogue-audit.js.map +1 -0
  82. package/lib/testing/data-doubles.d.ts +11 -12
  83. package/lib/testing/data-doubles.d.ts.map +1 -1
  84. package/lib/testing/data-doubles.js +14 -5
  85. package/lib/testing/data-doubles.js.map +1 -1
  86. package/lib/testing/index.d.ts +1 -0
  87. package/lib/testing/index.d.ts.map +1 -1
  88. package/lib/testing/index.js +4 -1
  89. package/lib/testing/index.js.map +1 -1
  90. package/lib/transfer-diagnostic.d.ts +33 -0
  91. package/lib/transfer-diagnostic.d.ts.map +1 -1
  92. package/lib/transfer-diagnostic.js +23 -0
  93. package/lib/transfer-diagnostic.js.map +1 -1
  94. package/lib/transfer-document.d.ts +15 -5
  95. package/lib/transfer-document.d.ts.map +1 -1
  96. package/lib/transfer-document.js +14 -1
  97. package/lib/transfer-document.js.map +1 -1
  98. package/package.json +11 -2
  99. package/src/client/data-connection.ts +181 -0
  100. package/src/client/data-events.ts +24 -1
  101. package/src/client/data-port.ts +17 -23
  102. package/src/client/data-session.ts +172 -131
  103. package/src/client/index.ts +10 -7
  104. package/src/client/message-relay.ts +28 -6
  105. package/src/client/rpc-connection.ts +230 -0
  106. package/src/client-ids.ts +45 -0
  107. package/src/data/data-protocol-methods.ts +6 -3
  108. package/src/data/data-server-protocol.ts +46 -2
  109. package/src/data/events.ts +74 -3
  110. package/src/errors.ts +41 -19
  111. package/src/index.ts +5 -0
  112. package/src/messages/index.ts +35 -0
  113. package/src/messages/primitives.ts +215 -0
  114. package/src/model-server.ts +30 -11
  115. package/src/model-service/args.ts +15 -13
  116. package/src/model-service/based-on.ts +60 -0
  117. package/src/model-service/index.ts +1 -0
  118. package/src/rpc/bind-rpc-methods.ts +49 -4
  119. package/src/rpc/create-rpc-proxy.ts +14 -1
  120. package/src/testing/catalogue-audit.ts +111 -0
  121. package/src/testing/data-doubles.ts +33 -17
  122. package/src/testing/index.ts +4 -1
  123. package/src/transfer-diagnostic.ts +40 -0
  124. package/src/transfer-document.ts +22 -6
@@ -25,6 +25,29 @@ var TransferDiagnostic;
25
25
  return diagnostic.type === 'parsing-error';
26
26
  }
27
27
  TransferDiagnostic.isParseError = isParseError;
28
+ /**
29
+ * The diagnostic as a renderable message, for a surface that translates.
30
+ * `undefined` when it carries no framework identity — a syntactic error, an
31
+ * adopter's own check, a linker failure — which is the case a caller must
32
+ * distinguish rather than render.
33
+ *
34
+ * Hand the result to `renderFrameworkMessage` with whatever catalogue the
35
+ * host has loaded. The `text` is the server's English, so a code the
36
+ * catalogue does not carry still yields a complete sentence.
37
+ *
38
+ * `code` alone does not establish an identity: it also holds Langium's
39
+ * internal code and an adopter's own, and either would be looked up against a
40
+ * catalogue that cannot have it. Requiring `params` is what discriminates,
41
+ * and it is why a parameterless framework message still populates the field
42
+ * with an empty object rather than omitting it.
43
+ */
44
+ function resolved(diagnostic) {
45
+ if (typeof diagnostic.code !== 'string' || diagnostic.params === undefined) {
46
+ return undefined;
47
+ }
48
+ return { code: diagnostic.code, params: diagnostic.params, text: diagnostic.message };
49
+ }
50
+ TransferDiagnostic.resolved = resolved;
28
51
  function getPath(diagnostic) {
29
52
  return diagnostic.property ? `${diagnostic.element}${TransferDiagnostic.ELEMENT_PROPERTY_SEPARATOR}${diagnostic.property}` : diagnostic.element;
30
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transfer-diagnostic.js","sourceRoot":"","sources":["../src/transfer-diagnostic.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAqDlF,IAAiB,kBAAkB,CA+BlC;AA/BD,WAAiB,kBAAkB;IAChC,mEAAmE;IACtD,4CAAyB,GAAG,GAAG,CAAC;IAC7C,wDAAwD;IAC3C,0CAAuB,GAAG,GAAG,CAAC;IAC3C,sFAAsF;IACzE,6CAA0B,GAAG,GAAG,CAAC;IAE9C,SAAgB,OAAO,CAAC,UAA8B;QACnD,OAAO,UAAU,CAAC,QAAQ,KAAK,OAAO,CAAC;IAC1C,CAAC;IA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AA;IAED,SAAgB,YAAY,CAAC,UAA8B;QACxD,OAAO,UAAU,CAAC,IAAI,KAAK,eAAe,CAAC;IAC9C,CAAC;IAFe,+BAAY,eAE3B,CAAA;IAED;;;;;;;;;;;;;;;OAeG;IACH,SAAgB,QAAQ,CAAC,UAA8B;QACpD,IAAI,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,IAAI,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1E,OAAO,SAAS,CAAC;QACpB,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC;IACzF,CAAC;IALe,2BAAQ,WAKvB,CAAA;IAED,SAAgB,OAAO,CAAC,UAA8B;QACnD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,OAAO,GAAG,mBAAA,0BAA0B,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC;IAChI,CAAC;IAFe,0BAAO,UAEtB,CAAA;IAED,SAAgB,MAAM,CAAC,WAAiC;QACrD,OAAO,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAFe,yBAAM,SAErB,CAAA;IAED,SAAgB,SAAS,CAAC,WAAiC;QACxD,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAFe,4BAAS,YAExB,CAAA;IAED,SAAgB,cAAc,CAAC,WAAiC;QAC7D,OAAO,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACzC,CAAC;IAFe,iCAAc,iBAE7B,CAAA;AACJ,CAAC,EAtDgB,kBAAkB,kCAAlB,kBAAkB,QAsDlC"}
@@ -8,6 +8,7 @@
8
8
  ********************************************************************************/
9
9
  import type { TransferDiagnostic } from './transfer-diagnostic';
10
10
  import type { TransferElement } from './transfer-element';
11
+ import { type SnapshotVersion } from './model-service/based-on';
11
12
  /**
12
13
  * Wire envelope exchanged between the model-server's data-server head and
13
14
  * its clients. Carries a transfer-shaped root — never an AST root — plus
@@ -25,14 +26,14 @@ export interface TransferDocument<TTransfer extends TransferElement, TDiagnostic
25
26
  uri: string;
26
27
  /**
27
28
  * The document version this snapshot was taken at — sourced from the
28
- * server's text-document version counter. Callers that mutate the
29
- * document subsequently pass this value back as `TransferUpdateArgs.baseVersion`
30
- * (or `TransferSaveArgs.baseVersion`) so the server can detect stale-based
31
- * updates and reject them with `ConflictError`.
29
+ * server's text-document version counter. A caller that mutates the document
30
+ * subsequently sends this straight back as `TransferUpdateArgs.basedOn` (or
31
+ * `TransferSaveArgs.basedOn`), and the server rejects a stale-based update
32
+ * with `ConflictError`.
32
33
  *
33
34
  * See `@hydranium/protocol#errors` for the conflict-detection contract.
34
35
  */
35
- version: number;
36
+ version: SnapshotVersion;
36
37
  /**
37
38
  * Absent when the document does not exist — the server answers an unknown URI
38
39
  * with a shaped envelope rather than an error, so absence is an ordinary
@@ -62,6 +63,15 @@ export declare namespace TransferDocument {
62
63
  * with it.
63
64
  */
64
65
  function assertLoaded<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(document: TransferDocument<TTransfer, TDiagnostic>): LoadedTransferDocument<TTransfer, TDiagnostic>;
66
+ /**
67
+ * The envelope for a document the server does not have — `root` absent, and
68
+ * the version a read of a URI the store never saw reports.
69
+ *
70
+ * Exists so the absent branch is built the same way the present one is: both
71
+ * doors mark the version as coming from a read, and neither asks a caller to
72
+ * do it.
73
+ */
74
+ function absent<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(uri: string, diagnostics?: TDiagnostic[]): TransferDocument<TTransfer, TDiagnostic>;
65
75
  /**
66
76
  * Construct a {@link TransferDocument} envelope. `diagnostics` defaults
67
77
  * to `[]` so test fixtures, fake protocol implementations, and the
@@ -1 +1 @@
1
- {"version":3,"file":"transfer-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CAAC,CAKhD;IAED;;;;;;;OAOG;IACH,SAAgB,MAAM,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EACvF,GAAG,EAAE,MAAM,EACX,WAAW,GAAE,WAAW,EAAO,GAC/B,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAE1C;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EACvF,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,EACf,WAAW,GAAE,WAAW,EAAO,GAC/B,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAE1C;CACH"}
@@ -9,6 +9,7 @@
9
9
  ********************************************************************************/
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.TransferDocument = void 0;
12
+ const based_on_1 = require("./model-service/based-on");
12
13
  var TransferDocument;
13
14
  (function (TransferDocument) {
14
15
  /**
@@ -32,6 +33,18 @@ var TransferDocument;
32
33
  return document;
33
34
  }
34
35
  TransferDocument.assertLoaded = assertLoaded;
36
+ /**
37
+ * The envelope for a document the server does not have — `root` absent, and
38
+ * the version a read of a URI the store never saw reports.
39
+ *
40
+ * Exists so the absent branch is built the same way the present one is: both
41
+ * doors mark the version as coming from a read, and neither asks a caller to
42
+ * do it.
43
+ */
44
+ function absent(uri, diagnostics = []) {
45
+ return { uri, version: (0, based_on_1.asSnapshotVersion)(0), root: undefined, diagnostics };
46
+ }
47
+ TransferDocument.absent = absent;
35
48
  /**
36
49
  * Construct a {@link TransferDocument} envelope. `diagnostics` defaults
37
50
  * to `[]` so test fixtures, fake protocol implementations, and the
@@ -39,7 +52,7 @@ var TransferDocument;
39
52
  * at every call site.
40
53
  */
41
54
  function create(uri, version, root, diagnostics = []) {
42
- return { uri, version, root, diagnostics };
55
+ return { uri, version: (0, based_on_1.asSnapshotVersion)(version), root, diagnostics };
43
56
  }
44
57
  TransferDocument.create = create;
45
58
  })(TransferDocument || (exports.TransferDocument = TransferDocument = {}));
@@ -1 +1 @@
1
- {"version":3,"file":"transfer-document.js","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAmDlF,IAAiB,gBAAgB,CAwChC;AAxCD,WAAiB,gBAAgB;IAC9B;;;OAGG;IACH,SAAgB,QAAQ,CACrB,QAAkD;QAElD,OAAO,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC;IACtC,CAAC;IAJe,yBAAQ,WAIvB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,YAAY,CACzB,QAAkD;QAElD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,QAAQ,CAAC;IACnB,CAAC;IAPe,6BAAY,eAO3B,CAAA;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CACnB,GAAW,EACX,OAAe,EACf,IAAe,EACf,cAA6B,EAAE;QAE/B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC9C,CAAC;IAPe,uBAAM,SAOrB,CAAA;AACJ,CAAC,EAxCgB,gBAAgB,gCAAhB,gBAAgB,QAwChC"}
1
+ {"version":3,"file":"transfer-document.js","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAIlF,uDAAmF;AAgDnF,IAAiB,gBAAgB,CAuDhC;AAvDD,WAAiB,gBAAgB;IAC9B;;;OAGG;IACH,SAAgB,QAAQ,CACrB,QAAkD;QAElD,OAAO,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC;IACtC,CAAC;IAJe,yBAAQ,WAIvB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,YAAY,CACzB,QAAkD;QAElD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,QAAQ,CAAC;IACnB,CAAC;IAPe,6BAAY,eAO3B,CAAA;IAED;;;;;;;OAOG;IACH,SAAgB,MAAM,CACnB,GAAW,EACX,cAA6B,EAAE;QAE/B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAA,4BAAiB,EAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;IAC/E,CAAC;IALe,uBAAM,SAKrB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CACnB,GAAW,EACX,OAAe,EACf,IAAe,EACf,cAA6B,EAAE;QAE/B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAA,4BAAiB,EAAC,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC1E,CAAC;IAPe,uBAAM,SAOrB,CAAA;AACJ,CAAC,EAvDgB,gBAAgB,gCAAhB,gBAAgB,QAuDhC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hydranium/protocol",
3
- "version": "1.0.0-next.8",
3
+ "version": "1.0.0-next.86",
4
4
  "description": "Generic, language-agnostic types, constants, and pure utilities for the hydranium framework.",
5
5
  "keywords": [
6
6
  "hydranium",
@@ -41,6 +41,14 @@
41
41
  "types": "./lib/data/index.d.ts",
42
42
  "default": "./lib/data/index.js"
43
43
  },
44
+ "./messages": {
45
+ "types": "./lib/messages/index.d.ts",
46
+ "default": "./lib/messages/index.js"
47
+ },
48
+ "./lib/messages": {
49
+ "types": "./lib/messages/index.d.ts",
50
+ "default": "./lib/messages/index.js"
51
+ },
44
52
  "./testing": {
45
53
  "types": "./lib/testing/index.d.ts",
46
54
  "default": "./lib/testing/index.js"
@@ -88,7 +96,7 @@
88
96
  "vscode-jsonrpc": "9.0.1"
89
97
  },
90
98
  "peerDependencies": {
91
- "vscode-jsonrpc": "^8.0.0 || ^9.0.0"
99
+ "vscode-jsonrpc": "9.0.1"
92
100
  },
93
101
  "engines": {
94
102
  "node": ">=22.13"
@@ -96,5 +104,6 @@
96
104
  "publishConfig": {
97
105
  "access": "public"
98
106
  },
107
+ "//peerDependencies": "`vscode-jsonrpc` is EXACT rather than a range, because it is one link of an atomic chain with no independently movable link: `vscode-languageserver-protocol` depends on it at exactly 9.0.1, so any other value an adopter supplies is a SECOND physical copy rather than an upgrade. This wire stack breaks on copy identity rather than on structure — `ParameterStructures.auto` is a singleton compared by `===` in connection.js, so a request type built by one copy and sent over a connection owned by the other throws `Unknown parameter structure auto`. A caret or union range was rejected because npm then resolves a `vscode-jsonrpc@8.2.0` tree SILENTLY, with no diagnostic at all, and the failure surfaces only later at server init. Exact does not fail the install either — npm downgrades an unsatisfiable peer to a warning — but it is a NAMED ERESOLVE warning printing the required version beside the found one, and a hard error for anyone installing with `--strict-peer-deps`. It does NOT prevent a NESTED copy — `@eclipse-glsp/*` carries its own exact `vscode-jsonrpc@8.2.0` dependency and root `overrides` do not ship — so a consumer of the GLSP head must pin the chain in its own manifest, and docs/adopting/requirements.md carries the block to paste.",
99
108
  "//prepack": "The publish guard, and it deliberately is NOT a `prepare`: npm runs a workspace `prepare` BEFORE the root `postinstall` that applies patches/vscode-jsonrpc+9.0.1.patch, so building there fails on a cold clone and npm rolls the entire install back. `prepack` runs only when a tarball is made (`npm pack`, `npm publish`) and never on install, so it cannot break the install it has no business touching. It FAILS rather than rebuilds, because the rebuild is exactly the part that ordering defeats. What it defends against: `files` lists `lib`, `lib` is gitignored, and a `files` entry matching nothing is skipped SILENTLY — so `npm publish` from an unbuilt tree emits a tarball of `src` and nothing else, with no error."
100
109
  }
@@ -0,0 +1,181 @@
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
+ import { FRAMEWORK_CLIENT_IDS } from '../client-ids';
11
+ import {
12
+ DATA_CLIENT_PROTOCOL_METHODS,
13
+ DATA_SERVER_WIRE_PREFIX,
14
+ type DataClientProtocol,
15
+ type DataServerProtocol,
16
+ type DiagnosticOf,
17
+ type ProjectOf
18
+ } from '../data';
19
+ import type { TransferElement } from '../transfer-element';
20
+ import { DataEvents } from './data-events';
21
+ import type { DataPort } from './data-port';
22
+ import { DataSession } from './data-session';
23
+ import { RpcConnection, type RpcConnectionLifecycle } from './rpc-connection';
24
+
25
+ /** Options for {@link DataConnection}. */
26
+ export interface DataConnectionOptions extends RpcConnectionLifecycle {
27
+ /**
28
+ * Wire namespace the server is addressed under. Defaults to the
29
+ * framework's {@link DATA_SERVER_WIRE_PREFIX}, which is what an unmodified
30
+ * `DataServer` binds. Override only alongside the server's own
31
+ * `methodNamespace` option — a mismatch turns every request into
32
+ * "Unhandled method" rather than failing at wire-up.
33
+ */
34
+ readonly methodNamespace?: string;
35
+ }
36
+
37
+ /** {@link DataConnectionOptions} for a client that does not speak {@link DataClientProtocol}. */
38
+ export interface DataConnectionOptionsWithMethods<TClient extends object> extends DataConnectionOptions {
39
+ /**
40
+ * Method names of the client to bind as inbound handlers. Declare it
41
+ * `as const satisfies ReadonlyArray<keyof YourClient & string>` so the list
42
+ * cannot drift from the interface.
43
+ */
44
+ readonly clientMethods: readonly (keyof TClient & string)[];
45
+ }
46
+
47
+ /**
48
+ * Trailing constructor arguments, required only when the client cannot take
49
+ * the framework's default method list.
50
+ *
51
+ * `bindRpcMethods` throws for a name the target does not implement, so a
52
+ * request/response-only client binding the default list fails at wire-up. The
53
+ * conditional turns that into a compile error.
54
+ */
55
+ export type DataConnectionArgs<TTransfer extends TransferElement, TClient extends object> =
56
+ TClient extends DataClientProtocol<TTransfer>
57
+ ? [options?: DataConnectionOptions & Partial<DataConnectionOptionsWithMethods<TClient>>]
58
+ : [options: DataConnectionOptionsWithMethods<TClient>];
59
+
60
+ /**
61
+ * A {@link RpcConnection} to the data head, carrying as many participants as
62
+ * the host has interested parties.
63
+ *
64
+ * Document operations live on the participants rather than here: they carry a
65
+ * `clientId`, which identifies a participant rather than a wire, and the server
66
+ * keys its holds and watches per `(uri, clientId)`. Two parties sharing one
67
+ * identity cannot tell each other's writes from their own echoes.
68
+ *
69
+ * Generic over the transfer root so this file names no grammar. An adopter
70
+ * binds the concrete root (or the union of them, for a multi-grammar head) at
71
+ * its own edge.
72
+ */
73
+ export class DataConnection<
74
+ TTransfer extends TransferElement,
75
+ TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>,
76
+ TClient extends object = DataClientProtocol<TTransfer>
77
+ > extends RpcConnection<TServer, TClient> {
78
+ protected readonly sessions = new Set<DataSession<TTransfer, TServer>>();
79
+
80
+ constructor(port: DataPort, client: TClient, ...rest: DataConnectionArgs<TTransfer, TClient>) {
81
+ const [options = {}] = rest as [(DataConnectionOptions & Partial<DataConnectionOptionsWithMethods<TClient>>)?];
82
+ super(port, client, {
83
+ methodNamespace: options.methodNamespace ?? DATA_SERVER_WIRE_PREFIX,
84
+ // The default is reachable only where `TClient` satisfies
85
+ // `DataClientProtocol`, which the constructor's conditional enforces;
86
+ // the compiler cannot carry that through to the generic parameter.
87
+ clientMethods: options.clientMethods ?? (DATA_CLIENT_PROTOCOL_METHODS as unknown as readonly (keyof TClient & string)[]),
88
+ lifecycle: options
89
+ });
90
+ }
91
+
92
+ /**
93
+ * Mint a participant on this connection under `clientId`.
94
+ *
95
+ * `clientId` must be distinct per participant and stable for its lifetime:
96
+ * it keys the server's per-`(uri, clientId)` hold and watch, and it is the
97
+ * echo key an inbound `onDocumentUpdated` is matched against.
98
+ *
99
+ * Throws for an id in {@link FRAMEWORK_CLIENT_IDS} — those are authors the
100
+ * SERVER emits rather than participants, so a session holding one would read
101
+ * the framework's own broadcasts as its own echoes and drop them. Nothing
102
+ * about that fails on its own: the document simply stops following, which
103
+ * looks like a dead connection.
104
+ *
105
+ * Throws, too, for an id a LIVE session on this connection already holds.
106
+ * Per-document membership is a set of client ids, so two participants
107
+ * sharing one collapse to a single hold and the first close releases it
108
+ * under the survivor, which then stops receiving updates for a document it
109
+ * is still showing. A constant bound once per participant KIND — one per
110
+ * widget class rather than per instance — satisfies the type and violates
111
+ * this.
112
+ *
113
+ * The check spans this connection only, so a head several connections reach
114
+ * can still be addressed twice under one id.
115
+ */
116
+ createSession(clientId: string): DataSession<TTransfer, TServer> {
117
+ this.assertLive();
118
+ if (FRAMEWORK_CLIENT_IDS.includes(clientId)) {
119
+ throw new Error(`clientId '${clientId}' is reserved by the framework and cannot identify a participant`);
120
+ }
121
+ if ([...this.sessions].some(session => session.clientId === clientId)) {
122
+ throw new Error(`clientId '${clientId}' already identifies a live participant on this connection`);
123
+ }
124
+ const session = new DataSession<TTransfer, TServer>(clientId, {
125
+ connected: () => this.connected(),
126
+ releaseSession: released => this.sessions.delete(released)
127
+ });
128
+ this.sessions.add(session);
129
+ return session;
130
+ }
131
+
132
+ /**
133
+ * Sessions are detached rather than disposed: the server releases every hold
134
+ * on a connection it sees close, so closing each document first sends
135
+ * requests over a connection this call is about to dispose.
136
+ */
137
+ override dispose(): void {
138
+ for (const session of [...this.sessions]) {
139
+ session.detach();
140
+ }
141
+ this.sessions.clear();
142
+ super.dispose();
143
+ }
144
+ }
145
+
146
+ /**
147
+ * A {@link DataConnection} that brings its own {@link DataEvents}, so a host
148
+ * with several interested parties does not have to supply one.
149
+ *
150
+ * **The client slot holds exactly one object, and that is why this exists.**
151
+ * `createRpcProxy` binds a single `localTarget`, and underneath a method name
152
+ * maps to one handler — a second registration replaces the first silently. So a
153
+ * properties panel and a tree cannot both be the client; one fan-out sits in the
154
+ * slot and both subscribe to it.
155
+ *
156
+ * Use {@link DataConnection} directly instead when the client is yours: an
157
+ * adopter service that implements the protocol plus its own methods, a single
158
+ * consumer that IS the client, or a request/response-only client that binds
159
+ * nothing.
160
+ */
161
+ export class DataConnectionWithEvents<
162
+ TTransfer extends TransferElement,
163
+ TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>
164
+ > extends DataConnection<TTransfer, TServer, DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>> {
165
+ /** Server pushes, fanned out to as many local listeners as the host has. */
166
+ readonly events: DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>;
167
+
168
+ constructor(port: DataPort, options?: DataConnectionOptions) {
169
+ // Built as a local because `this` is unavailable before `super`, then
170
+ // read back onto the field.
171
+ const events = new DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>();
172
+ super(port, events, options);
173
+ this.events = events;
174
+ }
175
+
176
+ /** Disposes the fan-out it created, which no caller else holds. */
177
+ override dispose(): void {
178
+ super.dispose();
179
+ this.events.dispose();
180
+ }
181
+ }
@@ -8,7 +8,14 @@
8
8
  ********************************************************************************/
9
9
 
10
10
  import { Emitter, type Event } from 'vscode-jsonrpc';
11
- import type { DataClientProtocol, ProjectsChangedEvent, TransferDocumentSavedEvent, TransferDocumentUpdatedEvent } from '../data';
11
+ import type {
12
+ DataClientProtocol,
13
+ ProjectsChangedEvent,
14
+ TransferDocumentDeletedEvent,
15
+ TransferDocumentSavedEvent,
16
+ TransferDocumentsBuiltEvent,
17
+ TransferDocumentUpdatedEvent
18
+ } from '../data';
12
19
  import type { Project } from '../project';
13
20
  import type { TransferDiagnostic } from '../transfer-diagnostic';
14
21
  import type { TransferElement } from '../transfer-element';
@@ -40,12 +47,18 @@ export class DataEvents<
40
47
  > implements DataClientProtocol<TTransfer, TDiagnostic, TProject> {
41
48
  protected readonly documentUpdatedEmitter = new Emitter<TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>>();
42
49
  protected readonly documentSavedEmitter = new Emitter<TransferDocumentSavedEvent<TTransfer, TDiagnostic>>();
50
+ protected readonly documentDeletedEmitter = new Emitter<TransferDocumentDeletedEvent>();
51
+ protected readonly documentsBuiltEmitter = new Emitter<TransferDocumentsBuiltEvent>();
43
52
  protected readonly projectsChangedEmitter = new Emitter<ProjectsChangedEvent<TProject>>();
44
53
 
45
54
  /** A build-phase event for a watched document. Carries the originating `sourceClientId`. */
46
55
  readonly onDidUpdateDocument: Event<TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>> = this.documentUpdatedEmitter.event;
47
56
  /** A watched document was persisted to disk. */
48
57
  readonly onDidSaveDocument: Event<TransferDocumentSavedEvent<TTransfer, TDiagnostic>> = this.documentSavedEmitter.event;
58
+ /** A document's backing file was removed, watched or not. Any watch survives. */
59
+ readonly onDidDeleteDocument: Event<TransferDocumentDeletedEvent> = this.documentDeletedEmitter.event;
60
+ /** Documents built that nobody watches — re-read anything derived from them. */
61
+ readonly onDidBuildDocuments: Event<TransferDocumentsBuiltEvent> = this.documentsBuiltEmitter.event;
49
62
  /** The project set changed. */
50
63
  readonly onDidChangeProjects: Event<ProjectsChangedEvent<TProject>> = this.projectsChangedEmitter.event;
51
64
 
@@ -59,6 +72,14 @@ export class DataEvents<
59
72
  this.documentSavedEmitter.fire(event);
60
73
  }
61
74
 
75
+ onDocumentDeleted(event: TransferDocumentDeletedEvent): void {
76
+ this.documentDeletedEmitter.fire(event);
77
+ }
78
+
79
+ onDocumentsBuilt(event: TransferDocumentsBuiltEvent): void {
80
+ this.documentsBuiltEmitter.fire(event);
81
+ }
82
+
62
83
  onProjectsChanged(event: ProjectsChangedEvent<TProject>): void {
63
84
  this.projectsChangedEmitter.fire(event);
64
85
  }
@@ -66,6 +87,8 @@ export class DataEvents<
66
87
  dispose(): void {
67
88
  this.documentUpdatedEmitter.dispose();
68
89
  this.documentSavedEmitter.dispose();
90
+ this.documentDeletedEmitter.dispose();
91
+ this.documentsBuiltEmitter.dispose();
69
92
  this.projectsChangedEmitter.dispose();
70
93
  }
71
94
  }
@@ -8,21 +8,25 @@
8
8
  ********************************************************************************/
9
9
 
10
10
  import type { Event, MessageConnection } from 'vscode-jsonrpc';
11
+ import type { ResolvedMessage } from '../messages/primitives';
11
12
 
12
13
  /**
13
14
  * The one thing a host has to supply for the data head: a live JSON-RPC
14
- * connection to the data server, plus the identity and failure sink that go
15
- * with it.
15
+ * connection to the data server, plus the failure sink that goes with it.
16
16
  *
17
- * "Port" in the hexagonal sense — the host implements it, `DataSession`
17
+ * "Port" in the hexagonal sense — the host implements it, `DataConnection`
18
18
  * consumes it, and nothing on either side of the boundary imports the other.
19
19
  *
20
+ * Carries no identity. A `clientId` names a participant, and one transport
21
+ * serves as many as the host has; binding an identity here is what makes two
22
+ * of them share one, so it lives on `DataSession` instead.
23
+ *
20
24
  * **This deliberately does NOT wrap the protocol methods.** `createRpcProxy`
21
25
  * already takes a promise of a connection and produces the whole typed
22
26
  * `DataServerProtocol` surface, so wrapping it would re-derive the framework's
23
27
  * pass-throughs in a second place and lose the `as const satisfies keyof`
24
28
  * method allowlists, which cannot drift. Everything a form or a tree actually
25
- * does — the wire contract, the open/watch/update/close sequence, `baseVersion`
29
+ * does — the wire contract, the open/watch/update/close sequence, `basedOn`
26
30
  * conflict handling, echo filtering by `sourceClientId` — is host-invariant and
27
31
  * lives above this interface. What varies between hosts is exactly the four
28
32
  * members below.
@@ -45,22 +49,6 @@ import type { Event, MessageConnection } from 'vscode-jsonrpc';
45
49
  * calls on the promise but never calls `listen` itself.
46
50
  */
47
51
  export interface DataPort {
48
- /**
49
- * Stable identity of this client on the data server, passed as `clientId`
50
- * on every document request.
51
- *
52
- * It has to be stable for the session because it is the echo key: an
53
- * inbound `onDocumentUpdated` carries the originating mutation's
54
- * `clientId` as `sourceClientId`, and a client that cannot recognise its
55
- * own echo treats its own write as a concurrent third-party one. It also
56
- * has to be distinct per client, since it keys the server's per-
57
- * `(uri, clientId)` watch bucket.
58
- *
59
- * Avoid the three values the framework itself uses as sentinels —
60
- * `'language-client'`, `'unknown'` and `'revert-on-close'`.
61
- */
62
- readonly clientId: string;
63
-
64
52
  /**
65
53
  * Open the transport and hand back a listening `MessageConnection`.
66
54
  *
@@ -77,10 +65,16 @@ export interface DataPort {
77
65
  *
78
66
  * It exists because the alternative is worse in both directions: this tier
79
67
  * cannot import a host's UI, and swallowing the error makes a dead
80
- * connection look like an empty model. `context` names what was being
81
- * attempted, not where in the code it happened.
68
+ * connection look like an empty model.
69
+ *
70
+ * `reported` is a complete sentence plus the identity needed to render it in
71
+ * another language. It carries a value rather than using a protocol field
72
+ * because this tier does not know whether a process hop intervenes — in a
73
+ * webview host the render happens across one — and a `ResolvedMessage` is
74
+ * structured-clone safe either way. Render it with `renderFrameworkMessage`;
75
+ * passing no translation map yields the English.
82
76
  */
83
- reportError(error: unknown, context: string): void;
77
+ reportError(error: unknown, reported: ResolvedMessage): void;
84
78
 
85
79
  /**
86
80
  * Fires when the host tears the transport down and the current connection