@naturalcycles/cloud-storage-lib 1.13.3 → 1.13.4

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