@naturalcycles/db-lib 8.33.0 → 8.33.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.
@@ -1,9 +1,17 @@
1
1
  import { AsyncMemoCache } from '@naturalcycles/js-lib';
2
2
  import { CommonKeyValueDao } from './commonKeyValueDao';
3
+ /**
4
+ * AsyncMemoCache implementation, backed by CommonKeyValueDao.
5
+ *
6
+ * Does NOT support persisting Errors, skips them instead.
7
+ *
8
+ * Also, does not support .clear(), as it's more dangerous than useful to actually
9
+ * clear the whole table/cache.
10
+ */
3
11
  export declare class CommonKeyValueDaoMemoCache<VALUE = any> implements AsyncMemoCache<string, VALUE> {
4
12
  private dao;
5
13
  constructor(dao: CommonKeyValueDao<VALUE>);
6
- get(k: string): Promise<VALUE | undefined>;
7
- set(k: string, v: VALUE): Promise<void>;
14
+ get(k: string): Promise<VALUE | Error | undefined>;
15
+ set(k: string, v: VALUE | Error): Promise<void>;
8
16
  clear(): Promise<void>;
9
17
  }
@@ -1,6 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommonKeyValueDaoMemoCache = void 0;
4
+ /**
5
+ * AsyncMemoCache implementation, backed by CommonKeyValueDao.
6
+ *
7
+ * Does NOT support persisting Errors, skips them instead.
8
+ *
9
+ * Also, does not support .clear(), as it's more dangerous than useful to actually
10
+ * clear the whole table/cache.
11
+ */
4
12
  class CommonKeyValueDaoMemoCache {
5
13
  constructor(dao) {
6
14
  this.dao = dao;
@@ -9,10 +17,14 @@ class CommonKeyValueDaoMemoCache {
9
17
  return (await this.dao.getById(k)) || undefined;
10
18
  }
11
19
  async set(k, v) {
20
+ if (v instanceof Error) {
21
+ // We currently don't persist errors there
22
+ return;
23
+ }
12
24
  await this.dao.save(k, v);
13
25
  }
14
26
  async clear() {
15
- throw new Error('CommonKeyValueDaoCacheFactory.clear is not supported, because cache is expected to be persistent');
27
+ throw new Error('CommonKeyValueDaoMemoCache.clear is not supported, because cache is expected to be persistent');
16
28
  }
17
29
  }
18
30
  exports.CommonKeyValueDaoMemoCache = CommonKeyValueDaoMemoCache;
package/package.json CHANGED
@@ -43,7 +43,7 @@
43
43
  "engines": {
44
44
  "node": ">=14.15"
45
45
  },
46
- "version": "8.33.0",
46
+ "version": "8.33.1",
47
47
  "description": "Lowest Common Denominator API to supported Databases",
48
48
  "keywords": [
49
49
  "db",
@@ -1,20 +1,33 @@
1
1
  import { AsyncMemoCache } from '@naturalcycles/js-lib'
2
2
  import { CommonKeyValueDao } from './commonKeyValueDao'
3
3
 
4
+ /**
5
+ * AsyncMemoCache implementation, backed by CommonKeyValueDao.
6
+ *
7
+ * Does NOT support persisting Errors, skips them instead.
8
+ *
9
+ * Also, does not support .clear(), as it's more dangerous than useful to actually
10
+ * clear the whole table/cache.
11
+ */
4
12
  export class CommonKeyValueDaoMemoCache<VALUE = any> implements AsyncMemoCache<string, VALUE> {
5
13
  constructor(private dao: CommonKeyValueDao<VALUE>) {}
6
14
 
7
- async get(k: string): Promise<VALUE | undefined> {
15
+ async get(k: string): Promise<VALUE | Error | undefined> {
8
16
  return (await this.dao.getById(k)) || undefined
9
17
  }
10
18
 
11
- async set(k: string, v: VALUE): Promise<void> {
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
+
12
25
  await this.dao.save(k, v)
13
26
  }
14
27
 
15
28
  async clear(): Promise<void> {
16
29
  throw new Error(
17
- 'CommonKeyValueDaoCacheFactory.clear is not supported, because cache is expected to be persistent',
30
+ 'CommonKeyValueDaoMemoCache.clear is not supported, because cache is expected to be persistent',
18
31
  )
19
32
  }
20
33
  }