@hydranium/data-server 1.0.0-next.31 → 1.0.0-next.313

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 (35) hide show
  1. package/README.md +57 -73
  2. package/lib/browser/index.d.ts +10 -0
  3. package/lib/browser/index.d.ts.map +1 -0
  4. package/lib/browser/index.js +15 -0
  5. package/lib/browser/index.js.map +1 -0
  6. package/lib/browser/start-data-server-in-worker.d.ts +23 -0
  7. package/lib/browser/start-data-server-in-worker.d.ts.map +1 -0
  8. package/lib/browser/start-data-server-in-worker.js +29 -0
  9. package/lib/browser/start-data-server-in-worker.js.map +1 -0
  10. package/lib/data-server.d.ts +444 -290
  11. package/lib/data-server.d.ts.map +1 -1
  12. package/lib/data-server.js +752 -506
  13. package/lib/data-server.js.map +1 -1
  14. package/lib/messages/index.d.ts +1 -1
  15. package/lib/messages/index.d.ts.map +1 -1
  16. package/lib/messages/index.js +1 -1
  17. package/lib/messages/index.js.map +1 -1
  18. package/lib/node/node-diagnostics-provider.d.ts.map +1 -1
  19. package/lib/node/node-diagnostics-provider.js +2 -1
  20. package/lib/node/node-diagnostics-provider.js.map +1 -1
  21. package/lib/testing/data-server-harness.d.ts +31 -14
  22. package/lib/testing/data-server-harness.d.ts.map +1 -1
  23. package/lib/testing/data-server-harness.js +8 -3
  24. package/lib/testing/data-server-harness.js.map +1 -1
  25. package/lib/testing/index.d.ts +1 -0
  26. package/lib/testing/index.d.ts.map +1 -1
  27. package/lib/testing/index.js.map +1 -1
  28. package/package.json +35 -43
  29. package/src/browser/index.ts +15 -0
  30. package/src/browser/start-data-server-in-worker.ts +35 -0
  31. package/src/data-server.ts +908 -545
  32. package/src/messages/index.ts +8 -1
  33. package/src/node/node-diagnostics-provider.ts +2 -8
  34. package/src/testing/data-server-harness.ts +55 -26
  35. package/src/testing/index.ts +5 -2
package/README.md CHANGED
@@ -1,42 +1,21 @@
1
1
  # `@hydranium/data-server`
2
2
 
