UNPKG

typia

Version:

Superfast runtime validators with only one line

77 lines (74 loc) 3.18 kB
import { FunctionalGeneralProgrammer } from '../../../programmers/functional/internal/FunctionalGeneralProgrammer.mjs'; import { Metadata } from '../../../schemas/metadata/Metadata.mjs'; import { MetadataFunction } from '../../../schemas/metadata/MetadataFunction.mjs'; import { MetadataParameter } from '../../../schemas/metadata/MetadataParameter.mjs'; import { CommentFactory } from '../../CommentFactory.mjs'; import { TypeFactory } from '../../TypeFactory.mjs'; import { explore_metadata } from './explore_metadata.mjs'; const iterate_metadata_function = (props) => { const declaration = TypeFactory.getFunction(props.type); if (declaration === null) return false; else if (!props.options.functional) { if (props.metadata.functions.length === 0) props.metadata.functions.push(MetadataFunction.create({ parameters: [], output: Metadata.initialize(), async: false, })); } else { const [signature] = props.type.getCallSignatures(); if (signature === undefined || signature.declaration === undefined) props.metadata.functions.push(MetadataFunction.create({ parameters: [], output: Metadata.initialize(), async: false, })); else { const { async } = FunctionalGeneralProgrammer.getReturnType({ checker: props.checker, declaration, }); props.metadata.functions.push(MetadataFunction.create({ parameters: signature.parameters.map((p) => MetadataParameter.create({ name: p.name, type: explore_metadata({ ...props, type: props.checker.getTypeOfSymbol(p), explore: { ...props.explore, top: false, parameter: p.name, }, intersected: false, }), tsType: props.checker.getTypeOfSymbol(p), description: CommentFactory.description(p) ?? null, jsDocTags: p?.getJsDocTags() ?? [], })), async, output: explore_metadata({ ...props, options: { ...props.options, functional: false, }, type: async ? (props.checker.getTypeArguments(signature.getReturnType())?.[0] ?? props.checker.getTypeFromTypeNode(TypeFactory.keyword("any"))) : signature.getReturnType(), explore: { ...props.explore, top: false, output: true, }, intersected: false, }), })); } } return true; }; export { iterate_metadata_function }; //# sourceMappingURL=iterate_metadata_function.mjs.map