@mikro-orm/core 6.5.7-dev.2 → 6.5.7-dev.20
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.d.ts +1 -0
- package/EntityManager.js +9 -3
- package/entity/EntityValidator.js +1 -1
- package/hydration/ObjectHydrator.js +8 -1
- package/index.js +5 -1
- package/index.mjs +4 -0
- package/package.json +3 -3
- package/typings.d.ts +30 -22
- package/utils/TransactionManager.js +10 -1
package/EntityManager.d.ts
CHANGED
package/EntityManager.js
CHANGED
|
@@ -1186,8 +1186,11 @@ class EntityManager {
|
|
|
1186
1186
|
}
|
|
1187
1187
|
const em = options.disableContextResolution ? this : this.getContext();
|
|
1188
1188
|
options.schema ??= em._schema;
|
|
1189
|
+
options.validate ??= true;
|
|
1189
1190
|
entityName = utils_1.Utils.className(entityName);
|
|
1190
|
-
|
|
1191
|
+
if (options.validate) {
|
|
1192
|
+
em.validator.validatePrimaryKey(data, em.metadata.get(entityName));
|
|
1193
|
+
}
|
|
1191
1194
|
let entity = em.unitOfWork.tryGetById(entityName, data, options.schema, false);
|
|
1192
1195
|
if (entity && (0, entity_1.helper)(entity).__managed && (0, entity_1.helper)(entity).__initialized && !options.refresh) {
|
|
1193
1196
|
return entity;
|
|
@@ -1196,11 +1199,14 @@ class EntityManager {
|
|
|
1196
1199
|
const childMeta = em.metadata.getByDiscriminatorColumn(meta, data);
|
|
1197
1200
|
const dataIsEntity = utils_1.Utils.isEntity(data);
|
|
1198
1201
|
if (options.keepIdentity && entity && dataIsEntity && entity !== data) {
|
|
1199
|
-
|
|
1202
|
+
(0, entity_1.helper)(entity).__data = (0, entity_1.helper)(data).__data;
|
|
1203
|
+
(0, entity_1.helper)(entity).__originalEntityData = (0, entity_1.helper)(data).__originalEntityData;
|
|
1200
1204
|
return entity;
|
|
1201
1205
|
}
|
|
1202
1206
|
entity = dataIsEntity ? data : em.entityFactory.create(entityName, data, { merge: true, ...options });
|
|
1203
|
-
|
|
1207
|
+
if (options.validate) {
|
|
1208
|
+
em.validator.validate(entity, data, childMeta ?? meta);
|
|
1209
|
+
}
|
|
1204
1210
|
em.unitOfWork.merge(entity);
|
|
1205
1211
|
return entity;
|
|
1206
1212
|
}
|
|
@@ -14,7 +14,7 @@ class EntityValidator {
|
|
|
14
14
|
}
|
|
15
15
|
validate(entity, payload, meta) {
|
|
16
16
|
meta.props.forEach(prop => {
|
|
17
|
-
if (prop.inherited) {
|
|
17
|
+
if (prop.inherited || (prop.persist === false && prop.userDefined !== false)) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
if ([enums_1.ReferenceKind.ONE_TO_MANY, enums_1.ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {
|
|
@@ -73,7 +73,14 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
73
73
|
ret.push(` const oldValue_${idx} = entity${entityKey};`);
|
|
74
74
|
}
|
|
75
75
|
ret.push(` if (data${dataKey} === null) {`);
|
|
76
|
-
|
|
76
|
+
if (prop.ref) {
|
|
77
|
+
ret.push(` entity${entityKey} = new ScalarReference();`);
|
|
78
|
+
ret.push(` entity${entityKey}.bind(entity, '${prop.name}');`);
|
|
79
|
+
ret.push(` entity${entityKey}.set(${nullVal});`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
ret.push(` entity${entityKey} = ${nullVal};`);
|
|
83
|
+
}
|
|
77
84
|
ret.push(` } else if (typeof data${dataKey} !== 'undefined') {`);
|
|
78
85
|
if (prop.customType) {
|
|
79
86
|
registerCustomType(prop, convertorKey, 'convertToJSValue', context);
|
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Config = exports.HiddenProps = exports.EagerProps = exports.OptionalProps = exports.EntityRepositoryType = exports.EntityMetadata = exports.PrimaryKeyProp = void 0;
|
|
17
|
+
exports.RequiredNullable = exports.DefineConfig = exports.Config = exports.Hidden = exports.Opt = exports.HiddenProps = exports.EagerProps = exports.OptionalProps = exports.EntityRepositoryType = exports.EntityMetadata = exports.PrimaryKeyProp = void 0;
|
|
18
18
|
/**
|
|
19
19
|
* @packageDocumentation
|
|
20
20
|
* @module core
|
|
@@ -27,7 +27,11 @@ Object.defineProperty(exports, "EntityRepositoryType", { enumerable: true, get:
|
|
|
27
27
|
Object.defineProperty(exports, "OptionalProps", { enumerable: true, get: function () { return typings_1.OptionalProps; } });
|
|
28
28
|
Object.defineProperty(exports, "EagerProps", { enumerable: true, get: function () { return typings_1.EagerProps; } });
|
|
29
29
|
Object.defineProperty(exports, "HiddenProps", { enumerable: true, get: function () { return typings_1.HiddenProps; } });
|
|
30
|
+
Object.defineProperty(exports, "Opt", { enumerable: true, get: function () { return typings_1.Opt; } });
|
|
31
|
+
Object.defineProperty(exports, "Hidden", { enumerable: true, get: function () { return typings_1.Hidden; } });
|
|
30
32
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return typings_1.Config; } });
|
|
33
|
+
Object.defineProperty(exports, "DefineConfig", { enumerable: true, get: function () { return typings_1.DefineConfig; } });
|
|
34
|
+
Object.defineProperty(exports, "RequiredNullable", { enumerable: true, get: function () { return typings_1.RequiredNullable; } });
|
|
31
35
|
__exportStar(require("./enums"), exports);
|
|
32
36
|
__exportStar(require("./errors"), exports);
|
|
33
37
|
__exportStar(require("./exceptions"), exports);
|
package/index.mjs
CHANGED
|
@@ -50,6 +50,7 @@ export const DeadlockException = mod.DeadlockException;
|
|
|
50
50
|
export const DecimalType = mod.DecimalType;
|
|
51
51
|
export const DefaultLogger = mod.DefaultLogger;
|
|
52
52
|
export const DeferMode = mod.DeferMode;
|
|
53
|
+
export const DefineConfig = mod.DefineConfig;
|
|
53
54
|
export const DoubleType = mod.DoubleType;
|
|
54
55
|
export const DriverException = mod.DriverException;
|
|
55
56
|
export const EagerProps = mod.EagerProps;
|
|
@@ -90,6 +91,7 @@ export const ForeignKeyConstraintViolationException = mod.ForeignKeyConstraintVi
|
|
|
90
91
|
export const Formula = mod.Formula;
|
|
91
92
|
export const GeneratedCacheAdapter = mod.GeneratedCacheAdapter;
|
|
92
93
|
export const GroupOperator = mod.GroupOperator;
|
|
94
|
+
export const Hidden = mod.Hidden;
|
|
93
95
|
export const HiddenProps = mod.HiddenProps;
|
|
94
96
|
export const Hydrator = mod.Hydrator;
|
|
95
97
|
export const IdentityMap = mod.IdentityMap;
|
|
@@ -132,6 +134,7 @@ export const OneToManyOptionsBuilder = mod.OneToManyOptionsBuilder;
|
|
|
132
134
|
export const OneToManyOptionsBuilderOnlyMappedBy = mod.OneToManyOptionsBuilderOnlyMappedBy;
|
|
133
135
|
export const OneToOne = mod.OneToOne;
|
|
134
136
|
export const OneToOneOptionsBuilder = mod.OneToOneOptionsBuilder;
|
|
137
|
+
export const Opt = mod.Opt;
|
|
135
138
|
export const OptimisticLockError = mod.OptimisticLockError;
|
|
136
139
|
export const OptionalProps = mod.OptionalProps;
|
|
137
140
|
export const PlainObject = mod.PlainObject;
|
|
@@ -155,6 +158,7 @@ export const ReferenceKind = mod.ReferenceKind;
|
|
|
155
158
|
export const ReferenceOptionsBuilder = mod.ReferenceOptionsBuilder;
|
|
156
159
|
export const ReflectMetadataProvider = mod.ReflectMetadataProvider;
|
|
157
160
|
export const RequestContext = mod.RequestContext;
|
|
161
|
+
export const RequiredNullable = mod.RequiredNullable;
|
|
158
162
|
export const SCALAR_TYPES = mod.SCALAR_TYPES;
|
|
159
163
|
export const ScalarReference = mod.ScalarReference;
|
|
160
164
|
export const SerializationContext = mod.SerializationContext;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.5.7-dev.
|
|
3
|
+
"version": "6.5.7-dev.20",
|
|
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
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -60,11 +60,11 @@
|
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"dataloader": "2.2.3",
|
|
63
|
-
"dotenv": "17.2.
|
|
63
|
+
"dotenv": "17.2.3",
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.3.2",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.5.7-dev.
|
|
67
|
+
"mikro-orm": "6.5.7-dev.20",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/typings.d.ts
CHANGED
|
@@ -43,22 +43,34 @@ export declare const OptionalProps: unique symbol;
|
|
|
43
43
|
export declare const EagerProps: unique symbol;
|
|
44
44
|
export declare const HiddenProps: unique symbol;
|
|
45
45
|
export declare const Config: unique symbol;
|
|
46
|
-
|
|
47
|
-
declare
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
export type RequiredNullable<T = never> = (T &
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
46
|
+
export type Opt<T = unknown> = T & Opt.Brand;
|
|
47
|
+
export declare namespace Opt {
|
|
48
|
+
const __optional: unique symbol;
|
|
49
|
+
interface Brand {
|
|
50
|
+
[__optional]?: 1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export type RequiredNullable<T = never> = (T & RequiredNullable.Brand) | null;
|
|
54
|
+
export declare namespace RequiredNullable {
|
|
55
|
+
const __requiredNullable: unique symbol;
|
|
56
|
+
interface Brand {
|
|
57
|
+
[__requiredNullable]?: 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export type Hidden<T = unknown> = T & Hidden.Brand;
|
|
61
|
+
export declare namespace Hidden {
|
|
62
|
+
const __hidden: unique symbol;
|
|
63
|
+
interface Brand {
|
|
64
|
+
[__hidden]?: 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export type DefineConfig<T extends TypeConfig> = T & DefineConfig.Brand;
|
|
68
|
+
export declare namespace DefineConfig {
|
|
69
|
+
const __config: unique symbol;
|
|
70
|
+
interface Brand {
|
|
71
|
+
[__config]?: 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
62
74
|
export type CleanTypeConfig<T> = Compute<Pick<T, Extract<keyof T, keyof TypeConfig>>>;
|
|
63
75
|
export interface TypeConfig {
|
|
64
76
|
forceObject?: boolean;
|
|
@@ -220,9 +232,7 @@ export type EntityDataProp<T, C extends boolean> = T extends Date ? string | Dat
|
|
|
220
232
|
__runtime?: infer Runtime;
|
|
221
233
|
__raw?: infer Raw;
|
|
222
234
|
} ? (C extends true ? Raw : Runtime) : T extends Reference<infer U> ? EntityDataNested<U, C> : T extends ScalarReference<infer U> ? EntityDataProp<U, C> : T extends Collection<infer U, any> ? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[] : T extends readonly (infer U)[] ? U extends NonArrayObject ? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[] : U[] | EntityDataNested<U, C>[] : EntityDataNested<T, C>;
|
|
223
|
-
export type RequiredEntityDataProp<T, O, C extends boolean> = T extends Date ? string | Date : Exclude<T, null> extends {
|
|
224
|
-
[__requiredNullable]?: 1;
|
|
225
|
-
} ? T | null : T extends Scalar ? T : T extends {
|
|
235
|
+
export type RequiredEntityDataProp<T, O, C extends boolean> = T extends Date ? string | Date : Exclude<T, null> extends RequiredNullable.Brand ? T | null : T extends Scalar ? T : T extends {
|
|
226
236
|
__runtime?: infer Runtime;
|
|
227
237
|
__raw?: infer Raw;
|
|
228
238
|
} ? (C extends true ? Raw : Runtime) : T extends Reference<infer U> ? RequiredEntityDataNested<U, O, C> : T extends ScalarReference<infer U> ? RequiredEntityDataProp<U, O, C> : T extends Collection<infer U, any> ? U | U[] | RequiredEntityDataNested<U, O, C> | RequiredEntityDataNested<U, O, C>[] : T extends readonly (infer U)[] ? U extends NonArrayObject ? U | U[] | RequiredEntityDataNested<U, O, C> | RequiredEntityDataNested<U, O, C>[] : U[] | RequiredEntityDataNested<U, O, C>[] : RequiredEntityDataNested<T, O, C>;
|
|
@@ -238,9 +248,7 @@ type NullableKeys<T, V = null> = {
|
|
|
238
248
|
[K in keyof T]: V extends T[K] ? K : never;
|
|
239
249
|
}[keyof T];
|
|
240
250
|
type RequiredNullableKeys<T> = {
|
|
241
|
-
[K in keyof T]: Exclude<T[K], null> extends
|
|
242
|
-
[__requiredNullable]?: 1;
|
|
243
|
-
} ? K : never;
|
|
251
|
+
[K in keyof T]: Exclude<T[K], null> extends RequiredNullable.Brand ? K : never;
|
|
244
252
|
}[keyof T];
|
|
245
253
|
type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
|
|
246
254
|
type IsOptional<T, K extends keyof T, I> = T[K] extends Collection<any, any> ? true : ExtractType<T[K]> extends I ? true : K extends ProbablyOptionalProps<T> ? true : false;
|
|
@@ -6,6 +6,7 @@ const events_1 = require("../events");
|
|
|
6
6
|
const TransactionContext_1 = require("../utils/TransactionContext");
|
|
7
7
|
const unit_of_work_1 = require("../unit-of-work");
|
|
8
8
|
const errors_1 = require("../errors");
|
|
9
|
+
const wrap_1 = require("../entity/wrap");
|
|
9
10
|
/**
|
|
10
11
|
* Manages transaction lifecycle and propagation for EntityManager.
|
|
11
12
|
*/
|
|
@@ -152,8 +153,16 @@ class TransactionManager {
|
|
|
152
153
|
* Merges entities from fork to parent EntityManager.
|
|
153
154
|
*/
|
|
154
155
|
mergeEntitiesToParent(fork, parent) {
|
|
156
|
+
// perf: if parent is empty, we can just move all entities from the fork to skill the `em.merge` overhead
|
|
157
|
+
if (parent.getUnitOfWork(false).getIdentityMap().keys().length === 0) {
|
|
158
|
+
for (const entity of fork.getUnitOfWork(false).getIdentityMap()) {
|
|
159
|
+
parent.getUnitOfWork(false).getIdentityMap().store(entity);
|
|
160
|
+
(0, wrap_1.helper)(entity).__em = parent;
|
|
161
|
+
}
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
155
164
|
for (const entity of fork.getUnitOfWork(false).getIdentityMap()) {
|
|
156
|
-
parent.merge(entity, { disableContextResolution: true, keepIdentity: true, refresh: true });
|
|
165
|
+
parent.merge(entity, { disableContextResolution: true, keepIdentity: true, refresh: true, validate: false });
|
|
157
166
|
}
|
|
158
167
|
}
|
|
159
168
|
/**
|