uql-orm 0.97.0 → 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 (114) 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 +57 -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 +51 -168
  20. package/dist/migrate/codegen/fieldOptionsSource.js +3 -6
  21. package/dist/migrate/codegen/index.d.ts +2 -7
  22. package/dist/migrate/codegen/index.js +2 -8
  23. package/dist/migrate/codegen/migrationFile.d.ts +1 -8
  24. package/dist/migrate/codegen/migrationFile.js +9 -13
  25. package/dist/migrate/ddl/defaultSql.d.ts +2 -1
  26. package/dist/migrate/ddl/defaultSql.js +1 -3
  27. package/dist/migrate/ddl/indexCapabilities.d.ts +18 -0
  28. package/dist/migrate/ddl/indexCapabilities.js +60 -0
  29. package/dist/migrate/ddl/indexDdl.d.ts +11 -24
  30. package/dist/migrate/ddl/indexDdl.js +22 -28
  31. package/dist/migrate/ddl/mssqlIndexDdl.d.ts +1 -7
  32. package/dist/migrate/ddl/mssqlIndexDdl.js +1 -7
  33. package/dist/migrate/ddl/mssqlTableDdl.d.ts +6 -9
  34. package/dist/migrate/ddl/mssqlTableDdl.js +14 -17
  35. package/dist/migrate/ddl/mysqlIndexDdl.d.ts +0 -21
  36. package/dist/migrate/ddl/mysqlIndexDdl.js +4 -48
  37. package/dist/migrate/ddl/mysqlTableDdl.d.ts +6 -5
  38. package/dist/migrate/ddl/mysqlTableDdl.js +15 -10
  39. package/dist/migrate/ddl/pgIndexDdl.d.ts +0 -10
  40. package/dist/migrate/ddl/pgIndexDdl.js +5 -44
  41. package/dist/migrate/ddl/pgTableDdl.d.ts +6 -2
  42. package/dist/migrate/ddl/pgTableDdl.js +17 -1
  43. package/dist/migrate/ddl/sqliteIndexDdl.js +2 -7
  44. package/dist/migrate/ddl/tableDdl.d.ts +43 -24
  45. package/dist/migrate/ddl/tableDdl.js +56 -37
  46. package/dist/migrate/ddl/tableRebuild.d.ts +2 -1
  47. package/dist/migrate/drift/driftDetector.d.ts +29 -32
  48. package/dist/migrate/drift/driftDetector.js +139 -205
  49. package/dist/migrate/drift/index.d.ts +1 -6
  50. package/dist/migrate/drift/index.js +1 -6
  51. package/dist/migrate/generator/definitionToNode.js +3 -3
  52. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +53 -76
  53. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +68 -90
  54. package/dist/migrate/introspection/mssqlIntrospector.d.ts +8 -43
  55. package/dist/migrate/introspection/mssqlIntrospector.js +44 -77
  56. package/dist/migrate/introspection/mysqlIntrospector.d.ts +11 -38
  57. package/dist/migrate/introspection/mysqlIntrospector.js +48 -57
  58. package/dist/migrate/introspection/postgresIntrospector.d.ts +12 -60
  59. package/dist/migrate/introspection/postgresIntrospector.js +62 -77
  60. package/dist/migrate/introspection/sqliteIntrospector.d.ts +14 -53
  61. package/dist/migrate/introspection/sqliteIntrospector.js +59 -119
  62. package/dist/migrate/introspection/tableSchemaAST.d.ts +13 -0
  63. package/dist/migrate/introspection/tableSchemaAST.js +85 -0
  64. package/dist/migrate/migrationTarget.js +10 -2
  65. package/dist/migrate/migrator.d.ts +4 -21
  66. package/dist/migrate/migrator.js +47 -71
  67. package/dist/migrate/schemaChange.d.ts +0 -2
  68. package/dist/migrate/schemaChange.js +1 -1
  69. package/dist/migrate/schemaGenerator.d.ts +22 -97
  70. package/dist/migrate/schemaGenerator.js +113 -298
  71. package/dist/migrate/storage/databaseStorage.d.ts +2 -1
  72. package/dist/migrate/storage/databaseStorage.js +3 -2
  73. package/dist/migrate/storage/jsonStorage.d.ts +1 -2
  74. package/dist/migrate/storage/jsonStorage.js +11 -20
  75. package/dist/migrate/triggerSql.d.ts +3 -3
  76. package/dist/migrate/triggerSql.js +5 -4
  77. package/dist/mongo/index.d.ts +0 -1
  78. package/dist/mongo/index.js +0 -1
  79. package/dist/mongo/mongoDialect.js +0 -1
  80. package/dist/mongo/mongoIntrospector.d.ts +0 -3
  81. package/dist/mongo/mongoIntrospector.js +7 -14
  82. package/dist/mongo/mongoSchemaGenerator.d.ts +7 -20
  83. package/dist/mongo/mongoSchemaGenerator.js +51 -70
  84. package/dist/mssql/mssqlDialect.js +0 -1
  85. package/dist/schema/canonicalType.d.ts +15 -19
  86. package/dist/schema/canonicalType.js +20 -43
  87. package/dist/schema/dependencyGraph.d.ts +2 -3
  88. package/dist/schema/dependencyGraph.js +0 -4
  89. package/dist/schema/indexDifferences.js +2 -2
  90. package/dist/schema/schemaAST.d.ts +1 -1
  91. package/dist/schema/schemaAST.js +4 -12
  92. package/dist/schema/schemaASTBuilder.d.ts +2 -5
  93. package/dist/schema/schemaASTBuilder.js +11 -14
  94. package/dist/schema/schemaASTDiffer.d.ts +4 -5
  95. package/dist/schema/schemaASTDiffer.js +22 -70
  96. package/dist/schema/types.d.ts +1 -48
  97. package/dist/sqlite/localSqliteQuerierPool.d.ts +16 -2
  98. package/dist/sqlite/localSqliteQuerierPool.js +20 -4
  99. package/dist/sqlite/nodeSqliteQuerierPool.js +2 -2
  100. package/dist/sqlite/sqliteDialect.js +0 -1
  101. package/dist/sqlite/sqliteQuerierPool.js +3 -3
  102. package/dist/type/dialect.d.ts +0 -2
  103. package/dist/type/migration.d.ts +3 -54
  104. package/dist/util/ddlExpression.util.d.ts +2 -2
  105. package/dist/util/ddlExpression.util.js +3 -3
  106. package/dist/util/sql.util.d.ts +0 -8
  107. package/dist/util/sql.util.js +7 -12
  108. package/package.json +1 -1
  109. package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -36
  110. package/dist/migrate/introspection/baseSqlIntrospector.js +0 -133
  111. package/dist/schema/index.d.ts +0 -2
  112. package/dist/schema/index.js +0 -1
  113. package/dist/sqlite/sqlitePragmas.d.ts +0 -3
  114. 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, 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,25 +14,18 @@ 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
