Comparing version 0.0.23 to 0.0.24
@@ -38,2 +38,8 @@ declare type AbortControllerGroup = { | ||
export declare const Except: <E = unknown>(initial: { | ||
response: Response; | ||
except: E; | ||
error: Error; | ||
}) => Except<E>; | ||
export declare type Except<ErrType = unknown> = Except_2<ErrType | null> & { | ||
@@ -63,4 +69,2 @@ aborted: false; | ||
export declare const FetchNoResponse: (error?: unknown, props?: Partial<NoResponse>) => NoResponse; | ||
export declare type FetchOptions = RequestInit & { | ||
@@ -112,2 +116,8 @@ strict?: boolean; | ||
export declare const NoResponse: (initial?: { | ||
error?: unknown; | ||
aborted?: boolean; | ||
timeout?: boolean; | ||
}) => NoResponse; | ||
export declare type NoResponse = Except_2<null> & { | ||
@@ -120,2 +130,13 @@ aborted: boolean; | ||
/** | ||
* Results | ||
*/ | ||
export declare const Ok: <V = unknown>(initial: { | ||
response: Response; | ||
value: V; | ||
}) => Ok<V>; | ||
/** | ||
* Result types | ||
*/ | ||
export declare type Ok<V = unknown> = Ok_2<V> & { | ||
@@ -184,5 +205,5 @@ aborted: false; | ||
export declare type SWRError<T> = Error & { | ||
result: NoResponse | Except<T>; | ||
except: null | T; | ||
export declare type SWRError<E> = Error & { | ||
result: NoResponse | Except<E>; | ||
except: null | E; | ||
status: null | number; | ||
@@ -189,0 +210,0 @@ }; |
128
dist/adnf.js
@@ -35,3 +35,3 @@ const C = (e) => "File" in window && e instanceof File, H = (e) => e instanceof FormData, D = (e) => { | ||
); | ||
}, j = (e = {}, t = {}, n = !0) => { | ||
}, x = (e = {}, t = {}, n = !0) => { | ||
n && (e.group && t.group || e.form && t.form || e.files && t.files) && console.warn( | ||
@@ -60,3 +60,3 @@ "ADNF: Merging two options with group, form or files. Note these options cannot be merged and will be replaced. Hide this and similar warnings with fetch(..., { warn: false }) option." | ||
} | ||
}, q = (e) => e == null, z = (e) => { | ||
}, q = (e) => e == null, v = (e) => { | ||
if (q(e)) | ||
@@ -75,3 +75,3 @@ throw new Error("Non-nullable assertion failed"); | ||
log: () => void console.log(e), | ||
notNullable: () => z(e) | ||
notNullable: () => v(e) | ||
}), m = Object.assign(L, { | ||
@@ -98,9 +98,9 @@ Ok: L, | ||
} | ||
}), B = (e) => { | ||
}), z = (e) => { | ||
try { | ||
return m.Ok(e()); | ||
} catch (t) { | ||
return m.Except(null, S(t) ? t : void 0); | ||
return m.Except(null, j(t) ? t : void 0); | ||
} | ||
}, S = (e) => e instanceof Error, Y = async (e, t) => { | ||
}, j = (e) => e instanceof Error, Q = async (e, t) => { | ||
const { | ||
@@ -120,4 +120,4 @@ strict: n = !0, | ||
files: E, | ||
timeout: x, | ||
unwrap: Q, | ||
timeout: P, | ||
unwrap: K, | ||
...l | ||
@@ -148,3 +148,3 @@ } = t ?? {}; | ||
} | ||
const N = typeof x == "number" ? setTimeout(() => h.abort(U), x) : null; | ||
const N = typeof P == "number" ? setTimeout(() => h.abort(U), P) : null; | ||
if (c && (l.body = f(c), g({ | ||
@@ -165,19 +165,27 @@ "Content-Type": "application/json" | ||
if (n && !T) | ||
return O( | ||
a, | ||
null, | ||
new Error("Fetch response not json in: fetch(..., { strict: true })") | ||
); | ||
return O({ | ||
response: a, | ||
except: null, | ||
error: new Error("Fetch response not json in: fetch(..., { strict: true })") | ||
}); | ||
const k = await a.text(), A = T ? p(k) : k; | ||
if (F) | ||
return V(a, A); | ||
return B({ | ||
value: A, | ||
response: a | ||
}); | ||
const $ = A; | ||
return n && !$ ? O( | ||
a, | ||
null, | ||
new Error("Fetch response error nullable in: fetch(..., { strict: true })") | ||
) : O(a, $, new Error("Fetch response not ok")); | ||
return O(n && !$ ? { | ||
response: a, | ||
except: null, | ||
error: new Error("Fetch response error nullable in: fetch(..., { strict: true })") | ||
} : { | ||
response: a, | ||
except: $, | ||
error: new Error("Fetch response Except") | ||
}); | ||
} catch (a) { | ||
const F = h.signal.aborted && h.signal.reason === U; | ||
return w(a, { | ||
return w({ | ||
error: a, | ||
aborted: h.signal.aborted, | ||
@@ -188,3 +196,4 @@ timeout: F | ||
} catch (g) { | ||
return w(g, { | ||
return w({ | ||
error: g, | ||
aborted: !1, | ||
@@ -194,23 +203,21 @@ timeout: !1 | ||
} | ||
}, V = (e, t) => Object.assign(m.Ok(t), { | ||
}, B = (e) => Object.assign(m.Ok(e.value), { | ||
aborted: !1, | ||
timeout: !1, | ||
resolved: !0, | ||
response: e | ||
}), O = (e, t, n, r = {}) => Object.assign(m.Except(t, n), { | ||
response: e.response | ||
}), O = (e) => Object.assign(m.Except(e.except, e.error), { | ||
aborted: !1, | ||
timeout: !1, | ||
resolved: !0, | ||
...r, | ||
response: e | ||
}), w = (e, t = {}) => { | ||
const n = S(e) ? e : new Error("FetchNoResponse: Provided error is on instance of Error()"); | ||
return Object.assign(m.Except(null, n), { | ||
aborted: !1, | ||
timeout: !1, | ||
response: e.response | ||
}), w = (e = {}) => { | ||
const t = j(e.error) ? e.error : new Error("NoResponse: Provided error is on instance of Error()"); | ||
return Object.assign(m.Except(null, t), { | ||
aborted: e.aborted ?? !1, | ||
timeout: e.timeout ?? !1, | ||
resolved: !1, | ||
...t, | ||
response: void 0 | ||
}); | ||
}, U = Symbol("Timeout"), Z = async (e, t) => (console.log( | ||
}, U = Symbol("Timeout"), Y = async (e, t) => (console.log( | ||
"%c🐕 " + ((t == null ? void 0 : t.method) || "GET").toUpperCase(), | ||
@@ -224,7 +231,7 @@ "background: #85ce47; border-radius: 999px; font-weight: 600; padding: 1.5px 5.5px; color: black", | ||
response: new Response() | ||
})), v = async (e, t) => Object.assign(m.Ok({}), { | ||
})), Z = async (e, t) => Object.assign(m.Ok({}), { | ||
aborted: !1, | ||
timeout: !1, | ||
response: new Response() | ||
}), P = (e, t) => { | ||
}), S = (e, t) => { | ||
const n = "_initFetch" in e ? e._initFetch : e, r = "_composedFetch" in e ? e._composedFetch : (s) => s, o = (s) => r(t ? t(s) : s), i = async (s, p) => { | ||
@@ -235,3 +242,3 @@ const f = (c, d) => (c = b(c), n(c + s, { ...d, ...p })); | ||
} catch (c) { | ||
return w(S(c) ? c : void 0); | ||
return w({ error: j(c) ? c : void 0 }); | ||
} | ||
@@ -242,12 +249,12 @@ }; | ||
_composedFetch: o, | ||
_create: (s) => P(i, s) | ||
_create: (s) => S(i, s) | ||
}); | ||
}, W = (e, t) => P(e, (n) => (r, o) => { | ||
}, V = (e, t) => S(e, (n) => (r, o) => { | ||
const i = typeof t == "function" ? t(o) : t; | ||
return n(r, j(o, i)); | ||
}), X = (e, t) => P(e, (n) => (r, o) => (r = b(r), n( | ||
return n(r, x(o, i)); | ||
}), W = (e, t) => S(e, (n) => (r, o) => (r = b(r), n( | ||
typeof t == "function" ? t(r) : r + b(t), | ||
o | ||
))), ee = (e, t) => X(e, (n) => t + n), te = (e) => { | ||
const t = (n) => W(e, { method: n }); | ||
))), ee = (e, t) => W(e, (n) => t + n), te = (e) => { | ||
const t = (n) => V(e, { method: n }); | ||
return { | ||
@@ -265,17 +272,17 @@ method: t, | ||
t = b(t); | ||
const r = I(t, typeof n == "function" ? {} : n); | ||
const r = X(t, typeof n == "function" ? {} : n); | ||
return { | ||
key: r, | ||
fetch: (i, u) => { | ||
const s = B( | ||
const s = z( | ||
() => typeof n == "function" ? n(i) : n | ||
); | ||
if (s.failed) | ||
return w(s.error); | ||
const p = s.value, f = j(p, { key: r }); | ||
return e(t, j(f, u)); | ||
return w({ error: s.error }); | ||
const p = s.value, f = x(p, { key: r }); | ||
return e(t, x(f, u)); | ||
}, | ||
resource: t | ||
}; | ||
}, I = (e, t) => J(e, (t == null ? void 0 : t.params) ?? {}), ne = () => { | ||
}, X = (e, t) => J(e, (t == null ? void 0 : t.params) ?? {}), ne = () => { | ||
const e = /* @__PURE__ */ new Set(); | ||
@@ -294,5 +301,5 @@ return { | ||
if (e.failed) | ||
throw K(e); | ||
throw I(e); | ||
return e.value; | ||
}, K = (e) => { | ||
}, I = (e) => { | ||
var t; | ||
@@ -306,20 +313,21 @@ return Object.assign(e.error, { | ||
export { | ||
w as FetchNoResponse, | ||
O as Except, | ||
w as NoResponse, | ||
m as Result, | ||
ne as createAbortGroup, | ||
Z as debugFetch, | ||
Y as fetch, | ||
j as mergeOptions, | ||
Y as debugFetch, | ||
Q as fetch, | ||
x as mergeOptions, | ||
J as params, | ||
J as respectParams, | ||
Y as resultFetch, | ||
Q as resultFetch, | ||
se as swrResult, | ||
oe as unwrap, | ||
v as voidFetch, | ||
Z as voidFetch, | ||
ee as withBase, | ||
re as withDeclarations, | ||
P as withFetch, | ||
S as withFetch, | ||
te as withMethods, | ||
W as withOptions, | ||
X as withResource | ||
V as withOptions, | ||
W as withResource | ||
}; |
{ | ||
"name": "adnf", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "files": [ |
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
43693
675