@lunora/codegen 1.0.0-alpha.16 → 1.0.0-alpha.18

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
@@ -201,6 +201,59 @@ interface MigrationIR {
201
201
  table: string;
202
202
  }
203
203
  /**
204
+ * A `defineShape({...})` declaration discovered in `lunora/shapes.ts`
205
+ * (local-first sync engine, Phase 7). The emitted `LUNORA_SHAPES` registry keys
206
+ * on {@link ShapeIR.exportName}; the generated DO's `resolveShape` override
207
+ * dispatches a `shape_subscribe` to the matching registered shape. Discovery is
208
+ * marker-driven (the `__lunoraShape` brand) — no field metadata is lifted here
209
+ * because the runtime object (`columns`/`compileWhere`) carries the authority.
210
+ */
211
+ interface ShapeIR {
212
+ /** Export binding name — the shape's registry key and import member. */
213
+ exportName: string;
214
+ /** Path relative to `<projectRoot>/lunora/` without extension — always `"shapes"`. */
215
+ filePath: string;
216
+ /**
217
+ * The `table` string literal from the `defineShape({ table })` call, lifted
218
+ * only for static advisor lints (the runtime object stays authoritative).
219
+ * `undefined` when `table` is not a plain string literal — lints skip those.
220
+ */
221
+ table?: string;
222
+ }
223
+ /**
224
+ * A `defineMutator({...})` declaration discovered in `lunora/mutators.ts`
225
+ * (local-first sync engine, Phase 7). The emitted registry registers the
226
+ * authoritative `server` impl into the DO's `LUNORA_FUNCTIONS` table (so
227
+ * `handleRpc` transaction-wraps it) and records its path in
228
+ * `LUNORA_MUTATOR_PATHS` so the DO's `isCustomMutator` override routes the
229
+ * client-watermark push protocol. The client `client` impl is split into the
230
+ * browser bundle separately — only the path crosses to the server side.
231
+ */
232
+ interface MutatorIR {
233
+ /** Export binding name — the mutator's registry key and import member. */
234
+ exportName: string;
235
+ /** Path relative to `<projectRoot>/lunora/` without extension — always `"mutators"`. */
236
+ filePath: string;
237
+ }
238
+ /**
239
+ * A whole-row `ctx.db.replace(id, document)` write discovered inside a custom
240
+ * mutator's inline `server` impl (`lunora/mutators.ts`) — the input the
241
+ * `mutator_full_row_replace` advisor lint consumes. A `replace` overwrites the
242
+ * entire row, so a concurrent edit to a different column on a synced table is
243
+ * clobbered; `ctx.db.patch(id, { field })` merges at the column level instead.
244
+ * Structurally identical to `AdvisorMutatorWrite` so it passes straight through
245
+ * to the advisor without conversion, exactly as `InsertWriteIR` does for
246
+ * `AdvisorInsertWrite`.
247
+ */
248
+ interface MutatorWriteIR {
249
+ /** The mutator export whose `server` impl performs the replace, e.g. `renameChannel`. */
250
+ exportName: string;
251
+ /** Openable source path the replace appears in — always `lunora/mutators.ts`. */
252
+ file: string;
253
+ /** 1-based line of the `replace(...)` call. */
254
+ line: number;
255
+ }
256
+ /**
204
257
  * A single cron job lifted from a `cronJobs()` builder in `lunora/crons.ts`.
205
258
  * Mirrors `@lunora/scheduler`'s `CronJob`: {@link CronJobIR.cron} is the compiled
206
259
  * standard cron expression, {@link CronJobIR.functionPath} is the target
@@ -783,7 +836,7 @@ interface ProjectIR {
783
836
  * pass straight through without conversion. Returns the findings; surfacing them
784
837
  * (console, error overlay, studio Advisors table) is the caller's choice.
785
838
  */
786
- 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[];
839
+ 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>, shapes?: ReadonlyArray<ShapeIR>, mutatorWrites?: ReadonlyArray<MutatorWriteIR>) => Finding[];
787
840
  /**
788
841
  * Render advisor findings as a single multi-line string for console surfacing:
789
842
  * a one-line summary header followed by one `[LEVEL] name: detail` line per
@@ -898,6 +951,23 @@ declare const discoverMaskProcedures: (project: Project, lunoraDirectory: string
898
951
  * key); `table` is best-effort and left `""` when not a literal.
899
952
  */
900
953
  declare const discoverMigrations: (project: Project, lunoraDirectory: string) => MigrationIR[];
