From 04dfe549c272878756544481f0a0d301d6e3c228 Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Sat, 18 Mar 2023 18:53:00 +0330 Subject: [PATCH 1/2] fix(type/service-response): default generics Co-authored-by: Mohammad Honarvar --- core/type/src/service-response.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/type/src/service-response.ts b/core/type/src/service-response.ts index 1d7012b89..209998468 100644 --- a/core/type/src/service-response.ts +++ b/core/type/src/service-response.ts @@ -14,7 +14,8 @@ export interface AlwatrServiceResponseFailed extends StringifyableRecord { data?: never; } -export interface AlwatrServiceResponseSuccess extends StringifyableRecord { +export interface AlwatrServiceResponseSuccess + extends StringifyableRecord { ok: true; statusCode?: number; errorCode?: never; @@ -23,8 +24,8 @@ export interface AlwatrServiceResponseSuccess } export interface AlwatrServiceResponseSuccessWithMeta< - TData extends StringifyableRecord, - TMeta extends StringifyableRecord + TData extends StringifyableRecord = StringifyableRecord, + TMeta extends StringifyableRecord = StringifyableRecord > extends StringifyableRecord { ok: true; statusCode?: number; @@ -33,7 +34,10 @@ export interface AlwatrServiceResponseSuccessWithMeta< data: TData; } -export type AlwatrServiceResponse = +export type AlwatrServiceResponse< + TData extends StringifyableRecord = StringifyableRecord, + TMeta extends StringifyableRecord = StringifyableRecord +> = | AlwatrServiceResponseSuccess | AlwatrServiceResponseSuccessWithMeta | AlwatrServiceResponseFailed; From 146094004e55886c1cecb8bb648901f294512264 Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Sun, 19 Mar 2023 00:31:21 +0330 Subject: [PATCH 2/2] refactor(type): AlwatrDocumentStorage type with AlwatrServiceResponseSuccessWithMeta --- core/type/src/storage.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/type/src/storage.ts b/core/type/src/storage.ts index 4ac1750ae..011232ef1 100644 --- a/core/type/src/storage.ts +++ b/core/type/src/storage.ts @@ -1,3 +1,4 @@ +import {AlwatrServiceResponseSuccessWithMeta} from './service-response.js'; import {StringifyableRecord} from './type-helper.js'; export interface AlwatrDocumentObject extends StringifyableRecord { @@ -22,8 +23,5 @@ export interface AlwatrStorageMeta extends StringifyableRecord { // 'statusCode' | 'errorCode' // >; -export interface AlwatrDocumentStorage extends StringifyableRecord { - ok: true; - data: Record; - meta: AlwatrStorageMeta; -} +export type AlwatrDocumentStorage = + AlwatrServiceResponseSuccessWithMeta, AlwatrStorageMeta>;