uql-orm 0.25.1 → 0.26.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/README.md +9 -8
- package/dist/browser/uql-browser.min.js.map +1 -1
- package/dist/cockroachdb/cockroachDialect.js +1 -1
- package/dist/dialect/indexSqlDialect.d.ts +3 -2
- package/dist/dialect/indexSqlDialect.js +10 -8
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +0 -2
- package/dist/dialect/mysqlLikeSqlDialect.js +0 -7
- package/dist/dialect/pgLikeSqlDialect.js +1 -0
- package/dist/maria/mariaDialect.js +1 -1
- package/dist/migrate/builder/migrationBuilder.js +1 -1
- package/dist/migrate/builder/tableBuilder.js +2 -2
- package/dist/migrate/cli.js +4 -6
- package/dist/migrate/codegen/entityCodeGenerator.d.ts +5 -0
- package/dist/migrate/codegen/entityCodeGenerator.js +22 -25
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +1 -1
- package/dist/migrate/codegen/fieldOptionsSource.js +6 -1
- package/dist/migrate/codegen/indexDecoratorSource.d.ts +14 -0
- package/dist/migrate/codegen/indexDecoratorSource.js +105 -0
- package/dist/migrate/drift/driftDetector.d.ts +5 -50
- package/dist/migrate/drift/driftDetector.js +215 -224
- package/dist/migrate/drift/index.d.ts +1 -1
- package/dist/migrate/drift/index.js +1 -1
- package/dist/migrate/generator/definitionToNode.d.ts +9 -0
- package/dist/migrate/generator/definitionToNode.js +79 -0
- package/dist/migrate/generator/indexNodeToSchema.js +4 -2
- package/dist/migrate/generator/mongoSchemaGenerator.js +3 -3
- package/dist/migrate/introspection/baseSqlIntrospector.d.ts +3 -0
- package/dist/migrate/introspection/baseSqlIntrospector.js +13 -5
- package/dist/migrate/introspection/mongoIntrospector.d.ts +3 -0
- package/dist/migrate/introspection/mongoIntrospector.js +5 -10
- package/dist/migrate/introspection/mysqlIntrospector.js +1 -1
- package/dist/migrate/introspection/postgresIntrospector.d.ts +57 -5
- package/dist/migrate/introspection/postgresIntrospector.js +93 -10
- package/dist/migrate/introspection/sqliteIntrospector.js +1 -1
- package/dist/migrate/migrator.js +3 -2
- package/dist/migrate/schemaGenerator.d.ts +26 -3
- package/dist/migrate/schemaGenerator.js +53 -92
- package/dist/schema/index.d.ts +3 -3
- package/dist/schema/index.js +2 -2
- package/dist/schema/indexColumns.d.ts +10 -0
- package/dist/schema/indexColumns.js +11 -0
- package/dist/schema/indexDifferences.d.ts +22 -0
- package/dist/schema/indexDifferences.js +49 -0
- package/dist/schema/schemaAST.js +2 -8
- package/dist/schema/schemaASTBuilder.d.ts +6 -59
- package/dist/schema/schemaASTBuilder.js +208 -236
- package/dist/schema/schemaASTDiffer.d.ts +9 -56
- package/dist/schema/schemaASTDiffer.js +229 -393
- package/dist/schema/types.d.ts +5 -12
- package/dist/schema/types.js +15 -0
- package/dist/type/dialect.d.ts +7 -2
- package/dist/type/dialect.js +1 -0
- package/dist/type/migration.d.ts +14 -1
- package/dist/util/string.util.js +6 -1
- package/package.json +1 -1
package/dist/schema/types.d.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* A unified graph representation of database schema with relationships as first-class citizens.
|
|
5
5
|
* Enables reliable diffing, smart relation detection, and dialect-agnostic schema operations.
|
|
6
6
|
*/
|
|
7
|
-
import type { IndexColumnSchema } from '../type/entity.js';
|
|
8
7
|
import type { IndexSchema } from '../type/migration.js';
|
|
9
8
|
/**
|
|
10
9
|
* Type categories universal across SQL dialects.
|
|
@@ -56,7 +55,8 @@ export type RelationshipSource = 'explicit_fk' | 'entity_decorator' | 'naming_pa
|
|
|
56
55
|
/**
|
|
57
56
|
* Index algorithm/type supported by various databases.
|
|
58
57
|
*/
|
|
59
|
-
export
|
|
58
|
+
export declare const INDEX_TYPES: readonly ['btree', 'hash', 'gin', 'gist', 'brin', 'fulltext', 'hnsw', 'ivfflat', 'vector', 'vectorSearch'];
|
|
59
|
+
export type IndexType = (typeof INDEX_TYPES)[number];
|
|
60
60
|
/**
|
|
61
61
|
* Source of where an index was defined.
|
|
62
62
|
*/
|
|
@@ -149,16 +149,9 @@ export interface RelationshipNode {
|
|
|
149
149
|
* Index node in the schema graph.
|
|
150
150
|
* Represents a database index on one or more columns.
|
|
151
151
|
*/
|
|
152
|
-
export type IndexNode =
|
|
152
|
+
export type IndexNode = IndexSchema & {
|
|
153
153
|
/** Reference to the table this index belongs to */
|
|
154
154
|
readonly table: TableNode;
|
|
155
|
-
/** Columns included in the index (order matters). Empty for an index over expressions only. */
|
|
156
|
-
readonly columns: ColumnNode[];
|
|
157
|
-
/**
|
|
158
|
-
* The index as authored, with names resolved: expressions, prefix lengths and per-column order that
|
|
159
|
-
* a `ColumnNode` cannot represent. The generator renders these; `columns` is what diffing compares.
|
|
160
|
-
*/
|
|
161
|
-
readonly entries?: readonly IndexColumnSchema[];
|
|
162
155
|
/** Where this index was defined */
|
|
163
156
|
readonly source?: IndexSource;
|
|
164
157
|
/** Current sync status */
|
|
@@ -187,7 +180,6 @@ export interface ColumnDiff {
|
|
|
187
180
|
readonly actual?: ColumnNode;
|
|
188
181
|
/** Whether this change could cause data loss */
|
|
189
182
|
readonly isBreaking?: boolean;
|
|
190
|
-
/** Human-readable description of the change */
|
|
191
183
|
readonly description?: string;
|
|
192
184
|
}
|
|
193
185
|
/**
|
|
@@ -208,6 +200,7 @@ export interface IndexDiff {
|
|
|
208
200
|
readonly type: 'create' | 'drop' | 'alter';
|
|
209
201
|
readonly expected?: IndexNode;
|
|
210
202
|
readonly actual?: IndexNode;
|
|
203
|
+
readonly description?: string;
|
|
211
204
|
}
|
|
212
205
|
/**
|
|
213
206
|
* Difference between two relationship definitions.
|
|
@@ -263,7 +256,7 @@ export type DriftSeverity = 'critical' | 'warning' | 'info';
|
|
|
263
256
|
/**
|
|
264
257
|
* Type of schema drift.
|
|
265
258
|
*/
|
|
266
|
-
export type DriftType = 'missing_table' | 'unexpected_table' | 'missing_column' | 'unexpected_column' | 'type_mismatch' | 'constraint_mismatch' | 'missing_index' | 'unexpected_index' | 'missing_relationship' | 'unexpected_relationship';
|
|
259
|
+
export type DriftType = 'missing_table' | 'unexpected_table' | 'missing_column' | 'unexpected_column' | 'type_mismatch' | 'constraint_mismatch' | 'missing_index' | 'unexpected_index' | 'index_mismatch' | 'missing_relationship' | 'unexpected_relationship';
|
|
267
260
|
/**
|
|
268
261
|
* A single schema drift issue.
|
|
269
262
|
*/
|
package/dist/schema/types.js
CHANGED
|
@@ -8,3 +8,18 @@
|
|
|
8
8
|
* Default action for foreign key ON DELETE and ON UPDATE clauses.
|
|
9
9
|
*/
|
|
10
10
|
export const DEFAULT_FOREIGN_KEY_ACTION = 'NO ACTION';
|
|
11
|
+
/**
|
|
12
|
+
* Index algorithm/type supported by various databases.
|
|
13
|
+
*/
|
|
14
|
+
export const INDEX_TYPES = [
|
|
15
|
+
'btree',
|
|
16
|
+
'hash',
|
|
17
|
+
'gin',
|
|
18
|
+
'gist',
|
|
19
|
+
'brin',
|
|
20
|
+
'fulltext',
|
|
21
|
+
'hnsw',
|
|
22
|
+
'ivfflat',
|
|
23
|
+
'vector',
|
|
24
|
+
'vectorSearch',
|
|
25
|
+
];
|
package/dist/type/dialect.d.ts
CHANGED
|
@@ -200,7 +200,12 @@ export interface SqlQueryDialect extends QueryDialect {
|
|
|
200
200
|
* An index capability that some engines have and others reject outright. Verified live: expression
|
|
201
201
|
* indexes exist everywhere but MariaDB 12.3 (which needs a generated column); prefix lengths are
|
|
202
202
|
* MySQL-family only and *required* there to index `TEXT`; `NULLS FIRST/LAST` and operator classes are
|
|
203
|
-
* Postgres-only (CockroachDB 26.2 answers "unimplemented"); `INCLUDE` is Postgres-wire only
|
|
203
|
+
* Postgres-only (CockroachDB 26.2 answers "unimplemented"); `INCLUDE` is Postgres-wire only; the
|
|
204
|
+
* MySQL family is alone in having no partial indexes.
|
|
205
|
+
*
|
|
206
|
+
* Introspectors reuse the vocabulary for what they can read *back*, which is what diffing may
|
|
207
|
+
* compare. The two sets are deliberately not the same object and must not be unified: Postgres can
|
|
208
|
+
* emit an expression index and read one back, but MySQL emits one it cannot describe afterwards.
|
|
204
209
|
*/
|
|
205
|
-
export type IndexFeature = 'expression' | 'prefixLength' | 'nullsOrder' | 'opsClass' | 'include';
|
|
210
|
+
export type IndexFeature = 'expression' | 'partial' | 'prefixLength' | 'nullsOrder' | 'opsClass' | 'include';
|
|
206
211
|
export declare const INDEX_FEATURE_LABELS: Record<IndexFeature, string>;
|
package/dist/type/dialect.js
CHANGED
package/dist/type/migration.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { VectorCast } from '../dialect/vectorCast.js';
|
|
2
2
|
import type { FullColumnDefinition, TableDefinition, TableForeignKeyDefinition } from '../migrate/builder/types.js';
|
|
3
|
+
import type { IndexFacet } from '../schema/indexDifferences.js';
|
|
3
4
|
import type { SchemaAST } from '../schema/schemaAST.js';
|
|
4
5
|
import type { ForeignKeyAction, IndexNode, IndexType, TableNode } from '../schema/types.js';
|
|
5
6
|
import type { EntityMeta, FieldOptions, IndexColumnSchema, LoggingOptions, SqlQuerier, Type, VectorIndexOptions } from './index.js';
|
|
@@ -131,7 +132,13 @@ export interface TableSchema {
|
|
|
131
132
|
*/
|
|
132
133
|
export interface IndexSchema extends VectorIndexOptions {
|
|
133
134
|
readonly name: string;
|
|
134
|
-
|
|
135
|
+
/**
|
|
136
|
+
* What the index is over, in order. Named `entries` and not `columns` because an entry need not be
|
|
137
|
+
* a column at all: `raw('lower(email)')` is one, and so is a column carrying a prefix length or a
|
|
138
|
+
* stored order. The authored form, `@Index([...])`, still spells this `columns`, since that is what
|
|
139
|
+
* it reads like at the call site.
|
|
140
|
+
*/
|
|
141
|
+
readonly entries: readonly IndexColumnSchema[];
|
|
135
142
|
readonly unique: boolean;
|
|
136
143
|
/** Index type (btree, hnsw, ivfflat, etc.) */
|
|
137
144
|
readonly type?: IndexType;
|
|
@@ -281,6 +288,12 @@ export interface SqlDdlGenerator extends SchemaGenerator {
|
|
|
281
288
|
* Interface for introspecting the current database schema
|
|
282
289
|
*/
|
|
283
290
|
export interface SchemaIntrospector {
|
|
291
|
+
/**
|
|
292
|
+
* What this introspector can read back about an index, and so all that diffing may compare.
|
|
293
|
+
* Comparing a feature it cannot read reports the same drift forever: the entity side declares it,
|
|
294
|
+
* the database side never reports it, and no migration can close the gap.
|
|
295
|
+
*/
|
|
296
|
+
readonly indexFacets: ReadonlySet<IndexFacet>;
|
|
284
297
|
/**
|
|
285
298
|
* Introspect entire database schema and return SchemaAST.
|
|
286
299
|
*/
|
package/dist/util/string.util.js
CHANGED
|
@@ -43,7 +43,12 @@ export function pascalCase(str) {
|
|
|
43
43
|
return '';
|
|
44
44
|
return str
|
|
45
45
|
.split(/[_\s-]+/)
|
|
46
|
-
.map((word) =>
|
|
46
|
+
.map((word) => {
|
|
47
|
+
// Lower-casing the rest is only right for a word that carries no case of its own: it turns
|
|
48
|
+
// `USER_ID` into `UserId`, but it also turns `tenantId` into `Tenantid`.
|
|
49
|
+
const rest = word === word.toUpperCase() ? word.slice(1).toLowerCase() : word.slice(1);
|
|
50
|
+
return word.charAt(0).toUpperCase() + rest;
|
|
51
|
+
})
|
|
47
52
|
.join('');
|
|
48
53
|
}
|
|
49
54
|
/**
|
package/package.json
CHANGED