954
+ /** The only file custom mutators may be declared in — mirrors `lunora/queues.ts`. */
955
+ declare const MUTATORS_FILENAME = "mutators.ts";
956
+ /**
957
+ * Decide whether a call's callee is `defineMutator` — either the bare imported
958
+ * identifier (`defineMutator(...)`) or a namespace member access
959
+ * (`server.defineMutator(...)`). Both are valid ES module syntax, so discovery
960
+ * must see mutators declared either way.
961
+ */
962
+
963
+ /**
964
+ * Discover every custom mutator the project declares: exported
965
+ * `defineMutator()` calls in `lunora/mutators.ts`. Returns `[]` when the file
966
+ * doesn't exist. Only the export binding is lifted — the runtime object carries
967
+ * the authoritative `server` impl + `handler`, so codegen never evaluates the
968
+ * body. The client `client` impl is split into the browser bundle separately.
969
+ */
970
+ declare const discoverMutators: (project: Project, lunoraDirectory: string) => MutatorIR[];
901
971
  /**
902
972
  * Discover non-deterministic API calls (`Date.now`, `new Date()`, `Date()`,
903
973
  * `Math.random`, `crypto.randomUUID`, `crypto.getRandomValues` — including
@@ -963,6 +1033,16 @@ declare const discoverRlsMetadata: (project: Project, lunoraDirectory: string) =
963
1033
  * return a structural IR. Throws if the file or call cannot be found.
964
1034
  */
965
1035
  declare const discoverSchema: (project: Project, schemaPath: string, projectRoot?: string) => SchemaIR;
1036
+ /** The only file shapes may be declared in — mirrors `lunora/queues.ts`. */
1037
+ declare const SHAPES_FILENAME = "shapes.ts";
1038
+ /**
1039
+ * Discover every replication shape the project declares: exported
1040
+ * `defineShape()` calls in `lunora/shapes.ts`. Returns `[]` when the file
1041
+ * doesn't exist. Only the export binding is lifted — the runtime object carries
1042
+ * the authoritative `table`/`columns`/`compileWhere`, so codegen never
1043
+ * evaluates the predicate.
1044
+ */
1045
+ declare const discoverShapes: (project: Project, lunoraDirectory: string) => ShapeIR[];
966
1046
  /**
967
1047
  * Aggregate the schema-wide storage-rule metadata the studio's inspector reads:
968
1048
  * every statically-discovered `(bucket, on, prefix, procedure)` entry across all
@@ -1001,8 +1081,31 @@ declare const emitApi: (functions: ReadonlyArray<FunctionIR>, workflows?: Readon
1001
1081
  * Returns `""` when `@lunora/seed` is not a declared dependency, so projects
1002
1082
  * that don't use it keep a clean `_generated/` and never import the package.
1003
1083
  */
