pbtsdb 0.9.3 → 0.10.1
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 +49 -0
- package/dist/chunk-4RQ6OSTM.js +1544 -0
- package/dist/chunk-4RQ6OSTM.js.map +1 -0
- package/dist/core.d.ts +105 -26
- package/dist/core.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-NVAHFHH4.js +0 -1067
- package/dist/chunk-NVAHFHH4.js.map +0 -1
package/README.md
CHANGED
|
@@ -358,6 +358,7 @@ const collection = c(collectionName: string, options?: CreateCollectionOptions);
|
|
|
358
358
|
- `alwaysFetchRelations?: readonly string[]` - Expand paths fetched with every request and filed into their `relations` targets; never kept on the row
|
|
359
359
|
- `omitOnInsert?: readonly string[]` - Fields to make optional during insert (e.g., `['created', 'updated'] as const`)
|
|
360
360
|
- `syncMode?: 'eager' | 'on-demand'` - Data fetching strategy (default: `'eager'`)
|
|
361
|
+
- `realtime?: 'collection' | 'query'` - Which rows the realtime subscription covers (default: `'collection'`; `'query'` requires `syncMode: 'on-demand'`; see [Realtime Scope](#realtime-scope))
|
|
361
362
|
- `onInsert?: InsertMutationFn | false` - Custom insert handler or `false` to disable
|
|
362
363
|
- `onUpdate?: UpdateMutationFn | false` - Custom update handler or `false` to disable
|
|
363
364
|
- `onDelete?: DeleteMutationFn | false` - Custom delete handler or `false` to disable
|
|
@@ -602,6 +603,54 @@ await collection.waitForSubscription(); // Wait with default 5s timeout
|
|
|
602
603
|
await collection.waitForSubscription(10000); // Wait with custom timeout (ms)
|
|
603
604
|
```
|
|
604
605
|
|
|
606
|
+
#### Realtime Scope
|
|
607
|
+
|
|
608
|
+
By default a collection subscribes to every row (`realtime: 'collection'`).
|
|
609
|
+
An on-demand collection can instead subscribe per active query, using the
|
|
610
|
+
same filter its fetch sends:
|
|
611
|
+
|
|
612
|
+
```typescript
|
|
613
|
+
const books = c('books', { syncMode: 'on-demand', realtime: 'query' });
|
|
614
|
+
|
|
615
|
+
// subscribes with filter genre = "Fantasy"
|
|
616
|
+
useLiveQuery((q) => q.from({ b: books }).where(({ b }) => eq(b.genre, 'Fantasy')));
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
One PocketBase subscription is opened per distinct filter string and closed
|
|
620
|
+
when the last query using it unmounts. A query with no `where` subscribes to
|
|
621
|
+
the whole collection. While any whole-collection subscription is open, the
|
|
622
|
+
filtered ones stay closed.
|
|
623
|
+
|
|
624
|
+
PocketBase caps a realtime subscription topic at 2500 characters. An id
|
|
625
|
+
subset is split into smaller chunks for realtime than for fetches, one
|
|
626
|
+
subscription per chunk. A filter whose topic is still too long (a long
|
|
627
|
+
non-subset `where`, or one combined with a factory `subscribeOptions` filter)
|
|
628
|
+
is not sent. The collection logs a warning and subscribes to every row while
|
|
629
|
+
that filter is in use.
|
|
630
|
+
|
|
631
|
+
A `'query'` collection held live as a relation target subscribes only to the
|
|
632
|
+
rows the parent filed into it: the expanded records' ids for a forward
|
|
633
|
+
relation (`author`), or `field = parentId` for a back-relation
|
|
634
|
+
(`books_via_author`), so new children still arrive. A `'collection'` target
|
|
635
|
+
subscribes to every row while held, as before.
|
|
636
|
+
|
|
637
|
+
Override the mode for one query with `withRealtime()`, which returns a view
|
|
638
|
+
and composes with `fetchRelations()` in either order:
|
|
639
|
+
|
|
640
|
+
```typescript
|
|
641
|
+
useLiveQuery((q) => q.from({ b: books.withRealtime('collection') }));
|
|
642
|
+
useLiveQuery((q) => q.from({ b: books.fetchRelations('author').withRealtime('query') }));
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
**Known limit.** PocketBase checks an update against the row's state after
|
|
646
|
+
the change. An update that moves a row out of every active filter sends no
|
|
647
|
+
event, so the row stays in the store until its query refetches. Deletes and
|
|
648
|
+
creates are delivered correctly. Use `'collection'` mode where that matters.
|
|
649
|
+
|
|
650
|
+
A held `'query'` target keeps the ids filed into it until the parent
|
|
651
|
+
collection is cleaned up, so a long session with many distinct filed ids
|
|
652
|
+
opens many subscriptions, one per id chunk.
|
|
653
|
+
|
|
605
654
|
#### Subscription Options
|
|
606
655
|
|
|
607
656
|
Pass `subscribeOptions` as the third `createCollection` argument to attach extra
|