@gam-test/fetch-wrapper
Version:
A simple fetch wrapper for better error handling and less response context
2 lines • 3.06 kB
JavaScript
Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkOVQZ33YOjs = require('./chunk-OVQZ33YO.js');var _chunkTNLHHRHAjs = require('./chunk-TNLHHRHA.js');var _chunkFAX5YA5Ejs = require('./chunk-FAX5YA5E.js');var _chunkZ2EHLFSPjs = require('./chunk-Z2EHLFSP.js');var _chunkKRNAN66Rjs = require('./chunk-KRNAN66R.js');var _chunkKADTXPPQjs = require('./chunk-KADTXPPQ.js');var d=class{#e;#n;#t;constructor({baseUrl:t,defaultBodyParser:e,config:n}){this.#e=t,this.#n=e,this.#t=n}#r(t){return t?"bodyParser"in t?{...this.#t,...t,bodyParser:_nullishCoalesce(t.bodyParser, () => (this.#n)),headers:{..._optionalChain([this, 'access', _ => _.#t, 'optionalAccess', _2 => _2.headers]),..._optionalChain([t, 'optionalAccess', _3 => _3.headers])}}:{...this.#t,...t,bodyParser:this.#n,headers:{..._optionalChain([this, 'access', _4 => _4.#t, 'optionalAccess', _5 => _5.headers]),..._optionalChain([t, 'optionalAccess', _6 => _6.headers])}}:{...this.#t,bodyParser:this.#n,headers:{..._optionalChain([this, 'access', _7 => _7.#t, 'optionalAccess', _8 => _8.headers])}}}#i(t){return t?"bodyParser"in t?{...this.#t,...t,bodyParser:_nullishCoalesce(t.bodyParser, () => (this.#n)),headers:{..._optionalChain([this, 'access', _9 => _9.#t, 'optionalAccess', _10 => _10.headers]),..._optionalChain([t, 'optionalAccess', _11 => _11.headers])}}:{...this.#t,...t,bodyParser:this.#n,headers:{..._optionalChain([this, 'access', _12 => _12.#t, 'optionalAccess', _13 => _13.headers]),..._optionalChain([t, 'optionalAccess', _14 => _14.headers])}}:{...this.#t,data:null,bodyParser:this.#n,headers:{..._optionalChain([this, 'access', _15 => _15.#t, 'optionalAccess', _16 => _16.headers])}}}async get(t,e){let n=new (0, _chunkOVQZ33YOjs.a)({url:`${this.#e}${t}`}),i=this.#r(e);return await n.request(i)}async head(t,e){let n=new (0, _chunkTNLHHRHAjs.a)({url:`${this.#e}${t}`}),i=this.#r(e);return await n.request({...i,bodyParser:void 0})}async post(t,e){let n=new (0, _chunkZ2EHLFSPjs.a)({url:`${this.#e}${t}`}),i=this.#i(e);return await n.request(i)}async patch(t,e){let n=new (0, _chunkFAX5YA5Ejs.a)({url:`${this.#e}${t}`}),i=this.#i(e);return await n.request(i)}async put(t,e){let n=new (0, _chunkKRNAN66Rjs.a)({url:`${this.#e}${t}`}),i=this.#i(e);return await n.request(i)}async delete(t,e){let n=new (0, _chunkKADTXPPQjs.a)({url:`${this.#e}${t}`}),i=this.#i(e);return await n.request(i)}};exports.a = d;
//# sourceMappingURL=chunk-W2OSCO7P.js.map
;