@toa.io/extensions.storages 1.0.0-alpha.21 → 1.0.0-alpha.219
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -14
- package/readme.md +96 -51
- package/schemas/annotation.cos.yaml +1 -0
- package/schemas/cloudinary.cos.yaml +37 -0
- package/schemas/fs.cos.yaml +2 -0
- package/schemas/s3.cos.yaml +1 -0
- package/schemas/tmp.cos.yaml +0 -1
- package/source/Entry.ts +13 -11
- package/source/Factory.ts +16 -9
- package/source/Provider.ts +22 -19
- package/source/Scanner.ts +58 -26
- package/source/Secrets.ts +6 -0
- package/source/Storage.test.ts +118 -274
- package/source/Storage.ts +62 -207
- package/source/deployment.ts +52 -16
- package/source/errors.ts +3 -0
- package/source/index.ts +3 -1
- package/source/manifest.ts +7 -6
- package/source/providers/Cloudinary.ts +320 -0
- package/source/providers/Declaration.ts +2 -1
- package/source/providers/FileSystem.ts +79 -25
- package/source/providers/S3.ts +81 -80
- package/source/providers/Temporary.ts +2 -3
- package/source/providers/Test.ts +4 -4
- package/source/providers/index.test.ts +102 -76
- package/source/providers/index.ts +10 -4
- package/source/schemas.ts +1 -0
- package/source/test/.env.example +4 -0
- package/source/test/arny.jpg +0 -0
- package/source/test/lenna.48x48.jpeg +0 -0
- package/source/test/plank.mp4 +0 -0
- package/source/test/sample.avi +0 -0
- package/source/test/sample.wav +0 -0
- package/source/test/sport.mp4 +0 -0
- package/source/test/util.ts +62 -12
- package/transpiled/Entry.d.ts +15 -11
- package/transpiled/Factory.js +11 -5
- package/transpiled/Factory.js.map +1 -1
- package/transpiled/Provider.d.ts +17 -16
- package/transpiled/Provider.js +6 -4
- package/transpiled/Provider.js.map +1 -1
- package/transpiled/Scanner.d.ts +6 -2
- package/transpiled/Scanner.js +49 -22
- package/transpiled/Scanner.js.map +1 -1
- package/transpiled/Secrets.d.ts +5 -0
- package/transpiled/Secrets.js +3 -0
- package/transpiled/Secrets.js.map +1 -0
- package/transpiled/Storage.d.ts +13 -21
- package/transpiled/Storage.js +52 -155
- package/transpiled/Storage.js.map +1 -1
- package/transpiled/deployment.d.ts +1 -1
- package/transpiled/deployment.js +43 -16
- package/transpiled/deployment.js.map +1 -1
- package/transpiled/errors.d.ts +2 -0
- package/transpiled/errors.js +6 -0
- package/transpiled/errors.js.map +1 -0
- package/transpiled/index.d.ts +3 -1
- package/transpiled/manifest.js +5 -2
- package/transpiled/manifest.js.map +1 -1
- package/transpiled/providers/Cloudinary.d.ts +51 -0
- package/transpiled/providers/Cloudinary.js +223 -0
- package/transpiled/providers/Cloudinary.js.map +1 -0
- package/transpiled/providers/Declaration.d.ts +3 -2
- package/transpiled/providers/FileSystem.d.ts +15 -7
- package/transpiled/providers/FileSystem.js +64 -24
- package/transpiled/providers/FileSystem.js.map +1 -1
- package/transpiled/providers/S3.d.ts +14 -14
- package/transpiled/providers/S3.js +62 -60
- package/transpiled/providers/S3.js.map +1 -1
- package/transpiled/providers/Temporary.d.ts +1 -2
- package/transpiled/providers/Temporary.js +2 -2
- package/transpiled/providers/Temporary.js.map +1 -1
- package/transpiled/providers/Test.d.ts +3 -3
- package/transpiled/providers/Test.js +2 -2
- package/transpiled/providers/Test.js.map +1 -1
- package/transpiled/providers/index.d.ts +7 -2
- package/transpiled/providers/index.js +2 -2
- package/transpiled/providers/index.js.map +1 -1
- package/transpiled/schemas.d.ts +1 -0
- package/transpiled/schemas.js +2 -1
- package/transpiled/schemas.js.map +1 -1
- package/transpiled/test/util.d.ts +89 -5
- package/transpiled/test/util.js +51 -4
- package/transpiled/test/util.js.map +1 -1
- package/transpiled/tsconfig.tsbuildinfo +1 -1
- package/source/providers/FileSystem.test.ts +0 -5
- package/source/providers/Memory.ts +0 -41
- package/source/providers/S3.test.ts +0 -133
- package/transpiled/providers/Memory.d.ts +0 -13
- package/transpiled/providers/Memory.js +0 -60
- package/transpiled/providers/Memory.js.map +0 -1
|
@@ -32,9 +32,11 @@ const node_buffer_1 = require("node:buffer");
|
|
|
32
32
|
const posix_1 = require("node:path/posix");
|
|
33
33
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
34
34
|
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
35
|
-
const
|
|
35
|
+
const s3 = __importStar(require("@aws-sdk/client-s3"));
|
|
36
36
|
const nodeNativeFetch = __importStar(require("smithy-node-native-fetch"));
|
|
37
|
+
const openspan_1 = require("openspan");
|
|
37
38
|
const Provider_1 = require("../Provider");
|
|
39
|
+
const errors_1 = require("../errors");
|
|
38
40
|
class S3 extends Provider_1.Provider {
|
|
39
41
|
static SECRETS = [
|
|
40
42
|
{ name: 'ACCESS_KEY_ID', optional: true },
|
|
@@ -43,7 +45,7 @@ class S3 extends Provider_1.Provider {
|
|
|
43
45
|
bucket;
|
|
44
46
|
client;
|
|
45
47
|
constructor(options, secrets) {
|
|
46
|
-
super(options);
|
|
48
|
+
super(options, secrets);
|
|
47
49
|
this.bucket = options.bucket;
|
|
48
50
|
const s3Config = {
|
|
49
51
|
retryMode: 'adaptive',
|
|
@@ -62,13 +64,13 @@ class S3 extends Provider_1.Provider {
|
|
|
62
64
|
secretAccessKey: secrets.SECRET_ACCESS_KEY
|
|
63
65
|
};
|
|
64
66
|
}
|
|
65
|
-
this.client = new
|
|
67
|
+
this.client = new s3.S3Client(s3Config);
|
|
66
68
|
this.client.middlewareStack.add((next, _context) => async (args) => {
|
|
69
|
+
// removes leading slash
|
|
67
70
|
if ('Key' in args.input && typeof args.input.Key === 'string')
|
|
68
|
-
// removes leading slash
|
|
69
71
|
args.input.Key = args.input.Key.replace(/^\//, '');
|
|
72
|
+
// removes leading slash and ensures finishing slash
|
|
70
73
|
if ('Prefix' in args.input && typeof args.input.Prefix === 'string')
|
|
71
|
-
// removes leading slash and ensures finishing slash
|
|
72
74
|
args.input.Prefix = args.input.Prefix.replace(/^\/|\/$/g, '') + '/';
|
|
73
75
|
return next(args);
|
|
74
76
|
}, {
|
|
@@ -78,76 +80,76 @@ class S3 extends Provider_1.Provider {
|
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
async get(Key) {
|
|
81
|
-
try {
|
|
82
|
-
const
|
|
83
|
+
return await this.try(async () => {
|
|
84
|
+
const entry = await this.client.send(new s3.GetObjectCommand({
|
|
83
85
|
Bucket: this.bucket,
|
|
84
86
|
Key
|
|
85
87
|
}));
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return null;
|
|
97
|
-
else
|
|
98
|
-
throw err;
|
|
99
|
-
}
|
|
88
|
+
const stream = entry.Body instanceof node_stream_1.Readable
|
|
89
|
+
? entry.Body
|
|
90
|
+
: node_stream_1.Readable.fromWeb((entry.Body instanceof node_buffer_1.Blob
|
|
91
|
+
? entry.Body.stream()
|
|
92
|
+
: entry.Body));
|
|
93
|
+
if (entry.Metadata?.value === undefined)
|
|
94
|
+
return errors_1.ERR_NOT_FOUND;
|
|
95
|
+
const metadata = JSON.parse(entry.Metadata.value);
|
|
96
|
+
return { stream, ...metadata };
|
|
97
|
+
});
|
|
100
98
|
}
|
|
101
|
-
async
|
|
99
|
+
async head(Key) {
|
|
100
|
+
return await this.try(async () => {
|
|
101
|
+
const entry = await this.client.send(new s3.HeadObjectCommand({
|
|
102
|
+
Bucket: this.bucket,
|
|
103
|
+
Key
|
|
104
|
+
}));
|
|
105
|
+
if (entry.Metadata?.value === undefined)
|
|
106
|
+
return errors_1.ERR_NOT_FOUND;
|
|
107
|
+
return JSON.parse(entry.Metadata.value);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async put(Key, stream) {
|
|
102
111
|
await new lib_storage_1.Upload({
|
|
103
112
|
client: this.client,
|
|
104
113
|
params: {
|
|
105
114
|
Bucket: this.bucket,
|
|
106
|
-
Key
|
|
115
|
+
Key,
|
|
107
116
|
Body: stream
|
|
108
117
|
}
|
|
109
118
|
}).done();
|
|
110
119
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
120
|
+
async commit(Key, metadata) {
|
|
121
|
+
await this.client.send(new s3.CopyObjectCommand({
|
|
122
|
+
Bucket: this.bucket,
|
|
123
|
+
Key,
|
|
124
|
+
CopySource: (0, posix_1.join)(this.bucket, Key),
|
|
125
|
+
Metadata: { value: JSON.stringify(metadata) },
|
|
126
|
+
MetadataDirective: 'REPLACE'
|
|
127
|
+
}));
|
|
128
|
+
openspan_1.console.debug('Uploaded to S3', { bucket: this.bucket, path: Key, metadata });
|
|
129
|
+
}
|
|
116
130
|
async delete(Key) {
|
|
117
|
-
|
|
118
|
-
// checking if given key is a single file
|
|
119
|
-
if (!Key.endsWith('/'))
|
|
120
|
-
try {
|
|
121
|
-
// DeleteObject on S3 returns no error if object does not exist
|
|
122
|
-
await client.send(new client_s3_1.HeadObjectCommand({ Bucket, Key }));
|
|
123
|
-
await client.send(new client_s3_1.DeleteObjectCommand({ Bucket, Key }));
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
catch (err) {
|
|
127
|
-
node_assert_1.default.ok(err instanceof client_s3_1.NotFound || err instanceof client_s3_1.NoSuchKey, err);
|
|
128
|
-
}
|
|
129
|
-
const objectsToRemove = [];
|
|
130
|
-
for await (const page of (0, client_s3_1.paginateListObjectsV2)({ client }, { Bucket, Prefix: Key }))
|
|
131
|
-
for (const { Key } of page.Contents ?? [])
|
|
132
|
-
objectsToRemove.push({ Key });
|
|
133
|
-
// Removing all objects in parallel in batches
|
|
134
|
-
await Promise.all((function* () {
|
|
135
|
-
while (objectsToRemove.length > 0)
|
|
136
|
-
yield client.send(new client_s3_1.DeleteObjectsCommand({
|
|
137
|
-
Bucket,
|
|
138
|
-
Delete: {
|
|
139
|
-
Objects: objectsToRemove.splice(0, 1000 /* max batch size for DeleteObjects */)
|
|
140
|
-
}
|
|
141
|
-
}));
|
|
142
|
-
})());
|
|
131
|
+
await this.client.send(new s3.DeleteObjectCommand({ Bucket: this.bucket, Key }));
|
|
143
132
|
}
|
|
144
133
|
async move(from, keyTo) {
|
|
145
|
-
await this.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
134
|
+
return await this.try(async () => {
|
|
135
|
+
await this.client.send(new s3.CopyObjectCommand({
|
|
136
|
+
Bucket: this.bucket,
|
|
137
|
+
Key: keyTo,
|
|
138
|
+
CopySource: (0, posix_1.join)(this.bucket, from)
|
|
139
|
+
}));
|
|
140
|
+
await this.client.send(new s3.DeleteObjectCommand({ Bucket: this.bucket, Key: from }));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
async try(action) {
|
|
144
|
+
try {
|
|
145
|
+
return await action();
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
if (err?.name === 'NotFound' || err?.name === 'NoSuchKey')
|
|
149
|
+
return errors_1.ERR_NOT_FOUND;
|
|
150
|
+
else
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
151
153
|
}
|
|
152
154
|
}
|
|
153
155
|
exports.S3 = S3;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"S3.js","sourceRoot":"","sources":["../../source/providers/S3.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAsC;AACtC,6CAAkC;AAClC,2CAAsC;AACtC,8DAAgC;AAChC,sDAA6C;AAC7C,
|
|
1
|
+
{"version":3,"file":"S3.js","sourceRoot":"","sources":["../../source/providers/S3.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAsC;AACtC,6CAAkC;AAClC,2CAAsC;AACtC,8DAAgC;AAChC,sDAA6C;AAC7C,uDAAwC;AACxC,0EAA2D;AAC3D,uCAAkC;AAClC,0CAAsC;AACtC,sCAAyC;AAezC,MAAa,EAAG,SAAQ,mBAAmB;IAClC,MAAM,CAAmB,OAAO,GAA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AAa,CAAA;;gBAEpB,MAAM,GAAG,CAAA;QACb,CAAC;IACH,CAAC;;AA7IH,gBA8IC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { FileSystem } from './FileSystem';
|
|
2
|
-
import type { ProviderSecrets } from '../Provider';
|
|
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
|
}
|
|
@@ -5,9 +5,9 @@ const node_os_1 = require("node:os");
|
|
|
5
5
|
const node_path_1 = require("node:path");
|
|
6
6
|
const FileSystem_1 = require("./FileSystem");
|
|
7
7
|
class Temporary extends FileSystem_1.FileSystem {
|
|
8
|
-
constructor(options
|
|
8
|
+
constructor(options) {
|
|
9
9
|
const path = (0, node_path_1.join)((0, node_os_1.tmpdir)(), options.directory);
|
|
10
|
-
super({ path }
|
|
10
|
+
super({ path });
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.Temporary = Temporary;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Temporary.js","sourceRoot":"","sources":["../../source/providers/Temporary.ts"],"names":[],"mappings":";;;AAAA,qCAAgC;AAChC,yCAAgC;AAChC,6CAAyC;
|
|
1
|
+
{"version":3,"file":"Temporary.js","sourceRoot":"","sources":["../../source/providers/Temporary.ts"],"names":[],"mappings":";;;AAAA,qCAAgC;AAChC,yCAAgC;AAChC,6CAAyC;AAMzC,MAAa,SAAU,SAAQ,uBAAU;IACvC,YAAoB,OAAyB;QAC3C,MAAM,IAAI,GAAG,IAAA,gBAAI,EAAC,IAAA,gBAAM,GAAE,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;QAE9C,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IACjB,CAAC;CACF;AAND,8BAMC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporary, type TemporaryOptions } from './Temporary';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Secret } from '../Secrets';
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Test.js","sourceRoot":"","sources":["../../source/providers/Test.ts"],"names":[],"mappings":";;;AAAA,2CAA8D;AAG9D,MAAa,IAAK,SAAQ,qBAAS;IAC1B,MAAM,CAAmB,OAAO,
|
|
1
|
+
{"version":3,"file":"Test.js","sourceRoot":"","sources":["../../source/providers/Test.ts"],"names":[],"mappings":";;;AAAA,2CAA8D;AAG9D,MAAa,IAAK,SAAQ,qBAAS;IAC1B,MAAM,CAAmB,OAAO,GAAsB;QAC3D,EAAE,IAAI,EAAE,UAAU,EAAE;QACpB,EAAE,IAAI,EAAE,UAAU,EAAE;KACrB,CAAA;IAED,YAAoB,OAAyB;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;;AARH,oBASC"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { FileSystem } from './FileSystem';
|
|
2
2
|
import { S3 } from './S3';
|
|
3
|
+
import { Cloudinary } from './Cloudinary';
|
|
3
4
|
import { Temporary } from './Temporary';
|
|
4
5
|
import { Test } from './Test';
|
|
5
|
-
import { InMemory } from './Memory';
|
|
6
6
|
export declare const providers: {
|
|
7
7
|
readonly s3: typeof S3;
|
|
8
|
+
readonly cloudinary: typeof Cloudinary;
|
|
8
9
|
readonly fs: typeof FileSystem;
|
|
9
10
|
readonly tmp: typeof Temporary;
|
|
10
|
-
readonly mem: typeof InMemory;
|
|
11
11
|
readonly test: typeof Test;
|
|
12
12
|
};
|
|
13
13
|
export type { Declaration } from './Declaration';
|
|
14
|
+
export type { S3Options } from './S3';
|
|
15
|
+
export type { CloudinaryOptions } from './Cloudinary';
|
|
16
|
+
export type { FileSystemOptions } from './FileSystem';
|
|
17
|
+
export type { TemporaryOptions } from './Temporary';
|
|
18
|
+
export type { FileSystem, S3, Cloudinary, Temporary };
|
|
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.providers = void 0;
|
|
4
4
|
const FileSystem_1 = require("./FileSystem");
|
|
5
5
|
const S3_1 = require("./S3");
|
|
6
|
+
const Cloudinary_1 = require("./Cloudinary");
|
|
6
7
|
const Temporary_1 = require("./Temporary");
|
|
7
8
|
const Test_1 = require("./Test");
|
|
8
|
-
const Memory_1 = require("./Memory");
|
|
9
9
|
exports.providers = {
|
|
10
10
|
s3: S3_1.S3,
|
|
11
|
+
cloudinary: Cloudinary_1.Cloudinary,
|
|
11
12
|
fs: FileSystem_1.FileSystem,
|
|
12
13
|
tmp: Temporary_1.Temporary,
|
|
13
|
-
mem: Memory_1.InMemory,
|
|
14
14
|
test: Test_1.Test
|
|
15
15
|
};
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/providers/index.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,6BAAyB;AACzB,2CAAuC;AACvC,iCAA6B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/providers/index.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,6BAAyB;AACzB,6CAAyC;AACzC,2CAAuC;AACvC,iCAA6B;AAGhB,QAAA,SAAS,GAAG;IACvB,EAAE,EAAE,OAAE;IACN,UAAU,EAAE,uBAAU;IACtB,EAAE,EAAE,uBAAU;IACd,GAAG,EAAE,qBAAS;IACd,IAAI,EAAE,WAAI;CACoC,CAAA"}
|
package/transpiled/schemas.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Schema } from '@toa.io/schemas';
|
|
|
3
3
|
import type { Annotation } from './Annotation';
|
|
4
4
|
export declare const annotation: Schema<Annotation>;
|
|
5
5
|
export declare const s3: Schema<Declaration>;
|
|
6
|
+
export declare const cloudinary: Schema<Declaration>;
|
|
6
7
|
export declare const fs: Schema<Declaration>;
|
|
7
8
|
export declare const mem: Schema<Declaration>;
|
|
8
9
|
export declare const tmp: Schema<Declaration>;
|
package/transpiled/schemas.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.test = exports.tmp = exports.mem = exports.fs = exports.s3 = exports.annotation = void 0;
|
|
3
|
+
exports.test = exports.tmp = exports.mem = exports.fs = exports.cloudinary = exports.s3 = exports.annotation = void 0;
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
5
|
const schemas_1 = require("@toa.io/schemas");
|
|
6
6
|
const path = (0, node_path_1.resolve)(__dirname, '../schemas');
|
|
7
7
|
const ns = (0, schemas_1.namespace)(path);
|
|
8
8
|
exports.annotation = ns.schema('annotation');
|
|
9
9
|
exports.s3 = ns.schema('s3');
|
|
10
|
+
exports.cloudinary = ns.schema('cloudinary');
|
|
10
11
|
exports.fs = ns.schema('fs');
|
|
11
12
|
exports.mem = ns.schema('mem');
|
|
12
13
|
exports.tmp = ns.schema('tmp');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":";;;AAAA,yCAAmC;AACnC,6CAA2C;AAK3C,MAAM,IAAI,GAAG,IAAA,mBAAO,EAAC,SAAS,EAAE,YAAY,CAAC,CAAA;AAC7C,MAAM,EAAE,GAAG,IAAA,mBAAS,EAAC,IAAI,CAAC,CAAA;AAEb,QAAA,UAAU,GAAuB,EAAE,CAAC,MAAM,CAAa,YAAY,CAAC,CAAA;AACpE,QAAA,EAAE,GAAwB,EAAE,CAAC,MAAM,CAAc,IAAI,CAAC,CAAA;AACtD,QAAA,EAAE,GAAwB,EAAE,CAAC,MAAM,CAAc,IAAI,CAAC,CAAA;AACtD,QAAA,GAAG,GAAwB,EAAE,CAAC,MAAM,CAAc,KAAK,CAAC,CAAA;AACxD,QAAA,GAAG,GAAwB,EAAE,CAAC,MAAM,CAAc,KAAK,CAAC,CAAA;AACxD,QAAA,IAAI,GAAwB,EAAE,CAAC,MAAM,CAAc,MAAM,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":";;;AAAA,yCAAmC;AACnC,6CAA2C;AAK3C,MAAM,IAAI,GAAG,IAAA,mBAAO,EAAC,SAAS,EAAE,YAAY,CAAC,CAAA;AAC7C,MAAM,EAAE,GAAG,IAAA,mBAAS,EAAC,IAAI,CAAC,CAAA;AAEb,QAAA,UAAU,GAAuB,EAAE,CAAC,MAAM,CAAa,YAAY,CAAC,CAAA;AACpE,QAAA,EAAE,GAAwB,EAAE,CAAC,MAAM,CAAc,IAAI,CAAC,CAAA;AACtD,QAAA,UAAU,GAAwB,EAAE,CAAC,MAAM,CAAc,YAAY,CAAC,CAAA;AACtE,QAAA,EAAE,GAAwB,EAAE,CAAC,MAAM,CAAc,IAAI,CAAC,CAAA;AACtD,QAAA,GAAG,GAAwB,EAAE,CAAC,MAAM,CAAc,KAAK,CAAC,CAAA;AACxD,QAAA,GAAG,GAAwB,EAAE,CAAC,MAAM,CAAc,KAAK,CAAC,CAAA;AACxD,QAAA,IAAI,GAAwB,EAAE,CAAC,MAAM,CAAc,MAAM,CAAC,CAAA"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Secrets } from '../Secrets';
|
|
2
|
+
import type { providers, S3Options, CloudinaryOptions, FileSystemOptions, TemporaryOptions } from '../providers';
|
|
1
3
|
export declare const suites: ({
|
|
2
4
|
run: true;
|
|
3
5
|
provider: "tmp";
|
|
@@ -6,13 +8,12 @@ export declare const suites: ({
|
|
|
6
8
|
endpoint?: undefined;
|
|
7
9
|
region?: undefined;
|
|
8
10
|
bucket?: undefined;
|
|
11
|
+
environment?: undefined;
|
|
12
|
+
type?: undefined;
|
|
13
|
+
prefix?: undefined;
|
|
14
|
+
transformations?: undefined;
|
|
9
15
|
};
|
|
10
16
|
secrets?: undefined;
|
|
11
|
-
} | {
|
|
12
|
-
run: true;
|
|
13
|
-
provider: "mem";
|
|
14
|
-
options?: undefined;
|
|
15
|
-
secrets?: undefined;
|
|
16
17
|
} | {
|
|
17
18
|
run: boolean;
|
|
18
19
|
provider: "s3";
|
|
@@ -21,9 +22,92 @@ export declare const suites: ({
|
|
|
21
22
|
region: string;
|
|
22
23
|
bucket: string;
|
|
23
24
|
directory?: undefined;
|
|
25
|
+
environment?: undefined;
|
|
26
|
+
type?: undefined;
|
|
27
|
+
prefix?: undefined;
|
|
28
|
+
transformations?: undefined;
|
|
24
29
|
};
|
|
25
30
|
secrets: {
|
|
26
31
|
ACCESS_KEY_ID: string;
|
|
27
32
|
SECRET_ACCESS_KEY: string;
|
|
33
|
+
API_KEY?: undefined;
|
|
34
|
+
API_SECRET?: undefined;
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
run: boolean;
|
|
38
|
+
provider: "cloudinary";
|
|
39
|
+
options: {
|
|
40
|
+
environment: string;
|
|
41
|
+
type: "image";
|
|
42
|
+
prefix: string;
|
|
43
|
+
transformations: ({
|
|
44
|
+
extension: string;
|
|
45
|
+
transformation: {
|
|
46
|
+
width: string;
|
|
47
|
+
height: string;
|
|
48
|
+
zoom: string;
|
|
49
|
+
crop: string;
|
|
50
|
+
gravity: string;
|
|
51
|
+
angle?: undefined;
|
|
52
|
+
fetch_format?: undefined;
|
|
53
|
+
};
|
|
54
|
+
optional: true;
|
|
55
|
+
condition?: undefined;
|
|
56
|
+
} | {
|
|
57
|
+
extension: string;
|
|
58
|
+
transformation: {
|
|
59
|
+
width: string;
|
|
60
|
+
height: string;
|
|
61
|
+
zoom: string;
|
|
62
|
+
crop: string;
|
|
63
|
+
gravity?: undefined;
|
|
64
|
+
angle?: undefined;
|
|
65
|
+
fetch_format?: undefined;
|
|
66
|
+
};
|
|
67
|
+
optional: true;
|
|
68
|
+
condition?: undefined;
|
|
69
|
+
} | {
|
|
70
|
+
extension: string;
|
|
71
|
+
condition: string;
|
|
72
|
+
transformation: {
|
|
73
|
+
angle: number;
|
|
74
|
+
width?: undefined;
|
|
75
|
+
height?: undefined;
|
|
76
|
+
zoom?: undefined;
|
|
77
|
+
crop?: undefined;
|
|
78
|
+
gravity?: undefined;
|
|
79
|
+
fetch_format?: undefined;
|
|
80
|
+
};
|
|
81
|
+
optional: true;
|
|
82
|
+
} | {
|
|
83
|
+
extension: string;
|
|
84
|
+
transformation: {
|
|
85
|
+
fetch_format: string;
|
|
86
|
+
width?: undefined;
|
|
87
|
+
height?: undefined;
|
|
88
|
+
zoom?: undefined;
|
|
89
|
+
crop?: undefined;
|
|
90
|
+
gravity?: undefined;
|
|
91
|
+
angle?: undefined;
|
|
92
|
+
};
|
|
93
|
+
optional: true;
|
|
94
|
+
condition?: undefined;
|
|
95
|
+
})[];
|
|
96
|
+
directory?: undefined;
|
|
97
|
+
endpoint?: undefined;
|
|
98
|
+
region?: undefined;
|
|
99
|
+
bucket?: undefined;
|
|
100
|
+
};
|
|
101
|
+
secrets: {
|
|
102
|
+
API_KEY: string;
|
|
103
|
+
API_SECRET: string;
|
|
104
|
+
ACCESS_KEY_ID?: undefined;
|
|
105
|
+
SECRET_ACCESS_KEY?: undefined;
|
|
28
106
|
};
|
|
29
107
|
})[];
|
|
108
|
+
export interface Suite {
|
|
109
|
+
run: boolean;
|
|
110
|
+
provider: keyof typeof providers;
|
|
111
|
+
options?: S3Options | CloudinaryOptions | FileSystemOptions | TemporaryOptions;
|
|
112
|
+
secrets?: Secrets;
|
|
113
|
+
}
|
package/transpiled/test/util.js
CHANGED
|
@@ -15,10 +15,6 @@ exports.suites = [
|
|
|
15
15
|
directory: 'toa-storages-temp'
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
|
-
{
|
|
19
|
-
run: true,
|
|
20
|
-
provider: 'mem'
|
|
21
|
-
},
|
|
22
18
|
{
|
|
23
19
|
run: process.env.RUN_S3 === '1',
|
|
24
20
|
provider: 's3',
|
|
@@ -31,6 +27,57 @@ exports.suites = [
|
|
|
31
27
|
ACCESS_KEY_ID: 'developer',
|
|
32
28
|
SECRET_ACCESS_KEY: 'secret'
|
|
33
29
|
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
run: process.env.RUN_CLOUDINARY === '1',
|
|
33
|
+
provider: 'cloudinary',
|
|
34
|
+
options: {
|
|
35
|
+
environment: 'dl5z4zgth',
|
|
36
|
+
type: 'image',
|
|
37
|
+
prefix: 'toa-dev',
|
|
38
|
+
transformations: [
|
|
39
|
+
{
|
|
40
|
+
extension: '(?<width>\\d*)x(?<height>\\d*)(z(?<zoom>\\d*))?',
|
|
41
|
+
transformation: {
|
|
42
|
+
width: '<width>',
|
|
43
|
+
height: '<height>',
|
|
44
|
+
zoom: '<zoom>',
|
|
45
|
+
crop: 'thumb',
|
|
46
|
+
gravity: 'face'
|
|
47
|
+
},
|
|
48
|
+
optional: true
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
extension: '\\[(?<width>\\d*)x(?<height>\\d*)\\](z(?<zoom>\\d+))?',
|
|
52
|
+
transformation: {
|
|
53
|
+
width: '<width>',
|
|
54
|
+
height: '<height>',
|
|
55
|
+
zoom: '<zoom>',
|
|
56
|
+
crop: 'fit'
|
|
57
|
+
},
|
|
58
|
+
optional: true
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
extension: 'vertical',
|
|
62
|
+
condition: 'w_gt_h',
|
|
63
|
+
transformation: {
|
|
64
|
+
angle: 90
|
|
65
|
+
},
|
|
66
|
+
optional: true
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
extension: '(?<format>jpeg|webp)',
|
|
70
|
+
transformation: {
|
|
71
|
+
fetch_format: '<format>'
|
|
72
|
+
},
|
|
73
|
+
optional: true
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
secrets: {
|
|
78
|
+
API_KEY: process.env.CLOUDINARY_API_KEY ?? '',
|
|
79
|
+
API_SECRET: process.env.CLOUDINARY_API_SECRET ?? ''
|
|
80
|
+
}
|
|
34
81
|
}
|
|
35
82
|
// add more providers here, use `run` as a condition to run the test
|
|
36
83
|
// e.g.: `run: process.env.ACCESS_KEY_ID !== undefined`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../source/test/util.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAgC;AAChC,oDAA2B;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../source/test/util.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAgC;AAChC,oDAA2B;AAU3B,gBAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAA,gBAAI,EAAC,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,CAAA;AAEnC,QAAA,MAAM,GAAG;IACpB;QACE,GAAG,EAAE,IAAI;QACT,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE;YACP,SAAS,EAAE,mBAAmB;SAC/B;KACF;IACD;QACE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,KAAK,GAAG;QAC/B,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE;YACP,QAAQ,EAAE,uBAAuB;YACjC,MAAM,EAAE,WAAW;YACnB,MAAM,EAAE,aAAa;SACtB;QACD,OAAO,EAAE;YACP,aAAa,EAAE,WAAW;YAC1B,iBAAiB,EAAE,QAAQ;SAC5B;KACF;IACD;QACE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,GAAG;QACvC,QAAQ,EAAE,YAAY;QACtB,OAAO,EAAE;YACP,WAAW,EAAE,WAAW;YACxB,IAAI,EAAE,OA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