nestjs-query-mikro-orm 0.1.3 → 0.1.5
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 +138 -103
- package/dist/index.cjs +425 -138
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -11
- package/dist/index.d.ts +47 -11
- package/dist/index.mjs +425 -138
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FilterQuery, EntityMetadata, EntityRepository, AnyEntity, EntityName } from '@mikro-orm/core';
|
|
2
2
|
import { DynamicModule, FactoryProvider } from '@nestjs/common';
|
|
3
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
|
-
declare class NestjsQueryMikroOrmModule {
|
|
6
|
-
static forFeature(entities: EntityName<AnyEntity>[], contextName?: string): DynamicModule;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
declare const createMikroOrmQueryServiceProviders: (entities: EntityName<AnyEntity>[], contextName?: string) => FactoryProvider[];
|
|
10
|
-
|
|
11
5
|
/**
|
|
12
6
|
* @internal
|
|
13
7
|
* Builds a WHERE clause from a Filter for MikroORM.
|
|
@@ -154,6 +148,11 @@ declare class ComparisonBuilder<Entity> {
|
|
|
154
148
|
private isBetweenVal;
|
|
155
149
|
}
|
|
156
150
|
|
|
151
|
+
type RelationLoadStrategy = 'select-in' | 'joined' | 'balanced';
|
|
152
|
+
interface RelationLoadOptions {
|
|
153
|
+
strategy?: RelationLoadStrategy;
|
|
154
|
+
useDataloader?: boolean;
|
|
155
|
+
}
|
|
157
156
|
type EntityIndexRelation<Relation> = Relation & {
|
|
158
157
|
__nestjsQuery__entityIndex__: number;
|
|
159
158
|
};
|
|
@@ -168,18 +167,32 @@ declare class RelationQueryBuilder<Entity extends object, Relation extends objec
|
|
|
168
167
|
readonly filterQueryBuilder: FilterQueryBuilder<Relation>;
|
|
169
168
|
constructor(repo: EntityRepository<Entity>, relation: string);
|
|
170
169
|
/**
|
|
171
|
-
* Executes a relation select using
|
|
170
|
+
* Executes a relation select using MikroORM native relation population first.
|
|
172
171
|
*/
|
|
173
|
-
selectAndExecute(entity: Entity, query: Query<Relation
|
|
172
|
+
selectAndExecute(entity: Entity, query: Query<Relation>, loadOptions?: RelationLoadOptions): Promise<Relation[]>;
|
|
173
|
+
batchSelectAndExecute(entities: Entity[], query: Query<Relation>, loadOptions?: RelationLoadOptions): Promise<Map<Entity, Relation[]>>;
|
|
174
|
+
populateEntityRelation(entity: Entity, useDataloader?: boolean, strategy?: RelationLoadStrategy): Promise<boolean>;
|
|
174
175
|
count(entity: Entity, query: Query<Relation>): Promise<number>;
|
|
175
176
|
aggregate(entity: Entity, query: Query<Relation>, aggregateQuery: AggregateQuery<Relation>): Promise<Record<string, unknown>[]>;
|
|
176
|
-
private buildWhereCondition;
|
|
177
177
|
private getRelationMeta;
|
|
178
178
|
get entityIndexColName(): string;
|
|
179
179
|
getRelationPrimaryKeysPropertyNameAndColumnsName(): {
|
|
180
180
|
columnName: string;
|
|
181
181
|
propertyName: string;
|
|
182
182
|
}[];
|
|
183
|
+
private getNativeLoadOptions;
|
|
184
|
+
private getNativePopulateOptions;
|
|
185
|
+
private tryBatchLoadRelationsNatively;
|
|
186
|
+
private tryLoadRelationsNatively;
|
|
187
|
+
private readLoadedRelation;
|
|
188
|
+
private applyPaging;
|
|
189
|
+
private applyPagingToMap;
|
|
190
|
+
private serializePrimaryKeyValue;
|
|
191
|
+
private hasFilterSortingOrPaging;
|
|
192
|
+
private hasFilterOrSorting;
|
|
193
|
+
private queryResolvedRelations;
|
|
194
|
+
private queryByOwnerCondition;
|
|
195
|
+
private buildWhereCondition;
|
|
183
196
|
}
|
|
184
197
|
|
|
185
198
|
declare enum AggregateFuncs {
|
|
@@ -220,15 +233,26 @@ declare class AggregateBuilder<Entity extends object> {
|
|
|
220
233
|
private createGroupBySelect;
|
|
221
234
|
}
|
|
222
235
|
|
|
236
|
+
type RelationLoadingStrategy = RelationLoadStrategy;
|
|
237
|
+
interface RelationLoadingOptions {
|
|
238
|
+
strategy?: RelationLoadingStrategy;
|
|
239
|
+
useDataloader?: boolean;
|
|
240
|
+
}
|
|
241
|
+
interface RelationQueryServiceOpts {
|
|
242
|
+
relationLoading?: RelationLoadingOptions;
|
|
243
|
+
}
|
|
223
244
|
/**
|
|
224
245
|
* Base class to house relations loading.
|
|
225
246
|
* @internal
|
|
226
247
|
*/
|
|
227
248
|
declare abstract class RelationQueryService<Entity extends object> {
|
|
249
|
+
protected readonly relationLoadingStrategy: RelationLoadingStrategy | undefined;
|
|
250
|
+
protected readonly nativeLoadUseDataloader: boolean;
|
|
228
251
|
abstract filterQueryBuilder: FilterQueryBuilder<Entity>;
|
|
229
252
|
abstract EntityClass: Class<Entity>;
|
|
230
253
|
abstract repo: EntityRepository<Entity>;
|
|
231
254
|
abstract getById(id: string | number, opts?: GetByIdOptions<Entity>): Promise<Entity>;
|
|
255
|
+
constructor(opts?: RelationQueryServiceOpts);
|
|
232
256
|
/**
|
|
233
257
|
* Query for an array of relations.
|
|
234
258
|
* @param RelationClass - The class to serialize the relations into.
|
|
@@ -343,6 +367,7 @@ declare abstract class RelationQueryService<Entity extends object> {
|
|
|
343
367
|
*/
|
|
344
368
|
private batchFindRelations;
|
|
345
369
|
private isRelationClassIdentity;
|
|
370
|
+
private getRelationLoadOptions;
|
|
346
371
|
private getRelationMeta;
|
|
347
372
|
private getRelationEntity;
|
|
348
373
|
private getRelations;
|
|
@@ -352,6 +377,7 @@ declare abstract class RelationQueryService<Entity extends object> {
|
|
|
352
377
|
interface MikroOrmQueryServiceOpts<Entity extends object> {
|
|
353
378
|
useSoftDelete?: boolean;
|
|
354
379
|
filterQueryBuilder?: FilterQueryBuilder<Entity>;
|
|
380
|
+
relationLoading?: RelationLoadingOptions;
|
|
355
381
|
}
|
|
356
382
|
/**
|
|
357
383
|
* Base class for all query services that use a MikroORM EntityRepository.
|
|
@@ -525,4 +551,14 @@ declare class MikroOrmQueryService<Entity extends object> extends RelationQueryS
|
|
|
525
551
|
private ensureSoftDeleteEnabled;
|
|
526
552
|
}
|
|
527
553
|
|
|
528
|
-
|
|
554
|
+
interface NestjsQueryMikroOrmFeatureOptions {
|
|
555
|
+
contextName?: string;
|
|
556
|
+
queryServiceOpts?: MikroOrmQueryServiceOpts<AnyEntity>;
|
|
557
|
+
}
|
|
558
|
+
declare class NestjsQueryMikroOrmModule {
|
|
559
|
+
static forFeature(entities: EntityName<AnyEntity>[], contextNameOrOptions?: string | NestjsQueryMikroOrmFeatureOptions): DynamicModule;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
declare const createMikroOrmQueryServiceProviders: (entities: EntityName<AnyEntity>[], contextName?: string, opts?: MikroOrmQueryServiceOpts<AnyEntity>) => FactoryProvider[];
|
|
563
|
+
|
|
564
|
+
export { AggregateBuilder, ComparisonBuilder, type EntityComparisonField, type EntityIndexRelation, FilterQueryBuilder, MikroOrmQueryService, type MikroOrmQueryServiceOpts, type NestedRecord, type NestjsQueryMikroOrmFeatureOptions, NestjsQueryMikroOrmModule, type RelationLoadOptions, type RelationLoadStrategy, type RelationLoadingOptions, type RelationLoadingStrategy, RelationQueryBuilder, RelationQueryService, type RelationQueryServiceOpts, WhereBuilder, createMikroOrmQueryServiceProviders };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FilterQuery, EntityMetadata, EntityRepository, AnyEntity, EntityName } from '@mikro-orm/core';
|
|
2
2
|
import { DynamicModule, FactoryProvider } from '@nestjs/common';
|
|
3
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
|
-
declare class NestjsQueryMikroOrmModule {
|
|
6
|
-
static forFeature(entities: EntityName<AnyEntity>[], contextName?: string): DynamicModule;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
declare const createMikroOrmQueryServiceProviders: (entities: EntityName<AnyEntity>[], contextName?: string) => FactoryProvider[];
|
|
10
|
-
|
|
11
5
|
/**
|
|
12
6
|
* @internal
|
|
13
7
|
* Builds a WHERE clause from a Filter for MikroORM.
|
|
@@ -154,6 +148,11 @@ declare class ComparisonBuilder<Entity> {
|
|
|
154
148
|
private isBetweenVal;
|
|
155
149
|
}
|
|
156
150
|
|
|
151
|
+
type RelationLoadStrategy = 'select-in' | 'joined' | 'balanced';
|
|
152
|
+
interface RelationLoadOptions {
|
|
153
|
+
strategy?: RelationLoadStrategy;
|
|
154
|
+
useDataloader?: boolean;
|
|
155
|
+
}
|
|
157
156
|
type EntityIndexRelation<Relation> = Relation & {
|
|
158
157
|
__nestjsQuery__entityIndex__: number;
|
|
159
158
|
};
|
|
@@ -168,18 +167,32 @@ declare class RelationQueryBuilder<Entity extends object, Relation extends objec
|
|
|
168
167
|
readonly filterQueryBuilder: FilterQueryBuilder<Relation>;
|
|
169
168
|
constructor(repo: EntityRepository<Entity>, relation: string);
|
|
170
169
|
/**
|
|
171
|
-
* Executes a relation select using
|
|
170
|
+
* Executes a relation select using MikroORM native relation population first.
|
|
172
171
|
*/
|
|
173
|
-
selectAndExecute(entity: Entity, query: Query<Relation
|
|
172
|
+
selectAndExecute(entity: Entity, query: Query<Relation>, loadOptions?: RelationLoadOptions): Promise<Relation[]>;
|
|
173
|
+
batchSelectAndExecute(entities: Entity[], query: Query<Relation>, loadOptions?: RelationLoadOptions): Promise<Map<Entity, Relation[]>>;
|
|
174
|
+
populateEntityRelation(entity: Entity, useDataloader?: boolean, strategy?: RelationLoadStrategy): Promise<boolean>;
|
|
174
175
|
count(entity: Entity, query: Query<Relation>): Promise<number>;
|
|
175
176
|
aggregate(entity: Entity, query: Query<Relation>, aggregateQuery: AggregateQuery<Relation>): Promise<Record<string, unknown>[]>;
|
|
176
|
-
private buildWhereCondition;
|
|
177
177
|
private getRelationMeta;
|
|
178
178
|
get entityIndexColName(): string;
|
|
179
179
|
getRelationPrimaryKeysPropertyNameAndColumnsName(): {
|
|
180
180
|
columnName: string;
|
|
181
181
|
propertyName: string;
|
|
182
182
|
}[];
|
|
183
|
+
private getNativeLoadOptions;
|
|
184
|
+
private getNativePopulateOptions;
|
|
185
|
+
private tryBatchLoadRelationsNatively;
|
|
186
|
+
private tryLoadRelationsNatively;
|
|
187
|
+
private readLoadedRelation;
|
|
188
|
+
private applyPaging;
|
|
189
|
+
private applyPagingToMap;
|
|
190
|
+
private serializePrimaryKeyValue;
|
|
191
|
+
private hasFilterSortingOrPaging;
|
|
192
|
+
private hasFilterOrSorting;
|
|
193
|
+
private queryResolvedRelations;
|
|
194
|
+
private queryByOwnerCondition;
|
|
195
|
+
private buildWhereCondition;
|
|
183
196
|
}
|
|
184
197
|
|
|
185
198
|
declare enum AggregateFuncs {
|
|
@@ -220,15 +233,26 @@ declare class AggregateBuilder<Entity extends object> {
|
|
|
220
233
|
private createGroupBySelect;
|
|
221
234
|
}
|
|
222
235
|
|
|
236
|
+
type RelationLoadingStrategy = RelationLoadStrategy;
|
|
237
|
+
interface RelationLoadingOptions {
|
|
238
|
+
strategy?: RelationLoadingStrategy;
|
|
239
|
+
useDataloader?: boolean;
|
|
240
|
+
}
|
|
241
|
+
interface RelationQueryServiceOpts {
|
|
242
|
+
relationLoading?: RelationLoadingOptions;
|
|
243
|
+
}
|
|
223
244
|
/**
|
|
224
245
|
* Base class to house relations loading.
|
|
225
246
|
* @internal
|
|
226
247
|
*/
|
|
227
248
|
declare abstract class RelationQueryService<Entity extends object> {
|
|
249
|
+
protected readonly relationLoadingStrategy: RelationLoadingStrategy | undefined;
|
|
250
|
+
protected readonly nativeLoadUseDataloader: boolean;
|
|
228
251
|
abstract filterQueryBuilder: FilterQueryBuilder<Entity>;
|
|
229
252
|
abstract EntityClass: Class<Entity>;
|
|
230
253
|
abstract repo: EntityRepository<Entity>;
|
|
231
254
|
abstract getById(id: string | number, opts?: GetByIdOptions<Entity>): Promise<Entity>;
|
|
255
|
+
constructor(opts?: RelationQueryServiceOpts);
|
|
232
256
|
/**
|
|
233
257
|
* Query for an array of relations.
|
|
234
258
|
* @param RelationClass - The class to serialize the relations into.
|
|
@@ -343,6 +367,7 @@ declare abstract class RelationQueryService<Entity extends object> {
|
|
|
343
367
|
*/
|
|
344
368
|
private batchFindRelations;
|
|
345
369
|
private isRelationClassIdentity;
|
|
370
|
+
private getRelationLoadOptions;
|
|
346
371
|
private getRelationMeta;
|
|
347
372
|
private getRelationEntity;
|
|
348
373
|
private getRelations;
|
|
@@ -352,6 +377,7 @@ declare abstract class RelationQueryService<Entity extends object> {
|
|
|
352
377
|
interface MikroOrmQueryServiceOpts<Entity extends object> {
|
|
353
378
|
useSoftDelete?: boolean;
|
|
354
379
|
filterQueryBuilder?: FilterQueryBuilder<Entity>;
|
|
380
|
+
relationLoading?: RelationLoadingOptions;
|
|
355
381
|
}
|
|
356
382
|
/**
|
|
357
383
|
* Base class for all query services that use a MikroORM EntityRepository.
|
|
@@ -525,4 +551,14 @@ declare class MikroOrmQueryService<Entity extends object> extends RelationQueryS
|
|
|
525
551
|
private ensureSoftDeleteEnabled;
|
|
526
552
|
}
|
|
527
553
|
|
|
528
|
-
|
|
554
|
+
interface NestjsQueryMikroOrmFeatureOptions {
|
|
555
|
+
contextName?: string;
|
|
556
|
+
queryServiceOpts?: MikroOrmQueryServiceOpts<AnyEntity>;
|
|
557
|
+
}
|
|
558
|
+
declare class NestjsQueryMikroOrmModule {
|
|
559
|
+
static forFeature(entities: EntityName<AnyEntity>[], contextNameOrOptions?: string | NestjsQueryMikroOrmFeatureOptions): DynamicModule;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
declare const createMikroOrmQueryServiceProviders: (entities: EntityName<AnyEntity>[], contextName?: string, opts?: MikroOrmQueryServiceOpts<AnyEntity>) => FactoryProvider[];
|
|
563
|
+
|
|
564
|
+
export { AggregateBuilder, ComparisonBuilder, type EntityComparisonField, type EntityIndexRelation, FilterQueryBuilder, MikroOrmQueryService, type MikroOrmQueryServiceOpts, type NestedRecord, type NestjsQueryMikroOrmFeatureOptions, NestjsQueryMikroOrmModule, type RelationLoadOptions, type RelationLoadStrategy, type RelationLoadingOptions, type RelationLoadingStrategy, RelationQueryBuilder, RelationQueryService, type RelationQueryServiceOpts, WhereBuilder, createMikroOrmQueryServiceProviders };
|