@cloudflare/config 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as PipelineBinding, A as Triggers, B as Bindings, C as WorkerEntrypointExportOptions, Ct as WorkflowBinding, D as FetchTrigger, E as EmailTrigger, F as AiSearchNamespaceBinding, G as FlagshipBinding, H as D1Binding, I as AnalyticsEngineDatasetBinding, J as JsonBinding, K as HyperdriveBinding, L as ArtifactsBinding, M as AgentMemoryBinding, N as AiBinding, O as QueueConsumerTrigger, P as AiSearchBinding, Q as MtlsCertificateBinding, R as AssetsBinding, S as WorkerEntrypointExport, St as WorkerLoaderBinding, T as ConnectTrigger, U as DispatchNamespaceBinding, V as BrowserBinding, W as DurableObjectBinding, X as LogfwdrBinding, Y as KvBinding, Z as MediaBinding, _ as DurableObjectDeletedExport, _t as VersionMetadataBinding, a as InferEnv, at as SendEmailBinding, b as DurableObjectTransferredExport, bt as WebSearchBinding, c as TypedWorkerDefinition, ct as TypedAiBinding, d as defineWorker, dt as TypedPipelineBinding, et as QueueBinding, f as SettingsConfig, ft as TypedQueueBinding, g as DurableObjectCreatedExport, gt as VectorizeBinding, h as resolveExportDefinition, ht as UnsafeBinding, i as InferDurableNamespaces, it as SecretsStoreSecretBinding, j as triggers, k as ScheduledTrigger, l as WorkerConfigExport, lt as TypedDurableObjectBinding, m as ConfigContext, mt as TypedWorkflowBinding, n as SettingsDefinition, nt as RateLimitBinding, o as InferMainModule, ot as StreamBinding, p as WorkerConfig, pt as TypedWorkerBinding, q as ImagesBinding, r as defineSettings, rt as SecretBinding, s as UnwrapConfig, st as TextBinding, t as SettingsConfigInput, tt as R2Binding, u as WorkerConfigInput, ut as TypedKvBinding, v as DurableObjectExpectingTransferExport, vt as VpcNetworkBinding, w as exports, wt as bindings, x as Exports, xt as WorkerBinding, y as DurableObjectRenamedExport, yt as VpcServiceBinding, z as BindingDevOptions } from "./public-DZgNmLyp.mjs";
1
+ import { $ as WorkerConfig, A as SecretsStoreSecretBinding, B as VersionMetadataBinding, C as MediaBinding, D as R2Binding, E as QueueBinding, F as TypedKvBinding, G as WorkerLoaderBinding, H as VpcServiceBinding, I as TypedPipelineBinding, J as bindings, K as WorkerReference, L as TypedQueueBinding, M as StreamBinding, N as TextBinding, O as RateLimitBinding, P as TypedAiBinding, Q as SettingsConfig, R as UnsafeBinding, S as LogfwdrBinding, T as PipelineBinding, U as WebSearchBinding, V as VpcNetworkBinding, W as WorkerBinding, X as WorkerConfigInput, Y as WorkerConfigExport, Z as defineWorker, _ as FlagshipBinding, _t as InferDurableNamespaces, a as AiBinding, at as Triggers, b as JsonBinding, bt as UnwrapConfig, c as AnalyticsEngineDatasetBinding, ct as DurableObjectDeletedExport, d as BindingDevOptions, dt as DurableObjectTransferredExport, et as ConnectTrigger, f as Bindings, ft as Exports, g as DurableObjectBinding, gt as ConfigContext, h as DispatchNamespaceBinding, ht as exports, i as AgentMemoryBinding, it as ScheduledTrigger, j as SendEmailBinding, k as SecretBinding, l as ArtifactsBinding, lt as DurableObjectExpectingTransferExport, m as D1Binding, mt as WorkerEntrypointExportOptions, n as SettingsConfigInput, nt as FetchTrigger, o as AiSearchBinding, ot as triggers, p as BrowserBinding, pt as WorkerEntrypointExport, q as WorkflowBinding, r as defineSettings, rt as QueueConsumerTrigger, s as AiSearchNamespaceBinding, st as DurableObjectCreatedExport, t as SettingsConfigExport, tt as EmailTrigger, u as AssetsBinding, ut as DurableObjectRenamedExport, v as HyperdriveBinding, vt as InferEnv, w as MtlsCertificateBinding, x as KvBinding, y as ImagesBinding, yt as InferMainModule, z as VectorizeBinding } from "./public-E85Be_2R.mjs";
2
2
  import * as z from "zod";