@@ -48,7 +37,7 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
48
37
  * the tables actually being created, so a narrowed `only` does not declare namespaces it is not
49
38
  * about to fill. Empty on an engine without schemas, whose tables are never qualified.
50
39
  */
51
- private generateCreateSchemas;
40
+ private createNamespaces;
52
41
  /**
53
42
  * The inverse of {@link generateCreateSchema}: a table's drop takes its triggers along, so only what they
54
43
  * leave behind follows it.
@@ -60,7 +49,7 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
60
49
  * resolves instead of being silently dropped.
61
50
  */
62
51
  private orderedTables;
63
- generateDropTable(tableName: string, options?: DropSchemaOptions): string;
52
+ private dropTableSql;
64
53
  /**
65
54
  * The statements taking a table through `diff`, in the one order both directions need: whatever holds
66
55
  * something down goes before it and comes back after it. A foreign key holds its columns and the key it
@@ -78,44 +67,13 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
78
67
  * already there hold a null it has to replace, and it is the only value the entity says it may take.
79
68
  */
80
69
  private defaultFills;
81
- /** `ADD CONSTRAINT` for each of `foreignKeys`. */
82
- private addForeignKeyStatements;
83
70
  /** An index added to a table that may already have rows: its `CREATE`, then what the engine needs after. */
84
71
  private addIndexStatements;
85
72
  /**
86
- * A column added to a table that exists, and its comment where the engine keeps one apart. `checks` go
87
- * inline, which is the one way to constrain a table that is rebuilt to alter.
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`.
88
75
  */
89
76
  private addColumnStatements;
