mikser-io-sdk-api 3.5.0 → 3.5.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 +4 -1
- package/package.json +1 -1
- package/src/entities.js +38 -12
package/README.md
CHANGED
|
@@ -453,6 +453,8 @@ For framework integration, prefer `live()` below — it handles the list+watch c
|
|
|
453
453
|
|
|
454
454
|
The higher-level real-time primitive. Calls `onChange(items)` with the initial snapshot, then again with the patched array on every create/update/delete event. Returns a dispose function.
|
|
455
455
|
|
|
456
|
+
The initial snapshot is the **complete** matching set — `live()` paginates to the end, it doesn't stop at the server's default page size. This keeps the snapshot consistent with the SSE stream that follows: `watch()` subscribes by filter with no limit, so a create/update/delete to *any* matching entity is delivered; if the snapshot were capped at page one, updates to entities past it would silently no-op (they aren't in `items`) and the view would drift. Pass `limit` (or `skip`) only when you want a bounded window — a "latest N" feed — and accept that updates outside that window won't be reflected.
|
|
457
|
+
|
|
456
458
|
```js
|
|
457
459
|
const dispose = docs.live(
|
|
458
460
|
{ 'meta.published': true, type: 'document' },
|
|
@@ -476,7 +478,8 @@ dispose()
|
|
|
476
478
|
Equivalent to:
|
|
477
479
|
|
|
478
480
|
```js
|
|
479
|
-
// 1.
|
|
481
|
+
// 1. paginate list({ filter, sort, fields }) to the end (or one bounded
|
|
482
|
+
// list() when limit/skip is set)
|
|
480
483
|
// 2. onChange(items)
|
|
481
484
|
// 3. for await (event of watch({ filter })) patch + onChange
|
|
482
485
|
// 4. abort on dispose
|
package/package.json
CHANGED
package/src/entities.js
CHANGED
|
@@ -556,19 +556,45 @@ export function createEntitiesClient({ baseUrl, basePath, fetch: doFetch, header
|
|
|
556
556
|
}
|
|
557
557
|
|
|
558
558
|
if (!usedFastPath) {
|
|
559
|
-
//
|
|
560
|
-
//
|
|
559
|
+
// The initial snapshot must be the COMPLETE matching
|
|
560
|
+
// set, not a single server page. watch() below
|
|
561
|
+
// subscribes by filter with no limit, so create /
|
|
562
|
+
// update / delete events arrive for ANY matching
|
|
563
|
+
// entity. If the initial load stopped at the server's
|
|
564
|
+
// default page size, an update to an entity past page 1
|
|
565
|
+
// would silently no-op (it isn't in `items`) and a
|
|
566
|
+
// create could append out of sort order — the live view
|
|
567
|
+
// would drift out of sync with its own change stream.
|
|
568
|
+
// So paginate to completion, unless the caller opted
|
|
569
|
+
// into a bounded window via `limit` or `skip`.
|
|
561
570
|
//
|
|
562
|
-
//
|
|
563
|
-
//
|
|
564
|
-
//
|
|
565
|
-
//
|
|
566
|
-
//
|
|
567
|
-
//
|
|
568
|
-
//
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
571
|
+
// Pass { quiet } so list()'s wide-warning honors the
|
|
572
|
+
// live() caller's quiet opt.
|
|
573
|
+
//
|
|
574
|
+
// `expand` flows through to the initial snapshot call
|
|
575
|
+
// AND to watch() below, so the server's graph-
|
|
576
|
+
// subscription path (runtime.refs) emits already-
|
|
577
|
+
// expanded entities on every mutation within the
|
|
578
|
+
// expansion graph. Update events replace items in place
|
|
579
|
+
// with the new expanded shape, keeping the consumer's
|
|
580
|
+
// view consistent.
|
|
581
|
+
const bounded = limit != null || skip != null
|
|
582
|
+
if (bounded) {
|
|
583
|
+
const env = await list({ filter, sort, fields, limit, skip, expand }, { quiet })
|
|
584
|
+
if (disposed || ac.signal.aborted) return
|
|
585
|
+
items = env.items
|
|
586
|
+
} else {
|
|
587
|
+
const collected = []
|
|
588
|
+
let page = 1
|
|
589
|
+
while (true) {
|
|
590
|
+
const env = await list({ filter, sort, fields, expand, limit: 1000, page }, { quiet })
|
|
591
|
+
if (disposed || ac.signal.aborted) return
|
|
592
|
+
collected.push(...env.items)
|
|
593
|
+
if (!env.hasNext) break
|
|
594
|
+
page = env.page + 1
|
|
595
|
+
}
|
|
596
|
+
items = collected
|
|
597
|
+
}
|
|
572
598
|
onChange(items)
|
|
573
599
|
}
|
|
574
600
|
|