3
3
  import { RawConfig } from "@cloudflare/workers-utils";
4
4
 
@@ -588,177 +588,6 @@ declare const OutputSettingsSchema: z.ZodObject<{
588
588
  mode: z.ZodOptional<z.ZodString>;
589
589
  }, z.core.$strict>;
590
590
  type ParsedOutputSettingsConfig = z.output<typeof OutputSettingsSchema>;
591
- /**
592
- * Schema for the resolved config exports, keyed by export
593
- * name. Each value is discriminated on its `type` field. Reserves the
594
- * `settings` export name exclusively for settings configs: a `settings`
595
- * config must live on the `settings` export, and the `settings` export
596
- * may only hold a `settings` config.
597
- */
598
- declare const ConfigExportsSchema: z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodObject<{
599
- settings: z.ZodOptional<z.ZodObject<{
600
- type: z.ZodLiteral<"settings">;
601
- accountId: z.ZodOptional<z.ZodString>;
602
- complianceRegion: z.ZodOptional<z.ZodEnum<{
603
- public: "public";
604
- "fedramp-high": "fedramp-high";
605
- }>>;
606
- }, z.core.$strict>>;
607
- }, z.core.$catchall<z.ZodObject<{
608
- type: z.ZodLiteral<"worker">;
609
- name: z.ZodString;
610
- compatibilityDate: z.ZodString;
611
- compatibilityFlags: z.ZodOptional<z.ZodArray<z.ZodString>>;
612
- assets: z.ZodOptional<z.ZodObject<{
613
- htmlHandling: z.ZodOptional<z.ZodEnum<{
614
- "auto-trailing-slash": "auto-trailing-slash";
615
- "drop-trailing-slash": "drop-trailing-slash";
616
- "force-trailing-slash": "force-trailing-slash";
617
- none: "none";
618
- }>>;
619
- notFoundHandling: z.ZodOptional<z.ZodEnum<{
620
- none: "none";
621
- "single-page-application": "single-page-application";
622
- "404-page": "404-page";
623
- }>>;
624
- runWorkerFirst: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodBoolean]>>;
625
- }, z.core.$strict>>;
626
- domains: z.ZodOptional<z.ZodArray<z.ZodString>>;
627
- triggers: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
628
- type: z.ZodLiteral<"email">;
629
- addresses: z.ZodArray<z.ZodString>;
630
- }, z.core.$strict>, z.ZodObject<{
631
- type: z.ZodLiteral<"fetch">;
632
- pattern: z.ZodString;
633
- zone: z.ZodOptional<z.ZodString>;
634
- }, z.core.$strict>, z.ZodObject<{
635
- type: z.ZodLiteral<"queue">;
636
- name: z.ZodString;
637
- deadLetterQueue: z.ZodOptional<z.ZodString>;
638
- maxBatchSize: z.ZodOptional<z.ZodNumber>;
639
- maxBatchTimeout: z.ZodOptional<z.ZodNumber>;
640
- maxConcurrency: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
641
- maxRetries: z.ZodOptional<z.ZodNumber>;
642
- retryDelay: z.ZodOptional<z.ZodNumber>;
643
- visibilityTimeoutMs: z.ZodOptional<z.ZodNumber>;
644
- }, z.core.$strict>, z.ZodObject<{
645
- type: z.ZodLiteral<"scheduled">;
646
- schedule: z.ZodString;
647
- }, z.core.$strict>, z.ZodObject<{
648
- type: z.ZodLiteral<"connect">;
649
- protocol: z.ZodEnum<{
650
- tcp: "tcp";
651
- }>;
652
- port: z.ZodNumber;
653
- address: z.ZodOptional<z.ZodString>;
654
- }, z.core.$strict>], "type">>>;
655
- tailConsumers: z.ZodOptional<z.ZodArray<z.ZodObject<{
656
- worker: z.ZodString;
657
- streaming: z.ZodOptional<z.ZodBoolean>;
658
- }, z.core.$strict>>>;
659
- cache: z.ZodOptional<z.ZodObject<{
660
- enabled: z.ZodBoolean;
661
- crossVersionCache: z.ZodOptional<z.ZodBoolean>;
662
- }, z.core.$strict>>;
663
- placement: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
664
- mode: z.ZodEnum<{
665
- off: "off";
666
- smart: "smart";
667
- }>;
668
- hint: z.ZodOptional<z.ZodString>;
669
- }, z.core.$strict>, z.ZodObject<{
670
- mode: z.ZodOptional<z.ZodLiteral<"targeted">>;
671
- region: z.ZodString;
672
- }, z.core.$strict>, z.ZodObject<{
673
- mode: z.ZodOptional<z.ZodLiteral<"targeted">>;
674
- host: z.ZodString;
675
- }, z.core.$strict>, z.ZodObject<{
676
- mode: z.ZodOptional<z.ZodLiteral<"targeted">>;
677
- hostname: z.ZodString;
678
- }, z.core.$strict>]>>;
679
- limits: z.ZodOptional<z.ZodObject<{
680
- cpuMs: z.ZodOptional<z.ZodNumber>;
681
- subrequests: z.ZodOptional<z.ZodNumber>;
682
- }, z.core.$strict>>;
683
- logpush: z.ZodOptional<z.ZodBoolean>;
684
- observability: z.ZodOptional<z.ZodObject<{
685
- enabled: z.ZodOptional<z.ZodBoolean>;
686
- headSamplingRate: z.ZodOptional<z.ZodNumber>;
687
- redactQueryString: z.ZodOptional<z.ZodBoolean>;
688
- logs: z.ZodOptional<z.ZodObject<{
689
- enabled: z.ZodOptional<z.ZodBoolean>;
690
- headSamplingRate: z.ZodOptional<z.ZodNumber>;
691
- invocationLogs: z.ZodOptional<z.ZodBoolean>;
692
- persist: z.ZodOptional<z.ZodBoolean>;
693
- destinations: z.ZodOptional<z.ZodArray<z.ZodString>>;
694
- }, z.core.$strict>>;
695
- traces: z.ZodOptional<z.ZodObject<{
696
- enabled: z.ZodOptional<z.ZodBoolean>;
697
- headSamplingRate: z.ZodOptional<z.ZodNumber>;
698
- persist: z.ZodOptional<z.ZodBoolean>;
699
- destinations: z.ZodOptional<z.ZodArray<z.ZodString>>;
700
- }, z.core.$strict>>;
701
- }, z.core.$strict>>;
702
- workersDev: z.ZodOptional<z.ZodBoolean>;
703
- previewUrls: z.ZodOptional<z.ZodBoolean>;
704
- firstPartyWorker: z.ZodOptional<z.ZodBoolean>;
705
- unsafe: z.ZodOptional<z.ZodObject<{
706
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
707
- capnp: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
708
- basePath: z.ZodString;
709
- sourceSchemas: z.ZodArray<z.ZodString>;
710
- compiledSchema: z.ZodOptional<z.ZodNever>;
711
- }, z.core.$strict>, z.ZodObject<{
712
- basePath: z.ZodOptional<z.ZodNever>;
713
- sourceSchemas: z.ZodOptional<z.ZodNever>;
714
- compiledSchema: z.ZodString;
715
- }, z.core.$strict>]>>;
716
- }, z.core.$strict>>;
717
- env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<BindingOutput, BindingInput, z.core.$ZodTypeInternals<BindingOutput, BindingInput>>>>;
718
- exports: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
719
- type: z.ZodLiteral<"durable-object">;
720
- state: z.ZodOptional<z.ZodLiteral<"created">>;
721
- container: z.ZodOptional<z.ZodString>;
722
- storage: z.ZodLiteral<"sqlite">;
723
- }, z.core.$strict>, z.ZodObject<{
724
- type: z.ZodLiteral<"durable-object">;
725
- state: z.ZodOptional<z.ZodLiteral<"created">>;
726
- storage: z.ZodLiteral<"legacy-kv">;
727
- }, z.core.$strict>, z.ZodObject<{
728
- type: z.ZodLiteral<"durable-object">;
729
- state: z.ZodLiteral<"deleted">;
730
- }, z.core.$strict>, z.ZodObject<{
731
- type: z.ZodLiteral<"durable-object">;
732
- state: z.ZodLiteral<"renamed">;
733
- renamedTo: z.ZodString;
734
- }, z.core.$strict>, z.ZodObject<{
735
- type: z.ZodLiteral<"durable-object">;
736
- state: z.ZodLiteral<"transferred">;
737
- transferredTo: z.ZodString;
738
- }, z.core.$strict>, z.ZodObject<{
739
- type: z.ZodLiteral<"durable-object">;
740
- state: z.ZodLiteral<"expecting-transfer">;
741
- transferFrom: z.ZodString;
742
- container: z.ZodOptional<z.ZodString>;
743
- storage: z.ZodLiteral<"sqlite">;
744
- }, z.core.$strict>, z.ZodObject<{
745
- type: z.ZodLiteral<"durable-object">;
746
- state: z.ZodLiteral<"expecting-transfer">;
747
- transferFrom: z.ZodString;
748
- storage: z.ZodLiteral<"legacy-kv">;
749
- }, z.core.$strict>, z.ZodObject<{
750
- type: z.ZodLiteral<"worker">;
751
- cache: z.ZodOptional<z.ZodObject<{
752
- enabled: z.ZodBoolean;
753
- }, z.core.$strict>>;
754
- }, z.core.$strict>]>>>;
755
- entrypoint: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
756
- default: z.ZodString;
757
- }, z.core.$strict>]>, z.ZodTransform<string, string | {
758
- default: string;
759
- }>>>;
760
- }, z.core.$strict>>>>;
761
- type ParsedConfigExports = z.output<typeof ConfigExportsSchema>;
762
591
  declare const ModuleTypeSchema: z.ZodEnum<{
763
592
  json: "json";
764
593
  text: "text";
@@ -1058,20 +887,32 @@ interface LoadConfigResult {
1058
887
  declare function registerConfigHooks(): () => void;
1059
888
  //#endregion
1060
889
  //#region src/config-loader.d.ts
890
+ type ParsedConfigExports = {
891
+ settings?: ParsedInputSettingsConfig;
892
+ } & Record<string, ParsedInputWorkerConfig>;
893
+ type ConfigParseResult = z.ZodSafeParseSuccess<ParsedConfigExports> | z.ZodSafeParseError<unknown>;
1061
894
  interface LoadAndValidateConfigResult {
1062
895
  /**
1063
- * Zod result for the validated exports record, keyed by JS export name.
896
+ * Zod result for the parsed exports record, keyed by JS export name.
1064
897
  * Consumers format `result.error` themselves.
1065
898
  */
1066
- result: z.ZodSafeParseResult<ParsedConfigExports>;
899
+ result: ConfigParseResult;
1067
900
  /** Transitive deps imported while resolving the config (node_modules excluded). */
1068
901
  dependencies: Set<string>;
1069
902
  }
1070
903
  /**
1071
- * Load a `cloudflare.config.ts`, resolve all exports, and validate against {@link ConfigExportsSchema}.
904
+ * Resolve and validate loaded `cloudflare.config.ts` exports.
905
+ *
906
+ * Config inputs are resolved once by identity. Top-level Worker exports are
907
+ * also parsed once by identity; unexported references are resolved only far
908
+ * enough to replace the reference with the Worker's name.
909
+ */
910
+ declare function resolveAndValidateConfigExports(exports: Record<string, unknown>, ctx: ConfigContext): Promise<ConfigParseResult>;
911
+ /**
912
+ * Load a `cloudflare.config.ts`, resolve all exports, and validate them.
1072
913
  */
1073
914
  declare function loadAndValidateConfig(configPath: string, ctx: ConfigContext, options?: {
1074
915
  include?: string[];
1075
916
  }): Promise<LoadAndValidateConfigResult>;
1076
917
  //#endregion
1077
- export { AgentMemoryBinding, AiBinding, AiSearchBinding, AiSearchNamespaceBinding, AnalyticsEngineDatasetBinding, AnalyticsEngineDatasetBindingSchema, ArtifactsBinding, AssetsBinding, AssetsSchema, BindingDevOptions, BindingSchema, Bindings, BrowserBinding, BrowserBindingSchema, ConfigContext, ConfigExportsSchema, ConnectTrigger, D1Binding, D1BindingSchema, DispatchNamespaceBinding, DurableObjectBinding, DurableObjectCreatedExport, DurableObjectCreatedExportSchema, DurableObjectDeletedExport, DurableObjectDeletedExportSchema, DurableObjectExpectingTransferExport, DurableObjectExpectingTransferExportSchema, DurableObjectRenamedExport, DurableObjectRenamedExportSchema, DurableObjectTransferredExport, DurableObjectTransferredExportSchema, EmailTrigger, ExportSchema, Exports, FetchTrigger, FlagshipBinding, FlagshipBindingSchema, HyperdriveBinding, HyperdriveBindingSchema, ImagesBinding, InferDurableNamespaces, InferEnv, InferMainModule, InputSettingsSchema, InputWorkerSchema, JsonBinding, KVBindingSchema, KnownBindingSchema, KvBinding, type LoadAndValidateConfigResult, type LoadConfigResult, LogfwdrBinding, MediaBinding, type ModuleType, ModuleTypeSchema, MtlsCertificateBinding, OutputSettingsSchema, OutputWorkerSchema, type ParsedConfigExports, type ParsedInputSettingsConfig, type ParsedInputWorkerConfig, type ParsedOutputSettingsConfig, type ParsedOutputWorkerConfig, PipelineBinding, QueueBinding, QueueBindingSchema, QueueConsumerTrigger, R2Binding, R2BindingSchema, RateLimitBinding, ScheduledTrigger, SecretBinding, SecretsStoreSecretBinding, SendEmailBinding, SettingsConfig, SettingsConfigInput, SettingsDefinition, StreamBinding, TailConsumerSchema, TextBinding, Triggers, TypedAiBinding, TypedDurableObjectBinding, TypedKvBinding, TypedPipelineBinding, TypedQueueBinding, TypedWorkerBinding, TypedWorkerDefinition, TypedWorkflowBinding, UnsafeBinding, UnsafeBindingSchema, UnwrapConfig, VectorizeBinding, VersionMetadataBinding, VpcNetworkBinding, VpcServiceBinding, WebSearchBinding, WorkerBinding, WorkerBindingSchema, WorkerConfig, WorkerConfigExport, WorkerConfigInput, WorkerEntrypointExport, WorkerEntrypointExportOptions, WorkerEntrypointExportSchema, WorkerLoaderBinding, WorkflowBinding, bindings, convertToWranglerConfig, defineSettings, defineWorker, exports, generateTypes, loadAndValidateConfig, loadConfig, registerConfigHooks, resolveExportDefinition, triggers, validateSingletonBindings };
918
+ export { AgentMemoryBinding, AiBinding, AiSearchBinding, AiSearchNamespaceBinding, AnalyticsEngineDatasetBinding, AnalyticsEngineDatasetBindingSchema, ArtifactsBinding, AssetsBinding, AssetsSchema, BindingDevOptions, BindingSchema, Bindings, BrowserBinding, BrowserBindingSchema, ConfigContext, type ConfigParseResult, ConnectTrigger, D1Binding, D1BindingSchema, DispatchNamespaceBinding, DurableObjectBinding, DurableObjectCreatedExport, DurableObjectCreatedExportSchema, DurableObjectDeletedExport, DurableObjectDeletedExportSchema, DurableObjectExpectingTransferExport, DurableObjectExpectingTransferExportSchema, DurableObjectRenamedExport, DurableObjectRenamedExportSchema, DurableObjectTransferredExport, DurableObjectTransferredExportSchema, EmailTrigger, ExportSchema, Exports, FetchTrigger, FlagshipBinding, FlagshipBindingSchema, HyperdriveBinding, HyperdriveBindingSchema, ImagesBinding, InferDurableNamespaces, InferEnv, InferMainModule, InputSettingsSchema, InputWorkerSchema, JsonBinding, KVBindingSchema, KnownBindingSchema, KvBinding, type LoadAndValidateConfigResult, type LoadConfigResult, LogfwdrBinding, MediaBinding, type ModuleType, ModuleTypeSchema, MtlsCertificateBinding, OutputSettingsSchema, OutputWorkerSchema, type ParsedConfigExports, type ParsedInputSettingsConfig, type ParsedInputWorkerConfig, type ParsedOutputSettingsConfig, type ParsedOutputWorkerConfig, PipelineBinding, QueueBinding, QueueBindingSchema, QueueConsumerTrigger, R2Binding, R2BindingSchema, RateLimitBinding, ScheduledTrigger, SecretBinding, SecretsStoreSecretBinding, SendEmailBinding, SettingsConfig, SettingsConfigExport, SettingsConfigInput, StreamBinding, TailConsumerSchema, TextBinding, Triggers, TypedAiBinding, TypedKvBinding, TypedPipelineBinding, TypedQueueBinding, UnsafeBinding, UnsafeBindingSchema, UnwrapConfig, VectorizeBinding, VersionMetadataBinding, VpcNetworkBinding, VpcServiceBinding, WebSearchBinding, WorkerBinding, WorkerBindingSchema, WorkerConfig, WorkerConfigExport, WorkerConfigInput, WorkerEntrypointExport, WorkerEntrypointExportOptions, WorkerEntrypointExportSchema, WorkerLoaderBinding, WorkerReference, WorkflowBinding, bindings, convertToWranglerConfig, defineSettings, defineWorker, exports, generateTypes, loadAndValidateConfig, loadConfig, registerConfigHooks, resolveAndValidateConfigExports, triggers, validateSingletonBindings };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as triggers, i as exports$1, n as defineWorker, o as bindings, r as resolveExportDefinition, t as defineSettings } from "./public-BwQqexwo.mjs";
1
+ import { a as bindings, i as triggers, n as defineWorker, r as exports$1, t as defineSettings } from "./public-bN7EDGtD.mjs";
2
2
  import * as nodeModule from "node:module";
3
3
  import * as z from "zod";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -475,15 +475,6 @@ const ConfigExportsTypeSchema = z.record(z.string(), z.unknown()).check((ctx) =>
475
475
  });
