typescript 7.1.0-dev.20261028.1 → 7.1.0-dev.20261030.1
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/dist/api/async/api.d.ts +10 -2
- package/dist/api/async/api.d.ts.map +1 -1
- package/dist/api/async/api.js +19 -2
- package/dist/api/async/api.js.map +1 -1
- package/dist/api/async/client.d.ts +9 -3
- package/dist/api/async/client.d.ts.map +1 -1
- package/dist/api/async/client.js +45 -26
- package/dist/api/async/client.js.map +1 -1
- package/dist/api/async/jsonrpc.d.ts +14 -0
- package/dist/api/async/jsonrpc.d.ts.map +1 -0
- package/dist/api/async/jsonrpc.js +93 -0
- package/dist/api/async/jsonrpc.js.map +1 -0
- package/dist/api/async/transport.d.ts +23 -0
- package/dist/api/async/transport.d.ts.map +1 -0
- package/dist/api/async/transport.js +2 -0
- package/dist/api/async/transport.js.map +1 -0
- package/dist/api/async/transportClient.d.ts +37 -0
- package/dist/api/async/transportClient.d.ts.map +1 -0
- package/dist/api/async/transportClient.js +256 -0
- package/dist/api/async/transportClient.js.map +1 -0
- package/dist/api/fs.d.ts +11 -18
- package/dist/api/fs.d.ts.map +1 -1
- package/dist/api/fs.js +22 -17
- package/dist/api/fs.js.map +1 -1
- package/dist/api/fsCallbacks.d.ts +18 -1
- package/dist/api/fsCallbacks.d.ts.map +1 -1
- package/dist/api/fsCallbacks.js +12 -1
- package/dist/api/fsCallbacks.js.map +1 -1
- package/dist/api/node/encoder.d.ts +1 -1
- package/dist/api/node/encoder.d.ts.map +1 -1
- package/dist/api/node/encoder.js +21 -7
- package/dist/api/node/encoder.js.map +1 -1
- package/dist/api/node/wtf8.d.ts.map +1 -1
- package/dist/api/node/wtf8.js +11 -4
- package/dist/api/node/wtf8.js.map +1 -1
- package/dist/api/nodeProcess.d.ts +8 -0
- package/dist/api/nodeProcess.d.ts.map +1 -0
- package/dist/api/nodeProcess.js +23 -0
- package/dist/api/nodeProcess.js.map +1 -0
- package/dist/api/options.d.ts +34 -2
- package/dist/api/options.d.ts.map +1 -1
- package/dist/api/options.js +9 -7
- package/dist/api/options.js.map +1 -1
- package/dist/api/proto.generated.d.ts +8 -2
- package/dist/api/proto.generated.d.ts.map +1 -1
- package/dist/api/sync/api.d.ts +7 -1
- package/dist/api/sync/api.d.ts.map +1 -1
- package/dist/api/sync/api.js +13 -0
- package/dist/api/sync/api.js.map +1 -1
- package/dist/api/sync/client.d.ts +9 -32
- package/dist/api/sync/client.d.ts.map +1 -1
- package/dist/api/sync/client.js +18 -112
- package/dist/api/sync/client.js.map +1 -1
- package/dist/api/sync/transport.d.ts +21 -0
- package/dist/api/sync/transport.d.ts.map +1 -0
- package/dist/api/sync/transport.js +2 -0
- package/dist/api/sync/transport.js.map +1 -0
- package/dist/api/sync/transportClient.d.ts +23 -0
- package/dist/api/sync/transportClient.d.ts.map +1 -0
- package/dist/api/sync/transportClient.js +104 -0
- package/dist/api/sync/transportClient.js.map +1 -0
- package/dist/api/syncChannel.d.ts +2 -0
- package/dist/api/syncChannel.d.ts.map +1 -1
- package/dist/api/syncChannel.js +48 -35
- package/dist/api/syncChannel.js.map +1 -1
- package/dist/api/timingDump.d.ts.map +1 -1
- package/dist/api/timingDump.js +7 -5
- package/dist/api/timingDump.js.map +1 -1
- package/dist/wasm/index.d.ts +9 -0
- package/dist/wasm/index.d.ts.map +1 -0
- package/dist/wasm/index.js +9 -0
- package/dist/wasm/index.js.map +1 -0
- package/dist/wasm/transport.d.ts +112 -0
- package/dist/wasm/transport.d.ts.map +1 -0
- package/dist/wasm/transport.js +333 -0
- package/dist/wasm/transport.js.map +1 -0
- package/dist/wasm/wasi.d.ts +35 -0
- package/dist/wasm/wasi.d.ts.map +1 -0
- package/dist/wasm/wasi.js +227 -0
- package/dist/wasm/wasi.js.map +1 -0
- package/lib/getExePath.d.ts +7 -1
- package/lib/getExePath.js +7 -7
- package/lib/tsc.js +5 -1
- package/package.json +12 -9
|
@@ -1,36 +1,13 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export type {
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
private
|
|
8
|
-
private
|
|
9
|
-
private timingDump;
|
|
1
|
+
import { type ClientSocketOptions, type ClientSpawnOptions, type SyncClientOptions } from "../options.ts";
|
|
2
|
+
import { TransportClient } from "./transportClient.ts";
|
|
3
|
+
export type { ClientSocketOptions, ClientSpawnOptions };
|
|
4
|
+
export type { ClientTransportOptions, SyncClientOptions as ClientOptions } from "../options.ts";
|
|
5
|
+
export type { SyncTransport } from "./transport.ts";
|
|
6
|
+
export declare class Client extends TransportClient {
|
|
7
|
+
private readonly channel;
|
|
8
|
+
private readonly timingDump;
|
|
10
9
|
private closed;
|
|
11
|
-
|
|
12
|
-
constructor(options: ClientOptions);
|
|
13
|
-
apiRequest<K extends keyof APIMethodInfo>(method: K, params?: APIMethodInfo[K]["params"]): APIMethodInfo[K]["result"];
|
|
14
|
-
registerCallback(name: string, callback: (params: unknown) => unknown): () => void;
|
|
15
|
-
batchRequests(requests: readonly APIRequest[]): BatchRequestsResponse;
|
|
16
|
-
apiRequestBinary<K extends SourceFileResponseMethod>(method: K, params?: APIMethodInfo[K]["params"]): Uint8Array | undefined;
|
|
17
|
-
echo(payload: string): string;
|
|
18
|
-
echoBinary(payload: Uint8Array): Uint8Array;
|
|
19
|
-
/**
|
|
20
|
-
* Returns a combined timing snapshot: client-measured round-trip and byte
|
|
21
|
-
* counts folded together with the server's own per-request processing time
|
|
22
|
-
* (fetched via a getServerTiming request) and estimated transport overhead.
|
|
23
|
-
*/
|
|
24
|
-
getTimingInfo(): TimingInfo;
|
|
25
|
-
resetTimingInfo(): void;
|
|
26
|
-
/**
|
|
27
|
-
* Returns the timing collector that per-node materialization is reported
|
|
28
|
-
* into, or undefined when timing collection is disabled. The returned
|
|
29
|
-
* collector is the same one folded into {@link getTimingInfo}, so
|
|
30
|
-
* materialization totals surface alongside request timings.
|
|
31
|
-
*/
|
|
32
|
-
getTimingCollector(): TimingCollector | undefined;
|
|
33
|
-
private recordTiming;
|
|
10
|
+
constructor(options: SyncClientOptions);
|
|
34
11
|
close(): void;
|
|
35
12
|
}
|
|
36
13
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/sync/client.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,KAAK,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/sync/client.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAKvB,KAAK,iBAAiB,EACzB,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;AACxD,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AAChG,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,qBAAa,MAAO,SAAQ,eAAe;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IACpD,OAAO,CAAC,MAAM,CAAS;IAEvB,YAAY,OAAO,EAAE,iBAAiB,EA+CrC;IAEQ,KAAK,IAAI,IAAI,CAqBrB;CACJ"}
|
package/dist/api/sync/client.js
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
import { configureFileSystemCallbacks, encodeFileSystemCallbackResult, } from "../fsCallbacks.js";
|
|
2
|
-
import { getAPIProcessArgs, isSpawnOptions, resolveExePath, } from "../options.js";
|
|
2
|
+
import { getAPIProcessArgs, isSpawnOptions, isTransportOptions, resolveExePath, } from "../options.js";
|
|
3
3
|
import { SyncRpcChannel } from "../syncChannel.js";
|
|
4
|
-
import { combineTimingInfo, disabledTimingInfo, TimingCollector, } from "../timing.js";
|
|
5
4
|
import { TimingDump } from "../timingDump.js";
|
|
6
|
-
|
|
5
|
+
import { TransportClient } from "./transportClient.js";
|
|
6
|
+
export class Client extends TransportClient {
|
|
7
7
|
channel;
|
|
8
|
-
encoder = new TextEncoder();
|
|
9
|
-
timing;
|
|
10
8
|
timingDump;
|
|
11
9
|
closed = false;
|
|
12
|
-
maxResponseBytesPerPage;
|
|
13
10
|
constructor(options) {
|
|
11
|
+
if (isTransportOptions(options)) {
|
|
12
|
+
if (options.fs !== undefined) {
|
|
13
|
+
options.transport.setFileSystem?.(options.fs);
|
|
14
|
+
}
|
|
15
|
+
super(options.transport, options.collectTiming ?? false, options.maxResponseBytesPerPage);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
14
18
|
if (!isSpawnOptions(options)) {
|
|
15
19
|
throw new Error("Socket connections are not yet supported in the sync client");
|
|
16
20
|
}
|
|
17
|
-
|
|
18
|
-
if (
|
|
21
|
+
const timingDump = TimingDump.fromEnvironment("sync", "spawn");
|
|
22
|
+
if (timingDump) {
|
|
19
23
|
options = { ...options, collectTiming: true };
|
|
20
24
|
}
|
|
21
25
|
const args = getAPIProcessArgs(options, false);
|
|
22
|
-
this.maxResponseBytesPerPage = options.maxResponseBytesPerPage;
|
|
23
26
|
const fsConfiguration = configureFileSystemCallbacks(options.fs);
|
|
24
27
|
if (fsConfiguration.arguments.length > 0) {
|
|
25
28
|
args.push(`--callbacks=${fsConfiguration.arguments.join(",")}`);
|
|
26
29
|
}
|
|
27
30
|
const collectTiming = options.collectTiming ?? false;
|
|
28
|
-
if (collectTiming) {
|
|
29
|
-
this.timing = new TimingCollector();
|
|
30
|
-
}
|
|
31
31
|
const channel = new SyncRpcChannel(resolveExePath(options), args, collectTiming);
|
|
32
|
+
super(channel, collectTiming, options.maxResponseBytesPerPage);
|
|
32
33
|
this.channel = channel;
|
|
34
|
+
this.timingDump = timingDump;
|
|
33
35
|
if (options.fs) {
|
|
34
36
|
for (const name of fsConfiguration.callbackNames) {
|
|
35
37
|
if (name === "writeFile") {
|
|
@@ -51,110 +53,14 @@ export class Client {
|
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
|
-
apiRequest(method, params) {
|
|
55
|
-
const encodedPayload = JSON.stringify(params);
|
|
56
|
-
const start = performance.now();
|
|
57
|
-
const result = this.channel.requestSync(method, encodedPayload);
|
|
58
|
-
this.recordTiming(method, start);
|
|
59
|
-
if (result.length) {
|
|
60
|
-
return JSON.parse(result);
|
|
61
|
-
}
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
registerCallback(name, callback) {
|
|
65
|
-
this.channel.registerCallback(name, (_, payload) => JSON.stringify(callback(JSON.parse(payload))) ?? "");
|
|
66
|
-
return () => this.channel.unregisterCallback(name);
|
|
67
|
-
}
|
|
68
|
-
batchRequests(requests) {
|
|
69
|
-
const params = { requests };
|
|
70
|
-
if (this.maxResponseBytesPerPage !== undefined) {
|
|
71
|
-
params.maxResponseBytesPerPage = this.maxResponseBytesPerPage;
|
|
72
|
-
}
|
|
73
|
-
const response = this.apiRequest("batchRequests", params);
|
|
74
|
-
let responses = response.responses;
|
|
75
|
-
let continuationToken = response.continuationToken;
|
|
76
|
-
while (continuationToken) {
|
|
77
|
-
const pageParams = {
|
|
78
|
-
requests: [],
|
|
79
|
-
continuationToken,
|
|
80
|
-
};
|
|
81
|
-
if (this.maxResponseBytesPerPage !== undefined) {
|
|
82
|
-
pageParams.maxResponseBytesPerPage = this.maxResponseBytesPerPage;
|
|
83
|
-
}
|
|
84
|
-
const page = this.apiRequest("batchRequests", pageParams);
|
|
85
|
-
if (page.responses.length < 200) {
|
|
86
|
-
responses.push(...page.responses);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
// If the number of responses is approaching the max argument length, we need to concat instead of push
|
|
90
|
-
responses = responses.concat(page.responses);
|
|
91
|
-
}
|
|
92
|
-
continuationToken = page.continuationToken;
|
|
93
|
-
}
|
|
94
|
-
return { responses };
|
|
95
|
-
}
|
|
96
|
-
apiRequestBinary(method, params) {
|
|
97
|
-
const start = performance.now();
|
|
98
|
-
const result = this.channel.requestBinarySync(method, this.encoder.encode(JSON.stringify(params)));
|
|
99
|
-
this.recordTiming(method, start);
|
|
100
|
-
if (result.length === 0)
|
|
101
|
-
return undefined;
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
echo(payload) {
|
|
105
|
-
return this.channel.requestSync("echo", payload);
|
|
106
|
-
}
|
|
107
|
-
echoBinary(payload) {
|
|
108
|
-
return this.channel.requestBinarySync("echo", payload);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Returns a combined timing snapshot: client-measured round-trip and byte
|
|
112
|
-
* counts folded together with the server's own per-request processing time
|
|
113
|
-
* (fetched via a getServerTiming request) and estimated transport overhead.
|
|
114
|
-
*/
|
|
115
|
-
getTimingInfo() {
|
|
116
|
-
if (!this.timing) {
|
|
117
|
-
return disabledTimingInfo();
|
|
118
|
-
}
|
|
119
|
-
const local = this.timing.getInfo();
|
|
120
|
-
// requestSync bypasses recordTiming, so this query does not pollute the
|
|
121
|
-
// client-side collector.
|
|
122
|
-
const result = this.channel.requestSync("getServerTiming", "");
|
|
123
|
-
return combineTimingInfo(local, JSON.parse(result));
|
|
124
|
-
}
|
|
125
|
-
resetTimingInfo() {
|
|
126
|
-
if (!this.timing)
|
|
127
|
-
return;
|
|
128
|
-
this.timing.reset();
|
|
129
|
-
// Keep the server's collection in sync so combined totals stay meaningful.
|
|
130
|
-
this.channel.requestSync("resetServerTiming", "");
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Returns the timing collector that per-node materialization is reported
|
|
134
|
-
* into, or undefined when timing collection is disabled. The returned
|
|
135
|
-
* collector is the same one folded into {@link getTimingInfo}, so
|
|
136
|
-
* materialization totals surface alongside request timings.
|
|
137
|
-
*/
|
|
138
|
-
getTimingCollector() {
|
|
139
|
-
return this.timing;
|
|
140
|
-
}
|
|
141
|
-
recordTiming(method, start) {
|
|
142
|
-
if (!this.timing)
|
|
143
|
-
return;
|
|
144
|
-
this.timing.record({
|
|
145
|
-
method,
|
|
146
|
-
roundTripMs: performance.now() - start,
|
|
147
|
-
bytesSent: this.channel.lastBytesSent,
|
|
148
|
-
bytesReceived: this.channel.lastBytesReceived,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
56
|
close() {
|
|
152
57
|
if (this.closed)
|
|
153
58
|
return;
|
|
154
59
|
this.closed = true;
|
|
155
60
|
try {
|
|
156
|
-
|
|
157
|
-
|
|
61
|
+
const timing = this.getTimingCollector();
|
|
62
|
+
if (this.timingDump && timing && this.channel) {
|
|
63
|
+
const local = timing.getInfo();
|
|
158
64
|
let server;
|
|
159
65
|
let serverTimingError;
|
|
160
66
|
try {
|
|
@@ -167,7 +73,7 @@ export class Client {
|
|
|
167
73
|
}
|
|
168
74
|
}
|
|
169
75
|
finally {
|
|
170
|
-
|
|
76
|
+
super.close();
|
|
171
77
|
}
|
|
172
78
|
}
|
|
173
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/api/sync/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,4BAA4B,EAC5B,8BAA8B,GACjC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/api/sync/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,4BAA4B,EAC5B,8BAA8B,GACjC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGH,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,cAAc,GAEjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;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;YACP,CAAC;QACL,CAAC;IACL,CAAC;IAEQ,KAAK;QACV,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACzC,IAAI,IAAI,CAAC,UAAU,IAAI,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;gBAC/B,IAAI,MAAoC,CAAC;gBACzC,IAAI,iBAAqC,CAAC;gBAC1C,IAAI,CAAC;oBACD,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAqB,CAAC;gBAC7F,CAAC;gBACD,OAAO,KAAK,EAAE,CAAC;oBACX,iBAAiB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;gBACtC,CAAC;gBACD,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC;YAC5D,CAAC;QACL,CAAC;gBACO,CAAC;YACL,KAAK,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FileSystemCallbacks } from "../fs.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A synchronous request transport connected to a TypeScript API session.
|
|
4
|
+
*
|
|
5
|
+
* Implementations may use a child process, an in-process WebAssembly reactor,
|
|
6
|
+
* or another embedding mechanism. Calls must run to completion before returning.
|
|
7
|
+
*/
|
|
8
|
+
export interface SyncTransport {
|
|
9
|
+
/** Payload bytes sent by the most recently completed request. */
|
|
10
|
+
readonly lastBytesSent: number;
|
|
11
|
+
/** Payload bytes received by the most recently completed request. */
|
|
12
|
+
readonly lastBytesReceived: number;
|
|
13
|
+
requestSync(method: string, payload: string): string;
|
|
14
|
+
requestBinarySync(method: string, payload: Uint8Array): Uint8Array;
|
|
15
|
+
/** Registers a synchronous callback, subject to the transport's reentrancy constraints. */
|
|
16
|
+
registerCallback?(name: string, callback: (name: string, payload: string) => string): void;
|
|
17
|
+
unregisterCallback?(name: string): void;
|
|
18
|
+
setFileSystem?(fs: FileSystemCallbacks | undefined): void;
|
|
19
|
+
close(): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/api/sync/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC1B,iEAAiE;IACjE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,qEAAqE;IACrE,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAEnC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACrD,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,UAAU,CAAC;IACnE,2FAA2F;IAC3F,gBAAgB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IAC3F,kBAAkB,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,aAAa,CAAC,CAAC,EAAE,EAAE,mBAAmB,GAAG,SAAS,GAAG,IAAI,CAAC;IAC1D,KAAK,IAAI,IAAI,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/api/sync/transport.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { APIMethodInfo, APIRequest, BatchRequestsResponse, SourceFileResponseMethod } from "../proto.ts";
|
|
2
|
+
import { TimingCollector, type TimingInfo } from "../timing.ts";
|
|
3
|
+
import type { SyncTransport } from "./transport.ts";
|
|
4
|
+
/** Protocol client shared by the process and embedded synchronous transports. */
|
|
5
|
+
export declare class TransportClient {
|
|
6
|
+
private readonly encoder;
|
|
7
|
+
private readonly timing;
|
|
8
|
+
private readonly transport;
|
|
9
|
+
private readonly maxResponseBytesPerPage;
|
|
10
|
+
constructor(transport: SyncTransport, collectTiming: boolean, maxResponseBytesPerPage?: number);
|
|
11
|
+
apiRequest<K extends keyof APIMethodInfo>(method: K, params?: APIMethodInfo[K]["params"]): APIMethodInfo[K]["result"];
|
|
12
|
+
registerCallback(name: string, callback: (params: unknown) => unknown): () => void;
|
|
13
|
+
batchRequests(requests: readonly APIRequest[]): BatchRequestsResponse;
|
|
14
|
+
echo(payload: string): string;
|
|
15
|
+
echoBinary(payload: Uint8Array): Uint8Array;
|
|
16
|
+
apiRequestBinary<K extends SourceFileResponseMethod>(method: K, params?: APIMethodInfo[K]["params"]): Uint8Array | undefined;
|
|
17
|
+
getTimingCollector(): TimingCollector | undefined;
|
|
18
|
+
getTimingInfo(): TimingInfo;
|
|
19
|
+
resetTimingInfo(): void;
|
|
20
|
+
close(): void;
|
|
21
|
+
private recordTiming;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=transportClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transportClient.d.ts","sourceRoot":"","sources":["../../../src/api/sync/transportClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,aAAa,EACb,UAAU,EAEV,qBAAqB,EACrB,wBAAwB,EAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EAIH,eAAe,EACf,KAAK,UAAU,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,K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TimingCollector, } from "../timing.js";
|
|
2
|
+
/** Protocol client shared by the process and embedded synchronous transports. */
|
|
3
|
+
export class TransportClient {
|
|
4
|
+
encoder = new TextEncoder();
|
|
5
|
+
timing;
|
|
6
|
+
transport;
|
|
7
|
+
maxResponseBytesPerPage;
|
|
8
|
+
constructor(transport, collectTiming, maxResponseBytesPerPage) {
|
|
9
|
+
this.transport = transport;
|
|
10
|
+
this.maxResponseBytesPerPage = maxResponseBytesPerPage;
|
|
11
|
+
if (collectTiming) {
|
|
12
|
+
this.timing = new TimingCollector();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
apiRequest(method, params) {
|
|
16
|
+
const encodedPayload = JSON.stringify(params);
|
|
17
|
+
const start = performance.now();
|
|
18
|
+
const result = this.transport.requestSync(method, encodedPayload);
|
|
19
|
+
this.recordTiming(method, start);
|
|
20
|
+
if (result.length) {
|
|
21
|
+
return JSON.parse(result);
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
registerCallback(name, callback) {
|
|
26
|
+
const register = this.transport.registerCallback;
|
|
27
|
+
const unregister = this.transport.unregisterCallback;
|
|
28
|
+
if (!register || !unregister) {
|
|
29
|
+
throw new Error("Callbacks are not supported by this transport");
|
|
30
|
+
}
|
|
31
|
+
register.call(this.transport, name, (_, payload) => JSON.stringify(callback(JSON.parse(payload))) ?? "");
|
|
32
|
+
return () => unregister.call(this.transport, name);
|
|
33
|
+
}
|
|
34
|
+
batchRequests(requests) {
|
|
35
|
+
const params = { requests };
|
|
36
|
+
if (this.maxResponseBytesPerPage !== undefined) {
|
|
37
|
+
params.maxResponseBytesPerPage = this.maxResponseBytesPerPage;
|
|
38
|
+
}
|
|
39
|
+
const response = this.apiRequest("batchRequests", params);
|
|
40
|
+
let responses = response.responses;
|
|
41
|
+
let continuationToken = response.continuationToken;
|
|
42
|
+
while (continuationToken) {
|
|
43
|
+
const pageParams = {
|
|
44
|
+
requests: [],
|
|
45
|
+
continuationToken,
|
|
46
|
+
};
|
|
47
|
+
if (this.maxResponseBytesPerPage !== undefined) {
|
|
48
|
+
pageParams.maxResponseBytesPerPage = this.maxResponseBytesPerPage;
|
|
49
|
+
}
|
|
50
|
+
const page = this.apiRequest("batchRequests", pageParams);
|
|
51
|
+
if (page.responses.length < 200) {
|
|
52
|
+
responses.push(...page.responses);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
responses = responses.concat(page.responses);
|
|
56
|
+
}
|
|
57
|
+
continuationToken = page.continuationToken;
|
|
58
|
+
}
|
|
59
|
+
return { responses };
|
|
60
|
+
}
|
|
61
|
+
echo(payload) {
|
|
62
|
+
return this.transport.requestSync("echo", payload);
|
|
63
|
+
}
|
|
64
|
+
echoBinary(payload) {
|
|
65
|
+
return this.transport.requestBinarySync("echo", payload);
|
|
66
|
+
}
|
|
67
|
+
apiRequestBinary(method, params) {
|
|
68
|
+
const start = performance.now();
|
|
69
|
+
const result = this.transport.requestBinarySync(method, this.encoder.encode(JSON.stringify(params)));
|
|
70
|
+
this.recordTiming(method, start);
|
|
71
|
+
return result.length === 0 ? undefined : result;
|
|
72
|
+
}
|
|
73
|
+
getTimingCollector() {
|
|
74
|
+
return this.timing;
|
|
75
|
+
}
|
|
76
|
+
getTimingInfo() {
|
|
77
|
+
if (!this.timing) {
|
|
78
|
+
return disabledTimingInfo();
|
|
79
|
+
}
|
|
80
|
+
const local = this.timing.getInfo();
|
|
81
|
+
const result = this.transport.requestSync("getServerTiming", "");
|
|
82
|
+
return combineTimingInfo(local, JSON.parse(result));
|
|
83
|
+
}
|
|
84
|
+
resetTimingInfo() {
|
|
85
|
+
if (!this.timing)
|
|
86
|
+
return;
|
|
87
|
+
this.timing.reset();
|
|
88
|
+
this.transport.requestSync("resetServerTiming", "");
|
|
89
|
+
}
|
|
90
|
+
close() {
|
|
91
|
+
this.transport.close();
|
|
92
|
+
}
|
|
93
|
+
recordTiming(method, start) {
|
|
94
|
+
if (!this.timing)
|
|
95
|
+
return;
|
|
96
|
+
this.timing.record({
|
|
97
|
+
method,
|
|
98
|
+
roundTripMs: performance.now() - start,
|
|
99
|
+
bytesSent: this.transport.lastBytesSent,
|
|
100
|
+
bytesReceived: this.transport.lastBytesReceived,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=transportClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transportClient.js","sourceRoot":"","sources":["../../../src/api/sync/transportClient.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,iBAAiB,EACjB,kBAAkB,EAElB,eAAe,GAElB,MAAM,cAAc,CAAC;AAGtB,iFAAiF;AACjF,MAAM,OAAO,eAAe;IACP,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAC5B,MAAM,CAA8B;IACpC,SAAS,CAAgB;IACzB,uBAAuB,CAAqB;IAE7D,YAAY,SAAwB,EAAE,aAAsB,EAAE,uBAAgC;QAC1F,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;QACvD,IAAI,aAAa,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACxC,CAAC;IACL,CAAC;IAED,UAAU,CAAgC,MAAS,EAAE,MAAmC;QACpF,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAClE,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACjC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAA+B,CAAC;QAC5D,CAAC;QACD,OAAO,SAAuC,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AAO,kBAAkB,EAAE,CAAC;QAChC,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;QACjE,OAAO,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAqB,CAAC,CAAC;IAC5E,CAAC;IAED,eAAe;QACX,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO;QACzB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,KAAK;QACD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAEO,YAAY,CAAC,MAAc,EAAE,KAAa;QAC9C,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO;QACzB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YACf,MAAM;YACN,WAAW,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK;YACtC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa;YACvC,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,iBAAiB;SAClD,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncChannel.d.ts","sourceRoot":"","sources":["../../src/api/syncChannel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA+EH,wBAAgB,cAAc,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"syncChannel.d.ts","sourceRoot":"","sources":["../../src/api/syncChannel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA+EH,wBAAgB,cAAc,IAAI,MAAM,CAGvC;AAED;;;;;;;;;;;;;;;GAeG;AACH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AY;IASpB,OAAO,CAAC,gBAAgB;IAqDxB;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU;IAiClB;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IA0DlB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IA2BjB;;OAEG;IACH,OAAO,CAAC,OAAO;IA0Bf,yEAAyE;IACzE,OAAO,CAAC,QAAQ;IAOhB,uDAAuD;IACvD,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,SAAS;IAiBjB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAsBtB;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAoCrB;;;OAGG;IACH,OAAO,CAAC,WAAW;CAiBtB"}
|
package/dist/api/syncChannel.js
CHANGED
|
@@ -9,10 +9,8 @@
|
|
|
9
9
|
* directly on the pipe file descriptors obtained from the spawned
|
|
10
10
|
* ChildProcess.
|
|
11
11
|
*/
|
|
12
|
-
import { spawn, } from "node:child_process";
|
|
13
|
-
import { randomBytes } from "node:crypto";
|
|
14
|
-
import { closeSync, openSync, readSync, writeSync, } from "node:fs";
|
|
15
12
|
import { binHeaderSize, MSGPACK_BIN16, MSGPACK_BIN32, MSGPACK_BIN8, MSGPACK_FIXARRAY3, MSGPACK_UINT8, writeBinHeader, } from "./node/msgpack.js";
|
|
13
|
+
import { nodeProcess } from "./nodeProcess.js";
|
|
16
14
|
// ── MessageType constants ────────────────────────────────────────────
|
|
17
15
|
// Sent by channel (parent → child)
|
|
18
16
|
const MSG_REQUEST = 1;
|
|
@@ -22,30 +20,39 @@ const MSG_CALL_ERROR = 3;
|
|
|
22
20
|
const MSG_RESPONSE = 4;
|
|
23
21
|
const MSG_ERROR = 5;
|
|
24
22
|
const MSG_CALL = 6;
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
// Module state is created on first use so that this module can be loaded
|
|
24
|
+
// outside Node.js.
|
|
25
|
+
// Buffer used by Atomics.wait for tiny sleeps when a non-blocking fd
|
|
26
|
+
// returns EAGAIN.
|
|
27
|
+
let sleepBuf;
|
|
28
|
+
function sleep(ms) {
|
|
29
|
+
Atomics.wait(sleepBuf ??= new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
30
|
+
}
|
|
31
31
|
// ── Global cleanup tracking ─────────────────────────────────────────
|
|
32
32
|
// Track all live child processes so they can be killed on process exit.
|
|
33
33
|
// This mimics the auto-cleanup behavior of the native libsyncrpc module,
|
|
34
34
|
// whose Rust/C++ destructors would kill children automatically.
|
|
35
|
-
|
|
36
|
-
process
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
let liveChildren;
|
|
36
|
+
function trackChild(process, child) {
|
|
37
|
+
if (!liveChildren) {
|
|
38
|
+
const children = liveChildren = new Set();
|
|
39
|
+
process.on("exit", () => {
|
|
40
|
+
for (const child of children) {
|
|
41
|
+
try {
|
|
42
|
+
child.kill();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// swallow – process may already be dead
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
children.clear();
|
|
49
|
+
});
|
|
44
50
|
}
|
|
45
|
-
liveChildren.
|
|
46
|
-
}
|
|
51
|
+
liveChildren.add(child);
|
|
52
|
+
}
|
|
47
53
|
export function createPipePath() {
|
|
48
|
-
|
|
54
|
+
const process = nodeProcess();
|
|
55
|
+
return `\\\\.\\pipe\\tsgo-sync-${process.pid}-${process.getBuiltinModule("node:crypto").randomBytes(16).toString("hex")}`;
|
|
49
56
|
}
|
|
50
57
|
/**
|
|
51
58
|
* SyncRpcChannel – drop-in replacement for the native libsyncrpc class.
|
|
@@ -81,9 +88,13 @@ export class SyncRpcChannel {
|
|
|
81
88
|
// immediately after a request returns (the channel is strictly serial).
|
|
82
89
|
lastBytesSent = 0;
|
|
83
90
|
lastBytesReceived = 0;
|
|
91
|
+
fs = nodeProcess().getBuiltinModule("node:fs");
|
|
92
|
+
// Shared empty buffer – avoids allocating Buffer.alloc(0) on every
|
|
93
|
+
// zero-length bin field.
|
|
94
|
+
emptyBuf = Buffer.alloc(0);
|
|
84
95
|
_msgType = 0;
|
|
85
|
-
_msgName =
|
|
86
|
-
_msgPayload =
|
|
96
|
+
_msgName = this.emptyBuf;
|
|
97
|
+
_msgPayload = this.emptyBuf;
|
|
87
98
|
headerBuf = Buffer.allocUnsafe(4);
|
|
88
99
|
// Read-ahead buffer – reduces readSync syscalls by buffering data from the pipe.
|
|
89
100
|
readBuf = Buffer.allocUnsafe(65536);
|
|
@@ -93,6 +104,8 @@ export class SyncRpcChannel {
|
|
|
93
104
|
writeBuf = Buffer.allocUnsafe(65536);
|
|
94
105
|
constructor(exe, args, collectTiming = false) {
|
|
95
106
|
this.collectTiming = collectTiming;
|
|
107
|
+
const process = nodeProcess();
|
|
108
|
+
const { spawn } = process.getBuiltinModule("node:child_process");
|
|
96
109
|
const isWindows = process.platform === "win32";
|
|
97
110
|
if (isWindows) {
|
|
98
111
|
// On Windows, libuv pipe handles don't expose POSIX fds, so
|
|
@@ -108,14 +121,14 @@ export class SyncRpcChannel {
|
|
|
108
121
|
let fd;
|
|
109
122
|
for (let i = 0; i < 500; i++) {
|
|
110
123
|
try {
|
|
111
|
-
fd = openSync(pipePath, "r+");
|
|
124
|
+
fd = this.fs.openSync(pipePath, "r+");
|
|
112
125
|
break;
|
|
113
126
|
}
|
|
114
127
|
catch {
|
|
115
128
|
if (this.child.exitCode !== null) {
|
|
116
129
|
throw new Error(`Child process exited with code ${this.child.exitCode} before pipe was ready`);
|
|
117
130
|
}
|
|
118
|
-
|
|
131
|
+
sleep(10);
|
|
119
132
|
}
|
|
120
133
|
}
|
|
121
134
|
if (fd === undefined) {
|
|
@@ -156,7 +169,7 @@ export class SyncRpcChannel {
|
|
|
156
169
|
stdin.unref();
|
|
157
170
|
}
|
|
158
171
|
// Track for auto-cleanup on process exit.
|
|
159
|
-
|
|
172
|
+
trackChild(process, this.child);
|
|
160
173
|
this.child.unref();
|
|
161
174
|
}
|
|
162
175
|
// ── Public API ──────────────────────────────────────────────────
|
|
@@ -187,9 +200,9 @@ export class SyncRpcChannel {
|
|
|
187
200
|
/** Kill the child process and release resources. */
|
|
188
201
|
close() {
|
|
189
202
|
try {
|
|
190
|
-
liveChildren
|
|
203
|
+
liveChildren?.delete(this.child);
|
|
191
204
|
if (this.pipeFd !== undefined) {
|
|
192
|
-
closeSync(this.pipeFd);
|
|
205
|
+
this.fs.closeSync(this.pipeFd);
|
|
193
206
|
this.pipeFd = undefined;
|
|
194
207
|
}
|
|
195
208
|
// Destroy the stdio streams so that their pipe handles are closed
|
|
@@ -401,7 +414,7 @@ export class SyncRpcChannel {
|
|
|
401
414
|
throw new Error(`Expected binary data (0xc4-0xc6), received: 0x${marker.toString(16)}`);
|
|
402
415
|
}
|
|
403
416
|
if (size === 0)
|
|
404
|
-
return
|
|
417
|
+
return this.emptyBuf;
|
|
405
418
|
return this.readExact(size);
|
|
406
419
|
}
|
|
407
420
|
// ── Low-level synchronous I/O ───────────────────────────────────
|
|
@@ -444,7 +457,7 @@ export class SyncRpcChannel {
|
|
|
444
457
|
this.readBufLen = 0;
|
|
445
458
|
for (;;) {
|
|
446
459
|
try {
|
|
447
|
-
const n = readSync(this.readFd, this.readBuf, 0, this.readBuf.length, null);
|
|
460
|
+
const n = this.fs.readSync(this.readFd, this.readBuf, 0, this.readBuf.length, null);
|
|
448
461
|
if (n === 0) {
|
|
449
462
|
throw this.eofError();
|
|
450
463
|
}
|
|
@@ -453,7 +466,7 @@ export class SyncRpcChannel {
|
|
|
453
466
|
}
|
|
454
467
|
catch (e) {
|
|
455
468
|
if (e instanceof Error && ("code" in e) && (e.code === "EAGAIN" || e.code === "EWOULDBLOCK")) {
|
|
456
|
-
|
|
469
|
+
sleep(1);
|
|
457
470
|
continue;
|
|
458
471
|
}
|
|
459
472
|
throw e;
|
|
@@ -481,7 +494,7 @@ export class SyncRpcChannel {
|
|
|
481
494
|
// Remaining data is larger than read buffer; read directly
|
|
482
495
|
// into the target to avoid unnecessary copying.
|
|
483
496
|
try {
|
|
484
|
-
const n = readSync(this.readFd, buffer, pos, length - pos, null);
|
|
497
|
+
const n = this.fs.readSync(this.readFd, buffer, pos, length - pos, null);
|
|
485
498
|
if (n === 0) {
|
|
486
499
|
throw this.eofError();
|
|
487
500
|
}
|
|
@@ -489,7 +502,7 @@ export class SyncRpcChannel {
|
|
|
489
502
|
}
|
|
490
503
|
catch (e) {
|
|
491
504
|
if (e instanceof Error && ("code" in e) && (e.code === "EAGAIN" || e.code === "EWOULDBLOCK")) {
|
|
492
|
-
|
|
505
|
+
sleep(1);
|
|
493
506
|
continue;
|
|
494
507
|
}
|
|
495
508
|
throw e;
|
|
@@ -510,12 +523,12 @@ export class SyncRpcChannel {
|
|
|
510
523
|
let pos = 0;
|
|
511
524
|
while (pos < total) {
|
|
512
525
|
try {
|
|
513
|
-
const n = writeSync(this.writeFd, data, pos, total - pos);
|
|
526
|
+
const n = this.fs.writeSync(this.writeFd, data, pos, total - pos);
|
|
514
527
|
pos += n;
|
|
515
528
|
}
|
|
516
529
|
catch (e) {
|
|
517
530
|
if (e instanceof Error && ("code" in e) && (e.code === "EAGAIN" || e.code === "EWOULDBLOCK")) {
|
|
518
|
-
|
|
531
|
+
sleep(1);
|
|
519
532
|
continue;
|
|
520
533
|
}
|
|
521
534
|
throw e;
|