uql-orm 0.25.0 → 0.25.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/migrate/bin.js
CHANGED
|
File without changes
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* - JSDoc comments for sync-added fields
|
|
11
11
|
*/
|
|
12
12
|
import { canonicalToTypeScript } from '../../schema/canonicalType.js';
|
|
13
|
+
import { DEFAULT_FOREIGN_KEY_ACTION, } from '../../schema/types.js';
|
|
13
14
|
import { camelCase, pascalCase, singularize } from '../../util/string.util.js';
|
|
14
15
|
import { buildFieldOptionsSource } from './fieldOptionsSource.js';
|
|
15
16
|
/**
|
|
@@ -234,8 +235,15 @@ export class EntityCodeGenerator {
|
|
|
234
235
|
}
|
|
235
236
|
lines.push(' */');
|
|
236
237
|
}
|
|
237
|
-
// Decorator
|
|
238
|
-
|
|
238
|
+
// Decorator. `onDelete`/`onUpdate` only when introspection found a real referential action, so a
|
|
239
|
+
// round-trip through an unconstrained column stays as terse as before.
|
|
240
|
+
const fkActions = [];
|
|
241
|
+
if (rel.onDelete && rel.onDelete !== DEFAULT_FOREIGN_KEY_ACTION)
|
|
242
|
+
fkActions.push(`onDelete: '${rel.onDelete}'`);
|
|
243
|
+
if (rel.onUpdate && rel.onUpdate !== DEFAULT_FOREIGN_KEY_ACTION)
|
|
244
|
+
fkActions.push(`onUpdate: '${rel.onUpdate}'`);
|
|
245
|
+
const fkActionsSource = fkActions.length ? `, ${fkActions.join(', ')}` : '';
|
|
246
|
+
lines.push(` @${decoratorName}({ entity: () => ${relatedClassName}${fkActionsSource} })`);
|
|
239
247
|
// Property
|
|
240
248
|
lines.push(` ${propertyName}?: ${relatedClassName};`);
|
|
241
249
|
return lines.join('\n');
|
|
@@ -181,9 +181,12 @@ export class SchemaASTBuilder {
|
|
|
181
181
|
type: relation.cardinality === 'm1' ? 'ManyToOne' : 'OneToOne',
|
|
182
182
|
from: { table, columns: [localColumn] },
|
|
183
183
|
to: { table: relatedTable, columns: [foreignColumn] },
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
onDelete: relation.onDelete ??
|
|
184
|
+
// Falls back to the FK column's own `onDelete`, which is what makes a bare `@Field({
|
|
185
|
+
// references, onDelete })` work with no relation declared at all.
|
|
186
|
+
onDelete: relation.onDelete ??
|
|
187
|
+
localField.onDelete ??
|
|
188
|
+
options.defaultForeignKeyAction ??
|
|
189
|
+
this.defaultForeignKeyAction,
|
|
187
190
|
onUpdate: relation.onUpdate ?? options.defaultForeignKeyAction ?? this.defaultForeignKeyAction,
|
|
188
191
|
confidence: 1.0,
|
|
189
192
|
inferredFrom: 'entity_decorator',
|
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/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.
|
|
6
|
+
"version": "0.25.1",
|
|
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.
|