@acrool/rtk-query-codegen-openapi 1.2.0-alpha.0 → 1.2.0-alpha.1

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 G=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var $e=Object.prototype.hasOwnProperty;var k=(n,e)=>()=>(n&&(e=n(n=0)),e);var Se=(n,e)=>{for(var t in e)G(n,t,{get:e[t],enumerable:!0})},Re=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ae(e))!$e.call(n,o)&&o!==t&&G(n,o,{get:()=>e[o],enumerable:!(r=Te(e,o))||r.enumerable});return n};var Ne=n=>Re(G({},"__esModule",{value:!0}),n);import{fileURLToPath as Ee}from"node:url";var we,l,c=k(()=>{"use strict";we=()=>Ee(import.meta.url),l=we()});var ie={};Se(ie,{argumentMatches:()=>ze,defaultIsDataResponse:()=>_e,getOperationName:()=>R,getOverrides:()=>M,getTags:()=>Be,operationMatches:()=>oe});import{getOperationName as Qe}from"oazapfts/generate";function _e(n,e){if(e&&n==="default")return!0;let t=Number(n);return!Number.isNaN(t)&&t>=200&&t<300}function R({verb:n,path:e}){return Qe(n,e,void 0)}function Be({verb:n,pathItem:e}){return n?e[n]?.tags||[]:[]}function ne(n){let e=Array.isArray(n)?n:[n];return function(r){return n?e.some(o=>typeof o=="string"?o===r:o?.test(r)):!0}}function oe(n){let e=typeof n=="function"?n:ne(n);return function(r){if(!n)return!0;let o=R(r);return e(o,r)}}function ze(n){let e=typeof n=="function"?n:ne(n);return function(r){if(!n||r.in==="path")return!0;let o=r.name;return e(o,r)}}function M(n,e){return e?.find(t=>oe(t.pattern)(n))}var K=k(()=>{"use strict";c()});c();import I from"commander";import{createRequire as rt}from"node:module";c();import Fe from"commander";import{createRequire as qe}from"node:module";import{resolve as V}from"node:path";import{existsSync as D,rmSync as Ie,readdirSync as Ge,statSync as De,mkdirSync as je}from"node:fs";import U from"node:path";var b=qe(l);function Me(n){let e=new Map;if(!D(n))return e;function t(r){try{let o=Ge(r);for(let i of o){let p=U.join(r,i);if(De(p).isDirectory())t(p);else if(i==="enhanceEndpoints.ts"){let u=b("node:fs").readFileSync(p);e.set(p,u)}}}catch{}}return t(n),e}function Ke(n){for(let[e,t]of n)try{let r=U.dirname(e);D(r)||je(r,{recursive:!0}),b("node:fs").writeFileSync(e,t)}catch(r){console.warn(`Failed to restore ${e}:`,r)}}function W(n){let e=["/","/usr","/etc","/var","/home","/Users",".",".."],t=V(n);if(e.some(r=>t===V(r))&&(console.error(`Dangerous path detected: ${t}. Refusing to delete.`),process.exit(1)),D(n)){console.log(`Cleaning output directory: ${n}`);let r=Me(n);Ie(n,{recursive:!0,force:!0}),r.size>0&&(Ke(r),console.log(`Protected ${r.size} enhanceEndpoints.ts file(s) from deletion`)),console.log(`Directory cleaned: ${n}`)}}function Q(){try{if(b.resolve("esbuild")&&b.resolve("esbuild-runner"))return b("esbuild-runner/register"),!0}catch{}try{if(b.resolve("typescript")&&b.resolve("ts-node"))return b("ts-node").register({transpileOnly:!0,compilerOptions:{target:"es6",module:"commonjs"}}),!0}catch{}return!1}function _(n){(!n||!/\.([mc]?(jsx?|tsx?)|jsonc?)?$/.test(n))&&(console.error("Please provide a valid configuration file."),Fe.help())}function B(n,e){/\.[mc]?tsx?$/.test(n)&&!e&&(console.error("Encountered a TypeScript config file, but neither esbuild-runner nor ts-node are installed."),process.exit(1))}import{dirname as nt,resolve as ot}from"node:path";c();c();import F from"node:path";import ye from"typescript";c();c();function T(n){return n.replace(n[0],n[0].toUpperCase())}c();import j from"node:fs";import ke from"node:path";c();function z(n){try{new URL(n)}catch{return!1}return!0}async function L(n,e){if(!z(n))throw new Error(`remoteFile must be a valid URL: ${n}`);try{let t=ke.dirname(e);j.existsSync(t)||await j.promises.mkdir(t,{recursive:!0});let r=await fetch(n);if(!r.ok)throw new Error(`Failed to download schema from ${n}: ${r.statusText}`);let o=await r.text();return await j.promises.writeFile(e,o,"utf-8"),console.log(`Schema downloaded from ${n} to ${e}`),e}catch(t){throw console.error(`Error downloading schema from ${n}:`,t),t}}c();c();var H=["get","put","post","delete","options","head","patch","trace"];function Z(n){return Object.entries(n.paths).flatMap(([e,t])=>t?Object.entries(t).filter(r=>H.includes(r[0])).map(([r,o])=>({path:e,verb:r,pathItem:t,operation:o})):[])}c();import Ve from"@apidevtools/swagger-parser";import Ue from"swagger2openapi";async function Y(n,e){let t=await Ve.bundle(n,{resolve:{http:e}});return"openapi"in t&&t.openapi.startsWith("3")?t:(await Ue.convertObj(t,{})).openapi}c();function J(n,e,t,r){return r?r(n,e):t?.type?t.type==="query":n==="get"}var A=class{docCache={};async getDocument(e,t){if(this.docCache[e])return this.docCache[e];let r=await Y(e,t);return this.docCache[e]=r,r}async downloadSchema(e,t){return L(e,t)}getPaths(e){return Object.keys(e.paths||{})}clearCache(){this.docCache={}}};c();import X from"lodash.camelcase";var $=class{groupPaths(e,t){let{groupKeyMatch:r,outputDir:o}=t,i=e.reduce((a,u)=>{let s=r(u),m=s?X(s):"_common";return a[m]||(a[m]=[]),a[m].push(u),a},{}),p={};for(let[a,u]of Object.entries(i))p[a]={groupKey:a,paths:u,outputPath:`${o}/${a}/query.service.ts`};return p}createGroupFilter(e,t){return(r,o)=>{let i=o.path,p=X(t.groupKeyMatch(i)||"");return p!==e&&(p||"_common")!==e?!1:t.filterEndpoint?t.filterEndpoint(r,i,e):!0}}};c();import re from"node:fs";import h from"node:path";c();import We from"node:path";import ee from"node:fs";async function te(n){let e=We.dirname(n);ee.existsSync(e)||await ee.promises.mkdir(e,{recursive:!0})}var S=class{async writeFile(e,t){try{let r=h.resolve(process.cwd(),e);return h.basename(r)==="enhanceEndpoints.ts"&&re.existsSync(r)?{path:r,success:!0}:(await te(r),re.writeFileSync(r,t),{path:r,success:!0})}catch(r){return{path:e,success:!1,error:r}}}async writeFiles(e){let t=[];for(let[r,o]of Object.entries(e)){let i=await this.writeFile(r,o);t.push(i)}return t}async writeGroupFiles(e,t){let r={};return t.types&&(r[h.join(e,"types.ts")]=t.types),t.queryService&&(r[h.join(e,"query.generated.ts")]=t.queryService),t.enhanceEndpoints&&(r[h.join(e,"enhanceEndpoints.ts")]=t.enhanceEndpoints),t.index&&(r[h.join(e,"index.ts")]=t.index),this.writeFiles(r)}async writeSharedFiles(e,t){let r={};return t.commonTypes&&(r[h.join(e,"common-types.ts")]=t.commonTypes),t.doNotModify&&(r[h.join(e,"DO_NOT_MODIFY.md")]=t.doNotModify),t.utils&&(r[h.join(e,"utils.ts")]=t.utils),this.writeFiles(r)}async writeSchemaFile(e,t){let r={};return r[h.join(e,"schema.ts")]=t,this.writeFiles(r)}};c();import Le from"oazapfts/generate";var N=class{constructor(e,t){this.v3Doc=e;this.apiGen=new Le(e,{unionUndefined:t.unionUndefined,mergeReadWriteOnly:t.mergeReadWriteOnly})}apiGen;initialize(){this.apiGen.spec.components?.schemas&&(Object.keys(this.apiGen.spec.components.schemas).forEach(e=>{let t=this.apiGen.spec.components.schemas[e];t&&typeof t=="object"&&"title"in t&&delete t.title}),this.apiGen.preprocessComponents(this.apiGen.spec.components.schemas),Object.keys(this.apiGen.spec.components.schemas).forEach(e=>{try{this.apiGen.getRefAlias({$ref:`#/components/schemas/${e}`})}catch{}}))}getOperationDefinitions(e){let{operationMatches:t}=(K(),Ne(ie));return Z(this.v3Doc).filter(t(e))}getApiGenerator(){return this.apiGen}getDocument(){return this.v3Doc}getSchemaTypeNames(){return new Set}};c();function se(){return`/* eslint-disable */
2
+ var j=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Se=Object.prototype.hasOwnProperty;var W=(r,e)=>()=>(r&&(e=r(r=0)),e);var Ee=(r,e)=>{for(var t in e)j(r,t,{get:e[t],enumerable:!0})},Re=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $e(e))!Se.call(r,o)&&o!==t&&j(r,o,{get:()=>e[o],enumerable:!(n=Ae(e,o))||n.enumerable});return r};var Ne=r=>Re(j({},"__esModule",{value:!0}),r);import{fileURLToPath as we}from"node:url";var Fe,g,p=W(()=>{"use strict";Fe=()=>we(import.meta.url),g=Fe()});var ae={};Ee(ae,{argumentMatches:()=>Le,defaultIsDataResponse:()=>Be,getOperationName:()=>w,getOverrides:()=>k,getTags:()=>ze,operationMatches:()=>se});import{getOperationName as _e}from"oazapfts/generate";function Be(r,e){if(e&&r==="default")return!0;let t=Number(r);return!Number.isNaN(t)&&t>=200&&t<300}function w({verb:r,path:e}){return _e(r,e,void 0)}function ze({verb:r,pathItem:e}){return r?e[r]?.tags||[]:[]}function ie(r){let e=Array.isArray(r)?r:[r];return function(n){return r?e.some(o=>typeof o=="string"?o===n:o?.test(n)):!0}}function se(r){let e=typeof r=="function"?r:ie(r);return function(n){if(!r)return!0;let o=w(n);return e(o,n)}}function Le(r){let e=typeof r=="function"?r:ie(r);return function(n){if(!r||n.in==="path")return!0;let o=n.name;return e(o,n)}}function k(r,e){return e?.find(t=>se(t.pattern)(r))}var V=W(()=>{"use strict";p()});p();import D from"commander";import{createRequire as nt}from"node:module";p();import qe from"commander";import{createRequire as Ge}from"node:module";import{resolve as U}from"node:path";import{existsSync as M,rmSync as Ie,readdirSync as De,statSync as je,mkdirSync as Me}from"node:fs";import Q from"node:path";var T=Ge(g);function Ke(r){let e=new Map;if(!M(r))return e;function t(n){try{let o=De(n);for(let i of o){let a=Q.join(n,i);if(je(a).isDirectory())t(a);else if(i==="enhanceEndpoints.ts"){let u=T("node:fs").readFileSync(a);e.set(a,u)}}}catch{}}return t(r),e}function ke(r){for(let[e,t]of r)try{let n=Q.dirname(e);M(n)||Me(n,{recursive:!0}),T("node:fs").writeFileSync(e,t)}catch(n){console.warn(`Failed to restore ${e}:`,n)}}function _(r){let e=["/","/usr","/etc","/var","/home","/Users",".",".."],t=U(r);if(e.some(n=>t===U(n))&&(console.error(`Dangerous path detected: ${t}. Refusing to delete.`),process.exit(1)),M(r)){console.log(`Cleaning output directory: ${r}`);let n=Ke(r);Ie(r,{recursive:!0,force:!0}),n.size>0&&(ke(n),console.log(`Protected ${n.size} enhanceEndpoints.ts file(s) from deletion`)),console.log(`Directory cleaned: ${r}`)}}function B(){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 z(r){(!r||!/\.([mc]?(jsx?|tsx?)|jsonc?)?$/.test(r))&&(console.error("Please provide a valid configuration file."),qe.help())}function L(r,e){/\.[mc]?tsx?$/.test(r)&&!e&&(console.error("Encountered a TypeScript config file, but neither esbuild-runner nor ts-node are installed."),process.exit(1))}import{dirname as ot,resolve as it}from"node:path";p();p();import $ from"node:path";import ve from"typescript";p();p();function S(r){return r.replace(r[0],r[0].toUpperCase())}p();import K from"node:fs";import Ve from"node:path";p();function H(r){try{new URL(r)}catch{return!1}return!0}async function Z(r,e){if(!H(r))throw new Error(`remoteFile must be a valid URL: ${r}`);try{let t=Ve.dirname(e);K.existsSync(t)||await K.promises.mkdir(t,{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 K.promises.writeFile(e,o,"utf-8"),console.log(`Schema downloaded from ${r} to ${e}`),e}catch(t){throw console.error(`Error downloading schema from ${r}:`,t),t}}p();p();var Y=["get","put","post","delete","options","head","patch","trace"];function J(r){return Object.entries(r.paths).flatMap(([e,t])=>t?Object.entries(t).filter(n=>Y.includes(n[0])).map(([n,o])=>({path:e,verb:n,pathItem:t,operation:o})):[])}p();import We from"@apidevtools/swagger-parser";import Ue from"swagger2openapi";async function X(r,e){let t=await We.bundle(r,{resolve:{http:e}});return"openapi"in t&&t.openapi.startsWith("3")?t:(await Ue.convertObj(t,{})).openapi}p();function ee(r,e,t,n){return n?n(r,e):t?.type?t.type==="query":r==="get"}var E=class{docCache={};async getDocument(e,t){if(this.docCache[e])return this.docCache[e];let n=await X(e,t);return this.docCache[e]=n,n}async downloadSchema(e,t){return Z(e,t)}getPaths(e){return Object.keys(e.paths||{})}clearCache(){this.docCache={}}};p();import te from"lodash.camelcase";var R=class{groupPaths(e,t){let{groupKeyMatch:n,outputDir:o}=t,i=e.reduce((s,u)=>{let m=n(u),l=m?te(m):"_common";return s[l]||(s[l]=[]),s[l].push(u),s},{}),a={};for(let[s,u]of Object.entries(i))a[s]={groupKey:s,paths:u,outputPath:`${o}/${s}/query.service.ts`};return a}createGroupFilter(e,t){return(n,o)=>{let i=o.path,a=te(t.groupKeyMatch(i)||"");return a!==e&&(a||"_common")!==e?!1:t.filterEndpoint?t.filterEndpoint(n,i,e):!0}}};p();import oe from"node:fs";import v from"node:path";p();import Qe from"node:path";import re from"node:fs";async function ne(r){let e=Qe.dirname(r);re.existsSync(e)||await re.promises.mkdir(e,{recursive:!0})}var N=class{async writeFile(e,t){try{let n=v.resolve(process.cwd(),e);return v.basename(n)==="enhanceEndpoints.ts"&&oe.existsSync(n)?{path:n,success:!0}:(await ne(n),oe.writeFileSync(n,t),{path:n,success:!0})}catch(n){return{path:e,success:!1,error:n}}}async writeFiles(e){let t=[];for(let[n,o]of Object.entries(e)){let i=await this.writeFile(n,o);t.push(i)}return t}async writeGroupFiles(e,t){let n={};return t.types&&(n[v.join(e,"types.ts")]=t.types),t.queryService&&(n[v.join(e,"query.generated.ts")]=t.queryService),t.enhanceEndpoints&&(n[v.join(e,"enhanceEndpoints.ts")]=t.enhanceEndpoints),t.index&&(n[v.join(e,"index.ts")]=t.index),this.writeFiles(n)}async writeSharedFiles(e,t){let n={};return t.commonTypes&&(n[v.join(e,"common-types.ts")]=t.commonTypes),t.doNotModify&&(n[v.join(e,"DO_NOT_MODIFY.md")]=t.doNotModify),t.utils&&(n[v.join(e,"utils.ts")]=t.utils),this.writeFiles(n)}async writeSchemaFile(e,t){let n={};return n[v.join(e,"schema.ts")]=t,this.writeFiles(n)}};p();import He from"oazapfts/generate";var F=class{constructor(e,t){this.v3Doc=e;this.apiGen=new He(e,{unionUndefined:t.unionUndefined,mergeReadWriteOnly:t.mergeReadWriteOnly})}apiGen;initialize(){this.apiGen.spec.components?.schemas&&(Object.keys(this.apiGen.spec.components.schemas).forEach(e=>{let t=this.apiGen.spec.components.schemas[e];t&&typeof t=="object"&&"title"in t&&delete t.title}),this.apiGen.preprocessComponents(this.apiGen.spec.components.schemas),Object.keys(this.apiGen.spec.components.schemas).forEach(e=>{try{this.apiGen.getRefAlias({$ref:`#/components/schemas/${e}`})}catch{}}))}getOperationDefinitions(e){let{operationMatches:t}=(V(),Ne(ae));return J(this.v3Doc).filter(t(e))}getApiGenerator(){return this.apiGen}getDocument(){return this.v3Doc}getSchemaTypeNames(){return new Set}};p();function pe(){return`/* eslint-disable */
3
3
  // [Warning] Generated automatically - do not edit manually
4
4
 
5
5
  export interface RequestOptions {
@@ -20,12 +20,12 @@ export type IRestFulEndpointsQueryReturn<TVariables> = TVariables extends void ?
20
20
  variables: TVariables;
21
21
  fetchOptions?: IRequestConfig;
22
22
  };
23
- `}c();import d from"typescript";function He(n){return n.charAt(0).toUpperCase()+n.slice(1)}function Ze(n,e,t){return d.transform(n,[r=>o=>d.visitNode(o,function i(p){return d.isIdentifier(p)&&p.text===e?d.factory.createIdentifier(t):d.visitEachChild(p,i,r)})]).transformed[0]}function ae(n){let e=d.createPrinter({newLine:d.NewLineKind.LineFeed}),t=d.createSourceFile("component-schema.ts","",d.ScriptTarget.Latest,!1,d.ScriptKind.TS),r=[],o={};return Object.entries(n).forEach(([i,p])=>{let a=He(i);o[i]=a;let u=Ze(p,i,a),s=e.printNode(d.EmitHint.Unspecified,u,t);r.push(s)}),`/* eslint-disable */
23
+ `}p();import h from"typescript";function Ze(r){return r.charAt(0).toUpperCase()+r.slice(1)}function Ye(r,e,t){return h.transform(r,[n=>o=>h.visitNode(o,function i(a){return h.isIdentifier(a)&&a.text===e?h.factory.createIdentifier(t):h.visitEachChild(a,i,n)})]).transformed[0]}function ce(r){let e=h.createPrinter({newLine:h.NewLineKind.LineFeed}),t=h.createSourceFile("component-schema.ts","",h.ScriptTarget.Latest,!1,h.ScriptKind.TS),n=[],o={};return Object.entries(r).forEach(([i,a])=>{let s=Ze(i);o[i]=s;let u=Ye(a,i,s),m=e.printNode(h.EmitHint.Unspecified,u,t);n.push(m)}),`/* eslint-disable */
24
24
  // [Warning] Generated automatically - do not edit manually
25
25
 
26
- ${r.join(`
26
+ ${n.join(`
27
27
  `)}
28
- `}c();function pe(){return`# \u8ACB\u52FF\u4FEE\u6539\u6B64\u8CC7\u6599\u593E
28
+ `}p();function ue(){return`# \u8ACB\u52FF\u4FEE\u6539\u6B64\u8CC7\u6599\u593E
29
29
 
30
30
  \u26A0\uFE0F **\u91CD\u8981\u63D0\u9192\uFF1A\u8ACB\u52FF\u4FEE\u6539\u6B64\u8CC7\u6599\u593E\u4E2D\u7684\u4EFB\u4F55\u6A94\u6848**
31
31
 
@@ -44,47 +44,48 @@ ${r.join(`
44
44
  \u9019\u4E9B\u6A94\u6848\u662F\u7531 @acrool/rtk-query-codegen-openapi \u7522\u751F\u5668\u6240\u5EFA\u7ACB\u3002
45
45
 
46
46
  \u5982\u6709\u7591\u554F\uFF0C\u8ACB\u53C3\u8003\u5C08\u6848\u6587\u4EF6\u6216\u806F\u7E6B\u958B\u767C\u5718\u968A\u3002
47
- `}c();import ge from"typescript";c();K();import{supportDeepObjects as Ye}from"oazapfts/generate";var E=class{constructor(e){this.options=e}extractEndpointInfos(e){return e.map(t=>this.extractSingleEndpointInfo(t))}extractSingleEndpointInfo(e){let{verb:t,path:r,operation:o}=e,{operationNameSuffix:i="",argSuffix:p="Req",responseSuffix:a="Res",queryMatch:u,endpointOverrides:s}=this.options,m=R({verb:t,path:r}),f=i?T(m+i):m,y=T(m+i+p),C=T(m+i+a),P=J(t,r,M(e,s),u),v=`${m.replace(/([A-Z])/g,"_$1").toUpperCase()}`,x=o.summary||`${t.toUpperCase()} ${r}`,{queryParams:ve,pathParams:Oe,isVoidArg:xe,hasRequestBody:be}=this.extractParameters(e),Pe=this.extractContentType(o),Ce=Array.isArray(o.tags)?o.tags:[];return{operationName:f,argTypeName:y,responseTypeName:C,isQuery:P,verb:t.toUpperCase(),path:r,queryKeyName:v,queryParams:ve,pathParams:Oe,isVoidArg:xe,summary:x,contentType:Pe,hasRequestBody:be,tags:Ce}}extractParameters(e){let{operation:t,pathItem:r}=e,o=this.resolveArray(t.parameters),i=this.resolveArray(r.parameters).filter(f=>!o.some(y=>y.name===f.name&&y.in===f.in)),p=Ye([...i,...o]).filter(f=>f.in!=="header"),a=p.filter(f=>f.in==="query"),u=p.filter(f=>f.in==="path"),s=!!t.requestBody,m=a.length===0&&u.length===0&&!t.requestBody;return{queryParams:a,pathParams:u,isVoidArg:m,hasRequestBody:s}}resolveArray(e){return e?Array.isArray(e)?e:[e]:[]}extractContentType(e){if(!e.requestBody)return"application/json";let t=e.requestBody.content;if(!t||typeof t!="object")return"application/json";let r=Object.keys(t);return r.length===0?"application/json":r[0]}};c();var Je=n=>n.charAt(0).toUpperCase()+n.slice(1);function ue(n,e,t,r){let o={};t&&Object.keys(t).forEach(s=>{if(o[s]=s,s.endsWith("Vo")){let m=s.slice(0,-2)+"VO";o[m]=s}if(s.endsWith("Dto")){let m=s.slice(0,-3)+"DTO";o[m]=s}});let i=`/* eslint-disable */
47
+ `}p();import fe from"typescript";p();V();import{supportDeepObjects as Je}from"oazapfts/generate";var q=class{constructor(e){this.options=e}extractEndpointInfos(e){return e.map(t=>this.extractSingleEndpointInfo(t))}extractSingleEndpointInfo(e){let{verb:t,path:n,operation:o}=e,{operationNameSuffix:i="",argSuffix:a="Req",responseSuffix:s="Res",queryMatch:u,endpointOverrides:m}=this.options,l=w({verb:t,path:n}),c=i?S(l+i):l,f=S(l+i+a),x=S(l+i+s),d=ee(t,n,k(e,m),u),A=`${l.replace(/([A-Z])/g,"_$1").toUpperCase()}`,P=o.summary||`${t.toUpperCase()} ${n}`,{queryParams:b,pathParams:C,isVoidArg:be,hasRequestBody:Te}=this.extractParameters(e),Pe=this.extractContentType(o),Ce=Array.isArray(o.tags)?o.tags:[];return{operationName:c,argTypeName:f,responseTypeName:x,isQuery:d,verb:t.toUpperCase(),path:n,queryKeyName:A,queryParams:b,pathParams:C,isVoidArg:be,summary:P,contentType:Pe,hasRequestBody:Te,tags:Ce}}extractParameters(e){let{operation:t,pathItem:n}=e,o=this.resolveArray(t.parameters),i=this.resolveArray(n.parameters).filter(c=>!o.some(f=>f.name===c.name&&f.in===c.in)),a=Je([...i,...o]).filter(c=>c.in!=="header"),s=a.filter(c=>c.in==="query"),u=a.filter(c=>c.in==="path"),m=!!t.requestBody,l=s.length===0&&u.length===0&&!t.requestBody;return{queryParams:s,pathParams:u,isVoidArg:l,hasRequestBody:m}}resolveArray(e){return e?Array.isArray(e)?e:[e]:[]}extractContentType(e){if(!e.requestBody)return"application/json";let t=e.requestBody.content;if(!t||typeof t!="object")return"application/json";let n=Object.keys(t);return n.length===0?"application/json":n[0]}};p();var Xe=r=>r.charAt(0).toUpperCase()+r.slice(1);function le(r,e,t,n){let o={};t&&Object.keys(t).forEach(m=>{if(o[m]=m,m.endsWith("Vo")){let l=m.slice(0,-2)+"VO";o[l]=m}if(m.endsWith("Dto")){let l=m.slice(0,-3)+"DTO";o[l]=m}});let i=`/* eslint-disable */
48
48
  // [Warning] Generated automatically - do not edit manually
49
49
 
50
50
  `;t&&Object.keys(t).length>0&&(i+=`import * as Schema from "../schema";
51
51
  `),i+=`
52
- `;let a=[],u=[];return n.forEach(s=>{let m=s.argTypeName,f=s.responseTypeName;if(m){let y=Xe(s,r,o);y.trim()===""?u.push(`export type ${m} = void;`,""):u.push(`export type ${m} = {`,y,"};","")}if(f){let y=et(s,r,o);y.trim()===""?u.push(`export type ${f} = void;`,""):u.push(`export type ${f} = {`,y,"};","")}}),u.length>0&&a.push(u.join(`
53
- `)),a.length===0&&a.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+a.join(`
52
+ `;let s=[],u=[];return r.forEach(m=>{let l=m.argTypeName,c=m.responseTypeName;if(l){let f=et(m,n,o);f.trim()===""?u.push(`export type ${l} = void;`,""):u.push(`export type ${l} = {`,f,"};","")}if(c){let f=tt(m,n,o);f.trim()===""?u.push(`export type ${c} = void;`,""):u.push(`export type ${c} = {`,f,"};","")}}),u.length>0&&s.push(u.join(`
53
+ `)),s.length===0&&s.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+s.join(`
54
54
 
55
- `)}function Xe(n,e,t={}){let r=[];n.queryParams&&n.queryParams.length>0&&n.queryParams.forEach(i=>{let p=i.required?"":"?",a=ce(i,t);r.push(` ${i.name}${p}: ${a};`)}),n.pathParams&&n.pathParams.length>0&&n.pathParams.forEach(i=>{let p=i.required?"":"?",a=ce(i,t);r.push(` ${i.name}${p}: ${a};`)});let o=e?.find(i=>i.operation?.operationId===n.operationName||i.operation?.operationId===n.operationName.toLowerCase()||i.verb===n.verb.toLowerCase()&&i.path===n.path);if(o?.operation?.requestBody){let p=o.operation.requestBody.content,a=p["application/json"]||p["*/*"],u=p["multipart/form-data"]||p["application/x-www-form-urlencoded"];if(a?.schema){let s=O(a.schema,t,1);r.push(` body: ${s};`)}else if(u?.schema){let s=O(u.schema,t,1);r.push(` body: ${s};`)}else{let s=Object.values(p)[0];if(s?.schema){let m=O(s.schema,t,1);r.push(` body: ${m};`)}else r.push(" body?: any; // Request body from OpenAPI")}}return r.length===0?"":r.join(`
56
- `)}function et(n,e,t={}){let r=[],o=e?.find(i=>i.operation?.operationId===n.operationName||i.operation?.operationId===n.operationName.toLowerCase()||i.verb===n.verb.toLowerCase()&&i.path===n.path);if(o?.operation?.responses){let i=o.operation.responses[200]||o.operation.responses[201];if(i?.content){let p=i.content["application/json"]||i.content["*/*"]||Object.values(i.content)[0];if(p?.schema){let a=tt(p.schema,t);r.push(...a)}else r.push(" // Success response from OpenAPI"),r.push(" data?: any;")}}return r.length===0?"":r.join(`
57
- `)}function tt(n,e={}){let t=[];if(n.type==="object"&&n.properties){let r=n.required||[];Object.entries(n.properties).forEach(([o,i])=>{let a=r.includes(o)?"":"?",u=O(i,e,1),m=/[^a-zA-Z0-9_$]/.test(o)?`"${o}"`:o;i.description&&t.push(` /** ${i.description} */`),t.push(` ${m}${a}: ${u};`)})}return t}function O(n,e={},t=0){if(!n)return"any";if(n.$ref){let o=n.$ref;if(o.startsWith("#/components/schemas/")){let i=o.replace("#/components/schemas/",""),p=e[i]||i,u=`Schema.${Je(p)}`;return n.nullable?`${u} | null`:u}}let r;switch(n.type){case"string":n.enum?r=n.enum.map(p=>`"${p}"`).join(" | "):n.format==="binary"?r="Blob":r="string";break;case"number":case"integer":r="number";break;case"boolean":r="boolean";break;case"array":let o=n.items?O(n.items,e,t):"any";r=o.includes("|")?`(${o})[]`:`${o}[]`;break;case"object":if(n.properties){let p=Object.entries(n.properties);if(p.length===0)n.additionalProperties?r=`Record<string, ${n.additionalProperties===!0?"any":O(n.additionalProperties,e,t)}>`:r="{}";else{let a=" ".repeat(t+1),u=" ".repeat(t),s=[];p.forEach(([m,f])=>{let C=(n.required||[]).includes(m)?"":"?",P=O(f,e,t+1),x=/[^a-zA-Z0-9_$]/.test(m)?`"${m}"`:m;f.description&&s.push(`${a}/** ${f.description} */`),s.push(`${a}${x}${C}: ${P};`)}),r=`{
58
- ${s.join(`
55
+ `)}function et(r,e,t={}){let n=[];r.queryParams&&r.queryParams.length>0&&r.queryParams.forEach(i=>{let a=i.required?"":"?",s=me(i,t);n.push(` ${i.name}${a}: ${s};`)}),r.pathParams&&r.pathParams.length>0&&r.pathParams.forEach(i=>{let a=i.required?"":"?",s=me(i,t);n.push(` ${i.name}${a}: ${s};`)});let o=e?.find(i=>i.operation?.operationId===r.operationName||i.operation?.operationId===r.operationName.toLowerCase()||i.verb===r.verb.toLowerCase()&&i.path===r.path);if(o?.operation?.requestBody){let a=o.operation.requestBody.content,s=a["application/json"]||a["*/*"],u=a["multipart/form-data"]||a["application/x-www-form-urlencoded"];if(s?.schema){let m=O(s.schema,t,1);n.push(` body: ${m};`)}else if(u?.schema){let m=O(u.schema,t,1);n.push(` body: ${m};`)}else{let m=Object.values(a)[0];if(m?.schema){let l=O(m.schema,t,1);n.push(` body: ${l};`)}else n.push(" body?: any; // Request body from OpenAPI")}}return n.length===0?"":n.join(`
56
+ `)}function tt(r,e,t={}){let n=[],o=e?.find(i=>i.operation?.operationId===r.operationName||i.operation?.operationId===r.operationName.toLowerCase()||i.verb===r.verb.toLowerCase()&&i.path===r.path);if(o?.operation?.responses){let i=o.operation.responses[200]||o.operation.responses[201];if(i?.content){let a=i.content["application/json"]||i.content["*/*"]||Object.values(i.content)[0];if(a?.schema){let s=rt(a.schema,t);n.push(...s)}else n.push(" // Success response from OpenAPI"),n.push(" data?: any;")}}return n.length===0?"":n.join(`
57
+ `)}function rt(r,e={}){let t=[];if(r.type==="object"&&r.properties){let n=r.required||[];Object.entries(r.properties).forEach(([o,i])=>{let s=n.includes(o)?"":"?",u=O(i,e,1),l=/[^a-zA-Z0-9_$]/.test(o)?`"${o}"`:o;i.description&&t.push(` /** ${i.description} */`),t.push(` ${l}${s}: ${u};`)})}return t}function O(r,e={},t=0){if(!r)return"any";if(r.$ref){let o=r.$ref;if(o.startsWith("#/components/schemas/")){let i=o.replace("#/components/schemas/",""),a=e[i]||i,u=`Schema.${Xe(a)}`;return r.nullable?`${u} | null`:u}}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,e,t):"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,e,t)}>`:n="{}";else{let s=" ".repeat(t+1),u=" ".repeat(t),m=[];a.forEach(([l,c])=>{let x=(r.required||[]).includes(l)?"":"?",d=O(c,e,t+1),P=/[^a-zA-Z0-9_$]/.test(l)?`"${l}"`:l;c.description&&m.push(`${s}/** ${c.description} */`),m.push(`${s}${P}${x}: ${d};`)}),n=`{
58
+ ${m.join(`
59
59
  `)}
60
- ${u}}`}}else n.additionalProperties?r=`Record<string, ${n.additionalProperties===!0?"any":O(n.additionalProperties,e,t)}>`:r="any";break;default:r="any";break}return n.nullable?`${r} | null`:r}function ce(n,e={}){return n.schema?O(n.schema,e):"any"}c();function me(n,e){let{groupKey:t}=e,r=e.httpClient?.importReturnTypeName||e.httpClient?.importName||"IRestFulEndpointsQueryReturn",o=n.map(s=>{let m=s.isQuery?"query":"mutation",f=s.isVoidArg?"void":`${r}<${s.argTypeName}>`,y=s.path;s.pathParams&&s.pathParams.length>0?(s.pathParams.forEach(v=>{y=y.replace(`{${v.name}}`,`\${queryArg.variables.${v.name}}`)}),y="`"+y+"`"):y=`"${y}"`;let C="";s.queryParams&&s.queryParams.length>0&&(C=`
60
+ ${u}}`}}else r.additionalProperties?n=`Record<string, ${r.additionalProperties===!0?"any":O(r.additionalProperties,e,t)}>`:n="any";break;default:n="any";break}return r.nullable?`${n} | null`:n}function me(r,e={}){return r.schema?O(r.schema,e):"any"}p();function ge(r,e){let{groupKey:t}=e,n=e.httpClient?.importReturnTypeName||"IRestFulEndpointsQueryReturn",o=r.map(c=>{let f=c.isQuery?"query":"mutation",x=c.isVoidArg?"void":`${n}<${c.argTypeName}>`,d=c.path;c.pathParams&&c.pathParams.length>0?(c.pathParams.forEach(b=>{d=d.replace(`{${b.name}}`,`\${queryArg.variables.${b.name}}`)}),d="`"+d+"`"):d=`"${d}"`;let A="";c.queryParams&&c.queryParams.length>0&&(A=`
61
61
  params: {
62
- ${s.queryParams.map(x=>` ${x.name}: queryArg.variables.${x.name},`).join(`
62
+ ${c.queryParams.map(C=>` ${C.name}: queryArg.variables.${C.name},`).join(`
63
63
  `)}
64
- },`);let P="";if(s.tags&&s.tags.length>0){let v=s.tags.map(x=>`"${x}"`).join(", ");s.isQuery?P=`
65
- providesTags: [${v}],`:P=`
66
- invalidatesTags: [${v}],`}return` /** ${s.summary||s.operationName} */
67
- ${s.operationName}: build.${m}<
68
- ${s.responseTypeName},
69
- ${f}
64
+ },`);let P="";if(c.tags&&c.tags.length>0){let b=c.tags.map(C=>`ECacheTagTypes.${C}`).join(", ");c.isQuery?P=`
65
+ providesTags: [${b}],`:P=`
66
+ invalidatesTags: [${b}],`}return` /** ${c.summary||c.operationName} */
67
+ ${c.operationName}: build.${f}<
68
+ ${c.responseTypeName},
69
+ ${x}
70
70
  >({${P}
71
71
  query: (queryArg) => ({
72
- url: ${y},
73
- method: "${s.verb.toUpperCase()}",
74
- contentType: "${s.contentType}",${C}${s.hasRequestBody?`
75
- body: queryArg.variables.body,`:""}${s.isVoidArg?"":`
72
+ url: ${d},
73
+ method: "${c.verb.toUpperCase()}",
74
+ contentType: "${c.contentType}",${A}${c.hasRequestBody?`
75
+ body: queryArg.variables.body,`:""}${c.isVoidArg?"":`
76
76
  fetchOptions: queryArg?.fetchOptions,`}
77
77
  }),
78
78
  }),`}).join(`
79
- `),i=[...new Set([...n.map(s=>s.argTypeName),...n.map(s=>s.responseTypeName)])].filter(s=>s!=="VoidApiArg"),p=i.length>0?`import type { ${i.join(", ")} } from "./types";`:"",a=e.apiConfiguration?`import {${e.apiConfiguration.importName} as api} from "${e.apiConfiguration.file.replace(/\.ts$/,"")}";
79
+ `),i=[...new Set([...r.map(c=>c.argTypeName),...r.map(c=>c.responseTypeName)])].filter(c=>c!=="VoidApiArg"),a=i.length>0?`import type { ${i.join(", ")} } from "./types";`:"",s=e.apiConfiguration?`import {${e.apiConfiguration.importName} as api} from "${e.apiConfiguration.file.replace(/\.ts$/,"")}";
80
80
  `:`import {baseApi as api} from "../../../library/redux/baseApi";
81
81
  `,u=e.httpClient?`import {${e.httpClient.importReturnTypeName}} from "${e.httpClient.file}";
82
82
  `:`import {IRestFulEndpointsQueryReturn} from "@acrool/react-fetcher";
83
- `;return`/* eslint-disable */
83
+ `,l=r.some(c=>c.tags&&c.tags.length>0)?`import {ECacheTagTypes} from "../tagTypes";
84
+ `:"";return`/* eslint-disable */
84
85
  // [Warning] Generated automatically - do not edit manually
85
86
 
86
- ${a}${u}
87
- ${p}
87
+ ${s}${u}${l}
88
+ ${a}
88
89
 
89
90
 
90
91
  const injectedRtkApi = api.injectEndpoints({
@@ -94,21 +95,21 @@ ${o}
94
95
  });
95
96
 
96
97
  export const {
97
- ${n.map(s=>{let m=s.operationName.charAt(0).toUpperCase()+s.operationName.slice(1);if(s.isQuery){let f=`use${m}Query`;if(e.useLazyQueries){let y=`useLazy${m}Query`;return` ${f},
98
- ${y},`}else return` ${f},`}else return` ${`use${m}Mutation`},`}).join(`
98
+ ${r.map(c=>{let f=c.operationName.charAt(0).toUpperCase()+c.operationName.slice(1);if(c.isQuery){let x=`use${f}Query`;if(e.useLazyQueries){let d=`useLazy${f}Query`;return` ${x},
99
+ ${d},`}else return` ${x},`}else return` ${`use${f}Mutation`},`}).join(`
99
100
  `)}
100
101
  } = injectedRtkApi;
101
102
 
102
103
  export default injectedRtkApi;
103
- `}c();function le(n,e){let{groupKey:t,cacheTagTypes:r}=e,o=n.map(p=>p.isQuery?` ${p.operationName}: {
104
+ `}p();function ye(r,e){let{groupKey:t,cacheTagTypes:n}=e,o=r.map(a=>a.isQuery?` ${a.operationName}: {
104
105
  providesTags: (result, error, arg) => [],
105
- },`:` ${p.operationName}: {
106
+ },`:` ${a.operationName}: {
106
107
  invalidatesTags: (result, error, arg) => [],
107
108
  },`).join(`
108
109
  `),i=`/* eslint-disable */
109
110
  // [Warning] Generated automatically - do not edit manually
110
111
 
111
- `;return r&&(i+=`import { ${r.importReturnTypeName} } from "${r.file}";
112
+ `;return n&&(i+=`import { ${n.importReturnTypeName} } from "${n.file}";
112
113
  `),i+=`import api from "./query.generated";
113
114
  `,`${i}
114
115
  const enhancedApi = api.enhanceEndpoints({
@@ -118,13 +119,13 @@ ${o}
118
119
  });
119
120
 
120
121
  export default enhancedApi;
121
- `}var w=class{constructor(e,t){this.parserService=e;this.options=t;this.infoExtractor=new E(t)}infoExtractor;async generate(){let e=this.parserService.getOperationDefinitions(this.options.filterEndpoints),t=this.infoExtractor.extractEndpointInfos(e);return this.generateRtkQueryCode(t)}generateRtkQueryCode(e){let t=this.generateTypes(e),r=me(e,this.options),o=le(e,this.options),i=this.generateIndex();return{operationNames:e.map(a=>a.operationName),files:{types:t,queryService:r,index:i,enhanceEndpoints:o}}}generateTypes(e){let t={...this.options,apiConfiguration:this.options.apiConfiguration||{file:"@/store/webapi",importName:"WebApiConfiguration"}},o=this.parserService.getApiGenerator().aliases.reduce((p,a)=>{if(ge.isInterfaceDeclaration(a)||ge.isTypeAliasDeclaration(a)){let u=a.name.text;return{...p,[u]:a}}return p},{}),i=this.parserService.getOperationDefinitions(this.options.filterEndpoints);return ue(e,t,o,i)}generateIndex(){let e=this.options.groupKey||"";return`/* eslint-disable */
122
+ `}var G=class{constructor(e,t){this.parserService=e;this.options=t;this.infoExtractor=new q(t)}infoExtractor;async generate(){let e=this.parserService.getOperationDefinitions(this.options.filterEndpoints),t=this.infoExtractor.extractEndpointInfos(e);return this.generateRtkQueryCode(t)}generateRtkQueryCode(e){let t=this.generateTypes(e),n=ge(e,this.options),o=ye(e,this.options),i=this.generateIndex(),a=e.map(u=>u.operationName),s=new Set;return e.forEach(u=>{u.tags&&Array.isArray(u.tags)&&u.tags.forEach(m=>s.add(m))}),{operationNames:a,tags:Array.from(s),files:{types:t,queryService:n,index:i,enhanceEndpoints:o}}}generateTypes(e){let t={...this.options,apiConfiguration:this.options.apiConfiguration||{file:"@/store/webapi",importName:"WebApiConfiguration"}},o=this.parserService.getApiGenerator().aliases.reduce((a,s)=>{if(fe.isInterfaceDeclaration(s)||fe.isTypeAliasDeclaration(s)){let u=s.name.text;return{...a,[u]:s}}return a},{}),i=this.parserService.getOperationDefinitions(this.options.filterEndpoints);return le(e,t,o,i)}generateIndex(){let e=this.options.groupKey||"";return`/* eslint-disable */
122
123
  // [Warning] Generated automatically - do not edit manually
123
124
 
124
125
  export { default as ${e?`${e.charAt(0).toLowerCase()+e.slice(1)}Api`:"api"} } from "./enhanceEndpoints";
125
126
  export * from "./query.generated";
126
127
  export * from "./types";
127
- `}};c();function fe(){return`/* eslint-disable */
128
+ `}};p();function de(){return`/* eslint-disable */
128
129
  // [Warning] Generated automatically - do not edit manually
129
130
 
130
131
  /**
@@ -137,10 +138,22 @@ export function withoutUndefined(obj?: Record<string, any>) {
137
138
  );
138
139
  }
139
140
 
140
- `}var q=class{_options;openApiService=new A;groupService=new $;fileWriterService=new S;openApiDoc=null;parserService=null;schemaInterfaces={};actualSchemaFile="";generatedContent={groups:[],commonTypes:"",componentSchema:"",doNotModify:"",utils:""};constructor(e){this._options=e}async generateAll(){return await this.prepare(),await this.generateApi(),this.generateCommonTypesContent(),this.generateSchemaContent(),this.generateUtilsContent(),this.generateDoNotModifyContent(),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 N(this.openApiDoc,this._options),this.parserService.initialize();let e=this.parserService.getApiGenerator();this.schemaInterfaces=e.aliases.reduce((t,r)=>{if(ye.isInterfaceDeclaration(r)||ye.isTypeAliasDeclaration(r)){let o=r.name.text;return{...t,[o]:r}}return t},{})}async generateApi(){if(!this.openApiDoc||!this.parserService)throw new Error("\u8ACB\u5148\u8ABF\u7528 prepare() \u65B9\u6CD5");let e=this.openApiService.getPaths(this.openApiDoc),t=this.groupService.groupPaths(e,this._options.outputFiles);for(let r of Object.values(t))try{let o=await this.generateApiGroupContent(this._options,r);o.operationNames.length>0&&this.generatedContent.groups.push({groupKey:r.groupKey,outputPath:r.outputPath,content:o})}catch(o){throw new Error(`\u7FA4\u7D44 ${r.groupKey} \u751F\u6210\u5931\u6557: ${o}`)}}async generateCommonTypesContent(){this.generatedContent.commonTypes=se()}async generateSchemaContent(){this.generatedContent.componentSchema=ae(this.schemaInterfaces)}async generateDoNotModifyContent(){this.generatedContent.doNotModify=pe()}async generateUtilsContent(){this.generatedContent.utils=fe()}async release(){let e=[],t=[],r=[];try{for(let a of this.generatedContent.groups)try{if(a.content?.files){let u=F.dirname(a.outputPath),s=await this.fileWriterService.writeGroupFiles(u,{types:a.content.files.types,queryService:a.content.files.queryService,enhanceEndpoints:a.content.files.enhanceEndpoints,index:a.content.files.index});e.push(...s),r.push(a.groupKey)}}catch(u){t.push(new Error(`\u5BEB\u5165\u7FA4\u7D44 ${a.groupKey} \u5931\u6557: ${u}`))}let o=this.generatedContent.groups[0]?F.dirname(F.dirname(this.generatedContent.groups[0].outputPath)):"./generated";if(this.generatedContent.commonTypes||this.generatedContent.doNotModify||this.generatedContent.utils){let a=await this.fileWriterService.writeSharedFiles(o,{commonTypes:this.generatedContent.commonTypes||void 0,doNotModify:this.generatedContent.doNotModify||void 0,utils:this.generatedContent.utils||void 0});e.push(...a)}if(this.generatedContent.componentSchema){let a=await this.fileWriterService.writeSchemaFile(o,this.generatedContent.componentSchema);e.push(...a)}let i=this.generateMainIndex(r),p=await this.fileWriterService.writeFile(F.join(o,"index.ts"),i);e.push(p)}catch(o){t.push(o)}return{success:t.length===0,writtenFiles:e,errors:t,generatedGroups:r}}async generateApiGroupContent(e,t){let{outputFiles:r,...o}=e,i={...o,schemaFile:this.actualSchemaFile,outputFile:t.outputPath,sharedTypesFile:`${r.outputDir}/common-types.ts`,filterEndpoints:this.groupService.createGroupFilter(t.groupKey,r),queryMatch:r.queryMatch,groupKey:t.groupKey};if(!this.openApiDoc||!this.parserService)throw new Error("OpenAPI \u6587\u6A94\u672A\u521D\u59CB\u5316\uFF0C\u8ACB\u5148\u8ABF\u7528 prepare()");return await new w(this.parserService,i).generate()}generateMainIndex(e){return`/* eslint-disable */
141
+ `}p();function he(r){return r.length===0?`/* eslint-disable */
141
142
  // [Warning] Generated automatically - do not edit manually
142
143
 
143
- ${e.map(r=>`export * from "./${r}";`).join(`
144
+ export enum ECacheTagTypes {
145
+ }
146
+ `:`/* eslint-disable */
147
+ // [Warning] Generated automatically - do not edit manually
148
+
149
+ export enum ECacheTagTypes {
150
+ ${r.sort().map(t=>` ${t} = '${t}',`).join(`
151
+ `)}
152
+ }
153
+ `}var I=class{_options;openApiService=new E;groupService=new R;fileWriterService=new N;openApiDoc=null;parserService=null;schemaInterfaces={};actualSchemaFile="";generatedContent={groups:[],commonTypes:"",componentSchema:"",doNotModify:"",utils:"",tagTypes:""};allTags=new Set;constructor(e){this._options=e}async generateAll(){return await this.prepare(),await this.generateApi(),this.generateCommonTypesContent(),this.generateSchemaContent(),this.generateUtilsContent(),this.generateDoNotModifyContent(),this.generateTagTypesContent(),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 F(this.openApiDoc,this._options),this.parserService.initialize();let e=this.parserService.getApiGenerator();this.schemaInterfaces=e.aliases.reduce((t,n)=>{if(ve.isInterfaceDeclaration(n)||ve.isTypeAliasDeclaration(n)){let o=n.name.text;return{...t,[o]:n}}return t},{})}async generateApi(){if(!this.openApiDoc||!this.parserService)throw new Error("\u8ACB\u5148\u8ABF\u7528 prepare() \u65B9\u6CD5");let e=this.openApiService.getPaths(this.openApiDoc),t=this.groupService.groupPaths(e,this._options.outputFiles);for(let n of Object.values(t))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(i=>this.allTags.add(i)))}catch(o){throw new Error(`\u7FA4\u7D44 ${n.groupKey} \u751F\u6210\u5931\u6557: ${o}`)}}async generateCommonTypesContent(){this.generatedContent.commonTypes=pe()}async generateSchemaContent(){this.generatedContent.componentSchema=ce(this.schemaInterfaces)}async generateDoNotModifyContent(){this.generatedContent.doNotModify=ue()}async generateUtilsContent(){this.generatedContent.utils=de()}async generateTagTypesContent(){let e=Array.from(this.allTags);this.generatedContent.tagTypes=he(e)}async release(){let e=[],t=[],n=[];try{for(let s of this.generatedContent.groups)try{if(s.content?.files){let u=$.dirname(s.outputPath),m=await this.fileWriterService.writeGroupFiles(u,{types:s.content.files.types,queryService:s.content.files.queryService,enhanceEndpoints:s.content.files.enhanceEndpoints,index:s.content.files.index});e.push(...m),n.push(s.groupKey)}}catch(u){t.push(new Error(`\u5BEB\u5165\u7FA4\u7D44 ${s.groupKey} \u5931\u6557: ${u}`))}let o=this.generatedContent.groups[0]?$.dirname($.dirname(this.generatedContent.groups[0].outputPath)):"./generated";if(this.generatedContent.commonTypes||this.generatedContent.doNotModify||this.generatedContent.utils){let s=await this.fileWriterService.writeSharedFiles(o,{commonTypes:this.generatedContent.commonTypes||void 0,doNotModify:this.generatedContent.doNotModify||void 0,utils:this.generatedContent.utils||void 0});e.push(...s)}if(this.generatedContent.tagTypes){let s=await this.fileWriterService.writeFile($.join(o,"tagTypes.ts"),this.generatedContent.tagTypes);e.push(s)}if(this.generatedContent.componentSchema){let s=await this.fileWriterService.writeSchemaFile(o,this.generatedContent.componentSchema);e.push(...s)}let i=this.generateMainIndex(n),a=await this.fileWriterService.writeFile($.join(o,"index.ts"),i);e.push(a)}catch(o){t.push(o)}return{success:t.length===0,writtenFiles:e,errors:t,generatedGroups:n}}async generateApiGroupContent(e,t){let{outputFiles:n,...o}=e,i={...o,schemaFile:this.actualSchemaFile,outputFile:t.outputPath,sharedTypesFile:`${n.outputDir}/common-types.ts`,filterEndpoints:this.groupService.createGroupFilter(t.groupKey,n),queryMatch:n.queryMatch,groupKey:t.groupKey};if(!this.openApiDoc||!this.parserService)throw new Error("OpenAPI \u6587\u6A94\u672A\u521D\u59CB\u5316\uFF0C\u8ACB\u5148\u8ABF\u7528 prepare()");return await new G(this.parserService,i).generate()}generateMainIndex(e){return`/* eslint-disable */
154
+ // [Warning] Generated automatically - do not edit manually
155
+
156
+ ${e.map(n=>`export * from "./${n}";`).join(`
144
157
  `)}
145
- `}};async function de(n){let t=await new q(n).generateAll();if(!t.success&&t.errors.length>0)throw t.errors[0]}var he=rt(l);async function it(n){let e=ot(process.cwd(),n);process.chdir(nt(e));let t=he(e),r=t.default??t;"outputFiles"in r||(console.error('Configuration must include "outputFiles" property. Single file output is no longer supported.'),process.exit(1)),r.outputFiles&&r.outputFiles.outputDir&&W(r.outputFiles.outputDir);try{console.log("Generating multiple outputs..."),await de(r),console.log("Done")}catch(o){console.error("Generation failed:",o),process.exit(1)}}async function st(){let n=he("../../package.json"),e=Q();I.version(n.version).usage("<path/to/config.js>").parse(process.argv);let t=I.args[0];if(I.args.length===0){I.help();return}_(t),B(t,e),await it(t)}st().catch(n=>{console.error("CLI execution failed:",n),process.exit(1)});export{it as runGeneration};
158
+ `}};async function xe(r){let t=await new I(r).generateAll();if(!t.success&&t.errors.length>0)throw t.errors[0]}var Oe=nt(g);async function st(r){let e=it(process.cwd(),r);process.chdir(ot(e));let t=Oe(e),n=t.default??t;"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&&_(n.outputFiles.outputDir);try{console.log("Generating multiple outputs..."),await xe(n),console.log("Done")}catch(o){console.error("Generation failed:",o),process.exit(1)}}async function at(){let r=Oe("../../package.json"),e=B();D.version(r.version).usage("<path/to/config.js>").parse(process.argv);let t=D.args[0];if(D.args.length===0){D.help();return}z(t),L(t,e),await st(t)}at().catch(r=>{console.error("CLI execution failed:",r),process.exit(1)});export{st as runGeneration};
146
159
  //# sourceMappingURL=cli.mjs.map