@lunora/codegen 1.0.0-alpha.382 → 1.0.0-alpha.384

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/index.d.mts +207 -94
  2. package/dist/index.d.ts +207 -94
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/{AGENTS_FILENAME-BedyJsOT.mjs → AGENTS_FILENAME-5mDMAMWy.mjs} +1 -1
  5. package/dist/packem_shared/{CONTAINERS_FILENAME-T1v8pyHN.mjs → CONTAINERS_FILENAME-BJYrxnq2.mjs} +1 -1
  6. package/dist/packem_shared/{GENERATED_HEADER-DPEvCN8Z.mjs → GENERATED_HEADER-Bzf6ZJ9r.mjs} +1 -1
  7. package/dist/packem_shared/{MUTATORS_FILENAME-Ipxibja6.mjs → MUTATORS_FILENAME-DlSftsvY.mjs} +1 -1
  8. package/dist/packem_shared/{NOTIFY_FILENAME-B-t7jQSm.mjs → NOTIFY_FILENAME-SKk8x0VM.mjs} +1 -1
  9. package/dist/packem_shared/{OPENRPC_VERSION-DA0ZNkhl.mjs → OPENRPC_VERSION-CSjT8wJW.mjs} +1 -1
  10. package/dist/packem_shared/{QUEUES_FILENAME-Dt5RG_P0.mjs → QUEUES_FILENAME-BeGwgqcw.mjs} +1 -1
  11. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-Dle_pfr9.mjs +31 -0
  12. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-BdxZuSxk.mjs +2 -0
  13. package/dist/packem_shared/SHAPES_FILENAME-rSSihffV.mjs +1 -0
  14. package/dist/packem_shared/SchemaSnapshotParseError-ycDz8gOB.mjs +17 -0
  15. package/dist/packem_shared/{WORKFLOWS_FILENAME-VAXgqqP-.mjs → WORKFLOWS_FILENAME--RWiu_Vy.mjs} +1 -1
  16. package/dist/packem_shared/{attribution-DUbGYT4N.mjs → attribution-CTMkuBkn.mjs} +1 -1
  17. package/dist/packem_shared/{buildOpenApiDocument-Ct2wK_Tj.mjs → buildOpenApiDocument-afHH7rN5.mjs} +1 -1
  18. package/dist/packem_shared/{context-property-calls-DKMO9ShK.mjs → context-property-calls-CYaejv5r.mjs} +1 -1
  19. package/dist/packem_shared/{context-root-BPfMNAJM.mjs → context-root-TiLodrRO.mjs} +1 -1
  20. package/dist/packem_shared/{database-calls-hLzaOquW.mjs → database-calls-QqsrkDMs.mjs} +1 -1
  21. package/dist/packem_shared/{discoverAuthApiCalls-Ce3BdKQr.mjs → discoverAuthApiCalls-DZMYREsq.mjs} +1 -1
  22. package/dist/packem_shared/discoverFunctions-DdHysjy1.mjs +1 -0
  23. package/dist/packem_shared/{discoverHttpRoutes-DHDfKLoa.mjs → discoverHttpRoutes-5iA7gI_Q.mjs} +1 -1
  24. package/dist/packem_shared/discoverHyperdriveCalls-BJRaIvLx.mjs +1 -0
  25. package/dist/packem_shared/{discoverInserts-IAa3lRR4.mjs → discoverInserts-Dw7fvL7s.mjs} +1 -1
  26. package/dist/packem_shared/discoverMaskProcedures-BLKjuD-A.mjs +1 -0
  27. package/dist/packem_shared/discoverMigrations-C649uAWL.mjs +1 -0
  28. package/dist/packem_shared/{discoverNondeterministicCalls-DZ_kIie5.mjs → discoverNondeterministicCalls-DQgVTcLv.mjs} +1 -1
  29. package/dist/packem_shared/{discoverQueries-DZOGiEPs.mjs → discoverQueries-DVFZJER7.mjs} +1 -1
  30. package/dist/packem_shared/discoverR2sqlCalls-BEBdqXi_.mjs +1 -0
  31. package/dist/packem_shared/{discoverRlsMetadata-Dq6iSXnC.mjs → discoverRlsMetadata-DqZpiGts.mjs} +1 -1
  32. package/dist/packem_shared/discoverRlsProcedures-C2lkSLPn.mjs +1 -0
  33. package/dist/packem_shared/{discoverSchema-DmkjooXZ.mjs → discoverSchema-Cycd1-H0.mjs} +1 -1
  34. package/dist/packem_shared/{discoverStorageRulesMetadata-CJ7h6SPK.mjs → discoverStorageRulesMetadata-H3RJzkH_.mjs} +1 -1
  35. package/dist/packem_shared/{emitAgents-D8TkTpNh.mjs → emitAgents-BeM6PZv4.mjs} +1 -1
  36. package/dist/packem_shared/{emitApi-D6uqyYd_.mjs → emitApi-GFmStqmq.mjs} +1 -1
  37. package/dist/packem_shared/{emitApp-D9kGG9Mu.mjs → emitApp-D-6FIpYb.mjs} +10 -6
  38. package/dist/packem_shared/{emitCrons-C3RiGYk7.mjs → emitCrons-Drdn8Mjn.mjs} +1 -1
  39. package/dist/packem_shared/{emitDataModel-BMMht_iZ.mjs → emitDataModel-LTnwnhV6.mjs} +1 -1
  40. package/dist/packem_shared/{emitDrizzleSchema-BmCxM6tO.mjs → emitDrizzleSchema-CM9jh_F0.mjs} +1 -1
  41. package/dist/packem_shared/{emitFunctions-NGByI1FZ.mjs → emitFunctions-DRAuiKPv.mjs} +90 -83
  42. package/dist/packem_shared/{emitServer-4NV3vaOg.mjs → emitServer-4l7MPmK0.mjs} +1 -1
  43. package/dist/packem_shared/emitShard-DqEvyZPZ.mjs +1 -0
  44. package/dist/packem_shared/{exported-procedure-chains-BaCIhnJ7.mjs → exported-procedure-chains-CRM-MVfP.mjs} +1 -1
  45. package/dist/packem_shared/handler-reference-90LXJART.mjs +1 -0
  46. package/dist/packem_shared/index-BhsJzv9r.mjs +1 -0
  47. package/dist/packem_shared/{index-BjDVAPNW.mjs → index-iw3axJ5Y.mjs} +1 -1
  48. package/dist/packem_shared/ip-reads-BVXbFgzV.mjs +1 -0
  49. package/dist/packem_shared/parse-validator-BisfC8bR.mjs +1 -0
  50. package/dist/packem_shared/{qualifiers-CPQCkXC4.mjs → qualifiers-D1Q_3wo2.mjs} +1 -1
  51. package/dist/packem_shared/{server-BY1v1bTx.mjs → server-D69SOfX8.mjs} +1 -1
  52. package/dist/packem_shared/{shard-DNXF9VZ5.mjs → shard-L3gYZnC9.mjs} +94 -91
  53. package/dist/packem_shared/{shard-runtime-Bg8MOBzw.mjs → shard-runtime-lkQU8trx.mjs} +1 -1
  54. package/dist/packem_shared/{shared-BErjtci3.mjs → shared-A1XHcT4t.mjs} +1 -1
  55. package/package.json +8 -8
  56. package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-CQyAtphV.mjs +0 -31
  57. package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-SplX7j_9.mjs +0 -2
  58. package/dist/packem_shared/SHAPES_FILENAME-mgEi072Z.mjs +0 -1
  59. package/dist/packem_shared/SchemaSnapshotParseError-CjKSMuex.mjs +0 -18
  60. package/dist/packem_shared/discoverFunctions-a0IT8OSb.mjs +0 -1
  61. package/dist/packem_shared/discoverHyperdriveCalls-i8Zcf64H.mjs +0 -1
  62. package/dist/packem_shared/discoverMaskProcedures-Bj6fPF4u.mjs +0 -1
  63. package/dist/packem_shared/discoverMigrations-Bv8kNIgy.mjs +0 -1
  64. package/dist/packem_shared/discoverR2sqlCalls-Lq6G--TZ.mjs +0 -1
  65. package/dist/packem_shared/discoverRlsProcedures-B0DYk-gW.mjs +0 -1
  66. package/dist/packem_shared/emitShard-9NVueN79.mjs +0 -1
  67. package/dist/packem_shared/handler-reference-D1wpw_qR.mjs +0 -1
  68. package/dist/packem_shared/parse-validator-CP5CL6Q7.mjs +0 -1
