@shadow-library/fastify 0.0.10 → 0.0.12
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.d.ts +6 -0
- package/cjs/classes/default-error-handler.js +9 -0
- package/cjs/constants.d.ts +12 -0
- package/cjs/constants.js +12 -0
- package/cjs/decorators/http-controller.decorator.d.ts +6 -0
- package/cjs/decorators/http-controller.decorator.js +12 -0
- package/cjs/decorators/http-input.decorator.d.ts +6 -0
- package/cjs/decorators/http-input.decorator.js +12 -0
- package/cjs/decorators/http-output.decorator.d.ts +9 -0
- package/cjs/decorators/http-output.decorator.js +6 -0
- package/cjs/decorators/http-route.decorator.d.ts +9 -0
- package/cjs/decorators/http-route.decorator.js +12 -0
- package/cjs/decorators/middleware.decorator.d.ts +11 -0
- package/cjs/decorators/middleware.decorator.js +9 -0
- package/cjs/decorators/sensitive.decorator.d.ts +9 -0
- package/cjs/decorators/sensitive.decorator.js +3 -0
- package/cjs/index.d.ts +6 -0
- package/cjs/index.js +6 -0
- package/cjs/interfaces/error-handler.interface.d.ts +12 -0
- package/cjs/interfaces/error-handler.interface.js +3 -0
- package/cjs/interfaces/middleware.interface.d.ts +9 -0
- package/cjs/interfaces/route-handler.interface.d.ts +12 -0
- package/cjs/interfaces/server-metadata.interface.d.ts +9 -0
- package/cjs/module/error-response.dto.d.ts +9 -0
- package/cjs/module/error-response.dto.js +12 -0
- package/cjs/module/fastify-module.interface.d.ts +55 -0
- package/cjs/module/fastify-router.d.ts +11 -0
- package/cjs/module/fastify-router.js +20 -1
- package/cjs/module/fastify.module.d.ts +6 -0
- package/cjs/module/fastify.module.js +12 -0
- package/cjs/module/fastify.utils.js +14 -1
- package/cjs/server.error.d.ts +17 -0
- package/cjs/server.error.js +26 -0
- package/cjs/services/context.service.d.ts +6 -0
- package/cjs/services/context.service.js +6 -0
- package/esm/classes/default-error-handler.d.ts +6 -0
- package/esm/classes/default-error-handler.js +9 -0
- package/esm/constants.d.ts +12 -0
- package/esm/constants.js +12 -0
- package/esm/decorators/http-controller.decorator.d.ts +6 -0
- package/esm/decorators/http-controller.decorator.js +12 -0
- package/esm/decorators/http-input.decorator.d.ts +6 -0
- package/esm/decorators/http-input.decorator.js +12 -0
- package/esm/decorators/http-output.decorator.d.ts +9 -0
- package/esm/decorators/http-output.decorator.js +6 -0
- package/esm/decorators/http-route.decorator.d.ts +9 -0
- package/esm/decorators/http-route.decorator.js +12 -0
- package/esm/decorators/middleware.decorator.d.ts +11 -0
- package/esm/decorators/middleware.decorator.js +9 -0
- package/esm/decorators/sensitive.decorator.d.ts +9 -0
- package/esm/decorators/sensitive.decorator.js +3 -0
- package/esm/index.d.ts +6 -0
- package/esm/index.js +6 -0
- package/esm/interfaces/error-handler.interface.d.ts +12 -0
- package/esm/interfaces/error-handler.interface.js +3 -0
- package/esm/interfaces/middleware.interface.d.ts +9 -0
- package/esm/interfaces/route-handler.interface.d.ts +12 -0
- package/esm/interfaces/server-metadata.interface.d.ts +9 -0
- package/esm/module/error-response.dto.d.ts +9 -0
- package/esm/module/error-response.dto.js +12 -0
- package/esm/module/fastify-module.interface.d.ts +55 -0
- package/esm/module/fastify-router.d.ts +11 -0
- package/esm/module/fastify-router.js +20 -1
- package/esm/module/fastify.module.d.ts +6 -0
- package/esm/module/fastify.module.js +12 -0
- package/esm/module/fastify.utils.js +14 -1
- package/esm/server.error.d.ts +17 -0
- package/esm/server.error.js +26 -0
- package/esm/services/context.service.d.ts +6 -0
- package/esm/services/context.service.js +6 -0
- package/package.json +1 -1
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FastifyModule = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Importing npm packages
|
|
6
|
+
*/
|
|
4
7
|
const app_1 = require("@shadow-library/app");
|
|
5
8
|
const class_schema_1 = require("@shadow-library/class-schema");
|
|
6
9
|
const common_1 = require("@shadow-library/common");
|
|
7
10
|
const uuid_1 = require("uuid");
|
|
11
|
+
/**
|
|
12
|
+
* Importing user defined packages
|
|
13
|
+
*/
|
|
8
14
|
const classes_1 = require("../classes/index.js");
|
|
9
15
|
const constants_1 = require("../constants.js");
|
|
10
16
|
const services_1 = require("../services/index.js");
|
|
11
17
|
const error_response_dto_1 = require("./error-response.dto.js");
|
|
12
18
|
const fastify_router_1 = require("./fastify-router.js");
|
|
13
19
|
const fastify_utils_1 = require("./fastify.utils.js");
|
|
20
|
+
/**
|
|
21
|
+
* Defining types
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Declaring the constants
|
|
25
|
+
*/
|
|
14
26
|
class FastifyModule {
|
|
15
27
|
static getDefaultConfig() {
|
|
16
28
|
const errorResponseSchema = class_schema_1.ClassSchema.generate(error_response_dto_1.ErrorResponseDto);
|
|
@@ -7,11 +7,23 @@ exports.notFoundHandler = void 0;
|
|
|
7
7
|
exports.compileValidator = compileValidator;
|
|
8
8
|
exports.formatSchemaErrors = formatSchemaErrors;
|
|
9
9
|
exports.createFastifyInstance = createFastifyInstance;
|
|
10
|
+
/**
|
|
11
|
+
* Importing npm packages
|
|
12
|
+
*/
|
|
10
13
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
11
14
|
const common_1 = require("@shadow-library/common");
|
|
12
15
|
const ajv_1 = __importDefault(require("ajv"));
|
|
13
16
|
const fastify_1 = require("fastify");
|
|
17
|
+
/**
|
|
18
|
+
* Importing user defined packages
|
|
19
|
+
*/
|
|
14
20
|
const server_error_1 = require("../server.error.js");
|
|
21
|
+
/**
|
|
22
|
+
* Defining types
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Declaring the constants
|
|
26
|
+
*/
|
|
15
27
|
const keywords = ['x-fastify'];
|
|
16
28
|
const allowedHttpParts = ['body', 'params', 'querystring'];
|
|
17
29
|
const strictValidator = new ajv_1.default({ allErrors: true, useDefaults: true, removeAdditional: true, strict: true, keywords });
|
|
@@ -39,12 +51,13 @@ function compileValidator(routeSchema) {
|
|
|
39
51
|
return (data) => {
|
|
40
52
|
validate(data);
|
|
41
53
|
for (const error of validate.errors ?? []) {
|
|
54
|
+
/** Since this schema is for querystring there won't be any nested objects so we are directly accessing the path */
|
|
42
55
|
const path = error.instancePath.substring(1);
|
|
43
56
|
const defaultValue = routeSchema.schema.properties?.[path]?.default;
|
|
44
57
|
if (defaultValue !== undefined)
|
|
45
58
|
data[path] = defaultValue;
|
|
46
59
|
else
|
|
47
|
-
delete data[path];
|
|
60
|
+
delete data[path]; // eslint-disable-line @typescript-eslint/no-dynamic-delete
|
|
48
61
|
}
|
|
49
62
|
return { value: data };
|
|
50
63
|
};
|
package/cjs/server.error.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import { AppError, ErrorCode, ErrorType } from '@shadow-library/common';
|
|
2
5
|
export declare class ServerError extends AppError<ServerErrorCode> {
|
|
3
6
|
getStatusCode(): number;
|
|
@@ -6,13 +9,27 @@ export declare class ServerErrorCode extends ErrorCode {
|
|
|
6
9
|
private readonly statusCode;
|
|
7
10
|
protected constructor(code: string, type: ErrorType, msg: string, statusCode?: number);
|
|
8
11
|
getStatusCode(): number;
|
|
12
|
+
/*!
|
|
13
|
+
* List of all server related errors
|
|
14
|
+
*/
|
|
15
|
+
/** An unexpected server error occurred while processing the request */
|
|
9
16
|
static readonly S001: ServerErrorCode;
|
|
17
|
+
/** The requested endpoint does not exist */
|
|
10
18
|
static readonly S002: ServerErrorCode;
|
|
19
|
+
/** The provided input data is invalid or does not meet validation requirements */
|
|
11
20
|
static readonly S003: ServerErrorCode;
|
|
21
|
+
/** Authentication credentials are required to access this resource */
|
|
12
22
|
static readonly S004: ServerErrorCode;
|
|
23
|
+
/** Access denied due to insufficient permissions to perform this operation */
|
|
13
24
|
static readonly S005: ServerErrorCode;
|
|
25
|
+
/** The request is malformed or contains invalid parameters */
|
|
14
26
|
static readonly S006: ServerErrorCode;
|
|
27
|
+
/** Rate limit exceeded due to too many requests sent in a given time frame */
|
|
15
28
|
static readonly S007: ServerErrorCode;
|
|
29
|
+
/** Resource conflict as the requested operation conflicts with existing data */
|
|
16
30
|
static readonly S008: ServerErrorCode;
|
|
31
|
+
/** The requested resource could not be found */
|
|
17
32
|
static readonly S009: ServerErrorCode;
|
|
33
|
+
/** Access blocked due to security policy restrictions */
|
|
34
|
+
static readonly S010: ServerErrorCode;
|
|
18
35
|
}
|
package/cjs/server.error.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServerErrorCode = exports.ServerError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Importing npm packages
|
|
6
|
+
*/
|
|
4
7
|
const common_1 = require("@shadow-library/common");
|
|
8
|
+
/**
|
|
9
|
+
* Importing user defined packages
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Defining types
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Declaring the constants
|
|
16
|
+
*/
|
|
5
17
|
const ERROR_STATUS_CODES = {
|
|
6
18
|
[common_1.ErrorType.CLIENT_ERROR]: 400,
|
|
7
19
|
[common_1.ErrorType.HTTP_ERROR]: 400,
|
|
@@ -27,14 +39,28 @@ class ServerErrorCode extends common_1.ErrorCode {
|
|
|
27
39
|
getStatusCode() {
|
|
28
40
|
return this.statusCode;
|
|
29
41
|
}
|
|
42
|
+
/*!
|
|
43
|
+
* List of all server related errors
|
|
44
|
+
*/
|
|
45
|
+
/** An unexpected server error occurred while processing the request */
|
|
30
46
|
static S001 = new ServerErrorCode('S001', common_1.ErrorType.SERVER_ERROR, 'An unexpected server error occurred while processing the request');
|
|
47
|
+
/** The requested endpoint does not exist */
|
|
31
48
|
static S002 = new ServerErrorCode('S002', common_1.ErrorType.NOT_FOUND, 'The requested endpoint does not exist');
|
|
49
|
+
/** The provided input data is invalid or does not meet validation requirements */
|
|
32
50
|
static S003 = new ServerErrorCode('S003', common_1.ErrorType.VALIDATION_ERROR, 'The provided input data is invalid or does not meet validation requirements');
|
|
51
|
+
/** Authentication credentials are required to access this resource */
|
|
33
52
|
static S004 = new ServerErrorCode('S004', common_1.ErrorType.UNAUTHENTICATED, 'Authentication credentials are required to access this resource');
|
|
53
|
+
/** Access denied due to insufficient permissions to perform this operation */
|
|
34
54
|
static S005 = new ServerErrorCode('S005', common_1.ErrorType.UNAUTHORIZED, 'Access denied due to insufficient permissions to perform this operation');
|
|
55
|
+
/** The request is malformed or contains invalid parameters */
|
|
35
56
|
static S006 = new ServerErrorCode('S006', common_1.ErrorType.CLIENT_ERROR, 'The request is malformed or contains invalid parameters');
|
|
57
|
+
/** Rate limit exceeded due to too many requests sent in a given time frame */
|
|
36
58
|
static S007 = new ServerErrorCode('S007', common_1.ErrorType.CLIENT_ERROR, 'Rate limit exceeded due to too many requests sent in a given time frame', 429);
|
|
59
|
+
/** Resource conflict as the requested operation conflicts with existing data */
|
|
37
60
|
static S008 = new ServerErrorCode('S008', common_1.ErrorType.CONFLICT, 'Resource conflict as the requested operation conflicts with existing data');
|
|
61
|
+
/** The requested resource could not be found */
|
|
38
62
|
static S009 = new ServerErrorCode('S009', common_1.ErrorType.NOT_FOUND, 'The requested resource could not be found');
|
|
63
|
+
/** Access blocked due to security policy restrictions */
|
|
64
|
+
static S010 = new ServerErrorCode('S010', common_1.ErrorType.UNAUTHORIZED, 'Access blocked due to security policy restrictions');
|
|
39
65
|
}
|
|
40
66
|
exports.ServerErrorCode = ServerErrorCode;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { onRequestHookHandler } from 'fastify';
|
|
2
|
+
/**
|
|
3
|
+
* Importing user defined packages
|
|
4
|
+
*/
|
|
2
5
|
import { HttpRequest, HttpResponse } from '../interfaces/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Defining types
|
|
8
|
+
*/
|
|
3
9
|
type Key = string | symbol;
|
|
4
10
|
export interface ContextExtension {
|
|
5
11
|
}
|
|
@@ -7,9 +7,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ContextService = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Importing npm packages
|
|
12
|
+
*/
|
|
10
13
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
11
14
|
const app_1 = require("@shadow-library/app");
|
|
12
15
|
const common_1 = require("@shadow-library/common");
|
|
16
|
+
/**
|
|
17
|
+
* Declaring the constants
|
|
18
|
+
*/
|
|
13
19
|
const REQUEST = Symbol('request');
|
|
14
20
|
const RESPONSE = Symbol('response');
|
|
15
21
|
const RID = Symbol('rid');
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import { AppErrorObject } from '@shadow-library/common';
|
|
2
5
|
import { FastifyError } from 'fastify';
|
|
3
6
|
import { ErrorHandler, HttpRequest, HttpResponse } from '../interfaces/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Defining types
|
|
9
|
+
*/
|
|
4
10
|
export interface ParsedFastifyError {
|
|
5
11
|
statusCode: number;
|
|
6
12
|
error: AppErrorObject;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import { AppError, Logger, ValidationError } from '@shadow-library/common';
|
|
5
|
+
/**
|
|
6
|
+
* Importing user defined packages
|
|
7
|
+
*/
|
|
2
8
|
import { NAMESPACE } from '../constants.js';
|
|
3
9
|
import { ServerError, ServerErrorCode } from '../server.error.js';
|
|
10
|
+
/**
|
|
11
|
+
* Declaring the constants
|
|
12
|
+
*/
|
|
4
13
|
const unexpectedError = new ServerError(ServerErrorCode.S001);
|
|
5
14
|
const validationError = new ServerError(ServerErrorCode.S003);
|
|
6
15
|
const invalidRequestError = new ServerError(ServerErrorCode.S006);
|
package/esm/constants.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Importing user defined packages
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Defining types
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Declaring the constants
|
|
12
|
+
*/
|
|
1
13
|
export declare const NAMESPACE = "@shadow-library/fastify";
|
|
2
14
|
export declare const PARAMTYPES_METADATA = "design:paramtypes";
|
|
3
15
|
export declare const FASTIFY_CONFIG: unique symbol;
|
package/esm/constants.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Importing user defined packages
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Defining types
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Declaring the constants
|
|
12
|
+
*/
|
|
1
13
|
export const NAMESPACE = '@shadow-library/fastify';
|
|
2
14
|
export const PARAMTYPES_METADATA = 'design:paramtypes';
|
|
3
15
|
export const FASTIFY_CONFIG = Symbol('fastify-config');
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import { Controller } from '@shadow-library/app';
|
|
5
|
+
/**
|
|
6
|
+
* Importing user defined packages
|
|
7
|
+
*/
|
|
2
8
|
import { HTTP_CONTROLLER_TYPE } from '../constants.js';
|
|
9
|
+
/**
|
|
10
|
+
* Defining types
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Declaring the constants
|
|
14
|
+
*/
|
|
3
15
|
export function HttpController(path = '') {
|
|
4
16
|
if (path.charAt(0) !== '/')
|
|
5
17
|
path = `/${path}`;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { JSONSchema } from '@shadow-library/class-schema';
|
|
2
2
|
import { Class } from 'type-fest';
|
|
3
|
+
/**
|
|
4
|
+
* Defining types
|
|
5
|
+
*/
|
|
3
6
|
export declare enum RouteInputType {
|
|
4
7
|
BODY = "body",
|
|
5
8
|
PARAMS = "params",
|
|
@@ -8,6 +11,9 @@ export declare enum RouteInputType {
|
|
|
8
11
|
RESPONSE = "response"
|
|
9
12
|
}
|
|
10
13
|
export type RouteInputSchemas = Partial<Record<'body' | 'params' | 'query', JSONSchema | Class<unknown>>>;
|
|
14
|
+
/**
|
|
15
|
+
* Declaring the constants
|
|
16
|
+
*/
|
|
11
17
|
export declare function HttpInput(type: RouteInputType, schema?: JSONSchema): ParameterDecorator;
|
|
12
18
|
export declare const Body: (schema?: JSONSchema) => ParameterDecorator;
|
|
13
19
|
export declare const Params: (schema?: JSONSchema) => ParameterDecorator;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import assert from 'node:assert';
|
|
2
5
|
import { Route } from '@shadow-library/app';
|
|
6
|
+
/**
|
|
7
|
+
* Importing user defined packages
|
|
8
|
+
*/
|
|
3
9
|
import { HTTP_CONTROLLER_INPUTS, PARAMTYPES_METADATA } from '../constants.js';
|
|
10
|
+
/**
|
|
11
|
+
* Defining types
|
|
12
|
+
*/
|
|
4
13
|
export var RouteInputType;
|
|
5
14
|
(function (RouteInputType) {
|
|
6
15
|
RouteInputType["BODY"] = "body";
|
|
@@ -9,6 +18,9 @@ export var RouteInputType;
|
|
|
9
18
|
RouteInputType["REQUEST"] = "request";
|
|
10
19
|
RouteInputType["RESPONSE"] = "response";
|
|
11
20
|
})(RouteInputType || (RouteInputType = {}));
|
|
21
|
+
/**
|
|
22
|
+
* Declaring the constants
|
|
23
|
+
*/
|
|
12
24
|
export function HttpInput(type, schema) {
|
|
13
25
|
return (target, propertyKey, index) => {
|
|
14
26
|
assert(propertyKey, 'Cannot apply decorator to a constructor parameter');
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import { JSONSchema, SchemaClass } from '@shadow-library/class-schema';
|
|
2
5
|
import { JsonObject } from 'type-fest';
|
|
6
|
+
/**
|
|
7
|
+
* Importing user defined packages
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Defining types
|
|
11
|
+
*/
|
|
3
12
|
export interface DynamicRender<T extends JsonObject> {
|
|
4
13
|
template: string;
|
|
5
14
|
data: T;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import { Route } from '@shadow-library/app';
|
|
2
5
|
import { ClassSchema } from '@shadow-library/class-schema';
|
|
6
|
+
/**
|
|
7
|
+
* Declaring the constants
|
|
8
|
+
*/
|
|
3
9
|
const isClass = (schema) => schema.toString().startsWith('class ');
|
|
4
10
|
export const HttpStatus = (status) => Route({ status });
|
|
5
11
|
export const Header = (name, value) => Route({ headers: { [name]: value } });
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing user defined packages
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Defining types
|
|
6
|
+
*/
|
|
1
7
|
export declare enum HttpMethod {
|
|
2
8
|
GET = "GET",
|
|
3
9
|
POST = "POST",
|
|
@@ -12,6 +18,9 @@ export interface RouteOptions {
|
|
|
12
18
|
method: HttpMethod;
|
|
13
19
|
path?: string;
|
|
14
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Declaring the constants
|
|
23
|
+
*/
|
|
15
24
|
export declare function HttpRoute(options: RouteOptions): MethodDecorator;
|
|
16
25
|
export declare const Get: (path?: string) => MethodDecorator;
|
|
17
26
|
export declare const Post: (path?: string) => MethodDecorator;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import { Route } from '@shadow-library/app';
|
|
5
|
+
/**
|
|
6
|
+
* Importing user defined packages
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Defining types
|
|
10
|
+
*/
|
|
2
11
|
export var HttpMethod;
|
|
3
12
|
(function (HttpMethod) {
|
|
4
13
|
HttpMethod["GET"] = "GET";
|
|
@@ -10,6 +19,9 @@ export var HttpMethod;
|
|
|
10
19
|
HttpMethod["HEAD"] = "HEAD";
|
|
11
20
|
HttpMethod["ALL"] = "ALL";
|
|
12
21
|
})(HttpMethod || (HttpMethod = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Declaring the constants
|
|
24
|
+
*/
|
|
13
25
|
export function HttpRoute(options) {
|
|
14
26
|
if (options.path && options.path.charAt(0) !== '/')
|
|
15
27
|
options.path = `/${options.path}`;
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing user defined packages
|
|
3
|
+
*/
|
|
1
4
|
import { HTTP_CONTROLLER_TYPE } from '../constants.js';
|
|
5
|
+
/**
|
|
6
|
+
* Defining types
|
|
7
|
+
*/
|
|
2
8
|
export type MiddlewareType = 'onRequest' | 'preParsing' | 'preValidation' | 'preHandler' | 'preSerialization' | 'onSend' | 'onResponse' | 'onError';
|
|
3
9
|
export interface MiddlewareOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Denotes when to execute the middleware. default value is `preHandler`.
|
|
12
|
+
* see https://fastify.dev/docs/latest/Reference/Lifecycle for more information
|
|
13
|
+
*/
|
|
4
14
|
type: MiddlewareType;
|
|
15
|
+
/** Denotes the execution order, the higher value gets executed first */
|
|
5
16
|
weight: number;
|
|
6
17
|
}
|
|
7
18
|
export interface MiddlewareMetadata extends MiddlewareOptions {
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import assert from 'node:assert';
|
|
2
5
|
import { Controller } from '@shadow-library/app';
|
|
6
|
+
/**
|
|
7
|
+
* Importing user defined packages
|
|
8
|
+
*/
|
|
3
9
|
import { HTTP_CONTROLLER_TYPE } from '../constants.js';
|
|
10
|
+
/**
|
|
11
|
+
* Declaring the constants
|
|
12
|
+
*/
|
|
4
13
|
const propertyKeys = ['generate', 'use'];
|
|
5
14
|
export function Middleware(options = {}) {
|
|
6
15
|
if (!options.type)
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { MaskOptions } from '@shadow-library/common';
|
|
2
|
+
/**
|
|
3
|
+
* Importing user defined packages
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Defining types
|
|
7
|
+
*/
|
|
2
8
|
export type SensitiveDataType = 'secret' | 'email' | 'number' | 'words';
|
|
9
|
+
/**
|
|
10
|
+
* Declaring the constants
|
|
11
|
+
*/
|
|
3
12
|
export declare function Sensitive(type?: SensitiveDataType): PropertyDecorator;
|
|
4
13
|
export declare function Sensitive(maskOptions: MaskOptions): PropertyDecorator;
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Importing user defined packages
|
|
6
|
+
*/
|
|
1
7
|
import { HttpRequest, HttpResponse } from './route-handler.interface.js';
|
|
8
|
+
/**
|
|
9
|
+
* Defining types
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Declaring the constants
|
|
13
|
+
*/
|
|
2
14
|
export interface ErrorHandler {
|
|
3
15
|
handle(err: Error, req: HttpRequest, res: HttpResponse): any | Promise<any>;
|
|
4
16
|
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import { RouteMetadata } from '@shadow-library/app';
|
|
5
|
+
/**
|
|
6
|
+
* Importing user defined packages
|
|
7
|
+
*/
|
|
2
8
|
import { HttpCallback, HttpRequest, HttpResponse, RouteHandler } from './route-handler.interface.js';
|
|
9
|
+
/**
|
|
10
|
+
* Defining types
|
|
11
|
+
*/
|
|
3
12
|
export interface MiddlewareGenerator {
|
|
4
13
|
cacheKey?: (metadata: RouteMetadata) => string;
|
|
5
14
|
generate(metadata: RouteMetadata): RouteHandler | undefined | Promise<RouteHandler | undefined>;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import { SyncValue } from '@shadow-library/common';
|
|
2
5
|
import { DoneFuncWithErrOrRes, FastifyReply, FastifyRequest } from 'fastify';
|
|
6
|
+
/**
|
|
7
|
+
* Importing user defined packages
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Defining types
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Declaring the constants
|
|
14
|
+
*/
|
|
3
15
|
export type HttpRequest = FastifyRequest;
|
|
4
16
|
export type HttpResponse = FastifyReply;
|
|
5
17
|
export type HttpCallback = DoneFuncWithErrOrRes;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import { RouteMetadata } from '@shadow-library/app';
|
|
2
5
|
import { JSONSchema } from '@shadow-library/class-schema';
|
|
3
6
|
import { RouteShorthandOptions } from 'fastify';
|
|
7
|
+
/**
|
|
8
|
+
* Importing user defined packages
|
|
9
|
+
*/
|
|
4
10
|
import { HTTP_CONTROLLER_TYPE } from '../constants.js';
|
|
5
11
|
import { HttpMethod, RouteInputSchemas } from '../decorators/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Defining types
|
|
14
|
+
*/
|
|
6
15
|
declare module '@shadow-library/app' {
|
|
7
16
|
interface RouteMetadata extends Omit<RouteShorthandOptions, 'config'> {
|
|
8
17
|
method?: HttpMethod;
|
|
@@ -7,7 +7,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Importing npm packages
|
|
12
|
+
*/
|
|
10
13
|
import { Field, Schema } from '@shadow-library/class-schema';
|
|
14
|
+
/**
|
|
15
|
+
* Importing user defined packages
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Defining types
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Declaring the constants
|
|
22
|
+
*/
|
|
11
23
|
let ErrorFieldDto = class ErrorFieldDto {
|
|
12
24
|
field;
|
|
13
25
|
msg;
|
|
@@ -1,24 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing npm packages
|
|
3
|
+
*/
|
|
1
4
|
import { FactoryProvider, ModuleMetadata } from '@shadow-library/app';
|
|
2
5
|
import { JSONSchema } from '@shadow-library/class-schema';
|
|
3
6
|
import { FastifyInstance, FastifyServerOptions } from 'fastify';
|
|
4
7
|
import { Promisable } from 'type-fest';
|
|
8
|
+
/**
|
|
9
|
+
* Importing user defined packages
|
|
10
|
+
*/
|
|
5
11
|
import { ErrorHandler } from '../interfaces/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Defining types
|
|
14
|
+
*/
|
|
6
15
|
export interface FastifyConfig extends FastifyServerOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The host on which the Fastify instance is to be started
|
|
18
|
+
* @default '127.0.0.1'
|
|
19
|
+
*/
|
|
7
20
|
host: string;
|
|
21
|
+
/**
|
|
22
|
+
* The port on which the Fastify instance is to be started
|
|
23
|
+
* @default 8080
|
|
24
|
+
*/
|
|
8
25
|
port: number;
|
|
26
|
+
/**
|
|
27
|
+
* The error handler to be used to handle errors thrown by the Fastify instance
|
|
28
|
+
* @default DefaultErrorHandler
|
|
29
|
+
*/
|
|
9
30
|
errorHandler: ErrorHandler;
|
|
31
|
+
/**
|
|
32
|
+
* The schema to be used to validate the response of the Fastify instance
|
|
33
|
+
* @default { '4xx': errorResponseSchema, '5xx': errorResponseSchema }
|
|
34
|
+
*/
|
|
10
35
|
responseSchema?: Record<string | number, JSONSchema>;
|
|
36
|
+
/**
|
|
37
|
+
* Enables internal execution of child routes (e.g., for SSR data fetching) without making actual HTTP requests.
|
|
38
|
+
* Useful for loading data while reusing middleware logic and shared context.
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
11
41
|
enableChildRoutes?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Masks fields marked as sensitive in API inputs (body, query, and URL params) when written to logs.
|
|
44
|
+
* @default true
|
|
45
|
+
*/
|
|
12
46
|
maskSensitiveData?: boolean;
|
|
13
47
|
}
|
|
14
48
|
export interface FastifyModuleOptions extends Partial<FastifyConfig> {
|
|
49
|
+
/**
|
|
50
|
+
* The list of modules whose controllers are to be registered in the Fastify instance
|
|
51
|
+
*/
|
|
15
52
|
imports?: ModuleMetadata['imports'];
|
|
53
|
+
/**
|
|
54
|
+
* Factory function to modify the Fastify instance before it is used to register the controllers
|
|
55
|
+
*/
|
|
16
56
|
fastifyFactory?: (instance: FastifyInstance) => Promisable<FastifyInstance>;
|
|
57
|
+
/**
|
|
58
|
+
* The list of controllers to be registered in the Fastify instance
|
|
59
|
+
*/
|
|
17
60
|
controllers?: ModuleMetadata['controllers'];
|
|
61
|
+
/**
|
|
62
|
+
* The list of providers to be registered in the Fastify instance
|
|
63
|
+
*/
|
|
18
64
|
providers?: ModuleMetadata['providers'];
|
|
65
|
+
/**
|
|
66
|
+
* The list of providers to be exported by the Fastify module
|
|
67
|
+
*/
|
|
19
68
|
exports?: ModuleMetadata['exports'];
|
|
20
69
|
}
|
|
21
70
|
export interface FastifyModuleAsyncOptions extends Pick<FastifyModuleOptions, 'imports' | 'controllers' | 'providers' | 'exports' | 'fastifyFactory'> {
|
|
71
|
+
/**
|
|
72
|
+
* Factory function to create the FastifyModuleOptions
|
|
73
|
+
*/
|
|
22
74
|
useFactory: (...args: any[]) => Promisable<FastifyConfig>;
|
|
75
|
+
/**
|
|
76
|
+
* The list of providers to be injected into the factory function
|
|
77
|
+
*/
|
|
23
78
|
inject?: FactoryProvider['inject'];
|
|
24
79
|
}
|