anl 26.510.1 → 26.514.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/package.cjs CHANGED
@@ -1 +1 @@
1
- var e=`26.510.1`;Object.defineProperty(exports,`version`,{enumerable:!0,get:function(){return e}});
1
+ var e=`26.514.1`;Object.defineProperty(exports,`version`,{enumerable:!0,get:function(){return e}});
@@ -1,5 +1,5 @@
1
- const e=require(`../../utils/logger.cjs`),t=require(`../../utils/index.cjs`),n=require(`../shared/format.cjs`),r=require(`../shared/naming.cjs`),i=require(`../shared/schema-utils.cjs`);var a=class{config;enumsMap=new Map;constructor(e){this.config=e}nullable(e){return i.nullableSuffix(e)}extractEnumMetadata(e){let n={},{enmuConfig:r}=this.config,i=e;if(e.example&&t.isValidJSON(e.example)&&(n.rawEnumJson=e.example),r?.varnames){let e=i[r.varnames];Array.isArray(e)&&(n.customNames=e.map(e=>`${e}`))}if(r?.comment){let e=i[r.comment];if(e&&typeof e==`object`&&!Array.isArray(e)){let t={};Object.entries(e).sort((e,t)=>e[0].localeCompare(t[0])).forEach(([e,n])=>{typeof n==`string`&&(t[e]=n)}),Object.keys(t).length&&(n.descriptionMap=t)}}return n}resolveEnumMemberName(e,t,n){let{customNames:r,isNumericEnum:i,treatStringAsNumeric:a}=n,o=r?.[t];return typeof o==`string`&&o.trim()?o:i||typeof e==`string`&&a?`NUMBER_${e}`:typeof e==`string`&&e?e.toUpperCase():`ENUM_${t}`}convertJsonToEnumString(t,i){try{let e=JSON.parse(t);return this.config.enmuConfig.erasableSyntaxOnly?`export const ${i} = {\n${Object.entries(e).sort((e,t)=>e[0].localeCompare(t[0])).map(([e,t])=>`${n.getIndentation(this.config)}${e}: '${String(t)}'`).join(`,
2
- `)}\n} as const;\n\nexport type ${r.getEnumTypeName(this.config,i)} = typeof ${i}[keyof typeof ${i}];`:`export enum ${i} {\n${Object.entries(e).sort((e,t)=>e[0].localeCompare(t[0])).map(([e,t])=>`${n.getIndentation(this.config)}${e} = '${String(t)}'`).join(`,
1
+ const e=require(`../../utils/logger.cjs`),t=require(`../../utils/index.cjs`),n=require(`../shared/format.cjs`),r=require(`../shared/naming.cjs`),i=require(`../shared/schema-utils.cjs`);var a=class{config;enumsMap=new Map;constructor(e){this.config=e}nullable(e){return i.nullableSuffix(e)}extractEnumMetadata(e){let n={},{enmuConfig:r}=this.config,i=e;if(e.example&&t.isValidJSON(e.example)&&(n.rawEnumJson=e.example),r?.varnames){let e=i[r.varnames];Array.isArray(e)&&(n.customNames=e.map(e=>`${e}`))}if(r?.comment){let e=i[r.comment];if(e&&typeof e==`object`&&!Array.isArray(e)){let t={};Object.entries(e).sort((e,t)=>e[0].localeCompare(t[0])).forEach(([e,n])=>{typeof n==`string`&&(t[e]=n)}),Object.keys(t).length&&(n.descriptionMap=t)}}return n}resolveEnumMemberName(e,t,n){let{customNames:i,isNumericEnum:a,treatStringAsNumeric:o}=n,s=i?.[t];return typeof s==`string`&&s.trim()?r.sanitizeIdentifierName(s):a||typeof e==`string`&&o?`NUMBER_${e}`:typeof e==`string`&&e?r.sanitizeIdentifierName(e.toUpperCase()):`ENUM_${t}`}convertJsonToEnumString(t,i){try{let e=JSON.parse(t);return this.config.enmuConfig.erasableSyntaxOnly?`export const ${i} = {\n${Object.entries(e).sort((e,t)=>e[0].localeCompare(t[0])).map(([e,t])=>`${n.getIndentation(this.config)}${r.sanitizeIdentifierName(e)}: '${String(t)}'`).join(`,
2
+ `)}\n} as const;\n\nexport type ${r.getEnumTypeName(this.config,i)} = typeof ${i}[keyof typeof ${i}];`:`export enum ${i} {\n${Object.entries(e).sort((e,t)=>e[0].localeCompare(t[0])).map(([e,t])=>`${n.getIndentation(this.config)}${r.sanitizeIdentifierName(e)} = '${String(t)}'`).join(`,
3
3
  `)}\n}`}catch(t){return e.log.error(`JSON 解析失败: ${t instanceof Error?t.message:String(t)}`),``}}normalizeEnumValues(e){return e.map((e,t)=>{if(typeof e==`string`||typeof e==`number`)return e;if(e&&typeof e==`object`){let n=e;if(n.value!==void 0&&(typeof n.value==`string`||typeof n.value==`number`))return n.value;if(n.key!==void 0&&(typeof n.key==`string`||typeof n.key==`number`))return n.key;if(n.id!==void 0&&(typeof n.id==`string`||typeof n.id==`number`))return n.id;try{return JSON.stringify(n)}catch{return`ENUM_${t}`}}return`ENUM_${t}`})}parseEnum(e,t){if(!Array.isArray(e.enum))return null;let i=[`integer`,`number`],a=this.normalizeEnumValues(e.enum),o=!!(e.type&&i.includes(e.type)),s=e.type===`string`&&a.every(e=>typeof e==`string`&&!isNaN(Number(e))),{customNames:c,descriptionMap:l,rawEnumJson:u}=this.extractEnumMetadata(e),d=this.config.enmuConfig.erasableSyntaxOnly;if(u){let e=this.convertJsonToEnumString(u,t);if(e)return{headerRef:``,renderStr:e}}let f=a.map((e,t)=>{let r=this.resolveEnumMemberName(e,t,{customNames:c,isNumericEnum:o,treatStringAsNumeric:s}),i=o?`${e}`:`'${String(e)}'`,a=d?`${r}: ${i},`:`${r} = ${i},`,u=l?.[String(e)];return u?[`${n.getIndentation(this.config)}/** ${u} */`,`${n.getIndentation(this.config)}${a}`].join(`
4
4
  `):`${n.getIndentation(this.config)}${a}`});return f.length?d?{headerRef:``,renderStr:[`export const ${t} = {`,...f,`} as const;`,``,`export type ${r.getEnumTypeName(this.config,t)} = typeof ${t}[keyof typeof ${t}];`].join(`
5
5
  `)}:{headerRef:``,renderStr:[`export enum ${t} {`,...f,`}`].join(`
@@ -1,7 +1,7 @@
1
- const e=require(`../../utils/logger.cjs`),t=require(`../../utils/index.cjs`),n=require(`../shared/format.cjs`),r=require(`../shared/naming.cjs`),i=require(`../shared/schema-utils.cjs`),a=require(`./enum-parser.cjs`);var o=class{schemas;config;requiredFieldSet=new Set;defaultReturn={headerRef:``,renderStr:``,comment:``,typeName:``};enumParser;schemasMap=new Map;constructor(e,t){this.schemas=e,this.config=t,this.enumParser=new a.EnumParser(t)}nullable(e){return i.nullableSuffix(e)}isRequired(e){return this.requiredFieldSet.has(e)}stringifyValue(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}buildDocComment(e,t){let r=n.getIndentation(this.config),i=[],a=e,o=a.title,s=a.description;o&&i.push(`@title ${o}`),s&&s.split(`
1
+ const e=require(`../../utils/logger.cjs`),t=require(`../../utils/index.cjs`),n=require(`../shared/format.cjs`),r=require(`../shared/naming.cjs`),i=require(`../shared/schema-utils.cjs`),a=require(`./enum-parser.cjs`);var o=class{schemas;config;requiredFieldSet=new Set;defaultReturn={headerRef:``,renderStr:``,comment:``,typeName:``};enumParser;schemasMap=new Map;constructor(e,t){this.schemas=e,this.config=t,this.enumParser=new a.EnumParser(t)}nullable(e){return i.nullableSuffix(e)}isRequired(e){let t=e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e;return this.requiredFieldSet.has(t)}stringifyValue(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}buildDocComment(e,t){let r=n.getIndentation(this.config),i=[],a=e,o=a.title,s=a.description;o&&i.push(`@title ${o}`),s&&s.split(`
2
2
  `).forEach((e,t)=>i.push(t===0?`@description ${e}`:e)),`deprecated`in e&&e.deprecated&&i.push(`@deprecated`),`default`in e&&e.default!==void 0&&i.push(`@default ${this.stringifyValue(e.default)}`),`example`in e&&e.example!==void 0&&i.push(`@example ${this.stringifyValue(e.example)}`),`format`in e&&e.format&&i.push(`@format ${e.format}`);let c=[[`pattern`,`@pattern`],[`minimum`,`@minimum`],[`maximum`,`@maximum`],[`exclusiveMinimum`,`@exclusiveMinimum`],[`exclusiveMaximum`,`@exclusiveMaximum`],[`minLength`,`@minLength`],[`maxLength`,`@maxLength`],[`minItems`,`@minItems`],[`maxItems`,`@maxItems`]],l=e;if(c.some(([e])=>l[e]!==void 0)){let e=c.map(([e,t])=>l[e]===void 0?``:`${t} ${this.stringifyValue(l[e])}`).filter(Boolean);i.push(...e)}if(!i.length)return``;let u=[`${r}/**`];return i.forEach(e=>{e&&(e.includes(`
3
3
  `)?e.split(`
4
4
  `).forEach(e=>u.push(`${r} * ${e}`)):u.push(`${r} * ${e}`))}),u.push(`${r} */`),u.join(`
5
- `)}nameTheHumpCenterStroke(e){let t=e.replace(`#/components/schemas/`,``),n=r.resolveSchemaName(t),i={typeName:n,fileName:r.typeNameToFileName(n),dataType:``};if(this.schemas){let e=this.schemas[t];e?.enum?i.dataType=`enum`:i.dataType=e?.type}return i}parseRef(e){if(!e?.trim())return{headerRefStr:``,typeName:``,dataType:``};let{fileName:t,typeName:n,dataType:i=``}=this.nameTheHumpCenterStroke(e),a;if(i===`enum`){let e=r.getEnumTypeName(this.config,n),t=r.getServerSegment(this.config);a=`import type { ${e} } from '${r.appendEnumSegment(r.adjustImportPathForSegment(this.config.importEnumPath??``,t),r.getEnumSegment(this.config))}';`}else a=`import type { ${n} } from './${t}';`;return{headerRefStr:a,typeName:n,dataType:i}}parseArray(e,i){let a=e,{items:o={},nullable:s}=a,c=o?.$ref;if(c){let{headerRefStr:e,typeName:o,dataType:l}=this.parseRef(c),u=a.example;if(l===`enum`&&typeof u==`string`&&t.isValidJSON(u)){let e=this.enumParser.convertJsonToEnumString(u,o);this.enumParser.addEnumByName(o,e)}let d=l===`enum`?r.getEnumTypeName(this.config,o):o;return{headerRef:e,renderStr:`${n.getIndentation(this.config)}${i}${this.isRequired(i)?``:`?`}: Array<${d}>${this.nullable(s)};`,typeName:d}}let l=o?.type,u=l===`integer`?`number`:l;return l===`object`&&(u=`Record<string, unknown>`),{headerRef:``,renderStr:`${n.getIndentation(this.config)}${i}${this.isRequired(i)?``:`?`}: Array<${u}>${this.nullable(s)};`,typeName:u}}parseBoolean(e,t){return e.type===`boolean`?`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: boolean${this.nullable(e.nullable)};`:``}parseInteger(e,t){return Array.isArray(e.enum)?this.enumParser.handleEnum(e,t,this.isRequired(t))?.renderStr??``:`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: number${this.nullable(e.nullable)};`}parseNumber(e,t){if(e.type!==`number`)return null;if(e.enum){let n=this.enumParser.handleEnum(e,t,this.isRequired(t));if(n)return n}return{headerRef:``,renderStr:`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: number${this.nullable(e.nullable)};`}}getStringTypeByFormat(e){if(!e)return`string`;switch(e){case`date-time`:case`date`:case`time`:return`Date`;case`email`:case`idn-email`:case`uuid`:case`uri`:case`uri-reference`:case`iri`:case`iri-reference`:case`hostname`:case`idn-hostname`:case`ipv4`:case`ipv6`:return`string`;case`binary`:return`File`;default:return`string`}}parseString(e,t){if(e.type!==`string`)return null;if(e.enum){let n=this.enumParser.handleEnum(e,t,this.isRequired(t));if(n)return n}let r=this.getStringTypeByFormat(e.format);return{headerRef:``,renderStr:`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: ${r}${this.nullable(e.nullable)};`}}parseObject(e,t){let r=``,i=``;if(e.type===`object`){let a=e;if(typeof a.additionalProperties==`object`){let e=this.parseArray(a.additionalProperties,t)??this.defaultReturn;r=e?.headerRef??``,i=e?.renderStr??``}i=typeof a.additionalProperties==`boolean`?`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: Record<string, unknown>${this.nullable(a.nullable)};`:`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: ${e.type}${this.nullable(e.nullable)};`}return{headerRef:r,renderStr:i}}parseProperties(e,i){let a=[],o=[];if(!e)return{headerRef:``,renderStr:`export interface ${i} {}`};let s=Object.keys(e).sort();for(let c of s){let s=e[c];if(s?.$ref){let{headerRefStr:e,typeName:l,dataType:u}=this.parseRef(s.$ref);!o.includes(e)&&l!==i&&o.push(e);let d=s,f=this.buildDocComment(d,c);f!==``&&a.push(f);let p=u===`enum`?r.getEnumTypeName(this.config,l):l;a.push(`${n.getIndentation(this.config)}${c}${this.isRequired(c)?``:`?`}: ${p};`);let m=s.example;if(u===`enum`&&m&&t.isValidJSON(m)){let e=this.enumParser.convertJsonToEnumString(m,l);this.enumParser.addEnumByName(l,e)}continue}if(`allOf`in s||`anyOf`in s||`oneOf`in s){let e=s.allOf?.length?`allOf`:s.anyOf?.length?`anyOf`:s.oneOf?.length?`oneOf`:null;if(e){let t=e===`allOf`?` & `:` | `,l=s[e],u=[];for(let e of l)if(e?.$ref){let{headerRefStr:t,typeName:n,dataType:a}=this.parseRef(e.$ref),s=a===`enum`?r.getEnumTypeName(this.config,n):n;!o.includes(t)&&n!==i&&o.push(t),u.push(s)}else switch(e.type){case`string`:u.push(`string`);break;case`number`:case`integer`:u.push(`number`);break;case`boolean`:u.push(`boolean`);break;case`array`:u.push(`unknown[]`);break;case`object`:u.push(`Record<string, unknown>`);break;default:u.push(`unknown`);break}if(u.length>0){let e=this.buildDocComment(s,c);e!==``&&a.push(e);let r=u.join(t),i=u.length>1&&s.nullable?`(${r})`:r;a.push(`${n.getIndentation(this.config)}${c}${this.isRequired(c)?``:`?`}: ${i}${this.nullable(s.nullable)};`);continue}}}let l=s,u=this.buildDocComment(l,c);switch(u!==``&&a.push(u),l.type){case`array`:{let e=this.parseArray(l,c)??this.defaultReturn;a.push(e?.renderStr??``),!o.includes(e.headerRef)&&i!==e.typeName&&o.push(e.headerRef)}break;case`boolean`:a.push(this.parseBoolean(l,c));break;case`integer`:a.push(this.parseInteger(l,c));break;case`number`:{let e=this.parseNumber(l,c);e&&(e.headerRef&&!o.includes(e.headerRef)&&o.push(e.headerRef),a.push(e.renderStr))}break;case`string`:if(l.enum){let e=this.enumParser.handleEnum(l,c,this.isRequired(c));e&&(e.headerRef&&!o.includes(e.headerRef)&&o.push(e.headerRef),e.renderStr&&a.push(e.renderStr))}else a.push(this.parseString(l,c)?.renderStr??``);break;case`object`:{let{headerRef:e,renderStr:t}=this.parseObject(l,c)??this.defaultReturn;a.push(t),o.includes(e)||o.push(e)}break}}let c=[`export interface ${i} {`,...a,`}`];if(o.length>0){let e=o.filter(e=>e!==``);e.length>0&&e.push(``),c.unshift(...e)}let l=c.join(`
5
+ `)}nameTheHumpCenterStroke(e){let t=e.replace(`#/components/schemas/`,``),n=r.resolveSchemaName(t),i={typeName:n,fileName:r.typeNameToFileName(n),dataType:``};if(this.schemas){let e=this.schemas[t];e?.enum?i.dataType=`enum`:i.dataType=e?.type}return i}parseRef(e){if(!e?.trim())return{headerRefStr:``,typeName:``,dataType:``};let{fileName:t,typeName:n,dataType:i=``}=this.nameTheHumpCenterStroke(e),a;if(i===`enum`){let e=r.getEnumTypeName(this.config,n),t=r.getServerSegment(this.config);a=`import type { ${e} } from '${r.appendEnumSegment(r.adjustImportPathForSegment(this.config.importEnumPath??``,t),r.getEnumSegment(this.config))}';`}else a=`import type { ${n} } from './${t}';`;return{headerRefStr:a,typeName:n,dataType:i}}parseArray(e,i){let a=e,{items:o={},nullable:s}=a,c=o?.$ref;if(c){let{headerRefStr:e,typeName:o,dataType:l}=this.parseRef(c),u=a.example;if(l===`enum`&&typeof u==`string`&&t.isValidJSON(u)){let e=this.enumParser.convertJsonToEnumString(u,o);this.enumParser.addEnumByName(o,e)}let d=l===`enum`?r.getEnumTypeName(this.config,o):o;return{headerRef:e,renderStr:`${n.getIndentation(this.config)}${i}${this.isRequired(i)?``:`?`}: Array<${d}>${this.nullable(s)};`,typeName:d}}let l=o?.type,u=l===`integer`?`number`:l;return l===`object`&&(u=`Record<string, unknown>`),{headerRef:``,renderStr:`${n.getIndentation(this.config)}${i}${this.isRequired(i)?``:`?`}: Array<${u}>${this.nullable(s)};`,typeName:u}}parseBoolean(e,t){return e.type===`boolean`?`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: boolean${this.nullable(e.nullable)};`:``}parseInteger(e,t){return Array.isArray(e.enum)?this.enumParser.handleEnum(e,t,this.isRequired(t))?.renderStr??``:`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: number${this.nullable(e.nullable)};`}parseNumber(e,t){if(e.type!==`number`)return null;if(e.enum){let n=this.enumParser.handleEnum(e,t,this.isRequired(t));if(n)return n}return{headerRef:``,renderStr:`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: number${this.nullable(e.nullable)};`}}getStringTypeByFormat(e){if(!e)return`string`;switch(e){case`date-time`:case`date`:case`time`:return`Date`;case`email`:case`idn-email`:case`uuid`:case`uri`:case`uri-reference`:case`iri`:case`iri-reference`:case`hostname`:case`idn-hostname`:case`ipv4`:case`ipv6`:return`string`;case`binary`:return`File`;default:return`string`}}parseString(e,t){if(e.type!==`string`)return null;if(e.enum){let n=this.enumParser.handleEnum(e,t,this.isRequired(t));if(n)return n}let r=this.getStringTypeByFormat(e.format);return{headerRef:``,renderStr:`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: ${r}${this.nullable(e.nullable)};`}}parseObject(e,t){let r=``,i=``;if(e.type===`object`){let a=e;if(typeof a.additionalProperties==`object`){let e=this.parseArray(a.additionalProperties,t)??this.defaultReturn;r=e?.headerRef??``,i=e?.renderStr??``}i=typeof a.additionalProperties==`boolean`?`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: Record<string, unknown>${this.nullable(a.nullable)};`:`${n.getIndentation(this.config)}${t}${this.isRequired(t)?``:`?`}: ${e.type}${this.nullable(e.nullable)};`}return{headerRef:r,renderStr:i}}parseProperties(e,i){let a=[],o=[];if(!e)return{headerRef:``,renderStr:`export interface ${i} {}`};let s=Object.keys(e).sort();for(let c of s){let s=e[c],l=r.formatPropertyName(c);if(s?.$ref){let{headerRefStr:e,typeName:c,dataType:u}=this.parseRef(s.$ref);!o.includes(e)&&c!==i&&o.push(e);let d=s,f=this.buildDocComment(d,l);f!==``&&a.push(f);let p=u===`enum`?r.getEnumTypeName(this.config,c):c;a.push(`${n.getIndentation(this.config)}${l}${this.isRequired(l)?``:`?`}: ${p};`);let m=s.example;if(u===`enum`&&m&&t.isValidJSON(m)){let e=this.enumParser.convertJsonToEnumString(m,c);this.enumParser.addEnumByName(c,e)}continue}if(`allOf`in s||`anyOf`in s||`oneOf`in s){let e=s.allOf?.length?`allOf`:s.anyOf?.length?`anyOf`:s.oneOf?.length?`oneOf`:null;if(e){let t=e===`allOf`?` & `:` | `,c=s[e],u=[];for(let e of c)if(e?.$ref){let{headerRefStr:t,typeName:n,dataType:a}=this.parseRef(e.$ref),s=a===`enum`?r.getEnumTypeName(this.config,n):n;!o.includes(t)&&n!==i&&o.push(t),u.push(s)}else switch(e.type){case`string`:u.push(`string`);break;case`number`:case`integer`:u.push(`number`);break;case`boolean`:u.push(`boolean`);break;case`array`:u.push(`unknown[]`);break;case`object`:u.push(`Record<string, unknown>`);break;default:u.push(`unknown`);break}if(u.length>0){let e=this.buildDocComment(s,l);e!==``&&a.push(e);let r=u.join(t),i=u.length>1&&s.nullable?`(${r})`:r;a.push(`${n.getIndentation(this.config)}${l}${this.isRequired(l)?``:`?`}: ${i}${this.nullable(s.nullable)};`);continue}}}let u=s,d=this.buildDocComment(u,l);switch(d!==``&&a.push(d),u.type){case`array`:{let e=this.parseArray(u,l)??this.defaultReturn;a.push(e?.renderStr??``),!o.includes(e.headerRef)&&i!==e.typeName&&o.push(e.headerRef)}break;case`boolean`:a.push(this.parseBoolean(u,l));break;case`integer`:a.push(this.parseInteger(u,l));break;case`number`:{let e=this.parseNumber(u,l);e&&(e.headerRef&&!o.includes(e.headerRef)&&o.push(e.headerRef),a.push(e.renderStr))}break;case`string`:if(u.enum){let e=this.enumParser.handleEnum(u,l,this.isRequired(l));e&&(e.headerRef&&!o.includes(e.headerRef)&&o.push(e.headerRef),e.renderStr&&a.push(e.renderStr))}else a.push(this.parseString(u,l)?.renderStr??``);break;case`object`:{let{headerRef:e,renderStr:t}=this.parseObject(u,l)??this.defaultReturn;a.push(t),o.includes(e)||o.push(e)}break}}let c=[`export interface ${i} {`,...a,`}`];if(o.length>0){let e=o.filter(e=>e!==``);e.length>0&&e.push(``),c.unshift(...e)}let l=c.join(`
6
6
  `);return{headerRef:o.join(`
7
7
  `),renderStr:l}}generateContent(t,n){if(`items`in t)return e.log.warn(`数组类型未处理: ${n}`),``;switch(t.type){case`boolean`:return this.parseBoolean(t,n);case`integer`:return this.parseInteger(t,n);case`number`:return this.parseNumber(t,n)?.renderStr??``;case`object`:return this.parseProperties(t.properties,n)?.renderStr??``;case`string`:return this.parseString(t,n)?.renderStr??``;default:return``}}main(){if(!this.schemas)return e.log.warn(`schemas 为空`),{enumsMap:this.enumParser.enumsMap,schemasMap:this.schemasMap};let t=Object.keys(this.schemas).sort();for(let n of t){let t=this.schemas[n];if(`$ref`in t){e.log.warn(`跳过 ReferenceObject: ${n}`);continue}let i=`type`in t?t:null;if(!i?.type){e.log.warn(`无效的 schema 对象: ${n}`);continue}if(Array.isArray(t.enum)){let e=r.resolveSchemaName(n),i=this.enumParser.parseEnum(t,e);i?.renderStr&&!this.enumParser.hasEnum(e)&&this.enumParser.addEnumByName(e,i.renderStr);continue}this.requiredFieldSet=new Set(t.required??[]);let a=r.resolveSchemaName(n),o=r.typeNameToFileName(a),s=this.generateContent(i,a);s&&((s.includes(`export enum `)||s.includes(`export const `)&&s.includes(`as const`))&&!this.enumParser.hasEnum(a)?this.enumParser.addEnumByName(a,s):this.schemasMap.set(a,{fileName:o,content:s}))}return{enumsMap:this.enumParser.enumsMap,schemasMap:this.schemasMap}}};exports.ComponentSchemaResolver=o;
@@ -1,7 +1,7 @@
1
1
  const e=require(`../../utils/logger.cjs`);require(`../../utils/index.cjs`);const t=require(`../shared/format.cjs`),n=require(`../shared/naming.cjs`),r=require(`../shared/http.cjs`),i=require(`./naming.cjs`),a=require(`./schema-resolver.cjs`),o=require(`./writer.cjs`);var s=function(e){return e.GET=`get`,e.PUT=`put`,e.POST=`post`,e.DELETE=`delete`,e.OPTIONS=`options`,e.HEAD=`head`,e.PATCH=`patch`,e.TRACE=`trace`,e}(s||{});const c={typeMapping:new Map([[`integer`,`number`],[`string`,`string`],[`boolean`,`boolean`],[`binary`,`File`],[`number`,`number`],[`null`,`null`],[`undefined`,`undefined`],[`date`,`Date`],[`time`,`Date`],[`datetime`,`Date`],[`timestamp`,`Date`]]),errorHandling:{throwOnError:!1,logErrors:!0}};var l=class{pathsObject={};nonArrayType=[`boolean`,`object`,`number`,`string`,`integer`];pathKey=``;contentBody={payload:{path:[],query:[],header:[],body:[]},response:``,_response:``,fileName:``,method:``,requestPath:``,summary:``,apiName:``,typeName:``,deprecated:!1,contentType:`application/json`};Map=new Map;config;errors=[];parameters={};schemas={};schemaResolver;writer;apiListFileContent=[];allowedInterfaceKeys=new Set;allInterfaceKeys=new Set;constructor(e,n,r,i){this.pathsObject=e,this.parameters=n??{},this.schemas=r??{},this.config=t.applyFormattingDefaults({...c,...i,typeMapping:new Map([...c.typeMapping??[],...i.typeMapping??[]])}),this.schemaResolver=new a.SchemaResolver(this.config,this.schemas,this.parameters,this.handleError.bind(this)),this.writer=new o.PathWriter(this.config)}handleError(t){if(!t.path&&this.contentBody.requestPath&&(t.path=this.contentBody.requestPath),!t.method&&this.contentBody.method&&(t.method=this.contentBody.method),this.errors.push(t),this.config.errorHandling?.logErrors&&e.log.error(e.formatParseError(t)),this.config.errorHandling?.throwOnError)throw Error(`${t.type}: ${t.message}`)}getIndentation(){return t.getIndentation(this.config)}getDoubleIndentation(){let e=this.getIndentation();return e+e}generateParamComment(e,t){let n=[],r=[];if(e.description&&r.push(e.description),e.deprecated&&r.push(`@deprecated`),e.schema&&typeof e.schema==`object`&&`example`in e.schema){let t=e.schema.example,n=typeof t==`string`?t:JSON.stringify(t);r.push(`@example ${n}`)}if(e.schema&&typeof e.schema==`object`&&`default`in e.schema){let t=e.schema.default,n=typeof t==`string`?t:JSON.stringify(t);r.push(`@default ${n}`)}return r.length>0&&(r.length===1&&!r[0].includes(`
2
2
  `)?n.push(`${t}/** ${r[0]} */`):(n.push(`${t}/**`),r.forEach(e=>{e.includes(`
3
3
  `)?e.split(`
4
- `).forEach(e=>{n.push(`${t} * ${e}`)}):n.push(`${t} * ${e}`)}),n.push(`${t} */`))),n}parametersItemHandle(t,r,i,a){let o=this.getDoubleIndentation(),s=`$ref`in t?t:null,c=`name`in t?t:null;if(s?.$ref&&s.$ref.startsWith(`#/components/parameters/`)&&this.parameters){let e=s.$ref.replace(`#/components/parameters/`,``),t=this.parameters[e];this.parametersItemHandle(t,r,i,a)}if(c){if(!c.schema){this.handleError({type:`PARAMETERS`,message:`Parameter "${c.name}" has no schema defined, skipping`});return}let t=this.schemaResolver.main(c.schema);if(!t||typeof t!=`string`){this.handleError({type:`PARAMETERS`,message:`Failed to parse schema for parameter "${c.name}"`,details:t});return}if(c.in===`path`)this.generateParamComment(c,o).forEach(e=>r.push(e)),r.push(`${o}type ${c.name} = ${t};`),this.contentBody.payload._path?this.contentBody.payload._path[c.name]=t:this.contentBody.payload._path={[c.name]:t};else if(c.in===`query`){this.generateParamComment(c,o).forEach(e=>i.push(e));let e=c.required===!0?``:`?`,r=n.formatPropertyName(c.name);i.push(`${o}${r}${e}: ${t};`),this.contentBody.payload._query?this.contentBody.payload._query[c.name]=t:this.contentBody.payload._query={[c.name]:t}}else if(c.in===`header`){this.generateParamComment(c,o).forEach(e=>a.push(e));let e=c.required===!0?``:`?`,r=n.formatPropertyName(c.name);a.push(`${o}${r}${e}: ${t};`),this.contentBody.payload._header?this.contentBody.payload._header[c.name]=t:this.contentBody.payload._header={[c.name]:t}}else c.in===`cookie`?e.log.verbose(`Cookie parameter "${c.name}" detected but not added to type definition`):this.handleError({type:`PARAMETERS`,message:`Unknown parameter location "${c.in}" for parameter "${c.name}"`})}}requestParametersParse(e){let t=this.getIndentation(),n=[],r=[],i=[];e?.map(e=>this.parametersItemHandle(e,n,r,i)),n.length!==0&&(n.unshift(`${t}namespace Path {`),n.push(`${t}}`)),r.length!==0&&(r.unshift(`${t}interface Query {`),r.push(`${t}}`)),i.length!==0&&(i.unshift(`${t}interface Header {`),i.push(`${t}}`)),this.contentBody.payload.path=n,this.contentBody.payload.query=r,this.contentBody.payload.header=i}pickRequestBodyContent(e){let t=e.content;if(!t||typeof t!=`object`)return{schema:null};for(let e of[`multipart/form-data`,`application/x-www-form-urlencoded`]){let n=t[e];if(n&&typeof n==`object`&&n.schema)return{schema:n.schema}}let n=Object.keys(t)[0],r=n?t[n]:null;return{schema:r&&typeof r==`object`&&r.schema?r.schema:null}}requestBodyObjectParse(e){let t=this.getIndentation(),{schema:n}=this.pickRequestBodyContent(e);if(n){let e=n?.type,r=`$ref`in n?n:null,i=e===`array`?n:null,a=e&&this.nonArrayType.includes(e)?n:null;if(r)return`${t}type Body = ${this.schemaResolver.referenceObjectParse(r)}`;if(i)return`${t}type Body = ${this.schemaResolver.arraySchemaObjectParse(i)}`;if(a){let e=this.schemaResolver.nonArraySchemaObjectParse(a);return Array.isArray(e)?e.length===0?[`${t}type Body = ${a.type};`]:[`${t}interface Body {`,...e,`}`]:[`${t}type Body = ${e}`]}}}requestBodyParse(e){if(!e)return`{}`;let t=`$ref`in e?e:null,n=`content`in e?e:null;if(t){let e=this.schemaResolver.referenceObjectParse(t);return`${this.getIndentation()}type Body = ${e}`}return n&&Object.keys(e).length!==0?this.requestBodyObjectParse(n):`{}`}normalizemodulePrefix(e){if(!e||e.trim()===``)return``;let t=e.trim();return t=t.replace(/\/+$/g,``),t.startsWith(`/`)||(t=`/`+t),t}apiRequestItemHandle(e){let{payload:t,requestPath:n,_response:i,method:a,typeName:o,apiName:s,contentType:c}=e,{_path:l,_query:u,body:d}=t,f=e.dataLevel??this.config.dataLevel??`serve`,p=this.normalizemodulePrefix(this.config.modulePrefix),m=()=>{let e=[],t=Object.keys(l??{}).sort();for(let n of t)e.push(`${n}: ${o}.Path.${n}`);let n=e.join(e.length>1?`,`:``);return n===``?n:n+`,`},h=()=>{let e=u?`query: ${o}.Query,`:``;return e===``?``:`${e}`},g=()=>{let e=d.length>0?`body: ${o}.Body,`:``;return e===``?``:`${e}`},_=m(),v=h(),y=g(),b=()=>{let e=r.SUPPORTED_REQUEST_UPLOAD_TYPES.includes(c)?`headers: { 'Content-Type': '${c}' }`:void 0;return[`{`,e?`${e},`:``,`...params, `,v===``?``:`query,`,y===``?``:`body,`,`},`].join(``)},x=(_+v+y).replace(/,$/,``);return[`export const ${s} = `,`(`,x,x===``?`params?: IRequestFnParams`:`, params?: IRequestFnParams`,`)`,` => `,a,`${i?`<${o}.Response>`:``}`,`(`,`\`${p}${n}\`,`,b(),`'${f}'`,`);`].join(``)}responseHandle(e){let t=e[200];if(!t)return;let n=`content`in t?t:null,r=`$ref`in t?t:null;if(n===null&&r===null&&(this.contentBody.response=`type Response = unknown`,this.contentBody._response=`unknown`),r){let e=this.schemaResolver.referenceObjectParse(r);this.config.responseModelTransform&&(e=this.schemaResolver.transformResponseModel(e,this.config.responseModelTransform)),this.contentBody.response=`type Response = ${e}`,this.contentBody._response=e}if(n){let e=this.schemaResolver.responseObjectParse(n);if(this.config.responseModelTransform&&(e=this.schemaResolver.transformResponseModel(e,this.config.responseModelTransform)),Array.isArray(e)){if(e.length===1&&e[0]===`unknown`)this.contentBody.response=`type Response = ${e.join(`
4
+ `).forEach(e=>{n.push(`${t} * ${e}`)}):n.push(`${t} * ${e}`)}),n.push(`${t} */`))),n}parametersItemHandle(t,r,i,a){let o=this.getDoubleIndentation(),s=`$ref`in t?t:null,c=`name`in t?t:null;if(s?.$ref&&s.$ref.startsWith(`#/components/parameters/`)&&this.parameters){let e=s.$ref.replace(`#/components/parameters/`,``),t=this.parameters[e];this.parametersItemHandle(t,r,i,a)}if(c){if(!c.schema){this.handleError({type:`PARAMETERS`,message:`Parameter "${c.name}" has no schema defined, skipping`});return}let t=this.schemaResolver.main(c.schema);if(!t||typeof t!=`string`){this.handleError({type:`PARAMETERS`,message:`Failed to parse schema for parameter "${c.name}"`,details:t});return}if(c.in===`path`){this.generateParamComment(c,o).forEach(e=>r.push(e));let e=n.sanitizeIdentifierName(c.name);r.push(`${o}type ${e} = ${t};`),this.contentBody.payload._path?this.contentBody.payload._path[e]=t:this.contentBody.payload._path={[e]:t}}else if(c.in===`query`){this.generateParamComment(c,o).forEach(e=>i.push(e));let e=c.required===!0?``:`?`,r=n.formatPropertyName(c.name);i.push(`${o}${r}${e}: ${t};`),this.contentBody.payload._query?this.contentBody.payload._query[c.name]=t:this.contentBody.payload._query={[c.name]:t}}else if(c.in===`header`){this.generateParamComment(c,o).forEach(e=>a.push(e));let e=c.required===!0?``:`?`,r=n.formatPropertyName(c.name);a.push(`${o}${r}${e}: ${t};`),this.contentBody.payload._header?this.contentBody.payload._header[c.name]=t:this.contentBody.payload._header={[c.name]:t}}else c.in===`cookie`?e.log.verbose(`Cookie parameter "${c.name}" detected but not added to type definition`):this.handleError({type:`PARAMETERS`,message:`Unknown parameter location "${c.in}" for parameter "${c.name}"`})}}requestParametersParse(e){let t=this.getIndentation(),n=[],r=[],i=[];e?.map(e=>this.parametersItemHandle(e,n,r,i)),n.length!==0&&(n.unshift(`${t}namespace Path {`),n.push(`${t}}`)),r.length!==0&&(r.unshift(`${t}interface Query {`),r.push(`${t}}`)),i.length!==0&&(i.unshift(`${t}interface Header {`),i.push(`${t}}`)),this.contentBody.payload.path=n,this.contentBody.payload.query=r,this.contentBody.payload.header=i}pickRequestBodyContent(e){let t=e.content;if(!t||typeof t!=`object`)return{schema:null};for(let e of[`multipart/form-data`,`application/x-www-form-urlencoded`]){let n=t[e];if(n&&typeof n==`object`&&n.schema)return{schema:n.schema}}let n=Object.keys(t)[0],r=n?t[n]:null;return{schema:r&&typeof r==`object`&&r.schema?r.schema:null}}requestBodyObjectParse(e){let t=this.getIndentation(),{schema:n}=this.pickRequestBodyContent(e);if(n){let e=n?.type,r=`$ref`in n?n:null,i=e===`array`?n:null,a=e&&this.nonArrayType.includes(e)?n:null;if(r)return`${t}type Body = ${this.schemaResolver.referenceObjectParse(r)}`;if(i)return`${t}type Body = ${this.schemaResolver.arraySchemaObjectParse(i)}`;if(a){let e=this.schemaResolver.nonArraySchemaObjectParse(a);return Array.isArray(e)?e.length===0?[`${t}type Body = ${a.type};`]:[`${t}interface Body {`,...e,`}`]:[`${t}type Body = ${e}`]}}}requestBodyParse(e){if(!e)return`{}`;let t=`$ref`in e?e:null,n=`content`in e?e:null;if(t){let e=this.schemaResolver.referenceObjectParse(t);return`${this.getIndentation()}type Body = ${e}`}return n&&Object.keys(e).length!==0?this.requestBodyObjectParse(n):`{}`}normalizemodulePrefix(e){if(!e||e.trim()===``)return``;let t=e.trim();return t=t.replace(/\/+$/g,``),t.startsWith(`/`)||(t=`/`+t),t}apiRequestItemHandle(e){let{payload:t,requestPath:n,_response:i,method:a,typeName:o,apiName:s,contentType:c}=e,{_path:l,_query:u,body:d}=t,f=e.dataLevel??this.config.dataLevel??`serve`,p=this.normalizemodulePrefix(this.config.modulePrefix),m=()=>{let e=[],t=Object.keys(l??{}).sort();for(let n of t)e.push(`${n}: ${o}.Path.${n}`);let n=e.join(e.length>1?`,`:``);return n===``?n:n+`,`},h=()=>{let e=u?`query: ${o}.Query,`:``;return e===``?``:`${e}`},g=()=>{let e=d.length>0?`body: ${o}.Body,`:``;return e===``?``:`${e}`},_=m(),v=h(),y=g(),b=()=>{let e=r.SUPPORTED_REQUEST_UPLOAD_TYPES.includes(c)?`headers: { 'Content-Type': '${c}' }`:void 0;return[`{`,e?`${e},`:``,`...params, `,v===``?``:`query,`,y===``?``:`body,`,`},`].join(``)},x=(_+v+y).replace(/,$/,``);return[`export const ${s} = `,`(`,x,x===``?`params?: IRequestFnParams`:`, params?: IRequestFnParams`,`)`,` => `,a,`${i?`<${o}.Response>`:``}`,`(`,`\`${p}${n}\`,`,b(),`'${f}'`,`);`].join(``)}responseHandle(e){let t=e[200];if(!t)return;let n=`content`in t?t:null,r=`$ref`in t?t:null;if(n===null&&r===null&&(this.contentBody.response=`type Response = unknown`,this.contentBody._response=`unknown`),r){let e=this.schemaResolver.referenceObjectParse(r);this.config.responseModelTransform&&(e=this.schemaResolver.transformResponseModel(e,this.config.responseModelTransform)),this.contentBody.response=`type Response = ${e}`,this.contentBody._response=e}if(n){let e=this.schemaResolver.responseObjectParse(n);if(this.config.responseModelTransform&&(e=this.schemaResolver.transformResponseModel(e,this.config.responseModelTransform)),Array.isArray(e)){if(e.length===1&&e[0]===`unknown`)this.contentBody.response=`type Response = ${e.join(`
5
5
  `)};`;else{let t=this.config.formatting?.lineEnding,n=this.config.formatting?.indentation;this.contentBody.response=`interface Response {${t}${e.join(`
6
6
  `)}${t}${n}};`}this.contentBody._response=`${e.join(`
7
7
  `)}`}else this.contentBody.response=`type Response = ${e}`,this.contentBody._response=`${e}`}}requestHandle(e){if(e.parameters&&this.requestParametersParse(e.parameters),e.requestBody){let t=this.requestBodyParse(e.requestBody);if(Array.isArray(t))this.contentBody.payload.body=t;else if(t){let e=t?.split(`
@@ -1 +1 @@
1
- const e=require(`../shared/naming.cjs`);function t(e){let t=e.replace(/^[0-9]+/,``);return t?(t=t.replace(/[^a-zA-Z0-9_.-]/g,``),t):`num`+e}function n(e,n=!1){let r=t(e).split(/[-_.]+/).filter(e=>e.length>0);return r.length===0?``:r.map((e,t)=>t===0&&n?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``)}function r(e){let n=t(e).split(/[-_.]+/).filter(e=>e.length>0);return n.length===0?``:n.map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``)}function i(e){return e?e.replace(/^\/+|\/+$/g,``):``}function a(e,t){let n=t.replace(/^\/+/,``),r=i(e.publicPrefix);if(r&&n.startsWith(r+`/`))n=n.slice(r.length+1);else if(r&&n===r)n=``;else if(r&&n.startsWith(r)){let e=n.slice(r.length);(e.startsWith(`/`)||e===``)&&(n=e.replace(/^\/+/,``))}return n}function o(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=e[r+1];i.type===`normal`&&a?.type===`param`&&t(i.normalized).toLowerCase().replace(/[-_.]/g,``)===t(a.normalized).toLowerCase().replace(/[-_.]/g,``)||n.push(i)}return n}function s(i,s){let c=i;i.startsWith(`/`)||(c=`/`+i);let[l,u]=c.split(`|`),d=a(s,l),f=d?d.split(`/`).filter(e=>e):[],p=o(f.map(e=>e.startsWith(`{`)&&e.endsWith(`}`)?{type:`param`,original:e,normalized:e.slice(1,-1)}:{type:`normal`,original:e,normalized:e})),m=s.parameterSeparator??`_`,h=``,g=[],_=e=>{if(g.length>0){let t=g.map((t,r)=>n(t,e&&r===0)).join(``);h+=(h&&g.length>0?m:``)+t,g=[]}};for(let e of p)if(e.type===`normal`)g.push(e.normalized);else{_(h===``);let n=t(e.normalized);h+=(h?m:``)+n}_(h===``);let v=``;g=[];let y=()=>{if(g.length>0){let e=g.map(e=>r(e)).join(``);v+=(v&&g.length>0?m:``)+e,g=[]}};for(let e of p)if(e.type===`normal`)g.push(e.normalized);else{y();let t=r(e.normalized);v+=(v?m:``)+t}y();let b=``;f.length>0?(b=f.map(e=>e.replace(/[{}]/g,``)).join(`-`),b=`${b}-${u}`.toLowerCase()):b=`${u}`.toLowerCase();let x=`/`+d;d||(x=`/`),x=x.replace(/\{(\w+)\}/g,(e,t)=>`\${${t}}`);let S=v?`${v}_${u}`:u,C=e.getNamespacePrefix(s),w=C?`${C}_${S}`:S;return{apiName:h?`${h}_${u}`:u,fileName:b,typeName:w,path:x}}exports.convertEndpointString=s;
1
+ const e=require(`../shared/naming.cjs`);function t(e){let t=e.replace(/^[0-9]+/,``);return t?(t=t.replace(/[^a-zA-Z0-9_.-]/g,``),t):`num`+e}function n(e,n=!1){let r=t(e).split(/[-_.]+/).filter(e=>e.length>0);return r.length===0?``:r.map((e,t)=>t===0&&n?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``)}function r(e){let n=t(e).split(/[-_.]+/).filter(e=>e.length>0);return n.length===0?``:n.map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``)}function i(e){return e?e.replace(/^\/+|\/+$/g,``):``}function a(e,t){let n=t.replace(/^\/+/,``),r=i(e.publicPrefix);if(r&&n.startsWith(r+`/`))n=n.slice(r.length+1);else if(r&&n===r)n=``;else if(r&&n.startsWith(r)){let e=n.slice(r.length);(e.startsWith(`/`)||e===``)&&(n=e.replace(/^\/+/,``))}return n}function o(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=e[r+1];i.type===`normal`&&a?.type===`param`&&t(i.normalized).toLowerCase().replace(/[-_.]/g,``)===t(a.normalized).toLowerCase().replace(/[-_.]/g,``)||n.push(i)}return n}function s(i,s){let c=i;i.startsWith(`/`)||(c=`/`+i);let[l,u]=c.split(`|`),d=a(s,l),f=d?d.split(`/`).filter(e=>e):[],p=o(f.map(e=>e.startsWith(`{`)&&e.endsWith(`}`)?{type:`param`,original:e,normalized:e.slice(1,-1)}:{type:`normal`,original:e,normalized:e})),m=s.parameterSeparator??`_`,h=``,g=[],_=e=>{if(g.length>0){let t=g.map((t,r)=>n(t,e&&r===0)).join(``);h+=(h&&g.length>0?m:``)+t,g=[]}};for(let e of p)if(e.type===`normal`)g.push(e.normalized);else{_(h===``);let n=t(e.normalized);h+=(h?m:``)+n}_(h===``);let v=``;g=[];let y=()=>{if(g.length>0){let e=g.map(e=>r(e)).join(``);v+=(v&&g.length>0?m:``)+e,g=[]}};for(let e of p)if(e.type===`normal`)g.push(e.normalized);else{y();let t=r(e.normalized);v+=(v?m:``)+t}y();let b=``;f.length>0?(b=f.map(e=>e.replace(/[{}]/g,``)).join(`-`),b=`${b}-${u}`.toLowerCase()):b=`${u}`.toLowerCase();let x=`/`+d;d||(x=`/`),x=x.replace(/\{([\w-]+)\}/g,(e,t)=>`\${${t.replace(/-/g,`_`)}}`);let S=v?`${v}_${u}`:u,C=e.getNamespacePrefix(s),w=C?`${C}_${S}`:S;return{apiName:h?`${h}_${u}`:u,fileName:b,typeName:w,path:x}}exports.convertEndpointString=s;
@@ -1 +1 @@
1
- require(`../../_virtual/rolldown_runtime.cjs`);const e=require(`../../utils/logger.cjs`);require(`../../utils/index.cjs`);let t=require(`pinyin-pro`);function n(e){return/[\u4e00-\u9fff]/.test(e)}function r(e){return e?e.charAt(0).toUpperCase()+e.slice(1):``}function i(e){return e.split(/[^a-zA-Z0-9_]+/).filter(Boolean).map(e=>r(e)).join(``)}function a(e){return n(e)?(e.match(/[\u4e00-\u9fff]+|[^\u4e00-\u9fff]+/g)??[]).map(e=>n(e)?(0,t.pinyin)(e,{toneType:`none`,type:`array`}).map(e=>r(e)).join(``):i(e)).join(``):e}function o(e){return e?/^[0-9]/.test(e)?`_${e}`:e:`Unknown`}function s(e){return e?n(e)?o(a(e)):/[^a-zA-Z0-9_$]/.test(e)?o(i(e)):o(e):`Unknown`}function c(e){return e.replace(/[^a-zA-Z0-9]+/g,`-`).replace(/([a-z])([A-Z])/g,`$1-$2`).toLowerCase().replace(/-+/g,`-`).replace(/^-|-$/g,``)}function l(e){let t=(e??``).trim();return t?(t.split(/[\\/]/).pop()??``).replace(/\.[^.]+$/,``).replace(/[^a-zA-Z0-9_-]+/g,`-`).replace(/^-+|-+$/g,``):``}function u(e){return e.__segment??``}function d(e){if(!e)return``;let t=e.split(/[-_.]+/).filter(Boolean).map(e=>r(e.toLowerCase())).join(``);return t?/^[0-9]/.test(t)?`_${t}`:t:``}function f(e){let t=e.__namespacePrefix;return typeof t==`string`?t:(e.namespaceIsolation??`segment`)===`none`?``:d(u(e))}function p(e){let t=e.apiListFileName?.replace(/\.[^/.]+$/,``).trim();if(t)return`【${t}】`;let n=u(e);if(n)return`【${n}】`;let r=e.swaggerJsonUrl;if(r)try{let e=new URL(r).host;if(e)return`【${e}】`}catch{}return``}function m(t,n){return!n||!t?t:t.startsWith(`./`)||t.startsWith(`../`)?`../`+t:(t.startsWith(`/`)||/^[a-zA-Z@]/.test(t)||e.log.warning(`importEnumPath="${t}" 形态不明确,建议以 "./" 或 "../" 开头。多服务隔离已开启,工具未自动补偿层级,请自行确认 enum 引用是否正确。`),t)}function h(e){let t=u(e);return!t||(e.enumIsolation??`segment`)===`none`?``:t}function g(e,t){return t?e?`${e.replace(/\/+$/,``)}/${t}`:t:e}function _(e,t){return e.enmuConfig.erasableSyntaxOnly?`${t}Type`:t}function v(e){return!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)}function y(e){return v(e)?`"${e}"`:e}exports.adjustImportPathForSegment=m,exports.appendEnumSegment=g,exports.computeSegment=l,exports.containsChinese=n,exports.formatPropertyName=y,exports.getEnumSegment=h,exports.getEnumTypeName=_,exports.getNamespacePrefix=f,exports.getServerSegment=u,exports.getServiceTag=p,exports.resolveSchemaName=s,exports.segmentToNamespacePrefix=d,exports.typeNameToFileName=c,exports.wordsToPascalCase=i;
1
+ require(`../../_virtual/rolldown_runtime.cjs`);const e=require(`../../utils/logger.cjs`);require(`../../utils/index.cjs`);let t=require(`pinyin-pro`);function n(e){return/[\u4e00-\u9fff]/.test(e)}function r(e){return e?e.charAt(0).toUpperCase()+e.slice(1):``}function i(e){return e.split(/[^a-zA-Z0-9_]+/).filter(Boolean).map(e=>r(e)).join(``)}function a(e){return n(e)?(e.match(/[\u4e00-\u9fff]+|[^\u4e00-\u9fff]+/g)??[]).map(e=>n(e)?(0,t.pinyin)(e,{toneType:`none`,type:`array`}).map(e=>r(e)).join(``):i(e)).join(``):e}function o(e){return e?/^[0-9]/.test(e)?`_${e}`:e:`Unknown`}function s(e){return e?n(e)?o(a(e)):/[^a-zA-Z0-9_$]/.test(e)?o(i(e)):o(e):`Unknown`}function c(e){return e.replace(/[^a-zA-Z0-9]+/g,`-`).replace(/([a-z])([A-Z])/g,`$1-$2`).toLowerCase().replace(/-+/g,`-`).replace(/^-|-$/g,``)}function l(e){let t=(e??``).trim();return t?(t.split(/[\\/]/).pop()??``).replace(/\.[^.]+$/,``).replace(/[^a-zA-Z0-9_-]+/g,`-`).replace(/^-+|-+$/g,``):``}function u(e){return e.__segment??``}function d(e){if(!e)return``;let t=e.split(/[-_.]+/).filter(Boolean).map(e=>r(e.toLowerCase())).join(``);return t?/^[0-9]/.test(t)?`_${t}`:t:``}function f(e){let t=e.__namespacePrefix;return typeof t==`string`?t:(e.namespaceIsolation??`segment`)===`none`?``:d(u(e))}function p(e){let t=e.apiListFileName?.replace(/\.[^/.]+$/,``).trim();if(t)return`【${t}】`;let n=u(e);if(n)return`【${n}】`;let r=e.swaggerJsonUrl;if(r)try{let e=new URL(r).host;if(e)return`【${e}】`}catch{}return``}function m(t,n){return!n||!t?t:t.startsWith(`./`)||t.startsWith(`../`)?`../`+t:(t.startsWith(`/`)||/^[a-zA-Z@]/.test(t)||e.log.warning(`importEnumPath="${t}" 形态不明确,建议以 "./" 或 "../" 开头。多服务隔离已开启,工具未自动补偿层级,请自行确认 enum 引用是否正确。`),t)}function h(e){let t=u(e);return!t||(e.enumIsolation??`segment`)===`none`?``:t}function g(e,t){return t?e?`${e.replace(/\/+$/,``)}/${t}`:t:e}function _(e,t){return e.enmuConfig.erasableSyntaxOnly?`${t}Type`:t}function v(e){return!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)}function y(e){return v(e)?`"${e}"`:e}function b(e){return e&&e.replace(/-/g,`_`)}exports.adjustImportPathForSegment=m,exports.appendEnumSegment=g,exports.computeSegment=l,exports.containsChinese=n,exports.formatPropertyName=y,exports.getEnumSegment=h,exports.getEnumTypeName=_,exports.getNamespacePrefix=f,exports.getServerSegment=u,exports.getServiceTag=p,exports.resolveSchemaName=s,exports.sanitizeIdentifierName=b,exports.segmentToNamespacePrefix=d,exports.typeNameToFileName=c,exports.wordsToPascalCase=i;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anl",
3
- "version": "26.510.1",
3
+ "version": "26.514.1",
4
4
  "description": "FE command line tool",
5
5
  "main": "bin/an-cli.js",
6
6
  "exports": {