@taladb/react 0.9.3 → 0.10.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/LICENSE +202 -21
- package/dist/index.d.mts +175 -41
- package/dist/index.d.ts +175 -41
- package/dist/index.js +383 -146
- package/dist/index.mjs +393 -149
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,21 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025-2026 thinkgrid-labs
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { CollectionOptions, Document, TalaDB, OpenDBOptions, Collection, Filter } from 'taladb';
|
|
3
|
+
import { CollectionOptions, Document, TalaDB, OpenDBOptions, Collection, Filter, AggregatePipeline, RestSourceOptions, ReplicationSource, CoverageState } from 'taladb';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Per-collection options (`schema`, `syncSchema`, `migrateDocument`, …), keyed by
|
|
@@ -163,6 +163,40 @@ interface FindOneResult<T> {
|
|
|
163
163
|
*/
|
|
164
164
|
declare function useFindOne<T extends Document>(collection: Collection<T>, filter: Filter<T>): FindOneResult<T>;
|
|
165
165
|
|
|
166
|
+
interface AggregateResult<R> {
|
|
167
|
+
/** The current pipeline results. Empty while loading. */
|
|
168
|
+
data: R[];
|
|
169
|
+
/** True until the first snapshot has been delivered. */
|
|
170
|
+
loading: boolean;
|
|
171
|
+
/** Most recent subscription error, cleared by the next successful snapshot. */
|
|
172
|
+
error: unknown | null;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Subscribe to a **live aggregation**. Re-renders whenever the results change.
|
|
176
|
+
*
|
|
177
|
+
* This is the paging primitive. `find()` has no sort/skip/limit — only `aggregate`
|
|
178
|
+
* does — but `aggregate` on its own returns a *dead snapshot*: call it in an effect
|
|
179
|
+
* and the page sits frozen while a background hydration fills the collection
|
|
180
|
+
* underneath it. The user watches a spinner finish and the rows never arrive.
|
|
181
|
+
*
|
|
182
|
+
* So anything that pages locally subscribes here rather than calling `aggregate`
|
|
183
|
+
* directly.
|
|
184
|
+
*
|
|
185
|
+
* @param collection A `Collection<T>` (memoize it, or take it from `useCollection`).
|
|
186
|
+
* @param pipeline Inline arrays are safe — the pipeline is serialised for
|
|
187
|
+
* subscription identity, so a fresh array each render does not
|
|
188
|
+
* re-subscribe.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* const page = useAggregate<Product, Product>(products, [
|
|
192
|
+
* { $match: { category: 'kitchen' } },
|
|
193
|
+
* { $sort: { price: 1 } },
|
|
194
|
+
* { $skip: 100 },
|
|
195
|
+
* { $limit: 100 },
|
|
196
|
+
* ])
|
|
197
|
+
*/
|
|
198
|
+
declare function useAggregate<T extends Document, R extends Document = T>(collection: Collection<T>, pipeline: AggregatePipeline<T>): AggregateResult<R>;
|
|
199
|
+
|
|
166
200
|
/** Resolved network configuration for one replicated slice. */
|
|
167
201
|
interface ResolvedReplicationConfig {
|
|
168
202
|
/** Base URL; `/push` and `/pull` are appended by {@link HttpSyncAdapter}. */
|
|
@@ -183,6 +217,37 @@ interface ResolvedReplicationConfig {
|
|
|
183
217
|
};
|
|
184
218
|
}
|
|
185
219
|
|
|
220
|
+
/** When the background hydration walk is allowed to start. */
|
|
221
|
+
type HydrateMode =
|
|
222
|
+
/** Immediately on mount. */
|
|
223
|
+
'eager'
|
|
224
|
+
/** When the browser is idle (default). Keeps first paint responsive. */
|
|
225
|
+
| 'idle'
|
|
226
|
+
/** Never automatically — the app calls `hydrate()` itself. */
|
|
227
|
+
| 'manual';
|
|
228
|
+
interface ReplicateScope<RemoteRow = any, T extends Document = Document> extends Omit<RestSourceOptions<RemoteRow, T>, 'collection'> {
|
|
229
|
+
/**
|
|
230
|
+
* Provide a fully custom source instead of the REST defaults. When present,
|
|
231
|
+
* every other field here is ignored.
|
|
232
|
+
*/
|
|
233
|
+
source?: ReplicationSource<RemoteRow, T>;
|
|
234
|
+
hydrate?: HydrateMode;
|
|
235
|
+
/** Rows per bootstrap page. Default 500. */
|
|
236
|
+
pageSize?: number;
|
|
237
|
+
/** Re-check the origin for changes on this interval. `0` disables. */
|
|
238
|
+
refreshMs?: number;
|
|
239
|
+
/**
|
|
240
|
+
* Fetch the current query directly when coverage isn't ready yet, so a cold
|
|
241
|
+
* start paints immediately. Default `true`.
|
|
242
|
+
*
|
|
243
|
+
* Mandatory in practice for a Vite SPA or React Native, which have no server
|
|
244
|
+
* render to paint behind while the replica fills.
|
|
245
|
+
*/
|
|
246
|
+
bridge?: boolean;
|
|
247
|
+
}
|
|
248
|
+
/** One entry per local collection. */
|
|
249
|
+
type ReplicateRegistry = Record<string, ReplicateScope<any, any>>;
|
|
250
|
+
|
|
186
251
|
/** A slice to warm on first run — a collection, optionally on a specific endpoint. */
|
|
187
252
|
type PrefetchSlice = {
|
|
188
253
|
collection: string;
|
|
@@ -236,7 +301,15 @@ interface ReplicationConfig {
|
|
|
236
301
|
/** Max concurrent prefetch pulls — keeps the active page from starving. Default `2`. */
|
|
237
302
|
prefetchConcurrency?: number;
|
|
238
303
|
}
|
|
239
|
-
interface ReplicationProviderProps extends ReplicationConfig {
|
|
304
|
+
interface ReplicationProviderProps extends Partial<ReplicationConfig> {
|
|
305
|
+
/**
|
|
306
|
+
* Collections to replicate from a remote origin, keyed by local collection name.
|
|
307
|
+
*
|
|
308
|
+
* This is what makes `useQuery` a local read: once a collection is fully
|
|
309
|
+
* hydrated for its scope, filtering, sorting and paging never touch the network.
|
|
310
|
+
* See {@link ReplicateRegistry}.
|
|
311
|
+
*/
|
|
312
|
+
replicate?: ReplicateRegistry;
|
|
240
313
|
children: ReactNode;
|
|
241
314
|
}
|
|
242
315
|
/**
|
|
@@ -257,7 +330,7 @@ interface ReplicationProviderProps extends ReplicationConfig {
|
|
|
257
330
|
* </TalaDBProvider>
|
|
258
331
|
* ```
|
|
259
332
|
*/
|
|
260
|
-
declare function ReplicationProvider({ children, ...config }: ReplicationProviderProps): react_jsx_runtime.JSX.Element;
|
|
333
|
+
declare function ReplicationProvider({ children, replicate, ...config }: ReplicationProviderProps): react_jsx_runtime.JSX.Element;
|
|
261
334
|
/**
|
|
262
335
|
* Read the nearest replication config, merged with per-hook overrides.
|
|
263
336
|
* Non-throwing: `config` is `null` when no endpoint is resolvable (valid for
|
|
@@ -268,73 +341,134 @@ declare function useReplicationConfig(overrides?: Partial<ReplicationConfig>): {
|
|
|
268
341
|
pollMs: number;
|
|
269
342
|
};
|
|
270
343
|
|
|
344
|
+
interface Coverage {
|
|
345
|
+
/** The raw state machine value. */
|
|
346
|
+
status: CoverageState['status'];
|
|
347
|
+
/**
|
|
348
|
+
* Whether a purely local read is authorized.
|
|
349
|
+
*
|
|
350
|
+
* True **only** for `complete`. Notably *not* for `best-effort`, which means we
|
|
351
|
+
* applied every row the origin gave us but the origin could not pin a snapshot —
|
|
352
|
+
* so a row that shifted between pages during the walk may never have been seen,
|
|
353
|
+
* and we cannot prove the replica is whole. Serving that as authoritative would
|
|
354
|
+
* silently return incomplete results, which is worse than going to the network.
|
|
355
|
+
*/
|
|
356
|
+
ready: boolean;
|
|
357
|
+
/** Rows hydrated so far. */
|
|
358
|
+
rows: number;
|
|
359
|
+
/** Total rows in scope when supplied by the origin. */
|
|
360
|
+
total?: number;
|
|
361
|
+
/** 0–1 when the origin reported a total; otherwise undefined. */
|
|
362
|
+
progress?: number;
|
|
363
|
+
/** Present on `error`, `stale` and `best-effort`. */
|
|
364
|
+
reason?: string;
|
|
365
|
+
}
|
|
271
366
|
/**
|
|
272
|
-
* How a
|
|
273
|
-
*
|
|
274
|
-
*
|
|
367
|
+
* How much of a collection is local, and whether it can be trusted for a
|
|
368
|
+
* network-free read.
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* const { ready, progress } = useCoverage('products')
|
|
372
|
+
* if (!ready) return <ProgressBar value={progress} />
|
|
275
373
|
*/
|
|
374
|
+
declare function useCoverage(collection: string): Coverage;
|
|
375
|
+
/** Semantic alias for progress-oriented UIs. */
|
|
376
|
+
declare const useHydrationProgress: typeof useCoverage;
|
|
377
|
+
|
|
276
378
|
type ReadSource = 'local-first' | 'remote-first' | 'local-only';
|
|
277
379
|
interface UseQueryOptions<T extends Document> extends Partial<Pick<ReplicationConfig, 'endpoint' | 'getAuth' | 'fetch' | 'paths' | 'pollMs'>> {
|
|
278
|
-
/**
|
|
380
|
+
/** The local collection to read. */
|
|
279
381
|
collection: string;
|
|
280
|
-
/**
|
|
382
|
+
/** Mongo-style filter, applied **locally**. */
|
|
281
383
|
filter?: Filter<T>;
|
|
282
|
-
/**
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
384
|
+
/** Sort, applied locally. `1` ascending, `-1` descending. */
|
|
385
|
+
sort?: Partial<Record<keyof T & string, 1 | -1>>;
|
|
386
|
+
/** 1-based page number. Requires `limit`. */
|
|
387
|
+
page?: number;
|
|
388
|
+
/** Rows per page. */
|
|
389
|
+
limit?: number;
|
|
390
|
+
/** Skip N rows. Ignored when `page` is set. */
|
|
391
|
+
skip?: number;
|
|
392
|
+
/** Skip the query entirely (e.g. while a route param is undefined). */
|
|
393
|
+
enabled?: boolean;
|
|
394
|
+
/** Legacy sync-contract read policy. Used when no full-replication scope exists. */
|
|
288
395
|
source?: ReadSource;
|
|
289
396
|
}
|
|
290
397
|
interface QueryResult<T> {
|
|
291
|
-
/**
|
|
398
|
+
/** The current page. Reactive: re-renders as rows land. */
|
|
292
399
|
data: T[];
|
|
293
|
-
/**
|
|
400
|
+
/** Total rows in the replicated scope when reported by the origin. */
|
|
401
|
+
total?: number;
|
|
402
|
+
/** True until the first local snapshot arrives. */
|
|
294
403
|
loading: boolean;
|
|
295
|
-
/** Most recent local
|
|
404
|
+
/** Most recent local read error. */
|
|
296
405
|
error: unknown | null;
|
|
297
|
-
/**
|
|
406
|
+
/** Most recent cold-start bridge error. */
|
|
407
|
+
fetchError: unknown | null;
|
|
408
|
+
/** How much of the collection is local, and whether it is trustworthy. */
|
|
409
|
+
coverage: Coverage;
|
|
410
|
+
/**
|
|
411
|
+
* A cold-start bridge fetch is in flight — we are serving the network because
|
|
412
|
+
* the replica isn't complete yet.
|
|
413
|
+
*/
|
|
414
|
+
fetching: boolean;
|
|
415
|
+
/** Legacy sync-contract pull in progress. */
|
|
298
416
|
syncing: boolean;
|
|
299
|
-
/**
|
|
417
|
+
/** Legacy sync-contract pull error. */
|
|
300
418
|
syncError: unknown | null;
|
|
301
|
-
/**
|
|
419
|
+
/** Force a delta refresh from the origin. */
|
|
302
420
|
refetch: () => Promise<void>;
|
|
303
421
|
}
|
|
304
422
|
/**
|
|
305
|
-
*
|
|
423
|
+
* Read a page of a collection.
|
|
424
|
+
*
|
|
425
|
+
* ## The point
|
|
426
|
+
*
|
|
427
|
+
* Once the collection is **covered** — fully replicated for this scope — this hook
|
|
428
|
+
* touches the network **zero times**. Filtering, sorting and paging are local
|
|
429
|
+
* queries against the on-device database. Page 1 → page 2 → a new filter → page 47
|
|
430
|
+
* → back to page 1: every one is a local read, instant and offline-capable.
|
|
431
|
+
* Pagination stops being a network concern at all.
|
|
432
|
+
*
|
|
433
|
+
* That is the whole reason to put a real database on the device. A cache of API
|
|
434
|
+
* pages could only ever answer the queries you already asked; a *covered replica*
|
|
435
|
+
* answers queries nobody has asked yet.
|
|
436
|
+
*
|
|
437
|
+
* ## Before coverage lands
|
|
306
438
|
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
439
|
+
* On a cold start the replica is empty, and a SPA or React Native app has no server
|
|
440
|
+
* render to paint behind. So the hook **bridges**: it fetches exactly the rows this
|
|
441
|
+
* query needs and writes them into the same collection, under the same derived ids
|
|
442
|
+
* the background walk will use. Those rows are not a cache entry to be reconciled
|
|
443
|
+
* later — they are the replica, arriving early. When the walk reaches them it
|
|
444
|
+
* overwrites them in place.
|
|
311
445
|
*
|
|
312
446
|
* @example
|
|
313
|
-
* const { data,
|
|
447
|
+
* const { data, coverage } = useQuery<Product>({
|
|
314
448
|
* collection: 'products',
|
|
315
|
-
* filter: { category: 'kitchen' },
|
|
316
|
-
*
|
|
449
|
+
* filter: { category: 'kitchen', price: { $lt: 500 } },
|
|
450
|
+
* sort: { price: 1 },
|
|
451
|
+
* page: 2,
|
|
452
|
+
* limit: 100,
|
|
317
453
|
* })
|
|
318
454
|
*/
|
|
319
455
|
declare function useQuery<T extends Document>(options: UseQueryOptions<T>): QueryResult<T>;
|
|
320
456
|
|
|
321
457
|
/**
|
|
322
|
-
*
|
|
323
|
-
* in parallel. The result array is index-aligned with `queries`.
|
|
458
|
+
* Several pages at once, from several collections. Index-aligned with `queries`.
|
|
324
459
|
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
* no cross-collection joins (TalaDB is a document store); compose in the
|
|
329
|
-
* component.
|
|
460
|
+
* Hooks can't be called in a variable-length loop, so this manages its own
|
|
461
|
+
* subscriptions rather than calling `useQuery` N times. Behaviour is otherwise
|
|
462
|
+
* identical: once a collection is covered, its read is purely local.
|
|
330
463
|
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
464
|
+
* TalaDB is a document store with no cross-collection joins, so a page needing
|
|
465
|
+
* several collections composes them in the component (or denormalises at the
|
|
466
|
+
* origin). This is the hook for that.
|
|
333
467
|
*
|
|
334
468
|
* @example
|
|
335
|
-
* const [
|
|
336
|
-
* { collection: '
|
|
337
|
-
* { collection: '
|
|
469
|
+
* const [products, categories] = useQueries([
|
|
470
|
+
* { collection: 'products', filter: { category }, sort: { price: 1 }, page, limit: 50 },
|
|
471
|
+
* { collection: 'categories' },
|
|
338
472
|
* ])
|
|
339
473
|
*/
|
|
340
474
|
declare function useQueries(queries: UseQueryOptions<Document>[]): QueryResult<Document>[];
|
|
@@ -392,4 +526,4 @@ interface MutationResult<T extends Document> {
|
|
|
392
526
|
*/
|
|
393
527
|
declare function useMutation<T extends Document>(options: UseMutationOptions): MutationResult<T>;
|
|
394
528
|
|
|
395
|
-
export { type CollectionRegistry, type CollectionResolver, type FindOneResult, type FindResult, type MutationResult, type PrefetchEntry, type PrefetchMode, type PrefetchSlice, type QueryResult, type
|
|
529
|
+
export { type AggregateResult, type CollectionRegistry, type CollectionResolver, type Coverage, type FindOneResult, type FindResult, type HydrateMode, type MutationResult, type PrefetchEntry, type PrefetchMode, type PrefetchSlice, type QueryResult, type ReplicateRegistry, type ReplicateScope, type ReplicationConfig, ReplicationProvider, type ReplicationProviderProps, TalaDBProvider, type TalaDBProviderProps, type UseMutationOptions, type UseQueryOptions, type WriteOp, useAggregate, useCollection, useCollectionOptions, useCoverage, useFind, useFindOne, useHydrationProgress, useMutation, useQueries, useQuery, useReplicationConfig, useTalaDB };
|