@toa.io/extensions.storages 1.0.0-alpha.21 → 1.0.0-alpha.219
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.
- package/package.json +14 -14
- package/readme.md +96 -51
- package/schemas/annotation.cos.yaml +1 -0
- package/schemas/cloudinary.cos.yaml +37 -0
- package/schemas/fs.cos.yaml +2 -0
- package/schemas/s3.cos.yaml +1 -0
- package/schemas/tmp.cos.yaml +0 -1
- package/source/Entry.ts +13 -11
- package/source/Factory.ts +16 -9
- package/source/Provider.ts +22 -19
- package/source/Scanner.ts +58 -26
- package/source/Secrets.ts +6 -0
- package/source/Storage.test.ts +118 -274
- package/source/Storage.ts +62 -207
- package/source/deployment.ts +52 -16
- package/source/errors.ts +3 -0
- package/source/index.ts +3 -1
- package/source/manifest.ts +7 -6
- package/source/providers/Cloudinary.ts +320 -0
- package/source/providers/Declaration.ts +2 -1
- package/source/providers/FileSystem.ts +79 -25
- package/source/providers/S3.ts +81 -80
- package/source/providers/Temporary.ts +2 -3
- package/source/providers/Test.ts +4 -4
- package/source/providers/index.test.ts +102 -76
- package/source/providers/index.ts +10 -4
- package/source/schemas.ts +1 -0
- package/source/test/.env.example +4 -0
- package/source/test/arny.jpg +0 -0
- package/source/test/lenna.48x48.jpeg +0 -0
- package/source/test/plank.mp4 +0 -0
- package/source/test/sample.avi +0 -0
- package/source/test/sample.wav +0 -0
- package/source/test/sport.mp4 +0 -0
- package/source/test/util.ts +62 -12
- package/transpiled/Entry.d.ts +15 -11
- package/transpiled/Factory.js +11 -5
- package/transpiled/Factory.js.map +1 -1
- package/transpiled/Provider.d.ts +17 -16
- package/transpiled/Provider.js +6 -4
- package/transpiled/Provider.js.map +1 -1
- package/transpiled/Scanner.d.ts +6 -2
- package/transpiled/Scanner.js +49 -22
- package/transpiled/Scanner.js.map +1 -1
- package/transpiled/Secrets.d.ts +5 -0
- package/transpiled/Secrets.js +3 -0
- package/transpiled/Secrets.js.map +1 -0
- package/transpiled/Storage.d.ts +13 -21
- package/transpiled/Storage.js +52 -155
- package/transpiled/Storage.js.map +1 -1
- package/transpiled/deployment.d.ts +1 -1
- package/transpiled/deployment.js +43 -16
- package/transpiled/deployment.js.map +1 -1
- package/transpiled/errors.d.ts +2 -0
- package/transpiled/errors.js +6 -0
- package/transpiled/errors.js.map +1 -0
- package/transpiled/index.d.ts +3 -1
- package/transpiled/manifest.js +5 -2
- package/transpiled/manifest.js.map +1 -1
- package/transpiled/providers/Cloudinary.d.ts +51 -0
- package/transpiled/providers/Cloudinary.js +223 -0
- package/transpiled/providers/Cloudinary.js.map +1 -0
- package/transpiled/providers/Declaration.d.ts +3 -2
- package/transpiled/providers/FileSystem.d.ts +15 -7
- package/transpiled/providers/FileSystem.js +64 -24
- package/transpiled/providers/FileSystem.js.map +1 -1
- package/transpiled/providers/S3.d.ts +14 -14
- package/transpiled/providers/S3.js +62 -60
- package/transpiled/providers/S3.js.map +1 -1
- package/transpiled/providers/Temporary.d.ts +1 -2
- package/transpiled/providers/Temporary.js +2 -2
- package/transpiled/providers/Temporary.js.map +1 -1
- package/transpiled/providers/Test.d.ts +3 -3
- package/transpiled/providers/Test.js +2 -2
- package/transpiled/providers/Test.js.map +1 -1
- package/transpiled/providers/index.d.ts +7 -2
- package/transpiled/providers/index.js +2 -2
- package/transpiled/providers/index.js.map +1 -1
- package/transpiled/schemas.d.ts +1 -0
- package/transpiled/schemas.js +2 -1
- package/transpiled/schemas.js.map +1 -1
- package/transpiled/test/util.d.ts +89 -5
- package/transpiled/test/util.js +51 -4
- package/transpiled/test/util.js.map +1 -1
- package/transpiled/tsconfig.tsbuildinfo +1 -1
- package/source/providers/FileSystem.test.ts +0 -5
- package/source/providers/Memory.ts +0 -41
- package/source/providers/S3.test.ts +0 -133
- package/transpiled/providers/Memory.d.ts +0 -13
- package/transpiled/providers/Memory.js +0 -60
- package/transpiled/providers/Memory.js.map +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
import { Provider } from '../Provider';
|
|
4
|
+
import type { Maybe } from '@toa.io/types';
|
|
5
|
+
import type { Metadata, Stream } from '../Entry';
|
|
6
|
+
import type { Secret, Secrets } from '../Secrets';
|
|
7
|
+
import type { TransformationOptions } from 'cloudinary';
|
|
8
|
+
export type CloudinarySecrets = Secrets<'API_KEY' | 'API_SECRET'>;
|
|
9
|
+
export declare class Cloudinary extends Provider<CloudinaryOptions> {
|
|
10
|
+
static readonly SECRETS: readonly Secret[];
|
|
11
|
+
private readonly type;
|
|
12
|
+
private readonly eager;
|
|
13
|
+
private readonly transformations;
|
|
14
|
+
private readonly config;
|
|
15
|
+
private readonly prefix;
|
|
16
|
+
constructor(options: CloudinaryOptions, secrets?: CloudinarySecrets);
|
|
17
|
+
get(path: string, options?: GetOptions): Promise<Maybe<Stream>>;
|
|
18
|
+
head(path: string): Promise<Maybe<Metadata>>;
|
|
19
|
+
put(path: string, stream: Readable): Promise<void>;
|
|
20
|
+
commit(): Promise<void>;
|
|
21
|
+
delete(path: string): Promise<void>;
|
|
22
|
+
move(from: string, to: string): Promise<void | Error>;
|
|
23
|
+
private fetch;
|
|
24
|
+
private url;
|
|
25
|
+
private toTransformation;
|
|
26
|
+
private mapTransformation;
|
|
27
|
+
private metadata;
|
|
28
|
+
private cloudinary;
|
|
29
|
+
}
|
|
30
|
+
interface GetOptions {
|
|
31
|
+
agent?: string;
|
|
32
|
+
range?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface CloudinaryOptions {
|
|
35
|
+
environment: string;
|
|
36
|
+
type: StorageType;
|
|
37
|
+
prefix?: string;
|
|
38
|
+
eager?: TransformationOptions[];
|
|
39
|
+
transformations?: TransformationDeclaration[];
|
|
40
|
+
}
|
|
41
|
+
type TransformationDeclaration = Omit<Transformation, 'extension'> & {
|
|
42
|
+
extension: string;
|
|
43
|
+
};
|
|
44
|
+
interface Transformation {
|
|
45
|
+
extension: RegExp;
|
|
46
|
+
condition?: string;
|
|
47
|
+
transformation: Record<string, unknown> | Array<Record<string, unknown>>;
|
|
48
|
+
optional?: boolean;
|
|
49
|
+
}
|
|
50
|
+
type StorageType = 'image' | 'video';
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Cloudinary = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const node_stream_1 = require("node:stream");
|
|
6
|
+
const cloudinary_1 = require("cloudinary");
|
|
7
|
+
const openspan_1 = require("openspan");
|
|
8
|
+
const Provider_1 = require("../Provider");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
class Cloudinary extends Provider_1.Provider {
|
|
11
|
+
static SECRETS = [
|
|
12
|
+
{ name: 'API_KEY' },
|
|
13
|
+
{ name: 'API_SECRET' }
|
|
14
|
+
];
|
|
15
|
+
type;
|
|
16
|
+
eager = [];
|
|
17
|
+
transformations = [];
|
|
18
|
+
config;
|
|
19
|
+
prefix;
|
|
20
|
+
constructor(options, secrets) {
|
|
21
|
+
super(options, secrets);
|
|
22
|
+
this.type = options.type;
|
|
23
|
+
if (options.eager !== undefined)
|
|
24
|
+
this.eager = options.eager;
|
|
25
|
+
if (options.transformations !== undefined)
|
|
26
|
+
this.transformations = options.transformations.map((transformation) => {
|
|
27
|
+
const { extension, ...rest } = transformation;
|
|
28
|
+
let expression = extension;
|
|
29
|
+
if (!extension.startsWith('^'))
|
|
30
|
+
expression = '^' + extension;
|
|
31
|
+
if (!extension.endsWith('$'))
|
|
32
|
+
expression = extension + '$';
|
|
33
|
+
return {
|
|
34
|
+
extension: new RegExp(expression),
|
|
35
|
+
...rest
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
this.config = {
|
|
39
|
+
cloud_name: options.environment,
|
|
40
|
+
api_key: secrets.API_KEY,
|
|
41
|
+
api_secret: secrets.API_SECRET
|
|
42
|
+
};
|
|
43
|
+
this.prefix = options.prefix ?? '/';
|
|
44
|
+
}
|
|
45
|
+
async get(path, options) {
|
|
46
|
+
const headers = {};
|
|
47
|
+
if (options?.range !== undefined)
|
|
48
|
+
headers.range = options.range;
|
|
49
|
+
if (options?.agent !== undefined)
|
|
50
|
+
headers['user-agent'] = options.agent;
|
|
51
|
+
const response = await this.fetch(path, { method: 'GET', headers });
|
|
52
|
+
if (response instanceof Error)
|
|
53
|
+
return errors_1.ERR_NOT_FOUND;
|
|
54
|
+
const metadata = this.metadata(response);
|
|
55
|
+
return {
|
|
56
|
+
stream: node_stream_1.Readable.fromWeb(response.body),
|
|
57
|
+
...metadata
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async head(path) {
|
|
61
|
+
const response = await this.fetch(path, { method: 'HEAD' });
|
|
62
|
+
if (response instanceof Error)
|
|
63
|
+
return errors_1.ERR_NOT_FOUND;
|
|
64
|
+
return this.metadata(response);
|
|
65
|
+
}
|
|
66
|
+
async put(path, stream) {
|
|
67
|
+
const id = (0, node_path_1.basename)(path);
|
|
68
|
+
const folder = (0, node_path_1.join)(this.prefix, (0, node_path_1.dirname)(path));
|
|
69
|
+
await new Promise((resolve, reject) => {
|
|
70
|
+
const options = {
|
|
71
|
+
public_id: id,
|
|
72
|
+
folder,
|
|
73
|
+
eager: this.eager,
|
|
74
|
+
resource_type: this.type
|
|
75
|
+
};
|
|
76
|
+
openspan_1.console.debug('Uploading to Cloudinary', { path, options });
|
|
77
|
+
stream.pipe(this.cloudinary().uploader.upload_stream(options, (error, result) => {
|
|
78
|
+
if (error !== undefined)
|
|
79
|
+
reject(error);
|
|
80
|
+
else
|
|
81
|
+
resolve(result);
|
|
82
|
+
}));
|
|
83
|
+
stream.on('error', (e) => {
|
|
84
|
+
openspan_1.console.error('Cloudinary stream error', { path, error: e });
|
|
85
|
+
stream.destroy();
|
|
86
|
+
reject(e);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
async commit() {
|
|
91
|
+
// metadata is read-only
|
|
92
|
+
}
|
|
93
|
+
async delete(path) {
|
|
94
|
+
const id = (0, node_path_1.join)(this.prefix, path);
|
|
95
|
+
openspan_1.console.debug('Deleting from Cloudinary', { path: id });
|
|
96
|
+
await this.cloudinary().uploader.destroy(id, { resource_type: this.type, invalidate: true });
|
|
97
|
+
}
|
|
98
|
+
async move(from, to) {
|
|
99
|
+
const source = (0, node_path_1.join)(this.prefix, from);
|
|
100
|
+
const target = (0, node_path_1.join)(this.prefix, to);
|
|
101
|
+
try {
|
|
102
|
+
await this.cloudinary().uploader.rename(source, target, { resource_type: this.type, overwrite: true });
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error.http_code === 404)
|
|
106
|
+
return errors_1.ERR_NOT_FOUND;
|
|
107
|
+
else
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async fetch(path, options = { method: 'GET' }) {
|
|
112
|
+
const url = this.url(path);
|
|
113
|
+
if (url === null)
|
|
114
|
+
return errors_1.ERR_NOT_FOUND;
|
|
115
|
+
openspan_1.console.debug('Fetching from Cloudinary', {
|
|
116
|
+
method: options.method,
|
|
117
|
+
path,
|
|
118
|
+
url
|
|
119
|
+
});
|
|
120
|
+
const response = await fetch(url, options).catch((e) => e);
|
|
121
|
+
if (response instanceof Error || response.ok === false) {
|
|
122
|
+
openspan_1.console.debug('Failed to fetch from Cloudinary', {
|
|
123
|
+
url,
|
|
124
|
+
status: response.status,
|
|
125
|
+
message: response.message
|
|
126
|
+
});
|
|
127
|
+
return errors_1.ERR_NOT_FOUND;
|
|
128
|
+
}
|
|
129
|
+
else
|
|
130
|
+
openspan_1.console.debug('Received response from Cloudinary', {
|
|
131
|
+
url,
|
|
132
|
+
status: response.status,
|
|
133
|
+
headers: response.headers
|
|
134
|
+
});
|
|
135
|
+
return response;
|
|
136
|
+
}
|
|
137
|
+
url(path) {
|
|
138
|
+
const [base, transformation] = this.toTransformation(path);
|
|
139
|
+
if (base === null)
|
|
140
|
+
return null;
|
|
141
|
+
const id = (0, node_path_1.join)(this.prefix, base);
|
|
142
|
+
return this.cloudinary().url(id, {
|
|
143
|
+
resource_type: this.type,
|
|
144
|
+
transformation,
|
|
145
|
+
version: 2
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
toTransformation(path) {
|
|
149
|
+
if (this.transformations.length === 0)
|
|
150
|
+
return [path, undefined];
|
|
151
|
+
const [base, ...extensions] = path.split('.');
|
|
152
|
+
const transformations = [];
|
|
153
|
+
let t = 0;
|
|
154
|
+
for (const extension of extensions) {
|
|
155
|
+
let found = false;
|
|
156
|
+
for (t; t < this.transformations.length && !found; t++) {
|
|
157
|
+
const { extension: regex, condition, transformation, optional } = this.transformations[t];
|
|
158
|
+
const match = regex.exec(extension);
|
|
159
|
+
// eslint-disable-next-line max-depth
|
|
160
|
+
if (match === null)
|
|
161
|
+
if (optional === true)
|
|
162
|
+
continue;
|
|
163
|
+
else
|
|
164
|
+
return [null, undefined];
|
|
165
|
+
const options = Array.isArray(transformation) ? transformation : [transformation];
|
|
166
|
+
const stages = options.map((stage) => this.mapTransformation(stage, match.groups));
|
|
167
|
+
found = true;
|
|
168
|
+
if (condition === undefined)
|
|
169
|
+
transformations.push(...stages);
|
|
170
|
+
else {
|
|
171
|
+
transformations.push({ if: condition });
|
|
172
|
+
transformations.push(...stages);
|
|
173
|
+
transformations.push({ if: 'end' });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (!found)
|
|
177
|
+
return [null, undefined];
|
|
178
|
+
}
|
|
179
|
+
for (t; t < this.transformations.length; t++)
|
|
180
|
+
if (this.transformations[t].optional !== true)
|
|
181
|
+
return [null, undefined];
|
|
182
|
+
return [base, transformations];
|
|
183
|
+
}
|
|
184
|
+
mapTransformation(options, groups) {
|
|
185
|
+
return Object.fromEntries(Object.entries(options).map(([key, value]) => {
|
|
186
|
+
if (typeof value !== 'string')
|
|
187
|
+
return [key, value];
|
|
188
|
+
if (value.startsWith('<') && value.endsWith('>'))
|
|
189
|
+
value = groups[value.slice(1, -1)];
|
|
190
|
+
if (key === 'zoom' && value !== undefined)
|
|
191
|
+
value = Number.parseInt(value) / 100;
|
|
192
|
+
if (key === 'fetch_format' && value === 'jpeg')
|
|
193
|
+
value = 'jpg';
|
|
194
|
+
return [key, value];
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
metadata(response) {
|
|
198
|
+
const size = response.headers.get('content-length') === null
|
|
199
|
+
? null
|
|
200
|
+
: Number.parseInt(response.headers.get('content-length'));
|
|
201
|
+
const created = response.headers.get('date') ?? new Date().toISOString();
|
|
202
|
+
const etag = response.headers.get('etag');
|
|
203
|
+
const checksum = etag === null ? (0, node_path_1.basename)(response.url) : etag.slice(1, -1);
|
|
204
|
+
const range = response.headers.get('content-range');
|
|
205
|
+
return {
|
|
206
|
+
type: response.headers.get('content-type'),
|
|
207
|
+
size,
|
|
208
|
+
checksum,
|
|
209
|
+
created,
|
|
210
|
+
range: range ?? undefined,
|
|
211
|
+
partial: response.status === 206,
|
|
212
|
+
attributes: {
|
|
213
|
+
url: response.url
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
cloudinary() {
|
|
218
|
+
cloudinary_1.v2.config(this.config);
|
|
219
|
+
return cloudinary_1.v2;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
exports.Cloudinary = Cloudinary;
|
|
223
|
+
//# sourceMappingURL=Cloudinary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cloudinary.js","sourceRoot":"","sources":["../../source/providers/Cloudinary.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AACnD,6CAAsC;AACtC,2CAA6C;AAC7C,uCAAkC;AAClC,0CAAsC;AACtC,sCAAyC;AAazC,MAAa,UAAW,SAAQ,mBAA2B;IAClD,MAAM,CAAmB,OAAO,GAAsB;QAC3D,EAAE,IAAI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CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACzC,MAAM,QAAQ,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAA,oBAAQ,EAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC3E,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;QAEnD,OAAO;YACL,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAE;YAC3C,IAAI;YACJ,QAAQ;YACR,OAAO;YACP,KAAK,EAAE,KAAK,IAAI,SAAS;YACzB,OAAO,EAAE,QAAQ,CAAC,MAAM,KAAK,GAAG;YAChC,UAAU,EAAE;gBACV,GAAG,EAAE,QAAQ,CAAC,GAAG;aAClB;SACF,CAAA;IACH,CAAC;IAEO,UAAU;QAChB,eAAU,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAE9B,OAAO,eAAU,CAAA;IACnB,CAAC;;AApRH,gCAqRC"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { S3Options } from './S3';
|
|
2
|
+
import type { CloudinaryOptions } from './Cloudinary';
|
|
2
3
|
import type { FileSystemOptions } from './FileSystem';
|
|
3
4
|
import type { TemporaryOptions } from './Temporary';
|
|
4
5
|
export type Declaration = ({
|
|
5
6
|
provider: 's3';
|
|
6
7
|
} & S3Options) | ({
|
|
8
|
+
provider: 'cloudinary';
|
|
9
|
+
} & CloudinaryOptions) | ({
|
|
7
10
|
provider: 'fs';
|
|
8
11
|
} & FileSystemOptions) | ({
|
|
9
12
|
provider: 'tmp';
|
|
10
13
|
} & TemporaryOptions) | ({
|
|
11
|
-
provider: 'mem';
|
|
12
|
-
}) | ({
|
|
13
14
|
provider: 'test';
|
|
14
15
|
} & TemporaryOptions);
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { type Readable } from 'node:stream';
|
|
3
2
|
import { Provider } from '../Provider';
|
|
4
|
-
import type {
|
|
3
|
+
import type { Readable } from 'node:stream';
|
|
4
|
+
import type { Maybe } from '@toa.io/types';
|
|
5
|
+
import type { Metadata, Stream } from '../Entry';
|
|
5
6
|
export interface FileSystemOptions {
|
|
6
7
|
path: string;
|
|
8
|
+
claim?: string;
|
|
7
9
|
}
|
|
8
10
|
export declare class FileSystem extends Provider<FileSystemOptions> {
|
|
9
|
-
|
|
10
|
-
constructor(options: FileSystemOptions
|
|
11
|
-
get(
|
|
12
|
-
|
|
11
|
+
readonly root: string;
|
|
12
|
+
constructor(options: FileSystemOptions);
|
|
13
|
+
get(rel: string): Promise<Maybe<Stream>>;
|
|
14
|
+
head(rel: string): Promise<Maybe<Metadata>>;
|
|
15
|
+
put(rel: string, stream: Readable): Promise<void>;
|
|
16
|
+
commit(rel: string, metadata: Metadata): Promise<void>;
|
|
13
17
|
delete(path: string): Promise<void>;
|
|
14
|
-
move(from: string, to: string): Promise<void
|
|
18
|
+
move(from: string, to: string): Promise<Maybe<void>>;
|
|
19
|
+
private blob;
|
|
20
|
+
private meta;
|
|
21
|
+
private join;
|
|
22
|
+
private try;
|
|
15
23
|
}
|
|
@@ -4,40 +4,80 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.FileSystem = void 0;
|
|
7
|
-
const node_path_1 = require("node:path");
|
|
8
7
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
9
10
|
const Provider_1 = require("../Provider");
|
|
11
|
+
const errors_1 = require("../errors");
|
|
10
12
|
class FileSystem extends Provider_1.Provider {
|
|
11
|
-
|
|
12
|
-
constructor(options
|
|
13
|
-
super(options
|
|
14
|
-
this.
|
|
13
|
+
root;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super(options);
|
|
16
|
+
this.root = options.path;
|
|
15
17
|
}
|
|
16
|
-
async get(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return null;
|
|
24
|
-
throw err;
|
|
25
|
-
}
|
|
18
|
+
async get(rel) {
|
|
19
|
+
const path = this.blob(rel);
|
|
20
|
+
const metadata = await this.head(rel);
|
|
21
|
+
if (metadata instanceof Error)
|
|
22
|
+
return metadata;
|
|
23
|
+
const stream = (0, node_fs_1.createReadStream)(path);
|
|
24
|
+
return { stream, ...metadata };
|
|
26
25
|
}
|
|
27
|
-
async
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
async head(rel) {
|
|
27
|
+
const path = this.meta(rel);
|
|
28
|
+
return this.try(async () => {
|
|
29
|
+
const contents = await promises_1.default.readFile(path, 'utf8');
|
|
30
|
+
return JSON.parse(contents);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async put(rel, stream) {
|
|
34
|
+
const path = this.blob(rel);
|
|
35
|
+
const dir = (0, node_path_1.dirname)(path);
|
|
36
|
+
await promises_1.default.mkdir(dir, { recursive: true });
|
|
31
37
|
await promises_1.default.writeFile(path, stream);
|
|
32
38
|
}
|
|
39
|
+
async commit(rel, metadata) {
|
|
40
|
+
const path = this.meta(rel);
|
|
41
|
+
await promises_1.default.writeFile(path, JSON.stringify(metadata), 'utf8');
|
|
42
|
+
}
|
|
33
43
|
async delete(path) {
|
|
34
|
-
await
|
|
44
|
+
await Promise.all([
|
|
45
|
+
promises_1.default.rm(this.blob(path), { force: true }),
|
|
46
|
+
promises_1.default.rm(this.meta(path), { force: true })
|
|
47
|
+
]);
|
|
35
48
|
}
|
|
36
49
|
async move(from, to) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
const bf = this.blob(from);
|
|
51
|
+
const bt = this.blob(to);
|
|
52
|
+
const mf = this.meta(from);
|
|
53
|
+
const mt = this.meta(to);
|
|
54
|
+
await promises_1.default.mkdir((0, node_path_1.dirname)(bt), { recursive: true });
|
|
55
|
+
return await this.try(async () => {
|
|
56
|
+
await Promise.all([
|
|
57
|
+
promises_1.default.rename(bf, bt),
|
|
58
|
+
promises_1.default.rename(mf, mt)
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
blob(rel) {
|
|
63
|
+
return this.join(rel, '.blob');
|
|
64
|
+
}
|
|
65
|
+
meta(rel) {
|
|
66
|
+
return this.join(rel, '.meta');
|
|
67
|
+
}
|
|
68
|
+
join(rel, ext) {
|
|
69
|
+
return (0, node_path_1.join)(this.root, rel) + ext;
|
|
70
|
+
}
|
|
71
|
+
async try(action) {
|
|
72
|
+
try {
|
|
73
|
+
return await action();
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
if (err?.code === 'ENOENT')
|
|
77
|
+
return errors_1.ERR_NOT_FOUND;
|
|
78
|
+
else
|
|
79
|
+
throw err;
|
|
80
|
+
}
|
|
41
81
|
}
|
|
42
82
|
}
|
|
43
83
|
exports.FileSystem = FileSystem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystem.js","sourceRoot":"","sources":["../../source/providers/FileSystem.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"FileSystem.js","sourceRoot":"","sources":["../../source/providers/FileSystem.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAiC;AACjC,qCAA0C;AAC1C,yCAAyC;AACzC,0CAAsC;AACtC,sCAAyC;AAUzC,MAAa,UAAW,SAAQ,mBAA2B;IAChC,IAAI,CAAQ;IAErC,YAAoB,OAA0B;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAA;QAEd,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IAC1B,CAAC;IAEM,KAAK,C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AAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAChC,CAAC;IAEO,IAAI,CAAE,GAAW,EAAE,GAAW;QACpC,OAAO,IAAA,gBAAI,EAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,GAAG,CAAA;IACnC,CAAC;IAEO,KAAK,CAAC,GAAG,CAAW,MAAwB;QAClD,IAAI,CAAC;YACH,OAAO,MAAM,MAAM,EAAE,CAAA;QACvB,CAAC;QAAC,OAAO,GAAgC,EAAE,CAAC;YAC1C,IAAI,GAAG,EAAE,IAAI,KAAK,QAAQ;gBACxB,OAAO,sBAAa,CAAA;;gBAEpB,MAAM,GAAG,CAAA;QACb,CAAC;IACH,CAAC;CACF;AA1FD,gCA0FC"}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Readable } from 'node:stream';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { Provider } from '../Provider';
|
|
4
|
+
import type { Maybe } from '@toa.io/types';
|
|
5
|
+
import type { Metadata, Stream } from '../Entry';
|
|
6
|
+
import type { Secret, Secrets } from '../Secrets';
|
|
5
7
|
export interface S3Options {
|
|
6
8
|
bucket: string;
|
|
7
9
|
region?: string;
|
|
8
10
|
prefix?: string;
|
|
9
11
|
endpoint?: string;
|
|
10
12
|
}
|
|
11
|
-
type S3Secrets =
|
|
13
|
+
type S3Secrets = Secrets<'ACCESS_KEY_ID' | 'SECRET_ACCESS_KEY'>;
|
|
12
14
|
export declare class S3 extends Provider<S3Options> {
|
|
13
|
-
static readonly SECRETS: readonly
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
static readonly SECRETS: readonly Secret[];
|
|
16
|
+
private readonly bucket;
|
|
17
|
+
private readonly client;
|
|
16
18
|
constructor(options: S3Options, secrets?: S3Secrets);
|
|
17
|
-
get(Key: string): Promise<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* with given prefix (prefix will be enforced to finish with `/`)
|
|
22
|
-
* @param Key - key name or path prefix
|
|
23
|
-
*/
|
|
19
|
+
get(Key: string): Promise<Maybe<Stream>>;
|
|
20
|
+
head(Key: string): Promise<Maybe<Metadata>>;
|
|
21
|
+
put(Key: string, stream: Readable): Promise<void>;
|
|
22
|
+
commit(Key: string, metadata: object): Promise<void>;
|
|
24
23
|
delete(Key: string): Promise<void>;
|
|
25
|
-
move(from: string, keyTo: string): Promise<void
|
|
24
|
+
move(from: string, keyTo: string): Promise<Maybe<void>>;
|
|
25
|
+
private try;
|
|
26
26
|
}
|
|
27
27
|
export {};
|