miniflare 0.0.0-e5037b92a → 0.0.0-e5ebdb143
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 +23 -0
- package/dist/src/index.d.ts +280 -84
- package/dist/src/index.js +319 -168
- package/dist/src/index.js.map +3 -3
- package/dist/src/workers/assets/assets.worker.js +183 -21
- package/dist/src/workers/assets/assets.worker.js.map +2 -2
- package/dist/src/workers/assets/router.worker.js +33 -20
- package/dist/src/workers/assets/router.worker.js.map +2 -2
- 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 +13 -13
- 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 +5 -3
- 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
|
};
|
|
@@ -2456,7 +2456,6 @@ __export(src_exports, {
|
|
|
2456
2456
|
DispatchFetchDispatcher: () => DispatchFetchDispatcher,
|
|
2457
2457
|
DurableObjectsOptionsSchema: () => DurableObjectsOptionsSchema,
|
|
2458
2458
|
DurableObjectsSharedOptionsSchema: () => DurableObjectsSharedOptionsSchema,
|
|
2459
|
-
ENTRY_SOCKET_HTTP_OPTIONS: () => ENTRY_SOCKET_HTTP_OPTIONS,
|
|
2460
2459
|
ErrorEvent: () => ErrorEvent,
|
|
2461
2460
|
File: () => import_undici4.File,
|
|
2462
2461
|
FormData: () => import_undici4.FormData,
|
|
@@ -2535,10 +2534,15 @@ __export(src_exports, {
|
|
|
2535
2534
|
TlsOptions_Version: () => import_workerd_capnp.TlsOptions_Version,
|
|
2536
2535
|
TypedEventTarget: () => TypedEventTarget,
|
|
2537
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,
|
|
2538
2540
|
WaitGroup: () => WaitGroup,
|
|
2539
2541
|
WebSocket: () => WebSocket,
|
|
2540
2542
|
WebSocketPair: () => WebSocketPair,
|
|
2541
2543
|
Worker_Binding_CryptoKey_Usage: () => import_workerd_capnp.Worker_Binding_CryptoKey_Usage,
|
|
2544
|
+
WorkflowsOptionsSchema: () => WorkflowsOptionsSchema,
|
|
2545
|
+
WorkflowsSharedOptionsSchema: () => WorkflowsSharedOptionsSchema,
|
|
2542
2546
|
__MiniflareFunctionWrapper: () => __MiniflareFunctionWrapper,
|
|
2543
2547
|
_enableControlEndpoints: () => _enableControlEndpoints,
|
|
2544
2548
|
_forceColour: () => _forceColour,
|
|
@@ -2612,11 +2616,11 @@ __export(src_exports, {
|
|
|
2612
2616
|
module.exports = __toCommonJS(src_exports);
|
|
2613
2617
|
var import_assert12 = __toESM(require("assert"));
|
|
2614
2618
|
var import_crypto3 = __toESM(require("crypto"));
|
|
2615
|
-
var
|
|
2619
|
+
var import_fs22 = __toESM(require("fs"));
|
|
2616
2620
|
var import_http6 = __toESM(require("http"));
|
|
2617
2621
|
var import_net = __toESM(require("net"));
|
|
2618
2622
|
var import_os2 = __toESM(require("os"));
|
|
2619
|
-
var
|
|
2623
|
+
var import_path26 = __toESM(require("path"));
|
|
2620
2624
|
var import_web5 = require("stream/web");
|
|
2621
2625
|
var import_util5 = __toESM(require("util"));
|
|
2622
2626
|
var import_zlib = __toESM(require("zlib"));
|
|
@@ -2703,7 +2707,7 @@ function zod_worker_default() {
|
|
|
2703
2707
|
|
|
2704
2708
|
// src/index.ts
|
|
2705
2709
|
var import_ws3 = require("ws");
|
|
2706
|
-
var
|
|
2710
|
+
var import_zod22 = require("zod");
|
|
2707
2711
|
|
|
2708
2712
|
// src/cf.ts
|
|
2709
2713
|
var import_assert = __toESM(require("assert"));
|
|
@@ -3311,12 +3315,12 @@ function createHTTPRevivers(impl) {
|
|
|
3311
3315
|
},
|
|
3312
3316
|
Request(value) {
|
|
3313
3317
|
(0, import_node_assert.default)(Array.isArray(value));
|
|
3314
|
-
const [method,
|
|
3318
|
+
const [method, url18, headers, cf, body] = value;
|
|
3315
3319
|
(0, import_node_assert.default)(typeof method === "string");
|
|
3316
|
-
(0, import_node_assert.default)(typeof
|
|
3320
|
+
(0, import_node_assert.default)(typeof url18 === "string");
|
|
3317
3321
|
(0, import_node_assert.default)(headers instanceof impl.Headers);
|
|
3318
3322
|
(0, import_node_assert.default)(body === null || impl.isReadableStream(body));
|
|
3319
|
-
return new impl.Request(
|
|
3323
|
+
return new impl.Request(url18, {
|
|
3320
3324
|
method,
|
|
3321
3325
|
headers,
|
|
3322
3326
|
cf,
|
|
@@ -3445,23 +3449,23 @@ function parseWithReadableStreams(impl, stringified, revivers2) {
|
|
|
3445
3449
|
}
|
|
3446
3450
|
|
|
3447
3451
|
// src/workers/core/routing.ts
|
|
3448
|
-
function matchRoutes(routes,
|
|
3452
|
+
function matchRoutes(routes, url18) {
|
|
3449
3453
|
for (const route of routes) {
|
|
3450
|
-
if (route.protocol && route.protocol !==
|
|
3454
|
+
if (route.protocol && route.protocol !== url18.protocol)
|
|
3451
3455
|
continue;
|
|
3452
3456
|
if (route.allowHostnamePrefix) {
|
|
3453
|
-
if (!
|
|
3457
|
+
if (!url18.hostname.endsWith(route.hostname))
|
|
3454
3458
|
continue;
|
|
3455
3459
|
} else {
|
|
3456
|
-
if (
|
|
3460
|
+
if (url18.hostname !== route.hostname)
|
|
3457
3461
|
continue;
|
|
3458
3462
|
}
|
|
3459
|
-
const
|
|
3463
|
+
const path28 = url18.pathname + url18.search;
|
|
3460
3464
|
if (route.allowPathSuffix) {
|
|
3461
|
-
if (!
|
|
3465
|
+
if (!path28.startsWith(route.path))
|
|
3462
3466
|
continue;
|
|
3463
3467
|
} else {
|
|
3464
|
-
if (
|
|
3468
|
+
if (path28 !== route.path)
|
|
3465
3469
|
continue;
|
|
3466
3470
|
}
|
|
3467
3471
|
return route.target;
|
|
@@ -3706,8 +3710,8 @@ function decodeSitesKey(key) {
|
|
|
3706
3710
|
return key.startsWith(SITES_NO_CACHE_PREFIX) ? decodeURIComponent(key.substring(SITES_NO_CACHE_PREFIX.length)) : key;
|
|
3707
3711
|
}
|
|
3708
3712
|
function isSitesRequest(request) {
|
|
3709
|
-
const
|
|
3710
|
-
return
|
|
3713
|
+
const url18 = new URL(request.url);
|
|
3714
|
+
return url18.pathname.startsWith(`/${SITES_NO_CACHE_PREFIX}`);
|
|
3711
3715
|
}
|
|
3712
3716
|
function serialiseRegExp(regExp) {
|
|
3713
3717
|
const str = regExp.toString();
|
|
@@ -3783,11 +3787,18 @@ var QueueConsumerOptionsSchema = /* @__PURE__ */ import_zod2.z.object({
|
|
|
3783
3787
|
// https://developers.cloudflare.com/queues/platform/configuration/#consumer
|
|
3784
3788
|
// https://developers.cloudflare.com/queues/platform/limits/
|
|
3785
3789
|
maxBatchSize: import_zod2.z.number().min(0).max(100).optional(),
|
|
3786
|
-
maxBatchTimeout: import_zod2.z.number().min(0).max(
|
|
3790
|
+
maxBatchTimeout: import_zod2.z.number().min(0).max(60).optional(),
|
|
3787
3791
|
// seconds
|
|
3788
3792
|
maxRetires: import_zod2.z.number().min(0).max(100).optional(),
|
|
3793
|
+
// deprecated
|
|
3794
|
+
maxRetries: import_zod2.z.number().min(0).max(100).optional(),
|
|
3789
3795
|
deadLetterQueue: import_zod2.z.ostring(),
|
|
3790
3796
|
retryDelay: QueueMessageDelaySchema
|
|
3797
|
+
}).transform((queue) => {
|
|
3798
|
+
if (queue.maxRetires !== void 0) {
|
|
3799
|
+
queue.maxRetries = queue.maxRetires;
|
|
3800
|
+
}
|
|
3801
|
+
return queue;
|
|
3791
3802
|
});
|
|
3792
3803
|
var QueueConsumerSchema = /* @__PURE__ */ import_zod2.z.intersection(
|
|
3793
3804
|
QueueConsumerOptionsSchema,
|
|
@@ -3854,8 +3865,8 @@ var Response = class extends import_undici3.Response {
|
|
|
3854
3865
|
Object.setPrototypeOf(response, Response.prototype);
|
|
3855
3866
|
return response;
|
|
3856
3867
|
}
|
|
3857
|
-
static redirect(
|
|
3858
|
-
const response = import_undici3.Response.redirect(
|
|
3868
|
+
static redirect(url18, status) {
|
|
3869
|
+
const response = import_undici3.Response.redirect(url18, status);
|
|
3859
3870
|
Object.setPrototypeOf(response, Response.prototype);
|
|
3860
3871
|
return response;
|
|
3861
3872
|
}
|
|
@@ -4363,14 +4374,14 @@ async function fetch3(input, init2) {
|
|
|
4363
4374
|
const requestInit = init2;
|
|
4364
4375
|
const request = new Request(input, requestInit);
|
|
4365
4376
|
if (request.method === "GET" && request.headers.get("upgrade") === "websocket") {
|
|
4366
|
-
const
|
|
4367
|
-
if (
|
|
4377
|
+
const url18 = new URL(request.url);
|
|
4378
|
+
if (url18.protocol !== "http:" && url18.protocol !== "https:") {
|
|
4368
4379
|
throw new TypeError(
|
|
4369
|
-
`Fetch API cannot load: ${
|
|
4380
|
+
`Fetch API cannot load: ${url18.toString()}.
|
|
4370
4381
|
Make sure you're using http(s):// URLs for WebSocket requests via fetch.`
|
|
4371
4382
|
);
|
|
4372
4383
|
}
|
|
4373
|
-
|
|
4384
|
+
url18.protocol = url18.protocol.replace("http", "ws");
|
|
4374
4385
|
const headers = {};
|
|
4375
4386
|
let protocols;
|
|
4376
4387
|
for (const [key, value] of request.headers.entries()) {
|
|
@@ -4382,10 +4393,10 @@ Make sure you're using http(s):// URLs for WebSocket requests via fetch.`
|
|
|
4382
4393
|
}
|
|
4383
4394
|
let rejectUnauthorized;
|
|
4384
4395
|
if (requestInit.dispatcher instanceof DispatchFetchDispatcher) {
|
|
4385
|
-
requestInit.dispatcher.addHeaders(headers,
|
|
4396
|
+
requestInit.dispatcher.addHeaders(headers, url18.pathname + url18.search);
|
|
4386
4397
|
rejectUnauthorized = { rejectUnauthorized: false };
|
|
4387
4398
|
}
|
|
4388
|
-
const ws = new import_ws2.default(
|
|
4399
|
+
const ws = new import_ws2.default(url18, protocols, {
|
|
4389
4400
|
followRedirects: request.redirect === "follow",
|
|
4390
4401
|
headers,
|
|
4391
4402
|
...rejectUnauthorized
|
|
@@ -4444,8 +4455,8 @@ var DispatchFetchDispatcher = class extends undici.Dispatcher {
|
|
|
4444
4455
|
this.cfBlobJson = JSON.stringify(cfBlob);
|
|
4445
4456
|
}
|
|
4446
4457
|
cfBlobJson;
|
|
4447
|
-
addHeaders(headers,
|
|
4448
|
-
const originalURL = this.userRuntimeOrigin +
|
|
4458
|
+
addHeaders(headers, path28) {
|
|
4459
|
+
const originalURL = this.userRuntimeOrigin + path28;
|
|
4449
4460
|
addHeader(headers, CoreHeaders.ORIGINAL_URL, originalURL);
|
|
4450
4461
|
addHeader(headers, CoreHeaders.DISABLE_PRETTY_ERROR, "true");
|
|
4451
4462
|
if (this.cfBlobJson !== void 0) {
|
|
@@ -4458,16 +4469,16 @@ var DispatchFetchDispatcher = class extends undici.Dispatcher {
|
|
|
4458
4469
|
origin = this.actualRuntimeOrigin;
|
|
4459
4470
|
if (origin === this.actualRuntimeOrigin) {
|
|
4460
4471
|
options.origin = origin;
|
|
4461
|
-
let
|
|
4472
|
+
let path28 = options.path;
|
|
4462
4473
|
if (options.query !== void 0) {
|
|
4463
|
-
const
|
|
4474
|
+
const url18 = new URL(path28, "http://placeholder/");
|
|
4464
4475
|
for (const [key, value] of Object.entries(options.query)) {
|
|
4465
|
-
|
|
4476
|
+
url18.searchParams.append(key, value);
|
|
4466
4477
|
}
|
|
4467
|
-
|
|
4478
|
+
path28 = url18.pathname + url18.search;
|
|
4468
4479
|
}
|
|
4469
4480
|
options.headers ??= {};
|
|
4470
|
-
this.addHeaders(options.headers,
|
|
4481
|
+
this.addHeaders(options.headers, path28);
|
|
4471
4482
|
return this.runtimeDispatcher.dispatch(options, handler);
|
|
4472
4483
|
} else {
|
|
4473
4484
|
return this.globalDispatcher.dispatch(options, handler);
|
|
@@ -4528,11 +4539,6 @@ ez/dHA==
|
|
|
4528
4539
|
`;
|
|
4529
4540
|
|
|
4530
4541
|
// src/http/server.ts
|
|
4531
|
-
var ENTRY_SOCKET_HTTP_OPTIONS = {
|
|
4532
|
-
// Even though we inject a `cf` object in the entry worker, allow it to
|
|
4533
|
-
// be customised via `dispatchFetch`
|
|
4534
|
-
cfBlobHeader: CoreHeaders.CF_BLOB
|
|
4535
|
-
};
|
|
4536
4542
|
async function getEntrySocketHttpOptions(coreOpts) {
|
|
4537
4543
|
let privateKey = void 0;
|
|
4538
4544
|
let certificateChain = void 0;
|
|
@@ -4549,7 +4555,6 @@ async function getEntrySocketHttpOptions(coreOpts) {
|
|
|
4549
4555
|
if (privateKey && certificateChain) {
|
|
4550
4556
|
return {
|
|
4551
4557
|
https: {
|
|
4552
|
-
options: ENTRY_SOCKET_HTTP_OPTIONS,
|
|
4553
4558
|
tlsOptions: {
|
|
4554
4559
|
keypair: {
|
|
4555
4560
|
privateKey,
|
|
@@ -4559,7 +4564,7 @@ async function getEntrySocketHttpOptions(coreOpts) {
|
|
|
4559
4564
|
}
|
|
4560
4565
|
};
|
|
4561
4566
|
} else {
|
|
4562
|
-
return { http:
|
|
4567
|
+
return { http: {} };
|
|
4563
4568
|
}
|
|
4564
4569
|
}
|
|
4565
4570
|
function valueOrFile(value, filePath) {
|
|
@@ -4604,7 +4609,8 @@ var MAX_ASSET_SIZE = 25 * 1024 * 1024;
|
|
|
4604
4609
|
// ../workers-shared/utils/types.ts
|
|
4605
4610
|
var import_zod4 = require("zod");
|
|
4606
4611
|
var RoutingConfigSchema = import_zod4.z.object({
|
|
4607
|
-
has_user_worker: import_zod4.z.boolean().optional()
|
|
4612
|
+
has_user_worker: import_zod4.z.boolean().optional(),
|
|
4613
|
+
invoke_user_worker_ahead_of_assets: import_zod4.z.boolean().optional()
|
|
4608
4614
|
});
|
|
4609
4615
|
var AssetConfigSchema = import_zod4.z.object({
|
|
4610
4616
|
html_handling: import_zod4.z.enum([
|
|
@@ -4613,7 +4619,8 @@ var AssetConfigSchema = import_zod4.z.object({
|
|
|
4613
4619
|
"drop-trailing-slash",
|
|
4614
4620
|
"none"
|
|
4615
4621
|
]).optional(),
|
|
4616
|
-
not_found_handling: import_zod4.z.enum(["single-page-application", "404-page", "none"]).optional()
|
|
4622
|
+
not_found_handling: import_zod4.z.enum(["single-page-application", "404-page", "none"]).optional(),
|
|
4623
|
+
serve_directly: import_zod4.z.boolean().optional()
|
|
4617
4624
|
});
|
|
4618
4625
|
|
|
4619
4626
|
// ../workers-shared/utils/helpers.ts
|
|
@@ -4633,7 +4640,7 @@ var getContentType = (absFilePath) => {
|
|
|
4633
4640
|
return contentType;
|
|
4634
4641
|
};
|
|
4635
4642
|
|
|
4636
|
-
// ../../node_modules/.pnpm/pretty-bytes@6.
|
|
4643
|
+
// ../../node_modules/.pnpm/pretty-bytes@6.1.1/node_modules/pretty-bytes/index.js
|
|
4637
4644
|
var BYTE_UNITS = [
|
|
4638
4645
|
"B",
|
|
4639
4646
|
"kB",
|
|
@@ -4647,7 +4654,7 @@ var BYTE_UNITS = [
|
|
|
4647
4654
|
];
|
|
4648
4655
|
var BIBYTE_UNITS = [
|
|
4649
4656
|
"B",
|
|
4650
|
-
"
|
|
4657
|
+
"KiB",
|
|
4651
4658
|
"MiB",
|
|
4652
4659
|
"GiB",
|
|
4653
4660
|
"TiB",
|
|
@@ -4694,11 +4701,13 @@ function prettyBytes(number, options) {
|
|
|
4694
4701
|
options = {
|
|
4695
4702
|
bits: false,
|
|
4696
4703
|
binary: false,
|
|
4704
|
+
space: true,
|
|
4697
4705
|
...options
|
|
4698
4706
|
};
|
|
4699
4707
|
const UNITS = options.bits ? options.binary ? BIBIT_UNITS : BIT_UNITS : options.binary ? BIBYTE_UNITS : BYTE_UNITS;
|
|
4708
|
+
const separator = options.space ? " " : "";
|
|
4700
4709
|
if (options.signed && number === 0) {
|
|
4701
|
-
return ` 0
|
|
4710
|
+
return ` 0${separator}${UNITS[0]}`;
|
|
4702
4711
|
}
|
|
4703
4712
|
const isNegative = number < 0;
|
|
4704
4713
|
const prefix = isNegative ? "-" : options.signed ? "+" : "";
|
|
@@ -4714,7 +4723,7 @@ function prettyBytes(number, options) {
|
|
|
4714
4723
|
}
|
|
4715
4724
|
if (number < 1) {
|
|
4716
4725
|
const numberString2 = toLocaleString(number, options.locale, localeOptions);
|
|
4717
|
-
return prefix + numberString2 +
|
|
4726
|
+
return prefix + numberString2 + separator + UNITS[0];
|
|
4718
4727
|
}
|
|
4719
4728
|
const exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1);
|
|
4720
4729
|
number /= (options.binary ? 1024 : 1e3) ** exponent;
|
|
@@ -4723,7 +4732,7 @@ function prettyBytes(number, options) {
|
|
|
4723
4732
|
}
|
|
4724
4733
|
const numberString = toLocaleString(Number(number), options.locale, localeOptions);
|
|
4725
4734
|
const unit = UNITS[exponent];
|
|
4726
|
-
return prefix + numberString +
|
|
4735
|
+
return prefix + numberString + separator + unit;
|
|
4727
4736
|
}
|
|
4728
4737
|
|
|
4729
4738
|
// embed-worker:/home/runner/work/workers-sdk/workers-sdk/packages/miniflare/src/workers/assets/assets.worker.ts
|
|
@@ -5079,12 +5088,12 @@ var kUnsafeEphemeralUniqueKey = Symbol.for(
|
|
|
5079
5088
|
var import_url11 = require("url");
|
|
5080
5089
|
var RouterError = class extends MiniflareError {
|
|
5081
5090
|
};
|
|
5082
|
-
function routeSpecificity(
|
|
5083
|
-
const hostParts =
|
|
5091
|
+
function routeSpecificity(url18) {
|
|
5092
|
+
const hostParts = url18.host.split(".");
|
|
5084
5093
|
let hostScore = hostParts.length;
|
|
5085
5094
|
if (hostParts[0] === "*")
|
|
5086
5095
|
hostScore -= 2;
|
|
5087
|
-
const pathParts =
|
|
5096
|
+
const pathParts = url18.pathname.split("/");
|
|
5088
5097
|
let pathScore = pathParts.length;
|
|
5089
5098
|
if (pathParts[pathParts.length - 1] === "*")
|
|
5090
5099
|
pathScore -= 2;
|
|
@@ -5098,30 +5107,30 @@ function parseRoutes(allRoutes) {
|
|
|
5098
5107
|
let urlInput = route;
|
|
5099
5108
|
if (!hasProtocol)
|
|
5100
5109
|
urlInput = `https://${urlInput}`;
|
|
5101
|
-
const
|
|
5102
|
-
const specificity = routeSpecificity(
|
|
5103
|
-
const protocol = hasProtocol ?
|
|
5104
|
-
const internationalisedAllowHostnamePrefix =
|
|
5105
|
-
const allowHostnamePrefix =
|
|
5106
|
-
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 === "*";
|
|
5107
5116
|
if (allowHostnamePrefix && !anyHostname) {
|
|
5108
|
-
let hostname =
|
|
5117
|
+
let hostname = url18.hostname;
|
|
5109
5118
|
if (internationalisedAllowHostnamePrefix) {
|
|
5110
5119
|
hostname = (0, import_url11.domainToUnicode)(hostname);
|
|
5111
5120
|
}
|
|
5112
|
-
|
|
5121
|
+
url18.hostname = hostname.substring(1);
|
|
5113
5122
|
}
|
|
5114
|
-
const allowPathSuffix =
|
|
5123
|
+
const allowPathSuffix = url18.pathname.endsWith("*");
|
|
5115
5124
|
if (allowPathSuffix) {
|
|
5116
|
-
|
|
5125
|
+
url18.pathname = url18.pathname.substring(0, url18.pathname.length - 1);
|
|
5117
5126
|
}
|
|
5118
|
-
if (
|
|
5127
|
+
if (url18.search) {
|
|
5119
5128
|
throw new RouterError(
|
|
5120
5129
|
"ERR_QUERY_STRING",
|
|
5121
5130
|
`Route "${route}" for "${target}" contains a query string. This is not allowed.`
|
|
5122
5131
|
);
|
|
5123
5132
|
}
|
|
5124
|
-
if (
|
|
5133
|
+
if (url18.toString().includes("*") && !anyHostname) {
|
|
5125
5134
|
throw new RouterError(
|
|
5126
5135
|
"ERR_INFIX_WILDCARD",
|
|
5127
5136
|
`Route "${route}" for "${target}" contains an infix wildcard. This is not allowed.`
|
|
@@ -5133,8 +5142,8 @@ function parseRoutes(allRoutes) {
|
|
|
5133
5142
|
specificity,
|
|
5134
5143
|
protocol,
|
|
5135
5144
|
allowHostnamePrefix,
|
|
5136
|
-
hostname: anyHostname ? "" :
|
|
5137
|
-
path:
|
|
5145
|
+
hostname: anyHostname ? "" : url18.hostname,
|
|
5146
|
+
path: url18.pathname,
|
|
5138
5147
|
allowPathSuffix
|
|
5139
5148
|
});
|
|
5140
5149
|
}
|
|
@@ -5175,11 +5184,11 @@ function namespaceEntries(namespaces) {
|
|
|
5175
5184
|
return [];
|
|
5176
5185
|
}
|
|
5177
5186
|
}
|
|
5178
|
-
function maybeParseURL(
|
|
5179
|
-
if (typeof
|
|
5187
|
+
function maybeParseURL(url18) {
|
|
5188
|
+
if (typeof url18 !== "string" || import_path14.default.isAbsolute(url18))
|
|
5180
5189
|
return;
|
|
5181
5190
|
try {
|
|
5182
|
-
return new URL(
|
|
5191
|
+
return new URL(url18);
|
|
5183
5192
|
} catch {
|
|
5184
5193
|
}
|
|
5185
5194
|
}
|
|
@@ -5188,16 +5197,16 @@ function getPersistPath(pluginName, tmpPath, persist) {
|
|
|
5188
5197
|
if (persist === void 0 || persist === false) {
|
|
5189
5198
|
return memoryishPath;
|
|
5190
5199
|
}
|
|
5191
|
-
const
|
|
5192
|
-
if (
|
|
5193
|
-
if (
|
|
5200
|
+
const url18 = maybeParseURL(persist);
|
|
5201
|
+
if (url18 !== void 0) {
|
|
5202
|
+
if (url18.protocol === "memory:") {
|
|
5194
5203
|
return memoryishPath;
|
|
5195
|
-
} else if (
|
|
5196
|
-
return (0, import_url12.fileURLToPath)(
|
|
5204
|
+
} else if (url18.protocol === "file:") {
|
|
5205
|
+
return (0, import_url12.fileURLToPath)(url18);
|
|
5197
5206
|
}
|
|
5198
5207
|
throw new MiniflareCoreError(
|
|
5199
5208
|
"ERR_PERSIST_UNSUPPORTED",
|
|
5200
|
-
`Unsupported "${
|
|
5209
|
+
`Unsupported "${url18.protocol}" persistence protocol for storage: ${url18.href}`
|
|
5201
5210
|
);
|
|
5202
5211
|
}
|
|
5203
5212
|
return persist === true ? import_path14.default.join(DEFAULT_PERSIST_ROOT, pluginName) : persist;
|
|
@@ -5817,60 +5826,60 @@ function createJavaScriptModule(code, name, modulePath, type) {
|
|
|
5817
5826
|
}
|
|
5818
5827
|
var encoder = new import_util.TextEncoder();
|
|
5819
5828
|
var decoder = new import_util.TextDecoder();
|
|
5820
|
-
function contentsToString(
|
|
5821
|
-
return typeof
|
|
5829
|
+
function contentsToString(contents18) {
|
|
5830
|
+
return typeof contents18 === "string" ? contents18 : decoder.decode(contents18);
|
|
5822
5831
|
}
|
|
5823
|
-
function contentsToArray(
|
|
5824
|
-
return typeof
|
|
5832
|
+
function contentsToArray(contents18) {
|
|
5833
|
+
return typeof contents18 === "string" ? encoder.encode(contents18) : contents18;
|
|
5825
5834
|
}
|
|
5826
5835
|
function convertModuleDefinition(modulesRoot, def) {
|
|
5827
5836
|
const name = moduleName(modulesRoot, def.path);
|
|
5828
|
-
const
|
|
5837
|
+
const contents18 = def.contents ?? (0, import_fs12.readFileSync)(def.path);
|
|
5829
5838
|
switch (def.type) {
|
|
5830
5839
|
case "ESModule":
|
|
5831
5840
|
case "CommonJS":
|
|
5832
5841
|
case "NodeJsCompatModule":
|
|
5833
5842
|
return createJavaScriptModule(
|
|
5834
|
-
contentsToString(
|
|
5843
|
+
contentsToString(contents18),
|
|
5835
5844
|
name,
|
|
5836
5845
|
import_path15.default.resolve(modulesRoot, def.path),
|
|
5837
5846
|
def.type
|
|
5838
5847
|
);
|
|
5839
5848
|
case "Text":
|
|
5840
|
-
return { name, text: contentsToString(
|
|
5849
|
+
return { name, text: contentsToString(contents18) };
|
|
5841
5850
|
case "Data":
|
|
5842
|
-
return { name, data: contentsToArray(
|
|
5851
|
+
return { name, data: contentsToArray(contents18) };
|
|
5843
5852
|
case "CompiledWasm":
|
|
5844
|
-
return { name, wasm: contentsToArray(
|
|
5853
|
+
return { name, wasm: contentsToArray(contents18) };
|
|
5845
5854
|
case "PythonModule":
|
|
5846
|
-
return { name, pythonModule: contentsToString(
|
|
5855
|
+
return { name, pythonModule: contentsToString(contents18) };
|
|
5847
5856
|
case "PythonRequirement":
|
|
5848
|
-
return { name, pythonRequirement: contentsToString(
|
|
5857
|
+
return { name, pythonRequirement: contentsToString(contents18) };
|
|
5849
5858
|
default:
|
|
5850
5859
|
const exhaustive = def.type;
|
|
5851
5860
|
import_assert5.default.fail(`Unreachable: ${exhaustive} modules are unsupported`);
|
|
5852
5861
|
}
|
|
5853
5862
|
}
|
|
5854
5863
|
function convertWorkerModule(mod) {
|
|
5855
|
-
const
|
|
5856
|
-
(0, import_assert5.default)(
|
|
5864
|
+
const path28 = mod.name;
|
|
5865
|
+
(0, import_assert5.default)(path28 !== void 0);
|
|
5857
5866
|
const m = mod;
|
|
5858
5867
|
if ("esModule" in m)
|
|
5859
|
-
return { path:
|
|
5868
|
+
return { path: path28, type: "ESModule" };
|
|
5860
5869
|
else if ("commonJsModule" in m)
|
|
5861
|
-
return { path:
|
|
5870
|
+
return { path: path28, type: "CommonJS" };
|
|
5862
5871
|
else if ("nodeJsCompatModule" in m)
|
|
5863
|
-
return { path:
|
|
5872
|
+
return { path: path28, type: "NodeJsCompatModule" };
|
|
5864
5873
|
else if ("text" in m)
|
|
5865
|
-
return { path:
|
|
5874
|
+
return { path: path28, type: "Text" };
|
|
5866
5875
|
else if ("data" in m)
|
|
5867
|
-
return { path:
|
|
5876
|
+
return { path: path28, type: "Data" };
|
|
5868
5877
|
else if ("wasm" in m)
|
|
5869
|
-
return { path:
|
|
5878
|
+
return { path: path28, type: "CompiledWasm" };
|
|
5870
5879
|
else if ("pythonModule" in m)
|
|
5871
|
-
return { path:
|
|
5880
|
+
return { path: path28, type: "PythonModule" };
|
|
5872
5881
|
else if ("pythonRequirement" in m)
|
|
5873
|
-
return { path:
|
|
5882
|
+
return { path: path28, type: "PythonRequirement" };
|
|
5874
5883
|
(0, import_assert5.default)(
|
|
5875
5884
|
!("json" in m || "fallbackService" in m),
|
|
5876
5885
|
"Unreachable: json or fallbackService modules aren't generated"
|
|
@@ -6073,8 +6082,8 @@ function getSourceMapper() {
|
|
|
6073
6082
|
// src/plugins/core/errors/index.ts
|
|
6074
6083
|
function maybeGetDiskFile(filePath) {
|
|
6075
6084
|
try {
|
|
6076
|
-
const
|
|
6077
|
-
return { path: filePath, contents:
|
|
6085
|
+
const contents18 = import_fs13.default.readFileSync(filePath, "utf8");
|
|
6086
|
+
return { path: filePath, contents: contents18 };
|
|
6078
6087
|
} catch (e) {
|
|
6079
6088
|
if (e.code !== "ENOENT")
|
|
6080
6089
|
throw e;
|
|
@@ -6089,8 +6098,8 @@ function maybeGetFile(workerSrcOpts, fileSpecifier) {
|
|
|
6089
6098
|
const modulesRoot = srcOpts.modulesRoot ?? "";
|
|
6090
6099
|
for (const module2 of srcOpts.modules) {
|
|
6091
6100
|
if (module2.contents !== void 0 && import_path16.default.resolve(modulesRoot, module2.path) === filePath) {
|
|
6092
|
-
const
|
|
6093
|
-
return { path: filePath, contents:
|
|
6101
|
+
const contents18 = contentsToString(module2.contents);
|
|
6102
|
+
return { path: filePath, contents: contents18 };
|
|
6094
6103
|
}
|
|
6095
6104
|
}
|
|
6096
6105
|
} else if ("script" in srcOpts && "scriptPath" in srcOpts && srcOpts.script !== void 0 && srcOpts.scriptPath !== void 0) {
|
|
@@ -6274,7 +6283,7 @@ var SynchronousFetcher = class {
|
|
|
6274
6283
|
transferList: [this.#channel.port2]
|
|
6275
6284
|
});
|
|
6276
6285
|
}
|
|
6277
|
-
fetch(
|
|
6286
|
+
fetch(url18, init2) {
|
|
6278
6287
|
this.#ensureWorker();
|
|
6279
6288
|
Atomics.store(
|
|
6280
6289
|
this.#notifyHandle,
|
|
@@ -6287,7 +6296,7 @@ var SynchronousFetcher = class {
|
|
|
6287
6296
|
this.#channel.port1.postMessage({
|
|
6288
6297
|
id,
|
|
6289
6298
|
method: init2.method,
|
|
6290
|
-
url:
|
|
6299
|
+
url: url18.toString(),
|
|
6291
6300
|
headers: init2.headers,
|
|
6292
6301
|
body: init2.body
|
|
6293
6302
|
});
|
|
@@ -6407,8 +6416,8 @@ var ProxyClient = class {
|
|
|
6407
6416
|
}
|
|
6408
6417
|
};
|
|
6409
6418
|
var ProxyClientBridge = class {
|
|
6410
|
-
constructor(
|
|
6411
|
-
this.url =
|
|
6419
|
+
constructor(url18, dispatchFetch) {
|
|
6420
|
+
this.url = url18;
|
|
6412
6421
|
this.dispatchFetch = dispatchFetch;
|
|
6413
6422
|
this.#finalizationRegistry = new FinalizationRegistry(this.#finalizeProxy);
|
|
6414
6423
|
}
|
|
@@ -7073,11 +7082,20 @@ function validateCompatibilityDate(log, compatibilityDate) {
|
|
|
7073
7082
|
}
|
|
7074
7083
|
return compatibilityDate;
|
|
7075
7084
|
}
|
|
7076
|
-
function
|
|
7077
|
-
return Object.entries(bindings).map(([name, value]) =>
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
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
|
+
});
|
|
7081
7099
|
}
|
|
7082
7100
|
var WRAPPED_MODULE_PREFIX = "miniflare-internal:wrapped:";
|
|
7083
7101
|
function workerNameToWrappedModule(workerName) {
|
|
@@ -7094,7 +7112,7 @@ var CORE_PLUGIN = {
|
|
|
7094
7112
|
getBindings(options, workerIndex) {
|
|
7095
7113
|
const bindings = [];
|
|
7096
7114
|
if (options.bindings !== void 0) {
|
|
7097
|
-
bindings.push(...
|
|
7115
|
+
bindings.push(...buildBindings(options.bindings));
|
|
7098
7116
|
}
|
|
7099
7117
|
if (options.wasmBindings !== void 0) {
|
|
7100
7118
|
bindings.push(
|
|
@@ -7106,7 +7124,7 @@ var CORE_PLUGIN = {
|
|
|
7106
7124
|
if (options.textBlobBindings !== void 0) {
|
|
7107
7125
|
bindings.push(
|
|
7108
7126
|
...Object.entries(options.textBlobBindings).map(
|
|
7109
|
-
([name,
|
|
7127
|
+
([name, path28]) => import_promises6.default.readFile(path28, "utf8").then((text) => ({ name, text }))
|
|
7110
7128
|
)
|
|
7111
7129
|
);
|
|
7112
7130
|
}
|
|
@@ -7143,7 +7161,7 @@ var CORE_PLUGIN = {
|
|
|
7143
7161
|
const entrypoint = isObject ? designator.entrypoint : void 0;
|
|
7144
7162
|
const bindings2 = isObject ? designator.bindings : void 0;
|
|
7145
7163
|
const moduleName2 = workerNameToWrappedModule(scriptName);
|
|
7146
|
-
const innerBindings = bindings2 === void 0 ? [] :
|
|
7164
|
+
const innerBindings = bindings2 === void 0 ? [] : buildBindings(bindings2);
|
|
7147
7165
|
return {
|
|
7148
7166
|
name,
|
|
7149
7167
|
wrapped: { moduleName: moduleName2, entrypoint, innerBindings }
|
|
@@ -7179,7 +7197,7 @@ var CORE_PLUGIN = {
|
|
|
7179
7197
|
if (options.textBlobBindings !== void 0) {
|
|
7180
7198
|
bindingEntries2.push(
|
|
7181
7199
|
...Object.entries(options.textBlobBindings).map(
|
|
7182
|
-
([name,
|
|
7200
|
+
([name, path28]) => import_promises6.default.readFile(path28, "utf8").then((text) => [name, text])
|
|
7183
7201
|
)
|
|
7184
7202
|
);
|
|
7185
7203
|
}
|
|
@@ -7752,9 +7770,9 @@ var encodeManifest = (manifest) => {
|
|
|
7752
7770
|
var bytesToHex = (buffer) => {
|
|
7753
7771
|
return [...new Uint8Array(buffer)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
7754
7772
|
};
|
|
7755
|
-
var hashPath = async (
|
|
7773
|
+
var hashPath = async (path28) => {
|
|
7756
7774
|
const encoder3 = new TextEncoder();
|
|
7757
|
-
const data = encoder3.encode(
|
|
7775
|
+
const data = encoder3.encode(path28);
|
|
7758
7776
|
const hashBuffer = await import_node_crypto.default.subtle.digest("SHA-256", data.buffer);
|
|
7759
7777
|
return new Uint8Array(hashBuffer, 0, PATH_HASH_SIZE);
|
|
7760
7778
|
};
|
|
@@ -7895,55 +7913,55 @@ var D1_PLUGIN = {
|
|
|
7895
7913
|
var import_node_assert3 = __toESM(require("node:assert"));
|
|
7896
7914
|
var import_zod15 = require("zod");
|
|
7897
7915
|
var HYPERDRIVE_PLUGIN_NAME = "hyperdrive";
|
|
7898
|
-
function hasPostgresProtocol(
|
|
7899
|
-
return
|
|
7916
|
+
function hasPostgresProtocol(url18) {
|
|
7917
|
+
return url18.protocol === "postgresql:" || url18.protocol === "postgres:";
|
|
7900
7918
|
}
|
|
7901
|
-
function getPort(
|
|
7902
|
-
if (
|
|
7903
|
-
return
|
|
7904
|
-
if (hasPostgresProtocol(
|
|
7919
|
+
function getPort(url18) {
|
|
7920
|
+
if (url18.port !== "")
|
|
7921
|
+
return url18.port;
|
|
7922
|
+
if (hasPostgresProtocol(url18))
|
|
7905
7923
|
return "5432";
|
|
7906
|
-
import_node_assert3.default.fail(`Expected known protocol, got ${
|
|
7924
|
+
import_node_assert3.default.fail(`Expected known protocol, got ${url18.protocol}`);
|
|
7907
7925
|
}
|
|
7908
|
-
var HyperdriveSchema = import_zod15.z.union([import_zod15.z.string().url(), import_zod15.z.instanceof(URL)]).transform((
|
|
7909
|
-
if (typeof
|
|
7910
|
-
|
|
7911
|
-
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 === "") {
|
|
7912
7930
|
ctx.addIssue({
|
|
7913
7931
|
code: import_zod15.z.ZodIssueCode.custom,
|
|
7914
7932
|
message: "You must specify the database protocol - e.g. 'postgresql'."
|
|
7915
7933
|
});
|
|
7916
|
-
} else if (!hasPostgresProtocol(
|
|
7934
|
+
} else if (!hasPostgresProtocol(url18)) {
|
|
7917
7935
|
ctx.addIssue({
|
|
7918
7936
|
code: import_zod15.z.ZodIssueCode.custom,
|
|
7919
7937
|
message: "Only PostgreSQL or PostgreSQL compatible databases are currently supported."
|
|
7920
7938
|
});
|
|
7921
7939
|
}
|
|
7922
|
-
if (
|
|
7940
|
+
if (url18.host === "") {
|
|
7923
7941
|
ctx.addIssue({
|
|
7924
7942
|
code: import_zod15.z.ZodIssueCode.custom,
|
|
7925
7943
|
message: "You must provide a hostname or IP address in your connection string - e.g. 'user:password@database-hostname.example.com:5432/databasename"
|
|
7926
7944
|
});
|
|
7927
7945
|
}
|
|
7928
|
-
if (
|
|
7946
|
+
if (url18.pathname === "") {
|
|
7929
7947
|
ctx.addIssue({
|
|
7930
7948
|
code: import_zod15.z.ZodIssueCode.custom,
|
|
7931
7949
|
message: "You must provide a database name as the path component - e.g. /postgres"
|
|
7932
7950
|
});
|
|
7933
7951
|
}
|
|
7934
|
-
if (
|
|
7952
|
+
if (url18.username === "") {
|
|
7935
7953
|
ctx.addIssue({
|
|
7936
7954
|
code: import_zod15.z.ZodIssueCode.custom,
|
|
7937
7955
|
message: "You must provide a username - e.g. 'user:password@database.example.com:port/databasename'"
|
|
7938
7956
|
});
|
|
7939
7957
|
}
|
|
7940
|
-
if (
|
|
7958
|
+
if (url18.password === "") {
|
|
7941
7959
|
ctx.addIssue({
|
|
7942
7960
|
code: import_zod15.z.ZodIssueCode.custom,
|
|
7943
7961
|
message: "You must provide a password - e.g. 'user:password@database.example.com:port/databasename' "
|
|
7944
7962
|
});
|
|
7945
7963
|
}
|
|
7946
|
-
return
|
|
7964
|
+
return url18;
|
|
7947
7965
|
});
|
|
7948
7966
|
var HyperdriveInputOptionsSchema = import_zod15.z.object({
|
|
7949
7967
|
hyperdrives: import_zod15.z.record(import_zod15.z.string(), HyperdriveSchema).optional()
|
|
@@ -7952,9 +7970,9 @@ var HYPERDRIVE_PLUGIN = {
|
|
|
7952
7970
|
options: HyperdriveInputOptionsSchema,
|
|
7953
7971
|
getBindings(options) {
|
|
7954
7972
|
return Object.entries(options.hyperdrives ?? {}).map(
|
|
7955
|
-
([name,
|
|
7956
|
-
const database =
|
|
7957
|
-
const scheme =
|
|
7973
|
+
([name, url18]) => {
|
|
7974
|
+
const database = url18.pathname.replace("/", "");
|
|
7975
|
+
const scheme = url18.protocol.replace(":", "");
|
|
7958
7976
|
return {
|
|
7959
7977
|
name,
|
|
7960
7978
|
hyperdrive: {
|
|
@@ -7962,8 +7980,8 @@ var HYPERDRIVE_PLUGIN = {
|
|
|
7962
7980
|
name: `${HYPERDRIVE_PLUGIN_NAME}:${name}`
|
|
7963
7981
|
},
|
|
7964
7982
|
database: decodeURIComponent(database),
|
|
7965
|
-
user: decodeURIComponent(
|
|
7966
|
-
password: decodeURIComponent(
|
|
7983
|
+
user: decodeURIComponent(url18.username),
|
|
7984
|
+
password: decodeURIComponent(url18.password),
|
|
7967
7985
|
scheme
|
|
7968
7986
|
}
|
|
7969
7987
|
};
|
|
@@ -7972,11 +7990,11 @@ var HYPERDRIVE_PLUGIN = {
|
|
|
7972
7990
|
},
|
|
7973
7991
|
getNodeBindings(options) {
|
|
7974
7992
|
return Object.fromEntries(
|
|
7975
|
-
Object.entries(options.hyperdrives ?? {}).map(([name,
|
|
7993
|
+
Object.entries(options.hyperdrives ?? {}).map(([name, url18]) => {
|
|
7976
7994
|
const connectionOverrides = {
|
|
7977
|
-
connectionString: `${
|
|
7978
|
-
port: Number.parseInt(
|
|
7979
|
-
host:
|
|
7995
|
+
connectionString: `${url18}`,
|
|
7996
|
+
port: Number.parseInt(url18.port),
|
|
7997
|
+
host: url18.hostname
|
|
7980
7998
|
};
|
|
7981
7999
|
const proxyNodeBinding = new ProxyNodeBinding({
|
|
7982
8000
|
get(target, prop) {
|
|
@@ -7989,10 +8007,10 @@ var HYPERDRIVE_PLUGIN = {
|
|
|
7989
8007
|
},
|
|
7990
8008
|
async getServices({ options }) {
|
|
7991
8009
|
return Object.entries(options.hyperdrives ?? {}).map(
|
|
7992
|
-
([name,
|
|
8010
|
+
([name, url18]) => ({
|
|
7993
8011
|
name: `${HYPERDRIVE_PLUGIN_NAME}:${name}`,
|
|
7994
8012
|
external: {
|
|
7995
|
-
address: `${
|
|
8013
|
+
address: `${url18.hostname}:${getPort(url18)}`,
|
|
7996
8014
|
tcp: {}
|
|
7997
8015
|
}
|
|
7998
8016
|
})
|
|
@@ -8326,7 +8344,11 @@ var QUEUES_PLUGIN = {
|
|
|
8326
8344
|
{ name: "broker.worker.js", esModule: broker_worker_default() }
|
|
8327
8345
|
],
|
|
8328
8346
|
durableObjectNamespaces: [
|
|
8329
|
-
{
|
|
8347
|
+
{
|
|
8348
|
+
className: QUEUE_BROKER_OBJECT_CLASS_NAME,
|
|
8349
|
+
uniqueKey,
|
|
8350
|
+
preventEviction: true
|
|
8351
|
+
}
|
|
8330
8352
|
],
|
|
8331
8353
|
// Miniflare's Queue broker is in-memory only at the moment
|
|
8332
8354
|
durableObjectStorage: { inMemory: kVoid },
|
|
@@ -8530,7 +8552,7 @@ var RatelimitOptionsSchema = import_zod19.z.object({
|
|
|
8530
8552
|
var RATELIMIT_PLUGIN_NAME = "ratelimit";
|
|
8531
8553
|
var SERVICE_RATELIMIT_PREFIX = `${RATELIMIT_PLUGIN_NAME}`;
|
|
8532
8554
|
var SERVICE_RATELIMIT_MODULE = `cloudflare-internal:${SERVICE_RATELIMIT_PREFIX}:module`;
|
|
8533
|
-
function
|
|
8555
|
+
function buildJsonBindings(bindings) {
|
|
8534
8556
|
return Object.entries(bindings).map(([name, value]) => ({
|
|
8535
8557
|
name,
|
|
8536
8558
|
json: JSON.stringify(value)
|
|
@@ -8547,7 +8569,7 @@ var RATELIMIT_PLUGIN = {
|
|
|
8547
8569
|
name,
|
|
8548
8570
|
wrapped: {
|
|
8549
8571
|
moduleName: SERVICE_RATELIMIT_MODULE,
|
|
8550
|
-
innerBindings:
|
|
8572
|
+
innerBindings: buildJsonBindings({
|
|
8551
8573
|
namespaceId: name,
|
|
8552
8574
|
limit: config.simple.limit,
|
|
8553
8575
|
period: config.simple.period
|
|
@@ -8589,6 +8611,125 @@ var RATELIMIT_PLUGIN = {
|
|
|
8589
8611
|
}
|
|
8590
8612
|
};
|
|
8591
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
|
+
|
|
8592
8733
|
// src/plugins/index.ts
|
|
8593
8734
|
var PLUGINS = {
|
|
8594
8735
|
[CORE_PLUGIN_NAME2]: CORE_PLUGIN,
|
|
@@ -8600,7 +8741,8 @@ var PLUGINS = {
|
|
|
8600
8741
|
[R2_PLUGIN_NAME]: R2_PLUGIN,
|
|
8601
8742
|
[HYPERDRIVE_PLUGIN_NAME]: HYPERDRIVE_PLUGIN,
|
|
8602
8743
|
[RATELIMIT_PLUGIN_NAME]: RATELIMIT_PLUGIN,
|
|
8603
|
-
[ASSETS_PLUGIN_NAME]: ASSETS_PLUGIN
|
|
8744
|
+
[ASSETS_PLUGIN_NAME]: ASSETS_PLUGIN,
|
|
8745
|
+
[WORKFLOWS_PLUGIN_NAME]: WORKFLOWS_PLUGIN
|
|
8604
8746
|
};
|
|
8605
8747
|
var PLUGIN_ENTRIES = Object.entries(PLUGINS);
|
|
8606
8748
|
|
|
@@ -8706,8 +8848,8 @@ function hasMultipleDistinctMessages(issues, atDepth) {
|
|
|
8706
8848
|
}
|
|
8707
8849
|
return false;
|
|
8708
8850
|
}
|
|
8709
|
-
function annotate(groupCounts, annotated, input, issue,
|
|
8710
|
-
if (
|
|
8851
|
+
function annotate(groupCounts, annotated, input, issue, path28, groupId) {
|
|
8852
|
+
if (path28.length === 0) {
|
|
8711
8853
|
if (issue.code === "invalid_union") {
|
|
8712
8854
|
const unionIssues = issue.unionErrors.flatMap(({ issues }) => issues);
|
|
8713
8855
|
let newGroupId;
|
|
@@ -8754,7 +8896,7 @@ function annotate(groupCounts, annotated, input, issue, path27, groupId) {
|
|
|
8754
8896
|
[kGroupId]: groupId
|
|
8755
8897
|
};
|
|
8756
8898
|
}
|
|
8757
|
-
const [head, ...tail] =
|
|
8899
|
+
const [head, ...tail] = path28;
|
|
8758
8900
|
(0, import_assert11.default)(isRecord(input), "Expected object/array input for nested issue");
|
|
8759
8901
|
if (annotated === void 0) {
|
|
8760
8902
|
if (Array.isArray(input)) {
|
|
@@ -8964,7 +9106,7 @@ function validateOptions(opts) {
|
|
|
8964
9106
|
);
|
|
8965
9107
|
const sharedRootPath = multipleWorkers ? getRootPath(sharedOpts) : "";
|
|
8966
9108
|
const workerRootPaths = workerOpts.map(
|
|
8967
|
-
(opts2) =>
|
|
9109
|
+
(opts2) => import_path26.default.resolve(sharedRootPath, getRootPath(opts2))
|
|
8968
9110
|
);
|
|
8969
9111
|
try {
|
|
8970
9112
|
for (const [key, plugin] of PLUGIN_ENTRIES) {
|
|
@@ -8980,7 +9122,7 @@ function validateOptions(opts) {
|
|
|
8980
9122
|
}
|
|
8981
9123
|
}
|
|
8982
9124
|
} catch (e) {
|
|
8983
|
-
if (e instanceof
|
|
9125
|
+
if (e instanceof import_zod22.z.ZodError) {
|
|
8984
9126
|
let formatted;
|
|
8985
9127
|
try {
|
|
8986
9128
|
formatted = formatZodError(e, opts);
|
|
@@ -9392,7 +9534,7 @@ var Miniflare2 = class {
|
|
|
9392
9534
|
}
|
|
9393
9535
|
}
|
|
9394
9536
|
});
|
|
9395
|
-
this.#tmpPath =
|
|
9537
|
+
this.#tmpPath = import_path26.default.join(
|
|
9396
9538
|
import_os2.default.tmpdir(),
|
|
9397
9539
|
`miniflare-${import_crypto3.default.randomBytes(16).toString("hex")}`
|
|
9398
9540
|
);
|
|
@@ -9400,7 +9542,7 @@ var Miniflare2 = class {
|
|
|
9400
9542
|
this.#removeExitHook = (0, import_exit_hook.default)(() => {
|
|
9401
9543
|
void this.#runtime?.dispose();
|
|
9402
9544
|
try {
|
|
9403
|
-
|
|
9545
|
+
import_fs22.default.rmSync(this.#tmpPath, { force: true, recursive: true });
|
|
9404
9546
|
} catch (e) {
|
|
9405
9547
|
this.#log.debug(`Unable to remove temporary directory: ${String(e)}`);
|
|
9406
9548
|
}
|
|
@@ -9437,7 +9579,7 @@ var Miniflare2 = class {
|
|
|
9437
9579
|
if (!(response instanceof Response)) {
|
|
9438
9580
|
response = new Response(response.body, response);
|
|
9439
9581
|
}
|
|
9440
|
-
return
|
|
9582
|
+
return import_zod22.z.instanceof(Response).parse(response);
|
|
9441
9583
|
} catch (e) {
|
|
9442
9584
|
return new Response(e?.stack ?? e, { status: 500 });
|
|
9443
9585
|
}
|
|
@@ -9462,11 +9604,11 @@ var Miniflare2 = class {
|
|
|
9462
9604
|
(0, import_assert12.default)(!Array.isArray(cfBlob));
|
|
9463
9605
|
const cf = cfBlob ? JSON.parse(cfBlob) : void 0;
|
|
9464
9606
|
const originalUrl = headers.get(CoreHeaders.ORIGINAL_URL);
|
|
9465
|
-
const
|
|
9607
|
+
const url18 = new URL(originalUrl ?? req.url ?? "", "http://localhost");
|
|
9466
9608
|
headers.delete(CoreHeaders.ORIGINAL_URL);
|
|
9467
9609
|
const noBody = req.method === "GET" || req.method === "HEAD";
|
|
9468
9610
|
const body = noBody ? void 0 : safeReadableStreamFrom(req);
|
|
9469
|
-
const request = new Request(
|
|
9611
|
+
const request = new Request(url18, {
|
|
9470
9612
|
method: req.method,
|
|
9471
9613
|
headers,
|
|
9472
9614
|
body,
|
|
@@ -9487,13 +9629,13 @@ var Miniflare2 = class {
|
|
|
9487
9629
|
request,
|
|
9488
9630
|
this
|
|
9489
9631
|
);
|
|
9490
|
-
} else if (
|
|
9632
|
+
} else if (url18.pathname === "/core/error") {
|
|
9491
9633
|
response = await handlePrettyErrorRequest(
|
|
9492
9634
|
this.#log,
|
|
9493
9635
|
this.#workerSrcOpts,
|
|
9494
9636
|
request
|
|
9495
9637
|
);
|
|
9496
|
-
} else if (
|
|
9638
|
+
} else if (url18.pathname === "/core/log") {
|
|
9497
9639
|
const level = parseInt(request.headers.get(SharedHeaders.LOG_LEVEL));
|
|
9498
9640
|
(0, import_assert12.default)(
|
|
9499
9641
|
0 /* NONE */ <= level && level <= 5 /* VERBOSE */,
|
|
@@ -9628,7 +9770,7 @@ var Miniflare2 = class {
|
|
|
9628
9770
|
sockets.push({
|
|
9629
9771
|
name: SOCKET_ENTRY_LOCAL,
|
|
9630
9772
|
service: { name: SERVICE_ENTRY },
|
|
9631
|
-
http:
|
|
9773
|
+
http: {},
|
|
9632
9774
|
address: "127.0.0.1:0"
|
|
9633
9775
|
});
|
|
9634
9776
|
}
|
|
@@ -9643,6 +9785,11 @@ var Miniflare2 = class {
|
|
|
9643
9785
|
const workerOpts = allWorkerOpts[i];
|
|
9644
9786
|
const workerName = workerOpts.core.name ?? "";
|
|
9645
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
|
+
}
|
|
9646
9793
|
const workerBindings = [];
|
|
9647
9794
|
allWorkerBindings.set(workerName, workerBindings);
|
|
9648
9795
|
const additionalModules = [];
|
|
@@ -9975,11 +10122,11 @@ var Miniflare2 = class {
|
|
|
9975
10122
|
(0, import_assert12.default)(this.#runtimeEntryURL !== void 0);
|
|
9976
10123
|
(0, import_assert12.default)(this.#runtimeDispatcher !== void 0);
|
|
9977
10124
|
const forward = new Request(input, init2);
|
|
9978
|
-
const
|
|
10125
|
+
const url18 = new URL(forward.url);
|
|
9979
10126
|
const actualRuntimeOrigin = this.#runtimeEntryURL.origin;
|
|
9980
|
-
const userRuntimeOrigin =
|
|
9981
|
-
|
|
9982
|
-
|
|
10127
|
+
const userRuntimeOrigin = url18.origin;
|
|
10128
|
+
url18.protocol = this.#runtimeEntryURL.protocol;
|
|
10129
|
+
url18.host = this.#runtimeEntryURL.host;
|
|
9983
10130
|
if (forward.body !== null && forward.headers.get("Content-Length") === "0") {
|
|
9984
10131
|
forward.headers.delete("Content-Length");
|
|
9985
10132
|
}
|
|
@@ -9993,7 +10140,7 @@ var Miniflare2 = class {
|
|
|
9993
10140
|
);
|
|
9994
10141
|
const forwardInit = forward;
|
|
9995
10142
|
forwardInit.dispatcher = dispatcher;
|
|
9996
|
-
const response = await fetch3(
|
|
10143
|
+
const response = await fetch3(url18, forwardInit);
|
|
9997
10144
|
const stack = response.headers.get(CoreHeaders.ERROR_STACK);
|
|
9998
10145
|
if (response.status === 500 && stack !== null) {
|
|
9999
10146
|
const caught = JsonErrorSchema.parse(await response.json());
|
|
@@ -10143,7 +10290,7 @@ var Miniflare2 = class {
|
|
|
10143
10290
|
await this.#proxyClient?.dispose();
|
|
10144
10291
|
await this.#runtime?.dispose();
|
|
10145
10292
|
await this.#stopLoopbackServer();
|
|
10146
|
-
await
|
|
10293
|
+
await import_fs22.default.promises.rm(this.#tmpPath, { force: true, recursive: true });
|
|
10147
10294
|
maybeInstanceRegistry?.delete(this);
|
|
10148
10295
|
}
|
|
10149
10296
|
}
|
|
@@ -10177,7 +10324,6 @@ var Miniflare2 = class {
|
|
|
10177
10324
|
DispatchFetchDispatcher,
|
|
10178
10325
|
DurableObjectsOptionsSchema,
|
|
10179
10326
|
DurableObjectsSharedOptionsSchema,
|
|
10180
|
-
ENTRY_SOCKET_HTTP_OPTIONS,
|
|
10181
10327
|
ErrorEvent,
|
|
10182
10328
|
File,
|
|
10183
10329
|
FormData,
|
|
@@ -10256,10 +10402,15 @@ var Miniflare2 = class {
|
|
|
10256
10402
|
TlsOptions_Version,
|
|
10257
10403
|
TypedEventTarget,
|
|
10258
10404
|
WORKER_BINDING_SERVICE_LOOPBACK,
|
|
10405
|
+
WORKFLOWS_PLUGIN,
|
|
10406
|
+
WORKFLOWS_PLUGIN_NAME,
|
|
10407
|
+
WORKFLOWS_STORAGE_SERVICE_NAME,
|
|
10259
10408
|
WaitGroup,
|
|
10260
10409
|
WebSocket,
|
|
10261
10410
|
WebSocketPair,
|
|
10262
10411
|
Worker_Binding_CryptoKey_Usage,
|
|
10412
|
+
WorkflowsOptionsSchema,
|
|
10413
|
+
WorkflowsSharedOptionsSchema,
|
|
10263
10414
|
__MiniflareFunctionWrapper,
|
|
10264
10415
|
_enableControlEndpoints,
|
|
10265
10416
|
_forceColour,
|