chore: update naming in abstract service to dto specifics (#6763)
This commit is contained in:
@@ -47,14 +47,19 @@ const writeMethods = [
|
|||||||
|
|
||||||
const methods: BaseMethods[] = [...readMethods, ...writeMethods]
|
const methods: BaseMethods[] = [...readMethods, ...writeMethods]
|
||||||
|
|
||||||
|
type ModelDTOConfig = {
|
||||||
|
dto: object
|
||||||
|
create?: object
|
||||||
|
update?: object
|
||||||
|
}
|
||||||
|
type ModelDTOConfigRecord = Record<any, ModelDTOConfig>
|
||||||
|
type ModelNamingConfig = {
|
||||||
|
singular?: string
|
||||||
|
plural?: string
|
||||||
|
}
|
||||||
|
|
||||||
type ModelsConfigTemplate = {
|
type ModelsConfigTemplate = {
|
||||||
[ModelName: string]: {
|
[ModelName: string]: ModelDTOConfig & ModelNamingConfig
|
||||||
singular?: string
|
|
||||||
plural?: string
|
|
||||||
dto: object
|
|
||||||
create?: object
|
|
||||||
update?: object
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExtractSingularName<
|
type ExtractSingularName<
|
||||||
@@ -63,17 +68,17 @@ type ExtractSingularName<
|
|||||||
> = T[K] extends { singular?: string } ? T[K]["singular"] : K
|
> = T[K] extends { singular?: string } ? T[K]["singular"] : K
|
||||||
|
|
||||||
type CreateMethodName<
|
type CreateMethodName<
|
||||||
ModelConfig extends Record<any, any>,
|
TModelDTOConfig extends ModelDTOConfigRecord,
|
||||||
ModelKey = keyof ModelConfig
|
TModelName = keyof TModelDTOConfig
|
||||||
> = ModelConfig[ModelKey] extends { create?: object }
|
> = TModelDTOConfig[TModelName] extends { create?: object }
|
||||||
? `create${ExtractPluralName<ModelConfig, ModelKey>}`
|
? `create${ExtractPluralName<TModelDTOConfig, TModelName>}`
|
||||||
: never
|
: never
|
||||||
|
|
||||||
type UpdateMethodName<
|
type UpdateMethodName<
|
||||||
ModelConfig extends Record<any, any>,
|
TModelDTOConfig extends ModelDTOConfigRecord,
|
||||||
ModelKey = keyof ModelConfig
|
TModelName = keyof TModelDTOConfig
|
||||||
> = ModelConfig[ModelKey] extends { update?: object }
|
> = TModelDTOConfig[TModelName] extends { update?: object }
|
||||||
? `update${ExtractPluralName<ModelConfig, ModelKey>}`
|
? `update${ExtractPluralName<TModelDTOConfig, TModelName>}`
|
||||||
: never
|
: never
|
||||||
|
|
||||||
type ExtractPluralName<T extends Record<any, any>, K = keyof T> = T[K] extends {
|
type ExtractPluralName<T extends Record<any, any>, K = keyof T> = T[K] extends {
|
||||||
@@ -128,33 +133,42 @@ export interface AbstractModuleServiceBase<TContainer, TMainModelDTO> {
|
|||||||
export type AbstractModuleService<
|
export type AbstractModuleService<
|
||||||
TContainer,
|
TContainer,
|
||||||
TMainModelDTO,
|
TMainModelDTO,
|
||||||
ModelsConfig extends ModelsConfigTemplate
|
TModelDTOConfig extends ModelsConfigTemplate
|
||||||
> = AbstractModuleServiceBase<TContainer, TMainModelDTO> & {
|
> = AbstractModuleServiceBase<TContainer, TMainModelDTO> & {
|
||||||
[K in keyof ModelsConfig as `retrieve${ExtractSingularName<ModelsConfig, K> &
|
[TModelName in keyof TModelDTOConfig as `retrieve${ExtractSingularName<
|
||||||
|
TModelDTOConfig,
|
||||||
|
TModelName
|
||||||
|
> &
|
||||||
string}`]: (
|
string}`]: (
|
||||||
id: string,
|
id: string,
|
||||||
config?: FindConfig<any>,
|
config?: FindConfig<any>,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
) => Promise<ModelsConfig[K & string]["dto"]>
|
) => Promise<TModelDTOConfig[TModelName & string]["dto"]>
|
||||||
} & {
|
} & {
|
||||||
[K in keyof ModelsConfig as `list${ExtractPluralName<ModelsConfig, K> &
|
[TModelName in keyof TModelDTOConfig as `list${ExtractPluralName<
|
||||||
|
TModelDTOConfig,
|
||||||
|
TModelName
|
||||||
|
> &
|
||||||
string}`]: (
|
string}`]: (
|
||||||
filters?: any,
|
filters?: any,
|
||||||
config?: FindConfig<any>,
|
config?: FindConfig<any>,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
) => Promise<ModelsConfig[K & string]["dto"][]>
|
) => Promise<TModelDTOConfig[TModelName & string]["dto"][]>
|
||||||
} & {
|
} & {
|
||||||
[K in keyof ModelsConfig as `listAndCount${ExtractPluralName<
|
[TModelName in keyof TModelDTOConfig as `listAndCount${ExtractPluralName<
|
||||||
ModelsConfig,
|
TModelDTOConfig,
|
||||||
K
|
TModelName
|
||||||
> &
|
> &
|
||||||
string}`]: {
|
string}`]: {
|
||||||
(filters?: any, config?: FindConfig<any>, sharedContext?: Context): Promise<
|
(filters?: any, config?: FindConfig<any>, sharedContext?: Context): Promise<
|
||||||
[ModelsConfig[K & string]["dto"][], number]
|
[TModelDTOConfig[TModelName & string]["dto"][], number]
|
||||||
>
|
>
|
||||||
}
|
}
|
||||||
} & {
|
} & {
|
||||||
[K in keyof ModelsConfig as `delete${ExtractPluralName<ModelsConfig, K> &
|
[TModelName in keyof TModelDTOConfig as `delete${ExtractPluralName<
|
||||||
|
TModelDTOConfig,
|
||||||
|
TModelName
|
||||||
|
> &
|
||||||
string}`]: {
|
string}`]: {
|
||||||
(
|
(
|
||||||
primaryKeyValues: string | object | string[] | object[],
|
primaryKeyValues: string | object | string[] | object[],
|
||||||
@@ -162,7 +176,10 @@ export type AbstractModuleService<
|
|||||||
): Promise<void>
|
): Promise<void>
|
||||||
}
|
}
|
||||||
} & {
|
} & {
|
||||||
[K in keyof ModelsConfig as `softDelete${ExtractPluralName<ModelsConfig, K> &
|
[TModelName in keyof TModelDTOConfig as `softDelete${ExtractPluralName<
|
||||||
|
TModelDTOConfig,
|
||||||
|
TModelName
|
||||||
|
> &
|
||||||
string}`]: {
|
string}`]: {
|
||||||
<TReturnableLinkableKeys extends string>(
|
<TReturnableLinkableKeys extends string>(
|
||||||
primaryKeyValues: string | object | string[] | object[],
|
primaryKeyValues: string | object | string[] | object[],
|
||||||
@@ -171,7 +188,10 @@ export type AbstractModuleService<
|
|||||||
): Promise<Record<string, string[]> | void>
|
): Promise<Record<string, string[]> | void>
|
||||||
}
|
}
|
||||||
} & {
|
} & {
|
||||||
[K in keyof ModelsConfig as `restore${ExtractPluralName<ModelsConfig, K> &
|
[TModelName in keyof TModelDTOConfig as `restore${ExtractPluralName<
|
||||||
|
TModelDTOConfig,
|
||||||
|
TModelName
|
||||||
|
> &
|
||||||
string}`]: {
|
string}`]: {
|
||||||
<TReturnableLinkableKeys extends string>(
|
<TReturnableLinkableKeys extends string>(
|
||||||
primaryKeyValues: string | object | string[] | object[],
|
primaryKeyValues: string | object | string[] | object[],
|
||||||
@@ -180,42 +200,44 @@ export type AbstractModuleService<
|
|||||||
): Promise<Record<string, string[]> | void>
|
): Promise<Record<string, string[]> | void>
|
||||||
}
|
}
|
||||||
} & {
|
} & {
|
||||||
[ModelName in keyof ModelsConfig as CreateMethodName<
|
[TModelName in keyof TModelDTOConfig as CreateMethodName<
|
||||||
ModelsConfig,
|
TModelDTOConfig,
|
||||||
ModelName
|
TModelName
|
||||||
>]: {
|
>]: {
|
||||||
(
|
(
|
||||||
data: ModelsConfig[ModelName]["create"][],
|
data: TModelDTOConfig[TModelName]["create"][],
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<ModelsConfig[ModelName]["dto"][]>
|
): Promise<TModelDTOConfig[TModelName]["dto"][]>
|
||||||
}
|
}
|
||||||
} & {
|
} & {
|
||||||
[ModelName in keyof ModelsConfig as CreateMethodName<
|
[TModelName in keyof TModelDTOConfig as CreateMethodName<
|
||||||
ModelsConfig,
|
TModelDTOConfig,
|
||||||
ModelName
|
TModelName
|
||||||
>]: {
|
|
||||||
(data: ModelsConfig[ModelName]["create"], sharedContext?: Context): Promise<
|
|
||||||
ModelsConfig[ModelName]["dto"]
|
|
||||||
>
|
|
||||||
}
|
|
||||||
} & {
|
|
||||||
[ModelName in keyof ModelsConfig as UpdateMethodName<
|
|
||||||
ModelsConfig,
|
|
||||||
ModelName
|
|
||||||
>]: {
|
>]: {
|
||||||
(
|
(
|
||||||
data: ModelsConfig[ModelName]["update"][],
|
data: TModelDTOConfig[TModelName]["create"],
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<ModelsConfig[ModelName]["dto"][]>
|
): Promise<TModelDTOConfig[TModelName]["dto"]>
|
||||||
}
|
}
|
||||||
} & {
|
} & {
|
||||||
[ModelName in keyof ModelsConfig as UpdateMethodName<
|
[TModelName in keyof TModelDTOConfig as UpdateMethodName<
|
||||||
ModelsConfig,
|
TModelDTOConfig,
|
||||||
ModelName
|
TModelName
|
||||||
>]: {
|
>]: {
|
||||||
(data: ModelsConfig[ModelName]["update"], sharedContext?: Context): Promise<
|
(
|
||||||
ModelsConfig[ModelName]["dto"]
|
data: TModelDTOConfig[TModelName]["update"][],
|
||||||
>
|
sharedContext?: Context
|
||||||
|
): Promise<TModelDTOConfig[TModelName]["dto"][]>
|
||||||
|
}
|
||||||
|
} & {
|
||||||
|
[TModelName in keyof TModelDTOConfig as UpdateMethodName<
|
||||||
|
TModelDTOConfig,
|
||||||
|
TModelName
|
||||||
|
>]: {
|
||||||
|
(
|
||||||
|
data: TModelDTOConfig[TModelName]["update"],
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<TModelDTOConfig[TModelName]["dto"]>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user