@naturalcycles/cloud-storage-lib 2.5.0 → 2.7.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.
@@ -1,7 +1,8 @@
1
1
  import type { Storage, StorageOptions } from '@google-cloud/storage';
2
2
  import type { LocalTimeInput } from '@naturalcycles/js-lib/datetime';
3
3
  import type { CommonLogger } from '@naturalcycles/js-lib/log';
4
- import type { ReadableBinary, ReadableTyped, WritableBinary } from '@naturalcycles/nodejs-lib/stream';
4
+ import { Pipeline } from '@naturalcycles/nodejs-lib/stream';
5
+ import type { WritableTyped } from '@naturalcycles/nodejs-lib/stream';
5
6
  import type { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage.js';
6
7
  import type { GCPServiceAccount } from './model.js';
7
8
  export type { Storage, StorageOptions, };
@@ -47,16 +48,16 @@ export declare class CloudStorage implements CommonStorage {
47
48
  deletePaths(bucketName: string, prefixes: string[]): Promise<void>;
48
49
  fileExists(bucketName: string, filePath: string): Promise<boolean>;
49
50
  getFileNames(bucketName: string, opt?: CommonStorageGetOptions): Promise<string[]>;
50
- getFileNamesStream(bucketName: string, opt?: CommonStorageGetOptions): ReadableTyped<string>;
51
- getFilesStream(bucketName: string, opt?: CommonStorageGetOptions): ReadableTyped<FileEntry>;
51
+ getFileNamesStream(bucketName: string, opt?: CommonStorageGetOptions): Pipeline<string>;
52
+ getFilesStream(bucketName: string, opt?: CommonStorageGetOptions): Pipeline<FileEntry>;
52
53
  getFile(bucketName: string, filePath: string): Promise<Buffer | null>;
53
54
  /**
54
55
  * Returns a Readable that is NOT object mode,
55
56
  * so you can e.g pipe it to fs.createWriteStream()
56
57
  */
57
- getFileReadStream(bucketName: string, filePath: string): ReadableBinary;
58
+ getFileReadStream(bucketName: string, filePath: string): Pipeline<Uint8Array>;
58
59
  saveFile(bucketName: string, filePath: string, content: Buffer): Promise<void>;
59
- getFileWriteStream(bucketName: string, filePath: string): WritableBinary;
60
+ getFileWriteStream(bucketName: string, filePath: string): WritableTyped<Uint8Array>;
60
61
  uploadFile(localFilePath: string, bucketName: string, bucketFilePath: string): Promise<void>;
61
62
  setFileVisibility(bucketName: string, filePath: string, isPublic: boolean): Promise<void>;
62
63
  getFileVisibility(bucketName: string, filePath: string): Promise<boolean>;
@@ -4,6 +4,7 @@ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
4
4
  import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
5
5
  import { _substringAfterLast } from '@naturalcycles/js-lib/string';
6
6
  import { SKIP } from '@naturalcycles/js-lib/types';
7
+ import { Pipeline } from '@naturalcycles/nodejs-lib/stream';
7
8
  const MAX_RECURSION_DEPTH = 10;
8
9
  const BATCH_SIZE = 32;
9
10
  /**
@@ -80,30 +81,23 @@ export class CloudStorage {
80
81
  }
81
82
  getFileNamesStream(bucketName, opt = {}) {
82
83
  const { prefix, fullPaths = true } = opt;
83
- return this.storage.bucket(bucketName).getFilesStream({
84
+ return Pipeline.from(this.storage.bucket(bucketName).getFilesStream({
84
85
  prefix,
85
86
  maxResults: opt.limit || undefined,
86
- }).flatMap(f => {
87
- const r = this.normalizeFilename(f.name, fullPaths);
88
- if (r === SKIP)
89
- return [];
90
- return [r];
91
- });
87
+ })).mapSync(f => this.normalizeFilename(f.name, fullPaths));
92
88
  }
93
89
  getFilesStream(bucketName, opt = {}) {
94
90
  const { prefix, fullPaths = true } = opt;
95
- return this.storage.bucket(bucketName).getFilesStream({
91
+ return Pipeline.from(this.storage.bucket(bucketName).getFilesStream({
96
92
  prefix,
97
93
  maxResults: opt.limit || undefined,
98
- }).flatMap(async (f) => {
94
+ })).map(async (f) => {
99
95
  const filePath = this.normalizeFilename(f.name, fullPaths);
100
96
  if (filePath === SKIP)
101
- return [];
97
+ return SKIP;
102
98
  const [content] = await f.download();
103
- return [{ filePath, content }];
104
- }, {
105
- concurrency: 16,
106
- });
99
+ return { filePath, content };
100
+ }, { concurrency: 16 });
107
101
  }
108
102
  async getFile(bucketName, filePath) {
109
103
  const [buf] = await this.storage
@@ -122,7 +116,7 @@ export class CloudStorage {
122
116
  * so you can e.g pipe it to fs.createWriteStream()
123
117
  */
124
118
  getFileReadStream(bucketName, filePath) {
125
- return this.storage.bucket(bucketName).file(filePath).createReadStream();
119
+ return Pipeline.from(this.storage.bucket(bucketName).file(filePath).createReadStream());
126
120
  }
127
121
  async saveFile(bucketName, filePath, content) {
128
122
  await this.storage.bucket(bucketName).file(filePath).save(content);
@@ -1,5 +1,5 @@
1
1
  import type { LocalTimeInput } from '@naturalcycles/js-lib/datetime';
2
- import type { ReadableBinary, ReadableTyped, WritableBinary } from '@naturalcycles/nodejs-lib/stream';
2
+ import type { Pipeline, WritableTyped } from '@naturalcycles/nodejs-lib/stream';
3
3
  export interface FileEntry {
4
4
  filePath: string;
5
5
  content: Buffer;
@@ -69,10 +69,13 @@ export interface CommonStorage {
69
69
  * return all files from sub-directories too!
70
70
  */
71
71
  getFileNames: (bucketName: string, opt?: CommonStorageGetOptions) => Promise<string[]>;
72
- getFileNamesStream: (bucketName: string, opt?: CommonStorageGetOptions) => ReadableTyped<string>;
73
- getFilesStream: (bucketName: string, opt?: CommonStorageGetOptions) => ReadableTyped<FileEntry>;
74
- getFileReadStream: (bucketName: string, filePath: string) => ReadableBinary;
75
- getFileWriteStream: (bucketName: string, filePath: string) => WritableBinary;
72
+ getFileNamesStream: (bucketName: string, opt?: CommonStorageGetOptions) => Pipeline<string>;
73
+ getFilesStream: (bucketName: string, opt?: CommonStorageGetOptions) => Pipeline<FileEntry>;
74
+ /**
75
+ * Returns a Pipeline with binary output, objectMode=false.
76
+ */
77
+ getFileReadStream: (bucketName: string, filePath: string) => Pipeline<Uint8Array>;
78
+ getFileWriteStream: (bucketName: string, filePath: string) => WritableTyped<Uint8Array>;
76
79
  /**
77
80
  * Upload local file to the bucket (by streaming it).
78
81
  */
@@ -1,5 +1,5 @@
1
- import type { Readable, Writable } from 'node:stream';
2
- import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
1
+ import type { Writable } from 'node:stream';
2
+ import type { Pipeline } from '@naturalcycles/nodejs-lib/stream';
3
3
  import type { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage.js';
4
4
  export interface CommonStorageBucketCfg {
5
5
  storage: CommonStorage;
@@ -56,9 +56,9 @@ export declare class CommonStorageBucket {
56
56
  * return all files from sub-directories too!
57
57
  */
58
58
  getFileNames(opt?: CommonStorageGetOptions): Promise<string[]>;
59
- getFileNamesStream(opt?: CommonStorageGetOptions): ReadableTyped<string>;
60
- getFilesStream(opt?: CommonStorageGetOptions): ReadableTyped<FileEntry>;
61
- getFileReadStream(filePath: string): Readable;
59
+ getFileNamesStream(opt?: CommonStorageGetOptions): Pipeline<string>;
60
+ getFilesStream(opt?: CommonStorageGetOptions): Pipeline<FileEntry>;
61
+ getFileReadStream(filePath: string): Pipeline<Uint8Array>;
62
62
  getFileWriteStream(filePath: string): Writable;
63
63
  setFileVisibility(filePath: string, isPublic: boolean): Promise<void>;
64
64
  getFileVisibility(filePath: string): Promise<boolean>;
@@ -1,6 +1,6 @@
1
1
  import type { CommonDBCreateOptions } from '@naturalcycles/db-lib';
2
2
  import type { CommonKeyValueDB, IncrementTuple, KeyValueDBTuple } from '@naturalcycles/db-lib/kv';
3
- import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
3
+ import type { Pipeline } from '@naturalcycles/nodejs-lib/stream';
4
4
  import type { CommonStorage } from './commonStorage.js';
5
5
  export interface CommonStorageKeyValueDBCfg {
6
6
  storage: CommonStorage;
@@ -27,9 +27,9 @@ export declare class CommonStorageKeyValueDB implements CommonKeyValueDB {
27
27
  deleteByIds(table: string, ids: string[]): Promise<void>;
28
28
  getByIds(table: string, ids: string[]): Promise<KeyValueDBTuple[]>;
29
29
  saveBatch(table: string, entries: KeyValueDBTuple[]): Promise<void>;
30
- streamIds(table: string, limit?: number): ReadableTyped<string>;
31
- streamValues(table: string, limit?: number): ReadableTyped<Buffer>;
32
- streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple>;
30
+ streamIds(table: string, limit?: number): Pipeline<string>;
31
+ streamValues(table: string, limit?: number): Pipeline<Buffer>;
32
+ streamEntries(table: string, limit?: number): Pipeline<KeyValueDBTuple>;
33
33
  count(table: string): Promise<number>;
34
34
  incrementBatch(_table: string, _entries: IncrementTuple[]): Promise<IncrementTuple[]>;
35
35
  }
@@ -69,13 +69,13 @@ export class CommonStorageKeyValueDB {
69
69
  }
70
70
  streamValues(table, limit) {
71
71
  const { bucketName, prefix } = this.getBucketAndPrefix(table);
72
- return this.cfg.storage.getFilesStream(bucketName, { prefix, limit }).map(f => f.content);
72
+ return this.cfg.storage.getFilesStream(bucketName, { prefix, limit }).mapSync(f => f.content);
73
73
  }
74
74
  streamEntries(table, limit) {
75
75
  const { bucketName, prefix } = this.getBucketAndPrefix(table);
76
76
  return this.cfg.storage
77
77
  .getFilesStream(bucketName, { prefix, limit, fullPaths: false })
78
- .map(f => [f.filePath, f.content]);
78
+ .mapSync(f => [f.filePath, f.content]);
79
79
  }
80
80
  async count(table) {
81
81
  const { bucketName, prefix } = this.getBucketAndPrefix(table);
@@ -1,6 +1,7 @@
1
1
  import type { LocalTimeInput } from '@naturalcycles/js-lib/datetime';
2
2
  import type { StringMap } from '@naturalcycles/js-lib/types';
3
- import type { ReadableBinary, ReadableTyped, WritableBinary } from '@naturalcycles/nodejs-lib/stream';
3
+ import { Pipeline } from '@naturalcycles/nodejs-lib/stream';
4
+ import type { WritableTyped } from '@naturalcycles/nodejs-lib/stream';
4
5
  import type { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage.js';
5
6
  export declare class InMemoryCommonStorage implements CommonStorage {
6
7
  /**
@@ -10,7 +11,7 @@ export declare class InMemoryCommonStorage implements CommonStorage {
10
11
  publicMap: StringMap<StringMap<boolean>>;
11
12
  ping(): Promise<void>;
12
13
  getBucketNames(): Promise<string[]>;
13
- getBucketNamesStream(): ReadableTyped<string>;
14
+ getBucketNamesStream(): Pipeline<string>;
14
15
  fileExists(bucketName: string, filePath: string): Promise<boolean>;
15
16
  getFile(bucketName: string, filePath: string): Promise<Buffer | null>;
16
17
  saveFile(bucketName: string, filePath: string, content: Buffer): Promise<void>;
@@ -18,10 +19,10 @@ export declare class InMemoryCommonStorage implements CommonStorage {
18
19
  deletePaths(bucketName: string, prefixes: string[]): Promise<void>;
19
20
  deleteFiles(bucketName: string, filePaths: string[]): Promise<void>;
20
21
  getFileNames(bucketName: string, opt?: CommonStorageGetOptions): Promise<string[]>;
21
- getFileNamesStream(bucketName: string, opt?: CommonStorageGetOptions): ReadableTyped<string>;
22
- getFilesStream(bucketName: string, opt?: CommonStorageGetOptions): ReadableTyped<FileEntry>;
23
- getFileReadStream(bucketName: string, filePath: string): ReadableBinary;
24
- getFileWriteStream(_bucketName: string, _filePath: string): WritableBinary;
22
+ getFileNamesStream(bucketName: string, opt?: CommonStorageGetOptions): Pipeline<string>;
23
+ getFilesStream(bucketName: string, opt?: CommonStorageGetOptions): Pipeline<FileEntry>;
24
+ getFileReadStream(bucketName: string, filePath: string): Pipeline<Uint8Array>;
25
+ getFileWriteStream(_bucketName: string, _filePath: string): WritableTyped<Uint8Array>;
25
26
  uploadFile(localFilePath: string, bucketName: string, bucketFilePath: string): Promise<void>;
26
27
  setFileVisibility(bucketName: string, filePath: string, isPublic: boolean): Promise<void>;
27
28
  getFileVisibility(bucketName: string, filePath: string): Promise<boolean>;
@@ -6,6 +6,7 @@ import { _substringAfterLast } from '@naturalcycles/js-lib/string';
6
6
  import { _stringMapEntries } from '@naturalcycles/js-lib/types';
7
7
  import { md5 } from '@naturalcycles/nodejs-lib';
8
8
  import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
9
+ import { Pipeline } from '@naturalcycles/nodejs-lib/stream';
9
10
  export class InMemoryCommonStorage {
10
11
  /**
11
12
  * data[bucketName][filePath] = Buffer
@@ -17,7 +18,7 @@ export class InMemoryCommonStorage {
17
18
  return Object.keys(this.data);
18
19
  }
19
20
  getBucketNamesStream() {
20
- return Readable.from(Object.keys(this.data));
21
+ return Pipeline.fromArray(Object.keys(this.data));
21
22
  }
22
23
  async fileExists(bucketName, filePath) {
23
24
  return !!this.data[bucketName]?.[filePath];
@@ -52,14 +53,14 @@ export class InMemoryCommonStorage {
52
53
  }
53
54
  getFileNamesStream(bucketName, opt = {}) {
54
55
  const { prefix = '', fullPaths = true } = opt;
55
- return Readable.from(Object.keys(this.data[bucketName] || {})
56
+ return Pipeline.fromArray(Object.keys(this.data[bucketName] || {})
56
57
  .filter(filePath => filePath.startsWith(prefix))
57
58
  .slice(0, opt.limit)
58
59
  .map(n => (fullPaths ? n : _substringAfterLast(n, '/'))));
59
60
  }
60
61
  getFilesStream(bucketName, opt = {}) {
61
62
  const { prefix = '', fullPaths = true } = opt;
62
- return Readable.from(_stringMapEntries(this.data[bucketName] || {})
63
+ return Pipeline.fromArray(_stringMapEntries(this.data[bucketName] || {})
63
64
  .map(([filePath, content]) => ({
64
65
  filePath,
65
66
  content,
@@ -69,7 +70,7 @@ export class InMemoryCommonStorage {
69
70
  .map(f => (fullPaths ? f : { ...f, filePath: _substringAfterLast(f.filePath, '/') })));
70
71
  }
71
72
  getFileReadStream(bucketName, filePath) {
72
- return Readable.from(this.data[bucketName][filePath]);
73
+ return Pipeline.from(Readable.from(this.data[bucketName][filePath]));
73
74
  }
74
75
  getFileWriteStream(_bucketName, _filePath) {
75
76
  throw new Error('Method not implemented.');
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './cloudStorage.js';
2
- export * from './commonStorage.js';
2
+ export type * from './commonStorage.js';
3
3
  export * from './commonStorageBucket.js';
4
4
  export * from './commonStorageKeyValueDB.js';
5
5
  export * from './inMemoryCommonStorage.js';
6
- export * from './model.js';
6
+ export type * from './model.js';
package/dist/index.js CHANGED
@@ -1,6 +1,4 @@
1
1
  export * from './cloudStorage.js';
2
- export * from './commonStorage.js';
3
2
  export * from './commonStorageBucket.js';
4
3
  export * from './commonStorageKeyValueDB.js';
5
4
  export * from './inMemoryCommonStorage.js';
6
- export * from './model.js';
package/package.json CHANGED
@@ -9,9 +9,10 @@
9
9
  "tslib": "^2"
10
10
  },
11
11
  "devDependencies": {
12
- "@types/node": "^24",
12
+ "@types/node": "^25",
13
+ "@typescript/native-preview": "7.0.0-dev.20260401.1",
13
14
  "firebase-admin": "^13",
14
- "@naturalcycles/dev-lib": "18.4.2"
15
+ "@naturalcycles/dev-lib": "20.42.0"
15
16
  },
16
17
  "exports": {
17
18
  ".": "./dist/index.js"
@@ -35,9 +36,9 @@
35
36
  "directory": "packages/cloud-storage-lib"
36
37
  },
37
38
  "engines": {
38
- "node": ">=22.12.0"
39
+ "node": ">=24.10.0"
39
40
  },
40
- "version": "2.5.0",
41
+ "version": "2.7.0",
41
42
  "description": "CommonStorage implementation based on Google Cloud Storage",
42
43
  "author": "Natural Cycles Team",
43
44
  "license": "MIT",
@@ -8,11 +8,8 @@ import { pMap } from '@naturalcycles/js-lib/promise/pMap.js'
8
8
  import { _substringAfterLast } from '@naturalcycles/js-lib/string'
9
9
  import type { UnixTimestampMillis } from '@naturalcycles/js-lib/types'
10
10
  import { SKIP } from '@naturalcycles/js-lib/types'
11
- import type {
12
- ReadableBinary,
13
- ReadableTyped,
14
- WritableBinary,
15
- } from '@naturalcycles/nodejs-lib/stream'
11
+ import { Pipeline } from '@naturalcycles/nodejs-lib/stream'
12
+ import type { WritableTyped } from '@naturalcycles/nodejs-lib/stream'
16
13
  import type { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage.js'
17
14
  import type { GCPServiceAccount } from './model.js'
18
15
 
@@ -40,6 +37,7 @@ export interface CloudStorageCfg {
40
37
  */
41
38
  logger?: CommonLogger
42
39
 
40
+ // todo: refactor to logLevel
43
41
  /**
44
42
  * Pass true for extra debugging
45
43
  */
@@ -142,40 +140,34 @@ export class CloudStorage implements CommonStorage {
142
140
  return files.map(f => _substringAfterLast(f.name, '/')).filter(Boolean)
143
141
  }
144
142
 
145
- getFileNamesStream(bucketName: string, opt: CommonStorageGetOptions = {}): ReadableTyped<string> {
143
+ getFileNamesStream(bucketName: string, opt: CommonStorageGetOptions = {}): Pipeline<string> {
146
144
  const { prefix, fullPaths = true } = opt
147
145
 
148
- return (
146
+ return Pipeline.from<File>(
149
147
  this.storage.bucket(bucketName).getFilesStream({
150
148
  prefix,
151
149
  maxResults: opt.limit || undefined,
152
- }) as ReadableTyped<File>
153
- ).flatMap(f => {
154
- const r = this.normalizeFilename(f.name, fullPaths)
155
- if (r === SKIP) return []
156
- return [r]
157
- })
150
+ }),
151
+ ).mapSync(f => this.normalizeFilename(f.name, fullPaths))
158
152
  }
159
153
 
160
- getFilesStream(bucketName: string, opt: CommonStorageGetOptions = {}): ReadableTyped<FileEntry> {
154
+ getFilesStream(bucketName: string, opt: CommonStorageGetOptions = {}): Pipeline<FileEntry> {
161
155
  const { prefix, fullPaths = true } = opt
162
156
 
163
- return (
157
+ return Pipeline.from<File>(
164
158
  this.storage.bucket(bucketName).getFilesStream({
165
159
  prefix,
166
160
  maxResults: opt.limit || undefined,
167
- }) as ReadableTyped<File>
168
- ).flatMap(
161
+ }),
162
+ ).map(
169
163
  async f => {
170
164
  const filePath = this.normalizeFilename(f.name, fullPaths)
171
- if (filePath === SKIP) return []
165
+ if (filePath === SKIP) return SKIP
172
166
 
173
167
  const [content] = await f.download()
174
- return [{ filePath, content }] as FileEntry[]
175
- },
176
- {
177
- concurrency: 16,
168
+ return { filePath, content } satisfies FileEntry
178
169
  },
170
+ { concurrency: 16 },
179
171
  )
180
172
  }
181
173
 
@@ -196,15 +188,15 @@ export class CloudStorage implements CommonStorage {
196
188
  * Returns a Readable that is NOT object mode,
197
189
  * so you can e.g pipe it to fs.createWriteStream()
198
190
  */
199
- getFileReadStream(bucketName: string, filePath: string): ReadableBinary {
200
- return this.storage.bucket(bucketName).file(filePath).createReadStream()
191
+ getFileReadStream(bucketName: string, filePath: string): Pipeline<Uint8Array> {
192
+ return Pipeline.from(this.storage.bucket(bucketName).file(filePath).createReadStream())
201
193
  }
202
194
 
203
195
  async saveFile(bucketName: string, filePath: string, content: Buffer): Promise<void> {
204
196
  await this.storage.bucket(bucketName).file(filePath).save(content)
205
197
  }
206
198
 
207
- getFileWriteStream(bucketName: string, filePath: string): WritableBinary {
199
+ getFileWriteStream(bucketName: string, filePath: string): WritableTyped<Uint8Array> {
208
200
  return this.storage.bucket(bucketName).file(filePath).createWriteStream()
209
201
  }
210
202
 
@@ -1,9 +1,5 @@
1
1
  import type { LocalTimeInput } from '@naturalcycles/js-lib/datetime'
2
- import type {
3
- ReadableBinary,
4
- ReadableTyped,
5
- WritableBinary,
6
- } from '@naturalcycles/nodejs-lib/stream'
2
+ import type { Pipeline, WritableTyped } from '@naturalcycles/nodejs-lib/stream'
7
3
 
8
4
  export interface FileEntry {
9
5
  filePath: string
@@ -90,13 +86,16 @@ export interface CommonStorage {
90
86
  */
91
87
  getFileNames: (bucketName: string, opt?: CommonStorageGetOptions) => Promise<string[]>
92
88
 
93
- getFileNamesStream: (bucketName: string, opt?: CommonStorageGetOptions) => ReadableTyped<string>
89
+ getFileNamesStream: (bucketName: string, opt?: CommonStorageGetOptions) => Pipeline<string>
94
90
 
95
- getFilesStream: (bucketName: string, opt?: CommonStorageGetOptions) => ReadableTyped<FileEntry>
91
+ getFilesStream: (bucketName: string, opt?: CommonStorageGetOptions) => Pipeline<FileEntry>
96
92
 
97
- getFileReadStream: (bucketName: string, filePath: string) => ReadableBinary
93
+ /**
94
+ * Returns a Pipeline with binary output, objectMode=false.
95
+ */
96
+ getFileReadStream: (bucketName: string, filePath: string) => Pipeline<Uint8Array>
98
97
 
99
- getFileWriteStream: (bucketName: string, filePath: string) => WritableBinary
98
+ getFileWriteStream: (bucketName: string, filePath: string) => WritableTyped<Uint8Array>
100
99
 
101
100
  /**
102
101
  * Upload local file to the bucket (by streaming it).
@@ -1,7 +1,7 @@
1
- import type { Readable, Writable } from 'node:stream'
1
+ import type { Writable } from 'node:stream'
2
2
  import { AppError } from '@naturalcycles/js-lib/error/error.util.js'
3
3
  import { pMap } from '@naturalcycles/js-lib/promise/pMap.js'
4
- import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
4
+ import type { Pipeline } from '@naturalcycles/nodejs-lib/stream'
5
5
  import type { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage.js'
6
6
 
7
7
  export interface CommonStorageBucketCfg {
@@ -160,15 +160,15 @@ export class CommonStorageBucket {
160
160
  return await this.cfg.storage.getFileNames(this.cfg.bucketName, opt)
161
161
  }
162
162
 
163
- getFileNamesStream(opt?: CommonStorageGetOptions): ReadableTyped<string> {
163
+ getFileNamesStream(opt?: CommonStorageGetOptions): Pipeline<string> {
164
164
  return this.cfg.storage.getFileNamesStream(this.cfg.bucketName, opt)
165
165
  }
166
166
 
167
- getFilesStream(opt?: CommonStorageGetOptions): ReadableTyped<FileEntry> {
167
+ getFilesStream(opt?: CommonStorageGetOptions): Pipeline<FileEntry> {
168
168
  return this.cfg.storage.getFilesStream(this.cfg.bucketName, opt)
169
169
  }
170
170
 
171
- getFileReadStream(filePath: string): Readable {
171
+ getFileReadStream(filePath: string): Pipeline<Uint8Array> {
172
172
  return this.cfg.storage.getFileReadStream(this.cfg.bucketName, filePath)
173
173
  }
174
174
 
@@ -4,7 +4,7 @@ import { commonKeyValueDBFullSupport } from '@naturalcycles/db-lib/kv'
4
4
  import { AppError } from '@naturalcycles/js-lib/error/error.util.js'
5
5
  import { pMap } from '@naturalcycles/js-lib/promise/pMap.js'
6
6
  import type { StringMap } from '@naturalcycles/js-lib/types'
7
- import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
7
+ import type { Pipeline } from '@naturalcycles/nodejs-lib/stream'
8
8
  import type { CommonStorage } from './commonStorage.js'
9
9
 
10
10
  export interface CommonStorageKeyValueDBCfg {
@@ -84,24 +84,24 @@ export class CommonStorageKeyValueDB implements CommonKeyValueDB {
84
84
  })
85
85
  }
86
86
 
87
- streamIds(table: string, limit?: number): ReadableTyped<string> {
87
+ streamIds(table: string, limit?: number): Pipeline<string> {
88
88
  const { bucketName, prefix } = this.getBucketAndPrefix(table)
89
89
 
90
90
  return this.cfg.storage.getFileNamesStream(bucketName, { prefix, limit, fullPaths: false })
91
91
  }
92
92
 
93
- streamValues(table: string, limit?: number): ReadableTyped<Buffer> {
93
+ streamValues(table: string, limit?: number): Pipeline<Buffer> {
94
94
  const { bucketName, prefix } = this.getBucketAndPrefix(table)
95
95
 
96
- return this.cfg.storage.getFilesStream(bucketName, { prefix, limit }).map(f => f.content)
96
+ return this.cfg.storage.getFilesStream(bucketName, { prefix, limit }).mapSync(f => f.content)
97
97
  }
98
98
 
99
- streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple> {
99
+ streamEntries(table: string, limit?: number): Pipeline<KeyValueDBTuple> {
100
100
  const { bucketName, prefix } = this.getBucketAndPrefix(table)
101
101
 
102
102
  return this.cfg.storage
103
103
  .getFilesStream(bucketName, { prefix, limit, fullPaths: false })
104
- .map(f => [f.filePath, f.content])
104
+ .mapSync(f => [f.filePath, f.content])
105
105
  }
106
106
 
107
107
  async count(table: string): Promise<number> {
@@ -8,11 +8,8 @@ import type { StringMap } from '@naturalcycles/js-lib/types'
8
8
  import { _stringMapEntries } from '@naturalcycles/js-lib/types'
9
9
  import { md5 } from '@naturalcycles/nodejs-lib'
10
10
  import { fs2 } from '@naturalcycles/nodejs-lib/fs2'
11
- import type {
12
- ReadableBinary,
13
- ReadableTyped,
14
- WritableBinary,
15
- } from '@naturalcycles/nodejs-lib/stream'
11
+ import { Pipeline } from '@naturalcycles/nodejs-lib/stream'
12
+ import type { WritableTyped } from '@naturalcycles/nodejs-lib/stream'
16
13
  import type { CommonStorage, CommonStorageGetOptions, FileEntry } from './commonStorage.js'
17
14
 
18
15
  export class InMemoryCommonStorage implements CommonStorage {
@@ -29,8 +26,8 @@ export class InMemoryCommonStorage implements CommonStorage {
29
26
  return Object.keys(this.data)
30
27
  }
31
28
 
32
- getBucketNamesStream(): ReadableTyped<string> {
33
- return Readable.from(Object.keys(this.data))
29
+ getBucketNamesStream(): Pipeline<string> {
30
+ return Pipeline.fromArray(Object.keys(this.data))
34
31
  }
35
32
 
36
33
  async fileExists(bucketName: string, filePath: string): Promise<boolean> {
@@ -70,10 +67,10 @@ export class InMemoryCommonStorage implements CommonStorage {
70
67
  .map(f => (fullPaths ? f : _substringAfterLast(f, '/')))
71
68
  }
72
69
 
73
- getFileNamesStream(bucketName: string, opt: CommonStorageGetOptions = {}): ReadableTyped<string> {
70
+ getFileNamesStream(bucketName: string, opt: CommonStorageGetOptions = {}): Pipeline<string> {
74
71
  const { prefix = '', fullPaths = true } = opt
75
72
 
76
- return Readable.from(
73
+ return Pipeline.fromArray(
77
74
  Object.keys(this.data[bucketName] || {})
78
75
  .filter(filePath => filePath.startsWith(prefix))
79
76
  .slice(0, opt.limit)
@@ -81,10 +78,10 @@ export class InMemoryCommonStorage implements CommonStorage {
81
78
  )
82
79
  }
83
80
 
84
- getFilesStream(bucketName: string, opt: CommonStorageGetOptions = {}): ReadableTyped<FileEntry> {
81
+ getFilesStream(bucketName: string, opt: CommonStorageGetOptions = {}): Pipeline<FileEntry> {
85
82
  const { prefix = '', fullPaths = true } = opt
86
83
 
87
- return Readable.from(
84
+ return Pipeline.fromArray(
88
85
  _stringMapEntries(this.data[bucketName] || {})
89
86
  .map(([filePath, content]) => ({
90
87
  filePath,
@@ -96,11 +93,11 @@ export class InMemoryCommonStorage implements CommonStorage {
96
93
  )
97
94
  }
98
95
 
99
- getFileReadStream(bucketName: string, filePath: string): ReadableBinary {
100
- return Readable.from(this.data[bucketName]![filePath]!)
96
+ getFileReadStream(bucketName: string, filePath: string): Pipeline<Uint8Array> {
97
+ return Pipeline.from(Readable.from(this.data[bucketName]![filePath]!))
101
98
  }
102
99
 
103
- getFileWriteStream(_bucketName: string, _filePath: string): WritableBinary {
100
+ getFileWriteStream(_bucketName: string, _filePath: string): WritableTyped<Uint8Array> {
104
101
  throw new Error('Method not implemented.')
105
102
  }
106
103
 
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './cloudStorage.js'
2
- export * from './commonStorage.js'
2
+ export type * from './commonStorage.js'
3
3
  export * from './commonStorageBucket.js'
4
4
  export * from './commonStorageKeyValueDB.js'
5
5
  export * from './inMemoryCommonStorage.js'
6
- export * from './model.js'
6
+ export type * from './model.js'