@toa.io/extensions.storages 0.24.0-alpha.9 → 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 +11 -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 +1 -1
- package/transpiled/Aspect.js +7 -3
- package/transpiled/Aspect.js.map +1 -1
- package/transpiled/Factory.d.ts +2 -3
- package/transpiled/Factory.js +24 -21
- package/transpiled/Factory.js.map +1 -1
- package/transpiled/Provider.d.ts +17 -5
- package/transpiled/Provider.js +33 -0
- package/transpiled/Provider.js.map +1 -1
- package/transpiled/Scanner.d.ts +2 -2
- package/transpiled/Scanner.js +2 -2
- package/transpiled/Scanner.js.map +1 -1
- package/transpiled/Storage.d.ts +6 -2
- package/transpiled/Storage.js +5 -5
- package/transpiled/Storage.js.map +1 -1
- package/transpiled/deployment.d.ts +2 -3
- package/transpiled/deployment.js +39 -23
- package/transpiled/deployment.js.map +1 -1
- 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 +7 -3
- package/transpiled/providers/FileSystem.js +17 -14
- package/transpiled/providers/FileSystem.js.map +1 -1
- 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 +20 -6
- package/transpiled/providers/S3.js +111 -32
- package/transpiled/providers/S3.js.map +1 -1
- package/transpiled/providers/Temporary.d.ts +5 -2
- package/transpiled/providers/Temporary.js +3 -4
- package/transpiled/providers/Temporary.js.map +1 -1
- package/transpiled/providers/Test.d.ts +4 -3
- package/transpiled/providers/Test.js +6 -9
- package/transpiled/providers/Test.js.map +1 -1
- package/transpiled/providers/index.d.ts +12 -4
- package/transpiled/providers/index.js +6 -4
- package/transpiled/providers/index.js.map +1 -1
- 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 -10
- package/transpiled/test/util.js +17 -40
- package/transpiled/test/util.js.map +1 -1
- package/transpiled/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as schemas from './schemas'
|
|
2
|
+
|
|
3
|
+
const ok = {
|
|
4
|
+
a: {
|
|
5
|
+
provider: 'tmp',
|
|
6
|
+
directory: 'ok'
|
|
7
|
+
},
|
|
8
|
+
b: {
|
|
9
|
+
provider: 'fs',
|
|
10
|
+
path: 'ok'
|
|
11
|
+
},
|
|
12
|
+
c: {
|
|
13
|
+
provider: 's3',
|
|
14
|
+
bucket: 'my-bucket'
|
|
15
|
+
},
|
|
16
|
+
d: {
|
|
17
|
+
provider: 'mem'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const oh = [
|
|
22
|
+
{
|
|
23
|
+
whatever: {
|
|
24
|
+
provider: 'non-existent'
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
whatever: {
|
|
29
|
+
provider: 'fs'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
whatever: {
|
|
34
|
+
provider: 'tmp',
|
|
35
|
+
extra: true
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
whatever: {
|
|
40
|
+
|
|
41
|
+
provider: 's3'
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
whatever: {
|
|
46
|
+
provider: 'mem',
|
|
47
|
+
extra: true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
it('should pass', () => {
|
|
53
|
+
expect(() => schemas.annotation.validate(ok)).not.toThrow()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it.each(oh)('should fail', (value) => {
|
|
57
|
+
expect(() => schemas.annotation.validate(value)).toThrow()
|
|
58
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
import { namespace } from '@toa.io/schemas'
|
|
3
|
+
import type { Declaration } from './providers'
|
|
4
|
+
import type { Schema } from '@toa.io/schemas'
|
|
5
|
+
import type { Annotation } from './Annotation'
|
|
6
|
+
|
|
7
|
+
const path = resolve(__dirname, '../schemas')
|
|
8
|
+
const ns = namespace(path)
|
|
9
|
+
|
|
10
|
+
export const annotation: Schema<Annotation> = ns.schema<Annotation>('annotation')
|
|
11
|
+
export const s3: Schema<Declaration> = ns.schema<Declaration>('s3')
|
|
12
|
+
export const fs: Schema<Declaration> = ns.schema<Declaration>('fs')
|
|
13
|
+
export const mem: Schema<Declaration> = ns.schema<Declaration>('mem')
|
|
14
|
+
export const tmp: Schema<Declaration> = ns.schema<Declaration>('tmp')
|
|
15
|
+
export const test: Schema<Declaration> = ns.schema<Declaration>('test')
|
package/source/test/util.ts
CHANGED
|
@@ -1,74 +1,45 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
|
-
import fs from 'node:fs/promises'
|
|
3
|
-
import { createReadStream, type ReadStream } from 'node:fs'
|
|
4
|
-
import { CreateBucketCommand, S3Client } from '@aws-sdk/client-s3'
|
|
5
2
|
import dotenv from 'dotenv'
|
|
3
|
+
import type { ProviderSecrets } from '../Provider'
|
|
4
|
+
import type { providers } from '../providers'
|
|
5
|
+
import type { FileSystemOptions } from '../providers/FileSystem'
|
|
6
|
+
import type { S3Options } from '../providers/S3'
|
|
7
|
+
import type { TemporaryOptions } from '../providers/Temporary'
|
|
6
8
|
|
|
7
9
|
dotenv.config({ path: join(__dirname, '.env') })
|
|
8
10
|
|
|
9
|
-
const suites
|
|
11
|
+
export const suites = [
|
|
10
12
|
{
|
|
11
13
|
run: true,
|
|
12
|
-
|
|
14
|
+
provider: 'tmp',
|
|
15
|
+
options: {
|
|
16
|
+
directory: 'toa-storages-temp'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
run: true,
|
|
21
|
+
provider: 'mem'
|
|
13
22
|
},
|
|
14
23
|
{
|
|
15
24
|
run: process.env.RUN_S3 === '1',
|
|
16
|
-
|
|
25
|
+
provider: 's3',
|
|
26
|
+
options: {
|
|
27
|
+
endpoint: 'http://localhost:4566',
|
|
28
|
+
region: 'us-west-1',
|
|
29
|
+
bucket: 'test-bucket'
|
|
30
|
+
},
|
|
17
31
|
secrets: {
|
|
18
32
|
ACCESS_KEY_ID: 'developer',
|
|
19
33
|
SECRET_ACCESS_KEY: 'secret'
|
|
20
|
-
}
|
|
21
|
-
init: initS3
|
|
34
|
+
}
|
|
22
35
|
}
|
|
23
36
|
// add more providers here, use `run` as a condition to run the test
|
|
24
37
|
// e.g.: `run: process.env.ACCESS_KEY_ID !== undefined`
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
function map (suite: Suite): Case {
|
|
28
|
-
const url = new URL(suite.ref)
|
|
29
|
-
|
|
30
|
-
return [url.protocol, url, suite.secrets ?? {}, suite.init]
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const cases = suites.filter(({ run }) => run).map(map)
|
|
34
|
-
|
|
35
|
-
export function rnd (): string {
|
|
36
|
-
return Math.random().toString(36).slice(2)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function open (rel: string): ReadStream {
|
|
40
|
-
const path = join(__dirname, rel)
|
|
41
|
-
|
|
42
|
-
return createReadStream(path)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function read (rel: string): Promise<Buffer> {
|
|
46
|
-
const path = join(__dirname, rel)
|
|
47
|
-
|
|
48
|
-
return await fs.readFile(path)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function initS3 (url: URL, secrets: Record<string, string>): Promise<void> {
|
|
52
|
-
const client = new S3Client({
|
|
53
|
-
credentials: {
|
|
54
|
-
accessKeyId: secrets.ACCESS_KEY_ID,
|
|
55
|
-
secretAccessKey: secrets.SECRET_ACCESS_KEY
|
|
56
|
-
},
|
|
57
|
-
region: url.host,
|
|
58
|
-
endpoint: url.searchParams.get('endpoint') ?? undefined
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
const command = new CreateBucketCommand({ Bucket: url.pathname.substring(1) })
|
|
62
|
-
|
|
63
|
-
await client.send(command).catch(() => undefined)
|
|
64
|
-
}
|
|
38
|
+
] satisfies Suite[]
|
|
65
39
|
|
|
66
40
|
interface Suite {
|
|
67
41
|
run: boolean
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
42
|
+
provider: keyof typeof providers
|
|
43
|
+
options?: FileSystemOptions | S3Options | TemporaryOptions
|
|
44
|
+
secrets?: ProviderSecrets
|
|
71
45
|
}
|
|
72
|
-
|
|
73
|
-
type SuiteInit = (url: URL, secrets: Record<string, string>) => Promise<void> | void
|
|
74
|
-
type Case = [string, URL, Record<string, string>, SuiteInit?]
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
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.validateAnnotation = void 0;
|
|
30
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
31
|
+
const providers_1 = require("./providers");
|
|
32
|
+
const schemas = __importStar(require("./schemas"));
|
|
33
|
+
function validateAnnotation(annotation) {
|
|
34
|
+
try {
|
|
35
|
+
schemas.annotation.validate(annotation);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
explain(annotation);
|
|
39
|
+
// if all declarations are valid, re-throw the error
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.validateAnnotation = validateAnnotation;
|
|
44
|
+
/*
|
|
45
|
+
It is required because `oneOf` schema is used for the annotation validation.
|
|
46
|
+
*/
|
|
47
|
+
function explain(annotation) {
|
|
48
|
+
node_assert_1.default.ok(typeof annotation === 'object' && annotation !== null, 'TOA_STORAGES is not an object');
|
|
49
|
+
for (const declaration of Object.values(annotation)) {
|
|
50
|
+
node_assert_1.default.ok(typeof declaration === 'object' && declaration !== null &&
|
|
51
|
+
declaration.provider in providers_1.providers, `Unknown provider '${declaration.provider}'`);
|
|
52
|
+
node_assert_1.default.ok(declaration.provider in schemas, `No schema for provider '${declaration.provider}'`);
|
|
53
|
+
const schema = schemas[declaration.provider];
|
|
54
|
+
schema.validate(declaration, `Storage '${declaration.provider}' annotation`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=Annotation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Annotation.js","sourceRoot":"","sources":["../source/Annotation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAgC;AAChC,2CAAuC;AACvC,mDAAoC;AAMpC,SAAgB,kBAAkB,CAAE,UAAmB;IACrD,IAAI,CAAC;QACH,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,UAAU,CAAC,CAAA;QAEnB,oDAAoD;QACpD,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC;AATD,gDASC;AAED;;GAEG;AACH,SAAS,OAAO,CAAE,UAAmB;IACnC,qBAAM,CAAC,EAAE,CAAC,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,IAAI,EAC7D,+BAA+B,CAAC,CAAA;IAElC,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QACpD,qBAAM,CAAC,EAAE,CAAC,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,IAAI;YAC/D,WAAW,CAAC,QAAQ,IAAI,qBAAS,EACjC,qBAAqB,WAAW,CAAC,QAAQ,GAAG,CAAC,CAAA;QAE/C,qBAAM,CAAC,EAAE,CAAC,WAAW,CAAC,QAAQ,IAAI,OAAO,EACvC,2BAA2B,WAAW,CAAC,QAAQ,GAAG,CAAC,CAAA;QAErD,MAAM,MAAM,GAAwB,OAAO,CAAC,WAAW,CAAC,QAAkC,CAAC,CAAA;QAE3F,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,YAAY,WAAW,CAAC,QAAQ,cAAc,CAAC,CAAA;IAC9E,CAAC;AACH,CAAC"}
|
package/transpiled/Aspect.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export declare class Aspect extends Connector implements extensions.Aspect {
|
|
|
4
4
|
readonly name = "storages";
|
|
5
5
|
private readonly storages;
|
|
6
6
|
constructor(storages: Storages);
|
|
7
|
-
invoke(name: string, method: keyof Storage, ...args:
|
|
7
|
+
invoke(name: string, method: keyof Storage, ...args: unknown[]): unknown;
|
|
8
8
|
}
|
package/transpiled/Aspect.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Aspect = void 0;
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
4
8
|
const core_1 = require("@toa.io/core");
|
|
5
9
|
class Aspect extends core_1.Connector {
|
|
6
10
|
name = 'storages';
|
|
@@ -10,11 +14,11 @@ class Aspect extends core_1.Connector {
|
|
|
10
14
|
this.storages = storages;
|
|
11
15
|
}
|
|
12
16
|
invoke(name, method, ...args) {
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
const storage = this.storages[name];
|
|
18
|
+
node_assert_1.default.ok(storage !== undefined, `Storage '${name}' is not defined`);
|
|
15
19
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
20
|
// @ts-expect-error
|
|
17
|
-
return
|
|
21
|
+
return storage[method](...args);
|
|
18
22
|
}
|
|
19
23
|
}
|
|
20
24
|
exports.Aspect = Aspect;
|
package/transpiled/Aspect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Aspect.js","sourceRoot":"","sources":["../source/Aspect.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Aspect.js","sourceRoot":"","sources":["../source/Aspect.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAgC;AAChC,uCAAyD;AAGzD,MAAa,MAAO,SAAQ,gBAAS;IACnB,IAAI,GAAG,UAAU,CAAA;IAEhB,QAAQ,CAAU;IAEnC,YAAoB,QAAkB;QACpC,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAEM,MAAM,CAAE,IAAY,EAAE,MAAqB,EAAE,GAAG,IAAe;QACpE,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAEnC,qBAAM,CAAC,EAAE,CAAC,OAAO,KAAK,SAAS,EAAE,YAAY,IAAI,kBAAkB,CAAC,CAAA;QAEpE,6DAA6D;QAC7D,mBAAmB;QACnB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;IACjC,CAAC;CACF;AApBD,wBAoBC"}
|
package/transpiled/Factory.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Storage } from './Storage';
|
|
2
1
|
import { Aspect } from './Aspect';
|
|
3
2
|
export declare class Factory {
|
|
4
|
-
private readonly
|
|
3
|
+
private readonly annotation;
|
|
5
4
|
constructor();
|
|
6
5
|
aspect(): Aspect;
|
|
7
|
-
createStorage(name: string, ref: string): Storage;
|
|
8
6
|
private createStorages;
|
|
7
|
+
private createStorage;
|
|
9
8
|
private resolveSecrets;
|
|
10
9
|
}
|
package/transpiled/Factory.js
CHANGED
|
@@ -1,47 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Factory = void 0;
|
|
4
|
-
const
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const generic_1 = require("@toa.io/generic");
|
|
5
9
|
const providers_1 = require("./providers");
|
|
6
10
|
const Storage_1 = require("./Storage");
|
|
7
11
|
const Aspect_1 = require("./Aspect");
|
|
12
|
+
const deployment_1 = require("./deployment");
|
|
13
|
+
const Annotation_1 = require("./Annotation");
|
|
8
14
|
class Factory {
|
|
9
|
-
|
|
15
|
+
annotation;
|
|
10
16
|
constructor() {
|
|
11
17
|
const env = process.env.TOA_STORAGES;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
node_assert_1.default.ok(env !== undefined, 'TOA_STORAGES is not defined');
|
|
19
|
+
this.annotation = (0, generic_1.decode)(env);
|
|
20
|
+
(0, Annotation_1.validateAnnotation)(this.annotation);
|
|
15
21
|
}
|
|
16
22
|
aspect() {
|
|
17
23
|
const storages = this.createStorages();
|
|
18
24
|
return new Aspect_1.Aspect(storages);
|
|
19
25
|
}
|
|
20
|
-
createStorage(name, ref) {
|
|
21
|
-
const url = new URL(ref);
|
|
22
|
-
const Provider = providers_1.providers[url.protocol];
|
|
23
|
-
if (Provider === undefined)
|
|
24
|
-
throw new Error(`No provider found for '${url.protocol}'`);
|
|
25
|
-
const secrets = this.resolveSecrets(name, Provider);
|
|
26
|
-
const provider = new Provider(url, secrets);
|
|
27
|
-
return new Storage_1.Storage(provider);
|
|
28
|
-
}
|
|
29
26
|
createStorages() {
|
|
30
27
|
const storages = {};
|
|
31
|
-
for (const [name,
|
|
32
|
-
storages[name] = this.createStorage(name,
|
|
28
|
+
for (const [name, declaration] of Object.entries(this.annotation))
|
|
29
|
+
storages[name] = this.createStorage(name, declaration);
|
|
33
30
|
return storages;
|
|
34
31
|
}
|
|
35
|
-
|
|
32
|
+
createStorage(name, declaration) {
|
|
33
|
+
const { provider: providerId, ...options } = declaration;
|
|
34
|
+
const Provider = providers_1.providers[providerId];
|
|
35
|
+
const secrets = this.resolveSecrets(name, Provider);
|
|
36
|
+
const provider = new Provider(options, secrets);
|
|
37
|
+
return new Storage_1.Storage(provider);
|
|
38
|
+
}
|
|
39
|
+
resolveSecrets(storageName, Class) {
|
|
36
40
|
if (Class.SECRETS === undefined)
|
|
37
41
|
return {};
|
|
38
42
|
const secrets = {};
|
|
39
43
|
for (const secret of Class.SECRETS) {
|
|
40
|
-
const variable =
|
|
44
|
+
const variable = `${deployment_1.SERIALIZATION_PREFIX}_${storageName}_${secret.name}`.toUpperCase();
|
|
41
45
|
const value = process.env[variable];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
secrets[secret] = value;
|
|
46
|
+
node_assert_1.default.ok(secret.optional === true || value !== undefined, `'${variable}' is not defined`);
|
|
47
|
+
secrets[secret.name] = value;
|
|
45
48
|
}
|
|
46
49
|
return secrets;
|
|
47
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory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,CAAA;IAC9B,CAAC;IAEO,cAAc,CAAE,WAAmB,EACzC,KAA0B;QAC1B,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS;YAC7B,OAAO,EAAE,CAAA;QAEX,MAAM,OAAO,GAAuC,EAAE,CAAA;QAEtD,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,GAAG,iCAAoB,IAAI,WAAW,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;YACtF,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YAEnC,qBAAM,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EACvD,IAAI,QAAQ,kBAAkB,CAAC,CAAA;YAEjC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;QAC9B,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AAxDD,0BAwDC"}
|
package/transpiled/Provider.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { type Readable } from 'node:stream';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export type ProviderSecrets<K extends string = string> = Record<K | string, string | undefined>;
|
|
4
|
+
export interface ProviderSecret {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly optional?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare abstract class Provider<Options = void> {
|
|
9
|
+
static readonly SECRETS: readonly ProviderSecret[];
|
|
10
|
+
constructor(_: Options, secrets?: ProviderSecrets);
|
|
11
|
+
abstract get(path: string): Promise<Readable | null>;
|
|
12
|
+
abstract put(path: string, filename: string, stream: Readable): Promise<void>;
|
|
13
|
+
abstract delete(path: string): Promise<void>;
|
|
14
|
+
abstract move(from: string, to: string): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export interface ProviderConstructor {
|
|
17
|
+
readonly SECRETS: readonly ProviderSecret[];
|
|
18
|
+
prototype: Provider;
|
|
19
|
+
new (options: any, secrets?: ProviderSecrets): Provider;
|
|
8
20
|
}
|
package/transpiled/Provider.js
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Provider = void 0;
|
|
27
|
+
const assert = __importStar(require("node:assert"));
|
|
28
|
+
class Provider {
|
|
29
|
+
static SECRETS = [];
|
|
30
|
+
constructor(_, secrets) {
|
|
31
|
+
for (const { name, optional = false } of new.target.SECRETS)
|
|
32
|
+
assert.ok(optional || secrets?.[name] !== undefined, `Missing secret '${name}'`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Provider = Provider;
|
|
3
36
|
//# sourceMappingURL=Provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../source/Provider.ts"],"names":[],"mappings":""}
|
|
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;IAE9D,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;;AANH,4BAeC"}
|
package/transpiled/Scanner.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare class Scanner extends PassThrough {
|
|
|
11
11
|
private position;
|
|
12
12
|
private detected;
|
|
13
13
|
private readonly chunks;
|
|
14
|
-
constructor(control?:
|
|
14
|
+
constructor(control?: ScanOptions);
|
|
15
15
|
digest(): string;
|
|
16
16
|
_transform(buffer: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
17
17
|
private readonly process;
|
|
@@ -20,7 +20,7 @@ export declare class Scanner extends PassThrough {
|
|
|
20
20
|
private match;
|
|
21
21
|
private interrupt;
|
|
22
22
|
}
|
|
23
|
-
export interface
|
|
23
|
+
export interface ScanOptions {
|
|
24
24
|
claim?: string;
|
|
25
25
|
accept?: string;
|
|
26
26
|
}
|
package/transpiled/Scanner.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Scanner = void 0;
|
|
4
4
|
const node_stream_1 = require("node:stream");
|
|
5
5
|
const node_crypto_1 = require("node:crypto");
|
|
6
|
-
const
|
|
6
|
+
const agent_1 = require("@toa.io/agent");
|
|
7
7
|
const error_value_1 = require("error-value");
|
|
8
8
|
class Scanner extends node_stream_1.PassThrough {
|
|
9
9
|
size = 0;
|
|
@@ -63,7 +63,7 @@ class Scanner extends node_stream_1.PassThrough {
|
|
|
63
63
|
match(type) {
|
|
64
64
|
if (this.accept === undefined)
|
|
65
65
|
return;
|
|
66
|
-
const unacceptable = (0,
|
|
66
|
+
const unacceptable = (0, agent_1.negotiate)(this.accept, [type]) === null;
|
|
67
67
|
if (unacceptable)
|
|
68
68
|
this.interrupt(ERR_NOT_ACCEPTABLE);
|
|
69
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Scanner.js","sourceRoot":"","sources":["../source/Scanner.ts"],"names":[],"mappings":";;;AAAA,6CAAiE;AACjE,6CAAwC;AACxC,
|
|
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/B,IAAI,GAAG,CAAC,CAAA;IACR,IAAI,GAAG,0BAA0B,CAAA;IACjC,KAAK,GAAiB,IAAI,CAAA;IAEhB,IAAI,GAAG,IAAA,wBAAU,EAAC,KAAK,CAAC,CAAA;IACxB,KAAK,CAAS;IACd,MAAM,CAAS;IACxB,QAAQ,GAAG,CAAC,CAAA;IACZ,QAAQ,GAAG,KAAK,CAAA;IACP,MAAM,GAAa,EAAE,CAAA;IAEtC,YAAoB,OAAqB;QACvC,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK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C,CAAA;AAC9C,MAAM,kBAAkB,GAAG,IAAA,iBAAG,EAAC,gBAAgB,CAAC,CAAA"}
|
package/transpiled/Storage.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Readable } from 'node:stream';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ScanOptions } from './Scanner';
|
|
4
4
|
import type { Provider } from './Provider';
|
|
5
5
|
import type { Entry } from './Entry';
|
|
6
6
|
export declare class Storage {
|
|
7
7
|
private readonly provider;
|
|
8
8
|
constructor(provider: Provider);
|
|
9
|
-
put(path: string, stream: Readable,
|
|
9
|
+
put(path: string, stream: Readable, options?: Options): Maybe<Entry>;
|
|
10
10
|
get(path: string): Maybe<Entry>;
|
|
11
11
|
fetch(path: string): Maybe<Readable>;
|
|
12
12
|
delete(path: string): Maybe<void>;
|
|
@@ -24,5 +24,9 @@ export declare class Storage {
|
|
|
24
24
|
private parse;
|
|
25
25
|
}
|
|
26
26
|
type Maybe<T> = Promise<T | Error>;
|
|
27
|
+
type Meta = Record<string, string>;
|
|
28
|
+
interface Options extends ScanOptions {
|
|
29
|
+
meta?: Meta;
|
|
30
|
+
}
|
|
27
31
|
export type Storages = Record<string, Storage>;
|
|
28
32
|
export {};
|
package/transpiled/Storage.js
CHANGED
|
@@ -12,15 +12,15 @@ class Storage {
|
|
|
12
12
|
constructor(provider) {
|
|
13
13
|
this.provider = provider;
|
|
14
14
|
}
|
|
15
|
-
async put(path, stream,
|
|
16
|
-
const scanner = new Scanner_1.Scanner(
|
|
15
|
+
async put(path, stream, options) {
|
|
16
|
+
const scanner = new Scanner_1.Scanner(options);
|
|
17
17
|
const pipe = stream.pipe(scanner);
|
|
18
18
|
const tempname = await this.transit(pipe);
|
|
19
19
|
if (scanner.error !== null)
|
|
20
20
|
return scanner.error;
|
|
21
21
|
const id = scanner.digest();
|
|
22
22
|
await this.persist(tempname, id);
|
|
23
|
-
return await this.create(path, id, scanner.size, scanner.type);
|
|
23
|
+
return await this.create(path, id, scanner.size, scanner.type, options?.meta);
|
|
24
24
|
}
|
|
25
25
|
async get(path) {
|
|
26
26
|
const metapath = node_path_1.posix.join(ENTRIES, path, META);
|
|
@@ -119,14 +119,14 @@ class Storage {
|
|
|
119
119
|
await this.provider.move(temp, blob);
|
|
120
120
|
}
|
|
121
121
|
// eslint-disable-next-line max-params
|
|
122
|
-
async create(path, id, size, type) {
|
|
122
|
+
async create(path, id, size, type, meta = {}) {
|
|
123
123
|
const entry = {
|
|
124
124
|
id,
|
|
125
125
|
size,
|
|
126
126
|
type,
|
|
127
127
|
created: Date.now(),
|
|
128
128
|
variants: [],
|
|
129
|
-
meta
|
|
129
|
+
meta
|
|
130
130
|
};
|
|
131
131
|
const metafile = node_path_1.posix.join(path, entry.id);
|
|
132
132
|
const existing = await this.get(metafile);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storage.js","sourceRoot":"","sources":["../source/Storage.ts"],"names":[],"mappings":";;;AAAA,6CAAsC;AACtC,yCAAiC;AACjC,uCAAyC;AACzC,6CAA+C;AAC/C,6CAAiC;AACjC,uCAAmC;AAKnC,MAAa,OAAO;IACD,QAAQ,CAAU;IAEnC,YAAoB,QAAkB;QACpC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAEM,KAAK,CAAC,GAAG,CAAE,IAAY,EAAE,MAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"Storage.js","sourceRoot":"","sources":["../source/Storage.ts"],"names":[],"mappings":";;;AAAA,6CAAsC;AACtC,yCAAiC;AACjC,uCAAyC;AACzC,6CAA+C;AAC/C,6CAAiC;AACjC,uCAAmC;AAKnC,MAAa,OAAO;IACD,QAAQ,CAAU;IAEnC,YAAoB,QAAkB;QACpC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAEM,KAAK,CAAC,GAAG,CAAE,IAAY,EAAE,MAAgB,EAAE,OAAiB;QACjE,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AM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,sBAAQ,CAAC,IAAI,CAAC,IAAA,iBAAM,EAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjE,CAAC;IAEO,KAAK,CAAE,IAAY;QACzB,MAAM,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAA;QACrD,MAAM,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACrC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QACvD,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAExC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,CAAA;IAC7B,CAAC;CACF;AAjND,0BAiNC;AAED,MAAM,aAAa,GAAG,IAAA,iBAAG,EAAC,WAAW,CAAC,CAAA;AACtC,MAAM,wBAAwB,GAAG,IAAA,iBAAG,EAAC,sBAAsB,CAAC,CAAA;AAE5D,MAAM,IAAI,GAAG,OAAO,CAAA;AACpB,MAAM,KAAK,GAAG,QAAQ,CAAA;AACtB,MAAM,OAAO,GAAG,UAAU,CAAA;AAC1B,MAAM,IAAI,GAAG,OAAO,CAAA;AACpB,MAAM,IAAI,GAAG,OAAO,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Dependency } from '@toa.io/operations';
|
|
2
2
|
import type { context } from '@toa.io/norm';
|
|
3
|
-
export declare
|
|
4
|
-
|
|
3
|
+
export declare const SERIALIZATION_PREFIX = "TOA_STORAGES";
|
|
4
|
+
export declare function deployment(instances: Instance[], annotation: unknown): Dependency;
|
|
5
5
|
export type Instance = context.Dependency<string[]>;
|
|
6
|
-
export {};
|