@lunora/config 1.0.0-alpha.29 → 1.0.0-alpha.291

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.
Files changed (114) hide show
  1. package/LICENSE.md +135 -0
  2. package/README.md +3 -3
  3. package/dist/cloudflare/index.d.mts +1065 -0
  4. package/dist/cloudflare/index.d.ts +1065 -0
  5. package/dist/cloudflare/index.mjs +1 -0
  6. package/dist/index.d.mts +1024 -918
  7. package/dist/index.d.ts +1024 -918
  8. package/dist/index.mjs +1 -23
  9. package/dist/packem_shared/ACCENT-CotPTfv7.mjs +7 -0
  10. package/dist/packem_shared/AGENT_MODE_ENV-D8MvSwPE.mjs +1 -0
  11. package/dist/packem_shared/AGENT_RULES_DIR-C54Ta_vz.mjs +1 -0
  12. package/dist/packem_shared/ALLOW_FORWARDED_ENV-BUndghJx.mjs +1 -0
  13. package/dist/packem_shared/BINDING_MANIFEST_VERSION-vItUTnHk.mjs +1 -0
  14. package/dist/packem_shared/CLOUDFLARE_DRIVER-Ci3VIqnk.mjs +1 -0
  15. package/dist/packem_shared/CODEGEN_ENV-ZsCxV1kP.mjs +1 -0
  16. package/dist/packem_shared/COMPOSED_WORKER_ENTRY-C69wqbSP.mjs +1 -0
  17. package/dist/packem_shared/DEFAULT_DEPLOY_TARGET-CfoV0tDu.mjs +1 -0
  18. package/dist/packem_shared/DEV_BINDINGS_FILE-pyOiNLP4.mjs +4 -0
  19. package/dist/packem_shared/DEV_VARS_EXAMPLE_FILE-CqLorAxT.mjs +6 -0
  20. package/dist/packem_shared/DEV_WORKER_ENV_VALUE-DwGANZVw.mjs +1 -0
  21. package/dist/packem_shared/LINKED_PROJECT_DIR-Ba5qPEwo.mjs +2 -0
  22. package/dist/packem_shared/LUNORA_EVENT_SOURCE-DYdcDU9G.mjs +1 -0
  23. package/dist/packem_shared/LUNORA_IGNORED_PATHS-B0-PPvRp.mjs +19 -0
  24. package/dist/packem_shared/LUNORA_TAG-CiQM3BkI.mjs +1 -0
  25. package/dist/packem_shared/LunoraReporter-f277GLNT.mjs +6 -0
  26. package/dist/packem_shared/PACKAGE_SECRETS_REGISTRY-De7gLGIy.mjs +1 -0
  27. package/dist/packem_shared/POLICY_SCAFFOLD_ENDPOINT-0QiGKazX.mjs +1 -0
  28. package/dist/packem_shared/REMOTE_ELIGIBLE_KEYS-ikHvqvS5.mjs +1 -0
  29. package/dist/packem_shared/REQUIRED_COMPATIBILITY_DATE-jTnj2MPJ.mjs +1 -0
  30. package/dist/packem_shared/SCHEMA_EDIT_ENDPOINT-Dbt0faMd.mjs +1 -0
  31. package/dist/packem_shared/SEED_ENDPOINT-2B56PN_H.mjs +1 -0
  32. package/dist/packem_shared/STUDIO_PATH-BZI8go9A.mjs +1 -0
  33. package/dist/packem_shared/UNEXPORTED_CLASS_MARKER-CugcZbPf.mjs +1 -0
  34. package/dist/packem_shared/WORKERS_CACHE_MIN_DATE-0k9ABJtF.mjs +1 -0
  35. package/dist/packem_shared/WRANGLER_FILES-UNW-xY5u.mjs +1 -0
  36. package/dist/packem_shared/acceptsConnection-DHhUYGjT.mjs +2 -0
  37. package/dist/packem_shared/addArgsFor-CYZKhNIo.mjs +1 -0
  38. package/dist/packem_shared/applyAdditiveEdit-CH0VhMJ2.mjs +6 -0
  39. package/dist/packem_shared/applyModify-DKP2l6S9.mjs +1 -0
  40. package/dist/packem_shared/applyStudioAssetCache-DHQEJuuv.mjs +1 -0
  41. package/dist/packem_shared/assertWranglerSatisfiesSchema-BiABHeMv.mjs +3 -0
  42. package/dist/packem_shared/assetContentType-CUb5bpbI.mjs +1 -0
  43. package/dist/packem_shared/buildPackageSecretsBlock-yv9mjKEW.mjs +19 -0
  44. package/dist/packem_shared/celld-config-D-L6uskI.mjs +3 -0
  45. package/dist/packem_shared/classifyPolicyEdit-D8NwrHxR.mjs +24 -0
  46. package/dist/packem_shared/collectExportGaps-CIYe_DRY.mjs +2 -0
  47. package/dist/packem_shared/collectWranglerSecretVariables-D-usPfT8.mjs +1 -0
  48. package/dist/packem_shared/createConfirm-D5mKTMHj.mjs +7 -0
  49. package/dist/packem_shared/describePreservedCrons-7gaDLxWx.mjs +1 -0
  50. package/dist/packem_shared/detectFramework-CUiVEHDQ.mjs +1 -0
  51. package/dist/packem_shared/discover-info-Vj9d4qYt.mjs +1 -0
  52. package/dist/packem_shared/discoverAgentInfo-CTdCSfYM.mjs +1 -0
  53. package/dist/packem_shared/discoverContainerInfo-EhZtEBQs.mjs +1 -0
  54. package/dist/packem_shared/discoverSchemaInfo-DJvevsCm.mjs +1 -0
  55. package/dist/packem_shared/discoverWorkflowInfo-BsPvlo6O.mjs +1 -0
  56. package/dist/packem_shared/inferLunoraBindings-DXLEJY9w.mjs +1 -0
  57. package/dist/packem_shared/interpretRemote-C9yJC_ZK.mjs +1 -0
  58. package/dist/packem_shared/lunora-manifest-v90ZUbVp.mjs +6 -0
  59. package/dist/packem_shared/mergeWranglerEnvironment-DOKJUNH8.mjs +1 -0
  60. package/dist/packem_shared/package-secrets-registry-DvtTiK4b.mjs +1 -0
  61. package/dist/packem_shared/parseDevVariable-teAAahVD.mjs +1 -0
  62. package/dist/packem_shared/parseSchema-D1Wbr1qv.mjs +1 -0
  63. package/dist/packem_shared/policy-scaffold.d-D2H4_G01.d.mts +86 -0
  64. package/dist/packem_shared/policy-scaffold.d-D2H4_G01.d.ts +86 -0
  65. package/dist/packem_shared/reconcile-services-3dn35zgy.mjs +1 -0
  66. package/dist/packem_shared/reconcileBindingsSafely-VBbLYoAx.mjs +1 -0
  67. package/dist/packem_shared/reconcileWranglerCompatibilityDate-hocXEuRA.mjs +1 -0
  68. package/dist/packem_shared/renderStudioHtml-ByowDtMl.mjs +15 -0
  69. package/dist/packem_shared/runPostCodegenHook-B0T1q2YI.mjs +1 -0
  70. package/dist/packem_shared/schema-info.d-fEhxTb9k.d.mts +397 -0
  71. package/dist/packem_shared/schema-info.d-fEhxTb9k.d.ts +397 -0
  72. package/dist/packem_shared/serveJsonHandler-Dv0EdCb9.mjs +1 -0
  73. package/dist/packem_shared/startCelldDevSession-BLFsd6jG.mjs +1 -0
  74. package/dist/packem_shared/streamContainerLogs-0nko1qpv.mjs +2 -0
  75. package/dist/packem_shared/validate-bindings-Dnf1t0SY.mjs +1 -0
  76. package/dist/packem_shared/withTailConsumer-B1NoKIsj.mjs +1 -0
  77. package/dist/packem_shared/wranglerToAlchemy-BMOQYRyw.mjs +6 -0
  78. package/dist/packem_shared/write-atomic-9d9xs5ON.mjs +1 -0
  79. package/dist/studio-host/index.d.mts +314 -110
  80. package/dist/studio-host/index.d.ts +314 -110
  81. package/dist/studio-host/index.mjs +1 -7
  82. package/package.json +15 -7
  83. package/dist/packem_shared/ACCENT-DW1XJn8i.mjs +0 -40
  84. package/dist/packem_shared/AGENT_RULES_DIR-lcgC08aE.mjs +0 -40
  85. package/dist/packem_shared/DEV_VARS_EXAMPLE_FILE-dJPNTEnK.mjs +0 -37
  86. package/dist/packem_shared/LINKED_PROJECT_DIR-CXwXzV_C.mjs +0 -52
  87. package/dist/packem_shared/LUNORA_CONFIG_FILE-CtcIcB5-.mjs +0 -34
  88. package/dist/packem_shared/LUNORA_EVENT_SOURCE-D2fDeGB6.mjs +0 -86
  89. package/dist/packem_shared/LunoraReporter-Ci-bDCK9.mjs +0 -70
  90. package/dist/packem_shared/PACKAGE_SECRETS_REGISTRY-B8t_SdoZ.mjs +0 -70
  91. package/dist/packem_shared/POLICY_SCAFFOLD_ENDPOINT-CiC2IGKx.mjs +0 -103
  92. package/dist/packem_shared/REMOTE_ELIGIBLE_KEYS-BC7_e9Bz.mjs +0 -105
  93. package/dist/packem_shared/REQUIRED_COMPATIBILITY_DATE-2YYyWJUq.mjs +0 -561
  94. package/dist/packem_shared/SCHEMA_EDIT_ENDPOINT-Df-Wrix-.mjs +0 -99
  95. package/dist/packem_shared/SEED_ENDPOINT-DVCjaGO-.mjs +0 -61
  96. package/dist/packem_shared/WRANGLER_FILES-DwSuC-Kn.mjs +0 -25
  97. package/dist/packem_shared/applyAdditiveEdit-C-snTFEV.mjs +0 -228
  98. package/dist/packem_shared/buildPackageSecretsBlock-DWDKHViT.mjs +0 -243
  99. package/dist/packem_shared/classifyPolicyEdit-BHeAqF8P.mjs +0 -99
  100. package/dist/packem_shared/createConfirm-fvpdgJ9s.mjs +0 -100
  101. package/dist/packem_shared/detectFramework-Br-BcPBq.mjs +0 -41
  102. package/dist/packem_shared/discoverContainerInfo-BXFs6Wav.mjs +0 -19
  103. package/dist/packem_shared/discoverSchemaInfo-BB-CKlTK.mjs +0 -25
  104. package/dist/packem_shared/discoverWorkflowInfo-CedvR0mn.mjs +0 -19
  105. package/dist/packem_shared/inferLunoraBindings-ByMwG-gH.mjs +0 -352
  106. package/dist/packem_shared/loadStudioAssets-Csk5RS4E.mjs +0 -28
  107. package/dist/packem_shared/parseDevVariable-CJiq2IwE.mjs +0 -30
  108. package/dist/packem_shared/parseSchema-DSeyktvG.mjs +0 -107
  109. package/dist/packem_shared/policy-scaffold.d-DCmwn7zQ.d.mts +0 -74
  110. package/dist/packem_shared/policy-scaffold.d-DCmwn7zQ.d.ts +0 -74
  111. package/dist/packem_shared/reconcileWranglerBindings-Cruwwx1M.mjs +0 -334
  112. package/dist/packem_shared/renderStudioHtml-449Ysn75.mjs +0 -37
  113. package/dist/packem_shared/serveJsonHandler-B4OLTGLS.mjs +0 -86
  114. package/dist/packem_shared/streamContainerLogs-BZ4cOZwH.mjs +0 -157
