apeframework 0.0.0-dev.17 → 0.0.0-dev.19
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/config/Config.d.ts +1 -1
- package/config/Config.ts +1 -1
- package/package.json +10 -8
- package/parser/factories/enum/createEnumParser.d.ts +6 -0
- package/parser/factories/enum/createEnumParser.js +13 -0
- package/parser/factories/enum/createEnumParser.ts +21 -0
- package/{api/Endpoint.d.ts → server/Route.d.ts} +2 -2
- package/{api/Endpoint.ts → server/Route.ts} +2 -2
- package/{api/Api.d.ts → server/Server.d.ts} +11 -7
- package/{api/Api.js → server/Server.js} +43 -33
- package/{api/Api.ts → server/Server.ts} +57 -42
- /package/{api → server}/ErrorHandler.d.ts +0 -0
- /package/{api → server}/ErrorHandler.js +0 -0
- /package/{api → server}/ErrorHandler.ts +0 -0
- /package/{api → server}/Format.d.ts +0 -0
- /package/{api → server}/Format.js +0 -0
- /package/{api → server}/Format.ts +0 -0
- /package/{api → server}/Handler.d.ts +0 -0
- /package/{api → server}/Handler.js +0 -0
- /package/{api → server}/Handler.ts +0 -0
- /package/{api → server}/Method.d.ts +0 -0
- /package/{api → server}/Method.js +0 -0
- /package/{api → server}/Method.ts +0 -0
- /package/{api → server}/OpenApiFormat.d.ts +0 -0
- /package/{api → server}/OpenApiFormat.js +0 -0
- /package/{api → server}/OpenApiFormat.ts +0 -0
- /package/{api/Endpoint.js → server/Route.js} +0 -0
- /package/{api → server}/Schema.d.ts +0 -0
- /package/{api → server}/Schema.js +0 -0
- /package/{api → server}/Schema.ts +0 -0
- /package/{api → server}/getAjv.d.ts +0 -0
- /package/{api → server}/getAjv.js +0 -0
- /package/{api → server}/getAjv.ts +0 -0
package/config/Config.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
type Config = Record<string,
|
|
1
|
+
type Config = Record<string, any>;
|
|
2
2
|
export { type Config, };
|
package/config/Config.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apeframework",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.19",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Matthieu Symoens",
|
|
6
6
|
"description": "Node.js app framework",
|
|
@@ -22,32 +22,34 @@
|
|
|
22
22
|
"node": "^22"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@fastify/compress": "^8.0",
|
|
25
26
|
"@fastify/cors": "^10.0",
|
|
27
|
+
"@fastify/helmet": "^13.0",
|
|
26
28
|
"@fastify/response-validation": "^3.0",
|
|
27
|
-
"@fastify/swagger": "^9.
|
|
29
|
+
"@fastify/swagger": "^9.4",
|
|
28
30
|
"@types/bcryptjs": "^2.4",
|
|
29
31
|
"@types/fs-extra": "^11.0",
|
|
30
32
|
"@types/nodemailer": "^6.4",
|
|
31
33
|
"@types/yargs-parser": "^21.0",
|
|
32
34
|
"ajv": "^8.17",
|
|
33
35
|
"bcryptjs": "^2.4",
|
|
34
|
-
"bullmq": "^5.
|
|
36
|
+
"bullmq": "^5.34",
|
|
35
37
|
"dotenv": "^16.4",
|
|
36
38
|
"fast-uri": "^3.0",
|
|
37
|
-
"fastify": "^5.
|
|
39
|
+
"fastify": "^5.2",
|
|
38
40
|
"fs-extra": "^11.2",
|
|
39
41
|
"ical-generator": "^8.0",
|
|
40
42
|
"ioredis": "^5.4",
|
|
41
43
|
"jose": "^5.9",
|
|
42
44
|
"nodemailer": "^6.9",
|
|
43
45
|
"openapi-types": "^12.1",
|
|
44
|
-
"pino": "^9.
|
|
45
|
-
"pino-pretty": "^
|
|
46
|
+
"pino": "^9.5",
|
|
47
|
+
"pino-pretty": "^13.0",
|
|
46
48
|
"yargs-parser": "^21.1"
|
|
47
49
|
},
|
|
48
50
|
"peerDependencies": {
|
|
49
|
-
"@types/node": "^22.
|
|
51
|
+
"@types/node": "^22.10",
|
|
50
52
|
"ts-node": "^10.9",
|
|
51
|
-
"typescript": "^5.
|
|
53
|
+
"typescript": "^5.7"
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEnumParser = void 0;
|
|
4
|
+
const ParseError_1 = require("../../errors/ParseError");
|
|
5
|
+
const createEnumParser = (params) => {
|
|
6
|
+
return (input) => {
|
|
7
|
+
if (!Object.values(params.enum).includes(input)) {
|
|
8
|
+
throw new ParseError_1.ParseError(params.type);
|
|
9
|
+
}
|
|
10
|
+
return input;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.createEnumParser = createEnumParser;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ParseError } from '../../errors/ParseError'
|
|
2
|
+
import type { Parser } from '../../Parser'
|
|
3
|
+
|
|
4
|
+
const createEnumParser = <Type extends Record<string, string | number>>(
|
|
5
|
+
params: {
|
|
6
|
+
type: string,
|
|
7
|
+
enum: Type,
|
|
8
|
+
},
|
|
9
|
+
): Parser<Type[keyof Type]> => {
|
|
10
|
+
return (input) => {
|
|
11
|
+
if (!Object.values(params.enum).includes(input)) {
|
|
12
|
+
throw new ParseError(params.type)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return input
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
createEnumParser,
|
|
21
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Handler } from './Handler';
|
|
2
2
|
import type { Method } from './Method';
|
|
3
3
|
import type { Schema } from './Schema';
|
|
4
|
-
interface
|
|
4
|
+
interface Route {
|
|
5
5
|
path: string;
|
|
6
6
|
method: Method;
|
|
7
7
|
name?: string;
|
|
@@ -9,4 +9,4 @@ interface Endpoint {
|
|
|
9
9
|
schema: Schema;
|
|
10
10
|
handler: Handler;
|
|
11
11
|
}
|
|
12
|
-
export { type
|
|
12
|
+
export { type Route, };
|
|
@@ -2,7 +2,7 @@ import type { Handler } from './Handler'
|
|
|
2
2
|
import type { Method } from './Method'
|
|
3
3
|
import type { Schema } from './Schema'
|
|
4
4
|
|
|
5
|
-
interface
|
|
5
|
+
interface Route {
|
|
6
6
|
path: string,
|
|
7
7
|
method: Method,
|
|
8
8
|
name?: string,
|
|
@@ -12,5 +12,5 @@ interface Endpoint {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export {
|
|
15
|
-
type
|
|
15
|
+
type Route,
|
|
16
16
|
}
|
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import { OpenApiFormat } from './OpenApiFormat';
|
|
2
|
-
import type { Endpoint } from './Endpoint';
|
|
3
2
|
import type { ErrorHandler } from './ErrorHandler';
|
|
4
3
|
import type { Format } from './Format';
|
|
5
4
|
import type { Handler } from './Handler';
|
|
5
|
+
import type { Route } from './Route';
|
|
6
6
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
7
|
-
declare class
|
|
7
|
+
declare class Server {
|
|
8
|
+
private readonly server;
|
|
8
9
|
private readonly host;
|
|
9
10
|
private readonly port;
|
|
10
|
-
private readonly server;
|
|
11
11
|
constructor(params: {
|
|
12
12
|
host: string;
|
|
13
13
|
port?: number;
|
|
14
|
-
|
|
14
|
+
routes: Route[];
|
|
15
15
|
formats?: Format[];
|
|
16
16
|
openapi?: {
|
|
17
17
|
name?: string;
|
|
18
18
|
version?: string;
|
|
19
19
|
};
|
|
20
|
+
responseValidation?: boolean;
|
|
21
|
+
compression?: {
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
threshold?: number;
|
|
24
|
+
};
|
|
20
25
|
cors?: {
|
|
21
|
-
|
|
26
|
+
enabled?: boolean;
|
|
22
27
|
origins?: string[];
|
|
23
28
|
};
|
|
24
|
-
responseValidation?: boolean;
|
|
25
29
|
onRequest?: Handler;
|
|
26
30
|
onResponse?: Handler;
|
|
27
31
|
onNotFound?: Handler;
|
|
@@ -30,4 +34,4 @@ declare class Api {
|
|
|
30
34
|
start(): Promise<string>;
|
|
31
35
|
openapi(format: OpenApiFormat): OpenAPIV3.Document;
|
|
32
36
|
}
|
|
33
|
-
export {
|
|
37
|
+
export { Server, };
|
|
@@ -3,37 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.Server = void 0;
|
|
7
|
+
const compress_1 = __importDefault(require("@fastify/compress"));
|
|
7
8
|
const cors_1 = __importDefault(require("@fastify/cors"));
|
|
9
|
+
const helmet_1 = __importDefault(require("@fastify/helmet"));
|
|
8
10
|
const response_validation_1 = __importDefault(require("@fastify/response-validation"));
|
|
9
11
|
const swagger_1 = __importDefault(require("@fastify/swagger"));
|
|
10
12
|
const fastify_1 = __importDefault(require("fastify"));
|
|
11
13
|
const OpenApiFormat_1 = require("./OpenApiFormat");
|
|
12
14
|
const getAjv_1 = require("./getAjv");
|
|
13
|
-
class
|
|
15
|
+
class Server {
|
|
16
|
+
server;
|
|
14
17
|
host;
|
|
15
18
|
port;
|
|
16
|
-
server;
|
|
17
19
|
constructor(params) {
|
|
18
20
|
this.host = params.host;
|
|
19
21
|
this.port = params.port;
|
|
20
22
|
this.server = (0, fastify_1.default)();
|
|
21
|
-
const ajv = (0, getAjv_1.getAjv)(params.formats);
|
|
22
23
|
this.server.setValidatorCompiler(({ schema }) => {
|
|
23
|
-
return
|
|
24
|
+
return (0, getAjv_1.getAjv)(params.formats).compile(schema);
|
|
24
25
|
});
|
|
25
|
-
if (params.onRequest) {
|
|
26
|
-
this.server.addHook('onRequest', params.onRequest);
|
|
27
|
-
}
|
|
28
|
-
if (params.onResponse) {
|
|
29
|
-
this.server.addHook('onResponse', params.onResponse);
|
|
30
|
-
}
|
|
31
|
-
if (params.onNotFound) {
|
|
32
|
-
this.server.setNotFoundHandler(params.onNotFound);
|
|
33
|
-
}
|
|
34
|
-
if (params.onError) {
|
|
35
|
-
this.server.setErrorHandler(params.onError);
|
|
36
|
-
}
|
|
37
26
|
this.server.register(swagger_1.default, {
|
|
38
27
|
openapi: {
|
|
39
28
|
openapi: '3.1.0',
|
|
@@ -43,33 +32,54 @@ class Api {
|
|
|
43
32
|
},
|
|
44
33
|
},
|
|
45
34
|
});
|
|
46
|
-
if (params.
|
|
35
|
+
if (params.responseValidation) {
|
|
36
|
+
this.server.register(response_validation_1.default);
|
|
37
|
+
}
|
|
38
|
+
if (params.compression?.enabled) {
|
|
39
|
+
this.server.register(compress_1.default, {
|
|
40
|
+
global: true,
|
|
41
|
+
threshold: params.compression.threshold ?? 1024,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (params.cors?.enabled) {
|
|
47
45
|
this.server.register(cors_1.default, {
|
|
48
46
|
origin: params.cors.origins,
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
49
|
+
this.server.register(helmet_1.default, {
|
|
50
|
+
global: false,
|
|
51
|
+
});
|
|
54
52
|
this.server.register((server, options, done) => {
|
|
55
|
-
params.
|
|
53
|
+
params.routes.forEach((route) => {
|
|
56
54
|
server.route({
|
|
57
|
-
url:
|
|
58
|
-
method:
|
|
55
|
+
url: route.path,
|
|
56
|
+
method: route.method,
|
|
59
57
|
schema: {
|
|
60
|
-
summary:
|
|
61
|
-
description:
|
|
62
|
-
...
|
|
63
|
-
...
|
|
64
|
-
...
|
|
65
|
-
...
|
|
66
|
-
...
|
|
58
|
+
summary: route.name ?? route.path,
|
|
59
|
+
description: route.description,
|
|
60
|
+
...route.schema.params ? { params: route.schema.params } : {},
|
|
61
|
+
...route.schema.query ? { query: route.schema.query } : {},
|
|
62
|
+
...route.schema.headers ? { headers: route.schema.headers } : {},
|
|
63
|
+
...route.schema.body ? { body: route.schema.body } : {},
|
|
64
|
+
...route.schema.response ? { response: route.schema.response } : {},
|
|
67
65
|
},
|
|
68
|
-
handler:
|
|
66
|
+
handler: route.handler,
|
|
69
67
|
});
|
|
70
68
|
});
|
|
71
69
|
done();
|
|
72
70
|
});
|
|
71
|
+
if (params.onRequest) {
|
|
72
|
+
this.server.addHook('onRequest', params.onRequest);
|
|
73
|
+
}
|
|
74
|
+
if (params.onResponse) {
|
|
75
|
+
this.server.addHook('onResponse', params.onResponse);
|
|
76
|
+
}
|
|
77
|
+
if (params.onNotFound) {
|
|
78
|
+
this.server.setNotFoundHandler(params.onNotFound);
|
|
79
|
+
}
|
|
80
|
+
if (params.onError) {
|
|
81
|
+
this.server.setErrorHandler(params.onError);
|
|
82
|
+
}
|
|
73
83
|
}
|
|
74
84
|
async start() {
|
|
75
85
|
return this.server.listen({
|
|
@@ -83,4 +93,4 @@ class Api {
|
|
|
83
93
|
});
|
|
84
94
|
}
|
|
85
95
|
}
|
|
86
|
-
exports.
|
|
96
|
+
exports.Server = Server;
|
|
@@ -1,37 +1,43 @@
|
|
|
1
|
+
import compress from '@fastify/compress'
|
|
1
2
|
import cors from '@fastify/cors'
|
|
3
|
+
import helmet from '@fastify/helmet'
|
|
2
4
|
import responseValidation from '@fastify/response-validation'
|
|
3
5
|
import swagger from '@fastify/swagger'
|
|
4
6
|
import fastify from 'fastify'
|
|
5
7
|
import { OpenApiFormat } from './OpenApiFormat'
|
|
6
8
|
import { getAjv } from './getAjv'
|
|
7
|
-
import type { Endpoint } from './Endpoint'
|
|
8
9
|
import type { ErrorHandler } from './ErrorHandler'
|
|
9
10
|
import type { Format } from './Format'
|
|
10
11
|
import type { Handler } from './Handler'
|
|
12
|
+
import type { Route } from './Route'
|
|
11
13
|
import type { FastifyInstance } from 'fastify'
|
|
12
14
|
import type { OpenAPIV3 } from 'openapi-types'
|
|
13
15
|
|
|
14
|
-
class
|
|
16
|
+
class Server {
|
|
17
|
+
private readonly server: FastifyInstance
|
|
18
|
+
|
|
15
19
|
private readonly host: string
|
|
16
20
|
|
|
17
21
|
private readonly port: number | undefined
|
|
18
22
|
|
|
19
|
-
private readonly server: FastifyInstance
|
|
20
|
-
|
|
21
23
|
public constructor(params: {
|
|
22
24
|
host: string,
|
|
23
25
|
port?: number,
|
|
24
|
-
|
|
26
|
+
routes: Route[],
|
|
25
27
|
formats?: Format[],
|
|
26
28
|
openapi?: {
|
|
27
29
|
name?: string,
|
|
28
30
|
version?: string,
|
|
29
31
|
},
|
|
32
|
+
responseValidation?: boolean,
|
|
33
|
+
compression?: {
|
|
34
|
+
enabled?: boolean,
|
|
35
|
+
threshold?: number,
|
|
36
|
+
},
|
|
30
37
|
cors?: {
|
|
31
|
-
|
|
38
|
+
enabled?: boolean,
|
|
32
39
|
origins?: string[],
|
|
33
40
|
},
|
|
34
|
-
responseValidation?: boolean,
|
|
35
41
|
onRequest?: Handler,
|
|
36
42
|
onResponse?: Handler,
|
|
37
43
|
onNotFound?: Handler,
|
|
@@ -42,28 +48,10 @@ class Api {
|
|
|
42
48
|
|
|
43
49
|
this.server = fastify()
|
|
44
50
|
|
|
45
|
-
const ajv = getAjv(params.formats)
|
|
46
|
-
|
|
47
51
|
this.server.setValidatorCompiler(({ schema }) => {
|
|
48
|
-
return
|
|
52
|
+
return getAjv(params.formats).compile(schema)
|
|
49
53
|
})
|
|
50
54
|
|
|
51
|
-
if (params.onRequest) {
|
|
52
|
-
this.server.addHook('onRequest', params.onRequest)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (params.onResponse) {
|
|
56
|
-
this.server.addHook('onResponse', params.onResponse)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (params.onNotFound) {
|
|
60
|
-
this.server.setNotFoundHandler(params.onNotFound)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (params.onError) {
|
|
64
|
-
this.server.setErrorHandler(params.onError)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
55
|
this.server.register(swagger, {
|
|
68
56
|
openapi: {
|
|
69
57
|
openapi: '3.1.0',
|
|
@@ -74,35 +62,62 @@ class Api {
|
|
|
74
62
|
},
|
|
75
63
|
})
|
|
76
64
|
|
|
77
|
-
if (params.
|
|
65
|
+
if (params.responseValidation) {
|
|
66
|
+
this.server.register(responseValidation)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (params.compression?.enabled) {
|
|
70
|
+
this.server.register(compress, {
|
|
71
|
+
global: true,
|
|
72
|
+
threshold: params.compression.threshold ?? 1024,
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (params.cors?.enabled) {
|
|
78
77
|
this.server.register(cors, {
|
|
79
78
|
origin: params.cors.origins,
|
|
80
79
|
})
|
|
81
80
|
}
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
82
|
+
this.server.register(helmet, {
|
|
83
|
+
global: false,
|
|
84
|
+
})
|
|
86
85
|
|
|
87
86
|
this.server.register((server, options, done) => {
|
|
88
|
-
params.
|
|
87
|
+
params.routes.forEach((route) => {
|
|
89
88
|
server.route({
|
|
90
|
-
url:
|
|
91
|
-
method:
|
|
89
|
+
url: route.path,
|
|
90
|
+
method: route.method,
|
|
92
91
|
schema: {
|
|
93
|
-
summary:
|
|
94
|
-
description:
|
|
95
|
-
...
|
|
96
|
-
...
|
|
97
|
-
...
|
|
98
|
-
...
|
|
99
|
-
...
|
|
92
|
+
summary: route.name ?? route.path,
|
|
93
|
+
description: route.description,
|
|
94
|
+
...route.schema.params ? { params: route.schema.params } : {},
|
|
95
|
+
...route.schema.query ? { query: route.schema.query } : {},
|
|
96
|
+
...route.schema.headers ? { headers: route.schema.headers } : {},
|
|
97
|
+
...route.schema.body ? { body: route.schema.body } : {},
|
|
98
|
+
...route.schema.response ? { response: route.schema.response } : {},
|
|
100
99
|
},
|
|
101
|
-
handler:
|
|
100
|
+
handler: route.handler,
|
|
102
101
|
})
|
|
103
102
|
})
|
|
104
103
|
done()
|
|
105
104
|
})
|
|
105
|
+
|
|
106
|
+
if (params.onRequest) {
|
|
107
|
+
this.server.addHook('onRequest', params.onRequest)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (params.onResponse) {
|
|
111
|
+
this.server.addHook('onResponse', params.onResponse)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (params.onNotFound) {
|
|
115
|
+
this.server.setNotFoundHandler(params.onNotFound)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (params.onError) {
|
|
119
|
+
this.server.setErrorHandler(params.onError)
|
|
120
|
+
}
|
|
106
121
|
}
|
|
107
122
|
|
|
108
123
|
public async start(): Promise<string> {
|
|
@@ -120,5 +135,5 @@ class Api {
|
|
|
120
135
|
}
|
|
121
136
|
|
|
122
137
|
export {
|
|
123
|
-
|
|
138
|
+
Server,
|
|
124
139
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|