@cloudflare/vitest-pool-workers 0.2.12 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/index.cjs +79 -20
- package/dist/config/index.cjs.map +3 -3
- package/dist/config/index.d.ts +1 -0
- package/dist/config/pages.d.ts +2 -0
- package/dist/pool/config.d.ts +3 -0
- package/dist/pool/index.mjs +44 -12
- package/dist/pool/index.mjs.map +1 -1
- package/dist/worker/index.mjs +65 -54
- package/dist/worker/index.mjs.map +2 -2
- package/dist/worker/lib/cloudflare/test-internal.mjs +379 -91
- package/dist/worker/lib/cloudflare/test-internal.mjs.map +3 -3
- package/dist/worker/lib/cloudflare/test-runner.mjs +24 -0
- package/dist/worker/lib/cloudflare/test-runner.mjs.map +1 -1
- package/dist/worker/lib/cloudflare/test.mjs +3 -1
- package/dist/worker/lib/cloudflare/test.mjs.map +1 -1
- package/dist/worker/lib/node/module.mjs +10 -3
- package/dist/worker/lib/node/module.mjs.map +1 -1
- package/package.json +8 -4
- package/types/cloudflare-test.d.ts +32 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
4
|
-
"mappings": ";AAAA,
|
|
3
|
+
"sources": ["../../src/worker/index.ts", "../../../miniflare/src/workers/core/devalue.ts", "../../src/shared/chunking-socket.ts"],
|
|
4
|
+
"mappings": ";AAAA,OAAOA,aAAY;AACnB,SAAS,UAAAC,eAAc;AACvB,OAAO,YAAY;AACnB,OAAO,aAAa;AACpB,YAAY,QAAQ;AACpB,OAAO,aAAa;AACpB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,YAAY,aAAa;;;ACdzB,OAAO,YAAY;AACnB,SAAS,cAAc;AACvB,SAAS,OAAO,iBAAiB;AAmBjC,IAAM,yCAAyC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA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OAAO,gBAAgB;AACxD,YAAM,qBAAqB,eAAe,UAAU;AAEpD,YAAM,OAAO;AACb,qBAAe,UAAU,aAAa,YAAa,MAAM;AACxD,aAAK,WAAW;AAChB,eAAO,mBAAmB,MAAM,MAAM,IAAI;AAAA,MAC3C;AAEA,MAAC,GAAG,KAAwC,OAAO;AACnD,aAAO,GAAG,IAAI,EAAE,GAAG,IAAI,EACrB,KAAK,MAAM;AACX,mBAAW,MAAM,KAAM,MAAM;AAAA,MAC9B,CAAC,EACA,MAAM,CAAC,MAAe;AACtB,aAAK,YAAY,EAAE,wBAAwB,EAAE,CAAC;AAC9C,cAAM,QAAQ,YAAY,CAAC;AAC3B,kBAAU,MAAM,yBAAyB,MAAM,KAAK;AACpD,mBAAW,MAAM,MAAM,gBAAgB;AAAA,MACxC,CAAC;AAAA,IACH,SAAS,GAAP;AACD,YAAM,QAAQ,YAAY,CAAC;AAC3B,gBAAU,MAAM,8BAA8B,MAAM,KAAK;AACzD,aAAO,SAAS,KAAK,OAAO;AAAA,QAC3B,QAAQ;AAAA,QACR,SAAS,EAAE,+BAA+B,OAAO;AAAA,MAClD,CAAC;AAAA,IACF;AAEA,WAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,KAAK,WAAW,mBAAmB,CAAC;AAAA,EACzE;AAAA,EAEA,MAAM,MAAM,SAAqC;AAChD,UAAM,WAAW,MAAM,sBAAsB,SAAS,IAAI;AAC1D,QAAI,aAAa,QAAW;AAC3B,aAAO;AAAA,IACR;AAEA,WAAO,KAAK,uBAAuB,OAAO;AAAA,EAC3C;AACD;AAEA,IAAO,iBAAQ,8BAA8B,SAAS;",
|
|
5
5
|
"names": ["assert", "Buffer", "assert", "Buffer", "Buffer", "assert"]
|
|
6
6
|
}
|
|
@@ -185,15 +185,6 @@ function runInRunnerObject(env2, callback) {
|
|
|
185
185
|
const stub = env2.__VITEST_POOL_WORKERS_RUNNER_OBJECT.get("singleton");
|
|
186
186
|
return runInStub(stub, callback);
|
|
187
187
|
}
|
|
188
|
-
function importModule(env2, specifier) {
|
|
189
|
-
return runInRunnerObject(env2, (instance) => {
|
|
190
|
-
assert2(
|
|
191
|
-
instance.executor !== void 0,
|
|
192
|
-
"Expected Vitest to start running before importing modules"
|
|
193
|
-
);
|
|
194
|
-
return instance.executor.executeId(specifier);
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
188
|
async function maybeHandleRunRequest(request, instance, state) {
|
|
198
189
|
const actionId = request.cf?.[CF_KEY_ACTION];
|
|
199
190
|
if (actionId === void 0) {
|
|
@@ -216,75 +207,6 @@ async function maybeHandleRunRequest(request, instance, state) {
|
|
|
216
207
|
return new Response(null, { status: 500 });
|
|
217
208
|
}
|
|
218
209
|
}
|
|
219
|
-
var DurableObjectWrapper = class {
|
|
220
|
-
constructor(state, env2, className) {
|
|
221
|
-
this.state = state;
|
|
222
|
-
this.env = env2;
|
|
223
|
-
this.className = className;
|
|
224
|
-
}
|
|
225
|
-
instanceConstructor;
|
|
226
|
-
instance;
|
|
227
|
-
async ensureInstance() {
|
|
228
|
-
const mainPath = getResolvedMainPath("Durable Object");
|
|
229
|
-
const mainModule = await importModule(this.env, mainPath);
|
|
230
|
-
const constructor = mainModule[this.className];
|
|
231
|
-
if (typeof constructor !== "function") {
|
|
232
|
-
throw new Error(
|
|
233
|
-
`${mainPath} does not export a ${this.className} Durable Object`
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
this.instanceConstructor ??= constructor;
|
|
237
|
-
if (this.instanceConstructor !== constructor) {
|
|
238
|
-
await this.state.blockConcurrencyWhile(() => {
|
|
239
|
-
throw new Error(
|
|
240
|
-
`${mainPath} changed, invalidating this Durable Object. Please retry the \`DurableObjectStub#fetch()\` call.`
|
|
241
|
-
);
|
|
242
|
-
});
|
|
243
|
-
assert2.fail("Unreachable");
|
|
244
|
-
}
|
|
245
|
-
if (this.instance === void 0) {
|
|
246
|
-
const userEnv = stripInternalEnv(this.env);
|
|
247
|
-
this.instance = new this.instanceConstructor(this.state, userEnv);
|
|
248
|
-
await this.state.blockConcurrencyWhile(async () => {
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
return this.instance;
|
|
252
|
-
}
|
|
253
|
-
async fetch(request) {
|
|
254
|
-
const instance = await this.ensureInstance();
|
|
255
|
-
const response = await maybeHandleRunRequest(request, instance, this.state);
|
|
256
|
-
if (response !== void 0) {
|
|
257
|
-
return response;
|
|
258
|
-
}
|
|
259
|
-
if (instance.fetch === void 0) {
|
|
260
|
-
throw new Error("Handler does not export a fetch() function.");
|
|
261
|
-
}
|
|
262
|
-
return instance.fetch(request);
|
|
263
|
-
}
|
|
264
|
-
async alarm(...args) {
|
|
265
|
-
const instance = await this.ensureInstance();
|
|
266
|
-
return instance.alarm?.(...args);
|
|
267
|
-
}
|
|
268
|
-
async webSocketMessage(...args) {
|
|
269
|
-
const instance = await this.ensureInstance();
|
|
270
|
-
return instance.webSocketMessage?.(...args);
|
|
271
|
-
}
|
|
272
|
-
async webSocketClose(...args) {
|
|
273
|
-
const instance = await this.ensureInstance();
|
|
274
|
-
return instance.webSocketClose?.(...args);
|
|
275
|
-
}
|
|
276
|
-
async webSocketError(...args) {
|
|
277
|
-
const instance = await this.ensureInstance();
|
|
278
|
-
return instance.webSocketError?.(...args);
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
function createDurableObjectWrapper(className) {
|
|
282
|
-
return class extends DurableObjectWrapper {
|
|
283
|
-
constructor(state, env2) {
|
|
284
|
-
super(state, env2, className);
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
210
|
async function listDurableObjectIds(namespace) {
|
|
289
211
|
if (!isDurableObjectNamespace(namespace)) {
|
|
290
212
|
throw new TypeError(
|
|
@@ -317,8 +239,15 @@ async function listDurableObjectIds(namespace) {
|
|
|
317
239
|
});
|
|
318
240
|
}
|
|
319
241
|
|
|
320
|
-
// src/worker/
|
|
321
|
-
|
|
242
|
+
// src/worker/entrypoints.ts
|
|
243
|
+
import assert3 from "node:assert";
|
|
244
|
+
import {
|
|
245
|
+
DurableObject as DurableObjectClass,
|
|
246
|
+
WorkerEntrypoint
|
|
247
|
+
} from "cloudflare:workers";
|
|
248
|
+
|
|
249
|
+
// src/worker/wait-until.ts
|
|
250
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
322
251
|
async function waitForWaitUntil(waitUntil) {
|
|
323
252
|
const errors = [];
|
|
324
253
|
while (waitUntil.length > 0) {
|
|
@@ -342,6 +271,290 @@ function registerGlobalWaitUntil(promise) {
|
|
|
342
271
|
function waitForGlobalWaitUntil() {
|
|
343
272
|
return waitForWaitUntil(globalWaitUntil);
|
|
344
273
|
}
|
|
274
|
+
var handlerContextStore = new AsyncLocalStorage();
|
|
275
|
+
var patchedHandlerContexts = /* @__PURE__ */ new WeakSet();
|
|
276
|
+
function patchAndRunWithHandlerContext(ctx, callback) {
|
|
277
|
+
if (!patchedHandlerContexts.has(ctx)) {
|
|
278
|
+
patchedHandlerContexts.add(ctx);
|
|
279
|
+
const originalWaitUntil = ctx.waitUntil;
|
|
280
|
+
ctx.waitUntil = (promise) => {
|
|
281
|
+
registerGlobalWaitUntil(promise);
|
|
282
|
+
return originalWaitUntil.call(ctx, promise);
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
return handlerContextStore.run(ctx, callback);
|
|
286
|
+
}
|
|
287
|
+
function registerHandlerAndGlobalWaitUntil(promise) {
|
|
288
|
+
const handlerContext = handlerContextStore.getStore();
|
|
289
|
+
if (handlerContext === void 0) {
|
|
290
|
+
registerGlobalWaitUntil(promise);
|
|
291
|
+
} else {
|
|
292
|
+
handlerContext.waitUntil(promise);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/worker/entrypoints.ts
|
|
297
|
+
function importModule(env2, specifier) {
|
|
298
|
+
return runInRunnerObject(env2, (instance) => {
|
|
299
|
+
if (instance.executor === void 0) {
|
|
300
|
+
const message = "Expected Vitest to start running before importing modules.\nThis usually means you have multiple `vitest` versions installed.\nUse your package manager's `why` command to list versions and why each is installed (e.g. `npm why vitest`).";
|
|
301
|
+
throw new Error(message);
|
|
302
|
+
}
|
|
303
|
+
return instance.executor.executeId(specifier);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
function createProxyPrototypeClass(superClass, getUnknownPrototypeKey) {
|
|
307
|
+
function Class(...args) {
|
|
308
|
+
Class.prototype = new Proxy(Class.prototype, {
|
|
309
|
+
get(target, key, receiver) {
|
|
310
|
+
const value = Reflect.get(target, key, receiver);
|
|
311
|
+
if (value !== void 0) {
|
|
312
|
+
return value;
|
|
313
|
+
}
|
|
314
|
+
if (key === "self" || typeof key === "symbol") {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
return getUnknownPrototypeKey.call(receiver, key);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
return Reflect.construct(superClass, args, Class);
|
|
321
|
+
}
|
|
322
|
+
Reflect.setPrototypeOf(Class.prototype, superClass.prototype);
|
|
323
|
+
Reflect.setPrototypeOf(Class, superClass);
|
|
324
|
+
return Class;
|
|
325
|
+
}
|
|
326
|
+
function getRPCProperty(ctor, instance, key) {
|
|
327
|
+
const prototypeHasKey = Reflect.has(ctor.prototype, key);
|
|
328
|
+
if (!prototypeHasKey) {
|
|
329
|
+
const quotedKey = JSON.stringify(key);
|
|
330
|
+
const instanceHasKey = Reflect.has(instance, key);
|
|
331
|
+
let message = "";
|
|
332
|
+
if (instanceHasKey) {
|
|
333
|
+
message = [
|
|
334
|
+
`The RPC receiver's prototype does not implement ${quotedKey}, but the receiver instance does.`,
|
|
335
|
+
"Only properties and methods defined on the prototype can be accessed over RPC.",
|
|
336
|
+
`Ensure properties are declared like \`get ${key}() { ... }\` instead of \`${key} = ...\`,`,
|
|
337
|
+
`and methods are declared like \`${key}() { ... }\` instead of \`${key} = () => { ... }\`.`
|
|
338
|
+
].join("\n");
|
|
339
|
+
} else {
|
|
340
|
+
message = `The RPC receiver does not implement ${quotedKey}.`;
|
|
341
|
+
}
|
|
342
|
+
throw new TypeError(message);
|
|
343
|
+
}
|
|
344
|
+
return Reflect.get(
|
|
345
|
+
/* target */
|
|
346
|
+
ctor.prototype,
|
|
347
|
+
key,
|
|
348
|
+
/* receiver */
|
|
349
|
+
instance
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
function getRPCPropertyCallableThenable(key, property) {
|
|
353
|
+
const fn = async function(...args) {
|
|
354
|
+
const maybeFn = await property;
|
|
355
|
+
if (typeof maybeFn === "function") {
|
|
356
|
+
return maybeFn(...args);
|
|
357
|
+
} else {
|
|
358
|
+
throw new TypeError(`${JSON.stringify(key)} is not a function.`);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
fn.then = (onFulfilled, onRejected) => property.then(onFulfilled, onRejected);
|
|
362
|
+
fn.catch = (onRejected) => property.catch(onRejected);
|
|
363
|
+
fn.finally = (onFinally) => property.finally(onFinally);
|
|
364
|
+
return fn;
|
|
365
|
+
}
|
|
366
|
+
function getEntrypointState(instance) {
|
|
367
|
+
return instance;
|
|
368
|
+
}
|
|
369
|
+
var WORKER_ENTRYPOINT_KEYS = [
|
|
370
|
+
"fetch",
|
|
371
|
+
"tail",
|
|
372
|
+
"trace",
|
|
373
|
+
"scheduled",
|
|
374
|
+
"queue",
|
|
375
|
+
"test"
|
|
376
|
+
];
|
|
377
|
+
var DURABLE_OBJECT_KEYS = [
|
|
378
|
+
"fetch",
|
|
379
|
+
"alarm",
|
|
380
|
+
"webSocketMessage",
|
|
381
|
+
"webSocketClose",
|
|
382
|
+
"webSocketError"
|
|
383
|
+
];
|
|
384
|
+
async function getWorkerEntrypointExport(env2, entrypoint) {
|
|
385
|
+
const mainPath = getResolvedMainPath("service");
|
|
386
|
+
const mainModule = await importModule(env2, mainPath);
|
|
387
|
+
const entrypointValue = typeof mainModule === "object" && mainModule !== null && entrypoint in mainModule && mainModule[entrypoint];
|
|
388
|
+
if (!entrypointValue) {
|
|
389
|
+
const message = `${mainPath} does not export a ${entrypoint} entrypoint. \`@cloudflare/vitest-pool-workers\` does not support service workers or named entrypoints for \`SELF\`.
|
|
390
|
+
If you're using service workers, please migrate to the modules format: https://developers.cloudflare.com/workers/reference/migrate-to-module-workers.`;
|
|
391
|
+
throw new TypeError(message);
|
|
392
|
+
}
|
|
393
|
+
return { mainPath, entrypointValue };
|
|
394
|
+
}
|
|
395
|
+
async function getWorkerEntrypointRPCProperty(wrapper, entrypoint, key) {
|
|
396
|
+
const { ctx, env: env2 } = getEntrypointState(wrapper);
|
|
397
|
+
const { mainPath, entrypointValue } = await getWorkerEntrypointExport(
|
|
398
|
+
env2,
|
|
399
|
+
entrypoint
|
|
400
|
+
);
|
|
401
|
+
const userEnv = stripInternalEnv(env2);
|
|
402
|
+
return patchAndRunWithHandlerContext(ctx, () => {
|
|
403
|
+
const expectedWorkerEntrypointMessage = `Expected ${entrypoint} export of ${mainPath} to be a subclass of \`WorkerEntrypoint\` for RPC`;
|
|
404
|
+
if (typeof entrypointValue !== "function") {
|
|
405
|
+
throw new TypeError(expectedWorkerEntrypointMessage);
|
|
406
|
+
}
|
|
407
|
+
const ctor = entrypointValue;
|
|
408
|
+
const instance = new ctor(ctx, userEnv);
|
|
409
|
+
if (!(instance instanceof WorkerEntrypoint)) {
|
|
410
|
+
throw new TypeError(expectedWorkerEntrypointMessage);
|
|
411
|
+
}
|
|
412
|
+
const value = getRPCProperty(ctor, instance, key);
|
|
413
|
+
if (typeof value === "function") {
|
|
414
|
+
return (...args) => patchAndRunWithHandlerContext(ctx, () => value.apply(instance, args));
|
|
415
|
+
} else {
|
|
416
|
+
return value;
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
function createWorkerEntrypointWrapper(entrypoint) {
|
|
421
|
+
const Wrapper = createProxyPrototypeClass(
|
|
422
|
+
WorkerEntrypoint,
|
|
423
|
+
function(key) {
|
|
424
|
+
if (DURABLE_OBJECT_KEYS.includes(key)) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const property = getWorkerEntrypointRPCProperty(this, entrypoint, key);
|
|
428
|
+
return getRPCPropertyCallableThenable(key, property);
|
|
429
|
+
}
|
|
430
|
+
);
|
|
431
|
+
for (const key of WORKER_ENTRYPOINT_KEYS) {
|
|
432
|
+
Wrapper.prototype[key] = async function(thing) {
|
|
433
|
+
const { mainPath, entrypointValue } = await getWorkerEntrypointExport(
|
|
434
|
+
this.env,
|
|
435
|
+
entrypoint
|
|
436
|
+
);
|
|
437
|
+
const userEnv = stripInternalEnv(this.env);
|
|
438
|
+
return patchAndRunWithHandlerContext(this.ctx, () => {
|
|
439
|
+
if (typeof entrypointValue === "object" && entrypointValue !== null) {
|
|
440
|
+
const maybeFn = entrypointValue[key];
|
|
441
|
+
if (typeof maybeFn === "function") {
|
|
442
|
+
return maybeFn.call(entrypointValue, thing, userEnv, this.ctx);
|
|
443
|
+
} else {
|
|
444
|
+
const message = `Expected ${entrypoint} export of ${mainPath} to define a \`${key}()\` function`;
|
|
445
|
+
throw new TypeError(message);
|
|
446
|
+
}
|
|
447
|
+
} else if (typeof entrypointValue === "function") {
|
|
448
|
+
const ctor = entrypointValue;
|
|
449
|
+
const instance = new ctor(this.ctx, userEnv);
|
|
450
|
+
if (!(instance instanceof WorkerEntrypoint)) {
|
|
451
|
+
const message = `Expected ${entrypoint} export of ${mainPath} to be a subclass of \`WorkerEntrypoint\``;
|
|
452
|
+
throw new TypeError(message);
|
|
453
|
+
}
|
|
454
|
+
const maybeFn = instance[key];
|
|
455
|
+
if (typeof maybeFn === "function") {
|
|
456
|
+
return maybeFn.call(instance, thing);
|
|
457
|
+
} else {
|
|
458
|
+
const message = `Expected ${entrypoint} export of ${mainPath} to define a \`${key}()\` method`;
|
|
459
|
+
throw new TypeError(message);
|
|
460
|
+
}
|
|
461
|
+
} else {
|
|
462
|
+
const message = `Expected ${entrypoint} export of ${mainPath}to be an object or a class, got ${entrypointValue}`;
|
|
463
|
+
throw new TypeError(message);
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
return Wrapper;
|
|
469
|
+
}
|
|
470
|
+
var kInstanceConstructor = Symbol("kInstanceConstructor");
|
|
471
|
+
var kInstance = Symbol("kInstance");
|
|
472
|
+
var kEnsureInstance = Symbol("kEnsureInstance");
|
|
473
|
+
async function getDurableObjectRPCProperty(wrapper, className, key) {
|
|
474
|
+
const { mainPath, instanceCtor, instance } = await wrapper[kEnsureInstance]();
|
|
475
|
+
if (!(instance instanceof DurableObjectClass)) {
|
|
476
|
+
const message = `Expected ${className} exported by ${mainPath} be a subclass of \`DurableObject\` for RPC`;
|
|
477
|
+
throw new TypeError(message);
|
|
478
|
+
}
|
|
479
|
+
const value = getRPCProperty(instanceCtor, instance, key);
|
|
480
|
+
if (typeof value === "function") {
|
|
481
|
+
return value.bind(instance);
|
|
482
|
+
} else {
|
|
483
|
+
return value;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
function createDurableObjectWrapper(className) {
|
|
487
|
+
const Wrapper = createProxyPrototypeClass(DurableObjectClass, function(key) {
|
|
488
|
+
if (WORKER_ENTRYPOINT_KEYS.includes(key)) {
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
const property = getDurableObjectRPCProperty(this, className, key);
|
|
492
|
+
return getRPCPropertyCallableThenable(key, property);
|
|
493
|
+
});
|
|
494
|
+
Wrapper.prototype[kEnsureInstance] = async function() {
|
|
495
|
+
const { ctx, env: env2 } = getEntrypointState(this);
|
|
496
|
+
const mainPath = getResolvedMainPath("Durable Object");
|
|
497
|
+
const mainModule = await importModule(env2, mainPath);
|
|
498
|
+
const constructor = mainModule[className];
|
|
499
|
+
if (typeof constructor !== "function") {
|
|
500
|
+
throw new TypeError(
|
|
501
|
+
`${mainPath} does not export a ${className} Durable Object`
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
this[kInstanceConstructor] ??= constructor;
|
|
505
|
+
if (this[kInstanceConstructor] !== constructor) {
|
|
506
|
+
await ctx.blockConcurrencyWhile(() => {
|
|
507
|
+
throw new Error(
|
|
508
|
+
`${mainPath} changed, invalidating this Durable Object. Please retry the \`DurableObjectStub#fetch()\` call.`
|
|
509
|
+
);
|
|
510
|
+
});
|
|
511
|
+
assert3.fail("Unreachable");
|
|
512
|
+
}
|
|
513
|
+
if (this[kInstance] === void 0) {
|
|
514
|
+
const userEnv = stripInternalEnv(env2);
|
|
515
|
+
this[kInstance] = new this[kInstanceConstructor](ctx, userEnv);
|
|
516
|
+
await ctx.blockConcurrencyWhile(async () => {
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
return {
|
|
520
|
+
mainPath,
|
|
521
|
+
instanceCtor: this[kInstanceConstructor],
|
|
522
|
+
instance: this[kInstance]
|
|
523
|
+
};
|
|
524
|
+
};
|
|
525
|
+
Wrapper.prototype.fetch = async function(request) {
|
|
526
|
+
const { ctx } = getEntrypointState(this);
|
|
527
|
+
const { mainPath, instance } = await this[kEnsureInstance]();
|
|
528
|
+
const response = await maybeHandleRunRequest(request, instance, ctx);
|
|
529
|
+
if (response !== void 0) {
|
|
530
|
+
return response;
|
|
531
|
+
}
|
|
532
|
+
if (instance.fetch === void 0) {
|
|
533
|
+
const message = `${className} exported by ${mainPath} does not define a \`fetch()\` method`;
|
|
534
|
+
throw new TypeError(message);
|
|
535
|
+
}
|
|
536
|
+
return instance.fetch(request);
|
|
537
|
+
};
|
|
538
|
+
for (const key of DURABLE_OBJECT_KEYS) {
|
|
539
|
+
if (key === "fetch") {
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
Wrapper.prototype[key] = async function(...args) {
|
|
543
|
+
const { mainPath, instance } = await this[kEnsureInstance]();
|
|
544
|
+
const maybeFn = instance[key];
|
|
545
|
+
if (typeof maybeFn === "function") {
|
|
546
|
+
return maybeFn.apply(instance, args);
|
|
547
|
+
} else {
|
|
548
|
+
const message = `${className} exported by ${mainPath} does not define a \`${key}()\` method`;
|
|
549
|
+
throw new TypeError(message);
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
return Wrapper;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// src/worker/events.ts
|
|
557
|
+
var kConstructFlag = Symbol("kConstructFlag");
|
|
345
558
|
var kWaitUntil = Symbol("kWaitUntil");
|
|
346
559
|
var ExecutionContext = class {
|
|
347
560
|
// https://github.com/cloudflare/workerd/blob/v1.20231218.0/src/workerd/api/global-scope.h#L168
|
|
@@ -364,10 +577,13 @@ var ExecutionContext = class {
|
|
|
364
577
|
function createExecutionContext() {
|
|
365
578
|
return new ExecutionContext(kConstructFlag);
|
|
366
579
|
}
|
|
580
|
+
function isExecutionContextLike(v) {
|
|
581
|
+
return typeof v === "object" && v !== null && kWaitUntil in v && Array.isArray(v[kWaitUntil]);
|
|
582
|
+
}
|
|
367
583
|
async function waitOnExecutionContext(ctx) {
|
|
368
|
-
if (!(ctx
|
|
584
|
+
if (!isExecutionContextLike(ctx)) {
|
|
369
585
|
throw new TypeError(
|
|
370
|
-
"Failed to execute 'getWaitUntil': parameter 1 is not of type 'ExecutionContext'.\nYou must call 'createExecutionContext()' to get an 'ExecutionContext' instance."
|
|
586
|
+
"Failed to execute 'getWaitUntil': parameter 1 is not of type 'ExecutionContext'.\nYou must call 'createExecutionContext()' or 'createPagesEventContext()' to get an 'ExecutionContext' instance."
|
|
371
587
|
);
|
|
372
588
|
}
|
|
373
589
|
return waitForWaitUntil(ctx[kWaitUntil]);
|
|
@@ -573,12 +789,12 @@ var QueueController = class {
|
|
|
573
789
|
function createMessageBatch(queueName, messages) {
|
|
574
790
|
if (arguments.length === 0) {
|
|
575
791
|
throw new TypeError(
|
|
576
|
-
"
|
|
792
|
+
"Failed to execute 'createMessageBatch': parameter 1 is not of type 'string'."
|
|
577
793
|
);
|
|
578
794
|
}
|
|
579
795
|
if (!Array.isArray(messages)) {
|
|
580
796
|
throw new TypeError(
|
|
581
|
-
"
|
|
797
|
+
"Failed to execute 'createMessageBatch': parameter 2 is not of type 'Array'."
|
|
582
798
|
);
|
|
583
799
|
}
|
|
584
800
|
return new QueueController(kConstructFlag, queueName, messages);
|
|
@@ -615,9 +831,77 @@ async function getQueueResult(batch, ctx) {
|
|
|
615
831
|
explicitAcks
|
|
616
832
|
};
|
|
617
833
|
}
|
|
834
|
+
function hasASSETSServiceBinding(value) {
|
|
835
|
+
return "ASSETS" in value && typeof value.ASSETS === "object" && value.ASSETS !== null && "fetch" in value.ASSETS && typeof value.ASSETS.fetch === "function";
|
|
836
|
+
}
|
|
837
|
+
function createPagesEventContext(opts) {
|
|
838
|
+
if (typeof opts !== "object" || opts === null) {
|
|
839
|
+
throw new TypeError(
|
|
840
|
+
"Failed to execute 'createPagesEventContext': parameter 1 is not of type 'EventContextInit'."
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
if (!(opts.request instanceof Request)) {
|
|
844
|
+
throw new TypeError(
|
|
845
|
+
"Incorrect type for the 'request' field on 'EventContextInit': the provided value is not of type 'Request'."
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
if (opts.functionPath !== void 0 && typeof opts.functionPath !== "string") {
|
|
849
|
+
throw new TypeError(
|
|
850
|
+
"Incorrect type for the 'functionPath' field on 'EventContextInit': the provided value is not of type 'string'."
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
if (opts.next !== void 0 && typeof opts.next !== "function") {
|
|
854
|
+
throw new TypeError(
|
|
855
|
+
"Incorrect type for the 'next' field on 'EventContextInit': the provided value is not of type 'function'."
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
if (opts.params !== void 0 && !(typeof opts.params === "object" && opts.params !== null)) {
|
|
859
|
+
throw new TypeError(
|
|
860
|
+
"Incorrect type for the 'params' field on 'EventContextInit': the provided value is not of type 'object'."
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
if (opts.data !== void 0 && !(typeof opts.data === "object" && opts.data !== null)) {
|
|
864
|
+
throw new TypeError(
|
|
865
|
+
"Incorrect type for the 'data' field on 'EventContextInit': the provided value is not of type 'object'."
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
if (!hasASSETSServiceBinding(env)) {
|
|
869
|
+
throw new TypeError(
|
|
870
|
+
"Cannot call `createPagesEventContext()` without defining `ASSETS` service binding"
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
const ctx = createExecutionContext();
|
|
874
|
+
return {
|
|
875
|
+
// If we might need to re-use this request, clone it
|
|
876
|
+
request: opts.next ? opts.request.clone() : opts.request,
|
|
877
|
+
functionPath: opts.functionPath ?? "",
|
|
878
|
+
[kWaitUntil]: ctx[kWaitUntil],
|
|
879
|
+
waitUntil: ctx.waitUntil.bind(ctx),
|
|
880
|
+
passThroughOnException: ctx.passThroughOnException.bind(ctx),
|
|
881
|
+
async next(nextInput, nextInit) {
|
|
882
|
+
if (opts.next === void 0) {
|
|
883
|
+
throw new TypeError(
|
|
884
|
+
"Cannot call `EventContext#next()` without including `next` property in 2nd argument to `createPagesEventContext()`"
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
if (nextInput === void 0) {
|
|
888
|
+
return opts.next(opts.request);
|
|
889
|
+
} else {
|
|
890
|
+
if (typeof nextInput === "string") {
|
|
891
|
+
nextInput = new URL(nextInput, opts.request.url).toString();
|
|
892
|
+
}
|
|
893
|
+
const nextRequest = new Request(nextInput, nextInit);
|
|
894
|
+
return opts.next(nextRequest);
|
|
895
|
+
}
|
|
896
|
+
},
|
|
897
|
+
env,
|
|
898
|
+
params: opts.params ?? {},
|
|
899
|
+
data: opts.data ?? {}
|
|
900
|
+
};
|
|
901
|
+
}
|
|
618
902
|
|
|
619
903
|
// src/worker/fetch-mock.ts
|
|
620
|
-
import
|
|
904
|
+
import assert4 from "node:assert";
|
|
621
905
|
import { Buffer } from "node:buffer";
|
|
622
906
|
import { isMockActive, MockAgent, setDispatcher } from "cloudflare:mock-agent";
|
|
623
907
|
var DECODER = new TextDecoder();
|
|
@@ -627,13 +911,13 @@ var responses = /* @__PURE__ */ new WeakMap();
|
|
|
627
911
|
var originalFetch = fetch;
|
|
628
912
|
setDispatcher((opts, handler) => {
|
|
629
913
|
const request = requests.get(opts);
|
|
630
|
-
|
|
914
|
+
assert4(request !== void 0, "Expected dispatch to come from fetch()");
|
|
631
915
|
originalFetch.call(globalThis, request.request, { body: request.body }).then((response) => {
|
|
632
916
|
responses.set(opts, response);
|
|
633
|
-
|
|
917
|
+
assert4(handler.onComplete !== void 0, "Expected onComplete() handler");
|
|
634
918
|
handler.onComplete?.([]);
|
|
635
919
|
}).catch((error) => {
|
|
636
|
-
|
|
920
|
+
assert4(handler.onError !== void 0, "Expected onError() handler");
|
|
637
921
|
handler.onError(error);
|
|
638
922
|
});
|
|
639
923
|
});
|
|
@@ -686,7 +970,7 @@ globalThis.fetch = async (input, init) => {
|
|
|
686
970
|
responseReject(error);
|
|
687
971
|
},
|
|
688
972
|
onUpgrade(_statusCode, _headers, _socket) {
|
|
689
|
-
|
|
973
|
+
assert4.fail("Unreachable: upgrade requests not supported");
|
|
690
974
|
},
|
|
691
975
|
// `onHeaders` and `onData` will only be called if the response was mocked
|
|
692
976
|
onHeaders(statusCode, headers, _resume, statusText) {
|
|
@@ -695,7 +979,7 @@ globalThis.fetch = async (input, init) => {
|
|
|
695
979
|
if (headers === null) {
|
|
696
980
|
return true;
|
|
697
981
|
}
|
|
698
|
-
|
|
982
|
+
assert4.strictEqual(headers.length % 2, 0, "Expected key/value array");
|
|
699
983
|
responseHeaders = Array.from({ length: headers.length / 2 }).map(
|
|
700
984
|
(_, i) => [headers[i * 2].toString(), headers[i * 2 + 1].toString()]
|
|
701
985
|
);
|
|
@@ -732,23 +1016,27 @@ export {
|
|
|
732
1016
|
createDurableObjectWrapper,
|
|
733
1017
|
createExecutionContext,
|
|
734
1018
|
createMessageBatch,
|
|
1019
|
+
createPagesEventContext,
|
|
735
1020
|
createScheduledController,
|
|
1021
|
+
createWorkerEntrypointWrapper,
|
|
736
1022
|
env,
|
|
737
1023
|
fetchMock,
|
|
738
1024
|
getQueueResult,
|
|
739
1025
|
getResolvedMainPath,
|
|
740
1026
|
getSerializedOptions,
|
|
741
|
-
importModule,
|
|
742
1027
|
internalEnv,
|
|
743
1028
|
listDurableObjectIds,
|
|
744
1029
|
maybeHandleRunRequest,
|
|
1030
|
+
patchAndRunWithHandlerContext,
|
|
745
1031
|
registerGlobalWaitUntil,
|
|
1032
|
+
registerHandlerAndGlobalWaitUntil,
|
|
746
1033
|
runDurableObjectAlarm,
|
|
747
1034
|
runInDurableObject,
|
|
748
1035
|
runInRunnerObject,
|
|
749
1036
|
setEnv,
|
|
750
1037
|
stripInternalEnv,
|
|
751
1038
|
waitForGlobalWaitUntil,
|
|
1039
|
+
waitForWaitUntil,
|
|
752
1040
|
waitOnExecutionContext
|
|
753
1041
|
};
|
|
754
1042
|
//# sourceMappingURL=test-internal.mjs.map
|