uql-orm 0.96.1 → 0.98.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.
Files changed (117) hide show
  1. package/dist/dialect/abstractSqlDialect.d.ts +1 -7
  2. package/dist/dialect/abstractSqlDialect.js +1 -9
  3. package/dist/dialect/mysqlLikeSqlDialect.d.ts +2 -0
  4. package/dist/dialect/mysqlLikeSqlDialect.js +4 -1
  5. package/dist/dialect/pgLikeSqlDialect.js +0 -1
  6. package/dist/migrate/acquireQuerierForMigrations.d.ts +4 -8
  7. package/dist/migrate/acquireQuerierForMigrations.js +10 -18
  8. package/dist/migrate/builder/columnBuilder.d.ts +1 -2
  9. package/dist/migrate/builder/columnBuilder.js +3 -10
  10. package/dist/migrate/builder/migrationBuilder.d.ts +6 -26
  11. package/dist/migrate/builder/migrationBuilder.js +21 -78
  12. package/dist/migrate/builder/tableBuilder.js +2 -3
  13. package/dist/migrate/builder/types.d.ts +59 -120
  14. package/dist/migrate/cli-config.d.ts +1 -0
  15. package/dist/migrate/cli-config.js +11 -26
  16. package/dist/migrate/cli.d.ts +0 -13
  17. package/dist/migrate/cli.js +55 -118
  18. package/dist/migrate/codegen/entityCodeGenerator.d.ts +7 -61
  19. package/dist/migrate/codegen/entityCodeGenerator.js +53 -174
  20. package/dist/migrate/codegen/fieldOptionsSource.d.ts +1 -3
  21. package/dist/migrate/codegen/fieldOptionsSource.js +3 -11
  22. package/dist/migrate/codegen/index.d.ts +2 -7
  23. package/dist/migrate/codegen/index.js +2 -8
  24. package/dist/migrate/codegen/migrationFile.d.ts +1 -8
  25. package/dist/migrate/codegen/migrationFile.js +9 -13
  26. package/dist/migrate/ddl/defaultSql.d.ts +2 -1
  27. package/dist/migrate/ddl/defaultSql.js +1 -3
  28. package/dist/migrate/ddl/indexCapabilities.d.ts +18 -0
  29. package/dist/migrate/ddl/indexCapabilities.js +60 -0
  30. package/dist/migrate/ddl/indexDdl.d.ts +11 -24
  31. package/dist/migrate/ddl/indexDdl.js +22 -28
  32. package/dist/migrate/ddl/mssqlIndexDdl.d.ts +1 -7
  33. package/dist/migrate/ddl/mssqlIndexDdl.js +1 -7
  34. package/dist/migrate/ddl/mssqlTableDdl.d.ts +6 -9
  35. package/dist/migrate/ddl/mssqlTableDdl.js +14 -17
  36. package/dist/migrate/ddl/mysqlIndexDdl.d.ts +0 -21
  37. package/dist/migrate/ddl/mysqlIndexDdl.js +4 -48
  38. package/dist/migrate/ddl/mysqlTableDdl.d.ts +6 -5
  39. package/dist/migrate/ddl/mysqlTableDdl.js +15 -10
  40. package/dist/migrate/ddl/pgIndexDdl.d.ts +0 -10
  41. package/dist/migrate/ddl/pgIndexDdl.js +5 -44
  42. package/dist/migrate/ddl/pgTableDdl.d.ts +6 -2
  43. package/dist/migrate/ddl/pgTableDdl.js +17 -1
  44. package/dist/migrate/ddl/sqliteIndexDdl.js +2 -7
  45. package/dist/migrate/ddl/tableDdl.d.ts +43 -24
  46. package/dist/migrate/ddl/tableDdl.js +56 -37
  47. package/dist/migrate/ddl/tableRebuild.d.ts +2 -1
  48. package/dist/migrate/drift/driftDetector.d.ts +29 -32
  49. package/dist/migrate/drift/driftDetector.js +155 -205
  50. package/dist/migrate/drift/index.d.ts +1 -6
  51. package/dist/migrate/drift/index.js +1 -6
  52. package/dist/migrate/generator/definitionToNode.d.ts +2 -2
  53. package/dist/migrate/generator/definitionToNode.js +6 -5
  54. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +56 -77
  55. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +75 -98
  56. package/dist/migrate/introspection/mssqlIntrospector.d.ts +10 -43
  57. package/dist/migrate/introspection/mssqlIntrospector.js +52 -77
  58. package/dist/migrate/introspection/mysqlIntrospector.d.ts +21 -37
  59. package/dist/migrate/introspection/mysqlIntrospector.js +75 -56
  60. package/dist/migrate/introspection/postgresIntrospector.d.ts +15 -60
  61. package/dist/migrate/introspection/postgresIntrospector.js +74 -77
  62. package/dist/migrate/introspection/sqliteIntrospector.d.ts +19 -53
  63. package/dist/migrate/introspection/sqliteIntrospector.js +73 -119
  64. package/dist/migrate/introspection/tableSchemaAST.d.ts +13 -0
  65. package/dist/migrate/introspection/tableSchemaAST.js +85 -0
  66. package/dist/migrate/migrationTarget.js +10 -2
  67. package/dist/migrate/migrator.d.ts +9 -44
  68. package/dist/migrate/migrator.js +72 -150
  69. package/dist/migrate/schemaChange.d.ts +8 -5
  70. package/dist/migrate/schemaChange.js +25 -8
  71. package/dist/migrate/schemaGenerator.d.ts +35 -109
  72. package/dist/migrate/schemaGenerator.js +179 -353
  73. package/dist/migrate/storage/databaseStorage.d.ts +2 -1
  74. package/dist/migrate/storage/databaseStorage.js +3 -2
  75. package/dist/migrate/storage/jsonStorage.d.ts +1 -2
  76. package/dist/migrate/storage/jsonStorage.js +11 -20
  77. package/dist/migrate/triggerSql.d.ts +7 -9
  78. package/dist/migrate/triggerSql.js +17 -18
  79. package/dist/mongo/index.d.ts +0 -1
  80. package/dist/mongo/index.js +0 -1
  81. package/dist/mongo/mongoDialect.js +0 -1
  82. package/dist/mongo/mongoIntrospector.d.ts +1 -6
  83. package/dist/mongo/mongoIntrospector.js +7 -18
  84. package/dist/mongo/mongoSchemaGenerator.d.ts +7 -26
  85. package/dist/mongo/mongoSchemaGenerator.js +51 -75
  86. package/dist/mssql/mssqlDialect.js +0 -1
  87. package/dist/schema/canonicalType.d.ts +15 -19
  88. package/dist/schema/canonicalType.js +20 -43
  89. package/dist/schema/dependencyGraph.d.ts +2 -3
  90. package/dist/schema/dependencyGraph.js +0 -4
  91. package/dist/schema/indexDifferences.js +2 -2
  92. package/dist/schema/schemaAST.d.ts +1 -1
  93. package/dist/schema/schemaAST.js +5 -12
  94. package/dist/schema/schemaASTBuilder.d.ts +5 -6
  95. package/dist/schema/schemaASTBuilder.js +17 -18
  96. package/dist/schema/schemaASTDiffer.d.ts +4 -5
  97. package/dist/schema/schemaASTDiffer.js +40 -73
  98. package/dist/schema/types.d.ts +24 -54
  99. package/dist/sqlite/localSqliteQuerierPool.d.ts +16 -2
  100. package/dist/sqlite/localSqliteQuerierPool.js +20 -4
  101. package/dist/sqlite/nodeSqliteQuerierPool.js +2 -2
  102. package/dist/sqlite/sqliteDialect.js +0 -1
  103. package/dist/sqlite/sqliteQuerierPool.js +3 -3
  104. package/dist/type/dialect.d.ts +0 -2
  105. package/dist/type/migration.d.ts +13 -73
  106. package/dist/util/ddlExpression.util.d.ts +13 -2
  107. package/dist/util/ddlExpression.util.js +27 -4
  108. package/dist/util/sql.util.d.ts +2 -12
  109. package/dist/util/sql.util.js +9 -18
  110. package/package.json +1 -1
  111. package/skills/uql-orm/SKILL.md +1 -1
  112. package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -36
  113. package/dist/migrate/introspection/baseSqlIntrospector.js +0 -133
  114. package/dist/schema/index.d.ts +0 -2
  115. package/dist/schema/index.js +0 -1
  116. package/dist/sqlite/sqlitePragmas.d.ts +0 -3
  117. package/dist/sqlite/sqlitePragmas.js +0 -15
