@naturalcycles/cloud-storage-lib 1.5.1 → 1.5.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.
@@ -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';
@@ -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;
@@ -40,18 +40,18 @@ export interface CommonStorage {
40
40
  *
41
41
  * Pass `bucketName` in case you only have permissions to operate on that bucket.
42
42
  */
43
- ping(bucketName?: string): Promise<void>;
43
+ ping: (bucketName?: string) => Promise<void>;
44
44
  /**
45
45
  * Creates a new bucket by given name.
46
46
  * todo: check what to do if it already exists
47
47
  */
48
- fileExists(bucketName: string, filePath: string): Promise<boolean>;
49
- getFile(bucketName: string, filePath: string): Promise<Buffer | null>;
50
- saveFile(bucketName: string, filePath: string, content: Buffer): Promise<void>;
48
+ fileExists: (bucketName: string, filePath: string) => Promise<boolean>;
49
+ getFile: (bucketName: string, filePath: string) => Promise<Buffer | null>;
50
+ saveFile: (bucketName: string, filePath: string, content: Buffer) => Promise<void>;
51
51
  /**
52
52
  * Should recursively delete all files in a folder, if path is a folder.
53
53
  */
54
- deletePath(bucketName: string, prefix: string): Promise<void>;
54
+ deletePath: (bucketName: string, prefix: string) => Promise<void>;
55
55
  /**
56
56
  * Returns an array of strings which are file paths.
57
57
  * Files that are not found by the path are not present in the map.
@@ -63,13 +63,13 @@ export interface CommonStorage {
63
63
  * Important difference between `prefix` and `path` is that `prefix` will
64
64
  * return all files from sub-directories too!
65
65
  */
66
- getFileNames(bucketName: string, opt?: CommonStorageGetOptions): Promise<string[]>;
67
- getFileNamesStream(bucketName: string, opt?: CommonStorageGetOptions): ReadableTyped<string>;
68
- getFilesStream(bucketName: string, opt?: CommonStorageGetOptions): ReadableTyped<FileEntry>;
69
- getFileReadStream(bucketName: string, filePath: string): Readable;
70
- getFileWriteStream(bucketName: string, filePath: string): Writable;
71
- setFileVisibility(bucketName: string, filePath: string, isPublic: boolean): Promise<void>;
72
- getFileVisibility(bucketName: string, filePath: string): Promise<boolean>;
73
- copyFile(fromBucket: string, fromPath: string, toPath: string, toBucket?: string): Promise<void>;
74
- moveFile(fromBucket: string, fromPath: string, toPath: string, toBucket?: string): Promise<void>;
66
+ getFileNames: (bucketName: string, opt?: CommonStorageGetOptions) => Promise<string[]>;
67
+ getFileNamesStream: (bucketName: string, opt?: CommonStorageGetOptions) => ReadableTyped<string>;
68
+ getFilesStream: (bucketName: string, opt?: CommonStorageGetOptions) => ReadableTyped<FileEntry>;
69
+ getFileReadStream: (bucketName: string, filePath: string) => Readable;
70
+ getFileWriteStream: (bucketName: string, filePath: string) => Writable;
71
+ setFileVisibility: (bucketName: string, filePath: string, isPublic: boolean) => Promise<void>;
72
+ getFileVisibility: (bucketName: string, filePath: string) => Promise<boolean>;
73
+ copyFile: (fromBucket: string, fromPath: string, toPath: string, toBucket?: string) => Promise<void>;
74
+ moveFile: (fromBucket: string, fromPath: string, toPath: string, toBucket?: string) => Promise<void>;
75
75
  }
@@ -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 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
@@ -10,10 +10,10 @@
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": "^28.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": ">=18.12.0"
37
37
  },
38
- "version": "1.5.1",
38
+ "version": "1.5.3",
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 {
@@ -45,7 +45,7 @@ export interface CommonStorage {
45
45
  *
46
46
  * Pass `bucketName` in case you only have permissions to operate on that bucket.
47
47
  */
48
- ping(bucketName?: string): Promise<void>
48
+ ping: (bucketName?: string) => Promise<void>
49
49
 
50
50
  /**
51
51
  * Creates a new bucket by given name.
@@ -53,16 +53,16 @@ export interface CommonStorage {
53
53
  */
54
54
  // createBucket(bucketName: string): Promise<void>
55
55
 
56
- fileExists(bucketName: string, filePath: string): Promise<boolean>
56
+ fileExists: (bucketName: string, filePath: string) => Promise<boolean>
57
57
 
58
- getFile(bucketName: string, filePath: string): Promise<Buffer | null>
58
+ getFile: (bucketName: string, filePath: string) => Promise<Buffer | null>
59
59
 
60
- saveFile(bucketName: string, filePath: string, content: Buffer): Promise<void>
60
+ saveFile: (bucketName: string, filePath: string, content: Buffer) => Promise<void>
61
61
 
62
62
  /**
63
63
  * Should recursively delete all files in a folder, if path is a folder.
64
64
  */
65
- deletePath(bucketName: string, prefix: string): Promise<void>
65
+ deletePath: (bucketName: string, prefix: string) => Promise<void>
66
66
 
67
67
  /**
68
68
  * Returns an array of strings which are file paths.
@@ -75,20 +75,30 @@ export interface CommonStorage {
75
75
  * Important difference between `prefix` and `path` is that `prefix` will
76
76
  * return all files from sub-directories too!
77
77
  */
78
- getFileNames(bucketName: string, opt?: CommonStorageGetOptions): Promise<string[]>
78
+ getFileNames: (bucketName: string, opt?: CommonStorageGetOptions) => Promise<string[]>
79
79
 
80
- getFileNamesStream(bucketName: string, opt?: CommonStorageGetOptions): ReadableTyped<string>
80
+ getFileNamesStream: (bucketName: string, opt?: CommonStorageGetOptions) => ReadableTyped<string>
81
81
 
82
- getFilesStream(bucketName: string, opt?: CommonStorageGetOptions): ReadableTyped<FileEntry>
82
+ getFilesStream: (bucketName: string, opt?: CommonStorageGetOptions) => ReadableTyped<FileEntry>
83
83
 
84
- getFileReadStream(bucketName: string, filePath: string): Readable
84
+ getFileReadStream: (bucketName: string, filePath: string) => Readable
85
85
 
86
- getFileWriteStream(bucketName: string, filePath: string): Writable
86
+ getFileWriteStream: (bucketName: string, filePath: string) => Writable
87
87
 
88
- setFileVisibility(bucketName: string, filePath: string, isPublic: boolean): Promise<void>
88
+ setFileVisibility: (bucketName: string, filePath: string, isPublic: boolean) => Promise<void>
89
89
 
90
- getFileVisibility(bucketName: string, filePath: string): Promise<boolean>
90
+ getFileVisibility: (bucketName: string, filePath: string) => Promise<boolean>
91
91
 
92
- copyFile(fromBucket: string, fromPath: string, toPath: string, toBucket?: string): Promise<void>
93
- moveFile(fromBucket: string, fromPath: string, toPath: string, toBucket?: string): Promise<void>
92
+ copyFile: (
93
+ fromBucket: string,
94
+ fromPath: string,
95
+ toPath: string,
96
+ toBucket?: string,
97
+ ) => Promise<void>
98
+ moveFile: (
99
+ fromBucket: string,
100
+ fromPath: string,
101
+ toPath: string,
102
+ toBucket?: string,
103
+ ) => Promise<void>
94
104
  }
@@ -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'