uql-orm 0.25.0 → 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/bin.js +0 -0
- 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 +32 -27
- 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 -233
- 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/entity.d.ts +12 -10
- package/dist/type/migration.d.ts +14 -1
- package/dist/util/string.util.js +6 -1
- package/package.json +3 -4
- package/LICENSE.md +0 -22
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/entity.d.ts
CHANGED
|
@@ -237,6 +237,13 @@ export type FieldOptions<V = TsTypeOf<FieldType>> = {
|
|
|
237
237
|
* Entity that this field references (for foreign keys).
|
|
238
238
|
*/
|
|
239
239
|
readonly references?: EntityGetter;
|
|
240
|
+
/**
|
|
241
|
+
* Referential action for the generated foreign key. Delete side only: `onUpdate` below already means
|
|
242
|
+
* a value callback. Reach for `@ManyToOne({ onDelete, onUpdate })` when the update side matters too, or
|
|
243
|
+
* when this disagrees with a relation also declared on the same column (the relation wins).
|
|
244
|
+
* @example `@Field({ references: () => Company, onDelete: 'CASCADE' }) companyId?: string;`
|
|
245
|
+
*/
|
|
246
|
+
readonly onDelete?: ForeignKeyAction;
|
|
240
247
|
readonly virtual?: QueryRaw;
|
|
241
248
|
readonly updatable?: boolean;
|
|
242
249
|
readonly eager?: boolean;
|
|
@@ -363,16 +370,11 @@ export type RelationOptions<E = any> = {
|
|
|
363
370
|
cardinality: RelationCardinality;
|
|
364
371
|
readonly cascade?: boolean | CascadeType;
|
|
365
372
|
/**
|
|
366
|
-
* Referential actions for the generated foreign key, letting the database
|
|
367
|
-
*
|
|
368
|
-
* `
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
* matching where TypeORM, Prisma and Drizzle put it. Not available on a bare `@Field({ references })`
|
|
372
|
-
* with no relation, because `FieldOptions.onUpdate` already means a value callback there.
|
|
373
|
-
*
|
|
374
|
-
* This overlaps `cascade` rather than conflicting with it: declaring both deletes the children in JS
|
|
375
|
-
* and then leaves the foreign key nothing to cascade, so pick one.
|
|
373
|
+
* Referential actions for the generated foreign key, letting the database cascade instead of the ORM's
|
|
374
|
+
* `cascade` (pick one; declaring both leaves the FK nothing to do). Read from the owning side
|
|
375
|
+
* (`@ManyToOne`, or a `@OneToOne` without `mappedBy`). `onDelete` falls back to the FK field's own
|
|
376
|
+
* `@Field({ onDelete })` when unset here; `onUpdate` has no such fallback since that key already means
|
|
377
|
+
* a value callback on `FieldOptions`.
|
|
376
378
|
*/
|
|
377
379
|
readonly onDelete?: ForeignKeyAction;
|
|
378
380
|
readonly onUpdate?: ForeignKeyAction;
|
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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"homepage": "https://uql-orm.dev",
|
|
4
4
|
"description": "Extremely fast, type-safe TypeScript ORM - one API for every database",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.26.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=24"
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
],
|
|
59
59
|
"scripts": {
|
|
60
60
|
"prepack": "bun run verify-dist.ts && cp ../../README.md .",
|
|
61
|
-
"postpack": "rm README.md",
|
|
61
|
+
"postpack": "rm README.md && npm pkg delete gitHead",
|
|
62
62
|
"compile.browser": "bun build src/browser/index.ts --minify --sourcemap=linked --format=esm --target=browser --outdir=dist/browser --entry-naming 'uql-browser.min.[ext]'",
|
|
63
63
|
"build": "bun run clean && tsc -b tsconfig.build.json && bun run compile.browser && bun run verify-dist.ts",
|
|
64
64
|
"start": "tsc --watch",
|
|
@@ -197,6 +197,5 @@
|
|
|
197
197
|
],
|
|
198
198
|
"publishConfig": {
|
|
199
199
|
"access": "public"
|
|
200
|
-
}
|
|
201
|
-
"gitHead": "cfe2b005308b808d2e6e3d6e062c13791c883d13"
|
|
200
|
+
}
|
|
202
201
|
}
|
package/LICENSE.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2015-present UQL Contributors
|
|
2
|
-
|
|
3
|
-
MIT License
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
a copy of this software and associated documentation files (the
|
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
-
the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
included in all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|