@mikro-orm/core 6.4.6-dev.1 → 6.4.6-dev.2
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/connections/Connection.js +1 -0
- package/drivers/DatabaseDriver.d.ts +1 -0
- package/drivers/DatabaseDriver.js +3 -3
- package/drivers/IDatabaseDriver.d.ts +1 -0
- package/entity/EntityFactory.d.ts +1 -0
- package/entity/EntityFactory.js +6 -5
- package/hydration/Hydrator.d.ts +2 -2
- package/hydration/Hydrator.js +2 -2
- package/hydration/ObjectHydrator.d.ts +3 -3
- package/hydration/ObjectHydrator.js +4 -4
- package/package.json +2 -2
- package/typings.d.ts +2 -2
- package/unit-of-work/IdentityMap.d.ts +2 -0
- package/unit-of-work/IdentityMap.js +5 -1
- package/unit-of-work/UnitOfWork.js +3 -2
- package/utils/Configuration.d.ts +2 -0
- package/utils/Configuration.js +12 -0
|
@@ -360,7 +360,7 @@ class DatabaseDriver {
|
|
|
360
360
|
*/
|
|
361
361
|
getTableName(meta, options, quote = true) {
|
|
362
362
|
const schema = this.getSchemaName(meta, options);
|
|
363
|
-
const tableName = schema ? `${schema}.${meta.tableName}` : meta.tableName;
|
|
363
|
+
const tableName = schema && schema !== this.platform.getDefaultSchemaName() ? `${schema}.${meta.tableName}` : meta.tableName;
|
|
364
364
|
if (quote) {
|
|
365
365
|
return this.platform.quoteIdentifier(tableName);
|
|
366
366
|
}
|
|
@@ -376,8 +376,8 @@ class DatabaseDriver {
|
|
|
376
376
|
if (options?.schema === '*') {
|
|
377
377
|
return this.config.get('schema');
|
|
378
378
|
}
|
|
379
|
-
const schemaName = meta?.schema === '*' ? this.config.
|
|
380
|
-
return options?.schema ?? schemaName ?? this.config.
|
|
379
|
+
const schemaName = meta?.schema === '*' ? this.config.getSchema() : meta?.schema;
|
|
380
|
+
return options?.schema ?? options?.parentSchema ?? schemaName ?? this.config.getSchema();
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
exports.DatabaseDriver = DatabaseDriver;
|
|
@@ -58,6 +58,7 @@ export interface IDatabaseDriver<C extends Connection = Connection> {
|
|
|
58
58
|
*/
|
|
59
59
|
getSchemaName(meta?: EntityMetadata, options?: {
|
|
60
60
|
schema?: string;
|
|
61
|
+
parentSchema?: string;
|
|
61
62
|
}): string | undefined;
|
|
62
63
|
}
|
|
63
64
|
export type EntityField<T, P extends string = PopulatePath.ALL> = keyof T | PopulatePath.ALL | AutoPath<T, P, `${PopulatePath.ALL}`>;
|
package/entity/EntityFactory.js
CHANGED
|
@@ -192,6 +192,7 @@ class EntityFactory {
|
|
|
192
192
|
return this.comparator;
|
|
193
193
|
}
|
|
194
194
|
createEntity(data, meta, options) {
|
|
195
|
+
const schema = this.driver.getSchemaName(meta, options);
|
|
195
196
|
if (options.newEntity || meta.forceConstructor || meta.virtual) {
|
|
196
197
|
if (!meta.class) {
|
|
197
198
|
throw new Error(`Cannot create entity ${meta.className}, class prototype is unknown`);
|
|
@@ -210,7 +211,7 @@ class EntityFactory {
|
|
|
210
211
|
if (meta.virtual) {
|
|
211
212
|
return entity;
|
|
212
213
|
}
|
|
213
|
-
(0, wrap_1.helper)(entity).__schema =
|
|
214
|
+
(0, wrap_1.helper)(entity).__schema = schema;
|
|
214
215
|
if (options.initialized) {
|
|
215
216
|
EntityHelper_1.EntityHelper.ensurePropagation(entity);
|
|
216
217
|
}
|
|
@@ -220,9 +221,9 @@ class EntityFactory {
|
|
|
220
221
|
const entity = Object.create(meta.class.prototype);
|
|
221
222
|
(0, wrap_1.helper)(entity).__managed = true;
|
|
222
223
|
(0, wrap_1.helper)(entity).__processing = !meta.embeddable && !meta.virtual;
|
|
223
|
-
(0, wrap_1.helper)(entity).__schema =
|
|
224
|
+
(0, wrap_1.helper)(entity).__schema = schema;
|
|
224
225
|
if (options.merge && !options.newEntity) {
|
|
225
|
-
this.hydrator.hydrateReference(entity, meta, data, this, options.convertCustomTypes,
|
|
226
|
+
this.hydrator.hydrateReference(entity, meta, data, this, options.convertCustomTypes, options.schema, options.parentSchema);
|
|
226
227
|
this.unitOfWork.register(entity);
|
|
227
228
|
}
|
|
228
229
|
if (options.initialized) {
|
|
@@ -232,10 +233,10 @@ class EntityFactory {
|
|
|
232
233
|
}
|
|
233
234
|
hydrate(entity, meta, data, options) {
|
|
234
235
|
if (options.initialized) {
|
|
235
|
-
this.hydrator.hydrate(entity, meta, data, this, 'full', options.newEntity, options.convertCustomTypes, this.driver.getSchemaName(meta, options));
|
|
236
|
+
this.hydrator.hydrate(entity, meta, data, this, 'full', options.newEntity, options.convertCustomTypes, options.schema, this.driver.getSchemaName(meta, options));
|
|
236
237
|
}
|
|
237
238
|
else {
|
|
238
|
-
this.hydrator.hydrateReference(entity, meta, data, this, options.convertCustomTypes, this.driver.getSchemaName(meta, options));
|
|
239
|
+
this.hydrator.hydrateReference(entity, meta, data, this, options.convertCustomTypes, options.schema, this.driver.getSchemaName(meta, options));
|
|
239
240
|
}
|
|
240
241
|
Utils_1.Utils.keys(data).forEach(key => {
|
|
241
242
|
(0, wrap_1.helper)(entity)?.__loadedProperties.add(key);
|
package/hydration/Hydrator.d.ts
CHANGED
|
@@ -12,11 +12,11 @@ export declare abstract class Hydrator implements IHydrator {
|
|
|
12
12
|
/**
|
|
13
13
|
* @inheritDoc
|
|
14
14
|
*/
|
|
15
|
-
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string): void;
|
|
15
|
+
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
16
16
|
/**
|
|
17
17
|
* @inheritDoc
|
|
18
18
|
*/
|
|
19
|
-
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string): void;
|
|
19
|
+
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
20
20
|
isRunning(): boolean;
|
|
21
21
|
protected getProperties<T extends object>(meta: EntityMetadata<T>, type: 'full' | 'reference'): EntityProperty<T>[];
|
|
22
22
|
protected hydrateProperty<T extends object>(entity: T, prop: EntityProperty<T>, data: EntityData<T>, factory: EntityFactory, newEntity?: boolean, convertCustomTypes?: boolean): void;
|
package/hydration/Hydrator.js
CHANGED
|
@@ -15,7 +15,7 @@ class Hydrator {
|
|
|
15
15
|
/**
|
|
16
16
|
* @inheritDoc
|
|
17
17
|
*/
|
|
18
|
-
hydrate(entity, meta, data, factory, type, newEntity = false, convertCustomTypes = false, schema) {
|
|
18
|
+
hydrate(entity, meta, data, factory, type, newEntity = false, convertCustomTypes = false, schema, parentSchema) {
|
|
19
19
|
// the running state is used to consider propagation as hydration, saving the values directly to the entity data,
|
|
20
20
|
// but we don't want that for new entities, their propagation should result in entity updates when flushing
|
|
21
21
|
this.running = !newEntity;
|
|
@@ -28,7 +28,7 @@ class Hydrator {
|
|
|
28
28
|
/**
|
|
29
29
|
* @inheritDoc
|
|
30
30
|
*/
|
|
31
|
-
hydrateReference(entity, meta, data, factory, convertCustomTypes, schema) {
|
|
31
|
+
hydrateReference(entity, meta, data, factory, convertCustomTypes, schema, parentSchema) {
|
|
32
32
|
this.running = true;
|
|
33
33
|
meta.primaryKeys.forEach(pk => {
|
|
34
34
|
this.hydrateProperty(entity, meta.properties[pk], data, factory, false, convertCustomTypes);
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { EntityData, EntityMetadata } from '../typings';
|
|
2
2
|
import { Hydrator } from './Hydrator';
|
|
3
3
|
import type { EntityFactory } from '../entity/EntityFactory';
|
|
4
|
-
type EntityHydrator<T extends object> = (entity: T, data: EntityData<T>, factory: EntityFactory, newEntity: boolean, convertCustomTypes: boolean, schema?: string) => void;
|
|
4
|
+
type EntityHydrator<T extends object> = (entity: T, data: EntityData<T>, factory: EntityFactory, newEntity: boolean, convertCustomTypes: boolean, schema?: string, parentSchema?: string) => void;
|
|
5
5
|
export declare class ObjectHydrator extends Hydrator {
|
|
6
6
|
private readonly hydrators;
|
|
7
7
|
private tmpIndex;
|
|
8
8
|
/**
|
|
9
9
|
* @inheritDoc
|
|
10
10
|
*/
|
|
11
|
-
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string): void;
|
|
11
|
+
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
12
12
|
/**
|
|
13
13
|
* @inheritDoc
|
|
14
14
|
*/
|
|
15
|
-
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string): void;
|
|
15
|
+
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
16
16
|
/**
|
|
17
17
|
* @internal Highly performance-sensitive method.
|
|
18
18
|
*/
|
|
@@ -16,23 +16,23 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
16
16
|
/**
|
|
17
17
|
* @inheritDoc
|
|
18
18
|
*/
|
|
19
|
-
hydrate(entity, meta, data, factory, type, newEntity = false, convertCustomTypes = false, schema) {
|
|
19
|
+
hydrate(entity, meta, data, factory, type, newEntity = false, convertCustomTypes = false, schema, parentSchema) {
|
|
20
20
|
const hydrate = this.getEntityHydrator(meta, type);
|
|
21
21
|
const running = this.running;
|
|
22
22
|
// the running state is used to consider propagation as hydration, saving the values directly to the entity data,
|
|
23
23
|
// but we don't want that for new entities, their propagation should result in entity updates when flushing
|
|
24
24
|
this.running = !newEntity;
|
|
25
|
-
Utils_1.Utils.callCompiledFunction(hydrate, entity, data, factory, newEntity, convertCustomTypes, schema);
|
|
25
|
+
Utils_1.Utils.callCompiledFunction(hydrate, entity, data, factory, newEntity, convertCustomTypes, schema, parentSchema);
|
|
26
26
|
this.running = running;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* @inheritDoc
|
|
30
30
|
*/
|
|
31
|
-
hydrateReference(entity, meta, data, factory, convertCustomTypes = false, schema) {
|
|
31
|
+
hydrateReference(entity, meta, data, factory, convertCustomTypes = false, schema, parentSchema) {
|
|
32
32
|
const hydrate = this.getEntityHydrator(meta, 'reference');
|
|
33
33
|
const running = this.running;
|
|
34
34
|
this.running = true;
|
|
35
|
-
Utils_1.Utils.callCompiledFunction(hydrate, entity, data, factory, false, convertCustomTypes, schema);
|
|
35
|
+
Utils_1.Utils.callCompiledFunction(hydrate, entity, data, factory, false, convertCustomTypes, schema, parentSchema);
|
|
36
36
|
this.running = running;
|
|
37
37
|
}
|
|
38
38
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.4.6-dev.
|
|
3
|
+
"version": "6.4.6-dev.2",
|
|
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",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.3.0",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.4.6-dev.
|
|
67
|
+
"mikro-orm": "6.4.6-dev.2",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/typings.d.ts
CHANGED
|
@@ -777,11 +777,11 @@ export interface IHydrator {
|
|
|
777
777
|
* Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances,
|
|
778
778
|
* mapping FKs to entity instances, as well as merging those entities.
|
|
779
779
|
*/
|
|
780
|
-
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string): void;
|
|
780
|
+
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
781
781
|
/**
|
|
782
782
|
* Hydrates primary keys only
|
|
783
783
|
*/
|
|
784
|
-
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string): void;
|
|
784
|
+
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
785
785
|
isRunning(): boolean;
|
|
786
786
|
}
|
|
787
787
|
export interface HydratorConstructor {
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IdentityMap = void 0;
|
|
4
4
|
class IdentityMap {
|
|
5
|
+
defaultSchema;
|
|
6
|
+
constructor(defaultSchema) {
|
|
7
|
+
this.defaultSchema = defaultSchema;
|
|
8
|
+
}
|
|
5
9
|
registry = new Map();
|
|
6
10
|
store(item) {
|
|
7
11
|
this.getStore(item.__meta.root).set(this.getPkHash(item), item);
|
|
@@ -62,7 +66,7 @@ class IdentityMap {
|
|
|
62
66
|
const wrapped = item.__helper;
|
|
63
67
|
const meta = wrapped.__meta;
|
|
64
68
|
const hash = wrapped.getSerializedPrimaryKey();
|
|
65
|
-
const schema = wrapped.__schema
|
|
69
|
+
const schema = wrapped.__schema ?? meta.root.schema ?? this.defaultSchema;
|
|
66
70
|
if (schema) {
|
|
67
71
|
return schema + ':' + hash;
|
|
68
72
|
}
|
|
@@ -17,7 +17,7 @@ const insideFlush = new node_async_hooks_1.AsyncLocalStorage();
|
|
|
17
17
|
class UnitOfWork {
|
|
18
18
|
em;
|
|
19
19
|
/** map of references to managed entities */
|
|
20
|
-
identityMap
|
|
20
|
+
identityMap;
|
|
21
21
|
persistStack = new Set();
|
|
22
22
|
removeStack = new Set();
|
|
23
23
|
orphanRemoveStack = new Set();
|
|
@@ -38,6 +38,7 @@ class UnitOfWork {
|
|
|
38
38
|
this.em = em;
|
|
39
39
|
this.metadata = this.em.getMetadata();
|
|
40
40
|
this.platform = this.em.getPlatform();
|
|
41
|
+
this.identityMap = new IdentityMap_1.IdentityMap(this.platform.getDefaultSchemaName());
|
|
41
42
|
this.eventManager = this.em.getEventManager();
|
|
42
43
|
this.comparator = this.em.getComparator();
|
|
43
44
|
this.changeSetComputer = new ChangeSetComputer_1.ChangeSetComputer(this.em.getValidator(), this.collectionUpdates, this.metadata, this.platform, this.em.config, this.em);
|
|
@@ -136,7 +137,7 @@ class UnitOfWork {
|
|
|
136
137
|
const keys = Array.isArray(id) ? Utils_1.Utils.flatten(id) : [id];
|
|
137
138
|
hash = Utils_1.Utils.getPrimaryKeyHash(keys);
|
|
138
139
|
}
|
|
139
|
-
schema ??= meta.schema ?? this.em.config.
|
|
140
|
+
schema ??= meta.schema ?? this.em.config.getSchema();
|
|
140
141
|
if (schema) {
|
|
141
142
|
hash = `${schema}:${hash}`;
|
|
142
143
|
}
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -167,10 +167,12 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
|
|
|
167
167
|
* Gets Logger instance.
|
|
168
168
|
*/
|
|
169
169
|
getLogger(): Logger;
|
|
170
|
+
getPlatform(): Platform;
|
|
170
171
|
/**
|
|
171
172
|
* Gets current client URL (connection string).
|
|
172
173
|
*/
|
|
173
174
|
getClientUrl(hidePassword?: boolean): string;
|
|
175
|
+
getSchema(skipDefaultSchema?: boolean): string | undefined;
|
|
174
176
|
/**
|
|
175
177
|
* Gets current database driver instance.
|
|
176
178
|
*/
|
package/utils/Configuration.js
CHANGED
|
@@ -198,6 +198,9 @@ class Configuration {
|
|
|
198
198
|
getLogger() {
|
|
199
199
|
return this.logger;
|
|
200
200
|
}
|
|
201
|
+
getPlatform() {
|
|
202
|
+
return this.platform;
|
|
203
|
+
}
|
|
201
204
|
/**
|
|
202
205
|
* Gets current client URL (connection string).
|
|
203
206
|
*/
|
|
@@ -207,6 +210,12 @@ class Configuration {
|
|
|
207
210
|
}
|
|
208
211
|
return this.options.clientUrl;
|
|
209
212
|
}
|
|
213
|
+
getSchema(skipDefaultSchema = false) {
|
|
214
|
+
if (skipDefaultSchema && this.options.schema === this.platform.getDefaultSchemaName()) {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
return this.options.schema;
|
|
218
|
+
}
|
|
210
219
|
/**
|
|
211
220
|
* Gets current database driver instance.
|
|
212
221
|
*/
|
|
@@ -317,6 +326,9 @@ class Configuration {
|
|
|
317
326
|
if (validate && !this.options.dbName && this.options.clientUrl) {
|
|
318
327
|
throw new Error("No database specified, `clientUrl` option provided but it's missing the pathname.");
|
|
319
328
|
}
|
|
329
|
+
if (!this.options.schema) {
|
|
330
|
+
this.options.schema = this.platform.getDefaultSchemaName();
|
|
331
|
+
}
|
|
320
332
|
if (!this.options.charset) {
|
|
321
333
|
this.options.charset = this.platform.getDefaultCharset();
|
|
322
334
|
}
|