@cloudflare/workers-utils 0.11.2 → 0.18.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 CHANGED
@@ -1,3 +1,5 @@
1
1
  # `@cloudflare/worker-utils`
2
2
 
3
- This package contains common utilities used across the dash, Wrangler, and other tooling
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.
@@ -1,4 +1,4 @@
1
- import { T as TailConsumer, am as WorkerMetadata, R as RawConfig } from './config-DAxLpjUL.mjs';
1
+ import { T as TailConsumer, au as WorkerMetadata, R as RawConfig } from './config-_M2XwEUI.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-4233U5MA.mjs';
2
- import './chunk-LDFBMPMW.mjs';
1
+ export { constructWranglerConfig } from './chunk-BLWXWFJK.mjs';
2
+ import './chunk-OZQVB3L3.mjs';
3
+ import './chunk-DCOBXSFB.mjs';
@@ -1,4 +1,5 @@
1
- import { __name, PATH_TO_DEPLOY_CONFIG } from './chunk-LDFBMPMW.mjs';
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
 
@@ -2373,6 +2374,9 @@ var APIError = class extends ParseError {
2373
2374
  this.name = this.constructor.name;
2374
2375
  this.#status = status;
2375
2376
  }
2377
+ get status() {
2378
+ return this.#status;
2379
+ }
2376
2380
  isGatewayError() {
2377
2381
  if (this.#status !== void 0) {
2378
2382
  return [524].includes(this.#status);
@@ -1,38 +1,7 @@
1
- import { __name, ENVIRONMENT_TAG_PREFIX, SERVICE_TAG_PREFIX } from './chunk-LDFBMPMW.mjs';
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 ?? formatCompatibilityDate(/* @__PURE__ */ new 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, formatCompatibilityDate, getLocalWorkerdCompatibilityDate, isCompatDate, mapWorkerMetadataBindings };
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
- // src/constants.ts
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 };