@uncutsql/core 0.8.0 → 0.9.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.cts CHANGED
@@ -354,6 +354,18 @@ export type TableAlteration = {
354
354
  readonly [key: string]: SchemaValue;
355
355
  };
356
356
  };
357
+ /** A column whose values a table change carries over, renamed or not. */
358
+ export interface ColumnPair {
359
+ readonly after: DatabaseColumn;
360
+ readonly before: DatabaseColumn;
361
+ readonly renamed: boolean;
362
+ }
363
+ /**
364
+ * Every column a table change carries over: changed, renamed and unchanged ones. A table option
365
+ * can change how a column with an unchanged declaration stores values (SQLite `STRICT`), so the
366
+ * dialect classifies every pair, not only declaration changes (ADR 0042).
367
+ */
368
+ export declare const pairedColumns: (before: DatabaseTable, after: DatabaseTable, changes: readonly TableAlteration[]) => ColumnPair[];
357
369
  interface TableChanges {
358
370
  readonly after: DatabaseTable;
359
371
  readonly before: DatabaseTable;
@@ -449,9 +461,24 @@ export interface DropGuard {
449
461
  readonly column?: string;
450
462
  readonly table: TableIdentity;
451
463
  }
464
+ export interface TypeChangeAnswer {
465
+ readonly classification: "may_lose" | "may_fail" | "both";
466
+ /** Source column name. */
467
+ readonly column: string;
468
+ readonly failure?: {
469
+ readonly action: "accept_failure";
470
+ } | {
471
+ readonly fallback: {
472
+ readonly literal: SchemaValue;
473
+ };
474
+ };
475
+ readonly loss?: "accept_loss" | "guard";
476
+ readonly table: TableIdentity;
477
+ }
452
478
  export interface DatabaseDiff {
453
479
  readonly changes: readonly (NamespaceChange | EnumChange | ExtensionChange | TableChange | ViewChange | TriggerChange | SequenceChange | FunctionChange | CommentChange)[];
454
480
  readonly dropGuards?: readonly DropGuard[];
481
+ readonly typeChanges?: readonly TypeChangeAnswer[];
455
482
  }
456
483
  export declare const validateDatabase: (database: DatabaseSchema, side: DiffDiagnostic["side"]) => readonly DiffDiagnostic[];
457
484
  /**
@@ -581,6 +608,7 @@ export type MigrationProcedure = {
581
608
  export interface DatabaseMigration {
582
609
  readonly dropGuards?: readonly DropGuard[];
583
610
  readonly procedures: readonly MigrationProcedure[];
611
+ readonly typeChanges?: readonly TypeChangeAnswer[];
584
612
  }
585
613
  /** Low-level logical lowering of caller-approved intent. Resolve migration decisions first in user-facing workflows. */
586
614
  export declare const planDatabaseMigration: (diff: DatabaseDiff) => DatabaseMigration;
@@ -592,6 +620,11 @@ interface ColumnIdentity {
592
620
  readonly key: DatabaseColumn["key"];
593
621
  readonly table: TableIdentity;
594
622
  }
623
+ type SemanticSubject = {
624
+ readonly table: TableIdentity;
625
+ } | {
626
+ readonly column: ColumnIdentity;
627
+ };
595
628
  /** A condition describes a dependency on database behavior, such as a default expression's result. */
596
629
  type SemanticFact<T> = {
597
630
  readonly status: "known";
@@ -786,6 +819,30 @@ interface ExternalUse {
786
819
  readonly externals: DatabaseExternals;
787
820
  readonly statement: number;
788
821
  }
822
+ type TypeChangeClassification = "lossless" | "may_lose" | "may_fail" | "both";
823
+ type TypeChangeLiteral = SchemaValue;
824
+ interface TypeChangeSide {
825
+ readonly column: DatabaseColumn;
826
+ readonly schema: DatabaseSchema;
827
+ readonly table: DatabaseTable;
828
+ }
829
+ interface TypeChange {
830
+ readonly after: TypeChangeSide;
831
+ readonly before: TypeChangeSide;
832
+ /** Accepted enum and label renames before this conversion. Absent means no rename. */
833
+ readonly enumRenames?: EnumRenames;
834
+ }
835
+ /** Pure, synchronous operations that describe the dialect's value conversion. */
836
+ interface TypeChangeSupport {
837
+ /** Returns undefined when there is no conversion to classify. */
838
+ readonly classify: (change: TypeChange) => TypeChangeClassification | undefined;
839
+ readonly displayTypes: (change: TypeChange) => {
840
+ source: string;
841
+ target: string;
842
+ };
843
+ /** Returns undefined when the literal fits, or the reason it is refused. */
844
+ readonly validateFallback: (change: TypeChange, literal: TypeChangeLiteral) => string | undefined;
845
+ }
789
846
  /** Dialect capabilities. The caller owns comparison and logical planning. */
790
847
  interface Dialect<Ast, PhysicalPlan, E extends Error = Error, R = never, SemanticError extends Error = E, SemanticServices = R> {
791
848
  /** Combine independently parsed schema documents in source order. */
@@ -846,6 +903,8 @@ interface Dialect<Ast, PhysicalPlan, E extends Error = Error, R = never, Semanti
846
903
  readonly externals?: DatabaseExternals;
847
904
  readonly onExternalUse?: (use: ExternalUse) => void;
848
905
  }) => Effect.Effect<DatabaseSchema, E, R>;
906
+ /** Classifies type changes and validates fallback literals for migration decisions. */
907
+ readonly typeChange?: TypeChangeSupport;
849
908
  }
