@lunora/codegen 1.0.0-alpha.2 → 1.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -384,6 +384,26 @@ interface NondeterministicCallIR {
384
384
  line: number;
385
385
  }
386
386
  /**
387
+ * One `ctx.r2sql` access lexically inside a `query`/`mutation` handler — the
388
+ * `r2sql_outside_action` advisor lint input. Structurally identical to the
389
+ * advisor's `AdvisorR2sqlCall` (same field set) so values pass straight through
390
+ * `lintSchema` without conversion, exactly as `NondeterministicCallIR` does.
391
+ * Only `query`/`mutation` handlers are recorded; `action(...)` is the intended
392
+ * home for `ctx.r2sql` and is skipped.
393
+ */
394
+ interface R2sqlCallIR {
395
+ /** The accessed `ctx.r2sql` surface, e.g. `ctx.r2sql.query` / `ctx.r2sql.from`. */
396
+ callee: string;
397
+ /** Export binding name of the function performing the access. */
398
+ exportName: string;
399
+ /** Source file relative to the lunora dir, without extension (the api namespace). */
400
+ file: string;
401
+ /** Which procedure kind the access lives in — only `query`/`mutation` handlers are recorded. */
402
+ kind: "mutation" | "query";
403
+ /** 1-based line of the access, or `0` when unknown. */
404
+ line: number;
405
+ }
406
+ /**
387
407
  * Per-procedure RLS usage snapshot, produced by `discoverRlsProcedures` for the
388
408
  * `rls_uncovered_table` advisor lint. Structurally identical to
389
409
  * `AdvisorRlsProcedure` (they share the same field set) so values pass straight
@@ -686,7 +706,7 @@ interface ProjectIR {
686
706
  * pass straight through without conversion. Returns the findings; surfacing them
687
707
  * (console, error overlay, studio Advisors table) is the caller's choice.
688
708
  */
689
- declare const lintSchema: (schema: SchemaIR, queries?: ReadonlyArray<QueryReadIR>, inserts?: ReadonlyArray<InsertWriteIR>, authApiCalls?: ReadonlyArray<AuthApiCallIR>, rlsProcedures?: ReadonlyArray<RlsProcedureIR>, containers?: ReadonlyArray<ContainerIR>, workflows?: ReadonlyArray<WorkflowIR>, workflowCalls?: ReadonlyArray<WorkflowCallIR>, maskProcedures?: ReadonlyArray<MaskProcedureIR>, nondeterministicCalls?: ReadonlyArray<NondeterministicCallIR>, procedureProtections?: ReadonlyArray<ProcedureMiddlewareIR>, argumentValidators?: ReadonlyArray<ArgumentValidatorIR>, secretLiterals?: ReadonlyArray<SecretLiteralIR>, sqlInterpolations?: ReadonlyArray<SqlInterpolationIR>, adminRoutes?: ReadonlyArray<AdminRouteIR>) => Finding[];
709
+ declare const lintSchema: (schema: SchemaIR, queries?: ReadonlyArray<QueryReadIR>, inserts?: ReadonlyArray<InsertWriteIR>, authApiCalls?: ReadonlyArray<AuthApiCallIR>, rlsProcedures?: ReadonlyArray<RlsProcedureIR>, containers?: ReadonlyArray<ContainerIR>, workflows?: ReadonlyArray<WorkflowIR>, workflowCalls?: ReadonlyArray<WorkflowCallIR>, maskProcedures?: ReadonlyArray<MaskProcedureIR>, nondeterministicCalls?: ReadonlyArray<NondeterministicCallIR>, procedureProtections?: ReadonlyArray<ProcedureMiddlewareIR>, argumentValidators?: ReadonlyArray<ArgumentValidatorIR>, secretLiterals?: ReadonlyArray<SecretLiteralIR>, sqlInterpolations?: ReadonlyArray<SqlInterpolationIR>, adminRoutes?: ReadonlyArray<AdminRouteIR>, r2sqlCalls?: ReadonlyArray<R2sqlCallIR>) => Finding[];
690
710
  /**
691
711
  * Render advisor findings as a single multi-line string for console surfacing:
692
712
  * a one-line summary header followed by one `[LEVEL] name: detail` line per
@@ -803,6 +823,19 @@ declare const discoverNondeterministicCalls: (project: Project, lunoraDirectory:
803
823
  * dropping the rest keeps the lint input small.
804
824
  */
805
825
  declare const discoverQueries: (project: Project, lunoraDirectory: string) => QueryReadIR[];
826
+ /**
827
+ * Discover `ctx.r2sql` accesses lexically inside the handler body of every
828
+ * exported `query(...)` / `mutation(...)` registration under the lunora source
829
+ * directory — the `r2sql_outside_action` lint input. `action(...)` (and
830
+ * `stream(...)`) registrations are intentionally skipped: R2 SQL is the
831
+ * external, non-reactive surface that belongs in actions.
832
+ *
833
+ * Traversal is scoped to the handler node (not the whole declaration), mirroring
834
+ * `discoverNondeterministicCalls` — so a `ctx.r2sql` touch in a sibling helper
835
+ * outside the handler is not attributed to the query/mutation. One
836
+ * {@link R2sqlCallIR} is produced per access site.
837
+ */
838
+ declare const discoverR2sqlCalls: (project: Project, lunoraDirectory: string) => R2sqlCallIR[];
806
839
  declare const discoverRlsProcedures: (project: Project, lunoraDirectory: string) => RlsProcedureIR[];
807
840
  /**
808
841
  * Aggregate the schema-wide RLS metadata the studio's read-only inspector reads:
@@ -877,6 +910,8 @@ interface EmitServerOptions {
877
910
  hasPayments?: boolean;
878
911
  /** A `lunora/` source uses `@lunora/pipelines` / `ctx.pipelines` — wires `ctx.pipelines` onto ActionCtx only. */
879
912
  hasPipelines?: boolean;
913
+ /** A `lunora/` source uses `@lunora/r2sql` / `ctx.r2sql` — wires `ctx.r2sql` onto ActionCtx only. */
914
+ hasR2sql?: boolean;
880
915
  schema?: SchemaIR;
881
916
  storageRuleBuckets?: ReadonlyArray<string>;
882
917
  /** The project depends on the `lunora` umbrella — import base packages via its subpaths. */
