nestjs-query-mikro-orm 0.0.9 → 0.1.0
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/README.md +1 -1
- package/dist/index.cjs +61 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +39 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntityName, AnyEntity, FilterQuery, EntityMetadata, EntityRepository } from '@mikro-orm/core';
|
|
2
2
|
import { DynamicModule, FactoryProvider } from '@nestjs/common';
|
|
3
|
-
import { Filter, Query, SortField, FilterComparisonOperators, CommonFieldComparisonBetweenType, AggregateQuery, AggregateResponse, Class, GetByIdOptions, FindRelationOptions, ModifyRelationOptions, QueryService, DeepPartial, FindByIdOptions, UpdateOneOptions, UpdateManyResponse, DeleteOneOptions, DeleteManyResponse, Filterable } from '@nestjs-query
|
|
3
|
+
import { Filter, Query, SortField, FilterComparisonOperators, CommonFieldComparisonBetweenType, AggregateQuery, AggregateResponse, Class, GetByIdOptions, FindRelationOptions, ModifyRelationOptions, QueryService, DeepPartial, FindByIdOptions, UpdateOneOptions, UpdateManyResponse, DeleteOneOptions, DeleteManyResponse, Filterable } from '@ptc-org/nestjs-query-core';
|
|
4
4
|
|
|
5
5
|
declare class NestjsQueryMikroOrmModule {
|
|
6
6
|
static forFeature(entities: EntityName<AnyEntity>[], contextName?: string): DynamicModule;
|
|
@@ -375,7 +375,7 @@ declare class MikroOrmQueryService<Entity extends object> extends RelationQueryS
|
|
|
375
375
|
constructor(repo: EntityRepository<Entity>, opts?: MikroOrmQueryServiceOpts<Entity>);
|
|
376
376
|
get EntityClass(): Class<Entity>;
|
|
377
377
|
/**
|
|
378
|
-
* Query for multiple entities, using a Query from `@nestjs-query
|
|
378
|
+
* Query for multiple entities, using a Query from `@ptc-org/nestjs-query-core`.
|
|
379
379
|
*
|
|
380
380
|
* @example
|
|
381
381
|
* ```ts
|
|
@@ -450,7 +450,7 @@ declare class MikroOrmQueryService<Entity extends object> extends RelationQueryS
|
|
|
450
450
|
*/
|
|
451
451
|
updateOne(id: number | string, update: DeepPartial<Entity>, opts?: UpdateOneOptions<Entity>): Promise<Entity>;
|
|
452
452
|
/**
|
|
453
|
-
* Update multiple entities with a `@nestjs-query
|
|
453
|
+
* Update multiple entities with a `@ptc-org/nestjs-query-core` Filter.
|
|
454
454
|
*
|
|
455
455
|
* @example
|
|
456
456
|
* ```ts
|
|
@@ -477,7 +477,7 @@ declare class MikroOrmQueryService<Entity extends object> extends RelationQueryS
|
|
|
477
477
|
*/
|
|
478
478
|
deleteOne(id: string | number, opts?: DeleteOneOptions<Entity>): Promise<Entity>;
|
|
479
479
|
/**
|
|
480
|
-
* Delete multiple records with a `@nestjs-query
|
|
480
|
+
* Delete multiple records with a `@ptc-org/nestjs-query-core` `Filter`.
|
|
481
481
|
*
|
|
482
482
|
* @example
|
|
483
483
|
*
|
|
@@ -504,7 +504,7 @@ declare class MikroOrmQueryService<Entity extends object> extends RelationQueryS
|
|
|
504
504
|
*/
|
|
505
505
|
restoreOne(id: string | number, opts?: Filterable<Entity>): Promise<Entity>;
|
|
506
506
|
/**
|
|
507
|
-
* Restores multiple records with a `@nestjs-query
|
|
507
|
+
* Restores multiple records with a `@ptc-org/nestjs-query-core` `Filter`.
|
|
508
508
|
*
|
|
509
509
|
* @example
|
|
510
510
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntityName, AnyEntity, FilterQuery, EntityMetadata, EntityRepository } from '@mikro-orm/core';
|
|
2
2
|
import { DynamicModule, FactoryProvider } from '@nestjs/common';
|
|
3
|
-
import { Filter, Query, SortField, FilterComparisonOperators, CommonFieldComparisonBetweenType, AggregateQuery, AggregateResponse, Class, GetByIdOptions, FindRelationOptions, ModifyRelationOptions, QueryService, DeepPartial, FindByIdOptions, UpdateOneOptions, UpdateManyResponse, DeleteOneOptions, DeleteManyResponse, Filterable } from '@nestjs-query
|
|
3
|
+
import { Filter, Query, SortField, FilterComparisonOperators, CommonFieldComparisonBetweenType, AggregateQuery, AggregateResponse, Class, GetByIdOptions, FindRelationOptions, ModifyRelationOptions, QueryService, DeepPartial, FindByIdOptions, UpdateOneOptions, UpdateManyResponse, DeleteOneOptions, DeleteManyResponse, Filterable } from '@ptc-org/nestjs-query-core';
|
|
4
4
|
|
|
5
5
|
declare class NestjsQueryMikroOrmModule {
|
|
6
6
|
static forFeature(entities: EntityName<AnyEntity>[], contextName?: string): DynamicModule;
|
|
@@ -375,7 +375,7 @@ declare class MikroOrmQueryService<Entity extends object> extends RelationQueryS
|
|
|
375
375
|
constructor(repo: EntityRepository<Entity>, opts?: MikroOrmQueryServiceOpts<Entity>);
|
|
376
376
|
get EntityClass(): Class<Entity>;
|
|
377
377
|
/**
|
|
378
|
-
* Query for multiple entities, using a Query from `@nestjs-query
|
|
378
|
+
* Query for multiple entities, using a Query from `@ptc-org/nestjs-query-core`.
|
|
379
379
|
*
|
|
380
380
|
* @example
|
|
381
381
|
* ```ts
|
|
@@ -450,7 +450,7 @@ declare class MikroOrmQueryService<Entity extends object> extends RelationQueryS
|
|
|
450
450
|
*/
|
|
451
451
|
updateOne(id: number | string, update: DeepPartial<Entity>, opts?: UpdateOneOptions<Entity>): Promise<Entity>;
|
|
452
452
|
/**
|
|
453
|
-
* Update multiple entities with a `@nestjs-query
|
|
453
|
+
* Update multiple entities with a `@ptc-org/nestjs-query-core` Filter.
|
|
454
454
|
*
|
|
455
455
|
* @example
|
|
456
456
|
* ```ts
|
|
@@ -477,7 +477,7 @@ declare class MikroOrmQueryService<Entity extends object> extends RelationQueryS
|
|
|
477
477
|
*/
|
|
478
478
|
deleteOne(id: string | number, opts?: DeleteOneOptions<Entity>): Promise<Entity>;
|
|
479
479
|
/**
|
|
480
|
-
* Delete multiple records with a `@nestjs-query
|
|
480
|
+
* Delete multiple records with a `@ptc-org/nestjs-query-core` `Filter`.
|
|
481
481
|
*
|
|
482
482
|
* @example
|
|
483
483
|
*
|
|
@@ -504,7 +504,7 @@ declare class MikroOrmQueryService<Entity extends object> extends RelationQueryS
|
|
|
504
504
|
*/
|
|
505
505
|
restoreOne(id: string | number, opts?: Filterable<Entity>): Promise<Entity>;
|
|
506
506
|
/**
|
|
507
|
-
* Restores multiple records with a `@nestjs-query
|
|
507
|
+
* Restores multiple records with a `@ptc-org/nestjs-query-core` `Filter`.
|
|
508
508
|
*
|
|
509
509
|
* @example
|
|
510
510
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MikroOrmModule, getRepositoryToken } from '@mikro-orm/nestjs';
|
|
2
|
-
import { getFilterFields, AssemblerFactory, AssemblerSerializer, AssemblerDeserializer, getQueryServiceToken } from '@nestjs-query
|
|
2
|
+
import { getFilterFields, AssemblerFactory, AssemblerSerializer, AssemblerDeserializer, getQueryServiceToken } from '@ptc-org/nestjs-query-core';
|
|
3
3
|
import { raw, wrap } from '@mikro-orm/core';
|
|
4
|
-
import { getAssemblerSerializer } from '@nestjs-query
|
|
4
|
+
import { getAssemblerSerializer } from '@ptc-org/nestjs-query-core/src/assemblers/assembler.serializer';
|
|
5
5
|
import { BadRequestException, NotFoundException, MethodNotAllowedException } from '@nestjs/common';
|
|
6
6
|
import { instanceToPlain } from 'class-transformer';
|
|
7
7
|
import merge from 'lodash.merge';
|
|
@@ -964,7 +964,8 @@ var AggregateBuilder = class _AggregateBuilder {
|
|
|
964
964
|
});
|
|
965
965
|
const funcSelects = [];
|
|
966
966
|
aggs.forEach(([func, fields]) => {
|
|
967
|
-
|
|
967
|
+
if (!fields || fields.length === 0) return;
|
|
968
|
+
const aliases = fields.map((f) => {
|
|
968
969
|
const col = alias ? `\`${alias}\`.\`${String(f)}\`` : `\`${String(f)}\``;
|
|
969
970
|
return [
|
|
970
971
|
`${func}(${col})`,
|
|
@@ -1019,7 +1020,8 @@ var AggregateBuilder = class _AggregateBuilder {
|
|
|
1019
1020
|
]
|
|
1020
1021
|
];
|
|
1021
1022
|
return aggs.reduce((cols, [func, fields]) => {
|
|
1022
|
-
|
|
1023
|
+
if (!fields || fields.length === 0) return cols;
|
|
1024
|
+
const aliases = fields.map((f) => this.getAggregateAlias(func, f));
|
|
1023
1025
|
return [
|
|
1024
1026
|
...cols,
|
|
1025
1027
|
...aliases
|
|
@@ -1095,14 +1097,34 @@ var AggregateBuilder = class _AggregateBuilder {
|
|
|
1095
1097
|
*/
|
|
1096
1098
|
build(qb, aggregate, alias) {
|
|
1097
1099
|
const metadata = qb.mainAlias?.metadata;
|
|
1098
|
-
const selects = [
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1100
|
+
const selects = [];
|
|
1101
|
+
selects.push(...this.createGroupBySelect(aggregate.groupBy, alias, metadata));
|
|
1102
|
+
const aggs = [
|
|
1103
|
+
[
|
|
1104
|
+
"COUNT",
|
|
1105
|
+
aggregate.count
|
|
1106
|
+
],
|
|
1107
|
+
[
|
|
1108
|
+
"SUM",
|
|
1109
|
+
aggregate.sum
|
|
1110
|
+
],
|
|
1111
|
+
[
|
|
1112
|
+
"AVG",
|
|
1113
|
+
aggregate.avg
|
|
1114
|
+
],
|
|
1115
|
+
[
|
|
1116
|
+
"MAX",
|
|
1117
|
+
aggregate.max
|
|
1118
|
+
],
|
|
1119
|
+
[
|
|
1120
|
+
"MIN",
|
|
1121
|
+
aggregate.min
|
|
1122
|
+
]
|
|
1105
1123
|
];
|
|
1124
|
+
aggs.forEach(([func, fields]) => {
|
|
1125
|
+
if (!fields || fields.length === 0) return;
|
|
1126
|
+
selects.push(...this.createAggSelect(func, fields, alias, metadata));
|
|
1127
|
+
});
|
|
1106
1128
|
if (!selects.length) {
|
|
1107
1129
|
throw new BadRequestException("No aggregate fields found.");
|
|
1108
1130
|
}
|
|
@@ -1148,7 +1170,7 @@ var RelationQueryService = class {
|
|
|
1148
1170
|
}
|
|
1149
1171
|
const assembler = AssemblerFactory.getAssembler(RelationClass, this.getRelationEntity(relationName));
|
|
1150
1172
|
const relationQueryBuilder = this.getRelationQueryBuilder(relationName);
|
|
1151
|
-
return assembler.
|
|
1173
|
+
return assembler.convertToDTOs(await relationQueryBuilder.selectAndExecute(dto, assembler.convertQuery(query)));
|
|
1152
1174
|
}
|
|
1153
1175
|
async aggregateRelations(RelationClass, relationName, dto, filter, aggregate) {
|
|
1154
1176
|
if (Array.isArray(dto)) {
|
|
@@ -1334,7 +1356,7 @@ var RelationQueryService = class {
|
|
|
1334
1356
|
const results = /* @__PURE__ */ new Map();
|
|
1335
1357
|
await Promise.all(entities.map(async (entity) => {
|
|
1336
1358
|
const relations = await relationQueryBuilder.selectAndExecute(entity, convertedQuery);
|
|
1337
|
-
const relationDtos = assembler.convertToDTOs(relations);
|
|
1359
|
+
const relationDtos = await assembler.convertToDTOs(relations);
|
|
1338
1360
|
if (relationDtos.length > 0) {
|
|
1339
1361
|
results.set(entity, relationDtos);
|
|
1340
1362
|
}
|
|
@@ -1492,7 +1514,7 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1492
1514
|
return metadata.class;
|
|
1493
1515
|
}
|
|
1494
1516
|
/**
|
|
1495
|
-
* Query for multiple entities, using a Query from `@nestjs-query
|
|
1517
|
+
* Query for multiple entities, using a Query from `@ptc-org/nestjs-query-core`.
|
|
1496
1518
|
*
|
|
1497
1519
|
* @example
|
|
1498
1520
|
* ```ts
|
|
@@ -1778,7 +1800,7 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1778
1800
|
return entity;
|
|
1779
1801
|
}
|
|
1780
1802
|
/**
|
|
1781
|
-
* Update multiple entities with a `@nestjs-query
|
|
1803
|
+
* Update multiple entities with a `@ptc-org/nestjs-query-core` Filter.
|
|
1782
1804
|
*
|
|
1783
1805
|
* @example
|
|
1784
1806
|
* ```ts
|
|
@@ -1829,7 +1851,7 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1829
1851
|
return entity;
|
|
1830
1852
|
}
|
|
1831
1853
|
/**
|
|
1832
|
-
* Delete multiple records with a `@nestjs-query
|
|
1854
|
+
* Delete multiple records with a `@ptc-org/nestjs-query-core` `Filter`.
|
|
1833
1855
|
*
|
|
1834
1856
|
* @example
|
|
1835
1857
|
*
|
|
@@ -1905,7 +1927,7 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1905
1927
|
return entity;
|
|
1906
1928
|
}
|
|
1907
1929
|
/**
|
|
1908
|
-
* Restores multiple records with a `@nestjs-query
|
|
1930
|
+
* Restores multiple records with a `@ptc-org/nestjs-query-core` `Filter`.
|
|
1909
1931
|
*
|
|
1910
1932
|
* @example
|
|
1911
1933
|
*
|