@lynx-js/devtool-connector 0.13.1 → 0.16.2
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/CHANGELOG.md +13 -0
- package/LICENSE +1 -1
- package/README.md +18 -134
- package/dist/2.js +2019 -0
- package/dist/{346.js → a.js} +102 -143
- package/dist/client-id.d.ts +0 -6
- package/dist/command/client.d.ts +8 -7
- package/dist/command/contract.d.ts +82 -24
- package/dist/command/core.d.ts +11 -10
- package/dist/command/in-process-client.d.ts +16 -0
- package/dist/command/index.d.ts +28 -20
- package/dist/command/index.js +177 -159
- package/dist/command/list-clients.d.ts +6 -0
- package/dist/command/list-sessions.d.ts +5 -0
- package/dist/command/open.d.ts +5 -0
- package/dist/command/query.d.ts +1 -1
- package/dist/command/reactlynx/controller.d.ts +3 -3
- package/dist/command/reactlynx/model.d.ts +7 -7
- package/dist/command/reactlynx/protocol.d.ts +0 -1
- package/dist/command/reactlynx/session.d.ts +3 -3
- package/dist/command/reactlynx/types.d.ts +7 -7
- package/dist/command/ref-actions.d.ts +4 -4
- package/dist/command/result.d.ts +0 -1
- package/dist/command/screenshot-annotation.d.ts +2 -2
- package/dist/command/screenshot.d.ts +2 -2
- package/dist/command/snapshot.d.ts +2 -2
- package/dist/command/source-info.d.ts +20 -0
- package/dist/command/targets.d.ts +8 -10
- package/dist/command/timeout.d.ts +3 -0
- package/dist/command/wait-for-client.d.ts +5 -0
- package/dist/daemon/device-connection.d.ts +4 -3
- package/dist/daemon/entry.js +18 -20
- package/dist/daemon/index.d.ts +7 -2
- package/dist/daemon/index.js +7 -3
- package/dist/daemon/inspector-assets.d.ts +11 -0
- package/dist/daemon/manager.d.ts +12 -4
- package/dist/daemon/protocol.d.ts +20 -16
- package/dist/daemon/server.d.ts +7 -1
- package/dist/daemon/static-server.d.ts +3 -1
- package/dist/f.js +5790 -0
- package/dist/f1.js +737 -0
- package/dist/{962.js → h.js} +841 -3259
- package/dist/{712.js → hb.js} +26 -19
- package/dist/i.js +2505 -0
- package/dist/index.d.ts +13 -18
- package/dist/index.js +3 -2
- package/dist/main.d.ts +2 -0
- package/dist/main.js +3 -0
- package/dist/request-id.d.ts +1 -0
- package/dist/streams/cdp.d.ts +3 -3
- package/dist/streams/customized.d.ts +5 -5
- package/dist/streams/index.d.ts +4 -3
- package/dist/streams/index.js +1 -1
- package/dist/streams/utils.d.ts +3 -3
- package/dist/{872.js → t.js} +364 -301
- package/dist/transport/adb-shell-types.d.ts +14 -0
- package/dist/transport/android-app-icon-helper.d.ts +1 -0
- package/dist/transport/android.d.ts +13 -3
- package/dist/transport/base.d.ts +2 -9
- package/dist/transport/daemon.d.ts +3 -2
- package/dist/transport/desktop.d.ts +1 -1
- package/dist/transport/hdt.d.ts +13 -0
- package/dist/transport/index.d.ts +9 -9
- package/dist/transport/index.js +2 -3
- package/dist/transport/ios.d.ts +2 -2
- package/dist/transport/peertalk.d.ts +4 -3
- package/dist/transport/stream-lifecycle.d.ts +4 -0
- package/dist/transport/transport.d.ts +4 -8
- package/dist/transport/usbmux.d.ts +5 -5
- package/dist/transport/ws-stream.d.ts +3 -10
- package/dist/types.d.ts +27 -54
- package/dist/{63.js → ws-stream.js} +23 -24
- package/package.json +32 -22
- package/dist/390.js +0 -329
- package/dist/556.js +0 -258
- package/dist/61.js +0 -3432
package/dist/{346.js → a.js}
RENAMED
|
@@ -1,36 +1,12 @@
|
|
|
1
|
-
import { randomInt } from "node:crypto";
|
|
2
1
|
import { ReadableStream } from "node:stream/web";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { DaemonTransport } from "./556.js";
|
|
2
|
+
import { isGetGlobalSwitchResponse, isInitializeResponse, AppResponseTransformStream, GlobalSwitchRequestTransformStream, isListSessionResponse, isHeadlessPrepareResponse, createCorrelatedFilter, isSetGlobalSwitchResponse, CDPResponseTransformStream, CDPOutputTransformStream, CustomizedResponseTransformStream, CDPRequestTransformStream, CustomizedRequestTransformStream, SessionGuardTransformStream, FilterTransformStream, InspectStream, CustomizedClientIdTransformStream, nextRequestId } from "./hb.js";
|
|
3
|
+
import { ansi_createDebug, isDaemonLifecycleError } from "./2.js";
|
|
4
|
+
import { DaemonTransport, HDTTransport, ClientId } from "./f1.js";
|
|
7
5
|
function throwClientDiscoveryFailures(failures) {
|
|
8
6
|
if (1 === failures.length) throw failures[0];
|
|
9
|
-
const details = failures.map((failure)=>failure instanceof Error ? failure.message : String(failure)).join(
|
|
7
|
+
const details = failures.map((failure)=>failure instanceof Error ? failure.message : String(failure)).join("; ");
|
|
10
8
|
throw new AggregateError(failures, `All client discovery transports failed: ${details}`);
|
|
11
9
|
}
|
|
12
|
-
class ClientId {
|
|
13
|
-
static serialize(deviceId, target) {
|
|
14
|
-
const encodedTarget = 'string' == typeof target ? encodeURIComponent(target) : target;
|
|
15
|
-
return `${encodeURIComponent(deviceId)}:${encodedTarget}`;
|
|
16
|
-
}
|
|
17
|
-
static deserialize(clientId) {
|
|
18
|
-
try {
|
|
19
|
-
const lastColonIndex = clientId.lastIndexOf(':');
|
|
20
|
-
if (-1 === lastColonIndex) return null;
|
|
21
|
-
const target = decodeURIComponent(clientId.substring(lastColonIndex + 1));
|
|
22
|
-
if (!target) return null;
|
|
23
|
-
const port = /^-?\d+$/.test(target) ? Number(target) : target;
|
|
24
|
-
if ('number' == typeof port && !Number.isSafeInteger(port)) return null;
|
|
25
|
-
return {
|
|
26
|
-
deviceId: decodeURIComponent(clientId.substring(0, lastColonIndex)),
|
|
27
|
-
port
|
|
28
|
-
};
|
|
29
|
-
} catch {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
10
|
function _ts_add_disposable_resource(env, value, async) {
|
|
35
11
|
if (null != value) {
|
|
36
12
|
if ("object" != typeof value && "function" != typeof value) throw new TypeError("Object expected.");
|
|
@@ -62,66 +38,57 @@ function _ts_add_disposable_resource(env, value, async) {
|
|
|
62
38
|
});
|
|
63
39
|
return value;
|
|
64
40
|
}
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return next();
|
|
84
|
-
});
|
|
85
|
-
} else s |= 1;
|
|
86
|
-
} catch (e) {
|
|
87
|
-
fail(e);
|
|
88
|
-
}
|
|
89
|
-
if (1 === s) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
90
|
-
if (env.hasError) throw env.error;
|
|
41
|
+
function _ts_dispose_resources(env) {
|
|
42
|
+
function fail(e) {
|
|
43
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
44
|
+
env.hasError = true;
|
|
45
|
+
}
|
|
46
|
+
var r, s = 0;
|
|
47
|
+
function next() {
|
|
48
|
+
while(r = env.stack.pop())try {
|
|
49
|
+
if (!r.async && 1 === s) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
50
|
+
if (r.dispose) {
|
|
51
|
+
var result = r.dispose.call(r.value);
|
|
52
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
53
|
+
fail(e);
|
|
54
|
+
return next();
|
|
55
|
+
});
|
|
56
|
+
} else s |= 1;
|
|
57
|
+
} catch (e) {
|
|
58
|
+
fail(e);
|
|
91
59
|
}
|
|
92
|
-
return
|
|
93
|
-
|
|
60
|
+
if (1 === s) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
61
|
+
if (env.hasError) throw env.error;
|
|
62
|
+
}
|
|
63
|
+
return next();
|
|
94
64
|
}
|
|
95
|
-
const debug =
|
|
65
|
+
const debug = ansi_createDebug("devtool-mcp-server:connector");
|
|
96
66
|
const openAppClientWaitTimeoutMs = 55000;
|
|
97
67
|
const clientSetupSwitches = [
|
|
98
68
|
{
|
|
99
|
-
key:
|
|
69
|
+
key: "enable_devtool",
|
|
100
70
|
value: true,
|
|
101
71
|
required: true
|
|
102
72
|
},
|
|
103
73
|
{
|
|
104
|
-
key:
|
|
74
|
+
key: "enable_quickjs_debug",
|
|
105
75
|
value: true,
|
|
106
76
|
required: true
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
key: 'enable_pixel_copy',
|
|
110
|
-
value: false,
|
|
111
|
-
required: false
|
|
112
77
|
}
|
|
113
78
|
];
|
|
114
79
|
function hasClientList(transport) {
|
|
115
|
-
return
|
|
80
|
+
return "function" == typeof transport.listClients;
|
|
116
81
|
}
|
|
117
82
|
function isNonEmptyListSessionResponse(response) {
|
|
118
83
|
return isListSessionResponse(response) && response.data.data.length > 0;
|
|
119
84
|
}
|
|
120
85
|
class Connector {
|
|
121
86
|
#transports;
|
|
87
|
+
#hdtTransports;
|
|
122
88
|
#daemonTransports;
|
|
123
89
|
constructor(transports){
|
|
124
90
|
this.#transports = transports;
|
|
91
|
+
this.#hdtTransports = transports.filter((t)=>t instanceof HDTTransport);
|
|
125
92
|
this.#daemonTransports = transports.filter((t)=>t instanceof DaemonTransport);
|
|
126
93
|
}
|
|
127
94
|
async listClients() {
|
|
@@ -131,36 +98,48 @@ class Connector {
|
|
|
131
98
|
await Promise.allSettled(clients.flatMap(({ id })=>this.#setupClient(transport, id)));
|
|
132
99
|
return clients;
|
|
133
100
|
}));
|
|
134
|
-
const fulfilledDaemonClientResults = daemonClientResults.filter((r)=>
|
|
135
|
-
discoveryFailures.push(...daemonClientResults.filter((r)=>
|
|
101
|
+
const fulfilledDaemonClientResults = daemonClientResults.filter((r)=>"fulfilled" === r.status);
|
|
102
|
+
discoveryFailures.push(...daemonClientResults.filter((r)=>"rejected" === r.status).map((r)=>r.reason));
|
|
136
103
|
const daemonClients = fulfilledDaemonClientResults.flatMap((r)=>r.value);
|
|
137
104
|
if (fulfilledDaemonClientResults.length > 0) {
|
|
138
|
-
debug(
|
|
105
|
+
debug("Using clients from daemon transport: %o", daemonClients);
|
|
139
106
|
return daemonClients;
|
|
140
107
|
}
|
|
141
|
-
const daemonLifecycleFailure = daemonClientResults.filter((result)=>
|
|
108
|
+
const daemonLifecycleFailure = daemonClientResults.filter((result)=>"rejected" === result.status).map((result)=>result.reason).find(isDaemonLifecycleError);
|
|
142
109
|
if (daemonLifecycleFailure) throw daemonLifecycleFailure;
|
|
143
|
-
const
|
|
110
|
+
const hdtClientResults = await Promise.allSettled(this.#hdtTransports.map(async (transport)=>{
|
|
111
|
+
const clients = await transport.listClients();
|
|
112
|
+
await Promise.allSettled(clients.flatMap(({ id })=>this.#setupClient(transport, id)));
|
|
113
|
+
return clients;
|
|
114
|
+
}));
|
|
115
|
+
const fulfilledHDTClientResults = hdtClientResults.filter((r)=>"fulfilled" === r.status);
|
|
116
|
+
discoveryFailures.push(...hdtClientResults.filter((r)=>"rejected" === r.status).map((r)=>r.reason));
|
|
117
|
+
const hdtClients = fulfilledHDTClientResults.flatMap((r)=>r.value);
|
|
118
|
+
if (fulfilledHDTClientResults.length > 0) {
|
|
119
|
+
debug("Using clients from HDT transport: %o", hdtClients);
|
|
120
|
+
return hdtClients;
|
|
121
|
+
}
|
|
122
|
+
const transportDevices = await Promise.allSettled(this.#transports.filter((t)=>!(t instanceof HDTTransport)).filter((t)=>!(t instanceof DaemonTransport)).map(async (transport)=>({
|
|
144
123
|
transport,
|
|
145
124
|
devices: await transport.listDevices()
|
|
146
125
|
})));
|
|
147
|
-
for (const result of transportDevices)if (
|
|
126
|
+
for (const result of transportDevices)if ("rejected" === result.status) {
|
|
148
127
|
discoveryFailures.push(result.reason);
|
|
149
|
-
debug(
|
|
128
|
+
debug("listClients: listDevices failed on one transport: %O", result.reason);
|
|
150
129
|
}
|
|
151
|
-
const fulfilledTransportDevices = transportDevices.filter((result)=>
|
|
130
|
+
const fulfilledTransportDevices = transportDevices.filter((result)=>"fulfilled" === result.status);
|
|
152
131
|
if (0 === fulfilledTransportDevices.length && discoveryFailures.length > 0) throwClientDiscoveryFailures(discoveryFailures);
|
|
153
132
|
const results = await Promise.allSettled(fulfilledTransportDevices.map((r)=>r.value).flatMap(({ transport, devices })=>devices.flatMap(({ id })=>this.#listClientsForDevice(transport, id))));
|
|
154
|
-
const fulfilledClientResults = results.filter((r)=>
|
|
133
|
+
const fulfilledClientResults = results.filter((r)=>"fulfilled" === r.status);
|
|
155
134
|
if (0 === fulfilledClientResults.length && results.length > 0) throwClientDiscoveryFailures([
|
|
156
135
|
...discoveryFailures,
|
|
157
|
-
...results.filter((result)=>
|
|
136
|
+
...results.filter((result)=>"rejected" === result.status).map((result)=>result.reason)
|
|
158
137
|
]);
|
|
159
138
|
return fulfilledClientResults.flatMap((r)=>r.value);
|
|
160
139
|
}
|
|
161
140
|
async listDevices() {
|
|
162
141
|
const results = await Promise.allSettled(this.#transports.map((t)=>t.listDevices()));
|
|
163
|
-
return results.filter((result)=>
|
|
142
|
+
return results.filter((result)=>"fulfilled" === result.status).flatMap(({ value })=>value);
|
|
164
143
|
}
|
|
165
144
|
async listAvailableApps(deviceId) {
|
|
166
145
|
const transport = await this.#findTransportWithDeviceId(deviceId);
|
|
@@ -198,31 +177,8 @@ class Connector {
|
|
|
198
177
|
}) {
|
|
199
178
|
return this.#sendMessage(clientId, message, pipeline);
|
|
200
179
|
}
|
|
201
|
-
async sendMessageNoReply(clientId, message) {
|
|
202
|
-
const { deviceId, port } = this.#resolveClientId(clientId);
|
|
203
|
-
const transport = await this.#findTransportWithDeviceId(deviceId);
|
|
204
|
-
const signal = AbortSignal.timeout(5000);
|
|
205
|
-
const conn = await transport.connect({
|
|
206
|
-
deviceId,
|
|
207
|
-
port,
|
|
208
|
-
signal
|
|
209
|
-
});
|
|
210
|
-
try {
|
|
211
|
-
const inputStream = [
|
|
212
|
-
new CustomizedClientIdTransformStream(port),
|
|
213
|
-
new InspectStream((msg)=>debug(`sendMessageNoReply ${deviceId}:${port} send %o`, JSON.stringify(msg)))
|
|
214
|
-
].reduce((stream, transform)=>stream.pipeThrough(transform), ReadableStream.from([
|
|
215
|
-
message
|
|
216
|
-
]));
|
|
217
|
-
await inputStream.pipeTo(conn.writable, {
|
|
218
|
-
preventClose: true
|
|
219
|
-
});
|
|
220
|
-
} finally{
|
|
221
|
-
await conn[Symbol.asyncDispose]();
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
180
|
async sendAppMessage(clientId, method, params) {
|
|
225
|
-
const id =
|
|
181
|
+
const id = nextRequestId();
|
|
226
182
|
return await this.#sendMessage(clientId, {
|
|
227
183
|
method,
|
|
228
184
|
params: {
|
|
@@ -231,7 +187,7 @@ class Connector {
|
|
|
231
187
|
}, {
|
|
232
188
|
input: [
|
|
233
189
|
new CustomizedRequestTransformStream({
|
|
234
|
-
type:
|
|
190
|
+
type: "App",
|
|
235
191
|
sessionId: -1,
|
|
236
192
|
messageBuilder: (message)=>({
|
|
237
193
|
id,
|
|
@@ -240,18 +196,18 @@ class Connector {
|
|
|
240
196
|
})
|
|
241
197
|
],
|
|
242
198
|
output: [
|
|
243
|
-
new CustomizedResponseTransformStream(
|
|
199
|
+
new CustomizedResponseTransformStream("App", id),
|
|
244
200
|
new AppResponseTransformStream(method)
|
|
245
201
|
]
|
|
246
202
|
});
|
|
247
203
|
}
|
|
248
204
|
async openPage(clientId, url) {
|
|
249
205
|
return await this.#sendMessage(clientId, {
|
|
250
|
-
event:
|
|
206
|
+
event: "Customized",
|
|
251
207
|
data: {
|
|
252
|
-
type:
|
|
208
|
+
type: "OpenCard",
|
|
253
209
|
data: {
|
|
254
|
-
type:
|
|
210
|
+
type: "url",
|
|
255
211
|
url
|
|
256
212
|
},
|
|
257
213
|
sender: -1
|
|
@@ -265,18 +221,18 @@ class Connector {
|
|
|
265
221
|
});
|
|
266
222
|
}
|
|
267
223
|
async sendCDPMessage(clientId, sessionId, method, params, isMainThread = false) {
|
|
268
|
-
const id =
|
|
224
|
+
const id = nextRequestId();
|
|
269
225
|
const SUPPORTED_DOMAIN = [
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
226
|
+
"Debugger",
|
|
227
|
+
"Runtime",
|
|
228
|
+
"HeapProfiler",
|
|
229
|
+
"Profiler"
|
|
274
230
|
];
|
|
275
|
-
if (isMainThread && !SUPPORTED_DOMAIN.some((domain)=>method.startsWith(domain +
|
|
231
|
+
if (isMainThread && !SUPPORTED_DOMAIN.some((domain)=>method.startsWith(domain + "."))) throw new Error(`Method ${method} is not supported for main thread. Supported domains: ${SUPPORTED_DOMAIN.join(", ")}`);
|
|
276
232
|
return await this.#sendMessage(clientId, {
|
|
277
233
|
method,
|
|
278
234
|
params,
|
|
279
|
-
sessionId: isMainThread ?
|
|
235
|
+
sessionId: isMainThread ? "Main" : void 0
|
|
280
236
|
}, {
|
|
281
237
|
input: [
|
|
282
238
|
new CDPRequestTransformStream(sessionId, id)
|
|
@@ -292,9 +248,9 @@ class Connector {
|
|
|
292
248
|
}
|
|
293
249
|
async prepareHeadless(clientId) {
|
|
294
250
|
const { data: { data: state } } = await this.#sendMessage(clientId, {
|
|
295
|
-
event:
|
|
251
|
+
event: "Customized",
|
|
296
252
|
data: {
|
|
297
|
-
type:
|
|
253
|
+
type: "HeadlessPrepare",
|
|
298
254
|
data: {}
|
|
299
255
|
}
|
|
300
256
|
}, {
|
|
@@ -312,19 +268,23 @@ class Connector {
|
|
|
312
268
|
const deadline = Date.now() + timeoutMs;
|
|
313
269
|
let lastError;
|
|
314
270
|
for(;;){
|
|
271
|
+
options.signal?.throwIfAborted();
|
|
315
272
|
const state = await this.prepareHeadless(clientId);
|
|
316
|
-
|
|
317
|
-
if (
|
|
273
|
+
options.signal?.throwIfAborted();
|
|
274
|
+
if ("ready" === state.status) return;
|
|
275
|
+
if ("error" === state.status) lastError = state.message ?? "unknown error";
|
|
318
276
|
if (Date.now() >= deadline) throw new Error(void 0 !== lastError ? `Failed to prepare headless runtime: ${lastError}` : `Timed out preparing headless runtime after ${timeoutMs}ms`);
|
|
319
|
-
await delay(pollIntervalMs
|
|
277
|
+
await delay(pollIntervalMs, void 0, options.signal ? {
|
|
278
|
+
signal: options.signal
|
|
279
|
+
} : {});
|
|
320
280
|
}
|
|
321
281
|
}
|
|
322
282
|
async #sendListSessionMessage(clientId) {
|
|
323
|
-
const id =
|
|
283
|
+
const id = nextRequestId();
|
|
324
284
|
const { data: { data: sessions } } = await this.#sendMessage(clientId, {
|
|
325
|
-
event:
|
|
285
|
+
event: "Customized",
|
|
326
286
|
data: {
|
|
327
|
-
type:
|
|
287
|
+
type: "ListSession",
|
|
328
288
|
data: {},
|
|
329
289
|
id
|
|
330
290
|
}
|
|
@@ -336,7 +296,7 @@ class Connector {
|
|
|
336
296
|
});
|
|
337
297
|
return sessions.map((session)=>({
|
|
338
298
|
...session,
|
|
339
|
-
type:
|
|
299
|
+
type: "" === session.type ? "lynx" : session.type
|
|
340
300
|
}));
|
|
341
301
|
}
|
|
342
302
|
async getGlobalSwitch(clientId, key) {
|
|
@@ -344,14 +304,14 @@ class Connector {
|
|
|
344
304
|
key
|
|
345
305
|
}, {
|
|
346
306
|
input: [
|
|
347
|
-
new GlobalSwitchRequestTransformStream(
|
|
307
|
+
new GlobalSwitchRequestTransformStream("GetGlobalSwitch")
|
|
348
308
|
],
|
|
349
309
|
output: [
|
|
350
310
|
new FilterTransformStream(isGetGlobalSwitchResponse)
|
|
351
311
|
]
|
|
352
312
|
});
|
|
353
|
-
if (
|
|
354
|
-
return
|
|
313
|
+
if ("object" == typeof message) return message?.global_value === "true" || message?.global_value === true;
|
|
314
|
+
else return "true" === message || true === message;
|
|
355
315
|
}
|
|
356
316
|
async setGlobalSwitch(clientId, key, value) {
|
|
357
317
|
await this.#sendMessage(clientId, {
|
|
@@ -359,7 +319,7 @@ class Connector {
|
|
|
359
319
|
value
|
|
360
320
|
}, {
|
|
361
321
|
input: [
|
|
362
|
-
new GlobalSwitchRequestTransformStream(
|
|
322
|
+
new GlobalSwitchRequestTransformStream("SetGlobalSwitch")
|
|
363
323
|
],
|
|
364
324
|
output: [
|
|
365
325
|
new FilterTransformStream(isSetGlobalSwitchResponse)
|
|
@@ -409,7 +369,7 @@ class Connector {
|
|
|
409
369
|
return await Promise.any(transports.map(async (transport)=>{
|
|
410
370
|
const devices = await transport.listDevices();
|
|
411
371
|
if (devices.some(({ id })=>id === deviceId)) return transport;
|
|
412
|
-
throw new Error(
|
|
372
|
+
throw new Error("Not found in this transport");
|
|
413
373
|
}));
|
|
414
374
|
} catch (error) {
|
|
415
375
|
if (error instanceof AggregateError) {
|
|
@@ -423,7 +383,7 @@ class Connector {
|
|
|
423
383
|
const { deviceId, port } = options;
|
|
424
384
|
const conn = await transport.connect(options);
|
|
425
385
|
const inputAbortController = new AbortController();
|
|
426
|
-
const inputAbortReason = new Error(
|
|
386
|
+
const inputAbortReason = new Error("Connector input stream disposed");
|
|
427
387
|
const inputClosed = [
|
|
428
388
|
...pipeline.input,
|
|
429
389
|
new CustomizedClientIdTransformStream(port),
|
|
@@ -485,8 +445,7 @@ class Connector {
|
|
|
485
445
|
if (response.done) {
|
|
486
446
|
const clientId = ClientId.serialize(options.deviceId, options.port);
|
|
487
447
|
throw new Error(`No response found for clientId: ${clientId}`);
|
|
488
|
-
}
|
|
489
|
-
result = response.value;
|
|
448
|
+
} else result = response.value;
|
|
490
449
|
} catch (err) {
|
|
491
450
|
failed = true;
|
|
492
451
|
primaryError = err;
|
|
@@ -497,7 +456,7 @@ class Connector {
|
|
|
497
456
|
try {
|
|
498
457
|
await outputStream[Symbol.asyncDispose]();
|
|
499
458
|
} catch (err) {
|
|
500
|
-
if (failed) debug(
|
|
459
|
+
if (failed) debug("connection cleanup suppressed after request failure %O", err);
|
|
501
460
|
else {
|
|
502
461
|
failed = true;
|
|
503
462
|
primaryError = err;
|
|
@@ -520,7 +479,7 @@ class Connector {
|
|
|
520
479
|
port
|
|
521
480
|
};
|
|
522
481
|
}));
|
|
523
|
-
const clients = results.filter((result)=>
|
|
482
|
+
const clients = results.filter((result)=>"fulfilled" === result.status).map((result)=>result.value);
|
|
524
483
|
if (0 === clients.length) discoverySignal.throwIfAborted();
|
|
525
484
|
return clients;
|
|
526
485
|
}
|
|
@@ -534,35 +493,35 @@ class Connector {
|
|
|
534
493
|
const lifetime = new AbortController();
|
|
535
494
|
const forwardStageSignal = (signal)=>{
|
|
536
495
|
const abort = ()=>lifetime.abort(signal.reason);
|
|
537
|
-
signal.addEventListener(
|
|
496
|
+
signal.addEventListener("abort", abort, {
|
|
538
497
|
once: true
|
|
539
498
|
});
|
|
540
499
|
if (signal.aborted) abort();
|
|
541
500
|
try {
|
|
542
501
|
lifetime.signal.throwIfAborted();
|
|
543
502
|
} catch (err) {
|
|
544
|
-
signal.removeEventListener(
|
|
503
|
+
signal.removeEventListener("abort", abort);
|
|
545
504
|
throw err;
|
|
546
505
|
}
|
|
547
|
-
return ()=>signal.removeEventListener(
|
|
506
|
+
return ()=>signal.removeEventListener("abort", abort);
|
|
548
507
|
};
|
|
549
508
|
const exchange = async (connection, message, predicate, signal)=>{
|
|
550
509
|
const stopForwardingSignal = forwardStageSignal(signal);
|
|
551
510
|
try {
|
|
552
511
|
signal.throwIfAborted();
|
|
553
512
|
const writer = connection.writable.getWriter();
|
|
554
|
-
debug(
|
|
513
|
+
debug("connect input stream send %o", JSON.stringify(message));
|
|
555
514
|
await writer.write(message).finally(()=>writer.releaseLock());
|
|
556
515
|
signal.throwIfAborted();
|
|
557
516
|
for await (const value of connection.readable.values({
|
|
558
517
|
preventCancel: true
|
|
559
518
|
})){
|
|
560
519
|
signal.throwIfAborted();
|
|
561
|
-
debug(
|
|
520
|
+
debug("connect output stream receive %O", value);
|
|
562
521
|
if (predicate(value)) return value;
|
|
563
522
|
}
|
|
564
523
|
signal.throwIfAborted();
|
|
565
|
-
throw new Error(
|
|
524
|
+
throw new Error("Connection closed before receiving the expected response");
|
|
566
525
|
} catch (err) {
|
|
567
526
|
signal.throwIfAborted();
|
|
568
527
|
throw err;
|
|
@@ -577,14 +536,14 @@ class Connector {
|
|
|
577
536
|
signal: lifetime.signal
|
|
578
537
|
}).finally(stopForwardingDiscovery), true);
|
|
579
538
|
const register = await exchange(connection, {
|
|
580
|
-
event:
|
|
539
|
+
event: "Initialize",
|
|
581
540
|
data: port
|
|
582
541
|
}, isInitializeResponse, discoverySignal);
|
|
583
542
|
for (const { key, value, required } of clientSetupSwitches)try {
|
|
584
543
|
await exchange(connection, {
|
|
585
|
-
event:
|
|
544
|
+
event: "Customized",
|
|
586
545
|
data: {
|
|
587
|
-
type:
|
|
546
|
+
type: "SetGlobalSwitch",
|
|
588
547
|
data: {
|
|
589
548
|
client_id: port,
|
|
590
549
|
session_id: -1,
|
|
@@ -605,7 +564,7 @@ class Connector {
|
|
|
605
564
|
env.error = e;
|
|
606
565
|
env.hasError = true;
|
|
607
566
|
} finally{
|
|
608
|
-
const result =
|
|
567
|
+
const result = _ts_dispose_resources(env);
|
|
609
568
|
if (result) await result;
|
|
610
569
|
}
|
|
611
570
|
}
|
|
@@ -621,7 +580,7 @@ class Connector {
|
|
|
621
580
|
value
|
|
622
581
|
}, {
|
|
623
582
|
input: [
|
|
624
|
-
new GlobalSwitchRequestTransformStream(
|
|
583
|
+
new GlobalSwitchRequestTransformStream("SetGlobalSwitch")
|
|
625
584
|
],
|
|
626
585
|
output: [
|
|
627
586
|
new FilterTransformStream(isSetGlobalSwitchResponse)
|
|
@@ -632,4 +591,4 @@ class Connector {
|
|
|
632
591
|
}
|
|
633
592
|
}
|
|
634
593
|
}
|
|
635
|
-
export {
|
|
594
|
+
export { Connector, throwClientDiscoveryFailures };
|
package/dist/client-id.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A client address on a device.
|
|
3
|
-
*
|
|
4
|
-
* Numeric targets are debug-router TCP ports. String targets identify clients
|
|
5
|
-
* that are not reachable through a numeric port and are matched verbatim.
|
|
6
|
-
*/
|
|
7
1
|
export type ClientTarget = number | string;
|
|
8
2
|
export declare class ClientId {
|
|
9
3
|
static serialize(deviceId: string, target: ClientTarget): string;
|
package/dist/command/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CommandAction, CommandClient, CommandData, CommandObject, CommandParams, StreamCommandAction, StreamCommandEvent, StreamCommandParams } from
|
|
2
|
-
import { type CommandResult } from
|
|
1
|
+
import type { CommandAction, CommandClient, CommandData, CommandObject, CommandParams, StreamCommandAction, StreamCommandEvent, StreamCommandParams } from "./contract.js";
|
|
2
|
+
import { type CommandResult } from "./result.js";
|
|
3
3
|
export interface CommandCallOptions {
|
|
4
4
|
port?: number;
|
|
5
5
|
timeoutMs?: number;
|
|
@@ -9,7 +9,7 @@ export interface CommandStreamOptions {
|
|
|
9
9
|
port?: number;
|
|
10
10
|
signal?: AbortSignal;
|
|
11
11
|
ensureDaemon?: boolean;
|
|
12
|
-
method?:
|
|
12
|
+
method?: "GET" | "POST";
|
|
13
13
|
}
|
|
14
14
|
export declare function callRawCommand<T = unknown>(action: string, params: CommandObject, options?: CommandCallOptions): Promise<CommandResult<T>>;
|
|
15
15
|
export declare function callCommand<Action extends CommandAction>(action: Action, params: CommandParams<Action>, options?: CommandCallOptions): Promise<CommandResult<CommandData<Action>>>;
|
|
@@ -21,8 +21,9 @@ export declare class HttpCommandClient implements CommandClient {
|
|
|
21
21
|
port?: number;
|
|
22
22
|
ensureDaemon?: boolean;
|
|
23
23
|
});
|
|
24
|
-
execute<Action extends CommandAction>(action: Action, params: CommandParams<Action>, options?: Omit<CommandCallOptions,
|
|
25
|
-
stream<Action extends StreamCommandAction>(action: Action, params: StreamCommandParams<Action>, options?: Omit<CommandStreamOptions,
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
execute<Action extends CommandAction>(action: Action, params: CommandParams<Action>, options?: Omit<CommandCallOptions, "port" | "ensureDaemon">): Promise<CommandResult<CommandData<Action>>>;
|
|
25
|
+
stream<Action extends StreamCommandAction>(action: Action, params: StreamCommandParams<Action>, options?: Omit<CommandStreamOptions, "port" | "ensureDaemon">): AsyncGenerator<CommandResult<StreamCommandEvent<Action>>>;
|
|
26
|
+
protected ensureDaemonRunning(port: number): Promise<void>;
|
|
27
|
+
executeRaw<T = unknown>(action: string, params: CommandObject, options?: Omit<CommandCallOptions, "port" | "ensureDaemon">): Promise<CommandResult<T>>;
|
|
28
|
+
streamRaw<T = unknown>(action: string, params: CommandObject, options?: Omit<CommandStreamOptions, "port" | "ensureDaemon">): AsyncGenerator<CommandResult<T>>;
|
|
28
29
|
}
|