@@ -1,15 +1,11 @@
1
1
  import type { AbstractSqlDialect } from '../dialect/index.js';
2
2
  import type { SchemaAST } from '../schema/schemaAST.js';
3
- import { type BuildSchemaASTOptions } from '../schema/schemaASTBuilder.js';
4
3
  import { type DiffOptions } from '../schema/schemaASTDiffer.js';
5
- import { type CanonicalType, type ColumnNode, type ForeignKeyAction, type IndexNode, type TableNode } from '../schema/types.js';
6
- import type { ColumnSchema, CreateSchemaOptions, DialectFeatures, DropSchemaOptions, EntityMeta, InstalledTriggers, EntityWhereMeta, FieldOptions, ForeignKeySchema, IndexSchema, Rename, NamingStrategy, SchemaDiff, SchemaGenerator, Type } from '../type/index.js';
7
- import type { AnyMigrationOperation, FullColumnDefinition, TableDefinition } from './builder/types.js';
4
+ import { type ForeignKeyAction, type TableNode } from '../schema/types.js';
5
+ import type { CreateSchemaOptions, DropSchemaOptions, ForeignKeySchema, Rename, SchemaDiff, SchemaGenerator, Type } from '../type/index.js';
6
+ import type { AnyMigrationOperation, TableDefinition } from './builder/types.js';
8
7
  import { type IndexDdl, type TableDdl } from './ddl/index.js';
