Files
ncd-fe/packages/pl-api/lib/schemas/index.ts
mkljczk 4b5402aed3 wip
Signed-off-by: mkljczk <git@mkljczk.pl>
2025-01-02 16:35:49 +01:00

22 lines
585 B
TypeScript

import * as v from 'valibot';
import { instanceSchema } from '../entities';
import type { ALL_SCHEMAS } from './all-schemas';
const nullSchema = v.fallback(v.null(), null);
const IMPORTED_SCHEMAS = {
instanceSchema,
} as typeof ALL_SCHEMAS;
const SCHEMAS = new Proxy(IMPORTED_SCHEMAS, {
get: (target, p: keyof typeof ALL_SCHEMAS) => p in target ? target[p] : nullSchema,
});
const importSchemas = (schemas: Partial<typeof ALL_SCHEMAS>) =>
// @ts-ignore
Object.entries(schemas).forEach(([key, value]) => IMPORTED_SCHEMAS[key] = value);
export { SCHEMAS, importSchemas };