miniflare 0.0.0-e8975a93a → 0.0.0-e8aaa3930
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 +34 -0
- package/dist/src/index.d.ts +482 -150
- package/dist/src/index.js +796 -460
- package/dist/src/index.js.map +3 -3
- package/dist/src/workers/assets/assets-kv.worker.js +5 -1
- package/dist/src/workers/assets/assets-kv.worker.js.map +1 -1
- package/dist/src/workers/assets/assets.worker.js +9406 -92
- package/dist/src/workers/assets/assets.worker.js.map +3 -3
- package/dist/src/workers/assets/router.worker.js +8762 -6
- package/dist/src/workers/assets/router.worker.js.map +3 -3
- package/dist/src/workers/cache/cache.worker.js +6 -5
- package/dist/src/workers/cache/cache.worker.js.map +2 -2
- package/dist/src/workers/core/entry.worker.js +18 -15
- package/dist/src/workers/core/entry.worker.js.map +1 -1
- package/dist/src/workers/d1/database.worker.js +1 -1
- package/dist/src/workers/d1/database.worker.js.map +1 -1
- package/dist/src/workers/queues/broker.worker.js +16 -8
- package/dist/src/workers/queues/broker.worker.js.map +1 -1
- package/dist/src/workers/workflows/binding.worker.js +1971 -0
- package/dist/src/workers/workflows/binding.worker.js.map +6 -0
- package/package.json +9 -8
package/dist/src/index.js
CHANGED
|
@@ -95,11 +95,11 @@ var require_Mime = __commonJS({
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
|
-
Mime.prototype.getType = function(
|
|
99
|
-
|
|
100
|
-
let last =
|
|
98
|
+
Mime.prototype.getType = function(path28) {
|
|
99
|
+
path28 = String(path28);
|
|
100
|
+
let last = path28.replace(/^.*[/\\]/, "").toLowerCase();
|
|
101
101
|
let ext = last.replace(/^.*\./, "").toLowerCase();
|
|
102
|
-
let hasPath = last.length <
|
|
102
|
+
let hasPath = last.length < path28.length;
|
|
103
103
|
let hasDot = ext.length < last.length - 1;
|
|
104
104
|
return (hasDot || !hasPath) && this._types[ext] || null;
|
|
105
105
|
};
|
|
@@ -669,6 +669,24 @@ var require_workerd_capnp = __commonJS({
|
|
|
669
669
|
capnp_ts_1.Struct.setUint16(0, 8, this);
|
|
670
670
|
capnp_ts_1.Struct.setText(1, value, this);
|
|
671
671
|
}
|
|
672
|
+
adoptNamedExports(value) {
|
|
673
|
+
capnp_ts_1.Struct.adopt(value, capnp_ts_1.Struct.getPointer(2, this));
|
|
674
|
+
}
|
|
675
|
+
disownNamedExports() {
|
|
676
|
+
return capnp_ts_1.Struct.disown(this.getNamedExports());
|
|
677
|
+
}
|
|
678
|
+
getNamedExports() {
|
|
679
|
+
return capnp_ts_1.Struct.getList(2, capnp.TextList, this);
|
|
680
|
+
}
|
|
681
|
+
hasNamedExports() {
|
|
682
|
+
return !capnp_ts_1.Struct.isNull(capnp_ts_1.Struct.getPointer(2, this));
|
|
683
|
+
}
|
|
684
|
+
initNamedExports(length) {
|
|
685
|
+
return capnp_ts_1.Struct.initList(2, capnp.TextList, length, this);
|
|
686
|
+
}
|
|
687
|
+
setNamedExports(value) {
|
|
688
|
+
capnp_ts_1.Struct.copyFrom(value, capnp_ts_1.Struct.getPointer(2, this));
|
|
689
|
+
}
|
|
672
690
|
toString() {
|
|
673
691
|
return "Worker_Module_" + super.toString();
|
|
674
692
|
}
|
|
@@ -686,7 +704,7 @@ var require_workerd_capnp = __commonJS({
|
|
|
686
704
|
Worker_Module3.NODE_JS_COMPAT_MODULE = Worker_Module_Which.NODE_JS_COMPAT_MODULE;
|
|
687
705
|
Worker_Module3.PYTHON_MODULE = Worker_Module_Which.PYTHON_MODULE;
|
|
688
706
|
Worker_Module3.PYTHON_REQUIREMENT = Worker_Module_Which.PYTHON_REQUIREMENT;
|
|
689
|
-
Worker_Module3._capnp = { displayName: "Module", id: "d9d87a63770a12f3", size: new capnp_ts_1.ObjectSize(8,
|
|
707
|
+
Worker_Module3._capnp = { displayName: "Module", id: "d9d87a63770a12f3", size: new capnp_ts_1.ObjectSize(8, 3) };
|
|
690
708
|
var Worker_Binding_Type_Which;
|
|
691
709
|
(function(Worker_Binding_Type_Which2) {
|
|
692
710
|
Worker_Binding_Type_Which2[Worker_Binding_Type_Which2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
@@ -1668,6 +1686,12 @@ var require_workerd_capnp = __commonJS({
|
|
|
1668
1686
|
setPreventEviction(value) {
|
|
1669
1687
|
capnp_ts_1.Struct.setBit(16, value, this);
|
|
1670
1688
|
}
|
|
1689
|
+
getEnableSql() {
|
|
1690
|
+
return capnp_ts_1.Struct.getBit(17, this);
|
|
1691
|
+
}
|
|
1692
|
+
setEnableSql(value) {
|
|
1693
|
+
capnp_ts_1.Struct.setBit(17, value, this);
|
|
1694
|
+
}
|
|
1671
1695
|
toString() {
|
|
1672
1696
|
return "Worker_DurableObjectNamespace_" + super.toString();
|
|
1673
1697
|
}
|
|
@@ -2432,7 +2456,6 @@ __export(src_exports, {
|
|
|
2432
2456
|
DispatchFetchDispatcher: () => DispatchFetchDispatcher,
|
|
2433
2457
|
DurableObjectsOptionsSchema: () => DurableObjectsOptionsSchema,
|
|
2434
2458
|
DurableObjectsSharedOptionsSchema: () => DurableObjectsSharedOptionsSchema,
|
|
2435
|
-
ENTRY_SOCKET_HTTP_OPTIONS: () => ENTRY_SOCKET_HTTP_OPTIONS,
|
|
2436
2459
|
ErrorEvent: () => ErrorEvent,
|
|
2437
2460
|
File: () => import_undici4.File,
|
|
2438
2461
|
FormData: () => import_undici4.FormData,
|
|
@@ -2470,6 +2493,7 @@ __export(src_exports, {
|
|
|
2470
2493
|
PersistenceSchema: () => PersistenceSchema,
|
|
2471
2494
|
ProxyAddresses: () => ProxyAddresses,
|
|
2472
2495
|
ProxyClient: () => ProxyClient,
|
|
2496
|
+
ProxyNodeBinding: () => ProxyNodeBinding,
|
|
2473
2497
|
ProxyOps: () => ProxyOps,
|
|
2474
2498
|
QUEUES_PLUGIN: () => QUEUES_PLUGIN,
|
|
2475
2499
|
QUEUES_PLUGIN_NAME: () => QUEUES_PLUGIN_NAME,
|
|
@@ -2497,7 +2521,6 @@ __export(src_exports, {
|
|
|
2497
2521
|
Request: () => Request,
|
|
2498
2522
|
Response: () => Response,
|
|
2499
2523
|
RouterError: () => RouterError,
|
|
2500
|
-
RoutingConfigSchema: () => RoutingConfigSchema,
|
|
2501
2524
|
Runtime: () => Runtime,
|
|
2502
2525
|
SERVICE_ENTRY: () => SERVICE_ENTRY,
|
|
2503
2526
|
SERVICE_LOOPBACK: () => SERVICE_LOOPBACK,
|
|
@@ -2511,10 +2534,15 @@ __export(src_exports, {
|
|
|
2511
2534
|
TlsOptions_Version: () => import_workerd_capnp.TlsOptions_Version,
|
|
2512
2535
|
TypedEventTarget: () => TypedEventTarget,
|
|
2513
2536
|
WORKER_BINDING_SERVICE_LOOPBACK: () => WORKER_BINDING_SERVICE_LOOPBACK,
|
|
2537
|
+
WORKFLOWS_PLUGIN: () => WORKFLOWS_PLUGIN,
|
|
2538
|
+
WORKFLOWS_PLUGIN_NAME: () => WORKFLOWS_PLUGIN_NAME,
|
|
2539
|
+
WORKFLOWS_STORAGE_SERVICE_NAME: () => WORKFLOWS_STORAGE_SERVICE_NAME,
|
|
2514
2540
|
WaitGroup: () => WaitGroup,
|
|
2515
2541
|
WebSocket: () => WebSocket,
|
|
2516
2542
|
WebSocketPair: () => WebSocketPair,
|
|
2517
2543
|
Worker_Binding_CryptoKey_Usage: () => import_workerd_capnp.Worker_Binding_CryptoKey_Usage,
|
|
2544
|
+
WorkflowsOptionsSchema: () => WorkflowsOptionsSchema,
|
|
2545
|
+
WorkflowsSharedOptionsSchema: () => WorkflowsSharedOptionsSchema,
|
|
2518
2546
|
__MiniflareFunctionWrapper: () => __MiniflareFunctionWrapper,
|
|
2519
2547
|
_enableControlEndpoints: () => _enableControlEndpoints,
|
|
2520
2548
|
_forceColour: () => _forceColour,
|
|
@@ -2523,7 +2551,7 @@ __export(src_exports, {
|
|
|
2523
2551
|
_transformsForContentEncodingAndContentType: () => _transformsForContentEncodingAndContentType,
|
|
2524
2552
|
base64Decode: () => base64Decode,
|
|
2525
2553
|
base64Encode: () => base64Encode,
|
|
2526
|
-
|
|
2554
|
+
buildAssetManifest: () => buildAssetManifest,
|
|
2527
2555
|
compileModuleRules: () => compileModuleRules,
|
|
2528
2556
|
coupleWebSocket: () => coupleWebSocket,
|
|
2529
2557
|
createFetchMock: () => createFetchMock,
|
|
@@ -2543,6 +2571,7 @@ __export(src_exports, {
|
|
|
2543
2571
|
getFreshSourceMapSupport: () => getFreshSourceMapSupport,
|
|
2544
2572
|
getGlobalServices: () => getGlobalServices,
|
|
2545
2573
|
getMiniflareObjectBindings: () => getMiniflareObjectBindings,
|
|
2574
|
+
getNodeCompat: () => getNodeCompat,
|
|
2546
2575
|
getPersistPath: () => getPersistPath,
|
|
2547
2576
|
getRootPath: () => getRootPath,
|
|
2548
2577
|
globsToRegExps: () => globsToRegExps,
|
|
@@ -2551,7 +2580,6 @@ __export(src_exports, {
|
|
|
2551
2580
|
isSitesRequest: () => isSitesRequest,
|
|
2552
2581
|
kCurrentWorker: () => kCurrentWorker,
|
|
2553
2582
|
kInspectorSocket: () => kInspectorSocket,
|
|
2554
|
-
kProxyNodeBinding: () => kProxyNodeBinding,
|
|
2555
2583
|
kUnsafeEphemeralUniqueKey: () => kUnsafeEphemeralUniqueKey,
|
|
2556
2584
|
kVoid: () => kVoid,
|
|
2557
2585
|
matchRoutes: () => matchRoutes,
|
|
@@ -2588,11 +2616,11 @@ __export(src_exports, {
|
|
|
2588
2616
|
module.exports = __toCommonJS(src_exports);
|
|
2589
2617
|
var import_assert12 = __toESM(require("assert"));
|
|
2590
2618
|
var import_crypto3 = __toESM(require("crypto"));
|
|
2591
|
-
var
|
|
2619
|
+
var import_fs22 = __toESM(require("fs"));
|
|
2592
2620
|
var import_http6 = __toESM(require("http"));
|
|
2593
2621
|
var import_net = __toESM(require("net"));
|
|
2594
2622
|
var import_os2 = __toESM(require("os"));
|
|
2595
|
-
var
|
|
2623
|
+
var import_path26 = __toESM(require("path"));
|
|
2596
2624
|
var import_web5 = require("stream/web");
|
|
2597
2625
|
var import_util5 = __toESM(require("util"));
|
|
2598
2626
|
var import_zlib = __toESM(require("zlib"));
|
|
@@ -2679,7 +2707,7 @@ function zod_worker_default() {
|
|
|
2679
2707
|
|
|
2680
2708
|
// src/index.ts
|
|
2681
2709
|
var import_ws3 = require("ws");
|
|
2682
|
-
var
|
|
2710
|
+
var import_zod22 = require("zod");
|
|
2683
2711
|
|
|
2684
2712
|
// src/cf.ts
|
|
2685
2713
|
var import_assert = __toESM(require("assert"));
|
|
@@ -3287,12 +3315,12 @@ function createHTTPRevivers(impl) {
|
|
|
3287
3315
|
},
|
|
3288
3316
|
Request(value) {
|
|
3289
3317
|
(0, import_node_assert.default)(Array.isArray(value));
|
|
3290
|
-
const [method,
|
|
3318
|
+
const [method, url18, headers, cf, body] = value;
|
|
3291
3319
|
(0, import_node_assert.default)(typeof method === "string");
|
|
3292
|
-
(0, import_node_assert.default)(typeof
|
|
3320
|
+
(0, import_node_assert.default)(typeof url18 === "string");
|
|
3293
3321
|
(0, import_node_assert.default)(headers instanceof impl.Headers);
|
|
3294
3322
|
(0, import_node_assert.default)(body === null || impl.isReadableStream(body));
|
|
3295
|
-
return new impl.Request(
|
|
3323
|
+
return new impl.Request(url18, {
|
|
3296
3324
|
method,
|
|
3297
3325
|
headers,
|
|
3298
3326
|
cf,
|
|
@@ -3421,23 +3449,23 @@ function parseWithReadableStreams(impl, stringified, revivers2) {
|
|
|
3421
3449
|
}
|
|
3422
3450
|
|
|
3423
3451
|
// src/workers/core/routing.ts
|
|
3424
|
-
function matchRoutes(routes,
|
|
3452
|
+
function matchRoutes(routes, url18) {
|
|
3425
3453
|
for (const route of routes) {
|
|
3426
|
-
if (route.protocol && route.protocol !==
|
|
3454
|
+
if (route.protocol && route.protocol !== url18.protocol)
|
|
3427
3455
|
continue;
|
|
3428
3456
|
if (route.allowHostnamePrefix) {
|
|
3429
|
-
if (!
|
|
3457
|
+
if (!url18.hostname.endsWith(route.hostname))
|
|
3430
3458
|
continue;
|
|
3431
3459
|
} else {
|
|
3432
|
-
if (
|
|
3460
|
+
if (url18.hostname !== route.hostname)
|
|
3433
3461
|
continue;
|
|
3434
3462
|
}
|
|
3435
|
-
const
|
|
3463
|
+
const path28 = url18.pathname + url18.search;
|
|
3436
3464
|
if (route.allowPathSuffix) {
|
|
3437
|
-
if (!
|
|
3465
|
+
if (!path28.startsWith(route.path))
|
|
3438
3466
|
continue;
|
|
3439
3467
|
} else {
|
|
3440
|
-
if (
|
|
3468
|
+
if (path28 !== route.path)
|
|
3441
3469
|
continue;
|
|
3442
3470
|
}
|
|
3443
3471
|
return route.target;
|
|
@@ -3682,8 +3710,8 @@ function decodeSitesKey(key) {
|
|
|
3682
3710
|
return key.startsWith(SITES_NO_CACHE_PREFIX) ? decodeURIComponent(key.substring(SITES_NO_CACHE_PREFIX.length)) : key;
|
|
3683
3711
|
}
|
|
3684
3712
|
function isSitesRequest(request) {
|
|
3685
|
-
const
|
|
3686
|
-
return
|
|
3713
|
+
const url18 = new URL(request.url);
|
|
3714
|
+
return url18.pathname.startsWith(`/${SITES_NO_CACHE_PREFIX}`);
|
|
3687
3715
|
}
|
|
3688
3716
|
function serialiseRegExp(regExp) {
|
|
3689
3717
|
const str = regExp.toString();
|
|
@@ -3759,11 +3787,18 @@ var QueueConsumerOptionsSchema = /* @__PURE__ */ import_zod2.z.object({
|
|
|
3759
3787
|
// https://developers.cloudflare.com/queues/platform/configuration/#consumer
|
|
3760
3788
|
// https://developers.cloudflare.com/queues/platform/limits/
|
|
3761
3789
|
maxBatchSize: import_zod2.z.number().min(0).max(100).optional(),
|
|
3762
|
-
maxBatchTimeout: import_zod2.z.number().min(0).max(
|
|
3790
|
+
maxBatchTimeout: import_zod2.z.number().min(0).max(60).optional(),
|
|
3763
3791
|
// seconds
|
|
3764
3792
|
maxRetires: import_zod2.z.number().min(0).max(100).optional(),
|
|
3793
|
+
// deprecated
|
|
3794
|
+
maxRetries: import_zod2.z.number().min(0).max(100).optional(),
|
|
3765
3795
|
deadLetterQueue: import_zod2.z.ostring(),
|
|
3766
3796
|
retryDelay: QueueMessageDelaySchema
|
|
3797
|
+
}).transform((queue) => {
|
|
3798
|
+
if (queue.maxRetires !== void 0) {
|
|
3799
|
+
queue.maxRetries = queue.maxRetires;
|
|
3800
|
+
}
|
|
3801
|
+
return queue;
|
|
3767
3802
|
});
|
|
3768
3803
|
var QueueConsumerSchema = /* @__PURE__ */ import_zod2.z.intersection(
|
|
3769
3804
|
QueueConsumerOptionsSchema,
|
|
@@ -3830,8 +3865,8 @@ var Response = class extends import_undici3.Response {
|
|
|
3830
3865
|
Object.setPrototypeOf(response, Response.prototype);
|
|
3831
3866
|
return response;
|
|
3832
3867
|
}
|
|
3833
|
-
static redirect(
|
|
3834
|
-
const response = import_undici3.Response.redirect(
|
|
3868
|
+
static redirect(url18, status) {
|
|
3869
|
+
const response = import_undici3.Response.redirect(url18, status);
|
|
3835
3870
|
Object.setPrototypeOf(response, Response.prototype);
|
|
3836
3871
|
return response;
|
|
3837
3872
|
}
|
|
@@ -4339,14 +4374,14 @@ async function fetch3(input, init2) {
|
|
|
4339
4374
|
const requestInit = init2;
|
|
4340
4375
|
const request = new Request(input, requestInit);
|
|
4341
4376
|
if (request.method === "GET" && request.headers.get("upgrade") === "websocket") {
|
|
4342
|
-
const
|
|
4343
|
-
if (
|
|
4377
|
+
const url18 = new URL(request.url);
|
|
4378
|
+
if (url18.protocol !== "http:" && url18.protocol !== "https:") {
|
|
4344
4379
|
throw new TypeError(
|
|
4345
|
-
`Fetch API cannot load: ${
|
|
4380
|
+
`Fetch API cannot load: ${url18.toString()}.
|
|
4346
4381
|
Make sure you're using http(s):// URLs for WebSocket requests via fetch.`
|
|
4347
4382
|
);
|
|
4348
4383
|
}
|
|
4349
|
-
|
|
4384
|
+
url18.protocol = url18.protocol.replace("http", "ws");
|
|
4350
4385
|
const headers = {};
|
|
4351
4386
|
let protocols;
|
|
4352
4387
|
for (const [key, value] of request.headers.entries()) {
|
|
@@ -4358,10 +4393,10 @@ Make sure you're using http(s):// URLs for WebSocket requests via fetch.`
|
|
|
4358
4393
|
}
|
|
4359
4394
|
let rejectUnauthorized;
|
|
4360
4395
|
if (requestInit.dispatcher instanceof DispatchFetchDispatcher) {
|
|
4361
|
-
requestInit.dispatcher.addHeaders(headers,
|
|
4396
|
+
requestInit.dispatcher.addHeaders(headers, url18.pathname + url18.search);
|
|
4362
4397
|
rejectUnauthorized = { rejectUnauthorized: false };
|
|
4363
4398
|
}
|
|
4364
|
-
const ws = new import_ws2.default(
|
|
4399
|
+
const ws = new import_ws2.default(url18, protocols, {
|
|
4365
4400
|
followRedirects: request.redirect === "follow",
|
|
4366
4401
|
headers,
|
|
4367
4402
|
...rejectUnauthorized
|
|
@@ -4420,8 +4455,8 @@ var DispatchFetchDispatcher = class extends undici.Dispatcher {
|
|
|
4420
4455
|
this.cfBlobJson = JSON.stringify(cfBlob);
|
|
4421
4456
|
}
|
|
4422
4457
|
cfBlobJson;
|
|
4423
|
-
addHeaders(headers,
|
|
4424
|
-
const originalURL = this.userRuntimeOrigin +
|
|
4458
|
+
addHeaders(headers, path28) {
|
|
4459
|
+
const originalURL = this.userRuntimeOrigin + path28;
|
|
4425
4460
|
addHeader(headers, CoreHeaders.ORIGINAL_URL, originalURL);
|
|
4426
4461
|
addHeader(headers, CoreHeaders.DISABLE_PRETTY_ERROR, "true");
|
|
4427
4462
|
if (this.cfBlobJson !== void 0) {
|
|
@@ -4434,16 +4469,16 @@ var DispatchFetchDispatcher = class extends undici.Dispatcher {
|
|
|
4434
4469
|
origin = this.actualRuntimeOrigin;
|
|
4435
4470
|
if (origin === this.actualRuntimeOrigin) {
|
|
4436
4471
|
options.origin = origin;
|
|
4437
|
-
let
|
|
4472
|
+
let path28 = options.path;
|
|
4438
4473
|
if (options.query !== void 0) {
|
|
4439
|
-
const
|
|
4474
|
+
const url18 = new URL(path28, "http://placeholder/");
|
|
4440
4475
|
for (const [key, value] of Object.entries(options.query)) {
|
|
4441
|
-
|
|
4476
|
+
url18.searchParams.append(key, value);
|
|
4442
4477
|
}
|
|
4443
|
-
|
|
4478
|
+
path28 = url18.pathname + url18.search;
|
|
4444
4479
|
}
|
|
4445
4480
|
options.headers ??= {};
|
|
4446
|
-
this.addHeaders(options.headers,
|
|
4481
|
+
this.addHeaders(options.headers, path28);
|
|
4447
4482
|
return this.runtimeDispatcher.dispatch(options, handler);
|
|
4448
4483
|
} else {
|
|
4449
4484
|
return this.globalDispatcher.dispatch(options, handler);
|
|
@@ -4504,11 +4539,6 @@ ez/dHA==
|
|
|
4504
4539
|
`;
|
|
4505
4540
|
|
|
4506
4541
|
// src/http/server.ts
|
|
4507
|
-
var ENTRY_SOCKET_HTTP_OPTIONS = {
|
|
4508
|
-
// Even though we inject a `cf` object in the entry worker, allow it to
|
|
4509
|
-
// be customised via `dispatchFetch`
|
|
4510
|
-
cfBlobHeader: CoreHeaders.CF_BLOB
|
|
4511
|
-
};
|
|
4512
4542
|
async function getEntrySocketHttpOptions(coreOpts) {
|
|
4513
4543
|
let privateKey = void 0;
|
|
4514
4544
|
let certificateChain = void 0;
|
|
@@ -4525,7 +4555,6 @@ async function getEntrySocketHttpOptions(coreOpts) {
|
|
|
4525
4555
|
if (privateKey && certificateChain) {
|
|
4526
4556
|
return {
|
|
4527
4557
|
https: {
|
|
4528
|
-
options: ENTRY_SOCKET_HTTP_OPTIONS,
|
|
4529
4558
|
tlsOptions: {
|
|
4530
4559
|
keypair: {
|
|
4531
4560
|
privateKey,
|
|
@@ -4535,7 +4564,7 @@ async function getEntrySocketHttpOptions(coreOpts) {
|
|
|
4535
4564
|
}
|
|
4536
4565
|
};
|
|
4537
4566
|
} else {
|
|
4538
|
-
return { http:
|
|
4567
|
+
return { http: {} };
|
|
4539
4568
|
}
|
|
4540
4569
|
}
|
|
4541
4570
|
function valueOrFile(value, filePath) {
|
|
@@ -4564,10 +4593,54 @@ var import_undici4 = require("undici");
|
|
|
4564
4593
|
// src/plugins/assets/index.ts
|
|
4565
4594
|
var import_node_crypto = __toESM(require("node:crypto"));
|
|
4566
4595
|
var import_promises7 = __toESM(require("node:fs/promises"));
|
|
4567
|
-
var
|
|
4596
|
+
var import_node_path2 = __toESM(require("node:path"));
|
|
4597
|
+
|
|
4598
|
+
// ../workers-shared/utils/constants.ts
|
|
4599
|
+
var HEADER_SIZE = 20;
|
|
4600
|
+
var PATH_HASH_SIZE = 16;
|
|
4601
|
+
var CONTENT_HASH_SIZE = 16;
|
|
4602
|
+
var TAIL_SIZE = 8;
|
|
4603
|
+
var PATH_HASH_OFFSET = 0;
|
|
4604
|
+
var CONTENT_HASH_OFFSET = PATH_HASH_SIZE;
|
|
4605
|
+
var ENTRY_SIZE = PATH_HASH_SIZE + CONTENT_HASH_SIZE + TAIL_SIZE;
|
|
4606
|
+
var MAX_ASSET_COUNT = 2e4;
|
|
4607
|
+
var MAX_ASSET_SIZE = 25 * 1024 * 1024;
|
|
4608
|
+
|
|
4609
|
+
// ../workers-shared/utils/types.ts
|
|
4610
|
+
var import_zod4 = require("zod");
|
|
4611
|
+
var RoutingConfigSchema = import_zod4.z.object({
|
|
4612
|
+
has_user_worker: import_zod4.z.boolean().optional(),
|
|
4613
|
+
invoke_user_worker_ahead_of_assets: import_zod4.z.boolean().optional()
|
|
4614
|
+
});
|
|
4615
|
+
var AssetConfigSchema = import_zod4.z.object({
|
|
4616
|
+
html_handling: import_zod4.z.enum([
|
|
4617
|
+
"auto-trailing-slash",
|
|
4618
|
+
"force-trailing-slash",
|
|
4619
|
+
"drop-trailing-slash",
|
|
4620
|
+
"none"
|
|
4621
|
+
]).optional(),
|
|
4622
|
+
not_found_handling: import_zod4.z.enum(["single-page-application", "404-page", "none"]).optional(),
|
|
4623
|
+
serve_directly: import_zod4.z.boolean().optional()
|
|
4624
|
+
});
|
|
4625
|
+
|
|
4626
|
+
// ../workers-shared/utils/helpers.ts
|
|
4627
|
+
var import_node_path = require("node:path");
|
|
4568
4628
|
var import_mime = __toESM(require_mime());
|
|
4629
|
+
var normalizeFilePath = (relativeFilepath) => {
|
|
4630
|
+
if ((0, import_node_path.isAbsolute)(relativeFilepath)) {
|
|
4631
|
+
throw new Error(`Expected relative path`);
|
|
4632
|
+
}
|
|
4633
|
+
return "/" + relativeFilepath.split(import_node_path.sep).join("/");
|
|
4634
|
+
};
|
|
4635
|
+
var getContentType = (absFilePath) => {
|
|
4636
|
+
let contentType = (0, import_mime.getType)(absFilePath) || "application/octet-stream";
|
|
4637
|
+
if (contentType.startsWith("text/") && !contentType.includes("charset")) {
|
|
4638
|
+
contentType = `${contentType}; charset=utf-8`;
|
|
4639
|
+
}
|
|
4640
|
+
return contentType;
|
|
4641
|
+
};
|
|
4569
4642
|
|
|
4570
|
-
// ../../node_modules/.pnpm/pretty-bytes@6.
|
|
4643
|
+
// ../../node_modules/.pnpm/pretty-bytes@6.1.1/node_modules/pretty-bytes/index.js
|
|
4571
4644
|
var BYTE_UNITS = [
|
|
4572
4645
|
"B",
|
|
4573
4646
|
"kB",
|
|
@@ -4581,7 +4654,7 @@ var BYTE_UNITS = [
|
|
|
4581
4654
|
];
|
|
4582
4655
|
var BIBYTE_UNITS = [
|
|
4583
4656
|
"B",
|
|
4584
|
-
"
|
|
4657
|
+
"KiB",
|
|
4585
4658
|
"MiB",
|
|
4586
4659
|
"GiB",
|
|
4587
4660
|
"TiB",
|
|
@@ -4628,11 +4701,13 @@ function prettyBytes(number, options) {
|
|
|
4628
4701
|
options = {
|
|
4629
4702
|
bits: false,
|
|
4630
4703
|
binary: false,
|
|
4704
|
+
space: true,
|
|
4631
4705
|
...options
|
|
4632
4706
|
};
|
|
4633
4707
|
const UNITS = options.bits ? options.binary ? BIBIT_UNITS : BIT_UNITS : options.binary ? BIBYTE_UNITS : BYTE_UNITS;
|
|
4708
|
+
const separator = options.space ? " " : "";
|
|
4634
4709
|
if (options.signed && number === 0) {
|
|
4635
|
-
return ` 0
|
|
4710
|
+
return ` 0${separator}${UNITS[0]}`;
|
|
4636
4711
|
}
|
|
4637
4712
|
const isNegative = number < 0;
|
|
4638
4713
|
const prefix = isNegative ? "-" : options.signed ? "+" : "";
|
|
@@ -4648,7 +4723,7 @@ function prettyBytes(number, options) {
|
|
|
4648
4723
|
}
|
|
4649
4724
|
if (number < 1) {
|
|
4650
4725
|
const numberString2 = toLocaleString(number, options.locale, localeOptions);
|
|
4651
|
-
return prefix + numberString2 +
|
|
4726
|
+
return prefix + numberString2 + separator + UNITS[0];
|
|
4652
4727
|
}
|
|
4653
4728
|
const exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1);
|
|
4654
4729
|
number /= (options.binary ? 1024 : 1e3) ** exponent;
|
|
@@ -4657,7 +4732,7 @@ function prettyBytes(number, options) {
|
|
|
4657
4732
|
}
|
|
4658
4733
|
const numberString = toLocaleString(Number(number), options.locale, localeOptions);
|
|
4659
4734
|
const unit = UNITS[exponent];
|
|
4660
|
-
return prefix + numberString +
|
|
4735
|
+
return prefix + numberString + separator + unit;
|
|
4661
4736
|
}
|
|
4662
4737
|
|
|
4663
4738
|
// embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/assets/assets.worker.ts
|
|
@@ -4723,7 +4798,7 @@ function entry_worker_default() {
|
|
|
4723
4798
|
}
|
|
4724
4799
|
|
|
4725
4800
|
// src/plugins/core/index.ts
|
|
4726
|
-
var
|
|
4801
|
+
var import_zod12 = require("zod");
|
|
4727
4802
|
|
|
4728
4803
|
// src/runtime/index.ts
|
|
4729
4804
|
var import_assert4 = __toESM(require("assert"));
|
|
@@ -4732,7 +4807,7 @@ var import_events2 = require("events");
|
|
|
4732
4807
|
var import_readline = __toESM(require("readline"));
|
|
4733
4808
|
var import_stream = require("stream");
|
|
4734
4809
|
var import_workerd2 = __toESM(require("workerd"));
|
|
4735
|
-
var
|
|
4810
|
+
var import_zod5 = require("zod");
|
|
4736
4811
|
|
|
4737
4812
|
// src/runtime/config/index.ts
|
|
4738
4813
|
var import_capnp_ts = require("capnp-ts");
|
|
@@ -4780,15 +4855,15 @@ function serializeConfig(config) {
|
|
|
4780
4855
|
}
|
|
4781
4856
|
|
|
4782
4857
|
// src/runtime/index.ts
|
|
4783
|
-
var ControlMessageSchema =
|
|
4784
|
-
|
|
4785
|
-
event:
|
|
4786
|
-
socket:
|
|
4787
|
-
port:
|
|
4858
|
+
var ControlMessageSchema = import_zod5.z.discriminatedUnion("event", [
|
|
4859
|
+
import_zod5.z.object({
|
|
4860
|
+
event: import_zod5.z.literal("listen"),
|
|
4861
|
+
socket: import_zod5.z.string(),
|
|
4862
|
+
port: import_zod5.z.number()
|
|
4788
4863
|
}),
|
|
4789
|
-
|
|
4790
|
-
event:
|
|
4791
|
-
port:
|
|
4864
|
+
import_zod5.z.object({
|
|
4865
|
+
event: import_zod5.z.literal("listen-inspector"),
|
|
4866
|
+
port: import_zod5.z.number()
|
|
4792
4867
|
})
|
|
4793
4868
|
]);
|
|
4794
4869
|
var kInspectorSocket = Symbol("kInspectorSocket");
|
|
@@ -4883,6 +4958,12 @@ var Runtime = class {
|
|
|
4883
4958
|
}
|
|
4884
4959
|
};
|
|
4885
4960
|
|
|
4961
|
+
// src/plugins/assets/constants.ts
|
|
4962
|
+
var ASSETS_PLUGIN_NAME = "assets";
|
|
4963
|
+
var ASSETS_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:assets-service`;
|
|
4964
|
+
var ROUTER_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:router`;
|
|
4965
|
+
var ASSETS_KV_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:kv`;
|
|
4966
|
+
|
|
4886
4967
|
// src/plugins/cache/index.ts
|
|
4887
4968
|
var import_promises4 = __toESM(require("fs/promises"));
|
|
4888
4969
|
|
|
@@ -4926,7 +5007,7 @@ function cache_entry_noop_worker_default() {
|
|
|
4926
5007
|
}
|
|
4927
5008
|
|
|
4928
5009
|
// src/plugins/cache/index.ts
|
|
4929
|
-
var
|
|
5010
|
+
var import_zod7 = require("zod");
|
|
4930
5011
|
|
|
4931
5012
|
// src/plugins/shared/index.ts
|
|
4932
5013
|
var import_crypto = __toESM(require("crypto"));
|
|
@@ -4934,7 +5015,7 @@ var import_fs11 = require("fs");
|
|
|
4934
5015
|
var import_promises3 = __toESM(require("fs/promises"));
|
|
4935
5016
|
var import_path14 = __toESM(require("path"));
|
|
4936
5017
|
var import_url12 = require("url");
|
|
4937
|
-
var
|
|
5018
|
+
var import_zod6 = require("zod");
|
|
4938
5019
|
|
|
4939
5020
|
// embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/shared/object-entry.worker.ts
|
|
4940
5021
|
var import_fs10 = __toESM(require("fs"));
|
|
@@ -5007,12 +5088,12 @@ var kUnsafeEphemeralUniqueKey = Symbol.for(
|
|
|
5007
5088
|
var import_url11 = require("url");
|
|
5008
5089
|
var RouterError = class extends MiniflareError {
|
|
5009
5090
|
};
|
|
5010
|
-
function routeSpecificity(
|
|
5011
|
-
const hostParts =
|
|
5091
|
+
function routeSpecificity(url18) {
|
|
5092
|
+
const hostParts = url18.host.split(".");
|
|
5012
5093
|
let hostScore = hostParts.length;
|
|
5013
5094
|
if (hostParts[0] === "*")
|
|
5014
5095
|
hostScore -= 2;
|
|
5015
|
-
const pathParts =
|
|
5096
|
+
const pathParts = url18.pathname.split("/");
|
|
5016
5097
|
let pathScore = pathParts.length;
|
|
5017
5098
|
if (pathParts[pathParts.length - 1] === "*")
|
|
5018
5099
|
pathScore -= 2;
|
|
@@ -5026,30 +5107,30 @@ function parseRoutes(allRoutes) {
|
|
|
5026
5107
|
let urlInput = route;
|
|
5027
5108
|
if (!hasProtocol)
|
|
5028
5109
|
urlInput = `https://${urlInput}`;
|
|
5029
|
-
const
|
|
5030
|
-
const specificity = routeSpecificity(
|
|
5031
|
-
const protocol = hasProtocol ?
|
|
5032
|
-
const internationalisedAllowHostnamePrefix =
|
|
5033
|
-
const allowHostnamePrefix =
|
|
5034
|
-
const anyHostname =
|
|
5110
|
+
const url18 = new import_url11.URL(urlInput);
|
|
5111
|
+
const specificity = routeSpecificity(url18);
|
|
5112
|
+
const protocol = hasProtocol ? url18.protocol : void 0;
|
|
5113
|
+
const internationalisedAllowHostnamePrefix = url18.hostname.startsWith("xn--*");
|
|
5114
|
+
const allowHostnamePrefix = url18.hostname.startsWith("*") || internationalisedAllowHostnamePrefix;
|
|
5115
|
+
const anyHostname = url18.hostname === "*";
|
|
5035
5116
|
if (allowHostnamePrefix && !anyHostname) {
|
|
5036
|
-
let hostname =
|
|
5117
|
+
let hostname = url18.hostname;
|
|
5037
5118
|
if (internationalisedAllowHostnamePrefix) {
|
|
5038
5119
|
hostname = (0, import_url11.domainToUnicode)(hostname);
|
|
5039
5120
|
}
|
|
5040
|
-
|
|
5121
|
+
url18.hostname = hostname.substring(1);
|
|
5041
5122
|
}
|
|
5042
|
-
const allowPathSuffix =
|
|
5123
|
+
const allowPathSuffix = url18.pathname.endsWith("*");
|
|
5043
5124
|
if (allowPathSuffix) {
|
|
5044
|
-
|
|
5125
|
+
url18.pathname = url18.pathname.substring(0, url18.pathname.length - 1);
|
|
5045
5126
|
}
|
|
5046
|
-
if (
|
|
5127
|
+
if (url18.search) {
|
|
5047
5128
|
throw new RouterError(
|
|
5048
5129
|
"ERR_QUERY_STRING",
|
|
5049
5130
|
`Route "${route}" for "${target}" contains a query string. This is not allowed.`
|
|
5050
5131
|
);
|
|
5051
5132
|
}
|
|
5052
|
-
if (
|
|
5133
|
+
if (url18.toString().includes("*") && !anyHostname) {
|
|
5053
5134
|
throw new RouterError(
|
|
5054
5135
|
"ERR_INFIX_WILDCARD",
|
|
5055
5136
|
`Route "${route}" for "${target}" contains an infix wildcard. This is not allowed.`
|
|
@@ -5061,8 +5142,8 @@ function parseRoutes(allRoutes) {
|
|
|
5061
5142
|
specificity,
|
|
5062
5143
|
protocol,
|
|
5063
5144
|
allowHostnamePrefix,
|
|
5064
|
-
hostname: anyHostname ? "" :
|
|
5065
|
-
path:
|
|
5145
|
+
hostname: anyHostname ? "" : url18.hostname,
|
|
5146
|
+
path: url18.pathname,
|
|
5066
5147
|
allowPathSuffix
|
|
5067
5148
|
});
|
|
5068
5149
|
}
|
|
@@ -5079,8 +5160,12 @@ function parseRoutes(allRoutes) {
|
|
|
5079
5160
|
|
|
5080
5161
|
// src/plugins/shared/index.ts
|
|
5081
5162
|
var DEFAULT_PERSIST_ROOT = ".mf";
|
|
5082
|
-
var PersistenceSchema =
|
|
5083
|
-
var
|
|
5163
|
+
var PersistenceSchema = import_zod6.z.union([import_zod6.z.boolean(), import_zod6.z.string().url(), PathSchema]).optional();
|
|
5164
|
+
var ProxyNodeBinding = class {
|
|
5165
|
+
constructor(proxyOverrideHandler) {
|
|
5166
|
+
this.proxyOverrideHandler = proxyOverrideHandler;
|
|
5167
|
+
}
|
|
5168
|
+
};
|
|
5084
5169
|
function namespaceKeys(namespaces) {
|
|
5085
5170
|
if (Array.isArray(namespaces)) {
|
|
5086
5171
|
return namespaces;
|
|
@@ -5099,11 +5184,11 @@ function namespaceEntries(namespaces) {
|
|
|
5099
5184
|
return [];
|
|
5100
5185
|
}
|
|
5101
5186
|
}
|
|
5102
|
-
function maybeParseURL(
|
|
5103
|
-
if (typeof
|
|
5187
|
+
function maybeParseURL(url18) {
|
|
5188
|
+
if (typeof url18 !== "string" || import_path14.default.isAbsolute(url18))
|
|
5104
5189
|
return;
|
|
5105
5190
|
try {
|
|
5106
|
-
return new URL(
|
|
5191
|
+
return new URL(url18);
|
|
5107
5192
|
} catch {
|
|
5108
5193
|
}
|
|
5109
5194
|
}
|
|
@@ -5112,16 +5197,16 @@ function getPersistPath(pluginName, tmpPath, persist) {
|
|
|
5112
5197
|
if (persist === void 0 || persist === false) {
|
|
5113
5198
|
return memoryishPath;
|
|
5114
5199
|
}
|
|
5115
|
-
const
|
|
5116
|
-
if (
|
|
5117
|
-
if (
|
|
5200
|
+
const url18 = maybeParseURL(persist);
|
|
5201
|
+
if (url18 !== void 0) {
|
|
5202
|
+
if (url18.protocol === "memory:") {
|
|
5118
5203
|
return memoryishPath;
|
|
5119
|
-
} else if (
|
|
5120
|
-
return (0, import_url12.fileURLToPath)(
|
|
5204
|
+
} else if (url18.protocol === "file:") {
|
|
5205
|
+
return (0, import_url12.fileURLToPath)(url18);
|
|
5121
5206
|
}
|
|
5122
5207
|
throw new MiniflareCoreError(
|
|
5123
5208
|
"ERR_PERSIST_UNSUPPORTED",
|
|
5124
|
-
`Unsupported "${
|
|
5209
|
+
`Unsupported "${url18.protocol}" persistence protocol for storage: ${url18.href}`
|
|
5125
5210
|
);
|
|
5126
5211
|
}
|
|
5127
5212
|
return persist === true ? import_path14.default.join(DEFAULT_PERSIST_ROOT, pluginName) : persist;
|
|
@@ -5164,11 +5249,11 @@ async function migrateDatabase(log, uniqueKey, persistPath, namespace) {
|
|
|
5164
5249
|
}
|
|
5165
5250
|
|
|
5166
5251
|
// src/plugins/cache/index.ts
|
|
5167
|
-
var CacheOptionsSchema =
|
|
5168
|
-
cache:
|
|
5169
|
-
cacheWarnUsage:
|
|
5252
|
+
var CacheOptionsSchema = import_zod7.z.object({
|
|
5253
|
+
cache: import_zod7.z.boolean().optional(),
|
|
5254
|
+
cacheWarnUsage: import_zod7.z.boolean().optional()
|
|
5170
5255
|
});
|
|
5171
|
-
var CacheSharedOptionsSchema =
|
|
5256
|
+
var CacheSharedOptionsSchema = import_zod7.z.object({
|
|
5172
5257
|
cachePersist: PersistenceSchema
|
|
5173
5258
|
});
|
|
5174
5259
|
var CACHE_PLUGIN_NAME = "cache";
|
|
@@ -5287,35 +5372,43 @@ var CACHE_PLUGIN = {
|
|
|
5287
5372
|
|
|
5288
5373
|
// src/plugins/do/index.ts
|
|
5289
5374
|
var import_promises5 = __toESM(require("fs/promises"));
|
|
5290
|
-
var
|
|
5291
|
-
var DurableObjectsOptionsSchema =
|
|
5292
|
-
durableObjects:
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
className:
|
|
5297
|
-
scriptName:
|
|
5375
|
+
var import_zod8 = require("zod");
|
|
5376
|
+
var DurableObjectsOptionsSchema = import_zod8.z.object({
|
|
5377
|
+
durableObjects: import_zod8.z.record(
|
|
5378
|
+
import_zod8.z.union([
|
|
5379
|
+
import_zod8.z.string(),
|
|
5380
|
+
import_zod8.z.object({
|
|
5381
|
+
className: import_zod8.z.string(),
|
|
5382
|
+
scriptName: import_zod8.z.string().optional(),
|
|
5383
|
+
useSQLite: import_zod8.z.boolean().optional(),
|
|
5298
5384
|
// Allow `uniqueKey` to be customised. We use in Wrangler when setting
|
|
5299
5385
|
// up stub Durable Objects that proxy requests to Durable Objects in
|
|
5300
5386
|
// another `workerd` process, to ensure the IDs created by the stub
|
|
5301
5387
|
// object can be used by the real object too.
|
|
5302
|
-
unsafeUniqueKey:
|
|
5388
|
+
unsafeUniqueKey: import_zod8.z.union([import_zod8.z.string(), import_zod8.z.literal(kUnsafeEphemeralUniqueKey)]).optional(),
|
|
5303
5389
|
// Prevents the Durable Object being evicted.
|
|
5304
|
-
unsafePreventEviction:
|
|
5390
|
+
unsafePreventEviction: import_zod8.z.boolean().optional()
|
|
5305
5391
|
})
|
|
5306
5392
|
])
|
|
5307
5393
|
).optional()
|
|
5308
5394
|
});
|
|
5309
|
-
var DurableObjectsSharedOptionsSchema =
|
|
5395
|
+
var DurableObjectsSharedOptionsSchema = import_zod8.z.object({
|
|
5310
5396
|
durableObjectsPersist: PersistenceSchema
|
|
5311
5397
|
});
|
|
5312
5398
|
function normaliseDurableObject(designator) {
|
|
5313
5399
|
const isObject = typeof designator === "object";
|
|
5314
5400
|
const className = isObject ? designator.className : designator;
|
|
5315
5401
|
const serviceName = isObject && designator.scriptName !== void 0 ? getUserServiceName(designator.scriptName) : void 0;
|
|
5402
|
+
const enableSql = isObject ? designator.useSQLite : void 0;
|
|
5316
5403
|
const unsafeUniqueKey = isObject ? designator.unsafeUniqueKey : void 0;
|
|
5317
5404
|
const unsafePreventEviction = isObject ? designator.unsafePreventEviction : void 0;
|
|
5318
|
-
return {
|
|
5405
|
+
return {
|
|
5406
|
+
className,
|
|
5407
|
+
serviceName,
|
|
5408
|
+
enableSql,
|
|
5409
|
+
unsafeUniqueKey,
|
|
5410
|
+
unsafePreventEviction
|
|
5411
|
+
};
|
|
5319
5412
|
}
|
|
5320
5413
|
var DURABLE_OBJECTS_PLUGIN_NAME = "do";
|
|
5321
5414
|
var DURABLE_OBJECTS_STORAGE_SERVICE_NAME = `${DURABLE_OBJECTS_PLUGIN_NAME}:storage`;
|
|
@@ -5335,7 +5428,9 @@ var DURABLE_OBJECTS_PLUGIN = {
|
|
|
5335
5428
|
},
|
|
5336
5429
|
getNodeBindings(options) {
|
|
5337
5430
|
const objects = Object.keys(options.durableObjects ?? {});
|
|
5338
|
-
return Object.fromEntries(
|
|
5431
|
+
return Object.fromEntries(
|
|
5432
|
+
objects.map((name) => [name, new ProxyNodeBinding()])
|
|
5433
|
+
);
|
|
5339
5434
|
},
|
|
5340
5435
|
async getServices({
|
|
5341
5436
|
sharedOptions,
|
|
@@ -5405,7 +5500,52 @@ var import_url13 = require("url");
|
|
|
5405
5500
|
var import_util = require("util");
|
|
5406
5501
|
var import_acorn = require("acorn");
|
|
5407
5502
|
var import_acorn_walk = require("acorn-walk");
|
|
5408
|
-
var
|
|
5503
|
+
var import_zod9 = require("zod");
|
|
5504
|
+
|
|
5505
|
+
// src/plugins/core/node-compat.ts
|
|
5506
|
+
function getNodeCompat(compatibilityDate = "2000-01-01", compatibilityFlags, opts) {
|
|
5507
|
+
const { nodeCompat = false } = opts ?? {};
|
|
5508
|
+
const {
|
|
5509
|
+
hasNodejsAlsFlag,
|
|
5510
|
+
hasNodejsCompatFlag,
|
|
5511
|
+
hasNodejsCompatV2Flag,
|
|
5512
|
+
hasNoNodejsCompatV2Flag,
|
|
5513
|
+
hasExperimentalNodejsCompatV2Flag
|
|
5514
|
+
} = parseNodeCompatibilityFlags(compatibilityFlags);
|
|
5515
|
+
const nodeCompatSwitchOverDate = "2024-09-23";
|
|
5516
|
+
const legacy = nodeCompat === true;
|
|
5517
|
+
let mode = null;
|
|
5518
|
+
if (hasNodejsCompatV2Flag || hasNodejsCompatFlag && compatibilityDate >= nodeCompatSwitchOverDate && !hasNoNodejsCompatV2Flag) {
|
|
5519
|
+
mode = "v2";
|
|
5520
|
+
} else if (hasNodejsCompatFlag) {
|
|
5521
|
+
mode = "v1";
|
|
5522
|
+
} else if (hasNodejsAlsFlag) {
|
|
5523
|
+
mode = "als";
|
|
5524
|
+
} else if (legacy) {
|
|
5525
|
+
mode = "legacy";
|
|
5526
|
+
}
|
|
5527
|
+
return {
|
|
5528
|
+
mode,
|
|
5529
|
+
hasNodejsAlsFlag,
|
|
5530
|
+
hasNodejsCompatFlag,
|
|
5531
|
+
hasNodejsCompatV2Flag,
|
|
5532
|
+
hasNoNodejsCompatV2Flag,
|
|
5533
|
+
hasExperimentalNodejsCompatV2Flag
|
|
5534
|
+
};
|
|
5535
|
+
}
|
|
5536
|
+
function parseNodeCompatibilityFlags(compatibilityFlags) {
|
|
5537
|
+
return {
|
|
5538
|
+
hasNodejsAlsFlag: compatibilityFlags.includes("nodejs_als"),
|
|
5539
|
+
hasNodejsCompatFlag: compatibilityFlags.includes("nodejs_compat"),
|
|
5540
|
+
hasNodejsCompatV2Flag: compatibilityFlags.includes("nodejs_compat_v2"),
|
|
5541
|
+
hasNoNodejsCompatV2Flag: compatibilityFlags.includes("no_nodejs_compat_v2"),
|
|
5542
|
+
hasExperimentalNodejsCompatV2Flag: compatibilityFlags.includes(
|
|
5543
|
+
"experimental:nodejs_compat_v2"
|
|
5544
|
+
)
|
|
5545
|
+
};
|
|
5546
|
+
}
|
|
5547
|
+
|
|
5548
|
+
// src/plugins/core/modules.ts
|
|
5409
5549
|
var SUGGEST_BUNDLE = "If you're trying to import an npm package, you'll need to bundle your Worker first.";
|
|
5410
5550
|
var SUGGEST_NODE = "If you're trying to import a Node.js built-in module, or an npm package that uses Node.js built-ins, you'll either need to:\n- Bundle your Worker, configuring your bundler to polyfill Node.js built-ins\n- Configure your bundler to load Workers-compatible builds by changing the main fields/conditions\n- Enable the `nodejs_compat` compatibility flag and use the `NodeJsCompatModule` module type\n- Find an alternative package that doesn't require Node.js built-ins";
|
|
5411
5551
|
var builtinModulesWithPrefix = import_module.builtinModules.concat(
|
|
@@ -5419,7 +5559,7 @@ function maybeGetStringScriptPathIndex(scriptPath) {
|
|
|
5419
5559
|
const match = stringScriptRegexp.exec(scriptPath);
|
|
5420
5560
|
return match === null ? void 0 : parseInt(match[1]);
|
|
5421
5561
|
}
|
|
5422
|
-
var ModuleRuleTypeSchema =
|
|
5562
|
+
var ModuleRuleTypeSchema = import_zod9.z.enum([
|
|
5423
5563
|
"ESModule",
|
|
5424
5564
|
"CommonJS",
|
|
5425
5565
|
"NodeJsCompatModule",
|
|
@@ -5429,45 +5569,45 @@ var ModuleRuleTypeSchema = import_zod8.z.enum([
|
|
|
5429
5569
|
"PythonModule",
|
|
5430
5570
|
"PythonRequirement"
|
|
5431
5571
|
]);
|
|
5432
|
-
var ModuleRuleSchema =
|
|
5572
|
+
var ModuleRuleSchema = import_zod9.z.object({
|
|
5433
5573
|
type: ModuleRuleTypeSchema,
|
|
5434
|
-
include:
|
|
5435
|
-
fallthrough:
|
|
5574
|
+
include: import_zod9.z.string().array(),
|
|
5575
|
+
fallthrough: import_zod9.z.boolean().optional()
|
|
5436
5576
|
});
|
|
5437
|
-
var ModuleDefinitionSchema =
|
|
5577
|
+
var ModuleDefinitionSchema = import_zod9.z.object({
|
|
5438
5578
|
type: ModuleRuleTypeSchema,
|
|
5439
5579
|
path: PathSchema,
|
|
5440
|
-
contents:
|
|
5580
|
+
contents: import_zod9.z.string().or(import_zod9.z.instanceof(Uint8Array)).optional()
|
|
5441
5581
|
});
|
|
5442
|
-
var SourceOptionsSchema =
|
|
5443
|
-
|
|
5582
|
+
var SourceOptionsSchema = import_zod9.z.union([
|
|
5583
|
+
import_zod9.z.object({
|
|
5444
5584
|
// Manually defined modules
|
|
5445
5585
|
// (used by Wrangler which has its own module collection code)
|
|
5446
|
-
modules:
|
|
5586
|
+
modules: import_zod9.z.array(ModuleDefinitionSchema),
|
|
5447
5587
|
// `modules` "name"s will be their paths relative to this value.
|
|
5448
5588
|
// This ensures file paths in stack traces are correct.
|
|
5449
5589
|
modulesRoot: PathSchema.optional()
|
|
5450
5590
|
}),
|
|
5451
|
-
|
|
5452
|
-
script:
|
|
5591
|
+
import_zod9.z.object({
|
|
5592
|
+
script: import_zod9.z.string(),
|
|
5453
5593
|
// Optional script path for resolving modules, and stack traces file names
|
|
5454
5594
|
scriptPath: PathSchema.optional(),
|
|
5455
5595
|
// Automatically collect modules by parsing `script` if `true`, or treat as
|
|
5456
5596
|
// service-worker if `false`
|
|
5457
|
-
modules:
|
|
5597
|
+
modules: import_zod9.z.boolean().optional(),
|
|
5458
5598
|
// How to interpret automatically collected modules
|
|
5459
|
-
modulesRules:
|
|
5599
|
+
modulesRules: import_zod9.z.array(ModuleRuleSchema).optional(),
|
|
5460
5600
|
// `modules` "name"s will be their paths relative to this value.
|
|
5461
5601
|
// This ensures file paths in stack traces are correct.
|
|
5462
5602
|
modulesRoot: PathSchema.optional()
|
|
5463
5603
|
}),
|
|
5464
|
-
|
|
5604
|
+
import_zod9.z.object({
|
|
5465
5605
|
scriptPath: PathSchema,
|
|
5466
5606
|
// Automatically collect modules by parsing `scriptPath` if `true`, or treat
|
|
5467
5607
|
// as service-worker if `false`
|
|
5468
|
-
modules:
|
|
5608
|
+
modules: import_zod9.z.boolean().optional(),
|
|
5469
5609
|
// How to interpret automatically collected modules
|
|
5470
|
-
modulesRules:
|
|
5610
|
+
modulesRules: import_zod9.z.array(ModuleRuleSchema).optional(),
|
|
5471
5611
|
// `modules` "name"s will be their paths relative to this value.
|
|
5472
5612
|
// This ensures file paths in stack traces are correct.
|
|
5473
5613
|
modulesRoot: PathSchema.optional()
|
|
@@ -5513,15 +5653,18 @@ function getResolveErrorPrefix(referencingPath) {
|
|
|
5513
5653
|
return `Unable to resolve "${relative}" dependency`;
|
|
5514
5654
|
}
|
|
5515
5655
|
var ModuleLocator = class {
|
|
5516
|
-
constructor(modulesRoot, additionalModuleNames, rules = [], compatibilityFlags) {
|
|
5656
|
+
constructor(modulesRoot, additionalModuleNames, rules = [], compatibilityDate, compatibilityFlags) {
|
|
5517
5657
|
this.modulesRoot = modulesRoot;
|
|
5518
5658
|
this.additionalModuleNames = additionalModuleNames;
|
|
5519
5659
|
rules = rules.concat(DEFAULT_MODULE_RULES);
|
|
5520
5660
|
this.#compiledRules = compileModuleRules(rules);
|
|
5521
|
-
this.#
|
|
5661
|
+
this.#nodejsCompatMode = getNodeCompat(
|
|
5662
|
+
compatibilityDate,
|
|
5663
|
+
compatibilityFlags ?? []
|
|
5664
|
+
).mode;
|
|
5522
5665
|
}
|
|
5523
5666
|
#compiledRules;
|
|
5524
|
-
#
|
|
5667
|
+
#nodejsCompatMode;
|
|
5525
5668
|
#visitedPaths = /* @__PURE__ */ new Set();
|
|
5526
5669
|
modules = [];
|
|
5527
5670
|
visitEntrypoint(code, modulePath) {
|
|
@@ -5605,7 +5748,14 @@ ${dim(modulesConfig)}`;
|
|
|
5605
5748
|
}
|
|
5606
5749
|
const spec = specExpression.value;
|
|
5607
5750
|
const isNodeJsCompatModule = referencingType === "NodeJsCompatModule";
|
|
5608
|
-
if (
|
|
5751
|
+
if (
|
|
5752
|
+
// `cloudflare:` and `workerd:` imports don't need to be included explicitly
|
|
5753
|
+
spec.startsWith("cloudflare:") || spec.startsWith("workerd:") || // Node.js compat v1 requires imports to be prefixed with `node:`
|
|
5754
|
+
this.#nodejsCompatMode === "v1" && spec.startsWith("node:") || // Node.js compat modules and v2 can also handle non-prefixed imports
|
|
5755
|
+
(this.#nodejsCompatMode === "v2" || isNodeJsCompatModule) && builtinModulesWithPrefix.includes(spec) || // Async Local Storage mode (node_als) only deals with `node:async_hooks` imports
|
|
5756
|
+
this.#nodejsCompatMode === "als" && spec === "node:async_hooks" || // Any "additional" external modules can be ignored
|
|
5757
|
+
this.additionalModuleNames.includes(spec)
|
|
5758
|
+
) {
|
|
5609
5759
|
return;
|
|
5610
5760
|
}
|
|
5611
5761
|
if (maybeGetStringScriptPathIndex(referencingName) !== void 0) {
|
|
@@ -5676,60 +5826,60 @@ function createJavaScriptModule(code, name, modulePath, type) {
|
|
|
5676
5826
|
}
|
|
5677
5827
|
var encoder = new import_util.TextEncoder();
|
|
5678
5828
|
var decoder = new import_util.TextDecoder();
|
|
5679
|
-
function contentsToString(
|
|
5680
|
-
return typeof
|
|
5829
|
+
function contentsToString(contents18) {
|
|
5830
|
+
return typeof contents18 === "string" ? contents18 : decoder.decode(contents18);
|
|
5681
5831
|
}
|
|
5682
|
-
function contentsToArray(
|
|
5683
|
-
return typeof
|
|
5832
|
+
function contentsToArray(contents18) {
|
|
5833
|
+
return typeof contents18 === "string" ? encoder.encode(contents18) : contents18;
|
|
5684
5834
|
}
|
|
5685
5835
|
function convertModuleDefinition(modulesRoot, def) {
|
|
5686
5836
|
const name = moduleName(modulesRoot, def.path);
|
|
5687
|
-
const
|
|
5837
|
+
const contents18 = def.contents ?? (0, import_fs12.readFileSync)(def.path);
|
|
5688
5838
|
switch (def.type) {
|
|
5689
5839
|
case "ESModule":
|
|
5690
5840
|
case "CommonJS":
|
|
5691
5841
|
case "NodeJsCompatModule":
|
|
5692
5842
|
return createJavaScriptModule(
|
|
5693
|
-
contentsToString(
|
|
5843
|
+
contentsToString(contents18),
|
|
5694
5844
|
name,
|
|
5695
5845
|
import_path15.default.resolve(modulesRoot, def.path),
|
|
5696
5846
|
def.type
|
|
5697
5847
|
);
|
|
5698
5848
|
case "Text":
|
|
5699
|
-
return { name, text: contentsToString(
|
|
5849
|
+
return { name, text: contentsToString(contents18) };
|
|
5700
5850
|
case "Data":
|
|
5701
|
-
return { name, data: contentsToArray(
|
|
5851
|
+
return { name, data: contentsToArray(contents18) };
|
|
5702
5852
|
case "CompiledWasm":
|
|
5703
|
-
return { name, wasm: contentsToArray(
|
|
5853
|
+
return { name, wasm: contentsToArray(contents18) };
|
|
5704
5854
|
case "PythonModule":
|
|
5705
|
-
return { name, pythonModule: contentsToString(
|
|
5855
|
+
return { name, pythonModule: contentsToString(contents18) };
|
|
5706
5856
|
case "PythonRequirement":
|
|
5707
|
-
return { name, pythonRequirement: contentsToString(
|
|
5857
|
+
return { name, pythonRequirement: contentsToString(contents18) };
|
|
5708
5858
|
default:
|
|
5709
5859
|
const exhaustive = def.type;
|
|
5710
5860
|
import_assert5.default.fail(`Unreachable: ${exhaustive} modules are unsupported`);
|
|
5711
5861
|
}
|
|
5712
5862
|
}
|
|
5713
5863
|
function convertWorkerModule(mod) {
|
|
5714
|
-
const
|
|
5715
|
-
(0, import_assert5.default)(
|
|
5864
|
+
const path28 = mod.name;
|
|
5865
|
+
(0, import_assert5.default)(path28 !== void 0);
|
|
5716
5866
|
const m = mod;
|
|
5717
5867
|
if ("esModule" in m)
|
|
5718
|
-
return { path:
|
|
5868
|
+
return { path: path28, type: "ESModule" };
|
|
5719
5869
|
else if ("commonJsModule" in m)
|
|
5720
|
-
return { path:
|
|
5870
|
+
return { path: path28, type: "CommonJS" };
|
|
5721
5871
|
else if ("nodeJsCompatModule" in m)
|
|
5722
|
-
return { path:
|
|
5872
|
+
return { path: path28, type: "NodeJsCompatModule" };
|
|
5723
5873
|
else if ("text" in m)
|
|
5724
|
-
return { path:
|
|
5874
|
+
return { path: path28, type: "Text" };
|
|
5725
5875
|
else if ("data" in m)
|
|
5726
|
-
return { path:
|
|
5876
|
+
return { path: path28, type: "Data" };
|
|
5727
5877
|
else if ("wasm" in m)
|
|
5728
|
-
return { path:
|
|
5878
|
+
return { path: path28, type: "CompiledWasm" };
|
|
5729
5879
|
else if ("pythonModule" in m)
|
|
5730
|
-
return { path:
|
|
5880
|
+
return { path: path28, type: "PythonModule" };
|
|
5731
5881
|
else if ("pythonRequirement" in m)
|
|
5732
|
-
return { path:
|
|
5882
|
+
return { path: path28, type: "PythonRequirement" };
|
|
5733
5883
|
(0, import_assert5.default)(
|
|
5734
5884
|
!("json" in m || "fallbackService" in m),
|
|
5735
5885
|
"Unreachable: json or fallbackService modules aren't generated"
|
|
@@ -5758,7 +5908,7 @@ var import_worker_threads = require("worker_threads");
|
|
|
5758
5908
|
var import_fs13 = __toESM(require("fs"));
|
|
5759
5909
|
var import_path16 = __toESM(require("path"));
|
|
5760
5910
|
var import_url14 = require("url");
|
|
5761
|
-
var
|
|
5911
|
+
var import_zod10 = require("zod");
|
|
5762
5912
|
|
|
5763
5913
|
// src/plugins/core/errors/sourcemap.ts
|
|
5764
5914
|
var import_assert6 = __toESM(require("assert"));
|
|
@@ -5932,8 +6082,8 @@ function getSourceMapper() {
|
|
|
5932
6082
|
// src/plugins/core/errors/index.ts
|
|
5933
6083
|
function maybeGetDiskFile(filePath) {
|
|
5934
6084
|
try {
|
|
5935
|
-
const
|
|
5936
|
-
return { path: filePath, contents:
|
|
6085
|
+
const contents18 = import_fs13.default.readFileSync(filePath, "utf8");
|
|
6086
|
+
return { path: filePath, contents: contents18 };
|
|
5937
6087
|
} catch (e) {
|
|
5938
6088
|
if (e.code !== "ENOENT")
|
|
5939
6089
|
throw e;
|
|
@@ -5948,8 +6098,8 @@ function maybeGetFile(workerSrcOpts, fileSpecifier) {
|
|
|
5948
6098
|
const modulesRoot = srcOpts.modulesRoot ?? "";
|
|
5949
6099
|
for (const module2 of srcOpts.modules) {
|
|
5950
6100
|
if (module2.contents !== void 0 && import_path16.default.resolve(modulesRoot, module2.path) === filePath) {
|
|
5951
|
-
const
|
|
5952
|
-
return { path: filePath, contents:
|
|
6101
|
+
const contents18 = contentsToString(module2.contents);
|
|
6102
|
+
return { path: filePath, contents: contents18 };
|
|
5953
6103
|
}
|
|
5954
6104
|
}
|
|
5955
6105
|
} else if ("script" in srcOpts && "scriptPath" in srcOpts && srcOpts.script !== void 0 && srcOpts.scriptPath !== void 0) {
|
|
@@ -5988,11 +6138,11 @@ function getSourceMappedStack(workerSrcOpts, error) {
|
|
|
5988
6138
|
}
|
|
5989
6139
|
return getSourceMapper()(retrieveSourceMap, error);
|
|
5990
6140
|
}
|
|
5991
|
-
var JsonErrorSchema =
|
|
5992
|
-
() =>
|
|
5993
|
-
message:
|
|
5994
|
-
name:
|
|
5995
|
-
stack:
|
|
6141
|
+
var JsonErrorSchema = import_zod10.z.lazy(
|
|
6142
|
+
() => import_zod10.z.object({
|
|
6143
|
+
message: import_zod10.z.string().optional(),
|
|
6144
|
+
name: import_zod10.z.string().optional(),
|
|
6145
|
+
stack: import_zod10.z.string().optional(),
|
|
5996
6146
|
cause: JsonErrorSchema.optional()
|
|
5997
6147
|
})
|
|
5998
6148
|
);
|
|
@@ -6133,7 +6283,7 @@ var SynchronousFetcher = class {
|
|
|
6133
6283
|
transferList: [this.#channel.port2]
|
|
6134
6284
|
});
|
|
6135
6285
|
}
|
|
6136
|
-
fetch(
|
|
6286
|
+
fetch(url18, init2) {
|
|
6137
6287
|
this.#ensureWorker();
|
|
6138
6288
|
Atomics.store(
|
|
6139
6289
|
this.#notifyHandle,
|
|
@@ -6146,7 +6296,7 @@ var SynchronousFetcher = class {
|
|
|
6146
6296
|
this.#channel.port1.postMessage({
|
|
6147
6297
|
id,
|
|
6148
6298
|
method: init2.method,
|
|
6149
|
-
url:
|
|
6299
|
+
url: url18.toString(),
|
|
6150
6300
|
headers: init2.headers,
|
|
6151
6301
|
body: init2.body
|
|
6152
6302
|
});
|
|
@@ -6266,8 +6416,8 @@ var ProxyClient = class {
|
|
|
6266
6416
|
}
|
|
6267
6417
|
};
|
|
6268
6418
|
var ProxyClientBridge = class {
|
|
6269
|
-
constructor(
|
|
6270
|
-
this.url =
|
|
6419
|
+
constructor(url18, dispatchFetch) {
|
|
6420
|
+
this.url = url18;
|
|
6271
6421
|
this.dispatchFetch = dispatchFetch;
|
|
6272
6422
|
this.#finalizationRegistry = new FinalizationRegistry(this.#finalizeProxy);
|
|
6273
6423
|
}
|
|
@@ -6670,73 +6820,73 @@ var ProxyStubHandler = class extends Function {
|
|
|
6670
6820
|
};
|
|
6671
6821
|
|
|
6672
6822
|
// src/plugins/core/services.ts
|
|
6673
|
-
var
|
|
6823
|
+
var import_zod11 = require("zod");
|
|
6674
6824
|
var kCurrentWorker = Symbol.for("miniflare.kCurrentWorker");
|
|
6675
|
-
var HttpOptionsHeaderSchema =
|
|
6676
|
-
name:
|
|
6825
|
+
var HttpOptionsHeaderSchema = import_zod11.z.object({
|
|
6826
|
+
name: import_zod11.z.string(),
|
|
6677
6827
|
// name should be required
|
|
6678
|
-
value:
|
|
6828
|
+
value: import_zod11.z.ostring()
|
|
6679
6829
|
// If omitted, the header will be removed
|
|
6680
6830
|
});
|
|
6681
|
-
var HttpOptionsSchema =
|
|
6682
|
-
style:
|
|
6683
|
-
forwardedProtoHeader:
|
|
6684
|
-
cfBlobHeader:
|
|
6831
|
+
var HttpOptionsSchema = import_zod11.z.object({
|
|
6832
|
+
style: import_zod11.z.nativeEnum(import_workerd_capnp.HttpOptions_Style).optional(),
|
|
6833
|
+
forwardedProtoHeader: import_zod11.z.ostring(),
|
|
6834
|
+
cfBlobHeader: import_zod11.z.ostring(),
|
|
6685
6835
|
injectRequestHeaders: HttpOptionsHeaderSchema.array().optional(),
|
|
6686
6836
|
injectResponseHeaders: HttpOptionsHeaderSchema.array().optional()
|
|
6687
6837
|
}).transform((options) => ({
|
|
6688
6838
|
...options,
|
|
6689
6839
|
capnpConnectHost: HOST_CAPNP_CONNECT
|
|
6690
6840
|
}));
|
|
6691
|
-
var TlsOptionsKeypairSchema =
|
|
6692
|
-
privateKey:
|
|
6693
|
-
certificateChain:
|
|
6841
|
+
var TlsOptionsKeypairSchema = import_zod11.z.object({
|
|
6842
|
+
privateKey: import_zod11.z.ostring(),
|
|
6843
|
+
certificateChain: import_zod11.z.ostring()
|
|
6694
6844
|
});
|
|
6695
|
-
var TlsOptionsSchema =
|
|
6845
|
+
var TlsOptionsSchema = import_zod11.z.object({
|
|
6696
6846
|
keypair: TlsOptionsKeypairSchema.optional(),
|
|
6697
|
-
requireClientCerts:
|
|
6698
|
-
trustBrowserCas:
|
|
6699
|
-
trustedCertificates:
|
|
6700
|
-
minVersion:
|
|
6701
|
-
cipherList:
|
|
6847
|
+
requireClientCerts: import_zod11.z.oboolean(),
|
|
6848
|
+
trustBrowserCas: import_zod11.z.oboolean(),
|
|
6849
|
+
trustedCertificates: import_zod11.z.string().array().optional(),
|
|
6850
|
+
minVersion: import_zod11.z.nativeEnum(import_workerd_capnp.TlsOptions_Version).optional(),
|
|
6851
|
+
cipherList: import_zod11.z.ostring()
|
|
6702
6852
|
});
|
|
6703
|
-
var NetworkSchema =
|
|
6704
|
-
allow:
|
|
6705
|
-
deny:
|
|
6853
|
+
var NetworkSchema = import_zod11.z.object({
|
|
6854
|
+
allow: import_zod11.z.string().array().optional(),
|
|
6855
|
+
deny: import_zod11.z.string().array().optional(),
|
|
6706
6856
|
tlsOptions: TlsOptionsSchema.optional()
|
|
6707
6857
|
});
|
|
6708
|
-
var ExternalServerSchema =
|
|
6709
|
-
|
|
6858
|
+
var ExternalServerSchema = import_zod11.z.intersection(
|
|
6859
|
+
import_zod11.z.object({ address: import_zod11.z.string() }),
|
|
6710
6860
|
// address should be required
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
https:
|
|
6715
|
-
|
|
6861
|
+
import_zod11.z.union([
|
|
6862
|
+
import_zod11.z.object({ http: import_zod11.z.optional(HttpOptionsSchema) }),
|
|
6863
|
+
import_zod11.z.object({
|
|
6864
|
+
https: import_zod11.z.optional(
|
|
6865
|
+
import_zod11.z.object({
|
|
6716
6866
|
options: HttpOptionsSchema.optional(),
|
|
6717
6867
|
tlsOptions: TlsOptionsSchema.optional(),
|
|
6718
|
-
certificateHost:
|
|
6868
|
+
certificateHost: import_zod11.z.ostring()
|
|
6719
6869
|
})
|
|
6720
6870
|
)
|
|
6721
6871
|
})
|
|
6722
6872
|
])
|
|
6723
6873
|
);
|
|
6724
|
-
var DiskDirectorySchema =
|
|
6725
|
-
path:
|
|
6874
|
+
var DiskDirectorySchema = import_zod11.z.object({
|
|
6875
|
+
path: import_zod11.z.string(),
|
|
6726
6876
|
// path should be required
|
|
6727
|
-
writable:
|
|
6877
|
+
writable: import_zod11.z.oboolean()
|
|
6728
6878
|
});
|
|
6729
|
-
var ServiceFetchSchema =
|
|
6730
|
-
var ServiceDesignatorSchema =
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
name:
|
|
6735
|
-
entrypoint:
|
|
6879
|
+
var ServiceFetchSchema = import_zod11.z.custom((v) => typeof v === "function");
|
|
6880
|
+
var ServiceDesignatorSchema = import_zod11.z.union([
|
|
6881
|
+
import_zod11.z.string(),
|
|
6882
|
+
import_zod11.z.literal(kCurrentWorker),
|
|
6883
|
+
import_zod11.z.object({
|
|
6884
|
+
name: import_zod11.z.union([import_zod11.z.string(), import_zod11.z.literal(kCurrentWorker)]),
|
|
6885
|
+
entrypoint: import_zod11.z.ostring()
|
|
6736
6886
|
}),
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6887
|
+
import_zod11.z.object({ network: NetworkSchema }),
|
|
6888
|
+
import_zod11.z.object({ external: ExternalServerSchema }),
|
|
6889
|
+
import_zod11.z.object({ disk: DiskDirectorySchema }),
|
|
6740
6890
|
ServiceFetchSchema
|
|
6741
6891
|
]);
|
|
6742
6892
|
|
|
@@ -6758,39 +6908,43 @@ var numericCompare = new Intl.Collator(void 0, { numeric: true }).compare;
|
|
|
6758
6908
|
function createFetchMock() {
|
|
6759
6909
|
return new import_undici7.MockAgent();
|
|
6760
6910
|
}
|
|
6761
|
-
var WrappedBindingSchema =
|
|
6762
|
-
scriptName:
|
|
6763
|
-
entrypoint:
|
|
6764
|
-
bindings:
|
|
6911
|
+
var WrappedBindingSchema = import_zod12.z.object({
|
|
6912
|
+
scriptName: import_zod12.z.string(),
|
|
6913
|
+
entrypoint: import_zod12.z.string().optional(),
|
|
6914
|
+
bindings: import_zod12.z.record(JsonSchema).optional()
|
|
6765
6915
|
});
|
|
6766
|
-
var UnusableStringSchema =
|
|
6767
|
-
var UnsafeDirectSocketSchema =
|
|
6768
|
-
host:
|
|
6769
|
-
port:
|
|
6770
|
-
entrypoint:
|
|
6771
|
-
proxy:
|
|
6916
|
+
var UnusableStringSchema = import_zod12.z.string().transform(() => void 0);
|
|
6917
|
+
var UnsafeDirectSocketSchema = import_zod12.z.object({
|
|
6918
|
+
host: import_zod12.z.ostring(),
|
|
6919
|
+
port: import_zod12.z.onumber(),
|
|
6920
|
+
entrypoint: import_zod12.z.ostring(),
|
|
6921
|
+
proxy: import_zod12.z.oboolean()
|
|
6772
6922
|
});
|
|
6773
|
-
var CoreOptionsSchemaInput =
|
|
6923
|
+
var CoreOptionsSchemaInput = import_zod12.z.intersection(
|
|
6774
6924
|
SourceOptionsSchema,
|
|
6775
|
-
|
|
6776
|
-
name:
|
|
6925
|
+
import_zod12.z.object({
|
|
6926
|
+
name: import_zod12.z.string().optional(),
|
|
6777
6927
|
rootPath: UnusableStringSchema.optional(),
|
|
6778
|
-
compatibilityDate:
|
|
6779
|
-
compatibilityFlags:
|
|
6780
|
-
routes:
|
|
6781
|
-
bindings:
|
|
6782
|
-
wasmBindings:
|
|
6783
|
-
textBlobBindings:
|
|
6784
|
-
dataBlobBindings:
|
|
6785
|
-
serviceBindings:
|
|
6786
|
-
wrappedBindings:
|
|
6928
|
+
compatibilityDate: import_zod12.z.string().optional(),
|
|
6929
|
+
compatibilityFlags: import_zod12.z.string().array().optional(),
|
|
6930
|
+
routes: import_zod12.z.string().array().optional(),
|
|
6931
|
+
bindings: import_zod12.z.record(JsonSchema).optional(),
|
|
6932
|
+
wasmBindings: import_zod12.z.record(import_zod12.z.union([PathSchema, import_zod12.z.instanceof(Uint8Array)])).optional(),
|
|
6933
|
+
textBlobBindings: import_zod12.z.record(PathSchema).optional(),
|
|
6934
|
+
dataBlobBindings: import_zod12.z.record(import_zod12.z.union([PathSchema, import_zod12.z.instanceof(Uint8Array)])).optional(),
|
|
6935
|
+
serviceBindings: import_zod12.z.record(ServiceDesignatorSchema).optional(),
|
|
6936
|
+
wrappedBindings: import_zod12.z.record(import_zod12.z.union([import_zod12.z.string(), WrappedBindingSchema])).optional(),
|
|
6787
6937
|
outboundService: ServiceDesignatorSchema.optional(),
|
|
6788
|
-
fetchMock:
|
|
6938
|
+
fetchMock: import_zod12.z.instanceof(import_undici7.MockAgent).optional(),
|
|
6789
6939
|
// TODO(soon): remove this in favour of per-object `unsafeUniqueKey: kEphemeralUniqueKey`
|
|
6790
|
-
unsafeEphemeralDurableObjects:
|
|
6940
|
+
unsafeEphemeralDurableObjects: import_zod12.z.boolean().optional(),
|
|
6791
6941
|
unsafeDirectSockets: UnsafeDirectSocketSchema.array().optional(),
|
|
6792
|
-
unsafeEvalBinding:
|
|
6793
|
-
unsafeUseModuleFallbackService:
|
|
6942
|
+
unsafeEvalBinding: import_zod12.z.string().optional(),
|
|
6943
|
+
unsafeUseModuleFallbackService: import_zod12.z.boolean().optional(),
|
|
6944
|
+
/** Used to set the vitest pool worker SELF binding to point to the router worker if there are assets.
|
|
6945
|
+
(If there are assets but we're not using vitest, the miniflare entry worker can point directly to RW.)
|
|
6946
|
+
*/
|
|
6947
|
+
hasAssetsAndIsVitest: import_zod12.z.boolean().optional()
|
|
6794
6948
|
})
|
|
6795
6949
|
);
|
|
6796
6950
|
var CoreOptionsSchema = CoreOptionsSchemaInput.transform((value) => {
|
|
@@ -6806,30 +6960,30 @@ var CoreOptionsSchema = CoreOptionsSchemaInput.transform((value) => {
|
|
|
6806
6960
|
}
|
|
6807
6961
|
return value;
|
|
6808
6962
|
});
|
|
6809
|
-
var CoreSharedOptionsSchema =
|
|
6963
|
+
var CoreSharedOptionsSchema = import_zod12.z.object({
|
|
6810
6964
|
rootPath: UnusableStringSchema.optional(),
|
|
6811
|
-
host:
|
|
6812
|
-
port:
|
|
6813
|
-
https:
|
|
6814
|
-
httpsKey:
|
|
6815
|
-
httpsKeyPath:
|
|
6816
|
-
httpsCert:
|
|
6817
|
-
httpsCertPath:
|
|
6818
|
-
inspectorPort:
|
|
6819
|
-
verbose:
|
|
6820
|
-
log:
|
|
6821
|
-
handleRuntimeStdio:
|
|
6822
|
-
upstream:
|
|
6965
|
+
host: import_zod12.z.string().optional(),
|
|
6966
|
+
port: import_zod12.z.number().optional(),
|
|
6967
|
+
https: import_zod12.z.boolean().optional(),
|
|
6968
|
+
httpsKey: import_zod12.z.string().optional(),
|
|
6969
|
+
httpsKeyPath: import_zod12.z.string().optional(),
|
|
6970
|
+
httpsCert: import_zod12.z.string().optional(),
|
|
6971
|
+
httpsCertPath: import_zod12.z.string().optional(),
|
|
6972
|
+
inspectorPort: import_zod12.z.number().optional(),
|
|
6973
|
+
verbose: import_zod12.z.boolean().optional(),
|
|
6974
|
+
log: import_zod12.z.instanceof(Log).optional(),
|
|
6975
|
+
handleRuntimeStdio: import_zod12.z.function(import_zod12.z.tuple([import_zod12.z.instanceof(import_stream2.Readable), import_zod12.z.instanceof(import_stream2.Readable)])).optional(),
|
|
6976
|
+
upstream: import_zod12.z.string().optional(),
|
|
6823
6977
|
// TODO: add back validation of cf object
|
|
6824
|
-
cf:
|
|
6825
|
-
liveReload:
|
|
6978
|
+
cf: import_zod12.z.union([import_zod12.z.boolean(), import_zod12.z.string(), import_zod12.z.record(import_zod12.z.any())]).optional(),
|
|
6979
|
+
liveReload: import_zod12.z.boolean().optional(),
|
|
6826
6980
|
// This is a shared secret between a proxy server and miniflare that can be
|
|
6827
6981
|
// passed in a header to prove that the request came from the proxy and not
|
|
6828
6982
|
// some malicious attacker.
|
|
6829
|
-
unsafeProxySharedSecret:
|
|
6983
|
+
unsafeProxySharedSecret: import_zod12.z.string().optional(),
|
|
6830
6984
|
unsafeModuleFallbackService: ServiceFetchSchema.optional(),
|
|
6831
6985
|
// Keep blobs when deleting/overwriting keys, required for stacked storage
|
|
6832
|
-
unsafeStickyBlobs:
|
|
6986
|
+
unsafeStickyBlobs: import_zod12.z.boolean().optional()
|
|
6833
6987
|
});
|
|
6834
6988
|
var CORE_PLUGIN_NAME2 = "core";
|
|
6835
6989
|
var LIVE_RELOAD_SCRIPT_TEMPLATE = (port) => `<script defer type="application/javascript">
|
|
@@ -6855,7 +7009,7 @@ var SCRIPT_CUSTOM_SERVICE = `addEventListener("fetch", (event) => {
|
|
|
6855
7009
|
request.headers.set("${CoreHeaders.ORIGINAL_URL}", request.url);
|
|
6856
7010
|
event.respondWith(${CoreBindings.SERVICE_LOOPBACK}.fetch(request));
|
|
6857
7011
|
})`;
|
|
6858
|
-
function getCustomServiceDesignator(refererName, workerIndex, kind, name, service) {
|
|
7012
|
+
function getCustomServiceDesignator(refererName, workerIndex, kind, name, service, hasAssetsAndIsVitest = false) {
|
|
6859
7013
|
let serviceName;
|
|
6860
7014
|
let entrypoint;
|
|
6861
7015
|
if (typeof service === "function") {
|
|
@@ -6872,7 +7026,7 @@ function getCustomServiceDesignator(refererName, workerIndex, kind, name, servic
|
|
|
6872
7026
|
serviceName = getBuiltinServiceName(workerIndex, kind, name);
|
|
6873
7027
|
}
|
|
6874
7028
|
} else if (service === kCurrentWorker) {
|
|
6875
|
-
serviceName = getUserServiceName(refererName);
|
|
7029
|
+
serviceName = hasAssetsAndIsVitest ? ROUTER_SERVICE_NAME : getUserServiceName(refererName);
|
|
6876
7030
|
} else {
|
|
6877
7031
|
serviceName = getUserServiceName(service);
|
|
6878
7032
|
}
|
|
@@ -6928,11 +7082,20 @@ function validateCompatibilityDate(log, compatibilityDate) {
|
|
|
6928
7082
|
}
|
|
6929
7083
|
return compatibilityDate;
|
|
6930
7084
|
}
|
|
6931
|
-
function
|
|
6932
|
-
return Object.entries(bindings).map(([name, value]) =>
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
|
|
7085
|
+
function buildBindings(bindings) {
|
|
7086
|
+
return Object.entries(bindings).map(([name, value]) => {
|
|
7087
|
+
if (typeof value === "string") {
|
|
7088
|
+
return {
|
|
7089
|
+
name,
|
|
7090
|
+
text: value
|
|
7091
|
+
};
|
|
7092
|
+
} else {
|
|
7093
|
+
return {
|
|
7094
|
+
name,
|
|
7095
|
+
json: JSON.stringify(value)
|
|
7096
|
+
};
|
|
7097
|
+
}
|
|
7098
|
+
});
|
|
6936
7099
|
}
|
|
6937
7100
|
var WRAPPED_MODULE_PREFIX = "miniflare-internal:wrapped:";
|
|
6938
7101
|
function workerNameToWrappedModule(workerName) {
|
|
@@ -6949,7 +7112,7 @@ var CORE_PLUGIN = {
|
|
|
6949
7112
|
getBindings(options, workerIndex) {
|
|
6950
7113
|
const bindings = [];
|
|
6951
7114
|
if (options.bindings !== void 0) {
|
|
6952
|
-
bindings.push(...
|
|
7115
|
+
bindings.push(...buildBindings(options.bindings));
|
|
6953
7116
|
}
|
|
6954
7117
|
if (options.wasmBindings !== void 0) {
|
|
6955
7118
|
bindings.push(
|
|
@@ -6961,7 +7124,7 @@ var CORE_PLUGIN = {
|
|
|
6961
7124
|
if (options.textBlobBindings !== void 0) {
|
|
6962
7125
|
bindings.push(
|
|
6963
7126
|
...Object.entries(options.textBlobBindings).map(
|
|
6964
|
-
([name,
|
|
7127
|
+
([name, path28]) => import_promises6.default.readFile(path28, "utf8").then((text) => ({ name, text }))
|
|
6965
7128
|
)
|
|
6966
7129
|
);
|
|
6967
7130
|
}
|
|
@@ -6983,7 +7146,8 @@ var CORE_PLUGIN = {
|
|
|
6983
7146
|
workerIndex,
|
|
6984
7147
|
"#" /* UNKNOWN */,
|
|
6985
7148
|
name,
|
|
6986
|
-
service
|
|
7149
|
+
service,
|
|
7150
|
+
options.hasAssetsAndIsVitest
|
|
6987
7151
|
)
|
|
6988
7152
|
};
|
|
6989
7153
|
})
|
|
@@ -6997,7 +7161,7 @@ var CORE_PLUGIN = {
|
|
|
6997
7161
|
const entrypoint = isObject ? designator.entrypoint : void 0;
|
|
6998
7162
|
const bindings2 = isObject ? designator.bindings : void 0;
|
|
6999
7163
|
const moduleName2 = workerNameToWrappedModule(scriptName);
|
|
7000
|
-
const innerBindings = bindings2 === void 0 ? [] :
|
|
7164
|
+
const innerBindings = bindings2 === void 0 ? [] : buildBindings(bindings2);
|
|
7001
7165
|
return {
|
|
7002
7166
|
name,
|
|
7003
7167
|
wrapped: { moduleName: moduleName2, entrypoint, innerBindings }
|
|
@@ -7033,7 +7197,7 @@ var CORE_PLUGIN = {
|
|
|
7033
7197
|
if (options.textBlobBindings !== void 0) {
|
|
7034
7198
|
bindingEntries2.push(
|
|
7035
7199
|
...Object.entries(options.textBlobBindings).map(
|
|
7036
|
-
([name,
|
|
7200
|
+
([name, path28]) => import_promises6.default.readFile(path28, "utf8").then((text) => [name, text])
|
|
7037
7201
|
)
|
|
7038
7202
|
);
|
|
7039
7203
|
}
|
|
@@ -7048,7 +7212,7 @@ var CORE_PLUGIN = {
|
|
|
7048
7212
|
bindingEntries2.push(
|
|
7049
7213
|
...Object.keys(options.serviceBindings).map((name) => [
|
|
7050
7214
|
name,
|
|
7051
|
-
|
|
7215
|
+
new ProxyNodeBinding()
|
|
7052
7216
|
])
|
|
7053
7217
|
);
|
|
7054
7218
|
}
|
|
@@ -7056,7 +7220,7 @@ var CORE_PLUGIN = {
|
|
|
7056
7220
|
bindingEntries2.push(
|
|
7057
7221
|
...Object.keys(options.wrappedBindings).map((name) => [
|
|
7058
7222
|
name,
|
|
7059
|
-
|
|
7223
|
+
new ProxyNodeBinding()
|
|
7060
7224
|
])
|
|
7061
7225
|
);
|
|
7062
7226
|
}
|
|
@@ -7174,16 +7338,21 @@ Ensure ${stringName} doesn't include unbundled \`import\`s.`
|
|
|
7174
7338
|
compatibilityFlags: options.compatibilityFlags,
|
|
7175
7339
|
bindings: workerBindings,
|
|
7176
7340
|
durableObjectNamespaces: classNamesEntries.map(
|
|
7177
|
-
([
|
|
7341
|
+
([
|
|
7342
|
+
className,
|
|
7343
|
+
{ enableSql, unsafeUniqueKey, unsafePreventEviction }
|
|
7344
|
+
]) => {
|
|
7178
7345
|
if (unsafeUniqueKey === kUnsafeEphemeralUniqueKey) {
|
|
7179
7346
|
return {
|
|
7180
7347
|
className,
|
|
7348
|
+
enableSql,
|
|
7181
7349
|
ephemeralLocal: kVoid,
|
|
7182
7350
|
preventEviction: unsafePreventEviction
|
|
7183
7351
|
};
|
|
7184
7352
|
} else {
|
|
7185
7353
|
return {
|
|
7186
7354
|
className,
|
|
7355
|
+
enableSql,
|
|
7187
7356
|
// This `uniqueKey` will (among other things) be used as part of the
|
|
7188
7357
|
// path when persisting to the file-system. `-` is invalid in
|
|
7189
7358
|
// JavaScript class names, but safe on filesystems (incl. Windows).
|
|
@@ -7200,7 +7369,8 @@ Ensure ${stringName} doesn't include unbundled \`import\`s.`
|
|
|
7200
7369
|
workerIndex,
|
|
7201
7370
|
"$" /* KNOWN */,
|
|
7202
7371
|
CUSTOM_SERVICE_KNOWN_OUTBOUND,
|
|
7203
|
-
options.outboundService
|
|
7372
|
+
options.outboundService,
|
|
7373
|
+
options.hasAssetsAndIsVitest
|
|
7204
7374
|
),
|
|
7205
7375
|
cacheApiOutbound: { name: getCacheServiceName(workerIndex) },
|
|
7206
7376
|
moduleFallback: options.unsafeUseModuleFallbackService && sharedOptions.unsafeModuleFallbackService !== void 0 ? `localhost:${loopbackPort}` : void 0
|
|
@@ -7363,6 +7533,7 @@ function getWorkerScript(options, workerIndex, additionalModuleNames) {
|
|
|
7363
7533
|
modulesRoot,
|
|
7364
7534
|
additionalModuleNames,
|
|
7365
7535
|
options.modulesRules,
|
|
7536
|
+
options.compatibilityDate,
|
|
7366
7537
|
options.compatibilityFlags
|
|
7367
7538
|
);
|
|
7368
7539
|
locator.visitEntrypoint(code, scriptPath);
|
|
@@ -7373,23 +7544,17 @@ function getWorkerScript(options, workerIndex, additionalModuleNames) {
|
|
|
7373
7544
|
}
|
|
7374
7545
|
}
|
|
7375
7546
|
|
|
7376
|
-
// src/plugins/assets/constants.ts
|
|
7377
|
-
var ASSETS_PLUGIN_NAME = "assets";
|
|
7378
|
-
var ASSETS_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:assets-service`;
|
|
7379
|
-
var ROUTER_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:router`;
|
|
7380
|
-
var ASSETS_KV_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:kv`;
|
|
7381
|
-
|
|
7382
7547
|
// src/plugins/assets/schema.ts
|
|
7383
|
-
var
|
|
7384
|
-
var
|
|
7385
|
-
|
|
7386
|
-
|
|
7387
|
-
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7548
|
+
var import_zod13 = require("zod");
|
|
7549
|
+
var AssetsOptionsSchema = import_zod13.z.object({
|
|
7550
|
+
assets: import_zod13.z.object({
|
|
7551
|
+
// User worker name or vitest runner - this is only ever set inside miniflare
|
|
7552
|
+
// The assets plugin needs access to the worker name to create the router worker - user worker binding
|
|
7553
|
+
workerName: import_zod13.z.string().optional(),
|
|
7554
|
+
directory: PathSchema,
|
|
7555
|
+
binding: import_zod13.z.string().optional(),
|
|
7556
|
+
routingConfig: RoutingConfigSchema.optional(),
|
|
7557
|
+
assetConfig: AssetConfigSchema.optional()
|
|
7393
7558
|
}).optional()
|
|
7394
7559
|
});
|
|
7395
7560
|
|
|
@@ -7397,35 +7562,37 @@ var AssetsOptionsSchema = import_zod12.z.object({
|
|
|
7397
7562
|
var ASSETS_PLUGIN = {
|
|
7398
7563
|
options: AssetsOptionsSchema,
|
|
7399
7564
|
async getBindings(options) {
|
|
7400
|
-
if (!options.assets?.
|
|
7565
|
+
if (!options.assets?.binding) {
|
|
7401
7566
|
return [];
|
|
7402
7567
|
}
|
|
7403
7568
|
return [
|
|
7404
7569
|
{
|
|
7405
7570
|
// binding between User Worker and Asset Worker
|
|
7406
|
-
name: options.assets.
|
|
7571
|
+
name: options.assets.binding,
|
|
7407
7572
|
service: { name: ASSETS_SERVICE_NAME }
|
|
7408
7573
|
}
|
|
7409
7574
|
];
|
|
7410
7575
|
},
|
|
7411
7576
|
async getNodeBindings(options) {
|
|
7412
|
-
if (!options.assets?.
|
|
7577
|
+
if (!options.assets?.binding) {
|
|
7413
7578
|
return {};
|
|
7414
7579
|
}
|
|
7415
7580
|
return {
|
|
7416
|
-
[options.assets.
|
|
7581
|
+
[options.assets.binding]: new ProxyNodeBinding()
|
|
7417
7582
|
};
|
|
7418
7583
|
},
|
|
7419
7584
|
async getServices({ options }) {
|
|
7420
7585
|
if (!options.assets) {
|
|
7421
7586
|
return [];
|
|
7422
7587
|
}
|
|
7423
|
-
const assetsReverseMap = await createReverseMap(options.assets?.path);
|
|
7424
7588
|
const storageServiceName = `${ASSETS_PLUGIN_NAME}:storage`;
|
|
7425
7589
|
const storageService = {
|
|
7426
7590
|
name: storageServiceName,
|
|
7427
|
-
disk: { path: options.assets.
|
|
7591
|
+
disk: { path: options.assets.directory, writable: true }
|
|
7428
7592
|
};
|
|
7593
|
+
const { encodedAssetManifest, assetsReverseMap } = await buildAssetManifest(
|
|
7594
|
+
options.assets.directory
|
|
7595
|
+
);
|
|
7429
7596
|
const namespaceService = {
|
|
7430
7597
|
name: ASSETS_KV_SERVICE_NAME,
|
|
7431
7598
|
worker: {
|
|
@@ -7444,12 +7611,11 @@ var ASSETS_PLUGIN = {
|
|
|
7444
7611
|
},
|
|
7445
7612
|
{
|
|
7446
7613
|
name: "ASSETS_REVERSE_MAP",
|
|
7447
|
-
json: assetsReverseMap
|
|
7614
|
+
json: JSON.stringify(assetsReverseMap)
|
|
7448
7615
|
}
|
|
7449
7616
|
]
|
|
7450
7617
|
}
|
|
7451
7618
|
};
|
|
7452
|
-
const assetsManifest = await buildAssetsManifest(options.assets.path);
|
|
7453
7619
|
const assetService = {
|
|
7454
7620
|
name: ASSETS_SERVICE_NAME,
|
|
7455
7621
|
worker: {
|
|
@@ -7467,7 +7633,11 @@ var ASSETS_PLUGIN = {
|
|
|
7467
7633
|
},
|
|
7468
7634
|
{
|
|
7469
7635
|
name: "ASSETS_MANIFEST",
|
|
7470
|
-
data:
|
|
7636
|
+
data: encodedAssetManifest
|
|
7637
|
+
},
|
|
7638
|
+
{
|
|
7639
|
+
name: "CONFIG",
|
|
7640
|
+
json: JSON.stringify(options.assets.assetConfig ?? {})
|
|
7471
7641
|
}
|
|
7472
7642
|
]
|
|
7473
7643
|
}
|
|
@@ -7501,40 +7671,25 @@ var ASSETS_PLUGIN = {
|
|
|
7501
7671
|
return [storageService, namespaceService, assetService, routerService];
|
|
7502
7672
|
}
|
|
7503
7673
|
};
|
|
7504
|
-
var
|
|
7505
|
-
|
|
7506
|
-
var MANIFEST_HEADER_SIZE = 20;
|
|
7507
|
-
var PATH_HASH_OFFSET = 0;
|
|
7508
|
-
var PATH_HASH_SIZE = 16;
|
|
7509
|
-
var CONTENT_HASH_OFFSET = PATH_HASH_SIZE;
|
|
7510
|
-
var CONTENT_HASH_SIZE = 16;
|
|
7511
|
-
var TAIL_RESERVED_SIZE = 8;
|
|
7512
|
-
var ENTRY_SIZE = PATH_HASH_SIZE + CONTENT_HASH_SIZE + TAIL_RESERVED_SIZE;
|
|
7513
|
-
var buildAssetsManifest = async (dir) => {
|
|
7514
|
-
const manifest = await walk(dir);
|
|
7674
|
+
var buildAssetManifest = async (dir) => {
|
|
7675
|
+
const { manifest, assetsReverseMap } = await walk(dir);
|
|
7515
7676
|
const sortedAssetManifest = sortManifest(manifest);
|
|
7516
7677
|
const encodedAssetManifest = encodeManifest(sortedAssetManifest);
|
|
7517
|
-
return encodedAssetManifest;
|
|
7678
|
+
return { encodedAssetManifest, assetsReverseMap };
|
|
7518
7679
|
};
|
|
7519
7680
|
var walk = async (dir) => {
|
|
7520
7681
|
const files = await import_promises7.default.readdir(dir, { recursive: true });
|
|
7521
7682
|
const manifest = [];
|
|
7683
|
+
const assetsReverseMap = {};
|
|
7522
7684
|
let counter = 0;
|
|
7523
7685
|
await Promise.all(
|
|
7524
7686
|
files.map(async (file) => {
|
|
7525
|
-
const filepath =
|
|
7526
|
-
const relativeFilepath =
|
|
7687
|
+
const filepath = import_node_path2.default.join(dir, file);
|
|
7688
|
+
const relativeFilepath = import_node_path2.default.relative(dir, filepath);
|
|
7527
7689
|
const filestat = await import_promises7.default.stat(filepath);
|
|
7528
7690
|
if (filestat.isSymbolicLink() || filestat.isDirectory()) {
|
|
7529
7691
|
return;
|
|
7530
7692
|
} else {
|
|
7531
|
-
if (counter >= MAX_ASSET_COUNT) {
|
|
7532
|
-
throw new Error(
|
|
7533
|
-
`Maximum number of assets exceeded.
|
|
7534
|
-
Cloudflare Workers supports up to ${MAX_ASSET_COUNT.toLocaleString()} assets in a version. We found ${counter.toLocaleString()} files in the specified assets directory "${dir}".
|
|
7535
|
-
Ensure your assets directory contains a maximum of ${MAX_ASSET_COUNT.toLocaleString()} files, and that you have specified your assets directory correctly.`
|
|
7536
|
-
);
|
|
7537
|
-
}
|
|
7538
7693
|
if (filestat.size > MAX_ASSET_SIZE) {
|
|
7539
7694
|
throw new Error(
|
|
7540
7695
|
`Asset too large.
|
|
@@ -7552,38 +7707,47 @@ Cloudflare Workers supports assets with sizes of up to ${prettyBytes(
|
|
|
7552
7707
|
Ensure all assets in your assets directory "${dir}" conform with the Workers maximum size requirement.`
|
|
7553
7708
|
);
|
|
7554
7709
|
}
|
|
7555
|
-
|
|
7710
|
+
const [pathHash, contentHash] = await Promise.all([
|
|
7711
|
+
hashPath(normalizeFilePath(relativeFilepath)),
|
|
7712
|
+
// used absolute filepath here so that changes to the enclosing asset folder will be registered
|
|
7713
|
+
hashPath(filepath + filestat.mtimeMs.toString())
|
|
7714
|
+
]);
|
|
7715
|
+
manifest.push({
|
|
7716
|
+
pathHash,
|
|
7717
|
+
contentHash
|
|
7718
|
+
});
|
|
7719
|
+
assetsReverseMap[bytesToHex(contentHash)] = {
|
|
7720
|
+
filePath: relativeFilepath,
|
|
7721
|
+
contentType: getContentType(filepath)
|
|
7722
|
+
};
|
|
7556
7723
|
counter++;
|
|
7557
7724
|
}
|
|
7558
7725
|
})
|
|
7559
7726
|
);
|
|
7560
|
-
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
|
|
7567
|
-
};
|
|
7568
|
-
var encodeFilePath = (filePath) => {
|
|
7569
|
-
const encodedPath = filePath.split(import_node_path.default.sep).map((segment) => encodeURIComponent(segment)).join("/");
|
|
7570
|
-
return "/" + encodedPath;
|
|
7727
|
+
if (counter > MAX_ASSET_COUNT) {
|
|
7728
|
+
throw new Error(
|
|
7729
|
+
`Maximum number of assets exceeded.
|
|
7730
|
+
Cloudflare Workers supports up to ${MAX_ASSET_COUNT.toLocaleString()} assets in a version. We found ${counter.toLocaleString()} files in the specified assets directory "${dir}".
|
|
7731
|
+
Ensure your assets directory contains a maximum of ${MAX_ASSET_COUNT.toLocaleString()} files, and that you have specified your assets directory correctly.`
|
|
7732
|
+
);
|
|
7733
|
+
}
|
|
7734
|
+
return { manifest, assetsReverseMap };
|
|
7571
7735
|
};
|
|
7572
7736
|
var sortManifest = (manifest) => {
|
|
7573
7737
|
return manifest.sort(comparisonFn);
|
|
7574
7738
|
};
|
|
7575
7739
|
var comparisonFn = (a, b) => {
|
|
7576
|
-
if (a.length < b.length) {
|
|
7740
|
+
if (a.pathHash.length < b.pathHash.length) {
|
|
7577
7741
|
return -1;
|
|
7578
7742
|
}
|
|
7579
|
-
if (a.length > b.length) {
|
|
7743
|
+
if (a.pathHash.length > b.pathHash.length) {
|
|
7580
7744
|
return 1;
|
|
7581
7745
|
}
|
|
7582
|
-
for (const [i, v] of a.entries()) {
|
|
7583
|
-
if (v < b[i]) {
|
|
7746
|
+
for (const [i, v] of a.pathHash.entries()) {
|
|
7747
|
+
if (v < b.pathHash[i]) {
|
|
7584
7748
|
return -1;
|
|
7585
7749
|
}
|
|
7586
|
-
if (v > b[i]) {
|
|
7750
|
+
if (v > b.pathHash[i]) {
|
|
7587
7751
|
return 1;
|
|
7588
7752
|
}
|
|
7589
7753
|
}
|
|
@@ -7591,41 +7755,27 @@ var comparisonFn = (a, b) => {
|
|
|
7591
7755
|
};
|
|
7592
7756
|
var encodeManifest = (manifest) => {
|
|
7593
7757
|
const assetManifestBytes = new Uint8Array(
|
|
7594
|
-
|
|
7758
|
+
HEADER_SIZE + manifest.length * ENTRY_SIZE
|
|
7595
7759
|
);
|
|
7596
7760
|
for (const [i, entry] of manifest.entries()) {
|
|
7597
|
-
const entryOffset =
|
|
7598
|
-
assetManifestBytes.set(entry, entryOffset + PATH_HASH_OFFSET);
|
|
7599
|
-
assetManifestBytes.set(
|
|
7761
|
+
const entryOffset = HEADER_SIZE + i * ENTRY_SIZE;
|
|
7762
|
+
assetManifestBytes.set(entry.pathHash, entryOffset + PATH_HASH_OFFSET);
|
|
7763
|
+
assetManifestBytes.set(
|
|
7764
|
+
entry.contentHash,
|
|
7765
|
+
entryOffset + CONTENT_HASH_OFFSET
|
|
7766
|
+
);
|
|
7600
7767
|
}
|
|
7601
7768
|
return assetManifestBytes;
|
|
7602
7769
|
};
|
|
7603
|
-
var createReverseMap = async (dir) => {
|
|
7604
|
-
const files = await import_promises7.default.readdir(dir, { recursive: true });
|
|
7605
|
-
const assetsReverseMap = {};
|
|
7606
|
-
await Promise.all(
|
|
7607
|
-
files.map(async (file) => {
|
|
7608
|
-
const filepath = import_node_path.default.join(dir, file);
|
|
7609
|
-
const relativeFilepath = import_node_path.default.relative(dir, filepath);
|
|
7610
|
-
const filestat = await import_promises7.default.stat(filepath);
|
|
7611
|
-
if (filestat.isSymbolicLink() || filestat.isDirectory()) {
|
|
7612
|
-
return;
|
|
7613
|
-
} else {
|
|
7614
|
-
const pathHash = bytesToHex(
|
|
7615
|
-
await hashPath(encodeFilePath(relativeFilepath))
|
|
7616
|
-
);
|
|
7617
|
-
assetsReverseMap[pathHash] = {
|
|
7618
|
-
filePath: relativeFilepath,
|
|
7619
|
-
contentType: (0, import_mime.getType)(filepath) ?? "application/octet-stream"
|
|
7620
|
-
};
|
|
7621
|
-
}
|
|
7622
|
-
})
|
|
7623
|
-
);
|
|
7624
|
-
return JSON.stringify(assetsReverseMap);
|
|
7625
|
-
};
|
|
7626
7770
|
var bytesToHex = (buffer) => {
|
|
7627
7771
|
return [...new Uint8Array(buffer)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
7628
7772
|
};
|
|
7773
|
+
var hashPath = async (path28) => {
|
|
7774
|
+
const encoder3 = new TextEncoder();
|
|
7775
|
+
const data = encoder3.encode(path28);
|
|
7776
|
+
const hashBuffer = await import_node_crypto.default.subtle.digest("SHA-256", data.buffer);
|
|
7777
|
+
return new Uint8Array(hashBuffer, 0, PATH_HASH_SIZE);
|
|
7778
|
+
};
|
|
7629
7779
|
|
|
7630
7780
|
// src/plugins/d1/index.ts
|
|
7631
7781
|
var import_promises8 = __toESM(require("fs/promises"));
|
|
@@ -7644,11 +7794,11 @@ function database_worker_default() {
|
|
|
7644
7794
|
}
|
|
7645
7795
|
|
|
7646
7796
|
// src/plugins/d1/index.ts
|
|
7647
|
-
var
|
|
7648
|
-
var D1OptionsSchema =
|
|
7649
|
-
d1Databases:
|
|
7797
|
+
var import_zod14 = require("zod");
|
|
7798
|
+
var D1OptionsSchema = import_zod14.z.object({
|
|
7799
|
+
d1Databases: import_zod14.z.union([import_zod14.z.record(import_zod14.z.string()), import_zod14.z.string().array()]).optional()
|
|
7650
7800
|
});
|
|
7651
|
-
var D1SharedOptionsSchema =
|
|
7801
|
+
var D1SharedOptionsSchema = import_zod14.z.object({
|
|
7652
7802
|
d1Persist: PersistenceSchema
|
|
7653
7803
|
});
|
|
7654
7804
|
var D1_PLUGIN_NAME = "d1";
|
|
@@ -7690,7 +7840,7 @@ var D1_PLUGIN = {
|
|
|
7690
7840
|
getNodeBindings(options) {
|
|
7691
7841
|
const databases = namespaceKeys(options.d1Databases);
|
|
7692
7842
|
return Object.fromEntries(
|
|
7693
|
-
databases.map((name) => [name,
|
|
7843
|
+
databases.map((name) => [name, new ProxyNodeBinding()])
|
|
7694
7844
|
);
|
|
7695
7845
|
},
|
|
7696
7846
|
async getServices({
|
|
@@ -7761,68 +7911,68 @@ var D1_PLUGIN = {
|
|
|
7761
7911
|
|
|
7762
7912
|
// src/plugins/hyperdrive/index.ts
|
|
7763
7913
|
var import_node_assert3 = __toESM(require("node:assert"));
|
|
7764
|
-
var
|
|
7914
|
+
var import_zod15 = require("zod");
|
|
7765
7915
|
var HYPERDRIVE_PLUGIN_NAME = "hyperdrive";
|
|
7766
|
-
function hasPostgresProtocol(
|
|
7767
|
-
return
|
|
7916
|
+
function hasPostgresProtocol(url18) {
|
|
7917
|
+
return url18.protocol === "postgresql:" || url18.protocol === "postgres:";
|
|
7768
7918
|
}
|
|
7769
|
-
function getPort(
|
|
7770
|
-
if (
|
|
7771
|
-
return
|
|
7772
|
-
if (hasPostgresProtocol(
|
|
7919
|
+
function getPort(url18) {
|
|
7920
|
+
if (url18.port !== "")
|
|
7921
|
+
return url18.port;
|
|
7922
|
+
if (hasPostgresProtocol(url18))
|
|
7773
7923
|
return "5432";
|
|
7774
|
-
import_node_assert3.default.fail(`Expected known protocol, got ${
|
|
7924
|
+
import_node_assert3.default.fail(`Expected known protocol, got ${url18.protocol}`);
|
|
7775
7925
|
}
|
|
7776
|
-
var HyperdriveSchema =
|
|
7777
|
-
if (typeof
|
|
7778
|
-
|
|
7779
|
-
if (
|
|
7926
|
+
var HyperdriveSchema = import_zod15.z.union([import_zod15.z.string().url(), import_zod15.z.instanceof(URL)]).transform((url18, ctx) => {
|
|
7927
|
+
if (typeof url18 === "string")
|
|
7928
|
+
url18 = new URL(url18);
|
|
7929
|
+
if (url18.protocol === "") {
|
|
7780
7930
|
ctx.addIssue({
|
|
7781
|
-
code:
|
|
7931
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
7782
7932
|
message: "You must specify the database protocol - e.g. 'postgresql'."
|
|
7783
7933
|
});
|
|
7784
|
-
} else if (!hasPostgresProtocol(
|
|
7934
|
+
} else if (!hasPostgresProtocol(url18)) {
|
|
7785
7935
|
ctx.addIssue({
|
|
7786
|
-
code:
|
|
7936
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
7787
7937
|
message: "Only PostgreSQL or PostgreSQL compatible databases are currently supported."
|
|
7788
7938
|
});
|
|
7789
7939
|
}
|
|
7790
|
-
if (
|
|
7940
|
+
if (url18.host === "") {
|
|
7791
7941
|
ctx.addIssue({
|
|
7792
|
-
code:
|
|
7942
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
7793
7943
|
message: "You must provide a hostname or IP address in your connection string - e.g. 'user:password@database-hostname.example.com:5432/databasename"
|
|
7794
7944
|
});
|
|
7795
7945
|
}
|
|
7796
|
-
if (
|
|
7946
|
+
if (url18.pathname === "") {
|
|
7797
7947
|
ctx.addIssue({
|
|
7798
|
-
code:
|
|
7948
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
7799
7949
|
message: "You must provide a database name as the path component - e.g. /postgres"
|
|
7800
7950
|
});
|
|
7801
7951
|
}
|
|
7802
|
-
if (
|
|
7952
|
+
if (url18.username === "") {
|
|
7803
7953
|
ctx.addIssue({
|
|
7804
|
-
code:
|
|
7954
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
7805
7955
|
message: "You must provide a username - e.g. 'user:password@database.example.com:port/databasename'"
|
|
7806
7956
|
});
|
|
7807
7957
|
}
|
|
7808
|
-
if (
|
|
7958
|
+
if (url18.password === "") {
|
|
7809
7959
|
ctx.addIssue({
|
|
7810
|
-
code:
|
|
7960
|
+
code: import_zod15.z.ZodIssueCode.custom,
|
|
7811
7961
|
message: "You must provide a password - e.g. 'user:password@database.example.com:port/databasename' "
|
|
7812
7962
|
});
|
|
7813
7963
|
}
|
|
7814
|
-
return
|
|
7964
|
+
return url18;
|
|
7815
7965
|
});
|
|
7816
|
-
var HyperdriveInputOptionsSchema =
|
|
7817
|
-
hyperdrives:
|
|
7966
|
+
var HyperdriveInputOptionsSchema = import_zod15.z.object({
|
|
7967
|
+
hyperdrives: import_zod15.z.record(import_zod15.z.string(), HyperdriveSchema).optional()
|
|
7818
7968
|
});
|
|
7819
7969
|
var HYPERDRIVE_PLUGIN = {
|
|
7820
7970
|
options: HyperdriveInputOptionsSchema,
|
|
7821
7971
|
getBindings(options) {
|
|
7822
7972
|
return Object.entries(options.hyperdrives ?? {}).map(
|
|
7823
|
-
([name,
|
|
7824
|
-
const database =
|
|
7825
|
-
const scheme =
|
|
7973
|
+
([name, url18]) => {
|
|
7974
|
+
const database = url18.pathname.replace("/", "");
|
|
7975
|
+
const scheme = url18.protocol.replace(":", "");
|
|
7826
7976
|
return {
|
|
7827
7977
|
name,
|
|
7828
7978
|
hyperdrive: {
|
|
@@ -7830,23 +7980,37 @@ var HYPERDRIVE_PLUGIN = {
|
|
|
7830
7980
|
name: `${HYPERDRIVE_PLUGIN_NAME}:${name}`
|
|
7831
7981
|
},
|
|
7832
7982
|
database: decodeURIComponent(database),
|
|
7833
|
-
user: decodeURIComponent(
|
|
7834
|
-
password: decodeURIComponent(
|
|
7983
|
+
user: decodeURIComponent(url18.username),
|
|
7984
|
+
password: decodeURIComponent(url18.password),
|
|
7835
7985
|
scheme
|
|
7836
7986
|
}
|
|
7837
7987
|
};
|
|
7838
7988
|
}
|
|
7839
7989
|
);
|
|
7840
7990
|
},
|
|
7841
|
-
getNodeBindings() {
|
|
7842
|
-
return
|
|
7991
|
+
getNodeBindings(options) {
|
|
7992
|
+
return Object.fromEntries(
|
|
7993
|
+
Object.entries(options.hyperdrives ?? {}).map(([name, url18]) => {
|
|
7994
|
+
const connectionOverrides = {
|
|
7995
|
+
connectionString: `${url18}`,
|
|
7996
|
+
port: Number.parseInt(url18.port),
|
|
7997
|
+
host: url18.hostname
|
|
7998
|
+
};
|
|
7999
|
+
const proxyNodeBinding = new ProxyNodeBinding({
|
|
8000
|
+
get(target, prop) {
|
|
8001
|
+
return prop in connectionOverrides ? connectionOverrides[prop] : target[prop];
|
|
8002
|
+
}
|
|
8003
|
+
});
|
|
8004
|
+
return [name, proxyNodeBinding];
|
|
8005
|
+
})
|
|
8006
|
+
);
|
|
7843
8007
|
},
|
|
7844
8008
|
async getServices({ options }) {
|
|
7845
8009
|
return Object.entries(options.hyperdrives ?? {}).map(
|
|
7846
|
-
([name,
|
|
8010
|
+
([name, url18]) => ({
|
|
7847
8011
|
name: `${HYPERDRIVE_PLUGIN_NAME}:${name}`,
|
|
7848
8012
|
external: {
|
|
7849
|
-
address: `${
|
|
8013
|
+
address: `${url18.hostname}:${getPort(url18)}`,
|
|
7850
8014
|
tcp: {}
|
|
7851
8015
|
}
|
|
7852
8016
|
})
|
|
@@ -7871,7 +8035,7 @@ function namespace_worker_default() {
|
|
|
7871
8035
|
}
|
|
7872
8036
|
|
|
7873
8037
|
// src/plugins/kv/index.ts
|
|
7874
|
-
var
|
|
8038
|
+
var import_zod16 = require("zod");
|
|
7875
8039
|
|
|
7876
8040
|
// src/plugins/kv/constants.ts
|
|
7877
8041
|
var KV_PLUGIN_NAME = "kv";
|
|
@@ -7950,7 +8114,7 @@ async function getSitesNodeBindings(options) {
|
|
|
7950
8114
|
siteRegExps
|
|
7951
8115
|
);
|
|
7952
8116
|
return {
|
|
7953
|
-
[SiteBindings.KV_NAMESPACE_SITE]:
|
|
8117
|
+
[SiteBindings.KV_NAMESPACE_SITE]: new ProxyNodeBinding(),
|
|
7954
8118
|
[SiteBindings.JSON_SITE_MANIFEST]: __STATIC_CONTENT_MANIFEST
|
|
7955
8119
|
};
|
|
7956
8120
|
}
|
|
@@ -7991,14 +8155,14 @@ function getSitesServices(options) {
|
|
|
7991
8155
|
}
|
|
7992
8156
|
|
|
7993
8157
|
// src/plugins/kv/index.ts
|
|
7994
|
-
var KVOptionsSchema =
|
|
7995
|
-
kvNamespaces:
|
|
8158
|
+
var KVOptionsSchema = import_zod16.z.object({
|
|
8159
|
+
kvNamespaces: import_zod16.z.union([import_zod16.z.record(import_zod16.z.string()), import_zod16.z.string().array()]).optional(),
|
|
7996
8160
|
// Workers Sites
|
|
7997
8161
|
sitePath: PathSchema.optional(),
|
|
7998
|
-
siteInclude:
|
|
7999
|
-
siteExclude:
|
|
8162
|
+
siteInclude: import_zod16.z.string().array().optional(),
|
|
8163
|
+
siteExclude: import_zod16.z.string().array().optional()
|
|
8000
8164
|
});
|
|
8001
|
-
var KVSharedOptionsSchema =
|
|
8165
|
+
var KVSharedOptionsSchema = import_zod16.z.object({
|
|
8002
8166
|
kvPersist: PersistenceSchema
|
|
8003
8167
|
});
|
|
8004
8168
|
var SERVICE_NAMESPACE_PREFIX = `${KV_PLUGIN_NAME}:ns`;
|
|
@@ -8028,7 +8192,7 @@ var KV_PLUGIN = {
|
|
|
8028
8192
|
async getNodeBindings(options) {
|
|
8029
8193
|
const namespaces = namespaceKeys(options.kvNamespaces);
|
|
8030
8194
|
const bindings = Object.fromEntries(
|
|
8031
|
-
namespaces.map((name) => [name,
|
|
8195
|
+
namespaces.map((name) => [name, new ProxyNodeBinding()])
|
|
8032
8196
|
);
|
|
8033
8197
|
if (isWorkersSitesEnabled(options)) {
|
|
8034
8198
|
Object.assign(bindings, await getSitesNodeBindings(options));
|
|
@@ -8115,20 +8279,20 @@ function broker_worker_default() {
|
|
|
8115
8279
|
}
|
|
8116
8280
|
|
|
8117
8281
|
// src/plugins/queues/index.ts
|
|
8118
|
-
var
|
|
8282
|
+
var import_zod17 = require("zod");
|
|
8119
8283
|
|
|
8120
8284
|
// src/plugins/queues/errors.ts
|
|
8121
8285
|
var QueuesError = class extends MiniflareError {
|
|
8122
8286
|
};
|
|
8123
8287
|
|
|
8124
8288
|
// src/plugins/queues/index.ts
|
|
8125
|
-
var QueuesOptionsSchema =
|
|
8126
|
-
queueProducers:
|
|
8127
|
-
|
|
8128
|
-
|
|
8129
|
-
|
|
8289
|
+
var QueuesOptionsSchema = import_zod17.z.object({
|
|
8290
|
+
queueProducers: import_zod17.z.union([
|
|
8291
|
+
import_zod17.z.record(QueueProducerOptionsSchema),
|
|
8292
|
+
import_zod17.z.string().array(),
|
|
8293
|
+
import_zod17.z.record(import_zod17.z.string())
|
|
8130
8294
|
]).optional(),
|
|
8131
|
-
queueConsumers:
|
|
8295
|
+
queueConsumers: import_zod17.z.union([import_zod17.z.record(QueueConsumerOptionsSchema), import_zod17.z.string().array()]).optional()
|
|
8132
8296
|
});
|
|
8133
8297
|
var QUEUES_PLUGIN_NAME = "queues";
|
|
8134
8298
|
var SERVICE_QUEUE_PREFIX = `${QUEUES_PLUGIN_NAME}:queue`;
|
|
@@ -8148,7 +8312,9 @@ var QUEUES_PLUGIN = {
|
|
|
8148
8312
|
},
|
|
8149
8313
|
getNodeBindings(options) {
|
|
8150
8314
|
const queues = bindingKeys(options.queueProducers);
|
|
8151
|
-
return Object.fromEntries(
|
|
8315
|
+
return Object.fromEntries(
|
|
8316
|
+
queues.map((name) => [name, new ProxyNodeBinding()])
|
|
8317
|
+
);
|
|
8152
8318
|
},
|
|
8153
8319
|
async getServices({
|
|
8154
8320
|
options,
|
|
@@ -8178,7 +8344,11 @@ var QUEUES_PLUGIN = {
|
|
|
8178
8344
|
{ name: "broker.worker.js", esModule: broker_worker_default() }
|
|
8179
8345
|
],
|
|
8180
8346
|
durableObjectNamespaces: [
|
|
8181
|
-
{
|
|
8347
|
+
{
|
|
8348
|
+
className: QUEUE_BROKER_OBJECT_CLASS_NAME,
|
|
8349
|
+
uniqueKey,
|
|
8350
|
+
preventEviction: true
|
|
8351
|
+
}
|
|
8182
8352
|
],
|
|
8183
8353
|
// Miniflare's Queue broker is in-memory only at the moment
|
|
8184
8354
|
durableObjectStorage: { inMemory: kVoid },
|
|
@@ -8252,11 +8422,11 @@ function bucket_worker_default() {
|
|
|
8252
8422
|
}
|
|
8253
8423
|
|
|
8254
8424
|
// src/plugins/r2/index.ts
|
|
8255
|
-
var
|
|
8256
|
-
var R2OptionsSchema =
|
|
8257
|
-
r2Buckets:
|
|
8425
|
+
var import_zod18 = require("zod");
|
|
8426
|
+
var R2OptionsSchema = import_zod18.z.object({
|
|
8427
|
+
r2Buckets: import_zod18.z.union([import_zod18.z.record(import_zod18.z.string()), import_zod18.z.string().array()]).optional()
|
|
8258
8428
|
});
|
|
8259
|
-
var R2SharedOptionsSchema =
|
|
8429
|
+
var R2SharedOptionsSchema = import_zod18.z.object({
|
|
8260
8430
|
r2Persist: PersistenceSchema
|
|
8261
8431
|
});
|
|
8262
8432
|
var R2_PLUGIN_NAME = "r2";
|
|
@@ -8279,7 +8449,9 @@ var R2_PLUGIN = {
|
|
|
8279
8449
|
},
|
|
8280
8450
|
getNodeBindings(options) {
|
|
8281
8451
|
const buckets = namespaceKeys(options.r2Buckets);
|
|
8282
|
-
return Object.fromEntries(
|
|
8452
|
+
return Object.fromEntries(
|
|
8453
|
+
buckets.map((name) => [name, new ProxyNodeBinding()])
|
|
8454
|
+
);
|
|
8283
8455
|
},
|
|
8284
8456
|
async getServices({
|
|
8285
8457
|
options,
|
|
@@ -8361,26 +8533,26 @@ function ratelimit_worker_default() {
|
|
|
8361
8533
|
}
|
|
8362
8534
|
|
|
8363
8535
|
// src/plugins/ratelimit/index.ts
|
|
8364
|
-
var
|
|
8536
|
+
var import_zod19 = require("zod");
|
|
8365
8537
|
var PeriodType = /* @__PURE__ */ ((PeriodType2) => {
|
|
8366
8538
|
PeriodType2[PeriodType2["TENSECONDS"] = 10] = "TENSECONDS";
|
|
8367
8539
|
PeriodType2[PeriodType2["MINUTE"] = 60] = "MINUTE";
|
|
8368
8540
|
return PeriodType2;
|
|
8369
8541
|
})(PeriodType || {});
|
|
8370
|
-
var RatelimitConfigSchema =
|
|
8371
|
-
simple:
|
|
8372
|
-
limit:
|
|
8542
|
+
var RatelimitConfigSchema = import_zod19.z.object({
|
|
8543
|
+
simple: import_zod19.z.object({
|
|
8544
|
+
limit: import_zod19.z.number().gt(0),
|
|
8373
8545
|
// may relax this to be any number in the future
|
|
8374
|
-
period:
|
|
8546
|
+
period: import_zod19.z.nativeEnum(PeriodType).optional()
|
|
8375
8547
|
})
|
|
8376
8548
|
});
|
|
8377
|
-
var RatelimitOptionsSchema =
|
|
8378
|
-
ratelimits:
|
|
8549
|
+
var RatelimitOptionsSchema = import_zod19.z.object({
|
|
8550
|
+
ratelimits: import_zod19.z.record(RatelimitConfigSchema).optional()
|
|
8379
8551
|
});
|
|
8380
8552
|
var RATELIMIT_PLUGIN_NAME = "ratelimit";
|
|
8381
8553
|
var SERVICE_RATELIMIT_PREFIX = `${RATELIMIT_PLUGIN_NAME}`;
|
|
8382
8554
|
var SERVICE_RATELIMIT_MODULE = `cloudflare-internal:${SERVICE_RATELIMIT_PREFIX}:module`;
|
|
8383
|
-
function
|
|
8555
|
+
function buildJsonBindings(bindings) {
|
|
8384
8556
|
return Object.entries(bindings).map(([name, value]) => ({
|
|
8385
8557
|
name,
|
|
8386
8558
|
json: JSON.stringify(value)
|
|
@@ -8397,7 +8569,7 @@ var RATELIMIT_PLUGIN = {
|
|
|
8397
8569
|
name,
|
|
8398
8570
|
wrapped: {
|
|
8399
8571
|
moduleName: SERVICE_RATELIMIT_MODULE,
|
|
8400
|
-
innerBindings:
|
|
8572
|
+
innerBindings: buildJsonBindings({
|
|
8401
8573
|
namespaceId: name,
|
|
8402
8574
|
limit: config.simple.limit,
|
|
8403
8575
|
period: config.simple.period
|
|
@@ -8412,7 +8584,10 @@ var RATELIMIT_PLUGIN = {
|
|
|
8412
8584
|
return {};
|
|
8413
8585
|
}
|
|
8414
8586
|
return Object.fromEntries(
|
|
8415
|
-
Object.keys(options.ratelimits).map((name) => [
|
|
8587
|
+
Object.keys(options.ratelimits).map((name) => [
|
|
8588
|
+
name,
|
|
8589
|
+
new ProxyNodeBinding()
|
|
8590
|
+
])
|
|
8416
8591
|
);
|
|
8417
8592
|
},
|
|
8418
8593
|
async getServices({ options }) {
|
|
@@ -8436,6 +8611,125 @@ var RATELIMIT_PLUGIN = {
|
|
|
8436
8611
|
}
|
|
8437
8612
|
};
|
|
8438
8613
|
|
|
8614
|
+
// src/plugins/workflows/index.ts
|
|
8615
|
+
var import_promises12 = __toESM(require("fs/promises"));
|
|
8616
|
+
|
|
8617
|
+
// embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/workflows/binding.worker.ts
|
|
8618
|
+
var import_fs21 = __toESM(require("fs"));
|
|
8619
|
+
var import_path25 = __toESM(require("path"));
|
|
8620
|
+
var import_url21 = __toESM(require("url"));
|
|
8621
|
+
var contents17;
|
|
8622
|
+
function binding_worker_default() {
|
|
8623
|
+
if (contents17 !== void 0)
|
|
8624
|
+
return contents17;
|
|
8625
|
+
const filePath = import_path25.default.join(__dirname, "workers", "workflows/binding.worker.js");
|
|
8626
|
+
contents17 = import_fs21.default.readFileSync(filePath, "utf8") + "//# sourceURL=" + import_url21.default.pathToFileURL(filePath);
|
|
8627
|
+
return contents17;
|
|
8628
|
+
}
|
|
8629
|
+
|
|
8630
|
+
// src/plugins/workflows/index.ts
|
|
8631
|
+
var import_zod20 = require("zod");
|
|
8632
|
+
var WorkflowsOptionsSchema = import_zod20.z.object({
|
|
8633
|
+
workflows: import_zod20.z.record(
|
|
8634
|
+
import_zod20.z.object({
|
|
8635
|
+
name: import_zod20.z.string(),
|
|
8636
|
+
className: import_zod20.z.string(),
|
|
8637
|
+
scriptName: import_zod20.z.string().optional()
|
|
8638
|
+
})
|
|
8639
|
+
).optional()
|
|
8640
|
+
});
|
|
8641
|
+
var WorkflowsSharedOptionsSchema = import_zod20.z.object({
|
|
8642
|
+
workflowsPersist: PersistenceSchema
|
|
8643
|
+
});
|
|
8644
|
+
var WORKFLOWS_PLUGIN_NAME = "workflows";
|
|
8645
|
+
var WORKFLOWS_STORAGE_SERVICE_NAME = `${WORKFLOWS_PLUGIN_NAME}:storage`;
|
|
8646
|
+
var WORKFLOWS_PLUGIN = {
|
|
8647
|
+
options: WorkflowsOptionsSchema,
|
|
8648
|
+
sharedOptions: WorkflowsSharedOptionsSchema,
|
|
8649
|
+
async getBindings(options) {
|
|
8650
|
+
return Object.entries(options.workflows ?? {}).map(
|
|
8651
|
+
([bindingName, workflow]) => ({
|
|
8652
|
+
name: bindingName,
|
|
8653
|
+
service: {
|
|
8654
|
+
name: `${WORKFLOWS_PLUGIN_NAME}:${workflow.name}`,
|
|
8655
|
+
entrypoint: "WorkflowBinding"
|
|
8656
|
+
}
|
|
8657
|
+
})
|
|
8658
|
+
);
|
|
8659
|
+
},
|
|
8660
|
+
async getNodeBindings(options) {
|
|
8661
|
+
return Object.fromEntries(
|
|
8662
|
+
Object.keys(options.workflows ?? {}).map((bindingName) => [
|
|
8663
|
+
bindingName,
|
|
8664
|
+
new ProxyNodeBinding()
|
|
8665
|
+
])
|
|
8666
|
+
);
|
|
8667
|
+
},
|
|
8668
|
+
async getServices({ options, sharedOptions, tmpPath }) {
|
|
8669
|
+
const persistPath = getPersistPath(
|
|
8670
|
+
WORKFLOWS_PLUGIN_NAME,
|
|
8671
|
+
tmpPath,
|
|
8672
|
+
sharedOptions.workflowsPersist
|
|
8673
|
+
);
|
|
8674
|
+
await import_promises12.default.mkdir(persistPath, { recursive: true });
|
|
8675
|
+
const storageServices = Object.entries(
|
|
8676
|
+
options.workflows ?? {}
|
|
8677
|
+
).map(([_, workflow]) => ({
|
|
8678
|
+
name: `${WORKFLOWS_STORAGE_SERVICE_NAME}-${workflow.name}`,
|
|
8679
|
+
disk: { path: persistPath, writable: true }
|
|
8680
|
+
}));
|
|
8681
|
+
const services = Object.entries(options.workflows ?? {}).map(
|
|
8682
|
+
([_bindingName, workflow]) => {
|
|
8683
|
+
const uniqueKey = `miniflare-workflows-${workflow.name}`;
|
|
8684
|
+
const workflowsBinding = {
|
|
8685
|
+
name: `${WORKFLOWS_PLUGIN_NAME}:${workflow.name}`,
|
|
8686
|
+
worker: {
|
|
8687
|
+
compatibilityDate: "2024-10-22",
|
|
8688
|
+
modules: [
|
|
8689
|
+
{
|
|
8690
|
+
name: "workflows.mjs",
|
|
8691
|
+
esModule: binding_worker_default()
|
|
8692
|
+
}
|
|
8693
|
+
],
|
|
8694
|
+
durableObjectNamespaces: [
|
|
8695
|
+
{
|
|
8696
|
+
className: "Engine",
|
|
8697
|
+
enableSql: true,
|
|
8698
|
+
uniqueKey,
|
|
8699
|
+
preventEviction: true
|
|
8700
|
+
}
|
|
8701
|
+
],
|
|
8702
|
+
durableObjectStorage: {
|
|
8703
|
+
localDisk: `${WORKFLOWS_STORAGE_SERVICE_NAME}-${workflow.name}`
|
|
8704
|
+
},
|
|
8705
|
+
bindings: [
|
|
8706
|
+
{
|
|
8707
|
+
name: "ENGINE",
|
|
8708
|
+
durableObjectNamespace: { className: "Engine" }
|
|
8709
|
+
},
|
|
8710
|
+
{
|
|
8711
|
+
name: "USER_WORKFLOW",
|
|
8712
|
+
service: {
|
|
8713
|
+
name: getUserServiceName(workflow.scriptName),
|
|
8714
|
+
entrypoint: workflow.className
|
|
8715
|
+
}
|
|
8716
|
+
}
|
|
8717
|
+
]
|
|
8718
|
+
}
|
|
8719
|
+
};
|
|
8720
|
+
return workflowsBinding;
|
|
8721
|
+
}
|
|
8722
|
+
);
|
|
8723
|
+
if (services.length === 0) {
|
|
8724
|
+
return [];
|
|
8725
|
+
}
|
|
8726
|
+
return [...storageServices, ...services];
|
|
8727
|
+
},
|
|
8728
|
+
getPersistPath({ workflowsPersist }, tmpPath) {
|
|
8729
|
+
return getPersistPath(WORKFLOWS_PLUGIN_NAME, tmpPath, workflowsPersist);
|
|
8730
|
+
}
|
|
8731
|
+
};
|
|
8732
|
+
|
|
8439
8733
|
// src/plugins/index.ts
|
|
8440
8734
|
var PLUGINS = {
|
|
8441
8735
|
[CORE_PLUGIN_NAME2]: CORE_PLUGIN,
|
|
@@ -8447,7 +8741,8 @@ var PLUGINS = {
|
|
|
8447
8741
|
[R2_PLUGIN_NAME]: R2_PLUGIN,
|
|
8448
8742
|
[HYPERDRIVE_PLUGIN_NAME]: HYPERDRIVE_PLUGIN,
|
|
8449
8743
|
[RATELIMIT_PLUGIN_NAME]: RATELIMIT_PLUGIN,
|
|
8450
|
-
[ASSETS_PLUGIN_NAME]: ASSETS_PLUGIN
|
|
8744
|
+
[ASSETS_PLUGIN_NAME]: ASSETS_PLUGIN,
|
|
8745
|
+
[WORKFLOWS_PLUGIN_NAME]: WORKFLOWS_PLUGIN
|
|
8451
8746
|
};
|
|
8452
8747
|
var PLUGIN_ENTRIES = Object.entries(PLUGINS);
|
|
8453
8748
|
|
|
@@ -8553,8 +8848,8 @@ function hasMultipleDistinctMessages(issues, atDepth) {
|
|
|
8553
8848
|
}
|
|
8554
8849
|
return false;
|
|
8555
8850
|
}
|
|
8556
|
-
function annotate(groupCounts, annotated, input, issue,
|
|
8557
|
-
if (
|
|
8851
|
+
function annotate(groupCounts, annotated, input, issue, path28, groupId) {
|
|
8852
|
+
if (path28.length === 0) {
|
|
8558
8853
|
if (issue.code === "invalid_union") {
|
|
8559
8854
|
const unionIssues = issue.unionErrors.flatMap(({ issues }) => issues);
|
|
8560
8855
|
let newGroupId;
|
|
@@ -8601,7 +8896,7 @@ function annotate(groupCounts, annotated, input, issue, path27, groupId) {
|
|
|
8601
8896
|
[kGroupId]: groupId
|
|
8602
8897
|
};
|
|
8603
8898
|
}
|
|
8604
|
-
const [head, ...tail] =
|
|
8899
|
+
const [head, ...tail] = path28;
|
|
8605
8900
|
(0, import_assert11.default)(isRecord(input), "Expected object/array input for nested issue");
|
|
8606
8901
|
if (annotated === void 0) {
|
|
8607
8902
|
if (Array.isArray(input)) {
|
|
@@ -8811,7 +9106,7 @@ function validateOptions(opts) {
|
|
|
8811
9106
|
);
|
|
8812
9107
|
const sharedRootPath = multipleWorkers ? getRootPath(sharedOpts) : "";
|
|
8813
9108
|
const workerRootPaths = workerOpts.map(
|
|
8814
|
-
(opts2) =>
|
|
9109
|
+
(opts2) => import_path26.default.resolve(sharedRootPath, getRootPath(opts2))
|
|
8815
9110
|
);
|
|
8816
9111
|
try {
|
|
8817
9112
|
for (const [key, plugin] of PLUGIN_ENTRIES) {
|
|
@@ -8827,7 +9122,7 @@ function validateOptions(opts) {
|
|
|
8827
9122
|
}
|
|
8828
9123
|
}
|
|
8829
9124
|
} catch (e) {
|
|
8830
|
-
if (e instanceof
|
|
9125
|
+
if (e instanceof import_zod22.z.ZodError) {
|
|
8831
9126
|
let formatted;
|
|
8832
9127
|
try {
|
|
8833
9128
|
formatted = formatZodError(e, opts);
|
|
@@ -8897,6 +9192,7 @@ function getDurableObjectClassNames(allWorkerOpts) {
|
|
|
8897
9192
|
className,
|
|
8898
9193
|
// Fallback to current worker service if name not defined
|
|
8899
9194
|
serviceName = workerServiceName,
|
|
9195
|
+
enableSql,
|
|
8900
9196
|
unsafeUniqueKey,
|
|
8901
9197
|
unsafePreventEviction
|
|
8902
9198
|
} = normaliseDurableObject(designator);
|
|
@@ -8907,6 +9203,14 @@ function getDurableObjectClassNames(allWorkerOpts) {
|
|
|
8907
9203
|
}
|
|
8908
9204
|
if (classNames.has(className)) {
|
|
8909
9205
|
const existingInfo = classNames.get(className);
|
|
9206
|
+
if (existingInfo?.enableSql !== enableSql) {
|
|
9207
|
+
throw new MiniflareCoreError(
|
|
9208
|
+
"ERR_DIFFERENT_STORAGE_BACKEND",
|
|
9209
|
+
`Different storage backends defined for Durable Object "${className}" in "${serviceName}": ${JSON.stringify(
|
|
9210
|
+
enableSql
|
|
9211
|
+
)} and ${JSON.stringify(existingInfo?.enableSql)}`
|
|
9212
|
+
);
|
|
9213
|
+
}
|
|
8910
9214
|
if (existingInfo?.unsafeUniqueKey !== unsafeUniqueKey) {
|
|
8911
9215
|
throw new MiniflareCoreError(
|
|
8912
9216
|
"ERR_DIFFERENT_UNIQUE_KEYS",
|
|
@@ -8924,7 +9228,11 @@ function getDurableObjectClassNames(allWorkerOpts) {
|
|
|
8924
9228
|
);
|
|
8925
9229
|
}
|
|
8926
9230
|
} else {
|
|
8927
|
-
classNames.set(className, {
|
|
9231
|
+
classNames.set(className, {
|
|
9232
|
+
enableSql,
|
|
9233
|
+
unsafeUniqueKey,
|
|
9234
|
+
unsafePreventEviction
|
|
9235
|
+
});
|
|
8928
9236
|
}
|
|
8929
9237
|
}
|
|
8930
9238
|
}
|
|
@@ -8978,8 +9286,15 @@ function getQueueProducers(allWorkerOpts) {
|
|
|
8978
9286
|
])
|
|
8979
9287
|
);
|
|
8980
9288
|
}
|
|
8981
|
-
|
|
8982
|
-
|
|
9289
|
+
const producersIterable = Object.entries(
|
|
9290
|
+
workerProducers
|
|
9291
|
+
);
|
|
9292
|
+
for (const [bindingName, opts] of producersIterable) {
|
|
9293
|
+
if (typeof opts === "string") {
|
|
9294
|
+
queueProducers.set(bindingName, { workerName, queueName: opts });
|
|
9295
|
+
} else {
|
|
9296
|
+
queueProducers.set(bindingName, { workerName, ...opts });
|
|
9297
|
+
}
|
|
8983
9298
|
}
|
|
8984
9299
|
}
|
|
8985
9300
|
}
|
|
@@ -9219,7 +9534,7 @@ var Miniflare2 = class {
|
|
|
9219
9534
|
}
|
|
9220
9535
|
}
|
|
9221
9536
|
});
|
|
9222
|
-
this.#tmpPath =
|
|
9537
|
+
this.#tmpPath = import_path26.default.join(
|
|
9223
9538
|
import_os2.default.tmpdir(),
|
|
9224
9539
|
`miniflare-${import_crypto3.default.randomBytes(16).toString("hex")}`
|
|
9225
9540
|
);
|
|
@@ -9227,7 +9542,7 @@ var Miniflare2 = class {
|
|
|
9227
9542
|
this.#removeExitHook = (0, import_exit_hook.default)(() => {
|
|
9228
9543
|
void this.#runtime?.dispose();
|
|
9229
9544
|
try {
|
|
9230
|
-
|
|
9545
|
+
import_fs22.default.rmSync(this.#tmpPath, { force: true, recursive: true });
|
|
9231
9546
|
} catch (e) {
|
|
9232
9547
|
this.#log.debug(`Unable to remove temporary directory: ${String(e)}`);
|
|
9233
9548
|
}
|
|
@@ -9260,8 +9575,11 @@ var Miniflare2 = class {
|
|
|
9260
9575
|
}
|
|
9261
9576
|
(0, import_assert12.default)(typeof service === "function");
|
|
9262
9577
|
try {
|
|
9263
|
-
|
|
9264
|
-
|
|
9578
|
+
let response = await service(request, this);
|
|
9579
|
+
if (!(response instanceof Response)) {
|
|
9580
|
+
response = new Response(response.body, response);
|
|
9581
|
+
}
|
|
9582
|
+
return import_zod22.z.instanceof(Response).parse(response);
|
|
9265
9583
|
} catch (e) {
|
|
9266
9584
|
return new Response(e?.stack ?? e, { status: 500 });
|
|
9267
9585
|
}
|
|
@@ -9286,11 +9604,11 @@ var Miniflare2 = class {
|
|
|
9286
9604
|
(0, import_assert12.default)(!Array.isArray(cfBlob));
|
|
9287
9605
|
const cf = cfBlob ? JSON.parse(cfBlob) : void 0;
|
|
9288
9606
|
const originalUrl = headers.get(CoreHeaders.ORIGINAL_URL);
|
|
9289
|
-
const
|
|
9607
|
+
const url18 = new URL(originalUrl ?? req.url ?? "", "http://localhost");
|
|
9290
9608
|
headers.delete(CoreHeaders.ORIGINAL_URL);
|
|
9291
9609
|
const noBody = req.method === "GET" || req.method === "HEAD";
|
|
9292
9610
|
const body = noBody ? void 0 : safeReadableStreamFrom(req);
|
|
9293
|
-
const request = new Request(
|
|
9611
|
+
const request = new Request(url18, {
|
|
9294
9612
|
method: req.method,
|
|
9295
9613
|
headers,
|
|
9296
9614
|
body,
|
|
@@ -9311,13 +9629,13 @@ var Miniflare2 = class {
|
|
|
9311
9629
|
request,
|
|
9312
9630
|
this
|
|
9313
9631
|
);
|
|
9314
|
-
} else if (
|
|
9632
|
+
} else if (url18.pathname === "/core/error") {
|
|
9315
9633
|
response = await handlePrettyErrorRequest(
|
|
9316
9634
|
this.#log,
|
|
9317
9635
|
this.#workerSrcOpts,
|
|
9318
9636
|
request
|
|
9319
9637
|
);
|
|
9320
|
-
} else if (
|
|
9638
|
+
} else if (url18.pathname === "/core/log") {
|
|
9321
9639
|
const level = parseInt(request.headers.get(SharedHeaders.LOG_LEVEL));
|
|
9322
9640
|
(0, import_assert12.default)(
|
|
9323
9641
|
0 /* NONE */ <= level && level <= 5 /* VERBOSE */,
|
|
@@ -9452,18 +9770,26 @@ var Miniflare2 = class {
|
|
|
9452
9770
|
sockets.push({
|
|
9453
9771
|
name: SOCKET_ENTRY_LOCAL,
|
|
9454
9772
|
service: { name: SERVICE_ENTRY },
|
|
9455
|
-
http:
|
|
9773
|
+
http: {},
|
|
9456
9774
|
address: "127.0.0.1:0"
|
|
9457
9775
|
});
|
|
9458
9776
|
}
|
|
9459
9777
|
const proxyBindings = [];
|
|
9460
9778
|
const allWorkerBindings = /* @__PURE__ */ new Map();
|
|
9461
9779
|
const wrappedBindingsToPopulate = [];
|
|
9780
|
+
if (this.#workerOpts[0].assets.assets) {
|
|
9781
|
+
this.#workerOpts[0].assets.assets.workerName = this.#workerOpts[0].core.name;
|
|
9782
|
+
}
|
|
9462
9783
|
for (let i = 0; i < allWorkerOpts.length; i++) {
|
|
9463
9784
|
const previousWorkerOpts = allPreviousWorkerOpts?.[i];
|
|
9464
9785
|
const workerOpts = allWorkerOpts[i];
|
|
9465
9786
|
const workerName = workerOpts.core.name ?? "";
|
|
9466
9787
|
const isModulesWorker = Boolean(workerOpts.core.modules);
|
|
9788
|
+
if (workerOpts.workflows.workflows) {
|
|
9789
|
+
for (const workflow of Object.values(workerOpts.workflows.workflows)) {
|
|
9790
|
+
workflow.scriptName ??= workerOpts.core.name;
|
|
9791
|
+
}
|
|
9792
|
+
}
|
|
9467
9793
|
const workerBindings = [];
|
|
9468
9794
|
allWorkerBindings.set(workerName, workerBindings);
|
|
9469
9795
|
const additionalModules = [];
|
|
@@ -9578,8 +9904,11 @@ var Miniflare2 = class {
|
|
|
9578
9904
|
const globalServices = getGlobalServices({
|
|
9579
9905
|
sharedOptions: sharedOpts.core,
|
|
9580
9906
|
allWorkerRoutes,
|
|
9581
|
-
// if Workers + Assets project, point to router Worker
|
|
9582
|
-
|
|
9907
|
+
// if Workers + Assets project but NOT Vitest, point to router Worker instead
|
|
9908
|
+
// if Vitest with assets, the self binding on the test runner will point to RW
|
|
9909
|
+
fallbackWorkerName: this.#workerOpts[0].assets.assets && !this.#workerOpts[0].core.name?.startsWith(
|
|
9910
|
+
"vitest-pool-workers-runner-"
|
|
9911
|
+
) ? ROUTER_SERVICE_NAME : getUserServiceName(this.#workerOpts[0].core.name),
|
|
9583
9912
|
loopbackPort,
|
|
9584
9913
|
log: this.#log,
|
|
9585
9914
|
proxyBindings
|
|
@@ -9793,11 +10122,11 @@ var Miniflare2 = class {
|
|
|
9793
10122
|
(0, import_assert12.default)(this.#runtimeEntryURL !== void 0);
|
|
9794
10123
|
(0, import_assert12.default)(this.#runtimeDispatcher !== void 0);
|
|
9795
10124
|
const forward = new Request(input, init2);
|
|
9796
|
-
const
|
|
10125
|
+
const url18 = new URL(forward.url);
|
|
9797
10126
|
const actualRuntimeOrigin = this.#runtimeEntryURL.origin;
|
|
9798
|
-
const userRuntimeOrigin =
|
|
9799
|
-
|
|
9800
|
-
|
|
10127
|
+
const userRuntimeOrigin = url18.origin;
|
|
10128
|
+
url18.protocol = this.#runtimeEntryURL.protocol;
|
|
10129
|
+
url18.host = this.#runtimeEntryURL.host;
|
|
9801
10130
|
if (forward.body !== null && forward.headers.get("Content-Length") === "0") {
|
|
9802
10131
|
forward.headers.delete("Content-Length");
|
|
9803
10132
|
}
|
|
@@ -9811,7 +10140,7 @@ var Miniflare2 = class {
|
|
|
9811
10140
|
);
|
|
9812
10141
|
const forwardInit = forward;
|
|
9813
10142
|
forwardInit.dispatcher = dispatcher;
|
|
9814
|
-
const response = await fetch3(
|
|
10143
|
+
const response = await fetch3(url18, forwardInit);
|
|
9815
10144
|
const stack = response.headers.get(CoreHeaders.ERROR_STACK);
|
|
9816
10145
|
if (response.status === 500 && stack !== null) {
|
|
9817
10146
|
const caught = JsonErrorSchema.parse(await response.json());
|
|
@@ -9864,13 +10193,16 @@ var Miniflare2 = class {
|
|
|
9864
10193
|
for (const [key, plugin] of PLUGIN_ENTRIES) {
|
|
9865
10194
|
const pluginBindings = await plugin.getNodeBindings(workerOpts[key]);
|
|
9866
10195
|
for (const [name, binding] of Object.entries(pluginBindings)) {
|
|
9867
|
-
if (binding
|
|
10196
|
+
if (binding instanceof ProxyNodeBinding) {
|
|
9868
10197
|
const proxyBindingName = getProxyBindingName(key, workerName, name);
|
|
9869
|
-
|
|
10198
|
+
let proxy = proxyClient.env[proxyBindingName];
|
|
9870
10199
|
(0, import_assert12.default)(
|
|
9871
10200
|
proxy !== void 0,
|
|
9872
10201
|
`Expected ${proxyBindingName} to be bound`
|
|
9873
10202
|
);
|
|
10203
|
+
if (binding.proxyOverrideHandler) {
|
|
10204
|
+
proxy = new Proxy(proxy, binding.proxyOverrideHandler);
|
|
10205
|
+
}
|
|
9874
10206
|
bindings[name] = proxy;
|
|
9875
10207
|
} else {
|
|
9876
10208
|
bindings[name] = binding;
|
|
@@ -9958,7 +10290,7 @@ var Miniflare2 = class {
|
|
|
9958
10290
|
await this.#proxyClient?.dispose();
|
|
9959
10291
|
await this.#runtime?.dispose();
|
|
9960
10292
|
await this.#stopLoopbackServer();
|
|
9961
|
-
await
|
|
10293
|
+
await import_fs22.default.promises.rm(this.#tmpPath, { force: true, recursive: true });
|
|
9962
10294
|
maybeInstanceRegistry?.delete(this);
|
|
9963
10295
|
}
|
|
9964
10296
|
}
|
|
@@ -9992,7 +10324,6 @@ var Miniflare2 = class {
|
|
|
9992
10324
|
DispatchFetchDispatcher,
|
|
9993
10325
|
DurableObjectsOptionsSchema,
|
|
9994
10326
|
DurableObjectsSharedOptionsSchema,
|
|
9995
|
-
ENTRY_SOCKET_HTTP_OPTIONS,
|
|
9996
10327
|
ErrorEvent,
|
|
9997
10328
|
File,
|
|
9998
10329
|
FormData,
|
|
@@ -10030,6 +10361,7 @@ var Miniflare2 = class {
|
|
|
10030
10361
|
PersistenceSchema,
|
|
10031
10362
|
ProxyAddresses,
|
|
10032
10363
|
ProxyClient,
|
|
10364
|
+
ProxyNodeBinding,
|
|
10033
10365
|
ProxyOps,
|
|
10034
10366
|
QUEUES_PLUGIN,
|
|
10035
10367
|
QUEUES_PLUGIN_NAME,
|
|
@@ -10057,7 +10389,6 @@ var Miniflare2 = class {
|
|
|
10057
10389
|
Request,
|
|
10058
10390
|
Response,
|
|
10059
10391
|
RouterError,
|
|
10060
|
-
RoutingConfigSchema,
|
|
10061
10392
|
Runtime,
|
|
10062
10393
|
SERVICE_ENTRY,
|
|
10063
10394
|
SERVICE_LOOPBACK,
|
|
@@ -10071,10 +10402,15 @@ var Miniflare2 = class {
|
|
|
10071
10402
|
TlsOptions_Version,
|
|
10072
10403
|
TypedEventTarget,
|
|
10073
10404
|
WORKER_BINDING_SERVICE_LOOPBACK,
|
|
10405
|
+
WORKFLOWS_PLUGIN,
|
|
10406
|
+
WORKFLOWS_PLUGIN_NAME,
|
|
10407
|
+
WORKFLOWS_STORAGE_SERVICE_NAME,
|
|
10074
10408
|
WaitGroup,
|
|
10075
10409
|
WebSocket,
|
|
10076
10410
|
WebSocketPair,
|
|
10077
10411
|
Worker_Binding_CryptoKey_Usage,
|
|
10412
|
+
WorkflowsOptionsSchema,
|
|
10413
|
+
WorkflowsSharedOptionsSchema,
|
|
10078
10414
|
__MiniflareFunctionWrapper,
|
|
10079
10415
|
_enableControlEndpoints,
|
|
10080
10416
|
_forceColour,
|
|
@@ -10083,7 +10419,7 @@ var Miniflare2 = class {
|
|
|
10083
10419
|
_transformsForContentEncodingAndContentType,
|
|
10084
10420
|
base64Decode,
|
|
10085
10421
|
base64Encode,
|
|
10086
|
-
|
|
10422
|
+
buildAssetManifest,
|
|
10087
10423
|
compileModuleRules,
|
|
10088
10424
|
coupleWebSocket,
|
|
10089
10425
|
createFetchMock,
|
|
@@ -10103,6 +10439,7 @@ var Miniflare2 = class {
|
|
|
10103
10439
|
getFreshSourceMapSupport,
|
|
10104
10440
|
getGlobalServices,
|
|
10105
10441
|
getMiniflareObjectBindings,
|
|
10442
|
+
getNodeCompat,
|
|
10106
10443
|
getPersistPath,
|
|
10107
10444
|
getRootPath,
|
|
10108
10445
|
globsToRegExps,
|
|
@@ -10111,7 +10448,6 @@ var Miniflare2 = class {
|
|
|
10111
10448
|
isSitesRequest,
|
|
10112
10449
|
kCurrentWorker,
|
|
10113
10450
|
kInspectorSocket,
|
|
10114
|
-
kProxyNodeBinding,
|
|
10115
10451
|
kUnsafeEphemeralUniqueKey,
|
|
10116
10452
|
kVoid,
|
|
10117
10453
|
matchRoutes,
|