476
476
  }
477
477
  });
478
- const ConfigExportsObjectSchema = z.object({ settings: InputSettingsSchema.optional() }).catchall(InputWorkerSchema);
479
- /**
480
- * Schema for the resolved config exports, keyed by export
481
- * name. Each value is discriminated on its `type` field. Reserves the
482
- * `settings` export name exclusively for settings configs: a `settings`
483
- * config must live on the `settings` export, and the `settings` export
484
- * may only hold a `settings` config.
485
- */
486
- const ConfigExportsSchema = ConfigExportsTypeSchema.pipe(ConfigExportsObjectSchema);
487
478
  const ModuleTypeSchema = z.enum([
488
479
  "esm",
489
480
  "cjs",
@@ -1349,18 +1340,103 @@ function cleanupImportAttributes(context) {
1349
1340
 
1350
1341
  //#endregion
1351
1342
  //#region src/config-loader.ts
1343
+ const CROSS_WORKER_BINDING_TYPES = new Set([
1344
+ "durable-object",
1345
+ "worker",
1346
+ "workflow"
1347
+ ]);
1348
+ function isRecord(value) {
1349
+ return typeof value === "object" && value !== null;
1350
+ }
1351
+ function isConfigReference(value) {
1352
+ return typeof value === "function" || isRecord(value);
1353
+ }
1354
+ function createDefinitionResolver(ctx) {
1355
+ const resolvedDefinitions = /* @__PURE__ */ new Map();
1356
+ return (input) => {
1357
+ const cached = resolvedDefinitions.get(input);
1358
+ if (cached) return cached;
1359
+ const resolved = (async () => {
1360
+ return await (typeof input === "function" ? input(ctx) : input);
1361
+ })();
1362
+ resolvedDefinitions.set(input, resolved);
1363
+ return resolved;
1364
+ };
1365
+ }
1366
+ async function normalizeWorkerReferences(resolved, resolveDefinition) {
1367
+ if (!isRecord(resolved) || !isRecord(resolved.env)) return resolved;
1368
+ const env = { ...resolved.env };
1369
+ for (const [bindingName, binding] of Object.entries(env)) {
1370
+ if (!isRecord(binding) || typeof binding.type !== "string" || !CROSS_WORKER_BINDING_TYPES.has(binding.type) || !isConfigReference(binding.worker)) continue;
1371
+ const target = await resolveDefinition(binding.worker);
1372
+ env[bindingName] = {
1373
+ ...binding,
1374
+ worker: isRecord(target) ? target.name : void 0
1375
+ };
1376
+ }
1377
+ return {
1378
+ ...resolved,
1379
+ env
1380
+ };
1381
+ }
1382
+ function prefixIssues(issues, prefix) {
1383
+ return issues.map((issue) => ({
1384
+ ...issue,
1385
+ path: [prefix, ...issue.path]
1386
+ }));
1387
+ }
1388
+ /**
1389
+ * Resolve and validate loaded `cloudflare.config.ts` exports.
1390
+ *
1391
+ * Config inputs are resolved once by identity. Top-level Worker exports are
1392
+ * also parsed once by identity; unexported references are resolved only far
1393
+ * enough to replace the reference with the Worker's name.
1394
+ */
1395
+ async function resolveAndValidateConfigExports(exports$2, ctx) {
1396
+ const resolveDefinition = createDefinitionResolver(ctx);
1397
+ const parsedWorkers = /* @__PURE__ */ new Map();
1398
+ const resolvedExports = {};
1399
+ for (const [name, input] of Object.entries(exports$2)) resolvedExports[name] = await resolveDefinition(input);
1400
+ const typeResult = ConfigExportsTypeSchema.safeParse(resolvedExports);
1401
+ if (!typeResult.success) return typeResult;
1402
+ const issues = [];
1403
+ const data = {};
1404
+ const resolvedSettings = resolvedExports.settings;
1405
+ const settingsResult = resolvedSettings ? InputSettingsSchema.safeParse(resolvedSettings) : void 0;
1406
+ if (settingsResult) if (settingsResult.success) data.settings = settingsResult.data;
1407
+ else issues.push(...prefixIssues(settingsResult.error.issues, "settings"));
1408
+ for (const [name, input] of Object.entries(exports$2)) {
1409
+ const resolved = resolvedExports[name];
1410
+ if (!isRecord(resolved)) continue;
1411
+ if (resolved.type === "worker") {
1412
+ let result = parsedWorkers.get(input);
1413
+ if (!result) {
1414
+ result = InputWorkerSchema.safeParse(await normalizeWorkerReferences(resolved, resolveDefinition));
1415
+ parsedWorkers.set(input, result);
1416
+ if (!result.success) issues.push(...prefixIssues(result.error.issues, name));
1417
+ }
1418
+ if (result.success) data[name] = result.data;
1419
+ continue;
1420
+ }
1421
+ }
1422
+ return issues.length > 0 ? {
1423
+ success: false,
1424
+ error: new z.ZodError(issues)
1425
+ } : {
1426
+ success: true,
1427
+ data
1428
+ };
1429
+ }
1352
1430
  /**
1353
- * Load a `cloudflare.config.ts`, resolve all exports, and validate against {@link ConfigExportsSchema}.
1431
+ * Load a `cloudflare.config.ts`, resolve all exports, and validate them.
1354
1432
  */
1355
1433
  async function loadAndValidateConfig(configPath, ctx, options) {
1356
1434
  const { exports: exports$2, dependencies } = await loadConfig(configPath, options);
1357
- const resolved = {};
1358
- for (const [name, value] of Object.entries(exports$2)) resolved[name] = await resolveExportDefinition(value, ctx);
1359
1435
  return {
1360
- result: ConfigExportsSchema.safeParse(resolved),
1436
+ result: await resolveAndValidateConfigExports(exports$2, ctx),
1361
1437
  dependencies
1362
1438
  };
1363
1439
  }
1364
1440
 
1365
1441
  //#endregion
1366
- export { AnalyticsEngineDatasetBindingSchema, AssetsSchema, BindingSchema, BrowserBindingSchema, ConfigExportsSchema, D1BindingSchema, DurableObjectCreatedExportSchema, DurableObjectDeletedExportSchema, DurableObjectExpectingTransferExportSchema, DurableObjectRenamedExportSchema, DurableObjectTransferredExportSchema, ExportSchema, FlagshipBindingSchema, HyperdriveBindingSchema, InputSettingsSchema, InputWorkerSchema, KVBindingSchema, KnownBindingSchema, ModuleTypeSchema, OutputSettingsSchema, OutputWorkerSchema, QueueBindingSchema, R2BindingSchema, TailConsumerSchema, UnsafeBindingSchema, WorkerBindingSchema, WorkerEntrypointExportSchema, bindings, convertToWranglerConfig, defineSettings, defineWorker, exports$1 as exports, generateTypes, loadAndValidateConfig, loadConfig, registerConfigHooks, resolveExportDefinition, triggers, validateSingletonBindings };
1442
+ export { AnalyticsEngineDatasetBindingSchema, AssetsSchema, BindingSchema, BrowserBindingSchema, D1BindingSchema, DurableObjectCreatedExportSchema, DurableObjectDeletedExportSchema, DurableObjectExpectingTransferExportSchema, DurableObjectRenamedExportSchema, DurableObjectTransferredExportSchema, ExportSchema, FlagshipBindingSchema, HyperdriveBindingSchema, InputSettingsSchema, InputWorkerSchema, KVBindingSchema, KnownBindingSchema, ModuleTypeSchema, OutputSettingsSchema, OutputWorkerSchema, QueueBindingSchema, R2BindingSchema, TailConsumerSchema, UnsafeBindingSchema, WorkerBindingSchema, WorkerEntrypointExportSchema, bindings, convertToWranglerConfig, defineSettings, defineWorker, exports$1 as exports, generateTypes, loadAndValidateConfig, loadConfig, registerConfigHooks, resolveAndValidateConfigExports, triggers, validateSingletonBindings };