oazapfts
Version:
OpenApi TypeScript client generator
23 lines (18 loc) • 25.7 kB
JavaScript
;var Xe=Object.defineProperty,et=Object.defineProperties;var tt=Object.getOwnPropertyDescriptors;var je=Object.getOwnPropertySymbols;var rt=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable;var ce=(t,e,r)=>e in t?Xe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,X=(t,e)=>{for(var r in e||(e={}))rt.call(e,r)&&ce(t,r,e[r]);if(je)for(var r of je(e))nt.call(e,r)&&ce(t,r,e[r]);return t},Ke=(t,e)=>et(t,tt(e));var j=(t,e,r)=>ce(t,typeof e!="symbol"?e+"":e,r);const u=require("typescript"),O=require("lodash"),_=u.factory;function it(t){const e=t.split(/{([\s\S]+?)}/g),r=O.chunk(e.slice(1),2);return ie(e[0],r.map(([n,i])=>({expression:_.createIdentifier(n),literal:i})))}function ot(t,e){const r=[F(W(Object.entries(e||{}).map(([n,i])=>({name:n,initializer:U(i.default)}))),{type:_.createTypeLiteralNode(Object.entries(e||{}).map(([n,i])=>x({name:n,type:i.enum?H(i.enum):_.createUnionTypeNode([h.string,h.number,h.boolean])})))})];return ye(r,it(t))}function st(t){return t.variables?ot(t.url,t.variables):_.createStringLiteral(t.url)}function at(t){if(!t)return"/";const{url:e,variables:r}=t;return r?e.replace(/\{(.+?)\}/g,(n,i)=>r[i]?String(r[i].default):n):e}function ke(t){return _.createStringLiteral(at(t[0]))}function ct(t,e){return t.description?O.camelCase(t.description.replace(/\W+/," ")):`server${e+1}`}function ut(t){return ne(t.map((e,r)=>[ct(e,r),st(e)]))}const a=u.factory,Le=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"],Pe={"*/*":"json","application/json":"json","application/x-www-form-urlencoded":"form","multipart/form-data":"multipart"};function Ie(t){return typeof t=="string"&&/^[^/]+\/[^/]+$/.test(t)}function te(t){return Pe[t]==="json"||/\bjson\b/i.test(t)}function Re(t){if(t!=null&&t.content)for(const e of Object.keys(t.content)){const r=Pe[e];if(r)return r;if(te(e))return"json"}}function Ce({style:t="form",explode:e=!0,content:r}){if(r){const n=Object.keys(r);if(n.length!==1)throw new Error("Parameters with content property must specify one media type");if(!te(n[0]))throw new Error("Parameters with content property must specify a JSON compatible media type");return"json"}return e&&t==="deepObject"?"deep":e?"explode":t==="spaceDelimited"?"space":t==="pipeDelimited"?"pipe":"form"}function $e(t){if(t&&!t.match(/[^\w\s]/)&&(t=O.camelCase(t),G(t)))return t}function qe(t,e,r){const n=$e(r);return n||(e=e.replace(/\{(.+?)\}/,"by $1").replace(/\{(.+?)\}/,"and $1"),w(`${t} ${e}`))}function Ue(t){return typeof t=="boolean"?t:t&&"nullable"in t?!N(t)&&t.nullable:!1}function N(t){return typeof t=="object"&&t!==null&&"$ref"in t}function fe(t){if(!t.startsWith("#/"))throw new Error(`External refs are not supported (${t}). Make sure to call SwaggerParser.bundle() first.`);return t.slice(2).split("/").map(e=>decodeURI(e.replace(/~1/g,"/").replace(/~0/g,"~")))}function q(t){return t.replace(/.+\//,"")}function pt(t){const e=q(t);return/^\d+/.test(e)?fe(t).join("_"):e}function ue(t){if(N(t))return q(t.$ref)}const ft={readOnly:"Read",writeOnly:"Write"};function lt(t){return t?ft[t]:""}function w(t,e=!1,r){let n=O.camelCase(t)+lt(r);return e&&(n=O.upperFirst(n)),G(n)?n:"$"+n}function De(t,e){const r=[],n=t.replace(/(.*?)\{(.+?)\}(.*?)(?=\{|$)/g,(i,o,s,f)=>{const p=w(s);return r.push({expression:D(a.createIdentifier("encodeURIComponent"),{args:[a.createIdentifier(p)]}),literal:f}),o});return e&&r.push({expression:e,literal:""}),ie(n,r)}function pe(t,e){return D(a.createPropertyAccessExpression(a.createIdentifier("QS"),t),{args:e})}function z(t,e,r){return D(a.createPropertyAccessExpression(a.createIdentifier("oazapfts"),t),{args:e,typeArgs:r})}function Be(t){const e=[],r={};return t.forEach(n=>{const i=/^(.+?)\[(.*?)\]/.exec(n.name);if(!i){e.push(n);return}const[,o,s]=i;let f=r[o];f||(f=r[o]={name:o,in:n.in,style:"deepObject",schema:{type:"object",properties:{}}},e.push(f)),f.schema.properties[s]=n.schema}),e}function dt(t){return t in h}class yt{constructor(e,r={},n=!1){j(this,"discriminatingSchemas",new Set);j(this,"aliases",[]);j(this,"enumAliases",[]);j(this,"enumRefs",{});j(this,"refs",{});j(this,"refsOnlyMode",new Map);j(this,"typeAliases",{});var i;this.spec=e,this.opts=r,this.isConverted=n,(i=this.spec.components)!=null&&i.schemas&&this.preprocessComponents(this.spec.components.schemas)}reset(){this.aliases=[],this.enumAliases=[],this.refs={},this.typeAliases={}}resolve(e){if(!N(e))return e;const r=e.$ref,n=fe(r),i=O.get(this.spec,n);if(typeof i=="undefined")throw new Error(`Can't find ${n}`);return i}resolveArray(e){return e?e.map(r=>this.resolve(r)):[]}skip(e){var n;return e&&e.some(i=>{var o,s;return(s=(o=this.opts)==null?void 0:o.exclude)==null?void 0:s.includes(i)})?!0:(n=this.opts)!=null&&n.include?!(e&&e.some(o=>{var s;return(s=this.opts.include)==null?void 0:s.includes(o)})):!1}findAvailableRef(e){const r=i=>{try{return this.resolve({$ref:i}),!1}catch(o){return!0}};if(r(e))return e;let n=2;for(;;){const i=e+String(n);if(r(i))return i;n+=1}}getUniqueAlias(e){let r=this.typeAliases[e]||0;return r&&(this.typeAliases[e]=++r,e+=r),this.typeAliases[e]=1,e}getEnumUniqueAlias(e,r){return this.enumRefs[e]&&this.enumRefs[e].values==r?e:this.getUniqueAlias(e)}getRefAlias(e,r,n){var o;const i=n?this.findAvailableRef(e.$ref+"Base"):e.$ref;if(!this.refs[i]){let s=this.resolve(e);typeof s!="boolean"&&n&&(s=O.cloneDeep(s),delete s.discriminator);const f=typeof s!="boolean"&&s.title||pt(i),p=w(f,!0);if(this.isTrueEnum(s,f))return this.getTypeFromSchema(s,f);const d=this.getUniqueAlias(p);this.refs[i]={base:a.createTypeReferenceNode(d,void 0),readOnly:void 0,writeOnly:void 0};const y=this.getTypeFromSchema(s,void 0);this.aliases.push(V({modifiers:[I.export],name:d,type:y}));const{readOnly:g,writeOnly:T}=this.checkSchemaOnlyMode(s);if(g){const S=this.getUniqueAlias(w(f,!0,"readOnly"));this.refs[i].readOnly=a.createTypeReferenceNode(S,void 0);const v=this.getTypeFromSchema(s,f,"readOnly");this.aliases.push(V({modifiers:[I.export],name:S,type:v}))}if(T){const S=this.getUniqueAlias(w(f,!0,"writeOnly"));this.refs[i].writeOnly=a.createTypeReferenceNode(S,void 0);const v=this.getTypeFromSchema(s,f,"writeOnly");this.aliases.push(V({modifiers:[I.export],name:S,type:v}))}}return(o=this.refs[i][r||"base"])!=null?o:this.refs[i].base}getUnionType(e,r,n){if(r){if(r.propertyName===void 0)throw new Error("Discriminators require a propertyName");const i=new Set(Object.values(r.mapping||{}).map(q));return a.createUnionTypeNode([...Object.entries(r.mapping||{}).map(([o,s])=>[o,{$ref:s}]),...e.filter(o=>{if(!N(o))throw new Error("Discriminators require references, not inline schemas");return!i.has(q(o.$ref))}).map(o=>{var y,g;const s=q(o.$ref),p=(y=this.resolve(o).properties)==null?void 0:y[r.propertyName];return[(p&&"enum"in p?(g=p==null?void 0:p.enum)==null?void 0:g[0]:"")||s,o]})].map(([o,s])=>a.createIntersectionTypeNode([a.createTypeLiteralNode([x({name:r.propertyName,type:a.createLiteralTypeNode(a.createStringLiteral(o))})]),this.getTypeFromSchema(s,void 0,n)])))}else return a.createUnionTypeNode(e.map(i=>this.getTypeFromSchema(i,void 0,n)))}getTypeFromSchema(e,r,n){const i=this.getBaseTypeFromSchema(e,r,n);return Ue(e)?a.createUnionTypeNode([i,h.null]):i}getBaseTypeFromSchema(e,r,n){var i;if(!e&&typeof e!="boolean")return h.any;if(N(e))return this.getRefAlias(e,n);if(e===!0)return h.any;if(e===!1)return h.never;if(e.oneOf){const o=X({},e);return delete o.oneOf,this.getUnionType(e.oneOf.map(s=>O.mergeWith({},o,s,(f,p)=>{if(O.isArray(f))return f.concat(p)})),e.discriminator,n)}if(e.anyOf)return this.getUnionType(e.anyOf,void 0,n);if((i=e.discriminator)!=null&&i.mapping){const o=e.discriminator.mapping;return this.getUnionType(Object.values(o).map(s=>({$ref:s})),void 0,n)}if(e.allOf){const o=[];for(const s of e.allOf)if(N(s)&&this.discriminatingSchemas.has(s.$ref)){const p=this.resolve(s).discriminator,d=Object.entries(p.mapping||{}).find(([,y])=>y===e["x-component-ref-path"]);if(d){const[y]=d;o.push(a.createTypeLiteralNode([x({name:p.propertyName,type:a.createLiteralTypeNode(a.createStringLiteral(y))})]))}o.push(this.getRefAlias(s,n,!0))}else o.push(this.getTypeFromSchema(X({required:e.required},s),void 0,n));return(e.properties||e.additionalProperties)&&o.push(this.getTypeFromProperties(e.properties||{},e.required,e.additionalProperties,n)),a.createIntersectionTypeNode(o)}if(Array.isArray(e.type))return a.createUnionTypeNode(e.type.map(o=>{const s=Ke(X({},e),{type:o});return"items"in s&&o!=="array"&&delete s.items,"properties"in s&&o!=="object"&&delete s.properties,this.getBaseTypeFromSchema(s,r,n)}));if("items"in e){const o=e.items;if(o.enum){const s=this.isTrueEnum(o,r)?this.getTrueEnum(o,r):H(o.enum);return a.createArrayTypeNode(s)}return a.createArrayTypeNode(this.getTypeFromSchema(e.items,void 0,n))}return"prefixItems"in e&&e.prefixItems?a.createTupleTypeNode(e.prefixItems.map(o=>this.getTypeFromSchema(o))):e.properties||e.additionalProperties?this.getTypeFromProperties(e.properties||{},e.required,e.additionalProperties,n):e.enum?this.isTrueEnum(e,r)?this.getTrueEnum(e,r):H(e.enum):e.format=="binary"?a.createTypeReferenceNode("Blob",[]):e.const?this.getTypeFromEnum([e.const]):e.type!==void 0?e.type===null?h.null:dt(e.type)?h[e.type]:h.any:h.any}isTrueEnum(e,r){return!!(typeof e!="boolean"&&e.enum&&this.opts.useEnumType&&r&&e.type!=="boolean")}getTypeFromEnum(e){const r=e.map(n=>{if(n===null)return h.null;if(typeof n=="boolean")return n?a.createLiteralTypeNode(u.factory.createToken(u.SyntaxKind.TrueKeyword)):a.createLiteralTypeNode(u.factory.createToken(u.SyntaxKind.FalseKeyword));if(typeof n=="number")return a.createLiteralTypeNode(a.createNumericLiteral(n));if(typeof n=="string")return a.createLiteralTypeNode(a.createStringLiteral(n));throw new Error(`Unexpected ${String(n)} of type ${typeof n} in enum`)});return r.length>1?a.createUnionTypeNode(r):r[0]}getEnumValuesString(e){return e.join("_")}getTrueEnum(e,r){var g;if(typeof e=="boolean")throw new Error("cannot get enum from boolean schema. schema must be an object");const i=(e.title||O.upperFirst(r)).split(/[^A-Za-z0-9$_]/g).map(T=>O.upperFirst(T)).join(""),o=this.getEnumValuesString(e.enum?e.enum:[]),s=this.getEnumUniqueAlias(i,o);if(this.enumRefs[i]&&i===s)return this.enumRefs[i].type;const f=e.enum?e.enum:[],p=(g=e["x-enumNames"])!=null?g:e["x-enum-varnames"];if(p){if(!Array.isArray(p))throw new Error("enum names must be an array");if(p.length!==f.length)throw new Error("enum names must have the same length as enum values")}const d=f.map((T,S)=>{if(e.type==="number"||e.type==="integer"){const v=p?p[S]:String(T);return a.createEnumMember(a.createIdentifier(w(v,!0)),U(T))}return a.createEnumMember(a.createIdentifier(w(T,!0)),U(T))});this.enumAliases.push(a.createEnumDeclaration([I.export],s,d));const y=a.createTypeReferenceNode(s,void 0);return this.enumRefs[i]={values:o,type:a.createTypeReferenceNode(s,void 0)},y}checkSchemaOnlyMode(e,r=!0){if(this.opts.mergeReadWriteOnly)return{readOnly:!1,writeOnly:!1};const n=(i,o)=>{var d,y,g,T,S,v;if(N(i)){if(!r)return{readOnly:!1,writeOnly:!1};if(o.has(i.$ref))return{readOnly:!1,writeOnly:!1};const R=this.refsOnlyMode.get(i.$ref);if(R)return R;o.add(i.$ref);const K=n(this.resolve(i),o);return o.delete(i.$ref),this.refsOnlyMode.set(i.$ref,K),K}if(typeof i=="boolean")return{readOnly:!1,writeOnly:!1};let s=(d=i.readOnly)!=null?d:!1,f=(y=i.writeOnly)!=null?y:!1;const p=[];"items"in i&&i.items?p.push(i.items):(p.push(...Object.values((g=i.properties)!=null?g:{})),p.push(...(T=i.allOf)!=null?T:[]),p.push(...(S=i.anyOf)!=null?S:[]),p.push(...(v=i.oneOf)!=null?v:[]));for(const R of p){if(s&&f)break;const K=n(R,o);s=s||K.readOnly,f=f||K.writeOnly}return{readOnly:s,writeOnly:f}};return n(e,new Set)}getTypeFromProperties(e,r,n,i){const f=Object.keys(e).filter(p=>{const d=e[p],{readOnly:y,writeOnly:g}=this.checkSchemaOnlyMode(d,!1);switch(i){case"readOnly":return y||!g;case"writeOnly":return g||!y;default:return!y&&!g}}).map(p=>{const d=e[p],y=r&&r.includes(p);let g=this.getTypeFromSchema(d,p,i);!y&&this.opts.unionUndefined&&(g=a.createUnionTypeNode([g,h.undefined]));const T=x({questionToken:!y,name:p,type:g});if(typeof d!="boolean"&&"description"in d&&d.description){const S=d.description.replace("*/","*\\/");u.addSyntheticLeadingComment(T,u.SyntaxKind.MultiLineCommentTrivia,`* ${S} `,!0)}return T});if(n){const p=n===!0?h.any:this.getTypeFromSchema(n,void 0,i);f.push(he(p))}return a.createTypeLiteralNode(f)}getTypeFromResponses(e,r){return a.createUnionTypeNode(Object.entries(e).map(([n,i])=>{const o=n==="default"?h.number:a.createLiteralTypeNode(a.createNumericLiteral(n)),s=[x({name:"status",type:o})],f=this.getTypeFromResponse(i,r);return f!==h.void&&s.push(x({name:"data",type:f})),a.createTypeLiteralNode(s)}))}getTypeFromResponse(e,r){const n=this.resolve(e);return!n||!n.content?h.void:this.getTypeFromSchema(this.getSchemaFromContent(n.content),void 0,r)}getResponseType(e){if(!e)return"text";const r=Object.values(e).map(i=>this.resolve(i));return r.some(i=>{var o;return Object.keys((o=i.content)!=null?o:{}).length>0})?r.some(i=>{var s;return Object.keys((s=i.content)!=null?s:{}).some(te)})?"json":r.some(i=>{var o;return Object.keys((o=i.content)!=null?o:[]).some(s=>s.startsWith("text/"))})?"text":"blob":"text"}getSchemaFromContent(e){const r=Object.keys(e).find(Ie);if(r){const{schema:n}=e[r];if(n)return n}return Object.keys(e).length===0||Object.keys(e).some(n=>n.startsWith("text/"))?{type:"string"}:{type:"string",format:"binary"}}getTypeFromParameter(e){if(e.content){const r=this.getSchemaFromContent(e.content);return this.getTypeFromSchema(r)}return this.getTypeFromSchema(N(e)?e:e.schema)}wrapResult(e){var r;return(r=this.opts)!=null&&r.optimistic?z("ok",[e]):e}preprocessComponents(e){const r="#/components/schemas/";for(const i of Object.keys(e)){const o=e[i];N(o)||typeof o=="boolean"||(o["x-component-ref-path"]=r+i,typeof o!="boolean"&&o.discriminator&&!o.oneOf&&!o.anyOf&&this.discriminatingSchemas.add(r+i))}const n=(i,o)=>Object.values(i.mapping||{}).includes(o);for(const i of Object.keys(e)){const o=e[i];if(!(N(o)||typeof o=="boolean"||!o.allOf))for(const s of o.allOf){if(!N(s)||!this.discriminatingSchemas.has(s.$ref))continue;const p=e[q(s.$ref)].discriminator;n(p,r+i)||(p.mapping||(p.mapping={}),p.mapping[i]=r+i)}}}generateApi(){this.reset();const e=u.createSourceFile("ApiStub.ts",`/**
* DO NOT MODIFY - This file has been generated using oazapfts.
* See https://www.npmjs.com/package/oazapfts
*/
import * as Oazapfts from "@oazapfts/runtime";
import * as QS from "@oazapfts/runtime/query";
export const defaults: Oazapfts.Defaults<Oazapfts.CustomHeaders> = {
headers: {},
baseUrl: "/",
};
const oazapfts = Oazapfts.runtime(defaults);
export const servers = {};
`,u.ScriptTarget.Latest,!1,u.ScriptKind.TS),r=ee(e.statements,"servers");Object.assign(r,{initializer:ut(this.spec.servers||[])});const{initializer:n}=ee(e.statements,"defaults");if(!n||!u.isObjectLiteralExpression(n))throw new Error("No object literal: defaults");Se(n,"baseUrl",ke(this.spec.servers||[]));const i=[],o={};return this.spec.paths&&Object.keys(this.spec.paths).forEach(s=>{if(!this.spec.paths)return;const f=this.spec.paths[s];f&&Object.keys(this.resolve(f)).forEach(p=>{var Ae;const d=p.toUpperCase();if(!Le.includes(d))return;const y=f[p],{operationId:g,requestBody:T,responses:S,summary:v,description:R,tags:K}=y;if(this.skip(K))return;let Y=qe(p,s,g);const we=o[Y]=(o[Y]||0)+1;we>1&&(Y+=we);const Z=this.resolveArray(f.parameters);for(const l of this.resolveArray(y.parameters))Z.find(P=>P.name===l.name&&P.in===l.in)||Z.push(l);const C=this.isConverted?Be(Z):Z,se=new Map;O.sortBy(C,"name.length").forEach(l=>{const b=w(l.name),A=[...se.values()].includes(b)?O.upperFirst(l.in):"";se.set(l,b+A)});const k=l=>{const b=se.get(l);if(!b)throw new Error(`Can't find parameter: ${l.name}`);return b},$=[];let L,E;switch((Ae=this.opts.argumentStyle)!=null?Ae:"positional"){case"positional":const[l,b]=O.partition(C,"required"),P=l.map(m=>F(k(this.resolve(m)),{type:this.getTypeFromParameter(m)}));if($.push(...P),T){L=this.resolve(T);const m=this.getSchemaFromContent(L.content),M=this.getTypeFromSchema(m,void 0,"writeOnly");E=w(M.name||ue(m)||"body"),$.push(F(E,{type:M,questionToken:!L.required}))}b.length&&$.push(F(W(b.map(m=>this.resolve(m)).map(m=>({name:k(m)}))),{initializer:a.createObjectLiteralExpression(),type:a.createTypeLiteralNode(b.map(m=>x({name:k(this.resolve(m)),questionToken:!0,type:this.getTypeFromParameter(m)})))}));break;case"object":const A=C.map(m=>x({name:k(this.resolve(m)),questionToken:!m.required,type:this.getTypeFromParameter(m)}));if(T){L=this.resolve(T);const m=this.getSchemaFromContent(L.content),M=this.getTypeFromSchema(m,void 0,"writeOnly");E=w(M.name||ue(m)||"body"),A.push(x({name:E,questionToken:!L.required,type:M}))}if(A.length===0)break;$.push(F(W([...C.map(m=>this.resolve(m)).map(m=>({name:k(m)})),...E?[{name:E}]:[]]),{type:a.createTypeLiteralNode(A)}));break}$.push(F("opts",{type:a.createTypeReferenceNode("Oazapfts.RequestOpts",void 0),questionToken:!0}));const ae=this.getResponseType(S),xe=C.filter(l=>l.in==="query"),ve=C.filter(l=>l.in==="header");let Fe;if(xe.length){const l=O.groupBy(xe,Ce);Fe=pe("query",Object.entries(l).map(([b,P])=>pe(b,[ne(P.map(A=>[A.name,k(A)]))])))}const Ze=De(s,Fe),B=[a.createSpreadAssignment(a.createIdentifier("opts"))];d!=="GET"&&B.push(a.createPropertyAssignment("method",a.createStringLiteral(d))),E&&B.push(Q("body",a.createIdentifier(E))),ve.length&&B.push(a.createPropertyAssignment("headers",z("mergeHeaders",[a.createPropertyAccessChain(a.createIdentifier("opts"),a.createToken(u.SyntaxKind.QuestionDotToken),"headers"),a.createObjectLiteralExpression([...ve.map(l=>Q(l.name,a.createIdentifier(k(l))))],!0)])));const Ee=[Ze];if(B.length){const l=Re(L),b=a.createObjectLiteralExpression(B,!0);Ee.push(l?z(l,[b]):b)}i.push(Oe(me(Y,{modifiers:[I.export]},$,de(a.createReturnStatement(this.wrapResult(z({json:"fetchJson",text:"fetchText",blob:"fetchBlob"}[ae],Ee,ae==="json"||ae==="blob"?[this.getTypeFromResponses(S,"readOnly")||u.SyntaxKind.AnyKeyword]:void 0))))),v||R))})}),Object.assign(e,{statements:be(e.statements,...this.aliases,...i,...this.enumAliases)}),e}}const c=u.factory,le=c.createToken(u.SyntaxKind.QuestionToken);function J(t){if(t)return t===!0?le:t}const h={any:c.createKeywordTypeNode(u.SyntaxKind.AnyKeyword),number:c.createKeywordTypeNode(u.SyntaxKind.NumberKeyword),integer:c.createKeywordTypeNode(u.SyntaxKind.NumberKeyword),object:c.createKeywordTypeNode(u.SyntaxKind.ObjectKeyword),string:c.createKeywordTypeNode(u.SyntaxKind.StringKeyword),boolean:c.createKeywordTypeNode(u.SyntaxKind.BooleanKeyword),undefined:c.createKeywordTypeNode(u.SyntaxKind.UndefinedKeyword),void:c.createKeywordTypeNode(u.SyntaxKind.VoidKeyword),never:c.createKeywordTypeNode(u.SyntaxKind.NeverKeyword),null:c.createLiteralTypeNode(c.createNull())};function Me(t){return h[t]}const I={async:c.createModifier(u.SyntaxKind.AsyncKeyword),export:c.createModifier(u.SyntaxKind.ExportKeyword)};function U(t){switch(typeof t){case"string":return c.createStringLiteral(t);case"boolean":return t?c.createTrue():c.createFalse();case"number":return String(t).charAt(0)==="-"?c.createPrefixUnaryExpression(u.SyntaxKind.MinusToken,c.createNumericLiteral(String(-t))):c.createNumericLiteral(String(t))}}function H(t){const e=t.map(r=>r===null?h.null:c.createLiteralTypeNode(U(r)));return e.length>1?c.createUnionTypeNode(e):e[0]}function V({modifiers:t,name:e,typeParameters:r,type:n}){return c.createTypeAliasDeclaration(t,e,r,n)}function ze({modifiers:t,name:e,typeParameters:r,type:n,inheritedNodeNames:i}){const o=i?[c.createHeritageClause(u.SyntaxKind.ExtendsKeyword,i.map(s=>{const f=typeof s=="string"?s:s.escapedText.toString();return c.createExpressionWithTypeArguments(c.createIdentifier(w(f,!0)),void 0)}))]:[];return c.createInterfaceDeclaration(t,e,r,o,n.members)}function re(t){return typeof t=="string"?c.createIdentifier(t):t}function D(t,{typeArgs:e,args:r}={}){return c.createCallExpression(re(t),e,r)}function Ve(t,e){return D(c.createPropertyAccessExpression(c.createThis(),t),e)}function ne(t){return c.createObjectLiteralExpression(t.map(([e,r])=>Q(e,re(r))),!0)}function Q(t,e){return u.isIdentifier(e)&&e.text===t?c.createShorthandPropertyAssignment(t):c.createPropertyAssignment(We(t),e)}function de(...t){return c.createBlock(t,!0)}function ye(t,e,{modifiers:r,typeParameters:n,type:i,equalsGreaterThanToken:o}={}){return c.createArrowFunction(r,n,t,i,o,e)}function me(t,{modifiers:e,asteriskToken:r,typeParameters:n,type:i},o,s){return c.createFunctionDeclaration(e,r,t,n,o,i,s)}function _e({modifiers:t,name:e,typeParameters:r,heritageClauses:n,members:i}){return c.createClassDeclaration(t,e,r,n,i)}function He({modifiers:t,parameters:e,body:r}){return c.createConstructorDeclaration(t,e,r)}function Qe(t,{modifiers:e,asteriskToken:r,questionToken:n,typeParameters:i,type:o}={},s=[],f){return c.createMethodDeclaration(e,r,t,J(n),i,s,o,f)}function F(t,{modifiers:e,dotDotDotToken:r,questionToken:n,type:i,initializer:o}){return c.createParameterDeclaration(e,r,t,J(n),i,o)}function We(t){return typeof t=="string"?G(t)?c.createIdentifier(t):c.createStringLiteral(t):t}function x({modifiers:t,name:e,questionToken:r,type:n}){return c.createPropertySignature(t,We(e),J(r),n)}function he(t,{modifiers:e,indexName:r="key",indexType:n=h.string}={}){return c.createIndexSignature(e,[F(r,{type:n})],t)}function W(t){return c.createObjectBindingPattern(t.map(({dotDotDotToken:e,propertyName:r,name:n,initializer:i})=>c.createBindingElement(e,r,n,i)))}function ie(t,e){return e.length?c.createTemplateExpression(c.createTemplateHead(t),e.map(({expression:r,literal:n},i)=>c.createTemplateSpan(r,i===e.length-1?c.createTemplateTail(n):c.createTemplateMiddle(n)))):c.createStringLiteral(t)}function ge(t,e,r){const n=t.find(i=>i.kind===e&&(!r||r(i)));if(!n)throw new Error(`Node not found: ${e}`);return n}function oe(t){return u.isIdentifier(t)?t.escapedText:u.isLiteralExpression(t)?t.text:""}function Te(t){const e=u.getNameOfDeclaration(t.declarationList.declarations[0]);return e?oe(e):""}function ee(t,e){const r=ge(t,u.SyntaxKind.VariableStatement,i=>Te(i)===e),[n]=r.declarationList.declarations;if(!n)throw new Error("Missing declaration");return n}function Se(t,e,r){const n=t.properties.find(i=>u.isPropertyAssignment(i)&&oe(i.name)===e);if(n&&u.isPropertyAssignment(n))Object.assign(n,{initializer:r});else throw new Error(`No such property: ${e}`)}function be(t,...e){return c.createNodeArray([...t,...e])}function Oe(t,e){return e?u.addSyntheticLeadingComment(t,u.SyntaxKind.MultiLineCommentTrivia,`*
* ${e.replace(/\n/g,`
* `)}
`,!0):t}const Ne=u.createPrinter({newLine:u.NewLineKind.LineFeed});function Je(t){const e=u.createSourceFile("someFileName.ts","",u.ScriptTarget.Latest,!1,u.ScriptKind.TS);return Ne.printNode(u.EmitHint.Unspecified,t,e)}function Ge(t){const e=u.createSourceFile("someFileName.ts","",u.ScriptTarget.Latest,!1,u.ScriptKind.TS);return t.map(r=>Ne.printNode(u.EmitHint.Unspecified,r,e)).join(`
`)}function Ye(t){return Ne.printFile(t)}function G(t){if(!t.length||t.trim()!==t)return!1;const e=u.parseIsolatedEntityName(t,u.ScriptTarget.Latest);return!!e&&e.kind===u.SyntaxKind.Identifier&&u.identifierToKeywordKind(e)===void 0}const mt=Object.freeze(Object.defineProperty({__proto__:null,addComment:Oe,appendNodes:be,block:de,changePropertyValue:Se,createArrowFunction:ye,createCall:D,createClassDeclaration:_e,createConstructor:He,createEnumTypeNode:H,createFunctionDeclaration:me,createIndexSignature:he,createInterfaceAliasDeclaration:ze,createKeywordType:Me,createLiteral:U,createMethod:Qe,createMethodCall:Ve,createObjectBinding:W,createObjectLiteral:ne,createParameter:F,createPropertyAssignment:Q,createPropertySignature:x,createQuestionToken:J,createTemplateString:ie,createTypeAliasDeclaration:V,findFirstVariableDeclaration:ee,findNode:ge,getFirstDeclarationName:Te,getName:oe,isValidIdentifier:G,keywordType:h,modifier:I,printFile:Ye,printNode:Je,printNodes:Ge,questionToken:le,toExpression:re},Symbol.toStringTag,{value:"Module"}));exports.ApiGenerator=yt;exports.addComment=Oe;exports.appendNodes=be;exports.block=de;exports.callOazapftsFunction=z;exports.callQsFunction=pe;exports.changePropertyValue=Se;exports.createArrowFunction=ye;exports.createCall=D;exports.createClassDeclaration=_e;exports.createConstructor=He;exports.createEnumTypeNode=H;exports.createFunctionDeclaration=me;exports.createIndexSignature=he;exports.createInterfaceAliasDeclaration=ze;exports.createKeywordType=Me;exports.createLiteral=U;exports.createMethod=Qe;exports.createMethodCall=Ve;exports.createObjectBinding=W;exports.createObjectLiteral=ne;exports.createParameter=F;exports.createPropertyAssignment=Q;exports.createPropertySignature=x;exports.createQuestionToken=J;exports.createTemplateString=ie;exports.createTypeAliasDeclaration=V;exports.createUrlExpression=De;exports.defaultBaseUrl=ke;exports.findFirstVariableDeclaration=ee;exports.findNode=ge;exports.getBodyFormatter=Re;exports.getFirstDeclarationName=Te;exports.getFormatter=Ce;exports.getName=oe;exports.getOperationIdentifier=$e;exports.getOperationName=qe;exports.getReferenceName=ue;exports.isJsonMimeType=te;exports.isMimeType=Ie;exports.isNullable=Ue;exports.isReference=N;exports.isValidIdentifier=G;exports.keywordType=h;exports.modifier=I;exports.printFile=Ye;exports.printNode=Je;exports.printNodes=Ge;exports.questionToken=le;exports.refPathToPropertyPath=fe;exports.supportDeepObjects=Be;exports.toExpression=re;exports.toIdentifier=w;exports.tscodegen=mt;exports.verbs=Le;
//# sourceMappingURL=tscodegen-DV-Rd5p1.cjs.map