84 lines
1.8 KiB
TypeScript
84 lines
1.8 KiB
TypeScript
|
|
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
|
||
|
|
|
||
|
|
export interface EndpointDefinition {
|
||
|
|
path: string
|
||
|
|
method: HttpMethod
|
||
|
|
description?: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ModuleEndpoints {
|
||
|
|
[key: string]: EndpointDefinition
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ModuleFrontendConfig {
|
||
|
|
enabled?: boolean
|
||
|
|
icon?: string
|
||
|
|
component?: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ModuleBackendConfig {
|
||
|
|
enabled?: boolean
|
||
|
|
createModule?: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ModuleDefinition<
|
||
|
|
TId extends string = string,
|
||
|
|
TEndpoints extends ModuleEndpoints = ModuleEndpoints
|
||
|
|
> {
|
||
|
|
id: TId
|
||
|
|
name: string
|
||
|
|
basePath: string
|
||
|
|
order: number
|
||
|
|
version?: string
|
||
|
|
endpoints?: TEndpoints
|
||
|
|
dependencies?: string[]
|
||
|
|
icon?: string
|
||
|
|
frontend?: ModuleFrontendConfig
|
||
|
|
backend?: ModuleBackendConfig
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ApiModuleConfig<
|
||
|
|
TId extends string = string,
|
||
|
|
TEndpoints extends ModuleEndpoints = ModuleEndpoints
|
||
|
|
> extends ModuleDefinition<TId, TEndpoints> {
|
||
|
|
version: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export function defineModule<
|
||
|
|
TId extends string,
|
||
|
|
TEndpoints extends ModuleEndpoints
|
||
|
|
>(
|
||
|
|
config: ModuleDefinition<TId, TEndpoints>
|
||
|
|
): ModuleDefinition<TId, TEndpoints> {
|
||
|
|
return config
|
||
|
|
}
|
||
|
|
|
||
|
|
export function defineApiModule<
|
||
|
|
TId extends string,
|
||
|
|
TEndpoints extends ModuleEndpoints
|
||
|
|
>(
|
||
|
|
config: ApiModuleConfig<TId, TEndpoints>
|
||
|
|
): ApiModuleConfig<TId, TEndpoints> {
|
||
|
|
return config
|
||
|
|
}
|
||
|
|
|
||
|
|
export function defineEndpoints<TEndpoints extends ModuleEndpoints>(
|
||
|
|
endpoints: TEndpoints
|
||
|
|
): TEndpoints {
|
||
|
|
return endpoints
|
||
|
|
}
|
||
|
|
|
||
|
|
export type ExtractEndpointPaths<TEndpoints extends ModuleEndpoints> = {
|
||
|
|
[K in keyof TEndpoints]: TEndpoints[K]['path']
|
||
|
|
}
|
||
|
|
|
||
|
|
export type ExtractEndpointMethods<TEndpoints extends ModuleEndpoints> = {
|
||
|
|
[K in keyof TEndpoints]: TEndpoints[K]['method']
|
||
|
|
}
|
||
|
|
|
||
|
|
export type EndpointConfig = EndpointDefinition
|
||
|
|
|
||
|
|
export interface ModuleApiConfig {
|
||
|
|
endpoints: ModuleEndpoints
|
||
|
|
}
|