@koolbase/core 12.48.0 → 12.49.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/dist/cjs/database.js +31 -2
- package/dist/esm/database.js +31 -2
- package/package.json +1 -1
package/dist/cjs/database.js
CHANGED
|
@@ -421,6 +421,16 @@ class KoolbaseDatabase {
|
|
|
421
421
|
if (operations.length === 0) {
|
|
422
422
|
throw new Error('batch requires at least one operation');
|
|
423
423
|
}
|
|
424
|
+
// The collections an update or delete addresses by id, from the device's
|
|
425
|
+
// saved copies, read before the request (12.49.0): a delete leaves nothing
|
|
426
|
+
// to read afterwards.
|
|
427
|
+
const userIdBefore = this.getUserId() ?? 'anonymous';
|
|
428
|
+
const byId = new Map();
|
|
429
|
+
for (const op of operations) {
|
|
430
|
+
if (op.type === 'update' || op.type === 'delete') {
|
|
431
|
+
byId.set(op.recordId, (await (0, cache_store_js_1.getCachedRecord)(userIdBefore, op.recordId))?.collection);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
424
434
|
const body = await this.request('POST', '/v1/sdk/db/batch', {
|
|
425
435
|
operations: operations.map(batchOpToWire),
|
|
426
436
|
});
|
|
@@ -446,16 +456,35 @@ class KoolbaseDatabase {
|
|
|
446
456
|
await (0, cache_store_js_1.cacheRecord)(userId, r.record.collection, r.record.id, r.record.data, r.record.revision);
|
|
447
457
|
}
|
|
448
458
|
}
|
|
459
|
+
// Every collection the batch wrote re-reads its live queries (12.49.0):
|
|
460
|
+
// an insert's or upsert's by its op, an update's by the record it returned
|
|
461
|
+
// or its saved copy, a delete's by its saved copy. One it cannot name --
|
|
462
|
+
// a record never read on this device -- re-runs every live query rather
|
|
463
|
+
// than a guess, as a single delete does.
|
|
449
464
|
const touched = new Set();
|
|
450
|
-
|
|
465
|
+
let unknown = false;
|
|
466
|
+
operations.forEach((op, i) => {
|
|
451
467
|
if (op.type === 'insert' || op.type === 'upsert') {
|
|
452
468
|
touched.add(op.collection);
|
|
469
|
+
return;
|
|
453
470
|
}
|
|
471
|
+
const col = results[i]?.record?.collection ?? byId.get(op.recordId);
|
|
472
|
+
if (col)
|
|
473
|
+
touched.add(col);
|
|
474
|
+
else
|
|
475
|
+
unknown = true;
|
|
476
|
+
});
|
|
477
|
+
for (const op of operations) {
|
|
478
|
+
if (op.type === 'delete')
|
|
479
|
+
await (0, cache_store_js_1.removeCachedRecord)(userId, op.recordId);
|
|
454
480
|
}
|
|
455
481
|
for (const col of touched) {
|
|
456
482
|
await (0, cache_store_js_3.invalidateCache)(userId, col);
|
|
457
|
-
|
|
483
|
+
if (!unknown)
|
|
484
|
+
void (0, query_refresh_js_1.refreshCollectionQueries)(col);
|
|
458
485
|
}
|
|
486
|
+
if (unknown)
|
|
487
|
+
void (0, query_refresh_js_1.refreshCollectionQueries)(undefined);
|
|
459
488
|
return results;
|
|
460
489
|
}
|
|
461
490
|
// ─── Get single record ──────────────────────────────────────────────────────
|
package/dist/esm/database.js
CHANGED
|
@@ -418,6 +418,16 @@ export class KoolbaseDatabase {
|
|
|
418
418
|
if (operations.length === 0) {
|
|
419
419
|
throw new Error('batch requires at least one operation');
|
|
420
420
|
}
|
|
421
|
+
// The collections an update or delete addresses by id, from the device's
|
|
422
|
+
// saved copies, read before the request (12.49.0): a delete leaves nothing
|
|
423
|
+
// to read afterwards.
|
|
424
|
+
const userIdBefore = this.getUserId() ?? 'anonymous';
|
|
425
|
+
const byId = new Map();
|
|
426
|
+
for (const op of operations) {
|
|
427
|
+
if (op.type === 'update' || op.type === 'delete') {
|
|
428
|
+
byId.set(op.recordId, (await getCachedRecord(userIdBefore, op.recordId))?.collection);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
421
431
|
const body = await this.request('POST', '/v1/sdk/db/batch', {
|
|
422
432
|
operations: operations.map(batchOpToWire),
|
|
423
433
|
});
|
|
@@ -443,16 +453,35 @@ export class KoolbaseDatabase {
|
|
|
443
453
|
await cacheRecord(userId, r.record.collection, r.record.id, r.record.data, r.record.revision);
|
|
444
454
|
}
|
|
445
455
|
}
|
|
456
|
+
// Every collection the batch wrote re-reads its live queries (12.49.0):
|
|
457
|
+
// an insert's or upsert's by its op, an update's by the record it returned
|
|
458
|
+
// or its saved copy, a delete's by its saved copy. One it cannot name --
|
|
459
|
+
// a record never read on this device -- re-runs every live query rather
|
|
460
|
+
// than a guess, as a single delete does.
|
|
446
461
|
const touched = new Set();
|
|
447
|
-
|
|
462
|
+
let unknown = false;
|
|
463
|
+
operations.forEach((op, i) => {
|
|
448
464
|
if (op.type === 'insert' || op.type === 'upsert') {
|
|
449
465
|
touched.add(op.collection);
|
|
466
|
+
return;
|
|
450
467
|
}
|
|
468
|
+
const col = results[i]?.record?.collection ?? byId.get(op.recordId);
|
|
469
|
+
if (col)
|
|
470
|
+
touched.add(col);
|
|
471
|
+
else
|
|
472
|
+
unknown = true;
|
|
473
|
+
});
|
|
474
|
+
for (const op of operations) {
|
|
475
|
+
if (op.type === 'delete')
|
|
476
|
+
await removeCachedRecord(userId, op.recordId);
|
|
451
477
|
}
|
|
452
478
|
for (const col of touched) {
|
|
453
479
|
await invalidateCache(userId, col);
|
|
454
|
-
|
|
480
|
+
if (!unknown)
|
|
481
|
+
void refreshCollectionQueries(col);
|
|
455
482
|
}
|
|
483
|
+
if (unknown)
|
|
484
|
+
void refreshCollectionQueries(undefined);
|
|
456
485
|
return results;
|
|
457
486
|
}
|
|
458
487
|
// ─── Get single record ──────────────────────────────────────────────────────
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/core",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.49.0",
|
|
4
4
|
"description": "Koolbase SDK core — shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"react-native": "./dist/esm/index.js",
|