@naturalcycles/cloud-storage-lib 1.5.1 → 1.5.2
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 +1 -1
- package/dist/commonStorage.d.ts +1 -1
- package/dist/commonStorageBucket.d.ts +1 -1
- package/dist/inMemoryCommonStorage.d.ts +1 -1
- package/dist/inMemoryCommonStorage.js +11 -15
- package/package.json +6 -6
- package/src/cloudStorage.ts +1 -1
- package/src/commonStorage.ts +1 -1
- package/src/commonStorageBucket.ts +1 -1
- package/src/inMemoryCommonStorage.ts +1 -1
package/dist/cloudStorage.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { Readable, Writable } from 'stream';
|
|
3
|
+
import { Readable, Writable } from 'node:stream';
|
|
4
4
|
import { Storage, StorageOptions } from '@google-cloud/storage';
|
|
5
5
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
6
6
|
import { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage';
|
package/dist/commonStorage.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { Readable, Writable } from 'stream';
|
|
3
|
+
import { Readable, Writable } from 'node:stream';
|
|
4
4
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
5
5
|
export interface FileEntry {
|
|
6
6
|
filePath: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { Readable, Writable } from 'stream';
|
|
3
|
+
import { Readable, Writable } from 'node:stream';
|
|
4
4
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
5
5
|
import { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage';
|
|
6
6
|
export interface CommonStorageBucketCfg {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { Readable, Writable } from 'stream';
|
|
3
|
+
import { Readable, Writable } from 'node:stream';
|
|
4
4
|
import { StringMap } from '@naturalcycles/js-lib';
|
|
5
5
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
6
6
|
import { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryCommonStorage = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
class InMemoryCommonStorage {
|
|
7
7
|
constructor() {
|
|
@@ -16,7 +16,7 @@ class InMemoryCommonStorage {
|
|
|
16
16
|
return Object.keys(this.data);
|
|
17
17
|
}
|
|
18
18
|
getBucketNamesStream() {
|
|
19
|
-
return
|
|
19
|
+
return node_stream_1.Readable.from(Object.keys(this.data));
|
|
20
20
|
}
|
|
21
21
|
async fileExists(bucketName, filePath) {
|
|
22
22
|
return !!this.data[bucketName]?.[filePath];
|
|
@@ -25,8 +25,7 @@ class InMemoryCommonStorage {
|
|
|
25
25
|
return this.data[bucketName]?.[filePath] || null;
|
|
26
26
|
}
|
|
27
27
|
async saveFile(bucketName, filePath, content) {
|
|
28
|
-
|
|
29
|
-
(_a = this.data)[bucketName] || (_a[bucketName] = {});
|
|
28
|
+
this.data[bucketName] ||= {};
|
|
30
29
|
this.data[bucketName][filePath] = content;
|
|
31
30
|
}
|
|
32
31
|
async deletePath(bucketName, prefix) {
|
|
@@ -44,14 +43,14 @@ class InMemoryCommonStorage {
|
|
|
44
43
|
}
|
|
45
44
|
getFileNamesStream(bucketName, opt = {}) {
|
|
46
45
|
const { prefix = '', fullPaths = true } = opt;
|
|
47
|
-
return
|
|
46
|
+
return node_stream_1.Readable.from(Object.keys(this.data[bucketName] || {})
|
|
48
47
|
.filter(filePath => filePath.startsWith(prefix))
|
|
49
48
|
.slice(0, opt.limit)
|
|
50
49
|
.map(n => (fullPaths ? n : (0, js_lib_1._substringAfterLast)(n, '/'))));
|
|
51
50
|
}
|
|
52
51
|
getFilesStream(bucketName, opt = {}) {
|
|
53
52
|
const { prefix = '', fullPaths = true } = opt;
|
|
54
|
-
return
|
|
53
|
+
return node_stream_1.Readable.from(Object.entries(this.data[bucketName] || {})
|
|
55
54
|
.map(([filePath, content]) => ({
|
|
56
55
|
filePath,
|
|
57
56
|
content,
|
|
@@ -61,31 +60,28 @@ class InMemoryCommonStorage {
|
|
|
61
60
|
.map(f => (fullPaths ? f : { ...f, filePath: (0, js_lib_1._substringAfterLast)(f.filePath, '/') })));
|
|
62
61
|
}
|
|
63
62
|
getFileReadStream(bucketName, filePath) {
|
|
64
|
-
return
|
|
63
|
+
return node_stream_1.Readable.from(this.data[bucketName][filePath]);
|
|
65
64
|
}
|
|
66
65
|
getFileWriteStream(_bucketName, _filePath) {
|
|
67
66
|
throw new Error('Method not implemented.');
|
|
68
67
|
}
|
|
69
68
|
async setFileVisibility(bucketName, filePath, isPublic) {
|
|
70
|
-
|
|
71
|
-
(_a = this.publicMap)[bucketName] || (_a[bucketName] = {});
|
|
69
|
+
this.publicMap[bucketName] ||= {};
|
|
72
70
|
this.publicMap[bucketName][filePath] = isPublic;
|
|
73
71
|
}
|
|
74
72
|
async getFileVisibility(bucketName, filePath) {
|
|
75
73
|
return !!this.publicMap[bucketName]?.[filePath];
|
|
76
74
|
}
|
|
77
75
|
async copyFile(fromBucket, fromPath, toPath, toBucket) {
|
|
78
|
-
var _a, _b;
|
|
79
76
|
const tob = toBucket || fromBucket;
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
this.data[fromBucket] ||= {};
|
|
78
|
+
this.data[tob] ||= {};
|
|
82
79
|
this.data[tob][toPath] = this.data[fromBucket][fromPath];
|
|
83
80
|
}
|
|
84
81
|
async moveFile(fromBucket, fromPath, toPath, toBucket) {
|
|
85
|
-
var _a, _b;
|
|
86
82
|
const tob = toBucket || fromBucket;
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
this.data[fromBucket] ||= {};
|
|
84
|
+
this.data[tob] ||= {};
|
|
89
85
|
this.data[tob][toPath] = this.data[fromBucket][fromPath];
|
|
90
86
|
delete this.data[fromBucket][fromPath];
|
|
91
87
|
}
|
package/package.json
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"@naturalcycles/nodejs-lib": "^12.31.0"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@naturalcycles/dev-lib": "^
|
|
14
|
-
"@types/node": "^
|
|
15
|
-
"firebase-admin": "^
|
|
16
|
-
"jest": "^
|
|
13
|
+
"@naturalcycles/dev-lib": "^13.0.1",
|
|
14
|
+
"@types/node": "^18.0.0",
|
|
15
|
+
"firebase-admin": "^11.0.0",
|
|
16
|
+
"jest": "^29.1.2"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"url": "https://github.com/NaturalCycles/cloud-storage-lib"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
36
|
-
"node": ">=
|
|
36
|
+
"node": ">=16.10.0"
|
|
37
37
|
},
|
|
38
|
-
"version": "1.5.
|
|
38
|
+
"version": "1.5.2",
|
|
39
39
|
"description": "",
|
|
40
40
|
"author": "Natural Cycles Team",
|
|
41
41
|
"license": "MIT"
|
package/src/cloudStorage.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Readable, Writable } from 'stream'
|
|
1
|
+
import { Readable, Writable } from 'node:stream'
|
|
2
2
|
import { _substringAfterLast } from '@naturalcycles/js-lib'
|
|
3
3
|
import { File, Storage, StorageOptions } from '@google-cloud/storage'
|
|
4
4
|
import { ReadableTyped, transformMap, transformMapSimple } from '@naturalcycles/nodejs-lib'
|
package/src/commonStorage.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Readable, Writable } from 'stream'
|
|
1
|
+
import { Readable, Writable } from 'node:stream'
|
|
2
2
|
import { AppError, pMap } from '@naturalcycles/js-lib'
|
|
3
3
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
4
4
|
import { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Readable, Writable } from 'stream'
|
|
1
|
+
import { Readable, Writable } from 'node:stream'
|
|
2
2
|
import { _substringAfterLast, StringMap } from '@naturalcycles/js-lib'
|
|
3
3
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
4
4
|
import { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage'
|