@ptc-org/nestjs-query-core
Advanced tools
Comparing version 5.0.0-alpha.0 to 5.0.0
{ | ||
"name": "@ptc-org/nestjs-query-core", | ||
"version": "5.0.0-alpha.0", | ||
"version": "5.0.0", | ||
"description": "Base query package", | ||
@@ -5,0 +5,0 @@ "author": "doug-martin <doug@dougamartin.com>", |
@@ -19,16 +19,12 @@ import { Class, DeepPartial } from '../common'; | ||
constructor(DTOClass?: Class<DTO>, EntityClass?: Class<Entity>); | ||
abstract convertToDTO(entity: Entity): DTO; | ||
abstract convertToEntity(dto: DTO): Entity; | ||
abstract convertToDTO(entity: Entity): Promise<DTO> | DTO; | ||
abstract convertToEntity(dto: DTO): Promise<Entity> | Entity; | ||
abstract convertQuery(query: Query<DTO>): Query<Entity>; | ||
abstract convertAggregateQuery(aggregate: AggregateQuery<DTO>): AggregateQuery<Entity>; | ||
abstract convertAggregateResponse(aggregate: AggregateResponse<Entity>): AggregateResponse<DTO>; | ||
abstract convertToCreateEntity(create: C): CE; | ||
abstract convertToUpdateEntity(update: U): UE; | ||
convertToDTOs(entities: Entity[]): DTO[]; | ||
convertToEntities(dtos: DTO[]): Entity[]; | ||
convertToCreateEntities(createDtos: C[]): CE[]; | ||
convertAsyncToDTO(entity: Promise<Entity>): Promise<DTO>; | ||
convertAsyncToDTOs(entities: Promise<Entity[]>): Promise<DTO[]>; | ||
convertAsyncToEntity(dto: Promise<DTO>): Promise<Entity>; | ||
convertAsyncToEntities(dtos: Promise<DTO[]>): Promise<Entity[]>; | ||
abstract convertToCreateEntity(create: C): Promise<CE> | CE; | ||
abstract convertToUpdateEntity(update: U): Promise<UE> | UE; | ||
convertToDTOs(entities: Entity[]): Promise<DTO[]>; | ||
convertToEntities(dtos: DTO[]): Promise<Entity[]>; | ||
convertToCreateEntities(createDtos: C[]): Promise<CE[]>; | ||
} |
@@ -29,28 +29,12 @@ "use strict"; | ||
convertToDTOs(entities) { | ||
return entities.map((e) => this.convertToDTO(e)); | ||
return Promise.all(entities.map((e) => this.convertToDTO(e))); | ||
} | ||
convertToEntities(dtos) { | ||
return dtos.map((dto) => this.convertToEntity(dto)); | ||
return Promise.all(dtos.map((dto) => this.convertToEntity(dto))); | ||
} | ||
convertToCreateEntities(createDtos) { | ||
return createDtos.map((c) => this.convertToCreateEntity(c)); | ||
return Promise.all(createDtos.map((c) => this.convertToCreateEntity(c))); | ||
} | ||
async convertAsyncToDTO(entity) { | ||
const e = await entity; | ||
return this.convertToDTO(e); | ||
} | ||
async convertAsyncToDTOs(entities) { | ||
const es = await entities; | ||
return this.convertToDTOs(es); | ||
} | ||
async convertAsyncToEntity(dto) { | ||
const d = await dto; | ||
return this.convertToEntity(d); | ||
} | ||
async convertAsyncToEntities(dtos) { | ||
const ds = await dtos; | ||
return this.convertToEntities(ds); | ||
} | ||
} | ||
exports.AbstractAssembler = AbstractAssembler; | ||
//# sourceMappingURL=abstract.assembler.js.map |
@@ -8,3 +8,3 @@ import { Class, DeepPartial, MetaValue } from '../common'; | ||
*/ | ||
convertToDTO(entity: Entity): DTO; | ||
convertToDTO(entity: Entity): Promise<DTO> | DTO; | ||
/** | ||
@@ -14,3 +14,3 @@ * Convert a DTO to an entity. | ||
*/ | ||
convertToEntity(dto: DTO): Entity; | ||
convertToEntity(dto: DTO): Promise<Entity> | Entity; | ||
/** | ||
@@ -35,3 +35,3 @@ * Convert a DTO query to an entity query. | ||
*/ | ||
convertToCreateEntity(createDTO: CreateDTO): CreateEntity; | ||
convertToCreateEntity(createDTO: CreateDTO): Promise<CreateEntity> | CreateEntity; | ||
/** | ||
@@ -41,3 +41,3 @@ * Convert a update dto input to the equivalent update entity type | ||
*/ | ||
convertToUpdateEntity(createDTO: UpdateDTO): UpdateEntity; | ||
convertToUpdateEntity(createDTO: UpdateDTO): Promise<UpdateEntity> | UpdateEntity; | ||
/** | ||
@@ -47,3 +47,3 @@ * Convert an array of entities to a an of DTOs | ||
*/ | ||
convertToDTOs(entities: Entity[]): DTO[]; | ||
convertToDTOs(entities: Entity[]): Promise<DTO[]>; | ||
/** | ||
@@ -53,28 +53,8 @@ * Convert an array of DTOs to an array of entities. | ||
*/ | ||
convertToEntities(dtos: DTO[]): Entity[]; | ||
convertToEntities(dtos: DTO[]): Promise<Entity[]>; | ||
/** | ||
* Convert an entity to a DTO. | ||
* @param entity - the promise that should resolve with the entity. | ||
*/ | ||
convertAsyncToDTO(entity: Promise<Entity>): Promise<DTO>; | ||
/** | ||
* Convert an array of entities to an array of DTOs. | ||
* @param entities - the promise that should resolve with the entity array. | ||
*/ | ||
convertAsyncToDTOs(entities: Promise<Entity[]>): Promise<DTO[]>; | ||
/** | ||
* Convert a DTO to an entity. | ||
* @param dto - the promise that should resolve with the DTO. | ||
*/ | ||
convertAsyncToEntity(dto: Promise<DTO>): Promise<Entity>; | ||
/** | ||
* Convert an array of DTOs to an array of entities. | ||
* @param dtos - the promise that should resolve with the dtos. | ||
*/ | ||
convertAsyncToEntities(dtos: Promise<DTO[]>): Promise<Entity[]>; | ||
/** | ||
* Convert an array of create DTOs to an array of create entities | ||
* @param createDtos | ||
*/ | ||
convertToCreateEntities(createDtos: CreateDTO[]): CreateEntity[]; | ||
convertToCreateEntities(createDtos: CreateDTO[]): Promise<CreateEntity[]>; | ||
} | ||
@@ -81,0 +61,0 @@ export interface AssemblerClasses<DTO, Entity> { |
@@ -9,13 +9,13 @@ "use strict"; | ||
} | ||
addRelations(relationName, id, relationIds, opts) { | ||
return this.assembler.convertAsyncToDTO(this.queryService.addRelations(relationName, id, relationIds, this.convertModifyRelationsOptions(opts))); | ||
async addRelations(relationName, id, relationIds, opts) { | ||
return this.assembler.convertToDTO(await this.queryService.addRelations(relationName, id, relationIds, this.convertModifyRelationsOptions(opts))); | ||
} | ||
createMany(items) { | ||
async createMany(items) { | ||
const { assembler } = this; | ||
const converted = assembler.convertToCreateEntities(items); | ||
return this.assembler.convertAsyncToDTOs(this.queryService.createMany(converted)); | ||
const converted = await assembler.convertToCreateEntities(items); | ||
return this.assembler.convertToDTOs(await this.queryService.createMany(converted)); | ||
} | ||
createOne(item) { | ||
const c = this.assembler.convertToCreateEntity(item); | ||
return this.assembler.convertAsyncToDTO(this.queryService.createOne(c)); | ||
async createOne(item) { | ||
const c = await this.assembler.convertToCreateEntity(item); | ||
return this.assembler.convertToDTO(await this.queryService.createOne(c)); | ||
} | ||
@@ -26,4 +26,4 @@ async deleteMany(filter) { | ||
} | ||
deleteOne(id, opts) { | ||
return this.assembler.convertAsyncToDTO(this.queryService.deleteOne(id, this.convertFilterable(opts))); | ||
async deleteOne(id, opts) { | ||
return this.assembler.convertToDTO(await this.queryService.deleteOne(id, this.convertFilterable(opts))); | ||
} | ||
@@ -37,7 +37,7 @@ async findById(id, opts) { | ||
} | ||
getById(id, opts) { | ||
return this.assembler.convertAsyncToDTO(this.queryService.getById(id, this.convertFilterable(opts))); | ||
async getById(id, opts) { | ||
return this.assembler.convertToDTO(await this.queryService.getById(id, this.convertFilterable(opts))); | ||
} | ||
query(query, opts) { | ||
return this.assembler.convertAsyncToDTOs(this.queryService.query(this.assembler.convertQuery(query), opts)); | ||
async query(query, opts) { | ||
return this.assembler.convertToDTOs(await this.queryService.query(this.assembler.convertQuery(query), opts)); | ||
} | ||
@@ -53,3 +53,3 @@ async aggregate(filter, aggregate, opts) { | ||
if (Array.isArray(dto)) { | ||
const entities = this.assembler.convertToEntities(dto); | ||
const entities = await this.assembler.convertToEntities(dto); | ||
const relationMap = await this.queryService.queryRelations(RelationClass, relationName, entities, query); | ||
@@ -62,7 +62,7 @@ return entities.reduce((map, e, index) => { | ||
} | ||
return this.queryService.queryRelations(RelationClass, relationName, this.assembler.convertToEntity(dto), query); | ||
return this.queryService.queryRelations(RelationClass, relationName, await this.assembler.convertToEntity(dto), query); | ||
} | ||
async countRelations(RelationClass, relationName, dto, filter) { | ||
if (Array.isArray(dto)) { | ||
const entities = this.assembler.convertToEntities(dto); | ||
const entities = await this.assembler.convertToEntities(dto); | ||
const relationMap = await this.queryService.countRelations(RelationClass, relationName, entities, filter); | ||
@@ -75,7 +75,7 @@ return entities.reduce((map, e, index) => { | ||
} | ||
return this.queryService.countRelations(RelationClass, relationName, this.assembler.convertToEntity(dto), filter); | ||
return this.queryService.countRelations(RelationClass, relationName, await this.assembler.convertToEntity(dto), filter); | ||
} | ||
async findRelation(RelationClass, relationName, dto, opts) { | ||
if (Array.isArray(dto)) { | ||
const entities = this.assembler.convertToEntities(dto); | ||
const entities = await this.assembler.convertToEntities(dto); | ||
const relationMap = await this.queryService.findRelation(RelationClass, relationName, entities, opts); | ||
@@ -87,27 +87,27 @@ return entities.reduce((map, e, index) => { | ||
} | ||
return this.queryService.findRelation(RelationClass, relationName, this.assembler.convertToEntity(dto)); | ||
return this.queryService.findRelation(RelationClass, relationName, await this.assembler.convertToEntity(dto)); | ||
} | ||
removeRelation(relationName, id, relationId, opts) { | ||
return this.assembler.convertAsyncToDTO(this.queryService.removeRelation(relationName, id, relationId, this.convertModifyRelationsOptions(opts))); | ||
async removeRelation(relationName, id, relationId, opts) { | ||
return this.assembler.convertToDTO(await this.queryService.removeRelation(relationName, id, relationId, this.convertModifyRelationsOptions(opts))); | ||
} | ||
removeRelations(relationName, id, relationIds, opts) { | ||
return this.assembler.convertAsyncToDTO(this.queryService.removeRelations(relationName, id, relationIds, this.convertModifyRelationsOptions(opts))); | ||
async removeRelations(relationName, id, relationIds, opts) { | ||
return this.assembler.convertToDTO(await this.queryService.removeRelations(relationName, id, relationIds, this.convertModifyRelationsOptions(opts))); | ||
} | ||
setRelations(relationName, id, relationIds, opts) { | ||
return this.assembler.convertAsyncToDTO(this.queryService.setRelations(relationName, id, relationIds, this.convertModifyRelationsOptions(opts))); | ||
async setRelations(relationName, id, relationIds, opts) { | ||
return this.assembler.convertToDTO(await this.queryService.setRelations(relationName, id, relationIds, this.convertModifyRelationsOptions(opts))); | ||
} | ||
setRelation(relationName, id, relationId, opts) { | ||
return this.assembler.convertAsyncToDTO(this.queryService.setRelation(relationName, id, relationId, this.convertModifyRelationsOptions(opts))); | ||
async setRelation(relationName, id, relationId, opts) { | ||
return this.assembler.convertToDTO(await this.queryService.setRelation(relationName, id, relationId, this.convertModifyRelationsOptions(opts))); | ||
} | ||
updateMany(update, filter) { | ||
return this.queryService.updateMany(this.assembler.convertToUpdateEntity(update), | ||
async updateMany(update, filter) { | ||
return this.queryService.updateMany(await this.assembler.convertToUpdateEntity(update), | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
this.assembler.convertQuery({ filter }).filter); | ||
} | ||
updateOne(id, update, opts) { | ||
return this.assembler.convertAsyncToDTO(this.queryService.updateOne(id, this.assembler.convertToUpdateEntity(update), this.convertFilterable(opts))); | ||
async updateOne(id, update, opts) { | ||
return this.assembler.convertToDTO(await this.queryService.updateOne(id, await this.assembler.convertToUpdateEntity(update), this.convertFilterable(opts))); | ||
} | ||
async aggregateRelations(RelationClass, relationName, dto, filter, aggregate) { | ||
if (Array.isArray(dto)) { | ||
const entities = this.assembler.convertToEntities(dto); | ||
const entities = await this.assembler.convertToEntities(dto); | ||
const relationMap = await this.queryService.aggregateRelations(RelationClass, relationName, entities, filter, aggregate); | ||
@@ -120,3 +120,3 @@ return entities.reduce((map, e, index) => { | ||
} | ||
return this.queryService.aggregateRelations(RelationClass, relationName, this.assembler.convertToEntity(dto), filter, aggregate); | ||
return this.queryService.aggregateRelations(RelationClass, relationName, await this.assembler.convertToEntity(dto), filter, aggregate); | ||
} | ||
@@ -123,0 +123,0 @@ convertFilterable(filterable) { |
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
0
201547
2897