anl 26.611.0 → 26.806.0

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.611.0`;Object.defineProperty(exports,`version`,{enumerable:!0,get:function(){return e}});
1
+ var e=`26.806.0`;Object.defineProperty(exports,`version`,{enumerable:!0,get:function(){return e}});
@@ -2,6 +2,7 @@ const e=require(`../../utils/logger.cjs`),t=require(`../../utils/index.cjs`),n=r
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],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(`
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){if(e.type!==`object`)return{headerRef:``,renderStr:``};let r=e,i=n.getIndentation(this.config),a=this.isRequired(t)?``:`?`,o=this.nullable(r.nullable),s=r.additionalProperties;if(s&&typeof s==`object`){let e=this.parseArray(s,t)??this.defaultReturn;return{headerRef:e?.headerRef??``,renderStr:e?.renderStr??``}}if(r.properties&&Object.keys(r.properties).length>0){let e=[],n=this.renderInlineObjectType(r,e);return{headerRef:e.join(`
6
+ `),renderStr:`${i}${t}${a}: ${n}${o};`}}return s===!0?{headerRef:``,renderStr:`${i}${t}${a}: Record<string, unknown>${o};`}:{headerRef:``,renderStr:`${i}${t}${a}: object${o};`}}renderInlineObjectType(e,t){let n=e.properties;if(!n||Object.keys(n).length===0)return e.additionalProperties===!0?`Record<string, unknown>`:`object`;let i=new Set(e.required??[]),a=[];for(let e of Object.keys(n).sort()){let o=n[e],s=r.formatPropertyName(e),c=s.startsWith(`"`)&&s.endsWith(`"`)?s.slice(1,-1):s,l=i.has(c)?``:`?`,u=this.renderInlineTypeString(o,t),d=`$ref`in o?``:this.nullable(o.nullable);a.push(`${s}${l}: ${u}${d};`)}return`{ ${a.join(` `)} }`}renderInlineTypeString(e,t){if(`$ref`in e&&e.$ref){let{headerRefStr:n,typeName:i,dataType:a}=this.parseRef(e.$ref);return n&&!t.includes(n)&&t.push(n),a===`enum`?r.getEnumTypeName(this.config,i):i}let n=e;switch(n.type){case`string`:return Array.isArray(n.enum)?n.enum.map(e=>`'${e}'`).join(` | `):this.getStringTypeByFormat(n.format);case`integer`:case`number`:return Array.isArray(n.enum)?n.enum.join(` | `):`number`;case`boolean`:return`boolean`;case`array`:return`Array<${this.renderInlineTypeString(n.items,t)}>`;case`object`:return this.renderInlineObjectType(n,t);default:return`unknown`}}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
7
  `);return{headerRef:o.join(`
7
8
  `),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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anl",
3
- "version": "26.611.0",
3
+ "version": "26.806.0",
4
4
  "description": "FE command line tool",
5
5
  "main": "bin/an-cli.js",
6
6
  "exports": {