@uncutsql/core 0.2.1 → 0.4.0

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.ts CHANGED
@@ -10,12 +10,16 @@ export interface TableIdentity {
10
10
  readonly schema?: string;
11
11
  }
12
12
  export interface Constraint {
13
+ /** Documentation text: non-empty, compared exactly. Absent: no comment. */
14
+ readonly comment?: string;
13
15
  readonly kind: string;
14
16
  readonly properties: {
15
17
  readonly [key: string]: SchemaValue;
16
18
  };
17
19
  }
18
20
  export interface DatabaseColumn {
21
+ /** Documentation text: non-empty, compared exactly. Absent: no comment. */
22
+ readonly comment?: string;
19
23
  readonly constraints: readonly Constraint[];
20
24
  readonly dataType: SchemaValue;
21
25
  readonly key: string;
@@ -23,14 +27,25 @@ export interface DatabaseColumn {
23
27
  }
24
28
  /** Standalone indexes belong to a table; keys are normalized within its namespace. */
25
29
  export interface DatabaseIndex {
30
+ /** Documentation text: non-empty, compared exactly. Absent: no comment. */
31
+ readonly comment?: string;
26
32
  readonly key: string;
27
33
  readonly name: string;
34
+ /**
35
+ * Namespaced keys retain vendor-specific index features without teaching core their meaning.
36
+ * Absent and `{}` are the same value; writers omit the field when it would be empty.
37
+ */
38
+ readonly options?: {
39
+ readonly [key: string]: SchemaValue;
40
+ };
28
41
  readonly terms: readonly SchemaValue[];
29
42
  readonly unique: boolean;
30
43
  readonly where: SchemaValue;
31
44
  }
32
45
  export interface DatabaseTable {
33
46
  readonly columns: readonly DatabaseColumn[];
47
+ /** Documentation text: non-empty, compared exactly. Absent: no comment. */
48
+ readonly comment?: string;
34
49
  readonly constraints: readonly Constraint[];
35
50
  readonly identity: TableIdentity;
36
51
  readonly indexes?: readonly DatabaseIndex[];
@@ -41,25 +56,88 @@ export interface DatabaseTable {
41
56
  };
42
57
  }
43
58
  export interface DatabaseView {
59
+ /**
60
+ * Comments of columns, keyed by output column name; each is non-empty. Absent and `{}` are the
61
+ * same value; writers omit the field when it would be empty.
62
+ */
63
+ readonly columnComments?: {
64
+ readonly [column: string]: string;
65
+ };
44
66
  readonly columns?: readonly string[];
67
+ /** Documentation text: non-empty, compared exactly. Absent: no comment. */
68
+ readonly comment?: string;
45
69
  readonly identity: TableIdentity;
46
70
  readonly name: string;
71
+ /**
72
+ * Namespaced keys retain vendor-specific view features without teaching core their meaning.
73
+ * Absent and `{}` are the same value; writers omit the field when it would be empty.
74
+ */
75
+ readonly options?: {
76
+ readonly [key: string]: SchemaValue;
77
+ };
47
78
  readonly query: SchemaValue;
48
79
  }
49
80
  export interface DatabaseTrigger {
81
+ /** Documentation text: non-empty, compared exactly. Absent: no comment. */
82
+ readonly comment?: string;
50
83
  /** Dialect-normalized timing, event, condition and ordered actions. */
51
84
  readonly definition: SchemaValue;
52
85
  readonly identity: TableIdentity;
53
86
  readonly name: string;
87
+ /**
88
+ * Where the name is unique. Absent: in its namespace (SQLite). `"target"`: on its target
89
+ * (PostgreSQL), so `identity` and `target` together are the key.
90
+ */
91
+ readonly scope?: "target";
54
92
  /** Normalized identity of the table or view that owns this trigger. */
55
93
  readonly target: TableIdentity;
56
94
  }
95
+ export interface SequenceOwner {
96
+ /** A column key of `table`. */
97
+ readonly column: string;
98
+ readonly table: TableIdentity;
99
+ }
100
+ export interface DatabaseSequence {
101
+ /** Documentation text: non-empty, compared exactly. Absent: no comment. */
102
+ readonly comment?: string;
103
+ /**
104
+ * Dialect-normalized data type and parameters. Core compares it with `schemaValueEqual`
105
+ * and never interprets its keys.
106
+ */
107
+ readonly definition: {
108
+ readonly [key: string]: SchemaValue;
109
+ };
110
+ readonly identity: TableIdentity;
111
+ readonly name: string;
112
+ /** The column whose removal drops the sequence. */
113
+ readonly owner?: SequenceOwner;
114
+ }
115
+ export interface DatabaseFunction {
116
+ /** Documentation text: non-empty, compared exactly. Absent: no comment. */
117
+ readonly comment?: string;
118
+ /**
119
+ * Dialect-normalized language, arguments, result, attributes and body. Core compares it with
120
+ * `schemaValueEqual` and never interprets its keys.
121
+ */
122
+ readonly definition: {
123
+ readonly [key: string]: SchemaValue;
124
+ };
125
+ readonly identity: TableIdentity;
126
+ readonly name: string;
127
+ /**
128
+ * Dialect-normalized types of the arguments that identify the function among overloads, in
129
+ * order. Together with `identity` it is the function's key.
130
+ */
131
+ readonly signature: readonly SchemaValue[];
132
+ }
57
133
  /** A container of named objects one level below an optional catalog. Keys are already normalized by the dialect. */
58
134
  export interface NamespaceIdentity {
59
135
  readonly catalog?: string;
60
136
  readonly name: string;
61
137
  }
62
138
  export interface DatabaseNamespace {
139
+ /** Documentation text: non-empty, compared exactly. Absent: no comment. */
140
+ readonly comment?: string;
63
141
  readonly identity: NamespaceIdentity;
64
142
  readonly name: string;
65
143
  /** Namespaced keys retain vendor-specific features without teaching core their meaning. */
@@ -67,14 +145,132 @@ export interface DatabaseNamespace {
67
145
  readonly [key: string]: SchemaValue;
68
146
  };
69
147
  }
148
+ export interface DatabaseExtension {
149
+ /** Documentation text: non-empty, compared exactly. Absent: no comment. */
150
+ readonly comment?: string;
151
+ /** The name as the database stores it. Unique in a model. */
152
+ readonly name: string;
153
+ /** The namespace that holds the extension's objects; absent in dialects without namespaces. */
154
+ readonly schema?: string;
155
+ /** The pinned version. Absent: the server's default version at creation, never compared. */
156
+ readonly version?: string;
157
+ }
158
+ /** A named type that holds one of an ordered list of labels. */
159
+ export interface DatabaseEnum {
160
+ /** Documentation text: non-empty, compared exactly. Absent: no comment. */
161
+ readonly comment?: string;
162
+ readonly identity: TableIdentity;
163
+ readonly name: string;
164
+ /** Labels in sort order, unique, compared exactly (case and spaces count). May be empty. */
165
+ readonly values: readonly string[];
166
+ }
167
+ export interface DatabaseExternals {
168
+ /** Absent and `[]` are the same value; writers omit the field when it would be empty. */
169
+ readonly enums?: readonly DatabaseEnum[];
170
+ /** Absent and `[]` are the same value; writers omit the field when it would be empty. */
171
+ readonly extensions?: readonly DatabaseExtension[];
172
+ /** Absent and `[]` are the same value; writers omit the field when it would be empty. */
173
+ readonly functions?: readonly DatabaseFunction[];
174
+ /** Absent and `[]` are the same value; writers omit the field when it would be empty. */
175
+ readonly tables?: readonly DatabaseTable[];
176
+ }
70
177
  export interface DatabaseSchema {
178
+ /** Absent and `[]` are the same value; writers omit the field when it would be empty. */
179
+ readonly enums?: readonly DatabaseEnum[];
180
+ /** Absent and `[]` are the same value; writers omit the field when it would be empty. */
181
+ readonly extensions?: readonly DatabaseExtension[];
182
+ /**
183
+ * Objects outside the managed scope that the model references. Diff, procedures and lowering
184
+ * never create, alter or drop them. Absent and `{}` are the same value.
185
+ */
186
+ readonly externals?: DatabaseExternals;
187
+ /** Absent and `[]` are the same value; writers omit the field when it would be empty. */
188
+ readonly functions?: readonly DatabaseFunction[];
71
189
  /** Absent means namespaces are not declared and no namespace check runs. */
72
190
  readonly namespaces?: readonly DatabaseNamespace[];
191
+ /** Absent and `[]` are the same value; writers omit the field when it would be empty. */
192
+ readonly sequences?: readonly DatabaseSequence[];
73
193
  readonly tables: readonly DatabaseTable[];
74
194
  readonly triggers?: readonly DatabaseTrigger[];
75
195
  readonly views?: readonly DatabaseView[];
76
196
  }
77
197
  export declare const tableKey: (table: TableIdentity) => string;
198
+ export declare const triggerKey: (trigger: DatabaseTrigger) => string;
199
+ export declare const functionKey: (fn: Pick<DatabaseFunction, "identity" | "signature">) => string;
200
+ /** `schema.name(type, …)` for diagnostics; signature entries that are not strings print as JSON. */
201
+ export declare const functionLabel: (fn: Pick<DatabaseFunction, "identity" | "signature">) => string;
202
+ export interface ExternalObject {
203
+ /** Set when the external is a function. */
204
+ readonly function?: DatabaseFunction;
205
+ readonly identity: TableIdentity;
206
+ /** `External table schema.name` or `External function schema.name(type, …)`. */
207
+ readonly label: string;
208
+ }
209
+ /** The external objects of the models, tables before functions, each listed once by its key. */
210
+ export declare const externalObjects: (...databases: readonly DatabaseSchema[]) => readonly ExternalObject[];
211
+ export interface EnumObject {
212
+ readonly identity: TableIdentity;
213
+ /** `Enum schema.name` or `External enum schema.name`. */
214
+ readonly label: string;
215
+ }
216
+ /** The managed and external enums of the models, each listed once by its key. */
217
+ export declare const enumObjects: (...databases: readonly DatabaseSchema[]) => readonly EnumObject[];
218
+ /** The managed and external extensions of the models, each listed once by its name. */
219
+ export declare const extensionObjects: (...databases: readonly DatabaseSchema[]) => readonly DatabaseExtension[];
220
+ /** The object a comment belongs to. Table, column and other names are those of the after model. */
221
+ export type CommentTarget = {
222
+ readonly identity: TableIdentity;
223
+ readonly kind: "enum" | "sequence" | "table" | "view";
224
+ } |
225
+ /** `column` is a column key. */
226
+ {
227
+ readonly column: string;
228
+ readonly kind: "column";
229
+ readonly table: TableIdentity;
230
+ } |
231
+ /** `column` is an output column name. */
232
+ {
233
+ readonly column: string;
234
+ readonly kind: "viewColumn";
235
+ readonly view: TableIdentity;
236
+ } |
237
+ /** `index` is an index key. */
238
+ {
239
+ readonly index: string;
240
+ readonly kind: "index";
241
+ readonly table: TableIdentity;
242
+ } |
243
+ /** Core does not know constraint names: the constraint is its value, without its comment. */
244
+ {
245
+ readonly constraint: Constraint;
246
+ readonly kind: "constraint";
247
+ readonly table: TableIdentity;
248
+ } | {
249
+ readonly identity: TableIdentity;
250
+ readonly kind: "function";
251
+ readonly signature: readonly SchemaValue[];
252
+ } | {
253
+ readonly kind: "trigger";
254
+ readonly name: string;
255
+ readonly target: TableIdentity;
256
+ } | {
257
+ readonly identity: NamespaceIdentity;
258
+ readonly kind: "namespace";
259
+ } | {
260
+ readonly kind: "extension";
261
+ readonly name: string;
262
+ };
263
+ export interface CommentObject {
264
+ /** The relation or named object, for the location of a diagnostic. */
265
+ readonly identity: TableIdentity;
266
+ /** `Comment on table schema.name`, `Comment on column schema.table.column`, and so on. */
267
+ readonly label: string;
268
+ }
269
+ /**
270
+ * Every commented object of the models, externals included, and of `targets` (for example those of
271
+ * `SetComment` procedures), each listed once by its label. A dialect without comments refuses them.
272
+ */
273
+ export declare const commentObjects: (databases: readonly DatabaseSchema[], targets?: readonly CommentTarget[]) => readonly CommentObject[];
78
274
  export declare const namespaceKey: (namespace: NamespaceIdentity) => string;
79
275
  /** The namespace that contains an object, or undefined when its identity has no schema level. */
80
276
  export declare const namespaceOf: (identity: TableIdentity) => NamespaceIdentity | undefined;
@@ -176,6 +372,45 @@ export type TriggerChange = {
176
372
  readonly after: DatabaseTrigger;
177
373
  readonly before: DatabaseTrigger;
178
374
  };
375
+ export type SequenceChange = {
376
+ readonly _tag: "SequenceAdded" | "SequenceRemoved";
377
+ readonly sequence: DatabaseSequence;
378
+ } | {
379
+ readonly _tag: "SequenceChanged" | "SequenceRenamed";
380
+ readonly after: DatabaseSequence;
381
+ readonly before: DatabaseSequence;
382
+ };
383
+ export type FunctionChange = {
384
+ readonly _tag: "FunctionAdded" | "FunctionRemoved";
385
+ readonly function: DatabaseFunction;
386
+ } | {
387
+ readonly _tag: "FunctionChanged";
388
+ readonly after: DatabaseFunction;
389
+ readonly before: DatabaseFunction;
390
+ };
391
+ export interface EnumValueRename {
392
+ readonly after: string;
393
+ readonly before: string;
394
+ }
395
+ export type EnumChange = {
396
+ readonly _tag: "EnumAdded" | "EnumRemoved";
397
+ readonly enum: DatabaseEnum;
398
+ } | {
399
+ readonly _tag: "EnumRenamed" | "EnumChanged";
400
+ readonly after: DatabaseEnum;
401
+ readonly before: DatabaseEnum;
402
+ /** The accepted value renames. Other label differences are additions, removals or order. */
403
+ readonly values: readonly EnumValueRename[];
404
+ };
405
+ /** An extension that changes both its version and its schema has one change of each. */
406
+ export type ExtensionChange = {
407
+ readonly _tag: "ExtensionAdded" | "ExtensionRemoved";
408
+ readonly extension: DatabaseExtension;
409
+ } | {
410
+ readonly _tag: "ExtensionVersionChanged" | "ExtensionSchemaChanged";
411
+ readonly after: DatabaseExtension;
412
+ readonly before: DatabaseExtension;
413
+ };
179
414
  /** A namespace change lists the namespace only; objects inside it keep their own changes. */
180
415
  export type NamespaceChange = {
181
416
  readonly _tag: "NamespaceAdded" | "NamespaceRemoved";
@@ -185,17 +420,65 @@ export type NamespaceChange = {
185
420
  readonly after: DatabaseNamespace;
186
421
  readonly before: DatabaseNamespace;
187
422
  };
423
+ /** A changed comment of an object that both models hold. `target` names it in the after model. */
424
+ export interface CommentChange {
425
+ readonly _tag: "CommentChanged";
426
+ readonly after?: string;
427
+ readonly before?: string;
428
+ readonly target: CommentTarget;
429
+ }
188
430
  export interface DropGuard {
189
431
  /** Source column name. Omit to require an empty table. */
190
432
  readonly column?: string;
191
433
  readonly table: TableIdentity;
192
434
  }
193
435
  export interface DatabaseDiff {
194
- readonly changes: readonly (NamespaceChange | TableChange | ViewChange | TriggerChange)[];
436
+ readonly changes: readonly (NamespaceChange | EnumChange | ExtensionChange | TableChange | ViewChange | TriggerChange | SequenceChange | FunctionChange | CommentChange)[];
195
437
  readonly dropGuards?: readonly DropGuard[];
196
438
  }
197
439
  export declare const validateDatabase: (database: DatabaseSchema, side: DiffDiagnostic["side"]) => readonly DiffDiagnostic[];
440
+ /**
441
+ * Checks an explicit list of managed schemas against the namespaces of a model built from schema
442
+ * files. Names are compared as catalog names, case-sensitively. The shape of the list (non-empty,
443
+ * unique, including `public`) is the caller's to validate.
444
+ */
445
+ export declare const checkManagedScope: (model: DatabaseSchema, managedSchemas: readonly string[]) => readonly DiffDiagnostic[];
446
+ /** Same kinds and properties in the same order; comments are compared by `diffComments`. */
447
+ export declare const constraintsEqual: (before: readonly Constraint[], after: readonly Constraint[]) => boolean;
198
448
  export declare const compareTable: (before: DatabaseTable, after: DatabaseTable) => readonly TableAlteration[];
449
+ /** Table and column renames of a migration, keyed by the table's key before the rename. */
450
+ export interface SequenceRenames {
451
+ readonly columns: ReadonlyMap<string, ReadonlyMap<string, string>>;
452
+ readonly tables: ReadonlyMap<string, TableIdentity>;
453
+ }
454
+ /** Collect the table and column renames that a list of changes carries. */
455
+ export declare const sequenceRenames: (changes: DatabaseDiff["changes"]) => SequenceRenames;
456
+ /** Function changes. A changed signature is another key: a removal and an addition. */
457
+ export declare const diffFunctions: (before: DatabaseSchema, after: DatabaseSchema) => readonly FunctionChange[];
458
+ /** Sequence changes. `renames` are the table and column renames the migration applies. */
459
+ export declare const diffSequences: (before: DatabaseSchema, after: DatabaseSchema, renames?: SequenceRenames) => readonly SequenceChange[];
460
+ /**
461
+ * Trigger changes, paired by `triggerKey`. `renames` are the table renames the migration applies: a
462
+ * trigger follows its renamed target. There are no trigger renames.
463
+ */
464
+ export declare const diffTriggers: (before: DatabaseSchema, after: DatabaseSchema, renames?: SequenceRenames) => readonly TriggerChange[];
465
+ /** The enum and value renames of a migration, keyed by the enum's key before the rename. */
466
+ export interface EnumRenames {
467
+ readonly enums: ReadonlyMap<string, TableIdentity>;
468
+ /** Per enum, each renamed label before and after. */
469
+ readonly values: ReadonlyMap<string, ReadonlyMap<string, string>>;
470
+ }
471
+ /**
472
+ * Enum changes, paired by `tableKey`. A renamed enum has one `EnumRenamed`, whether or not its
473
+ * labels differ too. Removals and order are not judged here; external enums are ignored.
474
+ */
475
+ export declare const diffEnums: (before: DatabaseSchema, after: DatabaseSchema, renames?: EnumRenames) => readonly EnumChange[];
476
+ /**
477
+ * Comment changes of the managed objects that both models hold. `changes` are the changes of the
478
+ * migration: their table, column, sequence and enum renames pair objects across a rename. Added and
479
+ * removed objects have no change here.
480
+ */
481
+ export declare const diffComments: (before: DatabaseSchema, after: DatabaseSchema, changes?: DatabaseDiff["changes"]) => readonly CommentChange[];
199
482
  /** Compare normalized relational models without parsing SQL or consulting a dialect. */
200
483
  export declare const diffDatabases: (before: DatabaseSchema, after: DatabaseSchema) => Effect.Effect<DatabaseDiff, SchemaDiffError>;
201
484
  interface TableProcedure {
@@ -211,6 +494,42 @@ export type MigrationProcedure = {
211
494
  readonly _tag: "AlterNamespace";
212
495
  readonly after: DatabaseNamespace;
213
496
  readonly before: DatabaseNamespace;
497
+ } | {
498
+ readonly _tag: "CreateEnum" | "DropEnum";
499
+ readonly enum: DatabaseEnum;
500
+ } | {
501
+ readonly _tag: "RenameEnum" | "AlterEnum";
502
+ readonly after: DatabaseEnum;
503
+ readonly before: DatabaseEnum;
504
+ /** Labels to rename; other label differences are additions, removals or order. */
505
+ readonly values: readonly EnumValueRename[];
506
+ } | {
507
+ readonly _tag: "CreateExtension" | "DropExtension";
508
+ readonly extension: DatabaseExtension;
509
+ } | {
510
+ /** Changes the pinned version. */
511
+ readonly _tag: "UpdateExtension";
512
+ readonly after: DatabaseExtension;
513
+ readonly before: DatabaseExtension;
514
+ } | {
515
+ /** Changes the schema. */
516
+ readonly _tag: "MoveExtension";
517
+ readonly after: DatabaseExtension;
518
+ readonly before: DatabaseExtension;
519
+ } | {
520
+ readonly _tag: "CreateFunction" | "DropFunction";
521
+ readonly function: DatabaseFunction;
522
+ } | {
523
+ readonly _tag: "ReplaceFunction";
524
+ readonly after: DatabaseFunction;
525
+ readonly before: DatabaseFunction;
526
+ } | {
527
+ readonly _tag: "CreateSequence" | "DropSequence";
528
+ readonly sequence: DatabaseSequence;
529
+ } | {
530
+ readonly _tag: "AlterSequence" | "RenameSequence";
531
+ readonly after: DatabaseSequence;
532
+ readonly before: DatabaseSequence;
214
533
  } | {
215
534
  readonly _tag: "CreateTrigger" | "DropTrigger";
216
535
  readonly trigger: DatabaseTrigger;
@@ -235,7 +554,13 @@ export type MigrationProcedure = {
235
554
  readonly _tag: "AlterTable";
236
555
  }) | (TableProcedure & {
237
556
  readonly _tag: "RenameTable";
238
- });
557
+ }) | {
558
+ /** Sets, changes or (without `after`) removes the comment of an object that both models hold. */
559
+ readonly _tag: "SetComment";
560
+ readonly after?: string;
561
+ readonly before?: string;
562
+ readonly target: CommentTarget;
563
+ };
239
564
  export interface DatabaseMigration {
240
565
  readonly dropGuards?: readonly DropGuard[];
241
566
  readonly procedures: readonly MigrationProcedure[];
@@ -272,7 +597,7 @@ interface SemanticStructField extends SemanticElement {
272
597
  }
273
598
  /**
274
599
  * Dialect-neutral, non-null database values. Numeric bounds are inclusive and exact decimal strings.
275
- * Nested domains are equal when they are structurally equal, field order included.
600
+ * Domains are equal when they are structurally equal, field and value order included.
276
601
  */
277
602
  type SemanticValueDomain = {
278
603
  readonly kind: "decimal" | "integer" | "real";
@@ -285,7 +610,14 @@ type SemanticValueDomain = {
285
610
  readonly scale?: number;
286
611
  };
287
612
  } | {
288
- readonly kind: "binary" | "boolean" | "date" | "json" | "opaque" | "text" | "time" | "timestamp";
613
+ readonly kind: "binary" | "boolean" | "date" | "json" | "opaque" | "time" | "timestamp";
614
+ } | {
615
+ readonly kind: "text";
616
+ /**
617
+ * The only non-null values the type allows, in the type's order: unique, compared exactly,
618
+ * possibly empty. Absent: any text.
619
+ */
620
+ readonly values?: readonly string[];
289
621
  } | {
290
622
  /** An ordered sequence. */
291
623
  readonly element: SemanticElement;
@@ -321,6 +653,8 @@ interface SemanticInsertPolicy extends SemanticWritePolicy {
321
653
  readonly omission: SemanticFact<"allowed" | "required">;
322
654
  }
323
655
  interface SemanticColumn {
656
+ /** The column's comment: non-empty, as the database stores it. */
657
+ readonly comment?: string;
324
658
  /** A known null means there is no computed expression. */
325
659
  readonly computed: SemanticFact<{
326
660
  readonly storage: SemanticFact<"stored" | "virtual">;
@@ -360,6 +694,8 @@ interface SemanticForeignKey {
360
694
  readonly target: SemanticForeignKeyTarget;
361
695
  }
362
696
  interface SemanticRelationIdentity {
697
+ /** The relation's comment: non-empty, as the database stores it. */
698
+ readonly comment?: string;
363
699
  readonly identity: TableIdentity;
364
700
  readonly kind: "table" | "view";
365
701
  /** Original SQL relation name. */
@@ -419,6 +755,11 @@ interface Dialect<Ast, PhysicalPlan, E extends Error = Error, R = never, Semanti
419
755
  * `false`, a migration with guards is refused before lowering.
420
756
  */
421
757
  readonly supportsDropGuards?: boolean;
758
+ /**
759
+ * When `true`, a project may list the schemas it manages (ADR 0024 Decision 1). When absent or
760
+ * `false`, the caller refuses such a list by name.
761
+ */
762
+ readonly supportsManagedSchemas?: boolean;
422
763
  readonly toDatabaseSchema: (ast: Ast, side?: DiffDiagnostic["side"]) => Effect.Effect<DatabaseSchema, E, R>;
423
764
  }
424
765
  declare const SchemaModelError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
@@ -452,24 +793,56 @@ interface ExecutionResult {
452
793
  readonly lastAppliedId: number;
453
794
  readonly rolledBackId?: number;
454
795
  }
796
+ interface ReplayOptions {
797
+ /** External declarations of the generation lock, created as stand-ins before replay (ADR 0024). */
798
+ readonly externals?: DatabaseExternals;
799
+ /** A database to replay in instead of the driver's default; nothing is kept in it. */
800
+ readonly replayDatabase?: string;
801
+ }
802
+ interface ExtractOptions {
803
+ /** ADR 0024 managed schemas. Set only when configured and the dialect supports them. */
804
+ readonly managedSchemas?: readonly string[];
805
+ }
806
+ interface ExtractedPart {
807
+ /** The owning object, as written in messages. */
808
+ readonly name: string;
809
+ /** Directory segments, then the file stem, relative to the destination. Absent means `[name]`. */
810
+ readonly path?: readonly string[];
811
+ readonly sql: string;
812
+ }
813
+ interface ExtractOmission {
814
+ readonly category: "dependent" | "unmanaged" | "unsupported";
815
+ /** For `dependent`, the omitted object it depends on; otherwise an optional reason. */
816
+ readonly detail?: string;
817
+ /** For example "partitioned table", "policy", "column type ltree". */
818
+ readonly kind: string;
819
+ /** Qualified catalog name: schema.object, then the sub-object (column, constraint, index, trigger, policy). */
820
+ readonly name: string;
821
+ }
822
+ interface ExtractResult {
823
+ /** Informational lines printed after success. */
824
+ readonly notes?: readonly string[];
825
+ readonly omitted: readonly ExtractOmission[];
826
+ /** In load order: concatenated in this order, and sorted by path, the parts give the same order. */
827
+ readonly parts: readonly ExtractedPart[];
828
+ }
829
+ /** One line per omission, ordered by category (unsupported, unmanaged, dependent), then name. */
830
+ export declare const formatExtractOmissions: (omitted: readonly ExtractOmission[]) => readonly string[];
455
831
  /** Optional execution capability, selected and wired by the consumer separately from syntax. */
456
832
  interface MigrationExecutor<E extends Error = Error, R = never> {
457
833
  /** Verify a replayed prefix against an existing target, then initialize its history. */
458
- readonly adopt?: <V extends Error, RV>(target: string, prefix: readonly MigrationSource[], verifySchema: (actual: DatabaseSchema, expected: DatabaseSchema) => Effect.Effect<void, V, RV>, desired?: DatabaseSchema) => Effect.Effect<void, E | V, R | RV>;
834
+ readonly adopt?: <V extends Error, RV>(target: string, prefix: readonly MigrationSource[], verifySchema: (actual: DatabaseSchema, expected: DatabaseSchema) => Effect.Effect<void, V, RV>, desired?: DatabaseSchema, options?: ReplayOptions) => Effect.Effect<void, E | V, R | RV>;
459
835
  readonly apply: <V extends Error, RV>(target: string, migrations: readonly MigrationSource[], desired: DatabaseSchema, verifySchema: (actual: DatabaseSchema, expected: DatabaseSchema, stage: "applied" | "desired") => Effect.Effect<void, V, RV>,
460
836
  /** With a checkpoint, files start immediately after it (at it for rollback).
461
837
  * Recheck the database position under the write transaction before executing. */
462
838
  checkpoint?: MigrationCheckpoint) => Effect.Effect<ExecutionResult, E | V, R | RV>;
463
839
  readonly checkpoint: (target: string) => Effect.Effect<MigrationCheckpoint, E, R>;
464
840
  /** Replay a verified prefix on an empty database and render its state as one SQL migration. */
465
- readonly compact?: (migrations: readonly MigrationSource[]) => Effect.Effect<string, E, R>;
841
+ readonly compact?: (migrations: readonly MigrationSource[], options?: ReplayOptions) => Effect.Effect<string, E, R>;
466
842
  /** Equal to the `Dialect.name` that produced the lock. Core and the CLI compare it only for equality. */
467
843
  readonly dialect: string;
468
- /** Schema-only SQL grouped by owning relation, in declaration order. */
469
- readonly extract?: (target: string) => Effect.Effect<readonly {
470
- readonly name: string;
471
- readonly sql: string;
472
- }[], E, R>;
844
+ /** Schema-only SQL in parts, with the objects the driver left out. */
845
+ readonly extract?: (target: string, options?: ExtractOptions) => Effect.Effect<ExtractResult, E, R>;
473
846
  /** Undo only the most recently applied migration. */
474
847
  readonly rollback?: MigrationExecutor<E, R>["apply"];
475
848
  }
@@ -488,10 +861,9 @@ export declare const migrationRun: (direction: "up" | "down", migrations: readon
488
861
  export declare const continuesRun: (run: MigrationRun, migrations: readonly MigrationSource[], checkpoint: MigrationCheckpoint | undefined, tip: MigrationCheckpoint) => boolean;
489
862
  /** The file to execute after the tip, or `undefined` when the run is complete. */
490
863
  export declare const nextMigration: (run: MigrationRun, migrations: readonly MigrationSource[], tipId: number) => MigrationSource | undefined;
491
- export interface MigrationDecision {
492
- /** Added table names or column keys, not guesses: no candidate is selected automatically. */
864
+ interface DecisionQuestion {
865
+ /** Added names, column keys or enum labels, not guesses: none is selected automatically. */
493
866
  readonly candidates: readonly string[];
494
- readonly column?: string;
495
867
  readonly id: string;
496
868
  readonly question: string;
497
869
  readonly resolution: {
@@ -502,8 +874,19 @@ export interface MigrationDecision {
502
874
  readonly action: "rename";
503
875
  readonly target: string;
504
876
  };
877
+ }
878
+ /** A removed table, or a removed column when `column` is set. */
879
+ export interface TableMigrationDecision extends DecisionQuestion {
880
+ readonly column?: string;
505
881
  readonly table: TableIdentity;
506
882
  }
883
+ /** A removed enum, or a removed label when `value` is set. `drop_if_empty` does not apply. */
884
+ export interface EnumMigrationDecision extends DecisionQuestion {
885
+ /** The enum's identity before the migration. */
886
+ readonly enum: TableIdentity;
887
+ readonly value?: string;
888
+ }
889
+ export type MigrationDecision = TableMigrationDecision | EnumMigrationDecision;
507
890
  export interface MigrationDecisions {
508
891
  readonly after: DatabaseSchema;
509
892
  readonly before: DatabaseSchema;
@@ -540,7 +923,7 @@ export interface SourceSpan {
540
923
  readonly end: number;
541
924
  readonly start: number;
542
925
  }
543
- export type SchemaSymbolKind = "column" | "index" | "namespace" | "table" | "trigger" | "view";
926
+ export type SchemaSymbolKind = "column" | "extension" | "function" | "index" | "namespace" | "table" | "trigger" | "type" | "view";
544
927
  export interface SchemaSymbol {
545
928
  readonly children: readonly SchemaSymbol[];
546
929
  /** Short context shown next to the name, such as the written namespace. */
@@ -556,25 +939,98 @@ export interface SchemaDiagnostic extends SourceSpan {
556
939
  /** A declaration that references can target. `key` is opaque and normalized by the dialect. */
557
940
  export interface SchemaDeclaration {
558
941
  readonly key: string;
942
+ /** What is declared. A declaration without `kind` is never a completion candidate. */
943
+ readonly kind?: SchemaSymbolKind;
944
+ /** Opaque, dialect-normalized key of the declared name alone. Its presence makes the declaration renamable. */
945
+ readonly nameKey?: string;
946
+ /** Tables only: SQL text that denotes the table from any namespace, such as `app.orders`. */
947
+ readonly qualifiedText?: string;
948
+ /** Opaque key of the scope in which the name is unique: a namespace for a table, the table key for a column. */
949
+ readonly scope?: string;
559
950
  readonly selection: SourceSpan;
951
+ /** SQL text that denotes the name alone, quoted when the dialect requires it. */
952
+ readonly text?: string;
560
953
  }
561
954
  export interface SchemaReference extends SourceSpan {
562
955
  readonly key: string;
956
+ /** The name token alone, when the span also covers a qualifier (`public.users`). */
957
+ readonly selection?: SourceSpan;
958
+ }
959
+ /** Where an unresolved identifier token was found. */
960
+ export type SchemaNameContext = "check" | "comment" | "default" | "generated" | "index" | "query" | "table" | "trigger" | "type" | "view";
961
+ /** An identifier token the service does not resolve. `nameKey` is built like `SchemaDeclaration.nameKey`. */
962
+ export interface SchemaNameUse extends SourceSpan {
963
+ readonly context: SchemaNameContext;
964
+ readonly nameKey: string;
563
965
  }
564
966
  export interface SchemaAnalysis {
565
967
  readonly declarations: readonly SchemaDeclaration[];
566
968
  readonly diagnostics: readonly SchemaDiagnostic[];
969
+ /** Uses that rename edits but no other feature reads (Decision 2). */
970
+ readonly occurrences?: readonly SchemaReference[];
567
971
  readonly references: readonly SchemaReference[];
568
972
  readonly symbols: readonly SchemaSymbol[];
973
+ /** Identifier tokens in constructs the service does not resolve (Decision 5). */
974
+ readonly unresolvedNames?: readonly SchemaNameUse[];
975
+ }
976
+ /** A validated new name: its key and the SQL text written at every edited site. */
977
+ export interface SchemaName {
978
+ readonly nameKey: string;
979
+ readonly text: string;
980
+ }
981
+ export type SchemaCompletionKind = "column" | "table";
982
+ /** What a completion request expects at the cursor. Keys are opaque, as everywhere else. */
983
+ export interface SchemaCompletion {
984
+ /** Declarations of the probed statement, with offsets in `source`, which no analysis holds yet. */
985
+ readonly declarations?: readonly SchemaDeclaration[];
986
+ readonly expected: SchemaCompletionKind;
987
+ /** Table sites only: tables of other namespaces are candidates too, inserted with `qualifiedText`. */
988
+ readonly qualify?: boolean;
989
+ /** The table key for a column; for a table, the namespace key an unqualified name resolves in. */
990
+ readonly scope: string;
991
+ /** The typed prefix the inserted text replaces; empty (`start === end`) when nothing is typed. */
992
+ readonly span: SourceSpan;
993
+ }
994
+ export interface SchemaCandidate {
995
+ readonly key: string;
996
+ readonly kind: SchemaCompletionKind;
997
+ /** Index in `analyses` of the first analysis that declares `key`. */
998
+ readonly source: number;
999
+ /** The SQL text inserted for the candidate. */
1000
+ readonly text: string;
569
1001
  }
570
1002
  export interface LanguageService {
571
1003
  /** Analyzes one document. Synchronous and total: it never throws, and a parse failure is a diagnostic. */
572
1004
  readonly analyze: (source: string) => SchemaAnalysis;
1005
+ /** The completion context at `offset`. Pure, synchronous and total; `undefined` where no site is known. */
1006
+ readonly complete?: (source: string, offset: number) => SchemaCompletion | undefined;
1007
+ /** Reads a new table or column name. Pure, synchronous and total; `undefined` when no identifier denotes it. */
1008
+ readonly name?: (input: string) => SchemaName | undefined;
573
1009
  }
1010
+ /**
1011
+ * Selects the completion candidates for `completion` from the analyses, in analysis then declaration order.
1012
+ * A declaration is a candidate when its `kind` is `expected` and it has `text`, and either its `scope` is the
1013
+ * completion's scope (inserting `text`), or the completion sets `qualify`, the declaration is a table with
1014
+ * `qualifiedText` and another scope (inserting `qualifiedText`). One candidate per key: the first one wins.
1015
+ */
1016
+ export declare const completionCandidates: (completion: SchemaCompletion, analyses: readonly Pick<SchemaAnalysis, "declarations">[]) => SchemaCandidate[];
574
1017
  /** Returns the first reference whose half-open span contains `offset`. */
575
1018
  export declare const referenceAt: (analysis: SchemaAnalysis, offset: number) => SchemaReference | undefined;
1019
+ /** Returns the first declaration whose half-open selection contains `offset`. */
1020
+ export declare const declarationAt: (analysis: SchemaAnalysis, offset: number) => SchemaDeclaration | undefined;
1021
+ /** Returns the spans of the references whose key equals `key`, then the declaration selections with that key when `includeDeclaration` is set. */
1022
+ export declare const referencesTo: (key: string, analysis: SchemaAnalysis, includeDeclaration: boolean) => SourceSpan[];
576
1023
  /** Returns the selections of the declarations whose key equals the reference key, in declaration order. */
577
1024
  export declare const definitions: (reference: SchemaReference, analysis: SchemaAnalysis) => SourceSpan[];
1025
+ /** The span that rename replaces: `selection` when present, else the reference span. */
1026
+ export declare const nameSpan: (reference: SchemaReference) => SourceSpan;
1027
+ /** The declaration, reference or occurrence whose name span contains `offset`. */
1028
+ export declare const renameSiteAt: (analysis: SchemaAnalysis, offset: number) => {
1029
+ readonly key: string;
1030
+ readonly span: SourceSpan;
1031
+ } | undefined;
1032
+ /** The name spans of every declaration, reference and occurrence with `key`, in document order. */
1033
+ export declare const renameSpans: (key: string, analysis: SchemaAnalysis) => SourceSpan[];
578
1034
  /** Stable application contract identity, independent of the plugin package version. */
579
1035
  interface ApplicationContract {
580
1036
  readonly id: string;
@@ -682,4 +1138,4 @@ interface DynamicGeneratorPlugin {
682
1138
  export declare const decodeMapperPlugin: (value: unknown) => Effect.Effect<DynamicMapperPlugin, CodegenError>;
683
1139
  /** Validate the generator value selected from a module by the consumer. */
684
1140
  export declare const decodeGeneratorPlugin: (value: unknown) => Effect.Effect<DynamicGeneratorPlugin, CodegenError>;
685
- export type { ApplicationContract, ApplicationMapper, CodegenDiagnostic, ColumnIdentity, Dialect, DynamicGeneratorPlugin, DynamicMapperPlugin, ExecutionResult, GeneratedFile, GenerationResult, Generator, GeneratorDescriptor, GeneratorPlugin, MapperDescriptor, MapperPlugin, MappingResult, MigrationCheckpoint, MigrationExecutor, MigrationRun, MigrationSource, SemanticColumn, SemanticColumnType, SemanticDatabaseSchema, SemanticDiagnostic, SemanticDiagnosticSubject, SemanticElement, SemanticFact, SemanticForeignKey, SemanticForeignKeyTarget, SemanticInsertPolicy, SemanticKey, SemanticRelation, SemanticSchemaResolution, SemanticStructField, SemanticValueDomain, SemanticWritePolicy };
1141
+ export type { ApplicationContract, ApplicationMapper, CodegenDiagnostic, ColumnIdentity, Dialect, DynamicGeneratorPlugin, DynamicMapperPlugin, ExecutionResult, ExtractOmission, ExtractOptions, ExtractResult, ExtractedPart, GeneratedFile, GenerationResult, Generator, GeneratorDescriptor, GeneratorPlugin, MapperDescriptor, MapperPlugin, MappingResult, MigrationCheckpoint, MigrationExecutor, MigrationRun, MigrationSource, ReplayOptions, SemanticColumn, SemanticColumnType, SemanticDatabaseSchema, SemanticDiagnostic, SemanticDiagnosticSubject, SemanticElement, SemanticFact, SemanticForeignKey, SemanticForeignKeyTarget, SemanticInsertPolicy, SemanticKey, SemanticRelation, SemanticSchemaResolution, SemanticStructField, SemanticValueDomain, SemanticWritePolicy };