@lunora/codegen 1.0.0-alpha.145 → 1.0.0-alpha.146

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 (50) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.mts +15 -3
  3. package/dist/index.d.ts +15 -3
  4. package/dist/index.mjs +1 -1
  5. package/dist/packem_shared/{AGENTS_FILENAME-D1qA0h5m.mjs → AGENTS_FILENAME-B1Abt3Gl.mjs} +1 -1
  6. package/dist/packem_shared/{CONTAINERS_FILENAME-oKaARMoA.mjs → CONTAINERS_FILENAME-CtcysaKS.mjs} +1 -1
  7. package/dist/packem_shared/DEFAULT_TARGET-BvzxeWRZ.mjs +1 -0
  8. package/dist/packem_shared/FLAGS_FILENAME-B3VZ6vTw.mjs +1 -0
  9. package/dist/packem_shared/{GENERATED_HEADER-D4WIATth.mjs → GENERATED_HEADER-Dfc3qlLQ.mjs} +1 -1
  10. package/dist/packem_shared/{NOTIFY_FILENAME-B-eIjru_.mjs → NOTIFY_FILENAME-CKO5gtGe.mjs} +1 -1
  11. package/dist/packem_shared/{OPENRPC_VERSION-CJwwFY8T.mjs → OPENRPC_VERSION-CdKqq_QT.mjs} +1 -1
  12. package/dist/packem_shared/{QUEUES_FILENAME-D229WtRm.mjs → QUEUES_FILENAME-C-pzLGy4.mjs} +1 -1
  13. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CeOctEWC.mjs +9 -0
  14. package/dist/packem_shared/{WORKFLOWS_FILENAME-DRaiCNa6.mjs → WORKFLOWS_FILENAME-BfvqsG9Z.mjs} +1 -1
  15. package/dist/packem_shared/ast-BYoSZlae.mjs +1 -0
  16. package/dist/packem_shared/{buildOpenApiDocument-CU1yw_t3.mjs → buildOpenApiDocument-D40ZeYsu.mjs} +1 -1
  17. package/dist/packem_shared/chain-Dygm2apY.mjs +1 -0
  18. package/dist/packem_shared/{classify-procedure-call-AKeIK05y.mjs → classify-procedure-call-Ib2EMtFH.mjs} +1 -1
  19. package/dist/packem_shared/{context-property-calls-DXH-4MTZ.mjs → context-property-calls-Br0sVv8E.mjs} +1 -1
  20. package/dist/packem_shared/{discoverAuthApiCalls-C35kkayg.mjs → discoverAuthApiCalls-DoNQSgso.mjs} +1 -1
  21. package/dist/packem_shared/{discoverCrons-wXBfQcfn.mjs → discoverCrons-DCxl4hty.mjs} +1 -1
  22. package/dist/packem_shared/{discoverFunctions-DglkHRlt.mjs → discoverFunctions-C29Tvxas.mjs} +1 -1
  23. package/dist/packem_shared/{discoverHttpRoutes-B60GWv_I.mjs → discoverHttpRoutes-CFIXlUy4.mjs} +1 -1
  24. package/dist/packem_shared/discoverHyperdriveCalls-DTq4PKT5.mjs +1 -0
  25. package/dist/packem_shared/{discoverInserts-C5l2INmE.mjs → discoverInserts-qU5F4W4g.mjs} +1 -1
  26. package/dist/packem_shared/discoverMaskProcedures-BZsC5dHd.mjs +1 -0
  27. package/dist/packem_shared/{discoverMigrations-CWH7T6qz.mjs → discoverMigrations-BFkJQ8Sy.mjs} +1 -1
  28. package/dist/packem_shared/{discoverNondeterministicCalls-JsO91i57.mjs → discoverNondeterministicCalls-B-NNzzPW.mjs} +1 -1
  29. package/dist/packem_shared/discoverQueries-B4emAFn5.mjs +1 -0
  30. package/dist/packem_shared/discoverR2sqlCalls-C2GtrFnl.mjs +1 -0
  31. package/dist/packem_shared/{discoverRlsMetadata-DGUGYgWs.mjs → discoverRlsMetadata-BKcUnSNr.mjs} +1 -1
  32. package/dist/packem_shared/{discoverRlsProcedures-CRshfYZE.mjs → discoverRlsProcedures-fAhxiIyD.mjs} +1 -1
  33. package/dist/packem_shared/discoverSandboxUsage-CJhnKA0_.mjs +1 -0
  34. package/dist/packem_shared/{discoverStorageRulesMetadata-gyO60A5S.mjs → discoverStorageRulesMetadata-C7XmORWp.mjs} +1 -1
  35. package/dist/packem_shared/{emit-Bo3kao_A.mjs → emit-BcAkLUfn.mjs} +179 -199
  36. package/dist/packem_shared/{emitApp-CPXPVz9b.mjs → emitApp-DoR55vKV.mjs} +1 -1
  37. package/dist/packem_shared/{exported-procedure-chains-MlZRKqSD.mjs → exported-procedure-chains-M40rbSYM.mjs} +1 -1
  38. package/dist/packem_shared/{index-CCDlo9L7.mjs → index-xGhyK9J_.mjs} +1 -1
  39. package/dist/packem_shared/{queries-B_xEHIeL.mjs → queries-Ddvo5dCs.mjs} +1 -1
  40. package/package.json +10 -10
  41. package/dist/packem_shared/DEFAULT_TARGET-CwB3hjFH.mjs +0 -1
  42. package/dist/packem_shared/FLAGS_FILENAME-BasxlnVS.mjs +0 -1
  43. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BtWckBME.mjs +0 -9
  44. package/dist/packem_shared/ast-CjWtsS6S.mjs +0 -1
  45. package/dist/packem_shared/chain-CtC3-wwZ.mjs +0 -1
  46. package/dist/packem_shared/discoverHyperdriveCalls-De_QiFIl.mjs +0 -1
  47. package/dist/packem_shared/discoverMaskProcedures-Df4JQp_2.mjs +0 -1
  48. package/dist/packem_shared/discoverQueries-iypfwfdZ.mjs +0 -1
  49. package/dist/packem_shared/discoverR2sqlCalls-BdkZw-D2.mjs +0 -1
  50. package/dist/packem_shared/discoverSandboxUsage-DdewAOuj.mjs +0 -1
package/README.md CHANGED
@@ -34,7 +34,7 @@
34
34
 
35
35
  ---
36
36
 
37
- The Lunora code generator. It parses your `lunora/schema.ts` plus every function file under `lunora/`, then writes `lunora/_generated/` so the rest of your app gets typed access to its own backend. The core outputs are `api.ts` (the `api` / `internal` function references), `server.ts` (the `query` / `mutation` / `action` / `internalQuery` / `internalMutation` / `internalAction` / `definePolicy` procedure builders bound to your schema), and `dataModel.ts` (the `Doc` / `Id` types). It also emits `app.ts`, `functions.ts`, `shard.ts`, Drizzle schemas, and — when the relevant features are used — `crons.ts`, `containers.ts`, `workflows.ts`, `vectors.ts`, `seed.ts`, and OpenAPI/OpenRPC specs.
37
+ The Lunora code generator. It parses your `lunora/schema.ts` plus every function file under `lunora/`, then writes `lunora/_generated/` so the rest of your app gets typed access to its own backend. The core outputs are `api.ts` (the `api` / `internal` function references), `server.ts` (the `query` / `mutation` / `action` / `internalQuery` / `internalMutation` / `internalAction` / `definePolicy` procedure builders bound to your schema), and `dataModel.ts` (the `Doc` / `Id` types). It also emits `app.ts`, `functions.ts`, `shard.ts`, the Drizzle schemas (`drizzle.shard.ts` / `drizzle.global.ts` — your tables as Drizzle `sqliteTable` objects, split by whether they are `.global()`, for when you need raw Drizzle rather than `ctx.db`), and — when the relevant features are used — `crons.ts`, `containers.ts`, `workflows.ts`, `vectors.ts`, `seed.ts`, and OpenAPI/OpenRPC specs.
38
38
 
39
39
  Most apps never call this package directly — the `lunora codegen` CLI command and the `@lunora/vite` plugin invoke it for you.
40
40
 
package/dist/index.d.mts CHANGED
@@ -2857,16 +2857,28 @@ declare const discoverRlsMetadata: (project: Project, lunoraDirectory: string) =
2857
2857
  /**
2858
2858
  * Which sandbox tools a project imports from `@lunora/agent` (main entry or the
2859
2859
  * `/sandbox` subpath), detected by NAMED value import. Drives two things:
2860
- * registering the `sandbox:invoke` dispatcher (either tool) and provisioning the
2861
- * `BROWSER` wrangler binding (`browserTool` — the browser op runs on
2862
- * `ctx.browser` inside the dispatcher).
2860
+ * registering the `sandbox:invoke` dispatcher (ANY of the three tools — an agent
2861
+ * whose only sandbox tool was `fsTool` used to be missed here, so every
2862
+ * `ls`/`read`/`write`/`rm`/`stat` died on FUNCTION_NOT_FOUND) and provisioning
2863
+ * the `BROWSER` wrangler binding (`browserTool` only — the browser op runs on
2864
+ * `ctx.browser` inside the dispatcher, while `fsTool` reads a hand-declared R2
2865
+ * bucket).
2863
2866
  */
2864
2867
  interface SandboxUsage {
2865
2868
  /** `import { browserTool } from "@lunora/agent"` (or `/sandbox`) appears in `lunora/`. */
2866
2869
  usesSandboxBrowser: boolean;
2867
2870
  /** `import { containerTool } from "@lunora/agent"` (or `/sandbox`) appears in `lunora/`. */
2868
2871
  usesSandboxContainer: boolean;
2872
+ /** `import { fsTool } from "@lunora/agent"` (or `/sandbox`) appears in `lunora/`. */
2873
+ usesSandboxFs: boolean;
2869
2874
  }
2875
+ /**
2876
+ * Scan the `lunora/` source set for named imports of the sandbox tools
2877
+ * ({@link TOOL_FLAGS}) from `@lunora/agent` (main entry or the `/sandbox`
2878
+ * subpath). Type-only imports (the input/option types) do not count — only a
2879
+ * value import wires a tool into an agent. A project that imports none yields
2880
+ * all-`false` and codegen emits byte-identical output.
2881
+ */
2870
2882
  declare const discoverSandboxUsage: (project: Project, lunoraDirectory: string) => SandboxUsage;
2871
2883
  /**
2872
2884
  * Load `<projectRoot>/lunora/schema.ts`, find `defineSchema({...})`, and
package/dist/index.d.ts CHANGED
@@ -2857,16 +2857,28 @@ declare const discoverRlsMetadata: (project: Project, lunoraDirectory: string) =
2857
2857
  /**
2858
2858
  * Which sandbox tools a project imports from `@lunora/agent` (main entry or the
2859
2859
  * `/sandbox` subpath), detected by NAMED value import. Drives two things:
2860
- * registering the `sandbox:invoke` dispatcher (either tool) and provisioning the
2861
- * `BROWSER` wrangler binding (`browserTool` — the browser op runs on
2862
- * `ctx.browser` inside the dispatcher).
2860
+ * registering the `sandbox:invoke` dispatcher (ANY of the three tools — an agent
2861
+ * whose only sandbox tool was `fsTool` used to be missed here, so every
2862
+ * `ls`/`read`/`write`/`rm`/`stat` died on FUNCTION_NOT_FOUND) and provisioning
2863
+ * the `BROWSER` wrangler binding (`browserTool` only — the browser op runs on
2864
+ * `ctx.browser` inside the dispatcher, while `fsTool` reads a hand-declared R2
2865
+ * bucket).
2863
2866
  */
2864
2867
  interface SandboxUsage {
2865
2868
  /** `import { browserTool } from "@lunora/agent"` (or `/sandbox`) appears in `lunora/`. */
2866
2869
  usesSandboxBrowser: boolean;
2867
2870
  /** `import { containerTool } from "@lunora/agent"` (or `/sandbox`) appears in `lunora/`. */
2868
2871
  usesSandboxContainer: boolean;
2872
+ /** `import { fsTool } from "@lunora/agent"` (or `/sandbox`) appears in `lunora/`. */
2873
+ usesSandboxFs: boolean;
2869
2874
  }
2875
+ /**
2876
+ * Scan the `lunora/` source set for named imports of the sandbox tools
2877
+ * ({@link TOOL_FLAGS}) from `@lunora/agent` (main entry or the `/sandbox`
2878
+ * subpath). Type-only imports (the input/option types) do not count — only a
2879
+ * value import wires a tool into an agent. A project that imports none yields
2880
+ * all-`false` and codegen emits byte-identical output.
2881
+ */
2870
2882
  declare const discoverSandboxUsage: (project: Project, lunoraDirectory: string) => SandboxUsage;
