@lunora/codegen 1.0.0-alpha.150 → 1.0.0-alpha.152

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 (69) hide show
  1. package/dist/index.d.mts +15 -2
  2. package/dist/index.d.ts +15 -2
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/AGENTS_FILENAME-CRdh_pOr.mjs +1 -0
  5. package/dist/packem_shared/CONTAINERS_FILENAME-BssQL6eI.mjs +1 -0
  6. package/dist/packem_shared/FLAGS_FILENAME-Bn_wWM4d.mjs +1 -0
  7. package/dist/packem_shared/{GENERATED_HEADER--PCtJMQc.mjs → GENERATED_HEADER-w7DB5GZI.mjs} +1 -1
  8. package/dist/packem_shared/NOTIFY_FILENAME-BH0djo6F.mjs +1 -0
  9. package/dist/packem_shared/{OPENRPC_VERSION-C4UXIUyy.mjs → OPENRPC_VERSION-BAgBIsQM.mjs} +1 -1
  10. package/dist/packem_shared/QUEUES_FILENAME-CIfuMMG3.mjs +1 -0
  11. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-S3Ey8df4.mjs +9 -0
  12. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-CWESEYLi.mjs +2 -0
  13. package/dist/packem_shared/{SchemaSnapshotParseError-yZc-1mxR.mjs → SchemaSnapshotParseError-yrVM8bTa.mjs} +1 -1
  14. package/dist/packem_shared/WORKFLOWS_FILENAME-CSqONfHS.mjs +1 -0
  15. package/dist/packem_shared/{buildOpenApiDocument-D5xOB07T.mjs → buildOpenApiDocument-ZdoDQXmt.mjs} +1 -1
  16. package/dist/packem_shared/chain-DboeOxBl.mjs +1 -0
  17. package/dist/packem_shared/classify-procedure-call-CRm5Etni.mjs +1 -0
  18. package/dist/packem_shared/context-property-calls-CBUh7oAY.mjs +1 -0
  19. package/dist/packem_shared/discoverAuthApiCalls-B5Qmjmyk.mjs +1 -0
  20. package/dist/packem_shared/discoverCrons-c0ig327z.mjs +1 -0
  21. package/dist/packem_shared/discoverFunctions-DeuEs6Ce.mjs +1 -0
  22. package/dist/packem_shared/discoverHttpRoutes-zWSSyyOj.mjs +1 -0
  23. package/dist/packem_shared/discoverHyperdriveCalls-C6kV2CPz.mjs +1 -0
  24. package/dist/packem_shared/discoverInserts-BB7o_8pU.mjs +1 -0
  25. package/dist/packem_shared/discoverMaskProcedures-CNqwOwXv.mjs +1 -0
  26. package/dist/packem_shared/discoverMigrations-CQjGLKW-.mjs +1 -0
  27. package/dist/packem_shared/discoverNondeterministicCalls-B07wjsd2.mjs +1 -0
  28. package/dist/packem_shared/discoverQueries-Dz2vDpE9.mjs +1 -0
  29. package/dist/packem_shared/discoverR2sqlCalls-CuHe5smg.mjs +1 -0
  30. package/dist/packem_shared/discoverRlsMetadata-CXWVNLk4.mjs +1 -0
  31. package/dist/packem_shared/discoverRlsProcedures-DXdr9YHi.mjs +1 -0
  32. package/dist/packem_shared/discoverSandboxUsage-BJHLHZR_.mjs +1 -0
  33. package/dist/packem_shared/discoverStorageRulesMetadata-CUa2Dtb4.mjs +1 -0
  34. package/dist/packem_shared/{emit-CXfWb_pY.mjs → emit-Dsr5DNpc.mjs} +291 -129
  35. package/dist/packem_shared/{emitApp-DcrQNgaz.mjs → emitApp-kFg_xYlc.mjs} +10 -2
  36. package/dist/packem_shared/{exported-procedure-chains-M40rbSYM.mjs → exported-procedure-chains-Cmt3Pr92.mjs} +1 -1
  37. package/dist/packem_shared/index-BsVoa-4F.mjs +1 -0
  38. package/dist/packem_shared/listLunoraSourceFiles-BvqYMy81.mjs +1 -0
  39. package/dist/packem_shared/queries-D8DheHbi.mjs +1 -0
  40. package/package.json +10 -10
  41. package/dist/packem_shared/AGENTS_FILENAME-B1Abt3Gl.mjs +0 -1
  42. package/dist/packem_shared/CONTAINERS_FILENAME-CtcysaKS.mjs +0 -1
  43. package/dist/packem_shared/FLAGS_FILENAME-B3VZ6vTw.mjs +0 -1
  44. package/dist/packem_shared/NOTIFY_FILENAME-CKO5gtGe.mjs +0 -1
  45. package/dist/packem_shared/QUEUES_FILENAME-C-pzLGy4.mjs +0 -1
  46. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-DazENDSB.mjs +0 -9
  47. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-B1BUjuG5.mjs +0 -2
  48. package/dist/packem_shared/WORKFLOWS_FILENAME-BfvqsG9Z.mjs +0 -1
  49. package/dist/packem_shared/ast-BYoSZlae.mjs +0 -1
  50. package/dist/packem_shared/chain-Dygm2apY.mjs +0 -1
  51. package/dist/packem_shared/classify-procedure-call-Ib2EMtFH.mjs +0 -1
  52. package/dist/packem_shared/context-property-calls-Br0sVv8E.mjs +0 -1
  53. package/dist/packem_shared/discoverAuthApiCalls-DoNQSgso.mjs +0 -1
  54. package/dist/packem_shared/discoverCrons-DCxl4hty.mjs +0 -1
  55. package/dist/packem_shared/discoverFunctions-CXURzTDU.mjs +0 -1
  56. package/dist/packem_shared/discoverHttpRoutes-2XhMbeh5.mjs +0 -1
  57. package/dist/packem_shared/discoverHyperdriveCalls-DTq4PKT5.mjs +0 -1
  58. package/dist/packem_shared/discoverInserts-qU5F4W4g.mjs +0 -1
  59. package/dist/packem_shared/discoverMaskProcedures-BZsC5dHd.mjs +0 -1
  60. package/dist/packem_shared/discoverMigrations-BFkJQ8Sy.mjs +0 -1
  61. package/dist/packem_shared/discoverNondeterministicCalls-B-NNzzPW.mjs +0 -1
  62. package/dist/packem_shared/discoverQueries-B4emAFn5.mjs +0 -1
  63. package/dist/packem_shared/discoverR2sqlCalls-C2GtrFnl.mjs +0 -1
  64. package/dist/packem_shared/discoverRlsMetadata-BKcUnSNr.mjs +0 -1
  65. package/dist/packem_shared/discoverRlsProcedures-fAhxiIyD.mjs +0 -1
  66. package/dist/packem_shared/discoverSandboxUsage-CJhnKA0_.mjs +0 -1
  67. package/dist/packem_shared/discoverStorageRulesMetadata-C7XmORWp.mjs +0 -1
  68. package/dist/packem_shared/index-xGhyK9J_.mjs +0 -1
  69. package/dist/packem_shared/queries-Ddvo5dCs.mjs +0 -1
package/dist/index.d.mts CHANGED
@@ -67,7 +67,12 @@ interface RelationSnapshot {
67
67
  }
68
68
  /** Structural snapshot of one table. */
69
69
  interface TableSnapshot {
70
- /** Field name → {@link FieldSnapshot}, in declared order. */
70
+ /**
71
+ * Field name → {@link FieldSnapshot}, keys sorted by UTF-16 code unit (see
72
+ * `sortKeys` below). Declaration order was tried and abandoned: the snapshot
73
+ * is HASHED, so moving a field up a line reported drift and consumed a
74
+ * version slot for an edit that changed nothing.
75
+ */
71
76
  fields: Record<string, FieldSnapshot>;
72
77
  /** Index name → {@link IndexSnapshot}. */
73
78
  indexes: Record<string, IndexSnapshot>;
@@ -2719,6 +2724,14 @@ declare const AGENTS_FILENAME = "agents.ts";
2719
2724
  * the `onEmail` closure body) is runtime-only, so codegen never evaluates it.
2720
2725
  */
2721
2726
  declare const discoverAgents: (project: Project, lunoraDirectory: string) => AgentIR[];
2727
+ /**
2728
+ * The exported entry point: every discoverer calls this with a directory and
2729
+ * nothing else. {@link walkLunoraSourceFiles}'s accumulator/root/visited stay
2730
+ * unexported because they are recursion state — a caller passing a pre-filled
2731
+ * accumulator or a stale `visited` silently changes which files are discovered,
2732
+ * and an exported signature freezes that hazard into the public API snapshot.
2733
+ */
2734
+ declare const listLunoraSourceFiles: (directory: string) => string[];
2722
2735
  /**
2723
2736
  * Discover `ctx.authApi.<method>(...)` (and bare `authApi.<method>(...)`) calls
2724
2737
  * under the lunora source directory and attribute each to the exported function
@@ -3822,4 +3835,4 @@ declare const secretKindOf: (value: string) => string | undefined;
3822
3835
  /** A redacted preview of a secret value — first 4 chars plus its length, never the full value. */
3823
3836
  declare const redact: (value: string) => string;
3824
3837
  declare const VERSION = "0.0.0";
3825
- export { AGENTS_FILENAME, type AgentIR, type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type ContextPropertyCallIR, type CronJobIR, DEFAULT_TARGET, type DriftChange, type DriftRemediation, type DriftScope, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type LintSchemaOptions, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcDocument, type OpenRpcEmitInput, type OpenRpcMethod, type PlatformDiagnostic, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, type RuntimeVerb, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SDK_LANGUAGES, SDK_TARGETS, SHAPES_FILENAME, type SandboxUsage, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type SdkFiles, type SdkMethod, type SdkNamespace, type SdkRenderInput, type SdkResult, type SdkTarget, type ShapeIR, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, describeErrorLevelFindings, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverHyperdriveCalls, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, errorAdvisoryNames, errorPlatformDiagnosticNames, evaluateSchemaDrift, findTsconfig, formatAdvisories, generateSdk, isTypedSchema, lintSchema, parseSchemaSnapshot, platformMatrixIds, readPackageDependencies, readProjectTarget, redact, refreshCodegenProject, resolveCodegenTarget, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, toAdvisorContext, validatorIrToJsonSchema };
3838
+ export { AGENTS_FILENAME, type AgentIR, type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type ContextPropertyCallIR, type CronJobIR, DEFAULT_TARGET, type DriftChange, type DriftRemediation, type DriftScope, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type LintSchemaOptions, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcDocument, type OpenRpcEmitInput, type OpenRpcMethod, type PlatformDiagnostic, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, type RuntimeVerb, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SDK_LANGUAGES, SDK_TARGETS, SHAPES_FILENAME, type SandboxUsage, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type SdkFiles, type SdkMethod, type SdkNamespace, type SdkRenderInput, type SdkResult, type SdkTarget, type ShapeIR, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, describeErrorLevelFindings, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverHyperdriveCalls, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, errorAdvisoryNames, errorPlatformDiagnosticNames, evaluateSchemaDrift, findTsconfig, formatAdvisories, generateSdk, isTypedSchema, lintSchema, listLunoraSourceFiles, parseSchemaSnapshot, platformMatrixIds, readPackageDependencies, readProjectTarget, redact, refreshCodegenProject, resolveCodegenTarget, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, toAdvisorContext, validatorIrToJsonSchema };
package/dist/index.d.ts CHANGED
@@ -67,7 +67,12 @@ interface RelationSnapshot {
67
67
  }
68
68
  /** Structural snapshot of one table. */
69
69
  interface TableSnapshot {
70
- /** Field name → {@link FieldSnapshot}, in declared order. */
70
+ /**
71
+ * Field name → {@link FieldSnapshot}, keys sorted by UTF-16 code unit (see
72
+ * `sortKeys` below). Declaration order was tried and abandoned: the snapshot
73
+ * is HASHED, so moving a field up a line reported drift and consumed a
74
+ * version slot for an edit that changed nothing.
75
+ */
71
76
  fields: Record<string, FieldSnapshot>;
72
77
  /** Index name → {@link IndexSnapshot}. */
73
78
  indexes: Record<string, IndexSnapshot>;
@@ -2719,6 +2724,14 @@ declare const AGENTS_FILENAME = "agents.ts";
2719
2724
  * the `onEmail` closure body) is runtime-only, so codegen never evaluates it.
2720
2725
  */
2721
2726
  declare const discoverAgents: (project: Project, lunoraDirectory: string) => AgentIR[];
2727
+ /**
2728
+ * The exported entry point: every discoverer calls this with a directory and
2729
+ * nothing else. {@link walkLunoraSourceFiles}'s accumulator/root/visited stay
2730
+ * unexported because they are recursion state — a caller passing a pre-filled
2731
+ * accumulator or a stale `visited` silently changes which files are discovered,
2732
+ * and an exported signature freezes that hazard into the public API snapshot.
2733
+ */
2734
+ declare const listLunoraSourceFiles: (directory: string) => string[];
2722
2735
  /**
2723
2736
  * Discover `ctx.authApi.<method>(...)` (and bare `authApi.<method>(...)`) calls
2724
2737
  * under the lunora source directory and attribute each to the exported function
@@ -3822,4 +3835,4 @@ declare const secretKindOf: (value: string) => string | undefined;
3822
3835
  /** A redacted preview of a secret value — first 4 chars plus its length, never the full value. */
3823
3836
  declare const redact: (value: string) => string;
3824
3837
  declare const VERSION = "0.0.0";
