import { z } from 'zod' import {Container, Singleton} from '../di' import {Collection, Maybe} from '../util' type ZodifyRegistrant = { id: number, schema: z.ZodType } export function registerZodifiedSchema(id: number, schema: z.ZodType): z.ZodType { Container.getContainer() .make(ZodifyRegistrar) .register(id, schema) return schema } @Singleton() export class ZodifyRegistrar { protected registeredSchemata: Collection = new Collection() public register(id: number, schema: z.ZodType): this { this.registeredSchemata.push({ id, schema, }) return this } public get(id: number): Maybe> { return this.registeredSchemata.firstWhere('id', '=', id)?.schema } }