3
- The typed JSON-RPC data head of [hydranium](../../README.md): it exposes the live
4
- Langium AST to non-LSP clients — form editors, tree views, code generators — as
5
- an adopter-defined transfer model over a `vscode-jsonrpc` `MessageConnection`.
6
- Installed by the server process that already composes
7
- [`@hydranium/core`](../core); a client needs only
8
- [`@hydranium/protocol`](../protocol).
3
+ The data head of [Hydranium](https://github.com/eclipse-emfcloud/hydranium): it
4
+ serves your model over JSON-RPC to clients other than a text editor, such as
5
+ forms, tree views and code generators. Install it in the server that composes
6
+ `@hydranium/core`; a client talks to it through `@hydranium/protocol`.
9
7
 
10
8
  ## What it gives you
11
9
 
12
- - **One class, `DataServer`.** `new DataServer(connection, services, options)`
13
- self-wires: a single `createRpcProxy` call registers the inbound
14
- `DataServerProtocol` handlers and builds the outbound `DataClientProtocol`
15
- proxy on the same wire. It contributes no shared-tier DI bindings — it reads
16
- exclusively from `ServerSharedServices`, so there is no shared module to
17
- compose.
18
- - **A document lifecycle over the shared workspace:** `openModelDocument`,
19
- `getModelDocument`, `updateModelDocument`, `saveModelDocument`,
20
- `closeModelDocument`, `watchModelDocument` / `unwatchModelDocument`, and
21
- `waitForReady` for clients that must not race workspace initialisation.
22
- - **Push notifications instead of polling:** `onDocumentUpdated` when a
23
- subscribed document reaches the configured build phase
24
- (`DataServerOptions.subscriptionPhase`, `DocumentState.Validated` by default),
25
- `onDocumentSaved` on a separate channel, and `onProjectsChanged` from the
26
- project registry.
27
- - **Projects as first-class:** `getProjects` and `getProjectForUri`, answered from
28
- the framework's `ProjectManager`.
29
- - **An opt-in reference/naming slice** — `findReferenceCandidates`,
30
- `resolveReference`, `findNextName` — implemented here but deliberately outside
31
- the `DataServerProtocol` composition, so a pure data consumer does not pay for
32
- it. Compose `ReferenceServerProtocol` onto the connection explicitly.
33
- - **A diagnostics seam,** `DataServerDiagnosticsProvider`, with the Node
34
- implementation `nodeDataServerDiagnostics()` behind `./node` so the portable
35
- entry keeps bundling for a browser.
36
-
37
- The projection itself is not this package's: it delegates to `TransferEncoder`
38
- and `ModelService` from `@hydranium/core`, so there is no second in-memory model
39
- to keep in sync.
10
+ - Typed reads, updates and saves of documents in the shared workspace, as your
11
+ transfer model. An edit from a data client reaches the other heads.
12
+ - Notifications when a document is rebuilt, saved or deleted, so a client
13
+ never polls.
14
+ - Your own methods on the same connection, through a `DataServer` subclass and
15
+ its `additionalMethods` option.
16
+ - An optional reference and naming slice: pass
17
+ `REFERENCE_SERVER_PROTOCOL_METHODS` from `@hydranium/protocol/data` in
18
+ `additionalMethods`.
40
19
 
41
20
  ## Install
42
21
 
@@ -44,48 +23,53 @@ to keep in sync.
44
23
  npm install @hydranium/data-server
45
24
  ```
46
25
 
47
- This package bundles no runtime dependencies. Its peers must be present:
48
- `@hydranium/core`, `@hydranium/protocol`, `@hydranium/langium`, `vscode-jsonrpc`
49
- and `vscode-languageserver-textdocument`. You must already have a composed
50
- hydranium shared services tree and a `MessageConnection` — the socket and stdio
51
- launchers live in `@hydranium/core/node`, not here.
52
-
53
- ## Exports
54
-
55
- | subpath | holds | platform |
56
- | ----------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------- |
57
- | `.` | `DataServer` and its option types, plus the `DataServerDiagnosticsProvider` seam — the whole production surface. | browser-neutral |
58
- | `./node` | `nodeDataServerDiagnostics()`, the runtime-backed half of the diagnostics seam. | Node-only |
59
- | `./testing` | `makeDataServerHarness` — a real server driven in-process over a duplex connection pair. | Node-only (`vscode-jsonrpc/node`) |
60
-
61
- `.` is gated as browser-neutral in CI (`scripts/check-neutral-bundles.mjs`). It
62
- stays that way through a `browser` field in `package.json` that swaps the
63
- diagnostics default for a browser twin, so a bundler never follows the
64
- `@hydranium/core/node` import a Node host resolves — see [what "gated neutral" does and does not promise](../../docs/concepts/browser-hosting.md#a-note-on-what-gated-neutral-does-and-does-not-promise).
65
- Each subpath also has a `./lib/…` twin for consumers on
66
- `moduleResolution: "Node"`.
67
-
68
- ## Getting oriented
69
-
70
- Construct the head after the shared services tree exists and keep the returned
71
- instance for `dispose`; it registers its handlers on the connection you pass and
72
- subscribes to the document builder, the text-document store and the project
73
- manager for its push notifications. The typed contract a client codes against —
74
- `DataServerProtocol`, `DataClientProtocol`, the drift-proof method-name lists and
75
- the port constants — lives in `@hydranium/protocol/data`, and the generic
76
- `createRpcProxy` / `bindRpcMethods` machinery in `@hydranium/protocol`. The four
77
- distinct meanings of "document" this head sits between are worth reading first:
78
- [`docs/concepts/document-layers.md`](../../docs/concepts/document-layers.md). See
79
- also [`docs/concepts/architecture.md`](../../docs/concepts/architecture.md) and
80
- [`docs/concepts/head-module-maps.md`](../../docs/concepts/head-module-maps.md).
26
+ | Peer | Range |
27
+ | ------------------------------------ | ------------- |
28
+ | `@hydranium/core` | `^1.0.0-next` |
29
+ | `@hydranium/langium` | `^1.0.0-next` |
30
+ | `@hydranium/protocol` | `^1.0.0-next` |
31
+ | `vscode-jsonrpc` | `^9.0.0` |
32
+ | `vscode-languageserver-textdocument` | `^1.0.12` |
33
+
34
+ ## Wiring
35
+
36
+ The head adds no services module: it reads the shared services you composed
37
+ with `@hydranium/core`.
38
+
39
+ 1. Start a launcher from `@hydranium/core/node`: `startSocketServer` beside the
40
+ LSP head, with `publishPortOnLspConnection` to tell the client its port, or
41
+ `startStdioServer` for a data head alone. Without an LSP head, give it the
42
+ workspace root as `workspace`.
43
+ 2. In its connection callback, create `new DataServer(connection, shared)`. It
44
+ cleans up when the connection closes.
45
+ 3. In a web worker, start it with `startDataServerInWorker` from `./browser`
46
+ on the port the page transferred for it; its callback creates the server.
47
+
48
+ See *Add a data-server method* and *Connect a data client* in
49
+ [Adopting Hydranium](https://github.com/eclipse-emfcloud/hydranium/blob/main/docs/ADOPTING.md).
50
+
51
+ ## Entry points
52
+
53
+ | Subpath | Use it for | Runs in |
54
+ | ------------ | ---------------------------------------------------------- | --------------- |
55
+ | `.` | `DataServer`, its options, and the diagnostics seam | browser-neutral |
56
+ | `./node` | The Node implementation of the diagnostics seam | Node-only |
57
+ | `./browser` | Starting the head in a web worker | browser-only |
58
+ | `./messages` | The codes of the messages this package raises | browser-neutral |
59
+ | `./testing` | A harness that drives a real data head in-process | Node-only |
60
+
61
+ The subpaths need a TypeScript `moduleResolution` that reads `exports`
62
+ (`NodeNext` or `Bundler`); see *Requirements* in
63
+ [Adopting Hydranium](https://github.com/eclipse-emfcloud/hydranium/blob/main/docs/ADOPTING.md).
81
64
 
82
65
  ## Status
83
66
 
84
- Alpha — pre-v0, not yet published. The API is not stable and may change without a
85
- deprecation cycle. See the [repository README](../../README.md) for the current
86
- status and known limitations.
67
+ Alpha: every release is a prerelease that may break the API, so pin an exact
68
+ version. Guides and known limitations:
69
+ [Adopting Hydranium](https://github.com/eclipse-emfcloud/hydranium/blob/main/docs/ADOPTING.md).
87
70
 
88
71
  ## License
89
72
 
90
- `MIT` — see this package's [`LICENSE`](./LICENSE). Third-party notices for the
91
- repository are recorded in [`NOTICE.md`](../../NOTICE.md).
73
+ `MIT` — see this package's [`LICENSE`](./LICENSE), and the repository
74
+ [`NOTICE.md`](https://github.com/eclipse-emfcloud/hydranium/blob/main/NOTICE.md)
75
+ for third-party notices.
@@ -0,0 +1,10 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+ export * from './start-data-server-in-worker.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAOlF,cAAc,kCAAkC,CAAC"}
@@ -0,0 +1,15 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+ // Browser-only entry (`@hydranium/data-server/browser`). Holds the worker
10
+ // starter, whose connection comes from `vscode-jsonrpc/browser`. The portable
11
+ // `.` entry stays free of that import for the same reason it stays free of the
12
+ // node one: it must resolve under both platforms, and a build that names one
13
+ // has picked.
14
+ export * from './start-data-server-in-worker.js';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,0EAA0E;AAC1E,8EAA8E;AAC9E,+EAA+E;AAC/E,6EAA6E;AAC7E,cAAc;AACd,cAAc,kCAAkC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+ import { type TransferredMessagePort } from '@hydranium/protocol';
10
+ import type { ServerSharedServicesMinimal } from '@hydranium/core';
11
+ import { type MessageConnection } from 'vscode-jsonrpc/browser';
12
+ /**
13
+ * Start the data head on the port the page transferred for it, on the same
14
+ * shared tier the LSP head runs on, and return the server `create` built.
15
+ *
16
+ * `create` constructs the adopter's `DataServer`, or a subclass of it, around
17
+ * the connection, as a Node host's socket callback does, and the connection
18
+ * listens once it has returned, in the order the Node launcher uses. The
19
+ * page's end of the port closing disposes the server, which ends every
20
+ * session this connection registered.
21
+ */
22
+ export declare function startDataServerInWorker<TServer>(port: TransferredMessagePort, shared: Pick<ServerSharedServicesMinimal, 'Logger'>, create: (connection: MessageConnection) => TServer): TServer;
23
+ //# sourceMappingURL=start-data-server-in-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-data-server-in-worker.d.ts","sourceRoot":"","sources":["../../src/browser/start-data-server-in-worker.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAA8B,KAAK,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAA2B,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEzF;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAC5C,IAAI,EAAE,sBAAsB,EAC5B,MAAM,EAAE,IAAI,CAAC,2BAA2B,EAAE,QAAQ,CAAC,EACnD,MAAM,EAAE,CAAC,UAAU,EAAE,iBAAiB,KAAK,OAAO,GAClD,OAAO,CAOT"}
@@ -0,0 +1,29 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+ import { createMessagePortTransport } from '@hydranium/protocol';
10
+ import { createMessageConnection } from 'vscode-jsonrpc/browser';
11
+ /**
12
+ * Start the data head on the port the page transferred for it, on the same
13
+ * shared tier the LSP head runs on, and return the server `create` built.
14
+ *
15
+ * `create` constructs the adopter's `DataServer`, or a subclass of it, around
16
+ * the connection, as a Node host's socket callback does, and the connection
17
+ * listens once it has returned, in the order the Node launcher uses. The
18
+ * page's end of the port closing disposes the server, which ends every
19
+ * session this connection registered.
20
+ */
21
+ export function startDataServerInWorker(port, shared, create) {
22
+ // Both ends use `createMessagePortTransport`; see it for why.
23
+ const transport = createMessagePortTransport(port);
24
+ const connection = createMessageConnection(transport.reader, transport.writer, shared.Logger.with('ModelServer'));
25
+ const server = create(connection);
26
+ connection.listen();
27
+ return server;
28
+ }
29
+ //# sourceMappingURL=start-data-server-in-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-data-server-in-worker.js","sourceRoot":"","sources":["../../src/browser/start-data-server-in-worker.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,0BAA0B,EAA+B,MAAM,qBAAqB,CAAC;AAE9F,OAAO,EAAE,uBAAuB,EAA0B,MAAM,wBAAwB,CAAC;AAEzF;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CACpC,IAA4B,EAC5B,MAAmD,EACnD,MAAkD;IAElD,8DAA8D;IAC9D,MAAM,SAAS,GAAG,0BAA0B,CAAC,IAAI,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,uBAAuB,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IAClH,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IAClC,UAAU,CAAC,MAAM,EAAE,CAAC;IACpB,OAAO,MAAM,CAAC;AACjB,CAAC"}