@hydranium/protocol 1.0.0-next.60 → 1.0.0-next.61

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.
@@ -0,0 +1,76 @@
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
+ import { type DataClientProtocol, type DataServerProtocol } from '../data';
10
+ import type { TransferElement } from '../transfer-element';
11
+ import type { DataPort } from './data-port';
12
+ import { DataSession } from './data-session';
13
+ import { RpcConnection, type RpcConnectionLifecycle } from './rpc-connection';
14
+ /** Options for {@link DataConnection}. */
15
+ export interface DataConnectionOptions extends RpcConnectionLifecycle {
16
+ /**
17
+ * Wire namespace the server is addressed under. Defaults to the
18
+ * framework's {@link DATA_SERVER_WIRE_PREFIX}, which is what an unmodified
19
+ * `DataServer` binds. Override only alongside the server's own
20
+ * `methodNamespace` option — a mismatch turns every request into
21
+ * "Unhandled method" rather than failing at wire-up.
22
+ */
23
+ readonly methodNamespace?: string;
24
+ }
25
+ /** {@link DataConnectionOptions} for a client that does not speak {@link DataClientProtocol}. */
26
+ export interface DataConnectionOptionsWithMethods<TClient extends object> extends DataConnectionOptions {
27
+ /**
28
+ * Method names of the client to bind as inbound handlers. Declare it
29
+ * `as const satisfies ReadonlyArray<keyof YourClient & string>` so the list
30
+ * cannot drift from the interface.
31
+ */
32
+ readonly clientMethods: readonly (keyof TClient & string)[];
33
+ }
34
+ /**
35
+ * Trailing constructor arguments, required only when the client cannot take
36
+ * the framework's default method list.
37
+ *
38
+ * `bindRpcMethods` throws for a name the target does not implement, so a
39
+ * request/response-only client binding the default list fails at wire-up. The
40
+ * conditional turns that into a compile error.
41
+ */
42
+ export type DataConnectionArgs<TTransfer extends TransferElement, TClient extends object> = TClient extends DataClientProtocol<TTransfer> ? [options?: DataConnectionOptions & Partial<DataConnectionOptionsWithMethods<TClient>>] : [options: DataConnectionOptionsWithMethods<TClient>];
43
+ /**
44
+ * A {@link RpcConnection} to the data head, carrying as many participants as
45
+ * the host has interested parties.
46
+ *
47
+ * Document operations live on the participants rather than here: they carry a
48
+ * `clientId`, which identifies a participant rather than a wire, and the server
49
+ * keys its holds and watches per `(uri, clientId)`. Two parties sharing one
50
+ * identity cannot tell each other's writes from their own echoes.
51
+ *
52
+ * Generic over the transfer root so this file names no grammar. An adopter
53
+ * binds the concrete root (or the union of them, for a multi-grammar head) at
54
+ * its own edge.
55
+ */
56
+ export declare class DataConnection<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer> = DataServerProtocol<TTransfer>, TClient extends object = DataClientProtocol<TTransfer>> extends RpcConnection<TServer, TClient> {
57
+ protected readonly sessions: Set<DataSession<TTransfer, TServer>>;
58
+ constructor(port: DataPort, client: TClient, ...rest: DataConnectionArgs<TTransfer, TClient>);
59
+ /**
60
+ * Mint a participant on this connection under `clientId`.
61
+ *
62
+ * `clientId` must be distinct per participant and stable for its lifetime:
63
+ * it keys the server's per-`(uri, clientId)` hold and watch, and it is the
64
+ * echo key an inbound `onDocumentUpdated` is matched against. Avoid the
65
+ * three values the framework uses as sentinels — `'language-client'`,
66
+ * `'unknown'` and `'revert-on-close'`.
67
+ */
68
+ createSession(clientId: string): DataSession<TTransfer, TServer>;
69
+ /**
70
+ * Sessions are detached rather than disposed: the server releases every hold
71
+ * on a connection it sees close, so closing each document first sends
72
+ * requests over a connection this call is about to dispose.
73
+ */
74
+ dispose(): void;
75
+ }
76
+ //# sourceMappingURL=data-connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-connection.d.ts","sourceRoot":"","sources":["../../src/client/data-connection.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAyD,KAAK,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClI,OAAO,KA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AS,EAAE,OAAO,CAAC;IAY5F;;;;;;;;OAQG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC;IAUhE;;;;OAIG;IACM,OAAO,IAAI,IAAI;CAO1B"}
@@ -0,0 +1,73 @@
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
+ exports.DataConnection = void 0;
12
+ const data_1 = require("../data");
13
+ const data_session_1 = require("./data-session");
14
+ const rpc_connection_1 = require("./rpc-connection");
15
+ /**
16
+ * A {@link RpcConnection} to the data head, carrying as many participants as
17
+ * the host has interested parties.
18
+ *
19
+ * Document operations live on the participants rather than here: they carry a
20
+ * `clientId`, which identifies a participant rather than a wire, and the server
21
+ * keys its holds and watches per `(uri, clientId)`. Two parties sharing one
22
+ * identity cannot tell each other's writes from their own echoes.
23
+ *
24
+ * Generic over the transfer root so this file names no grammar. An adopter
25
+ * binds the concrete root (or the union of them, for a multi-grammar head) at
26
+ * its own edge.
27
+ */
28
+ class DataConnection extends rpc_connection_1.RpcConnection {
29
+ sessions = new Set();
30
+ constructor(port, client, ...rest) {
31
+ const [options = {}] = rest;
32
+ super(port, client, {
33
+ methodNamespace: options.methodNamespace ?? data_1.DATA_SERVER_WIRE_PREFIX,
34
+ // The default is reachable only where `TClient` satisfies
35
+ // `DataClientProtocol`, which the constructor's conditional enforces;
36
+ // the compiler cannot carry that through to the generic parameter.
37
+ clientMethods: options.clientMethods ?? data_1.DATA_CLIENT_PROTOCOL_METHODS,
38
+ lifecycle: options
39
+ });
40
+ }
41
+ /**
42
+ * Mint a participant on this connection under `clientId`.
43
+ *
44
+ * `clientId` must be distinct per participant and stable for its lifetime:
45
+ * it keys the server's per-`(uri, clientId)` hold and watch, and it is the
46
+ * echo key an inbound `onDocumentUpdated` is matched against. Avoid the
47
+ * three values the framework uses as sentinels — `'language-client'`,
48
+ * `'unknown'` and `'revert-on-close'`.
49
+ */
50
+ createSession(clientId) {
51
+ this.assertLive();
52
+ const session = new data_session_1.DataSession(clientId, {
53
+ connected: () => this.connected(),
54
+ releaseSession: released => this.sessions.delete(released)
55
+ });
56
+ this.sessions.add(session);
57
+ return session;
58
+ }
59
+ /**
60
+ * Sessions are detached rather than disposed: the server releases every hold
61
+ * on a connection it sees close, so closing each document first sends
62
+ * requests over a connection this call is about to dispose.
63
+ */
64
+ dispose() {
65
+ for (const session of [...this.sessions]) {
66
+ session.detach();
67
+ }
68
+ this.sessions.clear();
69
+ super.dispose();
70
+ }
71
+ }
72
+ exports.DataConnection = DataConnection;
73
+ //# sourceMappingURL=data-connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-connection.js","sourceRoot":"","sources":["../../src/client/data-connection.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAElF,kCAAkI;AAGlI,iDAA6C;AAC7C,qDAA8E;AAqC9E;;;;;;;;;;;;GAYG;AACH,MAAa,cAIX,SAAQ,8BAA+B;IACnB,QAAQ,GAAG,IAAI,GAAG,EAAmC,CAAC;IAEzE,YAAY,IAAc,EAAE,MAAe,EAAE,GAAG,IAA4C;QACzF,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,IAAuF,CAAC;QAC/G,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE;YACjB,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,8BAAuB;YACnE,0DAA0D;YAC1D,sEAAsE;YACtE,mEAAmE;YACnE,aAAa,EAAE,OAAO,CAAC,aAAa,IAAK,mCAA+E;YACxH,SAAS,EAAE,OAAO;SACpB,CAAC,CAAC;IACN,CAAC;IAED;;;;;;;;OAQG;IACH,aAAa,CAAC,QAAgB;QAC3B,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,MAAM,OAAO,GAAG,IAAI,0BAAW,CAAqB,QAAQ,EAAE;YAC3D,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE;YACjC,cAAc,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC;SAC5D,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACM,OAAO;QACb,KAAK,MAAM,OAAO,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,KAAK,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;CACH;AAlDD,wCAkDC"}
@@ -10,12 +10,15 @@ import type { Event, MessageConnection } from 'vscode-jsonrpc';
10
10
  import type { ResolvedMessage } from '../messages/primitives';
