@naturalcycles/cloud-storage-lib 1.13.1 → 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.
package/dist/cloudStorage.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CommonLogger, LocalTimeInput } from '@naturalcycles/js-lib';
|
|
|
3
3
|
import type { ReadableBinary, ReadableTyped, WritableBinary } from '@naturalcycles/nodejs-lib';
|
|
4
4
|
import type { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage';
|
|
5
5
|
import type { GCPServiceAccount } from './model';
|
|
6
|
-
export {
|
|
6
|
+
export type { Storage, StorageOptions, };
|
|
7
7
|
/**
|
|
8
8
|
* This object is intentionally made to NOT extend StorageOptions,
|
|
9
9
|
* because StorageOptions is complicated and provides just too many ways
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { CommonDBCreateOptions, CommonKeyValueDB
|
|
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';
|
|
2
4
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
5
|
import { CommonStorage } from './commonStorage';
|
|
4
6
|
export interface CommonStorageKeyValueDBCfg {
|
|
@@ -16,6 +18,10 @@ export interface CommonStorageKeyValueDBCfg {
|
|
|
16
18
|
export declare class CommonStorageKeyValueDB implements CommonKeyValueDB {
|
|
17
19
|
cfg: CommonStorageKeyValueDBCfg;
|
|
18
20
|
constructor(cfg: CommonStorageKeyValueDBCfg);
|
|
21
|
+
support: {
|
|
22
|
+
increment: boolean;
|
|
23
|
+
count?: boolean;
|
|
24
|
+
};
|
|
19
25
|
ping(): Promise<void>;
|
|
20
26
|
createTable(_table: string, _opt?: CommonDBCreateOptions): Promise<void>;
|
|
21
27
|
/**
|
|
@@ -23,11 +29,11 @@ export declare class CommonStorageKeyValueDB implements CommonKeyValueDB {
|
|
|
23
29
|
*/
|
|
24
30
|
private getBucketAndPrefix;
|
|
25
31
|
deleteByIds(table: string, ids: string[]): Promise<void>;
|
|
26
|
-
getByIds(table: string, ids: string[]): Promise<
|
|
27
|
-
saveBatch(table: string, entries:
|
|
32
|
+
getByIds<V>(table: string, ids: string[]): Promise<KeyValueTuple<string, V>[]>;
|
|
33
|
+
saveBatch<V>(table: string, entries: KeyValueTuple<string, V>[]): Promise<void>;
|
|
28
34
|
streamIds(table: string, limit?: number): ReadableTyped<string>;
|
|
29
|
-
streamValues(table: string, limit?: number): ReadableTyped<
|
|
30
|
-
streamEntries(table: string, limit?: number): ReadableTyped<
|
|
35
|
+
streamValues<V>(table: string, limit?: number): ReadableTyped<V>;
|
|
36
|
+
streamEntries<V>(table: string, limit?: number): ReadableTyped<KeyValueTuple<string, V>>;
|
|
31
37
|
count(table: string): Promise<number>;
|
|
32
|
-
|
|
38
|
+
incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]>;
|
|
33
39
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommonStorageKeyValueDB = void 0;
|
|
4
|
+
const db_lib_1 = require("@naturalcycles/db-lib");
|
|
4
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
6
|
/**
|
|
6
7
|
* CommonKeyValueDB, backed up by a CommonStorage implementation.
|
|
@@ -13,6 +14,10 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
13
14
|
class CommonStorageKeyValueDB {
|
|
14
15
|
constructor(cfg) {
|
|
15
16
|
this.cfg = cfg;
|
|
17
|
+
this.support = {
|
|
18
|
+
...db_lib_1.commonKeyValueDBFullSupport,
|
|
19
|
+
increment: false,
|
|
20
|
+
};
|
|
16
21
|
}
|
|
17
22
|
async ping() {
|
|
18
23
|
await this.cfg.storage.ping(this.cfg.bucketName);
|
|
@@ -77,8 +82,8 @@ class CommonStorageKeyValueDB {
|
|
|
77
82
|
const { bucketName, prefix } = this.getBucketAndPrefix(table);
|
|
78
83
|
return (await this.cfg.storage.getFileNames(bucketName, { prefix })).length;
|
|
79
84
|
}
|
|
80
|
-
async
|
|
81
|
-
throw new js_lib_1.AppError('CommonStorageKeyValueDB.
|
|
85
|
+
async incrementBatch(_table, _entries) {
|
|
86
|
+
throw new js_lib_1.AppError('CommonStorageKeyValueDB.incrementBatch() is not implemented');
|
|
82
87
|
}
|
|
83
88
|
}
|
|
84
89
|
exports.CommonStorageKeyValueDB = CommonStorageKeyValueDB;
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/cloud-storage-lib",
|
|
3
3
|
"scripts": {
|
|
4
|
-
"prepare": "husky"
|
|
4
|
+
"prepare": "husky",
|
|
5
|
+
"build": "dev-lib build",
|
|
6
|
+
"test": "dev-lib test",
|
|
7
|
+
"lint": "dev-lib lint",
|
|
8
|
+
"bt": "dev-lib bt",
|
|
9
|
+
"lbt": "dev-lib lbt"
|
|
5
10
|
},
|
|
6
11
|
"dependencies": {
|
|
7
12
|
"@google-cloud/storage": "^7.0.0",
|
|
@@ -11,7 +16,7 @@
|
|
|
11
16
|
},
|
|
12
17
|
"devDependencies": {
|
|
13
18
|
"@naturalcycles/dev-lib": "^15.18.0",
|
|
14
|
-
"@types/node": "^
|
|
19
|
+
"@types/node": "^22.7.4",
|
|
15
20
|
"firebase-admin": "^12.0.0",
|
|
16
21
|
"jest": "^29.1.2"
|
|
17
22
|
},
|
|
@@ -33,9 +38,9 @@
|
|
|
33
38
|
"url": "https://github.com/NaturalCycles/cloud-storage-lib"
|
|
34
39
|
},
|
|
35
40
|
"engines": {
|
|
36
|
-
"node": ">=
|
|
41
|
+
"node": ">=20.13.0"
|
|
37
42
|
},
|
|
38
|
-
"version": "1.13.
|
|
43
|
+
"version": "1.13.3",
|
|
39
44
|
"description": "CommonStorage implementation based on Google Cloud Storage",
|
|
40
45
|
"author": "Natural Cycles Team",
|
|
41
46
|
"license": "MIT"
|
package/src/cloudStorage.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-duplicates
|
|
1
|
+
// eslint-disable-next-line import-x/no-duplicates
|
|
2
2
|
import type { File, Storage, StorageOptions } from '@google-cloud/storage'
|
|
3
|
-
// eslint-disable-next-line import/no-duplicates
|
|
3
|
+
// eslint-disable-next-line import-x/no-duplicates
|
|
4
4
|
import type * as StorageLib from '@google-cloud/storage'
|
|
5
5
|
import {
|
|
6
6
|
_assert,
|
|
@@ -17,10 +17,10 @@ import type { ReadableBinary, ReadableTyped, WritableBinary } from '@naturalcycl
|
|
|
17
17
|
import type { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage'
|
|
18
18
|
import type { GCPServiceAccount } from './model'
|
|
19
19
|
|
|
20
|
-
export {
|
|
20
|
+
export type {
|
|
21
21
|
// This is the latest version, to be imported by consumers
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
Storage,
|
|
23
|
+
StorageOptions,
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const MAX_RECURSION_DEPTH = 10
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
CommonDBCreateOptions,
|
|
3
|
+
CommonKeyValueDB,
|
|
4
|
+
commonKeyValueDBFullSupport,
|
|
5
|
+
} from '@naturalcycles/db-lib'
|
|
6
|
+
import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB'
|
|
7
|
+
import { AppError, KeyValueTuple, pMap, StringMap } from '@naturalcycles/js-lib'
|
|
3
8
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
4
9
|
import { CommonStorage } from './commonStorage'
|
|
5
10
|
|
|
@@ -19,6 +24,11 @@ export interface CommonStorageKeyValueDBCfg {
|
|
|
19
24
|
export class CommonStorageKeyValueDB implements CommonKeyValueDB {
|
|
20
25
|
constructor(public cfg: CommonStorageKeyValueDBCfg) {}
|
|
21
26
|
|
|
27
|
+
support = {
|
|
28
|
+
...commonKeyValueDBFullSupport,
|
|
29
|
+
increment: false,
|
|
30
|
+
}
|
|
31
|
+
|
|
22
32
|
async ping(): Promise<void> {
|
|
23
33
|
await this.cfg.storage.ping(this.cfg.bucketName)
|
|
24
34
|
}
|
|
@@ -54,7 +64,7 @@ export class CommonStorageKeyValueDB implements CommonKeyValueDB {
|
|
|
54
64
|
})
|
|
55
65
|
}
|
|
56
66
|
|
|
57
|
-
async getByIds(table: string, ids: string[]): Promise<
|
|
67
|
+
async getByIds<V>(table: string, ids: string[]): Promise<KeyValueTuple<string, V>[]> {
|
|
58
68
|
const { bucketName, prefix } = this.getBucketAndPrefix(table)
|
|
59
69
|
|
|
60
70
|
const map: StringMap<Buffer> = {}
|
|
@@ -64,14 +74,14 @@ export class CommonStorageKeyValueDB implements CommonKeyValueDB {
|
|
|
64
74
|
if (buf) map[id] = buf
|
|
65
75
|
})
|
|
66
76
|
|
|
67
|
-
return ids.map(id => [id, map[id]] as
|
|
77
|
+
return ids.map(id => [id, map[id]] as KeyValueTuple<string, V>).filter(t => t[1])
|
|
68
78
|
}
|
|
69
79
|
|
|
70
|
-
async saveBatch(table: string, entries:
|
|
80
|
+
async saveBatch<V>(table: string, entries: KeyValueTuple<string, V>[]): Promise<void> {
|
|
71
81
|
const { bucketName, prefix } = this.getBucketAndPrefix(table)
|
|
72
82
|
|
|
73
83
|
await pMap(entries, async ([id, content]) => {
|
|
74
|
-
await this.cfg.storage.saveFile(bucketName, [prefix, id].join('/'), content)
|
|
84
|
+
await this.cfg.storage.saveFile(bucketName, [prefix, id].join('/'), content as Buffer)
|
|
75
85
|
})
|
|
76
86
|
}
|
|
77
87
|
|
|
@@ -81,18 +91,18 @@ export class CommonStorageKeyValueDB implements CommonKeyValueDB {
|
|
|
81
91
|
return this.cfg.storage.getFileNamesStream(bucketName, { prefix, limit, fullPaths: false })
|
|
82
92
|
}
|
|
83
93
|
|
|
84
|
-
streamValues(table: string, limit?: number): ReadableTyped<
|
|
94
|
+
streamValues<V>(table: string, limit?: number): ReadableTyped<V> {
|
|
85
95
|
const { bucketName, prefix } = this.getBucketAndPrefix(table)
|
|
86
96
|
|
|
87
|
-
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)
|
|
88
98
|
}
|
|
89
99
|
|
|
90
|
-
streamEntries(table: string, limit?: number): ReadableTyped<
|
|
100
|
+
streamEntries<V>(table: string, limit?: number): ReadableTyped<KeyValueTuple<string, V>> {
|
|
91
101
|
const { bucketName, prefix } = this.getBucketAndPrefix(table)
|
|
92
102
|
|
|
93
103
|
return this.cfg.storage
|
|
94
104
|
.getFilesStream(bucketName, { prefix, limit, fullPaths: false })
|
|
95
|
-
.map(f => [f.filePath, f.content
|
|
105
|
+
.map(f => [f.filePath, f.content as V])
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
async count(table: string): Promise<number> {
|
|
@@ -101,7 +111,7 @@ export class CommonStorageKeyValueDB implements CommonKeyValueDB {
|
|
|
101
111
|
return (await this.cfg.storage.getFileNames(bucketName, { prefix })).length
|
|
102
112
|
}
|
|
103
113
|
|
|
104
|
-
async
|
|
105
|
-
throw new AppError('CommonStorageKeyValueDB.
|
|
114
|
+
async incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]> {
|
|
115
|
+
throw new AppError('CommonStorageKeyValueDB.incrementBatch() is not implemented')
|
|
106
116
|
}
|
|
107
117
|
}
|