@@ -893,6 +928,7 @@ declare const emitServer: ({
893
928
  hasKv,
894
929
  hasPayments,
895
930
  hasPipelines,
931
+ hasR2sql,
896
932
  schema,
897
933
  storageRuleBuckets,
898
934
  useUmbrella,
@@ -941,6 +977,8 @@ interface EmitShardOptions {
941
977
  /** A `lunora/` source reads `ctx.kv` — wires `ctx.kv` onto every ctx. */
942
978
  hasKv?: boolean;
943
979
  hasPayments?: boolean;
980
+ /** A `lunora/` source reads `ctx.r2sql` (R2 SQL) — wires `ctx.r2sql` onto the ActionCtx only. */
981
+ hasR2sql?: boolean;
944
982
  maskMetadata?: MaskMetadataIR;
945
983
  rlsMetadata?: RlsMetadataIR;
946
984
  schema: SchemaIR;
@@ -960,6 +998,7 @@ declare const emitShard: ({
960
998
  hasImages,
961
999
  hasKv,
962
1000
  hasPayments,
1001
+ hasR2sql,
963
1002
  maskMetadata,
964
1003
  rlsMetadata,
965
1004
  schema,
@@ -1049,6 +1088,8 @@ interface EmitAppOptions {
1049
1088
  hasKv: boolean;
1050
1089
  /** App uses `@lunora/payment` / `ctx.payments` → emit `.payment()`. */
1051
1090
  hasPayments: boolean;
1091
+ /** App uses `@lunora/r2sql` / `ctx.r2sql` → emit `.r2sql()`. */
1092
+ hasR2sql: boolean;
1052
1093
  /** App imports `@lunora/scheduler` / declares crons → emit `.scheduler()`. */
1053
1094
  hasScheduler: boolean;
1054
1095
  /** App uses `@lunora/storage` → emit `.storage()` (DO `ctx.storage` + studio file browser). */
@@ -1470,4 +1511,4 @@ declare const validatorIrToJsonSchema: (validator: ValidatorIR) => JsonSchema;
1470
1511
  */
1471
1512
  declare const LUNORA_ERROR_CODES: ReadonlyArray<string>;
1472
1513
  declare const VERSION = "0.0.0";
1473
- export { type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, type DriftChange, type EmitAppOptions, type FieldSnapshot, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type MaskProcedureIR, type MigrationIR, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, type ProjectIR, type QueryReadIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, diagnosticAt, diffSchemaSnapshots, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverNondeterministicCalls, discoverQueries, discoverRlsMetadata, discoverRlsProcedures, discoverSchema, discoverStorageRulesMetadata, discoverWorkflows, emitApi, emitApp, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, evaluateSchemaDrift, formatAdvisories, lintSchema, parseSchemaSnapshot, refreshCodegenProject, runCodegen, schemaFromIr, serializeSchemaSnapshot, validatorIrToJsonSchema };
1514
+ export { type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, type DriftChange, type EmitAppOptions, type FieldSnapshot, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type MaskProcedureIR, type MigrationIR, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, type ProjectIR, type QueryReadIR, type R2sqlCallIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, diagnosticAt, diffSchemaSnapshots, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverNondeterministicCalls, discoverQueries, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSchema, discoverStorageRulesMetadata, discoverWorkflows, emitApi, emitApp, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, evaluateSchemaDrift, formatAdvisories, lintSchema, parseSchemaSnapshot, refreshCodegenProject, runCodegen, schemaFromIr, serializeSchemaSnapshot, validatorIrToJsonSchema };
package/dist/index.d.ts CHANGED
@@ -384,6 +384,26 @@ interface NondeterministicCallIR {
384
384
  line: number;
385
385
  }
386
386
  /**
387
+ * One `ctx.r2sql` access lexically inside a `query`/`mutation` handler — the
388
+ * `r2sql_outside_action` advisor lint input. Structurally identical to the
389
+ * advisor's `AdvisorR2sqlCall` (same field set) so values pass straight through
390
+ * `lintSchema` without conversion, exactly as `NondeterministicCallIR` does.
391
+ * Only `query`/`mutation` handlers are recorded; `action(...)` is the intended
392
+ * home for `ctx.r2sql` and is skipped.
393
+ */
394
+ interface R2sqlCallIR {
395
+ /** The accessed `ctx.r2sql` surface, e.g. `ctx.r2sql.query` / `ctx.r2sql.from`. */
396
+ callee: string;
397
+ /** Export binding name of the function performing the access. */
398
+ exportName: string;
399
+ /** Source file relative to the lunora dir, without extension (the api namespace). */
400
+ file: string;
401
+ /** Which procedure kind the access lives in — only `query`/`mutation` handlers are recorded. */
402
+ kind: "mutation" | "query";
403
+ /** 1-based line of the access, or `0` when unknown. */
404
+ line: number;
405
+ }
406
+ /**
387
407
  * Per-procedure RLS usage snapshot, produced by `discoverRlsProcedures` for the
388
408
  * `rls_uncovered_table` advisor lint. Structurally identical to
389
409
  * `AdvisorRlsProcedure` (they share the same field set) so values pass straight
@@ -686,7 +706,7 @@ interface ProjectIR {
686
706
  * pass straight through without conversion. Returns the findings; surfacing them
687
707
  * (console, error overlay, studio Advisors table) is the caller's choice.
688
708
  */
689
- declare const lintSchema: (schema: SchemaIR, queries?: ReadonlyArray<QueryReadIR>, inserts?: ReadonlyArray<InsertWriteIR>, authApiCalls?: ReadonlyArray<AuthApiCallIR>, rlsProcedures?: ReadonlyArray<RlsProcedureIR>, containers?: ReadonlyArray<ContainerIR>, workflows?: ReadonlyArray<WorkflowIR>, workflowCalls?: ReadonlyArray<WorkflowCallIR>, maskProcedures?: ReadonlyArray<MaskProcedureIR>, nondeterministicCalls?: ReadonlyArray<NondeterministicCallIR>, procedureProtections?: ReadonlyArray<ProcedureMiddlewareIR>, argumentValidators?: ReadonlyArray<ArgumentValidatorIR>, secretLiterals?: ReadonlyArray<SecretLiteralIR>, sqlInterpolations?: ReadonlyArray<SqlInterpolationIR>, adminRoutes?: ReadonlyArray<AdminRouteIR>) => Finding[];
709
+ declare const lintSchema: (schema: SchemaIR, queries?: ReadonlyArray<QueryReadIR>, inserts?: ReadonlyArray<InsertWriteIR>, authApiCalls?: ReadonlyArray<AuthApiCallIR>, rlsProcedures?: ReadonlyArray<RlsProcedureIR>, containers?: ReadonlyArray<ContainerIR>, workflows?: ReadonlyArray<WorkflowIR>, workflowCalls?: ReadonlyArray<WorkflowCallIR>, maskProcedures?: ReadonlyArray<MaskProcedureIR>, nondeterministicCalls?: ReadonlyArray<NondeterministicCallIR>, procedureProtections?: ReadonlyArray<ProcedureMiddlewareIR>, argumentValidators?: ReadonlyArray<ArgumentValidatorIR>, secretLiterals?: ReadonlyArray<SecretLiteralIR>, sqlInterpolations?: ReadonlyArray<SqlInterpolationIR>, adminRoutes?: ReadonlyArray<AdminRouteIR>, r2sqlCalls?: ReadonlyArray<R2sqlCallIR>) => Finding[];
690
710
  /**
691
711
  * Render advisor findings as a single multi-line string for console surfacing:
692
712
  * a one-line summary header followed by one `[LEVEL] name: detail` line per
@@ -803,6 +823,19 @@ declare const discoverNondeterministicCalls: (project: Project, lunoraDirectory:
803
823
  * dropping the rest keeps the lint input small.
804
824
  */
805
825
  declare const discoverQueries: (project: Project, lunoraDirectory: string) => QueryReadIR[];
826
+ /**
827
+ * Discover `ctx.r2sql` accesses lexically inside the handler body of every
828
+ * exported `query(...)` / `mutation(...)` registration under the lunora source
829
+ * directory — the `r2sql_outside_action` lint input. `action(...)` (and
830
+ * `stream(...)`) registrations are intentionally skipped: R2 SQL is the
831
+ * external, non-reactive surface that belongs in actions.
832
+ *
833
+ * Traversal is scoped to the handler node (not the whole declaration), mirroring
834
+ * `discoverNondeterministicCalls` — so a `ctx.r2sql` touch in a sibling helper
835
+ * outside the handler is not attributed to the query/mutation. One
836
+ * {@link R2sqlCallIR} is produced per access site.
837
+ */
838
+ declare const discoverR2sqlCalls: (project: Project, lunoraDirectory: string) => R2sqlCallIR[];
806
839
  declare const discoverRlsProcedures: (project: Project, lunoraDirectory: string) => RlsProcedureIR[];
807
840
  /**
808
841
  * Aggregate the schema-wide RLS metadata the studio's read-only inspector reads:
@@ -877,6 +910,8 @@ interface EmitServerOptions {
877
910
  hasPayments?: boolean;
878
911
  /** A `lunora/` source uses `@lunora/pipelines` / `ctx.pipelines` — wires `ctx.pipelines` onto ActionCtx only. */
879
912
  hasPipelines?: boolean;
913
+ /** A `lunora/` source uses `@lunora/r2sql` / `ctx.r2sql` — wires `ctx.r2sql` onto ActionCtx only. */
914
+ hasR2sql?: boolean;
880
915
  schema?: SchemaIR;
881
916
  storageRuleBuckets?: ReadonlyArray<string>;
882
917
  /** The project depends on the `lunora` umbrella — import base packages via its subpaths. */
@@ -893,6 +928,7 @@ declare const emitServer: ({
893
928
  hasKv,
894
929
  hasPayments,
895
930
  hasPipelines,
931
+ hasR2sql,
896
932
  schema,
897
933
  storageRuleBuckets,
898
934
  useUmbrella,
@@ -941,6 +977,8 @@ interface EmitShardOptions {
941
977
  /** A `lunora/` source reads `ctx.kv` — wires `ctx.kv` onto every ctx. */
942
978
  hasKv?: boolean;
943
979
  hasPayments?: boolean;
980
+ /** A `lunora/` source reads `ctx.r2sql` (R2 SQL) — wires `ctx.r2sql` onto the ActionCtx only. */
981
+ hasR2sql?: boolean;
944
982
  maskMetadata?: MaskMetadataIR;
945
983
  rlsMetadata?: RlsMetadataIR;
946
984
  schema: SchemaIR;
@@ -960,6 +998,7 @@ declare const emitShard: ({
960
998
  hasImages,
961
999
  hasKv,
962
1000
  hasPayments,
1001
+ hasR2sql,
963
1002
  maskMetadata,
964
1003
  rlsMetadata,
965
1004
  schema,
@@ -1049,6 +1088,8 @@ interface EmitAppOptions {
1049
1088
  hasKv: boolean;
1050
1089
  /** App uses `@lunora/payment` / `ctx.payments` → emit `.payment()`. */
1051
1090
  hasPayments: boolean;
1091
+ /** App uses `@lunora/r2sql` / `ctx.r2sql` → emit `.r2sql()`. */
1092
+ hasR2sql: boolean;
1052
1093
  /** App imports `@lunora/scheduler` / declares crons → emit `.scheduler()`. */
1053
1094
  hasScheduler: boolean;
1054
1095
  /** App uses `@lunora/storage` → emit `.storage()` (DO `ctx.storage` + studio file browser). */
@@ -1470,4 +1511,4 @@ declare const validatorIrToJsonSchema: (validator: ValidatorIR) => JsonSchema;
1470
1511
  */
1471
1512
  declare const LUNORA_ERROR_CODES: ReadonlyArray<string>;
1472
1513
  declare const VERSION = "0.0.0";
1473
- export { type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, type DriftChange, type EmitAppOptions, type FieldSnapshot, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type MaskProcedureIR, type MigrationIR, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, type ProjectIR, type QueryReadIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, diagnosticAt, diffSchemaSnapshots, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverNondeterministicCalls, discoverQueries, discoverRlsMetadata, discoverRlsProcedures, discoverSchema, discoverStorageRulesMetadata, discoverWorkflows, emitApi, emitApp, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, evaluateSchemaDrift, formatAdvisories, lintSchema, parseSchemaSnapshot, refreshCodegenProject, runCodegen, schemaFromIr, serializeSchemaSnapshot, validatorIrToJsonSchema };
1514
+ export { type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, type DriftChange, type EmitAppOptions, type FieldSnapshot, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type MaskProcedureIR, type MigrationIR, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, type ProjectIR, type QueryReadIR, type R2sqlCallIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, diagnosticAt, diffSchemaSnapshots, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverNondeterministicCalls, discoverQueries, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSchema, discoverStorageRulesMetadata, discoverWorkflows, emitApi, emitApp, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, evaluateSchemaDrift, formatAdvisories, lintSchema, parseSchemaSnapshot, refreshCodegenProject, runCodegen, schemaFromIr, serializeSchemaSnapshot, validatorIrToJsonSchema };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { formatAdvisories, lintSchema } from './packem_shared/lintSchema-DicbOHvH.mjs';
1
+ export { formatAdvisories, lintSchema } from './packem_shared/formatAdvisories-8NIv1k0I.mjs';
2
2
  export { CodegenDiagnosticError, diagnosticAt } from './packem_shared/CodegenDiagnosticError-54jWDxA9.mjs';
3
3
  export { default as discoverAuthApiCalls } from './packem_shared/discoverAuthApiCalls-C35R6z0T.mjs';
4
4
  export { CONTAINERS_FILENAME, discoverContainers } from './packem_shared/CONTAINERS_FILENAME-0K-pjNb8.mjs';
@@ -10,16 +10,17 @@ export { default as discoverMaskProcedures } from './packem_shared/discoverMaskP
10
10
  export { default as discoverMigrations } from './packem_shared/discoverMigrations-Doj_-BAA.mjs';
11
11
  export { default as discoverNondeterministicCalls } from './packem_shared/discoverNondeterministicCalls-4KiPQxQU.mjs';
12
12
  export { default as discoverQueries } from './packem_shared/discoverQueries-BkIi0dBD.mjs';
13
+ export { default as discoverR2sqlCalls } from './packem_shared/discoverR2sqlCalls-BpDqvcUn.mjs';
13
14
  export { discoverRlsMetadata, default as discoverRlsProcedures } from './packem_shared/discoverRlsMetadata-DpRB1HMe.mjs';
14
15
  export { default as discoverSchema } from './packem_shared/discoverSchema-BBulgGbH.mjs';
15
16
  export { default as discoverStorageRulesMetadata } from './packem_shared/discoverStorageRulesMetadata-DAqJUxUv.mjs';
16
- export { WORKFLOWS_FILENAME, discoverWorkflows } from './packem_shared/discoverWorkflows-DRDQdhfq.mjs';
17
- export { GENERATED_HEADER, emitApi, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers } from './packem_shared/emitApi-hRVC-kE7.mjs';
18
- export { emitApp } from './packem_shared/emitApp-CzZ6GbrD.mjs';
19
- export { buildOpenApiDocument, emitOpenApi, emitOpenApiModule } from './packem_shared/buildOpenApiDocument-yHVN66Xd.mjs';
20
- export { OPENRPC_VERSION, buildOpenRpcDocument, emitOpenRpc, emitOpenRpcModule } from './packem_shared/buildOpenRpcDocument-BZGY1-jT.mjs';
21
- export { SCHEMA_SNAPSHOT_FILENAME, createCodegenProject, refreshCodegenProject, runCodegen } from './packem_shared/createCodegenProject-DGJm0_Pk.mjs';
22
- export { SCHEMA_SNAPSHOT_VERSION, SchemaSnapshotParseError, buildSchemaSnapshot, diffSchemaSnapshots, evaluateSchemaDrift, parseSchemaSnapshot, serializeSchemaSnapshot } from './packem_shared/buildSchemaSnapshot-DzLDbWk3.mjs';
17
+ export { WORKFLOWS_FILENAME, discoverWorkflows } from './packem_shared/WORKFLOWS_FILENAME-DRDQdhfq.mjs';
18
+ export { GENERATED_HEADER, emitApi, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers } from './packem_shared/GENERATED_HEADER-CuLyj0WQ.mjs';
19
+ export { emitApp } from './packem_shared/emitApp-CzSxVDaG.mjs';
20
+ export { buildOpenApiDocument, emitOpenApi, emitOpenApiModule } from './packem_shared/buildOpenApiDocument-CXwnbp4b.mjs';
21
+ export { OPENRPC_VERSION, buildOpenRpcDocument, emitOpenRpc, emitOpenRpcModule } from './packem_shared/OPENRPC_VERSION-BGUrsrt_.mjs';
22
+ export { SCHEMA_SNAPSHOT_FILENAME, createCodegenProject, refreshCodegenProject, runCodegen } from './packem_shared/SCHEMA_SNAPSHOT_FILENAME-BQ_kCZ81.mjs';
23
+ export { SCHEMA_SNAPSHOT_VERSION, SchemaSnapshotParseError, buildSchemaSnapshot, diffSchemaSnapshots, evaluateSchemaDrift, parseSchemaSnapshot, serializeSchemaSnapshot } from './packem_shared/SCHEMA_SNAPSHOT_VERSION-DzLDbWk3.mjs';
23
24
  export { schemaFromIr } from './packem_shared/schemaFromIr-DTYsLBaA.mjs';
24
25
  export { LUNORA_ERROR_CODES, validatorIrToJsonSchema } from './packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs';
25
26
 
@@ -539,6 +539,7 @@ const emitServer = ({
539
539
  hasKv = false,
540
540
  hasPayments = false,
541
541
  hasPipelines = false,
542
+ hasR2sql = false,
542
543
  schema,
543
544
  storageRuleBuckets = [],
544
545
  useUmbrella = false,
@@ -612,6 +613,11 @@ export type Env = CloudflareBindings;`;
612
613
  const pipelinesActionField = hasPipelines ? `
613
614
  /** Pipelines ingestion sink (durable, R2-backed). Fire-and-forget and batched; do not read it back in-handler. */
614
615
  readonly pipelines: import("@lunora/pipelines").PipelineClient;` : "";
616
+ const r2sqlActionField = hasR2sql ? `
617
+ /**
618
+ * R2 SQL over Apache Iceberg tables (window functions, DISTINCT, set operations). Non-deterministic — available only in actions. Reads here are NOT tracked by Lunora live queries.
619
+ */
620
+ readonly r2sql: import("@lunora/r2sql").R2SqlClient;` : "";
615
621
  const hasWorkflows = workflows.length > 0;
616
622
  const workflowsTypeImport = hasWorkflows ? `import type { WorkflowHandle } from "@lunora/workflow";
617
623
  import type * as lunoraWorkflowDefinitions from "../workflows.js";
@@ -701,7 +707,7 @@ export interface MutationCtx extends Omit<MutationCtxBase, "db" | "storage"${wor
701
707
  export interface ActionCtx extends Omit<ActionCtxBase, "db" | "storage"${workflowsOmit}> {
702
708
  readonly db: Omit<DatabaseWriter, "query" | "get"> & DatabaseWriterFacade & { query: TypedTableQuery; get: TypedTableGet };
703
709
  readonly orm: OrmWriter;
704
- readonly storage: StorageBase<StorageBucketName>;${aiActionField}${paymentsActionField}${containersActionField}${kvContextField}${hyperdriveActionField}${browserActionField}${imagesActionField}${analyticsContextField}${pipelinesActionField}${workflowsContextField}
710
+ readonly storage: StorageBase<StorageBucketName>;${aiActionField}${paymentsActionField}${containersActionField}${kvContextField}${hyperdriveActionField}${browserActionField}${imagesActionField}${analyticsContextField}${pipelinesActionField}${r2sqlActionField}${workflowsContextField}
705
711
  }
706
712
 
707
713
  /**
@@ -1183,6 +1189,56 @@ const browserStub: Browser = {
1183
1189
  `
1184
1190
  };
1185
1191
  };
1192
+ const emitR2sqlFragments = (hasR2sql) => {
1193
+ if (!hasR2sql) {
1194
+ return EMPTY_HELPER_FRAGMENTS;
1195
+ }
1196
+ const r2sqlMissing = `throw new Error("ctx.r2sql: no R2 SQL credentials found. Set \\\`R2_SQL_TOKEN\\\`, \\\`R2_SQL_ACCOUNT_ID\\\` (or \\\`CLOUDFLARE_ACCOUNT_ID\\\`), and \\\`R2_SQL_BUCKET\\\` in your env/.dev.vars, or pass an \\\`r2sql\\\` config thunk to createShardDO().");`;
1197
+ return {
1198
+ build: `
1199
+ const r2sqlEnv = env as Record<string, unknown>;
1200
+ const r2sqlAccountId = (r2sqlEnv.R2_SQL_ACCOUNT_ID ?? r2sqlEnv.CLOUDFLARE_ACCOUNT_ID) as string | undefined;
1201
+ const r2sqlToken = r2sqlEnv.R2_SQL_TOKEN as string | undefined;
1202
+ const r2sqlBucket = r2sqlEnv.R2_SQL_BUCKET as string | undefined;
1203
+ const r2sql: R2SqlClient = config.r2sql
1204
+ ? config.r2sql(env)
1205
+ : r2sqlAccountId && r2sqlToken && r2sqlBucket
1206
+ ? createR2Sql({ accountId: r2sqlAccountId, apiToken: r2sqlToken, bucket: r2sqlBucket })
1207
+ : r2sqlStub;
1208
+ `,
1209
+ configField: `
1210
+ r2sql?: (env: Record<string, unknown>) => R2SqlClient;`,
1211
+ // ActionCtx-only: attached via the \`ctx.r2sql = r2sql\` assignment in the
1212
+ // \`isAction\` block, never the every-ctx object literal.
1213
+ contextField: "",
1214
+ importLines: [`import type { R2SqlClient } from "@lunora/r2sql";`, `import { createR2Sql } from "@lunora/r2sql";`],
1215
+ // The stub is typed `R2SqlClient`, so TS flags a missing method at build
1216
+ // time — but it must stay structurally in sync with that interface
1217
+ // (`@lunora/r2sql` client.ts) when a method is added there.
1218
+ stub: `
1219
+ const r2sqlStub: R2SqlClient = {
1220
+ describe: async () => {
1221
+ ${r2sqlMissing}
1222
+ },
1223
+ explain: async () => {
1224
+ ${r2sqlMissing}
1225
+ },
1226
+ from: () => {
1227
+ ${r2sqlMissing}
1228
+ },
1229
+ query: async () => {
1230
+ ${r2sqlMissing}
1231
+ },
1232
+ showDatabases: async () => {
1233
+ ${r2sqlMissing}
1234
+ },
1235
+ showTables: async () => {
1236
+ ${r2sqlMissing}
1237
+ },
1238
+ };
1239
+ `
1240
+ };
1241
+ };
1186
1242
  const emitContainers = (containers) => {
1187
1243
  if (containers.length === 0) {
1188
1244
  return "";
@@ -1420,6 +1476,7 @@ const emitShard = ({
1420
1476
  hasImages = false,
1421
1477
  hasKv = false,
1422
1478
  hasPayments = false,
1479
+ hasR2sql = false,
1423
1480
  maskMetadata,
1424
1481
  rlsMetadata,
1425
1482
  schema,
@@ -1435,6 +1492,7 @@ const emitShard = ({
1435
1492
  const imagesFragments = emitImagesFragments(hasImages);
1436
1493
  const hyperdriveFragments = emitHyperdriveFragments(hasHyperdrive);
1437
1494
  const browserFragments = emitBrowserFragments(hasBrowser);
1495
+ const r2sqlFragments = emitR2sqlFragments(hasR2sql);
1438
1496
  const {
1439
1497
  build: containersBuild,
1440
1498
  contextField: containersContextField,
@@ -1509,6 +1567,7 @@ const emitShard = ({
1509
1567
  ...imagesFragments.importLines,
1510
1568
  ...hyperdriveFragments.importLines,
1511
1569
  ...browserFragments.importLines,
1570
+ ...r2sqlFragments.importLines,
1512
1571
  ...containerImportLines,
1513
1572
  ...workflowImportLines,
1514
1573
  ...paymentsImports,
@@ -1654,15 +1713,16 @@ ${schema.tables.map(
1654
1713
  ` : "";
1655
1714
  const everyContextBuild = `${kvFragments.build}${analyticsFragments.build}`;
1656
1715
  const everyContextField = `${kvFragments.contextField}${analyticsFragments.contextField}`;
1657
- const actionOnlyHasAny = hasImages || hasHyperdrive || hasBrowser;
1716
+ const actionOnlyHasAny = hasImages || hasHyperdrive || hasBrowser || hasR2sql;
1658
1717
  const actionOnlyBlock = actionOnlyHasAny ? `
1659
1718
  // ActionCtx-only helpers (external, non-deterministic I/O): constructed
1660
1719
  // and attached only for an \`action\` so query/mutation ctx never carry them.
1661
1720
  if (isAction) {
1662
- ${imagesFragments.build}${hyperdriveFragments.build}${browserFragments.build}${[
1721
+ ${imagesFragments.build}${hyperdriveFragments.build}${browserFragments.build}${r2sqlFragments.build}${[
1663
1722
  ...hasImages ? [" ctx.images = images;"] : [],
1664
1723
  ...hasHyperdrive ? [" ctx.sql = sql;"] : [],
1665
- ...hasBrowser ? [" ctx.browser = browser;"] : []
1724
+ ...hasBrowser ? [" ctx.browser = browser;"] : [],
1725
+ ...hasR2sql ? [" ctx.r2sql = r2sql;"] : []
1666
1726
  ].join("\n")}
1667
1727
  }
1668
1728
  ` : "";
@@ -1709,7 +1769,7 @@ export interface ShardDOConfig {
1709
1769
  /** Optional telemetry sink. When supplied, each \`ctx.log.*\` call is forwarded to \`sink.onLog\`. Pass the SAME sink you give \`createWorker({ observability })\` (which drives \`onRpc\`) to route both RPC and log events. */
1710
1770
  observability?: (env: Record<string, unknown>) => LogSink | undefined;
1711
1771
  scheduler?: (env: Record<string, unknown>) => unknown;
1712
- storage?: (env: Record<string, unknown>) => unknown;${vectorsConfigField}${aiConfigField}${kvFragments.configField}${analyticsFragments.configField}${imagesFragments.configField}${hyperdriveFragments.configField}${browserFragments.configField}${paymentsConfigField}${d1ConfigField}${hyperdriveGlobalConfigField}
1772
+ storage?: (env: Record<string, unknown>) => unknown;${vectorsConfigField}${aiConfigField}${kvFragments.configField}${analyticsFragments.configField}${imagesFragments.configField}${hyperdriveFragments.configField}${browserFragments.configField}${r2sqlFragments.configField}${paymentsConfigField}${d1ConfigField}${hyperdriveGlobalConfigField}
1713
1773
  }
1714
1774
 
1715
1775
  const schedulerStub = {
@@ -1747,7 +1807,7 @@ const storageStub = {
1747
1807
  throw new Error("ctx.storage: no storage configured. Pass \`storage\` to createShardDO().");
1748
1808
  },
1749
1809
  };
1750
- ${globalDatabaseStub}${vectorsStub}${aiStub}${kvFragments.stub}${analyticsFragments.stub}${imagesFragments.stub}${hyperdriveFragments.stub}${browserFragments.stub}${paymentStub}${bindTableHelper}
1810
+ ${globalDatabaseStub}${vectorsStub}${aiStub}${kvFragments.stub}${analyticsFragments.stub}${imagesFragments.stub}${hyperdriveFragments.stub}${browserFragments.stub}${r2sqlFragments.stub}${paymentStub}${bindTableHelper}
1751
1811
  // Bound in-process \`ctx.run*\` composition depth so a self- or cyclically-
1752
1812
  // referencing call fails loudly with a clear error instead of overflowing the
1753
1813
  // stack. Tracked across the awaited handler chain (one DO invocation is
@@ -1,4 +1,4 @@
1
- import { GENERATED_HEADER } from './emitApi-hRVC-kE7.mjs';
1
+ import { GENERATED_HEADER } from './GENERATED_HEADER-CuLyj0WQ.mjs';
2
2
  import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
3
3
  import { argsObjectSchema, LUNORA_ERROR_CODES } from './LUNORA_ERROR_CODES-CySpQPD3.mjs';
4
4
 
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
2
2
  import { join, dirname } from 'node:path';
3
3
  import { Node, SyntaxKind, Project } from 'ts-morph';
4
- import { lintSchema } from './lintSchema-DicbOHvH.mjs';
4
+ import { lintSchema } from './formatAdvisories-8NIv1k0I.mjs';
5
5
  import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall, discoverFunctions } from './discoverFunctions-DEgAcRuD.mjs';
6
6
  import discoverAuthApiCalls from './discoverAuthApiCalls-C35R6z0T.mjs';
7
7
  import { discoverContainers } from './CONTAINERS_FILENAME-0K-pjNb8.mjs';
@@ -12,16 +12,17 @@ import discoverMaskProcedures, { discoverMaskMetadata } from './discoverMaskProc
12
12
  import discoverMigrations from './discoverMigrations-Doj_-BAA.mjs';
13
13
  import discoverNondeterministicCalls from './discoverNondeterministicCalls-4KiPQxQU.mjs';
14
14
  import discoverQueries from './discoverQueries-BkIi0dBD.mjs';
15
+ import discoverR2sqlCalls from './discoverR2sqlCalls-BpDqvcUn.mjs';
15
16
  import discoverRlsProcedures, { discoverRlsMetadata } from './discoverRlsMetadata-DpRB1HMe.mjs';
16
17
  import discoverSchema from './discoverSchema-BBulgGbH.mjs';
17
18
  import discoverStorageRulesMetadata from './discoverStorageRulesMetadata-DAqJUxUv.mjs';
18
19
  import { e as enclosingExportName$1 } from './discover-ast-CT6BgBr4.mjs';
19
- import { discoverWorkflows } from './discoverWorkflows-DRDQdhfq.mjs';
20
- import { buildStorageColumns, emitDataModel, emitApi, emitServer, emitFunctions, emitShard, emitContainers, emitWorkflows, emitCrons, emitVectors, emitDrizzleSchema, emitSeed, emitWranglerCronTriggers } from './emitApi-hRVC-kE7.mjs';
21
- import { emitApp } from './emitApp-CzZ6GbrD.mjs';
22
- import { buildOpenApiDocument, emitOpenApiModule } from './buildOpenApiDocument-yHVN66Xd.mjs';
23
- import { buildOpenRpcDocument, emitOpenRpcModule } from './buildOpenRpcDocument-BZGY1-jT.mjs';
24
- import { buildSchemaSnapshot, serializeSchemaSnapshot } from './buildSchemaSnapshot-DzLDbWk3.mjs';
20
+ import { discoverWorkflows } from './WORKFLOWS_FILENAME-DRDQdhfq.mjs';
21
+ import { buildStorageColumns, emitDataModel, emitApi, emitServer, emitFunctions, emitShard, emitContainers, emitWorkflows, emitCrons, emitVectors, emitDrizzleSchema, emitSeed, emitWranglerCronTriggers } from './GENERATED_HEADER-CuLyj0WQ.mjs';
22
+ import { emitApp } from './emitApp-CzSxVDaG.mjs';
23
+ import { buildOpenApiDocument, emitOpenApiModule } from './buildOpenApiDocument-CXwnbp4b.mjs';
24
+ import { buildOpenRpcDocument, emitOpenRpcModule } from './OPENRPC_VERSION-BGUrsrt_.mjs';
25
+ import { buildSchemaSnapshot, serializeSchemaSnapshot } from './SCHEMA_SNAPSHOT_VERSION-DzLDbWk3.mjs';
25
26
 
26
27
  const HTTP_VERBS = /* @__PURE__ */ new Set(["delete", "get", "head", "options", "patch", "post", "put"]);
27
28
  const TERMINAL_STEPS = /* @__PURE__ */ new Set(["handler", "stream"]);
@@ -246,6 +247,7 @@ const PROBES = {
246
247
  mail: { moduleSpecifier: "@lunora/mail" },
247
248
  payments: { contextProperty: "payments", moduleSpecifier: "@lunora/payment" },
248
249
  pipelines: { contextProperty: "pipelines", moduleSpecifier: "@lunora/pipelines" },
250
+ r2sql: { contextProperty: "r2sql", moduleSpecifier: "@lunora/r2sql" },
249
251
  scheduler: { contextProperty: "scheduler", moduleSpecifier: "@lunora/scheduler" },
250
252
  storage: { contextProperty: "storage", moduleSpecifier: "@lunora/storage" },
251
253
  vectors: { contextProperty: "vectors", moduleSpecifier: "@lunora/vectors" },
@@ -277,6 +279,7 @@ const discoverFeatureUsage = (project, lunoraDirectory) => {
277
279
  mail: false,
278
280
  payments: false,
279
281
  pipelines: false,
282
+ r2sql: false,
280
283
  scheduler: false,
281
284
  storage: false,
282
285
  vectors: false,
@@ -723,7 +726,8 @@ const runCodegen = (options) => {
723
726
  discoverArgumentValidators(project, lunoraDirectory),
724
727
  discoverSecrets(project, lunoraDirectory),
725
728
  discoverSqlInterpolation(project, lunoraDirectory),
726
- discoverAdminRoutes(project, lunoraDirectory)
729
+ discoverAdminRoutes(project, lunoraDirectory),
730
+ discoverR2sqlCalls(project, lunoraDirectory)
727
731
  );
728
732
  const rlsMetadata = discoverRlsMetadata(project, lunoraDirectory);
729
733
  const maskMetadata = discoverMaskMetadata(project, lunoraDirectory);
@@ -737,6 +741,7 @@ const runCodegen = (options) => {
737
741
  const hasImages = featureUsage.images;
738
742
  const hasAnalytics = featureUsage.analytics;
739
743
  const hasPipelines = featureUsage.pipelines;
744
+ const hasR2sql = featureUsage.r2sql;
740
745
  const dependencies = discoverPackageDependencies(options.projectRoot);
741
746
  const studioFeatures = buildStudioFeatures(featureUsage, {
742
747
  cronCount: crons.length,
@@ -759,6 +764,7 @@ const runCodegen = (options) => {
759
764
  hasKv,
760
765
  hasPayments,
761
766
  hasPipelines,
767
+ hasR2sql,
762
768
  schema,
763
769
  storageRuleBuckets: storageRulesMetadata.rules.map((rule) => rule.bucket),
764
770
  useUmbrella,
@@ -775,6 +781,7 @@ const runCodegen = (options) => {
775
781
  hasImages,
776
782
  hasKv,
777
783
  hasPayments,
784
+ hasR2sql,
778
785
  maskMetadata,
779
786
  rlsMetadata,
780
787
  schema,
@@ -809,6 +816,7 @@ const runCodegen = (options) => {
809
816
  hasImages,
810
817
  hasKv,
811
818
  hasPayments,
819
+ hasR2sql,
812
820
  hasScheduler: studioFeatures.scheduler,
813
821
  hasStorage: studioFeatures.storage,
814
822
  hasVectors: schema.vectorIndexes.length > 0,
@@ -1,4 +1,4 @@
1
- import { GENERATED_HEADER } from './emitApi-hRVC-kE7.mjs';
1
+ import { GENERATED_HEADER } from './GENERATED_HEADER-CuLyj0WQ.mjs';
2
2
  import { s as sanitizeNamespace } from './paths-BRd6JHuF.mjs';
3
3
  import { LUNORA_ERROR_CODES, objectSchema, argsObjectSchema, validatorIrToJsonSchema } from './LUNORA_ERROR_CODES-CySpQPD3.mjs';
4
4
 
@@ -0,0 +1,80 @@
1
+ import { Node, SyntaxKind } from 'ts-morph';
2
+ import { listLunoraSourceFiles, lunoraRelativePath, classifyProcedureCall } from './discoverFunctions-DEgAcRuD.mjs';
3
+
4
+ const handlerOf = (call, receiver) => {
5
+ if (receiver) {
6
+ const handler = call.getArguments()[0];
7
+ return handler && (Node.isArrowFunction(handler) || Node.isFunctionExpression(handler)) ? handler : void 0;
8
+ }
9
+ const first = call.getArguments()[0];
10
+ if (!first || !Node.isObjectLiteralExpression(first)) {
11
+ return void 0;
12
+ }
13
+ const handlerProperty = first.getProperty("handler");
14
+ if (!handlerProperty || !Node.isPropertyAssignment(handlerProperty)) {
15
+ return void 0;
16
+ }
17
+ const initializer = handlerProperty.getInitializer();
18
+ return initializer && (Node.isArrowFunction(initializer) || Node.isFunctionExpression(initializer)) ? initializer : void 0;
19
+ };
20
+ const exportedProcedureHandler = (declaration) => {
21
+ const initializer = declaration.getInitializer();
22
+ if (!initializer || !Node.isCallExpression(initializer)) {
23
+ return void 0;
24
+ }
25
+ const classified = classifyProcedureCall(initializer);
26
+ if (!classified || classified.kind !== "query" && classified.kind !== "mutation") {
27
+ return void 0;
28
+ }
29
+ const handler = handlerOf(initializer, classified.receiver);
30
+ return handler ? { exportName: declaration.getName(), handler, kind: classified.kind } : void 0;
31
+ };
32
+ const r2sqlCalleeOf = (access) => {
33
+ if (!Node.isPropertyAccessExpression(access) || access.getName() !== "r2sql") {
34
+ return void 0;
35
+ }
36
+ const receiver = access.getExpression();
37
+ if (!Node.isIdentifier(receiver) || receiver.getText() !== "ctx") {
38
+ return void 0;
39
+ }
40
+ const parent = access.getParent();
41
+ if (parent && Node.isPropertyAccessExpression(parent) && parent.getExpression() === access) {
42
+ return `ctx.r2sql.${parent.getName()}`;
43
+ }
44
+ return "ctx.r2sql";
45
+ };
46
+ const accessesInHandler = (procedure, file) => {
47
+ const found = [];
48
+ for (const access of procedure.handler.getDescendantsOfKind(SyntaxKind.PropertyAccessExpression)) {
49
+ const callee = r2sqlCalleeOf(access);
50
+ if (callee !== void 0) {
51
+ found.push({ callee, exportName: procedure.exportName, file, kind: procedure.kind, line: access.getStartLineNumber() });
52
+ }
53
+ }
54
+ return found;
55
+ };
56
+ const accessesInSourceFile = (sourceFile, relativePath) => {
57
+ const found = [];
58
+ for (const statement of sourceFile.getVariableStatements()) {
59
+ if (!statement.isExported()) {
60
+ continue;
61
+ }
62
+ for (const declaration of statement.getDeclarations()) {
63
+ const procedure = exportedProcedureHandler(declaration);
64
+ if (procedure) {
65
+ found.push(...accessesInHandler(procedure, relativePath));
66
+ }
67
+ }
68
+ }
69
+ return found;
70
+ };
71
+ const discoverR2sqlCalls = (project, lunoraDirectory) => {
72
+ const calls = [];
73
+ for (const filePath of listLunoraSourceFiles(lunoraDirectory)) {
74
+ const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPath(filePath);
75
+ calls.push(...accessesInSourceFile(sourceFile, lunoraRelativePath(lunoraDirectory, filePath)));
76
+ }
77
+ return calls;
78
+ };
79
+
80
+ export { discoverR2sqlCalls as default };
@@ -1,4 +1,4 @@
1
- import { GENERATED_HEADER } from './emitApi-hRVC-kE7.mjs';
1
+ import { GENERATED_HEADER } from './GENERATED_HEADER-CuLyj0WQ.mjs';
2
2
 
3
3
  const LONG_TAIL = [
4
4
  ["hasAi", "ai", "ai", "Override the Workers AI binding backing `ctx.ai` (defaults to `env.AI`)."],
@@ -13,6 +13,12 @@ const LONG_TAIL = [
13
13
  ["hasImages", "images", "images", "Override the Images binding backing `ctx.images` (defaults to `env.IMAGES`)."],
14
14
  ["hasKv", "kv", "kv", "Override the Workers KV binding backing `ctx.kv` (defaults to `env.KV`)."],
15
15
  ["hasPayments", "payment", "payment", "Wire the payment options backing `ctx.payments`."],
16
+ [
17
+ "hasR2sql",
18
+ "r2sql",
19
+ "r2sql",
20
+ "Wire the R2 SQL client backing `ctx.r2sql` — build it with `createR2Sql({ accountId, apiToken, bucket })` (defaults to env `R2_SQL_TOKEN` / `R2_SQL_ACCOUNT_ID` / `R2_SQL_BUCKET`)."
21
+ ],
16
22
  ["hasVectors", "vectors", "vectors", "Wire the Vectorize index map backing `ctx.vectors`."]
17
23
  ];
18
24
  const hasAnyLongTail = (options) => LONG_TAIL.some(([flag]) => options[flag]);
@@ -36,7 +36,7 @@ const toAdvisorSchema = (schema) => {
36
36
  })
37
37
  };
38
38
  };
39
- const lintSchema = (schema, queries = [], inserts, authApiCalls, rlsProcedures, containers, workflows, workflowCalls, maskProcedures, nondeterministicCalls, procedureProtections, argumentValidators, secretLiterals, sqlInterpolations, adminRoutes) => runAdvisor(
39
+ const lintSchema = (schema, queries = [], inserts, authApiCalls, rlsProcedures, containers, workflows, workflowCalls, maskProcedures, nondeterministicCalls, procedureProtections, argumentValidators, secretLiterals, sqlInterpolations, adminRoutes, r2sqlCalls) => runAdvisor(
40
40
  {
41
41
  adminRoutes,
42
42
  argValidators: argumentValidators,
@@ -47,6 +47,7 @@ const lintSchema = (schema, queries = [], inserts, authApiCalls, rlsProcedures,
47
47
  nondeterministicCalls,
48
48
  procedureProtections,
49
49
  queries,
50
+ r2sqlCalls,
50
51
  rlsProcedures,
51
52
  schema: toAdvisorSchema(schema),
52
53
  secretLiterals,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/codegen",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.3",
4
4
  "description": "Code generator for Lunora: emits _generated/{api,server,dataModel}.ts from your schema",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -46,7 +46,7 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@lunora/advisor": "1.0.0-alpha.1",
49
+ "@lunora/advisor": "1.0.0-alpha.2",
50
50
  "@lunora/container": "1.0.0-alpha.1",
51
51
  "@lunora/scheduler": "1.0.0-alpha.1",
52
52
  "@lunora/values": "1.0.0-alpha.1",