UNPKG

@nestia/sdk

Version:

Nestia SDK and Swagger generator

127 lines 18.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SdkAliasCollection = void 0; const typescript_1 = __importDefault(require("typescript")); const typia_1 = __importDefault(require("typia")); const TypeFactory_1 = require("typia/lib/factories/TypeFactory"); const SdkTypeProgrammer_1 = require("./SdkTypeProgrammer"); var SdkAliasCollection; (function (SdkAliasCollection) { SdkAliasCollection.name = ({ type }) => typescript_1.default.factory.createTypeReferenceNode(type.name, type.typeArguments ? type.typeArguments.map((a) => SdkAliasCollection.name({ type: a })) : undefined); SdkAliasCollection.from = (project) => (importer) => (metadata) => SdkTypeProgrammer_1.SdkTypeProgrammer.write(project)(importer)(metadata); SdkAliasCollection.headers = (project) => (importer) => (param) => { if (project.config.clone === true) return SdkAliasCollection.from(project)(importer)(param.metadata); const type = SdkAliasCollection.name(param); if (project.config.primitive === false) return type; return typescript_1.default.factory.createTypeReferenceNode(importer.external({ type: true, library: "typia", instance: "Resolved", }), [type]); }; SdkAliasCollection.query = (project) => (importer) => (param) => { if (project.config.clone === true) return SdkAliasCollection.from(project)(importer)(param.metadata); const type = SdkAliasCollection.name(param); if (project.config.primitive === false) return type; return typescript_1.default.factory.createTypeReferenceNode(importer.external({ type: true, library: "typia", instance: "Resolved", }), [type]); }; SdkAliasCollection.input = (project) => (importer) => (param) => { if (project.config.clone === true) { const type = SdkAliasCollection.from(project)(importer)(param.metadata); return param.contentType === "multipart/form-data" ? formDataInput(importer)(type) : type; } const type = SdkAliasCollection.name(param); if (param.contentType === "multipart/form-data") return formDataInput(importer)(type); else if (project.config.primitive === false) return type; return typescript_1.default.factory.createTypeReferenceNode(importer.external({ type: true, library: "typia", instance: (() => { const _io0 = input => ("application/json" === input.contentType || "application/x-www-form-urlencoded" === input.contentType || "multipart/form-data" === input.contentType || "text/plain" === input.contentType) && "boolean" === typeof input.encrypted && "body" === input.category && "string" === typeof input.name && "number" === typeof input.index && ("object" === typeof input.type && null !== input.type && _io1(input.type)) && ("object" === typeof input.metadata && null !== input.metadata && _io2(input.metadata)) && ("object" === typeof input.components && null !== input.components && _io26(input.components)) && "function" === typeof input.validate && true && (undefined === input.examples || "object" === typeof input.examples && null !== input.examples && false === Array.isArray(input.examples) && _io32(input.examples)) && (null === input.description || "string" === typeof input.description) && (Array.isArray(input.jsDocTags) && input.jsDocTags.every(elem => "object" === typeof elem && null !== elem && _io5(elem))); const _io1 = input => "string" === typeof input.name && (undefined === input.typeArguments || Array.isArray(input.typeArguments) && input.typeArguments.every(elem => "object" === typeof elem && null !== elem && _io1(elem))); const _io2 = input => "boolean" === typeof input.any && "boolean" === typeof input.required && "boolean" === typeof input.optional && "boolean" === typeof input.nullable && (Array.isArray(input.functions) && input.functions.every(elem => "object" === typeof elem && null !== elem && _io3(elem))) && (Array.isArray(input.atomics) && input.atomics.every(elem => "object" === typeof elem && null !== elem && _io7(elem))) && (Array.isArray(input.constants) && input.constants.every(elem => "object" === typeof elem && null !== elem && _iu0(elem))) && (Array.isArray(input.templates) && input.templates.every(elem => "object" === typeof elem && null !== elem && _io17(elem))) && (null === input.escaped || "object" === typeof input.escaped && null !== input.escaped && _io18(input.escaped)) && (null === input.rest || "object" === typeof input.rest && null !== input.rest && _io2(input.rest)) && (Array.isArray(input.arrays) && input.arrays.every(elem => "object" === typeof elem && null !== elem && _io19(elem))) && (Array.isArray(input.tuples) && input.tuples.every(elem => "object" === typeof elem && null !== elem && _io20(elem))) && (Array.isArray(input.objects) && input.objects.every(elem => "object" === typeof elem && null !== elem && _io21(elem))) && (Array.isArray(input.aliases) && input.aliases.every(elem => "object" === typeof elem && null !== elem && _io22(elem))) && (Array.isArray(input.natives) && input.natives.every(elem => "object" === typeof elem && null !== elem && _io23(elem))) && (Array.isArray(input.sets) && input.sets.every(elem => "object" === typeof elem && null !== elem && _io24(elem))) && (Array.isArray(input.maps) && input.maps.every(elem => "object" === typeof elem && null !== elem && _io25(elem))); const _io3 = input => Array.isArray(input.parameters) && input.parameters.every(elem => "object" === typeof elem && null !== elem && _io4(elem)) && ("object" === typeof input.output && null !== input.output && _io2(input.output)) && "boolean" === typeof input.async; const _io4 = input => "string" === typeof input.name && ("object" === typeof input.type && null !== input.type && _io2(input.type)) && (null === input.description || "string" === typeof input.description) && (Array.isArray(input.jsDocTags) && input.jsDocTags.every(elem => "object" === typeof elem && null !== elem && _io5(elem))); const _io5 = input => "string" === typeof input.name && (undefined === input.text || Array.isArray(input.text) && input.text.every(elem => "object" === typeof elem && null !== elem && _io6(elem))); const _io6 = input => "string" === typeof input.text && "string" === typeof input.kind; const _io7 = input => ("string" === input.type || "number" === input.type || "bigint" === input.type || "boolean" === input.type) && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))); const _io8 = input => ("string" === input.target || "number" === input.target || "bigint" === input.target || "boolean" === input.target || "object" === input.target || "array" === input.target) && "string" === typeof input.name && "string" === typeof input.kind && (null !== input.exclusive && undefined !== input.exclusive && ("boolean" === typeof input.exclusive || Array.isArray(input.exclusive) && input.exclusive.every(elem => "string" === typeof elem))) && true && (undefined === input.validate || "string" === typeof input.validate) && (undefined === input.schema || "object" === typeof input.schema && null !== input.schema && false === Array.isArray(input.schema) && _io9(input.schema)); const _io9 = input => true; const _io10 = input => "boolean" === input.type && (Array.isArray(input.values) && input.values.every(elem => "object" === typeof elem && null !== elem && _io11(elem))); const _io11 = input => "boolean" === typeof input.value && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))) && (null === input.description || undefined === input.description || "string" === typeof input.description) && (undefined === input.jsDocTags || Array.isArray(input.jsDocTags) && input.jsDocTags.every(elem => "object" === typeof elem && null !== elem && _io5(elem))); const _io12 = input => "number" === input.type && (Array.isArray(input.values) && input.values.every(elem => "object" === typeof elem && null !== elem && _io13(elem))); const _io13 = input => "number" === typeof input.value && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))) && (null === input.description || undefined === input.description || "string" === typeof input.description) && (undefined === input.jsDocTags || Array.isArray(input.jsDocTags) && input.jsDocTags.every(elem => "object" === typeof elem && null !== elem && _io5(elem))); const _io14 = input => "string" === input.type && (Array.isArray(input.values) && input.values.every(elem => "object" === typeof elem && null !== elem && _io15(elem))); const _io15 = input => "string" === typeof input.value && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))) && (null === input.description || undefined === input.description || "string" === typeof input.description) && (undefined === input.jsDocTags || Array.isArray(input.jsDocTags) && input.jsDocTags.every(elem => "object" === typeof elem && null !== elem && _io5(elem))); const _io16 = input => "bigint" === input.type && (Array.isArray(input.values) && input.values.every(elem => "object" === typeof elem && null !== elem && _io15(elem))); const _io17 = input => Array.isArray(input.row) && input.row.every(elem => "object" === typeof elem && null !== elem && _io2(elem)) && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))); const _io18 = input => "object" === typeof input.original && null !== input.original && _io2(input.original) && ("object" === typeof input.returns && null !== input.returns && _io2(input.returns)); const _io19 = input => "string" === typeof input.name && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))); const _io20 = input => "string" === typeof input.name && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))); const _io21 = input => "string" === typeof input.name && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))); const _io22 = input => "string" === typeof input.name && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))); const _io23 = input => "string" === typeof input.name && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))); const _io24 = input => "object" === typeof input.value && null !== input.value && _io2(input.value) && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))); const _io25 = input => "object" === typeof input.key && null !== input.key && _io2(input.key) && ("object" === typeof input.value && null !== input.value && _io2(input.value)) && (Array.isArray(input.tags) && input.tags.every(elem => Array.isArray(elem) && elem.every(elem => "object" === typeof elem && null !== elem && _io8(elem)))); const _io26 = input => Array.isArray(input.objects) && input.objects.every(elem => "object" === typeof elem && null !== elem && _io27(elem)) && (Array.isArray(input.aliases) && input.aliases.every(elem => "object" === typeof elem && null !== elem && _io29(elem))) && (Array.isArray(input.arrays) && input.arrays.every(elem => "object" === typeof elem && null !== elem && _io30(elem))) && (Array.isArray(input.tuples) && input.tuples.every(elem => "object" === typeof elem && null !== elem && _io31(elem))); const _io27 = input => "string" === typeof input.name && (Array.isArray(input.properties) && input.properties.every(elem => "object" === typeof elem && null !== elem && _io28(elem))) && (undefined === input.description || "string" === typeof input.description) && (Array.isArray(input.jsDocTags) && input.jsDocTags.every(elem => "object" === typeof elem && null !== elem && _io5(elem))) && "number" === typeof input.index && "boolean" === typeof input.recursive && (Array.isArray(input.nullables) && input.nullables.every(elem => "boolean" === typeof elem)); const _io28 = input => "object" === typeof input.key && null !== input.key && _io2(input.key) && ("object" === typeof input.value && null !== input.value && _io2(input.value)) && (null === input.description || "string" === typeof input.description) && (Array.isArray(input.jsDocTags) && input.jsDocTags.every(elem => "object" === typeof elem && null !== elem && _io5(elem))); const _io29 = input => "string" === typeof input.name && ("object" === typeof input.value && null !== input.value && _io2(input.value)) && (Array.isArray(input.nullables) && input.nullables.every(elem => "boolean" === typeof elem)) && (null === input.description || "string" === typeof input.description) && (Array.isArray(input.jsDocTags) && input.jsDocTags.every(elem => "object" === typeof elem && null !== elem && _io5(elem))) && "boolean" === typeof input.recursive; const _io30 = input => "string" === typeof input.name && ("object" === typeof input.value && null !== input.value && _io2(input.value)) && (Array.isArray(input.nullables) && input.nullables.every(elem => "boolean" === typeof elem)) && "boolean" === typeof input.recursive && (null === input.index || "number" === typeof input.index); const _io31 = input => "string" === typeof input.name && (Array.isArray(input.elements) && input.elements.every(elem => "object" === typeof elem && null !== elem && _io2(elem))) && (null === input.index || "number" === typeof input.index) && "boolean" === typeof input.recursive && (Array.isArray(input.nullables) && input.nullables.every(elem => "boolean" === typeof elem)); const _io32 = input => Object.keys(input).every(key => { const value = input[key]; if (undefined === value) return true; return true; }); const _iu0 = input => (() => { if ("bigint" === input.type) return _io16(input); else if ("string" === input.type) return _io14(input); else if ("number" === input.type) return _io12(input); else if ("boolean" === input.type) return _io10(input); else return false; })(); return input => "object" === typeof input && null !== input && _io0(input); })()(param) && (param.contentType === "application/json" || param.encrypted === true) ? "Primitive" : "Resolved", }), [type]); }; SdkAliasCollection.output = (project) => (importer) => (route) => { var _a; const schema = (p) => p.metadata.size() === 0 ? TypeFactory_1.TypeFactory.keyword("void") : project.config.clone === true ? SdkAliasCollection.from(project)(importer)(p.metadata) : project.config.primitive !== false ? typescript_1.default.factory.createTypeReferenceNode(importer.external({ type: true, library: "typia", instance: route.success.contentType === "application/json" || route.success.encrypted === true ? "Primitive" : "Resolved", }), [SdkAliasCollection.name(p)]) : SdkAliasCollection.name(p); if (project.config.propagate !== true) return schema(route.success); const branches = [ { status: String((_a = route.success.status) !== null && _a !== void 0 ? _a : (route.method === "POST" ? 201 : 200)), type: schema(route.success), }, ...Object.entries(route.exceptions).map(([status, value]) => ({ status, type: schema(value), })), ]; return typescript_1.default.factory.createTypeReferenceNode(importer.external({ type: true, library: "@nestia/fetcher", instance: "IPropagation", }), [ typescript_1.default.factory.createTypeLiteralNode(branches.map((b) => typescript_1.default.factory.createPropertySignature(undefined, typescript_1.default.factory.createNumericLiteral(b.status), undefined, b.type))), ...(route.success.status ? [ typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNumericLiteral(route.success.status)), ] : []), ]); }; SdkAliasCollection.responseBody = (project) => (importer) => (route) => SdkAliasCollection.output(Object.assign(Object.assign({}, project), { config: Object.assign(Object.assign({}, project.config), { propagate: false }) }))(importer)(route); const formDataInput = (importer) => (type) => typescript_1.default.factory.createTypeReferenceNode(importer.external({ type: true, library: "@nestia/fetcher", instance: "FormDataInput", }), [type]); })(SdkAliasCollection || (exports.SdkAliasCollection = SdkAliasCollection = {})); //# sourceMappingURL=SdkAliasCollection.js.map