@quatrain/storage-supabase 1.2.2 → 1.2.4

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,24 +1,115 @@
1
1
  import { AbstractStorageAdapter, FileType, FileResponseLinkType, StorageParameters, DownloadFileMetaType } from '@quatrain/storage';
2
2
  import { Readable, Stream } from 'node:stream';
3
3
  import { StorageClient } from '@supabase/storage-js';
4
+ /**
5
+ * Storage adapter implementation targeting Supabase Storage.
6
+ * Interfaces with the `@supabase/storage-js` client to manage buckets,
7
+ * secure signed URLs, and file uploads.
8
+ */
4
9
  export declare class SupabaseStorageAdapter extends AbstractStorageAdapter {
5
10
  protected _client: StorageClient;
6
11
  constructor(params: StorageParameters);
12
+ /**
13
+ * Exposes the underlying Supabase `StorageClient` instance.
14
+ *
15
+ * @returns The storage client.
16
+ */
7
17
  getDriver(): StorageClient;
18
+ /**
19
+ * Retrieves file metadata. Currently acts as a passthrough for Supabase.
20
+ *
21
+ * @param file - Target file footprint.
22
+ * @returns The file metadata.
23
+ */
8
24
  getMetaData(file: FileType): Promise<FileType>;
25
+ /**
26
+ * Validates backend connectivity by listing available buckets in the Supabase project.
27
+ *
28
+ * @returns True if connected.
29
+ */
9
30
  test(): Promise<boolean>;
31
+ /**
32
+ * Helper converting a node stream to a Buffer, essential for Blob creation.
33
+ *
34
+ * @param stream - The input stream.
35
+ * @returns A promise resolving to the concatenated Buffer.
36
+ */
10
37
  streamToBuffer(stream: Stream): Promise<Buffer>;
38
+ /**
39
+ * Internal helper to convert a Buffer into a native ArrayBuffer.
40
+ *
41
+ * @param buffer - The raw Buffer.
42
+ * @returns The ArrayBuffer representation.
43
+ */
11
44
  toArrayBuffer(buffer: Buffer): ArrayBuffer;
45
+ /**
46
+ * Uploads a local file path or stream to the Supabase storage bucket.
47
+ *
48
+ * @param file - Target file schema.
49
+ * @param stream - Readable stream or string path to the file.
50
+ * @returns A promise resolving to the created file footprint.
51
+ * @throws {Error} If upload is rejected.
52
+ */
12
53
  create(file: FileType, stream: Readable | string): Promise<FileType>;
54
+ /**
55
+ * Copies a file to a new destination key natively on the Supabase backend.
56
+ *
57
+ * @param file - Original file.
58
+ * @param destFile - Target destination.
59
+ */
13
60
  copy(file: FileType, destFile: FileType): Promise<void>;
61
+ /**
62
+ * Moves/Renames an existing file natively within Supabase Storage.
63
+ *
64
+ * @param file - The source file.
65
+ * @param destFile - The target file.
66
+ * @returns A promise resolving to the newly placed destination file.
67
+ * @throws {Error} If the move operation fails.
68
+ */
14
69
  move(file: FileType, destFile: FileType): Promise<FileType>;
15
- _getUrl(file: FileType, expiresIn?: number, action?: any, extra?: any): Promise<{
70
+ /**
71
+ * Generates a secure, temporary GET link to access the object remotely.
72
+ *
73
+ * @param file - The file footprint.
74
+ * @param expiresIn - URL expiration in seconds.
75
+ * @param action - Intended action context.
76
+ * @param extra - Optional parameters (e.g. cache configurations).
77
+ * @returns A promise resolving to the signed URL payload.
78
+ * @throws {Error} If signature creation fails.
79
+ */
80
+ getUrl(file: FileType, expiresIn?: number, action?: any, extra?: any): Promise<{
16
81
  url: string;
17
82
  expiresIn: number;
18
83
  }>;
84
+ /**
85
+ * Permanently removes the file from the Supabase bucket.
86
+ *
87
+ * @param file - Target file.
88
+ * @returns True upon success.
89
+ */
19
90
  delete(file: FileType): Promise<boolean>;
91
+ /**
92
+ * Downloads the file content to a temporary location and returns a Readable stream.
93
+ *
94
+ * @param file - File to read.
95
+ * @returns The content as a stream.
96
+ */
20
97
  getReadable(file: FileType): Promise<Readable>;
98
+ /**
99
+ * Fetches and pipes the file content into the given response stream.
100
+ *
101
+ * @param file - File to stream.
102
+ * @param res - Writable stream or HTTP response object.
103
+ * @returns The piped stream instance.
104
+ */
21
105
  stream(file: FileType, res: any): Promise<any>;
106
+ /**
107
+ * Downloads the file directly, either returning the blob content or saving it locally.
108
+ *
109
+ * @param file - File footprint.
110
+ * @param meta - Options dictating save path or return format.
111
+ * @returns A promise resolving to the blob or local file path.
112
+ */
22
113
  download(file: FileType, meta: DownloadFileMetaType): Promise<string | Blob>;
23
114
  /**
24
115
  * Get signed upload url for file
@@ -19,6 +19,11 @@ const storage_js_1 = require("@supabase/storage-js");
19
19
  const node_os_1 = require("node:os");
20
20
  const node_path_1 = require("node:path");
21
21
  const node_fs_1 = __importDefault(require("node:fs"));
22
+ /**
23
+ * Storage adapter implementation targeting Supabase Storage.
24
+ * Interfaces with the `@supabase/storage-js` client to manage buckets,
25
+ * secure signed URLs, and file uploads.
26
+ */
22
27
  class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
23
28
  constructor(params) {
24
29
  super(params);
@@ -28,12 +33,28 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
28
33
  });
29
34
  storage_1.Storage.info(`[SSA] Supabase Storage Adapter initialized`);
30
35
  }