850
909
  /** An external of `after` that `before` lacks (`new`) or declares differently (`changed`). */
851
910
  type ExternalChange = {
@@ -1034,13 +1093,40 @@ export interface EnumMigrationDecision extends DecisionQuestion {
1034
1093
  readonly enum: TableIdentity;
1035
1094
  readonly value?: string;
1036
1095
  }
1037
- export type MigrationDecision = TableMigrationDecision | EnumMigrationDecision;
1096
+ export interface TypeChangeDecision {
1097
+ /** Type-change questions have no rename candidates. */
1098
+ readonly candidates?: never;
1099
+ readonly column: string;
1100
+ readonly id: string;
1101
+ readonly kind: "type_change_loss" | "type_change_failure";
1102
+ readonly question: string;
1103
+ readonly resolution: {
1104
+ readonly action: "pending";
1105
+ } | {
1106
+ readonly action: "accept_loss";
1107
+ } | {
1108
+ readonly action: "guard";
1109
+ } | {
1110
+ readonly action: "accept_failure";
1111
+ } | {
1112
+ readonly action?: never;
1113
+ readonly fallback: {
1114
+ readonly literal: TypeChangeLiteral;
1115
+ };
1116
+ };
1117
+ readonly table: TableIdentity;
1118
+ }
1119
+ type RemovalDecision = TableMigrationDecision | EnumMigrationDecision;
1120
+ export type MigrationDecision = RemovalDecision | TypeChangeDecision;
1038
1121
  export interface MigrationDecisions {
1039
1122
  readonly after: DatabaseSchema;
1040
1123
  readonly before: DatabaseSchema;
1041
1124
  readonly decisions: readonly MigrationDecision[];
1042
1125
  readonly version: 1;
1043
1126
  }
1127
+ type RemovalDecisions = Omit<MigrationDecisions, "decisions"> & {
1128
+ readonly decisions: readonly RemovalDecision[];
1129
+ };
1044
1130
  declare const MigrationDecisionError_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 & {
1045
1131
  readonly _tag: "MigrationDecisionError";
1046
1132
  } & Readonly<A>;
@@ -1048,21 +1134,15 @@ export declare class MigrationDecisionError extends MigrationDecisionError_base<
1048
1134
  readonly message: string;
1049
1135
  readonly pending: MigrationDecisions;
1050
1136
  }> {}
1051
- export declare const prepareMigrationDecisions: (before: DatabaseSchema, after: DatabaseSchema) => Effect.Effect<{
1052
- after: DatabaseSchema;
1053
- before: DatabaseSchema;
1054
- decisions: readonly MigrationDecision[];
1055
- version: 1;
1056
- }, SchemaDiffError, never>;
1137
+ export declare function prepareMigrationDecisions(before: DatabaseSchema, after: DatabaseSchema): Effect.Effect<RemovalDecisions, SchemaDiffError>;
1138
+ export declare function prepareMigrationDecisions(before: DatabaseSchema, after: DatabaseSchema, typeChange?: TypeChangeSupport): Effect.Effect<MigrationDecisions, SchemaDiffError>;
1139
+ /** Rebuild the column pair and accepted enum renames to validate a proposed fallback. */
1140
+ export declare const validateTypeChangeFallback: (document: MigrationDecisions, decision: TypeChangeDecision, literal: TypeChangeLiteral, typeChange: TypeChangeSupport) => string | undefined;
1057
1141
  /** Refresh the questions and snapshots, carrying forward applicable reviewed choices. */
1058
- export declare const mergeMigrationDecisions: (fresh: MigrationDecisions, previous: unknown) => Effect.Effect<{
1059
- decisions: MigrationDecision[];
1060
- after: DatabaseSchema;
1061
- before: DatabaseSchema;
1062
- version: 1;
1063
- }, SchemaModelError | SchemaDiffError | MigrationDecisionError, never>;
1142
+ export declare function mergeMigrationDecisions(fresh: MigrationDecisions, previous: unknown): Effect.Effect<RemovalDecisions, MigrationDecisionError | SchemaDiffError | SchemaModelError>;
1143
+ export declare function mergeMigrationDecisions(fresh: MigrationDecisions, previous: unknown, typeChange?: TypeChangeSupport): Effect.Effect<MigrationDecisions, MigrationDecisionError | SchemaDiffError | SchemaModelError>;
1064
1144
  /** Validate untrusted JSON and resolve intent against fresh comparison results. */
