From 4c5284f8017747911519494432227959a63caec0 Mon Sep 17 00:00:00 2001 From: Alex H Date: Thu, 5 Dec 2024 13:25:47 +0100 Subject: [PATCH] chore(json-api-nestjs): Fix types --- .../json-api/json-api-nestjs/src/lib/helper/orm/orm-helper.ts | 3 ++- .../src/lib/mixin/service/typeorm-utils.service.ts | 3 +-- libs/json-api/json-api-nestjs/src/lib/types/utils.ts | 4 +--- libs/json-api/json-shared-type/src/types/entity-type.ts | 1 + 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libs/json-api/json-api-nestjs/src/lib/helper/orm/orm-helper.ts b/libs/json-api/json-api-nestjs/src/lib/helper/orm/orm-helper.ts index df6dec9..d73f083 100644 --- a/libs/json-api/json-api-nestjs/src/lib/helper/orm/orm-helper.ts +++ b/libs/json-api/json-api-nestjs/src/lib/helper/orm/orm-helper.ts @@ -7,6 +7,7 @@ import { EntityProps, EntityPropsArray, EntityRelation, + IsArray, TypeCast, TypeOfArray, UnionToTuple, @@ -79,7 +80,7 @@ export enum TypeField { export type TypeForId = Extract; export type FieldWithType = { - [K in EntityProps]: E[K] extends unknown[] + [K in EntityProps]: IsArray extends true ? TypeField.array : E[K] extends Date ? TypeField.date diff --git a/libs/json-api/json-api-nestjs/src/lib/mixin/service/typeorm-utils.service.ts b/libs/json-api/json-api-nestjs/src/lib/mixin/service/typeorm-utils.service.ts index 125ddba..846a575 100644 --- a/libs/json-api/json-api-nestjs/src/lib/mixin/service/typeorm-utils.service.ts +++ b/libs/json-api/json-api-nestjs/src/lib/mixin/service/typeorm-utils.service.ts @@ -243,7 +243,6 @@ export class TypeormUtilsService { const paramsName = this.getParamName(fieldWithAlias); if (!isTargetField(this._relationFields, fieldName)) { - if ( (operand === FilterOperand.ne || operand === FilterOperand.eq) && (valueConditional === 'null' || valueConditional === null) @@ -525,7 +524,7 @@ export class TypeormUtilsService { )) { const [props, type] = ObjectTyped.entries(item)[0]; if (type !== null) { - target[props] = type; + target[props] = type as any; } else { target[props] = null as any; } diff --git a/libs/json-api/json-api-nestjs/src/lib/types/utils.ts b/libs/json-api/json-api-nestjs/src/lib/types/utils.ts index 6662470..87021b2 100644 --- a/libs/json-api/json-api-nestjs/src/lib/types/utils.ts +++ b/libs/json-api/json-api-nestjs/src/lib/types/utils.ts @@ -61,6 +61,4 @@ export type JSONValue = | { [x: string]: JSONValue } | Array; -export type IsArray = T extends unknown[] ? true : false; - -export type IsPropertyIsArray> = IsArray; +export type IsArray = [Extract] extends [never] ? false : true; diff --git a/libs/json-api/json-shared-type/src/types/entity-type.ts b/libs/json-api/json-shared-type/src/types/entity-type.ts index 9866fee..cae7b49 100644 --- a/libs/json-api/json-shared-type/src/types/entity-type.ts +++ b/libs/json-api/json-shared-type/src/types/entity-type.ts @@ -4,6 +4,7 @@ export type EntityField = | boolean | string[] | number[] + | null | Date; export type EntityProps = {