Initial commit
This commit is contained in:
83
shared/modules/types.ts
Normal file
83
shared/modules/types.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user