@shadow-library/fastify 0.0.4 → 0.0.5
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/cjs/classes/default-error-handler.js +3 -9
- package/cjs/constants.d.ts +1 -0
- package/cjs/constants.js +2 -1
- package/cjs/module/fastify-router.js +3 -4
- package/esm/classes/default-error-handler.js +3 -9
- package/esm/constants.d.ts +1 -0
- package/esm/constants.js +1 -0
- package/esm/module/fastify-router.js +4 -5
- package/package.json +7 -7
|
@@ -2,22 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultErrorHandler = void 0;
|
|
4
4
|
const common_1 = require("@shadow-library/common");
|
|
5
|
+
const constants_1 = require("../constants.js");
|
|
5
6
|
const server_error_1 = require("../server.error.js");
|
|
6
7
|
const unexpectedError = new server_error_1.ServerError(server_error_1.ServerErrorCode.S001);
|
|
7
8
|
const validationError = new server_error_1.ServerError(server_error_1.ServerErrorCode.S003);
|
|
8
9
|
class DefaultErrorHandler {
|
|
9
|
-
logger = common_1.Logger.getLogger(DefaultErrorHandler
|
|
10
|
+
logger = common_1.Logger.getLogger(constants_1.NAMESPACE, 'DefaultErrorHandler');
|
|
10
11
|
parseFastifyError(err) {
|
|
11
12
|
if (err.statusCode === 500)
|
|
12
13
|
return { statusCode: 500, error: unexpectedError.toObject() };
|
|
13
|
-
return {
|
|
14
|
-
statusCode: err.statusCode,
|
|
15
|
-
error: {
|
|
16
|
-
code: err.code,
|
|
17
|
-
type: common_1.ErrorType.CLIENT_ERROR,
|
|
18
|
-
message: err.message,
|
|
19
|
-
},
|
|
20
|
-
};
|
|
14
|
+
return { statusCode: err.statusCode, error: { code: err.code, type: common_1.ErrorType.CLIENT_ERROR, message: err.message } };
|
|
21
15
|
}
|
|
22
16
|
handle(err, _req, res) {
|
|
23
17
|
this.logger.warn('Handling error', err);
|
package/cjs/constants.d.ts
CHANGED
package/cjs/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HTTP_CONTROLLER_INPUTS = exports.HTTP_CONTROLLER_TYPE = exports.FASTIFY_INSTANCE = exports.FASTIFY_CONFIG = exports.PARAMTYPES_METADATA = void 0;
|
|
3
|
+
exports.HTTP_CONTROLLER_INPUTS = exports.HTTP_CONTROLLER_TYPE = exports.FASTIFY_INSTANCE = exports.FASTIFY_CONFIG = exports.PARAMTYPES_METADATA = exports.NAMESPACE = void 0;
|
|
4
|
+
exports.NAMESPACE = '@shadow-library/fastify';
|
|
4
5
|
exports.PARAMTYPES_METADATA = 'design:paramtypes';
|
|
5
6
|
exports.FASTIFY_CONFIG = Symbol('fastify-config');
|
|
6
7
|
exports.FASTIFY_INSTANCE = Symbol('fastify-instance');
|
|
@@ -14,7 +14,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
15
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
16
|
};
|
|
17
|
-
var FastifyRouter_1;
|
|
18
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
18
|
exports.FastifyRouter = void 0;
|
|
20
19
|
const assert_1 = __importDefault(require("assert"));
|
|
@@ -25,11 +24,11 @@ const constants_1 = require("../constants.js");
|
|
|
25
24
|
const decorators_1 = require("../decorators/index.js");
|
|
26
25
|
const services_1 = require("../services/index.js");
|
|
27
26
|
const httpMethods = Object.values(decorators_1.HttpMethod).filter(m => m !== decorators_1.HttpMethod.ALL);
|
|
28
|
-
let FastifyRouter =
|
|
27
|
+
let FastifyRouter = class FastifyRouter extends app_1.Router {
|
|
29
28
|
config;
|
|
30
29
|
instance;
|
|
31
30
|
context;
|
|
32
|
-
logger = common_1.Logger.getLogger(
|
|
31
|
+
logger = common_1.Logger.getLogger(constants_1.NAMESPACE, 'FastifyRouter');
|
|
33
32
|
constructor(config, instance, context) {
|
|
34
33
|
super();
|
|
35
34
|
this.config = config;
|
|
@@ -209,7 +208,7 @@ let FastifyRouter = FastifyRouter_1 = class FastifyRouter extends app_1.Router {
|
|
|
209
208
|
}
|
|
210
209
|
};
|
|
211
210
|
exports.FastifyRouter = FastifyRouter;
|
|
212
|
-
exports.FastifyRouter = FastifyRouter =
|
|
211
|
+
exports.FastifyRouter = FastifyRouter = __decorate([
|
|
213
212
|
(0, app_1.Injectable)(),
|
|
214
213
|
__param(0, (0, app_1.Inject)(constants_1.FASTIFY_CONFIG)),
|
|
215
214
|
__param(1, (0, app_1.Inject)(constants_1.FASTIFY_INSTANCE)),
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { AppError, ErrorType, Logger, ValidationError } from '@shadow-library/common';
|
|
2
|
+
import { NAMESPACE } from '../constants.js';
|
|
2
3
|
import { ServerError, ServerErrorCode } from '../server.error.js';
|
|
3
4
|
const unexpectedError = new ServerError(ServerErrorCode.S001);
|
|
4
5
|
const validationError = new ServerError(ServerErrorCode.S003);
|
|
5
6
|
export class DefaultErrorHandler {
|
|
6
|
-
logger = Logger.getLogger(DefaultErrorHandler
|
|
7
|
+
logger = Logger.getLogger(NAMESPACE, 'DefaultErrorHandler');
|
|
7
8
|
parseFastifyError(err) {
|
|
8
9
|
if (err.statusCode === 500)
|
|
9
10
|
return { statusCode: 500, error: unexpectedError.toObject() };
|
|
10
|
-
return {
|
|
11
|
-
statusCode: err.statusCode,
|
|
12
|
-
error: {
|
|
13
|
-
code: err.code,
|
|
14
|
-
type: ErrorType.CLIENT_ERROR,
|
|
15
|
-
message: err.message,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
11
|
+
return { statusCode: err.statusCode, error: { code: err.code, type: ErrorType.CLIENT_ERROR, message: err.message } };
|
|
18
12
|
}
|
|
19
13
|
handle(err, _req, res) {
|
|
20
14
|
this.logger.warn('Handling error', err);
|
package/esm/constants.d.ts
CHANGED
package/esm/constants.js
CHANGED
|
@@ -10,20 +10,19 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
|
-
var FastifyRouter_1;
|
|
14
13
|
import assert from 'assert';
|
|
15
14
|
import { Inject, Injectable, Router } from '@shadow-library/app';
|
|
16
15
|
import { InternalError, Logger, utils } from '@shadow-library/common';
|
|
17
16
|
import merge from 'deepmerge';
|
|
18
|
-
import { FASTIFY_CONFIG, FASTIFY_INSTANCE, HTTP_CONTROLLER_INPUTS, HTTP_CONTROLLER_TYPE } from '../constants.js';
|
|
17
|
+
import { FASTIFY_CONFIG, FASTIFY_INSTANCE, HTTP_CONTROLLER_INPUTS, HTTP_CONTROLLER_TYPE, NAMESPACE } from '../constants.js';
|
|
19
18
|
import { HttpMethod } from '../decorators/index.js';
|
|
20
19
|
import { Context } from '../services/index.js';
|
|
21
20
|
const httpMethods = Object.values(HttpMethod).filter(m => m !== HttpMethod.ALL);
|
|
22
|
-
let FastifyRouter =
|
|
21
|
+
let FastifyRouter = class FastifyRouter extends Router {
|
|
23
22
|
config;
|
|
24
23
|
instance;
|
|
25
24
|
context;
|
|
26
|
-
logger = Logger.getLogger(
|
|
25
|
+
logger = Logger.getLogger(NAMESPACE, 'FastifyRouter');
|
|
27
26
|
constructor(config, instance, context) {
|
|
28
27
|
super();
|
|
29
28
|
this.config = config;
|
|
@@ -202,7 +201,7 @@ let FastifyRouter = FastifyRouter_1 = class FastifyRouter extends Router {
|
|
|
202
201
|
return options ? this.instance.inject(options) : this.instance.inject();
|
|
203
202
|
}
|
|
204
203
|
};
|
|
205
|
-
FastifyRouter =
|
|
204
|
+
FastifyRouter = __decorate([
|
|
206
205
|
Injectable(),
|
|
207
206
|
__param(0, Inject(FASTIFY_CONFIG)),
|
|
208
207
|
__param(1, Inject(FASTIFY_INSTANCE)),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shadow-library/fastify",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "A Fastify wrapper featuring decorator-based routing, middleware and error handling",
|
|
7
7
|
"repository": {
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
"homepage": "https://github.com/shadow-library/fastify#readme",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@fastify/middie": "^9.0.3",
|
|
19
|
-
"@shadow-library/class-schema": "^0.0.5",
|
|
20
19
|
"ajv": "^8.17.1",
|
|
21
20
|
"deepmerge": "^4.3.1",
|
|
22
|
-
"fastify": "^5.
|
|
21
|
+
"fastify": "^5.3.3",
|
|
23
22
|
"jest": "^29.7.0",
|
|
24
|
-
"type-fest": "^4.
|
|
25
|
-
"uuid": "^11.0
|
|
23
|
+
"type-fest": "^4.41.0",
|
|
24
|
+
"uuid": "^11.1.0"
|
|
26
25
|
},
|
|
27
26
|
"peerDependencies": {
|
|
28
27
|
"@fastify/view": "^10.0.0",
|
|
29
|
-
"@shadow-library/app": "^1.0.
|
|
30
|
-
"@shadow-library/
|
|
28
|
+
"@shadow-library/app": "^1.0.7",
|
|
29
|
+
"@shadow-library/class-schema": "^0.0.5",
|
|
30
|
+
"@shadow-library/common": "^1.0.13",
|
|
31
31
|
"reflect-metadata": "^0.2.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependenciesMeta": {
|