11
11
  /**
12
12
  * The one thing a host has to supply for the data head: a live JSON-RPC
13
- * connection to the data server, plus the identity and failure sink that go
14
- * with it.
13
+ * connection to the data server, plus the failure sink that goes with it.
15
14
  *
16
- * "Port" in the hexagonal sense — the host implements it, `DataSession`
15
+ * "Port" in the hexagonal sense — the host implements it, `DataConnection`
17
16
  * consumes it, and nothing on either side of the boundary imports the other.
18
17
  *
18
+ * Carries no identity. A `clientId` names a participant, and one transport
19
+ * serves as many as the host has; binding an identity here is what makes two
20
+ * of them share one, so it lives on `DataSession` instead.
21
+ *
19
22
  * **This deliberately does NOT wrap the protocol methods.** `createRpcProxy`
20
23
  * already takes a promise of a connection and produces the whole typed
21
24
  * `DataServerProtocol` surface, so wrapping it would re-derive the framework's
@@ -44,21 +47,6 @@ import type { ResolvedMessage } from '../messages/primitives';
44
47
  * calls on the promise but never calls `listen` itself.
45
48
  */
46
49
  export interface DataPort {
47
- /**
48
- * Stable identity of this client on the data server, passed as `clientId`
49
- * on every document request.
50
- *
51
- * It has to be stable for the session because it is the echo key: an
52
- * inbound `onDocumentUpdated` carries the originating mutation's
53
- * `clientId` as `sourceClientId`, and a client that cannot recognise its
54
- * own echo treats its own write as a concurrent third-party one. It also
55
- * has to be distinct per client, since it keys the server's per-
56
- * `(uri, clientId)` watch bucket.
57
- *
58
- * Avoid the three values the framework itself uses as sentinels —
59
- * `'language-client'`, `'unknown'` and `'revert-on-close'`.
60
- */
61
- readonly clientId: string;
62
50
  /**
63
51
  * Open the transport and hand back a listening `MessageConnection`.
64
52
  *
@@ -1 +1 @@
1
- {"version":3,"file":"data-port.d.ts","sourceRoot":"","sources":["../../src/client/data-port.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,WAAW,QAAQ;IACtB;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;;;;;OAOG;IACH,OAAO,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAEtC;;;;;;;;;;;;;;OAcG;IACH,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAE7D;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;CAClC"}
1
+ {"version":3,"file":"data-port.d.ts","sourceRoot":"","sources":["../../src/client/data-port.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,WAAW,QAAQ;IACtB;;;;;;;OAOG;IACH,OAAO,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAEtC;;;;;;;;;;;;;;OAcG;IACH,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAE7D;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;CAClC"}
@@ -6,89 +6,52 @@
6
6
  *
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
- import type { MessageConnection } from 'vscode-jsonrpc';
10
- import { type DataClientProtocol, type DataServerProtocol } from '../data';
11
- import { type RpcProxy } from '../rpc';
9
+ import type { DataServerProtocol, TransferSaveDocumentArgs, TransferUpdateDocumentArgs } from '../data';
10
+ import type { RpcProxy } from '../rpc';
12
11
  import type { TransferDocument } from '../transfer-document';
13
12
  import type { TransferElement } from '../transfer-element';
14
- import type { DataPort } from './data-port';
13
+ /** Update a document through a session; the session supplies `clientId`. */
14
+ export type DataSessionUpdateArgs<TTransfer> = Omit<TransferUpdateDocumentArgs<TTransfer>, 'clientId'>;
15
+ /** Persist a document through a session; the session supplies `clientId`. */
16
+ export type DataSessionSaveArgs<TTransfer> = Omit<TransferSaveDocumentArgs<TTransfer>, 'clientId'>;
15
17
  /**
16
- * The transport never opened. A complete sentence rather than a fragment: a
17
- * fragment is nested inside a sentence the framework does not own, so no
18
- * translator controls the whole and the composition cannot be made to read
19
- * correctly in every language.
18
+ * What a {@link DataSession} needs from the connection that minted it.
19
+ *
20
+ * Narrower than the connection itself so the dependency points one way:
21
+ * `DataConnection` constructs sessions, and nothing here imports it back.
20
22
  */
21
- export declare const DATA_SERVER_CONNECT_FAILED: import("../messages/primitives").MessageDefinition<"Could not connect to the data server: {detail}">;
22
- export declare const DATA_SERVER_NOT_READY: import("../messages/primitives").MessageDefinition<"The data server did not become ready: {detail}">;
23
- /** Options for {@link DataSession}. */
24
- export interface DataSessionOptions {
25
- /**
26
- * Wire namespace the server is addressed under. Defaults to the
27
- * framework's {@link DATA_SERVER_WIRE_PREFIX}, which is what an unmodified
28
- * `DataServer` binds. Override only alongside the server's own
29
- * `methodNamespace` option — a mismatch turns every request into
30
- * "Unhandled method" rather than failing at wire-up.
31
- */
32
- readonly methodNamespace?: string;
33
- }
34
- /** One connection generation: its connection, its proxy, and its readiness. */
35
- interface Generation<TTransfer extends TransferElement> {
36
- readonly connection: Promise<MessageConnection>;
37
- readonly server: RpcProxy<DataServerProtocol<TTransfer>>;
38
- /** Set on first use; the shared readiness gate for this generation. */
39
- ready?: Promise<void>;
23
+ export interface DataSessionHost<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer>> {
24
+ connected(): Promise<RpcProxy<TServer>>;
25
+ releaseSession(session: DataSession<TTransfer, TServer>): void;
40
26
  }
41
27
  /**
42
- * The host-invariant half of talking to the data head: everything above
43
- * {@link DataPort} that would otherwise be re-derived by every host
44
- * adapter.
45
- *
46
- * Three jobs, and deliberately no fourth:
28
+ * One participant on a data connection: a properties panel, a tree, a
29
+ * form editor.
47
30
  *
48
- * 1. **Build the typed proxy** over the port's connection, with the framework's
49
- * wire prefix and its drift-proof client-method allowlist.
50
- * 2. **Own the readiness gate** — `waitForReady` once per connection, shared
51
- * across concurrent callers. A socket client can connect before the
52
- * workspace walk finishes, and an early request is then answered correctly
53
- * from an empty registry, which reads as a broken project tier rather than
54
- * as a race.
55
- * 3. **Own the reconnect policy**, by dropping its connection generation when
56
- * the port disposes and building a fresh one on the next request.
31
+ * The server keys every hold and watch per `(uri, clientId)`, so the identity
32
+ * belongs to the participant rather than to the wire — several sessions share
33
+ * one connection, and two participants forced to share one identity cannot
34
+ * distinguish each other's writes from their own echoes.
57
35
  *
58
- * It does **not** wrap the protocol methods; callers reach them through
59
- * {@link connected}. The one exception is {@link openDocument}, which exists
60
- * because the open/watch *order* is silently wrong the other way round — see
61
- * its own doc.
36
+ * Every document operation stamps {@link clientId} itself. A caller that
37
+ * passed its own could pass another participant's, and the server would
38
+ * attribute the write and release the hold accordingly.
62
39
  *
63
- * Generic over the transfer root so this file names no grammar. An adopter
64
- * binds the concrete root (or the union of them, for a multi-grammar head) at
65
- * its own edge.
40
+ * Generic over the transfer root so this file names no grammar.
66
41
  */
67
- export declare class DataSession<TTransfer extends TransferElement> {
68
- protected readonly port: DataPort;
69
- protected readonly client: DataClientProtocol<TTransfer>;
70
- protected readonly methodNamespace: string;
71
- /** The current generation, or `undefined` before the first request / after a teardown. */
72
- protected generation?: Generation<TTransfer>;
42
+ export declare class DataSession<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer> = DataServerProtocol<TTransfer>> {
43
+ readonly clientId: string;
44
+ protected readonly host: DataSessionHost<TTransfer, TServer>;
45
+ /** URIs this session holds open, so {@link dispose} can release exactly those. */
46
+ protected readonly openUris: Set<string>;
73
47
  protected disposed: boolean;
74
- protected readonly portDisposeListener: {
75
- dispose(): void;
76
- };
77
- constructor(port: DataPort, client: DataClientProtocol<TTransfer>, options?: DataSessionOptions);
78
- /** The identity every request is made under — the port's, not a second one. */
79
- get clientId(): string;
48
+ constructor(clientId: string, host: DataSessionHost<TTransfer, TServer>);
80
49
  /**
81
- * The connected, READY server proxy.
82
- *
83
- * Returns the proxy rather than `void` on purpose. A reconnect replaces the
84
- * proxy, so a caller that cached one from an earlier call would go on
85
- * addressing a dead connection with no error — handing it back per call
86
- * makes the stale reference unrepresentable.
87
- *
88
- * Concurrent callers share one readiness promise, so `waitForReady` is
89
- * awaited once per generation and not once per caller.
50
+ * The connected, READY server proxy, for protocol methods this session does
51
+ * not wrap — the ones carrying no `clientId`, so no identity can be got
52
+ * wrong through them.
90
53
  */
91
- connected(): Promise<RpcProxy<DataServerProtocol<TTransfer>>>;
54
+ connected(): Promise<RpcProxy<TServer>>;
92
55
  /**
93
56
  * Open `uri` for editing and start watching it, in that order, returning
94
57
  * the opened snapshot.
@@ -113,25 +76,36 @@ export declare class DataSession<TTransfer extends TransferElement> {
113
76
  * {@link openDocument} and needs no separate unwatch.
114
77
  */
115
78
  closeDocument(uri: string): Promise<void>;
79
+ /** Write `args.model` back as this session. */
80
+ updateDocument(args: DataSessionUpdateArgs<TTransfer>): Promise<TransferDocument<TTransfer>>;
81
+ /** Persist `args.model` to disk as this session. */
82
+ saveDocument(args: DataSessionSaveArgs<TTransfer>): Promise<TransferDocument<TTransfer>>;
116
83
  /**
117
- * Whether `event.sourceClientId` identifies this session's own write.
84
+ * Whether `sourceClientId` identifies this session's own write.
118
85
  *
119
86
  * Every watcher needs this and the check is one comparison, so getting it
120
87
  * wrong is cheap to do and expensive to find: an unfiltered echo looks
121
88
  * exactly like a concurrent third-party edit.
122
89
  */
123
90
  isOwnEcho(sourceClientId: string): boolean;
124
- /** Tear down the current connection and stop tracking the port. Idempotent. */
91
+ /**
92
+ * Release this session's holds and detach it from the connection.
93
+ * Idempotent, and leaves the connection usable by its other sessions.
94
+ *
95
+ * The closes are fired without being awaited, because a `Disposable` cannot
96
+ * be: a host disposing a widget has nowhere to put the promise. A close
97
+ * that fails is no worse than the leak this exists to prevent, so the
98
+ * rejection is swallowed rather than surfaced from a teardown.
99
+ */
125
100
  dispose(): void;
126
- /** The live generation, building one if there is none. */
127
- protected currentGeneration(): Generation<TTransfer>;
128
- /** Await the connection and the server's startup gate for one generation. */
129
- protected awaitReady(generation: Generation<TTransfer>): Promise<void>;
130
101
  /**
131
- * Discard the current generation, disposing its connection if it opened.
132
- * The next {@link connected} builds a fresh one.
102
+ * Come off the connection because it is going away.
103
+ *
104
+ * Sends no close, unlike {@link dispose}: the server releases every hold on
105
+ * a connection it sees close, and the close would travel over the very
106
+ * connection being disposed.
133
107
  */
134
- protected dropGeneration(): void;
108
+ detach(): void;
109
+ protected assertLive(): void;
135
110
  }
136
- export {};
137
111
  //# sourceMappingURL=data-session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data-session.d.ts","sourceRoot":"","sources":["../../src/client/data-session.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAyD,KAAK,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElI,OAAO,EAAE,KAAK,QAAQ,EAAkB,MAAM,QAAQ,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,sGAGtC,CAAC;AAEF,eAAO,MAAM,qBAAqB,sGAGjC,CAAC;AAEF,uCAAuC;AACvC,MAAM,WAAW,kBAAkB;IAChC;;;;;;OAMG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,+EAA+E;AAC/E,UAAU,UAAU,CAAC,SAAS,SAAS,eAAe;IACnD,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAChD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAC;IACzD,uEAAuE;IACvE,KAAK,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,WAAW,CAAC,SAAS,SAAS,eAAe;IAQpD,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ;IACjC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC,SAAS,CAA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;;;;OAiBG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAQrE;;;OAGG;IACG,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM/C,+CAA+C;IACzC,cAAc,CAAC,IAAI,EAAE,qBAAqB,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAKlG,oDAAoD;IAC9C,YAAY,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAK9F;;;;;;OAMG;IACH,SAAS,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO;IAI1C;;;;;;;;OAQG;IACH,OAAO,IAAI,IAAI;IAgBf;;;;;;OAMG;IACH,MAAM,IAAI,IAAI;IAKd,SAAS,CAAC,UAAU,IAAI,IAAI;CAK9B"}
@@ -8,83 +8,43 @@
8
8
  * SPDX-License-Identifier: MIT
9
9
  ********************************************************************************/
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.DataSession = exports.DATA_SERVER_NOT_READY = exports.DATA_SERVER_CONNECT_FAILED = void 0;
12
- const data_1 = require("../data");
13
- const primitives_1 = require("../messages/primitives");
14
- const rpc_1 = require("../rpc");
11
+ exports.DataSession = void 0;
15
12
  /**
16
- * The transport never opened. A complete sentence rather than a fragment: a
17
- * fragment is nested inside a sentence the framework does not own, so no
18
- * translator controls the whole and the composition cannot be made to read
19
- * correctly in every language.
20
- */
21
- exports.DATA_SERVER_CONNECT_FAILED = (0, primitives_1.defineMessage)('hydranium/protocol/data-server-connect-failed', 'Could not connect to the data server: {detail}');
22
- exports.DATA_SERVER_NOT_READY = (0, primitives_1.defineMessage)('hydranium/protocol/data-server-not-ready', 'The data server did not become ready: {detail}');
23
- /**
24
- * The host-invariant half of talking to the data head: everything above
25
- * {@link DataPort} that would otherwise be re-derived by every host
26
- * adapter.
13
+ * One participant on a data connection: a properties panel, a tree, a
14
+ * form editor.
27
15
  *
28
- * Three jobs, and deliberately no fourth:
16
+ * The server keys every hold and watch per `(uri, clientId)`, so the identity
17
+ * belongs to the participant rather than to the wire — several sessions share
18
+ * one connection, and two participants forced to share one identity cannot
19
+ * distinguish each other's writes from their own echoes.
29
20
  *
30
- * 1. **Build the typed proxy** over the port's connection, with the framework's
31
- * wire prefix and its drift-proof client-method allowlist.
32
- * 2. **Own the readiness gate** — `waitForReady` once per connection, shared
33
- * across concurrent callers. A socket client can connect before the
34
- * workspace walk finishes, and an early request is then answered correctly
35
- * from an empty registry, which reads as a broken project tier rather than
36
- * as a race.
37
- * 3. **Own the reconnect policy**, by dropping its connection generation when
38
- * the port disposes and building a fresh one on the next request.
21
+ * Every document operation stamps {@link clientId} itself. A caller that
22
+ * passed its own could pass another participant's, and the server would
23
+ * attribute the write and release the hold accordingly.
39
24
  *
40
- * It does **not** wrap the protocol methods; callers reach them through
41
- * {@link connected}. The one exception is {@link openDocument}, which exists
42
- * because the open/watch *order* is silently wrong the other way round — see
43
- * its own doc.
44
- *
45
- * Generic over the transfer root so this file names no grammar. An adopter
46
- * binds the concrete root (or the union of them, for a multi-grammar head) at
47
- * its own edge.
25
+ * Generic over the transfer root so this file names no grammar.
48
26
  */
49
27
  class DataSession {
50
- port;
51
- client;
52
- methodNamespace;
53
- /** The current generation, or `undefined` before the first request / after a teardown. */
54
- generation;
28
+ clientId;
29
+ host;
30
+ /** URIs this session holds open, so {@link dispose} can release exactly those. */
31
+ openUris = new Set();
55
32
  disposed = false;
56
- portDisposeListener;
57
- constructor(port, client, options = {}) {
58
- this.port = port;
59
- this.client = client;
60
- this.methodNamespace = options.methodNamespace ?? data_1.DATA_SERVER_WIRE_PREFIX;
61
- this.portDisposeListener = this.port.onDispose(() => this.dropGeneration());
62
- }
63
- /** The identity every request is made under — the port's, not a second one. */
64
- get clientId() {
65
- return this.port.clientId;
33
+ constructor(clientId, host) {
34
+ this.clientId = clientId;
35
+ this.host = host;
66
36
  }
67
37
  /**
68
- * The connected, READY server proxy.
69
- *
70
- * Returns the proxy rather than `void` on purpose. A reconnect replaces the
71
- * proxy, so a caller that cached one from an earlier call would go on
72
- * addressing a dead connection with no error — handing it back per call
73
- * makes the stale reference unrepresentable.
74
- *
75
- * Concurrent callers share one readiness promise, so `waitForReady` is
76
- * awaited once per generation and not once per caller.
38
+ * The connected, READY server proxy, for protocol methods this session does
39
+ * not wrap — the ones carrying no `clientId`, so no identity can be got
40
+ * wrong through them.
77
41
  */
78
42
  async connected() {
79
- if (this.disposed) {
80
- throw new Error('DataSession is disposed');
81
- }
82
- const generation = this.currentGeneration();
83
- if (!generation.ready) {
84
- generation.ready = this.awaitReady(generation);
85
- }
86
- await generation.ready;
87
- return generation.server;
43
+ // `async` so a disposed session REJECTS rather than throwing
44
+ // synchronously: the connection's own `connected` rejects, and a caller
45
+ // reaching for `.catch` on one of them would not catch the other.
46
+ this.assertLive();
47
+ return this.host.connected();
88
48
  }
89
49
  /**
90
50
  * Open `uri` for editing and start watching it, in that order, returning
@@ -108,6 +68,7 @@ class DataSession {
108
68
  const server = await this.connected();
109
69
  const document = await server.openModelDocument({ uri, clientId: this.clientId });
110
70
  await server.watchModelDocument({ uri, clientId: this.clientId });
71
+ this.openUris.add(uri);
111
72
  return document;
112
73
  }
113
74
  /**
@@ -116,10 +77,21 @@ class DataSession {
116
77
  */
117
78
  async closeDocument(uri) {
118
79
  const server = await this.connected();
80
+ this.openUris.delete(uri);
119
81
  await server.closeModelDocument({ uri, clientId: this.clientId });
120
82
  }
83
+ /** Write `args.model` back as this session. */
84
+ async updateDocument(args) {
85
+ const server = await this.connected();
86
+ return server.updateModelDocument({ ...args, clientId: this.clientId });
87
+ }
88
+ /** Persist `args.model` to disk as this session. */
89
+ async saveDocument(args) {
90
+ const server = await this.connected();
91
+ return server.saveModelDocument({ ...args, clientId: this.clientId });
92
+ }
121
93
  /**
122
- * Whether `event.sourceClientId` identifies this session's own write.
94
+ * Whether `sourceClientId` identifies this session's own write.
123
95
  *
124
96
  * Every watcher needs this and the check is one comparison, so getting it
125
97
  * wrong is cheap to do and expensive to find: an unfiltered echo looks
@@ -128,60 +100,45 @@ class DataSession {
128
100
  isOwnEcho(sourceClientId) {
129
101
  return sourceClientId === this.clientId;
130
102
  }
131
- /** Tear down the current connection and stop tracking the port. Idempotent. */
103
+ /**
104
+ * Release this session's holds and detach it from the connection.
105
+ * Idempotent, and leaves the connection usable by its other sessions.
106
+ *
107
+ * The closes are fired without being awaited, because a `Disposable` cannot
108
+ * be: a host disposing a widget has nowhere to put the promise. A close
109
+ * that fails is no worse than the leak this exists to prevent, so the
110
+ * rejection is swallowed rather than surfaced from a teardown.
111
+ */
132
112
  dispose() {
133
113
  if (this.disposed) {
134
114
  return;
135
115
  }
136
116
  this.disposed = true;
137
- this.portDisposeListener.dispose();
138
- this.dropGeneration();
139
- }
140
- /** The live generation, building one if there is none. */
141
- currentGeneration() {
142
- if (this.generation) {
143
- return this.generation;
144
- }
145
- const connection = this.port.connect();
146
- // Rejection is reported here rather than left to float: an unhandled
147
- // rejection on a connection promise is the failure mode that reads as
148
- // "the model is empty" instead of "the transport never opened".
149
- connection.catch((error) => this.port.reportError(error, (0, primitives_1.resolve)(exports.DATA_SERVER_CONNECT_FAILED, { detail: (0, primitives_1.describeError)(error) })));
150
- const server = (0, rpc_1.createRpcProxy)(connection, {
151
- methodNamespace: this.methodNamespace,
152
- localTarget: this.client,
153
- localMethods: data_1.DATA_CLIENT_PROTOCOL_METHODS
154
- });
155
- this.generation = { connection, server };
156
- return this.generation;
157
- }
158
- /** Await the connection and the server's startup gate for one generation. */
159
- async awaitReady(generation) {
160
- try {
161
- await generation.connection;
162
- await generation.server.waitForReady();
163
- }
164
- catch (error) {
165
- // Drop the generation so the next request retries rather than
166
- // re-awaiting a settled rejection forever.
167
- if (this.generation === generation) {
168
- this.generation = undefined;
169
- }
170
- this.port.reportError(error, (0, primitives_1.resolve)(exports.DATA_SERVER_NOT_READY, { detail: (0, primitives_1.describeError)(error) }));
171
- throw error;
117
+ const uris = [...this.openUris];
118
+ this.openUris.clear();
119
+ this.host.releaseSession(this);
120
+ for (const uri of uris) {
121
+ void this.host
122
+ .connected()
123
+ .then(server => server.closeModelDocument({ uri, clientId: this.clientId }))
124
+ .catch(() => undefined);
172
125
  }
173
126
  }
174
127
  /**
175
- * Discard the current generation, disposing its connection if it opened.
176
- * The next {@link connected} builds a fresh one.
128
+ * Come off the connection because it is going away.
129
+ *
130
+ * Sends no close, unlike {@link dispose}: the server releases every hold on
131
+ * a connection it sees close, and the close would travel over the very
132
+ * connection being disposed.
177
133
  */
178
- dropGeneration() {
179
- const generation = this.generation;
180
- this.generation = undefined;
181
- if (!generation) {
182
- return;
134
+ detach() {
135
+ this.disposed = true;
136
+ this.openUris.clear();
137
+ }
138
+ assertLive() {
139
+ if (this.disposed) {
140
+ throw new Error('DataSession is disposed');
183
141
  }
184
- generation.connection.then(connection => connection.dispose()).catch(() => undefined);
185
142
  }
186
143
  }
187
144
  exports.DataSession = DataSession;