UNPKG

typia

Version:

Superfast runtime validators with only one line

69 lines (66 loc) 2.98 kB
import { MetadataCollection } from '../../factories/MetadataCollection.mjs'; import { MetadataFactory } from '../../factories/MetadataFactory.mjs'; import { TransformerError } from '../../transformers/TransformerError.mjs'; var LlmMetadataFactory; (function (LlmMetadataFactory) { LlmMetadataFactory.getConfig = (props) => { if (props.node === undefined) return undefined; const type = props.context.checker.getTypeFromTypeNode(props.node); const collection = new MetadataCollection(); const result = MetadataFactory.analyze({ checker: props.context.checker, transformer: props.context.transformer, options: { absorb: true, escape: false, constant: true, functional: false, }, collection, type, }); if (result.success === false) throw new TransformerError({ code: `typia.llm.${props.method}`, message: `Failed to analyze generic argument "Config".`, }); const meta = result.data; if (meta.size() !== 1 || meta.objects.length !== 1 || meta.nullable === true || meta.isRequired() === false) throw new TransformerError({ code: `typia.llm.${props.method}`, message: `Invalid generic argument "Config". It must be a literal object type.`, }); const obj = meta.objects[0]; if (obj.type.properties.some((p) => p.key.isSoleLiteral() === false)) throw new TransformerError({ code: `typia.llm.${props.method}`, message: `Invalid generic argument "Config". It must be a literal object type. Do not allow dynamic properties.`, }); else if (obj.type.properties.some((p) => p.value.size() !== 1 || p.value.constants.length !== 1 || p.value.nullable === true || p.value.isRequired() === false)) throw new TransformerError({ code: `typia.llm.${props.method}`, message: `Invalid generic argument "Config". It must be a literal object type. Do not allow variable type.`, }); const config = {}; for (const prop of obj.type.properties) { const key = prop.key.getSoleLiteral(); const value = prop.value.constants[0].values[0].value; if (typeof value === "bigint") throw new TransformerError({ code: `typia.llm.${props.method}`, message: `Invalid generic argument "Config". It must be a literal object type. Do not allow bigint.`, }); config[key] = value; } return config; }; })(LlmMetadataFactory || (LlmMetadataFactory = {})); export { LlmMetadataFactory }; //# sourceMappingURL=LlmMetadataFactory.mjs.map