1084
+
1085
+ /**
1086
+ * Emit `_generated/collections.ts` — one TanStack DB collection factory per
1087
+ * `defineShape` in `lunora/shapes.ts` (the local-first partial-replication
1088
+ * surface). Each factory builds a live collection that syncs its shape's rowset
1089
+ * through the client's poke protocol (`subscribeShape`), so an app feeds the
1090
+ * result straight to `useLiveQuery`.
1091
+ *
1092
+ * Returns `""` (so `writeIfPresent` skips the file) unless the project both
1093
+ * declares shapes AND installs `@lunora/db` — the add-on that ships
1094
+ * `lunoraCollectionOptions`. `@lunora/db` stays a scoped install even under the
1095
+ * `lunorash` umbrella (an opt-in add-on, like `@lunora/auth`), so its import is
1096
+ * always `@lunora/db/collections`; only the in-umbrella `@lunora/client` import
1097
+ * is remapped to `lunorash/client`.
1098
+ */
1099
+ declare const emitCollections: (shapes: ReadonlyArray<ShapeIR>, hasDatabase: boolean, useUmbrella?: boolean) => string;
1004
1100
  interface EmitServerOptions {
1005
1101
  containers?: ReadonlyArray<ContainerIR>;
1102
+ /**
1103
+ * A `lunora/` source reads `ctx.access` — wires the verified Cloudflare Access
1104
+ * facade (`@lunora/cloudflare-access/context`) onto every ctx. Distinct from
1105
+ * `emitApp`'s `hasAccess` (which gates the worker's `.access()` resolveIdentity
1106
+ * method); this one gates the per-request `ctx.access` read surface.
1107
+ */
1108
+ hasAccessFacade?: boolean;
1006
1109
  hasAi?: boolean;
1007
1110
  /** A `lunora/` source uses `@lunora/bindings/analytics` / `ctx.analytics` — wires the write helper onto every ctx. */
1008
1111
  hasAnalytics?: boolean;
@@ -1031,6 +1134,7 @@ interface EmitServerOptions {
1031
1134
  }
1032
1135
  declare const emitServer: ({
1033
1136
  containers,
1137
+ hasAccessFacade,
1034
1138
  hasAi,
1035
1139
  hasAnalytics,
1036
1140
  hasBrowser,
@@ -1047,7 +1151,7 @@ declare const emitServer: ({
1047
1151
  useUmbrella,
1048
1152
  workflows
1049
1153
  }?: EmitServerOptions) => string;
1050
- declare const emitFunctions: (functions: ReadonlyArray<FunctionIR>, migrations?: ReadonlyArray<MigrationIR>, useUmbrella?: boolean) => string;
1154
+ declare const emitFunctions: (functions: ReadonlyArray<FunctionIR>, migrations?: ReadonlyArray<MigrationIR>, useUmbrella?: boolean, mutators?: ReadonlyArray<MutatorIR>, shapes?: ReadonlyArray<ShapeIR>) => string;
1051
1155
  /**
1052
1156
  * Storage-column map per table for the file browser: `{ table: [field, …] }` for
1053
1157
  * every field declared `v.storage(...)` (unwrapping `v.optional(...)`). The
@@ -1091,6 +1195,8 @@ interface EmitShardOptions {
1091
1195
  key: string;
1092
1196
  type: "boolean" | "number" | "object" | "string";
1093
1197
  }>;
1198
+ /** A `lunora/` source reads `ctx.access` — wires the verified Cloudflare Access facade onto every ctx. */
1199
+ hasAccessFacade?: boolean;
1094
1200
  hasAi?: boolean;
1095
1201
  /** A `lunora/` source reads `ctx.analytics` — wires the Analytics Engine write helper onto every ctx. */
1096
1202
  hasAnalytics?: boolean;
@@ -1110,10 +1216,14 @@ interface EmitShardOptions {
1110
1216
  /** A `lunora/` source reads `ctx.r2sql` (R2 SQL) — wires `ctx.r2sql` onto the ActionCtx only. */
1111
1217
  hasR2sql?: boolean;
1112
1218
  maskMetadata?: MaskMetadataIR;
1219
+ /** Custom mutators declared via `defineMutator` in `lunora/mutators.ts` — wires the `isCustomMutator` push-protocol override. */
1220
+ mutators?: ReadonlyArray<MutatorIR>;
1113
1221
  /** Queues declared via `defineQueue` exports in `lunora/queues.ts` — wires the typed `ctx.queues` producers. */
1114
1222
  queues?: ReadonlyArray<QueueIR>;
1115
1223
  rlsMetadata?: RlsMetadataIR;
1116
1224
  schema: SchemaIR;
1225
+ /** Replication shapes declared via `defineShape` in `lunora/shapes.ts` — wires the `resolveShape` subscription override. */
1226
+ shapes?: ReadonlyArray<ShapeIR>;
1117
1227
  storageRules?: StorageRulesMetadataIR;
1118
1228
  studioFeatures?: StudioFeaturesResult;
1119
1229
  /** The project depends on the `lunora` umbrella — import base packages via its subpaths. */
@@ -1124,6 +1234,7 @@ declare const emitShard: ({
1124
1234
  advisories,
1125
1235
  containers,
1126
1236
  flagKeys,
1237
+ hasAccessFacade,
1127
1238
  hasAi,
1128
1239
  hasAnalytics,
1129
1240
  hasBrowser,
@@ -1135,9 +1246,11 @@ declare const emitShard: ({
1135
1246
  hasPipelines,
1136
1247
  hasR2sql,
1137
1248
  maskMetadata,
1249
+ mutators,
1138
1250
  queues,
1139
1251
  rlsMetadata,
1140
1252
  schema,
1253
+ shapes,
1141
1254
  storageRules,
1142
1255
  studioFeatures,
1143
1256
  useUmbrella,
@@ -1202,6 +1315,8 @@ declare const emitVectors: (vectorIndexes: ReadonlyArray<VectorIndexIR>) => stri
1202
1315
  declare const emitWranglerCronTriggers: (crons: ReadonlyArray<CronJobIR>) => string[];
1203
1316
  /** Which capability methods the generated `defineApp` builder exposes — one flag per package-backed feature the app actually uses. */
1204
1317
  interface EmitAppOptions {
1318
+ /** App depends on `@lunora/cloudflare-access` → emit `.access()` (wire the Cloudflare Access `resolveIdentity`, composed ahead of `@lunora/auth` when both are present). */
1319
+ hasAccess: boolean;
1205
1320
  /** App uses `@lunora/ai` / `ctx.ai` → emit `.ai()` (override the Workers AI binding backing `ctx.ai`). */
1206
1321
  hasAi: boolean;
1207
1322
  /** App uses `@lunora/bindings/analytics` / `ctx.analytics` → emit `.analytics()` (override the dataset backing `ctx.analytics`). */
@@ -1591,6 +1706,8 @@ interface CodegenResult {
1591
1706
  generated: {
1592
1707
  api: string; /** Fluent worker-composition builder (`_generated/app.ts`) — `defineApp()`. Always written. */
1593
1708
  app: string;
1709
+ /** Partial-replication collection factories (`_generated/collections.ts`); `""` (and not written) unless the project declares shapes and installs `@lunora/db`. */
1710
+ collections: string;
1594
1711
  /** Container DO classes (`_generated/containers.ts`); `""` (and not written) when no containers are declared. */
1595
1712
  containers: string;
1596
1713
  crons: string;
@@ -1725,4 +1842,4 @@ declare const LUNORA_SOLUTION_RULES: ReadonlyArray<LunoraSolutionRule>;
1725
1842
  */
1726
1843
  declare const findLunoraSolution: (message: string) => LunoraSolution | undefined;
1727
1844
  declare const VERSION = "0.0.0";
1728
- export { type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, type DriftChange, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, LUNORA_SOLUTION_RULES, type LunoraSolution, type LunoraSolutionRule, type MaskProcedureIR, type MigrationIR, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, 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, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverNondeterministicCalls, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSchema, discoverStorageRulesMetadata, discoverWorkflows, emitApi, emitApp, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, evaluateSchemaDrift, findLunoraSolution, formatAdvisories, lintSchema, parseSchemaSnapshot, refreshCodegenProject, runCodegen, schemaFromIr, serializeSchemaSnapshot, validatorIrToJsonSchema };
1845
+ export { type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, type DriftChange, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, LUNORA_SOLUTION_RULES, type LunoraSolution, type LunoraSolutionRule, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type R2sqlCallIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SHAPES_FILENAME, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type ShapeIR, 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, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, evaluateSchemaDrift, findLunoraSolution, formatAdvisories, lintSchema, parseSchemaSnapshot, refreshCodegenProject, runCodegen, schemaFromIr, serializeSchemaSnapshot, validatorIrToJsonSchema };
package/dist/index.d.ts CHANGED
@@ -201,6 +201,59 @@ interface MigrationIR {
201
201
  table: string;
202
202
  }
203
203
  /**
204
+ * A `defineShape({...})` declaration discovered in `lunora/shapes.ts`
205
+ * (local-first sync engine, Phase 7). The emitted `LUNORA_SHAPES` registry keys
206
+ * on {@link ShapeIR.exportName}; the generated DO's `resolveShape` override
207
+ * dispatches a `shape_subscribe` to the matching registered shape. Discovery is
208
+ * marker-driven (the `__lunoraShape` brand) — no field metadata is lifted here
209
+ * because the runtime object (`columns`/`compileWhere`) carries the authority.
210
+ */
211
+ interface ShapeIR {
212
+ /** Export binding name — the shape's registry key and import member. */
213
+ exportName: string;
214
+ /** Path relative to `&lt;projectRoot>/lunora/` without extension — always `"shapes"`. */
215
+ filePath: string;
216
+ /**
217
+ * The `table` string literal from the `defineShape({ table })` call, lifted
218
+ * only for static advisor lints (the runtime object stays authoritative).
219
+ * `undefined` when `table` is not a plain string literal — lints skip those.
220
+ */
221
+ table?: string;
222
+ }
223
+ /**
224
+ * A `defineMutator({...})` declaration discovered in `lunora/mutators.ts`
225
+ * (local-first sync engine, Phase 7). The emitted registry registers the
226
+ * authoritative `server` impl into the DO's `LUNORA_FUNCTIONS` table (so
227
+ * `handleRpc` transaction-wraps it) and records its path in
228
+ * `LUNORA_MUTATOR_PATHS` so the DO's `isCustomMutator` override routes the
229
+ * client-watermark push protocol. The client `client` impl is split into the
230
+ * browser bundle separately — only the path crosses to the server side.
231
+ */
232
+ interface MutatorIR {
233
+ /** Export binding name — the mutator's registry key and import member. */
234
+ exportName: string;
235
+ /** Path relative to `&lt;projectRoot>/lunora/` without extension — always `"mutators"`. */
236
+ filePath: string;
237
+ }
238
+ /**
239
+ * A whole-row `ctx.db.replace(id, document)` write discovered inside a custom
240
+ * mutator's inline `server` impl (`lunora/mutators.ts`) — the input the
241
+ * `mutator_full_row_replace` advisor lint consumes. A `replace` overwrites the
242
+ * entire row, so a concurrent edit to a different column on a synced table is
243
+ * clobbered; `ctx.db.patch(id, { field })` merges at the column level instead.
244
+ * Structurally identical to `AdvisorMutatorWrite` so it passes straight through
245
+ * to the advisor without conversion, exactly as `InsertWriteIR` does for
246
+ * `AdvisorInsertWrite`.
247
+ */
248
+ interface MutatorWriteIR {
249
+ /** The mutator export whose `server` impl performs the replace, e.g. `renameChannel`. */
250
+ exportName: string;
251
+ /** Openable source path the replace appears in — always `lunora/mutators.ts`. */
252
+ file: string;
253
+ /** 1-based line of the `replace(...)` call. */
254
+ line: number;
255
+ }
256
+ /**
204
257
  * A single cron job lifted from a `cronJobs()` builder in `lunora/crons.ts`.
205
258
  * Mirrors `@lunora/scheduler`'s `CronJob`: {@link CronJobIR.cron} is the compiled
206
259
  * standard cron expression, {@link CronJobIR.functionPath} is the target
@@ -783,7 +836,7 @@ interface ProjectIR {
783
836
  * pass straight through without conversion. Returns the findings; surfacing them
784
837
  * (console, error overlay, studio Advisors table) is the caller's choice.
785
838
  */
786
- 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[];
839
+ 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>, shapes?: ReadonlyArray<ShapeIR>, mutatorWrites?: ReadonlyArray<MutatorWriteIR>) => Finding[];
787
840
  /**
788
841
  * Render advisor findings as a single multi-line string for console surfacing:
789
842
  * a one-line summary header followed by one `[LEVEL] name: detail` line per
@@ -898,6 +951,23 @@ declare const discoverMaskProcedures: (project: Project, lunoraDirectory: string
898
951
  * key); `table` is best-effort and left `""` when not a literal.
899
952
  */
900
953
  declare const discoverMigrations: (project: Project, lunoraDirectory: string) => MigrationIR[];
954
+ /** The only file custom mutators may be declared in — mirrors `lunora/queues.ts`. */
955
+ declare const MUTATORS_FILENAME = "mutators.ts";
956
+ /**
957
+ * Decide whether a call's callee is `defineMutator` — either the bare imported
958
+ * identifier (`defineMutator(...)`) or a namespace member access
959
+ * (`server.defineMutator(...)`). Both are valid ES module syntax, so discovery
960
+ * must see mutators declared either way.
961
+ */
962
+
963
+ /**
964
+ * Discover every custom mutator the project declares: exported
965
+ * `defineMutator()` calls in `lunora/mutators.ts`. Returns `[]` when the file
966
+ * doesn't exist. Only the export binding is lifted — the runtime object carries
967
+ * the authoritative `server` impl + `handler`, so codegen never evaluates the
968
+ * body. The client `client` impl is split into the browser bundle separately.
969
+ */
970
+ declare const discoverMutators: (project: Project, lunoraDirectory: string) => MutatorIR[];
901
971
  /**
902
972
  * Discover non-deterministic API calls (`Date.now`, `new Date()`, `Date()`,
903
973
  * `Math.random`, `crypto.randomUUID`, `crypto.getRandomValues` — including
@@ -963,6 +1033,16 @@ declare const discoverRlsMetadata: (project: Project, lunoraDirectory: string) =
963
1033
  * return a structural IR. Throws if the file or call cannot be found.
964
1034
  */
965
1035
  declare const discoverSchema: (project: Project, schemaPath: string, projectRoot?: string) => SchemaIR;
1036
+ /** The only file shapes may be declared in — mirrors `lunora/queues.ts`. */
1037
+ declare const SHAPES_FILENAME = "shapes.ts";
1038
+ /**
1039
+ * Discover every replication shape the project declares: exported
1040
+ * `defineShape()` calls in `lunora/shapes.ts`. Returns `[]` when the file
1041
+ * doesn't exist. Only the export binding is lifted — the runtime object carries
1042
+ * the authoritative `table`/`columns`/`compileWhere`, so codegen never
1043
+ * evaluates the predicate.
1044
+ */
1045
+ declare const discoverShapes: (project: Project, lunoraDirectory: string) => ShapeIR[];
966
1046
  /**
967
1047
  * Aggregate the schema-wide storage-rule metadata the studio's inspector reads:
968
1048
  * every statically-discovered `(bucket, on, prefix, procedure)` entry across all
@@ -1001,8 +1081,31 @@ declare const emitApi: (functions: ReadonlyArray<FunctionIR>, workflows?: Readon
1001
1081
  * Returns `""` when `@lunora/seed` is not a declared dependency, so projects
1002
1082
  * that don't use it keep a clean `_generated/` and never import the package.
1003
1083
  */
1084
+
1085
+ /**
1086
+ * Emit `_generated/collections.ts` — one TanStack DB collection factory per
1087
+ * `defineShape` in `lunora/shapes.ts` (the local-first partial-replication
1088
+ * surface). Each factory builds a live collection that syncs its shape's rowset
1089
+ * through the client's poke protocol (`subscribeShape`), so an app feeds the
1090
+ * result straight to `useLiveQuery`.
1091
+ *
1092
+ * Returns `""` (so `writeIfPresent` skips the file) unless the project both
1093
+ * declares shapes AND installs `@lunora/db` — the add-on that ships
1094
+ * `lunoraCollectionOptions`. `@lunora/db` stays a scoped install even under the
1095
+ * `lunorash` umbrella (an opt-in add-on, like `@lunora/auth`), so its import is
1096
+ * always `@lunora/db/collections`; only the in-umbrella `@lunora/client` import
1097
+ * is remapped to `lunorash/client`.
1098
+ */
1099
+ declare const emitCollections: (shapes: ReadonlyArray<ShapeIR>, hasDatabase: boolean, useUmbrella?: boolean) => string;
1004
1100
  interface EmitServerOptions {
1005
1101
  containers?: ReadonlyArray<ContainerIR>;
1102
+ /**
1103
+ * A `lunora/` source reads `ctx.access` — wires the verified Cloudflare Access
1104
+ * facade (`@lunora/cloudflare-access/context`) onto every ctx. Distinct from
1105
+ * `emitApp`'s `hasAccess` (which gates the worker's `.access()` resolveIdentity
1106
+ * method); this one gates the per-request `ctx.access` read surface.
1107
+ */
1108
+ hasAccessFacade?: boolean;
1006
1109
  hasAi?: boolean;
1007
1110
  /** A `lunora/` source uses `@lunora/bindings/analytics` / `ctx.analytics` — wires the write helper onto every ctx. */
1008
1111
  hasAnalytics?: boolean;
@@ -1031,6 +1134,7 @@ interface EmitServerOptions {
1031
1134
  }
1032
1135
  declare const emitServer: ({
1033
1136
  containers,
1137
+ hasAccessFacade,
1034
1138
  hasAi,
1035
1139
  hasAnalytics,
1036
1140
  hasBrowser,
@@ -1047,7 +1151,7 @@ declare const emitServer: ({
1047
1151
  useUmbrella,
1048
1152
  workflows
1049
1153
  }?: EmitServerOptions) => string;
1050
- declare const emitFunctions: (functions: ReadonlyArray<FunctionIR>, migrations?: ReadonlyArray<MigrationIR>, useUmbrella?: boolean) => string;
1154
+ declare const emitFunctions: (functions: ReadonlyArray<FunctionIR>, migrations?: ReadonlyArray<MigrationIR>, useUmbrella?: boolean, mutators?: ReadonlyArray<MutatorIR>, shapes?: ReadonlyArray<ShapeIR>) => string;
1051
1155
  /**
1052
1156
  * Storage-column map per table for the file browser: `{ table: [field, …] }` for
1053
1157
  * every field declared `v.storage(...)` (unwrapping `v.optional(...)`). The
@@ -1091,6 +1195,8 @@ interface EmitShardOptions {
1091
1195
  key: string;
1092
1196
  type: "boolean" | "number" | "object" | "string";
1093
1197
  }>;
1198
+ /** A `lunora/` source reads `ctx.access` — wires the verified Cloudflare Access facade onto every ctx. */
1199
+ hasAccessFacade?: boolean;
1094
1200
  hasAi?: boolean;
1095
1201
  /** A `lunora/` source reads `ctx.analytics` — wires the Analytics Engine write helper onto every ctx. */
1096
1202
  hasAnalytics?: boolean;
@@ -1110,10 +1216,14 @@ interface EmitShardOptions {
1110
1216
  /** A `lunora/` source reads `ctx.r2sql` (R2 SQL) — wires `ctx.r2sql` onto the ActionCtx only. */
1111
1217
  hasR2sql?: boolean;
1112
1218
  maskMetadata?: MaskMetadataIR;
1219
+ /** Custom mutators declared via `defineMutator` in `lunora/mutators.ts` — wires the `isCustomMutator` push-protocol override. */
1220
+ mutators?: ReadonlyArray<MutatorIR>;
1113
1221
  /** Queues declared via `defineQueue` exports in `lunora/queues.ts` — wires the typed `ctx.queues` producers. */
1114
1222
  queues?: ReadonlyArray<QueueIR>;
1115
1223
  rlsMetadata?: RlsMetadataIR;
1116
1224
  schema: SchemaIR;
1225
+ /** Replication shapes declared via `defineShape` in `lunora/shapes.ts` — wires the `resolveShape` subscription override. */
1226
+ shapes?: ReadonlyArray<ShapeIR>;
1117
1227
  storageRules?: StorageRulesMetadataIR;
1118
1228
  studioFeatures?: StudioFeaturesResult;
1119
1229
  /** The project depends on the `lunora` umbrella — import base packages via its subpaths. */
@@ -1124,6 +1234,7 @@ declare const emitShard: ({
1124
1234
  advisories,
1125
1235
  containers,
1126
1236
  flagKeys,
1237
+ hasAccessFacade,
1127
1238
  hasAi,
1128
1239
  hasAnalytics,
1129
1240
  hasBrowser,
@@ -1135,9 +1246,11 @@ declare const emitShard: ({
1135
1246
  hasPipelines,
1136
1247
  hasR2sql,
1137
1248
  maskMetadata,
1249
+ mutators,
1138
1250
  queues,
1139
1251
  rlsMetadata,
1140
1252
  schema,
1253
+ shapes,
1141
1254
  storageRules,
1142
1255
  studioFeatures,
1143
1256
  useUmbrella,
@@ -1202,6 +1315,8 @@ declare const emitVectors: (vectorIndexes: ReadonlyArray<VectorIndexIR>) => stri
1202
1315
  declare const emitWranglerCronTriggers: (crons: ReadonlyArray<CronJobIR>) => string[];
1203
1316
  /** Which capability methods the generated `defineApp` builder exposes — one flag per package-backed feature the app actually uses. */
1204
1317
  interface EmitAppOptions {
1318
+ /** App depends on `@lunora/cloudflare-access` → emit `.access()` (wire the Cloudflare Access `resolveIdentity`, composed ahead of `@lunora/auth` when both are present). */
1319
+ hasAccess: boolean;
1205
1320
  /** App uses `@lunora/ai` / `ctx.ai` → emit `.ai()` (override the Workers AI binding backing `ctx.ai`). */
1206
1321
  hasAi: boolean;
1207
1322
  /** App uses `@lunora/bindings/analytics` / `ctx.analytics` → emit `.analytics()` (override the dataset backing `ctx.analytics`). */
@@ -1591,6 +1706,8 @@ interface CodegenResult {
1591
1706
  generated: {
1592
1707
  api: string; /** Fluent worker-composition builder (`_generated/app.ts`) — `defineApp()`. Always written. */
1593
1708
  app: string;
1709
+ /** Partial-replication collection factories (`_generated/collections.ts`); `""` (and not written) unless the project declares shapes and installs `@lunora/db`. */
1710
+ collections: string;
1594
1711
  /** Container DO classes (`_generated/containers.ts`); `""` (and not written) when no containers are declared. */
1595
1712
  containers: string;
1596
1713
  crons: string;
@@ -1725,4 +1842,4 @@ declare const LUNORA_SOLUTION_RULES: ReadonlyArray<LunoraSolutionRule>;
1725
1842
  */
1726
1843
  declare const findLunoraSolution: (message: string) => LunoraSolution | undefined;
1727
1844
  declare const VERSION = "0.0.0";
1728
- export { type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, type DriftChange, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, LUNORA_SOLUTION_RULES, type LunoraSolution, type LunoraSolutionRule, type MaskProcedureIR, type MigrationIR, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, 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, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverNondeterministicCalls, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSchema, discoverStorageRulesMetadata, discoverWorkflows, emitApi, emitApp, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, evaluateSchemaDrift, findLunoraSolution, formatAdvisories, lintSchema, parseSchemaSnapshot, refreshCodegenProject, runCodegen, schemaFromIr, serializeSchemaSnapshot, validatorIrToJsonSchema };
1845
+ export { type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, type DriftChange, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, LUNORA_SOLUTION_RULES, type LunoraSolution, type LunoraSolutionRule, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type R2sqlCallIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SHAPES_FILENAME, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type ShapeIR, 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, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, evaluateSchemaDrift, findLunoraSolution, formatAdvisories, lintSchema, parseSchemaSnapshot, refreshCodegenProject, runCodegen, schemaFromIr, serializeSchemaSnapshot, validatorIrToJsonSchema };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { formatAdvisories, lintSchema } from './packem_shared/formatAdvisories-8NIv1k0I.mjs';
1
+ export { formatAdvisories, lintSchema } from './packem_shared/formatAdvisories-LM8-Ixjw.mjs';
2
2
  export { CodegenDiagnosticError, diagnosticAt } from './packem_shared/CodegenDiagnosticError-DeblMkzO.mjs';
3
3
  export { default as discoverAuthApiCalls } from './packem_shared/discoverAuthApiCalls-CoirYbg6.mjs';
4
4
  export { CONTAINERS_FILENAME, discoverContainers } from './packem_shared/CONTAINERS_FILENAME-DlP6YM_Q.mjs';
@@ -9,19 +9,21 @@ export { default as discoverHttpRoutes } from './packem_shared/discoverHttpRoute
9
9
  export { default as discoverInserts } from './packem_shared/discoverInserts-C7zxXkUf.mjs';
10
10
  export { default as discoverMaskProcedures } from './packem_shared/discoverMaskProcedures-Cm81kwrb.mjs';
11
11
  export { default as discoverMigrations } from './packem_shared/discoverMigrations-Bi5nJ0mJ.mjs';
12
+ export { MUTATORS_FILENAME, discoverMutators } from './packem_shared/MUTATORS_FILENAME-BhqdPtKp.mjs';
12
13
  export { default as discoverNondeterministicCalls } from './packem_shared/discoverNondeterministicCalls-C4M8AXmQ.mjs';
13
14
  export { default as discoverQueries } from './packem_shared/discoverQueries-B0wGT-xe.mjs';
14
15
  export { QUEUES_FILENAME, discoverQueues } from './packem_shared/QUEUES_FILENAME-B5_eWCRe.mjs';
15
16
  export { default as discoverR2sqlCalls } from './packem_shared/discoverR2sqlCalls-BVNMd428.mjs';
16
17
  export { discoverRlsMetadata, default as discoverRlsProcedures } from './packem_shared/discoverRlsMetadata-BS9GOGC5.mjs';
17
18
  export { default as discoverSchema } from './packem_shared/discoverSchema-BnWHHJ4T.mjs';
19
+ export { SHAPES_FILENAME, discoverShapes } from './packem_shared/SHAPES_FILENAME-ChV7MqgE.mjs';
18
20
  export { default as discoverStorageRulesMetadata } from './packem_shared/discoverStorageRulesMetadata-Da8BKXcI.mjs';
19
21
  export { WORKFLOWS_FILENAME, discoverWorkflows } from './packem_shared/WORKFLOWS_FILENAME-D62dcBGg.mjs';
20
- export { GENERATED_HEADER, emitApi, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers } from './packem_shared/GENERATED_HEADER-CkZUgM4_.mjs';
21
- export { emitApp } from './packem_shared/emitApp-DGmlt5fq.mjs';
22
- export { buildOpenApiDocument, emitOpenApi, emitOpenApiModule } from './packem_shared/buildOpenApiDocument-BSoDzIn8.mjs';
23
- export { OPENRPC_VERSION, buildOpenRpcDocument, emitOpenRpc, emitOpenRpcModule } from './packem_shared/OPENRPC_VERSION-VINwUAxf.mjs';
24
- export { SCHEMA_SNAPSHOT_FILENAME, createCodegenProject, refreshCodegenProject, runCodegen } from './packem_shared/SCHEMA_SNAPSHOT_FILENAME-DsBxQ5C_.mjs';
22
+ export { GENERATED_HEADER, emitApi, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers } from './packem_shared/GENERATED_HEADER-D-AbhmRh.mjs';
23
+ export { emitApp } from './packem_shared/emitApp-CV81L74c.mjs';
24
+ export { buildOpenApiDocument, emitOpenApi, emitOpenApiModule } from './packem_shared/buildOpenApiDocument-DoK7_x1g.mjs';
25
+ export { OPENRPC_VERSION, buildOpenRpcDocument, emitOpenRpc, emitOpenRpcModule } from './packem_shared/OPENRPC_VERSION-DDT4mIzD.mjs';
26
+ export { SCHEMA_SNAPSHOT_FILENAME, createCodegenProject, refreshCodegenProject, runCodegen } from './packem_shared/SCHEMA_SNAPSHOT_FILENAME-ExbveiC6.mjs';
25
27
  export { SCHEMA_SNAPSHOT_VERSION, SchemaSnapshotParseError, buildSchemaSnapshot, diffSchemaSnapshots, evaluateSchemaDrift, parseSchemaSnapshot, serializeSchemaSnapshot } from './packem_shared/SCHEMA_SNAPSHOT_VERSION-wWGP2_5E.mjs';
26
28
  export { schemaFromIr } from './packem_shared/schemaFromIr-DTYsLBaA.mjs';
27
29
  export { LUNORA_ERROR_CODES, validatorIrToJsonSchema } from './packem_shared/LUNORA_ERROR_CODES-CySpQPD3.mjs';