@askrjs/askr 0.2.3 → 0.3.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/CHANGELOG.md +11 -0
- package/dist/access-CEA2pOry.js +1046 -0
- package/dist/actions/index.d.ts +16 -2
- package/dist/actions/index.js +5 -5
- package/dist/{activity-ZxJXI9hF.js → activity-oy2YFTFF.js} +22 -16
- package/dist/benchmark.js +8 -9
- package/dist/boot/index.d.ts +21 -9
- package/dist/boot/index.js +1 -1
- package/dist/{boot-D4GaLA0d.js → boot-BMBMWUGI.js} +680 -440
- package/dist/capabilities-Bbf0mlp9.js +42 -0
- package/dist/components/index.d.ts +11 -8
- package/dist/components/index.js +1 -1
- package/dist/{compose-ref-Bfaf4kUC.js → compose-ref-v0qGlHoN.js} +7 -1
- package/dist/control/index.d.ts +20 -2
- package/dist/control/index.js +1 -1
- package/dist/{control-57x3wa4J.js → control-BR_mrX__.js} +4 -4
- package/dist/core.d.ts +163 -0
- package/dist/csp-nonce-BfFWcd0w.js +173 -0
- package/dist/data/index.d.ts +74 -2
- package/dist/data/index.js +3 -3
- package/dist/{data-B7XCDeC8.js → data-2edW0jhF.js} +133 -138
- package/dist/{data-runtime-7t_Y0iv3.js → data-runtime-CxoY98lX.js} +22 -15
- package/dist/{deferred-BELyvMsC.js → deferred-CbgNhf67.js} +5 -5
- package/dist/dom-renderer.d.ts +77 -0
- package/dist/domains/actions.d.ts +70 -0
- package/dist/domains/component.d.ts +119 -0
- package/dist/domains/context.d.ts +73 -0
- package/dist/domains/control.d.ts +328 -0
- package/dist/domains/data.d.ts +461 -0
- package/dist/domains/diagnostics.d.ts +21 -0
- package/dist/domains/lifecycle.d.ts +112 -0
- package/dist/domains/refs.d.ts +18 -0
- package/dist/domains/renderer.d.ts +127 -0
- package/dist/domains/routing.d.ts +501 -0
- package/dist/domains/scheduler.d.ts +79 -0
- package/dist/domains/server.d.ts +112 -0
- package/dist/domains/state.d.ts +129 -0
- package/dist/domains/telemetry.d.ts +29 -0
- package/dist/eager-control.d.ts +8 -0
- package/dist/{effect-4LwBwV58.js → effect-C3Zsc1k6.js} +14 -41
- package/dist/{types-DkVJhVs9.d.ts → elements.d.ts} +84 -42
- package/dist/{for-internal-DeoSg_AV.js → for-state-BDykeOJL.js} +623 -511
- package/dist/foundations/icon/index.d.ts +67 -16
- package/dist/foundations/icon/index.js +1 -1
- package/dist/foundations/index.d.ts +26 -3
- package/dist/foundations/index.js +1 -1
- package/dist/foundations/interactions/index.d.ts +73 -34
- package/dist/foundations/interactions/index.js +1 -1
- package/dist/foundations/state/index.d.ts +12 -5
- package/dist/foundations/state/index.js +1 -1
- package/dist/foundations/structures/index.d.ts +44 -3
- package/dist/foundations/structures/index.js +1 -1
- package/dist/foundations/utilities/index.d.ts +34 -3
- package/dist/foundations/utilities/index.js +1 -1
- package/dist/fx/index.d.ts +72 -25
- package/dist/fx/index.js +8 -8
- package/dist/index.d.ts +121 -4
- package/dist/index.js +316 -47
- package/dist/{component-internal-Dl02WQKS.js → instance-VAFYVJOa.js} +495 -283
- package/dist/{interactions-D102JxBR.js → interactions-CTeACdT_.js} +1 -1
- package/dist/jsx-dev-runtime.d.ts +51 -11
- package/dist/jsx-globals.d.ts +2 -0
- package/dist/jsx-runtime-CPJXAOBF.js +43 -0
- package/dist/jsx-runtime.d.ts +17 -3
- package/dist/jsx-runtime.js +2 -42
- package/dist/jsx.d.ts +108 -0
- package/dist/{manifest-D6rfj_jC.js → manifest-D1P3UNWV.js} +4 -9
- package/dist/{navigate-C46GtScG.js → navigate-prC5V8XV.js} +204 -476
- package/dist/{navigate-wel1e6cU.d.ts → navigation.d.ts} +10 -8
- package/dist/{readable-CEcteIDE.js → notify-DxxuDPeY.js} +96 -34
- package/dist/{query-registry-Bua3cDyb.js → query-registry-LrYpQsDJ.js} +1 -1
- package/dist/{compose-ref-DOJHoW5X.d.ts → refs.d.ts} +11 -7
- package/dist/{ssr-BaC5qHEw.js → render-resolved-BC0W7_5b.js} +165 -558
- package/dist/{renderer-BhXofszH.js → renderer-CT0HeY58.js} +6866 -5715
- package/dist/{resolution-t8J0yNaU.js → resolution-3DskUkjG.js} +189 -180
- package/dist/{resource-operation-B8q-QRUx.js → resource-18-sFRl9.js} +98 -58
- package/dist/resources/index.d.ts +64 -46
- package/dist/resources/index.js +215 -9
- package/dist/route-activity.d.ts +21 -0
- package/dist/{route-matching-Bo6UqG-5.js → route-matching-CUzZ31gT.js} +68 -82
- package/dist/router/index.d.ts +378 -79
- package/dist/router/index.js +9 -9
- package/dist/router-internal-7nuNEHfG.js +36 -0
- package/dist/scope-Cq_iYbTR.js +403 -0
- package/dist/{selector-C7rIpOnN.js → selector-BSPVkjKP.js} +41 -41
- package/dist/{shared-CGrx2AOL.js → shared-kU8yvryp.js} +3 -6
- package/dist/{snapshot-source-BB42xgwb.js → snapshot-source-An4iKajG.js} +1 -1
- package/dist/ssg/index.d.ts +51 -15
- package/dist/ssg/index.js +269 -209
- package/dist/ssr/index.d.ts +121 -68
- package/dist/ssr/index.js +2 -1
- package/dist/ssr-CiNm6Vzl.js +393 -0
- package/dist/{ssr-DSHd_Q9K.js → ssr-EPjwJH5R.js} +5 -1
- package/dist/{state-BzhOW2TX.js → state-BXJfudq1.js} +10 -15
- package/dist/{structures-BwfeO4Iz.js → structures-CjEzfj4h.js} +37 -57
- package/dist/{index-r5THqzPN.d.ts → structures.d.ts} +57 -36
- package/dist/testing/index.d.ts +125 -24
- package/dist/testing/index.js +26 -62
- package/dist/timer-C7uqnJVt.js +85 -0
- package/dist/{index-B1gu0_m0.d.ts → utilities.d.ts} +24 -13
- package/dist/{verify-hydration-_Q6avFp0.js → verify-hydration-ikaxotf7.js} +8 -5
- package/package.json +13 -15
- package/dist/access-Rr7CMa06.js +0 -507
- package/dist/activity-CAJ5eho-.d.ts +0 -14
- package/dist/benchmark.d.ts +0 -26
- package/dist/cleanup-DsrbV-rr.js +0 -535
- package/dist/component-cleanup-DjpwO9WX.js +0 -143
- package/dist/component-scope-4I3yEMkb.js +0 -195
- package/dist/control-DdFw-Caz.d.ts +0 -8
- package/dist/csp-nonce-C9OuML0U.js +0 -72
- package/dist/css-BuPaTOfe.js +0 -70
- package/dist/fastlane-Buz1Rvlr.js +0 -166
- package/dist/index-DSqXWc77.d.ts +0 -1402
- package/dist/jsx-runtime-BTzDdBJ_.d.ts +0 -2
- package/dist/jsx-runtime-Cdd6Gkb0.d.ts +0 -38
- package/dist/lifecycle-batch-Be-CLDjV.js +0 -253
- package/dist/lifecycle-operations-C5m03NQc.js +0 -195
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { JSXElementType, JSXElement, Props } from '../elements.js';
|
|
2
|
+
import '../jsx-globals.js';
|
|
3
|
+
import { AuthContext, AuthRequirement } from '@askrjs/auth';
|
|
4
|
+
import { InferSchema, ObjectSchema } from '@askrjs/schema';
|
|
5
|
+
import { state } from './state.js';
|
|
6
|
+
import { CoreTelemetry } from './telemetry.js';
|
|
7
|
+
import { on } from './lifecycle.js';
|
|
8
|
+
import { action } from './actions.js';
|
|
9
|
+
|
|
10
|
+
/** Freshness classification for a {@link Query}'s current data. */
|
|
11
|
+
type QueryConsistency = 'fresh' | 'stale' | 'refreshing' | 'pending-write';
|
|
12
|
+
|
|
13
|
+
/** Why a {@link Query} is stale. */
|
|
14
|
+
type QueryStaleReason = 'aborted' | 'error' | 'inconsistent';
|
|
15
|
+
|
|
16
|
+
/** Isolated cache/state container backing queries and mutations, e.g. one per test or request. */
|
|
17
|
+
interface DataRuntime {
|
|
18
|
+
readonly queryCache: Map<string, unknown>;
|
|
19
|
+
readonly queryData: Map<string, unknown>;
|
|
20
|
+
/** Test-only query overrides keyed by the canonical query key. */
|
|
21
|
+
readonly queryTestOverrides: Map<string, unknown>;
|
|
22
|
+
/** Test-only mutation overrides keyed by the canonical mutation key. */
|
|
23
|
+
readonly mutationTestOverrides: Map<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Options for {@link createDataRuntime}. */
|
|
27
|
+
interface DataRuntimeOptions {
|
|
28
|
+
queryCache?: Map<string, unknown>;
|
|
29
|
+
queryData?: Map<string, unknown>;
|
|
30
|
+
queryTestOverrides?: Map<string, unknown>;
|
|
31
|
+
mutationTestOverrides?: Map<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Reusable query definition for {@link defineQuery}: key, fetcher, and freshness checks. */
|
|
35
|
+
interface QueryDefinition<TInput, TResult extends {}> {
|
|
36
|
+
readonly key: (input: TInput) => string;
|
|
37
|
+
readonly fetch: (
|
|
38
|
+
context: TInput & {
|
|
39
|
+
signal: AbortSignal;
|
|
40
|
+
}
|
|
41
|
+
) => Promise<TResult>;
|
|
42
|
+
readonly isConsistent?: (data: TResult) => boolean;
|
|
43
|
+
readonly reconcile?: (
|
|
44
|
+
data: TResult,
|
|
45
|
+
context: {
|
|
46
|
+
key: string;
|
|
47
|
+
}
|
|
48
|
+
) => Promise<boolean> | boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Stable identity for one member of a {@link QueryCollection}. */
|
|
52
|
+
type QueryCollectionKey = string | number | symbol;
|
|
53
|
+
|
|
54
|
+
/** One keyed input and its underlying cache-backed query reader. */
|
|
55
|
+
interface QueryCollectionEntry<
|
|
56
|
+
TInput,
|
|
57
|
+
TResult extends {},
|
|
58
|
+
TKey extends QueryCollectionKey = string,
|
|
59
|
+
> {
|
|
60
|
+
readonly key: TKey;
|
|
61
|
+
readonly input: TInput;
|
|
62
|
+
readonly query: Query<TResult>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Options for {@link createQueryCollection}. */
|
|
66
|
+
interface QueryCollectionOptions<
|
|
67
|
+
TInput,
|
|
68
|
+
TResult extends {},
|
|
69
|
+
TKey extends QueryCollectionKey = string,
|
|
70
|
+
> {
|
|
71
|
+
readonly query: QueryDefinition<TInput, TResult>;
|
|
72
|
+
readonly inputs: () => readonly TInput[];
|
|
73
|
+
readonly key: (input: TInput) => TKey;
|
|
74
|
+
readonly concurrency?: number;
|
|
75
|
+
readonly runtime?: DataRuntime;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Aggregate reactive state for a lifecycle-owned dynamic query collection. */
|
|
79
|
+
interface QueryCollection<
|
|
80
|
+
TInput,
|
|
81
|
+
TResult extends {},
|
|
82
|
+
TKey extends QueryCollectionKey = string,
|
|
83
|
+
> {
|
|
84
|
+
readonly entries: readonly QueryCollectionEntry<TInput, TResult, TKey>[];
|
|
85
|
+
readonly loading: boolean;
|
|
86
|
+
readonly settled: boolean;
|
|
87
|
+
readonly results: ReadonlyMap<TKey, TResult>;
|
|
88
|
+
readonly errors: ReadonlyMap<TKey, {}>;
|
|
89
|
+
get(key: TKey): QueryCollectionEntry<TInput, TResult, TKey> | undefined;
|
|
90
|
+
retry(key: TKey): Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Context passed to server prefetch callbacks, exposing a scoped `prefetch` helper. */
|
|
94
|
+
interface QueryPrefetchContext {
|
|
95
|
+
readonly runtime: DataRuntime;
|
|
96
|
+
readonly request?: Request;
|
|
97
|
+
readonly signal: AbortSignal;
|
|
98
|
+
readonly mode: 'ssr' | 'spa';
|
|
99
|
+
prefetch<TInput, TResult extends {}>(
|
|
100
|
+
query: QueryDefinition<TInput, TResult>,
|
|
101
|
+
input: TInput
|
|
102
|
+
): Promise<boolean>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Server-side handler that resolves a {@link QueryDefinition}'s data for `serveQuery`. */
|
|
106
|
+
type ServerQueryHandler<TInput, TResult extends {}> = (context: {
|
|
107
|
+
input: TInput;
|
|
108
|
+
request?: Request;
|
|
109
|
+
signal: AbortSignal;
|
|
110
|
+
}) => Promise<TResult> | TResult;
|
|
111
|
+
|
|
112
|
+
/** Options for {@link invalidate} and {@link QueryScope.invalidate}. */
|
|
113
|
+
interface InvalidateOptions {
|
|
114
|
+
markPendingWrite?: boolean;
|
|
115
|
+
runtime?: DataRuntime;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Options for {@link invalidateOnInterval}. */
|
|
119
|
+
interface InvalidateOnIntervalOptions extends InvalidateOptions {
|
|
120
|
+
intervalMs: number;
|
|
121
|
+
activeOn?: string | readonly string[];
|
|
122
|
+
visibleOnly?: boolean;
|
|
123
|
+
focusedOnly?: boolean;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** A JSON-serializable value usable as part of a query key or invalidation prefix. */
|
|
127
|
+
type QueryKeyPart =
|
|
128
|
+
| string
|
|
129
|
+
| number
|
|
130
|
+
| boolean
|
|
131
|
+
| null
|
|
132
|
+
| undefined
|
|
133
|
+
| readonly QueryKeyPart[]
|
|
134
|
+
| {
|
|
135
|
+
readonly [key: string]: QueryKeyPart;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** Namespaced key-building and invalidation helper returned by {@link queryScope}. */
|
|
139
|
+
interface QueryScope {
|
|
140
|
+
key(...parts: QueryKeyPart[]): string;
|
|
141
|
+
prefix(...parts: QueryKeyPart[]): string;
|
|
142
|
+
invalidate(parts: readonly QueryKeyPart[], options?: InvalidateOptions): void;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
type QueryControls = {
|
|
146
|
+
refresh(): Promise<void>;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
type QueryLoading = {
|
|
150
|
+
data: null;
|
|
151
|
+
error: null;
|
|
152
|
+
loading: true;
|
|
153
|
+
refreshing: false;
|
|
154
|
+
stale: false;
|
|
155
|
+
consistency: 'fresh';
|
|
156
|
+
staleReason: null;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
type QueryFresh<T> = {
|
|
160
|
+
data: T;
|
|
161
|
+
error: null;
|
|
162
|
+
loading: false;
|
|
163
|
+
refreshing: false;
|
|
164
|
+
stale: false;
|
|
165
|
+
consistency: 'fresh';
|
|
166
|
+
staleReason: null;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
type QueryRefreshing<T> = {
|
|
170
|
+
data: T;
|
|
171
|
+
error: null;
|
|
172
|
+
loading: false;
|
|
173
|
+
refreshing: true;
|
|
174
|
+
stale: true;
|
|
175
|
+
consistency: 'refreshing';
|
|
176
|
+
staleReason: null;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
type QueryPendingWrite<T> = {
|
|
180
|
+
data: T;
|
|
181
|
+
error: null;
|
|
182
|
+
loading: false;
|
|
183
|
+
refreshing: true;
|
|
184
|
+
stale: true;
|
|
185
|
+
consistency: 'pending-write';
|
|
186
|
+
staleReason: null;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
type QueryStaleValue<T> = {
|
|
190
|
+
data: T;
|
|
191
|
+
error: null;
|
|
192
|
+
loading: false;
|
|
193
|
+
refreshing: false;
|
|
194
|
+
stale: true;
|
|
195
|
+
consistency: 'stale';
|
|
196
|
+
staleReason: 'aborted' | 'inconsistent';
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
type QueryStaleErrorWithValue<T> = {
|
|
200
|
+
data: T;
|
|
201
|
+
error: {};
|
|
202
|
+
loading: false;
|
|
203
|
+
refreshing: false;
|
|
204
|
+
stale: true;
|
|
205
|
+
consistency: 'stale';
|
|
206
|
+
staleReason: 'error';
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
type QueryStaleError = {
|
|
210
|
+
data: null;
|
|
211
|
+
error: {};
|
|
212
|
+
loading: false;
|
|
213
|
+
refreshing: false;
|
|
214
|
+
stale: true;
|
|
215
|
+
consistency: 'stale';
|
|
216
|
+
staleReason: 'error';
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
/** Reactive read state for a query cell: data, loading/refresh flags, and freshness. */
|
|
220
|
+
type Query<T extends {}> = QueryControls &
|
|
221
|
+
(
|
|
222
|
+
| QueryLoading
|
|
223
|
+
| QueryFresh<T>
|
|
224
|
+
| QueryRefreshing<T>
|
|
225
|
+
| QueryPendingWrite<T>
|
|
226
|
+
| QueryStaleValue<T>
|
|
227
|
+
| QueryStaleErrorWithValue<T>
|
|
228
|
+
| QueryStaleError
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
type MutationControls<TInput, TResult> = {
|
|
232
|
+
execute(input: TInput): Promise<TResult>;
|
|
233
|
+
abort(): void;
|
|
234
|
+
reset(): void;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
type MutationIdle = {
|
|
238
|
+
status: 'idle';
|
|
239
|
+
pending: false;
|
|
240
|
+
error: null;
|
|
241
|
+
result: null;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
type MutationPending = {
|
|
245
|
+
status: 'pending';
|
|
246
|
+
pending: true;
|
|
247
|
+
error: null;
|
|
248
|
+
result: null;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
type MutationSuccess<TResult> = {
|
|
252
|
+
status: 'success';
|
|
253
|
+
pending: false;
|
|
254
|
+
error: null;
|
|
255
|
+
result: TResult;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
type MutationError = {
|
|
259
|
+
status: 'error';
|
|
260
|
+
pending: false;
|
|
261
|
+
error: {};
|
|
262
|
+
result: null;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
/** Reactive state for a mutation cell: status, error/result, and execute/abort/reset controls. */
|
|
266
|
+
type Mutation<TInput, TResult> = MutationControls<TInput, TResult> &
|
|
267
|
+
(MutationIdle | MutationPending | MutationSuccess<TResult> | MutationError);
|
|
268
|
+
|
|
269
|
+
type QueryOptions<T> = {
|
|
270
|
+
key: string;
|
|
271
|
+
fetch: (ctx: { signal: AbortSignal }) => Promise<T>;
|
|
272
|
+
isConsistent?: (data: T) => boolean;
|
|
273
|
+
reconcile?: (
|
|
274
|
+
data: T,
|
|
275
|
+
ctx: {
|
|
276
|
+
key: string;
|
|
277
|
+
}
|
|
278
|
+
) => Promise<boolean> | boolean;
|
|
279
|
+
runtime?: DataRuntime;
|
|
280
|
+
initialData?: T;
|
|
281
|
+
skipInitialFetch?: boolean;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
/** Options for {@link createMutation}. */
|
|
285
|
+
type MutationOptions<TInput, TResult> = {
|
|
286
|
+
/** Stable identity used by runtime-scoped mutation test overrides. */
|
|
287
|
+
key?: string;
|
|
288
|
+
action: (
|
|
289
|
+
input: TInput,
|
|
290
|
+
ctx: {
|
|
291
|
+
signal: AbortSignal;
|
|
292
|
+
}
|
|
293
|
+
) => Promise<TResult>;
|
|
294
|
+
affects?: (input: TInput, result: TResult) => string[];
|
|
295
|
+
afterSuccess?: 'invalidate';
|
|
296
|
+
runtime?: DataRuntime;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Create a reactive {@link Mutation} cell bound to the current component,
|
|
301
|
+
* running `options.action` on `execute()` and optionally invalidating
|
|
302
|
+
* affected query prefixes on success.
|
|
303
|
+
*/
|
|
304
|
+
declare function createMutation<TInput, TResult>(
|
|
305
|
+
options: MutationOptions<TInput, TResult>
|
|
306
|
+
): Mutation<TInput, TResult>;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Create a reactive {@link Query} cell bound to the current component, either
|
|
310
|
+
* from inline `options` (key + fetch) or a reusable {@link QueryDefinition}
|
|
311
|
+
* plus its input.
|
|
312
|
+
*/
|
|
313
|
+
declare function createQuery<T extends {}>(options: QueryOptions<T>): Query<T>;
|
|
314
|
+
|
|
315
|
+
declare function createQuery<TInput, TResult extends {}>(
|
|
316
|
+
definition: QueryDefinition<TInput, TResult>,
|
|
317
|
+
input: TInput,
|
|
318
|
+
options?: Omit<QueryOptions<TResult>, 'key' | 'fetch'>
|
|
319
|
+
): Query<TResult>;
|
|
320
|
+
|
|
321
|
+
/** Create a new, isolated {@link DataRuntime} with its own query/mutation caches. */
|
|
322
|
+
declare function createDataRuntime(options?: DataRuntimeOptions): DataRuntime;
|
|
323
|
+
|
|
324
|
+
/** Get the process-wide default {@link DataRuntime} used when none is provided explicitly. */
|
|
325
|
+
declare function getDefaultDataRuntime(): DataRuntime;
|
|
326
|
+
|
|
327
|
+
/** Mark all cached queries whose key starts with `prefix` as stale, triggering a refresh. */
|
|
328
|
+
declare function invalidate(prefix: string, options?: InvalidateOptions): void;
|
|
329
|
+
|
|
330
|
+
/** Create a {@link QueryScope} that namespaces keys and invalidations under `namespace`. */
|
|
331
|
+
declare function queryScope(namespace: string): QueryScope;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Periodically invalidate queries matching `prefix` on a fixed interval,
|
|
335
|
+
* optionally gated by active route, document visibility, or window focus.
|
|
336
|
+
*/
|
|
337
|
+
declare function invalidateOnInterval(
|
|
338
|
+
prefix: string,
|
|
339
|
+
options: InvalidateOnIntervalOptions
|
|
340
|
+
): void;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Create one lifecycle-owned collection of dynamically keyed readers for a
|
|
344
|
+
* reusable query definition, with bounded collection-started fetches.
|
|
345
|
+
*/
|
|
346
|
+
declare function createQueryCollection<
|
|
347
|
+
TInput,
|
|
348
|
+
TResult extends {},
|
|
349
|
+
TKey extends QueryCollectionKey = string,
|
|
350
|
+
>(
|
|
351
|
+
options: QueryCollectionOptions<TInput, TResult, TKey>
|
|
352
|
+
): QueryCollection<TInput, TResult, TKey>;
|
|
353
|
+
|
|
354
|
+
/** Lookup table of server handlers keyed by their {@link QueryDefinition}, built by {@link defineServerQueries}. */
|
|
355
|
+
interface ServerQueryRegistry {
|
|
356
|
+
readonly entries: readonly ServerQueryEntry<unknown, {}>[];
|
|
357
|
+
get<TInput, TResult extends {}>(
|
|
358
|
+
query: QueryDefinition<TInput, TResult>
|
|
359
|
+
): ServerQueryHandler<TInput, TResult> | undefined;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** A query paired with the server handler that resolves it, produced by {@link serveQuery}. */
|
|
363
|
+
interface ServerQueryEntry<TInput, TResult extends {}> {
|
|
364
|
+
readonly query: QueryDefinition<TInput, TResult>;
|
|
365
|
+
readonly handler: ServerQueryHandler<TInput, TResult>;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** Pair a {@link QueryDefinition} with the server-side handler that resolves it. */
|
|
369
|
+
declare function serveQuery<TInput, TResult extends {}>(
|
|
370
|
+
query: QueryDefinition<TInput, TResult>,
|
|
371
|
+
handler: ServerQueryHandler<TInput, TResult>
|
|
372
|
+
): ServerQueryEntry<TInput, TResult>;
|
|
373
|
+
|
|
374
|
+
/** Build a {@link ServerQueryRegistry} from one or more {@link serveQuery} entries. */
|
|
375
|
+
declare function defineServerQueries(
|
|
376
|
+
...entries: readonly ServerQueryEntry<any, any>[]
|
|
377
|
+
): ServerQueryRegistry;
|
|
378
|
+
|
|
379
|
+
/** Freeze and return a reusable {@link QueryDefinition}. */
|
|
380
|
+
declare function defineQuery<TInput, TResult extends {}>(
|
|
381
|
+
definition: QueryDefinition<TInput, TResult>
|
|
382
|
+
): QueryDefinition<TInput, TResult>;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Create a {@link QueryPrefetchContext} for prefetching query data ahead of
|
|
386
|
+
* render, e.g. during SSR route resolution.
|
|
387
|
+
*/
|
|
388
|
+
declare function createQueryPrefetchContext(options?: {
|
|
389
|
+
runtime?: DataRuntime;
|
|
390
|
+
registry?: ServerQueryRegistry;
|
|
391
|
+
request?: Request;
|
|
392
|
+
signal?: AbortSignal;
|
|
393
|
+
mode?: 'ssr' | 'spa';
|
|
394
|
+
telemetry?: CoreTelemetry;
|
|
395
|
+
}): QueryPrefetchContext;
|
|
396
|
+
|
|
397
|
+
/** Prefetch `query` with `input` into a {@link QueryPrefetchContext}'s runtime. */
|
|
398
|
+
declare function prefetchQuery<TInput, TResult extends {}>(
|
|
399
|
+
context: QueryPrefetchContext,
|
|
400
|
+
query: QueryDefinition<TInput, TResult>,
|
|
401
|
+
input: TInput
|
|
402
|
+
): Promise<boolean>;
|
|
403
|
+
|
|
404
|
+
/** Extract a runtime's cached query data into a JSON-serializable snapshot, dropping non-serializable values. */
|
|
405
|
+
declare function dehydrateDataRuntime(
|
|
406
|
+
runtime: DataRuntime
|
|
407
|
+
): Record<string, unknown>;
|
|
408
|
+
|
|
409
|
+
/** Load a {@link dehydrateDataRuntime} snapshot back into a runtime's query cache. */
|
|
410
|
+
declare function hydrateDataRuntime(runtime: DataRuntime, data: unknown): void;
|
|
411
|
+
export {
|
|
412
|
+
QueryConsistency,
|
|
413
|
+
QueryStaleReason,
|
|
414
|
+
DataRuntime,
|
|
415
|
+
DataRuntimeOptions,
|
|
416
|
+
QueryDefinition,
|
|
417
|
+
QueryCollectionKey,
|
|
418
|
+
QueryCollectionEntry,
|
|
419
|
+
QueryCollectionOptions,
|
|
420
|
+
QueryCollection,
|
|
421
|
+
QueryPrefetchContext,
|
|
422
|
+
ServerQueryHandler,
|
|
423
|
+
InvalidateOptions,
|
|
424
|
+
InvalidateOnIntervalOptions,
|
|
425
|
+
QueryKeyPart,
|
|
426
|
+
QueryScope,
|
|
427
|
+
QueryControls,
|
|
428
|
+
QueryLoading,
|
|
429
|
+
QueryFresh,
|
|
430
|
+
QueryRefreshing,
|
|
431
|
+
QueryPendingWrite,
|
|
432
|
+
QueryStaleValue,
|
|
433
|
+
QueryStaleErrorWithValue,
|
|
434
|
+
QueryStaleError,
|
|
435
|
+
Query,
|
|
436
|
+
MutationControls,
|
|
437
|
+
MutationIdle,
|
|
438
|
+
MutationPending,
|
|
439
|
+
MutationSuccess,
|
|
440
|
+
MutationError,
|
|
441
|
+
Mutation,
|
|
442
|
+
QueryOptions,
|
|
443
|
+
MutationOptions,
|
|
444
|
+
createMutation,
|
|
445
|
+
createQuery,
|
|
446
|
+
createDataRuntime,
|
|
447
|
+
getDefaultDataRuntime,
|
|
448
|
+
invalidate,
|
|
449
|
+
queryScope,
|
|
450
|
+
invalidateOnInterval,
|
|
451
|
+
createQueryCollection,
|
|
452
|
+
ServerQueryRegistry,
|
|
453
|
+
ServerQueryEntry,
|
|
454
|
+
serveQuery,
|
|
455
|
+
defineServerQueries,
|
|
456
|
+
defineQuery,
|
|
457
|
+
createQueryPrefetchContext,
|
|
458
|
+
prefetchQuery,
|
|
459
|
+
dehydrateDataRuntime,
|
|
460
|
+
hydrateDataRuntime,
|
|
461
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { JSXElementType, JSXElement, Props } from '../elements.js';
|
|
2
|
+
import '../jsx-globals.js';
|
|
3
|
+
import { AuthContext, AuthRequirement } from '@askrjs/auth';
|
|
4
|
+
import { InferSchema, ObjectSchema } from '@askrjs/schema';
|
|
5
|
+
|
|
6
|
+
interface RenderDiagnosticsOptions {
|
|
7
|
+
/** Emit one warning per component instance when a render exceeds the threshold. */
|
|
8
|
+
slowRenderWarnings?: boolean;
|
|
9
|
+
/** Slow-render threshold in milliseconds. The default is 5. */
|
|
10
|
+
slowRenderThresholdMs?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Configure development render diagnostics and return a function that restores
|
|
15
|
+
* the previous configuration. Component counters and timing remain enabled
|
|
16
|
+
* when warning output is disabled.
|
|
17
|
+
*/
|
|
18
|
+
declare function configureRenderDiagnostics(
|
|
19
|
+
options: RenderDiagnosticsOptions
|
|
20
|
+
): () => void;
|
|
21
|
+
export { RenderDiagnosticsOptions, configureRenderDiagnostics };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { JSXElementType, JSXElement, Props } from '../elements.js';
|
|
2
|
+
import '../jsx-globals.js';
|
|
3
|
+
import { AuthContext, AuthRequirement } from '@askrjs/auth';
|
|
4
|
+
import { InferSchema, ObjectSchema } from '@askrjs/schema';
|
|
5
|
+
import { ReadableSource } from './component.js';
|
|
6
|
+
|
|
7
|
+
/** A gating condition for lifecycle primitives like {@link timer}; `true` means active. */
|
|
8
|
+
type ActivityPredicate = () => boolean;
|
|
9
|
+
|
|
10
|
+
/** Options for {@link timer}. */
|
|
11
|
+
interface TimerOptions {
|
|
12
|
+
when?: ActivityPredicate | readonly ActivityPredicate[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** {@link ActivityPredicate} that is true while the current route matches `pathOrPaths`. */
|
|
16
|
+
declare function routeActive(
|
|
17
|
+
pathOrPaths: string | readonly string[]
|
|
18
|
+
): ActivityPredicate;
|
|
19
|
+
|
|
20
|
+
/** {@link ActivityPredicate} that is true while the document is visible. */
|
|
21
|
+
declare function documentVisible(): ActivityPredicate;
|
|
22
|
+
|
|
23
|
+
/** {@link ActivityPredicate} that is true while the window has focus. */
|
|
24
|
+
declare function windowFocused(): ActivityPredicate;
|
|
25
|
+
|
|
26
|
+
/** An event target, or a function resolving one, accepted by {@link on}. */
|
|
27
|
+
type ListenerTarget = EventTarget | (() => EventTarget | null | undefined);
|
|
28
|
+
|
|
29
|
+
type ListenerOptions = boolean | AddEventListenerOptions | undefined;
|
|
30
|
+
|
|
31
|
+
/** Attach an owned event listener to `target` for the current component's lifetime. */
|
|
32
|
+
declare function on(
|
|
33
|
+
target: ListenerTarget,
|
|
34
|
+
event: string,
|
|
35
|
+
handler: EventListener,
|
|
36
|
+
options?: ListenerOptions
|
|
37
|
+
): void;
|
|
38
|
+
|
|
39
|
+
/** Run `fn` on an owned interval for the current component's lifetime, optionally gated by `options.when`. */
|
|
40
|
+
declare function timer(
|
|
41
|
+
intervalMs: number,
|
|
42
|
+
fn: () => void,
|
|
43
|
+
options?: TimerOptions
|
|
44
|
+
): void;
|
|
45
|
+
|
|
46
|
+
/** Runs an owned task after commit. */
|
|
47
|
+
declare function task(
|
|
48
|
+
fn: () => void | (() => void) | PromiseLike<void | (() => void)>
|
|
49
|
+
): void;
|
|
50
|
+
|
|
51
|
+
/** A callable reactive source accepted by {@link watch}. */
|
|
52
|
+
type WatchSource<T> = ReadableSource<T>;
|
|
53
|
+
|
|
54
|
+
/** Values inferred from an ordered tuple of {@link WatchSource} accessors. */
|
|
55
|
+
type WatchValues<TSources extends readonly WatchSource<unknown>[]> = {
|
|
56
|
+
-readonly [TIndex in keyof TSources]: ReturnType<TSources[TIndex]>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** Post-commit generation details supplied to a {@link watch} callback. */
|
|
60
|
+
interface WatchContext<TValue> {
|
|
61
|
+
readonly initial: boolean;
|
|
62
|
+
readonly previous: TValue | undefined;
|
|
63
|
+
readonly signal: AbortSignal;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Owned side-effect callback invoked by {@link watch}. */
|
|
67
|
+
type WatchCallback<TValue> = (
|
|
68
|
+
value: TValue,
|
|
69
|
+
context: WatchContext<TValue>
|
|
70
|
+
) => void | (() => void) | PromiseLike<void>;
|
|
71
|
+
|
|
72
|
+
/** Observe one readable source after commit and whenever its value changes. */
|
|
73
|
+
declare function watch<TValue>(
|
|
74
|
+
source: WatchSource<TValue>,
|
|
75
|
+
callback: WatchCallback<TValue>
|
|
76
|
+
): void;
|
|
77
|
+
|
|
78
|
+
/** Observe an ordered tuple of readable sources after commit and whenever an entry changes. */
|
|
79
|
+
declare function watch<const TSources extends readonly WatchSource<unknown>[]>(
|
|
80
|
+
sources: TSources,
|
|
81
|
+
callback: WatchCallback<WatchValues<TSources>>
|
|
82
|
+
): void;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Capture the result of a synchronous expression at call time and return a
|
|
86
|
+
* thunk that returns the captured value later. This is a low-level helper for
|
|
87
|
+
* cases where async continuations need to observe a snapshot of values at the
|
|
88
|
+
* moment scheduling occurred.
|
|
89
|
+
*
|
|
90
|
+
* Usage (public API):
|
|
91
|
+
* const snapshot = capture(() => someState());
|
|
92
|
+
* Promise.resolve().then(() => { use(snapshot()); });
|
|
93
|
+
*/
|
|
94
|
+
declare function capture<T>(fn: () => T): () => T;
|
|
95
|
+
export {
|
|
96
|
+
ActivityPredicate,
|
|
97
|
+
TimerOptions,
|
|
98
|
+
routeActive,
|
|
99
|
+
documentVisible,
|
|
100
|
+
windowFocused,
|
|
101
|
+
ListenerTarget,
|
|
102
|
+
ListenerOptions,
|
|
103
|
+
on,
|
|
104
|
+
timer,
|
|
105
|
+
task,
|
|
106
|
+
WatchSource,
|
|
107
|
+
WatchValues,
|
|
108
|
+
WatchContext,
|
|
109
|
+
WatchCallback,
|
|
110
|
+
watch,
|
|
111
|
+
capture,
|
|
112
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JSXElementType, JSXElement, Props } from '../elements.js';
|
|
2
|
+
import '../jsx-globals.js';
|
|
3
|
+
import { AuthContext, AuthRequirement } from '@askrjs/auth';
|
|
4
|
+
import { InferSchema, ObjectSchema } from '@askrjs/schema';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a stable holder for an intrinsic element ref.
|
|
8
|
+
*
|
|
9
|
+
* The renderer mutates `current` during commit and clears it during cleanup.
|
|
10
|
+
* Updating the holder never schedules a render.
|
|
11
|
+
*/
|
|
12
|
+
interface Ref<T extends Element = Element> {
|
|
13
|
+
current: T | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Create a new, empty {@link Ref} holder. */
|
|
17
|
+
declare function createRef<T extends Element = Element>(): Ref<T>;
|
|
18
|
+
export { Ref, createRef };
|