@naturalcycles/db-lib 9.9.0 → 9.9.2
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.
|
@@ -494,23 +494,29 @@ class CommonDao {
|
|
|
494
494
|
return await this.patchInTransaction(bm, patch, opt);
|
|
495
495
|
}
|
|
496
496
|
if (opt.skipDBRead) {
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
497
|
+
const patched = {
|
|
498
|
+
...bm,
|
|
499
|
+
...patch,
|
|
500
|
+
};
|
|
501
|
+
if ((0, js_lib_1._deepJsonEquals)(bm, patched)) {
|
|
500
502
|
// Skipping the save operation, as data is the same
|
|
501
503
|
return bm;
|
|
502
504
|
}
|
|
505
|
+
Object.assign(bm, patch);
|
|
503
506
|
}
|
|
504
507
|
else {
|
|
505
508
|
const loaded = await this.getById(bm.id, opt);
|
|
506
509
|
if (loaded) {
|
|
507
|
-
|
|
508
|
-
|
|
510
|
+
const loadedWithPatch = {
|
|
511
|
+
...loaded,
|
|
512
|
+
...patch,
|
|
513
|
+
};
|
|
514
|
+
// Make `bm` exactly the same as `loadedWithPatch`
|
|
515
|
+
(0, js_lib_1._objectAssignExact)(bm, loadedWithPatch);
|
|
516
|
+
if ((0, js_lib_1._deepJsonEquals)(loaded, loadedWithPatch)) {
|
|
509
517
|
// Skipping the save operation, as data is the same
|
|
510
518
|
return bm;
|
|
511
519
|
}
|
|
512
|
-
// Make `bm` exactly the same as `loaded`
|
|
513
|
-
(0, js_lib_1._objectAssignExact)(bm, loaded);
|
|
514
520
|
}
|
|
515
521
|
else {
|
|
516
522
|
Object.assign(bm, patch);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncMemoCache } from '@naturalcycles/js-lib';
|
|
1
|
+
import { AsyncMemoCache, MISS } from '@naturalcycles/js-lib';
|
|
2
2
|
import { CommonKeyValueDao } from './commonKeyValueDao';
|
|
3
3
|
/**
|
|
4
4
|
* AsyncMemoCache implementation, backed by CommonKeyValueDao.
|
|
@@ -11,7 +11,7 @@ import { CommonKeyValueDao } from './commonKeyValueDao';
|
|
|
11
11
|
export declare class CommonKeyValueDaoMemoCache<VALUE = any> implements AsyncMemoCache<string, VALUE> {
|
|
12
12
|
private dao;
|
|
13
13
|
constructor(dao: CommonKeyValueDao<VALUE>);
|
|
14
|
-
get(k: string): Promise<VALUE |
|
|
15
|
-
set(k: string, v: VALUE
|
|
14
|
+
get(k: string): Promise<VALUE | typeof MISS>;
|
|
15
|
+
set(k: string, v: VALUE): Promise<void>;
|
|
16
16
|
clear(): Promise<void>;
|
|
17
17
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommonKeyValueDaoMemoCache = void 0;
|
|
4
|
+
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
4
5
|
/**
|
|
5
6
|
* AsyncMemoCache implementation, backed by CommonKeyValueDao.
|
|
6
7
|
*
|
|
@@ -14,13 +15,9 @@ class CommonKeyValueDaoMemoCache {
|
|
|
14
15
|
this.dao = dao;
|
|
15
16
|
}
|
|
16
17
|
async get(k) {
|
|
17
|
-
return (await this.dao.getById(k)) ||
|
|
18
|
+
return (await this.dao.getById(k)) || js_lib_1.MISS;
|
|
18
19
|
}
|
|
19
20
|
async set(k, v) {
|
|
20
|
-
if (v instanceof Error) {
|
|
21
|
-
// We currently don't persist errors there
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
21
|
await this.dao.save(k, v);
|
|
25
22
|
}
|
|
26
23
|
async clear() {
|
package/package.json
CHANGED
|
@@ -669,25 +669,32 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM> {
|
|
|
669
669
|
}
|
|
670
670
|
|
|
671
671
|
if (opt.skipDBRead) {
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
|
|
672
|
+
const patched: BM = {
|
|
673
|
+
...bm,
|
|
674
|
+
...patch,
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
if (_deepJsonEquals(bm, patched)) {
|
|
675
678
|
// Skipping the save operation, as data is the same
|
|
676
679
|
return bm
|
|
677
680
|
}
|
|
681
|
+
Object.assign(bm, patch)
|
|
678
682
|
} else {
|
|
679
683
|
const loaded = await this.getById(bm.id, opt)
|
|
680
684
|
|
|
681
685
|
if (loaded) {
|
|
682
|
-
|
|
686
|
+
const loadedWithPatch: BM = {
|
|
687
|
+
...loaded,
|
|
688
|
+
...patch,
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// Make `bm` exactly the same as `loadedWithPatch`
|
|
692
|
+
_objectAssignExact(bm, loadedWithPatch)
|
|
683
693
|
|
|
684
|
-
if (_deepJsonEquals(loaded,
|
|
694
|
+
if (_deepJsonEquals(loaded, loadedWithPatch)) {
|
|
685
695
|
// Skipping the save operation, as data is the same
|
|
686
696
|
return bm
|
|
687
697
|
}
|
|
688
|
-
|
|
689
|
-
// Make `bm` exactly the same as `loaded`
|
|
690
|
-
_objectAssignExact(bm, loaded)
|
|
691
698
|
} else {
|
|
692
699
|
Object.assign(bm, patch)
|
|
693
700
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncMemoCache } from '@naturalcycles/js-lib'
|
|
1
|
+
import { AsyncMemoCache, MISS } from '@naturalcycles/js-lib'
|
|
2
2
|
import { CommonKeyValueDao } from './commonKeyValueDao'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -12,16 +12,11 @@ import { CommonKeyValueDao } from './commonKeyValueDao'
|
|
|
12
12
|
export class CommonKeyValueDaoMemoCache<VALUE = any> implements AsyncMemoCache<string, VALUE> {
|
|
13
13
|
constructor(private dao: CommonKeyValueDao<VALUE>) {}
|
|
14
14
|
|
|
15
|
-
async get(k: string): Promise<VALUE |
|
|
16
|
-
return (await this.dao.getById(k)) ||
|
|
15
|
+
async get(k: string): Promise<VALUE | typeof MISS> {
|
|
16
|
+
return (await this.dao.getById(k)) || MISS
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
async set(k: string, v: VALUE
|
|
20
|
-
if (v instanceof Error) {
|
|
21
|
-
// We currently don't persist errors there
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
|
|
19
|
+
async set(k: string, v: VALUE): Promise<void> {
|
|
25
20
|
await this.dao.save(k, v)
|
|
26
21
|
}
|
|
27
22
|
|