@hydranium/data-server 1.0.0-next.39 → 1.0.0-next.390
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.
- package/README.md +57 -77
- package/lib/browser/index.d.ts +10 -0
- package/lib/browser/index.d.ts.map +1 -0
- package/lib/browser/index.js +15 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/start-data-server-in-worker.d.ts +23 -0
- package/lib/browser/start-data-server-in-worker.d.ts.map +1 -0
- package/lib/browser/start-data-server-in-worker.js +29 -0
- package/lib/browser/start-data-server-in-worker.js.map +1 -0
- package/lib/data-server.d.ts +391 -319
- package/lib/data-server.d.ts.map +1 -1
- package/lib/data-server.js +682 -531
- package/lib/data-server.js.map +1 -1
- package/lib/messages/index.d.ts +1 -1
- package/lib/messages/index.d.ts.map +1 -1
- package/lib/messages/index.js +1 -1
- package/lib/messages/index.js.map +1 -1
- package/lib/node/node-diagnostics-provider.d.ts.map +1 -1
- package/lib/node/node-diagnostics-provider.js +3 -2
- package/lib/node/node-diagnostics-provider.js.map +1 -1
- package/lib/testing/data-server-harness.d.ts +27 -14
- package/lib/testing/data-server-harness.d.ts.map +1 -1
- package/lib/testing/data-server-harness.js +5 -2
- package/lib/testing/data-server-harness.js.map +1 -1
- package/lib/testing/index.d.ts +1 -0
- package/lib/testing/index.d.ts.map +1 -1
- package/lib/testing/index.js.map +1 -1
- package/package.json +35 -43
- package/src/browser/index.ts +15 -0
- package/src/browser/start-data-server-in-worker.ts +35 -0
- package/src/data-server.ts +846 -581
- package/src/messages/index.ts +8 -1
- package/src/node/node-diagnostics-provider.ts +3 -9
- package/src/testing/data-server-harness.ts +44 -25
- package/src/testing/index.ts +5 -2
package/src/messages/index.ts
CHANGED
|
@@ -16,4 +16,11 @@
|
|
|
16
16
|
* code is the contract, and renaming one is a breaking change.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
export {
|
|
19
|
+
export {
|
|
20
|
+
NO_ACTIVE_PROFILE,
|
|
21
|
+
NO_ACTIVE_PROFILE_CODE,
|
|
22
|
+
noActiveProfileError,
|
|
23
|
+
REFERENCE_SETTLE_TIMEOUT,
|
|
24
|
+
REFERENCE_SETTLE_TIMEOUT_CODE,
|
|
25
|
+
referenceSettleTimeoutError
|
|
26
|
+
} from '../data-server.js';
|
|
@@ -8,14 +8,8 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import type { ServerSharedServices } from '@hydranium/core';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
formatProfileReport,
|
|
14
|
-
formatServerState,
|
|
15
|
-
ProfileCapture,
|
|
16
|
-
recordServerSummaryEntry,
|
|
17
|
-
writeHeapSnapshotToDir
|
|
18
|
-
} from '@hydranium/core/node';
|
|
11
|
+
import { formatProfileReport, formatServerState, ProfileCapture, recordServerSummaryEntry } from '@hydranium/core/node';
|
|
12
|
+
import { formatPodMemory, writeHeapSnapshotToDir } from '@hydranium/protocol/node';
|
|
19
13
|
import type { DumpServerStateArgs, StartProfilingArgs, StopProfilingArgs, WriteServerHeapSnapshotArgs } from '@hydranium/protocol';
|
|
20
14
|
import type { DataServerDiagnosticsProvider, DataServerProfileCapture } from '../diagnostics-provider.js';
|
|
21
15
|
|
|
@@ -51,7 +45,7 @@ class NodeProfileCapture implements DataServerProfileCapture {
|
|
|
51
45
|
class NodeDataServerDiagnostics implements DataServerDiagnosticsProvider {
|
|
52
46
|
async dumpServerState(services: ServerSharedServices, args: DumpServerStateArgs): Promise<string> {
|
|
53
47
|
const openDocuments = services.workspace.TextDocuments.openDocuments();
|
|
54
|
-
return formatServerState(services.workspace
|
|
48
|
+
return formatServerState(services.workspace, args.label, { openDocuments });
|
|
55
49
|
}
|
|
56
50
|
|
|
57
51
|
async writeHeapSnapshot(args: WriteServerHeapSnapshotArgs): Promise<string> {
|
|
@@ -15,11 +15,12 @@ import {
|
|
|
15
15
|
type DataServerProtocol,
|
|
16
16
|
type ProjectsChangedEvent,
|
|
17
17
|
type TransferDocumentDeletedEvent,
|
|
18
|
+
type TransferDocumentDirtyChangedEvent,
|
|
18
19
|
type TransferDocumentSavedEvent,
|
|
19
20
|
type TransferDocumentsBuiltEvent,
|
|
20
21
|
type TransferDocumentUpdatedEvent
|
|
21
22
|
} from '@hydranium/protocol/data';
|
|
22
|
-
import { type Harness, makeCapturingDataClient } from '@hydranium/protocol/testing';
|
|
23
|
+
import { type AdditionalClientMethod, type Harness, makeCapturingDataClient } from '@hydranium/protocol/testing';
|
|
23
24
|
import { makeDuplexConnectionPair, type DuplexConnectionPair } from '@hydranium/protocol/testing/node';
|
|
24
25
|
import type { MessageConnection } from 'vscode-jsonrpc/node';
|
|
25
26
|
|
|
@@ -31,16 +32,17 @@ import type { MessageConnection } from 'vscode-jsonrpc/node';
|
|
|
31
32
|
* (the "server side" of the duplex pair). The factory is invoked once,
|
|
32
33
|
* synchronously, after the pair is wired.
|
|
33
34
|
*
|
|
34
|
-
* `client` lets tests override individual handlers on the captured
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* `client` lets tests override individual handlers on the captured client.
|
|
36
|
+
* Unspecified handlers default to pushing incoming events into the
|
|
37
|
+
* {@link DataServerHarness} bundle's `events` / `saves` / `projectsChanges`
|
|
38
|
+
* arrays — the typical assertion target.
|
|
38
39
|
*/
|
|
39
40
|
export interface MakeDataServerHarnessOptions<
|
|
40
41
|
TServer,
|
|
41
42
|
TTransfer extends TransferElement,
|
|
42
43
|
TDiagnostic extends TransferDiagnostic = TransferDiagnostic,
|
|
43
|
-
TProject extends Project = Project
|
|
44
|
+
TProject extends Project = Project,
|
|
45
|
+
TClient extends DataClientProtocol<TTransfer, TDiagnostic, TProject> = DataClientProtocol<TTransfer, TDiagnostic, TProject>
|
|
44
46
|
> {
|
|
45
47
|
/**
|
|
46
48
|
* Construct the `DataServer` (or subclass) under test against
|
|
@@ -49,12 +51,19 @@ export interface MakeDataServerHarnessOptions<
|
|
|
49
51
|
*/
|
|
50
52
|
server: (channel: MessageConnection) => TServer;
|
|
51
53
|
/**
|
|
52
|
-
* Override per-method handlers on the captured
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
54
|
+
* Override per-method handlers on the captured client. An additional
|
|
55
|
+
* method's override needs the method in `additionalClientMethods`, or the
|
|
56
|
+
* harness throws. Each overridden handler REPLACES the default (which
|
|
57
|
+
* pushes into the bundle's capture arrays); test code wanting to BOTH
|
|
58
|
+
* capture AND react should push to the array manually inside the override.
|
|
56
59
|
*/
|
|
57
|
-
client?: Partial<
|
|
60
|
+
client?: Partial<TClient>;
|
|
61
|
+
/**
|
|
62
|
+
* Notification methods `TClient` adds to {@link DataClientProtocol}. Each is
|
|
63
|
+
* bound and captured into `additionalNotifications`; one left out reaches no
|
|
64
|
+
* handler.
|
|
65
|
+
*/
|
|
66
|
+
additionalClientMethods?: readonly AdditionalClientMethod<TClient>[];
|
|
58
67
|
/**
|
|
59
68
|
* Wire namespace the proxy addresses the server under. Defaults to
|
|
60
69
|
* {@link DATA_SERVER_WIRE_PREFIX}. Override when the `DataServer`
|
|
@@ -80,7 +89,8 @@ export interface DataServerHarness<
|
|
|
80
89
|
TServer,
|
|
81
90
|
TTransfer extends TransferElement,
|
|
82
91
|
TDiagnostic extends TransferDiagnostic = TransferDiagnostic,
|
|
83
|
-
TProject extends Project = Project
|
|
92
|
+
TProject extends Project = Project,
|
|
93
|
+
TClient extends DataClientProtocol<TTransfer, TDiagnostic, TProject> = DataClientProtocol<TTransfer, TDiagnostic, TProject>
|
|
84
94
|
> extends Harness {
|
|
85
95
|
readonly server: TServer;
|
|
86
96
|
readonly proxy: DataServerProtocol<TTransfer, TDiagnostic, TProject>;
|
|
@@ -89,12 +99,18 @@ export interface DataServerHarness<
|
|
|
89
99
|
readonly events: ReadonlyArray<TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>>;
|
|
90
100
|
/** Captured `onDocumentSaved` events. */
|
|
91
101
|
readonly saves: ReadonlyArray<TransferDocumentSavedEvent<TTransfer, TDiagnostic>>;
|
|
102
|
+
/** Captured `onDocumentDirtyChanged` events. */
|
|
103
|
+
readonly dirtyChanges: ReadonlyArray<TransferDocumentDirtyChangedEvent>;
|
|
92
104
|
/** Captured `onDocumentDeleted` events. */
|
|
93
105
|
readonly deletions: ReadonlyArray<TransferDocumentDeletedEvent>;
|
|
94
106
|
/** Captured `onDocumentsBuilt` events, one per build that had unwatched documents. */
|
|
95
107
|
readonly builds: ReadonlyArray<TransferDocumentsBuiltEvent>;
|
|
96
108
|
/** Captured `onProjectsChanged` events. */
|
|
97
109
|
readonly projectsChanges: ReadonlyArray<ProjectsChangedEvent<TProject>>;
|
|
110
|
+
/** Captured events of each `additionalClientMethods` entry, keyed by method. */
|
|
111
|
+
readonly additionalNotifications: {
|
|
112
|
+
readonly [K in AdditionalClientMethod<TClient>]: TClient[K] extends (event: infer TEvent) => void ? ReadonlyArray<TEvent> : never;
|
|
113
|
+
};
|
|
98
114
|
/** Dispose the underlying duplex pair. Idempotent. */
|
|
99
115
|
dispose(): void;
|
|
100
116
|
}
|
|
@@ -113,12 +129,14 @@ export function makeDataServerHarness<
|
|
|
113
129
|
TServer,
|
|
114
130
|
TTransfer extends TransferElement,
|
|
115
131
|
TDiagnostic extends TransferDiagnostic = TransferDiagnostic,
|
|
116
|
-
TProject extends Project = Project
|
|
132
|
+
TProject extends Project = Project,
|
|
133
|
+
TClient extends DataClientProtocol<TTransfer, TDiagnostic, TProject> = DataClientProtocol<TTransfer, TDiagnostic, TProject>
|
|
117
134
|
>(
|
|
118
|
-
options: MakeDataServerHarnessOptions<TServer, TTransfer, TDiagnostic, TProject>
|
|
119
|
-
): DataServerHarness<TServer, TTransfer, TDiagnostic, TProject> {
|
|
135
|
+
options: MakeDataServerHarnessOptions<TServer, TTransfer, TDiagnostic, TProject, TClient>
|
|
136
|
+
): DataServerHarness<TServer, TTransfer, TDiagnostic, TProject, TClient> {
|
|
120
137
|
const pair = makeDuplexConnectionPair();
|
|
121
138
|
const server = options.server(pair.left);
|
|
139
|
+
const additionalClientMethods = options.additionalClientMethods ?? [];
|
|
122
140
|
|
|
123
141
|
// The capture half is the shared client double, not a local copy: the same
|
|
124
142
|
// recording semantics (every channel, an override replacing rather than
|
|
@@ -129,19 +147,18 @@ export function makeDataServerHarness<
|
|
|
129
147
|
client: localClient,
|
|
130
148
|
updates: events,
|
|
131
149
|
saves,
|
|
150
|
+
dirtyChanges,
|
|
132
151
|
deletions,
|
|
133
152
|
builds,
|
|
134
|
-
projectsChanges
|
|
135
|
-
|
|
153
|
+
projectsChanges,
|
|
154
|
+
additionalNotifications
|
|
155
|
+
} = makeCapturingDataClient<TTransfer, TDiagnostic, TProject, TClient>(options.client, additionalClientMethods);
|
|
136
156
|
|
|
137
|
-
const proxy = createRpcProxy<DataServerProtocol<TTransfer, TDiagnostic, TProject>,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
localMethods: DATA_CLIENT_PROTOCOL_METHODS
|
|
143
|
-
}
|
|
144
|
-
);
|
|
157
|
+
const proxy = createRpcProxy<DataServerProtocol<TTransfer, TDiagnostic, TProject>, TClient>(pair.right, {
|
|
158
|
+
methodNamespace: options.methodNamespace ?? DATA_SERVER_WIRE_PREFIX,
|
|
159
|
+
localTarget: localClient,
|
|
160
|
+
localMethods: [...DATA_CLIENT_PROTOCOL_METHODS, ...additionalClientMethods]
|
|
161
|
+
});
|
|
145
162
|
|
|
146
163
|
return {
|
|
147
164
|
server,
|
|
@@ -149,9 +166,11 @@ export function makeDataServerHarness<
|
|
|
149
166
|
pair,
|
|
150
167
|
events,
|
|
151
168
|
saves,
|
|
169
|
+
dirtyChanges,
|
|
152
170
|
deletions,
|
|
153
171
|
builds,
|
|
154
172
|
projectsChanges,
|
|
173
|
+
additionalNotifications,
|
|
155
174
|
dispose: () => pair.dispose()
|
|
156
175
|
};
|
|
157
176
|
}
|
package/src/testing/index.ts
CHANGED
|
@@ -12,8 +12,11 @@
|
|
|
12
12
|
// real wire. The duplex `MessageConnection` pair lives in
|
|
13
13
|
// `@hydranium/protocol/testing`, which owns the transport; only its TYPE is
|
|
14
14
|
// re-exported here, because `DataServerHarness.pair` names it in a public
|
|
15
|
-
// signature
|
|
16
|
-
//
|
|
15
|
+
// signature; `AdditionalClientMethod` is re-exported for the same reason, as
|
|
16
|
+
// the harness options name it. A test that wires its own server rather than
|
|
17
|
+
// using the harness calls `makeDuplexConnectionPair` from
|
|
18
|
+
// `@hydranium/protocol/testing` directly.
|
|
17
19
|
|
|
20
|
+
export type { AdditionalClientMethod } from '@hydranium/protocol/testing';
|
|
18
21
|
export type { DuplexConnectionPair } from '@hydranium/protocol/testing/node';
|
|
19
22
|
export * from './data-server-harness.js';
|