@mikro-orm/core 7.1.0-dev.21 → 7.1.0-dev.23
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/EntityManager.js +0 -6
- package/entity/defineEntity.d.ts +8 -2
- package/entity/defineEntity.js +7 -0
- package/metadata/MetadataDiscovery.js +19 -1
- package/metadata/types.d.ts +6 -1
- package/package.json +1 -1
- package/serialization/EntitySerializer.js +2 -1
- package/typings.d.ts +2 -1
- package/unit-of-work/UnitOfWork.js +3 -0
- package/utils/Utils.js +1 -1
package/EntityManager.js
CHANGED
|
@@ -1179,9 +1179,6 @@ export class EntityManager {
|
|
|
1179
1179
|
helper(data).setSchema(options.schema);
|
|
1180
1180
|
}
|
|
1181
1181
|
if (!helper(data).__managed) {
|
|
1182
|
-
// the entity might have been created via `em.create()`, which adds it to the persist stack automatically
|
|
1183
|
-
em.#unitOfWork.getPersistStack().delete(data);
|
|
1184
|
-
// it can be also in the identity map if it had a PK value already
|
|
1185
1182
|
em.#unitOfWork.unsetIdentity(data);
|
|
1186
1183
|
}
|
|
1187
1184
|
const meta = helper(data).__meta;
|
|
@@ -1270,9 +1267,6 @@ export class EntityManager {
|
|
|
1270
1267
|
helper(row).setSchema(options.schema);
|
|
1271
1268
|
}
|
|
1272
1269
|
if (!helper(row).__managed) {
|
|
1273
|
-
// the entity might have been created via `em.create()`, which adds it to the persist stack automatically
|
|
1274
|
-
em.#unitOfWork.getPersistStack().delete(row);
|
|
1275
|
-
// it can be also in the identity map if it had a PK value already
|
|
1276
1270
|
em.#unitOfWork.unsetIdentity(row);
|
|
1277
1271
|
}
|
|
1278
1272
|
const payload = em.#comparator.prepareEntity(row);
|
package/entity/defineEntity.d.ts
CHANGED
|
@@ -117,7 +117,7 @@ export interface PropertyChain<Value, Options> {
|
|
|
117
117
|
groups(...groups: string[]): PropertyChain<Value, Options>;
|
|
118
118
|
customOrder(...customOrder: string[] | number[] | boolean[]): PropertyChain<Value, Options>;
|
|
119
119
|
extra(extra: string): PropertyChain<Value, Options>;
|
|
120
|
-
ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default')[]): PropertyChain<Value, Options>;
|
|
120
|
+
ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default' | 'collation')[]): PropertyChain<Value, Options>;
|
|
121
121
|
/** Explicitly specify index on a property. When a string name is passed, it enables type-safe `using` in `FindOptions`. */
|
|
122
122
|
index<N extends string>(name: N): PropertyChain<Value, Omit<Options, 'index'> & {
|
|
123
123
|
index: N;
|
|
@@ -129,6 +129,7 @@ export interface PropertyChain<Value, Options> {
|
|
|
129
129
|
}>;
|
|
130
130
|
unique(unique?: boolean): PropertyChain<Value, Options>;
|
|
131
131
|
comment(comment: string): PropertyChain<Value, Options>;
|
|
132
|
+
collation(collation: string): PropertyChain<Value, Options>;
|
|
132
133
|
accessor(accessor?: string | boolean): PropertyChain<Value, Options>;
|
|
133
134
|
eager(eager?: boolean): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
134
135
|
cascade(...cascade: Cascade[]): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
@@ -478,6 +479,11 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
478
479
|
* Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
479
480
|
*/
|
|
480
481
|
comment(comment: string): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
482
|
+
/**
|
|
483
|
+
* Specify column-level collation for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
484
|
+
* Emits a `COLLATE` clause on the column definition; the accepted collation names are dialect-specific.
|
|
485
|
+
*/
|
|
486
|
+
collation(collation: string): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
481
487
|
/** mysql only */
|
|
482
488
|
extra(extra: string): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
483
489
|
/**
|
|
@@ -485,7 +491,7 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
485
491
|
*
|
|
486
492
|
* @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
|
|
487
493
|
*/
|
|
488
|
-
ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default')[]): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
494
|
+
ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default' | 'collation')[]): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
489
495
|
array(): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'array'> & {
|
|
490
496
|
array: true;
|
|
491
497
|
}, IncludeKeys>, IncludeKeys>;
|
package/entity/defineEntity.js
CHANGED
|
@@ -316,6 +316,13 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
316
316
|
comment(comment) {
|
|
317
317
|
return this.assignOptions({ comment });
|
|
318
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* Specify column-level collation for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
321
|
+
* Emits a `COLLATE` clause on the column definition; the accepted collation names are dialect-specific.
|
|
322
|
+
*/
|
|
323
|
+
collation(collation) {
|
|
324
|
+
return this.assignOptions({ collation });
|
|
325
|
+
}
|
|
319
326
|
/** mysql only */
|
|
320
327
|
extra(extra) {
|
|
321
328
|
return this.assignOptions({ extra });
|
|
@@ -1268,7 +1268,10 @@ export class MetadataDiscovery {
|
|
|
1268
1268
|
if (!rootProp || rootProp.kind !== prop.kind) {
|
|
1269
1269
|
return false;
|
|
1270
1270
|
}
|
|
1271
|
-
if (prop.kind !== ReferenceKind.MANY_TO_ONE &&
|
|
1271
|
+
if (prop.kind !== ReferenceKind.MANY_TO_ONE &&
|
|
1272
|
+
prop.kind !== ReferenceKind.ONE_TO_ONE &&
|
|
1273
|
+
prop.kind !== ReferenceKind.ONE_TO_MANY &&
|
|
1274
|
+
prop.kind !== ReferenceKind.MANY_TO_MANY) {
|
|
1272
1275
|
return false;
|
|
1273
1276
|
}
|
|
1274
1277
|
const aRoot = this.#metadata.getByClassName(prop.type, false)?.root;
|
|
@@ -1324,7 +1327,14 @@ export class MetadataDiscovery {
|
|
|
1324
1327
|
// cleared implicitly when the first child claims the root property via
|
|
1325
1328
|
// addProperty below, so subsequent children correctly trigger renaming.
|
|
1326
1329
|
const typesMatch = rootProp?.type === prop.type || rootProp?.stiMerged === true || narrowedRelationOverride;
|
|
1330
|
+
// Inverse-side relations (1:m, inverse m:n) have no FK column on this
|
|
1331
|
+
// entity, so the rename branch — which exists to disambiguate physical
|
|
1332
|
+
// columns shared across STI children — doesn't apply. Skipping it also
|
|
1333
|
+
// avoids crashing on `[...rootProp.fieldNames]` since fieldNames is
|
|
1334
|
+
// never populated for inverse-side properties.
|
|
1335
|
+
const isInverseSideRelation = prop.kind === ReferenceKind.ONE_TO_MANY || (prop.kind === ReferenceKind.MANY_TO_MANY && !prop.owner);
|
|
1327
1336
|
if (rootProp &&
|
|
1337
|
+
!isInverseSideRelation &&
|
|
1328
1338
|
(!typesMatch ||
|
|
1329
1339
|
(rootProp.fieldNames && prop.fieldNames && !compareArrays(rootProp.fieldNames, prop.fieldNames)))) {
|
|
1330
1340
|
const name = newProp.name;
|
|
@@ -1379,6 +1389,14 @@ export class MetadataDiscovery {
|
|
|
1379
1389
|
if (narrowedRelationOverride) {
|
|
1380
1390
|
return;
|
|
1381
1391
|
}
|
|
1392
|
+
// STI siblings can declare the same property name on inverse-side relations
|
|
1393
|
+
// pointing to disjoint targets (e.g. `Dog.items → DogItem` and
|
|
1394
|
+
// `Cat.items → CatItem` with no shared base). There's no physical column
|
|
1395
|
+
// to manage at root, and propagating would clobber the first child's
|
|
1396
|
+
// declaration; each child keeps its local typed property instead.
|
|
1397
|
+
if (isInverseSideRelation && rootProp && rootProp.type !== prop.type) {
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1382
1400
|
meta.root.addProperty(newProp);
|
|
1383
1401
|
});
|
|
1384
1402
|
meta.tableName = meta.root.tableName;
|
package/metadata/types.d.ts
CHANGED
|
@@ -381,6 +381,11 @@ export interface PropertyOptions<Owner> {
|
|
|
381
381
|
* Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
382
382
|
*/
|
|
383
383
|
comment?: string;
|
|
384
|
+
/**
|
|
385
|
+
* Specify column-level collation for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
386
|
+
* Emits a `COLLATE` clause on the column definition; the accepted collation names are dialect-specific.
|
|
387
|
+
*/
|
|
388
|
+
collation?: string;
|
|
384
389
|
/** mysql only */
|
|
385
390
|
extra?: string;
|
|
386
391
|
/**
|
|
@@ -388,7 +393,7 @@ export interface PropertyOptions<Owner> {
|
|
|
388
393
|
*
|
|
389
394
|
* @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
|
|
390
395
|
*/
|
|
391
|
-
ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
|
|
396
|
+
ignoreSchemaChanges?: ('type' | 'extra' | 'default' | 'collation')[];
|
|
392
397
|
}
|
|
393
398
|
export interface ReferenceOptions<Owner, Target> extends PropertyOptions<Owner> {
|
|
394
399
|
/** Set target entity type. For polymorphic relations, pass an array of entity types. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.1.0-dev.
|
|
3
|
+
"version": "7.1.0-dev.23",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -16,7 +16,8 @@ function isVisible(meta, propName, options) {
|
|
|
16
16
|
if (Array.isArray(options.fields) && options.fields.length > 0 && !matchesPath(options.fields, propName)) {
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
|
-
if (Array.isArray(options.populate) &&
|
|
19
|
+
if (Array.isArray(options.populate) &&
|
|
20
|
+
options.populate.find(item => item === propName || item.startsWith(propName + '.'))) {
|
|
20
21
|
return true;
|
|
21
22
|
}
|
|
22
23
|
if (options.exclude?.find(item => item === propName)) {
|
package/typings.d.ts
CHANGED
|
@@ -809,11 +809,12 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
809
809
|
serializer?: (value: any, options?: SerializeOptions<any>) => any;
|
|
810
810
|
serializedName?: string;
|
|
811
811
|
comment?: string;
|
|
812
|
+
collation?: string;
|
|
812
813
|
/** mysql only */
|
|
813
814
|
extra?: string;
|
|
814
815
|
userDefined?: boolean;
|
|
815
816
|
optional?: boolean;
|
|
816
|
-
ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
|
|
817
|
+
ignoreSchemaChanges?: ('type' | 'extra' | 'default' | 'collation')[];
|
|
817
818
|
deferMode?: DeferMode;
|
|
818
819
|
createForeignKeyConstraint: boolean;
|
|
819
820
|
foreignKeyName?: string;
|
|
@@ -474,6 +474,9 @@ export class UnitOfWork {
|
|
|
474
474
|
}
|
|
475
475
|
unsetIdentity(entity) {
|
|
476
476
|
this.#identityMap.delete(entity);
|
|
477
|
+
this.#persistStack.delete(entity);
|
|
478
|
+
this.#removeStack.delete(entity);
|
|
479
|
+
this.#orphanRemoveStack.delete(entity);
|
|
477
480
|
const wrapped = helper(entity);
|
|
478
481
|
const serializedPK = wrapped.getSerializedPrimaryKey();
|
|
479
482
|
// remove references of this entity in all managed entities, otherwise flushing could reinsert the entity
|
package/utils/Utils.js
CHANGED
|
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
|
|
|
141
141
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
142
142
|
export class Utils {
|
|
143
143
|
static PK_SEPARATOR = '~~~';
|
|
144
|
-
static #ORM_VERSION = '7.1.0-dev.
|
|
144
|
+
static #ORM_VERSION = '7.1.0-dev.23';
|
|
145
145
|
/**
|
|
146
146
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
147
147
|
*/
|