@livequery/core 2.0.92 → 2.0.98

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.
Files changed (40) hide show
  1. package/README.md +56 -49
  2. package/dist/LivequeryCollection.d.ts +19 -17
  3. package/dist/LivequeryCollection.d.ts.map +1 -1
  4. package/dist/LivequeryCollection.js +231 -0
  5. package/dist/LivequeryCollection.js.map +1 -0
  6. package/dist/LivequeryCore.d.ts +4 -4
  7. package/dist/LivequeryCore.d.ts.map +1 -1
  8. package/dist/LivequeryCore.js +337 -0
  9. package/dist/LivequeryCore.js.map +1 -0
  10. package/dist/LivequeryDocument.d.ts +2 -2
  11. package/dist/LivequeryDocument.d.ts.map +1 -1
  12. package/dist/LivequeryDocument.js +22 -0
  13. package/dist/LivequeryDocument.js.map +1 -0
  14. package/dist/LivequeryMemoryStorage.d.ts +2 -2
  15. package/dist/LivequeryMemoryStorage.d.ts.map +1 -1
  16. package/dist/LivequeryMemoryStorage.js +89 -0
  17. package/dist/LivequeryMemoryStorage.js.map +1 -0
  18. package/dist/LivequeryStorge.d.ts +1 -1
  19. package/dist/LivequeryStorge.d.ts.map +1 -1
  20. package/dist/LivequeryStorge.js +2 -0
  21. package/dist/LivequeryStorge.js.map +1 -0
  22. package/dist/LivequeryTransporter.d.ts +1 -1
  23. package/dist/LivequeryTransporter.d.ts.map +1 -1
  24. package/dist/LivequeryTransporter.js +2 -0
  25. package/dist/LivequeryTransporter.js.map +1 -0
  26. package/dist/helpers/filterDocs.d.ts +1 -1
  27. package/dist/helpers/filterDocs.d.ts.map +1 -1
  28. package/dist/helpers/filterDocs.js +80 -0
  29. package/dist/helpers/filterDocs.js.map +1 -0
  30. package/dist/helpers/tryCatch.js +10 -0
  31. package/dist/helpers/tryCatch.js.map +1 -0
  32. package/dist/helpers/whenCompleted.js +5 -0
  33. package/dist/helpers/whenCompleted.js.map +1 -0
  34. package/dist/index.d.ts +8 -8
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +9 -3167
  37. package/dist/index.js.map +1 -100
  38. package/dist/types.js +2 -0
  39. package/dist/types.js.map +1 -0
  40. package/package.json +73 -4
package/README.md CHANGED
@@ -1,32 +1,26 @@
1
1
  # @livequery/core
2
2
 
3
- Reactive local-first data primitives for browser clients. The package combines RxJS-based collections, pluggable local storage, pluggable remote transporters, optimistic mutations, and typed inline filters.
3
+ Reactive local-first data primitives for browser clients.
4
4
 
5
- This package is only the core layer. You can use the built-in pieces, but you can also implement your own `LivequeryStorge` and `LivequeryTransporter` adapters to match your cache strategy, backend API, realtime channel, or persistence model.
5
+ This package provides the core building blocks behind Livequery collections: reactive document state, pluggable local storage, pluggable transporters, optimistic mutations, and typed inline filters.
6
6
 
7
7
  ## Installation
8
8
 
9
9
  ```bash
10
- npm install @livequery/core rxjs
11
- # or
12
10
  bun add @livequery/core rxjs
13
11
  ```
14
12
 
15
13
  For React projects:
16
14
 
17
15
  ```bash
18
- npm install @livequery/core @livequery/react rxjs
19
- # or
20
16
  bun add @livequery/core @livequery/react rxjs
21
17
  ```
22
18
 
23
19
  The package is published as ESM and targets browser usage.
24
20
 
25
- If you are using this package with React, `@livequery/react` is the recommended companion package so collection state can be connected to React components more ergonomically.
26
-
27
21
  ## Public Exports
28
22
 
29
- The public API is re-exported from `src/index.ts`:
23
+ The package re-exports:
30
24
 
