@oazapfts/runtime
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -137,2 +137,3 @@ export declare type ApiFunction = (...args: any[]) => Promise<WithHeaders<ApiResponse>>; | ||
mode?: RequestMode | undefined; | ||
priority?: RequestPriority | undefined; | ||
redirect?: RequestRedirect | undefined; | ||
@@ -156,2 +157,3 @@ referrer?: string | undefined; | ||
mode?: RequestMode | undefined; | ||
priority?: RequestPriority | undefined; | ||
redirect?: RequestRedirect | undefined; | ||
@@ -175,2 +177,3 @@ referrer?: string | undefined; | ||
mode?: RequestMode | undefined; | ||
priority?: RequestPriority | undefined; | ||
redirect?: RequestRedirect | undefined; | ||
@@ -193,2 +196,3 @@ referrer?: string | undefined; | ||
mode?: RequestMode | undefined; | ||
priority?: RequestPriority | undefined; | ||
redirect?: RequestRedirect | undefined; | ||
@@ -195,0 +199,0 @@ referrer?: string | undefined; |
92
index.js
import { form as w } from "./query.js"; | ||
import { joinUrl as j } from "./util.js"; | ||
import { mergeHeaders as d, normalizeHeaders as p } from "./headers.js"; | ||
function O(a = {}) { | ||
import { joinUrl as b } from "./util.js"; | ||
import { mergeHeaders as d, normalizeHeaders as h } from "./headers.js"; | ||
function J(a = {}) { | ||
async function e(r, n) { | ||
const t = await h(r, n); | ||
const t = await p(r, n); | ||
let s; | ||
@@ -19,4 +19,4 @@ try { | ||
} | ||
async function o(r, n = {}) { | ||
const { status: t, headers: s, contentType: u, data: i } = await e(r, { | ||
async function i(r, n = {}) { | ||
const { status: t, headers: s, contentType: u, data: o } = await e(r, { | ||
...n, | ||
@@ -33,7 +33,7 @@ headers: d( | ||
headers: s, | ||
data: i ? JSON.parse(i) : null | ||
} : { status: t, headers: s, data: i }; | ||
data: o ? JSON.parse(o) : null | ||
} : { status: t, headers: s, data: o }; | ||
} | ||
async function c(r, n = {}) { | ||
const t = await h(r, n); | ||
async function f(r, n = {}) { | ||
const t = await p(r, n); | ||
let s; | ||
@@ -46,3 +46,3 @@ try { | ||
} | ||
async function h(r, n = {}) { | ||
async function p(r, n = {}) { | ||
const { | ||
@@ -56,10 +56,10 @@ baseUrl: t, | ||
headers: d(a.headers, n.headers) | ||
}, i = j(t, r); | ||
return await (s || fetch)(i, u); | ||
}, o = b(t, r); | ||
return await (s || fetch)(o, u); | ||
} | ||
return { | ||
ok: l, | ||
ok: y, | ||
fetchText: e, | ||
fetchJson: o, | ||
fetchBlob: c, | ||
fetchJson: i, | ||
fetchBlob: f, | ||
mergeHeaders: d, | ||
@@ -92,15 +92,15 @@ json({ body: r, headers: n, ...t }) { | ||
if (r == null) | ||
return { ...t, body: r, headers: p(n) }; | ||
const s = new (a.formDataConstructor || t.formDataConstructor || FormData)(), u = (i, f) => { | ||
typeof f == "string" || f instanceof Blob ? s.append(i, f) : s.append( | ||
i, | ||
new Blob([JSON.stringify(f)], { type: "application/json" }) | ||
return { ...t, body: r, headers: h(n) }; | ||
const s = new (a.formDataConstructor || t.formDataConstructor || FormData)(), u = (o, c) => { | ||
typeof c == "string" || c instanceof Blob ? s.append(o, c) : typeof c == "number" ? s.append(o, String(c)) : s.append( | ||
o, | ||
new Blob([JSON.stringify(c)], { type: "application/json" }) | ||
); | ||
}; | ||
return Object.entries(r).forEach(([i, f]) => { | ||
Array.isArray(f) ? f.forEach((m) => u(i, m)) : u(i, f); | ||
return Object.entries(r).forEach(([o, c]) => { | ||
Array.isArray(c) ? c.forEach((m) => u(o, m)) : u(o, c); | ||
}), { | ||
...t, | ||
body: s, | ||
headers: p(n) | ||
headers: h(n) | ||
}; | ||
@@ -110,43 +110,43 @@ } | ||
} | ||
async function g(a, e) { | ||
const { status: o, data: c, headers: h } = await a, r = e[o]; | ||
async function O(a, e) { | ||
const { status: i, data: f, headers: p } = await a, r = e[i]; | ||
if (r) | ||
return r(c); | ||
return r(f); | ||
if (e.default) | ||
return e.default(o, c); | ||
throw new y(o, c, h); | ||
return e.default(i, f); | ||
throw new l(i, f, p); | ||
} | ||
const E = [200, 201, 202, 204]; | ||
async function l(a) { | ||
const j = [200, 201, 202, 204]; | ||
async function y(a) { | ||
const e = await a; | ||
if (E.some((o) => o == e.status)) | ||
if (j.some((i) => i == e.status)) | ||
return e.data; | ||
throw new y(e.status, e.data, e.headers); | ||
throw new l(e.status, e.data, e.headers); | ||
} | ||
function b(a) { | ||
return (...e) => l(a(...e)); | ||
function E(a) { | ||
return (...e) => y(a(...e)); | ||
} | ||
function x(a) { | ||
const e = {}; | ||
return Object.entries(a).forEach(([o, c]) => { | ||
e[o] = typeof c == "function" ? b(c) : c; | ||
return Object.entries(a).forEach(([i, f]) => { | ||
e[i] = typeof f == "function" ? E(f) : f; | ||
}), e; | ||
} | ||
class y extends Error { | ||
class l extends Error { | ||
status; | ||
data; | ||
headers; | ||
constructor(e, o, c) { | ||
super(`Error: ${e}`), this.status = e, this.data = o, this.headers = c; | ||
constructor(e, i, f) { | ||
super(`Error: ${e}`), this.status = e, this.data = i, this.headers = f; | ||
} | ||
} | ||
export { | ||
y as HttpError, | ||
E as SUCCESS_CODES, | ||
g as handle, | ||
l as ok, | ||
b as okify, | ||
l as HttpError, | ||
j as SUCCESS_CODES, | ||
O as handle, | ||
y as ok, | ||
E as okify, | ||
x as optimistic, | ||
O as runtime | ||
J as runtime | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@oazapfts/runtime", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Runtime for OpenApi TypeScript client generator", | ||
@@ -37,3 +37,3 @@ "type": "module", | ||
"scripts": { | ||
"build": "rm -rf dist && tsc && vite build --mode esm && vite build --mode cjs", | ||
"build": "rm -rf dist && vite build --mode esm && vite build --mode cjs", | ||
"prepack": "sed -i 's|||g' package.json && mv * ." | ||
@@ -40,0 +40,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64975
473