@toa.io/extensions.storages 1.0.0-alpha.0 → 1.0.0-alpha.2
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 +12 -11
- package/readme.md +63 -19
- package/schemas/annotation.cos.yaml +10 -0
- package/schemas/fs.cos.yaml +9 -0
- package/schemas/mem.cos.yaml +6 -0
- package/schemas/s3.cos.yaml +16 -0
- package/schemas/test.cos.yaml +8 -0
- package/schemas/tmp.cos.yaml +9 -0
- package/source/Annotation.ts +39 -0
- package/source/Aspect.ts +6 -4
- package/source/Factory.ts +31 -28
- package/source/Provider.ts +30 -5
- package/source/Scanner.ts +3 -3
- package/source/Storage.test.ts +110 -105
- package/source/Storage.ts +13 -6
- package/source/deployment.ts +21 -29
- package/source/providers/Declaration.ts +10 -0
- package/source/providers/FileSystem.test.ts +1 -9
- package/source/providers/FileSystem.ts +20 -15
- package/source/providers/Memory.ts +41 -0
- package/source/providers/S3.test.ts +133 -0
- package/source/providers/S3.ts +114 -39
- package/source/providers/Temporary.ts +8 -6
- package/source/providers/Test.ts +8 -8
- package/source/providers/index.test.ts +24 -19
- package/source/providers/index.ts +10 -9
- package/source/providers/readme.md +1 -1
- package/source/schemas.test.ts +58 -0
- package/source/schemas.ts +15 -0
- package/source/test/util.ts +25 -54
- package/transpiled/Annotation.d.ts +3 -0
- package/transpiled/Annotation.js +57 -0
- package/transpiled/Annotation.js.map +1 -0
- package/transpiled/Aspect.d.ts +8 -0
- package/transpiled/Aspect.js +25 -0
- package/transpiled/Aspect.js.map +1 -0
- package/transpiled/Entry.d.ts +14 -0
- package/transpiled/Entry.js +3 -0
- package/transpiled/Entry.js.map +1 -0
- package/transpiled/Factory.d.ts +9 -0
- package/transpiled/Factory.js +53 -0
- package/transpiled/Factory.js.map +1 -0
- package/transpiled/Provider.d.ts +20 -0
- package/transpiled/Provider.js +36 -0
- package/transpiled/Provider.js.map +1 -0
- package/transpiled/Scanner.d.ts +26 -0
- package/transpiled/Scanner.js +98 -0
- package/transpiled/Scanner.js.map +1 -0
- package/transpiled/Storage.d.ts +32 -0
- package/transpiled/Storage.js +176 -0
- package/transpiled/Storage.js.map +1 -0
- package/transpiled/deployment.d.ts +5 -0
- package/transpiled/deployment.js +68 -0
- package/transpiled/deployment.js.map +1 -0
- package/transpiled/index.d.ts +4 -0
- package/transpiled/index.js +10 -0
- package/transpiled/index.js.map +1 -0
- package/transpiled/manifest.d.ts +1 -0
- package/transpiled/manifest.js +9 -0
- package/transpiled/manifest.js.map +1 -0
- package/transpiled/providers/Declaration.d.ts +14 -0
- package/transpiled/providers/Declaration.js +3 -0
- package/transpiled/providers/Declaration.js.map +1 -0
- package/transpiled/providers/FileSystem.d.ts +15 -0
- package/transpiled/providers/FileSystem.js +44 -0
- package/transpiled/providers/FileSystem.js.map +1 -0
- package/transpiled/providers/Memory.d.ts +13 -0
- package/transpiled/providers/Memory.js +60 -0
- package/transpiled/providers/Memory.js.map +1 -0
- package/transpiled/providers/S3.d.ts +27 -0
- package/transpiled/providers/S3.js +154 -0
- package/transpiled/providers/S3.js.map +1 -0
- package/transpiled/providers/Temporary.d.ts +8 -0
- package/transpiled/providers/Temporary.js +14 -0
- package/transpiled/providers/Temporary.js.map +1 -0
- package/transpiled/providers/Test.d.ts +6 -0
- package/transpiled/providers/Test.js +15 -0
- package/transpiled/providers/Test.js.map +1 -0
- package/transpiled/providers/index.d.ts +13 -0
- package/transpiled/providers/index.js +16 -0
- package/transpiled/providers/index.js.map +1 -0
- package/transpiled/schemas.d.ts +9 -0
- package/transpiled/schemas.js +14 -0
- package/transpiled/schemas.js.map +1 -0
- package/transpiled/test/util.d.ts +29 -0
- package/transpiled/test/util.js +38 -0
- package/transpiled/test/util.js.map +1 -0
- package/transpiled/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Storage = void 0;
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const msgpackr_1 = require("msgpackr");
|
|
7
|
+
const generic_1 = require("@toa.io/generic");
|
|
8
|
+
const error_value_1 = require("error-value");
|
|
9
|
+
const Scanner_1 = require("./Scanner");
|
|
10
|
+
class Storage {
|
|
11
|
+
provider;
|
|
12
|
+
constructor(provider) {
|
|
13
|
+
this.provider = provider;
|
|
14
|
+
}
|
|
15
|
+
async put(path, stream, options) {
|
|
16
|
+
const scanner = new Scanner_1.Scanner(options);
|
|
17
|
+
const pipe = stream.pipe(scanner);
|
|
18
|
+
const tempname = await this.transit(pipe);
|
|
19
|
+
if (scanner.error !== null)
|
|
20
|
+
return scanner.error;
|
|
21
|
+
const id = scanner.digest();
|
|
22
|
+
await this.persist(tempname, id);
|
|
23
|
+
return await this.create(path, id, scanner.size, scanner.type, options?.meta);
|
|
24
|
+
}
|
|
25
|
+
async get(path) {
|
|
26
|
+
const metapath = node_path_1.posix.join(ENTRIES, path, META);
|
|
27
|
+
const result = await this.provider.get(metapath);
|
|
28
|
+
if (result === null)
|
|
29
|
+
return ERR_NOT_FOUND;
|
|
30
|
+
else
|
|
31
|
+
return (0, msgpackr_1.decode)(await (0, generic_1.buffer)(result));
|
|
32
|
+
}
|
|
33
|
+
async fetch(path) {
|
|
34
|
+
const { rel, id, variant } = this.parse(path);
|
|
35
|
+
if (variant === null && rel !== '') {
|
|
36
|
+
const entry = await this.get(path);
|
|
37
|
+
if (entry instanceof Error)
|
|
38
|
+
return entry;
|
|
39
|
+
}
|
|
40
|
+
const blob = variant === null
|
|
41
|
+
? node_path_1.posix.join(BLOBs, id)
|
|
42
|
+
: node_path_1.posix.join(ENTRIES, rel, id, variant);
|
|
43
|
+
const stream = await this.provider.get(blob);
|
|
44
|
+
if (stream === null)
|
|
45
|
+
return ERR_NOT_FOUND;
|
|
46
|
+
else
|
|
47
|
+
return stream;
|
|
48
|
+
}
|
|
49
|
+
async delete(path) {
|
|
50
|
+
const entry = await this.get(path);
|
|
51
|
+
if (entry instanceof Error)
|
|
52
|
+
return entry;
|
|
53
|
+
await this.conceal(path);
|
|
54
|
+
await this.provider.delete(node_path_1.posix.join(ENTRIES, path));
|
|
55
|
+
}
|
|
56
|
+
async list(path) {
|
|
57
|
+
const listfile = node_path_1.posix.join(ENTRIES, path, LIST);
|
|
58
|
+
const stream = await this.provider.get(listfile);
|
|
59
|
+
return stream === null ? [] : (0, msgpackr_1.decode)(await (0, generic_1.buffer)(stream));
|
|
60
|
+
}
|
|
61
|
+
async permute(path, ids) {
|
|
62
|
+
const unique = new Set(ids);
|
|
63
|
+
const dir = node_path_1.posix.join(ENTRIES, path);
|
|
64
|
+
const list = await this.list(path);
|
|
65
|
+
if (list.length !== ids.length || unique.size !== ids.length)
|
|
66
|
+
return ERR_PERMUTATION_MISMATCH;
|
|
67
|
+
for (const id of ids)
|
|
68
|
+
if (!list.includes(id))
|
|
69
|
+
return ERR_PERMUTATION_MISMATCH;
|
|
70
|
+
await this.provider.put(dir, LIST, node_stream_1.Readable.from((0, msgpackr_1.encode)(ids)));
|
|
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);
|
|
85
|
+
}
|
|
86
|
+
async diversify(path, name, stream) {
|
|
87
|
+
const scanner = new Scanner_1.Scanner();
|
|
88
|
+
const pipe = stream.pipe(scanner);
|
|
89
|
+
await this.provider.put(node_path_1.posix.join(ENTRIES, path), name, pipe);
|
|
90
|
+
if (scanner.error !== null)
|
|
91
|
+
return scanner.error;
|
|
92
|
+
const { size, type } = scanner;
|
|
93
|
+
const entry = await this.get(path);
|
|
94
|
+
if (entry instanceof Error)
|
|
95
|
+
return entry;
|
|
96
|
+
entry.variants = entry.variants.filter((variant) => variant.name !== name);
|
|
97
|
+
entry.variants.push({ name, size, type });
|
|
98
|
+
await this.save(path, entry);
|
|
99
|
+
}
|
|
100
|
+
async annotate(path, key, value) {
|
|
101
|
+
const entry = await this.get(path);
|
|
102
|
+
if (entry instanceof Error)
|
|
103
|
+
return entry;
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
105
|
+
if (value === undefined)
|
|
106
|
+
delete entry.meta[key];
|
|
107
|
+
else
|
|
108
|
+
entry.meta[key] = value;
|
|
109
|
+
await this.save(path, entry);
|
|
110
|
+
}
|
|
111
|
+
async transit(stream) {
|
|
112
|
+
const tempname = (0, generic_1.newid)();
|
|
113
|
+
await this.provider.put(TEMP, tempname, stream);
|
|
114
|
+
return tempname;
|
|
115
|
+
}
|
|
116
|
+
async persist(tempname, id) {
|
|
117
|
+
const temp = node_path_1.posix.join(TEMP, tempname);
|
|
118
|
+
const blob = node_path_1.posix.join(BLOBs, id);
|
|
119
|
+
await this.provider.move(temp, blob);
|
|
120
|
+
}
|
|
121
|
+
// eslint-disable-next-line max-params
|
|
122
|
+
async create(path, id, size, type, meta = {}) {
|
|
123
|
+
const entry = {
|
|
124
|
+
id,
|
|
125
|
+
size,
|
|
126
|
+
type,
|
|
127
|
+
created: Date.now(),
|
|
128
|
+
variants: [],
|
|
129
|
+
meta
|
|
130
|
+
};
|
|
131
|
+
const metafile = node_path_1.posix.join(path, entry.id);
|
|
132
|
+
const existing = await this.get(metafile);
|
|
133
|
+
if (existing instanceof Error)
|
|
134
|
+
await this.save(metafile, entry);
|
|
135
|
+
await this.enroll(path, id, true);
|
|
136
|
+
return entry;
|
|
137
|
+
}
|
|
138
|
+
async save(rel, entry) {
|
|
139
|
+
const buffer = (0, msgpackr_1.encode)(entry);
|
|
140
|
+
const stream = node_stream_1.Readable.from(buffer);
|
|
141
|
+
await this.provider.put(node_path_1.posix.join(ENTRIES, rel), META, stream);
|
|
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)));
|
|
159
|
+
}
|
|
160
|
+
parse(path) {
|
|
161
|
+
const [last, ...segments] = path.split('/').reverse();
|
|
162
|
+
const [id, ...rest] = last.split('.');
|
|
163
|
+
const variant = rest.length > 0 ? rest.join('.') : null;
|
|
164
|
+
const rel = segments.reverse().join('/');
|
|
165
|
+
return { rel, id, variant };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.Storage = Storage;
|
|
169
|
+
const ERR_NOT_FOUND = (0, error_value_1.Err)('NOT_FOUND');
|
|
170
|
+
const ERR_PERMUTATION_MISMATCH = (0, error_value_1.Err)('PERMUTATION_MISMATCH');
|
|
171
|
+
const TEMP = '/temp';
|
|
172
|
+
const BLOBs = '/blobs';
|
|
173
|
+
const ENTRIES = '/entries';
|
|
174
|
+
const LIST = '.list';
|
|
175
|
+
const META = '.meta';
|
|
176
|
+
//# sourceMappingURL=Storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.js","sour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,OAAO,GAAG,UAAU,CAAA;AAC1B,MAAM,IAAI,GAAG,OAAO,CAAA;AACpB,MAAM,IAAI,GAAG,OAAO,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Dependency } from '@toa.io/operations';
|
|
2
|
+
import type { context } from '@toa.io/norm';
|
|
3
|
+
export declare const SERIALIZATION_PREFIX = "TOA_STORAGES";
|
|
4
|
+
export declare function deployment(instances: Instance[], annotation: unknown): Dependency;
|
|
5
|
+
export type Instance = context.Dependency<string[]>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.deployment = exports.SERIALIZATION_PREFIX = void 0;
|
|
27
|
+
const assert = __importStar(require("node:assert"));
|
|
28
|
+
const generic_1 = require("@toa.io/generic");
|
|
29
|
+
const providers_1 = require("./providers");
|
|
30
|
+
const Annotation_1 = require("./Annotation");
|
|
31
|
+
exports.SERIALIZATION_PREFIX = 'TOA_STORAGES';
|
|
32
|
+
function deployment(instances, annotation) {
|
|
33
|
+
validate(instances, annotation);
|
|
34
|
+
const value = (0, generic_1.encode)(annotation);
|
|
35
|
+
const pointer = { name: exports.SERIALIZATION_PREFIX, value };
|
|
36
|
+
const secrets = getSecrets(annotation);
|
|
37
|
+
return {
|
|
38
|
+
variables: { global: [pointer, ...secrets] }
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.deployment = deployment;
|
|
42
|
+
function validate(instances, annotation) {
|
|
43
|
+
(0, Annotation_1.validateAnnotation)(annotation);
|
|
44
|
+
for (const instance of instances)
|
|
45
|
+
contains(instance, annotation);
|
|
46
|
+
}
|
|
47
|
+
function contains(instance, annotation) {
|
|
48
|
+
for (const name of instance.manifest)
|
|
49
|
+
assert.ok(name in annotation, `Missing '${name}' storage annotation ` +
|
|
50
|
+
`declared in '${instance.component.locator.id}'`);
|
|
51
|
+
}
|
|
52
|
+
function getSecrets(annotation) {
|
|
53
|
+
const secrets = [];
|
|
54
|
+
for (const [name, declaration] of Object.entries(annotation)) {
|
|
55
|
+
const Provider = providers_1.providers[declaration.provider];
|
|
56
|
+
for (const secret of Provider.SECRETS)
|
|
57
|
+
secrets.push({
|
|
58
|
+
name: `${exports.SERIALIZATION_PREFIX}_${name}_${secret.name}`.toUpperCase(),
|
|
59
|
+
secret: {
|
|
60
|
+
name: `toa-storages-${name}`,
|
|
61
|
+
key: secret.name,
|
|
62
|
+
optional: secret.optional
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return secrets;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=deployment.js.map
|
|
@@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AU,CAAC,EAAE,CAAC;QAC7D,MAAM,QAAQ,GAAG,qBAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;QAEhD,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,OAAO;YACnC,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,GAAG,4BAAoB,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE;gBACpE,MAAM,EAAE;oBACN,IAAI,EAAE,gBAAgB,IAAI,EAAE;oBAC5B,GAAG,EAAE,MAAM,CAAC,IAAI;oBAChB,QAAQ,EAAE,MAAM,CAAC,QAAQ;iBAC1B;aACF,CAAC,CAAA;IACN,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
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; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAChB,2CAAyC;AAAhC,wGAAA,UAAU,OAAA;AACnB,uCAAqC;AAA5B,oGAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function manifest(manifest: string | string[] | null): string[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.manifest = void 0;
|
|
4
|
+
const matchacho_1 = require("matchacho");
|
|
5
|
+
function manifest(manifest) {
|
|
6
|
+
return (0, matchacho_1.match)(manifest, String, (name) => [name], Array, manifest, null, []);
|
|
7
|
+
}
|
|
8
|
+
exports.manifest = manifest;
|
|
9
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../source/manifest.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAEjC,SAAgB,QAAQ,CAAE,QAAkC;IAC1D,OAAO,IAAA,iBAAK,EAAC,QAAQ,EACnB,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAChC,KAAK,EAAE,QAAQ,EACf,IAAI,EAAE,EAAE,CAAC,CAAA;AACb,CAAC;AALD,4BAKC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { S3Options } from './S3';
|
|
2
|
+
import type { FileSystemOptions } from './FileSystem';
|
|
3
|
+
import type { TemporaryOptions } from './Temporary';
|
|
4
|
+
export type Declaration = ({
|
|
5
|
+
provider: 's3';
|
|
6
|
+
} & S3Options) | ({
|
|
7
|
+
provider: 'fs';
|
|
8
|
+
} & FileSystemOptions) | ({
|
|
9
|
+
provider: 'tmp';
|
|
10
|
+
} & TemporaryOptions) | ({
|
|
11
|
+
provider: 'mem';
|
|
12
|
+
}) | ({
|
|
13
|
+
provider: 'test';
|
|
14
|
+
} & TemporaryOptions);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Declaration.js","sourceRoot":"","sources":["../../source/providers/Declaration.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { type Readable } from 'node:stream';
|
|
3
|
+
import { Provider } from '../Provider';
|
|
4
|
+
import type { ProviderSecrets } from '../Provider';
|
|
5
|
+
export interface FileSystemOptions {
|
|
6
|
+
path: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class FileSystem extends Provider<FileSystemOptions> {
|
|
9
|
+
protected readonly path: string;
|
|
10
|
+
constructor(options: FileSystemOptions, secrets?: ProviderSecrets);
|
|
11
|
+
get(path: string): Promise<Readable | null>;
|
|
12
|
+
put(rel: string, filename: string, stream: Readable): Promise<void>;
|
|
13
|
+
delete(path: string): Promise<void>;
|
|
14
|
+
move(from: string, to: string): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FileSystem = void 0;
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
|
+
const Provider_1 = require("../Provider");
|
|
10
|
+
class FileSystem extends Provider_1.Provider {
|
|
11
|
+
path;
|
|
12
|
+
constructor(options, secrets) {
|
|
13
|
+
super(options, secrets);
|
|
14
|
+
this.path = options.path;
|
|
15
|
+
}
|
|
16
|
+
async get(path) {
|
|
17
|
+
try {
|
|
18
|
+
const fd = await promises_1.default.open((0, node_path_1.join)(this.path, path));
|
|
19
|
+
return fd.createReadStream();
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
if (err?.code === 'ENOENT')
|
|
23
|
+
return null;
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async put(rel, filename, stream) {
|
|
28
|
+
const dir = (0, node_path_1.join)(this.path, rel);
|
|
29
|
+
const path = (0, node_path_1.join)(dir, filename);
|
|
30
|
+
await promises_1.default.mkdir((0, node_path_1.dirname)(path), { recursive: true });
|
|
31
|
+
await promises_1.default.writeFile(path, stream);
|
|
32
|
+
}
|
|
33
|
+
async delete(path) {
|
|
34
|
+
await promises_1.default.rm((0, node_path_1.join)(this.path, path), { recursive: true, force: true });
|
|
35
|
+
}
|
|
36
|
+
async move(from, to) {
|
|
37
|
+
from = (0, node_path_1.join)(this.path, from);
|
|
38
|
+
to = (0, node_path_1.join)(this.path, to);
|
|
39
|
+
await promises_1.default.mkdir((0, node_path_1.dirname)(to), { recursive: true });
|
|
40
|
+
await promises_1.default.rename(from, to);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.FileSystem = FileSystem;
|
|
44
|
+
//# sourceMappingURL=FileSystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileSystem.js","sourceRoot":"","sources":["../../source/providers/FileSystem.ts"],"names":[],"mappings":";;;;;;AACA,yCAAyC;AACzC,gEAAiC;AACjC,0CAAsC;AAOtC,MAAa,UAAW,SAAQ,mBAA2B;IACtC,IAAI,CAAQ;IAE/B,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,EAAE,CAAC;YACb,IAAK,GAA6B,EAAE,IAAI,KAAK,QAAQ;gBAAE,OAAO,IAAI,CAAA;YAElE,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,GAAG,CAAE,GAAW,EAAE,QAAgB,EAAE,MAAgB;QAC/D,MAAM,GAAG,GAAG,IAAA,gBAAI,EAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QAChC,MAAM,IAAI,GAAG,IAAA,gBAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;QAEhC,MAAM,kBAAE,CAAC,KAAK,CAAC,IAAA,mBAAO,EAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAClD,MAAM,kBAAE,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAClC,CAAC;IAEM,KAAK,CAAC,MAAM,CAAE,IAAY;QAC/B,MAAM,kBAAE,CAAC,EAAE,CAAC,IAAA,gBAAI,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IACtE,CAAC;IAEM,KAAK,CAAC,IAAI,CAAE,IAAY,EAAE,EAAU;QACzC,IAAI,GAAG,IAAA,gBAAI,EAAC,IAAI,CAAC,IAAI,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;CACF;AAxCD,gCAwCC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
import { Provider } from '../Provider';
|
|
4
|
+
/**
|
|
5
|
+
* In-memory provider
|
|
6
|
+
*/
|
|
7
|
+
export declare class InMemory extends Provider {
|
|
8
|
+
private readonly storage;
|
|
9
|
+
get(path: string): Promise<Readable | null>;
|
|
10
|
+
put(path: string, filename: string, stream: Readable): Promise<void>;
|
|
11
|
+
delete(path: string): Promise<void>;
|
|
12
|
+
move(from: string, to: string): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.InMemory = void 0;
|
|
27
|
+
const node_stream_1 = require("node:stream");
|
|
28
|
+
const node_path_1 = require("node:path");
|
|
29
|
+
const consumers_1 = require("node:stream/consumers");
|
|
30
|
+
const assert = __importStar(require("node:assert"));
|
|
31
|
+
const Provider_1 = require("../Provider");
|
|
32
|
+
/**
|
|
33
|
+
* In-memory provider
|
|
34
|
+
*/
|
|
35
|
+
class InMemory extends Provider_1.Provider {
|
|
36
|
+
storage = new Map();
|
|
37
|
+
async get(path) {
|
|
38
|
+
const data = this.storage.get(path);
|
|
39
|
+
if (data === undefined)
|
|
40
|
+
return null;
|
|
41
|
+
return node_stream_1.Readable.from(data);
|
|
42
|
+
}
|
|
43
|
+
async put(path, filename, stream) {
|
|
44
|
+
this.storage.set((0, node_path_1.join)(path, filename), await (0, consumers_1.buffer)(stream));
|
|
45
|
+
}
|
|
46
|
+
async delete(path) {
|
|
47
|
+
for (const f of this.storage.keys())
|
|
48
|
+
if (f.startsWith(path))
|
|
49
|
+
this.storage.delete(f);
|
|
50
|
+
}
|
|
51
|
+
async move(from, to) {
|
|
52
|
+
assert.notEqual(from, to, 'Source and destination are the same');
|
|
53
|
+
const buf = this.storage.get(from);
|
|
54
|
+
assert.ok(buf !== undefined, `File not found: ${from}`);
|
|
55
|
+
this.storage.set(to, buf);
|
|
56
|
+
this.storage.delete(from);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.InMemory = InMemory;
|
|
60
|
+
//# sourceMappingURL=Memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Memory.js","sourceRoot":"","sources":["../../source/providers/Memory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAsC;AACtC,yCAAgC;AAChC,qDAA8C;AAC9C,oDAAqC;AAErC,0CAAsC;AAEtC;;GAEG;AACH,MAAa,QAAS,SAAQ,mBAAQ;IACnB,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAA;IAEpC,KAAK,CAAC,GAAG,CAAE,IAAY;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAEnC,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,IAAI,CAAA;QAEnC,OAAO,sBAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;IAEe,KAAK,CAAC,GAAG,CAAE,IAAY,EAAE,QAAgB,EAAE,MAAgB;QACzE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAA,gBAAI,EAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAA,kBAAM,EAAC,MAAM,CAAC,CAAC,CAAA;IAC9D,CAAC;IAEe,KAAK,CAAC,MAAM,CAAE,IAAY;QACxC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;YACjC,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;gBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAClD,CAAC;IAEe,KAAK,CAAC,IAAI,CAAE,IAAY,EAAE,EAAU;QAClD,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,qCAAqC,CAAC,CAAA;QAEhE,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAElC,MAAM,CAAC,EAAE,CAAC,GAAG,KAAK,SAAS,EAAE,mBAAmB,IAAI,EAAE,CAAC,CAAA;QAEvD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;QACzB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;CACF;AA9BD,4BA8BC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
4
|
+
import { Provider, type ProviderSecret, type ProviderSecrets } from '../Provider';
|
|
5
|
+
export interface S3Options {
|
|
6
|
+
bucket: string;
|
|
7
|
+
region?: string;
|
|
8
|
+
prefix?: string;
|
|
9
|
+
endpoint?: string;
|
|
10
|
+
}
|
|
11
|
+
type S3Secrets = ProviderSecrets<'ACCESS_KEY_ID' | 'SECRET_ACCESS_KEY'>;
|
|
12
|
+
export declare class S3 extends Provider<S3Options> {
|
|
13
|
+
static readonly SECRETS: readonly ProviderSecret[];
|
|
14
|
+
protected readonly bucket: string;
|
|
15
|
+
protected readonly client: S3Client;
|
|
16
|
+
constructor(options: S3Options, secrets?: S3Secrets);
|
|
17
|
+
get(Key: string): Promise<Readable | null>;
|
|
18
|
+
put(path: string, filename: string, stream: Readable): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Deletes either a single object or "directory" - all objects
|
|
21
|
+
* with given prefix (prefix will be enforced to finish with `/`)
|
|
22
|
+
* @param Key - key name or path prefix
|
|
23
|
+
*/
|
|
24
|
+
delete(Key: string): Promise<void>;
|
|
25
|
+
move(from: string, keyTo: string): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export {};
|