package/dist/index.d.mts CHANGED
@@ -219,11 +219,12 @@ type DriftScope = "schema" | "table";
219
219
  * - `"backfill"` — a `defineMigration` transform rewrites the affected rows.
220
220
  * The ONLY value for which a data migration is the answer.
221
221
  * - `"rehome"` — the rows' physical storage moves (a different Durable Object,
222
- * or a different region). The per-shard runner only ever replaces a row inside
223
- * the shard it was handed, so no transform reaches these; the fix is an
224
- * export/import round trip, or a revert.
222
+ * or a different region), or a table is emptied on cold start. The per-shard
223
+ * runner only ever replaces a row inside the shard it was handed, so the move
224
+ * itself is an export/import round trip; the change clears once a new migration
225
+ * on the table accompanies it (to give each row what its new home needs).
225
226
  * - `"code"` — nothing happens to stored data; a query or a call site has to
226
- * change (a dropped index, a dropped relation).
227
+ * change (a dropped index a query still names).
227
228
  * - `"none"` — additive, nothing to do.
228
229
  *
229
230
  * This lives HERE, next to the change union, for the same reason {@link DriftScope}
@@ -234,6 +235,22 @@ type DriftScope = "schema" | "table";
234
235
  * sends the operator to a tool that cannot work.
