@ricsam/isolate 0.1.10 → 0.1.12
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 +257 -18
- package/dist/cjs/bridge/diagnostics.cjs +37 -2
- package/dist/cjs/bridge/diagnostics.cjs.map +3 -3
- package/dist/cjs/bridge/runtime-bindings.cjs +230 -51
- package/dist/cjs/bridge/runtime-bindings.cjs.map +3 -3
- package/dist/cjs/bridge/sandbox-isolate.cjs +464 -0
- package/dist/cjs/bridge/sandbox-isolate.cjs.map +10 -0
- package/dist/cjs/host/create-isolate-host.cjs +130 -25
- package/dist/cjs/host/create-isolate-host.cjs.map +3 -3
- package/dist/cjs/host/nested-host-controller.cjs +369 -0
- package/dist/cjs/host/nested-host-controller.cjs.map +10 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/internal/browser-source.cjs +102 -0
- package/dist/cjs/internal/browser-source.cjs.map +10 -0
- package/dist/cjs/internal/client/connection.cjs +163 -172
- package/dist/cjs/internal/client/connection.cjs.map +3 -3
- package/dist/cjs/internal/daemon/callback-fs-handler.cjs +3 -3
- package/dist/cjs/internal/daemon/callback-fs-handler.cjs.map +3 -3
- package/dist/cjs/internal/daemon/connection.cjs +156 -13
- package/dist/cjs/internal/daemon/connection.cjs.map +3 -3
- package/dist/cjs/internal/playwright/client.cjs +4 -2
- package/dist/cjs/internal/playwright/client.cjs.map +3 -3
- package/dist/cjs/internal/playwright/handler.cjs +298 -25
- package/dist/cjs/internal/playwright/handler.cjs.map +3 -3
- package/dist/cjs/internal/playwright/index.cjs +54 -8
- package/dist/cjs/internal/playwright/index.cjs.map +3 -3
- package/dist/cjs/internal/playwright/types.cjs +3 -1
- package/dist/cjs/internal/playwright/types.cjs.map +3 -3
- package/dist/cjs/internal/protocol/codec.cjs +16 -5
- package/dist/cjs/internal/protocol/codec.cjs.map +3 -3
- package/dist/cjs/internal/protocol/marshalValue.cjs +37 -6
- package/dist/cjs/internal/protocol/marshalValue.cjs.map +3 -3
- package/dist/cjs/internal/protocol/types.cjs +2 -1
- package/dist/cjs/internal/protocol/types.cjs.map +3 -3
- package/dist/cjs/internal/runtime/index.cjs +377 -22
- package/dist/cjs/internal/runtime/index.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/index.cjs +2 -1
- package/dist/cjs/internal/typecheck/index.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/isolate-types.cjs +218 -13
- package/dist/cjs/internal/typecheck/isolate-types.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/typecheck.cjs +2 -3
- package/dist/cjs/internal/typecheck/typecheck.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/playwright.cjs +76 -0
- package/dist/cjs/playwright.cjs.map +10 -0
- package/dist/cjs/runtime/namespaced-runtime.cjs +181 -0
- package/dist/cjs/runtime/namespaced-runtime.cjs.map +10 -0
- package/dist/cjs/runtime/script-runtime.cjs +14 -12
- package/dist/cjs/runtime/script-runtime.cjs.map +3 -3
- package/dist/cjs/runtime/test-runtime.cjs +113 -0
- package/dist/cjs/runtime/test-runtime.cjs.map +10 -0
- package/dist/cjs/server/app-server.cjs +16 -9
- package/dist/cjs/server/app-server.cjs.map +3 -3
- package/dist/cjs/typecheck/index.cjs +2 -1
- package/dist/cjs/typecheck/index.cjs.map +3 -3
- package/dist/mjs/bridge/diagnostics.mjs +37 -2
- package/dist/mjs/bridge/diagnostics.mjs.map +3 -3
- package/dist/mjs/bridge/runtime-bindings.mjs +233 -51
- package/dist/mjs/bridge/runtime-bindings.mjs.map +3 -3
- package/dist/mjs/bridge/sandbox-isolate.mjs +424 -0
- package/dist/mjs/bridge/sandbox-isolate.mjs.map +10 -0
- package/dist/mjs/host/create-isolate-host.mjs +132 -25
- package/dist/mjs/host/create-isolate-host.mjs.map +3 -3
- package/dist/mjs/host/nested-host-controller.mjs +333 -0
- package/dist/mjs/host/nested-host-controller.mjs.map +10 -0
- package/dist/mjs/index.mjs.map +1 -1
- package/dist/mjs/internal/browser-source.mjs +62 -0
- package/dist/mjs/internal/browser-source.mjs.map +10 -0
- package/dist/mjs/internal/client/connection.mjs +165 -173
- package/dist/mjs/internal/client/connection.mjs.map +3 -3
- package/dist/mjs/internal/daemon/callback-fs-handler.mjs +3 -3
- package/dist/mjs/internal/daemon/callback-fs-handler.mjs.map +3 -3
- package/dist/mjs/internal/daemon/connection.mjs +156 -13
- package/dist/mjs/internal/daemon/connection.mjs.map +3 -3
- package/dist/mjs/internal/playwright/client.mjs +7 -3
- package/dist/mjs/internal/playwright/client.mjs.map +3 -3
- package/dist/mjs/internal/playwright/handler.mjs +300 -26
- package/dist/mjs/internal/playwright/handler.mjs.map +3 -3
- package/dist/mjs/internal/playwright/index.mjs +59 -9
- package/dist/mjs/internal/playwright/index.mjs.map +3 -3
- package/dist/mjs/internal/playwright/types.mjs +3 -1
- package/dist/mjs/internal/playwright/types.mjs.map +3 -3
- package/dist/mjs/internal/protocol/codec.mjs +16 -5
- package/dist/mjs/internal/protocol/codec.mjs.map +3 -3
- package/dist/mjs/internal/protocol/marshalValue.mjs +38 -6
- package/dist/mjs/internal/protocol/marshalValue.mjs.map +3 -3
- package/dist/mjs/internal/protocol/types.mjs +2 -1
- package/dist/mjs/internal/protocol/types.mjs.map +3 -3
- package/dist/mjs/internal/runtime/index.mjs +377 -22
- package/dist/mjs/internal/runtime/index.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/index.mjs +3 -1
- package/dist/mjs/internal/typecheck/index.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/isolate-types.mjs +218 -13
- package/dist/mjs/internal/typecheck/isolate-types.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/typecheck.mjs +2 -3
- package/dist/mjs/internal/typecheck/typecheck.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/playwright.mjs +47 -0
- package/dist/mjs/playwright.mjs.map +10 -0
- package/dist/mjs/runtime/namespaced-runtime.mjs +143 -0
- package/dist/mjs/runtime/namespaced-runtime.mjs.map +10 -0
- package/dist/mjs/runtime/script-runtime.mjs +16 -12
- package/dist/mjs/runtime/script-runtime.mjs.map +3 -3
- package/dist/mjs/runtime/test-runtime.mjs +78 -0
- package/dist/mjs/runtime/test-runtime.mjs.map +10 -0
- package/dist/mjs/server/app-server.mjs +23 -11
- package/dist/mjs/server/app-server.mjs.map +3 -3
- package/dist/mjs/typecheck/index.mjs +2 -1
- package/dist/mjs/typecheck/index.mjs.map +3 -3
- package/dist/types/bridge/diagnostics.d.ts +6 -1
- package/dist/types/bridge/runtime-bindings.d.ts +5 -1
- package/dist/types/bridge/sandbox-isolate.d.ts +21 -0
- package/dist/types/host/nested-host-controller.d.ts +15 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internal/browser-source.d.ts +10 -0
- package/dist/types/internal/client/types.d.ts +9 -0
- package/dist/types/internal/daemon/types.d.ts +0 -2
- package/dist/types/internal/playwright/client.d.ts +2 -2
- package/dist/types/internal/playwright/handler.d.ts +27 -4
- package/dist/types/internal/playwright/index.d.ts +2 -2
- package/dist/types/internal/playwright/types.d.ts +33 -1
- package/dist/types/internal/protocol/codec.d.ts +12 -2
- package/dist/types/internal/protocol/marshalValue.d.ts +3 -2
- package/dist/types/internal/protocol/types.d.ts +33 -2
- package/dist/types/internal/runtime/index.d.ts +5 -0
- package/dist/types/internal/typecheck/index.d.ts +1 -1
- package/dist/types/internal/typecheck/isolate-types.d.ts +6 -4
- package/dist/types/internal/typecheck/typecheck.d.ts +1 -1
- package/dist/types/playwright.d.ts +26 -0
- package/dist/types/runtime/namespaced-runtime.d.ts +11 -0
- package/dist/types/runtime/script-runtime.d.ts +2 -1
- package/dist/types/runtime/test-runtime.d.ts +4 -0
- package/dist/types/server/app-server.d.ts +2 -1
- package/dist/types/types.d.ts +75 -33
- package/package.json +8 -3
- package/dist/cjs/browser/browser-runtime.cjs +0 -157
- package/dist/cjs/browser/browser-runtime.cjs.map +0 -10
- package/dist/mjs/browser/browser-runtime.mjs +0 -93
- package/dist/mjs/browser/browser-runtime.mjs.map +0 -10
- package/dist/types/browser/browser-runtime.d.ts +0 -3
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/bridge/sandbox-isolate.ts
|
|
40
|
+
var exports_sandbox_isolate = {};
|
|
41
|
+
__export(exports_sandbox_isolate, {
|
|
42
|
+
SANDBOX_ISOLATE_MODULE_SPECIFIER: () => SANDBOX_ISOLATE_MODULE_SPECIFIER,
|
|
43
|
+
SANDBOX_ISOLATE_MODULE_SOURCE: () => SANDBOX_ISOLATE_MODULE_SOURCE
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(exports_sandbox_isolate);
|
|
46
|
+
var import_browser_source = require("../internal/browser-source.cjs");
|
|
47
|
+
var SANDBOX_ISOLATE_MODULE_SPECIFIER = "@ricsam/isolate";
|
|
48
|
+
var SANDBOX_ISOLATE_MODULE_SOURCE = `
|
|
49
|
+
const __isolateBrowserDescriptorProperty = ${JSON.stringify(import_browser_source.ISOLATE_BROWSER_DESCRIPTOR_PROPERTY)};
|
|
50
|
+
|
|
51
|
+
function __normalizeBrowserHandle(value) {
|
|
52
|
+
if (
|
|
53
|
+
value &&
|
|
54
|
+
typeof value === "object" &&
|
|
55
|
+
value[__isolateBrowserDescriptorProperty]
|
|
56
|
+
) {
|
|
57
|
+
return {
|
|
58
|
+
[__isolateBrowserDescriptorProperty]: value[__isolateBrowserDescriptorProperty],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function __normalizeBindings(bindings) {
|
|
65
|
+
if (!bindings || typeof bindings !== "object") {
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const normalized = { ...bindings };
|
|
70
|
+
if ("browser" in normalized) {
|
|
71
|
+
normalized.browser = __normalizeBrowserHandle(normalized.browser);
|
|
72
|
+
}
|
|
73
|
+
return normalized;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function __normalizeRuntimeOptions(options) {
|
|
77
|
+
const normalized = options ? { ...options } : {};
|
|
78
|
+
normalized.bindings = __normalizeBindings(normalized.bindings);
|
|
79
|
+
return normalized;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function __normalizeNamespacedRuntimeOptions(key, options) {
|
|
83
|
+
return {
|
|
84
|
+
key,
|
|
85
|
+
options: __normalizeRuntimeOptions(options),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function __serializeRequest(requestLike) {
|
|
90
|
+
const request = requestLike instanceof Request
|
|
91
|
+
? requestLike
|
|
92
|
+
: new Request(requestLike);
|
|
93
|
+
const headers = [];
|
|
94
|
+
request.headers.forEach((value, key) => {
|
|
95
|
+
headers.push([key, value]);
|
|
96
|
+
});
|
|
97
|
+
let body = null;
|
|
98
|
+
if (request.body) {
|
|
99
|
+
const cloned = request.clone();
|
|
100
|
+
body = Array.from(new Uint8Array(await cloned.arrayBuffer()));
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
url: request.url,
|
|
104
|
+
method: request.method,
|
|
105
|
+
headers,
|
|
106
|
+
body,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function __normalizeEvalOptions(options) {
|
|
111
|
+
if (typeof options === "string") {
|
|
112
|
+
return { filename: options };
|
|
113
|
+
}
|
|
114
|
+
return options ?? null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function __waitForNestedCallbacks() {
|
|
118
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
class NestedScriptRuntime {
|
|
122
|
+
#resourceId;
|
|
123
|
+
|
|
124
|
+
constructor(resourceId) {
|
|
125
|
+
this.#resourceId = resourceId;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async eval(code, options) {
|
|
129
|
+
await __isolateHost_callResource(
|
|
130
|
+
"runtime",
|
|
131
|
+
this.#resourceId,
|
|
132
|
+
"eval",
|
|
133
|
+
[code, __normalizeEvalOptions(options)],
|
|
134
|
+
);
|
|
135
|
+
await __waitForNestedCallbacks();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async dispose(options) {
|
|
139
|
+
await __isolateHost_callResource(
|
|
140
|
+
"runtime",
|
|
141
|
+
this.#resourceId,
|
|
142
|
+
"dispose",
|
|
143
|
+
[options ?? null],
|
|
144
|
+
);
|
|
145
|
+
await __waitForNestedCallbacks();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async diagnostics() {
|
|
149
|
+
return await __isolateHost_callResource(
|
|
150
|
+
"runtime",
|
|
151
|
+
this.#resourceId,
|
|
152
|
+
"diagnostics",
|
|
153
|
+
[],
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
events = {
|
|
158
|
+
on: (event, handler) => {
|
|
159
|
+
const subscriptionPromise = __isolateHost_callResource(
|
|
160
|
+
"runtime",
|
|
161
|
+
this.#resourceId,
|
|
162
|
+
"events.on",
|
|
163
|
+
[event, handler],
|
|
164
|
+
);
|
|
165
|
+
return () => {
|
|
166
|
+
void subscriptionPromise
|
|
167
|
+
.then((subscriptionId) => __isolateHost_callResource(
|
|
168
|
+
"runtime",
|
|
169
|
+
this.#resourceId,
|
|
170
|
+
"events.off",
|
|
171
|
+
[subscriptionId],
|
|
172
|
+
))
|
|
173
|
+
.catch(() => {});
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
emit: async (event, payload) => {
|
|
177
|
+
await __isolateHost_callResource(
|
|
178
|
+
"runtime",
|
|
179
|
+
this.#resourceId,
|
|
180
|
+
"events.emit",
|
|
181
|
+
[event, payload],
|
|
182
|
+
);
|
|
183
|
+
await __waitForNestedCallbacks();
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
class NestedAppServer {
|
|
189
|
+
#resourceId;
|
|
190
|
+
|
|
191
|
+
constructor(resourceId) {
|
|
192
|
+
this.#resourceId = resourceId;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async handle(request, options) {
|
|
196
|
+
const serializedRequest = await __serializeRequest(request);
|
|
197
|
+
const result = await __isolateHost_callResource(
|
|
198
|
+
"appServer",
|
|
199
|
+
this.#resourceId,
|
|
200
|
+
"handle",
|
|
201
|
+
[
|
|
202
|
+
serializedRequest,
|
|
203
|
+
options
|
|
204
|
+
? {
|
|
205
|
+
requestId: options.requestId,
|
|
206
|
+
metadata: options.metadata,
|
|
207
|
+
}
|
|
208
|
+
: null,
|
|
209
|
+
],
|
|
210
|
+
);
|
|
211
|
+
await __waitForNestedCallbacks();
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
ws = {
|
|
216
|
+
open: async (connectionId) => {
|
|
217
|
+
await __isolateHost_callResource(
|
|
218
|
+
"appServer",
|
|
219
|
+
this.#resourceId,
|
|
220
|
+
"ws.open",
|
|
221
|
+
[connectionId],
|
|
222
|
+
);
|
|
223
|
+
await __waitForNestedCallbacks();
|
|
224
|
+
},
|
|
225
|
+
message: async (connectionId, data) => {
|
|
226
|
+
await __isolateHost_callResource(
|
|
227
|
+
"appServer",
|
|
228
|
+
this.#resourceId,
|
|
229
|
+
"ws.message",
|
|
230
|
+
[connectionId, data],
|
|
231
|
+
);
|
|
232
|
+
await __waitForNestedCallbacks();
|
|
233
|
+
},
|
|
234
|
+
close: async (connectionId, code, reason) => {
|
|
235
|
+
await __isolateHost_callResource(
|
|
236
|
+
"appServer",
|
|
237
|
+
this.#resourceId,
|
|
238
|
+
"ws.close",
|
|
239
|
+
[connectionId, code, reason],
|
|
240
|
+
);
|
|
241
|
+
await __waitForNestedCallbacks();
|
|
242
|
+
},
|
|
243
|
+
error: async (connectionId, error) => {
|
|
244
|
+
await __isolateHost_callResource(
|
|
245
|
+
"appServer",
|
|
246
|
+
this.#resourceId,
|
|
247
|
+
"ws.error",
|
|
248
|
+
[connectionId, error],
|
|
249
|
+
);
|
|
250
|
+
await __waitForNestedCallbacks();
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
async reload(reason) {
|
|
255
|
+
await __isolateHost_callResource(
|
|
256
|
+
"appServer",
|
|
257
|
+
this.#resourceId,
|
|
258
|
+
"reload",
|
|
259
|
+
[reason ?? null],
|
|
260
|
+
);
|
|
261
|
+
await __waitForNestedCallbacks();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async dispose(options) {
|
|
265
|
+
await __isolateHost_callResource(
|
|
266
|
+
"appServer",
|
|
267
|
+
this.#resourceId,
|
|
268
|
+
"dispose",
|
|
269
|
+
[options ?? null],
|
|
270
|
+
);
|
|
271
|
+
await __waitForNestedCallbacks();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async diagnostics() {
|
|
275
|
+
return await __isolateHost_callResource(
|
|
276
|
+
"appServer",
|
|
277
|
+
this.#resourceId,
|
|
278
|
+
"diagnostics",
|
|
279
|
+
[],
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
class NestedTestRuntime {
|
|
285
|
+
#resourceId;
|
|
286
|
+
|
|
287
|
+
constructor(resourceId) {
|
|
288
|
+
this.#resourceId = resourceId;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async run(code, options) {
|
|
292
|
+
const result = await __isolateHost_callResource(
|
|
293
|
+
"testRuntime",
|
|
294
|
+
this.#resourceId,
|
|
295
|
+
"run",
|
|
296
|
+
[code, options ?? null],
|
|
297
|
+
);
|
|
298
|
+
await __waitForNestedCallbacks();
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
async diagnostics() {
|
|
303
|
+
return await __isolateHost_callResource(
|
|
304
|
+
"testRuntime",
|
|
305
|
+
this.#resourceId,
|
|
306
|
+
"diagnostics",
|
|
307
|
+
[],
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async dispose(options) {
|
|
312
|
+
await __isolateHost_callResource(
|
|
313
|
+
"testRuntime",
|
|
314
|
+
this.#resourceId,
|
|
315
|
+
"dispose",
|
|
316
|
+
[options ?? null],
|
|
317
|
+
);
|
|
318
|
+
await __waitForNestedCallbacks();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
class NestedNamespacedRuntime {
|
|
323
|
+
#resourceId;
|
|
324
|
+
|
|
325
|
+
constructor(resourceId) {
|
|
326
|
+
this.#resourceId = resourceId;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async eval(code, options) {
|
|
330
|
+
await __isolateHost_callResource(
|
|
331
|
+
"namespacedRuntime",
|
|
332
|
+
this.#resourceId,
|
|
333
|
+
"eval",
|
|
334
|
+
[code, __normalizeEvalOptions(options)],
|
|
335
|
+
);
|
|
336
|
+
await __waitForNestedCallbacks();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async runTests(code, options) {
|
|
340
|
+
const result = await __isolateHost_callResource(
|
|
341
|
+
"namespacedRuntime",
|
|
342
|
+
this.#resourceId,
|
|
343
|
+
"runTests",
|
|
344
|
+
[code, options ?? null],
|
|
345
|
+
);
|
|
346
|
+
await __waitForNestedCallbacks();
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async diagnostics() {
|
|
351
|
+
return await __isolateHost_callResource(
|
|
352
|
+
"namespacedRuntime",
|
|
353
|
+
this.#resourceId,
|
|
354
|
+
"diagnostics",
|
|
355
|
+
[],
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
async dispose(options) {
|
|
360
|
+
await __isolateHost_callResource(
|
|
361
|
+
"namespacedRuntime",
|
|
362
|
+
this.#resourceId,
|
|
363
|
+
"dispose",
|
|
364
|
+
[options ?? null],
|
|
365
|
+
);
|
|
366
|
+
await __waitForNestedCallbacks();
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
events = {
|
|
370
|
+
on: (event, handler) => {
|
|
371
|
+
const subscriptionPromise = __isolateHost_callResource(
|
|
372
|
+
"namespacedRuntime",
|
|
373
|
+
this.#resourceId,
|
|
374
|
+
"events.on",
|
|
375
|
+
[event, handler],
|
|
376
|
+
);
|
|
377
|
+
return () => {
|
|
378
|
+
void subscriptionPromise
|
|
379
|
+
.then((subscriptionId) => __isolateHost_callResource(
|
|
380
|
+
"namespacedRuntime",
|
|
381
|
+
this.#resourceId,
|
|
382
|
+
"events.off",
|
|
383
|
+
[subscriptionId],
|
|
384
|
+
))
|
|
385
|
+
.catch(() => {});
|
|
386
|
+
};
|
|
387
|
+
},
|
|
388
|
+
emit: async (event, payload) => {
|
|
389
|
+
await __isolateHost_callResource(
|
|
390
|
+
"namespacedRuntime",
|
|
391
|
+
this.#resourceId,
|
|
392
|
+
"events.emit",
|
|
393
|
+
[event, payload],
|
|
394
|
+
);
|
|
395
|
+
await __waitForNestedCallbacks();
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export function createIsolateHost() {
|
|
401
|
+
let hostIdPromise;
|
|
402
|
+
|
|
403
|
+
const ensureHostId = async () => {
|
|
404
|
+
if (!hostIdPromise) {
|
|
405
|
+
hostIdPromise = __isolateHost_createHost();
|
|
406
|
+
}
|
|
407
|
+
return await hostIdPromise;
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
return {
|
|
411
|
+
async createRuntime(options) {
|
|
412
|
+
const hostId = await ensureHostId();
|
|
413
|
+
const resourceId = await __isolateHost_createResource(
|
|
414
|
+
hostId,
|
|
415
|
+
"runtime",
|
|
416
|
+
__normalizeRuntimeOptions(options),
|
|
417
|
+
);
|
|
418
|
+
return new NestedScriptRuntime(resourceId);
|
|
419
|
+
},
|
|
420
|
+
async createAppServer(options) {
|
|
421
|
+
const hostId = await ensureHostId();
|
|
422
|
+
const resourceId = await __isolateHost_createResource(
|
|
423
|
+
hostId,
|
|
424
|
+
"appServer",
|
|
425
|
+
__normalizeRuntimeOptions(options),
|
|
426
|
+
);
|
|
427
|
+
return new NestedAppServer(resourceId);
|
|
428
|
+
},
|
|
429
|
+
async createTestRuntime(options) {
|
|
430
|
+
const hostId = await ensureHostId();
|
|
431
|
+
const resourceId = await __isolateHost_createResource(
|
|
432
|
+
hostId,
|
|
433
|
+
"testRuntime",
|
|
434
|
+
__normalizeRuntimeOptions(options),
|
|
435
|
+
);
|
|
436
|
+
return new NestedTestRuntime(resourceId);
|
|
437
|
+
},
|
|
438
|
+
async getNamespacedRuntime(key, options) {
|
|
439
|
+
const hostId = await ensureHostId();
|
|
440
|
+
const resourceId = await __isolateHost_createResource(
|
|
441
|
+
hostId,
|
|
442
|
+
"namespacedRuntime",
|
|
443
|
+
__normalizeNamespacedRuntimeOptions(key, options),
|
|
444
|
+
);
|
|
445
|
+
return new NestedNamespacedRuntime(resourceId);
|
|
446
|
+
},
|
|
447
|
+
async disposeNamespace(key, options) {
|
|
448
|
+
const hostId = await ensureHostId();
|
|
449
|
+
await __isolateHost_disposeNamespace(hostId, key, options ?? null);
|
|
450
|
+
await __waitForNestedCallbacks();
|
|
451
|
+
},
|
|
452
|
+
async diagnostics() {
|
|
453
|
+
return await __isolateHost_hostDiagnostics(await ensureHostId());
|
|
454
|
+
},
|
|
455
|
+
async close() {
|
|
456
|
+
const hostId = await ensureHostId();
|
|
457
|
+
await __isolateHost_closeHost(hostId);
|
|
458
|
+
await __waitForNestedCallbacks();
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
`;
|
|
463
|
+
|
|
464
|
+
//# debugId=F53DA3120369FC5164756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/bridge/sandbox-isolate.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { ISOLATE_BROWSER_DESCRIPTOR_PROPERTY } from \"../internal/browser-source.cjs\";\nimport type {\n CreateAppServerOptions,\n CreateNamespacedRuntimeOptions,\n CreateRuntimeOptions,\n CreateTestRuntimeOptions,\n HostCallContext,\n} from \"../types.cjs\";\n\nexport const SANDBOX_ISOLATE_MODULE_SPECIFIER = \"@ricsam/isolate\";\n\nexport type NestedResourceKind =\n | \"runtime\"\n | \"appServer\"\n | \"testRuntime\"\n | \"namespacedRuntime\";\n\nexport interface NestedHostBindings {\n createHost(context: HostCallContext): Promise<string>;\n closeHost(hostId: string, context: HostCallContext): Promise<void>;\n diagnostics(\n hostId: string,\n context: HostCallContext,\n ): Promise<{ runtimes: number; servers: number; connected: boolean }>;\n createResource(\n hostId: string,\n kind: NestedResourceKind,\n options:\n | CreateRuntimeOptions\n | CreateAppServerOptions\n | CreateTestRuntimeOptions\n | {\n key: string;\n options: CreateNamespacedRuntimeOptions;\n },\n context: HostCallContext,\n ): Promise<string>;\n disposeNamespace(\n hostId: string,\n key: string,\n options: { reason?: string } | undefined,\n context: HostCallContext,\n ): Promise<void>;\n callResource(\n kind: NestedResourceKind,\n resourceId: string,\n method: string,\n args: unknown[],\n context: HostCallContext,\n ): Promise<unknown>;\n}\n\nexport const SANDBOX_ISOLATE_MODULE_SOURCE = `\nconst __isolateBrowserDescriptorProperty = ${JSON.stringify(ISOLATE_BROWSER_DESCRIPTOR_PROPERTY)};\n\nfunction __normalizeBrowserHandle(value) {\n if (\n value &&\n typeof value === \"object\" &&\n value[__isolateBrowserDescriptorProperty]\n ) {\n return {\n [__isolateBrowserDescriptorProperty]: value[__isolateBrowserDescriptorProperty],\n };\n }\n return value;\n}\n\nfunction __normalizeBindings(bindings) {\n if (!bindings || typeof bindings !== \"object\") {\n return {};\n }\n\n const normalized = { ...bindings };\n if (\"browser\" in normalized) {\n normalized.browser = __normalizeBrowserHandle(normalized.browser);\n }\n return normalized;\n}\n\nfunction __normalizeRuntimeOptions(options) {\n const normalized = options ? { ...options } : {};\n normalized.bindings = __normalizeBindings(normalized.bindings);\n return normalized;\n}\n\nfunction __normalizeNamespacedRuntimeOptions(key, options) {\n return {\n key,\n options: __normalizeRuntimeOptions(options),\n };\n}\n\nasync function __serializeRequest(requestLike) {\n const request = requestLike instanceof Request\n ? requestLike\n : new Request(requestLike);\n const headers = [];\n request.headers.forEach((value, key) => {\n headers.push([key, value]);\n });\n let body = null;\n if (request.body) {\n const cloned = request.clone();\n body = Array.from(new Uint8Array(await cloned.arrayBuffer()));\n }\n return {\n url: request.url,\n method: request.method,\n headers,\n body,\n };\n}\n\nfunction __normalizeEvalOptions(options) {\n if (typeof options === \"string\") {\n return { filename: options };\n }\n return options ?? null;\n}\n\nasync function __waitForNestedCallbacks() {\n await new Promise((resolve) => setTimeout(resolve, 0));\n}\n\nclass NestedScriptRuntime {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async eval(code, options) {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"eval\",\n [code, __normalizeEvalOptions(options)],\n );\n await __waitForNestedCallbacks();\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n\n events = {\n on: (event, handler) => {\n const subscriptionPromise = __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.on\",\n [event, handler],\n );\n return () => {\n void subscriptionPromise\n .then((subscriptionId) => __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.off\",\n [subscriptionId],\n ))\n .catch(() => {});\n };\n },\n emit: async (event, payload) => {\n await __isolateHost_callResource(\n \"runtime\",\n this.#resourceId,\n \"events.emit\",\n [event, payload],\n );\n await __waitForNestedCallbacks();\n },\n };\n}\n\nclass NestedAppServer {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async handle(request, options) {\n const serializedRequest = await __serializeRequest(request);\n const result = await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"handle\",\n [\n serializedRequest,\n options\n ? {\n requestId: options.requestId,\n metadata: options.metadata,\n }\n : null,\n ],\n );\n await __waitForNestedCallbacks();\n return result;\n }\n\n ws = {\n open: async (connectionId) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.open\",\n [connectionId],\n );\n await __waitForNestedCallbacks();\n },\n message: async (connectionId, data) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.message\",\n [connectionId, data],\n );\n await __waitForNestedCallbacks();\n },\n close: async (connectionId, code, reason) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.close\",\n [connectionId, code, reason],\n );\n await __waitForNestedCallbacks();\n },\n error: async (connectionId, error) => {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"ws.error\",\n [connectionId, error],\n );\n await __waitForNestedCallbacks();\n },\n };\n\n async reload(reason) {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"reload\",\n [reason ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"appServer\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n}\n\nclass NestedTestRuntime {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async run(code, options) {\n const result = await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"run\",\n [code, options ?? null],\n );\n await __waitForNestedCallbacks();\n return result;\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"testRuntime\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n}\n\nclass NestedNamespacedRuntime {\n #resourceId;\n\n constructor(resourceId) {\n this.#resourceId = resourceId;\n }\n\n async eval(code, options) {\n await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"eval\",\n [code, __normalizeEvalOptions(options)],\n );\n await __waitForNestedCallbacks();\n }\n\n async runTests(code, options) {\n const result = await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"runTests\",\n [code, options ?? null],\n );\n await __waitForNestedCallbacks();\n return result;\n }\n\n async diagnostics() {\n return await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"diagnostics\",\n [],\n );\n }\n\n async dispose(options) {\n await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"dispose\",\n [options ?? null],\n );\n await __waitForNestedCallbacks();\n }\n\n events = {\n on: (event, handler) => {\n const subscriptionPromise = __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"events.on\",\n [event, handler],\n );\n return () => {\n void subscriptionPromise\n .then((subscriptionId) => __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"events.off\",\n [subscriptionId],\n ))\n .catch(() => {});\n };\n },\n emit: async (event, payload) => {\n await __isolateHost_callResource(\n \"namespacedRuntime\",\n this.#resourceId,\n \"events.emit\",\n [event, payload],\n );\n await __waitForNestedCallbacks();\n },\n };\n}\n\nexport function createIsolateHost() {\n let hostIdPromise;\n\n const ensureHostId = async () => {\n if (!hostIdPromise) {\n hostIdPromise = __isolateHost_createHost();\n }\n return await hostIdPromise;\n };\n\n return {\n async createRuntime(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"runtime\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedScriptRuntime(resourceId);\n },\n async createAppServer(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"appServer\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedAppServer(resourceId);\n },\n async createTestRuntime(options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"testRuntime\",\n __normalizeRuntimeOptions(options),\n );\n return new NestedTestRuntime(resourceId);\n },\n async getNamespacedRuntime(key, options) {\n const hostId = await ensureHostId();\n const resourceId = await __isolateHost_createResource(\n hostId,\n \"namespacedRuntime\",\n __normalizeNamespacedRuntimeOptions(key, options),\n );\n return new NestedNamespacedRuntime(resourceId);\n },\n async disposeNamespace(key, options) {\n const hostId = await ensureHostId();\n await __isolateHost_disposeNamespace(hostId, key, options ?? null);\n await __waitForNestedCallbacks();\n },\n async diagnostics() {\n return await __isolateHost_hostDiagnostics(await ensureHostId());\n },\n async close() {\n const hostId = await ensureHostId();\n await __isolateHost_closeHost(hostId);\n await __waitForNestedCallbacks();\n },\n };\n}\n`;\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAoD,IAApD;AASO,IAAM,mCAAmC;AA2CzC,IAAM,gCAAgC;AAAA,6CACA,KAAK,UAAU,yDAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
8
|
+
"debugId": "F53DA3120369FC5164756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|