@lunora/codegen 1.0.0-alpha.92 → 1.0.0-alpha.94

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 (68) hide show
  1. package/dist/index.d.mts +16 -0
  2. package/dist/index.d.ts +16 -0
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/AGENTS_FILENAME-Dk-k250h.mjs +1 -0
  5. package/dist/packem_shared/CONTAINERS_FILENAME-DQpyhY6c.mjs +1 -0
  6. package/dist/packem_shared/FLAGS_FILENAME-Boqm0YCP.mjs +1 -0
  7. package/dist/packem_shared/GENERATED_HEADER-CzjybmTV.mjs +1 -0
  8. package/dist/packem_shared/LUNORA_ERROR_CODES-zfAI2OFs.mjs +1 -0
  9. package/dist/packem_shared/{MUTATORS_FILENAME-DY3rgWGl.mjs → MUTATORS_FILENAME-Cp_JxLSz.mjs} +1 -1
  10. package/dist/packem_shared/NOTIFY_FILENAME-DwyJ5I4Q.mjs +1 -0
  11. package/dist/packem_shared/OPENRPC_VERSION-5uSsJTUF.mjs +3 -0
  12. package/dist/packem_shared/QUEUES_FILENAME-QpMZsde0.mjs +1 -0
  13. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-BaZ2lWSm.mjs +9 -0
  14. package/dist/packem_shared/{SHAPES_FILENAME-BdLj5-mD.mjs → SHAPES_FILENAME-WxXOsYfe.mjs} +1 -1
  15. package/dist/packem_shared/SchemaSnapshotParseError-BkgxjBPQ.mjs +16 -0
  16. package/dist/packem_shared/WORKFLOWS_FILENAME-Dz80zqeT.mjs +1 -0
  17. package/dist/packem_shared/buildOpenApiDocument-C-oA9yKS.mjs +3 -0
  18. package/dist/packem_shared/discover-ast-7ABwvTVn.mjs +1 -0
  19. package/dist/packem_shared/discover-queries-i4Vd2si7.mjs +1 -0
  20. package/dist/packem_shared/discoverAuthApiCalls-XfNbxqlq.mjs +1 -0
  21. package/dist/packem_shared/discoverCrons-RlATa0_t.mjs +1 -0
  22. package/dist/packem_shared/discoverFunctions-4TNKUv7P.mjs +1 -0
  23. package/dist/packem_shared/discoverHttpRoutes-DQivLBqT.mjs +1 -0
  24. package/dist/packem_shared/discoverInserts-D6szWzrV.mjs +1 -0
  25. package/dist/packem_shared/discoverMaskProcedures-BBPqLXA5.mjs +1 -0
  26. package/dist/packem_shared/discoverMigrations-rbjxflR8.mjs +1 -0
  27. package/dist/packem_shared/discoverNondeterministicCalls-Bxr652Rz.mjs +1 -0
  28. package/dist/packem_shared/discoverQueries-uFtLDmn_.mjs +1 -0
  29. package/dist/packem_shared/discoverR2sqlCalls-DMxG6gHr.mjs +1 -0
  30. package/dist/packem_shared/discoverRlsMetadata-B63ARnKG.mjs +1 -0
  31. package/dist/packem_shared/discoverSandboxUsage-DBM98vVh.mjs +1 -0
  32. package/dist/packem_shared/discoverSchema-BNr7PVcZ.mjs +1 -0
  33. package/dist/packem_shared/discoverStorageRulesMetadata-_40MGqRX.mjs +1 -0
  34. package/dist/packem_shared/{emit-DMvG162j.mjs → emit-QxfTfRoJ.mjs} +300 -561
  35. package/dist/packem_shared/{emitApp--dJ6EnFn.mjs → emitApp-Fnuxk68h.mjs} +4 -3
  36. package/dist/packem_shared/formatAdvisories-CQvIhQ04.mjs +2 -0
  37. package/dist/packem_shared/parse-validator-CusS8QwU.mjs +1 -0
  38. package/package.json +9 -9
  39. package/dist/packem_shared/AGENTS_FILENAME-BesaDYkL.mjs +0 -1
  40. package/dist/packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs +0 -1
  41. package/dist/packem_shared/FLAGS_FILENAME-CHaH6obH.mjs +0 -1
  42. package/dist/packem_shared/GENERATED_HEADER-CUBdTCVk.mjs +0 -1
  43. package/dist/packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs +0 -1
  44. package/dist/packem_shared/NOTIFY_FILENAME-CDvoTY3Y.mjs +0 -1
  45. package/dist/packem_shared/OPENRPC_VERSION-aq5eyIkd.mjs +0 -3
  46. package/dist/packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs +0 -1
  47. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-ChA6rpGP.mjs +0 -9
  48. package/dist/packem_shared/SchemaSnapshotParseError-BJkhTEpi.mjs +0 -16
  49. package/dist/packem_shared/WORKFLOWS_FILENAME-ClsYRKXp.mjs +0 -1
  50. package/dist/packem_shared/buildOpenApiDocument-Bw3MChvT.mjs +0 -3
  51. package/dist/packem_shared/discover-ast-CezKqEhE.mjs +0 -1
  52. package/dist/packem_shared/discover-queries-BmZeJ--u.mjs +0 -1
  53. package/dist/packem_shared/discoverAuthApiCalls-BgL6nj03.mjs +0 -1
  54. package/dist/packem_shared/discoverCrons-WJscxQFl.mjs +0 -1
  55. package/dist/packem_shared/discoverFunctions-BgGmxEqW.mjs +0 -1
  56. package/dist/packem_shared/discoverHttpRoutes-eW8RbVOr.mjs +0 -1
  57. package/dist/packem_shared/discoverInserts-BCz6zpI0.mjs +0 -1
  58. package/dist/packem_shared/discoverMaskProcedures-DLfQRsQc.mjs +0 -1
  59. package/dist/packem_shared/discoverMigrations-Cbc4W765.mjs +0 -1
  60. package/dist/packem_shared/discoverNondeterministicCalls-x9IhWxPP.mjs +0 -1
  61. package/dist/packem_shared/discoverQueries-Cf0LGoQG.mjs +0 -1
  62. package/dist/packem_shared/discoverR2sqlCalls--MSfSeDm.mjs +0 -1
  63. package/dist/packem_shared/discoverRlsMetadata-DTRS0ROc.mjs +0 -1
  64. package/dist/packem_shared/discoverSandboxUsage-BDyeyuYo.mjs +0 -1
  65. package/dist/packem_shared/discoverSchema-DSJSX4Ss.mjs +0 -1
  66. package/dist/packem_shared/discoverStorageRulesMetadata-Cic97L-2.mjs +0 -1
  67. package/dist/packem_shared/formatAdvisories-BCEfzLT0.mjs +0 -2
  68. package/dist/packem_shared/parse-validator-CkLxY-Mr.mjs +0 -1
package/dist/index.d.mts CHANGED
@@ -1953,6 +1953,21 @@ interface ProjectIR {
1953
1953
  migrations: ReadonlyArray<MigrationIR>;
1954
1954
  schema: SchemaIR;
1955
1955
  }
