rsbuild-plugin-cloudflare 0.0.0-stage → 0.0.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/LICENSE +25 -0
- package/README.md +228 -2
- package/dist/chunk-53YJWLG7-_ps118Xl.mjs +43 -0
- package/dist/index.d.mts +123 -0
- package/dist/index.mjs +86790 -0
- package/dist/open-NPEHYJ5T-BP70Y_ly.mjs +530 -0
- package/dist/package--IFPzIbF.mjs +92 -0
- package/dist/workers/asset-worker/index.js +5997 -0
- package/dist/workers/asset-worker/index.js.map +1 -0
- package/dist/workers/router-worker/index.js +6415 -0
- package/dist/workers/router-worker/index.js.map +1 -0
- package/dist/workers/runner-worker/index.js +457 -0
- package/dist/workers/runner-worker/index.js.map +1 -0
- package/dist/workers/runner-worker/module-runner-legacy.js +1130 -0
- package/dist/workers/runner-worker/module-runner-legacy.js.map +1 -0
- package/dist/workers/runner-worker/module-runner.js +1260 -0
- package/dist/workers/runner-worker/module-runner.js.map +1 -0
- package/dist/workers/vite-proxy-worker/index.js +32 -0
- package/dist/workers/vite-proxy-worker/index.js.map +1 -0
- package/package.json +66 -3
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { DurableObject, WorkerEntrypoint, WorkflowEntrypoint } from "cloudflare:workers";
|
|
2
|
+
import { ModuleRunner, ssrDynamicImportKey, ssrModuleExportsKey } from "vite/module-runner";
|
|
3
|
+
|
|
4
|
+
//#region src/shared.ts
|
|
5
|
+
const UNKNOWN_HOST = "http://localhost";
|
|
6
|
+
const INIT_PATH = "/__vite_plugin_cloudflare_init__";
|
|
7
|
+
const GET_EXPORT_TYPES_PATH = "/__vite_plugin_cloudflare_get_export_types__";
|
|
8
|
+
const WORKER_ENTRY_PATH_HEADER = "__VITE_WORKER_ENTRY_PATH__";
|
|
9
|
+
const IS_ENTRY_WORKER_HEADER = "__VITE_IS_ENTRY_WORKER__";
|
|
10
|
+
const ENVIRONMENT_NAME_HEADER = "__VITE_ENVIRONMENT_NAME__";
|
|
11
|
+
const IS_PARENT_ENVIRONMENT_HEADER = "__VITE_IS_PARENT_ENVIRONMENT__";
|
|
12
|
+
const virtualPrefix = "virtual:cloudflare/";
|
|
13
|
+
const VIRTUAL_WORKER_ENTRY = `${virtualPrefix}worker-entry`;
|
|
14
|
+
const VIRTUAL_EXPORT_TYPES = `${virtualPrefix}export-types`;
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/workers/runner-worker/env.ts
|
|
18
|
+
/**
|
|
19
|
+
* Strips internal properties from the `env` object, returning only the user-defined properties.
|
|
20
|
+
* @param internalEnv - The full wrapper env, including internal properties
|
|
21
|
+
* @returns The user-defined env
|
|
22
|
+
*/
|
|
23
|
+
function stripInternalEnv(internalEnv) {
|
|
24
|
+
const { __VITE_RUNNER_OBJECT__: __VITE_RUNNER_OBJECT__$1, __VITE_INVOKE_MODULE__, __VITE_UNSAFE_EVAL__,...userEnv } = internalEnv;
|
|
25
|
+
return userEnv;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/workers/runner-worker/errors.ts
|
|
30
|
+
/**
|
|
31
|
+
* Converts an error to an object that can be be serialized and revived by Miniflare.
|
|
32
|
+
* Copied from `packages/wrangler/templates/middleware/middleware-miniflare3-json-error.ts`
|
|
33
|
+
*/
|
|
34
|
+
function reduceError(e) {
|
|
35
|
+
const errorObj = e ?? {};
|
|
36
|
+
return {
|
|
37
|
+
name: errorObj.name,
|
|
38
|
+
message: errorObj.message ?? String(e),
|
|
39
|
+
stack: errorObj.stack,
|
|
40
|
+
cause: errorObj.cause === void 0 ? void 0 : reduceError(errorObj.cause)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Captures errors in the `fetch` handler of the default export of the entry Worker.
|
|
45
|
+
* These are returned as a JSON response that is revived by Miniflare.
|
|
46
|
+
* See comment in `/packages/wrangler/src/deployment-bundle/bundle.ts` for more info.
|
|
47
|
+
*/
|
|
48
|
+
async function maybeCaptureError(options, fn) {
|
|
49
|
+
if (!options.isEntryWorker || options.exportName !== "default" || options.key !== "fetch") return fn();
|
|
50
|
+
try {
|
|
51
|
+
return await fn();
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return Response.json(reduceError(error), {
|
|
54
|
+
status: 500,
|
|
55
|
+
headers: { "MF-Experimental-Error-Stack": "true" }
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/workers/runner-worker/keys.ts
|
|
62
|
+
/** Keys that should be ignored during RPC property access */
|
|
63
|
+
const IGNORED_KEYS = ["self"];
|
|
64
|
+
/** Available methods for `WorkerEntrypoint` class */
|
|
65
|
+
const WORKER_ENTRYPOINT_KEYS = [
|
|
66
|
+
"connect",
|
|
67
|
+
"email",
|
|
68
|
+
"fetch",
|
|
69
|
+
"queue",
|
|
70
|
+
"tail",
|
|
71
|
+
"tailStream",
|
|
72
|
+
"test",
|
|
73
|
+
"trace",
|
|
74
|
+
"scheduled"
|
|
75
|
+
];
|
|
76
|
+
/** Available methods for `DurableObject` class */
|
|
77
|
+
const DURABLE_OBJECT_KEYS = [
|
|
78
|
+
"alarm",
|
|
79
|
+
"connect",
|
|
80
|
+
"fetch",
|
|
81
|
+
"webSocketClose",
|
|
82
|
+
"webSocketError",
|
|
83
|
+
"webSocketMessage"
|
|
84
|
+
];
|
|
85
|
+
/** Available methods for `WorkflowEntrypoint` classes */
|
|
86
|
+
const WORKFLOW_ENTRYPOINT_KEYS = ["run"];
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/workers/runner-worker/module-runner.ts
|
|
90
|
+
/** Module runner instances keyed by environment name */
|
|
91
|
+
const moduleRunners = /* @__PURE__ */ new Map();
|
|
92
|
+
/** The parent environment name (set explicitly via IS_PARENT_ENVIRONMENT_HEADER) */
|
|
93
|
+
let parentEnvironmentName;
|
|
94
|
+
let nextCallbackId = 0;
|
|
95
|
+
const pendingCallbacks = /* @__PURE__ */ new Map();
|
|
96
|
+
const callbackResults = /* @__PURE__ */ new Map();
|
|
97
|
+
/**
|
|
98
|
+
* Executes a callback in the runner Durable Object's IoContext via RPC + shared memory.
|
|
99
|
+
* The callback function is stored in a module-scope map (shared with the DO
|
|
100
|
+
* since both run in the same V8 isolate). Only a numeric ID crosses the RPC
|
|
101
|
+
* boundary.
|
|
102
|
+
*/
|
|
103
|
+
async function runInRunnerObject(env, callback) {
|
|
104
|
+
const id = nextCallbackId++;
|
|
105
|
+
pendingCallbacks.set(id, callback);
|
|
106
|
+
try {
|
|
107
|
+
await env.__VITE_RUNNER_OBJECT__.get("singleton").executeCallback(id);
|
|
108
|
+
return callbackResults.get(id);
|
|
109
|
+
} finally {
|
|
110
|
+
pendingCallbacks.delete(id);
|
|
111
|
+
callbackResults.delete(id);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Durable Object that provides an IoContext for module evaluation and handles
|
|
116
|
+
* WebSocket communication with the Vite dev server.
|
|
117
|
+
*
|
|
118
|
+
* In workerd, a Durable Object has a single shared IoContext across all
|
|
119
|
+
* incoming events, so promises are freely shareable within the DO without
|
|
120
|
+
* cross-context issues.
|
|
121
|
+
*/
|
|
122
|
+
var __VITE_RUNNER_OBJECT__ = class extends DurableObject {
|
|
123
|
+
/** Per-environment WebSockets */
|
|
124
|
+
#webSockets = /* @__PURE__ */ new Map();
|
|
125
|
+
/**
|
|
126
|
+
* Creates a WebSocket pair for communication with the Vite dev server and initializes the ModuleRunner.
|
|
127
|
+
*/
|
|
128
|
+
async fetch(request) {
|
|
129
|
+
const { pathname } = new URL(request.url);
|
|
130
|
+
if (pathname !== INIT_PATH) throw new Error(`__VITE_RUNNER_OBJECT__ received invalid pathname: "${pathname}"`);
|
|
131
|
+
const environmentName = request.headers.get(ENVIRONMENT_NAME_HEADER);
|
|
132
|
+
if (!environmentName) throw new Error(`__VITE_RUNNER_OBJECT__ received request without "${ENVIRONMENT_NAME_HEADER}" header`);
|
|
133
|
+
if (moduleRunners.has(environmentName)) throw new Error(`Module runner already initialized for environment: "${environmentName}"`);
|
|
134
|
+
if (request.headers.get(IS_PARENT_ENVIRONMENT_HEADER) === "true") {
|
|
135
|
+
parentEnvironmentName = environmentName;
|
|
136
|
+
globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__ = async (envName, id) => {
|
|
137
|
+
const runner = moduleRunners.get(envName);
|
|
138
|
+
if (!runner) throw new Error(`Module runner not initialized for environment: "${envName}". Do you need to set \`childEnvironments: ["${envName}"]\` in the plugin config?`);
|
|
139
|
+
return runInRunnerObject(this.env, () => runner.import(id));
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const { 0: client, 1: server } = new WebSocketPair();
|
|
143
|
+
server.accept();
|
|
144
|
+
const moduleRunner = await createModuleRunner(this.env, server, environmentName);
|
|
145
|
+
moduleRunners.set(environmentName, moduleRunner);
|
|
146
|
+
this.#webSockets.set(environmentName, server);
|
|
147
|
+
return new Response(null, {
|
|
148
|
+
status: 101,
|
|
149
|
+
webSocket: client
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Sends data to the Vite dev server via the WebSocket for a specific environment.
|
|
154
|
+
*/
|
|
155
|
+
send(environmentName, data) {
|
|
156
|
+
const webSocket = this.#webSockets.get(environmentName);
|
|
157
|
+
if (!webSocket) throw new Error(`Module runner not initialized for environment: "${environmentName}"`);
|
|
158
|
+
webSocket.send(data);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Executes a callback stored in the module-scope `pendingCallbacks` map.
|
|
162
|
+
* The callback runs in the DO's IoContext, ensuring all promises created
|
|
163
|
+
* during execution belong to the DO's shared context.
|
|
164
|
+
*/
|
|
165
|
+
async executeCallback(id) {
|
|
166
|
+
const callback = pendingCallbacks.get(id);
|
|
167
|
+
if (!callback) throw new Error(`No pending callback with id ${id}`);
|
|
168
|
+
const result = await callback();
|
|
169
|
+
callbackResults.set(id, result);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Creates a new module runner instance with a WebSocket transport.
|
|
174
|
+
* @param env - The wrapper env
|
|
175
|
+
* @param webSocket - WebSocket connection for communication with Vite dev server
|
|
176
|
+
* @param environmentName - The name of the environment this runner is for
|
|
177
|
+
* @returns Configured module runner instance
|
|
178
|
+
*/
|
|
179
|
+
async function createModuleRunner(env, webSocket, environmentName) {
|
|
180
|
+
return new ModuleRunner({
|
|
181
|
+
sourcemapInterceptor: "prepareStackTrace",
|
|
182
|
+
transport: {
|
|
183
|
+
connect({ onMessage }) {
|
|
184
|
+
webSocket.addEventListener("message", async ({ data }) => {
|
|
185
|
+
onMessage(JSON.parse(data.toString()));
|
|
186
|
+
});
|
|
187
|
+
onMessage({
|
|
188
|
+
type: "custom",
|
|
189
|
+
event: "vite:ws:connect",
|
|
190
|
+
data: { webSocket }
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
disconnect() {
|
|
194
|
+
webSocket.close();
|
|
195
|
+
},
|
|
196
|
+
send(data) {
|
|
197
|
+
env.__VITE_RUNNER_OBJECT__.get("singleton").send(environmentName, JSON.stringify(data));
|
|
198
|
+
},
|
|
199
|
+
async invoke(data) {
|
|
200
|
+
let lastError;
|
|
201
|
+
for (let attempt = 0; attempt < 3; attempt++) try {
|
|
202
|
+
return await (await env.__VITE_INVOKE_MODULE__.fetch(new Request(UNKNOWN_HOST, {
|
|
203
|
+
method: "POST",
|
|
204
|
+
headers: { [ENVIRONMENT_NAME_HEADER]: environmentName },
|
|
205
|
+
body: JSON.stringify(data)
|
|
206
|
+
}))).json();
|
|
207
|
+
} catch (error) {
|
|
208
|
+
lastError = error;
|
|
209
|
+
}
|
|
210
|
+
throw lastError;
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
hmr: true
|
|
214
|
+
}, {
|
|
215
|
+
async runInlinedModule(context, transformed, module) {
|
|
216
|
+
const originalDynamicImport = context[ssrDynamicImportKey];
|
|
217
|
+
context[ssrDynamicImportKey] = (dep) => {
|
|
218
|
+
return runInRunnerObject(env, () => originalDynamicImport(dep));
|
|
219
|
+
};
|
|
220
|
+
const code = `"use strict";async (${Object.keys(context).join(",")})=>{${transformed}\n}`;
|
|
221
|
+
await env.__VITE_UNSAFE_EVAL__.eval(code, module.id)(...Object.values(context));
|
|
222
|
+
Object.seal(context[ssrModuleExportsKey]);
|
|
223
|
+
},
|
|
224
|
+
async runExternalModule(filepath) {
|
|
225
|
+
if (filepath === "cloudflare:workers") {
|
|
226
|
+
const originalCloudflareWorkersModule = await import("cloudflare:workers");
|
|
227
|
+
return Object.seal({
|
|
228
|
+
...originalCloudflareWorkersModule,
|
|
229
|
+
env: stripInternalEnv(originalCloudflareWorkersModule.env)
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return import(filepath);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Retrieves a specific export from a Worker entry module using the module runner.
|
|
238
|
+
*/
|
|
239
|
+
async function getWorkerEntryExport(workerEntryPath$1, exportName) {
|
|
240
|
+
if (!parentEnvironmentName) throw new Error(`Parent environment not initialized`);
|
|
241
|
+
const module = await globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__(parentEnvironmentName, VIRTUAL_WORKER_ENTRY);
|
|
242
|
+
const exportValue = typeof module === "object" && module !== null && exportName in module && module[exportName];
|
|
243
|
+
if (!exportValue) throw new Error(`"${workerEntryPath$1}" does not define a "${exportName}" export.`);
|
|
244
|
+
return exportValue;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Retrieves the export types of the Worker entry module.
|
|
248
|
+
*/
|
|
249
|
+
async function getWorkerEntryExportTypes() {
|
|
250
|
+
if (!parentEnvironmentName) throw new Error(`Parent environment not initialized`);
|
|
251
|
+
const { getExportTypes } = await globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__(parentEnvironmentName, VIRTUAL_EXPORT_TYPES);
|
|
252
|
+
return getExportTypes(await globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__(parentEnvironmentName, VIRTUAL_WORKER_ENTRY));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/workers/runner-worker/index.ts
|
|
257
|
+
/** The path to the Worker entry file. We store it in the module scope so that it is easily accessible in error messages etc.. */
|
|
258
|
+
let workerEntryPath = "";
|
|
259
|
+
let isEntryWorker = false;
|
|
260
|
+
/**
|
|
261
|
+
* Creates a callable thenable that is used to access the properties of an RPC target.
|
|
262
|
+
* It can be both awaited and invoked as a function.
|
|
263
|
+
* This enables RPC properties to be used both as promises and callable functions.
|
|
264
|
+
* @param key - The property key name used for error messages
|
|
265
|
+
* @param property - The promise that resolves to the property value
|
|
266
|
+
* @returns A callable thenable that implements both Promise and function interfaces
|
|
267
|
+
*/
|
|
268
|
+
function getRpcPropertyCallableThenable(key, property) {
|
|
269
|
+
const fn = async function(...args) {
|
|
270
|
+
const maybeFn = await property;
|
|
271
|
+
if (typeof maybeFn !== "function") throw new TypeError(`"${key}" is not a function.`);
|
|
272
|
+
return maybeFn(...args);
|
|
273
|
+
};
|
|
274
|
+
fn.then = (onFulfilled, onRejected) => property.then(onFulfilled, onRejected);
|
|
275
|
+
fn.catch = (onRejected) => property.catch(onRejected);
|
|
276
|
+
fn.finally = (onFinally) => property.finally(onFinally);
|
|
277
|
+
return fn;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Retrieves an RPC property from a constructor prototype, ensuring it exists on the prototype rather than the instance to maintain RPC compatibility.
|
|
281
|
+
* @param ctor - The constructor function (`WorkerEntrypoint` or `DurableObject`)
|
|
282
|
+
* @param instance - The instance to bind methods to
|
|
283
|
+
* @param key - The property key to retrieve
|
|
284
|
+
* @returns The property value from the prototype
|
|
285
|
+
* @throws TypeError if the property doesn't exist on the prototype
|
|
286
|
+
*/
|
|
287
|
+
function getRpcProperty(ctor, instance, key) {
|
|
288
|
+
if (!Reflect.has(ctor.prototype, key)) {
|
|
289
|
+
if (Reflect.has(instance, key)) throw new TypeError([
|
|
290
|
+
`The RPC receiver's prototype does not implement "${key}", but the receiver instance does.`,
|
|
291
|
+
"Only properties and methods defined on the prototype can be accessed over RPC.",
|
|
292
|
+
`Ensure properties are declared as \`get ${key}() { ... }\` instead of \`${key} = ...\`,`,
|
|
293
|
+
`and methods are declared as \`${key}() { ... }\` instead of \`${key} = () => { ... }\`.`
|
|
294
|
+
].join("\n"));
|
|
295
|
+
throw new TypeError(`The RPC receiver does not implement "${key}".`);
|
|
296
|
+
}
|
|
297
|
+
return Reflect.get(ctor.prototype, key, instance);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Retrieves an RPC property from a `WorkerEntrypoint` export, creating an instance and returning the bound method or property value.
|
|
301
|
+
* @param exportName - The name of the `WorkerEntrypoint` export
|
|
302
|
+
* @param key - The property key to access on the `WorkerEntrypoint` instance
|
|
303
|
+
* @returns The property value, with methods bound to the instance
|
|
304
|
+
* @throws TypeError if the export is not a `WorkerEntrypoint` subclass
|
|
305
|
+
*/
|
|
306
|
+
async function getWorkerEntrypointRpcProperty(exportName, key) {
|
|
307
|
+
const ctor = await getWorkerEntryExport(workerEntryPath, exportName);
|
|
308
|
+
const userEnv = stripInternalEnv(this.env);
|
|
309
|
+
const expectedWorkerEntrypointMessage = `Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`WorkerEntrypoint\` for RPC.`;
|
|
310
|
+
if (typeof ctor !== "function") throw new TypeError(expectedWorkerEntrypointMessage);
|
|
311
|
+
const instance = new ctor(this.ctx, userEnv);
|
|
312
|
+
if (!(instance instanceof WorkerEntrypoint)) throw new TypeError(expectedWorkerEntrypointMessage);
|
|
313
|
+
const value = getRpcProperty(ctor, instance, key);
|
|
314
|
+
if (typeof value === "function") return value.bind(instance);
|
|
315
|
+
return value;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Creates a proxy wrapper for `WorkerEntrypoint` classes that enables RPC functionality.
|
|
319
|
+
* The wrapper intercepts property access and delegates to the user code, handling both direct method calls and RPC property access.
|
|
320
|
+
* @param exportName - The name of the `WorkerEntrypoint` export to wrap
|
|
321
|
+
* @returns A `WorkerEntrypoint` constructor that acts as a proxy to the user code
|
|
322
|
+
*/
|
|
323
|
+
function createWorkerEntrypointWrapper(exportName) {
|
|
324
|
+
class Wrapper extends WorkerEntrypoint {
|
|
325
|
+
constructor(ctx, env) {
|
|
326
|
+
super(ctx, env);
|
|
327
|
+
return new Proxy(this, { get(target, key, receiver) {
|
|
328
|
+
const value = Reflect.get(target, key, receiver);
|
|
329
|
+
if (value !== void 0) return value;
|
|
330
|
+
if (typeof key === "symbol" || IGNORED_KEYS.includes(key) || DURABLE_OBJECT_KEYS.includes(key)) return;
|
|
331
|
+
return getRpcPropertyCallableThenable(key, getWorkerEntrypointRpcProperty.call(receiver, exportName, key));
|
|
332
|
+
} });
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
for (const key of WORKER_ENTRYPOINT_KEYS) Wrapper.prototype[key] = async function(arg) {
|
|
336
|
+
return maybeCaptureError({
|
|
337
|
+
isEntryWorker,
|
|
338
|
+
exportName,
|
|
339
|
+
key
|
|
340
|
+
}, async () => {
|
|
341
|
+
if (key === "fetch") {
|
|
342
|
+
const request = arg;
|
|
343
|
+
const url = new URL(request.url);
|
|
344
|
+
if (url.pathname === INIT_PATH) {
|
|
345
|
+
if (request.headers.get(IS_PARENT_ENVIRONMENT_HEADER) === "true") {
|
|
346
|
+
const workerEntryPathHeader = request.headers.get(WORKER_ENTRY_PATH_HEADER);
|
|
347
|
+
if (!workerEntryPathHeader) throw new Error(`Unexpected error: "${WORKER_ENTRY_PATH_HEADER}" header not set.`);
|
|
348
|
+
const isEntryWorkerHeader = request.headers.get(IS_ENTRY_WORKER_HEADER);
|
|
349
|
+
if (!isEntryWorkerHeader) throw new Error(`Unexpected error: "${IS_ENTRY_WORKER_HEADER}" header not set.`);
|
|
350
|
+
workerEntryPath = decodeURIComponent(workerEntryPathHeader);
|
|
351
|
+
isEntryWorker = isEntryWorkerHeader === "true";
|
|
352
|
+
}
|
|
353
|
+
return this.env.__VITE_RUNNER_OBJECT__.get("singleton").fetch(request);
|
|
354
|
+
}
|
|
355
|
+
if (url.pathname === GET_EXPORT_TYPES_PATH) {
|
|
356
|
+
const workerEntryExportTypes = await getWorkerEntryExportTypes();
|
|
357
|
+
return Response.json(workerEntryExportTypes);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const exportValue = await getWorkerEntryExport(workerEntryPath, exportName);
|
|
361
|
+
const userEnv = stripInternalEnv(this.env);
|
|
362
|
+
if (typeof exportValue === "object" && exportValue !== null) {
|
|
363
|
+
const maybeFn = exportValue[key];
|
|
364
|
+
if (typeof maybeFn !== "function") throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to define a \`${key}()\` function.`);
|
|
365
|
+
return maybeFn.call(exportValue, arg, userEnv, this.ctx);
|
|
366
|
+
} else if (typeof exportValue === "function") {
|
|
367
|
+
const instance = new exportValue(this.ctx, userEnv);
|
|
368
|
+
if (!(instance instanceof WorkerEntrypoint)) throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`WorkerEntrypoint\`.`);
|
|
369
|
+
const maybeFn = instance[key];
|
|
370
|
+
if (typeof maybeFn !== "function") throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to define a \`${key}()\` method.`);
|
|
371
|
+
return maybeFn.call(instance, arg);
|
|
372
|
+
} else return /* @__PURE__ */ new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to be an object or a class.`);
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
return Wrapper;
|
|
376
|
+
}
|
|
377
|
+
/** Symbol key for storing the `DurableObject` instance */
|
|
378
|
+
const kInstance = Symbol("kInstance");
|
|
379
|
+
/** Symbol key for the instance initialization method */
|
|
380
|
+
const kEnsureInstance = Symbol("kEnsureInstance");
|
|
381
|
+
/**
|
|
382
|
+
* Retrieves an RPC property from a `DurableObject` export, ensuring an instance is properly initialized and returning the bound method or property value.
|
|
383
|
+
* @param exportName - The name of the `DurableObject` export
|
|
384
|
+
* @param key - The property key to access on the `DurableObject` instance
|
|
385
|
+
* @returns The property value, with methods bound to the instance
|
|
386
|
+
* @throws TypeError if the export is not a `DurableObject` subclass
|
|
387
|
+
*/
|
|
388
|
+
async function getDurableObjectRpcProperty(exportName, key) {
|
|
389
|
+
const { ctor, instance } = await this[kEnsureInstance]();
|
|
390
|
+
if (!(instance instanceof DurableObject)) throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`DurableObject\` for RPC.`);
|
|
391
|
+
const value = getRpcProperty(ctor, instance, key);
|
|
392
|
+
if (typeof value === "function") return value.bind(instance);
|
|
393
|
+
return value;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Creates a proxy wrapper for `DurableObject` classes that enables RPC functionality.
|
|
397
|
+
* The wrapper manages instance lifecycle and delegates method calls to the user code, handling both direct method calls and RPC property access.
|
|
398
|
+
* @param exportName - The name of the `DurableObject` export to wrap
|
|
399
|
+
* @returns A `DurableObject` constructor that acts as a proxy to the user code
|
|
400
|
+
*/
|
|
401
|
+
function createDurableObjectWrapper(exportName) {
|
|
402
|
+
class Wrapper extends DurableObject {
|
|
403
|
+
[kInstance];
|
|
404
|
+
constructor(ctx, env) {
|
|
405
|
+
super(ctx, env);
|
|
406
|
+
return new Proxy(this, { get(target, key, receiver) {
|
|
407
|
+
const value = Reflect.get(target, key, receiver);
|
|
408
|
+
if (value !== void 0) return value;
|
|
409
|
+
if (typeof key === "symbol" || IGNORED_KEYS.includes(key) || WORKER_ENTRYPOINT_KEYS.includes(key)) return;
|
|
410
|
+
return getRpcPropertyCallableThenable(key, getDurableObjectRpcProperty.call(receiver, exportName, key));
|
|
411
|
+
} });
|
|
412
|
+
}
|
|
413
|
+
async [kEnsureInstance]() {
|
|
414
|
+
const ctor = await getWorkerEntryExport(workerEntryPath, exportName);
|
|
415
|
+
if (typeof ctor !== "function") throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`DurableObject\`.`);
|
|
416
|
+
if (!this[kInstance] || this[kInstance].ctor !== ctor) {
|
|
417
|
+
const userEnv = stripInternalEnv(this.env);
|
|
418
|
+
this[kInstance] = {
|
|
419
|
+
ctor,
|
|
420
|
+
instance: new ctor(this.ctx, userEnv)
|
|
421
|
+
};
|
|
422
|
+
await this.ctx.blockConcurrencyWhile(async () => {});
|
|
423
|
+
}
|
|
424
|
+
return this[kInstance];
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
for (const key of DURABLE_OBJECT_KEYS) Wrapper.prototype[key] = async function(...args) {
|
|
428
|
+
const { instance } = await this[kEnsureInstance]();
|
|
429
|
+
const maybeFn = instance[key];
|
|
430
|
+
if (typeof maybeFn !== "function") throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to define a \`${key}()\` function.`);
|
|
431
|
+
return maybeFn.apply(instance, args);
|
|
432
|
+
};
|
|
433
|
+
return Wrapper;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Creates a proxy wrapper for `WorkflowEntrypoint` classes.
|
|
437
|
+
* The wrapper delegates method calls to the user code.
|
|
438
|
+
* @param exportName - The name of the `WorkflowEntrypoint` export to wrap
|
|
439
|
+
* @returns A `WorkflowEntrypoint` constructor that acts as a proxy to the user code
|
|
440
|
+
*/
|
|
441
|
+
function createWorkflowEntrypointWrapper(exportName) {
|
|
442
|
+
class Wrapper extends WorkflowEntrypoint {}
|
|
443
|
+
for (const key of WORKFLOW_ENTRYPOINT_KEYS) Wrapper.prototype[key] = async function(...args) {
|
|
444
|
+
const ctor = await getWorkerEntryExport(workerEntryPath, exportName);
|
|
445
|
+
const userEnv = stripInternalEnv(this.env);
|
|
446
|
+
const instance = new ctor(this.ctx, userEnv);
|
|
447
|
+
if (!(instance instanceof WorkflowEntrypoint)) throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to be a subclass of \`WorkflowEntrypoint\`.`);
|
|
448
|
+
const maybeFn = instance[key];
|
|
449
|
+
if (typeof maybeFn !== "function") throw new TypeError(`Expected "${exportName}" export of "${workerEntryPath}" to define a \`${key}()\` function.`);
|
|
450
|
+
return maybeFn.apply(instance, args);
|
|
451
|
+
};
|
|
452
|
+
return Wrapper;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
//#endregion
|
|
456
|
+
export { __VITE_RUNNER_OBJECT__, createDurableObjectWrapper, createWorkerEntrypointWrapper, createWorkflowEntrypointWrapper };
|
|
457
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["parentEnvironmentName: string | undefined","#webSockets","lastError: unknown","workerEntryPath"],"sources":["../../../src/shared.ts","../../../src/workers/runner-worker/env.ts","../../../src/workers/runner-worker/errors.ts","../../../src/workers/runner-worker/keys.ts","../../../src/workers/runner-worker/module-runner.ts","../../../src/workers/runner-worker/index.ts"],"sourcesContent":["export const UNKNOWN_HOST = \"http://localhost\";\n\n// pathnames\nexport const INIT_PATH = \"/__vite_plugin_cloudflare_init__\";\nexport const GET_EXPORT_TYPES_PATH =\n\t\"/__vite_plugin_cloudflare_get_export_types__\";\n\n// headers\nexport const WORKER_ENTRY_PATH_HEADER = \"__VITE_WORKER_ENTRY_PATH__\";\nexport const IS_ENTRY_WORKER_HEADER = \"__VITE_IS_ENTRY_WORKER__\";\nexport const ENVIRONMENT_NAME_HEADER = \"__VITE_ENVIRONMENT_NAME__\";\nexport const IS_PARENT_ENVIRONMENT_HEADER = \"__VITE_IS_PARENT_ENVIRONMENT__\";\n\n// virtual modules\nexport const virtualPrefix = \"virtual:cloudflare/\";\nexport const VIRTUAL_WORKER_ENTRY = `${virtualPrefix}worker-entry`;\nexport const VIRTUAL_EXPORT_TYPES = `${virtualPrefix}export-types`;\n","import type { __VITE_RUNNER_OBJECT__ } from \"./module-runner\";\n\n/**\n * Env type that includes both user-defined properties and properties required for internal use\n */\nexport interface WrapperEnv {\n\t/** Durable Object binding for the Vite module runner */\n\t__VITE_RUNNER_OBJECT__: { get(id: \"singleton\"): __VITE_RUNNER_OBJECT__ };\n\t/** Service binding for fetching modules from the Vite dev server */\n\t__VITE_INVOKE_MODULE__: {\n\t\tfetch: (request: Request) => Promise<Response>;\n\t};\n\t/** Binding for evaluating code */\n\t__VITE_UNSAFE_EVAL__: {\n\t\teval: (code: string, filename: string) => (...args: unknown[]) => unknown;\n\t};\n\t/** User-defined env */\n\t[key: string]: unknown;\n}\n\n/**\n * Strips internal properties from the `env` object, returning only the user-defined properties.\n * @param internalEnv - The full wrapper env, including internal properties\n * @returns The user-defined env\n */\nexport function stripInternalEnv(internalEnv: WrapperEnv) {\n\tconst {\n\t\t__VITE_RUNNER_OBJECT__,\n\t\t__VITE_INVOKE_MODULE__,\n\t\t__VITE_UNSAFE_EVAL__,\n\t\t...userEnv\n\t} = internalEnv;\n\n\treturn userEnv;\n}\n","// Note: the approach used here has the following implications:\n// - Errors that occur in named entrypoints, auxiliary Workers etc. will display in stack traces as occurring in the default export of the entry Worker\n// - If an error occurs in a named entrypoint or auxiliary Worker and the `fetch` handler in the default export of the entry Worker returns the response from the binding directly then the stack trace will be incorrect\n\n/**\n * Converts an error to an object that can be be serialized and revived by Miniflare.\n * Copied from `packages/wrangler/templates/middleware/middleware-miniflare3-json-error.ts`\n */\nfunction reduceError(e: unknown): unknown {\n\tconst errorObj = (e ?? {}) as Record<string, unknown>;\n\treturn {\n\t\tname: errorObj.name,\n\t\tmessage: errorObj.message ?? String(e),\n\t\tstack: errorObj.stack,\n\t\tcause:\n\t\t\terrorObj.cause === undefined ? undefined : reduceError(errorObj.cause),\n\t};\n}\n\n/**\n * Captures errors in the `fetch` handler of the default export of the entry Worker.\n * These are returned as a JSON response that is revived by Miniflare.\n * See comment in `/packages/wrangler/src/deployment-bundle/bundle.ts` for more info.\n */\nexport async function maybeCaptureError<T>(\n\toptions: { isEntryWorker: boolean; key: string; exportName: string },\n\tfn: () => T\n) {\n\tif (\n\t\t!options.isEntryWorker ||\n\t\toptions.exportName !== \"default\" ||\n\t\toptions.key !== \"fetch\"\n\t) {\n\t\treturn fn();\n\t}\n\n\ttry {\n\t\treturn await fn();\n\t} catch (error) {\n\t\treturn Response.json(reduceError(error), {\n\t\t\tstatus: 500,\n\t\t\theaders: { \"MF-Experimental-Error-Stack\": \"true\" },\n\t\t});\n\t}\n}\n","import type {\n\tDurableObject,\n\tWorkerEntrypoint,\n\tWorkflowEntrypoint,\n} from \"cloudflare:workers\";\n\n/** Keys that should be ignored during RPC property access */\nexport const IGNORED_KEYS = [\"self\"] as const;\n\n/** Available methods for `WorkerEntrypoint` class */\nexport const WORKER_ENTRYPOINT_KEYS = [\n\t\"connect\",\n\t\"email\",\n\t\"fetch\",\n\t\"queue\",\n\t\"tail\",\n\t\"tailStream\",\n\t\"test\",\n\t\"trace\",\n\t\"scheduled\",\n] as const;\n\n/** Available methods for `DurableObject` class */\nexport const DURABLE_OBJECT_KEYS = [\n\t\"alarm\",\n\t\"connect\",\n\t\"fetch\",\n\t\"webSocketClose\",\n\t\"webSocketError\",\n\t\"webSocketMessage\",\n] as const;\n\n/** Available methods for `WorkflowEntrypoint` classes */\nexport const WORKFLOW_ENTRYPOINT_KEYS = [\"run\"] as const;\n\n/**\n * This function is not used.\n * It is is included to check that we have included all the necessary keys.\n */\n// @ts-expect-error: function declaration only used to check types\nfunction _checkExhaustiveKeys() {\n\t// Remove branded keys\n\ttype UnbrandedKeys<T> = Exclude<keyof T, `__${string}_BRAND`>;\n\n\tconst _workerEntrypointExhaustive: (typeof WORKER_ENTRYPOINT_KEYS)[number] =\n\t\tundefined as unknown as UnbrandedKeys<WorkerEntrypoint>;\n\tconst _durableObjectExhaustive: (typeof DURABLE_OBJECT_KEYS)[number] =\n\t\tundefined as unknown as UnbrandedKeys<DurableObject>;\n\tconst _workflowEntrypointExhaustive: (typeof WORKFLOW_ENTRYPOINT_KEYS)[number] =\n\t\tundefined as unknown as UnbrandedKeys<WorkflowEntrypoint>;\n\n\t// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- these unused expressions are here to exercise the typechecker\n\t_workerEntrypointExhaustive ||\n\t\t_durableObjectExhaustive ||\n\t\t_workflowEntrypointExhaustive;\n}\n","import { DurableObject } from \"cloudflare:workers\";\nimport {\n\tModuleRunner,\n\tssrDynamicImportKey,\n\tssrModuleExportsKey,\n} from \"vite/module-runner\";\nimport {\n\tENVIRONMENT_NAME_HEADER,\n\tINIT_PATH,\n\tIS_PARENT_ENVIRONMENT_HEADER,\n\tUNKNOWN_HOST,\n\tVIRTUAL_EXPORT_TYPES,\n\tVIRTUAL_WORKER_ENTRY,\n} from \"../../shared\";\nimport { stripInternalEnv } from \"./env\";\nimport type { WrapperEnv } from \"./env\";\n\ndeclare global {\n\t// This global variable is accessed by `@vitejs/plugin-rsc`\n\tvar __VITE_ENVIRONMENT_RUNNER_IMPORT__: (\n\t\tenvironmentName: string,\n\t\tid: string\n\t) => Promise<unknown>;\n}\n\n/** Module runner instances keyed by environment name */\nconst moduleRunners = new Map<string, ModuleRunner>();\n\n/** The parent environment name (set explicitly via IS_PARENT_ENVIRONMENT_HEADER) */\nlet parentEnvironmentName: string | undefined;\n\nlet nextCallbackId = 0;\nconst pendingCallbacks = new Map<number, () => Promise<unknown>>();\nconst callbackResults = new Map<number, unknown>();\n\n/**\n * Executes a callback in the runner Durable Object's IoContext via RPC + shared memory.\n * The callback function is stored in a module-scope map (shared with the DO\n * since both run in the same V8 isolate). Only a numeric ID crosses the RPC\n * boundary.\n */\nasync function runInRunnerObject(\n\tenv: WrapperEnv,\n\tcallback: () => Promise<unknown>\n): Promise<unknown> {\n\tconst id = nextCallbackId++;\n\tpendingCallbacks.set(id, callback);\n\n\ttry {\n\t\tconst stub = env.__VITE_RUNNER_OBJECT__.get(\"singleton\");\n\t\tawait stub.executeCallback(id);\n\n\t\treturn callbackResults.get(id);\n\t} finally {\n\t\tpendingCallbacks.delete(id);\n\t\tcallbackResults.delete(id);\n\t}\n}\n\n/**\n * Durable Object that provides an IoContext for module evaluation and handles\n * WebSocket communication with the Vite dev server.\n *\n * In workerd, a Durable Object has a single shared IoContext across all\n * incoming events, so promises are freely shareable within the DO without\n * cross-context issues.\n */\nexport class __VITE_RUNNER_OBJECT__ extends DurableObject<WrapperEnv> {\n\t/** Per-environment WebSockets */\n\t#webSockets = new Map<string, WebSocket>();\n\n\t/**\n\t * Creates a WebSocket pair for communication with the Vite dev server and initializes the ModuleRunner.\n\t */\n\toverride async fetch(request: Request) {\n\t\tconst { pathname } = new URL(request.url);\n\n\t\tif (pathname !== INIT_PATH) {\n\t\t\tthrow new Error(\n\t\t\t\t`__VITE_RUNNER_OBJECT__ received invalid pathname: \"${pathname}\"`\n\t\t\t);\n\t\t}\n\n\t\tconst environmentName = request.headers.get(ENVIRONMENT_NAME_HEADER);\n\n\t\tif (!environmentName) {\n\t\t\tthrow new Error(\n\t\t\t\t`__VITE_RUNNER_OBJECT__ received request without \"${ENVIRONMENT_NAME_HEADER}\" header`\n\t\t\t);\n\t\t}\n\n\t\tif (moduleRunners.has(environmentName)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Module runner already initialized for environment: \"${environmentName}\"`\n\t\t\t);\n\t\t}\n\n\t\tconst isParentEnvironment =\n\t\t\trequest.headers.get(IS_PARENT_ENVIRONMENT_HEADER) === \"true\";\n\n\t\tif (isParentEnvironment) {\n\t\t\tparentEnvironmentName = environmentName;\n\n\t\t\tglobalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__ = async (\n\t\t\t\tenvName: string,\n\t\t\t\tid: string\n\t\t\t): Promise<unknown> => {\n\t\t\t\tconst runner = moduleRunners.get(envName);\n\n\t\t\t\tif (!runner) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Module runner not initialized for environment: \"${envName}\". Do you need to set \\`childEnvironments: [\"${envName}\"]\\` in the plugin config?`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn runInRunnerObject(this.env, () => runner.import(id));\n\t\t\t};\n\t\t}\n\n\t\tconst { 0: client, 1: server } = new WebSocketPair();\n\t\tserver.accept();\n\n\t\tconst moduleRunner = await createModuleRunner(\n\t\t\tthis.env,\n\t\t\tserver,\n\t\t\tenvironmentName\n\t\t);\n\n\t\tmoduleRunners.set(environmentName, moduleRunner);\n\t\tthis.#webSockets.set(environmentName, server);\n\n\t\treturn new Response(null, { status: 101, webSocket: client });\n\t}\n\n\t/**\n\t * Sends data to the Vite dev server via the WebSocket for a specific environment.\n\t */\n\tsend(environmentName: string, data: string): void {\n\t\tconst webSocket = this.#webSockets.get(environmentName);\n\n\t\tif (!webSocket) {\n\t\t\tthrow new Error(\n\t\t\t\t`Module runner not initialized for environment: \"${environmentName}\"`\n\t\t\t);\n\t\t}\n\n\t\twebSocket.send(data);\n\t}\n\n\t/**\n\t * Executes a callback stored in the module-scope `pendingCallbacks` map.\n\t * The callback runs in the DO's IoContext, ensuring all promises created\n\t * during execution belong to the DO's shared context.\n\t */\n\tasync executeCallback(id: number): Promise<void> {\n\t\tconst callback = pendingCallbacks.get(id);\n\n\t\tif (!callback) {\n\t\t\tthrow new Error(`No pending callback with id ${id}`);\n\t\t}\n\n\t\tconst result = await callback();\n\t\tcallbackResults.set(id, result);\n\t}\n}\n\n/**\n * Creates a new module runner instance with a WebSocket transport.\n * @param env - The wrapper env\n * @param webSocket - WebSocket connection for communication with Vite dev server\n * @param environmentName - The name of the environment this runner is for\n * @returns Configured module runner instance\n */\nasync function createModuleRunner(\n\tenv: WrapperEnv,\n\twebSocket: WebSocket,\n\tenvironmentName: string\n) {\n\treturn new ModuleRunner(\n\t\t{\n\t\t\tsourcemapInterceptor: \"prepareStackTrace\",\n\t\t\ttransport: {\n\t\t\t\tconnect({ onMessage }) {\n\t\t\t\t\twebSocket.addEventListener(\"message\", async ({ data }) => {\n\t\t\t\t\t\tonMessage(JSON.parse(data.toString()));\n\t\t\t\t\t});\n\n\t\t\t\t\tonMessage({\n\t\t\t\t\t\ttype: \"custom\",\n\t\t\t\t\t\tevent: \"vite:ws:connect\",\n\t\t\t\t\t\tdata: { webSocket },\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tdisconnect() {\n\t\t\t\t\twebSocket.close();\n\t\t\t\t},\n\t\t\t\tsend(data) {\n\t\t\t\t\t// We send messages via a binding to the Durable Object.\n\t\t\t\t\t// This is because `import.meta.send` may be called within a Worker's request context.\n\t\t\t\t\t// Directly using a WebSocket created in another context would be forbidden.\n\t\t\t\t\tconst stub = env.__VITE_RUNNER_OBJECT__.get(\"singleton\");\n\t\t\t\t\tstub.send(environmentName, JSON.stringify(data));\n\t\t\t\t},\n\t\t\t\tasync invoke(data) {\n\t\t\t\t\t// The fetch can fail transiently (e.g. the runtime reusing a\n\t\t\t\t\t// pooled connection to the loopback server just as it closes).\n\t\t\t\t\t// A failed invoke is cached by the module runner and poisons the\n\t\t\t\t\t// module graph for the rest of the session, so retry before\n\t\t\t\t\t// giving up. Invokes are idempotent requests for module code,\n\t\t\t\t\t// making retries safe.\n\t\t\t\t\tlet lastError: unknown;\n\n\t\t\t\t\tfor (let attempt = 0; attempt < 3; attempt++) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst response = await env.__VITE_INVOKE_MODULE__.fetch(\n\t\t\t\t\t\t\t\tnew Request(UNKNOWN_HOST, {\n\t\t\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t\t\t[ENVIRONMENT_NAME_HEADER]: environmentName,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tbody: JSON.stringify(data),\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconst result = await response.json();\n\n\t\t\t\t\t\t\treturn result as { result: unknown } | { error: unknown };\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tlastError = error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow lastError;\n\t\t\t\t},\n\t\t\t},\n\t\t\thmr: true,\n\t\t},\n\t\t{\n\t\t\tasync runInlinedModule(context, transformed, module) {\n\t\t\t\t// Wrap dynamic imports to route deferred dynamic imports\n\t\t\t\t// through the DO's IoContext.\n\t\t\t\tconst originalDynamicImport = context[ssrDynamicImportKey];\n\t\t\t\tcontext[ssrDynamicImportKey] = (dep) => {\n\t\t\t\t\treturn runInRunnerObject(env, () => originalDynamicImport(dep));\n\t\t\t\t};\n\n\t\t\t\t// The trailing newline ensures a `//` comment on the last line of\n\t\t\t\t// `transformed` (e.g. a sourceMappingURL comment preserved by\n\t\t\t\t// vite-plus) cannot swallow the closing brace.\n\t\t\t\tconst code = `\"use strict\";async (${Object.keys(context).join(\",\")})=>{${transformed}\\n}`;\n\t\t\t\tconst fn = env.__VITE_UNSAFE_EVAL__.eval(code, module.id);\n\t\t\t\tawait fn(...Object.values(context));\n\t\t\t\tObject.seal(context[ssrModuleExportsKey]);\n\t\t\t},\n\t\t\tasync runExternalModule(filepath) {\n\t\t\t\tif (filepath === \"cloudflare:workers\") {\n\t\t\t\t\tconst originalCloudflareWorkersModule =\n\t\t\t\t\t\tawait import(\"cloudflare:workers\");\n\n\t\t\t\t\treturn Object.seal({\n\t\t\t\t\t\t...originalCloudflareWorkersModule,\n\t\t\t\t\t\tenv: stripInternalEnv(\n\t\t\t\t\t\t\toriginalCloudflareWorkersModule.env as WrapperEnv\n\t\t\t\t\t\t),\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\treturn import(filepath);\n\t\t\t},\n\t\t}\n\t);\n}\n\n/**\n * Retrieves a specific export from a Worker entry module using the module runner.\n */\nexport async function getWorkerEntryExport(\n\tworkerEntryPath: string,\n\texportName: string\n): Promise<unknown> {\n\tif (!parentEnvironmentName) {\n\t\tthrow new Error(`Parent environment not initialized`);\n\t}\n\n\tconst module = await globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__(\n\t\tparentEnvironmentName,\n\t\tVIRTUAL_WORKER_ENTRY\n\t);\n\n\tconst exportValue =\n\t\ttypeof module === \"object\" &&\n\t\tmodule !== null &&\n\t\texportName in module &&\n\t\t(module as Record<string, unknown>)[exportName];\n\n\tif (!exportValue) {\n\t\tthrow new Error(\n\t\t\t`\"${workerEntryPath}\" does not define a \"${exportName}\" export.`\n\t\t);\n\t}\n\n\treturn exportValue;\n}\n\n/**\n * Retrieves the export types of the Worker entry module.\n */\nexport async function getWorkerEntryExportTypes() {\n\tif (!parentEnvironmentName) {\n\t\tthrow new Error(`Parent environment not initialized`);\n\t}\n\n\tconst { getExportTypes } =\n\t\t(await globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__(\n\t\t\tparentEnvironmentName,\n\t\t\tVIRTUAL_EXPORT_TYPES\n\t\t)) as { getExportTypes: (module: unknown) => unknown };\n\n\tconst module = await globalThis.__VITE_ENVIRONMENT_RUNNER_IMPORT__(\n\t\tparentEnvironmentName,\n\t\tVIRTUAL_WORKER_ENTRY\n\t);\n\n\treturn getExportTypes(module);\n}\n","import {\n\tDurableObject,\n\tWorkerEntrypoint,\n\tWorkflowEntrypoint,\n} from \"cloudflare:workers\";\nimport {\n\tGET_EXPORT_TYPES_PATH,\n\tINIT_PATH,\n\tIS_ENTRY_WORKER_HEADER,\n\tIS_PARENT_ENVIRONMENT_HEADER,\n\tWORKER_ENTRY_PATH_HEADER,\n} from \"../../shared\";\nimport { stripInternalEnv } from \"./env\";\nimport { maybeCaptureError } from \"./errors\";\nimport {\n\tDURABLE_OBJECT_KEYS,\n\tIGNORED_KEYS,\n\tWORKER_ENTRYPOINT_KEYS,\n\tWORKFLOW_ENTRYPOINT_KEYS,\n} from \"./keys\";\nimport {\n\tgetWorkerEntryExport,\n\tgetWorkerEntryExportTypes,\n} from \"./module-runner\";\nimport type { WrapperEnv } from \"./env\";\n\nexport { __VITE_RUNNER_OBJECT__ } from \"./module-runner\";\n\n/**\n * Constructor interface for `WorkerEntrypoint` class.\n * @template T - The `env` type\n */\ninterface WorkerEntrypointConstructor<T = Cloudflare.Env> {\n\tnew (\n\t\t...args: ConstructorParameters<typeof WorkerEntrypoint<T>>\n\t): WorkerEntrypoint<T>;\n}\n\n/**\n * Constructor interface for `DurableObject` class.\n * @template T - The `env` type\n */\ninterface DurableObjectConstructor<T = Cloudflare.Env> {\n\tnew (\n\t\t...args: ConstructorParameters<typeof DurableObject<T>>\n\t): DurableObject<T>;\n}\n\n/**\n * Constructor interface for `WorkflowEntrypoint` class.\n * @template T - The `env` type\n */\ninterface WorkflowEntrypointConstructor<T = Cloudflare.Env> {\n\tnew (\n\t\t...args: ConstructorParameters<typeof WorkflowEntrypoint<T>>\n\t): WorkflowEntrypoint<T>;\n}\n\n/** The path to the Worker entry file. We store it in the module scope so that it is easily accessible in error messages etc.. */\nlet workerEntryPath = \"\";\nlet isEntryWorker = false;\n\n/**\n * Creates a callable thenable that is used to access the properties of an RPC target.\n * It can be both awaited and invoked as a function.\n * This enables RPC properties to be used both as promises and callable functions.\n * @param key - The property key name used for error messages\n * @param property - The promise that resolves to the property value\n * @returns A callable thenable that implements both Promise and function interfaces\n */\nfunction getRpcPropertyCallableThenable(\n\tkey: string,\n\tproperty: Promise<unknown>\n): Promise<unknown> & ((...args: unknown[]) => Promise<unknown>) {\n\tconst fn = async function (...args: unknown[]) {\n\t\tconst maybeFn = await property;\n\n\t\tif (typeof maybeFn !== \"function\") {\n\t\t\tthrow new TypeError(`\"${key}\" is not a function.`);\n\t\t}\n\n\t\treturn maybeFn(...args);\n\t} as Promise<unknown> & ((...args: unknown[]) => Promise<unknown>);\n\n\tfn.then = (onFulfilled, onRejected) => property.then(onFulfilled, onRejected);\n\tfn.catch = (onRejected) => property.catch(onRejected);\n\tfn.finally = (onFinally) => property.finally(onFinally);\n\n\treturn fn;\n}\n\n/**\n * Retrieves an RPC property from a constructor prototype, ensuring it exists on the prototype rather than the instance to maintain RPC compatibility.\n * @param ctor - The constructor function (`WorkerEntrypoint` or `DurableObject`)\n * @param instance - The instance to bind methods to\n * @param key - The property key to retrieve\n * @returns The property value from the prototype\n * @throws TypeError if the property doesn't exist on the prototype\n */\nfunction getRpcProperty(\n\tctor: WorkerEntrypointConstructor | DurableObjectConstructor,\n\tinstance: WorkerEntrypoint | DurableObject,\n\tkey: string\n): unknown {\n\tconst prototypeHasKey = Reflect.has(ctor.prototype, key);\n\n\tif (!prototypeHasKey) {\n\t\tconst instanceHasKey = Reflect.has(instance, key);\n\n\t\tif (instanceHasKey) {\n\t\t\tthrow new TypeError(\n\t\t\t\t[\n\t\t\t\t\t`The RPC receiver's prototype does not implement \"${key}\", but the receiver instance does.`,\n\t\t\t\t\t\"Only properties and methods defined on the prototype can be accessed over RPC.\",\n\t\t\t\t\t`Ensure properties are declared as \\`get ${key}() { ... }\\` instead of \\`${key} = ...\\`,`,\n\t\t\t\t\t`and methods are declared as \\`${key}() { ... }\\` instead of \\`${key} = () => { ... }\\`.`,\n\t\t\t\t].join(\"\\n\")\n\t\t\t);\n\t\t}\n\n\t\tthrow new TypeError(`The RPC receiver does not implement \"${key}\".`);\n\t}\n\n\treturn Reflect.get(ctor.prototype, key, instance);\n}\n\n/**\n * Retrieves an RPC property from a `WorkerEntrypoint` export, creating an instance and returning the bound method or property value.\n * @param exportName - The name of the `WorkerEntrypoint` export\n * @param key - The property key to access on the `WorkerEntrypoint` instance\n * @returns The property value, with methods bound to the instance\n * @throws TypeError if the export is not a `WorkerEntrypoint` subclass\n */\nasync function getWorkerEntrypointRpcProperty(\n\tthis: WorkerEntrypoint<WrapperEnv>,\n\texportName: string,\n\tkey: string\n): Promise<unknown> {\n\tconst ctor = (await getWorkerEntryExport(\n\t\tworkerEntryPath,\n\t\texportName\n\t)) as WorkerEntrypointConstructor;\n\tconst userEnv = stripInternalEnv(this.env);\n\tconst expectedWorkerEntrypointMessage = `Expected \"${exportName}\" export of \"${workerEntryPath}\" to be a subclass of \\`WorkerEntrypoint\\` for RPC.`;\n\n\tif (typeof ctor !== \"function\") {\n\t\tthrow new TypeError(expectedWorkerEntrypointMessage);\n\t}\n\n\tconst instance = new ctor(this.ctx, userEnv);\n\n\tif (!(instance instanceof WorkerEntrypoint)) {\n\t\tthrow new TypeError(expectedWorkerEntrypointMessage);\n\t}\n\n\tconst value = getRpcProperty(ctor, instance, key);\n\n\tif (typeof value === \"function\") {\n\t\treturn value.bind(instance);\n\t}\n\n\treturn value;\n}\n\n/**\n * Creates a proxy wrapper for `WorkerEntrypoint` classes that enables RPC functionality.\n * The wrapper intercepts property access and delegates to the user code, handling both direct method calls and RPC property access.\n * @param exportName - The name of the `WorkerEntrypoint` export to wrap\n * @returns A `WorkerEntrypoint` constructor that acts as a proxy to the user code\n */\nexport function createWorkerEntrypointWrapper(\n\texportName: string\n): WorkerEntrypointConstructor<WrapperEnv> {\n\tclass Wrapper extends WorkerEntrypoint<WrapperEnv> {\n\t\tconstructor(ctx: ExecutionContext, env: WrapperEnv) {\n\t\t\tsuper(ctx, env);\n\n\t\t\treturn new Proxy(this, {\n\t\t\t\tget(target, key, receiver) {\n\t\t\t\t\tconst value = Reflect.get(target, key, receiver);\n\n\t\t\t\t\tif (value !== undefined) {\n\t\t\t\t\t\treturn value;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof key === \"symbol\" ||\n\t\t\t\t\t\t(IGNORED_KEYS as readonly string[]).includes(key) ||\n\t\t\t\t\t\t// The class methods are accessed to determine the type of the export.\n\t\t\t\t\t\t// We should therefore avoid proxying `DurableObject` methods on the `WorkerEntrypoint` class.\n\t\t\t\t\t\t(DURABLE_OBJECT_KEYS as readonly string[]).includes(key)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst property = getWorkerEntrypointRpcProperty.call(\n\t\t\t\t\t\treceiver,\n\t\t\t\t\t\texportName,\n\t\t\t\t\t\tkey\n\t\t\t\t\t);\n\n\t\t\t\t\treturn getRpcPropertyCallableThenable(key, property);\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\tfor (const key of WORKER_ENTRYPOINT_KEYS) {\n\t\tWrapper.prototype[key] = async function (arg) {\n\t\t\treturn maybeCaptureError({ isEntryWorker, exportName, key }, async () => {\n\t\t\t\tif (key === \"fetch\") {\n\t\t\t\t\tconst request = arg as Request;\n\t\t\t\t\tconst url = new URL(request.url);\n\n\t\t\t\t\t// Initialize the module runner\n\t\t\t\t\tif (url.pathname === INIT_PATH) {\n\t\t\t\t\t\tconst isParentEnvironmentHeader = request.headers.get(\n\t\t\t\t\t\t\tIS_PARENT_ENVIRONMENT_HEADER\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Only set Worker variables when initializing the parent environment\n\t\t\t\t\t\tif (isParentEnvironmentHeader === \"true\") {\n\t\t\t\t\t\t\tconst workerEntryPathHeader = request.headers.get(\n\t\t\t\t\t\t\t\tWORKER_ENTRY_PATH_HEADER\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (!workerEntryPathHeader) {\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`Unexpected error: \"${WORKER_ENTRY_PATH_HEADER}\" header not set.`\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst isEntryWorkerHeader = request.headers.get(\n\t\t\t\t\t\t\t\tIS_ENTRY_WORKER_HEADER\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (!isEntryWorkerHeader) {\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`Unexpected error: \"${IS_ENTRY_WORKER_HEADER}\" header not set.`\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tworkerEntryPath = decodeURIComponent(workerEntryPathHeader);\n\t\t\t\t\t\t\tisEntryWorker = isEntryWorkerHeader === \"true\";\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst stub = this.env.__VITE_RUNNER_OBJECT__.get(\"singleton\");\n\n\t\t\t\t\t\t// Forward the request to the Durable Object to initialize the module runner and return the WebSocket\n\t\t\t\t\t\treturn stub.fetch(request);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (url.pathname === GET_EXPORT_TYPES_PATH) {\n\t\t\t\t\t\tconst workerEntryExportTypes = await getWorkerEntryExportTypes();\n\n\t\t\t\t\t\treturn Response.json(workerEntryExportTypes);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst exportValue = await getWorkerEntryExport(\n\t\t\t\t\tworkerEntryPath,\n\t\t\t\t\texportName\n\t\t\t\t);\n\t\t\t\tconst userEnv = stripInternalEnv(this.env);\n\n\t\t\t\tif (typeof exportValue === \"object\" && exportValue !== null) {\n\t\t\t\t\t// The export is an `ExportedHandler`\n\t\t\t\t\tconst maybeFn = (exportValue as Record<string, unknown>)[key];\n\n\t\t\t\t\tif (typeof maybeFn !== \"function\") {\n\t\t\t\t\t\tthrow new TypeError(\n\t\t\t\t\t\t\t`Expected \"${exportName}\" export of \"${workerEntryPath}\" to define a \\`${key}()\\` function.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn maybeFn.call(exportValue, arg, userEnv, this.ctx);\n\t\t\t\t} else if (typeof exportValue === \"function\") {\n\t\t\t\t\t// The export is a `WorkerEntrypoint`\n\t\t\t\t\tconst ctor = exportValue as WorkerEntrypointConstructor;\n\t\t\t\t\tconst instance = new ctor(this.ctx, userEnv);\n\n\t\t\t\t\tif (!(instance instanceof WorkerEntrypoint)) {\n\t\t\t\t\t\tthrow new TypeError(\n\t\t\t\t\t\t\t`Expected \"${exportName}\" export of \"${workerEntryPath}\" to be a subclass of \\`WorkerEntrypoint\\`.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst maybeFn = instance[key];\n\n\t\t\t\t\tif (typeof maybeFn !== \"function\") {\n\t\t\t\t\t\tthrow new TypeError(\n\t\t\t\t\t\t\t`Expected \"${exportName}\" export of \"${workerEntryPath}\" to define a \\`${key}()\\` method.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (maybeFn as (arg: unknown) => unknown).call(instance, arg);\n\t\t\t\t} else {\n\t\t\t\t\treturn new TypeError(\n\t\t\t\t\t\t`Expected \"${exportName}\" export of \"${workerEntryPath}\" to be an object or a class.`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t};\n\t}\n\n\treturn Wrapper;\n}\n\n/** Symbol key for storing the `DurableObject` instance */\nconst kInstance = Symbol(\"kInstance\");\n/** Symbol key for the instance initialization method */\nconst kEnsureInstance = Symbol(\"kEnsureInstance\");\n\n/**\n * Container for a `DurableObject` constructor and its instance.\n */\ninterface DurableObjectInstance {\n\tctor: DurableObjectConstructor;\n\tinstance: DurableObject;\n}\n\n/**\n * Extended `DurableObject` interface that includes instance management methods.\n */\ninterface DurableObjectWrapper extends DurableObject<WrapperEnv> {\n\t[kInstance]?: DurableObjectInstance;\n\t[kEnsureInstance](): Promise<DurableObjectInstance>;\n}\n\n/**\n * Retrieves an RPC property from a `DurableObject` export, ensuring an instance is properly initialized and returning the bound method or property value.\n * @param exportName - The name of the `DurableObject` export\n * @param key - The property key to access on the `DurableObject` instance\n * @returns The property value, with methods bound to the instance\n * @throws TypeError if the export is not a `DurableObject` subclass\n */\nasync function getDurableObjectRpcProperty(\n\tthis: DurableObjectWrapper,\n\texportName: string,\n\tkey: string\n): Promise<unknown> {\n\tconst { ctor, instance } = await this[kEnsureInstance]();\n\n\tif (!(instance instanceof DurableObject)) {\n\t\tthrow new TypeError(\n\t\t\t`Expected \"${exportName}\" export of \"${workerEntryPath}\" to be a subclass of \\`DurableObject\\` for RPC.`\n\t\t);\n\t}\n\n\tconst value = getRpcProperty(ctor, instance, key);\n\n\tif (typeof value === \"function\") {\n\t\treturn value.bind(instance);\n\t}\n\n\treturn value;\n}\n\n/**\n * Creates a proxy wrapper for `DurableObject` classes that enables RPC functionality.\n * The wrapper manages instance lifecycle and delegates method calls to the user code, handling both direct method calls and RPC property access.\n * @param exportName - The name of the `DurableObject` export to wrap\n * @returns A `DurableObject` constructor that acts as a proxy to the user code\n */\nexport function createDurableObjectWrapper(\n\texportName: string\n): DurableObjectConstructor<WrapperEnv> {\n\tclass Wrapper\n\t\textends DurableObject<WrapperEnv>\n\t\timplements DurableObjectWrapper\n\t{\n\t\t[kInstance]?: DurableObjectInstance;\n\n\t\tconstructor(ctx: DurableObjectState, env: WrapperEnv) {\n\t\t\tsuper(ctx, env);\n\n\t\t\treturn new Proxy(this, {\n\t\t\t\tget(target, key, receiver) {\n\t\t\t\t\tconst value = Reflect.get(target, key, receiver);\n\n\t\t\t\t\tif (value !== undefined) {\n\t\t\t\t\t\treturn value;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof key === \"symbol\" ||\n\t\t\t\t\t\t(IGNORED_KEYS as readonly string[]).includes(key) ||\n\t\t\t\t\t\t// The class methods are accessed to determine the type of the export.\n\t\t\t\t\t\t// We should therefore avoid proxying `WorkerEntrypoint` methods on the `DurableObject` class.\n\t\t\t\t\t\t(WORKER_ENTRYPOINT_KEYS as readonly string[]).includes(key)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst property = getDurableObjectRpcProperty.call(\n\t\t\t\t\t\treceiver,\n\t\t\t\t\t\texportName,\n\t\t\t\t\t\tkey\n\t\t\t\t\t);\n\n\t\t\t\t\treturn getRpcPropertyCallableThenable(key, property);\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\tasync [kEnsureInstance]() {\n\t\t\tconst ctor = (await getWorkerEntryExport(\n\t\t\t\tworkerEntryPath,\n\t\t\t\texportName\n\t\t\t)) as DurableObjectConstructor;\n\n\t\t\tif (typeof ctor !== \"function\") {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Expected \"${exportName}\" export of \"${workerEntryPath}\" to be a subclass of \\`DurableObject\\`.`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// We reuse the same instance unless the constructor changes\n\t\t\tif (!this[kInstance] || this[kInstance].ctor !== ctor) {\n\t\t\t\tconst userEnv = stripInternalEnv(this.env);\n\t\t\t\tconst instance = new ctor(this.ctx, userEnv);\n\n\t\t\t\tthis[kInstance] = { ctor, instance };\n\n\t\t\t\t// Wait for `blockConcurrencyWhile()`s in the constructor to complete\n\t\t\t\tawait this.ctx.blockConcurrencyWhile(async () => {});\n\t\t\t}\n\n\t\t\treturn this[kInstance];\n\t\t}\n\t}\n\n\tfor (const key of DURABLE_OBJECT_KEYS) {\n\t\tWrapper.prototype[key] = async function (...args: unknown[]) {\n\t\t\tconst { instance } = await this[kEnsureInstance]();\n\t\t\tconst maybeFn = instance[key];\n\n\t\t\tif (typeof maybeFn !== \"function\") {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Expected \"${exportName}\" export of \"${workerEntryPath}\" to define a \\`${key}()\\` function.`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic method assignment in a loop can't satisfy the intersection of all method signatures\n\t\t\treturn (maybeFn as (...args: unknown[]) => any).apply(instance, args);\n\t\t};\n\t}\n\n\treturn Wrapper;\n}\n\n/**\n * Creates a proxy wrapper for `WorkflowEntrypoint` classes.\n * The wrapper delegates method calls to the user code.\n * @param exportName - The name of the `WorkflowEntrypoint` export to wrap\n * @returns A `WorkflowEntrypoint` constructor that acts as a proxy to the user code\n */\nexport function createWorkflowEntrypointWrapper(\n\texportName: string\n): WorkflowEntrypointConstructor<WrapperEnv> {\n\tclass Wrapper extends WorkflowEntrypoint<WrapperEnv> {}\n\n\tfor (const key of WORKFLOW_ENTRYPOINT_KEYS) {\n\t\tWrapper.prototype[key] = async function (...args: unknown[]) {\n\t\t\tconst ctor = (await getWorkerEntryExport(\n\t\t\t\tworkerEntryPath,\n\t\t\t\texportName\n\t\t\t)) as WorkflowEntrypointConstructor;\n\t\t\tconst userEnv = stripInternalEnv(this.env);\n\t\t\tconst instance = new ctor(this.ctx, userEnv);\n\n\t\t\tif (!(instance instanceof WorkflowEntrypoint)) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Expected \"${exportName}\" export of \"${workerEntryPath}\" to be a subclass of \\`WorkflowEntrypoint\\`.`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst maybeFn = instance[key];\n\n\t\t\tif (typeof maybeFn !== \"function\") {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Expected \"${exportName}\" export of \"${workerEntryPath}\" to define a \\`${key}()\\` function.`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn (maybeFn as (...args: unknown[]) => unknown).apply(instance, args);\n\t\t};\n\t}\n\n\treturn Wrapper;\n}\n"],"mappings":";;;;AAAA,MAAa,eAAe;AAG5B,MAAa,YAAY;AACzB,MAAa,wBACZ;AAGD,MAAa,2BAA2B;AACxC,MAAa,yBAAyB;AACtC,MAAa,0BAA0B;AACvC,MAAa,+BAA+B;AAG5C,MAAa,gBAAgB;AAC7B,MAAa,uBAAuB,GAAG,cAAc;AACrD,MAAa,uBAAuB,GAAG,cAAc;;;;;;;;;ACSrD,SAAgB,iBAAiB,aAAyB;CACzD,MAAM,EACL,kDACA,wBACA,qBACA,GAAG,YACA;AAEJ,QAAO;;;;;;;;;ACzBR,SAAS,YAAY,GAAqB;CACzC,MAAM,WAAY,KAAK,EAAE;AACzB,QAAO;EACN,MAAM,SAAS;EACf,SAAS,SAAS,WAAW,OAAO,EAAE;EACtC,OAAO,SAAS;EAChB,OACC,SAAS,UAAU,SAAY,SAAY,YAAY,SAAS,MAAM;EACvE;;;;;;;AAQF,eAAsB,kBACrB,SACA,IACC;AACD,KACC,CAAC,QAAQ,iBACT,QAAQ,eAAe,aACvB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