@dragonmastery/tamer 0.36.3 → 0.36.4
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/{apply-CSQ2lLYY.mjs → apply-DPkTNVwz.mjs} +8 -8
- package/dist/{apply-CSQ2lLYY.mjs.map → apply-DPkTNVwz.mjs.map} +1 -1
- package/dist/{applyTarget-q8lQlmL6.mjs → applyTarget-IwJLJY-2.mjs} +2 -2
- package/dist/{applyTarget-q8lQlmL6.mjs.map → applyTarget-IwJLJY-2.mjs.map} +1 -1
- package/dist/{cloudflareSnapshot-D9LAgUVP.mjs → cloudflareSnapshot-DOphOBnH.mjs} +2 -2
- package/dist/{cloudflareSnapshot-D9LAgUVP.mjs.map → cloudflareSnapshot-DOphOBnH.mjs.map} +1 -1
- package/dist/{deploy-CNQ9lhnp.mjs → deploy-BvWkPRlh.mjs} +5 -5
- package/dist/{deploy-CNQ9lhnp.mjs.map → deploy-BvWkPRlh.mjs.map} +1 -1
- package/dist/{destroy-D18ZIufa.mjs → destroy-OozAEB7_.mjs} +5 -5
- package/dist/{destroy-D18ZIufa.mjs.map → destroy-OozAEB7_.mjs.map} +1 -1
- package/dist/{dev-CsZ0sDe0.mjs → dev-CcM6_SJV.mjs} +4 -4
- package/dist/{dev-CsZ0sDe0.mjs.map → dev-CcM6_SJV.mjs.map} +1 -1
- package/dist/{drift-Bdt91dCs.mjs → drift-DxrfuuD0.mjs} +2 -2
- package/dist/{drift-Bdt91dCs.mjs.map → drift-DxrfuuD0.mjs.map} +1 -1
- package/dist/{drift-ATV3NuQ0.mjs → drift-ODjZs4io.mjs} +2 -2
- package/dist/{emit-D0p7CKFk.mjs → emit-BxHhy1ZC.mjs} +2 -2
- package/dist/{emit-D0p7CKFk.mjs.map → emit-BxHhy1ZC.mjs.map} +1 -1
- package/dist/{generator-vDl0esL-.mjs → generator-qyqB1_Yv.mjs} +2 -2
- package/dist/{generator-vDl0esL-.mjs.map → generator-qyqB1_Yv.mjs.map} +1 -1
- package/dist/{import-7TWYhptE.mjs → import-Bp07LFfK.mjs} +2 -2
- package/dist/{import-7TWYhptE.mjs.map → import-Bp07LFfK.mjs.map} +1 -1
- package/dist/{migrate-DaxG75UZ.mjs → migrate-CeUZBQtV.mjs} +3 -3
- package/dist/{migrate-DaxG75UZ.mjs.map → migrate-CeUZBQtV.mjs.map} +1 -1
- package/dist/{plan-NIPM6cF3.mjs → plan-NOBO-FYD.mjs} +5 -5
- package/dist/{plan-NIPM6cF3.mjs.map → plan-NOBO-FYD.mjs.map} +1 -1
- package/dist/{registry-Du91dVUE.mjs → registry-BlTu3xMp.mjs} +25 -17
- package/dist/{registry-Du91dVUE.mjs.map → registry-BlTu3xMp.mjs.map} +1 -1
- package/dist/{status-BOlsYClM.mjs → status-Cj14l-ax.mjs} +2 -2
- package/dist/{status-BOlsYClM.mjs.map → status-Cj14l-ax.mjs.map} +1 -1
- package/dist/{sync-nkUmYv5B.mjs → sync-B6vBSAKa.mjs} +2 -2
- package/dist/{sync-nkUmYv5B.mjs.map → sync-B6vBSAKa.mjs.map} +1 -1
- package/dist/tamer.mjs +11 -11
- package/dist/{types-OTsgglTT.mjs → types-CcuMLDrv.mjs} +3 -3
- package/dist/{types-OTsgglTT.mjs.map → types-CcuMLDrv.mjs.map} +1 -1
- package/dist/{verifyPlanFile-B6Wxl2m2.mjs → verifyPlanFile-CuG9sooo.mjs} +2 -2
- package/dist/{verifyPlanFile-B6Wxl2m2.mjs.map → verifyPlanFile-CuG9sooo.mjs.map} +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry-Du91dVUE.mjs","names":["override","todayIso","derivedName","uuid","compact","iso","drift: ResourceDrift","bindings: WranglerD1Database[]","results: D1StatusResult[]","d1Module: ResourceModule<D1ResourceConfig, CFD1>","entry: D1StateEntry","errors: string[]","drift: ResourceDrift","bindings: WranglerR2Bucket[]","results: R2StatusResult[]","r2Module: ResourceModule<R2ResourceConfig, CFR2>","entry: R2StateEntry","drift: ResourceDrift","bindings: WranglerKVNamespace[]","results: KVStatusResult[]","kvModule: ResourceModule<KVResourceConfig, CFKv>","entry: KVStateEntry","STATE_KEY_PREFIX","stateKey","drift: ResourceDrift","producers: Array<{ binding: string; queue: string }>","out: QueuesStatusResult[]","queuesModule: ResourceModule<QueueResourceConfig, CFQueue>","out: NonNullable<\n import(\"../../generated/wrangler-types.js\").WranglerConfig[\"queues\"]\n >","entry: QueueStateEntry","items: PlanItem[]","computeChanges","formatVal","changes: PlanFieldChange[]","STATE_KEY_PREFIX","stateKey","origin","drift: ResourceDrift","out: GeneratedHyperdriveBinding[]","out: HyperdriveStatusResult[]","hyperdriveModule: ResourceModule<\n HyperdriveResourceConfig,\n CFHyperdrive\n>","entry: HyperdriveStateEntry","STATE_KEY_PREFIX","stateKey","drift: ResourceDrift","out: GeneratedVectorizeBinding[]","out: VectorizeStatusResult[]","items: PlanItem[]","changes: PlanFieldChange[]","vectorizeModule: ResourceModule<\n VectorizeResourceConfig,\n CFVectorize\n>","entry: VectorizeStateEntry","items: PlanItem[]","formatVal","changes: PlanFieldChange[]","STATE_KEY_PREFIX","stateKey","drift: ResourceDrift","out: AIGatewayStatusResult[]","aiGatewayModule: ResourceModule<\n AIGatewayResourceConfig,\n CFAIGateway\n>","entry: AIGatewayStateEntry","STATE_KEY_PREFIX","stateKey","drift: ResourceDrift","out: GeneratedPipelineBinding[]","out: PipelineStatusResult[]","items: PlanItem[]","changes: PlanFieldChange[]","pipelinesModule: ResourceModule<\n PipelineResourceConfig,\n CFPipeline\n>","entry: PipelineStateEntry","items: PlanItem[]","changes: PlanFieldChange[]","STATE_KEY_PREFIX","stateKey","upserted: Awaited<ReturnType<typeof api.workflowUpsert>>","entry: WorkflowStateEntry","entry: WorkflowStateEntry","drift: ResourceDrift","out: GeneratedWorkflowBinding[]","binding: GeneratedWorkflowBinding","out: WorkflowStatusResult[]","workflowsModule: ResourceModule<\n WorkflowResourceConfig,\n CFWorkflow\n>","entry: WorkflowStateEntry","allStores:\n | Awaited<ReturnType<typeof api.secretsStoreListAll>>\n | null","cfId: string","entry: SecretsStoreStateEntry","entry: SecretsStoreStateEntry","drift: ResourceDrift","out: SecretsStoreStatusResult[]","secretsStoreModule: ResourceModule<\n SecretsStoreResourceConfig,\n CFSecretsStore\n>","entry: SecretsStoreStateEntry","resourceModules: ReadonlyArray<ResourceModule>","moduleByKind: Map<ResourceKind, ResourceModule>"],"sources":["../src/core/naming/resolveCloudflareName.ts","../src/features/d1/d1.ownership.ts","../src/features/d1/d1.naming.ts","../src/features/d1/d1.apply.ts","../src/features/d1/d1.sync.ts","../src/features/d1/d1.drift.ts","../src/core/config/resourcesFromConfig.ts","../src/features/d1/d1.destroy.ts","../src/features/d1/d1.generate.ts","../src/features/d1/d1.status.ts","../src/core/registry/pickResources.ts","../src/core/registry/findResourceForImport.ts","../src/features/d1/d1.module.ts","../src/features/r2/r2.naming.ts","../src/features/r2/r2.apply.ts","../src/features/r2/r2.sync.ts","../src/features/r2/r2.drift.ts","../src/features/r2/r2.destroy.ts","../src/features/r2/r2.generate.ts","../src/features/r2/r2.status.ts","../src/features/r2/r2.module.ts","../src/features/kv/kv.naming.ts","../src/features/kv/kv.apply.ts","../src/features/kv/kv.sync.ts","../src/features/kv/kv.drift.ts","../src/features/kv/kv.destroy.ts","../src/features/kv/kv.generate.ts","../src/features/kv/kv.status.ts","../src/features/kv/kv.module.ts","../src/features/queues/queues.naming.ts","../src/features/queues/queues.apply.ts","../src/features/queues/queues.sync.ts","../src/features/queues/queues.drift.ts","../src/features/queues/queues.destroy.ts","../src/features/queues/queues.generate.ts","../src/features/queues/queues.status.ts","../src/features/queues/queues.module.ts","../src/features/hyperdrive/hyperdrive.secrets.ts","../src/features/hyperdrive/hyperdrive.naming.ts","../src/features/hyperdrive/hyperdrive.diff.ts","../src/features/hyperdrive/hyperdrive.apply.ts","../src/features/hyperdrive/hyperdrive.sync.ts","../src/features/hyperdrive/hyperdrive.drift.ts","../src/features/hyperdrive/hyperdrive.destroy.ts","../src/features/hyperdrive/hyperdrive.generate.ts","../src/features/hyperdrive/hyperdrive.status.ts","../src/features/hyperdrive/hyperdrive.module.ts","../src/features/vectorize/vectorize.naming.ts","../src/features/vectorize/vectorize.apply.ts","../src/features/vectorize/vectorize.sync.ts","../src/features/vectorize/vectorize.drift.ts","../src/features/vectorize/vectorize.destroy.ts","../src/features/vectorize/vectorize.generate.ts","../src/features/vectorize/vectorize.status.ts","../src/features/vectorize/vectorize.diff.ts","../src/features/vectorize/vectorize.module.ts","../src/features/ai-gateway/ai-gateway.types.ts","../src/features/ai-gateway/ai-gateway.naming.ts","../src/features/ai-gateway/ai-gateway.diff.ts","../src/features/ai-gateway/ai-gateway.apply.ts","../src/features/ai-gateway/ai-gateway.sync.ts","../src/features/ai-gateway/ai-gateway.drift.ts","../src/features/ai-gateway/ai-gateway.destroy.ts","../src/features/ai-gateway/ai-gateway.status.ts","../src/features/ai-gateway/ai-gateway.module.ts","../src/features/pipelines/pipelines.naming.ts","../src/features/pipelines/pipelines.apply.ts","../src/features/pipelines/pipelines.sync.ts","../src/features/pipelines/pipelines.drift.ts","../src/features/pipelines/pipelines.destroy.ts","../src/features/pipelines/pipelines.generate.ts","../src/features/pipelines/pipelines.status.ts","../src/features/pipelines/pipelines.diff.ts","../src/features/pipelines/pipelines.module.ts","../src/features/workflows/workflows.naming.ts","../src/features/workflows/workflows.diff.ts","../src/features/workflows/workflows.apply.ts","../src/features/workflows/workflows.sync.ts","../src/features/workflows/workflows.drift.ts","../src/features/workflows/workflows.destroy.ts","../src/features/workflows/workflows.generate.ts","../src/features/workflows/workflows.status.ts","../src/features/workflows/workflows.module.ts","../src/features/secrets-store/secrets-store.naming.ts","../src/features/secrets-store/secrets-store.apply.ts","../src/features/secrets-store/secrets-store.sync.ts","../src/features/secrets-store/secrets-store.drift.ts","../src/features/secrets-store/secrets-store.destroy.ts","../src/features/secrets-store/secrets-store.status.ts","../src/features/secrets-store/secrets-store.module.ts","../src/core/registry/registry.ts"],"sourcesContent":["import type {\n AIGatewayResourceConfig,\n CloudflareNameContext,\n CloudflareNameFn,\n D1ResourceConfig,\n HyperdriveResourceConfig,\n KVResourceConfig,\n PipelineResourceConfig,\n QueueResourceConfig,\n R2ResourceConfig,\n SecretsStoreResourceConfig,\n VectorizeResourceConfig,\n WorkflowResourceConfig,\n} from \"../../types.js\";\nimport type { NamingEngine } from \"./NamingEngine.js\";\n\nfunction resolveOverride(\n fn: CloudflareNameFn | undefined,\n tenantId: string,\n env: string,\n ctx?: CloudflareNameContext,\n): string | undefined {\n if (!fn) return undefined;\n return fn(tenantId, env, ctx);\n}\n\n/** Managed D1 Cloudflare database name (not external `databaseName`). */\nexport function resolveD1CloudflareName(\n config: D1ResourceConfig,\n env: string,\n naming: NamingEngine,\n shardDate?: string,\n): string {\n const tenantId = naming.tenantId;\n if (config.type === \"single\") {\n const override = resolveOverride(config.cloudflareName, tenantId, env);\n if (override !== undefined) return override;\n return naming.d1SingleName(config.logicalName, env);\n }\n if (!shardDate) {\n throw new Error(`Sharded D1 \"${config.logicalName}\" requires shardDate`);\n }\n const override = resolveOverride(config.cloudflareName, tenantId, env, {\n shardDate,\n });\n if (override !== undefined) return override;\n return naming.d1ShardName(config.logicalName, shardDate, env);\n}\n\nexport function resolveR2CloudflareName(\n config: R2ResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.r2BucketName(config.logicalName, env);\n}\n\nexport function resolveWorkflowCloudflareName(\n config: WorkflowResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.workflowName(config.logicalName, env);\n}\n\nexport function resolveKVCloudflareName(\n config: KVResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.kvNamespaceName(config.logicalName, env);\n}\n\nexport function resolveQueueCloudflareName(\n config: QueueResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.queueName(config.logicalName, env);\n}\n\nexport function resolveHyperdriveCloudflareName(\n config: HyperdriveResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.hyperdriveName(config.logicalName, env);\n}\n\nexport function resolveVectorizeCloudflareName(\n config: VectorizeResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.vectorizeName(config.logicalName, env);\n}\n\nexport function resolveAIGatewayCloudflareName(\n config: AIGatewayResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.aiGatewayId(config.logicalName, env);\n}\n\nexport function resolvePipelineCloudflareName(\n config: PipelineResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.pipelineName(config.logicalName, env);\n}\n\nexport function resolveSecretsStoreCloudflareName(\n config: SecretsStoreResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.secretsStoreName(config.logicalName, env);\n}\n","import type { D1ResourceConfig } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveD1CloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\n\nexport function d1IsExternal(config: D1ResourceConfig): boolean {\n return config.ownership === \"external\";\n}\n\n/**\n * Skip provision / migrate / Cloudflare delete for this binding.\n * `preserveOnDestroy` alone keeps legacy \"same derived name as owner\" behaviour.\n */\nexport function d1SkipsProvisionAndMigrate(config: D1ResourceConfig): boolean {\n return d1IsExternal(config) || config.preserveOnDestroy === true;\n}\n\n/** Cloudflare D1 database name for state keys, sync, and wrangler `database_name`. */\nexport function d1CloudflareDatabaseName(\n config: D1ResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n if (config.type !== \"single\") {\n throw new Error(\n `D1 \"${config.logicalName}\": expected type \"single\" for derived database name`,\n );\n }\n if (d1IsExternal(config)) {\n const n = config.databaseName;\n if (typeof n !== \"string\" || !n.trim()) {\n throw new Error(\n `D1 \"${config.logicalName}\" has ownership \"external\" but databaseName is empty — ` +\n `ensure imports are pre-fetched and config is merged with resolveWorkerConfig / mergeWorkerConfigWithResolvedRefs.`,\n );\n }\n return n.trim();\n }\n return resolveD1CloudflareName(config, env, naming);\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveD1CloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { D1ResourceConfig } from \"./d1.types.js\";\n\n/** Normalize config/import shard dates to ISO `YYYY-MM-DD`. */\nexport function normalizeShardDateIso(raw: string): string {\n const trimmed = raw.trim();\n if (/^\\d{8}$/.test(trimmed)) {\n return `${trimmed.slice(0, 4)}-${trimmed.slice(4, 6)}-${trimmed.slice(6, 8)}`;\n }\n if (/^\\d{4}-\\d{2}-\\d{2}$/.test(trimmed)) {\n return trimmed;\n }\n throw new Error(\n `Invalid shardDate \"${raw}\" — use YYYY-MM-DD or YYYYMMDD`,\n );\n}\n\nexport function d1DeriveName(\n config: D1ResourceConfig,\n env: string,\n shardDate: string | undefined,\n naming: NamingEngine,\n): string {\n if (config.type === \"single\") {\n return resolveD1CloudflareName(config, env, naming);\n }\n const resolved = shardDate ?? config.shardDate;\n if (!resolved) {\n throw new Error(`Sharded D1 \"${config.logicalName}\" requires shardDate`);\n }\n return resolveD1CloudflareName(\n config,\n env,\n naming,\n normalizeShardDateIso(resolved),\n );\n}\n\nexport function d1DeriveBindingKey(\n config: D1ResourceConfig,\n shardDate: string | undefined,\n naming: NamingEngine,\n): string {\n const explicit = config.binding?.trim();\n if (config.type === \"single\") {\n return explicit || naming.d1SingleBindingKey(config.logicalName);\n }\n if (explicit) {\n return explicit;\n }\n const resolved = shardDate ?? config.shardDate;\n if (!resolved) {\n throw new Error(`Sharded D1 \"${config.logicalName}\" requires shardDate`);\n }\n return naming.d1ShardBindingKey(\n config.logicalName,\n normalizeShardDateIso(resolved),\n );\n}\n\n/** Shard date stored on state rows (ISO), from config pin or CF name extraction. */\nexport function d1ResolveShardDateIso(\n config: D1ResourceConfig,\n extractedFromName: string | null | undefined,\n): string | undefined {\n if (config.type !== \"sharded\") return undefined;\n if (config.shardDate) {\n return normalizeShardDateIso(config.shardDate);\n }\n return extractedFromName ?? undefined;\n}\n\nexport function d1MatchPattern(\n config: D1ResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n if (config.type === \"single\") {\n const exactName = resolveD1CloudflareName(config, env, naming);\n return (name: string) => name === exactName;\n }\n\n const pinnedIso = config.shardDate\n ? normalizeShardDateIso(config.shardDate)\n : undefined;\n\n if (config.cloudflareName || naming.hasD1ShardConvention()) {\n return (name: string) => {\n const shardDate = d1ExtractShardDate(name, naming);\n if (!shardDate) return false;\n if (pinnedIso && normalizeShardDateIso(shardDate) !== pinnedIso) {\n return false;\n }\n try {\n return resolveD1CloudflareName(config, env, naming, shardDate) === name;\n } catch {\n return false;\n }\n };\n }\n\n const base = naming.d1MatchPattern(config.logicalName, env);\n if (!pinnedIso) return base;\n return (name: string) => {\n if (!base(name)) return false;\n const shardDate = d1ExtractShardDate(name, naming);\n return shardDate !== null && normalizeShardDateIso(shardDate) === pinnedIso;\n };\n}\n\nexport function d1ExtractShardDate(name: string, naming: NamingEngine): string | null {\n return naming.extractD1ShardDate(name);\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { D1ResourceConfig } from \"./d1.types.js\";\nimport {\n d1CloudflareDatabaseName,\n d1SkipsProvisionAndMigrate,\n} from \"./d1.ownership.js\";\nimport { d1DeriveName, d1DeriveBindingKey, normalizeShardDateIso } from \"./d1.naming.js\";\n\nfunction todayNoDashes(): string {\n return new Date().toISOString().slice(0, 10).replace(/-/g, \"\");\n}\n\nfunction todayIso(): string {\n return new Date().toISOString().slice(0, 10);\n}\n\nfunction resolveInitialShardDate(config: D1ResourceConfig): {\n iso: string;\n compact: string;\n} {\n if (config.shardDate) {\n const iso = normalizeShardDateIso(config.shardDate);\n return { iso, compact: iso.replace(/-/g, \"\") };\n }\n return { iso: todayIso(), compact: todayNoDashes() };\n}\n\nexport async function d1Apply(\n resources: D1ResourceConfig[],\n tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n addShard?: string\n): Promise<void> {\n for (const config of resources) {\n if (config.type === \"single\") {\n const derivedName = d1CloudflareDatabaseName(config, env, naming);\n const existing = state.get(derivedName);\n if (existing) continue;\n\n if (d1SkipsProvisionAndMigrate(config)) {\n console.warn(\n `[apply] Skipping D1 create for \"${config.logicalName}\" (external / preserveOnDestroy). ` +\n `Run \\`tamer sync\\` after the owning stack has created ${derivedName}.`,\n );\n continue;\n }\n\n const { uuid } = await api.d1Create(derivedName);\n state.set(derivedName, {\n type: \"d1_database\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: d1DeriveBindingKey(config, undefined, naming),\n cfId: uuid,\n migrationsDir: config.migrationsDir,\n preserveOnDestroy: false,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n continue;\n }\n\n if (addShard && addShard !== config.logicalName) continue;\n if (addShard && addShard === config.logicalName) {\n const { iso, compact } = resolveInitialShardDate(config);\n const derivedName = d1DeriveName(config, env, compact, naming);\n const existing = state.get(derivedName);\n if (existing) continue;\n\n const { uuid } = await api.d1Create(derivedName);\n state.set(derivedName, {\n type: \"d1_database\",\n logicalName: config.logicalName,\n shardDate: iso,\n derivedName,\n bindingKey: d1DeriveBindingKey(config, iso, naming),\n cfId: uuid,\n migrationsDir: config.migrationsDir,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n continue;\n }\n\n const allResources = state.getAll();\n const existingShards = Object.values(allResources).filter(\n (e) => e.type === \"d1_database\" && \"logicalName\" in e && e.logicalName === config.logicalName\n );\n if (existingShards.length > 0) continue;\n\n const { iso, compact } = resolveInitialShardDate(config);\n const derivedName = d1DeriveName(config, env, compact, naming);\n const { uuid } = await api.d1Create(derivedName);\n state.set(derivedName, {\n type: \"d1_database\",\n logicalName: config.logicalName,\n shardDate: iso,\n derivedName,\n bindingKey: d1DeriveBindingKey(config, iso, naming),\n cfId: uuid,\n migrationsDir: config.migrationsDir,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { D1ResourceConfig, D1StateEntry } from \"./d1.types.js\";\nimport { d1MatchPattern, d1ExtractShardDate, d1DeriveBindingKey, d1ResolveShardDateIso } from \"./d1.naming.js\";\nimport {\n d1CloudflareDatabaseName,\n d1SkipsProvisionAndMigrate,\n} from \"./d1.ownership.js\";\n\ninterface CFD1Database {\n uuid: string;\n name: string;\n created_at: string;\n}\n\nexport function d1Sync(\n allD1: CFD1Database[],\n resources: D1ResourceConfig[],\n tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine\n): void {\n for (const config of resources) {\n const pattern = d1MatchPattern(config, env, naming);\n\n if (config.type === \"single\") {\n const derivedKey = d1CloudflareDatabaseName(config, env, naming);\n const match = allD1.find((db) => db.name === derivedKey);\n if (match) {\n state.set(match.name, {\n type: \"d1_database\",\n logicalName: config.logicalName,\n derivedName: match.name,\n bindingKey: d1DeriveBindingKey(config, undefined, naming),\n cfId: match.uuid,\n migrationsDir: config.migrationsDir,\n preserveOnDestroy: d1SkipsProvisionAndMigrate(config),\n createdAt: match.created_at,\n updatedAt: new Date().toISOString(),\n });\n }\n continue;\n }\n\n const shards = allD1.filter((db) => pattern(db.name));\n for (const shard of shards) {\n const extracted = d1ExtractShardDate(shard.name, naming);\n const shardDateIso = d1ResolveShardDateIso(config, extracted);\n if (!shardDateIso) continue;\n\n state.set(shard.name, {\n type: \"d1_database\",\n logicalName: config.logicalName,\n shardDate: shardDateIso,\n derivedName: shard.name,\n bindingKey: d1DeriveBindingKey(config, shardDateIso, naming),\n cfId: shard.uuid,\n migrationsDir: config.migrationsDir,\n createdAt: shard.created_at,\n updatedAt: new Date().toISOString(),\n });\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { D1ResourceConfig, D1StateEntry } from \"./d1.types.js\";\nimport { d1MatchPattern, d1ExtractShardDate } from \"./d1.naming.js\";\nimport { d1CloudflareDatabaseName } from \"./d1.ownership.js\";\nimport type { ResourceDrift, DriftEntry } from \"../../core/drift/drift.types.js\";\n\ninterface CFD1Database {\n uuid: string;\n name: string;\n}\n\n/**\n * Diff D1 state against the Cloudflare list and the current config.\n *\n * - **single**: one expected derived name per resource.\n * - **sharded**: every CF database matching the pattern is \"expected\"; state\n * should contain an entry for each.\n */\nexport function d1Drift(\n allD1: CFD1Database[],\n resources: D1ResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"d1\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allD1.map((db) => [db.name, db.uuid]));\n const allState = state.getAll();\n const d1State = Object.values(allState).filter(\n (e): e is D1StateEntry => e.type === \"d1_database\",\n );\n\n for (const config of resources) {\n if (config.type === \"single\") {\n const derivedName = d1CloudflareDatabaseName(config, env, naming);\n const cfId = cfByName.get(derivedName);\n const stateEntry = d1State.find(\n (e) => e.logicalName === config.logicalName && !e.shardDate,\n );\n\n if (stateEntry && !cfId) {\n drift.missingFromCloudflare.push(toEntry(stateEntry));\n } else if (cfId && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId,\n });\n } else if (!cfId && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n continue;\n }\n\n const pattern = d1MatchPattern(config, env, naming);\n const cfShards = allD1.filter((db) => pattern(db.name));\n const cfShardNames = new Set(cfShards.map((s) => s.name));\n const stateShards = d1State.filter(\n (e) => e.logicalName === config.logicalName && !!e.shardDate,\n );\n const stateShardNames = new Set(stateShards.map((s) => s.derivedName));\n\n for (const shard of stateShards) {\n if (!cfShardNames.has(shard.derivedName)) {\n drift.missingFromCloudflare.push(toEntry(shard));\n }\n }\n for (const shard of cfShards) {\n if (!stateShardNames.has(shard.name)) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName: shard.name,\n cfId: shard.uuid,\n detail: d1ExtractShardDate(shard.name, naming) ?? undefined,\n });\n }\n }\n if (cfShards.length === 0 && stateShards.length === 0) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName: `(no shards for ${config.logicalName})`,\n });\n }\n }\n\n return drift;\n}\n\nfunction toEntry(e: D1StateEntry): DriftEntry {\n return {\n logicalName: e.logicalName,\n derivedName: e.derivedName,\n cfId: e.cfId,\n detail: e.shardDate,\n };\n}\n","import type { CfiConfig } from \"../../types.js\";\nimport { getWorkers } from \"./loader.js\";\nimport {\n getResourceModule,\n type ResourceKind,\n} from \"../registry/registry.js\";\n\n/**\n * Logical resource names declared on workers in this config (for\n * stack-scoped destroy / drift). Iterates the resource registry — adding a\n * new kind doesn't require editing this file.\n */\nexport async function logicalNamesForResourceKind(\n config: CfiConfig,\n baseDir: string,\n kind: ResourceKind,\n): Promise<Set<string>> {\n const mod = getResourceModule(kind);\n if (!mod) return new Set();\n const workers = await getWorkers(config, baseDir);\n const set = new Set<string>();\n for (const [, wc] of workers) {\n for (const r of mod.pickResources(wc)) {\n const logical = (r as { logicalName?: string }).logicalName;\n if (logical) set.add(logical);\n }\n }\n return set;\n}\n","import type { CfiConfig } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\nimport type { D1StateEntry } from \"./d1.types.js\";\n\nexport async function d1Destroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"d1\");\n const resources = state.getAll();\n const d1Entries = Object.values(resources).filter(\n (e): e is D1StateEntry => e.type === \"d1_database\",\n );\n\n for (const entry of d1Entries) {\n if (!owned.has(entry.logicalName)) continue;\n if (entry.preserveOnDestroy) {\n console.log(\n `Skipping D1 destroy for ${entry.derivedName} (preserveOnDestroy / cross-stack binding).`,\n );\n continue;\n }\n try {\n await api.d1Delete(entry.cfId);\n state.delete(entry.derivedName);\n } catch (err) {\n console.warn(`Failed to delete D1 ${entry.derivedName}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { D1ResourceConfig, D1StateEntry } from \"./d1.types.js\";\nimport {\n d1CloudflareDatabaseName,\n d1SkipsProvisionAndMigrate,\n} from \"./d1.ownership.js\";\nimport type { WranglerD1Database } from \"../../generated/wrangler-types.js\";\nimport type { StateEntry } from \"../../types.js\";\n\nexport interface D1StateLike {\n get(derivedName: string): StateEntry | undefined;\n getAll(): Record<string, StateEntry>;\n}\n\nexport function d1Generate(\n resources: D1ResourceConfig[],\n env: string,\n state: D1StateLike,\n naming: NamingEngine\n): WranglerD1Database[] {\n const bindings: WranglerD1Database[] = [];\n\n for (const config of resources) {\n if (config.type === \"single\") {\n const derivedName = d1CloudflareDatabaseName(config, env, naming);\n const entry = state.get(derivedName);\n if (!entry || entry.type !== \"d1_database\") {\n if (d1SkipsProvisionAndMigrate(config)) {\n throw new Error(\n `Cross-stack D1 \"${config.logicalName}\" (${derivedName}) not in state. ` +\n `Deploy the owning stack first, then re-run from this stack ` +\n `(apply now syncs automatically for env \"${env}\").`,\n );\n }\n throw new Error(\n `D1 \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`\n );\n }\n bindings.push({\n binding: entry.bindingKey,\n database_id: entry.cfId,\n database_name: derivedName,\n migrations_dir: config.migrationsDir,\n migrations_table: config.migrationsTable,\n });\n continue;\n }\n\n const allResources = state.getAll();\n const shards = Object.values(allResources).filter(\n (e): e is D1StateEntry =>\n e.type === \"d1_database\" && e.logicalName === config.logicalName\n );\n\n for (const shard of shards) {\n bindings.push({\n binding: shard.bindingKey,\n database_id: shard.cfId,\n database_name: shard.derivedName,\n migrations_dir: config.migrationsDir,\n migrations_table: config.migrationsTable,\n });\n }\n }\n\n return bindings;\n}\n","import type { ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { D1ResourceConfig, D1StateEntry } from \"./d1.types.js\";\nimport { d1CloudflareDatabaseName } from \"./d1.ownership.js\";\nimport { d1DeriveBindingKey } from \"./d1.naming.js\";\n\nexport interface D1StatusResult {\n binding: string;\n name: string;\n cfId: string;\n status: ResourceStatus;\n}\n\nexport function d1Status(\n resources: D1ResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine\n): D1StatusResult[] {\n const results: D1StatusResult[] = [];\n\n for (const config of resources) {\n if (config.type === \"single\") {\n const derivedName = d1CloudflareDatabaseName(config, env, naming);\n const entry = state.get(derivedName) as D1StateEntry | undefined;\n results.push({\n binding: d1DeriveBindingKey(config, undefined, naming),\n name: derivedName,\n cfId: entry?.cfId ?? \"\",\n status: entry ? \"ok\" : \"missing\",\n });\n continue;\n }\n\n const allResources = state.getAll();\n const shards = Object.values(allResources).filter(\n (e): e is D1StateEntry =>\n e.type === \"d1_database\" && e.logicalName === config.logicalName\n );\n\n for (const shard of shards) {\n results.push({\n binding: shard.bindingKey,\n name: shard.derivedName,\n cfId: shard.cfId,\n status: \"ok\",\n });\n }\n\n if (shards.length === 0) {\n const placeholderDate = config.shardDate ?? \"00000000\";\n results.push({\n binding: d1DeriveBindingKey(config, placeholderDate, naming),\n name: `(no shards for ${config.logicalName})`,\n cfId: \"\",\n status: \"missing\",\n });\n }\n }\n\n return results;\n}\n","import type { WorkerConfig, WorkerResources } from \"../../types.js\";\n\n/**\n * Helper used by every {@link ResourceModule.pickResources} so module files\n * can accept either a full `WorkerConfig` (the common path from `apply`,\n * `sync`, `drift`, `status`) or a bare `WorkerResources` (the wrangler\n * generator passes `resolved.resources` directly). Returns `undefined`\n * when no resource map is present.\n */\nexport function resourcesFrom(\n source: WorkerConfig | WorkerResources | undefined,\n): WorkerResources | undefined {\n if (!source) return undefined;\n if (\"resources\" in source) {\n return (source as WorkerConfig).resources;\n }\n return source as WorkerResources;\n}\n","import type { CfiConfig, WorkerResources } from \"../../types.js\";\nimport { getWorkers } from \"../config/loader.js\";\n\n/**\n * Find the first declared resource config matching `logical` across all workers.\n * Used by `tamer import` to validate CF names against {@link cloudflareName} overrides.\n */\nexport async function findWorkerResourceByLogicalName<\n C extends { logicalName: string },\n>(\n config: CfiConfig,\n configKey: keyof WorkerResources,\n logical: string,\n baseDir?: string,\n): Promise<C | undefined> {\n const workers = await getWorkers(config, baseDir);\n for (const [, wc] of workers) {\n const list = wc.resources?.[configKey] as C[] | undefined;\n if (!list) continue;\n const hit = list.find((r) => r.logicalName === logical);\n if (hit) return hit;\n }\n return undefined;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { D1ResourceConfig } from \"./d1.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n D1StateEntry,\n} from \"../../types.js\";\nimport { d1Apply } from \"./d1.apply.js\";\nimport { d1Sync } from \"./d1.sync.js\";\nimport { d1Drift } from \"./d1.drift.js\";\nimport { d1Destroy } from \"./d1.destroy.js\";\nimport { d1Generate } from \"./d1.generate.js\";\nimport { d1Status } from \"./d1.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { d1DeriveName, d1DeriveBindingKey, normalizeShardDateIso } from \"./d1.naming.js\";\n\ninterface CFD1 {\n uuid: string;\n name: string;\n created_at: string;\n}\n\nexport const d1Module: ResourceModule<D1ResourceConfig, CFD1> = {\n kind: \"d1\",\n label: \"D1\",\n configKey: \"d1\",\n stateEntryType: \"d1_database\",\n\n async fetchAll(api: CFApiClient): Promise<CFD1[]> {\n return api.d1ListAll();\n },\n\n async apply(ctx) {\n await d1Apply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n ctx.addShard,\n );\n },\n\n sync(ctx) {\n d1Sync(ctx.all, ctx.resources, ctx.tenant, ctx.env, ctx.state, ctx.naming);\n },\n\n drift(ctx) {\n return d1Drift(ctx.all, ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n async destroy(ctx) {\n await d1Destroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return d1Status(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n if (ctx.resources.length === 0) return {};\n const generated = d1Generate(ctx.resources, ctx.env, ctx.state, ctx.naming);\n const passthrough = ctx.passthrough?.d1_databases ?? [];\n return { d1_databases: [...passthrough, ...generated] };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): D1ResourceConfig[] {\n return resourcesFrom(source)?.d1 ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"d1_database\") return;\n try {\n await api.d1Delete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(`Rollback: failed to delete D1 ${entry.derivedName}:`, err);\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n if (!options.cfId) throw new Error(\"import d1: --cf-id <uuid> is required\");\n const resourceConfig = await findWorkerResourceByLogicalName<D1ResourceConfig>(\n config,\n \"d1\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import d1: no resources.d1 entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.d1ListAll();\n const hit = all.find((d) => d.uuid === options.cfId);\n if (!hit) {\n throw new Error(\n `import d1: D1 database with uuid \"${options.cfId}\" not found in account`,\n );\n }\n const shardDateIso = options.shardDate\n ? normalizeShardDateIso(options.shardDate)\n : resourceConfig.shardDate\n ? normalizeShardDateIso(resourceConfig.shardDate)\n : undefined;\n const derivedName = shardDateIso\n ? d1DeriveName(resourceConfig, env, shardDateIso, naming)\n : d1DeriveName(resourceConfig, env, undefined, naming);\n if (hit.name !== derivedName) {\n throw new Error(\n `import d1: cf name \"${hit.name}\" does not match derived \"${derivedName}\" — wrong --logical, missing --shard-date, or naming convention drift?`,\n );\n }\n const bindingKey = d1DeriveBindingKey(\n resourceConfig,\n shardDateIso,\n naming,\n );\n const existing = state.get(derivedName);\n if (\n existing &&\n existing.type === \"d1_database\" &&\n existing.cfId !== options.cfId\n ) {\n throw new Error(\n `import d1: state already tracks \"${derivedName}\" with a different cfId`,\n );\n }\n const entry: D1StateEntry = {\n type: \"d1_database\",\n logicalName: options.logical,\n shardDate: shardDateIso ?? options.shardDate,\n derivedName,\n bindingKey,\n cfId: options.cfId,\n createdAt: existing?.type === \"d1_database\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(derivedName, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveR2CloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { R2ResourceConfig } from \"./r2.types.js\";\n\nexport function r2DeriveName(\n config: R2ResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveR2CloudflareName(config, env, naming);\n}\n\nexport function r2MatchPattern(\n config: R2ResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n if (config.cloudflareName) {\n const expected = resolveR2CloudflareName(config, env, naming);\n return (name: string) => name === expected;\n }\n return naming.r2MatchPattern(config.logicalName, env);\n}\n\nexport function r2ExtractDate(name: string, naming: NamingEngine): string | null {\n return naming.extractR2Date(name);\n}\n","import type { TenantMeta, R2StateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { R2ResourceConfig } from \"./r2.types.js\";\nimport { r2DeriveName } from \"./r2.naming.js\";\n\nfunction existingR2ForLogical(\n state: StateManager,\n logicalName: string,\n): R2StateEntry | undefined {\n for (const e of Object.values(state.getAll())) {\n if (e.type === \"r2_bucket\" && e.logicalName === logicalName) {\n return e;\n }\n }\n return undefined;\n}\n\nfunction todayIso(): string {\n return new Date().toISOString().slice(0, 10);\n}\n\n// https://developers.cloudflare.com/r2/buckets/create-buckets/#bucket-level-operations\nfunction assertValidR2BucketName(name: string, logicalName: string): void {\n const errors: string[] = [];\n if (name.length < 3 || name.length > 63) {\n errors.push(`length must be 3-63 chars (got ${name.length})`);\n }\n if (!/^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(name)) {\n errors.push(\n \"must contain only lowercase letters, numbers, and hyphens, and start/end with a letter or number\",\n );\n }\n if (/--/.test(name)) {\n errors.push(\"must not contain consecutive hyphens\");\n }\n if (errors.length > 0) {\n throw new Error(\n `Invalid R2 bucket name \"${name}\" (derived for logical resource \"${logicalName}\"): ${errors.join(\"; \")}. ` +\n `Adjust your naming.r2Bucket hook (e.g., replace underscores with hyphens and lowercase the result).`,\n );\n }\n}\n\nexport async function r2Apply(\n resources: R2ResourceConfig[],\n tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = r2DeriveName(config, env, naming);\n const existing = state.get(derivedName);\n if (existing) {\n console.log(\n `R2: skip \"${derivedName}\" (already in state; logical \"${config.logicalName}\")`,\n );\n continue;\n }\n const prior = existingR2ForLogical(state, config.logicalName);\n if (prior) {\n console.log(\n `R2: skip \"${derivedName}\" (logical \"${config.logicalName}\" already in state as \"${prior.derivedName}\")`,\n );\n continue;\n }\n\n assertValidR2BucketName(derivedName, config.logicalName);\n await api.r2Create(derivedName);\n console.log(\n `R2: created \"${derivedName}\" (logical \"${config.logicalName}\")`,\n );\n state.set(derivedName, {\n type: \"r2_bucket\",\n logicalName: config.logicalName,\n createdDate: todayIso(),\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.r2BindingKey(config.logicalName),\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { R2ResourceConfig } from \"./r2.types.js\";\nimport { r2ExtractDate, r2MatchPattern } from \"./r2.naming.js\";\n\ninterface CFR2Bucket {\n name: string;\n creation_date: string;\n}\n\nexport function r2Sync(\n allR2: CFR2Bucket[],\n resources: R2ResourceConfig[],\n tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine\n): void {\n for (const config of resources) {\n const pattern = r2MatchPattern(config, env, naming);\n const match = allR2.find((b) => pattern(b.name));\n if (match) {\n const createdDate = r2ExtractDate(match.name, naming) ?? match.creation_date.slice(0, 10);\n const prev = state.get(match.name);\n state.set(match.name, {\n type: \"r2_bucket\",\n logicalName: config.logicalName,\n createdDate,\n derivedName: match.name,\n bindingKey:\n config.binding?.trim() ||\n (prev?.type === \"r2_bucket\" && prev.bindingKey\n ? prev.bindingKey\n : naming.r2BindingKey(config.logicalName)),\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { R2ResourceConfig, R2StateEntry } from \"./r2.types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { r2MatchPattern } from \"./r2.naming.js\";\n\ninterface CFR2Bucket {\n name: string;\n}\n\n/**\n * Diff R2 state against the Cloudflare list and the current config.\n *\n * R2 buckets carry a date stamp, so each declared resource matches at most one\n * bucket (the one whose name matches the logical-name pattern).\n */\nexport function r2Drift(\n allR2: CFR2Bucket[],\n resources: R2ResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"r2\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfNames = new Set(allR2.map((b) => b.name));\n const allState = state.getAll();\n const r2State = Object.values(allState).filter(\n (e): e is R2StateEntry => e.type === \"r2_bucket\",\n );\n\n for (const config of resources) {\n const pattern = r2MatchPattern(config, env, naming);\n const cfMatch = allR2.find((b) => pattern(b.name));\n const stateEntry = r2State.find(\n (e) => e.logicalName === config.logicalName,\n );\n\n if (stateEntry && !cfNames.has(stateEntry.derivedName)) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n });\n continue;\n }\n if (cfMatch && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName: cfMatch.name,\n });\n continue;\n }\n if (!cfMatch && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName: `(no bucket for ${config.logicalName})`,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\nimport type { R2StateEntry } from \"./r2.types.js\";\nimport {\n emptyR2BucketViaS3,\n r2S3CredentialsFromEnv,\n} from \"./r2S3EmptyBucket.js\";\n\nexport async function r2Destroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"r2\");\n const resources = state.getAll();\n const r2Entries = Object.values(resources).filter(\n (e): e is R2StateEntry => e.type === \"r2_bucket\",\n );\n const accountId = api.getAccountId();\n const s3creds = r2S3CredentialsFromEnv();\n\n for (const entry of r2Entries) {\n if (!owned.has(entry.logicalName)) continue;\n const name = entry.derivedName;\n if (s3creds) {\n try {\n console.log(\n `R2: emptying bucket \"${name}\" via S3 API (incomplete multipart uploads, then objects)…`,\n );\n const { uploadsAborted, objectsDeleted } = await emptyR2BucketViaS3(\n accountId,\n name,\n s3creds,\n );\n console.log(\n `R2: bucket \"${name}\" — aborted ${uploadsAborted} multipart upload(s), deleted ${objectsDeleted} object(s).`,\n );\n } catch (err) {\n console.warn(\n `R2: S3 empty failed for \"${name}\" (fix credentials or use the dashboard; still attempting API bucket delete):`,\n err instanceof Error ? err.message : err,\n );\n }\n } else {\n console.warn(\n `R2: skipping S3 empty for \"${name}\" (set R2_ACCESS_KEY_ID and R2_SECRET_ACCESS_KEY to remove all objects and incomplete multipart uploads before bucket delete). ` +\n `Create an R2 API token in the dashboard (R2 → Manage R2 API Tokens) with object read+write; those keys are not the same as CLOUDFLARE_API_TOKEN.`,\n );\n }\n try {\n await api.r2Delete(name);\n state.delete(name);\n } catch (err) {\n console.warn(`Failed to delete R2 ${name}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { R2ResourceConfig, R2StateEntry } from \"./r2.types.js\";\nimport type { WranglerR2Bucket } from \"../../generated/wrangler-types.js\";\nimport type { StateEntry } from \"../../types.js\";\n\nexport interface R2StateLike {\n get(derivedName: string): StateEntry | undefined;\n getAll(): Record<string, StateEntry>;\n}\n\nexport function r2Generate(\n resources: R2ResourceConfig[],\n env: string,\n state: R2StateLike,\n naming: NamingEngine\n): WranglerR2Bucket[] {\n const bindings: WranglerR2Bucket[] = [];\n\n for (const config of resources) {\n const allResources = state.getAll();\n const entry = Object.values(allResources).find(\n (e): e is R2StateEntry =>\n e.type === \"r2_bucket\" && e.logicalName === config.logicalName,\n );\n\n if (!entry) {\n throw new Error(\n `R2 \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`\n );\n }\n\n bindings.push({\n binding: entry.bindingKey,\n bucket_name: entry.derivedName,\n });\n }\n\n return bindings;\n}\n","import type { ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { R2ResourceConfig, R2StateEntry } from \"./r2.types.js\";\nimport { r2DeriveName } from \"./r2.naming.js\";\n\nexport interface R2StatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function r2Status(\n resources: R2ResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine\n): R2StatusResult[] {\n const results: R2StatusResult[] = [];\n\n for (const config of resources) {\n const allResources = state.getAll();\n const entry = Object.values(allResources).find(\n (e): e is R2StateEntry =>\n e.type === \"r2_bucket\" && e.logicalName === config.logicalName\n );\n\n results.push({\n binding: entry?.bindingKey ?? naming.r2BindingKey(config.logicalName),\n name: entry?.derivedName ?? r2DeriveName(config, env, naming),\n status: entry ? \"ok\" : \"missing\",\n });\n }\n\n return results;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { R2ResourceConfig } from \"./r2.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n R2StateEntry,\n} from \"../../types.js\";\nimport { r2Apply } from \"./r2.apply.js\";\nimport { r2Sync } from \"./r2.sync.js\";\nimport { r2Drift } from \"./r2.drift.js\";\nimport { r2Destroy } from \"./r2.destroy.js\";\nimport { r2Generate } from \"./r2.generate.js\";\nimport { r2Status } from \"./r2.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { r2MatchPattern } from \"./r2.naming.js\";\n\ninterface CFR2 {\n name: string;\n creation_date: string;\n}\n\nexport const r2Module: ResourceModule<R2ResourceConfig, CFR2> = {\n kind: \"r2\",\n label: \"R2\",\n configKey: \"r2\",\n stateEntryType: \"r2_bucket\",\n\n async fetchAll(api: CFApiClient): Promise<CFR2[]> {\n return api.r2ListAll();\n },\n\n async apply(ctx) {\n await r2Apply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n r2Sync(ctx.all, ctx.resources, ctx.tenant, ctx.env, ctx.state, ctx.naming);\n },\n\n drift(ctx) {\n return r2Drift(ctx.all, ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n async destroy(ctx) {\n await r2Destroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return r2Status(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n if (ctx.resources.length === 0) return {};\n return {\n r2_buckets: r2Generate(ctx.resources, ctx.env, ctx.state, ctx.naming),\n };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): R2ResourceConfig[] {\n return resourcesFrom(source)?.r2 ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"r2_bucket\") return;\n try {\n await api.r2Delete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(`Rollback: failed to delete R2 ${entry.derivedName}:`, err);\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const bucketName = options.cfId;\n if (!bucketName) {\n throw new Error(\"import r2: --cf-id <bucket-name> is required\");\n }\n const resourceConfig = await findWorkerResourceByLogicalName<R2ResourceConfig>(\n config,\n \"r2\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import r2: no resources.r2 entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.r2ListAll();\n const hit = all.find((b) => b.name === bucketName);\n if (!hit) {\n throw new Error(`import r2: bucket \"${bucketName}\" not found in account`);\n }\n const pattern = r2MatchPattern(resourceConfig, env, naming);\n if (!pattern(hit.name)) {\n throw new Error(\n `import r2: bucket name \"${hit.name}\" does not match expected pattern for logical \"${options.logical}\" and env \"${env}\"`,\n );\n }\n const derivedName = hit.name;\n const createdDate =\n options.createdDate ??\n naming.extractR2Date(hit.name) ??\n hit.creation_date.slice(0, 10);\n const bindingKey = naming.r2BindingKey(options.logical);\n const existing = state.get(derivedName);\n const entry: R2StateEntry = {\n type: \"r2_bucket\",\n logicalName: options.logical,\n derivedName,\n bindingKey,\n createdDate,\n createdAt: existing?.type === \"r2_bucket\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(derivedName, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveKVCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { KVResourceConfig } from \"../../types.js\";\n\nexport function kvDeriveName(\n config: KVResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveKVCloudflareName(config, env, naming);\n}\n\nexport function kvMatchPattern(\n config: KVResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveKVCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\nexport async function kvApply(\n resources: KVResourceConfig[],\n tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine\n): Promise<void> {\n for (const config of resources) {\n const derivedName = kvDeriveName(config, env, naming);\n const existing = state.get(derivedName);\n if (existing) continue;\n\n const { id } = await api.kvCreate(derivedName);\n state.set(derivedName, {\n type: \"kv_namespace\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.kvBindingKey(config.logicalName),\n cfId: id,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\ninterface CFKVNamespace {\n id: string;\n title: string;\n}\n\nexport function kvSync(\n allKV: CFKVNamespace[],\n resources: KVResourceConfig[],\n tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine\n): void {\n for (const config of resources) {\n const derivedName = kvDeriveName(config, env, naming);\n const match = allKV.find((ns) => ns.title === derivedName);\n if (match) {\n state.set(derivedName, {\n type: \"kv_namespace\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.kvBindingKey(config.logicalName),\n cfId: match.id,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport type { KVStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\ninterface CFKVNamespace {\n id: string;\n title: string;\n}\n\nexport function kvDrift(\n allKV: CFKVNamespace[],\n resources: KVResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"kv\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByTitle = new Map(allKV.map((ns) => [ns.title, ns.id]));\n const allState = state.getAll();\n const kvState = Object.values(allState).filter(\n (e): e is KVStateEntry => e.type === \"kv_namespace\",\n );\n\n for (const config of resources) {\n const derivedName = kvDeriveName(config, env, naming);\n const cfId = cfByTitle.get(derivedName);\n const stateEntry = kvState.find(\n (e) => e.logicalName === config.logicalName,\n );\n\n if (stateEntry && !cfId) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (cfId && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId,\n });\n } else if (!cfId && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, KVStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function kvDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"kv\");\n const resources = state.getAll();\n const kvEntries = Object.values(resources).filter(\n (e): e is KVStateEntry => e.type === \"kv_namespace\"\n );\n\n for (const entry of kvEntries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.kvDelete(entry.cfId);\n state.delete(entry.derivedName);\n } catch (err) {\n console.warn(`Failed to delete KV ${entry.derivedName}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport type { KVStateEntry } from \"../../types.js\";\nimport type { WranglerKVNamespace } from \"../../generated/wrangler-types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\nexport interface KVStateLike {\n get(derivedName: string): StateEntry | undefined;\n getAll(): Record<string, StateEntry>;\n}\n\nexport function kvGenerate(\n resources: KVResourceConfig[],\n env: string,\n state: KVStateLike,\n naming: NamingEngine\n): WranglerKVNamespace[] {\n const bindings: WranglerKVNamespace[] = [];\n\n for (const config of resources) {\n const derivedName = kvDeriveName(config, env, naming);\n const entry = state.get(derivedName);\n if (!entry || entry.type !== \"kv_namespace\") {\n throw new Error(\n `KV \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`\n );\n }\n\n bindings.push({\n binding: entry.bindingKey,\n id: entry.cfId,\n });\n }\n\n return bindings;\n}\n","import type { ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport type { KVStateEntry } from \"../../types.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\nexport interface KVStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function kvStatus(\n resources: KVResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine\n): KVStatusResult[] {\n const results: KVStatusResult[] = [];\n\n for (const config of resources) {\n const derivedName = kvDeriveName(config, env, naming);\n const entry = state.get(derivedName) as KVStateEntry | undefined;\n\n results.push({\n binding: naming.kvBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n\n return results;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n KVStateEntry,\n} from \"../../types.js\";\nimport { kvApply } from \"./kv.apply.js\";\nimport { kvSync } from \"./kv.sync.js\";\nimport { kvDrift } from \"./kv.drift.js\";\nimport { kvDestroy } from \"./kv.destroy.js\";\nimport { kvGenerate } from \"./kv.generate.js\";\nimport { kvStatus } from \"./kv.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\ninterface CFKv {\n id: string;\n title: string;\n}\n\nexport const kvModule: ResourceModule<KVResourceConfig, CFKv> = {\n kind: \"kv\",\n label: \"KV\",\n configKey: \"kv\",\n stateEntryType: \"kv_namespace\",\n\n async fetchAll(api: CFApiClient): Promise<CFKv[]> {\n const all = await api.kvListAll();\n return all.map((k) => ({ id: k.id, title: k.title }));\n },\n\n async apply(ctx) {\n await kvApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n kvSync(ctx.all, ctx.resources, ctx.tenant, ctx.env, ctx.state, ctx.naming);\n },\n\n drift(ctx) {\n return kvDrift(ctx.all, ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n async destroy(ctx) {\n await kvDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return kvStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n if (ctx.resources.length === 0) return {};\n return {\n kv_namespaces: kvGenerate(ctx.resources, ctx.env, ctx.state, ctx.naming),\n };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): KVResourceConfig[] {\n return resourcesFrom(source)?.kv ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"kv_namespace\") return;\n try {\n await api.kvDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(`Rollback: failed to delete KV ${entry.derivedName}:`, err);\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n if (!options.cfId)\n throw new Error(\"import kv: --cf-id <namespace-id> is required\");\n const resourceConfig = await findWorkerResourceByLogicalName<KVResourceConfig>(\n config,\n \"kv\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import kv: no resources.kv entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.kvListAll();\n const hit = all.find((k) => k.id === options.cfId);\n if (!hit) {\n throw new Error(\n `import kv: KV namespace id \"${options.cfId}\" not found in account`,\n );\n }\n const derivedName = kvDeriveName(resourceConfig, env, naming);\n if (hit.title !== derivedName) {\n throw new Error(\n `import kv: cf title \"${hit.title}\" does not match derived \"${derivedName}\"`,\n );\n }\n const bindingKey = naming.kvBindingKey(options.logical);\n const existing = state.get(derivedName);\n const entry: KVStateEntry = {\n type: \"kv_namespace\",\n logicalName: options.logical,\n derivedName,\n bindingKey,\n cfId: options.cfId,\n createdAt: existing?.type === \"kv_namespace\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(derivedName, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveQueueCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { QueueResourceConfig } from \"../../types.js\";\n\nexport function queueDeriveName(\n config: QueueResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveQueueCloudflareName(config, env, naming);\n}\n\nexport function queueMatchPattern(\n config: QueueResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveQueueCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\nconst STATE_KEY_PREFIX = \"queue:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\nexport async function queuesApply(\n resources: QueueResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = queueDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n if (existing) continue;\n\n const ts = new Date().toISOString();\n const { queue_id } = await api.queueCreate(derivedName);\n state.set(key, {\n type: \"queue\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.queueBindingKey(config.logicalName),\n cfId: queue_id,\n producerBinding: !config.consumerOnly,\n createdAt: ts,\n updatedAt: ts,\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\ninterface CFQueue {\n queue_id: string;\n queue_name: string;\n}\n\nexport function queuesSync(\n allQueues: CFQueue[],\n resources: QueueResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = queueDeriveName(config, env, naming);\n const match = allQueues.find((q) => q.queue_name === derivedName);\n if (!match) continue;\n const key = `queue:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n state.set(key, {\n type: \"queue\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.queueBindingKey(config.logicalName),\n cfId: match.queue_id,\n producerBinding: !config.consumerOnly,\n createdAt: existing?.type === \"queue\" ? existing.createdAt : ts,\n updatedAt: ts,\n });\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport type { QueueStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\ninterface CFQueue {\n queue_id: string;\n queue_name: string;\n}\n\nexport function queuesDrift(\n allQueues: CFQueue[],\n resources: QueueResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"queue\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allQueues.map((q) => [q.queue_name, q.queue_id]));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is QueueStateEntry => e.type === \"queue\",\n );\n\n for (const config of resources) {\n const derivedName = queueDeriveName(config, env, naming);\n const cfId = cfByName.get(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !cfId) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (cfId && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId,\n });\n } else if (!cfId && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, QueueStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function queuesDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"queue\");\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, QueueStateEntry] => kv[1].type === \"queue\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.queueDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(`Failed to delete queue ${entry.derivedName}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\nexport interface QueuesStateLike {\n get(key: string): StateEntry | undefined;\n getAll(): Record<string, StateEntry>;\n}\n\nexport interface GeneratedQueues {\n producers?: Array<{ binding: string; queue: string }>;\n}\n\n/**\n * Emit `queues.producers[]` for every declared queue (skips entries marked\n * `consumerOnly`). Consumers stay wrangler-side and can be set on the worker\n * config under `queues.consumers` (passed through unchanged).\n */\nexport function queuesGenerate(\n resources: QueueResourceConfig[],\n env: string,\n state: QueuesStateLike,\n naming: NamingEngine,\n): GeneratedQueues | undefined {\n const producers: Array<{ binding: string; queue: string }> = [];\n\n for (const config of resources) {\n if (config.consumerOnly) continue;\n const derivedName = queueDeriveName(config, env, naming);\n const entry = state.get(`queue:${derivedName}`);\n if (!entry || entry.type !== \"queue\") {\n throw new Error(\n `Queue \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`,\n );\n }\n producers.push({\n binding: entry.bindingKey,\n queue: entry.derivedName,\n });\n }\n\n if (producers.length === 0) return undefined;\n return { producers };\n}\n","import type { ResourceStatus, QueueStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\nexport interface QueuesStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function queuesStatus(\n resources: QueueResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): QueuesStatusResult[] {\n const out: QueuesStatusResult[] = [];\n for (const config of resources) {\n const derivedName = queueDeriveName(config, env, naming);\n const entry = state.get(`queue:${derivedName}`) as\n | QueueStateEntry\n | undefined;\n out.push({\n binding:\n config.binding?.trim() || naming.queueBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n QueueStateEntry,\n} from \"../../types.js\";\nimport { queuesApply } from \"./queues.apply.js\";\nimport { queuesSync } from \"./queues.sync.js\";\nimport { queuesDrift } from \"./queues.drift.js\";\nimport { queuesDestroy } from \"./queues.destroy.js\";\nimport { queuesGenerate } from \"./queues.generate.js\";\nimport { queuesStatus } from \"./queues.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\ninterface CFQueue {\n queue_id: string;\n queue_name: string;\n}\n\nexport const queuesModule: ResourceModule<QueueResourceConfig, CFQueue> = {\n kind: \"queue\",\n label: \"Queues\",\n configKey: \"queues\",\n stateEntryType: \"queue\",\n\n async fetchAll(api: CFApiClient): Promise<CFQueue[]> {\n const all = await api.queuesListAll();\n return all.map((q) => ({ queue_id: q.queue_id, queue_name: q.queue_name }));\n },\n\n async apply(ctx) {\n await queuesApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n queuesSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return queuesDrift(ctx.all, ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n async destroy(ctx) {\n await queuesDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return queuesStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n const generated =\n ctx.resources.length > 0\n ? queuesGenerate(ctx.resources, ctx.env, ctx.state, ctx.naming)\n : undefined;\n const passthrough = ctx.passthrough?.queues;\n if (!generated && !passthrough) return {};\n const producers = [\n ...(passthrough?.producers ?? []),\n ...(generated?.producers ?? []),\n ];\n const consumers = passthrough?.consumers ?? [];\n if (producers.length === 0 && consumers.length === 0) return {};\n const out: NonNullable<\n import(\"../../generated/wrangler-types.js\").WranglerConfig[\"queues\"]\n > = {};\n if (producers.length > 0) out.producers = producers;\n if (consumers.length > 0) out.consumers = consumers;\n return { queues: out };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): QueueResourceConfig[] {\n return resourcesFrom(source)?.queues ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"queue\") return;\n try {\n await api.queueDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete queue ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n if (!options.cfId) {\n throw new Error(\"import queue: --cf-id <queue-id> is required\");\n }\n const resourceConfig =\n await findWorkerResourceByLogicalName<QueueResourceConfig>(\n config,\n \"queues\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import queue: no resources.queues entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.queuesListAll();\n const hit = all.find((q) => q.queue_id === options.cfId);\n if (!hit) {\n throw new Error(\n `import queue: queue id \"${options.cfId}\" not found in account`,\n );\n }\n const derivedName = queueDeriveName(resourceConfig, env, naming);\n if (hit.queue_name !== derivedName) {\n throw new Error(\n `import queue: cf name \"${hit.queue_name}\" does not match derived \"${derivedName}\"`,\n );\n }\n const bindingKey = naming.queueBindingKey(options.logical);\n const key = `queue:${derivedName}`;\n const existing = state.get(key);\n const entry: QueueStateEntry = {\n type: \"queue\",\n logicalName: options.logical,\n derivedName,\n bindingKey,\n cfId: options.cfId,\n producerBinding: existing?.type === \"queue\" ? existing.producerBinding : true,\n createdAt: existing?.type === \"queue\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { HyperdriveResourceConfig } from \"../../types.js\";\n\n/**\n * Resolve a value that is either a literal string or `{ fromEnv: \"VAR\" }`\n * lookup against `process.env`. Throws a clear error when the env var is\n * missing — these values are sent to Cloudflare on create and never\n * persisted in Tamer state.\n */\nexport function resolveSecret(\n value: string | { fromEnv: string },\n label: string,\n): string {\n if (typeof value === \"string\") return value;\n const envName = value.fromEnv;\n const v = process.env[envName];\n if (!v) {\n throw new Error(\n `hyperdrive: ${label} requires env var ${envName} (set it before running 'tamer apply')`,\n );\n }\n return v;\n}\n\nexport interface ResolvedHyperdriveOrigin {\n scheme: string;\n host: string;\n port?: number;\n database: string;\n user: string;\n password: string;\n access_client_id?: string;\n access_client_secret?: string;\n}\n\nexport function resolveHyperdriveOrigin(\n config: HyperdriveResourceConfig,\n): ResolvedHyperdriveOrigin {\n const o = config.origin;\n return {\n scheme: o.scheme,\n host: o.host,\n port: o.port,\n database: o.database,\n user: o.user,\n password: resolveSecret(o.password, `${config.logicalName}.origin.password`),\n access_client_id: o.access_client_id,\n access_client_secret: o.access_client_secret\n ? resolveSecret(\n o.access_client_secret,\n `${config.logicalName}.origin.access_client_secret`,\n )\n : undefined,\n };\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveHyperdriveCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { HyperdriveResourceConfig } from \"../../types.js\";\n\nexport function hyperdriveDeriveName(\n config: HyperdriveResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveHyperdriveCloudflareName(config, env, naming);\n}\n\nexport function hyperdriveMatchPattern(\n config: HyperdriveResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveHyperdriveCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","/**\n * Plan-time field-level diff for declared Hyperdrive configurations.\n * Mirrors the PATCH path in {@link hyperdriveApply}: Cloudflare's\n * `PATCH /accounts/{id}/hyperdrive/configs/{id}` accepts in-place edits\n * to `origin` (host / database / scheme / user / port / password) so any\n * drift on the **state-tracked** origin metadata (`scheme`, `originHost`,\n * `originDatabase`) becomes an `update` action — Tamer never destroys\n * and recreates a Hyperdrive config.\n *\n * Origin password is intentionally **not** in state (write-only on\n * Cloudflare's side, never returned), so it cannot be diffed; users who\n * rotate via `{ fromEnv: \"DATABASE_PASSWORD\" }` should run `tamer apply`\n * which always re-sends the resolved origin payload.\n *\n * Resources without a state row are reported by `hyperdriveDrift` as\n * `undeployed` and become `create` items.\n */\n\nimport type {\n HyperdriveResourceConfig,\n HyperdriveStateEntry,\n} from \"../../types.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { PlanFieldChange, PlanItem } from \"../../core/plan/plan.types.js\";\n\nexport function hyperdriveDiffPlanItems(args: {\n resources: HyperdriveResourceConfig[];\n env: string;\n state: StateManager;\n naming: NamingEngine;\n}): PlanItem[] {\n const { resources, env, state, naming } = args;\n const items: PlanItem[] = [];\n\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const entry = state.get(`hyperdrive:${derivedName}`);\n if (!entry || entry.type !== \"hyperdrive\") continue;\n\n const changes = computeChanges(entry as HyperdriveStateEntry, config);\n if (changes.length === 0) continue;\n items.push({\n kind: \"hyperdrive\",\n action: \"update\",\n logicalName: config.logicalName,\n derivedName,\n detail: changes\n .map((c) => `${c.field}: ${formatVal(c.from)} -> ${formatVal(c.to)}`)\n .join(\", \"),\n changes,\n });\n }\n\n return items;\n}\n\n/**\n * Pure comparison shared with `hyperdriveApply` so plan and apply agree\n * on what counts as drift on the origin fields Tamer persists.\n */\nexport function computeHyperdriveChanges(\n state: HyperdriveStateEntry,\n config: HyperdriveResourceConfig,\n): PlanFieldChange[] {\n return computeChanges(state, config);\n}\n\nfunction computeChanges(\n state: HyperdriveStateEntry,\n config: HyperdriveResourceConfig,\n): PlanFieldChange[] {\n const changes: PlanFieldChange[] = [];\n if (state.scheme !== config.origin.scheme) {\n changes.push({\n field: \"origin.scheme\",\n from: state.scheme,\n to: config.origin.scheme,\n kind: \"mutable\",\n });\n }\n if (state.originHost !== config.origin.host) {\n changes.push({\n field: \"origin.host\",\n from: state.originHost,\n to: config.origin.host,\n kind: \"mutable\",\n });\n }\n if (state.originDatabase !== config.origin.database) {\n changes.push({\n field: \"origin.database\",\n from: state.originDatabase,\n to: config.origin.database,\n kind: \"mutable\",\n });\n }\n return changes;\n}\n\nfunction formatVal(v: unknown): string {\n if (v === undefined) return \"(unset)\";\n if (typeof v === \"string\") return v.length > 32 ? `${v.slice(0, 29)}...` : v;\n return String(v);\n}\n","import type { HyperdriveStateEntry, TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport { resolveHyperdriveOrigin } from \"./hyperdrive.secrets.js\";\nimport { computeHyperdriveChanges } from \"./hyperdrive.diff.js\";\nimport { logApplyChange } from \"../../core/plan/planFormat.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\nconst STATE_KEY_PREFIX = \"hyperdrive:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\nexport async function hyperdriveApply(\n resources: HyperdriveResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n const ts = new Date().toISOString();\n\n if (existing && existing.type === \"hyperdrive\") {\n const stateEntry = existing as HyperdriveStateEntry;\n const changes = computeHyperdriveChanges(stateEntry, config);\n if (changes.length === 0) continue;\n logApplyChange({\n kind: \"hyperdrive\",\n action: \"update\",\n logical: config.logicalName,\n derived: derivedName,\n changes,\n });\n // Cloudflare's PATCH treats `origin` as a unit (password is\n // write-only and never echoed back). Re-resolve the full origin\n // from config — this also re-reads `{ fromEnv: ... }` secrets so\n // password rotation flows through naturally.\n const origin = resolveHyperdriveOrigin(config);\n await api.hyperdrivePatch(stateEntry.cfId, { origin });\n state.set(key, {\n ...stateEntry,\n scheme: config.origin.scheme,\n originHost: config.origin.host,\n originDatabase: config.origin.database,\n updatedAt: ts,\n });\n continue;\n }\n\n logApplyChange({\n kind: \"hyperdrive\",\n action: \"create\",\n logical: config.logicalName,\n derived: derivedName,\n });\n const origin = resolveHyperdriveOrigin(config);\n const { id } = await api.hyperdriveCreate({\n name: derivedName,\n origin,\n caching: config.caching,\n mtls: config.mtls,\n });\n state.set(key, {\n type: \"hyperdrive\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() ||\n naming.hyperdriveBindingKey(config.logicalName),\n cfId: id,\n scheme: config.origin.scheme,\n originHost: config.origin.host,\n originDatabase: config.origin.database,\n createdAt: ts,\n updatedAt: ts,\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\ninterface CFHyperdrive {\n id: string;\n name: string;\n origin?: { scheme?: string; host?: string; database?: string };\n}\n\nexport function hyperdriveSync(\n allHyperdrive: CFHyperdrive[],\n resources: HyperdriveResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const match = allHyperdrive.find((h) => h.name === derivedName);\n if (!match) continue;\n const key = `hyperdrive:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n state.set(key, {\n type: \"hyperdrive\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() ||\n naming.hyperdriveBindingKey(config.logicalName),\n cfId: match.id,\n scheme: config.origin.scheme,\n originHost: match.origin?.host ?? config.origin.host,\n originDatabase: match.origin?.database ?? config.origin.database,\n createdAt: existing?.type === \"hyperdrive\" ? existing.createdAt : ts,\n updatedAt: ts,\n });\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport type { HyperdriveStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\ninterface CFHyperdrive {\n id: string;\n name: string;\n}\n\nexport function hyperdriveDrift(\n allHyperdrive: CFHyperdrive[],\n resources: HyperdriveResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"hyperdrive\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allHyperdrive.map((h) => [h.name, h.id]));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is HyperdriveStateEntry => e.type === \"hyperdrive\",\n );\n\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const cfId = cfByName.get(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !cfId) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (cfId && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId,\n });\n } else if (!cfId && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, HyperdriveStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function hyperdriveDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(\n config,\n baseDir,\n \"hyperdrive\",\n );\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, HyperdriveStateEntry] => kv[1].type === \"hyperdrive\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.hyperdriveDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(`Failed to delete hyperdrive ${entry.derivedName}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\nexport interface HyperdriveStateLike {\n get(key: string): StateEntry | undefined;\n getAll(): Record<string, StateEntry>;\n}\n\nexport interface GeneratedHyperdriveBinding {\n binding: string;\n id: string;\n localConnectionString?: string;\n}\n\nexport function hyperdriveGenerate(\n resources: HyperdriveResourceConfig[],\n env: string,\n state: HyperdriveStateLike,\n naming: NamingEngine,\n): GeneratedHyperdriveBinding[] {\n const out: GeneratedHyperdriveBinding[] = [];\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const entry = state.get(`hyperdrive:${derivedName}`);\n if (!entry || entry.type !== \"hyperdrive\") {\n throw new Error(\n `Hyperdrive \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`,\n );\n }\n out.push({\n binding: entry.bindingKey,\n id: entry.cfId,\n localConnectionString: config.localConnectionString,\n });\n }\n return out;\n}\n","import type { ResourceStatus, HyperdriveStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\nexport interface HyperdriveStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function hyperdriveStatus(\n resources: HyperdriveResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): HyperdriveStatusResult[] {\n const out: HyperdriveStatusResult[] = [];\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const entry = state.get(`hyperdrive:${derivedName}`) as\n | HyperdriveStateEntry\n | undefined;\n out.push({\n binding:\n config.binding?.trim() ||\n naming.hyperdriveBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n HyperdriveStateEntry,\n} from \"../../types.js\";\nimport { hyperdriveApply } from \"./hyperdrive.apply.js\";\nimport { hyperdriveSync } from \"./hyperdrive.sync.js\";\nimport { hyperdriveDrift } from \"./hyperdrive.drift.js\";\nimport { hyperdriveDestroy } from \"./hyperdrive.destroy.js\";\nimport { hyperdriveGenerate } from \"./hyperdrive.generate.js\";\nimport { hyperdriveStatus } from \"./hyperdrive.status.js\";\nimport { hyperdriveDiffPlanItems } from \"./hyperdrive.diff.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\ninterface CFHyperdrive {\n id: string;\n name: string;\n origin?: { scheme?: string; host?: string; database?: string };\n}\n\nexport const hyperdriveModule: ResourceModule<\n HyperdriveResourceConfig,\n CFHyperdrive\n> = {\n kind: \"hyperdrive\",\n label: \"Hyperdrive\",\n configKey: \"hyperdrive\",\n stateEntryType: \"hyperdrive\",\n\n async fetchAll(api: CFApiClient): Promise<CFHyperdrive[]> {\n const all = await api.hyperdriveListAll();\n return all.map((h) => ({ id: h.id, name: h.name, origin: h.origin }));\n },\n\n async apply(ctx) {\n await hyperdriveApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n hyperdriveSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return hyperdriveDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n diff(ctx) {\n return hyperdriveDiffPlanItems({\n resources: ctx.resources,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n });\n },\n\n async destroy(ctx) {\n await hyperdriveDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return hyperdriveStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n const generated =\n ctx.resources.length > 0\n ? hyperdriveGenerate(ctx.resources, ctx.env, ctx.state, ctx.naming)\n : [];\n const passthrough = ctx.passthrough?.hyperdrive ?? [];\n if (generated.length === 0 && passthrough.length === 0) return {};\n return { hyperdrive: [...passthrough, ...generated] };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): HyperdriveResourceConfig[] {\n return resourcesFrom(source)?.hyperdrive ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"hyperdrive\") return;\n try {\n await api.hyperdriveDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete Hyperdrive ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n if (!options.cfId) {\n throw new Error(\"import hyperdrive: --cf-id <config-id> is required\");\n }\n const resourceConfig =\n await findWorkerResourceByLogicalName<HyperdriveResourceConfig>(\n config,\n \"hyperdrive\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import hyperdrive: no resources.hyperdrive entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.hyperdriveListAll();\n const hit = all.find((h) => h.id === options.cfId);\n if (!hit) {\n throw new Error(\n `import hyperdrive: config id \"${options.cfId}\" not found in account`,\n );\n }\n const derivedName = hyperdriveDeriveName(resourceConfig, env, naming);\n if (hit.name !== derivedName) {\n throw new Error(\n `import hyperdrive: cf name \"${hit.name}\" does not match derived \"${derivedName}\"`,\n );\n }\n const bindingKey = naming.hyperdriveBindingKey(options.logical);\n const key = `hyperdrive:${derivedName}`;\n const existing = state.get(key);\n const scheme = (\n hit.origin?.scheme === \"mysql\"\n ? \"mysql\"\n : hit.origin?.scheme === \"postgresql\"\n ? \"postgresql\"\n : \"postgres\"\n ) as \"postgres\" | \"postgresql\" | \"mysql\";\n const entry: HyperdriveStateEntry = {\n type: \"hyperdrive\",\n logicalName: options.logical,\n derivedName,\n bindingKey,\n cfId: options.cfId,\n scheme,\n originHost: hit.origin?.host ?? \"\",\n originDatabase: hit.origin?.database ?? \"\",\n createdAt: existing?.type === \"hyperdrive\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveVectorizeCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { VectorizeResourceConfig } from \"../../types.js\";\n\nexport function vectorizeDeriveName(\n config: VectorizeResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveVectorizeCloudflareName(config, env, naming);\n}\n\nexport function vectorizeMatchPattern(\n config: VectorizeResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveVectorizeCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\nconst STATE_KEY_PREFIX = \"vectorize:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\nexport async function vectorizeApply(\n resources: VectorizeResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n if (existing) {\n if (existing.type === \"vectorize\") {\n if (\n existing.dimensions !== config.dimensions ||\n existing.metric !== config.metric\n ) {\n throw new Error(\n `Vectorize index \"${config.logicalName}\" config changed (dimensions/metric are immutable). ` +\n `Run 'tamer destroy --resource ${config.logicalName}' first, then re-apply.`,\n );\n }\n }\n continue;\n }\n\n const ts = new Date().toISOString();\n const created = await api.vectorizeCreate({\n name: derivedName,\n description: config.description,\n config: { dimensions: config.dimensions, metric: config.metric },\n });\n state.set(key, {\n type: \"vectorize\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() ||\n naming.vectorizeBindingKey(config.logicalName),\n cfId: created.id ?? derivedName,\n dimensions: config.dimensions,\n metric: config.metric,\n createdAt: ts,\n updatedAt: ts,\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\ninterface CFVectorize {\n id?: string;\n name: string;\n config?: { dimensions: number; metric: string };\n}\n\nexport function vectorizeSync(\n allIndexes: CFVectorize[],\n resources: VectorizeResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const match = allIndexes.find((i) => i.name === derivedName);\n if (!match) continue;\n const key = `vectorize:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n state.set(key, {\n type: \"vectorize\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() ||\n naming.vectorizeBindingKey(config.logicalName),\n cfId: match.id ?? derivedName,\n dimensions: match.config?.dimensions ?? config.dimensions,\n metric:\n ((match.config?.metric as VectorizeResourceConfig[\"metric\"]) ?? null) ||\n config.metric,\n createdAt: existing?.type === \"vectorize\" ? existing.createdAt : ts,\n updatedAt: ts,\n });\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport type { VectorizeStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\ninterface CFVectorize {\n id?: string;\n name: string;\n}\n\nexport function vectorizeDrift(\n allIndexes: CFVectorize[],\n resources: VectorizeResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"vectorize\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(\n allIndexes.map((i) => [i.name, i.id ?? i.name]),\n );\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is VectorizeStateEntry => e.type === \"vectorize\",\n );\n\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const cfId = cfByName.get(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !cfId) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (cfId && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId,\n });\n } else if (!cfId && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, VectorizeStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function vectorizeDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"vectorize\");\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, VectorizeStateEntry] => kv[1].type === \"vectorize\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.vectorizeDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(`Failed to delete vectorize index ${entry.derivedName}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\nexport interface VectorizeStateLike {\n get(key: string): StateEntry | undefined;\n}\n\nexport interface GeneratedVectorizeBinding {\n binding: string;\n index_name: string;\n}\n\n/**\n * Emit `vectorize[]` bindings for declared indexes. Each binding requires\n * the index to exist in state (i.e. `tamer apply` has run). Throws otherwise\n * so the operator gets an actionable error before `wrangler deploy`.\n */\nexport function vectorizeGenerate(\n resources: VectorizeResourceConfig[],\n env: string,\n state: VectorizeStateLike,\n naming: NamingEngine,\n): GeneratedVectorizeBinding[] {\n const out: GeneratedVectorizeBinding[] = [];\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const entry = state.get(`vectorize:${derivedName}`);\n if (!entry || entry.type !== \"vectorize\") {\n throw new Error(\n `Vectorize index \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`,\n );\n }\n out.push({\n binding: entry.bindingKey,\n index_name: entry.derivedName,\n });\n }\n return out;\n}\n","import type { ResourceStatus, VectorizeStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\nexport interface VectorizeStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function vectorizeStatus(\n resources: VectorizeResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): VectorizeStatusResult[] {\n const out: VectorizeStatusResult[] = [];\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const entry = state.get(`vectorize:${derivedName}`) as\n | VectorizeStateEntry\n | undefined;\n out.push({\n binding:\n config.binding?.trim() ||\n naming.vectorizeBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","/**\n * Plan-time diff for Vectorize indexes. `dimensions` and `metric` are\n * **immutable** per the Vectorize V2 API — Cloudflare rejects PATCH on\n * either field, so any drift surfaces as `replace` (delete + recreate\n * via `tamer destroy --resource <logical>` then `apply`). No `update`\n * action is ever emitted for this kind today.\n */\n\nimport type {\n VectorizeResourceConfig,\n VectorizeStateEntry,\n} from \"../../types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { PlanFieldChange, PlanItem } from \"../../core/plan/plan.types.js\";\n\nexport function vectorizeDiffPlanItems(args: {\n resources: VectorizeResourceConfig[];\n env: string;\n state: StateManager;\n naming: NamingEngine;\n}): PlanItem[] {\n const { resources, env, state, naming } = args;\n const items: PlanItem[] = [];\n\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const key = `vectorize:${derivedName}`;\n const entry = state.get(key);\n if (!entry || entry.type !== \"vectorize\") continue;\n const stateEntry = entry as VectorizeStateEntry;\n\n const changes: PlanFieldChange[] = [];\n if (stateEntry.dimensions !== config.dimensions) {\n changes.push({\n field: \"dimensions\",\n from: stateEntry.dimensions,\n to: config.dimensions,\n kind: \"immutable\",\n });\n }\n if (stateEntry.metric !== config.metric) {\n changes.push({\n field: \"metric\",\n from: stateEntry.metric,\n to: config.metric,\n kind: \"immutable\",\n });\n }\n\n if (changes.length === 0) continue;\n items.push({\n kind: \"vectorize\",\n action: \"replace\",\n logicalName: config.logicalName,\n derivedName,\n detail: changes\n .map((c) => `${c.field}: ${c.from} -> ${c.to}`)\n .join(\", \"),\n changes,\n });\n }\n\n return items;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n VectorizeStateEntry,\n} from \"../../types.js\";\nimport { vectorizeApply } from \"./vectorize.apply.js\";\nimport { vectorizeSync } from \"./vectorize.sync.js\";\nimport { vectorizeDrift } from \"./vectorize.drift.js\";\nimport { vectorizeDestroy } from \"./vectorize.destroy.js\";\nimport { vectorizeGenerate } from \"./vectorize.generate.js\";\nimport { vectorizeStatus } from \"./vectorize.status.js\";\nimport { vectorizeDiffPlanItems } from \"./vectorize.diff.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\ninterface CFVectorize {\n id?: string;\n name: string;\n config?: { dimensions: number; metric: string };\n}\n\nexport const vectorizeModule: ResourceModule<\n VectorizeResourceConfig,\n CFVectorize\n> = {\n kind: \"vectorize\",\n label: \"Vectorize\",\n configKey: \"vectorize\",\n stateEntryType: \"vectorize\",\n\n async fetchAll(api: CFApiClient): Promise<CFVectorize[]> {\n const all = await api.vectorizeListAll();\n return all.map((v) => ({ id: v.id, name: v.name, config: v.config }));\n },\n\n async apply(ctx) {\n await vectorizeApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n vectorizeSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return vectorizeDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n diff(ctx) {\n return vectorizeDiffPlanItems({\n resources: ctx.resources,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n });\n },\n\n async destroy(ctx) {\n await vectorizeDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return vectorizeStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n const generated =\n ctx.resources.length > 0\n ? vectorizeGenerate(ctx.resources, ctx.env, ctx.state, ctx.naming)\n : [];\n const passthrough = ctx.passthrough?.vectorize ?? [];\n if (generated.length === 0 && passthrough.length === 0) return {};\n return { vectorize: [...passthrough, ...generated] };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): VectorizeResourceConfig[] {\n return resourcesFrom(source)?.vectorize ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"vectorize\") return;\n try {\n await api.vectorizeDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete Vectorize ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const indexName = options.cfId;\n if (!indexName) {\n throw new Error(\"import vectorize: --cf-id <index-name> is required\");\n }\n const resourceConfig =\n await findWorkerResourceByLogicalName<VectorizeResourceConfig>(\n config,\n \"vectorize\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import vectorize: no resources.vectorize entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.vectorizeListAll();\n const hit = all.find((v) => v.name === indexName);\n if (!hit) {\n throw new Error(\n `import vectorize: index \"${indexName}\" not found in account`,\n );\n }\n const derivedName = vectorizeDeriveName(resourceConfig, env, naming);\n if (hit.name !== derivedName) {\n throw new Error(\n `import vectorize: cf name \"${hit.name}\" does not match derived \"${derivedName}\"`,\n );\n }\n if (!hit.config) {\n throw new Error(\n `import vectorize: cf index \"${hit.name}\" returned no config (dimensions/metric)`,\n );\n }\n const metric = hit.config.metric as \"cosine\" | \"euclidean\" | \"dot-product\";\n const bindingKey = naming.vectorizeBindingKey(options.logical);\n const key = `vectorize:${derivedName}`;\n const existing = state.get(key);\n const entry: VectorizeStateEntry = {\n type: \"vectorize\",\n logicalName: options.logical,\n derivedName,\n bindingKey,\n cfId: hit.id ?? derivedName,\n dimensions: hit.config.dimensions,\n metric,\n createdAt: existing?.type === \"vectorize\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { AIGatewayResourceConfig } from \"../../types.js\";\n\nexport type { AIGatewayResourceConfig };\n\n/**\n * Default values applied to optional `AIGatewayResourceConfig` fields. Kept\n * here so apply / sync / drift agree on what \"no override\" actually means\n * when comparing config to Cloudflare state.\n */\nexport const AI_GATEWAY_DEFAULTS = {\n cacheTtl: 0,\n cacheInvalidateOnUpdate: false,\n collectLogs: true,\n authentication: false,\n rateLimitingInterval: 0,\n rateLimitingLimit: 0,\n rateLimitingTechnique: \"fixed\" as const,\n};\n\nexport type ResolvedAIGatewayConfig = Required<\n Pick<\n AIGatewayResourceConfig,\n | \"cacheTtl\"\n | \"cacheInvalidateOnUpdate\"\n | \"collectLogs\"\n | \"authentication\"\n | \"rateLimitingInterval\"\n | \"rateLimitingLimit\"\n | \"rateLimitingTechnique\"\n >\n>;\n\nexport function resolveAIGatewayConfig(\n config: AIGatewayResourceConfig,\n): ResolvedAIGatewayConfig {\n return {\n cacheTtl: config.cacheTtl ?? AI_GATEWAY_DEFAULTS.cacheTtl,\n cacheInvalidateOnUpdate:\n config.cacheInvalidateOnUpdate ??\n AI_GATEWAY_DEFAULTS.cacheInvalidateOnUpdate,\n collectLogs: config.collectLogs ?? AI_GATEWAY_DEFAULTS.collectLogs,\n authentication: config.authentication ?? AI_GATEWAY_DEFAULTS.authentication,\n rateLimitingInterval:\n config.rateLimitingInterval ?? AI_GATEWAY_DEFAULTS.rateLimitingInterval,\n rateLimitingLimit:\n config.rateLimitingLimit ?? AI_GATEWAY_DEFAULTS.rateLimitingLimit,\n rateLimitingTechnique:\n config.rateLimitingTechnique ?? AI_GATEWAY_DEFAULTS.rateLimitingTechnique,\n };\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveAIGatewayCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { AIGatewayResourceConfig } from \"../../types.js\";\n\nexport function aiGatewayDeriveName(\n config: AIGatewayResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveAIGatewayCloudflareName(config, env, naming);\n}\n\nexport function aiGatewayMatchPattern(\n config: AIGatewayResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveAIGatewayCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","/**\n * Plan-time field-level diff for declared AI Gateways. Pure: takes the\n * recorded {@link AIGatewayStateEntry} and the declared\n * {@link AIGatewayResourceConfig}, and returns the `update` items\n * `tamer plan` should emit.\n *\n * All AI Gateway settings tracked here are mutable via\n * `PUT /accounts/{id}/ai-gateway/gateways/{id}` (Cloudflare's API uses\n * full-PUT, not PATCH, but it never rejects in-place edits on these\n * fields), so every detected drift becomes an `update` action — never\n * `replace`. Gateway id itself is part of the derived name and changes to\n * `logicalName` would surface as a different state row entirely.\n *\n * Resources without a state row are reported by `aiGatewayDrift` as\n * `undeployed` and become `create` items.\n */\n\nimport type {\n AIGatewayResourceConfig,\n AIGatewayStateEntry,\n} from \"../../types.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { PlanFieldChange, PlanItem } from \"../../core/plan/plan.types.js\";\nimport { resolveAIGatewayConfig } from \"./ai-gateway.types.js\";\n\nexport function aiGatewayDiffPlanItems(args: {\n resources: AIGatewayResourceConfig[];\n env: string;\n state: StateManager;\n naming: NamingEngine;\n}): PlanItem[] {\n const { resources, env, state, naming } = args;\n const items: PlanItem[] = [];\n\n for (const config of resources) {\n const derivedName = aiGatewayDeriveName(config, env, naming);\n const entry = state.get(`ai_gateway:${derivedName}`);\n if (!entry || entry.type !== \"ai_gateway\") continue;\n\n const changes = computeChanges(entry as AIGatewayStateEntry, config);\n if (changes.length === 0) continue;\n items.push({\n kind: \"ai_gateway\",\n action: \"update\",\n logicalName: config.logicalName,\n derivedName,\n detail: changes\n .map((c) => `${c.field}: ${formatVal(c.from)} -> ${formatVal(c.to)}`)\n .join(\", \"),\n changes,\n });\n }\n\n return items;\n}\n\n/**\n * Pure comparison shared with `aiGatewayApply` — keeps the plan and the\n * apply path in lockstep about which fields count as drift.\n */\nexport function computeAIGatewayChanges(\n state: AIGatewayStateEntry,\n config: AIGatewayResourceConfig,\n): PlanFieldChange[] {\n return computeChanges(state, config);\n}\n\nfunction computeChanges(\n state: AIGatewayStateEntry,\n config: AIGatewayResourceConfig,\n): PlanFieldChange[] {\n const resolved = resolveAIGatewayConfig(config);\n const changes: PlanFieldChange[] = [];\n\n if (state.cacheTtl !== resolved.cacheTtl) {\n changes.push({\n field: \"cacheTtl\",\n from: state.cacheTtl,\n to: resolved.cacheTtl,\n kind: \"mutable\",\n });\n }\n if (state.cacheInvalidateOnUpdate !== resolved.cacheInvalidateOnUpdate) {\n changes.push({\n field: \"cacheInvalidateOnUpdate\",\n from: state.cacheInvalidateOnUpdate,\n to: resolved.cacheInvalidateOnUpdate,\n kind: \"mutable\",\n });\n }\n if (state.collectLogs !== resolved.collectLogs) {\n changes.push({\n field: \"collectLogs\",\n from: state.collectLogs,\n to: resolved.collectLogs,\n kind: \"mutable\",\n });\n }\n if (state.authentication !== resolved.authentication) {\n changes.push({\n field: \"authentication\",\n from: state.authentication,\n to: resolved.authentication,\n kind: \"mutable\",\n });\n }\n if (state.rateLimitingInterval !== resolved.rateLimitingInterval) {\n changes.push({\n field: \"rateLimitingInterval\",\n from: state.rateLimitingInterval,\n to: resolved.rateLimitingInterval,\n kind: \"mutable\",\n });\n }\n if (state.rateLimitingLimit !== resolved.rateLimitingLimit) {\n changes.push({\n field: \"rateLimitingLimit\",\n from: state.rateLimitingLimit,\n to: resolved.rateLimitingLimit,\n kind: \"mutable\",\n });\n }\n if (state.rateLimitingTechnique !== resolved.rateLimitingTechnique) {\n changes.push({\n field: \"rateLimitingTechnique\",\n from: state.rateLimitingTechnique,\n to: resolved.rateLimitingTechnique,\n kind: \"mutable\",\n });\n }\n return changes;\n}\n\nfunction formatVal(v: unknown): string {\n if (v === undefined) return \"(unset)\";\n if (typeof v === \"string\") return v.length > 32 ? `${v.slice(0, 29)}...` : v;\n return String(v);\n}\n","import type { AIGatewayStateEntry, TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { AIGatewayResourceConfig } from \"./ai-gateway.types.js\";\nimport { resolveAIGatewayConfig } from \"./ai-gateway.types.js\";\nimport { computeAIGatewayChanges } from \"./ai-gateway.diff.js\";\nimport { logApplyChange } from \"../../core/plan/planFormat.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\n\nconst STATE_KEY_PREFIX = \"ai_gateway:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\nexport async function aiGatewayApply(\n resources: AIGatewayResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = aiGatewayDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n const resolved = resolveAIGatewayConfig(config);\n const ts = new Date().toISOString();\n\n if (existing && existing.type === \"ai_gateway\") {\n const changes = computeAIGatewayChanges(\n existing as AIGatewayStateEntry,\n config,\n );\n if (changes.length === 0) continue;\n logApplyChange({\n kind: \"ai_gateway\",\n action: \"update\",\n logical: config.logicalName,\n derived: derivedName,\n changes,\n });\n await api.aiGatewayUpdate(derivedName, {\n cache_ttl: resolved.cacheTtl,\n cache_invalidate_on_update: resolved.cacheInvalidateOnUpdate,\n collect_logs: resolved.collectLogs,\n authentication: resolved.authentication,\n rate_limiting_interval: resolved.rateLimitingInterval,\n rate_limiting_limit: resolved.rateLimitingLimit,\n rate_limiting_technique: resolved.rateLimitingTechnique,\n });\n state.set(key, {\n ...(existing as AIGatewayStateEntry),\n cacheTtl: resolved.cacheTtl,\n cacheInvalidateOnUpdate: resolved.cacheInvalidateOnUpdate,\n collectLogs: resolved.collectLogs,\n authentication: resolved.authentication,\n rateLimitingInterval: resolved.rateLimitingInterval,\n rateLimitingLimit: resolved.rateLimitingLimit,\n rateLimitingTechnique: resolved.rateLimitingTechnique,\n updatedAt: ts,\n });\n continue;\n }\n\n logApplyChange({\n kind: \"ai_gateway\",\n action: \"create\",\n logical: config.logicalName,\n derived: derivedName,\n });\n await api.aiGatewayCreate({\n id: derivedName,\n cache_ttl: resolved.cacheTtl,\n cache_invalidate_on_update: resolved.cacheInvalidateOnUpdate,\n collect_logs: resolved.collectLogs,\n authentication: resolved.authentication,\n rate_limiting_interval: resolved.rateLimitingInterval,\n rate_limiting_limit: resolved.rateLimitingLimit,\n rate_limiting_technique: resolved.rateLimitingTechnique,\n });\n state.set(key, {\n type: \"ai_gateway\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: naming.aiGatewayBindingKey(config.logicalName),\n cfId: derivedName,\n cacheTtl: resolved.cacheTtl,\n cacheInvalidateOnUpdate: resolved.cacheInvalidateOnUpdate,\n collectLogs: resolved.collectLogs,\n authentication: resolved.authentication,\n rateLimitingInterval: resolved.rateLimitingInterval,\n rateLimitingLimit: resolved.rateLimitingLimit,\n rateLimitingTechnique: resolved.rateLimitingTechnique,\n createdAt: ts,\n updatedAt: ts,\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { AIGatewayResourceConfig } from \"./ai-gateway.types.js\";\nimport { resolveAIGatewayConfig } from \"./ai-gateway.types.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\n\ninterface CFAIGateway {\n id: string;\n cache_ttl?: number;\n cache_invalidate_on_update?: boolean;\n collect_logs?: boolean;\n authentication?: boolean;\n rate_limiting_interval?: number;\n rate_limiting_limit?: number;\n rate_limiting_technique?: \"fixed\" | \"sliding\";\n}\n\nexport function aiGatewaySync(\n allGateways: CFAIGateway[],\n resources: AIGatewayResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = aiGatewayDeriveName(config, env, naming);\n const match = allGateways.find((g) => g.id === derivedName);\n if (!match) continue;\n const key = `ai_gateway:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n const resolved = resolveAIGatewayConfig(config);\n state.set(key, {\n type: \"ai_gateway\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: naming.aiGatewayBindingKey(config.logicalName),\n cfId: derivedName,\n cacheTtl: match.cache_ttl ?? resolved.cacheTtl,\n cacheInvalidateOnUpdate:\n match.cache_invalidate_on_update ?? resolved.cacheInvalidateOnUpdate,\n collectLogs: match.collect_logs ?? resolved.collectLogs,\n authentication: match.authentication ?? resolved.authentication,\n rateLimitingInterval:\n match.rate_limiting_interval ?? resolved.rateLimitingInterval,\n rateLimitingLimit:\n match.rate_limiting_limit ?? resolved.rateLimitingLimit,\n rateLimitingTechnique:\n match.rate_limiting_technique ?? resolved.rateLimitingTechnique,\n createdAt: existing?.type === \"ai_gateway\" ? existing.createdAt : ts,\n updatedAt: ts,\n });\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { AIGatewayResourceConfig } from \"./ai-gateway.types.js\";\nimport type { AIGatewayStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\n\ninterface CFAIGateway {\n id: string;\n}\n\nexport function aiGatewayDrift(\n allGateways: CFAIGateway[],\n resources: AIGatewayResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"ai_gateway\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfIds = new Set(allGateways.map((g) => g.id));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is AIGatewayStateEntry => e.type === \"ai_gateway\",\n );\n\n for (const config of resources) {\n const derivedName = aiGatewayDeriveName(config, env, naming);\n const inCloudflare = cfIds.has(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !inCloudflare) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (inCloudflare && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId: derivedName,\n });\n } else if (!inCloudflare && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { AIGatewayStateEntry, CfiConfig } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function aiGatewayDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"ai_gateway\");\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, AIGatewayStateEntry] => kv[1].type === \"ai_gateway\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.aiGatewayDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Failed to delete AI Gateway ${entry.derivedName}:`,\n err,\n );\n }\n }\n}\n","import type { AIGatewayStateEntry, ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { AIGatewayResourceConfig } from \"./ai-gateway.types.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\n\nexport interface AIGatewayStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function aiGatewayStatus(\n resources: AIGatewayResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): AIGatewayStatusResult[] {\n const out: AIGatewayStatusResult[] = [];\n for (const config of resources) {\n const derivedName = aiGatewayDeriveName(config, env, naming);\n const entry = state.get(`ai_gateway:${derivedName}`) as\n | AIGatewayStateEntry\n | undefined;\n out.push({\n binding: naming.aiGatewayBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { AIGatewayResourceConfig } from \"./ai-gateway.types.js\";\nimport type {\n AIGatewayStateEntry,\n WorkerConfig,\n WorkerResources,\n} from \"../../types.js\";\nimport { aiGatewayApply } from \"./ai-gateway.apply.js\";\nimport { aiGatewaySync } from \"./ai-gateway.sync.js\";\nimport { aiGatewayDrift } from \"./ai-gateway.drift.js\";\nimport { aiGatewayDestroy } from \"./ai-gateway.destroy.js\";\nimport { aiGatewayStatus } from \"./ai-gateway.status.js\";\nimport { aiGatewayDiffPlanItems } from \"./ai-gateway.diff.js\";\nimport { resolveAIGatewayConfig } from \"./ai-gateway.types.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\n\ninterface CFAIGateway {\n id: string;\n cache_ttl?: number;\n cache_invalidate_on_update?: boolean;\n collect_logs?: boolean;\n authentication?: boolean;\n rate_limiting_interval?: number;\n rate_limiting_limit?: number;\n rate_limiting_technique?: \"fixed\" | \"sliding\";\n}\n\nexport const aiGatewayModule: ResourceModule<\n AIGatewayResourceConfig,\n CFAIGateway\n> = {\n kind: \"ai_gateway\",\n label: \"AI Gateway\",\n configKey: \"aiGateway\",\n stateEntryType: \"ai_gateway\",\n\n async fetchAll(api: CFApiClient): Promise<CFAIGateway[]> {\n return await api.aiGatewayListAll();\n },\n\n async apply(ctx) {\n await aiGatewayApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n aiGatewaySync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return aiGatewayDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n diff(ctx) {\n return aiGatewayDiffPlanItems({\n resources: ctx.resources,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n });\n },\n\n async destroy(ctx) {\n await aiGatewayDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return aiGatewayStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n /**\n * AI Gateway has no Wrangler binding kind — gateways are referenced per\n * request via `env.AI.run(model, opts, { gateway: { id } })`. Cross-resource\n * refs (`${tamer:ai_gateway:my_gw.name}`) are how the derived id reaches\n * worker code.\n */\n generate() {\n return {};\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): AIGatewayResourceConfig[] {\n return resourcesFrom(source)?.aiGateway ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"ai_gateway\") return;\n try {\n await api.aiGatewayDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete AI Gateway ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const gatewayId = options.cfId;\n if (!gatewayId) {\n throw new Error(\"import ai_gateway: --cf-id <gateway-id> is required\");\n }\n const resourceConfig =\n await findWorkerResourceByLogicalName<AIGatewayResourceConfig>(\n config,\n \"aiGateway\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import ai_gateway: no resources.aiGateway entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.aiGatewayListAll();\n const hit = all.find((g) => g.id === gatewayId);\n if (!hit) {\n throw new Error(\n `import ai_gateway: gateway \"${gatewayId}\" not found in account`,\n );\n }\n const derivedName = aiGatewayDeriveName(resourceConfig, env, naming);\n if (hit.id !== derivedName) {\n throw new Error(\n `import ai_gateway: cf id \"${hit.id}\" does not match derived \"${derivedName}\"`,\n );\n }\n const key = `ai_gateway:${derivedName}`;\n const existing = state.get(key);\n const defaults = resolveAIGatewayConfig({ logicalName: options.logical });\n const entry: AIGatewayStateEntry = {\n type: \"ai_gateway\",\n logicalName: options.logical,\n derivedName,\n bindingKey: naming.aiGatewayBindingKey(options.logical),\n cfId: hit.id,\n cacheTtl: hit.cache_ttl ?? defaults.cacheTtl,\n cacheInvalidateOnUpdate:\n hit.cache_invalidate_on_update ?? defaults.cacheInvalidateOnUpdate,\n collectLogs: hit.collect_logs ?? defaults.collectLogs,\n authentication: hit.authentication ?? defaults.authentication,\n rateLimitingInterval:\n hit.rate_limiting_interval ?? defaults.rateLimitingInterval,\n rateLimitingLimit: hit.rate_limiting_limit ?? defaults.rateLimitingLimit,\n rateLimitingTechnique:\n hit.rate_limiting_technique ?? defaults.rateLimitingTechnique,\n createdAt: existing?.type === \"ai_gateway\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolvePipelineCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { PipelineResourceConfig } from \"../../types.js\";\n\nexport function pipelineDeriveName(\n config: PipelineResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolvePipelineCloudflareName(config, env, naming);\n}\n\nexport function pipelineMatchPattern(\n config: PipelineResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolvePipelineCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\nconst STATE_KEY_PREFIX = \"pipeline:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\n/**\n * Idempotent create — skips when a state entry already exists. Pipeline SQL\n * updates on existing pipelines are deliberately not handled here (Cloudflare's\n * V1 endpoint has no PATCH today; SQL changes require a destroy + recreate).\n * Drift surfaces SQL mismatches so operators can recover explicitly.\n */\nexport async function pipelinesApply(\n resources: PipelineResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n if (existing) continue;\n\n const ts = new Date().toISOString();\n const created = await api.pipelineCreate({\n name: derivedName,\n sql: config.sql,\n });\n state.set(key, {\n type: \"pipeline\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.pipelineBindingKey(config.logicalName),\n cfId: created.id,\n sql: created.sql ?? config.sql,\n status: created.status,\n createdAt: ts,\n updatedAt: ts,\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\ninterface CFPipeline {\n id: string;\n name: string;\n sql: string;\n status?: string;\n}\n\nexport function pipelinesSync(\n allPipelines: CFPipeline[],\n resources: PipelineResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const match = allPipelines.find((p) => p.name === derivedName);\n if (!match) continue;\n const key = `pipeline:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n state.set(key, {\n type: \"pipeline\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.pipelineBindingKey(config.logicalName),\n cfId: match.id,\n sql: match.sql,\n status: match.status,\n createdAt: existing?.type === \"pipeline\" ? existing.createdAt : ts,\n updatedAt: ts,\n });\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport type { PipelineStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\ninterface CFPipeline {\n id: string;\n name: string;\n sql: string;\n}\n\nexport function pipelinesDrift(\n allPipelines: CFPipeline[],\n resources: PipelineResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"pipeline\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allPipelines.map((p) => [p.name, p]));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is PipelineStateEntry => e.type === \"pipeline\",\n );\n\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const inCloudflare = cfByName.has(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !inCloudflare) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (inCloudflare && !stateEntry) {\n const cf = cfByName.get(derivedName)!;\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId: cf.id,\n });\n } else if (!inCloudflare && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, PipelineStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function pipelinesDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"pipeline\");\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, PipelineStateEntry] => kv[1].type === \"pipeline\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.pipelineDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Failed to delete Pipeline ${entry.derivedName}:`,\n err,\n );\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\nexport interface PipelineStateLike {\n get(key: string): StateEntry | undefined;\n}\n\nexport interface GeneratedPipelineBinding {\n binding: string;\n pipeline: string;\n}\n\n/**\n * Emit `pipelines[]` bindings for declared pipelines. Each binding requires\n * the pipeline to exist in state (i.e. `tamer apply` has run). Throws\n * otherwise so the operator gets an actionable error before `wrangler deploy`.\n *\n * Note: Wrangler's `pipeline` field accepts the pipeline **name**, not the\n * server-assigned id, so we emit the derived name here.\n */\nexport function pipelinesGenerate(\n resources: PipelineResourceConfig[],\n env: string,\n state: PipelineStateLike,\n naming: NamingEngine,\n): GeneratedPipelineBinding[] {\n const out: GeneratedPipelineBinding[] = [];\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const entry = state.get(`pipeline:${derivedName}`);\n if (!entry || entry.type !== \"pipeline\") {\n throw new Error(\n `Pipeline \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`,\n );\n }\n out.push({\n binding: entry.bindingKey,\n pipeline: entry.derivedName,\n });\n }\n return out;\n}\n","import type { PipelineStateEntry, ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\nexport interface PipelineStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function pipelinesStatus(\n resources: PipelineResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): PipelineStatusResult[] {\n const out: PipelineStatusResult[] = [];\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const entry = state.get(`pipeline:${derivedName}`) as\n | PipelineStateEntry\n | undefined;\n out.push({\n binding:\n config.binding?.trim() || naming.pipelineBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","/**\n * Plan-time diff for Cloudflare Pipelines (V1, SQL). The pipeline `sql`\n * body is the only mutable knob today, but Cloudflare V1 has no PATCH\n * endpoint — SQL changes require destroy + recreate. Plan signals this as\n * `replace` so the operator (or `apply --replace`, future work) can act on\n * it explicitly.\n *\n * The `binding` key is stored alongside the state row but is a wrangler-\n * generation concern (no Cloudflare-side resource changes), so a binding-\n * only drift is reported as `update` rather than `replace`.\n */\n\nimport type {\n PipelineResourceConfig,\n PipelineStateEntry,\n} from \"../../types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { PlanFieldChange, PlanItem } from \"../../core/plan/plan.types.js\";\n\nexport function pipelinesDiffPlanItems(args: {\n resources: PipelineResourceConfig[];\n env: string;\n state: StateManager;\n naming: NamingEngine;\n}): PlanItem[] {\n const { resources, env, state, naming } = args;\n const items: PlanItem[] = [];\n\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const key = `pipeline:${derivedName}`;\n const entry = state.get(key);\n if (!entry || entry.type !== \"pipeline\") continue;\n const stateEntry = entry as PipelineStateEntry;\n\n const expectedBinding =\n config.binding?.trim() || naming.pipelineBindingKey(config.logicalName);\n\n const changes: PlanFieldChange[] = [];\n if (stateEntry.sql !== config.sql) {\n changes.push({\n field: \"sql\",\n from: truncate(stateEntry.sql),\n to: truncate(config.sql),\n kind: \"immutable\",\n });\n }\n if (stateEntry.bindingKey !== expectedBinding) {\n changes.push({\n field: \"binding\",\n from: stateEntry.bindingKey,\n to: expectedBinding,\n kind: \"mutable\",\n });\n }\n\n if (changes.length === 0) continue;\n const hasImmutable = changes.some((c) => c.kind === \"immutable\");\n items.push({\n kind: \"pipeline\",\n action: hasImmutable ? \"replace\" : \"update\",\n logicalName: config.logicalName,\n derivedName,\n detail: changes.map((c) => c.field).join(\", \"),\n changes,\n });\n }\n\n return items;\n}\n\nfunction truncate(v: string): string {\n return v.length > 60 ? `${v.slice(0, 57)}...` : v;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport type {\n PipelineStateEntry,\n WorkerConfig,\n WorkerResources,\n} from \"../../types.js\";\nimport { pipelinesApply } from \"./pipelines.apply.js\";\nimport { pipelinesSync } from \"./pipelines.sync.js\";\nimport { pipelinesDrift } from \"./pipelines.drift.js\";\nimport { pipelinesDestroy } from \"./pipelines.destroy.js\";\nimport { pipelinesGenerate } from \"./pipelines.generate.js\";\nimport { pipelinesStatus } from \"./pipelines.status.js\";\nimport { pipelinesDiffPlanItems } from \"./pipelines.diff.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\ninterface CFPipeline {\n id: string;\n name: string;\n sql: string;\n status?: string;\n}\n\nexport const pipelinesModule: ResourceModule<\n PipelineResourceConfig,\n CFPipeline\n> = {\n kind: \"pipeline\",\n label: \"Pipeline\",\n configKey: \"pipelines\",\n stateEntryType: \"pipeline\",\n\n async fetchAll(api: CFApiClient): Promise<CFPipeline[]> {\n const all = await api.pipelineListAll();\n return all.map((p) => ({\n id: p.id,\n name: p.name,\n sql: p.sql,\n status: p.status,\n }));\n },\n\n async apply(ctx) {\n await pipelinesApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n pipelinesSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return pipelinesDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n diff(ctx) {\n return pipelinesDiffPlanItems({\n resources: ctx.resources,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n });\n },\n\n async destroy(ctx) {\n await pipelinesDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return pipelinesStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n const generated =\n ctx.resources.length > 0\n ? pipelinesGenerate(ctx.resources, ctx.env, ctx.state, ctx.naming)\n : [];\n const passthrough = ctx.passthrough?.pipelines ?? [];\n if (generated.length === 0 && passthrough.length === 0) return {};\n return { pipelines: [...passthrough, ...generated] };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): PipelineResourceConfig[] {\n return resourcesFrom(source)?.pipelines ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"pipeline\") return;\n try {\n await api.pipelineDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete Pipeline ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const pipelineId = options.cfId;\n if (!pipelineId) {\n throw new Error(\"import pipeline: --cf-id <pipeline-id> is required\");\n }\n const resourceConfig =\n await findWorkerResourceByLogicalName<PipelineResourceConfig>(\n config,\n \"pipelines\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import pipeline: no resources.pipelines entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.pipelineListAll();\n const hit = all.find((p) => p.id === pipelineId);\n if (!hit) {\n throw new Error(\n `import pipeline: pipeline \"${pipelineId}\" not found in account`,\n );\n }\n const derivedName = pipelineDeriveName(resourceConfig, env, naming);\n if (hit.name !== derivedName) {\n throw new Error(\n `import pipeline: cf name \"${hit.name}\" does not match derived \"${derivedName}\"`,\n );\n }\n const key = `pipeline:${derivedName}`;\n const existing = state.get(key);\n const entry: PipelineStateEntry = {\n type: \"pipeline\",\n logicalName: options.logical,\n derivedName,\n bindingKey: naming.pipelineBindingKey(options.logical),\n cfId: hit.id,\n sql: hit.sql,\n status: hit.status,\n createdAt: existing?.type === \"pipeline\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveWorkflowCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\n\nexport function workflowDeriveName(\n config: WorkflowResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveWorkflowCloudflareName(config, env, naming);\n}\n\nexport function workflowMatchPattern(\n config: WorkflowResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveWorkflowCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","/**\n * Plan-time field-level diff for declared Workflows. Compares the recorded\n * {@link WorkflowStateEntry} against the {@link WorkflowResourceConfig} the\n * user wrote, and returns `update` {@link PlanItem}s for any drifted field.\n *\n * Workflows are upserted via `PUT /accounts/{id}/workflows/{name}` —\n * Cloudflare treats the call as create-or-update across `class_name`,\n * `script_name`, and `limits`, so every meaningful drift is an in-place\n * `update` (never a `replace`). Drift in just the binding key is also\n * tracked since `wrangler deploy` would emit a different fragment.\n *\n * Resources without a recorded state entry are not surfaced here — they\n * appear as `create` items via the `drift().undeployed` path in\n * `computePlan`.\n */\n\nimport type {\n WorkflowResourceConfig,\n WorkflowStateEntry,\n} from \"../../types.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { WorkerScope } from \"../../core/registry/types.js\";\nimport type { PlanFieldChange, PlanItem } from \"../../core/plan/plan.types.js\";\n\nexport function workflowsDiffPlanItems(args: {\n resources: WorkflowResourceConfig[];\n env: string;\n state: StateManager;\n naming: NamingEngine;\n worker?: WorkerScope;\n}): PlanItem[] {\n const { resources, env, state, naming, worker } = args;\n const items: PlanItem[] = [];\n\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const key = `workflow:${derivedName}`;\n const entry = state.get(key);\n if (!entry || entry.type !== \"workflow\") continue;\n\n const stateEntry = entry as WorkflowStateEntry;\n const changes = computeWorkflowChanges(stateEntry, config, naming, worker);\n if (changes.length === 0) continue;\n items.push({\n kind: \"workflow\",\n action: \"update\",\n logicalName: config.logicalName,\n derivedName,\n detail: changes\n .map((c) => `${c.field}: ${formatVal(c.from)} -> ${formatVal(c.to)}`)\n .join(\", \"),\n changes,\n });\n }\n\n return items;\n}\n\n/**\n * Pure comparison shared with `workflowsApply` so plan and apply agree\n * on what counts as drift on a registered workflow. Drift in any of\n * `className`, `scriptName` (defaulting to the owning worker's\n * deployed name), `limits.steps`, or the binding key triggers an\n * in-place PUT — Cloudflare treats `PUT /accounts/{id}/workflows/{name}`\n * as create-or-update.\n */\nexport function computeWorkflowChanges(\n state: WorkflowStateEntry,\n config: WorkflowResourceConfig,\n naming: NamingEngine,\n worker: WorkerScope | undefined,\n): PlanFieldChange[] {\n const expectedScriptName =\n config.scriptName?.trim() ?? worker?.deployedName;\n const expectedBindingKey =\n config.binding?.trim() || naming.workflowBindingKey(config.logicalName);\n\n const changes: PlanFieldChange[] = [];\n\n if (state.className !== config.className) {\n changes.push({\n field: \"className\",\n from: state.className,\n to: config.className,\n kind: \"mutable\",\n });\n }\n if (\n expectedScriptName !== undefined &&\n state.scriptName !== expectedScriptName\n ) {\n changes.push({\n field: \"scriptName\",\n from: state.scriptName,\n to: expectedScriptName,\n kind: \"mutable\",\n });\n }\n const stateSteps = state.limits?.steps;\n const configSteps = config.limits?.steps;\n if ((stateSteps ?? null) !== (configSteps ?? null)) {\n changes.push({\n field: \"limits.steps\",\n from: stateSteps,\n to: configSteps,\n kind: \"mutable\",\n });\n }\n if (state.bindingKey !== expectedBindingKey) {\n changes.push({\n field: \"binding\",\n from: state.bindingKey,\n to: expectedBindingKey,\n kind: \"mutable\",\n });\n }\n\n return changes;\n}\n\nfunction formatVal(v: unknown): string {\n if (v === undefined || v === null) return \"(unset)\";\n if (typeof v === \"string\") return v.length > 32 ? `${v.slice(0, 29)}...` : v;\n return String(v);\n}\n","import type { TenantMeta, WorkflowStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { WorkerScope } from \"../../core/registry/types.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport { computeWorkflowChanges } from \"./workflows.diff.js\";\nimport { logApplyChange } from \"../../core/plan/planFormat.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\n\nconst STATE_KEY_PREFIX = \"workflow:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\nfunction resolveScriptName(\n config: WorkflowResourceConfig,\n worker: WorkerScope | undefined,\n): string {\n const explicit = config.scriptName?.trim();\n if (explicit) return explicit;\n if (!worker) {\n throw new Error(\n `workflow \"${config.logicalName}\": no scriptName given and module ran ` +\n `without a worker scope — set scriptName on the resource or invoke ` +\n `apply per-worker.`,\n );\n }\n return worker.deployedName;\n}\n\nfunction limitsEqual(\n a: { steps?: number } | undefined,\n b: { steps?: number } | undefined,\n): boolean {\n return (a?.steps ?? null) === (b?.steps ?? null);\n}\n\n/**\n * Idempotent upsert via `PUT /accounts/{id}/workflows/{name}`. Cloudflare\n * treats PUT as create-or-update, so we issue it whenever the recorded\n * `(class_name, script_name, limits)` triple has drifted from config (or\n * the workflow has never been registered at all). Drift between recorded\n * state and *live* Cloudflare is surfaced separately by `workflowsDrift`.\n */\nexport async function workflowsApply(\n resources: WorkflowResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n worker?: WorkerScope,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const scriptName = resolveScriptName(config, worker);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n const wantsBindingKey =\n config.binding?.trim() || naming.workflowBindingKey(config.logicalName);\n\n if (\n existing &&\n existing.type === \"workflow\" &&\n existing.className === config.className &&\n existing.scriptName === scriptName &&\n limitsEqual(existing.limits, config.limits) &&\n existing.bindingKey === wantsBindingKey\n ) {\n continue;\n }\n\n if (existing && existing.type === \"workflow\") {\n const changes = computeWorkflowChanges(existing, config, naming, worker);\n logApplyChange({\n kind: \"workflow\",\n action: \"update\",\n logical: config.logicalName,\n derived: derivedName,\n changes,\n });\n } else {\n logApplyChange({\n kind: \"workflow\",\n action: \"create\",\n logical: config.logicalName,\n derived: derivedName,\n });\n }\n\n const ts = new Date().toISOString();\n let upserted: Awaited<ReturnType<typeof api.workflowUpsert>>;\n try {\n upserted = await api.workflowUpsert(derivedName, {\n class_name: config.className,\n script_name: scriptName,\n ...(config.limits ? { limits: config.limits } : {}),\n });\n } catch (err) {\n // Script may not be deployed yet (chicken-and-egg: apply runs before\n // deploy on greenfield envs). Skip — deploy will register the workflow\n // after wrangler deploy succeeds.\n if (!existing) {\n console.warn(\n ` workflow ${config.logicalName} -> ${derivedName}: deferred (script \"${scriptName}\" not deployed yet; will register during deploy)`,\n );\n continue;\n }\n throw err;\n }\n const entry: WorkflowStateEntry = {\n type: \"workflow\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: wantsBindingKey,\n cfId: upserted.id,\n className: upserted.class_name,\n scriptName: upserted.script_name,\n limits: config.limits,\n createdAt: existing?.type === \"workflow\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n }\n}\n","import type { TenantMeta, WorkflowStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport { workflowDeriveName, workflowMatchPattern } from \"./workflows.naming.js\";\n\ninterface CFWorkflow {\n id: string;\n name: string;\n class_name: string;\n script_name: string;\n}\n\n/**\n * Match each declared workflow against `GET /accounts/{id}/workflows` and\n * upsert into state. Stack-scoped: `resources` is already filtered to the\n * current config, so we never persist a workflow owned by another stack\n * sharing this state row.\n */\nexport function workflowsSync(\n allWorkflows: CFWorkflow[],\n resources: WorkflowResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const pattern = workflowMatchPattern(config, env, naming);\n const match = allWorkflows.find((w) => pattern(w.name));\n if (!match) continue;\n const key = `workflow:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n const entry: WorkflowStateEntry = {\n type: \"workflow\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() ||\n naming.workflowBindingKey(config.logicalName),\n cfId: match.id,\n className: match.class_name,\n scriptName: match.script_name,\n limits:\n existing?.type === \"workflow\" ? existing.limits : config.limits,\n createdAt: existing?.type === \"workflow\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport type { WorkflowStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\n\ninterface CFWorkflow {\n id: string;\n name: string;\n class_name: string;\n script_name: string;\n}\n\nexport function workflowsDrift(\n allWorkflows: CFWorkflow[],\n resources: WorkflowResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"workflow\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allWorkflows.map((w) => [w.name, w]));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is WorkflowStateEntry => e.type === \"workflow\",\n );\n\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const inCloudflare = cfByName.has(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !inCloudflare) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (inCloudflare && !stateEntry) {\n const cf = cfByName.get(derivedName)!;\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId: cf.id,\n });\n } else if (!inCloudflare && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, WorkflowStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function workflowsDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"workflow\");\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, WorkflowStateEntry] => kv[1].type === \"workflow\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.workflowDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Failed to delete Workflow ${entry.derivedName}:`,\n err,\n );\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport type { WorkerScope } from \"../../core/registry/types.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\n\nexport interface WorkflowStateLike {\n get(key: string): StateEntry | undefined;\n}\n\nexport interface GeneratedWorkflowBinding {\n binding: string;\n name: string;\n class_name: string;\n /**\n * Optional per Cloudflare's wrangler schema — omitted when the workflow\n * lives in the same script as the binding (Wrangler defaults `script_name`\n * to the worker's own `name`). Emitted only when an explicit\n * `WorkflowResourceConfig.scriptName` was provided.\n */\n script_name?: string;\n}\n\n/**\n * Emit `workflows[]` bindings for declared workflows. Requires `tamer apply`\n * to have run (state row present) so we can fail fast with a clear message\n * before `wrangler deploy` would surface a less actionable error.\n *\n * `script_name` is only emitted when the user pinned an explicit override\n * — without it, Wrangler binds to the current worker's own script, which\n * matches our default-to-owning-worker semantics in apply.\n */\nexport function workflowsGenerate(\n resources: WorkflowResourceConfig[],\n env: string,\n state: WorkflowStateLike,\n naming: NamingEngine,\n worker?: WorkerScope,\n): GeneratedWorkflowBinding[] {\n const out: GeneratedWorkflowBinding[] = [];\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const entry = state.get(`workflow:${derivedName}`);\n if (!entry || entry.type !== \"workflow\") {\n throw new Error(\n `Workflow \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`,\n );\n }\n const explicitScript = config.scriptName?.trim();\n const ownerScript = worker?.deployedName;\n const binding: GeneratedWorkflowBinding = {\n binding: entry.bindingKey,\n name: entry.derivedName,\n class_name: entry.className,\n };\n if (explicitScript) {\n binding.script_name = explicitScript;\n } else if (ownerScript && ownerScript !== entry.scriptName) {\n // Recorded scriptName diverges from the current worker we're emitting\n // wrangler.json for — pin it explicitly so the binding still resolves.\n binding.script_name = entry.scriptName;\n }\n out.push(binding);\n }\n return out;\n}\n","import type { WorkflowStateEntry, ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\n\nexport interface WorkflowStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function workflowsStatus(\n resources: WorkflowResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): WorkflowStatusResult[] {\n const out: WorkflowStatusResult[] = [];\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const entry = state.get(`workflow:${derivedName}`) as\n | WorkflowStateEntry\n | undefined;\n out.push({\n binding:\n config.binding?.trim() ||\n naming.workflowBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport type {\n WorkflowStateEntry,\n WorkerConfig,\n WorkerResources,\n} from \"../../types.js\";\nimport { workflowsApply } from \"./workflows.apply.js\";\nimport { workflowsSync } from \"./workflows.sync.js\";\nimport { workflowsDrift } from \"./workflows.drift.js\";\nimport { workflowsDiffPlanItems } from \"./workflows.diff.js\";\nimport { workflowsDestroy } from \"./workflows.destroy.js\";\nimport { workflowsGenerate } from \"./workflows.generate.js\";\nimport { workflowsStatus } from \"./workflows.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\n\ninterface CFWorkflow {\n id: string;\n name: string;\n class_name: string;\n script_name: string;\n}\n\nexport const workflowsModule: ResourceModule<\n WorkflowResourceConfig,\n CFWorkflow\n> = {\n kind: \"workflow\",\n label: \"Workflow\",\n configKey: \"workflows\",\n stateEntryType: \"workflow\",\n\n async fetchAll(api: CFApiClient): Promise<CFWorkflow[]> {\n const all = await api.workflowListAll();\n return all.map((w) => ({\n id: w.id,\n name: w.name,\n class_name: w.class_name,\n script_name: w.script_name,\n }));\n },\n\n async apply(ctx) {\n await workflowsApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n ctx.worker,\n );\n },\n\n sync(ctx) {\n workflowsSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return workflowsDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n diff(ctx) {\n return workflowsDiffPlanItems({\n resources: ctx.resources,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n worker: ctx.worker,\n });\n },\n\n async destroy(ctx) {\n await workflowsDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return workflowsStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n const generated =\n ctx.resources.length > 0\n ? workflowsGenerate(\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n ctx.worker,\n )\n : [];\n const passthrough = ctx.passthrough?.workflows ?? [];\n if (generated.length === 0 && passthrough.length === 0) return {};\n return { workflows: [...passthrough, ...generated] };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): WorkflowResourceConfig[] {\n return resourcesFrom(source)?.workflows ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"workflow\") return;\n try {\n await api.workflowDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete Workflow ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const resourceConfig =\n await findWorkerResourceByLogicalName<WorkflowResourceConfig>(\n config,\n \"workflows\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import workflow: no resources.workflows entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const derivedName = workflowDeriveName(resourceConfig, env, naming);\n const all = await api.workflowListAll();\n const hit = all.find((w) => w.name === derivedName);\n if (!hit) {\n throw new Error(\n `import workflow: no workflow named \"${derivedName}\" found in account`,\n );\n }\n if (options.cfId && hit.id !== options.cfId) {\n throw new Error(\n `import workflow: cf id \"${hit.id}\" does not match --cf-id \"${options.cfId}\"`,\n );\n }\n const key = `workflow:${derivedName}`;\n const existing = state.get(key);\n const entry: WorkflowStateEntry = {\n type: \"workflow\",\n logicalName: options.logical,\n derivedName,\n bindingKey: naming.workflowBindingKey(options.logical),\n cfId: hit.id,\n className: hit.class_name,\n scriptName: hit.script_name,\n limits:\n existing?.type === \"workflow\" ? existing.limits : undefined,\n createdAt: existing?.type === \"workflow\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveSecretsStoreCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { SecretsStoreResourceConfig } from \"../../types.js\";\n\nexport function secretsStoreDeriveName(\n config: SecretsStoreResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveSecretsStoreCloudflareName(config, env, naming);\n}\n\nexport function secretsStoreMatchPattern(\n config: SecretsStoreResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveSecretsStoreCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","import type { TenantMeta, SecretsStoreStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { SecretsStoreResourceConfig } from \"./secrets-store.types.js\";\nimport { secretsStoreDeriveName } from \"./secrets-store.naming.js\";\n\nconst STATE_KEY_PREFIX = \"secrets_store:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\n/**\n * Idempotent provisioning for Secrets Store stores. The Cloudflare create\n * endpoint is non-idempotent (a duplicate name returns 409), so we list\n * first and short-circuit when a matching name already exists. Secret\n * **values** are deliberately out of scope — Tamer only manages the\n * account-scoped container. See `SecretsStoreSecretBinding` for how\n * worker bindings reference the resolved `store_id`.\n */\nexport async function secretsStoreApply(\n resources: SecretsStoreResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n if (resources.length === 0) return;\n\n let allStores:\n | Awaited<ReturnType<typeof api.secretsStoreListAll>>\n | null = null;\n\n for (const config of resources) {\n const derivedName = secretsStoreDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n const wantsBindingKey = naming.secretsStoreBindingKey(config.logicalName);\n\n if (\n existing &&\n existing.type === \"secrets_store\" &&\n existing.bindingKey === wantsBindingKey\n ) {\n continue;\n }\n\n if (allStores === null) {\n allStores = await api.secretsStoreListAll();\n }\n const match = allStores.find((s) => s.name === derivedName);\n\n const ts = new Date().toISOString();\n let cfId: string;\n if (match) {\n cfId = match.id;\n } else {\n const created = await api.secretsStoreCreate(derivedName);\n cfId = created.id;\n }\n\n const entry: SecretsStoreStateEntry = {\n type: \"secrets_store\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: wantsBindingKey,\n cfId,\n createdAt:\n existing?.type === \"secrets_store\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n }\n}\n","import type { TenantMeta, SecretsStoreStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { SecretsStoreResourceConfig } from \"./secrets-store.types.js\";\nimport { secretsStoreDeriveName } from \"./secrets-store.naming.js\";\n\ninterface CFSecretsStore {\n id: string;\n name: string;\n}\n\n/**\n * Match each declared store against `GET /accounts/{id}/secrets_store/stores`\n * and upsert into state. Stack-scoped: `resources` is already filtered to\n * the current config so we never persist a store owned by another stack\n * sharing this state row.\n */\nexport function secretsStoreSync(\n allStores: CFSecretsStore[],\n resources: SecretsStoreResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = secretsStoreDeriveName(config, env, naming);\n const match = allStores.find((s) => s.name === derivedName);\n if (!match) continue;\n const key = `secrets_store:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n const entry: SecretsStoreStateEntry = {\n type: \"secrets_store\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: naming.secretsStoreBindingKey(config.logicalName),\n cfId: match.id,\n createdAt:\n existing?.type === \"secrets_store\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { SecretsStoreResourceConfig } from \"./secrets-store.types.js\";\nimport type { SecretsStoreStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { secretsStoreDeriveName } from \"./secrets-store.naming.js\";\n\ninterface CFSecretsStore {\n id: string;\n name: string;\n}\n\nexport function secretsStoreDrift(\n allStores: CFSecretsStore[],\n resources: SecretsStoreResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"secret_store\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allStores.map((s) => [s.name, s]));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is SecretsStoreStateEntry => e.type === \"secrets_store\",\n );\n\n for (const config of resources) {\n const derivedName = secretsStoreDeriveName(config, env, naming);\n const inCloudflare = cfByName.has(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !inCloudflare) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (inCloudflare && !stateEntry) {\n const cf = cfByName.get(derivedName)!;\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId: cf.id,\n });\n } else if (!inCloudflare && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, SecretsStoreStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function secretsStoreDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(\n config,\n baseDir,\n \"secret_store\",\n );\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, SecretsStoreStateEntry] =>\n kv[1].type === \"secrets_store\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.secretsStoreDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Failed to delete Secrets Store ${entry.derivedName}:`,\n err,\n );\n }\n }\n}\n","import type { SecretsStoreStateEntry, ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { SecretsStoreResourceConfig } from \"./secrets-store.types.js\";\nimport { secretsStoreDeriveName } from \"./secrets-store.naming.js\";\n\nexport interface SecretsStoreStatusResult {\n binding: string;\n name: string;\n cfId?: string;\n status: ResourceStatus;\n}\n\nexport function secretsStoreStatus(\n resources: SecretsStoreResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): SecretsStoreStatusResult[] {\n const out: SecretsStoreStatusResult[] = [];\n for (const config of resources) {\n const derivedName = secretsStoreDeriveName(config, env, naming);\n const entry = state.get(`secrets_store:${derivedName}`) as\n | SecretsStoreStateEntry\n | undefined;\n out.push({\n binding: naming.secretsStoreBindingKey(config.logicalName),\n name: derivedName,\n cfId: entry?.cfId,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { SecretsStoreResourceConfig } from \"./secrets-store.types.js\";\nimport type {\n SecretsStoreStateEntry,\n WorkerConfig,\n WorkerResources,\n} from \"../../types.js\";\nimport { secretsStoreApply } from \"./secrets-store.apply.js\";\nimport { secretsStoreSync } from \"./secrets-store.sync.js\";\nimport { secretsStoreDrift } from \"./secrets-store.drift.js\";\nimport { secretsStoreDestroy } from \"./secrets-store.destroy.js\";\nimport { secretsStoreStatus } from \"./secrets-store.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { secretsStoreDeriveName } from \"./secrets-store.naming.js\";\n\ninterface CFSecretsStore {\n id: string;\n name: string;\n}\n\nexport const secretsStoreModule: ResourceModule<\n SecretsStoreResourceConfig,\n CFSecretsStore\n> = {\n kind: \"secret_store\",\n label: \"Secrets Store\",\n configKey: \"secretsStores\",\n stateEntryType: \"secrets_store\",\n\n async fetchAll(api: CFApiClient): Promise<CFSecretsStore[]> {\n const all = await api.secretsStoreListAll();\n return all.map((s) => ({ id: s.id, name: s.name }));\n },\n\n async apply(ctx) {\n await secretsStoreApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n secretsStoreSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return secretsStoreDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n async destroy(ctx) {\n await secretsStoreDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return secretsStoreStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n /**\n * Stores themselves contribute no wrangler binding — `secrets_store_secrets[]`\n * rows are emitted in `generator.ts` after all module fragments merge,\n * because they reference the worker's `secretsStoreSecrets` (a separate\n * deploy-time field, not a managed lifecycle resource).\n */\n generate() {\n return {};\n },\n\n /**\n * No `diff()` opt-in: Cloudflare's Secrets Store API exposes **no update\n * endpoint** for stores themselves (only `POST` / `GET` / `DELETE`;\n * `PATCH /accounts/{id}/secrets_store/stores/{store_id}/secrets/{secret_id}`\n * targets individual *secrets*, which Tamer deliberately does not manage —\n * see `SECRETS_STORE_DEFAULTS`). `SecretsStoreResourceConfig` is also just\n * `{ logicalName }`, so there are no Tamer-tracked fields whose drift could\n * become an `update` plan item. Renaming a store's `logicalName` changes\n * the **derived** name (identity), which falls into the registry's normal\n * delete-and-recreate path via `pickResources` / `destroyOne`. If\n * Cloudflare ever exposes per-store mutable settings (e.g. retention,\n * region pin), wire them through `SECRETS_STORE_DEFAULTS` and add a\n * `diff()` here following the AI Gateway / Hyperdrive pattern.\n */\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): SecretsStoreResourceConfig[] {\n return resourcesFrom(source)?.secretsStores ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"secrets_store\") return;\n try {\n await api.secretsStoreDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete Secrets Store ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const resourceConfig =\n await findWorkerResourceByLogicalName<SecretsStoreResourceConfig>(\n config,\n \"secretsStores\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import secret_store: no resources.secretsStores entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.secretsStoreListAll();\n const derivedName = secretsStoreDeriveName(resourceConfig, env, naming);\n const hit = all.find((s) => s.name === derivedName);\n if (!hit) {\n throw new Error(\n `import secret_store: no store named \"${derivedName}\" found in account`,\n );\n }\n if (options.cfId && hit.id !== options.cfId) {\n throw new Error(\n `import secret_store: cf id \"${hit.id}\" does not match --cf-id \"${options.cfId}\"`,\n );\n }\n const key = `secrets_store:${derivedName}`;\n const existing = state.get(key);\n const entry: SecretsStoreStateEntry = {\n type: \"secrets_store\",\n logicalName: options.logical,\n derivedName,\n bindingKey: naming.secretsStoreBindingKey(options.logical),\n cfId: hit.id,\n createdAt:\n existing?.type === \"secrets_store\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","/**\n * Single source of truth for Tamer-managed Cloudflare resource kinds.\n *\n * To add a new resource (e.g. Pipelines, Workflows, Pages):\n * 1. Add the config + state types to `src/types.ts` and Zod schema.\n * 2. Implement the per-resource feature module under `src/features/<kind>/`.\n * 3. Author `<kind>.module.ts` exporting a {@link ResourceModule}.\n * 4. Append it to {@link resourceModules} below.\n *\n * Every command (`apply`, `sync`, `drift`, `destroy`, `status`, `import`,\n * the wrangler generator) iterates this array — no additional plumbing is\n * required for the resource to be honored across all commands.\n */\n\nimport type { ResourceKind, ResourceModule } from \"./types.js\";\nimport { d1Module } from \"../../features/d1/d1.module.js\";\nimport { r2Module } from \"../../features/r2/r2.module.js\";\nimport { kvModule } from \"../../features/kv/kv.module.js\";\nimport { queuesModule } from \"../../features/queues/queues.module.js\";\nimport { hyperdriveModule } from \"../../features/hyperdrive/hyperdrive.module.js\";\nimport { vectorizeModule } from \"../../features/vectorize/vectorize.module.js\";\nimport { aiGatewayModule } from \"../../features/ai-gateway/ai-gateway.module.js\";\nimport { pipelinesModule } from \"../../features/pipelines/pipelines.module.js\";\nimport { workflowsModule } from \"../../features/workflows/workflows.module.js\";\nimport { secretsStoreModule } from \"../../features/secrets-store/secrets-store.module.js\";\n\nexport const resourceModules: ReadonlyArray<ResourceModule> = [\n d1Module as ResourceModule,\n r2Module as ResourceModule,\n kvModule as ResourceModule,\n queuesModule as ResourceModule,\n hyperdriveModule as ResourceModule,\n vectorizeModule as ResourceModule,\n aiGatewayModule as ResourceModule,\n pipelinesModule as ResourceModule,\n workflowsModule as ResourceModule,\n secretsStoreModule as ResourceModule,\n];\n\nconst moduleByKind: Map<ResourceKind, ResourceModule> = new Map(\n resourceModules.map((m) => [m.kind, m]),\n);\n\n/** Lookup by stable kind. Returns `undefined` for unknown kinds. */\nexport function getResourceModule(\n kind: ResourceKind,\n): ResourceModule | undefined {\n return moduleByKind.get(kind);\n}\n\n/** Throws if no module is registered for `kind`. */\nexport function requireResourceModule(kind: ResourceKind): ResourceModule {\n const m = moduleByKind.get(kind);\n if (!m) throw new Error(`No registered resource module for kind \"${kind}\"`);\n return m;\n}\n\nexport type { ResourceKind, ResourceModule } from \"./types.js\";\n"],"mappings":";;;;;AAgBA,SAAS,gBACP,IACA,UACA,KACA,KACoB;AACpB,KAAI,CAAC,GAAI,QAAO;AAChB,QAAO,GAAG,UAAU,KAAK,IAAI;;;AAI/B,SAAgB,wBACd,QACA,KACA,QACA,WACQ;CACR,MAAM,WAAW,OAAO;AACxB,KAAI,OAAO,SAAS,UAAU;EAC5B,MAAMA,aAAW,gBAAgB,OAAO,gBAAgB,UAAU,IAAI;AACtE,MAAIA,eAAa,OAAW,QAAOA;AACnC,SAAO,OAAO,aAAa,OAAO,aAAa,IAAI;;AAErD,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,eAAe,OAAO,YAAY,sBAAsB;CAE1E,MAAM,WAAW,gBAAgB,OAAO,gBAAgB,UAAU,KAAK,EACrE,WACD,CAAC;AACF,KAAI,aAAa,OAAW,QAAO;AACnC,QAAO,OAAO,YAAY,OAAO,aAAa,WAAW,IAAI;;AAG/D,SAAgB,wBACd,QACA,KACA,QACQ;CACR,MAAM,WAAW,gBACf,OAAO,gBACP,OAAO,UACP,IACD;AACD,KAAI,aAAa,OAAW,QAAO;AACnC,QAAO,OAAO,aAAa,OAAO,aAAa,IAAI;;AAGrD,SAAgB,8BACd,QACA,KACA,QACQ;CACR,MAAM,WAAW,gBACf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;CAIL,MAAM,UAAU,EAAE,SAAS,KAAK,KAAK,OAAO,QAAQ,QAAQ,SAAS,MAAM;EACzE,MAAM,iBACJ,MAAM,gCACJ,QACA,iBACA,QAAQ,SACR,QACD;AACH,MAAI,CAAC,eACH,OAAM,IAAI,MACR,2EAA2E,QAAQ,QAAQ,+BAC5F;EAEH,MAAM,MAAM,MAAM,IAAI,qBAAqB;EAC3C,MAAM,cAAc,uBAAuB,gBAAgB,KAAK,OAAO;EACvE,MAAM,MAAM,IAAI,MAAM,MAAM,EAAE,SAAS,YAAY;AACnD,MAAI,CAAC,IACH,OAAM,IAAI,MACR,wCAAwC,YAAY,oBACrD;AAEH,MAAI,QAAQ,QAAQ,IAAI,OAAO,QAAQ,KACrC,OAAM,IAAI,MACR,+BAA+B,IAAI,GAAG,4BAA4B,QAAQ,KAAK,GAChF;EAEH,MAAM,MAAM,iBAAiB;EAC7B,MAAM,WAAW,MAAM,IAAI,IAAI;EAC/B,MAAMC,QAAgC;GACpC,MAAM;GACN,aAAa,QAAQ;GACrB;GACA,YAAY,OAAO,uBAAuB,QAAQ,QAAQ;GAC1D,MAAM,IAAI;GACV,WACE,UAAU,SAAS,kBAAkB,SAAS,YAAY;GAC5D,WAAW;GACZ;AACD,QAAM,IAAI,KAAK,MAAM;;CAExB;;;;AC7ID,MAAaC,kBAAiD;CAC5D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAMC,eAAkD,IAAI,IAC1D,gBAAgB,KAAK,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CACxC;;AAGD,SAAgB,kBACd,MAC4B;AAC5B,QAAO,aAAa,IAAI,KAAK"}
|
|
1
|
+
{"version":3,"file":"registry-BlTu3xMp.mjs","names":["override","todayIso","derivedName","uuid","compact","iso","drift: ResourceDrift","bindings: WranglerD1Database[]","results: D1StatusResult[]","d1Module: ResourceModule<D1ResourceConfig, CFD1>","entry: D1StateEntry","errors: string[]","drift: ResourceDrift","bindings: WranglerR2Bucket[]","results: R2StatusResult[]","r2Module: ResourceModule<R2ResourceConfig, CFR2>","entry: R2StateEntry","drift: ResourceDrift","bindings: WranglerKVNamespace[]","results: KVStatusResult[]","kvModule: ResourceModule<KVResourceConfig, CFKv>","entry: KVStateEntry","STATE_KEY_PREFIX","stateKey","drift: ResourceDrift","producers: Array<{ binding: string; queue: string }>","out: QueuesStatusResult[]","queuesModule: ResourceModule<QueueResourceConfig, CFQueue>","out: NonNullable<\n import(\"../../generated/wrangler-types.js\").WranglerConfig[\"queues\"]\n >","entry: QueueStateEntry","items: PlanItem[]","computeChanges","formatVal","changes: PlanFieldChange[]","STATE_KEY_PREFIX","stateKey","origin","drift: ResourceDrift","out: GeneratedHyperdriveBinding[]","out: HyperdriveStatusResult[]","hyperdriveModule: ResourceModule<\n HyperdriveResourceConfig,\n CFHyperdrive\n>","entry: HyperdriveStateEntry","STATE_KEY_PREFIX","stateKey","drift: ResourceDrift","out: GeneratedVectorizeBinding[]","out: VectorizeStatusResult[]","items: PlanItem[]","changes: PlanFieldChange[]","vectorizeModule: ResourceModule<\n VectorizeResourceConfig,\n CFVectorize\n>","entry: VectorizeStateEntry","items: PlanItem[]","formatVal","changes: PlanFieldChange[]","STATE_KEY_PREFIX","stateKey","drift: ResourceDrift","out: AIGatewayStatusResult[]","aiGatewayModule: ResourceModule<\n AIGatewayResourceConfig,\n CFAIGateway\n>","entry: AIGatewayStateEntry","STATE_KEY_PREFIX","stateKey","drift: ResourceDrift","out: GeneratedPipelineBinding[]","out: PipelineStatusResult[]","items: PlanItem[]","changes: PlanFieldChange[]","pipelinesModule: ResourceModule<\n PipelineResourceConfig,\n CFPipeline\n>","entry: PipelineStateEntry","items: PlanItem[]","changes: PlanFieldChange[]","STATE_KEY_PREFIX","stateKey","upserted: Awaited<ReturnType<typeof api.workflowUpsert>>","entry: WorkflowStateEntry","entry: WorkflowStateEntry","drift: ResourceDrift","out: GeneratedWorkflowBinding[]","binding: GeneratedWorkflowBinding","out: WorkflowStatusResult[]","workflowsModule: ResourceModule<\n WorkflowResourceConfig,\n CFWorkflow\n>","entry: WorkflowStateEntry","allStores:\n | Awaited<ReturnType<typeof api.secretsStoreListAll>>\n | null","cfId: string","entry: SecretsStoreStateEntry","entry: SecretsStoreStateEntry","drift: ResourceDrift","out: SecretsStoreStatusResult[]","secretsStoreModule: ResourceModule<\n SecretsStoreResourceConfig,\n CFSecretsStore\n>","entry: SecretsStoreStateEntry","resourceModules: ReadonlyArray<ResourceModule>","moduleByKind: Map<ResourceKind, ResourceModule>"],"sources":["../src/core/naming/resolveCloudflareName.ts","../src/features/d1/d1.ownership.ts","../src/features/d1/d1.naming.ts","../src/features/d1/d1.apply.ts","../src/features/d1/d1.sync.ts","../src/features/d1/d1.drift.ts","../src/core/config/resourcesFromConfig.ts","../src/features/d1/d1.destroy.ts","../src/features/d1/d1.generate.ts","../src/features/d1/d1.status.ts","../src/core/registry/pickResources.ts","../src/core/registry/findResourceForImport.ts","../src/features/d1/d1.module.ts","../src/features/r2/r2.naming.ts","../src/features/r2/r2.apply.ts","../src/features/r2/r2.sync.ts","../src/features/r2/r2.drift.ts","../src/features/r2/r2.destroy.ts","../src/features/r2/r2.generate.ts","../src/features/r2/r2.status.ts","../src/features/r2/r2.module.ts","../src/features/kv/kv.naming.ts","../src/features/kv/kv.apply.ts","../src/features/kv/kv.sync.ts","../src/features/kv/kv.drift.ts","../src/features/kv/kv.destroy.ts","../src/features/kv/kv.generate.ts","../src/features/kv/kv.status.ts","../src/features/kv/kv.module.ts","../src/features/queues/queues.naming.ts","../src/features/queues/queues.apply.ts","../src/features/queues/queues.sync.ts","../src/features/queues/queues.drift.ts","../src/features/queues/queues.destroy.ts","../src/features/queues/queues.generate.ts","../src/features/queues/queues.status.ts","../src/features/queues/queues.module.ts","../src/features/hyperdrive/hyperdrive.secrets.ts","../src/features/hyperdrive/hyperdrive.naming.ts","../src/features/hyperdrive/hyperdrive.diff.ts","../src/features/hyperdrive/hyperdrive.apply.ts","../src/features/hyperdrive/hyperdrive.sync.ts","../src/features/hyperdrive/hyperdrive.drift.ts","../src/features/hyperdrive/hyperdrive.destroy.ts","../src/features/hyperdrive/hyperdrive.generate.ts","../src/features/hyperdrive/hyperdrive.status.ts","../src/features/hyperdrive/hyperdrive.module.ts","../src/features/vectorize/vectorize.naming.ts","../src/features/vectorize/vectorize.apply.ts","../src/features/vectorize/vectorize.sync.ts","../src/features/vectorize/vectorize.drift.ts","../src/features/vectorize/vectorize.destroy.ts","../src/features/vectorize/vectorize.generate.ts","../src/features/vectorize/vectorize.status.ts","../src/features/vectorize/vectorize.diff.ts","../src/features/vectorize/vectorize.module.ts","../src/features/ai-gateway/ai-gateway.types.ts","../src/features/ai-gateway/ai-gateway.naming.ts","../src/features/ai-gateway/ai-gateway.diff.ts","../src/features/ai-gateway/ai-gateway.apply.ts","../src/features/ai-gateway/ai-gateway.sync.ts","../src/features/ai-gateway/ai-gateway.drift.ts","../src/features/ai-gateway/ai-gateway.destroy.ts","../src/features/ai-gateway/ai-gateway.status.ts","../src/features/ai-gateway/ai-gateway.module.ts","../src/features/pipelines/pipelines.naming.ts","../src/features/pipelines/pipelines.apply.ts","../src/features/pipelines/pipelines.sync.ts","../src/features/pipelines/pipelines.drift.ts","../src/features/pipelines/pipelines.destroy.ts","../src/features/pipelines/pipelines.generate.ts","../src/features/pipelines/pipelines.status.ts","../src/features/pipelines/pipelines.diff.ts","../src/features/pipelines/pipelines.module.ts","../src/features/workflows/workflows.naming.ts","../src/features/workflows/workflows.diff.ts","../src/features/workflows/workflows.apply.ts","../src/features/workflows/workflows.sync.ts","../src/features/workflows/workflows.drift.ts","../src/features/workflows/workflows.destroy.ts","../src/features/workflows/workflows.generate.ts","../src/features/workflows/workflows.status.ts","../src/features/workflows/workflows.module.ts","../src/features/secrets-store/secrets-store.naming.ts","../src/features/secrets-store/secrets-store.apply.ts","../src/features/secrets-store/secrets-store.sync.ts","../src/features/secrets-store/secrets-store.drift.ts","../src/features/secrets-store/secrets-store.destroy.ts","../src/features/secrets-store/secrets-store.status.ts","../src/features/secrets-store/secrets-store.module.ts","../src/core/registry/registry.ts"],"sourcesContent":["import type {\n AIGatewayResourceConfig,\n CloudflareNameContext,\n CloudflareNameFn,\n D1ResourceConfig,\n HyperdriveResourceConfig,\n KVResourceConfig,\n PipelineResourceConfig,\n QueueResourceConfig,\n R2ResourceConfig,\n SecretsStoreResourceConfig,\n VectorizeResourceConfig,\n WorkflowResourceConfig,\n} from \"../../types.js\";\nimport type { NamingEngine } from \"./NamingEngine.js\";\n\nfunction resolveOverride(\n fn: CloudflareNameFn | undefined,\n tenantId: string,\n env: string,\n ctx?: CloudflareNameContext,\n): string | undefined {\n if (!fn) return undefined;\n return fn(tenantId, env, ctx);\n}\n\n/** Managed D1 Cloudflare database name (not external `databaseName`). */\nexport function resolveD1CloudflareName(\n config: D1ResourceConfig,\n env: string,\n naming: NamingEngine,\n shardDate?: string,\n): string {\n const tenantId = naming.tenantId;\n if (config.type === \"single\") {\n const override = resolveOverride(config.cloudflareName, tenantId, env);\n if (override !== undefined) return override;\n return naming.d1SingleName(config.logicalName, env);\n }\n if (!shardDate) {\n throw new Error(`Sharded D1 \"${config.logicalName}\" requires shardDate`);\n }\n const override = resolveOverride(config.cloudflareName, tenantId, env, {\n shardDate,\n });\n if (override !== undefined) return override;\n return naming.d1ShardName(config.logicalName, shardDate, env);\n}\n\nexport function resolveR2CloudflareName(\n config: R2ResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.r2BucketName(config.logicalName, env);\n}\n\nexport function resolveWorkflowCloudflareName(\n config: WorkflowResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.workflowName(config.logicalName, env);\n}\n\nexport function resolveKVCloudflareName(\n config: KVResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.kvNamespaceName(config.logicalName, env);\n}\n\nexport function resolveQueueCloudflareName(\n config: QueueResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.queueName(config.logicalName, env);\n}\n\nexport function resolveHyperdriveCloudflareName(\n config: HyperdriveResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.hyperdriveName(config.logicalName, env);\n}\n\nexport function resolveVectorizeCloudflareName(\n config: VectorizeResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.vectorizeName(config.logicalName, env);\n}\n\nexport function resolveAIGatewayCloudflareName(\n config: AIGatewayResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.aiGatewayId(config.logicalName, env);\n}\n\nexport function resolvePipelineCloudflareName(\n config: PipelineResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.pipelineName(config.logicalName, env);\n}\n\nexport function resolveSecretsStoreCloudflareName(\n config: SecretsStoreResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n const override = resolveOverride(\n config.cloudflareName,\n naming.tenantId,\n env,\n );\n if (override !== undefined) return override;\n return naming.secretsStoreName(config.logicalName, env);\n}\n","import type { D1ResourceConfig } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveD1CloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\n\nexport function d1IsExternal(config: D1ResourceConfig): boolean {\n return config.ownership === \"external\";\n}\n\n/**\n * Skip provision / migrate / Cloudflare delete for this binding.\n * `preserveOnDestroy` alone keeps legacy \"same derived name as owner\" behaviour.\n */\nexport function d1SkipsProvisionAndMigrate(config: D1ResourceConfig): boolean {\n return d1IsExternal(config) || config.preserveOnDestroy === true;\n}\n\n/** Cloudflare D1 database name for state keys, sync, and wrangler `database_name`. */\nexport function d1CloudflareDatabaseName(\n config: D1ResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n if (config.type !== \"single\") {\n throw new Error(\n `D1 \"${config.logicalName}\": expected type \"single\" for derived database name`,\n );\n }\n if (d1IsExternal(config)) {\n const n = config.databaseName;\n if (typeof n !== \"string\" || !n.trim()) {\n throw new Error(\n `D1 \"${config.logicalName}\" has ownership \"external\" but databaseName is empty — ` +\n `ensure imports are pre-fetched and config is merged with resolveWorkerConfig / mergeWorkerConfigWithResolvedRefs.`,\n );\n }\n return n.trim();\n }\n return resolveD1CloudflareName(config, env, naming);\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveD1CloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { D1ResourceConfig } from \"./d1.types.js\";\n\n/** Normalize config/import shard dates to ISO `YYYY-MM-DD`. */\nexport function normalizeShardDateIso(raw: string): string {\n const trimmed = raw.trim();\n if (/^\\d{8}$/.test(trimmed)) {\n return `${trimmed.slice(0, 4)}-${trimmed.slice(4, 6)}-${trimmed.slice(6, 8)}`;\n }\n if (/^\\d{4}-\\d{2}-\\d{2}$/.test(trimmed)) {\n return trimmed;\n }\n throw new Error(\n `Invalid shardDate \"${raw}\" — use YYYY-MM-DD or YYYYMMDD`,\n );\n}\n\nexport function d1DeriveName(\n config: D1ResourceConfig,\n env: string,\n shardDate: string | undefined,\n naming: NamingEngine,\n): string {\n if (config.type === \"single\") {\n return resolveD1CloudflareName(config, env, naming);\n }\n const resolved = shardDate ?? config.shardDate;\n if (!resolved) {\n throw new Error(`Sharded D1 \"${config.logicalName}\" requires shardDate`);\n }\n return resolveD1CloudflareName(\n config,\n env,\n naming,\n normalizeShardDateIso(resolved),\n );\n}\n\nexport function d1DeriveBindingKey(\n config: D1ResourceConfig,\n shardDate: string | undefined,\n naming: NamingEngine,\n): string {\n const explicit = config.binding?.trim();\n if (config.type === \"single\") {\n return explicit || naming.d1SingleBindingKey(config.logicalName);\n }\n if (explicit) {\n return explicit;\n }\n const resolved = shardDate ?? config.shardDate;\n if (!resolved) {\n throw new Error(`Sharded D1 \"${config.logicalName}\" requires shardDate`);\n }\n return naming.d1ShardBindingKey(\n config.logicalName,\n normalizeShardDateIso(resolved),\n );\n}\n\n/** Shard date stored on state rows (ISO), from config pin or CF name extraction. */\nexport function d1ResolveShardDateIso(\n config: D1ResourceConfig,\n extractedFromName: string | null | undefined,\n): string | undefined {\n if (config.type !== \"sharded\") return undefined;\n if (config.shardDate) {\n return normalizeShardDateIso(config.shardDate);\n }\n return extractedFromName ?? undefined;\n}\n\nexport function d1MatchPattern(\n config: D1ResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n if (config.type === \"single\") {\n const exactName = resolveD1CloudflareName(config, env, naming);\n return (name: string) => name === exactName;\n }\n\n const pinnedIso = config.shardDate\n ? normalizeShardDateIso(config.shardDate)\n : undefined;\n\n if (config.cloudflareName || naming.hasD1ShardConvention()) {\n return (name: string) => {\n const shardDate = d1ExtractShardDate(name, naming);\n if (!shardDate) return false;\n if (pinnedIso && normalizeShardDateIso(shardDate) !== pinnedIso) {\n return false;\n }\n try {\n return resolveD1CloudflareName(config, env, naming, shardDate) === name;\n } catch {\n return false;\n }\n };\n }\n\n const base = naming.d1MatchPattern(config.logicalName, env);\n if (!pinnedIso) return base;\n return (name: string) => {\n if (!base(name)) return false;\n const shardDate = d1ExtractShardDate(name, naming);\n return shardDate !== null && normalizeShardDateIso(shardDate) === pinnedIso;\n };\n}\n\nexport function d1ExtractShardDate(name: string, naming: NamingEngine): string | null {\n return naming.extractD1ShardDate(name);\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { D1ResourceConfig } from \"./d1.types.js\";\nimport {\n d1CloudflareDatabaseName,\n d1SkipsProvisionAndMigrate,\n} from \"./d1.ownership.js\";\nimport { d1DeriveName, d1DeriveBindingKey, normalizeShardDateIso } from \"./d1.naming.js\";\n\nfunction todayNoDashes(): string {\n return new Date().toISOString().slice(0, 10).replace(/-/g, \"\");\n}\n\nfunction todayIso(): string {\n return new Date().toISOString().slice(0, 10);\n}\n\nfunction resolveInitialShardDate(config: D1ResourceConfig): {\n iso: string;\n compact: string;\n} {\n if (config.shardDate) {\n const iso = normalizeShardDateIso(config.shardDate);\n return { iso, compact: iso.replace(/-/g, \"\") };\n }\n return { iso: todayIso(), compact: todayNoDashes() };\n}\n\nexport async function d1Apply(\n resources: D1ResourceConfig[],\n tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n addShard?: string\n): Promise<void> {\n for (const config of resources) {\n if (config.type === \"single\") {\n const derivedName = d1CloudflareDatabaseName(config, env, naming);\n const existing = state.get(derivedName);\n if (existing) continue;\n\n if (d1SkipsProvisionAndMigrate(config)) {\n console.warn(\n `[apply] Skipping D1 create for \"${config.logicalName}\" (external / preserveOnDestroy). ` +\n `Run \\`tamer sync\\` after the owning stack has created ${derivedName}.`,\n );\n continue;\n }\n\n const { uuid } = await api.d1Create(derivedName);\n state.set(derivedName, {\n type: \"d1_database\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: d1DeriveBindingKey(config, undefined, naming),\n cfId: uuid,\n migrationsDir: config.migrationsDir,\n preserveOnDestroy: false,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n continue;\n }\n\n if (addShard && addShard !== config.logicalName) continue;\n if (addShard && addShard === config.logicalName) {\n const { iso, compact } = resolveInitialShardDate(config);\n const derivedName = d1DeriveName(config, env, compact, naming);\n const existing = state.get(derivedName);\n if (existing) continue;\n\n const { uuid } = await api.d1Create(derivedName);\n state.set(derivedName, {\n type: \"d1_database\",\n logicalName: config.logicalName,\n shardDate: iso,\n derivedName,\n bindingKey: d1DeriveBindingKey(config, iso, naming),\n cfId: uuid,\n migrationsDir: config.migrationsDir,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n continue;\n }\n\n const allResources = state.getAll();\n const existingShards = Object.values(allResources).filter(\n (e) => e.type === \"d1_database\" && \"logicalName\" in e && e.logicalName === config.logicalName\n );\n if (existingShards.length > 0) continue;\n\n const { iso, compact } = resolveInitialShardDate(config);\n const derivedName = d1DeriveName(config, env, compact, naming);\n const { uuid } = await api.d1Create(derivedName);\n state.set(derivedName, {\n type: \"d1_database\",\n logicalName: config.logicalName,\n shardDate: iso,\n derivedName,\n bindingKey: d1DeriveBindingKey(config, iso, naming),\n cfId: uuid,\n migrationsDir: config.migrationsDir,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { D1ResourceConfig, D1StateEntry } from \"./d1.types.js\";\nimport { d1MatchPattern, d1ExtractShardDate, d1DeriveBindingKey, d1ResolveShardDateIso } from \"./d1.naming.js\";\nimport {\n d1CloudflareDatabaseName,\n d1SkipsProvisionAndMigrate,\n} from \"./d1.ownership.js\";\n\ninterface CFD1Database {\n uuid: string;\n name: string;\n created_at: string;\n}\n\nexport function d1Sync(\n allD1: CFD1Database[],\n resources: D1ResourceConfig[],\n tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine\n): void {\n for (const config of resources) {\n const pattern = d1MatchPattern(config, env, naming);\n\n if (config.type === \"single\") {\n const derivedKey = d1CloudflareDatabaseName(config, env, naming);\n const match = allD1.find((db) => db.name === derivedKey);\n if (match) {\n state.set(match.name, {\n type: \"d1_database\",\n logicalName: config.logicalName,\n derivedName: match.name,\n bindingKey: d1DeriveBindingKey(config, undefined, naming),\n cfId: match.uuid,\n migrationsDir: config.migrationsDir,\n preserveOnDestroy: d1SkipsProvisionAndMigrate(config),\n createdAt: match.created_at,\n updatedAt: new Date().toISOString(),\n });\n }\n continue;\n }\n\n const shards = allD1.filter((db) => pattern(db.name));\n for (const shard of shards) {\n const extracted = d1ExtractShardDate(shard.name, naming);\n const shardDateIso = d1ResolveShardDateIso(config, extracted);\n if (!shardDateIso) continue;\n\n state.set(shard.name, {\n type: \"d1_database\",\n logicalName: config.logicalName,\n shardDate: shardDateIso,\n derivedName: shard.name,\n bindingKey: d1DeriveBindingKey(config, shardDateIso, naming),\n cfId: shard.uuid,\n migrationsDir: config.migrationsDir,\n createdAt: shard.created_at,\n updatedAt: new Date().toISOString(),\n });\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { D1ResourceConfig, D1StateEntry } from \"./d1.types.js\";\nimport { d1MatchPattern, d1ExtractShardDate } from \"./d1.naming.js\";\nimport { d1CloudflareDatabaseName } from \"./d1.ownership.js\";\nimport type { ResourceDrift, DriftEntry } from \"../../core/drift/drift.types.js\";\n\ninterface CFD1Database {\n uuid: string;\n name: string;\n}\n\n/**\n * Diff D1 state against the Cloudflare list and the current config.\n *\n * - **single**: one expected derived name per resource.\n * - **sharded**: every CF database matching the pattern is \"expected\"; state\n * should contain an entry for each.\n */\nexport function d1Drift(\n allD1: CFD1Database[],\n resources: D1ResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"d1\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allD1.map((db) => [db.name, db.uuid]));\n const allState = state.getAll();\n const d1State = Object.values(allState).filter(\n (e): e is D1StateEntry => e.type === \"d1_database\",\n );\n\n for (const config of resources) {\n if (config.type === \"single\") {\n const derivedName = d1CloudflareDatabaseName(config, env, naming);\n const cfId = cfByName.get(derivedName);\n const stateEntry = d1State.find(\n (e) => e.logicalName === config.logicalName && !e.shardDate,\n );\n\n if (stateEntry && !cfId) {\n drift.missingFromCloudflare.push(toEntry(stateEntry));\n } else if (cfId && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId,\n });\n } else if (!cfId && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n continue;\n }\n\n const pattern = d1MatchPattern(config, env, naming);\n const cfShards = allD1.filter((db) => pattern(db.name));\n const cfShardNames = new Set(cfShards.map((s) => s.name));\n const stateShards = d1State.filter(\n (e) => e.logicalName === config.logicalName && !!e.shardDate,\n );\n const stateShardNames = new Set(stateShards.map((s) => s.derivedName));\n\n for (const shard of stateShards) {\n if (!cfShardNames.has(shard.derivedName)) {\n drift.missingFromCloudflare.push(toEntry(shard));\n }\n }\n for (const shard of cfShards) {\n if (!stateShardNames.has(shard.name)) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName: shard.name,\n cfId: shard.uuid,\n detail: d1ExtractShardDate(shard.name, naming) ?? undefined,\n });\n }\n }\n if (cfShards.length === 0 && stateShards.length === 0) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName: `(no shards for ${config.logicalName})`,\n });\n }\n }\n\n return drift;\n}\n\nfunction toEntry(e: D1StateEntry): DriftEntry {\n return {\n logicalName: e.logicalName,\n derivedName: e.derivedName,\n cfId: e.cfId,\n detail: e.shardDate,\n };\n}\n","import type { CfiConfig } from \"../../types.js\";\nimport { getWorkers } from \"./loader.js\";\nimport {\n getResourceModule,\n type ResourceKind,\n} from \"../registry/registry.js\";\n\n/**\n * Logical resource names declared on workers in this config (for\n * stack-scoped destroy / drift). Iterates the resource registry — adding a\n * new kind doesn't require editing this file.\n */\nexport async function logicalNamesForResourceKind(\n config: CfiConfig,\n baseDir: string,\n kind: ResourceKind,\n): Promise<Set<string>> {\n const mod = getResourceModule(kind);\n if (!mod) return new Set();\n const workers = await getWorkers(config, baseDir);\n const set = new Set<string>();\n for (const [, wc] of workers) {\n for (const r of mod.pickResources(wc)) {\n const logical = (r as { logicalName?: string }).logicalName;\n if (logical) set.add(logical);\n }\n }\n return set;\n}\n","import type { CfiConfig } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\nimport type { D1StateEntry } from \"./d1.types.js\";\n\nexport async function d1Destroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"d1\");\n const resources = state.getAll();\n const d1Entries = Object.values(resources).filter(\n (e): e is D1StateEntry => e.type === \"d1_database\",\n );\n\n for (const entry of d1Entries) {\n if (!owned.has(entry.logicalName)) continue;\n if (entry.preserveOnDestroy) {\n console.log(\n `Skipping D1 destroy for ${entry.derivedName} (preserveOnDestroy / cross-stack binding).`,\n );\n continue;\n }\n try {\n await api.d1Delete(entry.cfId);\n state.delete(entry.derivedName);\n } catch (err) {\n console.warn(`Failed to delete D1 ${entry.derivedName}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { D1ResourceConfig, D1StateEntry } from \"./d1.types.js\";\nimport {\n d1CloudflareDatabaseName,\n d1SkipsProvisionAndMigrate,\n} from \"./d1.ownership.js\";\nimport type { WranglerD1Database } from \"../../generated/wrangler-types.js\";\nimport type { StateEntry } from \"../../types.js\";\n\nexport interface D1StateLike {\n get(derivedName: string): StateEntry | undefined;\n getAll(): Record<string, StateEntry>;\n}\n\nexport function d1Generate(\n resources: D1ResourceConfig[],\n env: string,\n state: D1StateLike,\n naming: NamingEngine\n): WranglerD1Database[] {\n const bindings: WranglerD1Database[] = [];\n\n for (const config of resources) {\n if (config.type === \"single\") {\n const derivedName = d1CloudflareDatabaseName(config, env, naming);\n const entry = state.get(derivedName);\n if (!entry || entry.type !== \"d1_database\") {\n if (d1SkipsProvisionAndMigrate(config)) {\n throw new Error(\n `Cross-stack D1 \"${config.logicalName}\" (${derivedName}) not in state. ` +\n `Deploy the owning stack first, then re-run from this stack ` +\n `(apply now syncs automatically for env \"${env}\").`,\n );\n }\n throw new Error(\n `D1 \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`\n );\n }\n bindings.push({\n binding: entry.bindingKey,\n database_id: entry.cfId,\n database_name: derivedName,\n migrations_dir: config.migrationsDir,\n migrations_table: config.migrationsTable,\n });\n continue;\n }\n\n const allResources = state.getAll();\n const shards = Object.values(allResources).filter(\n (e): e is D1StateEntry =>\n e.type === \"d1_database\" && e.logicalName === config.logicalName\n );\n\n for (const shard of shards) {\n bindings.push({\n binding: shard.bindingKey,\n database_id: shard.cfId,\n database_name: shard.derivedName,\n migrations_dir: config.migrationsDir,\n migrations_table: config.migrationsTable,\n });\n }\n }\n\n return bindings;\n}\n","import type { ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { D1ResourceConfig, D1StateEntry } from \"./d1.types.js\";\nimport { d1CloudflareDatabaseName } from \"./d1.ownership.js\";\nimport { d1DeriveBindingKey } from \"./d1.naming.js\";\n\nexport interface D1StatusResult {\n binding: string;\n name: string;\n cfId: string;\n status: ResourceStatus;\n}\n\nexport function d1Status(\n resources: D1ResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine\n): D1StatusResult[] {\n const results: D1StatusResult[] = [];\n\n for (const config of resources) {\n if (config.type === \"single\") {\n const derivedName = d1CloudflareDatabaseName(config, env, naming);\n const entry = state.get(derivedName) as D1StateEntry | undefined;\n results.push({\n binding: d1DeriveBindingKey(config, undefined, naming),\n name: derivedName,\n cfId: entry?.cfId ?? \"\",\n status: entry ? \"ok\" : \"missing\",\n });\n continue;\n }\n\n const allResources = state.getAll();\n const shards = Object.values(allResources).filter(\n (e): e is D1StateEntry =>\n e.type === \"d1_database\" && e.logicalName === config.logicalName\n );\n\n for (const shard of shards) {\n results.push({\n binding: shard.bindingKey,\n name: shard.derivedName,\n cfId: shard.cfId,\n status: \"ok\",\n });\n }\n\n if (shards.length === 0) {\n const placeholderDate = config.shardDate ?? \"00000000\";\n results.push({\n binding: d1DeriveBindingKey(config, placeholderDate, naming),\n name: `(no shards for ${config.logicalName})`,\n cfId: \"\",\n status: \"missing\",\n });\n }\n }\n\n return results;\n}\n","import type { WorkerConfig, WorkerResources } from \"../../types.js\";\n\n/**\n * Helper used by every {@link ResourceModule.pickResources} so module files\n * can accept either a full `WorkerConfig` (the common path from `apply`,\n * `sync`, `drift`, `status`) or a bare `WorkerResources` (the wrangler\n * generator passes `resolved.resources` directly). Returns `undefined`\n * when no resource map is present.\n */\nexport function resourcesFrom(\n source: WorkerConfig | WorkerResources | undefined,\n): WorkerResources | undefined {\n if (!source) return undefined;\n if (\"resources\" in source) {\n return (source as WorkerConfig).resources;\n }\n return source as WorkerResources;\n}\n","import type { CfiConfig, WorkerResources } from \"../../types.js\";\nimport { getWorkers } from \"../config/loader.js\";\n\n/**\n * Find the first declared resource config matching `logical` across all workers.\n * Used by `tamer import` to validate CF names against {@link cloudflareName} overrides.\n */\nexport async function findWorkerResourceByLogicalName<\n C extends { logicalName: string },\n>(\n config: CfiConfig,\n configKey: keyof WorkerResources,\n logical: string,\n baseDir?: string,\n): Promise<C | undefined> {\n const workers = await getWorkers(config, baseDir);\n for (const [, wc] of workers) {\n const list = wc.resources?.[configKey] as C[] | undefined;\n if (!list) continue;\n const hit = list.find((r) => r.logicalName === logical);\n if (hit) return hit;\n }\n return undefined;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { D1ResourceConfig } from \"./d1.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n D1StateEntry,\n} from \"../../types.js\";\nimport { d1Apply } from \"./d1.apply.js\";\nimport { d1Sync } from \"./d1.sync.js\";\nimport { d1Drift } from \"./d1.drift.js\";\nimport { d1Destroy } from \"./d1.destroy.js\";\nimport { d1Generate } from \"./d1.generate.js\";\nimport { d1Status } from \"./d1.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { d1DeriveName, d1DeriveBindingKey, normalizeShardDateIso } from \"./d1.naming.js\";\n\ninterface CFD1 {\n uuid: string;\n name: string;\n created_at: string;\n}\n\nexport const d1Module: ResourceModule<D1ResourceConfig, CFD1> = {\n kind: \"d1\",\n label: \"D1\",\n configKey: \"d1\",\n stateEntryType: \"d1_database\",\n\n async fetchAll(api: CFApiClient): Promise<CFD1[]> {\n return api.d1ListAll();\n },\n\n async apply(ctx) {\n await d1Apply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n ctx.addShard,\n );\n },\n\n sync(ctx) {\n d1Sync(ctx.all, ctx.resources, ctx.tenant, ctx.env, ctx.state, ctx.naming);\n },\n\n drift(ctx) {\n return d1Drift(ctx.all, ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n async destroy(ctx) {\n await d1Destroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return d1Status(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n if (ctx.resources.length === 0) return {};\n const generated = d1Generate(ctx.resources, ctx.env, ctx.state, ctx.naming);\n const passthrough = ctx.passthrough?.d1_databases ?? [];\n return { d1_databases: [...passthrough, ...generated] };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): D1ResourceConfig[] {\n return resourcesFrom(source)?.d1 ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"d1_database\") return;\n try {\n await api.d1Delete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(`Rollback: failed to delete D1 ${entry.derivedName}:`, err);\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n if (!options.cfId) throw new Error(\"import d1: --cf-id <uuid> is required\");\n const resourceConfig = await findWorkerResourceByLogicalName<D1ResourceConfig>(\n config,\n \"d1\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import d1: no resources.d1 entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.d1ListAll();\n const hit = all.find((d) => d.uuid === options.cfId);\n if (!hit) {\n throw new Error(\n `import d1: D1 database with uuid \"${options.cfId}\" not found in account`,\n );\n }\n const shardDateIso = options.shardDate\n ? normalizeShardDateIso(options.shardDate)\n : resourceConfig.shardDate\n ? normalizeShardDateIso(resourceConfig.shardDate)\n : undefined;\n const derivedName = shardDateIso\n ? d1DeriveName(resourceConfig, env, shardDateIso, naming)\n : d1DeriveName(resourceConfig, env, undefined, naming);\n if (hit.name !== derivedName) {\n throw new Error(\n `import d1: cf name \"${hit.name}\" does not match derived \"${derivedName}\" — wrong --logical, missing --shard-date, or naming convention drift?`,\n );\n }\n const bindingKey = d1DeriveBindingKey(\n resourceConfig,\n shardDateIso,\n naming,\n );\n const existing = state.get(derivedName);\n if (\n existing &&\n existing.type === \"d1_database\" &&\n existing.cfId !== options.cfId\n ) {\n throw new Error(\n `import d1: state already tracks \"${derivedName}\" with a different cfId`,\n );\n }\n const entry: D1StateEntry = {\n type: \"d1_database\",\n logicalName: options.logical,\n shardDate: shardDateIso ?? options.shardDate,\n derivedName,\n bindingKey,\n cfId: options.cfId,\n createdAt: existing?.type === \"d1_database\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(derivedName, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveR2CloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { R2ResourceConfig } from \"./r2.types.js\";\n\nexport function r2DeriveName(\n config: R2ResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveR2CloudflareName(config, env, naming);\n}\n\nexport function r2MatchPattern(\n config: R2ResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n if (config.cloudflareName) {\n const expected = resolveR2CloudflareName(config, env, naming);\n return (name: string) => name === expected;\n }\n return naming.r2MatchPattern(config.logicalName, env);\n}\n\nexport function r2ExtractDate(name: string, naming: NamingEngine): string | null {\n return naming.extractR2Date(name);\n}\n","import type { TenantMeta, R2StateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { R2ResourceConfig } from \"./r2.types.js\";\nimport { r2DeriveName } from \"./r2.naming.js\";\n\nfunction existingR2ForLogical(\n state: StateManager,\n logicalName: string,\n): R2StateEntry | undefined {\n for (const e of Object.values(state.getAll())) {\n if (e.type === \"r2_bucket\" && e.logicalName === logicalName) {\n return e;\n }\n }\n return undefined;\n}\n\nfunction todayIso(): string {\n return new Date().toISOString().slice(0, 10);\n}\n\n// https://developers.cloudflare.com/r2/buckets/create-buckets/#bucket-level-operations\nfunction assertValidR2BucketName(name: string, logicalName: string): void {\n const errors: string[] = [];\n if (name.length < 3 || name.length > 63) {\n errors.push(`length must be 3-63 chars (got ${name.length})`);\n }\n if (!/^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(name)) {\n errors.push(\n \"must contain only lowercase letters, numbers, and hyphens, and start/end with a letter or number\",\n );\n }\n if (/--/.test(name)) {\n errors.push(\"must not contain consecutive hyphens\");\n }\n if (errors.length > 0) {\n throw new Error(\n `Invalid R2 bucket name \"${name}\" (derived for logical resource \"${logicalName}\"): ${errors.join(\"; \")}. ` +\n `Adjust your naming.r2Bucket hook (e.g., replace underscores with hyphens and lowercase the result).`,\n );\n }\n}\n\nexport async function r2Apply(\n resources: R2ResourceConfig[],\n tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = r2DeriveName(config, env, naming);\n const existing = state.get(derivedName);\n if (existing) {\n console.log(\n `R2: skip \"${derivedName}\" (already in state; logical \"${config.logicalName}\")`,\n );\n continue;\n }\n const prior = existingR2ForLogical(state, config.logicalName);\n if (prior) {\n console.log(\n `R2: skip \"${derivedName}\" (logical \"${config.logicalName}\" already in state as \"${prior.derivedName}\")`,\n );\n continue;\n }\n\n assertValidR2BucketName(derivedName, config.logicalName);\n await api.r2Create(derivedName);\n console.log(\n `R2: created \"${derivedName}\" (logical \"${config.logicalName}\")`,\n );\n state.set(derivedName, {\n type: \"r2_bucket\",\n logicalName: config.logicalName,\n createdDate: todayIso(),\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.r2BindingKey(config.logicalName),\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { R2ResourceConfig } from \"./r2.types.js\";\nimport { r2ExtractDate, r2MatchPattern } from \"./r2.naming.js\";\n\ninterface CFR2Bucket {\n name: string;\n creation_date: string;\n}\n\nexport function r2Sync(\n allR2: CFR2Bucket[],\n resources: R2ResourceConfig[],\n tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine\n): void {\n for (const config of resources) {\n const pattern = r2MatchPattern(config, env, naming);\n const match = allR2.find((b) => pattern(b.name));\n if (match) {\n const createdDate = r2ExtractDate(match.name, naming) ?? match.creation_date.slice(0, 10);\n const prev = state.get(match.name);\n state.set(match.name, {\n type: \"r2_bucket\",\n logicalName: config.logicalName,\n createdDate,\n derivedName: match.name,\n bindingKey:\n config.binding?.trim() ||\n (prev?.type === \"r2_bucket\" && prev.bindingKey\n ? prev.bindingKey\n : naming.r2BindingKey(config.logicalName)),\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { R2ResourceConfig, R2StateEntry } from \"./r2.types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { r2MatchPattern } from \"./r2.naming.js\";\n\ninterface CFR2Bucket {\n name: string;\n}\n\n/**\n * Diff R2 state against the Cloudflare list and the current config.\n *\n * R2 buckets carry a date stamp, so each declared resource matches at most one\n * bucket (the one whose name matches the logical-name pattern).\n */\nexport function r2Drift(\n allR2: CFR2Bucket[],\n resources: R2ResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"r2\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfNames = new Set(allR2.map((b) => b.name));\n const allState = state.getAll();\n const r2State = Object.values(allState).filter(\n (e): e is R2StateEntry => e.type === \"r2_bucket\",\n );\n\n for (const config of resources) {\n const pattern = r2MatchPattern(config, env, naming);\n const cfMatch = allR2.find((b) => pattern(b.name));\n const stateEntry = r2State.find(\n (e) => e.logicalName === config.logicalName,\n );\n\n if (stateEntry && !cfNames.has(stateEntry.derivedName)) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n });\n continue;\n }\n if (cfMatch && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName: cfMatch.name,\n });\n continue;\n }\n if (!cfMatch && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName: `(no bucket for ${config.logicalName})`,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\nimport type { R2StateEntry } from \"./r2.types.js\";\nimport {\n emptyR2BucketViaS3,\n r2S3CredentialsFromEnv,\n} from \"./r2S3EmptyBucket.js\";\n\nexport async function r2Destroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"r2\");\n const resources = state.getAll();\n const r2Entries = Object.values(resources).filter(\n (e): e is R2StateEntry => e.type === \"r2_bucket\",\n );\n const accountId = api.getAccountId();\n const s3creds = r2S3CredentialsFromEnv();\n\n for (const entry of r2Entries) {\n if (!owned.has(entry.logicalName)) continue;\n const name = entry.derivedName;\n if (s3creds) {\n try {\n console.log(\n `R2: emptying bucket \"${name}\" via S3 API (incomplete multipart uploads, then objects)…`,\n );\n const { uploadsAborted, objectsDeleted } = await emptyR2BucketViaS3(\n accountId,\n name,\n s3creds,\n );\n console.log(\n `R2: bucket \"${name}\" — aborted ${uploadsAborted} multipart upload(s), deleted ${objectsDeleted} object(s).`,\n );\n } catch (err) {\n console.warn(\n `R2: S3 empty failed for \"${name}\" (fix credentials or use the dashboard; still attempting API bucket delete):`,\n err instanceof Error ? err.message : err,\n );\n }\n } else {\n console.warn(\n `R2: skipping S3 empty for \"${name}\" (set R2_ACCESS_KEY_ID and R2_SECRET_ACCESS_KEY to remove all objects and incomplete multipart uploads before bucket delete). ` +\n `Create an R2 API token in the dashboard (R2 → Manage R2 API Tokens) with object read+write; those keys are not the same as CLOUDFLARE_API_TOKEN.`,\n );\n }\n try {\n await api.r2Delete(name);\n state.delete(name);\n } catch (err) {\n console.warn(`Failed to delete R2 ${name}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { R2ResourceConfig, R2StateEntry } from \"./r2.types.js\";\nimport type { WranglerR2Bucket } from \"../../generated/wrangler-types.js\";\nimport type { StateEntry } from \"../../types.js\";\n\nexport interface R2StateLike {\n get(derivedName: string): StateEntry | undefined;\n getAll(): Record<string, StateEntry>;\n}\n\nexport function r2Generate(\n resources: R2ResourceConfig[],\n env: string,\n state: R2StateLike,\n naming: NamingEngine\n): WranglerR2Bucket[] {\n const bindings: WranglerR2Bucket[] = [];\n\n for (const config of resources) {\n const allResources = state.getAll();\n const entry = Object.values(allResources).find(\n (e): e is R2StateEntry =>\n e.type === \"r2_bucket\" && e.logicalName === config.logicalName,\n );\n\n if (!entry) {\n throw new Error(\n `R2 \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`\n );\n }\n\n bindings.push({\n binding: entry.bindingKey,\n bucket_name: entry.derivedName,\n });\n }\n\n return bindings;\n}\n","import type { ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { R2ResourceConfig, R2StateEntry } from \"./r2.types.js\";\nimport { r2DeriveName } from \"./r2.naming.js\";\n\nexport interface R2StatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function r2Status(\n resources: R2ResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine\n): R2StatusResult[] {\n const results: R2StatusResult[] = [];\n\n for (const config of resources) {\n const allResources = state.getAll();\n const entry = Object.values(allResources).find(\n (e): e is R2StateEntry =>\n e.type === \"r2_bucket\" && e.logicalName === config.logicalName\n );\n\n results.push({\n binding: entry?.bindingKey ?? naming.r2BindingKey(config.logicalName),\n name: entry?.derivedName ?? r2DeriveName(config, env, naming),\n status: entry ? \"ok\" : \"missing\",\n });\n }\n\n return results;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { R2ResourceConfig } from \"./r2.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n R2StateEntry,\n} from \"../../types.js\";\nimport { r2Apply } from \"./r2.apply.js\";\nimport { r2Sync } from \"./r2.sync.js\";\nimport { r2Drift } from \"./r2.drift.js\";\nimport { r2Destroy } from \"./r2.destroy.js\";\nimport { r2Generate } from \"./r2.generate.js\";\nimport { r2Status } from \"./r2.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { r2MatchPattern } from \"./r2.naming.js\";\n\ninterface CFR2 {\n name: string;\n creation_date: string;\n}\n\nexport const r2Module: ResourceModule<R2ResourceConfig, CFR2> = {\n kind: \"r2\",\n label: \"R2\",\n configKey: \"r2\",\n stateEntryType: \"r2_bucket\",\n\n async fetchAll(api: CFApiClient): Promise<CFR2[]> {\n return api.r2ListAll();\n },\n\n async apply(ctx) {\n await r2Apply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n r2Sync(ctx.all, ctx.resources, ctx.tenant, ctx.env, ctx.state, ctx.naming);\n },\n\n drift(ctx) {\n return r2Drift(ctx.all, ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n async destroy(ctx) {\n await r2Destroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return r2Status(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n if (ctx.resources.length === 0) return {};\n return {\n r2_buckets: r2Generate(ctx.resources, ctx.env, ctx.state, ctx.naming),\n };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): R2ResourceConfig[] {\n return resourcesFrom(source)?.r2 ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"r2_bucket\") return;\n try {\n await api.r2Delete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(`Rollback: failed to delete R2 ${entry.derivedName}:`, err);\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const bucketName = options.cfId;\n if (!bucketName) {\n throw new Error(\"import r2: --cf-id <bucket-name> is required\");\n }\n const resourceConfig = await findWorkerResourceByLogicalName<R2ResourceConfig>(\n config,\n \"r2\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import r2: no resources.r2 entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.r2ListAll();\n const hit = all.find((b) => b.name === bucketName);\n if (!hit) {\n throw new Error(`import r2: bucket \"${bucketName}\" not found in account`);\n }\n const pattern = r2MatchPattern(resourceConfig, env, naming);\n if (!pattern(hit.name)) {\n throw new Error(\n `import r2: bucket name \"${hit.name}\" does not match expected pattern for logical \"${options.logical}\" and env \"${env}\"`,\n );\n }\n const derivedName = hit.name;\n const createdDate =\n options.createdDate ??\n naming.extractR2Date(hit.name) ??\n hit.creation_date.slice(0, 10);\n const bindingKey = naming.r2BindingKey(options.logical);\n const existing = state.get(derivedName);\n const entry: R2StateEntry = {\n type: \"r2_bucket\",\n logicalName: options.logical,\n derivedName,\n bindingKey,\n createdDate,\n createdAt: existing?.type === \"r2_bucket\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(derivedName, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveKVCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { KVResourceConfig } from \"../../types.js\";\n\nexport function kvDeriveName(\n config: KVResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveKVCloudflareName(config, env, naming);\n}\n\nexport function kvMatchPattern(\n config: KVResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveKVCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\nexport async function kvApply(\n resources: KVResourceConfig[],\n tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine\n): Promise<void> {\n for (const config of resources) {\n const derivedName = kvDeriveName(config, env, naming);\n const existing = state.get(derivedName);\n if (existing) continue;\n\n const { id } = await api.kvCreate(derivedName);\n state.set(derivedName, {\n type: \"kv_namespace\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.kvBindingKey(config.logicalName),\n cfId: id,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\ninterface CFKVNamespace {\n id: string;\n title: string;\n}\n\nexport function kvSync(\n allKV: CFKVNamespace[],\n resources: KVResourceConfig[],\n tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine\n): void {\n for (const config of resources) {\n const derivedName = kvDeriveName(config, env, naming);\n const match = allKV.find((ns) => ns.title === derivedName);\n if (match) {\n state.set(derivedName, {\n type: \"kv_namespace\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.kvBindingKey(config.logicalName),\n cfId: match.id,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n });\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport type { KVStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\ninterface CFKVNamespace {\n id: string;\n title: string;\n}\n\nexport function kvDrift(\n allKV: CFKVNamespace[],\n resources: KVResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"kv\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByTitle = new Map(allKV.map((ns) => [ns.title, ns.id]));\n const allState = state.getAll();\n const kvState = Object.values(allState).filter(\n (e): e is KVStateEntry => e.type === \"kv_namespace\",\n );\n\n for (const config of resources) {\n const derivedName = kvDeriveName(config, env, naming);\n const cfId = cfByTitle.get(derivedName);\n const stateEntry = kvState.find(\n (e) => e.logicalName === config.logicalName,\n );\n\n if (stateEntry && !cfId) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (cfId && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId,\n });\n } else if (!cfId && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, KVStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function kvDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"kv\");\n const resources = state.getAll();\n const kvEntries = Object.values(resources).filter(\n (e): e is KVStateEntry => e.type === \"kv_namespace\"\n );\n\n for (const entry of kvEntries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.kvDelete(entry.cfId);\n state.delete(entry.derivedName);\n } catch (err) {\n console.warn(`Failed to delete KV ${entry.derivedName}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport type { KVStateEntry } from \"../../types.js\";\nimport type { WranglerKVNamespace } from \"../../generated/wrangler-types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\nexport interface KVStateLike {\n get(derivedName: string): StateEntry | undefined;\n getAll(): Record<string, StateEntry>;\n}\n\nexport function kvGenerate(\n resources: KVResourceConfig[],\n env: string,\n state: KVStateLike,\n naming: NamingEngine\n): WranglerKVNamespace[] {\n const bindings: WranglerKVNamespace[] = [];\n\n for (const config of resources) {\n const derivedName = kvDeriveName(config, env, naming);\n const entry = state.get(derivedName);\n if (!entry || entry.type !== \"kv_namespace\") {\n throw new Error(\n `KV \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`\n );\n }\n\n bindings.push({\n binding: entry.bindingKey,\n id: entry.cfId,\n });\n }\n\n return bindings;\n}\n","import type { ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport type { KVStateEntry } from \"../../types.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\nexport interface KVStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function kvStatus(\n resources: KVResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine\n): KVStatusResult[] {\n const results: KVStatusResult[] = [];\n\n for (const config of resources) {\n const derivedName = kvDeriveName(config, env, naming);\n const entry = state.get(derivedName) as KVStateEntry | undefined;\n\n results.push({\n binding: naming.kvBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n\n return results;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { KVResourceConfig } from \"./kv.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n KVStateEntry,\n} from \"../../types.js\";\nimport { kvApply } from \"./kv.apply.js\";\nimport { kvSync } from \"./kv.sync.js\";\nimport { kvDrift } from \"./kv.drift.js\";\nimport { kvDestroy } from \"./kv.destroy.js\";\nimport { kvGenerate } from \"./kv.generate.js\";\nimport { kvStatus } from \"./kv.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { kvDeriveName } from \"./kv.naming.js\";\n\ninterface CFKv {\n id: string;\n title: string;\n}\n\nexport const kvModule: ResourceModule<KVResourceConfig, CFKv> = {\n kind: \"kv\",\n label: \"KV\",\n configKey: \"kv\",\n stateEntryType: \"kv_namespace\",\n\n async fetchAll(api: CFApiClient): Promise<CFKv[]> {\n const all = await api.kvListAll();\n return all.map((k) => ({ id: k.id, title: k.title }));\n },\n\n async apply(ctx) {\n await kvApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n kvSync(ctx.all, ctx.resources, ctx.tenant, ctx.env, ctx.state, ctx.naming);\n },\n\n drift(ctx) {\n return kvDrift(ctx.all, ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n async destroy(ctx) {\n await kvDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return kvStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n if (ctx.resources.length === 0) return {};\n return {\n kv_namespaces: kvGenerate(ctx.resources, ctx.env, ctx.state, ctx.naming),\n };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): KVResourceConfig[] {\n return resourcesFrom(source)?.kv ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"kv_namespace\") return;\n try {\n await api.kvDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(`Rollback: failed to delete KV ${entry.derivedName}:`, err);\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n if (!options.cfId)\n throw new Error(\"import kv: --cf-id <namespace-id> is required\");\n const resourceConfig = await findWorkerResourceByLogicalName<KVResourceConfig>(\n config,\n \"kv\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import kv: no resources.kv entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.kvListAll();\n const hit = all.find((k) => k.id === options.cfId);\n if (!hit) {\n throw new Error(\n `import kv: KV namespace id \"${options.cfId}\" not found in account`,\n );\n }\n const derivedName = kvDeriveName(resourceConfig, env, naming);\n if (hit.title !== derivedName) {\n throw new Error(\n `import kv: cf title \"${hit.title}\" does not match derived \"${derivedName}\"`,\n );\n }\n const bindingKey = naming.kvBindingKey(options.logical);\n const existing = state.get(derivedName);\n const entry: KVStateEntry = {\n type: \"kv_namespace\",\n logicalName: options.logical,\n derivedName,\n bindingKey,\n cfId: options.cfId,\n createdAt: existing?.type === \"kv_namespace\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(derivedName, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveQueueCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { QueueResourceConfig } from \"../../types.js\";\n\nexport function queueDeriveName(\n config: QueueResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveQueueCloudflareName(config, env, naming);\n}\n\nexport function queueMatchPattern(\n config: QueueResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveQueueCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\nconst STATE_KEY_PREFIX = \"queue:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\nexport async function queuesApply(\n resources: QueueResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = queueDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n if (existing) continue;\n\n const ts = new Date().toISOString();\n const { queue_id } = await api.queueCreate(derivedName);\n state.set(key, {\n type: \"queue\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.queueBindingKey(config.logicalName),\n cfId: queue_id,\n producerBinding: !config.consumerOnly,\n createdAt: ts,\n updatedAt: ts,\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\ninterface CFQueue {\n queue_id: string;\n queue_name: string;\n}\n\nexport function queuesSync(\n allQueues: CFQueue[],\n resources: QueueResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = queueDeriveName(config, env, naming);\n const match = allQueues.find((q) => q.queue_name === derivedName);\n if (!match) continue;\n const key = `queue:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n state.set(key, {\n type: \"queue\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.queueBindingKey(config.logicalName),\n cfId: match.queue_id,\n producerBinding: !config.consumerOnly,\n createdAt: existing?.type === \"queue\" ? existing.createdAt : ts,\n updatedAt: ts,\n });\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport type { QueueStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\ninterface CFQueue {\n queue_id: string;\n queue_name: string;\n}\n\nexport function queuesDrift(\n allQueues: CFQueue[],\n resources: QueueResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"queue\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allQueues.map((q) => [q.queue_name, q.queue_id]));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is QueueStateEntry => e.type === \"queue\",\n );\n\n for (const config of resources) {\n const derivedName = queueDeriveName(config, env, naming);\n const cfId = cfByName.get(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !cfId) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (cfId && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId,\n });\n } else if (!cfId && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, QueueStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function queuesDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"queue\");\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, QueueStateEntry] => kv[1].type === \"queue\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.queueDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(`Failed to delete queue ${entry.derivedName}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\nexport interface QueuesStateLike {\n get(key: string): StateEntry | undefined;\n getAll(): Record<string, StateEntry>;\n}\n\nexport interface GeneratedQueues {\n producers?: Array<{ binding: string; queue: string }>;\n}\n\n/**\n * Emit `queues.producers[]` for every declared queue (skips entries marked\n * `consumerOnly`). Consumers stay wrangler-side and can be set on the worker\n * config under `queues.consumers` (passed through unchanged).\n */\nexport function queuesGenerate(\n resources: QueueResourceConfig[],\n env: string,\n state: QueuesStateLike,\n naming: NamingEngine,\n): GeneratedQueues | undefined {\n const producers: Array<{ binding: string; queue: string }> = [];\n\n for (const config of resources) {\n if (config.consumerOnly) continue;\n const derivedName = queueDeriveName(config, env, naming);\n const entry = state.get(`queue:${derivedName}`);\n if (!entry || entry.type !== \"queue\") {\n throw new Error(\n `Queue \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`,\n );\n }\n producers.push({\n binding: entry.bindingKey,\n queue: entry.derivedName,\n });\n }\n\n if (producers.length === 0) return undefined;\n return { producers };\n}\n","import type { ResourceStatus, QueueStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\nexport interface QueuesStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function queuesStatus(\n resources: QueueResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): QueuesStatusResult[] {\n const out: QueuesStatusResult[] = [];\n for (const config of resources) {\n const derivedName = queueDeriveName(config, env, naming);\n const entry = state.get(`queue:${derivedName}`) as\n | QueueStateEntry\n | undefined;\n out.push({\n binding:\n config.binding?.trim() || naming.queueBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { QueueResourceConfig } from \"./queues.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n QueueStateEntry,\n} from \"../../types.js\";\nimport { queuesApply } from \"./queues.apply.js\";\nimport { queuesSync } from \"./queues.sync.js\";\nimport { queuesDrift } from \"./queues.drift.js\";\nimport { queuesDestroy } from \"./queues.destroy.js\";\nimport { queuesGenerate } from \"./queues.generate.js\";\nimport { queuesStatus } from \"./queues.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { queueDeriveName } from \"./queues.naming.js\";\n\ninterface CFQueue {\n queue_id: string;\n queue_name: string;\n}\n\nexport const queuesModule: ResourceModule<QueueResourceConfig, CFQueue> = {\n kind: \"queue\",\n label: \"Queues\",\n configKey: \"queues\",\n stateEntryType: \"queue\",\n\n async fetchAll(api: CFApiClient): Promise<CFQueue[]> {\n const all = await api.queuesListAll();\n return all.map((q) => ({ queue_id: q.queue_id, queue_name: q.queue_name }));\n },\n\n async apply(ctx) {\n await queuesApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n queuesSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return queuesDrift(ctx.all, ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n async destroy(ctx) {\n await queuesDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return queuesStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n const generated =\n ctx.resources.length > 0\n ? queuesGenerate(ctx.resources, ctx.env, ctx.state, ctx.naming)\n : undefined;\n const passthrough = ctx.passthrough?.queues;\n if (!generated && !passthrough) return {};\n const producers = [\n ...(passthrough?.producers ?? []),\n ...(generated?.producers ?? []),\n ];\n const consumers = passthrough?.consumers ?? [];\n if (producers.length === 0 && consumers.length === 0) return {};\n const out: NonNullable<\n import(\"../../generated/wrangler-types.js\").WranglerConfig[\"queues\"]\n > = {};\n if (producers.length > 0) out.producers = producers;\n if (consumers.length > 0) out.consumers = consumers;\n return { queues: out };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): QueueResourceConfig[] {\n return resourcesFrom(source)?.queues ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"queue\") return;\n try {\n await api.queueDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete queue ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n if (!options.cfId) {\n throw new Error(\"import queue: --cf-id <queue-id> is required\");\n }\n const resourceConfig =\n await findWorkerResourceByLogicalName<QueueResourceConfig>(\n config,\n \"queues\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import queue: no resources.queues entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.queuesListAll();\n const hit = all.find((q) => q.queue_id === options.cfId);\n if (!hit) {\n throw new Error(\n `import queue: queue id \"${options.cfId}\" not found in account`,\n );\n }\n const derivedName = queueDeriveName(resourceConfig, env, naming);\n if (hit.queue_name !== derivedName) {\n throw new Error(\n `import queue: cf name \"${hit.queue_name}\" does not match derived \"${derivedName}\"`,\n );\n }\n const bindingKey = naming.queueBindingKey(options.logical);\n const key = `queue:${derivedName}`;\n const existing = state.get(key);\n const entry: QueueStateEntry = {\n type: \"queue\",\n logicalName: options.logical,\n derivedName,\n bindingKey,\n cfId: options.cfId,\n producerBinding: existing?.type === \"queue\" ? existing.producerBinding : true,\n createdAt: existing?.type === \"queue\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { HyperdriveResourceConfig } from \"../../types.js\";\n\n/**\n * Resolve a value that is either a literal string or `{ fromEnv: \"VAR\" }`\n * lookup against `process.env`. Throws a clear error when the env var is\n * missing — these values are sent to Cloudflare on create and never\n * persisted in Tamer state.\n */\nexport function resolveSecret(\n value: string | { fromEnv: string },\n label: string,\n): string {\n if (typeof value === \"string\") return value;\n const envName = value.fromEnv;\n const v = process.env[envName];\n if (!v) {\n throw new Error(\n `hyperdrive: ${label} requires env var ${envName} (set it before running 'tamer apply')`,\n );\n }\n return v;\n}\n\nexport interface ResolvedHyperdriveOrigin {\n scheme: string;\n host: string;\n port?: number;\n database: string;\n user: string;\n password: string;\n access_client_id?: string;\n access_client_secret?: string;\n}\n\nexport function resolveHyperdriveOrigin(\n config: HyperdriveResourceConfig,\n): ResolvedHyperdriveOrigin {\n const o = config.origin;\n return {\n scheme: o.scheme,\n host: o.host,\n port: o.port,\n database: o.database,\n user: o.user,\n password: resolveSecret(o.password, `${config.logicalName}.origin.password`),\n access_client_id: o.access_client_id,\n access_client_secret: o.access_client_secret\n ? resolveSecret(\n o.access_client_secret,\n `${config.logicalName}.origin.access_client_secret`,\n )\n : undefined,\n };\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveHyperdriveCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { HyperdriveResourceConfig } from \"../../types.js\";\n\nexport function hyperdriveDeriveName(\n config: HyperdriveResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveHyperdriveCloudflareName(config, env, naming);\n}\n\nexport function hyperdriveMatchPattern(\n config: HyperdriveResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveHyperdriveCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","/**\n * Plan-time field-level diff for declared Hyperdrive configurations.\n * Mirrors the PATCH path in {@link hyperdriveApply}: Cloudflare's\n * `PATCH /accounts/{id}/hyperdrive/configs/{id}` accepts in-place edits\n * to `origin` (host / database / scheme / user / port / password) so any\n * drift on the **state-tracked** origin metadata (`scheme`, `originHost`,\n * `originDatabase`) becomes an `update` action — Tamer never destroys\n * and recreates a Hyperdrive config.\n *\n * Origin password is intentionally **not** in state (write-only on\n * Cloudflare's side, never returned), so it cannot be diffed; users who\n * rotate via `{ fromEnv: \"DATABASE_PASSWORD\" }` should run `tamer apply`\n * which always re-sends the resolved origin payload.\n *\n * Resources without a state row are reported by `hyperdriveDrift` as\n * `undeployed` and become `create` items.\n */\n\nimport type {\n HyperdriveResourceConfig,\n HyperdriveStateEntry,\n} from \"../../types.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { PlanFieldChange, PlanItem } from \"../../core/plan/plan.types.js\";\n\nexport function hyperdriveDiffPlanItems(args: {\n resources: HyperdriveResourceConfig[];\n env: string;\n state: StateManager;\n naming: NamingEngine;\n}): PlanItem[] {\n const { resources, env, state, naming } = args;\n const items: PlanItem[] = [];\n\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const entry = state.get(`hyperdrive:${derivedName}`);\n if (!entry || entry.type !== \"hyperdrive\") continue;\n\n const changes = computeChanges(entry as HyperdriveStateEntry, config);\n if (changes.length === 0) continue;\n items.push({\n kind: \"hyperdrive\",\n action: \"update\",\n logicalName: config.logicalName,\n derivedName,\n detail: changes\n .map((c) => `${c.field}: ${formatVal(c.from)} -> ${formatVal(c.to)}`)\n .join(\", \"),\n changes,\n });\n }\n\n return items;\n}\n\n/**\n * Pure comparison shared with `hyperdriveApply` so plan and apply agree\n * on what counts as drift on the origin fields Tamer persists.\n */\nexport function computeHyperdriveChanges(\n state: HyperdriveStateEntry,\n config: HyperdriveResourceConfig,\n): PlanFieldChange[] {\n return computeChanges(state, config);\n}\n\nfunction computeChanges(\n state: HyperdriveStateEntry,\n config: HyperdriveResourceConfig,\n): PlanFieldChange[] {\n const changes: PlanFieldChange[] = [];\n if (state.scheme !== config.origin.scheme) {\n changes.push({\n field: \"origin.scheme\",\n from: state.scheme,\n to: config.origin.scheme,\n kind: \"mutable\",\n });\n }\n if (state.originHost !== config.origin.host) {\n changes.push({\n field: \"origin.host\",\n from: state.originHost,\n to: config.origin.host,\n kind: \"mutable\",\n });\n }\n if (state.originDatabase !== config.origin.database) {\n changes.push({\n field: \"origin.database\",\n from: state.originDatabase,\n to: config.origin.database,\n kind: \"mutable\",\n });\n }\n return changes;\n}\n\nfunction formatVal(v: unknown): string {\n if (v === undefined) return \"(unset)\";\n if (typeof v === \"string\") return v.length > 32 ? `${v.slice(0, 29)}...` : v;\n return String(v);\n}\n","import type { HyperdriveStateEntry, TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport { resolveHyperdriveOrigin } from \"./hyperdrive.secrets.js\";\nimport { computeHyperdriveChanges } from \"./hyperdrive.diff.js\";\nimport { logApplyChange } from \"../../core/plan/planFormat.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\nconst STATE_KEY_PREFIX = \"hyperdrive:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\nexport async function hyperdriveApply(\n resources: HyperdriveResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n const ts = new Date().toISOString();\n\n if (existing && existing.type === \"hyperdrive\") {\n const stateEntry = existing as HyperdriveStateEntry;\n const changes = computeHyperdriveChanges(stateEntry, config);\n if (changes.length === 0) continue;\n logApplyChange({\n kind: \"hyperdrive\",\n action: \"update\",\n logical: config.logicalName,\n derived: derivedName,\n changes,\n });\n // Cloudflare's PATCH treats `origin` as a unit (password is\n // write-only and never echoed back). Re-resolve the full origin\n // from config — this also re-reads `{ fromEnv: ... }` secrets so\n // password rotation flows through naturally.\n const origin = resolveHyperdriveOrigin(config);\n await api.hyperdrivePatch(stateEntry.cfId, { origin });\n state.set(key, {\n ...stateEntry,\n scheme: config.origin.scheme,\n originHost: config.origin.host,\n originDatabase: config.origin.database,\n updatedAt: ts,\n });\n continue;\n }\n\n logApplyChange({\n kind: \"hyperdrive\",\n action: \"create\",\n logical: config.logicalName,\n derived: derivedName,\n });\n const origin = resolveHyperdriveOrigin(config);\n const { id } = await api.hyperdriveCreate({\n name: derivedName,\n origin,\n caching: config.caching,\n mtls: config.mtls,\n });\n state.set(key, {\n type: \"hyperdrive\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() ||\n naming.hyperdriveBindingKey(config.logicalName),\n cfId: id,\n scheme: config.origin.scheme,\n originHost: config.origin.host,\n originDatabase: config.origin.database,\n createdAt: ts,\n updatedAt: ts,\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\ninterface CFHyperdrive {\n id: string;\n name: string;\n origin?: { scheme?: string; host?: string; database?: string };\n}\n\nexport function hyperdriveSync(\n allHyperdrive: CFHyperdrive[],\n resources: HyperdriveResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const match = allHyperdrive.find((h) => h.name === derivedName);\n if (!match) continue;\n const key = `hyperdrive:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n state.set(key, {\n type: \"hyperdrive\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() ||\n naming.hyperdriveBindingKey(config.logicalName),\n cfId: match.id,\n scheme: config.origin.scheme,\n originHost: match.origin?.host ?? config.origin.host,\n originDatabase: match.origin?.database ?? config.origin.database,\n createdAt: existing?.type === \"hyperdrive\" ? existing.createdAt : ts,\n updatedAt: ts,\n });\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport type { HyperdriveStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\ninterface CFHyperdrive {\n id: string;\n name: string;\n}\n\nexport function hyperdriveDrift(\n allHyperdrive: CFHyperdrive[],\n resources: HyperdriveResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"hyperdrive\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allHyperdrive.map((h) => [h.name, h.id]));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is HyperdriveStateEntry => e.type === \"hyperdrive\",\n );\n\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const cfId = cfByName.get(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !cfId) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (cfId && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId,\n });\n } else if (!cfId && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, HyperdriveStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function hyperdriveDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(\n config,\n baseDir,\n \"hyperdrive\",\n );\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, HyperdriveStateEntry] => kv[1].type === \"hyperdrive\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.hyperdriveDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(`Failed to delete hyperdrive ${entry.derivedName}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\nexport interface HyperdriveStateLike {\n get(key: string): StateEntry | undefined;\n getAll(): Record<string, StateEntry>;\n}\n\nexport interface GeneratedHyperdriveBinding {\n binding: string;\n id: string;\n localConnectionString?: string;\n}\n\nexport function hyperdriveGenerate(\n resources: HyperdriveResourceConfig[],\n env: string,\n state: HyperdriveStateLike,\n naming: NamingEngine,\n): GeneratedHyperdriveBinding[] {\n const out: GeneratedHyperdriveBinding[] = [];\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const entry = state.get(`hyperdrive:${derivedName}`);\n if (!entry || entry.type !== \"hyperdrive\") {\n throw new Error(\n `Hyperdrive \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`,\n );\n }\n out.push({\n binding: entry.bindingKey,\n id: entry.cfId,\n localConnectionString: config.localConnectionString,\n });\n }\n return out;\n}\n","import type { ResourceStatus, HyperdriveStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\nexport interface HyperdriveStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function hyperdriveStatus(\n resources: HyperdriveResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): HyperdriveStatusResult[] {\n const out: HyperdriveStatusResult[] = [];\n for (const config of resources) {\n const derivedName = hyperdriveDeriveName(config, env, naming);\n const entry = state.get(`hyperdrive:${derivedName}`) as\n | HyperdriveStateEntry\n | undefined;\n out.push({\n binding:\n config.binding?.trim() ||\n naming.hyperdriveBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { HyperdriveResourceConfig } from \"./hyperdrive.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n HyperdriveStateEntry,\n} from \"../../types.js\";\nimport { hyperdriveApply } from \"./hyperdrive.apply.js\";\nimport { hyperdriveSync } from \"./hyperdrive.sync.js\";\nimport { hyperdriveDrift } from \"./hyperdrive.drift.js\";\nimport { hyperdriveDestroy } from \"./hyperdrive.destroy.js\";\nimport { hyperdriveGenerate } from \"./hyperdrive.generate.js\";\nimport { hyperdriveStatus } from \"./hyperdrive.status.js\";\nimport { hyperdriveDiffPlanItems } from \"./hyperdrive.diff.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { hyperdriveDeriveName } from \"./hyperdrive.naming.js\";\n\ninterface CFHyperdrive {\n id: string;\n name: string;\n origin?: { scheme?: string; host?: string; database?: string };\n}\n\nexport const hyperdriveModule: ResourceModule<\n HyperdriveResourceConfig,\n CFHyperdrive\n> = {\n kind: \"hyperdrive\",\n label: \"Hyperdrive\",\n configKey: \"hyperdrive\",\n stateEntryType: \"hyperdrive\",\n\n async fetchAll(api: CFApiClient): Promise<CFHyperdrive[]> {\n const all = await api.hyperdriveListAll();\n return all.map((h) => ({ id: h.id, name: h.name, origin: h.origin }));\n },\n\n async apply(ctx) {\n await hyperdriveApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n hyperdriveSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return hyperdriveDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n diff(ctx) {\n return hyperdriveDiffPlanItems({\n resources: ctx.resources,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n });\n },\n\n async destroy(ctx) {\n await hyperdriveDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return hyperdriveStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n const generated =\n ctx.resources.length > 0\n ? hyperdriveGenerate(ctx.resources, ctx.env, ctx.state, ctx.naming)\n : [];\n const passthrough = ctx.passthrough?.hyperdrive ?? [];\n if (generated.length === 0 && passthrough.length === 0) return {};\n return { hyperdrive: [...passthrough, ...generated] };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): HyperdriveResourceConfig[] {\n return resourcesFrom(source)?.hyperdrive ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"hyperdrive\") return;\n try {\n await api.hyperdriveDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete Hyperdrive ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n if (!options.cfId) {\n throw new Error(\"import hyperdrive: --cf-id <config-id> is required\");\n }\n const resourceConfig =\n await findWorkerResourceByLogicalName<HyperdriveResourceConfig>(\n config,\n \"hyperdrive\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import hyperdrive: no resources.hyperdrive entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.hyperdriveListAll();\n const hit = all.find((h) => h.id === options.cfId);\n if (!hit) {\n throw new Error(\n `import hyperdrive: config id \"${options.cfId}\" not found in account`,\n );\n }\n const derivedName = hyperdriveDeriveName(resourceConfig, env, naming);\n if (hit.name !== derivedName) {\n throw new Error(\n `import hyperdrive: cf name \"${hit.name}\" does not match derived \"${derivedName}\"`,\n );\n }\n const bindingKey = naming.hyperdriveBindingKey(options.logical);\n const key = `hyperdrive:${derivedName}`;\n const existing = state.get(key);\n const scheme = (\n hit.origin?.scheme === \"mysql\"\n ? \"mysql\"\n : hit.origin?.scheme === \"postgresql\"\n ? \"postgresql\"\n : \"postgres\"\n ) as \"postgres\" | \"postgresql\" | \"mysql\";\n const entry: HyperdriveStateEntry = {\n type: \"hyperdrive\",\n logicalName: options.logical,\n derivedName,\n bindingKey,\n cfId: options.cfId,\n scheme,\n originHost: hit.origin?.host ?? \"\",\n originDatabase: hit.origin?.database ?? \"\",\n createdAt: existing?.type === \"hyperdrive\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveVectorizeCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { VectorizeResourceConfig } from \"../../types.js\";\n\nexport function vectorizeDeriveName(\n config: VectorizeResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveVectorizeCloudflareName(config, env, naming);\n}\n\nexport function vectorizeMatchPattern(\n config: VectorizeResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveVectorizeCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\nconst STATE_KEY_PREFIX = \"vectorize:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\nexport async function vectorizeApply(\n resources: VectorizeResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n if (existing) {\n if (existing.type === \"vectorize\") {\n if (\n existing.dimensions !== config.dimensions ||\n existing.metric !== config.metric\n ) {\n throw new Error(\n `Vectorize index \"${config.logicalName}\" config changed (dimensions/metric are immutable). ` +\n `Run 'tamer destroy --resource ${config.logicalName}' first, then re-apply.`,\n );\n }\n }\n continue;\n }\n\n const ts = new Date().toISOString();\n const created = await api.vectorizeCreate({\n name: derivedName,\n description: config.description,\n config: { dimensions: config.dimensions, metric: config.metric },\n });\n state.set(key, {\n type: \"vectorize\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() ||\n naming.vectorizeBindingKey(config.logicalName),\n cfId: created.id ?? derivedName,\n dimensions: config.dimensions,\n metric: config.metric,\n createdAt: ts,\n updatedAt: ts,\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\ninterface CFVectorize {\n id?: string;\n name: string;\n config?: { dimensions: number; metric: string };\n}\n\nexport function vectorizeSync(\n allIndexes: CFVectorize[],\n resources: VectorizeResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const match = allIndexes.find((i) => i.name === derivedName);\n if (!match) continue;\n const key = `vectorize:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n state.set(key, {\n type: \"vectorize\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() ||\n naming.vectorizeBindingKey(config.logicalName),\n cfId: match.id ?? derivedName,\n dimensions: match.config?.dimensions ?? config.dimensions,\n metric:\n ((match.config?.metric as VectorizeResourceConfig[\"metric\"]) ?? null) ||\n config.metric,\n createdAt: existing?.type === \"vectorize\" ? existing.createdAt : ts,\n updatedAt: ts,\n });\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport type { VectorizeStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\ninterface CFVectorize {\n id?: string;\n name: string;\n}\n\nexport function vectorizeDrift(\n allIndexes: CFVectorize[],\n resources: VectorizeResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"vectorize\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(\n allIndexes.map((i) => [i.name, i.id ?? i.name]),\n );\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is VectorizeStateEntry => e.type === \"vectorize\",\n );\n\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const cfId = cfByName.get(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !cfId) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (cfId && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId,\n });\n } else if (!cfId && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, VectorizeStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function vectorizeDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"vectorize\");\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, VectorizeStateEntry] => kv[1].type === \"vectorize\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.vectorizeDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(`Failed to delete vectorize index ${entry.derivedName}:`, err);\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\nexport interface VectorizeStateLike {\n get(key: string): StateEntry | undefined;\n}\n\nexport interface GeneratedVectorizeBinding {\n binding: string;\n index_name: string;\n}\n\n/**\n * Emit `vectorize[]` bindings for declared indexes. Each binding requires\n * the index to exist in state (i.e. `tamer apply` has run). Throws otherwise\n * so the operator gets an actionable error before `wrangler deploy`.\n */\nexport function vectorizeGenerate(\n resources: VectorizeResourceConfig[],\n env: string,\n state: VectorizeStateLike,\n naming: NamingEngine,\n): GeneratedVectorizeBinding[] {\n const out: GeneratedVectorizeBinding[] = [];\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const entry = state.get(`vectorize:${derivedName}`);\n if (!entry || entry.type !== \"vectorize\") {\n throw new Error(\n `Vectorize index \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`,\n );\n }\n out.push({\n binding: entry.bindingKey,\n index_name: entry.derivedName,\n });\n }\n return out;\n}\n","import type { ResourceStatus, VectorizeStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\nexport interface VectorizeStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function vectorizeStatus(\n resources: VectorizeResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): VectorizeStatusResult[] {\n const out: VectorizeStatusResult[] = [];\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const entry = state.get(`vectorize:${derivedName}`) as\n | VectorizeStateEntry\n | undefined;\n out.push({\n binding:\n config.binding?.trim() ||\n naming.vectorizeBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","/**\n * Plan-time diff for Vectorize indexes. `dimensions` and `metric` are\n * **immutable** per the Vectorize V2 API — Cloudflare rejects PATCH on\n * either field, so any drift surfaces as `replace` (delete + recreate\n * via `tamer destroy --resource <logical>` then `apply`). No `update`\n * action is ever emitted for this kind today.\n */\n\nimport type {\n VectorizeResourceConfig,\n VectorizeStateEntry,\n} from \"../../types.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { PlanFieldChange, PlanItem } from \"../../core/plan/plan.types.js\";\n\nexport function vectorizeDiffPlanItems(args: {\n resources: VectorizeResourceConfig[];\n env: string;\n state: StateManager;\n naming: NamingEngine;\n}): PlanItem[] {\n const { resources, env, state, naming } = args;\n const items: PlanItem[] = [];\n\n for (const config of resources) {\n const derivedName = vectorizeDeriveName(config, env, naming);\n const key = `vectorize:${derivedName}`;\n const entry = state.get(key);\n if (!entry || entry.type !== \"vectorize\") continue;\n const stateEntry = entry as VectorizeStateEntry;\n\n const changes: PlanFieldChange[] = [];\n if (stateEntry.dimensions !== config.dimensions) {\n changes.push({\n field: \"dimensions\",\n from: stateEntry.dimensions,\n to: config.dimensions,\n kind: \"immutable\",\n });\n }\n if (stateEntry.metric !== config.metric) {\n changes.push({\n field: \"metric\",\n from: stateEntry.metric,\n to: config.metric,\n kind: \"immutable\",\n });\n }\n\n if (changes.length === 0) continue;\n items.push({\n kind: \"vectorize\",\n action: \"replace\",\n logicalName: config.logicalName,\n derivedName,\n detail: changes\n .map((c) => `${c.field}: ${c.from} -> ${c.to}`)\n .join(\", \"),\n changes,\n });\n }\n\n return items;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { VectorizeResourceConfig } from \"./vectorize.types.js\";\nimport type {\n WorkerConfig,\n WorkerResources,\n VectorizeStateEntry,\n} from \"../../types.js\";\nimport { vectorizeApply } from \"./vectorize.apply.js\";\nimport { vectorizeSync } from \"./vectorize.sync.js\";\nimport { vectorizeDrift } from \"./vectorize.drift.js\";\nimport { vectorizeDestroy } from \"./vectorize.destroy.js\";\nimport { vectorizeGenerate } from \"./vectorize.generate.js\";\nimport { vectorizeStatus } from \"./vectorize.status.js\";\nimport { vectorizeDiffPlanItems } from \"./vectorize.diff.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { vectorizeDeriveName } from \"./vectorize.naming.js\";\n\ninterface CFVectorize {\n id?: string;\n name: string;\n config?: { dimensions: number; metric: string };\n}\n\nexport const vectorizeModule: ResourceModule<\n VectorizeResourceConfig,\n CFVectorize\n> = {\n kind: \"vectorize\",\n label: \"Vectorize\",\n configKey: \"vectorize\",\n stateEntryType: \"vectorize\",\n\n async fetchAll(api: CFApiClient): Promise<CFVectorize[]> {\n const all = await api.vectorizeListAll();\n return all.map((v) => ({ id: v.id, name: v.name, config: v.config }));\n },\n\n async apply(ctx) {\n await vectorizeApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n vectorizeSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return vectorizeDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n diff(ctx) {\n return vectorizeDiffPlanItems({\n resources: ctx.resources,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n });\n },\n\n async destroy(ctx) {\n await vectorizeDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return vectorizeStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n const generated =\n ctx.resources.length > 0\n ? vectorizeGenerate(ctx.resources, ctx.env, ctx.state, ctx.naming)\n : [];\n const passthrough = ctx.passthrough?.vectorize ?? [];\n if (generated.length === 0 && passthrough.length === 0) return {};\n return { vectorize: [...passthrough, ...generated] };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): VectorizeResourceConfig[] {\n return resourcesFrom(source)?.vectorize ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"vectorize\") return;\n try {\n await api.vectorizeDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete Vectorize ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const indexName = options.cfId;\n if (!indexName) {\n throw new Error(\"import vectorize: --cf-id <index-name> is required\");\n }\n const resourceConfig =\n await findWorkerResourceByLogicalName<VectorizeResourceConfig>(\n config,\n \"vectorize\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import vectorize: no resources.vectorize entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.vectorizeListAll();\n const hit = all.find((v) => v.name === indexName);\n if (!hit) {\n throw new Error(\n `import vectorize: index \"${indexName}\" not found in account`,\n );\n }\n const derivedName = vectorizeDeriveName(resourceConfig, env, naming);\n if (hit.name !== derivedName) {\n throw new Error(\n `import vectorize: cf name \"${hit.name}\" does not match derived \"${derivedName}\"`,\n );\n }\n if (!hit.config) {\n throw new Error(\n `import vectorize: cf index \"${hit.name}\" returned no config (dimensions/metric)`,\n );\n }\n const metric = hit.config.metric as \"cosine\" | \"euclidean\" | \"dot-product\";\n const bindingKey = naming.vectorizeBindingKey(options.logical);\n const key = `vectorize:${derivedName}`;\n const existing = state.get(key);\n const entry: VectorizeStateEntry = {\n type: \"vectorize\",\n logicalName: options.logical,\n derivedName,\n bindingKey,\n cfId: hit.id ?? derivedName,\n dimensions: hit.config.dimensions,\n metric,\n createdAt: existing?.type === \"vectorize\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { AIGatewayResourceConfig } from \"../../types.js\";\n\nexport type { AIGatewayResourceConfig };\n\n/**\n * Default values applied to optional `AIGatewayResourceConfig` fields. Kept\n * here so apply / sync / drift agree on what \"no override\" actually means\n * when comparing config to Cloudflare state.\n */\nexport const AI_GATEWAY_DEFAULTS = {\n cacheTtl: 0,\n cacheInvalidateOnUpdate: false,\n collectLogs: true,\n authentication: false,\n rateLimitingInterval: 0,\n rateLimitingLimit: 0,\n rateLimitingTechnique: \"fixed\" as const,\n};\n\nexport type ResolvedAIGatewayConfig = Required<\n Pick<\n AIGatewayResourceConfig,\n | \"cacheTtl\"\n | \"cacheInvalidateOnUpdate\"\n | \"collectLogs\"\n | \"authentication\"\n | \"rateLimitingInterval\"\n | \"rateLimitingLimit\"\n | \"rateLimitingTechnique\"\n >\n>;\n\nexport function resolveAIGatewayConfig(\n config: AIGatewayResourceConfig,\n): ResolvedAIGatewayConfig {\n return {\n cacheTtl: config.cacheTtl ?? AI_GATEWAY_DEFAULTS.cacheTtl,\n cacheInvalidateOnUpdate:\n config.cacheInvalidateOnUpdate ??\n AI_GATEWAY_DEFAULTS.cacheInvalidateOnUpdate,\n collectLogs: config.collectLogs ?? AI_GATEWAY_DEFAULTS.collectLogs,\n authentication: config.authentication ?? AI_GATEWAY_DEFAULTS.authentication,\n rateLimitingInterval:\n config.rateLimitingInterval ?? AI_GATEWAY_DEFAULTS.rateLimitingInterval,\n rateLimitingLimit:\n config.rateLimitingLimit ?? AI_GATEWAY_DEFAULTS.rateLimitingLimit,\n rateLimitingTechnique:\n config.rateLimitingTechnique ?? AI_GATEWAY_DEFAULTS.rateLimitingTechnique,\n };\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveAIGatewayCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { AIGatewayResourceConfig } from \"../../types.js\";\n\nexport function aiGatewayDeriveName(\n config: AIGatewayResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveAIGatewayCloudflareName(config, env, naming);\n}\n\nexport function aiGatewayMatchPattern(\n config: AIGatewayResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveAIGatewayCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","/**\n * Plan-time field-level diff for declared AI Gateways. Pure: takes the\n * recorded {@link AIGatewayStateEntry} and the declared\n * {@link AIGatewayResourceConfig}, and returns the `update` items\n * `tamer plan` should emit.\n *\n * All AI Gateway settings tracked here are mutable via\n * `PUT /accounts/{id}/ai-gateway/gateways/{id}` (Cloudflare's API uses\n * full-PUT, not PATCH, but it never rejects in-place edits on these\n * fields), so every detected drift becomes an `update` action — never\n * `replace`. Gateway id itself is part of the derived name and changes to\n * `logicalName` would surface as a different state row entirely.\n *\n * Resources without a state row are reported by `aiGatewayDrift` as\n * `undeployed` and become `create` items.\n */\n\nimport type {\n AIGatewayResourceConfig,\n AIGatewayStateEntry,\n} from \"../../types.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { PlanFieldChange, PlanItem } from \"../../core/plan/plan.types.js\";\nimport { resolveAIGatewayConfig } from \"./ai-gateway.types.js\";\n\nexport function aiGatewayDiffPlanItems(args: {\n resources: AIGatewayResourceConfig[];\n env: string;\n state: StateManager;\n naming: NamingEngine;\n}): PlanItem[] {\n const { resources, env, state, naming } = args;\n const items: PlanItem[] = [];\n\n for (const config of resources) {\n const derivedName = aiGatewayDeriveName(config, env, naming);\n const entry = state.get(`ai_gateway:${derivedName}`);\n if (!entry || entry.type !== \"ai_gateway\") continue;\n\n const changes = computeChanges(entry as AIGatewayStateEntry, config);\n if (changes.length === 0) continue;\n items.push({\n kind: \"ai_gateway\",\n action: \"update\",\n logicalName: config.logicalName,\n derivedName,\n detail: changes\n .map((c) => `${c.field}: ${formatVal(c.from)} -> ${formatVal(c.to)}`)\n .join(\", \"),\n changes,\n });\n }\n\n return items;\n}\n\n/**\n * Pure comparison shared with `aiGatewayApply` — keeps the plan and the\n * apply path in lockstep about which fields count as drift.\n */\nexport function computeAIGatewayChanges(\n state: AIGatewayStateEntry,\n config: AIGatewayResourceConfig,\n): PlanFieldChange[] {\n return computeChanges(state, config);\n}\n\nfunction computeChanges(\n state: AIGatewayStateEntry,\n config: AIGatewayResourceConfig,\n): PlanFieldChange[] {\n const resolved = resolveAIGatewayConfig(config);\n const changes: PlanFieldChange[] = [];\n\n if (state.cacheTtl !== resolved.cacheTtl) {\n changes.push({\n field: \"cacheTtl\",\n from: state.cacheTtl,\n to: resolved.cacheTtl,\n kind: \"mutable\",\n });\n }\n if (state.cacheInvalidateOnUpdate !== resolved.cacheInvalidateOnUpdate) {\n changes.push({\n field: \"cacheInvalidateOnUpdate\",\n from: state.cacheInvalidateOnUpdate,\n to: resolved.cacheInvalidateOnUpdate,\n kind: \"mutable\",\n });\n }\n if (state.collectLogs !== resolved.collectLogs) {\n changes.push({\n field: \"collectLogs\",\n from: state.collectLogs,\n to: resolved.collectLogs,\n kind: \"mutable\",\n });\n }\n if (state.authentication !== resolved.authentication) {\n changes.push({\n field: \"authentication\",\n from: state.authentication,\n to: resolved.authentication,\n kind: \"mutable\",\n });\n }\n if (state.rateLimitingInterval !== resolved.rateLimitingInterval) {\n changes.push({\n field: \"rateLimitingInterval\",\n from: state.rateLimitingInterval,\n to: resolved.rateLimitingInterval,\n kind: \"mutable\",\n });\n }\n if (state.rateLimitingLimit !== resolved.rateLimitingLimit) {\n changes.push({\n field: \"rateLimitingLimit\",\n from: state.rateLimitingLimit,\n to: resolved.rateLimitingLimit,\n kind: \"mutable\",\n });\n }\n if (state.rateLimitingTechnique !== resolved.rateLimitingTechnique) {\n changes.push({\n field: \"rateLimitingTechnique\",\n from: state.rateLimitingTechnique,\n to: resolved.rateLimitingTechnique,\n kind: \"mutable\",\n });\n }\n return changes;\n}\n\nfunction formatVal(v: unknown): string {\n if (v === undefined) return \"(unset)\";\n if (typeof v === \"string\") return v.length > 32 ? `${v.slice(0, 29)}...` : v;\n return String(v);\n}\n","import type { AIGatewayStateEntry, TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { AIGatewayResourceConfig } from \"./ai-gateway.types.js\";\nimport { resolveAIGatewayConfig } from \"./ai-gateway.types.js\";\nimport { computeAIGatewayChanges } from \"./ai-gateway.diff.js\";\nimport { logApplyChange } from \"../../core/plan/planFormat.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\n\nconst STATE_KEY_PREFIX = \"ai_gateway:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\nexport async function aiGatewayApply(\n resources: AIGatewayResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = aiGatewayDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n const resolved = resolveAIGatewayConfig(config);\n const ts = new Date().toISOString();\n\n if (existing && existing.type === \"ai_gateway\") {\n const changes = computeAIGatewayChanges(\n existing as AIGatewayStateEntry,\n config,\n );\n if (changes.length === 0) continue;\n logApplyChange({\n kind: \"ai_gateway\",\n action: \"update\",\n logical: config.logicalName,\n derived: derivedName,\n changes,\n });\n await api.aiGatewayUpdate(derivedName, {\n cache_ttl: resolved.cacheTtl,\n cache_invalidate_on_update: resolved.cacheInvalidateOnUpdate,\n collect_logs: resolved.collectLogs,\n authentication: resolved.authentication,\n rate_limiting_interval: resolved.rateLimitingInterval,\n rate_limiting_limit: resolved.rateLimitingLimit,\n rate_limiting_technique: resolved.rateLimitingTechnique,\n });\n state.set(key, {\n ...(existing as AIGatewayStateEntry),\n cacheTtl: resolved.cacheTtl,\n cacheInvalidateOnUpdate: resolved.cacheInvalidateOnUpdate,\n collectLogs: resolved.collectLogs,\n authentication: resolved.authentication,\n rateLimitingInterval: resolved.rateLimitingInterval,\n rateLimitingLimit: resolved.rateLimitingLimit,\n rateLimitingTechnique: resolved.rateLimitingTechnique,\n updatedAt: ts,\n });\n continue;\n }\n\n logApplyChange({\n kind: \"ai_gateway\",\n action: \"create\",\n logical: config.logicalName,\n derived: derivedName,\n });\n await api.aiGatewayCreate({\n id: derivedName,\n cache_ttl: resolved.cacheTtl,\n cache_invalidate_on_update: resolved.cacheInvalidateOnUpdate,\n collect_logs: resolved.collectLogs,\n authentication: resolved.authentication,\n rate_limiting_interval: resolved.rateLimitingInterval,\n rate_limiting_limit: resolved.rateLimitingLimit,\n rate_limiting_technique: resolved.rateLimitingTechnique,\n });\n state.set(key, {\n type: \"ai_gateway\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: naming.aiGatewayBindingKey(config.logicalName),\n cfId: derivedName,\n cacheTtl: resolved.cacheTtl,\n cacheInvalidateOnUpdate: resolved.cacheInvalidateOnUpdate,\n collectLogs: resolved.collectLogs,\n authentication: resolved.authentication,\n rateLimitingInterval: resolved.rateLimitingInterval,\n rateLimitingLimit: resolved.rateLimitingLimit,\n rateLimitingTechnique: resolved.rateLimitingTechnique,\n createdAt: ts,\n updatedAt: ts,\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { AIGatewayResourceConfig } from \"./ai-gateway.types.js\";\nimport { resolveAIGatewayConfig } from \"./ai-gateway.types.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\n\ninterface CFAIGateway {\n id: string;\n cache_ttl?: number;\n cache_invalidate_on_update?: boolean;\n collect_logs?: boolean;\n authentication?: boolean;\n rate_limiting_interval?: number;\n rate_limiting_limit?: number;\n rate_limiting_technique?: \"fixed\" | \"sliding\";\n}\n\nexport function aiGatewaySync(\n allGateways: CFAIGateway[],\n resources: AIGatewayResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = aiGatewayDeriveName(config, env, naming);\n const match = allGateways.find((g) => g.id === derivedName);\n if (!match) continue;\n const key = `ai_gateway:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n const resolved = resolveAIGatewayConfig(config);\n state.set(key, {\n type: \"ai_gateway\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: naming.aiGatewayBindingKey(config.logicalName),\n cfId: derivedName,\n cacheTtl: match.cache_ttl ?? resolved.cacheTtl,\n cacheInvalidateOnUpdate:\n match.cache_invalidate_on_update ?? resolved.cacheInvalidateOnUpdate,\n collectLogs: match.collect_logs ?? resolved.collectLogs,\n authentication: match.authentication ?? resolved.authentication,\n rateLimitingInterval:\n match.rate_limiting_interval ?? resolved.rateLimitingInterval,\n rateLimitingLimit:\n match.rate_limiting_limit ?? resolved.rateLimitingLimit,\n rateLimitingTechnique:\n match.rate_limiting_technique ?? resolved.rateLimitingTechnique,\n createdAt: existing?.type === \"ai_gateway\" ? existing.createdAt : ts,\n updatedAt: ts,\n });\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { AIGatewayResourceConfig } from \"./ai-gateway.types.js\";\nimport type { AIGatewayStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\n\ninterface CFAIGateway {\n id: string;\n}\n\nexport function aiGatewayDrift(\n allGateways: CFAIGateway[],\n resources: AIGatewayResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"ai_gateway\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfIds = new Set(allGateways.map((g) => g.id));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is AIGatewayStateEntry => e.type === \"ai_gateway\",\n );\n\n for (const config of resources) {\n const derivedName = aiGatewayDeriveName(config, env, naming);\n const inCloudflare = cfIds.has(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !inCloudflare) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (inCloudflare && !stateEntry) {\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId: derivedName,\n });\n } else if (!inCloudflare && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { AIGatewayStateEntry, CfiConfig } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function aiGatewayDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"ai_gateway\");\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, AIGatewayStateEntry] => kv[1].type === \"ai_gateway\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.aiGatewayDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Failed to delete AI Gateway ${entry.derivedName}:`,\n err,\n );\n }\n }\n}\n","import type { AIGatewayStateEntry, ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { AIGatewayResourceConfig } from \"./ai-gateway.types.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\n\nexport interface AIGatewayStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function aiGatewayStatus(\n resources: AIGatewayResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): AIGatewayStatusResult[] {\n const out: AIGatewayStatusResult[] = [];\n for (const config of resources) {\n const derivedName = aiGatewayDeriveName(config, env, naming);\n const entry = state.get(`ai_gateway:${derivedName}`) as\n | AIGatewayStateEntry\n | undefined;\n out.push({\n binding: naming.aiGatewayBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { AIGatewayResourceConfig } from \"./ai-gateway.types.js\";\nimport type {\n AIGatewayStateEntry,\n WorkerConfig,\n WorkerResources,\n} from \"../../types.js\";\nimport { aiGatewayApply } from \"./ai-gateway.apply.js\";\nimport { aiGatewaySync } from \"./ai-gateway.sync.js\";\nimport { aiGatewayDrift } from \"./ai-gateway.drift.js\";\nimport { aiGatewayDestroy } from \"./ai-gateway.destroy.js\";\nimport { aiGatewayStatus } from \"./ai-gateway.status.js\";\nimport { aiGatewayDiffPlanItems } from \"./ai-gateway.diff.js\";\nimport { resolveAIGatewayConfig } from \"./ai-gateway.types.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { aiGatewayDeriveName } from \"./ai-gateway.naming.js\";\n\ninterface CFAIGateway {\n id: string;\n cache_ttl?: number;\n cache_invalidate_on_update?: boolean;\n collect_logs?: boolean;\n authentication?: boolean;\n rate_limiting_interval?: number;\n rate_limiting_limit?: number;\n rate_limiting_technique?: \"fixed\" | \"sliding\";\n}\n\nexport const aiGatewayModule: ResourceModule<\n AIGatewayResourceConfig,\n CFAIGateway\n> = {\n kind: \"ai_gateway\",\n label: \"AI Gateway\",\n configKey: \"aiGateway\",\n stateEntryType: \"ai_gateway\",\n\n async fetchAll(api: CFApiClient): Promise<CFAIGateway[]> {\n return await api.aiGatewayListAll();\n },\n\n async apply(ctx) {\n await aiGatewayApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n aiGatewaySync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return aiGatewayDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n diff(ctx) {\n return aiGatewayDiffPlanItems({\n resources: ctx.resources,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n });\n },\n\n async destroy(ctx) {\n await aiGatewayDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return aiGatewayStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n /**\n * AI Gateway has no Wrangler binding kind — gateways are referenced per\n * request via `env.AI.run(model, opts, { gateway: { id } })`. Cross-resource\n * refs (`${tamer:ai_gateway:my_gw.name}`) are how the derived id reaches\n * worker code.\n */\n generate() {\n return {};\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): AIGatewayResourceConfig[] {\n return resourcesFrom(source)?.aiGateway ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"ai_gateway\") return;\n try {\n await api.aiGatewayDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete AI Gateway ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const gatewayId = options.cfId;\n if (!gatewayId) {\n throw new Error(\"import ai_gateway: --cf-id <gateway-id> is required\");\n }\n const resourceConfig =\n await findWorkerResourceByLogicalName<AIGatewayResourceConfig>(\n config,\n \"aiGateway\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import ai_gateway: no resources.aiGateway entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.aiGatewayListAll();\n const hit = all.find((g) => g.id === gatewayId);\n if (!hit) {\n throw new Error(\n `import ai_gateway: gateway \"${gatewayId}\" not found in account`,\n );\n }\n const derivedName = aiGatewayDeriveName(resourceConfig, env, naming);\n if (hit.id !== derivedName) {\n throw new Error(\n `import ai_gateway: cf id \"${hit.id}\" does not match derived \"${derivedName}\"`,\n );\n }\n const key = `ai_gateway:${derivedName}`;\n const existing = state.get(key);\n const defaults = resolveAIGatewayConfig({ logicalName: options.logical });\n const entry: AIGatewayStateEntry = {\n type: \"ai_gateway\",\n logicalName: options.logical,\n derivedName,\n bindingKey: naming.aiGatewayBindingKey(options.logical),\n cfId: hit.id,\n cacheTtl: hit.cache_ttl ?? defaults.cacheTtl,\n cacheInvalidateOnUpdate:\n hit.cache_invalidate_on_update ?? defaults.cacheInvalidateOnUpdate,\n collectLogs: hit.collect_logs ?? defaults.collectLogs,\n authentication: hit.authentication ?? defaults.authentication,\n rateLimitingInterval:\n hit.rate_limiting_interval ?? defaults.rateLimitingInterval,\n rateLimitingLimit: hit.rate_limiting_limit ?? defaults.rateLimitingLimit,\n rateLimitingTechnique:\n hit.rate_limiting_technique ?? defaults.rateLimitingTechnique,\n createdAt: existing?.type === \"ai_gateway\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolvePipelineCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { PipelineResourceConfig } from \"../../types.js\";\n\nexport function pipelineDeriveName(\n config: PipelineResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolvePipelineCloudflareName(config, env, naming);\n}\n\nexport function pipelineMatchPattern(\n config: PipelineResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolvePipelineCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\nconst STATE_KEY_PREFIX = \"pipeline:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\n/**\n * Idempotent create — skips when a state entry already exists. Pipeline SQL\n * updates on existing pipelines are deliberately not handled here (Cloudflare's\n * V1 endpoint has no PATCH today; SQL changes require a destroy + recreate).\n * Drift surfaces SQL mismatches so operators can recover explicitly.\n */\nexport async function pipelinesApply(\n resources: PipelineResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n if (existing) continue;\n\n const ts = new Date().toISOString();\n const created = await api.pipelineCreate({\n name: derivedName,\n sql: config.sql,\n });\n state.set(key, {\n type: \"pipeline\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.pipelineBindingKey(config.logicalName),\n cfId: created.id,\n sql: created.sql ?? config.sql,\n status: created.status,\n createdAt: ts,\n updatedAt: ts,\n });\n }\n}\n","import type { TenantMeta } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\ninterface CFPipeline {\n id: string;\n name: string;\n sql: string;\n status?: string;\n}\n\nexport function pipelinesSync(\n allPipelines: CFPipeline[],\n resources: PipelineResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const match = allPipelines.find((p) => p.name === derivedName);\n if (!match) continue;\n const key = `pipeline:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n state.set(key, {\n type: \"pipeline\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() || naming.pipelineBindingKey(config.logicalName),\n cfId: match.id,\n sql: match.sql,\n status: match.status,\n createdAt: existing?.type === \"pipeline\" ? existing.createdAt : ts,\n updatedAt: ts,\n });\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport type { PipelineStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\ninterface CFPipeline {\n id: string;\n name: string;\n sql: string;\n}\n\nexport function pipelinesDrift(\n allPipelines: CFPipeline[],\n resources: PipelineResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"pipeline\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allPipelines.map((p) => [p.name, p]));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is PipelineStateEntry => e.type === \"pipeline\",\n );\n\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const inCloudflare = cfByName.has(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !inCloudflare) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (inCloudflare && !stateEntry) {\n const cf = cfByName.get(derivedName)!;\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId: cf.id,\n });\n } else if (!inCloudflare && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, PipelineStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function pipelinesDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"pipeline\");\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, PipelineStateEntry] => kv[1].type === \"pipeline\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.pipelineDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Failed to delete Pipeline ${entry.derivedName}:`,\n err,\n );\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\nexport interface PipelineStateLike {\n get(key: string): StateEntry | undefined;\n}\n\nexport interface GeneratedPipelineBinding {\n binding: string;\n pipeline: string;\n}\n\n/**\n * Emit `pipelines[]` bindings for declared pipelines. Each binding requires\n * the pipeline to exist in state (i.e. `tamer apply` has run). Throws\n * otherwise so the operator gets an actionable error before `wrangler deploy`.\n *\n * Note: Wrangler's `pipeline` field accepts the pipeline **name**, not the\n * server-assigned id, so we emit the derived name here.\n */\nexport function pipelinesGenerate(\n resources: PipelineResourceConfig[],\n env: string,\n state: PipelineStateLike,\n naming: NamingEngine,\n): GeneratedPipelineBinding[] {\n const out: GeneratedPipelineBinding[] = [];\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const entry = state.get(`pipeline:${derivedName}`);\n if (!entry || entry.type !== \"pipeline\") {\n throw new Error(\n `Pipeline \"${config.logicalName}\" not in state. Run 'tamer apply --env ${env}' first.`,\n );\n }\n out.push({\n binding: entry.bindingKey,\n pipeline: entry.derivedName,\n });\n }\n return out;\n}\n","import type { PipelineStateEntry, ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\nexport interface PipelineStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function pipelinesStatus(\n resources: PipelineResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): PipelineStatusResult[] {\n const out: PipelineStatusResult[] = [];\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const entry = state.get(`pipeline:${derivedName}`) as\n | PipelineStateEntry\n | undefined;\n out.push({\n binding:\n config.binding?.trim() || naming.pipelineBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","/**\n * Plan-time diff for Cloudflare Pipelines (V1, SQL). The pipeline `sql`\n * body is the only mutable knob today, but Cloudflare V1 has no PATCH\n * endpoint — SQL changes require destroy + recreate. Plan signals this as\n * `replace` so the operator (or `apply --replace`, future work) can act on\n * it explicitly.\n *\n * The `binding` key is stored alongside the state row but is a wrangler-\n * generation concern (no Cloudflare-side resource changes), so a binding-\n * only drift is reported as `update` rather than `replace`.\n */\n\nimport type {\n PipelineResourceConfig,\n PipelineStateEntry,\n} from \"../../types.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { PlanFieldChange, PlanItem } from \"../../core/plan/plan.types.js\";\n\nexport function pipelinesDiffPlanItems(args: {\n resources: PipelineResourceConfig[];\n env: string;\n state: StateManager;\n naming: NamingEngine;\n}): PlanItem[] {\n const { resources, env, state, naming } = args;\n const items: PlanItem[] = [];\n\n for (const config of resources) {\n const derivedName = pipelineDeriveName(config, env, naming);\n const key = `pipeline:${derivedName}`;\n const entry = state.get(key);\n if (!entry || entry.type !== \"pipeline\") continue;\n const stateEntry = entry as PipelineStateEntry;\n\n const expectedBinding =\n config.binding?.trim() || naming.pipelineBindingKey(config.logicalName);\n\n const changes: PlanFieldChange[] = [];\n if (stateEntry.sql !== config.sql) {\n changes.push({\n field: \"sql\",\n from: truncate(stateEntry.sql),\n to: truncate(config.sql),\n kind: \"immutable\",\n });\n }\n if (stateEntry.bindingKey !== expectedBinding) {\n changes.push({\n field: \"binding\",\n from: stateEntry.bindingKey,\n to: expectedBinding,\n kind: \"mutable\",\n });\n }\n\n if (changes.length === 0) continue;\n const hasImmutable = changes.some((c) => c.kind === \"immutable\");\n items.push({\n kind: \"pipeline\",\n action: hasImmutable ? \"replace\" : \"update\",\n logicalName: config.logicalName,\n derivedName,\n detail: changes.map((c) => c.field).join(\", \"),\n changes,\n });\n }\n\n return items;\n}\n\nfunction truncate(v: string): string {\n return v.length > 60 ? `${v.slice(0, 57)}...` : v;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { PipelineResourceConfig } from \"./pipelines.types.js\";\nimport type {\n PipelineStateEntry,\n WorkerConfig,\n WorkerResources,\n} from \"../../types.js\";\nimport { pipelinesApply } from \"./pipelines.apply.js\";\nimport { pipelinesSync } from \"./pipelines.sync.js\";\nimport { pipelinesDrift } from \"./pipelines.drift.js\";\nimport { pipelinesDestroy } from \"./pipelines.destroy.js\";\nimport { pipelinesGenerate } from \"./pipelines.generate.js\";\nimport { pipelinesStatus } from \"./pipelines.status.js\";\nimport { pipelinesDiffPlanItems } from \"./pipelines.diff.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { pipelineDeriveName } from \"./pipelines.naming.js\";\n\ninterface CFPipeline {\n id: string;\n name: string;\n sql: string;\n status?: string;\n}\n\nexport const pipelinesModule: ResourceModule<\n PipelineResourceConfig,\n CFPipeline\n> = {\n kind: \"pipeline\",\n label: \"Pipeline\",\n configKey: \"pipelines\",\n stateEntryType: \"pipeline\",\n\n async fetchAll(api: CFApiClient): Promise<CFPipeline[]> {\n const all = await api.pipelineListAll();\n return all.map((p) => ({\n id: p.id,\n name: p.name,\n sql: p.sql,\n status: p.status,\n }));\n },\n\n async apply(ctx) {\n await pipelinesApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n pipelinesSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return pipelinesDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n diff(ctx) {\n return pipelinesDiffPlanItems({\n resources: ctx.resources,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n });\n },\n\n async destroy(ctx) {\n await pipelinesDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return pipelinesStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n const generated =\n ctx.resources.length > 0\n ? pipelinesGenerate(ctx.resources, ctx.env, ctx.state, ctx.naming)\n : [];\n const passthrough = ctx.passthrough?.pipelines ?? [];\n if (generated.length === 0 && passthrough.length === 0) return {};\n return { pipelines: [...passthrough, ...generated] };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): PipelineResourceConfig[] {\n return resourcesFrom(source)?.pipelines ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"pipeline\") return;\n try {\n await api.pipelineDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete Pipeline ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const pipelineId = options.cfId;\n if (!pipelineId) {\n throw new Error(\"import pipeline: --cf-id <pipeline-id> is required\");\n }\n const resourceConfig =\n await findWorkerResourceByLogicalName<PipelineResourceConfig>(\n config,\n \"pipelines\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import pipeline: no resources.pipelines entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.pipelineListAll();\n const hit = all.find((p) => p.id === pipelineId);\n if (!hit) {\n throw new Error(\n `import pipeline: pipeline \"${pipelineId}\" not found in account`,\n );\n }\n const derivedName = pipelineDeriveName(resourceConfig, env, naming);\n if (hit.name !== derivedName) {\n throw new Error(\n `import pipeline: cf name \"${hit.name}\" does not match derived \"${derivedName}\"`,\n );\n }\n const key = `pipeline:${derivedName}`;\n const existing = state.get(key);\n const entry: PipelineStateEntry = {\n type: \"pipeline\",\n logicalName: options.logical,\n derivedName,\n bindingKey: naming.pipelineBindingKey(options.logical),\n cfId: hit.id,\n sql: hit.sql,\n status: hit.status,\n createdAt: existing?.type === \"pipeline\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveWorkflowCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\n\nexport function workflowDeriveName(\n config: WorkflowResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveWorkflowCloudflareName(config, env, naming);\n}\n\nexport function workflowMatchPattern(\n config: WorkflowResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveWorkflowCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","/**\n * Plan-time field-level diff for declared Workflows. Compares the recorded\n * {@link WorkflowStateEntry} against the {@link WorkflowResourceConfig} the\n * user wrote, and returns `update` {@link PlanItem}s for any drifted field.\n *\n * Workflows are upserted via `PUT /accounts/{id}/workflows/{name}` —\n * Cloudflare treats the call as create-or-update across `class_name`,\n * `script_name`, and `limits`, so every meaningful drift is an in-place\n * `update` (never a `replace`). Drift in just the binding key is also\n * tracked since `wrangler deploy` would emit a different fragment.\n *\n * Resources without a recorded state entry are not surfaced here — they\n * appear as `create` items via the `drift().undeployed` path in\n * `computePlan`.\n */\n\nimport type {\n WorkflowResourceConfig,\n WorkflowStateEntry,\n} from \"../../types.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { WorkerScope } from \"../../core/registry/types.js\";\nimport type { PlanFieldChange, PlanItem } from \"../../core/plan/plan.types.js\";\n\nexport function workflowsDiffPlanItems(args: {\n resources: WorkflowResourceConfig[];\n env: string;\n state: StateManager;\n naming: NamingEngine;\n worker?: WorkerScope;\n}): PlanItem[] {\n const { resources, env, state, naming, worker } = args;\n const items: PlanItem[] = [];\n\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const key = `workflow:${derivedName}`;\n const entry = state.get(key);\n if (!entry || entry.type !== \"workflow\") continue;\n\n const stateEntry = entry as WorkflowStateEntry;\n const changes = computeWorkflowChanges(stateEntry, config, naming, worker);\n if (changes.length === 0) continue;\n items.push({\n kind: \"workflow\",\n action: \"update\",\n logicalName: config.logicalName,\n derivedName,\n detail: changes\n .map((c) => `${c.field}: ${formatVal(c.from)} -> ${formatVal(c.to)}`)\n .join(\", \"),\n changes,\n });\n }\n\n return items;\n}\n\n/**\n * Pure comparison shared with `workflowsApply` so plan and apply agree\n * on what counts as drift on a registered workflow. Drift in any of\n * `className`, `scriptName` (defaulting to the owning worker's\n * deployed name), `limits.steps`, or the binding key triggers an\n * in-place PUT — Cloudflare treats `PUT /accounts/{id}/workflows/{name}`\n * as create-or-update.\n */\nexport function computeWorkflowChanges(\n state: WorkflowStateEntry,\n config: WorkflowResourceConfig,\n naming: NamingEngine,\n worker: WorkerScope | undefined,\n): PlanFieldChange[] {\n const expectedScriptName =\n config.scriptName?.trim() ?? worker?.deployedName;\n const expectedBindingKey =\n config.binding?.trim() || naming.workflowBindingKey(config.logicalName);\n\n const changes: PlanFieldChange[] = [];\n\n if (state.className !== config.className) {\n changes.push({\n field: \"className\",\n from: state.className,\n to: config.className,\n kind: \"mutable\",\n });\n }\n if (\n expectedScriptName !== undefined &&\n state.scriptName !== expectedScriptName\n ) {\n changes.push({\n field: \"scriptName\",\n from: state.scriptName,\n to: expectedScriptName,\n kind: \"mutable\",\n });\n }\n const stateSteps = state.limits?.steps;\n const configSteps = config.limits?.steps;\n if ((stateSteps ?? null) !== (configSteps ?? null)) {\n changes.push({\n field: \"limits.steps\",\n from: stateSteps,\n to: configSteps,\n kind: \"mutable\",\n });\n }\n if (state.bindingKey !== expectedBindingKey) {\n changes.push({\n field: \"binding\",\n from: state.bindingKey,\n to: expectedBindingKey,\n kind: \"mutable\",\n });\n }\n\n return changes;\n}\n\nfunction formatVal(v: unknown): string {\n if (v === undefined || v === null) return \"(unset)\";\n if (typeof v === \"string\") return v.length > 32 ? `${v.slice(0, 29)}...` : v;\n return String(v);\n}\n","import type { TenantMeta, WorkflowStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { WorkerScope } from \"../../core/registry/types.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport { computeWorkflowChanges } from \"./workflows.diff.js\";\nimport { logApplyChange } from \"../../core/plan/planFormat.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\n\nconst STATE_KEY_PREFIX = \"workflow:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\nfunction resolveScriptName(\n config: WorkflowResourceConfig,\n worker: WorkerScope | undefined,\n): string {\n const explicit = config.scriptName?.trim();\n if (explicit) return explicit;\n if (!worker) {\n throw new Error(\n `workflow \"${config.logicalName}\": no scriptName given and module ran ` +\n `without a worker scope — set scriptName on the resource or invoke ` +\n `apply per-worker.`,\n );\n }\n return worker.deployedName;\n}\n\nfunction limitsEqual(\n a: { steps?: number } | undefined,\n b: { steps?: number } | undefined,\n): boolean {\n return (a?.steps ?? null) === (b?.steps ?? null);\n}\n\n/**\n * Idempotent upsert via `PUT /accounts/{id}/workflows/{name}`. Cloudflare\n * treats PUT as create-or-update, so we issue it whenever the recorded\n * `(class_name, script_name, limits)` triple has drifted from config (or\n * the workflow has never been registered at all). Drift between recorded\n * state and *live* Cloudflare is surfaced separately by `workflowsDrift`.\n */\nexport async function workflowsApply(\n resources: WorkflowResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n worker?: WorkerScope,\n): Promise<void> {\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const scriptName = resolveScriptName(config, worker);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n const wantsBindingKey =\n config.binding?.trim() || naming.workflowBindingKey(config.logicalName);\n\n if (\n existing &&\n existing.type === \"workflow\" &&\n existing.className === config.className &&\n existing.scriptName === scriptName &&\n limitsEqual(existing.limits, config.limits) &&\n existing.bindingKey === wantsBindingKey\n ) {\n continue;\n }\n\n if (existing && existing.type === \"workflow\") {\n const changes = computeWorkflowChanges(existing, config, naming, worker);\n logApplyChange({\n kind: \"workflow\",\n action: \"update\",\n logical: config.logicalName,\n derived: derivedName,\n changes,\n });\n } else {\n logApplyChange({\n kind: \"workflow\",\n action: \"create\",\n logical: config.logicalName,\n derived: derivedName,\n });\n }\n\n const ts = new Date().toISOString();\n let upserted: Awaited<ReturnType<typeof api.workflowUpsert>>;\n try {\n upserted = await api.workflowUpsert(derivedName, {\n class_name: config.className,\n script_name: scriptName,\n ...(config.limits ? { limits: config.limits } : {}),\n });\n } catch (err) {\n // Script may not be deployed yet (chicken-and-egg: apply runs before\n // deploy on greenfield envs). Skip — deploy will register the workflow\n // after wrangler deploy succeeds.\n if (!existing) {\n console.warn(\n ` workflow ${config.logicalName} -> ${derivedName}: deferred (script \"${scriptName}\" not deployed yet; will register during deploy)`,\n );\n continue;\n }\n throw err;\n }\n const entry: WorkflowStateEntry = {\n type: \"workflow\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: wantsBindingKey,\n cfId: upserted.id,\n className: upserted.class_name,\n scriptName: upserted.script_name,\n limits: config.limits,\n createdAt: existing?.type === \"workflow\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n }\n}\n","import type { TenantMeta, WorkflowStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport { workflowDeriveName, workflowMatchPattern } from \"./workflows.naming.js\";\n\ninterface CFWorkflow {\n id: string;\n name: string;\n class_name: string;\n script_name: string;\n}\n\n/**\n * Match each declared workflow against `GET /accounts/{id}/workflows` and\n * upsert into state. Stack-scoped: `resources` is already filtered to the\n * current config, so we never persist a workflow owned by another stack\n * sharing this state row.\n */\nexport function workflowsSync(\n allWorkflows: CFWorkflow[],\n resources: WorkflowResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const pattern = workflowMatchPattern(config, env, naming);\n const match = allWorkflows.find((w) => pattern(w.name));\n if (!match) continue;\n const key = `workflow:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n const entry: WorkflowStateEntry = {\n type: \"workflow\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey:\n config.binding?.trim() ||\n naming.workflowBindingKey(config.logicalName),\n cfId: match.id,\n className: match.class_name,\n scriptName: match.script_name,\n limits:\n existing?.type === \"workflow\" ? existing.limits : config.limits,\n createdAt: existing?.type === \"workflow\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport type { WorkflowStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\n\ninterface CFWorkflow {\n id: string;\n name: string;\n class_name: string;\n script_name: string;\n}\n\nexport function workflowsDrift(\n allWorkflows: CFWorkflow[],\n resources: WorkflowResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"workflow\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allWorkflows.map((w) => [w.name, w]));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is WorkflowStateEntry => e.type === \"workflow\",\n );\n\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const inCloudflare = cfByName.has(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !inCloudflare) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (inCloudflare && !stateEntry) {\n const cf = cfByName.get(derivedName)!;\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId: cf.id,\n });\n } else if (!inCloudflare && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, WorkflowStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function workflowsDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(config, baseDir, \"workflow\");\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, WorkflowStateEntry] => kv[1].type === \"workflow\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.workflowDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Failed to delete Workflow ${entry.derivedName}:`,\n err,\n );\n }\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport type { StateEntry } from \"../../types.js\";\nimport type { WorkerScope } from \"../../core/registry/types.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\n\nexport interface WorkflowStateLike {\n get(key: string): StateEntry | undefined;\n}\n\nexport interface GeneratedWorkflowBinding {\n binding: string;\n name: string;\n class_name: string;\n /**\n * Optional per Cloudflare's wrangler schema — omitted when the workflow\n * lives in the same script as the binding (Wrangler defaults `script_name`\n * to the worker's own `name`). Emitted only when an explicit\n * `WorkflowResourceConfig.scriptName` was provided.\n */\n script_name?: string;\n}\n\n/**\n * Emit `workflows[]` bindings for declared workflows. When the workflow is\n * already in state (normal case after apply), uses the recorded values.\n * When not in state (deferred during apply because the script wasn't\n * deployed yet), derives binding values from config + naming engine so\n * wrangler.json can be generated — deploy will register the workflow\n * after the script is live.\n */\nexport function workflowsGenerate(\n resources: WorkflowResourceConfig[],\n env: string,\n state: WorkflowStateLike,\n naming: NamingEngine,\n worker?: WorkerScope,\n): GeneratedWorkflowBinding[] {\n const out: GeneratedWorkflowBinding[] = [];\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const entry = state.get(`workflow:${derivedName}`);\n const explicitScript = config.scriptName?.trim();\n const ownerScript = worker?.deployedName;\n\n if (entry && entry.type === \"workflow\") {\n // Normal case: workflow in state, use recorded values.\n const binding: GeneratedWorkflowBinding = {\n binding: entry.bindingKey,\n name: entry.derivedName,\n class_name: entry.className,\n };\n if (explicitScript) {\n binding.script_name = explicitScript;\n } else if (ownerScript && ownerScript !== entry.scriptName) {\n binding.script_name = entry.scriptName;\n }\n out.push(binding);\n } else {\n // Deferred: workflow not in state (script not deployed yet).\n // Derive from config so wrangler.json can be generated.\n const binding: GeneratedWorkflowBinding = {\n binding: config.binding?.trim() ?? naming.workflowBindingKey(config.logicalName),\n name: derivedName,\n class_name: config.className,\n };\n if (explicitScript) {\n binding.script_name = explicitScript;\n }\n out.push(binding);\n }\n }\n return out;\n}\n","import type { WorkflowStateEntry, ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\n\nexport interface WorkflowStatusResult {\n binding: string;\n name: string;\n status: ResourceStatus;\n}\n\nexport function workflowsStatus(\n resources: WorkflowResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): WorkflowStatusResult[] {\n const out: WorkflowStatusResult[] = [];\n for (const config of resources) {\n const derivedName = workflowDeriveName(config, env, naming);\n const entry = state.get(`workflow:${derivedName}`) as\n | WorkflowStateEntry\n | undefined;\n out.push({\n binding:\n config.binding?.trim() ||\n naming.workflowBindingKey(config.logicalName),\n name: derivedName,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { WorkflowResourceConfig } from \"./workflows.types.js\";\nimport type {\n WorkflowStateEntry,\n WorkerConfig,\n WorkerResources,\n} from \"../../types.js\";\nimport { workflowsApply } from \"./workflows.apply.js\";\nimport { workflowsSync } from \"./workflows.sync.js\";\nimport { workflowsDrift } from \"./workflows.drift.js\";\nimport { workflowsDiffPlanItems } from \"./workflows.diff.js\";\nimport { workflowsDestroy } from \"./workflows.destroy.js\";\nimport { workflowsGenerate } from \"./workflows.generate.js\";\nimport { workflowsStatus } from \"./workflows.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { workflowDeriveName } from \"./workflows.naming.js\";\n\ninterface CFWorkflow {\n id: string;\n name: string;\n class_name: string;\n script_name: string;\n}\n\nexport const workflowsModule: ResourceModule<\n WorkflowResourceConfig,\n CFWorkflow\n> = {\n kind: \"workflow\",\n label: \"Workflow\",\n configKey: \"workflows\",\n stateEntryType: \"workflow\",\n\n async fetchAll(api: CFApiClient): Promise<CFWorkflow[]> {\n const all = await api.workflowListAll();\n return all.map((w) => ({\n id: w.id,\n name: w.name,\n class_name: w.class_name,\n script_name: w.script_name,\n }));\n },\n\n async apply(ctx) {\n await workflowsApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n ctx.worker,\n );\n },\n\n sync(ctx) {\n workflowsSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return workflowsDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n diff(ctx) {\n return workflowsDiffPlanItems({\n resources: ctx.resources,\n env: ctx.env,\n state: ctx.state,\n naming: ctx.naming,\n worker: ctx.worker,\n });\n },\n\n async destroy(ctx) {\n await workflowsDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return workflowsStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n generate(ctx) {\n const generated =\n ctx.resources.length > 0\n ? workflowsGenerate(\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n ctx.worker,\n )\n : [];\n const passthrough = ctx.passthrough?.workflows ?? [];\n if (generated.length === 0 && passthrough.length === 0) return {};\n return { workflows: [...passthrough, ...generated] };\n },\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): WorkflowResourceConfig[] {\n return resourcesFrom(source)?.workflows ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"workflow\") return;\n try {\n await api.workflowDelete(entry.derivedName);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete Workflow ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const resourceConfig =\n await findWorkerResourceByLogicalName<WorkflowResourceConfig>(\n config,\n \"workflows\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import workflow: no resources.workflows entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const derivedName = workflowDeriveName(resourceConfig, env, naming);\n const all = await api.workflowListAll();\n const hit = all.find((w) => w.name === derivedName);\n if (!hit) {\n throw new Error(\n `import workflow: no workflow named \"${derivedName}\" found in account`,\n );\n }\n if (options.cfId && hit.id !== options.cfId) {\n throw new Error(\n `import workflow: cf id \"${hit.id}\" does not match --cf-id \"${options.cfId}\"`,\n );\n }\n const key = `workflow:${derivedName}`;\n const existing = state.get(key);\n const entry: WorkflowStateEntry = {\n type: \"workflow\",\n logicalName: options.logical,\n derivedName,\n bindingKey: naming.workflowBindingKey(options.logical),\n cfId: hit.id,\n className: hit.class_name,\n scriptName: hit.script_name,\n limits:\n existing?.type === \"workflow\" ? existing.limits : undefined,\n createdAt: existing?.type === \"workflow\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport { resolveSecretsStoreCloudflareName } from \"../../core/naming/resolveCloudflareName.js\";\nimport type { SecretsStoreResourceConfig } from \"../../types.js\";\n\nexport function secretsStoreDeriveName(\n config: SecretsStoreResourceConfig,\n env: string,\n naming: NamingEngine,\n): string {\n return resolveSecretsStoreCloudflareName(config, env, naming);\n}\n\nexport function secretsStoreMatchPattern(\n config: SecretsStoreResourceConfig,\n env: string,\n naming: NamingEngine,\n): (name: string) => boolean {\n const expected = resolveSecretsStoreCloudflareName(config, env, naming);\n return (name: string) => name === expected;\n}\n","import type { TenantMeta, SecretsStoreStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { SecretsStoreResourceConfig } from \"./secrets-store.types.js\";\nimport { secretsStoreDeriveName } from \"./secrets-store.naming.js\";\n\nconst STATE_KEY_PREFIX = \"secrets_store:\";\n\nfunction stateKey(derivedName: string): string {\n return `${STATE_KEY_PREFIX}${derivedName}`;\n}\n\n/**\n * Idempotent provisioning for Secrets Store stores. The Cloudflare create\n * endpoint is non-idempotent (a duplicate name returns 409), so we list\n * first and short-circuit when a matching name already exists. Secret\n * **values** are deliberately out of scope — Tamer only manages the\n * account-scoped container. See `SecretsStoreSecretBinding` for how\n * worker bindings reference the resolved `store_id`.\n */\nexport async function secretsStoreApply(\n resources: SecretsStoreResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n api: CFApiClient,\n state: StateManager,\n naming: NamingEngine,\n): Promise<void> {\n if (resources.length === 0) return;\n\n let allStores:\n | Awaited<ReturnType<typeof api.secretsStoreListAll>>\n | null = null;\n\n for (const config of resources) {\n const derivedName = secretsStoreDeriveName(config, env, naming);\n const key = stateKey(derivedName);\n const existing = state.get(key);\n const wantsBindingKey = naming.secretsStoreBindingKey(config.logicalName);\n\n if (\n existing &&\n existing.type === \"secrets_store\" &&\n existing.bindingKey === wantsBindingKey\n ) {\n continue;\n }\n\n if (allStores === null) {\n allStores = await api.secretsStoreListAll();\n }\n const match = allStores.find((s) => s.name === derivedName);\n\n const ts = new Date().toISOString();\n let cfId: string;\n if (match) {\n cfId = match.id;\n } else {\n const created = await api.secretsStoreCreate(derivedName);\n cfId = created.id;\n }\n\n const entry: SecretsStoreStateEntry = {\n type: \"secrets_store\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: wantsBindingKey,\n cfId,\n createdAt:\n existing?.type === \"secrets_store\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n }\n}\n","import type { TenantMeta, SecretsStoreStateEntry } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { SecretsStoreResourceConfig } from \"./secrets-store.types.js\";\nimport { secretsStoreDeriveName } from \"./secrets-store.naming.js\";\n\ninterface CFSecretsStore {\n id: string;\n name: string;\n}\n\n/**\n * Match each declared store against `GET /accounts/{id}/secrets_store/stores`\n * and upsert into state. Stack-scoped: `resources` is already filtered to\n * the current config so we never persist a store owned by another stack\n * sharing this state row.\n */\nexport function secretsStoreSync(\n allStores: CFSecretsStore[],\n resources: SecretsStoreResourceConfig[],\n _tenant: TenantMeta,\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): void {\n for (const config of resources) {\n const derivedName = secretsStoreDeriveName(config, env, naming);\n const match = allStores.find((s) => s.name === derivedName);\n if (!match) continue;\n const key = `secrets_store:${derivedName}`;\n const existing = state.get(key);\n const ts = new Date().toISOString();\n const entry: SecretsStoreStateEntry = {\n type: \"secrets_store\",\n logicalName: config.logicalName,\n derivedName,\n bindingKey: naming.secretsStoreBindingKey(config.logicalName),\n cfId: match.id,\n createdAt:\n existing?.type === \"secrets_store\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n }\n}\n","import type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { SecretsStoreResourceConfig } from \"./secrets-store.types.js\";\nimport type { SecretsStoreStateEntry } from \"../../types.js\";\nimport type { ResourceDrift } from \"../../core/drift/drift.types.js\";\nimport { secretsStoreDeriveName } from \"./secrets-store.naming.js\";\n\ninterface CFSecretsStore {\n id: string;\n name: string;\n}\n\nexport function secretsStoreDrift(\n allStores: CFSecretsStore[],\n resources: SecretsStoreResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): ResourceDrift {\n const drift: ResourceDrift = {\n kind: \"secret_store\",\n missingFromCloudflare: [],\n unrecordedInState: [],\n undeployed: [],\n };\n\n const cfByName = new Map(allStores.map((s) => [s.name, s]));\n const stateEntries = Object.values(state.getAll()).filter(\n (e): e is SecretsStoreStateEntry => e.type === \"secrets_store\",\n );\n\n for (const config of resources) {\n const derivedName = secretsStoreDeriveName(config, env, naming);\n const inCloudflare = cfByName.has(derivedName);\n const stateEntry = stateEntries.find(\n (e) => e.logicalName === config.logicalName,\n );\n if (stateEntry && !inCloudflare) {\n drift.missingFromCloudflare.push({\n logicalName: stateEntry.logicalName,\n derivedName: stateEntry.derivedName,\n cfId: stateEntry.cfId,\n });\n } else if (inCloudflare && !stateEntry) {\n const cf = cfByName.get(derivedName)!;\n drift.unrecordedInState.push({\n logicalName: config.logicalName,\n derivedName,\n cfId: cf.id,\n });\n } else if (!inCloudflare && !stateEntry) {\n drift.undeployed.push({\n logicalName: config.logicalName,\n derivedName,\n });\n }\n }\n\n return drift;\n}\n","import type { CfiConfig, SecretsStoreStateEntry } from \"../../types.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport { logicalNamesForResourceKind } from \"../../core/config/resourcesFromConfig.js\";\n\nexport async function secretsStoreDestroy(\n _env: string,\n state: StateManager,\n api: CFApiClient,\n config: CfiConfig,\n baseDir: string,\n _force?: boolean,\n): Promise<void> {\n const owned = await logicalNamesForResourceKind(\n config,\n baseDir,\n \"secret_store\",\n );\n const resources = state.getAll();\n const entries = Object.entries(resources).filter(\n (kv): kv is [string, SecretsStoreStateEntry] =>\n kv[1].type === \"secrets_store\",\n );\n\n for (const [key, entry] of entries) {\n if (!owned.has(entry.logicalName)) continue;\n try {\n await api.secretsStoreDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Failed to delete Secrets Store ${entry.derivedName}:`,\n err,\n );\n }\n }\n}\n","import type { SecretsStoreStateEntry, ResourceStatus } from \"../../types.js\";\nimport type { NamingEngine } from \"../../core/naming/NamingEngine.js\";\nimport type { StateManager } from \"../../core/state/StateManager.js\";\nimport type { SecretsStoreResourceConfig } from \"./secrets-store.types.js\";\nimport { secretsStoreDeriveName } from \"./secrets-store.naming.js\";\n\nexport interface SecretsStoreStatusResult {\n binding: string;\n name: string;\n cfId?: string;\n status: ResourceStatus;\n}\n\nexport function secretsStoreStatus(\n resources: SecretsStoreResourceConfig[],\n env: string,\n state: StateManager,\n naming: NamingEngine,\n): SecretsStoreStatusResult[] {\n const out: SecretsStoreStatusResult[] = [];\n for (const config of resources) {\n const derivedName = secretsStoreDeriveName(config, env, naming);\n const entry = state.get(`secrets_store:${derivedName}`) as\n | SecretsStoreStateEntry\n | undefined;\n out.push({\n binding: naming.secretsStoreBindingKey(config.logicalName),\n name: derivedName,\n cfId: entry?.cfId,\n status: entry ? \"ok\" : \"missing\",\n });\n }\n return out;\n}\n","import type { CFApiClient } from \"../../core/api/CFApiClient.js\";\nimport type { ResourceModule } from \"../../core/registry/types.js\";\nimport type { SecretsStoreResourceConfig } from \"./secrets-store.types.js\";\nimport type {\n SecretsStoreStateEntry,\n WorkerConfig,\n WorkerResources,\n} from \"../../types.js\";\nimport { secretsStoreApply } from \"./secrets-store.apply.js\";\nimport { secretsStoreSync } from \"./secrets-store.sync.js\";\nimport { secretsStoreDrift } from \"./secrets-store.drift.js\";\nimport { secretsStoreDestroy } from \"./secrets-store.destroy.js\";\nimport { secretsStoreStatus } from \"./secrets-store.status.js\";\nimport { resourcesFrom } from \"../../core/registry/pickResources.js\";\nimport { findWorkerResourceByLogicalName } from \"../../core/registry/findResourceForImport.js\";\nimport { secretsStoreDeriveName } from \"./secrets-store.naming.js\";\n\ninterface CFSecretsStore {\n id: string;\n name: string;\n}\n\nexport const secretsStoreModule: ResourceModule<\n SecretsStoreResourceConfig,\n CFSecretsStore\n> = {\n kind: \"secret_store\",\n label: \"Secrets Store\",\n configKey: \"secretsStores\",\n stateEntryType: \"secrets_store\",\n\n async fetchAll(api: CFApiClient): Promise<CFSecretsStore[]> {\n const all = await api.secretsStoreListAll();\n return all.map((s) => ({ id: s.id, name: s.name }));\n },\n\n async apply(ctx) {\n await secretsStoreApply(\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.api,\n ctx.state,\n ctx.naming,\n );\n },\n\n sync(ctx) {\n secretsStoreSync(\n ctx.all,\n ctx.resources,\n ctx.tenant,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n drift(ctx) {\n return secretsStoreDrift(\n ctx.all,\n ctx.resources,\n ctx.env,\n ctx.state,\n ctx.naming,\n );\n },\n\n async destroy(ctx) {\n await secretsStoreDestroy(\n ctx.env,\n ctx.state,\n ctx.api,\n ctx.config,\n ctx.baseDir,\n ctx.force,\n );\n },\n\n status(ctx) {\n return secretsStoreStatus(ctx.resources, ctx.env, ctx.state, ctx.naming);\n },\n\n /**\n * Stores themselves contribute no wrangler binding — `secrets_store_secrets[]`\n * rows are emitted in `generator.ts` after all module fragments merge,\n * because they reference the worker's `secretsStoreSecrets` (a separate\n * deploy-time field, not a managed lifecycle resource).\n */\n generate() {\n return {};\n },\n\n /**\n * No `diff()` opt-in: Cloudflare's Secrets Store API exposes **no update\n * endpoint** for stores themselves (only `POST` / `GET` / `DELETE`;\n * `PATCH /accounts/{id}/secrets_store/stores/{store_id}/secrets/{secret_id}`\n * targets individual *secrets*, which Tamer deliberately does not manage —\n * see `SECRETS_STORE_DEFAULTS`). `SecretsStoreResourceConfig` is also just\n * `{ logicalName }`, so there are no Tamer-tracked fields whose drift could\n * become an `update` plan item. Renaming a store's `logicalName` changes\n * the **derived** name (identity), which falls into the registry's normal\n * delete-and-recreate path via `pickResources` / `destroyOne`. If\n * Cloudflare ever exposes per-store mutable settings (e.g. retention,\n * region pin), wire them through `SECRETS_STORE_DEFAULTS` and add a\n * `diff()` here following the AI Gateway / Hyperdrive pattern.\n */\n\n pickResources(\n source: WorkerConfig | WorkerResources | undefined,\n ): SecretsStoreResourceConfig[] {\n return resourcesFrom(source)?.secretsStores ?? [];\n },\n\n async destroyOne({ api, state, key, entry }) {\n if (entry.type !== \"secrets_store\") return;\n try {\n await api.secretsStoreDelete(entry.cfId);\n state.delete(key);\n } catch (err) {\n console.warn(\n `Rollback: failed to delete Secrets Store ${entry.derivedName}:`,\n err,\n );\n }\n },\n\n async importOne({ options, env, api, state, naming, config, baseDir, ts }) {\n const resourceConfig =\n await findWorkerResourceByLogicalName<SecretsStoreResourceConfig>(\n config,\n \"secretsStores\",\n options.logical,\n baseDir,\n );\n if (!resourceConfig) {\n throw new Error(\n `import secret_store: no resources.secretsStores entry with logicalName \"${options.logical}\" in the Tamer project config`,\n );\n }\n const all = await api.secretsStoreListAll();\n const derivedName = secretsStoreDeriveName(resourceConfig, env, naming);\n const hit = all.find((s) => s.name === derivedName);\n if (!hit) {\n throw new Error(\n `import secret_store: no store named \"${derivedName}\" found in account`,\n );\n }\n if (options.cfId && hit.id !== options.cfId) {\n throw new Error(\n `import secret_store: cf id \"${hit.id}\" does not match --cf-id \"${options.cfId}\"`,\n );\n }\n const key = `secrets_store:${derivedName}`;\n const existing = state.get(key);\n const entry: SecretsStoreStateEntry = {\n type: \"secrets_store\",\n logicalName: options.logical,\n derivedName,\n bindingKey: naming.secretsStoreBindingKey(options.logical),\n cfId: hit.id,\n createdAt:\n existing?.type === \"secrets_store\" ? existing.createdAt : ts,\n updatedAt: ts,\n };\n state.set(key, entry);\n },\n};\n","/**\n * Single source of truth for Tamer-managed Cloudflare resource kinds.\n *\n * To add a new resource (e.g. Pipelines, Workflows, Pages):\n * 1. Add the config + state types to `src/types.ts` and Zod schema.\n * 2. Implement the per-resource feature module under `src/features/<kind>/`.\n * 3. Author `<kind>.module.ts` exporting a {@link ResourceModule}.\n * 4. Append it to {@link resourceModules} below.\n *\n * Every command (`apply`, `sync`, `drift`, `destroy`, `status`, `import`,\n * the wrangler generator) iterates this array — no additional plumbing is\n * required for the resource to be honored across all commands.\n */\n\nimport type { ResourceKind, ResourceModule } from \"./types.js\";\nimport { d1Module } from \"../../features/d1/d1.module.js\";\nimport { r2Module } from \"../../features/r2/r2.module.js\";\nimport { kvModule } from \"../../features/kv/kv.module.js\";\nimport { queuesModule } from \"../../features/queues/queues.module.js\";\nimport { hyperdriveModule } from \"../../features/hyperdrive/hyperdrive.module.js\";\nimport { vectorizeModule } from \"../../features/vectorize/vectorize.module.js\";\nimport { aiGatewayModule } from \"../../features/ai-gateway/ai-gateway.module.js\";\nimport { pipelinesModule } from \"../../features/pipelines/pipelines.module.js\";\nimport { workflowsModule } from \"../../features/workflows/workflows.module.js\";\nimport { secretsStoreModule } from \"../../features/secrets-store/secrets-store.module.js\";\n\nexport const resourceModules: ReadonlyArray<ResourceModule> = [\n d1Module as ResourceModule,\n r2Module as ResourceModule,\n kvModule as ResourceModule,\n queuesModule as ResourceModule,\n hyperdriveModule as ResourceModule,\n vectorizeModule as ResourceModule,\n aiGatewayModule as ResourceModule,\n pipelinesModule as ResourceModule,\n workflowsModule as ResourceModule,\n secretsStoreModule as ResourceModule,\n];\n\nconst moduleByKind: Map<ResourceKind, ResourceModule> = new Map(\n resourceModules.map((m) => [m.kind, m]),\n);\n\n/** Lookup by stable kind. Returns `undefined` for unknown kinds. */\nexport function getResourceModule(\n kind: ResourceKind,\n): ResourceModule | undefined {\n return moduleByKind.get(kind);\n}\n\n/** Throws if no module is registered for `kind`. */\nexport function requireResourceModule(kind: ResourceKind): ResourceModule {\n const m = moduleByKind.get(kind);\n if (!m) throw new Error(`No registered resource module for kind \"${kind}\"`);\n return m;\n}\n\nexport type { ResourceKind, ResourceModule } from \"./types.js\";\n"],"mappings":";;;;;AAgBA,SAAS,gBACP,IACA,UACA,KACA,KACoB;AACpB,KAAI,CAAC,GAAI,QAAO;AAChB,QAAO,GAAG,UAAU,KAAK,IAAI;;;AAI/B,SAAgB,wBACd,QACA,KACA,QACA,WACQ;CACR,MAAM,WAAW,OAAO;AACxB,KAAI,OAAO,SAAS,UAAU;EAC5B,MAAMA,aAAW,gBAAgB,OAAO,gBAAgB,UAAU,IAAI;AACtE,MAAIA,eAAa,OAAW,QAAOA;AACnC,SAAO,OAAO,aAAa,OAAO,aAAa,IAAI;;AAErD,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,eAAe,OAAO,YAAY,sBAAsB;CAE1E,MAAM,WAAW,gBAAgB,OAAO,gBAAgB,UAAU,KAAK,EACrE,WACD,CAAC;AACF,KAAI,aAAa,OAAW,QAAO;AACnC,QAAO,OAAO,YAAY,OAAO,aAAa,WAAW,IAAI;;AAG/D,SAAgB,wBACd,QACA,KACA,QACQ;CACR,MAAM,WAAW,gBACf,OAAO,gBACP,OAAO,UACP,IACD;AACD,KAAI,aAAa,OA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