90
- generateCreateIndex(tableName: string, index: IndexSchema, options?: {
91
- ifNotExists?: boolean;
92
- }): string;
93
- /**
94
- * `schema` is the table's, because that is where its indexes live. MySQL takes it from the table
95
- * operand instead, which is already qualified.
96
- */
97
- generateDropIndex(tableName: string, indexName: string, schema?: string): string;
98
- /**
99
- * A column definition from a {@link ColumnSchema}, whose type is already the engine's spelling. Apart from
100
- * {@link generateColumnFromNode}, which sizes a canonical type; both render through {@link renderColumn}.
101
- */
102
- generateColumnDefinitionFromSchema(column: ColumnSchema): string;
103
- /**
104
- * The one place a column definition is spelled, so the `ColumnSchema` and `ColumnNode` paths cannot
105
- * drift. A key column states `NOT NULL` rather than leave it to the key: SQLite lets a key column hold
106
- * NULL otherwise, and SQL Server adds no key over a nullable column. Never `UNIQUE`: a unique column is
107
- * a unique index, which the table creates beside it. Nor an enum's `CHECK`, which is the table's, named.
108
- */
109
- private renderColumn;
110
- /** The inline ` COMMENT '...'` a column declaration carries, where the engine takes one there. */
111
- generateColumnComment(comment: string): string;
112
- /** The `COMMENT ON` statements a table and its columns need, after the `CREATE TABLE`, where the engine uses them. */
113
- protected generateCommentStatements(table: TableNode): string[];
114
- /** The `COMMENT ON COLUMN` a column needs where the engine uses one, for `CREATE TABLE` and every path adding a column. */
115
- protected generateColumnCommentStatement(tableName: string, column: {
116
- name: string;
117
- comment?: string;
118
- }, schema?: string): string[];
119
77
  /**
120
78
  * How the entity differs from the table the database reported, compared by {@link diffTable}, the one
121
79
  * drift detection runs, with types normalized as the engine stores them.
@@ -137,51 +95,23 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
137
95
  generateCreateTableFromNode(table: TableNode, options?: {
138
96
  ifNotExists?: boolean;
139
97
  }): string[];
140
- /**
141
- * Generate a column definition from a ColumnNode. The primary key is never inline: it is always a table
142
- * constraint, so a later `DROP` can name it.
143
- */
144
- protected generateColumnFromNode(col: ColumnNode): string;
145
- /**
146
- * Generate CREATE INDEX SQL from an IndexNode.
147
- * Delegates to `generateCreateIndex` for unified SQL assembly.
148
- */
149
- generateCreateIndexFromNode(index: IndexNode, options?: {
150
- ifNotExists: boolean;
151
- }): string;
98
+ /** The `CREATE INDEX` for an index of the AST. */
99
+ private createIndexFromNode;
152
100
  generateCreateTableFromDefinition(table: TableDefinition, options?: {
153
101
  ifNotExists?: boolean;
154
102
  }): string[];
155
- generateRenameTableSql(oldName: string, newName: string): string;
156
103
  /** `raw` is split, being the one SQL no generator wrote. */
157
104
  generateOperation(operation: AnyMigrationOperation): string[];
158
105
  /** `ADD COLUMN`, plus the foreign key and index the column declares, as `CREATE TABLE` lifts them. */
159
- generateAddColumnSql(tableName: string, column: FullColumnDefinition): string[];
160
- generateAlterColumnSql(tableName: string, columnName: string, column: FullColumnDefinition): string[];
161
- generateDropColumnSql(tableName: string, columnName: string): string[];
162
- generateRenameColumnSql(tableName: string, oldName: string, newName: string): string;
106
+ private addColumnSql;
163
107
  /**
164
108
  * `CONSTRAINT <name> FOREIGN KEY (...) REFERENCES ... ON DELETE ... ON UPDATE ...`.
165
109
  *
166
110
  * One spelling for the two places that need it - inline in a `CREATE TABLE`, and after `ADD` in an
167
111
  * `ALTER`. Written twice, the two drifted over which end they qualified with a schema.
168
112
  */
169
- protected foreignKeyConstraint(tableName: string, foreignKey: ForeignKeySchema, refTableSql: string): string;
170
- generateAddForeignKeySql(tableName: string, foreignKey: ForeignKeySchema): string;
171
- generateDropForeignKeySql(tableName: string, constraintName: string): string;
172
- /**
173
- * `ALTER TABLE ... ADD CONSTRAINT <name> PRIMARY KEY (...)`, the other half of
174
- * {@link generateDropPrimaryKeySql}. Refused where the engine cannot alter a key at all, by name,
175
- * rather than emitting DDL it will reject.
176
- */
177
- generateAddPrimaryKeySql(tableName: string, columns: readonly string[], name?: string): string;
178
- /**
179
- * Drops the table's key, by the name the constraint really has: introspected, or derived where this
180
- * generator added it. MySQL takes no name.
181
- */
182
- generateDropPrimaryKeySql(tableName: string, constraintName?: string): string;
183
- /** A stored generated column, which an engine that rebuilds tables takes only in a `CREATE TABLE`. */
184
- private assertColumnAddable;
113
+ private foreignKeyConstraint;
114
+ private addForeignKeySql;
185
115
  /**
186
116
  * Refuses `what` where the engine makes it only by rebuilding the table, which a migration generated
187
117
  * from the entities does and a lone statement of the builder cannot.
@@ -193,8 +123,3 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
193
123
  * Shared by the add and the drop so a `DROP CONSTRAINT` names exactly what an `ADD CONSTRAINT` made.
194
124
  */
195
125
  export declare function constraintNameOf(tableName: string, foreignKey: ForeignKeySchema): string;
196
- /**
197
- * The entities as an AST, named by `generator`'s resolvers rather than a naming strategy, which would
198
- * also rename an explicit `@Entity({ name })` and so compare each table under another name.
199
- */
200
- export declare function buildEntityAST(generator: Pick<SchemaGenerator, 'resolveTableAlias' | 'resolveSchema' | 'resolveColumnName' | 'compileDdl' | 'compileIndexPredicate'>, entities: readonly Type<object>[], options?: Pick<BuildSchemaASTOptions, 'defaultForeignKeyAction' | 'textScoreIndexes' | 'vectorIndexRequiresNotNull' | 'renderTriggers'>): SchemaAST;