typia
Version:
Superfast runtime validators with only one line
68 lines • 3.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LlmMetadataFactory = void 0;
const MetadataCollection_1 = require("../../factories/MetadataCollection");
const MetadataFactory_1 = require("../../factories/MetadataFactory");
const TransformerError_1 = require("../../transformers/TransformerError");
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_1.MetadataCollection();
const result = MetadataFactory_1.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_1.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_1.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_1.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_1.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_1.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 || (exports.LlmMetadataFactory = LlmMetadataFactory = {}));
//# sourceMappingURL=LlmMetadataFactory.js.map