3825
- export { AGENTS_FILENAME, type AgentIR, type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type ContextPropertyCallIR, type CronJobIR, DEFAULT_TARGET, type DriftChange, type DriftRemediation, type DriftScope, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type LintSchemaOptions, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcDocument, type OpenRpcEmitInput, type OpenRpcMethod, type PlatformDiagnostic, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, type RuntimeVerb, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SDK_LANGUAGES, SDK_TARGETS, SHAPES_FILENAME, type SandboxUsage, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type SdkFiles, type SdkMethod, type SdkNamespace, type SdkRenderInput, type SdkResult, type SdkTarget, type ShapeIR, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, describeErrorLevelFindings, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverHyperdriveCalls, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, errorAdvisoryNames, errorPlatformDiagnosticNames, evaluateSchemaDrift, findTsconfig, formatAdvisories, generateSdk, isTypedSchema, lintSchema, parseSchemaSnapshot, platformMatrixIds, readPackageDependencies, readProjectTarget, redact, refreshCodegenProject, resolveCodegenTarget, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, toAdvisorContext, validatorIrToJsonSchema };
3838
+ export { AGENTS_FILENAME, type AgentIR, type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type ContextPropertyCallIR, type CronJobIR, DEFAULT_TARGET, type DriftChange, type DriftRemediation, type DriftScope, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type LintSchemaOptions, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcDocument, type OpenRpcEmitInput, type OpenRpcMethod, type PlatformDiagnostic, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, type RuntimeVerb, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SDK_LANGUAGES, SDK_TARGETS, SHAPES_FILENAME, type SandboxUsage, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type SdkFiles, type SdkMethod, type SdkNamespace, type SdkRenderInput, type SdkResult, type SdkTarget, type ShapeIR, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, describeErrorLevelFindings, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverHyperdriveCalls, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, errorAdvisoryNames, errorPlatformDiagnosticNames, evaluateSchemaDrift, findTsconfig, formatAdvisories, generateSdk, isTypedSchema, lintSchema, listLunoraSourceFiles, parseSchemaSnapshot, platformMatrixIds, readPackageDependencies, readProjectTarget, redact, refreshCodegenProject, resolveCodegenTarget, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, toAdvisorContext, validatorIrToJsonSchema };
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-B1BUjuG5.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as x,diagnosticAt as E}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-B1Abt3Gl.mjs";import{default as g}from"./packem_shared/discoverAuthApiCalls-DoNQSgso.mjs";import{CONTAINERS_FILENAME as R,discoverContainers as C}from"./packem_shared/CONTAINERS_FILENAME-CtcysaKS.mjs";import{default as h}from"./packem_shared/discoverCrons-DCxl4hty.mjs";import{FLAGS_FILENAME as T,discoverFlags as I}from"./packem_shared/FLAGS_FILENAME-B3VZ6vTw.mjs";import{default as F}from"./packem_shared/discoverFunctions-CXURzTDU.mjs";import{default as P}from"./packem_shared/discoverHttpRoutes-2XhMbeh5.mjs";import{default as G}from"./packem_shared/discoverHyperdriveCalls-DTq4PKT5.mjs";import{default as b}from"./packem_shared/discoverInserts-qU5F4W4g.mjs";import{d as y}from"./packem_shared/index-xGhyK9J_.mjs";import{default as j}from"./packem_shared/discoverMigrations-BFkJQ8Sy.mjs";import{MUTATORS_FILENAME as V,discoverMutators as z}from"./packem_shared/MUTATORS_FILENAME-DHX1qUP5.mjs";import{default as w}from"./packem_shared/discoverNondeterministicCalls-B-NNzzPW.mjs";import{NOTIFY_FILENAME as B,discoverNotifyCalls as J,discoverNotifyConfig as Y}from"./packem_shared/NOTIFY_FILENAME-CKO5gtGe.mjs";import{default as Z}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as ee}from"./packem_shared/queries-Ddvo5dCs.mjs";import{QUEUES_FILENAME as oe,discoverQueues as te}from"./packem_shared/QUEUES_FILENAME-C-pzLGy4.mjs";import{default as ae}from"./packem_shared/discoverR2sqlCalls-C2GtrFnl.mjs";import{default as me}from"./packem_shared/discoverRlsProcedures-fAhxiIyD.mjs";import{default as fe}from"./packem_shared/discoverRlsMetadata-BKcUnSNr.mjs";import{discoverSandboxUsage as ce}from"./packem_shared/discoverSandboxUsage-CJhnKA0_.mjs";import{default as le}from"./packem_shared/discoverSchema-D5XGH2wu.mjs";import{SHAPES_FILENAME as xe,discoverShapes as Ee}from"./packem_shared/SHAPES_FILENAME-DhZ3JkkH.mjs";import{default as ue}from"./packem_shared/discoverStorageRulesMetadata-C7XmORWp.mjs";import{WORKFLOWS_FILENAME as Ne,discoverWorkflows as ge}from"./packem_shared/WORKFLOWS_FILENAME-BfvqsG9Z.mjs";import{G as Re,e as Ce,a as Me,b as he,c as _e,d as Te,f as Ie,g as Le,h as Fe,i as De,j as Pe,k as Ue,l as Ge,m as He}from"./packem_shared/emit-CXfWb_pY.mjs";import{emitApp as ke}from"./packem_shared/emitApp-DcrQNgaz.mjs";import{buildOpenApiDocument as We,emitOpenApi as je,emitOpenApiModule as Ke}from"./packem_shared/buildOpenApiDocument-D5xOB07T.mjs";import{OPENRPC_VERSION as ze,buildOpenRpcDocument as Qe,emitOpenRpc as we,emitOpenRpcModule as qe}from"./packem_shared/OPENRPC_VERSION-C4UXIUyy.mjs";import{DEFAULT_TARGET as Je,platformMatrixIds as Ye,readProjectTarget as Xe,resolveCodegenTarget as Ze}from"./packem_shared/DEFAULT_TARGET-lPq34YeN.mjs";import{SCHEMA_SNAPSHOT_FILENAME as er,createCodegenProject as rr,findTsconfig as or,refreshCodegenProject as tr,runCodegen as sr}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-DazENDSB.mjs";import{SchemaSnapshotParseError as ir,buildSchemaSnapshot as mr,evaluateSchemaDrift as dr,parseSchemaSnapshot as fr}from"./packem_shared/SchemaSnapshotParseError-yZc-1mxR.mjs";import{schemaFromIr as cr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as lr,validatorIrToJsonSchema as Sr}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as Er,SDK_TARGETS as Ar,generateSdk as ur}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as Nr,secretKindOf as gr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as Rr,findSolutionByMessage as Cr}from"@lunora/errors";import{isTypedSchema as hr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,R as CONTAINERS_FILENAME,x as CodegenDiagnosticError,Je as DEFAULT_TARGET,T as FLAGS_FILENAME,Re as GENERATED_HEADER,lr as LUNORA_ERROR_CODES,Rr as LUNORA_SOLUTION_RULES,V as MUTATORS_FILENAME,B as NOTIFY_FILENAME,ze as OPENRPC_VERSION,oe as QUEUES_FILENAME,er as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,Er as SDK_LANGUAGES,Ar as SDK_TARGETS,xe as SHAPES_FILENAME,ir as SchemaSnapshotParseError,e as VERSION,Ne as WORKFLOWS_FILENAME,We as buildOpenApiDocument,Qe as buildOpenRpcDocument,mr as buildSchemaSnapshot,rr as createCodegenProject,c as describeErrorLevelFindings,E as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,g as discoverAuthApiCalls,C as discoverContainers,h as discoverCrons,I as discoverFlags,F as discoverFunctions,P as discoverHttpRoutes,G as discoverHyperdriveCalls,b as discoverInserts,y as discoverMaskProcedures,j as discoverMigrations,z as discoverMutators,w as discoverNondeterministicCalls,J as discoverNotifyCalls,Y as discoverNotifyConfig,ee as discoverQueries,te as discoverQueues,ae as discoverR2sqlCalls,fe as discoverRlsMetadata,me as discoverRlsProcedures,ce as discoverSandboxUsage,le as discoverSchema,Ee as discoverShapes,ue as discoverStorageRulesMetadata,ge as discoverWorkflows,Ce as emitAgents,Me as emitApi,ke as emitApp,he as emitCollections,_e as emitContainers,Te as emitCrons,Ie as emitDataModel,Le as emitDrizzleSchema,Fe as emitFunctions,je as emitOpenApi,Ke as emitOpenApiModule,we as emitOpenRpc,qe as emitOpenRpcModule,De as emitServer,Pe as emitShard,Ue as emitVectors,Ge as emitWorkflows,He as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,dr as evaluateSchemaDrift,Cr as findLunoraSolution,or as findTsconfig,m as formatAdvisories,ur as generateSdk,hr as isTypedSchema,d as lintSchema,fr as parseSchemaSnapshot,Ye as platformMatrixIds,Z as readPackageDependencies,Xe as readProjectTarget,Nr as redact,tr as refreshCodegenProject,Ze as resolveCodegenTarget,sr as runCodegen,cr as schemaFromIr,gr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,Sr as validatorIrToJsonSchema};
1
+ import{SCHEMA_SNAPSHOT_VERSION as t,diffSchemaSnapshots as s,serializeSchemaSnapshot as a}from"./packem_shared/SCHEMA_SNAPSHOT_VERSION-CWESEYLi.mjs";import{formatAdvisories as m,lintSchema as d,toAdvisorContext as f}from"./packem_shared/formatAdvisories-CkEu1eye.mjs";import{describeErrorLevelFindings as c,errorAdvisoryNames as n,errorPlatformDiagnosticNames as l}from"./packem_shared/describeErrorLevelFindings-D23VSkFP.mjs";import{CodegenDiagnosticError as x,diagnosticAt as E}from"./packem_shared/CodegenDiagnosticError-BUXlG3P-.mjs";import{AGENTS_FILENAME as u,discoverAgents as v}from"./packem_shared/AGENTS_FILENAME-CRdh_pOr.mjs";import{listLunoraSourceFiles as g}from"./packem_shared/listLunoraSourceFiles-BvqYMy81.mjs";import{default as R}from"./packem_shared/discoverAuthApiCalls-B5Qmjmyk.mjs";import{CONTAINERS_FILENAME as M,discoverContainers as h}from"./packem_shared/CONTAINERS_FILENAME-BssQL6eI.mjs";import{default as L}from"./packem_shared/discoverCrons-c0ig327z.mjs";import{FLAGS_FILENAME as I,discoverFlags as F}from"./packem_shared/FLAGS_FILENAME-Bn_wWM4d.mjs";import{default as P}from"./packem_shared/discoverFunctions-DeuEs6Ce.mjs";import{default as G}from"./packem_shared/discoverHttpRoutes-zWSSyyOj.mjs";import{default as b}from"./packem_shared/discoverHyperdriveCalls-C6kV2CPz.mjs";import{default as y}from"./packem_shared/discoverInserts-BB7o_8pU.mjs";import{d as j}from"./packem_shared/index-BsVoa-4F.mjs";import{default as V}from"./packem_shared/discoverMigrations-CQjGLKW-.mjs";import{MUTATORS_FILENAME as Q,discoverMutators as w}from"./packem_shared/MUTATORS_FILENAME-DHX1qUP5.mjs";import{default as B}from"./packem_shared/discoverNondeterministicCalls-B07wjsd2.mjs";import{NOTIFY_FILENAME as Y,discoverNotifyCalls as X,discoverNotifyConfig as Z}from"./packem_shared/NOTIFY_FILENAME-BH0djo6F.mjs";import{default as ee}from"./packem_shared/readPackageDependencies-C6h6FZuP.mjs";import{d as oe}from"./packem_shared/queries-D8DheHbi.mjs";import{QUEUES_FILENAME as se,discoverQueues as ae}from"./packem_shared/QUEUES_FILENAME-CIfuMMG3.mjs";import{default as me}from"./packem_shared/discoverR2sqlCalls-CuHe5smg.mjs";import{default as fe}from"./packem_shared/discoverRlsProcedures-DXdr9YHi.mjs";import{default as ce}from"./packem_shared/discoverRlsMetadata-CXWVNLk4.mjs";import{discoverSandboxUsage as le}from"./packem_shared/discoverSandboxUsage-BJHLHZR_.mjs";import{default as xe}from"./packem_shared/discoverSchema-D5XGH2wu.mjs";import{SHAPES_FILENAME as Ae,discoverShapes as ue}from"./packem_shared/SHAPES_FILENAME-DhZ3JkkH.mjs";import{default as Ne}from"./packem_shared/discoverStorageRulesMetadata-CUa2Dtb4.mjs";import{WORKFLOWS_FILENAME as Oe,discoverWorkflows as Re}from"./packem_shared/WORKFLOWS_FILENAME-CSqONfHS.mjs";import{G as Me,e as he,a as _e,b as Le,c as Te,d as Ie,f as Fe,g as De,h as Pe,i as Ue,j as Ge,k as He,l as be,m as ke}from"./packem_shared/emit-Dsr5DNpc.mjs";import{emitApp as We}from"./packem_shared/emitApp-kFg_xYlc.mjs";import{buildOpenApiDocument as Ke,emitOpenApi as Ve,emitOpenApiModule as ze}from"./packem_shared/buildOpenApiDocument-ZdoDQXmt.mjs";import{OPENRPC_VERSION as we,buildOpenRpcDocument as qe,emitOpenRpc as Be,emitOpenRpcModule as Je}from"./packem_shared/OPENRPC_VERSION-BAgBIsQM.mjs";import{DEFAULT_TARGET as Xe,platformMatrixIds as Ze,readProjectTarget as $e,resolveCodegenTarget as er}from"./packem_shared/DEFAULT_TARGET-lPq34YeN.mjs";import{SCHEMA_SNAPSHOT_FILENAME as or,createCodegenProject as tr,findTsconfig as sr,refreshCodegenProject as ar,runCodegen as ir}from"./packem_shared/SCHEMA_SNAPSHOT_FILENAME-S3Ey8df4.mjs";import{SchemaSnapshotParseError as dr,buildSchemaSnapshot as fr,evaluateSchemaDrift as pr,parseSchemaSnapshot as cr}from"./packem_shared/SchemaSnapshotParseError-yrVM8bTa.mjs";import{schemaFromIr as lr}from"./packem_shared/schemaFromIr-BWFnvCVg.mjs";import{LUNORA_ERROR_CODES as xr,validatorIrToJsonSchema as Er}from"./packem_shared/LUNORA_ERROR_CODES-BYg8Lpgb.mjs";import{SDK_LANGUAGES as ur,SDK_TARGETS as vr,generateSdk as Nr}from"./packem_shared/SDK_LANGUAGES-CFyux-74.mjs";import{redact as Or,secretKindOf as Rr}from"./packem_shared/redact-Cy14LEnc.mjs";import{MESSAGE_SOLUTIONS as Mr,findSolutionByMessage as hr}from"@lunora/errors";import{isTypedSchema as Lr}from"./packem_shared/isTypedSchema-B_qlBbE-.mjs";const e="0.0.0";export{u as AGENTS_FILENAME,M as CONTAINERS_FILENAME,x as CodegenDiagnosticError,Xe as DEFAULT_TARGET,I as FLAGS_FILENAME,Me as GENERATED_HEADER,xr as LUNORA_ERROR_CODES,Mr as LUNORA_SOLUTION_RULES,Q as MUTATORS_FILENAME,Y as NOTIFY_FILENAME,we as OPENRPC_VERSION,se as QUEUES_FILENAME,or as SCHEMA_SNAPSHOT_FILENAME,t as SCHEMA_SNAPSHOT_VERSION,ur as SDK_LANGUAGES,vr as SDK_TARGETS,Ae as SHAPES_FILENAME,dr as SchemaSnapshotParseError,e as VERSION,Oe as WORKFLOWS_FILENAME,Ke as buildOpenApiDocument,qe as buildOpenRpcDocument,fr as buildSchemaSnapshot,tr as createCodegenProject,c as describeErrorLevelFindings,E as diagnosticAt,s as diffSchemaSnapshots,v as discoverAgents,R as discoverAuthApiCalls,h as discoverContainers,L as discoverCrons,F as discoverFlags,P as discoverFunctions,G as discoverHttpRoutes,b as discoverHyperdriveCalls,y as discoverInserts,j as discoverMaskProcedures,V as discoverMigrations,w as discoverMutators,B as discoverNondeterministicCalls,X as discoverNotifyCalls,Z as discoverNotifyConfig,oe as discoverQueries,ae as discoverQueues,me as discoverR2sqlCalls,ce as discoverRlsMetadata,fe as discoverRlsProcedures,le as discoverSandboxUsage,xe as discoverSchema,ue as discoverShapes,Ne as discoverStorageRulesMetadata,Re as discoverWorkflows,he as emitAgents,_e as emitApi,We as emitApp,Le as emitCollections,Te as emitContainers,Ie as emitCrons,Fe as emitDataModel,De as emitDrizzleSchema,Pe as emitFunctions,Ve as emitOpenApi,ze as emitOpenApiModule,Be as emitOpenRpc,Je as emitOpenRpcModule,Ue as emitServer,Ge as emitShard,He as emitVectors,be as emitWorkflows,ke as emitWranglerCronTriggers,n as errorAdvisoryNames,l as errorPlatformDiagnosticNames,pr as evaluateSchemaDrift,hr as findLunoraSolution,sr as findTsconfig,m as formatAdvisories,Nr as generateSdk,Lr as isTypedSchema,d as lintSchema,g as listLunoraSourceFiles,cr as parseSchemaSnapshot,Ze as platformMatrixIds,ee as readPackageDependencies,$e as readProjectTarget,Or as redact,ar as refreshCodegenProject,er as resolveCodegenTarget,ir as runCodegen,lr as schemaFromIr,Rr as secretKindOf,a as serializeSchemaSnapshot,f as toAdvisorContext,Er as validatorIrToJsonSchema};
@@ -0,0 +1 @@
1
+ import{existsSync as u}from"node:fs";import{join as p}from"node:path";import{agentDefaultName as d,agentClassName as f,agentBindingName as b,voiceBindingName as N,voiceClassName as y}from"@lunora/agent/naming";import{LunoraError as l}from"@lunora/errors";import{Node as a,SyntaxKind as m}from"ts-morph";import{diagnosticAt as g}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as A,stringPropertyFor as w}from"./listLunoraSourceFiles-BvqYMy81.mjs";const h="agents.ts",E=i=>{const t=i.getSymbol();if(!t)return i.getText()==="defineAgent";for(const n of t.getDeclarations())if(a.isImportSpecifier(n))return n.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/agent"?!1:n.getNameNode().getText()==="defineAgent";return!1},P=w("agent"),I=(i,t,n)=>{if(i.getKind()===m.TrueKeyword)return!0;if(i.getKind()===m.FalseKeyword)return!1;throw g(i,`agent "${t}": \`${n}\` must be a static boolean literal — it is deploy configuration codegen writes into the ctx.agents wiring spec`)},T=(i,t)=>{const n=i.getArguments()[0];if(!n||!a.isObjectLiteralExpression(n))throw g(i,`agent "${t}": defineAgent must be passed an inline object literal`);const o={bindingName:b(t),className:f(t),exportName:t,name:d(t)},e=n.getProperty("name");e&&a.isPropertyAssignment(e)&&(o.name=P(e.getInitializerOrThrow(),t,"name"));const r=n.getProperty("publicRun");r&&a.isPropertyAssignment(r)&&I(r.getInitializerOrThrow(),t,"publicRun")&&(o.publicRun=!0);const s=n.getProperty("voice");if(s&&a.isPropertyAssignment(s)){const c=s.getInitializerOrThrow();if(!a.isObjectLiteralExpression(c))throw g(c,`agent "${t}": \`voice\` must be an inline object literal — its presence tells codegen to emit the voice-session Durable Object`);o.voice=!0,o.voiceBindingName=N(t),o.voiceClassName=y(t)}return n.getProperty("onEmail")&&(o.onEmail=!0),o},v=i=>{const t=[];for(const n of i.getVariableDeclarations()){if(!n.isExported())continue;const o=A(n.getInitializer());if(!o)continue;const e=o.getExpression();if(!a.isIdentifier(e)||!E(e))continue;const r=n.getNameNode();if(!a.isIdentifier(r))throw g(r,"defineAgent exports must be plain named exports (no destructuring)");t.push(T(o,r.getText()))}return t},D=i=>{const t=new Map,n=new Map,o=new Map;for(const e of i){const r=t.get(e.name);if(r!==void 0)throw new l("DUPLICATE_AGENT_NAME",`Duplicate agent name "${e.name}": produced by both "${r}" and "${e.exportName}". Deployed agent names must be unique across the project.`,{status:500});t.set(e.name,e.exportName);const s=n.get(e.bindingName);if(s!==void 0)throw new l("DUPLICATE_AGENT_BINDING",`Duplicate agent binding "${e.bindingName}": produced by both "${s}" and "${e.exportName}". Agent export names must yield unique binding names.`,{status:500});n.set(e.bindingName,e.exportName);const c=o.get(e.className);if(c!==void 0)throw new l("DUPLICATE_AGENT_CLASS",`Duplicate agent class "${e.className}": produced by both "${c}" and "${e.exportName}". Agent export names must yield unique generated class names.`,{status:500});o.set(e.className,e.exportName)}},j=(i,t)=>{const n=p(t,h);if(!u(n))return[];const o=i.getSourceFile(n)??i.addSourceFileAtPath(n),e=v(o);return e.sort((r,s)=>r.exportName.localeCompare(s.exportName)),D(e),e};export{h as AGENTS_FILENAME,j as discoverAgents};
@@ -0,0 +1 @@
1
+ import{existsSync as f}from"node:fs";import{join as d}from"node:path";import{containerClassName as b,containerBindingName as p,normalizeContainerImage as u}from"@lunora/container";import{SyntaxKind as y,Node as n}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{stringPropertyFor as L}from"./listLunoraSourceFiles-BvqYMy81.mjs";const P="containers.ts",h=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineContainer";for(const i of t.getDeclarations())if(n.isImportSpecifier(i))return i.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/container"?!1:i.getNameNode().getText()==="defineContainer";return!1},g=L("container"),m=(e,t,i)=>{if(n.isNumericLiteral(e))return e.getLiteralValue();throw c(e,`container "${t}": \`${i}\` must be a static number literal — it is deploy configuration codegen writes into wrangler.jsonc`)},T=(e,t)=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e))return u(e.getLiteralValue());if(n.isObjectLiteralExpression(e)){const i=e.getProperty("registry");if(i&&n.isPropertyAssignment(i)){const o=i.getInitializerOrThrow();return u({registry:g(o,t,"image.registry")})}const r=e.getProperty("build");if(r&&n.isPropertyAssignment(r)){const o=r.getInitializerOrThrow();return u({build:g(o,t,"image.build")})}}throw c(e,`container "${t}": \`image\` must be a static string path, { registry: "…" }, or { build: "…" } literal`)},k=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getInitializerOrThrow();(n.isStringLiteral(r)||n.isNoSubstitutionTemplateLiteral(r))&&(t[i.getName()]=r.getLiteralValue())}return Object.keys(t).length>0?t:void 0},I=e=>{if(!n.isObjectLiteralExpression(e))return;const t={};for(const i of e.getProperties()){if(!n.isPropertyAssignment(i))continue;const r=i.getName(),o=i.getInitializerOrThrow();n.isNumericLiteral(o)&&(r==="gracePeriodSeconds"||r==="stepPercentage")&&(t[r]=o.getLiteralValue())}return t.gracePeriodSeconds===void 0&&t.stepPercentage===void 0?void 0:t},w=e=>{if(n.isTrueLiteral(e))return!0;if(n.isFalseLiteral(e))return!1},S=e=>{if(n.isStringLiteral(e)||n.isNoSubstitutionTemplateLiteral(e)||n.isNumericLiteral(e))return e.getLiteralValue()},A=(e,t)=>{if(n.isStringLiteral(e))return e.getLiteralValue();if(n.isObjectLiteralExpression(e)){const i={};for(const r of e.getProperties()){if(!n.isPropertyAssignment(r))throw c(r,`container "${t}": \`instanceType\` must be an object of static number literals`);const o=r.getName();if(o!=="diskMb"&&o!=="memoryMib"&&o!=="vcpu")throw c(r,`container "${t}": unknown \`instanceType\` field "${o}" — expected vcpu, memoryMib, or diskMb`);i[o]=m(r.getInitializerOrThrow(),t,`instanceType.${o}`)}return i}throw c(e,`container "${t}": \`instanceType\` must be a static string or { vcpu, memoryMib, diskMb } literal`)},v=(e,t)=>{const i=e.getArguments()[0];if(!i||!n.isObjectLiteralExpression(i))throw c(e,`container "${t}": defineContainer must be passed an inline object literal`);const r={bindingName:p(t),className:b(t),exportName:t,image:{buildContext:".",dockerfilePath:"./Dockerfile",kind:"dockerfile"}};let o=!1;for(const a of i.getProperties()){if(!n.isPropertyAssignment(a))continue;const l=a.getName(),s=a.getInitializerOrThrow();switch(l){case"buildArgs":{r.buildArgs=k(s);break}case"enableInternet":{r.enableInternet=w(s);break}case"image":{r.image=T(s,t),o=!0;break}case"instanceType":{r.instanceType=A(s,t);break}case"maxInstances":{r.maxInstances=m(s,t,"maxInstances");break}case"name":{r.name=g(s,t,"name");break}case"rollout":{r.rollout=I(s);break}case"sleepAfter":{r.sleepAfter=S(s);break}}}if(!o)throw c(i,`container "${t}": defineContainer requires a static \`image\` property`);return r},C=e=>{const t=[];for(const i of e.getVariableDeclarations()){if(!i.isExported())continue;const r=i.getInitializer();if(r?.getKind()!==y.CallExpression)continue;const o=r,a=o.getExpression();if(!n.isIdentifier(a)||!h(a))continue;const l=i.getNameNode();if(!n.isIdentifier(l))throw c(l,"defineContainer exports must be plain named exports (no destructuring)");t.push(v(o,l.getText()))}return t},F=(e,t)=>{const i=d(t,P);if(!f(i))return[];const r=e.getSourceFile(i)??e.addSourceFileAtPath(i),o=C(r);return o.sort((a,l)=>a.exportName.localeCompare(l.exportName)),o};export{P as CONTAINERS_FILENAME,F as discoverContainers};
@@ -0,0 +1 @@
1
+ import{existsSync as l}from"node:fs";import{join as p}from"node:path";import{Node as i}from"ts-morph";import{defaultExportExpression as g,propertyInitializer as f}from"./listLunoraSourceFiles-BvqYMy81.mjs";const c="flags.ts",d=new Set(["@lunora/flags/providers/flagship","lunorash/flags/flagship"]),u=e=>{const t=e.getSymbol();if(!t)return e.getText()==="flagshipProvider";for(const r of t.getDeclarations())if(i.isImportSpecifier(r))return d.has(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="flagshipProvider":!1;return!1},m=(e,t)=>{const r=e.getProperty(t);if(!r||!i.isPropertyAssignment(r))return;const o=r.getInitializerOrThrow();if(i.isStringLiteral(o)||i.isNoSubstitutionTemplateLiteral(o))return o.getLiteralValue()},v=e=>{const t=e.getArguments()[0];if(t&&i.isObjectLiteralExpression(t)){const r=m(t,"binding");if(r!==void 0&&r.length>0)return{bindingName:r,mode:"binding",provider:"flagship"}}return{mode:"http",provider:"flagship"}},h=e=>f(e.getArguments()[0],"provider"),P=(e,t)=>{const r=p(t,c);if(!l(r))return;const o=e.getSourceFile(r)??e.addSourceFileAtPath(r),n=g(o);if(!n||!i.isCallExpression(n))return{provider:"custom"};const s=h(n);if(s&&i.isCallExpression(s)){const a=s.getExpression();if(i.isIdentifier(a)&&u(a))return v(s)}return{provider:"custom"}};export{c as FLAGS_FILENAME,P as discoverFlags};
@@ -1 +1 @@
1
- import"./SCHEMA_SNAPSHOT_VERSION-B1BUjuG5.mjs";import{G as t,U as m,n as r,e as o,a as n,b as l,c as A,d as E,f as S,g,h as C,o as c,p as d,i as p,j as u,k as D,l as f,m as h}from"./emit-CXfWb_pY.mjs";import"./paths-C-9fwEgQ.mjs";export{t as GENERATED_HEADER,m as UMBRELLA_BASE_PACKAGES,r as buildStorageColumns,o as emitAgents,n as emitApi,l as emitCollections,A as emitContainers,E as emitCrons,S as emitDataModel,g as emitDrizzleSchema,C as emitFunctions,c as emitQueues,d as emitSeed,p as emitServer,u as emitShard,D as emitVectors,f as emitWorkflows,h as emitWranglerCronTriggers};
1
+ import"./SCHEMA_SNAPSHOT_VERSION-CWESEYLi.mjs";import{G as t,U as m,n as r,e as o,a as n,b as l,c as A,d as E,f as S,g,h as C,o as c,p as d,i as p,j as u,k as D,l as f,m as h}from"./emit-Dsr5DNpc.mjs";import"./paths-C-9fwEgQ.mjs";export{t as GENERATED_HEADER,m as UMBRELLA_BASE_PACKAGES,r as buildStorageColumns,o as emitAgents,n as emitApi,l as emitCollections,A as emitContainers,E as emitCrons,S as emitDataModel,g as emitDrizzleSchema,C as emitFunctions,c as emitQueues,d as emitSeed,p as emitServer,u as emitShard,D as emitVectors,f as emitWorkflows,h as emitWranglerCronTriggers};
@@ -0,0 +1 @@
1
+ import{existsSync as m}from"node:fs";import{join as x}from"node:path";import{SyntaxKind as d,Node as c}from"ts-morph";import{listLunoraSourceFiles as l,lunoraRelativePath as g,defaultExportExpression as P,handlerOf as E}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{c as S}from"./classify-procedure-call-CRm5Etni.mjs";const y="notify.ts",v=new Set(["chat","inApp","send","webhook"]),p=new Set(["broadcast","send"]),N=e=>{const t=e.getInitializer();if(!t||!c.isCallExpression(t))return;const o=S(t);if(!o)return;const r=E(t,o.receiver);return r?{exportName:e.getName(),handler:r,kind:o.kind}:void 0},h=e=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const r of o.getDeclarations()){const s=N(r);s&&t.push(s)}return t},a=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=e.getExpression();if((t==="notify"||t==="push")&&c.isIdentifier(o)&&o.getText()==="ctx")return t;if(t==="push"&&a(o)==="notify")return"push"},F=e=>{if(!c.isPropertyAccessExpression(e))return;const t=e.getName(),o=a(e.getExpression());if(o==="notify"&&v.has(t))return`ctx.notify.${t}`;if(o==="push"&&p.has(t))return`ctx.push.${t}`},A=e=>c.isPropertyAccessExpression(e)?a(e.getExpression())==="push"&&p.has(e.getName()):!1,T=(e,t)=>{const o=[];for(const r of l(t)){const s=e.getSourceFile(r)??e.addSourceFileAtPath(r),f=g(t,r);for(const n of h(s))if(!(n.kind!=="query"&&n.kind!=="mutation"))for(const i of n.handler.getDescendantsOfKind(d.PropertyAccessExpression)){const u=F(i);u!==void 0&&o.push({callee:u,exportName:n.exportName,file:f,kind:n.kind,line:i.getStartLineNumber()})}}return o},O=(e,t)=>{for(const o of l(t)){const r=e.getSourceFile(o)??e.addSourceFileAtPath(o);for(const s of h(r))for(const f of s.handler.getDescendantsOfKind(d.PropertyAccessExpression))if(A(f))return!0}return!1},_=(e,t)=>{const o=x(t,y);if(!m(o))return;const r=e.getSourceFile(o)??e.addSourceFileAtPath(o),s=P(r);let f=!1,n=!1;if(s&&c.isCallExpression(s)){const i=s.getArguments()[0];i&&c.isObjectLiteralExpression(i)&&(f=i.getProperty("webPush")!==void 0,n=i.getProperty("fcm")!==void 0)}return{hasFcm:n,hasWebPush:f,usesPush:O(e,t)}};export{y as NOTIFY_FILENAME,T as discoverNotifyCalls,_ as discoverNotifyConfig};
@@ -1,3 +1,3 @@
1
- import{G as c}from"./emit-CXfWb_pY.mjs";import{s as u}from"./paths-C-9fwEgQ.mjs";import{validatorIrToJsonSchema as m,objectSchema as p,LUNORA_ERROR_CODES as i}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const l="1.3.2",d={description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."},R=e=>{const n=u(e.filePath),o=`${n}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${o}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${o}", "args": { … } }\`).`,errors:i.map((r,s)=>({code:-32e3-s,data:{code:r},message:r})),name:o,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:p(e.args)}],result:{name:"result",schema:e.output?m(e.output):d},summary:`${e.kind}: ${o}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:n}]}},g=e=>{const n=e.version??"0.0.0",r=e.functions.filter(t=>t.visibility!=="internal"&&t.kind!=="stream").map(t=>R(t)).toSorted((t,a)=>t.name.localeCompare(a.name));return{info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora RPC",version:n},methods:r,openrpc:l}},S=e=>`${JSON.stringify(g(e),void 0,2)}
1
+ import{G as c}from"./emit-Dsr5DNpc.mjs";import{s as u}from"./paths-C-9fwEgQ.mjs";import{validatorIrToJsonSchema as m,objectSchema as p,LUNORA_ERROR_CODES as i}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const l="1.3.2",d={description:"Result is TS-inferred from the function's return type (no `.output()` declared); best-effort — any JSON."},R=e=>{const n=u(e.filePath),o=`${n}:${e.exportName}`;return{description:`Invoke the \`${e.kind}\` \`${o}\` over the Lunora RPC envelope (POST /_lunora/rpc, body \`{ "functionPath": "${o}", "args": { … } }\`).`,errors:i.map((r,s)=>({code:-32e3-s,data:{code:r},message:r})),name:o,params:[{description:"The function's argument object (the RPC envelope's `args`).",name:"args",required:Object.keys(e.args).length>0,schema:p(e.args)}],result:{name:"result",schema:e.output?m(e.output):d},summary:`${e.kind}: ${o}`,"x-lunora-function-kind":e.kind,"x-tags":[{name:n}]}},g=e=>{const n=e.version??"0.0.0",r=e.functions.filter(t=>t.visibility!=="internal"&&t.kind!=="stream").map(t=>R(t)).toSorted((t,a)=>t.name.localeCompare(a.name));return{info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora RPC",version:n},methods:r,openrpc:l}},S=e=>`${JSON.stringify(g(e),void 0,2)}
2
2
  `,v=e=>`${c}export const openRpcSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
3
3
  `;export{l as OPENRPC_VERSION,g as buildOpenRpcDocument,S as emitOpenRpc,v as emitOpenRpcModule};
@@ -0,0 +1 @@
1
+ import{existsSync as g}from"node:fs";import{join as l}from"node:path";import{LunoraError as d}from"@lunora/errors";import{queueDefaultName as p,queueBindingName as f}from"@lunora/queue";import{SyntaxKind as y,Node as s}from"ts-morph";import{diagnosticAt as a}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{stringPropertyFor as h}from"./listLunoraSourceFiles-BvqYMy81.mjs";const q="queues.ts",b=r=>{const t=r.getSymbol();if(!t)return r.getText()==="defineQueue";for(const e of t.getDeclarations())if(s.isImportSpecifier(e))return e.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/queue"?!1:e.getNameNode().getText()==="defineQueue";return!1},c=h("queue"),N=(r,t,e)=>{if(s.isNumericLiteral(r))return r.getLiteralValue();throw a(r,`queue "${t}": \`${e}\` must be a static numeric literal — it is deploy configuration codegen writes into wrangler.jsonc`)},w=(r,t)=>{const e=r.getProperty("name");if(!e||!s.isPropertyAssignment(e))return;const n=c(e.getInitializerOrThrow(),t,"name");if(n.length===0)throw a(e,`queue "${t}": \`name\` must be a non-empty string when provided`);return n},P=(r,t)=>{const e=r.getArguments()[0];if(!e||!s.isObjectLiteralExpression(e))throw a(r,`queue "${t}": defineQueue must be passed an inline object literal`);const n={bindingName:f(t),exportName:t,mode:"push",name:w(e,t)??p(t),tuning:{}},o=e.getProperty("mode");if(o&&s.isPropertyAssignment(o)){const i=c(o.getInitializerOrThrow(),t,"mode");if(i!=="push"&&i!=="pull")throw a(o,`queue "${t}": \`mode\` must be "push" or "pull" (got ${JSON.stringify(i)})`);n.mode=i}const u=e.getProperty("deadLetterQueue");u&&s.isPropertyAssignment(u)&&(n.tuning.deadLetterQueue=c(u.getInitializerOrThrow(),t,"deadLetterQueue"));for(const i of["maxBatchSize","maxBatchTimeout","maxRetries","retryDelay"]){const m=e.getProperty(i);m&&s.isPropertyAssignment(m)&&(n.tuning[i]=N(m.getInitializerOrThrow(),t,i))}return n},E=r=>{const t=[];for(const e of r.getVariableDeclarations()){if(!e.isExported())continue;const n=e.getInitializer();if(n?.getKind()!==y.CallExpression)continue;const o=n,u=o.getExpression();if(!s.isIdentifier(u)||!b(u))continue;const i=e.getNameNode();if(!s.isIdentifier(i))throw a(i,"defineQueue exports must be plain named exports (no destructuring)");t.push(P(o,i.getText()))}return t},I=r=>{const t=new Map,e=new Map;for(const n of r){const o=t.get(n.name);if(o!==void 0)throw new d("DUPLICATE_QUEUE_NAME",`Duplicate queue name "${n.name}": produced by both "${o}" and "${n.exportName}". Deployed queue names must be unique across the project.`,{status:500});t.set(n.name,n.exportName);const u=e.get(n.bindingName);if(u!==void 0)throw new d("DUPLICATE_QUEUE_BINDING",`Duplicate queue binding "${n.bindingName}": produced by both "${u}" and "${n.exportName}". Queue export names must yield unique binding names.`,{status:500});e.set(n.bindingName,n.exportName)}},T=(r,t)=>{const e=l(t,q);if(!g(e))return[];const n=r.getSourceFile(e)??r.addSourceFileAtPath(e),o=E(n);return o.sort((u,i)=>u.exportName.localeCompare(i.exportName)),I(o),o};export{q as QUEUES_FILENAME,T as discoverQueues};
@@ -0,0 +1,9 @@
1
+ import{existsSync as P,mkdirSync as os,readFileSync as yt,writeFileSync as as,rmSync as cs}from"node:fs";import{join as f,dirname as X}from"node:path";import{performance as ge}from"node:perf_hooks";import{runAdvisor as ls}from"@lunora/advisor";import{LunoraError as k}from"@lunora/errors";import{SyntaxKind as l,Node as o,Project as Ze}from"ts-morph";import{serializeSchemaSnapshot as us}from"./SCHEMA_SNAPSHOT_VERSION-CWESEYLi.mjs";import{toAdvisorContext as ds}from"./formatAdvisories-CkEu1eye.mjs";import{s as fs}from"./paths-C-9fwEgQ.mjs";import{discoverAgents as gs}from"./AGENTS_FILENAME-CRdh_pOr.mjs";import{discoverContainers as ps}from"./CONTAINERS_FILENAME-BssQL6eI.mjs";import ms from"./discoverCrons-c0ig327z.mjs";import{diagnosticAt as re}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{b as ie}from"./module-specifiers-WF8iAydP.mjs";import{C as pe,i as hs,f as xs,n as Es,j as vs,b as Ss,c as As,l as ys,e as Ns,o as bs,d as Ps,k as Is,g as ws,p as Ts,m as Cs,a as Fs,h as Os}from"./emit-Dsr5DNpc.mjs";import{listLunoraSourceFiles as p,lunoraRelativePath as v,collectCallRows as w,collectSecurityCallRows as Ls,propertyInitializer as y,listSecurityScanFiles as Nt,limitNameOf as bt,isContextIdentifier as Ee,handlerOf as Rs,isDatabaseAccessor as M,unwrapExpression as Je,readTargetOf as Pt,enclosingExportName as Ds}from"./listLunoraSourceFiles-BvqYMy81.mjs";import ks from"./readPackageDependencies-C6h6FZuP.mjs";import{discoverQueues as Ms}from"./QUEUES_FILENAME-CIfuMMG3.mjs";import{discoverSandboxUsage as Ks}from"./discoverSandboxUsage-BJHLHZR_.mjs";import _s from"./discoverStorageRulesMetadata-CUa2Dtb4.mjs";import{discoverWorkflows as zs}from"./WORKFLOWS_FILENAME-CSqONfHS.mjs";import{gatePlatformFeatures as Us,resolveCodegenTarget as Bs}from"./DEFAULT_TARGET-lPq34YeN.mjs";import{i as R,a as _,e as E,r as qs,b as $s,s as oe,c as js,f as Vs,d as Ws}from"./queries-D8DheHbi.mjs";import{a as A,c as z,d as It,e as Hs}from"./classify-procedure-call-CRm5Etni.mjs";import Gs from"./discoverAuthApiCalls-B5Qmjmyk.mjs";import et from"./discoverFunctions-DeuEs6Ce.mjs";import{i as Ys,r as Qs,e as Xs}from"./unwrap-handler-return-CmIWbykC.mjs";import tt from"./discoverHttpRoutes-zWSSyyOj.mjs";import Zs from"./discoverHyperdriveCalls-C6kV2CPz.mjs";import Js from"./discoverInserts-BB7o_8pU.mjs";import{m as Ne,a as J,s as wt,d as en}from"./index-BsVoa-4F.mjs";import{e as Tt}from"./exported-procedure-chains-Cmt3Pr92.mjs";import tn from"./discoverMigrations-CQjGLKW-.mjs";import{MUTATORS_FILENAME as sn,isDefineMutatorCallee as nn,discoverMutators as st}from"./MUTATORS_FILENAME-DHX1qUP5.mjs";import rn from"./discoverNondeterministicCalls-B07wjsd2.mjs";import{discoverNotifyConfig as on,discoverNotifyCalls as an}from"./NOTIFY_FILENAME-BH0djo6F.mjs";import cn from"./discoverR2sqlCalls-CuHe5smg.mjs";import ln from"./discoverRlsProcedures-DXdr9YHi.mjs";import un from"./discoverRlsMetadata-CXWVNLk4.mjs";import dn from"./discoverSchema-D5XGH2wu.mjs";import{secretKindOf as fn,redact as gn,isHeuristicSecretKind as pn,isSecretishName as mn}from"./redact-Cy14LEnc.mjs";import{discoverShapes as hn}from"./SHAPES_FILENAME-DhZ3JkkH.mjs";import{emitApp as xn}from"./emitApp-kFg_xYlc.mjs";import{buildOpenApiDocument as En,emitOpenApiModule as vn}from"./buildOpenApiDocument-ZdoDQXmt.mjs";import{buildOpenRpcDocument as Sn,emitOpenRpcModule as An}from"./OPENRPC_VERSION-BAgBIsQM.mjs";import{s as yn}from"./parse-validator-CMV0eq2a.mjs";import{buildSchemaSnapshot as Nn}from"./SchemaSnapshotParseError-yrVM8bTa.mjs";const bn=e=>{const t=new Map;for(const s of e){const n=fs(s),i=t.get(n);if(i===void 0){t.set(n,s);continue}if(i!==s)throw new k("INTERNAL",`@lunora/codegen: "${i}" and "${s}" both map to the api namespace "${n}" — the generated api.ts would declare "${n}" twice and the dispatch key "${n}:<fn>" would be ambiguous. Rename one file so the two differ by more than a non-identifier character (\`-\`, \`.\`, \`/\` and \`_\` all sanitize to \`_\`).`,{status:500})}},Pn=e=>{const t=[],s=e.tables.filter(n=>n.shardMode==="global");return s.some(n=>n.globalBackend!=="hyperdrive")&&t.push({name:"@lunora/d1",reason:"`.global()` tables are D1-backed, so `_generated/app.ts` imports the D1 `ctx.db` adapter"}),s.some(n=>n.globalBackend==="hyperdrive")&&t.push({name:"@lunora/hyperdrive",reason:'`.global({ backend: "hyperdrive" })` tables route through `@lunora/hyperdrive/global`'}),e.vectorIndexes.length>0&&t.push({name:"@lunora/bindings",reason:"`.vectorize()` indexes make `_generated/vectors.ts` import `@lunora/bindings/vectors`"}),t},In=(e,t)=>{if(t===void 0)return;const s=Pn(e).filter(i=>!t.has(i.name));if(s.length===0)return;const n=s.map(i=>` - ${i.name} — ${i.reason}`).join(`
2
+ `);throw new k("INTERNAL",`@lunora/codegen: this schema's generated code imports packages the project does not declare:
3
+ ${n}
4
+
5
+ Install them with your package manager, then re-run codegen.`)},wn="env.ts",Tn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineEnv";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return ie(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineEnv":!1;return!1},Cn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&ie(n.getModuleSpecifierValue())}return!1},Fn=e=>{if(o.isIdentifier(e))return Tn(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineEnv"&&o.isIdentifier(t)&&Cn(t)}return!1},On=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Fn(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw re(r,"defineEnv exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},Ln=(e,t)=>{const s=f(t,wn);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=On(n);if(i.length!==0){if(i.length>1)throw re(n,`lunora/env.ts declares ${i.length.toString()} defineEnv() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Ct=e=>{const t=n=>o.isIdentifier(n)&&n.getText()==="ctx",s=new Set;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression))t(n.getExpression())&&s.add(n.getName());for(const n of e.getDescendantsOfKind(l.VariableDeclaration)){const i=n.getInitializer(),r=n.getNameNode();if(!(i===void 0||!t(i)||!o.isObjectBindingPattern(r)))for(const a of r.getElements()){const c=a.getPropertyNameNode()?.getText()??a.getName();c&&s.add(c)}}return s},Rn=(e,t)=>{const s=Object.fromEntries(pe.map(n=>[n.key,!1]));for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=new Set(i.getImportDeclarations().map(c=>c.getModuleSpecifierValue())),a=Ct(i);for(const c of pe)if(!s[c.key]){if(r.has(c.moduleSpecifier)){s[c.key]=!0;continue}c.contextProperty!==void 0&&a.has(c.contextProperty)&&(s[c.key]=!0)}if(pe.every(c=>s[c.key]))break}return s},Ft="identity.ts",Dn=e=>{const t=e.getSymbol();if(!t)return e.getText()==="defineIdentity";for(const s of t.getDeclarations())if(o.isImportSpecifier(s))return ie(s.getImportDeclaration().getModuleSpecifierValue())?s.getNameNode().getText()==="defineIdentity":!1;return!1},kn=e=>{const t=e.getSymbol();if(!t)return!1;for(const s of t.getDeclarations()){if(!o.isNamespaceImport(s))continue;const n=s.getFirstAncestorByKind(l.ImportDeclaration);return n!==void 0&&ie(n.getModuleSpecifierValue())}return!1},Mn=e=>{if(o.isIdentifier(e))return Dn(e);if(o.isPropertyAccessExpression(e)){const t=e.getExpression();return e.getName()==="defineIdentity"&&o.isIdentifier(t)&&kn(t)}return!1},Kn=e=>{const t=[];for(const s of e.getVariableDeclarations()){if(!s.isExported())continue;const n=s.getInitializer();if(n?.getKind()!==l.CallExpression||!Mn(n.getExpression()))continue;const r=s.getNameNode();if(!o.isIdentifier(r))throw re(r,"defineIdentity exports must be plain named exports (no destructuring)");t.push({exportName:r.getText()})}return t},_n=(e,t)=>{const s=f(t,Ft);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s),i=Kn(n);if(i.length!==0){if(i.length>1)throw re(n,`lunora/identity.ts declares ${i.length.toString()} defineIdentity() contracts (${i.map(r=>r.exportName).join(", ")}); exactly one is allowed`);return i[0]}},Ot=e=>o.isParenthesizedExpression(e)?Ot(e.getExpression()):e,zn=e=>o.isObjectLiteralExpression(e)&&e.getProperties().some(t=>{if(o.isShorthandPropertyAssignment(t))return t.getName()==="durable";if(!o.isPropertyAssignment(t)||t.getName()!=="durable")return!1;const s=t.getInitializer();return s===void 0||Ot(s).getText()!=="false"}),Un=(e,t)=>{const s={durableStreams:!1,secrets:!1};for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);if(s.secrets||(s.secrets=Ct(i).has("secrets")),s.durableStreams||(s.durableStreams=i.getDescendantsOfKind(l.CallExpression).some(r=>{const a=r.getExpression();return(o.isPropertyAccessExpression(a)?a.getName():a.getText())==="stream"&&r.getArguments().some(u=>zn(u))})),s.durableStreams&&s.secrets)break}return s},Bn=(e,t)=>{const s=new Map,n=new Map,i=new Map;for(const r of e)s.set(r.name,`workflow "${r.exportName}"`),n.set(r.bindingName,`workflow "${r.exportName}"`),i.set(r.className,`workflow "${r.exportName}"`);for(const r of t){const a=s.get(r.name);if(a!==void 0)throw new k("DUPLICATE_WORKFLOW_NAME",`Duplicate deployed name "${r.name}": produced by both ${a} and agent "${r.exportName}". Workflow and agent names share the same wrangler workflows[] array and must be unique together.`,{status:500});const c=n.get(r.bindingName);if(c!==void 0)throw new k("DUPLICATE_WORKFLOW_BINDING",`Duplicate binding "${r.bindingName}": produced by both ${c} and agent "${r.exportName}". Workflow and agent bindings share the same wrangler workflows[] array and must be unique together.`,{status:500});const u=i.get(r.className);if(u!==void 0)throw new k("DUPLICATE_WORKFLOW_CLASS",`Duplicate generated class "${r.className}": produced by both ${u} and agent "${r.exportName}". Workflow and agent export names must yield unique generated class names.`,{status:500})}},qn=e=>{const{lunoraDirectory:t,project:s,projectRoot:n,schema:i}=e,r=_n(s,t),a=Ln(s,t),c=zs(s,t),u=Ms(s,t),d=gs(s,t);Bn(c,d);const S=ps(s,t),x=_s(s,t),I=ms(s,t,c,d),g=Un(s,t),T=Ks(s,t),F=Rn(s,t);F.browser=F.browser||T.usesSandboxBrowser;const D=Us(F,Bs(n,e.target),{agents:d.length>0,commitOrderedTables:i.tables.some(b=>b.commitOrdered===!0),cronTriggers:I.length>0,crossShardFanout:i.tables.some(b=>typeof b.shardMode=="object"),durableStreams:g.durableStreams,globalTables:i.tables.some(b=>b.shardMode==="global"),queues:u.length>0,secrets:g.secrets,vectorStore:i.vectorIndexes.length>0}),N=D.usage,O=ks(n),U=O??new Set,B=U.has("lunorash");In(i,O);const W=P(f(t,"flags.ts")),K=P(f(t,"notify.ts"));return{agents:d,containers:S,crons:I,dataModelContent:xs(i),declaredDependencies:O,dependencies:U,env:a,featureUsage:N,hasFlags:W,hasNotify:K,identity:r,platformGate:D,queues:u,serverContent:hs({agents:d,containers:S,env:a,hasAccessFacade:N.access,hasAi:N.ai,hasAnalytics:N.analytics,hasBrowser:N.browser,hasVectors:D.signals.vectorStore!==!1,hasFlags:W,hasHyperdrive:N.hyperdrive,hasImages:N.images,hasKv:N.kv,hasNotify:K,hasPayments:N.payments,hasPipelines:N.pipelines,hasR2sql:N.r2sql,hasX402:N.x402,identity:r,queues:u,schema:i,storageRuleBuckets:x.rules.map(b=>b.bucket),useUmbrella:B,workflows:c}),storageRulesMetadata:x,usesSandbox:T.usesSandboxBrowser||T.usesSandboxContainer||T.usesSandboxFs,useUmbrella:B,workflows:c}},Lt=new Set(["delete","get","head","options","patch","post","put"]),$n=new Set(["handler","stream"]),jn=/\/(?:_|admin|internal|superuser|sudo|root|debug)/iu,nt=new Set(["ADMIN_TOKEN","adminToken","assertAdmin","assertAuth","auth","Authorization","getSession","identity","isAdmin","requireAdmin","requireAuth","requireRole","verifyAdmin"]),Vn=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Lt.has(t.getName()))return;const s=t.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpRoute")return;const n=e.getArguments()[0];if(!(!n||!o.isStringLiteral(n)))return{method:t.getName().toUpperCase(),path:n.getLiteralValue()}},Wn=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||Lt.has(n.getName()))break;s=n.getExpression()}return Vn(s)},Hn=e=>{for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression))if(nt.has(t.getName()))return!0;for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&nt.has(s.getText()))return!0}return!1},Gn=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=s.getExpression();if(!o.isPropertyAccessExpression(n)||!$n.has(n.getName()))return;const i=Wn(s);if(!i||!jn.test(i.path))return;const r=s.getArguments()[0],a=r!==void 0&&(o.isArrowFunction(r)||o.isFunctionExpression(r))&&Hn(r);return{exportName:e.getName(),file:t,method:i.method,path:i.path,usesGuard:a}},Yn=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=Gn(i,t);r&&s.push(r)}return s},Qn=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Yn(i,v(t,n)))}return s},Xn=e=>!o.isPropertyAccessExpression(e)||e.getName()!=="run"?!1:e.getExpression().getText()==="ctx.ai",Zn=(e,t)=>{if(!Xn(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!R(s)||_(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},Jn=(e,t)=>w(e,t,Zn),er=new Set(["generateText","streamText"]),tr=new Set(["messages","prompt","system"]),sr=[{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"]}],nr=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=t.getName(),n=t.getExpression().getText();for(const i of sr)if(i.methods.has(s)&&i.prefixes.some(r=>n===r||n.startsWith(`${r}.`)))return`${n}.${s}`},rr=e=>{for(const t of e.getDescendantsOfKind(l.CallExpression)){const s=nr(t);if(s!==void 0)return s}},ir=e=>{const t=new Set,s=e.getFirstAncestor(r=>o.isArrowFunction(r)||o.isFunctionExpression(r)||o.isFunctionDeclaration(r)),[n]=s?.getParameters()??[],i=n?.getNameNode();if(i===void 0||!o.isObjectBindingPattern(i))return t;for(const r of i.getElements()){const a=r.getPropertyNameNode()?.getText()??r.getName(),c=r.getNameNode();if(a==="args"&&o.isObjectBindingPattern(c))for(const u of c.getElements())t.add(u.getName())}return t},or=e=>{if(qs(e))return!0;const t=ir(e);return t.size===0?!1:e.getDescendantsOfKind(l.Identifier).some(s=>t.has(s.getText()))},ar=e=>{for(const t of e.getProperties()){if(!o.isPropertyAssignment(t)||!tr.has(t.getName()))continue;const s=t.getInitializer();if(s!==void 0&&or(s))return!0}return!1},cr=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=A(n.getExpression());if(i===void 0||!er.has(i))continue;const[r]=n.getArguments();if(r===void 0||!o.isObjectLiteralExpression(r))continue;let a;for(const c of r.getDescendantsOfKind(l.CallExpression))if(A(c.getExpression())==="tool"&&(a=rr(c),a!==void 0))break;a!==void 0&&s.push({exportName:E(n),file:t,line:n.getStartLineNumber(),method:i,sideEffect:a,userInputDerived:ar(r)})}return s},lr=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...cr(i,v(t,n)))}return s},ur=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="fetch")return!1;const t=e.getExpression();return o.isIdentifier(t)&&t.getText()==="ctx"},dr=(e,t)=>{if(!ur(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!R(s)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},fr=(e,t)=>w(e,t,dr),Rt=e=>e.getProperties().some(t=>o.isSpreadAssignment(t)),gr=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return{objects:[],opaque:!0};const s=t.getProperty("args");if(!s)return{objects:[],opaque:!1};if(!o.isPropertyAssignment(s))return{objects:[],opaque:!0};const n=s.getInitializer();return!n||!o.isObjectLiteralExpression(n)?{objects:[],opaque:!0}:{objects:[n],opaque:Rt(n)}},pr=e=>{const t=[];let s=!1,n=e;for(;o.isCallExpression(n);){const i=n.getExpression();if(!o.isPropertyAccessExpression(i))break;if(i.getName()==="input"){const r=n.getArguments()[0];r&&o.isObjectLiteralExpression(r)?(t.push(r),s||=Rt(r)):s=!0}n=i.getExpression()}return{objects:t,opaque:s}},Dt=(e,t)=>t?pr(t):gr(e),mr=e=>e.flatMap(t=>t.getProperties().filter(s=>o.isPropertyAssignment(s)||o.isShorthandPropertyAssignment(s)).map(s=>s.getName())),hr=new Set(["check","length","max"]),ve=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(!(!o.isPropertyAccessExpression(t)||t.getExpression().getText()!=="v"))return t.getName()},xr=e=>[e,...e.getDescendants()].filter(t=>ve(t)!==void 0),Er=e=>{let t=e;for(;;){const s=t.getParent();if(!s||!o.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;const n=s.getParent();if(!n||!o.isCallExpression(n)||n.getExpression()!==s)return!1;if(hr.has(s.getName()))return!0;t=n}},vr=e=>{const t=[],s=[];for(const n of e)for(const i of n.getProperties()){if(!o.isPropertyAssignment(i))continue;const r=i.getInitializer();if(!r)continue;const a=xr(r),c=i.getName();a.some(u=>ve(u)==="any")?t.push(c):a.some(u=>ve(u)==="string"&&!Er(u))&&s.push(c)}return{anyArgs:t,unboundedStringArgs:s}},Sr=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=z(s);if(n?.visibility!=="public")return;const{objects:i}=Dt(s,n.receiver),{anyArgs:r,unboundedStringArgs:a}=vr(i);if(!(r.length===0&&a.length===0))return{anyArgs:r,exportName:e.getName(),file:t,line:s.getStartLineNumber(),unboundedStringArgs:a}},Ar=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=Sr(i,t);r&&s.push(r)}return s},yr=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ar(i,v(t,n)))}return s},me=e=>e?.getKind()===l.TrueKeyword,Nr=e=>e?.getKind()===l.FalseKeyword,br=e=>e!==void 0&&o.isNumericLiteral(e)&&e.getLiteralValue()===0,Pr=new Set(["lunoraAuthAdapter","lunoraD1Adapter"]),Ir=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isCallExpression(t)&&A(t.getExpression())==="scim"),wr=e=>e!==void 0&&o.isCallExpression(e)&&Pr.has(A(e.getExpression())??""),Tr=e=>!e||!o.isArrayLiteralExpression(e)?!1:e.getElements().some(t=>o.isStringLiteral(t)&&t.getLiteralText()==="*"),Cr=e=>{const t=y(e,"advanced"),s=y(e,"emailAndPassword"),n=y(e,"session");return{analyzable:!0,disableCsrfCheck:me(y(t,"disableCSRFCheck")),emailPasswordEnabled:me(y(s,"enabled")),requireEmailVerification:me(y(s,"requireEmailVerification")),scimOnNonTransactionalAdapter:Ir(y(e,"plugins"))&&wr(y(e,"database")),secureCookiesDisabled:Nr(y(t,"useSecureCookies")),sessionFreshAgeZero:br(y(n,"freshAge")),trustedOriginsWildcard:Tr(y(e,"trustedOrigins"))}},Fr=()=>({analyzable:!1,disableCsrfCheck:!1,emailPasswordEnabled:!1,requireEmailVerification:!1,scimOnNonTransactionalAdapter:!1,secureCookiesDisabled:!1,sessionFreshAgeZero:!1,trustedOriginsWildcard:!1}),Or=(e,t)=>{if(A(e.getExpression())!=="createAuth")return;const s=e.getArguments()[0],n=s!==void 0&&o.isObjectLiteralExpression(s)&&s.getProperties().some(r=>o.isSpreadAssignment(r)),i=s!==void 0&&o.isObjectLiteralExpression(s)&&!n?Cr(s):Fr();return{exportName:E(e),file:t,line:e.getStartLineNumber(),...i}},Lr=(e,t)=>Ls(e,t,Or),Rr=(e,t)=>{if(!o.isPropertyAccessExpression(e))return;const s=e.getName();if(t.methods.has(s))return t.matchReceiver(e.getExpression().getText())?s:void 0},Dr=(e,t,s)=>{const n=Rr(e.getExpression(),s);if(n===void 0)return;const i=e.getArguments()[s.argIndex];if(!(!i||!R(i)||_(i))&&!(s.requireUnmodifiedReach===!0&&!$s(i)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:n}},kr=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression)){const r=Dr(i,t,s);r&&n.push(r)}return n},ae=(e,t,s)=>{const n=[];for(const i of p(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...kr(r,v(t,i),s))}return n},Mr=new Set(["content","pdf","scrape","screenshot"]),Kr=(e,t)=>ae(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.browser",methods:Mr}),_r=new Set(["createBrowser","createInboundEmailHandler","createPayment"]),zr=new Set(["RateLimiter"]),Ur=new Set(["extend"]),rt="lunora",Br=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],kt=e=>{const t=[],s=[];let n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),i.getInitializer()?.getKind()===l.TrueKeyword&&s.push(r);continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,presentKeys:t,trueKeys:s}},Se=e=>e&&o.isObjectLiteralExpression(e)?kt(e):{analyzable:!1,presentKeys:[],trueKeys:[]},qr=e=>{const t=e.getStatements(),[s]=t;if(t.length!==1||s===void 0||!o.isReturnStatement(s))return;const n=s.getExpression();return n!==void 0&&o.isObjectLiteralExpression(n)?n:void 0},$r=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)?qr(e):void 0},jr=e=>{const t=e&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,s=t&&$r(t.getBody());return s?kt(s):{analyzable:!1,presentKeys:[],trueKeys:[]}},Vr=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=A(n.getExpression());i!==void 0&&(_r.has(i)?s.push({callee:i,file:t,line:n.getStartLineNumber(),...Se(n.getArguments()[0])}):Ur.has(i)&&s.push({callee:i,file:t,line:n.getStartLineNumber(),...jr(n.getArguments()[0])}))}for(const n of e.getDescendantsOfKind(l.NewExpression)){const i=A(n.getExpression());i===void 0||!zr.has(i)||s.push({callee:i,file:t,line:n.getStartLineNumber(),...Se(n.getArguments()[0])})}return s},Wr=(e,t)=>{for(const s of Br){const n=f(t,s);if(!P(n))continue;const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=[];for(const a of i.getDescendantsOfKind(l.CallExpression))A(a.getExpression())===rt&&r.push({callee:rt,file:s,line:a.getStartLineNumber(),...Se(a.getArguments()[0])});return r}return[]},Hr=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Nt(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);s.push(...Vr(r,n))}return s.push(...Wr(e,X(t))),s},it="ctx.containers.",Gr=e=>{if(!e.startsWith(it))return!1;const t=e.slice(it.length);return t.length>0&&!t.includes(".")},Yr=(e,t)=>ae(e,t,{argIndex:0,matchReceiver:Gr,methods:new Set(["get"])}),Qr=new Set(["allow","deny","setAllowed"]),Xr=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())},Zr=(e,t)=>{const s=e.getExpression();if(!(!o.isPropertyAccessExpression(s)||s.getName()!=="start"||!Xr(e)))return{detail:"enableInternet: true",exportName:E(e),file:t,kind:"enable_internet",line:e.getStartLineNumber()}},Jr=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||!Qr.has(s.getName()))return;const n=s.getExpression();if(!(!o.isPropertyAccessExpression(n)||n.getName()!=="egress"))return{detail:s.getName(),exportName:E(e),file:t,kind:"egress_relaxation",line:e.getStartLineNumber()}},ei=(e,t)=>Zr(e,t)??Jr(e,t),ti=(e,t)=>w(e,t,ei),si=new Set(["defineExportSink","r2Sink","webhookExportSink"]),ni=e=>{const t=e.getExpression();if(!o.isIdentifier(t))return;const s=t.getText();return si.has(s)?s:void 0},ri=e=>{const t=[],s=[];for(const n of e.getProperties()){if(o.isSpreadAssignment(n))return{analyzable:!1,emptyKeys:[],presentKeys:[]};if(o.isPropertyAssignment(n)){const i=n.getName();t.push(i);const r=n.getInitializer();r&&o.isStringLiteral(r)&&r.getLiteralText()===""&&s.push(i);continue}(o.isShorthandPropertyAssignment(n)||o.isMethodDeclaration(n)||o.isGetAccessorDeclaration(n))&&t.push(n.getName())}return{analyzable:!0,emptyKeys:s,presentKeys:t}},ii=(e,t)=>{const s=[];for(const{displayPath:n,filePath:i}of Nt(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);for(const a of r.getDescendantsOfKind(l.CallExpression)){const c=ni(a);if(c===void 0)continue;const u=a.getArguments()[0],d=u&&o.isObjectLiteralExpression(u)?ri(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},oi=new Map([["dbRateLimit",2],["rateLimit",2],["verifyTurnstileMiddleware",0]]),ai=new Set(["dbRateLimit","rateLimit"]),ci=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},li=(e,t)=>{const s=A(e.getExpression());if(s===void 0)return;const n=oi.get(s);if(n!==void 0)return{callee:s,exportName:E(e),failOpen:ci(e.getArguments()[n]),file:t,limitName:ai.has(s)?bt(e):"",line:e.getStartLineNumber()}},ui=(e,t)=>w(e,t,li),di=new Set(["boolean","number","object","string"]),fi=e=>{const t=e.getName();if(!di.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="flags"&&Ee(s.getExpression()))return t;const n=s.getExpression();if(s.getName()==="details"&&o.isPropertyAccessExpression(n)&&n.getName()==="flags"&&Ee(n.getExpression()))return t},gi=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t))return;const s=fi(t);if(s===void 0)return;const n=e.getArguments()[0];if(!n||!(o.isStringLiteral(n)||o.isNoSubstitutionTemplateLiteral(n)))return;const i=n.getLiteralValue();return i.length>0?{key:i,type:s}:void 0},pi=(e,t)=>{const s=new Map;for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getDescendantsOfKind(l.CallExpression)){const a=gi(r);a&&!s.has(a.key)&&s.set(a.key,a.type)}}return[...s.entries()].map(([n,i])=>({key:n,type:i})).toSorted((n,i)=>n.key.localeCompare(i.key))},mi=e=>{const t=e.getInitializer();if(!t||!o.isCallExpression(t))return;const s=z(t);if(s?.kind!=="query")return;const n=Rs(t,s.receiver);return n?{exportName:e.getName(),handler:n}:void 0},ot=e=>{const t=e.getParent();return t&&o.isPropertyAccessExpression(t)&&t.getExpression()===e?t:void 0},hi=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="flags")return;const t=e.getExpression();if(!o.isIdentifier(t)||t.getText()!=="ctx")return;const s=ot(e);if(!s)return"ctx.flags";if(s.getName()==="details"){const n=ot(s);return n?`ctx.flags.details.${n.getName()}`:"ctx.flags.details"}return`ctx.flags.${s.getName()}`},xi=(e,t)=>{const s=[];for(const n of e.handler.getDescendantsOfKind(l.PropertyAccessExpression)){const i=hi(n);i!==void 0&&s.push({callee:i,exportName:e.exportName,file:t,line:n.getStartLineNumber()})}return s},Ei=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=mi(i);r&&s.push(...xi(r,t))}return s},vi=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ei(i,v(t,n)))}return s},Si=e=>{if(!o.isPropertyAccessExpression(e)||e.getName()!=="boolean")return!1;const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="flags"&&Ee(t.getExpression())},Ai=e=>{if(e?.getKind()===l.TrueKeyword)return!0;if(e?.getKind()===l.FalseKeyword)return!1},yi=(e,t)=>{if(!Si(e.getExpression()))return;const[s,n]=e.getArguments();if(!s||!(o.isStringLiteral(s)||o.isNoSubstitutionTemplateLiteral(s)))return;const i=s.getLiteralValue(),r=Ai(n);if(!(i.length===0||r===void 0))return{defaultValue:r,exportName:E(e),file:t,key:i,line:e.getStartLineNumber()}},Ni=(e,t)=>w(e,t,yi),bi=e=>{const t=e.getType().getProperty("~standard");if(!t)return;const s=t.getTypeAtLocation(e).getProperty("types");if(!s)return;const n=s.getTypeAtLocation(e).getNonNullableType().getProperty("output");if(!n)return;const i=n.getTypeAtLocation(e),r=i.getText(e);if(!r||r==="any"||r==="never"||Ys(r))return;const a=e.getSourceFile().getFilePath();return Qs(i,e,a)?Xs(i,e,a,0,new Set):r},Pi=e=>{const t=e.getExpression();return o.isPropertyAccessExpression(t)&&t.getName()==="withGeoIndex"},Ii=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},wi=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression))Pi(a)&&s.push({file:r,indexName:Ii(a),line:a.getStartLineNumber()})}return s},V=e=>e!==void 0&&(o.isArrowFunction(e)||o.isFunctionExpression(e))?e:void 0,Mt=e=>{const t=e.getArguments()[0],s=V(t);if(s!==void 0)return s;if(t===void 0||!o.isObjectLiteralExpression(t))return;const n=t.getProperty("handler");return n!==void 0&&o.isPropertyAssignment(n)?V(n.getInitializer()):void 0},Ti=new Set(["delete","get","head","options","patch","post","put"]),Ci=new Set(["handler","stream"]),Fi=new Set(["runAction","runMutation"]),Oi=new Set(["delete","insert","insertManyUnsafe","patch","replace"]),ee=(e,t)=>e!==void 0&&o.isIdentifier(e)&&e.getText()===t,at=(e,t)=>{const s=e.getParameters()[0];if(s===void 0)return;const n=s.getNameNode();if(t)return o.isIdentifier(n)?n.getText():void 0;if(o.isObjectBindingPattern(n)){for(const i of n.getElements())if((i.getPropertyNameNode()?.getText()??i.getNameNode().getText())==="ctx"){const a=i.getNameNode();return o.isIdentifier(a)?a.getText():void 0}}},ct=(e,t)=>{const s=e.getBody(),n=s.getDescendantsOfKind(l.CallExpression);o.isCallExpression(s)&&n.unshift(s);for(const i of n){const r=i.getExpression();if(!o.isPropertyAccessExpression(r))continue;const a=r.getName(),c=r.getExpression();if(Fi.has(a)&&ee(c,t))return a;if(Oi.has(a)&&o.isPropertyAccessExpression(c)&&c.getName()==="db"&&ee(c.getExpression(),t))return`db.${a}`}},lt=(e,t)=>{const s=e.getBody();for(const n of s.getDescendantsOfKind(l.PropertyAccessExpression))if(n.getName()==="auth"&&ee(n.getExpression(),t))return!0;for(const n of s.getDescendantsOfKind(l.VariableDeclaration)){const i=n.getNameNode();if(!(!o.isObjectBindingPattern(i)||!ee(n.getInitializer(),t))){for(const r of i.getElements())if((r.getPropertyNameNode()?.getText()??r.getNameNode().getText())==="auth")return!0}}return!1},Li=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Ci.has(t.getName()))return;let s=t.getExpression();for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))return;const i=n.getName();if(Ti.has(i)){const r=n.getExpression();return o.isIdentifier(r)&&r.getText()==="httpRoute"?i.toUpperCase():void 0}s=n.getExpression()}},Ri=(e,t)=>{const s=e.getExpression();if(o.isIdentifier(s)&&s.getText()==="httpAction"){const c=V(e.getArguments()[0]),u=c&&at(c,!0);if(!c||u===void 0)return;const d=ct(c,u);return d===void 0?void 0:{exportName:E(e),file:t,kind:"httpAction",line:e.getStartLineNumber(),readsAuth:lt(c,u),sideEffect:d}}const n=Li(e);if(n===void 0)return;const i=V(e.getArguments()[0]),r=i&&at(i,!1);if(!i||r===void 0)return;const a=ct(i,r);return a===void 0?void 0:{exportName:E(e),file:t,kind:"httpRoute",line:e.getStartLineNumber(),method:n,readsAuth:lt(i,r),sideEffect:a}},Di=(e,t)=>w(e,t,Ri),ki=new Set(["btoa","encodeURI","encodeURIComponent","isSafeHeaderValue","Number","parseFloat","parseInt"]),Mi=new Set(["append","set"]),Kt=e=>e!==void 0&&(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))?e.getLiteralText():"",ut=(e,t)=>(o.isCallExpression(e)?[e,...e.getDescendantsOfKind(l.CallExpression)]:e.getDescendantsOfKind(l.CallExpression)).some(n=>ki.has(A(n.getExpression())??"")&&Vs(n,t)),Ki=(e,t)=>{if(ut(e,t))return!0;const s=oe(e);return s!==void 0&&ut(s,t)},Ae=(e,t)=>js(e,t)&&!Ki(e,t),_i=e=>{if(o.isPropertyAccessExpression(e)&&e.getName()==="headers")return!0;const t=oe(e);return t!==void 0&&o.isNewExpression(t)&&A(t.getExpression())==="Headers"},te=e=>{if(e===void 0)return;if(o.isObjectLiteralExpression(e))return e;const t=oe(e);return t!==void 0&&o.isObjectLiteralExpression(t)?t:void 0},be=(e,t,s)=>{for(const n of e.getProperties())if(o.isPropertyAssignment(n)){const i=n.getInitializer();i!==void 0&&Ae(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:Kt(n.getNameNode()),line:i.getStartLineNumber(),via:t})}else if(o.isShorthandPropertyAssignment(n)){const i=n.getNameNode();Ae(i,s.requestName)&&s.rows.push({exportName:s.exportName,file:s.relativePath,headerName:n.getName(),line:i.getStartLineNumber(),via:t})}else if(o.isSpreadAssignment(n)){const i=te(n.getExpression());i!==void 0&&be(i,t,s)}},_t=(e,t)=>{const s=te(e);if(s===void 0)return;const n=s.getProperty("headers");if(n===void 0||!o.isPropertyAssignment(n))return;const i=te(n.getInitializer());i!==void 0&&be(i,"response-init",t)},zi=(e,t)=>{const s=A(e.getExpression());if(s==="Response")_t(e.getArguments()[1],t);else if(s==="Headers"){const n=te(e.getArguments()[0]);n!==void 0&&be(n,"headers-ctor",t)}},Ui=(e,t)=>{const s=e.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName(),i=s.getExpression();if(n==="json"&&o.isIdentifier(i)&&i.getText()==="Response"){_t(e.getArguments()[1],t);return}if(Mi.has(n)&&_i(i)){const r=e.getArguments()[1];r!==void 0&&Ae(r,t.requestName)&&t.rows.push({exportName:t.exportName,file:t.relativePath,headerName:Kt(e.getArguments()[0]),line:r.getStartLineNumber(),via:n==="set"?"headers-set":"headers-append"})}},Bi=(e,t)=>{for(const s of e.getDescendantsOfKind(l.NewExpression))zi(s,t);for(const s of e.getDescendantsOfKind(l.CallExpression))Ui(s,t)},qi=(e,t)=>{const s=e.getExpression();if(!o.isIdentifier(s)||s.getText()!=="httpAction")return[];const n=V(e.getArguments()[0]);if(n===void 0)return[];const i=n.getParameters()[1];if(i===void 0)return[];const r=i.getNameNode();if(!o.isIdentifier(r))return[];const a=[];return Bi(n,{exportName:E(e),relativePath:t,requestName:r.getText(),rows:a}),a},$i=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression))s.push(...qi(n,t));return s},ji=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...$i(i,v(t,n)))}return s},Vi=new Set(["auth","context.auth","ctx.auth"]),Wi="userId",Hi=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},Gi=(e,t)=>{const s=f(t,Ft);if(!P(s))return;const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const i of n.getDescendantsOfKind(l.CallExpression)){if(A(i.getExpression())!=="defineIdentity")continue;const[r]=i.getArguments();return r&&o.isObjectLiteralExpression(r)?Hi(r):void 0}},dt=e=>{if(!(e===void 0||!o.isPropertyAccessExpression(e)||e.getName()!=="identity"))return Vi.has(e.getExpression().getText())?e:void 0},Yi=e=>{if(o.isPropertyAccessExpression(e)&&dt(e.getExpression())!==void 0)return e.getName();if(o.isElementAccessExpression(e)&&dt(e.getExpression())!==void 0){const t=e.getArgumentExpression();return t&&o.isStringLiteral(t)?t.getLiteralValue():void 0}},Qi=(e,t,s)=>{const n=[];for(const i of e.getDescendants()){const r=Yi(i);r!==void 0&&n.push({declared:r===Wi||s.has(r),exportName:E(i),file:t,key:r,line:i.getStartLineNumber()})}return n},Xi=(e,t)=>{const s=Gi(e,t);if(s===void 0)return[];const n=[];for(const i of p(t)){const r=e.getSourceFile(i)??e.addSourceFileAtPath(i);n.push(...Qi(r,v(t,i),s))}return n},Zi=(e,t)=>{if(A(e.getExpression())!=="buildImageDeliveryUrl")return;const s=e.getArguments()[0];if(!s)return;const n=y(s,"key");if(!(!n||!R(n)||_(n)))return{exportName:E(e),file:t,line:e.getStartLineNumber()}},Ji=(e,t)=>w(e,t,Zi),eo=new Set(["delete","get","getRaw","getWithMetadata","put"]),to=(e,t)=>ae(e,t,{argIndex:0,matchReceiver:s=>s==="ctx.kv"||s.startsWith("ctx.kv."),methods:eo}),so=new Set(["queue","send"]),ft=new Set(["bcc","cc","to"]),no=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!so.has(t))return;const s=e.getExpression().getText();return s==="ctx.mail"||s==="ctx.email"?t:void 0},ro=e=>o.isObjectLiteralExpression(e)?e.getProperties().some(t=>{if(o.isShorthandPropertyAssignment(t)){const n=t.getNameNode();return ft.has(t.getName())&&R(n)&&!_(n)}if(!o.isPropertyAssignment(t)||!ft.has(t.getName()))return!1;const s=t.getInitializer();return s!==void 0&&R(s)&&!_(s)}):!1,io=(e,t)=>{const s=no(e.getExpression());if(s===void 0)return;const n=e.getArguments()[0];if(!(!n||!ro(n)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s}},oo=(e,t)=>w(e,t,io),ao=e=>o.isPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?o.isComputedPropertyName(e.getNameNode()):!1,co=e=>o.isPropertyAssignment(e)||o.isShorthandPropertyAssignment(e)||o.isMethodDeclaration(e)||o.isGetAccessorDeclaration(e)?ao(e):!0,zt=(e,t=!1)=>{for(const s of e.getProperties()){if(co(s))return!0;if(t)continue;if(!o.isPropertyAssignment(s))return!0;const n=s.getInitializer();if(!n||!o.isObjectLiteralExpression(n)||zt(n,!0))return!0}return!1},lo=(e,t)=>{for(const s of p(t)){const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);for(const{receiver:i}of Tt(n))for(const r of Ne(i)){const a=r.getArguments()[0];if(a!==void 0&&(!o.isObjectLiteralExpression(a)||zt(a)))return!0}}return!1},uo=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return[];const s=[];for(const n of t.getProperties()){const i=J(n);if(i===void 0||!o.isPropertyAssignment(n))continue;const r=n.getInitializer();if(!(!r||!o.isObjectLiteralExpression(r)))for(const a of r.getProperties()){const c=J(a);c!==void 0&&s.push({column:c,strategy:wt(a),table:i})}}return s},fo=(e,t)=>{const s=new Map;for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const{receiver:r}of Tt(i))for(const a of Ne(r))for(const c of uo(a)){const u=`${c.table}\0${c.column}`;s.has(u)||s.set(u,c)}}return{columns:[...s.values()]}},go=(e,t,s)=>{const n=e.getArguments()[0];if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){const a=J(r);if(a===void 0||!o.isPropertyAssignment(r))continue;const c=r.getInitializer();if(!(!c||!o.isObjectLiteralExpression(c)))for(const u of c.getProperties()){const d=J(u);if(d===void 0)continue;const S=wt(u);S!=="custom"&&i.push({column:d,exportName:t,file:s,line:u.getStartLineNumber(),strategy:S,table:a})}}return i},po=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?z(s):void 0;return n?.receiver?Ne(n.receiver).flatMap(i=>go(i,e.getName(),t)):[]},mo=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...po(c,r))}return s},ho=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="replace")return!1;const s=t.getExpression();return M(s)},xo=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},Eo=e=>{if(!e.isExported())return;const t=e.getInitializer();if(t?.getKind()!==l.CallExpression)return;const s=t;return nn(s.getExpression())?s:void 0},vo=e=>{const t=Eo(e),s=t===void 0?void 0:xo(t);if(s===void 0)return[];const n=e.getNameNode(),i=o.isIdentifier(n)?n.getText():"";return s.getDescendantsOfKind(l.CallExpression).filter(r=>ho(r)).map(r=>({exportName:i,file:"lunora/mutators.ts",line:r.getStartLineNumber()}))},So=e=>e.getVariableDeclarations().flatMap(t=>vo(t)),Ao=(e,t)=>{const s=f(t,sn);if(!P(s))return[];const n=e.getSourceFile(s)??e.addSourceFileAtPath(s);return So(n)},yo=new Set(["delete","get","patch"]),No=new Set(["accountId","authorId","companyId","createdBy","createdById","customerId","groupId","memberId","organizationId","orgId","ownerId","projectId","teamId","tenantId","userId","workspaceId"]),bo=new Set(["auth","identity","session","user"]),Po=new Set([l.EqualsEqualsEqualsToken,l.EqualsEqualsToken,l.ExclamationEqualsEqualsToken,l.ExclamationEqualsToken]),Io=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="normalizeId"||!M(t.getExpression()))return;const s=e.getArguments()[0];return s&&o.isStringLiteral(s)?s.getLiteralText():""},wo=e=>{let t=e,s=t.getParent();for(;s!==void 0&&(o.isAsExpression(s)||o.isParenthesizedExpression(s)||o.isNonNullExpression(s));)t=s,s=t.getParent();if(s===void 0||!o.isVariableDeclaration(s))return;const n=s.getNameNode();return o.isIdentifier(n)?n.getText():void 0},To=(e,t)=>e.getDescendantsOfKind(l.Identifier).some(s=>s.getText()===t),Co=e=>o.isThrowStatement(e)||o.isReturnStatement(e)||e.getDescendantsOfKind(l.ThrowStatement).length>0||e.getDescendantsOfKind(l.ReturnStatement).length>0,Fo=(e,t)=>e.getDescendantsOfKind(l.IfStatement).some(s=>To(s.getExpression(),t)&&Co(s.getThenStatement())),Oo=(e,t)=>{for(const s of e.getDescendantsOfKind(l.CallExpression)){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))continue;const i=n.getName();if(!yo.has(i))continue;const r=n.getExpression();if(!(M(r)||o.isPropertyAccessExpression(r)&&M(r.getExpression())))continue;const c=s.getArguments()[0];if(c!==void 0&&o.isIdentifier(c)&&c.getText()===t)return i}},Lo=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},Ro=e=>e.getDescendantsOfKind(l.CallExpression).some(t=>t.getArguments().some(s=>Lo(s)==="ctx")),Do=e=>e.getDescendantsOfKind(l.BinaryExpression).some(t=>Po.has(t.getOperatorToken().getKind())?o.isPropertyAccessExpression(t.getLeft())||o.isPropertyAccessExpression(t.getRight()):!1),ko=e=>{for(const t of e.getDescendantsOfKind(l.Identifier))if(No.has(t.getText()))return!0;for(const t of e.getDescendantsOfKind(l.PropertyAccessExpression)){const s=t.getExpression();if(o.isIdentifier(s)&&s.getText()==="ctx"&&bo.has(t.getName()))return!0}return Ro(e)||Do(e)},Mo=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=z(s);if(n?.kind!=="query"&&n?.kind!=="mutation")return[];const i=Mt(s);if(i===void 0)return[];const r=n.receiver!==void 0&&It(n.receiver,"use","rls"),a=ko(i),c=new Set,u=[];for(const d of i.getDescendantsOfKind(l.CallExpression)){const S=Io(d);if(S===void 0)continue;const x=wo(d);if(x===void 0||c.has(x)||!Fo(i,x))continue;const I=Oo(i,x);I!==void 0&&(c.add(x),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),mentionsOwnership:a,sinkMethod:I,table:S,usesRls:r,visibility:n.visibility}))}return u},Ko=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...Mo(c,r))}return s},_o=new Set(["accountId","authorId","createdBy","createdById","organizationId","orgId","ownerId","tenantId","updatedBy","userId","workspaceId"]),zo=new Set(["insert","insertManyUnsafe","patch","replace"]),Uo=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(!zo.has(t))return;const s=e.getExpression();if(!o.isPropertyAccessExpression(s)||s.getName()!=="db")return;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"?t:void 0},Bo=(e,t)=>{if(t!=="insertManyUnsafe")return o.isObjectLiteralExpression(e)?[e]:[];if(!o.isArrayLiteralExpression(e))return[];const s=[];for(const n of e.getElements())o.isObjectLiteralExpression(n)&&s.push(n);return s},qo=(e,t,s,n)=>{const i=[];for(const r of e.getProperties()){let a,c;o.isPropertyAssignment(r)?(a=r.getName(),c=r.getInitializer()):o.isShorthandPropertyAssignment(r)&&(a=r.getName(),c=r.getNameNode()),!(a===void 0||c===void 0||!_o.has(a))&&R(c)&&!_(c)&&i.push({exportName:E(s),field:a,file:n,line:s.getStartLineNumber(),method:t})}return i},$o=(e,t)=>{const s=Uo(e.getExpression());if(s===void 0)return[];const n=e.getArguments()[1];return n?Bo(n,s).flatMap(i=>qo(i,s,e,t)):[]},jo=(e,t,s)=>{const n=[];for(const i of e.getDescendantsOfKind(l.CallExpression))for(const r of $o(i,t)){const a=s(r.exportName);n.push(a===void 0?r:{...r,visibility:a})}return n},Vo=(e,t,s=[])=>{const n=[],i=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));for(const r of p(t)){const a=e.getSourceFile(r)??e.addSourceFileAtPath(r),c=v(t,r);n.push(...jo(a,c,u=>i.get(`${c}:${u}`)))}return n},Wo=["providerSubscriptionId","state"],Ho=["providerEventId","processedAt"],gt=(e,t)=>t.every(s=>s in e.shape),Go=e=>{const t=e.find(n=>n.name==="subscriptions"),s=e.find(n=>n.name==="events");return t!==void 0&&s!==void 0&&gt(t,Wo)&&gt(s,Ho)},Yo=new Set(["createAutumnAdapter","createDodoPaymentsAdapter","createPolarAdapter","createStripeAdapter"]),Qo=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,Xo=e=>{const t=e.getProperty("webhookToleranceSeconds");return t&&o.isPropertyAssignment(t)?Qo(t.getInitializer()):void 0},Zo=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!Yo.has(s))return;const[n]=e.getArguments(),i=n&&o.isObjectLiteralExpression(n)?Xo(n):void 0;return{callee:s,exportName:E(e),file:t,line:e.getStartLineNumber(),...i===void 0?{}:{toleranceSeconds:i}}},Jo=(e,t)=>w(e,t,Zo),ea=new Set(["defineQueue","defineWorkflow"]),ta=new Set(["run","runAction","runMutation","runQuery"]),sa=new Set(["api","internal"]),na=e=>{const t=e.getExpression();return o.isIdentifier(t)?t.getText():void 0},ra=e=>{const t=e.getArguments()[0];if(!t||!o.isObjectLiteralExpression(t))return;const s=t.getProperty("handler");if(s===void 0||!o.isPropertyAssignment(s))return;const n=s.getInitializer();if(n&&(o.isArrowFunction(n)||o.isFunctionExpression(n)))return n},Ut=(e,t)=>{const s=e.getParameters()[t]?.getNameNode();return s&&o.isIdentifier(s)?s.getText():void 0},Bt=(e,t)=>e===t||e.startsWith(`${t}.`),qt=e=>{const t=e.getDescendantsOfKind(l.PropertyAccessExpression);return o.isPropertyAccessExpression(e)&&t.push(e),t},pt=e=>{const t=e.getParent();return o.isPropertyAccessExpression(t)&&t.getNameNode()===e||o.isPropertyAssignment(t)&&t.getNameNode()===e?!1:!(o.isBindingElement(t)&&t.getNameNode()===e)},$t=e=>{const t=e.getDescendantsOfKind(l.Identifier).filter(s=>pt(s));return o.isIdentifier(e)&&pt(e)&&t.push(e),t},ia=e=>{if(!o.isVariableDeclaration(e))return[];const t=e.getNameNode();return o.isIdentifier(t)?[t.getText()]:t.getDescendantsOfKind(l.BindingElement).map(s=>s.getName())},oa=e=>{const t=Ut(e,1);if(t===void 0)return[];const s=[`${t}.messages`];for(const n of e.getDescendantsOfKind(l.ForOfStatement)){if(n.getExpression().getText()!==`${t}.messages`)continue;const i=n.getInitializer(),r=o.isVariableDeclarationList(i)?i.getDeclarations()[0]?.getNameNode():void 0;r&&o.isIdentifier(r)&&s.push(`${r.getText()}.body`)}return s},aa=(e,t,s)=>{const n=t==="workflow"?[`${s}.params`]:oa(e),i=new Set,r=a=>qt(a).some(c=>n.some(u=>Bt(c.getText(),u)))?!0:$t(a).some(c=>i.has(c.getText()));for(const a of e.getDescendantsOfKind(l.VariableDeclaration)){const c=a.getInitializer();if(c&&r(c))for(const u of ia(a))i.add(u)}return{names:i,prefixes:n}},ca=(e,t)=>qt(e).some(s=>t.prefixes.some(n=>Bt(s.getText(),n)))?!0:$t(e).some(s=>t.names.has(s.getText())),la=e=>{if(e===void 0||!o.isPropertyAccessExpression(e))return;const t=[];let s=e;for(;o.isPropertyAccessExpression(s);)t.unshift(s.getName()),s=s.getExpression();const n=t.at(-1);if(!(n===void 0||!o.isIdentifier(s)||!sa.has(s.getText())||t.length<2))return{exportName:n,file:t.slice(0,-1).join("/")}},ua=(e,t,s)=>{const n=Ut(e,0);if(n===void 0)return[];const i=aa(e,t,n),r=[];for(const a of e.getDescendantsOfKind(l.CallExpression)){const c=a.getExpression();if(!o.isPropertyAccessExpression(c)||!ta.has(c.getName())||c.getExpression().getText()!==n)continue;const u=a.getArguments()[1];if(!u||!ca(u,i))continue;const d=la(a.getArguments()[0]);d!==void 0&&r.push({dispatchKind:t,file:s,handlerExport:E(a),line:a.getStartLineNumber(),targetExport:d.exportName,targetFile:d.file})}return r},da=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=na(n);if(i===void 0||!ea.has(i))continue;const r=ra(n);r!==void 0&&s.push(...ua(r,i==="defineQueue"?"queue":"workflow",t))}return s},fa=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...da(i,v(t,n)))}return s},mt={dbRateLimit:"usesRateLimit",emailGateMiddleware:"usesEmailGate",mask:"usesMask",rateLimit:"usesRateLimit",rls:"usesRls",verifyTurnstileMiddleware:"usesCaptcha"},ht=new Set(["account","credential","member","passkey","session","user"]),ga=e=>e.replaceAll(/[-_]/gu," ").replaceAll(/([a-z0-9])([A-Z])/gu,"$1 $2").split(" ").filter(Boolean).map(t=>t.toLowerCase()),pa=e=>{const s=ga(e).at(-1);if(!s)return!1;const n=s.endsWith("s")?s.slice(0,-1):s;return ht.has(s)||ht.has(n)},ma=e=>{const t=e.replaceAll(/[^a-z0-9]/giu,"").toLowerCase();return t.endsWith("email")||t.endsWith("emailaddress")},ha=(e,t)=>{const{objects:s,opaque:n}=Dt(e,t);return mr(s).some(i=>ma(i))?!0:n?void 0:!1},xa=e=>{const t=e.getArguments()[0];return!t||!o.isObjectLiteralExpression(t)?{usesCaptcha:!1,usesRateLimit:!1}:{usesCaptcha:!!t.getProperty("captcha"),usesRateLimit:!!t.getProperty("rateLimit")}},Ea=e=>{if(o.isCallExpression(e))return e;if(!o.isIdentifier(e))return;const s=e.getSourceFile().getVariableDeclaration(e.getText())?.getInitializer();return s&&o.isCallExpression(s)?s:void 0},Z={usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},va=e=>{const t=Ea(e),s=t?A(t.getExpression()):void 0;if(t&&s==="protectPublic"){const n=xa(t);return{...Z,usesCaptcha:n.usesCaptcha,usesRateLimit:n.usesRateLimit}}return s!==void 0&&s in mt?{...Z,[mt[s]]:!0}:Z},Sa=e=>{const t={...Z};let s=e;for(;o.isCallExpression(s);){const n=s.getExpression();if(!o.isPropertyAccessExpression(n))break;const i=n.getName()==="use"?s.getArguments()[0]:void 0;if(i){const r=va(i);t.usesCaptcha||=r.usesCaptcha,t.usesEmailGate||=r.usesEmailGate,t.usesMask||=r.usesMask,t.usesRateLimit||=r.usesRateLimit,t.usesRls||=r.usesRls}s=n.getExpression()}return t},Aa=new Set(["insert","insertMany","insertManyUnsafe","replace"]),ya=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Aa.has(t.getName()))return!1;const s=t.getExpression();if(!M(s))return!1;const i=e.getArguments()[0];return!i||!(o.isStringLiteral(i)||o.isNoSubstitutionTemplateLiteral(i))?!1:pa(i.getLiteralText())},Na=new Set(["create","runAfter","runAt","send","sendBatch"]),ba=new Set(["queues","scheduler","workflows"]),Pa=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!Na.has(t.getName()))return!1;let s=t.getExpression();for(;o.isCallExpression(s)||o.isElementAccessExpression(s)||o.isPropertyAccessExpression(s);){if(o.isPropertyAccessExpression(s)&&ba.has(s.getName())){const n=s.getExpression();if(o.isIdentifier(n)&&n.getText()==="ctx")return!0}s=s.getExpression()}return!1},Ia=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||t.getName()!=="insertManyUnsafe")return!1;const s=t.getExpression();return M(s)},jt=new Set(["generateObject","generateText","streamObject","streamText"]),wa=e=>{const t=A(e.getExpression());return t!==void 0&&jt.has(t)},Ta=e=>{const t=A(e.getExpression());if(t===void 0||!jt.has(t))return!1;const s=e.getArguments()[0];return!s||!o.isObjectLiteralExpression(s)||s.getProperties().some(n=>o.isSpreadAssignment(n))?!1:!s.getProperty("maxOutputTokens")},Ca=new Set(["log","span","trace"]),Fa=new Set(["ai"]),Oa=new Set(["email","mail"]),La=new Set(["ai","browser","fetch","mail","notify","queues","sql","storage","workflows"]),he=(e,t)=>e.getDescendantsOfKind(l.PropertyAccessExpression).some(s=>{if(!t.has(s.getName()))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="ctx"}),Ra=new Set([l.ArrowFunction,l.FunctionDeclaration,l.FunctionExpression,l.GetAccessor,l.MethodDeclaration,l.SetAccessor]),Da=new Set(["every","filter","flatMap","forEach","map","some"]),ka=new Set(["all","allSettled","race"]),Ma=e=>{const t=e.getParent();if(!t||!o.isCallExpression(t)||!t.getArguments().includes(e))return;const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;const n=s.getName();if(Da.has(n))return t;const i=s.getExpression();if(o.isIdentifier(i)&&i.getText()==="Promise"&&ka.has(n))return t},Ka=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(Ra.has(t.getKind())){const s=Ma(t);if(!s)return!1;t=s;continue}t=t.getParent()}return!1},_a=e=>{let t=e;for(;;){const s=t.getParent();if(!o.isPropertyAccessExpression(s)||s.getExpression()!==t)return!1;if(s.getName()==="catch")return!0;if(s.getName()!=="then"&&s.getName()!=="finally")return!1;const n=s.getParent();if(!o.isCallExpression(n)||n.getExpression()!==s)return!1;t=n}},za=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}},Ua=e=>{let t=!1,s=!0;for(const n of e.getDescendantsOfKind(l.PropertyAccessExpression)){if(!La.has(n.getName()))continue;const i=n.getExpression();if(!o.isIdentifier(i)||i.getText()!=="ctx")continue;const r=za(n);r&&(t=!0,!Ka(r)&&!_a(r)&&(s=!1))}return{handlesErrors:t&&s,reachesOutbound:t}},Ba=e=>e.getDescendantsOfKind(l.ThrowStatement).some(t=>{const s=t.getExpression();if(!o.isNewExpression(s))return!1;const n=s.getExpression();return o.isIdentifier(n)&&n.getText()==="Error"}),xt="lunora-advisor-exempt",qa=/^[\s*/]+/u,$a=/[\w-]/u,ja=e=>{const s=(e.getFirstAncestorByKind(l.VariableStatement)??e).getLeadingCommentRanges().map(n=>n.getText()).join(`
6
+ `);for(const n of s.split(`
7
+ `)){const i=n.replace(qa,"");if(!i.startsWith(xt))continue;const r=i.slice(xt.length);if($a.test(r.charAt(0)))continue;const a=r.indexOf("--");return{exempt:!0,exemptReason:(a===-1?"":r.slice(a+2).split("*")[0]??"").trim()}}return{exempt:!1,exemptReason:""}},Va=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}},Wa=(e,t)=>{const s=Va(t);if(!s)return;if(o.isArrowFunction(s)||o.isFunctionExpression(s)||o.isMethodDeclaration(s))return e;if(!o.isIdentifier(s))return;const n=s.getSourceFile(),i=s.getText(),r=n.getVariableDeclaration(i)?.getInitializer();return r&&(o.isArrowFunction(r)||o.isFunctionExpression(r))?r:n.getFunction(i)},Ha=e=>{let t=!1,s=!1,n=!1,i=!1,r=!1;for(const u of e.getDescendantsOfKind(l.CallExpression))if(ya(u)&&(r=!0),Pa(u)&&(t=!0),Ia(u)&&(i=!0),wa(u)&&(s=!0),Ta(u)&&(n=!0),r&&t&&i&&n)break;const{handlesErrors:a,reachesOutbound:c}=Ua(e);return{callsMail:he(e,Oa),emitsEvent:he(e,Ca),fanOut:t,handlesErrors:a,reachesOutbound:c,runsAiGeneration:s||he(e,Fa),throwsBareError:Ba(e),unboundedAiGeneration:n,usesInsertManyUnsafe:i,writesUserTable:r}},Ga=(e,t)=>{const s=e.getInitializer();if(!s||!o.isCallExpression(s))return;const n=z(s);if(!n||n.kind!=="query"&&n.kind!=="mutation"&&n.kind!=="action")return;const i=n.receiver?Sa(n.receiver):{usesCaptcha:!1,usesEmailGate:!1,usesMask:!1,usesRateLimit:!1,usesRls:!1},r=Wa(e,s);return{...r?Ha(r):{},...ja(e),...i,analyzableBody:r!==void 0,exportName:e.getName(),file:t,hasEmailArg:ha(s,n.receiver),kind:n.kind,visibility:n.visibility}},Ya=(e,t)=>{const s=[];for(const n of e.getVariableStatements())if(n.isExported())for(const i of n.getDeclarations()){const r=Ga(i,t);r&&s.push(r)}return s},Qa=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...Ya(i,v(t,n)))}return s},Xa=new Set(["dbRateLimit","rateLimit"]),Za=e=>o.isArrowFunction(e)?e.getBody():e,Ja=(e,t)=>{const s=A(e.getExpression());if(s===void 0||!Xa.has(s))return;const n=e.getArguments()[2];if(!n)return;const i=y(n,"key");if(!i)return;const r=Za(i);if(!(!R(r)||_(r)))return{callee:s,exportName:E(e),file:t,limitName:bt(e),line:e.getStartLineNumber()}},ec=(e,t)=>w(e,t,Ja),tc=new Set(["findFirst","findFirstOrThrow","findMany","get"]),sc=e=>{const t=e.getExpression();if(!o.isPropertyAccessExpression(t)||!tc.has(t.getName()))return;const s=t.getExpression();if(M(s)){const n=e.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}if(o.isPropertyAccessExpression(s)&&M(s.getExpression()))return s.getName()},nc=e=>{let t=e;for(;o.isCallExpression(t);){const s=t.getExpression();if(!o.isPropertyAccessExpression(s))return;if(s.getName()==="query"&&M(s.getExpression())){const n=t.getArguments()[0];return n&&o.isStringLiteral(n)?n.getLiteralText():""}t=s.getExpression()}},rc=e=>{let t=Je(e)??e;for(;o.isAwaitExpression(t);)t=Je(t.getExpression())??t.getExpression();return t},Vt=(e,t=!1)=>{const s=rc(e);if(o.isIdentifier(s)){if(t)return;const n=oe(s);return n===void 0?void 0:Vt(n,!0)}if(o.isCallExpression(s))return sc(s)??nc(s)},ic=e=>{const t=e.getBody();if(!o.isBlock(t))return[t];const s=[];for(const n of e.getDescendantsOfKind(l.ReturnStatement)){const i=n.getFirstAncestor(a=>o.isArrowFunction(a)||o.isFunctionExpression(a)||o.isFunctionDeclaration(a)),r=n.getExpression();i===e&&r!==void 0&&s.push(r)}return s},oc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer();if(s===void 0||!o.isCallExpression(s))return[];const n=z(s);if(n?.kind!=="query")return[];const i=Mt(s);if(i===void 0)return[];const r=n.receiver!==void 0&&Hs(n.receiver,"output"),a=n.receiver!==void 0&&It(n.receiver,"use","mask"),c=new Set,u=[];for(const d of ic(i)){const S=Vt(d);S===void 0||c.has(S)||(c.add(S),u.push({exportName:e.getName(),file:t,line:d.getStartLineNumber(),table:S,usesMask:a,usesOutput:r,visibility:n.visibility}))}return u},ac=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...oc(c,r))}return s},cc=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},lc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?z(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Pt(r);if(a===void 0)continue;const c=cc(y(a.options,"with"));c.length!==0&&i.push({exportName:e.getName(),file:t,line:r.getStartLineNumber(),parentTable:a.table,relations:c,visibility:n.visibility})}return i},uc=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...lc(c,r))}return s},se=e=>{if(o.isStringLiteral(e)||o.isNoSubstitutionTemplateLiteral(e))return e.getLiteralText();if(o.isBinaryExpression(e)&&e.getOperatorToken().getKind()===l.PlusToken){const t=se(e.getLeft()),s=se(e.getRight());return t!==void 0&&s!==void 0?t+s:void 0}},dc=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&&se(t)!==void 0},fc=/(?:^|\/)__tests__\//u,gc=/\.(?:spec|test)$/u,pc=e=>fc.test(e)||gc.test(e),mc=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()}},hc=(e,t,s)=>pn(e)?!pc(s)&&mn(mc(t)):!0,xc=(e,t)=>{const s=[],n=[...e.getDescendantsOfKind(l.BinaryExpression),...e.getDescendantsOfKind(l.StringLiteral),...e.getDescendantsOfKind(l.NoSubstitutionTemplateLiteral)],i=new Set;for(const r of n){if(dc(r))continue;const a=se(r);if(a===void 0)continue;const c=fn(a);if(c===void 0||!hc(c,r,t))continue;const u=r.getStartLineNumber(),d=`${String(u)}:${c}`;i.has(d)||(i.add(d),s.push({file:t,kind:c,line:u,preview:gn(a)}))}return s},Ec=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...xc(i,v(t,n)))}return s},vc=(e,t)=>{if(!o.isVariableDeclaration(e))return[];const s=e.getInitializer(),n=s&&o.isCallExpression(s)?z(s):void 0;if(!n)return[];const i=[];for(const r of e.getDescendantsOfKind(l.CallExpression)){const a=Pt(r);if(a===void 0)continue;const c=y(a.options,"includeDeleted");if(c===void 0)continue;const u=o.isTrueLiteral(c),d=!u&&R(c);!u&&!d||i.push({exportName:e.getName(),file:t,fromArgs:d,hardcodedTrue:u,line:r.getStartLineNumber(),table:a.table,visibility:n.visibility})}return i},Sc=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getVariableStatements())if(a.isExported())for(const c of a.getDeclarations())s.push(...vc(c,r))}return s},Ac=new Set(["query","unsafe"]),yc=e=>{if(!o.isPropertyAccessExpression(e)||!Ac.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"},Nc=e=>o.isBinaryExpression(e)||o.isTemplateExpression(e),bc=e=>e.getFirstAncestorByKind(l.VariableDeclaration)?.getName()??"<module>",Pc=(e,t)=>{if(!yc(e.getExpression()))return;const s=e.getArguments()[0];if(!(!s||!Nc(s)))return{exportName:bc(e),file:t,line:s.getStartLineNumber()}},Ic=(e,t)=>w(e,t,Pc),wc=[["convex",["convex","@convex-dev/"]],["supabase",["@supabase/"]],["firebase",["firebase","@firebase/","firebase-admin"]]],Tc=e=>{for(const[t,s]of wc)for(const n of s)if(e===n||e.startsWith(n.endsWith("/")?n:`${n}/`))return t},Cc=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);for(const r of i.getImportDeclarations()){const a=r.getModuleSpecifierValue(),c=Tc(a);c!==void 0&&s.push({file:v(t,n),line:r.getStartLineNumber(),moduleSpecifier:a,platform:c})}}return s},Fc=new Set(["createMultipartUpload","delete","download","generateUploadUrl","get","getMetadata","getPresignedUrl","getSignedUrl","getUrl","head","put","resumeMultipartUpload","store","upload"]),Oc=(e,t,s=[])=>{const n=new Map(s.map(r=>[`${r.filePath}:${r.exportName}`,r.visibility]));return ae(e,t,{argIndex:0,matchReceiver:r=>r==="ctx.storage"||r.startsWith("ctx.storage."),methods:Fc,requireUnmodifiedReach:!0}).map(r=>{const a=n.get(`${r.file}:${r.exportName}`);return a===void 0?r:{...r,visibility:a}})},Lc=new Map([["generateUploadUrl",1],["getPresignedUrl",1],["getSignedUrl",1],["store",2],["upload",2]]),Rc=e=>e&&o.isNumericLiteral(e)?Number(e.getText()):void 0,Dc=e=>{if(e===void 0)return{analyzable:!0,presentKeys:[]};if(!o.isObjectLiteralExpression(e))return{analyzable:!1,presentKeys:[]};const t=[];let s,n=!1;for(const i of e.getProperties()){if(o.isSpreadAssignment(i)){n=!0;continue}if(o.isPropertyAssignment(i)){const r=i.getName();t.push(r),r==="expiresInSeconds"&&(s=Rc(i.getInitializer()));continue}(o.isShorthandPropertyAssignment(i)||o.isMethodDeclaration(i))&&t.push(i.getName())}return{analyzable:!n,expiresInSeconds:s,presentKeys:t}},kc=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName(),s=Lc.get(t);if(s===void 0)return;const n=e.getExpression().getText();return n==="ctx.storage"||n.startsWith("ctx.storage.")?{method:t,optionsIndex:s}:void 0},Mc=(e,t)=>{const s=kc(e.getExpression());if(s!==void 0)return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s.method,...Dc(e.getArguments()[s.optionsIndex])}},Kc=(e,t)=>w(e,t,Mc),_c=(e,t)=>({analytics:e.analytics||t.dependencies.has("@lunora/bindings"),auth:t.dependencies.has("@lunora/auth"),containers:e.container||t.containerCount>0||t.dependencies.has("@lunora/container"),flags:e.flags||t.dependencies.has("@lunora/flags"),kv:e.kv||t.dependencies.has("@lunora/bindings"),mail:e.mail||t.dependencies.has("@lunora/mail"),notifications:e.notify||t.dependencies.has("@lunora/notify"),payments:e.payments||t.hasPaymentTables,queues:t.queueCount>0||t.dependencies.has("@lunora/queue"),scheduler:e.scheduler||t.cronCount>0||t.dependencies.has("@lunora/scheduler"),storage:e.storage||t.storageRuleCount>0||t.storageColumnCount>0||t.dependencies.has("@lunora/storage"),vectors:e.vectors||t.vectorIndexCount>0||t.dependencies.has("@lunora/bindings"),workflows:e.workflows||t.workflowCount>0||t.dependencies.has("@lunora/workflow")}),zc=new Set(["RegisteredAction","RegisteredMutation","RegisteredQuery"]),Pe=e=>{const t=e.getType(),s=t.getAliasSymbol()?.getName()??t.getSymbol()?.getName();return s!==void 0&&zc.has(s)?s:void 0},Wt=e=>{const t=e.getInitializer();return t===void 0?!1:o.isCallExpression(t)||o.isIdentifier(t)||o.isPropertyAccessExpression(t)},Ht={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."},Uc={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."},Ie=(e,t,s,n,i)=>({cacheKey:`procedure_not_registered:${e}:${t}`,categories:["SCHEMA"],description:"Codegen registers an export only when the declaration carries `export` and its initializer is literally a builder chain. A procedure written any other way exists at runtime but never reaches `_generated/api.ts`, so no caller can address it.",detail:`\`${t}\` in \`${e}\` (line ${n.toString()}) has type \`${s}\` but was not registered — ${i.cause}.`,facing:"INTERNAL",level:"WARN",metadata:{exportName:t,filePath:e,line:n,typeName:s},name:"procedure_not_registered",remediation:`Assign the builder chain directly: \`export const ${t} = query.input({ … }).query(handler);\`. ${i.remediation}`,title:"Procedure exists at runtime but is missing from the generated API"}),Bc=(e,t,s)=>{const n=[];for(const i of e.getVariableStatements().filter(r=>r.isExported()))for(const r of i.getDeclarations()){const a=r.getName();if(s.has(`${t}:${a}`)||!Wt(r))continue;const c=Pe(r);c!==void 0&&n.push(Ie(t,a,c,r.getStartLineNumber(),Ht))}return n},qc=(e,t,s)=>{if(s.has(`${t}:default`))return[];const n=[];for(const i of e.getExportAssignments().filter(r=>!r.isExportEquals())){const r=Pe(i.getExpression());r!==void 0&&n.push(Ie(t,"default",r,i.getStartLineNumber(),Ht))}return n},$c=(e,t,s)=>{const n=[];for(const i of e.getExportDeclarations().filter(r=>r.getModuleSpecifier()===void 0))for(const r of i.getNamedExports()){const a=r.getAliasNode()?.getText()??r.getName();if(s.has(`${t}:${a}`))continue;const c=r.getLocalTargetDeclarations().find(d=>o.isVariableDeclaration(d));if(c===void 0||!Wt(c))continue;const u=Pe(c);u!==void 0&&n.push(Ie(t,a,u,r.getStartLineNumber(),Uc))}return n},jc=(e,t,s)=>[...Bc(e,t,s),...qc(e,t,s),...$c(e,t,s)],Vc=(e,t,s)=>{const n=new Set(s.map(r=>`${r.filePath}:${r.exportName}`)),i=[];for(const r of p(t)){const a=e.getSourceFile(r);a!==void 0&&i.push(...jc(a,v(t,r),n))}return i.toSorted((r,a)=>r.cacheKey.localeCompare(a.cacheKey))},Wc=new Set(["when","where"]),xe=new Set(["definePolicy","defineShape"]),Hc=e=>{if(!o.isCallExpression(e))return;const t=e.getExpression();if(o.isPropertyAccessExpression(t)){const n=t.getName();return xe.has(n)?n:void 0}if(!o.isIdentifier(t))return;for(const n of t.getSymbol()?.getDeclarations()??[])if(o.isImportSpecifier(n)){const i=n.getNameNode().getText();return xe.has(i)?i:void 0}const s=t.getText();return xe.has(s)?s:void 0},Gc=e=>o.isObjectLiteralExpression(e)&&e.getProperties().length===0,Gt=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 Gt(e.getExpression())}},we=e=>e.getAncestors().find(t=>o.isArrowFunction(t)||o.isFunctionExpression(t)||o.isFunctionDeclaration(t)),Yc=e=>e.getDescendantsOfKind(l.ReturnStatement).filter(t=>we(t)===e),Yt=e=>e.getDescendantsOfKind(l.ConditionalExpression).filter(t=>we(t)===e),Qc=e=>{const t=Yc(e);return t.length>1?!0:t.some(s=>s.getFirstAncestorByKind(l.IfStatement)!==void 0)||Yt(e).length>0},Xc=e=>e.getDescendantsOfKind(l.IfStatement).filter(t=>we(t)===e),ye=e=>e.getKind()===l.NullKeyword||e.getKind()===l.FalseKeyword||o.isIdentifier(e)&&e.getText()==="undefined"?!0:o.isNumericLiteral(e)?e.getLiteralValue()===0:o.isStringLiteral(e)&&e.getLiteralValue()==="",Zc=(e,t)=>ye(e)||ye(t),Jc=new Map([[l.EqualsEqualsEqualsToken,"positive"],[l.EqualsEqualsToken,"positive"],[l.ExclamationEqualsEqualsToken,"negative"],[l.ExclamationEqualsToken,"negative"]]),Et=e=>!ye(e)&&(o.isLiteralExpression(e)||e.getKind()===l.TrueKeyword),el=(e,t,s)=>{const n=Jc.get(e);if(n!==void 0)return Zc(t,s)?n==="positive"?"negative":"positive":Et(t)||Et(s)?void 0:n},j=e=>{if(o.isParenthesizedExpression(e))return j(e.getExpression());if(o.isPrefixUnaryExpression(e)&&e.getOperatorToken()===l.ExclamationToken)return"negative";if(o.isBinaryExpression(e)){const t=e.getOperatorToken().getKind(),s=el(t,e.getLeft(),e.getRight());if(s!==void 0)return s;if(t===l.AmpersandAmpersandToken||t===l.BarBarToken){const n=j(e.getLeft()),i=j(e.getRight());return n===i?n:"indeterminate"}}return o.isIdentifier(e)||o.isPropertyAccessExpression(e)||o.isElementAccessExpression(e)||o.isCallExpression(e)?"positive":"indeterminate"},vt=e=>{if(e!==void 0){if(o.isReturnStatement(e))return e;if(o.isBlock(e)){const t=e.getStatements().at(-1);return t!==void 0&&o.isReturnStatement(t)?t:void 0}}},tl=e=>{if(e.getElseStatement()!==void 0)return;const t=e.getNextSiblingIfKind(l.ReturnStatement);return t!==void 0&&t.getNextSibling()===void 0?t:void 0},sl=e=>o.isReturnStatement(e)?e.getExpression()??e:e,nl=e=>{const t=[];for(const s of Yt(e)){const n=j(s.getCondition());n==="positive"?t.push(s.getWhenFalse()):n==="negative"&&t.push(s.getWhenTrue())}for(const s of Xc(e)){const n=j(s.getExpression());if(n==="indeterminate")continue;const i=n==="negative"?vt(s.getThenStatement()):vt(s.getElseStatement())??tl(s);i!==void 0&&t.push(sl(i))}return t},rl=e=>{for(const t of e.getAncestors())if(o.isVariableDeclaration(t)){const s=t.getNameNode();if(o.isIdentifier(s))return s.getText()}return"<anonymous>"},il=(e,t,s)=>{if(!o.isCallExpression(e))return[];const[n]=e.getArguments();if(!n||!o.isObjectLiteralExpression(n))return[];const i=[];for(const r of n.getProperties()){if(!o.isPropertyAssignment(r)||!Wc.has(r.getName()))continue;const a=r.getInitializer();if(!(!a||!(o.isArrowFunction(a)||o.isFunctionExpression(a)))&&Qc(a))for(const c of nl(a)){const u=Gt(c);u!==void 0&&i.push({exportName:rl(e),file:s,form:u,key:r.getName(),line:c.getStartLineNumber(),owner:t})}}return i},ol=(e,t)=>{const s=[];for(const n of e.getDescendantsOfKind(l.CallExpression)){const i=Hc(n);i!==void 0&&s.push(...il(n,i,t))}return s},al=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n);s.push(...ol(i,v(t,n)))}return s},cl=new Set(["query","upsert","upsertMany"]),ll=e=>{if(!o.isPropertyAccessExpression(e))return;const t=e.getName();if(cl.has(t))return e.getExpression().getText()==="ctx.vectors"?t:void 0},ul=(e,t)=>{const s=ll(e.getExpression());if(s===void 0)return;const n=e.getArguments()[1];if(!n)return;const i=y(n,"namespace");if(!(!i||!R(i)||_(i)))return{exportName:E(e),file:t,line:e.getStartLineNumber(),method:s}},dl=(e,t)=>w(e,t,ul),fl=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"},gl=e=>{const t=e.getArguments()[0];return t&&o.isStringLiteral(t)?t.getLiteralText():""},pl=(e,t)=>{const s=[];for(const n of p(t)){const i=e.getSourceFile(n)??e.addSourceFileAtPath(n),r=v(t,n);for(const a of i.getDescendantsOfKind(l.CallExpression)){if(!fl(a))continue;const c=Ds(a);c!==""&&s.push({exportName:c,file:r,line:a.getStartLineNumber(),workflow:gl(a)})}}return s},ml=".lunora-schema.json",C=(e,t)=>{P(e)&&yt(e,"utf8")===t||as(e,t,"utf8")},L=(e,t)=>{if(t===""){cs(e,{force:!0});return}C(e,t)},hl=e=>{const t=f(e,"package.json");if(P(t))try{const s=JSON.parse(yt(t,"utf8"));return typeof s.version=="string"&&s.version!==""?s.version:void 0}catch{return}},xl=()=>{const e=process.env.LUNORA_CODEGEN_TIMING;return e!==void 0&&e!==""},El=e=>{let t=P(e)?e:X(e);for(;t&&t!==X(t);){const s=f(t,"tsconfig.json");if(P(s))return s;t=X(t)}},St=e=>e.replaceAll("\\","/"),vl=(e,t,s)=>{if(s&&e.length>0){const r=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) (${r}), codegen can't verify none of them replicate a table that policy masks — inline every table and column as literal keys so codegen can verify it, or remove the affected shape(s).`,{status:422})}const n=new Map;for(const r of t.columns){const a=n.get(r.table)??[];a.push(r.column),n.set(r.table,a)}const i=t.columns.length>0;for(const r of e){if(r.table===void 0){if(i)throw new k("MASK_UNSUPPORTED",`defineShape "${r.exportName}" has a non-literal \`table\` (a variable or expression, not a string literal), so codegen can't statically verify it doesn't replicate a table that masks a column. This project masks at least one column elsewhere, so the combination can't be proven safe — change "${r.exportName}"'s \`table\` to a plain string literal so codegen can verify it, or remove the mask(s) on the table it targets.`,{status:422});continue}const a=n.get(r.table);if(a===void 0)continue;const c=a.map(u=>`"${u}"`).join(", ");throw new k("MASK_UNSUPPORTED",`defineShape "${r.exportName}" replicates table "${r.table}", which masks column(s) ${c} on at least one procedure. A shape runs no procedure, so \`.use(mask(...))\` never applies to its replicated rows — remove the shape, unmask the table, or wait for shape-masking support.`,{status:422})}},ne=(e,t,s)=>{const n=e.getSourceFile(t);if(n===void 0){e.createSourceFile(t,s,{overwrite:!0});return}n.getFullText()!==s&&n.replaceWithText(s)},At=(e,t,s)=>e.getSourceFile(t)?.getFullText()===s,Sl=8,Al=e=>{const{agents:t,apiPath:s,generatedFunctionsPath:n,lunoraDirectory:i,migrations:r,project:a,shapes:c,usesSandbox:u,useUmbrella:d,workflows:S}=e;let x=et(a,i),I=st(a,i),g=tt(a,i);bn([...x,...I].map(T=>T.filePath));for(let T=1;;T+=1){const F=Fs({agents:t,functions:x,httpRoutes:g,mutators:I,useUmbrella:d,workflows:S}),D=Os({agents:t,functions:x,migrations:r,mutators:I,shapes:c,useUmbrella:d,usesSandbox:u});if(T>=Sl||At(a,s,F)&&At(a,n,D))return{apiContent:F,functions:x,functionsContent:D,httpRoutes:g,mutators:I};ne(a,s,F),ne(a,n,D),x=et(a,i),I=st(a,i),g=tt(a,i)}},yl=e=>{const t=El(e);return t?new Ze({skipAddingFilesFromTsConfig:!1,tsConfigFilePath:t,useInMemoryFileSystem:!1}):new Ze({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1})},hu=(e,t)=>{const s=p(t),n=f(t,"schema.ts");P(n)&&s.push(n);for(const c of s){const u=e.getSourceFile(c);u===void 0?e.addSourceFileAtPath(c):u.refreshFromFileSystemSync()}const i=new Set(s.map(c=>St(c))),r=St(t),a=`${r}/`;for(const c of e.getSourceFiles()){const u=c.getFilePath();(u===r||u.startsWith(a))&&!i.has(u)&&e.removeSourceFile(c)}for(const c of e.getSourceFiles()){const u=c.getFilePath();if(!(u===r||u.startsWith(a)||u.includes("/node_modules/")))try{c.refreshFromFileSystemSync()}catch{e.removeSourceFile(c)}}},xu=e=>{const t=xl(),s=t?ge.now():0,n=f(e.projectRoot,e.lunoraDirectory??"lunora"),i=f(n,"schema.ts");if(!P(i))throw new k("INTERNAL",`schema.ts not found at ${i}`);const r=e.project??yl(n);yn(bi);const a=dn(r,i,e.projectRoot),{agents:c,containers:u,crons:d,dataModelContent:S,dependencies:x,env:I,featureUsage:g,hasFlags:T,hasNotify:F,identity:D,platformGate:N,queues:O,serverContent:U,storageRulesMetadata:B,usesSandbox:W,useUmbrella:K,workflows:b}=qn({lunoraDirectory:n,project:r,projectRoot:e.projectRoot,schema:a,target:e.target}),m=f(n,"_generated"),Te=f(m,"dataModel.ts"),Ce=f(m,"server.ts"),Qt=f(m,"api.ts"),Xt=f(m,"functions.ts");ne(r,Te,S),ne(r,Ce,U);const ce=tn(r,n),q=hn(r,n),{apiContent:Fe,functions:$,functionsContent:Oe,httpRoutes:Zt,mutators:Jt}=Al({agents:c,apiPath:Qt,generatedFunctionsPath:Xt,lunoraDirectory:n,migrations:ce,project:r,shapes:q,useUmbrella:K,usesSandbox:W,workflows:b}),H=e.lint===!1?void 0:ds({adminRoutes:Qn(r,n),aiRawRuns:Jn(r,n),aiToolSideEffects:lr(r,n),argumentDerivedFetches:fr(r,n),argumentValidators:yr(r,n),authApiCalls:Gs(r,n),authConfigs:Lr(r,n),browserUrlAccesses:Kr(r,n),configCalls:Hr(r,n),containerKeyAccesses:Yr(r,n),containerOverrides:ti(r,n),containers:u,exportSinks:ii(r,n),staleMigrationImports:Cc(r,n),failOpenGuards:ui(r,n),flagReads:vi(r,n),flagSecurityDefaults:Ni(r,n),geoIndexUsages:wi(r,n),httpActionGuards:Di(r,n),httpHeaderWrites:ji(r,n),hyperdriveCalls:Zs(r,n),identityClaimReads:Xi(r,n),imageDeliveryUrlAccesses:Ji(r,n),inserts:Js(r,n),kvKeyAccesses:to(r,n),mailRecipientAccesses:oo(r,n),maskProcedures:en(r,n),maskStrategies:mo(r,n),mutatorWrites:Ao(r,n),nondeterministicCalls:rn(r,n),normalizeIdAuthorizations:Ko(r,n),notifyCalls:an(r,n),notifyConfig:on(r,n),ownerFieldWrites:Vo(r,n,$),unrestrictedWhereBranches:al(r,n),paymentWebhooks:Jo(r,n),privilegedDispatches:fa(r,n),procedureProtections:Qa(r,n),queries:Ws(r,n),queues:O,r2sqlCalls:cn(r,n),ratelimitKeySelectors:ec(r,n),rawRowReturns:ac(r,n),relationLoads:uc(r,n),rlsProcedures:ln(r,n),schema:a,secretLiterals:Ec(r,n),shapes:q,softDeleteReads:Sc(r,n),sqlInterpolations:Ic(r,n),storageKeyAccesses:Oc(r,n,$),storageUploads:Kc(r,n),vectorNamespaceAccesses:dl(r,n),workflowCalls:pl(r,n),workflows:b,wranglerVariables:e.wranglerVariables}),Le=H===void 0?[]:[...ls(H,{source:"static"}),...Vc(r,n,$)],es=un(r,n),Re=fo(r,n);vl(q,Re,lo(r,n));const ts=T?pi(r,n):[],G=_c(g,{containerCount:u.length,cronCount:d.length,dependencies:x,hasPaymentTables:Go(a.tables),queueCount:O.length,storageColumnCount:Object.keys(Es(a)).length,storageRuleCount:B.rules.length,vectorIndexCount:a.vectorIndexes.length,workflowCount:b.length}),De=t?ge.now():0,le=Nn(a,ce.map(h=>h.id)),ke=vs({advisories:Le,advisorProcedures:H?.procedureProtections??[],agents:c,containers:u,env:I,flagKeys:ts,hasAccessFacade:g.access,hasAi:g.ai,hasAnalytics:g.analytics,hasBrowser:g.browser,hasFlags:T,hasHyperdrive:g.hyperdrive,hasImages:g.images,hasKv:g.kv,hasNotify:F,hasPayments:g.payments,hasPipelines:g.pipelines,hasR2sql:g.r2sql,hasX402:g.x402,maskMetadata:Re,mutators:Jt,queues:O,rlsMetadata:es,schema:a,schemaSnapshot:le,shapes:q,storageRules:B,studioFeatures:G,useUmbrella:K,workflows:b}),Me=Ss(q,x.has("@lunora/db"),K),Ke=As(u,a.jurisdiction),_e=ys(b),ze=Ns(c),Ue=bs(O),Be=Ps(d),qe=Is(a.vectorIndexes),Y=ws(a,K),$e=Ts(x.has("@lunora/seed")),Q=e.apiSpec??"openapi",ue=Q==="openapi"||Q==="both",de=Q==="openrpc"||Q==="both",je=xn({emailAgents:c.filter(h=>h.onEmail===!0).map(h=>({bindingName:h.bindingName,exportName:h.exportName})),hasAccess:x.has("@lunora/cloudflare-access"),hasAi:g.ai,hasAnalytics:g.analytics,hasAuth:x.has("@lunora/auth"),hasBrowser:g.browser,hasFramework:x.has("@lunora/astro")||x.has("@lunora/svelte")||x.has("@lunora/vue"),hasGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend!=="hyperdrive"),hasHyperdrive:g.hyperdrive,hasHyperdriveGlobal:a.tables.some(h=>h.shardMode==="global"&&h.globalBackend==="hyperdrive"),hasImages:g.images,hasKv:g.kv,hasKvIntrospector:G.kv,hasNotify:F,hasPayments:g.payments,hasR2sql:g.r2sql,hasQueue:O.some(h=>h.mode==="push"),hasScheduler:G.scheduler,hasStorage:G.storage,hasVectors:N.signals.vectorStore!==!1&&a.vectorIndexes.length>0,hasWorkflow:b.length>0,hasX402:g.x402,identity:D,jurisdiction:a.jurisdiction,tableNames:a.tables.map(h=>h.name),useUmbrella:K,voiceAgents:c.filter(h=>h.voice===!0&&h.voiceBindingName!==void 0).map(h=>({bindingName:h.voiceBindingName,exportName:h.exportName})),wantsOpenApi:ue,wantsOpenRpc:de}),Ve=hl(e.projectRoot),We=En({functions:$,httpRoutes:Zt,version:Ve}),He=Sn({functions:$,version:Ve}),Ge=`${JSON.stringify(We,void 0,2)}
8
+ `,Ye=`${JSON.stringify(He,void 0,2)}
9
+ `,Qe=vn(We),Xe=An(He),fe=f(n,ml),ss=P(fe);if(e.dryRun||(P(m)||os(m,{recursive:!0}),C(f(m,"app.ts"),je),C(Te,S),C(f(m,"api.ts"),Fe),C(Ce,U),C(f(m,"functions.ts"),Oe),C(f(m,"shard.ts"),ke),C(f(m,"crons.ts"),Be),C(f(m,"vectors.ts"),qe),C(f(m,"drizzle.global.ts"),Y.global),C(f(m,"drizzle.shard.ts"),Y.shard),L(f(m,"containers.ts"),Ke),L(f(m,"workflows.ts"),_e),L(f(m,"agents.ts"),ze),L(f(m,"queues.ts"),Ue),L(f(m,"seed.ts"),$e),L(f(m,"collections.ts"),Me),L(f(m,"openapi.json"),ue?Ge:""),L(f(m,"openapi.ts"),ue?Qe:""),L(f(m,"openrpc.json"),de?Ye:""),L(f(m,"openrpc.ts"),de?Xe:""),(!ss||e.updateSchemaBaseline===!0)&&C(fe,us(le))),t){const h=ge.now(),ns=Math.round(h-s),rs=Math.round(De-s),is=Math.round(h-De);console.error(`@lunora/codegen: codegen took ${ns.toString()}ms (discovery ${rs.toString()}ms, emit ${is.toString()}ms)`)}return{advisories:Le,advisorContext:H,agents:c,containers:u,cronTriggers:Cs(d),generated:{agents:ze,api:Fe,app:je,collections:Me,containers:Ke,crons:Be,dataModel:S,drizzleGlobal:Y.global,drizzleShard:Y.shard,functions:Oe,openApi:Ge,openApiModule:Qe,openRpc:Ye,openRpcModule:Xe,queues:Ue,seed:$e,server:U,shard:ke,vectors:qe,workflows:_e},migrations:ce,outputDirectory:m,platformDiagnostics:N.diagnostics,queues:O,schemaSnapshot:le,schemaSnapshotPath:fe,workflows:b}};export{ml as SCHEMA_SNAPSHOT_FILENAME,yl as createCodegenProject,El as findTsconfig,hu as refreshCodegenProject,xu as runCodegen};
@@ -0,0 +1,2 @@
1
+ const f=(e,i=2166136261)=>{let t=i;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")},m=e=>`${f(e,2166136261)}${f(e,16777619)}`,I=1;function g(e){const i={},t=Object.keys(e);t.sort();for(const n of t)i[n]=e[n];return i}const v=e=>`${JSON.stringify(e,void 0,2)}
2
+ `,q=e=>m(v(e)),d=e=>typeof e=="object"&&e!==null,$=e=>d(e)&&d(e.fields)&&d(e.indexes)&&d(e.relations)&&typeof e.shardMode=="string",_=e=>{if(e===void 0||e.trim()==="")return{status:"absent"};let i;try{i=JSON.parse(e)}catch(n){return{error:`baseline is not valid JSON: ${n instanceof Error?n.message:String(n)}`,status:"invalid"}}if(!d(i)||i.version!==1||!d(i.tables))return{error:`baseline is malformed or written by an incompatible version (expected version ${String(1)})`,status:"invalid"};for(const[n,o]of Object.entries(i.tables))if(!$(o))return{error:`baseline table "${n}" has an invalid structure`,status:"invalid"};return{snapshot:{jurisdiction:typeof i.jurisdiction=="string"?i.jurisdiction:void 0,migrationIds:Array.isArray(i.migrationIds)?i.migrationIds:[],tables:i.tables,version:1},status:"ok"}},b=(e,i)=>e.unique===i.unique&&e.fields.length===i.fields.length&&e.fields.every((t,n)=>t===i.fields[n]),p=e=>e.unique!==void 0,u=({nullable:e,optional:i,refined:t,unique:n,...o})=>JSON.stringify(g(o)),h=e=>({form:JSON.stringify([u(e),e.optional===!0,e.nullable===!0]),refined:e.refined===!0}),y=e=>e.kind==="union"&&e.members?e.members.map(i=>h(i)):[h({...e,nullable:!1,optional:!1})],S=(e,i)=>{if(i.kind!=="union")return!1;const t=y(i);return y(e).every(n=>t.some(o=>o.form===n.form&&(n.refined||!o.refined)))},a=e=>{switch(e.kind){case"array":return`array(${e.of?a(e.of):"?"})`;case"id":return`id(${e.ref??"?"})`;case"literal":return`literal(${e.literal??"?"})`;case"object":return`object({ ${Object.keys(e.fields??{}).join(", ")} })`;case"record":return`record(${e.key?a(e.key):"?"}, ${e.of?a(e.of):"?"})`;case"union":return(e.members??[]).map(i=>a(i)).join(" | ");default:return e.kind}},c=(e,i,t)=>({remediation:"backfill",scope:"table",severity:"breaking",summary:t,table:e,type:i}),l=(e,i,t)=>({remediation:"none",scope:"table",severity:"safe",summary:t,table:e,type:i}),k=(e,i,t,n,o)=>{if(!(t.kind===n.kind&&(!o||u(t)===u(n))))return o&&S(t,n)?l(e,"widenedFieldShape",`field ${e}.${i} widened: ${a(t)} → ${a(n)} — every stored value stays valid`):t.kind!==n.kind?c(e,"changedFieldKind",`field ${e}.${i} changed type: ${t.kind} → ${n.kind} — add a data migration to convert existing values`):c(e,"changedFieldShape",`field ${e}.${i} changed shape: ${a(t)} → ${a(n)} — stored values were written against the old shape; add a data migration to convert them`)},O=(e,i,t,n)=>{const o=[];return t.unique!==n.unique&&o.push(n.unique===!0?c(e,"addedFieldConstraint",`field ${e}.${i} became unique — existing duplicates would violate it; add a data migration to de-duplicate first`):l(e,"relaxedFieldConstraint",`field ${e}.${i} is no longer unique`)),t.nullable!==n.nullable&&o.push(n.nullable===!0?l(e,"relaxedFieldConstraint",`field ${e}.${i} became nullable`):c(e,"addedFieldConstraint",`field ${e}.${i} is no longer nullable — rows holding NULL would be invalid; add a data migration to backfill them`)),t.refined!==n.refined&&o.push(n.refined===!0?c(e,"addedFieldConstraint",`field ${e}.${i} gained a validation refinement — stored values were never checked against it; add a data migration if any could fail`):l(e,"relaxedFieldConstraint",`field ${e}.${i} dropped its validation refinement`)),o},F=(e,i,t,n)=>{const o=[],s=p(t)&&p(n),r=k(e,i,t,n,s);return r&&o.push(r),s&&o.push(...O(e,i,t,n)),t.optional&&!n.optional?o.push({remediation:"backfill",severity:"breaking",summary:`field ${e}.${i} became required — rows missing it would be invalid; add a data migration to backfill it`,table:e,scope:"table",type:"fieldOptionalToRequired"}):!t.optional&&n.optional&&o.push({remediation:"none",scope:"table",severity:"safe",summary:`field ${e}.${i} became optional`,table:e,type:"fieldRequiredToOptional"}),o},x=(e,i,t)=>t.optional?{remediation:"none",scope:"table",severity:"safe",summary:`added optional field ${e}.${i}`,table:e,type:"addedOptionalField"}:{remediation:"backfill",severity:"breaking",summary:`added required field ${e}.${i} — existing rows have no value; add a data migration to backfill it`,table:e,scope:"table",type:"addedRequiredField"},j=(e,i,t,n)=>{for(const[o,s]of Object.entries(t.fields)){const r=i.fields[o];r===void 0?n.push(x(e,o,s)):n.push(...F(e,o,r,s))}for(const o of Object.keys(i.fields))t.fields[o]===void 0&&n.push({remediation:"backfill",severity:"breaking",summary:`removed field ${e}.${o} — add a data migration if stored data must be cleaned up`,table:e,scope:"table",type:"removedField"})},A=(e,i,t,n)=>{for(const[o,s]of Object.entries(t.indexes)){const r=i.indexes[o];if(r===void 0){n.push({remediation:"none",scope:"table",severity:"safe",summary:`added index ${o} on ${e}`,table:e,type:"addedIndex"});continue}b(r,s)||n.push({remediation:"code",severity:"breaking",summary:`index ${o} on ${e} changed shape — a query may have relied on the old index`,table:e,scope:"table",type:"changedIndex"})}for(const o of Object.keys(i.indexes))t.indexes[o]===void 0&&n.push({remediation:"code",severity:"breaking",summary:`removed index ${o} on ${e} — a query that used \`.withIndex("${o}")\` would break`,table:e,scope:"table",type:"removedIndex"})},w=(e,i,t,n)=>{for(const o of Object.keys(t.relations))i.relations[o]===void 0&&n.push({remediation:"none",scope:"schema",severity:"safe",summary:`added relation ${e}.${o}`,table:e,type:"addedRelation"});for(const o of Object.keys(i.relations))t.relations[o]===void 0&&n.push({remediation:"code",scope:"schema",severity:"breaking",summary:`removed relation ${e}.${o}`,table:e,type:"removedRelation"})},E=(e,i,t,n)=>{i.shardMode!==t.shardMode&&n.push({remediation:"rehome",severity:"breaking",summary:`table ${e} changed shard mode: ${i.shardMode} → ${t.shardMode} — its physical storage moves, and existing rows do NOT follow the schema; re-home them with an export/import round trip (https://lunora.sh/docs/concepts/sharding#migrating-a-populated-table)`,table:e,scope:"table",type:"changedShardMode"}),j(e,i,t,n),A(e,i,t,n),w(e,i,t,n)},C=(e,i)=>{const t=[],n=e?.tables??{};for(const[o,s]of Object.entries(i.tables)){const r=n[o];if(r===void 0){t.push({remediation:"none",scope:"table",severity:"safe",summary:`added table ${o}`,table:o,type:"addedTable"});continue}E(o,r,s,t)}for(const o of Object.keys(n))i.tables[o]===void 0&&t.push({remediation:"rehome",scope:"table",severity:"breaking",summary:`removed table ${o} — its rows stay in each shard's SQLite, unreachable through the schema; export the shard first if the data must be kept`,table:o,type:"removedTable"});if(e!==void 0&&e.jurisdiction!==i.jurisdiction){const o=e.jurisdiction??"(none)",s=i.jurisdiction??"(none)";t.push({remediation:"rehome",scope:"schema",severity:"breaking",summary:`Durable Object jurisdiction changed from ${o} to ${s} — this re-homes every DO and strands all existing shard, scheduler, and session-DO data in the old region (no in-place migration; export then import to move it). Revert the change, or override the gate to proceed intentionally.`,type:"changedJurisdiction"})}return{changes:t}};export{I as SCHEMA_SNAPSHOT_VERSION,a as describeShape,F as diffExistingField,C as diffSchemaSnapshots,q as hashSchemaSnapshot,$ as isValidTableSnapshot,_ as parseSnapshotJson,v as serializeSchemaSnapshot,g as sortKeys};
@@ -1,4 +1,4 @@
1
- import{LunoraError as E}from"@lunora/errors";import{SCHEMA_SNAPSHOT_VERSION as I,sortKeys as f,diffSchemaSnapshots as A,parseSnapshotJson as L}from"./SCHEMA_SNAPSHOT_VERSION-B1BUjuG5.mjs";import{serializeSchemaSnapshot as V}from"./SCHEMA_SNAPSHOT_VERSION-B1BUjuG5.mjs";const _=e=>e==="global"||e==="root"?e:`shardBy:${e.field}`,N=(e,t)=>{const s=JSON.stringify(e),i=JSON.stringify(t);return s===i?0:s<i?-1:1},l=e=>{const t=e.kind==="optional",s=t?e.inner:void 0,i=s??e,n={kind:t?s?.kind??"unknown":e.kind,nullable:i.column?.notNull===!1||e.column?.notNull===!1,optional:t,unique:i.column?.unique===!0||e.column?.unique===!0,...v[i.kind]?.(i)};return(i.hasRefinement===!0||e.hasRefinement===!0)&&(n.refined=!0),n},j=e=>{const t={};for(const[s,i]of Object.entries(e))t[s]=l(i);return f(t)},v={array:e=>e.inner?{of:l(e.inner)}:{},id:e=>e.tableName===void 0?{}:{ref:e.tableName},literal:e=>e.literalValue===void 0?{}:{literal:e.literalValue},object:e=>e.shape?{fields:j(e.shape)}:{},record:e=>({...e.keyType?{key:l(e.keyType)}:{},...e.valueType?{of:l(e.valueType)}:{}}),union:e=>e.members?{members:e.members.map(t=>l(t)).toSorted(N)}:{}},D=e=>{const t={};for(const[n,a]of Object.entries(e.shape))t[n]=l(a);const s={};for(const n of e.indexes)s[n.name]={fields:[...n.fields],unique:n.unique??!1};const i={};for(const n of e.relations)i[n.name]={field:n.field,kind:n.kind,table:n.table};return{fields:f(t),indexes:f(s),relations:f(i),shardMode:_(e.shardMode)}},U=(e,t)=>{const s={};for(const n of e.tables)s[n.name]=D(n);const i=[...t].sort();return{jurisdiction:e.jurisdiction,migrationIds:i,tables:f(s),version:I}};class O extends E{constructor(t){super("SCHEMA_SNAPSHOT_PARSE",t,{name:"SchemaSnapshotParseError"})}}const C=e=>{const t=L(e);if(t.status==="invalid")throw new O(t.error);return t.status==="ok"?t.snapshot:void 0},R={build:{allowDrift:!0,updateBaseline:!1},deploy:{allowDrift:!0,updateBaseline:!0},prepare:{allowDrift:!0,updateBaseline:!0},verify:{allowDrift:!0,updateBaseline:!1}},y=" • For backward-compatible changes (e.g. adding an optional field): pass `--allow-schema-drift` to skip the block.",k=" • To accept the new shape without a migration (you know data is compatible): pass `--update-schema-baseline`.",M=e=>{const t=e===void 0?void 0:R[e];if(e===void 0||t===void 0)return`${y}
1
+ import{LunoraError as E}from"@lunora/errors";import{SCHEMA_SNAPSHOT_VERSION as I,sortKeys as f,diffSchemaSnapshots as A,parseSnapshotJson as L}from"./SCHEMA_SNAPSHOT_VERSION-CWESEYLi.mjs";import{serializeSchemaSnapshot as V}from"./SCHEMA_SNAPSHOT_VERSION-CWESEYLi.mjs";const _=e=>e==="global"||e==="root"?e:`shardBy:${e.field}`,N=(e,t)=>{const s=JSON.stringify(e),i=JSON.stringify(t);return s===i?0:s<i?-1:1},l=e=>{const t=e.kind==="optional",s=t?e.inner:void 0,i=s??e,n={kind:t?s?.kind??"unknown":e.kind,nullable:i.column?.notNull===!1||e.column?.notNull===!1,optional:t,unique:i.column?.unique===!0||e.column?.unique===!0,...v[i.kind]?.(i)};return(i.hasRefinement===!0||e.hasRefinement===!0)&&(n.refined=!0),n},j=e=>{const t={};for(const[s,i]of Object.entries(e))t[s]=l(i);return f(t)},v={array:e=>e.inner?{of:l(e.inner)}:{},id:e=>e.tableName===void 0?{}:{ref:e.tableName},literal:e=>e.literalValue===void 0?{}:{literal:e.literalValue},object:e=>e.shape?{fields:j(e.shape)}:{},record:e=>({...e.keyType?{key:l(e.keyType)}:{},...e.valueType?{of:l(e.valueType)}:{}}),union:e=>e.members?{members:e.members.map(t=>l(t)).toSorted(N)}:{}},D=e=>{const t={};for(const[n,a]of Object.entries(e.shape))t[n]=l(a);const s={};for(const n of e.indexes)s[n.name]={fields:[...n.fields],unique:n.unique??!1};const i={};for(const n of e.relations)i[n.name]={field:n.field,kind:n.kind,table:n.table};return{fields:f(t),indexes:f(s),relations:f(i),shardMode:_(e.shardMode)}},U=(e,t)=>{const s={};for(const n of e.tables)s[n.name]=D(n);const i=[...t].sort();return{jurisdiction:e.jurisdiction,migrationIds:i,tables:f(s),version:I}};class O extends E{constructor(t){super("SCHEMA_SNAPSHOT_PARSE",t,{name:"SchemaSnapshotParseError"})}}const C=e=>{const t=L(e);if(t.status==="invalid")throw new O(t.error);return t.status==="ok"?t.snapshot:void 0},R={build:{allowDrift:!0,updateBaseline:!1},deploy:{allowDrift:!0,updateBaseline:!0},prepare:{allowDrift:!0,updateBaseline:!0},verify:{allowDrift:!0,updateBaseline:!1}},y=" • For backward-compatible changes (e.g. adding an optional field): pass `--allow-schema-drift` to skip the block.",k=" • To accept the new shape without a migration (you know data is compatible): pass `--update-schema-baseline`.",M=e=>{const t=e===void 0?void 0:R[e];if(e===void 0||t===void 0)return`${y}
2
2
  ${k}
3
3
  `;const s=t.updateBaseline?k:` • To accept the new shape without a migration, run \`lunora prepare --update-schema-baseline\` — \`lunora ${e}\` does not take that flag.`;return`${y}
4
4
  ${s}
@@ -0,0 +1 @@
1
+ import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{LunoraError as a}from"@lunora/errors";import{workflowDefaultName as u,workflowClassName as d,workflowBindingName as g}from"@lunora/workflow";import{Node as i,VariableDeclarationKind as w,SyntaxKind as x}from"ts-morph";import{diagnosticAt as c}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{unwrapToCallExpression as b,stringPropertyFor as h}from"./listLunoraSourceFiles-BvqYMy81.mjs";const k="workflows.ts",N=new Set(["do","sleep","sleepUntil","waitForEvent"]),y=n=>{const e=n.getSymbol();if(!e)return n.getText()==="defineWorkflow";for(const t of e.getDeclarations())if(i.isImportSpecifier(t))return t.getImportDeclaration().getModuleSpecifierValue()!=="@lunora/workflow"?!1:t.getNameNode().getText()==="defineWorkflow";return!1},E=h("workflow"),S=n=>{const e=n.getExpression();if(!i.isPropertyAccessExpression(e)||!N.has(e.getName()))return!1;const t=e.getExpression();return i.isPropertyAccessExpression(t)&&t.getName()==="step"?!0:i.isIdentifier(t)&&t.getText()==="step"},D=n=>{const e=n.getProperty("handler");if(!e)return[];const t=i.isPropertyAssignment(e)?e.getInitializer():e;if(!t)return[];const o=[];for(const r of t.getDescendantsOfKind(x.CallExpression)){if(!S(r))continue;const s=r.getArguments()[0];!s||!(i.isStringLiteral(s)||i.isNoSubstitutionTemplateLiteral(s))||o.push({line:r.getStartLineNumber(),method:r.getExpression().getName(),name:s.getLiteralValue()})}return o},l=n=>{let e=n;for(;e&&(i.isAsExpression(e)||i.isSatisfiesExpression(e)||i.isParenthesizedExpression(e));)e=e.getExpression();return e},P=n=>{const e=l(n);if(e&&i.isObjectLiteralExpression(e))return e;if(!(!e||!i.isIdentifier(e)))for(const t of e.getSymbol()?.getDeclarations()??[]){const r=i.isVariableDeclaration(t)&&t.getVariableStatement()?.getDeclarationKind()===w.Const?l(t.getInitializer()):void 0;if(r&&i.isObjectLiteralExpression(r))return r}},W=(n,e)=>{const t=P(n.getArguments()[0]);if(!t)throw c(n,`workflow "${e}": defineWorkflow's argument must be an object literal, or a local \`const\` holding one — codegen reads \`name\` and the \`ctx.step.*\` calls out of it statically. Keep the handler wherever you like and pass it through: \`const config = { handler: myHandler }; export const ${e} = defineWorkflow(config);\`.`);const o={bindingName:g(e),className:d(e),exportName:e,name:u(e),steps:D(t)},r=t.getProperty("name");return r&&i.isPropertyAssignment(r)&&(o.name=E(r.getInitializerOrThrow(),e,"name")),o},I=n=>{const e=[];for(const t of n.getVariableDeclarations()){if(!t.isExported())continue;const o=b(t.getInitializer());if(!o)continue;const r=o.getExpression();if(!i.isIdentifier(r)||!y(r))continue;const s=t.getNameNode();if(!i.isIdentifier(s))throw c(s,"defineWorkflow exports must be plain named exports (no destructuring)");e.push(W(o,s.getText()))}return e},A=n=>{const e=new Map,t=new Map;for(const o of n){const r=e.get(o.name);if(r!==void 0)throw new a("DUPLICATE_WORKFLOW_NAME",`Duplicate workflow name "${o.name}": produced by both "${r}" and "${o.exportName}". Deployed workflow names must be unique across the project.`,{status:500});e.set(o.name,o.exportName);const s=t.get(o.bindingName);if(s!==void 0)throw new a("DUPLICATE_WORKFLOW_BINDING",`Duplicate workflow binding "${o.bindingName}": produced by both "${s}" and "${o.exportName}". Workflow export names must yield unique binding names.`,{status:500});t.set(o.bindingName,o.exportName)}},$=(n,e)=>{const t=m(e,k);if(!p(t))return[];const o=n.getSourceFile(t)??n.addSourceFileAtPath(t),r=I(o);return r.sort((s,f)=>s.exportName.localeCompare(f.exportName)),A(r),r};export{k as WORKFLOWS_FILENAME,$ as discoverWorkflows};
@@ -1,3 +1,3 @@
1
- import{G as S}from"./emit-CXfWb_pY.mjs";import{s as p}from"./paths-C-9fwEgQ.mjs";import{LUNORA_ERROR_CODES as O,objectSchema as h,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const E="/_lunora/rest",A=["authorization","cf-access-jwt-assertion","cookie","x-payment"],f=["x-d1-bookmark","x-lunora-shard-key"],P=e=>[...A,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],g=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,y=(...e)=>{const t=[];for(const r of e)for(const o of r?.split(",")??[]){const s=o.trim().toLowerCase();s!==""&&!t.includes(s)&&t.push(s)}return t.length===0?void 0:t.join(", ")},T=(e,t)=>{const r=[t,`max-age=${String(g(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(g(e.staleWhileRevalidate))}`),r.join(", ")},b=e=>e.scope==="public"?y(e.vary,...P(e),...f):y(e.vary,...f),x=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},N=e=>{const t=x(e);if(t!==void 0)return`${E}/${t.namespace}/${t.name}`},k=e=>e==="query"?"GET":"POST",m="#/components/responses/LunoraError",v=/:([A-Za-z_$][\w$]*)/gu,q=e=>[...e.matchAll(v)].map(t=>t[1]),_=e=>e.replaceAll(v,"{$1}"),l=e=>e.kind==="optional"?e.inner??e:e,j=e=>{const t=new Set(q(e.path)),r=[];for(const[o,s]of Object.entries(e.searchParams)){const c=l(s);r.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:s.kind!=="optional",schema:u(c)})}for(const[o,s]of Object.entries(e.params)){const c=l(s);r.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:s.kind!=="optional",schema:u(c)})}return r},$=e=>e?{content:{"application/json":{schema:u(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},C=e=>{const t=p(e.filePath),r=j(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${p(e.path)}`,responses:{200:$(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:m}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(o.parameters=r),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:h(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},w=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o={additionalProperties:!1,properties:{args:h(e.args),functionPath:{const:r,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${r}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:r,requestBody:{content:{"application/json":{schema:o}},required:!0},responses:{200:$(e.output),default:{$ref:m}},summary:`${e.kind}: ${r}`,tags:[t],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${r}`}},D=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},o={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:T(r,r.scope),type:"string"}}};r.tag!==void 0&&(o["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const s=b(r);return s!==void 0&&(o.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:s,type:"string"}}),{headers:o}},L=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o=N(r);if(o===void 0)return;const s=k(e.kind),c=s==="GET",d={description:`Public REST endpoint for the \`${e.kind}\` \`${r}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${p(o)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort).",...D(e.expose?.cache,c?"get":"post")},default:{$ref:m}},summary:`${s} ${o}`,tags:[t],"x-lunora-function-kind":e.kind};if(c){const n=Object.entries(e.args).map(([a,i])=>{const R=l(i);return{description:`Argument \`${a}\` (JSON-encoded for non-string values).`,in:"query",name:a,required:i.kind!=="optional",schema:u(R)}});return n.length>0&&(d.parameters=n),{method:"get",operation:d,path:o}}return d.requestBody={content:{"application/json":{schema:h(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:d,path:o}},I=e=>{const t=e.version??"0.0.0",r={},o=new Set;for(const n of e.httpRoutes){const a=_(n.path),i=r[a]??{};i[n.method.toLowerCase()]=C(n),r[a]=i,o.add(p(n.filePath))}const s=e.functions.filter(n=>n.visibility!=="internal"&&n.kind!=="stream");for(const n of s){const{operation:a,pathKey:i}=w(n);r[i]={post:a},o.add(p(n.filePath))}for(const n of s){if(n.expose?.rest!==!0)continue;const a=L(n);if(a===void 0)continue;const i=r[a.path]??{};i[a.method]=a.operation,r[a.path]=i}const c=[...o].toSorted((n,a)=>n.localeCompare(a)).map(n=>({description:`Operations declared in \`lunora/${n}\`.`,name:n}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:O,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:r,tags:c}},J=e=>`${JSON.stringify(I(e),void 0,2)}
1
+ import{G as S}from"./emit-Dsr5DNpc.mjs";import{s as p}from"./paths-C-9fwEgQ.mjs";import{LUNORA_ERROR_CODES as O,objectSchema as h,validatorIrToJsonSchema as u}from"./LUNORA_ERROR_CODES-BYg8Lpgb.mjs";const E="/_lunora/rest",A=["authorization","cf-access-jwt-assertion","cookie","x-payment"],f=["x-d1-bookmark","x-lunora-shard-key"],P=e=>[...A,...(e.credentialHeaders??[]).map(t=>t.toLowerCase())],g=e=>Number.isFinite(e)?Math.max(0,Math.floor(e)):0,y=(...e)=>{const t=[];for(const r of e)for(const o of r?.split(",")??[]){const s=o.trim().toLowerCase();s!==""&&!t.includes(s)&&t.push(s)}return t.length===0?void 0:t.join(", ")},T=(e,t)=>{const r=[t,`max-age=${String(g(e.maxAge))}`];return e.staleWhileRevalidate!==void 0&&r.push(`stale-while-revalidate=${String(g(e.staleWhileRevalidate))}`),r.join(", ")},b=e=>e.scope==="public"?y(e.vary,...P(e),...f):y(e.vary,...f),x=e=>{const t=e.indexOf(":");if(!(t<=0||t>=e.length-1||e.indexOf(":",t+1)!==-1))return{name:e.slice(t+1),namespace:e.slice(0,t)}},N=e=>{const t=x(e);if(t!==void 0)return`${E}/${t.namespace}/${t.name}`},k=e=>e==="query"?"GET":"POST",m="#/components/responses/LunoraError",v=/:([A-Za-z_$][\w$]*)/gu,q=e=>[...e.matchAll(v)].map(t=>t[1]),_=e=>e.replaceAll(v,"{$1}"),l=e=>e.kind==="optional"?e.inner??e:e,j=e=>{const t=new Set(q(e.path)),r=[];for(const[o,s]of Object.entries(e.searchParams)){const c=l(s);r.push({description:`Query parameter \`${o}\``,in:"query",name:o,required:s.kind!=="optional",schema:u(c)})}for(const[o,s]of Object.entries(e.params)){const c=l(s);r.push({description:`Path parameter \`${o}\``,in:t.has(o)?"path":"query",name:o,required:t.has(o)?!0:s.kind!=="optional",schema:u(c)})}return r},$=e=>e?{content:{"application/json":{schema:u(e)}},description:"Successful response."}:{content:{"application/json":{schema:{description:"Return shape is TS-inferred (no `.output()` declared); best-effort — any JSON."}}},description:"Successful response. The return shape is TypeScript-inferred and not declared via `.output()`, so it is documented best-effort."},C=e=>{const t=p(e.filePath),r=j(e),o={description:`${e.stream?"Streaming (SSE) ":""}HTTP route handler \`${e.exportName}\` (${e.method} ${e.path}).`,operationId:`${e.method.toLowerCase()}_${p(e.path)}`,responses:{200:$(e.output),204:{description:"No content (handler returned `undefined`)."},default:{$ref:m}},summary:`${e.method} ${e.path}`,tags:[t]};return r.length>0&&(o.parameters=r),Object.keys(e.body).length>0&&(o.requestBody={content:{"application/json":{schema:h(e.body)}},required:!0}),e.stream&&(o["x-lunora-stream"]="text/event-stream"),o},w=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o={additionalProperties:!1,properties:{args:h(e.args),functionPath:{const:r,type:"string"},shardKey:{description:"Optional shard key; omitted routes to the default shard.",type:"string"}},required:["functionPath"],type:"object"};return{operation:{description:`Invoke the \`${e.kind}\` \`${r}\` over the Lunora RPC envelope (POST /_lunora/rpc).`,operationId:r,requestBody:{content:{"application/json":{schema:o}},required:!0},responses:{200:$(e.output),default:{$ref:m}},summary:`${e.kind}: ${r}`,tags:[t],"x-lunora-function-kind":e.kind},pathKey:`/_lunora/rpc#${r}`}},D=(e,t)=>{if(e===void 0||t!=="get"||e.scope===void 0||e.maxAge===void 0)return{};const r={maxAge:e.maxAge,scope:e.scope,...e.staleWhileRevalidate===void 0?{}:{staleWhileRevalidate:e.staleWhileRevalidate},...e.tag===void 0?{}:{tag:e.tag},...e.vary===void 0?{}:{vary:e.vary}},o={"Cache-Control":{description:r.scope==="public"?"Caching policy. `public` applies only to an uncredentialed request — a request carrying `Authorization` or `Cookie` is always answered `private`.":"Caching policy. Restricted to the caller's own cache; never stored by a shared/edge cache.",schema:{example:T(r,r.scope),type:"string"}}};r.tag!==void 0&&(o["Cache-Tag"]={description:"Purge tag for `ctx.cache.purge({ tags: [...] })`.",schema:{example:r.tag,type:"string"}});const s=b(r);return s!==void 0&&(o.Vary={description:"Request headers this response varies by. The endpoint's own negotiated headers are merged in at runtime.",schema:{example:s,type:"string"}}),{headers:o}},L=e=>{const t=p(e.filePath),r=`${t}:${e.exportName}`,o=N(r);if(o===void 0)return;const s=k(e.kind),c=s==="GET",d={description:`Public REST endpoint for the \`${e.kind}\` \`${r}\` (opt-in via \`.expose({ rest: true })\`). Routed through the procedure, so auth / RLS / validators are enforced.`,operationId:`rest_${p(o)}`,responses:{200:{content:{"application/json":{schema:{description:"Procedure result. The shape is TS-inferred from the return type; best-effort — any JSON."}}},description:"Successful result (TypeScript-inferred return shape, documented best-effort).",...D(e.expose?.cache,c?"get":"post")},default:{$ref:m}},summary:`${s} ${o}`,tags:[t],"x-lunora-function-kind":e.kind};if(c){const n=Object.entries(e.args).map(([a,i])=>{const R=l(i);return{description:`Argument \`${a}\` (JSON-encoded for non-string values).`,in:"query",name:a,required:i.kind!=="optional",schema:u(R)}});return n.length>0&&(d.parameters=n),{method:"get",operation:d,path:o}}return d.requestBody={content:{"application/json":{schema:h(e.args)}},required:Object.keys(e.args).length>0},{method:"post",operation:d,path:o}},I=e=>{const t=e.version??"0.0.0",r={},o=new Set;for(const n of e.httpRoutes){const a=_(n.path),i=r[a]??{};i[n.method.toLowerCase()]=C(n),r[a]=i,o.add(p(n.filePath))}const s=e.functions.filter(n=>n.visibility!=="internal"&&n.kind!=="stream");for(const n of s){const{operation:a,pathKey:i}=w(n);r[i]={post:a},o.add(p(n.filePath))}for(const n of s){if(n.expose?.rest!==!0)continue;const a=L(n);if(a===void 0)continue;const i=r[a.path]??{};i[a.method]=a.operation,r[a.path]=i}const c=[...o].toSorted((n,a)=>n.localeCompare(a)).map(n=>({description:`Operations declared in \`lunora/${n}\`.`,name:n}));return{components:{responses:{LunoraError:{content:{"application/json":{schema:{additionalProperties:!1,description:"Standard Lunora error envelope.",properties:{error:{additionalProperties:!1,properties:{code:{description:"Machine-readable error code. Clients switch on this value.",enum:O,type:"string"},message:{description:"Human-readable error message (never echoes internal details).",type:"string"}},required:["code","message"],type:"object"}},required:["error"],type:"object"}}},description:"A Lunora error response. The HTTP status reflects the error code (e.g. BAD_REQUEST→400, UNAUTHORIZED→401, FORBIDDEN→403, NOT_FOUND→404)."}}},info:{description:"Auto-generated from @lunora/values-typed functions by @lunora/codegen. Do not edit — run `lunora codegen` to regenerate.",title:"Lunora API",version:t},openapi:"3.1.0",paths:r,tags:c}},J=e=>`${JSON.stringify(I(e),void 0,2)}
2
2
  `,U=e=>`${S}export const openApiSpec: Record<string, unknown> = ${JSON.stringify(e,void 0,4)};
3
3
  `;export{I as buildOpenApiDocument,J as emitOpenApi,U as emitOpenApiModule};
