@acrool/rtk-query-codegen-openapi 1.4.0-alpha.4 → 1.4.0-alpha.5

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 B=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var ee=(r,e)=>()=>(r&&(e=r(r=0)),e);var qe=(r,e)=>{for(var t in e)B(r,t,{get:e[t],enumerable:!0})},Ge=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of je(e))!Ie.call(r,o)&&o!==t&&B(r,o,{get:()=>e[o],enumerable:!(n=Fe(e,o))||n.enumerable});return r};var ke=r=>Ge(B({},"__esModule",{value:!0}),r);import{fileURLToPath as Me}from"node:url";var Ke,y,u=ee(()=>{"use strict";Ke=()=>Me(import.meta.url),y=Ke()});var Te={};qe(Te,{argumentMatches:()=>rt,defaultIsDataResponse:()=>et,getOperationName:()=>K,getOverrides:()=>Z,getTags:()=>tt,operationMatches:()=>Oe});import{getOperationName as Xe}from"oazapfts/generate";function et(r,e){if(e&&r==="default")return!0;let t=Number(r);return!Number.isNaN(t)&&t>=200&&t<300}function K({verb:r,path:e}){return Xe(r,e,void 0)}function tt({verb:r,pathItem:e}){return r?e[r]?.tags||[]:[]}function he(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 Oe(r){let e=typeof r=="function"?r:he(r);return function(n){if(!r)return!0;let o=K(n);return e(o,n)}}function rt(r){let e=typeof r=="function"?r:he(r);return function(n){if(!r||n.in==="path")return!0;let o=n.name;return e(o,n)}}function Z(r,e){return e?.find(t=>Oe(t.pattern)(r))}var Y=ee(()=>{"use strict";u()});u();import z from"commander";import{createRequire as Tt}from"node:module";u();import Qe from"commander";import{createRequire as Ve}from"node:module";import{resolve as te}from"node:path";import{existsSync as _,rmSync as Ue,readdirSync as We,statSync as Le,mkdirSync as ze}from"node:fs";import re from"node:path";var E=Ve(y);function Be(r){let e=new Map;if(!_(r))return e;function t(n){try{let o=We(n);for(let i of o){let s=re.join(n,i);if(Le(s).isDirectory())t(s);else if(i==="enhanceEndpoints.ts"){let p=E("node:fs").readFileSync(s);e.set(s,p)}}}catch{}}return t(r),e}function _e(r){for(let[e,t]of r)try{let n=re.dirname(e);_(n)||ze(n,{recursive:!0}),E("node:fs").writeFileSync(e,t)}catch(n){console.warn(`Failed to restore ${e}:`,n)}}function ne(r){let e=["/","/usr","/etc","/var","/home","/Users",".",".."],t=te(r);if(e.some(n=>t===te(n))&&(console.error(`Dangerous path detected: ${t}. Refusing to delete.`),process.exit(1)),_(r)){console.log(`Cleaning output directory: ${r}`);let n=Be(r);Ue(r,{recursive:!0,force:!0}),n.size>0&&(_e(n),console.log(`Protected ${n.size} enhanceEndpoints.ts file(s) from deletion`)),console.log(`Directory cleaned: ${r}`)}}function oe(){try{if(E.resolve("esbuild")&&E.resolve("esbuild-runner"))return E("esbuild-runner/register"),!0}catch{}try{if(E.resolve("typescript")&&E.resolve("ts-node"))return E("ts-node").register({transpileOnly:!0,compilerOptions:{target:"es6",module:"commonjs"}}),!0}catch{}return!1}function ie(r){(!r||!/\.([mc]?(jsx?|tsx?)|jsonc?)?$/.test(r))&&(console.error("Please provide a valid configuration file."),Qe.help())}function se(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 bt,resolve as St}from"node:path";u();u();import W from"node:path";import we from"typescript";u();u();function q(r){return r.replace(r[0],r[0].toUpperCase())}u();import H from"node:fs";import He from"node:path";u();function ae(r){try{new URL(r)}catch{return!1}return!0}async function pe(r,e){if(!ae(r))throw new Error(`remoteFile must be a valid URL: ${r}`);try{let t=He.dirname(e);H.existsSync(t)||await H.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 H.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}}u();u();var ce=["get","put","post","delete","options","head","patch","trace"];function ue(r){return Object.entries(r.paths).flatMap(([e,t])=>t?Object.entries(t).filter(n=>ce.includes(n[0])).map(([n,o])=>({path:e,verb:n,pathItem:t,operation:o})):[])}u();import Ze from"@apidevtools/swagger-parser";import Ye from"swagger2openapi";async function le(r,e){let t=await Ze.bundle(r,{resolve:{http:e}});return"openapi"in t&&t.openapi.startsWith("3")?t:(await Ye.convertObj(t,{})).openapi}u();function me(r,e,t,n){return n?n(r,e):t?.type?t.type==="query":r==="get"}var G=class{docCache={};async getDocument(e,t){if(this.docCache[e])return this.docCache[e];let n=await le(e,t);return this.docCache[e]=n,n}async downloadSchema(e,t){return pe(e,t)}getPaths(e){return Object.keys(e.paths||{})}clearCache(){this.docCache={}}};u();import fe from"lodash.camelcase";var k=class{groupPaths(e,t){let{groupKeyMatch:n,outputDir:o}=t,i=e.reduce((a,p)=>{let f=n(p),l=f?fe(f):"_common";return a[l]||(a[l]=[]),a[l].push(p),a},{}),s={};for(let[a,p]of Object.entries(i))s[a]={groupKey:a,paths:p,outputPath:`${o}/${a}/query.service.ts`};return s}createGroupFilter(e,t){return(n,o)=>{let i=o.path,s=fe(t.groupKeyMatch(i)||"");return s!==e&&(s||"_common")!==e?!1:t.filterEndpoint?t.filterEndpoint(n,i,e):!0}}};u();import de from"node:fs";import C from"node:path";u();import Je from"node:path";import ge from"node:fs";async function ye(r){let e=Je.dirname(r);ge.existsSync(e)||await ge.promises.mkdir(e,{recursive:!0})}var M=class{async writeFile(e,t){try{let n=C.resolve(process.cwd(),e);return C.basename(n)==="enhanceEndpoints.ts"&&de.existsSync(n)?{path:n,success:!0}:(await ye(n),de.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[C.join(e,"types.ts")]=t.types),t.queryService&&(n[C.join(e,"query.generated.ts")]=t.queryService),t.enhanceEndpoints&&(n[C.join(e,"enhanceEndpoints.ts")]=t.enhanceEndpoints),t.index&&(n[C.join(e,"index.ts")]=t.index),this.writeFiles(n)}async writeSharedFiles(e,t){let n={};return t.commonTypes&&(n[C.join(e,"common-types.ts")]=t.commonTypes),t.doNotModify&&(n[C.join(e,"DO_NOT_MODIFY.md")]=t.doNotModify),t.utils&&(n[C.join(e,"utils.ts")]=t.utils),this.writeFiles(n)}async writeSchemaFile(e,t){let n={};return n[C.join(e,"schema.ts")]=t,this.writeFiles(n)}};u();import nt from"oazapfts/generate";var Q=class{constructor(e,t){this.v3Doc=e;this.apiGen=new nt(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}=(Y(),ke(Te));return ue(this.v3Doc).filter(t(e))}getApiGenerator(){return this.apiGen}getDocument(){return this.v3Doc}getSchemaTypeNames(){return new Set}};u();function be(){return`/* eslint-disable */
2
+ var B=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var ee=(r,e)=>()=>(r&&(e=r(r=0)),e);var qe=(r,e)=>{for(var t in e)B(r,t,{get:e[t],enumerable:!0})},Ge=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of je(e))!Ie.call(r,o)&&o!==t&&B(r,o,{get:()=>e[o],enumerable:!(n=Fe(e,o))||n.enumerable});return r};var ke=r=>Ge(B({},"__esModule",{value:!0}),r);import{fileURLToPath as Me}from"node:url";var Ke,y,u=ee(()=>{"use strict";Ke=()=>Me(import.meta.url),y=Ke()});var be={};qe(be,{argumentMatches:()=>rt,defaultIsDataResponse:()=>et,getOperationName:()=>K,getOverrides:()=>Z,getTags:()=>tt,operationMatches:()=>Oe});import{getOperationName as Xe}from"oazapfts/generate";function et(r,e){if(e&&r==="default")return!0;let t=Number(r);return!Number.isNaN(t)&&t>=200&&t<300}function K({verb:r,path:e}){return Xe(r,e,void 0)}function tt({verb:r,pathItem:e}){return r?e[r]?.tags||[]:[]}function he(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 Oe(r){let e=typeof r=="function"?r:he(r);return function(n){if(!r)return!0;let o=K(n);return e(o,n)}}function rt(r){let e=typeof r=="function"?r:he(r);return function(n){if(!r||n.in==="path")return!0;let o=n.name;return e(o,n)}}function Z(r,e){return e?.find(t=>Oe(t.pattern)(r))}var Y=ee(()=>{"use strict";u()});u();import z from"commander";import{createRequire as bt}from"node:module";u();import Ve from"commander";import{createRequire as Qe}from"node:module";import{resolve as te}from"node:path";import{existsSync as _,rmSync as Ue,readdirSync as We,statSync as Le,mkdirSync as ze}from"node:fs";import re from"node:path";var E=Qe(y);function Be(r){let e=new Map;if(!_(r))return e;function t(n){try{let o=We(n);for(let i of o){let s=re.join(n,i);if(Le(s).isDirectory())t(s);else if(i==="enhanceEndpoints.ts"){let p=E("node:fs").readFileSync(s);e.set(s,p)}}}catch{}}return t(r),e}function _e(r){for(let[e,t]of r)try{let n=re.dirname(e);_(n)||ze(n,{recursive:!0}),E("node:fs").writeFileSync(e,t)}catch(n){console.warn(`Failed to restore ${e}:`,n)}}function ne(r){let e=["/","/usr","/etc","/var","/home","/Users",".",".."],t=te(r);if(e.some(n=>t===te(n))&&(console.error(`Dangerous path detected: ${t}. Refusing to delete.`),process.exit(1)),_(r)){console.log(`Cleaning output directory: ${r}`);let n=Be(r);Ue(r,{recursive:!0,force:!0}),n.size>0&&(_e(n),console.log(`Protected ${n.size} enhanceEndpoints.ts file(s) from deletion`)),console.log(`Directory cleaned: ${r}`)}}function oe(){try{if(E.resolve("esbuild")&&E.resolve("esbuild-runner"))return E("esbuild-runner/register"),!0}catch{}try{if(E.resolve("typescript")&&E.resolve("ts-node"))return E("ts-node").register({transpileOnly:!0,compilerOptions:{target:"es6",module:"commonjs"}}),!0}catch{}return!1}function ie(r){(!r||!/\.([mc]?(jsx?|tsx?)|jsonc?)?$/.test(r))&&(console.error("Please provide a valid configuration file."),Ve.help())}function se(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 Tt,resolve as St}from"node:path";u();u();import W from"node:path";import Ne from"typescript";u();u();function q(r){return r.replace(r[0],r[0].toUpperCase())}u();import H from"node:fs";import He from"node:path";u();function ae(r){try{new URL(r)}catch{return!1}return!0}async function pe(r,e){if(!ae(r))throw new Error(`remoteFile must be a valid URL: ${r}`);try{let t=He.dirname(e);H.existsSync(t)||await H.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 H.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}}u();u();var ce=["get","put","post","delete","options","head","patch","trace"];function ue(r){return Object.entries(r.paths).flatMap(([e,t])=>t?Object.entries(t).filter(n=>ce.includes(n[0])).map(([n,o])=>({path:e,verb:n,pathItem:t,operation:o})):[])}u();import Ze from"@apidevtools/swagger-parser";import Ye from"swagger2openapi";async function le(r,e){let t=await Ze.bundle(r,{resolve:{http:e}});return"openapi"in t&&t.openapi.startsWith("3")?t:(await Ye.convertObj(t,{})).openapi}u();function me(r,e,t,n){return n?n(r,e):t?.type?t.type==="query":r==="get"}var G=class{docCache={};async getDocument(e,t){if(this.docCache[e])return this.docCache[e];let n=await le(e,t);return this.docCache[e]=n,n}async downloadSchema(e,t){return pe(e,t)}getPaths(e){return Object.keys(e.paths||{})}clearCache(){this.docCache={}}};u();import fe from"lodash.camelcase";var k=class{groupPaths(e,t){let{groupKeyMatch:n,outputDir:o}=t,i=e.reduce((a,p)=>{let f=n(p),l=f?fe(f):"_common";return a[l]||(a[l]=[]),a[l].push(p),a},{}),s={};for(let[a,p]of Object.entries(i))s[a]={groupKey:a,paths:p,outputPath:`${o}/${a}/query.service.ts`};return s}createGroupFilter(e,t){return(n,o)=>{let i=o.path,s=fe(t.groupKeyMatch(i)||"");return s!==e&&(s||"_common")!==e?!1:t.filterEndpoint?t.filterEndpoint(n,i,e):!0}}};u();import de from"node:fs";import R from"node:path";u();import Je from"node:path";import ge from"node:fs";async function ye(r){let e=Je.dirname(r);ge.existsSync(e)||await ge.promises.mkdir(e,{recursive:!0})}var M=class{async writeFile(e,t){try{let n=R.resolve(process.cwd(),e);return R.basename(n)==="enhanceEndpoints.ts"&&de.existsSync(n)?{path:n,success:!0}:(await ye(n),de.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[R.join(e,"types.ts")]=t.types),t.queryService&&(n[R.join(e,"query.generated.ts")]=t.queryService),t.enhanceEndpoints&&(n[R.join(e,"enhanceEndpoints.ts")]=t.enhanceEndpoints),t.index&&(n[R.join(e,"index.ts")]=t.index),this.writeFiles(n)}async writeSharedFiles(e,t){let n={};return t.commonTypes&&(n[R.join(e,"common-types.ts")]=t.commonTypes),t.doNotModify&&(n[R.join(e,"DO_NOT_MODIFY.md")]=t.doNotModify),t.utils&&(n[R.join(e,"utils.ts")]=t.utils),this.writeFiles(n)}async writeSchemaFile(e,t){let n={};return n[R.join(e,"schema.ts")]=t,this.writeFiles(n)}};u();import nt from"oazapfts/generate";var V=class{constructor(e,t){this.v3Doc=e;this.apiGen=new nt(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}=(Y(),ke(be));return ue(this.v3Doc).filter(t(e))}getApiGenerator(){return this.apiGen}getDocument(){return this.v3Doc}getSchemaTypeNames(){return new Set}};u();function Te(){return`/* eslint-disable */
3
3
  // [Warning] Generated automatically - do not edit manually
4
4
 
5
5
  export interface RequestOptions {
@@ -94,24 +94,24 @@ ${o.join(`
94
94
  \u9019\u4E9B\u6A94\u6848\u662F\u7531 @acrool/rtk-query-codegen-openapi \u7522\u751F\u5668\u6240\u5EFA\u7ACB\u3002
95
95
 
96
96
  \u5982\u6709\u7591\u554F\uFF0C\u8ACB\u53C3\u8003\u5C08\u6848\u6587\u4EF6\u6216\u806F\u7E6B\u958B\u767C\u5718\u968A\u3002
97
- `}u();import Ce from"typescript";u();Y();import{supportDeepObjects as pt}from"oazapfts/generate";var j=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:s="Req",responseSuffix:a="Res",queryMatch:p,endpointOverrides:f}=this.options,l=K({verb:t,path:n}),m=i?q(l+i):l,g=q(l+i+s),T=q(l+i+a),b=me(t,n,Z(e,f),p),O=`${l.replace(/([A-Z])/g,"_$1").toUpperCase()}`,P=o.summary||`${t.toUpperCase()} ${n}`,{queryParams:$,pathParams:c,isVoidArg:A,hasRequestBody:N}=this.extractParameters(e),S=this.extractContentType(o),x=Array.isArray(o.tags)?o.tags:[];return{operationName:m,argTypeName:g,responseTypeName:T,isQuery:b,verb:t.toUpperCase(),path:n,queryKeyName:O,queryParams:$,pathParams:c,isVoidArg:A,summary:P,contentType:S,hasRequestBody:N,tags:x}}extractParameters(e){let{operation:t,pathItem:n}=e,o=this.resolveArray(t.parameters),i=this.resolveArray(n.parameters).filter(m=>!o.some(g=>g.name===m.name&&g.in===m.in)),s=pt([...i,...o]).filter(m=>m.in!=="header"),a=s.filter(m=>m.in==="query"),p=s.filter(m=>m.in==="path"),f=!!t.requestBody,l=a.length===0&&p.length===0&&!t.requestBody;return{queryParams:a,pathParams:p,isVoidArg:l,hasRequestBody:f}}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]}};u();import h from"typescript";var J=r=>r.charAt(0).toUpperCase()+r.slice(1);function ct(r,e,t){return h.transform(r,[n=>o=>h.visitNode(o,function i(s){return h.isIdentifier(s)&&s.text===e?h.factory.createIdentifier(t):h.visitEachChild(s,i,n)})]).transformed[0]}function ut(r,e,t,n){let o=new Set;for(let i of e)t.has(i)||o.add(J(i));return h.transform(r,[i=>s=>h.visitNode(s,function a(p){if(h.isTypeReferenceNode(p)&&h.isIdentifier(p.typeName)){let f=p.typeName.text;if(o.has(f)&&f!==n){let l=h.factory.createQualifiedName(h.factory.createIdentifier("Schema"),h.factory.createIdentifier(f));return h.factory.createTypeReferenceNode(l,p.typeArguments)}}return h.visitEachChild(p,a,i)})]).transformed[0]}function lt(r){if(!h.isUnionTypeNode(r.type))return null;let e=[];for(let t of r.type.types)if(h.isLiteralTypeNode(t)&&h.isStringLiteral(t.literal))e.push(t.literal.text);else return null;return e.length>0?e:null}function mt(r,e){let t=e.map(n=>` ${n.charAt(0).toUpperCase()+n.slice(1)} = "${n}"`);return`export enum ${r} {
97
+ `}u();import Re from"typescript";u();Y();import{supportDeepObjects as pt}from"oazapfts/generate";var j=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:s="Req",responseSuffix:a="Res",queryMatch:p,endpointOverrides:f}=this.options,l=K({verb:t,path:n}),m=i?q(l+i):l,g=q(l+i+s),b=q(l+i+a),T=me(t,n,Z(e,f),p),O=`${l.replace(/([A-Z])/g,"_$1").toUpperCase()}`,P=o.summary||`${t.toUpperCase()} ${n}`,{queryParams:$,pathParams:c,isVoidArg:A,hasRequestBody:w}=this.extractParameters(e),S=this.extractContentType(o),x=Array.isArray(o.tags)?o.tags:[];return{operationName:m,argTypeName:g,responseTypeName:b,isQuery:T,verb:t.toUpperCase(),path:n,queryKeyName:O,queryParams:$,pathParams:c,isVoidArg:A,summary:P,contentType:S,hasRequestBody:w,tags:x}}extractParameters(e){let{operation:t,pathItem:n}=e,o=this.resolveArray(t.parameters),i=this.resolveArray(n.parameters).filter(m=>!o.some(g=>g.name===m.name&&g.in===m.in)),s=pt([...i,...o]).filter(m=>m.in!=="header"),a=s.filter(m=>m.in==="query"),p=s.filter(m=>m.in==="path"),f=!!t.requestBody,l=a.length===0&&p.length===0&&!t.requestBody;return{queryParams:a,pathParams:p,isVoidArg:l,hasRequestBody:f}}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]}};u();import h from"typescript";var J=r=>r.charAt(0).toUpperCase()+r.slice(1);function ct(r,e,t){return h.transform(r,[n=>o=>h.visitNode(o,function i(s){return h.isIdentifier(s)&&s.text===e?h.factory.createIdentifier(t):h.visitEachChild(s,i,n)})]).transformed[0]}function ut(r,e,t,n){let o=new Set;for(let i of e)t.has(i)||o.add(J(i));return h.transform(r,[i=>s=>h.visitNode(s,function a(p){if(h.isTypeReferenceNode(p)&&h.isIdentifier(p.typeName)){let f=p.typeName.text;if(o.has(f)&&f!==n){let l=h.factory.createQualifiedName(h.factory.createIdentifier("Schema"),h.factory.createIdentifier(f));return h.factory.createTypeReferenceNode(l,p.typeArguments)}}return h.visitEachChild(p,a,i)})]).transformed[0]}function lt(r){if(!h.isUnionTypeNode(r.type))return null;let e=[];for(let t of r.type.types)if(h.isLiteralTypeNode(t)&&h.isStringLiteral(t.literal))e.push(t.literal.text);else return null;return e.length>0?e:null}function mt(r,e){let t=e.map(n=>` ${n.charAt(0).toUpperCase()+n.slice(1)} = "${n}"`);return`export enum ${r} {
98
98
  ${t.join(`,
99
99
  `)}
100
- }`}function V(r,e,t,n,o){let i=o?.localSchemaNames??new Set,s=o?.localSchemaInterfaces??{},a={};t&&Object.keys(t).forEach(g=>{if(a[g]=g,g.endsWith("Vo")){let T=g.slice(0,-2)+"VO";a[T]=g}if(g.endsWith("Dto")){let T=g.slice(0,-3)+"DTO";a[T]=g}});let p=t&&Object.keys(t).some(g=>!i.has(g)),f=`/* eslint-disable */
100
+ }`}function Q(r,e,t,n,o){let i=o?.localSchemaNames??new Set,s=o?.localSchemaInterfaces??{},a={};t&&Object.keys(t).forEach(g=>{if(a[g]=g,g.endsWith("Vo")){let b=g.slice(0,-2)+"VO";a[b]=g}if(g.endsWith("Dto")){let b=g.slice(0,-3)+"DTO";a[b]=g}});let p=t&&Object.keys(t).some(g=>!i.has(g)),f=`/* eslint-disable */
101
101
  // [Warning] Generated automatically - do not edit manually
102
102
 
103
103
  `;p&&(f+=`import * as Schema from "../schema";
104
104
  `),f+=`
105
- `;let l=[];if(Object.keys(s).length>0){let g=h.createPrinter({newLine:h.NewLineKind.LineFeed}),T=h.createSourceFile("types.ts","",h.ScriptTarget.Latest,!1,h.ScriptKind.TS),b=[],O=new Set(t?Object.keys(t):[]);for(let[P,$]of Object.entries(s)){let c=J(P);if(h.isTypeAliasDeclaration($)){let S=lt($);if(S){b.push(mt(c,S));continue}}let A=ct($,P,c);A=ut(A,O,i,c);let N=g.printNode(h.EmitHint.Unspecified,A,T);b.push(N)}b.length>0&&l.push(b.join(`
106
- `))}let m=[];return r.forEach(g=>{let T=g.argTypeName,b=g.responseTypeName;if(T){let O=ft(g,n,a,i);O.trim()===""?m.push(`export type ${T} = void;`,""):m.push(`export type ${T} = {`,O,"};","")}if(b){let O=gt(g,n,a,i);O.content.trim()===""?m.push(`export type ${b} = void;`,""):O.isDirectType?m.push(`export type ${b} = ${O.content};`,""):m.push(`export type ${b} = {`,O.content,"};","")}}),m.length>0&&l.push(m.join(`
105
+ `;let l=[];if(Object.keys(s).length>0){let g=h.createPrinter({newLine:h.NewLineKind.LineFeed}),b=h.createSourceFile("types.ts","",h.ScriptTarget.Latest,!1,h.ScriptKind.TS),T=[],O=new Set(t?Object.keys(t):[]);for(let[P,$]of Object.entries(s)){let c=J(P);if(h.isTypeAliasDeclaration($)){let S=lt($);if(S){T.push(mt(c,S));continue}}let A=ct($,P,c);A=ut(A,O,i,c);let w=g.printNode(h.EmitHint.Unspecified,A,b);T.push(w)}T.length>0&&l.push(T.join(`
106
+ `))}let m=[];return r.forEach(g=>{let b=g.argTypeName,T=g.responseTypeName;if(b){let O=ft(g,n,a,i);O.trim()===""?m.push(`export type ${b} = void;`,""):m.push(`export type ${b} = {`,O,"};","")}if(T){let O=gt(g,n,a,i);O.content.trim()===""?m.push(`export type ${T} = void;`,""):O.isDirectType?m.push(`export type ${T} = ${O.content};`,""):m.push(`export type ${T} = {`,O.content,"};","")}}),m.length>0&&l.push(m.join(`
107
107
  `)),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",""),f+l.join(`
108
108
 
109
- `)}function ft(r,e,t={},n=new Set){let o=[];r.queryParams&&r.queryParams.length>0&&r.queryParams.forEach(s=>{let a=s.required?"":"?",p=xe(s,t,n);o.push(` ${s.name}${a}: ${p};`)}),r.pathParams&&r.pathParams.length>0&&r.pathParams.forEach(s=>{let a=s.required?"":"?",p=xe(s,t,n);o.push(` ${s.name}${a}: ${p};`)});let i=e?.find(s=>s.operation?.operationId===r.operationName||s.operation?.operationId===r.operationName.toLowerCase()||s.verb===r.verb.toLowerCase()&&s.path===r.path);if(i?.operation?.requestBody){let a=i.operation.requestBody.content,p=a["application/json"]||a["*/*"],f=a["multipart/form-data"]||a["application/x-www-form-urlencoded"];if(p?.schema){let l=R(p.schema,t,1,n);o.push(` body: ${l};`)}else if(f?.schema){let l=R(f.schema,t,1,n);o.push(` body: ${l};`)}else{let l=Object.values(a)[0];if(l?.schema){let m=R(l.schema,t,1,n);o.push(` body: ${m};`)}else o.push(" body?: any; // Request body from OpenAPI")}}return o.length===0?"":o.join(`
110
- `)}function gt(r,e,t={},n=new Set){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?.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 f=R(a,t,0,n);if(f&&f!=="any")return{content:f,isDirectType:!0}}let p=yt(a,t,n);if(p.length>0)return{content:p.join(`
111
- `),isDirectType:!1}}}}return{content:"",isDirectType:!1}}function yt(r,e={},t=new Set){let n=[];if(r.type==="object"&&r.properties){let o=r.required||[];Object.entries(r.properties).forEach(([i,s])=>{let p=o.includes(i)?"":"?",f=R(s,e,1,t),m=/[^a-zA-Z0-9_$]/.test(i)?`"${i}"`:i;s.description&&n.push(` /** ${s.description} */`),n.push(` ${m}${p}: ${f};`)})}return n}function R(r,e={},t=0,n=new Set){if(!r)return"any";if(r.$ref){let i=r.$ref;if(i.startsWith("#/components/schemas/")){let s=i.replace("#/components/schemas/",""),a=e[s]||s,p=J(a),f=n.has(s)?p:`Schema.${p}`;return r.nullable?`${f} | null`:f}}let o;switch(r.type){case"string":r.enum?o=r.enum.map(a=>`"${a}"`).join(" | "):r.format==="binary"?o="Blob":o="string";break;case"number":case"integer":o="number";break;case"boolean":o="boolean";break;case"array":let i=r.items?R(r.items,e,t,n):"any";o=i.includes("|")?`(${i})[]`:`${i}[]`;break;case"object":if(r.properties){let a=Object.entries(r.properties);if(a.length===0)r.additionalProperties?o=`Record<string, ${r.additionalProperties===!0?"any":R(r.additionalProperties,e,t,n)}>`:o="{}";else{let p=" ".repeat(t+1),f=" ".repeat(t),l=[];a.forEach(([m,g])=>{let b=(r.required||[]).includes(m)?"":"?",O=R(g,e,t+1,n),$=/[^a-zA-Z0-9_$]/.test(m)?`"${m}"`:m;g.description&&l.push(`${p}/** ${g.description} */`),l.push(`${p}${$}${b}: ${O};`)}),o=`{
109
+ `)}function ft(r,e,t={},n=new Set){let o=[];r.queryParams&&r.queryParams.length>0&&r.queryParams.forEach(s=>{let a=s.required?"":"?",p=xe(s,t,n);o.push(` ${s.name}${a}: ${p};`)}),r.pathParams&&r.pathParams.length>0&&r.pathParams.forEach(s=>{let a=s.required?"":"?",p=xe(s,t,n);o.push(` ${s.name}${a}: ${p};`)});let i=e?.find(s=>s.operation?.operationId===r.operationName||s.operation?.operationId===r.operationName.toLowerCase()||s.verb===r.verb.toLowerCase()&&s.path===r.path);if(i?.operation?.requestBody){let a=i.operation.requestBody.content,p=a["application/json"]||a["*/*"],f=a["multipart/form-data"]||a["application/x-www-form-urlencoded"];if(p?.schema){let l=C(p.schema,t,1,n);o.push(` body: ${l};`)}else if(f?.schema){let l=C(f.schema,t,1,n);o.push(` body: ${l};`)}else{let l=Object.values(a)[0];if(l?.schema){let m=C(l.schema,t,1,n);o.push(` body: ${m};`)}else o.push(" body?: any; // Request body from OpenAPI")}}return o.length===0?"":o.join(`
110
+ `)}function gt(r,e,t={},n=new Set){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?.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 f=C(a,t,0,n);if(f&&f!=="any")return{content:f,isDirectType:!0}}let p=yt(a,t,n);if(p.length>0)return{content:p.join(`
111
+ `),isDirectType:!1}}}}return{content:"",isDirectType:!1}}function yt(r,e={},t=new Set){let n=[];if(r.type==="object"&&r.properties){let o=r.required||[];Object.entries(r.properties).forEach(([i,s])=>{let p=o.includes(i)?"":"?",f=C(s,e,1,t),m=/[^a-zA-Z0-9_$]/.test(i)?`"${i}"`:i;s.description&&n.push(` /** ${s.description} */`),n.push(` ${m}${p}: ${f};`)})}return n}function C(r,e={},t=0,n=new Set){if(!r)return"any";if(r.$ref){let i=r.$ref;if(i.startsWith("#/components/schemas/")){let s=i.replace("#/components/schemas/",""),a=e[s]||s,p=J(a),f=n.has(s)?p:`Schema.${p}`;return r.nullable?`${f} | null`:f}}let o;switch(r.type){case"string":r.enum?o=r.enum.map(a=>`"${a}"`).join(" | "):r.format==="binary"?o="Blob":o="string";break;case"number":case"integer":o="number";break;case"boolean":o="boolean";break;case"array":let i=r.items?C(r.items,e,t,n):"any";o=i.includes("|")?`(${i})[]`:`${i}[]`;break;case"object":if(r.properties){let a=Object.entries(r.properties);if(a.length===0)r.additionalProperties?o=`Record<string, ${r.additionalProperties===!0?"any":C(r.additionalProperties,e,t,n)}>`:o="{}";else{let p=" ".repeat(t+1),f=" ".repeat(t),l=[];a.forEach(([m,g])=>{let T=(r.required||[]).includes(m)?"":"?",O=C(g,e,t+1,n),$=/[^a-zA-Z0-9_$]/.test(m)?`"${m}"`:m;g.description&&l.push(`${p}/** ${g.description} */`),l.push(`${p}${$}${T}: ${O};`)}),o=`{
112
112
  ${l.join(`
113
113
  `)}
114
- ${f}}`}}else r.additionalProperties?o=`Record<string, ${r.additionalProperties===!0?"any":R(r.additionalProperties,e,t,n)}>`:o="any";break;default:o="any";break}return r.nullable?`${o} | null`:o}function xe(r,e={},t=new Set){return r.schema?R(r.schema,e,0,t):"any"}u();function Ae(r,e){let{groupKey:t}=e,n=e.httpClient?.importReturnTypeName||"IRestFulEndpointsQueryReturn",o=r.map(c=>{let A=c.isQuery?"query":"mutation",N=c.isVoidArg?"void":`${n}<${c.argTypeName}>`,S=c.path;c.pathParams&&c.pathParams.length>0?(c.pathParams.forEach(F=>{S=S.replace(`{${F.name}}`,`\${queryArg.variables.${F.name}}`)}),S="`"+S+"`"):S=`"${S}"`;let x="";c.queryParams&&c.queryParams.length>0&&(x=`
114
+ ${f}}`}}else r.additionalProperties?o=`Record<string, ${r.additionalProperties===!0?"any":C(r.additionalProperties,e,t,n)}>`:o="any";break;default:o="any";break}return r.nullable?`${o} | null`:o}function xe(r,e={},t=new Set){return r.schema?C(r.schema,e,0,t):"any"}u();function Ae(r,e){let{groupKey:t}=e,n=e.httpClient?.importReturnTypeName||"IRestFulEndpointsQueryReturn",o=r.map(c=>{let A=c.isQuery?"query":"mutation",w=c.isVoidArg?"void":`${n}<${c.argTypeName}>`,S=c.path;c.pathParams&&c.pathParams.length>0?(c.pathParams.forEach(F=>{S=S.replace(`{${F.name}}`,`\${queryArg.variables.${F.name}}`)}),S="`"+S+"`"):S=`"${S}"`;let x="";c.queryParams&&c.queryParams.length>0&&(x=`
115
115
  params: {
116
116
  ${c.queryParams.map(I=>` ${I.name}: queryArg.variables.${I.name},`).join(`
117
117
  `)}
@@ -120,7 +120,7 @@ ${c.queryParams.map(I=>` ${I.name}: queryArg.variables.${I.na
120
120
  invalidatesTags: (result, error) => error ? [] : [${F}],`}return` /** ${c.summary||c.operationName} */
121
121
  ${c.operationName}: build.${A}<
122
122
  ${c.responseTypeName},
123
- ${N}
123
+ ${w}
124
124
  >({${D}
125
125
  query: (queryArg) => ({
126
126
  url: ${S},
@@ -135,8 +135,8 @@ ${c.queryParams.map(I=>` ${I.name}: queryArg.variables.${I.na
135
135
  `,p=e.httpClient?`import {${e.httpClient.importReturnTypeName}} from "${e.httpClient.file}";
136
136
  `:`import {IRestFulEndpointsQueryReturn} from "@acrool/react-fetcher";
137
137
  `,l=r.some(c=>c.tags&&c.tags.length>0)?`import {ECacheTagTypes} from "../tagTypes";
138
- `:"",m=r.some(c=>c.isQuery&&c.isVoidArg),g=r.some(c=>c.isQuery&&!c.isVoidArg),T=r.some(c=>c.isQuery)&&!!e.useLazyQueries,b=r.some(c=>!c.isQuery),O=[];g&&O.push("SimpleQueryHook"),m&&O.push("SimpleVoidQueryHook"),T&&O.push("SimpleLazyQueryHook"),b&&O.push("UseSimpleMutation");let P=O.length>0?`import type { ${O.join(", ")} } from "../common-types";
139
- `:"",$=r.map(c=>{let A=c.operationName.charAt(0).toUpperCase()+c.operationName.slice(1),N=c.isVoidArg?"void":`${n}<${c.argTypeName}>`,S=[];if(c.isQuery){let x=`use${A}Query`;if(c.isVoidArg?S.push(`export const ${x} = injectedRtkApi.${x} as SimpleVoidQueryHook<${c.responseTypeName}>;`):S.push(`export const ${x} = injectedRtkApi.${x} as SimpleQueryHook<${c.responseTypeName}, ${N}>;`),e.useLazyQueries){let D=`useLazy${A}Query`;S.push(`export const ${D} = injectedRtkApi.${D} as unknown as SimpleLazyQueryHook<${c.responseTypeName}, ${N}>;`)}}else{let x=`use${A}Mutation`;S.push(`export const ${x} = injectedRtkApi.${x} as unknown as UseSimpleMutation<${c.responseTypeName}, ${N}>;`)}return S.join(`
138
+ `:"",m=r.some(c=>c.isQuery&&c.isVoidArg),g=r.some(c=>c.isQuery&&!c.isVoidArg),b=r.some(c=>c.isQuery)&&!!e.useLazyQueries,T=r.some(c=>!c.isQuery),O=[];g&&O.push("SimpleQueryHook"),m&&O.push("SimpleVoidQueryHook"),b&&O.push("SimpleLazyQueryHook"),T&&O.push("UseSimpleMutation");let P=O.length>0?`import type { ${O.join(", ")} } from "../common-types";
139
+ `:"",$=r.map(c=>{let A=c.operationName.charAt(0).toUpperCase()+c.operationName.slice(1),w=c.isVoidArg?"void":`${n}<${c.argTypeName}>`,S=[];if(c.isQuery){let x=`use${A}Query`;if(c.isVoidArg?S.push(`export const ${x} = injectedRtkApi.${x} as SimpleVoidQueryHook<${c.responseTypeName}>;`):S.push(`export const ${x} = injectedRtkApi.${x} as SimpleQueryHook<${c.responseTypeName}, ${w}>;`),e.useLazyQueries){let D=`useLazy${A}Query`;S.push(`export const ${D} = injectedRtkApi.${D} as unknown as SimpleLazyQueryHook<${c.responseTypeName}, ${w}>;`)}}else{let x=`use${A}Mutation`;S.push(`export const ${x} = injectedRtkApi.${x} as unknown as UseSimpleMutation<${c.responseTypeName}, ${w}>;`)}return S.join(`
140
140
  `)}).join(`
141
141
  `);return`/* eslint-disable */
142
142
  // [Warning] Generated automatically - do not edit manually
@@ -160,24 +160,17 @@ export default injectedRtkApi;
160
160
  import api from "./query.generated";
161
161
 
162
162
  const enhancedApi = api.enhanceEndpoints({
163
- endpoints: {
164
- ${r.map(o=>o.isQuery?` ${o.operationName}: {
165
- providesTags: (result, error, arg) => [],
166
- },`:` ${o.operationName}: {
167
- invalidatesTags: (result, error, arg) => [],
168
- },`).join(`
169
- `)}
170
- },
163
+ endpoints: {},
171
164
  });
172
165
 
173
166
  export default enhancedApi;
174
- `}var U=class{constructor(e,t){this.parserService=e;this.options=t;this.infoExtractor=new j(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=Ae(e,this.options),o=Pe(e,this.options),i=this.generateIndex(),s=e.map(p=>p.operationName),a=new Set;return e.forEach(p=>{p.tags&&Array.isArray(p.tags)&&p.tags.forEach(f=>a.add(f))}),{operationNames:s,tags:Array.from(a),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((s,a)=>{if(Ce.isInterfaceDeclaration(a)||Ce.isTypeAliasDeclaration(a)){let p=a.name.text;return{...s,[p]:a}}return s},{}),i=this.parserService.getOperationDefinitions(this.options.filterEndpoints);return V(e,t,o,i)}generateIndex(){let e=this.options.groupKey||"";return`/* eslint-disable */
167
+ `}var U=class{constructor(e,t){this.parserService=e;this.options=t;this.infoExtractor=new j(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=Ae(e,this.options),o=Pe(e,this.options),i=this.generateIndex(),s=e.map(p=>p.operationName),a=new Set;return e.forEach(p=>{p.tags&&Array.isArray(p.tags)&&p.tags.forEach(f=>a.add(f))}),{operationNames:s,tags:Array.from(a),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((s,a)=>{if(Re.isInterfaceDeclaration(a)||Re.isTypeAliasDeclaration(a)){let p=a.name.text;return{...s,[p]:a}}return s},{}),i=this.parserService.getOperationDefinitions(this.options.filterEndpoints);return Q(e,t,o,i)}generateIndex(){let e=this.options.groupKey||"";return`/* eslint-disable */
175
168
  // [Warning] Generated automatically - do not edit manually
176
169
 
177
170
  export { default as ${e?`${e.charAt(0).toLowerCase()+e.slice(1)}Api`:"api"} } from "./enhanceEndpoints";
178
171
  export * from "./query.generated";
179
172
  export * from "./types";
180
- `}};u();function Re(){return`/* eslint-disable */
173
+ `}};u();function Ce(){return`/* eslint-disable */
181
174
  // [Warning] Generated automatically - do not edit manually
182
175
 
183
176
  /**
@@ -202,11 +195,11 @@ export enum ECacheTagTypes {
202
195
  ${r.sort().map(t=>` ${dt(t)} = '${t}',`).join(`
203
196
  `)}
204
197
  }
205
- `}u();function w(r,e){if(!(!r||typeof r!="object")){if(r.$ref&&typeof r.$ref=="string"){let t=r.$ref.match(/^#\/components\/schemas\/(.+)$/);t&&e.add(t[1])}if(r.properties)for(let t of Object.values(r.properties))w(t,e);r.items&&w(r.items,e),r.additionalProperties&&typeof r.additionalProperties=="object"&&w(r.additionalProperties,e);for(let t of["allOf","oneOf","anyOf"])if(Array.isArray(r[t]))for(let n of r[t])w(n,e)}}function ht(r){let e=new Set;for(let t of r){let n=t.operation;if(n.parameters)for(let o of n.parameters){let i=o;i.schema&&w(i.schema,e)}if(n.requestBody){let o=n.requestBody;if(o.content)for(let i of Object.values(o.content))i.schema&&w(i.schema,e)}if(n.responses)for(let o of Object.values(n.responses)){let i=o;if(i.content)for(let s of Object.values(i.content))s.schema&&w(s.schema,e)}}return e}function Ot(r,e){let t=new Set,n=[...r];for(;n.length>0;){let o=n.pop();if(t.has(o))continue;t.add(o);let i=e[o];if(!i)continue;let s=new Set;w(i,s);for(let a of s)t.has(a)||n.push(a)}return t}function Ne(r,e,t){let n=new Map;for(let[f,l]of r){let m=ht(l),g=Ot(m,e);n.set(f,g)}let o=new Map;for(let[f,l]of n)for(let m of l)o.has(m)||o.set(m,new Set),o.get(m).add(f);let i=new Set,s=new Map,a=new Set;for(let f of t){let l=o.get(f);if(!l||l.size===0)a.add(f);else if(l.size===1){let m=[...l][0];s.has(m)||s.set(m,new Set),s.get(m).add(f)}else i.add(f)}let p=!0;for(;p;){p=!1;for(let[f,l]of s)for(let m of[...l]){let g=e[m];if(!g)continue;let T=new Set;w(g,T);for(let b of T)for(let[O,P]of s)O!==f&&P.has(b)&&(i.add(b),i.add(m),P.delete(b),l.delete(m),p=!0)}}return{sharedSchemas:i,groupLocalSchemas:s,unusedSchemas:a}}var L=class{_options;openApiService=new G;groupService=new k;fileWriterService=new M;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 Q(this.openApiDoc,this._options),this.parserService.initialize();let e=this.parserService.getApiGenerator();this.schemaInterfaces=e.aliases.reduce((t,n)=>{if(we.isInterfaceDeclaration(n)||we.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}`)}}splitSchemaByUsage(){if(!this.openApiDoc||this.groupOperationDefs.size===0)return;let e=this.openApiDoc.components?.schemas??{},t=Object.keys(this.schemaInterfaces),n=Ne(this.groupOperationDefs,e,t);this.sharedSchemaNames=n.sharedSchemas;for(let o of this.generatedContent.groups){let i=n.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 T of i)this.schemaInterfaces[T]&&(a[T]=this.schemaInterfaces[T]);let p=new j(s),f=this.groupOperationDefs.get(o.groupKey)??[],l=p.extractEndpointInfos(f),m={...s,apiConfiguration:s.apiConfiguration||{file:"@/store/webapi",importName:"WebApiConfiguration"}},g=V(l,m,this.schemaInterfaces,f,{localSchemaInterfaces:a,localSchemaNames:i});o.content.files.types=g}}sharedSchemaNames=null;async generateCommonTypesContent(){this.generatedContent.commonTypes=be()}async generateSchemaContent(){this.generatedContent.componentSchema=Se(this.schemaInterfaces,this.sharedSchemaNames??void 0)}async generateDoNotModifyContent(){this.generatedContent.doNotModify=ve()}async generateUtilsContent(){this.generatedContent.utils=Re()}async generateTagTypesContent(){let e=Array.from(this.allTags);this.generatedContent.tagTypes=$e(e)}async release(){let e=[],t=[],n=[];try{for(let i of this.generatedContent.groups)try{if(i.content?.files){let s=W.dirname(i.outputPath),a=await this.fileWriterService.writeGroupFiles(s,{types:i.content.files.types,queryService:i.content.files.queryService,enhanceEndpoints:i.content.files.enhanceEndpoints,index:i.content.files.index});e.push(...a),n.push(i.groupKey)}}catch(s){t.push(new Error(`\u5BEB\u5165\u7FA4\u7D44 ${i.groupKey} \u5931\u6557: ${s}`))}let o=this.generatedContent.groups[0]?W.dirname(W.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(W.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)}}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()");let s=this.parserService.getOperationDefinitions(i.filterEndpoints);return this.groupOperationDefs.set(t.groupKey,s),this.groupGenerationOptions.set(t.groupKey,i),await new U(this.parserService,i).generate()}generateMainIndex(e){return`/* eslint-disable */
198
+ `}u();function N(r,e){if(!(!r||typeof r!="object")){if(r.$ref&&typeof r.$ref=="string"){let t=r.$ref.match(/^#\/components\/schemas\/(.+)$/);t&&e.add(t[1])}if(r.properties)for(let t of Object.values(r.properties))N(t,e);r.items&&N(r.items,e),r.additionalProperties&&typeof r.additionalProperties=="object"&&N(r.additionalProperties,e);for(let t of["allOf","oneOf","anyOf"])if(Array.isArray(r[t]))for(let n of r[t])N(n,e)}}function ht(r){let e=new Set;for(let t of r){let n=t.operation;if(n.parameters)for(let o of n.parameters){let i=o;i.schema&&N(i.schema,e)}if(n.requestBody){let o=n.requestBody;if(o.content)for(let i of Object.values(o.content))i.schema&&N(i.schema,e)}if(n.responses)for(let o of Object.values(n.responses)){let i=o;if(i.content)for(let s of Object.values(i.content))s.schema&&N(s.schema,e)}}return e}function Ot(r,e){let t=new Set,n=[...r];for(;n.length>0;){let o=n.pop();if(t.has(o))continue;t.add(o);let i=e[o];if(!i)continue;let s=new Set;N(i,s);for(let a of s)t.has(a)||n.push(a)}return t}function we(r,e,t){let n=new Map;for(let[f,l]of r){let m=ht(l),g=Ot(m,e);n.set(f,g)}let o=new Map;for(let[f,l]of n)for(let m of l)o.has(m)||o.set(m,new Set),o.get(m).add(f);let i=new Set,s=new Map,a=new Set;for(let f of t){let l=o.get(f);if(!l||l.size===0)a.add(f);else if(l.size===1){let m=[...l][0];s.has(m)||s.set(m,new Set),s.get(m).add(f)}else i.add(f)}let p=!0;for(;p;){p=!1;for(let[f,l]of s)for(let m of[...l]){let g=e[m];if(!g)continue;let b=new Set;N(g,b);for(let T of b)for(let[O,P]of s)O!==f&&P.has(T)&&(i.add(T),i.add(m),P.delete(T),l.delete(m),p=!0)}}return{sharedSchemas:i,groupLocalSchemas:s,unusedSchemas:a}}var L=class{_options;openApiService=new G;groupService=new k;fileWriterService=new M;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 V(this.openApiDoc,this._options),this.parserService.initialize();let e=this.parserService.getApiGenerator();this.schemaInterfaces=e.aliases.reduce((t,n)=>{if(Ne.isInterfaceDeclaration(n)||Ne.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}`)}}splitSchemaByUsage(){if(!this.openApiDoc||this.groupOperationDefs.size===0)return;let e=this.openApiDoc.components?.schemas??{},t=Object.keys(this.schemaInterfaces),n=we(this.groupOperationDefs,e,t);this.sharedSchemaNames=n.sharedSchemas;for(let o of this.generatedContent.groups){let i=n.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 b of i)this.schemaInterfaces[b]&&(a[b]=this.schemaInterfaces[b]);let p=new j(s),f=this.groupOperationDefs.get(o.groupKey)??[],l=p.extractEndpointInfos(f),m={...s,apiConfiguration:s.apiConfiguration||{file:"@/store/webapi",importName:"WebApiConfiguration"}},g=Q(l,m,this.schemaInterfaces,f,{localSchemaInterfaces:a,localSchemaNames:i});o.content.files.types=g}}sharedSchemaNames=null;async generateCommonTypesContent(){this.generatedContent.commonTypes=Te()}async generateSchemaContent(){this.generatedContent.componentSchema=Se(this.schemaInterfaces,this.sharedSchemaNames??void 0)}async generateDoNotModifyContent(){this.generatedContent.doNotModify=ve()}async generateUtilsContent(){this.generatedContent.utils=Ce()}async generateTagTypesContent(){let e=Array.from(this.allTags);this.generatedContent.tagTypes=$e(e)}async release(){let e=[],t=[],n=[];try{for(let i of this.generatedContent.groups)try{if(i.content?.files){let s=W.dirname(i.outputPath),a=await this.fileWriterService.writeGroupFiles(s,{types:i.content.files.types,queryService:i.content.files.queryService,enhanceEndpoints:i.content.files.enhanceEndpoints,index:i.content.files.index});e.push(...a),n.push(i.groupKey)}}catch(s){t.push(new Error(`\u5BEB\u5165\u7FA4\u7D44 ${i.groupKey} \u5931\u6557: ${s}`))}let o=this.generatedContent.groups[0]?W.dirname(W.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(W.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)}}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()");let s=this.parserService.getOperationDefinitions(i.filterEndpoints);return this.groupOperationDefs.set(t.groupKey,s),this.groupGenerationOptions.set(t.groupKey,i),await new U(this.parserService,i).generate()}generateMainIndex(e){return`/* eslint-disable */
206
199
  // [Warning] Generated automatically - do not edit manually
207
200
 
208
201
  export * from "./schema";
209
202
  ${e.map(n=>`export * from "./${n}";`).join(`
210
203
  `)}
211
- `}};async function Ee(r){let t=await new L(r).generateAll();if(!t.success&&t.errors.length>0)throw t.errors[0]}var De=Tt(y);async function vt(r){let e=St(process.cwd(),r);process.chdir(bt(e));let t=De(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&&ne(n.outputFiles.outputDir);try{console.log("Generating multiple outputs..."),await Ee(n),console.log("Done")}catch(o){console.error("Generation failed:",o),process.exit(1)}}async function xt(){let r=De("../../package.json"),e=oe();z.version(r.version).usage("<path/to/config.js>").parse(process.argv);let t=z.args[0];if(z.args.length===0){z.help();return}ie(t),se(t,e),await vt(t)}xt().catch(r=>{console.error("CLI execution failed:",r),process.exit(1)});export{vt as runGeneration};
204
+ `}};async function Ee(r){let t=await new L(r).generateAll();if(!t.success&&t.errors.length>0)throw t.errors[0]}var De=bt(y);async function vt(r){let e=St(process.cwd(),r);process.chdir(Tt(e));let t=De(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&&ne(n.outputFiles.outputDir);try{console.log("Generating multiple outputs..."),await Ee(n),console.log("Done")}catch(o){console.error("Generation failed:",o),process.exit(1)}}async function xt(){let r=De("../../package.json"),e=oe();z.version(r.version).usage("<path/to/config.js>").parse(process.argv);let t=z.args[0];if(z.args.length===0){z.help();return}ie(t),se(t,e),await vt(t)}xt().catch(r=>{console.error("CLI execution failed:",r),process.exit(1)});export{vt as runGeneration};
212
205
  //# sourceMappingURL=cli.mjs.map