235
236
  */
236
237
  type DriftRemediation = "backfill" | "code" | "none" | "rehome";
238
+ /**
239
+ * What a migration's `covers` must say for it to clear a change that moves or empties data: the table (when one is involved) and the
240
+ * target of the change. A `shardMode` is the snapshot's spelling (`root`, `global:d1`, `global:hyperdrive`, `shardBy:<field>`) and
241
+ * `global` stands for any global backend; a `jurisdiction` is the one the schema moves to, `none` when it is removed.
242
+ */
243
+ interface DriftCoverage {
244
+ jurisdiction?: string;
245
+ memory?: true;
246
+ shardMode?: string;
247
+ table?: string;
248
+ /** The TTL policy a table moves to: the column and the offset (`after`, milliseconds; absent is 0). */
249
+ ttl?: {
250
+ after?: number;
251
+ field: string;
252
+ };
253
+ }
237
254
  /** One classified structural change between two snapshots. */
238
255
  interface DriftChange {
239
256
  /** What fixes this change — see {@link DriftRemediation}. `"none"` for every `safe` change. */
@@ -248,8 +265,41 @@ interface DriftChange {
248
265
  severity: "breaking" | "safe";
249
266
  /** Human-readable, actionable description (used in the gate message). */
250
267
  summary: string;
268
+ /**
269
+ * The field this change belongs to, for a change to one field (its kind, shape,
270
+ * optionality, a constraint, or the field being added or removed).
271
+ */
272
+ field?: string;
251
273
  /** The table this change belongs to. Always set when `scope` is `"table"`. */
252
274
  table?: string;
275
+ /**
276
+ * Set on a change that is safe for the stored data but that the operator must hear about: what happens to data the schema
277
+ * no longer describes, or which rows a new TTL will sweep. The gate logs it as a warning when the run proceeds.
278
+ */
279
+ warning?: true;
280
+ /** Set on a change whose backfill a migration returning each row unchanged performs, because rewriting the row is what does it. */
281
+ identityRewrites?: true;
282
+ /** The TTL a change installs, and the one it replaces, so a caller that can read rows can count what the next sweep deletes. */
283
+ expiry?: {
284
+ after?: number;
285
+ field: string;
286
+ previous?: {
287
+ after?: number;
288
+ field: string;
289
+ };
290
+ };
291
+ /**
292
+ * Set on a change that moves or empties data (a shard-mode flip, a table turned `.memory()`, a jurisdiction change): the `covers`
293
+ * a new migration must declare to clear it. Absent when no migration can name the change.
294
+ */
295
+ coverage?: DriftCoverage;
296
+ /** The index a change is about, set on a removed index so a caller can check whether a query still names it. */
297
+ index?: string;
298
+ /**
299
+ * Set when the change adds a uniqueness constraint: the fields whose combined value must not repeat among a table's stored rows.
300
+ * Rows can settle it, so a caller that can read them checks for duplicates instead of asking for a migration.
301
+ */
302
+ uniqueOn?: ReadonlyArray<string>;
253
303
  /** A machine-readable change discriminator. */
254
304
  type: "addedFieldConstraint" | "addedIndex" | "addedOptionalField" | "addedRelation" | "addedRequiredField" | "addedTable" | "changedCommitOrdering" | "changedFieldKind" | "changedFieldShape" | "changedIndex" | "changedJurisdiction" | "changedMemoryMode" | "changedShardMode" | "changedTtlPolicy" | "fieldOptionalToRequired" | "fieldRequiredToOptional" | "relaxedFieldConstraint" | "removedField" | "removedIndex" | "removedRelation" | "removedTable" | "widenedFieldShape";
255
305
  }
@@ -1144,6 +1194,12 @@ interface ValidatorIR {
1144
1194
  * flag, because compiling it would silently skip the predicate.
1145
1195
  */
1146
1196
  unmodelledRefinement?: boolean;
1197
+ /**
1198
+ * `true` on a `v.object(...)` whose `shape` is not the whole validator: the
1199
+ * argument is built at runtime, spreads something unreadable, or is absent. An
1200
+ * empty `shape` then stands for "unknown", not "no properties".
1201
+ */
1202
+ unresolvedShape?: boolean;
1147
1203
  valueType?: ValidatorIR;
1148
1204
  }
1149
1205
  interface IndexIR {
@@ -1415,12 +1471,32 @@ interface ExposeCacheIR {
1415
1471
  * tables with breaking drift, so a migration left at `""` covers nothing.
1416
1472
  */
1417
1473
  interface MigrationIR {
1474
+ /**
1475
+ * The change this migration declares it accounts for, read from `covers: { … }` when every value is a literal. The drift gate
1476
+ * clears a shard-mode flip, a table turned `.memory()` or a jurisdiction change only for a migration naming exactly that change.
1477
+ */
1478
+ covers?: {
1479
+ jurisdiction?: string;
1480
+ memory?: true;
1481
+ shardMode?: string;
1482
+ table?: string;
1483
+ ttl?: {
1484
+ after?: number;
1485
+ field: string;
1486
+ };
1487
+ };
1418
1488
  /** Export binding name, used to reference the module member in generated imports. */
1419
1489
  exportName: string;
1420
1490
  /** Path relative to `<projectRoot>/lunora/` without extension, e.g. "migrations". */
1421
1491
  filePath: string;
1422
1492
  /** Stable migration id — the registry key and per-shard run-state key. */
1423
1493
  id: string;
1494
+ /**
1495
+ * `true` when `up` returns its document unchanged (`(document) => document`, the
1496
+ * shape `lunora migrate create` scaffolds). Such a migration rewrites no row, so it
1497
+ * cannot by itself account for a schema change on its table.
1498
+ */
1499
+ identity?: true;
1424
1500
  /** Table the migration iterates; `""` when not a static string literal. */
1425
1501
  table: string;
1426
1502
  }
@@ -1552,6 +1628,11 @@ interface FunctionIR {
1552
1628
  * ts-morph cannot resolve the type (typically because the consuming
1553
1629
  * project lacks a tsconfig that can reach `@lunora/server`).
1554
1630
  */
1631
+ /**
1632
+ * Set on a query that may read `ctx.ip`, decided statically and failing closed: the shard never resumes it
1633
+ * warm, whatever fingerprint a client presents, because its rows can depend on the address the cursor was read at.
1634
+ */
1635
+ readsIp?: true;
1555
1636
  returnType: string;
1556
1637
  /**
1557
1638
  * A `defineWebSocket` route: the literal URL `path` it serves and whether it requires a session (`auth`). Read at
@@ -1597,6 +1678,11 @@ interface ShapeIR {
1597
1678
  exportName: string;
1598
1679
  /** Path relative to `<projectRoot>/lunora/` without extension — always `"shapes"`. */
1599
1680
  filePath: string;
1681
+ /**
1682
+ * The shape's `where` may read `ctx.ip`, decided statically and failing closed (same rule as {@link FunctionIR.readsIp}),
1683
+ * so the shard never resumes it warm.
1684
+ */
1685
+ readsIp?: true;
1600
1686
  /**
1601
1687
  * The `table` string literal from the `defineShape({ table })` call, lifted
1602
1688
  * only for static advisor lints (the runtime object stays authoritative).
@@ -3286,6 +3372,108 @@ interface PlatformDiagnostic {
3286
3372
  /** The requested deploy target. */
3287
3373
  target: string;
3288
3374
  }
3375
+ /**
3376
+ * Build a {@link SchemaSnapshot} from a parsed {@link SchemaIR} and the set of
3377
+ * declared migration ids. Tables and migration ids are sorted so the emitted
3378
+ * JSON is byte-stable across runs AND across machines (no spurious diffs /
3379
+ * churn) — see `sortKeys` in `shared/schema-snapshot.ts` for why that ordering
3380
+ * must not be locale-aware.
3381
+ *
3382
+ * Field / index / relation keys are sorted the same way, by `tableSnapshotOf` —
3383
+ * see there for why declaration order was the wrong default for a hashed file.
3384
+ */
3385
+ declare const buildSchemaSnapshot: (schema: SchemaIR, migrationIds: ReadonlyArray<string>) => SchemaSnapshot;
3386
+ /**
3387
+ * Thrown by {@link parseSchemaSnapshot} when the baseline file exists but is
3388
+ * malformed (bad JSON / wrong version / invalid table shape). Lets the CLI gate
3389
+ * treat a corrupt baseline as a hard error rather than silently degrading to a
3390
+ * "first capture" that would mask drift and then overwrite the bad file.
3391
+ */
3392
+ declare class SchemaSnapshotParseError extends LunoraError {
3393
+ constructor(message: string);
3394
+ }
3395
+ /**
3396
+ * Parse a committed snapshot file. Returns `undefined` ONLY when the content is
3397
+ * absent/empty; throws {@link SchemaSnapshotParseError} when content is present
3398
+ * but malformed (bad JSON, wrong version, or structurally-invalid tables) so the
3399
+ * caller can distinguish "no baseline yet" (a legitimate first capture) from "a
3400
+ * corrupt baseline" (which must not be silently treated as a first capture).
3401
+ *
3402
+ * The parsing itself lives in `shared/schema-snapshot.ts` (the Studio reads the
3403
+ * same JSON out of the DO ledger); this wrapper only applies the CLI's policy of
3404
+ * treating a malformed baseline as fatal.
3405
+ */
3406
+ declare const parseSchemaSnapshot: (content: string | undefined) => SchemaSnapshot | undefined;
3407
+ /**
3408
+ * A `.withIndex(name)` the application's own functions make: the table read, the index named (`undefined` when the name is not a
3409
+ * string literal, so any index of the table may be the one), and where. The drift gate refuses to drop an index one of these names.
3410
+ */
3411
+ interface IndexReference {
3412
+ file: string;
3413
+ /** The exported function (or helper, or `<module>`) containing the read. */
3414
+ function: string;
3415
+ index: string | undefined;
3416
+ line: number;
3417
+ /** `""` when the table is not a string literal, so any table may be the one. */
3418
+ table: string;
3419
+ }
3420
+ /** The `.withIndex` reads among a run's discovered queries, reduced to what the index check needs. */
3421
+ declare const indexReferencesOf: (queries: ReadonlyArray<QueryReadIR>) => IndexReference[];
3422
+ /** The decision the pre-deploy gate returns. */
3423
+ interface SchemaDriftDecision {
3424
+ /** True when the deploy must be blocked (breaking drift no new migration covers, and no override). */
3425
+ blocked: boolean;
3426
+ /** Every classified change (both severities), for reporting. */
3427
+ changes: ReadonlyArray<DriftChange>;
3428
+ /**
3429
+ * Migration ids declared now but absent from the baseline. Reported for
3430
+ * context; the gate acts on which of them cover an affected TABLE, not on how
3431
+ * many there are.
3432
+ */
3433
+ newMigrationIds: ReadonlyArray<string>;
3434
+ /**
3435
+ * A multi-line, actionable explanation. Always present; empty string when
3436
+ * there is no drift at all. Mirrors the D1-placeholder guard's message style.
3437
+ */
3438
+ reason: string;
3439
+ /**
3440
+ * The breaking changes no new migration accounts for. Non-empty exactly when
3441
+ * the run blocks or an override waved it through; a caller that can read the
3442
+ * stored rows checks these.
3443
+ */
3444
+ uncovered: ReadonlyArray<DriftChange>;
3445
+ }
3446
+ /**
3447
+ * Decide whether breaking schema drift should block a deploy.
3448
+ *
3449
+ * Blocks only when the baseline exists (a first-ever capture is never blocking),
3450
+ * there is at least one `breaking` change, no new migration COVERS it, and the
3451
+ * `allowDrift` override is not set. Safe-only drift passes.
3452
+ *
3453
+ * "Covers" is per-table, not per-run: a new migration excuses breaking drift on
3454
+ * the table it iterates, and nothing else. Counting new ids alone let a backfill
3455
+ * on `messages` unblock a required field added to `users` — the gate reported
3456
+ * "accompanied by a migration" for a change that migration would never visit.
3457
+ * The shard-mode diff cites this block to justify the studio not shipping a
3458
+ * stranded-rows detector (see `shared/schema-snapshot.ts`), and that claim only
3459
+ * holds if an unrelated migration cannot wave it through.
3460
+ *
3461
+ * Only a `"backfill"` or `"rehome"` change is coverable. A `"code"` change breaks
3462
+ * a call site (a dropped index a query still names); rewriting rows fixes neither,
3463
+ * so a migration must not excuse it however well its table matches. It is cleared
3464
+ * by fixing the code (`--allow-schema-drift` skips it for one run).
3465
+ */
3466
+ declare const evaluateSchemaDrift: (options: {
3467
+ allowDrift?: boolean;
3468
+ baseline: SchemaSnapshot | undefined;
3469
+ /** The command printing the remediation, so it names only flags that command accepts. */
3470
+ command?: string;
3471
+ current: SchemaSnapshot;
3472
+ /** The `.withIndex` reads the application makes, so a dropped index a query still names is refused. */
3473
+ indexReferences?: ReadonlyArray<IndexReference>;
3474
+ /** This run's declared migrations, so a new one is matched to the table it iterates. */
3475
+ migrations: ReadonlyArray<Pick<MigrationIR, "covers" | "id" | "identity" | "table">>;
3476
+ }) => SchemaDriftDecision;
3289
3477
  interface CodegenOptions {
3290
3478
  /**
3291
3479
  * Which machine-readable API spec(s) to emit into `_generated/`.
@@ -3342,14 +3530,6 @@ interface CodegenOptions {
3342
3530
  * `platform_unknown_target` diagnostic.
3343
3531
  */
3344
3532
  target?: string;
3345
- /**
3346
- * Re-bless the committed schema-drift baseline (`lunora/.lunora-schema.json`)
3347
- * with the current structural snapshot. The baseline is ALWAYS written on
3348
- * first capture (when the file is absent); set this to overwrite an existing
3349
- * one — e.g. after the developer has added the data migration that justifies
3350
- * a breaking change. Ignored when `dryRun` is true.
3351
- */
3352
- updateSchemaBaseline?: boolean;
3353
3533
  /**
3354
3534
  * Every `queues.producers[]` entry of `wrangler.jsonc`, top level and each
3355
3535
  * `env.<name>` block. A producer naming a push queue's binding with another
@@ -3466,6 +3646,11 @@ interface CodegenResult {
3466
3646
  /** WorkflowEntrypoint classes (`_generated/workflows.ts`); `""` (and not written) when no workflows are declared. */
3467
3647
  workflows: string;
3468
3648
  };
3649
+ /**
3650
+ * Every `.withIndex(name)` the application's functions make, so the drift gate can refuse to drop an index a
3651
+ * query still names. Computed on every run, lint or not: the gate must not depend on an advisory opt-out.
3652
+ */
3653
+ indexReferences: ReadonlyArray<IndexReference>;
3469
3654
  /**
3470
3655
  * Data migrations discovered from `defineMigration` exports under `lunora/`,
3471
3656
  * each with the table it iterates. The drift gate matches a NEW id against
@@ -3499,6 +3684,12 @@ interface CodegenResult {
3499
3684
  schemaSnapshot: SchemaSnapshot;
3500
3685
  /** Absolute path of the committed baseline file (`lunora/.lunora-schema.json`). */
3501
3686
  schemaSnapshotPath: string;
3687
+ /**
3688
+ * The parsed tables this run's snapshot was built from. The snapshot keeps a
3689
+ * field's kind but not whether its validator was resolvable, so a caller that
3690
+ * checks stored rows against the schema reads the validators here.
3691
+ */
3692
+ schemaTables: ReadonlyArray<TableIR>;
3502
3693
  /**
3503
3694
  * Workflows discovered from `defineWorkflow` exports in
3504
3695
  * `lunora/workflows.ts` — the list the config layer reconciles into
@@ -4135,6 +4326,8 @@ interface EmitShardOptions {
4135
4326
  }>;
4136
4327
  /** The project declares `lunora/flags.ts` — wires `ctx.flags` (OpenFeature) onto every ctx. */
4137
4328
  hasFlags?: boolean;
4329
+ /** Whether some query may read `ctx.ip` (see `LUNORA_IP_READER_PATHS`), so the shard seeds its address-keyed set from it. */
4330
+ hasIpReaders?: boolean;
4138
4331
  /** The project declares `lunora/notify.ts` — wires `ctx.notify` + its `ctx.push` alias (`@lunora/notify`) onto every ctx. */
4139
4332
  hasNotify?: boolean;
4140
4333
  /** The project declares at least one `defineRoom` — wires the `LUNORA_ROOMS` topic→path resolution in the `roomHandlerPath` override. */
@@ -4200,7 +4393,7 @@ interface EmitShardOptions {
4200
4393
  workflowEvents?: ReadonlyArray<WorkflowEventIR>;
4201
4394
  workflows?: ReadonlyArray<WorkflowIR>;
4202
4395
  }
4203
- declare const emitShard: ({ advisories, advisorProcedures, agents, capabilities, containers, env, flagKeys, hasFlags, hasNotify, hasRooms, hasSecretValues, hasSensitiveArgs, hasSockets, lazyFunctions, hasVectors, liveStreamDeclarations, liveStreams, maskMetadata, mutators, queues, rlsMetadata, schema, schemaSnapshot, shapes, storageRules, studioFeatures, services, topics, useUmbrella, workflowEvents, workflows }: EmitShardOptions) => string;
4396
+ declare const emitShard: ({ advisories, advisorProcedures, agents, capabilities, containers, env, flagKeys, hasFlags, hasNotify, hasRooms, hasSecretValues, hasSensitiveArgs, hasSockets, lazyFunctions, hasVectors, liveStreamDeclarations, liveStreams, maskMetadata, mutators, queues, rlsMetadata, schema, schemaSnapshot, shapes, storageRules, studioFeatures, hasIpReaders, services, topics, useUmbrella, workflowEvents, workflows }: EmitShardOptions) => string;
4204
4397
  /**
4205
4398
  * Emit `_generated/containers.ts` — one container-enabled Durable Object class
4206
4399
  * per `defineContainer` export, each a thin subclass of `LunoraContainer`
@@ -4664,86 +4857,6 @@ declare const loadProjectConfig: (projectRoot: string) => Promise<LoadedProjectC
4664
4857
  * module header for what this can and cannot see, and why.
4665
4858
  */
4666
4859
  declare const readProjectConfigLiterals: (projectRoot: string) => ProjectConfigLiterals;
4667
- /**
4668
- * Build a {@link SchemaSnapshot} from a parsed {@link SchemaIR} and the set of
4669
- * declared migration ids. Tables and migration ids are sorted so the emitted
4670
- * JSON is byte-stable across runs AND across machines (no spurious diffs /
4671
- * churn) — see `sortKeys` in `shared/schema-snapshot.ts` for why that ordering
4672
- * must not be locale-aware.
4673
- *
4674
- * Field / index / relation keys are sorted the same way, by `tableSnapshotOf` —
4675
- * see there for why declaration order was the wrong default for a hashed file.
4676
- */
4677
- declare const buildSchemaSnapshot: (schema: SchemaIR, migrationIds: ReadonlyArray<string>) => SchemaSnapshot;
4678
- /**
4679
- * Thrown by {@link parseSchemaSnapshot} when the baseline file exists but is
4680
- * malformed (bad JSON / wrong version / invalid table shape). Lets the CLI gate
4681
- * treat a corrupt baseline as a hard error rather than silently degrading to a
4682
- * "first capture" that would mask drift and then overwrite the bad file.
4683
- */
4684
- declare class SchemaSnapshotParseError extends LunoraError {
4685
- constructor(message: string);
4686
- }
4687
- /**
4688
- * Parse a committed snapshot file. Returns `undefined` ONLY when the content is
4689
- * absent/empty; throws {@link SchemaSnapshotParseError} when content is present
4690
- * but malformed (bad JSON, wrong version, or structurally-invalid tables) so the
4691
- * caller can distinguish "no baseline yet" (a legitimate first capture) from "a
4692
- * corrupt baseline" (which must not be silently treated as a first capture).
4693
- *
4694
- * The parsing itself lives in `shared/schema-snapshot.ts` (the Studio reads the
4695
- * same JSON out of the DO ledger); this wrapper only applies the CLI's policy of
4696
- * treating a malformed baseline as fatal.
4697
- */
4698
- declare const parseSchemaSnapshot: (content: string | undefined) => SchemaSnapshot | undefined;
4699
- /** The decision the pre-deploy gate returns. */
4700
- interface SchemaDriftDecision {
4701
- /** True when the deploy must be blocked (breaking drift no new migration covers, and no override). */
4702
- blocked: boolean;
4703
- /** Every classified change (both severities), for reporting. */
4704
- changes: ReadonlyArray<DriftChange>;
4705
- /**
4706
- * Migration ids declared now but absent from the baseline. Reported for
4707
- * context; the gate acts on which of them cover an affected TABLE, not on how
4708
- * many there are.
4709
- */
4710
- newMigrationIds: ReadonlyArray<string>;
4711
- /**
4712
- * A multi-line, actionable explanation. Always present; empty string when
4713
- * there is no drift at all. Mirrors the D1-placeholder guard's message style.
4714
- */
4715
- reason: string;
4716
- }
4717
- /**
4718
- * Decide whether breaking schema drift should block a deploy.
4719
- *
4720
- * Blocks only when the baseline exists (a first-ever capture is never blocking),
4721
- * there is at least one `breaking` change, no new migration COVERS it, and the
4722
- * `allowDrift` override is not set. Safe-only drift passes.
4723
- *
4724
- * "Covers" is per-table, not per-run: a new migration excuses breaking drift on
4725
- * the table it iterates, and nothing else. Counting new ids alone let a backfill
4726
- * on `messages` unblock a required field added to `users` — the gate reported
4727
- * "accompanied by a migration" for a change that migration would never visit.
4728
- * The shard-mode diff cites this block to justify the studio not shipping a
4729
- * stranded-rows detector (see `shared/schema-snapshot.ts`), and that claim only
4730
- * holds if an unrelated migration cannot wave it through.
4731
- *
4732
- * Only a `"backfill"` change is coverable at all. A `"rehome"` change moves rows
4733
- * to another Durable Object or region and a `"code"` change breaks a call site;
4734
- * rewriting rows fixes neither, so a migration must not excuse them however well
4735
- * its table matches. Those are cleared by fixing the code or accepting the new
4736
- * shape (`--allow-schema-drift` / `--update-schema-baseline`).
4737
- */
4738
- declare const evaluateSchemaDrift: (options: {
4739
- allowDrift?: boolean;
4740
- baseline: SchemaSnapshot | undefined;
4741
- /** The command printing the remediation, so it names only flags that command accepts. */
4742
- command?: string;
4743
- current: SchemaSnapshot;
4744
- /** This run's declared migrations, so a new one is matched to the table it iterates. */
4745
- migrations: ReadonlyArray<Pick<MigrationIR, "id" | "table">>;
4746
- }) => SchemaDriftDecision;
4747
4860
  /**
4748
4861
  * Content hash of the schema directory's TypeScript sources — everything codegen
4749
4862
  * reads, minus its own `_generated/` output.
@@ -4802,4 +4915,4 @@ declare const secretKindOf: (value: string) => string | undefined;
4802
4915
  /** A redacted preview of a secret value — first 4 chars plus its length, never the full value. */
4803
4916
  declare const redact: (value: string) => string;
4804
4917
  declare const VERSION = "0.0.0";
4805
- export { AGENTS_FILENAME, type AgentIR, type ArchitectureManifest, type AuthApiCallIR, CAPABILITY_PROBES, CONTAINERS_FILENAME, type CapabilityKey, type CapabilityProbe, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type ContainerImageIR, type ContainerNamedImageIR, type ContextPropertyCallIR, type CronJobIR, DEFAULT_TARGET, type DefaultScheduledContainerIR, type DriftChange, type DriftRemediation, type DriftScope, type DurableObjectScheduledContainerIR, 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, type LoadedProjectConfig, type LunoraProjectConfig, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, type NotifyChannels, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, PROJECT_CONFIG_FILENAMES, type PlatformDiagnostic, type ProjectConfigLiterals, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SHAPES_FILENAME, type SandboxUsage, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type ServiceBindingIR, type ServiceLiteral, type ShapeIR, type SourceCapabilitySignals, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, type TargetScope, type TopicIR, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, type WranglerQueueProducerIR, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, capabilitiesUsedBy, createCodegenProject, createTargetScope, describeErrorLevelFindings, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverHyperdriveCalls, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyChannels, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitInternalApi, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitScheduler, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, errorAdvisoryNames, errorPlatformDiagnosticNames, evaluateSchemaDrift, findCodegenConfigFile, findProjectConfigFile, findTsconfig, fingerprintSchemaSources, foldCapabilitySignals, formatAdvisories, isD1GlobalTable, isHyperdriveGlobalTable, isTestPath, lintSchema, listLunoraSourceFiles, loadProjectConfig, mayReadCapabilityContext, parseSchemaSnapshot, platformMatrixIds, projectConfigCandidatePaths, readPackageDependencies, readProjectConfigLiterals, readProjectTarget, readServiceBindings, redact, refreshCodegenProject, resolveCodegenTarget, resolveServiceBindings, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, sortedUniqueNames, sourceCapabilitySignals, toAdvisorContext, tsconfigFingerprint, validatorIrToJsonSchema };
4918
+ export { AGENTS_FILENAME, type AgentIR, type ArchitectureManifest, type AuthApiCallIR, CAPABILITY_PROBES, CONTAINERS_FILENAME, type CapabilityKey, type CapabilityProbe, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type ContainerImageIR, type ContainerNamedImageIR, type ContextPropertyCallIR, type CronJobIR, DEFAULT_TARGET, type DefaultScheduledContainerIR, type DriftChange, type DriftRemediation, type DriftScope, type DurableObjectScheduledContainerIR, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexReference, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type LintSchemaOptions, type LoadedProjectConfig, type LunoraProjectConfig, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, type NotifyChannels, OPENRPC_VERSION, type OpenApiEmitInput, type OpenRpcEmitInput, PROJECT_CONFIG_FILENAMES, type PlatformDiagnostic, type ProjectConfigLiterals, type ProjectIR, QUEUES_FILENAME, type QueryReadIR, type QueueIR, type RelationSnapshot, type RlsMetadataIR, type RlsPolicyIR, type RlsProcedureIR, type RlsRoleIR, SCHEMA_SNAPSHOT_FILENAME, SCHEMA_SNAPSHOT_VERSION, SHAPES_FILENAME, type SandboxUsage, type SchemaDrift, type SchemaDriftDecision, type SchemaIR, type SchemaSnapshot, SchemaSnapshotParseError, type ServiceBindingIR, type ServiceLiteral, type ShapeIR, type SourceCapabilitySignals, type StorageRuleIR, type StorageRulesMetadataIR, type TableIR, type TableSnapshot, type TargetScope, type TopicIR, VERSION, type ValidatorIR, type VectorIndexIR, WORKFLOWS_FILENAME, type WorkflowIR, type WranglerQueueProducerIR, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, capabilitiesUsedBy, createCodegenProject, createTargetScope, describeErrorLevelFindings, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverHyperdriveCalls, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyChannels, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitInternalApi, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitScheduler, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, errorAdvisoryNames, errorPlatformDiagnosticNames, evaluateSchemaDrift, findCodegenConfigFile, findProjectConfigFile, findTsconfig, fingerprintSchemaSources, foldCapabilitySignals, formatAdvisories, indexReferencesOf, isD1GlobalTable, isHyperdriveGlobalTable, isTestPath, lintSchema, listLunoraSourceFiles, loadProjectConfig, mayReadCapabilityContext, parseSchemaSnapshot, platformMatrixIds, projectConfigCandidatePaths, readPackageDependencies, readProjectConfigLiterals, readProjectTarget, readServiceBindings, redact, refreshCodegenProject, resolveCodegenTarget, resolveServiceBindings, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, sortedUniqueNames, sourceCapabilitySignals, toAdvisorContext, tsconfigFingerprint, validatorIrToJsonSchema };