@naturalcycles/cloud-storage-lib 1.13.2 → 1.13.3

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,5 +1,6 @@
1
- import { CommonDBCreateOptions, CommonKeyValueDB, KeyValueDBTuple } from '@naturalcycles/db-lib';
2
- import { StringMap } from '@naturalcycles/js-lib';
1
+ import { CommonDBCreateOptions, CommonKeyValueDB } from '@naturalcycles/db-lib';
2
+ import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB';
3
+ import { KeyValueTuple } from '@naturalcycles/js-lib';
3
4
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
4
5
  import { CommonStorage } from './commonStorage';
5
6
  export interface CommonStorageKeyValueDBCfg {
@@ -28,12 +29,11 @@ export declare class CommonStorageKeyValueDB implements CommonKeyValueDB {
28
29
  */
29
30
  private getBucketAndPrefix;
30
31
  deleteByIds(table: string, ids: string[]): Promise<void>;
31
- getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]>;
32
- saveBatch(table: string, entries: KeyValueDBTuple[]): Promise<void>;
32
+ getByIds<V>(table: string, ids: string[]): Promise<KeyValueTuple<string, V>[]>;
33
+ saveBatch<V>(table: string, entries: KeyValueTuple<string, V>[]): Promise<void>;
33
34
  streamIds(table: string, limit?: number): ReadableTyped<string>;
34
- streamValues(table: string, limit?: number): ReadableTyped<Buffer>;
35
- streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple>;
35
+ streamValues<V>(table: string, limit?: number): ReadableTyped<V>;
36
+ streamEntries<V>(table: string, limit?: number): ReadableTyped<KeyValueTuple<string, V>>;
36
37
  count(table: string): Promise<number>;
37
- increment(_table: string, _id: string, _by?: number): Promise<number>;
38
- incrementBatch(_table: string, _incrementMap: StringMap<number>): Promise<StringMap<number>>;
38
+ incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]>;
39
39
  }
@@ -82,10 +82,7 @@ class CommonStorageKeyValueDB {
82
82
  const { bucketName, prefix } = this.getBucketAndPrefix(table);
83
83
  return (await this.cfg.storage.getFileNames(bucketName, { prefix })).length;
84
84
  }
85
- async increment(_table, _id, _by) {
86
- throw new js_lib_1.AppError('CommonStorageKeyValueDB.increment() is not implemented');
87
- }
88
- async incrementBatch(_table, _incrementMap) {
85
+ async incrementBatch(_table, _entries) {
89
86
  throw new js_lib_1.AppError('CommonStorageKeyValueDB.incrementBatch() is not implemented');
90
87
  }
91
88
  }
package/package.json CHANGED
@@ -40,7 +40,7 @@
40
40
  "engines": {
41
41
  "node": ">=20.13.0"
42
42
  },
43
- "version": "1.13.2",
43
+ "version": "1.13.3",
44
44
  "description": "CommonStorage implementation based on Google Cloud Storage",
45
45
  "author": "Natural Cycles Team",
46
46
  "license": "MIT"
@@ -2,9 +2,9 @@ import {
2
2
  CommonDBCreateOptions,
3
3
  CommonKeyValueDB,
4
4
  commonKeyValueDBFullSupport,
5
- KeyValueDBTuple,
6
5
  } from '@naturalcycles/db-lib'
7
- import { AppError, pMap, StringMap } from '@naturalcycles/js-lib'
6
+ import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB'
7
+ import { AppError, KeyValueTuple, pMap, StringMap } from '@naturalcycles/js-lib'
8
8
  import { ReadableTyped } from '@naturalcycles/nodejs-lib'
9
9
  import { CommonStorage } from './commonStorage'
10
10
 
@@ -64,7 +64,7 @@ export class CommonStorageKeyValueDB implements CommonKeyValueDB {
64
64
  })
65
65
  }
66
66
 
67
- async getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]> {
67
+ async getByIds<V>(table: string, ids: string[]): Promise<KeyValueTuple<string, V>[]> {
68
68
  const { bucketName, prefix } = this.getBucketAndPrefix(table)
69
69
 
70
70
  const map: StringMap<Buffer> = {}
@@ -74,14 +74,14 @@ export class CommonStorageKeyValueDB implements CommonKeyValueDB {
74
74
  if (buf) map[id] = buf
75
75
  })
76
76
 
77
- return ids.map(id => [id, map[id]] as KeyValueDBTuple).filter(t => t[1])
77
+ return ids.map(id => [id, map[id]] as KeyValueTuple<string, V>).filter(t => t[1])
78
78
  }
79
79
 
80
- async saveBatch(table: string, entries: KeyValueDBTuple[]): Promise<void> {
80
+ async saveBatch<V>(table: string, entries: KeyValueTuple<string, V>[]): Promise<void> {
81
81
  const { bucketName, prefix } = this.getBucketAndPrefix(table)
82
82
 
83
83
  await pMap(entries, async ([id, content]) => {
84
- await this.cfg.storage.saveFile(bucketName, [prefix, id].join('/'), content)
84
+ await this.cfg.storage.saveFile(bucketName, [prefix, id].join('/'), content as Buffer)
85
85
  })
86
86
  }
87
87
 
@@ -91,18 +91,18 @@ export class CommonStorageKeyValueDB implements CommonKeyValueDB {
91
91
  return this.cfg.storage.getFileNamesStream(bucketName, { prefix, limit, fullPaths: false })
92
92
  }
93
93
 
94
- streamValues(table: string, limit?: number): ReadableTyped<Buffer> {
94
+ streamValues<V>(table: string, limit?: number): ReadableTyped<V> {
95
95
  const { bucketName, prefix } = this.getBucketAndPrefix(table)
96
96
 
97
- return this.cfg.storage.getFilesStream(bucketName, { prefix, limit }).map(f => f.content)
97
+ return this.cfg.storage.getFilesStream(bucketName, { prefix, limit }).map(f => f.content as V)
98
98
  }
99
99
 
100
- streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple> {
100
+ streamEntries<V>(table: string, limit?: number): ReadableTyped<KeyValueTuple<string, V>> {
101
101
  const { bucketName, prefix } = this.getBucketAndPrefix(table)
102
102
 
103
103
  return this.cfg.storage
104
104
  .getFilesStream(bucketName, { prefix, limit, fullPaths: false })
105
- .map(f => [f.filePath, f.content] satisfies KeyValueDBTuple)
105
+ .map(f => [f.filePath, f.content as V])
106
106
  }
107
107
 
108
108
  async count(table: string): Promise<number> {
@@ -111,14 +111,7 @@ export class CommonStorageKeyValueDB implements CommonKeyValueDB {
111
111
  return (await this.cfg.storage.getFileNames(bucketName, { prefix })).length
112
112
  }
113
113
 
114
- async increment(_table: string, _id: string, _by?: number): Promise<number> {
115
- throw new AppError('CommonStorageKeyValueDB.increment() is not implemented')
116
- }
117
-
118
- async incrementBatch(
119
- _table: string,
120
- _incrementMap: StringMap<number>,
121
- ): Promise<StringMap<number>> {
114
+ async incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]> {
122
115
  throw new AppError('CommonStorageKeyValueDB.incrementBatch() is not implemented')
123
116
  }
124
117
  }