36
+ /**
37
+ * Exposes the underlying Supabase `StorageClient` instance.
38
+ *
39
+ * @returns The storage client.
40
+ */
31
41
  getDriver() {
32
42
  return this._client;
33
43
  }
44
+ /**
45
+ * Retrieves file metadata. Currently acts as a passthrough for Supabase.
46
+ *
47
+ * @param file - Target file footprint.
48
+ * @returns The file metadata.
49
+ */
34
50
  getMetaData(file) {
35
51
  return new Promise(() => file);
36
52
  }
53
+ /**
54
+ * Validates backend connectivity by listing available buckets in the Supabase project.
55
+ *
56
+ * @returns True if connected.
57
+ */
37
58
  test() {
38
59
  return __awaiter(this, void 0, void 0, function* () {
39
60
  try {
@@ -51,6 +72,12 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
51
72
  }
52
73
  });
53
74
  }
75
+ /**
76
+ * Helper converting a node stream to a Buffer, essential for Blob creation.
77
+ *
78
+ * @param stream - The input stream.
79
+ * @returns A promise resolving to the concatenated Buffer.
80
+ */
54
81
  streamToBuffer(stream) {
55
82
  return __awaiter(this, void 0, void 0, function* () {
56
83
  return new Promise((resolve, reject) => {
@@ -61,6 +88,12 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
61
88
  });
62
89
  });
63
90
  }
91
+ /**
92
+ * Internal helper to convert a Buffer into a native ArrayBuffer.
93
+ *
94
+ * @param buffer - The raw Buffer.
95
+ * @returns The ArrayBuffer representation.
96
+ */
64
97
  toArrayBuffer(buffer) {
65
98
  const arrayBuffer = new ArrayBuffer(buffer.length);
66
99
  const view = new Uint8Array(arrayBuffer);
@@ -69,6 +102,14 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
69
102
  }
70
103
  return arrayBuffer;
71
104
  }
105
+ /**
106
+ * Uploads a local file path or stream to the Supabase storage bucket.
107
+ *
108
+ * @param file - Target file schema.
109
+ * @param stream - Readable stream or string path to the file.
110
+ * @returns A promise resolving to the created file footprint.
111
+ * @throws {Error} If upload is rejected.
112
+ */
72
113
  create(file, stream) {
73
114
  return __awaiter(this, void 0, void 0, function* () {
74
115
  storage_1.Storage.info(`[SSA] Uploading ${file.ref} to ${file.bucket}`);
@@ -105,6 +146,12 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
105
146
  return file;
106
147
  });
107
148
  }
