anl 26.514.0 → 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.514.
|
|
1
|
+
var e=`26.514.1`;Object.defineProperty(exports,`version`,{enumerable:!0,get:function(){return e}});
|
|
@@ -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));let e=n.sanitizeIdentifierName(c.name);r.push(`${o}${e}
|
|
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;
|