@naturalcycles/cloud-storage-lib 1.5.0 → 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.
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { Readable, Writable } from 'stream';
2
+ /// <reference types="node" />
3
+ import { Readable, Writable } from 'node:stream';
3
4
  import { Storage, StorageOptions } from '@google-cloud/storage';
4
5
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
5
6
  import { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage';
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { Readable, Writable } from 'stream';
2
+ /// <reference types="node" />
3
+ import { Readable, Writable } from 'node:stream';
3
4
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
4
5
  export interface FileEntry {
5
6
  filePath: string;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { Readable, Writable } from 'stream';
2
+ /// <reference types="node" />
3
+ import { Readable, Writable } from 'node:stream';
3
4
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
4
5
  import { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage';
5
6
  export interface CommonStorageBucketCfg {
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { Readable, Writable } from 'stream';
2
+ /// <reference types="node" />
3
+ import { Readable, Writable } from 'node:stream';
3
4
  import { StringMap } from '@naturalcycles/js-lib';
4
5
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
5
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 stream_1 = require("stream");
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 stream_1.Readable.from(Object.keys(this.data));
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
- var _a;
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 stream_1.Readable.from(Object.keys(this.data[bucketName] || {})
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 stream_1.Readable.from(Object.entries(this.data[bucketName] || {})
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 stream_1.Readable.from(this.data[bucketName][filePath]);
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
- var _a;
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
- (_a = this.data)[fromBucket] || (_a[fromBucket] = {});
81
- (_b = this.data)[tob] || (_b[tob] = {});
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
- (_a = this.data)[fromBucket] || (_a[fromBucket] = {});
88
- (_b = this.data)[tob] || (_b[tob] = {});
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
@@ -4,16 +4,16 @@
4
4
  "prepare": "husky install"
5
5
  },
6
6
  "dependencies": {
7
- "@google-cloud/storage": "^5.14.0",
7
+ "@google-cloud/storage": "^6.0.0",
8
8
  "@naturalcycles/db-lib": "^8.25.0",
9
9
  "@naturalcycles/js-lib": "^14.41.0",
10
10
  "@naturalcycles/nodejs-lib": "^12.31.0"
11
11
  },
12
12
  "devDependencies": {
13
- "@naturalcycles/dev-lib": "^12.1.3",
14
- "@types/node": "^17.0.8",
15
- "firebase-admin": "^10.0.1",
16
- "jest": "^27.1.0"
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": ">=14.16.0"
36
+ "node": ">=16.10.0"
37
37
  },
38
- "version": "1.5.0",
38
+ "version": "1.5.2",
39
39
  "description": "",
40
40
  "author": "Natural Cycles Team",
41
41
  "license": "MIT"
@@ -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'
@@ -1,4 +1,4 @@
1
- import { Readable, Writable } from 'stream'
1
+ import { Readable, Writable } from 'node:stream'
2
2
  import { ReadableTyped } from '@naturalcycles/nodejs-lib'
3
3
 
4
4
  export interface FileEntry {
@@ -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'