@naturalcycles/db-lib 9.9.1 → 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.
@@ -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 | Error | undefined>;
15
- set(k: string, v: VALUE | Error): Promise<void>;
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)) || undefined;
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
@@ -40,7 +40,7 @@
40
40
  "engines": {
41
41
  "node": ">=18.12"
42
42
  },
43
- "version": "9.9.1",
43
+ "version": "9.9.2",
44
44
  "description": "Lowest Common Denominator API to supported Databases",
45
45
  "keywords": [
46
46
  "db",
@@ -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 | Error | undefined> {
16
- return (await this.dao.getById(k)) || undefined
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 | Error): Promise<void> {
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