9
- /**
10
- * Unified SQL schema generator.
11
- * Parameterized by dialect to handle Postgres, MySQL, MariaDB, and SQLite.
12
- */
8
+ /** The SQL schema generator, one for every SQL engine, its spellings taken from the dialect and its DDL classes. */
13
9
  export declare class SqlSchemaGenerator implements SchemaGenerator {
14
10
  protected readonly dialect: AbstractSqlDialect;
15
11
  protected readonly defaultForeignKeyAction: ForeignKeyAction;
@@ -18,48 +14,34 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
18
14
  /** The `ALTER TABLE` statements this dialect spells its own way, the migrator's for the same reason. */
19
15
  protected readonly tableDdl: TableDdl;
20
16
  constructor(dialect: AbstractSqlDialect, defaultForeignKeyAction?: ForeignKeyAction);
21
- get namingStrategy(): NamingStrategy | undefined;
22
- get features(): DialectFeatures;
23
- resolveTableName<E>(meta: EntityMeta<E>): string;
24
- resolveTableAlias<E>(meta: EntityMeta<E>): string;
25
- resolveSchema<E>(meta: EntityMeta<E>): string | undefined;
26
- resolveColumnName(key: string, field: FieldOptions): string;
27
- compileDdl(sql: EntityWhereMeta<object>, entity: Type<object>): string;
28
- compileIndexPredicate(where: EntityWhereMeta<object>, entity: Type<object>, indexName: string): string;
17
+ private get features();
29
18
  /** Escape an identifier (table name, column name, etc.) */
30
- protected escapeId(identifier: string): string;
19
+ private escapeId;
20
+ /**
21
+ * The SQL type a column is spelled with: its canonical type, plus the engine's generated suffix on an
22
+ * auto-increment key, so a foreign key taking its type from the key gets the same one.
23
+ */
24
+ private columnSqlType;
31
25
  /**
32
- * An auto-increment key's type: its canonical type rendered like any column's, plus the engine's generated
33
- * suffix, so a foreign key taking its type from this key gets the same one.
26
+ * The entity side as an AST, carrying this generator's default referential action. Named by the dialect's
27
+ * resolvers rather than a naming strategy, which would also rename an explicit `@Entity({ name })`.
34
28
  */
35
- protected serialType(type: CanonicalType): string;
36
- /** The SQL type a column is spelled with: the generated-key form for an auto-increment key, the canonical type otherwise. */
37
- protected columnSqlType(col: Pick<ColumnNode, 'type' | 'isPrimaryKey' | 'isAutoIncrement'>): string;
38
- protected canonicalTypeToSql(type: CanonicalType): string;
39
- /** The entity side as an AST, carrying this generator's default referential action. */
40
29
  buildAST(entities: readonly Type<object>[]): SchemaAST;
41
30
  /**
42
31
  * Every `CREATE TABLE` for `entities`, then their foreign keys, since a relation graph is routinely
43
32
  * cyclic. SQLite keeps them inline: it cannot add one later, and resolves a forward reference lazily.
44
33
  */
45
34
  generateCreateSchema(entities: readonly Type<object>[], options?: CreateSchemaOptions): string[];
46
- /**
47
- * The installed triggers on `entity`'s table it does not declare, and the declared ones not installed,
48
- * compared by name alone: a name carries a hash of the trigger's SQL, so an edited one is a new name.
49
- * Every trigger counts - the ones it authored, and one per event each stamp names.
50
- */
51
- private triggerChanges;
52
- generateTriggers(entity: Type<object>, installed?: InstalledTriggers): string[];
53
- generateTriggersDown(entity: Type<object>, installed?: InstalledTriggers): string[];
54
- /** `dropped` taken off `entity`'s table and `created` put on, which is a reconcile read either way. */
55
- private swapTriggers;
56
- generateTriggerDrops(entity: Type<object>, names: readonly string[]): string[];
57
35
  /**
58
36
  * One statement per distinct schema the tables being created live in, in first-seen order. Only
59
37
  * the tables actually being created, so a narrowed `only` does not declare namespaces it is not
60
38
  * about to fill. Empty on an engine without schemas, whose tables are never qualified.
61
39
  */
62
- private generateCreateSchemas;
40
+ private createNamespaces;
41
+ /**
42
+ * The inverse of {@link generateCreateSchema}: a table's drop takes its triggers along, so only what they
43
+ * leave behind follows it.
44
+ */
63
45
  generateDropSchema(entities: readonly Type<object>[], options?: DropSchemaOptions): string[];
64
46
  /**
65
47
  * The tables of `entities` in dependency order, optionally narrowed to `only`. The AST always spans
@@ -67,54 +49,31 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
67
49
  * resolves instead of being silently dropped.
68
50
  */
69
51
  private orderedTables;
70
- generateDropTable(tableName: string, options?: DropSchemaOptions): string;
52
+ private dropTableSql;
71
53
  /**
72
54
  * The statements taking a table through `diff`, in the one order both directions need: whatever holds
73
55
  * something down goes before it and comes back after it. A foreign key holds its columns and the key it
74
56
  * points at, so it goes first and comes back last; the key holds its columns; and some engines drop an
75
- * index along with its column, which would leave nothing to name. An alter is its drop, then its add.
57
+ * index along with its column, which would leave nothing to name. A check holds the columns it names, which
58
+ * MySQL refuses to rename or drop under one. An alter is its drop, then its add.
76
59
  */
77
60
  generateAlterTable(diff: SchemaDiff): string[];
61
+ /** `CONSTRAINT <name> CHECK (...)`, in a `CREATE TABLE`, after `ADD`, or inline where a column brings it. */
62
+ private checkConstraint;
63
+ private addCheckSql;
64
+ private dropCheckSql;
78
65
  /**
79
66
  * Each column the changes make required while declaring a default, and that default as SQL: the rows
80
67
  * already there hold a null it has to replace, and it is the only value the entity says it may take.
81
68
  */
82
69
  private defaultFills;
83
- /** `ADD CONSTRAINT` for each of `foreignKeys`. */
84
- private addForeignKeyStatements;
85
70
  /** An index added to a table that may already have rows: its `CREATE`, then what the engine needs after. */
86
71
  private addIndexStatements;
87
- /** A column added to a table that exists, and its comment where the engine keeps one apart. */
88
- private addColumnStatements;
89
- generateCreateIndex(tableName: string, index: IndexSchema, options?: {
90
- ifNotExists?: boolean;
91
- }): string;
92
72
  /**
93
- * `schema` is the table's, because that is where its indexes live. MySQL takes it from the table
94
- * operand instead, which is already qualified.
73
+ * A column added to a table that exists. `checks` go inline, which is the one way to constrain a table that is
74
+ * rebuilt to alter; a stored generated column, an engine that rebuilds tables takes only in a `CREATE TABLE`.
95
75
  */
96
- generateDropIndex(tableName: string, indexName: string, schema?: string): string;
97
- /**
98
- * A column definition from a {@link ColumnSchema}, whose type is already the engine's spelling. Apart from
99
- * {@link generateColumnFromNode}, which alone knows an `enum`; both render through {@link renderColumn}.
100
- */
101
- generateColumnDefinitionFromSchema(column: ColumnSchema): string;
102
- /**
103
- * The one place a column definition is spelled, so the `ColumnSchema` and `ColumnNode` paths cannot
104
- * drift. A key column states `NOT NULL` rather than leave it to the key: SQLite lets a key column hold
105
- * NULL otherwise, and SQL Server adds no key over a nullable column. Never `UNIQUE`: a unique column is
106
- * a unique index, which the table creates beside it. An enum's `CHECK` comes last, the only place MariaDB takes it.
107
- */
108
- private renderColumn;
109
- /** The inline ` COMMENT '...'` a column declaration carries, where the engine takes one there. */
110
- generateColumnComment(comment: string): string;
111
- /** The `COMMENT ON` statements a table and its columns need, after the `CREATE TABLE`, where the engine uses them. */
112
- protected generateCommentStatements(table: TableNode): string[];
113
- /** The `COMMENT ON COLUMN` a column needs where the engine uses one, for `CREATE TABLE` and every path adding a column. */
114
- protected generateColumnCommentStatement(tableName: string, column: {
115
- name: string;
116
- comment?: string;
117
- }, schema?: string): string[];
76
+ private addColumnStatements;
118
77
  /**
119
78
  * How the entity differs from the table the database reported, compared by {@link diffTable}, the one
120
79
  * drift detection runs, with types normalized as the engine stores them.
@@ -122,8 +81,8 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
122
81
  diffSchema(entity: Type<object>, currentTable: TableNode | undefined, desiredAst?: SchemaAST, renamedColumns?: readonly Rename[]): SchemaDiff | undefined;
123
82
  /**
124
83
  * Both ends of rebuilding `actual` as `desired`. The new table is the entity's, keeping what it cannot
125
- * know of: the indexes and triggers uql did not make, and foreign keys to tables no entity names. The
126
- * old one is the engine's own statements, so a rollback restores it exactly, checks included.
84
+ * know of: the indexes, checks and triggers uql did not make, and foreign keys to tables no entity names.
85
+ * The old one is the engine's own statements, so a rollback restores it exactly.
127
86
  */
128
87
  private rebuildOf;
129
88
  diffOptions(): DiffOptions;
@@ -136,51 +95,23 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
136
95
  generateCreateTableFromNode(table: TableNode, options?: {
137
96
  ifNotExists?: boolean;
138
97
  }): string[];
139
- /**
140
- * Generate a column definition from a ColumnNode. The primary key is never inline: it is always a table
141
- * constraint, so a later `DROP` can name it.
142
- */
143
- protected generateColumnFromNode(col: ColumnNode): string;
144
- /**
145
- * Generate CREATE INDEX SQL from an IndexNode.
146
- * Delegates to `generateCreateIndex` for unified SQL assembly.
147
- */
148
- generateCreateIndexFromNode(index: IndexNode, options?: {
149
- ifNotExists: boolean;
150
- }): string;
98
+ /** The `CREATE INDEX` for an index of the AST. */
99
+ private createIndexFromNode;
151
100
  generateCreateTableFromDefinition(table: TableDefinition, options?: {
152
101
  ifNotExists?: boolean;
153
102
  }): string[];
154
- generateRenameTableSql(oldName: string, newName: string): string;
155
103
  /** `raw` is split, being the one SQL no generator wrote. */
156
104
  generateOperation(operation: AnyMigrationOperation): string[];
157
105
  /** `ADD COLUMN`, plus the foreign key and index the column declares, as `CREATE TABLE` lifts them. */
158
- generateAddColumnSql(tableName: string, column: FullColumnDefinition): string[];
159
- generateAlterColumnSql(tableName: string, columnName: string, column: FullColumnDefinition): string[];
160
- generateDropColumnSql(tableName: string, columnName: string): string[];
161
- generateRenameColumnSql(tableName: string, oldName: string, newName: string): string;
106
+ private addColumnSql;
162
107
  /**
163
108
  * `CONSTRAINT <name> FOREIGN KEY (...) REFERENCES ... ON DELETE ... ON UPDATE ...`.
164
109
  *
165
110
  * One spelling for the two places that need it - inline in a `CREATE TABLE`, and after `ADD` in an
166
111
  * `ALTER`. Written twice, the two drifted over which end they qualified with a schema.
167
112
  */
168
- protected foreignKeyConstraint(tableName: string, foreignKey: ForeignKeySchema, refTableSql: string): string;
169
- generateAddForeignKeySql(tableName: string, foreignKey: ForeignKeySchema): string;
170
- generateDropForeignKeySql(tableName: string, constraintName: string): string;
171
- /**
172
- * `ALTER TABLE ... ADD CONSTRAINT <name> PRIMARY KEY (...)`, the other half of
173
- * {@link generateDropPrimaryKeySql}. Refused where the engine cannot alter a key at all, by name,
174
- * rather than emitting DDL it will reject.
175
- */
176
- generateAddPrimaryKeySql(tableName: string, columns: readonly string[], name?: string): string;
177
- /**
178
- * Drops the table's key, by the name the constraint really has: introspected, or derived where this
179
- * generator added it. MySQL takes no name.
180
- */
181
- generateDropPrimaryKeySql(tableName: string, constraintName?: string): string;
182
- /** A stored generated column, which an engine that rebuilds tables takes only in a `CREATE TABLE`. */
183
- private assertColumnAddable;
113
+ private foreignKeyConstraint;
114
+ private addForeignKeySql;
184
115
  /**
185
116
  * Refuses `what` where the engine makes it only by rebuilding the table, which a migration generated
186
117
  * from the entities does and a lone statement of the builder cannot.
@@ -192,8 +123,3 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
192
123
  * Shared by the add and the drop so a `DROP CONSTRAINT` names exactly what an `ADD CONSTRAINT` made.
193
124
  */
194
125
  export declare function constraintNameOf(tableName: string, foreignKey: ForeignKeySchema): string;
195
- /**
196
- * The entities as an AST, named by `generator`'s resolvers rather than a naming strategy, which would
197
- * also rename an explicit `@Entity({ name })` and so compare each table under another name.
198
- */
199
- export declare function buildEntityAST(generator: Pick<SchemaGenerator, 'resolveTableAlias' | 'resolveSchema' | 'resolveColumnName' | 'compileDdl' | 'compileIndexPredicate'>, entities: readonly Type<object>[], options?: Pick<BuildSchemaASTOptions, 'defaultForeignKeyAction' | 'textScoreIndexes' | 'vectorIndexRequiresNotNull'>): SchemaAST;