@hey-api/openapi-ts 0.86.3 → 0.86.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/bin/run.cmd +3 -0
- package/bin/run.js +18 -0
- package/dist/clients/angular/utils.ts +9 -8
- package/dist/clients/axios/utils.ts +9 -8
- package/dist/clients/core/bodySerializer.ts +12 -4
- package/dist/clients/fetch/utils.ts +9 -8
- package/dist/clients/next/utils.ts +9 -8
- package/dist/clients/nuxt/utils.ts +9 -8
- package/dist/clients/ofetch/utils.ts +9 -8
- package/dist/getSpec-CdBgV-sm.js +24 -0
- package/dist/getSpec-CdBgV-sm.js.map +1 -0
- package/dist/getSpec-y1q2Fa6c.cjs +24 -0
- package/dist/getSpec-y1q2Fa6c.cjs.map +1 -0
- package/dist/index.cjs +1 -1318
- package/dist/index.d.cts +1217 -11
- package/dist/index.d.ts +1219 -11
- package/dist/index.js +1 -1310
- package/dist/internal.cjs +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +1 -1
- package/dist/run.cjs +3 -0
- package/dist/run.cjs.map +1 -0
- package/dist/run.d.cts +1 -0
- package/dist/run.d.ts +1 -0
- package/dist/run.js +3 -0
- package/dist/run.js.map +1 -0
- package/dist/src-DxujYdu0.cjs +1318 -0
- package/dist/src-DxujYdu0.cjs.map +1 -0
- package/dist/src-SnUobB4f.js +1310 -0
- package/dist/src-SnUobB4f.js.map +1 -0
- package/dist/{types-TTJZ61ck.d.ts → types-7_tn_FD9.d.ts} +7674 -8802
- package/dist/{types-CBGf9bNY.d.cts → types-ComCm5zo.d.cts} +7674 -8802
- package/package.json +3 -3
- package/bin/index.cjs +0 -148
- package/dist/getSpec-DhkA7wWv.cjs +0 -24
- package/dist/getSpec-DhkA7wWv.cjs.map +0 -1
- package/dist/getSpec-DzntayfV.js +0 -24
- package/dist/getSpec-DzntayfV.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,1310 @@
|
|
|
1
|
+
import{i as e,r as t,t as n}from"./chunk-C-EqMg7d.js";import{A as r,C as i,D as a,E as o,F as s,I as c,M as l,N as u,O as d,P as f,S as p,T as m,d as h,f as g,g as _,h as v,i as y,j as b,k as ee,l as te,m as ne,n as re,o as x,p as S,t as ie,u as ae,v as C,w,y as T}from"./getSpec-CdBgV-sm.js";import"@hey-api/codegen-core";import E from"ansi-colors";import oe from"color-support";import D from"node:fs";import O from"node:path";import{$RefParser as se}from"@hey-api/json-schema-ref-parser";import k from"handlebars";const ce=()=>{if(typeof Bun<`u`){let[e]=Bun.version.split(`.`).map(Number);if(e<1)throw new a(`Unsupported Bun version ${Bun.version}. Please use Bun 1.0.0 or newer.`)}else if(typeof process<`u`&&process.versions?.node){let[e]=process.versions.node.split(`.`).map(Number);if(e<20)throw new a(`Unsupported Node version ${process.versions.node}. Please use Node 20 or newer.`)}},A=e=>{switch(e){case`legacy/angular`:return`AngularHttpRequest`;case`legacy/axios`:return`AxiosHttpRequest`;case`legacy/fetch`:return`FetchHttpRequest`;case`legacy/node`:return`NodeHttpRequest`;case`legacy/xhr`:return`XHRHttpRequest`;default:return``}},le=async(e,t,n,r)=>{let a=i(),s=o(a),c=r.client({$config:a,...n,httpRequest:A(s.name),models:g(n.models),services:g(n.services)});m(a)&&(f(t),D.writeFileSync(O.resolve(t,`${m(a)}.ts`),c))},j=async(e,t,n)=>{let r=i();if(r.exportCore){let i=o(r),a={httpRequest:A(i.name),server:r.base===void 0?t.server:r.base,version:t.version};if(D.rmSync(O.resolve(e),{force:!0,recursive:!0}),D.mkdirSync(O.resolve(e),{recursive:!0}),await D.writeFileSync(O.resolve(e,`OpenAPI.ts`),n.core.settings({$config:r,...a})),await D.writeFileSync(O.resolve(e,`ApiError.ts`),n.core.apiError({$config:r,...a})),await D.writeFileSync(O.resolve(e,`ApiRequestOptions.ts`),n.core.apiRequestOptions({$config:r,...a})),await D.writeFileSync(O.resolve(e,`ApiResult.ts`),n.core.apiResult({$config:r,...a})),i.name!==`legacy/angular`&&await D.writeFileSync(O.resolve(e,`CancelablePromise.ts`),n.core.cancelablePromise({$config:r,...a})),await D.writeFileSync(O.resolve(e,`request.ts`),n.core.request({$config:r,...a})),m(r)&&(await D.writeFileSync(O.resolve(e,`BaseHttpRequest.ts`),n.core.baseHttpRequest({$config:r,...a})),await D.writeFileSync(O.resolve(e,`${a.httpRequest}.ts`),n.core.httpRequest({$config:r,...a}))),r.request){let t=O.resolve(process.cwd(),r.request);if(!await D.existsSync(t))throw Error(`Custom request file "${t}" does not exists`);await D.copyFileSync(t,O.resolve(e,`request.ts`))}}},M=({files:e})=>{let t=i();e.index=new y({dir:t.output.path,id:`index`,name:`index.ts`}),m(t)&&e.index.add(C.exportNamedDeclaration({exports:m(t),module:`./${m(t)}`})),t.exportCore&&(e.index.add(C.exportNamedDeclaration({exports:`ApiError`,module:`./core/ApiError`})),t.plugins[`@hey-api/sdk`]?.config.response===`response`&&e.index.add(C.exportNamedDeclaration({exports:{asType:!0,name:`ApiResult`},module:`./core/ApiResult`})),m(t)&&e.index.add(C.exportNamedDeclaration({exports:`BaseHttpRequest`,module:`./core/BaseHttpRequest`})),o(t).name!==`legacy/angular`&&e.index.add(C.exportNamedDeclaration({exports:[`CancelablePromise`,`CancelError`],module:`./core/CancelablePromise`})),e.index.add(C.exportNamedDeclaration({exports:[`OpenAPI`,{asType:!0,name:`OpenAPIConfig`}],module:`./core/OpenAPI`}))),Object.keys(e).sort().forEach(t=>{let n=e[t];t===`index`||n.isEmpty()||n.exportFromIndex&&e.index.add(C.exportAllDeclaration({module:`./${n.nameWithoutExtension()}`}))})},N=async({client:e,openApi:t,templates:n})=>{let r=i(),a=t;if(e){if(r.plugins[`@hey-api/sdk`]?.config.include&&r.plugins[`@hey-api/sdk`].config.asClass){let t=new RegExp(r.plugins[`@hey-api/sdk`].config.include);e.services=e.services.filter(e=>t.test(e.name))}if(r.plugins[`@hey-api/typescript`]?.config.include){let t=new RegExp(r.plugins[`@hey-api/typescript`].config.include);e.models=e.models.filter(e=>t.test(e.name))}}let c=O.resolve(r.output.path);r.output.clean&&s(c);let l=o(r);!w(r)&&`bundle`in l.config&&l.config.bundle&&!r.dryRun&&x({meta:{importFileExtension:r.output.importFileExtension},outputPath:c,plugin:l}),await le(a,c,e,n),await j(O.resolve(r.output.path,`core`),e,n);let u={};for(let t of r.pluginOrder){let n=r.plugins[t],i=(n.output??``).split(`/`),o=O.resolve(r.output.path,...i.slice(0,i.length-1));u[n.name]=new y({dir:o,id:`legacy-unused-${n.name}`,name:`${i[i.length-1]}.ts`}),n.handlerLegacy?.({client:e,files:u,openApi:a,plugin:n})}M({files:u}),Object.entries(u).forEach(([e,t])=>{r.dryRun||(e===`index`?t.write(`
|
|
2
|
+
`,r.output.tsConfig):t.write(`
|
|
3
|
+
|
|
4
|
+
`,r.output.tsConfig))})},P=async({context:e})=>{let t=O.resolve(e.config.output.path);e.config.output.clean&&s(t);let n={importFileExtension:e.config.output.importFileExtension},r=o(e.config);`bundle`in r.config&&r.config.bundle&&!e.config.dryRun&&(e.config._FRAGILE_CLIENT_BUNDLE_RENAMED=x({meta:n,outputPath:t,plugin:r,project:e.gen}));for(let t of e.registerPlugins())await t.run();for(let r of e.gen.render(n)){let n=O.resolve(t,r.path),i=O.dirname(n);e.config.dryRun||(D.mkdirSync(i,{recursive:!0}),D.writeFileSync(n,r.content,{encoding:`utf8`}))}},F=({patchOptions:e,spec:t})=>{if(!e)return;let n=t;if(`swagger`in n){if(e.version&&n.swagger&&(n.swagger=typeof e.version==`string`?e.version:e.version(n.swagger)),e.meta&&n.info&&e.meta(n.info),e.schemas&&n.definitions)for(let t in e.schemas){let r=n.definitions[t];if(!r||typeof r!=`object`)continue;let i=e.schemas[t];i(r)}if(e.operations&&n.paths)for(let t in e.operations){let[r,i]=t.split(` `);if(!r||!i)continue;let a=n.paths[i];if(!a)continue;let o=a[r.toLocaleLowerCase()]||a[r.toLocaleUpperCase()];if(!o||typeof o!=`object`)continue;let s=e.operations[t];s(o)}return}if(e.version&&n.openapi&&(n.openapi=typeof e.version==`string`?e.version:e.version(n.openapi)),e.meta&&n.info&&e.meta(n.info),n.components){if(e.schemas&&n.components.schemas)for(let t in e.schemas){let r=n.components.schemas[t];if(!r||typeof r!=`object`)continue;let i=e.schemas[t];i(r)}if(e.parameters&&n.components.parameters)for(let t in e.parameters){let r=n.components.parameters[t];if(!r||typeof r!=`object`)continue;let i=e.parameters[t];i(r)}if(e.requestBodies&&n.components.requestBodies)for(let t in e.requestBodies){let r=n.components.requestBodies[t];if(!r||typeof r!=`object`)continue;let i=e.requestBodies[t];i(r)}if(e.responses&&n.components.responses)for(let t in e.responses){let r=n.components.responses[t];if(!r||typeof r!=`object`)continue;let i=e.responses[t];i(r)}}if(e.operations&&n.paths)for(let t in e.operations){let[r,i]=t.split(` `);if(!r||!i)continue;let a=n.paths[i];if(!a)continue;let o=a[r.toLocaleLowerCase()]||a[r.toLocaleUpperCase()];if(!o||typeof o!=`object`)continue;let s=e.operations[t];s(o)}};var I=n(((e,n)=>{n.exports=o,o.sync=s;var r=t(`fs`);function i(e,t){var n=t.pathExt===void 0?process.env.PATHEXT:t.pathExt;if(!n||(n=n.split(`;`),n.indexOf(``)!==-1))return!0;for(var r=0;r<n.length;r++){var i=n[r].toLowerCase();if(i&&e.substr(-i.length).toLowerCase()===i)return!0}return!1}function a(e,t,n){return!e.isSymbolicLink()&&!e.isFile()?!1:i(t,n)}function o(e,t,n){r.stat(e,function(r,i){n(r,r?!1:a(i,e,t))})}function s(e,t){return a(r.statSync(e),e,t)}})),L=n(((e,n)=>{n.exports=i,i.sync=a;var r=t(`fs`);function i(e,t,n){r.stat(e,function(e,r){n(e,e?!1:o(r,t))})}function a(e,t){return o(r.statSync(e),t)}function o(e,t){return e.isFile()&&s(e,t)}function s(e,t){var n=e.mode,r=e.uid,i=e.gid,a=t.uid===void 0?process.getuid&&process.getuid():t.uid,o=t.gid===void 0?process.getgid&&process.getgid():t.gid,s=64,c=8,l=1,u=s|c;return n&l||n&c&&i===o||n&s&&r===a||n&u&&a===0}})),R=n(((e,n)=>{t(`fs`);var r=process.platform===`win32`||global.TESTING_WINDOWS?I():L();n.exports=i,i.sync=a;function i(e,t,n){if(typeof t==`function`&&(n=t,t={}),!n){if(typeof Promise!=`function`)throw TypeError(`callback not provided`);return new Promise(function(n,r){i(e,t||{},function(e,t){e?r(e):n(t)})})}r(e,t||{},function(e,r){e&&(e.code===`EACCES`||t&&t.ignoreErrors)&&(e=null,r=!1),n(e,r)})}function a(e,t){try{return r.sync(e,t||{})}catch(e){if(t&&t.ignoreErrors||e.code===`EACCES`)return!1;throw e}}})),z=n(((e,n)=>{let r=process.platform===`win32`||process.env.OSTYPE===`cygwin`||process.env.OSTYPE===`msys`,i=t(`path`),a=r?`;`:`:`,o=R(),s=e=>Object.assign(Error(`not found: ${e}`),{code:`ENOENT`}),c=(e,t)=>{let n=t.colon||a,i=e.match(/\//)||r&&e.match(/\\/)?[``]:[...r?[process.cwd()]:[],...(t.path||process.env.PATH||``).split(n)],o=r?t.pathExt||process.env.PATHEXT||`.EXE;.CMD;.BAT;.COM`:``,s=r?o.split(n):[``];return r&&e.indexOf(`.`)!==-1&&s[0]!==``&&s.unshift(``),{pathEnv:i,pathExt:s,pathExtExe:o}},l=(e,t,n)=>{typeof t==`function`&&(n=t,t={}),t||={};let{pathEnv:r,pathExt:a,pathExtExe:l}=c(e,t),u=[],d=n=>new Promise((a,o)=>{if(n===r.length)return t.all&&u.length?a(u):o(s(e));let c=r[n],l=/^".*"$/.test(c)?c.slice(1,-1):c,d=i.join(l,e);a(f(!l&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d,n,0))}),f=(e,n,r)=>new Promise((i,s)=>{if(r===a.length)return i(d(n+1));let c=a[r];o(e+c,{pathExt:l},(a,o)=>{if(!a&&o)if(t.all)u.push(e+c);else return i(e+c);return i(f(e,n,r+1))})});return n?d(0).then(e=>n(null,e),n):d(0)};n.exports=l,l.sync=(e,t)=>{t||={};let{pathEnv:n,pathExt:r,pathExtExe:a}=c(e,t),l=[];for(let s=0;s<n.length;s++){let c=n[s],u=/^".*"$/.test(c)?c.slice(1,-1):c,d=i.join(u,e),f=!u&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d;for(let e=0;e<r.length;e++){let n=f+r[e];try{if(o.sync(n,{pathExt:a}))if(t.all)l.push(n);else return n}catch{}}}if(t.all&&l.length)return l;if(t.nothrow)return null;throw s(e)}})),B=n(((e,t)=>{let n=(e={})=>{let t=e.env||process.env;return(e.platform||process.platform)===`win32`?Object.keys(t).reverse().find(e=>e.toUpperCase()===`PATH`)||`Path`:`PATH`};t.exports=n,t.exports.default=n})),V=n(((e,n)=>{let r=t(`path`),i=z(),a=B();function o(e,t){let n=e.options.env||process.env,o=process.cwd(),s=e.options.cwd!=null,c=s&&process.chdir!==void 0&&!process.chdir.disabled;if(c)try{process.chdir(e.options.cwd)}catch{}let l;try{l=i.sync(e.command,{path:n[a({env:n})],pathExt:t?r.delimiter:void 0})}catch{}finally{c&&process.chdir(o)}return l&&=r.resolve(s?e.options.cwd:``,l),l}function s(e){return o(e)||o(e,!0)}n.exports=s})),H=n(((e,t)=>{let n=/([()\][%!^"`<>&|;, *?])/g;function r(e){return e=e.replace(n,`^$1`),e}function i(e,t){return e=`${e}`,e=e.replace(/(?=(\\+?)?)\1"/g,`$1$1\\"`),e=e.replace(/(?=(\\+?)?)\1$/,`$1$1`),e=`"${e}"`,e=e.replace(n,`^$1`),t&&(e=e.replace(n,`^$1`)),e}t.exports.command=r,t.exports.argument=i})),U=n(((e,t)=>{t.exports=/^#!(.*)/})),W=n(((e,t)=>{let n=U();t.exports=(e=``)=>{let t=e.match(n);if(!t)return null;let[r,i]=t[0].replace(/#! ?/,``).split(` `),a=r.split(`/`).pop();return a===`env`?i:i?`${a} ${i}`:a}})),ue=n(((e,n)=>{let r=t(`fs`),i=W();function a(e){let t=Buffer.alloc(150),n;try{n=r.openSync(e,`r`),r.readSync(n,t,0,150,0),r.closeSync(n)}catch{}return i(t.toString())}n.exports=a})),de=n(((e,n)=>{let r=t(`path`),i=V(),a=H(),o=ue(),s=process.platform===`win32`,c=/\.(?:com|exe)$/i,l=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function u(e){e.file=i(e);let t=e.file&&o(e.file);return t?(e.args.unshift(e.file),e.command=t,i(e)):e.file}function d(e){if(!s)return e;let t=u(e),n=!c.test(t);if(e.options.forceShell||n){let n=l.test(t);e.command=r.normalize(e.command),e.command=a.command(e.command),e.args=e.args.map(e=>a.argument(e,n)),e.args=[`/d`,`/s`,`/c`,`"${[e.command].concat(e.args).join(` `)}"`],e.command=process.env.comspec||`cmd.exe`,e.options.windowsVerbatimArguments=!0}return e}function f(e,t,n){t&&!Array.isArray(t)&&(n=t,t=null),t=t?t.slice(0):[],n=Object.assign({},n);let r={command:e,args:t,options:n,file:void 0,original:{command:e,args:t}};return n.shell?r:d(r)}n.exports=f})),fe=n(((e,t)=>{let n=process.platform===`win32`;function r(e,t){return Object.assign(Error(`${t} ${e.command} ENOENT`),{code:`ENOENT`,errno:`ENOENT`,syscall:`${t} ${e.command}`,path:e.command,spawnargs:e.args})}function i(e,t){if(!n)return;let r=e.emit;e.emit=function(n,i){if(n===`exit`){let n=a(i,t);if(n)return r.call(e,`error`,n)}return r.apply(e,arguments)}}function a(e,t){return n&&e===1&&!t.file?r(t.original,`spawn`):null}function o(e,t){return n&&e===1&&!t.file?r(t.original,`spawnSync`):null}t.exports={hookChildProcess:i,verifyENOENT:a,verifyENOENTSync:o,notFoundError:r}})),G=e(n(((e,n)=>{let r=t(`child_process`),i=de(),a=fe();function o(e,t,n){let o=i(e,t,n),s=r.spawn(o.command,o.args,o.options);return a.hookChildProcess(s,o),s}function s(e,t,n){let o=i(e,t,n),s=r.spawnSync(o.command,o.args,o.options);return s.error=s.error||a.verifyENOENTSync(s.status,o),s}n.exports=o,n.exports.spawn=o,n.exports.sync=s,n.exports._parse=i,n.exports._enoent=a}))(),1);const pe={biome:{args:e=>[`format`,`--write`,e],command:`biome`,name:`Biome (Format)`},prettier:{args:e=>[`--ignore-unknown`,e,`--write`,`--ignore-path`,`./.prettierignore`],command:`prettier`,name:`Prettier`}},me={biome:{args:e=>[`lint`,`--apply`,e],command:`biome`,name:`Biome (Lint)`},eslint:{args:e=>[e,`--fix`],command:`eslint`,name:`ESLint`},oxlint:{args:e=>[`--fix`,e],command:`oxlint`,name:`oxlint`}},he=({config:e})=>{if(e.output.format){let t=pe[e.output.format];console.log(`✨ Running ${t.name}`),(0,G.sync)(t.command,t.args(e.output.path))}if(e.output.lint){let t=me[e.output.lint];console.log(`✨ Running ${t.name}`),(0,G.sync)(t.command,t.args(e.output.path))}};function ge(e,t){return{...e,config:t,models:e.models.map(e=>_e(e)),services:ve(e.operations).map(ye),types:{}}}const _e=e=>({...e,$refs:e.$refs.filter((e,t,n)=>S(e,t,n)),enum:e.enum.filter((e,t,n)=>n.findIndex(t=>t.value===e.value)===t),enums:e.enums.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t),imports:e.imports.filter((t,n,r)=>S(t,n,r)&&t!==e.name).sort(h)}),ve=e=>{let t=i(),n=new Map;return e.forEach(e=>{(e.tags?.length&&(t.plugins[`@hey-api/sdk`]?.config.asClass||m(t))?e.tags.filter(S):[`Default`]).forEach(t=>{let r={...e,service:Se(t)},i=n.get(r.service)||xe(r);i.$refs=[...i.$refs,...r.$refs],i.imports=[...i.imports,...r.imports],i.operations=[...i.operations,r],n.set(r.service,i)})}),Array.from(n.values())},ye=e=>{let t={...e};return t.operations=be(t),t.operations.forEach(e=>{t.imports.push(...e.imports)}),t.imports=t.imports.filter(S).sort(h),t},be=e=>{let t=new Map;return e.operations.map(e=>{let n={...e};n.imports.push(...n.parameters.flatMap(e=>e.imports));let r=n.responses.filter(e=>e.responseTypes.includes(`success`));n.imports.push(...r.flatMap(e=>e.imports));let i=n.name,a=t.get(i)||0;return a>0&&(n.name=`${i}${a}`),t.set(i,a+1),n})},xe=e=>({$refs:[],imports:[],name:e.service,operations:[]}),Se=e=>T({case:`PascalCase`,value:_(e)}),Ce=e=>{let t={...e,path:``};if(e.path&&(typeof e.path!=`string`||e.registry!==`hey-api`))return t.path=e.path,t;let[n,r]=e.path.split(`?`),i=(r||``).split(`&`).map(e=>e.split(`=`)),a=n||``;a.endsWith(`/`)&&(a=a.slice(0,a.length-1));let[,o]=a.split(`://`),[s,c,l]=(o||``).split(`/`);t.organization=c||e.organization,t.project=l||e.project;let u=[],d=`api_key`;t.api_key=i.find(([e])=>e===d)?.[1]||e.api_key||process.env.HEY_API_TOKEN,t.api_key&&u.push(`${d}=${t.api_key}`);let f=`branch`;t.branch=i.find(([e])=>e===f)?.[1]||e.branch,t.branch&&u.push(`${f}=${t.branch}`);let p=`commit_sha`;t.commit_sha=i.find(([e])=>e===p)?.[1]||e.commit_sha,t.commit_sha&&u.push(`${p}=${t.commit_sha}`);let m=`tags`;t.tags=i.find(([e])=>e===m)?.[1]?.split(`,`)||e.tags,t.tags?.length&&u.push(`${m}=${t.tags.join(`,`)}`);let h=`version`;if(t.version=i.find(([e])=>e===h)?.[1]||e.version,t.version&&u.push(`${h}=${t.version}`),!t.organization)throw Error(`missing organization - from which Hey API Platform organization do you want to generate your output?`);if(!t.project)throw Error(`missing project - from which Hey API Platform project do you want to generate your output?`);let g=u.join(`&`),_=s||`get.heyapi.dev`,v=_.startsWith(`localhost`),y=[v?`http`:`https`,_].join(`://`),b=v?[y,`v1`,`get`,t.organization,t.project].join(`/`):[y,t.organization,t.project].join(`/`);return t.path=g?`${b}?${g}`:b,t},K=(e,t)=>{let n=[],r=E.gray(`[Job ${t+1}] `),i=e.length,a=E.cyan(`Generating from ${i} ${i===1?`input`:`inputs`}:`);n.push(`${r}⏳ ${a}`),e.forEach((e,t)=>{let i=` [${t+1}] `,a=E.cyan(i),o=` `.repeat(i.length);if(typeof e.path!=`string`){n.push(`${r}${a}raw OpenAPI specification`);return}switch(e.registry){case`hey-api`:{let t=[e.organization,e.project].filter(Boolean).join(`/`);n.push(`${r}${a}${t}`),e.branch&&n.push(`${r}${o}${E.gray(`branch:`)} ${E.green(e.branch)}`),e.commit_sha&&n.push(`${r}${o}${E.gray(`commit:`)} ${E.green(e.commit_sha)}`),e.tags?.length&&n.push(`${r}${o}${E.gray(`tags:`)} ${E.green(e.tags.join(`, `))}`),e.version&&n.push(`${r}${o}${E.gray(`version:`)} ${E.green(e.version)}`),n.push(`${r}${o}${E.gray(`registry:`)} ${E.green(`Hey API`)}`);break}case`readme`:{let t=[e.organization,e.project].filter(Boolean).join(`/`);t?n.push(`${r}${a}${t}`):n.push(`${r}${a}${e.path}`),e.uuid&&n.push(`${r}${o}${E.gray(`uuid:`)} ${E.green(e.uuid)}`),n.push(`${r}${o}${E.gray(`registry:`)} ${E.green(`ReadMe`)}`);break}case`scalar`:{let t=[e.organization,e.project].filter(Boolean).join(`/`);n.push(`${r}${a}${t}`),n.push(`${r}${o}${E.gray(`registry:`)} ${E.green(`Scalar`)}`);break}default:n.push(`${r}${a}${e.path}`);break}});for(let e of n)console.log(e)},q=async({config:e,dependencies:t,jobIndex:n,logger:r,templates:i,watches:a})=>{let o=a||Array.from({length:e.input.length},()=>({headers:new Headers})),s=e.input.map(e=>Ce(e));e.logs.level!==`silent`&&!a&&K(s,n);let c=async(e,t)=>{let n=r.timeEvent(`spec`),{arrayBuffer:i,error:c,resolvedInput:l,response:u}=await ie({fetchOptions:e.fetch,inputPath:s[t].path,timeout:e.watch.timeout,watch:o[t]});if(n.timeEnd(),c&&!a)throw Error(`Request failed with status ${u.status}: ${u.statusText}`);return{arrayBuffer:i,resolvedInput:l}},l=(await Promise.all(e.input.map((e,t)=>c(e,t)))).filter(e=>e.arrayBuffer||e.resolvedInput),u,d;if(l.length){let o=new se,c=l.length>1?await o.bundleMany({arrayBuffer:l.map(e=>e.arrayBuffer),pathOrUrlOrSchemas:[],resolvedInputs:l.map(e=>e.resolvedInput)}):await o.bundle({arrayBuffer:l[0].arrayBuffer,pathOrUrlOrSchema:void 0,resolvedInput:l[0].resolvedInput});e.logs.level!==`silent`&&a&&(console.clear(),K(s,n));let f=r.timeEvent(`input.patch`);F({patchOptions:e.parser.patch,spec:c}),f.timeEnd();let p=r.timeEvent(`parser`);e.experimentalParser&&!w(e)&&!m(e)&&(d=ae({config:e,dependencies:t,logger:r,spec:c})),d?d.graph=v(d.ir,r).graph:u=ge(te({openApi:c}),e),p.timeEnd();let h=r.timeEvent(`generator`);d?await P({context:d}):u&&await N({client:u,openApi:c,templates:i}),h.timeEnd();let g=r.timeEvent(`postprocess`);if(!e.dryRun&&(he({config:e}),e.logs.level!==`silent`)){let t=process.env.INIT_CWD?`./${O.relative(process.env.INIT_CWD,e.output.path)}`:e.output.path,r=E.gray(`[Job ${n+1}] `);console.log(`${r}${E.green(`✅ Done!`)} Your output is in ${E.cyanBright(t)}`)}g.timeEnd()}let f=e.input.find((e,t)=>e.watch.enabled&&typeof s[t].path==`string`);return f&&setTimeout(()=>{q({config:e,dependencies:t,jobIndex:n,logger:r,templates:i,watches:o})},f.watch.interval),d||u},we=(e,t)=>{let n=[],r=Array.from({length:t?.padding??0}).fill(``);n.push(...r);let i=0,a=``;for(let t of e)t===`
|
|
5
|
+
`?a&&=(n.push(a),i=Math.max(i,a.length),``):a+=t;return n.push(...r),{lines:n,maxLineLength:i}};function Te(){let e=c(),t=we(`
|
|
6
|
+
888 | e 888~-_ 888
|
|
7
|
+
888___| e88~~8e Y88b / d8b 888 \\ 888
|
|
8
|
+
888 | d888 88b Y888/ /Y88b 888 | 888
|
|
9
|
+
888 | 8888__888 Y8/ / Y88b 888 / 888
|
|
10
|
+
888 | Y888 , Y /____Y88b 888_-~ 888
|
|
11
|
+
888 | "88___/ / / Y88b 888 888
|
|
12
|
+
_/
|
|
13
|
+
`,{padding:1});for(let e of t.lines)console.log(E.cyan(e));console.log(E.gray(`${e.name} v${e.version}`)),console.log(``)}var Ee={1:function(e,t,n,r,i){return`import { NgModule} from '@angular/core';
|
|
14
|
+
import { HttpClientModule } from '@angular/common/http';
|
|
15
|
+
|
|
16
|
+
import { AngularHttpRequest } from './core/AngularHttpRequest';
|
|
17
|
+
import { BaseHttpRequest } from './core/BaseHttpRequest';
|
|
18
|
+
import type { OpenAPIConfig } from './core/OpenAPI';
|
|
19
|
+
import { OpenAPI } from './core/OpenAPI';
|
|
20
|
+
import { Interceptors } from './core/OpenAPI';
|
|
21
|
+
`},3:function(e,t,n,r,i){var a=e.strict,o=e.lambda;return`import type { BaseHttpRequest } from './core/BaseHttpRequest';
|
|
22
|
+
import type { OpenAPIConfig } from './core/OpenAPI';
|
|
23
|
+
import { Interceptors } from './core/OpenAPI';
|
|
24
|
+
import { `+(o(a(t,`httpRequest`,{start:{line:14,column:12},end:{line:14,column:23}}),t)??``)+` } from './core/`+(o(a(t,`httpRequest`,{start:{line:14,column:45},end:{line:14,column:56}}),t)??``)+`';
|
|
25
|
+
`},5:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return a(n,`each`).call(t??(e.nullContext||{}),a(t,`services`),{name:`each`,hash:{},fn:e.program(6,i,0),inverse:e.noop,data:i,loc:{start:{line:18,column:0},end:{line:20,column:9}}})??``},6:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`import { `+(a(n,`transformServiceName`).call(t??(e.nullContext||{}),a(t,`name`),{name:`transformServiceName`,hash:{},data:i,loc:{start:{line:19,column:9},end:{line:19,column:40}}})??``)+` } from './sdk.gen';
|
|
26
|
+
`},8:function(e,t,n,r,i){var a=e.strict,o=e.lambda,s=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`@NgModule({
|
|
27
|
+
imports: [HttpClientModule],
|
|
28
|
+
providers: [
|
|
29
|
+
{
|
|
30
|
+
provide: OpenAPI,
|
|
31
|
+
useValue: {
|
|
32
|
+
BASE: OpenAPI?.BASE ?? '`+(o(a(t,`server`,{start:{line:30,column:31},end:{line:30,column:37}}),t)??``)+`',
|
|
33
|
+
VERSION: OpenAPI?.VERSION ?? '`+(o(a(t,`version`,{start:{line:31,column:37},end:{line:31,column:44}}),t)??``)+`',
|
|
34
|
+
WITH_CREDENTIALS: OpenAPI?.WITH_CREDENTIALS ?? false,
|
|
35
|
+
CREDENTIALS: OpenAPI?.CREDENTIALS ?? 'include',
|
|
36
|
+
TOKEN: OpenAPI?.TOKEN,
|
|
37
|
+
USERNAME: OpenAPI?.USERNAME,
|
|
38
|
+
PASSWORD: OpenAPI?.PASSWORD,
|
|
39
|
+
HEADERS: OpenAPI?.HEADERS,
|
|
40
|
+
ENCODE_PATH: OpenAPI?.ENCODE_PATH,
|
|
41
|
+
interceptors: {
|
|
42
|
+
response: OpenAPI?.interceptors?.response ?? new Interceptors(),
|
|
43
|
+
},
|
|
44
|
+
} as OpenAPIConfig,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
provide: BaseHttpRequest,
|
|
48
|
+
useClass: AngularHttpRequest,
|
|
49
|
+
},
|
|
50
|
+
`+(s(n,`each`).call(t??(e.nullContext||{}),s(t,`services`),{name:`each`,hash:{},fn:e.program(9,i,0),inverse:e.noop,data:i,loc:{start:{line:48,column:2},end:{line:50,column:11}}})??``)+` ]
|
|
51
|
+
})
|
|
52
|
+
export class `+(o(a(s(s(i,`root`),`$config`),`name`,{start:{line:53,column:16},end:{line:53,column:34}}),t)??``)+` {}
|
|
53
|
+
`},9:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return` `+(a(n,`transformServiceName`).call(t??(e.nullContext||{}),a(t,`name`),{name:`transformServiceName`,hash:{},data:i,loc:{start:{line:49,column:2},end:{line:49,column:33}}})??``)+`,
|
|
54
|
+
`},11:function(e,t,n,r,i){var a=e.strict,o=e.lambda,s=t??(e.nullContext||{}),c=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
|
|
55
|
+
|
|
56
|
+
export class `+(o(a(c(c(i,`root`),`$config`),`name`,{start:{line:57,column:16},end:{line:57,column:34}}),t)??``)+` {
|
|
57
|
+
|
|
58
|
+
`+(c(n,`each`).call(s,c(t,`services`),{name:`each`,hash:{},fn:e.program(12,i,0),inverse:e.noop,data:i,loc:{start:{line:59,column:1},end:{line:61,column:10}}})??``)+`
|
|
59
|
+
public readonly request: BaseHttpRequest;
|
|
60
|
+
|
|
61
|
+
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = `+(o(a(t,`httpRequest`,{start:{line:65,column:87},end:{line:65,column:98}}),t)??``)+`) {
|
|
62
|
+
this.request = new HttpRequest({
|
|
63
|
+
BASE: config?.BASE ?? '`+(o(a(t,`server`,{start:{line:67,column:29},end:{line:67,column:35}}),t)??``)+`',
|
|
64
|
+
VERSION: config?.VERSION ?? '`+(o(a(t,`version`,{start:{line:68,column:35},end:{line:68,column:42}}),t)??``)+`',
|
|
65
|
+
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
|
|
66
|
+
CREDENTIALS: config?.CREDENTIALS ?? 'include',
|
|
67
|
+
TOKEN: config?.TOKEN,
|
|
68
|
+
USERNAME: config?.USERNAME,
|
|
69
|
+
PASSWORD: config?.PASSWORD,
|
|
70
|
+
HEADERS: config?.HEADERS,
|
|
71
|
+
ENCODE_PATH: config?.ENCODE_PATH,
|
|
72
|
+
interceptors: {
|
|
73
|
+
request: config?.interceptors?.request ?? new Interceptors(),
|
|
74
|
+
response: config?.interceptors?.response ?? new Interceptors(),
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
`+(c(n,`each`).call(s,c(t,`services`),{name:`each`,hash:{},fn:e.program(14,i,0),inverse:e.noop,data:i,loc:{start:{line:82,column:2},end:{line:84,column:11}}})??``)+` }
|
|
79
|
+
}
|
|
80
|
+
`},12:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return` public readonly `+(o(n,`camelCase`).call(a,o(t,`name`),{name:`camelCase`,hash:{},data:i,loc:{start:{line:60,column:17},end:{line:60,column:37}}})??``)+`: `+(o(n,`transformServiceName`).call(a,o(t,`name`),{name:`transformServiceName`,hash:{},data:i,loc:{start:{line:60,column:39},end:{line:60,column:70}}})??``)+`;
|
|
81
|
+
`},14:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return` this.`+(o(n,`camelCase`).call(a,o(t,`name`),{name:`camelCase`,hash:{},data:i,loc:{start:{line:83,column:7},end:{line:83,column:27}}})??``)+` = new `+(o(n,`transformServiceName`).call(a,o(t,`name`),{name:`transformServiceName`,hash:{},data:i,loc:{start:{line:83,column:34},end:{line:83,column:65}}})??``)+`(this.request);
|
|
82
|
+
`},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:1,column:0},end:{line:15,column:11}}})??``)+`
|
|
83
|
+
`+(o(n,`if`).call(a,o(t,`services`),{name:`if`,hash:{},fn:e.program(5,i,0),inverse:e.noop,data:i,loc:{start:{line:17,column:0},end:{line:21,column:7}}})??``)+`
|
|
84
|
+
`+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(8,i,0),inverse:e.program(11,i,0),data:i,loc:{start:{line:23,column:0},end:{line:87,column:11}}})??``)},useData:!0},De={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getHeaders = <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): Observable<HttpHeaders> => {
|
|
85
|
+
return forkJoin({
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
token: resolve(options, config.TOKEN),
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
username: resolve(options, config.USERNAME),
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
password: resolve(options, config.PASSWORD),
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
additionalHeaders: resolve(options, config.HEADERS),
|
|
94
|
+
}).pipe(
|
|
95
|
+
map(({ token, username, password, additionalHeaders }) => {
|
|
96
|
+
const headers = Object.entries({
|
|
97
|
+
Accept: 'application/json',
|
|
98
|
+
...additionalHeaders,
|
|
99
|
+
...options.headers,
|
|
100
|
+
})
|
|
101
|
+
.filter(([, value]) => value !== undefined && value !== null)
|
|
102
|
+
.reduce((headers, [key, value]) => ({
|
|
103
|
+
...headers,
|
|
104
|
+
[key]: String(value),
|
|
105
|
+
}), {} as Record<string, string>);
|
|
106
|
+
|
|
107
|
+
if (isStringWithValue(token)) {
|
|
108
|
+
headers['Authorization'] = \`Bearer \${token}\`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
112
|
+
const credentials = base64(\`\${username}:\${password}\`);
|
|
113
|
+
headers['Authorization'] = \`Basic \${credentials}\`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (options.body !== undefined) {
|
|
117
|
+
if (options.mediaType) {
|
|
118
|
+
headers['Content-Type'] = options.mediaType;
|
|
119
|
+
} else if (isBlob(options.body)) {
|
|
120
|
+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
|
121
|
+
} else if (isString(options.body)) {
|
|
122
|
+
headers['Content-Type'] = 'text/plain';
|
|
123
|
+
} else if (!isFormData(options.body)) {
|
|
124
|
+
headers['Content-Type'] = 'application/json';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return new HttpHeaders(headers);
|
|
129
|
+
}),
|
|
130
|
+
);
|
|
131
|
+
};`},useData:!0},Oe={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getRequestBody = (options: ApiRequestOptions): unknown => {
|
|
132
|
+
if (options.body) {
|
|
133
|
+
if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
|
|
134
|
+
return JSON.stringify(options.body);
|
|
135
|
+
} else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
|
|
136
|
+
return options.body;
|
|
137
|
+
} else {
|
|
138
|
+
return JSON.stringify(options.body);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return undefined;
|
|
142
|
+
};`},useData:!0},ke={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseBody = <T>(response: HttpResponse<T>): T | undefined => {
|
|
143
|
+
if (response.status !== 204 && response.body !== null) {
|
|
144
|
+
return response.body;
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
};`},useData:!0},Ae={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseHeader = <T>(response: HttpResponse<T>, responseHeader?: string): string | undefined => {
|
|
148
|
+
if (responseHeader) {
|
|
149
|
+
const value = response.headers.get(responseHeader);
|
|
150
|
+
if (isString(value)) {
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
};`},useData:!0},je={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
156
|
+
import type { HttpResponse, HttpErrorResponse } from '@angular/common/http';
|
|
157
|
+
import { forkJoin, of, throwError } from 'rxjs';
|
|
158
|
+
import { catchError, map, switchMap } from 'rxjs/operators';
|
|
159
|
+
import type { Observable } from 'rxjs';
|
|
160
|
+
|
|
161
|
+
import { ApiError } from './ApiError';
|
|
162
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
163
|
+
import type { ApiResult } from './ApiResult';
|
|
164
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
165
|
+
|
|
166
|
+
`+(e.invokePartial(a(r,`functions/isString`),t,{name:`functions/isString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
167
|
+
|
|
168
|
+
`+(e.invokePartial(a(r,`functions/isStringWithValue`),t,{name:`functions/isStringWithValue`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
169
|
+
|
|
170
|
+
`+(e.invokePartial(a(r,`functions/isBlob`),t,{name:`functions/isBlob`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
171
|
+
|
|
172
|
+
`+(e.invokePartial(a(r,`functions/isFormData`),t,{name:`functions/isFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
173
|
+
|
|
174
|
+
`+(e.invokePartial(a(r,`functions/base64`),t,{name:`functions/base64`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
175
|
+
|
|
176
|
+
`+(e.invokePartial(a(r,`functions/getQueryString`),t,{name:`functions/getQueryString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
177
|
+
|
|
178
|
+
`+(e.invokePartial(a(r,`functions/getUrl`),t,{name:`functions/getUrl`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
179
|
+
|
|
180
|
+
`+(e.invokePartial(a(r,`functions/getFormData`),t,{name:`functions/getFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
181
|
+
|
|
182
|
+
`+(e.invokePartial(a(r,`functions/resolve`),t,{name:`functions/resolve`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
183
|
+
|
|
184
|
+
`+(e.invokePartial(a(r,`angular/getHeaders`),t,{name:`angular/getHeaders`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
185
|
+
|
|
186
|
+
`+(e.invokePartial(a(r,`angular/getRequestBody`),t,{name:`angular/getRequestBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
187
|
+
|
|
188
|
+
`+(e.invokePartial(a(r,`angular/sendRequest`),t,{name:`angular/sendRequest`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
189
|
+
|
|
190
|
+
`+(e.invokePartial(a(r,`angular/getResponseHeader`),t,{name:`angular/getResponseHeader`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
191
|
+
|
|
192
|
+
`+(e.invokePartial(a(r,`angular/getResponseBody`),t,{name:`angular/getResponseBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
193
|
+
|
|
194
|
+
`+(e.invokePartial(a(r,`functions/catchErrorCodes`),t,{name:`functions/catchErrorCodes`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Request method
|
|
198
|
+
* @param config The OpenAPI configuration object
|
|
199
|
+
* @param http The Angular HTTP client
|
|
200
|
+
* @param options The request options from the service
|
|
201
|
+
* @returns Observable<T>
|
|
202
|
+
* @throws ApiError
|
|
203
|
+
*/
|
|
204
|
+
export const request = <T>(config: OpenAPIConfig, http: HttpClient, options: ApiRequestOptions<T>): Observable<T> => {
|
|
205
|
+
const url = getUrl(config, options);
|
|
206
|
+
const formData = getFormData(options);
|
|
207
|
+
const body = getRequestBody(options);
|
|
208
|
+
|
|
209
|
+
return getHeaders(config, options).pipe(
|
|
210
|
+
switchMap(headers => {
|
|
211
|
+
return sendRequest<T>(config, options, http, url, body, formData, headers);
|
|
212
|
+
}),
|
|
213
|
+
switchMap(async response => {
|
|
214
|
+
for (const fn of config.interceptors.response._fns) {
|
|
215
|
+
response = await fn(response);
|
|
216
|
+
}
|
|
217
|
+
const responseBody = getResponseBody(response);
|
|
218
|
+
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
219
|
+
|
|
220
|
+
let transformedBody = responseBody;
|
|
221
|
+
if (options.responseTransformer && response.ok) {
|
|
222
|
+
transformedBody = await options.responseTransformer(responseBody)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
url,
|
|
227
|
+
ok: response.ok,
|
|
228
|
+
status: response.status,
|
|
229
|
+
statusText: response.statusText,
|
|
230
|
+
body: responseHeader ?? transformedBody,
|
|
231
|
+
} as ApiResult;
|
|
232
|
+
}),
|
|
233
|
+
catchError((error: HttpErrorResponse) => {
|
|
234
|
+
if (!error.status) {
|
|
235
|
+
return throwError(() => error);
|
|
236
|
+
}
|
|
237
|
+
return of({
|
|
238
|
+
url,
|
|
239
|
+
ok: error.ok,
|
|
240
|
+
status: error.status,
|
|
241
|
+
statusText: error.statusText,
|
|
242
|
+
body: error.error ?? error.statusText,
|
|
243
|
+
} as ApiResult);
|
|
244
|
+
}),
|
|
245
|
+
map(result => {
|
|
246
|
+
catchErrorCodes(options, result);
|
|
247
|
+
return result.body as T;
|
|
248
|
+
}),
|
|
249
|
+
catchError((error: ApiError) => {
|
|
250
|
+
return throwError(() => error);
|
|
251
|
+
}),
|
|
252
|
+
);
|
|
253
|
+
};`},usePartial:!0,useData:!0},Me={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const sendRequest = <T>(
|
|
254
|
+
config: OpenAPIConfig,
|
|
255
|
+
options: ApiRequestOptions<T>,
|
|
256
|
+
http: HttpClient,
|
|
257
|
+
url: string,
|
|
258
|
+
body: unknown,
|
|
259
|
+
formData: FormData | undefined,
|
|
260
|
+
headers: HttpHeaders
|
|
261
|
+
): Observable<HttpResponse<T>> => {
|
|
262
|
+
return http.request<T>(options.method, url, {
|
|
263
|
+
headers,
|
|
264
|
+
body: body ?? formData,
|
|
265
|
+
withCredentials: config.WITH_CREDENTIALS,
|
|
266
|
+
observe: 'response',
|
|
267
|
+
});
|
|
268
|
+
};`},useData:!0},Ne={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
269
|
+
import type { ApiResult } from './ApiResult';
|
|
270
|
+
|
|
271
|
+
export class ApiError extends Error {
|
|
272
|
+
public readonly url: string;
|
|
273
|
+
public readonly status: number;
|
|
274
|
+
public readonly statusText: string;
|
|
275
|
+
public readonly body: unknown;
|
|
276
|
+
public readonly request: ApiRequestOptions;
|
|
277
|
+
|
|
278
|
+
constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
|
|
279
|
+
super(message);
|
|
280
|
+
|
|
281
|
+
this.name = 'ApiError';
|
|
282
|
+
this.url = response.url;
|
|
283
|
+
this.status = response.status;
|
|
284
|
+
this.statusText = response.statusText;
|
|
285
|
+
this.body = response.body;
|
|
286
|
+
this.request = request;
|
|
287
|
+
}
|
|
288
|
+
}`},useData:!0},Pe={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export type ApiRequestOptions<T = unknown> = {
|
|
289
|
+
readonly body?: any;
|
|
290
|
+
readonly cookies?: Record<string, unknown>;
|
|
291
|
+
readonly errors?: Record<number | string, string>;
|
|
292
|
+
readonly formData?: Record<string, unknown> | any[] | Blob | File;
|
|
293
|
+
readonly headers?: Record<string, unknown>;
|
|
294
|
+
readonly mediaType?: string;
|
|
295
|
+
readonly method:
|
|
296
|
+
| 'DELETE'
|
|
297
|
+
| 'GET'
|
|
298
|
+
| 'HEAD'
|
|
299
|
+
| 'OPTIONS'
|
|
300
|
+
| 'PATCH'
|
|
301
|
+
| 'POST'
|
|
302
|
+
| 'PUT';
|
|
303
|
+
readonly path?: Record<string, unknown>;
|
|
304
|
+
readonly query?: Record<string, unknown>;
|
|
305
|
+
readonly responseHeader?: string;
|
|
306
|
+
readonly responseTransformer?: (data: unknown) => Promise<T>;
|
|
307
|
+
readonly url: string;
|
|
308
|
+
};`},useData:!0},Fe={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export type ApiResult<TData = any> = {
|
|
309
|
+
readonly body: TData;
|
|
310
|
+
readonly ok: boolean;
|
|
311
|
+
readonly status: number;
|
|
312
|
+
readonly statusText: string;
|
|
313
|
+
readonly url: string;
|
|
314
|
+
};`},useData:!0},Ie={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getHeaders = async <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): Promise<Record<string, string>> => {
|
|
315
|
+
const [token, username, password, additionalHeaders] = await Promise.all([
|
|
316
|
+
// @ts-ignore
|
|
317
|
+
resolve(options, config.TOKEN),
|
|
318
|
+
// @ts-ignore
|
|
319
|
+
resolve(options, config.USERNAME),
|
|
320
|
+
// @ts-ignore
|
|
321
|
+
resolve(options, config.PASSWORD),
|
|
322
|
+
// @ts-ignore
|
|
323
|
+
resolve(options, config.HEADERS),
|
|
324
|
+
]);
|
|
325
|
+
|
|
326
|
+
const headers = Object.entries({
|
|
327
|
+
Accept: 'application/json',
|
|
328
|
+
...additionalHeaders,
|
|
329
|
+
...options.headers,
|
|
330
|
+
})
|
|
331
|
+
.filter(([, value]) => value !== undefined && value !== null)
|
|
332
|
+
.reduce((headers, [key, value]) => ({
|
|
333
|
+
...headers,
|
|
334
|
+
[key]: String(value),
|
|
335
|
+
}), {} as Record<string, string>);
|
|
336
|
+
|
|
337
|
+
if (isStringWithValue(token)) {
|
|
338
|
+
headers['Authorization'] = \`Bearer \${token}\`;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
342
|
+
const credentials = base64(\`\${username}:\${password}\`);
|
|
343
|
+
headers['Authorization'] = \`Basic \${credentials}\`;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (options.body !== undefined) {
|
|
347
|
+
if (options.mediaType) {
|
|
348
|
+
headers['Content-Type'] = options.mediaType;
|
|
349
|
+
} else if (isBlob(options.body)) {
|
|
350
|
+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
|
351
|
+
} else if (isString(options.body)) {
|
|
352
|
+
headers['Content-Type'] = 'text/plain';
|
|
353
|
+
} else if (!isFormData(options.body)) {
|
|
354
|
+
headers['Content-Type'] = 'application/json';
|
|
355
|
+
}
|
|
356
|
+
} else if (options.formData !== undefined) {
|
|
357
|
+
if (options.mediaType) {
|
|
358
|
+
headers['Content-Type'] = options.mediaType;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return headers;
|
|
363
|
+
};`},useData:!0},Le={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getRequestBody = (options: ApiRequestOptions): unknown => {
|
|
364
|
+
if (options.body) {
|
|
365
|
+
return options.body;
|
|
366
|
+
}
|
|
367
|
+
return undefined;
|
|
368
|
+
};`},useData:!0},Re={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseBody = (response: AxiosResponse<unknown>): unknown => {
|
|
369
|
+
if (response.status !== 204) {
|
|
370
|
+
return response.data;
|
|
371
|
+
}
|
|
372
|
+
return undefined;
|
|
373
|
+
};`},useData:!0},ze={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseHeader = (response: AxiosResponse<unknown>, responseHeader?: string): string | undefined => {
|
|
374
|
+
if (responseHeader) {
|
|
375
|
+
const content = response.headers[responseHeader];
|
|
376
|
+
if (isString(content)) {
|
|
377
|
+
return content;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return undefined;
|
|
381
|
+
};`},useData:!0},Be={1:function(e,t,n,r,i){return`ApiResult<T>`},3:function(e,t,n,r,i){return`T`},5:function(e,t,n,r,i){return`result.body`},7:function(e,t,n,r,i){return`result`},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`import axios from 'axios';
|
|
382
|
+
import type { AxiosError, AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios';
|
|
383
|
+
|
|
384
|
+
import { ApiError } from './ApiError';
|
|
385
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
386
|
+
import type { ApiResult } from './ApiResult';
|
|
387
|
+
import { CancelablePromise } from './CancelablePromise';
|
|
388
|
+
import type { OnCancel } from './CancelablePromise';
|
|
389
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
390
|
+
|
|
391
|
+
`+(e.invokePartial(o(r,`functions/isString`),t,{name:`functions/isString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
392
|
+
|
|
393
|
+
`+(e.invokePartial(o(r,`functions/isStringWithValue`),t,{name:`functions/isStringWithValue`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
394
|
+
|
|
395
|
+
`+(e.invokePartial(o(r,`functions/isBlob`),t,{name:`functions/isBlob`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
396
|
+
|
|
397
|
+
`+(e.invokePartial(o(r,`functions/isFormData`),t,{name:`functions/isFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
398
|
+
|
|
399
|
+
`+(e.invokePartial(o(r,`functions/isSuccess`),t,{name:`functions/isSuccess`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
400
|
+
|
|
401
|
+
`+(e.invokePartial(o(r,`functions/base64`),t,{name:`functions/base64`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
402
|
+
|
|
403
|
+
`+(e.invokePartial(o(r,`functions/getQueryString`),t,{name:`functions/getQueryString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
404
|
+
|
|
405
|
+
`+(e.invokePartial(o(r,`functions/getUrl`),t,{name:`functions/getUrl`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
406
|
+
|
|
407
|
+
`+(e.invokePartial(o(r,`functions/getFormData`),t,{name:`functions/getFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
408
|
+
|
|
409
|
+
`+(e.invokePartial(o(r,`functions/resolve`),t,{name:`functions/resolve`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
410
|
+
|
|
411
|
+
`+(e.invokePartial(o(r,`axios/getHeaders`),t,{name:`axios/getHeaders`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
412
|
+
|
|
413
|
+
`+(e.invokePartial(o(r,`axios/getRequestBody`),t,{name:`axios/getRequestBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
414
|
+
|
|
415
|
+
`+(e.invokePartial(o(r,`axios/sendRequest`),t,{name:`axios/sendRequest`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
416
|
+
|
|
417
|
+
`+(e.invokePartial(o(r,`axios/getResponseHeader`),t,{name:`axios/getResponseHeader`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
418
|
+
|
|
419
|
+
`+(e.invokePartial(o(r,`axios/getResponseBody`),t,{name:`axios/getResponseBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
420
|
+
|
|
421
|
+
`+(e.invokePartial(o(r,`functions/catchErrorCodes`),t,{name:`functions/catchErrorCodes`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Request method
|
|
425
|
+
* @param config The OpenAPI configuration object
|
|
426
|
+
* @param options The request options from the service
|
|
427
|
+
* @param axiosClient The axios client instance to use
|
|
428
|
+
* @returns CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:64,column:30},end:{line:64,column:108}}})??``)+`>
|
|
429
|
+
* @throws ApiError
|
|
430
|
+
*/
|
|
431
|
+
export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>, axiosClient: AxiosInstance = axios): CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:67,column:136},end:{line:67,column:214}}})??``)+`> => {
|
|
432
|
+
return new CancelablePromise(async (resolve, reject, onCancel) => {
|
|
433
|
+
try {
|
|
434
|
+
const url = getUrl(config, options);
|
|
435
|
+
const formData = getFormData(options);
|
|
436
|
+
const body = getRequestBody(options);
|
|
437
|
+
const headers = await getHeaders(config, options);
|
|
438
|
+
|
|
439
|
+
if (!onCancel.isCancelled) {
|
|
440
|
+
let response = await sendRequest<T>(config, options, url, body, formData, headers, onCancel, axiosClient);
|
|
441
|
+
|
|
442
|
+
for (const fn of config.interceptors.response._fns) {
|
|
443
|
+
response = await fn(response);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const responseBody = getResponseBody(response);
|
|
447
|
+
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
448
|
+
|
|
449
|
+
let transformedBody = responseBody;
|
|
450
|
+
if (options.responseTransformer && isSuccess(response.status)) {
|
|
451
|
+
transformedBody = await options.responseTransformer(responseBody)
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const result: ApiResult = {
|
|
455
|
+
url,
|
|
456
|
+
ok: isSuccess(response.status),
|
|
457
|
+
status: response.status,
|
|
458
|
+
statusText: response.statusText,
|
|
459
|
+
body: responseHeader ?? transformedBody,
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
catchErrorCodes(options, result);
|
|
463
|
+
|
|
464
|
+
resolve(`+(o(n,`ifServicesResponse`).call(a,`body`,{name:`ifServicesResponse`,hash:{},fn:e.program(5,i,0),inverse:e.program(7,i,0),data:i,loc:{start:{line:100,column:12},end:{line:100,column:90}}})??``)+`);
|
|
465
|
+
}
|
|
466
|
+
} catch (error) {
|
|
467
|
+
reject(error);
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
};`},usePartial:!0,useData:!0},Ve={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const sendRequest = async <T>(
|
|
471
|
+
config: OpenAPIConfig,
|
|
472
|
+
options: ApiRequestOptions<T>,
|
|
473
|
+
url: string,
|
|
474
|
+
body: unknown,
|
|
475
|
+
formData: FormData | undefined,
|
|
476
|
+
headers: Record<string, string>,
|
|
477
|
+
onCancel: OnCancel,
|
|
478
|
+
axiosClient: AxiosInstance
|
|
479
|
+
): Promise<AxiosResponse<T>> => {
|
|
480
|
+
const controller = new AbortController();
|
|
481
|
+
|
|
482
|
+
let requestConfig: AxiosRequestConfig = {
|
|
483
|
+
data: body ?? formData,
|
|
484
|
+
headers,
|
|
485
|
+
method: options.method,
|
|
486
|
+
signal: controller.signal,
|
|
487
|
+
url,
|
|
488
|
+
withCredentials: config.WITH_CREDENTIALS,
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
onCancel(() => controller.abort());
|
|
492
|
+
|
|
493
|
+
for (const fn of config.interceptors.request._fns) {
|
|
494
|
+
requestConfig = await fn(requestConfig);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
try {
|
|
498
|
+
return await axiosClient.request(requestConfig);
|
|
499
|
+
} catch (error) {
|
|
500
|
+
const axiosError = error as AxiosError<T>;
|
|
501
|
+
if (axiosError.response) {
|
|
502
|
+
return axiosError.response;
|
|
503
|
+
}
|
|
504
|
+
throw error;
|
|
505
|
+
}
|
|
506
|
+
};`},useData:!0},He={1:function(e,t,n,r,i){return`import type { HttpClient } from '@angular/common/http';
|
|
507
|
+
import type { Observable } from 'rxjs';
|
|
508
|
+
|
|
509
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
510
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
511
|
+
`},3:function(e,t,n,r,i){return`import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
512
|
+
import type { CancelablePromise } from './CancelablePromise';
|
|
513
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
514
|
+
`},5:function(e,t,n,r,i){return` constructor(
|
|
515
|
+
public readonly config: OpenAPIConfig,
|
|
516
|
+
public readonly http: HttpClient,
|
|
517
|
+
) {}
|
|
518
|
+
`},7:function(e,t,n,r,i){return` constructor(public readonly config: OpenAPIConfig) {}
|
|
519
|
+
`},9:function(e,t,n,r,i){return` public abstract request<T>(options: ApiRequestOptions<T>): Observable<T>;
|
|
520
|
+
`},11:function(e,t,n,r,i){return` public abstract request<T>(options: ApiRequestOptions<T>): CancelablePromise<T>;
|
|
521
|
+
`},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:1,column:0},end:{line:11,column:11}}})??``)+`
|
|
522
|
+
export abstract class BaseHttpRequest {
|
|
523
|
+
|
|
524
|
+
`+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(5,i,0),inverse:e.program(7,i,0),data:i,loc:{start:{line:15,column:1},end:{line:22,column:12}}})??``)+`
|
|
525
|
+
`+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(9,i,0),inverse:e.program(11,i,0),data:i,loc:{start:{line:24,column:1},end:{line:28,column:12}}})??``)+`}`},useData:!0},Ue={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export class CancelError extends Error {
|
|
526
|
+
constructor(message: string) {
|
|
527
|
+
super(message);
|
|
528
|
+
this.name = 'CancelError';
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
public get isCancelled(): boolean {
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
export interface OnCancel {
|
|
537
|
+
readonly isResolved: boolean;
|
|
538
|
+
readonly isRejected: boolean;
|
|
539
|
+
readonly isCancelled: boolean;
|
|
540
|
+
|
|
541
|
+
(cancelHandler: () => void): void;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export class CancelablePromise<T> implements Promise<T> {
|
|
545
|
+
private _isResolved: boolean;
|
|
546
|
+
private _isRejected: boolean;
|
|
547
|
+
private _isCancelled: boolean;
|
|
548
|
+
readonly cancelHandlers: (() => void)[];
|
|
549
|
+
readonly promise: Promise<T>;
|
|
550
|
+
private _resolve?: (value: T | PromiseLike<T>) => void;
|
|
551
|
+
private _reject?: (reason?: unknown) => void;
|
|
552
|
+
|
|
553
|
+
constructor(
|
|
554
|
+
executor: (
|
|
555
|
+
resolve: (value: T | PromiseLike<T>) => void,
|
|
556
|
+
reject: (reason?: unknown) => void,
|
|
557
|
+
onCancel: OnCancel
|
|
558
|
+
) => void
|
|
559
|
+
) {
|
|
560
|
+
this._isResolved = false;
|
|
561
|
+
this._isRejected = false;
|
|
562
|
+
this._isCancelled = false;
|
|
563
|
+
this.cancelHandlers = [];
|
|
564
|
+
this.promise = new Promise<T>((resolve, reject) => {
|
|
565
|
+
this._resolve = resolve;
|
|
566
|
+
this._reject = reject;
|
|
567
|
+
|
|
568
|
+
const onResolve = (value: T | PromiseLike<T>): void => {
|
|
569
|
+
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
this._isResolved = true;
|
|
573
|
+
if (this._resolve) this._resolve(value);
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
const onReject = (reason?: unknown): void => {
|
|
577
|
+
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
this._isRejected = true;
|
|
581
|
+
if (this._reject) this._reject(reason);
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
const onCancel = (cancelHandler: () => void): void => {
|
|
585
|
+
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
this.cancelHandlers.push(cancelHandler);
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
Object.defineProperty(onCancel, 'isResolved', {
|
|
592
|
+
get: (): boolean => this._isResolved,
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
Object.defineProperty(onCancel, 'isRejected', {
|
|
596
|
+
get: (): boolean => this._isRejected,
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
Object.defineProperty(onCancel, 'isCancelled', {
|
|
600
|
+
get: (): boolean => this._isCancelled,
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
return executor(onResolve, onReject, onCancel as OnCancel);
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
get [Symbol.toStringTag](): string {
|
|
608
|
+
return "Cancellable Promise";
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
public then<TResult1 = T, TResult2 = never>(
|
|
612
|
+
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
|
|
613
|
+
onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null
|
|
614
|
+
): Promise<TResult1 | TResult2> {
|
|
615
|
+
return this.promise.then(onFulfilled, onRejected);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
public catch<TResult = never>(
|
|
619
|
+
onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null
|
|
620
|
+
): Promise<T | TResult> {
|
|
621
|
+
return this.promise.catch(onRejected);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
public finally(onFinally?: (() => void) | null): Promise<T> {
|
|
625
|
+
return this.promise.finally(onFinally);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
public cancel(): void {
|
|
629
|
+
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
this._isCancelled = true;
|
|
633
|
+
if (this.cancelHandlers.length) {
|
|
634
|
+
try {
|
|
635
|
+
for (const cancelHandler of this.cancelHandlers) {
|
|
636
|
+
cancelHandler();
|
|
637
|
+
}
|
|
638
|
+
} catch (error) {
|
|
639
|
+
console.warn('Cancellation threw an error', error);
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
this.cancelHandlers.length = 0;
|
|
644
|
+
if (this._reject) this._reject(new CancelError('Request aborted'));
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
public get isCancelled(): boolean {
|
|
648
|
+
return this._isCancelled;
|
|
649
|
+
}
|
|
650
|
+
}`},useData:!0},We={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getHeaders = async <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): Promise<Headers> => {
|
|
651
|
+
const [token, username, password, additionalHeaders] = await Promise.all([
|
|
652
|
+
// @ts-ignore
|
|
653
|
+
resolve(options, config.TOKEN),
|
|
654
|
+
// @ts-ignore
|
|
655
|
+
resolve(options, config.USERNAME),
|
|
656
|
+
// @ts-ignore
|
|
657
|
+
resolve(options, config.PASSWORD),
|
|
658
|
+
// @ts-ignore
|
|
659
|
+
resolve(options, config.HEADERS),
|
|
660
|
+
]);
|
|
661
|
+
|
|
662
|
+
const headers = Object.entries({
|
|
663
|
+
Accept: 'application/json',
|
|
664
|
+
...additionalHeaders,
|
|
665
|
+
...options.headers,
|
|
666
|
+
})
|
|
667
|
+
.filter(([, value]) => value !== undefined && value !== null)
|
|
668
|
+
.reduce((headers, [key, value]) => ({
|
|
669
|
+
...headers,
|
|
670
|
+
[key]: String(value),
|
|
671
|
+
}), {} as Record<string, string>);
|
|
672
|
+
|
|
673
|
+
if (isStringWithValue(token)) {
|
|
674
|
+
headers['Authorization'] = \`Bearer \${token}\`;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
678
|
+
const credentials = base64(\`\${username}:\${password}\`);
|
|
679
|
+
headers['Authorization'] = \`Basic \${credentials}\`;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
if (options.body !== undefined) {
|
|
683
|
+
if (options.mediaType) {
|
|
684
|
+
headers['Content-Type'] = options.mediaType;
|
|
685
|
+
} else if (isBlob(options.body)) {
|
|
686
|
+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
|
687
|
+
} else if (isString(options.body)) {
|
|
688
|
+
headers['Content-Type'] = 'text/plain';
|
|
689
|
+
} else if (!isFormData(options.body)) {
|
|
690
|
+
headers['Content-Type'] = 'application/json';
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
return new Headers(headers);
|
|
695
|
+
};`},useData:!0},Ge={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getRequestBody = (options: ApiRequestOptions): unknown => {
|
|
696
|
+
if (options.body !== undefined) {
|
|
697
|
+
if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
|
|
698
|
+
return JSON.stringify(options.body);
|
|
699
|
+
} else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
|
|
700
|
+
return options.body;
|
|
701
|
+
} else {
|
|
702
|
+
return JSON.stringify(options.body);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return undefined;
|
|
706
|
+
};`},useData:!0},Ke={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseBody = async (response: Response): Promise<unknown> => {
|
|
707
|
+
if (response.status !== 204) {
|
|
708
|
+
try {
|
|
709
|
+
const contentType = response.headers.get('Content-Type');
|
|
710
|
+
if (contentType) {
|
|
711
|
+
const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/'];
|
|
712
|
+
if (contentType.includes('application/json') || contentType.includes('+json')) {
|
|
713
|
+
return await response.json();
|
|
714
|
+
} else if (binaryTypes.some(type => contentType.includes(type))) {
|
|
715
|
+
return await response.blob();
|
|
716
|
+
} else if (contentType.includes('multipart/form-data')) {
|
|
717
|
+
return await response.formData();
|
|
718
|
+
} else if (contentType.includes('text/')) {
|
|
719
|
+
return await response.text();
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
} catch (error) {
|
|
723
|
+
console.error(error);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return undefined;
|
|
727
|
+
};`},useData:!0},qe={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => {
|
|
728
|
+
if (responseHeader) {
|
|
729
|
+
const content = response.headers.get(responseHeader);
|
|
730
|
+
if (isString(content)) {
|
|
731
|
+
return content;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return undefined;
|
|
735
|
+
};`},useData:!0},Je={1:function(e,t,n,r,i){return`import fetch, { FormData, Headers } from 'node-fetch';
|
|
736
|
+
import type { RequestInit, Response } from 'node-fetch';
|
|
737
|
+
|
|
738
|
+
`},3:function(e,t,n,r,i){return`ApiResult<T>`},5:function(e,t,n,r,i){return`T`},7:function(e,t,n,r,i){return`result.body`},9:function(e,t,n,r,i){return`result`},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/node`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.noop,data:i,loc:{start:{line:1,column:0},end:{line:5,column:11}}})??``)+`import { ApiError } from './ApiError';
|
|
739
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
740
|
+
import type { ApiResult } from './ApiResult';
|
|
741
|
+
import { CancelablePromise } from './CancelablePromise';
|
|
742
|
+
import type { OnCancel } from './CancelablePromise';
|
|
743
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
744
|
+
|
|
745
|
+
`+(e.invokePartial(o(r,`functions/isString`),t,{name:`functions/isString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
746
|
+
|
|
747
|
+
`+(e.invokePartial(o(r,`functions/isStringWithValue`),t,{name:`functions/isStringWithValue`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
748
|
+
|
|
749
|
+
`+(e.invokePartial(o(r,`functions/isBlob`),t,{name:`functions/isBlob`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
750
|
+
|
|
751
|
+
`+(e.invokePartial(o(r,`functions/isFormData`),t,{name:`functions/isFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
752
|
+
|
|
753
|
+
`+(e.invokePartial(o(r,`functions/base64`),t,{name:`functions/base64`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
754
|
+
|
|
755
|
+
`+(e.invokePartial(o(r,`functions/getQueryString`),t,{name:`functions/getQueryString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
756
|
+
|
|
757
|
+
`+(e.invokePartial(o(r,`functions/getUrl`),t,{name:`functions/getUrl`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
758
|
+
|
|
759
|
+
`+(e.invokePartial(o(r,`functions/getFormData`),t,{name:`functions/getFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
760
|
+
|
|
761
|
+
`+(e.invokePartial(o(r,`functions/resolve`),t,{name:`functions/resolve`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
762
|
+
|
|
763
|
+
`+(e.invokePartial(o(r,`fetch/getHeaders`),t,{name:`fetch/getHeaders`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
764
|
+
|
|
765
|
+
`+(e.invokePartial(o(r,`fetch/getRequestBody`),t,{name:`fetch/getRequestBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
766
|
+
|
|
767
|
+
`+(e.invokePartial(o(r,`fetch/sendRequest`),t,{name:`fetch/sendRequest`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
768
|
+
|
|
769
|
+
`+(e.invokePartial(o(r,`fetch/getResponseHeader`),t,{name:`fetch/getResponseHeader`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
770
|
+
|
|
771
|
+
`+(e.invokePartial(o(r,`fetch/getResponseBody`),t,{name:`fetch/getResponseBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
772
|
+
|
|
773
|
+
`+(e.invokePartial(o(r,`functions/catchErrorCodes`),t,{name:`functions/catchErrorCodes`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Request method
|
|
777
|
+
* @param config The OpenAPI configuration object
|
|
778
|
+
* @param options The request options from the service
|
|
779
|
+
* @returns CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(3,i,0),inverse:e.program(5,i,0),data:i,loc:{start:{line:62,column:30},end:{line:62,column:108}}})??``)+`>
|
|
780
|
+
* @throws ApiError
|
|
781
|
+
*/
|
|
782
|
+
export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(3,i,0),inverse:e.program(5,i,0),data:i,loc:{start:{line:65,column:100},end:{line:65,column:178}}})??``)+`> => {
|
|
783
|
+
return new CancelablePromise(async (resolve, reject, onCancel) => {
|
|
784
|
+
try {
|
|
785
|
+
const url = getUrl(config, options);
|
|
786
|
+
const formData = getFormData(options);
|
|
787
|
+
const body = getRequestBody(options);
|
|
788
|
+
const headers = await getHeaders(config, options);
|
|
789
|
+
|
|
790
|
+
if (!onCancel.isCancelled) {
|
|
791
|
+
let response = await sendRequest(config, options, url, body, formData, headers, onCancel);
|
|
792
|
+
|
|
793
|
+
for (const fn of config.interceptors.response._fns) {
|
|
794
|
+
response = await fn(response);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
const responseBody = await getResponseBody(response);
|
|
798
|
+
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
799
|
+
|
|
800
|
+
let transformedBody = responseBody;
|
|
801
|
+
if (options.responseTransformer && response.ok) {
|
|
802
|
+
transformedBody = await options.responseTransformer(responseBody)
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
const result: ApiResult = {
|
|
806
|
+
url,
|
|
807
|
+
ok: response.ok,
|
|
808
|
+
status: response.status,
|
|
809
|
+
statusText: response.statusText,
|
|
810
|
+
body: responseHeader ?? transformedBody,
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
catchErrorCodes(options, result);
|
|
814
|
+
|
|
815
|
+
resolve(`+(o(n,`ifServicesResponse`).call(a,`body`,{name:`ifServicesResponse`,hash:{},fn:e.program(7,i,0),inverse:e.program(9,i,0),data:i,loc:{start:{line:98,column:12},end:{line:98,column:90}}})??``)+`);
|
|
816
|
+
}
|
|
817
|
+
} catch (error) {
|
|
818
|
+
reject(error);
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
};`},usePartial:!0,useData:!0},Ye={1:function(e,t,n,r,i){return` if (config.WITH_CREDENTIALS) {
|
|
822
|
+
request.credentials = config.CREDENTIALS;
|
|
823
|
+
}
|
|
824
|
+
`},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`export const sendRequest = async (
|
|
825
|
+
config: OpenAPIConfig,
|
|
826
|
+
options: ApiRequestOptions,
|
|
827
|
+
url: string,
|
|
828
|
+
body: any,
|
|
829
|
+
formData: FormData | undefined,
|
|
830
|
+
headers: Headers,
|
|
831
|
+
onCancel: OnCancel
|
|
832
|
+
): Promise<Response> => {
|
|
833
|
+
const controller = new AbortController();
|
|
834
|
+
|
|
835
|
+
let request: RequestInit = {
|
|
836
|
+
headers,
|
|
837
|
+
body: body ?? formData,
|
|
838
|
+
method: options.method,
|
|
839
|
+
signal: controller.signal,
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
`+(a(n,`equals`).call(t??(e.nullContext||{}),a(a(a(a(i,`root`),`$config`),`client`),`name`),`legacy/fetch`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.noop,data:i,loc:{start:{line:19,column:1},end:{line:23,column:12}}})??``)+`
|
|
843
|
+
for (const fn of config.interceptors.request._fns) {
|
|
844
|
+
request = await fn(request);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
onCancel(() => controller.abort());
|
|
848
|
+
|
|
849
|
+
return await fetch(url, request);
|
|
850
|
+
};`},useData:!0},Xe={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const base64 = (str: string): string => {
|
|
851
|
+
try {
|
|
852
|
+
return btoa(str);
|
|
853
|
+
} catch (err) {
|
|
854
|
+
// @ts-ignore
|
|
855
|
+
return Buffer.from(str).toString('base64');
|
|
856
|
+
}
|
|
857
|
+
};`},useData:!0},Ze={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
|
|
858
|
+
const errors: Record<number, string> = {
|
|
859
|
+
400: 'Bad Request',
|
|
860
|
+
401: 'Unauthorized',
|
|
861
|
+
402: 'Payment Required',
|
|
862
|
+
403: 'Forbidden',
|
|
863
|
+
404: 'Not Found',
|
|
864
|
+
405: 'Method Not Allowed',
|
|
865
|
+
406: 'Not Acceptable',
|
|
866
|
+
407: 'Proxy Authentication Required',
|
|
867
|
+
408: 'Request Timeout',
|
|
868
|
+
409: 'Conflict',
|
|
869
|
+
410: 'Gone',
|
|
870
|
+
411: 'Length Required',
|
|
871
|
+
412: 'Precondition Failed',
|
|
872
|
+
413: 'Payload Too Large',
|
|
873
|
+
414: 'URI Too Long',
|
|
874
|
+
415: 'Unsupported Media Type',
|
|
875
|
+
416: 'Range Not Satisfiable',
|
|
876
|
+
417: 'Expectation Failed',
|
|
877
|
+
418: 'Im a teapot',
|
|
878
|
+
421: 'Misdirected Request',
|
|
879
|
+
422: 'Unprocessable Content',
|
|
880
|
+
423: 'Locked',
|
|
881
|
+
424: 'Failed Dependency',
|
|
882
|
+
425: 'Too Early',
|
|
883
|
+
426: 'Upgrade Required',
|
|
884
|
+
428: 'Precondition Required',
|
|
885
|
+
429: 'Too Many Requests',
|
|
886
|
+
431: 'Request Header Fields Too Large',
|
|
887
|
+
451: 'Unavailable For Legal Reasons',
|
|
888
|
+
500: 'Internal Server Error',
|
|
889
|
+
501: 'Not Implemented',
|
|
890
|
+
502: 'Bad Gateway',
|
|
891
|
+
503: 'Service Unavailable',
|
|
892
|
+
504: 'Gateway Timeout',
|
|
893
|
+
505: 'HTTP Version Not Supported',
|
|
894
|
+
506: 'Variant Also Negotiates',
|
|
895
|
+
507: 'Insufficient Storage',
|
|
896
|
+
508: 'Loop Detected',
|
|
897
|
+
510: 'Not Extended',
|
|
898
|
+
511: 'Network Authentication Required',
|
|
899
|
+
...options.errors,
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
const error = errors[result.status];
|
|
903
|
+
if (error) {
|
|
904
|
+
throw new ApiError(options, result, error);
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
if (!result.ok) {
|
|
908
|
+
const errorStatus = result.status ?? 'unknown';
|
|
909
|
+
const errorStatusText = result.statusText ?? 'unknown';
|
|
910
|
+
const errorBody = (() => {
|
|
911
|
+
try {
|
|
912
|
+
return JSON.stringify(result.body, null, 2);
|
|
913
|
+
} catch (e) {
|
|
914
|
+
return undefined;
|
|
915
|
+
}
|
|
916
|
+
})();
|
|
917
|
+
|
|
918
|
+
throw new ApiError(options, result,
|
|
919
|
+
\`Generic Error: status: \${errorStatus}; status text: \${errorStatusText}; body: \${errorBody}\`
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
};`},useData:!0},Qe={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getFormData = (options: ApiRequestOptions): FormData | undefined => {
|
|
923
|
+
if (options.formData) {
|
|
924
|
+
const formData = new FormData();
|
|
925
|
+
|
|
926
|
+
const process = (key: string, value: unknown) => {
|
|
927
|
+
if (isString(value) || isBlob(value)) {
|
|
928
|
+
formData.append(key, value);
|
|
929
|
+
} else {
|
|
930
|
+
formData.append(key, JSON.stringify(value));
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
Object.entries(options.formData)
|
|
935
|
+
.filter(([, value]) => value !== undefined && value !== null)
|
|
936
|
+
.forEach(([key, value]) => {
|
|
937
|
+
if (Array.isArray(value)) {
|
|
938
|
+
value.forEach(v => process(key, v));
|
|
939
|
+
} else {
|
|
940
|
+
process(key, value);
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
return formData;
|
|
945
|
+
}
|
|
946
|
+
return undefined;
|
|
947
|
+
};`},useData:!0},$e={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getQueryString = (params: Record<string, unknown>): string => {
|
|
948
|
+
const qs: string[] = [];
|
|
949
|
+
|
|
950
|
+
const append = (key: string, value: unknown) => {
|
|
951
|
+
qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`);
|
|
952
|
+
};
|
|
953
|
+
|
|
954
|
+
const encodePair = (key: string, value: unknown) => {
|
|
955
|
+
if (value === undefined || value === null) {
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
if (value instanceof Date) {
|
|
960
|
+
append(key, value.toISOString());
|
|
961
|
+
} else if (Array.isArray(value)) {
|
|
962
|
+
value.forEach(v => encodePair(key, v));
|
|
963
|
+
} else if (typeof value === 'object') {
|
|
964
|
+
Object.entries(value).forEach(([k, v]) => encodePair(\`\${key}[\${k}]\`, v));
|
|
965
|
+
} else {
|
|
966
|
+
append(key, value);
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
|
|
970
|
+
Object.entries(params).forEach(([key, value]) => encodePair(key, value));
|
|
971
|
+
|
|
972
|
+
return qs.length ? \`?\${qs.join('&')}\` : '';
|
|
973
|
+
};`},useData:!0},et={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
|
|
974
|
+
const encoder = config.ENCODE_PATH || encodeURI;
|
|
975
|
+
|
|
976
|
+
const path = options.url
|
|
977
|
+
.replace('{api-version}', config.VERSION)
|
|
978
|
+
.replace(/{(.*?)}/g, (substring: string, group: string) => {
|
|
979
|
+
if (options.path?.hasOwnProperty(group)) {
|
|
980
|
+
return encoder(String(options.path[group]));
|
|
981
|
+
}
|
|
982
|
+
return substring;
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
const url = config.BASE + path;
|
|
986
|
+
return options.query ? url + getQueryString(options.query) : url;
|
|
987
|
+
};`},useData:!0},tt={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const isBlob = (value: any): value is Blob => {
|
|
988
|
+
return value instanceof Blob;
|
|
989
|
+
};`},useData:!0},nt={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const isFormData = (value: unknown): value is FormData => {
|
|
990
|
+
return value instanceof FormData;
|
|
991
|
+
};`},useData:!0},rt={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const isString = (value: unknown): value is string => {
|
|
992
|
+
return typeof value === 'string';
|
|
993
|
+
};`},useData:!0},it={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const isStringWithValue = (value: unknown): value is string => {
|
|
994
|
+
return isString(value) && value !== '';
|
|
995
|
+
};`},useData:!0},at={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const isSuccess = (status: number): boolean => {
|
|
996
|
+
return status >= 200 && status < 300;
|
|
997
|
+
};`},useData:!0},ot={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>;
|
|
998
|
+
|
|
999
|
+
export const resolve = async <T>(options: ApiRequestOptions<T>, resolver?: T | Resolver<T>): Promise<T | undefined> => {
|
|
1000
|
+
if (typeof resolver === 'function') {
|
|
1001
|
+
return (resolver as Resolver<T>)(options);
|
|
1002
|
+
}
|
|
1003
|
+
return resolver;
|
|
1004
|
+
};`},useData:!0},st={1:function(e,t,n,r,i){return`import { Inject, Injectable } from '@angular/core';
|
|
1005
|
+
import { HttpClient } from '@angular/common/http';
|
|
1006
|
+
import type { Observable } from 'rxjs';
|
|
1007
|
+
|
|
1008
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
1009
|
+
import { BaseHttpRequest } from './BaseHttpRequest';
|
|
1010
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
1011
|
+
import { OpenAPI } from './OpenAPI';
|
|
1012
|
+
import { request as __request } from './request';
|
|
1013
|
+
`},3:function(e,t,n,r,i){return`import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
1014
|
+
import { BaseHttpRequest } from './BaseHttpRequest';
|
|
1015
|
+
import type { CancelablePromise } from './CancelablePromise';
|
|
1016
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
1017
|
+
import { request as __request } from './request';
|
|
1018
|
+
`},5:function(e,t,n,r,i){return`@Injectable()
|
|
1019
|
+
`},7:function(e,t,n,r,i){return` constructor(
|
|
1020
|
+
@Inject(OpenAPI)
|
|
1021
|
+
config: OpenAPIConfig,
|
|
1022
|
+
http: HttpClient,
|
|
1023
|
+
) {
|
|
1024
|
+
super(config, http);
|
|
1025
|
+
}
|
|
1026
|
+
`},9:function(e,t,n,r,i){return` constructor(config: OpenAPIConfig) {
|
|
1027
|
+
super(config);
|
|
1028
|
+
}
|
|
1029
|
+
`},11:function(e,t,n,r,i){return` /**
|
|
1030
|
+
* Request method
|
|
1031
|
+
* @param options The request options from the service
|
|
1032
|
+
* @returns Observable<T>
|
|
1033
|
+
* @throws ApiError
|
|
1034
|
+
*/
|
|
1035
|
+
public override request<T>(options: ApiRequestOptions<T>): Observable<T> {
|
|
1036
|
+
return __request(this.config, this.http, options);
|
|
1037
|
+
}
|
|
1038
|
+
`},13:function(e,t,n,r,i){return` /**
|
|
1039
|
+
* Request method
|
|
1040
|
+
* @param options The request options from the service
|
|
1041
|
+
* @returns CancelablePromise<T>
|
|
1042
|
+
* @throws ApiError
|
|
1043
|
+
*/
|
|
1044
|
+
public override request<T>(options: ApiRequestOptions<T>): CancelablePromise<T> {
|
|
1045
|
+
return __request(this.config, options);
|
|
1046
|
+
}
|
|
1047
|
+
`},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:1,column:0},end:{line:17,column:11}}})??``)+`
|
|
1048
|
+
`+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(5,i,0),inverse:e.noop,data:i,loc:{start:{line:19,column:0},end:{line:21,column:11}}})??``)+`export class `+(e.lambda(e.strict(t,`httpRequest`,{start:{line:22,column:15},end:{line:22,column:26}}),t)??``)+` extends BaseHttpRequest {
|
|
1049
|
+
|
|
1050
|
+
`+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(7,i,0),inverse:e.program(9,i,0),data:i,loc:{start:{line:24,column:1},end:{line:36,column:12}}})??``)+`
|
|
1051
|
+
`+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(11,i,0),inverse:e.program(13,i,0),data:i,loc:{start:{line:38,column:1},end:{line:58,column:12}}})??``)+`}`},useData:!0},ct={1:function(e,t,n,r,i){return`import type { HttpResponse } from '@angular/common/http';
|
|
1052
|
+
`},3:function(e,t,n,r,i){return`import type { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
1053
|
+
`},5:function(e,t,n,r,i){return`import type { RequestInit, Response } from 'node-fetch';
|
|
1054
|
+
`},7:function(e,t,n,r,i){return` response: Interceptors<HttpResponse<any>>;
|
|
1055
|
+
`},9:function(e,t,n,r,i){return` request: Interceptors<AxiosRequestConfig>;
|
|
1056
|
+
response: Interceptors<AxiosResponse>;
|
|
1057
|
+
`},11:function(e,t,n,r,i){return` request: Interceptors<RequestInit>;
|
|
1058
|
+
response: Interceptors<Response>;
|
|
1059
|
+
`},13:function(e,t,n,r,i){return` request: Interceptors<XMLHttpRequest>;
|
|
1060
|
+
response: Interceptors<XMLHttpRequest>;
|
|
1061
|
+
`},15:function(e,t,n,r,i){return` request: new Interceptors(),
|
|
1062
|
+
`},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.strict,s=e.lambda,c=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.noop,data:i,loc:{start:{line:1,column:0},end:{line:3,column:11}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/axios`,{name:`equals`,hash:{},fn:e.program(3,i,0),inverse:e.noop,data:i,loc:{start:{line:4,column:0},end:{line:6,column:11}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/node`,{name:`equals`,hash:{},fn:e.program(5,i,0),inverse:e.noop,data:i,loc:{start:{line:7,column:0},end:{line:9,column:11}}})??``)+`import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
1063
|
+
|
|
1064
|
+
type Headers = Record<string, string>;
|
|
1065
|
+
type Middleware<T> = (value: T) => T | Promise<T>;
|
|
1066
|
+
type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>;
|
|
1067
|
+
|
|
1068
|
+
export class Interceptors<T> {
|
|
1069
|
+
_fns: Middleware<T>[];
|
|
1070
|
+
|
|
1071
|
+
constructor() {
|
|
1072
|
+
this._fns = [];
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
eject(fn: Middleware<T>): void {
|
|
1076
|
+
const index = this._fns.indexOf(fn);
|
|
1077
|
+
if (index !== -1) {
|
|
1078
|
+
this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)];
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
use(fn: Middleware<T>): void {
|
|
1083
|
+
this._fns = [...this._fns, fn];
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
export type OpenAPIConfig = {
|
|
1088
|
+
BASE: string;
|
|
1089
|
+
CREDENTIALS: 'include' | 'omit' | 'same-origin';
|
|
1090
|
+
ENCODE_PATH?: ((path: string) => string) | undefined;
|
|
1091
|
+
HEADERS?: Headers | Resolver<Headers> | undefined;
|
|
1092
|
+
PASSWORD?: string | Resolver<string> | undefined;
|
|
1093
|
+
TOKEN?: string | Resolver<string> | undefined;
|
|
1094
|
+
USERNAME?: string | Resolver<string> | undefined;
|
|
1095
|
+
VERSION: string;
|
|
1096
|
+
WITH_CREDENTIALS: boolean;
|
|
1097
|
+
interceptors: {
|
|
1098
|
+
`+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(7,i,0),inverse:e.noop,data:i,loc:{start:{line:46,column:2},end:{line:48,column:13}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/axios`,{name:`equals`,hash:{},fn:e.program(9,i,0),inverse:e.noop,data:i,loc:{start:{line:49,column:2},end:{line:52,column:13}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/fetch`,{name:`equals`,hash:{},fn:e.program(11,i,0),inverse:e.noop,data:i,loc:{start:{line:53,column:2},end:{line:56,column:13}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/node`,{name:`equals`,hash:{},fn:e.program(11,i,0),inverse:e.noop,data:i,loc:{start:{line:57,column:2},end:{line:60,column:13}}})??``)+(c(n,`equals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/xhr`,{name:`equals`,hash:{},fn:e.program(13,i,0),inverse:e.noop,data:i,loc:{start:{line:61,column:2},end:{line:64,column:13}}})??``)+` };
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
export const OpenAPI: OpenAPIConfig = {
|
|
1102
|
+
BASE: '`+(s(o(t,`server`,{start:{line:69,column:11},end:{line:69,column:17}}),t)??``)+`',
|
|
1103
|
+
CREDENTIALS: 'include',
|
|
1104
|
+
ENCODE_PATH: undefined,
|
|
1105
|
+
HEADERS: undefined,
|
|
1106
|
+
PASSWORD: undefined,
|
|
1107
|
+
TOKEN: undefined,
|
|
1108
|
+
USERNAME: undefined,
|
|
1109
|
+
VERSION: '`+(s(o(t,`version`,{start:{line:76,column:14},end:{line:76,column:21}}),t)??``)+`',
|
|
1110
|
+
WITH_CREDENTIALS: false,
|
|
1111
|
+
interceptors: {
|
|
1112
|
+
`+(c(n,`notEquals`).call(a,c(c(c(c(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`notEquals`,hash:{},fn:e.program(15,i,0),inverse:e.noop,data:i,loc:{start:{line:79,column:2},end:{line:81,column:16}}})??``)+` response: new Interceptors(),
|
|
1113
|
+
},
|
|
1114
|
+
};`},useData:!0},lt={1:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return e.invokePartial(a(r,`angular/request`),t,{name:`angular/request`,data:i,helpers:n,partials:r,decorators:e.decorators})??``},3:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return e.invokePartial(a(r,`axios/request`),t,{name:`axios/request`,data:i,helpers:n,partials:r,decorators:e.decorators})??``},5:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return e.invokePartial(a(r,`fetch/request`),t,{name:`fetch/request`,data:i,helpers:n,partials:r,decorators:e.decorators})??``},7:function(e,t,n,r,i){var a=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return e.invokePartial(a(r,`xhr/request`),t,{name:`xhr/request`,data:i,helpers:n,partials:r,decorators:e.decorators})??``},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/angular`,{name:`equals`,hash:{},fn:e.program(1,i,0),inverse:e.noop,data:i,loc:{start:{line:1,column:0},end:{line:1,column:87}}})??``)+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/axios`,{name:`equals`,hash:{},fn:e.program(3,i,0),inverse:e.noop,data:i,loc:{start:{line:2,column:0},end:{line:2,column:83}}})??``)+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/fetch`,{name:`equals`,hash:{},fn:e.program(5,i,0),inverse:e.noop,data:i,loc:{start:{line:3,column:0},end:{line:3,column:83}}})??``)+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/node`,{name:`equals`,hash:{},fn:e.program(5,i,0),inverse:e.noop,data:i,loc:{start:{line:4,column:0},end:{line:4,column:82}}})??``)+(o(n,`equals`).call(a,o(o(o(o(i,`root`),`$config`),`client`),`name`),`legacy/xhr`,{name:`equals`,hash:{},fn:e.program(7,i,0),inverse:e.noop,data:i,loc:{start:{line:5,column:0},end:{line:5,column:79}}})??``)},usePartial:!0,useData:!0},ut={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getHeaders = async <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): Promise<Headers> => {
|
|
1115
|
+
const [token, username, password, additionalHeaders] = await Promise.all([
|
|
1116
|
+
// @ts-ignore
|
|
1117
|
+
resolve(options, config.TOKEN),
|
|
1118
|
+
// @ts-ignore
|
|
1119
|
+
resolve(options, config.USERNAME),
|
|
1120
|
+
// @ts-ignore
|
|
1121
|
+
resolve(options, config.PASSWORD),
|
|
1122
|
+
// @ts-ignore
|
|
1123
|
+
resolve(options, config.HEADERS),
|
|
1124
|
+
]);
|
|
1125
|
+
|
|
1126
|
+
const headers = Object.entries({
|
|
1127
|
+
Accept: 'application/json',
|
|
1128
|
+
...additionalHeaders,
|
|
1129
|
+
...options.headers,
|
|
1130
|
+
})
|
|
1131
|
+
.filter(([, value]) => value !== undefined && value !== null)
|
|
1132
|
+
.reduce((headers, [key, value]) => ({
|
|
1133
|
+
...headers,
|
|
1134
|
+
[key]: String(value),
|
|
1135
|
+
}), {} as Record<string, string>);
|
|
1136
|
+
|
|
1137
|
+
if (isStringWithValue(token)) {
|
|
1138
|
+
headers['Authorization'] = \`Bearer \${token}\`;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
1142
|
+
const credentials = base64(\`\${username}:\${password}\`);
|
|
1143
|
+
headers['Authorization'] = \`Basic \${credentials}\`;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
if (options.body !== undefined) {
|
|
1147
|
+
if (options.mediaType) {
|
|
1148
|
+
headers['Content-Type'] = options.mediaType;
|
|
1149
|
+
} else if (isBlob(options.body)) {
|
|
1150
|
+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
|
1151
|
+
} else if (isString(options.body)) {
|
|
1152
|
+
headers['Content-Type'] = 'text/plain';
|
|
1153
|
+
} else if (!isFormData(options.body)) {
|
|
1154
|
+
headers['Content-Type'] = 'application/json';
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
return new Headers(headers);
|
|
1159
|
+
};`},useData:!0},dt={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getRequestBody = (options: ApiRequestOptions): unknown => {
|
|
1160
|
+
if (options.body !== undefined) {
|
|
1161
|
+
if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
|
|
1162
|
+
return JSON.stringify(options.body);
|
|
1163
|
+
} else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
|
|
1164
|
+
return options.body;
|
|
1165
|
+
} else {
|
|
1166
|
+
return JSON.stringify(options.body);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
return undefined;
|
|
1170
|
+
};`},useData:!0},ft={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseBody = (xhr: XMLHttpRequest): unknown => {
|
|
1171
|
+
if (xhr.status !== 204) {
|
|
1172
|
+
try {
|
|
1173
|
+
const contentType = xhr.getResponseHeader('Content-Type');
|
|
1174
|
+
if (contentType) {
|
|
1175
|
+
if (contentType.includes('application/json') || contentType.includes('+json')) {
|
|
1176
|
+
return JSON.parse(xhr.responseText);
|
|
1177
|
+
} else {
|
|
1178
|
+
return xhr.responseText;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
} catch (error) {
|
|
1182
|
+
console.error(error);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
return undefined;
|
|
1186
|
+
};`},useData:!0},pt={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const getResponseHeader = (xhr: XMLHttpRequest, responseHeader?: string): string | undefined => {
|
|
1187
|
+
if (responseHeader) {
|
|
1188
|
+
const content = xhr.getResponseHeader(responseHeader);
|
|
1189
|
+
if (isString(content)) {
|
|
1190
|
+
return content;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
return undefined;
|
|
1194
|
+
};`},useData:!0},mt={1:function(e,t,n,r,i){return`ApiResult<T>`},3:function(e,t,n,r,i){return`T`},5:function(e,t,n,r,i){return`result.body`},7:function(e,t,n,r,i){return`result`},compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){var a=t??(e.nullContext||{}),o=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return`import { ApiError } from './ApiError';
|
|
1195
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
1196
|
+
import type { ApiResult } from './ApiResult';
|
|
1197
|
+
import { CancelablePromise } from './CancelablePromise';
|
|
1198
|
+
import type { OnCancel } from './CancelablePromise';
|
|
1199
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
1200
|
+
|
|
1201
|
+
`+(e.invokePartial(o(r,`functions/isString`),t,{name:`functions/isString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1202
|
+
|
|
1203
|
+
`+(e.invokePartial(o(r,`functions/isStringWithValue`),t,{name:`functions/isStringWithValue`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1204
|
+
|
|
1205
|
+
`+(e.invokePartial(o(r,`functions/isBlob`),t,{name:`functions/isBlob`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1206
|
+
|
|
1207
|
+
`+(e.invokePartial(o(r,`functions/isFormData`),t,{name:`functions/isFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1208
|
+
|
|
1209
|
+
`+(e.invokePartial(o(r,`functions/isSuccess`),t,{name:`functions/isSuccess`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1210
|
+
|
|
1211
|
+
`+(e.invokePartial(o(r,`functions/base64`),t,{name:`functions/base64`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1212
|
+
|
|
1213
|
+
`+(e.invokePartial(o(r,`functions/getQueryString`),t,{name:`functions/getQueryString`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1214
|
+
|
|
1215
|
+
`+(e.invokePartial(o(r,`functions/getUrl`),t,{name:`functions/getUrl`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1216
|
+
|
|
1217
|
+
`+(e.invokePartial(o(r,`functions/getFormData`),t,{name:`functions/getFormData`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1218
|
+
|
|
1219
|
+
`+(e.invokePartial(o(r,`functions/resolve`),t,{name:`functions/resolve`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1220
|
+
|
|
1221
|
+
`+(e.invokePartial(o(r,`fetch/getHeaders`),t,{name:`fetch/getHeaders`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1222
|
+
|
|
1223
|
+
`+(e.invokePartial(o(r,`xhr/getRequestBody`),t,{name:`xhr/getRequestBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1224
|
+
|
|
1225
|
+
`+(e.invokePartial(o(r,`xhr/sendRequest`),t,{name:`xhr/sendRequest`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1226
|
+
|
|
1227
|
+
`+(e.invokePartial(o(r,`xhr/getResponseHeader`),t,{name:`xhr/getResponseHeader`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1228
|
+
|
|
1229
|
+
`+(e.invokePartial(o(r,`xhr/getResponseBody`),t,{name:`xhr/getResponseBody`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1230
|
+
|
|
1231
|
+
`+(e.invokePartial(o(r,`functions/catchErrorCodes`),t,{name:`functions/catchErrorCodes`,data:i,helpers:n,partials:r,decorators:e.decorators})??``)+`
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* Request method
|
|
1235
|
+
* @param config The OpenAPI configuration object
|
|
1236
|
+
* @param options The request options from the service
|
|
1237
|
+
* @returns CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:60,column:30},end:{line:60,column:108}}})??``)+`>
|
|
1238
|
+
* @throws ApiError
|
|
1239
|
+
*/
|
|
1240
|
+
export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): CancelablePromise<`+(o(n,`ifServicesResponse`).call(a,`response`,{name:`ifServicesResponse`,hash:{},fn:e.program(1,i,0),inverse:e.program(3,i,0),data:i,loc:{start:{line:63,column:100},end:{line:63,column:178}}})??``)+`> => {
|
|
1241
|
+
return new CancelablePromise(async (resolve, reject, onCancel) => {
|
|
1242
|
+
try {
|
|
1243
|
+
const url = getUrl(config, options);
|
|
1244
|
+
const formData = getFormData(options);
|
|
1245
|
+
const body = getRequestBody(options);
|
|
1246
|
+
const headers = await getHeaders(config, options);
|
|
1247
|
+
|
|
1248
|
+
if (!onCancel.isCancelled) {
|
|
1249
|
+
let response = await sendRequest(config, options, url, body, formData, headers, onCancel);
|
|
1250
|
+
|
|
1251
|
+
for (const fn of config.interceptors.response._fns) {
|
|
1252
|
+
response = await fn(response);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
const responseBody = getResponseBody(response);
|
|
1256
|
+
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
1257
|
+
|
|
1258
|
+
let transformedBody = responseBody;
|
|
1259
|
+
if (options.responseTransformer && isSuccess(response.status)) {
|
|
1260
|
+
transformedBody = await options.responseTransformer(responseBody)
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
const result: ApiResult = {
|
|
1264
|
+
url,
|
|
1265
|
+
ok: isSuccess(response.status),
|
|
1266
|
+
status: response.status,
|
|
1267
|
+
statusText: response.statusText,
|
|
1268
|
+
body: responseHeader ?? transformedBody,
|
|
1269
|
+
};
|
|
1270
|
+
|
|
1271
|
+
catchErrorCodes(options, result);
|
|
1272
|
+
|
|
1273
|
+
resolve(`+(o(n,`ifServicesResponse`).call(a,`body`,{name:`ifServicesResponse`,hash:{},fn:e.program(5,i,0),inverse:e.program(7,i,0),data:i,loc:{start:{line:96,column:12},end:{line:96,column:90}}})??``)+`);
|
|
1274
|
+
}
|
|
1275
|
+
} catch (error) {
|
|
1276
|
+
reject(error);
|
|
1277
|
+
}
|
|
1278
|
+
});
|
|
1279
|
+
};`},usePartial:!0,useData:!0},ht={compiler:[8,`>= 4.3.0`],main:function(e,t,n,r,i){return`export const sendRequest = async (
|
|
1280
|
+
config: OpenAPIConfig,
|
|
1281
|
+
options: ApiRequestOptions,
|
|
1282
|
+
url: string,
|
|
1283
|
+
body: any,
|
|
1284
|
+
formData: FormData | undefined,
|
|
1285
|
+
headers: Headers,
|
|
1286
|
+
onCancel: OnCancel
|
|
1287
|
+
): Promise<XMLHttpRequest> => {
|
|
1288
|
+
let xhr = new XMLHttpRequest();
|
|
1289
|
+
xhr.open(options.method, url, true);
|
|
1290
|
+
xhr.withCredentials = config.WITH_CREDENTIALS;
|
|
1291
|
+
|
|
1292
|
+
headers.forEach((value, key) => {
|
|
1293
|
+
xhr.setRequestHeader(key, value);
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1296
|
+
return new Promise<XMLHttpRequest>(async (resolve, reject) => {
|
|
1297
|
+
xhr.onload = () => resolve(xhr);
|
|
1298
|
+
xhr.onabort = () => reject(new Error('Request aborted'));
|
|
1299
|
+
xhr.onerror = () => reject(new Error('Network error'));
|
|
1300
|
+
|
|
1301
|
+
for (const fn of config.interceptors.request._fns) {
|
|
1302
|
+
xhr = await fn(xhr);
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
xhr.send(body ?? formData);
|
|
1306
|
+
|
|
1307
|
+
onCancel(() => xhr.abort());
|
|
1308
|
+
});
|
|
1309
|
+
};`},useData:!0};const gt=()=>{k.registerHelper(`camelCase`,function(e){return T({case:`camelCase`,value:e})}),k.registerHelper(`equals`,function(e,t,n){return e===t?n.fn(this):n.inverse(this)}),k.registerHelper(`ifServicesResponse`,function(e,t){return i().plugins[`@hey-api/sdk`]?.config.response===e?t.fn(this):t.inverse(this)}),k.registerHelper(`ifdef`,function(...e){let t=e.pop();return e.every(e=>!e)?t.inverse(this):t.fn(this)}),k.registerHelper(`notEquals`,function(e,t,n){return e===t?n.inverse(this):n.fn(this)}),k.registerHelper(`transformServiceName`,function(e){return ne({config:i(),name:e})})},_t=()=>{gt();let e={client:k.template(Ee),core:{apiError:k.template(Ne),apiRequestOptions:k.template(Pe),apiResult:k.template(Fe),baseHttpRequest:k.template(He),cancelablePromise:k.template(Ue),httpRequest:k.template(st),request:k.template(lt),settings:k.template(ct)}};return k.registerPartial(`functions/base64`,k.template(Xe)),k.registerPartial(`functions/catchErrorCodes`,k.template(Ze)),k.registerPartial(`functions/getFormData`,k.template(Qe)),k.registerPartial(`functions/getQueryString`,k.template($e)),k.registerPartial(`functions/getUrl`,k.template(et)),k.registerPartial(`functions/isBlob`,k.template(tt)),k.registerPartial(`functions/isFormData`,k.template(nt)),k.registerPartial(`functions/isString`,k.template(rt)),k.registerPartial(`functions/isStringWithValue`,k.template(it)),k.registerPartial(`functions/isSuccess`,k.template(at)),k.registerPartial(`functions/resolve`,k.template(ot)),k.registerPartial(`fetch/getHeaders`,k.template(We)),k.registerPartial(`fetch/getRequestBody`,k.template(Ge)),k.registerPartial(`fetch/getResponseBody`,k.template(Ke)),k.registerPartial(`fetch/getResponseHeader`,k.template(qe)),k.registerPartial(`fetch/request`,k.template(Je)),k.registerPartial(`fetch/sendRequest`,k.template(Ye)),k.registerPartial(`xhr/getHeaders`,k.template(ut)),k.registerPartial(`xhr/getRequestBody`,k.template(dt)),k.registerPartial(`xhr/getResponseBody`,k.template(ft)),k.registerPartial(`xhr/getResponseHeader`,k.template(pt)),k.registerPartial(`xhr/request`,k.template(mt)),k.registerPartial(`xhr/sendRequest`,k.template(ht)),k.registerPartial(`axios/getHeaders`,k.template(Ie)),k.registerPartial(`axios/getRequestBody`,k.template(Le)),k.registerPartial(`axios/getResponseBody`,k.template(Re)),k.registerPartial(`axios/getResponseHeader`,k.template(ze)),k.registerPartial(`axios/request`,k.template(Be)),k.registerPartial(`axios/sendRequest`,k.template(Ve)),k.registerPartial(`angular/getHeaders`,k.template(De)),k.registerPartial(`angular/getRequestBody`,k.template(Oe)),k.registerPartial(`angular/getResponseBody`,k.template(ke)),k.registerPartial(`angular/getResponseHeader`,k.template(Ae)),k.registerPartial(`angular/request`,k.template(je)),k.registerPartial(`angular/sendRequest`,k.template(Me)),e};let J=0;const Y=e=>`${e}-${J++}`,X=e=>`${e}-end`,Z=e=>`${e}-length`,Q=e=>`${e}-start`,vt=(e,t)=>{if(e>200)return{color:E.red,type:`duration`};if(t>30)return{color:E.red,type:`percentage`};if(e>50)return{color:E.yellow,type:`duration`};if(t>10)return{color:E.yellow,type:`percentage`}};var $=class{events=[];end(e){let t,n=this.events;for(let r of e.position)t=n[r],t?.events&&(n=t.events);t&&!t.end&&(t.end=performance.mark(X(t.id)))}report(e=!0){let t=this.events[0];if(!t)return;let n=this.events[this.events.length-1],r=`root`,i=Y(r),a=performance.measure(Z(i),Q(t.id),X(n.id));return e&&this.reportEvent({end:n.end,events:this.events,id:i,indent:0,measure:a,name:r,start:t.start}),a}reportEvent({indent:e,...t}){let n=e?E.gray:E.cyan,r=t.events.length-1;t.events.forEach((i,a)=>{let o=performance.measure(Z(i.id),Q(i.id),X(i.id)),s=Math.ceil(o.duration*100)/100,c=Math.ceil(o.duration/t.measure.duration*100*100)/100,l=e?vt(s,c):void 0,u=`${s.toFixed(2).padStart(8)}ms`;l?.type===`duration`&&(u=l.color(u));let d=a===r?`└─ `:`├─ `,f=e?`│ `.repeat(e-1)+d:``,p=38-f.length,m=e?`↳ `:``,h=`${e?` `.repeat(e-1)+m:``}${c.toFixed(2)}%`;l?.type===`percentage`&&(h=l.color(h));let g=E.gray(`[root] `);console.log(`${g}${E.gray(f)}${n(`${i.name.padEnd(p)} ${u} (${h})`)}`),this.reportEvent({...i,indent:e+1,measure:o})})}start(e){return performance.mark(Q(e))}storeEvent({result:e,...t}){let n=t.events.length-1,r=t.events[n];if(r&&!r.end){e.position=[...e.position,n],this.storeEvent({...t,events:r.events,result:e});return}let i=t.events.push({...t,events:[]});e.position=[...e.position,i-1]}timeEvent(e){let t=Y(e),n=this.start(t),r={events:this.events,id:t,name:e,start:n},i={position:[]};return this.storeEvent({...r,result:i}),{mark:n,timeEnd:()=>this.end(i)}}};const yt=async(e,t=new $)=>{let n=typeof e==`function`?await e():e,i=n?n instanceof Array?n:[n]:[],a=i.find(e=>p(e).level!==`silent`)?.logs;typeof a==`string`&&(a=p({logs:a}));let o;try{ce();let e=t.timeEvent(`createClient`),n=t.timeEvent(`config`);o=await re({logger:t,userConfigs:i}),o.results.some(e=>e.config.logs.level!==`silent`)&&Te(),n.timeEnd();let r=o.results.flatMap(e=>e.errors.map(t=>({error:t,jobIndex:e.jobIndex})));if(r.length)throw new d(r);let a=t.timeEvent(`handlebars`),s=_t();a.timeEnd();let c=(await Promise.all(o.results.map(async e=>{try{return await q({config:e.config,dependencies:o.dependencies,jobIndex:e.jobIndex,logger:t,templates:s})}catch(t){throw new ee(``,{error:t,jobIndex:e.jobIndex})}}))).filter(e=>!!e);e.timeEnd();let l=o.results.some(e=>e.config.logs.level===`debug`);return t.report(l),c}catch(e){let t=o?.results??[],n=t.find(e=>e.config.logs.level!==`silent`)?.config.logs??t[0]?.config.logs??a,s=t.some(e=>e.config.dryRun)??i.some(e=>e.dryRun)??!1,c=n?.file&&!s?r(e,n.path??``):void 0;throw(!n||n.level!==`silent`)&&(l({error:e,logPath:c}),await u({error:e,isInteractive:t.some(e=>e.config.interactive)??i.some(e=>e.interactive)??!1})&&await b(e)),e}},bt={stringCase:T};E.enabled=oe().hasBasic;const xt=async e=>typeof e==`function`?await e():e;export{$ as i,bt as n,yt as r,xt as t};
|
|
1310
|
+
//# sourceMappingURL=src-SnUobB4f.js.map
|