@@ -0,0 +1 @@
1
+ import{w as a}from"./classify-procedure-call-CRm5Etni.mjs";const l=s=>a(s,"use","rls");export{l as r};
@@ -0,0 +1 @@
1
+ import{Node as o}from"ts-morph";import{unwrapExpression as a}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{a as u}from"./module-specifiers-WF8iAydP.mjs";const T=t=>o.isIdentifier(t)?t.getText():o.isPropertyAccessExpression(t)?t.getName():void 0,y=(t,i)=>{const e=new Set;for(const r of t.getImportDeclarations())if(u(r.getModuleSpecifierValue()))for(const n of r.getNamedImports())n.getNameNode().getText()===i&&e.add(n.getAliasNode()?.getText()??n.getName());return e},x=(t,i)=>{if(o.isPropertyAccessExpression(t))return t.getName()===i;if(!o.isIdentifier(t))return!1;const e=t.getText();return e===i||y(t.getSourceFile(),i).has(e)},d=t=>{const i=t.getSymbol();if(!i)return t.getText();for(const e of i.getDeclarations())if(o.isImportSpecifier(e))return u(e.getImportDeclaration().getModuleSpecifierValue())?e.getNameNode().getText():void 0},p=t=>{const i=[];let e=a(t);for(;e&&o.isCallExpression(e);){const r=a(e.getExpression());if(!r||!o.isPropertyAccessExpression(r))return{root:void 0,steps:i};i.push({call:e,name:r.getName()}),e=a(r.getExpression())}return{root:e,steps:i}},f=t=>p(t).steps,N=(t,i,e)=>f(t).filter(r=>r.name===i).map(r=>r.call.getArguments()[0]).filter(r=>r!==void 0&&o.isCallExpression(r)&&x(r.getExpression(),e)),A=(t,i)=>f(t).some(e=>e.name===i),w=(t,i,e)=>N(t,i,e).length>0,l=new Set(["action","mutation","query","stream"]),m={internalAction:"action",internalMutation:"mutation",internalQuery:"query"},I={onConnect:"connect",onDisconnect:"disconnect",onQueryChange:"reactor",onShardInit:"init"},C=t=>{const{root:i}=p(t);return i&&o.isIdentifier(i)?i:void 0},g=(t,i=!1)=>{const e=C(t);if(!e)return;const r=d(e);if(r===void 0){if(i)return;const n=e.getSymbol()?.getValueDeclaration();if(n&&o.isVariableDeclaration(n)){const s=n.getInitializer();return s?g(s,!0):void 0}return}return l.has(r)?"public":m[r]?"internal":void 0},E=t=>{const i=t.getName();if(!l.has(i))return;const e=t.getExpression(),r=a(e)??e,n=e===r?[r]:[e,r];if(n.some(c=>c.getType().getProperty("__lunoraProcedure"))){const c=n.some(v=>v.getType().getProperty("__lunoraVisibility"));return{kind:i,receiver:r,visibility:c?"internal":"public"}}const s=g(r);if(s)return{kind:i,receiver:r,visibility:s}},P=t=>{const i=t.getExpression();if(o.isPropertyAccessExpression(i))return E(i);if(!o.isIdentifier(i))return;const e=d(i);if(!e)return;if(l.has(e))return{kind:e,visibility:"public"};const r=m[e];if(r)return{kind:r,visibility:"internal"};const n=I[e];if(n)return{kind:"mutation",lifecycle:n,visibility:"internal"}};export{T as a,f as b,P as c,w as d,A as e,N as w};
@@ -0,0 +1 @@
1
+ import{Node as s,SyntaxKind as a}from"ts-morph";import{listLunoraSourceFiles as d,lunoraRelativePath as l,handlerOf as f}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{c as u}from"./classify-procedure-call-CRm5Etni.mjs";const x=e=>{const n=e.getInitializer();if(!n||!s.isCallExpression(n))return;const r=u(n);if(!r||r.kind!=="query"&&r.kind!=="mutation")return;const t=f(n,r.receiver);return t?{exportName:e.getName(),handler:t,kind:r.kind}:void 0},p=(e,n)=>{if(!s.isPropertyAccessExpression(e)||e.getName()!==n)return;const r=e.getExpression();if(!s.isIdentifier(r)||r.getText()!=="ctx")return;const t=e.getParent();return t&&s.isPropertyAccessExpression(t)&&t.getExpression()===e?`ctx.${n}.${t.getName()}`:`ctx.${n}`},m=(e,n,r)=>{const t=[];for(const o of e.handler.getDescendantsOfKind(a.PropertyAccessExpression)){const i=p(o,r);i!==void 0&&t.push({callee:i,exportName:e.exportName,file:n,kind:e.kind,line:o.getStartLineNumber()})}return t},g=(e,n,r)=>{const t=[];for(const o of e.getVariableStatements())if(o.isExported())for(const i of o.getDeclarations()){const c=x(i);c&&t.push(...m(c,n,r))}return t},N=(e,n,r)=>{const t=[];for(const o of d(n)){const i=e.getSourceFile(o)??e.addSourceFileAtPath(o);t.push(...g(i,l(n,o),r))}return t};export{N as d};
@@ -0,0 +1 @@
1
+ import{SyntaxKind as p,Node as s}from"ts-morph";import{listLunoraSourceFiles as f,lunoraRelativePath as g,enclosingExportName as d}from"./listLunoraSourceFiles-BvqYMy81.mjs";const m=r=>{const t=r.getExpression();if(!s.isPropertyAccessExpression(t))return!1;const e=t.getExpression();return s.isPropertyAccessExpression(e)?e.getName()==="authApi":s.isIdentifier(e)&&e.getText()==="authApi"},h=r=>{const t=r.getArguments()[0];if(t===void 0)return!1;if(!s.isObjectLiteralExpression(t))return!0;for(const e of t.getProperties())if((s.isPropertyAssignment(e)||s.isShorthandPropertyAssignment(e))&&e.getName()==="headers"||s.isSpreadAssignment(e))return!0;return!1},P=(r,t)=>{const e=[];for(const n of f(t)){const c=r.getSourceFile(n)??r.addSourceFileAtPath(n),l=g(t,n);for(const i of c.getDescendantsOfKind(p.CallExpression)){if(!m(i))continue;const o=d(i);if(o==="")continue;const a=i.getExpression(),u=s.isPropertyAccessExpression(a)?a.getName():"";e.push({exportName:o,file:l,hasHeaders:h(i),line:i.getStartLineNumber(),method:u})}}return e};export{P as default};
@@ -0,0 +1 @@
1
+ import{LunoraError as L}from"@lunora/errors";import{CRON_SCHEDULE_KINDS as A,isValidCronExpression as O,warnIfSecondsLeading as S,compileCronSchedule as b}from"@lunora/scheduler";import{SyntaxKind as m,Node as s}from"ts-morph";import{diagnosticAt as f,CodegenDiagnosticError as I}from"./CodegenDiagnosticError-BUXlG3P-.mjs";import{i as R}from"./module-specifiers-WF8iAydP.mjs";import{s as $}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as y}from"./listLunoraSourceFiles-BvqYMy81.mjs";const P=new Set([...A,"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(r.getImportDeclaration().getModuleSpecifierValue())?r.getNameNode().getText()==="cronJobs":!1;return!1},v=e=>{const t=new Set;for(const r of e.getVariableDeclarations()){const o=r.getInitializer();if(o?.getKind()!==m.CallExpression)continue;const i=o.getExpression();s.isIdentifier(i)&&D(i)&&t.add(r.getName())}return t},F=e=>{let t=e;for(;s.isCallExpression(t)||s.isPropertyAccessExpression(t);)t=t.getExpression();return s.isIdentifier(t)?t.getText():void 0},x=(e,t)=>{const r=e.getArguments()[t];return r&&(s.isStringLiteral(r)||s.isNoSubstitutionTemplateLiteral(r))?r.getLiteralValue():void 0},_=(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 p(e,t);if(s.isArrayLiteralExpression(e))return e.getElements().map(r=>_(r,t));throw f(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})},p=(e,t)=>{const r={};for(const o of e.getProperties()){if(!s.isPropertyAssignment(o))throw f(o,`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=o.getInitializer();i&&(r[o.getName()]=_(i,t))}return r},C=(e,t,r)=>{const o=e.getArguments()[t];if(!o||!s.isPropertyAccessExpression(o))throw f(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=o.getName(),n=o.getExpression();if(!s.isPropertyAccessExpression(n))throw f(o,`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=n.getName();return`${$(a)}:${i}`},h=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),w=e=>({workflow:{binding:e.bindingName,exportName:e.exportName}}),T=(e,t,r,o,i,n)=>{const a=e.getExpression();if(!s.isIdentifier(a)||a.getText()!==t)return;const c=r.get(e.getName());if(c)return n(c);throw f(e,`Cron job "${o}" targets ${t}.${e.getName()}, but no such ${i} is declared in lunora/${i}s.ts.`,{code:"CRON_NON_STATIC_FN",name:"LunoraError",status:500})},V=(e,t,r,o,i)=>{const n=e.getArguments()[t];if(n&&s.isPropertyAccessExpression(n)){const a=T(n,"workflows",o,r,"workflow",h);if(a)return a;const c=T(n,"agents",i,r,"agent",w);return c||{functionPath:C(e,t,r)}}if(n&&s.isIdentifier(n)){const a=o.get(n.getText()),c=i.get(n.getText());if(a&&c)throw f(n,`Cron job "${r}" references "${n.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(c)return w(c);throw f(n,`Cron job "${r}" references "${n.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)}},j=/^@lunora\/scheduler:\s*/u,k=(e,t)=>{const r=x(e,1);if(r===void 0)throw f(e,`Cron job "${t}" must pass a string-literal cron expression to ".cron(...)".`,{code:"CRON_EXPR_NOT_STATIC",name:"LunoraError",status:500});if(!O(r))throw f(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 S(r,`cron expression for job "${t}"`),r},U=(e,t,r)=>{const o=e.getArguments()[1];if(!o||!s.isObjectLiteralExpression(o))throw f(e,`Cron job "${r}" must pass an object-literal schedule to ".${t}(...)".`,{code:"CRON_SCHEDULE_NOT_STATIC",name:"LunoraError",status:500});try{return b(t,p(o,r),r)}catch(i){if(i instanceof I)throw i;const n=i instanceof Error?i.message.replace(j,""):String(i);throw f(e,n,{code:"CRON_SCHEDULE_INVALID",name:"LunoraError",status:500})}},M=(e,t,r,o,i)=>{const n=t.getName();if(!P.has(n)||!r.has(F(t.getExpression())??""))return;const a=x(e,0);if(a===void 0||a.trim()==="")throw f(e,`A cron ".${n}(...)" registration must pass a non-empty string-literal name as its first argument.`,{code:"CRON_NAME_NOT_STATIC",name:"LunoraError",status:500});const c=n==="cron"?k(e,a):U(e,n,a),u=V(e,2,a,o,i),l=e.getArguments()[3];return{args:l&&s.isObjectLiteralExpression(l)?p(l,a):{},cron:c,name:a,...u}},z=e=>{const t=new Set;for(const r of e){if(t.has(r.name))throw new L("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=[],o=[])=>{const i=y(t),n=[],a=new Map(r.map(u=>[u.exportName,u])),c=new Map(o.map(u=>[u.exportName,u]));for(const u of i){const l=e.getSourceFile(u)??e.addSourceFileAtPath(u),g=v(l);if(g.size!==0)for(const d of l.getDescendantsOfKind(m.CallExpression)){const N=d.getExpression();if(!s.isPropertyAccessExpression(N))continue;const E=M(d,N,g,a,c);E&&n.push(E)}}return n.sort((u,l)=>u.name.localeCompare(l.name)),z(n),n};export{Q as default};
@@ -0,0 +1 @@
1
+ import{s as x}from"./paths-C-9fwEgQ.mjs";import{listLunoraSourceFiles as h,lunoraRelativePath as P}from"./listLunoraSourceFiles-BvqYMy81.mjs";import{b as f,c as E}from"./classify-procedure-call-CRm5Etni.mjs";import{Node as n,SyntaxKind as b}from"ts-morph";import{p as A,a as d}from"./parse-validator-CMV0eq2a.mjs";import{u as v}from"./unwrap-handler-return-CmIWbykC.mjs";const N=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return"unknown";const t=e.getProperty("handler");if(!t||!n.isPropertyAssignment(t))return"unknown";const r=t.getInitializer();return!r||!(n.isArrowFunction(r)||n.isFunctionExpression(r))?"unknown":v(r)},F=i=>{const e=i.getArguments()[0];return!e||!(n.isArrowFunction(e)||n.isFunctionExpression(e))?"unknown":v(e)},z=i=>{let e={};for(const t of f(i)){if(t.name!=="input")continue;const r=t.call.getArguments()[0];r&&n.isObjectLiteralExpression(r)&&(e={...d(r),...e})}return e},C=i=>{const e=f(i).find(r=>r.name==="output");if(!e)return;const t=e.call.getArguments()[0];return t&&n.isExpression(t)?A(t):void 0},u=(i,e)=>{const t=i.getProperty(e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isStringLiteral(r)?r.getLiteralValue():void 0},m=(i,e)=>{const t=i.getProperty(e);if(t===void 0||!n.isPropertyAssignment(t))return;const r=t.getInitializer();return r!==void 0&&n.isNumericLiteral(r)?r.getLiteralValue():void 0},O=i=>{const e=i.getProperty("cache");if(e===void 0||!n.isPropertyAssignment(e))return;const t=e.getInitializer();if(t===void 0||!n.isObjectLiteralExpression(t))return;const r=u(t,"scope"),s=m(t,"maxAge"),o=m(t,"staleWhileRevalidate"),a=u(t,"tag"),c=u(t,"vary"),g={...s===void 0?{}:{maxAge:s},...r==="private"||r==="public"?{scope:r}:{},...o===void 0?{}:{staleWhileRevalidate:o},...a===void 0?{}:{tag:a},...c===void 0?{}:{vary:c}};return Object.keys(g).length===0?void 0:g},S=i=>{if(i===void 0||!n.isObjectLiteralExpression(i))return{};const e=O(i),t=i.getProperty("rest");return t!==void 0&&n.isPropertyAssignment(t)?{...e===void 0?{}:{cache:e},rest:t.getInitializer()?.getText()==="true"}:e===void 0?{}:{cache:e}},L=i=>{const e=f(i).find(t=>t.name==="expose");return e?S(e.call.getArguments()[0]):void 0},I=i=>{const e=i.getArguments()[0];if(!e||!n.isObjectLiteralExpression(e))return{};const t=e.getProperty("args");if(!t||!n.isPropertyAssignment(t))return{};const r=t.getInitializer();return!r||!n.isObjectLiteralExpression(r)?{}:d(r)},T=8,l=(i,e=0)=>{if(e>T)return;if(n.isCallExpression(i))return i;if(n.isParenthesizedExpression(i)||n.isAsExpression(i)||n.isSatisfiesExpression(i)||n.isNonNullExpression(i))return l(i.getExpression(),e+1);if(!n.isIdentifier(i)&&!n.isPropertyAccessExpression(i))return;const t=i.getSymbol()?.getValueDeclaration();return t?p(t,e+1):void 0},p=(i,e)=>{if(n.isVariableDeclaration(i)||n.isPropertyAssignment(i)){const t=i.getInitializer();return t?l(t,e):void 0}if(n.isShorthandPropertyAssignment(i)){const t=i.getValueSymbol()?.getValueDeclaration();return t?p(t,e+1):void 0}if(n.isBindingElement(i)){const t=i.getPropertyNameNode()?.getText()??i.getName(),o=i.getFirstAncestorByKind(b.VariableDeclaration)?.getInitializer()?.getType().getProperty(t)?.getValueDeclaration();return o?p(o,e+1):void 0}},k=i=>{const e=i.getNameNode();if(n.isObjectBindingPattern(e)){const s=[];for(const o of e.getElements()){const a=l(o.getNameNode());a&&s.push([o.getName(),a])}return s}const t=i.getInitializer(),r=t&&(n.isCallExpression(t)?t:l(t));return r?[[i.getName(),r]]:[]},V=i=>{const e=E(i);if(e){if(e.receiver){const t=L(e.receiver),r=C(e.receiver);return{args:z(e.receiver),...t?{expose:t}:{},kind:e.kind,...r?{output:r}:{},returnType:F(i),visibility:e.visibility}}return e.lifecycle?{args:{},kind:e.kind,lifecycle:e.lifecycle,returnType:"void",visibility:e.visibility}:{args:I(i),kind:e.kind,returnType:N(i),visibility:e.visibility}}},y=(i,e,t)=>{const r=V(i);if(r)return{args:r.args,exportName:e,filePath:t,kind:r.kind,returnType:r.returnType,...r.output?{output:r.output}:{},visibility:r.visibility,...r.expose?{expose:r.expose}:{},...r.lifecycle?{lifecycle:r.lifecycle}:{}}},w=(i,e)=>{const t=[];for(const r of i.getExportAssignments()){if(r.isExportEquals())continue;const s=l(r.getExpression()),o=s?y(s,"default",e):void 0;o&&t.push(o)}return t},D=(i,e)=>{const t=[];for(const r of i.getVariableStatements())if(r.isExported())for(const s of r.getDeclarations())for(const[o,a]of k(s)){const c=y(a,o,e);c&&t.push(c)}return t.push(...w(i,e)),t},j=i=>{const e=new Map;for(const t of i){const r=x(t.filePath),s=e.get(r);if(s&&s!==t.filePath)throw Object.assign(new Error(`Namespace collision: "${s}" and "${t.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:[s,t.filePath],status:500});e.set(r,t.filePath)}},K=(i,e)=>{const t=h(e),r=[];for(const s of t){const o=i.getSourceFile(s)??i.addSourceFileAtPath(s),a=P(e,s);r.push(...D(o,a))}return r.sort((s,o)=>`${s.filePath}:${s.exportName}`.localeCompare(`${o.filePath}:${o.exportName}`)),j(r),r};export{K as default};