sibujs 4.5.0 → 4.7.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 +1 -1
- package/dist/browser.cjs +326 -133
- package/dist/browser.d.cts +46 -14
- package/dist/browser.d.ts +46 -14
- package/dist/browser.js +8 -6
- package/dist/build.cjs +2094 -1033
- package/dist/build.d.cts +133 -44
- package/dist/build.d.ts +133 -44
- package/dist/build.js +1372 -574
- package/dist/cdn.dev.global.js +10 -10
- package/dist/cdn.full.dev.global.js +11 -11
- package/dist/cdn.full.global.js +10 -10
- package/dist/cdn.global.js +10 -10
- package/dist/{chunk-2DCGACUU.js → chunk-2BPG2XDA.js} +251 -66
- package/dist/{chunk-IXKSNWV5.js → chunk-2INLLLMZ.js} +1 -1
- package/dist/{chunk-4PMLNECI.js → chunk-3QWBSL5R.js} +98 -29
- package/dist/{chunk-KKLW7YWL.js → chunk-4AWA2PVD.js} +275 -144
- package/dist/chunk-5HZXGZ6T.js +24 -0
- package/dist/{chunk-PCT43HW3.js → chunk-7LUJQAOJ.js} +1 -1
- package/dist/{chunk-5DXA2J44.js → chunk-7XHATCIH.js} +5 -2
- package/dist/chunk-BC2SECJD.js +44 -0
- package/dist/{chunk-TBYTO6BS.js → chunk-BSY63EM6.js} +136 -80
- package/dist/{chunk-FTIR4QW2.js → chunk-DKXRACVN.js} +6 -8
- package/dist/{chunk-ONOHFDLG.js → chunk-FNJXNGYZ.js} +3 -3
- package/dist/{chunk-XZZOBQAY.js → chunk-FQRUXCEE.js} +6 -5
- package/dist/{chunk-NIOYEGBQ.js → chunk-HURREPU2.js} +27 -13
- package/dist/chunk-J6FW5TV6.js +233 -0
- package/dist/{chunk-UGRX3S57.js → chunk-JWKYU5GV.js} +22 -4
- package/dist/chunk-NYNYSPK7.js +318 -0
- package/dist/{chunk-RBTPLM32.js → chunk-RUSSKG6G.js} +13 -12
- package/dist/{chunk-7LN645I6.js → chunk-SLM3IA34.js} +3 -3
- package/dist/{chunk-R25EFXXC.js → chunk-TUCPL2HB.js} +3 -3
- package/dist/{chunk-B3WHI2QA.js → chunk-UNWRJRKC.js} +55 -31
- package/dist/{chunk-KEISJXBU.js → chunk-UOL2ECCS.js} +44 -17
- package/dist/{chunk-RJE2BNI4.js → chunk-VZSG24LS.js} +108 -45
- package/dist/{chunk-RIXRAYIU.js → chunk-WEQ3DMVL.js} +10 -4
- package/dist/{chunk-3JZ4L5TJ.js → chunk-WOLJZUFQ.js} +354 -90
- package/dist/{chunk-S373NSMK.js → chunk-XYV3EDB7.js} +283 -123
- package/dist/{chunk-VZKNK2V7.js → chunk-XZR4PXRE.js} +296 -38
- package/dist/{chunk-GW3SCCZG.js → chunk-Z3OHK6QT.js} +153 -110
- package/dist/{chunk-OMJJM3KM.js → chunk-ZVL7TY4K.js} +287 -130
- package/dist/{contracts-DBdg9J_a.d.ts → contracts-CLqzJnOV.d.ts} +36 -17
- package/dist/{contracts-DBdg9J_a.d.cts → contracts-CTOJXu-x.d.cts} +36 -17
- package/dist/{customElement-OB9CIsc5.d.cts → customElement-MmInOW1U.d.cts} +21 -0
- package/dist/{customElement-OB9CIsc5.d.ts → customElement-MmInOW1U.d.ts} +21 -0
- package/dist/data.cjs +410 -155
- package/dist/data.d.cts +166 -12
- package/dist/data.d.ts +166 -12
- package/dist/data.js +12 -9
- package/dist/devtools.cjs +98 -61
- package/dist/devtools.js +7 -8
- package/dist/dispose-GEIG2KOF.js +28 -0
- package/dist/ecosystem.cjs +372 -126
- package/dist/ecosystem.d.cts +20 -3
- package/dist/ecosystem.d.ts +20 -3
- package/dist/ecosystem.js +12 -12
- package/dist/extras.cjs +2366 -909
- package/dist/extras.d.cts +11 -9
- package/dist/extras.d.ts +11 -9
- package/dist/extras.js +39 -28
- package/dist/index.cjs +421 -158
- package/dist/index.d.cts +213 -171
- package/dist/index.d.ts +213 -171
- package/dist/index.js +24 -27
- package/dist/motion.cjs +118 -44
- package/dist/motion.js +5 -5
- package/dist/patterns.cjs +344 -53
- package/dist/patterns.d.cts +28 -9
- package/dist/patterns.d.ts +28 -9
- package/dist/patterns.js +8 -8
- package/dist/performance.cjs +325 -220
- package/dist/performance.d.cts +2 -2
- package/dist/performance.d.ts +2 -2
- package/dist/performance.js +8 -9
- package/dist/plugin-DVgSnTfK.d.cts +112 -0
- package/dist/plugin-DVgSnTfK.d.ts +112 -0
- package/dist/plugins.cjs +664 -233
- package/dist/plugins.d.cts +127 -14
- package/dist/plugins.d.ts +127 -14
- package/dist/plugins.js +96 -42
- package/dist/signal-EotCj4hS.d.cts +110 -0
- package/dist/signal-EotCj4hS.d.ts +110 -0
- package/dist/{ssr-BiPRdZ6n.d.cts → ssr-Bli9XRW5.d.cts} +5 -0
- package/dist/{ssr-BiPRdZ6n.d.ts → ssr-Bli9XRW5.d.ts} +5 -0
- package/dist/{ssr-Y7XOEPEN.js → ssr-XOTUASDO.js} +4 -5
- package/dist/ssr.cjs +229 -84
- package/dist/ssr.d.cts +9 -3
- package/dist/ssr.d.ts +9 -3
- package/dist/ssr.js +11 -12
- package/dist/{startup-BMpaiMhP.d.ts → startup-BLfSeL15.d.cts} +73 -22
- package/dist/{startup-BMpaiMhP.d.cts → startup-BLfSeL15.d.ts} +73 -22
- package/dist/tagFactory-8qL9LCIx.d.cts +156 -0
- package/dist/tagFactory-BL2fymez.d.ts +156 -0
- package/dist/testing.cjs +2503 -2191
- package/dist/testing.d.cts +56 -5
- package/dist/testing.d.ts +56 -5
- package/dist/testing.js +580 -307
- package/dist/types-CJFViL6Q.d.cts +26 -0
- package/dist/types-CJFViL6Q.d.ts +26 -0
- package/dist/ui.cjs +732 -329
- package/dist/ui.d.cts +41 -7
- package/dist/ui.d.ts +41 -7
- package/dist/ui.js +151 -56
- package/dist/widgets.cjs +267 -291
- package/dist/widgets.js +9 -10
- package/package.json +4 -2
- package/dist/chunk-2WLZ6757.js +0 -149
- package/dist/chunk-CCSJMTRN.js +0 -15
- package/dist/chunk-QKRPLZ2V.js +0 -108
- package/dist/chunk-VUF4ALSW.js +0 -60
- package/dist/chunk-WWV3SJ3L.js +0 -131
- package/dist/dispose-46BOMMQJ.js +0 -19
- package/dist/plugin-D30wlGW5.d.cts +0 -71
- package/dist/plugin-D30wlGW5.d.ts +0 -71
- package/dist/tagFactory-DVoDpHye.d.cts +0 -215
- package/dist/tagFactory-DVoDpHye.d.ts +0 -215
package/dist/data.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { D as DisposableAccessor } from './signal-EotCj4hS.cjs';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Configurable retry strategies for async operations.
|
|
3
5
|
* Used by `resource` and `query` for automatic error recovery.
|
|
@@ -55,6 +57,43 @@ declare function calculateDelay(attempt: number, strategy: "exponential" | "line
|
|
|
55
57
|
*/
|
|
56
58
|
declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions, onRetry?: (error: unknown, attempt: number, delay: number) => void, signal?: AbortSignal): Promise<T>;
|
|
57
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Structural sharing for the data layer.
|
|
62
|
+
*
|
|
63
|
+
* A refetch almost always produces a brand-new object graph, even when the
|
|
64
|
+
* server sent back exactly what it sent last time. Committing that graph to a
|
|
65
|
+
* signal notifies every subscriber — signals compare with `Object.is` — so a
|
|
66
|
+
* background refresh that changed nothing still re-ran every binding reading
|
|
67
|
+
* the data, and a `when(() => q.data(), …)` or a `() => q.data() && Form()`
|
|
68
|
+
* child rebuilt its subtree and threw away whatever the user was typing.
|
|
69
|
+
*
|
|
70
|
+
* `replaceEqualDeep(prev, next)` reconciles the new graph against the old one:
|
|
71
|
+
*
|
|
72
|
+
* - deeply equal → returns `prev` itself, so the signal write is a no-op and
|
|
73
|
+
* nothing is notified;
|
|
74
|
+
* - partially equal → returns a new container in which every unchanged
|
|
75
|
+
* subtree is the OLD reference, so an `each()` keyed by reference, a
|
|
76
|
+
* `derived` over one branch, or an `equals`-less signal holding a sub-object
|
|
77
|
+
* stays stable while only the changed path gets fresh identities.
|
|
78
|
+
*
|
|
79
|
+
* Only plain objects (prototype `Object.prototype` or `null`) and arrays are
|
|
80
|
+
* reconciled. Everything else — Date, Map, Set, class instances — is opaque
|
|
81
|
+
* and compared by identity: its enumerable keys say nothing about its state,
|
|
82
|
+
* and rebuilding it as a plain object would change its type.
|
|
83
|
+
*
|
|
84
|
+
* Internal to the data layer; not re-exported from `data.ts`.
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* The public knob shared by `query()` and `resource()`.
|
|
88
|
+
*
|
|
89
|
+
* - `true` (default) — reconcile with {@link replaceEqualDeep}.
|
|
90
|
+
* - `false` — commit every result as-is (a fresh reference notifies).
|
|
91
|
+
* - a function — custom reconciliation. It receives the previously committed
|
|
92
|
+
* value and the new one and returns what to commit; returning `prev` means
|
|
93
|
+
* "unchanged" and notifies nobody.
|
|
94
|
+
*/
|
|
95
|
+
type StructuralSharingOption<T> = boolean | ((prev: T, next: T) => T);
|
|
96
|
+
|
|
58
97
|
/**
|
|
59
98
|
* ## Callback semantics
|
|
60
99
|
*
|
|
@@ -116,8 +155,52 @@ interface QueryOptions<T> {
|
|
|
116
155
|
onError?: (error: Error) => void;
|
|
117
156
|
/** Called on fetch settle (success or error) */
|
|
118
157
|
onSettled?: () => void;
|
|
119
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* Transform fetched data before returning to consumers. Cache stores raw data.
|
|
160
|
+
*
|
|
161
|
+
* Runs in this observer's own reactive computation: it re-runs when the
|
|
162
|
+
* cached value changes, and when a signal it reads changes — without
|
|
163
|
+
* re-running the key effect, so such a signal never triggers a refetch. It
|
|
164
|
+
* runs once per fetch that changed the data, and its output is structurally
|
|
165
|
+
* shared against this observer's previous output for the same key, so an
|
|
166
|
+
* identical refetch notifies nobody.
|
|
167
|
+
*/
|
|
120
168
|
select?: (data: T) => T;
|
|
169
|
+
/**
|
|
170
|
+
* Keep data referentially stable across refetches. Default: `true`.
|
|
171
|
+
*
|
|
172
|
+
* Every refetch — `refetchInterval`, window focus, reconnect,
|
|
173
|
+
* `invalidateQueries` — produces a new object graph even when the server
|
|
174
|
+
* returned the same thing. With structural sharing on, the new result is
|
|
175
|
+
* reconciled against the previous value of the same key: if it is deeply
|
|
176
|
+
* equal the previous reference is kept and `data` subscribers are not
|
|
177
|
+
* notified at all; if only part of it changed, every unchanged nested object
|
|
178
|
+
* or array keeps its old reference, so `each()` rows and deriveds over
|
|
179
|
+
* untouched branches stay put. Only plain objects and arrays are compared —
|
|
180
|
+
* Date, Map, Set and class instances compare by identity. Cyclic data is
|
|
181
|
+
* safe: the containers on a cycle are taken as-is.
|
|
182
|
+
*
|
|
183
|
+
* Every observer of a key using the default holds the SAME reference.
|
|
184
|
+
*
|
|
185
|
+
* `setQueryData()` is an explicit write, not a fetch: when it hands over a
|
|
186
|
+
* new top-level reference, observers always receive a new top-level
|
|
187
|
+
* reference and are notified — even if every child is unchanged, as after
|
|
188
|
+
* `prev.items.push(x); return { ...prev }`. Unchanged nested subtrees are
|
|
189
|
+
* still reused beneath it.
|
|
190
|
+
*
|
|
191
|
+
* The option applies to this observer only; observers of one key may use
|
|
192
|
+
* different settings.
|
|
193
|
+
*
|
|
194
|
+
* - `false` commits every result as-is (each refetch notifies).
|
|
195
|
+
* - A function `(prev, next) => T` replaces the default reconciliation;
|
|
196
|
+
* `prev` is this observer's previous value for the same key. Return `prev`
|
|
197
|
+
* to report "unchanged" (ignored for an explicit write of a new
|
|
198
|
+
* reference). It must not throw — if it does, the error is reported and
|
|
199
|
+
* `next` is committed unshared.
|
|
200
|
+
*
|
|
201
|
+
* Also applied to this observer's `select` output.
|
|
202
|
+
*/
|
|
203
|
+
structuralSharing?: StructuralSharingOption<T>;
|
|
121
204
|
}
|
|
122
205
|
interface QueryResult<T> {
|
|
123
206
|
/** Reactive getter for the cached data */
|
|
@@ -141,9 +224,20 @@ declare function query<T>(key: string | (() => string), fetcher: (ctx: {
|
|
|
141
224
|
}) => Promise<T>, options?: QueryOptions<T>): QueryResult<T>;
|
|
142
225
|
/** Invalidate queries matching a key or predicate, triggering refetch for active subscribers */
|
|
143
226
|
declare function invalidateQueries(keyOrPredicate: string | ((key: string) => boolean)): void;
|
|
144
|
-
/**
|
|
227
|
+
/**
|
|
228
|
+
* Get cached data for a query key — the same reference every observer using
|
|
229
|
+
* the default `structuralSharing` holds.
|
|
230
|
+
*/
|
|
145
231
|
declare function getQueryData<T>(key: string): T | undefined;
|
|
146
|
-
/**
|
|
232
|
+
/**
|
|
233
|
+
* Set cached data for a query key, notifying subscribers.
|
|
234
|
+
*
|
|
235
|
+
* An explicit write: a value (or updater result) that is a new top-level
|
|
236
|
+
* reference reaches every observer as a new top-level reference, even when it
|
|
237
|
+
* is deeply equal to the previous value — so `prev.items.push(x); return
|
|
238
|
+
* { ...prev }` is never dropped. Unchanged nested subtrees are still reused.
|
|
239
|
+
* Returning `prev` itself changes nothing.
|
|
240
|
+
*/
|
|
147
241
|
declare function setQueryData<T>(key: string, data: T | ((prev: T | undefined) => T)): void;
|
|
148
242
|
/** Clear the entire query cache */
|
|
149
243
|
declare function clearQueryCache(): void;
|
|
@@ -278,7 +372,8 @@ declare function infiniteQuery<TData, TPageParam = number>(key: string | (() =>
|
|
|
278
372
|
* Returns `undefined` on first read (there is no previous value yet).
|
|
279
373
|
*
|
|
280
374
|
* @param getter A reactive getter to track
|
|
281
|
-
* @returns A reactive getter for the previous value
|
|
375
|
+
* @returns A reactive getter for the previous value, with `dispose()` to stop
|
|
376
|
+
* tracking the source
|
|
282
377
|
*
|
|
283
378
|
* @example
|
|
284
379
|
* ```ts
|
|
@@ -291,7 +386,7 @@ declare function infiniteQuery<TData, TPageParam = number>(key: string | (() =>
|
|
|
291
386
|
* prev(); // 5
|
|
292
387
|
* ```
|
|
293
388
|
*/
|
|
294
|
-
declare function previous<T>(getter: () => T):
|
|
389
|
+
declare function previous<T>(getter: () => T): DisposableAccessor<T | undefined>;
|
|
295
390
|
|
|
296
391
|
/**
|
|
297
392
|
* Returns a debounced reactive getter that only updates after `delay` ms
|
|
@@ -299,7 +394,8 @@ declare function previous<T>(getter: () => T): () => T | undefined;
|
|
|
299
394
|
*
|
|
300
395
|
* @param getter A reactive getter to debounce
|
|
301
396
|
* @param delay Debounce delay in milliseconds
|
|
302
|
-
* @returns A reactive getter for the debounced value
|
|
397
|
+
* @returns A reactive getter for the debounced value, with `dispose()` to stop
|
|
398
|
+
* tracking the source and cancel the pending timer
|
|
303
399
|
*
|
|
304
400
|
* @example
|
|
305
401
|
* ```ts
|
|
@@ -308,7 +404,7 @@ declare function previous<T>(getter: () => T): () => T | undefined;
|
|
|
308
404
|
* // debouncedSearch() only updates 300ms after the last setSearch call
|
|
309
405
|
* ```
|
|
310
406
|
*/
|
|
311
|
-
declare function debounce<T>(getter: () => T, delay: number):
|
|
407
|
+
declare function debounce<T>(getter: () => T, delay: number): DisposableAccessor<T>;
|
|
312
408
|
|
|
313
409
|
/**
|
|
314
410
|
* Returns a throttled reactive getter that updates at most once per `interval` ms.
|
|
@@ -317,7 +413,8 @@ declare function debounce<T>(getter: () => T, delay: number): () => T;
|
|
|
317
413
|
*
|
|
318
414
|
* @param getter A reactive getter to throttle
|
|
319
415
|
* @param interval Throttle interval in milliseconds
|
|
320
|
-
* @returns A reactive getter for the throttled value
|
|
416
|
+
* @returns A reactive getter for the throttled value, with `dispose()` to stop
|
|
417
|
+
* tracking the source and clear the cooldown timer
|
|
321
418
|
*
|
|
322
419
|
* @example
|
|
323
420
|
* ```ts
|
|
@@ -326,7 +423,7 @@ declare function debounce<T>(getter: () => T, delay: number): () => T;
|
|
|
326
423
|
* // throttled() updates at most once every 100ms
|
|
327
424
|
* ```
|
|
328
425
|
*/
|
|
329
|
-
declare function throttle<T>(getter: () => T, interval: number):
|
|
426
|
+
declare function throttle<T>(getter: () => T, interval: number): DisposableAccessor<T>;
|
|
330
427
|
|
|
331
428
|
/**
|
|
332
429
|
* Lifecycle callbacks follow the shared data-layer contract: an exception
|
|
@@ -349,6 +446,30 @@ interface ResourceOptions<T> {
|
|
|
349
446
|
onError?: (error: Error) => void;
|
|
350
447
|
/** Called on fetch settle (success or error) */
|
|
351
448
|
onSettled?: () => void;
|
|
449
|
+
/**
|
|
450
|
+
* Keep data referentially stable across refetches. Default: `true`.
|
|
451
|
+
*
|
|
452
|
+
* Each fetched result — from `refetch()` or a source change — is
|
|
453
|
+
* reconciled against the value already held: a deeply equal result keeps
|
|
454
|
+
* the previous reference and notifies nobody, and a partially changed one
|
|
455
|
+
* reuses every unchanged nested object or array. Only plain objects and
|
|
456
|
+
* arrays are compared; Date, Map, Set and class instances compare by
|
|
457
|
+
* identity. Cyclic data is safe: the containers on a cycle are taken as-is.
|
|
458
|
+
* Same contract as `QueryOptions.structuralSharing`.
|
|
459
|
+
*
|
|
460
|
+
* `mutate()` is an explicit write, not a fetch: when it hands over a new
|
|
461
|
+
* top-level reference, `data` always becomes a new top-level reference and
|
|
462
|
+
* notifies — even if every child is unchanged, as after
|
|
463
|
+
* `prev.items.push(x); return { ...prev }`. Unchanged nested subtrees are
|
|
464
|
+
* still reused beneath it.
|
|
465
|
+
*
|
|
466
|
+
* - `false` commits every result as-is.
|
|
467
|
+
* - A function `(prev, next) => T` replaces the default reconciliation;
|
|
468
|
+
* return `prev` to report "unchanged" (ignored for a `mutate()` of a new
|
|
469
|
+
* reference). If it throws, the error is reported and `next` is committed
|
|
470
|
+
* unshared.
|
|
471
|
+
*/
|
|
472
|
+
structuralSharing?: StructuralSharingOption<T>;
|
|
352
473
|
}
|
|
353
474
|
interface Resource<T> {
|
|
354
475
|
/** Reactive getter for the fetched data */
|
|
@@ -527,14 +648,47 @@ interface LoaderRoute {
|
|
|
527
648
|
}
|
|
528
649
|
/**
|
|
529
650
|
* Execute a route loader and wrap its result in a reactive Resource.
|
|
651
|
+
*
|
|
652
|
+
* Executing a loader does not make its data visible to `loaderData()`; render
|
|
653
|
+
* the route's component inside {@link renderWithLoader} (or use
|
|
654
|
+
* {@link withLoader}) so the component reads its own route's data.
|
|
530
655
|
*/
|
|
531
656
|
declare function executeLoader<T>(loader: RouteLoaderFn<T>, context: {
|
|
532
657
|
params: Record<string, string>;
|
|
533
658
|
path: string;
|
|
534
659
|
}, options?: ResourceOptions<T>): Resource<T>;
|
|
535
660
|
/**
|
|
536
|
-
*
|
|
537
|
-
*
|
|
661
|
+
* Run `render` with `loader` as the loader data seen by `loaderData()`, then
|
|
662
|
+
* restore the previous scope — even if `render` throws. Scopes nest: an inner
|
|
663
|
+
* call shadows the outer one only for its own duration.
|
|
664
|
+
*
|
|
665
|
+
* `loaderData()` must be called synchronously while `render` runs (typically at
|
|
666
|
+
* the top of the component); the accessors it returns stay bound to `loader`
|
|
667
|
+
* afterwards.
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* ```ts
|
|
671
|
+
* const data = executeLoader(route.loader, ctx);
|
|
672
|
+
* const view = renderWithLoader(data, () => route.component());
|
|
673
|
+
* ```
|
|
674
|
+
*/
|
|
675
|
+
declare function renderWithLoader<T, R>(loader: Resource<T>, render: () => R): R;
|
|
676
|
+
/**
|
|
677
|
+
* Execute `loader` and render with its data in scope, in one step. Returns the
|
|
678
|
+
* rendered result together with the resource, which the caller disposes when
|
|
679
|
+
* the route unmounts.
|
|
680
|
+
*/
|
|
681
|
+
declare function withLoader<T, R>(loader: RouteLoaderFn<T>, context: {
|
|
682
|
+
params: Record<string, string>;
|
|
683
|
+
path: string;
|
|
684
|
+
}, render: () => R, options?: ResourceOptions<T>): {
|
|
685
|
+
view: R;
|
|
686
|
+
resource: Resource<T>;
|
|
687
|
+
};
|
|
688
|
+
/**
|
|
689
|
+
* Access loader data from within a route component: the innermost
|
|
690
|
+
* {@link renderWithLoader} scope (per SSR request on the server). Throws when
|
|
691
|
+
* called outside such a scope, or when that scope's loader has been disposed.
|
|
538
692
|
*/
|
|
539
693
|
declare function loaderData<T = unknown>(): {
|
|
540
694
|
data: () => T | undefined;
|
|
@@ -596,4 +750,4 @@ declare function stream(url: string, options?: {
|
|
|
596
750
|
dispose: () => void;
|
|
597
751
|
};
|
|
598
752
|
|
|
599
|
-
export { type ConflictStrategy, type InfiniteQueryOptions, type InfiniteQueryResult, type LoaderRoute, type MutationOptions, type MutationResult, type OfflineStore, type OfflineStoreOptions, type QueryOptions, type QueryResult, type Resource, type ResourceOptions, type RetryOptions, type RouteLoaderFn, type SyncAdapter, type SyncChange, type SyncConflict, type SyncResult, __resetQueryCache, calculateDelay, clearQueryCache, debounce, executeLoader, getQueryData, infiniteQuery, invalidateQueries, loaderData, mutation, offlineStore, preloadRoute, previous, query, resource, setQueryData, socket, stream, syncAdapter, throttle, withRetry };
|
|
753
|
+
export { type ConflictStrategy, type InfiniteQueryOptions, type InfiniteQueryResult, type LoaderRoute, type MutationOptions, type MutationResult, type OfflineStore, type OfflineStoreOptions, type QueryOptions, type QueryResult, type Resource, type ResourceOptions, type RetryOptions, type RouteLoaderFn, type SyncAdapter, type SyncChange, type SyncConflict, type SyncResult, __resetQueryCache, calculateDelay, clearQueryCache, debounce, executeLoader, getQueryData, infiniteQuery, invalidateQueries, loaderData, mutation, offlineStore, preloadRoute, previous, query, renderWithLoader, resource, setQueryData, socket, stream, syncAdapter, throttle, withLoader, withRetry };
|
package/dist/data.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { D as DisposableAccessor } from './signal-EotCj4hS.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Configurable retry strategies for async operations.
|
|
3
5
|
* Used by `resource` and `query` for automatic error recovery.
|
|
@@ -55,6 +57,43 @@ declare function calculateDelay(attempt: number, strategy: "exponential" | "line
|
|
|
55
57
|
*/
|
|
56
58
|
declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions, onRetry?: (error: unknown, attempt: number, delay: number) => void, signal?: AbortSignal): Promise<T>;
|
|
57
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Structural sharing for the data layer.
|
|
62
|
+
*
|
|
63
|
+
* A refetch almost always produces a brand-new object graph, even when the
|
|
64
|
+
* server sent back exactly what it sent last time. Committing that graph to a
|
|
65
|
+
* signal notifies every subscriber — signals compare with `Object.is` — so a
|
|
66
|
+
* background refresh that changed nothing still re-ran every binding reading
|
|
67
|
+
* the data, and a `when(() => q.data(), …)` or a `() => q.data() && Form()`
|
|
68
|
+
* child rebuilt its subtree and threw away whatever the user was typing.
|
|
69
|
+
*
|
|
70
|
+
* `replaceEqualDeep(prev, next)` reconciles the new graph against the old one:
|
|
71
|
+
*
|
|
72
|
+
* - deeply equal → returns `prev` itself, so the signal write is a no-op and
|
|
73
|
+
* nothing is notified;
|
|
74
|
+
* - partially equal → returns a new container in which every unchanged
|
|
75
|
+
* subtree is the OLD reference, so an `each()` keyed by reference, a
|
|
76
|
+
* `derived` over one branch, or an `equals`-less signal holding a sub-object
|
|
77
|
+
* stays stable while only the changed path gets fresh identities.
|
|
78
|
+
*
|
|
79
|
+
* Only plain objects (prototype `Object.prototype` or `null`) and arrays are
|
|
80
|
+
* reconciled. Everything else — Date, Map, Set, class instances — is opaque
|
|
81
|
+
* and compared by identity: its enumerable keys say nothing about its state,
|
|
82
|
+
* and rebuilding it as a plain object would change its type.
|
|
83
|
+
*
|
|
84
|
+
* Internal to the data layer; not re-exported from `data.ts`.
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* The public knob shared by `query()` and `resource()`.
|
|
88
|
+
*
|
|
89
|
+
* - `true` (default) — reconcile with {@link replaceEqualDeep}.
|
|
90
|
+
* - `false` — commit every result as-is (a fresh reference notifies).
|
|
91
|
+
* - a function — custom reconciliation. It receives the previously committed
|
|
92
|
+
* value and the new one and returns what to commit; returning `prev` means
|
|
93
|
+
* "unchanged" and notifies nobody.
|
|
94
|
+
*/
|
|
95
|
+
type StructuralSharingOption<T> = boolean | ((prev: T, next: T) => T);
|
|
96
|
+
|
|
58
97
|
/**
|
|
59
98
|
* ## Callback semantics
|
|
60
99
|
*
|
|
@@ -116,8 +155,52 @@ interface QueryOptions<T> {
|
|
|
116
155
|
onError?: (error: Error) => void;
|
|
117
156
|
/** Called on fetch settle (success or error) */
|
|
118
157
|
onSettled?: () => void;
|
|
119
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* Transform fetched data before returning to consumers. Cache stores raw data.
|
|
160
|
+
*
|
|
161
|
+
* Runs in this observer's own reactive computation: it re-runs when the
|
|
162
|
+
* cached value changes, and when a signal it reads changes — without
|
|
163
|
+
* re-running the key effect, so such a signal never triggers a refetch. It
|
|
164
|
+
* runs once per fetch that changed the data, and its output is structurally
|
|
165
|
+
* shared against this observer's previous output for the same key, so an
|
|
166
|
+
* identical refetch notifies nobody.
|
|
167
|
+
*/
|
|
120
168
|
select?: (data: T) => T;
|
|
169
|
+
/**
|
|
170
|
+
* Keep data referentially stable across refetches. Default: `true`.
|
|
171
|
+
*
|
|
172
|
+
* Every refetch — `refetchInterval`, window focus, reconnect,
|
|
173
|
+
* `invalidateQueries` — produces a new object graph even when the server
|
|
174
|
+
* returned the same thing. With structural sharing on, the new result is
|
|
175
|
+
* reconciled against the previous value of the same key: if it is deeply
|
|
176
|
+
* equal the previous reference is kept and `data` subscribers are not
|
|
177
|
+
* notified at all; if only part of it changed, every unchanged nested object
|
|
178
|
+
* or array keeps its old reference, so `each()` rows and deriveds over
|
|
179
|
+
* untouched branches stay put. Only plain objects and arrays are compared —
|
|
180
|
+
* Date, Map, Set and class instances compare by identity. Cyclic data is
|
|
181
|
+
* safe: the containers on a cycle are taken as-is.
|
|
182
|
+
*
|
|
183
|
+
* Every observer of a key using the default holds the SAME reference.
|
|
184
|
+
*
|
|
185
|
+
* `setQueryData()` is an explicit write, not a fetch: when it hands over a
|
|
186
|
+
* new top-level reference, observers always receive a new top-level
|
|
187
|
+
* reference and are notified — even if every child is unchanged, as after
|
|
188
|
+
* `prev.items.push(x); return { ...prev }`. Unchanged nested subtrees are
|
|
189
|
+
* still reused beneath it.
|
|
190
|
+
*
|
|
191
|
+
* The option applies to this observer only; observers of one key may use
|
|
192
|
+
* different settings.
|
|
193
|
+
*
|
|
194
|
+
* - `false` commits every result as-is (each refetch notifies).
|
|
195
|
+
* - A function `(prev, next) => T` replaces the default reconciliation;
|
|
196
|
+
* `prev` is this observer's previous value for the same key. Return `prev`
|
|
197
|
+
* to report "unchanged" (ignored for an explicit write of a new
|
|
198
|
+
* reference). It must not throw — if it does, the error is reported and
|
|
199
|
+
* `next` is committed unshared.
|
|
200
|
+
*
|
|
201
|
+
* Also applied to this observer's `select` output.
|
|
202
|
+
*/
|
|
203
|
+
structuralSharing?: StructuralSharingOption<T>;
|
|
121
204
|
}
|
|
122
205
|
interface QueryResult<T> {
|
|
123
206
|
/** Reactive getter for the cached data */
|
|
@@ -141,9 +224,20 @@ declare function query<T>(key: string | (() => string), fetcher: (ctx: {
|
|
|
141
224
|
}) => Promise<T>, options?: QueryOptions<T>): QueryResult<T>;
|
|
142
225
|
/** Invalidate queries matching a key or predicate, triggering refetch for active subscribers */
|
|
143
226
|
declare function invalidateQueries(keyOrPredicate: string | ((key: string) => boolean)): void;
|
|
144
|
-
/**
|
|
227
|
+
/**
|
|
228
|
+
* Get cached data for a query key — the same reference every observer using
|
|
229
|
+
* the default `structuralSharing` holds.
|
|
230
|
+
*/
|
|
145
231
|
declare function getQueryData<T>(key: string): T | undefined;
|
|
146
|
-
/**
|
|
232
|
+
/**
|
|
233
|
+
* Set cached data for a query key, notifying subscribers.
|
|
234
|
+
*
|
|
235
|
+
* An explicit write: a value (or updater result) that is a new top-level
|
|
236
|
+
* reference reaches every observer as a new top-level reference, even when it
|
|
237
|
+
* is deeply equal to the previous value — so `prev.items.push(x); return
|
|
238
|
+
* { ...prev }` is never dropped. Unchanged nested subtrees are still reused.
|
|
239
|
+
* Returning `prev` itself changes nothing.
|
|
240
|
+
*/
|
|
147
241
|
declare function setQueryData<T>(key: string, data: T | ((prev: T | undefined) => T)): void;
|
|
148
242
|
/** Clear the entire query cache */
|
|
149
243
|
declare function clearQueryCache(): void;
|
|
@@ -278,7 +372,8 @@ declare function infiniteQuery<TData, TPageParam = number>(key: string | (() =>
|
|
|
278
372
|
* Returns `undefined` on first read (there is no previous value yet).
|
|
279
373
|
*
|
|
280
374
|
* @param getter A reactive getter to track
|
|
281
|
-
* @returns A reactive getter for the previous value
|
|
375
|
+
* @returns A reactive getter for the previous value, with `dispose()` to stop
|
|
376
|
+
* tracking the source
|
|
282
377
|
*
|
|
283
378
|
* @example
|
|
284
379
|
* ```ts
|
|
@@ -291,7 +386,7 @@ declare function infiniteQuery<TData, TPageParam = number>(key: string | (() =>
|
|
|
291
386
|
* prev(); // 5
|
|
292
387
|
* ```
|
|
293
388
|
*/
|
|
294
|
-
declare function previous<T>(getter: () => T):
|
|
389
|
+
declare function previous<T>(getter: () => T): DisposableAccessor<T | undefined>;
|
|
295
390
|
|
|
296
391
|
/**
|
|
297
392
|
* Returns a debounced reactive getter that only updates after `delay` ms
|
|
@@ -299,7 +394,8 @@ declare function previous<T>(getter: () => T): () => T | undefined;
|
|
|
299
394
|
*
|
|
300
395
|
* @param getter A reactive getter to debounce
|
|
301
396
|
* @param delay Debounce delay in milliseconds
|
|
302
|
-
* @returns A reactive getter for the debounced value
|
|
397
|
+
* @returns A reactive getter for the debounced value, with `dispose()` to stop
|
|
398
|
+
* tracking the source and cancel the pending timer
|
|
303
399
|
*
|
|
304
400
|
* @example
|
|
305
401
|
* ```ts
|
|
@@ -308,7 +404,7 @@ declare function previous<T>(getter: () => T): () => T | undefined;
|
|
|
308
404
|
* // debouncedSearch() only updates 300ms after the last setSearch call
|
|
309
405
|
* ```
|
|
310
406
|
*/
|
|
311
|
-
declare function debounce<T>(getter: () => T, delay: number):
|
|
407
|
+
declare function debounce<T>(getter: () => T, delay: number): DisposableAccessor<T>;
|
|
312
408
|
|
|
313
409
|
/**
|
|
314
410
|
* Returns a throttled reactive getter that updates at most once per `interval` ms.
|
|
@@ -317,7 +413,8 @@ declare function debounce<T>(getter: () => T, delay: number): () => T;
|
|
|
317
413
|
*
|
|
318
414
|
* @param getter A reactive getter to throttle
|
|
319
415
|
* @param interval Throttle interval in milliseconds
|
|
320
|
-
* @returns A reactive getter for the throttled value
|
|
416
|
+
* @returns A reactive getter for the throttled value, with `dispose()` to stop
|
|
417
|
+
* tracking the source and clear the cooldown timer
|
|
321
418
|
*
|
|
322
419
|
* @example
|
|
323
420
|
* ```ts
|
|
@@ -326,7 +423,7 @@ declare function debounce<T>(getter: () => T, delay: number): () => T;
|
|
|
326
423
|
* // throttled() updates at most once every 100ms
|
|
327
424
|
* ```
|
|
328
425
|
*/
|
|
329
|
-
declare function throttle<T>(getter: () => T, interval: number):
|
|
426
|
+
declare function throttle<T>(getter: () => T, interval: number): DisposableAccessor<T>;
|
|
330
427
|
|
|
331
428
|
/**
|
|
332
429
|
* Lifecycle callbacks follow the shared data-layer contract: an exception
|
|
@@ -349,6 +446,30 @@ interface ResourceOptions<T> {
|
|
|
349
446
|
onError?: (error: Error) => void;
|
|
350
447
|
/** Called on fetch settle (success or error) */
|
|
351
448
|
onSettled?: () => void;
|
|
449
|
+
/**
|
|
450
|
+
* Keep data referentially stable across refetches. Default: `true`.
|
|
451
|
+
*
|
|
452
|
+
* Each fetched result — from `refetch()` or a source change — is
|
|
453
|
+
* reconciled against the value already held: a deeply equal result keeps
|
|
454
|
+
* the previous reference and notifies nobody, and a partially changed one
|
|
455
|
+
* reuses every unchanged nested object or array. Only plain objects and
|
|
456
|
+
* arrays are compared; Date, Map, Set and class instances compare by
|
|
457
|
+
* identity. Cyclic data is safe: the containers on a cycle are taken as-is.
|
|
458
|
+
* Same contract as `QueryOptions.structuralSharing`.
|
|
459
|
+
*
|
|
460
|
+
* `mutate()` is an explicit write, not a fetch: when it hands over a new
|
|
461
|
+
* top-level reference, `data` always becomes a new top-level reference and
|
|
462
|
+
* notifies — even if every child is unchanged, as after
|
|
463
|
+
* `prev.items.push(x); return { ...prev }`. Unchanged nested subtrees are
|
|
464
|
+
* still reused beneath it.
|
|
465
|
+
*
|
|
466
|
+
* - `false` commits every result as-is.
|
|
467
|
+
* - A function `(prev, next) => T` replaces the default reconciliation;
|
|
468
|
+
* return `prev` to report "unchanged" (ignored for a `mutate()` of a new
|
|
469
|
+
* reference). If it throws, the error is reported and `next` is committed
|
|
470
|
+
* unshared.
|
|
471
|
+
*/
|
|
472
|
+
structuralSharing?: StructuralSharingOption<T>;
|
|
352
473
|
}
|
|
353
474
|
interface Resource<T> {
|
|
354
475
|
/** Reactive getter for the fetched data */
|
|
@@ -527,14 +648,47 @@ interface LoaderRoute {
|
|
|
527
648
|
}
|
|
528
649
|
/**
|
|
529
650
|
* Execute a route loader and wrap its result in a reactive Resource.
|
|
651
|
+
*
|
|
652
|
+
* Executing a loader does not make its data visible to `loaderData()`; render
|
|
653
|
+
* the route's component inside {@link renderWithLoader} (or use
|
|
654
|
+
* {@link withLoader}) so the component reads its own route's data.
|
|
530
655
|
*/
|
|
531
656
|
declare function executeLoader<T>(loader: RouteLoaderFn<T>, context: {
|
|
532
657
|
params: Record<string, string>;
|
|
533
658
|
path: string;
|
|
534
659
|
}, options?: ResourceOptions<T>): Resource<T>;
|
|
535
660
|
/**
|
|
536
|
-
*
|
|
537
|
-
*
|
|
661
|
+
* Run `render` with `loader` as the loader data seen by `loaderData()`, then
|
|
662
|
+
* restore the previous scope — even if `render` throws. Scopes nest: an inner
|
|
663
|
+
* call shadows the outer one only for its own duration.
|
|
664
|
+
*
|
|
665
|
+
* `loaderData()` must be called synchronously while `render` runs (typically at
|
|
666
|
+
* the top of the component); the accessors it returns stay bound to `loader`
|
|
667
|
+
* afterwards.
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* ```ts
|
|
671
|
+
* const data = executeLoader(route.loader, ctx);
|
|
672
|
+
* const view = renderWithLoader(data, () => route.component());
|
|
673
|
+
* ```
|
|
674
|
+
*/
|
|
675
|
+
declare function renderWithLoader<T, R>(loader: Resource<T>, render: () => R): R;
|
|
676
|
+
/**
|
|
677
|
+
* Execute `loader` and render with its data in scope, in one step. Returns the
|
|
678
|
+
* rendered result together with the resource, which the caller disposes when
|
|
679
|
+
* the route unmounts.
|
|
680
|
+
*/
|
|
681
|
+
declare function withLoader<T, R>(loader: RouteLoaderFn<T>, context: {
|
|
682
|
+
params: Record<string, string>;
|
|
683
|
+
path: string;
|
|
684
|
+
}, render: () => R, options?: ResourceOptions<T>): {
|
|
685
|
+
view: R;
|
|
686
|
+
resource: Resource<T>;
|
|
687
|
+
};
|
|
688
|
+
/**
|
|
689
|
+
* Access loader data from within a route component: the innermost
|
|
690
|
+
* {@link renderWithLoader} scope (per SSR request on the server). Throws when
|
|
691
|
+
* called outside such a scope, or when that scope's loader has been disposed.
|
|
538
692
|
*/
|
|
539
693
|
declare function loaderData<T = unknown>(): {
|
|
540
694
|
data: () => T | undefined;
|
|
@@ -596,4 +750,4 @@ declare function stream(url: string, options?: {
|
|
|
596
750
|
dispose: () => void;
|
|
597
751
|
};
|
|
598
752
|
|
|
599
|
-
export { type ConflictStrategy, type InfiniteQueryOptions, type InfiniteQueryResult, type LoaderRoute, type MutationOptions, type MutationResult, type OfflineStore, type OfflineStoreOptions, type QueryOptions, type QueryResult, type Resource, type ResourceOptions, type RetryOptions, type RouteLoaderFn, type SyncAdapter, type SyncChange, type SyncConflict, type SyncResult, __resetQueryCache, calculateDelay, clearQueryCache, debounce, executeLoader, getQueryData, infiniteQuery, invalidateQueries, loaderData, mutation, offlineStore, preloadRoute, previous, query, resource, setQueryData, socket, stream, syncAdapter, throttle, withRetry };
|
|
753
|
+
export { type ConflictStrategy, type InfiniteQueryOptions, type InfiniteQueryResult, type LoaderRoute, type MutationOptions, type MutationResult, type OfflineStore, type OfflineStoreOptions, type QueryOptions, type QueryResult, type Resource, type ResourceOptions, type RetryOptions, type RouteLoaderFn, type SyncAdapter, type SyncChange, type SyncConflict, type SyncResult, __resetQueryCache, calculateDelay, clearQueryCache, debounce, executeLoader, getQueryData, infiniteQuery, invalidateQueries, loaderData, mutation, offlineStore, preloadRoute, previous, query, renderWithLoader, resource, setQueryData, socket, stream, syncAdapter, throttle, withLoader, withRetry };
|
package/dist/data.js
CHANGED
|
@@ -13,23 +13,24 @@ import {
|
|
|
13
13
|
preloadRoute,
|
|
14
14
|
previous,
|
|
15
15
|
query,
|
|
16
|
+
renderWithLoader,
|
|
16
17
|
resource,
|
|
17
18
|
setQueryData,
|
|
18
19
|
socket,
|
|
19
20
|
stream,
|
|
20
21
|
syncAdapter,
|
|
21
22
|
throttle,
|
|
23
|
+
withLoader,
|
|
22
24
|
withRetry
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
import "./chunk-
|
|
25
|
-
import "./chunk-
|
|
26
|
-
import "./chunk-IXKSNWV5.js";
|
|
25
|
+
} from "./chunk-WOLJZUFQ.js";
|
|
26
|
+
import "./chunk-RUSSKG6G.js";
|
|
27
|
+
import "./chunk-2INLLLMZ.js";
|
|
27
28
|
import "./chunk-7ZHH77QA.js";
|
|
28
|
-
import "./chunk-
|
|
29
|
-
import "./chunk-
|
|
30
|
-
import "./chunk-
|
|
31
|
-
import "./chunk-
|
|
32
|
-
import "./chunk-
|
|
29
|
+
import "./chunk-WEQ3DMVL.js";
|
|
30
|
+
import "./chunk-7XHATCIH.js";
|
|
31
|
+
import "./chunk-FQRUXCEE.js";
|
|
32
|
+
import "./chunk-JWKYU5GV.js";
|
|
33
|
+
import "./chunk-NYNYSPK7.js";
|
|
33
34
|
export {
|
|
34
35
|
__resetQueryCache,
|
|
35
36
|
calculateDelay,
|
|
@@ -45,11 +46,13 @@ export {
|
|
|
45
46
|
preloadRoute,
|
|
46
47
|
previous,
|
|
47
48
|
query,
|
|
49
|
+
renderWithLoader,
|
|
48
50
|
resource,
|
|
49
51
|
setQueryData,
|
|
50
52
|
socket,
|
|
51
53
|
stream,
|
|
52
54
|
syncAdapter,
|
|
53
55
|
throttle,
|
|
56
|
+
withLoader,
|
|
54
57
|
withRetry
|
|
55
58
|
};
|