UNPKG

@sontrx/typia

Version:

Superfast runtime validators with only one line

49 lines 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LlmApplicationOfValidateProgrammer = void 0; const TypeFactory_1 = require("../../factories/TypeFactory"); const ValidateProgrammer_1 = require("../ValidateProgrammer"); const LlmApplicationProgrammer_1 = require("./LlmApplicationProgrammer"); var LlmApplicationOfValidateProgrammer; (function (LlmApplicationOfValidateProgrammer) { LlmApplicationOfValidateProgrammer.validate = (props) => LlmApplicationProgrammer_1.LlmApplicationProgrammer.validate(props); LlmApplicationOfValidateProgrammer.write = (props) => { const app = LlmApplicationProgrammer_1.LlmApplicationProgrammer.write(props); const parameters = Object.fromEntries(props.metadata.objects[0].type.properties.filter((p) => p.key.isSoleLiteral() && p.value.size() === 1 && p.value.nullable === false && p.value.isRequired() === true && p.value.functions.length === 1) .filter((p) => p.jsDocTags.find((tag) => tag.name === "hidden" || tag.name === "internal") === undefined) .map((p) => [ p.key.getSoleLiteral(), p.value.functions[0].parameters[0], ])); return Object.assign(Object.assign({}, app), { functions: app.functions.map((func) => { var _a; return (Object.assign(Object.assign({}, func), { validate: writeValidadtor({ context: props.context, modulo: props.modulo, className: props.name, name: func.name, parameter: (_a = parameters[func.name]) !== null && _a !== void 0 ? _a : null, }) })); }) }); }; const writeValidadtor = (props) => { if (props.parameter === null) return ValidateProgrammer_1.ValidateProgrammer.write(Object.assign(Object.assign({}, props), { type: props.context.checker.getTypeFromTypeNode(TypeFactory_1.TypeFactory.keyword("any")), config: { equals: false, }, name: undefined })); const type = props.parameter.tsType; if (type === undefined) // unreachable throw new Error("Failed to write LLM application's function validator. You don't have to call `LlmApplicationOfValidator.write()` function by yourself, but only by the `typia.llm.applicationOfValidate()` function."); return ValidateProgrammer_1.ValidateProgrammer.write(Object.assign(Object.assign({}, props), { type: props.parameter.tsType, config: { equals: false, }, name: props.className ? `Parameters<${props.className}[${JSON.stringify(props.name)}]>[0]` : undefined })); }; })(LlmApplicationOfValidateProgrammer || (exports.LlmApplicationOfValidateProgrammer = LlmApplicationOfValidateProgrammer = {})); //# sourceMappingURL=LlmApplicationOfValidateProgrammer.js.map