31
25
  ```ts
32
26
  export * from "./LivequeryCollection"
@@ -39,7 +33,7 @@ export * from "./helpers/filterDocs"
39
33
  export * from "./LivequeryDocument"
40
34
  ```
41
35
 
42
- ## Core Concepts
36
+ ## Core Types
43
37
 
44
38
  ### `Doc`
45
39
 
@@ -53,7 +47,7 @@ type Doc<T = {}> = T & {
53
47
 
54
48
  ### `DocState`
55
49
 
56
- Collections expose documents as `DocState<T>`, which adds optimistic mutation metadata.
50
+ Collections and documents expose `DocState<T>`, which adds optimistic mutation metadata.
57
51
 
58
52
  ```ts
59
53
  type DocState<T extends Doc> = T & {
@@ -70,7 +64,7 @@ type DocState<T extends Doc> = T & {
70
64
 
71
65
  ### `DataChangeEvent`
72
66
 
73
- Remote query streams feed the core with incremental changes:
67
+ Transporters stream incremental change events back into the core.
74
68
 
75
69
  ```ts
76
70
  type DataChangeEvent = {
@@ -93,9 +87,9 @@ LivequeryCollection / LivequeryDocument
93
87
  LivequeryStorge LivequeryTransporter(s)
94
88
  ```
95
89
 
96
- - `LivequeryCollection` manages reactive state for one collection or document ref.
97
- - `LivequeryDocument` wraps one item as a `BehaviorSubject` with convenience mutation methods.
98
- - `LivequeryCore` coordinates storage, transporters, optimistic writes, and broadcast fan-out.
90
+ - `LivequeryCollection` owns the reactive state for one collection ref or one document ref.
91
+ - `LivequeryDocument` wraps an item as a `BehaviorSubject` with convenience mutation methods.
92
+ - `LivequeryCore` coordinates storage, transporters, optimistic writes, and fan-out to watchers.
99
93
  - `LivequeryStorge` is the local persistence contract.
100
94
  - `LivequeryTransporter` is the remote sync contract.
101
95
 
@@ -121,11 +115,12 @@ type Todo = Doc<{
121
115
  const storage = new LivequeryMemoryStorage()
122
116
 
123
117
  const transporter: LivequeryTransporter = {
124
- query() {
118
+ query(_query) {
125
119
  return of<Partial<LivequeryQueryResult>>({
126
120
  changes: [],
127
121
  summary: {},
128
122
  paging: { total: 0, current: 0 },
123
+ metadata: {},
129
124
  source: "query",
130
125
  })
131
126
  },
@@ -150,12 +145,12 @@ const core = new LivequeryCore({
150
145
  },
151
146
  })
152
147
 
153
- const todos = new LivequeryCollection<Todo>({
148
+ const todos = new LivequeryCollection<Todo>(core, {
154
149
  filters: { "createdAt:sort": "desc" },
155
150
  mode: "server-first",
156
151
  })
157
152
 
158
- todos.initialize(core, "todos")
153
+ todos.initialize("todos")
159
154
 
160
155
  todos.items.subscribe((items) => {
161
156
  console.log(items.map((doc) => doc.value))
@@ -195,11 +190,11 @@ Documents created locally receive ids prefixed with `local:` until a transporter
195
190
 
196
191
  Collections support three modes through `LivequeryCollectionOptions.mode`:
197
192
 
198
- - `server-first`: collection reads are driven by the transporter layer. In practice, the collection waits for remote query results and builds state from transporter events.
199
- - `cache-first`: the collection reads from local cache first, then pulls fresh data from the transporter and merges the result back in.
200
- - `local-first`: the collection reads only from local cache for the query result, applies filters at the storage layer, then performs background synchronization so remote changes are applied silently afterward.
193
+ - `server-first`: queries are driven by transporters, and collection state is built from streamed change events.
194
+ - `cache-first`: first query can hydrate from local storage, then transporters refresh the result.
195
+ - `local-first`: queries resolve from local storage while remote sync runs in the background and rebroadcasts matching changes.
201
196
 
202
- Current implementation detail: in `local-first` mode, active filters are not forwarded to the transporter. The query result is filtered by the storage adapter, and added events are filtered again before they are rebroadcast into matching collections.
197
+ Implementation detail: in `local-first` mode, filters are applied by the storage adapter, while the remote query path is triggered with empty filters and matching is re-checked when added events are broadcast locally.
203
198
 
204
199
  ## `LivequeryCollection`
205
200
 
@@ -207,6 +202,7 @@ Current implementation detail: in `local-first` mode, active filters are not for
207
202
 
208
203
  ```ts
209
204
  type LivequeryCollectionOptions<T extends Doc> = {
205
+ core: LivequeryCore
210
206
  filters: Partial<LivequeryFilters<T>>
211
207
  lazy: boolean
212
208
  debounce: number
@@ -214,20 +210,33 @@ type LivequeryCollectionOptions<T extends Doc> = {
214
210
  }
215
211
  ```
216
212
 
217
- ### Initialize a collection
213
+ ### Create and initialize a collection
214
+
215
+ The current constructor takes `core` as the first argument and options as the second argument.
218
216
 
219
217
  ```ts
220
- const posts = new LivequeryCollection<Post>({
218
+ const posts = new LivequeryCollection<Post>(core, {
221
219
  filters: { "publishedAt:sort": "desc" },
222
220
  lazy: false,
223
221
  debounce: 250,
224
222
  mode: "cache-first",
225
223
  })
226
224
 
227
- posts.initialize(core, "posts")
225
+ posts.initialize("posts")
228
226
  ```
229
227
 
230
- `initialize()` subscribes the collection to `LivequeryCore.watch(ref, id, mode)`. In the current implementation, it is browser-only and returns early when `window` is unavailable.
228
+ `initialize(ref)` subscribes the collection to `LivequeryCore.watch(ref, id, mode)`. In the current implementation, it is browser-only and returns early when `window` is unavailable.
229
+
230
+ ### Collection refs and document refs
231
+
232
+ If a ref has an even number of path segments, the last segment is treated as a document id.
233
+
234
+ ```ts
235
+ posts.initialize("posts")
236
+ singlePost.initialize("posts/post-1")
237
+ ```
238
+
239
+ For collection mutations, `add`, `update`, and `delete` always target the collection portion of the ref.
231
240
 
232
241
  ### Reactive state
233
242
 
@@ -238,18 +247,17 @@ posts.initialize(core, "posts")
238
247
  - `paging`: `BehaviorSubject<LivequeryPaging>`
239
248
  - `error`: `BehaviorSubject<{ code: string; message: string } | null>`
240
249
 
241
- `items` is a `BehaviorSubject`, not a plain array. Reading `collection.items.value` gives you the current snapshot only. If you need live updates, you must subscribe.
250
+ `items` is a `BehaviorSubject`, not a plain array. Reading `collection.items.value` gives the current snapshot only. If you need live updates, subscribe.
242
251
 
243
252
  ```ts
244
253
  const subscription = posts.items.subscribe((items) => {
245
254
  console.log("realtime items", items.map((doc) => doc.value))
246
255
  })
247
256
 
248
- // later
249
257
  subscription.unsubscribe()
250
258
  ```
251
259
 
252
- In React, using only `collection.items.value` during render will not cause rerenders when new events arrive. Bridge the `BehaviorSubject` into React state with `subscribe()`.
260
+ In React, reading only `collection.items.value` during render will not trigger rerenders when new events arrive. Bridge the `BehaviorSubject` into component state.
253
261
 
254
262
  ```tsx
255
263
  function TodoList({ collection }: { collection: LivequeryCollection<Todo> }) {
@@ -286,18 +294,17 @@ resetError(): void
286
294
  watch(check: (prev: T, next: T) => boolean): Observable<[DocState<T>, DocState<T>]>
287
295
  ```
288
296
 
289
- ### Collection refs and document refs
297
+ Notes about current behavior:
290
298
 
291
- If a ref has an even number of path segments, the last segment is treated as a document id.
292
-
293
- ```ts
294
- posts.initialize(core, "posts")
295
- singlePost.initialize(core, "posts/post-1")
296
- ```
299
+ - `query()` requires `initialize()` to have run first so the collection has a `ref` and watcher registration.
300
+ - `debounceQuery()` only emits through the debounced path when `options.debounce` is truthy.
301
+ - `loadMore()` uses `paging.next.cursor` as `:after`.
302
+ - `loadPrev()` uses `paging.prev.cursor` as `:before`.
303
+ - `loadAround()` currently sets both `:after` and `:before` to the provided cursor.
297
304
 
298
305
  ## `LivequeryDocument`
299
306
 
300
- Each item inside `collection.items` is a `LivequeryDocument`, which extends `BehaviorSubject<DocState<T>>`.
307
+ Each entry inside `collection.items` is a `LivequeryDocument`, which extends `BehaviorSubject<DocState<T>>`.
301
308
 
302
309
  ```ts
303
310
  class LivequeryDocument<T extends Doc> extends BehaviorSubject<DocState<T>> {
@@ -345,12 +352,12 @@ The package ships with `LivequeryMemoryStorage`, an in-memory adapter useful for
345
352
 
346
353
  ### `LivequeryMemoryStorage`
347
354
 
348
- Behavior of the built-in adapter:
355
+ The built-in adapter:
349
356
 
350
357
  - stores documents in `Map<string, Map<string, Doc>>`
351
358
  - generates a local id with `local:${crypto.randomUUID()}` when `id` is missing
352
- - supports nested sort paths such as `profile.createdAt:sort`
353
- - applies filters with the exported `filterDocs()` helper
359
+ - applies filters through the exported `filterDocs()` helper
360
+ - supports nested sort keys such as `profile.createdAt:sort`
354
361
 
355
362
  ## `LivequeryTransporter`
356
363
 
@@ -380,7 +387,7 @@ type LivequeryQueryResult = {
380
387
  }
381
388
  ```
382
389
 
383
- Transporters can emit partial results. In practice, the most important fields are `changes`, `paging`, `summary`, and `error`.
390
+ Transporters can emit partial results. In practice, the most useful fields are `changes`, `paging`, `summary`, `metadata`, and `error`.
384
391
 
385
392
  ## Query Filters
386
393
 
@@ -435,14 +442,14 @@ const visible = filterDocs(docs, {
435
442
 
436
443
  The helper module also exports `matchesAllFilters(doc, filters)` for direct predicate checks.
437
444
 
438
- ## Notes
445
+ ## Caveats
439
446
 
440
- - `initialize()` is browser-only in the current implementation
441
- - the public storage interface name is spelled `LivequeryStorge`, matching the source
442
- - optimistic flags such as `_adding`, `_updating`, and `_deleting` are system fields managed by the core
443
- - remote query streams are expected to emit `changes` rather than full snapshots
444
- - `LivequeryCollection` declares a `metadata` field, but it is not initialized in the current constructor, so transporter-emitted `metadata` is not safe to rely on through the collection API yet
445
- - `trigger()` is typed as `Observable<{ data, error? }>` at the collection and document layer, but the current runtime implementation forwards raw transporter results without wrapping them
447
+ - `initialize()` is browser-only because it exits early when `window` is unavailable.
448
+ - The public storage interface name is intentionally spelled `LivequeryStorge`, matching the source.
449
+ - Optimistic flags such as `_adding`, `_updating`, `_deleting`, and `_prev` are system-managed fields.
450
+ - Transporter query streams are expected to emit incremental `changes`, not full snapshots.
451
+ - `LivequeryCollection` declares a `metadata` subject but does not initialize it in the constructor, so transporter-emitted `metadata` is not safe to rely on yet.
452
+ - `trigger()` is typed at the collection and document layer as `Observable<{ data, error? }>` but currently forwards raw transporter results from `LivequeryCore.trigger()`.
446
453
 
447
454
  ## Development
448
455
 
@@ -456,4 +463,4 @@ Available scripts:
456
463
  - `bun run build:js`
457
464
  - `bun run build:types`
458
465
  - `bun run build`
459
- - `bun run build:watch`
466
+ - `bun run build:watch`
@@ -1,8 +1,9 @@
1
1
  import { BehaviorSubject, Observable, Subscription } from "rxjs";
2
- import { LivequeryCore, type CollectionMetadata, type LivequeryLoadingState } from "./LivequeryCore";
3
- import type { Doc, DocState, LivequeryFilters, LivequeryPaging } from "./types";
4
- import { LivequeryDocument } from "./LivequeryDocument";
2
+ import { LivequeryCore, type CollectionMetadata, type LivequeryLoadingState } from "./LivequeryCore.js";
3
+ import type { Doc, DocState, LivequeryFilters, LivequeryPaging } from "./types.js";
4
+ import { LivequeryDocument } from "./LivequeryDocument.js";
5
5
  export type LivequeryCollectionOptions<T extends Doc> = {
6
+ core: LivequeryCore;
6
7
  filters: Partial<LivequeryFilters<T>>;
7
8
  lazy: boolean;
8
9
  debounce: number;
@@ -10,6 +11,7 @@ export type LivequeryCollectionOptions<T extends Doc> = {
10
11
  };
11
12
  export declare class LivequeryCollection<T extends Doc> {
12
13
  #private;
14
+ private core;
13
15
  private options;
14
16
  readonly id: string;
15
17
  ref: string | undefined;
@@ -24,8 +26,8 @@ export declare class LivequeryCollection<T extends Doc> {
24
26
  code: string;
25
27
  message: string;
26
28
  } | null>;
27
- constructor(options?: Partial<LivequeryCollectionOptions<T>>);
28
- initialize(core: LivequeryCore, ref: string): Subscription | undefined;
29
+ constructor(core: LivequeryCore, options?: Partial<LivequeryCollectionOptions<T>>);
30
+ initialize(ref: string): Subscription | undefined;
29
31
  query(filters: Partial<LivequeryFilters<T>>): Promise<void>;
30
32
  debounceQuery(filters: Partial<LivequeryFilters<T>>): Promise<void>;
31
33
  loadMore(): Promise<void>;
@@ -41,38 +43,38 @@ export declare class LivequeryCollection<T extends Doc> {
41
43
  resetError(): void;
42
44
  watch(check: (a: T, b: T) => boolean): Observable<[T & {
43
45
  _deleting?: boolean;
44
- _deleting_error?: import("./types").DocError;
46
+ _deleting_error?: import("./types.js").DocError;
45
47
  _updating?: boolean;
46
- _updating_error?: import("./types").DocError;
48
+ _updating_error?: import("./types.js").DocError;
47
49
  _adding?: boolean;
48
- _adding_error?: import("./types").DocError;
50
+ _adding_error?: import("./types.js").DocError;
49
51
  _remotes?: Record<string, string | number>;
50
52
  _prev?: Partial<T> | undefined;
51
53
  } & {
52
54
  _deleting?: boolean;
53
- _deleting_error?: import("./types").DocError;
55
+ _deleting_error?: import("./types.js").DocError;
54
56
  _updating?: boolean;
55
- _updating_error?: import("./types").DocError;
57
+ _updating_error?: import("./types.js").DocError;
56
58
  _adding?: boolean;
57
- _adding_error?: import("./types").DocError;
59
+ _adding_error?: import("./types.js").DocError;
58
60
  _remotes?: Record<string, string | number>;
59
61
  _prev?: Partial<DocState<T>> | undefined;
60
62
  }, T & {
61
63
  _deleting?: boolean;
62
- _deleting_error?: import("./types").DocError;
64
+ _deleting_error?: import("./types.js").DocError;
63
65
  _updating?: boolean;
64
- _updating_error?: import("./types").DocError;
66
+ _updating_error?: import("./types.js").DocError;
65
67
  _adding?: boolean;
66
- _adding_error?: import("./types").DocError;
68
+ _adding_error?: import("./types.js").DocError;
67
69
  _remotes?: Record<string, string | number>;
68
70
  _prev?: Partial<T> | undefined;
69
71
  } & {
70
72
  _deleting?: boolean;
71
- _deleting_error?: import("./types").DocError;
73
+ _deleting_error?: import("./types.js").DocError;
72
74
  _updating?: boolean;
73
- _updating_error?: import("./types").DocError;
75
+ _updating_error?: import("./types.js").DocError;
74
76
  _adding?: boolean;
75
- _adding_error?: import("./types").DocError;
77
+ _adding_error?: import("./types.js").DocError;
76
78
  _remotes?: Record<string, string | number>;
77
79
  _prev?: Partial<DocState<T>> | undefined;
78
80
  }]>;
@@ -1 +1 @@
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,kBAAkB,EAAE,KAAK,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACpG,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,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAA;IACrC,IAAI,EAAE,OAAO,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAA;CACnC,CAAA;AAED,qBAAa,mBAAmB,CAAC,CAAC,SAAS,GAAG;;IAoB9B,OAAO,CAAC,OAAO;IAlB3B,SAAgB,EAAE,SAAsC;IAMjD,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;IACvB,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;IAEzC,SAAgB,KAAK,EAAE,eAAe,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IACxE,SAA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,CAAC,EAAE,CAAC,KAAK,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAYvC"}
@@ -0,0 +1,231 @@
1
+ import { BehaviorSubject, debounceTime, EMPTY, filter, finalize, merge, Observable, pairwise, Subject, Subscription, switchMap, tap } from "rxjs";
2
+ import { LivequeryCore } from "./LivequeryCore.js";
3
+ import { LivequeryDocument } from "./LivequeryDocument.js";
4
+ export class LivequeryCollection {
5
+ core;
6
+ options;
7
+ id = (Math.random() * 1e18).toString(36);
8
+ #keys = new Map();
9
+ #indexes;
10
+ #filters = new Subject();
11
+ ref;
12
+ collection_ref;
13
+ items;
14
+ summary;
15
+ metadata;
16
+ loading;
17
+ filters;
18
+ paging;
19
+ error;
20
+ constructor(core, options = {}) {
21
+ this.core = core;
22
+ this.options = options;
23
+ this.#indexes = new Map();
24
+ this.items = new BehaviorSubject([]);
25
+ this.summary = new BehaviorSubject({});
26
+ this.loading = new BehaviorSubject(null);
27
+ this.filters = new BehaviorSubject(options?.filters || {});
28
+ this.paging = new BehaviorSubject({
29
+ total: 0,
30
+ current: 0
31
+ });
32
+ this.error = new BehaviorSubject(null);
33
+ if (options) {
34
+ this.options = options;
35
+ }
36
+ }
37
+ #commit(items) {
38
+ this.items.next(items);
39
+ this.#indexes = items.reduce((p, c, index) => {
40
+ p.set(c.value.id, index);
41
+ return p;
42
+ }, new Map());
43
+ }
44
+ #subscription = null;
45
+ initialize(ref) {
46
+ if (!ref)
47
+ return;
48
+ if (typeof window == 'undefined')
49
+ return;
50
+ this.ref = ref;
51
+ const refs = ref.split('/');
52
+ this.collection_ref = refs.length % 2 == 0 ? refs.slice(0, -1).join('/') : ref;
53
+ const timer = this.options.lazy !== true && setTimeout(() => !ref.includes('undefined') && this.query(this.filters.value || {}));
54
+ this.#subscription?.unsubscribe();
55
+ this.#subscription = merge(this.options.debounce ? merge(this.#filters.pipe(debounceTime(this.options.debounce), switchMap(filters => this.query(filters)))) : EMPTY, this.core.watch(this.ref, this.id, this.options.mode || 'server-first').pipe(finalize(() => {
56
+ timer && clearTimeout(timer);
57
+ }), tap(event => {
58
+ event.loading !== undefined && event.loading !== this.loading.value && this.loading.next(event.loading);
59
+ event.summary && this.summary.next(event.summary);
60
+ event.metadata && this.metadata.next(event.metadata);
61
+ event.paging && this.paging.next(event.paging);
62
+ event.error && this.error.next(event.error);
63
+ if (!event.changes || event.changes.length == 0)
64
+ return;
65
+ const chaos = event.changes && event.changes.some(change => {
66
+ if (change.type == 'added' || change.type == 'removed')
67
+ return true;
68
+ if (change.data && change.data.id != change.id)
69
+ return true;
70
+ return Object.keys(change.data || {}).some(k => this.#keys.has(k));
71
+ });
72
+ const sorter = (a, b) => {
73
+ for (const [key, order] of this.#keys) {
74
+ const va = a.value[key];
75
+ const vb = b.value[key];
76
+ if (typeof va === 'number' && typeof vb === 'number') {
77
+ if (va < vb)
78
+ return -order;
79
+ if (va > vb)
80
+ return order;
81
+ }
82
+ if (typeof va === 'string' && typeof vb === 'string') {
83
+ if (va < vb)
84
+ return -order;
85
+ if (va > vb)
86
+ return order;
87
+ }
88
+ }
89
+ return 0;
90
+ };
91
+ const events = event.changes.reduce((p, c) => {
92
+ return {
93
+ ...p,
94
+ [c.type]: [
95
+ ...(p[c.type] || []),
96
+ c
97
+ ]
98
+ };
99
+ }, {
100
+ added: [],
101
+ modified: [],
102
+ removed: []
103
+ });
104
+ const updated_items = events.modified.reduce((p, { data, id }) => {
105
+ const index = this.#indexes.get(id);
106
+ const target = index != undefined && index >= 0 ? p[index] : null;
107
+ target && target.next({ ...target.value, ...data });
108
+ return p;
109
+ }, this.items.value);
110
+ const new_items = (events.added
111
+ .filter(a => a.data)
112
+ .reduce((p, c) => {
113
+ if (!p.indexes.has(c.id)) {
114
+ const doc = new LivequeryDocument(this, { id: c.id, ...c.data });
115
+ p.list.push(doc);
116
+ p.indexes.add(c.id);
117
+ }
118
+ return p;
119
+ }, {
120
+ list: [],
121
+ indexes: new Set(this.#indexes.keys())
122
+ }));
123
+ const remove_indexes = (events.removed
124
+ .map(r => this.#indexes.get(r.id))
125
+ .filter(i => i != undefined)
126
+ .sort((a, b) => b - a));
127
+ const unsort_items = remove_indexes.reduce((p, index) => {
128
+ return [
129
+ ...p.slice(0, index),
130
+ ...p.slice(index + 1)
131
+ ];
132
+ }, [
133
+ ...updated_items,
134
+ ...new_items.list
135
+ ]);
136
+ const items = chaos ? unsort_items.sort(sorter) : unsort_items;
137
+ chaos && this.#commit(items);
138
+ event.paging && this.paging.next(event.paging);
139
+ }))).subscribe();
140
+ return this.#subscription;
141
+ }
142
+ async #query(filters, flush) {
143
+ if (!this.ref)
144
+ return;
145
+ this.error.next(null);
146
+ flush && this.#commit([]);
147
+ this.#keys = Object.entries(filters).reduce((p, [k, v]) => {
148
+ if (k.endsWith(':sort')) {
149
+ const field = k.split(':')[0];
150
+ p.set(field, v === 'asc' ? 1 : -1);
151
+ }
152
+ return p;
153
+ }, new Map());
154
+ this.filters.next(filters);
155
+ const cache = await this.core.query({
156
+ ref: this.ref,
157
+ filters,
158
+ collection_id: this.id
159
+ });
160
+ if (cache && cache.documents && flush) {
161
+ this.#commit(cache.documents.map(i => new LivequeryDocument(this, i)));
162
+ }
163
+ }
164
+ async query(filters) {
165
+ await this.#query(filters, true);
166
+ }
167
+ async debounceQuery(filters) {
168
+ this.#filters.next(filters);
169
+ }
170
+ async loadMore() {
171
+ const next = this.paging.value.next;
172
+ if (!next)
173
+ return;
174
+ const filters = {
175
+ ...this.filters.value,
176
+ ':after': next.cursor
177
+ };
178
+ await this.#query(filters || {}, false);
179
+ }
180
+ async loadPrev() {
181
+ const prev = this.paging.value.prev;
182
+ if (!prev)
183
+ return;
184
+ const filters = {
185
+ ...this.filters.value,
186
+ ':before': prev.cursor
187
+ };
188
+ await this.#query(filters || {}, false);
189
+ }
190
+ async loadAround(cursor) {
191
+ const filters = {
192
+ ...this.filters.value,
193
+ ':after': cursor,
194
+ ':before': cursor
195
+ };
196
+ await this.#query(filters || {}, false);
197
+ }
198
+ add(payload) {
199
+ if (!this.collection_ref)
200
+ throw new Error('LivequeryCollection is not initialized with a ref');
201
+ return this.core.add(this.collection_ref, payload);
202
+ }
203
+ update(id, payload) {
204
+ if (!this.collection_ref)
205
+ throw new Error('LivequeryCollection is not initialized with a ref');
206
+ return this.core.update(this.collection_ref, id, payload);
207
+ }
208
+ delete(id) {
209
+ if (!this.collection_ref)
210
+ throw new Error('LivequeryCollection is not initialized with a ref');
211
+ return this.core.delete(this.collection_ref, id);
212
+ }
213
+ trigger(action, payload) {
214
+ if (!this.ref)
215
+ throw new Error('LivequeryCollection is not initialized with a ref');
216
+ return this.core.trigger({
217
+ action,
218
+ payload,
219
+ ref: this.ref
220
+ });
221
+ }
222
+ resetError() {
223
+ this.error.next(null);
224
+ }
225
+ watch(check) {
226
+ return this.items.pipe(switchMap(items => merge(...items.map(item => item.pipe(pairwise(), filter(([p, n]) => {
227
+ return check(p, n);
228
+ }))))));
229
+ }
230
+ }
231
+ //# sourceMappingURL=LivequeryCollection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LivequeryCollection.js","sourceRoot":"","sources":["../src/LivequeryCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AACjJ,OAAO,EAAE,aAAa,EAAuD,MAAM,oBAAoB,CAAA;AAEvG,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAY1D,MAAM,OAAO,mBAAmB;IAkBR;IAA6B;IAhBjC,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IACxD,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAA;IAClC,QAAQ,CAAqB;IA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import type { LivequeryQueryResult, LivequeryTransporter } from "./LivequeryTransporter";
4
- import type { DataChangeEvent, LivequeryAction, Doc, LivequeryQueryParams, LivequeryFilters, RealtimeChangeSource } from "./types";
2
+ import type { LivequeryStorge } from "./LivequeryStorge.js";
3
+ import type { LivequeryQueryResult, LivequeryTransporter } from "./LivequeryTransporter.js";
4
+ import type { DataChangeEvent, LivequeryAction, Doc, LivequeryQueryParams, LivequeryFilters, RealtimeChangeSource } from "./types.js";
5
5
  export type LivequeryCoreOptions = {
6
6
  transporters: Record<string, LivequeryTransporter>;
7
7
  storage: LivequeryStorge;
@@ -45,7 +45,7 @@ export declare class LivequeryCore {
45
45
  collection_id: string;
46
46
  }): Promise<{
47
47
  documents: T[];
48
- paging: import("./types").LivequeryPaging;
48
+ paging: import("./types.js").LivequeryPaging;
49
49
  } | {
50
50
  documents: T[];
51
51
  } | undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"LivequeryCore.d.ts","sourceRoot":"","sources":["../src/LivequeryCore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmH,UAAU,EAAyB,OAAO,EAAwC,MAAM,MAAM,CAAA;AACxN,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACxF,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,EAAE,oBAAoB,EAAY,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAM5I,MAAM,MAAM,oBAAoB,GAAG;IAC/B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAA;IAClD,OAAO,EAAE,eAAe,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAA;AAKlE,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG;IACxC,GAAG,E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