@toa.io/extensions.storages 1.0.0-alpha.31 → 1.0.0-alpha.310
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 +38 -18
- package/readme.md +115 -47
- package/transpiled/Aspect.d.ts +8 -4
- package/transpiled/Aspect.js +12 -14
- package/transpiled/Aspect.js.map +1 -1
- package/transpiled/Entry.d.ts +14 -11
- package/transpiled/Entry.js +1 -2
- package/transpiled/Factory.d.ts +1 -1
- package/transpiled/Factory.js +29 -30
- package/transpiled/Factory.js.map +1 -1
- package/transpiled/Provider.d.ts +17 -19
- package/transpiled/Provider.js +10 -33
- package/transpiled/Provider.js.map +1 -1
- package/transpiled/Scanner.d.ts +5 -4
- package/transpiled/Scanner.js +33 -26
- package/transpiled/Scanner.js.map +1 -1
- package/transpiled/Secrets.d.ts +5 -0
- package/transpiled/Secrets.js +2 -0
- package/transpiled/Secrets.js.map +1 -0
- package/transpiled/Storage.d.ts +23 -22
- package/transpiled/Storage.js +79 -142
- package/transpiled/Storage.js.map +1 -1
- package/transpiled/errors.d.ts +7 -0
- package/transpiled/errors.js +4 -0
- package/transpiled/errors.js.map +1 -0
- package/transpiled/index.d.ts +4 -4
- package/transpiled/index.js +1 -9
- package/transpiled/index.js.map +1 -1
- package/transpiled/measurements.d.ts +3 -0
- package/transpiled/measurements.js +23 -0
- package/transpiled/measurements.js.map +1 -0
- package/transpiled/providers/Cloudinary.d.ts +50 -0
- package/transpiled/providers/Cloudinary.js +223 -0
- package/transpiled/providers/Cloudinary.js.map +1 -0
- package/transpiled/providers/Declaration.d.ts +9 -5
- package/transpiled/providers/Declaration.js +1 -2
- package/transpiled/providers/FileSystem.d.ts +16 -11
- package/transpiled/providers/FileSystem.js +64 -43
- package/transpiled/providers/FileSystem.js.map +1 -1
- package/transpiled/providers/S3.d.ts +14 -19
- package/transpiled/providers/S3.js +72 -123
- package/transpiled/providers/S3.js.map +1 -1
- package/transpiled/providers/Spaces.d.ts +12 -0
- package/transpiled/providers/Spaces.js +13 -0
- package/transpiled/providers/Spaces.js.map +1 -0
- package/transpiled/providers/Temporary.d.ts +2 -3
- package/transpiled/providers/Temporary.js +7 -11
- package/transpiled/providers/Temporary.js.map +1 -1
- package/transpiled/providers/Test.d.ts +4 -4
- package/transpiled/providers/Test.js +6 -12
- package/transpiled/providers/Test.js.map +1 -1
- package/transpiled/providers/index.d.ts +23 -11
- package/transpiled/providers/index.js +30 -14
- package/transpiled/providers/index.js.map +1 -1
- package/transpiled/providers/index.types.d.ts +5 -0
- package/transpiled/providers/index.types.js +2 -0
- package/transpiled/providers/index.types.js.map +1 -0
- package/transpiled/test/util.d.ts +113 -6
- package/transpiled/test/util.js +68 -15
- package/transpiled/test/util.js.map +1 -1
- package/schemas/annotation.cos.yaml +0 -10
- package/schemas/fs.cos.yaml +0 -9
- package/schemas/mem.cos.yaml +0 -6
- package/schemas/s3.cos.yaml +0 -16
- package/schemas/test.cos.yaml +0 -8
- package/schemas/tmp.cos.yaml +0 -9
- package/source/Annotation.ts +0 -39
- package/source/Aspect.ts +0 -25
- package/source/Entry.ts +0 -14
- package/source/Factory.ts +0 -68
- package/source/Provider.ts +0 -37
- package/source/Scanner.ts +0 -153
- package/source/Storage.test.ts +0 -472
- package/source/Storage.ts +0 -235
- package/source/deployment.ts +0 -57
- package/source/index.ts +0 -5
- package/source/manifest.ts +0 -8
- package/source/providers/Declaration.ts +0 -10
- package/source/providers/FileSystem.test.ts +0 -5
- package/source/providers/FileSystem.ts +0 -63
- package/source/providers/Memory.ts +0 -55
- package/source/providers/S3.test.ts +0 -134
- package/source/providers/S3.ts +0 -196
- package/source/providers/Temporary.ts +0 -16
- package/source/providers/Test.ts +0 -13
- package/source/providers/index.test.ts +0 -136
- package/source/providers/index.ts +0 -16
- package/source/providers/readme.md +0 -25
- package/source/schemas.test.ts +0 -58
- package/source/schemas.ts +0 -15
- package/source/test/.env.example +0 -1
- package/source/test/albert.jpg +0 -0
- package/source/test/empty.txt +0 -0
- package/source/test/lenna.ascii +0 -64
- package/source/test/lenna.png +0 -0
- package/source/test/sample.avi +0 -0
- package/source/test/sample.avif +0 -0
- package/source/test/sample.gif +0 -0
- package/source/test/sample.heic +0 -0
- package/source/test/sample.jpeg +0 -0
- package/source/test/sample.jxl +0 -0
- package/source/test/sample.svg +0 -4
- package/source/test/sample.wav +0 -0
- package/source/test/sample.webp +0 -0
- package/source/test/util.ts +0 -45
- package/transpiled/Annotation.d.ts +0 -3
- package/transpiled/Annotation.js +0 -57
- package/transpiled/Annotation.js.map +0 -1
- package/transpiled/deployment.d.ts +0 -5
- package/transpiled/deployment.js +0 -68
- package/transpiled/deployment.js.map +0 -1
- package/transpiled/manifest.d.ts +0 -1
- package/transpiled/manifest.js +0 -9
- package/transpiled/manifest.js.map +0 -1
- package/transpiled/providers/Memory.d.ts +0 -15
- package/transpiled/providers/Memory.js +0 -72
- package/transpiled/providers/Memory.js.map +0 -1
- package/transpiled/schemas.d.ts +0 -9
- package/transpiled/schemas.js +0 -14
- package/transpiled/schemas.js.map +0 -1
- package/transpiled/tsconfig.tsbuildinfo +0 -1
- package/tsconfig.json +0 -12
package/transpiled/Scanner.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const node_crypto_1 = require("node:crypto");
|
|
6
|
-
const agent_1 = require("@toa.io/agent");
|
|
7
|
-
const error_value_1 = require("error-value");
|
|
8
|
-
class Scanner extends node_stream_1.PassThrough {
|
|
1
|
+
import { PassThrough } from 'node:stream';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import Negotiator from 'negotiator';
|
|
4
|
+
export class Scanner extends PassThrough {
|
|
9
5
|
size = 0;
|
|
10
6
|
type = 'application/octet-stream';
|
|
11
|
-
error
|
|
12
|
-
hash =
|
|
7
|
+
error;
|
|
8
|
+
hash = createHash('md5');
|
|
13
9
|
claim;
|
|
14
10
|
accept;
|
|
11
|
+
limit;
|
|
15
12
|
position = 0;
|
|
16
|
-
|
|
13
|
+
completed = false;
|
|
17
14
|
chunks = [];
|
|
18
15
|
constructor(control) {
|
|
19
16
|
super();
|
|
20
17
|
this.claim = control?.claim;
|
|
21
18
|
this.accept = control?.accept;
|
|
19
|
+
this.limit = control?.limit;
|
|
22
20
|
}
|
|
23
21
|
digest() {
|
|
24
22
|
return this.hash.digest('hex');
|
|
@@ -30,7 +28,7 @@ class Scanner extends node_stream_1.PassThrough {
|
|
|
30
28
|
process = (buffer) => {
|
|
31
29
|
this.size += buffer.length;
|
|
32
30
|
this.hash.update(buffer);
|
|
33
|
-
if (this.
|
|
31
|
+
if (this.completed)
|
|
34
32
|
return;
|
|
35
33
|
if (this.position + buffer.length > HEADER_SIZE)
|
|
36
34
|
buffer = buffer.subarray(0, HEADER_SIZE - this.position);
|
|
@@ -38,15 +36,14 @@ class Scanner extends node_stream_1.PassThrough {
|
|
|
38
36
|
this.position += buffer.length;
|
|
39
37
|
if (this.position === HEADER_SIZE)
|
|
40
38
|
this.complete();
|
|
39
|
+
if (this.limit !== undefined && this.size > this.limit)
|
|
40
|
+
this.interrupt(ERR_LIMIT_EXCEEDED);
|
|
41
41
|
};
|
|
42
42
|
complete() {
|
|
43
43
|
const header = Buffer.concat(this.chunks).toString('hex');
|
|
44
|
-
const signature = SIGNATURES
|
|
45
|
-
.find(({ off, hex, expression }) => {
|
|
44
|
+
const signature = SIGNATURES.find(({ off, hex, expression }) => {
|
|
46
45
|
const sig = header.slice(off, off + hex.length);
|
|
47
|
-
return expression === undefined
|
|
48
|
-
? sig === hex
|
|
49
|
-
: expression.test(sig);
|
|
46
|
+
return expression === undefined ? sig === hex : expression.test(sig);
|
|
50
47
|
});
|
|
51
48
|
const type = signature?.type ?? this.claim;
|
|
52
49
|
if (type !== undefined) {
|
|
@@ -54,7 +51,7 @@ class Scanner extends node_stream_1.PassThrough {
|
|
|
54
51
|
this.type = type;
|
|
55
52
|
}
|
|
56
53
|
this.verify(signature);
|
|
57
|
-
this.
|
|
54
|
+
this.completed = true;
|
|
58
55
|
}
|
|
59
56
|
verify(signature) {
|
|
60
57
|
if (this.claim === undefined || this.claim === 'application/octet-stream')
|
|
@@ -68,20 +65,24 @@ class Scanner extends node_stream_1.PassThrough {
|
|
|
68
65
|
match(type) {
|
|
69
66
|
if (this.accept === undefined)
|
|
70
67
|
return;
|
|
71
|
-
const unacceptable =
|
|
68
|
+
const unacceptable = this.negotiate(this.accept, [type]) === null;
|
|
72
69
|
if (unacceptable)
|
|
73
70
|
this.interrupt(ERR_NOT_ACCEPTABLE);
|
|
74
71
|
}
|
|
72
|
+
negotiate(accept, type) {
|
|
73
|
+
return new Negotiator({ headers: { accept } }).mediaType(type) ?? null;
|
|
74
|
+
}
|
|
75
75
|
interrupt(error) {
|
|
76
|
+
this.completed = true;
|
|
76
77
|
this.error = error;
|
|
77
|
-
this.
|
|
78
|
+
this.destroy(error);
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
|
-
exports.Scanner = Scanner;
|
|
81
81
|
// https://en.wikipedia.org/wiki/List_of_file_signatures
|
|
82
82
|
const SIGNATURES = [
|
|
83
83
|
{ hex: 'ff d8 ff e0', off: 0, type: 'image/jpeg' },
|
|
84
84
|
{ hex: 'ff d8 ff e1', off: 0, type: 'image/jpeg' },
|
|
85
|
+
{ hex: 'ff d8 ff e2', off: 0, type: 'image/jpeg' },
|
|
85
86
|
{ hex: 'ff d8 ff ee', off: 0, type: 'image/jpeg' },
|
|
86
87
|
{ hex: 'ff d8 ff db', off: 0, type: 'image/jpeg' },
|
|
87
88
|
{ hex: '89 50 4e 47', off: 0, type: 'image/png' },
|
|
@@ -94,7 +95,7 @@ const SIGNATURES = [
|
|
|
94
95
|
{ hex: '52 49 46 46 ?? ?? ?? ?? 57 41 56 45', off: 0, type: 'audio/wav' }
|
|
95
96
|
/*
|
|
96
97
|
When adding a new signature, include a copyright-free sample file in the `.tests` directory
|
|
97
|
-
and update the
|
|
98
|
+
and update the `signatures` test group in `Storage.test.ts`.
|
|
98
99
|
*/
|
|
99
100
|
].map((signature) => {
|
|
100
101
|
signature.hex = signature.hex.replaceAll(' ', '');
|
|
@@ -104,9 +105,15 @@ const SIGNATURES = [
|
|
|
104
105
|
}
|
|
105
106
|
return signature;
|
|
106
107
|
});
|
|
107
|
-
const HEADER_SIZE = SIGNATURES
|
|
108
|
-
.reduce((max, { off, hex }) => Math.max(max, off + hex.length), 0) / 2;
|
|
108
|
+
const HEADER_SIZE = SIGNATURES.reduce((max, { off, hex }) => Math.max(max, off + hex.length), 0) / 2;
|
|
109
109
|
const KNOWN_TYPES = new Set(SIGNATURES.map(({ type }) => type));
|
|
110
|
-
const ERR_TYPE_MISMATCH = (
|
|
111
|
-
|
|
110
|
+
const ERR_TYPE_MISMATCH = new (class TypeMismatchError extends Error {
|
|
111
|
+
code = 'TYPE_MISMATCH';
|
|
112
|
+
})();
|
|
113
|
+
const ERR_NOT_ACCEPTABLE = new (class NotAcceptableError extends Error {
|
|
114
|
+
code = 'NOT_ACCEPTABLE';
|
|
115
|
+
})();
|
|
116
|
+
const ERR_LIMIT_EXCEEDED = new (class LimitExceededError extends Error {
|
|
117
|
+
code = 'LIMIT_EXCEEDED';
|
|
118
|
+
})();
|
|
112
119
|
//# sourceMappingURL=Scanner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Scanner.js","sourceRoot":"","sources":["../source/Scanner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Scanner.js","sourceRoot":"","sources":["../source/Scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA0B,MAAM,aAAa,CAAA;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,UAAU,MAAM,YAAY,CAAA;AAEnC,MAAM,OAAO,OAAQ,SAAQ,WAAW;IAC/B,IAAI,GAAG,CAAC,CAAA;IACR,IAAI,GAAG,0BAA0B,CAAA;IACjC,KAAK,C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,WAAW,GACf,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAElF,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;AAE/D,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,iBAAkB,SAAQ,KAAK;IAClD,IAAI,GAAG,eAAe,CAAA;CACvC,CAAC,EAAE,CAAA;AAEJ,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,kBAAmB,SAAQ,KAAK;IACpD,IAAI,GAAG,gBAAgB,CAAA;CACxC,CAAC,EAAE,CAAA;AAEJ,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,kBAAmB,SAAQ,KAAK;IACpD,IAAI,GAAG,gBAAgB,CAAA;CACxC,CAAC,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Secrets.js","sourceRoot":"","sources":["../source/Secrets.ts"],"names":[],"mappings":""}
|
package/transpiled/Storage.d.ts
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import type { ScanOptions } from './Scanner';
|
|
4
|
-
import type { Provider } from './Provider';
|
|
5
|
-
|
|
6
|
-
export declare class Storage {
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import type { Attributes, Entry, Stream } from './Entry.ts';
|
|
3
|
+
import type { ScanOptions } from './Scanner.ts';
|
|
4
|
+
import type { Provider } from './Provider.ts';
|
|
5
|
+
export declare class Storage<T extends Provider = Provider> {
|
|
7
6
|
private readonly provider;
|
|
8
|
-
|
|
7
|
+
private readonly scope?;
|
|
8
|
+
constructor(provider: T, scope?: Scope);
|
|
9
|
+
options(): T['options'];
|
|
9
10
|
put(path: string, stream: Readable, options?: Options): Maybe<Entry>;
|
|
10
|
-
get(path: string): Maybe<
|
|
11
|
-
|
|
12
|
-
fetch(path: string): Maybe<Readable>;
|
|
11
|
+
get(path: string, options?: unknown): Maybe<Stream>;
|
|
12
|
+
head(path: string): Promise<Maybe<Entry>>;
|
|
13
13
|
delete(path: string): Maybe<void>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
private transit;
|
|
18
|
-
private persist;
|
|
19
|
-
private create;
|
|
20
|
-
private save;
|
|
21
|
-
private parse;
|
|
22
|
-
private destruct;
|
|
14
|
+
path(): string | null;
|
|
15
|
+
private locate;
|
|
16
|
+
private span;
|
|
23
17
|
}
|
|
24
|
-
type Maybe<T> = Promise<T | Error>;
|
|
25
|
-
type Meta = Record<string, string>;
|
|
26
18
|
interface Options extends ScanOptions {
|
|
27
|
-
|
|
19
|
+
id?: string;
|
|
20
|
+
origin?: string;
|
|
21
|
+
attributes?: Attributes;
|
|
22
|
+
}
|
|
23
|
+
type Maybe<T> = Promise<T | Error>;
|
|
24
|
+
export interface Scope {
|
|
25
|
+
/** the logical storage name, e.g. `octets` */
|
|
26
|
+
name: string;
|
|
27
|
+
/** the provider id, e.g. `s3` */
|
|
28
|
+
provider: string;
|
|
28
29
|
}
|
|
29
30
|
export type Storages = Record<string, Storage>;
|
|
30
31
|
export {};
|
package/transpiled/Storage.js
CHANGED
|
@@ -1,157 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const msgpackr_1 = require("msgpackr");
|
|
8
|
-
const generic_1 = require("@toa.io/generic");
|
|
9
|
-
const error_value_1 = require("error-value");
|
|
10
|
-
const Scanner_1 = require("./Scanner");
|
|
11
|
-
class Storage {
|
|
1
|
+
import { basename, dirname, join } from 'node:path';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { console } from 'openspan';
|
|
4
|
+
import { Scanner } from './Scanner.js';
|
|
5
|
+
import { operation } from './measurements.js';
|
|
6
|
+
export class Storage {
|
|
12
7
|
provider;
|
|
13
|
-
|
|
8
|
+
scope;
|
|
9
|
+
constructor(provider, scope) {
|
|
14
10
|
this.provider = provider;
|
|
11
|
+
this.scope = scope;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const pipe = stream.pipe(scanner);
|
|
19
|
-
const tempname = await this.transit(pipe);
|
|
20
|
-
if (scanner.error !== null)
|
|
21
|
-
return scanner.error;
|
|
22
|
-
const id = scanner.digest();
|
|
23
|
-
await this.persist(tempname, id);
|
|
24
|
-
return await this.create(path, id, scanner.size, scanner.type, options?.meta);
|
|
13
|
+
options() {
|
|
14
|
+
return this.provider.options;
|
|
25
15
|
}
|
|
26
|
-
async
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
async put(path, stream, options) {
|
|
17
|
+
return await console.span(this.span('put', path), async () => {
|
|
18
|
+
const scanner = new Scanner(options);
|
|
19
|
+
const pipe = stream.pipe(scanner).on('error', () => undefined);
|
|
20
|
+
const id = options?.id ?? randomUUID().replace(/-/g, '');
|
|
21
|
+
const location = this.locate(path, id);
|
|
22
|
+
/**
|
|
23
|
+
* Provider can return or throw an error.
|
|
24
|
+
* If thrown error is TYPE_MISMATCH from the Scanner, it should be returned.
|
|
25
|
+
*/
|
|
26
|
+
const error = await this.provider
|
|
27
|
+
.put(location, pipe)
|
|
28
|
+
.catch((error) => {
|
|
29
|
+
if (error === scanner.error)
|
|
30
|
+
return error;
|
|
31
|
+
else
|
|
32
|
+
throw error;
|
|
33
|
+
});
|
|
34
|
+
if (error instanceof Error)
|
|
35
|
+
return error;
|
|
36
|
+
const metadata = {
|
|
37
|
+
id,
|
|
38
|
+
size: scanner.size,
|
|
39
|
+
type: scanner.type,
|
|
40
|
+
checksum: scanner.digest(),
|
|
41
|
+
created: new Date().toISOString(),
|
|
42
|
+
attributes: options?.attributes ?? {}
|
|
43
|
+
};
|
|
44
|
+
if (options?.origin !== undefined)
|
|
45
|
+
metadata.attributes.origin = options.origin;
|
|
46
|
+
await this.provider.commit(location, metadata);
|
|
47
|
+
return metadata;
|
|
48
|
+
});
|
|
33
49
|
}
|
|
34
|
-
async
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
async get(path, options) {
|
|
51
|
+
return await console.span(this.span('get', dirname(path)), async () => {
|
|
52
|
+
const location = this.locate(path);
|
|
53
|
+
return await this.provider.get(location, options);
|
|
54
|
+
});
|
|
37
55
|
}
|
|
38
|
-
async
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return ERR_NOT_FOUND;
|
|
51
|
-
else
|
|
52
|
-
return stream;
|
|
56
|
+
async head(path) {
|
|
57
|
+
return await console.span(this.span('head', dirname(path)), async () => {
|
|
58
|
+
const id = basename(path).split('.')[0];
|
|
59
|
+
const location = this.locate(path);
|
|
60
|
+
const metadata = await this.provider.head(location);
|
|
61
|
+
if (metadata instanceof Error)
|
|
62
|
+
return metadata;
|
|
63
|
+
return {
|
|
64
|
+
id,
|
|
65
|
+
...metadata
|
|
66
|
+
};
|
|
67
|
+
});
|
|
53
68
|
}
|
|
54
69
|
async delete(path) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
await Promise.all([
|
|
60
|
-
this.provider.delete(paths.metafile),
|
|
61
|
-
this.provider.delete(paths.vardir)
|
|
62
|
-
]);
|
|
63
|
-
}
|
|
64
|
-
async move(path, to) {
|
|
65
|
-
const source = this.destruct(path);
|
|
66
|
-
const rel = to.startsWith('.');
|
|
67
|
-
const dir = to.endsWith('/');
|
|
68
|
-
if (rel)
|
|
69
|
-
to = node_path_1.posix.resolve(source.rel + '/', to);
|
|
70
|
-
if (dir)
|
|
71
|
-
to = node_path_1.posix.join(to, source.ent);
|
|
72
|
-
const target = this.destruct(to);
|
|
73
|
-
await Promise.all([
|
|
74
|
-
this.provider.move(source.metafile, target.metafile),
|
|
75
|
-
this.provider.moveDir(source.vardir, target.vardir)
|
|
76
|
-
]);
|
|
77
|
-
}
|
|
78
|
-
async diversify(path, name, stream) {
|
|
79
|
-
const scanner = new Scanner_1.Scanner();
|
|
80
|
-
const pipe = stream.pipe(scanner);
|
|
81
|
-
await this.provider.put(node_path_1.posix.join(ENTRIES_ROOT, path), name, pipe);
|
|
82
|
-
if (scanner.error !== null)
|
|
83
|
-
return scanner.error;
|
|
84
|
-
const { size, type } = scanner;
|
|
85
|
-
const entry = await this.get(path);
|
|
86
|
-
if (entry instanceof Error)
|
|
87
|
-
return entry;
|
|
88
|
-
entry.variants = entry.variants.filter((variant) => variant.name !== name);
|
|
89
|
-
entry.variants.push({ name, size, type });
|
|
90
|
-
await this.save(path, entry);
|
|
70
|
+
return await console.span(this.span('delete', dirname(path)), async () => {
|
|
71
|
+
const location = this.locate(path);
|
|
72
|
+
return await this.provider.delete(location);
|
|
73
|
+
});
|
|
91
74
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (entry instanceof Error)
|
|
95
|
-
return entry;
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
97
|
-
if (value === undefined)
|
|
98
|
-
delete entry.meta[key];
|
|
99
|
-
else
|
|
100
|
-
entry.meta[key] = value;
|
|
101
|
-
await this.save(path, entry);
|
|
75
|
+
path() {
|
|
76
|
+
return this.provider.root ?? null;
|
|
102
77
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
await this.provider.put(TEMP, tempname, stream);
|
|
106
|
-
return tempname;
|
|
78
|
+
locate(...rel) {
|
|
79
|
+
return join(ENTRIES, ...rel);
|
|
107
80
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
size,
|
|
118
|
-
type,
|
|
119
|
-
created: Date.now(),
|
|
120
|
-
variants: [],
|
|
121
|
-
meta
|
|
81
|
+
span(method, path) {
|
|
82
|
+
return {
|
|
83
|
+
name: `${method} ${this.scope?.name ?? 'storage'}`,
|
|
84
|
+
kind: 'client',
|
|
85
|
+
attributes: {
|
|
86
|
+
...(this.scope === undefined ? {} : { provider: this.scope.provider }),
|
|
87
|
+
path
|
|
88
|
+
},
|
|
89
|
+
measure: operation(method, this.scope)
|
|
122
90
|
};
|
|
123
|
-
const metafile = node_path_1.posix.join(path, entry.id);
|
|
124
|
-
const existing = await this.get(metafile);
|
|
125
|
-
if (existing instanceof Error)
|
|
126
|
-
await this.save(metafile, entry);
|
|
127
|
-
return entry;
|
|
128
|
-
}
|
|
129
|
-
async save(path, entry) {
|
|
130
|
-
const paths = this.destruct(path);
|
|
131
|
-
const stream = node_stream_1.Readable.from((0, msgpackr_1.encode)(entry));
|
|
132
|
-
await this.provider.put(paths.metadir, paths.ent, stream);
|
|
133
|
-
}
|
|
134
|
-
parse(path) {
|
|
135
|
-
const [last, ...segments] = path.split('/').reverse();
|
|
136
|
-
const [id, ...rest] = last.split('.');
|
|
137
|
-
const variant = rest.length > 0 ? rest.join('.') : null;
|
|
138
|
-
const rel = segments.reverse().join('/');
|
|
139
|
-
return { rel, id, variant };
|
|
140
|
-
}
|
|
141
|
-
destruct(path) {
|
|
142
|
-
const rel = node_path_1.posix.dirname(path);
|
|
143
|
-
const dir = node_path_1.posix.join(ENTRIES_ROOT, rel);
|
|
144
|
-
const ent = node_path_1.posix.basename(path);
|
|
145
|
-
const metadir = node_path_1.posix.join(dir, ENTRIES_DIR);
|
|
146
|
-
const metafile = node_path_1.posix.join(metadir, ent);
|
|
147
|
-
const vardir = node_path_1.posix.join(dir, ent);
|
|
148
|
-
return { rel, dir, ent, metadir, metafile, vardir };
|
|
149
91
|
}
|
|
150
92
|
}
|
|
151
|
-
|
|
152
|
-
const ERR_NOT_FOUND = (0, error_value_1.Err)('NOT_FOUND');
|
|
153
|
-
const TEMP = '/temp';
|
|
154
|
-
const BLOBs = '/blobs';
|
|
155
|
-
const ENTRIES_ROOT = '/entries';
|
|
156
|
-
const ENTRIES_DIR = '.meta';
|
|
93
|
+
const ENTRIES = '/';
|
|
157
94
|
//# sourceMappingURL=Storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storage.js","sourceRoot":"","sources":["../source/Storage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Storage.js","sourceRoot":"","sources":["../source/Storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,OAAO,EAAoB,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAM7C,MAAM,OAAO,OAAO;IACD,QAAQ,CAAG;IACX,KAAK,CAAQ;IAE9B,YAAmB,QAAW,EAAE,KAAa;QAC3C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAA;IAC9B,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,MAAgB,EAAE,OAAiB;QAChE,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE;YAC3D,MAAM,O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,QAAQ,CAAC,CAAA;QAC7C,CAAC,CAAC,CAAA;IACJ,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAA;IACnC,CAAC;IAEO,MAAM,CAAC,GAAG,GAAa;QAC7B,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC,CAAA;IAC9B,CAAC;IAEO,IAAI,CAAC,MAAc,EAAE,IAAY;QACvC,OAAO;YACL,IAAI,EAAE,GAAG,MAAM,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI,IAAI,SAAS,EAAE;YAClD,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACtE,IAAI;aACL;YACD,OAAO,EAAE,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC;SACvC,CAAA;IACH,CAAC;CACF;AAED,MAAM,OAAO,GAAG,GAAG,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../source/errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,aAAc,SAAQ,KAAK;IACjD,IAAI,GAAG,WAAW,CAAA;CACnC,CAAC,EAAE,CAAA"}
|
package/transpiled/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Factory } from './Factory';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export type
|
|
1
|
+
export { Factory } from './Factory.ts';
|
|
2
|
+
export type { Entry, Stream } from './Entry.ts';
|
|
3
|
+
export type { Storage } from './Storage.ts';
|
|
4
|
+
export type * from './providers/index.ts';
|
package/transpiled/index.js
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.manifest = exports.deployment = exports.Factory = void 0;
|
|
4
|
-
var Factory_1 = require("./Factory");
|
|
5
|
-
Object.defineProperty(exports, "Factory", { enumerable: true, get: function () { return Factory_1.Factory; } });
|
|
6
|
-
var deployment_1 = require("./deployment");
|
|
7
|
-
Object.defineProperty(exports, "deployment", { enumerable: true, get: function () { return deployment_1.deployment; } });
|
|
8
|
-
var manifest_1 = require("./manifest");
|
|
9
|
-
Object.defineProperty(exports, "manifest", { enumerable: true, get: function () { return manifest_1.manifest; } });
|
|
1
|
+
export { Factory } from './Factory.js';
|
|
10
2
|
//# sourceMappingURL=index.js.map
|
package/transpiled/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { registry } from 'openspan';
|
|
2
|
+
/**
|
|
3
|
+
* What a BLOB storage measures. Network I/O to a third party, and nothing else reports it.
|
|
4
|
+
*
|
|
5
|
+
* `storage` is the name the component declared it under and `provider` is what stands behind it:
|
|
6
|
+
* a component declares several and uses them for different things, so the provider alone does not
|
|
7
|
+
* say which one was slow where two declarations share one.
|
|
8
|
+
*/
|
|
9
|
+
const meters = registry();
|
|
10
|
+
/** Wider than a query's, because a third party over the network is slower than a database. */
|
|
11
|
+
const DURATIONS = [0.01, 0.05, 0.1, 0.5, 1, 2.5, 5, 10, 30];
|
|
12
|
+
const duration = meters.histogram('toa.blob.operation.duration', { buckets: DURATIONS, unit: 's' }, { storage: null, provider: null, operation: null });
|
|
13
|
+
export function operation(method, scope) {
|
|
14
|
+
return {
|
|
15
|
+
histogram: duration,
|
|
16
|
+
labels: {
|
|
17
|
+
storage: scope?.name,
|
|
18
|
+
provider: scope?.provider,
|
|
19
|
+
operation: method
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=measurements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measurements.js","sourceRoot":"","sources":["../source/measurements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAInC;;;;;;GAMG;AACH,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAA;AAEzB,8FAA8F;AAC9F,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;AAE3D,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAC/B,6BAA6B,EAC7B,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,EACjC,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CACnD,CAAA;AAED,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,KAAa;IACrD,OAAO;QACL,SAAS,EAAE,QAAQ;QACnB,MAAM,EAAE;YACN,OAAO,EAAE,KAAK,EAAE,IAAI;YACpB,QAAQ,EAAE,KAAK,EAAE,QAAQ;YACzB,SAAS,EAAE,MAAM;SAClB;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import { Provider } from '../Provider.ts';
|
|
3
|
+
import type { Maybe } from '@toa.io/core/types';
|
|
4
|
+
import type { Metadata, Stream } from '../Entry.ts';
|
|
5
|
+
import type { Secret, Secrets } from '../Secrets.ts';
|
|
6
|
+
import type { TransformationOptions } from 'cloudinary';
|
|
7
|
+
export type CloudinarySecrets = Secrets<'API_KEY' | 'API_SECRET'>;
|
|
8
|
+
export declare class Cloudinary extends Provider<CloudinaryOptions> {
|
|
9
|
+
static readonly SECRETS: readonly Secret[];
|
|
10
|
+
private readonly type;
|
|
11
|
+
private readonly eager;
|
|
12
|
+
private readonly transformations;
|
|
13
|
+
private readonly config;
|
|
14
|
+
private readonly prefix;
|
|
15
|
+
constructor(options: CloudinaryOptions, secrets?: CloudinarySecrets);
|
|
16
|
+
get(path: string, options?: GetOptions): Promise<Maybe<Stream>>;
|
|
17
|
+
head(path: string): Promise<Maybe<Metadata>>;
|
|
18
|
+
put(path: string, stream: Readable): Promise<void>;
|
|
19
|
+
commit(): Promise<void>;
|
|
20
|
+
delete(path: string): Promise<void>;
|
|
21
|
+
move(from: string, to: string): Promise<void | Error>;
|
|
22
|
+
private fetch;
|
|
23
|
+
private url;
|
|
24
|
+
private toTransformation;
|
|
25
|
+
private mapTransformation;
|
|
26
|
+
private metadata;
|
|
27
|
+
private cloudinary;
|
|
28
|
+
}
|
|
29
|
+
interface GetOptions {
|
|
30
|
+
agent?: string;
|
|
31
|
+
range?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface CloudinaryOptions {
|
|
34
|
+
environment: string;
|
|
35
|
+
type: StorageType;
|
|
36
|
+
prefix?: string;
|
|
37
|
+
eager?: TransformationOptions[];
|
|
38
|
+
transformations?: TransformationDeclaration[];
|
|
39
|
+
}
|
|
40
|
+
type TransformationDeclaration = Omit<Transformation, 'extension'> & {
|
|
41
|
+
extension: string;
|
|
42
|
+
};
|
|
43
|
+
interface Transformation {
|
|
44
|
+
extension: RegExp;
|
|
45
|
+
condition?: string;
|
|
46
|
+
transformation: Record<string, unknown> | Array<Record<string, unknown>>;
|
|
47
|
+
optional?: boolean;
|
|
48
|
+
}
|
|
49
|
+
type StorageType = 'image' | 'video';
|
|
50
|
+
export {};
|