@nest-boot/mikro-orm 7.7.7 → 8.0.0-beta.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/index.d.ts +7 -7
- package/dist/index.js +7 -25
- package/dist/index.js.map +1 -1
- package/dist/interfaces/id-entity.interface.d.ts +0 -2
- package/dist/interfaces/id-entity.interface.js +1 -2
- package/dist/interfaces/index.d.ts +2 -2
- package/dist/interfaces/index.js +2 -18
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/mikro-orm-module-options.interface.d.ts +0 -1
- package/dist/interfaces/mikro-orm-module-options.interface.js +1 -2
- package/dist/mikro-orm.module-definition.d.ts +8 -2
- package/dist/mikro-orm.module-definition.js +5 -8
- package/dist/mikro-orm.module-definition.js.map +1 -1
- package/dist/mikro-orm.module.d.ts +3 -39
- package/dist/mikro-orm.module.js +84 -90
- package/dist/mikro-orm.module.js.map +1 -1
- package/dist/property-types/index.d.ts +1 -1
- package/dist/property-types/index.js +1 -17
- package/dist/property-types/index.js.map +1 -1
- package/dist/property-types/vector.type.d.ts +0 -16
- package/dist/property-types/vector.type.js +3 -22
- package/dist/property-types/vector.type.js.map +1 -1
- package/dist/services/entity.service.d.ts +4 -73
- package/dist/services/entity.service.js +115 -198
- package/dist/services/entity.service.js.map +1 -1
- package/dist/types/chunk-by-id-options.type.d.ts +0 -1
- package/dist/types/chunk-by-id-options.type.js +1 -2
- package/dist/types/id-or-entity.type.d.ts +1 -2
- package/dist/types/id-or-entity.type.js +1 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +2 -18
- package/dist/types/index.js.map +1 -1
- package/dist/utils/load-config-from-env.util.d.ts +0 -29
- package/dist/utils/load-config-from-env.util.js +10 -62
- package/dist/utils/load-config-from-env.util.js.map +1 -1
- package/dist/utils/load-default-config.util.d.ts +0 -1
- package/dist/utils/load-default-config.util.js +5 -9
- package/dist/utils/load-default-config.util.js.map +1 -1
- package/package.json +48 -36
- package/dist/property-types/vector.type.spec.d.ts +0 -1
- package/dist/property-types/vector.type.spec.js +0 -34
- package/dist/property-types/vector.type.spec.js.map +0 -1
- package/dist/services/entity.service.spec.d.ts +0 -1
- package/dist/services/entity.service.spec.js +0 -327
- package/dist/services/entity.service.spec.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/utils/load-config-from-env.util.spec.d.ts +0 -1
- package/dist/utils/load-config-from-env.util.spec.js +0 -302
- package/dist/utils/load-config-from-env.util.spec.js.map +0 -1
|
@@ -1,92 +1,23 @@
|
|
|
1
|
-
import { type AssignOptions, CountOptions, type EntityData, type EntityDTO, EntityManager, type ExpandQuery, FilterQuery, FindOptions, type FromEntityType, type IsSubset, type Loaded, type PopulatePath } from "@mikro-orm/core";
|
|
2
|
-
import type { RequiredEntityData } from "@mikro-orm/core/typings";
|
|
1
|
+
import { type AssignOptions, CountOptions, type EntityData, type EntityDTO, EntityManager, type ExpandQuery, FilterQuery, FindOptions, type FromEntityType, type IsSubset, type Loaded, type PopulatePath, type RequiredEntityData } from "@mikro-orm/core";
|
|
3
2
|
import { Type } from "@nestjs/common";
|
|
4
|
-
import type { IdEntity } from "../interfaces/id-entity.interface";
|
|
5
|
-
import type { ChunkByIdOptions } from "../types/chunk-by-id-options.type";
|
|
6
|
-
import type { IdOrEntity } from "../types/id-or-entity.type";
|
|
7
|
-
/** Options for configuring an {@link EntityService} instance. */
|
|
3
|
+
import type { IdEntity } from "../interfaces/id-entity.interface.js";
|
|
4
|
+
import type { ChunkByIdOptions } from "../types/chunk-by-id-options.type.js";
|
|
5
|
+
import type { IdOrEntity } from "../types/id-or-entity.type.js";
|
|
8
6
|
export interface EntityServiceOptions<Entity extends IdEntity> {
|
|
9
|
-
/** Entity property key used for soft-delete timestamps (defaults to `"deletedAt"`). */
|
|
10
7
|
softDeleteKey?: keyof Entity;
|
|
11
8
|
}
|
|
12
|
-
/**
|
|
13
|
-
* Generic CRUD service for MikroORM entities with DataLoader batching.
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* Provides batched `create`, `findOne`, `update`, and `remove` operations
|
|
17
|
-
* via DataLoader for automatic N+1 prevention, plus standard `findAll`,
|
|
18
|
-
* `count`, and `chunkById` methods.
|
|
19
|
-
*
|
|
20
|
-
* @typeParam Entity - The entity type, which must have an `id` property
|
|
21
|
-
*/
|
|
22
9
|
export declare class EntityService<Entity extends IdEntity> {
|
|
23
10
|
#private;
|
|
24
11
|
protected readonly entityClass: Type<Entity>;
|
|
25
12
|
protected readonly em: EntityManager;
|
|
26
13
|
protected readonly options?: EntityServiceOptions<Entity> | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* Creates a new EntityService instance.
|
|
29
|
-
* @param entityClass - The entity class to manage
|
|
30
|
-
* @param em - MikroORM entity manager
|
|
31
|
-
* @param options - Optional service configuration (e.g. soft-delete key)
|
|
32
|
-
*/
|
|
33
14
|
constructor(entityClass: Type<Entity>, em: EntityManager, options?: EntityServiceOptions<Entity> | undefined);
|
|
34
|
-
/**
|
|
35
|
-
* Creates a new entity and persists it.
|
|
36
|
-
* @param data - The entity data to create
|
|
37
|
-
* @returns The created entity
|
|
38
|
-
*/
|
|
39
15
|
create(data: RequiredEntityData<Entity>): Promise<Entity>;
|
|
40
|
-
/**
|
|
41
|
-
* Finds a single entity by ID, entity reference, or filter query.
|
|
42
|
-
* @param idOrEntityOrWhere - The entity ID, entity instance, or filter query
|
|
43
|
-
* @returns The found entity or null
|
|
44
|
-
*/
|
|
45
16
|
findOne(idOrEntityOrWhere: IdOrEntity<Entity> | FilterQuery<NoInfer<Entity>>): Promise<Loaded<Entity> | null>;
|
|
46
|
-
/**
|
|
47
|
-
* Finds a single entity by ID, entity reference, or filter query, throwing if not found.
|
|
48
|
-
* @param idOrEntityOrWhere - The entity ID, entity instance, or filter query
|
|
49
|
-
* @returns The found entity
|
|
50
|
-
* @throws NotFoundException if the entity is not found
|
|
51
|
-
*/
|
|
52
17
|
findOneOrFail(idOrEntityOrWhere: IdOrEntity<Entity> | FilterQuery<Entity>): Promise<Loaded<Entity>>;
|
|
53
|
-
/**
|
|
54
|
-
* Finds all entities matching the given filter query.
|
|
55
|
-
* @param where - Filter query
|
|
56
|
-
* @param options - Find options (populate, limit, offset, etc.)
|
|
57
|
-
* @returns Array of matching entities
|
|
58
|
-
*/
|
|
59
18
|
findAll<Hint extends string = never, Fields extends string = PopulatePath.ALL, Excludes extends string = never>(where: FilterQuery<NoInfer<Entity>>, options?: FindOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes>[]>;
|
|
60
|
-
/**
|
|
61
|
-
* Counts entities matching the given filter query.
|
|
62
|
-
* @param where - Filter query
|
|
63
|
-
* @param options - Count options
|
|
64
|
-
* @returns The number of matching entities
|
|
65
|
-
*/
|
|
66
19
|
count<Hint extends string = never>(where: FilterQuery<NoInfer<Entity>>, options?: CountOptions<Entity, Hint>): Promise<number>;
|
|
67
|
-
/**
|
|
68
|
-
* Updates an entity by ID or reference.
|
|
69
|
-
* @param idOrEntity - The entity ID or entity instance to update
|
|
70
|
-
* @param data - The data to assign to the entity
|
|
71
|
-
* @param options - Optional assign options
|
|
72
|
-
* @returns The updated entity
|
|
73
|
-
* @throws NotFoundException if the entity is not found
|
|
74
|
-
*/
|
|
75
20
|
update<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(idOrEntity: IdOrEntity<Entity>, data: Data & IsSubset<EntityData<Naked, Convert>, Data>, options?: AssignOptions<Convert>): Promise<Entity>;
|
|
76
|
-
/**
|
|
77
|
-
* Removes an entity by ID or reference (supports soft-delete).
|
|
78
|
-
* @param idOrEntity - The entity ID or entity instance to remove
|
|
79
|
-
* @param softDelete - Whether to soft-delete (default: true)
|
|
80
|
-
* @returns The removed entity
|
|
81
|
-
* @throws NotFoundException if the entity is not found
|
|
82
|
-
*/
|
|
83
21
|
remove(idOrEntity: IdOrEntity<Entity>, softDelete?: boolean): Promise<Entity>;
|
|
84
|
-
/**
|
|
85
|
-
* Iterates over entities in chunks ordered by ID, useful for batch processing.
|
|
86
|
-
* @param where - Filter query
|
|
87
|
-
* @param options - Find options (limit determines chunk size)
|
|
88
|
-
* @param callback - Async callback invoked with each chunk of entities
|
|
89
|
-
* @returns This service instance for chaining
|
|
90
|
-
*/
|
|
91
22
|
chunkById<Hint extends string = never, Fields extends string = PopulatePath.ALL, Excludes extends string = never>(where: ExpandQuery<Entity>, options: ChunkByIdOptions<Entity, Hint, Fields, Excludes>, callback: (entities: Loaded<Entity, Hint, Fields, Excludes>[]) => Promise<void>): Promise<this>;
|
|
92
23
|
}
|
|
@@ -1,132 +1,155 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _EntityService_instances, _EntityService_dataLoadersByEntityManager, _EntityService_dataLoaders_get, _EntityService_createDataLoaders;
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.EntityService = void 0;
|
|
13
|
-
const core_1 = require("@mikro-orm/core");
|
|
14
|
-
const common_1 = require("@nestjs/common");
|
|
15
|
-
const dataloader_1 = __importDefault(require("dataloader"));
|
|
16
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
17
|
-
/**
|
|
18
|
-
* Generic CRUD service for MikroORM entities with DataLoader batching.
|
|
19
|
-
*
|
|
20
|
-
* @remarks
|
|
21
|
-
* Provides batched `create`, `findOne`, `update`, and `remove` operations
|
|
22
|
-
* via DataLoader for automatic N+1 prevention, plus standard `findAll`,
|
|
23
|
-
* `count`, and `chunkById` methods.
|
|
24
|
-
*
|
|
25
|
-
* @typeParam Entity - The entity type, which must have an `id` property
|
|
26
|
-
*/
|
|
27
|
-
class EntityService {
|
|
28
|
-
/**
|
|
29
|
-
* Creates a new EntityService instance.
|
|
30
|
-
* @param entityClass - The entity class to manage
|
|
31
|
-
* @param em - MikroORM entity manager
|
|
32
|
-
* @param options - Optional service configuration (e.g. soft-delete key)
|
|
33
|
-
*/
|
|
1
|
+
import { QueryOrder, } from "@mikro-orm/core";
|
|
2
|
+
import { NotFoundException } from "@nestjs/common";
|
|
3
|
+
import DataLoader from "dataloader";
|
|
4
|
+
import { capitalize, isPlainObject } from "lodash-es";
|
|
5
|
+
export class EntityService {
|
|
6
|
+
entityClass;
|
|
7
|
+
em;
|
|
8
|
+
options;
|
|
9
|
+
#dataLoadersByEntityManager = new WeakMap();
|
|
34
10
|
constructor(entityClass, em, options) {
|
|
35
|
-
_EntityService_instances.add(this);
|
|
36
11
|
this.entityClass = entityClass;
|
|
37
12
|
this.em = em;
|
|
38
13
|
this.options = options;
|
|
39
|
-
_EntityService_dataLoadersByEntityManager.set(this, new WeakMap());
|
|
40
14
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
15
|
+
get #dataLoaders() {
|
|
16
|
+
const em = this.em.getContext(false);
|
|
17
|
+
const existingDataLoaders = this.#dataLoadersByEntityManager.get(em);
|
|
18
|
+
if (existingDataLoaders) {
|
|
19
|
+
return existingDataLoaders;
|
|
20
|
+
}
|
|
21
|
+
const dataLoaders = this.#createDataLoaders(em);
|
|
22
|
+
this.#dataLoadersByEntityManager.set(em, dataLoaders);
|
|
23
|
+
return dataLoaders;
|
|
24
|
+
}
|
|
25
|
+
#createDataLoaders(em) {
|
|
26
|
+
const findOne = new DataLoader(async (items) => {
|
|
27
|
+
const uow = em.getUnitOfWork();
|
|
28
|
+
const ids = items.map(({ idOrEntity }) => typeof idOrEntity === "object" ? idOrEntity.id : idOrEntity);
|
|
29
|
+
const entitiesFromUow = [];
|
|
30
|
+
const idsToFetch = [];
|
|
31
|
+
for (const id of ids) {
|
|
32
|
+
const entity = uow.getById(this.entityClass, id);
|
|
33
|
+
if (entity) {
|
|
34
|
+
entitiesFromUow.push(entity);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
idsToFetch.push(id);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
let entitiesFromDb = [];
|
|
41
|
+
if (idsToFetch.length > 0) {
|
|
42
|
+
entitiesFromDb = await em.find(this.entityClass, {
|
|
43
|
+
id: { $in: idsToFetch },
|
|
44
|
+
}, { limit: idsToFetch.length });
|
|
45
|
+
}
|
|
46
|
+
const allEntities = [...entitiesFromUow, ...entitiesFromDb];
|
|
47
|
+
return ids.map((id) => {
|
|
48
|
+
return allEntities.find((entity) => entity.id === id) ?? null;
|
|
49
|
+
});
|
|
50
|
+
}, { cache: false });
|
|
51
|
+
const create = new DataLoader(async (data) => {
|
|
52
|
+
const entities = data.map((item) => {
|
|
53
|
+
return em.create(this.entityClass, item, {
|
|
54
|
+
persist: true,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
await em.flush();
|
|
58
|
+
return entities;
|
|
59
|
+
}, { cache: false });
|
|
60
|
+
const update = new DataLoader(async (items) => {
|
|
61
|
+
const entitiesOrErrors = (await Promise.all(items.map(({ idOrEntity }) => this.findOne(idOrEntity)))).map((entity) => {
|
|
62
|
+
if (entity === null) {
|
|
63
|
+
return new NotFoundException(`${this.entityClass.name.toLowerCase()}.not_found`);
|
|
64
|
+
}
|
|
65
|
+
return entity;
|
|
66
|
+
});
|
|
67
|
+
entitiesOrErrors.forEach((entityOrError, index) => {
|
|
68
|
+
if (entityOrError instanceof Error) {
|
|
69
|
+
return entityOrError;
|
|
70
|
+
}
|
|
71
|
+
const { data, options } = items[index];
|
|
72
|
+
const filteredData = Object.fromEntries(Object.entries(data).filter(([, value]) => value !== undefined));
|
|
73
|
+
em.assign(entityOrError, filteredData, options);
|
|
74
|
+
});
|
|
75
|
+
await em.flush();
|
|
76
|
+
return entitiesOrErrors;
|
|
77
|
+
}, { cache: false });
|
|
78
|
+
const remove = new DataLoader(async (items) => {
|
|
79
|
+
const entitiesOrErrors = (await Promise.all(items.map(({ idOrEntity }) => this.findOne(idOrEntity)))).map((entity) => {
|
|
80
|
+
if (entity === null) {
|
|
81
|
+
return new NotFoundException(`${this.entityClass.name.toLowerCase()}.not_found`);
|
|
82
|
+
}
|
|
83
|
+
return entity;
|
|
84
|
+
});
|
|
85
|
+
const removeHandler = async () => {
|
|
86
|
+
entitiesOrErrors.forEach((entityOrError, index) => {
|
|
87
|
+
if (entityOrError instanceof Error) {
|
|
88
|
+
return entityOrError;
|
|
89
|
+
}
|
|
90
|
+
const { softDelete } = items[index];
|
|
91
|
+
const softDeleteKey = this.options?.softDeleteKey ?? "deletedAt";
|
|
92
|
+
if (softDelete && softDeleteKey in entityOrError) {
|
|
93
|
+
entityOrError[softDeleteKey] = new Date();
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
em.remove(entityOrError);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
await em.flush();
|
|
100
|
+
return entitiesOrErrors;
|
|
101
|
+
};
|
|
102
|
+
if (em.isInTransaction()) {
|
|
103
|
+
return await removeHandler();
|
|
104
|
+
}
|
|
105
|
+
return await em.transactional(removeHandler);
|
|
106
|
+
}, { cache: false });
|
|
107
|
+
return {
|
|
108
|
+
create,
|
|
109
|
+
findOne,
|
|
110
|
+
remove,
|
|
111
|
+
update,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
46
114
|
create(data) {
|
|
47
|
-
return
|
|
115
|
+
return this.#dataLoaders.create.load(data);
|
|
48
116
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Finds a single entity by ID, entity reference, or filter query.
|
|
51
|
-
* @param idOrEntityOrWhere - The entity ID, entity instance, or filter query
|
|
52
|
-
* @returns The found entity or null
|
|
53
|
-
*/
|
|
54
117
|
async findOne(idOrEntityOrWhere) {
|
|
55
|
-
if (
|
|
118
|
+
if (isPlainObject(idOrEntityOrWhere)) {
|
|
56
119
|
return await this.em.findOne(this.entityClass, idOrEntityOrWhere);
|
|
57
120
|
}
|
|
58
121
|
else {
|
|
59
|
-
return (await
|
|
122
|
+
return (await this.#dataLoaders.findOne.load({
|
|
60
123
|
idOrEntity: idOrEntityOrWhere,
|
|
61
124
|
}));
|
|
62
125
|
}
|
|
63
126
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Finds a single entity by ID, entity reference, or filter query, throwing if not found.
|
|
66
|
-
* @param idOrEntityOrWhere - The entity ID, entity instance, or filter query
|
|
67
|
-
* @returns The found entity
|
|
68
|
-
* @throws NotFoundException if the entity is not found
|
|
69
|
-
*/
|
|
70
127
|
async findOneOrFail(idOrEntityOrWhere) {
|
|
71
128
|
const entity = await this.findOne(idOrEntityOrWhere);
|
|
72
129
|
if (entity === null) {
|
|
73
|
-
throw new
|
|
130
|
+
throw new NotFoundException(`${capitalize(this.entityClass.name)} not found`);
|
|
74
131
|
}
|
|
75
132
|
return entity;
|
|
76
133
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Finds all entities matching the given filter query.
|
|
79
|
-
* @param where - Filter query
|
|
80
|
-
* @param options - Find options (populate, limit, offset, etc.)
|
|
81
|
-
* @returns Array of matching entities
|
|
82
|
-
*/
|
|
83
134
|
async findAll(where, options) {
|
|
84
135
|
return await this.em.find(this.entityClass, where, options);
|
|
85
136
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Counts entities matching the given filter query.
|
|
88
|
-
* @param where - Filter query
|
|
89
|
-
* @param options - Count options
|
|
90
|
-
* @returns The number of matching entities
|
|
91
|
-
*/
|
|
92
137
|
async count(where, options) {
|
|
93
138
|
return await this.em.count(this.entityClass, where, options);
|
|
94
139
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Updates an entity by ID or reference.
|
|
97
|
-
* @param idOrEntity - The entity ID or entity instance to update
|
|
98
|
-
* @param data - The data to assign to the entity
|
|
99
|
-
* @param options - Optional assign options
|
|
100
|
-
* @returns The updated entity
|
|
101
|
-
* @throws NotFoundException if the entity is not found
|
|
102
|
-
*/
|
|
103
140
|
async update(idOrEntity, data, options) {
|
|
104
|
-
return await
|
|
141
|
+
return await this.#dataLoaders.update.load({
|
|
105
142
|
idOrEntity,
|
|
106
143
|
data,
|
|
107
144
|
options,
|
|
108
145
|
});
|
|
109
146
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Removes an entity by ID or reference (supports soft-delete).
|
|
112
|
-
* @param idOrEntity - The entity ID or entity instance to remove
|
|
113
|
-
* @param softDelete - Whether to soft-delete (default: true)
|
|
114
|
-
* @returns The removed entity
|
|
115
|
-
* @throws NotFoundException if the entity is not found
|
|
116
|
-
*/
|
|
117
147
|
async remove(idOrEntity, softDelete = true) {
|
|
118
|
-
return await
|
|
148
|
+
return await this.#dataLoaders.remove.load({
|
|
119
149
|
idOrEntity,
|
|
120
150
|
softDelete,
|
|
121
151
|
});
|
|
122
152
|
}
|
|
123
|
-
/**
|
|
124
|
-
* Iterates over entities in chunks ordered by ID, useful for batch processing.
|
|
125
|
-
* @param where - Filter query
|
|
126
|
-
* @param options - Find options (limit determines chunk size)
|
|
127
|
-
* @param callback - Async callback invoked with each chunk of entities
|
|
128
|
-
* @returns This service instance for chaining
|
|
129
|
-
*/
|
|
130
153
|
async chunkById(where, options, callback) {
|
|
131
154
|
let lastId;
|
|
132
155
|
let count = 0;
|
|
@@ -138,7 +161,7 @@ class EntityService {
|
|
|
138
161
|
],
|
|
139
162
|
}, {
|
|
140
163
|
...options,
|
|
141
|
-
orderBy: { id:
|
|
164
|
+
orderBy: { id: QueryOrder.ASC },
|
|
142
165
|
});
|
|
143
166
|
count = entities.length;
|
|
144
167
|
if (count > 0) {
|
|
@@ -152,110 +175,4 @@ class EntityService {
|
|
|
152
175
|
return this;
|
|
153
176
|
}
|
|
154
177
|
}
|
|
155
|
-
exports.EntityService = EntityService;
|
|
156
|
-
_EntityService_dataLoadersByEntityManager = new WeakMap(), _EntityService_instances = new WeakSet(), _EntityService_dataLoaders_get = function _EntityService_dataLoaders_get() {
|
|
157
|
-
const em = this.em.getContext(false);
|
|
158
|
-
const existingDataLoaders = __classPrivateFieldGet(this, _EntityService_dataLoadersByEntityManager, "f").get(em);
|
|
159
|
-
if (existingDataLoaders) {
|
|
160
|
-
return existingDataLoaders;
|
|
161
|
-
}
|
|
162
|
-
const dataLoaders = __classPrivateFieldGet(this, _EntityService_instances, "m", _EntityService_createDataLoaders).call(this, em);
|
|
163
|
-
__classPrivateFieldGet(this, _EntityService_dataLoadersByEntityManager, "f").set(em, dataLoaders);
|
|
164
|
-
return dataLoaders;
|
|
165
|
-
}, _EntityService_createDataLoaders = function _EntityService_createDataLoaders(em) {
|
|
166
|
-
const findOne = new dataloader_1.default(async (items) => {
|
|
167
|
-
const uow = em.getUnitOfWork();
|
|
168
|
-
// Get all IDs
|
|
169
|
-
const ids = items.map(({ idOrEntity }) => typeof idOrEntity === "object" ? idOrEntity.id : idOrEntity);
|
|
170
|
-
// First try to get already loaded entities from UnitOfWork
|
|
171
|
-
const entitiesFromUow = [];
|
|
172
|
-
const idsToFetch = [];
|
|
173
|
-
for (const id of ids) {
|
|
174
|
-
// Try to get entity from UnitOfWork's identity map
|
|
175
|
-
const entity = uow.getById(core_1.Utils.className(this.entityClass), id);
|
|
176
|
-
if (entity) {
|
|
177
|
-
entitiesFromUow.push(entity);
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
idsToFetch.push(id);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
// If there are IDs that need to be fetched from the database, execute the query
|
|
184
|
-
let entitiesFromDb = [];
|
|
185
|
-
if (idsToFetch.length > 0) {
|
|
186
|
-
entitiesFromDb = await em.find(this.entityClass, {
|
|
187
|
-
id: { $in: idsToFetch },
|
|
188
|
-
}, { limit: idsToFetch.length });
|
|
189
|
-
}
|
|
190
|
-
// Merge results from UnitOfWork and database query
|
|
191
|
-
const allEntities = [...entitiesFromUow, ...entitiesFromDb];
|
|
192
|
-
// Return results in the original order
|
|
193
|
-
return ids.map((id) => {
|
|
194
|
-
return allEntities.find((entity) => entity.id === id) ?? null;
|
|
195
|
-
});
|
|
196
|
-
}, { cache: false });
|
|
197
|
-
const create = new dataloader_1.default(async (data) => {
|
|
198
|
-
const entities = data.map((item) => {
|
|
199
|
-
return em.create(this.entityClass, item, {
|
|
200
|
-
persist: true,
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
await em.flush();
|
|
204
|
-
return entities;
|
|
205
|
-
}, { cache: false });
|
|
206
|
-
const update = new dataloader_1.default(async (items) => {
|
|
207
|
-
const entitiesOrErrors = (await Promise.all(items.map(({ idOrEntity }) => this.findOne(idOrEntity)))).map((entity) => {
|
|
208
|
-
if (entity === null) {
|
|
209
|
-
return new common_1.NotFoundException(`${this.entityClass.name.toLowerCase()}.not_found`);
|
|
210
|
-
}
|
|
211
|
-
return entity;
|
|
212
|
-
});
|
|
213
|
-
entitiesOrErrors.forEach((entityOrError, index) => {
|
|
214
|
-
if (entityOrError instanceof Error) {
|
|
215
|
-
return entityOrError;
|
|
216
|
-
}
|
|
217
|
-
const { data, options } = items[index];
|
|
218
|
-
// Filter out undefined values
|
|
219
|
-
const filteredData = Object.fromEntries(Object.entries(data).filter(([, value]) => value !== undefined));
|
|
220
|
-
em.assign(entityOrError, filteredData, options);
|
|
221
|
-
});
|
|
222
|
-
await em.flush();
|
|
223
|
-
return entitiesOrErrors;
|
|
224
|
-
}, { cache: false });
|
|
225
|
-
const remove = new dataloader_1.default(async (items) => {
|
|
226
|
-
const entitiesOrErrors = (await Promise.all(items.map(({ idOrEntity }) => this.findOne(idOrEntity)))).map((entity) => {
|
|
227
|
-
if (entity === null) {
|
|
228
|
-
return new common_1.NotFoundException(`${this.entityClass.name.toLowerCase()}.not_found`);
|
|
229
|
-
}
|
|
230
|
-
return entity;
|
|
231
|
-
});
|
|
232
|
-
const removeHandler = async () => {
|
|
233
|
-
entitiesOrErrors.forEach((entityOrError, index) => {
|
|
234
|
-
if (entityOrError instanceof Error) {
|
|
235
|
-
return entityOrError;
|
|
236
|
-
}
|
|
237
|
-
const { softDelete } = items[index];
|
|
238
|
-
const softDeleteKey = this.options?.softDeleteKey ?? "deletedAt";
|
|
239
|
-
if (softDelete && softDeleteKey in entityOrError) {
|
|
240
|
-
entityOrError[softDeleteKey] = new Date();
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
em.remove(entityOrError);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
await em.flush();
|
|
247
|
-
return entitiesOrErrors;
|
|
248
|
-
};
|
|
249
|
-
if (em.isInTransaction()) {
|
|
250
|
-
return await removeHandler();
|
|
251
|
-
}
|
|
252
|
-
return await em.transactional(removeHandler);
|
|
253
|
-
}, { cache: false });
|
|
254
|
-
return {
|
|
255
|
-
create,
|
|
256
|
-
findOne,
|
|
257
|
-
remove,
|
|
258
|
-
update,
|
|
259
|
-
};
|
|
260
|
-
};
|
|
261
178
|
//# sourceMappingURL=entity.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.service.js","sourceRoot":"","sources":["../../src/services/entity.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity.service.js","sourceRoot":"","sources":["../../src/services/entity.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAcL,UAAU,GAGX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAQ,MAAM,gBAAgB,CAAC;AACzD,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAmDtD,MAAM,OAAO,aAAa;IAaH;IACA;IACA;IAdZ,2BAA2B,GAAG,IAAI,OAAO,EAG/C,CAAC;IAQJ,YACqB,WAAyB,EACzB,EAAiB,EACjB,OAAsC;QAFtC,gBAAW,GAAX,WAAW,CAAc;QACzB,OAAE,GAAF,EAAE,CAAe;QACjB,YAAO,GAAP,OAAO,CAA+B;IACxD,CAAC;IAEJ,IAAI,YAAY;QACd,MAAM,EAAE,GAA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B,UAAU,GAAG,IAAI;QAEjB,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC;YACzC,UAAU;YACV,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IASD,KAAK,CAAC,SAAS,CAKb,KAA0B,EAC1B,OAAyD,EACzD,QAEkB;QAElB,IAAI,MAA4C,CAAC;QACjD,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,GAAG,CAAC;YACF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CACjC,IAAI,CAAC,WAAW,EAChB;gBACE,IAAI,EAAE;oBACJ,KAAK;oBACL,GAAG,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;iBACpE;aACgC,EACnC;gBACE,GAAG,OAAO;gBACV,OAAO,EAAE,EAAE,EAAE,EAAE,UAAU,CAAC,GAAG,EAAsC;aAC7D,CACT,CAAC;YAEF,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC;YAExB,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;gBACd,MAAM,GAAI,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAY,EAAE,EAAE,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACN,MAAM;YACR,CAAC;YAED,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC3B,CAAC,QAAQ,KAAK,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE;QAEzC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import type { FindOptions, PopulatePath } from "@mikro-orm/core";
|
|
2
|
-
/** Options for {@link EntityService.chunkById}, excluding offset and orderBy (managed internally). */
|
|
3
2
|
export type ChunkByIdOptions<Entity, Hint extends string = never, Fields extends string = PopulatePath.ALL, Excludes extends string = never> = Omit<FindOptions<Entity, Hint, Fields, Excludes>, "offset" | "orderBy">;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { IdEntity } from "../interfaces/id-entity.interface";
|
|
2
|
-
/** Accepts either an entity's ID value or the entity instance itself. */
|
|
1
|
+
import type { IdEntity } from "../interfaces/id-entity.interface.js";
|
|
3
2
|
export type IdOrEntity<Entity extends IdEntity> = Entity["id"] | Entity;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./chunk-by-id-options.type";
|
|
2
|
-
export * from "./id-or-entity.type";
|
|
1
|
+
export * from "./chunk-by-id-options.type.js";
|
|
2
|
+
export * from "./id-or-entity.type.js";
|
package/dist/types/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./chunk-by-id-options.type"), exports);
|
|
18
|
-
__exportStar(require("./id-or-entity.type"), exports);
|
|
1
|
+
export * from "./chunk-by-id-options.type.js";
|
|
2
|
+
export * from "./id-or-entity.type.js";
|
|
19
3
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC"}
|
|
@@ -1,47 +1,18 @@
|
|
|
1
1
|
import { Configuration, IDatabaseDriver, type Options } from "@mikro-orm/core";
|
|
2
|
-
/** Constructor type for a MikroORM database driver. */
|
|
3
2
|
export type DatabaseDriverConstructor = new (config: Configuration) => IDatabaseDriver;
|
|
4
|
-
/** Database driver configuration for MikroORM. */
|
|
5
3
|
export interface DriverConfig {
|
|
6
|
-
/** Database driver class constructor. */
|
|
7
4
|
driver?: DatabaseDriverConstructor;
|
|
8
5
|
}
|
|
9
|
-
/** URL-based database connection configuration for explicit module options. */
|
|
10
6
|
export interface UrlConfig {
|
|
11
|
-
/** Database connection URL. */
|
|
12
7
|
clientUrl?: string;
|
|
13
8
|
}
|
|
14
|
-
/** Host-based database connection configuration. */
|
|
15
9
|
export interface HostConfig {
|
|
16
|
-
/** Database host. */
|
|
17
10
|
host?: string;
|
|
18
|
-
/** Database port. */
|
|
19
11
|
port?: number;
|
|
20
|
-
/** Database name. */
|
|
21
12
|
dbName?: string;
|
|
22
|
-
/** Database user. */
|
|
23
13
|
user?: string;
|
|
24
|
-
/** Database password. */
|
|
25
14
|
password?: string;
|
|
26
|
-
/** Default database schema. */
|
|
27
15
|
schema?: string;
|
|
28
|
-
/** Driver connection options parsed from URL query parameters. */
|
|
29
16
|
driverOptions?: Options["driverOptions"];
|
|
30
17
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Loads MikroORM configuration from environment variables.
|
|
33
|
-
*
|
|
34
|
-
* @remarks
|
|
35
|
-
* Supports `DATABASE_URL`, which is parsed into individual connection options,
|
|
36
|
-
* including structured query options. The `postgresql:` and `postgres:`
|
|
37
|
-
* protocols select PostgreSQL, `mysql:` selects MySQL, and `file:` selects
|
|
38
|
-
* SQLite. Only the URL forms documented by those databases are accepted;
|
|
39
|
-
* other protocol names and driver-specific compatibility forms are rejected.
|
|
40
|
-
* PostgreSQL supports `sslmode=disable`, `require`, `verify-ca`, and
|
|
41
|
-
* `verify-full`; MySQL supports `ssl-mode=DISABLED`, `REQUIRED`, `VERIFY_CA`,
|
|
42
|
-
* and `VERIFY_IDENTITY`. Modes that require a plaintext fallback are rejected
|
|
43
|
-
* because one structured driver configuration cannot preserve that behavior.
|
|
44
|
-
*
|
|
45
|
-
* @returns MikroORM options derived from environment variables
|
|
46
|
-
*/
|
|
47
18
|
export declare function loadConfigFromEnv(): Promise<DriverConfig & HostConfig>;
|