@quatrain/storage-supabase 0.1.0 → 1.1.6
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
2
|
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
3
4
|
import { AbstractStorageAdapter, FileType, FileResponseLinkType, StorageParameters, DownloadFileMetaType } from '@quatrain/storage';
|
|
4
5
|
import { Readable, Stream } from 'stream';
|
|
5
6
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
@@ -10,6 +11,7 @@ export declare class SupabaseStorageAdapter extends AbstractStorageAdapter {
|
|
|
10
11
|
streamToBuffer(stream: Stream): Promise<Buffer>;
|
|
11
12
|
create(file: FileType, stream: Readable): Promise<FileType>;
|
|
12
13
|
copy(file: FileType, destFile: FileType): Promise<void>;
|
|
14
|
+
move(file: FileType, destFile: FileType): Promise<string | FileType>;
|
|
13
15
|
getUrl(file: FileType, expiresIn?: number): Promise<{
|
|
14
16
|
url: string;
|
|
15
17
|
expiresIn: number;
|
|
@@ -18,7 +18,7 @@ const path_1 = require("path");
|
|
|
18
18
|
class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
19
19
|
constructor(params) {
|
|
20
20
|
super(params);
|
|
21
|
-
this._client = (0, supabase_js_1.createClient)(this._params.config.
|
|
21
|
+
this._client = (0, supabase_js_1.createClient)(this._params.config.supabaseUrl, this._params.config.supabaseKey);
|
|
22
22
|
storage_1.Storage.log(`[ASA] Supabase Storage Adapter initialized`);
|
|
23
23
|
}
|
|
24
24
|
getDriver() {
|
|
@@ -48,6 +48,7 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
48
48
|
}
|
|
49
49
|
copy(file, destFile) {
|
|
50
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
storage_1.Storage.log(`Copying file ${file.ref} to ${destFile.ref} in bucket ${file.bucket}`);
|
|
51
52
|
try {
|
|
52
53
|
const response = yield this._client.storage
|
|
53
54
|
.from(file.bucket)
|
|
@@ -61,6 +62,18 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
61
62
|
}
|
|
62
63
|
});
|
|
63
64
|
}
|
|
65
|
+
move(file, destFile) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
try {
|
|
68
|
+
yield this.copy(file, destFile);
|
|
69
|
+
yield this.delete(file);
|
|
70
|
+
return destFile;
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
return err.message;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
64
77
|
getUrl(file, expiresIn = 3600) {
|
|
65
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
79
|
const { data, error } = yield this._client.storage
|
|
@@ -80,13 +93,14 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
80
93
|
if (error !== null) {
|
|
81
94
|
throw new Error(`Unable to delete ${file.ref}`);
|
|
82
95
|
}
|
|
83
|
-
storage_1.Storage.log('
|
|
96
|
+
storage_1.Storage.log('Object successfully deleted');
|
|
84
97
|
return true;
|
|
85
98
|
});
|
|
86
99
|
}
|
|
87
100
|
getReadable(file) {
|
|
88
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
102
|
storage_1.Storage.log(`GET Readable : ${file.ref}`);
|
|
103
|
+
console.log(file);
|
|
90
104
|
const path = (0, path_1.join)((0, os_1.tmpdir)(), String(Date.now()));
|
|
91
105
|
const item = yield this.download(file, { path, onlyContent: true });
|
|
92
106
|
const buffer = Buffer.from(item.toString(), 'base64');
|
|
@@ -114,6 +128,7 @@ class SupabaseStorageAdapter extends storage_1.AbstractStorageAdapter {
|
|
|
114
128
|
.from(file.bucket)
|
|
115
129
|
.download(meta.path);
|
|
116
130
|
if (error !== null) {
|
|
131
|
+
console.log(error);
|
|
117
132
|
throw new Error(`Unable to download ${file.ref}`);
|
|
118
133
|
}
|
|
119
134
|
if (meta.onlyContent) {
|
package/package.json
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
2
|
+
"name": "@quatrain/storage-supabase",
|
|
3
|
+
"version": "1.1.6",
|
|
4
|
+
"description": "Storage adapter for Supabase Storage",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"author": "Quatrain Développement SAS <developers@quatrain.com>",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@tsconfig/recommended": "^1.0.1",
|
|
15
|
+
"@types/jest": "^27.0.3",
|
|
16
|
+
"@types/node": "^22.10.1",
|
|
17
|
+
"jest": "^27.4.7",
|
|
18
|
+
"jest-node-exports-resolver": "^1.1.6",
|
|
19
|
+
"trace-unhandled": "^2.0.1",
|
|
20
|
+
"ts-jest": "^27.1.2",
|
|
21
|
+
"ts-node": "^10.4.0",
|
|
22
|
+
"typescript": "^5.1.5"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@quatrain/core": "^1.1.6",
|
|
26
|
+
"@quatrain/storage": "^1.1.6",
|
|
27
|
+
"@supabase/supabase-js": "^2.45.1"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"test": "tsc && jest --verbose",
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"wbuild": "tsc --watch",
|
|
33
|
+
"bump-to": "yarn version",
|
|
34
|
+
"patch": "yarn version --patch --no-git-tag-version",
|
|
35
|
+
"publish": "yarn build && yarn npm publish --access public"
|
|
36
|
+
}
|
|
37
|
+
}
|