@@ -0,0 +1,397 @@
1
+ import { AgentIR, ContainerIR, QueueIR, ServiceBindingIR, WorkflowIR } from '@lunora/codegen';
2
+ /**
3
+ * `DeployDriver` — the provider-neutral seam between a Lunora command and the
4
+ * host CLI that carries it out (plan 114, §5.3).
5
+ *
6
+ * The seam is the **toolchain surface**: which command a host runs to deploy,
7
+ * serve, tail, or set a secret. A driver only *describes* that command
8
+ * ({@link ToolchainCommand}); it never spawns. The CLI keeps ownership of
9
+ * running it — package-manager resolution (`pnpm exec` / `npx --` / `bun x`)
10
+ * and the injected spawner its tests substitute — so the driver stays free of
11
+ * process concerns and remains trivially testable as a pure function.
12
+ *
13
+ * Each request type below is deliberately neutral: `preview`, `environment`,
14
+ * `temporary` are concepts, not wrangler flags. A second host maps the same
15
+ * request onto its own CLI without the caller changing.
16
+ *
17
+ * Three drivers are registered: Cloudflare (`cloudflare/cloudflare-driver.ts`)
18
+ * and celld (`celld/celld-driver.ts`), which ship toolchains, and Node
19
+ * (`node/node-driver.ts`), which has none — it is a codegen target, and
20
+ * `lunora deploy` / `lunora dev` refuse it at selection.
21
+ *
22
+ * **What this seam deliberately does NOT carry: configuration inference.** It
23
+ * used to, through an `infer`/`provision` pair over a provider-neutral
24
+ * `ResourceGraph`. Nothing ever called either one — every consumer reads
25
+ * `.toolchain` or just validates the target — and the arm rotted in place: the
26
+ * Node driver was *only* `infer` + `provision`, so its report of what that
27
+ * target cannot serve (containers, undispatched crons) could not reach an
28
+ * operator however wrong the app was. The reason it never got wired is worth
29
+ * keeping: writing real host configuration needs the host's own encodings —
30
+ * binding names, DO class wiring, migration tags — which a neutral graph
31
+ * necessarily discards, so `provision` re-derived them anyway and the graph was
32
+ * decorative. A second target that needs to share inference should grow the
33
+ * seam back with a caller attached, and with an encoding escape hatch.
34
+ */
35
+ /**
36
+ * A host CLI invocation, described but not run.
37
+ *
38
+ * `tool` is the binary name only (`"wrangler"`); the caller resolves how to
39
+ * execute it through the project's package manager (see `toolchainExecArgs`).
40
+ * Keeping that split means a driver never has to know whether the project uses
41
+ * pnpm, npm, yarn, or bun.
42
+ */
43
+ interface ToolchainCommand {
44
+ /** Arguments for {@link ToolchainCommand.tool}. */
45
+ args: ReadonlyArray<string>;
46
+ /**
47
+ * The tool is a standalone binary installed on `PATH`, not a project
48
+ * dependency: run it directly. Going through the package manager would be
49
+ * wrong for it — `npx --` / `bun x` fetch an npm package of the same name
50
+ * when none is installed locally, which for a non-npm binary is somebody
51
+ * else's code.
52
+ */
53
+ onPath?: boolean;
54
+ /** The host CLI binary, e.g. `"wrangler"`. */
55
+ tool: string;
56
+ }
57
+ /** Neutral options for a deploy. */
58
+ interface DeployRequest {
59
+ /** Host config file to deploy, when the flow uses a projected one (see {@link DeployDriver.projectConfig}). */
60
+ configPath?: string;
61
+ /** Validate and bundle without publishing — nothing ships. */
62
+ dryRun?: boolean;
63
+ /** Deploy this entry file instead of the host config's default (framework composition). */
64
+ entry?: string;
65
+ /** Named deployment environment, when the host supports them. */
66
+ environment?: string;
67
+ /** Write the built bundle (and any build metadata) to this directory. */
68
+ outDir?: string;
69
+ /** Upload a preview/versioned artifact instead of taking production traffic. */
70
+ preview?: boolean;
71
+ /** Deploy to a short-lived, unauthenticated account where the host offers one. */
72
+ temporary?: boolean;
73
+ }
74
+ /** Neutral options for a local dev server. */
75
+ interface DevRequest {
76
+ /** Host config file to run against, when the flow uses a generated one. */
77
+ configPath?: string;
78
+ /** Named environment. */
79
+ environment?: string;
80
+ /** Extra host-specific flags the caller has already resolved. */
81
+ extraArgs?: ReadonlyArray<string>;
82
+ }
83
+ /** Neutral options for tailing live logs. */
84
+ interface TailRequest {
85
+ /** Named environment. */
86
+ environment?: string;
87
+ /** Output format the host tail supports (`"json"`, `"pretty"`, …). */
88
+ format?: string;
89
+ /** Free-text filter. */
90
+ search?: string;
91
+ /** Status filter (`"error"`, `"ok"`, …). */
92
+ status?: string;
93
+ /** Tail a short-lived account's deployment. */
94
+ temporary?: boolean;
95
+ /** Tail a specific deployed worker/service by name, when the host addresses them individually. */
96
+ worker?: string;
97
+ }
98
+ /** Neutral options for reading or writing deployment secrets. */
99
+ interface SecretRequest {
100
+ /** Named environment. */
101
+ environment?: string;
102
+ /** The secret's name — required for `put`, unused for `list`. */
103
+ key?: string;
104
+ /** Operate against a short-lived account. */
105
+ temporary?: boolean;
106
+ }
107
+ /**
108
+ * The host's command-line surface. Optional as a whole: a host with no vendor
109
+ * CLI (the Node target; a hypothetical API-driven one) declares none, and
110
+ * `isRunnableTarget` refuses it for the commands that would have to shell out.
111
+ *
112
+ * `deploy` and `dev` are what make a target runnable. The secret and tail
113
+ * commands are optional on their own, because a runnable host can simply not
114
+ * have them — celld keeps configuration in plain `vars` and has no log tail —
115
+ * and the commands that need one say so rather than guessing a substitute.
116
+ */
117
+ interface DriverToolchain {
118
+ /** The command that deploys the app. */
119
+ deploy: (request: DeployRequest) => ToolchainCommand;
120
+ /** The command that runs a local dev server. */
121
+ dev: (request: DevRequest) => ToolchainCommand;
122
+ /**
123
+ * Where `lunora dev` runs the worker. `"workerd"`: `wrangler dev`, or the
124
+ * Vite plugin's `@cloudflare/vite-plugin`, whichever flavor the project
125
+ * picks. `"own"`: the host's dev server ({@link DriverToolchain.dev}) on
126
+ * the projected config, always the standalone flavor — neither Vite nor a
127
+ * framework sidecar can serve the worker on that runtime.
128
+ */
129
+ readonly devServer: "own" | "workerd";
130
+ /**
131
+ * Whether `lunora deploy` builds and pushes container images itself
132
+ * (railpack, into the host's registry) before `deploy`. `false` when the
133
+ * host CLI builds each image from its Dockerfile during the deploy.
134
+ */
135
+ readonly prebuildsContainerImages: boolean;
136
+ /** The command that lists remote secret names, when the host has a secret store. */
137
+ secretList?: (request: SecretRequest) => ToolchainCommand;
138
+ /** The command that writes one secret, when the host has a secret store. Its value is passed on stdin, never argv. */
139
+ secretPut?: (request: SecretRequest) => ToolchainCommand;
140
+ /** The command that tails live logs, when the host has one. */
141
+ tail?: (request: TailRequest) => ToolchainCommand;
142
+ }
143
+ /** What a {@link DeployDriver.projectConfig} projection is for — a dev server may need a different source than a deploy. */
144
+ type ProjectionPurpose = "deploy" | "dev";
145
+ /**
146
+ * The result of {@link DeployDriver.projectConfig}: a plan, not yet on disk.
147
+ * The caller validates the request it is for (the toolchain's argv builder
148
+ * refuses unsupported options), then calls `write` — so a refused command
149
+ * changes nothing.
150
+ */
151
+ interface ProjectedConfig {
152
+ /** Where the projection goes, to pass as the request's `configPath`. */
153
+ configPath: string;
154
+ /** Every key removed, as a dotted path (`observability`, `containers[0].rollout_step_percentage`). */
155
+ dropped: ReadonlyArray<string>;
156
+ /** Write the projection (and any build-artifact cleanup it planned). */
157
+ write: () => void;
158
+ }
159
+ /** A deploy target's implementation: an identity the registry resolves, and the host CLI surface (if any) behind it. */
160
+ interface DeployDriver {
161
+ /** The target id this driver serves (`"cloudflare"`, …) — matches codegen's `target`. */
162
+ readonly id: string;
163
+ /** Human-readable target name, for logs. */
164
+ readonly name: string;
165
+ /**
166
+ * Rewrite the project's wrangler config into the form this host's CLI
167
+ * accepts, and return the file to hand `deploy`/`dev` as `configPath`.
168
+ * Absent when the host reads the project's config as-is (Cloudflare).
169
+ *
170
+ * Needed because Lunora's reconcilers and templates write Cloudflare-only
171
+ * keys (`observability`, `limits`, …) that a Workers-compatible host with a
172
+ * strict config reader refuses outright. `dropped` names what was removed,
173
+ * so the caller can say so instead of silently deploying less than the
174
+ * config describes.
175
+ */
176
+ readonly projectConfig?: (projectRoot: string, purpose: ProjectionPurpose) => ProjectedConfig;
177
+ /**
178
+ * The host's command-line surface, or `undefined` for a host that has none.
179
+ * Pure: these build argv, they never spawn.
180
+ */
181
+ readonly toolchain?: DriverToolchain;
182
+ }
183
+ interface DurableObjectSpec {
184
+ binding: string;
185
+ className: string;
186
+ }
187
+ /**
188
+ * The `_generated/` modules that hold a generated Durable Object / Workflow
189
+ * class — one per class kind a project can declare. wrangler validates every
190
+ * `class_name` against the worker's exports, so this is the set a worker entry
191
+ * re-exports (and the set the composed class-A entry star-re-exports for the
192
+ * kinds the project has).
193
+ *
194
+ * Owned here because four places need it and they must not drift:
195
+ * `@lunora/vite` emits one star re-export per entry, the wrangler validator
196
+ * DECIDES the composed entry's exports from it, `reconcile-bindings` types its
197
+ * export-gap `module` field on it, and this module's own `detectClassExports`
198
+ * probes the same names.
199
+ *
200
+ * `scheduler` carries no `define*` declarations of its own — codegen writes it
201
+ * off `hasScheduler` purely so the composed class-A entry has a `SchedulerDO`
202
+ * to forward. Its presence is therefore the ONLY signal the plugin and the
203
+ * validator need, and it is the same signal that decides whether the builder
204
+ * has a `.scheduler()` method at all. `@lunora/vite` depends on `@lunora/config`, so config
205
+ * owning it is the direction the dependency graph allows.
206
+ */
207
+ declare const GENERATED_CLASS_MODULES: readonly ["agents", "containers", "scheduler", "shardRegistry", "workflows"];
208
+ /** One {@link GENERATED_CLASS_MODULES} entry. */
209
+ type GeneratedClassModule = (typeof GENERATED_CLASS_MODULES)[number];
210
+ /**
211
+ * The class-B composed entry. `lunora deploy` passes this file to wrangler as
212
+ * the positional script whenever it exists, overriding `wrangler.main` — so it
213
+ * is what actually gets bundled and what wrangler checks its DO/Workflow
214
+ * bindings against. `main` in a class-B project names the framework adapter's
215
+ * build output (`.svelte-kit/cloudflare/_worker.js`, `dist/_worker.js`), which
216
+ * exists after `vite build` and exports only the SSR fetch handler. Lexing that
217
+ * instead read every declared class as unexported: nothing provisioned, plus a
218
+ * "add `export * from …`" warning the user cannot silence.
219
+ *
220
+ * Exported, not documented-as-duplicated: the CLI's `resolveComposedWorkerEntry`
221
+ * imports this constant, so the deploy's positional entry and the file this
222
+ * module lexes for exported classes cannot drift apart.
223
+ */
224
+ declare const COMPOSED_WORKER_ENTRY = "src/worker.ts";
225
+ /**
226
+ * A `defineContainer` declaration plus whether its generated DO class is
227
+ * exported by the worker entry. Only exported containers are safe to
228
+ * provision — wrangler rejects a `containers[].class_name` (and its Durable
229
+ * Object binding) that the worker doesn't export.
230
+ */
231
+ type InferredContainer = ContainerIR & {
232
+ exported: boolean;
233
+ };
234
+ /**
235
+ * A `defineWorkflow` declaration plus whether its generated
236
+ * `WorkflowEntrypoint` class is exported by the worker entry. Only exported
237
+ * workflows are safe to provision — wrangler rejects an `exports.<Class>`
238
+ * workflow the worker doesn't export. Workflows are NOT Durable Objects, so this never
239
+ * implies a `durable_objects` binding or migration.
240
+ */
241
+ interface InferredWorkflow extends WorkflowIR {
242
+ exported: boolean;
243
+ }
244
+ /**
245
+ * A `defineAgent` declaration plus whether its generated agent
246
+ * `WorkflowEntrypoint` class (e.g. `SupportAgentWorkflow`) is exported by the
247
+ * worker entry. An agent compiles onto a Cloudflare Workflow, so — exactly like
248
+ * {@link InferredWorkflow} — only exported agents are safe to provision
249
+ * (wrangler rejects an `exports.<Class>` workflow the worker doesn't export), and
250
+ * an agent is NOT a Durable Object (no `durable_objects` binding or migration).
251
+ */
252
+ interface InferredAgent extends AgentIR {
253
+ exported: boolean;
254
+ }
255
+ /**
256
+ * A queue declared in `lunora/queues.ts`. Unlike workflows, a queue needs no
257
+ * worker-entry class export (its `queue()` handler rides `createWorker`), so
258
+ * there is no `exported` flag — every declared queue is reconcilable into the
259
+ * wrangler `queues.producers[]` / `queues.consumers[]`.
260
+ */
261
+ type InferredQueue = QueueIR;
262
+ interface InferredBindings {
263
+ /** Agents declared in `lunora/agents.ts` (exported or not — see {@link InferredAgent.exported}); reconciled into wrangler `exports`. */
264
+ agents: InferredAgent[];
265
+ /** Containers declared in `lunora/containers.ts` (exported or not — see {@link InferredContainer.exported}). */
266
+ containers: InferredContainer[];
267
+ /** Durable Objects the worker entry exports → safe to bind. */
268
+ durableObjects: DurableObjectSpec[];
269
+ /**
270
+ * The wrangler `flagship[].binding` name implied by `lunora/flags.ts` when it
271
+ * uses the Flagship provider in binding mode — `undefined` for HTTP-mode
272
+ * Flagship, a custom OpenFeature provider, or no flags. The binding needs an
273
+ * un-mintable `app_id`, so it is reconciled as a hint, not auto-written.
274
+ */
275
+ flagshipBinding?: string;
276
+ /** Schema declares a `.global()` table → needs the `DB` D1 binding. */
277
+ needsD1: boolean;
278
+ /** Queues declared in `lunora/queues.ts` → reconciled into `queues.producers[]` / `queues.consumers[]`. */
279
+ queues: InferredQueue[];
280
+ /**
281
+ * Sibling Workers declared in `lunora.config` `services` → reconciled into
282
+ * `services[]` (plan 457). `undefined` when the declaration is unreadable, so
283
+ * reconcile leaves every entry alone rather than removing the owned ones.
284
+ */
285
+ services: ServiceBindingIR[] | undefined;
286
+ /** Human-readable provenance for each inferred binding / hint, for logging. */
287
+ signals: string[];
288
+ /** `@lunora/ai` is imported or `env.AI` is used → needs the `ai` Workers AI binding. */
289
+ usesAi: boolean;
290
+ /** `@lunora/bindings/analytics` is imported → self-describing `analytics_engine_datasets` binding (auto-writeable). */
291
+ usesAnalytics: boolean;
292
+ /** `@lunora/auth` is imported (sessions may be D1- or `SessionDO`-backed). */
293
+ usesAuth: boolean;
294
+ /** `@lunora/browser` is imported → self-describing `browser` binding (auto-writeable). */
295
+ usesBrowser: boolean;
296
+ /** `lunora/flags.ts` declares a feature-flag provider (any OpenFeature provider — Flagship or custom). */
297
+ usesFlags: boolean;
298
+ /** `@lunora/hyperdrive` is imported (binding needs an un-mintable remote `id`; hint-only). */
299
+ usesHyperdrive: boolean;
300
+ /** `@lunora/bindings/images` is imported → self-describing `images` binding (auto-writeable). */
301
+ usesImages: boolean;
302
+ /** `@lunora/bindings/kv` is imported (namespace binding name + id are user-defined; hint-only). */
303
+ usesKv: boolean;
304
+ /** `@lunora/mail` is imported (Resend API key must be set in `.dev.vars`; no binding). */
305
+ usesMail: boolean;
306
+ /** `@lunora/notify` is imported (Web Push needs VAPID/FCM secrets in `.dev.vars`; no binding). */
307
+ usesNotify: boolean;
308
+ /** `@lunora/payment` is imported (provider secrets must be set in `.dev.vars`; no binding). */
309
+ usesPayment: boolean;
310
+ /** `ctx.pipelines` is used (binding needs an un-mintable remote pipeline name; hint-only). */
311
+ usesPipelines: boolean;
312
+ /** `ctx.r2sql` is used (needs the `R2_SQL_*` secrets in `.dev.vars`; no binding). */
313
+ usesR2sql: boolean;
314
+ /** `@lunora/scheduler` is imported. */
315
+ usesScheduler: boolean;
316
+ /** `@lunora/storage` is imported (R2 bucket binding name is user-defined). */
317
+ usesStorage: boolean;
318
+ /** `jsCodeTool` is imported from `@lunora/agent` in `lunora/` → self-describing `worker_loaders` binding (`LOADER`). */
319
+ usesWorkerLoader: boolean;
320
+ /** `@lunora/x402/charge` is imported — the charge rail settles USDC to a recipient address (a public `[vars]` entry, user-named; hint-only). */
321
+ usesX402Charge: boolean;
322
+ /** `@lunora/x402/pay` is imported — the agent-wallet pay rail signs from a Secrets Store binding paired with a spend policy (ActionCtx-only; hint-only). */
323
+ usesX402Pay: boolean;
324
+ /** Workflows declared in `lunora/workflows.ts` (exported or not — see {@link InferredWorkflow.exported}). */
325
+ workflows: InferredWorkflow[];
326
+ }
327
+ interface InferOptions {
328
+ projectRoot: string;
329
+ /** Directories (relative to root) to scan. Defaults to `lunora` + `src`. */
330
+ scanDirs?: ReadonlyArray<string>;
331
+ /** Lunora source directory holding `schema.ts`. Defaults to `lunora`. */
332
+ schemaDir?: string;
333
+ }
334
+ /**
335
+ * Scan a Lunora project and report which Cloudflare bindings its code implies.
336
+ * Read-only: performs no writes. Binding provisioning is driven by the worker
337
+ * entry's Durable Object exports plus the schema's D1 need; capability imports
338
+ * surface as hints.
339
+ */
340
+ declare const inferLunoraBindings: (options: InferOptions) => Promise<InferredBindings>;
341
+ /**
342
+ * Derive the list of `@lunora/*` package names that are actively used by a
343
+ * project, based on its already-resolved {@link InferredBindings}.
344
+ *
345
+ * This is the canonical bridge between binding inference and the package-aware
346
+ * `.dev.vars.example` scaffolding in `scaffold-dev-variables.ts`. The result is
347
+ * a stable, predictable slice of {@link CAPABILITY_SOURCES} source values,
348
+ * filtered to the flags that are `true` in `bindings` — in CAPABILITY_SOURCES
349
+ * declaration order.
350
+ */
351
+ declare const packageNamesFromBindings: (bindings: InferredBindings) => string[];
352
+ /** One filterable Vectorize metadata property a schema declares. */
353
+ interface VectorMetadataDeclaration {
354
+ /** The vector index the property belongs to. */
355
+ index: string;
356
+ /**
357
+ * The validator kind behind the column, or `undefined` when the column
358
+ * isn't in the owning table's shape. Callers map it to the Vectorize
359
+ * metadata type; a kind that can't be filtered on is reported, not indexed.
360
+ */
361
+ kind: string | undefined;
362
+ /** Column mirrored into vector metadata. */
363
+ property: string;
364
+ }
365
+ interface SchemaInfo {
366
+ /**
367
+ * Whether the schema declares a **D1-backed** `.global()` table — the only
368
+ * flavour that needs the `DB` binding and the app's `.global({ d1 })` chain.
369
+ * A `.global({ backend: "hyperdrive" })` table needs neither, and counting it
370
+ * here demanded a D1 database of a project that has none.
371
+ */
372
+ hasD1GlobalTable: boolean;
373
+ /** Whether the schema declares a `.global({ backend: "hyperdrive" })` table — needs the app's `.hyperdriveGlobal(...)` chain instead. Required, not optional: the only producer always knows the answer, and `?` made every consumer read a two-valued fact as three-valued. */
374
+ hasHyperdriveGlobalTable: boolean;
375
+ /** Names of vector indexes declared via `.vectorize()` / `defineVectorIndex()`. */
376
+ vectorIndexNames?: ReadonlyArray<string>;
377
+ /**
378
+ * Metadata properties declared filterable on a vector index. Cloudflare
379
+ * needs an explicit metadata index per property before a `filter` can match
380
+ * anything, so deploy provisions these and doctor reports them.
381
+ */
382
+ vectorMetadata?: ReadonlyArray<VectorMetadataDeclaration>;
383
+ }
384
+ interface DiscoverSchemaInfoResult {
385
+ /** Parse error message, when the schema exists but could not be analyzed. */
386
+ error?: string;
387
+ /** Schema facts, or `undefined` when no `schema.ts` exists or parsing failed. */
388
+ info: SchemaInfo | undefined;
389
+ }
390
+ /**
391
+ * Discover {@link SchemaInfo} for a project. Returns `{ info: undefined }` when
392
+ * the project declares no `schema.ts` (not an error), or `{ info: undefined,
393
+ * error }` when a present schema could not be parsed — callers decide whether a
394
+ * parse failure is a warning (validator) or simply ignorable (inference).
395
+ */
396
+ declare const discoverSchemaInfo: (projectRoot: string, schemaDirectory: string) => DiscoverSchemaInfoResult;
397
+ export { COMPOSED_WORKER_ENTRY as C, DeployDriver as D, GeneratedClassModule as G, InferredBindings as I, ProjectionPurpose as P, SchemaInfo as S, ToolchainCommand as T, DeployRequest as a, DevRequest as b, DiscoverSchemaInfoResult as c, DriverToolchain as d, GENERATED_CLASS_MODULES as e, InferOptions as f, InferredAgent as g, InferredContainer as h, InferredWorkflow as i, ProjectedConfig as j, SecretRequest as k, TailRequest as l, discoverSchemaInfo as m, inferLunoraBindings as n, packageNamesFromBindings as p };
@@ -0,0 +1 @@
1
+ import{headerValue as a}from"./ALLOW_FORWARDED_ENV-BUndghJx.mjs";const l=1e6,g=async t=>await new Promise((o,e)=>{const n=[];let i=0;t.on("data",c=>{if(i+=c.length,i>l){e(new Error("request body too large"));return}n.push(c)}),t.on("end",()=>{o(Buffer.concat(n).toString("utf8"))}),t.on("error",e)}),s=(t,o,e)=>{t.statusCode=o,t.setHeader("Content-Type","application/json; charset=utf-8"),t.end(JSON.stringify(e))},u=new Set(["none","same-origin","same-site"]),y=t=>{const o=a(t.headers["sec-fetch-site"]);if(o!==void 0)return u.has(o)?void 0:"cross-origin request rejected";const e=a(t.headers.origin);if(e===void 0||e==="null")return;let n;try{n=new URL(e).host.toLowerCase()}catch{return"invalid origin header"}return n===a(t.headers.host)?void 0:"cross-origin request rejected"},p=t=>{const o=(t.method??"GET").toUpperCase(),e=o!=="GET"&&o!=="HEAD",n=y(t);if(n!==void 0)return n;if(e&&!a(t.headers["content-type"])?.startsWith("application/json"))return"content-type must be application/json"},v=(t,o,e,n,i={})=>{(async()=>{try{const r=p(t);if(r!==void 0){s(o,403,{error:r,ok:!1});return}const d=t.method==="GET"?"":await g(t);let h;try{h=d===""?void 0:JSON.parse(d)}catch{s(o,400,{error:"invalid-json",ok:!1});return}const f=e({...i,body:h,method:t.method??"POST",projectRoot:n});s(o,f.status,f.body)}catch(r){s(o,500,{error:r instanceof Error?r.message:String(r),ok:!1})}})().catch(()=>{})};export{v as serveJsonHandler};
@@ -0,0 +1 @@
1
+ import{watch as A}from"node:fs";import{createServer as _}from"node:net";import{dirname as C}from"node:path";import{readServiceBindings as R}from"@lunora/codegen";import{acceptsConnection as b,startDevProcess as M}from"./acceptsConnection-DHhUYGjT.mjs";import{p as D,a as x}from"./celld-config-D-L6uskI.mjs";const N=6e4,O=200,j=new Set([".celld",".wrangler","node_modules"]),I=/[/\\]/u,B=async()=>new Promise((r,a)=>{const s=_();s.once("error",a),s.listen(0,"127.0.0.1",()=>{const o=s.address();s.close(()=>{r(typeof o=="object"&&o!==null?o.port:0)})})}),F=r=>r?.split(I).some(a=>j.has(a))===!0,G=(r,a,s)=>{let o;const c=A(r,{recursive:!0},(l,w)=>{F(w)||(clearTimeout(o),o=setTimeout(a,O))}),i=()=>{clearTimeout(o),c.close()};return c.once("error",l=>{i(),s(l)}),{close:i}},H=r=>r instanceof Error?r.message:String(r),J=async r=>{const{log:a,port:s,projectRoot:o}=r,c=(t,e="stdout")=>{a(t,{stream:e,tag:"celld"})};if(await b(s))throw new Error(`port ${String(s)} is already in use — stop whatever is serving there (another dev server?), or pick another worker port`);const i=R(o);if(i.error!==void 0)throw new Error(`could not read the lunora.config services: ${i.error}`);const l=D(o,"dev");l.write();const w=C(l.configPath),m=[...new Map(i.services.map(t=>[t.wranglerPath,t])).values()],p=new AbortController,h=()=>p.signal.aborted,v=async(t,e,n)=>M({args:["dev",t,"--port",String(n)],command:"celld",cwd:o,label:"celld dev",notFound:"`celld` was not found on PATH — install it (https://celld.dev) to run the celld target",onLine:T=>{T.trim()!==""&&a(T,{stream:"stdout",tag:e})},port:n,readyTimeoutMs:N,signal:p.signal,spawn:r.spawn}),S=async t=>{const e=x(w,t.wranglerPath);e.write(),c(`registering service ${t.worker} in the local dev state`),await(await v(e.configPath,`celld:${t.worker}`,await B())).stop()};for(const t of m)await S(t);let g=()=>{};const E=new Promise(t=>{g=t}),y=async()=>{const t=await v(l.configPath,"celld",s);return t.crashed.then(g).catch(()=>{}),t};let d=await y();const $=async t=>{await d.stop();let e;try{await S(t)}catch(n){e=n instanceof Error?n:new Error(String(n))}if(!h()){try{d=await y()}catch(n){throw h()||g(1),n}if(e!==void 0)throw e}};let f=Promise.resolve();const k=t=>{c(`service ${t.worker} changed — restarting`),f=f.then(async()=>$(t)).catch(e=>{h()||c(`service ${t.worker} failed to restart: ${H(e)}`,"stderr")})},P=[],u=()=>{for(const t of P)t.close()};try{for(const t of m)P.push(G(C(t.wranglerPath),()=>{k(t)},e=>{c(`stopped watching service ${t.worker}: ${e.message} — restart the dev server to pick up its edits`,"stderr")}))}catch(t){throw u(),await d.stop(),t}return E.then(u).catch(()=>{}),{exited:E,stop:async()=>{p.abort(),u(),await f,await d.stop()}}};export{J as startCelldDevSession};
@@ -0,0 +1,2 @@
1
+ import{Writable as D}from"node:stream";import{StringDecoder as N}from"node:string_decoder";const y="cloudflare-dev/",_=1500,b=async()=>{const{default:t}=await import("dockerode");return new t},C=t=>{if(!t.startsWith(y))return;const[a]=t.slice(y.length).split(":");return a!==void 0&&a.length>0?a:void 0},I=t=>{const a=new N("utf8");let c="";const o=r=>{t(r.endsWith("\r")?r.slice(0,-1):r)};return new D({final(r){c+=a.end(),c.length>0&&(o(c),c=""),r()},write(r,m,i){c+=a.write(r);const d=c.split(`
2
+ `);c=d.pop()??"";for(const v of d)o(v);i()}})},T=t=>{const a=new Map(t.containers.map(e=>[e.className.toLowerCase(),e.exportName]));if(a.size===0)return{close:()=>{}};const c=t.pollIntervalMs??_,o=new Map;let r=!1,m=!1,i,d;const v=async()=>(d??=t.docker?Promise.resolve(t.docker):b(),d),p=async(e,s,f)=>{try{const n=await e.getContainer(s).logs({follow:!0,stderr:!0,stdout:!0,tail:"all",timestamps:!1});if(r){n.destroy();return}const l=I(w=>{t.onLine({level:"info",name:f,text:w})}),u=I(w=>{t.onLine({level:"error",name:f,text:w})});e.modem.demuxStream(n,l,u),n.on("end",()=>{l.end(),u.end(),o.delete(s)}),n.on("error",()=>{o.delete(s)}),o.set(s,n)}catch{}},L=async()=>{try{const s=await(await v()).listContainers({filters:{status:["running"]}});return m=!1,s}catch(e){m||(m=!0,t.onUnavailable?.(e instanceof Error?e.message:String(e)));return}},k=async(e,s)=>{const f=new Set;for(const n of s){const l=C(n.Image),u=l===void 0?void 0:a.get(l);u!==void 0&&(f.add(n.Id),o.has(n.Id)||await p(e,n.Id,u))}for(const[n,l]of o)f.has(n)||(l.destroy(),o.delete(n))},E=async()=>{if(r)return;const e=await L();e!==void 0&&await k(await v(),e)};let g=!1;const h=()=>{g||r||(g=!0,E().finally(()=>{g=!1}).catch(()=>{}))};return i=setInterval(h,c),i.unref(),h(),{close:()=>{r=!0,i&&(clearInterval(i),i=void 0);for(const[e,s]of o)s.destroy(),o.delete(e)}}};export{T as streamContainerLogs};
@@ -0,0 +1 @@
1
+ const f=[{of:e=>e.schedules===void 0?void 0:[...e.schedules],path:["schedules"]},{of:e=>e.limits?.steps,path:["limits","steps"]},{of:e=>e.defaultRetention?.successRetention,path:["default_retention","success_retention"]},{of:e=>e.defaultRetention?.errorRetention,path:["default_retention","error_retention"]}],D=[...new Set(f.map(({path:e})=>e[0]))],u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),p=(e,n)=>{let i=e;for(const s of n)i=u(i)?i[s]:void 0;return i},O=e=>{const n={};for(const{of:i,path:s}of f){const a=i(e);if(a===void 0)continue;const[t,o]=s;n[t]=o===void 0?a:{...n[t],[o]:a}}return n},I=(e,n,i)=>{if(n.length===0)return;const s=e.vectorize??[],a=new Set(s.filter(Boolean).map(t=>t?.index_name));for(const t of n)a.has(t)||i.push(`schema declares vector index "${t}"; wrangler "vectorize" must include a binding with index_name "${t}"`)},v=new Set(["basic","dev","lite","standard","standard-1","standard-2","standard-3","standard-4"]),$={disk_mb:2e4,memory_mib:12288,vcpu:4},k=(e,n,i)=>{const s=e.instance_type;if(s===void 0)return;if(typeof s=="string"){v.has(s)||i.push(`${n} has unknown instance_type "${s}" — expected lite, basic, standard-1..4, or a custom { vcpu, memory_mib, disk_mb } object`);return}for(const[r,c]of Object.entries($)){const m=s[r];m!==void 0&&(typeof m!="number"||m<=0||m>c)&&i.push(`${n} custom instance_type ${r} must be a positive number ≤ ${String(c)} (got ${String(m)})`)}const{disk_mb:a,memory_mib:t,vcpu:o}=s;if(typeof o=="number"&&typeof t=="number"&&t<o*3072&&i.push(`${n} custom instance_type needs ≥ 3 GiB (3072 MiB) memory per vCPU (got ${String(t)} MiB for ${String(o)} vCPU)`),typeof t=="number"&&typeof a=="number"){const r=Math.floor(t/1024*2e3);a>r&&i.push(`${n} custom instance_type allows ≤ 2 GB disk per GiB memory (≤ ${String(r)} MB for ${String(t)} MiB memory; got ${String(a)} MB)`)}},w=(e,n,i)=>{for(const s of["image","instance_type","max_instances"])e[s]!==void 0&&i.push(`${n} sets "${s}", which the durable_object scheduling policy does not take — the Durable Object picks image and size at start`);for(const[s,a]of Object.entries(e.images??{}))[a?.dockerfile,a?.image].filter(o=>typeof o=="string"&&o.length>0).length!==1&&i.push(`${n} images["${s}"] must set exactly one of "dockerfile" or "image"`)},M=(e,n,i)=>{const{boundClasses:s,classKinds:a,errors:t,warnings:o}=i;if(!e||typeof e!="object"||typeof e.class_name!="string"||e.class_name.length===0){t.push(`${n} must have a non-empty "class_name" naming its container-enabled Durable Object class`);return}const r=e.scheduling_policy==="durable_object";e.scheduling_policy!==void 0&&e.scheduling_policy!=="default"&&!r&&t.push(`${n} ("${e.class_name}") has unknown scheduling_policy "${e.scheduling_policy}" — expected "default" or "durable_object"`),r?w(e,`${n} ("${e.class_name}")`,t):(typeof e.image!="string"||e.image.length===0)&&t.push(`${n} ("${e.class_name}") must have an "image" — a Dockerfile path or a registry reference`),s.has(e.class_name)||t.push(`${n} class "${e.class_name}" has no matching durable_objects binding — your dev server auto-reconciles this on startup; add { "name": "...", "class_name": "${e.class_name}" } to fix it by hand`);const c=a.get(e.class_name);c!=="sqlite"&&t.push(c==="classic"?`${n} class "${e.class_name}" is registered via "new_classes" but containers require SQLite-backed DOs — move it to "new_sqlite_classes"`:`${n} class "${e.class_name}" is missing from migrations — add a migration entry with "new_sqlite_classes": ["${e.class_name}"]`),k(e,`${n} ("${e.class_name}")`,t),e.max_instances===void 0&&!r&&o.push(`${n} ("${e.class_name}") declares no max_instances — set a cap so a traffic spike can't fan out unbounded container spend`)},d=e=>typeof e=="string"&&e.length>0,g=e=>Array.isArray(e)?e.filter(n=>n!==null&&typeof n=="object"):[],l=e=>Array.isArray(e)?e.filter(n=>d(n)):[],_=e=>{const n=new Map;for(const i of g(e)){for(const s of l(i.new_classes))n.set(s,"classic");for(const s of l(i.new_sqlite_classes))n.set(s,"sqlite");for(const s of g(i.renamed_classes))if(d(s.from)&&d(s.to)){const a=n.get(s.from)??"sqlite";n.delete(s.from),n.set(s.to,a)}for(const s of l(i.deleted_classes))n.delete(s)}return n},S=e=>new Set(_(e).keys()),N=(e,n)=>{const i=S(e.migrations);for(const s of g(e.durable_objects?.bindings))s.script_name===void 0&&d(s.class_name)&&!i.has(s.class_name)&&n.push(`durable_objects.bindings declares class "${s.class_name}" but it is missing from migrations — add a migration entry with "new_sqlite_classes": ["${s.class_name}"] (or "new_classes" for a non-SQLite-backed class), or let the dev server auto-reconcile it on the next start`)},C=(e,n,i)=>{if(e.containers===void 0)return;if(!Array.isArray(e.containers)){n.push("containers must be an array of { class_name, image, ... } entries");return}const s=e.containers;if(s.length===0)return;const a=new Set(g(e.durable_objects?.bindings).map(o=>o.class_name)),t=_(e.migrations);for(const[o,r]of s.entries())M(r,`containers[${String(o)}]`,{boundClasses:a,classKinds:t,errors:n,warnings:i});e.observability?.enabled!==!0&&i.push('containers are configured but observability is not enabled — container logs will not be captured (add { "observability": { "enabled": true } })')},b=e=>e,h=(e,n,i,s)=>{if(e!==void 0){if(!Array.isArray(e)){s.push(i.arrayMessage);return}for(const[a,t]of b(e).entries()){const o=`${n}[${String(a)}]`;if(!t||typeof t!="object"){s.push(i.objectMessage(o));continue}for(const r of i.fields)d(t[r.field])||s.push(r.message(o))}}},F={arrayMessage:"workflows must be an array of { name, binding, class_name } entries",fields:[{field:"binding",message:e=>`${e} must have a non-empty "binding" naming the Workflow binding (e.g. MY_WORKFLOW)`},{field:"class_name",message:e=>`${e} must have a non-empty "class_name" naming the exported WorkflowEntrypoint class`},{field:"name",message:e=>`${e} must have a non-empty "name" naming the deployed workflow`}],objectMessage:e=>`${e} must be a { name, binding, class_name } object`},j=(e,n)=>e===void 0||n&&d(e)||Array.isArray(e)&&e.length>0&&e.every(s=>d(s))?void 0:"schedules must be a non-empty array of cron expression strings",E=e=>{if(e!==void 0)return u(e)?e.steps===void 0||Number.isInteger(e.steps)&&e.steps>0?void 0:"limits.steps must be a positive integer":"limits must be an object"},x=e=>e===void 0?[]:u(e)?["success_retention","error_retention"].filter(n=>e[n]!==void 0&&!d(e[n])).map(n=>`default_retention.${n} must be a duration string (e.g. "7 days")`):["default_retention must be an object"],y=(e,n,i,s)=>{const a=[j(e.schedules,i),E(e.limits),...x(e.default_retention)];for(const t of a)t!==void 0&&s.push(`${n}.${t}`)},A=(e,n)=>f.map(({path:i})=>i).filter(i=>{const s=p(e,i),a=p(n,i),t=typeof a=="string"&&i[0]==="schedules"?[a]:a;return s!==void 0&&a!==void 0&&JSON.stringify(s)!==JSON.stringify(t)}).map(i=>i.join(".")),R=(e,n,i,s)=>{const a=`exports["${e}"]`,t=String(n.name);for(const o of i){if(!u(o)||o.name!==n.name)continue;const r=`workflows entry "${String(o.binding)}"`;if(o.script_name!==void 0){s.push(`${r} binds workflow "${t}" in another Worker, but ${a} declares a workflow with that name here — workflow names are unique per account`);continue}o.class_name!==e&&s.push(`${r} and ${a} both declare workflow "${t}" but name different classes ("${String(o.class_name)}" vs "${e}")`);for(const c of A(o,n))s.push(`${r} and ${a} set ${c} to different values for workflow "${t}" — set it in one place`)}},L=(e,n)=>{const i=Array.isArray(e.workflows)?b(e.workflows):[];for(const[a,t]of i.entries())u(t)&&y(t,`workflows[${String(a)}]`,!1,n);const s=u(e.exports)?Object.entries(e.exports):[];for(const[a,t]of s)!u(t)||t.type!=="workflow"||(d(t.name)?(y(t,`exports["${a}"]`,!0,n),R(a,t,i,n)):n.push(`exports["${a}"] is a workflow export and must have a non-empty "name" naming the deployed workflow`))},q={arrayMessage:"queues.producers must be an array of { binding, queue } entries",fields:[{field:"binding",message:e=>`${e} must have a non-empty "binding" naming the Queue producer (e.g. QUEUE_EMAIL)`},{field:"queue",message:e=>`${e} must have a non-empty "queue" naming the deployed queue`}],objectMessage:e=>`${e} must be a { binding, queue } object`},B={arrayMessage:"queues.consumers must be an array of { queue } entries",fields:[{field:"queue",message:e=>`${e} must have a non-empty "queue" naming the consumed queue`}],objectMessage:e=>`${e} must be a { queue } object`},U=(e,n)=>{if(e.queues!==void 0){if(typeof e.queues!="object"||Array.isArray(e.queues)){n.push("queues must be a { producers, consumers } object");return}h(e.queues.producers,"queues.producers",q,n),h(e.queues.consumers,"queues.consumers",B,n)}},T={arrayMessage:"secrets_store_secrets must be an array of { binding, store_id, secret_name } entries",fields:["binding","store_id","secret_name"].map(e=>({field:e,message:n=>`${n} must have a non-empty "${e}"`})),objectMessage:e=>`${e} must be a { binding, store_id, secret_name } object`},W=[{arrayMessage:"kv_namespaces must be an array of { binding, id } entries",bindingMessage:e=>`${e} must have a non-empty "binding" naming the KV namespace binding`,hintField:"id",hintMessage:(e,n)=>`${e} ("${n}") has no "id" — run \`wrangler kv namespace create\` and set the namespace id, or the binding can't resolve`,key:"kv_namespaces"},{arrayMessage:"flagship must be an array of { binding, app_id } entries",bindingMessage:e=>`${e} must have a non-empty "binding" naming the Flagship binding`,hintField:"app_id",hintMessage:(e,n)=>`${e} ("${n}") has no "app_id" — create a Flagship app and set its id, or the binding can't resolve`,key:"flagship"},{arrayMessage:"hyperdrive must be an array of { binding, id } entries",bindingMessage:e=>`${e} must have a non-empty "binding" naming the Hyperdrive binding`,hintField:"id",hintMessage:(e,n)=>`${e} ("${n}") has no "id" — run \`wrangler hyperdrive create\` and set the id, or the binding can't connect`,key:"hyperdrive"},{arrayMessage:"pipelines must be an array of { binding, stream } entries",bindingMessage:e=>`${e} must have a non-empty "binding" naming the Pipelines binding`,hintField:["stream","pipeline"],hintMessage:(e,n)=>`${e} ("${n}") has no "stream" — run \`wrangler pipelines create <name>\` and set the stream name, or the binding can't resolve`,key:"pipelines"},{arrayMessage:"analytics_engine_datasets must be an array of { binding, dataset } entries",bindingMessage:e=>`${e} must have a non-empty "binding" naming the Analytics Engine binding`,hintField:"dataset",hintMessage:(e,n)=>`${e} ("${n}") has no "dataset" — it defaults to the binding name; set it explicitly to avoid drift`,key:"analytics_engine_datasets"}],G=(e,n,i,s)=>{const a=e[n.key];if(a!==void 0){if(!Array.isArray(a)){i.push(n.arrayMessage);return}for(const[t,o]of b(a).entries()){const r=`${n.key}[${String(t)}]`;if(!o||typeof o!="object"||!d(o.binding)){i.push(n.bindingMessage(r));continue}(typeof n.hintField=="string"?[n.hintField]:n.hintField).some(m=>d(o[m]))||s.push(n.hintMessage(r,o.binding))}}},P=[{key:"browser",message:'browser must be an object with a non-empty "binding" (e.g. { "binding": "BROWSER" })'},{key:"images",message:'images must be an object with a non-empty "binding" (e.g. { "binding": "IMAGES" })'},{key:"media",message:'media must be an object with a non-empty "binding" (e.g. { "binding": "MEDIA" })'},{key:"stream",message:'stream must be an object with a non-empty "binding" (e.g. { "binding": "STREAM" })'}],K=(e,n,i)=>{const s=e[n.key];s!==void 0&&(typeof s!="object"||s===null||Array.isArray(s)||!d(s.binding))&&i.push(n.message)},Q=[{arrayMessage:"services must be an array of { binding, service, entrypoint? } entries",fields:[{field:"binding",message:e=>`${e} must have a non-empty "binding" naming the service binding`},{field:"service",message:e=>`${e} must have a non-empty "service" naming the target Worker`}],key:"services",objectMessage:e=>`${e} must be a { binding, service, entrypoint? } object`},{arrayMessage:"dispatch_namespaces must be an array of { binding, namespace } entries",fields:[{field:"binding",message:e=>`${e} must have a non-empty "binding"`},{field:"namespace",message:e=>`${e} must have a non-empty "namespace" naming the dispatch namespace`}],key:"dispatch_namespaces",objectMessage:e=>`${e} must be a { binding, namespace } object`},{arrayMessage:"mtls_certificates must be an array of { binding, certificate_id } entries",fields:[{field:"binding",message:e=>`${e} must have a non-empty "binding"`},{field:"certificate_id",message:e=>`${e} must have a non-empty "certificate_id" (upload via \`wrangler mtls-certificate upload\`)`}],key:"mtls_certificates",objectMessage:e=>`${e} must be a { binding, certificate_id } object`},{arrayMessage:"r2_buckets must be an array of { binding, bucket_name } entries",fields:[{field:"binding",message:e=>`${e} must have a non-empty "binding" naming the R2 bucket binding`},{field:"bucket_name",message:e=>`${e} must have a non-empty "bucket_name" naming the deployed bucket`}],key:"r2_buckets",objectMessage:e=>`${e} must be a { binding, bucket_name } object`},{arrayMessage:"vpc_services must be an array of { binding, service_id } entries",fields:[{field:"binding",message:e=>`${e} must have a non-empty "binding" naming the VPC Service binding`},{field:"service_id",message:e=>`${e} must have a non-empty "service_id" (create one with \`wrangler vpc service create\`)`}],key:"vpc_services",objectMessage:e=>`${e} must be a { binding, service_id } object`},{arrayMessage:"artifacts must be an array of { binding, namespace } entries",fields:[{field:"binding",message:e=>`${e} must have a non-empty "binding" naming the Artifacts binding`},{field:"namespace",message:e=>`${e} must have a non-empty "namespace" naming the Artifacts namespace`}],key:"artifacts",objectMessage:e=>`${e} must be a { binding, namespace } object`}],z=(e,n,i)=>{n?.hasD1GlobalTable&&!g(e.d1_databases).some(s=>s.binding==="DB")&&i.push('schema declares .global() tables; d1_databases must include a binding named "DB" — your dev server auto-reconciles this on startup, or add the binding manually'),n?.hasHyperdriveGlobalTable&&g(e.hyperdrive).length===0&&i.push('schema declares .global({ backend: "hyperdrive" }) tables; wrangler must declare a hyperdrive binding for `.hyperdriveGlobal({ exec })` to read — run `wrangler hyperdrive create <name> --connection-string=...` and add `"hyperdrive": [{ "binding": "HYPERDRIVE", "id": "<id>" }]` (any binding name works; your `exec` selector picks it)')},H=(e,n)=>{const{d1_databases:i}=e;if(i!==void 0){if(!Array.isArray(i)){n.push("d1_databases must be an array of { binding, database_id | database_name } entries");return}for(const[s,a]of b(i).entries()){const t=`d1_databases[${String(s)}]`;if(!a||typeof a!="object"){n.push(`${t} must be a { binding, database_id | database_name } object`);continue}d(a.binding)||n.push(`${t} must have a non-empty "binding" naming the D1 binding`),!d(a.database_id)&&!d(a.database_name)&&n.push(`${t} must have a "database_id" or a "database_name" — run \`wrangler d1 create\` and set one, or the binding can't resolve`)}}},V=(e,n)=>{const{vpc_networks:i}=e;if(i!==void 0){if(!Array.isArray(i)){n.push("vpc_networks must be an array of { binding, tunnel_id | network_id } entries");return}for(const[s,a]of b(i).entries()){const t=`vpc_networks[${String(s)}]`;if(!a||typeof a!="object"){n.push(`${t} must be a { binding, tunnel_id | network_id } object`);continue}d(a.binding)||n.push(`${t} must have a non-empty "binding" naming the VPC Network binding`),d(a.tunnel_id)===d(a.network_id)&&n.push(`${t} must set exactly one of "tunnel_id" (a Cloudflare Tunnel) or "network_id" ("cf1:network" for Cloudflare Mesh)`)}}};export{W as H,Q as R,P as S,F as W,z as a,H as b,I as c,C as d,h as e,L as f,U as g,G as h,K as i,V as j,T as k,d as l,D as m,l as n,g as o,f as p,p as s,N as v,O as w};
@@ -0,0 +1 @@
1
+ import{l as d,o as p}from"./validate-bindings-Dnf1t0SY.mjs";const b=new Set(["1","enabled","on","true","yes"]),m=s=>typeof s=="string"&&b.has(s.trim().toLowerCase()),y=(s,t,e)=>{const i=s.send_email;if(i===void 0)return;if(!Array.isArray(i)){t.push("send_email must be an array of { name, destination_address? } entries");return}const n=i;for(const[o,a]of n.entries())(!a||typeof a!="object"||typeof a.name!="string"||a.name.length===0)&&e.push(`send_email[${String(o)}] has no non-empty "name" naming the send-email binding — set one before deploying`)},g=(s,t)=>{s.logpush!==void 0&&typeof s.logpush!="boolean"&&t.push('logpush must be a boolean (set "logpush": true to enable Cloudflare Logpush)')},v=(s,t)=>{const e=s.secrets;if(e===void 0)return;const i=typeof e=="object"&&e!==null&&!Array.isArray(e)?e.required:void 0;(!Array.isArray(i)||i.some(n=>typeof n!="string"||n===""))&&t.push('secrets must be an object whose "required" is an array of secret names (e.g. { "required": ["API_KEY"] })')},c=3e5,_=(s,t)=>{const{limits:e}=s;if(e===void 0)return;if(typeof e!="object"||Array.isArray(e)){t.push('limits must be an object (e.g. { "cpu_ms": 30000 })');return}const i=e.cpu_ms;if(i!==void 0){if(typeof i!="number"||!Number.isFinite(i)||!Number.isInteger(i)||i<=0){t.push("limits.cpu_ms must be a positive integer number of milliseconds");return}i>c&&t.push(`limits.cpu_ms must be at most ${String(c)} (Cloudflare's per-invocation ceiling)`)}},l=new Set(["off","smart","targeted"]),A=(s,t)=>{const{placement:e}=s;if(e===void 0)return;if(typeof e!="object"||e===null||Array.isArray(e)){t.push('placement must be an object (e.g. { "mode": "smart" })');return}const{mode:i}=e;i!==void 0&&(typeof i!="string"||!l.has(i))&&t.push(`placement.mode must be one of ${[...l].map(n=>`"${n}"`).join(", ")}`)},j=(s,t)=>{const{observability:e}=s;if(e===void 0)return;if(typeof e!="object"||Array.isArray(e)){t.push('observability must be an object (e.g. { "enabled": true, "head_sampling_rate": 1 })');return}const i=(n,o)=>{n!==void 0&&(typeof n!="number"||Number.isNaN(n)||n<0||n>1)&&t.push(`${o} must be a number in [0, 1] (the fraction of requests sampled)`)};i(e.head_sampling_rate,"observability.head_sampling_rate"),e.logs!==void 0&&(typeof e.logs!="object"||Array.isArray(e.logs)?t.push("observability.logs must be an object"):(i(e.logs.head_sampling_rate,"observability.logs.head_sampling_rate"),e.logs.invocation_logs!==void 0&&typeof e.logs.invocation_logs!="boolean"&&t.push('observability.logs.invocation_logs must be a boolean (set "invocation_logs": true to keep per-invocation summaries)')))},S=(s,t)=>{const{cache:e}=s;if(e!==void 0){if(typeof e!="object"||e===null||Array.isArray(e)){t.push('cache must be an object (e.g. { "enabled": true })');return}e.enabled!==void 0&&typeof e.enabled!="boolean"&&t.push("cache.enabled must be a boolean (true or false)")}},O=(s,t)=>{const{exports:e}=s;if(e!==void 0){if(typeof e!="object"||e===null||Array.isArray(e)){t.push("exports must be an object keyed by entrypoint name");return}for(const[i,n]of Object.entries(e)){if(typeof n!="object"||n===null){t.push(`exports["${i}"] must be an object`);continue}n.type!==void 0&&typeof n.type!="string"&&t.push(`exports["${i}"].type must be a string`),n.cache!==void 0&&(typeof n.cache!="object"||n.cache===null||Array.isArray(n.cache)?t.push(`exports["${i}"].cache must be an object`):n.cache.enabled!==void 0&&typeof n.cache.enabled!="boolean"&&t.push(`exports["${i}"].cache.enabled must be a boolean`))}}},E=(s,t)=>{const{assets:e}=s;if(e!==void 0){if(typeof e!="object"||Array.isArray(e)){t.push('assets must be an object (e.g. { "directory": "./dist/client", "binding": "ASSETS" })');return}(typeof e.directory!="string"||e.directory.length===0)&&t.push('assets must declare a non-empty "directory" pointing at the built client output (e.g. "./dist/client")'),e.binding!==void 0&&(typeof e.binding!="string"||e.binding.length===0)&&t.push('assets.binding must be a non-empty string (e.g. "ASSETS")'),e.html_handling!==void 0&&typeof e.html_handling!="string"&&t.push("assets.html_handling must be a string"),e.not_found_handling!==void 0&&typeof e.not_found_handling!="string"&&t.push("assets.not_found_handling must be a string")}},L=(s,t)=>{const e=s.tail_consumers;if(e===void 0)return;if(!Array.isArray(e)){t.push("tail_consumers must be an array of { service, environment? } entries");return}const i=e;for(const[n,o]of i.entries())(!o||typeof o!="object"||typeof o.service!="string"||o.service.length===0)&&t.push(`tail_consumers[${String(n)}] must have a non-empty "service" naming the consumer Worker`)},N=(s,t)=>{const e=s.tail_consumers??[];return e.some(n=>!!n&&n?.service===t.service&&n?.environment===t.environment)?s:{...s,tail_consumers:[...e,t]}},R=(s,t)=>{const{vars:e}=s;if(!e||typeof e!="object")return;const i=e.LUNORA_ALLOWED_ORIGINS,n=e.LUNORA_CORS_ALLOW_CREDENTIALS,o=typeof i=="string"&&i.split(",").some(u=>u.trim()==="*"),a=m(n);o&&a&&t.push('vars.LUNORA_ALLOWED_ORIGINS includes a "*" wildcard while vars.LUNORA_CORS_ALLOW_CREDENTIALS is on — browsers reject this combination and it defeats the allowlist; name explicit origins or drop credentials')},f=s=>p(s.durable_objects?.bindings).some(t=>t.class_name==="SchedulerDO"&&t.script_name===void 0),r="LUNORA_ORIGIN_URL",$=(s,t,e)=>{if(!f(s)||d(s.vars?.[r]))return;const i=t===void 0?"vars":`env.${t}.vars`,n=t===void 0?"":` --env ${t}`;e.push(`durable_objects.bindings declares the SchedulerDO but ${i}.${r} is unset — the DO reads its dispatch origin from its own env and refuses to schedule without it, so every ctx.scheduler.runAfter/runAt fails with ORIGIN_NOT_CONFIGURED. Set ${i}.${r} to the worker's public URL, or \`wrangler secret put ${r}${n}\` (ignore this if it is already set as a secret or in the dashboard).`)};export{E as validateAssets,S as validateCache,R as validateCorsVariables,O as validateExports,_ as validateLimits,g as validateLogpush,j as validateObservability,A as validatePlacement,$ as validateSchedulerOrigin,v as validateSecretsRequired,y as validateSendEmail,L as validateTailConsumers,N as withTailConsumer};
@@ -0,0 +1,6 @@
1
+ const o=e=>JSON.stringify(e),$=/^[A-Z_a-z][\w$]*$/u,d=e=>$.test(e),u=e=>d(e)?e:`binding_${e.replaceAll(/\W/gu,"_")}`,m=(e,s=u(e))=>{const n=d(e);return n&&s===e?`${e},`:`${n?e:o(e)}: ${s},`},g=e=>{const s=new Set;for(const n of e.migrations??[])for(const r of n.new_sqlite_classes??[])s.add(r);return s},v=(e,s,n,r,c)=>{for(const a of e.durable_objects?.bindings??[])if(!(a.name===void 0||a.class_name===void 0)){if(a.script_name!==void 0){c.push(`durable_objects.${a.name} (external script_name "${a.script_name}")`);continue}n.add("DurableObjectNamespace"),r.push(m(a.name,`DurableObjectNamespace(${o(a.name)}, { className: ${o(a.class_name)}, sqlite: ${String(s.has(a.class_name))} })`))}},h=(e,s)=>{for(const[n,r]of Object.entries(e.vars??{}))s.push(m(n,o(r)))},w=["ai","analytics_engine_datasets","assets","browser","containers","flagship","hyperdrive","images","pipelines","secrets_store_secrets","send_email","services","tail_consumers","vectorize","worker_loaders","workflows","exports"],f=(e,s)=>{for(const n of w){const r=e[n];r!==void 0&&(!Array.isArray(r)||r.length>0)&&s.push(n)}(e.queues?.consumers?.length??0)>0&&s.push("queues.consumers")},k=e=>{const s=e.name??"worker",n=[],r=new Set(["Worker"]),c=[],a=[],p=g(e),b=[{construct:"D1Database",entries:(e.d1_databases??[]).map(t=>({binding:t.binding,name:t.database_name})),nameKey:"name"},{construct:"R2Bucket",entries:(e.r2_buckets??[]).map(t=>({binding:t.binding,name:t.bucket_name})),nameKey:"name"},{construct:"KVNamespace",entries:(e.kv_namespaces??[]).map(t=>({binding:t.binding,name:t.binding})),nameKey:"title"},{construct:"Queue",entries:(e.queues?.producers??[]).map(t=>({binding:t.binding,name:t.queue})),nameKey:"name"}];for(const{construct:t,entries:l,nameKey:y}of b)for(const i of l)i.binding!==void 0&&(r.add(t),c.push(`const ${u(i.binding)} = await ${t}(${o(i.binding)}, { adopt: true, ${y}: ${o(i.name??i.binding)} });`),a.push(m(i.binding)));v(e,p,r,a,n),h(e,a),f(e,n);const _=["adopt: true,",a.length===0?void 0:`bindings: {
2
+ ${a.join(`
3
+ `)}
4
+ },`,e.compatibility_date===void 0?void 0:`compatibilityDate: ${o(e.compatibility_date)},`,e.compatibility_flags===void 0||e.compatibility_flags.length===0?void 0:`compatibilityFlags: ${o([...e.compatibility_flags])},`,e.triggers?.crons===void 0||e.triggers.crons.length===0?void 0:`crons: ${o([...e.triggers.crons])},`,e.main===void 0?void 0:`entrypoint: ${o(e.main)},`,`name: ${o(s)},`].filter(t=>t!==void 0);return{source:["// GENERATED by @lunora/config from wrangler.jsonc — do not edit.","// Re-generated on every `lunora deploy`; edit wrangler.jsonc instead.","",'import alchemy from "alchemy";',`import { ${[...r].toSorted((t,l)=>t.localeCompare(l)).join(", ")} } from "alchemy/cloudflare";`,"",`const app = await alchemy(${o(s)});`,"",...c.length===0?[]:[...c,""],`export const worker = await Worker(${o(s)}, {`,` ${_.join(`
5
+ `)}`,"});","","await app.finalize();",""].join(`
6
+ `),unsupported:n}};export{g as sqliteClasses,k as wranglerToAlchemy};
@@ -0,0 +1 @@
1
+ import{runCodegen as c,CodegenDiagnosticError as a}from"@lunora/codegen";import{collectWranglerSecretVariables as i}from"./collectWranglerSecretVariables-D-usPfT8.mjs";import{isCodegenDisabled as s,CODEGEN_ENV as t}from"./CODEGEN_ENV-ZsCxV1kP.mjs";import{writeFileSync as m,renameSync as p,rmSync as d}from"node:fs";const g=r=>({apiSpec:r.apiSpec,lunoraDirectory:r.schemaDirectory??"lunora",projectRoot:r.projectRoot,wranglerVariables:i(r.projectRoot)}),y=r=>{if(s(process.env[t]))return[`codegen is off (${t}=0 / \`lunora dev --no-codegen\`) — the source was written but \`_generated/\` was NOT regenerated`];try{c(g(r))}catch(e){if(e instanceof a)return[e.message];throw e}return[]},S=(r,e)=>{const o=`${r}.lunora-tmp`;try{m(o,e,"utf8"),p(o,r)}catch(n){throw d(o,{force:!0}),n}};export{y as r,S as w};