1065
- export declare const resolveMigrationDecisions: (before: DatabaseSchema, after: DatabaseSchema, supplied?: unknown) => Effect.Effect<{
1145
+ export declare const resolveMigrationDecisions: (before: DatabaseSchema, after: DatabaseSchema, supplied?: unknown, typeChange?: TypeChangeSupport) => Effect.Effect<{
1066
1146
  decisions: MigrationDecisions;
1067
1147
  diff: DatabaseDiff;
1068
1148
  }, SchemaDiffError | MigrationDecisionError, never>;
@@ -1096,6 +1176,12 @@ export interface SchemaDeclaration {
1096
1176
  /** Opaque key of the scope in which the name is unique: a namespace for a table, the table key for a column. */
1097
1177
  readonly scope?: string;
1098
1178
  readonly selection: SourceSpan;
1179
+ /**
1180
+ * Set by the language service on table and column declarations that reach the end of the document.
1181
+ * It equals the identity `toDatabaseSchema` gives the object. Absent for dropped, renamed-away or
1182
+ * unconverted objects, and when the service omits subjects (only mapper hovers are unavailable).
1183
+ */
1184
+ readonly subject?: SemanticSubject;
1099
1185
  /** SQL text that denotes the name alone, quoted when the dialect requires it. */
1100
1186
  readonly text?: string;
1101
1187
  }
@@ -1111,7 +1197,9 @@ export interface SchemaNameUse extends SourceSpan {
1111
1197
  readonly context: SchemaNameContext;
1112
1198
  readonly nameKey: string;
1113
1199
  }
1114
- export interface SchemaAnalysis {
1200
+ export interface SchemaAnalysis<Ast = unknown> {
1201
+ /** The document's parse result, equal to what the same module's `Dialect.parse` succeeds with. Absent when parsing failed. */
1202
+ readonly ast?: Ast;
1115
1203
  readonly declarations: readonly SchemaDeclaration[];
1116
1204
  readonly diagnostics: readonly SchemaDiagnostic[];
1117
1205
  /** Uses that rename edits but no other feature reads (Decision 2). */
@@ -1147,13 +1235,13 @@ export interface SchemaCandidate {
1147
1235
  /** The SQL text inserted for the candidate. */
1148
1236
  readonly text: string;
1149
1237
  }
1150
- export interface LanguageService {
1238
+ export interface LanguageService<Ast = unknown> {
1151
1239
  /**
1152
1240
  * Analyzes one document. Synchronous and total: it never throws. Each diagnostic is either a
1153
1241
  * parse failure or a statement whose precondition fails (it cannot apply). Either kind means the
1154
1242
  * document has errors, which suspends project checks.
1155
1243
  */
1156
- readonly analyze: (source: string) => SchemaAnalysis;
1244
+ readonly analyze: (source: string) => SchemaAnalysis<Ast>;
1157
1245
  /** The completion context at `offset`. Pure, synchronous and total; `undefined` where no site is known. */
1158
1246
  readonly complete?: (source: string, offset: number) => SchemaCompletion | undefined;
1159
1247
  /** Reads a new table or column name. Pure, synchronous and total; `undefined` when no identifier denotes it. */
@@ -1233,10 +1321,26 @@ interface ApplicationMapper<Input, Output, Options, E = never, R = never> {
1233
1321
  interface Generator<Schema, Options, E = never, R = never> {
1234
1322
  readonly generate: (schema: Schema, options: Options) => Effect.Effect<GenerationResult, E, R>;
1235
1323
  }
1324
+ /** A mapper's own rendering of one mapped table or column, for editor hovers. */
1325
+ interface MapperSubjectDescription {
1326
+ /** Named types the texts use, such as a brand declaration. */
1327
+ readonly definitions?: readonly string[];
1328
+ /** Code block language, such as `typescript` or `python`. */
1329
+ readonly language: string;
1330
+ /** Why the subject has these types, such as `override accounts.email` or `runtime profile bigint`. */
1331
+ readonly notes?: readonly string[];
1332
+ /** Labelled type texts in display order, such as select, insert and update. */
1333
+ readonly types: readonly {
1334
+ readonly label: string;
1335
+ readonly text: string;
1336
+ }[];
1337
+ }
1236
1338
  /** Programmatic plugin contract. A dynamically exported mapper supplies its own services. */
1237
1339
  interface MapperPlugin<Input, Output, Options, E = never, R = never> extends ApplicationMapper<Input, Output, Options, E, R> {
1238
1340
  readonly decodeInput: (value: unknown) => Effect.Effect<Input, E, R>;
1239
1341
  readonly decodeOptions: (value: unknown) => Effect.Effect<Options, E, R>;
1342
+ /** Optional: describes a mapped subject. Core never reads the mapped output itself. */
1343
+ readonly describe?: (schema: Output, subject: SemanticSubject) => MapperSubjectDescription | undefined;
1240
1344
  readonly descriptor: MapperDescriptor;
1241
1345
  }
1242
1346
  /** Programmatic plugin contract. A dynamically exported generator supplies its own services. */
@@ -1279,6 +1383,8 @@ export declare const validateApplicationCompatibility: (output: ApplicationContr
1279
1383
  /** Validate the text artifact and diagnostic envelopes before handing results to a consumer. */
1280
1384
  export declare const decodeGenerationResult: (value: unknown) => Effect.Effect<GenerationResult, CodegenError>;
1281
1385
  interface DynamicMapperPlugin {
1386
+ /** Synchronous and optional. Throws a CodegenError when the plugin fails or returns an invalid value. */
1387
+ readonly describe?: (schema: unknown, subject: SemanticSubject) => MapperSubjectDescription | undefined;
1282
1388
  readonly descriptor: MapperDescriptor;
1283
1389
  readonly map: (schema: unknown, options: unknown) => Effect.Effect<MappingResult<unknown>, CodegenError>;
1284
1390
  }
@@ -1290,4 +1396,37 @@ interface DynamicGeneratorPlugin {
1290
1396
  export declare const decodeMapperPlugin: (value: unknown) => Effect.Effect<DynamicMapperPlugin, CodegenError>;
1291
1397
  /** Validate the generator value selected from a module by the consumer. */
1292
1398
  export declare const decodeGeneratorPlugin: (value: unknown) => Effect.Effect<DynamicGeneratorPlugin, CodegenError>;
1293
- export type { ApplicationContract, ApplicationMapper, CodegenDiagnostic, ColumnIdentity, Dialect, DynamicGeneratorPlugin, DynamicMapperPlugin, ExecutionOptions, ExecutionResult, ExecutorCapabilities, ExternalChange, ExternalUse, 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, StatementEdit };
1399
+ interface MappingFailure {
1400
+ readonly error: CodegenError;
1401
+ }
1402
+ interface MappedProfile {
1403
+ readonly mapper: DynamicMapperPlugin;
1404
+ readonly name: string;
1405
+ readonly result: MappingResult<unknown> | MappingFailure;
1406
+ }
1407
+ /** Map every profile in order, retaining errors and diagnostics for the caller. */
1408
+ export declare const mapProfiles: (schema: SemanticDatabaseSchema, profiles: readonly {
1409
+ readonly mapper: DynamicMapperPlugin;
1410
+ readonly name: string;
1411
+ readonly options: unknown;
1412
+ }[]) => Effect.Effect<readonly MappedProfile[]>;
1413
+ declare const GenerationFailure_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 & {
1414
+ readonly _tag: "GenerationFailure";
1415
+ } & Readonly<A>;
1416
+ declare class GenerationFailure extends GenerationFailure_base<{
1417
+ readonly error: CodegenError;
1418
+ readonly generator: string;
1419
+ readonly stage: "compatibility" | "generation";
1420
+ }> {}
1421
+ /** Check the entire batch's contracts before invoking any generator. */
1422
+ export declare const generate: (mapped: MappedProfile & {
1423
+ readonly result: MappingResult<unknown>;
1424
+ }, generators: readonly {
1425
+ readonly generator: DynamicGeneratorPlugin;
1426
+ readonly name: string;
1427
+ readonly options: unknown;
1428
+ }[]) => Effect.Effect<readonly {
1429
+ readonly name: string;
1430
+ readonly result: GenerationResult;
1431
+ }[], GenerationFailure>;
1432
+ export type { ApplicationContract, ApplicationMapper, CodegenDiagnostic, ColumnIdentity, Dialect, DynamicGeneratorPlugin, DynamicMapperPlugin, ExecutionOptions, ExecutionResult, ExecutorCapabilities, ExternalChange, ExternalUse, ExtractOmission, ExtractOptions, ExtractResult, ExtractedPart, GeneratedFile, GenerationFailure, GenerationResult, Generator, GeneratorDescriptor, GeneratorPlugin, MappedProfile, MapperDescriptor, MapperPlugin, MapperSubjectDescription, MappingFailure, MappingResult, MigrationCheckpoint, MigrationExecutor, MigrationRun, MigrationSource, ReplayOptions, SemanticColumn, SemanticColumnType, SemanticDatabaseSchema, SemanticDiagnostic, SemanticDiagnosticSubject, SemanticElement, SemanticFact, SemanticForeignKey, SemanticForeignKeyTarget, SemanticInsertPolicy, SemanticKey, SemanticRelation, SemanticSchemaResolution, SemanticStructField, SemanticSubject, SemanticValueDomain, SemanticWritePolicy, StatementEdit, TypeChange, TypeChangeClassification, TypeChangeLiteral, TypeChangeSupport };
package/dist/index.d.ts CHANGED
@@ -354,6 +354,18 @@ export type TableAlteration = {
354
354
  readonly [key: string]: SchemaValue;
355
355
  };
356
356
  };
357
+ /** A column whose values a table change carries over, renamed or not. */
358
+ export interface ColumnPair {
359
+ readonly after: DatabaseColumn;
360
+ readonly before: DatabaseColumn;
361
+ readonly renamed: boolean;
362
+ }
363
+ /**
364
+ * Every column a table change carries over: changed, renamed and unchanged ones. A table option
365
+ * can change how a column with an unchanged declaration stores values (SQLite `STRICT`), so the
366
+ * dialect classifies every pair, not only declaration changes (ADR 0042).
367
+ */
368
+ export declare const pairedColumns: (before: DatabaseTable, after: DatabaseTable, changes: readonly TableAlteration[]) => ColumnPair[];
357
369
  interface TableChanges {
358
370
  readonly after: DatabaseTable;
359
371
  readonly before: DatabaseTable;
@@ -449,9 +461,24 @@ export interface DropGuard {
449
461
  readonly column?: string;
450
462
  readonly table: TableIdentity;
451
463
  }
464
+ export interface TypeChangeAnswer {
465
+ readonly classification: "may_lose" | "may_fail" | "both";
466
+ /** Source column name. */
467
+ readonly column: string;
468
+ readonly failure?: {
469
+ readonly action: "accept_failure";
470
+ } | {
471
+ readonly fallback: {
472
+ readonly literal: SchemaValue;
473
+ };
474
+ };
475
+ readonly loss?: "accept_loss" | "guard";
476
+ readonly table: TableIdentity;
477
+ }
452
478
  export interface DatabaseDiff {
453
479
  readonly changes: readonly (NamespaceChange | EnumChange | ExtensionChange | TableChange | ViewChange | TriggerChange | SequenceChange | FunctionChange | CommentChange)[];
454
480
  readonly dropGuards?: readonly DropGuard[];
481
+ readonly typeChanges?: readonly TypeChangeAnswer[];
455
482
  }
456
483
  export declare const validateDatabase: (database: DatabaseSchema, side: DiffDiagnostic["side"]) => readonly DiffDiagnostic[];
457
484
  /**
@@ -581,6 +608,7 @@ export type MigrationProcedure = {
581
608
  export interface DatabaseMigration {
582
609
  readonly dropGuards?: readonly DropGuard[];
583
610
  readonly procedures: readonly MigrationProcedure[];
611
+ readonly typeChanges?: readonly TypeChangeAnswer[];
584
612
  }
585
613
  /** Low-level logical lowering of caller-approved intent. Resolve migration decisions first in user-facing workflows. */
586
614
  export declare const planDatabaseMigration: (diff: DatabaseDiff) => DatabaseMigration;
@@ -592,6 +620,11 @@ interface ColumnIdentity {
592
620
  readonly key: DatabaseColumn["key"];
593
621
  readonly table: TableIdentity;
594
622
  }
623
+ type SemanticSubject = {
624
+ readonly table: TableIdentity;
625
+ } | {
626
+ readonly column: ColumnIdentity;
627
+ };
595
628
  /** A condition describes a dependency on database behavior, such as a default expression's result. */
596
629
  type SemanticFact<T> = {
597
630
  readonly status: "known";
@@ -786,6 +819,30 @@ interface ExternalUse {
786
819
  readonly externals: DatabaseExternals;
787
820
  readonly statement: number;
788
821
  }
822
+ type TypeChangeClassification = "lossless" | "may_lose" | "may_fail" | "both";
823
+ type TypeChangeLiteral = SchemaValue;
824
+ interface TypeChangeSide {
825
+ readonly column: DatabaseColumn;
826
+ readonly schema: DatabaseSchema;
827
+ readonly table: DatabaseTable;
828
+ }
829
+ interface TypeChange {
830
+ readonly after: TypeChangeSide;
831
+ readonly before: TypeChangeSide;
832
+ /** Accepted enum and label renames before this conversion. Absent means no rename. */
833
+ readonly enumRenames?: EnumRenames;
834
+ }
835
+ /** Pure, synchronous operations that describe the dialect's value conversion. */
836
+ interface TypeChangeSupport {
837
+ /** Returns undefined when there is no conversion to classify. */
838
+ readonly classify: (change: TypeChange) => TypeChangeClassification | undefined;
839
+ readonly displayTypes: (change: TypeChange) => {
840
+ source: string;
841
+ target: string;
842
+ };
843
+ /** Returns undefined when the literal fits, or the reason it is refused. */
844
+ readonly validateFallback: (change: TypeChange, literal: TypeChangeLiteral) => string | undefined;
845
+ }
789
846
  /** Dialect capabilities. The caller owns comparison and logical planning. */
790
847
  interface Dialect<Ast, PhysicalPlan, E extends Error = Error, R = never, SemanticError extends Error = E, SemanticServices = R> {
791
848
  /** Combine independently parsed schema documents in source order. */
@@ -846,6 +903,8 @@ interface Dialect<Ast, PhysicalPlan, E extends Error = Error, R = never, Semanti
846
903
  readonly externals?: DatabaseExternals;
847
904
  readonly onExternalUse?: (use: ExternalUse) => void;
848
905
  }) => Effect.Effect<DatabaseSchema, E, R>;
906
+ /** Classifies type changes and validates fallback literals for migration decisions. */
907
+ readonly typeChange?: TypeChangeSupport;
849
908
  }
850
909
  /** An external of `after` that `before` lacks (`new`) or declares differently (`changed`). */
851
910
  type ExternalChange = {
@@ -1034,13 +1093,40 @@ export interface EnumMigrationDecision extends DecisionQuestion {
1034
1093
  readonly enum: TableIdentity;
1035
1094
  readonly value?: string;
1036
1095
  }
1037
- export type MigrationDecision = TableMigrationDecision | EnumMigrationDecision;
1096
+ export interface TypeChangeDecision {
1097
+ /** Type-change questions have no rename candidates. */
1098
+ readonly candidates?: never;
1099
+ readonly column: string;
1100
+ readonly id: string;
1101
+ readonly kind: "type_change_loss" | "type_change_failure";
1102
+ readonly question: string;
1103
+ readonly resolution: {
1104
+ readonly action: "pending";
1105
+ } | {
1106
+ readonly action: "accept_loss";
1107
+ } | {
1108
+ readonly action: "guard";
1109
+ } | {
1110
+ readonly action: "accept_failure";
1111
+ } | {
1112
+ readonly action?: never;
1113
+ readonly fallback: {
1114
+ readonly literal: TypeChangeLiteral;
1115
+ };
1116
+ };
1117
+ readonly table: TableIdentity;
1118
+ }
1119
+ type RemovalDecision = TableMigrationDecision | EnumMigrationDecision;
1120
+ export type MigrationDecision = RemovalDecision | TypeChangeDecision;
1038
1121
  export interface MigrationDecisions {
1039
1122
  readonly after: DatabaseSchema;
1040
1123
  readonly before: DatabaseSchema;
1041
1124
  readonly decisions: readonly MigrationDecision[];
1042
1125
  readonly version: 1;
1043
1126
  }
1127
+ type RemovalDecisions = Omit<MigrationDecisions, "decisions"> & {
1128
+ readonly decisions: readonly RemovalDecision[];
1129
+ };
1044
1130
  declare const MigrationDecisionError_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 & {
1045
1131
  readonly _tag: "MigrationDecisionError";
1046
1132
  } & Readonly<A>;
@@ -1048,21 +1134,15 @@ export declare class MigrationDecisionError extends MigrationDecisionError_base<
1048
1134
  readonly message: string;
1049
1135
  readonly pending: MigrationDecisions;
1050
1136
  }> {}
1051
- export declare const prepareMigrationDecisions: (before: DatabaseSchema, after: DatabaseSchema) => Effect.Effect<{
1052
- after: DatabaseSchema;
1053
- before: DatabaseSchema;
1054
- decisions: readonly MigrationDecision[];
1055
- version: 1;
1056
- }, SchemaDiffError, never>;
1137
+ export declare function prepareMigrationDecisions(before: DatabaseSchema, after: DatabaseSchema): Effect.Effect<RemovalDecisions, SchemaDiffError>;
1138
+ export declare function prepareMigrationDecisions(before: DatabaseSchema, after: DatabaseSchema, typeChange?: TypeChangeSupport): Effect.Effect<MigrationDecisions, SchemaDiffError>;
1139
+ /** Rebuild the column pair and accepted enum renames to validate a proposed fallback. */
1140
+ export declare const validateTypeChangeFallback: (document: MigrationDecisions, decision: TypeChangeDecision, literal: TypeChangeLiteral, typeChange: TypeChangeSupport) => string | undefined;
1057
1141
  /** Refresh the questions and snapshots, carrying forward applicable reviewed choices. */
1058
- export declare const mergeMigrationDecisions: (fresh: MigrationDecisions, previous: unknown) => Effect.Effect<{
1059
- decisions: MigrationDecision[];
1060
- after: DatabaseSchema;
1061
- before: DatabaseSchema;
1062
- version: 1;
1063
- }, SchemaModelError | SchemaDiffError | MigrationDecisionError, never>;
1142
+ export declare function mergeMigrationDecisions(fresh: MigrationDecisions, previous: unknown): Effect.Effect<RemovalDecisions, MigrationDecisionError | SchemaDiffError | SchemaModelError>;
1143
+ export declare function mergeMigrationDecisions(fresh: MigrationDecisions, previous: unknown, typeChange?: TypeChangeSupport): Effect.Effect<MigrationDecisions, MigrationDecisionError | SchemaDiffError | SchemaModelError>;
1064
1144
  /** Validate untrusted JSON and resolve intent against fresh comparison results. */
1065
- export declare const resolveMigrationDecisions: (before: DatabaseSchema, after: DatabaseSchema, supplied?: unknown) => Effect.Effect<{
1145
+ export declare const resolveMigrationDecisions: (before: DatabaseSchema, after: DatabaseSchema, supplied?: unknown, typeChange?: TypeChangeSupport) => Effect.Effect<{
1066
1146
  decisions: MigrationDecisions;
1067
1147
  diff: DatabaseDiff;
1068
1148
  }, SchemaDiffError | MigrationDecisionError, never>;
@@ -1096,6 +1176,12 @@ export interface SchemaDeclaration {
1096
1176
  /** Opaque key of the scope in which the name is unique: a namespace for a table, the table key for a column. */
1097
1177
  readonly scope?: string;
1098
1178
  readonly selection: SourceSpan;
1179
+ /**
1180
+ * Set by the language service on table and column declarations that reach the end of the document.
1181
+ * It equals the identity `toDatabaseSchema` gives the object. Absent for dropped, renamed-away or
1182
+ * unconverted objects, and when the service omits subjects (only mapper hovers are unavailable).
1183
+ */
1184
+ readonly subject?: SemanticSubject;
1099
1185
  /** SQL text that denotes the name alone, quoted when the dialect requires it. */
1100
1186
  readonly text?: string;
1101
1187
  }
@@ -1111,7 +1197,9 @@ export interface SchemaNameUse extends SourceSpan {
1111
1197
  readonly context: SchemaNameContext;
1112
1198
  readonly nameKey: string;
1113
1199
  }
1114
- export interface SchemaAnalysis {
1200
+ export interface SchemaAnalysis<Ast = unknown> {
1201
+ /** The document's parse result, equal to what the same module's `Dialect.parse` succeeds with. Absent when parsing failed. */
1202
+ readonly ast?: Ast;
1115
1203
  readonly declarations: readonly SchemaDeclaration[];
1116
1204
  readonly diagnostics: readonly SchemaDiagnostic[];
1117
1205
  /** Uses that rename edits but no other feature reads (Decision 2). */
@@ -1147,13 +1235,13 @@ export interface SchemaCandidate {
1147
1235
  /** The SQL text inserted for the candidate. */
1148
1236
  readonly text: string;
1149
1237
  }
1150
- export interface LanguageService {
1238
+ export interface LanguageService<Ast = unknown> {
1151
1239
  /**
1152
1240
  * Analyzes one document. Synchronous and total: it never throws. Each diagnostic is either a
1153
1241
  * parse failure or a statement whose precondition fails (it cannot apply). Either kind means the
1154
1242
  * document has errors, which suspends project checks.
1155
1243
  */
1156
- readonly analyze: (source: string) => SchemaAnalysis;
1244
+ readonly analyze: (source: string) => SchemaAnalysis<Ast>;
1157
1245
  /** The completion context at `offset`. Pure, synchronous and total; `undefined` where no site is known. */
1158
1246
  readonly complete?: (source: string, offset: number) => SchemaCompletion | undefined;
1159
1247
  /** Reads a new table or column name. Pure, synchronous and total; `undefined` when no identifier denotes it. */
@@ -1233,10 +1321,26 @@ interface ApplicationMapper<Input, Output, Options, E = never, R = never> {
1233
1321
  interface Generator<Schema, Options, E = never, R = never> {
1234
1322
  readonly generate: (schema: Schema, options: Options) => Effect.Effect<GenerationResult, E, R>;
1235
1323
  }
1324
+ /** A mapper's own rendering of one mapped table or column, for editor hovers. */
1325
+ interface MapperSubjectDescription {
1326
+ /** Named types the texts use, such as a brand declaration. */
1327
+ readonly definitions?: readonly string[];
1328
+ /** Code block language, such as `typescript` or `python`. */
1329
+ readonly language: string;
1330
+ /** Why the subject has these types, such as `override accounts.email` or `runtime profile bigint`. */
1331
+ readonly notes?: readonly string[];
1332
+ /** Labelled type texts in display order, such as select, insert and update. */
1333
+ readonly types: readonly {
1334
+ readonly label: string;
1335
+ readonly text: string;
1336
+ }[];
1337
+ }
1236
1338
  /** Programmatic plugin contract. A dynamically exported mapper supplies its own services. */
1237
1339
  interface MapperPlugin<Input, Output, Options, E = never, R = never> extends ApplicationMapper<Input, Output, Options, E, R> {
1238
1340
  readonly decodeInput: (value: unknown) => Effect.Effect<Input, E, R>;
1239
1341
  readonly decodeOptions: (value: unknown) => Effect.Effect<Options, E, R>;
1342
+ /** Optional: describes a mapped subject. Core never reads the mapped output itself. */
1343
+ readonly describe?: (schema: Output, subject: SemanticSubject) => MapperSubjectDescription | undefined;
1240
1344
  readonly descriptor: MapperDescriptor;
1241
1345
  }
1242
1346
  /** Programmatic plugin contract. A dynamically exported generator supplies its own services. */
@@ -1279,6 +1383,8 @@ export declare const validateApplicationCompatibility: (output: ApplicationContr
1279
1383
  /** Validate the text artifact and diagnostic envelopes before handing results to a consumer. */
1280
1384
  export declare const decodeGenerationResult: (value: unknown) => Effect.Effect<GenerationResult, CodegenError>;
1281
1385
  interface DynamicMapperPlugin {
1386
+ /** Synchronous and optional. Throws a CodegenError when the plugin fails or returns an invalid value. */
1387
+ readonly describe?: (schema: unknown, subject: SemanticSubject) => MapperSubjectDescription | undefined;
1282
1388
  readonly descriptor: MapperDescriptor;
1283
1389
  readonly map: (schema: unknown, options: unknown) => Effect.Effect<MappingResult<unknown>, CodegenError>;
1284
1390
  }
@@ -1290,4 +1396,37 @@ interface DynamicGeneratorPlugin {
1290
1396
  export declare const decodeMapperPlugin: (value: unknown) => Effect.Effect<DynamicMapperPlugin, CodegenError>;
1291
1397
  /** Validate the generator value selected from a module by the consumer. */
1292
1398
  export declare const decodeGeneratorPlugin: (value: unknown) => Effect.Effect<DynamicGeneratorPlugin, CodegenError>;
1293
- export type { ApplicationContract, ApplicationMapper, CodegenDiagnostic, ColumnIdentity, Dialect, DynamicGeneratorPlugin, DynamicMapperPlugin, ExecutionOptions, ExecutionResult, ExecutorCapabilities, ExternalChange, ExternalUse, 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, StatementEdit };
1399
+ interface MappingFailure {
1400
+ readonly error: CodegenError;
1401
+ }
1402
+ interface MappedProfile {
1403
+ readonly mapper: DynamicMapperPlugin;
1404
+ readonly name: string;
1405
+ readonly result: MappingResult<unknown> | MappingFailure;
1406
+ }
1407
+ /** Map every profile in order, retaining errors and diagnostics for the caller. */
1408
+ export declare const mapProfiles: (schema: SemanticDatabaseSchema, profiles: readonly {
1409
+ readonly mapper: DynamicMapperPlugin;
1410
+ readonly name: string;
1411
+ readonly options: unknown;
1412
+ }[]) => Effect.Effect<readonly MappedProfile[]>;
1413
+ declare const GenerationFailure_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 & {
1414
+ readonly _tag: "GenerationFailure";
1415
+ } & Readonly<A>;
1416
+ declare class GenerationFailure extends GenerationFailure_base<{
1417
+ readonly error: CodegenError;
1418
+ readonly generator: string;
1419
+ readonly stage: "compatibility" | "generation";
1420
+ }> {}
1421
+ /** Check the entire batch's contracts before invoking any generator. */
1422
+ export declare const generate: (mapped: MappedProfile & {
1423
+ readonly result: MappingResult<unknown>;
1424
+ }, generators: readonly {
1425
+ readonly generator: DynamicGeneratorPlugin;
1426
+ readonly name: string;
1427
+ readonly options: unknown;
1428
+ }[]) => Effect.Effect<readonly {
1429
+ readonly name: string;
1430
+ readonly result: GenerationResult;
1431
+ }[], GenerationFailure>;
1432
+ export type { ApplicationContract, ApplicationMapper, CodegenDiagnostic, ColumnIdentity, Dialect, DynamicGeneratorPlugin, DynamicMapperPlugin, ExecutionOptions, ExecutionResult, ExecutorCapabilities, ExternalChange, ExternalUse, ExtractOmission, ExtractOptions, ExtractResult, ExtractedPart, GeneratedFile, GenerationFailure, GenerationResult, Generator, GeneratorDescriptor, GeneratorPlugin, MappedProfile, MapperDescriptor, MapperPlugin, MapperSubjectDescription, MappingFailure, MappingResult, MigrationCheckpoint, MigrationExecutor, MigrationRun, MigrationSource, ReplayOptions, SemanticColumn, SemanticColumnType, SemanticDatabaseSchema, SemanticDiagnostic, SemanticDiagnosticSubject, SemanticElement, SemanticFact, SemanticForeignKey, SemanticForeignKeyTarget, SemanticInsertPolicy, SemanticKey, SemanticRelation, SemanticSchemaResolution, SemanticStructField, SemanticSubject, SemanticValueDomain, SemanticWritePolicy, StatementEdit, TypeChange, TypeChangeClassification, TypeChangeLiteral, TypeChangeSupport };