uql-orm 0.41.1 → 0.42.1
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/dist/browser/querier/httpQuerier.d.ts +7 -7
- package/dist/browser/querier/httpQuerier.js +21 -6
- package/dist/browser/type/clientQuerier.d.ts +3 -3
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +4 -4
- package/dist/dialect/abstractSqlDialect.d.ts +32 -3
- package/dist/dialect/abstractSqlDialect.js +58 -22
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +3 -2
- package/dist/dialect/mysqlLikeSqlDialect.js +5 -3
- package/dist/dialect/pgLikeSqlDialect.d.ts +1 -1
- package/dist/dialect/pgLikeSqlDialect.js +2 -1
- package/dist/entity/decorator/entity.d.ts +1 -1
- package/dist/entity/decorator/entity.js +1 -1
- package/dist/entity/decorator/members.d.ts +10 -2
- package/dist/entity/index.d.ts +1 -1
- package/dist/entity/index.js +1 -1
- package/dist/entity/metadata/definition.d.ts +18 -1
- package/dist/entity/metadata/definition.js +91 -36
- package/dist/http/handler.js +4 -4
- package/dist/maria/mariaDialect.d.ts +2 -2
- package/dist/maria/mariaDialect.js +3 -2
- package/dist/migrate/builder/tableBuilder.js +5 -4
- package/dist/migrate/drift/driftDetector.js +16 -0
- package/dist/migrate/generator/mongoSchemaGenerator.d.ts +7 -0
- package/dist/migrate/generator/mongoSchemaGenerator.js +24 -28
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +9 -1
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +11 -2
- package/dist/migrate/introspection/baseSqlIntrospector.js +6 -3
- package/dist/migrate/introspection/postgresIntrospector.js +1 -1
- package/dist/migrate/introspection/sqliteIntrospector.js +7 -3
- package/dist/migrate/migrator.js +6 -0
- package/dist/migrate/schemaGenerator.d.ts +44 -34
- package/dist/migrate/schemaGenerator.js +158 -141
- package/dist/mongo/mongoDialect.js +39 -14
- package/dist/mongo/mongodbQuerier.js +6 -3
- package/dist/postgres/postgresDialect.js +1 -1
- package/dist/querier/abstractQuerier.d.ts +16 -12
- package/dist/querier/abstractQuerier.js +88 -40
- package/dist/querier/abstractQuerierPool.d.ts +8 -8
- package/dist/querier/abstractSqlQuerier.d.ts +1 -1
- package/dist/querier/abstractSqlQuerier.js +12 -7
- package/dist/querier/relationCount.js +44 -33
- package/dist/schema/indexDifferences.d.ts +28 -0
- package/dist/schema/indexDifferences.js +46 -0
- package/dist/schema/schemaASTBuilder.js +38 -31
- package/dist/schema/schemaASTDiffer.d.ts +27 -1
- package/dist/schema/schemaASTDiffer.js +54 -18
- package/dist/schema/types.d.ts +46 -7
- package/dist/sqlite/sqliteDialect.d.ts +2 -1
- package/dist/sqlite/sqliteDialect.js +4 -1
- package/dist/type/dialect.d.ts +6 -0
- package/dist/type/entity.d.ts +57 -14
- package/dist/type/migration.d.ts +19 -0
- package/dist/type/queryWhere.d.ts +7 -2
- package/dist/type/universalQuerier.d.ts +8 -8
- package/dist/util/dialect.util.js +15 -14
- package/dist/util/field.util.d.ts +11 -1
- package/dist/util/field.util.js +12 -0
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +1 -0
- package/dist/util/object.util.d.ts +6 -0
- package/dist/util/object.util.js +18 -0
- package/dist/util/relationQuery.util.d.ts +48 -7
- package/dist/util/relationQuery.util.js +70 -9
- package/dist/util/rowKey.util.d.ts +9 -0
- package/dist/util/rowKey.util.js +24 -0
- package/dist/util/sql.util.d.ts +24 -7
- package/dist/util/sql.util.js +75 -10
- package/package.json +1 -1
package/dist/util/sql.util.d.ts
CHANGED
|
@@ -13,20 +13,37 @@ export declare function obtainAttrsPaths<T extends object>(row: T): {
|
|
|
13
13
|
* A name behind its namespace, or bare where there is none: the one place the two are joined, so a
|
|
14
14
|
* table's key, its statement operand and its escaped form cannot spell it differently. Never the
|
|
15
15
|
* seed for a derived identifier - an index or constraint name is a single identifier, and
|
|
16
|
-
* `
|
|
16
|
+
* `sales.Order_total_idx` is a syntax error.
|
|
17
17
|
*/
|
|
18
18
|
export declare function qualifyName(name: string, schema?: string): string;
|
|
19
19
|
/**
|
|
20
|
-
* The name a derived index or constraint gets when nothing named it: `
|
|
20
|
+
* The name a derived index or constraint gets when nothing named it: `Order__total_idx`.
|
|
21
21
|
*
|
|
22
|
-
* One owner, because it is a rule two layers apply and a third has to match: the
|
|
23
|
-
* it, the DDL generator falls back to it, and a
|
|
22
|
+
* One owner for all four kinds, because it is a rule two layers apply and a third has to match: the
|
|
23
|
+
* entity AST derives it, the DDL generator falls back to it, and a `DROP` names what it drops.
|
|
24
24
|
* `table` is the table's own name, never qualified - the result is a single identifier.
|
|
25
|
+
*
|
|
26
|
+
* The kind goes last, as Postgres spells its own (`users_pkey`, `users_email_idx`), so a table's
|
|
27
|
+
* constraints sort together under the table they belong to.
|
|
28
|
+
*/
|
|
29
|
+
export declare function derivedConstraintName(table: string, parts: readonly (string | number)[], kind: ConstraintKind): string;
|
|
30
|
+
/** The kinds of derived name, which is also what `indexNameStem` strips to compare them. */
|
|
31
|
+
export type ConstraintKind = 'pk' | 'fk' | 'idx' | 'ck' | 'uk';
|
|
32
|
+
/**
|
|
33
|
+
* The name a derived index gets when nothing named it: `Order__total_idx`, or `Order__total_uk` for a
|
|
34
|
+
* unique one - which the builder has always spelled apart, and which reads as what it enforces.
|
|
35
|
+
*/
|
|
36
|
+
export declare function derivedIndexName(table: string, columns: readonly string[], unique?: boolean): string;
|
|
37
|
+
/**
|
|
38
|
+
* The constraint name a primary key gets when we name one: `Enrolment__studentId_courseId_pk`.
|
|
39
|
+
*
|
|
40
|
+
* Only ever used to *emit* a key. Which columns a key holds is what decides whether two keys are the
|
|
41
|
+
* same, so an existing constraint keeps whatever the engine called it - see `SchemaDiff.primaryKey`.
|
|
25
42
|
*/
|
|
26
|
-
export declare function
|
|
27
|
-
/** The constraint name a check gets when nothing named it: `
|
|
43
|
+
export declare function derivedPrimaryKeyName(table: string, columns: readonly string[]): string;
|
|
44
|
+
/** The constraint name a check gets when nothing named it: `Order__1_ck`, by declaration order. */
|
|
28
45
|
export declare function derivedCheckName(table: string, position: number): string;
|
|
29
|
-
/** The constraint name a foreign key gets when nothing named it: `
|
|
46
|
+
/** The constraint name a foreign key gets when nothing named it: `Order__customerId_fk`. */
|
|
30
47
|
export declare function derivedForeignKeyName(table: string, columns: readonly string[]): string;
|
|
31
48
|
/**
|
|
32
49
|
* Escape a SQL identifier (table name, column name, etc.)
|
package/dist/util/sql.util.js
CHANGED
|
@@ -52,28 +52,93 @@ export function obtainAttrsPaths(row) {
|
|
|
52
52
|
* A name behind its namespace, or bare where there is none: the one place the two are joined, so a
|
|
53
53
|
* table's key, its statement operand and its escaped form cannot spell it differently. Never the
|
|
54
54
|
* seed for a derived identifier - an index or constraint name is a single identifier, and
|
|
55
|
-
* `
|
|
55
|
+
* `sales.Order_total_idx` is a syntax error.
|
|
56
56
|
*/
|
|
57
57
|
export function qualifyName(name, schema) {
|
|
58
58
|
return schema ? `${schema}.${name}` : name;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
* The
|
|
61
|
+
* The longest identifier every engine here accepts. Postgres truncates silently at 63 bytes and
|
|
62
|
+
* MySQL errors at 64, so one conservative limit needs no per-dialect plumbing to be safe on both -
|
|
63
|
+
* and SQLite, which has no limit, loses nothing by observing it.
|
|
64
|
+
*/
|
|
65
|
+
const MAX_IDENTIFIER_LENGTH = 63;
|
|
66
|
+
/** Hex chars of hash kept when a name has to be shortened. 24 bits over one table's constraints. */
|
|
67
|
+
const NAME_HASH_LENGTH = 6;
|
|
68
|
+
/**
|
|
69
|
+
* The name a derived index or constraint gets when nothing named it: `Order__total_idx`.
|
|
62
70
|
*
|
|
63
|
-
* One owner, because it is a rule two layers apply and a third has to match: the
|
|
64
|
-
* it, the DDL generator falls back to it, and a
|
|
71
|
+
* One owner for all four kinds, because it is a rule two layers apply and a third has to match: the
|
|
72
|
+
* entity AST derives it, the DDL generator falls back to it, and a `DROP` names what it drops.
|
|
65
73
|
* `table` is the table's own name, never qualified - the result is a single identifier.
|
|
74
|
+
*
|
|
75
|
+
* The kind goes last, as Postgres spells its own (`users_pkey`, `users_email_idx`), so a table's
|
|
76
|
+
* constraints sort together under the table they belong to.
|
|
77
|
+
*/
|
|
78
|
+
export function derivedConstraintName(table, parts, kind) {
|
|
79
|
+
const body = parts.length ? `${table}${TABLE_SEPARATOR}${parts.join('_')}` : table;
|
|
80
|
+
return clampIdentifier(`${body}_${kind}`);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* What separates the table from the columns, doubled where every other join is single.
|
|
84
|
+
*
|
|
85
|
+
* Postgres and SQLite keep index and constraint names in one flat namespace across the whole
|
|
86
|
+
* database rather than scoping them to a table, so a single underscore lets two tables collide:
|
|
87
|
+
* `user` + `profile_id` and `user_profile` + `id` both reduce to `user_profile_id_idx`. Doubling the
|
|
88
|
+
* one ambiguous boundary settles it, on the same assumption Drupal made for the same engines - that
|
|
89
|
+
* nothing sane carries `__` in a table or column name.
|
|
90
|
+
*/
|
|
91
|
+
const TABLE_SEPARATOR = '__';
|
|
92
|
+
/**
|
|
93
|
+
* A name the engine will store whole, shortened around a hash of the full one when it is too long.
|
|
94
|
+
*
|
|
95
|
+
* Truncating alone collides - two long names over the same table differ only in their tail - and a
|
|
96
|
+
* collision means one constraint silently replacing another. The hash is of the *whole* name, so it
|
|
97
|
+
* stays the same on every run, which is what lets a later migration still recognise what it made.
|
|
98
|
+
*/
|
|
99
|
+
function clampIdentifier(name) {
|
|
100
|
+
if (name.length <= MAX_IDENTIFIER_LENGTH) {
|
|
101
|
+
return name;
|
|
102
|
+
}
|
|
103
|
+
const suffix = `_${hashIdentifier(name)}`;
|
|
104
|
+
return name.slice(0, MAX_IDENTIFIER_LENGTH - suffix.length) + suffix;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* FNV-1a, by hand: the package ships zero runtime dependencies, and `node:crypto` is not reachable
|
|
108
|
+
* from the browser and edge entries this module is bundled into. Not a security hash - it only has
|
|
109
|
+
* to spread the names of one table's constraints.
|
|
110
|
+
*/
|
|
111
|
+
function hashIdentifier(value) {
|
|
112
|
+
let hash = 0x811c9dc5;
|
|
113
|
+
for (let i = 0; i < value.length; i++) {
|
|
114
|
+
hash ^= value.charCodeAt(i);
|
|
115
|
+
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
116
|
+
}
|
|
117
|
+
return hash.toString(16).padStart(NAME_HASH_LENGTH, '0').slice(-NAME_HASH_LENGTH);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The name a derived index gets when nothing named it: `Order__total_idx`, or `Order__total_uk` for a
|
|
121
|
+
* unique one - which the builder has always spelled apart, and which reads as what it enforces.
|
|
122
|
+
*/
|
|
123
|
+
export function derivedIndexName(table, columns, unique = false) {
|
|
124
|
+
return derivedConstraintName(table, columns, unique ? 'uk' : 'idx');
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The constraint name a primary key gets when we name one: `Enrolment__studentId_courseId_pk`.
|
|
128
|
+
*
|
|
129
|
+
* Only ever used to *emit* a key. Which columns a key holds is what decides whether two keys are the
|
|
130
|
+
* same, so an existing constraint keeps whatever the engine called it - see `SchemaDiff.primaryKey`.
|
|
66
131
|
*/
|
|
67
|
-
export function
|
|
68
|
-
return
|
|
132
|
+
export function derivedPrimaryKeyName(table, columns) {
|
|
133
|
+
return derivedConstraintName(table, columns, 'pk');
|
|
69
134
|
}
|
|
70
|
-
/** The constraint name a check gets when nothing named it: `
|
|
135
|
+
/** The constraint name a check gets when nothing named it: `Order__1_ck`, by declaration order. */
|
|
71
136
|
export function derivedCheckName(table, position) {
|
|
72
|
-
return
|
|
137
|
+
return derivedConstraintName(table, [position], 'ck');
|
|
73
138
|
}
|
|
74
|
-
/** The constraint name a foreign key gets when nothing named it: `
|
|
139
|
+
/** The constraint name a foreign key gets when nothing named it: `Order__customerId_fk`. */
|
|
75
140
|
export function derivedForeignKeyName(table, columns) {
|
|
76
|
-
return
|
|
141
|
+
return derivedConstraintName(table, columns, 'fk');
|
|
77
142
|
}
|
|
78
143
|
/**
|
|
79
144
|
* Escape a SQL identifier (table name, column name, etc.)
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"homepage": "https://uql-orm.dev",
|
|
4
4
|
"description": "JSON-native ORM for Node.js, Bun and Deno. Supports PostgreSQL, PGlite, MySQL, MariaDB, SQLite, CockroachDB, Turso, Neon, Cloudflare D1 and MongoDB. Queries are plain JSON, typed to the leaf.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.42.1",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=24"
|