@manyducks.co/dolla 2.0.0-alpha.8 → 2.0.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 +222 -512
- package/dist/core/app.d.ts +24 -0
- package/dist/core/context.d.ts +147 -0
- package/dist/core/env.d.ts +3 -0
- package/dist/core/hooks.d.ts +70 -0
- package/dist/core/hooks.test.d.ts +1 -0
- package/dist/core/index.d.ts +25 -0
- package/dist/core/logger.d.ts +42 -0
- package/dist/core/logger.test.d.ts +0 -0
- package/dist/core/markup.d.ts +82 -0
- package/dist/core/markup.test.d.ts +0 -0
- package/dist/core/nodes/_markup.d.ts +36 -0
- package/dist/core/nodes/dom.d.ts +13 -0
- package/dist/core/nodes/dynamic.d.ts +22 -0
- package/dist/core/nodes/element.d.ts +27 -0
- package/dist/core/nodes/portal.d.ts +18 -0
- package/dist/core/nodes/repeat.d.ts +27 -0
- package/dist/core/nodes/view.d.ts +25 -0
- package/dist/core/ref.d.ts +19 -0
- package/dist/core/ref.test.d.ts +1 -0
- package/dist/core/signals.d.ts +100 -0
- package/dist/core/signals.test.d.ts +1 -0
- package/dist/{views → core/views}/default-crash-view.d.ts +11 -4
- package/dist/core/views/for.d.ts +21 -0
- package/dist/core/views/fragment.d.ts +7 -0
- package/dist/core/views/portal.d.ts +16 -0
- package/dist/core/views/show.d.ts +25 -0
- package/dist/fragment-BahD_BJA.js +7 -0
- package/dist/fragment-BahD_BJA.js.map +1 -0
- package/dist/{modules/http.d.ts → http/index.d.ts} +3 -5
- package/dist/http.js +150 -0
- package/dist/http.js.map +1 -0
- package/dist/i18n/index.d.ts +134 -0
- package/dist/i18n.js +309 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index-DRJlxs-Q.js +535 -0
- package/dist/index-DRJlxs-Q.js.map +1 -0
- package/dist/index.js +160 -1386
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +3 -2
- package/dist/jsx-dev-runtime.js +5 -12
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +4 -3
- package/dist/jsx-runtime.js +9 -15
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/logger-Aqi9m1CF.js +565 -0
- package/dist/logger-Aqi9m1CF.js.map +1 -0
- package/dist/markup-8jNhoqDe.js +1089 -0
- package/dist/markup-8jNhoqDe.js.map +1 -0
- package/dist/router/hooks.d.ts +2 -0
- package/dist/router/index.d.ts +3 -0
- package/dist/router/router.d.ts +166 -0
- package/dist/{routing.d.ts → router/router.utils.d.ts} +17 -3
- package/dist/router/router.utils.test.d.ts +1 -0
- package/dist/router.js +6 -0
- package/dist/router.js.map +1 -0
- package/dist/typeChecking-5kmX0ulW.js +65 -0
- package/dist/typeChecking-5kmX0ulW.js.map +1 -0
- package/dist/typeChecking.d.ts +2 -98
- package/dist/typeChecking.test.d.ts +1 -0
- package/dist/types.d.ts +97 -25
- package/dist/utils.d.ts +25 -3
- package/docs/buildless.md +132 -0
- package/docs/components.md +238 -0
- package/docs/hooks.md +356 -0
- package/docs/http.md +178 -0
- package/docs/i18n.md +220 -0
- package/docs/index.md +10 -0
- package/docs/markup.md +136 -0
- package/docs/mixins.md +176 -0
- package/docs/ref.md +77 -0
- package/docs/router.md +281 -0
- package/docs/setup.md +137 -0
- package/docs/signals.md +262 -0
- package/docs/stores.md +113 -0
- package/docs/views.md +356 -0
- package/index.d.ts +2 -2
- package/notes/atomic.md +452 -0
- package/notes/elimination.md +33 -0
- package/notes/observable.md +180 -0
- package/notes/scratch.md +350 -18
- package/notes/splitting.md +5 -0
- package/package.json +29 -15
- package/vite.config.js +5 -11
- package/build.js +0 -34
- package/dist/index.d.ts +0 -21
- package/dist/markup.d.ts +0 -108
- package/dist/modules/dolla.d.ts +0 -111
- package/dist/modules/language.d.ts +0 -41
- package/dist/modules/render.d.ts +0 -17
- package/dist/modules/router.d.ts +0 -152
- package/dist/nodes/cond.d.ts +0 -26
- package/dist/nodes/html.d.ts +0 -31
- package/dist/nodes/observer.d.ts +0 -29
- package/dist/nodes/outlet.d.ts +0 -22
- package/dist/nodes/portal.d.ts +0 -19
- package/dist/nodes/repeat.d.ts +0 -34
- package/dist/nodes/text.d.ts +0 -19
- package/dist/passthrough-9kwwjgWk.js +0 -1279
- package/dist/passthrough-9kwwjgWk.js.map +0 -1
- package/dist/state.d.ts +0 -101
- package/dist/view.d.ts +0 -65
- package/dist/views/passthrough.d.ts +0 -5
- package/notes/context-vars.md +0 -21
- package/notes/readme-scratch.md +0 -222
- package/notes/route-middleware.md +0 -42
- package/tests/state.test.js +0 -135
- /package/dist/{routing.test.d.ts → core/context.test.d.ts} +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Context } from "./context";
|
|
2
|
+
export declare function getCurrentContext(): Context | undefined;
|
|
3
|
+
export declare function setCurrentContext(context: Context | undefined): Context | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* A function that returns the current value of a signal.
|
|
6
|
+
* Automatically tracked as a dependency when called within a tracking scope (such as `memo` or `effect` functions).
|
|
7
|
+
*/
|
|
8
|
+
export interface Signal<T> {
|
|
9
|
+
(): T;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A function that sets the value of the signal.
|
|
13
|
+
*/
|
|
14
|
+
export interface Setter<T> {
|
|
15
|
+
(value: T | ((previousValue: T) => T)): void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A getter and setter in a single object. Callable like a getter, but includes a `set` method for updating the signal's value.
|
|
19
|
+
*/
|
|
20
|
+
export interface Writable<T> extends Signal<T> {
|
|
21
|
+
set: Setter<T>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Utility type for a value that may be a getter or a plain value.
|
|
25
|
+
* This value can be unwrapped to a plain value with `get` or `untracked` (depending on whether you're in a tracking context and need to track it).
|
|
26
|
+
*/
|
|
27
|
+
export type MaybeSignal<T> = Signal<T> | T;
|
|
28
|
+
export type EqualityFn<T> = (previousValue: T, nextValue: T) => boolean;
|
|
29
|
+
export interface SignalOptions<T> {
|
|
30
|
+
/**
|
|
31
|
+
* A function to compare the current and next values. Returning `true` means the value has changed.
|
|
32
|
+
*/
|
|
33
|
+
equals?: EqualityFn<T>;
|
|
34
|
+
}
|
|
35
|
+
export declare function writable<T>(): Writable<T | undefined>;
|
|
36
|
+
export declare function writable<T>(initialValue: undefined, options: SignalOptions<T | undefined>): Writable<T | undefined>;
|
|
37
|
+
export declare function writable<T>(initialValue: T, options?: SignalOptions<T>): Writable<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Ensures that a value is a read-only signal.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const $number = readable(5); // converts plain values to signals
|
|
43
|
+
*
|
|
44
|
+
* const $number = writable(5);
|
|
45
|
+
* const $value = readable($number);
|
|
46
|
+
* $number(); // 5
|
|
47
|
+
* $value(); // 5
|
|
48
|
+
* $number.set(6);
|
|
49
|
+
* $number(); // 6
|
|
50
|
+
* $value(); // 6 (tracks value but can't be written)
|
|
51
|
+
*/
|
|
52
|
+
export declare function readable<T>(signal: MaybeSignal<T>): Signal<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new signal, returning a getter and setter pair.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const [$count, setCount] = signal(0);
|
|
58
|
+
*/
|
|
59
|
+
export declare function signal<T>(initialValue: T, options?: SignalOptions<T>): [Signal<T>, Setter<T>];
|
|
60
|
+
export declare function signal<T>(initialValue: undefined, options: SignalOptions<T>): [Signal<T | undefined>, Setter<T | undefined>];
|
|
61
|
+
export declare function signal<T>(): [Signal<T | undefined>, Setter<T | undefined>];
|
|
62
|
+
export interface MemoOptions<T> extends SignalOptions<T> {
|
|
63
|
+
/**
|
|
64
|
+
* An array of signals this `memo` depends on. If this is passed, calls to signals within `fn` will NOT be tracked.
|
|
65
|
+
* Instead the `deps` array will be tracked and `fn` will re-run when any value in `deps` changes.
|
|
66
|
+
*/
|
|
67
|
+
deps?: Signal<any>[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates a derived signal that recomputes its value only when its dependencies change.
|
|
71
|
+
* Subsequent calls will return a cached value.
|
|
72
|
+
* Dependencies are tracked when called inside `fn` by default,
|
|
73
|
+
* but can be overridden by passing a `deps` array in the options object.
|
|
74
|
+
*/
|
|
75
|
+
export declare function memo<T>(compute: (previousValue?: T) => MaybeSignal<T>, options?: MemoOptions<T>): Signal<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Suspends effects during `fn`. Effects for all updated Signal values are called at the end of the batch.
|
|
78
|
+
*/
|
|
79
|
+
export declare function batch(fn: () => void): void;
|
|
80
|
+
/**
|
|
81
|
+
* Call a Signal function without tracking its value.
|
|
82
|
+
*/
|
|
83
|
+
export declare function untracked<T>(value: MaybeSignal<T>): T;
|
|
84
|
+
/**
|
|
85
|
+
* Unwraps the plain value from a Signal. If the value is not a Signal it is returned as-is.
|
|
86
|
+
*/
|
|
87
|
+
export declare function get<T>(value: MaybeSignal<T>): T;
|
|
88
|
+
/**
|
|
89
|
+
* Function to be invoked for the effect. Can return an optional cleanup function to be called between invocations.
|
|
90
|
+
*/
|
|
91
|
+
export type EffectFn = () => void | (() => void);
|
|
92
|
+
export type UnsubscribeFn = () => void;
|
|
93
|
+
/**
|
|
94
|
+
* Creates a tracked scope that re-runs whenever the values of any tracked reactives changes.
|
|
95
|
+
* Reactives are tracked by accessing their `value` within the body of the function.
|
|
96
|
+
*
|
|
97
|
+
* NOTE: You must call the unsubscribe function to clean up the effect.
|
|
98
|
+
* If you are using an effect inside a View or Store, try the `useEffect` hook instead, which cleans up automatically when the component unmounts.
|
|
99
|
+
*/
|
|
100
|
+
export declare function effect(fn: EffectFn): UnsubscribeFn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Props passed to the crash view when a crash occurs.
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export interface CrashViewProps {
|
|
5
5
|
/**
|
|
6
6
|
* JavaScript Error object.
|
|
7
7
|
*/
|
|
@@ -13,6 +13,13 @@ export type CrashViewProps = {
|
|
|
13
13
|
/**
|
|
14
14
|
* Unique identifier to pinpoint the specific view that reported the crash.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
tag?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Label for the tag.
|
|
19
|
+
*/
|
|
20
|
+
tagName?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The crash view displayed unless you specify your own.
|
|
24
|
+
*/
|
|
25
|
+
export declare function DefaultCrashView(props: CrashViewProps): import("../markup.js").Markup<string | import("../index.js").View<any>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Key, RenderFn, RepeatNode } from "../nodes/repeat";
|
|
2
|
+
import { type MaybeSignal } from "../signals";
|
|
3
|
+
export interface ForProps<T> {
|
|
4
|
+
/**
|
|
5
|
+
* An array of items to render.
|
|
6
|
+
*/
|
|
7
|
+
each: MaybeSignal<T[]>;
|
|
8
|
+
/**
|
|
9
|
+
* A function to extract a unique key that identifies each item.
|
|
10
|
+
* If no `key` function is passed, object identity (===) will be used.
|
|
11
|
+
*/
|
|
12
|
+
key?: (item: T, index: number) => Key;
|
|
13
|
+
/**
|
|
14
|
+
* A render function. Takes the item and its index in signal form and returns something to display for each item.
|
|
15
|
+
*/
|
|
16
|
+
children: RenderFn<T>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export declare function For<T>(props: ForProps<T>): RepeatNode<T>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Renderable } from "../../types";
|
|
2
|
+
import { Markup, MarkupType } from "../markup";
|
|
3
|
+
export interface PortalProps {
|
|
4
|
+
/**
|
|
5
|
+
* The parent element or a selector that will match it.
|
|
6
|
+
*/
|
|
7
|
+
into: Element | string;
|
|
8
|
+
/**
|
|
9
|
+
* Content to render inside the `into` element.
|
|
10
|
+
*/
|
|
11
|
+
children: Renderable;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Render content into any element on the page.
|
|
15
|
+
*/
|
|
16
|
+
export declare function Portal(props: PortalProps): Markup<MarkupType.Portal>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Renderable } from "../../types";
|
|
2
|
+
import { DynamicNode } from "../nodes/dynamic";
|
|
3
|
+
import { type MaybeSignal } from "../signals";
|
|
4
|
+
export interface ShowProps {
|
|
5
|
+
/**
|
|
6
|
+
* If present, children will be rendered only when this signal holds a truthy value.
|
|
7
|
+
*/
|
|
8
|
+
when?: MaybeSignal<any>;
|
|
9
|
+
/**
|
|
10
|
+
* If present, children will be rendered only when this signal holds a falsy value.
|
|
11
|
+
*/
|
|
12
|
+
unless?: MaybeSignal<any>;
|
|
13
|
+
/**
|
|
14
|
+
* Content to render if conditions permit.
|
|
15
|
+
*/
|
|
16
|
+
children: Renderable;
|
|
17
|
+
/**
|
|
18
|
+
* Content to render when conditions don't permit `children` to render.
|
|
19
|
+
*/
|
|
20
|
+
fallback?: Renderable;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Conditionally display children.
|
|
24
|
+
*/
|
|
25
|
+
export declare function Show(props: ShowProps): DynamicNode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fragment-BahD_BJA.js","sources":["../src/core/views/fragment.ts"],"sourcesContent":["import type { Renderable } from \"../../types.js\";\n\n/**\n * A utility view that displays its children.\n */\nexport function Fragment(props: { children?: Renderable }) {\n return props.children;\n}\n"],"names":["Fragment","props"],"mappings":"AAKO,SAASA,EAASC,GAAkC;AACzD,SAAOA,EAAM;AACf;"}
|
|
@@ -37,18 +37,16 @@ export interface RequestOptions<ReqBody> {
|
|
|
37
37
|
}
|
|
38
38
|
export interface HTTPRequest<Body> {
|
|
39
39
|
method: string;
|
|
40
|
-
|
|
41
|
-
readonly sameOrigin: boolean;
|
|
40
|
+
url: URL;
|
|
42
41
|
headers: Headers;
|
|
43
|
-
query: URLSearchParams;
|
|
44
42
|
body: Body;
|
|
45
43
|
}
|
|
46
44
|
export interface HTTPResponse<Body> {
|
|
47
45
|
method: string;
|
|
48
|
-
|
|
46
|
+
url: URL;
|
|
47
|
+
headers: Headers;
|
|
49
48
|
status: number;
|
|
50
49
|
statusText: string;
|
|
51
|
-
headers: Record<string, string>;
|
|
52
50
|
body: Body;
|
|
53
51
|
}
|
|
54
52
|
export declare class HTTPResponseError extends Error {
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { a } from "./typeChecking-5kmX0ulW.js";
|
|
2
|
+
class p {
|
|
3
|
+
#t = [];
|
|
4
|
+
#s = h();
|
|
5
|
+
/**
|
|
6
|
+
* Adds a new middleware that will apply to subsequent requests.
|
|
7
|
+
* Returns a function to remove this middleware.
|
|
8
|
+
*
|
|
9
|
+
* @param middleware - A middleware function that will intercept requests.
|
|
10
|
+
*/
|
|
11
|
+
use(e) {
|
|
12
|
+
return this.#t.push(e), () => {
|
|
13
|
+
this.#t.splice(this.#t.indexOf(e), 1);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async get(e, t) {
|
|
17
|
+
return this.#e("get", e, t);
|
|
18
|
+
}
|
|
19
|
+
async put(e, t) {
|
|
20
|
+
return this.#e("put", e, t);
|
|
21
|
+
}
|
|
22
|
+
async patch(e, t) {
|
|
23
|
+
return this.#e("patch", e, t);
|
|
24
|
+
}
|
|
25
|
+
async post(e, t) {
|
|
26
|
+
return this.#e("post", e, t);
|
|
27
|
+
}
|
|
28
|
+
async delete(e, t) {
|
|
29
|
+
return this.#e("delete", e, t);
|
|
30
|
+
}
|
|
31
|
+
async head(e, t) {
|
|
32
|
+
return this.#e("head", e, t);
|
|
33
|
+
}
|
|
34
|
+
async options(e, t) {
|
|
35
|
+
return this.#e("options", e, t);
|
|
36
|
+
}
|
|
37
|
+
async trace(e, t) {
|
|
38
|
+
return this.#e("trace", e, t);
|
|
39
|
+
}
|
|
40
|
+
async #e(e, t, s) {
|
|
41
|
+
return new u({
|
|
42
|
+
...s,
|
|
43
|
+
method: e,
|
|
44
|
+
uri: t,
|
|
45
|
+
middleware: this.#t,
|
|
46
|
+
fetch: this.#s
|
|
47
|
+
}).fetch();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function h() {
|
|
51
|
+
if (typeof window < "u" && window.fetch)
|
|
52
|
+
return window.fetch.bind(window);
|
|
53
|
+
if (typeof global < "u" && global.fetch)
|
|
54
|
+
return global.fetch.bind(global);
|
|
55
|
+
throw new Error("Running in neither browser nor node. Please run this app in one of the supported environments.");
|
|
56
|
+
}
|
|
57
|
+
class l extends Error {
|
|
58
|
+
response;
|
|
59
|
+
constructor(e) {
|
|
60
|
+
const { status: t, statusText: s, method: r, url: n } = e, o = `${t} ${s}: Request failed (${r.toUpperCase()} ${n.toString()})`;
|
|
61
|
+
super(o), this.response = e;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
class c {
|
|
65
|
+
method;
|
|
66
|
+
url;
|
|
67
|
+
headers = new Headers();
|
|
68
|
+
body;
|
|
69
|
+
get isSameOrigin() {
|
|
70
|
+
return this.url.origin === window.location.origin;
|
|
71
|
+
}
|
|
72
|
+
constructor(e) {
|
|
73
|
+
this.method = e.method, this.body = e.body, e.uri.startsWith("http") ? this.url = new URL(e.uri) : this.url = new URL(e.uri, window.location.origin), this._applyHeaders(e.headers), this._applyQueryParams(e.query);
|
|
74
|
+
}
|
|
75
|
+
_applyHeaders(e) {
|
|
76
|
+
if (e != null)
|
|
77
|
+
if (e instanceof Map || e instanceof Headers)
|
|
78
|
+
e.forEach((t, s) => {
|
|
79
|
+
this.headers.set(s, t);
|
|
80
|
+
});
|
|
81
|
+
else if (a(e))
|
|
82
|
+
for (const t in e) {
|
|
83
|
+
const s = e[t];
|
|
84
|
+
s instanceof Date ? this.headers.set(t, s.toISOString()) : s != null && this.headers.set(t, String(s));
|
|
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
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sources":["../src/http/index.ts"],"sourcesContent":["import { isObject } from \"../typeChecking.js\";\n\n/**\n * A simple HTTP client with middleware support. Middleware applies to all requests made through this store,\n * so it's the perfect way to handle things like auth headers and permission checks for API calls.\n */\nexport class HTTP {\n #middleware: HTTPMiddleware[] = [];\n #fetch = getDefaultFetch();\n\n /**\n * Adds a new middleware that will apply to subsequent requests.\n * Returns a function to remove this middleware.\n *\n * @param middleware - A middleware function that will intercept requests.\n */\n use(fn: HTTPMiddleware) {\n this.#middleware.push(fn);\n\n // Call returned function to remove this middleware for subsequent requests.\n return () => {\n this.#middleware.splice(this.#middleware.indexOf(fn), 1);\n };\n }\n\n async get<ResBody = unknown>(uri: string, options?: RequestOptions<never>) {\n return this.#request<ResBody, never>(\"get\", uri, options);\n }\n\n async put<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"put\", uri, options);\n }\n\n async patch<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"patch\", uri, options);\n }\n\n async post<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"post\", uri, options);\n }\n\n async delete<ResBody = unknown>(uri: string, options?: RequestOptions<never>) {\n return this.#request<ResBody, never>(\"delete\", uri, options);\n }\n\n async head<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"head\", uri, options);\n }\n\n async options<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"options\", uri, options);\n }\n\n async trace<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"trace\", uri, options);\n }\n\n async #request<ResBody, ReqBody>(method: string, uri: string, options?: RequestOptions<any>) {\n const runner = new Runner<ResBody, ReqBody>({\n ...options,\n method,\n uri,\n middleware: this.#middleware,\n fetch: this.#fetch,\n });\n return runner.fetch();\n }\n}\n\nfunction getDefaultFetch(): typeof window.fetch {\n if (typeof window !== \"undefined\" && window.fetch) {\n return window.fetch.bind(window);\n }\n\n if (typeof global !== \"undefined\" && global.fetch) {\n return global.fetch.bind(global);\n }\n\n throw new Error(\"Running in neither browser nor node. Please run this app in one of the supported environments.\");\n}\n\n/*====================*\\\n|| Request ||\n\\*====================*/\n\nexport type HTTPMiddleware = (\n request: HTTPRequest<unknown>,\n next: () => Promise<HTTPResponse<unknown>>,\n) => void | Promise<void>;\n\nexport interface RequestOptions<ReqBody> {\n /**\n * Body to send with the request.\n */\n body?: ReqBody;\n\n /**\n * Headers to send with the request.\n */\n headers?: Record<string, any> | Headers;\n\n /**\n * Query params to interpolate into the URL.\n */\n query?: Record<string, any> | URLSearchParams;\n}\n\nexport interface HTTPRequest<Body> {\n method: string;\n url: URL;\n headers: Headers;\n body: Body;\n}\n\nexport interface HTTPResponse<Body> {\n method: string;\n url: URL;\n headers: Headers;\n status: number;\n statusText: string;\n body: Body;\n}\n\ninterface MakeRequestConfig<ReqBody> extends RequestOptions<ReqBody> {\n method: string;\n uri: string;\n middleware: HTTPMiddleware[];\n fetch: typeof window.fetch;\n}\n\nexport class HTTPResponseError extends Error {\n response;\n\n constructor(response: HTTPResponse<any>) {\n const { status, statusText, method, url } = response;\n const message = `${status} ${statusText}: Request failed (${method.toUpperCase()} ${url.toString()})`;\n\n super(message);\n\n this.response = response;\n }\n}\n\nclass Request<ReqBody> implements HTTPRequest<ReqBody> {\n method: string;\n url: URL;\n headers = new Headers();\n body!: ReqBody;\n\n get isSameOrigin() {\n return this.url.origin === window.location.origin;\n }\n\n constructor(config: MakeRequestConfig<ReqBody>) {\n this.method = config.method;\n this.body = config.body!;\n if (config.uri.startsWith(\"http\")) {\n this.url = new URL(config.uri);\n } else {\n this.url = new URL(config.uri, window.location.origin);\n }\n\n this._applyHeaders(config.headers);\n this._applyQueryParams(config.query);\n }\n\n private _applyHeaders(headers: any) {\n if (headers == null) return;\n\n if (headers instanceof Map || headers instanceof Headers) {\n headers.forEach((value, key) => {\n this.headers.set(key, value);\n });\n } else if (isObject(headers)) {\n for (const name in headers) {\n const value = headers[name];\n if (value instanceof Date) {\n this.headers.set(name, value.toISOString());\n } else if (value != null) {\n this.headers.set(name, String(value));\n }\n }\n } else {\n throw new TypeError(`Unknown headers type. Got: ${headers}`);\n }\n }\n\n private _applyQueryParams(query: any) {\n if (query == null) return;\n\n if (query instanceof Map || query instanceof URLSearchParams) {\n query.forEach((value, key) => {\n this.url.searchParams.set(key, value);\n });\n } else if (isObject(query)) {\n for (const name in query) {\n const value = query[name];\n if (value instanceof Date) {\n this.url.searchParams.set(name, value.toISOString());\n } else if (value != null) {\n this.url.searchParams.set(name, String(value));\n }\n }\n } else {\n throw new TypeError(`Unknown query params type. Got: ${query}`);\n }\n }\n}\n\nclass Runner<ResBody, ReqBody> {\n private _middleware;\n private _fetch;\n\n private _request: Request<ReqBody>;\n private _response?: HTTPResponse<ResBody>;\n\n constructor(config: MakeRequestConfig<ReqBody>) {\n this._middleware = config.middleware;\n this._fetch = config.fetch;\n\n this._request = new Request(config);\n }\n\n async fetch() {\n if (this._middleware.length > 0) {\n const mount = (index = 0) => {\n const current = this._middleware[index];\n const next = this._middleware[index + 1] ? mount(index + 1) : this._handler.bind(this);\n\n return async () =>\n current(this._request, async () => {\n await next();\n return this._response!;\n });\n };\n\n await mount()();\n } else {\n await this._handler();\n }\n\n if (this._response!.status < 200 || this._response!.status >= 400) {\n throw new HTTPResponseError(this._response!);\n }\n\n return this._response!;\n }\n\n // This is the function that performs the actual request after the final middleware.\n private async _handler() {\n let reqBody: BodyInit;\n\n const req = this._request;\n\n if (!req.headers.has(\"content-type\") && isObject(req.body)) {\n // Auto-detect JSON bodies and encode as a string with correct headers.\n req.headers.set(\"content-type\", \"application/json\");\n reqBody = JSON.stringify(req.body);\n } else {\n reqBody = req.body as BodyInit;\n }\n\n const fetched = await this._fetch(req.url.toString(), {\n method: req.method,\n headers: req.headers,\n body: reqBody,\n });\n\n // Auto-parse response body based on content-type header\n const contentType = fetched.headers.get(\"content-type\");\n\n let body: ResBody;\n\n if (contentType?.includes(\"application/json\")) {\n body = await fetched.json();\n } else if (contentType?.includes(\"application/x-www-form-urlencoded\")) {\n body = (await fetched.formData()) as ResBody;\n } else {\n body = (await fetched.text()) as ResBody;\n }\n\n this._response = {\n method: req.method,\n url: req.url,\n status: fetched.status,\n statusText: fetched.statusText,\n headers: fetched.headers,\n body,\n };\n }\n}\n"],"names":["HTTP","#middleware","#fetch","getDefaultFetch","fn","uri","options","#request","method","Runner","HTTPResponseError","response","status","statusText","url","message","Request","config","headers","value","key","isObject","name","query","mount","index","current","next","reqBody","req","fetched","contentType","body"],"mappings":";AAMO,MAAMA,EAAK;AAAA,EAChBC,KAAgC,CAAA;AAAA,EAChCC,KAASC,EAAA;AAAA;AAAA;A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AMH,IAAM;AAAA,IACd;AACE,YAAM,KAAK,SAAA;AAGb,QAAI,KAAK,UAAW,SAAS,OAAO,KAAK,UAAW,UAAU;AAC5D,YAAM,IAAId,EAAkB,KAAK,SAAU;AAG7C,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,MAAc,WAAW;AACvB,QAAIkB;AAEJ,UAAMC,IAAM,KAAK;AAEjB,IAAI,CAACA,EAAI,QAAQ,IAAI,cAAc,KAAKR,EAASQ,EAAI,IAAI,KAEvDA,EAAI,QAAQ,IAAI,gBAAgB,kBAAkB,GAClDD,IAAU,KAAK,UAAUC,EAAI,IAAI,KAEjCD,IAAUC,EAAI;AAGhB,UAAMC,IAAU,MAAM,KAAK,OAAOD,EAAI,IAAI,YAAY;AAAA,MACpD,QAAQA,EAAI;AAAA,MACZ,SAASA,EAAI;AAAA,MACb,MAAMD;AAAA,IAAA,CACP,GAGKG,IAAcD,EAAQ,QAAQ,IAAI,cAAc;AAEtD,QAAIE;AAEJ,IAAID,GAAa,SAAS,kBAAkB,IAC1CC,IAAO,MAAMF,EAAQ,KAAA,IACZC,GAAa,SAAS,mCAAmC,IAClEC,IAAQ,MAAMF,EAAQ,SAAA,IAEtBE,IAAQ,MAAMF,EAAQ,KAAA,GAGxB,KAAK,YAAY;AAAA,MACf,QAAQD,EAAI;AAAA,MACZ,KAAKA,EAAI;AAAA,MACT,QAAQC,EAAQ;AAAA,MAChB,YAAYA,EAAQ;AAAA,MACpB,SAASA,EAAQ;AAAA,MACjB,MAAAE;AAAA,IAAA;AAAA,EAEJ;AACF;"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { type MaybeSignal, type Signal } from "../core/signals.js";
|
|
2
|
+
/**
|
|
3
|
+
* A JSON object of translated strings. Values can be string templates or nested objects.
|
|
4
|
+
*/
|
|
5
|
+
interface LocalizedStrings extends Record<string, string | LocalizedStrings> {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A formatter to be applied to a variable.
|
|
9
|
+
*/
|
|
10
|
+
type Format = {
|
|
11
|
+
name: string;
|
|
12
|
+
options: Record<string, any>;
|
|
13
|
+
};
|
|
14
|
+
export interface TranslationConfig {
|
|
15
|
+
/**
|
|
16
|
+
* Name of the locale this translation is for (BCP 47 locale names recommended).
|
|
17
|
+
*/
|
|
18
|
+
locale: string;
|
|
19
|
+
/**
|
|
20
|
+
* An object with translated strings for this language.
|
|
21
|
+
*/
|
|
22
|
+
strings?: LocalizedStrings;
|
|
23
|
+
/**
|
|
24
|
+
* A callback function that returns a Promise that resolves to the translation object for this language.
|
|
25
|
+
*/
|
|
26
|
+
fetch?: () => Promise<LocalizedStrings>;
|
|
27
|
+
/**
|
|
28
|
+
* Path to a JSON file with translated strings for this language.
|
|
29
|
+
*/
|
|
30
|
+
path?: string;
|
|
31
|
+
}
|
|
32
|
+
export type I18nSetupOptions = {
|
|
33
|
+
/**
|
|
34
|
+
* Default locale to load on startup
|
|
35
|
+
*/
|
|
36
|
+
locale?: string | null;
|
|
37
|
+
translations: TranslationConfig[];
|
|
38
|
+
};
|
|
39
|
+
export type TOptions = {
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
count?: MaybeSignal<number>;
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
context?: MaybeSignal<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Override formats specified in the template with the ones in the array for each named variable.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* t("example_key", {
|
|
53
|
+
* count: 5,
|
|
54
|
+
* formatOverrides: {
|
|
55
|
+
* count: [ { name: "datetime", options: { style: "currency", currency: "JPY" } } ]
|
|
56
|
+
* }
|
|
57
|
+
* });
|
|
58
|
+
*/
|
|
59
|
+
formatOverrides?: MaybeSignal<Record<string, Record<string, Format[]>>>;
|
|
60
|
+
[value: string]: MaybeSignal<any>;
|
|
61
|
+
};
|
|
62
|
+
export type Formatter = (locale: string, value: unknown, options: Record<string, any>) => string;
|
|
63
|
+
/**
|
|
64
|
+
* Dolla's I(nternationalizatio)n module. Manages language translations and locale-based formatting.
|
|
65
|
+
*/
|
|
66
|
+
declare class I18n {
|
|
67
|
+
#private;
|
|
68
|
+
readonly $locale: Signal<string>;
|
|
69
|
+
constructor();
|
|
70
|
+
get locales(): string[];
|
|
71
|
+
setup(options: I18nSetupOptions): Promise<void>;
|
|
72
|
+
setLocale(name: string): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Returns a State containing the value at `key`.
|
|
75
|
+
|
|
76
|
+
* @param selector - Key to the translated value.
|
|
77
|
+
* @param options - A map of `{{placeholder}}` names and the values to replace them with.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* const $value = t("your.key.here", { count: 5 });
|
|
81
|
+
*/
|
|
82
|
+
t(selector: string, options?: TOptions): Signal<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Add a custom format callback.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* Dolla.i18n.addFormat("uppercase", (locale, value, options) => {
|
|
88
|
+
* return value.toUpperCase();
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* {
|
|
92
|
+
* "greeting": "Hello, {{name|uppercase}}!"
|
|
93
|
+
* }
|
|
94
|
+
*
|
|
95
|
+
* t("greeting", {name: "world"}); // State<"Hello, WORLD!">
|
|
96
|
+
*/
|
|
97
|
+
addFormat(name: string, callback: (locale: string, value: unknown, options: Record<string, any>) => string): void;
|
|
98
|
+
/**
|
|
99
|
+
* Creates an `Intl.Collator` configured for the current locale.
|
|
100
|
+
* NOTE: The locale is tracked if called within a signal tracking context.
|
|
101
|
+
*
|
|
102
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
|
|
103
|
+
*/
|
|
104
|
+
collator(options?: Intl.CollatorOptions): Intl.Collator;
|
|
105
|
+
/**
|
|
106
|
+
* Formats a number for the current locale. Uses `Intl.NumberFormat` under the hood.
|
|
107
|
+
*
|
|
108
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
|
|
109
|
+
*/
|
|
110
|
+
number(count: MaybeSignal<number | bigint>, options?: Intl.NumberFormatOptions): Signal<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Formats a date for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
113
|
+
*
|
|
114
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* const date = new Date();
|
|
118
|
+
* const $formatted = Dolla.i18n.dateTime(date, { dateFormat: "short" });
|
|
119
|
+
*/
|
|
120
|
+
dateTime(date?: MaybeSignal<string | number | Date | undefined>, options?: Intl.DateTimeFormatOptions): Signal<string>;
|
|
121
|
+
/**
|
|
122
|
+
* Formats a list for the current locale. Uses `Intl.ListFormat` under the hood.
|
|
123
|
+
*
|
|
124
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* const list = new Date();
|
|
128
|
+
* const $formatted = Dolla.i18n.list(list, { });
|
|
129
|
+
*/
|
|
130
|
+
list(list: MaybeSignal<Iterable<string>>, options?: Intl.ListFormatOptions): Signal<string>;
|
|
131
|
+
}
|
|
132
|
+
export declare const i18n: I18n;
|
|
133
|
+
export declare const t: (selector: string, options?: TOptions) => Signal<string>;
|
|
134
|
+
export {};
|