@livequery/core 2.0.76 → 2.0.78
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 +97 -160
- package/dist/LivequeryCollection.d.ts +2 -0
- package/dist/LivequeryCollection.d.ts.map +1 -1
- package/dist/LivequeryCore.d.ts.map +1 -1
- package/dist/index.js +242 -13
- package/dist/index.js.map +13 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @livequery/
|
|
1
|
+
# @livequery/core
|
|
2
2
|
|
|
3
3
|
A local-first reactive data library for browser clients. Type-safe, RxJS-based collection system with pluggable storage and transporter adapters, optimistic local mutations, and real-time synchronisation support.
|
|
4
4
|
|
|
@@ -18,7 +18,6 @@ A local-first reactive data library for browser clients. Type-safe, RxJS-based c
|
|
|
18
18
|
- [API Reference](#api-reference)
|
|
19
19
|
- [LivequeryMemoryStorage](#livequerymemorystorage)
|
|
20
20
|
- [LivequeryCollection methods](#livequerycollection-methods)
|
|
21
|
-
- [WorkerRpc](#workerrpc)
|
|
22
21
|
- [Writing a Custom Transporter](#writing-a-custom-transporter)
|
|
23
22
|
- [Writing a Custom Storage Adapter](#writing-a-custom-storage-adapter)
|
|
24
23
|
- [Types Reference](#types-reference)
|
|
@@ -50,10 +49,10 @@ A local-first reactive data library for browser clients. Type-safe, RxJS-based c
|
|
|
50
49
|
```
|
|
51
50
|
|
|
52
51
|
**Data flow for a mutation (add / update / delete):**
|
|
53
|
-
1. `LivequeryCollection.add/update/delete` calls `LivequeryCore.
|
|
54
|
-
2. The core applies the change to storage immediately (optimistic update).
|
|
52
|
+
1. `LivequeryCollection.add/update/delete` calls `LivequeryCore.add/update/delete`.
|
|
53
|
+
2. The core applies the change to local storage immediately (optimistic update).
|
|
55
54
|
3. The change is broadcast to all live collections watching the same `ref`.
|
|
56
|
-
4. The core then calls every configured transporter to
|
|
55
|
+
4. The core then calls every configured transporter to push the change remotely.
|
|
57
56
|
|
|
58
57
|
**Data flow for a query:**
|
|
59
58
|
1. `LivequeryCollection.query(filters)` calls `LivequeryCore.query`.
|
|
@@ -66,9 +65,9 @@ A local-first reactive data library for browser clients. Type-safe, RxJS-based c
|
|
|
66
65
|
## Installation
|
|
67
66
|
|
|
68
67
|
```bash
|
|
69
|
-
npm install @livequery/
|
|
68
|
+
npm install @livequery/core rxjs
|
|
70
69
|
# or
|
|
71
|
-
bun add @livequery/
|
|
70
|
+
bun add @livequery/core rxjs
|
|
72
71
|
```
|
|
73
72
|
|
|
74
73
|
---
|
|
@@ -82,7 +81,7 @@ import {
|
|
|
82
81
|
LivequeryMemoryStorage,
|
|
83
82
|
type Doc,
|
|
84
83
|
type LivequeryTransporter,
|
|
85
|
-
} from "@livequery/
|
|
84
|
+
} from "@livequery/core"
|
|
86
85
|
import { of } from "rxjs"
|
|
87
86
|
|
|
88
87
|
// 1. Define your document shape
|
|
@@ -97,46 +96,36 @@ const storage = new LivequeryMemoryStorage()
|
|
|
97
96
|
|
|
98
97
|
// 3. Create a transporter (no-op; replace with your real backend)
|
|
99
98
|
const transporter: LivequeryTransporter = {
|
|
100
|
-
query(
|
|
101
|
-
return of({
|
|
102
|
-
},
|
|
103
|
-
trigger(_action) {
|
|
104
|
-
return of({ data: {} as any })
|
|
99
|
+
query(_query) {
|
|
100
|
+
return of({ changes: [], summary: {}, paging: { total: 0, current: 0 }, metadata: {}, source: "query" as const })
|
|
105
101
|
},
|
|
102
|
+
add: async (_ref, doc) => ({ ...doc, id: crypto.randomUUID() } as any),
|
|
103
|
+
update: async (_ref, _id, doc) => doc as any,
|
|
104
|
+
delete: async (_ref, _id) => ({} as any),
|
|
105
|
+
trigger: async (_action) => ({} as any),
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// 4. Create the core
|
|
109
109
|
const core = new LivequeryCore({
|
|
110
110
|
storage,
|
|
111
111
|
transporters: { primary: transporter },
|
|
112
|
-
resolver: ({ change, old_document }) => ({
|
|
113
|
-
approved: true,
|
|
114
|
-
document: { ...old_document, ...change.data } as Todo,
|
|
115
|
-
}),
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
// 5. Create a reactive collection
|
|
119
|
-
const todos = new LivequeryCollection<Todo>({
|
|
120
|
-
core,
|
|
121
|
-
ref: "todos",
|
|
122
|
-
filters: { "createdAt:sort": "desc", ":limit": 20, ":page": 1, ":before": "", ":after": "" },
|
|
123
|
-
lazy: true,
|
|
124
112
|
})
|
|
125
113
|
|
|
126
|
-
//
|
|
127
|
-
todos
|
|
114
|
+
// 5. Create a reactive collection and initialize it
|
|
115
|
+
const todos = new LivequeryCollection<Todo>({ filters: { "createdAt:sort": "desc" } })
|
|
116
|
+
todos.initialize(core, "todos")
|
|
128
117
|
|
|
129
|
-
//
|
|
118
|
+
// 6. Subscribe to reactive state
|
|
130
119
|
todos.items.subscribe((docs) => {
|
|
131
|
-
console.log("items:", docs.map((doc
|
|
120
|
+
console.log("items:", docs.map((doc) => doc.value))
|
|
132
121
|
})
|
|
133
122
|
todos.loading.subscribe((state) => console.log("loading:", state))
|
|
134
123
|
todos.paging.subscribe((p) => console.log("paging:", p))
|
|
135
124
|
|
|
136
|
-
//
|
|
137
|
-
await todos.query({ "createdAt:sort": "desc", ":limit": 20
|
|
125
|
+
// 7. Query with filters
|
|
126
|
+
await todos.query({ "createdAt:sort": "desc", ":limit": 20 })
|
|
138
127
|
|
|
139
|
-
//
|
|
128
|
+
// 8. Mutate data
|
|
140
129
|
await todos.add({ title: "Buy milk", done: false, createdAt: Date.now() })
|
|
141
130
|
await todos.update("some-id", { done: true })
|
|
142
131
|
await todos.delete("some-id")
|
|
@@ -206,13 +195,18 @@ A transporter connects the core to a remote backend (REST API, WebSocket, Fireba
|
|
|
206
195
|
|
|
207
196
|
```ts
|
|
208
197
|
type LivequeryTransporter = {
|
|
209
|
-
// Called for every query. Returns an Observable so the remote can stream
|
|
198
|
+
// Called for every query. Returns an Observable so the remote can stream realtime updates.
|
|
210
199
|
query<T extends Doc>(
|
|
211
200
|
query: LivequeryQueryParams<T>
|
|
212
|
-
): Observable<Partial<LivequeryQueryResult
|
|
201
|
+
): Observable<Partial<LivequeryQueryResult>>
|
|
202
|
+
|
|
203
|
+
// Called for optimistic mutations
|
|
204
|
+
add<T extends Doc>(ref: string, doc: Omit<T, 'id'>): Promise<T>
|
|
205
|
+
update<T extends Doc>(ref: string, id: string, doc: Partial<T>): Promise<T>
|
|
206
|
+
delete<T extends Doc>(ref: string, id: string): Promise<T>
|
|
213
207
|
|
|
214
|
-
// Called for
|
|
215
|
-
trigger<T>(action: LivequeryAction):
|
|
208
|
+
// Called for custom actions
|
|
209
|
+
trigger<T>(action: LivequeryAction): Promise<T>
|
|
216
210
|
}
|
|
217
211
|
```
|
|
218
212
|
|
|
@@ -228,31 +222,6 @@ const core = new LivequeryCore({
|
|
|
228
222
|
transporters: { // one or more named transporters
|
|
229
223
|
primary: myTransporter,
|
|
230
224
|
},
|
|
231
|
-
resolver, // ConflictResolverFunction
|
|
232
|
-
})
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
#### Conflict resolver
|
|
236
|
-
|
|
237
|
-
Called for every local mutation. Decides whether to approve the change and what the final merged document should be.
|
|
238
|
-
|
|
239
|
-
```ts
|
|
240
|
-
type ConflictResolverFunction = <T extends Doc>(e: {
|
|
241
|
-
from: Record<string, string | number | boolean> // remote version cursors (_remotes)
|
|
242
|
-
old_document: T // current local document
|
|
243
|
-
change: DataChangeEvent<T> // incoming change
|
|
244
|
-
}) => {
|
|
245
|
-
approved: boolean // false → discard the change
|
|
246
|
-
document: T // resolved document to persist
|
|
247
|
-
}
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
Simple last-write-wins example:
|
|
251
|
-
|
|
252
|
-
```ts
|
|
253
|
-
const resolver: ConflictResolverFunction = ({ change, old_document }) => ({
|
|
254
|
-
approved: true,
|
|
255
|
-
document: { ...old_document, ...change.data } as typeof old_document,
|
|
256
225
|
})
|
|
257
226
|
```
|
|
258
227
|
|
|
@@ -264,14 +233,13 @@ const resolver: ConflictResolverFunction = ({ change, old_document }) => ({
|
|
|
264
233
|
|
|
265
234
|
```ts
|
|
266
235
|
const posts = new LivequeryCollection<Post>({
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
lazy: true, // true = don't auto-load on initialize(); false = load immediately
|
|
236
|
+
filters: { "publishedAt:sort": "desc" },
|
|
237
|
+
lazy: true, // true = don't auto-load on initialize(); false = load immediately (default)
|
|
238
|
+
debounce: 300, // optional debounce time in ms for debounceQuery()
|
|
271
239
|
})
|
|
272
240
|
|
|
273
|
-
//
|
|
274
|
-
posts.initialize()
|
|
241
|
+
// Wire up the core and the collection path, then start watching
|
|
242
|
+
posts.initialize(core, "posts")
|
|
275
243
|
```
|
|
276
244
|
|
|
277
245
|
#### Reactive state properties
|
|
@@ -279,25 +247,17 @@ posts.initialize()
|
|
|
279
247
|
| Property | Type | Description |
|
|
280
248
|
|----------|------|-------------|
|
|
281
249
|
| `items` | `BehaviorSubject<LivequeryDocument<DocState<T>>[]>` | Current list of documents |
|
|
282
|
-
| `loading` | `BehaviorSubject<LivequeryLoadingState>` |
|
|
250
|
+
| `loading` | `BehaviorSubject<LivequeryLoadingState \| null>` | `null`, `'all'`, `'next'`, or `'prev'` |
|
|
283
251
|
| `filters` | `BehaviorSubject<Partial<LivequeryFilters<T>>>` | Active filters |
|
|
284
252
|
| `paging` | `BehaviorSubject<LivequeryPaging>` | Pagination info |
|
|
285
253
|
| `summary` | `BehaviorSubject<Record<string, any>>` | Aggregation data from transporter |
|
|
286
254
|
| `metadata` | `BehaviorSubject<Record<string, any>>` | Arbitrary metadata from transporter |
|
|
255
|
+
| `error` | `BehaviorSubject<{code: string, message: string} \| null>` | Last error from transporter |
|
|
287
256
|
|
|
288
257
|
```ts
|
|
289
258
|
posts.items.subscribe((docs) => console.log(docs.map(d => d.value)))
|
|
290
|
-
posts.loading.subscribe((
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
`LivequeryLoadingState`:
|
|
294
|
-
|
|
295
|
-
```ts
|
|
296
|
-
type LivequeryLoadingState = {
|
|
297
|
-
all: boolean // initial query in progress
|
|
298
|
-
next: boolean // loading next page
|
|
299
|
-
prev: boolean // loading previous page
|
|
300
|
-
}
|
|
259
|
+
posts.loading.subscribe((state) => console.log("loading:", state))
|
|
260
|
+
// state is null | 'all' | 'next' | 'prev'
|
|
301
261
|
```
|
|
302
262
|
|
|
303
263
|
---
|
|
@@ -310,7 +270,7 @@ Each element of `collection.items.value` is a `LivequeryDocument<DocState<T>>`,
|
|
|
310
270
|
class LivequeryDocument<T extends Doc> extends BehaviorSubject<T> {
|
|
311
271
|
update(data: Partial<T>): Promise<void>
|
|
312
272
|
del(): Promise<void>
|
|
313
|
-
trigger<R>(action:
|
|
273
|
+
trigger<R>(action: string, payload: Record<string, any>): Observable<{ data: R; error?: Error }>
|
|
314
274
|
}
|
|
315
275
|
```
|
|
316
276
|
|
|
@@ -325,7 +285,7 @@ await doc.update({ title: "Updated title" })
|
|
|
325
285
|
await doc.del()
|
|
326
286
|
|
|
327
287
|
// Fire a custom action
|
|
328
|
-
doc.trigger("
|
|
288
|
+
doc.trigger("publish", { scheduledAt: Date.now() }).subscribe()
|
|
329
289
|
```
|
|
330
290
|
|
|
331
291
|
---
|
|
@@ -402,14 +362,9 @@ const storage = new LivequeryMemoryStorage()
|
|
|
402
362
|
| `add` | `(collection, document) → Promise<T>` | Upsert a document (insert or replace by id) |
|
|
403
363
|
| `update` | `(collection, id, partial) → Promise<T \| null>` | Merge partial fields into existing document |
|
|
404
364
|
| `delete` | `(collection, id) → Promise<T \| null>` | Remove and return a document |
|
|
405
|
-
| `seed` | `(collection, docs[]) → void` | Bulk-load documents (replaces existing) |
|
|
406
365
|
| `clear` | `(collection?) → void` | Clear one collection or all collections |
|
|
407
366
|
|
|
408
367
|
```ts
|
|
409
|
-
storage.seed<Todo>("todos", [
|
|
410
|
-
{ id: "1", title: "Write docs", done: false, createdAt: Date.now() }
|
|
411
|
-
])
|
|
412
|
-
|
|
413
368
|
storage.clear("todos") // clear one collection
|
|
414
369
|
storage.clear() // clear everything
|
|
415
370
|
```
|
|
@@ -420,15 +375,18 @@ storage.clear() // clear everything
|
|
|
420
375
|
|
|
421
376
|
| Method | Description |
|
|
422
377
|
|--------|-------------|
|
|
423
|
-
| `initialize()` | Wire up the core
|
|
378
|
+
| `initialize(core, ref)` | Wire up the core for a given collection path; optionally auto-loads (required before use) |
|
|
424
379
|
| `query(filters)` | Execute a fresh query replacing current items |
|
|
380
|
+
| `debounceQuery(filters)` | Queue a debounced query (uses the `debounce` option) |
|
|
425
381
|
| `loadMore()` | Append next page using `paging.next.cursor` |
|
|
426
382
|
| `loadPrev()` | Prepend previous page using `paging.prev.cursor` |
|
|
427
383
|
| `loadAround(cursor)` | Load items around a specific cursor (both directions) |
|
|
428
384
|
| `add(payload)` | Optimistically add a new document |
|
|
429
385
|
| `update(id, payload)` | Optimistically update a document |
|
|
430
386
|
| `delete(id)` | Optimistically delete a document |
|
|
431
|
-
| `trigger(action, payload?)` | Fire a custom action
|
|
387
|
+
| `trigger(action, payload?)` | Fire a custom action via the transporter |
|
|
388
|
+
| `watch(check)` | Returns an Observable that emits when a document changes, filtered by `check` |
|
|
389
|
+
| `resetError()` | Clear the current `error` state |
|
|
432
390
|
|
|
433
391
|
```ts
|
|
434
392
|
// Paginate
|
|
@@ -442,51 +400,14 @@ await collection.update("doc-id", { done: true })
|
|
|
442
400
|
await collection.delete("doc-id")
|
|
443
401
|
|
|
444
402
|
// Custom action handled by your transporter
|
|
445
|
-
collection.trigger("
|
|
446
|
-
```
|
|
447
|
-
|
|
448
|
-
---
|
|
449
|
-
|
|
450
|
-
### WorkerRpc
|
|
403
|
+
collection.trigger("sendEmail", { to: "user@example.com" }).subscribe()
|
|
451
404
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
```ts
|
|
457
|
-
// worker.ts
|
|
458
|
-
import { WorkerRpc } from "@livequery/new"
|
|
459
|
-
|
|
460
|
-
class DataService {
|
|
461
|
-
async getUser(id: string) {
|
|
462
|
-
return { id, name: "Alice" }
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
const rpc = new WorkerRpc()
|
|
467
|
-
rpc.exposeWorkerService(new DataService())
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
#### Consume the service in the main thread
|
|
471
|
-
|
|
472
|
-
```ts
|
|
473
|
-
// main.ts
|
|
474
|
-
import { WorkerRpc } from "@livequery/new"
|
|
475
|
-
|
|
476
|
-
const worker = new SharedWorker(new URL("./worker.ts", import.meta.url), { type: "module" })
|
|
477
|
-
|
|
478
|
-
// Returns a typed proxy
|
|
479
|
-
const service = WorkerRpc.linkWorkerService<DataService>("DataService", worker)
|
|
480
|
-
|
|
481
|
-
// Call as a Promise
|
|
482
|
-
const user = await service.getUser("123")
|
|
483
|
-
|
|
484
|
-
// Or subscribe as an Observable (for streaming methods)
|
|
485
|
-
service.getUser("123").subscribe((user) => console.log(user))
|
|
405
|
+
// Watch for field changes across all items
|
|
406
|
+
collection.watch((prev, next) => prev.done !== next.done).subscribe(([prev, next]) => {
|
|
407
|
+
console.log("done changed", prev, next)
|
|
408
|
+
})
|
|
486
409
|
```
|
|
487
410
|
|
|
488
|
-
The proxy is transparent — if the underlying method returns an `Observable`, the proxy streams values back; if it returns a `Promise` or plain value, it resolves once.
|
|
489
|
-
|
|
490
411
|
---
|
|
491
412
|
|
|
492
413
|
## Writing a Custom Transporter
|
|
@@ -498,7 +419,7 @@ import { Observable } from "rxjs"
|
|
|
498
419
|
import type {
|
|
499
420
|
LivequeryTransporter, Doc,
|
|
500
421
|
LivequeryQueryParams, LivequeryAction
|
|
501
|
-
} from "@livequery/
|
|
422
|
+
} from "@livequery/core"
|
|
502
423
|
|
|
503
424
|
const httpTransporter: LivequeryTransporter = {
|
|
504
425
|
query<T extends Doc>(params: LivequeryQueryParams<T>) {
|
|
@@ -507,7 +428,6 @@ const httpTransporter: LivequeryTransporter = {
|
|
|
507
428
|
.then(r => r.json())
|
|
508
429
|
.then(data => {
|
|
509
430
|
subscriber.next({
|
|
510
|
-
query_id: params.query_id,
|
|
511
431
|
changes: data.items.map((item: T) => ({ id: item.id, type: "added", data: item })),
|
|
512
432
|
paging: data.paging,
|
|
513
433
|
summary: data.summary ?? {},
|
|
@@ -520,19 +440,36 @@ const httpTransporter: LivequeryTransporter = {
|
|
|
520
440
|
})
|
|
521
441
|
},
|
|
522
442
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
method,
|
|
529
|
-
headers: { "Content-Type": "application/json" },
|
|
530
|
-
body: JSON.stringify(action.payload),
|
|
531
|
-
})
|
|
532
|
-
.then(r => r.json())
|
|
533
|
-
.then(data => { subscriber.next({ data }); subscriber.complete() })
|
|
534
|
-
.catch(err => subscriber.error(err))
|
|
443
|
+
async add<T extends Doc>(ref: string, doc: Omit<T, 'id'>) {
|
|
444
|
+
const res = await fetch(`/api/${ref}`, {
|
|
445
|
+
method: "POST",
|
|
446
|
+
headers: { "Content-Type": "application/json" },
|
|
447
|
+
body: JSON.stringify(doc),
|
|
535
448
|
})
|
|
449
|
+
return res.json() as Promise<T>
|
|
450
|
+
},
|
|
451
|
+
|
|
452
|
+
async update<T extends Doc>(ref: string, id: string, doc: Partial<T>) {
|
|
453
|
+
const res = await fetch(`/api/${ref}/${id}`, {
|
|
454
|
+
method: "PATCH",
|
|
455
|
+
headers: { "Content-Type": "application/json" },
|
|
456
|
+
body: JSON.stringify(doc),
|
|
457
|
+
})
|
|
458
|
+
return res.json() as Promise<T>
|
|
459
|
+
},
|
|
460
|
+
|
|
461
|
+
async delete<T extends Doc>(ref: string, id: string) {
|
|
462
|
+
const res = await fetch(`/api/${ref}/${id}`, { method: "DELETE" })
|
|
463
|
+
return res.json() as Promise<T>
|
|
464
|
+
},
|
|
465
|
+
|
|
466
|
+
async trigger<T>(action: LivequeryAction) {
|
|
467
|
+
const res = await fetch(`/api/${action.ref}/${action.action}`, {
|
|
468
|
+
method: "POST",
|
|
469
|
+
headers: { "Content-Type": "application/json" },
|
|
470
|
+
body: JSON.stringify(action.payload),
|
|
471
|
+
})
|
|
472
|
+
return res.json() as Promise<T>
|
|
536
473
|
},
|
|
537
474
|
}
|
|
538
475
|
```
|
|
@@ -544,7 +481,7 @@ const httpTransporter: LivequeryTransporter = {
|
|
|
544
481
|
Implement `LivequeryStorge` to persist data in `localStorage`, `IndexedDB`, SQLite, etc.:
|
|
545
482
|
|
|
546
483
|
```ts
|
|
547
|
-
import type { LivequeryStorge, Doc, LivequeryPaging } from "@livequery/
|
|
484
|
+
import type { LivequeryStorge, Doc, LivequeryPaging } from "@livequery/core"
|
|
548
485
|
|
|
549
486
|
class LocalStorageAdapter implements LivequeryStorge {
|
|
550
487
|
private read<T>(collection: string): T[] {
|
|
@@ -605,43 +542,40 @@ type DocState<T extends Doc> = T & {
|
|
|
605
542
|
_deleting?: boolean
|
|
606
543
|
_updating?: boolean
|
|
607
544
|
_adding?: boolean
|
|
608
|
-
_remotes?: Record<string, string | number>
|
|
609
|
-
_prev?: Partial<T>
|
|
545
|
+
_remotes?: Record<string, string | number> // per-transporter version cursors
|
|
546
|
+
_prev?: Partial<T> // previous values before last local mutation
|
|
610
547
|
}
|
|
611
548
|
|
|
612
549
|
// Change event emitted by transporters and the core
|
|
613
|
-
type DataChangeEvent
|
|
550
|
+
type DataChangeEvent = {
|
|
551
|
+
collection_ref: string
|
|
614
552
|
id: string
|
|
615
|
-
type:
|
|
616
|
-
data?:
|
|
553
|
+
type: 'added' | 'removed' | 'modified'
|
|
554
|
+
data?: Record<string, any>
|
|
617
555
|
}
|
|
618
556
|
|
|
619
557
|
// Query parameters forwarded to every transporter
|
|
620
558
|
type LivequeryQueryParams<T extends Doc> = {
|
|
621
559
|
ref: string
|
|
622
|
-
query_id: string
|
|
623
|
-
collection_id: string
|
|
624
560
|
filters?: Partial<LivequeryFilters<T>>
|
|
625
561
|
headers?: Record<string, string>
|
|
626
562
|
}
|
|
627
563
|
|
|
628
564
|
// Result streamed back from a transporter query
|
|
629
|
-
type LivequeryQueryResult
|
|
630
|
-
|
|
631
|
-
changes: DataChangeEvent
|
|
565
|
+
type LivequeryQueryResult = {
|
|
566
|
+
error: { code: string, message: string }
|
|
567
|
+
changes: DataChangeEvent[]
|
|
632
568
|
summary: Record<string, any>
|
|
633
569
|
paging: LivequeryPaging
|
|
634
570
|
metadata: Record<string, any>
|
|
635
|
-
source:
|
|
571
|
+
source: 'query' | 'action' | 'realtime'
|
|
636
572
|
}
|
|
637
573
|
|
|
638
|
-
// Action sent to
|
|
574
|
+
// Action sent to a transporter for custom operations
|
|
639
575
|
type LivequeryAction = {
|
|
640
576
|
ref: string
|
|
641
|
-
|
|
642
|
-
action: "add" | "update" | "delete" | `~${string}`
|
|
577
|
+
action: string
|
|
643
578
|
payload?: Record<string, any>
|
|
644
|
-
headers?: Record<string, string>
|
|
645
579
|
}
|
|
646
580
|
|
|
647
581
|
// Pagination info
|
|
@@ -651,6 +585,9 @@ type LivequeryPaging = {
|
|
|
651
585
|
next?: { count: number; cursor: string }
|
|
652
586
|
prev?: { count: number; cursor: string }
|
|
653
587
|
}
|
|
588
|
+
|
|
589
|
+
// Loading state for a collection
|
|
590
|
+
type LivequeryLoadingState = null | 'next' | 'prev' | 'all'
|
|
654
591
|
```
|
|
655
592
|
|
|
656
593
|
---
|
|
@@ -6,6 +6,7 @@ export type LivequeryCollectionOptions<T extends Doc> = {
|
|
|
6
6
|
filters?: Partial<LivequeryFilters<T>>;
|
|
7
7
|
lazy?: boolean;
|
|
8
8
|
full?: boolean;
|
|
9
|
+
debounce?: number;
|
|
9
10
|
};
|
|
10
11
|
export declare class LivequeryCollection<T extends Doc> {
|
|
11
12
|
#private;
|
|
@@ -25,6 +26,7 @@ export declare class LivequeryCollection<T extends Doc> {
|
|
|
25
26
|
constructor(options: LivequeryCollectionOptions<T>);
|
|
26
27
|
initialize(core: LivequeryCore, ref: string): Subscription | undefined;
|
|
27
28
|
query(filters: Partial<LivequeryFilters<T>>): Promise<void>;
|
|
29
|
+
debounceQuery(filters: Partial<LivequeryFilters<T>>): Promise<void>;
|
|
28
30
|
loadMore(): Promise<void>;
|
|
29
31
|
loadPrev(): Promise<void>;
|
|
30
32
|
loadAround(cursor: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LivequeryCollection.d.ts","sourceRoot":"","sources":["../src/LivequeryCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"LivequeryCollection.d.ts","sourceRoot":"","sources":["../src/LivequeryCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAgD,UAAU,EAAqB,YAAY,EAAkB,MAAM,MAAM,CAAA;AACjJ,OAAO,EAAE,aAAa,EAAE,KAAK,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAC3E,OAAO,KAAK,EAAmB,GAAG,EAAE,QAAQ,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAIvD,MAAM,MAAM,0BAA0B,CAAC,CAAC,SAAS,GAAG,IAAI;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAA;IACtC,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,qBAAa,mBAAmB,CAAC,CAAC,SAAS,GAAG;;IAE1C,SAAgB,EAAE,SAAsC;IAMjD,GAAG,EAAE,MAAM,CAAA;IAElB,SAAgB,KAAK,EAAE,eAAe,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IACx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