@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
|
@@ -1,54 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.S3 = void 0;
|
|
30
|
-
const node_stream_1 = require("node:stream");
|
|
31
|
-
const node_buffer_1 = require("node:buffer");
|
|
32
|
-
const posix_1 = require("node:path/posix");
|
|
33
|
-
const node_assert_1 = __importDefault(require("node:assert"));
|
|
34
|
-
const node_path_1 = require("node:path");
|
|
35
|
-
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
36
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
37
|
-
const nodeNativeFetch = __importStar(require("smithy-node-native-fetch"));
|
|
38
|
-
const Provider_1 = require("../Provider");
|
|
39
|
-
class S3 extends Provider_1.Provider {
|
|
40
|
-
static SECRETS = [
|
|
41
|
-
{ name: 'ACCESS_KEY_ID', optional: true },
|
|
42
|
-
{ name: 'SECRET_ACCESS_KEY', optional: true }
|
|
43
|
-
];
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import { Blob } from 'node:buffer';
|
|
3
|
+
import { join } from 'node:path/posix';
|
|
4
|
+
import { Upload } from '@aws-sdk/lib-storage';
|
|
5
|
+
import * as s3 from '@aws-sdk/client-s3';
|
|
6
|
+
import { console } from 'openspan';
|
|
7
|
+
import { Provider } from '../Provider.js';
|
|
8
|
+
import { secrets } from '@toa.io/definitions/extensions.storages';
|
|
9
|
+
import { ERR_NOT_FOUND } from '../errors.js';
|
|
10
|
+
export class S3 extends Provider {
|
|
11
|
+
static SECRETS = secrets.s3;
|
|
44
12
|
bucket;
|
|
45
13
|
client;
|
|
46
14
|
constructor(options, secrets) {
|
|
47
|
-
super(options);
|
|
15
|
+
super(options, secrets);
|
|
48
16
|
this.bucket = options.bucket;
|
|
49
17
|
const s3Config = {
|
|
50
|
-
retryMode: 'adaptive'
|
|
51
|
-
...nodeNativeFetch
|
|
18
|
+
retryMode: 'adaptive'
|
|
52
19
|
};
|
|
53
20
|
if (options.endpoint !== undefined) {
|
|
54
21
|
s3Config.forcePathStyle = options.endpoint.startsWith('http://');
|
|
@@ -57,19 +24,20 @@ class S3 extends Provider_1.Provider {
|
|
|
57
24
|
if (options.region !== undefined)
|
|
58
25
|
s3Config.region = options.region;
|
|
59
26
|
if (typeof secrets?.ACCESS_KEY_ID === 'string') {
|
|
60
|
-
|
|
27
|
+
if (secrets.SECRET_ACCESS_KEY === undefined)
|
|
28
|
+
throw new Error('SECRET_ACCESS_KEY is required if ACCESS_KEY_ID is provided');
|
|
61
29
|
s3Config.credentials = {
|
|
62
30
|
accessKeyId: secrets.ACCESS_KEY_ID,
|
|
63
31
|
secretAccessKey: secrets.SECRET_ACCESS_KEY
|
|
64
32
|
};
|
|
65
33
|
}
|
|
66
|
-
this.client = new
|
|
34
|
+
this.client = new s3.S3Client(s3Config);
|
|
67
35
|
this.client.middlewareStack.add((next, _context) => async (args) => {
|
|
36
|
+
// removes leading slash
|
|
68
37
|
if ('Key' in args.input && typeof args.input.Key === 'string')
|
|
69
|
-
// removes leading slash
|
|
70
38
|
args.input.Key = args.input.Key.replace(/^\//, '');
|
|
39
|
+
// removes leading slash and ensures finishing slash
|
|
71
40
|
if ('Prefix' in args.input && typeof args.input.Prefix === 'string')
|
|
72
|
-
// removes leading slash and ensures finishing slash
|
|
73
41
|
args.input.Prefix = args.input.Prefix.replace(/^\/|\/$/g, '') + '/';
|
|
74
42
|
return next(args);
|
|
75
43
|
}, {
|
|
@@ -79,95 +47,76 @@ class S3 extends Provider_1.Provider {
|
|
|
79
47
|
});
|
|
80
48
|
}
|
|
81
49
|
async get(Key) {
|
|
82
|
-
try {
|
|
83
|
-
const
|
|
50
|
+
return await this.try(async () => {
|
|
51
|
+
const entry = await this.client.send(new s3.GetObjectCommand({
|
|
84
52
|
Bucket: this.bucket,
|
|
85
53
|
Key
|
|
86
54
|
}));
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return null;
|
|
98
|
-
else
|
|
99
|
-
throw err;
|
|
100
|
-
}
|
|
55
|
+
const stream = entry.Body instanceof Readable
|
|
56
|
+
? entry.Body
|
|
57
|
+
: Readable.fromWeb((entry.Body instanceof Blob
|
|
58
|
+
? entry.Body.stream()
|
|
59
|
+
: entry.Body));
|
|
60
|
+
if (entry.Metadata?.value === undefined)
|
|
61
|
+
return ERR_NOT_FOUND;
|
|
62
|
+
const metadata = JSON.parse(entry.Metadata.value);
|
|
63
|
+
return { stream, ...metadata };
|
|
64
|
+
});
|
|
101
65
|
}
|
|
102
|
-
async
|
|
103
|
-
return
|
|
104
|
-
|
|
66
|
+
async head(Key) {
|
|
67
|
+
return await this.try(async () => {
|
|
68
|
+
const entry = await this.client.send(new s3.HeadObjectCommand({
|
|
69
|
+
Bucket: this.bucket,
|
|
70
|
+
Key
|
|
71
|
+
}));
|
|
72
|
+
if (entry.Metadata?.value === undefined)
|
|
73
|
+
return ERR_NOT_FOUND;
|
|
74
|
+
return JSON.parse(entry.Metadata.value);
|
|
75
|
+
});
|
|
105
76
|
}
|
|
106
|
-
async put(
|
|
107
|
-
await new
|
|
77
|
+
async put(Key, stream) {
|
|
78
|
+
await new Upload({
|
|
108
79
|
client: this.client,
|
|
109
80
|
params: {
|
|
110
81
|
Bucket: this.bucket,
|
|
111
|
-
Key
|
|
82
|
+
Key,
|
|
112
83
|
Body: stream
|
|
113
84
|
}
|
|
114
85
|
}).done();
|
|
115
86
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
* with given prefix (prefix will be enforced to finish with `/`)
|
|
119
|
-
* @param Key - key name or path prefix
|
|
120
|
-
*/
|
|
121
|
-
async delete(Key) {
|
|
122
|
-
const { client, bucket: Bucket } = this;
|
|
123
|
-
// checking if given key is a single file
|
|
124
|
-
if (!Key.endsWith('/'))
|
|
125
|
-
try {
|
|
126
|
-
// DeleteObject on S3 returns no error if object does not exist
|
|
127
|
-
await client.send(new client_s3_1.HeadObjectCommand({ Bucket, Key }));
|
|
128
|
-
await client.send(new client_s3_1.DeleteObjectCommand({ Bucket, Key }));
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
node_assert_1.default.ok(err instanceof client_s3_1.NotFound || err instanceof client_s3_1.NoSuchKey, err);
|
|
133
|
-
}
|
|
134
|
-
const objectsToRemove = await this.listObjects(Key);
|
|
135
|
-
// Removing all objects in parallel in batches
|
|
136
|
-
await Promise.all((function* () {
|
|
137
|
-
while (objectsToRemove.length > 0)
|
|
138
|
-
yield client.send(new client_s3_1.DeleteObjectsCommand({
|
|
139
|
-
Bucket,
|
|
140
|
-
Delete: {
|
|
141
|
-
Objects: objectsToRemove.splice(0, 1000 /* max batch size for DeleteObjects */)
|
|
142
|
-
}
|
|
143
|
-
}));
|
|
144
|
-
})());
|
|
145
|
-
}
|
|
146
|
-
async move(from, keyTo) {
|
|
147
|
-
await this.client.send(new client_s3_1.CopyObjectCommand({
|
|
87
|
+
async commit(Key, metadata) {
|
|
88
|
+
await this.client.send(new s3.CopyObjectCommand({
|
|
148
89
|
Bucket: this.bucket,
|
|
149
|
-
Key
|
|
150
|
-
CopySource:
|
|
90
|
+
Key,
|
|
91
|
+
CopySource: join(this.bucket, Key),
|
|
92
|
+
Metadata: { value: JSON.stringify(metadata) },
|
|
93
|
+
MetadataDirective: 'REPLACE'
|
|
151
94
|
}));
|
|
152
|
-
|
|
95
|
+
console.debug('Uploaded to S3', { bucket: this.bucket, path: Key, metadata });
|
|
153
96
|
}
|
|
154
|
-
async
|
|
155
|
-
|
|
156
|
-
await Promise.all(objects.map(async ({ Key }) => {
|
|
157
|
-
const ent = node_path_1.posix.basename(Key);
|
|
158
|
-
const source = node_path_1.posix.join(from, ent);
|
|
159
|
-
const target = node_path_1.posix.join(to, ent);
|
|
160
|
-
return this.move(source, target);
|
|
161
|
-
}));
|
|
97
|
+
async delete(Key) {
|
|
98
|
+
await this.client.send(new s3.DeleteObjectCommand({ Bucket: this.bucket, Key }));
|
|
162
99
|
}
|
|
163
|
-
async
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
100
|
+
async move(from, keyTo) {
|
|
101
|
+
return await this.try(async () => {
|
|
102
|
+
await this.client.send(new s3.CopyObjectCommand({
|
|
103
|
+
Bucket: this.bucket,
|
|
104
|
+
Key: keyTo,
|
|
105
|
+
CopySource: join(this.bucket, from)
|
|
106
|
+
}));
|
|
107
|
+
await this.client.send(new s3.DeleteObjectCommand({ Bucket: this.bucket, Key: from }));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async try(action) {
|
|
111
|
+
try {
|
|
112
|
+
return await action();
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
if (err?.name === 'NotFound' || err?.name === 'NoSuchKey')
|
|
116
|
+
return ERR_NOT_FOUND;
|
|
117
|
+
else
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
170
120
|
}
|
|
171
121
|
}
|
|
172
|
-
exports.S3 = S3;
|
|
173
122
|
//# sourceMappingURL=S3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"S3.js","sourceRoot":"","sources":["../../source/providers/S3.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"S3.js","sourceRoot":"","sources":["../../source/providers/S3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAA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E,CAAA;QACvB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,GAAG,EAAE,IAAI,KAAK,UAAU,IAAI,GAAG,EAAE,IAAI,KAAK,WAAW;gBAAE,OAAO,aAAa,CAAA;;gBAC1E,MAAM,GAAG,CAAA;QAChB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { S3 } from './S3.ts';
|
|
2
|
+
import type { Secret, Secrets } from '../Secrets.ts';
|
|
3
|
+
export interface SpacesOptions {
|
|
4
|
+
space: string;
|
|
5
|
+
region: string;
|
|
6
|
+
}
|
|
7
|
+
type SpacesSecrets = Secrets<'ACCESS_KEY_ID' | 'SECRET_ACCESS_KEY'>;
|
|
8
|
+
export declare class Spaces extends S3 {
|
|
9
|
+
static readonly SECRETS: readonly Secret[];
|
|
10
|
+
constructor(options: SpacesOptions, secrets?: SpacesSecrets);
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { S3 } from './S3.js';
|
|
2
|
+
import { secrets } from '@toa.io/definitions/extensions.storages';
|
|
3
|
+
export class Spaces extends S3 {
|
|
4
|
+
static SECRETS = secrets.spaces;
|
|
5
|
+
constructor(options, secrets) {
|
|
6
|
+
super({
|
|
7
|
+
bucket: options.space,
|
|
8
|
+
region: options.region,
|
|
9
|
+
endpoint: `https://${options.region}.digitaloceanspaces.com`
|
|
10
|
+
}, secrets);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=Spaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Spaces.js","sourceRoot":"","sources":["../../source/providers/Spaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAA;AAUjE,MAAM,OAAO,MAAO,SAAQ,EAAE;IACrB,MAAM,CAAmB,OAAO,GAAsB,OAAO,CAAC,MAAM,CAAA;IAE3E,YAAmB,OAAsB,EAAE,OAAuB;QAChE,KAAK,CACH;YACE,MAAM,EAAE,OAAO,CAAC,KAAK;YACrB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,QAAQ,EAAE,WAAW,OAAO,CAAC,MAAM,yBAAyB;SAC7D,EACD,OAAO,CACR,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { FileSystem } from './FileSystem';
|
|
2
|
-
import type { ProviderSecrets } from '../Provider';
|
|
1
|
+
import { FileSystem } from './FileSystem.ts';
|
|
3
2
|
export interface TemporaryOptions {
|
|
4
3
|
directory: string;
|
|
5
4
|
}
|
|
6
5
|
export declare class Temporary extends FileSystem {
|
|
7
|
-
constructor(options: TemporaryOptions
|
|
6
|
+
constructor(options: TemporaryOptions);
|
|
8
7
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
constructor(options, secrets) {
|
|
9
|
-
const path = (0, node_path_1.join)((0, node_os_1.tmpdir)(), options.directory);
|
|
10
|
-
super({ path }, secrets);
|
|
1
|
+
import { tmpdir } from 'node:os';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { FileSystem } from './FileSystem.js';
|
|
4
|
+
export class Temporary extends FileSystem {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
const path = join(tmpdir(), options.directory);
|
|
7
|
+
super({ path });
|
|
11
8
|
}
|
|
12
9
|
}
|
|
13
|
-
exports.Temporary = Temporary;
|
|
14
10
|
//# sourceMappingURL=Temporary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Temporary.js","sourceRoot":"","sources":["../../source/providers/Temporary.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Temporary.js","sourceRoot":"","sources":["../../source/providers/Temporary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAM5C,MAAM,OAAO,SAAU,SAAQ,UAAU;IACvC,YAAmB,OAAyB;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;QAE9C,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IACjB,CAAC;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Temporary, type TemporaryOptions } from './Temporary';
|
|
2
|
-
import type {
|
|
1
|
+
import { Temporary, type TemporaryOptions } from './Temporary.ts';
|
|
2
|
+
import type { Secret } from '../Secrets.ts';
|
|
3
3
|
export declare class Test extends Temporary {
|
|
4
|
-
static readonly SECRETS: readonly
|
|
5
|
-
constructor(options: TemporaryOptions
|
|
4
|
+
static readonly SECRETS: readonly Secret[];
|
|
5
|
+
constructor(options: TemporaryOptions);
|
|
6
6
|
}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
{ name: 'USERNAME' },
|
|
8
|
-
{ name: 'PASSWORD' }
|
|
9
|
-
];
|
|
10
|
-
constructor(options, secrets) {
|
|
11
|
-
super(options, secrets);
|
|
1
|
+
import { Temporary } from './Temporary.js';
|
|
2
|
+
import { secrets } from '@toa.io/definitions/extensions.storages';
|
|
3
|
+
export class Test extends Temporary {
|
|
4
|
+
static SECRETS = secrets.test;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
super(options);
|
|
12
7
|
}
|
|
13
8
|
}
|
|
14
|
-
exports.Test = Test;
|
|
15
9
|
//# sourceMappingURL=Test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Test.js","sourceRoot":"","sources":["../../source/providers/Test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Test.js","sourceRoot":"","sources":["../../source/providers/Test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAyB,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAA;AAGjE,MAAM,OAAO,IAAK,SAAQ,SAAS;IAC1B,MAAM,CAAmB,OAAO,GAAsB,OAAO,CAAC,IAAI,CAAA;IAEzE,YAAmB,OAAyB;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;CACF"}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { Constructor } from '../Provider.ts';
|
|
2
|
+
/**
|
|
3
|
+
* A provider is loaded when a storage names it: the SDK one is written against is not paid
|
|
4
|
+
* for by a process that declares another, and is not installed by one either — it is an
|
|
5
|
+
* optional peer of this package, which a deploy installs for the storages a component
|
|
6
|
+
* declares. See `provider` below for what a workspace that has not gets told.
|
|
7
|
+
*/
|
|
6
8
|
export declare const providers: {
|
|
7
|
-
readonly s3: typeof S3
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
9
|
+
readonly s3: () => Promise<typeof import("./S3.ts").S3>;
|
|
10
|
+
readonly spaces: () => Promise<typeof import("./Spaces.ts").Spaces>;
|
|
11
|
+
readonly cloudinary: () => Promise<typeof import("./Cloudinary.ts").Cloudinary>;
|
|
12
|
+
readonly fs: () => Promise<typeof import("./FileSystem.ts").FileSystem>;
|
|
13
|
+
readonly tmp: () => Promise<typeof import("./Temporary.ts").Temporary>;
|
|
14
|
+
readonly test: () => Promise<typeof import("./Test.ts").Test>;
|
|
12
15
|
};
|
|
13
|
-
export type
|
|
16
|
+
export type Id = keyof typeof providers;
|
|
17
|
+
/** The provider a declaration names, or what to install to have it. */
|
|
18
|
+
export declare function provider(id: Id): Promise<Constructor>;
|
|
19
|
+
export type { Declaration } from './Declaration.ts';
|
|
20
|
+
export type { S3Options } from './S3.ts';
|
|
21
|
+
export type { SpacesOptions } from './Spaces.ts';
|
|
22
|
+
export type { CloudinaryOptions } from './Cloudinary.ts';
|
|
23
|
+
export type { FileSystemOptions } from './FileSystem.ts';
|
|
24
|
+
export type { TemporaryOptions } from './Temporary.ts';
|
|
25
|
+
export type { FileSystem, S3, Spaces, Cloudinary, Temporary } from './index.types.ts';
|
|
@@ -1,16 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
test:
|
|
1
|
+
import { packages } from '@toa.io/definitions/extensions.storages';
|
|
2
|
+
/**
|
|
3
|
+
* A provider is loaded when a storage names it: the SDK one is written against is not paid
|
|
4
|
+
* for by a process that declares another, and is not installed by one either — it is an
|
|
5
|
+
* optional peer of this package, which a deploy installs for the storages a component
|
|
6
|
+
* declares. See `provider` below for what a workspace that has not gets told.
|
|
7
|
+
*/
|
|
8
|
+
export const providers = {
|
|
9
|
+
s3: async () => (await import('./S3.js')).S3,
|
|
10
|
+
spaces: async () => (await import('./Spaces.js')).Spaces,
|
|
11
|
+
cloudinary: async () => (await import('./Cloudinary.js')).Cloudinary,
|
|
12
|
+
fs: async () => (await import('./FileSystem.js')).FileSystem,
|
|
13
|
+
tmp: async () => (await import('./Temporary.js')).Temporary,
|
|
14
|
+
test: async () => (await import('./Test.js')).Test
|
|
15
15
|
};
|
|
16
|
+
/** The provider a declaration names, or what to install to have it. */
|
|
17
|
+
export async function provider(id) {
|
|
18
|
+
try {
|
|
19
|
+
return await providers[id]();
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
const missing = Object.entries(packages[id]).map(([name, version]) => `${name}@${version}`);
|
|
23
|
+
if (missing.length === 0 || !isMissingModule(error))
|
|
24
|
+
throw error;
|
|
25
|
+
throw new Error(`Storage provider '${id}' needs ${missing.join(' ')}, which is not installed. ` +
|
|
26
|
+
`\`toa npm\` installs what this context's components declare.`, { cause: error });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function isMissingModule(error) {
|
|
30
|
+
return error?.code === 'ERR_MODULE_NOT_FOUND';
|
|
31
|
+
}
|
|
16
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/providers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yCAAyC,CAAA;AAGlE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,EAAE,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;IAC5C,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM;IACxD,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,UAAU;IACpE,EAAE,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,UAAU;IAC5D,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS;IAC3D,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI;CACW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