| 1 | import type { ZodDto } from '@yikart/common' |
| 2 | import type { ZodType } from 'zod' |
| 3 | import { AppException, ResponseCode } from '@yikart/common' |
| 4 | |
| 5 | interface ConfigEditorSourceConfig { |
| 6 | meta?: { |
| 7 | configPath?: string |
| 8 | } |
| 9 | } |
| 10 | |
| 11 | export interface ConfigEditorModuleOptions<T> { |
| 12 | schema: ZodDto<T, any> | ZodType |
| 13 | config: ConfigEditorSourceConfig |
| 14 | routePrefix?: string |
| 15 | } |
| 16 | |
| 17 | export class ConfigEditorConfig<T> { |
| 18 | schema: ZodDto<T, any> | ZodType |
| 19 | configPath: string |
| 20 | routePrefix: string |
| 21 | |
| 22 | constructor(options: ConfigEditorModuleOptions<T>) { |
| 23 | const configPath = options.config.meta?.configPath |
| 24 | if (!configPath) { |
| 25 | throw new AppException(ResponseCode.ConfigEditorConfigPathMissing) |
| 26 | } |
| 27 | |
| 28 | this.schema = options.schema |
| 29 | this.configPath = configPath |
| 30 | this.routePrefix = (options.routePrefix ?? 'config').replace(/^\/+|\/+$/g, '') || 'config' |
| 31 | } |
| 32 | } |
| 33 |