149
+ /**
150
+ * Copies a file to a new destination key natively on the Supabase backend.
151
+ *
152
+ * @param file - Original file.
153
+ * @param destFile - Target destination.
154
+ */
108
155
  copy(file, destFile) {
109
156
  return __awaiter(this, void 0, void 0, function* () {
110
157
  try {
@@ -119,6 +166,14 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
119
166
  }
120
167
  });
121
168
  }
169
+ /**
170
+ * Moves/Renames an existing file natively within Supabase Storage.
171
+ *
172
+ * @param file - The source file.
173
+ * @param destFile - The target file.
174
+ * @returns A promise resolving to the newly placed destination file.
175
+ * @throws {Error} If the move operation fails.
176
+ */
122
177
  move(file, destFile) {
123
178
  return __awaiter(this, void 0, void 0, function* () {
124
179
  storage_1.Storage.info(`Moving file ${file.ref} to ${destFile.ref} in same bucket ${file.bucket}`);
@@ -132,7 +187,17 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
132
187
  return destFile;
133
188
  });
134
189
  }
135
- _getUrl(file_1) {
190
+ /**
191
+ * Generates a secure, temporary GET link to access the object remotely.
192
+ *
193
+ * @param file - The file footprint.
194
+ * @param expiresIn - URL expiration in seconds.
195
+ * @param action - Intended action context.
196
+ * @param extra - Optional parameters (e.g. cache configurations).
197
+ * @returns A promise resolving to the signed URL payload.
198
+ * @throws {Error} If signature creation fails.
199
+ */
200
+ getUrl(file_1) {
136
201
  return __awaiter(this, arguments, void 0, function* (file, expiresIn = 3600, action = 'read', extra = {}) {
137
202
  storage_1.Storage.debug(`Getting signed url for file ${file.ref} in bucket ${file.bucket}`);
138
203
  const cacheControl = extra.cacheControl || (this._params.config.publicCacheDuration ? `${this._params.config.publicCacheDuration}` : undefined);
@@ -148,6 +213,12 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
148
213
  return { url: data === null || data === void 0 ? void 0 : data.signedUrl, expiresIn };
149
214
  });
150
215
  }
216
+ /**
217
+ * Permanently removes the file from the Supabase bucket.
218
+ *
219
+ * @param file - Target file.
220
+ * @returns True upon success.
221
+ */
151
222
  delete(file) {
152
223
  return __awaiter(this, void 0, void 0, function* () {
153
224
  storage_1.Storage.info(`Deleting file ${file.ref} in bucket ${file.bucket}`);
@@ -159,6 +230,12 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
159
230
  return true;
160
231
  });
161
232
  }
233
+ /**
234
+ * Downloads the file content to a temporary location and returns a Readable stream.
235
+ *
236
+ * @param file - File to read.
237
+ * @returns The content as a stream.
238
+ */
162
239
  getReadable(file) {
163
240
  return __awaiter(this, void 0, void 0, function* () {
164
241
  storage_1.Storage.debug(`GET Readable : ${file.ref}`);
@@ -171,6 +248,13 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
171
248
  return readable;
172
249
  });
173
250
  }
251
+ /**
252
+ * Fetches and pipes the file content into the given response stream.
253
+ *
254
+ * @param file - File to stream.
255
+ * @param res - Writable stream or HTTP response object.
256
+ * @returns The piped stream instance.
257
+ */
174
258
  stream(file, res) {
175
259
  return __awaiter(this, void 0, void 0, function* () {
176
260
  storage_1.Storage.debug(`GET Stream : ${file.ref}`);
@@ -183,6 +267,13 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
183
267
  return readable.pipe(res);
184
268
  });
185
269
  }
270
+ /**
271
+ * Downloads the file directly, either returning the blob content or saving it locally.
272
+ *
273
+ * @param file - File footprint.
274
+ * @param meta - Options dictating save path or return format.
275
+ * @returns A promise resolving to the blob or local file path.
276
+ */
186
277
  download(file, meta) {
187
278
  return __awaiter(this, void 0, void 0, function* () {
188
279
  const { data, error } = yield this._client
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/storage-supabase",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Storage adapter for Supabase Storage",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,8 +31,8 @@
31
31
  "typescript": "^5.1.5"
32
32
  },
33
33
  "dependencies": {
34
- "@quatrain/core": "^1.2.5",
35
- "@quatrain/storage": "^1.2.2",
34
+ "@quatrain/core": "^1.2.6",
35
+ "@quatrain/storage": "^1.2.5",
36
36
  "@supabase/storage-js": "^2.7.2",
37
37
  "@supabase/supabase-js": "^2.87.3"
38
38
  },
@@ -12,6 +12,11 @@ import { tmpdir } from 'node:os'
12
12
  import { join } from 'node:path'
13
13
  import fs from 'node:fs'
14
14
 
15
+ /**
16
+ * Storage adapter implementation targeting Supabase Storage.
17
+ * Interfaces with the `@supabase/storage-js` client to manage buckets,
18
+ * secure signed URLs, and file uploads.
19
+ */
15
20
  export class SupabaseStorageAdapter extends AbstractStorageAdapter {
16
21
  protected _client: StorageClient
17
22
 
@@ -25,14 +30,30 @@ export class SupabaseStorageAdapter extends AbstractStorageAdapter {
25
30
  Storage.info(`[SSA] Supabase Storage Adapter initialized`)
26
31
  }
27
32
 
33
+ /**
34
+ * Exposes the underlying Supabase `StorageClient` instance.
35
+ *
36
+ * @returns The storage client.
37
+ */
28
38
  getDriver() {
29
39
  return this._client
30
40
  }
31
41
 
42
+ /**
43
+ * Retrieves file metadata. Currently acts as a passthrough for Supabase.
44
+ *
45
+ * @param file - Target file footprint.
46
+ * @returns The file metadata.
47
+ */
32
48
  getMetaData(file: FileType): Promise<FileType> {
33
49
  return new Promise(() => file)
34
50
  }
35
51
 
52
+ /**
53
+ * Validates backend connectivity by listing available buckets in the Supabase project.
54
+ *
55
+ * @returns True if connected.
56
+ */
36
57
  async test(): Promise<boolean> {
37
58
  try {
38
59
  const { data, error } = await this._client.listBuckets()
@@ -53,6 +74,12 @@ export class SupabaseStorageAdapter extends AbstractStorageAdapter {
53
74
  }
54
75
  }
55
76
 
77
+ /**
78
+ * Helper converting a node stream to a Buffer, essential for Blob creation.
79
+ *
80
+ * @param stream - The input stream.
81
+ * @returns A promise resolving to the concatenated Buffer.
82
+ */
56
83
  async streamToBuffer(stream: Stream): Promise<Buffer> {
57
84
  return new Promise<Buffer>((resolve, reject) => {
58
85
  const _buf: any[] = []
@@ -63,6 +90,12 @@ export class SupabaseStorageAdapter extends AbstractStorageAdapter {
63
90
  })
64
91
  }
65
92
 
93
+ /**
94
+ * Internal helper to convert a Buffer into a native ArrayBuffer.
95
+ *
96
+ * @param buffer - The raw Buffer.
97
+ * @returns The ArrayBuffer representation.
98
+ */
66
99
  toArrayBuffer(buffer: Buffer): ArrayBuffer {
67
100
  const arrayBuffer = new ArrayBuffer(buffer.length)
68
101
  const view = new Uint8Array(arrayBuffer)
@@ -72,6 +105,14 @@ export class SupabaseStorageAdapter extends AbstractStorageAdapter {
72
105
  return arrayBuffer
73
106
  }
74
107
 
108
+ /**
109
+ * Uploads a local file path or stream to the Supabase storage bucket.
110
+ *
111
+ * @param file - Target file schema.
112
+ * @param stream - Readable stream or string path to the file.
113
+ * @returns A promise resolving to the created file footprint.
114
+ * @throws {Error} If upload is rejected.
115
+ */
75
116
  async create(file: FileType, stream: Readable | string): Promise<FileType> {
76
117
  Storage.info(`[SSA] Uploading ${file.ref} to ${file.bucket}`)
77
118
 
@@ -108,6 +149,12 @@ export class SupabaseStorageAdapter extends AbstractStorageAdapter {
108
149
  return file
109
150
  }
110
151
 
152
+ /**
153
+ * Copies a file to a new destination key natively on the Supabase backend.
154
+ *
155
+ * @param file - Original file.
156
+ * @param destFile - Target destination.
157
+ */
111
158
  async copy(file: FileType, destFile: FileType) {
112
159
  try {
113
160
  const response = await this._client
@@ -120,6 +167,14 @@ export class SupabaseStorageAdapter extends AbstractStorageAdapter {
120
167
  }
121
168
  }
122
169
 
170
+ /**
171
+ * Moves/Renames an existing file natively within Supabase Storage.
172
+ *
173
+ * @param file - The source file.
174
+ * @param destFile - The target file.
175
+ * @returns A promise resolving to the newly placed destination file.
176
+ * @throws {Error} If the move operation fails.
177
+ */
123
178
  async move(file: FileType, destFile: FileType) {
124
179
  Storage.info(
125
180
  `Moving file ${file.ref} to ${destFile.ref} in same bucket ${file.bucket}`
@@ -138,7 +193,17 @@ export class SupabaseStorageAdapter extends AbstractStorageAdapter {
138
193
  return destFile
139
194
  }
140
195
 
141
- async _getUrl(file: FileType, expiresIn = 3600, action: any = 'read', extra: any = {}) {
196
+ /**
197
+ * Generates a secure, temporary GET link to access the object remotely.
198
+ *
199
+ * @param file - The file footprint.
200
+ * @param expiresIn - URL expiration in seconds.
201
+ * @param action - Intended action context.
202
+ * @param extra - Optional parameters (e.g. cache configurations).
203
+ * @returns A promise resolving to the signed URL payload.
204
+ * @throws {Error} If signature creation fails.
205
+ */
206
+ async getUrl(file: FileType, expiresIn = 3600, action: any = 'read', extra: any = {}) {
142
207
  Storage.debug(
143
208
  `Getting signed url for file ${file.ref} in bucket ${file.bucket}`
144
209
  )
@@ -160,6 +225,12 @@ export class SupabaseStorageAdapter extends AbstractStorageAdapter {
160
225
  return { url: data?.signedUrl, expiresIn }
161
226
  }
162
227
 
228
+ /**
229
+ * Permanently removes the file from the Supabase bucket.
230
+ *
231
+ * @param file - Target file.
232
+ * @returns True upon success.
233
+ */
163
234
  async delete(file: FileType) {
164
235
  Storage.info(`Deleting file ${file.ref} in bucket ${file.bucket}`)
165
236
  const { error } = await this._client.from(file.bucket).remove([file.ref])
@@ -173,6 +244,12 @@ export class SupabaseStorageAdapter extends AbstractStorageAdapter {
173
244
  return true
174
245
  }
175
246
 
247
+ /**
248
+ * Downloads the file content to a temporary location and returns a Readable stream.
249
+ *
250
+ * @param file - File to read.
251
+ * @returns The content as a stream.
252
+ */
176
253
  async getReadable(file: FileType): Promise<Readable> {
177
254
  Storage.debug(`GET Readable : ${file.ref}`)
178
255
 
@@ -186,6 +263,13 @@ export class SupabaseStorageAdapter extends AbstractStorageAdapter {
186
263
  return readable
187
264
  }
188
265
 
266
+ /**
267
+ * Fetches and pipes the file content into the given response stream.
268
+ *
269
+ * @param file - File to stream.
270
+ * @param res - Writable stream or HTTP response object.
271
+ * @returns The piped stream instance.
272
+ */
189
273
  async stream(file: FileType, res: any) {
190
274
  Storage.debug(`GET Stream : ${file.ref}`)
191
275
 
@@ -199,6 +283,13 @@ export class SupabaseStorageAdapter extends AbstractStorageAdapter {
199
283
  return readable.pipe(res)
200
284
  }
201
285
 
286
+ /**
287
+ * Downloads the file directly, either returning the blob content or saving it locally.
288
+ *
289
+ * @param file - File footprint.
290
+ * @param meta - Options dictating save path or return format.
291
+ * @returns A promise resolving to the blob or local file path.
292
+ */
202
293
  async download(
203
294
  file: FileType,
204
295
  meta: DownloadFileMetaType