@reactivescript/runtime 0.0.0 → 0.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 +34 -43
- package/dist/server.d.ts +1 -0
- package/dist/server.js +470 -0
- package/dist/types/rt-server.d.ts +161 -0
- package/dist/types/rt-web.d.ts +186 -0
- package/dist/web.d.ts +1 -0
- package/dist/web.js +615 -0
- package/package.json +61 -7
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { getOwner } from "solid-js";
|
|
2
|
+
import { generateHydrationScript } from "@solidjs/web";
|
|
3
|
+
export type Acc = () => unknown;
|
|
4
|
+
export type Writer = {
|
|
5
|
+
set: (v: unknown) => void;
|
|
6
|
+
path: (keys: (string | number)[], v: unknown) => void;
|
|
7
|
+
guess: (v: unknown, keys?: (string | number)[]) => void;
|
|
8
|
+
};
|
|
9
|
+
export type Entry = {
|
|
10
|
+
get?: Acc;
|
|
11
|
+
w?: Writer;
|
|
12
|
+
value?: unknown;
|
|
13
|
+
};
|
|
14
|
+
export { generateHydrationScript };
|
|
15
|
+
export declare const ERR: {
|
|
16
|
+
toString: () => string;
|
|
17
|
+
};
|
|
18
|
+
export declare const PENDING_MARK: {
|
|
19
|
+
toString: () => string;
|
|
20
|
+
};
|
|
21
|
+
export declare const fmt: (v: unknown) => string;
|
|
22
|
+
type ErrorClass = ((...args: unknown[]) => Error) & {
|
|
23
|
+
cls: new (...args: unknown[]) => Error;
|
|
24
|
+
errorClass: string;
|
|
25
|
+
};
|
|
26
|
+
/** The server renders once: an errored read throws where it is read, so a catch is an ordinary try around the read. (The
|
|
27
|
+
* client's is an error boundary: its ids are reserved.) */
|
|
28
|
+
declare function catchAcc(f: () => unknown, match: (err: unknown) => boolean, alt: (err: unknown) => unknown): () => unknown;
|
|
29
|
+
declare function tryCatch(f: () => unknown, match: (err: unknown) => boolean, alt: (err: unknown) => unknown): unknown;
|
|
30
|
+
/** As rt.ts's Flight. A rejection is sent as it is only when its class is declared (SV-5): `errorClass` marks those. */
|
|
31
|
+
export declare class Flight {
|
|
32
|
+
key: string;
|
|
33
|
+
first: Promise<unknown>;
|
|
34
|
+
private settleFirst;
|
|
35
|
+
private rejectFirst;
|
|
36
|
+
private queue;
|
|
37
|
+
private waiters;
|
|
38
|
+
private started;
|
|
39
|
+
constructor(key: string);
|
|
40
|
+
private push;
|
|
41
|
+
resolve(v: unknown): void;
|
|
42
|
+
reject(e: unknown): void;
|
|
43
|
+
[Symbol.asyncIterator](): {
|
|
44
|
+
next: () => Promise<IteratorResult<unknown>>;
|
|
45
|
+
return: () => Promise<{
|
|
46
|
+
value: undefined;
|
|
47
|
+
done: true;
|
|
48
|
+
}>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
type Owner = ReturnType<typeof getOwner>;
|
|
52
|
+
type Ctx = {
|
|
53
|
+
name: string;
|
|
54
|
+
id: symbol;
|
|
55
|
+
dflt: (() => unknown) | null;
|
|
56
|
+
owner: Owner;
|
|
57
|
+
dv: Entry | null;
|
|
58
|
+
};
|
|
59
|
+
export declare function createApp(opts?: {
|
|
60
|
+
api?: Record<string, (...a: any[]) => unknown>;
|
|
61
|
+
}): {
|
|
62
|
+
log: string[];
|
|
63
|
+
flights: Map<string, Flight>;
|
|
64
|
+
lastKey: Map<string, string>;
|
|
65
|
+
asyncError: unknown;
|
|
66
|
+
/** Render `view` as a stream: `write` receives each chunk, `end` the close. */
|
|
67
|
+
/** One request (a request event, as Solid's integrations provide one — a server function called during the render runs
|
|
68
|
+
* in it, SF-2b). */
|
|
69
|
+
stream(view: () => unknown, sink: {
|
|
70
|
+
write: (s: string) => void;
|
|
71
|
+
end: () => void;
|
|
72
|
+
}): any;
|
|
73
|
+
B: Record<string, any>;
|
|
74
|
+
/** MO-8: a class a `.d.rx` declares — a failure the server sends as it is (SV-5). */
|
|
75
|
+
jsError(name: string): unknown;
|
|
76
|
+
/** A JS function's promise: a rejection with a declared class is marked safe to send; any other is redacted (SV-5). */
|
|
77
|
+
api: (name: string) => (...a: unknown[]) => unknown;
|
|
78
|
+
reg(name: string, e: Entry): void;
|
|
79
|
+
dget(name: string): any;
|
|
80
|
+
lookup(name: string): Entry;
|
|
81
|
+
source(name: string, init: unknown): [Acc, Writer];
|
|
82
|
+
question(name: string, compute: (prev: unknown) => unknown, o: {
|
|
83
|
+
loadingValue?: unknown;
|
|
84
|
+
} | undefined, mode: {
|
|
85
|
+
optimistic: boolean;
|
|
86
|
+
structured: boolean;
|
|
87
|
+
}, key?: string): [Acc, Writer];
|
|
88
|
+
memo: (name: string | null, fn: (prev: unknown) => unknown, o?: {
|
|
89
|
+
loadingValue?: unknown;
|
|
90
|
+
}) => Acc;
|
|
91
|
+
deferred: (name: string, fn: (prev: unknown) => unknown, o?: {
|
|
92
|
+
loadingValue?: unknown;
|
|
93
|
+
}) => Acc;
|
|
94
|
+
keyed: (name: string, key: string, fn: () => unknown) => Acc;
|
|
95
|
+
draft: (seed: unknown, body: (d: any) => void) => Acc;
|
|
96
|
+
pre: (get: Acc) => Acc;
|
|
97
|
+
firstPaint: (f: () => unknown) => {
|
|
98
|
+
loadingValue: any;
|
|
99
|
+
};
|
|
100
|
+
/** SV-2: the apply half runs on the client, after hydration. The compute half is reactive scope — Solid's server runs it;
|
|
101
|
+
* an input's failure is an answer (E-12), not a server error. */
|
|
102
|
+
effect(_n: number, inputs: () => unknown[], _apply: (p: unknown[]) => unknown): void;
|
|
103
|
+
action(_gen: (...a: unknown[]) => Generator<unknown, unknown, unknown>): () => never;
|
|
104
|
+
awaited: (v: unknown) => unknown;
|
|
105
|
+
/** RG-8: Solid's Portal — client-only: the server renders nothing for it, the browser renders it once it has the page. */
|
|
106
|
+
Portal: any;
|
|
107
|
+
/** CSS-2: a dynamic class with the view's scope class after it. */
|
|
108
|
+
scopedClass: (v: unknown, hash: string) => string;
|
|
109
|
+
/** SV-7b: a client question — not asked on the server; the browser asks it once hydrated (Solid's \`ssrSource: "client"\`). */
|
|
110
|
+
clientQuestion: (o?: {
|
|
111
|
+
loadingValue?: unknown;
|
|
112
|
+
}) => {
|
|
113
|
+
ssrSource: string;
|
|
114
|
+
loadingValue?: unknown;
|
|
115
|
+
};
|
|
116
|
+
/** 12 SF-2: a server fn as the client calls it — every call a flight. Asked in reactive scope it is a question, one
|
|
117
|
+
* flight per arguments, as a JS import's; in imperative scope each call is a new request. \`fn\` is the module-level
|
|
118
|
+
* \`"use server"\` function (SF-7a): the body in place, or — once Solid's \`transformDirectives\` has made it a reference
|
|
119
|
+
* — a request to the server. */
|
|
120
|
+
serverRef(name: string, fn: (...a: unknown[]) => Promise<unknown>): (...args: unknown[]) => Flight;
|
|
121
|
+
/** SF-6: a server fn's body (a generator, as an action's), driven by promises — not by an action: it is no change of
|
|
122
|
+
* the client's — behind a wire that copies arguments and result and lets only declared failures through. */
|
|
123
|
+
serverCall(name: string, gen: (...a: unknown[]) => Generator<unknown, unknown, unknown>, args: unknown[]): Promise<unknown>;
|
|
124
|
+
hoisted(_name: string, _get: Acc): void;
|
|
125
|
+
refresh: () => never;
|
|
126
|
+
affects: () => never;
|
|
127
|
+
onSettled: () => never;
|
|
128
|
+
onFlush: () => never;
|
|
129
|
+
preOr: (v: unknown, init: () => unknown) => unknown;
|
|
130
|
+
module(key: unknown, factory: (rt: unknown) => Record<string, unknown>): Record<string, unknown>;
|
|
131
|
+
owner: () => any;
|
|
132
|
+
context(name: string, dflt: (() => unknown) | null): Ctx;
|
|
133
|
+
provide(c: Ctx, e: Entry): void;
|
|
134
|
+
use(c: Ctx, owner: Owner): Entry;
|
|
135
|
+
useGet(c: Ctx, owner: Owner): unknown;
|
|
136
|
+
runWithOwner: any;
|
|
137
|
+
snapshot(get: Acc): any;
|
|
138
|
+
errorClass: (name: string, params: string[], message: (...args: unknown[]) => unknown) => ErrorClass;
|
|
139
|
+
isA: (err: unknown, classes: unknown[] | undefined) => boolean;
|
|
140
|
+
PANIC: {
|
|
141
|
+
readonly panic: true;
|
|
142
|
+
};
|
|
143
|
+
catchMemo: typeof catchAcc;
|
|
144
|
+
tryCatch: typeof tryCatch;
|
|
145
|
+
catchRead: (f: () => unknown, match: (err: unknown) => boolean, alt: (err: unknown) => unknown) => unknown;
|
|
146
|
+
throw: (e: unknown) => never;
|
|
147
|
+
eq: (a: unknown, b: unknown) => boolean;
|
|
148
|
+
untrack: any;
|
|
149
|
+
latest: (f: () => unknown) => any;
|
|
150
|
+
isPending: (f: () => unknown) => any;
|
|
151
|
+
fmt: (v: unknown) => string;
|
|
152
|
+
show: (v: unknown) => any;
|
|
153
|
+
/** A failure of another class passes to the boundary above (R-f-4): on the server, a rethrow from the fallback. The
|
|
154
|
+
* client's unwrapping memo has no counterpart here: its id is reserved. */
|
|
155
|
+
TypedErrored(props: {
|
|
156
|
+
classes: unknown[];
|
|
157
|
+
fallback: (err: Acc) => unknown;
|
|
158
|
+
children: unknown;
|
|
159
|
+
}): any;
|
|
160
|
+
};
|
|
161
|
+
export type ServerApp = ReturnType<typeof createApp>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { createContext, flush, getOwner } from "solid-js";
|
|
2
|
+
export { flush };
|
|
3
|
+
export type Acc = () => unknown;
|
|
4
|
+
export type Writer = {
|
|
5
|
+
set: (v: unknown) => void;
|
|
6
|
+
path: (keys: (string | number)[], v: unknown) => void;
|
|
7
|
+
guess: (v: unknown, keys?: (string | number)[]) => void;
|
|
8
|
+
};
|
|
9
|
+
export type Entry = {
|
|
10
|
+
get?: Acc;
|
|
11
|
+
w?: Writer;
|
|
12
|
+
value?: unknown;
|
|
13
|
+
};
|
|
14
|
+
export declare const ERR: {
|
|
15
|
+
toString: () => string;
|
|
16
|
+
};
|
|
17
|
+
export declare const PENDING_MARK: {
|
|
18
|
+
toString: () => string;
|
|
19
|
+
};
|
|
20
|
+
export declare const fmt: (v: unknown) => string;
|
|
21
|
+
type ErrorClass = ((...args: unknown[]) => Error) & {
|
|
22
|
+
cls: new (...args: unknown[]) => Error;
|
|
23
|
+
errorClass: string;
|
|
24
|
+
};
|
|
25
|
+
/** `e catch (x: C) => alt`, reactive: an error boundary around the read whose fallback is the value (Solid: an errored read
|
|
26
|
+
* reaches the nearest boundary even inside a JS `try`). The fallback is decided when read, so a change of class re-decides it. */
|
|
27
|
+
declare function catchAcc(f: () => unknown, match: (err: unknown) => boolean, alt: (err: unknown) => unknown): () => unknown;
|
|
28
|
+
/** Imperative scope: an ordinary try. */
|
|
29
|
+
declare function tryCatch(f: () => unknown, match: (err: unknown) => boolean, alt: (err: unknown) => unknown): unknown;
|
|
30
|
+
/** A controllable flight: an async iterable (a stream — each resolve is a landing) that actions await through `first`. */
|
|
31
|
+
export declare class Flight {
|
|
32
|
+
key: string;
|
|
33
|
+
first: Promise<unknown>;
|
|
34
|
+
private settleFirst;
|
|
35
|
+
private rejectFirst;
|
|
36
|
+
private queue;
|
|
37
|
+
private waiters;
|
|
38
|
+
private started;
|
|
39
|
+
constructor(key: string);
|
|
40
|
+
private push;
|
|
41
|
+
resolve(v: unknown): void;
|
|
42
|
+
reject(e: unknown): void;
|
|
43
|
+
[Symbol.asyncIterator](): {
|
|
44
|
+
next: () => Promise<IteratorResult<unknown>>;
|
|
45
|
+
return: () => Promise<{
|
|
46
|
+
value: undefined;
|
|
47
|
+
done: true;
|
|
48
|
+
}>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export declare function createApp(opts: {
|
|
52
|
+
root: any;
|
|
53
|
+
api?: Record<string, (...a: any[]) => unknown>;
|
|
54
|
+
}): {
|
|
55
|
+
root: any;
|
|
56
|
+
log: string[];
|
|
57
|
+
flights: Map<string, Flight>;
|
|
58
|
+
lastKey: Map<string, string>;
|
|
59
|
+
asyncError: unknown;
|
|
60
|
+
/** Mount `view` on the root: build it, or (SV-3) adopt the page the server streamed into it. */
|
|
61
|
+
mount(view: () => unknown, hydrating?: boolean): any;
|
|
62
|
+
B: Record<string, any>;
|
|
63
|
+
/** `import pure { f } from "./api"`: every function is a flight keyed by its name and formatted arguments. */
|
|
64
|
+
/** MO-8: a class `api.d.rx` declares as an error: the real module's, or (in the harness) a stand-in `C(message)`. */
|
|
65
|
+
jsError: (name: string) => unknown;
|
|
66
|
+
api: (name: string) => (...a: any[]) => unknown;
|
|
67
|
+
reg(name: string, e: Entry): void;
|
|
68
|
+
lookup(name: string): Entry;
|
|
69
|
+
dget(name: string, live?: boolean): any;
|
|
70
|
+
dset(name: string, keys: (string | number)[], v: unknown, guess?: boolean): void;
|
|
71
|
+
/** `source x := e`: atomic → a signal; structured → a store behind a signal slot, so the root can be replaced (ST-1, ST-2a). */
|
|
72
|
+
source(name: string, init: unknown): [Acc, Writer];
|
|
73
|
+
/** `source x = e` (ST-5): createSignal(fn); with a guess written to it, a createOptimistic layer over that truth (AC-3);
|
|
74
|
+
* written or probed by path, createStore(fn, {}) whose derive writes its draft. */
|
|
75
|
+
question(name: string, compute: (prev: unknown) => unknown, opts: {
|
|
76
|
+
loadingValue?: unknown;
|
|
77
|
+
} | undefined, mode: {
|
|
78
|
+
optimistic: boolean;
|
|
79
|
+
structured: boolean;
|
|
80
|
+
}, key?: string): [Acc, Writer];
|
|
81
|
+
memo: (name: string | null, fn: (prev: unknown) => unknown, opts?: {
|
|
82
|
+
loadingValue?: unknown;
|
|
83
|
+
}) => Acc;
|
|
84
|
+
deferred: (name: string, fn: (prev: unknown) => unknown, opts?: {
|
|
85
|
+
loadingValue?: unknown;
|
|
86
|
+
}) => Acc;
|
|
87
|
+
/** `x key k = e` (ST-4): a keyed projection. */
|
|
88
|
+
keyed: (name: string, key: string, fn: () => unknown) => Acc;
|
|
89
|
+
/** `x = draft(pre x -> seed) { … }` (ST-3). */
|
|
90
|
+
draft: (seed: unknown, body: (d: any) => void) => Acc;
|
|
91
|
+
/** `pre y` of another node (C-2): a companion memo carrying (current, previous), owned where `y` is declared. */
|
|
92
|
+
pre: (get: Acc) => Acc;
|
|
93
|
+
firstPaint: (f: () => unknown) => {
|
|
94
|
+
loadingValue: any;
|
|
95
|
+
};
|
|
96
|
+
/** `effect (…) { … }`: compute, then apply; an error is an answer the apply receives (E-12); fires on a differing value (EF-2); a store enters whole, as a snapshot. */
|
|
97
|
+
effect(n: number, inputs: () => unknown[], apply: (p: unknown[]) => unknown): void;
|
|
98
|
+
/** `action f(…) { … }` (AC-1): a generator; a statement-level `await` is a hold-safe yield. */
|
|
99
|
+
action(gen: (...a: unknown[]) => Generator<unknown, unknown, unknown>): (...a: unknown[]) => Promise<unknown>;
|
|
100
|
+
awaited: (v: unknown) => unknown;
|
|
101
|
+
/** RG-8: Solid's Portal — client-only: the server renders nothing for it, the browser renders it once it has the page. */
|
|
102
|
+
Portal: any;
|
|
103
|
+
/** CSS-2: a dynamic class with the view's scope class after it. */
|
|
104
|
+
scopedClass: (v: unknown, hash: string) => string;
|
|
105
|
+
/** SV-7b: a client question — not asked on the server; the browser asks it once hydrated (Solid's \`ssrSource: "client"\`). */
|
|
106
|
+
clientQuestion: (o?: {
|
|
107
|
+
loadingValue?: unknown;
|
|
108
|
+
}) => {
|
|
109
|
+
ssrSource: string;
|
|
110
|
+
loadingValue?: unknown;
|
|
111
|
+
};
|
|
112
|
+
/** 12 SF-2: a server fn as the client calls it — every call a flight. Asked in reactive scope it is a question, one
|
|
113
|
+
* flight per arguments, as a JS import's; in imperative scope each call is a new request. \`fn\` is the module-level
|
|
114
|
+
* \`"use server"\` function (SF-7a): the body in place, or — once Solid's \`transformDirectives\` has made it a reference
|
|
115
|
+
* — a request to the server. */
|
|
116
|
+
serverRef(name: string, fn: (...a: unknown[]) => Promise<unknown>): (...args: unknown[]) => Flight;
|
|
117
|
+
/** SF-6: a server fn's body (a generator, as an action's), driven by promises — not by an action: it is no change of
|
|
118
|
+
* the client's — behind a wire that copies arguments and result and lets only declared failures through. */
|
|
119
|
+
serverCall(name: string, gen: (...a: unknown[]) => Generator<unknown, unknown, unknown>, args: unknown[]): Promise<unknown>;
|
|
120
|
+
hoisted(name: string, get: Acc): void;
|
|
121
|
+
until: (p: () => unknown) => any;
|
|
122
|
+
onSettled: (f: () => void) => any;
|
|
123
|
+
onFlush: (f: () => void) => any;
|
|
124
|
+
refresh(name: string, get: Acc): void;
|
|
125
|
+
affects: (get: Acc) => any;
|
|
126
|
+
preOr: (v: unknown, init: () => unknown) => unknown;
|
|
127
|
+
module(key: unknown, factory: (rt: unknown) => Record<string, unknown>): Record<string, unknown>;
|
|
128
|
+
owner: () => any;
|
|
129
|
+
/** `context x: T = d` (RG-7): the declaration is the identity; `d`, if any, is evaluated once, owned where it is declared. */
|
|
130
|
+
/** `context x: T = d` (RG-7): the declaration is the identity (a sentinel default: absence is ours to decide); `d` is
|
|
131
|
+
* evaluated once, owned where it is declared — created now, so it takes its id there on both sides (SV-3). */
|
|
132
|
+
context(name: string, dflt: (() => unknown) | null): {
|
|
133
|
+
name: string;
|
|
134
|
+
ctx: ReturnType<typeof createContext<Entry | undefined>>;
|
|
135
|
+
dflt: (() => unknown) | null;
|
|
136
|
+
owner: ReturnType<typeof getOwner>;
|
|
137
|
+
dv: Entry | null;
|
|
138
|
+
};
|
|
139
|
+
provide(c: {
|
|
140
|
+
name: string;
|
|
141
|
+
ctx: ReturnType<typeof createContext<Entry | undefined>>;
|
|
142
|
+
dflt: (() => unknown) | null;
|
|
143
|
+
owner: ReturnType<typeof getOwner>;
|
|
144
|
+
dv: Entry | null;
|
|
145
|
+
}, e: Entry): void;
|
|
146
|
+
use(c: {
|
|
147
|
+
name: string;
|
|
148
|
+
ctx: ReturnType<typeof createContext<Entry | undefined>>;
|
|
149
|
+
dflt: (() => unknown) | null;
|
|
150
|
+
owner: ReturnType<typeof getOwner>;
|
|
151
|
+
dv: Entry | null;
|
|
152
|
+
}, owner: ReturnType<typeof getOwner>): Entry;
|
|
153
|
+
useGet(c: {
|
|
154
|
+
name: string;
|
|
155
|
+
ctx: ReturnType<typeof createContext<Entry | undefined>>;
|
|
156
|
+
dflt: (() => unknown) | null;
|
|
157
|
+
owner: ReturnType<typeof getOwner>;
|
|
158
|
+
dv: Entry | null;
|
|
159
|
+
}, owner: ReturnType<typeof getOwner>): unknown;
|
|
160
|
+
runWithOwner: any;
|
|
161
|
+
/** An imperative read sees σ (H-10): a pending value is a value; a snapshot of an error throws it (R-f-7). */
|
|
162
|
+
snapshot(get: Acc): any;
|
|
163
|
+
errorClass: (name: string, params: string[], message: (...args: unknown[]) => unknown) => ErrorClass;
|
|
164
|
+
isA: (err: unknown, classes: unknown[] | undefined) => boolean;
|
|
165
|
+
PANIC: {
|
|
166
|
+
readonly panic: true;
|
|
167
|
+
};
|
|
168
|
+
catchMemo: typeof catchAcc;
|
|
169
|
+
tryCatch: typeof tryCatch;
|
|
170
|
+
catchRead: (f: () => unknown, match: (err: unknown) => boolean, alt: (err: unknown) => unknown) => unknown;
|
|
171
|
+
throw: (e: unknown) => never;
|
|
172
|
+
eq: (a: unknown, b: unknown) => boolean;
|
|
173
|
+
untrack: any;
|
|
174
|
+
latest: (f: () => unknown) => any;
|
|
175
|
+
isPending: (f: () => unknown) => any;
|
|
176
|
+
fmt: (v: unknown) => string;
|
|
177
|
+
show: (v: unknown) => unknown;
|
|
178
|
+
/** `errored fallback(e: A | B)`: a failure of another class passes to the boundary above (R-f-4) — the fallback hands it out
|
|
179
|
+
* and a memo throws it there (a rethrow from the fallback itself did not recover until solidjs/solid#4277: ref/oracle/repros/dv7-rethrow.mjs). */
|
|
180
|
+
TypedErrored(props: {
|
|
181
|
+
classes: unknown[];
|
|
182
|
+
fallback: (err: Acc) => unknown;
|
|
183
|
+
children: unknown;
|
|
184
|
+
}): any;
|
|
185
|
+
};
|
|
186
|
+
export type App = ReturnType<typeof createApp>;
|
package/dist/web.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types/rt-web.js";
|