@cloudflare/config 0.15.0 → 0.17.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 +307 -92
- package/dist/index.mjs +141 -227
- package/dist/{public-Dyr8BJqf.mjs → public-BMg6-Hxh.mjs} +65 -47
- package/dist/{public-CFsFemEv.d.mts → public-fVh2BrM5.d.mts} +280 -307
- package/dist/public.d.mts +2 -2
- package/dist/public.mjs +2 -2
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as triggers, i as exports$1, n as
|
|
1
|
+
import { a as triggers, i as exports$1, n as defineContainer, o as bindings, r as defineWorker, t as defineConfig } from "./public-BMg6-Hxh.mjs";
|
|
2
2
|
import * as nodeModule from "node:module";
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -324,7 +324,6 @@ const ContainerObservabilityBaseSchema = z.strictObject({
|
|
|
324
324
|
});
|
|
325
325
|
const StandardContainerObservabilitySchema = z.union([ContainerObservabilityBaseSchema.extend({ targetInstancePercentage: z.number().min(0).max(100).optional() }), ContainerObservabilityBaseSchema.extend({ targetInstanceCount: z.number().int().nonnegative().optional() })]);
|
|
326
326
|
const BaseContainerSchema = z.strictObject({
|
|
327
|
-
type: z.literal("container"),
|
|
328
327
|
name: z.string().min(1),
|
|
329
328
|
unsafe: z.record(z.string(), z.unknown()).optional()
|
|
330
329
|
});
|
|
@@ -381,14 +380,13 @@ const DurableObjectContainerBaseSchema = BaseContainerSchema.extend({
|
|
|
381
380
|
observability: ContainerObservabilityBaseSchema.optional()
|
|
382
381
|
});
|
|
383
382
|
/**
|
|
384
|
-
* Input Container schema —
|
|
385
|
-
* Container
|
|
383
|
+
* Input Container schema — parses user-authored `cloudflare.config.ts`
|
|
384
|
+
* Container objects. Dockerfiles are built by the consuming build tool.
|
|
386
385
|
*/
|
|
387
386
|
const InputContainerSchema = z.union([StandardContainerBaseSchema.extend({ image: InputContainerImageSchema }).superRefine(validateContainerRelationships), DurableObjectContainerBaseSchema.extend({ images: z.record(z.string(), InputContainerImageSchema).optional() })]);
|
|
388
387
|
/**
|
|
389
|
-
* Output Container schema —
|
|
390
|
-
* Specification, after any Dockerfile has been built into a local
|
|
391
|
-
* image reference.
|
|
388
|
+
* Output Container schema — parses `container.config.json` files in the Build
|
|
389
|
+
* Output Specification, after any Dockerfile has been built into a local image reference.
|
|
392
390
|
*/
|
|
393
391
|
const OutputContainerSchema = z.union([StandardContainerBaseSchema.extend({ image: OutputContainerImageSchema }).superRefine(validateContainerRelationships), DurableObjectContainerBaseSchema.extend({ images: z.record(z.string(), OutputContainerImageSchema).optional() })]);
|
|
394
392
|
const DurableObjectCreatedExportSchema = z.strictObject({
|
|
@@ -530,7 +528,6 @@ const UnsafeSchema = z.strictObject({
|
|
|
530
528
|
* (user-authored) and output (on-disk) Worker configs.
|
|
531
529
|
*/
|
|
532
530
|
const BaseWorkerSchema = z.strictObject({
|
|
533
|
-
type: z.literal("worker"),
|
|
534
531
|
name: z.string(),
|
|
535
532
|
compatibilityDate: z.string(),
|
|
536
533
|
compatibilityFlags: z.array(z.string()).optional(),
|
|
@@ -551,75 +548,37 @@ const BaseWorkerSchema = z.strictObject({
|
|
|
551
548
|
exports: z.record(z.string(), ExportSchema).optional()
|
|
552
549
|
});
|
|
553
550
|
/**
|
|
554
|
-
* Input Worker schema —
|
|
555
|
-
* files
|
|
556
|
-
* base schema.
|
|
551
|
+
* Input Worker schema — parses Worker definitions from user-authored
|
|
552
|
+
* `cloudflare.config.ts` files. Adds an optional string `entrypoint` field to
|
|
553
|
+
* the base schema.
|
|
557
554
|
*/
|
|
558
|
-
const InputWorkerSchema = BaseWorkerSchema.extend({ entrypoint: z.
|
|
555
|
+
const InputWorkerSchema = BaseWorkerSchema.extend({ entrypoint: z.string().optional() });
|
|
559
556
|
/**
|
|
560
|
-
* Input settings schema —
|
|
561
|
-
* `cloudflare.config.ts`.
|
|
557
|
+
* Input settings schema — parses the account settings at the top level of
|
|
558
|
+
* `cloudflare.config.ts`.
|
|
562
559
|
*/
|
|
563
|
-
const InputSettingsSchema = z.
|
|
564
|
-
type: z.literal("settings"),
|
|
560
|
+
const InputSettingsSchema = z.object({
|
|
565
561
|
accountId: z.string().optional(),
|
|
566
562
|
complianceRegion: z.enum(["public", "fedramp-high"]).optional()
|
|
567
563
|
});
|
|
568
|
-
/**
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
564
|
+
/** The resolved, user-authored project configuration. */
|
|
565
|
+
const InputConfigSchema = z.strictObject({
|
|
566
|
+
...InputSettingsSchema.shape,
|
|
567
|
+
worker: InputWorkerSchema.optional(),
|
|
568
|
+
containers: z.array(InputContainerSchema).default([])
|
|
569
|
+
});
|
|
570
|
+
const BuildContextSchema = z.strictObject({
|
|
571
|
+
isPreview: z.boolean(),
|
|
574
572
|
mode: z.string().optional()
|
|
575
573
|
});
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
return `The \`${exportName}\` export is not a supported export type. Move constants, helper functions, and other unsupported exports to a separate module.`;
|
|
585
|
-
}
|
|
586
|
-
const ConfigExportsTypeSchema = z.record(z.string(), z.unknown()).check((ctx) => {
|
|
587
|
-
for (const [key, value] of Object.entries(ctx.value)) {
|
|
588
|
-
const isObject = typeof value === "object" && value !== null;
|
|
589
|
-
const type = isObject && "type" in value ? value.type : void 0;
|
|
590
|
-
if (typeof type !== "string" || !SUPPORTED_EXPORT_TYPES.has(type)) {
|
|
591
|
-
ctx.issues.push({
|
|
592
|
-
code: "custom",
|
|
593
|
-
input: value,
|
|
594
|
-
path: isObject ? [key, "type"] : [key],
|
|
595
|
-
message: invalidConfigExportMessage(key)
|
|
596
|
-
});
|
|
597
|
-
continue;
|
|
598
|
-
}
|
|
599
|
-
if (key === DEFAULT_EXPORT_NAME && type !== "worker") {
|
|
600
|
-
ctx.issues.push({
|
|
601
|
-
code: "custom",
|
|
602
|
-
input: value,
|
|
603
|
-
path: [key],
|
|
604
|
-
message: `The \`${DEFAULT_EXPORT_NAME}\` export is reserved for a \`worker\` config; found a \`${type}\` config.`
|
|
605
|
-
});
|
|
606
|
-
continue;
|
|
607
|
-
}
|
|
608
|
-
const isSettingsName = key === SETTINGS_EXPORT_NAME;
|
|
609
|
-
const isSettingsType = type === "settings";
|
|
610
|
-
if (isSettingsType && !isSettingsName) ctx.issues.push({
|
|
611
|
-
code: "custom",
|
|
612
|
-
input: value,
|
|
613
|
-
path: [key],
|
|
614
|
-
message: `A \`settings\` config is only allowed on the \`${SETTINGS_EXPORT_NAME}\` export; found one on the \`${key}\` export.`
|
|
615
|
-
});
|
|
616
|
-
else if (isSettingsName && !isSettingsType) ctx.issues.push({
|
|
617
|
-
code: "custom",
|
|
618
|
-
input: value,
|
|
619
|
-
path: [key],
|
|
620
|
-
message: `The \`${SETTINGS_EXPORT_NAME}\` export is reserved for a \`settings\` config; found a \`${type}\` config.`
|
|
621
|
-
});
|
|
622
|
-
}
|
|
574
|
+
/**
|
|
575
|
+
* The shape of the root `config.json` in the Build Output Specification.
|
|
576
|
+
* Account settings remain at the top level while build context is grouped
|
|
577
|
+
* under `buildContext`.
|
|
578
|
+
*/
|
|
579
|
+
const OutputRootConfigSchema = z.strictObject({
|
|
580
|
+
...InputSettingsSchema.shape,
|
|
581
|
+
buildContext: BuildContextSchema
|
|
623
582
|
});
|
|
624
583
|
const ModuleTypeSchema = z.enum([
|
|
625
584
|
"esm",
|
|
@@ -651,9 +610,9 @@ const ManifestSchema = z.strictObject({
|
|
|
651
610
|
});
|
|
652
611
|
});
|
|
653
612
|
/**
|
|
654
|
-
* Output Worker schema — the shape of the Worker's `config.json` in the
|
|
655
|
-
* Build Output Specification. Adds an optional `manifest` field to the
|
|
656
|
-
*
|
|
613
|
+
* Output Worker schema — the shape of the Worker's `worker.config.json` in the
|
|
614
|
+
* Build Output Specification. Adds an optional `manifest` field to the base
|
|
615
|
+
* schema.
|
|
657
616
|
*/
|
|
658
617
|
const OutputWorkerSchema = BaseWorkerSchema.extend({ manifest: ManifestSchema.optional() });
|
|
659
618
|
|
|
@@ -719,7 +678,8 @@ function generateTypes({ configPath, packageName = "@cloudflare/config" }) {
|
|
|
719
678
|
return import_dist.dedent`
|
|
720
679
|
/* eslint-disable */
|
|
721
680
|
// Generated by @cloudflare/config
|
|
722
|
-
type
|
|
681
|
+
type __Config = import("${packageName}").UnwrapConfig<typeof import("${configPath.replace(/\.(ts|js|mts|mjs)$/, "")}").default>;
|
|
682
|
+
type __WorkerConfig = import("${packageName}").UnwrapConfig<__Config["worker"]>;
|
|
723
683
|
type __Env = import("${packageName}").InferEnv<__WorkerConfig>;
|
|
724
684
|
|
|
725
685
|
declare namespace Cloudflare {
|
|
@@ -810,27 +770,25 @@ const ROLLOUT_KIND_MAP = {
|
|
|
810
770
|
/**
|
|
811
771
|
* Convert a parsed `@cloudflare/config` config into a Wrangler `RawConfig`.
|
|
812
772
|
*
|
|
813
|
-
* The caller is responsible for
|
|
814
|
-
*
|
|
815
|
-
* passing them in.
|
|
773
|
+
* The caller is responsible for resolving any function/promise wrappers and
|
|
774
|
+
* parsing the configuration before passing it in.
|
|
816
775
|
*
|
|
817
|
-
* @param
|
|
818
|
-
* @param settingsConfig The optional parsed settings config, whose fields
|
|
819
|
-
* are merged onto the result.
|
|
820
|
-
* @param containerExports The parsed Container exports to include in the
|
|
821
|
-
* result.
|
|
776
|
+
* @param config The parsed configuration.
|
|
822
777
|
* @returns The corresponding Wrangler `RawConfig`.
|
|
823
778
|
*/
|
|
824
|
-
function convertToWranglerConfig(
|
|
779
|
+
function convertToWranglerConfig(config) {
|
|
825
780
|
const result = {};
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
781
|
+
const { worker, containers } = config;
|
|
782
|
+
if (worker !== void 0) {
|
|
783
|
+
convertTopLevel(worker, result);
|
|
784
|
+
convertBindingsAndAssets(worker, result);
|
|
785
|
+
convertExports(worker, result);
|
|
786
|
+
convertDomains(worker, result);
|
|
787
|
+
convertTriggers(worker, result);
|
|
788
|
+
convertTailConsumers(worker, result);
|
|
789
|
+
}
|
|
790
|
+
convertSettings(config, result);
|
|
791
|
+
if (containers.length > 0) result.containers = containers.map((container) => convertContainer(container));
|
|
834
792
|
return result;
|
|
835
793
|
}
|
|
836
794
|
function convertContainer(container) {
|
|
@@ -1431,31 +1389,22 @@ const CF_NO_CACHE_QUERY_KEY = "cf-no-cache";
|
|
|
1431
1389
|
const RE_NODE_MODULES = /[/\\]node_modules[/\\]/;
|
|
1432
1390
|
const depsStore = new AsyncLocalStorage();
|
|
1433
1391
|
/**
|
|
1434
|
-
* Dynamically import a
|
|
1392
|
+
* Dynamically import a Cloudflare config file from disk.
|
|
1435
1393
|
*
|
|
1436
|
-
* Returns
|
|
1437
|
-
*
|
|
1438
|
-
* are responsible for unwrapping function/promise/definition wrappers around
|
|
1439
|
-
* each export and validating them.
|
|
1394
|
+
* Returns the module's default export plus the set of file paths imported
|
|
1395
|
+
* during resolution.
|
|
1440
1396
|
*
|
|
1441
1397
|
* @param configPath Filesystem path to the config file. Relative paths are
|
|
1442
1398
|
* resolved against `process.cwd()`.
|
|
1443
|
-
* @param options.include When provided, only exports whose names are listed
|
|
1444
|
-
* survive into the returned `exports` map. Filtering happens before any
|
|
1445
|
-
* resolution or validation.
|
|
1446
1399
|
*/
|
|
1447
|
-
async function loadConfig(configPath
|
|
1400
|
+
async function loadConfig(configPath) {
|
|
1448
1401
|
registerConfigHooks();
|
|
1449
1402
|
const url = pathToFileURL(configPath).href;
|
|
1450
1403
|
const dependencies = /* @__PURE__ */ new Set();
|
|
1451
1404
|
const mod = await depsStore.run(dependencies, () => import(url, { with: { [CF_ATTR]: CF_NO_CACHE_VALUE } }));
|
|
1452
|
-
|
|
1453
|
-
for (const [name, value] of Object.entries(mod)) {
|
|
1454
|
-
if (options?.include && !options.include.includes(name)) continue;
|
|
1455
|
-
exports$2[name] = value;
|
|
1456
|
-
}
|
|
1405
|
+
if (!("default" in mod)) throw new Error(`The config file "${configPath}" does not have a default export. Export your configuration with \`export default defineConfig({ ... })\`.`);
|
|
1457
1406
|
return {
|
|
1458
|
-
|
|
1407
|
+
config: mod.default,
|
|
1459
1408
|
dependencies
|
|
1460
1409
|
};
|
|
1461
1410
|
}
|
|
@@ -1547,23 +1496,11 @@ const CROSS_WORKER_BINDING_TYPES = new Set([
|
|
|
1547
1496
|
"worker",
|
|
1548
1497
|
"workflow"
|
|
1549
1498
|
]);
|
|
1550
|
-
/**
|
|
1551
|
-
* Selects the Container exports from a validated project configuration.
|
|
1552
|
-
*
|
|
1553
|
-
* @param config - Validated exports keyed by their JavaScript export names.
|
|
1554
|
-
* @returns Container configurations keyed by those same export names.
|
|
1555
|
-
*/
|
|
1556
|
-
function getContainerConfigExports(config) {
|
|
1557
|
-
return Object.fromEntries(Object.entries(config).filter((entry) => entry[1]?.type === "container"));
|
|
1558
|
-
}
|
|
1559
1499
|
function isRecord(value) {
|
|
1560
1500
|
return typeof value === "object" && value !== null;
|
|
1561
1501
|
}
|
|
1562
|
-
function
|
|
1563
|
-
return typeof
|
|
1564
|
-
}
|
|
1565
|
-
function normalizeConfigReference(reference, resolved, expectedType) {
|
|
1566
|
-
return isRecord(resolved) && resolved.type === expectedType && typeof resolved.name === "string" ? resolved.name : reference;
|
|
1502
|
+
function normalizeConfigReference(reference, resolved) {
|
|
1503
|
+
return isRecord(resolved) && typeof resolved.name === "string" ? resolved.name : reference;
|
|
1567
1504
|
}
|
|
1568
1505
|
function createDefinitionResolver(ctx) {
|
|
1569
1506
|
const resolvedDefinitions = /* @__PURE__ */ new Map();
|
|
@@ -1581,11 +1518,11 @@ async function normalizeWorkerReferences(resolved, resolveDefinition) {
|
|
|
1581
1518
|
if (!isRecord(resolved) || !isRecord(resolved.env)) return resolved;
|
|
1582
1519
|
const env = { ...resolved.env };
|
|
1583
1520
|
for (const [bindingName, binding] of Object.entries(env)) {
|
|
1584
|
-
if (!isRecord(binding) || typeof binding.type !== "string" || !CROSS_WORKER_BINDING_TYPES.has(binding.type) ||
|
|
1521
|
+
if (!isRecord(binding) || typeof binding.type !== "string" || !CROSS_WORKER_BINDING_TYPES.has(binding.type) || typeof binding.worker === "string") continue;
|
|
1585
1522
|
const target = await resolveDefinition(binding.worker);
|
|
1586
1523
|
env[bindingName] = {
|
|
1587
1524
|
...binding,
|
|
1588
|
-
worker: normalizeConfigReference(binding.worker, target
|
|
1525
|
+
worker: normalizeConfigReference(binding.worker, target)
|
|
1589
1526
|
};
|
|
1590
1527
|
}
|
|
1591
1528
|
return {
|
|
@@ -1593,7 +1530,14 @@ async function normalizeWorkerReferences(resolved, resolveDefinition) {
|
|
|
1593
1530
|
env
|
|
1594
1531
|
};
|
|
1595
1532
|
}
|
|
1596
|
-
|
|
1533
|
+
function normalizeWorkerEntrypoint(resolved) {
|
|
1534
|
+
if (!isRecord(resolved) || !isRecord(resolved.entrypoint) || !("default" in resolved.entrypoint)) return resolved;
|
|
1535
|
+
return {
|
|
1536
|
+
...resolved,
|
|
1537
|
+
entrypoint: resolved.entrypoint.default
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1540
|
+
async function normalizeContainerReferences(resolved, resolveDefinition, containers) {
|
|
1597
1541
|
const issues = [];
|
|
1598
1542
|
if (!isRecord(resolved) || !isRecord(resolved.exports)) return {
|
|
1599
1543
|
value: resolved,
|
|
@@ -1612,7 +1556,7 @@ async function normalizeContainerReferences(resolved, resolveDefinition, resolve
|
|
|
1612
1556
|
exportName,
|
|
1613
1557
|
"container"
|
|
1614
1558
|
],
|
|
1615
|
-
message: "Container provided as a string. Reference
|
|
1559
|
+
message: "Container provided as a string. Reference a Container definition instead, for example `container: myContainer`."
|
|
1616
1560
|
});
|
|
1617
1561
|
workerExports[exportName] = {
|
|
1618
1562
|
...workerExport,
|
|
@@ -1621,7 +1565,7 @@ async function normalizeContainerReferences(resolved, resolveDefinition, resolve
|
|
|
1621
1565
|
continue;
|
|
1622
1566
|
}
|
|
1623
1567
|
const target = await resolveDefinition(reference);
|
|
1624
|
-
if (isRecord(target) &&
|
|
1568
|
+
if (isRecord(target) && typeof target.name === "string" && !containers.includes(target)) {
|
|
1625
1569
|
issues.push({
|
|
1626
1570
|
code: "custom",
|
|
1627
1571
|
input: reference,
|
|
@@ -1630,7 +1574,7 @@ async function normalizeContainerReferences(resolved, resolveDefinition, resolve
|
|
|
1630
1574
|
exportName,
|
|
1631
1575
|
"container"
|
|
1632
1576
|
],
|
|
1633
|
-
message: `The referenced Container "${target.name}" is not
|
|
1577
|
+
message: `The referenced Container "${target.name}" is not included in the \`containers\` array.`
|
|
1634
1578
|
});
|
|
1635
1579
|
workerExports[exportName] = {
|
|
1636
1580
|
...workerExport,
|
|
@@ -1640,7 +1584,7 @@ async function normalizeContainerReferences(resolved, resolveDefinition, resolve
|
|
|
1640
1584
|
}
|
|
1641
1585
|
workerExports[exportName] = {
|
|
1642
1586
|
...workerExport,
|
|
1643
|
-
container: normalizeConfigReference(reference, target
|
|
1587
|
+
container: normalizeConfigReference(reference, target)
|
|
1644
1588
|
};
|
|
1645
1589
|
}
|
|
1646
1590
|
return {
|
|
@@ -1651,8 +1595,8 @@ async function normalizeContainerReferences(resolved, resolveDefinition, resolve
|
|
|
1651
1595
|
issues
|
|
1652
1596
|
};
|
|
1653
1597
|
}
|
|
1654
|
-
async function
|
|
1655
|
-
return normalizeContainerReferences(await normalizeWorkerReferences(resolved, resolveDefinition), resolveDefinition,
|
|
1598
|
+
async function normalizeWorkerConfig(resolved, resolveDefinition, containers) {
|
|
1599
|
+
return normalizeContainerReferences(await normalizeWorkerReferences(normalizeWorkerEntrypoint(resolved), resolveDefinition), resolveDefinition, containers);
|
|
1656
1600
|
}
|
|
1657
1601
|
function prefixIssues(issues, prefix) {
|
|
1658
1602
|
return issues.map((issue) => ({
|
|
@@ -1660,129 +1604,99 @@ function prefixIssues(issues, prefix) {
|
|
|
1660
1604
|
path: [prefix, ...issue.path]
|
|
1661
1605
|
}));
|
|
1662
1606
|
}
|
|
1663
|
-
function
|
|
1607
|
+
function validateUniqueContainerNames(config) {
|
|
1664
1608
|
const issues = [];
|
|
1665
|
-
const
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
for (const [exportName, config] of Object.entries(configExports)) {
|
|
1670
|
-
if (config.type !== "container" && config.type !== "worker") continue;
|
|
1671
|
-
const resourceType = config.type === "container" ? "Container" : "Worker";
|
|
1672
|
-
const exportNames = exportNameByResourceName[config.type];
|
|
1673
|
-
const previousExportName = exportNames.get(config.name);
|
|
1674
|
-
if (previousExportName !== void 0) {
|
|
1609
|
+
const firstIndexByName = /* @__PURE__ */ new Map();
|
|
1610
|
+
for (const [index, container] of config.containers.entries()) {
|
|
1611
|
+
const firstIndex = firstIndexByName.get(container.name);
|
|
1612
|
+
if (firstIndex !== void 0) {
|
|
1675
1613
|
issues.push({
|
|
1676
1614
|
code: "custom",
|
|
1677
|
-
input:
|
|
1678
|
-
path: [
|
|
1679
|
-
|
|
1615
|
+
input: container.name,
|
|
1616
|
+
path: [
|
|
1617
|
+
"containers",
|
|
1618
|
+
index,
|
|
1619
|
+
"name"
|
|
1620
|
+
],
|
|
1621
|
+
message: `The Container name "${container.name}" is also used by \`containers[${firstIndex}]\`. Container names must be unique.`
|
|
1680
1622
|
});
|
|
1681
1623
|
continue;
|
|
1682
1624
|
}
|
|
1683
|
-
|
|
1625
|
+
firstIndexByName.set(container.name, index);
|
|
1684
1626
|
}
|
|
1685
1627
|
return issues;
|
|
1686
1628
|
}
|
|
1687
|
-
function
|
|
1629
|
+
function validateContainerLinks(config) {
|
|
1688
1630
|
const issues = [];
|
|
1689
|
-
const
|
|
1690
|
-
for (const
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
code: "custom",
|
|
1706
|
-
input: containerName,
|
|
1707
|
-
path,
|
|
1708
|
-
message: `The Container "${containerName}" is not exported from this configuration.`
|
|
1709
|
-
});
|
|
1710
|
-
continue;
|
|
1711
|
-
}
|
|
1712
|
-
const firstReference = firstReferenceByContainerName.get(containerName);
|
|
1713
|
-
if (firstReference !== void 0) {
|
|
1714
|
-
issues.push({
|
|
1715
|
-
code: "custom",
|
|
1716
|
-
input: containerName,
|
|
1717
|
-
path,
|
|
1718
|
-
message: `The Container "${containerName}" is already referenced by "${firstReference.workerExportName}.exports.${firstReference.durableObjectExportName}". A Container can only be linked to one Durable Object.`
|
|
1719
|
-
});
|
|
1720
|
-
continue;
|
|
1721
|
-
}
|
|
1722
|
-
firstReferenceByContainerName.set(containerName, {
|
|
1723
|
-
workerExportName,
|
|
1724
|
-
durableObjectExportName
|
|
1631
|
+
const firstExportByContainerName = /* @__PURE__ */ new Map();
|
|
1632
|
+
for (const [exportName, workerExport] of Object.entries(config.worker?.exports ?? {})) {
|
|
1633
|
+
if (workerExport.type !== "durable-object" || !("container" in workerExport) || workerExport.container === void 0) continue;
|
|
1634
|
+
const containerName = workerExport.container;
|
|
1635
|
+
const firstExportName = firstExportByContainerName.get(containerName);
|
|
1636
|
+
if (firstExportName !== void 0) {
|
|
1637
|
+
issues.push({
|
|
1638
|
+
code: "custom",
|
|
1639
|
+
input: containerName,
|
|
1640
|
+
path: [
|
|
1641
|
+
"worker",
|
|
1642
|
+
"exports",
|
|
1643
|
+
exportName,
|
|
1644
|
+
"container"
|
|
1645
|
+
],
|
|
1646
|
+
message: `The Container "${containerName}" is already referenced by \`worker.exports.${firstExportName}\`. A Container can only be linked to one Durable Object.`
|
|
1725
1647
|
});
|
|
1648
|
+
continue;
|
|
1726
1649
|
}
|
|
1650
|
+
firstExportByContainerName.set(containerName, exportName);
|
|
1727
1651
|
}
|
|
1728
1652
|
return issues;
|
|
1729
1653
|
}
|
|
1730
|
-
/**
|
|
1731
|
-
|
|
1732
|
-
*
|
|
1733
|
-
* Config inputs are resolved once by identity. Top-level Worker and Container
|
|
1734
|
-
* exports are also parsed once by identity. References are resolved only far
|
|
1735
|
-
* enough to replace them with resource names, then Container links are
|
|
1736
|
-
* validated across the exported resources.
|
|
1737
|
-
*/
|
|
1738
|
-
async function resolveAndValidateConfigExports(exports$2, ctx) {
|
|
1654
|
+
/** Resolve and parse the default configuration export. */
|
|
1655
|
+
async function resolveAndParseConfig(input, ctx) {
|
|
1739
1656
|
const resolveDefinition = createDefinitionResolver(ctx);
|
|
1740
|
-
const
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
const
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
const
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
if (resolved.type === "worker") {
|
|
1758
|
-
const normalized = await normalizeConfigReferences(resolved, resolveDefinition, resolvedExports);
|
|
1759
|
-
issues.push(...prefixIssues(normalized.issues, name));
|
|
1760
|
-
result = InputWorkerSchema.safeParse(normalized.value);
|
|
1761
|
-
} else result = InputContainerSchema.safeParse(resolved);
|
|
1762
|
-
parsedResources.set(input, result);
|
|
1763
|
-
if (!result.success) issues.push(...prefixIssues(result.error.issues, name));
|
|
1764
|
-
}
|
|
1765
|
-
if (result.success) data[name] = result.data;
|
|
1766
|
-
}
|
|
1767
|
-
issues.push(...validateUniqueResourceNames(data), ...validateContainerExportLinks(data));
|
|
1657
|
+
const resolved = await resolveDefinition(input);
|
|
1658
|
+
if (!isRecord(resolved)) return InputConfigSchema.safeParse(resolved);
|
|
1659
|
+
const containerInputs = Array.isArray(resolved.containers) ? resolved.containers : [];
|
|
1660
|
+
const containers = await Promise.all(containerInputs.map((container) => resolveDefinition(container)));
|
|
1661
|
+
const normalizedWorker = resolved.worker === void 0 ? {
|
|
1662
|
+
value: void 0,
|
|
1663
|
+
issues: []
|
|
1664
|
+
} : await normalizeWorkerConfig(await resolveDefinition(resolved.worker), resolveDefinition, containers);
|
|
1665
|
+
const candidate = {
|
|
1666
|
+
...resolved,
|
|
1667
|
+
...resolved.worker === void 0 ? {} : { worker: normalizedWorker.value },
|
|
1668
|
+
...Array.isArray(resolved.containers) ? { containers } : {}
|
|
1669
|
+
};
|
|
1670
|
+
const result = InputConfigSchema.safeParse(candidate);
|
|
1671
|
+
const issues = [...prefixIssues(normalizedWorker.issues, "worker")];
|
|
1672
|
+
if (!result.success) issues.push(...result.error.issues);
|
|
1673
|
+
else issues.push(...validateUniqueContainerNames(result.data), ...validateContainerLinks(result.data));
|
|
1768
1674
|
return issues.length > 0 ? {
|
|
1769
1675
|
success: false,
|
|
1770
1676
|
error: new z.ZodError(issues)
|
|
1771
|
-
} :
|
|
1772
|
-
|
|
1773
|
-
|
|
1677
|
+
} : result;
|
|
1678
|
+
}
|
|
1679
|
+
/** Resolve and parse only the account settings in a configuration definition. */
|
|
1680
|
+
async function resolveAndParseConfigSettings(input, ctx) {
|
|
1681
|
+
const resolved = await createDefinitionResolver(ctx)(input);
|
|
1682
|
+
return InputSettingsSchema.safeParse(resolved);
|
|
1683
|
+
}
|
|
1684
|
+
/** Load and parse `cloudflare.config.ts`'s default export. */
|
|
1685
|
+
async function loadAndParseConfig(configPath, ctx) {
|
|
1686
|
+
const { config, dependencies } = await loadConfig(configPath);
|
|
1687
|
+
return {
|
|
1688
|
+
result: await resolveAndParseConfig(config, ctx),
|
|
1689
|
+
dependencies
|
|
1774
1690
|
};
|
|
1775
1691
|
}
|
|
1776
|
-
/**
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
async function loadAndValidateConfig(configPath, ctx, options) {
|
|
1780
|
-
const { exports: exports$2, dependencies } = await loadConfig(configPath, options);
|
|
1692
|
+
/** Load and parse only account settings from the default export. */
|
|
1693
|
+
async function loadAndParseConfigSettings(configPath, ctx) {
|
|
1694
|
+
const { config, dependencies } = await loadConfig(configPath);
|
|
1781
1695
|
return {
|
|
1782
|
-
result: await
|
|
1696
|
+
result: await resolveAndParseConfigSettings(config, ctx),
|
|
1783
1697
|
dependencies
|
|
1784
1698
|
};
|
|
1785
1699
|
}
|
|
1786
1700
|
|
|
1787
1701
|
//#endregion
|
|
1788
|
-
export { AnalyticsEngineDatasetBindingSchema, AssetsSchema, BindingSchema, BrowserBindingSchema, D1BindingSchema, DurableObjectCreatedExportSchema, DurableObjectDeletedExportSchema, DurableObjectExpectingTransferExportSchema, DurableObjectRenamedExportSchema, DurableObjectTransferredExportSchema, ExportSchema, FlagshipBindingSchema, HyperdriveBindingSchema, InputContainerSchema, InputSettingsSchema, InputWorkerSchema, KVBindingSchema, KnownBindingSchema, ModuleTypeSchema, OutputContainerSchema,
|
|
1702
|
+
export { AnalyticsEngineDatasetBindingSchema, AssetsSchema, BindingSchema, BrowserBindingSchema, D1BindingSchema, DurableObjectCreatedExportSchema, DurableObjectDeletedExportSchema, DurableObjectExpectingTransferExportSchema, DurableObjectRenamedExportSchema, DurableObjectTransferredExportSchema, ExportSchema, FlagshipBindingSchema, HyperdriveBindingSchema, InputConfigSchema, InputContainerSchema, InputSettingsSchema, InputWorkerSchema, KVBindingSchema, KnownBindingSchema, ModuleTypeSchema, OutputContainerSchema, OutputRootConfigSchema, OutputWorkerSchema, QueueBindingSchema, R2BindingSchema, TailConsumerSchema, UnsafeBindingSchema, WorkerBindingSchema, WorkerEntrypointExportSchema, bindings, convertToWranglerConfig, defineConfig, defineContainer, defineWorker, exports$1 as exports, generateTypes, loadAndParseConfig, loadAndParseConfigSettings, loadConfig, registerConfigHooks, resolveAndParseConfig, resolveAndParseConfigSettings, triggers, validateSingletonBindings };
|