1956
+ /**
1957
+ * One import of a migrated-away platform's SDK still present in `lunora/`
1958
+ * source. Structurally identical to the advisor's `AdvisorStaleMigrationImport`
1959
+ * so it passes through the feeder without conversion.
1960
+ */
1961
+ interface StaleMigrationImportIR {
1962
+ /** Source file relative to the lunora dir, no extension. */
1963
+ file: string;
1964
+ /** 1-based line of the import, or `0` when unknown. */
1965
+ line: number;
1966
+ /** The imported module, e.g. `@supabase/supabase-js`. */
1967
+ moduleSpecifier: string;
1968
+ /** Which migration guide covers this platform. */
1969
+ platform: "convex" | "firebase" | "supabase";
1970
+ }
1956
1971
  /**
1957
1972
  * Named inputs for {@link lintSchema}. Every feeder is a discrete key rather than
1958
1973
  * a positional argument: the feeder list grows every few releases and many IR
@@ -2009,6 +2024,7 @@ interface LintSchemaOptions {
2009
2024
  shapes?: ReadonlyArray<ShapeIR>;
2010
2025
  softDeleteReads?: ReadonlyArray<SoftDeleteReadIR>;
2011
2026
  sqlInterpolations?: ReadonlyArray<SqlInterpolationIR>;
2027
+ staleMigrationImports?: ReadonlyArray<StaleMigrationImportIR>;
2012
2028
  storageKeyAccesses?: ReadonlyArray<StorageKeyAccessIR>;
2013
2029
  storageUploads?: ReadonlyArray<StorageUploadIR>;
2014
2030
  unrestrictedWhereBranches?: ReadonlyArray<UnrestrictedWhereBranchIR>;
package/dist/index.d.ts CHANGED
@@ -1953,6 +1953,21 @@ interface ProjectIR {
1953
1953
  migrations: ReadonlyArray<MigrationIR>;
1954
1954
  schema: SchemaIR;
1955
1955
  }
1956
+ /**
1957
+ * One import of a migrated-away platform's SDK still present in `lunora/`
1958
+ * source. Structurally identical to the advisor's `AdvisorStaleMigrationImport`
1959
+ * so it passes through the feeder without conversion.
1960
+ */
1961
+ interface StaleMigrationImportIR {
1962
+ /** Source file relative to the lunora dir, no extension. */
1963
+ file: string;
1964
+ /** 1-based line of the import, or `0` when unknown. */
1965
+ line: number;
1966
+ /** The imported module, e.g. `@supabase/supabase-js`. */
1967
+ moduleSpecifier: string;
1968
+ /** Which migration guide covers this platform. */
1969
+ platform: "convex" | "firebase" | "supabase";
1970
+ }
1956
1971
  /**
1957
1972
  * Named inputs for {@link lintSchema}. Every feeder is a discrete key rather than
1958
1973
  * a positional argument: the feeder list grows every few releases and many IR
@@ -2009,6 +2024,7 @@ interface LintSchemaOptions {
2009
2024
  shapes?: ReadonlyArray<ShapeIR>;
2010
2025
  softDeleteReads?: ReadonlyArray<SoftDeleteReadIR>;
2011
2026
  sqlInterpolations?: ReadonlyArray<SqlInterpolationIR>;
2027
+ staleMigrationImports?: ReadonlyArray<StaleMigrationImportIR>;
2012
2028
  storageKeyAccesses?: ReadonlyArray<StorageKeyAccessIR>;
2013
2029
  storageUploads?: ReadonlyArray<StorageUploadIR>;
2014
2030
  unrestrictedWhereBranches?: ReadonlyArray<UnrestrictedWhereBranchIR>;
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-CFhF_hmg.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-BCEfzLT0.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l}from"./packem_shared/describeErrorLevelFindings-IhNx9gPr.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-BesaDYkL.mjs";import{default as O}from"./packem_shared/discoverAuthApiCalls-BgL6nj03.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as C}from"./packem_shared/CONTAINERS_FILENAME-CFwdyaCI.mjs";import{default as h}from"./packem_shared/discoverCrons-WJscxQFl.mjs";import{FLAGS_FILENAME as _,discoverFlags as L}from"./packem_shared/FLAGS_FILENAME-CHaH6obH.mjs";import{discoverFunctions as T}from"./packem_shared/discoverFunctions-BgGmxEqW.mjs";import{default as D}from"./packem_shared/discoverHttpRoutes-eW8RbVOr.mjs";import{default as H}from"./packem_shared/discoverInserts-BCz6zpI0.mjs";import{default as y}from"./packem_shared/discoverMaskProcedures-DLfQRsQc.mjs";import{default as W}from"./packem_shared/discoverMigrations-Cbc4W765.mjs";import{MUTATORS_FILENAME as V,discoverMutators as j}from"./packem_shared/MUTATORS_FILENAME-DY3rgWGl.mjs";import{default as Q}from"./packem_shared/discoverNondeterministicCalls-x9IhWxPP.mjs";import{NOTIFY_FILENAME as w,discoverNotifyCalls as B,discoverNotifyConfig as K}from"./packem_shared/NOTIFY_FILENAME-CDvoTY3Y.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-CogJX1Ia.mjs";import{y as X}from"./packem_shared/discover-queries-BmZeJ--u.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-CSE6i-ld.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls--MSfSeDm.mjs";import{discoverRlsMetadata as ae,default as ie}from"./packem_shared/discoverRlsMetadata-DTRS0ROc.mjs";import{discoverSandboxUsage as de}from"./packem_shared/discoverSandboxUsage-BDyeyuYo.mjs";import{default as pe}from"./packem_shared/discoverSchema-DSJSX4Ss.mjs";import{SHAPES_FILENAME as ne,discoverShapes as le}from"./packem_shared/SHAPES_FILENAME-BdLj5-mD.mjs";import{default as Ee}from"./packem_shared/discoverStorageRulesMetadata-Cic97L-2.mjs";import{WORKFLOWS_FILENAME as Ae,discoverWorkflows as ue}from"./packem_shared/WORKFLOWS_FILENAME-ClsYRKXp.mjs";import{S as Ne,c as Oe,C as ge,E as Re,s as Ce,A as Me,g as he,$ as Ie,q as _e,B as Le,x as Fe,N as Te,l as Pe,T as De}from"./packem_shared/emit-DMvG162j.mjs";import{emitApp as He}from"./packem_shared/emitApp--dJ6EnFn.mjs";import{buildOpenApiDocument as ye,emitOpenApi as Ge,emitOpenApiModule as We}from"./packem_shared/buildOpenApiDocument-Bw3MChvT.mjs";import{OPENRPC_VERSION as Ve,buildOpenRpcDocument as je,emitOpenRpc as ze,emitOpenRpcModule as Qe}from"./packem_shared/OPENRPC_VERSION-aq5eyIkd.mjs";import{DEFAULT_TARGET as we,platformMatrixIds as Be,readProjectTarget as Ke,resolveCodegenTarget as Je}from"./packem_shared/DEFAULT_TARGET-CH5disA3.mjs";import{SCHEMA_SNAPSHOT_FILENAME as $e,createCodegenProject as Xe,refreshCodegenProject as Ze,runCodegen as er}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-ChA6rpGP.mjs";import{SchemaSnapshotParseError as or,buildSchemaSnapshot as tr,evaluateSchemaDrift as sr,parseSchemaSnapshot as ar}from"./packem_shared/SchemaSnapshotParseError-BJkhTEpi.mjs";import{schemaFromIr as mr}from"./packem_shared/schemaFromIr-R1ZFzVyy.mjs";import{LUNORA_ERROR_CODES as fr,validatorIrToJsonSchema as pr}from"./packem_shared/LUNORA_ERROR_CODES-Um9hC1gr.mjs";import{redact as nr,secretKindOf as lr}from"./packem_shared/redact-6jD4lAhq.mjs";import{MESSAGE_SOLUTIONS as Er,findSolutionByMessage as xr}from"@lunora/errors";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,E as CodegenDiagnosticError,we as DEFAULT_TARGET,_ as FLAGS_FILENAME,Ne as GENERATED_HEADER,fr as LUNORA_ERROR_CODES,Er as LUNORA_SOLUTION_RULES,V as MUTATORS_FILENAME,w as NOTIFY_FILENAME,Ve as OPENRPC_VERSION,ee as QUEUES_FILENAME,$e as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,ne as SHAPES_FILENAME,or as SchemaSnapshotParseError,e as VERSION,Ae as WORKFLOWS_FILENAME,ye as buildOpenApiDocument,je as buildOpenRpcDocument,tr as buildSchemaSnapshot,Xe as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,O as discoverAuthApiCalls,C as discoverContainers,h as discoverCrons,L as discoverFlags,T as discoverFunctions,D as discoverHttpRoutes,H as discoverInserts,y as discoverMaskProcedures,W as discoverMigrations,j as discoverMutators,Q as discoverNondeterministicCalls,B as discoverNotifyCalls,K as discoverNotifyConfig,X as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,ae as discoverRlsMetadata,ie as discoverRlsProcedures,de as discoverSandboxUsage,pe as discoverSchema,le as discoverShapes,Ee as discoverStorageRulesMetadata,ue as discoverWorkflows,Oe as emitAgents,ge as emitApi,He as emitApp,Re as emitCollections,Ce as emitContainers,Me as emitCrons,he as emitDataModel,Ie as emitDrizzleSchema,_e as emitFunctions,Ge as emitOpenApi,We as emitOpenApiModule,ze as emitOpenRpc,Qe as emitOpenRpcModule,Le as emitServer,Fe as emitShard,Te as emitVectors,Pe as emitWorkflows,De as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,sr as evaluateSchemaDrift,xr as findLunoraSolution,m as formatAdvisories,d as lintSchema,ar as parseSchemaSnapshot,Be as platformMatrixIds,Y as readPackageDependencies,Ke as readProjectTarget,nr as redact,Ze as refreshCodegenProject,Je as resolveCodegenTarget,er as runCodegen,mr as schemaFromIr,lr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,pr as validatorIrToJsonSchema};
1
+ import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as p}from"./packem_shared/formatAdvisories-CQvIhQ04.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l}from"./packem_shared/describeErrorLevelFindings-IhNx9gPr.mjs";import{CodegenDiagnosticError as E,diagnosticAt as x}from"./packem_shared/CodegenDiagnosticError-DPezpZTz.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-Dk-k250h.mjs";import{default as O}from"./packem_shared/discoverAuthApiCalls-XfNbxqlq.mjs";import{CONTAINERS_FILENAME as g,discoverContainers as C}from"./packem_shared/CONTAINERS_FILENAME-DQpyhY6c.mjs";import{default as h}from"./packem_shared/discoverCrons-RlATa0_t.mjs";import{FLAGS_FILENAME as L,discoverFlags as _}from"./packem_shared/FLAGS_FILENAME-Boqm0YCP.mjs";import{discoverFunctions as T}from"./packem_shared/discoverFunctions-4TNKUv7P.mjs";import{default as D}from"./packem_shared/discoverHttpRoutes-DQivLBqT.mjs";import{default as H}from"./packem_shared/discoverInserts-D6szWzrV.mjs";import{default as y}from"./packem_shared/discoverMaskProcedures-BBPqLXA5.mjs";import{default as V}from"./packem_shared/discoverMigrations-rbjxflR8.mjs";import{MUTATORS_FILENAME as k,discoverMutators as Q}from"./packem_shared/MUTATORS_FILENAME-Cp_JxLSz.mjs";import{default as z}from"./packem_shared/discoverNondeterministicCalls-Bxr652Rz.mjs";import{NOTIFY_FILENAME as B,discoverNotifyCalls as K,discoverNotifyConfig as q}from"./packem_shared/NOTIFY_FILENAME-DwyJ5I4Q.mjs";import{default as Y}from"./packem_shared/readPackageDependencies-CogJX1Ia.mjs";import{y as X}from"./packem_shared/discover-queries-i4Vd2si7.mjs";import{QUEUES_FILENAME as ee,discoverQueues as re}from"./packem_shared/QUEUES_FILENAME-QpMZsde0.mjs";import{default as te}from"./packem_shared/discoverR2sqlCalls-DMxG6gHr.mjs";import{discoverRlsMetadata as ae,default as ie}from"./packem_shared/discoverRlsMetadata-B63ARnKG.mjs";import{discoverSandboxUsage as de}from"./packem_shared/discoverSandboxUsage-DBM98vVh.mjs";import{default as fe}from"./packem_shared/discoverSchema-BNr7PVcZ.mjs";import{SHAPES_FILENAME as ne,discoverShapes as le}from"./packem_shared/SHAPES_FILENAME-WxXOsYfe.mjs";import{default as Ee}from"./packem_shared/discoverStorageRulesMetadata-_40MGqRX.mjs";import{WORKFLOWS_FILENAME as Ae,discoverWorkflows as ue}from"./packem_shared/WORKFLOWS_FILENAME-Dz80zqeT.mjs";import{S as Ne,h as Oe,P as Re,B as ge,p as Ce,L as Me,R as he,C as Ie,V as Le,Q as _e,$ as Fe,E as Te,m as Pe,F as De}from"./packem_shared/emit-QxfTfRoJ.mjs";import{emitApp as He}from"./packem_shared/emitApp-Fnuxk68h.mjs";import{buildOpenApiDocument as ye,emitOpenApi as Ge,emitOpenApiModule as Ve}from"./packem_shared/buildOpenApiDocument-C-oA9yKS.mjs";import{OPENRPC_VERSION as ke,buildOpenRpcDocument as Qe,emitOpenRpc as je,emitOpenRpcModule as ze}from"./packem_shared/OPENRPC_VERSION-5uSsJTUF.mjs";import{DEFAULT_TARGET as Be,platformMatrixIds as Ke,readProjectTarget as qe,resolveCodegenTarget as Je}from"./packem_shared/DEFAULT_TARGET-CH5disA3.mjs";import{SCHEMA_SNAPSHOT_FILENAME as $e,createCodegenProject as Xe,refreshCodegenProject as Ze,runCodegen as er}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-BaZ2lWSm.mjs";import{SchemaSnapshotParseError as or,buildSchemaSnapshot as tr,evaluateSchemaDrift as sr,parseSchemaSnapshot as ar}from"./packem_shared/SchemaSnapshotParseError-BkgxjBPQ.mjs";import{schemaFromIr as mr}from"./packem_shared/schemaFromIr-R1ZFzVyy.mjs";import{LUNORA_ERROR_CODES as pr,validatorIrToJsonSchema as fr}from"./packem_shared/LUNORA_ERROR_CODES-zfAI2OFs.mjs";import{redact as nr,secretKindOf as lr}from"./packem_shared/redact-6jD4lAhq.mjs";import{MESSAGE_SOLUTIONS as Er,findSolutionByMessage as xr}from"@lunora/errors";const e="0.0.0";export{u as AGENTS_FILENAME,g as CONTAINERS_FILENAME,E as CodegenDiagnosticError,Be as DEFAULT_TARGET,L as FLAGS_FILENAME,Ne as GENERATED_HEADER,pr as LUNORA_ERROR_CODES,Er as LUNORA_SOLUTION_RULES,k as MUTATORS_FILENAME,B as NOTIFY_FILENAME,ke as OPENRPC_VERSION,ee as QUEUES_FILENAME,$e as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,ne as SHAPES_FILENAME,or as SchemaSnapshotParseError,e as VERSION,Ae as WORKFLOWS_FILENAME,ye as buildOpenApiDocument,Qe as buildOpenRpcDocument,tr as buildSchemaSnapshot,Xe as createCodegenProject,c as describeErrorLevelFindings,x as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,O as discoverAuthApiCalls,C as discoverContainers,h as discoverCrons,_ as discoverFlags,T as discoverFunctions,D as discoverHttpRoutes,H as discoverInserts,y as discoverMaskProcedures,V as discoverMigrations,Q as discoverMutators,z as discoverNondeterministicCalls,K as discoverNotifyCalls,q as discoverNotifyConfig,X as discoverQueries,re as discoverQueues,te as discoverR2sqlCalls,ae as discoverRlsMetadata,ie as discoverRlsProcedures,de as discoverSandboxUsage,fe as discoverSchema,le as discoverShapes,Ee as discoverStorageRulesMetadata,ue as discoverWorkflows,Oe as emitAgents,Re as emitApi,He as emitApp,ge as emitCollections,Ce as emitContainers,Me as emitCrons,he as emitDataModel,Ie as emitDrizzleSchema,Le as emitFunctions,Ge as emitOpenApi,Ve as emitOpenApiModule,je as emitOpenRpc,ze as emitOpenRpcModule,_e as emitServer,Fe as emitShard,Te as emitVectors,Pe as emitWorkflows,De as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,sr as evaluateSchemaDrift,xr as findLunoraSolution,m as formatAdvisories,d as lintSchema,ar as parseSchemaSnapshot,Ke as platformMatrixIds,Y as readPackageDependencies,qe as readProjectTarget,nr as redact,Ze as refreshCodegenProject,Je as resolveCodegenTarget,er as runCodegen,mr as schemaFromIr,lr as secretKindOf,a as serializeSchemaSnapshot,p as toAdvisorContext,fr as validatorIrToJsonSchema};
@@ -0,0 +1 @@
1
+ import{existsSync as l}from"node:fs";import{join as p}from"node:path";import{agentDefaultName as d,agentClassName as f,agentBindingName as N,voiceBindingName as b,voiceClassName as x}from"@lunora/agent/naming";import{LunoraError as g}from"@lunora/errors";import{Node as s,SyntaxKind as u}from"ts-morph";import{diagnosticAt as m}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{T as A,v as w}from"./discover-ast-7ABwvTVn.mjs";const h="agents.ts",y=o=>{const t=o.getSymbol();if(!t)return o.getText()==="defineAgent";for(const n of t.getDeclarations())if(s.isImportSpecifier(n))return n.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/agent"?!1:n.getNameNode().getText()==="defineAgent";return!1},E=w("agent"),T=(o,t,n)=>{if(o.getKind()===u.TrueKeyword)return!0;if(o.getKind()===u.FalseKeyword)return!1;throw m(o,`agent "${t}": \`${n}\` must be a static boolean literal — it is deploy configuration codegen writes into the ctx.agents wiring spec`)},D=(o,t)=>{const n=o.getArguments()[0];if(!n||!s.isObjectLiteralExpression(n))throw m(o,`agent "${t}": defineAgent must be passed an inline object literal`);const i={bindingName:N(t),className:f(t),exportName:t,name:d(t)},e=n.getProperty("name");e&&s.isPropertyAssignment(e)&&(i.name=E(e.getInitializerOrThrow(),t,"name"));const r=n.getProperty("publicRun");r&&s.isPropertyAssignment(r)&&T(r.getInitializerOrThrow(),t,"publicRun")&&(i.publicRun=!0);const a=n.getProperty("voice");if(a&&s.isPropertyAssignment(a)){const c=a.getInitializerOrThrow();if(!s.isObjectLiteralExpression(c))throw m(c,`agent "${t}": \`voice\` must be an inline object literal — its presence tells codegen to emit the voice-session Durable Object`);i.voice=!0,i.voiceBindingName=b(t),i.voiceClassName=x(t)}return n.getProperty("onEmail")&&(i.onEmail=!0),i},I=o=>{const t=[];for(const n of o.getVariableDeclarations()){if(!n.isExported())continue;const i=A(n.getInitializer());if(!i)continue;const e=i.getExpression();if(!s.isIdentifier(e)||!y(e))continue;const r=n.getNameNode();if(!s.isIdentifier(r))throw m(r,"defineAgent exports must be plain named exports (no destructuring)");t.push(D(i,r.getText()))}return t},$=o=>{const t=new Map,n=new Map,i=new Map;for(const e of o){const r=t.get(e.name);if(r!==void 0)throw new g("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 a=n.get(e.bindingName);if(a!==void 0)throw new g("DUPLICATE_AGENT_BINDING",`Duplicate agent binding "${e.bindingName}": produced by both "${a}" and "${e.exportName}". Agent export names must yield unique binding names.`,{status:500});n.set(e.bindingName,e.exportName);const c=i.get(e.className);if(c!==void 0)throw new g("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});i.set(e.className,e.exportName)}},M=(o,t)=>{const n=p(t,h);if(!l(n))return[];const i=o.getSourceFile(n)??o.addSourceFileAtPath(n),e=I(i);return e.sort((r,a)=>r.exportName.localeCompare(a.exportName)),$(e),e};export{h as AGENTS_FILENAME,M as discoverAgents};
@@ -0,0 +1 @@
1
+ import{existsSync as f}from"node:fs";import{join as p}from"node:path";import{containerClassName as d,containerBindingName as b,normalizeContainerImage as g}from"@lunora/container";import{SyntaxKind as y,Node as n}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{v as N}from"./discover-ast-7ABwvTVn.mjs";const x="containers.ts",L=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},u=N("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`)},h=(e,t)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e))return g(e.getLiteralValue());if(n.isObjectLiteralExpression(e)){const i=e.getProperty("registry");if(i&&n.isPropertyAssignment(i)){const o=i.getInitializerOrThrow();return g({registry:u(o,t,"image.registry")})}const r=e.getProperty("build");if(r&&n.isPropertyAssignment(r)){const o=r.getInitializerOrThrow();return g({build:u(o,t,"image.build")})}}throw c(e,`container "${t}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},T=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},w=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},I=e=>{if(n.isTrueLiteral(e))return!0;if(n.isFalseLiteral(e))return!1},P=e=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e))return e.getLiteralValue()},k=(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`)},S=(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:b(t),className:d(t),exportName:t,image:{buildContext:".",dockerfilePath:"./Dockerfile",kind:"dockerfile"}};let o=!1;for(const s of i.getProperties()){if(!n.isPropertyAssignment(s))continue;const l=s.getName(),a=s.getInitializerOrThrow();switch(l){case"buildArgs":{r.buildArgs=T(a);break}case"enableInternet":{r.enableInternet=I(a);break}case"image":{r.image=h(a,t),o=!0;break}case"instanceType":{r.instanceType=k(a,t);break}case"maxInstances":{r.maxInstances=m(a,t,"maxInstances");break}case"name":{r.name=u(a,t,"name");break}case"rollout":{r.rollout=w(a);break}case"sleepAfter":{r.sleepAfter=P(a);break}}}if(!o)throw c(i,`container "${t}": defineContainer requires a static \`image\` property`);return r},A=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,s=o.getExpression();if(!n.isIdentifier(s)||!L(s))continue;const l=i.getNameNode();if(!n.isIdentifier(l))throw c(l,"defineContainer exports must be plain named exports (no destructuring)");t.push(S(o,l.getText()))}return t},z=(e,t)=>{const i=p(t,x);if(!f(i))return[];const r=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=A(r);return o.sort((s,l)=>s.exportName.localeCompare(l.exportName)),o};export{x as CONTAINERS_FILENAME,z as discoverContainers};
@@ -0,0 +1 @@
1
+ import{existsSync as l}from"node:fs";import{join as p}from"node:path";import{SyntaxKind as c,Node as i}from"ts-morph";import{g as f,I as u,C as d,z as g}from"./discover-ast-7ABwvTVn.mjs";const m="flags.ts",x=new Set(["boolean","number","object","string"]),y="@lunora/flags/providers/flagship",S=t=>{const s=t.getSymbol();if(!s)return t.getText()==="flagshipProvider";for(const e of s.getDeclarations())if(i.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!==y?!1:e.getNameNode().getText()==="flagshipProvider";return!1},E=(t,s)=>{const e=t.getProperty(s);if(!e||!i.isPropertyAssignment(e))return;const r=e.getInitializerOrThrow();if(i.isStringLiteral(r)||i.isNoSubstitutionTemplateLiteral(r))return r.getLiteralValue()},h=t=>{const s=t.getArguments()[0];if(s&&i.isObjectLiteralExpression(s)){const e=E(s,"binding");if(e!==void 0&&e.length>0)return{bindingName:e,mode:"binding",provider:"flagship"}}return{mode:"http",provider:"flagship"}},v=t=>d(t.getArguments()[0],"provider"),I=(t,s)=>{const e=p(s,m);if(!l(e))return;const r=t.getSourceFile(e)??t.addSourceFileAtPath(e),o=u(r);if(!o||!i.isCallExpression(o))return{provider:"custom"};const a=v(o);if(a&&i.isCallExpression(a)){const n=a.getExpression();if(i.isIdentifier(n)&&S(n))return h(a)}return{provider:"custom"}},A=t=>{const s=t.getName();if(!x.has(s))return;const e=t.getExpression();if(!i.isPropertyAccessExpression(e))return;if(e.getName()==="flags"&&g(e.getExpression()))return s;const r=e.getExpression();if(e.getName()==="details"&&i.isPropertyAccessExpression(r)&&r.getName()==="flags"&&g(r.getExpression()))return s},b=t=>{const s=t.getExpression();if(!i.isPropertyAccessExpression(s))return;const e=A(s);if(e===void 0)return;const r=t.getArguments()[0];if(!r||!(i.isStringLiteral(r)||i.isNoSubstitutionTemplateLiteral(r)))return;const o=r.getLiteralValue();return o.length>0?{key:o,type:e}:void 0},k=(t,s)=>{const e=new Map;for(const r of f(s)){const o=t.getSourceFile(r)??t.addSourceFileAtPath(r);for(const a of o.getDescendantsOfKind(c.CallExpression)){const n=b(a);n&&!e.has(n.key)&&e.set(n.key,n.type)}}return[...e.entries()].map(([r,o])=>({key:r,type:o})).toSorted((r,o)=>r.key.localeCompare(o.key))};export{m as FLAGS_FILENAME,k as discoverFlagKeys,I as discoverFlags};
@@ -0,0 +1 @@
1
+ import"@lunora/agent/component";import"@lunora/errors";import"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{S as r,d as o,a as n,h as E,P as l,B as A,p as S,L as p,R as C,C as d,V as g,f as u,M as c,Q as D,$ as R,E as f,m as h,F as B}from"./emit-QxfTfRoJ.mjs";import"./paths-BmX5O1sG.mjs";export{r as GENERATED_HEADER,o as UMBRELLA_BASE_PACKAGES,n as buildStorageColumns,E as emitAgents,l as emitApi,A as emitCollections,S as emitContainers,p as emitCrons,C as emitDataModel,d as emitDrizzleSchema,g as emitFunctions,u as emitQueues,c as emitSeed,D as emitServer,R as emitShard,f as emitVectors,h as emitWorkflows,B as emitWranglerCronTriggers};
@@ -0,0 +1 @@
1
+ import{jsonSchemaFromNode as n,objectSchemaFromNodes as a}from"@lunora/values";const N=t=>{if(t===void 0)return{};const e=t.trim();if(e==="true")return{const:!0};if(e==="false")return{const:!1};if(e==="null")return{const:null,type:"null"};if(e.startsWith('"')&&e.endsWith('"'))try{return{const:JSON.parse(e),type:"string"}}catch{return{const:e.slice(1,-1),type:"string"}}if(e.startsWith("'")&&e.endsWith("'"))return{const:e.slice(1,-1),type:"string"};const r=Number(e);return Number.isNaN(r)?{const:e}:{const:r}},s={constraints:()=>{},inner:t=>t.inner,isNullable:t=>t.column?.notNull===!1,kind:t=>t.kind,literalSchema:t=>N(t.literalValue),members:t=>t.members??[],shape:t=>t.shape??{},tableName:t=>t.tableName,valueChild:t=>t.valueType},l=t=>n(t,s),o=t=>a(t,s),O=["BAD_REQUEST","CONFLICT","COUNT_RLS_UNSUPPORTED","FORBIDDEN","FUNCTION_NOT_FOUND","INTERNAL","INTERNAL_SERVER_ERROR","METHOD_NOT_ALLOWED","NOT_FOUND","NOT_IMPLEMENTED","PAYLOAD_TOO_LARGE","TOO_MANY_REQUESTS","UNAUTHORIZED","UNPROCESSABLE","VALIDATION_ERROR"];export{O as LUNORA_ERROR_CODES,N as literalConst,o as objectSchema,l as validatorIrToJsonSchema};
@@ -1 +1 @@
1
- import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{Node as o,SyntaxKind as c}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{unwrapHandlerReturn as g}from"./discoverFunctions-BgGmxEqW.mjs";import{t as d}from"./module-specifiers-8FEEiUcv.mjs";import{f as x}from"./parse-validator-CkLxY-Mr.mjs";const y="mutators.ts",f=d,E=r=>{const e=r.getSymbol();if(!e)return r.getText()==="defineMutator";for(const t of e.getDeclarations())if(o.isImportSpecifier(t))return f(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMutator":!1;return!1},N=r=>{const e=r.getSymbol();if(!e)return!1;for(const t of e.getDeclarations()){if(!o.isNamespaceImport(t))continue;const i=t.getFirstAncestorByKind(c.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},I=r=>{if(o.isIdentifier(r))return E(r);if(o.isPropertyAccessExpression(r)){const e=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(e)&&N(e)}return!1},S=r=>{const e=r.getArguments()[0];return e&&o.isObjectLiteralExpression(e)?e:void 0},A=r=>{const e=r?.getProperty("args");if(!e||!o.isPropertyAssignment(e))return{};const t=e.getInitializer();return t&&o.isObjectLiteralExpression(t)?x(t):{}},M=r=>{const e=r?.getProperty("server");if(!e||!o.isPropertyAssignment(e))return"unknown";const t=e.getInitializer();return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":g(t)},P=r=>{const e=[];for(const t of r.getVariableDeclarations()){if(!t.isExported())continue;const i=t.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const n=i,a=n.getExpression();if(!I(a))continue;const s=t.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineMutator exports must be plain named exports (no destructuring)");const u=S(n);e.push({args:A(u),exportName:s.getText(),filePath:"mutators",returnType:M(u)})}return e},j=(r,e)=>{const t=m(e,y);if(!p(t))return[];const i=r.getSourceFile(t)??r.addSourceFileAtPath(t),n=P(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{y as MUTATORS_FILENAME,j as discoverMutators,I as isDefineMutatorCallee};
1
+ import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{Node as o,SyntaxKind as c}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{unwrapHandlerReturn as g}from"./discoverFunctions-4TNKUv7P.mjs";import{t as d}from"./module-specifiers-8FEEiUcv.mjs";import{g as x}from"./parse-validator-CusS8QwU.mjs";const y="mutators.ts",f=d,E=r=>{const e=r.getSymbol();if(!e)return r.getText()==="defineMutator";for(const t of e.getDeclarations())if(o.isImportSpecifier(t))return f(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMutator":!1;return!1},N=r=>{const e=r.getSymbol();if(!e)return!1;for(const t of e.getDeclarations()){if(!o.isNamespaceImport(t))continue;const i=t.getFirstAncestorByKind(c.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},I=r=>{if(o.isIdentifier(r))return E(r);if(o.isPropertyAccessExpression(r)){const e=r.getExpression();return r.getName()==="defineMutator"&&o.isIdentifier(e)&&N(e)}return!1},S=r=>{const e=r.getArguments()[0];return e&&o.isObjectLiteralExpression(e)?e:void 0},A=r=>{const e=r?.getProperty("args");if(!e||!o.isPropertyAssignment(e))return{};const t=e.getInitializer();return t&&o.isObjectLiteralExpression(t)?x(t):{}},M=r=>{const e=r?.getProperty("server");if(!e||!o.isPropertyAssignment(e))return"unknown";const t=e.getInitializer();return!t||!(o.isArrowFunction(t)||o.isFunctionExpression(t))?"unknown":g(t)},P=r=>{const e=[];for(const t of r.getVariableDeclarations()){if(!t.isExported())continue;const i=t.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const n=i,a=n.getExpression();if(!I(a))continue;const s=t.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineMutator exports must be plain named exports (no destructuring)");const u=S(n);e.push({args:A(u),exportName:s.getText(),filePath:"mutators",returnType:M(u)})}return e},j=(r,e)=>{const t=m(e,y);if(!p(t))return[];const i=r.getSourceFile(t)??r.addSourceFileAtPath(t),n=P(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{y as MUTATORS_FILENAME,j as discoverMutators,I as isDefineMutatorCallee};
@@ -0,0 +1 @@
1
+ import{existsSync as m}from"node:fs";import{join as g}from"node:path";import{SyntaxKind as u,Node as c}from"ts-morph";import{g as d,p as x,I as y,w as E}from"./discover-ast-7ABwvTVn.mjs";import{classifyProcedureCall as P}from"./discoverFunctions-4TNKUv7P.mjs";const N="notify.ts",A=new Set(["chat","inApp","send","webhook"]),l=new Set(["broadcast","send"]),S=e=>{const t=e.getInitializer();if(!t||!c.isCallExpression(t))return;const s=P(t);if(!s)return;const r=E(t,s.receiver);return r?{exportName:e.getName(),handler:r,kind:s.kind}:void 0},h=e=>{const t=[];for(const s of e.getVariableStatements())if(s.isExported())for(const r of s.getDeclarations()){const o=S(r);o&&t.push(o)}return t},a=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"&&a(s)==="notify")return"push"},F=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),s=a(e.getExpression());if(s==="notify"&&A.has(t))return`ctx.notify.${t}`;if(s==="push"&&l.has(t))return`ctx.push.${t}`},b=e=>c.isPropertyAccessExpression(e)?a(e.getExpression())==="push"&&l.has(e.getName()):!1,D=(e,t)=>{const s=[];for(const r of d(t)){const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),f=x(t,r);for(const n of h(o))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(u.PropertyAccessExpression)){const p=F(i);p!==void 0&&s.push({callee:p,exportName:n.exportName,file:f,kind:n.kind,line:i.getStartLineNumber()})}}return s},v=(e,t)=>{for(const s of d(t)){const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const o of h(r))for(const f of o.handler.getDescendantsOfKind(u.PropertyAccessExpression))if(b(f))return!0}return!1},K=(e,t)=>{const s=g(t,N);if(!m(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),o=y(r);let f=!1,n=!1;if(o&&c.isCallExpression(o)){const i=o.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(f=i.getProperty("webPush")!==void 0,n=i.getProperty("fcm")!==void 0)}return{hasFcm:n,hasWebPush:f,usesPush:v(e,t)}};export{N as NOTIFY_FILENAME,D as discoverNotifyCalls,K as discoverNotifyConfig};
@@ -0,0 +1,3 @@
1
+ import{S as a}from"./emit-QxfTfRoJ.mjs";import{n as i}from"./paths-BmX5O1sG.mjs";import{objectSchema as s,LUNORA_ERROR_CODES as c}from"./LUNORA_ERROR_CODES-zfAI2OFs.mjs";const m="1.3.2",p={description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."},u=e=>{const t=i(e.filePath),r=`${t}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${r}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${r}", "args": { … } }\`).`,errors:c.map((o,n)=>({code:-32e3-n,data:{code:o},message:o})),name:r,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:s(e.args)}],result:{name:"result",schema:p},summary:`${e.kind}: ${r}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:t}]}},d=e=>{const t=e.version??"0.0.0",r=e.functions.filter(o=>o.visibility!=="internal"&&o.kind!=="stream").map(o=>u(o)).toSorted((o,n)=>o.name.localeCompare(n.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:t},methods:r,openrpc:m}},R=e=>`${JSON.stringify(d(e),void 0,2)}
2
+ `,O=e=>`${a}export const openRpcSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
3
+ `;export{m as OPENRPC_VERSION,d as buildOpenRpcDocument,R as emitOpenRpc,O as emitOpenRpcModule};
@@ -0,0 +1 @@
1
+ import{existsSync as d}from"node:fs";import{join as g}from"node:path";import{LunoraError as p}from"@lunora/errors";import{queueDefaultName as l,queueBindingName as f}from"@lunora/queue";import{SyntaxKind as N,Node as u}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{v as h}from"./discover-ast-7ABwvTVn.mjs";const x="queues.ts",b=i=>{const t=i.getSymbol();if(!t)return i.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"),y=(i,t,e)=>{if(u.isNumericLiteral(i))return i.getLiteralValue();throw a(i,`queue "${t}": \`${e}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},w=(i,t)=>{const e=i.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},E=(i,t)=>{const e=i.getArguments()[0];if(!e||!u.isObjectLiteralExpression(e))throw a(i,`queue "${t}": defineQueue must be passed an inline object literal`);const n={bindingName:f(t),exportName:t,mode:"push",name:w(e,t)??l(t),tuning:{}},o=e.getProperty("mode");if(o&&u.isPropertyAssignment(o)){const r=c(o.getInitializerOrThrow(),t,"mode");if(r!=="push"&&r!=="pull")throw a(o,`queue "${t}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(r)})`);n.mode=r}const s=e.getProperty("deadLetterQueue");s&&u.isPropertyAssignment(s)&&(n.tuning.deadLetterQueue=c(s.getInitializerOrThrow(),t,"deadLetterQueue"));for(const r of["maxBatchSize","maxBatchTimeout","maxRetries","retryDelay"]){const m=e.getProperty(r);m&&u.isPropertyAssignment(m)&&(n.tuning[r]=y(m.getInitializerOrThrow(),t,r))}return n},q=i=>{const t=[];for(const e of i.getVariableDeclarations()){if(!e.isExported())continue;const n=e.getInitializer();if(n?.getKind()!==N.CallExpression)continue;const o=n,s=o.getExpression();if(!u.isIdentifier(s)||!b(s))continue;const r=e.getNameNode();if(!u.isIdentifier(r))throw a(r,"defineQueue exports must be plain named exports (no destructuring)");t.push(E(o,r.getText()))}return t},I=i=>{const t=new Map,e=new Map;for(const n of i){const o=t.get(n.name);if(o!==void 0)throw new p("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 p("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=(i,t)=>{const e=g(t,x);if(!d(e))return[];const n=i.getSourceFile(e)??i.addSourceFileAtPath(e),o=q(n);return o.sort((s,r)=>s.exportName.localeCompare(r.exportName)),I(o),o};export{x as QUEUES_FILENAME,T as discoverQueues};
@@ -0,0 +1,9 @@
1
+ import{existsSync as b,mkdirSync as qt,readFileSync as dt,writeFileSync as Bt,rmSync as Ut}from"node:fs";import{join as g,dirname as le}from"node:path";import{performance as ue}from"node:perf_hooks";import{runAdvisor as Vt}from"@lunora/advisor";import{LunoraError as k}from"@lunora/errors";import{SyntaxKind as l,Node as o,Project as Ge}from"ts-morph";import{serializeSchemaSnapshot as Wt}from"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{toAdvisorContext as _t}from"./formatAdvisories-CQvIhQ04.mjs";import{discoverAgents as Gt}from"./AGENTS_FILENAME-Dk-k250h.mjs";import{discoverContainers as Ht}from"./CONTAINERS_FILENAME-DQpyhY6c.mjs";import{diagnosticAt as Z}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as Y}from"./module-specifiers-8FEEiUcv.mjs";import{r as de,Q as Qt,R as Jt,a as Xt,P as Zt,V as Yt,$ as es,B as ts,p as ss,m as rs,h as ns,f as is,L as os,E as as,C as cs,M as ls,F as us}from"./emit-QxfTfRoJ.mjs";import{g as h,p as E,P as N,C as $,O as gt,z as ds,R as pt,h as gs}from"./discover-ast-7ABwvTVn.mjs";import ps from"./readPackageDependencies-CogJX1Ia.mjs";import{discoverQueues as fs}from"./QUEUES_FILENAME-QpMZsde0.mjs";import{discoverSandboxUsage as ms}from"./discoverSandboxUsage-DBM98vVh.mjs";import hs from"./discoverStorageRulesMetadata-_40MGqRX.mjs";import{discoverWorkflows as xs}from"./WORKFLOWS_FILENAME-Dz80zqeT.mjs";import{gatePlatformFeatures as Es,resolveCodegenTarget as ys}from"./DEFAULT_TARGET-CH5disA3.mjs";import{i as I,a as D,e as x,c as A,r as $s,b as vs,s as ee,d as bs,f as Ns,y as Ss}from"./discover-queries-i4Vd2si7.mjs";import{classifyProcedureCall as M,inlineHandler as As,procedureHandler as ft,chainUsesWrappedCall as mt,isDatabaseAccessor as R,chainHasStep as ws,discoverFunctions as Ps,resolveStandardSchemaType as Is}from"./discoverFunctions-4TNKUv7P.mjs";import Ts from"./discoverAuthApiCalls-XfNbxqlq.mjs";import Ls from"./discoverCrons-RlATa0_t.mjs";import{discoverFlagKeys as ks}from"./FLAGS_FILENAME-Boqm0YCP.mjs";import Ds from"./discoverHttpRoutes-DQivLBqT.mjs";import Os from"./discoverInserts-D6szWzrV.mjs";import Cs,{discoverMaskStrategies as Fs,discoverMaskMetadata as Ks,discoverMaskHasNonLiteralPolicy as Rs}from"./discoverMaskProcedures-BBPqLXA5.mjs";import Ms from"./discoverMigrations-rbjxflR8.mjs";import{MUTATORS_FILENAME as js,isDefineMutatorCallee as zs,discoverMutators as qs}from"./MUTATORS_FILENAME-Cp_JxLSz.mjs";import Bs from"./discoverNondeterministicCalls-Bxr652Rz.mjs";import{discoverNotifyConfig as Us,discoverNotifyCalls as Vs}from"./NOTIFY_FILENAME-DwyJ5I4Q.mjs";import Ws from"./discoverR2sqlCalls-DMxG6gHr.mjs";import _s,{discoverRlsMetadata as Gs}from"./discoverRlsMetadata-B63ARnKG.mjs";import Hs from"./discoverSchema-BNr7PVcZ.mjs";import{secretKindOf as Qs,redact as Js,isHeuristicSecretKind as Xs,isSecretishName as Zs}from"./redact-6jD4lAhq.mjs";import{discoverShapes as Ys}from"./SHAPES_FILENAME-WxXOsYfe.mjs";import{emitApp as er}from"./emitApp-Fnuxk68h.mjs";import{buildOpenApiDocument as tr,emitOpenApiModule as sr}from"./buildOpenApiDocument-C-oA9yKS.mjs";import{buildOpenRpcDocument as rr,emitOpenRpcModule as nr}from"./OPENRPC_VERSION-5uSsJTUF.mjs";import{y as ir}from"./parse-validator-CusS8QwU.mjs";import{buildSchemaSnapshot as or}from"./SchemaSnapshotParseError-BkgxjBPQ.mjs";const ar=e=>{const t=[],s=e.tables.filter(r=>r.shardMode==="global");return s.some(r=>r.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(r=>r.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},cr=(e,t)=>{if(t===void 0)return;const s=ar(e).filter(i=>!t.has(i.name));if(s.length===0)return;const r=s.map(i=>` - ${i.name} — ${i.reason}`).join(`
2
+ `);throw new k("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
3
+ ${r}
4
+
5
+ Install them with your package manager, then re-run codegen.`)},lr="env.ts",ur=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return Y(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},dr=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(l.ImportDeclaration);return r!==void 0&&Y(r.getModuleSpecifierValue())}return!1},gr=e=>{if(o.isIdentifier(e))return ur(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&o.isIdentifier(t)&&dr(t)}return!1},pr=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==l.CallExpression||!gr(r.getExpression()))continue;const i=s.getNameNode();if(!o.isIdentifier(i))throw Z(i,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:i.getText()})}return t},fr=(e,t)=>{const s=g(t,lr);if(!b(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=pr(r);if(i.length!==0){if(i.length>1)throw Z(r,`lunora/env.ts declares ${i.length.toString()} defineEnv() contracts (${i.map(n=>n.exportName).join(", ")}); exactly one is allowed`);return i[0]}},mr=e=>{const t=r=>o.isIdentifier(r)&&r.getText()==="ctx",s=new Set;for(const r of e.getDescendantsOfKind(l.PropertyAccessExpression))t(r.getExpression())&&s.add(r.getName());for(const r of e.getDescendantsOfKind(l.VariableDeclaration)){const i=r.getInitializer(),n=r.getNameNode();if(!(i===void 0||!t(i)||!o.isObjectBindingPattern(n)))for(const a of n.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},hr=(e,t)=>{const s=Object.fromEntries(de.map(r=>[r.key,!1]));for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=new Set(i.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=mr(i);for(const c of de)if(!s[c.key]){if(n.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(de.every(c=>s[c.key]))break}return s},xr=["providerSubscriptionId","state"],Er=["providerEventId","processedAt"],He=(e,t)=>t.every(s=>s in e.shape),yr=e=>{const t=e.find(r=>r.name==="subscriptions"),s=e.find(r=>r.name==="events");return t!==void 0&&s!==void 0&&He(t,xr)&&He(s,Er)},$r=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings/analytics"),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/kv"),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/vectors"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),ht="identity.ts",vr=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return Y(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},br=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const r=s.getFirstAncestorByKind(l.ImportDeclaration);return r!==void 0&&Y(r.getModuleSpecifierValue())}return!1},Nr=e=>{if(o.isIdentifier(e))return vr(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&o.isIdentifier(t)&&br(t)}return!1},Sr=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const r=s.getInitializer();if(r?.getKind()!==l.CallExpression||!Nr(r.getExpression()))continue;const i=s.getNameNode();if(!o.isIdentifier(i))throw Z(i,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:i.getText()})}return t},Ar=(e,t)=>{const s=g(t,ht);if(!b(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Sr(r);if(i.length!==0){if(i.length>1)throw Z(r,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(n=>n.exportName).join(", ")}); exactly one is allowed`);return i[0]}},wr=(e,t)=>{const s=new Map,r=new Map,i=new Map;for(const n of e)s.set(n.name,`workflow "${n.exportName}"`),r.set(n.bindingName,`workflow "${n.exportName}"`),i.set(n.className,`workflow "${n.exportName}"`);for(const n of t){const a=s.get(n.name);if(a!==void 0)throw new k("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${n.name}": produced by both ${a} and agent "${n.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=r.get(n.bindingName);if(c!==void 0)throw new k("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${n.bindingName}": produced by both ${c} and agent "${n.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=i.get(n.className);if(u!==void 0)throw new k("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${n.className}": produced by both ${u} and agent "${n.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},Pr=e=>{const{lunoraDirectory:t,project:s,projectRoot:r,schema:i}=e,n=Ar(s,t),a=fr(s,t),c=xs(s,t),u=fs(s,t),d=Gt(s,t);wr(c,d);const y=Ht(s,t),w=hs(s,t),p=Es(hr(s,t),ys(r,e.target)),v=p.usage,C=ms(s,t),j=v.browser||C.usesSandboxBrowser,z=ps(r),U=z??new Set,T=U.has("lunorash");cr(i,z);const F=b(g(t,"flags.ts")),q=b(g(t,"notify.ts"));return{agents:d,containers:y,dataModelContent:Jt(i),declaredDependencies:z,dependencies:U,env:a,featureUsage:v,hasBrowser:j,hasFlags:F,hasNotify:q,identity:n,platformGate:p,queues:u,serverContent:Qt({agents:d,containers:y,env:a,hasAccessFacade:v.access,hasAi:v.ai,hasAnalytics:v.analytics,hasBrowser:j,hasFlags:F,hasHyperdrive:v.hyperdrive,hasImages:v.images,hasKv:v.kv,hasNotify:q,hasPayments:v.payments,hasPipelines:v.pipelines,hasR2sql:v.r2sql,hasX402:v.x402,identity:n,queues:u,schema:i,storageRuleBuckets:w.rules.map(se=>se.bucket),useUmbrella:T,workflows:c}),storageRulesMetadata:w,usesSandbox:C.usesSandboxBrowser||C.usesSandboxContainer,useUmbrella:T,workflows:c}},xt=new Set(["delete","get","head","options","patch","post","put"]),Ir=new Set(["handler","stream"]),Tr=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,Qe=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Lr=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!xt.has(t.getName()))return;const s=t.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpRoute")return;const r=e.getArguments()[0];if(!(!r||!o.isStringLiteral(r)))return{method:t.getName().toUpperCase(),path:r.getLiteralValue()}},kr=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;o.isCallExpression(s);){const r=s.getExpression();if(!o.isPropertyAccessExpression(r)||xt.has(r.getName()))break;s=r.getExpression()}return Lr(s)},Dr=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(Qe.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&Qe.has(s.getText()))return!0}return!1},Or=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const r=s.getExpression();if(!o.isPropertyAccessExpression(r)||!Ir.has(r.getName()))return;const i=kr(s);if(!i||!Tr.test(i.path))return;const n=s.getArguments()[0],a=n!==void 0&&(o.isArrowFunction(n)||o.isFunctionExpression(n))&&Dr(n);return{exportName:e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},Cr=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const i of r.getDeclarations()){const n=Or(i,t);n&&s.push(n)}return s},Fr=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Cr(i,E(t,r)))}return s},Kr=e=>!o.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Rr=(e,t)=>{if(!Kr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!I(s)||D(s)))return{exportName:x(e),file:t,line:e.getStartLineNumber()}},Mr=(e,t)=>N(e,t,Rr),jr=new Set(["generateText","streamText"]),zr=new Set(["messages","prompt","system"]),qr=[{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"]}],Br=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),r=t.getExpression().getText();for(const i of qr)if(i.methods.has(s)&&i.prefixes.some(n=>r===n||r.startsWith(`${n}.`)))return`${r}.${s}`},Ur=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=Br(t);if(s!==void 0)return s}},Vr=e=>{const t=new Set,s=e.getFirstAncestor(n=>o.isArrowFunction(n)||o.isFunctionExpression(n)||o.isFunctionDeclaration(n)),[r]=s?.getParameters()??[],i=r?.getNameNode();if(i===void 0||!o.isObjectBindingPattern(i))return t;for(const n of i.getElements()){const a=n.getPropertyNameNode()?.getText()??n.getName(),c=n.getNameNode();if(a==="args"&&o.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},Wr=e=>{if($s(e))return!0;const t=Vr(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},_r=e=>{for(const t of e.getProperties()){if(!o.isPropertyAssignment(t)||!zr.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&Wr(s))return!0}return!1},Gr=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const i=A(r.getExpression());if(i===void 0||!jr.has(i))continue;const[n]=r.getArguments();if(n===void 0||!o.isObjectLiteralExpression(n))continue;let a;for(const c of n.getDescendantsOfKind(l.CallExpression))if(A(c.getExpression())==="tool"&&(a=Ur(c),a!==void 0))break;a!==void 0&&s.push({exportName:x(r),file:t,line:r.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:_r(n)})}return s},Hr=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Gr(i,E(t,r)))}return s},Qr=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return o.isIdentifier(t)&&t.getText()==="ctx"},Jr=(e,t)=>{if(!Qr(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!I(s)))return{exportName:x(e),file:t,line:e.getStartLineNumber()}},Xr=(e,t)=>N(e,t,Jr),Et=e=>e.getProperties().some(t=>o.isSpreadAssignment(t)),Zr=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 r=s.getInitializer();return!r||!o.isObjectLiteralExpression(r)?{objects:[],opaque:!0}:{objects:[r],opaque:Et(r)}},Yr=e=>{const t=[];let s=!1,r=e;for(;o.isCallExpression(r);){const i=r.getExpression();if(!o.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const n=r.getArguments()[0];n&&o.isObjectLiteralExpression(n)?(t.push(n),s||=Et(n)):s=!0}r=i.getExpression()}return{objects:t,opaque:s}},yt=(e,t)=>t?Yr(t):Zr(e),en=e=>e.flatMap(t=>t.getProperties().filter(s=>o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)).map(s=>s.getName())),tn=/\.check\(|\.meta\(|length|max/iu,sn=/\bv\.any\s*\(/u,rn=/\bv\.string\s*\(/u,nn=e=>sn.test(e),on=e=>rn.test(e)&&!tn.test(e),an=e=>{const t=[],s=[];for(const r of e)for(const i of r.getProperties()){if(!o.isPropertyAssignment(i))continue;const n=i.getInitializer();if(!n)continue;const a=n.getText(),c=i.getName();nn(a)?t.push(c):on(a)&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},cn=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const r=M(s);if(r?.visibility!=="public")return;const{objects:i}=yt(s,r.receiver),{anyArgs:n,unboundedStringArgs:a}=an(i);if(!(n.length===0&&a.length===0))return{anyArgs:n,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},ln=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const i of r.getDeclarations()){const n=cn(i,t);n&&s.push(n)}return s},un=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...ln(i,E(t,r)))}return s},ge=e=>e?.getKind()===l.TrueKeyword,dn=e=>e?.getKind()===l.FalseKeyword,gn=e=>e!==void 0&&o.isNumericLiteral(e)&&e.getLiteralValue()===0,pn=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),fn=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isCallExpression(t)&&A(t.getExpression())==="scim"),mn=e=>e!==void 0&&o.isCallExpression(e)&&pn.has(A(e.getExpression())??""),hn=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isStringLiteral(t)&&t.getLiteralText()==="*"),xn=e=>{const t=$(e,"advanced"),s=$(e,"emailAndPassword"),r=$(e,"session");return{analyzable:!0,disableCsrfCheck:ge($(t,"disableCSRFCheck")),emailPasswordEnabled:ge($(s,"enabled")),requireEmailVerification:ge($(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:fn($(e,"plugins"))&&mn($(e,"database")),secureCookiesDisabled:dn($(t,"useSecureCookies")),sessionFreshAgeZero:gn($(r,"freshAge")),trustedOriginsWildcard:hn($(e,"trustedOrigins"))}},En=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),yn=(e,t)=>{if(A(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],r=s!==void 0&&o.isObjectLiteralExpression(s)&&s.getProperties().some(n=>o.isSpreadAssignment(n)),i=s!==void 0&&o.isObjectLiteralExpression(s)&&!r?xn(s):En();return{exportName:x(e),file:t,line:e.getStartLineNumber(),...i}},$n=(e,t)=>N(e,t,yn),vn=(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},bn=(e,t,s)=>{const r=vn(e.getExpression(),s);if(r===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!I(i)||D(i))&&!(s.requireUnmodifiedReach===!0&&!vs(i)))return{exportName:x(e),file:t,line:e.getStartLineNumber(),method:r}},Nn=(e,t,s)=>{const r=[];for(const i of e.getDescendantsOfKind(l.CallExpression)){const n=bn(i,t,s);n&&r.push(n)}return r},te=(e,t,s)=>{const r=[];for(const i of h(t)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i);r.push(...Nn(n,E(t,i),s))}return r},Sn=new Set(["content","pdf","scrape","screenshot"]),An=(e,t)=>te(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Sn}),wn=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),Pn=new Set(["RateLimiter"]),In=new Set(["extend"]),$t=e=>{const t=[],s=[];let r=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){r=!0;continue}if(o.isPropertyAssignment(i)){const n=i.getName();t.push(n),i.getInitializer()?.getKind()===l.TrueKeyword&&s.push(n);continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!r,presentKeys:t,trueKeys:s}},Je=e=>e&&o.isObjectLiteralExpression(e)?$t(e):{analyzable:!1,presentKeys:[],trueKeys:[]},Tn=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!o.isReturnStatement(s))return;const r=s.getExpression();return r!==void 0&&o.isObjectLiteralExpression(r)?r:void 0},Ln=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)?Tn(e):void 0},kn=e=>{const t=e&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,s=t&&Ln(t.getBody());return s?$t(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Dn=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const i=A(r.getExpression());i!==void 0&&(wn.has(i)?s.push({callee:i,file:t,line:r.getStartLineNumber(),...Je(r.getArguments()[0])}):In.has(i)&&s.push({callee:i,file:t,line:r.getStartLineNumber(),...kn(r.getArguments()[0])}))}for(const r of e.getDescendantsOfKind(l.NewExpression)){const i=A(r.getExpression());i===void 0||!Pn.has(i)||s.push({callee:i,file:t,line:r.getStartLineNumber(),...Je(r.getArguments()[0])})}return s},On=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Dn(i,E(t,r)))}return s},Xe="ctx.containers.",Cn=e=>{if(!e.startsWith(Xe))return!1;const t=e.slice(Xe.length);return t.length>0&&!t.includes(".")},Fn=(e,t)=>te(e,t,{argIndex:0,matchReceiver:Cn,methods:new Set(["get"])}),Kn=new Set(["allow","deny","setAllowed"]),Rn=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())},Mn=(e,t)=>{const s=e.getExpression();if(!(!o.isPropertyAccessExpression(s)||s.getName()!=="start"||!Rn(e)))return{detail:"enableInternet: true",exportName:x(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},jn=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||!Kn.has(s.getName()))return;const r=s.getExpression();if(!(!o.isPropertyAccessExpression(r)||r.getName()!=="egress"))return{detail:s.getName(),exportName:x(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},zn=(e,t)=>Mn(e,t)??jn(e,t),qn=(e,t)=>N(e,t,zn),Bn=new Set(["defineExportSink","r2Sink","webhookExportSink"]),Un=e=>{const t=e.getExpression();if(!o.isIdentifier(t))return;const s=t.getText();return Bn.has(s)?s:void 0},Vn=e=>{const t=[],s=[];for(const r of e.getProperties()){if(o.isSpreadAssignment(r))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(o.isPropertyAssignment(r)){const i=r.getName();t.push(i);const n=r.getInitializer();n&&o.isStringLiteral(n)&&n.getLiteralText()===""&&s.push(i);continue}(o.isShorthandPropertyAssignment(r)||o.isMethodDeclaration(r)||o.isGetAccessorDeclaration(r))&&t.push(r.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},Wn=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=E(t,r);for(const a of i.getDescendantsOfKind(l.CallExpression)){const c=Un(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&o.isObjectLiteralExpression(u)?Vn(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},_n=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),Gn=new Set(["dbRateLimit","rateLimit"]),Hn=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},Qn=(e,t)=>{const s=A(e.getExpression());if(s===void 0)return;const r=_n.get(s);if(r!==void 0)return{callee:s,exportName:x(e),failOpen:Hn(e.getArguments()[r]),file:t,limitName:Gn.has(s)?gt(e):"",line:e.getStartLineNumber()}},Jn=(e,t)=>N(e,t,Qn),Xn=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="flags"&&ds(t.getExpression())},Zn=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},Yn=(e,t)=>{if(!Xn(e.getExpression()))return;const[s,r]=e.getArguments();if(!s||!(o.isStringLiteral(s)||o.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),n=Zn(r);if(!(i.length===0||n===void 0))return{defaultValue:n,exportName:x(e),file:t,key:i,line:e.getStartLineNumber()}},ei=(e,t)=>N(e,t,Yn),ti=e=>{const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},si=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},ri=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=E(t,r);for(const a of i.getDescendantsOfKind(l.CallExpression))ti(a)&&s.push({file:n,indexName:si(a),line:a.getStartLineNumber()})}return s},ni=new Set(["delete","get","head","options","patch","post","put"]),ii=new Set(["handler","stream"]),oi=new Set(["runAction","runMutation"]),ai=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),Q=(e,t)=>e!==void 0&&o.isIdentifier(e)&&e.getText()===t,Ze=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,Ye=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const r=s.getNameNode();if(t)return o.isIdentifier(r)?r.getText():void 0;if(o.isObjectBindingPattern(r)){for(const i of r.getElements())if((i.getPropertyNameNode()?.getText()??i.getNameNode().getText())==="ctx"){const n=i.getNameNode();return o.isIdentifier(n)?n.getText():void 0}}},et=(e,t)=>{const s=e.getBody(),r=s.getDescendantsOfKind(l.CallExpression);o.isCallExpression(s)&&r.unshift(s);for(const i of r){const n=i.getExpression();if(!o.isPropertyAccessExpression(n))continue;const a=n.getName(),c=n.getExpression();if(oi.has(a)&&Q(c,t))return a;if(ai.has(a)&&o.isPropertyAccessExpression(c)&&c.getName()==="db"&&Q(c.getExpression(),t))return`db.${a}`}},tt=(e,t)=>{const s=e.getBody();for(const r of s.getDescendantsOfKind(l.PropertyAccessExpression))if(r.getName()==="auth"&&Q(r.getExpression(),t))return!0;for(const r of s.getDescendantsOfKind(l.VariableDeclaration)){const i=r.getNameNode();if(!(!o.isObjectBindingPattern(i)||!Q(r.getInitializer(),t))){for(const n of i.getElements())if((n.getPropertyNameNode()?.getText()??n.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 r=s.getExpression();if(!o.isPropertyAccessExpression(r))return;const i=r.getName();if(ni.has(i)){const n=r.getExpression();return o.isIdentifier(n)&&n.getText()==="httpRoute"?i.toUpperCase():void 0}s=r.getExpression()}},li=(e,t)=>{const s=e.getExpression();if(o.isIdentifier(s)&&s.getText()==="httpAction"){const c=Ze(e.getArguments()[0]),u=c&&Ye(c,!0);if(!c||u===void 0)return;const d=et(c,u);return d===void 0?void 0:{exportName:x(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:tt(c,u),sideEffect:d}}const r=ci(e);if(r===void 0)return;const i=Ze(e.getArguments()[0]),n=i&&Ye(i,!1);if(!i||n===void 0)return;const a=et(i,n);return a===void 0?void 0:{exportName:x(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:r,readsAuth:tt(i,n),sideEffect:a}},ui=(e,t)=>N(e,t,li),di=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),gi=new Set(["append","set"]),he=e=>o.isIdentifier(e)?e.getText():o.isPropertyAccessExpression(e)?e.getName():"",vt=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",st=(e,t)=>(o.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(s=>di.has(he(s.getExpression()))&&Ns(s,t)),pi=(e,t)=>{if(st(e,t))return!0;const s=ee(e);return s!==void 0&&st(s,t)},me=(e,t)=>bs(e,t)&&!pi(e,t),fi=e=>{if(o.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=ee(e);return t!==void 0&&o.isNewExpression(t)&&he(t.getExpression())==="Headers"},J=e=>{if(e===void 0)return;if(o.isObjectLiteralExpression(e))return e;const t=ee(e);return t!==void 0&&o.isObjectLiteralExpression(t)?t:void 0},xe=(e,t,s)=>{for(const r of e.getProperties())if(o.isPropertyAssignment(r)){const i=r.getInitializer();i!==void 0&&me(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:vt(r.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(o.isShorthandPropertyAssignment(r)){const i=r.getNameNode();me(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:r.getName(),line:i.getStartLineNumber(),via:t})}else if(o.isSpreadAssignment(r)){const i=J(r.getExpression());i!==void 0&&xe(i,t,s)}},bt=(e,t)=>{const s=J(e);if(s===void 0)return;const r=s.getProperty("headers");if(r===void 0||!o.isPropertyAssignment(r))return;const i=J(r.getInitializer());i!==void 0&&xe(i,"response-init",t)},mi=(e,t)=>{const s=he(e.getExpression());if(s==="Response")bt(e.getArguments()[1],t);else if(s==="Headers"){const r=J(e.getArguments()[0]);r!==void 0&&xe(r,"headers-ctor",t)}},hi=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;const r=s.getName(),i=s.getExpression();if(r==="json"&&o.isIdentifier(i)&&i.getText()==="Response"){bt(e.getArguments()[1],t);return}if(gi.has(r)&&fi(i)){const n=e.getArguments()[1];n!==void 0&&me(n,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:vt(e.getArguments()[0]),line:n.getStartLineNumber(),via:r==="set"?"headers-set":"headers-append"})}},xi=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))mi(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))hi(s,t)},Ei=(e,t)=>{const s=e.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpAction")return[];const r=As(e.getArguments()[0]);if(r===void 0)return[];const i=r.getParameters()[1];if(i===void 0)return[];const n=i.getNameNode();if(!o.isIdentifier(n))return[];const a=[];return xi(r,{exportName:x(e),relativePath:t,requestName:n.getText(),rows:a}),a},yi=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(l.CallExpression))s.push(...Ei(r,t));return s},$i=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...yi(i,E(t,r)))}return s},vi=new Set(["auth","context.auth","ctx.auth"]),bi="userId",Ni=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},Si=(e,t)=>{const s=g(t,ht);if(!b(s))return;const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of r.getDescendantsOfKind(l.CallExpression)){if(A(i.getExpression())!=="defineIdentity")continue;const[n]=i.getArguments();return n&&o.isObjectLiteralExpression(n)?Ni(n):void 0}},rt=e=>{if(!(e===void 0||!o.isPropertyAccessExpression(e)||e.getName()!=="identity"))return vi.has(e.getExpression().getText())?e:void 0},Ai=e=>{if(o.isPropertyAccessExpression(e)&&rt(e.getExpression())!==void 0)return e.getName();if(o.isElementAccessExpression(e)&&rt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0}},wi=(e,t,s)=>{const r=[];for(const i of e.getDescendants()){const n=Ai(i);n!==void 0&&r.push({declared:n===bi||s.has(n),exportName:x(i),file:t,key:n,line:i.getStartLineNumber()})}return r},Pi=(e,t)=>{const s=Si(e,t);if(s===void 0)return[];const r=[];for(const i of h(t)){const n=e.getSourceFile(i)??e.addSourceFileAtPath(i);r.push(...wi(n,E(t,i),s))}return r},Ii=(e,t)=>{if(A(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const r=$(s,"key");if(!(!r||!I(r)||D(r)))return{exportName:x(e),file:t,line:e.getStartLineNumber()}},Ti=(e,t)=>N(e,t,Ii),Li=new Set(["delete","get","getRaw","getWithMetadata","put"]),ki=(e,t)=>te(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:Li}),Di=new Set(["queue","send"]),nt=new Set(["bcc","cc","to"]),Oi=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!Di.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},Ci=e=>o.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(o.isShorthandPropertyAssignment(t)){const r=t.getNameNode();return nt.has(t.getName())&&I(r)&&!D(r)}if(!o.isPropertyAssignment(t)||!nt.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&I(s)&&!D(s)}):!1,Fi=(e,t)=>{const s=Oi(e.getExpression());if(s===void 0)return;const r=e.getArguments()[0];if(!(!r||!Ci(r)))return{exportName:x(e),file:t,line:e.getStartLineNumber(),method:s}},Ki=(e,t)=>N(e,t,Fi),Ri=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return o.isPropertyAccessExpression(s)?s.getName()==="db":o.isIdentifier(s)&&s.getText()==="db"},Mi=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},ji=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return zs(s.getExpression())?s:void 0},zi=e=>{const t=ji(e),s=t===void 0?void 0:Mi(t);if(s===void 0)return[];const r=e.getNameNode(),i=o.isIdentifier(r)?r.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(n=>Ri(n)).map(n=>({exportName:i,file:"lunora/mutators.ts",line:n.getStartLineNumber()}))},qi=e=>e.getVariableDeclarations().flatMap(t=>zi(t)),Bi=(e,t)=>{const s=g(t,js);if(!b(s))return[];const r=e.getSourceFile(s)??e.addSourceFileAtPath(s);return qi(r)},Ui=new Set(["delete","get","patch"]),Vi=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),Wi=new Set(["auth","identity","session","user"]),_i=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),Gi=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!R(t.getExpression()))return;const s=e.getArguments()[0];return s&&o.isStringLiteral(s)?s.getLiteralText():""},Hi=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 r=s.getNameNode();return o.isIdentifier(r)?r.getText():void 0},Qi=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),Ji=e=>o.isThrowStatement(e)||o.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,Xi=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>Qi(s.getExpression(),t)&&Ji(s.getThenStatement())),Zi=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const r=s.getExpression();if(!o.isPropertyAccessExpression(r))continue;const i=r.getName();if(!Ui.has(i))continue;const n=r.getExpression();if(!(R(n)||o.isPropertyAccessExpression(n)&&R(n.getExpression())))continue;const a=s.getArguments()[0];if(a!==void 0&&o.isIdentifier(a)&&a.getText()===t)return i}},Yi=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},eo=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>Yi(s)==="ctx")),to=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>_i.has(t.getOperatorToken().getKind())?o.isPropertyAccessExpression(t.getLeft())||o.isPropertyAccessExpression(t.getRight()):!1),so=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(Vi.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&s.getText()==="ctx"&&Wi.has(t.getName()))return!0}return eo(e)||to(e)},ro=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const r=M(s);if(r?.kind!=="query"&&r?.kind!=="mutation")return[];const i=ft(s);if(i===void 0)return[];const n=r.receiver!==void 0&&mt(r.receiver,"use","rls"),a=so(i),c=new Set,u=[];for(const d of i.getDescendantsOfKind(l.CallExpression)){const y=Gi(d);if(y===void 0)continue;const w=Hi(d);if(w===void 0||c.has(w)||!Xi(i,w))continue;const p=Zi(i,w);p!==void 0&&(c.add(w),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:p,table:y,usesRls:n,visibility:r.visibility}))}return u},no=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=E(t,r);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...ro(c,n))}return s},io=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),oo=new Set(["insert","insertManyUnsafe","patch","replace"]),ao=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!oo.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="db")return;const r=s.getExpression();return o.isIdentifier(r)&&r.getText()==="ctx"?t:void 0},co=(e,t)=>{if(t!=="insertManyUnsafe")return o.isObjectLiteralExpression(e)?[e]:[];if(!o.isArrayLiteralExpression(e))return[];const s=[];for(const r of e.getElements())o.isObjectLiteralExpression(r)&&s.push(r);return s},lo=(e,t,s,r)=>{const i=[];for(const n of e.getProperties()){let a,c;o.isPropertyAssignment(n)?(a=n.getName(),c=n.getInitializer()):o.isShorthandPropertyAssignment(n)&&(a=n.getName(),c=n.getNameNode()),!(a===void 0||c===void 0||!io.has(a))&&I(c)&&!D(c)&&i.push({exportName:x(s),field:a,file:r,line:s.getStartLineNumber(),method:t})}return i},uo=(e,t)=>{const s=ao(e.getExpression());if(s===void 0)return[];const r=e.getArguments()[1];return r?co(r,s).flatMap(i=>lo(i,s,e,t)):[]},go=(e,t,s)=>{const r=[];for(const i of e.getDescendantsOfKind(l.CallExpression))for(const n of uo(i,t)){const a=s(n.exportName);r.push(a===void 0?n:{...n,visibility:a})}return r},po=(e,t,s=[])=>{const r=[],i=new Map(s.map(n=>[`${n.filePath}:${n.exportName}`,n.visibility]));for(const n of h(t)){const a=e.getSourceFile(n)??e.addSourceFileAtPath(n),c=E(t,n);r.push(...go(a,c,u=>i.get(`${c}:${u}`)))}return r},fo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),mo=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,ho=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&o.isPropertyAssignment(t)?mo(t.getInitializer()):void 0},xo=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!fo.has(s))return;const[r]=e.getArguments(),i=r&&o.isObjectLiteralExpression(r)?ho(r):void 0;return{callee:s,exportName:x(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},Eo=(e,t)=>N(e,t,xo),yo=new Set(["defineQueue","defineWorkflow"]),$o=new Set(["run","runAction","runMutation","runQuery"]),vo=new Set(["api","internal"]),bo=e=>{const t=e.getExpression();return o.isIdentifier(t)?t.getText():void 0},No=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 r=s.getInitializer();if(r&&(o.isArrowFunction(r)||o.isFunctionExpression(r)))return r},Nt=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&o.isIdentifier(s)?s.getText():void 0},St=(e,t)=>e===t||e.startsWith(`${t}.`),At=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return o.isPropertyAccessExpression(e)&&t.push(e),t},it=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)},wt=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>it(s));return o.isIdentifier(e)&&it(e)&&t.push(e),t},So=e=>{if(!o.isVariableDeclaration(e))return[];const t=e.getNameNode();return o.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},Ao=e=>{const t=Nt(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const r of e.getDescendantsOfKind(l.ForOfStatement)){if(r.getExpression().getText()!==`${t}.messages`)continue;const i=r.getInitializer(),n=o.isVariableDeclarationList(i)?i.getDeclarations()[0]?.getNameNode():void 0;n&&o.isIdentifier(n)&&s.push(`${n.getText()}.body`)}return s},wo=(e,t,s)=>{const r=t==="workflow"?[`${s}.params`]:Ao(e),i=new Set,n=a=>At(a).some(c=>r.some(u=>St(c.getText(),u)))?!0:wt(a).some(c=>i.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&n(c))for(const u of So(a))i.add(u)}return{names:i,prefixes:r}},Po=(e,t)=>At(e).some(s=>t.prefixes.some(r=>St(s.getText(),r)))?!0:wt(e).some(s=>t.names.has(s.getText())),Io=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 r=t.at(-1);if(!(r===void 0||!o.isIdentifier(s)||!vo.has(s.getText())||t.length<2))return{exportName:r,file:t.slice(0,-1).join("/")}},To=(e,t,s)=>{const r=Nt(e,0);if(r===void 0)return[];const i=wo(e,t,r),n=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!o.isPropertyAccessExpression(c)||!$o.has(c.getName())||c.getExpression().getText()!==r)continue;const u=a.getArguments()[1];if(!u||!Po(u,i))continue;const d=Io(a.getArguments()[0]);d!==void 0&&n.push({dispatchKind:t,file:s,handlerExport:x(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return n},Lo=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const i=bo(r);if(i===void 0||!yo.has(i))continue;const n=No(r);n!==void 0&&s.push(...To(n,i==="defineQueue"?"queue":"workflow",t))}return s},ko=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Lo(i,E(t,r)))}return s},ot={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstile:"usesCaptcha",verifyTurnstileMiddleware:"usesCaptcha"},at=new Set(["account","credential","member","passkey","session","user"]),Do=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),Oo=e=>{const t=Do(e).at(-1);if(!t)return!1;const s=t.endsWith("s")?t.slice(0,-1):t;return at.has(t)||at.has(s)},Co=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},Fo=(e,t)=>{const{objects:s,opaque:r}=yt(e,t);return en(s).some(i=>Co(i))?!0:r?void 0:!1},Ee=e=>{const t=e.getExpression();if(o.isIdentifier(t))return t.getText();if(o.isPropertyAccessExpression(t))return t.getName()},Ko=e=>{const t=e.getArguments()[0];return!t||!o.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Ro=e=>{if(o.isCallExpression(e))return e;if(!o.isIdentifier(e))return;const t=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return t&&o.isCallExpression(t)?t:void 0},H={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},Mo=e=>{const t=Ro(e),s=t?Ee(t):void 0;if(t&&s==="protectPublic"){const r=Ko(t);return{...H,usesCaptcha:r.usesCaptcha,usesRateLimit:r.usesRateLimit}}return s!==void 0&&s in ot?{...H,[ot[s]]:!0}:H},jo=e=>{const t={...H};let s=e;for(;o.isCallExpression(s);){const r=s.getExpression();if(!o.isPropertyAccessExpression(r))break;const i=r.getName()==="use"?s.getArguments()[0]:void 0;if(i){const n=Mo(i);t.usesCaptcha||=n.usesCaptcha,t.usesEmailGate||=n.usesEmailGate,t.usesMask||=n.usesMask,t.usesRateLimit||=n.usesRateLimit,t.usesRls||=n.usesRls}s=r.getExpression()}return t},zo=new Set(["insert","insertMany","insertManyUnsafe","replace"]),qo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!zo.has(t.getName()))return!1;const s=t.getExpression();if(!(o.isPropertyAccessExpression(s)?s.getName()==="db":o.isIdentifier(s)&&s.getText()==="db"))return!1;const r=e.getArguments()[0];return!r||!(o.isStringLiteral(r)||o.isNoSubstitutionTemplateLiteral(r))?!1:Oo(r.getLiteralText())},Bo=new Set(["create","runAfter","runAt","send","sendBatch"]),Uo=new Set(["queues","scheduler","workflows"]),Vo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Bo.has(t.getName()))return!1;let s=t.getExpression();for(;o.isCallExpression(s)||o.isElementAccessExpression(s)||o.isPropertyAccessExpression(s);){if(o.isPropertyAccessExpression(s)&&Uo.has(s.getName())){const r=s.getExpression();if(o.isIdentifier(r)&&r.getText()==="ctx")return!0}s=s.getExpression()}return!1},Wo=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return o.isPropertyAccessExpression(s)?s.getName()==="db":o.isIdentifier(s)&&s.getText()==="db"},Pt=new Set(["generateObject","generateText","streamObject","streamText"]),_o=e=>{const t=Ee(e);return t!==void 0&&Pt.has(t)},Go=e=>{const t=Ee(e);if(t===void 0||!Pt.has(t))return!1;const s=e.getArguments()[0];return!s||!o.isObjectLiteralExpression(s)||s.getProperties().some(r=>o.isSpreadAssignment(r))?!1:!s.getProperty("maxOutputTokens")},Ho=new Set(["log","span","trace"]),Qo=new Set(["ai"]),Jo=new Set(["email","mail"]),Xo=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),pe=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const r=s.getExpression();return o.isIdentifier(r)&&r.getText()==="ctx"}),Zo=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),Yo=new Set(["every","filter","flatMap","forEach","map","some"]),ea=new Set(["all","allSettled","race"]),ta=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 r=s.getName();if(Yo.has(r))return t;const i=s.getExpression();if(o.isIdentifier(i)&&i.getText()==="Promise"&&ea.has(r))return t},sa=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(Zo.has(t.getKind())){const s=ta(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},ra=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 r=s.getParent();if(!o.isCallExpression(r)||r.getExpression()!==s)return!1;t=r}},na=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}},ia=e=>{let t=!1,s=!0;for(const r of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!Xo.has(r.getName()))continue;const i=r.getExpression();if(!o.isIdentifier(i)||i.getText()!=="ctx")continue;const n=na(r);n&&(t=!0,!sa(n)&&!ra(n)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},oa=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!o.isNewExpression(s))return!1;const r=s.getExpression();return o.isIdentifier(r)&&r.getText()==="Error"}),ct="lunora-advisor-exempt",aa=/^[\s*/]+/u,ca=/[\w-]/u,la=e=>{const t=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(s=>s.getText()).join(`
6
+ `);for(const s of t.split(`
7
+ `)){const r=s.replace(aa,"");if(!r.startsWith(ct))continue;const i=r.slice(ct.length);if(ca.test(i.charAt(0)))continue;const n=i.indexOf("--");return{exempt:!0,exemptReason:(n===-1?"":i.slice(n+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},ua=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}},da=(e,t)=>{const s=ua(t);if(!s)return;if(o.isArrowFunction(s)||o.isFunctionExpression(s)||o.isMethodDeclaration(s))return e;if(!o.isIdentifier(s))return;const r=s.getSourceFile(),i=s.getText(),n=r.getVariableDeclaration(i)?.getInitializer();return n&&(o.isArrowFunction(n)||o.isFunctionExpression(n))?n:r.getFunction(i)},ga=e=>{let t=!1,s=!1,r=!1,i=!1,n=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(qo(u)&&(n=!0),Vo(u)&&(t=!0),Wo(u)&&(i=!0),_o(u)&&(s=!0),Go(u)&&(r=!0),n&&t&&i&&r)break;const{handlesErrors:a,reachesOutbound:c}=ia(e);return{callsMail:pe(e,Jo),emitsEvent:pe(e,Ho),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||pe(e,Qo),throwsBareError:oa(e),unboundedAiGeneration:r,usesInsertManyUnsafe:i,writesUserTable:n}},pa=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const r=M(s);if(!r||r.kind!=="query"&&r.kind!=="mutation"&&r.kind!=="action")return;const i=r.receiver?jo(r.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},n=da(e,s);return{...n?ga(n):{},...la(e),...i,analyzableBody:n!==void 0,exportName:e.getName(),file:t,hasEmailArg:Fo(s,r.receiver),kind:r.kind,visibility:r.visibility}},fa=(e,t)=>{const s=[];for(const r of e.getVariableStatements())if(r.isExported())for(const i of r.getDeclarations()){const n=pa(i,t);n&&s.push(n)}return s},ma=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...fa(i,E(t,r)))}return s},ha=new Set(["dbRateLimit","rateLimit"]),xa=e=>o.isArrowFunction(e)?e.getBody():e,Ea=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!ha.has(s))return;const r=e.getArguments()[2];if(!r)return;const i=$(r,"key");if(!i)return;const n=xa(i);if(!(!I(n)||D(n)))return{callee:s,exportName:x(e),file:t,limitName:gt(e),line:e.getStartLineNumber()}},ya=(e,t)=>N(e,t,Ea),$a=new Set(["findFirst","findFirstOrThrow","findMany","get"]),va=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!$a.has(t.getName()))return;const s=t.getExpression();if(R(s)){const r=e.getArguments()[0];return r&&o.isStringLiteral(r)?r.getLiteralText():""}if(o.isPropertyAccessExpression(s)&&R(s.getExpression()))return s.getName()},ba=e=>{let t=e;for(;o.isCallExpression(t);){const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&R(s.getExpression())){const r=t.getArguments()[0];return r&&o.isStringLiteral(r)?r.getLiteralText():""}t=s.getExpression()}},Na=e=>{let t=e;for(;o.isAwaitExpression(t)||o.isParenthesizedExpression(t)||o.isNonNullExpression(t)||o.isAsExpression(t);)t=t.getExpression();return t},It=(e,t=!1)=>{const s=Na(e);if(o.isIdentifier(s)){if(t)return;const r=ee(s);return r===void 0?void 0:It(r,!0)}if(o.isCallExpression(s))return va(s)??ba(s)},Sa=e=>{const t=e.getBody();if(!o.isBlock(t))return[t];const s=[];for(const r of e.getDescendantsOfKind(l.ReturnStatement)){const i=r.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a)),n=r.getExpression();i===e&&n!==void 0&&s.push(n)}return s},Aa=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const r=M(s);if(r?.kind!=="query")return[];const i=ft(s);if(i===void 0)return[];const n=r.receiver!==void 0&&ws(r.receiver,"output"),a=r.receiver!==void 0&&mt(r.receiver,"use","mask"),c=new Set,u=[];for(const d of Sa(i)){const y=It(d);y===void 0||c.has(y)||(c.add(y),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:y,usesMask:a,usesOutput:n,visibility:r.visibility}))}return u},wa=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=E(t,r);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Aa(c,n))}return s},Pa=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},Ia=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&o.isCallExpression(s)?M(s):void 0;if(!r)return[];const i=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const a=pt(n);if(a===void 0)continue;const c=Pa($(a.options,"with"));c.length!==0&&i.push({exportName:e.getName(),file:t,line:n.getStartLineNumber(),parentTable:a.table,relations:c,visibility:r.visibility})}return i},Ta=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=E(t,r);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ia(c,n))}return s},X=e=>{if(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(o.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=X(e.getLeft()),s=X(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},La=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&&X(t)!==void 0},ka=/(?:^|\/)__tests__\//u,Da=/\.(?:spec|test)$/u,Oa=e=>ka.test(e)||Da.test(e),Ca=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()}},Fa=(e,t,s)=>Xs(e)?!Oa(s)&&Zs(Ca(t)):!0,Ka=(e,t)=>{const s=[],r=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],i=new Set;for(const n of r){if(La(n))continue;const a=X(n);if(a===void 0)continue;const c=Qs(a);if(c===void 0||!Fa(c,n,t))continue;const u=n.getStartLineNumber(),d=`${String(u)}:${c}`;i.has(d)||(i.add(d),s.push({file:t,kind:c,line:u,preview:Js(a)}))}return s},Ra=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...Ka(i,E(t,r)))}return s},Ma=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),r=s&&o.isCallExpression(s)?M(s):void 0;if(!r)return[];const i=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const a=pt(n);if(a===void 0)continue;const c=$(a.options,"includeDeleted");if(c===void 0)continue;const u=o.isTrueLiteral(c),d=!u&&I(c);!u&&!d||i.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:n.getStartLineNumber(),table:a.table,visibility:r.visibility})}return i},ja=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=E(t,r);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Ma(c,n))}return s},za=new Set(["query","unsafe"]),qa=e=>{if(!o.isPropertyAccessExpression(e)||!za.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"},Ba=e=>o.isBinaryExpression(e)||o.isTemplateExpression(e),Ua=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",Va=(e,t)=>{if(!qa(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Ba(s)))return{exportName:Ua(e),file:t,line:s.getStartLineNumber()}},Wa=(e,t)=>N(e,t,Va),_a=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Ga=e=>{for(const[t,s]of _a)for(const r of s)if(e===r||e.startsWith(r.endsWith("/")?r:`${r}/`))return t},Ha=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);for(const n of i.getImportDeclarations()){const a=n.getModuleSpecifierValue(),c=Ga(a);c!==void 0&&s.push({file:E(t,r),line:n.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},Qa=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Ja=(e,t,s=[])=>{const r=new Map(s.map(i=>[`${i.filePath}:${i.exportName}`,i.visibility]));return te(e,t,{argIndex:0,matchReceiver:i=>i==="ctx.storage"||i.startsWith("ctx.storage."),methods:Qa,requireUnmodifiedReach:!0}).map(i=>{const n=r.get(`${i.file}:${i.exportName}`);return n===void 0?i:{...i,visibility:n}})},Xa=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Za=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,Ya=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!o.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,r=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){r=!0;continue}if(o.isPropertyAssignment(i)){const n=i.getName();t.push(n),n==="expiresInSeconds"&&(s=Za(i.getInitializer()));continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!r,expiresInSeconds:s,presentKeys:t}},ec=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName(),s=Xa.get(t);if(s===void 0)return;const r=e.getExpression().getText();return r==="ctx.storage"||r.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},tc=(e,t)=>{const s=ec(e.getExpression());if(s!==void 0)return{exportName:x(e),file:t,line:e.getStartLineNumber(),method:s.method,...Ya(e.getArguments()[s.optionsIndex])}},sc=(e,t)=>N(e,t,tc),rc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),ye=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&rc.has(s)?s:void 0},Tt=e=>{const t=e.getInitializer();return t===void 0?!1:o.isCallExpression(t)||o.isIdentifier(t)||o.isPropertyAccessExpression(t)},Lt={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."},nc={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."},$e=(e,t,s,r,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 ${r.toString()}) has type \`${s}\` but was not registered — ${i.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:r,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"}),ic=(e,t,s)=>{const r=[];for(const i of e.getVariableStatements().filter(n=>n.isExported()))for(const n of i.getDeclarations()){const a=n.getName();if(s.has(`${t}:${a}`)||!Tt(n))continue;const c=ye(n);c!==void 0&&r.push($e(t,a,c,n.getStartLineNumber(),Lt))}return r},oc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const r=[];for(const i of e.getExportAssignments().filter(n=>!n.isExportEquals())){const n=ye(i.getExpression());n!==void 0&&r.push($e(t,"default",n,i.getStartLineNumber(),Lt))}return r},ac=(e,t,s)=>{const r=[];for(const i of e.getExportDeclarations().filter(n=>n.getModuleSpecifier()===void 0))for(const n of i.getNamedExports()){const a=n.getAliasNode()?.getText()??n.getName();if(s.has(`${t}:${a}`))continue;const c=n.getLocalTargetDeclarations().find(d=>o.isVariableDeclaration(d));if(c===void 0||!Tt(c))continue;const u=ye(c);u!==void 0&&r.push($e(t,a,u,n.getStartLineNumber(),nc))}return r},cc=(e,t,s)=>[...ic(e,t,s),...oc(e,t,s),...ac(e,t,s)],lc=(e,t,s)=>{const r=new Set(s.map(n=>`${n.filePath}:${n.exportName}`)),i=[];for(const n of h(t)){const a=e.getSourceFile(n);a!==void 0&&i.push(...cc(a,E(t,n),r))}return i.toSorted((n,a)=>n.cacheKey.localeCompare(a.cacheKey))},uc=new Set(["when","where"]),fe=new Set(["definePolicy","defineShape"]),dc=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const r=t.getName();return fe.has(r)?r:void 0}if(!o.isIdentifier(t))return;for(const r of t.getSymbol()?.getDeclarations()??[])if(o.isImportSpecifier(r)){const i=r.getNameNode().getText();return fe.has(i)?i:void 0}const s=t.getText();return fe.has(s)?s:void 0},gc=e=>o.isObjectLiteralExpression(e)&&e.getProperties().length===0,kt=e=>{if(e!==void 0){if(o.isReturnStatement(e)&&e.getExpression()===void 0||e.getKind()===l.UndefinedKeyword||e.getText()==="undefined")return"undefined";if(gc(e))return"empty-object";if(o.isParenthesizedExpression(e))return kt(e.getExpression())}},Dt=e=>e.getAncestors().find(t=>o.isArrowFunction(t)||o.isFunctionExpression(t)||o.isFunctionDeclaration(t)),Ot=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>Dt(t)===e),Ct=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>Dt(t)===e),pc=e=>{const t=Ot(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||Ct(e).length>0},fc=e=>{const t=[],s=e.getBody();o.isBlock(s)||t.push(s);for(const r of Ot(e)){const i=o.isReturnStatement(r)?r.getExpression():void 0;t.push(i??r)}for(const r of Ct(e))t.push(r.getWhenTrue(),r.getWhenFalse());return t},mc=e=>{for(const t of e.getAncestors())if(o.isVariableDeclaration(t)){const s=t.getNameNode();if(o.isIdentifier(s))return s.getText()}return"<anonymous>"},hc=(e,t,s)=>{if(!o.isCallExpression(e))return[];const[r]=e.getArguments();if(!r||!o.isObjectLiteralExpression(r))return[];const i=[];for(const n of r.getProperties()){if(!o.isPropertyAssignment(n)||!uc.has(n.getName()))continue;const a=n.getInitializer();if(!(!a||!(o.isArrowFunction(a)||o.isFunctionExpression(a)))&&pc(a))for(const c of fc(a)){const u=kt(c);u!==void 0&&i.push({exportName:mc(e),file:s,form:u,key:n.getName(),line:c.getStartLineNumber(),owner:t})}}return i},xc=(e,t)=>{const s=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const i=dc(r);i!==void 0&&s.push(...hc(r,i,t))}return s},Ec=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r);s.push(...xc(i,E(t,r)))}return s},yc=new Set(["query","upsert","upsertMany"]),$c=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(yc.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},vc=(e,t)=>{const s=$c(e.getExpression());if(s===void 0)return;const r=e.getArguments()[1];if(!r)return;const i=$(r,"namespace");if(!(!i||!I(i)||D(i)))return{exportName:x(e),file:t,line:e.getStartLineNumber(),method:s}},bc=(e,t)=>N(e,t,vc),Nc=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"},Sc=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},Ac=(e,t)=>{const s=[];for(const r of h(t)){const i=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=E(t,r);for(const a of i.getDescendantsOfKind(l.CallExpression)){if(!Nc(a))continue;const c=gs(a);c!==""&&s.push({exportName:c,file:n,line:a.getStartLineNumber(),workflow:Sc(a)})}}return s},wc=".lunora-schema.json",S=(e,t)=>{b(e)&&dt(e,"utf8")===t||Bt(e,t,"utf8")},P=(e,t)=>{if(t===""){Ut(e,{force:!0});return}S(e,t)},Pc=e=>{const t=g(e,"package.json");if(b(t))try{const s=JSON.parse(dt(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},Ic=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},Tc=e=>{let t=b(e)?e:le(e);for(;t&&t!==le(t);){const s=g(t,"tsconfig.json");if(b(s))return s;t=le(t)}},lt=e=>e.replaceAll("\\","/"),Lc=(e,t,s)=>{if(s&&e.length>0){const n=e.map(a=>`"${a.exportName}"`).join(", ");throw new k("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) (${n}), 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 r=new Map;for(const n of t.columns){const a=r.get(n.table)??[];a.push(n.column),r.set(n.table,a)}const i=t.columns.length>0;for(const n of e){if(n.table===void 0){if(i)throw new k("MASK_UNSUPPORTED",`defineShape "${n.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 "${n.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=r.get(n.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new k("MASK_UNSUPPORTED",`defineShape "${n.exportName}" replicates table "${n.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})}},ut=(e,t,s)=>{const r=e.getSourceFile(t);if(r===void 0){e.createSourceFile(t,s,{overwrite:!0});return}r.getFullText()!==s&&r.replaceWithText(s)},kc=e=>{const t=Tc(e);return t?new Ge({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Ge({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},$l=(e,t)=>{const s=h(t),r=g(t,"schema.ts");b(r)&&s.push(r);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=>lt(c))),n=lt(t),a=`${n}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===n||u.startsWith(a))&&!i.has(u)&&e.removeSourceFile(c)}},vl=e=>{const t=Ic(),s=t?ue.now():0,r=g(e.projectRoot,e.lunoraDirectory??"lunora"),i=g(r,"schema.ts");if(!b(i))throw new k("INTERNAL",`schema.ts not found at ${i}`);const n=e.project??kc(r);ir(Is);const a=Hs(n,i,e.projectRoot),{agents:c,containers:u,dataModelContent:d,dependencies:y,env:w,featureUsage:p,hasBrowser:v,hasFlags:C,hasNotify:j,identity:z,platformGate:U,queues:T,serverContent:F,storageRulesMetadata:q,usesSandbox:se,useUmbrella:K,workflows:L}=Pr({lunoraDirectory:r,project:n,projectRoot:e.projectRoot,schema:a,target:e.target}),f=g(r,"_generated"),ve=g(f,"dataModel.ts"),be=g(f,"server.ts");ut(n,ve,d),ut(n,be,F);const O=Ps(n,r),Ne=Ds(n,r),Se=Ms(n,r),B=Ys(n,r),re=qs(n,r),ne=Ls(n,r,L,c),V=e.lint===!1?void 0:_t({adminRoutes:Fr(n,r),aiRawRuns:Mr(n,r),aiToolSideEffects:Hr(n,r),argumentDerivedFetches:Xr(n,r),argumentValidators:un(n,r),authApiCalls:Ts(n,r),authConfigs:$n(n,r),browserUrlAccesses:An(n,r),configCalls:On(n,r),containerKeyAccesses:Fn(n,r),containerOverrides:qn(n,r),containers:u,exportSinks:Wn(n,r),staleMigrationImports:Ha(n,r),failOpenGuards:Jn(n,r),flagSecurityDefaults:ei(n,r),geoIndexUsages:ri(n,r),httpActionGuards:ui(n,r),httpHeaderWrites:$i(n,r),identityClaimReads:Pi(n,r),imageDeliveryUrlAccesses:Ti(n,r),inserts:Os(n,r),kvKeyAccesses:ki(n,r),mailRecipientAccesses:Ki(n,r),maskProcedures:Cs(n,r),maskStrategies:Fs(n,r),mutatorWrites:Bi(n,r),nondeterministicCalls:Bs(n,r),normalizeIdAuthorizations:no(n,r),notifyCalls:Vs(n,r),notifyConfig:Us(n,r),ownerFieldWrites:po(n,r,O),unrestrictedWhereBranches:Ec(n,r),paymentWebhooks:Eo(n,r),privilegedDispatches:ko(n,r),procedureProtections:ma(n,r),queries:Ss(n,r),queues:T,r2sqlCalls:Ws(n,r),ratelimitKeySelectors:ya(n,r),rawRowReturns:wa(n,r),relationLoads:Ta(n,r),rlsProcedures:_s(n,r),schema:a,secretLiterals:Ra(n,r),shapes:B,softDeleteReads:ja(n,r),sqlInterpolations:Wa(n,r),storageKeyAccesses:Ja(n,r,O),storageUploads:sc(n,r),vectorNamespaceAccesses:bc(n,r),workflowCalls:Ac(n,r),workflows:L,wranglerVariables:e.wranglerVariables}),Ae=V===void 0?[]:[...Vt(V,{source:"static"}),...lc(n,r,O)],Ft=Gs(n,r),we=Ks(n,r);Lc(B,we,Rs(n,r));const Kt=C?ks(n,r):[],W=$r(p,{containerCount:u.length,cronCount:ne.length,dependencies:y,hasPaymentTables:yr(a.tables),queueCount:T.length,storageColumnCount:Object.keys(Xt(a)).length,storageRuleCount:q.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:L.length}),Pe=t?ue.now():0,Ie=Zt({agents:c,functions:O,httpRoutes:Ne,mutators:re,useUmbrella:K,workflows:L}),Te=Yt({agents:c,functions:O,migrations:Se,mutators:re,shapes:B,useUmbrella:K,usesSandbox:se}),ie=or(a,Se.map(m=>m.id)),Le=es({advisories:Ae,advisorProcedures:V?.procedureProtections??[],agents:c,containers:u,env:w,flagKeys:Kt,hasAccessFacade:p.access,hasAi:p.ai,hasAnalytics:p.analytics,hasBrowser:v,hasFlags:C,hasHyperdrive:p.hyperdrive,hasImages:p.images,hasKv:p.kv,hasNotify:j,hasPayments:p.payments,hasPipelines:p.pipelines,hasR2sql:p.r2sql,hasX402:p.x402,maskMetadata:we,mutators:re,queues:T,rlsMetadata:Ft,schema:a,schemaSnapshot:ie,shapes:B,storageRules:q,studioFeatures:W,useUmbrella:K,workflows:L}),ke=ts(B,y.has("@lunora/db"),K),De=ss(u,a.jurisdiction),Oe=rs(L),Ce=ns(c),Fe=is(T),Ke=os(ne),Re=as(a.vectorIndexes),_=cs(a,K),Me=ls(y.has("@lunora/seed")),G=e.apiSpec??"openapi",oe=G==="openapi"||G==="both",ae=G==="openrpc"||G==="both",je=er({emailAgents:c.filter(m=>m.onEmail===!0).map(m=>({bindingName:m.bindingName,exportName:m.exportName})),hasAccess:y.has("@lunora/cloudflare-access"),hasAi:p.ai,hasAnalytics:p.analytics,hasAuth:y.has("@lunora/auth"),hasBrowser:v,hasFramework:y.has("@lunora/astro")||y.has("@lunora/svelte")||y.has("@lunora/vue"),hasGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend!=="hyperdrive"),hasHyperdrive:p.hyperdrive,hasHyperdriveGlobal:a.tables.some(m=>m.shardMode==="global"&&m.globalBackend==="hyperdrive"),hasImages:p.images,hasKv:W.kv,hasNotify:j,hasPayments:p.payments,hasR2sql:p.r2sql,hasQueue:T.some(m=>m.mode==="push"),hasScheduler:W.scheduler,hasStorage:W.storage,hasVectors:a.vectorIndexes.length>0,hasWorkflow:L.length>0,hasX402:p.x402,identity:z,jurisdiction:a.jurisdiction,useUmbrella:K,voiceAgents:c.filter(m=>m.voice===!0&&m.voiceBindingName!==void 0).map(m=>({bindingName:m.voiceBindingName,exportName:m.exportName})),wantsOpenApi:oe,wantsOpenRpc:ae}),ze=Pc(e.projectRoot),qe=tr({functions:O,httpRoutes:Ne,version:ze}),Be=rr({functions:O,version:ze}),Ue=`${JSON.stringify(qe,void 0,2)}
8
+ `,Ve=`${JSON.stringify(Be,void 0,2)}
9
+ `,We=sr(qe),_e=nr(Be),ce=g(r,wc),Rt=b(ce);if(e.dryRun||(b(f)||qt(f,{recursive:!0}),S(g(f,"app.ts"),je),S(ve,d),S(g(f,"api.ts"),Ie),S(be,F),S(g(f,"functions.ts"),Te),S(g(f,"shard.ts"),Le),S(g(f,"crons.ts"),Ke),S(g(f,"vectors.ts"),Re),S(g(f,"drizzle.global.ts"),_.global),S(g(f,"drizzle.shard.ts"),_.shard),P(g(f,"containers.ts"),De),P(g(f,"workflows.ts"),Oe),P(g(f,"agents.ts"),Ce),P(g(f,"queues.ts"),Fe),P(g(f,"seed.ts"),Me),P(g(f,"collections.ts"),ke),P(g(f,"openapi.json"),oe?Ue:""),P(g(f,"openapi.ts"),oe?We:""),P(g(f,"openrpc.json"),ae?Ve:""),P(g(f,"openrpc.ts"),ae?_e:""),(!Rt||e.updateSchemaBaseline===!0)&&S(ce,Wt(ie))),t){const m=ue.now(),Mt=Math.round(m-s),jt=Math.round(Pe-s),zt=Math.round(m-Pe);console.error(`@lunora/codegen: codegen took ${Mt.toString()}ms (discovery ${jt.toString()}ms, emit ${zt.toString()}ms)`)}return{advisories:Ae,advisorContext:V,agents:c,containers:u,cronTriggers:us(ne),generated:{agents:Ce,api:Ie,app:je,collections:ke,containers:De,crons:Ke,dataModel:d,drizzleGlobal:_.global,drizzleShard:_.shard,functions:Te,openApi:Ue,openApiModule:We,openRpc:Ve,openRpcModule:_e,queues:Fe,seed:Me,server:F,shard:Le,vectors:Re,workflows:Oe},outputDirectory:f,platformDiagnostics:U.diagnostics,queues:T,schemaSnapshot:ie,schemaSnapshotPath:ce,workflows:L}};export{wc as SCHEMA_SNAPSHOT_FILENAME,kc as createCodegenProject,$l as refreshCodegenProject,vl as runCodegen};
@@ -1 +1 @@
1
- import{existsSync as p}from"node:fs";import{join as g}from"node:path";import{SyntaxKind as c,Node as o}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as f}from"./module-specifiers-8FEEiUcv.mjs";import{f as u}from"./parse-validator-CkLxY-Mr.mjs";const m="shapes.ts",d=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineShape";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return f(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineShape":!1;return!1},x=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(c.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},S=r=>{if(o.isIdentifier(r))return d(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineShape"&&o.isIdentifier(t)&&x(t)}return!1},h=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return;const e=t.getProperty("table");if(!e||!o.isPropertyAssignment(e))return;const i=e.getInitializer();return i&&o.isStringLiteral(i)?i.getLiteralValue():void 0},I=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return{};const e=t.getProperty("args");if(!e||!o.isPropertyAssignment(e))return{};const i=e.getInitializer();return!i||!o.isObjectLiteralExpression(i)?{}:u(i)},y=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const n=i,a=n.getExpression();if(!S(a))continue;const s=e.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineShape exports must be plain named exports (no destructuring)");t.push({args:I(n),exportName:s.getText(),filePath:"shapes",table:h(n)})}return t},D=(r,t)=>{const e=g(t,m);if(!p(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),n=y(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{m as SHAPES_FILENAME,D as discoverShapes};
1
+ import{existsSync as p}from"node:fs";import{join as g}from"node:path";import{SyntaxKind as c,Node as o}from"ts-morph";import{diagnosticAt as l}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{o as f}from"./module-specifiers-8FEEiUcv.mjs";import{g as u}from"./parse-validator-CusS8QwU.mjs";const m="shapes.ts",d=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineShape";for(const e of t.getDeclarations())if(o.isImportSpecifier(e))return f(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText()==="defineShape":!1;return!1},x=r=>{const t=r.getSymbol();if(!t)return!1;for(const e of t.getDeclarations()){if(!o.isNamespaceImport(e))continue;const i=e.getFirstAncestorByKind(c.ImportDeclaration);return i!==void 0&&f(i.getModuleSpecifierValue())}return!1},S=r=>{if(o.isIdentifier(r))return d(r);if(o.isPropertyAccessExpression(r)){const t=r.getExpression();return r.getName()==="defineShape"&&o.isIdentifier(t)&&x(t)}return!1},h=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return;const e=t.getProperty("table");if(!e||!o.isPropertyAssignment(e))return;const i=e.getInitializer();return i&&o.isStringLiteral(i)?i.getLiteralValue():void 0},I=r=>{const[t]=r.getArguments();if(!t||!o.isObjectLiteralExpression(t))return{};const e=t.getProperty("args");if(!e||!o.isPropertyAssignment(e))return{};const i=e.getInitializer();return!i||!o.isObjectLiteralExpression(i)?{}:u(i)},y=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const i=e.getInitializer();if(i?.getKind()!==c.CallExpression)continue;const n=i,a=n.getExpression();if(!S(a))continue;const s=e.getNameNode();if(!o.isIdentifier(s))throw l(s,"defineShape exports must be plain named exports (no destructuring)");t.push({args:I(n),exportName:s.getText(),filePath:"shapes",table:h(n)})}return t},D=(r,t)=>{const e=g(t,m);if(!p(e))return[];const i=r.getSourceFile(e)??r.addSourceFileAtPath(e),n=y(i);return n.sort((a,s)=>a.exportName.localeCompare(s.exportName)),n};export{m as SHAPES_FILENAME,D as discoverShapes};
@@ -0,0 +1,16 @@
1
+ import{LunoraError as m}from"@lunora/errors";import{SCHEMA_SNAPSHOT_VERSION as g,sortKeys as S,diffSchemaSnapshots as b,parseSnapshotJson as k}from"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";import{serializeSchemaSnapshot as O}from"./SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs";const w=e=>e==="global"||e==="root"?e:`shardBy:${e.field}`,$=e=>e.kind==="optional"?{kind:e.inner?.kind??"unknown",optional:!0}:{kind:e.kind,optional:!1},v=e=>{const a={};for(const[t,r]of Object.entries(e.shape))a[t]=$(r);const n={};for(const t of e.indexes)n[t.name]={fields:[...t.fields],unique:t.unique??!1};const o={};for(const t of e.relations)o[t.name]={field:t.field,kind:t.kind,table:t.table};return{fields:a,indexes:n,relations:o,shardMode:w(e.shardMode)}},I=(e,a)=>{const n={};for(const t of e.tables)n[t.name]=v(t);const o=[...a].sort();return{jurisdiction:e.jurisdiction,migrationIds:o,tables:S(n),version:g}};class y extends m{constructor(a){super("SCHEMA_SNAPSHOT_PARSE",a,{name:"SchemaSnapshotParseError"})}}const M=e=>{const a=k(e);if(a.status==="invalid")throw new y(a.error);return a.status==="ok"?a.snapshot:void 0},E={deploy:{allowDrift:!0,updateBaseline:!0},prepare:{allowDrift:!0,updateBaseline:!0},verify:{allowDrift:!0,updateBaseline:!1}},u=" • For backward-compatible changes (e.g. adding an optional field): pass `--allow-schema-drift` to skip the block.",p=" • To accept the new shape without a migration (you know data is compatible): pass `--update-schema-baseline`.",x=e=>{const a=e===void 0?void 0:E[e];if(e===void 0||a===void 0)return`${u}
2
+ ${p}
3
+ `;const n=a.updateBaseline?p:` • To accept the new shape without a migration, run \`lunora prepare --update-schema-baseline\` — \`lunora ${e}\` does not take that flag.`;return`${u}
4
+ ${n}
5
+ `},T=e=>{const{allowDrift:a=!1,baseline:n,command:o,current:t}=e,r=b(n,t),d=r.changes.filter(s=>s.severity==="breaking"),l=t.migrationIds.filter(s=>!(n?.migrationIds??[]).includes(s)),i=(s,c)=>({blocked:s,changes:r.changes,newMigrationIds:l,reason:c});if(r.changes.length===0||n===void 0)return i(!1,"");if(d.length===0){const s=r.changes.map(c=>` - ${c.summary}`).join(`
6
+ `);return i(!1,`schema drift detected (all additive/safe):
7
+ ${s}`)}const h=d.map(s=>` - ${s.summary}`).join(`
8
+ `);if(l.length>0)return i(!1,`breaking schema drift detected, but ${String(l.length)} new migration(s) were added (${l.join(", ")}):
9
+ ${h}`);const f=`deploy blocked: ${String(d.length)} breaking schema change(s) detected since the last blessed schema baseline — these changes are incompatible with existing data without a migration:
10
+ ${h}
11
+
12
+ To fix:
13
+ • For breaking changes: add a \`defineMigration({ id, table, up })\` in lunora/ for each affected table, then run \`lunora migrate\` (or \`lunora codegen\`) to apply and re-bless the baseline.
14
+ ${x(o)}Docs: https://lunora.dev/docs/migrations`;return a?i(!1,`${f}
15
+
16
+ (overridden by --allow-schema-drift)`):i(!0,f)};export{g as SCHEMA_SNAPSHOT_VERSION,y as SchemaSnapshotParseError,I as buildSchemaSnapshot,b as diffSchemaSnapshots,T as evaluateSchemaDrift,M as parseSchemaSnapshot,O as serializeSchemaSnapshot};
@@ -0,0 +1 @@
1
+ import{existsSync as m}from"node:fs";import{join as p}from"node:path";import{LunoraError as a}from"@lunora/errors";import{workflowDefaultName as g,workflowClassName as d,workflowBindingName as u}from"@lunora/workflow";import{Node as i,VariableDeclarationKind as w,SyntaxKind as x}from"ts-morph";import{diagnosticAt as f}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{T as N,v as b}from"./discover-ast-7ABwvTVn.mjs";const h="workflows.ts",E=new Set(["do","sleep","sleepUntil","waitForEvent"]),k=r=>{const e=r.getSymbol();if(!e)return r.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},y=b("workflow"),D=r=>{const e=r.getExpression();if(!i.isPropertyAccessExpression(e)||!E.has(e.getName()))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:i.isIdentifier(t)&&t.getText()==="step"},I=r=>{const e=r.getProperty("handler");if(!e)return[];const t=i.isPropertyAssignment(e)?e.getInitializer():e;if(!t)return[];const o=[];for(const n of t.getDescendantsOfKind(x.CallExpression)){if(!D(n))continue;const s=n.getArguments()[0];!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s))||o.push({line:n.getStartLineNumber(),method:n.getExpression().getName(),name:s.getLiteralValue()})}return o},l=r=>{let e=r;for(;e&&(i.isAsExpression(e)||i.isSatisfiesExpression(e)||i.isParenthesizedExpression(e));)e=e.getExpression();return e},S=r=>{const e=l(r);if(e&&i.isObjectLiteralExpression(e))return e;if(!(!e||!i.isIdentifier(e)))for(const t of e.getSymbol()?.getDeclarations()??[]){const o=i.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===w.Const?l(t.getInitializer()):void 0;if(o&&i.isObjectLiteralExpression(o))return o}},A=(r,e)=>{const t=S(r.getArguments()[0]);if(!t)throw f(r,`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:u(e),className:d(e),exportName:e,name:g(e),steps:I(t)},n=t.getProperty("name");return n&&i.isPropertyAssignment(n)&&(o.name=y(n.getInitializerOrThrow(),e,"name")),o},L=r=>{const e=[];for(const t of r.getVariableDeclarations()){if(!t.isExported())continue;const o=N(t.getInitializer());if(!o)continue;const n=o.getExpression();if(!i.isIdentifier(n)||!k(n))continue;const s=t.getNameNode();if(!i.isIdentifier(s))throw f(s,"defineWorkflow exports must be plain named exports (no destructuring)");e.push(A(o,s.getText()))}return e},W=r=>{const e=new Map,t=new Map;for(const o of r){const n=e.get(o.name);if(n!==void 0)throw new a("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${o.name}": produced by both "${n}" 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)}},C=(r,e)=>{const t=p(e,h);if(!m(t))return[];const o=r.getSourceFile(t)??r.addSourceFileAtPath(t),n=L(o);return n.sort((s,c)=>s.exportName.localeCompare(c.exportName)),W(n),n};export{h as WORKFLOWS_FILENAME,C as discoverWorkflows};
@@ -0,0 +1,3 @@
1
+ import{S}from"./emit-QxfTfRoJ.mjs";import{n as p}from"./paths-BmX5O1sG.mjs";import{LUNORA_ERROR_CODES as b,objectSchema as l,validatorIrToJsonSchema as d}from"./LUNORA_ERROR_CODES-zfAI2OFs.mjs";const x="/_lunora/rest",O=["authorization","cf-access-jwt-assertion","cookie"],f=["x-d1-bookmark","x-lunora-shard-key"],T=e=>[...O,...(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 a=o.trim().toLowerCase();a!==""&&!t.includes(a)&&t.push(a)}return t.length===0?void 0:t.join(", ")},k=(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(", ")},R=e=>e.scope==="public"?y(e.vary,...T(e),...f):y(e.vary,...f),P=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)}},j=e=>{const t=P(e);if(t!==void 0)return`${x}/${t.namespace}/${t.name}`},q=e=>e==="query"?"GET":"POST",h="#/components/responses/LunoraError",$=/:([A-Za-z_$][\w$]*)/gu,A=e=>[...e.matchAll($)].map(t=>t[1]),N=e=>e.replaceAll($,"{$1}"),u=e=>e.kind==="optional"?e.inner??e:e,w=e=>{const t=new Set(A(e.path)),r=[];for(const[o,a]of Object.entries(e.searchParams)){const c=u(a);r.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:a.kind!=="optional",schema:d(c)})}for(const[o,a]of Object.entries(e.params)){const c=u(a);r.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:a.kind!=="optional",schema:d(c)})}return r},C=e=>e?{content:{"application/json":{schema:d(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."},E=e=>{const t=p(e.filePath),r=w(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:C(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:h}},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:l(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},L=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o={additionalProperties:!1,properties:{args:l(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:{content:{"application/json":{schema:{description:"RPC result. The shape is TS-inferred from the function's return type; best-effort — any JSON."}}},description:"Successful RPC result (TypeScript-inferred return shape, documented best-effort)."},default:{$ref:h}},summary:`${e.kind}: ${r}`,tags:[t],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${r}`}},_=(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:k(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 a=R(r);return a!==void 0&&(o.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:a,type:"string"}}),{headers:o}},I=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o=j(r);if(o===void 0)return;const a=q(e.kind),c=a==="GET",n={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).",..._(e.expose?.cache,c?"get":"post")},default:{$ref:h}},summary:`${a} ${o}`,tags:[t],"x-lunora-function-kind":e.kind};if(c){const s=Object.entries(e.args).map(([i,m])=>{const v=u(m);return{description:`Argument \`${i}\` (JSON-encoded for non-string values).`,in:"query",name:i,required:m.kind!=="optional",schema:d(v)}});return s.length>0&&(n.parameters=s),{method:"get",operation:n,path:o}}return n.requestBody={content:{"application/json":{schema:l(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:n,path:o}},D=e=>{const t=e.version??"0.0.0",r={},o=new Set;for(const n of e.httpRoutes){const s=N(n.path),i=r[s]??{};i[n.method.toLowerCase()]=E(n),r[s]=i,o.add(p(n.filePath))}const a=e.functions.filter(n=>n.visibility!=="internal"&&n.kind!=="stream");for(const n of a){const{operation:s,pathKey:i}=L(n);r[i]={post:s},o.add(p(n.filePath))}for(const n of a){if(n.expose?.rest!==!0)continue;const s=I(n);if(s===void 0)continue;const i=r[s.path]??{};i[s.method]=s.operation,r[s.path]=i}const c=[...o].toSorted((n,s)=>n.localeCompare(s)).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:b,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}},U=e=>`${JSON.stringify(D(e),void 0,2)}
2
+ `,W=e=>`${S}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
3
+ `;export{D as buildOpenApiDocument,U as emitOpenApi,W as emitOpenApiModule};
@@ -0,0 +1 @@
1
+ import{readdirSync as d,lstatSync as x}from"node:fs";import{join as m,extname as E,relative as A,sep as y}from"node:path";import{Node as s,SyntaxKind as u}from"ts-morph";import{diagnosticAt as b}from"./CodegenDiagnosticError-DPezpZTz.mjs";const S=/\.ts$/u,L=(t,e)=>A(t,e).split(y).join("/").replace(S,""),p=(t,e=[],r=t)=>{let i;try{i=d(t)}catch{return e}for(const n of i){const o=m(t,n),a=x(o);if(a.isDirectory()){if(n==="_generated"||n==="node_modules")continue;p(o,e,r)}else if(a.isFile()&&E(n)===".ts"){if(n==="schema.ts"&&t===r)continue;e.push(o)}}return e},T=(t,e,r)=>{const i=[];for(const n of p(e)){const o=t.getSourceFile(n)??t.addSourceFileAtPath(n),a=L(e,n);for(const f of o.getDescendantsOfKind(u.CallExpression)){const c=r(f,a);c!==void 0&&i.push(c)}}return i},N=t=>{for(const e of t.getAncestors())if(s.isVariableDeclaration(e)&&e.getVariableStatement()?.hasExportKeyword()===!0)return e.getName();return""},v=(t,e)=>{if(e){const o=t.getArguments()[0];return o&&(s.isArrowFunction(o)||s.isFunctionExpression(o))?o:void 0}const r=t.getArguments()[0];if(!r||!s.isObjectLiteralExpression(r))return;const i=r.getProperty("handler");if(!i||!s.isPropertyAssignment(i))return;const n=i.getInitializer();return n&&(s.isArrowFunction(n)||s.isFunctionExpression(n))?n:void 0},D=(t,e)=>{if(!t||!s.isObjectLiteralExpression(t))return;const r=t.getProperty(e);return r&&s.isPropertyAssignment(r)?r.getInitializer():void 0},P=new Set(["findFirst","findFirstOrThrow","findMany"]),O=t=>{const e=t.getExpression();if(!s.isPropertyAccessExpression(e)||!P.has(e.getName()))return;const r=e.getExpression();if(s.isPropertyAccessExpression(r)&&r.getName()==="db"||s.isIdentifier(r)&&r.getText()==="db"){const i=t.getArguments()[0];return{options:t.getArguments()[1],table:i&&s.isStringLiteral(i)?i.getLiteralText():""}}if(s.isPropertyAccessExpression(r)){const i=r.getExpression();if(s.isPropertyAccessExpression(i)&&i.getName()==="db"||s.isIdentifier(i)&&i.getText()==="db")return{options:t.getArguments()[0],table:r.getName()}}},g=(t,e)=>{const r=t.getExpression();if(!s.isPropertyAccessExpression(r)||!e.has(r.getName()))return!1;const i=r.getExpression();return s.isPropertyAccessExpression(i)?i.getName()==="db":s.isIdentifier(i)&&i.getText()==="db"},l=t=>{const e=t.getArguments()[0];return e&&s.isStringLiteral(e)?e.getLiteralText():""},j=(t,e,r)=>{const i=new Set,n=new Set;for(const o of t.getDescendantsOfKind(u.CallExpression))if(g(o,e)){const a=l(o);a!==""&&i.add(a)}else if(g(o,r)){const a=l(o);a!==""&&n.add(a)}return{tablesRead:[...i],tablesWritten:[...n]}},z=t=>{let e=t;for(;e&&(s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isParenthesizedExpression(e));)e=e.getExpression();return e&&s.isCallExpression(e)?e:void 0},V=t=>{const e=t.getExportAssignment(n=>!n.isExportEquals());if(!e)return;const r=e.getExpression();if(!s.isIdentifier(r))return r;const i=r.getSymbol()?.getValueDeclaration();return i&&s.isVariableDeclaration(i)?i.getInitializer():r},C=t=>{const e=t.getArguments()[1];return e&&s.isStringLiteral(e)?e.getLiteralValue():""},K=(t,e)=>{if(!s.isObjectLiteralExpression(t))return;const r=t.getProperty(e);if(!r||!s.isPropertyAssignment(r))return;const i=r.getInitializer();return i&&s.isStringLiteral(i)?i.getLiteralText():void 0},$=t=>s.isIdentifier(t)&&t.getText()==="ctx",R=t=>(e,r,i)=>{if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e))return e.getLiteralValue();throw b(e,`${t} "${r}": \`${i}\` must be a static string literal — it is deploy configuration codegen writes into wrangler.jsonc`)};export{D as C,K as D,j as F,V as I,C as O,T as P,O as R,z as T,p as g,N as h,L as p,R as v,v as w,$ as z};
@@ -0,0 +1 @@
1
+ import{Node as s,SyntaxKind as g}from"ts-morph";import{g as E,p as N}from"./discover-ast-7ABwvTVn.mjs";const x=(e,t)=>{if(e.getText()!==t)return!1;const r=e.getParent();return s.isPropertyAccessExpression(r)&&r.getNameNode()===e?!1:!(s.isPropertyAssignment(r)&&r.getNameNode()===e)},p=(e,t)=>s.isIdentifier(e)?x(e,t):e.getDescendantsOfKind(g.Identifier).some(r=>x(r,t)),l=e=>p(e,"ctx"),A=e=>{let t=e;for(;s.isPropertyAccessExpression(t)||s.isElementAccessExpression(t)||s.isNonNullExpression(t);)t=t.getExpression();return s.isIdentifier(t)?t:void 0},F=e=>{if(s.isIdentifier(e))return e.getText();if(s.isPropertyAccessExpression(e))return e.getName()},m=e=>p(e,"args"),a=e=>{if(!s.isIdentifier(e))return;const t=e.getText(),r=e.getFirstAncestor(o=>s.isArrowFunction(o)||s.isFunctionExpression(o)||s.isFunctionDeclaration(o));if(r===void 0)return;const n=e.getStart();let i,f=-1;for(const o of r.getDescendantsOfKind(g.VariableDeclaration)){if(o.getName()!==t)continue;const c=o.getInitializer(),u=o.getStart();c!==void 0&&u<n&&u>f&&(i=c,f=u)}return i},K=e=>{if(m(e))return!0;const t=a(e);return t!==void 0&&m(t)},C=e=>{if(s.isCallExpression(e)||s.isNewExpression(e))return!1;const t=a(e);return t===void 0||!(s.isCallExpression(t)||s.isNewExpression(t))},T=e=>{if(l(e))return!0;const t=a(e);if(t!==void 0&&l(t))return!0;const r=t??e;return(s.isIdentifier(r)?[r]:r.getDescendantsOfKind(g.Identifier)).some(n=>{const i=a(n);return i!==void 0&&l(i)})},d=(e,t)=>p(e,t),$=(e,t)=>{if(d(e,t))return!0;const r=a(e);if(r!==void 0&&d(r,t))return!0;const n=A(e);if(n!==void 0){const i=a(n);return i!==void 0&&d(i,t)}return!1},P=e=>{for(const t of e.getAncestors())if(s.isVariableDeclaration(t)&&t.getVariableStatement()?.hasExportKeyword()===!0)return t.getName();return"<module>"},y=new Set(["withIndex","withSearchIndex"]),I=e=>{const t=e.getExpression();if(!s.isPropertyAccessExpression(t)||t.getName()!=="query")return!1;const r=t.getExpression();return s.isPropertyAccessExpression(r)?r.getName()==="db":s.isIdentifier(r)&&r.getText()==="db"},h=e=>{const t=[];let r=e;for(;;){const n=r.getParent();if(!n||!s.isPropertyAccessExpression(n))break;const i=n.getParent();if(!i||!s.isCallExpression(i))break;t.push(n.getName()),r=i}return t},v=/\b[A-Za-z_$][\w$]*\._id\s*===?[^=]/u,b=e=>{let t=e;for(;;){const r=t.getParent();if(!r||!s.isPropertyAccessExpression(r))return!1;const n=r.getParent();if(!n||!s.isCallExpression(n))return!1;if(r.getName()==="filter"){const i=n.getArguments()[0];if(i&&v.test(i.getText()))return!0}t=n}},S=e=>{const t=e.getArguments()[0];return t&&s.isStringLiteral(t)?t.getLiteralText():""},O=(e,t)=>{const r=[];for(const n of E(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),f=N(t,n);for(const o of i.getDescendantsOfKind(g.CallExpression)){if(!I(o))continue;const c=h(o);c.includes("filter")&&r.push({exportName:P(o),file:f,filtersPrimaryKey:b(o),hasFilter:!0,hasIndex:c.some(u=>y.has(u)),line:o.getStartLineNumber(),table:S(o)})}}return r};export{T as a,C as b,F as c,$ as d,P as e,d as f,K as i,m as r,a as s,O as y};
@@ -0,0 +1 @@
1
+ import{SyntaxKind as g,Node as s}from"ts-morph";import{g as u,p as d,h as m}from"./discover-ast-7ABwvTVn.mjs";const h=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"},l=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},E=(r,t)=>{const e=[];for(const o of u(t)){const c=r.getSourceFile(o)??r.addSourceFileAtPath(o),p=d(t,o);for(const n of c.getDescendantsOfKind(g.CallExpression)){if(!h(n))continue;const i=m(n);if(i==="")continue;const a=n.getExpression(),f=s.isPropertyAccessExpression(a)?a.getName():"";e.push({exportName:i,file:p,hasHeaders:l(n),line:n.getStartLineNumber(),method:f})}}return e};export{E as default};
@@ -0,0 +1 @@
1
+ import{LunoraError as T}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as b,isValidCronExpression as A,warnIfSecondsLeading as O,compileCronSchedule as S}from"@lunora/scheduler";import{SyntaxKind as m,Node as s}from"ts-morph";import{diagnosticAt as u,CodegenDiagnosticError as I}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{E as $}from"./module-specifiers-8FEEiUcv.mjs";import{n as j}from"./paths-BmX5O1sG.mjs";import{g as y}from"./discover-ast-7ABwvTVn.mjs";const R=new Set([...b,"cron"]),D=e=>{const t=e.getSymbol();if(!t)return e.getText()==="cronJobs";for(const r of t.getDeclarations())if(s.isImportSpecifier(r))return $(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},P=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const n=r.getInitializer();if(n?.getKind()!==m.CallExpression)continue;const i=n.getExpression();s.isIdentifier(i)&&D(i)&&t.add(r.getName())}return t},V=e=>{let t=e;for(;s.isCallExpression(t)||s.isPropertyAccessExpression(t);)t=t.getExpression();return s.isIdentifier(t)?t.getText():void 0},_=(e,t)=>{const r=e.getArguments()[t];return r&&(s.isStringLiteral(r)||s.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},L=(e,t)=>{if(s.isStringLiteral(e)||s.isNoSubstitutionTemplateLiteral(e)||s.isNumericLiteral(e))return e.getLiteralValue();if(s.isTrueLiteral(e))return!0;if(s.isFalseLiteral(e))return!1;if(s.isPrefixUnaryExpression(e)&&e.getOperatorToken()===m.MinusToken){const r=e.getOperand();if(s.isNumericLiteral(r))return-r.getLiteralValue()}if(s.isObjectLiteralExpression(e))return g(e,t);if(s.isArrayLiteralExpression(e))return e.getElements().map(r=>L(r,t));throw u(e,`Cron job "${t}" passes a non-static value where a literal is required; codegen can only read literals.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500})},g=(e,t)=>{const r={};for(const n of e.getProperties()){if(!s.isPropertyAssignment(n))throw u(n,`Cron job "${t}" uses an unsupported object property (shorthand/spread/method) where a static literal is required.`,{code:"CRON_NON_STATIC_VALUE",name:"LunoraError",status:500});const i=n.getInitializer();i&&(r[n.getName()]=L(i,t))}return r},C=(e,t,r)=>{const n=e.getArguments()[t];if(!n||!s.isPropertyAccessExpression(n))throw u(e,`Cron job "${r}" must reference a function statically (e.g. internal.email.digest); codegen cannot resolve a dynamic reference.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const i=n.getName(),o=n.getExpression();if(!s.isPropertyAccessExpression(o))throw u(n,`Cron job "${r}" function reference must be of the form internal.file.fn (two property accesses).`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});const a=o.getName();return`${j(a)}:${i}`},h=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),x=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),w=(e,t,r,n,i,o)=>{const a=e.getExpression();if(!s.isIdentifier(a)||a.getText()!==t)return;const f=r.get(e.getName());if(f)return o(f);throw u(e,`Cron job "${n}" targets ${t}.${e.getName()}, but no such ${i} is declared in lunora/${i}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},k=(e,t,r,n,i)=>{const o=e.getArguments()[t];if(o&&s.isPropertyAccessExpression(o)){const a=w(o,"workflows",n,r,"workflow",h);return a||w(o,"agents",i,r,"agent",x)||{functionPath:C(e,t,r)}}if(o&&s.isIdentifier(o)){const a=n.get(o.getText()),f=i.get(o.getText());if(a&&f)throw u(o,`Cron job "${r}" references "${o.getText()}", which is ambiguous: a workflow and an agent are both declared under that name.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500});if(a)return h(a);if(f)return x(f);throw u(o,`Cron job "${r}" references "${o.getText()}", which is neither a function (internal.file.fn / api.file.fn) nor a declared workflow in lunora/workflows.ts nor a declared agent in lunora/agents.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})}return{functionPath:C(e,t,r)}},F=/^@lunora\/scheduler:\s*/u,v=(e,t)=>{const r=_(e,1);if(r===void 0)throw u(e,`Cron job "${t}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!A(r))throw u(e,`Cron job "${t}" has an invalid cron expression "${r}" — expected 5 or 6 space-separated fields.`,{code:"CRON_EXPR_INVALID",name:"LunoraError",status:500});return O(r,`cron expression for job "${t}"`),r},U=(e,t,r)=>{const n=e.getArguments()[1];if(!n||!s.isObjectLiteralExpression(n))throw u(e,`Cron job "${r}" must pass an object-literal schedule to ".${t}(...)".`,{code:"CRON_SCHEDULE_NOT_STATIC",name:"LunoraError",status:500});try{return S(t,g(n,r),r)}catch(i){if(i instanceof I)throw i;const o=i instanceof Error?i.message.replace(F,""):String(i);throw u(e,o,{code:"CRON_SCHEDULE_INVALID",name:"LunoraError",status:500})}},M=(e,t,r,n,i)=>{const o=t.getName();if(!R.has(o)||!r.has(V(t.getExpression())??""))return;const a=_(e,0);if(a===void 0||a.trim()==="")throw u(e,`A cron ".${o}(...)" registration must pass a non-empty string-literal name as its first argument.`,{code:"CRON_NAME_NOT_STATIC",name:"LunoraError",status:500});const f=o==="cron"?v(e,a):U(e,o,a),c=k(e,2,a,n,i),l=e.getArguments()[3];return{args:l&&s.isObjectLiteralExpression(l)?g(l,a):{},cron:f,name:a,...c}},z=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new T("DUPLICATE_CRON_NAME",`Duplicate cron job name "${r.name}": cron names must be unique across the project.`,{status:500});t.add(r.name)}},Q=(e,t,r=[],n=[])=>{const i=y(t),o=[],a=new Map(r.map(c=>[c.exportName,c])),f=new Map(n.map(c=>[c.exportName,c]));for(const c of i){const l=e.getSourceFile(c)??e.addSourceFileAtPath(c),p=P(l);if(p.size!==0)for(const d of l.getDescendantsOfKind(m.CallExpression)){const N=d.getExpression();if(!s.isPropertyAccessExpression(N))continue;const E=M(d,N,p,a,f);E&&o.push(E)}}return o.sort((c,l)=>c.name.localeCompare(l.name)),z(o),o};export{Q as default};
@@ -0,0 +1 @@
1
+ import{Node as s,SyntaxKind as D}from"ts-morph";import{g as C,p as $}from"./discover-ast-7ABwvTVn.mjs";import{t as O}from"./module-specifiers-8FEEiUcv.mjs";import{s as j,g as P}from"./parse-validator-CusS8QwU.mjs";import{n as z}from"./paths-BmX5O1sG.mjs";const m=new Set(["action","mutation","query","stream"]),b=/\bany\b(?!\s*(?:\?\s*)?:)/u,h=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`/gu,U=/^[A-Za-z_$][\w$]*$/u,V=e=>U.test(e)?e:JSON.stringify(e),N={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},M={onConnect:"connect",onDisconnect:"disconnect"},R=O,S=e=>{const t=e.getSymbol();if(!t)return e.getText();const i=t.getDeclarations();for(const r of i){if(!s.isImportSpecifier(r))continue;const n=r.getImportDeclaration().getModuleSpecifierValue();return R(n)?r.getNameNode().getText():void 0}},T=(e,t=!1)=>{let i=e;for(;s.isCallExpression(i);){const n=i.getExpression();if(!s.isPropertyAccessExpression(n))return;i=n.getExpression()}if(!s.isIdentifier(i))return;const r=S(i);if(r===void 0){if(t)return;const n=i.getSymbol()?.getValueDeclaration();if(n&&s.isVariableDeclaration(n)){const o=n.getInitializer();return o?T(o,!0):void 0}return}return m.has(r)?"public":N[r]?"internal":void 0},y=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&s.isStringLiteral(r)?r.getLiteralValue():void 0},E=(e,t)=>{const i=e.getProperty(t);if(i===void 0||!s.isPropertyAssignment(i))return;const r=i.getInitializer();return r!==void 0&&s.isNumericLiteral(r)?r.getLiteralValue():void 0},_=e=>{const t=e.getProperty("cache");if(t===void 0||!s.isPropertyAssignment(t))return;const i=t.getInitializer();if(i===void 0||!s.isObjectLiteralExpression(i))return;const r=y(i,"scope"),n=E(i,"maxAge"),o=E(i,"staleWhileRevalidate"),a=y(i,"tag"),c=y(i,"vary"),l={...n===void 0?{}:{maxAge:n},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(l).length===0?void 0:l},H=e=>{if(e===void 0||!s.isObjectLiteralExpression(e))return{};const t=_(e),i=e.getProperty("rest");return i!==void 0&&s.isPropertyAssignment(i)?{...t===void 0?{}:{cache:t},rest:i.getInitializer()?.getText()==="true"}:t===void 0?{}:{cache:t}},q=e=>{let t=e;for(;s.isCallExpression(t);){const i=t.getExpression();if(!s.isPropertyAccessExpression(i))return;if(i.getName()==="expose")return H(t.getArguments()[0]);t=i.getExpression()}},B=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return{};const i=t.getProperty("args");if(!i||!s.isPropertyAssignment(i))return{};const r=i.getInitializer();return!r||!s.isObjectLiteralExpression(r)?{}:P(r)},W="/_generated/",J=(e,t,i)=>{const r=t.getSourceFile(),n=(a,c)=>r.getImportDeclarations().some(l=>l.getModuleSpecifierSourceFile()!==a?!1:l.getNamespaceImport()!==void 0||l.getNamedImports().some(f=>f.getName()===c)),o=a=>{const c=a.getSourceFile();if(c.isInNodeModules()||c.isDeclarationFile()||!s.isInterfaceDeclaration(a)&&!s.isTypeAliasDeclaration(a))return!1;const l=c.getFilePath();return l.includes(W)?!1:l===i||n(c,a.getName())};return[e.getSymbol(),e.getAliasSymbol()].flatMap(a=>a?.getDeclarations()??[]).some(a=>o(a))},K=e=>{const t=[...e.getTypeArguments()];return e.isUnion()&&t.push(...e.getUnionTypes()),e.isIntersection()&&t.push(...e.getIntersectionTypes()),t},I=e=>!e.isObject()||e.isArray()||e.isTuple()||e.getCallSignatures().length>0||e.getConstructSignatures().length>0?!1:e.getStringIndexType()===void 0&&e.getNumberIndexType()===void 0,p=(e,t,i,r=new Set)=>r.has(e)?!1:(r.add(e),J(e,t,i)||K(e).some(n=>p(n,t,i,r))?!0:I(e)?e.getProperties().some(n=>p(n.getTypeAtLocation(t),t,i,r)):!1),Q=(e,t)=>{const i=e.getValueDeclaration()??e.getDeclarations()[0];return i&&(s.isPropertySignature(i)||s.isPropertyDeclaration(i))&&i.hasQuestionToken()?!0:t.isUnion()&&t.getUnionTypes().some(r=>r.isUndefined())},G=8,Z=(e,t,i,r,n,o)=>{const a=e.getArrayElementType(),c=a?o(a,t,i,r,n):void 0;if(c!==void 0)return a?.isUnion()?`(${c})[]`:`${c}[]`},X=(e,t,i,r,n,o)=>{const a=[];for(const c of e.getUnionTypes()){const l=o(c,t,i,r,n);if(l===void 0)return;a.push(l)}return a.join(" | ")},Y=(e,t,i,r,n,o)=>{if(!I(e))return;const a=[];for(const c of e.getProperties()){const l=c.getTypeAtLocation(t),f=Q(c,l),w=f&&l.isUnion()?l.getUnionTypes().filter(d=>!d.isUndefined()):[l],x=[];for(const d of w){const v=o(d,t,i,r+1,n);if(v===void 0)return;x.push(v)}a.push(`${V(c.getName())}${f?"?":""}: ${x.join(" | ")}`)}return a.length>0?`{ ${a.join("; ")} }`:"{}"},g=(e,t,i,r,n)=>{if(r>G||n.has(e))return;if(!p(e,t,i))return e.getText(t);const o=new Set(n).add(e);return e.isArray()?Z(e,t,i,r,o,g):e.isUnion()?X(e,t,i,r,o,g):Y(e,t,i,r,o,g)},k=e=>{const t=e.getType().getCallSignatures()[0];if(!t)return"unknown";let i=t.getReturnType();const r=(i.getSymbol()??i.getAliasSymbol())?.getName();if(r==="Promise"||r==="AsyncIterable"||r==="AsyncIterableIterator"||r==="AsyncGenerator"){const a=i.getTypeArguments()[0];a&&(i=a)}const n=i.getText(e);if(!n||n==="any"||n==="never"||b.test(n.replaceAll(h,"")))return"unknown";const o=e.getSourceFile().getFilePath();return p(i,e,o)?g(i,e,o,0,new Set)??"unknown":n},xe=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const i=t.getTypeAtLocation(e).getProperty("types");if(!i)return;const r=i.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!r)return;const n=r.getTypeAtLocation(e),o=n.getText(e);if(!o||o==="any"||o==="never"||b.test(o.replaceAll(h,"")))return;const a=e.getSourceFile().getFilePath();return p(n,e,a)?g(n,e,a,0,new Set):o},ee=e=>{const t=e.getArguments()[0];if(!t||!s.isObjectLiteralExpression(t))return"unknown";const i=t.getProperty("handler");if(!i||!s.isPropertyAssignment(i))return"unknown";const r=i.getInitializer();return!r||!(s.isArrowFunction(r)||s.isFunctionExpression(r))?"unknown":k(r)},te=e=>{const t=e.getArguments()[0];return!t||!(s.isArrowFunction(t)||s.isFunctionExpression(t))?"unknown":k(t)},ie=e=>{let t={},i=e;for(;s.isCallExpression(i);){const r=i.getExpression();if(!s.isPropertyAccessExpression(r))break;if(r.getName()==="input"){const n=i.getArguments()[0];n&&s.isObjectLiteralExpression(n)&&(t={...P(n),...t})}i=r.getExpression()}return t},re=e=>{let t=e;for(;s.isCallExpression(t);){const i=t.getExpression();if(!s.isPropertyAccessExpression(i))return;if(i.getName()==="output"){const r=t.getArguments()[0];return r&&s.isExpression(r)?j(r):void 0}t=i.getExpression()}},ne=e=>{const t=e.getExpression();if(s.isPropertyAccessExpression(t)){const o=t.getName();if(!m.has(o))return;const a=t.getExpression();if(a.getType().getProperty("__lunoraProcedure"))return{kind:o,receiver:a,visibility:a.getType().getProperty("__lunoraVisibility")?"internal":"public"};const c=T(a);return c?{kind:o,receiver:a,visibility:c}:void 0}if(!s.isIdentifier(t))return;const i=S(t);if(!i)return;if(m.has(i))return{kind:i,visibility:"public"};const r=N[i];if(r)return{kind:r,visibility:"internal"};const n=M[i];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}},A=e=>e!==void 0&&(s.isArrowFunction(e)||s.isFunctionExpression(e))?e:void 0,ve=e=>s.isPropertyAccessExpression(e)&&e.getName()==="db"||s.isIdentifier(e)&&e.getText()==="db",Ee=e=>{const t=e.getArguments()[0],i=A(t);if(i!==void 0)return i;if(t===void 0||!s.isObjectLiteralExpression(t))return;const r=t.getProperty("handler");return r!==void 0&&s.isPropertyAssignment(r)?A(r.getInitializer()):void 0},se=e=>s.isIdentifier(e)?e.getText():s.isPropertyAccessExpression(e)?e.getName():"",Ae=(e,t)=>{let i=e;for(;s.isCallExpression(i);){const r=i.getExpression();if(!s.isPropertyAccessExpression(r))break;if(r.getName()===t)return!0;i=r.getExpression()}return!1},Pe=(e,t,i)=>{let r=e;for(;s.isCallExpression(r);){const n=r.getExpression();if(!s.isPropertyAccessExpression(n))break;const o=r.getArguments()[0];if(n.getName()===t&&o!==void 0&&s.isCallExpression(o)&&se(o.getExpression())===i)return!0;r=n.getExpression()}return!1},oe=e=>{const t=ne(e);if(t){if(t.receiver){const i=q(t.receiver),r=re(t.receiver);return{args:ie(t.receiver),...i?{expose:i}:{},kind:t.kind,...r?{output:r}:{},returnType:te(e),visibility:t.visibility}}return t.lifecycle?{args:{},kind:t.kind,lifecycle:t.lifecycle,returnType:"void",visibility:t.visibility}:{args:B(e),kind:t.kind,returnType:ee(e),visibility:t.visibility}}},ae=8,u=(e,t=0)=>{if(t>ae)return;if(s.isCallExpression(e))return e;if(s.isParenthesizedExpression(e)||s.isAsExpression(e)||s.isSatisfiesExpression(e)||s.isNonNullExpression(e))return u(e.getExpression(),t+1);if(!s.isIdentifier(e)&&!s.isPropertyAccessExpression(e))return;const i=e.getSymbol()?.getValueDeclaration();return i?F(i,t+1):void 0},F=(e,t)=>{if(s.isVariableDeclaration(e)||s.isPropertyAssignment(e)){const i=e.getInitializer();return i?u(i,t):void 0}if(s.isShorthandPropertyAssignment(e))return u(e.getNameNode(),t);if(s.isBindingElement(e)){const i=e.getPropertyNameNode()?.getText()??e.getName(),r=e.getFirstAncestorByKind(D.VariableDeclaration)?.getInitializer()?.getType().getProperty(i)?.getValueDeclaration();return r?F(r,t+1):void 0}},ce=e=>{const t=e.getNameNode();if(s.isObjectBindingPattern(t)){const n=[];for(const o of t.getElements()){const a=u(o.getNameNode());a&&n.push([o.getName(),a])}return n}const i=e.getInitializer(),r=i&&(s.isCallExpression(i)?i:u(i));return r?[[e.getName(),r]]:[]},L=(e,t,i)=>{const r=oe(e);if(r)return{args:r.args,exportName:t,filePath:i,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},le=(e,t)=>{const i=[];for(const r of e.getExportAssignments()){if(r.isExportEquals())continue;const n=u(r.getExpression()),o=n?L(n,"default",t):void 0;o&&i.push(o)}return i},ue=(e,t)=>{const i=[];for(const r of e.getVariableStatements())if(r.isExported())for(const n of r.getDeclarations())for(const[o,a]of ce(n)){const c=L(a,o,t);c&&i.push(c)}return i.push(...le(e,t)),i},ge=e=>{const t=new Map;for(const i of e){const r=z(i.filePath),n=t.get(r);if(n&&n!==i.filePath)throw Object.assign(new Error(`Namespace collision: "${n}" and "${i.filePath}" both resolve to "${r}". Rename one of the files so the JS-identifier-sanitized names differ. (note: case-insensitive filesystems may also cause this — \`foo\` and \`FOO\` map to the same identifier)`),{code:"NAMESPACE_COLLISION",name:"LunoraError",paths:[n,i.filePath],status:500});t.set(r,i.filePath)}},be=(e,t)=>{const i=C(t),r=[];for(const n of i){const o=e.getSourceFile(n)??e.addSourceFileAtPath(n),a=$(t,n);r.push(...ue(o,a))}return r.sort((n,o)=>`${n.filePath}:${n.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),ge(r),r};export{Ae as chainHasStep,Pe as chainUsesWrappedCall,ne as classifyProcedureCall,be as discoverFunctions,A as inlineHandler,ve as isDatabaseAccessor,C as listLunoraSourceFiles,$ as lunoraRelativePath,Ee as procedureHandler,xe as resolveStandardSchemaType,k as unwrapHandlerReturn};
@@ -0,0 +1 @@
1
+ import{Node as a}from"ts-morph";import{g as m,p as h}from"./discover-ast-7ABwvTVn.mjs";import{unwrapHandlerReturn as f}from"./discoverFunctions-4TNKUv7P.mjs";import{s as g,g as l}from"./parse-validator-CusS8QwU.mjs";const u=new Set(["delete","get","head","options","patch","post","put"]),d=new Set(["body","params","searchParams"]),x=new Set(["handler","stream"]),E=r=>{const e=r.getArguments()[0];if(e&&a.isStringLiteral(e))return e.getLiteralValue()},P=r=>{const e=r.getArguments()[0];return e&&a.isObjectLiteralExpression(e)?l(e):{}},A=r=>{if(!a.isCallExpression(r))return;const e=r.getExpression();if(!a.isPropertyAccessExpression(e))return;const o=e.getName();if(!u.has(o))return;const n=e.getExpression();if(!a.isIdentifier(n)||n.getText()!=="httpRoute")return;const s=E(r);return s===void 0?void 0:{method:o.toUpperCase(),path:s}},y=(r,e)=>{const o={body:{},params:{},searchParams:{},stream:e==="stream"},n=r.getExpression();if(!a.isPropertyAccessExpression(n))return;let s=n.getExpression();for(;a.isCallExpression(s);){const i=s.getExpression();if(!a.isPropertyAccessExpression(i))break;const p=i.getName();if(u.has(p))break;if(d.has(p)){const c=P(s);o[p]={...c,...o[p]}}else if(p==="output"&&o.output===void 0){const c=s.getArguments()[0];c&&a.isExpression(c)&&(o.output=g(c))}s=i.getExpression()}const t=A(s);if(t)return o.method=t.method,o.path=t.path,o},b=r=>{const e=r.getArguments()[0];return!e||!(a.isArrowFunction(e)||a.isFunctionExpression(e))?"unknown":f(e)},S=(r,e,o,n)=>{const s=e.getName();if(!x.has(s))return;const t=y(r,s);if(!(t?.method===void 0||t.path===void 0))return{body:t.body,exportName:o,filePath:n,method:t.method,params:t.params,path:t.path,searchParams:t.searchParams,stream:t.stream,...t.stream?{chunkType:b(r)}:{},...t.output?{output:t.output}:{}}},C=(r,e)=>{const o=[];for(const n of r.getVariableStatements())if(n.isExported())for(const s of n.getDeclarations()){const t=s.getInitializer();if(!t||!a.isCallExpression(t))continue;const i=t.getExpression();if(!a.isPropertyAccessExpression(i))continue;const p=S(t,i,s.getName(),e);p&&o.push(p)}return o},k=(r,e)=>{const o=m(e),n=[];for(const s of o){const t=r.getSourceFile(s)??r.addSourceFileAtPath(s),i=h(e,s);n.push(...C(t,i))}return n.sort((s,t)=>`${s.method} ${s.path}`.localeCompare(`${t.method} ${t.path}`)||s.filePath.localeCompare(t.filePath)),n};export{k as default};
@@ -0,0 +1 @@
1
+ import{SyntaxKind as l,Node as i}from"ts-morph";import{g,p as f,h as p}from"./discover-ast-7ABwvTVn.mjs";const d=t=>{const e=t.getExpression();if(!i.isPropertyAccessExpression(e)||e.getName()!=="insert")return!1;const r=e.getExpression();return i.isPropertyAccessExpression(r)?r.getName()==="db":i.isIdentifier(r)&&r.getText()==="db"},u=t=>{if(!i.isIdentifier(t))return;const e=t.getSymbol(),r=e?.getAliasedSymbol()?.getDeclarations()??e?.getDeclarations()??[];for(const s of r)if(i.isVariableDeclaration(s)){const n=s.getInitializer();if(n&&i.isStringLiteral(n))return n.getLiteralText()}},m=t=>{const e=t.getArguments()[0];return e?i.isStringLiteral(e)?e.getLiteralText():u(e)??"":""},b=(t,e)=>{const r=[];for(const s of g(e)){const n=t.getSourceFile(s)??t.addSourceFileAtPath(s),c=f(e,s);for(const o of n.getDescendantsOfKind(l.CallExpression)){if(!d(o))continue;const a=p(o);a!==""&&r.push({exportName:a,file:c,line:o.getStartLineNumber(),table:m(o)})}}return r};export{b as default};
@@ -0,0 +1 @@
1
+ import{Node as o}from"ts-morph";import{g as u,p as x,F as h}from"./discover-ast-7ABwvTVn.mjs";import{classifyProcedureCall as p}from"./discoverFunctions-4TNKUv7P.mjs";const v=t=>{if(!o.isCallExpression(t))return!1;const s=t.getExpression();return o.isIdentifier(s)?s.getText()==="mask":o.isPropertyAccessExpression(s)?s.getName()==="mask":!1},f=t=>{if(o.isPropertyAssignment(t)||o.isShorthandPropertyAssignment(t)||o.isMethodDeclaration(t)||o.isGetAccessorDeclaration(t))return t.getName()},y=t=>{const s=t.getArguments()[0];if(!s||!o.isObjectLiteralExpression(s))return[];const e=[];for(const r of s.getProperties()){const i=f(r);if(i===void 0||!o.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!o.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=f(a);c!==void 0&&e.push({column:c,table:i})}}return e},g=t=>{const s=[];let e=t;for(;o.isCallExpression(e);){const r=e.getExpression();if(!o.isPropertyAccessExpression(r))break;if(r.getName()==="use"){const i=e.getArguments()[0];i&&v(i)&&s.push(i)}e=r.getExpression()}return s},E=t=>{const s=g(t);return{maskColumns:s.flatMap(e=>y(e)),usesMask:s.length>0}},S=new Set(["findFirst","findFirstOrThrow","findMany","get","query"]),k=new Set(["delete","insert","patch","replace"]),M=(t,s)=>{if(!o.isVariableDeclaration(t))return;const e=t.getInitializer();if(!e||!o.isCallExpression(e))return;const r=p(e);if(!r)return;const i=r.receiver?E(r.receiver):{maskColumns:[],usesMask:!1},{tablesRead:n,tablesWritten:a}=h(t,S,k);return{exportName:t.getName(),file:s,maskColumns:i.maskColumns,tablesRead:n,tablesWritten:a,usesMask:i.usesMask,visibility:r.visibility}},j=(t,s)=>{const e=[];for(const r of u(s)){const i=t.getSourceFile(r)??t.addSourceFileAtPath(r),n=x(s,r);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations()){const l=M(c,n);l&&e.push(l)}}return e},P=t=>{if(o.isPropertyAssignment(t)){const s=t.getInitializer();if(s&&o.isStringLiteral(s)){const e=s.getLiteralText();if(e==="redact"||e==="hash")return e}}return"custom"},N=t=>{const s=t.getArguments()[0];if(!s||!o.isObjectLiteralExpression(s))return[];const e=[];for(const r of s.getProperties()){const i=f(r);if(i===void 0||!o.isPropertyAssignment(r))continue;const n=r.getInitializer();if(!(!n||!o.isObjectLiteralExpression(n)))for(const a of n.getProperties()){const c=f(a);c!==void 0&&e.push({column:c,strategy:P(a),table:i})}}return e},b=t=>{const s=[];for(const e of t.getVariableStatements())if(e.isExported())for(const r of e.getDeclarations()){const i=r.getInitializer(),n=i&&o.isCallExpression(i)?p(i):void 0;n?.receiver&&s.push(n.receiver)}return s},V=(t,s)=>{const e=new Map;for(const r of u(s)){const i=t.getSourceFile(r)??t.addSourceFileAtPath(r);for(const n of b(i))for(const a of g(n))for(const c of N(a)){const l=`${c.table}\0${c.column}`;e.has(l)||e.set(l,c)}}return{columns:[...e.values()]}},F=(t,s,e)=>{const r=t.getArguments()[0];if(!r||!o.isObjectLiteralExpression(r))return[];const i=[];for(const n of r.getProperties()){const a=f(n);if(a===void 0||!o.isPropertyAssignment(n))continue;const c=n.getInitializer();if(!(!c||!o.isObjectLiteralExpression(c)))for(const l of c.getProperties()){const m=f(l);if(m===void 0)continue;const d=P(l);d!=="custom"&&i.push({column:m,exportName:s,file:e,line:l.getStartLineNumber(),strategy:d,table:a})}}return i},L=(t,s)=>{if(!o.isVariableDeclaration(t))return[];const e=t.getInitializer(),r=e&&o.isCallExpression(e)?p(e):void 0;return r?.receiver?g(r.receiver).flatMap(i=>F(i,t.getName(),s)):[]},w=(t,s)=>{const e=[];for(const r of u(s)){const i=t.getSourceFile(r)??t.addSourceFileAtPath(r),n=x(s,r);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())e.push(...L(c,n))}return e},C=t=>o.isPropertyAssignment(t)||o.isMethodDeclaration(t)||o.isGetAccessorDeclaration(t)?o.isComputedPropertyName(t.getNameNode()):!1,D=t=>o.isPropertyAssignment(t)||o.isShorthandPropertyAssignment(t)||o.isMethodDeclaration(t)||o.isGetAccessorDeclaration(t)?C(t):!0,A=(t,s=!1)=>{for(const e of t.getProperties()){if(D(e))return!0;if(s)continue;if(!o.isPropertyAssignment(e))return!0;const r=e.getInitializer();if(!r||!o.isObjectLiteralExpression(r)||A(r,!0))return!0}return!1},R=(t,s)=>{for(const e of u(s)){const r=t.getSourceFile(e)??t.addSourceFileAtPath(e);for(const i of b(r))for(const n of g(i)){const a=n.getArguments()[0];if(a!==void 0&&(!o.isObjectLiteralExpression(a)||A(a)))return!0}}return!1};export{j as default,R as discoverMaskHasNonLiteralPolicy,V as discoverMaskMetadata,w as discoverMaskStrategies};
@@ -0,0 +1 @@
1
+ import{SyntaxKind as g,Node as s}from"ts-morph";import{diagnosticAt as u}from"./CodegenDiagnosticError-DPezpZTz.mjs";import{g as m,p}from"./discover-ast-7ABwvTVn.mjs";import{o as h}from"./module-specifiers-8FEEiUcv.mjs";const I=r=>{const i=r.getSymbol();if(!i)return r.getText()==="defineMigration";for(const t of i.getDeclarations())if(s.isImportSpecifier(t))return h(t.getImportDeclaration().getModuleSpecifierValue())?t.getNameNode().getText()==="defineMigration":!1;return!1},f=(r,i)=>{const t=r.getProperty(i);if(!t||!s.isPropertyAssignment(t))return;const e=t.getInitializer();return e&&s.isStringLiteral(e)?e.getLiteralValue():void 0},b=(r,i)=>{const t=r.getInitializer();if(t?.getKind()!==g.CallExpression)return;const e=t.getExpression();if(!s.isIdentifier(e)||!I(e))return;const o=t.getArguments()[0];if(!o||!s.isObjectLiteralExpression(o))return;const n=f(o,"id"),a=r.getName();if(n===void 0||n.trim()==="")throw u(o,`Migration "${a}" in "${i}" must declare \`id\` as a non-empty string literal so codegen can key the registry.`,{code:"MIGRATION_ID_NOT_STATIC",name:"LunoraError",status:500});return{exportName:a,filePath:i,id:n,table:f(o,"table")??""}},x=r=>{const i=new Map;for(const t of r){const e=i.get(t.id);if(e!==void 0)throw Object.assign(new Error(`Duplicate migration id "${t.id}": declared in both "${e}" and "${t.filePath}". Migration ids must be unique across the project.`),{code:"DUPLICATE_MIGRATION_ID",id:t.id,name:"LunoraError",paths:[e,t.filePath],status:500});i.set(t.id,t.filePath)}},E=(r,i)=>{const t=m(i),e=[];for(const o of t){const n=r.getSourceFile(o)??r.addSourceFileAtPath(o),a=p(i,o);for(const c of n.getVariableStatements())if(c.isExported())for(const l of c.getDeclarations()){const d=b(l,a);d&&e.push(d)}}return e.sort((o,n)=>o.id.localeCompare(n.id)),x(e),e};export{E as default};
@@ -0,0 +1 @@
1
+ import{Node as o,SyntaxKind as a}from"ts-morph";import{g as c,p as d,w as f}from"./discover-ast-7ABwvTVn.mjs";import{classifyProcedureCall as l}from"./discoverFunctions-4TNKUv7P.mjs";const p={"crypto.getRandomValues":"crypto.getRandomValues","crypto.randomUUID":"crypto.randomUUID","Date.now":"Date.now","Math.random":"Math.random"},u=new Set(["globalThis","self"]),g=new Set(["globalThis","self","window"]),m=e=>{if(o.isIdentifier(e))return e.getText();if(o.isPropertyAccessExpression(e)){const t=e.getExpression();if(o.isIdentifier(t)&&g.has(t.getText()))return e.getName()}},x=e=>{const t=e.getExpression();if(o.isIdentifier(t)){const i=t.getText();return i==="fetch"||i==="Date"?i:void 0}if(!o.isPropertyAccessExpression(t))return;const r=t.getName(),n=m(t.getExpression());if(n!==void 0)return r==="fetch"&&u.has(n)?"fetch":p[`${n}.${r}`]},h=e=>{const t=e.getExpression();if(!o.isIdentifier(t)||t.getText()!=="Date")return;const r=e.getArguments(),n=r.every(i=>o.isNumericLiteral(i)||o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i));return r.length>0&&n?void 0:"new Date"},N=e=>{const t=e.getInitializer();if(!t||!o.isCallExpression(t))return;const r=l(t);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const n=f(t,r.receiver);return n?{exportName:e.getName(),handler:n,kind:r.kind}:void 0},E=(e,t)=>{const r=[];for(const n of e.handler.getDescendantsOfKind(a.CallExpression)){const i=x(n);i!==void 0&&r.push({callee:i,exportName:e.exportName,file:t,kind:e.kind,line:n.getStartLineNumber()})}for(const n of e.handler.getDescendantsOfKind(a.NewExpression)){const i=h(n);i!==void 0&&r.push({callee:i,exportName:e.exportName,file:t,kind:e.kind,line:n.getStartLineNumber()})}return r},y=(e,t)=>{const r=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const s=N(i);s&&r.push(...E(s,t))}return r},k=(e,t)=>{const r=[];for(const n of c(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);r.push(...y(i,d(t,n)))}return r};export{k as default};
@@ -0,0 +1 @@
1
+ import"ts-morph";import{y as p}from"./discover-queries-i4Vd2si7.mjs";import"./discover-ast-7ABwvTVn.mjs";export{p as default};
@@ -0,0 +1 @@
1
+ import{Node as o,SyntaxKind as c}from"ts-morph";import{g as a,p,w as f}from"./discover-ast-7ABwvTVn.mjs";import{classifyProcedureCall as d}from"./discoverFunctions-4TNKUv7P.mjs";const l=t=>{const s=t.getInitializer();if(!s||!o.isCallExpression(s))return;const e=d(s);if(!e||e.kind!=="query"&&e.kind!=="mutation")return;const n=f(s,e.receiver);return n?{exportName:t.getName(),handler:n,kind:e.kind}:void 0},u=t=>{if(!o.isPropertyAccessExpression(t)||t.getName()!=="r2sql")return;const s=t.getExpression();if(!o.isIdentifier(s)||s.getText()!=="ctx")return;const e=t.getParent();return e&&o.isPropertyAccessExpression(e)&&e.getExpression()===t?`ctx.r2sql.${e.getName()}`:"ctx.r2sql"},g=(t,s)=>{const e=[];for(const n of t.handler.getDescendantsOfKind(c.PropertyAccessExpression)){const r=u(n);r!==void 0&&e.push({callee:r,exportName:t.exportName,file:s,kind:t.kind,line:n.getStartLineNumber()})}return e},m=(t,s)=>{const e=[];for(const n of t.getVariableStatements())if(n.isExported())for(const r of n.getDeclarations()){const i=l(r);i&&e.push(...g(i,s))}return e},h=(t,s)=>{const e=[];for(const n of a(s)){const r=t.getSourceFile(n)??t.addSourceFileAtPath(n);e.push(...m(r,p(s,n)))}return e};export{h as default};