@bitstack/ng-query-codegen-openapi 0.0.38-alpha.3 → 0.0.38-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/bin/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- var I=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Ne=Object.prototype.hasOwnProperty;var Q=(r,t)=>()=>(r&&(t=r(r=0)),t);var Ae=(r,t)=>{for(var e in t)I(r,e,{get:t[e],enumerable:!0})},Ee=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $e(t))!Ne.call(r,o)&&o!==e&&I(r,o,{get:()=>t[o],enumerable:!(n=Pe(t,o))||n.enumerable});return r};var Re=r=>Ee(I({},"__esModule",{value:!0}),r);import{fileURLToPath as Se}from"node:url";var qe,l,c=Q(()=>{"use strict";qe=()=>Se(import.meta.url),l=qe()});var ne={};Ae(ne,{argumentMatches:()=>Ue,defaultIsDataResponse:()=>ke,getOperationName:()=>E,getOverrides:()=>D,getTags:()=>Ve,operationMatches:()=>re});import{getOperationName as Me}from"oazapfts/generate";function ke(r,t){if(t&&r==="default")return!0;let e=Number(r);return!Number.isNaN(e)&&e>=200&&e<300}function E({verb:r,path:t}){return Me(r,t,void 0)}function Ve({verb:r,pathItem:t}){return r?t[r]?.tags||[]:[]}function te(r){let t=Array.isArray(r)?r:[r];return function(n){return r?t.some(o=>typeof o=="string"?o===n:o?.test(n)):!0}}function re(r){let t=typeof r=="function"?r:te(r);return function(n){if(!r)return!0;let o=E(n);return t(o,n)}}function Ue(r){let t=typeof r=="function"?r:te(r);return function(n){if(!r||n.in==="path")return!0;let o=n.name;return t(o,n)}}function D(r,t){return t?.find(e=>re(e.pattern)(r))}var K=Q(()=>{"use strict";c()});c();import j from"commander";import{createRequire as Je}from"node:module";c();import Fe from"commander";import{createRequire as we}from"node:module";import{resolve as M}from"node:path";import{existsSync as je,rmSync as Ie,readdirSync as ut,statSync as mt,mkdirSync as lt}from"node:fs";var x=we(l);function k(r){let t=["/","/usr","/etc","/var","/home","/Users",".",".."],e=M(r);t.some(n=>e===M(n))&&(console.error(`Dangerous path detected: ${e}. Refusing to delete.`),process.exit(1)),je(r)&&(console.log(`Cleaning output directory: ${r}`),Ie(r,{recursive:!0,force:!0}),console.log(`Directory cleaned: ${r}`))}function V(){try{if(x.resolve("esbuild")&&x.resolve("esbuild-runner"))return x("esbuild-runner/register"),!0}catch{}try{if(x.resolve("typescript")&&x.resolve("ts-node"))return x("ts-node").register({transpileOnly:!0,compilerOptions:{target:"es6",module:"commonjs"}}),!0}catch{}return!1}function U(r){(!r||!/\.([mc]?(jsx?|tsx?)|jsonc?)?$/.test(r))&&(console.error("Please provide a valid configuration file."),Fe.help())}function W(r,t){/\.[mc]?tsx?$/.test(r)&&!t&&(console.error("Encountered a TypeScript config file, but neither esbuild-runner nor ts-node are installed."),process.exit(1))}import{dirname as Xe,resolve as et}from"node:path";c();c();import F from"node:path";import fe from"typescript";c();c();function P(r){return r.replace(r[0],r[0].toUpperCase())}c();import G from"node:fs";import Ge from"node:path";c();function _(r){try{new URL(r)}catch{return!1}return!0}async function B(r,t){if(!_(r))throw new Error(`remoteFile must be a valid URL: ${r}`);try{let e=Ge.dirname(t);G.existsSync(e)||await G.promises.mkdir(e,{recursive:!0});let n=await fetch(r);if(!n.ok)throw new Error(`Failed to download schema from ${r}: ${n.statusText}`);let o=await n.text();return await G.promises.writeFile(t,o,"utf-8"),console.log(`Schema downloaded from ${r} to ${t}`),t}catch(e){throw console.error(`Error downloading schema from ${r}:`,e),e}}c();c();var z=["get","put","post","delete","options","head","patch","trace"];function L(r){return Object.entries(r.paths).flatMap(([t,e])=>e?Object.entries(e).filter(n=>z.includes(n[0])).map(([n,o])=>({path:t,verb:n,pathItem:e,operation:o})):[])}c();import De from"@apidevtools/swagger-parser";import Ke from"swagger2openapi";async function H(r,t){let e=await De.bundle(r,{resolve:{http:t}});return"openapi"in e&&e.openapi.startsWith("3")?e:(await Ke.convertObj(e,{})).openapi}c();function Z(r,t,e,n){return n?n(r,t):e?.type?e.type==="query":r==="get"}var $=class{docCache={};async getDocument(t,e){if(this.docCache[t])return this.docCache[t];let n=await H(t,e);return this.docCache[t]=n,n}async downloadSchema(t,e){return B(t,e)}getPaths(t){return Object.keys(t.paths||{})}clearCache(){this.docCache={}}};c();import Y from"lodash.camelcase";var N=class{groupPaths(t,e){let{groupKeyMatch:n,outputDir:o}=e,s=t.reduce((p,u)=>{let i=n(u),m=i?Y(i):"_common";return p[m]||(p[m]=[]),p[m].push(u),p},{}),a={};for(let[p,u]of Object.entries(s))a[p]={groupKey:p,paths:u,outputPath:`${o}/${p}/query.service.ts`};return a}createGroupFilter(t,e){return(n,o)=>{let s=o.path,a=Y(e.groupKeyMatch(s)||"");return a!==t&&(a||"_common")!==t?!1:e.filterEndpoint?e.filterEndpoint(n,s,t):!0}}};c();import ee from"node:fs";import d from"node:path";c();import Qe from"node:path";import J from"node:fs";async function X(r){let t=Qe.dirname(r);J.existsSync(t)||await J.promises.mkdir(t,{recursive:!0})}var A=class{async writeFile(t,e){try{let n=d.resolve(process.cwd(),t);return d.basename(n)==="enhanceEndpoints.ts"&&ee.existsSync(n)?{path:n,success:!0}:(await X(n),ee.writeFileSync(n,e),{path:n,success:!0})}catch(n){return{path:t,success:!1,error:n}}}async writeFiles(t){let e=[];for(let[n,o]of Object.entries(t)){let s=await this.writeFile(n,o);e.push(s)}return e}async writeGroupFiles(t,e){let n={};return e.types&&(n[d.join(t,"types.ts")]=e.types),e.queryService&&(n[d.join(t,"query.generated.ts")]=e.queryService),e.enhanceEndpoints&&(n[d.join(t,"enhanceEndpoints.ts")]=e.enhanceEndpoints),e.index&&(n[d.join(t,"index.ts")]=e.index),this.writeFiles(n)}async writeSharedFiles(t,e){let n={};return e.commonTypes&&(n[d.join(t,"common-types.ts")]=e.commonTypes),e.tagTypes&&(n[d.join(t,"tagTypes.ts")]=e.tagTypes),e.doNotModify&&(n[d.join(t,"DO_NOT_MODIFY.md")]=e.doNotModify),e.utils&&(n[d.join(t,"utils.ts")]=e.utils),this.writeFiles(n)}async writeSchemaFile(t,e){let n={};return n[d.join(t,"schema.ts")]=e,this.writeFiles(n)}};c();import We from"oazapfts/generate";var R=class{constructor(t,e){this.v3Doc=t;this.apiGen=new We(t,{unionUndefined:e.unionUndefined,mergeReadWriteOnly:e.mergeReadWriteOnly})}apiGen;initialize(){this.apiGen.spec.components?.schemas&&(Object.keys(this.apiGen.spec.components.schemas).forEach(t=>{let e=this.apiGen.spec.components.schemas[t];e&&typeof e=="object"&&"title"in e&&delete e.title}),this.apiGen.preprocessComponents(this.apiGen.spec.components.schemas),Object.keys(this.apiGen.spec.components.schemas).forEach(t=>{try{this.apiGen.getRefAlias({$ref:`#/components/schemas/${t}`})}catch{}}))}getOperationDefinitions(t){let{operationMatches:e}=(K(),Re(ne));return L(this.v3Doc).filter(e(t))}getApiGenerator(){return this.apiGen}getDocument(){return this.v3Doc}getSchemaTypeNames(){return new Set}};c();function oe(){return`/* eslint-disable */
2
+ var G=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var Re=Object.prototype.hasOwnProperty;var M=(r,t)=>()=>(r&&(t=r(r=0)),t);var Ee=(r,t)=>{for(var e in t)G(r,e,{get:t[e],enumerable:!0})},Ae=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ne(t))!Re.call(r,o)&&o!==e&&G(r,o,{get:()=>t[o],enumerable:!(n=$e(t,o))||n.enumerable});return r};var Se=r=>Ae(G({},"__esModule",{value:!0}),r);import{fileURLToPath as qe}from"node:url";var Fe,l,c=M(()=>{"use strict";Fe=()=>qe(import.meta.url),l=Fe()});var oe={};Ee(oe,{argumentMatches:()=>Be,defaultIsDataResponse:()=>Ve,getOperationName:()=>A,getOverrides:()=>K,getTags:()=>Ue,operationMatches:()=>ne});import{getOperationName as ke}from"oazapfts/generate";function Ve(r,t){if(t&&r==="default")return!0;let e=Number(r);return!Number.isNaN(e)&&e>=200&&e<300}function A({verb:r,path:t}){return ke(r,t,void 0)}function Ue({verb:r,pathItem:t}){return r?t[r]?.tags||[]:[]}function re(r){let t=Array.isArray(r)?r:[r];return function(n){return r?t.some(o=>typeof o=="string"?o===n:o?.test(n)):!0}}function ne(r){let t=typeof r=="function"?r:re(r);return function(n){if(!r)return!0;let o=A(n);return t(o,n)}}function Be(r){let t=typeof r=="function"?r:re(r);return function(n){if(!r||n.in==="path")return!0;let o=n.name;return t(o,n)}}function K(r,t){return t?.find(e=>ne(e.pattern)(r))}var Q=M(()=>{"use strict";c()});c();import I from"commander";import{createRequire as Xe}from"node:module";c();import we from"commander";import{createRequire as je}from"node:module";import{resolve as k}from"node:path";import{existsSync as Ie,rmSync as Ge,readdirSync as mt,statSync as lt,mkdirSync as yt}from"node:fs";var T=je(l);function V(r){let t=["/","/usr","/etc","/var","/home","/Users",".",".."],e=k(r);t.some(n=>e===k(n))&&(console.error(`Dangerous path detected: ${e}. Refusing to delete.`),process.exit(1)),Ie(r)&&(console.log(`Cleaning output directory: ${r}`),Ge(r,{recursive:!0,force:!0}),console.log(`Directory cleaned: ${r}`))}function U(){try{if(T.resolve("esbuild")&&T.resolve("esbuild-runner"))return T("esbuild-runner/register"),!0}catch{}try{if(T.resolve("typescript")&&T.resolve("ts-node"))return T("ts-node").register({transpileOnly:!0,compilerOptions:{target:"es6",module:"commonjs"}}),!0}catch{}return!1}function B(r){(!r||!/\.([mc]?(jsx?|tsx?)|jsonc?)?$/.test(r))&&(console.error("Please provide a valid configuration file."),we.help())}function W(r,t){/\.[mc]?tsx?$/.test(r)&&!t&&(console.error("Encountered a TypeScript config file, but neither esbuild-runner nor ts-node are installed."),process.exit(1))}import{dirname as et,resolve as tt}from"node:path";c();c();import w from"node:path";import de from"typescript";c();c();function $(r){return r.replace(r[0],r[0].toUpperCase())}c();import D from"node:fs";import De from"node:path";c();function _(r){try{new URL(r)}catch{return!1}return!0}async function z(r,t){if(!_(r))throw new Error(`remoteFile must be a valid URL: ${r}`);try{let e=De.dirname(t);D.existsSync(e)||await D.promises.mkdir(e,{recursive:!0});let n=await fetch(r);if(!n.ok)throw new Error(`Failed to download schema from ${r}: ${n.statusText}`);let o=await n.text();return await D.promises.writeFile(t,o,"utf-8"),console.log(`Schema downloaded from ${r} to ${t}`),t}catch(e){throw console.error(`Error downloading schema from ${r}:`,e),e}}c();c();var L=["get","put","post","delete","options","head","patch","trace"];function H(r){return Object.entries(r.paths).flatMap(([t,e])=>e?Object.entries(e).filter(n=>L.includes(n[0])).map(([n,o])=>({path:t,verb:n,pathItem:e,operation:o})):[])}c();import Ke from"@apidevtools/swagger-parser";import Qe from"swagger2openapi";async function Z(r,t){let e=await Ke.bundle(r,{resolve:{http:t}});return"openapi"in e&&e.openapi.startsWith("3")?e:(await Qe.convertObj(e,{})).openapi}c();function Y(r,t,e,n){return n?n(r,t):e?.type?e.type==="query":r==="get"}var N=class{docCache={};async getDocument(t,e){if(this.docCache[t])return this.docCache[t];let n=await Z(t,e);return this.docCache[t]=n,n}async downloadSchema(t,e){return z(t,e)}getPaths(t){return Object.keys(t.paths||{})}clearCache(){this.docCache={}}};c();import J from"lodash.camelcase";var R=class{groupPaths(t,e){let{groupKeyMatch:n,outputDir:o}=e,a=t.reduce((p,u)=>{let s=n(u),m=s?J(s):"_common";return p[m]||(p[m]=[]),p[m].push(u),p},{}),i={};for(let[p,u]of Object.entries(a))i[p]={groupKey:p,paths:u,outputPath:`${o}/${p}/query.service.ts`};return i}createGroupFilter(t,e){return(n,o)=>{let a=o.path,i=J(e.groupKeyMatch(a)||"");return i!==t&&(i||"_common")!==t?!1:e.filterEndpoint?e.filterEndpoint(n,a,t):!0}}};c();import te from"node:fs";import h from"node:path";c();import Me from"node:path";import X from"node:fs";async function ee(r){let t=Me.dirname(r);X.existsSync(t)||await X.promises.mkdir(t,{recursive:!0})}var E=class{async writeFile(t,e){try{let n=h.resolve(process.cwd(),t);return h.basename(n)==="enhanceEndpoints.ts"&&te.existsSync(n)?{path:n,success:!0}:(await ee(n),te.writeFileSync(n,e),{path:n,success:!0})}catch(n){return{path:t,success:!1,error:n}}}async writeFiles(t){let e=[];for(let[n,o]of Object.entries(t)){let a=await this.writeFile(n,o);e.push(a)}return e}async writeGroupFiles(t,e){let n={};return e.types&&(n[h.join(t,"types.ts")]=e.types),e.queryService&&(n[h.join(t,"query.generated.ts")]=e.queryService),e.enhanceEndpoints&&(n[h.join(t,"enhanceEndpoints.ts")]=e.enhanceEndpoints),e.index&&(n[h.join(t,"index.ts")]=e.index),this.writeFiles(n)}async writeSharedFiles(t,e){let n={};return e.commonTypes&&(n[h.join(t,"common-types.ts")]=e.commonTypes),e.tagTypes&&(n[h.join(t,"tagTypes.ts")]=e.tagTypes),e.doNotModify&&(n[h.join(t,"DO_NOT_MODIFY.md")]=e.doNotModify),e.utils&&(n[h.join(t,"utils.ts")]=e.utils),this.writeFiles(n)}async writeSchemaFile(t,e){let n={};return n[h.join(t,"schema.ts")]=e,this.writeFiles(n)}};c();import We from"oazapfts/generate";var S=class{constructor(t,e){this.v3Doc=t;this.apiGen=new We(t,{unionUndefined:e.unionUndefined,mergeReadWriteOnly:e.mergeReadWriteOnly})}apiGen;initialize(){this.apiGen.spec.components?.schemas&&(Object.keys(this.apiGen.spec.components.schemas).forEach(t=>{let e=this.apiGen.spec.components.schemas[t];e&&typeof e=="object"&&"title"in e&&delete e.title}),this.apiGen.preprocessComponents(this.apiGen.spec.components.schemas),Object.keys(this.apiGen.spec.components.schemas).forEach(t=>{try{this.apiGen.getRefAlias({$ref:`#/components/schemas/${t}`})}catch{}}))}getOperationDefinitions(t){let{operationMatches:e}=(Q(),Se(oe));return H(this.v3Doc).filter(e(t))}getApiGenerator(){return this.apiGen}getDocument(){return this.v3Doc}getSchemaTypeNames(){return new Set}};c();function ie(){return`/* eslint-disable */
3
3
  // [Warning] Generated automatically - do not edit manually
4
4
 
5
5
  export interface RequestOptions {
@@ -28,12 +28,12 @@ export type IRestFulEndpointsQueryReturn<TVariables> = TVariables extends void ?
28
28
  fetchOptions?: IRequestConfig;
29
29
  config?: QueryConfig;
30
30
  };
31
- `}c();import h from"typescript";function _e(r){return r.charAt(0).toUpperCase()+r.slice(1)}function Be(r,t,e){return h.transform(r,[n=>o=>h.visitNode(o,function s(a){return h.isIdentifier(a)&&a.text===t?h.factory.createIdentifier(e):h.visitEachChild(a,s,n)})]).transformed[0]}function ie(r){let t=h.createPrinter({newLine:h.NewLineKind.LineFeed}),e=h.createSourceFile("component-schema.ts","",h.ScriptTarget.Latest,!1,h.ScriptKind.TS),n=[],o={};return Object.entries(r).forEach(([s,a])=>{let p=_e(s);o[s]=p;let u=Be(a,s,p),i=t.printNode(h.EmitHint.Unspecified,u,e);n.push(i)}),`/* eslint-disable */
31
+ `}c();import b from"typescript";function _e(r){return r.charAt(0).toUpperCase()+r.slice(1)}function ze(r,t,e){return b.transform(r,[n=>o=>b.visitNode(o,function a(i){return b.isIdentifier(i)&&i.text===t?b.factory.createIdentifier(e):b.visitEachChild(i,a,n)})]).transformed[0]}function se(r){let t=b.createPrinter({newLine:b.NewLineKind.LineFeed}),e=b.createSourceFile("component-schema.ts","",b.ScriptTarget.Latest,!1,b.ScriptKind.TS),n=[],o={};return Object.entries(r).forEach(([a,i])=>{let p=_e(a);o[a]=p;let u=ze(i,a,p),s=t.printNode(b.EmitHint.Unspecified,u,e);n.push(s)}),`/* eslint-disable */
32
32
  // [Warning] Generated automatically - do not edit manually
33
33
 
34
34
  ${n.join(`
35
35
  `)}
36
- `}c();function se(){return`# \u8ACB\u52FF\u4FEE\u6539\u6B64\u8CC7\u6599\u593E
36
+ `}c();function ae(){return`# \u8ACB\u52FF\u4FEE\u6539\u6B64\u8CC7\u6599\u593E
37
37
 
38
38
  \u26A0\uFE0F **\u91CD\u8981\u63D0\u9192\uFF1A\u8ACB\u52FF\u4FEE\u6539\u6B64\u8CC7\u6599\u593E\u4E2D\u7684\u4EFB\u4F55\u6A94\u6848**
39
39
 
@@ -52,58 +52,59 @@ ${n.join(`
52
52
  \u9019\u4E9B\u6A94\u6848\u662F\u7531 @bitstack/ng-query-codegen-openapi \u7522\u751F\u5668\u6240\u5EFA\u7ACB\u3002
53
53
 
54
54
  \u5982\u6709\u7591\u554F\uFF0C\u8ACB\u53C3\u8003\u5C08\u6848\u6587\u4EF6\u6216\u806F\u7E6B\u958B\u767C\u5718\u968A\u3002
55
- `}c();import me from"typescript";c();K();import{supportDeepObjects as ze}from"oazapfts/generate";var S=class{constructor(t){this.options=t}extractEndpointInfos(t){return t.map(e=>this.extractSingleEndpointInfo(e))}extractSingleEndpointInfo(t){let{verb:e,path:n,operation:o}=t,{operationNameSuffix:s="",argSuffix:a="Req",responseSuffix:p="Res",queryMatch:u,endpointOverrides:i}=this.options,m=E({verb:e,path:n}),g=s?P(m+s):m,f=P(m+s+a),T=P(m+s+p),v=Z(e,n,D(t,i),u),C=`${m.replace(/([A-Z])/g,"_$1").toUpperCase()}`,b=o.summary||`${e.toUpperCase()} ${n}`,{queryParams:Oe,pathParams:ve,isVoidArg:be,hasRequestBody:xe}=this.extractParameters(t),Te=this.extractContentType(o),Ce=Array.isArray(o.tags)?o.tags:[];return{operationName:g,argTypeName:f,responseTypeName:T,isQuery:v,verb:e.toUpperCase(),path:n,queryKeyName:C,queryParams:Oe,pathParams:ve,isVoidArg:be,summary:b,contentType:Te,hasRequestBody:xe,tags:Ce}}extractParameters(t){let{operation:e,pathItem:n}=t,o=this.resolveArray(e.parameters),s=this.resolveArray(n.parameters).filter(g=>!o.some(f=>f.name===g.name&&f.in===g.in)),a=ze([...s,...o]).filter(g=>g.in!=="header"),p=a.filter(g=>g.in==="query"),u=a.filter(g=>g.in==="path"),i=!!e.requestBody,m=p.length===0&&u.length===0&&!e.requestBody;return{queryParams:p,pathParams:u,isVoidArg:m,hasRequestBody:i}}resolveArray(t){return t?Array.isArray(t)?t:[t]:[]}extractContentType(t){if(!t.requestBody)return"application/json";let e=t.requestBody.content;if(!e||typeof e!="object")return"application/json";let n=Object.keys(e);return n.length===0?"application/json":n[0]}};c();var Le=r=>r.charAt(0).toUpperCase()+r.slice(1);function pe(r,t,e,n){let o={};e&&Object.keys(e).forEach(i=>{if(o[i]=i,i.endsWith("Vo")){let m=i.slice(0,-2)+"VO";o[m]=i}if(i.endsWith("Dto")){let m=i.slice(0,-3)+"DTO";o[m]=i}});let s=`/* eslint-disable */
56
- // [Warning] Generated automatically - do not edit manually
57
-
58
- `;e&&Object.keys(e).length>0&&(s+=`import * as Schema from "../schema";
59
- `),s+=`
60
- `;let p=[],u=[];return r.forEach(i=>{let m=i.argTypeName,g=i.responseTypeName;if(m){let f=He(i,n,o);f.trim()===""?u.push(`export type ${m} = void;`,""):u.push(`export type ${m} = {`,f,"};","")}if(g){let f=Ze(i,n,o);f.trim()===""?u.push(`export type ${g} = void;`,""):u.push(`export type ${g} = {`,f,"};","")}}),u.length>0&&p.push(u.join(`
61
- `)),p.length===0&&p.push("// \u6B64\u6A94\u6848\u7528\u65BC\u5B9A\u7FA9 API \u76F8\u95DC\u7684\u985E\u578B","// \u985E\u578B\u5B9A\u7FA9\u6703\u6839\u64DA OpenAPI Schema \u81EA\u52D5\u751F\u6210",""),s+p.join(`
62
-
63
- `)}function He(r,t,e={}){let n=[];r.queryParams&&r.queryParams.length>0&&r.queryParams.forEach(s=>{let a=s.required?"":"?",p=ae(s,e);n.push(` ${s.name}${a}: ${p};`)}),r.pathParams&&r.pathParams.length>0&&r.pathParams.forEach(s=>{let a=s.required?"":"?",p=ae(s,e);n.push(` ${s.name}${a}: ${p};`)});let o=t?.find(s=>s.operation?.operationId===r.operationName||s.operation?.operationId===r.operationName.toLowerCase()||s.verb===r.verb.toLowerCase()&&s.path===r.path);if(o?.operation?.requestBody){let a=o.operation.requestBody.content,p=a["application/json"]||a["*/*"],u=a["multipart/form-data"]||a["application/x-www-form-urlencoded"];if(p?.schema){let i=O(p.schema,e,1);n.push(` body: ${i};`)}else if(u?.schema){let i=O(u.schema,e,1);n.push(` body: ${i};`)}else{let i=Object.values(a)[0];if(i?.schema){let m=O(i.schema,e,1);n.push(` body: ${m};`)}else n.push(" body?: any; // Request body from OpenAPI")}}return n.length===0?"":n.join(`
64
- `)}function Ze(r,t,e={}){let n=[],o=t?.find(s=>s.operation?.operationId===r.operationName||s.operation?.operationId===r.operationName.toLowerCase()||s.verb===r.verb.toLowerCase()&&s.path===r.path);if(o?.operation?.responses){let s=o.operation.responses[200]||o.operation.responses[201];if(s?.content){let a=s.content["application/json"]||s.content["*/*"]||Object.values(s.content)[0];if(a?.schema){let p=Ye(a.schema,e);n.push(...p)}else n.push(" // Success response from OpenAPI"),n.push(" data?: any;")}}return n.length===0?"":n.join(`
65
- `)}function Ye(r,t={}){let e=[];if(r.type==="object"&&r.properties){let n=r.required||[];Object.entries(r.properties).forEach(([o,s])=>{let p=n.includes(o)?"":"?",u=O(s,t,1),m=/[^a-zA-Z0-9_$]/.test(o)?`"${o}"`:o;(s.title||s.description)&&e.push(` /** ${s.title??""} ${s.description??""}*/`),e.push(` ${m}${p}: ${u};`)})}return e}function O(r,t={},e=0){if(!r)return"any";if(r.$ref){let o=r.$ref;if(o.startsWith("#/components/schemas/")){let s=o.replace("#/components/schemas/",""),a=t[s]||s,u=`Schema.${Le(a)}`;return r.nullable?`${u} | null`:u}}if(r.oneOf||r.anyOf){let a=(r.oneOf||r.anyOf).map(p=>O(p,t,e)).join(" | ");return r.nullable?`${a} | null`:a}if(r.allOf){let s=r.allOf.map(a=>O(a,t,e)).join(" & ");return r.nullable?`(${s}) | null`:s}let n;switch(r.type){case"string":r.enum?n=r.enum.map(a=>`"${a}"`).join(" | "):r.format==="binary"?n="Blob":n="string";break;case"number":case"integer":n="number";break;case"boolean":n="boolean";break;case"array":let o=r.items?O(r.items,t,e):"any";n=o.includes("|")?`(${o})[]`:`${o}[]`;break;case"object":if(r.properties){let a=Object.entries(r.properties);if(a.length===0)r.additionalProperties?n=`Record<string, ${r.additionalProperties===!0?"any":O(r.additionalProperties,t,e)}>`:n="{}";else{let p=" ".repeat(e+1),u=" ".repeat(e),i=[];a.forEach(([m,g])=>{let T=(r.required||[]).includes(m)?"":"?",v=O(g,t,e+1),b=/[^a-zA-Z0-9_$]/.test(m)?`"${m}"`:m;(g.title||g.description)&&i.push(`${p}/** ${g.title??""} ${g.description??""}*/`),i.push(`${p}${b}${T}: ${v};`)}),n=`{
66
- ${i.join(`
55
+ `}c();import le from"typescript";c();Q();import{supportDeepObjects as Le}from"oazapfts/generate";var q=class{constructor(t){this.options=t}extractEndpointInfos(t){return t.map(e=>this.extractSingleEndpointInfo(e))}extractSingleEndpointInfo(t){let{verb:e,path:n,operation:o}=t,{operationNameSuffix:a="",argSuffix:i="Req",responseSuffix:p="Res",queryMatch:u,endpointOverrides:s}=this.options,m=A({verb:e,path:n}),g=a?$(m+a):m,f=$(m+a+i),d=$(m+a+p),v=Y(e,n,K(t,s),u),x=`${m.replace(/([A-Z])/g,"_$1").toUpperCase()}`,C=o.summary||`${e.toUpperCase()} ${n}`,{queryParams:P,pathParams:Oe,isVoidArg:ve,hasRequestBody:Te}=this.extractParameters(t),xe=this.extractContentType(o),Ce=Array.isArray(o.tags)?o.tags:[],Pe=this.isBlobResponseEndpoint(o);return{operationName:g,argTypeName:f,responseTypeName:d,isQuery:v,verb:e.toUpperCase(),path:n,queryKeyName:x,queryParams:P,pathParams:Oe,isVoidArg:ve,summary:C,contentType:xe,hasRequestBody:Te,tags:Ce,isBlobResponse:Pe}}extractParameters(t){let{operation:e,pathItem:n}=t,o=this.resolveArray(e.parameters),a=this.resolveArray(n.parameters).filter(g=>!o.some(f=>f.name===g.name&&f.in===g.in)),i=Le([...a,...o]).filter(g=>g.in!=="header"),p=i.filter(g=>g.in==="query"),u=i.filter(g=>g.in==="path"),s=!!e.requestBody,m=p.length===0&&u.length===0&&!e.requestBody;return{queryParams:p,pathParams:u,isVoidArg:m,hasRequestBody:s}}resolveArray(t){return t?Array.isArray(t)?t:[t]:[]}isBlobResponseEndpoint(t){if(!t.responses)return!1;let e=t.responses[200]||t.responses[201];if(!e?.content)return!1;let n=Object.keys(e.content),o=["application/json","text/","*/*"];if(n.some(i=>!o.some(p=>i===p||i.startsWith(p))))return!0;for(let i of n){let p=e.content[i]?.schema;if(p&&p.type==="string"&&p.format==="binary")return!0}return!1}extractContentType(t){if(!t.requestBody)return"application/json";let e=t.requestBody.content;if(!e||typeof e!="object")return"application/json";let n=Object.keys(e);return n.length===0?"application/json":n[0]}};c();var He=r=>r.charAt(0).toUpperCase()+r.slice(1);function ce(r,t,e,n){let o={};e&&Object.keys(e).forEach(m=>{if(o[m]=m,m.endsWith("Vo")){let g=m.slice(0,-2)+"VO";o[g]=m}if(m.endsWith("Dto")){let g=m.slice(0,-3)+"DTO";o[g]=m}});let a=r.some(m=>m.isBlobResponse),i=`/* eslint-disable */
56
+ // [Warning] Generated automatically - do not edit manually
57
+
58
+ `;a&&(i+=`import { HttpResponse } from '@angular/common/http';
59
+ `),e&&Object.keys(e).length>0&&(i+=`import * as Schema from "../schema";
60
+ `),i+=`
61
+ `;let u=[],s=[];return r.forEach(m=>{let g=m.argTypeName,f=m.responseTypeName;if(g){let d=Ze(m,n,o);d.trim()===""?s.push(`export type ${g} = void;`,""):s.push(`export type ${g} = {`,d,"};","")}if(f)if(m.isBlobResponse)s.push(`export type ${f} = HttpResponse<Blob>;`,"");else{let d=Ye(m,n,o);d.trim()===""?s.push(`export type ${f} = void;`,""):s.push(`export type ${f} = {`,d,"};","")}}),s.length>0&&u.push(s.join(`
62
+ `)),u.length===0&&u.push("// \u6B64\u6A94\u6848\u7528\u65BC\u5B9A\u7FA9 API \u76F8\u95DC\u7684\u985E\u578B","// \u985E\u578B\u5B9A\u7FA9\u6703\u6839\u64DA OpenAPI Schema \u81EA\u52D5\u751F\u6210",""),i+u.join(`
63
+
64
+ `)}function Ze(r,t,e={}){let n=[];r.queryParams&&r.queryParams.length>0&&r.queryParams.forEach(a=>{let i=a.required?"":"?",p=pe(a,e);n.push(` ${a.name}${i}: ${p};`)}),r.pathParams&&r.pathParams.length>0&&r.pathParams.forEach(a=>{let i=a.required?"":"?",p=pe(a,e);n.push(` ${a.name}${i}: ${p};`)});let o=t?.find(a=>a.operation?.operationId===r.operationName||a.operation?.operationId===r.operationName.toLowerCase()||a.verb===r.verb.toLowerCase()&&a.path===r.path);if(o?.operation?.requestBody){let i=o.operation.requestBody.content,p=i["application/json"]||i["*/*"],u=i["multipart/form-data"]||i["application/x-www-form-urlencoded"];if(p?.schema){let s=O(p.schema,e,1);n.push(` body: ${s};`)}else if(u?.schema){let s=O(u.schema,e,1);n.push(` body: ${s};`)}else{let s=Object.values(i)[0];if(s?.schema){let m=O(s.schema,e,1);n.push(` body: ${m};`)}else n.push(" body?: any; // Request body from OpenAPI")}}return n.length===0?"":n.join(`
65
+ `)}function Ye(r,t,e={}){let n=[],o=t?.find(a=>a.operation?.operationId===r.operationName||a.operation?.operationId===r.operationName.toLowerCase()||a.verb===r.verb.toLowerCase()&&a.path===r.path);if(o?.operation?.responses){let a=o.operation.responses[200]||o.operation.responses[201];if(a?.content){let i=a.content["application/json"]||a.content["*/*"]||Object.values(a.content)[0];if(i?.schema){let p=Je(i.schema,e);n.push(...p)}else n.push(" // Success response from OpenAPI"),n.push(" data?: any;")}}return n.length===0?"":n.join(`
66
+ `)}function Je(r,t={}){let e=[];if(r.type==="object"&&r.properties){let n=r.required||[];Object.entries(r.properties).forEach(([o,a])=>{let p=n.includes(o)?"":"?",u=O(a,t,1),m=/[^a-zA-Z0-9_$]/.test(o)?`"${o}"`:o;(a.title||a.description)&&e.push(` /** ${a.title??""} ${a.description??""}*/`),e.push(` ${m}${p}: ${u};`)})}return e}function O(r,t={},e=0){if(!r)return"any";if(r.$ref){let o=r.$ref;if(o.startsWith("#/components/schemas/")){let a=o.replace("#/components/schemas/",""),i=t[a]||a,u=`Schema.${He(i)}`;return r.nullable?`${u} | null`:u}}if(r.oneOf||r.anyOf){let i=(r.oneOf||r.anyOf).map(p=>O(p,t,e)).join(" | ");return r.nullable?`${i} | null`:i}if(r.allOf){let a=r.allOf.map(i=>O(i,t,e)).join(" & ");return r.nullable?`(${a}) | null`:a}let n;switch(r.type){case"string":r.enum?n=r.enum.map(i=>`"${i}"`).join(" | "):r.format==="binary"?n="Blob":n="string";break;case"number":case"integer":n="number";break;case"boolean":n="boolean";break;case"array":let o=r.items?O(r.items,t,e):"any";n=o.includes("|")?`(${o})[]`:`${o}[]`;break;case"object":if(r.properties){let i=Object.entries(r.properties);if(i.length===0)r.additionalProperties?n=`Record<string, ${r.additionalProperties===!0?"any":O(r.additionalProperties,t,e)}>`:n="{}";else{let p=" ".repeat(e+1),u=" ".repeat(e),s=[];i.forEach(([m,g])=>{let d=(r.required||[]).includes(m)?"":"?",v=O(g,t,e+1),C=/[^a-zA-Z0-9_$]/.test(m)?`"${m}"`:m;(g.title||g.description)&&s.push(`${p}/** ${g.title??""} ${g.description??""}*/`),s.push(`${p}${C}${d}: ${v};`)}),n=`{
67
+ ${s.join(`
67
68
  `)}
68
- ${u}}`}}else r.additionalProperties?n=`Record<string, ${r.additionalProperties===!0?"any":O(r.additionalProperties,t,e)}>`:n="any";break;default:n="any";break}return r.nullable?`${n} | null`:n}function ae(r,t={}){return r.schema?O(r.schema,t):"any"}c();function ce(r,t){let{groupKey:e,refetchOnMountOrArgChange:n=60}=t,o=e?`${e.charAt(0).toUpperCase()+e.slice(1)}QueryService`:"QueryService",s=e?`${e.charAt(0).toUpperCase()+e.slice(1)}ApiService`:"ApiService",a=r.filter(i=>i.isQuery).map(i=>`
69
+ ${u}}`}}else r.additionalProperties?n=`Record<string, ${r.additionalProperties===!0?"any":O(r.additionalProperties,t,e)}>`:n="any";break;default:n="any";break}return r.nullable?`${n} | null`:n}function pe(r,t={}){return r.schema?O(r.schema,t):"any"}c();function ue(r,t){let{groupKey:e,refetchOnMountOrArgChange:n=60}=t,o=e?`${e.charAt(0).toUpperCase()+e.slice(1)}QueryService`:"QueryService",a=e?`${e.charAt(0).toUpperCase()+e.slice(1)}ApiService`:"ApiService",i=r.filter(s=>s.isQuery).map(s=>`
69
70
  /**
70
- * ${i.summary}
71
+ * ${s.summary}
71
72
  */
72
- ${i.operationName}Query(args: IRestFulEndpointsQueryReturn<${i.argTypeName}>, queryOptions?: BaseQueryOptions): Observable<QueryState<${i.responseTypeName}>> {
73
+ ${s.operationName}Query(args: IRestFulEndpointsQueryReturn<${s.argTypeName}>, queryOptions?: BaseQueryOptions): Observable<QueryState<${s.responseTypeName}>> {
73
74
  if (queryOptions?.skip) {
74
- return this.ntkQuery.skipQuery<${i.responseTypeName}>();
75
+ return this.ntkQuery.skipQuery<${s.responseTypeName}>();
75
76
  }
76
- return this.ntkQuery.query<${i.responseTypeName}, ${i.isVoidArg?"void":`IRestFulEndpointsQueryReturn<${i.argTypeName}>`}>({
77
- queryKey: [ECacheTagTypes.${i.queryKeyName}${i.isVoidArg?"":", args.variables"}],
77
+ return this.ntkQuery.query<${s.responseTypeName}, ${s.isVoidArg?"void":`IRestFulEndpointsQueryReturn<${s.argTypeName}>`}>({
78
+ queryKey: [ECacheTagTypes.${s.queryKeyName}${s.isVoidArg?"":", args.variables"}],
78
79
  queryFn: () => {
79
- return this.apiService.${i.operationName}(args);
80
+ return this.apiService.${s.operationName}(args);
80
81
  },
81
82
  fetchOptions: args?.fetchOptions,
82
83
  config: args?.config,
83
84
  refetchDeps: queryOptions?.refetchDeps,
84
- })(${i.isVoidArg?"":"args"});
85
- }`).join(""),p=r.filter(i=>!i.isQuery).map(i=>`
85
+ })(${s.isVoidArg?"":"args"});
86
+ }`).join(""),p=r.filter(s=>!s.isQuery).map(s=>`
86
87
  /**
87
- * ${i.summary}
88
+ * ${s.summary}
88
89
  */
89
- ${i.operationName}Mutation(): MutationResponse<${i.responseTypeName}, {
90
- variables: ${i.isVoidArg?"void":i.argTypeName};
90
+ ${s.operationName}Mutation(): MutationResponse<${s.responseTypeName}, {
91
+ variables: ${s.isVoidArg?"void":s.argTypeName};
91
92
  fetchOptions?: RequestOptions;
92
93
  }, HttpErrorResponse> {
93
- return this.ntkQuery.mutation<${i.responseTypeName}, ${i.isVoidArg?"{}":`IRestFulEndpointsQueryReturn<${i.argTypeName}>`}, HttpErrorResponse>({
94
- endpointName: '${i.operationName}',
94
+ return this.ntkQuery.mutation<${s.responseTypeName}, ${s.isVoidArg?"{}":`IRestFulEndpointsQueryReturn<${s.argTypeName}>`}, HttpErrorResponse>({
95
+ endpointName: '${s.operationName}',
95
96
  mutationFn: (args) => {
96
- return this.apiService.${i.operationName}(args);
97
+ return this.apiService.${s.operationName}(args);
97
98
  },
98
99
  });
99
- }`).join(""),u=r.filter(i=>i.isQuery).map(i=>`
100
+ }`).join(""),u=r.filter(s=>s.isQuery).map(s=>`
100
101
  /**
101
- * ${i.summary}
102
+ * ${s.summary}
102
103
  */
103
- ${i.operationName}LazyQuery(): LazyQueryResult<${i.responseTypeName}, IRestFulEndpointsQueryReturn<${i.argTypeName}>> {
104
- return this.ntkQuery.lazyQuery<${i.responseTypeName}, IRestFulEndpointsQueryReturn<${i.argTypeName}>>(
105
- ECacheTagTypes.${i.queryKeyName},
106
- (args) => this.apiService.${i.operationName}(args),
104
+ ${s.operationName}LazyQuery(): LazyQueryResult<${s.responseTypeName}, IRestFulEndpointsQueryReturn<${s.argTypeName}>> {
105
+ return this.ntkQuery.lazyQuery<${s.responseTypeName}, IRestFulEndpointsQueryReturn<${s.argTypeName}>>(
106
+ ECacheTagTypes.${s.queryKeyName},
107
+ (args) => this.apiService.${s.operationName}(args),
107
108
  );
108
109
  }`).join("");return`/* eslint-disable */
109
110
  // [Warning] Generated automatically - do not edit manually
@@ -113,19 +114,19 @@ import {Observable} from 'rxjs';
113
114
  import {HttpErrorResponse} from '@angular/common/http';
114
115
  import {NtkQueryService, MutationState, QueryState, BaseQueryOptions, MutationResponse, LazyQueryResult, LazyQueryTriggerOptions} from '@core/ntk-query';
115
116
  import {ECacheTagTypes} from '../tagTypes';
116
- import {${s}} from './enhanceEndpoints';
117
+ import {${a}} from './enhanceEndpoints';
117
118
  import {IRestFulEndpointsQueryReturn, RequestOptions} from '../common-types';
118
- import {${r.map(i=>` ${i.argTypeName}, ${i.responseTypeName}`).join(",")}} from './types';
119
+ import {${r.map(s=>` ${s.argTypeName}, ${s.responseTypeName}`).join(",")}} from './types';
119
120
 
120
121
  @Injectable({
121
122
  providedIn: 'root',
122
123
  })
123
124
  export class ${o} {
124
- private apiService = inject(${s});
125
+ private apiService = inject(${a});
125
126
  private ntkQuery = inject(NtkQueryService);
126
- ${a}${p}${u}
127
+ ${i}${p}${u}
127
128
  }
128
- `}c();function ue(r,t){let{apiConfiguration:e,httpClient:n,groupKey:o}=t,s=o?`${o.charAt(0).toUpperCase()+o.slice(1)}ApiService`:"ApiService";return`/* eslint-disable */
129
+ `}c();function me(r,t){let{apiConfiguration:e,httpClient:n,groupKey:o}=t,a=o?`${o.charAt(0).toUpperCase()+o.slice(1)}ApiService`:"ApiService";return`/* eslint-disable */
129
130
  // [Warning] Generated automatically - do not edit manually
130
131
 
131
132
  import { ${n.importReturnTypeName} } from '${n.file}';
@@ -134,38 +135,40 @@ import { Observable } from 'rxjs';
134
135
  import { ${e.importName} } from '${e.file}';
135
136
  import { RequestOptions, IRestFulEndpointsQueryReturn } from '../common-types';
136
137
  import { withoutUndefined } from '../utils';
137
- import {${r.map(a=>` ${a.argTypeName}, ${a.responseTypeName}`).join(",")} } from './types';
138
+ import {${r.map(i=>` ${i.argTypeName}, ${i.responseTypeName}`).join(",")} } from './types';
138
139
 
139
140
  @Injectable({
140
141
  providedIn: 'root',
141
142
  })
142
- export class ${s} {
143
+ export class ${a} {
143
144
  private config = inject(${e.importName});
144
145
  private http = inject(${n.importReturnTypeName});
145
146
 
146
- ${r.map(a=>{let p=a.verb.toUpperCase()==="GET",u=!a.isVoidArg,i=a.hasRequestBody,m=v=>v.includes("{")&&u?`\`\${this.config.rootUrl}${v.replace(/\{([^}]+)\}/g,"${args.variables.$1}")}\``:`\`\${this.config.rootUrl}${v}\``,g=a.queryParams.length>0,f=!p&&u,T=()=>{let v="";return a.queryParams&&a.queryParams.length>0&&(v=`params: {${a.queryParams.map(b=>`${b.name}: args.variables.${b.name},`).join(`
147
- `)}},`),`{
147
+ ${r.map(i=>{let p=i.verb.toUpperCase()==="GET",u=!i.isVoidArg,s=i.hasRequestBody,m=v=>v.includes("{")&&u?`\`\${this.config.rootUrl}${v.replace(/\{([^}]+)\}/g,"${args.variables.$1}")}\``:`\`\${this.config.rootUrl}${v}\``,g=i.queryParams.length>0,f=!p&&u,d=()=>{let v="";i.queryParams&&i.queryParams.length>0&&(v=`params: {${i.queryParams.map(P=>`${P.name}: args.variables.${P.name},`).join(`
148
+ `)}},`);let x=i.isBlobResponse?`
149
+ responseType: 'blob',
150
+ observe: 'response',`:"";return`{
148
151
  ...args?.fetchOptions,
149
- headers: { 'Content-Type': '${a.contentType}', ...args?.fetchOptions?.headers },
150
- ${v}${a.hasRequestBody?"body: args.variables.body,":""}
152
+ headers: { 'Content-Type': '${i.contentType}', ...args?.fetchOptions?.headers },
153
+ ${v}${i.hasRequestBody?"body: args.variables.body,":""}${x}
151
154
  }`};return`
152
155
  /**
153
- * ${a.summary}
156
+ * ${i.summary}
154
157
  */
155
- ${a.operationName}(
156
- args: IRestFulEndpointsQueryReturn<${a.argTypeName}>,
157
- ): Observable<${a.responseTypeName}> {
158
- const url = ${m(a.path)};
159
- return this.http.request('${a.verb.toLowerCase()}', url, ${T()});
158
+ ${i.operationName}(
159
+ args: IRestFulEndpointsQueryReturn<${i.argTypeName}>,
160
+ ): Observable<${i.responseTypeName}> {
161
+ const url = ${m(i.path)};
162
+ return this.http.request('${i.verb.toLowerCase()}', url, ${d()});
160
163
  }`}).join("")}
161
164
  }
162
- `}var q=class{constructor(t,e){this.parserService=t;this.options=e;this.infoExtractor=new S(e)}infoExtractor;async generate(){let t=this.parserService.getOperationDefinitions(this.options.filterEndpoints),e=this.infoExtractor.extractEndpointInfos(t);return this.generateRtkQueryCode(e)}generateRtkQueryCode(t){let e=this.generateTypes(t),n=ce(t,this.options),o=ue(t,this.options),s=this.generateIndex(),a=t.filter(i=>i.isQuery).map(i=>({operationName:i.operationName,queryKeyName:i.queryKeyName,groupKey:this.options.groupKey||"_common"})),p=t.map(i=>i.operationName),u=new Set;return t.forEach(i=>{i.tags&&Array.isArray(i.tags)&&i.tags.forEach(m=>u.add(m))}),{operationNames:p,tags:Array.from(u),files:{types:e,queryService:n,index:s,enhanceEndpoints:o,allEndpointCacheKeys:a}}}generateTypes(t){let e={...this.options,apiConfiguration:this.options.apiConfiguration||{file:"@/store/webapi",importName:"WebApiConfiguration"}},o=this.parserService.getApiGenerator().aliases.reduce((a,p)=>{if(me.isInterfaceDeclaration(p)||me.isTypeAliasDeclaration(p)){let u=p.name.text;return{...a,[u]:p}}return a},{}),s=this.parserService.getOperationDefinitions(this.options.filterEndpoints);return pe(t,e,o,s)}generateIndex(){let t=this.options.groupKey||"",e=t?`${t.charAt(0).toLowerCase()+t.slice(1)}Api`:"api";return`/* eslint-disable */
165
+ `}var F=class{constructor(t,e){this.parserService=t;this.options=e;this.infoExtractor=new q(e)}infoExtractor;async generate(){let t=this.parserService.getOperationDefinitions(this.options.filterEndpoints),e=this.infoExtractor.extractEndpointInfos(t);return this.generateRtkQueryCode(e)}generateRtkQueryCode(t){let e=this.generateTypes(t),n=ue(t,this.options),o=me(t,this.options),a=this.generateIndex(),i=t.filter(s=>s.isQuery).map(s=>({operationName:s.operationName,queryKeyName:s.queryKeyName,groupKey:this.options.groupKey||"_common"})),p=t.map(s=>s.operationName),u=new Set;return t.forEach(s=>{s.tags&&Array.isArray(s.tags)&&s.tags.forEach(m=>u.add(m))}),{operationNames:p,tags:Array.from(u),files:{types:e,queryService:n,index:a,enhanceEndpoints:o,allEndpointCacheKeys:i}}}generateTypes(t){let e={...this.options,apiConfiguration:this.options.apiConfiguration||{file:"@/store/webapi",importName:"WebApiConfiguration"}},o=this.parserService.getApiGenerator().aliases.reduce((i,p)=>{if(le.isInterfaceDeclaration(p)||le.isTypeAliasDeclaration(p)){let u=p.name.text;return{...i,[u]:p}}return i},{}),a=this.parserService.getOperationDefinitions(this.options.filterEndpoints);return ce(t,e,o,a)}generateIndex(){let t=this.options.groupKey||"",e=t?`${t.charAt(0).toLowerCase()+t.slice(1)}Api`:"api";return`/* eslint-disable */
163
166
  // [Warning] Generated automatically - do not edit manually
164
167
 
165
168
  export * from "./enhanceEndpoints";
166
169
  export * from "./query.generated";
167
170
  export * from "./types";
168
- `}};c();function le(){return`/* eslint-disable */
171
+ `}};c();function ye(){return`/* eslint-disable */
169
172
  // [Warning] Generated automatically - do not edit manually
170
173
 
171
174
  /**
@@ -178,25 +181,25 @@ export function withoutUndefined(obj?: Record<string, any>) {
178
181
  );
179
182
  }
180
183
 
181
- `}function ye(r){return r.toLowerCase().replace(/_([a-z])/g,(t,e)=>e.toUpperCase())}c();function ge(r){let t=r.reduce((n,o)=>(n[o.groupKey]||(n[o.groupKey]=[]),n[o.groupKey].push({operationName:o.operationName,queryKeyName:o.queryKeyName}),n),{});return`// [Warning] Generated automatically - do not edit manually
184
+ `}function ge(r){return r.toLowerCase().replace(/_([a-z])/g,(t,e)=>e.toUpperCase())}c();function fe(r){let t=r.reduce((n,o)=>(n[o.groupKey]||(n[o.groupKey]=[]),n[o.groupKey].push({operationName:o.operationName,queryKeyName:o.queryKeyName}),n),{});return`// [Warning] Generated automatically - do not edit manually
182
185
 
183
186
  /**
184
187
  * Cache keys enum for all API queries
185
188
  */
186
189
  export enum ECacheTagTypes {
187
- ${Object.entries(t).map(([n,o])=>{let s=` // ${n.charAt(0).toUpperCase()+n.slice(1)} related cache keys`,a=o.map(p=>` ${p.queryKeyName} = '${ye(p.queryKeyName)}',`).join(`
188
- `);return`${s}
189
- ${a}`}).join(`
190
+ ${Object.entries(t).map(([n,o])=>{let a=` // ${n.charAt(0).toUpperCase()+n.slice(1)} related cache keys`,i=o.map(p=>` ${p.queryKeyName} = '${ge(p.queryKeyName)}',`).join(`
191
+ `);return`${a}
192
+ ${i}`}).join(`
190
193
 
191
194
  `)}
192
195
  }
193
196
 
194
197
  export default ECacheTagTypes;
195
- `}var w=class{_options;openApiService=new $;groupService=new N;fileWriterService=new A;allEndpointCacheKeys=[];openApiDoc=null;parserService=null;schemaInterfaces={};actualSchemaFile="";generatedContent={groups:[],commonTypes:"",componentSchema:"",doNotModify:"",utils:"",tagTypes:""};allTags=new Set;constructor(t){this._options=t}async generateAll(){return await this.prepare(),await this.generateApi(),this.generateCommonTypesContent(),this.generateSchemaContent(),this.generateUtilsContent(),this.generateDoNotModifyContent(),this.generatECacheTagTypesContent(),await this.release()}async prepare(){this.actualSchemaFile=this._options.schemaFile,this._options.remoteFile&&(this.actualSchemaFile=await this.openApiService.downloadSchema(this._options.remoteFile,this._options.schemaFile)),this.openApiDoc=await this.openApiService.getDocument(this.actualSchemaFile,this._options.httpResolverOptions),this.parserService=new R(this.openApiDoc,this._options),this.parserService.initialize();let t=this.parserService.getApiGenerator();this.schemaInterfaces=t.aliases.reduce((e,n)=>{if(fe.isInterfaceDeclaration(n)||fe.isTypeAliasDeclaration(n)){let o=n.name.text;return{...e,[o]:n}}return e},{})}async generateApi(){if(!this.openApiDoc||!this.parserService)throw new Error("\u8ACB\u5148\u8ABF\u7528 prepare() \u65B9\u6CD5");let t=this.openApiService.getPaths(this.openApiDoc),e=this.groupService.groupPaths(t,this._options.outputFiles);for(let n of Object.values(e))try{let o=await this.generateApiGroupContent(this._options,n);o.operationNames.length>0&&(this.generatedContent.groups.push({groupKey:n.groupKey,outputPath:n.outputPath,content:o}),o.tags&&Array.isArray(o.tags)&&o.tags.forEach(s=>this.allTags.add(s)))}catch(o){throw new Error(`\u7FA4\u7D44 ${n.groupKey} \u751F\u6210\u5931\u6557: ${o}`)}}async generatECacheTagTypesContent(){this.generatedContent.tagTypes=ge(this.allEndpointCacheKeys)}async generateCommonTypesContent(){this.generatedContent.commonTypes=oe()}async generateSchemaContent(){this.generatedContent.componentSchema=ie(this.schemaInterfaces)}async generateDoNotModifyContent(){this.generatedContent.doNotModify=se()}async generateUtilsContent(){this.generatedContent.utils=le()}async release(){let t=[],e=[],n=[];try{for(let p of this.generatedContent.groups)try{if(p.content?.files){let u=F.dirname(p.outputPath),i=await this.fileWriterService.writeGroupFiles(u,{types:p.content.files.types,queryService:p.content.files.queryService,enhanceEndpoints:p.content.files.enhanceEndpoints,index:p.content.files.index});t.push(...i),n.push(p.groupKey)}}catch(u){e.push(new Error(`\u5BEB\u5165\u7FA4\u7D44 ${p.groupKey} \u5931\u6557: ${u}`))}let o=this.generatedContent.groups[0]?F.dirname(F.dirname(this.generatedContent.groups[0].outputPath)):"./generated";if(this.generatedContent.tagTypes||this.generatedContent.commonTypes||this.generatedContent.doNotModify||this.generatedContent.utils){let p=await this.fileWriterService.writeSharedFiles(o,{tagTypes:this.generatedContent.tagTypes||void 0,commonTypes:this.generatedContent.commonTypes||void 0,doNotModify:this.generatedContent.doNotModify||void 0,utils:this.generatedContent.utils||void 0});t.push(...p)}if(this.generatedContent.componentSchema){let p=await this.fileWriterService.writeSchemaFile(o,this.generatedContent.componentSchema);t.push(...p)}let s=this.generateMainIndex(n),a=await this.fileWriterService.writeFile(F.join(o,"index.ts"),s);t.push(a)}catch(o){e.push(o)}return{success:e.length===0,writtenFiles:t,errors:e,generatedGroups:n}}async generateApiGroupContent(t,e){let{outputFiles:n,...o}=t,s={...o,schemaFile:this.actualSchemaFile,outputFile:e.outputPath,sharedTypesFile:`${n.outputDir}/common-types.ts`,filterEndpoints:this.groupService.createGroupFilter(e.groupKey,n),queryMatch:n.queryMatch,groupKey:e.groupKey};if(!this.openApiDoc||!this.parserService)throw new Error("OpenAPI \u6587\u6A94\u672A\u521D\u59CB\u5316\uFF0C\u8ACB\u5148\u8ABF\u7528 prepare()");let p=await new q(this.parserService,s).generate();if(p.files&&"allEndpointCacheKeys"in p.files){let u=p.files.allEndpointCacheKeys;this.allEndpointCacheKeys.push(...u)}return p}generateMainIndex(t){return`/* eslint-disable */
198
+ `}var j=class{_options;openApiService=new N;groupService=new R;fileWriterService=new E;allEndpointCacheKeys=[];openApiDoc=null;parserService=null;schemaInterfaces={};actualSchemaFile="";generatedContent={groups:[],commonTypes:"",componentSchema:"",doNotModify:"",utils:"",tagTypes:""};allTags=new Set;constructor(t){this._options=t}async generateAll(){return await this.prepare(),await this.generateApi(),this.generateCommonTypesContent(),this.generateSchemaContent(),this.generateUtilsContent(),this.generateDoNotModifyContent(),this.generatECacheTagTypesContent(),await this.release()}async prepare(){this.actualSchemaFile=this._options.schemaFile,this._options.remoteFile&&(this.actualSchemaFile=await this.openApiService.downloadSchema(this._options.remoteFile,this._options.schemaFile)),this.openApiDoc=await this.openApiService.getDocument(this.actualSchemaFile,this._options.httpResolverOptions),this.parserService=new S(this.openApiDoc,this._options),this.parserService.initialize();let t=this.parserService.getApiGenerator();this.schemaInterfaces=t.aliases.reduce((e,n)=>{if(de.isInterfaceDeclaration(n)||de.isTypeAliasDeclaration(n)){let o=n.name.text;return{...e,[o]:n}}return e},{})}async generateApi(){if(!this.openApiDoc||!this.parserService)throw new Error("\u8ACB\u5148\u8ABF\u7528 prepare() \u65B9\u6CD5");let t=this.openApiService.getPaths(this.openApiDoc),e=this.groupService.groupPaths(t,this._options.outputFiles);for(let n of Object.values(e))try{let o=await this.generateApiGroupContent(this._options,n);o.operationNames.length>0&&(this.generatedContent.groups.push({groupKey:n.groupKey,outputPath:n.outputPath,content:o}),o.tags&&Array.isArray(o.tags)&&o.tags.forEach(a=>this.allTags.add(a)))}catch(o){throw new Error(`\u7FA4\u7D44 ${n.groupKey} \u751F\u6210\u5931\u6557: ${o}`)}}async generatECacheTagTypesContent(){this.generatedContent.tagTypes=fe(this.allEndpointCacheKeys)}async generateCommonTypesContent(){this.generatedContent.commonTypes=ie()}async generateSchemaContent(){this.generatedContent.componentSchema=se(this.schemaInterfaces)}async generateDoNotModifyContent(){this.generatedContent.doNotModify=ae()}async generateUtilsContent(){this.generatedContent.utils=ye()}async release(){let t=[],e=[],n=[];try{for(let p of this.generatedContent.groups)try{if(p.content?.files){let u=w.dirname(p.outputPath),s=await this.fileWriterService.writeGroupFiles(u,{types:p.content.files.types,queryService:p.content.files.queryService,enhanceEndpoints:p.content.files.enhanceEndpoints,index:p.content.files.index});t.push(...s),n.push(p.groupKey)}}catch(u){e.push(new Error(`\u5BEB\u5165\u7FA4\u7D44 ${p.groupKey} \u5931\u6557: ${u}`))}let o=this.generatedContent.groups[0]?w.dirname(w.dirname(this.generatedContent.groups[0].outputPath)):"./generated";if(this.generatedContent.tagTypes||this.generatedContent.commonTypes||this.generatedContent.doNotModify||this.generatedContent.utils){let p=await this.fileWriterService.writeSharedFiles(o,{tagTypes:this.generatedContent.tagTypes||void 0,commonTypes:this.generatedContent.commonTypes||void 0,doNotModify:this.generatedContent.doNotModify||void 0,utils:this.generatedContent.utils||void 0});t.push(...p)}if(this.generatedContent.componentSchema){let p=await this.fileWriterService.writeSchemaFile(o,this.generatedContent.componentSchema);t.push(...p)}let a=this.generateMainIndex(n),i=await this.fileWriterService.writeFile(w.join(o,"index.ts"),a);t.push(i)}catch(o){e.push(o)}return{success:e.length===0,writtenFiles:t,errors:e,generatedGroups:n}}async generateApiGroupContent(t,e){let{outputFiles:n,...o}=t,a={...o,schemaFile:this.actualSchemaFile,outputFile:e.outputPath,sharedTypesFile:`${n.outputDir}/common-types.ts`,filterEndpoints:this.groupService.createGroupFilter(e.groupKey,n),queryMatch:n.queryMatch,groupKey:e.groupKey};if(!this.openApiDoc||!this.parserService)throw new Error("OpenAPI \u6587\u6A94\u672A\u521D\u59CB\u5316\uFF0C\u8ACB\u5148\u8ABF\u7528 prepare()");let p=await new F(this.parserService,a).generate();if(p.files&&"allEndpointCacheKeys"in p.files){let u=p.files.allEndpointCacheKeys;this.allEndpointCacheKeys.push(...u)}return p}generateMainIndex(t){return`/* eslint-disable */
196
199
  // [Warning] Generated automatically - do not edit manually
197
200
 
198
201
  ${t.map(n=>`export * from "./${n}";`).concat(`
199
202
  export * from "./tagTypes";`).join(`
200
203
  `)}
201
- `}};async function de(r){let e=await new w(r).generateAll();if(!e.success&&e.errors.length>0)throw e.errors[0]}var he=Je(l);async function tt(r){let t=et(process.cwd(),r);process.chdir(Xe(t));let e=he(t),n=e.default??e;"outputFiles"in n||(console.error('Configuration must include "outputFiles" property. Single file output is no longer supported.'),process.exit(1)),n.outputFiles&&n.outputFiles.outputDir&&k(n.outputFiles.outputDir);try{console.log("Generating multiple outputs..."),await de(n),console.log("Done")}catch(o){console.error("Generation failed:",o),process.exit(1)}}async function rt(){let r=he("../../package.json"),t=V();j.version(r.version).usage("<path/to/config.js>").parse(process.argv);let e=j.args[0];if(j.args.length===0){j.help();return}U(e),W(e,t),await tt(e)}rt().catch(r=>{console.error("CLI execution failed:",r),process.exit(1)});export{tt as runGeneration};
204
+ `}};async function he(r){let e=await new j(r).generateAll();if(!e.success&&e.errors.length>0)throw e.errors[0]}var be=Xe(l);async function rt(r){let t=tt(process.cwd(),r);process.chdir(et(t));let e=be(t),n=e.default??e;"outputFiles"in n||(console.error('Configuration must include "outputFiles" property. Single file output is no longer supported.'),process.exit(1)),n.outputFiles&&n.outputFiles.outputDir&&V(n.outputFiles.outputDir);try{console.log("Generating multiple outputs..."),await he(n),console.log("Done")}catch(o){console.error("Generation failed:",o),process.exit(1)}}async function nt(){let r=be("../../package.json"),t=U();I.version(r.version).usage("<path/to/config.js>").parse(process.argv);let e=I.args[0];if(I.args.length===0){I.help();return}B(e),W(e,t),await rt(e)}nt().catch(r=>{console.error("CLI execution failed:",r),process.exit(1)});export{rt as runGeneration};
202
205
  //# sourceMappingURL=cli.mjs.map