@manyducks.co/dolla 2.0.0 → 3.1.0
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/README.md +133 -284
- package/dist/context-B5blupD2.js +363 -0
- package/dist/context-B5blupD2.js.map +1 -0
- package/dist/core/context.d.ts +29 -144
- package/dist/core/debug.d.ts +19 -0
- package/dist/core/index.d.ts +15 -16
- package/dist/core/markup/helpers.d.ts +34 -0
- package/dist/core/markup/html.d.ts +3 -0
- package/dist/core/{nodes → markup/nodes}/dom.d.ts +5 -4
- package/dist/core/markup/nodes/dynamic.d.ts +16 -0
- package/dist/core/markup/nodes/element.d.ts +14 -0
- package/dist/core/markup/nodes/portal.d.ts +15 -0
- package/dist/core/markup/nodes/repeat.d.ts +21 -0
- package/dist/core/markup/nodes/view.d.ts +17 -0
- package/dist/core/markup/scheduler.d.ts +1 -0
- package/dist/core/markup/types.d.ts +62 -0
- package/dist/core/markup/utils.d.ts +22 -0
- package/dist/core/ref.d.ts +6 -12
- package/dist/core/root.d.ts +36 -0
- package/dist/core/signals.d.ts +46 -76
- package/dist/core/symbols.d.ts +2 -0
- package/dist/core-JHktdqjt.js +242 -0
- package/dist/core-JHktdqjt.js.map +1 -0
- package/dist/http/index.d.ts +21 -33
- package/dist/http.js +89 -149
- package/dist/http.js.map +1 -1
- package/dist/index.js +4 -174
- package/dist/jsx-dev-runtime.d.ts +4 -3
- package/dist/jsx-dev-runtime.js +12 -9
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +5 -4
- package/dist/jsx-runtime.js +17 -12
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/router/index.d.ts +4 -3
- package/dist/router/router.d.ts +19 -162
- package/dist/router/store.d.ts +12 -0
- package/dist/router/types.d.ts +152 -0
- package/dist/router/utils.d.ts +99 -0
- package/dist/router/utils.test.d.ts +1 -0
- package/dist/router.js +428 -5
- package/dist/router.js.map +1 -1
- package/dist/signals-CMJPGr_M.js +354 -0
- package/dist/signals-CMJPGr_M.js.map +1 -0
- package/dist/translate/index.d.ts +82 -0
- package/dist/translate.js +125 -0
- package/dist/translate.js.map +1 -0
- package/dist/types.d.ts +21 -39
- package/dist/utils.d.ts +41 -29
- package/dist/utils.test.d.ts +1 -0
- package/dist/virtual/index.d.ts +1 -0
- package/dist/virtual/list.d.ts +53 -0
- package/package.json +19 -16
- package/dist/core/app.d.ts +0 -24
- package/dist/core/env.d.ts +0 -3
- package/dist/core/hooks.d.ts +0 -70
- package/dist/core/logger.d.ts +0 -42
- package/dist/core/logger.test.d.ts +0 -0
- package/dist/core/markup.d.ts +0 -82
- package/dist/core/markup.test.d.ts +0 -0
- package/dist/core/nodes/_markup.d.ts +0 -36
- package/dist/core/nodes/dynamic.d.ts +0 -22
- package/dist/core/nodes/element.d.ts +0 -27
- package/dist/core/nodes/portal.d.ts +0 -18
- package/dist/core/nodes/repeat.d.ts +0 -27
- package/dist/core/nodes/view.d.ts +0 -25
- package/dist/core/views/default-crash-view.d.ts +0 -25
- package/dist/core/views/for.d.ts +0 -21
- package/dist/core/views/fragment.d.ts +0 -7
- package/dist/core/views/portal.d.ts +0 -16
- package/dist/core/views/show.d.ts +0 -25
- package/dist/fragment-BahD_BJA.js +0 -7
- package/dist/fragment-BahD_BJA.js.map +0 -1
- package/dist/i18n/index.d.ts +0 -134
- package/dist/i18n.js +0 -309
- package/dist/i18n.js.map +0 -1
- package/dist/index-DRJlxs-Q.js +0 -535
- package/dist/index-DRJlxs-Q.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger-Aqi9m1CF.js +0 -565
- package/dist/logger-Aqi9m1CF.js.map +0 -1
- package/dist/markup-8jNhoqDe.js +0 -1089
- package/dist/markup-8jNhoqDe.js.map +0 -1
- package/dist/router/hooks.d.ts +0 -2
- package/dist/router/router.utils.d.ts +0 -93
- package/dist/typeChecking-5kmX0ulW.js +0 -65
- package/dist/typeChecking-5kmX0ulW.js.map +0 -1
- package/dist/typeChecking.d.ts +0 -95
- package/docs/buildless.md +0 -132
- package/docs/components.md +0 -238
- package/docs/hooks.md +0 -356
- package/docs/http.md +0 -178
- package/docs/i18n.md +0 -220
- package/docs/index.md +0 -10
- package/docs/markup.md +0 -136
- package/docs/mixins.md +0 -176
- package/docs/ref.md +0 -77
- package/docs/router.md +0 -281
- package/docs/setup.md +0 -137
- package/docs/signals.md +0 -262
- package/docs/stores.md +0 -113
- package/docs/views.md +0 -356
- package/notes/atomic.md +0 -452
- package/notes/elimination.md +0 -33
- package/notes/observable.md +0 -180
- package/notes/scratch.md +0 -565
- package/notes/splitting.md +0 -5
- package/notes/views.md +0 -195
- package/vite.config.js +0 -22
- /package/dist/core/{hooks.test.d.ts → markup/html.test.d.ts} +0 -0
- /package/dist/core/{ref.test.d.ts → markup/utils.test.d.ts} +0 -0
- /package/dist/router/{router.utils.test.d.ts → matcher.test.d.ts} +0 -0
- /package/dist/{typeChecking.test.d.ts → router/router.test.d.ts} +0 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { c as e, n as t, o as n, p as r, r as i, t as a, u as o } from "./signals-CMJPGr_M.js";
|
|
2
|
+
import { S as s, _ as c, b as l, d as u, f as d, g as f, h as p, m, n as h, o as g, u as _, v, x as y, y as b } from "./context-B5blupD2.js";
|
|
3
|
+
//#region src/core/root.ts
|
|
4
|
+
function x(t, n) {
|
|
5
|
+
let i = r(t) ? document.querySelector(t) : t;
|
|
6
|
+
e(i, "Element cannot be null.");
|
|
7
|
+
let a = h();
|
|
8
|
+
a.name = "dolla:root";
|
|
9
|
+
let s = [], l = [];
|
|
10
|
+
a[b] = i, a[v] = !!n?.debug;
|
|
11
|
+
let d = null, f = {
|
|
12
|
+
plugin: p,
|
|
13
|
+
mount: m,
|
|
14
|
+
unmount: y
|
|
15
|
+
};
|
|
16
|
+
function p(e) {
|
|
17
|
+
return s.push(e), f;
|
|
18
|
+
}
|
|
19
|
+
async function m(e) {
|
|
20
|
+
if (a.isMounted) return;
|
|
21
|
+
let t = await Promise.all(s.map((e) => e(a)));
|
|
22
|
+
for (let e of t) o(e) && l.push(e);
|
|
23
|
+
d = o(e) ? new u(a, e, {}) : c(e, a), d?.mount(i), g(a);
|
|
24
|
+
}
|
|
25
|
+
async function y() {
|
|
26
|
+
a.isMounted && (d?.unmount(!1), d = null, _(a), await Promise.all(l.map((e) => e())), l.length = 0);
|
|
27
|
+
}
|
|
28
|
+
return f;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/core/debug.ts
|
|
32
|
+
var S = () => {}, C = {
|
|
33
|
+
trace: 1,
|
|
34
|
+
info: 1,
|
|
35
|
+
log: 2,
|
|
36
|
+
warn: 3,
|
|
37
|
+
error: 4,
|
|
38
|
+
silent: 5
|
|
39
|
+
}, w = 1, T = (e) => !e.startsWith("dolla:"), E = (e) => {
|
|
40
|
+
w = C[e] || 1;
|
|
41
|
+
}, D = (e) => {
|
|
42
|
+
T = e;
|
|
43
|
+
}, O = globalThis.console || {};
|
|
44
|
+
function k(e, ...t) {
|
|
45
|
+
let n = e.name, r, i = (e, i) => {
|
|
46
|
+
if (i < w || !T(n) || !O[e]) return S;
|
|
47
|
+
if (!r) {
|
|
48
|
+
let e = "%c" + n, i = [`color:${j(n)};font-weight:bold`];
|
|
49
|
+
for (let [n, r] of t) e += `%c[${n}: %c${r}%c]`, i.push("color:#777", "color:#aaa", "color:#777");
|
|
50
|
+
r = [e, ...i];
|
|
51
|
+
}
|
|
52
|
+
return O[e].bind(O, ...r);
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
get info() {
|
|
56
|
+
return i("info", 1);
|
|
57
|
+
},
|
|
58
|
+
get trace() {
|
|
59
|
+
return i("trace", 1);
|
|
60
|
+
},
|
|
61
|
+
get log() {
|
|
62
|
+
return i("log", 2);
|
|
63
|
+
},
|
|
64
|
+
get warn() {
|
|
65
|
+
return i("warn", 3);
|
|
66
|
+
},
|
|
67
|
+
get error() {
|
|
68
|
+
return i("error", 4);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function A(e, ...t) {
|
|
73
|
+
let n = h();
|
|
74
|
+
return n.name = e, k(n, ...t);
|
|
75
|
+
}
|
|
76
|
+
function j(e) {
|
|
77
|
+
let t = 0;
|
|
78
|
+
for (let n = 0; n < e.length; n++) t = (t + e.charCodeAt(n) * 10) % 360;
|
|
79
|
+
return `oklch(0.68 0.15 ${t}deg)`;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/core/markup/nodes/portal.ts
|
|
83
|
+
var M = class extends s {
|
|
84
|
+
#e = p("");
|
|
85
|
+
#t;
|
|
86
|
+
#n;
|
|
87
|
+
#r;
|
|
88
|
+
#i;
|
|
89
|
+
constructor(e, t, n) {
|
|
90
|
+
super(), this.#t = e, this.#n = t, this.#r = n;
|
|
91
|
+
}
|
|
92
|
+
getRoot() {
|
|
93
|
+
return this.#e;
|
|
94
|
+
}
|
|
95
|
+
isMounted() {
|
|
96
|
+
return this.#e.parentNode != null;
|
|
97
|
+
}
|
|
98
|
+
mount(e, t) {
|
|
99
|
+
this.isMounted() || (d(e, this.#e, t), this.#i ||= c(this.#n, this.#t), this.#i.mount(this.#r));
|
|
100
|
+
}
|
|
101
|
+
unmount(e = !1) {
|
|
102
|
+
this.isMounted() && (e || this.#e.parentNode?.removeChild(this.#e), this.#i?.isMounted() && this.#i.unmount(!1));
|
|
103
|
+
}
|
|
104
|
+
move(e, t) {
|
|
105
|
+
f(e, this.#e, t);
|
|
106
|
+
}
|
|
107
|
+
}, N = class extends s {
|
|
108
|
+
#e = p("");
|
|
109
|
+
#t;
|
|
110
|
+
#n;
|
|
111
|
+
#r;
|
|
112
|
+
#i;
|
|
113
|
+
#a = null;
|
|
114
|
+
#o = /* @__PURE__ */ new Map();
|
|
115
|
+
constructor(e, t, n, r) {
|
|
116
|
+
super(), this.#t = e, this.#n = t, this.#r = n, this.#i = r;
|
|
117
|
+
}
|
|
118
|
+
getRoot() {
|
|
119
|
+
return this.#e;
|
|
120
|
+
}
|
|
121
|
+
isMounted() {
|
|
122
|
+
return this.#e.parentNode != null;
|
|
123
|
+
}
|
|
124
|
+
mount(e, t) {
|
|
125
|
+
this.isMounted() || (d(e, this.#e, t), this.#a = n(this.#n, (e) => {
|
|
126
|
+
y(() => {
|
|
127
|
+
this._update(Array.from(e));
|
|
128
|
+
});
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
unmount(e = !1) {
|
|
132
|
+
this.#a &&= (this.#a(), null), !e && this.isMounted() && this.#e.parentNode?.removeChild(this.#e), this._cleanup(e);
|
|
133
|
+
}
|
|
134
|
+
move(e, t) {
|
|
135
|
+
return this.mount(e, t);
|
|
136
|
+
}
|
|
137
|
+
_cleanup(e) {
|
|
138
|
+
for (let t of this.#o.values()) t._node.unmount(e);
|
|
139
|
+
this.#o.clear();
|
|
140
|
+
}
|
|
141
|
+
_update(e) {
|
|
142
|
+
if (!this.isMounted()) return;
|
|
143
|
+
if (e.length === 0) return this._cleanup(!1);
|
|
144
|
+
let t = /* @__PURE__ */ new Map();
|
|
145
|
+
a(() => {
|
|
146
|
+
let n = new Set(e.map((e, t) => this.#r(e, t)));
|
|
147
|
+
for (let [e, t] of this.#o.entries()) n.has(e) || t._node.unmount(!1);
|
|
148
|
+
for (let r = 0; r < e.length; r++) {
|
|
149
|
+
let a = e[r], o = this.#r(a, r), s = this.#o.get(o);
|
|
150
|
+
if (s && n.has(o)) s._setItem(a), s._setIndex(r);
|
|
151
|
+
else {
|
|
152
|
+
let [e, t] = i(a), [n, l] = i(r);
|
|
153
|
+
s = {
|
|
154
|
+
_key: o,
|
|
155
|
+
_node: c(this.#i(() => e(), () => n()), this.#t),
|
|
156
|
+
_item: e,
|
|
157
|
+
_setItem: t,
|
|
158
|
+
_index: n,
|
|
159
|
+
_setIndex: l
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
t.set(o, s);
|
|
163
|
+
}
|
|
164
|
+
}), this.#o = t;
|
|
165
|
+
let n = this.#e.parentElement, r = this.#e;
|
|
166
|
+
for (let e of this.#o.values()) {
|
|
167
|
+
let t = r.nextSibling;
|
|
168
|
+
e._node.isMounted() ? e._node.getRoot() !== t && e._node.move(n, r) : e._node.mount(n, r), r = e._node.getRoot();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/core/markup/helpers.ts
|
|
174
|
+
function P(e, t, n) {
|
|
175
|
+
return o(e) ? m(N, { args: [
|
|
176
|
+
e,
|
|
177
|
+
t,
|
|
178
|
+
n
|
|
179
|
+
] }) : Array.from(e).map((e, t) => n(() => e, () => t));
|
|
180
|
+
}
|
|
181
|
+
function F(e, n, r) {
|
|
182
|
+
return o(e) ? m(l, { args: [t(() => e() ? n : r)] }) : e ? n : r;
|
|
183
|
+
}
|
|
184
|
+
function I(e, t, n) {
|
|
185
|
+
return F(e, t, n);
|
|
186
|
+
}
|
|
187
|
+
function L(e, t, n) {
|
|
188
|
+
return F(e, n, t);
|
|
189
|
+
}
|
|
190
|
+
function R(e, t) {
|
|
191
|
+
return m(M, { args: [t, e] });
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/core/markup/html.ts
|
|
195
|
+
var z = /* @__PURE__ */ function(e) {
|
|
196
|
+
return e[e.Slash = 0] = "Slash", e[e.Text = 1] = "Text", e[e.Whitespace = 2] = "Whitespace", e[e.TagName = 3] = "TagName", e[e.Comment = 4] = "Comment", e[e.PropSet = 5] = "PropSet", e[e.PropAppend = 6] = "PropAppend", e;
|
|
197
|
+
}(z || {});
|
|
198
|
+
function B(e, ...t) {
|
|
199
|
+
let n = [e, ...t], r = z.Text, i = "", a = "", o = [0], s = "", c = (e) => {
|
|
200
|
+
r === z.Text && (e || (i = i.replace(/^\s*\n\s*|\s*\n\s*$/g, ""))) ? o.push(e ? n[e] : i) : r === z.TagName && (e || i) ? (o[1] = e ? n[e] : i, r = z.Whitespace) : r === z.Whitespace && i === "..." && e ? o[2] = Object.assign(o[2] || {}, n[e]) : r === z.Whitespace && i && !e ? (o[2] = o[2] || {})[i] = !0 : r >= z.PropSet && (r === z.PropSet ? ((o[2] = o[2] || {})[s] = e ? i ? i + n[e] : n[e] : i, r = z.PropAppend) : (e || i) && (o[2][s] += e ? i + n[e] : i)), i = "";
|
|
201
|
+
};
|
|
202
|
+
for (let t = 0; t < e.length; t++) {
|
|
203
|
+
t && (r === z.Text && c(), c(t));
|
|
204
|
+
for (let n = 0; n < e[t].length; n++) {
|
|
205
|
+
let l = e[t][n];
|
|
206
|
+
if (r === z.Text) l === "<" ? (c(), o = [
|
|
207
|
+
o,
|
|
208
|
+
"",
|
|
209
|
+
null
|
|
210
|
+
], r = z.TagName) : i += l;
|
|
211
|
+
else if (r === z.Comment) i === "--" && l === ">" ? (r = z.Text, i = "") : i = l + i[0];
|
|
212
|
+
else if (a) l === a ? a = "" : i += l;
|
|
213
|
+
else if (l === "\"" || l === "'") a = l;
|
|
214
|
+
else if (l === ">") c(), r = z.Text;
|
|
215
|
+
else if (r) if (l === "=") r = z.PropSet, s = i, i = "";
|
|
216
|
+
else if (l === "/" && (r < z.PropSet || e[t][n + 1] === ">")) {
|
|
217
|
+
c(), r === z.TagName && (o = o[0]);
|
|
218
|
+
let e = o;
|
|
219
|
+
o = o[0];
|
|
220
|
+
let t = e[1], n = e[2] || {}, i = e.slice(3);
|
|
221
|
+
o.push(m(t, {
|
|
222
|
+
...n,
|
|
223
|
+
children: i
|
|
224
|
+
})), r = z.Slash;
|
|
225
|
+
} else l === " " || l === " " || l === "\n" || l === "\r" ? (c(), r = z.Whitespace) : i += l;
|
|
226
|
+
r === z.TagName && i === "!--" && (r = z.Comment, o = o[0]);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return c(), o.length > 2 ? o.slice(1) : o[1];
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/core/ref.ts
|
|
233
|
+
function V() {
|
|
234
|
+
let e;
|
|
235
|
+
return ((...t) => t.length ? (e = t[0], () => {
|
|
236
|
+
e = void 0;
|
|
237
|
+
}) : e);
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
export { L as a, k as c, x as d, P as i, D as l, B as n, I as o, R as r, A as s, V as t, E as u };
|
|
241
|
+
|
|
242
|
+
//# sourceMappingURL=core-JHktdqjt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-JHktdqjt.js","names":["#context","#value","#parent","#anchor","#childNode","#context","#items","#key","#render","#root","#unsubscribe","#connectedItems"],"sources":["../src/core/root.ts","../src/core/debug.ts","../src/core/markup/nodes/portal.ts","../src/core/markup/nodes/repeat.ts","../src/core/markup/helpers.ts","../src/core/markup/html.ts","../src/core/ref.ts"],"sourcesContent":["import type { Renderable, View } from \"../types.js\";\nimport { assert, isFunction, isString } from \"../utils.js\";\nimport { type Context, createContext, mountContext, unmountContext } from \"./context.js\";\nimport { ViewNode } from \"./markup/nodes/view.js\";\nimport { type MarkupNode } from \"./markup/types.js\";\nimport { render } from \"./markup/utils.js\";\nimport { DEBUG, PARENT_ELEMENT } from \"./symbols.js\";\n\nexport type CleanupCallback = () => void | Promise<void>;\n\n/**\n * Plugins run before the app is mounted. If they return a promise, mounting will be delayed until the promise resolves.\n * If a cleanup function is returned, it will be called before the app is unmounted. The cleanup function's promise will delay unmounting.\n *\n * Hooks can be used inside plugins.\n */\nexport type DollaPlugin = (context: Context) => Promise<CleanupCallback | void> | CleanupCallback | void;\n\nexport interface DollaRootOptions {\n /**\n * Adds additional view info to the DOM to help with debugging.\n */\n debug?: boolean;\n}\n\nexport interface DollaRoot {\n /**\n * Registers a plugin to be added before `mount`.\n */\n plugin(plugin: DollaPlugin): DollaRoot;\n\n /**\n * Mounts a `view` to this root.\n */\n mount(view: View<{}>): Promise<void>;\n\n /**\n * Mounts any renderable content to this root.\n */\n mount(content: Renderable): Promise<void>;\n\n /**\n * Unmounts the currently mounted content.\n */\n unmount(): void;\n}\n\nexport function createRoot(selector: string, options?: DollaRootOptions): DollaRoot;\nexport function createRoot(element: Element, options?: DollaRootOptions): DollaRoot;\nexport function createRoot(target: string | Element, options?: DollaRootOptions) {\n const element = isString(target) ? document.querySelector(target) : target;\n assert(element, \"Element cannot be null.\");\n\n const context = createContext();\n context.name = \"dolla:root\";\n\n const plugins: DollaPlugin[] = [];\n const cleanup: CleanupCallback[] = [];\n\n context[PARENT_ELEMENT] = element;\n context[DEBUG] = Boolean(options?.debug);\n\n let rootNode: MarkupNode | null = null;\n\n const self: DollaRoot = { plugin, mount, unmount };\n\n function plugin(plugin: DollaPlugin) {\n plugins.push(plugin);\n return self;\n }\n\n async function mount(content: View<{}> | Renderable) {\n if (context.isMounted) return;\n\n const results = await Promise.all(plugins.map((fn) => fn(context)));\n for (const result of results) {\n if (isFunction<CleanupCallback>(result)) {\n cleanup.push(result);\n }\n }\n\n rootNode = isFunction<View<{}>>(content) ? new ViewNode(context, content, {}) : render(content, context);\n rootNode?.mount(element!);\n\n mountContext(context);\n }\n\n async function unmount() {\n if (!context.isMounted) return;\n\n rootNode?.unmount(false);\n rootNode = null;\n\n unmountContext(context);\n\n await Promise.all(cleanup.map((callback) => callback()));\n cleanup.length = 0;\n }\n\n return self;\n}\n","import { Context, createContext } from \"./context.js\";\n\nexport const noOp = () => {};\n\nexport type LogLevel = \"info\" | \"log\" | \"warn\" | \"error\" | \"silent\";\nconst LEVELS: Record<string, number> = { trace: 1, info: 1, log: 2, warn: 3, error: 4, silent: 5 };\n\nlet logLevel = 1;\nlet logFilter = (name: string) => !name.startsWith(\"dolla:\");\n\n// 3. Extracted configuration setters (replacing static class methods)\nexport const setLogLevel = (level: LogLevel) => {\n logLevel = LEVELS[level] || 1;\n};\nexport const setLogFilter = (filter: (name: string) => boolean) => {\n logFilter = filter;\n};\n\nconst c: any = globalThis.console || {};\n\nexport function getDebug(context: Context, ...tags: [string, any][]) {\n const name = context.name;\n let args: any[];\n\n const make = (method: string, level: number): ((...args: any[]) => void) => {\n if (level < logLevel || !logFilter(name) || !c[method]) return noOp;\n\n // Build and cache the console arguments on the first valid log\n if (!args) {\n let p = \"%c\" + name;\n let s = [`color:${okhash(name)};font-weight:bold`];\n for (const [k, v] of tags) {\n p += `%c[${k}: %c${v}%c]`;\n s.push(\"color:#777\", \"color:#aaa\", \"color:#777\");\n }\n args = [p, ...s];\n }\n\n return c[method].bind(c, ...args);\n };\n\n return {\n get info() {\n return make(\"info\", 1);\n },\n get trace() {\n return make(\"trace\", 1);\n },\n get log() {\n return make(\"log\", 2);\n },\n get warn() {\n return make(\"warn\", 3);\n },\n get error() {\n return make(\"error\", 4);\n },\n };\n}\n\nexport function createDebug(name: string, ...tags: [string, any][]) {\n const context = createContext();\n context.name = name;\n return getDebug(context, ...tags);\n}\n\n/**\n * Takes any string and returns an OKLCH color.\n */\nfunction okhash(value: string) {\n let hue = 0;\n for (let i = 0; i < value.length; i++) {\n hue = (hue + value.charCodeAt(i) * 10) % 360;\n }\n return `oklch(0.68 0.15 ${hue}deg)`;\n}\n","import type { Renderable } from \"../../../types.js\";\nimport { Context } from \"../../context.js\";\nimport { MarkupNode, MountTarget } from \"../types.js\";\nimport { addChild, createTextNode, moveAfter, render } from \"../utils.js\";\n\n/**\n * Renders content into a specified parent node.\n */\nexport class PortalNode extends MarkupNode {\n // Acts as a physical placeholder in the logical DOM tree\n #anchor = createTextNode(\"\");\n\n #context: Context;\n #value: Renderable;\n #parent: MountTarget;\n #childNode?: MarkupNode;\n\n constructor(context: Context, value: Renderable, parent: MountTarget) {\n super();\n this.#context = context;\n this.#value = value;\n this.#parent = parent;\n }\n\n override getRoot() {\n // Return the anchor, allowing siblings to mount correctly around it\n return this.#anchor;\n }\n\n override isMounted() {\n return this.#anchor.parentNode != null;\n }\n\n override mount(logicalParent: MountTarget, after?: Node) {\n if (!this.isMounted()) {\n // Mount the anchor in the standard document flow\n addChild(logicalParent, this.#anchor, after);\n\n // Render the content and mount it to the portal target\n if (!this.#childNode) {\n this.#childNode = render(this.#value, this.#context);\n }\n this.#childNode.mount(this.#parent);\n }\n }\n\n override unmount(skipDOM = false) {\n if (this.isMounted()) {\n if (!skipDOM) {\n this.#anchor.parentNode?.removeChild(this.#anchor);\n }\n\n // Portals always force unmount the DOM of their children\n if (this.#childNode?.isMounted()) {\n this.#childNode.unmount(false);\n }\n }\n }\n\n override move(logicalParent: MountTarget, after?: Node) {\n moveAfter(logicalParent, this.#anchor, after);\n }\n}\n","import type { Renderable } from \"../../../types.js\";\nimport type { Context } from \"../../context.js\";\nimport { batch, type Getter, createAtom, subscribe, type Setter } from \"../../signals.js\";\nimport { scheduleUpdate } from \"../scheduler.js\";\nimport { MarkupNode } from \"../types.js\";\nimport { addChild, createTextNode, render } from \"../utils.js\";\n\n// ----- Types ----- //\n\nexport type Key = any;\n\nexport type KeyFn<T> = (item: T, index: number) => Key;\nexport type RenderFn<T> = (item: Getter<T>, index: Getter<number>) => Renderable;\n\ntype ConnectedItem<T> = {\n _key: Key;\n _item: Getter<T>;\n _setItem: Setter<T>;\n _index: Getter<number>;\n _setIndex: Setter<number>;\n _node: MarkupNode;\n};\n\n// ----- Code ----- //\n\n/**\n * Renders a list of items.\n */\nexport class RepeatNode<T> extends MarkupNode {\n #root = createTextNode(\"\");\n\n #context;\n\n #items: Getter<Iterable<T>>;\n #key: KeyFn<T>;\n #render: RenderFn<T>;\n\n #unsubscribe: (() => void) | null = null;\n #connectedItems: Map<Key, ConnectedItem<T>> = new Map();\n\n constructor(context: Context, items: Getter<Iterable<T>>, key: KeyFn<T>, render: RenderFn<T>) {\n super();\n this.#context = context;\n\n this.#items = items;\n this.#key = key;\n this.#render = render;\n }\n\n override getRoot() {\n return this.#root;\n }\n\n override isMounted() {\n return this.#root.parentNode != null;\n }\n\n override mount(parent: Element, after?: Node) {\n if (!this.isMounted()) {\n addChild(parent, this.#root, after);\n\n this.#unsubscribe = subscribe(this.#items, (items) => {\n scheduleUpdate(() => {\n this._update(Array.from(items));\n });\n });\n }\n }\n\n override unmount(skipDOM = false) {\n if (this.#unsubscribe) {\n this.#unsubscribe();\n this.#unsubscribe = null;\n }\n\n if (!skipDOM && this.isMounted()) {\n this.#root.parentNode?.removeChild(this.#root);\n }\n\n this._cleanup(skipDOM);\n }\n\n override move(parent: Element, after?: Node) {\n // TODO: Implement move\n return this.mount(parent, after);\n }\n\n private _cleanup(skipDOM: boolean) {\n for (const item of this.#connectedItems.values()) {\n item._node.unmount(skipDOM);\n }\n this.#connectedItems.clear();\n }\n\n private _update(value: T[]) {\n if (!this.isMounted()) return;\n\n if (value.length === 0) {\n return this._cleanup(false);\n }\n\n const nextItems = new Map<Key, ConnectedItem<T>>();\n\n batch(() => {\n // Track keys for the incoming list\n const nextKeys = new Set(value.map((item, index) => this.#key(item, index)));\n\n // Unmount deleted items immediately.\n // This collapses the DOM tree so surviving items sit adjacent to each other.\n for (const [key, connected] of this.#connectedItems.entries()) {\n if (!nextKeys.has(key)) {\n connected._node.unmount(false);\n }\n }\n\n // Prepare state and allocate new nodes.\n for (let i = 0; i < value.length; i++) {\n const itemVal = value[i];\n const key = this.#key(itemVal, i);\n let connected = this.#connectedItems.get(key);\n\n if (connected && nextKeys.has(key)) {\n connected._setItem(itemVal);\n connected._setIndex(i);\n } else {\n const [_item, _setItem] = createAtom(itemVal);\n const [_index, _setIndex] = createAtom(i);\n\n const renderContent = this.#render(\n () => _item(),\n () => _index(),\n );\n const _node = render(renderContent, this.#context);\n\n connected = {\n _key: key,\n _node,\n _item,\n _setItem,\n _index,\n _setIndex,\n };\n }\n nextItems.set(key, connected);\n }\n });\n\n this.#connectedItems = nextItems;\n\n // Forward pass to insert or move nodes.\n const parent = this.#root.parentElement!;\n let referenceNode: Node = this.#root;\n\n for (const connected of this.#connectedItems.values()) {\n const expectedNext = referenceNode.nextSibling;\n\n if (!connected._node.isMounted()) {\n // Node is new. Mount it exactly at the current cursor.\n connected._node.mount(parent, referenceNode);\n } else if (connected._node.getRoot() !== expectedNext) {\n // Node is out of order. Move it.\n connected._node.move(parent, referenceNode);\n }\n\n // Advance the cursor.\n referenceNode = connected._node.getRoot()!;\n }\n }\n}\n","import { createMarkup, Renderable } from \"..\";\nimport { isFunction } from \"../../utils\";\nimport { type Getter, compose } from \"../signals\";\nimport { DynamicNode } from \"./nodes/dynamic\";\nimport { PortalNode } from \"./nodes/portal\";\nimport { KeyFn, RenderFn, RepeatNode } from \"./nodes/repeat\";\n\n/**\n * Displays a dynamic list. Items will be added and removed as the list is updated.\n *\n * @param items - List items. Can be reactive.\n * @param keyFn - Takes (item, index) as plain values and returns a unique key to identify that item (usually the item's ID).\n * @param renderFn - Takes (item, index) as Reactive values and returns content to display for that item.\n */\nexport function forEach<T>(\n items: Getter<Iterable<T>> | Iterable<T>,\n keyFn: KeyFn<T>,\n renderFn: RenderFn<T>,\n): Renderable {\n if (isFunction(items)) {\n return createMarkup(RepeatNode<T>, { args: [items, keyFn, renderFn] });\n } else {\n return Array.from(items).map((item, index) =>\n renderFn(\n () => item,\n () => index,\n ),\n );\n }\n}\n\n/**\n * Displays content conditionally. When `condition` is truthy, display `content`. When `condition` is falsy, display `fallback`.\n *\n * @param condition - Condition to hide or show content on. Can be reactive.\n * @param whenTruthy - Content to display when condition is truthy.\n * @param whenFalsy - Content to display when condition is falsy.\n */\nfunction _conditional(condition: any, whenTruthy?: Renderable, whenFalsy?: Renderable): Renderable {\n if (isFunction(condition)) {\n return createMarkup(DynamicNode, {\n args: [compose(() => (condition() ? whenTruthy : whenFalsy))],\n });\n } else if (condition) {\n return whenTruthy;\n } else {\n return whenFalsy;\n }\n}\n\n/**\n * Shows content only when `condition` is truthy.\n * It can be a plain value or a Getter to track dynamically.\n *\n * @param condition - Condition to hide or show content on.\n * @param content - Content to display when condition is truthy.\n * @param fallback - Content to display when condition is falsy.\n */\nexport function showIf(condition: any, content: Renderable, fallback?: Renderable): Renderable {\n return _conditional(condition, content, fallback);\n}\n\n/**\n * Shows content only when `condition` is falsy.\n * It can be a plain value or a Getter to track dynamically.\n *\n * @param condition - Condition to hide or show content on.\n * @param content - Content to display when condition is falsy.\n * @param fallback - Content to display when condition is truthy.\n */\nexport function hideIf(condition: any, content: Renderable, fallback?: Renderable): Renderable {\n return _conditional(condition, fallback, content);\n}\n\n/**\n * Creates a portal that renders `content` into another element on the page.\n **/\nexport function createPortal(parent: Element, content: Renderable) {\n return createMarkup(PortalNode, { args: [content, parent] });\n}\n","// This file is a heavily modified version of the 'htm' library.\n// Original source: https://github.com/developit/htm\n//\n// --- Original htm License ---\n// Copyright 2018 Jason Miller\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { Markup } from \"./types.js\";\nimport { createMarkup } from \"./utils.js\";\n\nexport type Template = Markup | Markup[];\n\nconst enum Mode {\n Slash = 0,\n Text = 1,\n Whitespace = 2,\n TagName = 3,\n Comment = 4,\n PropSet = 5,\n PropAppend = 6,\n}\n\nexport function html(statics: TemplateStringsArray, ...args: any[]): Template {\n const fields = [statics, ...args];\n\n let mode = Mode.Text;\n let buffer = \"\";\n let quote = \"\";\n let current: any[] = [0];\n let propName = \"\";\n\n const commit = (field?: number) => {\n if (mode === Mode.Text && (field || (buffer = buffer.replace(/^\\s*\\n\\s*|\\s*\\n\\s*$/g, \"\")))) {\n current.push(field ? fields[field] : buffer);\n } else if (mode === Mode.TagName && (field || buffer)) {\n current[1] = field ? fields[field] : buffer;\n mode = Mode.Whitespace;\n } else if (mode === Mode.Whitespace && buffer === \"...\" && field) {\n current[2] = Object.assign(current[2] || {}, fields[field]);\n } else if (mode === Mode.Whitespace && buffer && !field) {\n (current[2] = current[2] || {})[buffer] = true;\n } else if (mode >= Mode.PropSet) {\n if (mode === Mode.PropSet) {\n (current[2] = current[2] || {})[propName] = field ? (buffer ? buffer + fields[field] : fields[field]) : buffer;\n mode = Mode.PropAppend;\n } else if (field || buffer) {\n current[2][propName] += field ? buffer + fields[field] : buffer;\n }\n }\n\n buffer = \"\";\n };\n\n for (let i = 0; i < statics.length; i++) {\n if (i) {\n if (mode === Mode.Text) commit();\n commit(i);\n }\n\n for (let j = 0; j < statics[i].length; j++) {\n const char = statics[i][j];\n\n if (mode === Mode.Text) {\n if (char === \"<\") {\n // commit buffer\n commit();\n current = [current, \"\", null];\n mode = Mode.TagName;\n } else {\n buffer += char;\n }\n } else if (mode === Mode.Comment) {\n // Ignore everything until the last three characters are '-', '-' and '>'\n if (buffer === \"--\" && char === \">\") {\n mode = Mode.Text;\n buffer = \"\";\n } else {\n buffer = char + buffer[0];\n }\n } else if (quote) {\n if (char === quote) {\n quote = \"\";\n } else {\n buffer += char;\n }\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === \">\") {\n commit();\n mode = Mode.Text;\n } else if (!mode) {\n // Ignore everything until the tag ends\n } else if (char === \"=\") {\n mode = Mode.PropSet;\n propName = buffer;\n buffer = \"\";\n } else if (char === \"/\" && (mode < Mode.PropSet || statics[i][j + 1] === \">\")) {\n commit();\n if (mode === Mode.TagName) {\n current = current[0];\n }\n const node = current;\n current = current[0];\n\n const type = node[1];\n const props = node[2] || {};\n const children = node.slice(3);\n\n current.push(createMarkup(type, { ...props, children }));\n\n mode = Mode.Slash;\n } else if (char === \" \" || char === \"\\t\" || char === \"\\n\" || char === \"\\r\") {\n // <a disabled>\n commit();\n mode = Mode.Whitespace;\n } else {\n buffer += char;\n }\n\n if (mode === Mode.TagName && buffer === \"!--\") {\n mode = Mode.Comment;\n current = current[0];\n }\n }\n }\n commit();\n\n return current.length > 2 ? current.slice(1) : current[1];\n}\n","import { assert } from \"../utils\";\n\nexport interface Ref<T> {\n /**\n * Call with no arguments to get the stored value.\n * Throws an error if the ref is empty (this means you forgot to pass it or it was called after teardown).\n */\n (): T;\n\n /**\n * Call with an argument to initialize the value. Returns a cleanup function.\n * The cleanup function should clear any references to the DOM node.\n */\n (value: T): () => void;\n}\n\nexport function createRef<T = HTMLElement>(): Ref<T> {\n let currentValue: T | undefined;\n\n return ((...args: [T]) => {\n if (args.length) {\n currentValue = args[0];\n return () => {\n currentValue = undefined;\n };\n } else {\n // assert(currentValue !== undefined, \"Empty ref!\");\n return currentValue;\n }\n }) as Ref<T>;\n}\n"],"mappings":";;;AAiDA,SAAgB,EAAW,GAA0B,GAA4B;CAC/E,IAAM,IAAU,EAAS,EAAO,GAAG,SAAS,cAAc,EAAO,GAAG;AACpE,GAAO,GAAS,0BAA0B;CAE1C,IAAM,IAAU,GAAe;AAC/B,GAAQ,OAAO;CAEf,IAAM,IAAyB,EAAE,EAC3B,IAA6B,EAAE;AAGrC,CADA,EAAQ,KAAkB,GAC1B,EAAQ,KAAS,EAAQ,GAAS;CAElC,IAAI,IAA8B,MAE5B,IAAkB;EAAE;EAAQ;EAAO;EAAS;CAElD,SAAS,EAAO,GAAqB;AAEnC,SADA,EAAQ,KAAK,EAAO,EACb;;CAGT,eAAe,EAAM,GAAgC;AACnD,MAAI,EAAQ,UAAW;EAEvB,IAAM,IAAU,MAAM,QAAQ,IAAI,EAAQ,KAAK,MAAO,EAAG,EAAQ,CAAC,CAAC;AACnE,OAAK,IAAM,KAAU,EACnB,CAAI,EAA4B,EAAO,IACrC,EAAQ,KAAK,EAAO;AAOxB,EAHA,IAAW,EAAqB,EAAQ,GAAG,IAAI,EAAS,GAAS,GAAS,EAAE,CAAC,GAAG,EAAO,GAAS,EAAQ,EACxG,GAAU,MAAM,EAAS,EAEzB,EAAa,EAAQ;;CAGvB,eAAe,IAAU;AAClB,IAAQ,cAEb,GAAU,QAAQ,GAAM,EACxB,IAAW,MAEX,EAAe,EAAQ,EAEvB,MAAM,QAAQ,IAAI,EAAQ,KAAK,MAAa,GAAU,CAAC,CAAC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MAAS,EAAK,QAEvB,CAAI,MAAW,QAAQ,MAAS,OAC9B,IAAO,EAAK,MACZ,IAAS,MAET,IAAS,IAAO,EAAO;YAEhB,EACT,CAAI,MAAS,IACX,IAAQ,KAER,KAAU;YAEH,MAAS,QAAO,MAAS,IAClC,KAAQ;YACC,MAAS,IAElB,CADA,GAAQ,EACR,IAAO,EAAK;YACF,EAAM,KAEP,MAAS,IAGlB,CAFA,IAAO,EAAK,SACZ,IAAW,GACX,IAAS;YACA,MAAS,QAAQ,IAAO,EAAK,WAAW,EAAQ,GAAG,IAAI,OAAO,MAAM;AAE7E,IADA,GAAQ,EACJ,MAAS,EAAK,YAChB,IAAU,EAAQ;IAEpB,IAAM,IAAO;AACb,QAAU,EAAQ;IAElB,IAAM,IAAO,EAAK,IACZ,IAAQ,EAAK,MAAM,EAAE,EACrB,IAAW,EAAK,MAAM,EAAE;AAI9B,IAFA,EAAQ,KAAK,EAAa,GAAM;KAAE,GAAG;KAAO;KAAU,CAAC,CAAC,EAExD,IAAO,EAAK;UACH,MAAS,OAAO,MAAS,OAAQ,MAAS,QAAQ,MAAS,QAEpE,GAAQ,EACR,IAAO,EAAK,cAEZ,KAAU;AAGZ,GAAI,MAAS,EAAK,WAAW,MAAW,UACtC,IAAO,EAAK,SACZ,IAAU,EAAQ;;;AAMxB,QAFA,GAAQ,EAED,EAAQ,SAAS,IAAI,EAAQ,MAAM,EAAE,GAAG,EAAQ;;;;ACtHzD,SAAgB,IAAqC;CACnD,IAAI;AAEJ,UAAS,GAAG,MACN,EAAK,UACP,IAAe,EAAK,UACP;AACX,MAAe,KAAA;MAIV"}
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,45 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* so it's the perfect way to handle things like auth headers and permission checks for API calls.
|
|
4
|
-
*/
|
|
5
|
-
export declare class HTTP {
|
|
6
|
-
#private;
|
|
7
|
-
/**
|
|
8
|
-
* Adds a new middleware that will apply to subsequent requests.
|
|
9
|
-
* Returns a function to remove this middleware.
|
|
10
|
-
*
|
|
11
|
-
* @param middleware - A middleware function that will intercept requests.
|
|
12
|
-
*/
|
|
13
|
-
use(fn: HTTPMiddleware): () => void;
|
|
14
|
-
get<ResBody = unknown>(uri: string, options?: RequestOptions<never>): Promise<HTTPResponse<ResBody>>;
|
|
15
|
-
put<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
16
|
-
patch<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
17
|
-
post<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
18
|
-
delete<ResBody = unknown>(uri: string, options?: RequestOptions<never>): Promise<HTTPResponse<ResBody>>;
|
|
19
|
-
head<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
20
|
-
options<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
21
|
-
trace<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
22
|
-
}
|
|
23
|
-
export type HTTPMiddleware = (request: HTTPRequest<unknown>, next: () => Promise<HTTPResponse<unknown>>) => void | Promise<void>;
|
|
24
|
-
export interface RequestOptions<ReqBody> {
|
|
25
|
-
/**
|
|
26
|
-
* Body to send with the request.
|
|
27
|
-
*/
|
|
1
|
+
export type HTTPMiddleware = (request: HTTPRequest<unknown>, next: () => Promise<HTTPResponse<unknown>>) => Promise<HTTPResponse<unknown> | void> | void;
|
|
2
|
+
export interface RequestOptions<ReqBody, ResBody> {
|
|
28
3
|
body?: ReqBody;
|
|
29
|
-
/**
|
|
30
|
-
* Headers to send with the request.
|
|
31
|
-
*/
|
|
32
4
|
headers?: Record<string, any> | Headers;
|
|
33
|
-
/**
|
|
34
|
-
* Query params to interpolate into the URL.
|
|
35
|
-
*/
|
|
36
5
|
query?: Record<string, any> | URLSearchParams;
|
|
6
|
+
parse?: (response: Response) => Promise<ResBody>;
|
|
7
|
+
signal?: AbortSignal;
|
|
37
8
|
}
|
|
38
9
|
export interface HTTPRequest<Body> {
|
|
39
10
|
method: string;
|
|
40
11
|
url: URL;
|
|
41
12
|
headers: Headers;
|
|
42
13
|
body: Body;
|
|
14
|
+
signal?: AbortSignal;
|
|
43
15
|
}
|
|
44
16
|
export interface HTTPResponse<Body> {
|
|
45
17
|
method: string;
|
|
@@ -53,3 +25,19 @@ export declare class HTTPResponseError extends Error {
|
|
|
53
25
|
response: HTTPResponse<any>;
|
|
54
26
|
constructor(response: HTTPResponse<any>);
|
|
55
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* A simple HTTP client with middleware support.
|
|
30
|
+
*/
|
|
31
|
+
export declare class HTTP {
|
|
32
|
+
#private;
|
|
33
|
+
constructor();
|
|
34
|
+
use(fn: HTTPMiddleware): () => void;
|
|
35
|
+
get<ResBody = unknown>(uri: string, options?: RequestOptions<never, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
36
|
+
put<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
37
|
+
patch<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
38
|
+
post<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
39
|
+
delete<ResBody = unknown>(uri: string, options?: RequestOptions<never, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
40
|
+
head<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
41
|
+
options<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
42
|
+
trace<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
43
|
+
}
|
package/dist/http.js
CHANGED
|
@@ -1,150 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
class
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
else
|
|
87
|
-
throw new TypeError(`Unknown headers type. Got: ${e}`);
|
|
88
|
-
}
|
|
89
|
-
_applyQueryParams(e) {
|
|
90
|
-
if (e != null)
|
|
91
|
-
if (e instanceof Map || e instanceof URLSearchParams)
|
|
92
|
-
e.forEach((t, s) => {
|
|
93
|
-
this.url.searchParams.set(s, t);
|
|
94
|
-
});
|
|
95
|
-
else if (a(e))
|
|
96
|
-
for (const t in e) {
|
|
97
|
-
const s = e[t];
|
|
98
|
-
s instanceof Date ? this.url.searchParams.set(t, s.toISOString()) : s != null && this.url.searchParams.set(t, String(s));
|
|
99
|
-
}
|
|
100
|
-
else
|
|
101
|
-
throw new TypeError(`Unknown query params type. Got: ${e}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
class u {
|
|
105
|
-
_middleware;
|
|
106
|
-
_fetch;
|
|
107
|
-
_request;
|
|
108
|
-
_response;
|
|
109
|
-
constructor(e) {
|
|
110
|
-
this._middleware = e.middleware, this._fetch = e.fetch, this._request = new c(e);
|
|
111
|
-
}
|
|
112
|
-
async fetch() {
|
|
113
|
-
if (this._middleware.length > 0) {
|
|
114
|
-
const e = (t = 0) => {
|
|
115
|
-
const s = this._middleware[t], r = this._middleware[t + 1] ? e(t + 1) : this._handler.bind(this);
|
|
116
|
-
return async () => s(this._request, async () => (await r(), this._response));
|
|
117
|
-
};
|
|
118
|
-
await e()();
|
|
119
|
-
} else
|
|
120
|
-
await this._handler();
|
|
121
|
-
if (this._response.status < 200 || this._response.status >= 400)
|
|
122
|
-
throw new l(this._response);
|
|
123
|
-
return this._response;
|
|
124
|
-
}
|
|
125
|
-
// This is the function that performs the actual request after the final middleware.
|
|
126
|
-
async _handler() {
|
|
127
|
-
let e;
|
|
128
|
-
const t = this._request;
|
|
129
|
-
!t.headers.has("content-type") && a(t.body) ? (t.headers.set("content-type", "application/json"), e = JSON.stringify(t.body)) : e = t.body;
|
|
130
|
-
const s = await this._fetch(t.url.toString(), {
|
|
131
|
-
method: t.method,
|
|
132
|
-
headers: t.headers,
|
|
133
|
-
body: e
|
|
134
|
-
}), r = s.headers.get("content-type");
|
|
135
|
-
let n;
|
|
136
|
-
r?.includes("application/json") ? n = await s.json() : r?.includes("application/x-www-form-urlencoded") ? n = await s.formData() : n = await s.text(), this._response = {
|
|
137
|
-
method: t.method,
|
|
138
|
-
url: t.url,
|
|
139
|
-
status: s.status,
|
|
140
|
-
statusText: s.statusText,
|
|
141
|
-
headers: s.headers,
|
|
142
|
-
body: n
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
export {
|
|
147
|
-
p as HTTP,
|
|
148
|
-
l as HTTPResponseError
|
|
1
|
+
//#region src/http/index.ts
|
|
2
|
+
var e = class extends Error {
|
|
3
|
+
response;
|
|
4
|
+
constructor(e) {
|
|
5
|
+
super(`${e.status} ${e.statusText}: Request failed (${e.method.toUpperCase()} ${e.url.toString()})`), this.response = e;
|
|
6
|
+
}
|
|
7
|
+
}, t = class {
|
|
8
|
+
#e = [];
|
|
9
|
+
#t = typeof window < "u" && window.fetch ? window.fetch.bind(window) : typeof global < "u" && global.fetch ? global.fetch.bind(global) : null;
|
|
10
|
+
constructor() {
|
|
11
|
+
if (!this.#t) throw Error("Fetch API not found. Unsupported environment.");
|
|
12
|
+
}
|
|
13
|
+
use(e) {
|
|
14
|
+
return this.#e.push(e), () => {
|
|
15
|
+
this.#e = this.#e.filter((t) => t !== e);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async get(e, t) {
|
|
19
|
+
return this.#n("GET", e, t);
|
|
20
|
+
}
|
|
21
|
+
async put(e, t) {
|
|
22
|
+
return this.#n("PUT", e, t);
|
|
23
|
+
}
|
|
24
|
+
async patch(e, t) {
|
|
25
|
+
return this.#n("PATCH", e, t);
|
|
26
|
+
}
|
|
27
|
+
async post(e, t) {
|
|
28
|
+
return this.#n("POST", e, t);
|
|
29
|
+
}
|
|
30
|
+
async delete(e, t) {
|
|
31
|
+
return this.#n("DELETE", e, t);
|
|
32
|
+
}
|
|
33
|
+
async head(e, t) {
|
|
34
|
+
return this.#n("HEAD", e, t);
|
|
35
|
+
}
|
|
36
|
+
async options(e, t) {
|
|
37
|
+
return this.#n("OPTIONS", e, t);
|
|
38
|
+
}
|
|
39
|
+
async trace(e, t) {
|
|
40
|
+
return this.#n("TRACE", e, t);
|
|
41
|
+
}
|
|
42
|
+
async #n(t, n, r = {}) {
|
|
43
|
+
let i = typeof window < "u" ? window.location.origin : "http://localhost", a = new URL(n, n.startsWith("http") ? void 0 : i);
|
|
44
|
+
if (r.query) if (r.query instanceof URLSearchParams) r.query.forEach((e, t) => a.searchParams.set(t, e));
|
|
45
|
+
else for (let [e, t] of Object.entries(r.query)) t != null && a.searchParams.set(e, t instanceof Date ? t.toISOString() : String(t));
|
|
46
|
+
let o = new Headers(r.headers), s = r.body, c = s && typeof s == "object" && s.constructor === Object;
|
|
47
|
+
!o.has("content-type") && (c || Array.isArray(s)) && (o.set("content-type", "application/json"), s = JSON.stringify(s));
|
|
48
|
+
let l = {
|
|
49
|
+
method: t,
|
|
50
|
+
url: a,
|
|
51
|
+
headers: o,
|
|
52
|
+
body: t === "GET" || t === "HEAD" ? void 0 : s,
|
|
53
|
+
signal: r.signal
|
|
54
|
+
}, u = -1, d = async (t) => {
|
|
55
|
+
if (t <= u) throw Error("next() called multiple times");
|
|
56
|
+
u = t;
|
|
57
|
+
let n = this.#e[t];
|
|
58
|
+
if (n) {
|
|
59
|
+
let e;
|
|
60
|
+
return await n(l, async () => (e = await d(t + 1), e)), e;
|
|
61
|
+
}
|
|
62
|
+
let i = await this.#t(l.url.toString(), {
|
|
63
|
+
method: l.method,
|
|
64
|
+
headers: l.headers,
|
|
65
|
+
body: l.body,
|
|
66
|
+
signal: l.signal
|
|
67
|
+
}), a;
|
|
68
|
+
if (r.parse) a = await r.parse(i);
|
|
69
|
+
else {
|
|
70
|
+
let e = i.headers.get("content-type") || "";
|
|
71
|
+
a = e.includes("json") ? await i.json() : e.includes("form") ? await i.formData() : await i.text();
|
|
72
|
+
}
|
|
73
|
+
let o = {
|
|
74
|
+
method: l.method,
|
|
75
|
+
url: l.url,
|
|
76
|
+
status: i.status,
|
|
77
|
+
statusText: i.statusText,
|
|
78
|
+
headers: i.headers,
|
|
79
|
+
body: a
|
|
80
|
+
};
|
|
81
|
+
if (!i.ok) throw new e(o);
|
|
82
|
+
return o;
|
|
83
|
+
};
|
|
84
|
+
return d(0);
|
|
85
|
+
}
|
|
149
86
|
};
|
|
150
|
-
//#
|
|
87
|
+
//#endregion
|
|
88
|
+
export { t as HTTP, e as HTTPResponseError };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=http.js.map
|