@toa.io/extensions.storages 1.0.0-alpha.7 → 1.0.0-alpha.78
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 +8 -8
- package/readme.md +32 -22
- 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 +1 -0
- package/source/Factory.ts +7 -4
- package/source/Provider.ts +5 -0
- package/source/Scanner.ts +46 -17
- package/source/Storage.test.ts +126 -76
- package/source/Storage.ts +92 -91
- package/source/deployment.ts +38 -7
- package/source/providers/FileSystem.test.ts +6 -0
- package/source/providers/FileSystem.ts +15 -2
- package/source/providers/Memory.ts +21 -7
- package/source/providers/S3.test.ts +1 -0
- package/source/providers/S3.ts +36 -6
- package/source/providers/index.test.ts +10 -0
- package/source/test/arny.jpg +0 -0
- package/source/test/sample.avi +0 -0
- package/source/test/sample.svg +4 -0
- package/source/test/sample.wav +0 -0
- package/transpiled/Entry.d.ts +1 -0
- package/transpiled/Factory.js +5 -3
- package/transpiled/Factory.js.map +1 -1
- package/transpiled/Provider.d.ts +3 -0
- package/transpiled/Provider.js +1 -0
- package/transpiled/Provider.js.map +1 -1
- package/transpiled/Scanner.d.ts +3 -1
- package/transpiled/Scanner.js +36 -15
- package/transpiled/Scanner.js.map +1 -1
- package/transpiled/Storage.d.ts +6 -6
- package/transpiled/Storage.js +66 -78
- package/transpiled/Storage.js.map +1 -1
- package/transpiled/deployment.d.ts +1 -1
- package/transpiled/deployment.js +30 -7
- package/transpiled/deployment.js.map +1 -1
- package/transpiled/providers/FileSystem.d.ts +4 -1
- package/transpiled/providers/FileSystem.js +10 -1
- package/transpiled/providers/FileSystem.js.map +1 -1
- package/transpiled/providers/Memory.d.ts +2 -0
- package/transpiled/providers/Memory.js +13 -1
- package/transpiled/providers/Memory.js.map +1 -1
- package/transpiled/providers/S3.d.ts +3 -0
- package/transpiled/providers/S3.js +23 -4
- package/transpiled/providers/S3.js.map +1 -1
- package/transpiled/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../source/Provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAAqC;AASrC,MAAsB,QAAQ;IACrB,MAAM,CAAU,OAAO,GAA8B,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../source/Provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAAqC;AASrC,MAAsB,QAAQ;IACrB,MAAM,CAAU,OAAO,GAA8B,EAAE,CAAA;IAC9C,IAAI,GAAkB,IAAI,CAAA;IAE1C,YAAoB,CAAU,EAAE,OAAyB;QACvD,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO;YACzD,MAAM,CAAC,EAAE,CAAC,QAAQ,IAAI,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,SAAS,EAAE,mBAAmB,IAAI,GAAG,CAAC,CAAA;IACpF,CAAC;;AAPH,4BAoBC"}
|
package/transpiled/Scanner.d.ts
CHANGED
|
@@ -8,8 +8,9 @@ export declare class Scanner extends PassThrough {
|
|
|
8
8
|
private readonly hash;
|
|
9
9
|
private readonly claim?;
|
|
10
10
|
private readonly accept?;
|
|
11
|
+
private readonly limit?;
|
|
11
12
|
private position;
|
|
12
|
-
private
|
|
13
|
+
private completed;
|
|
13
14
|
private readonly chunks;
|
|
14
15
|
constructor(control?: ScanOptions);
|
|
15
16
|
digest(): string;
|
|
@@ -23,4 +24,5 @@ export declare class Scanner extends PassThrough {
|
|
|
23
24
|
export interface ScanOptions {
|
|
24
25
|
claim?: string;
|
|
25
26
|
accept?: string;
|
|
27
|
+
limit?: number;
|
|
26
28
|
}
|
package/transpiled/Scanner.js
CHANGED
|
@@ -12,13 +12,15 @@ class Scanner extends node_stream_1.PassThrough {
|
|
|
12
12
|
hash = (0, node_crypto_1.createHash)('md5');
|
|
13
13
|
claim;
|
|
14
14
|
accept;
|
|
15
|
+
limit;
|
|
15
16
|
position = 0;
|
|
16
|
-
|
|
17
|
+
completed = false;
|
|
17
18
|
chunks = [];
|
|
18
19
|
constructor(control) {
|
|
19
20
|
super();
|
|
20
21
|
this.claim = control?.claim;
|
|
21
22
|
this.accept = control?.accept;
|
|
23
|
+
this.limit = control?.limit;
|
|
22
24
|
}
|
|
23
25
|
digest() {
|
|
24
26
|
return this.hash.digest('hex');
|
|
@@ -30,7 +32,7 @@ class Scanner extends node_stream_1.PassThrough {
|
|
|
30
32
|
process = (buffer) => {
|
|
31
33
|
this.size += buffer.length;
|
|
32
34
|
this.hash.update(buffer);
|
|
33
|
-
if (this.
|
|
35
|
+
if (this.completed)
|
|
34
36
|
return;
|
|
35
37
|
if (this.position + buffer.length > HEADER_SIZE)
|
|
36
38
|
buffer = buffer.subarray(0, HEADER_SIZE - this.position);
|
|
@@ -38,18 +40,25 @@ class Scanner extends node_stream_1.PassThrough {
|
|
|
38
40
|
this.position += buffer.length;
|
|
39
41
|
if (this.position === HEADER_SIZE)
|
|
40
42
|
this.complete();
|
|
43
|
+
if (this.limit !== undefined && this.size > this.limit)
|
|
44
|
+
this.interrupt(ERR_LIMIT_EXCEEDED);
|
|
41
45
|
};
|
|
42
46
|
complete() {
|
|
43
47
|
const header = Buffer.concat(this.chunks).toString('hex');
|
|
44
48
|
const signature = SIGNATURES
|
|
45
|
-
.find(({ hex,
|
|
49
|
+
.find(({ off, hex, expression }) => {
|
|
50
|
+
const sig = header.slice(off, off + hex.length);
|
|
51
|
+
return expression === undefined
|
|
52
|
+
? sig === hex
|
|
53
|
+
: expression.test(sig);
|
|
54
|
+
});
|
|
46
55
|
const type = signature?.type ?? this.claim;
|
|
47
56
|
if (type !== undefined) {
|
|
48
57
|
this.match(type);
|
|
49
58
|
this.type = type;
|
|
50
59
|
}
|
|
51
60
|
this.verify(signature);
|
|
52
|
-
this.
|
|
61
|
+
this.completed = true;
|
|
53
62
|
}
|
|
54
63
|
verify(signature) {
|
|
55
64
|
if (this.claim === undefined || this.claim === 'application/octet-stream')
|
|
@@ -68,6 +77,7 @@ class Scanner extends node_stream_1.PassThrough {
|
|
|
68
77
|
this.interrupt(ERR_NOT_ACCEPTABLE);
|
|
69
78
|
}
|
|
70
79
|
interrupt(error) {
|
|
80
|
+
this.completed = true;
|
|
71
81
|
this.error = error;
|
|
72
82
|
this.end();
|
|
73
83
|
}
|
|
@@ -75,24 +85,35 @@ class Scanner extends node_stream_1.PassThrough {
|
|
|
75
85
|
exports.Scanner = Scanner;
|
|
76
86
|
// https://en.wikipedia.org/wiki/List_of_file_signatures
|
|
77
87
|
const SIGNATURES = [
|
|
78
|
-
{ hex: '
|
|
79
|
-
{ hex: '
|
|
80
|
-
{ hex: '
|
|
81
|
-
{ hex: '
|
|
82
|
-
{ hex: '
|
|
83
|
-
{ hex: '
|
|
84
|
-
{ hex: '
|
|
85
|
-
{ hex: '
|
|
86
|
-
{ hex: '
|
|
87
|
-
{ hex: '
|
|
88
|
+
{ hex: 'ff d8 ff e0', off: 0, type: 'image/jpeg' },
|
|
89
|
+
{ hex: 'ff d8 ff e1', off: 0, type: 'image/jpeg' },
|
|
90
|
+
{ hex: 'ff d8 ff e2', off: 0, type: 'image/jpeg' },
|
|
91
|
+
{ hex: 'ff d8 ff ee', off: 0, type: 'image/jpeg' },
|
|
92
|
+
{ hex: 'ff d8 ff db', off: 0, type: 'image/jpeg' },
|
|
93
|
+
{ hex: '89 50 4e 47', off: 0, type: 'image/png' },
|
|
94
|
+
{ hex: '47 49 46 38', off: 0, type: 'image/gif' },
|
|
95
|
+
{ hex: '52 49 46 46 ?? ?? ?? ?? 57 45 42 50', off: 0, type: 'image/webp' },
|
|
96
|
+
{ hex: '4a 58 4c 20 0d 0a 87 0a', off: 8, type: 'image/jxl' },
|
|
97
|
+
{ hex: '66 74 79 70 68 65 69 63', off: 8, type: 'image/heic' },
|
|
98
|
+
{ hex: '66 74 79 70 61 76 69 66', off: 8, type: 'image/avif' },
|
|
99
|
+
{ hex: '52 49 46 46 ?? ?? ?? ?? 41 56 49 20', off: 0, type: 'video/avi' },
|
|
100
|
+
{ hex: '52 49 46 46 ?? ?? ?? ?? 57 41 56 45', off: 0, type: 'audio/wav' }
|
|
88
101
|
/*
|
|
89
102
|
When adding a new signature, include a copyright-free sample file in the `.tests` directory
|
|
90
103
|
and update the 'signatures' test group in `Storage.test.ts`.
|
|
91
104
|
*/
|
|
92
|
-
]
|
|
105
|
+
].map((signature) => {
|
|
106
|
+
signature.hex = signature.hex.replaceAll(' ', '');
|
|
107
|
+
if (signature.hex.includes('??')) {
|
|
108
|
+
const expression = signature.hex.replaceAll(/(?<wildcards>\?{1,24})/g, (_, wildcards) => `[0-9a-f]{${wildcards.length}}`);
|
|
109
|
+
signature.expression = new RegExp(expression, 'i');
|
|
110
|
+
}
|
|
111
|
+
return signature;
|
|
112
|
+
});
|
|
93
113
|
const HEADER_SIZE = SIGNATURES
|
|
94
114
|
.reduce((max, { off, hex }) => Math.max(max, off + hex.length), 0) / 2;
|
|
95
115
|
const KNOWN_TYPES = new Set(SIGNATURES.map(({ type }) => type));
|
|
96
116
|
const ERR_TYPE_MISMATCH = (0, error_value_1.Err)('TYPE_MISMATCH');
|
|
97
117
|
const ERR_NOT_ACCEPTABLE = (0, error_value_1.Err)('NOT_ACCEPTABLE');
|
|
118
|
+
const ERR_LIMIT_EXCEEDED = (0, error_value_1.Err)('LIMIT_EXCEEDED');
|
|
98
119
|
//# sourceMappingURL=Scanner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Scanner.js","sourceRoot":"","sources":["../source/Scanner.ts"],"names":[],"mappings":";;;AAAA,6CAAiE;AACjE,6CAAwC;AACxC,yCAAyC;AACzC,6CAAiC;AAEjC,MAAa,OAAQ,SAAQ,yBAAW;IAC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C,GAAG,CAAC,UAAU,CAAC,yBAAyB,EACnE,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC,YAAY,SAAS,CAAC,MAAM,GAAG,CAAC,CAAA;QAEpD,SAAS,CAAC,UAAU,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;IACpD,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAC,CAAA;AAEF,MAAM,WAAW,GAAG,UAAU;KAC3B,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;AAExE,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,IAAA,iBAAG,EAAC,eAAe,CAAC,CAAA;AAC9C,MAAM,kBAAkB,GAAG,IAAA,iBAAG,EAAC,gBAAgB,CAAC,CAAA;AAChD,MAAM,kBAAkB,GAAG,IAAA,iBAAG,EAAC,gBAAgB,CAAC,CAAA"}
|
package/transpiled/Storage.d.ts
CHANGED
|
@@ -8,24 +8,24 @@ export declare class Storage {
|
|
|
8
8
|
constructor(provider: Provider);
|
|
9
9
|
put(path: string, stream: Readable, options?: Options): Maybe<Entry>;
|
|
10
10
|
get(path: string): Maybe<Entry>;
|
|
11
|
+
list(path: string): Promise<string[]>;
|
|
11
12
|
fetch(path: string): Maybe<Readable>;
|
|
12
13
|
delete(path: string): Maybe<void>;
|
|
13
|
-
|
|
14
|
-
permute(path: string, ids: string[]): Maybe<void>;
|
|
15
|
-
conceal(path: string): Maybe<void>;
|
|
16
|
-
reveal(path: string): Maybe<void>;
|
|
14
|
+
move(path: string, to: string): Maybe<void>;
|
|
17
15
|
diversify(path: string, name: string, stream: Readable): Maybe<void>;
|
|
18
|
-
annotate(path: string, key: string, value?: unknown): Maybe<void>;
|
|
16
|
+
annotate(path: string, key: string | Record<string, unknown>, value?: unknown): Maybe<void>;
|
|
17
|
+
path(): string | null;
|
|
19
18
|
private transit;
|
|
20
19
|
private persist;
|
|
21
20
|
private create;
|
|
22
21
|
private save;
|
|
23
|
-
private enroll;
|
|
24
22
|
private parse;
|
|
23
|
+
private destruct;
|
|
25
24
|
}
|
|
26
25
|
type Maybe<T> = Promise<T | Error>;
|
|
27
26
|
type Meta = Record<string, string>;
|
|
28
27
|
interface Options extends ScanOptions {
|
|
28
|
+
origin?: string;
|
|
29
29
|
meta?: Meta;
|
|
30
30
|
}
|
|
31
31
|
export type Storages = Record<string, Storage>;
|
package/transpiled/Storage.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Storage = void 0;
|
|
4
4
|
const node_stream_1 = require("node:stream");
|
|
5
5
|
const node_path_1 = require("node:path");
|
|
6
|
+
const consumers_1 = require("node:stream/consumers");
|
|
6
7
|
const msgpackr_1 = require("msgpackr");
|
|
7
8
|
const generic_1 = require("@toa.io/generic");
|
|
8
9
|
const error_value_1 = require("error-value");
|
|
@@ -20,15 +21,28 @@ class Storage {
|
|
|
20
21
|
return scanner.error;
|
|
21
22
|
const id = scanner.digest();
|
|
22
23
|
await this.persist(tempname, id);
|
|
23
|
-
|
|
24
|
+
const entry = {
|
|
25
|
+
id,
|
|
26
|
+
size: scanner.size,
|
|
27
|
+
type: scanner.type,
|
|
28
|
+
origin: options?.origin,
|
|
29
|
+
created: Date.now(),
|
|
30
|
+
variants: [],
|
|
31
|
+
meta: options?.meta ?? {}
|
|
32
|
+
};
|
|
33
|
+
return await this.create(path, entry);
|
|
24
34
|
}
|
|
25
35
|
async get(path) {
|
|
26
|
-
const
|
|
27
|
-
const result = await this.provider.get(
|
|
36
|
+
const paths = this.destruct(path);
|
|
37
|
+
const result = await this.provider.get(paths.metafile);
|
|
28
38
|
if (result === null)
|
|
29
39
|
return ERR_NOT_FOUND;
|
|
30
40
|
else
|
|
31
|
-
return (0, msgpackr_1.decode)(await (0,
|
|
41
|
+
return (0, msgpackr_1.decode)(await (0, consumers_1.buffer)(result));
|
|
42
|
+
}
|
|
43
|
+
async list(path) {
|
|
44
|
+
const dir = node_path_1.posix.join(ENTRIES_ROOT, path, ENTRIES_DIR);
|
|
45
|
+
return await this.provider.list(dir);
|
|
32
46
|
}
|
|
33
47
|
async fetch(path) {
|
|
34
48
|
const { rel, id, variant } = this.parse(path);
|
|
@@ -39,7 +53,7 @@ class Storage {
|
|
|
39
53
|
}
|
|
40
54
|
const blob = variant === null
|
|
41
55
|
? node_path_1.posix.join(BLOBs, id)
|
|
42
|
-
: node_path_1.posix.join(
|
|
56
|
+
: node_path_1.posix.join(ENTRIES_ROOT, rel, id, variant);
|
|
43
57
|
const stream = await this.provider.get(blob);
|
|
44
58
|
if (stream === null)
|
|
45
59
|
return ERR_NOT_FOUND;
|
|
@@ -50,43 +64,30 @@ class Storage {
|
|
|
50
64
|
const entry = await this.get(path);
|
|
51
65
|
if (entry instanceof Error)
|
|
52
66
|
return entry;
|
|
53
|
-
|
|
54
|
-
await
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
async conceal(path) {
|
|
73
|
-
const { id, rel } = this.parse(path);
|
|
74
|
-
const dir = node_path_1.posix.join(ENTRIES, rel);
|
|
75
|
-
const list = await this.list(rel);
|
|
76
|
-
const index = list.indexOf(id);
|
|
77
|
-
if (index === -1)
|
|
78
|
-
return ERR_NOT_FOUND;
|
|
79
|
-
list.splice(index, 1);
|
|
80
|
-
await this.provider.put(dir, LIST, node_stream_1.Readable.from((0, msgpackr_1.encode)(list)));
|
|
81
|
-
}
|
|
82
|
-
async reveal(path) {
|
|
83
|
-
const { id, rel } = this.parse(path);
|
|
84
|
-
return await this.enroll(rel, id);
|
|
67
|
+
const paths = this.destruct(path);
|
|
68
|
+
await Promise.all([
|
|
69
|
+
this.provider.delete(paths.metafile),
|
|
70
|
+
this.provider.delete(paths.vardir)
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
async move(path, to) {
|
|
74
|
+
const source = this.destruct(path);
|
|
75
|
+
const rel = to.startsWith('.');
|
|
76
|
+
const dir = to.endsWith('/');
|
|
77
|
+
if (rel)
|
|
78
|
+
to = node_path_1.posix.resolve(source.rel + '/', to);
|
|
79
|
+
if (dir)
|
|
80
|
+
to = node_path_1.posix.join(to, source.ent);
|
|
81
|
+
const target = this.destruct(to);
|
|
82
|
+
await Promise.all([
|
|
83
|
+
this.provider.move(source.metafile, target.metafile),
|
|
84
|
+
this.provider.moveDir(source.vardir, target.vardir)
|
|
85
|
+
]);
|
|
85
86
|
}
|
|
86
87
|
async diversify(path, name, stream) {
|
|
87
88
|
const scanner = new Scanner_1.Scanner();
|
|
88
89
|
const pipe = stream.pipe(scanner);
|
|
89
|
-
await this.provider.put(node_path_1.posix.join(
|
|
90
|
+
await this.provider.put(node_path_1.posix.join(ENTRIES_ROOT, path), name, pipe);
|
|
90
91
|
if (scanner.error !== null)
|
|
91
92
|
return scanner.error;
|
|
92
93
|
const { size, type } = scanner;
|
|
@@ -101,13 +102,19 @@ class Storage {
|
|
|
101
102
|
const entry = await this.get(path);
|
|
102
103
|
if (entry instanceof Error)
|
|
103
104
|
return entry;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
const update = typeof key === 'string'
|
|
106
|
+
? { [key]: value }
|
|
107
|
+
: key;
|
|
108
|
+
Object.assign(entry.meta, update);
|
|
109
|
+
// filter undefined values
|
|
110
|
+
for (const key of Object.keys(entry.meta))
|
|
111
|
+
if (entry.meta[key] === undefined)
|
|
112
|
+
delete entry.meta[key];
|
|
109
113
|
await this.save(path, entry);
|
|
110
114
|
}
|
|
115
|
+
path() {
|
|
116
|
+
return this.provider.path;
|
|
117
|
+
}
|
|
111
118
|
async transit(stream) {
|
|
112
119
|
const tempname = (0, generic_1.newid)();
|
|
113
120
|
await this.provider.put(TEMP, tempname, stream);
|
|
@@ -119,43 +126,17 @@ class Storage {
|
|
|
119
126
|
await this.provider.move(temp, blob);
|
|
120
127
|
}
|
|
121
128
|
// eslint-disable-next-line max-params
|
|
122
|
-
async create(path,
|
|
123
|
-
const entry = {
|
|
124
|
-
id,
|
|
125
|
-
size,
|
|
126
|
-
type,
|
|
127
|
-
created: Date.now(),
|
|
128
|
-
variants: [],
|
|
129
|
-
meta
|
|
130
|
-
};
|
|
129
|
+
async create(path, entry) {
|
|
131
130
|
const metafile = node_path_1.posix.join(path, entry.id);
|
|
132
131
|
const existing = await this.get(metafile);
|
|
133
132
|
if (existing instanceof Error)
|
|
134
133
|
await this.save(metafile, entry);
|
|
135
|
-
await this.enroll(path, id, true);
|
|
136
134
|
return entry;
|
|
137
135
|
}
|
|
138
|
-
async save(
|
|
139
|
-
const
|
|
140
|
-
const stream = node_stream_1.Readable.from(
|
|
141
|
-
await this.provider.put(
|
|
142
|
-
}
|
|
143
|
-
async enroll(path, id, addition = false) {
|
|
144
|
-
const dir = node_path_1.posix.join(ENTRIES, path);
|
|
145
|
-
const list = await this.list(path);
|
|
146
|
-
const index = list.indexOf(id);
|
|
147
|
-
if (index !== -1)
|
|
148
|
-
if (addition)
|
|
149
|
-
list.splice(index, 1);
|
|
150
|
-
else
|
|
151
|
-
return;
|
|
152
|
-
else if (!addition) {
|
|
153
|
-
const entry = await this.get(node_path_1.posix.join(path, id));
|
|
154
|
-
if (entry instanceof Error)
|
|
155
|
-
return entry;
|
|
156
|
-
}
|
|
157
|
-
list.push(id);
|
|
158
|
-
await this.provider.put(dir, LIST, node_stream_1.Readable.from((0, msgpackr_1.encode)(list)));
|
|
136
|
+
async save(path, entry) {
|
|
137
|
+
const paths = this.destruct(path);
|
|
138
|
+
const stream = node_stream_1.Readable.from((0, msgpackr_1.encode)(entry));
|
|
139
|
+
await this.provider.put(paths.metadir, paths.ent, stream);
|
|
159
140
|
}
|
|
160
141
|
parse(path) {
|
|
161
142
|
const [last, ...segments] = path.split('/').reverse();
|
|
@@ -164,13 +145,20 @@ class Storage {
|
|
|
164
145
|
const rel = segments.reverse().join('/');
|
|
165
146
|
return { rel, id, variant };
|
|
166
147
|
}
|
|
148
|
+
destruct(path) {
|
|
149
|
+
const rel = node_path_1.posix.dirname(path);
|
|
150
|
+
const dir = node_path_1.posix.join(ENTRIES_ROOT, rel);
|
|
151
|
+
const ent = node_path_1.posix.basename(path);
|
|
152
|
+
const metadir = node_path_1.posix.join(dir, ENTRIES_DIR);
|
|
153
|
+
const metafile = node_path_1.posix.join(metadir, ent);
|
|
154
|
+
const vardir = node_path_1.posix.join(dir, ent);
|
|
155
|
+
return { rel, dir, ent, metadir, metafile, vardir };
|
|
156
|
+
}
|
|
167
157
|
}
|
|
168
158
|
exports.Storage = Storage;
|
|
169
159
|
const ERR_NOT_FOUND = (0, error_value_1.Err)('NOT_FOUND');
|
|
170
|
-
const ERR_PERMUTATION_MISMATCH = (0, error_value_1.Err)('PERMUTATION_MISMATCH');
|
|
171
160
|
const TEMP = '/temp';
|
|
172
161
|
const BLOBs = '/blobs';
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
const META = '.meta';
|
|
162
|
+
const ENTRIES_ROOT = '/entries';
|
|
163
|
+
const ENTRIES_DIR = '.meta';
|
|
176
164
|
//# sourceMappingURL=Storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storage.js","sourceRoot":"","sources":["../source/Storage.ts"],"names":[],"mappings":";;;AAAA,6CAAsC;AACtC,yCAAiC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G,EAAE,WAAW,CAAC,CAAA;QAC5C,MAAM,QAAQ,GAAG,iBAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;QACzC,MAAM,MAAM,GAAG,iBAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAEnC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;IACrD,CAAC;CACF;AAzMD,0BAyMC;AAED,MAAM,aAAa,GAAG,IAAA,iBAAG,EAAC,WAAW,CAAC,CAAA;AAEtC,MAAM,IAAI,GAAG,OAAO,CAAA;AACpB,MAAM,KAAK,GAAG,QAAQ,CAAA;AACtB,MAAM,YAAY,GAAG,UAAU,CAAA;AAC/B,MAAM,WAAW,GAAG,OAAO,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Dependency } from '@toa.io/operations';
|
|
2
2
|
import type { context } from '@toa.io/norm';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const ENV_PREFIX = "TOA_STORAGES";
|
|
4
4
|
export declare function deployment(instances: Instance[], annotation: unknown): Dependency;
|
|
5
5
|
export type Instance = context.Dependency<string[]>;
|
package/transpiled/deployment.js
CHANGED
|
@@ -23,20 +23,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.deployment = exports.
|
|
26
|
+
exports.deployment = exports.ENV_PREFIX = void 0;
|
|
27
27
|
const assert = __importStar(require("node:assert"));
|
|
28
28
|
const generic_1 = require("@toa.io/generic");
|
|
29
29
|
const providers_1 = require("./providers");
|
|
30
30
|
const Annotation_1 = require("./Annotation");
|
|
31
|
-
exports.
|
|
31
|
+
exports.ENV_PREFIX = 'TOA_STORAGES';
|
|
32
32
|
function deployment(instances, annotation) {
|
|
33
33
|
validate(instances, annotation);
|
|
34
34
|
const value = (0, generic_1.encode)(annotation);
|
|
35
|
-
const pointer = { name: exports.
|
|
35
|
+
const pointer = { name: exports.ENV_PREFIX, value };
|
|
36
36
|
const secrets = getSecrets(annotation);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const mounts = getMounts(instances, annotation);
|
|
38
|
+
const dependency = { variables: { global: [pointer, ...secrets] } };
|
|
39
|
+
if (mounts !== null)
|
|
40
|
+
dependency.mounts = mounts;
|
|
41
|
+
return dependency;
|
|
40
42
|
}
|
|
41
43
|
exports.deployment = deployment;
|
|
42
44
|
function validate(instances, annotation) {
|
|
@@ -55,7 +57,7 @@ function getSecrets(annotation) {
|
|
|
55
57
|
const Provider = providers_1.providers[declaration.provider];
|
|
56
58
|
for (const secret of Provider.SECRETS)
|
|
57
59
|
secrets.push({
|
|
58
|
-
name: `${exports.
|
|
60
|
+
name: `${exports.ENV_PREFIX}_${name}_${secret.name}`.toUpperCase(),
|
|
59
61
|
secret: {
|
|
60
62
|
name: `toa-storages-${name}`,
|
|
61
63
|
key: secret.name,
|
|
@@ -65,4 +67,25 @@ function getSecrets(annotation) {
|
|
|
65
67
|
}
|
|
66
68
|
return secrets;
|
|
67
69
|
}
|
|
70
|
+
function getMounts(instances, annotation) {
|
|
71
|
+
let mounts = null;
|
|
72
|
+
for (const { locator, manifest } of instances)
|
|
73
|
+
for (const name of manifest) {
|
|
74
|
+
const declaration = annotation[name];
|
|
75
|
+
// eslint-disable-next-line max-depth
|
|
76
|
+
if (declaration.provider !== 'fs')
|
|
77
|
+
continue;
|
|
78
|
+
// eslint-disable-next-line max-depth
|
|
79
|
+
if (declaration.claim !== undefined) {
|
|
80
|
+
mounts ??= {};
|
|
81
|
+
mounts[locator.label] ??= [];
|
|
82
|
+
mounts[locator.label].push({
|
|
83
|
+
name,
|
|
84
|
+
path: declaration.path,
|
|
85
|
+
claim: declaration.claim
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return mounts;
|
|
90
|
+
}
|
|
68
91
|
//# sourceMappingURL=deployment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployment.js","sourceRoot":"","sources":["../source/deployment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAqC;AACrC,6CAAwC;AACxC,2CAAuC;AACvC,6CAAiD;AAKpC,QAAA,
|
|
1
|
+
{"version":3,"file":"deployment.js","sourceRoot":"","sources":["../source/deployment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAqC;AACrC,6CAAwC;AACxC,2CAAuC;AACvC,6CAAiD;AAKpC,QAAA,UAAU,GAAG,cAAc,CAAA;AAExC,SAAgB,UAAU,CAAE,SAAqB,EAAE,UAAmB;IACpE,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;IAE/B,MAAM,KAAK,GAAG,IAAA,gBAAM,EAAC,UAAU,CAAC,CAAA;IAChC,MAAM,OAAO,GAAa,EAAE,IAAI,EAAE,kBAAU,EAAE,KAAK,EAAE,CAAA;IACrD,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IACtC,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;IAE/C,MAAM,UAAU,GAAe,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,EAAE,EAAE,CAAA;IAE/E,IAAI,MAAM,KAAK,IAAI;QACjB,UAAU,CAAC,MAAM,GAAG,MAAM,CAAA;IAE5B,OAAO,UAAU,CAAA;AACnB,CAAC;AAdD,gCAcC;AAED,SAAS,QAAQ,CAAE,SAAqB,EAAE,UAAmB;IAC3D,IAAA,+BAAkB,EAAC,UAAU,CAAC,CAAA;IAE9B,KAAK,MAAM,QAAQ,IAAI,SAAS;QAC9B,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;AAClC,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IAAI,WAAW,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBACpC,MAAM,KAAK,EAAE,CAAA;gBACb,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;gBAE5B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;oBACzB,IAAI;oBACJ,IAAI,EAAE,WAAW,CAAC,IAAI;oBACtB,KAAK,EAAE,WAAW,CAAC,KAAK;iBACzB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IAEH,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -4,12 +4,15 @@ import { Provider } from '../Provider';
|
|
|
4
4
|
import type { ProviderSecrets } from '../Provider';
|
|
5
5
|
export interface FileSystemOptions {
|
|
6
6
|
path: string;
|
|
7
|
+
claim?: string;
|
|
7
8
|
}
|
|
8
9
|
export declare class FileSystem extends Provider<FileSystemOptions> {
|
|
9
|
-
|
|
10
|
+
readonly path: string;
|
|
10
11
|
constructor(options: FileSystemOptions, secrets?: ProviderSecrets);
|
|
11
12
|
get(path: string): Promise<Readable | null>;
|
|
13
|
+
list(path: string): Promise<string[]>;
|
|
12
14
|
put(rel: string, filename: string, stream: Readable): Promise<void>;
|
|
13
15
|
delete(path: string): Promise<void>;
|
|
14
16
|
move(from: string, to: string): Promise<void>;
|
|
17
|
+
moveDir(from: string, to: string): Promise<void>;
|
|
15
18
|
}
|
|
@@ -24,10 +24,16 @@ class FileSystem extends Provider_1.Provider {
|
|
|
24
24
|
throw err;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
async list(path) {
|
|
28
|
+
const dir = (0, node_path_1.join)(this.path, path);
|
|
29
|
+
return (await promises_1.default.readdir(dir, { withFileTypes: true }))
|
|
30
|
+
.filter((dirent) => dirent.isFile())
|
|
31
|
+
.map((dirent) => dirent.name);
|
|
32
|
+
}
|
|
27
33
|
async put(rel, filename, stream) {
|
|
28
34
|
const dir = (0, node_path_1.join)(this.path, rel);
|
|
29
35
|
const path = (0, node_path_1.join)(dir, filename);
|
|
30
|
-
await promises_1.default.mkdir(
|
|
36
|
+
await promises_1.default.mkdir(dir, { recursive: true });
|
|
31
37
|
await promises_1.default.writeFile(path, stream);
|
|
32
38
|
}
|
|
33
39
|
async delete(path) {
|
|
@@ -39,6 +45,9 @@ class FileSystem extends Provider_1.Provider {
|
|
|
39
45
|
await promises_1.default.mkdir((0, node_path_1.dirname)(to), { recursive: true });
|
|
40
46
|
await promises_1.default.rename(from, to);
|
|
41
47
|
}
|
|
48
|
+
async moveDir(from, to) {
|
|
49
|
+
await this.move(from, to).catch(() => null);
|
|
50
|
+
}
|
|
42
51
|
}
|
|
43
52
|
exports.FileSystem = FileSystem;
|
|
44
53
|
//# sourceMappingURL=FileSystem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystem.js","sourceRoot":"","sources":["../../source/providers/FileSystem.ts"],"names":[],"mappings":";;;;;;AACA,yCAAyC;AACzC,gEAAiC;AACjC,0CAAsC;
|
|
1
|
+
{"version":3,"file":"FileSystem.js","sourceRoot":"","sources":["../../source/providers/FileSystem.ts"],"names":[],"mappings":";;;;;;AACA,yCAAyC;AACzC,gEAAiC;AACjC,0CAAsC;AAQtC,MAAa,UAAW,SAAQ,mBAA2B;IAChC,IAAI,CAAQ;IAErC,YAAoB,OAA0B,EAAE,OAAyB;QACvE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAEvB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IAC1B,CAAC;IAEM,KAAK,CAAC,GAAG,CAAE,IAAY;QAC5B,IAAI,CAAC;YACH,MAAM,EAAE,GAAG,MAAM,kBAAE,CAAC,IAAI,CAAC,IAAA,gBAAI,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;YAE/C,OAAO,EAAE,CAAC,gBAAgB,EAAE,CAAA;QAC9B,CAAC;QAAC,OAAO,GAAG,EAA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EAAE,IAAI,CAAC,CAAA;QAC5B,EAAE,GAAG,IAAA,gBAAI,EAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QAExB,MAAM,kBAAE,CAAC,KAAK,CAAC,IAAA,mBAAO,EAAC,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAChD,MAAM,kBAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IAC3B,CAAC;IAEM,KAAK,CAAC,OAAO,CAAE,IAAY,EAAE,EAAU;QAC5C,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;IAC7C,CAAC;CACF;AApDD,gCAoDC"}
|
|
@@ -7,7 +7,9 @@ import { Provider } from '../Provider';
|
|
|
7
7
|
export declare class InMemory extends Provider {
|
|
8
8
|
private readonly storage;
|
|
9
9
|
get(path: string): Promise<Readable | null>;
|
|
10
|
+
list(path: string): Promise<string[]>;
|
|
10
11
|
put(path: string, filename: string, stream: Readable): Promise<void>;
|
|
11
12
|
delete(path: string): Promise<void>;
|
|
12
13
|
move(from: string, to: string): Promise<void>;
|
|
14
|
+
moveDir(from: string, to: string): Promise<void>;
|
|
13
15
|
}
|
|
@@ -40,6 +40,11 @@ class InMemory extends Provider_1.Provider {
|
|
|
40
40
|
return null;
|
|
41
41
|
return node_stream_1.Readable.from(data);
|
|
42
42
|
}
|
|
43
|
+
async list(path) {
|
|
44
|
+
return Array.from(this.storage.keys())
|
|
45
|
+
.filter((f) => node_path_1.posix.dirname(f) === path)
|
|
46
|
+
.map((f) => node_path_1.posix.basename(f));
|
|
47
|
+
}
|
|
43
48
|
async put(path, filename, stream) {
|
|
44
49
|
this.storage.set((0, node_path_1.join)(path, filename), await (0, consumers_1.buffer)(stream));
|
|
45
50
|
}
|
|
@@ -49,12 +54,19 @@ class InMemory extends Provider_1.Provider {
|
|
|
49
54
|
this.storage.delete(f);
|
|
50
55
|
}
|
|
51
56
|
async move(from, to) {
|
|
52
|
-
assert.notEqual(from, to, 'Source and destination are the same');
|
|
53
57
|
const buf = this.storage.get(from);
|
|
54
58
|
assert.ok(buf !== undefined, `File not found: ${from}`);
|
|
55
59
|
this.storage.set(to, buf);
|
|
56
60
|
this.storage.delete(from);
|
|
57
61
|
}
|
|
62
|
+
async moveDir(from, to) {
|
|
63
|
+
for (const f of this.storage.keys())
|
|
64
|
+
if (f.startsWith(from)) {
|
|
65
|
+
const toPath = to + f.slice(from.length);
|
|
66
|
+
this.storage.set(toPath, this.storage.get(f));
|
|
67
|
+
this.storage.delete(f);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
58
70
|
}
|
|
59
71
|
exports.InMemory = InMemory;
|
|
60
72
|
//# sourceMappingURL=Memory.js.map
|