@lunora/codegen 1.0.0-alpha.74 → 1.0.0-alpha.76
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 +190 -136
- package/dist/index.d.ts +190 -136
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/GENERATED_HEADER-CQRdzwf9.mjs +1 -0
- package/dist/packem_shared/{OPENRPC_VERSION-CvVFqUlq.mjs → OPENRPC_VERSION-67sJ7JrS.mjs} +1 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-x_pw6Agi.mjs +3 -0
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-CFhF_hmg.mjs +2 -0
- package/dist/packem_shared/SchemaSnapshotParseError-0KRzSjo4.mjs +14 -0
- package/dist/packem_shared/{buildOpenApiDocument-xYxqrlj1.mjs → buildOpenApiDocument-DeMEuKaw.mjs} +1 -1
- package/dist/packem_shared/{emit-D7VIjvlm.mjs → emit-sQzv_a8t.mjs} +165 -162
- package/dist/packem_shared/{emitApp-CAeIj6e_.mjs → emitApp-D5X1S54W.mjs} +1 -1
- package/package.json +9 -9
- package/dist/packem_shared/GENERATED_HEADER-DV-sQj-R.mjs +0 -1
- package/dist/packem_shared/SCHEMA_SNAPSHOT_FILENAME-Bj7EusPY.mjs +0 -3
- package/dist/packem_shared/SCHEMA_SNAPSHOT_VERSION-Bpf1FGMG.mjs +0 -15
package/dist/index.d.mts
CHANGED
|
@@ -6,6 +6,126 @@ import { Node, Project } from 'ts-morph';
|
|
|
6
6
|
import { StudioFeaturesResult } from '@lunora/do';
|
|
7
7
|
import { Schema } from '@lunora/server';
|
|
8
8
|
import { JsonSchema } from '@lunora/values';
|
|
9
|
+
/**
|
|
10
|
+
* The structural schema-snapshot format and its diff, shared by `@lunora/codegen`
|
|
11
|
+
* (which builds snapshots from the parsed schema IR and gates deploys on the
|
|
12
|
+
* diff) and `@lunora/studio` (which renders the same diff as a visual migration
|
|
13
|
+
* history).
|
|
14
|
+
*
|
|
15
|
+
* Having ONE diff is the point: the Studio's schema-history view and the
|
|
16
|
+
* pre-deploy drift gate must classify a change identically, or the UI will say a
|
|
17
|
+
* change is safe while `lunora deploy` refuses it. `@lunora/codegen` is a
|
|
18
|
+
* build-time package the browser bundle cannot import, and neither package sits
|
|
19
|
+
* below the other, so — like `shared/quote-identifier.ts` — this lives outside
|
|
20
|
+
* both and is bundler-inlined into each. Keep it genuinely zero-dependency
|
|
21
|
+
* (relative/built-in imports only) or inlining breaks. Consumers must drop
|
|
22
|
+
* `outDir`/`rootDir` from their `tsconfig.json` (a set `rootDir` raises TS6059
|
|
23
|
+
* for this out-of-package file under `tsc --noEmit`).
|
|
24
|
+
*
|
|
25
|
+
* What stays in `@lunora/codegen`: building a snapshot from `SchemaIR`, the
|
|
26
|
+
* `SchemaSnapshotParseError` class (it extends `LunoraError`), and the deploy
|
|
27
|
+
* gate's policy (`evaluateSchemaDrift`). What lives here: the format, the diff,
|
|
28
|
+
* the severity classification, and the content hash.
|
|
29
|
+
*/
|
|
30
|
+
/** Current snapshot format version. Bumped if the structural shape below changes. */
|
|
31
|
+
declare const SCHEMA_SNAPSHOT_VERSION: 1;
|
|
32
|
+
/** A single field's structural shape: its value kind and whether it is optional. */
|
|
33
|
+
interface FieldSnapshot {
|
|
34
|
+
/** The validator kind (`string`, `number`, `id`, `object`, …) after unwrapping `v.optional`. */
|
|
35
|
+
kind: string;
|
|
36
|
+
/** True when declared `v.optional(...)` — accepts `undefined` / absent on insert. */
|
|
37
|
+
optional: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** A single secondary index's structural shape. */
|
|
40
|
+
interface IndexSnapshot {
|
|
41
|
+
fields: ReadonlyArray<string>;
|
|
42
|
+
unique: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** A single relation's structural shape. */
|
|
45
|
+
interface RelationSnapshot {
|
|
46
|
+
field: string;
|
|
47
|
+
kind: "many" | "one";
|
|
48
|
+
table: string;
|
|
49
|
+
}
|
|
50
|
+
/** Structural snapshot of one table. */
|
|
51
|
+
interface TableSnapshot {
|
|
52
|
+
/** Field name → {@link FieldSnapshot}, in declared order. */
|
|
53
|
+
fields: Record<string, FieldSnapshot>;
|
|
54
|
+
/** Index name → {@link IndexSnapshot}. */
|
|
55
|
+
indexes: Record<string, IndexSnapshot>;
|
|
56
|
+
/** Relation accessor name → {@link RelationSnapshot}. */
|
|
57
|
+
relations: Record<string, RelationSnapshot>;
|
|
58
|
+
/**
|
|
59
|
+
* `"root"` (default single-DO), `"global"` (D1-replicated), or
|
|
60
|
+
* `"shardBy:<field>"` (partitioned). Encoded as a string so the snapshot
|
|
61
|
+
* stays a plain JSON-stable value.
|
|
62
|
+
*/
|
|
63
|
+
shardMode: string;
|
|
64
|
+
}
|
|
65
|
+
/** A deterministic structural view of the whole schema at one point in time. */
|
|
66
|
+
interface SchemaSnapshot {
|
|
67
|
+
/**
|
|
68
|
+
* Cloudflare DO data-residency jurisdiction declared via `.jurisdiction("…")`,
|
|
69
|
+
* or absent. Tracked because changing it strands all existing Durable Object
|
|
70
|
+
* data (a DO name maps to a different ID per jurisdiction). Optional, so old
|
|
71
|
+
* baselines written before this field parse cleanly (absent ⇒ undefined).
|
|
72
|
+
*
|
|
73
|
+
* Typed as a plain `string` (not the authoring union) on purpose: this is
|
|
74
|
+
* STORED data that a newer Lunora may have written with a jurisdiction this
|
|
75
|
+
* version doesn't yet know. Preserving the raw value keeps the breaking
|
|
76
|
+
* `changedJurisdiction` diff correct under a downgrade — coercing an unknown
|
|
77
|
+
* value to `undefined` would fail OPEN and hide the most destructive change.
|
|
78
|
+
*/
|
|
79
|
+
jurisdiction?: string;
|
|
80
|
+
/** Sorted list of every declared `defineMigration` id at capture time. */
|
|
81
|
+
migrationIds: ReadonlyArray<string>;
|
|
82
|
+
/** Table name → {@link TableSnapshot}, keys sorted for stable serialization. */
|
|
83
|
+
tables: Record<string, TableSnapshot>;
|
|
84
|
+
version: typeof SCHEMA_SNAPSHOT_VERSION;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Whether a change is anchored to one table's own shape, or to the schema as a
|
|
88
|
+
* whole.
|
|
89
|
+
*
|
|
90
|
+
* This is the signal a UI needs to decide which tables to mark as changed, and
|
|
91
|
+
* it lives HERE — next to the change union it classifies — rather than as a
|
|
92
|
+
* hand-maintained set of type names in the consumer. A set in the consumer gives
|
|
93
|
+
* zero compile-time pressure: adding a variant to `DriftChange["type"]` would
|
|
94
|
+
* silently render an affected table as untouched, which is exactly the
|
|
95
|
+
* UI-disagrees-with-the-deploy-gate divergence this module exists to prevent.
|
|
96
|
+
*/
|
|
97
|
+
type DriftScope = "schema" | "table";
|
|
98
|
+
/** One classified structural change between two snapshots. */
|
|
99
|
+
interface DriftChange {
|
|
100
|
+
/**
|
|
101
|
+
* `"table"` means this table's own DDL moved (fields, indexes, shard mode) —
|
|
102
|
+
* a relation whose foreign key lives on the OTHER table stays `"schema"`, so
|
|
103
|
+
* the "changed" signal keeps meaning "this table's shape moved".
|
|
104
|
+
*/
|
|
105
|
+
scope: DriftScope;
|
|
106
|
+
/** `"breaking"` changes need a data migration; `"safe"` changes are additive. */
|
|
107
|
+
severity: "breaking" | "safe";
|
|
108
|
+
/** Human-readable, actionable description (used in the gate message). */
|
|
109
|
+
summary: string;
|
|
110
|
+
/** The table this change belongs to. Always set when `scope` is `"table"`. */
|
|
111
|
+
table?: string;
|
|
112
|
+
/** A machine-readable change discriminator. */
|
|
113
|
+
type: "addedIndex" | "addedOptionalField" | "addedRelation" | "addedRequiredField" | "addedTable" | "changedFieldKind" | "changedIndex" | "changedJurisdiction" | "changedShardMode" | "fieldOptionalToRequired" | "fieldRequiredToOptional" | "removedField" | "removedIndex" | "removedRelation" | "removedTable";
|
|
114
|
+
}
|
|
115
|
+
/** The result of diffing two snapshots: every classified change. */
|
|
116
|
+
interface SchemaDrift {
|
|
117
|
+
/** Every classified change, in a stable order (added/changed per table, then removals). */
|
|
118
|
+
changes: ReadonlyArray<DriftChange>;
|
|
119
|
+
}
|
|
120
|
+
/** Serialize a snapshot to the exact bytes written to `lunora/.lunora-schema.json` (trailing newline). */
|
|
121
|
+
declare const serializeSchemaSnapshot: (snapshot: SchemaSnapshot) => string;
|
|
122
|
+
/**
|
|
123
|
+
* Diff the current snapshot against a baseline and classify every structural
|
|
124
|
+
* change. Pure — no I/O. When `baseline` is `undefined` (no snapshot yet) there
|
|
125
|
+
* is no drift to report: every table is treated as a fresh additive
|
|
126
|
+
* `addedTable`, so a first deploy is never blocked.
|
|
127
|
+
*/
|
|
128
|
+
declare const diffSchemaSnapshots: (baseline: SchemaSnapshot | undefined, current: SchemaSnapshot) => SchemaDrift;
|
|
9
129
|
/**
|
|
10
130
|
* AST-observable subset of a column's modifier chain (`.unique()`, `.default()`,
|
|
11
131
|
* …). Function-valued modifiers (`.$defaultFn`/`.$onUpdateFn`) can't be
|
|
@@ -2300,6 +2420,14 @@ interface EmitShardOptions {
|
|
|
2300
2420
|
queues?: ReadonlyArray<QueueIR>;
|
|
2301
2421
|
rlsMetadata?: RlsMetadataIR;
|
|
2302
2422
|
schema: SchemaIR;
|
|
2423
|
+
/**
|
|
2424
|
+
* The structural snapshot the pre-deploy drift gate diffs against, threaded
|
|
2425
|
+
* in so the emitted DO records it in `__lunora_schema_history` on cold start
|
|
2426
|
+
* (plan 200 — the Studio's schema-version timeline). Optional so an emitter
|
|
2427
|
+
* caller that has no snapshot (tests, fixtures) emits the pre-ledger shape
|
|
2428
|
+
* unchanged.
|
|
2429
|
+
*/
|
|
2430
|
+
schemaSnapshot?: SchemaSnapshot;
|
|
2303
2431
|
/** Replication shapes declared via `defineShape` in `lunora/shapes.ts` — wires the `resolveShape` subscription override. */
|
|
2304
2432
|
shapes?: ReadonlyArray<ShapeIR>;
|
|
2305
2433
|
storageRules?: StorageRulesMetadataIR;
|
|
@@ -2308,7 +2436,7 @@ interface EmitShardOptions {
|
|
|
2308
2436
|
useUmbrella?: boolean;
|
|
2309
2437
|
workflows?: ReadonlyArray<WorkflowIR>;
|
|
2310
2438
|
}
|
|
2311
|
-
declare const emitShard: ({ advisories, agents, containers, env, flagKeys, hasAccessFacade, hasAi, hasAnalytics, hasBrowser, hasFlags, hasHyperdrive, hasImages, hasKv, hasNotify, hasPayments, hasPipelines, hasR2sql, hasX402, maskMetadata, mutators, queues, rlsMetadata, schema, shapes, storageRules, studioFeatures, useUmbrella, workflows }: EmitShardOptions) => string;
|
|
2439
|
+
declare const emitShard: ({ advisories, agents, containers, env, flagKeys, hasAccessFacade, hasAi, hasAnalytics, hasBrowser, hasFlags, hasHyperdrive, hasImages, hasKv, hasNotify, hasPayments, hasPipelines, hasR2sql, hasX402, maskMetadata, mutators, queues, rlsMetadata, schema, schemaSnapshot, shapes, storageRules, studioFeatures, useUmbrella, workflows }: EmitShardOptions) => string;
|
|
2312
2440
|
/**
|
|
2313
2441
|
* Emit drizzle `sqliteTable` definitions for the project schema, split into
|
|
2314
2442
|
* `global` (D1-backed) and `shard` (DO-SQLite-backed) buckets. Tables marked
|
|
@@ -2540,140 +2668,6 @@ declare const emitOpenRpc: (input: OpenRpcEmitInput) => string;
|
|
|
2540
2668
|
* the object returned by {@link buildOpenRpcDocument} (reused, never recomputed).
|
|
2541
2669
|
*/
|
|
2542
2670
|
declare const emitOpenRpcModule: (document_: Record<string, unknown>) => string;
|
|
2543
|
-
/** Current snapshot format version. Bumped if the structural shape below changes. */
|
|
2544
|
-
declare const SCHEMA_SNAPSHOT_VERSION: 1;
|
|
2545
|
-
/** A single field's structural shape: its value kind and whether it is optional. */
|
|
2546
|
-
interface FieldSnapshot {
|
|
2547
|
-
/** The validator kind (`string`, `number`, `id`, `object`, …) after unwrapping `v.optional`. */
|
|
2548
|
-
kind: string;
|
|
2549
|
-
/** True when declared `v.optional(...)` — accepts `undefined` / absent on insert. */
|
|
2550
|
-
optional: boolean;
|
|
2551
|
-
}
|
|
2552
|
-
/** A single secondary index's structural shape. */
|
|
2553
|
-
interface IndexSnapshot {
|
|
2554
|
-
fields: ReadonlyArray<string>;
|
|
2555
|
-
unique: boolean;
|
|
2556
|
-
}
|
|
2557
|
-
/** A single relation's structural shape. */
|
|
2558
|
-
interface RelationSnapshot {
|
|
2559
|
-
field: string;
|
|
2560
|
-
kind: "many" | "one";
|
|
2561
|
-
table: string;
|
|
2562
|
-
}
|
|
2563
|
-
/** Structural snapshot of one table. */
|
|
2564
|
-
interface TableSnapshot {
|
|
2565
|
-
/** Field name → {@link FieldSnapshot}, in declared order. */
|
|
2566
|
-
fields: Record<string, FieldSnapshot>;
|
|
2567
|
-
/** Index name → {@link IndexSnapshot}. */
|
|
2568
|
-
indexes: Record<string, IndexSnapshot>;
|
|
2569
|
-
/** Relation accessor name → {@link RelationSnapshot}. */
|
|
2570
|
-
relations: Record<string, RelationSnapshot>;
|
|
2571
|
-
/**
|
|
2572
|
-
* `"root"` (default single-DO), `"global"` (D1-replicated), or
|
|
2573
|
-
* `"shardBy:<field>"` (partitioned). Encoded as a string so the snapshot
|
|
2574
|
-
* stays a plain JSON-stable value.
|
|
2575
|
-
*/
|
|
2576
|
-
shardMode: string;
|
|
2577
|
-
}
|
|
2578
|
-
/** The committed baseline — a deterministic structural view of the whole schema. */
|
|
2579
|
-
interface SchemaSnapshot {
|
|
2580
|
-
/**
|
|
2581
|
-
* Cloudflare DO data-residency jurisdiction declared via `.jurisdiction("…")`,
|
|
2582
|
-
* or absent. Tracked because changing it strands all existing Durable Object
|
|
2583
|
-
* data (a DO name maps to a different ID per jurisdiction). Optional, so old
|
|
2584
|
-
* baselines written before this field parse cleanly (absent ⇒ undefined).
|
|
2585
|
-
*
|
|
2586
|
-
* Typed as a plain `string` (not the authoring union) on purpose: this is
|
|
2587
|
-
* STORED data that a newer Lunora may have written with a jurisdiction this
|
|
2588
|
-
* version doesn't yet know. Preserving the raw value keeps the breaking
|
|
2589
|
-
* `changedJurisdiction` diff correct under a downgrade — coercing an unknown
|
|
2590
|
-
* value to `undefined` would fail OPEN and hide the most destructive change.
|
|
2591
|
-
*/
|
|
2592
|
-
jurisdiction?: string;
|
|
2593
|
-
/** Sorted list of every declared `defineMigration` id at capture time. */
|
|
2594
|
-
migrationIds: ReadonlyArray<string>;
|
|
2595
|
-
/** Table name → {@link TableSnapshot}, keys sorted for stable serialization. */
|
|
2596
|
-
tables: Record<string, TableSnapshot>;
|
|
2597
|
-
version: typeof SCHEMA_SNAPSHOT_VERSION;
|
|
2598
|
-
}
|
|
2599
|
-
/** One classified structural change between the baseline and the current schema. */
|
|
2600
|
-
interface DriftChange {
|
|
2601
|
-
/** `"breaking"` changes need a data migration; `"safe"` changes are additive. */
|
|
2602
|
-
severity: "breaking" | "safe";
|
|
2603
|
-
/** Human-readable, actionable description (used in the gate message). */
|
|
2604
|
-
summary: string;
|
|
2605
|
-
/** A machine-readable change discriminator. */
|
|
2606
|
-
type: "addedIndex" | "addedOptionalField" | "addedRelation" | "addedRequiredField" | "addedTable" | "changedJurisdiction" | "changedFieldKind" | "changedIndex" | "changedShardMode" | "fieldOptionalToRequired" | "fieldRequiredToOptional" | "removedField" | "removedIndex" | "removedRelation" | "removedTable";
|
|
2607
|
-
}
|
|
2608
|
-
/** The result of diffing two snapshots: every classified change. */
|
|
2609
|
-
interface SchemaDrift {
|
|
2610
|
-
/** Every classified change, in a stable order (added/changed per table, then removals). */
|
|
2611
|
-
changes: ReadonlyArray<DriftChange>;
|
|
2612
|
-
}
|
|
2613
|
-
/**
|
|
2614
|
-
* Build a {@link SchemaSnapshot} from a parsed {@link SchemaIR} and the set of
|
|
2615
|
-
* declared migration ids. Tables and migration ids are sorted so the emitted
|
|
2616
|
-
* JSON is byte-stable across runs AND across machines (no spurious diffs /
|
|
2617
|
-
* churn) — see {@link sortKeys} for why that ordering must not be locale-aware.
|
|
2618
|
-
*
|
|
2619
|
-
* Field / index / relation keys are deliberately NOT sorted: they are emitted in
|
|
2620
|
-
* declaration order from the schema source, which is already deterministic for a
|
|
2621
|
-
* given source file and keeps the snapshot readable next to the schema it mirrors.
|
|
2622
|
-
*/
|
|
2623
|
-
declare const buildSchemaSnapshot: (schema: SchemaIR, migrationIds: ReadonlyArray<string>) => SchemaSnapshot;
|
|
2624
|
-
/** Serialize a snapshot to the exact bytes written to `lunora/.lunora-schema.json` (trailing newline). */
|
|
2625
|
-
declare const serializeSchemaSnapshot: (snapshot: SchemaSnapshot) => string;
|
|
2626
|
-
/**
|
|
2627
|
-
* Thrown by {@link parseSchemaSnapshot} when the baseline file exists but is
|
|
2628
|
-
* malformed (bad JSON / wrong version / invalid table shape). Lets the CLI gate
|
|
2629
|
-
* treat a corrupt baseline as a hard error rather than silently degrading to a
|
|
2630
|
-
* "first capture" that would mask drift and then overwrite the bad file.
|
|
2631
|
-
*/
|
|
2632
|
-
declare class SchemaSnapshotParseError extends LunoraError {
|
|
2633
|
-
constructor(message: string);
|
|
2634
|
-
}
|
|
2635
|
-
/**
|
|
2636
|
-
* Parse a committed snapshot file. Returns `undefined` ONLY when the content is
|
|
2637
|
-
* absent/empty; throws {@link SchemaSnapshotParseError} when content is present
|
|
2638
|
-
* but malformed (bad JSON, wrong version, or structurally-invalid tables) so the
|
|
2639
|
-
* caller can distinguish "no baseline yet" (a legitimate first capture) from "a
|
|
2640
|
-
* corrupt baseline" (which must not be silently treated as a first capture).
|
|
2641
|
-
*/
|
|
2642
|
-
declare const parseSchemaSnapshot: (content: string | undefined) => SchemaSnapshot | undefined;
|
|
2643
|
-
/**
|
|
2644
|
-
* Diff the current snapshot against a committed baseline and classify every
|
|
2645
|
-
* structural change. Pure — no I/O. When `baseline` is `undefined` (no committed
|
|
2646
|
-
* snapshot yet) there is no drift to report: every table is treated as a fresh
|
|
2647
|
-
* additive `addedTable`, so a first deploy is never blocked.
|
|
2648
|
-
*/
|
|
2649
|
-
declare const diffSchemaSnapshots: (baseline: SchemaSnapshot | undefined, current: SchemaSnapshot) => SchemaDrift;
|
|
2650
|
-
/** The decision the pre-deploy gate returns. */
|
|
2651
|
-
interface SchemaDriftDecision {
|
|
2652
|
-
/** True when the deploy must be blocked (breaking drift with no new migration, and no override). */
|
|
2653
|
-
blocked: boolean;
|
|
2654
|
-
/** Every classified change (both severities), for reporting. */
|
|
2655
|
-
changes: ReadonlyArray<DriftChange>;
|
|
2656
|
-
/** Migration ids declared now but absent from the baseline — proof a migration was added. */
|
|
2657
|
-
newMigrationIds: ReadonlyArray<string>;
|
|
2658
|
-
/**
|
|
2659
|
-
* A multi-line, actionable explanation. Always present; empty string when
|
|
2660
|
-
* there is no drift at all. Mirrors the D1-placeholder guard's message style.
|
|
2661
|
-
*/
|
|
2662
|
-
reason: string;
|
|
2663
|
-
}
|
|
2664
|
-
/**
|
|
2665
|
-
* Decide whether breaking schema drift should block a deploy.
|
|
2666
|
-
*
|
|
2667
|
-
* Blocks only when the baseline exists (a first-ever capture is never blocking),
|
|
2668
|
-
* there is at least one `breaking` change, no NEW migration id was added since
|
|
2669
|
-
* the baseline, and the `allowDrift` override is not set. Safe-only drift (or
|
|
2670
|
-
* breaking drift accompanied by a new migration id) passes.
|
|
2671
|
-
*/
|
|
2672
|
-
declare const evaluateSchemaDrift: (options: {
|
|
2673
|
-
allowDrift?: boolean;
|
|
2674
|
-
baseline: SchemaSnapshot | undefined;
|
|
2675
|
-
current: SchemaSnapshot;
|
|
2676
|
-
}) => SchemaDriftDecision;
|
|
2677
2671
|
/**
|
|
2678
2672
|
* Committed, tracked baseline file holding the blessed structural schema
|
|
2679
2673
|
* snapshot the pre-deploy drift gate diffs against. Lives in `lunora/` (NOT the
|
|
@@ -2873,6 +2867,66 @@ interface CodegenResult {
|
|
|
2873
2867
|
*/
|
|
2874
2868
|
workflows: ReadonlyArray<WorkflowIR>;
|
|
2875
2869
|
}
|
|
2870
|
+
/**
|
|
2871
|
+
* Build a {@link SchemaSnapshot} from a parsed {@link SchemaIR} and the set of
|
|
2872
|
+
* declared migration ids. Tables and migration ids are sorted so the emitted
|
|
2873
|
+
* JSON is byte-stable across runs AND across machines (no spurious diffs /
|
|
2874
|
+
* churn) — see `sortKeys` in `shared/schema-snapshot.ts` for why that ordering
|
|
2875
|
+
* must not be locale-aware.
|
|
2876
|
+
*
|
|
2877
|
+
* Field / index / relation keys are deliberately NOT sorted: they are emitted in
|
|
2878
|
+
* declaration order from the schema source, which is already deterministic for a
|
|
2879
|
+
* given source file and keeps the snapshot readable next to the schema it mirrors.
|
|
2880
|
+
*/
|
|
2881
|
+
declare const buildSchemaSnapshot: (schema: SchemaIR, migrationIds: ReadonlyArray<string>) => SchemaSnapshot;
|
|
2882
|
+
/**
|
|
2883
|
+
* Thrown by {@link parseSchemaSnapshot} when the baseline file exists but is
|
|
2884
|
+
* malformed (bad JSON / wrong version / invalid table shape). Lets the CLI gate
|
|
2885
|
+
* treat a corrupt baseline as a hard error rather than silently degrading to a
|
|
2886
|
+
* "first capture" that would mask drift and then overwrite the bad file.
|
|
2887
|
+
*/
|
|
2888
|
+
declare class SchemaSnapshotParseError extends LunoraError {
|
|
2889
|
+
constructor(message: string);
|
|
2890
|
+
}
|
|
2891
|
+
/**
|
|
2892
|
+
* Parse a committed snapshot file. Returns `undefined` ONLY when the content is
|
|
2893
|
+
* absent/empty; throws {@link SchemaSnapshotParseError} when content is present
|
|
2894
|
+
* but malformed (bad JSON, wrong version, or structurally-invalid tables) so the
|
|
2895
|
+
* caller can distinguish "no baseline yet" (a legitimate first capture) from "a
|
|
2896
|
+
* corrupt baseline" (which must not be silently treated as a first capture).
|
|
2897
|
+
*
|
|
2898
|
+
* The parsing itself lives in `shared/schema-snapshot.ts` (the Studio reads the
|
|
2899
|
+
* same JSON out of the DO ledger); this wrapper only applies the CLI's policy of
|
|
2900
|
+
* treating a malformed baseline as fatal.
|
|
2901
|
+
*/
|
|
2902
|
+
declare const parseSchemaSnapshot: (content: string | undefined) => SchemaSnapshot | undefined;
|
|
2903
|
+
/** The decision the pre-deploy gate returns. */
|
|
2904
|
+
interface SchemaDriftDecision {
|
|
2905
|
+
/** True when the deploy must be blocked (breaking drift with no new migration, and no override). */
|
|
2906
|
+
blocked: boolean;
|
|
2907
|
+
/** Every classified change (both severities), for reporting. */
|
|
2908
|
+
changes: ReadonlyArray<DriftChange>;
|
|
2909
|
+
/** Migration ids declared now but absent from the baseline — proof a migration was added. */
|
|
2910
|
+
newMigrationIds: ReadonlyArray<string>;
|
|
2911
|
+
/**
|
|
2912
|
+
* A multi-line, actionable explanation. Always present; empty string when
|
|
2913
|
+
* there is no drift at all. Mirrors the D1-placeholder guard's message style.
|
|
2914
|
+
*/
|
|
2915
|
+
reason: string;
|
|
2916
|
+
}
|
|
2917
|
+
/**
|
|
2918
|
+
* Decide whether breaking schema drift should block a deploy.
|
|
2919
|
+
*
|
|
2920
|
+
* Blocks only when the baseline exists (a first-ever capture is never blocking),
|
|
2921
|
+
* there is at least one `breaking` change, no NEW migration id was added since
|
|
2922
|
+
* the baseline, and the `allowDrift` override is not set. Safe-only drift (or
|
|
2923
|
+
* breaking drift accompanied by a new migration id) passes.
|
|
2924
|
+
*/
|
|
2925
|
+
declare const evaluateSchemaDrift: (options: {
|
|
2926
|
+
allowDrift?: boolean;
|
|
2927
|
+
baseline: SchemaSnapshot | undefined;
|
|
2928
|
+
current: SchemaSnapshot;
|
|
2929
|
+
}) => SchemaDriftDecision;
|
|
2876
2930
|
/**
|
|
2877
2931
|
* Convert a {@link SchemaIR} into a synthetic runtime {@link Schema} carrying just
|
|
2878
2932
|
* the `tables[name].shape` surface `@lunora/seed` introspects. System columns
|
|
@@ -2902,4 +2956,4 @@ declare const secretKindOf: (value: string) => string | undefined;
|
|
|
2902
2956
|
/** A redacted preview of a secret value — first 4 chars plus its length, never the full value. */
|
|
2903
2957
|
declare const redact: (value: string) => string;
|
|
2904
2958
|
declare const VERSION = "0.0.0";
|
|
2905
|
-
export { AGENTS_FILENAME, type AgentIR, 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, type LintSchemaOptions, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, 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 SandboxUsage, 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, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, evaluateSchemaDrift, formatAdvisories, lintSchema, parseSchemaSnapshot, redact, refreshCodegenProject, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, validatorIrToJsonSchema };
|
|
2959
|
+
export { AGENTS_FILENAME, type AgentIR, type AuthApiCallIR, CONTAINERS_FILENAME, CodegenDiagnosticError, type CodegenOptions, type CodegenResult, type ContainerIR, type CronJobIR, type DriftChange, type DriftScope, type EmitAppOptions, FLAGS_FILENAME, type FieldSnapshot, type FlagsIR, type FunctionIR, GENERATED_HEADER, type HttpRouteIR, type IndexIR, type IndexSnapshot, type InsertWriteIR, LUNORA_ERROR_CODES, type LintSchemaOptions, MUTATORS_FILENAME, type MaskProcedureIR, type MigrationIR, type MutatorIR, NOTIFY_FILENAME, OPENRPC_VERSION, type OpenApiEmitInput, type 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 SandboxUsage, 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, type WranglerVariableIR, buildOpenApiDocument, buildOpenRpcDocument, buildSchemaSnapshot, createCodegenProject, diagnosticAt, diffSchemaSnapshots, discoverAgents, discoverAuthApiCalls, discoverContainers, discoverCrons, discoverFlags, discoverFunctions, discoverHttpRoutes, discoverInserts, discoverMaskProcedures, discoverMigrations, discoverMutators, discoverNondeterministicCalls, discoverNotifyCalls, discoverNotifyConfig, discoverQueries, discoverQueues, discoverR2sqlCalls, discoverRlsMetadata, discoverRlsProcedures, discoverSandboxUsage, discoverSchema, discoverShapes, discoverStorageRulesMetadata, discoverWorkflows, emitAgents, emitApi, emitApp, emitCollections, emitContainers, emitCrons, emitDataModel, emitDrizzleSchema, emitFunctions, emitOpenApi, emitOpenApiModule, emitOpenRpc, emitOpenRpcModule, emitServer, emitShard, emitVectors, emitWorkflows, emitWranglerCronTriggers, evaluateSchemaDrift, formatAdvisories, lintSchema, parseSchemaSnapshot, redact, refreshCodegenProject, runCodegen, schemaFromIr, secretKindOf, serializeSchemaSnapshot, validatorIrToJsonSchema };
|