@cloudflare/workers-utils 0.12.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/browser.d.mts +1 -1
- package/dist/browser.mjs +3 -2
- package/dist/{chunk-4233U5MA.mjs → chunk-BLWXWFJK.mjs} +72 -36
- package/dist/{chunk-LDFBMPMW.mjs → chunk-DCOBXSFB.mjs} +1 -8
- package/dist/chunk-O4YGOZSW.mjs +52 -0
- package/dist/chunk-OZQVB3L3.mjs +8 -0
- package/dist/{chunk-NNMRVG4F.mjs → chunk-XXCQEG76.mjs} +32 -26
- package/dist/{config-BQZJPwXe.d.mts → config-CnJQHRQs.d.mts} +250 -12
- package/dist/index.d.mts +112 -40
- package/dist/index.mjs +5855 -393
- package/dist/metafile-esm.json +1 -1
- package/dist/prometheus-metrics.d.mts +50 -0
- package/dist/prometheus-metrics.mjs +2 -0
- package/dist/test-helpers/index.d.mts +1 -1
- package/dist/test-helpers/index.mjs +3 -2
- package/package.json +23 -18
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
# `@cloudflare/worker-utils`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Internal utility package for workers-sdk. Not intended for external use — APIs may change without notice.
|
|
4
|
+
|
|
5
|
+
This package contains common utilities used across the dash, Wrangler, and other tooling.
|
package/dist/browser.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as TailConsumer,
|
|
1
|
+
import { T as TailConsumer, au as WorkerMetadata, R as RawConfig } from './config-CnJQHRQs.mjs';
|
|
2
2
|
import { AssetConfig } from '@cloudflare/workers-shared';
|
|
3
3
|
import { Cloudflare } from 'cloudflare';
|
|
4
4
|
|
package/dist/browser.mjs
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { constructWranglerConfig } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { constructWranglerConfig } from './chunk-BLWXWFJK.mjs';
|
|
2
|
+
import './chunk-OZQVB3L3.mjs';
|
|
3
|
+
import './chunk-DCOBXSFB.mjs';
|
|
@@ -1,38 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ENVIRONMENT_TAG_PREFIX, SERVICE_TAG_PREFIX } from './chunk-OZQVB3L3.mjs';
|
|
2
|
+
import { __name } from './chunk-DCOBXSFB.mjs';
|
|
2
3
|
import assert from 'node:assert';
|
|
3
|
-
import module from 'node:module';
|
|
4
|
-
import path from 'node:path';
|
|
5
4
|
|
|
6
|
-
function getLocalWorkerdCompatibilityDate({
|
|
7
|
-
projectPath = process.cwd()
|
|
8
|
-
} = {}) {
|
|
9
|
-
try {
|
|
10
|
-
const projectRequire = module.createRequire(
|
|
11
|
-
path.join(projectPath, "package.json")
|
|
12
|
-
);
|
|
13
|
-
const miniflareEntry = projectRequire.resolve("miniflare");
|
|
14
|
-
const miniflareRequire = module.createRequire(miniflareEntry);
|
|
15
|
-
const miniflareWorkerd = miniflareRequire("workerd");
|
|
16
|
-
const workerdDate = miniflareWorkerd.compatibilityDate;
|
|
17
|
-
return {
|
|
18
|
-
date: toSafeCompatibilityDate(new Date(workerdDate)),
|
|
19
|
-
source: "workerd"
|
|
20
|
-
};
|
|
21
|
-
} catch {
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
date: "2025-09-27",
|
|
25
|
-
source: "fallback"
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
__name(getLocalWorkerdCompatibilityDate, "getLocalWorkerdCompatibilityDate");
|
|
29
|
-
function toSafeCompatibilityDate(date) {
|
|
30
|
-
if (date.getTime() > Date.now()) {
|
|
31
|
-
return formatCompatibilityDate(/* @__PURE__ */ new Date());
|
|
32
|
-
}
|
|
33
|
-
return formatCompatibilityDate(date);
|
|
34
|
-
}
|
|
35
|
-
__name(toSafeCompatibilityDate, "toSafeCompatibilityDate");
|
|
36
5
|
function isCompatDate(str) {
|
|
37
6
|
return /^\d{4}-\d{2}-\d{2}$/.test(str);
|
|
38
7
|
}
|
|
@@ -43,6 +12,10 @@ function formatCompatibilityDate(date) {
|
|
|
43
12
|
return compatDate;
|
|
44
13
|
}
|
|
45
14
|
__name(formatCompatibilityDate, "formatCompatibilityDate");
|
|
15
|
+
function getTodaysCompatDate() {
|
|
16
|
+
return formatCompatibilityDate(/* @__PURE__ */ new Date());
|
|
17
|
+
}
|
|
18
|
+
__name(getTodaysCompatDate, "getTodaysCompatDate");
|
|
46
19
|
|
|
47
20
|
// src/assert-never.ts
|
|
48
21
|
function assertNever(_value) {
|
|
@@ -125,6 +98,13 @@ function mapWorkerMetadataBindings(bindings) {
|
|
|
125
98
|
};
|
|
126
99
|
}
|
|
127
100
|
break;
|
|
101
|
+
case "stream":
|
|
102
|
+
{
|
|
103
|
+
configObj.stream = {
|
|
104
|
+
binding: binding.name
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
128
108
|
case "media":
|
|
129
109
|
{
|
|
130
110
|
configObj.media = {
|
|
@@ -156,6 +136,17 @@ function mapWorkerMetadataBindings(bindings) {
|
|
|
156
136
|
];
|
|
157
137
|
}
|
|
158
138
|
break;
|
|
139
|
+
case "artifacts":
|
|
140
|
+
{
|
|
141
|
+
configObj.artifacts = [
|
|
142
|
+
...configObj.artifacts ?? [],
|
|
143
|
+
{
|
|
144
|
+
binding: binding.name,
|
|
145
|
+
namespace: binding.namespace
|
|
146
|
+
}
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
159
150
|
case "unsafe_hello_world": {
|
|
160
151
|
configObj.unsafe_hello_world = [
|
|
161
152
|
...configObj.unsafe_hello_world ?? [],
|
|
@@ -166,6 +157,16 @@ function mapWorkerMetadataBindings(bindings) {
|
|
|
166
157
|
];
|
|
167
158
|
break;
|
|
168
159
|
}
|
|
160
|
+
case "flagship": {
|
|
161
|
+
configObj.flagship = [
|
|
162
|
+
...configObj.flagship ?? [],
|
|
163
|
+
{
|
|
164
|
+
binding: binding.name,
|
|
165
|
+
app_id: binding.app_id
|
|
166
|
+
}
|
|
167
|
+
];
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
169
170
|
case "service":
|
|
170
171
|
{
|
|
171
172
|
configObj.services = [
|
|
@@ -281,6 +282,24 @@ function mapWorkerMetadataBindings(bindings) {
|
|
|
281
282
|
}
|
|
282
283
|
];
|
|
283
284
|
break;
|
|
285
|
+
case "ai_search_namespace":
|
|
286
|
+
configObj.ai_search_namespaces = [
|
|
287
|
+
...configObj.ai_search_namespaces ?? [],
|
|
288
|
+
{
|
|
289
|
+
binding: binding.name,
|
|
290
|
+
namespace: binding.namespace
|
|
291
|
+
}
|
|
292
|
+
];
|
|
293
|
+
break;
|
|
294
|
+
case "ai_search":
|
|
295
|
+
configObj.ai_search = [
|
|
296
|
+
...configObj.ai_search ?? [],
|
|
297
|
+
{
|
|
298
|
+
binding: binding.name,
|
|
299
|
+
instance_name: binding.instance_name
|
|
300
|
+
}
|
|
301
|
+
];
|
|
302
|
+
break;
|
|
284
303
|
case "hyperdrive":
|
|
285
304
|
configObj.hyperdrive = [
|
|
286
305
|
...configObj.hyperdrive ?? [],
|
|
@@ -371,6 +390,21 @@ function mapWorkerMetadataBindings(bindings) {
|
|
|
371
390
|
];
|
|
372
391
|
}
|
|
373
392
|
break;
|
|
393
|
+
case "vpc_network":
|
|
394
|
+
{
|
|
395
|
+
if (binding.tunnel_id !== void 0) {
|
|
396
|
+
configObj.vpc_networks = [
|
|
397
|
+
...configObj.vpc_networks ?? [],
|
|
398
|
+
{ binding: binding.name, tunnel_id: binding.tunnel_id }
|
|
399
|
+
];
|
|
400
|
+
} else if (binding.network_id !== void 0) {
|
|
401
|
+
configObj.vpc_networks = [
|
|
402
|
+
...configObj.vpc_networks ?? [],
|
|
403
|
+
{ binding: binding.name, network_id: binding.network_id }
|
|
404
|
+
];
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
break;
|
|
374
408
|
default: {
|
|
375
409
|
configObj.unsafe = {
|
|
376
410
|
bindings: [...configObj.unsafe?.bindings ?? [], binding],
|
|
@@ -399,7 +433,9 @@ function convertWorkerToWranglerConfig(config) {
|
|
|
399
433
|
...config.domains.map((c) => ({
|
|
400
434
|
pattern: c.hostname,
|
|
401
435
|
zone_name: c.zone_name,
|
|
402
|
-
custom_domain: true
|
|
436
|
+
custom_domain: true,
|
|
437
|
+
enabled: c.enabled,
|
|
438
|
+
previews_enabled: c.previews_enabled
|
|
403
439
|
}))
|
|
404
440
|
];
|
|
405
441
|
return {
|
|
@@ -407,7 +443,7 @@ function convertWorkerToWranglerConfig(config) {
|
|
|
407
443
|
main: config.entrypoint,
|
|
408
444
|
workers_dev: config.subdomain.enabled,
|
|
409
445
|
preview_urls: config.subdomain.previews_enabled,
|
|
410
|
-
compatibility_date: config.compatibility_date ??
|
|
446
|
+
compatibility_date: config.compatibility_date ?? getTodaysCompatDate(),
|
|
411
447
|
compatibility_flags: config.compatibility_flags,
|
|
412
448
|
...allRoutes.length ? { routes: allRoutes } : {},
|
|
413
449
|
placement: config.placement?.mode === "smart" ? { mode: "smart" } : void 0,
|
|
@@ -468,4 +504,4 @@ function constructWranglerConfig(workerOrWorkers) {
|
|
|
468
504
|
}
|
|
469
505
|
__name(constructWranglerConfig, "constructWranglerConfig");
|
|
470
506
|
|
|
471
|
-
export { assertNever, constructWranglerConfig,
|
|
507
|
+
export { assertNever, constructWranglerConfig, getTodaysCompatDate, isCompatDate, mapWorkerMetadataBindings };
|
|
@@ -36,11 +36,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
mod
|
|
37
37
|
));
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
var INHERIT_SYMBOL = Symbol.for("inherit_binding");
|
|
41
|
-
var SERVICE_TAG_PREFIX = "cf:service=";
|
|
42
|
-
var ENVIRONMENT_TAG_PREFIX = "cf:environment=";
|
|
43
|
-
var PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
|
|
44
|
-
var JSON_CONFIG_FORMATS = ["json", "jsonc"];
|
|
45
|
-
|
|
46
|
-
export { ENVIRONMENT_TAG_PREFIX, INHERIT_SYMBOL, JSON_CONFIG_FORMATS, PATH_TO_DEPLOY_CONFIG, SERVICE_TAG_PREFIX, __commonJS, __export, __name, __reExport, __require, __toESM };
|
|
39
|
+
export { __commonJS, __export, __name, __reExport, __require, __toESM };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { __name } from './chunk-DCOBXSFB.mjs';
|
|
2
|
+
|
|
3
|
+
// src/prometheus-metrics.ts
|
|
4
|
+
var MetricsRegistry = class {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "MetricsRegistry");
|
|
7
|
+
}
|
|
8
|
+
counters = [];
|
|
9
|
+
/**
|
|
10
|
+
* Create and register a new counter metric.
|
|
11
|
+
*
|
|
12
|
+
* @param name - The metric name (e.g. "service_request_total")
|
|
13
|
+
* @param help - A human-readable description of the metric
|
|
14
|
+
* @returns A Counter that can be incremented
|
|
15
|
+
*/
|
|
16
|
+
createCounter(name, help) {
|
|
17
|
+
const entry = { name, help, value: 0 };
|
|
18
|
+
this.counters.push(entry);
|
|
19
|
+
return {
|
|
20
|
+
inc: /* @__PURE__ */ __name(() => {
|
|
21
|
+
entry.value++;
|
|
22
|
+
}, "inc"),
|
|
23
|
+
add: /* @__PURE__ */ __name((amount) => {
|
|
24
|
+
if (amount < 0) {
|
|
25
|
+
throw new Error("Counter value cannot decrease");
|
|
26
|
+
}
|
|
27
|
+
entry.value += amount;
|
|
28
|
+
}, "add")
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Serialize all registered metrics in Prometheus text exposition format.
|
|
33
|
+
*
|
|
34
|
+
* @see https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
|
|
35
|
+
*/
|
|
36
|
+
metrics() {
|
|
37
|
+
return this.counters.map((c) => {
|
|
38
|
+
let result = "";
|
|
39
|
+
if (c.help.length > 0) {
|
|
40
|
+
result += `# HELP ${c.name} ${c.help}
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
result += `# TYPE ${c.name} counter
|
|
44
|
+
`;
|
|
45
|
+
result += `${c.name} ${c.value}
|
|
46
|
+
`;
|
|
47
|
+
return result;
|
|
48
|
+
}).join("");
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { MetricsRegistry };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var INHERIT_SYMBOL = Symbol.for("inherit_binding");
|
|
3
|
+
var SERVICE_TAG_PREFIX = "cf:service=";
|
|
4
|
+
var ENVIRONMENT_TAG_PREFIX = "cf:environment=";
|
|
5
|
+
var PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
|
|
6
|
+
var JSON_CONFIG_FORMATS = ["json", "jsonc"];
|
|
7
|
+
|
|
8
|
+
export { ENVIRONMENT_TAG_PREFIX, INHERIT_SYMBOL, JSON_CONFIG_FORMATS, PATH_TO_DEPLOY_CONFIG, SERVICE_TAG_PREFIX };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PATH_TO_DEPLOY_CONFIG } from './chunk-OZQVB3L3.mjs';
|
|
2
|
+
import { __name } from './chunk-DCOBXSFB.mjs';
|
|
2
3
|
import fs, { readFileSync as readFileSync$1, statSync, existsSync } from 'node:fs';
|
|
3
4
|
import path, { resolve, isAbsolute, dirname, join } from 'node:path';
|
|
4
5
|
|
|
@@ -11,7 +12,7 @@ var UserError = class extends Error {
|
|
|
11
12
|
constructor(message, options) {
|
|
12
13
|
super(message, options);
|
|
13
14
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
14
|
-
this.telemetryMessage = options?.telemetryMessage ===
|
|
15
|
+
this.telemetryMessage = typeof options?.telemetryMessage === "string" ? options.telemetryMessage : options?.telemetryMessage ? message : void 0;
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
var DeprecationError = class extends UserError {
|
|
@@ -24,13 +25,14 @@ ${message}`, options);
|
|
|
24
25
|
}
|
|
25
26
|
};
|
|
26
27
|
var FatalError = class extends UserError {
|
|
27
|
-
constructor(message, code, options) {
|
|
28
|
-
super(message, options);
|
|
29
|
-
this.code = code;
|
|
30
|
-
}
|
|
31
28
|
static {
|
|
32
29
|
__name(this, "FatalError");
|
|
33
30
|
}
|
|
31
|
+
code;
|
|
32
|
+
constructor(message, options) {
|
|
33
|
+
super(message, options);
|
|
34
|
+
this.code = options.code;
|
|
35
|
+
}
|
|
34
36
|
};
|
|
35
37
|
var CommandLineArgsError = class extends UserError {
|
|
36
38
|
static {
|
|
@@ -38,10 +40,6 @@ var CommandLineArgsError = class extends UserError {
|
|
|
38
40
|
}
|
|
39
41
|
};
|
|
40
42
|
var JsonFriendlyFatalError = class extends FatalError {
|
|
41
|
-
constructor(message, code, options) {
|
|
42
|
-
super(message, code, options);
|
|
43
|
-
this.code = code;
|
|
44
|
-
}
|
|
45
43
|
static {
|
|
46
44
|
__name(this, "JsonFriendlyFatalError");
|
|
47
45
|
}
|
|
@@ -56,16 +54,11 @@ var MissingConfigError = class extends Error {
|
|
|
56
54
|
this.telemetryMessage = `Missing config value for ${key}`;
|
|
57
55
|
}
|
|
58
56
|
};
|
|
59
|
-
function createFatalError(message, isJson,
|
|
57
|
+
function createFatalError(message, isJson, options) {
|
|
60
58
|
if (isJson) {
|
|
61
|
-
return new JsonFriendlyFatalError(
|
|
62
|
-
JSON.stringify(message),
|
|
63
|
-
code,
|
|
64
|
-
telemetryMessage
|
|
65
|
-
);
|
|
66
|
-
} else {
|
|
67
|
-
return new FatalError(`${message}`, code, telemetryMessage);
|
|
59
|
+
return new JsonFriendlyFatalError(JSON.stringify(message), options);
|
|
68
60
|
}
|
|
61
|
+
return new FatalError(`${message}`, options);
|
|
69
62
|
}
|
|
70
63
|
__name(createFatalError, "createFatalError");
|
|
71
64
|
|
|
@@ -2373,6 +2366,9 @@ var APIError = class extends ParseError {
|
|
|
2373
2366
|
this.name = this.constructor.name;
|
|
2374
2367
|
this.#status = status;
|
|
2375
2368
|
}
|
|
2369
|
+
get status() {
|
|
2370
|
+
return this.#status;
|
|
2371
|
+
}
|
|
2376
2372
|
isGatewayError() {
|
|
2377
2373
|
if (this.#status !== void 0) {
|
|
2378
2374
|
return [524].includes(this.#status);
|
|
@@ -2452,7 +2448,8 @@ function readFileSyncToBuffer(file2) {
|
|
|
2452
2448
|
{
|
|
2453
2449
|
text: message.replace(file2, resolve(file2))
|
|
2454
2450
|
}
|
|
2455
|
-
]
|
|
2451
|
+
],
|
|
2452
|
+
telemetryMessage: false
|
|
2456
2453
|
});
|
|
2457
2454
|
}
|
|
2458
2455
|
}
|
|
@@ -2780,32 +2777,41 @@ function findRedirectedWranglerConfig(cwd, userConfigPath) {
|
|
|
2780
2777
|
} catch (e) {
|
|
2781
2778
|
throw new UserError(
|
|
2782
2779
|
`Failed to parse the deploy configuration file at ${path.relative(".", deployConfigPath)}`,
|
|
2783
|
-
{ cause: e }
|
|
2780
|
+
{ cause: e, telemetryMessage: false }
|
|
2784
2781
|
);
|
|
2785
2782
|
}
|
|
2786
2783
|
if (!redirectedConfigPath) {
|
|
2787
|
-
throw new UserError(
|
|
2784
|
+
throw new UserError(
|
|
2785
|
+
esm_default`
|
|
2788
2786
|
A deploy configuration file was found at "${path.relative(".", deployConfigPath)}".
|
|
2789
2787
|
But this is not valid - the required "configPath" property was not found.
|
|
2790
2788
|
Instead this file contains:
|
|
2791
2789
|
\`\`\`
|
|
2792
2790
|
${deployConfigFile}
|
|
2793
2791
|
\`\`\`
|
|
2794
|
-
|
|
2792
|
+
`,
|
|
2793
|
+
{ telemetryMessage: false }
|
|
2794
|
+
);
|
|
2795
2795
|
}
|
|
2796
2796
|
if (!existsSync(redirectedConfigPath)) {
|
|
2797
|
-
throw new UserError(
|
|
2797
|
+
throw new UserError(
|
|
2798
|
+
esm_default`
|
|
2798
2799
|
There is a deploy configuration at "${path.relative(".", deployConfigPath)}".
|
|
2799
2800
|
But the redirected configuration path it points to, "${path.relative(".", redirectedConfigPath)}", does not exist.
|
|
2800
|
-
|
|
2801
|
+
`,
|
|
2802
|
+
{ telemetryMessage: false }
|
|
2803
|
+
);
|
|
2801
2804
|
}
|
|
2802
2805
|
if (userConfigPath) {
|
|
2803
2806
|
if (path.join(path.dirname(userConfigPath), PATH_TO_DEPLOY_CONFIG) !== deployConfigPath) {
|
|
2804
|
-
throw new UserError(
|
|
2807
|
+
throw new UserError(
|
|
2808
|
+
esm_default`
|
|
2805
2809
|
Found both a user configuration file at "${path.relative(".", userConfigPath)}"
|
|
2806
2810
|
and a deploy configuration file at "${path.relative(".", deployConfigPath)}".
|
|
2807
2811
|
But these do not share the same base path so it is not clear which should be used.
|
|
2808
|
-
|
|
2812
|
+
`,
|
|
2813
|
+
{ telemetryMessage: false }
|
|
2814
|
+
);
|
|
2809
2815
|
}
|
|
2810
2816
|
}
|
|
2811
2817
|
return {
|