UNPKG

@tsed/schema

Version:
35 lines (34 loc) 1.03 kB
/** * @ignore */ const JsonSchemaMappersContainer = new Map(); /** * @ignore */ export function registerJsonSchemaMapper(type, mapper, spec) { return JsonSchemaMappersContainer.set(spec ? `${spec}:${type}` : type, mapper); } /** * @ignore */ export function getJsonSchemaMapper(type, options) { const mapper = JsonSchemaMappersContainer.get(`${options?.specType}:${type}`) || JsonSchemaMappersContainer.get(type); if (mapper) { return mapper; } // istanbul ignore next throw new Error(`JsonSchema ${type} mapper doesn't exists`); } /** * @ignore */ export function execMapper(type, args, options, parent) { return getJsonSchemaMapper(type, options)(...args, options, parent); } export function hasMapper(type) { return JsonSchemaMappersContainer.has(type); } export function execOneOfMapper(types, options) { return (types.find((type) => JsonSchemaMappersContainer.has(`${options?.specType}:${type}`)) || types.find((type) => JsonSchemaMappersContainer.has(type))); }