apeframework 0.0.0-dev.3 → 0.0.0-dev.4
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/README.md +0 -14
- package/api/Api.d.ts +28 -0
- package/api/Api.js +72 -0
- package/api/Api.ts +104 -0
- package/api/Endpoint.d.ts +12 -0
- package/api/Endpoint.ts +16 -0
- package/api/ErrorHandler.d.ts +3 -0
- package/api/ErrorHandler.ts +11 -0
- package/api/Handler.d.ts +3 -0
- package/api/Handler.ts +10 -0
- package/api/Method.d.ts +8 -0
- package/api/Method.js +11 -0
- package/api/Method.ts +11 -0
- package/api/Schema.d.ts +9 -0
- package/api/Schema.ts +13 -0
- package/cipher/Cipher.js +2 -2
- package/cipher/Cipher.ts +2 -2
- package/cipher/errors/{CipherDecryptError.d.ts → DecryptError.d.ts} +2 -2
- package/cipher/errors/{CipherDecryptError.js → DecryptError.js} +3 -3
- package/cipher/errors/{CipherDecryptError.ts → DecryptError.ts} +2 -2
- package/cipher/errors/SecretLengthError.d.ts +5 -0
- package/{jwt/errors/JwtSecretLengthError.js → cipher/errors/SecretLengthError.js} +3 -3
- package/{jwt/errors/JwtSecretLengthError.ts → cipher/errors/SecretLengthError.ts} +2 -2
- package/cipher/validateSecretLength.js +2 -2
- package/cipher/validateSecretLength.ts +2 -2
- package/cli/utils/print.d.ts +2 -0
- package/cli/utils/{write.js → print.js} +3 -3
- package/cli/utils/print.ts +7 -0
- package/cli/utils/printLn.d.ts +2 -0
- package/cli/utils/{writeLn.js → printLn.js} +3 -3
- package/cli/utils/{writeLn.ts → printLn.ts} +2 -2
- package/{env/errors/EnvFileReadError.d.ts → config/errors/FileReadError.d.ts} +2 -2
- package/{tls/errors/TlsFileReadError.js → config/errors/FileReadError.js} +3 -3
- package/{env/errors/EnvFileReadError.ts → config/errors/FileReadError.ts} +2 -2
- package/config/errors/PropertyNameError.d.ts +5 -0
- package/config/errors/{ConfigPropertyNameError.js → PropertyNameError.js} +3 -3
- package/config/errors/{ConfigPropertyNameError.ts → PropertyNameError.ts} +2 -2
- package/config/errors/PropertyParseError.d.ts +5 -0
- package/config/errors/PropertyParseError.js +10 -0
- package/config/errors/PropertyParseError.ts +11 -0
- package/config/parseProperty.js +2 -2
- package/config/parseProperty.ts +2 -2
- package/config/readFile.js +4 -4
- package/config/readFile.ts +4 -4
- package/config/validatePropertyName.js +2 -2
- package/config/validatePropertyName.ts +2 -2
- package/{tls/errors/TlsFileReadError.d.ts → env/errors/FileReadError.d.ts} +2 -2
- package/env/errors/{EnvFileReadError.js → FileReadError.js} +3 -3
- package/{tls/errors/TlsFileReadError.ts → env/errors/FileReadError.ts} +2 -2
- package/env/readFile.js +3 -3
- package/env/readFile.ts +3 -3
- package/jwt/Jwt.d.ts +0 -6
- package/jwt/Jwt.js +8 -34
- package/jwt/Jwt.ts +8 -51
- package/jwt/Payload.d.ts +7 -3
- package/jwt/Payload.ts +7 -3
- package/jwt/errors/SecretLengthError.d.ts +5 -0
- package/{cipher/errors/CipherSecretLengthError.js → jwt/errors/SecretLengthError.js} +3 -3
- package/{cipher/errors/CipherSecretLengthError.ts → jwt/errors/SecretLengthError.ts} +2 -2
- package/jwt/validateSecretLength.js +2 -2
- package/jwt/validateSecretLength.ts +2 -2
- package/logger/Level.d.ts +7 -6
- package/logger/Level.js +7 -6
- package/logger/Level.ts +7 -6
- package/logger/Logger.d.ts +9 -9
- package/logger/Logger.js +4 -0
- package/logger/Logger.ts +15 -9
- package/logger/Severity.d.ts +6 -7
- package/logger/Severity.js +6 -7
- package/logger/Severity.ts +6 -7
- package/logger/adapters/file/FileLogger.d.ts +5 -5
- package/logger/adapters/file/FileLogger.js +17 -17
- package/logger/adapters/file/FileLogger.ts +19 -19
- package/logger/adapters/noop/NoopLogger.d.ts +2 -2
- package/logger/adapters/noop/NoopLogger.js +2 -1
- package/logger/adapters/noop/NoopLogger.ts +2 -2
- package/logger/adapters/stdio/StdioLogger.d.ts +5 -5
- package/logger/adapters/stdio/StdioLogger.js +19 -17
- package/logger/adapters/stdio/StdioLogger.ts +21 -19
- package/mailer/Event.d.ts +4 -4
- package/mailer/Event.ts +4 -4
- package/mailer/{EventLocation.d.ts → Location.d.ts} +2 -2
- package/mailer/Location.js +2 -0
- package/mailer/{EventLocation.ts → Location.ts} +2 -2
- package/mailer/Mailer.d.ts +5 -4
- package/mailer/Mailer.js +48 -0
- package/mailer/Mailer.ts +63 -4
- package/mailer/Method.d.ts +5 -0
- package/mailer/Method.js +8 -0
- package/mailer/{EventMethod.ts → Method.ts} +2 -2
- package/mailer/adapters/noop/NoopMailer.d.ts +3 -3
- package/mailer/adapters/noop/NoopMailer.js +3 -2
- package/mailer/adapters/noop/NoopMailer.ts +3 -3
- package/mailer/adapters/smtp/SmtpMailer.d.ts +3 -3
- package/mailer/adapters/smtp/SmtpMailer.js +4 -2
- package/mailer/adapters/smtp/SmtpMailer.ts +5 -3
- package/mailer/errors/AddressEmailError.d.ts +5 -0
- package/mailer/errors/{MailerAddressEmailError.js → AddressEmailError.js} +3 -3
- package/mailer/errors/{MailerAddressEmailError.ts → AddressEmailError.ts} +2 -2
- package/mailer/errors/EventAttachmentUrlError.d.ts +5 -0
- package/mailer/errors/{MailerEventAttachmentUrlError.js → EventAttachmentUrlError.js} +3 -3
- package/mailer/errors/{MailerEventAttachmentUrlError.ts → EventAttachmentUrlError.ts} +2 -2
- package/mailer/errors/{MailerEventGeolocationError.d.ts → EventGeolocationError.d.ts} +2 -2
- package/mailer/errors/{MailerEventGeolocationError.js → EventGeolocationError.js} +3 -3
- package/mailer/errors/{MailerEventGeolocationError.ts → EventGeolocationError.ts} +2 -2
- package/mailer/errors/EventUrlError.d.ts +5 -0
- package/mailer/errors/{MailerEventUrlError.js → EventUrlError.js} +3 -3
- package/mailer/errors/{MailerEventUrlError.ts → EventUrlError.ts} +2 -2
- package/mailer/errors/{MailerListUrlError.d.ts → ListUrlError.d.ts} +2 -2
- package/mailer/errors/{MailerListUrlError.js → ListUrlError.js} +3 -3
- package/mailer/errors/{MailerListUrlError.ts → ListUrlError.ts} +2 -2
- package/mailer/validateAddressEmail.js +2 -2
- package/mailer/validateAddressEmail.ts +2 -2
- package/mailer/validateEventAttachmentUrl.js +2 -2
- package/mailer/validateEventAttachmentUrl.ts +2 -2
- package/mailer/validateEventGeolocation.js +2 -2
- package/mailer/validateEventGeolocation.ts +2 -2
- package/mailer/validateEventUrl.js +2 -2
- package/mailer/validateEventUrl.ts +2 -2
- package/mailer/validateListUrl.js +2 -2
- package/mailer/validateListUrl.ts +2 -2
- package/package.json +1 -1
- package/parser/errors/{ParserInputError.d.ts → ParseError.d.ts} +2 -2
- package/parser/errors/ParseError.js +10 -0
- package/parser/errors/ParseError.ts +11 -0
- package/parser/factories/unit/createUnitParser.js +3 -3
- package/parser/factories/unit/createUnitParser.ts +3 -3
- package/parser/parseBoolean.js +2 -2
- package/parser/parseBoolean.ts +2 -2
- package/parser/parseInteger.js +3 -3
- package/parser/parseInteger.ts +3 -3
- package/parser/parseNumber.js +3 -3
- package/parser/parseNumber.ts +3 -3
- package/parser/parseString.js +2 -2
- package/parser/parseString.ts +2 -2
- package/pwd/errors/{PwdHashRoundsError.d.ts → HashRoundsError.d.ts} +2 -2
- package/pwd/errors/{PwdHashRoundsError.js → HashRoundsError.js} +3 -3
- package/pwd/errors/{PwdHashRoundsError.ts → HashRoundsError.ts} +2 -2
- package/pwd/validateHashRounds.js +2 -2
- package/pwd/validateHashRounds.ts +2 -2
- package/{config/errors/ConfigFileReadError.d.ts → tls/errors/FileReadError.d.ts} +2 -2
- package/{config/errors/ConfigFileReadError.js → tls/errors/FileReadError.js} +3 -3
- package/{config/errors/ConfigFileReadError.ts → tls/errors/FileReadError.ts} +2 -2
- package/tls/readFile.js +3 -3
- package/tls/readFile.ts +3 -3
- package/cipher/errors/CipherSecretLengthError.d.ts +0 -5
- package/cli/utils/write.d.ts +0 -2
- package/cli/utils/write.ts +0 -7
- package/cli/utils/writeLn.d.ts +0 -2
- package/config/errors/ConfigParseError.d.ts +0 -5
- package/config/errors/ConfigParseError.js +0 -10
- package/config/errors/ConfigParseError.ts +0 -11
- package/config/errors/ConfigPropertyNameError.d.ts +0 -5
- package/db/ColumnBuilder.d.ts +0 -13
- package/db/ColumnBuilder.js +0 -42
- package/db/ColumnBuilder.ts +0 -61
- package/db/Database.d.ts +0 -19
- package/db/Database.js +0 -49
- package/db/Database.ts +0 -74
- package/db/Driver.d.ts +0 -30
- package/db/Driver.ts +0 -33
- package/db/NullConstraint.d.ts +0 -2
- package/db/NullConstraint.ts +0 -5
- package/db/ReferentialAction.d.ts +0 -2
- package/db/ReferentialAction.ts +0 -5
- package/db/TableBuilder.d.ts +0 -49
- package/db/TableBuilder.js +0 -234
- package/db/TableBuilder.ts +0 -367
- package/db/adapters/mysql/createMysqlDatabase.d.ts +0 -12
- package/db/adapters/mysql/createMysqlDatabase.js +0 -32
- package/db/adapters/mysql/createMysqlDatabase.ts +0 -39
- package/db/adapters/mysql/driver.d.ts +0 -3
- package/db/adapters/mysql/driver.js +0 -43
- package/db/adapters/mysql/driver.ts +0 -45
- package/db/adapters/mysql/typeCast.d.ts +0 -2
- package/db/adapters/mysql/typeCast.js +0 -17
- package/db/adapters/mysql/typeCast.ts +0 -18
- package/db/adapters/postgres/driver.d.ts +0 -3
- package/db/adapters/postgres/driver.js +0 -43
- package/db/adapters/postgres/driver.ts +0 -45
- package/db/adapters/sqlite/driver.d.ts +0 -3
- package/db/adapters/sqlite/driver.js +0 -43
- package/db/adapters/sqlite/driver.ts +0 -45
- package/db/errors/DbColumnLengthError.d.ts +0 -5
- package/db/errors/DbColumnLengthError.js +0 -10
- package/db/errors/DbColumnLengthError.ts +0 -11
- package/db/errors/DbColumnMaxLengthError.d.ts +0 -5
- package/db/errors/DbColumnMaxLengthError.js +0 -10
- package/db/errors/DbColumnMaxLengthError.ts +0 -11
- package/db/errors/DbColumnPrecisionError.d.ts +0 -5
- package/db/errors/DbColumnPrecisionError.js +0 -10
- package/db/errors/DbColumnPrecisionError.ts +0 -11
- package/db/errors/DbColumnScaleError.d.ts +0 -5
- package/db/errors/DbColumnScaleError.js +0 -10
- package/db/errors/DbColumnScaleError.ts +0 -11
- package/db/getConstraintName.d.ts +0 -2
- package/db/getConstraintName.js +0 -15
- package/db/getConstraintName.ts +0 -18
- package/db/getReferentialActionSql.d.ts +0 -3
- package/db/getReferentialActionSql.js +0 -12
- package/db/getReferentialActionSql.ts +0 -17
- package/db/setNullConstraint.d.ts +0 -4
- package/db/setNullConstraint.js +0 -9
- package/db/setNullConstraint.ts +0 -15
- package/db/validateColumnLength.d.ts +0 -2
- package/db/validateColumnLength.js +0 -10
- package/db/validateColumnLength.ts +0 -11
- package/db/validateColumnMaxLength.d.ts +0 -2
- package/db/validateColumnMaxLength.js +0 -10
- package/db/validateColumnMaxLength.ts +0 -11
- package/db/validateColumnPrecision.d.ts +0 -2
- package/db/validateColumnPrecision.js +0 -14
- package/db/validateColumnPrecision.ts +0 -15
- package/jwt/errors/JwtSecretLengthError.d.ts +0 -5
- package/mailer/EventMethod.d.ts +0 -5
- package/mailer/EventMethod.js +0 -8
- package/mailer/errors/MailerAddressEmailError.d.ts +0 -5
- package/mailer/errors/MailerEventAttachmentUrlError.d.ts +0 -5
- package/mailer/errors/MailerEventUrlError.d.ts +0 -5
- package/parser/errors/ParserInputError.js +0 -10
- package/parser/errors/ParserInputError.ts +0 -11
- /package/{db/Driver.js → api/Endpoint.js} +0 -0
- /package/{db/NullConstraint.js → api/ErrorHandler.js} +0 -0
- /package/{db/ReferentialAction.js → api/Handler.js} +0 -0
- /package/{mailer/EventLocation.js → api/Schema.js} +0 -0
package/README.md
CHANGED
|
@@ -11,17 +11,3 @@ GitHub repository: [ApeFramework/apeframework](https://github.com/ApeFramework/a
|
|
|
11
11
|
```
|
|
12
12
|
npm install apeframework
|
|
13
13
|
```
|
|
14
|
-
|
|
15
|
-
## Development
|
|
16
|
-
|
|
17
|
-
Deploy dev stack:
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
docker compose up
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Get a shell from the Node.js container:
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
docker compose exec node bash
|
|
27
|
-
```
|
package/api/Api.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Endpoint } from './Endpoint';
|
|
2
|
+
import type { ErrorHandler } from './ErrorHandler';
|
|
3
|
+
import type { Handler } from './Handler';
|
|
4
|
+
declare class Api {
|
|
5
|
+
private readonly host;
|
|
6
|
+
private readonly port;
|
|
7
|
+
private readonly server;
|
|
8
|
+
constructor(params: {
|
|
9
|
+
host: string;
|
|
10
|
+
port?: number;
|
|
11
|
+
endpoints: Endpoint[];
|
|
12
|
+
onRequest?: Handler;
|
|
13
|
+
onResponse?: Handler;
|
|
14
|
+
onNotFound?: Handler;
|
|
15
|
+
onError?: ErrorHandler;
|
|
16
|
+
openapi?: {
|
|
17
|
+
title?: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
};
|
|
20
|
+
cors?: {
|
|
21
|
+
enable?: boolean;
|
|
22
|
+
origin?: string[];
|
|
23
|
+
};
|
|
24
|
+
responseValidation?: boolean;
|
|
25
|
+
});
|
|
26
|
+
start(): Promise<string>;
|
|
27
|
+
}
|
|
28
|
+
export { Api, };
|
package/api/Api.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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.Api = void 0;
|
|
7
|
+
const cors_1 = __importDefault(require("@fastify/cors"));
|
|
8
|
+
const response_validation_1 = __importDefault(require("@fastify/response-validation"));
|
|
9
|
+
const swagger_1 = __importDefault(require("@fastify/swagger"));
|
|
10
|
+
const fastify_1 = __importDefault(require("fastify"));
|
|
11
|
+
class Api {
|
|
12
|
+
host;
|
|
13
|
+
port;
|
|
14
|
+
server;
|
|
15
|
+
constructor(params) {
|
|
16
|
+
this.host = params.host;
|
|
17
|
+
this.port = params.port;
|
|
18
|
+
this.server = (0, fastify_1.default)();
|
|
19
|
+
if (params.onRequest) {
|
|
20
|
+
this.server.addHook('onRequest', params.onRequest);
|
|
21
|
+
}
|
|
22
|
+
if (params.onResponse) {
|
|
23
|
+
this.server.addHook('onResponse', params.onResponse);
|
|
24
|
+
}
|
|
25
|
+
if (params.onNotFound) {
|
|
26
|
+
this.server.setNotFoundHandler(params.onNotFound);
|
|
27
|
+
}
|
|
28
|
+
if (params.onError) {
|
|
29
|
+
this.server.setErrorHandler(params.onError);
|
|
30
|
+
}
|
|
31
|
+
this.server.register(swagger_1.default, {
|
|
32
|
+
openapi: {
|
|
33
|
+
openapi: '3.1.0',
|
|
34
|
+
info: {
|
|
35
|
+
title: params.openapi?.title ?? '',
|
|
36
|
+
version: params.openapi?.version ?? '',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
if (params.cors?.enable) {
|
|
41
|
+
this.server.register(cors_1.default, {
|
|
42
|
+
origin: params.cors.origin,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (params.responseValidation) {
|
|
46
|
+
this.server.register(response_validation_1.default);
|
|
47
|
+
}
|
|
48
|
+
params.endpoints.forEach((e) => {
|
|
49
|
+
this.server.route({
|
|
50
|
+
url: e.path,
|
|
51
|
+
method: e.method,
|
|
52
|
+
schema: {
|
|
53
|
+
summary: e.name ?? e.path,
|
|
54
|
+
description: e.description,
|
|
55
|
+
...e.schema.params ? { params: e.schema.params } : {},
|
|
56
|
+
...e.schema.query ? { query: e.schema.query } : {},
|
|
57
|
+
...e.schema.headers ? { headers: e.schema.headers } : {},
|
|
58
|
+
...e.schema.body ? { body: e.schema.body } : {},
|
|
59
|
+
...e.schema.response ? { response: e.schema.response } : {},
|
|
60
|
+
},
|
|
61
|
+
handler: e.handler,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async start() {
|
|
66
|
+
return this.server.listen({
|
|
67
|
+
host: this.host,
|
|
68
|
+
port: this.port,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.Api = Api;
|
package/api/Api.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import cors from '@fastify/cors'
|
|
2
|
+
import responseValidation from '@fastify/response-validation'
|
|
3
|
+
import swagger from '@fastify/swagger'
|
|
4
|
+
import fastify from 'fastify'
|
|
5
|
+
import type { Endpoint } from './Endpoint'
|
|
6
|
+
import type { ErrorHandler } from './ErrorHandler'
|
|
7
|
+
import type { Handler } from './Handler'
|
|
8
|
+
import type { FastifyInstance } from 'fastify'
|
|
9
|
+
|
|
10
|
+
class Api {
|
|
11
|
+
private readonly host: string
|
|
12
|
+
|
|
13
|
+
private readonly port: number | undefined
|
|
14
|
+
|
|
15
|
+
private readonly server: FastifyInstance
|
|
16
|
+
|
|
17
|
+
public constructor(params: {
|
|
18
|
+
host: string,
|
|
19
|
+
port?: number,
|
|
20
|
+
endpoints: Endpoint[],
|
|
21
|
+
onRequest?: Handler,
|
|
22
|
+
onResponse?: Handler,
|
|
23
|
+
onNotFound?: Handler,
|
|
24
|
+
onError?: ErrorHandler,
|
|
25
|
+
openapi?: {
|
|
26
|
+
title?: string,
|
|
27
|
+
version?: string,
|
|
28
|
+
},
|
|
29
|
+
cors?: {
|
|
30
|
+
enable?: boolean,
|
|
31
|
+
origin?: string[],
|
|
32
|
+
},
|
|
33
|
+
responseValidation?: boolean,
|
|
34
|
+
}) {
|
|
35
|
+
this.host = params.host
|
|
36
|
+
this.port = params.port
|
|
37
|
+
|
|
38
|
+
this.server = fastify()
|
|
39
|
+
|
|
40
|
+
if (params.onRequest) {
|
|
41
|
+
this.server.addHook('onRequest', params.onRequest)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (params.onResponse) {
|
|
45
|
+
this.server.addHook('onResponse', params.onResponse)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (params.onNotFound) {
|
|
49
|
+
this.server.setNotFoundHandler(params.onNotFound)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (params.onError) {
|
|
53
|
+
this.server.setErrorHandler(params.onError)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.server.register(swagger, {
|
|
57
|
+
openapi: {
|
|
58
|
+
openapi: '3.1.0',
|
|
59
|
+
info: {
|
|
60
|
+
title: params.openapi?.title ?? '',
|
|
61
|
+
version: params.openapi?.version ?? '',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
if (params.cors?.enable) {
|
|
67
|
+
this.server.register(cors, {
|
|
68
|
+
origin: params.cors.origin,
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (params.responseValidation) {
|
|
73
|
+
this.server.register(responseValidation)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
params.endpoints.forEach((e) => {
|
|
77
|
+
this.server.route({
|
|
78
|
+
url: e.path,
|
|
79
|
+
method: e.method,
|
|
80
|
+
schema: {
|
|
81
|
+
summary: e.name ?? e.path,
|
|
82
|
+
description: e.description,
|
|
83
|
+
...e.schema.params ? { params: e.schema.params } : {},
|
|
84
|
+
...e.schema.query ? { query: e.schema.query } : {},
|
|
85
|
+
...e.schema.headers ? { headers: e.schema.headers } : {},
|
|
86
|
+
...e.schema.body ? { body: e.schema.body } : {},
|
|
87
|
+
...e.schema.response ? { response: e.schema.response } : {},
|
|
88
|
+
},
|
|
89
|
+
handler: e.handler,
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public async start(): Promise<string> {
|
|
95
|
+
return this.server.listen({
|
|
96
|
+
host: this.host,
|
|
97
|
+
port: this.port,
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export {
|
|
103
|
+
Api,
|
|
104
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Handler } from './Handler';
|
|
2
|
+
import type { Method } from './Method';
|
|
3
|
+
import type { Schema } from './Schema';
|
|
4
|
+
interface Endpoint {
|
|
5
|
+
path: string;
|
|
6
|
+
method: Method;
|
|
7
|
+
name?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
schema: Schema;
|
|
10
|
+
handler: Handler;
|
|
11
|
+
}
|
|
12
|
+
export { type Endpoint, };
|
package/api/Endpoint.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Handler } from './Handler'
|
|
2
|
+
import type { Method } from './Method'
|
|
3
|
+
import type { Schema } from './Schema'
|
|
4
|
+
|
|
5
|
+
interface Endpoint {
|
|
6
|
+
path: string,
|
|
7
|
+
method: Method,
|
|
8
|
+
name?: string,
|
|
9
|
+
description?: string,
|
|
10
|
+
schema: Schema,
|
|
11
|
+
handler: Handler,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
type Endpoint,
|
|
16
|
+
}
|
package/api/Handler.d.ts
ADDED
package/api/Handler.ts
ADDED
package/api/Method.d.ts
ADDED
package/api/Method.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Method = void 0;
|
|
4
|
+
var Method;
|
|
5
|
+
(function (Method) {
|
|
6
|
+
Method["DELETE"] = "DELETE";
|
|
7
|
+
Method["GET"] = "GET";
|
|
8
|
+
Method["PATCH"] = "PATCH";
|
|
9
|
+
Method["POST"] = "POST";
|
|
10
|
+
Method["PUT"] = "PUT";
|
|
11
|
+
})(Method || (exports.Method = Method = {}));
|
package/api/Method.ts
ADDED
package/api/Schema.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
interface Schema {
|
|
3
|
+
params?: OpenAPIV3.SchemaObject;
|
|
4
|
+
query?: OpenAPIV3.SchemaObject;
|
|
5
|
+
headers?: OpenAPIV3.SchemaObject;
|
|
6
|
+
body?: OpenAPIV3.SchemaObject;
|
|
7
|
+
response?: Record<number, OpenAPIV3.SchemaObject>;
|
|
8
|
+
}
|
|
9
|
+
export { type Schema, };
|
package/api/Schema.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from 'openapi-types'
|
|
2
|
+
|
|
3
|
+
interface Schema {
|
|
4
|
+
params?: OpenAPIV3.SchemaObject,
|
|
5
|
+
query?: OpenAPIV3.SchemaObject,
|
|
6
|
+
headers?: OpenAPIV3.SchemaObject,
|
|
7
|
+
body?: OpenAPIV3.SchemaObject,
|
|
8
|
+
response?: Record<number, OpenAPIV3.SchemaObject>,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
type Schema,
|
|
13
|
+
}
|
package/cipher/Cipher.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Cipher = void 0;
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
-
const
|
|
8
|
+
const DecryptError_1 = require("./errors/DecryptError");
|
|
9
9
|
const validateSecretLength_1 = require("./validateSecretLength");
|
|
10
10
|
class Cipher {
|
|
11
11
|
algorithm;
|
|
@@ -31,7 +31,7 @@ class Cipher {
|
|
|
31
31
|
+ decipher.final('utf8');
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
|
-
throw new
|
|
34
|
+
throw new DecryptError_1.DecryptError(error.message);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
package/cipher/Cipher.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import crypto from 'crypto'
|
|
2
|
-
import {
|
|
2
|
+
import { DecryptError } from './errors/DecryptError'
|
|
3
3
|
import { validateSecretLength } from './validateSecretLength'
|
|
4
4
|
import type { Algorithm } from './Algorithm'
|
|
5
5
|
|
|
@@ -36,7 +36,7 @@ class Cipher {
|
|
|
36
36
|
return decipher.update(buffer.subarray(16), undefined, 'utf8')
|
|
37
37
|
+ decipher.final('utf8')
|
|
38
38
|
} catch (error) {
|
|
39
|
-
throw new
|
|
39
|
+
throw new DecryptError((error as Error).message)
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DecryptError = void 0;
|
|
4
4
|
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class
|
|
5
|
+
class DecryptError extends BaseError_1.BaseError {
|
|
6
6
|
constructor(message) {
|
|
7
7
|
super(`failed decrypting string: ${message}`);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
exports.
|
|
10
|
+
exports.DecryptError = DecryptError;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseError } from '../../error/BaseError'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class DecryptError extends BaseError {
|
|
4
4
|
public constructor(message: string) {
|
|
5
5
|
super(`failed decrypting string: ${message}`)
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
DecryptError,
|
|
11
11
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SecretLengthError = void 0;
|
|
4
4
|
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class
|
|
5
|
+
class SecretLengthError extends BaseError_1.BaseError {
|
|
6
6
|
constructor() {
|
|
7
7
|
super('invalid secret length');
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
exports.
|
|
10
|
+
exports.SecretLengthError = SecretLengthError;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseError } from '../../error/BaseError'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class SecretLengthError extends BaseError {
|
|
4
4
|
public constructor() {
|
|
5
5
|
super('invalid secret length')
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
SecretLengthError,
|
|
11
11
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateSecretLength = void 0;
|
|
4
4
|
const Algorithm_1 = require("./Algorithm");
|
|
5
|
-
const
|
|
5
|
+
const SecretLengthError_1 = require("./errors/SecretLengthError");
|
|
6
6
|
const secretLength = {
|
|
7
7
|
[Algorithm_1.Algorithm.AES128]: 16,
|
|
8
8
|
[Algorithm_1.Algorithm.AES192]: 24,
|
|
@@ -10,7 +10,7 @@ const secretLength = {
|
|
|
10
10
|
};
|
|
11
11
|
const validateSecretLength = (algorithm, secret) => {
|
|
12
12
|
if (Buffer.from(secret).length !== secretLength[algorithm]) {
|
|
13
|
-
throw new
|
|
13
|
+
throw new SecretLengthError_1.SecretLengthError();
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
exports.validateSecretLength = validateSecretLength;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Algorithm } from './Algorithm'
|
|
2
|
-
import {
|
|
2
|
+
import { SecretLengthError } from './errors/SecretLengthError'
|
|
3
3
|
|
|
4
4
|
const secretLength = {
|
|
5
5
|
[Algorithm.AES128]: 16,
|
|
@@ -9,7 +9,7 @@ const secretLength = {
|
|
|
9
9
|
|
|
10
10
|
const validateSecretLength = (algorithm: Algorithm, secret: string): void => {
|
|
11
11
|
if (Buffer.from(secret).length !== secretLength[algorithm]) {
|
|
12
|
-
throw new
|
|
12
|
+
throw new SecretLengthError()
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.print = void 0;
|
|
4
|
+
const print = (s) => {
|
|
5
5
|
process.stdout.write(s);
|
|
6
6
|
};
|
|
7
|
-
exports.
|
|
7
|
+
exports.print = print;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.printLn = void 0;
|
|
4
4
|
const os_1 = require("os");
|
|
5
|
-
const
|
|
5
|
+
const printLn = (s) => {
|
|
6
6
|
process.stdout.write(`${s}${os_1.EOL}`);
|
|
7
7
|
};
|
|
8
|
-
exports.
|
|
8
|
+
exports.printLn = printLn;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FileReadError = void 0;
|
|
4
4
|
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class
|
|
5
|
+
class FileReadError extends BaseError_1.BaseError {
|
|
6
6
|
constructor(path, message) {
|
|
7
7
|
super(`failed reading file "${path}": ${message}`);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
exports.
|
|
10
|
+
exports.FileReadError = FileReadError;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseError } from '../../error/BaseError'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class FileReadError extends BaseError {
|
|
4
4
|
public constructor(path: string, message: string) {
|
|
5
5
|
super(`failed reading file "${path}": ${message}`)
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
FileReadError,
|
|
11
11
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PropertyNameError = void 0;
|
|
4
4
|
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class
|
|
5
|
+
class PropertyNameError extends BaseError_1.BaseError {
|
|
6
6
|
constructor(name) {
|
|
7
7
|
super(`invalid property name "${name}"`);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
exports.
|
|
10
|
+
exports.PropertyNameError = PropertyNameError;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseError } from '../../error/BaseError'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class PropertyNameError extends BaseError {
|
|
4
4
|
public constructor(name: string) {
|
|
5
5
|
super(`invalid property name "${name}"`)
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
PropertyNameError,
|
|
11
11
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PropertyParseError = void 0;
|
|
4
|
+
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
+
class PropertyParseError extends BaseError_1.BaseError {
|
|
6
|
+
constructor(name, source, message) {
|
|
7
|
+
super(`failed parsing property "${name}" from ${source}: ${message}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.PropertyParseError = PropertyParseError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseError } from '../../error/BaseError'
|
|
2
|
+
|
|
3
|
+
class PropertyParseError extends BaseError {
|
|
4
|
+
public constructor(name: string, source: string, message: string) {
|
|
5
|
+
super(`failed parsing property "${name}" from ${source}: ${message}`)
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
PropertyParseError,
|
|
11
|
+
}
|