@oazapfts/runtime
Advanced tools
Comparing version 1.0.0-alpha.4 to 1.0.0-alpha.5
@@ -1,94 +0,91 @@ | ||
var j = Object.defineProperty; | ||
var E = (n, t, s) => t in n ? j(n, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[t] = s; | ||
var p = (n, t, s) => (E(n, typeof t != "symbol" ? t + "" : t, s), s); | ||
import { form as b } from "./query.js"; | ||
import { joinUrl as C } from "./util.js"; | ||
import { mergeHeaders as h, normalizeHeaders as l } from "./headers.js"; | ||
function A(n = {}) { | ||
async function t(r, a) { | ||
const e = await d(r, a); | ||
let o; | ||
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 = {}) { | ||
async function e(r, n) { | ||
const t = await h(r, n); | ||
let s; | ||
try { | ||
o = await e.text(); | ||
s = await t.text(); | ||
} catch { | ||
} | ||
return { | ||
status: e.status, | ||
headers: e.headers, | ||
contentType: e.headers.get("content-type"), | ||
data: o | ||
status: t.status, | ||
headers: t.headers, | ||
contentType: t.headers.get("content-type"), | ||
data: s | ||
}; | ||
} | ||
async function s(r, a = {}) { | ||
const { status: e, headers: o, contentType: u, data: i } = await t(r, { | ||
...a, | ||
headers: h( | ||
async function o(r, n = {}) { | ||
const { status: t, headers: s, contentType: u, data: i } = await e(r, { | ||
...n, | ||
headers: d( | ||
{ | ||
Accept: "application/json" | ||
}, | ||
a.headers | ||
n.headers | ||
) | ||
}); | ||
return (u ? u.includes("json") : !1) ? { | ||
status: e, | ||
headers: o, | ||
status: t, | ||
headers: s, | ||
data: i ? JSON.parse(i) : null | ||
} : { status: e, headers: o, data: i }; | ||
} : { status: t, headers: s, data: i }; | ||
} | ||
async function c(r, a = {}) { | ||
const e = await d(r, a); | ||
let o; | ||
async function c(r, n = {}) { | ||
const t = await h(r, n); | ||
let s; | ||
try { | ||
o = await e.blob(); | ||
s = await t.blob(); | ||
} catch { | ||
} | ||
return { status: e.status, headers: e.headers, data: o }; | ||
return { status: t.status, headers: t.headers, data: s }; | ||
} | ||
async function d(r, a = {}) { | ||
async function h(r, n = {}) { | ||
const { | ||
baseUrl: e, | ||
fetch: o, | ||
baseUrl: t, | ||
fetch: s, | ||
...u | ||
} = { | ||
...a, | ||
...n, | ||
...a, | ||
headers: h(n.headers, a.headers) | ||
}, i = C(e, r); | ||
return await (o || fetch)(i, u); | ||
headers: d(a.headers, n.headers) | ||
}, i = j(t, r); | ||
return await (s || fetch)(i, u); | ||
} | ||
return { | ||
ok: y, | ||
fetchText: t, | ||
fetchJson: s, | ||
ok: l, | ||
fetchText: e, | ||
fetchJson: o, | ||
fetchBlob: c, | ||
mergeHeaders: h, | ||
json({ body: r, headers: a, ...e }) { | ||
mergeHeaders: d, | ||
json({ body: r, headers: n, ...t }) { | ||
return { | ||
...e, | ||
...t, | ||
...r != null && { body: JSON.stringify(r) }, | ||
headers: h( | ||
headers: d( | ||
{ | ||
"Content-Type": "application/json" | ||
}, | ||
a | ||
n | ||
) | ||
}; | ||
}, | ||
form({ body: r, headers: a, ...e }) { | ||
form({ body: r, headers: n, ...t }) { | ||
return { | ||
...e, | ||
...r != null && { body: b(r) }, | ||
headers: h( | ||
...t, | ||
...r != null && { body: w(r) }, | ||
headers: d( | ||
{ | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
}, | ||
a | ||
n | ||
) | ||
}; | ||
}, | ||
multipart({ body: r, headers: a, ...e }) { | ||
multipart({ body: r, headers: n, ...t }) { | ||
if (r == null) | ||
return { ...e, body: r, headers: l(a) }; | ||
const o = new (n.formDataConstructor || e.formDataConstructor || FormData)(), u = (i, f) => { | ||
typeof f == "string" || f instanceof Blob ? o.append(i, f) : o.append( | ||
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, | ||
@@ -99,7 +96,7 @@ new Blob([JSON.stringify(f)], { type: "application/json" }) | ||
return Object.entries(r).forEach(([i, f]) => { | ||
Array.isArray(f) ? f.forEach((w) => u(i, w)) : u(i, f); | ||
Array.isArray(f) ? f.forEach((m) => u(i, m)) : u(i, f); | ||
}), { | ||
...e, | ||
body: o, | ||
headers: l(a) | ||
...t, | ||
body: s, | ||
headers: p(n) | ||
}; | ||
@@ -109,44 +106,43 @@ } | ||
} | ||
async function D(n, t) { | ||
const { status: s, data: c, headers: d } = await n, r = t[s]; | ||
async function g(a, e) { | ||
const { status: o, data: c, headers: h } = await a, r = e[o]; | ||
if (r) | ||
return r(c); | ||
if (t.default) | ||
return t.default(s, c); | ||
throw new m(s, c, d); | ||
if (e.default) | ||
return e.default(o, c); | ||
throw new y(o, c, h); | ||
} | ||
const S = [200, 201, 202, 204]; | ||
async function y(n) { | ||
const t = await n; | ||
if (S.some((s) => s == t.status)) | ||
return t.data; | ||
throw new m(t.status, t.data, t.headers); | ||
const E = [200, 201, 202, 204]; | ||
async function l(a) { | ||
const e = await a; | ||
if (E.some((o) => o == e.status)) | ||
return e.data; | ||
throw new y(e.status, e.data, e.headers); | ||
} | ||
function J(n) { | ||
return (...t) => y(n(...t)); | ||
function b(a) { | ||
return (...e) => l(a(...e)); | ||
} | ||
function H(n) { | ||
const t = {}; | ||
return Object.entries(n).forEach(([s, c]) => { | ||
t[s] = typeof c == "function" ? J(c) : c; | ||
}), t; | ||
function x(a) { | ||
const e = {}; | ||
return Object.entries(a).forEach(([o, c]) => { | ||
e[o] = typeof c == "function" ? b(c) : c; | ||
}), e; | ||
} | ||
class m extends Error { | ||
constructor(s, c, d) { | ||
super(`Error: ${s}`); | ||
p(this, "status"); | ||
p(this, "data"); | ||
p(this, "headers"); | ||
this.status = s, this.data = c, this.headers = d; | ||
class y extends Error { | ||
status; | ||
data; | ||
headers; | ||
constructor(e, o, c) { | ||
super(`Error: ${e}`), this.status = e, this.data = o, this.headers = c; | ||
} | ||
} | ||
export { | ||
m as HttpError, | ||
S as SUCCESS_CODES, | ||
D as handle, | ||
y as ok, | ||
J as okify, | ||
H as optimistic, | ||
A as runtime | ||
y as HttpError, | ||
E as SUCCESS_CODES, | ||
g as handle, | ||
l as ok, | ||
b as okify, | ||
x as optimistic, | ||
O as runtime | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@oazapfts/runtime", | ||
"version": "1.0.0-alpha.4", | ||
"version": "1.0.0-alpha.5", | ||
"description": "Runtime for OpenApi TypeScript client generator", | ||
@@ -34,3 +34,3 @@ "type": "module", | ||
"scripts": { | ||
"build": "rm -rf dist && tsc && vite build" | ||
"build": "rm -rf dist && tsc && vite build --mode esm && vite build --mode cjs" | ||
}, | ||
@@ -37,0 +37,0 @@ "release": { |
@@ -1,4 +0,4 @@ | ||
import { UserConfig } from "vite"; | ||
import { defineConfig } from "vite"; | ||
export default { | ||
export default defineConfig(({ mode }) => ({ | ||
build: { | ||
@@ -8,5 +8,6 @@ sourcemap: true, | ||
outDir: "dist", | ||
target: mode === "esm" ? "esnext" : "es2015", | ||
lib: { | ||
entry: ["src/index.ts", "src/query.ts", "src/util.ts", "src/headers.ts"], | ||
formats: ["es", "cjs"], | ||
formats: [mode === "esm" ? "es" : "cjs"], | ||
}, | ||
@@ -20,2 +21,2 @@ rollupOptions: { | ||
}, | ||
} satisfies UserConfig; | ||
})); |
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
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
64289
488