2871
2883
  /**
2872
2884
  * Load `<projectRoot>/lunora/schema.ts`, find `defineSchema({...})`, and
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CTWRkAF5.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as x,diagnosticAt as E}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-D1qA0h5m.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-C35kkayg.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as C}from"./packem_shared/CONTAINERS_FILENAME-oKaARMoA.mjs";import{default as h}from"./packem_shared/discoverCrons-wXBfQcfn.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-BasxlnVS.mjs";import{default as F}from"./packem_shared/discoverFunctions-DglkHRlt.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-B60GWv_I.mjs";import{default as G}from"./packem_shared/discoverHyperdriveCalls-De_QiFIl.mjs";import{default as b}from"./packem_shared/discoverInserts-C5l2INmE.mjs";import{d as y}from"./packem_shared/index-CCDlo9L7.mjs";import{default as j}from"./packem_shared/discoverMigrations-CWH7T6qz.mjs";import{MUTATORS_FILENAME as V,discoverMutators as z}from"./packem_shared/MUTATORS_FILENAME-BKSzaCkq.mjs";import{default as w}from"./packem_shared/discoverNondeterministicCalls-JsO91i57.mjs";import{NOTIFY_FILENAME as B,discoverNotifyCalls as J,discoverNotifyConfig as Y}from"./packem_shared/NOTIFY_FILENAME-B-eIjru_.mjs";import{default as Z}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as ee}from"./packem_shared/queries-B_xEHIeL.mjs";import{QUEUES_FILENAME as oe,discoverQueues as te}from"./packem_shared/QUEUES_FILENAME-D229WtRm.mjs";import{default as ae}from"./packem_shared/discoverR2sqlCalls-BdkZw-D2.mjs";import{default as me}from"./packem_shared/discoverRlsProcedures-CRshfYZE.mjs";import{default as fe}from"./packem_shared/discoverRlsMetadata-DGUGYgWs.mjs";import{discoverSandboxUsage as ce}from"./packem_shared/discoverSandboxUsage-DdewAOuj.mjs";import{default as le}from"./packem_shared/discoverSchema-CubSTjtY.mjs";import{SHAPES_FILENAME as xe,discoverShapes as Ee}from"./packem_shared/SHAPES_FILENAME-D3N7xcEk.mjs";import{default as ue}from"./packem_shared/discoverStorageRulesMetadata-gyO60A5S.mjs";import{WORKFLOWS_FILENAME as Ne,discoverWorkflows as ge}from"./packem_shared/WORKFLOWS_FILENAME-DRaiCNa6.mjs";import{G as Re,e as Ce,a as Me,b as he,c as _e,d as Te,f as Ie,g as Le,h as Fe,i as De,j as Pe,k as Ue,l as Ge,m as He}from"./packem_shared/emit-Bo3kao_A.mjs";import{emitApp as ke}from"./packem_shared/emitApp-CPXPVz9b.mjs";import{buildOpenApiDocument as We,emitOpenApi as je,emitOpenApiModule as Ke}from"./packem_shared/buildOpenApiDocument-CU1yw_t3.mjs";import{OPENRPC_VERSION as ze,buildOpenRpcDocument as Qe,emitOpenRpc as we,emitOpenRpcModule as qe}from"./packem_shared/OPENRPC_VERSION-CJwwFY8T.mjs";import{DEFAULT_TARGET as Je,platformMatrixIds as Ye,readProjectTarget as Xe,resolveCodegenTarget as Ze}from"./packem_shared/DEFAULT_TARGET-CwB3hjFH.mjs";import{SCHEMA_SNAPSHOT_FILENAME as er,createCodegenProject as rr,findTsconfig as or,refreshCodegenProject as tr,runCodegen as sr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-BtWckBME.mjs";import{SchemaSnapshotParseError as ir,buildSchemaSnapshot as mr,evaluateSchemaDrift as dr,parseSchemaSnapshot as fr}from"./packem_shared/SchemaSnapshotParseError-qXCOA7dD.mjs";import{schemaFromIr as cr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as lr,validatorIrToJsonSchema as Sr}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as Er,SDK_TARGETS as Ar,generateSdk as ur}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as Nr,secretKindOf as gr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as Rr,findSolutionByMessage as Cr}from"@lunora/errors";import{isTypedSchema as hr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,x as CodegenDiagnosticError,Je as DEFAULT_TARGET,T as FLAGS_FILENAME,Re as GENERATED_HEADER,lr as LUNORA_ERROR_CODES,Rr as LUNORA_SOLUTION_RULES,V as MUTATORS_FILENAME,B as NOTIFY_FILENAME,ze as OPENRPC_VERSION,oe as QUEUES_FILENAME,er as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Er as SDK_LANGUAGES,Ar as SDK_TARGETS,xe as SHAPES_FILENAME,ir as SchemaSnapshotParseError,e as VERSION,Ne as WORKFLOWS_FILENAME,We as buildOpenApiDocument,Qe as buildOpenRpcDocument,mr as buildSchemaSnapshot,rr as createCodegenProject,c as describeErrorLevelFindings,E as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,g as discoverAuthApiCalls,C as discoverContainers,h as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverHyperdriveCalls,b as discoverInserts,y as discoverMaskProcedures,j as discoverMigrations,z as discoverMutators,w as discoverNondeterministicCalls,J as discoverNotifyCalls,Y as discoverNotifyConfig,ee as discoverQueries,te as discoverQueues,ae as discoverR2sqlCalls,fe as discoverRlsMetadata,me as discoverRlsProcedures,ce as discoverSandboxUsage,le as discoverSchema,Ee as discoverShapes,ue as discoverStorageRulesMetadata,ge as discoverWorkflows,Ce as emitAgents,Me as emitApi,ke as emitApp,he as emitCollections,_e as emitContainers,Te as emitCrons,Ie as emitDataModel,Le as emitDrizzleSchema,Fe as emitFunctions,je as emitOpenApi,Ke as emitOpenApiModule,we as emitOpenRpc,qe as emitOpenRpcModule,De as emitServer,Pe as emitShard,Ue as emitVectors,Ge as emitWorkflows,He as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,dr as evaluateSchemaDrift,Cr as findLunoraSolution,or as findTsconfig,m as formatAdvisories,ur as generateSdk,hr as isTypedSchema,d as lintSchema,fr as parseSchemaSnapshot,Ye as platformMatrixIds,Z as readPackageDependencies,Xe as readProjectTarget,Nr as redact,tr as refreshCodegenProject,Ze as resolveCodegenTarget,sr as runCodegen,cr as schemaFromIr,gr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,Sr as validatorIrToJsonSchema};
1
+ import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CTWRkAF5.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as x,diagnosticAt as E}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-B1Abt3Gl.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-DoNQSgso.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as C}from"./packem_shared/CONTAINERS_FILENAME-CtcysaKS.mjs";import{default as h}from"./packem_shared/discoverCrons-DCxl4hty.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-B3VZ6vTw.mjs";import{default as F}from"./packem_shared/discoverFunctions-C29Tvxas.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-CFIXlUy4.mjs";import{default as G}from"./packem_shared/discoverHyperdriveCalls-DTq4PKT5.mjs";import{default as b}from"./packem_shared/discoverInserts-qU5F4W4g.mjs";import{d as y}from"./packem_shared/index-xGhyK9J_.mjs";import{default as j}from"./packem_shared/discoverMigrations-BFkJQ8Sy.mjs";import{MUTATORS_FILENAME as V,discoverMutators as z}from"./packem_shared/MUTATORS_FILENAME-BKSzaCkq.mjs";import{default as w}from"./packem_shared/discoverNondeterministicCalls-B-NNzzPW.mjs";import{NOTIFY_FILENAME as B,discoverNotifyCalls as J,discoverNotifyConfig as Y}from"./packem_shared/NOTIFY_FILENAME-CKO5gtGe.mjs";import{default as Z}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as ee}from"./packem_shared/queries-Ddvo5dCs.mjs";import{QUEUES_FILENAME as oe,discoverQueues as te}from"./packem_shared/QUEUES_FILENAME-C-pzLGy4.mjs";import{default as ae}from"./packem_shared/discoverR2sqlCalls-C2GtrFnl.mjs";import{default as me}from"./packem_shared/discoverRlsProcedures-fAhxiIyD.mjs";import{default as fe}from"./packem_shared/discoverRlsMetadata-BKcUnSNr.mjs";import{discoverSandboxUsage as ce}from"./packem_shared/discoverSandboxUsage-CJhnKA0_.mjs";import{default as le}from"./packem_shared/discoverSchema-CubSTjtY.mjs";import{SHAPES_FILENAME as xe,discoverShapes as Ee}from"./packem_shared/SHAPES_FILENAME-D3N7xcEk.mjs";import{default as ue}from"./packem_shared/discoverStorageRulesMetadata-C7XmORWp.mjs";import{WORKFLOWS_FILENAME as Ne,discoverWorkflows as ge}from"./packem_shared/WORKFLOWS_FILENAME-BfvqsG9Z.mjs";import{G as Re,e as Ce,a as Me,b as he,c as _e,d as Te,f as Ie,g as Le,h as Fe,i as De,j as Pe,k as Ue,l as Ge,m as He}from"./packem_shared/emit-BcAkLUfn.mjs";import{emitApp as ke}from"./packem_shared/emitApp-DoR55vKV.mjs";import{buildOpenApiDocument as We,emitOpenApi as je,emitOpenApiModule as Ke}from"./packem_shared/buildOpenApiDocument-D40ZeYsu.mjs";import{OPENRPC_VERSION as ze,buildOpenRpcDocument as Qe,emitOpenRpc as we,emitOpenRpcModule as qe}from"./packem_shared/OPENRPC_VERSION-CdKqq_QT.mjs";import{DEFAULT_TARGET as Je,platformMatrixIds as Ye,readProjectTarget as Xe,resolveCodegenTarget as Ze}from"./packem_shared/DEFAULT_TARGET-BvzxeWRZ.mjs";import{SCHEMA_SNAPSHOT_FILENAME as er,createCodegenProject as rr,findTsconfig as or,refreshCodegenProject as tr,runCodegen as sr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-CeOctEWC.mjs";import{SchemaSnapshotParseError as ir,buildSchemaSnapshot as mr,evaluateSchemaDrift as dr,parseSchemaSnapshot as fr}from"./packem_shared/SchemaSnapshotParseError-qXCOA7dD.mjs";import{schemaFromIr as cr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as lr,validatorIrToJsonSchema as Sr}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as Er,SDK_TARGETS as Ar,generateSdk as ur}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as Nr,secretKindOf as gr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as Rr,findSolutionByMessage as Cr}from"@lunora/errors";import{isTypedSchema as hr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,x as CodegenDiagnosticError,Je as DEFAULT_TARGET,T as FLAGS_FILENAME,Re as GENERATED_HEADER,lr as LUNORA_ERROR_CODES,Rr as LUNORA_SOLUTION_RULES,V as MUTATORS_FILENAME,B as NOTIFY_FILENAME,ze as OPENRPC_VERSION,oe as QUEUES_FILENAME,er as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Er as SDK_LANGUAGES,Ar as SDK_TARGETS,xe as SHAPES_FILENAME,ir as SchemaSnapshotParseError,e as VERSION,Ne as WORKFLOWS_FILENAME,We as buildOpenApiDocument,Qe as buildOpenRpcDocument,mr as buildSchemaSnapshot,rr as createCodegenProject,c as describeErrorLevelFindings,E as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,g as discoverAuthApiCalls,C as discoverContainers,h as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverHyperdriveCalls,b as discoverInserts,y as discoverMaskProcedures,j as discoverMigrations,z as discoverMutators,w as discoverNondeterministicCalls,J as discoverNotifyCalls,Y as discoverNotifyConfig,ee as discoverQueries,te as discoverQueues,ae as discoverR2sqlCalls,fe as discoverRlsMetadata,me as discoverRlsProcedures,ce as discoverSandboxUsage,le as discoverSchema,Ee as discoverShapes,ue as discoverStorageRulesMetadata,ge as discoverWorkflows,Ce as emitAgents,Me as emitApi,ke as emitApp,he as emitCollections,_e as emitContainers,Te as emitCrons,Ie as emitDataModel,Le as emitDrizzleSchema,Fe as emitFunctions,je as emitOpenApi,Ke as emitOpenApiModule,we as emitOpenRpc,qe as emitOpenRpcModule,De as emitServer,Pe as emitShard,Ue as emitVectors,Ge as emitWorkflows,He as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,dr as evaluateSchemaDrift,Cr as findLunoraSolution,or as findTsconfig,m as formatAdvisories,ur as generateSdk,hr as isTypedSchema,d as lintSchema,fr as parseSchemaSnapshot,Ye as platformMatrixIds,Z as readPackageDependencies,Xe as readProjectTarget,Nr as redact,tr as refreshCodegenProject,Ze as resolveCodegenTarget,sr as runCodegen,cr as schemaFromIr,gr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,Sr as validatorIrToJsonSchema};
@@ -1 +1 @@
1
- import{existsSync as u}from"node:fs";import{join as p}from"node:path";import{agentDefaultName as d,agentClassName as f,agentBindingName as b,voiceBindingName as N,voiceClassName as y}from"@lunora/agent/naming";import{LunoraError as l}from"@lunora/errors";import{Node as a,SyntaxKind as m}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{u as A,s as w}from"./ast-CjWtsS6S.mjs";const h="agents.ts",E=i=>{const t=i.getSymbol();if(!t)return i.getText()==="defineAgent";for(const n of t.getDeclarations())if(a.isImportSpecifier(n))return n.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/agent"?!1:n.getNameNode().getText()==="defineAgent";return!1},P=w("agent"),I=(i,t,n)=>{if(i.getKind()===m.TrueKeyword)return!0;if(i.getKind()===m.FalseKeyword)return!1;throw g(i,`agent "${t}": \`${n}\` must be a static boolean literal — it is deploy configuration codegen writes into the ctx.agents wiring spec`)},T=(i,t)=>{const n=i.getArguments()[0];if(!n||!a.isObjectLiteralExpression(n))throw g(i,`agent "${t}": defineAgent must be passed an inline object literal`);const o={bindingName:b(t),className:f(t),exportName:t,name:d(t)},e=n.getProperty("name");e&&a.isPropertyAssignment(e)&&(o.name=P(e.getInitializerOrThrow(),t,"name"));const r=n.getProperty("publicRun");r&&a.isPropertyAssignment(r)&&I(r.getInitializerOrThrow(),t,"publicRun")&&(o.publicRun=!0);const s=n.getProperty("voice");if(s&&a.isPropertyAssignment(s)){const c=s.getInitializerOrThrow();if(!a.isObjectLiteralExpression(c))throw g(c,`agent "${t}": \`voice\` must be an inline object literal — its presence tells codegen to emit the voice-session Durable Object`);o.voice=!0,o.voiceBindingName=N(t),o.voiceClassName=y(t)}return n.getProperty("onEmail")&&(o.onEmail=!0),o},v=i=>{const t=[];for(const n of i.getVariableDeclarations()){if(!n.isExported())continue;const o=A(n.getInitializer());if(!o)continue;const e=o.getExpression();if(!a.isIdentifier(e)||!E(e))continue;const r=n.getNameNode();if(!a.isIdentifier(r))throw g(r,"defineAgent exports must be plain named exports (no destructuring)");t.push(T(o,r.getText()))}return t},D=i=>{const t=new Map,n=new Map,o=new Map;for(const e of i){const r=t.get(e.name);if(r!==void 0)throw new l("DUPLICATE_AGENT_NAME",`Duplicate agent name "${e.name}": produced by both "${r}" and "${e.exportName}". Deployed agent names must be unique across the project.`,{status:500});t.set(e.name,e.exportName);const s=n.get(e.bindingName);if(s!==void 0)throw new l("DUPLICATE_AGENT_BINDING",`Duplicate agent binding "${e.bindingName}": produced by both "${s}" and "${e.exportName}". Agent export names must yield unique binding names.`,{status:500});n.set(e.bindingName,e.exportName);const c=o.get(e.className);if(c!==void 0)throw new l("DUPLICATE_AGENT_CLASS",`Duplicate agent class "${e.className}": produced by both "${c}" and "${e.exportName}". Agent export names must yield unique generated class names.`,{status:500});o.set(e.className,e.exportName)}},j=(i,t)=>{const n=p(t,h);if(!u(n))return[];const o=i.getSourceFile(n)??i.addSourceFileAtPath(n),e=v(o);return e.sort((r,s)=>r.exportName.localeCompare(s.exportName)),D(e),e};export{h as AGENTS_FILENAME,j as discoverAgents};
1
+ import{existsSync as u}from"node:fs";import{join as p}from"node:path";import{agentDefaultName as d,agentClassName as f,agentBindingName as b,voiceBindingName as N,voiceClassName as y}from"@lunora/agent/naming";import{LunoraError as l}from"@lunora/errors";import{Node as a,SyntaxKind as m}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{u as A,s as w}from"./ast-BYoSZlae.mjs";const h="agents.ts",E=i=>{const t=i.getSymbol();if(!t)return i.getText()==="defineAgent";for(const n of t.getDeclarations())if(a.isImportSpecifier(n))return n.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/agent"?!1:n.getNameNode().getText()==="defineAgent";return!1},P=w("agent"),I=(i,t,n)=>{if(i.getKind()===m.TrueKeyword)return!0;if(i.getKind()===m.FalseKeyword)return!1;throw g(i,`agent "${t}": \`${n}\` must be a static boolean literal — it is deploy configuration codegen writes into the ctx.agents wiring spec`)},T=(i,t)=>{const n=i.getArguments()[0];if(!n||!a.isObjectLiteralExpression(n))throw g(i,`agent "${t}": defineAgent must be passed an inline object literal`);const o={bindingName:b(t),className:f(t),exportName:t,name:d(t)},e=n.getProperty("name");e&&a.isPropertyAssignment(e)&&(o.name=P(e.getInitializerOrThrow(),t,"name"));const r=n.getProperty("publicRun");r&&a.isPropertyAssignment(r)&&I(r.getInitializerOrThrow(),t,"publicRun")&&(o.publicRun=!0);const s=n.getProperty("voice");if(s&&a.isPropertyAssignment(s)){const c=s.getInitializerOrThrow();if(!a.isObjectLiteralExpression(c))throw g(c,`agent "${t}": \`voice\` must be an inline object literal — its presence tells codegen to emit the voice-session Durable Object`);o.voice=!0,o.voiceBindingName=N(t),o.voiceClassName=y(t)}return n.getProperty("onEmail")&&(o.onEmail=!0),o},v=i=>{const t=[];for(const n of i.getVariableDeclarations()){if(!n.isExported())continue;const o=A(n.getInitializer());if(!o)continue;const e=o.getExpression();if(!a.isIdentifier(e)||!E(e))continue;const r=n.getNameNode();if(!a.isIdentifier(r))throw g(r,"defineAgent exports must be plain named exports (no destructuring)");t.push(T(o,r.getText()))}return t},D=i=>{const t=new Map,n=new Map,o=new Map;for(const e of i){const r=t.get(e.name);if(r!==void 0)throw new l("DUPLICATE_AGENT_NAME",`Duplicate agent name "${e.name}": produced by both "${r}" and "${e.exportName}". Deployed agent names must be unique across the project.`,{status:500});t.set(e.name,e.exportName);const s=n.get(e.bindingName);if(s!==void 0)throw new l("DUPLICATE_AGENT_BINDING",`Duplicate agent binding "${e.bindingName}": produced by both "${s}" and "${e.exportName}". Agent export names must yield unique binding names.`,{status:500});n.set(e.bindingName,e.exportName);const c=o.get(e.className);if(c!==void 0)throw new l("DUPLICATE_AGENT_CLASS",`Duplicate agent class "${e.className}": produced by both "${c}" and "${e.exportName}". Agent export names must yield unique generated class names.`,{status:500});o.set(e.className,e.exportName)}},j=(i,t)=>{const n=p(t,h);if(!u(n))return[];const o=i.getSourceFile(n)??i.addSourceFileAtPath(n),e=v(o);return e.sort((r,s)=>r.exportName.localeCompare(s.exportName)),D(e),e};export{h as AGENTS_FILENAME,j as discoverAgents};
@@ -1 +1 @@
1
- import{existsSync as f}from"node:fs";import{join as d}from"node:path";import{containerClassName as b,containerBindingName as p,normalizeContainerImage as u}from"@lunora/container";import{SyntaxKind as y,Node as n}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as L}from"./ast-CjWtsS6S.mjs";const P="containers.ts",h=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineContainer";for(const i of t.getDeclarations())if(n.isImportSpecifier(i))return i.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:i.getNameNode().getText()==="defineContainer";return!1},g=L("container"),m=(e,t,i)=>{if(n.isNumericLiteral(e))return e.getLiteralValue();throw c(e,`container "${t}": \`${i}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},T=(e,t)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e))return u(e.getLiteralValue());if(n.isObjectLiteralExpression(e)){const i=e.getProperty("registry");if(i&&n.isPropertyAssignment(i)){const o=i.getInitializerOrThrow();return u({registry:g(o,t,"image.registry")})}const r=e.getProperty("build");if(r&&n.isPropertyAssignment(r)){const o=r.getInitializerOrThrow();return u({build:g(o,t,"image.build")})}}throw c(e,`container "${t}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},k=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getInitializerOrThrow();(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))&&(t[i.getName()]=r.getLiteralValue())}return Object.keys(t).length>0?t:void 0},I=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getName(),o=i.getInitializerOrThrow();n.isNumericLiteral(o)&&(r==="gracePeriodSeconds"||r==="stepPercentage")&&(t[r]=o.getLiteralValue())}return t.gracePeriodSeconds===void 0&&t.stepPercentage===void 0?void 0:t},w=e=>{if(n.isTrueLiteral(e))return!0;if(n.isFalseLiteral(e))return!1},S=e=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e))return e.getLiteralValue()},A=(e,t)=>{if(n.isStringLiteral(e))return e.getLiteralValue();if(n.isObjectLiteralExpression(e)){const i={};for(const r of e.getProperties()){if(!n.isPropertyAssignment(r))throw c(r,`container "${t}": \`instanceType\` must be an object of static number literals`);const o=r.getName();if(o!=="diskMb"&&o!=="memoryMib"&&o!=="vcpu")throw c(r,`container "${t}": unknown \`instanceType\` field "${o}" — expected vcpu, memoryMib, or diskMb`);i[o]=m(r.getInitializerOrThrow(),t,`instanceType.${o}`)}return i}throw c(e,`container "${t}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},v=(e,t)=>{const i=e.getArguments()[0];if(!i||!n.isObjectLiteralExpression(i))throw c(e,`container "${t}": defineContainer must be passed an inline object literal`);const r={bindingName:p(t),className:b(t),exportName:t,image:{buildContext:".",dockerfilePath:"./Dockerfile",kind:"dockerfile"}};let o=!1;for(const a of i.getProperties()){if(!n.isPropertyAssignment(a))continue;const l=a.getName(),s=a.getInitializerOrThrow();switch(l){case"buildArgs":{r.buildArgs=k(s);break}case"enableInternet":{r.enableInternet=w(s);break}case"image":{r.image=T(s,t),o=!0;break}case"instanceType":{r.instanceType=A(s,t);break}case"maxInstances":{r.maxInstances=m(s,t,"maxInstances");break}case"name":{r.name=g(s,t,"name");break}case"rollout":{r.rollout=I(s);break}case"sleepAfter":{r.sleepAfter=S(s);break}}}if(!o)throw c(i,`container "${t}": defineContainer requires a static \`image\` property`);return r},C=e=>{const t=[];for(const i of e.getVariableDeclarations()){if(!i.isExported())continue;const r=i.getInitializer();if(r?.getKind()!==y.CallExpression)continue;const o=r,a=o.getExpression();if(!n.isIdentifier(a)||!h(a))continue;const l=i.getNameNode();if(!n.isIdentifier(l))throw c(l,"defineContainer exports must be plain named exports (no destructuring)");t.push(v(o,l.getText()))}return t},F=(e,t)=>{const i=d(t,P);if(!f(i))return[];const r=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=C(r);return o.sort((a,l)=>a.exportName.localeCompare(l.exportName)),o};export{P as CONTAINERS_FILENAME,F as discoverContainers};
1
+ import{existsSync as f}from"node:fs";import{join as d}from"node:path";import{containerClassName as b,containerBindingName as p,normalizeContainerImage as u}from"@lunora/container";import{SyntaxKind as y,Node as n}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as L}from"./ast-BYoSZlae.mjs";const P="containers.ts",h=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineContainer";for(const i of t.getDeclarations())if(n.isImportSpecifier(i))return i.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:i.getNameNode().getText()==="defineContainer";return!1},g=L("container"),m=(e,t,i)=>{if(n.isNumericLiteral(e))return e.getLiteralValue();throw c(e,`container "${t}": \`${i}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},T=(e,t)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e))return u(e.getLiteralValue());if(n.isObjectLiteralExpression(e)){const i=e.getProperty("registry");if(i&&n.isPropertyAssignment(i)){const o=i.getInitializerOrThrow();return u({registry:g(o,t,"image.registry")})}const r=e.getProperty("build");if(r&&n.isPropertyAssignment(r)){const o=r.getInitializerOrThrow();return u({build:g(o,t,"image.build")})}}throw c(e,`container "${t}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},k=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getInitializerOrThrow();(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))&&(t[i.getName()]=r.getLiteralValue())}return Object.keys(t).length>0?t:void 0},I=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getName(),o=i.getInitializerOrThrow();n.isNumericLiteral(o)&&(r==="gracePeriodSeconds"||r==="stepPercentage")&&(t[r]=o.getLiteralValue())}return t.gracePeriodSeconds===void 0&&t.stepPercentage===void 0?void 0:t},w=e=>{if(n.isTrueLiteral(e))return!0;if(n.isFalseLiteral(e))return!1},S=e=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e))return e.getLiteralValue()},A=(e,t)=>{if(n.isStringLiteral(e))return e.getLiteralValue();if(n.isObjectLiteralExpression(e)){const i={};for(const r of e.getProperties()){if(!n.isPropertyAssignment(r))throw c(r,`container "${t}": \`instanceType\` must be an object of static number literals`);const o=r.getName();if(o!=="diskMb"&&o!=="memoryMib"&&o!=="vcpu")throw c(r,`container "${t}": unknown \`instanceType\` field "${o}" — expected vcpu, memoryMib, or diskMb`);i[o]=m(r.getInitializerOrThrow(),t,`instanceType.${o}`)}return i}throw c(e,`container "${t}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},v=(e,t)=>{const i=e.getArguments()[0];if(!i||!n.isObjectLiteralExpression(i))throw c(e,`container "${t}": defineContainer must be passed an inline object literal`);const r={bindingName:p(t),className:b(t),exportName:t,image:{buildContext:".",dockerfilePath:"./Dockerfile",kind:"dockerfile"}};let o=!1;for(const a of i.getProperties()){if(!n.isPropertyAssignment(a))continue;const l=a.getName(),s=a.getInitializerOrThrow();switch(l){case"buildArgs":{r.buildArgs=k(s);break}case"enableInternet":{r.enableInternet=w(s);break}case"image":{r.image=T(s,t),o=!0;break}case"instanceType":{r.instanceType=A(s,t);break}case"maxInstances":{r.maxInstances=m(s,t,"maxInstances");break}case"name":{r.name=g(s,t,"name");break}case"rollout":{r.rollout=I(s);break}case"sleepAfter":{r.sleepAfter=S(s);break}}}if(!o)throw c(i,`container "${t}": defineContainer requires a static \`image\` property`);return r},C=e=>{const t=[];for(const i of e.getVariableDeclarations()){if(!i.isExported())continue;const r=i.getInitializer();if(r?.getKind()!==y.CallExpression)continue;const o=r,a=o.getExpression();if(!n.isIdentifier(a)||!h(a))continue;const l=i.getNameNode();if(!n.isIdentifier(l))throw c(l,"defineContainer exports must be plain named exports (no destructuring)");t.push(v(o,l.getText()))}return t},F=(e,t)=>{const i=d(t,P);if(!f(i))return[];const r=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=C(r);return o.sort((a,l)=>a.exportName.localeCompare(l.exportName)),o};export{P as CONTAINERS_FILENAME,F as discoverContainers};
@@ -0,0 +1 @@
1
+ import{existsSync as c,readFileSync as p}from"node:fs";import{join as m}from"node:path";import{NODE_CAPABILITIES as f,CLOUDFLARE_CAPABILITIES as h}from"@lunora/platform";import{parse as g}from"jsonc-parser";const v="cloudflare",y="lunora.json",b=r=>{const e=m(r,y);if(!c(e))return;let a;try{a=p(e,"utf8")}catch{return}const s=[],n=g(a,s,{allowTrailingComma:!0});if(s.length>0||n===null||typeof n!="object")return;const{target:o}=n;return typeof o=="string"&&o.length>0?o:void 0},E=(r,e)=>e??b(r)??v,i={cloudflare:h,node:f},L=()=>Object.keys(i).toSorted((r,e)=>r.localeCompare(e)),T={access:null,ai:"ai",analytics:"analytics",browser:"browser",container:"containers",flags:null,hyperdrive:"hyperdrive",images:"images",kv:"keyValueStore",mail:"mail",notify:null,payments:null,pipelines:"pipelines",r2sql:null,scheduler:"scheduler",storage:"objectStorage",vectors:"vectorStore",workflows:"workflows",x402:null},_=["commitOrderedTables","crossShardFanout","durableStreams","globalTables","queues","secrets"],d={commitOrderedTables:"commit-ordered tables (`.commitOrdered()`)",crossShardFanout:"cross-shard fan-out queries (a `.shardBy(...)` schema)",durableStreams:"durable streams (`.stream(handler, { durable: true })`)",globalTables:"global tables (`.global()`)",queues:"queues (`defineQueue`)",secrets:"the secrets store (`ctx.secrets`)"},$=(r,e,a,s={})=>{const n={...r},o=[];for(const[t,l]of Object.entries(T)){if(l===null||!r[t])continue;const u=e.features[l]?.level;u==="unsupported"?(n[t]=!1,o.push({feature:t,level:"error",message:`${e.name} does not support "${t}" (ctx.${t}). Its surface was omitted from the generated types.`,name:"platform_unsupported_feature",remediation:`Remove the ctx.${t} usage, or deploy to a target whose capability matrix marks "${l}" as native or emulated.`,target:a})):u===void 0&&(n[t]=!1,o.push({feature:t,level:"error",message:`${e.name}'s capability matrix does not declare a support level for "${t}" (ctx.${t}). Treated as unsupported and its surface was omitted from the generated types.`,name:"platform_undeclared_feature",remediation:`Rate "${l}" in the ${e.name} capability matrix as "native", "emulated", or "unsupported" — an undeclared feature fails closed rather than shipping a surface the host may not provide.`,target:a}))}for(const t of _){if(s[t]!==!0)continue;const l=e.features[t]?.level;l==="unsupported"?o.push({level:"error",message:`${e.name} does not support ${d[t]}, which this app declares.`,name:"platform_unsupported_feature",remediation:`Remove the declaration, or deploy to a target whose capability matrix marks "${t}" as native or emulated.`,target:a}):l===void 0&&o.push({level:"error",message:`${e.name}'s capability matrix does not declare a support level for ${d[t]}, which this app declares. Treated as unsupported.`,name:"platform_undeclared_feature",remediation:`Rate "${t}" in the ${e.name} capability matrix as "native", "emulated", or "unsupported" — an undeclared feature fails closed rather than letting the app deploy onto a primitive the host may not provide.`,target:a})}return{diagnostics:o,usage:n}},O=(r,e,a={})=>{const s=i[e];return s===void 0?{diagnostics:[{level:"error",message:`Unknown deploy target "${e}" — no capability matrix is registered for it. Codegen emitted the full Cloudflare surface un-gated.`,name:"platform_unknown_target",remediation:`Use a registered target (${Object.keys(i).join(", ")}) or install the target's @lunora/platform-${e} package.`,target:e}],usage:{...r}}:$(r,s,e,a)};export{T as CAPABILITY_TO_FEATURE,v as DEFAULT_TARGET,y as PROJECT_CONFIG_FILE,$ as gateAgainstMatrix,O as gatePlatformFeatures,L as platformMatrixIds,b as readProjectTarget,E as resolveCodegenTarget};
@@ -0,0 +1 @@
1
+ import{existsSync as l}from"node:fs";import{join as p}from"node:path";import{Node as i}from"ts-morph";import{d as g,p as f}from"./ast-BYoSZlae.mjs";const d="flags.ts",c=new Set(["@lunora/flags/providers/flagship","lunorash/flags/flagship"]),u=e=>{const t=e.getSymbol();if(!t)return e.getText()==="flagshipProvider";for(const r of t.getDeclarations())if(i.isImportSpecifier(r))return c.has(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="flagshipProvider":!1;return!1},m=(e,t)=>{const r=e.getProperty(t);if(!r||!i.isPropertyAssignment(r))return;const o=r.getInitializerOrThrow();if(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))return o.getLiteralValue()},v=e=>{const t=e.getArguments()[0];if(t&&i.isObjectLiteralExpression(t)){const r=m(t,"binding");if(r!==void 0&&r.length>0)return{bindingName:r,mode:"binding",provider:"flagship"}}return{mode:"http",provider:"flagship"}},h=e=>f(e.getArguments()[0],"provider"),P=(e,t)=>{const r=p(t,d);if(!l(r))return;const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=g(o);if(!n||!i.isCallExpression(n))return{provider:"custom"};const s=h(n);if(s&&i.isCallExpression(s)){const a=s.getExpression();if(i.isIdentifier(a)&&u(a))return v(s)}return{provider:"custom"}};export{d as FLAGS_FILENAME,P as discoverFlags};
@@ -1 +1 @@
1
- import"./SCHEMA_SNAPSHOT_VERSION-CTWRkAF5.mjs";import{G as t,U as m,n as r,e as o,a as n,b as l,c as A,d as E,f as S,g,h as C,o as c,p as d,i as p,j as u,k as D,l as f,m as h}from"./emit-Bo3kao_A.mjs";import"./paths-C-9fwEgQ.mjs";export{t as GENERATED_HEADER,m as UMBRELLA_BASE_PACKAGES,r as buildStorageColumns,o as emitAgents,n as emitApi,l as emitCollections,A as emitContainers,E as emitCrons,S as emitDataModel,g as emitDrizzleSchema,C as emitFunctions,c as emitQueues,d as emitSeed,p as emitServer,u as emitShard,D as emitVectors,f as emitWorkflows,h as emitWranglerCronTriggers};
1
+ import"./SCHEMA_SNAPSHOT_VERSION-CTWRkAF5.mjs";import{G as t,U as m,n as r,e as o,a as n,b as l,c as A,d as E,f as S,g,h as C,o as c,p as d,i as p,j as u,k as D,l as f,m as h}from"./emit-BcAkLUfn.mjs";import"./paths-C-9fwEgQ.mjs";export{t as GENERATED_HEADER,m as UMBRELLA_BASE_PACKAGES,r as buildStorageColumns,o as emitAgents,n as emitApi,l as emitCollections,A as emitContainers,E as emitCrons,S as emitDataModel,g as emitDrizzleSchema,C as emitFunctions,c as emitQueues,d as emitSeed,p as emitServer,u as emitShard,D as emitVectors,f as emitWorkflows,h as emitWranglerCronTriggers};
@@ -1 +1 @@
1
- import{existsSync as m}from"node:fs";import{join as x}from"node:path";import{SyntaxKind as d,Node as c}from"ts-morph";import{l,a as g,d as P,h as E}from"./ast-CjWtsS6S.mjs";import{c as S}from"./classify-procedure-call-AKeIK05y.mjs";const y="notify.ts",v=new Set(["chat","inApp","send","webhook"]),p=new Set(["broadcast","send"]),N=e=>{const t=e.getInitializer();if(!t||!c.isCallExpression(t))return;const s=S(t);if(!s)return;const o=E(t,s.receiver);return o?{exportName:e.getName(),handler:o,kind:s.kind}:void 0},h=e=>{const t=[];for(const s of e.getVariableStatements())if(s.isExported())for(const o of s.getDeclarations()){const r=N(o);r&&t.push(r)}return t},f=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),s=e.getExpression();if((t==="notify"||t==="push")&&c.isIdentifier(s)&&s.getText()==="ctx")return t;if(t==="push"&&f(s)==="notify")return"push"},F=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),s=f(e.getExpression());if(s==="notify"&&v.has(t))return`ctx.notify.${t}`;if(s==="push"&&p.has(t))return`ctx.push.${t}`},A=e=>c.isPropertyAccessExpression(e)?f(e.getExpression())==="push"&&p.has(e.getName()):!1,T=(e,t)=>{const s=[];for(const o of l(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o),a=g(t,o);for(const n of h(r))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(d.PropertyAccessExpression)){const u=F(i);u!==void 0&&s.push({callee:u,exportName:n.exportName,file:a,kind:n.kind,line:i.getStartLineNumber()})}}return s},O=(e,t)=>{for(const s of l(t)){const o=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of h(o))for(const a of r.handler.getDescendantsOfKind(d.PropertyAccessExpression))if(A(a))return!0}return!1},_=(e,t)=>{const s=x(t,y);if(!m(s))return;const o=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=P(o);let a=!1,n=!1;if(r&&c.isCallExpression(r)){const i=r.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(a=i.getProperty("webPush")!==void 0,n=i.getProperty("fcm")!==void 0)}return{hasFcm:n,hasWebPush:a,usesPush:O(e,t)}};export{y as NOTIFY_FILENAME,T as discoverNotifyCalls,_ as discoverNotifyConfig};
1
+ import{existsSync as m}from"node:fs";import{join as x}from"node:path";import{SyntaxKind as d,Node as c}from"ts-morph";import{l,a as g,d as P,h as E}from"./ast-BYoSZlae.mjs";import{c as S}from"./classify-procedure-call-Ib2EMtFH.mjs";const y="notify.ts",v=new Set(["chat","inApp","send","webhook"]),p=new Set(["broadcast","send"]),N=e=>{const t=e.getInitializer();if(!t||!c.isCallExpression(t))return;const s=S(t);if(!s)return;const o=E(t,s.receiver);return o?{exportName:e.getName(),handler:o,kind:s.kind}:void 0},h=e=>{const t=[];for(const s of e.getVariableStatements())if(s.isExported())for(const o of s.getDeclarations()){const r=N(o);r&&t.push(r)}return t},f=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),s=e.getExpression();if((t==="notify"||t==="push")&&c.isIdentifier(s)&&s.getText()==="ctx")return t;if(t==="push"&&f(s)==="notify")return"push"},F=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),s=f(e.getExpression());if(s==="notify"&&v.has(t))return`ctx.notify.${t}`;if(s==="push"&&p.has(t))return`ctx.push.${t}`},A=e=>c.isPropertyAccessExpression(e)?f(e.getExpression())==="push"&&p.has(e.getName()):!1,T=(e,t)=>{const s=[];for(const o of l(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o),a=g(t,o);for(const n of h(r))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(d.PropertyAccessExpression)){const u=F(i);u!==void 0&&s.push({callee:u,exportName:n.exportName,file:a,kind:n.kind,line:i.getStartLineNumber()})}}return s},O=(e,t)=>{for(const s of l(t)){const o=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const r of h(o))for(const a of r.handler.getDescendantsOfKind(d.PropertyAccessExpression))if(A(a))return!0}return!1},_=(e,t)=>{const s=x(t,y);if(!m(s))return;const o=e.getSourceFile(s)??e.addSourceFileAtPath(s),r=P(o);let a=!1,n=!1;if(r&&c.isCallExpression(r)){const i=r.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(a=i.getProperty("webPush")!==void 0,n=i.getProperty("fcm")!==void 0)}return{hasFcm:n,hasWebPush:a,usesPush:O(e,t)}};export{y as NOTIFY_FILENAME,T as discoverNotifyCalls,_ as discoverNotifyConfig};
@@ -1,3 +1,3 @@
1
- import{G as c}from"./emit-Bo3kao_A.mjs";import{s as u}from"./paths-C-9fwEgQ.mjs";import{validatorIrToJsonSchema as m,objectSchema as p,LUNORA_ERROR_CODES as i}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const l="1.3.2",d={description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."},R=e=>{const n=u(e.filePath),o=`${n}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${o}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${o}", "args": { … } }\`).`,errors:i.map((r,s)=>({code:-32e3-s,data:{code:r},message:r})),name:o,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:p(e.args)}],result:{name:"result",schema:e.output?m(e.output):d},summary:`${e.kind}: ${o}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:n}]}},g=e=>{const n=e.version??"0.0.0",r=e.functions.filter(t=>t.visibility!=="internal"&&t.kind!=="stream").map(t=>R(t)).toSorted((t,a)=>t.name.localeCompare(a.name));return{info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora RPC",version:n},methods:r,openrpc:l}},S=e=>`${JSON.stringify(g(e),void 0,2)}
1
+ import{G as c}from"./emit-BcAkLUfn.mjs";import{s as u}from"./paths-C-9fwEgQ.mjs";import{validatorIrToJsonSchema as m,objectSchema as p,LUNORA_ERROR_CODES as i}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const l="1.3.2",d={description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."},R=e=>{const n=u(e.filePath),o=`${n}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${o}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${o}", "args": { … } }\`).`,errors:i.map((r,s)=>({code:-32e3-s,data:{code:r},message:r})),name:o,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:p(e.args)}],result:{name:"result",schema:e.output?m(e.output):d},summary:`${e.kind}: ${o}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:n}]}},g=e=>{const n=e.version??"0.0.0",r=e.functions.filter(t=>t.visibility!=="internal"&&t.kind!=="stream").map(t=>R(t)).toSorted((t,a)=>t.name.localeCompare(a.name));return{info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora RPC",version:n},methods:r,openrpc:l}},S=e=>`${JSON.stringify(g(e),void 0,2)}
2
2
  `,v=e=>`${c}export const openRpcSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
3
3
  `;export{l as OPENRPC_VERSION,g as buildOpenRpcDocument,S as emitOpenRpc,v as emitOpenRpcModule};
@@ -1 +1 @@
1
- import{existsSync as g}from"node:fs";import{join as l}from"node:path";import{LunoraError as d}from"@lunora/errors";import{queueDefaultName as p,queueBindingName as f}from"@lunora/queue";import{SyntaxKind as y,Node as u}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as h}from"./ast-CjWtsS6S.mjs";const q="queues.ts",b=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineQueue";for(const e of t.getDeclarations())if(u.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue"?!1:e.getNameNode().getText()==="defineQueue";return!1},c=h("queue"),N=(r,t,e)=>{if(u.isNumericLiteral(r))return r.getLiteralValue();throw a(r,`queue "${t}": \`${e}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},w=(r,t)=>{const e=r.getProperty("name");if(!e||!u.isPropertyAssignment(e))return;const n=c(e.getInitializerOrThrow(),t,"name");if(n.length===0)throw a(e,`queue "${t}": \`name\` must be a non-empty string when provided`);return n},P=(r,t)=>{const e=r.getArguments()[0];if(!e||!u.isObjectLiteralExpression(e))throw a(r,`queue "${t}": defineQueue must be passed an inline object literal`);const n={bindingName:f(t),exportName:t,mode:"push",name:w(e,t)??p(t),tuning:{}},o=e.getProperty("mode");if(o&&u.isPropertyAssignment(o)){const i=c(o.getInitializerOrThrow(),t,"mode");if(i!=="push"&&i!=="pull")throw a(o,`queue "${t}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(i)})`);n.mode=i}const s=e.getProperty("deadLetterQueue");s&&u.isPropertyAssignment(s)&&(n.tuning.deadLetterQueue=c(s.getInitializerOrThrow(),t,"deadLetterQueue"));for(const i of["maxBatchSize","maxBatchTimeout","maxRetries","retryDelay"]){const m=e.getProperty(i);m&&u.isPropertyAssignment(m)&&(n.tuning[i]=N(m.getInitializerOrThrow(),t,i))}return n},E=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const n=e.getInitializer();if(n?.getKind()!==y.CallExpression)continue;const o=n,s=o.getExpression();if(!u.isIdentifier(s)||!b(s))continue;const i=e.getNameNode();if(!u.isIdentifier(i))throw a(i,"defineQueue exports must be plain named exports (no destructuring)");t.push(P(o,i.getText()))}return t},I=r=>{const t=new Map,e=new Map;for(const n of r){const o=t.get(n.name);if(o!==void 0)throw new d("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${n.name}": produced by both "${o}" and "${n.exportName}". Deployed queue names must be unique across the project.`,{status:500});t.set(n.name,n.exportName);const s=e.get(n.bindingName);if(s!==void 0)throw new d("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${n.bindingName}": produced by both "${s}" and "${n.exportName}". Queue export names must yield unique binding names.`,{status:500});e.set(n.bindingName,n.exportName)}},T=(r,t)=>{const e=l(t,q);if(!g(e))return[];const n=r.getSourceFile(e)??r.addSourceFileAtPath(e),o=E(n);return o.sort((s,i)=>s.exportName.localeCompare(i.exportName)),I(o),o};export{q as QUEUES_FILENAME,T as discoverQueues};
1
+ import{existsSync as g}from"node:fs";import{join as l}from"node:path";import{LunoraError as d}from"@lunora/errors";import{queueDefaultName as p,queueBindingName as f}from"@lunora/queue";import{SyntaxKind as y,Node as u}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{s as h}from"./ast-BYoSZlae.mjs";const q="queues.ts",b=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineQueue";for(const e of t.getDeclarations())if(u.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue"?!1:e.getNameNode().getText()==="defineQueue";return!1},c=h("queue"),N=(r,t,e)=>{if(u.isNumericLiteral(r))return r.getLiteralValue();throw a(r,`queue "${t}": \`${e}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},w=(r,t)=>{const e=r.getProperty("name");if(!e||!u.isPropertyAssignment(e))return;const n=c(e.getInitializerOrThrow(),t,"name");if(n.length===0)throw a(e,`queue "${t}": \`name\` must be a non-empty string when provided`);return n},P=(r,t)=>{const e=r.getArguments()[0];if(!e||!u.isObjectLiteralExpression(e))throw a(r,`queue "${t}": defineQueue must be passed an inline object literal`);const n={bindingName:f(t),exportName:t,mode:"push",name:w(e,t)??p(t),tuning:{}},o=e.getProperty("mode");if(o&&u.isPropertyAssignment(o)){const i=c(o.getInitializerOrThrow(),t,"mode");if(i!=="push"&&i!=="pull")throw a(o,`queue "${t}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(i)})`);n.mode=i}const s=e.getProperty("deadLetterQueue");s&&u.isPropertyAssignment(s)&&(n.tuning.deadLetterQueue=c(s.getInitializerOrThrow(),t,"deadLetterQueue"));for(const i of["maxBatchSize","maxBatchTimeout","maxRetries","retryDelay"]){const m=e.getProperty(i);m&&u.isPropertyAssignment(m)&&(n.tuning[i]=N(m.getInitializerOrThrow(),t,i))}return n},E=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const n=e.getInitializer();if(n?.getKind()!==y.CallExpression)continue;const o=n,s=o.getExpression();if(!u.isIdentifier(s)||!b(s))continue;const i=e.getNameNode();if(!u.isIdentifier(i))throw a(i,"defineQueue exports must be plain named exports (no destructuring)");t.push(P(o,i.getText()))}return t},I=r=>{const t=new Map,e=new Map;for(const n of r){const o=t.get(n.name);if(o!==void 0)throw new d("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${n.name}": produced by both "${o}" and "${n.exportName}". Deployed queue names must be unique across the project.`,{status:500});t.set(n.name,n.exportName);const s=e.get(n.bindingName);if(s!==void 0)throw new d("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${n.bindingName}": produced by both "${s}" and "${n.exportName}". Queue export names must yield unique binding names.`,{status:500});e.set(n.bindingName,n.exportName)}},T=(r,t)=>{const e=l(t,q);if(!g(e))return[];const n=r.getSourceFile(e)??r.addSourceFileAtPath(e),o=E(n);return o.sort((s,i)=>s.exportName.localeCompare(i.exportName)),I(o),o};export{q as QUEUES_FILENAME,T as discoverQueues};
@@ -0,0 +1,9 @@
1
+ import{existsSync as b,mkdirSync as ns,readFileSync as At,writeFileSync as rs,rmSync as is}from"node:fs";import{join as f,dirname as pe}from"node:path";import{performance as ge}from"node:perf_hooks";import{runAdvisor as os}from"@lunora/advisor";import{LunoraError as L}from"@lunora/errors";import{SyntaxKind as l,Node as o,Project as Xe}from"ts-morph";import{serializeSchemaSnapshot as as}from"./SCHEMA_SNAPSHOT_VERSION-CTWRkAF5.mjs";import{toAdvisorContext as cs}from"./formatAdvisories-CkEu1eye.mjs";import{s as ls}from"./paths-C-9fwEgQ.mjs";import{discoverAgents as us}from"./AGENTS_FILENAME-B1Abt3Gl.mjs";import{discoverContainers as ds}from"./CONTAINERS_FILENAME-CtcysaKS.mjs";import{diagnosticAt as ne}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as re}from"./module-specifiers-WF8iAydP.mjs";import{C as me,i as fs,f as ps,n as gs,j as ms,b as hs,c as xs,l as Es,e as vs,o as Ss,d as As,k as ys,g as Ns,p as bs,m as Ps,a as Is,h as ws}from"./emit-BcAkLUfn.mjs";import{l as g,a as v,f as P,p as N,g as yt,j as Nt,k as ve,h as Ts,i as D,b as Ze,r as bt,e as Cs}from"./ast-BYoSZlae.mjs";import Fs from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as Os}from"./QUEUES_FILENAME-C-pzLGy4.mjs";import{discoverSandboxUsage as Rs}from"./discoverSandboxUsage-CJhnKA0_.mjs";import Ls from"./discoverStorageRulesMetadata-C7XmORWp.mjs";import{discoverWorkflows as Ds}from"./WORKFLOWS_FILENAME-BfvqsG9Z.mjs";import{gatePlatformFeatures as ks,resolveCodegenTarget as Ms}from"./DEFAULT_TARGET-BvzxeWRZ.mjs";import{i as F,a as K,e as E,r as Ks,b as _s,s as ie,c as zs,f as Us,d as Bs}from"./queries-Ddvo5dCs.mjs";import{a as A,c as _,d as Pt,e as qs}from"./classify-procedure-call-Ib2EMtFH.mjs";import $s from"./discoverAuthApiCalls-DoNQSgso.mjs";import js from"./discoverCrons-DCxl4hty.mjs";import Je from"./discoverFunctions-C29Tvxas.mjs";import{i as Vs,r as Ws,e as Hs}from"./unwrap-handler-return-CmIWbykC.mjs";import et from"./discoverHttpRoutes-CFIXlUy4.mjs";import Gs from"./discoverHyperdriveCalls-DTq4PKT5.mjs";import Ys from"./discoverInserts-qU5F4W4g.mjs";import{m as ye,a as Z,s as It,d as Qs}from"./index-xGhyK9J_.mjs";import{e as wt}from"./exported-procedure-chains-M40rbSYM.mjs";import Xs from"./discoverMigrations-BFkJQ8Sy.mjs";import{MUTATORS_FILENAME as Zs,isDefineMutatorCallee as Js,discoverMutators as tt}from"./MUTATORS_FILENAME-BKSzaCkq.mjs";import en from"./discoverNondeterministicCalls-B-NNzzPW.mjs";import{discoverNotifyConfig as tn,discoverNotifyCalls as sn}from"./NOTIFY_FILENAME-CKO5gtGe.mjs";import nn from"./discoverR2sqlCalls-C2GtrFnl.mjs";import rn from"./discoverRlsProcedures-fAhxiIyD.mjs";import on from"./discoverRlsMetadata-BKcUnSNr.mjs";import an from"./discoverSchema-CubSTjtY.mjs";import{secretKindOf as cn,redact as ln,isHeuristicSecretKind as un,isSecretishName as dn}from"./redact-Cy14LEnc.mjs";import{discoverShapes as fn}from"./SHAPES_FILENAME-D3N7xcEk.mjs";import{emitApp as pn}from"./emitApp-DoR55vKV.mjs";import{buildOpenApiDocument as gn,emitOpenApiModule as mn}from"./buildOpenApiDocument-D40ZeYsu.mjs";import{buildOpenRpcDocument as hn,emitOpenRpcModule as xn}from"./OPENRPC_VERSION-CdKqq_QT.mjs";import{s as En}from"./parse-validator-Q58kladC.mjs";import{buildSchemaSnapshot as vn}from"./SchemaSnapshotParseError-qXCOA7dD.mjs";const Sn=e=>{const t=new Map;for(const s of e){const n=ls(s),i=t.get(n);if(i===void 0){t.set(n,s);continue}if(i!==s)throw new L("INTERNAL",`@lunora/codegen: "${i}" and "${s}" both map to the api namespace "${n}" — the generated api.ts would declare "${n}" twice and the dispatch key "${n}:<fn>" would be ambiguous. Rename one file so the two differ by more than a non-identifier character (\`-\`, \`.\`, \`/\` and \`_\` all sanitize to \`_\`).`,{status:500})}},An=e=>{const t=[],s=e.tables.filter(n=>n.shardMode==="global");return s.some(n=>n.globalBackend!=="hyperdrive")&&t.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),s.some(n=>n.globalBackend==="hyperdrive")&&t.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'}),e.vectorIndexes.length>0&&t.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/vectors.ts` import `@lunora/bindings/vectors`"}),t},yn=(e,t)=>{if(t===void 0)return;const s=An(e).filter(i=>!t.has(i.name));if(s.length===0)return;const n=s.map(i=>` - ${i.name} — ${i.reason}`).join(`
2
+ `);throw new L("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
3
+ ${n}
4
+
5
+ Install them with your package manager, then re-run codegen.`)},Nn="env.ts",bn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return re(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},Pn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&re(n.getModuleSpecifierValue())}return!1},In=e=>{if(o.isIdentifier(e))return bn(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&o.isIdentifier(t)&&Pn(t)}return!1},wn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!In(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw ne(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},Tn=(e,t)=>{const s=f(t,Nn);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=wn(n);if(i.length!==0){if(i.length>1)throw ne(n,`lunora/env.ts declares ${i.length.toString()} defineEnv() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Cn=e=>{const t=n=>o.isIdentifier(n)&&n.getText()==="ctx",s=new Set;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression))t(n.getExpression())&&s.add(n.getName());for(const n of e.getDescendantsOfKind(l.VariableDeclaration)){const i=n.getInitializer(),r=n.getNameNode();if(!(i===void 0||!t(i)||!o.isObjectBindingPattern(r)))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},Fn=(e,t)=>{const s=Object.fromEntries(me.map(n=>[n.key,!1]));for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(i.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Cn(i);for(const c of me)if(!s[c.key]){if(r.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(me.every(c=>s[c.key]))break}return s},Tt="identity.ts",On=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return re(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},Rn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&re(n.getModuleSpecifierValue())}return!1},Ln=e=>{if(o.isIdentifier(e))return On(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&o.isIdentifier(t)&&Rn(t)}return!1},Dn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Ln(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw ne(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},kn=(e,t)=>{const s=f(t,Tt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Dn(n);if(i.length!==0){if(i.length>1)throw ne(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Mn=e=>o.isObjectLiteralExpression(e)&&e.getProperties().some(t=>(o.isPropertyAssignment(t)||o.isShorthandPropertyAssignment(t))&&t.getName()==="durable"),Kn=(e,t)=>{const s={durableStreams:!1,secrets:!1};for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);if(s.secrets||(s.secrets=i.getDescendantsOfKind(l.PropertyAccessExpression).some(r=>r.getName()==="secrets"&&o.isIdentifier(r.getExpression())&&r.getExpression().getText()==="ctx")),s.durableStreams||(s.durableStreams=i.getDescendantsOfKind(l.CallExpression).some(r=>{const a=r.getExpression();return(o.isPropertyAccessExpression(a)?a.getName():a.getText())==="stream"&&r.getArguments().some(u=>Mn(u))})),s.durableStreams&&s.secrets)break}return s},_n=(e,t)=>{const s=new Map,n=new Map,i=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),i.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new L("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new L("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=i.get(r.className);if(u!==void 0)throw new L("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},zn=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:i}=e,r=kn(s,t),a=Tn(s,t),c=Ds(s,t),u=Os(s,t),d=us(s,t);_n(c,d);const x=ds(s,t),y=Ls(s,t),p=Kn(s,t),O=ks(Fn(s,t),Ms(n,e.target),{commitOrderedTables:i.tables.some(I=>I.commitOrdered===!0),crossShardFanout:i.tables.some(I=>typeof I.shardMode=="object"),durableStreams:p.durableStreams,globalTables:i.tables.some(I=>I.shardMode==="global"),queues:u.length>0,secrets:p.secrets}),S=O.usage,T=Rs(s,t),k=S.browser||T.usesSandboxBrowser,U=Fs(n),R=U??new Set,z=R.has("lunorash");yn(i,U);const B=b(f(t,"flags.ts")),W=b(f(t,"notify.ts"));return{agents:d,containers:x,dataModelContent:ps(i),declaredDependencies:U,dependencies:R,env:a,featureUsage:S,hasBrowser:k,hasFlags:B,hasNotify:W,identity:r,platformGate:O,queues:u,serverContent:fs({agents:d,containers:x,env:a,hasAccessFacade:S.access,hasAi:S.ai,hasAnalytics:S.analytics,hasBrowser:k,hasFlags:B,hasHyperdrive:S.hyperdrive,hasImages:S.images,hasKv:S.kv,hasNotify:W,hasPayments:S.payments,hasPipelines:S.pipelines,hasR2sql:S.r2sql,hasX402:S.x402,identity:r,queues:u,schema:i,storageRuleBuckets:y.rules.map(I=>I.bucket),useUmbrella:z,workflows:c}),storageRulesMetadata:y,usesSandbox:T.usesSandboxBrowser||T.usesSandboxContainer||T.usesSandboxFs,useUmbrella:z,workflows:c}},Ct=new Set(["delete","get","head","options","patch","post","put"]),Un=new Set(["handler","stream"]),Bn=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,st=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),qn=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Ct.has(t.getName()))return;const s=t.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!o.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},$n=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||Ct.has(n.getName()))break;s=n.getExpression()}return qn(s)},jn=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(st.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&st.has(s.getText()))return!0}return!1},Vn=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||!Un.has(n.getName()))return;const i=$n(s);if(!i||!Bn.test(i.path))return;const r=s.getArguments()[0],a=r!==void 0&&(o.isArrowFunction(r)||o.isFunctionExpression(r))&&jn(r);return{exportName:e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},Wn=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=Vn(i,t);r&&s.push(r)}return s},Hn=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Wn(i,v(t,n)))}return s},Gn=e=>!o.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Yn=(e,t)=>{if(!Gn(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!F(s)||K(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},Qn=(e,t)=>P(e,t,Yn),Xn=new Set(["generateText","streamText"]),Zn=new Set(["messages","prompt","system"]),Jn=[{methods:new Set(["delete","insert","insertManyUnsafe","patch","replace"]),prefixes:["context.db","ctx.db"]},{methods:new Set(["run","runAction","runMutation"]),prefixes:["context","ctx"]},{methods:new Set(["fetch"]),prefixes:["context","ctx"]},{methods:new Set(["queue","send"]),prefixes:["context.email","context.mail","ctx.email","ctx.mail"]}],er=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const i of Jn)if(i.methods.has(s)&&i.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},tr=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=er(t);if(s!==void 0)return s}},sr=e=>{const t=new Set,s=e.getFirstAncestor(r=>o.isArrowFunction(r)||o.isFunctionExpression(r)||o.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],i=n?.getNameNode();if(i===void 0||!o.isObjectBindingPattern(i))return t;for(const r of i.getElements()){const a=r.getPropertyNameNode()?.getText()??r.getName(),c=r.getNameNode();if(a==="args"&&o.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},nr=e=>{if(Ks(e))return!0;const t=sr(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},rr=e=>{for(const t of e.getProperties()){if(!o.isPropertyAssignment(t)||!Zn.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&nr(s))return!0}return!1},ir=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=A(n.getExpression());if(i===void 0||!Xn.has(i))continue;const[r]=n.getArguments();if(r===void 0||!o.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(A(c.getExpression())==="tool"&&(a=tr(c),a!==void 0))break;a!==void 0&&s.push({exportName:E(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:rr(r)})}return s},or=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ir(i,v(t,n)))}return s},ar=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return o.isIdentifier(t)&&t.getText()==="ctx"},cr=(e,t)=>{if(!ar(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!F(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},lr=(e,t)=>P(e,t,cr),Ft=e=>e.getProperties().some(t=>o.isSpreadAssignment(t)),ur=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!o.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer();return!n||!o.isObjectLiteralExpression(n)?{objects:[],opaque:!0}:{objects:[n],opaque:Ft(n)}},dr=e=>{const t=[];let s=!1,n=e;for(;o.isCallExpression(n);){const i=n.getExpression();if(!o.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const r=n.getArguments()[0];r&&o.isObjectLiteralExpression(r)?(t.push(r),s||=Ft(r)):s=!0}n=i.getExpression()}return{objects:t,opaque:s}},Ot=(e,t)=>t?dr(t):ur(e),fr=e=>e.flatMap(t=>t.getProperties().filter(s=>o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)).map(s=>s.getName())),pr=/\.check\(|\.meta\(|length|max/iu,gr=/\bv\.any\s*\(/u,mr=/\bv\.string\s*\(/u,hr=e=>gr.test(e),xr=e=>mr.test(e)&&!pr.test(e),Er=e=>{const t=[],s=[];for(const n of e)for(const i of n.getProperties()){if(!o.isPropertyAssignment(i))continue;const r=i.getInitializer();if(!r)continue;const a=r.getText(),c=i.getName();hr(a)?t.push(c):xr(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},vr=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=_(s);if(n?.visibility!=="public")return;const{objects:i}=Ot(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=Er(i);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Sr=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=vr(i,t);r&&s.push(r)}return s},Ar=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Sr(i,v(t,n)))}return s},he=e=>e?.getKind()===l.TrueKeyword,yr=e=>e?.getKind()===l.FalseKeyword,Nr=e=>e!==void 0&&o.isNumericLiteral(e)&&e.getLiteralValue()===0,br=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Pr=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isCallExpression(t)&&A(t.getExpression())==="scim"),Ir=e=>e!==void 0&&o.isCallExpression(e)&&br.has(A(e.getExpression())??""),wr=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isStringLiteral(t)&&t.getLiteralText()==="*"),Tr=e=>{const t=N(e,"advanced"),s=N(e,"emailAndPassword"),n=N(e,"session");return{analyzable:!0,disableCsrfCheck:he(N(t,"disableCSRFCheck")),emailPasswordEnabled:he(N(s,"enabled")),requireEmailVerification:he(N(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Pr(N(e,"plugins"))&&Ir(N(e,"database")),secureCookiesDisabled:yr(N(t,"useSecureCookies")),sessionFreshAgeZero:Nr(N(n,"freshAge")),trustedOriginsWildcard:wr(N(e,"trustedOrigins"))}},Cr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Fr=(e,t)=>{if(A(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&o.isObjectLiteralExpression(s)&&s.getProperties().some(r=>o.isSpreadAssignment(r)),i=s!==void 0&&o.isObjectLiteralExpression(s)&&!n?Tr(s):Cr();return{exportName:E(e),file:t,line:e.getStartLineNumber(),...i}},Or=(e,t)=>P(e,t,Fr),Rr=(e,t)=>{if(!o.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},Lr=(e,t,s)=>{const n=Rr(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!F(i)||K(i))&&!(s.requireUnmodifiedReach===!0&&!_s(i)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:n}},Dr=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression)){const r=Lr(i,t,s);r&&n.push(r)}return n},oe=(e,t,s)=>{const n=[];for(const i of g(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...Dr(r,v(t,i),s))}return n},kr=new Set(["content","pdf","scrape","screenshot"]),Mr=(e,t)=>oe(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:kr}),Kr=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),_r=new Set(["RateLimiter"]),zr=new Set(["extend"]),Rt=e=>{const t=[],s=[];let n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),i.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,presentKeys:t,trueKeys:s}},nt=e=>e&&o.isObjectLiteralExpression(e)?Rt(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Ur=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!o.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&o.isObjectLiteralExpression(n)?n:void 0},Br=e=>{if(o.isObjectLiteralExpression(e))return e;if(o.isParenthesizedExpression(e)){const t=e.getExpression();return o.isObjectLiteralExpression(t)?t:void 0}return o.isBlock(e)?Ur(e):void 0},qr=e=>{const t=e&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,s=t&&Br(t.getBody());return s?Rt(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},$r=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=A(n.getExpression());i!==void 0&&(Kr.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...nt(n.getArguments()[0])}):zr.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),...qr(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const i=A(n.getExpression());i===void 0||!_r.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...nt(n.getArguments()[0])})}return s},jr=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of yt(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);s.push(...$r(r,n))}return s},rt="ctx.containers.",Vr=e=>{if(!e.startsWith(rt))return!1;const t=e.slice(rt.length);return t.length>0&&!t.includes(".")},Wr=(e,t)=>oe(e,t,{argIndex:0,matchReceiver:Vr,methods:new Set(["get"])}),Hr=new Set(["allow","deny","setAllowed"]),Gr=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return!1;const s=t.getProperty("enableInternet");return s!==void 0&&o.isPropertyAssignment(s)&&o.isTrueLiteral(s.getInitializerOrThrow())},Yr=(e,t)=>{const s=e.getExpression();if(!(!o.isPropertyAccessExpression(s)||s.getName()!=="start"||!Gr(e)))return{detail:"enableInternet: true",exportName:E(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Qr=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||!Hr.has(s.getName()))return;const n=s.getExpression();if(!(!o.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:E(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},Xr=(e,t)=>Yr(e,t)??Qr(e,t),Zr=(e,t)=>P(e,t,Xr),Jr=new Set(["defineExportSink","r2Sink","webhookExportSink"]),ei=e=>{const t=e.getExpression();if(!o.isIdentifier(t))return;const s=t.getText();return Jr.has(s)?s:void 0},ti=e=>{const t=[],s=[];for(const n of e.getProperties()){if(o.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(o.isPropertyAssignment(n)){const i=n.getName();t.push(i);const r=n.getInitializer();r&&o.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(i);continue}(o.isShorthandPropertyAssignment(n)||o.isMethodDeclaration(n)||o.isGetAccessorDeclaration(n))&&t.push(n.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},si=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of yt(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);for(const a of r.getDescendantsOfKind(l.CallExpression)){const c=ei(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&o.isObjectLiteralExpression(u)?ti(u):{analyzable:!1,emptyKeys:[],presentKeys:[]};s.push({analyzable:d.analyzable,emptyKeys:d.emptyKeys,factory:c,file:n,line:a.getStartLineNumber(),presentKeys:d.presentKeys})}}return s},ni=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),ri=new Set(["dbRateLimit","rateLimit"]),ii=e=>{if(!e||!o.isObjectLiteralExpression(e))return!1;const t=e.getProperty("failOpen");return t!==void 0&&o.isPropertyAssignment(t)&&t.getInitializer()?.getKind()===l.TrueKeyword},oi=(e,t)=>{const s=A(e.getExpression());if(s===void 0)return;const n=ni.get(s);if(n!==void 0)return{callee:s,exportName:E(e),failOpen:ii(e.getArguments()[n]),file:t,limitName:ri.has(s)?Nt(e):"",line:e.getStartLineNumber()}},ai=(e,t)=>P(e,t,oi),ci=new Set(["boolean","number","object","string"]),li=e=>{const t=e.getName();if(!ci.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&ve(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&o.isPropertyAccessExpression(n)&&n.getName()==="flags"&&ve(n.getExpression()))return t},ui=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=li(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(o.isStringLiteral(n)||o.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();return i.length>0?{key:i,type:s}:void 0},di=(e,t)=>{const s=new Map;for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getDescendantsOfKind(l.CallExpression)){const a=ui(r);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,i])=>({key:n,type:i})).toSorted((n,i)=>n.key.localeCompare(i.key))},fi=e=>{const t=e.getInitializer();if(!t||!o.isCallExpression(t))return;const s=_(t);if(s?.kind!=="query")return;const n=Ts(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},it=e=>{const t=e.getParent();return t&&o.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},pi=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!o.isIdentifier(t)||t.getText()!=="ctx")return;const s=it(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=it(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},gi=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const i=pi(n);i!==void 0&&s.push({callee:i,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},mi=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=fi(i);r&&s.push(...gi(r,t))}return s},hi=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...mi(i,v(t,n)))}return s},xi=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="flags"&&ve(t.getExpression())},Ei=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},vi=(e,t)=>{if(!xi(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(o.isStringLiteral(s)||o.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),r=Ei(n);if(!(i.length===0||r===void 0))return{defaultValue:r,exportName:E(e),file:t,key:i,line:e.getStartLineNumber()}},Si=(e,t)=>P(e,t,vi),Ai=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const s=t.getTypeAtLocation(e).getProperty("types");if(!s)return;const n=s.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!n)return;const i=n.getTypeAtLocation(e),r=i.getText(e);if(!r||r==="any"||r==="never"||Vs(r))return;const a=e.getSourceFile().getFilePath();return Ws(i,e,a)?Hs(i,e,a,0,new Set):r},yi=e=>{const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Ni=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},bi=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression))yi(a)&&s.push({file:r,indexName:Ni(a),line:a.getStartLineNumber()})}return s},V=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,Lt=e=>{const t=e.getArguments()[0],s=V(t);if(s!==void 0)return s;if(t===void 0||!o.isObjectLiteralExpression(t))return;const n=t.getProperty("handler");return n!==void 0&&o.isPropertyAssignment(n)?V(n.getInitializer()):void 0},Pi=new Set(["delete","get","head","options","patch","post","put"]),Ii=new Set(["handler","stream"]),wi=new Set(["runAction","runMutation"]),Ti=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),J=(e,t)=>e!==void 0&&o.isIdentifier(e)&&e.getText()===t,ot=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const n=s.getNameNode();if(t)return o.isIdentifier(n)?n.getText():void 0;if(o.isObjectBindingPattern(n)){for(const i of n.getElements())if((i.getPropertyNameNode()?.getText()??i.getNameNode().getText())==="ctx"){const a=i.getNameNode();return o.isIdentifier(a)?a.getText():void 0}}},at=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);o.isCallExpression(s)&&n.unshift(s);for(const i of n){const r=i.getExpression();if(!o.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(wi.has(a)&&J(c,t))return a;if(Ti.has(a)&&o.isPropertyAccessExpression(c)&&c.getName()==="db"&&J(c.getExpression(),t))return`db.${a}`}},ct=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&J(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const i=n.getNameNode();if(!(!o.isObjectBindingPattern(i)||!J(n.getInitializer(),t))){for(const r of i.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},Ci=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Ii.has(t.getName()))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))return;const i=n.getName();if(Pi.has(i)){const r=n.getExpression();return o.isIdentifier(r)&&r.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},Fi=(e,t)=>{const s=e.getExpression();if(o.isIdentifier(s)&&s.getText()==="httpAction"){const c=V(e.getArguments()[0]),u=c&&ot(c,!0);if(!c||u===void 0)return;const d=at(c,u);return d===void 0?void 0:{exportName:E(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:ct(c,u),sideEffect:d}}const n=Ci(e);if(n===void 0)return;const i=V(e.getArguments()[0]),r=i&&ot(i,!1);if(!i||r===void 0)return;const a=at(i,r);return a===void 0?void 0:{exportName:E(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:ct(i,r),sideEffect:a}},Oi=(e,t)=>P(e,t,Fi),Ri=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Li=new Set(["append","set"]),Dt=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",lt=(e,t)=>(o.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>Ri.has(A(n.getExpression())??"")&&Us(n,t)),Di=(e,t)=>{if(lt(e,t))return!0;const s=ie(e);return s!==void 0&&lt(s,t)},Se=(e,t)=>zs(e,t)&&!Di(e,t),ki=e=>{if(o.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=ie(e);return t!==void 0&&o.isNewExpression(t)&&A(t.getExpression())==="Headers"},ee=e=>{if(e===void 0)return;if(o.isObjectLiteralExpression(e))return e;const t=ie(e);return t!==void 0&&o.isObjectLiteralExpression(t)?t:void 0},Ne=(e,t,s)=>{for(const n of e.getProperties())if(o.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&Se(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Dt(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(o.isShorthandPropertyAssignment(n)){const i=n.getNameNode();Se(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:n.getName(),line:i.getStartLineNumber(),via:t})}else if(o.isSpreadAssignment(n)){const i=ee(n.getExpression());i!==void 0&&Ne(i,t,s)}},kt=(e,t)=>{const s=ee(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!o.isPropertyAssignment(n))return;const i=ee(n.getInitializer());i!==void 0&&Ne(i,"response-init",t)},Mi=(e,t)=>{const s=A(e.getExpression());if(s==="Response")kt(e.getArguments()[1],t);else if(s==="Headers"){const n=ee(e.getArguments()[0]);n!==void 0&&Ne(n,"headers-ctor",t)}},Ki=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName(),i=s.getExpression();if(n==="json"&&o.isIdentifier(i)&&i.getText()==="Response"){kt(e.getArguments()[1],t);return}if(Li.has(n)&&ki(i)){const r=e.getArguments()[1];r!==void 0&&Se(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Dt(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},_i=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))Mi(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))Ki(s,t)},zi=(e,t)=>{const s=e.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=V(e.getArguments()[0]);if(n===void 0)return[];const i=n.getParameters()[1];if(i===void 0)return[];const r=i.getNameNode();if(!o.isIdentifier(r))return[];const a=[];return _i(n,{exportName:E(e),relativePath:t,requestName:r.getText(),rows:a}),a},Ui=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...zi(n,t));return s},Bi=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ui(i,v(t,n)))}return s},qi=new Set(["auth","context.auth","ctx.auth"]),$i="userId",ji=e=>{const t=new Set;for(const s of e.getProperties()){if(o.isSpreadAssignment(s))return;(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s))&&t.add(s.getName())}return t},Vi=(e,t)=>{const s=f(t,Tt);if(!b(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(l.CallExpression)){if(A(i.getExpression())!=="defineIdentity")continue;const[r]=i.getArguments();return r&&o.isObjectLiteralExpression(r)?ji(r):void 0}},ut=e=>{if(!(e===void 0||!o.isPropertyAccessExpression(e)||e.getName()!=="identity"))return qi.has(e.getExpression().getText())?e:void 0},Wi=e=>{if(o.isPropertyAccessExpression(e)&&ut(e.getExpression())!==void 0)return e.getName();if(o.isElementAccessExpression(e)&&ut(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0}},Hi=(e,t,s)=>{const n=[];for(const i of e.getDescendants()){const r=Wi(i);r!==void 0&&n.push({declared:r===$i||s.has(r),exportName:E(i),file:t,key:r,line:i.getStartLineNumber()})}return n},Gi=(e,t)=>{const s=Vi(e,t);if(s===void 0)return[];const n=[];for(const i of g(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...Hi(r,v(t,i),s))}return n},Yi=(e,t)=>{if(A(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=N(s,"key");if(!(!n||!F(n)||K(n)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},Qi=(e,t)=>P(e,t,Yi),Xi=new Set(["delete","get","getRaw","getWithMetadata","put"]),Zi=(e,t)=>oe(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Xi}),Ji=new Set(["queue","send"]),dt=new Set(["bcc","cc","to"]),eo=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Ji.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},to=e=>o.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(o.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return dt.has(t.getName())&&F(n)&&!K(n)}if(!o.isPropertyAssignment(t)||!dt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&F(s)&&!K(s)}):!1,so=(e,t)=>{const s=eo(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!to(n)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s}},no=(e,t)=>P(e,t,so),ro=e=>o.isPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?o.isComputedPropertyName(e.getNameNode()):!1,io=e=>o.isPropertyAssignment(e)||o.isShorthandPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?ro(e):!0,Mt=(e,t=!1)=>{for(const s of e.getProperties()){if(io(s))return!0;if(t)continue;if(!o.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!o.isObjectLiteralExpression(n)||Mt(n,!0))return!0}return!1},oo=(e,t)=>{for(const s of g(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:i}of wt(n))for(const r of ye(i)){const a=r.getArguments()[0];if(a!==void 0&&(!o.isObjectLiteralExpression(a)||Mt(a)))return!0}}return!1},ao=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const i=Z(n);if(i===void 0||!o.isPropertyAssignment(n))continue;const r=n.getInitializer();if(!(!r||!o.isObjectLiteralExpression(r)))for(const a of r.getProperties()){const c=Z(a);c!==void 0&&s.push({column:c,strategy:It(a),table:i})}}return s},co=(e,t)=>{const s=new Map;for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:r}of wt(i))for(const a of ye(r))for(const c of ao(a)){const u=`${c.table}\0${c.column}`;s.has(u)||s.set(u,c)}}return{columns:[...s.values()]}},lo=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){const a=Z(r);if(a===void 0||!o.isPropertyAssignment(r))continue;const c=r.getInitializer();if(!(!c||!o.isObjectLiteralExpression(c)))for(const u of c.getProperties()){const d=Z(u);if(d===void 0)continue;const x=It(u);x!=="custom"&&i.push({column:d,exportName:t,file:s,line:u.getStartLineNumber(),strategy:x,table:a})}}return i},uo=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?_(s):void 0;return n?.receiver?ye(n.receiver).flatMap(i=>lo(i,e.getName(),t)):[]},fo=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...uo(c,r))}return s},po=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return D(s)},go=e=>{const t=e.getArguments()[0];if(t===void 0||!o.isObjectLiteralExpression(t))return;const s=t.getProperty("server");if(s!==void 0)return o.isPropertyAssignment(s)?s.getInitializer():s},mo=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return Js(s.getExpression())?s:void 0},ho=e=>{const t=mo(e),s=t===void 0?void 0:go(t);if(s===void 0)return[];const n=e.getNameNode(),i=o.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>po(r)).map(r=>({exportName:i,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},xo=e=>e.getVariableDeclarations().flatMap(t=>ho(t)),Eo=(e,t)=>{const s=f(t,Zs);if(!b(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return xo(n)},vo=new Set(["delete","get","patch"]),So=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Ao=new Set(["auth","identity","session","user"]),yo=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),No=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!D(t.getExpression()))return;const s=e.getArguments()[0];return s&&o.isStringLiteral(s)?s.getLiteralText():""},bo=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(o.isAsExpression(s)||o.isParenthesizedExpression(s)||o.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!o.isVariableDeclaration(s))return;const n=s.getNameNode();return o.isIdentifier(n)?n.getText():void 0},Po=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),Io=e=>o.isThrowStatement(e)||o.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,wo=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>Po(s.getExpression(),t)&&Io(s.getThenStatement())),To=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))continue;const i=n.getName();if(!vo.has(i))continue;const r=n.getExpression();if(!(D(r)||o.isPropertyAccessExpression(r)&&D(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&o.isIdentifier(c)&&c.getText()===t)return i}},Co=e=>{let t=e;for(;o.isPropertyAccessExpression(t)||o.isElementAccessExpression(t)||o.isNonNullExpression(t)||o.isParenthesizedExpression(t)||o.isAsExpression(t)||o.isAwaitExpression(t);)t=t.getExpression();return o.isIdentifier(t)?t.getText():void 0},Fo=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>Co(s)==="ctx")),Oo=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>yo.has(t.getOperatorToken().getKind())?o.isPropertyAccessExpression(t.getLeft())||o.isPropertyAccessExpression(t.getRight()):!1),Ro=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(So.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&s.getText()==="ctx"&&Ao.has(t.getName()))return!0}return Fo(e)||Oo(e)},Lo=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=_(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=Lt(s);if(i===void 0)return[];const r=n.receiver!==void 0&&Pt(n.receiver,"use","rls"),a=Ro(i),c=new Set,u=[];for(const d of i.getDescendantsOfKind(l.CallExpression)){const x=No(d);if(x===void 0)continue;const y=bo(d);if(y===void 0||c.has(y)||!wo(i,y))continue;const p=To(i,y);p!==void 0&&(c.add(y),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:x,usesRls:r,visibility:n.visibility}))}return u},Do=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Lo(c,r))}return s},ko=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),Mo=new Set(["insert","insertManyUnsafe","patch","replace"]),Ko=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Mo.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},_o=(e,t)=>{if(t!=="insertManyUnsafe")return o.isObjectLiteralExpression(e)?[e]:[];if(!o.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())o.isObjectLiteralExpression(n)&&s.push(n);return s},zo=(e,t,s,n)=>{const i=[];for(const r of e.getProperties()){let a,c;o.isPropertyAssignment(r)?(a=r.getName(),c=r.getInitializer()):o.isShorthandPropertyAssignment(r)&&(a=r.getName(),c=r.getNameNode()),!(a===void 0||c===void 0||!ko.has(a))&&F(c)&&!K(c)&&i.push({exportName:E(s),field:a,file:n,line:s.getStartLineNumber(),method:t})}return i},Uo=(e,t)=>{const s=Ko(e.getExpression());if(s===void 0)return[];const n=e.getArguments()[1];return n?_o(n,s).flatMap(i=>zo(i,s,e,t)):[]},Bo=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression))for(const r of Uo(i,t)){const a=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},qo=(e,t,s=[])=>{const n=[],i=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));for(const r of g(t)){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=v(t,r);n.push(...Bo(a,c,u=>i.get(`${c}:${u}`)))}return n},$o=["providerSubscriptionId","state"],jo=["providerEventId","processedAt"],ft=(e,t)=>t.every(s=>s in e.shape),Vo=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&ft(t,$o)&&ft(s,jo)},Wo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Ho=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,Go=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&o.isPropertyAssignment(t)?Ho(t.getInitializer()):void 0},Yo=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!Wo.has(s))return;const[n]=e.getArguments(),i=n&&o.isObjectLiteralExpression(n)?Go(n):void 0;return{callee:s,exportName:E(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},Qo=(e,t)=>P(e,t,Yo),Xo=new Set(["defineQueue","defineWorkflow"]),Zo=new Set(["run","runAction","runMutation","runQuery"]),Jo=new Set(["api","internal"]),ea=e=>{const t=e.getExpression();return o.isIdentifier(t)?t.getText():void 0},ta=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!o.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(o.isArrowFunction(n)||o.isFunctionExpression(n)))return n},Kt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&o.isIdentifier(s)?s.getText():void 0},_t=(e,t)=>e===t||e.startsWith(`${t}.`),zt=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return o.isPropertyAccessExpression(e)&&t.push(e),t},pt=e=>{const t=e.getParent();return o.isPropertyAccessExpression(t)&&t.getNameNode()===e||o.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(o.isBindingElement(t)&&t.getNameNode()===e)},Ut=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>pt(s));return o.isIdentifier(e)&&pt(e)&&t.push(e),t},sa=e=>{if(!o.isVariableDeclaration(e))return[];const t=e.getNameNode();return o.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},na=e=>{const t=Kt(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const i=n.getInitializer(),r=o.isVariableDeclarationList(i)?i.getDeclarations()[0]?.getNameNode():void 0;r&&o.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},ra=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:na(e),i=new Set,r=a=>zt(a).some(c=>n.some(u=>_t(c.getText(),u)))?!0:Ut(a).some(c=>i.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of sa(a))i.add(u)}return{names:i,prefixes:n}},ia=(e,t)=>zt(e).some(s=>t.prefixes.some(n=>_t(s.getText(),n)))?!0:Ut(e).some(s=>t.names.has(s.getText())),oa=e=>{if(e===void 0||!o.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;o.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!o.isIdentifier(s)||!Jo.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},aa=(e,t,s)=>{const n=Kt(e,0);if(n===void 0)return[];const i=ra(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!o.isPropertyAccessExpression(c)||!Zo.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!ia(u,i))continue;const d=oa(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:E(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},ca=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=ea(n);if(i===void 0||!Xo.has(i))continue;const r=ta(n);r!==void 0&&s.push(...aa(r,i==="defineQueue"?"queue":"workflow",t))}return s},la=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ca(i,v(t,n)))}return s},gt={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},mt=new Set(["account","credential","member","passkey","session","user"]),ua=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),da=e=>{const s=ua(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return mt.has(s)||mt.has(n)},fa=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},pa=(e,t)=>{const{objects:s,opaque:n}=Ot(e,t);return fr(s).some(i=>fa(i))?!0:n?void 0:!1},ga=e=>{const t=e.getArguments()[0];return!t||!o.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},ma=e=>{if(o.isCallExpression(e))return e;if(!o.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&o.isCallExpression(s)?s:void 0},X={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},ha=e=>{const t=ma(e),s=t?A(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=ga(t);return{...X,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in gt?{...X,[gt[s]]:!0}:X},xa=e=>{const t={...X};let s=e;for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))break;const i=n.getName()==="use"?s.getArguments()[0]:void 0;if(i){const r=ha(i);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},Ea=new Set(["insert","insertMany","insertManyUnsafe","replace"]),va=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Ea.has(t.getName()))return!1;const s=t.getExpression();if(!D(s))return!1;const i=e.getArguments()[0];return!i||!(o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i))?!1:da(i.getLiteralText())},Sa=new Set(["create","runAfter","runAt","send","sendBatch"]),Aa=new Set(["queues","scheduler","workflows"]),ya=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Sa.has(t.getName()))return!1;let s=t.getExpression();for(;o.isCallExpression(s)||o.isElementAccessExpression(s)||o.isPropertyAccessExpression(s);){if(o.isPropertyAccessExpression(s)&&Aa.has(s.getName())){const n=s.getExpression();if(o.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},Na=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return D(s)},Bt=new Set(["generateObject","generateText","streamObject","streamText"]),ba=e=>{const t=A(e.getExpression());return t!==void 0&&Bt.has(t)},Pa=e=>{const t=A(e.getExpression());if(t===void 0||!Bt.has(t))return!1;const s=e.getArguments()[0];return!s||!o.isObjectLiteralExpression(s)||s.getProperties().some(n=>o.isSpreadAssignment(n))?!1:!s.getProperty("maxOutputTokens")},Ia=new Set(["log","span","trace"]),wa=new Set(["ai"]),Ta=new Set(["email","mail"]),Ca=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),xe=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"}),Fa=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),Oa=new Set(["every","filter","flatMap","forEach","map","some"]),Ra=new Set(["all","allSettled","race"]),La=e=>{const t=e.getParent();if(!t||!o.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName();if(Oa.has(n))return t;const i=s.getExpression();if(o.isIdentifier(i)&&i.getText()==="Promise"&&Ra.has(n))return t},Da=e=>{let t=e.getParent();for(;t;){if(o.isTryStatement(t)){const s=t.getTryBlock();if(e.getPos()>=s.getPos()&&e.getEnd()<=s.getEnd())return!0}if(Fa.has(t.getKind())){const s=La(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},ka=e=>{let t=e;for(;;){const s=t.getParent();if(!o.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!o.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},Ma=e=>{let t=e;for(;;){const s=t.getParent();if(o.isPropertyAccessExpression(s)&&s.getExpression()===t){t=s;continue}return o.isCallExpression(s)&&s.getExpression()===t?s:void 0}},Ka=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!Ca.has(n.getName()))continue;const i=n.getExpression();if(!o.isIdentifier(i)||i.getText()!=="ctx")continue;const r=Ma(n);r&&(t=!0,!Da(r)&&!ka(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},_a=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!o.isNewExpression(s))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="Error"}),ht="lunora-advisor-exempt",za=/^[\s*/]+/u,Ua=/[\w-]/u,Ba=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
6
+ `);for(const n of s.split(`
7
+ `)){const i=n.replace(za,"");if(!i.startsWith(ht))continue;const r=i.slice(ht.length);if(Ua.test(r.charAt(0)))continue;const a=r.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":r.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},qa=e=>{const[t]=e.getArguments();if(t){if(o.isObjectLiteralExpression(t)){const s=t.getProperty("handler");return s?o.isPropertyAssignment(s)?s.getInitializer():o.isShorthandPropertyAssignment(s)?s.getNameNode():o.isMethodDeclaration(s)?s:void 0:void 0}return t}},$a=(e,t)=>{const s=qa(t);if(!s)return;if(o.isArrowFunction(s)||o.isFunctionExpression(s)||o.isMethodDeclaration(s))return e;if(!o.isIdentifier(s))return;const n=s.getSourceFile(),i=s.getText(),r=n.getVariableDeclaration(i)?.getInitializer();return r&&(o.isArrowFunction(r)||o.isFunctionExpression(r))?r:n.getFunction(i)},ja=e=>{let t=!1,s=!1,n=!1,i=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(va(u)&&(r=!0),ya(u)&&(t=!0),Na(u)&&(i=!0),ba(u)&&(s=!0),Pa(u)&&(n=!0),r&&t&&i&&n)break;const{handlesErrors:a,reachesOutbound:c}=Ka(e);return{callsMail:xe(e,Ta),emitsEvent:xe(e,Ia),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||xe(e,wa),throwsBareError:_a(e),unboundedAiGeneration:n,usesInsertManyUnsafe:i,writesUserTable:r}},Va=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=_(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const i=n.receiver?xa(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=$a(e,s);return{...r?ja(r):{},...Ba(e),...i,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:pa(s,n.receiver),kind:n.kind,visibility:n.visibility}},Wa=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=Va(i,t);r&&s.push(r)}return s},Ha=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Wa(i,v(t,n)))}return s},Ga=new Set(["dbRateLimit","rateLimit"]),Ya=e=>o.isArrowFunction(e)?e.getBody():e,Qa=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!Ga.has(s))return;const n=e.getArguments()[2];if(!n)return;const i=N(n,"key");if(!i)return;const r=Ya(i);if(!(!F(r)||K(r)))return{callee:s,exportName:E(e),file:t,limitName:Nt(e),line:e.getStartLineNumber()}},Xa=(e,t)=>P(e,t,Qa),Za=new Set(["findFirst","findFirstOrThrow","findMany","get"]),Ja=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Za.has(t.getName()))return;const s=t.getExpression();if(D(s)){const n=e.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}if(o.isPropertyAccessExpression(s)&&D(s.getExpression()))return s.getName()},ec=e=>{let t=e;for(;o.isCallExpression(t);){const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&D(s.getExpression())){const n=t.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},tc=e=>{let t=Ze(e)??e;for(;o.isAwaitExpression(t);)t=Ze(t.getExpression())??t.getExpression();return t},qt=(e,t=!1)=>{const s=tc(e);if(o.isIdentifier(s)){if(t)return;const n=ie(s);return n===void 0?void 0:qt(n,!0)}if(o.isCallExpression(s))return Ja(s)??ec(s)},sc=e=>{const t=e.getBody();if(!o.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const i=n.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a)),r=n.getExpression();i===e&&r!==void 0&&s.push(r)}return s},nc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=_(s);if(n?.kind!=="query")return[];const i=Lt(s);if(i===void 0)return[];const r=n.receiver!==void 0&&qs(n.receiver,"output"),a=n.receiver!==void 0&&Pt(n.receiver,"use","mask"),c=new Set,u=[];for(const d of sc(i)){const x=qt(d);x===void 0||c.has(x)||(c.add(x),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:x,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},rc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...nc(c,r))}return s},ic=e=>{if(!e||!o.isObjectLiteralExpression(e))return[];const t=[];for(const s of e.getProperties())(o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)||o.isMethodDeclaration(s)||o.isGetAccessorDeclaration(s))&&t.push(s.getName());return t},oc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?_(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=bt(r);if(a===void 0)continue;const c=ic(N(a.options,"with"));c.length!==0&&i.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return i},ac=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...oc(c,r))}return s},te=e=>{if(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(o.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=te(e.getLeft()),s=te(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},cc=e=>{let t=e,s=t.getParent();for(;s!==void 0&&o.isBinaryExpression(s)&&s.getOperatorToken().getKind()===l.PlusToken;)t=s,s=t.getParent();return t!==e&&te(t)!==void 0},lc=/(?:^|\/)__tests__\//u,uc=/\.(?:spec|test)$/u,dc=e=>lc.test(e)||uc.test(e),fc=e=>{const t=e.getParent();if(t!==void 0){if(o.isVariableDeclaration(t)||o.isPropertyAssignment(t)||o.isPropertySignature(t))return t.getName();if(o.isBinaryExpression(t)&&t.getOperatorToken().getKind()===l.EqualsToken)return t.getLeft().getText()}},pc=(e,t,s)=>un(e)?!dc(s)&&dn(fc(t)):!0,gc=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],i=new Set;for(const r of n){if(cc(r))continue;const a=te(r);if(a===void 0)continue;const c=cn(a);if(c===void 0||!pc(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;i.has(d)||(i.add(d),s.push({file:t,kind:c,line:u,preview:ln(a)}))}return s},mc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...gc(i,v(t,n)))}return s},hc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?_(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=bt(r);if(a===void 0)continue;const c=N(a.options,"includeDeleted");if(c===void 0)continue;const u=o.isTrueLiteral(c),d=!u&&F(c);!u&&!d||i.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return i},xc=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...hc(c,r))}return s},Ec=new Set(["query","unsafe"]),vc=e=>{if(!o.isPropertyAccessExpression(e)||!Ec.has(e.getName()))return!1;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="sql")return!1;const s=t.getExpression();return o.isIdentifier(s)&&s.getText()==="ctx"},Sc=e=>o.isBinaryExpression(e)||o.isTemplateExpression(e),Ac=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",yc=(e,t)=>{if(!vc(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Sc(s)))return{exportName:Ac(e),file:t,line:s.getStartLineNumber()}},Nc=(e,t)=>P(e,t,yc),bc=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Pc=e=>{for(const[t,s]of bc)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Ic=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=Pc(a);c!==void 0&&s.push({file:v(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},wc=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Tc=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return oe(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:wc,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},Cc=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Fc=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,Oc=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!o.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),r==="expiresInSeconds"&&(s=Fc(i.getInitializer()));continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},Rc=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName(),s=Cc.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},Lc=(e,t)=>{const s=Rc(e.getExpression());if(s!==void 0)return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s.method,...Oc(e.getArguments()[s.optionsIndex])}},Dc=(e,t)=>P(e,t,Lc),kc=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),Mc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),be=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&Mc.has(s)?s:void 0},$t=e=>{const t=e.getInitializer();return t===void 0?!1:o.isCallExpression(t)||o.isIdentifier(t)||o.isPropertyAccessExpression(t)},jt={cause:"codegen recognises a procedure only when the initializer is a builder chain, and this one is produced by a call or an alias",remediation:"A factory that returns a procedure cannot be read statically — inline it, or export the chain the factory builds."},Kc={cause:"the binding is exported by a separate `export { … }` statement, and codegen reads the `export` keyword on the declaration itself",remediation:"Move the keyword onto the declaration and drop the separate export statement."},Pe=(e,t,s,n,i)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${s}\` but was not registered — ${i.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${i.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),_c=(e,t,s)=>{const n=[];for(const i of e.getVariableStatements().filter(r=>r.isExported()))for(const r of i.getDeclarations()){const a=r.getName();if(s.has(`${t}:${a}`)||!$t(r))continue;const c=be(r);c!==void 0&&n.push(Pe(t,a,c,r.getStartLineNumber(),jt))}return n},zc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const n=[];for(const i of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=be(i.getExpression());r!==void 0&&n.push(Pe(t,"default",r,i.getStartLineNumber(),jt))}return n},Uc=(e,t,s)=>{const n=[];for(const i of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of i.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(s.has(`${t}:${a}`))continue;const c=r.getLocalTargetDeclarations().find(d=>o.isVariableDeclaration(d));if(c===void 0||!$t(c))continue;const u=be(c);u!==void 0&&n.push(Pe(t,a,u,r.getStartLineNumber(),Kc))}return n},Bc=(e,t,s)=>[..._c(e,t,s),...zc(e,t,s),...Uc(e,t,s)],qc=(e,t,s)=>{const n=new Set(s.map(r=>`${r.filePath}:${r.exportName}`)),i=[];for(const r of g(t)){const a=e.getSourceFile(r);a!==void 0&&i.push(...Bc(a,v(t,r),n))}return i.toSorted((r,a)=>r.cacheKey.localeCompare(a.cacheKey))},$c=new Set(["when","where"]),Ee=new Set(["definePolicy","defineShape"]),jc=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const n=t.getName();return Ee.has(n)?n:void 0}if(!o.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(o.isImportSpecifier(n)){const i=n.getNameNode().getText();return Ee.has(i)?i:void 0}const s=t.getText();return Ee.has(s)?s:void 0},Vc=e=>o.isObjectLiteralExpression(e)&&e.getProperties().length===0,Vt=e=>{if(e!==void 0){if(o.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(Vc(e))return"empty-object";if(o.isParenthesizedExpression(e))return Vt(e.getExpression())}},Ie=e=>e.getAncestors().find(t=>o.isArrowFunction(t)||o.isFunctionExpression(t)||o.isFunctionDeclaration(t)),Wc=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>Ie(t)===e),Wt=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>Ie(t)===e),Hc=e=>{const t=Wc(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||Wt(e).length>0},Gc=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>Ie(t)===e),Ae=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||o.isIdentifier(e)&&e.getText()==="undefined"?!0:o.isNumericLiteral(e)?e.getLiteralValue()===0:o.isStringLiteral(e)&&e.getLiteralValue()==="",Yc=(e,t)=>Ae(e)||Ae(t),Qc=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),xt=e=>!Ae(e)&&(o.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),Xc=(e,t,s)=>{const n=Qc.get(e);if(n!==void 0)return Yc(t,s)?n==="positive"?"negative":"positive":xt(t)||xt(s)?void 0:n},j=e=>{if(o.isParenthesizedExpression(e))return j(e.getExpression());if(o.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(o.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=Xc(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=j(e.getLeft()),i=j(e.getRight());return n===i?n:"indeterminate"}}return o.isIdentifier(e)||o.isPropertyAccessExpression(e)||o.isElementAccessExpression(e)||o.isCallExpression(e)?"positive":"indeterminate"},Et=e=>{if(e!==void 0){if(o.isReturnStatement(e))return e;if(o.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&o.isReturnStatement(t)?t:void 0}}},Zc=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},Jc=e=>o.isReturnStatement(e)?e.getExpression()??e:e,el=e=>{const t=[];for(const s of Wt(e)){const n=j(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of Gc(e)){const n=j(s.getExpression());if(n==="indeterminate")continue;const i=n==="negative"?Et(s.getThenStatement()):Et(s.getElseStatement())??Zc(s);i!==void 0&&t.push(Jc(i))}return t},tl=e=>{for(const t of e.getAncestors())if(o.isVariableDeclaration(t)){const s=t.getNameNode();if(o.isIdentifier(s))return s.getText()}return"<anonymous>"},sl=(e,t,s)=>{if(!o.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){if(!o.isPropertyAssignment(r)||!$c.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(o.isArrowFunction(a)||o.isFunctionExpression(a)))&&Hc(a))for(const c of el(a)){const u=Vt(c);u!==void 0&&i.push({exportName:tl(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return i},nl=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=jc(n);i!==void 0&&s.push(...sl(n,i,t))}return s},rl=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...nl(i,v(t,n)))}return s},il=new Set(["query","upsert","upsertMany"]),ol=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(il.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},al=(e,t)=>{const s=ol(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const i=N(n,"namespace");if(!(!i||!F(i)||K(i)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s}},cl=(e,t)=>P(e,t,al),ll=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="get")return!1;const s=t.getExpression();return o.isPropertyAccessExpression(s)?s.getName()==="workflows":o.isIdentifier(s)&&s.getText()==="workflows"},ul=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},dl=(e,t)=>{const s=[];for(const n of g(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression)){if(!ll(a))continue;const c=Cs(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:ul(a)})}}return s},fl=".lunora-schema.json",w=(e,t)=>{b(e)&&At(e,"utf8")===t||rs(e,t,"utf8")},C=(e,t)=>{if(t===""){is(e,{force:!0});return}w(e,t)},pl=e=>{const t=f(e,"package.json");if(b(t))try{const s=JSON.parse(At(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},gl=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},ml=e=>{let t=b(e)?e:pe(e);for(;t&&t!==pe(t);){const s=f(t,"tsconfig.json");if(b(s))return s;t=pe(t)}},vt=e=>e.replaceAll("\\","/"),hl=(e,t,s)=>{if(s&&e.length>0){const r=e.map(a=>`"${a.exportName}"`).join(", ");throw new L("MASK_UNSUPPORTED",`This project declares a \`mask(...)\` policy whose argument isn't a plain object literal (e.g. \`mask(sharedPolicies)\` referencing a hoisted variable), or contains a spread (\`...shared\`) or computed key (\`[name]:\`) codegen can't enumerate, so codegen can't tell which columns it masks. Because the project also declares replication shape(s) (${r}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const i=t.columns.length>0;for(const r of e){if(r.table===void 0){if(i)throw new L("MASK_UNSUPPORTED",`defineShape "${r.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${r.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new L("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},se=(e,t,s)=>{const n=e.getSourceFile(t);if(n===void 0){e.createSourceFile(t,s,{overwrite:!0});return}n.getFullText()!==s&&n.replaceWithText(s)},St=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,xl=8,El=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:i,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:x}=e;let y=Je(a,i),p=tt(a,i),O=et(a,i);Sn([...y,...p].map(S=>S.filePath));for(let S=1;;S+=1){const T=Is({agents:t,functions:y,httpRoutes:O,mutators:p,useUmbrella:d,workflows:x}),k=ws({agents:t,functions:y,migrations:r,mutators:p,shapes:c,useUmbrella:d,usesSandbox:u});if(S>=xl||St(a,s,T)&&St(a,n,k))return{apiContent:T,functions:y,functionsContent:k,httpRoutes:O,mutators:p};se(a,s,T),se(a,n,k),y=Je(a,i),p=tt(a,i),O=et(a,i)}},vl=e=>{const t=ml(e);return t?new Xe({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Xe({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},pu=(e,t)=>{const s=g(t),n=f(t,"schema.ts");b(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const i=new Set(s.map(c=>vt(c))),r=vt(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!i.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},gu=e=>{const t=gl(),s=t?ge.now():0,n=f(e.projectRoot,e.lunoraDirectory??"lunora"),i=f(n,"schema.ts");if(!b(i))throw new L("INTERNAL",`schema.ts not found at ${i}`);const r=e.project??vl(n);En(Ai);const a=an(r,i,e.projectRoot),{agents:c,containers:u,dataModelContent:d,dependencies:x,env:y,featureUsage:p,hasBrowser:O,hasFlags:S,hasNotify:T,identity:k,platformGate:U,queues:R,serverContent:z,storageRulesMetadata:B,usesSandbox:W,useUmbrella:I,workflows:M}=zn({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),m=f(n,"_generated"),we=f(m,"dataModel.ts"),Te=f(m,"server.ts"),Ht=f(m,"api.ts"),Gt=f(m,"functions.ts");se(r,we,d),se(r,Te,z);const ae=Xs(r,n),q=fn(r,n),{apiContent:Ce,functions:$,functionsContent:Fe,httpRoutes:Yt,mutators:Qt}=El({agents:c,apiPath:Ht,generatedFunctionsPath:Gt,lunoraDirectory:n,migrations:ae,project:r,shapes:q,useUmbrella:I,usesSandbox:W,workflows:M}),ce=js(r,n,M,c),H=e.lint===!1?void 0:cs({adminRoutes:Hn(r,n),aiRawRuns:Qn(r,n),aiToolSideEffects:or(r,n),argumentDerivedFetches:lr(r,n),argumentValidators:Ar(r,n),authApiCalls:$s(r,n),authConfigs:Or(r,n),browserUrlAccesses:Mr(r,n),configCalls:jr(r,n),containerKeyAccesses:Wr(r,n),containerOverrides:Zr(r,n),containers:u,exportSinks:si(r,n),staleMigrationImports:Ic(r,n),failOpenGuards:ai(r,n),flagReads:hi(r,n),flagSecurityDefaults:Si(r,n),geoIndexUsages:bi(r,n),httpActionGuards:Oi(r,n),httpHeaderWrites:Bi(r,n),hyperdriveCalls:Gs(r,n),identityClaimReads:Gi(r,n),imageDeliveryUrlAccesses:Qi(r,n),inserts:Ys(r,n),kvKeyAccesses:Zi(r,n),mailRecipientAccesses:no(r,n),maskProcedures:Qs(r,n),maskStrategies:fo(r,n),mutatorWrites:Eo(r,n),nondeterministicCalls:en(r,n),normalizeIdAuthorizations:Do(r,n),notifyCalls:sn(r,n),notifyConfig:tn(r,n),ownerFieldWrites:qo(r,n,$),unrestrictedWhereBranches:rl(r,n),paymentWebhooks:Qo(r,n),privilegedDispatches:la(r,n),procedureProtections:Ha(r,n),queries:Bs(r,n),queues:R,r2sqlCalls:nn(r,n),ratelimitKeySelectors:Xa(r,n),rawRowReturns:rc(r,n),relationLoads:ac(r,n),rlsProcedures:rn(r,n),schema:a,secretLiterals:mc(r,n),shapes:q,softDeleteReads:xc(r,n),sqlInterpolations:Nc(r,n),storageKeyAccesses:Tc(r,n,$),storageUploads:Dc(r,n),vectorNamespaceAccesses:cl(r,n),workflowCalls:dl(r,n),workflows:M,wranglerVariables:e.wranglerVariables}),Oe=H===void 0?[]:[...os(H,{source:"static"}),...qc(r,n,$)],Xt=on(r,n),Re=co(r,n);hl(q,Re,oo(r,n));const Zt=S?di(r,n):[],G=kc(p,{containerCount:u.length,cronCount:ce.length,dependencies:x,hasPaymentTables:Vo(a.tables),queueCount:R.length,storageColumnCount:Object.keys(gs(a)).length,storageRuleCount:B.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:M.length}),Le=t?ge.now():0,le=vn(a,ae.map(h=>h.id)),De=ms({advisories:Oe,advisorProcedures:H?.procedureProtections??[],agents:c,containers:u,env:y,flagKeys:Zt,hasAccessFacade:p.access,hasAi:p.ai,hasAnalytics:p.analytics,hasBrowser:O,hasFlags:S,hasHyperdrive:p.hyperdrive,hasImages:p.images,hasKv:p.kv,hasNotify:T,hasPayments:p.payments,hasPipelines:p.pipelines,hasR2sql:p.r2sql,hasX402:p.x402,maskMetadata:Re,mutators:Qt,queues:R,rlsMetadata:Xt,schema:a,schemaSnapshot:le,shapes:q,storageRules:B,studioFeatures:G,useUmbrella:I,workflows:M}),ke=hs(q,x.has("@lunora/db"),I),Me=xs(u,a.jurisdiction),Ke=Es(M),_e=vs(c),ze=Ss(R),Ue=As(ce),Be=ys(a.vectorIndexes),Y=Ns(a,I),qe=bs(x.has("@lunora/seed")),Q=e.apiSpec??"openapi",ue=Q==="openapi"||Q==="both",de=Q==="openrpc"||Q==="both",$e=pn({emailAgents:c.filter(h=>h.onEmail===!0).map(h=>({bindingName:h.bindingName,exportName:h.exportName})),hasAccess:x.has("@lunora/cloudflare-access"),hasAi:p.ai,hasAnalytics:p.analytics,hasAuth:x.has("@lunora/auth"),hasBrowser:O,hasFramework:x.has("@lunora/astro")||x.has("@lunora/svelte")||x.has("@lunora/vue"),hasGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend!=="hyperdrive"),hasHyperdrive:p.hyperdrive,hasHyperdriveGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend==="hyperdrive"),hasImages:p.images,hasKv:p.kv,hasKvIntrospector:G.kv,hasNotify:T,hasPayments:p.payments,hasR2sql:p.r2sql,hasQueue:R.some(h=>h.mode==="push"),hasScheduler:G.scheduler,hasStorage:G.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:M.length>0,hasX402:p.x402,identity:k,jurisdiction:a.jurisdiction,tableNames:a.tables.map(h=>h.name),useUmbrella:I,voiceAgents:c.filter(h=>h.voice===!0&&h.voiceBindingName!==void 0).map(h=>({bindingName:h.voiceBindingName,exportName:h.exportName})),wantsOpenApi:ue,wantsOpenRpc:de}),je=pl(e.projectRoot),Ve=gn({functions:$,httpRoutes:Yt,version:je}),We=hn({functions:$,version:je}),He=`${JSON.stringify(Ve,void 0,2)}
8
+ `,Ge=`${JSON.stringify(We,void 0,2)}
9
+ `,Ye=mn(Ve),Qe=xn(We),fe=f(n,fl),Jt=b(fe);if(e.dryRun||(b(m)||ns(m,{recursive:!0}),w(f(m,"app.ts"),$e),w(we,d),w(f(m,"api.ts"),Ce),w(Te,z),w(f(m,"functions.ts"),Fe),w(f(m,"shard.ts"),De),w(f(m,"crons.ts"),Ue),w(f(m,"vectors.ts"),Be),w(f(m,"drizzle.global.ts"),Y.global),w(f(m,"drizzle.shard.ts"),Y.shard),C(f(m,"containers.ts"),Me),C(f(m,"workflows.ts"),Ke),C(f(m,"agents.ts"),_e),C(f(m,"queues.ts"),ze),C(f(m,"seed.ts"),qe),C(f(m,"collections.ts"),ke),C(f(m,"openapi.json"),ue?He:""),C(f(m,"openapi.ts"),ue?Ye:""),C(f(m,"openrpc.json"),de?Ge:""),C(f(m,"openrpc.ts"),de?Qe:""),(!Jt||e.updateSchemaBaseline===!0)&&w(fe,as(le))),t){const h=ge.now(),es=Math.round(h-s),ts=Math.round(Le-s),ss=Math.round(h-Le);console.error(`@lunora/codegen: codegen took ${es.toString()}ms (discovery ${ts.toString()}ms, emit ${ss.toString()}ms)`)}return{advisories:Oe,advisorContext:H,agents:c,containers:u,cronTriggers:Ps(ce),generated:{agents:_e,api:Ce,app:$e,collections:ke,containers:Me,crons:Ue,dataModel:d,drizzleGlobal:Y.global,drizzleShard:Y.shard,functions:Fe,openApi:He,openApiModule:Ye,openRpc:Ge,openRpcModule:Qe,queues:ze,seed:qe,server:z,shard:De,vectors:Be,workflows:Ke},migrations:ae,outputDirectory:m,platformDiagnostics:U.diagnostics,queues:R,schemaSnapshot:le,schemaSnapshotPath:fe,workflows:M}};export{fl as SCHEMA_SNAPSHOT_FILENAME,vl as createCodegenProject,ml as findTsconfig,pu as refreshCodegenProject,gu as runCodegen};
@@ -1 +1 @@
1
- import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{LunoraError as a}from"@lunora/errors";import{workflowDefaultName as u,workflowClassName as d,workflowBindingName as g}from"@lunora/workflow";import{Node as i,VariableDeclarationKind as w,SyntaxKind as x}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{u as b,s as h}from"./ast-CjWtsS6S.mjs";const k="workflows.ts",N=new Set(["do","sleep","sleepUntil","waitForEvent"]),y=n=>{const e=n.getSymbol();if(!e)return n.getText()==="defineWorkflow";for(const t of e.getDeclarations())if(i.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/workflow"?!1:t.getNameNode().getText()==="defineWorkflow";return!1},E=h("workflow"),S=n=>{const e=n.getExpression();if(!i.isPropertyAccessExpression(e)||!N.has(e.getName()))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:i.isIdentifier(t)&&t.getText()==="step"},D=n=>{const e=n.getProperty("handler");if(!e)return[];const t=i.isPropertyAssignment(e)?e.getInitializer():e;if(!t)return[];const o=[];for(const r of t.getDescendantsOfKind(x.CallExpression)){if(!S(r))continue;const s=r.getArguments()[0];!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s))||o.push({line:r.getStartLineNumber(),method:r.getExpression().getName(),name:s.getLiteralValue()})}return o},l=n=>{let e=n;for(;e&&(i.isAsExpression(e)||i.isSatisfiesExpression(e)||i.isParenthesizedExpression(e));)e=e.getExpression();return e},P=n=>{const e=l(n);if(e&&i.isObjectLiteralExpression(e))return e;if(!(!e||!i.isIdentifier(e)))for(const t of e.getSymbol()?.getDeclarations()??[]){const r=i.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===w.Const?l(t.getInitializer()):void 0;if(r&&i.isObjectLiteralExpression(r))return r}},W=(n,e)=>{const t=P(n.getArguments()[0]);if(!t)throw c(n,`workflow "${e}": defineWorkflow's argument must be an object literal, or a local \`const\` holding one — codegen reads \`name\` and the \`ctx.step.*\` calls out of it statically. Keep the handler wherever you like and pass it through: \`const config = { handler: myHandler }; export const ${e} = defineWorkflow(config);\`.`);const o={bindingName:g(e),className:d(e),exportName:e,name:u(e),steps:D(t)},r=t.getProperty("name");return r&&i.isPropertyAssignment(r)&&(o.name=E(r.getInitializerOrThrow(),e,"name")),o},I=n=>{const e=[];for(const t of n.getVariableDeclarations()){if(!t.isExported())continue;const o=b(t.getInitializer());if(!o)continue;const r=o.getExpression();if(!i.isIdentifier(r)||!y(r))continue;const s=t.getNameNode();if(!i.isIdentifier(s))throw c(s,"defineWorkflow exports must be plain named exports (no destructuring)");e.push(W(o,s.getText()))}return e},A=n=>{const e=new Map,t=new Map;for(const o of n){const r=e.get(o.name);if(r!==void 0)throw new a("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${o.name}": produced by both "${r}" and "${o.exportName}". Deployed workflow names must be unique across the project.`,{status:500});e.set(o.name,o.exportName);const s=t.get(o.bindingName);if(s!==void 0)throw new a("DUPLICATE_WORKFLOW_BINDING",`Duplicate workflow binding "${o.bindingName}": produced by both "${s}" and "${o.exportName}". Workflow export names must yield unique binding names.`,{status:500});t.set(o.bindingName,o.exportName)}},$=(n,e)=>{const t=m(e,k);if(!p(t))return[];const o=n.getSourceFile(t)??n.addSourceFileAtPath(t),r=I(o);return r.sort((s,f)=>s.exportName.localeCompare(f.exportName)),A(r),r};export{k as WORKFLOWS_FILENAME,$ as discoverWorkflows};
1
+ import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{LunoraError as a}from"@lunora/errors";import{workflowDefaultName as u,workflowClassName as d,workflowBindingName as g}from"@lunora/workflow";import{Node as i,VariableDeclarationKind as w,SyntaxKind as x}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{u as b,s as h}from"./ast-BYoSZlae.mjs";const k="workflows.ts",N=new Set(["do","sleep","sleepUntil","waitForEvent"]),y=n=>{const e=n.getSymbol();if(!e)return n.getText()==="defineWorkflow";for(const t of e.getDeclarations())if(i.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/workflow"?!1:t.getNameNode().getText()==="defineWorkflow";return!1},E=h("workflow"),S=n=>{const e=n.getExpression();if(!i.isPropertyAccessExpression(e)||!N.has(e.getName()))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:i.isIdentifier(t)&&t.getText()==="step"},D=n=>{const e=n.getProperty("handler");if(!e)return[];const t=i.isPropertyAssignment(e)?e.getInitializer():e;if(!t)return[];const o=[];for(const r of t.getDescendantsOfKind(x.CallExpression)){if(!S(r))continue;const s=r.getArguments()[0];!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s))||o.push({line:r.getStartLineNumber(),method:r.getExpression().getName(),name:s.getLiteralValue()})}return o},l=n=>{let e=n;for(;e&&(i.isAsExpression(e)||i.isSatisfiesExpression(e)||i.isParenthesizedExpression(e));)e=e.getExpression();return e},P=n=>{const e=l(n);if(e&&i.isObjectLiteralExpression(e))return e;if(!(!e||!i.isIdentifier(e)))for(const t of e.getSymbol()?.getDeclarations()??[]){const r=i.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===w.Const?l(t.getInitializer()):void 0;if(r&&i.isObjectLiteralExpression(r))return r}},W=(n,e)=>{const t=P(n.getArguments()[0]);if(!t)throw c(n,`workflow "${e}": defineWorkflow's argument must be an object literal, or a local \`const\` holding one — codegen reads \`name\` and the \`ctx.step.*\` calls out of it statically. Keep the handler wherever you like and pass it through: \`const config = { handler: myHandler }; export const ${e} = defineWorkflow(config);\`.`);const o={bindingName:g(e),className:d(e),exportName:e,name:u(e),steps:D(t)},r=t.getProperty("name");return r&&i.isPropertyAssignment(r)&&(o.name=E(r.getInitializerOrThrow(),e,"name")),o},I=n=>{const e=[];for(const t of n.getVariableDeclarations()){if(!t.isExported())continue;const o=b(t.getInitializer());if(!o)continue;const r=o.getExpression();if(!i.isIdentifier(r)||!y(r))continue;const s=t.getNameNode();if(!i.isIdentifier(s))throw c(s,"defineWorkflow exports must be plain named exports (no destructuring)");e.push(W(o,s.getText()))}return e},A=n=>{const e=new Map,t=new Map;for(const o of n){const r=e.get(o.name);if(r!==void 0)throw new a("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${o.name}": produced by both "${r}" and "${o.exportName}". Deployed workflow names must be unique across the project.`,{status:500});e.set(o.name,o.exportName);const s=t.get(o.bindingName);if(s!==void 0)throw new a("DUPLICATE_WORKFLOW_BINDING",`Duplicate workflow binding "${o.bindingName}": produced by both "${s}" and "${o.exportName}". Workflow export names must yield unique binding names.`,{status:500});t.set(o.bindingName,o.exportName)}},$=(n,e)=>{const t=m(e,k);if(!p(t))return[];const o=n.getSourceFile(t)??n.addSourceFileAtPath(t),r=I(o);return r.sort((s,f)=>s.exportName.localeCompare(f.exportName)),A(r),r};export{k as WORKFLOWS_FILENAME,$ as discoverWorkflows};
@@ -0,0 +1 @@
1
+ import{readdirSync as E,lstatSync as x}from"node:fs";import{join as f,extname as m,relative as h,sep as b,dirname as P}from"node:path";import{Node as r,SyntaxKind as S}from"ts-morph";import{diagnosticAt as w}from"./CodegenDiagnosticError-BUXlG3P-.mjs";const N=/\.ts$/u,c=(e,t)=>h(e,t).split(b).join("/").replace(N,""),g=(e,t=[],s=e)=>{let n;try{n=E(e)}catch{return t}for(const i of n){const o=f(e,i),a=x(o);if(a.isDirectory()){if(i==="_generated"||i==="node_modules")continue;g(o,t,s)}else if(a.isFile()&&m(i)===".ts"){if(i==="schema.ts"&&e===s)continue;t.push(o)}}return t},O=["src/server","src/index.ts","src/worker.ts"],v=new Set([".ts",".tsx"]),y=(e,t=[])=>{let s;try{s=x(e)}catch{return t}if(s.isFile())return v.has(m(e))&&t.push(e),t;if(!s.isDirectory())return t;for(const n of E(e))n==="_generated"||n==="node_modules"||y(f(e,n),t);return t},_=e=>{const t=P(e),s=g(e).map(i=>({displayPath:c(e,i),filePath:i})),n=new Set(s.map(i=>i.filePath));for(const i of O)for(const o of y(f(t,i)))n.has(o)||(n.add(o),s.push({displayPath:c(t,o),filePath:o}));return s},z=(e,t,s)=>{const n=[];for(const i of g(t)){const o=e.getSourceFile(i)??e.addSourceFileAtPath(i),a=c(t,i);for(const A of o.getDescendantsOfKind(S.CallExpression)){const p=s(A,a);p!==void 0&&n.push(p)}}return n},C=e=>{for(const t of e.getAncestors())if(r.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return""},V=(e,t)=>{if(t){const o=e.getArguments()[0];return o&&(r.isArrowFunction(o)||r.isFunctionExpression(o))?o:void 0}const s=e.getArguments()[0];if(!s||!r.isObjectLiteralExpression(s))return;const n=s.getProperty("handler");if(!n||!r.isPropertyAssignment(n))return;const i=n.getInitializer();return i&&(r.isArrowFunction(i)||r.isFunctionExpression(i))?i:void 0},K=(e,t)=>{if(!e||!r.isObjectLiteralExpression(e))return;const s=e.getProperty(t);return s&&r.isPropertyAssignment(s)?s.getInitializer():void 0},l=e=>r.isPropertyAccessExpression(e)&&e.getName()==="db"||r.isIdentifier(e)&&e.getText()==="db",T=new Set(["findFirst","findFirstOrThrow","findMany"]),j=e=>{const t=e.getExpression();if(!r.isPropertyAccessExpression(t)||!T.has(t.getName()))return;const s=t.getExpression();if(l(s)){const n=e.getArguments()[0];return{options:e.getArguments()[1],table:n&&r.isStringLiteral(n)?n.getLiteralText():""}}if(r.isPropertyAccessExpression(s)){const n=s.getExpression();if(l(n))return{options:e.getArguments()[0],table:s.getName()}}},u=(e,t)=>{const s=e.getExpression();return!r.isPropertyAccessExpression(s)||!t.has(s.getName())?!1:l(s.getExpression())},d=e=>{const t=e.getArguments()[0];return t&&r.isStringLiteral(t)?t.getLiteralText():""},$=(e,t,s)=>{const n=new Set,i=new Set;for(const o of e.getDescendantsOfKind(S.CallExpression))if(u(o,t)){const a=d(o);a!==""&&n.add(a)}else if(u(o,s)){const a=d(o);a!==""&&i.add(a)}return{tablesRead:[...n],tablesWritten:[...i]}},F=e=>{let t=e;for(;t&&(r.isAsExpression(t)||r.isSatisfiesExpression(t)||r.isParenthesizedExpression(t)||r.isNonNullExpression(t));)t=t.getExpression();return t},W=e=>{const t=F(e);return t&&r.isCallExpression(t)?t:void 0},k=e=>{const t=e.getExportAssignment(i=>!i.isExportEquals());if(!t)return;const s=t.getExpression();if(!r.isIdentifier(s))return s;const n=s.getSymbol()?.getValueDeclaration();return n&&r.isVariableDeclaration(n)?n.getInitializer():s},M=e=>{const t=e.getArguments()[1];return t&&r.isStringLiteral(t)?t.getLiteralValue():""},X=(e,t)=>{if(!r.isObjectLiteralExpression(e))return;const s=e.getProperty(t);if(!s||!r.isPropertyAssignment(s))return;const n=s.getInitializer();return n&&r.isStringLiteral(n)?n.getLiteralText():void 0},Y=e=>r.isIdentifier(e)&&e.getText()==="ctx",q=e=>(t,s,n)=>{if(r.isStringLiteral(t)||r.isNoSubstitutionTemplateLiteral(t))return t.getLiteralValue();throw w(t,`${e} "${s}": \`${n}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)};export{c as a,F as b,X as c,k as d,C as e,z as f,_ as g,V as h,l as i,M as j,Y as k,g as l,K as p,j as r,q as s,$ as t,W as u};
@@ -1,3 +1,3 @@
1
- import{G as S}from"./emit-Bo3kao_A.mjs";import{s as p}from"./paths-C-9fwEgQ.mjs";import{LUNORA_ERROR_CODES as O,objectSchema as h,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const E="/_lunora/rest",A=["authorization","cf-access-jwt-assertion","cookie","x-payment"],f=["x-d1-bookmark","x-lunora-shard-key"],P=e=>[...A,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],g=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,y=(...e)=>{const t=[];for(const r of e)for(const o of r?.split(",")??[]){const s=o.trim().toLowerCase();s!==""&&!t.includes(s)&&t.push(s)}return t.length===0?void 0:t.join(", ")},T=(e,t)=>{const r=[t,`max-age=${String(g(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(g(e.staleWhileRevalidate))}`),r.join(", ")},b=e=>e.scope==="public"?y(e.vary,...P(e),...f):y(e.vary,...f),x=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},N=e=>{const t=x(e);if(t!==void 0)return`${E}/${t.namespace}/${t.name}`},k=e=>e==="query"?"GET":"POST",m="#/components/responses/LunoraError",v=/:([A-Za-z_$][\w$]*)/gu,q=e=>[...e.matchAll(v)].map(t=>t[1]),_=e=>e.replaceAll(v,"{$1}"),l=e=>e.kind==="optional"?e.inner??e:e,j=e=>{const t=new Set(q(e.path)),r=[];for(const[o,s]of Object.entries(e.searchParams)){const c=l(s);r.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:s.kind!=="optional",schema:u(c)})}for(const[o,s]of Object.entries(e.params)){const c=l(s);r.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:s.kind!=="optional",schema:u(c)})}return r},$=e=>e?{content:{"application/json":{schema:u(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},C=e=>{const t=p(e.filePath),r=j(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${p(e.path)}`,responses:{200:$(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:m}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(o.parameters=r),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:h(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},w=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o={additionalProperties:!1,properties:{args:h(e.args),functionPath:{const:r,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${r}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:r,requestBody:{content:{"application/json":{schema:o}},required:!0},responses:{200:$(e.output),default:{$ref:m}},summary:`${e.kind}: ${r}`,tags:[t],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${r}`}},D=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},o={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:T(r,r.scope),type:"string"}}};r.tag!==void 0&&(o["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const s=b(r);return s!==void 0&&(o.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:s,type:"string"}}),{headers:o}},L=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o=N(r);if(o===void 0)return;const s=k(e.kind),c=s==="GET",d={description:`Public REST endpoint for the \`${e.kind}\` \`${r}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${p(o)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort).",...D(e.expose?.cache,c?"get":"post")},default:{$ref:m}},summary:`${s} ${o}`,tags:[t],"x-lunora-function-kind":e.kind};if(c){const n=Object.entries(e.args).map(([a,i])=>{const R=l(i);return{description:`Argument \`${a}\` (JSON-encoded for non-string values).`,in:"query",name:a,required:i.kind!=="optional",schema:u(R)}});return n.length>0&&(d.parameters=n),{method:"get",operation:d,path:o}}return d.requestBody={content:{"application/json":{schema:h(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:d,path:o}},I=e=>{const t=e.version??"0.0.0",r={},o=new Set;for(const n of e.httpRoutes){const a=_(n.path),i=r[a]??{};i[n.method.toLowerCase()]=C(n),r[a]=i,o.add(p(n.filePath))}const s=e.functions.filter(n=>n.visibility!=="internal"&&n.kind!=="stream");for(const n of s){const{operation:a,pathKey:i}=w(n);r[i]={post:a},o.add(p(n.filePath))}for(const n of s){if(n.expose?.rest!==!0)continue;const a=L(n);if(a===void 0)continue;const i=r[a.path]??{};i[a.method]=a.operation,r[a.path]=i}const c=[...o].toSorted((n,a)=>n.localeCompare(a)).map(n=>({description:`Operations declared in \`lunora/${n}\`.`,name:n}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:O,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:r,tags:c}},J=e=>`${JSON.stringify(I(e),void 0,2)}
1
+ import{G as S}from"./emit-BcAkLUfn.mjs";import{s as p}from"./paths-C-9fwEgQ.mjs";import{LUNORA_ERROR_CODES as O,objectSchema as h,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const E="/_lunora/rest",A=["authorization","cf-access-jwt-assertion","cookie","x-payment"],f=["x-d1-bookmark","x-lunora-shard-key"],P=e=>[...A,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],g=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,y=(...e)=>{const t=[];for(const r of e)for(const o of r?.split(",")??[]){const s=o.trim().toLowerCase();s!==""&&!t.includes(s)&&t.push(s)}return t.length===0?void 0:t.join(", ")},T=(e,t)=>{const r=[t,`max-age=${String(g(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(g(e.staleWhileRevalidate))}`),r.join(", ")},b=e=>e.scope==="public"?y(e.vary,...P(e),...f):y(e.vary,...f),x=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},N=e=>{const t=x(e);if(t!==void 0)return`${E}/${t.namespace}/${t.name}`},k=e=>e==="query"?"GET":"POST",m="#/components/responses/LunoraError",v=/:([A-Za-z_$][\w$]*)/gu,q=e=>[...e.matchAll(v)].map(t=>t[1]),_=e=>e.replaceAll(v,"{$1}"),l=e=>e.kind==="optional"?e.inner??e:e,j=e=>{const t=new Set(q(e.path)),r=[];for(const[o,s]of Object.entries(e.searchParams)){const c=l(s);r.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:s.kind!=="optional",schema:u(c)})}for(const[o,s]of Object.entries(e.params)){const c=l(s);r.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:s.kind!=="optional",schema:u(c)})}return r},$=e=>e?{content:{"application/json":{schema:u(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},C=e=>{const t=p(e.filePath),r=j(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${p(e.path)}`,responses:{200:$(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:m}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(o.parameters=r),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:h(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},w=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o={additionalProperties:!1,properties:{args:h(e.args),functionPath:{const:r,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${r}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:r,requestBody:{content:{"application/json":{schema:o}},required:!0},responses:{200:$(e.output),default:{$ref:m}},summary:`${e.kind}: ${r}`,tags:[t],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${r}`}},D=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},o={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:T(r,r.scope),type:"string"}}};r.tag!==void 0&&(o["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const s=b(r);return s!==void 0&&(o.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:s,type:"string"}}),{headers:o}},L=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o=N(r);if(o===void 0)return;const s=k(e.kind),c=s==="GET",d={description:`Public REST endpoint for the \`${e.kind}\` \`${r}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${p(o)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort).",...D(e.expose?.cache,c?"get":"post")},default:{$ref:m}},summary:`${s} ${o}`,tags:[t],"x-lunora-function-kind":e.kind};if(c){const n=Object.entries(e.args).map(([a,i])=>{const R=l(i);return{description:`Argument \`${a}\` (JSON-encoded for non-string values).`,in:"query",name:a,required:i.kind!=="optional",schema:u(R)}});return n.length>0&&(d.parameters=n),{method:"get",operation:d,path:o}}return d.requestBody={content:{"application/json":{schema:h(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:d,path:o}},I=e=>{const t=e.version??"0.0.0",r={},o=new Set;for(const n of e.httpRoutes){const a=_(n.path),i=r[a]??{};i[n.method.toLowerCase()]=C(n),r[a]=i,o.add(p(n.filePath))}const s=e.functions.filter(n=>n.visibility!=="internal"&&n.kind!=="stream");for(const n of s){const{operation:a,pathKey:i}=w(n);r[i]={post:a},o.add(p(n.filePath))}for(const n of s){if(n.expose?.rest!==!0)continue;const a=L(n);if(a===void 0)continue;const i=r[a.path]??{};i[a.method]=a.operation,r[a.path]=i}const c=[...o].toSorted((n,a)=>n.localeCompare(a)).map(n=>({description:`Operations declared in \`lunora/${n}\`.`,name:n}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:O,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:r,tags:c}},J=e=>`${JSON.stringify(I(e),void 0,2)}
2
2
  `,U=e=>`${S}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
3
3
  `;export{I as buildOpenApiDocument,J as emitOpenApi,U as emitOpenApiModule};
@@ -0,0 +1 @@
1
+ import{w as a}from"./classify-procedure-call-Ib2EMtFH.mjs";const l=s=>a(s,"use","rls");export{l as r};
@@ -1 +1 @@
1
- import{Node as o}from"ts-morph";import{b as a}from"./ast-CjWtsS6S.mjs";import{a as u}from"./module-specifiers-WF8iAydP.mjs";const T=t=>o.isIdentifier(t)?t.getText():o.isPropertyAccessExpression(t)?t.getName():void 0,y=(t,i)=>{const e=new Set;for(const r of t.getImportDeclarations())if(u(r.getModuleSpecifierValue()))for(const n of r.getNamedImports())n.getNameNode().getText()===i&&e.add(n.getAliasNode()?.getText()??n.getName());return e},x=(t,i)=>{if(o.isPropertyAccessExpression(t))return t.getName()===i;if(!o.isIdentifier(t))return!1;const e=t.getText();return e===i||y(t.getSourceFile(),i).has(e)},d=t=>{const i=t.getSymbol();if(!i)return t.getText();for(const e of i.getDeclarations())if(o.isImportSpecifier(e))return u(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText():void 0},p=t=>{const i=[];let e=a(t);for(;e&&o.isCallExpression(e);){const r=a(e.getExpression());if(!r||!o.isPropertyAccessExpression(r))return{root:void 0,steps:i};i.push({call:e,name:r.getName()}),e=a(r.getExpression())}return{root:e,steps:i}},f=t=>p(t).steps,N=(t,i,e)=>f(t).filter(r=>r.name===i).map(r=>r.call.getArguments()[0]).filter(r=>r!==void 0&&o.isCallExpression(r)&&x(r.getExpression(),e)),A=(t,i)=>f(t).some(e=>e.name===i),w=(t,i,e)=>N(t,i,e).length>0,l=new Set(["action","mutation","query","stream"]),m={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},I={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init"},b=t=>{const{root:i}=p(t);return i&&o.isIdentifier(i)?i:void 0},g=(t,i=!1)=>{const e=b(t);if(!e)return;const r=d(e);if(r===void 0){if(i)return;const n=e.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?g(s,!0):void 0}return}return l.has(r)?"public":m[r]?"internal":void 0},C=t=>{const i=t.getName();if(!l.has(i))return;const e=t.getExpression(),r=a(e)??e,n=e===r?[r]:[e,r];if(n.some(c=>c.getType().getProperty("__lunoraProcedure"))){const c=n.some(v=>v.getType().getProperty("__lunoraVisibility"));return{kind:i,receiver:r,visibility:c?"internal":"public"}}const s=g(r);if(s)return{kind:i,receiver:r,visibility:s}},P=t=>{const i=t.getExpression();if(o.isPropertyAccessExpression(i))return C(i);if(!o.isIdentifier(i))return;const e=d(i);if(!e)return;if(l.has(e))return{kind:e,visibility:"public"};const r=m[e];if(r)return{kind:r,visibility:"internal"};const n=I[e];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}};export{T as a,f as b,P as c,w as d,A as e,N as w};
1
+ import{Node as o}from"ts-morph";import{b as a}from"./ast-BYoSZlae.mjs";import{a as u}from"./module-specifiers-WF8iAydP.mjs";const T=t=>o.isIdentifier(t)?t.getText():o.isPropertyAccessExpression(t)?t.getName():void 0,y=(t,i)=>{const e=new Set;for(const r of t.getImportDeclarations())if(u(r.getModuleSpecifierValue()))for(const n of r.getNamedImports())n.getNameNode().getText()===i&&e.add(n.getAliasNode()?.getText()??n.getName());return e},x=(t,i)=>{if(o.isPropertyAccessExpression(t))return t.getName()===i;if(!o.isIdentifier(t))return!1;const e=t.getText();return e===i||y(t.getSourceFile(),i).has(e)},d=t=>{const i=t.getSymbol();if(!i)return t.getText();for(const e of i.getDeclarations())if(o.isImportSpecifier(e))return u(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText():void 0},p=t=>{const i=[];let e=a(t);for(;e&&o.isCallExpression(e);){const r=a(e.getExpression());if(!r||!o.isPropertyAccessExpression(r))return{root:void 0,steps:i};i.push({call:e,name:r.getName()}),e=a(r.getExpression())}return{root:e,steps:i}},f=t=>p(t).steps,N=(t,i,e)=>f(t).filter(r=>r.name===i).map(r=>r.call.getArguments()[0]).filter(r=>r!==void 0&&o.isCallExpression(r)&&x(r.getExpression(),e)),A=(t,i)=>f(t).some(e=>e.name===i),w=(t,i,e)=>N(t,i,e).length>0,l=new Set(["action","mutation","query","stream"]),m={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},I={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init"},b=t=>{const{root:i}=p(t);return i&&o.isIdentifier(i)?i:void 0},g=(t,i=!1)=>{const e=b(t);if(!e)return;const r=d(e);if(r===void 0){if(i)return;const n=e.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?g(s,!0):void 0}return}return l.has(r)?"public":m[r]?"internal":void 0},C=t=>{const i=t.getName();if(!l.has(i))return;const e=t.getExpression(),r=a(e)??e,n=e===r?[r]:[e,r];if(n.some(c=>c.getType().getProperty("__lunoraProcedure"))){const c=n.some(v=>v.getType().getProperty("__lunoraVisibility"));return{kind:i,receiver:r,visibility:c?"internal":"public"}}const s=g(r);if(s)return{kind:i,receiver:r,visibility:s}},P=t=>{const i=t.getExpression();if(o.isPropertyAccessExpression(i))return C(i);if(!o.isIdentifier(i))return;const e=d(i);if(!e)return;if(l.has(e))return{kind:e,visibility:"public"};const r=m[e];if(r)return{kind:r,visibility:"internal"};const n=I[e];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}};export{T as a,f as b,P as c,w as d,A as e,N as w};
@@ -1 +1 @@
1
- import{Node as i,SyntaxKind as c}from"ts-morph";import{l,a as d,h as f}from"./ast-CjWtsS6S.mjs";import{c as u}from"./classify-procedure-call-AKeIK05y.mjs";const x=e=>{const n=e.getInitializer();if(!n||!i.isCallExpression(n))return;const r=u(n);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const t=f(n,r.receiver);return t?{exportName:e.getName(),handler:t,kind:r.kind}:void 0},p=(e,n)=>{if(!i.isPropertyAccessExpression(e)||e.getName()!==n)return;const r=e.getExpression();if(!i.isIdentifier(r)||r.getText()!=="ctx")return;const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?`ctx.${n}.${t.getName()}`:`ctx.${n}`},m=(e,n,r)=>{const t=[];for(const o of e.handler.getDescendantsOfKind(c.PropertyAccessExpression)){const s=p(o,r);s!==void 0&&t.push({callee:s,exportName:e.exportName,file:n,kind:e.kind,line:o.getStartLineNumber()})}return t},g=(e,n,r)=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const s of o.getDeclarations()){const a=x(s);a&&t.push(...m(a,n,r))}return t},N=(e,n,r)=>{const t=[];for(const o of l(n)){const s=e.getSourceFile(o)??e.addSourceFileAtPath(o);t.push(...g(s,d(n,o),r))}return t};export{N as d};
1
+ import{Node as i,SyntaxKind as c}from"ts-morph";import{l,a as d,h as f}from"./ast-BYoSZlae.mjs";import{c as u}from"./classify-procedure-call-Ib2EMtFH.mjs";const x=e=>{const n=e.getInitializer();if(!n||!i.isCallExpression(n))return;const r=u(n);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const t=f(n,r.receiver);return t?{exportName:e.getName(),handler:t,kind:r.kind}:void 0},p=(e,n)=>{if(!i.isPropertyAccessExpression(e)||e.getName()!==n)return;const r=e.getExpression();if(!i.isIdentifier(r)||r.getText()!=="ctx")return;const t=e.getParent();return t&&i.isPropertyAccessExpression(t)&&t.getExpression()===e?`ctx.${n}.${t.getName()}`:`ctx.${n}`},m=(e,n,r)=>{const t=[];for(const o of e.handler.getDescendantsOfKind(c.PropertyAccessExpression)){const s=p(o,r);s!==void 0&&t.push({callee:s,exportName:e.exportName,file:n,kind:e.kind,line:o.getStartLineNumber()})}return t},g=(e,n,r)=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const s of o.getDeclarations()){const a=x(s);a&&t.push(...m(a,n,r))}return t},N=(e,n,r)=>{const t=[];for(const o of l(n)){const s=e.getSourceFile(o)??e.addSourceFileAtPath(o);t.push(...g(s,d(n,o),r))}return t};export{N as d};
@@ -1 +1 @@
1
- import{SyntaxKind as p,Node as s}from"ts-morph";import{l as f,a as g,e as d}from"./ast-CjWtsS6S.mjs";const m=r=>{const t=r.getExpression();if(!s.isPropertyAccessExpression(t))return!1;const e=t.getExpression();return s.isPropertyAccessExpression(e)?e.getName()==="authApi":s.isIdentifier(e)&&e.getText()==="authApi"},h=r=>{const t=r.getArguments()[0];if(t===void 0)return!1;if(!s.isObjectLiteralExpression(t))return!0;for(const e of t.getProperties())if((s.isPropertyAssignment(e)||s.isShorthandPropertyAssignment(e))&&e.getName()==="headers"||s.isSpreadAssignment(e))return!0;return!1},P=(r,t)=>{const e=[];for(const n of f(t)){const c=r.getSourceFile(n)??r.addSourceFileAtPath(n),l=g(t,n);for(const i of c.getDescendantsOfKind(p.CallExpression)){if(!m(i))continue;const o=d(i);if(o==="")continue;const a=i.getExpression(),u=s.isPropertyAccessExpression(a)?a.getName():"";e.push({exportName:o,file:l,hasHeaders:h(i),line:i.getStartLineNumber(),method:u})}}return e};export{P as default};
1
+ import{SyntaxKind as p,Node as s}from"ts-morph";import{l as f,a as g,e as d}from"./ast-BYoSZlae.mjs";const m=r=>{const t=r.getExpression();if(!s.isPropertyAccessExpression(t))return!1;const e=t.getExpression();return s.isPropertyAccessExpression(e)?e.getName()==="authApi":s.isIdentifier(e)&&e.getText()==="authApi"},h=r=>{const t=r.getArguments()[0];if(t===void 0)return!1;if(!s.isObjectLiteralExpression(t))return!0;for(const e of t.getProperties())if((s.isPropertyAssignment(e)||s.isShorthandPropertyAssignment(e))&&e.getName()==="headers"||s.isSpreadAssignment(e))return!0;return!1},P=(r,t)=>{const e=[];for(const n of f(t)){const c=r.getSourceFile(n)??r.addSourceFileAtPath(n),l=g(t,n);for(const i of c.getDescendantsOfKind(p.CallExpression)){if(!m(i))continue;const o=d(i);if(o==="")continue;const a=i.getExpression(),u=s.isPropertyAccessExpression(a)?a.getName():"";e.push({exportName:o,file:l,hasHeaders:h(i),line:i.getStartLineNumber(),method:u})}}return e};export{P as default};