@ptc-org/nestjs-query-core
Advanced tools
Comparing version
{ | ||
"name": "@ptc-org/nestjs-query-core", | ||
"version": "2.2.0-alpha.5", | ||
"version": "2.2.0", | ||
"description": "Base query package", | ||
@@ -5,0 +5,0 @@ "author": "doug-martin <doug@dougamartin.com>", |
import { Filterable } from './filterable.interface'; | ||
import { SelectRelations } from './select-relation.interface'; | ||
export interface FindByIdOptions<DTO> extends Filterable<DTO>, SelectRelations<DTO> { | ||
/** | ||
* Allow also deleted records to be retrieved | ||
*/ | ||
withDeleted?: boolean; | ||
import { WithDeleted } from './with-deleted.interface'; | ||
export interface FindByIdOptions<DTO> extends Filterable<DTO>, WithDeleted { | ||
} |
@@ -7,6 +7,2 @@ import { Filterable } from './filterable.interface'; | ||
withDeleted?: boolean; | ||
/** | ||
* Relation is looked ahead | ||
*/ | ||
lookedAhead?: boolean; | ||
} |
@@ -0,3 +1,5 @@ | ||
export * from './aggregate-options.interface'; | ||
export * from './aggregate-query.interface'; | ||
export * from './aggregate-response.interface'; | ||
export * from './count-options.interface'; | ||
export * from './delete-many-options.interface'; | ||
@@ -15,5 +17,6 @@ export * from './delete-many-response.interface'; | ||
export * from './query.inteface'; | ||
export * from './select-relation.interface'; | ||
export * from './query-options.interface'; | ||
export * from './sort-field.interface'; | ||
export * from './update-many-response.interface'; | ||
export * from './update-one-options.interface'; | ||
export * from './with-deleted.interface'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./aggregate-options.interface"), exports); | ||
tslib_1.__exportStar(require("./aggregate-query.interface"), exports); | ||
tslib_1.__exportStar(require("./aggregate-response.interface"), exports); | ||
tslib_1.__exportStar(require("./count-options.interface"), exports); | ||
tslib_1.__exportStar(require("./delete-many-options.interface"), exports); | ||
@@ -18,6 +20,7 @@ tslib_1.__exportStar(require("./delete-many-response.interface"), exports); | ||
tslib_1.__exportStar(require("./query.inteface"), exports); | ||
tslib_1.__exportStar(require("./select-relation.interface"), exports); | ||
tslib_1.__exportStar(require("./query-options.interface"), exports); | ||
tslib_1.__exportStar(require("./sort-field.interface"), exports); | ||
tslib_1.__exportStar(require("./update-many-response.interface"), exports); | ||
tslib_1.__exportStar(require("./update-one-options.interface"), exports); | ||
tslib_1.__exportStar(require("./with-deleted.interface"), exports); | ||
//# sourceMappingURL=index.js.map |
import { Filterable } from './filterable.interface'; | ||
import { Paging } from './paging.interface'; | ||
import { SelectRelation } from './select-relation.interface'; | ||
import { SortField } from './sort-field.interface'; | ||
@@ -29,3 +28,3 @@ /** | ||
*/ | ||
export interface Query<DTO> extends Filterable<DTO> { | ||
export interface Query<T> extends Filterable<T> { | ||
/** | ||
@@ -38,8 +37,3 @@ * Option to page through the collection. | ||
*/ | ||
sorting?: SortField<DTO>[]; | ||
/** | ||
* Select relations when doing the query. | ||
* @internal this implementation is not final and subjected to change! Use at own risk! | ||
*/ | ||
relations?: SelectRelation<DTO>[]; | ||
sorting?: SortField<T>[]; | ||
} |
import { Assembler } from '../assemblers'; | ||
import { Class, DeepPartial } from '../common'; | ||
import { AggregateQuery, AggregateResponse, DeleteManyResponse, DeleteOneOptions, Filter, FindByIdOptions, FindRelationOptions, GetByIdOptions, ModifyRelationOptions, Query, UpdateManyResponse, UpdateOneOptions } from '../interfaces'; | ||
import { AggregateOptions, AggregateQuery, AggregateResponse, CountOptions, DeleteManyResponse, DeleteOneOptions, Filter, FindByIdOptions, FindRelationOptions, GetByIdOptions, ModifyRelationOptions, Query, QueryOptions, UpdateManyResponse, UpdateOneOptions } from '../interfaces'; | ||
import { QueryService } from './query.service'; | ||
@@ -16,5 +16,5 @@ export declare class AssemblerQueryService<DTO, Entity, C = DeepPartial<DTO>, CE = DeepPartial<Entity>, U = C, UE = CE> implements QueryService<DTO, C, U> { | ||
getById(id: string | number, opts?: GetByIdOptions<DTO>): Promise<DTO>; | ||
query(query: Query<DTO>): Promise<DTO[]>; | ||
aggregate(filter: Filter<DTO>, aggregate: AggregateQuery<DTO>): Promise<AggregateResponse<DTO>[]>; | ||
count(filter: Filter<DTO>): Promise<number>; | ||
query(query: Query<DTO>, opts?: QueryOptions): Promise<DTO[]>; | ||
aggregate(filter: Filter<DTO>, aggregate: AggregateQuery<DTO>, opts?: AggregateOptions): Promise<AggregateResponse<DTO>[]>; | ||
count(filter: Filter<DTO>, opts?: CountOptions): Promise<number>; | ||
/** | ||
@@ -21,0 +21,0 @@ * Query for relations for an array of DTOs. This method will return a map with the DTO as the key and the relations as the value. |
@@ -38,11 +38,11 @@ "use strict"; | ||
} | ||
query(query) { | ||
return this.assembler.convertAsyncToDTOs(this.queryService.query(this.assembler.convertQuery(query))); | ||
query(query, opts) { | ||
return this.assembler.convertAsyncToDTOs(this.queryService.query(this.assembler.convertQuery(query), opts)); | ||
} | ||
async aggregate(filter, aggregate) { | ||
const aggregateResponse = await this.queryService.aggregate(this.assembler.convertQuery({ filter }).filter || {}, this.assembler.convertAggregateQuery(aggregate)); | ||
async aggregate(filter, aggregate, opts) { | ||
const aggregateResponse = await this.queryService.aggregate(this.assembler.convertQuery({ filter }).filter || {}, this.assembler.convertAggregateQuery(aggregate), opts); | ||
return aggregateResponse.map((agg) => this.assembler.convertAggregateResponse(agg)); | ||
} | ||
count(filter) { | ||
return this.queryService.count(this.assembler.convertQuery({ filter }).filter || {}); | ||
count(filter, opts) { | ||
return this.queryService.count(this.assembler.convertQuery({ filter }).filter || {}, opts); | ||
} | ||
@@ -49,0 +49,0 @@ async queryRelations(RelationClass, relationName, dto, query) { |
import { Class, DeepPartial } from '../common'; | ||
import { AggregateQuery, AggregateResponse, DeleteManyOptions, DeleteManyResponse, DeleteOneOptions, Filter, FindByIdOptions, FindRelationOptions, GetByIdOptions, ModifyRelationOptions, Query, UpdateManyResponse, UpdateOneOptions } from '../interfaces'; | ||
import { AggregateOptions, AggregateQuery, AggregateResponse, CountOptions, DeleteManyOptions, DeleteManyResponse, DeleteOneOptions, Filter, FindByIdOptions, FindRelationOptions, GetByIdOptions, ModifyRelationOptions, Query, QueryOptions, UpdateManyResponse, UpdateOneOptions } from '../interfaces'; | ||
import { QueryService } from './query.service'; | ||
@@ -17,5 +17,5 @@ export declare class NoOpQueryService<DTO, C = DeepPartial<DTO>, U = DeepPartial<DTO>> implements QueryService<DTO, C, U> { | ||
getById(id: string | number, opts?: GetByIdOptions<DTO>): Promise<DTO>; | ||
query(query: Query<DTO>): Promise<DTO[]>; | ||
aggregate(filter: Filter<DTO>, aggregate: AggregateQuery<DTO>): Promise<AggregateResponse<DTO>[]>; | ||
count(filter: Filter<DTO>): Promise<number>; | ||
query(query: Query<DTO>, opts?: QueryOptions): Promise<DTO[]>; | ||
aggregate(filter: Filter<DTO>, aggregate: AggregateQuery<DTO>, opts?: AggregateOptions): Promise<AggregateResponse<DTO>[]>; | ||
count(filter: Filter<DTO>, opts?: CountOptions): Promise<number>; | ||
queryRelations<Relation>(RelationClass: Class<Relation>, relationName: string, dto: DTO, query: Query<Relation>): Promise<Relation[]>; | ||
@@ -22,0 +22,0 @@ queryRelations<Relation>(RelationClass: Class<Relation>, relationName: string, dtos: DTO[], query: Query<Relation>): Promise<Map<DTO, Relation[]>>; |
@@ -37,9 +37,9 @@ "use strict"; | ||
} | ||
query(query) { | ||
query(query, opts) { | ||
return Promise.reject(new common_1.NotImplementedException('query is not implemented')); | ||
} | ||
aggregate(filter, aggregate) { | ||
aggregate(filter, aggregate, opts) { | ||
return Promise.reject(new common_1.NotImplementedException('aggregate is not implemented')); | ||
} | ||
count(filter) { | ||
count(filter, opts) { | ||
return Promise.reject(new common_1.NotImplementedException('count is not implemented')); | ||
@@ -46,0 +46,0 @@ } |
import { Class, DeepPartial } from '../common'; | ||
import { AggregateQuery, AggregateResponse, DeleteManyResponse, DeleteOneOptions, Filter, FindByIdOptions, FindRelationOptions, GetByIdOptions, ModifyRelationOptions, Query, UpdateManyResponse, UpdateOneOptions } from '../interfaces'; | ||
import { AggregateOptions, AggregateQuery, AggregateResponse, CountOptions, DeleteManyResponse, DeleteOneOptions, Filter, FindByIdOptions, FindRelationOptions, GetByIdOptions, ModifyRelationOptions, Query, QueryOptions, UpdateManyResponse, UpdateOneOptions } from '../interfaces'; | ||
import { QueryService } from './query.service'; | ||
@@ -52,5 +52,5 @@ export declare class ProxyQueryService<DTO, C = DeepPartial<DTO>, U = DeepPartial<DTO>> implements QueryService<DTO, C, U> { | ||
getById(id: string | number, opts?: GetByIdOptions<DTO>): Promise<DTO>; | ||
query(query: Query<DTO>): Promise<DTO[]>; | ||
aggregate(filter: Filter<DTO>, query: AggregateQuery<DTO>): Promise<AggregateResponse<DTO>[]>; | ||
count(filter: Filter<DTO>): Promise<number>; | ||
query(query: Query<DTO>, opts?: QueryOptions): Promise<DTO[]>; | ||
aggregate(filter: Filter<DTO>, query: AggregateQuery<DTO>, opts?: AggregateOptions): Promise<AggregateResponse<DTO>[]>; | ||
count(filter: Filter<DTO>, opts?: CountOptions): Promise<number>; | ||
updateMany(update: U, filter: Filter<DTO>): Promise<UpdateManyResponse>; | ||
@@ -57,0 +57,0 @@ updateOne(id: string | number, update: U, opts?: UpdateOneOptions<DTO>): Promise<DTO>; |
@@ -59,10 +59,10 @@ "use strict"; | ||
} | ||
query(query) { | ||
return this.proxied.query(query); | ||
query(query, opts) { | ||
return this.proxied.query(query, opts); | ||
} | ||
aggregate(filter, query) { | ||
return this.proxied.aggregate(filter, query); | ||
aggregate(filter, query, opts) { | ||
return this.proxied.aggregate(filter, query, opts); | ||
} | ||
count(filter) { | ||
return this.proxied.count(filter); | ||
count(filter, opts) { | ||
return this.proxied.count(filter, opts); | ||
} | ||
@@ -69,0 +69,0 @@ updateMany(update, filter) { |
import { Class, DeepPartial } from '../common'; | ||
import { AggregateQuery, AggregateResponse, DeleteManyOptions, DeleteManyResponse, DeleteOneOptions, Filter, FindByIdOptions, FindRelationOptions, GetByIdOptions, ModifyRelationOptions, Query, UpdateManyResponse, UpdateOneOptions } from '../interfaces'; | ||
import { AggregateOptions, AggregateQuery, AggregateResponse, CountOptions, DeleteManyOptions, DeleteManyResponse, DeleteOneOptions, Filter, FindByIdOptions, FindRelationOptions, GetByIdOptions, ModifyRelationOptions, Query, QueryOptions, UpdateManyResponse, UpdateOneOptions } from '../interfaces'; | ||
/** | ||
@@ -12,6 +12,5 @@ * Base interface for all QueryServices. | ||
* @param query - the query used to filer, page or sort records. | ||
* @param selectRelations - additional relation to select and fetch in the same query. | ||
* @returns a promise with an array of records that match the query. | ||
*/ | ||
query(query: Query<DTO>): Promise<DTO[]>; | ||
query(query: Query<DTO>, opts?: QueryOptions): Promise<DTO[]>; | ||
/** | ||
@@ -22,3 +21,3 @@ * Perform an aggregate query | ||
*/ | ||
aggregate(filter: Filter<DTO>, aggregate: AggregateQuery<DTO>): Promise<AggregateResponse<DTO>[]>; | ||
aggregate(filter: Filter<DTO>, aggregate: AggregateQuery<DTO>, opts?: AggregateOptions): Promise<AggregateResponse<DTO>[]>; | ||
/** | ||
@@ -29,3 +28,3 @@ * Count the number of records that match the filter. | ||
*/ | ||
count(filter: Filter<DTO>): Promise<number>; | ||
count(filter: Filter<DTO>, opts?: CountOptions): Promise<number>; | ||
/** | ||
@@ -32,0 +31,0 @@ * Finds a record by `id`. |
@@ -11,5 +11,7 @@ "use strict"; | ||
function QueryService(DTOClass) { | ||
return (cls) => (0, common_1.Injectable)()(cls); | ||
return (cls) => { | ||
return (0, common_1.Injectable)()(cls); | ||
}; | ||
} | ||
exports.QueryService = QueryService; | ||
//# sourceMappingURL=query.service.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
199028
0.85%179
5.29%2871
0.24%0
-100%