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