@naturalcycles/cloud-storage-lib 1.4.1 → 1.5.0
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Readable, Writable } from 'stream';
|
|
3
|
-
import { Storage } from '@google-cloud/storage';
|
|
3
|
+
import { Storage, StorageOptions } from '@google-cloud/storage';
|
|
4
4
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
5
5
|
import { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage';
|
|
6
6
|
import { GCPServiceAccount } from './model';
|
|
@@ -14,7 +14,10 @@ import { GCPServiceAccount } from './model';
|
|
|
14
14
|
* (either personal one or non-personal).
|
|
15
15
|
*/
|
|
16
16
|
export interface CloudStorageCfg {
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* It's optional, to allow automatic credentials in AppEngine, or GOOGLE_APPLICATION_CREDENTIALS.
|
|
19
|
+
*/
|
|
20
|
+
credentials?: GCPServiceAccount;
|
|
18
21
|
}
|
|
19
22
|
export declare class CloudStorage implements CommonStorage {
|
|
20
23
|
storage: Storage;
|
|
@@ -24,6 +27,7 @@ export declare class CloudStorage implements CommonStorage {
|
|
|
24
27
|
*/
|
|
25
28
|
constructor(storage: Storage);
|
|
26
29
|
static createFromGCPServiceAccount(cfg: CloudStorageCfg): CloudStorage;
|
|
30
|
+
static createFromStorageOptions(storageOptions?: StorageOptions): CloudStorage;
|
|
27
31
|
ping(bucketName?: string): Promise<void>;
|
|
28
32
|
deletePath(bucketName: string, prefix: string): Promise<void>;
|
|
29
33
|
fileExists(bucketName: string, filePath: string): Promise<boolean>;
|
package/dist/cloudStorage.js
CHANGED
|
@@ -20,10 +20,14 @@ class CloudStorage {
|
|
|
20
20
|
// To learn more about authentication and Google APIs, visit:
|
|
21
21
|
// https://cloud.google.com/docs/authentication/getting-started
|
|
22
22
|
// at /root/repo/node_modules/google-auth-library/build/src/auth/googleauth.js:95:31
|
|
23
|
-
projectId: cfg.credentials
|
|
23
|
+
projectId: cfg.credentials?.project_id,
|
|
24
24
|
});
|
|
25
25
|
return new CloudStorage(storage);
|
|
26
26
|
}
|
|
27
|
+
static createFromStorageOptions(storageOptions) {
|
|
28
|
+
const storage = new storage_1.Storage(storageOptions);
|
|
29
|
+
return new CloudStorage(storage);
|
|
30
|
+
}
|
|
27
31
|
async ping(bucketName) {
|
|
28
32
|
await this.storage.bucket(bucketName || 'non-existing-for-sure').exists();
|
|
29
33
|
}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@naturalcycles/dev-lib": "^12.1.3",
|
|
14
|
-
"@types/node": "^
|
|
14
|
+
"@types/node": "^17.0.8",
|
|
15
15
|
"firebase-admin": "^10.0.1",
|
|
16
16
|
"jest": "^27.1.0"
|
|
17
17
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">=14.16.0"
|
|
37
37
|
},
|
|
38
|
-
"version": "1.
|
|
38
|
+
"version": "1.5.0",
|
|
39
39
|
"description": "",
|
|
40
40
|
"author": "Natural Cycles Team",
|
|
41
41
|
"license": "MIT"
|
package/src/cloudStorage.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as Buffer from 'buffer'
|
|
2
1
|
import { Readable, Writable } from 'stream'
|
|
3
2
|
import { _substringAfterLast } from '@naturalcycles/js-lib'
|
|
4
|
-
import { File, Storage } from '@google-cloud/storage'
|
|
3
|
+
import { File, Storage, StorageOptions } from '@google-cloud/storage'
|
|
5
4
|
import { ReadableTyped, transformMap, transformMapSimple } from '@naturalcycles/nodejs-lib'
|
|
6
5
|
import { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage'
|
|
7
6
|
import { GCPServiceAccount } from './model'
|
|
@@ -16,7 +15,10 @@ import { GCPServiceAccount } from './model'
|
|
|
16
15
|
* (either personal one or non-personal).
|
|
17
16
|
*/
|
|
18
17
|
export interface CloudStorageCfg {
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* It's optional, to allow automatic credentials in AppEngine, or GOOGLE_APPLICATION_CREDENTIALS.
|
|
20
|
+
*/
|
|
21
|
+
credentials?: GCPServiceAccount
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export class CloudStorage implements CommonStorage {
|
|
@@ -34,12 +36,17 @@ export class CloudStorage implements CommonStorage {
|
|
|
34
36
|
// To learn more about authentication and Google APIs, visit:
|
|
35
37
|
// https://cloud.google.com/docs/authentication/getting-started
|
|
36
38
|
// at /root/repo/node_modules/google-auth-library/build/src/auth/googleauth.js:95:31
|
|
37
|
-
projectId: cfg.credentials
|
|
39
|
+
projectId: cfg.credentials?.project_id,
|
|
38
40
|
})
|
|
39
41
|
|
|
40
42
|
return new CloudStorage(storage)
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
static createFromStorageOptions(storageOptions?: StorageOptions): CloudStorage {
|
|
46
|
+
const storage = new Storage(storageOptions)
|
|
47
|
+
return new CloudStorage(storage)
|
|
48
|
+
}
|
|
49
|
+
|
|
43
50
|
async ping(bucketName?: string): Promise<void> {
|
|
44
51
|
await this.storage.bucket(bucketName || 'non-existing-for-sure').exists()
|
|
45
52
|
}
|