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.
Files changed (58) hide show
  1. package/README.md +9 -8
  2. package/dist/browser/uql-browser.min.js.map +1 -1
  3. package/dist/cockroachdb/cockroachDialect.js +1 -1
  4. package/dist/dialect/indexSqlDialect.d.ts +3 -2
  5. package/dist/dialect/indexSqlDialect.js +10 -8
  6. package/dist/dialect/mysqlLikeSqlDialect.d.ts +0 -2
  7. package/dist/dialect/mysqlLikeSqlDialect.js +0 -7
  8. package/dist/dialect/pgLikeSqlDialect.js +1 -0
  9. package/dist/maria/mariaDialect.js +1 -1
  10. package/dist/migrate/bin.js +0 -0
  11. package/dist/migrate/builder/migrationBuilder.js +1 -1
  12. package/dist/migrate/builder/tableBuilder.js +2 -2
  13. package/dist/migrate/cli.js +4 -6
  14. package/dist/migrate/codegen/entityCodeGenerator.d.ts +5 -0
  15. package/dist/migrate/codegen/entityCodeGenerator.js +32 -27
  16. package/dist/migrate/codegen/fieldOptionsSource.d.ts +1 -1
  17. package/dist/migrate/codegen/fieldOptionsSource.js +6 -1
  18. package/dist/migrate/codegen/indexDecoratorSource.d.ts +14 -0
  19. package/dist/migrate/codegen/indexDecoratorSource.js +105 -0
  20. package/dist/migrate/drift/driftDetector.d.ts +5 -50
  21. package/dist/migrate/drift/driftDetector.js +215 -224
  22. package/dist/migrate/drift/index.d.ts +1 -1
  23. package/dist/migrate/drift/index.js +1 -1
  24. package/dist/migrate/generator/definitionToNode.d.ts +9 -0
  25. package/dist/migrate/generator/definitionToNode.js +79 -0
  26. package/dist/migrate/generator/indexNodeToSchema.js +4 -2
  27. package/dist/migrate/generator/mongoSchemaGenerator.js +3 -3
  28. package/dist/migrate/introspection/baseSqlIntrospector.d.ts +3 -0
  29. package/dist/migrate/introspection/baseSqlIntrospector.js +13 -5
  30. package/dist/migrate/introspection/mongoIntrospector.d.ts +3 -0
  31. package/dist/migrate/introspection/mongoIntrospector.js +5 -10
  32. package/dist/migrate/introspection/mysqlIntrospector.js +1 -1
  33. package/dist/migrate/introspection/postgresIntrospector.d.ts +57 -5
  34. package/dist/migrate/introspection/postgresIntrospector.js +93 -10
  35. package/dist/migrate/introspection/sqliteIntrospector.js +1 -1
  36. package/dist/migrate/migrator.js +3 -2
  37. package/dist/migrate/schemaGenerator.d.ts +26 -3
  38. package/dist/migrate/schemaGenerator.js +53 -92
  39. package/dist/schema/index.d.ts +3 -3
  40. package/dist/schema/index.js +2 -2
  41. package/dist/schema/indexColumns.d.ts +10 -0
  42. package/dist/schema/indexColumns.js +11 -0
  43. package/dist/schema/indexDifferences.d.ts +22 -0
  44. package/dist/schema/indexDifferences.js +49 -0
  45. package/dist/schema/schemaAST.js +2 -8
  46. package/dist/schema/schemaASTBuilder.d.ts +6 -59
  47. package/dist/schema/schemaASTBuilder.js +208 -233
  48. package/dist/schema/schemaASTDiffer.d.ts +9 -56
  49. package/dist/schema/schemaASTDiffer.js +229 -393
  50. package/dist/schema/types.d.ts +5 -12
  51. package/dist/schema/types.js +15 -0
  52. package/dist/type/dialect.d.ts +7 -2
  53. package/dist/type/dialect.js +1 -0
  54. package/dist/type/entity.d.ts +12 -10
  55. package/dist/type/migration.d.ts +14 -1
  56. package/dist/util/string.util.js +6 -1
  57. package/package.json +3 -4
  58. package/LICENSE.md +0 -22
@@ -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 type IndexType = 'btree' | 'hash' | 'gin' | 'gist' | 'brin' | 'fulltext' | 'hnsw' | 'ivfflat' | 'vector' | 'vectorSearch';
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 = Omit<IndexSchema, 'columns'> & {
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
  */
@@ -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
+ ];
@@ -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>;
@@ -1,5 +1,6 @@
1
1
  export const INDEX_FEATURE_LABELS = {
2
2
  expression: 'expression indexes',
3
+ partial: 'partial indexes',
3
4
  prefixLength: 'index prefix lengths',
4
5
  nullsOrder: 'NULLS FIRST/LAST in an index',
5
6
  opsClass: 'index operator classes',
@@ -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 do the work instead of the
367
- * ORM: `onDelete: 'CASCADE'` makes deleting the parent a single statement rather than the graph walk
368
- * `cascade` performs. Defaults to the migrator's `defaultForeignKeyAction`.
369
- *
370
- * Read only from the side that owns the key (`@ManyToOne`, or a `@OneToOne` without `mappedBy`),
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;
@@ -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
- readonly columns: readonly IndexColumnSchema[];
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
  */
@@ -43,7 +43,12 @@ export function pascalCase(str) {
43
43
  return '';
44
44
  return str
45
45
  .split(/[_\s-]+/)
46
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
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.25.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.