@expressive-tea/core 2.0.0
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/.gitattributes +4 -0
- package/.swcrc +61 -0
- package/LICENSE +201 -0
- package/README.md +627 -0
- package/banner.png +0 -0
- package/classes/Boot.d.ts +145 -0
- package/classes/Boot.js +223 -0
- package/classes/Engine.d.ts +63 -0
- package/classes/Engine.js +90 -0
- package/classes/EngineRegistry.d.ts +154 -0
- package/classes/EngineRegistry.js +247 -0
- package/classes/LoadBalancer.d.ts +8 -0
- package/classes/LoadBalancer.js +28 -0
- package/classes/ProxyRoute.d.ts +14 -0
- package/classes/ProxyRoute.js +40 -0
- package/classes/Settings.d.ts +128 -0
- package/classes/Settings.js +172 -0
- package/decorators/annotations.d.ts +91 -0
- package/decorators/annotations.js +132 -0
- package/decorators/env.d.ts +145 -0
- package/decorators/env.js +177 -0
- package/decorators/health.d.ts +115 -0
- package/decorators/health.js +124 -0
- package/decorators/module.d.ts +34 -0
- package/decorators/module.js +39 -0
- package/decorators/proxy.d.ts +28 -0
- package/decorators/proxy.js +60 -0
- package/decorators/router.d.ts +199 -0
- package/decorators/router.js +252 -0
- package/decorators/server.d.ts +92 -0
- package/decorators/server.js +247 -0
- package/engines/constants/constants.d.ts +2 -0
- package/engines/constants/constants.js +5 -0
- package/engines/health/index.d.ts +120 -0
- package/engines/health/index.js +179 -0
- package/engines/http/index.d.ts +12 -0
- package/engines/http/index.js +59 -0
- package/engines/index.d.ts +32 -0
- package/engines/index.js +112 -0
- package/engines/socketio/index.d.ts +7 -0
- package/engines/socketio/index.js +30 -0
- package/engines/teacup/index.d.ts +27 -0
- package/engines/teacup/index.js +136 -0
- package/engines/teapot/index.d.ts +32 -0
- package/engines/teapot/index.js +167 -0
- package/engines/websocket/index.d.ts +9 -0
- package/engines/websocket/index.js +39 -0
- package/eslint.config.mjs +138 -0
- package/exceptions/BootLoaderExceptions.d.ts +26 -0
- package/exceptions/BootLoaderExceptions.js +31 -0
- package/exceptions/RequestExceptions.d.ts +75 -0
- package/exceptions/RequestExceptions.js +89 -0
- package/helpers/boot-helper.d.ts +7 -0
- package/helpers/boot-helper.js +84 -0
- package/helpers/decorators.d.ts +1 -0
- package/helpers/decorators.js +15 -0
- package/helpers/promise-helper.d.ts +1 -0
- package/helpers/promise-helper.js +6 -0
- package/helpers/server.d.ts +35 -0
- package/helpers/server.js +141 -0
- package/helpers/teapot-helper.d.ts +18 -0
- package/helpers/teapot-helper.js +88 -0
- package/helpers/websocket-helper.d.ts +3 -0
- package/helpers/websocket-helper.js +20 -0
- package/images/announcement-01.png +0 -0
- package/images/logo-sticky-01.png +0 -0
- package/images/logo-wp-01.png +0 -0
- package/images/logo.png +0 -0
- package/images/zero-oneit.png +0 -0
- package/interfaces/index.d.ts +4 -0
- package/interfaces/index.js +2 -0
- package/inversify.config.d.ts +9 -0
- package/inversify.config.js +8 -0
- package/libs/classNames.d.ts +1 -0
- package/libs/classNames.js +4 -0
- package/libs/utilities.d.ts +21910 -0
- package/libs/utilities.js +420 -0
- package/mixins/module.d.ts +45 -0
- package/mixins/module.js +71 -0
- package/mixins/proxy.d.ts +46 -0
- package/mixins/proxy.js +86 -0
- package/mixins/route.d.ts +48 -0
- package/mixins/route.js +96 -0
- package/package.json +137 -0
- package/services/DependencyInjection.d.ts +159 -0
- package/services/DependencyInjection.js +201 -0
- package/services/WebsocketService.d.ts +18 -0
- package/services/WebsocketService.js +47 -0
- package/types/core.d.ts +14 -0
- package/types/core.js +2 -0
- package/types/injection-types.d.ts +6 -0
- package/types/injection-types.js +10 -0
- package/types/inversify.d.ts +5 -0
- package/types/inversify.js +3 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HealthCheck = HealthCheck;
|
|
4
|
+
exports.getHealthChecks = getHealthChecks;
|
|
5
|
+
const commons_1 = require("@expressive-tea/commons");
|
|
6
|
+
/**
|
|
7
|
+
* Health check decorator metadata key
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
const HEALTH_CHECKS_KEY = 'expressive-tea:health-checks';
|
|
11
|
+
/**
|
|
12
|
+
* Class decorator to register health checks for monitoring and orchestration.
|
|
13
|
+
*
|
|
14
|
+
* Adds standardized health check endpoints:
|
|
15
|
+
* - `/health` - Detailed health status with all checks
|
|
16
|
+
* - `/health/live` - Liveness probe (Kubernetes compatible)
|
|
17
|
+
* - `/health/ready` - Readiness probe (only passes if all critical checks pass)
|
|
18
|
+
*
|
|
19
|
+
* Health checks are executed asynchronously and can be marked as critical for readiness.
|
|
20
|
+
* Non-critical checks only affect the detailed `/health` endpoint.
|
|
21
|
+
*
|
|
22
|
+
* @decorator {ClassDecorator} HealthCheck - Register health checks
|
|
23
|
+
* @param options - Health check configuration
|
|
24
|
+
* @returns Class decorator function
|
|
25
|
+
* @since 2.0.0
|
|
26
|
+
* @summary Register application health checks for monitoring
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Basic health check
|
|
30
|
+
* @HealthCheck({
|
|
31
|
+
* checks: [
|
|
32
|
+
* {
|
|
33
|
+
* name: 'database',
|
|
34
|
+
* check: async () => {
|
|
35
|
+
* const isConnected = await db.ping();
|
|
36
|
+
* return { status: isConnected ? 'pass' : 'fail' };
|
|
37
|
+
* },
|
|
38
|
+
* critical: true,
|
|
39
|
+
* timeout: 5000
|
|
40
|
+
* }
|
|
41
|
+
* ]
|
|
42
|
+
* })
|
|
43
|
+
* class MyApp extends Boot {}
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // Multiple health checks with different priorities
|
|
47
|
+
* @HealthCheck({
|
|
48
|
+
* checks: [
|
|
49
|
+
* {
|
|
50
|
+
* name: 'database',
|
|
51
|
+
* check: async () => {
|
|
52
|
+
* const connected = await db.ping();
|
|
53
|
+
* return {
|
|
54
|
+
* status: connected ? 'pass' : 'fail',
|
|
55
|
+
* details: { connections: db.poolSize }
|
|
56
|
+
* };
|
|
57
|
+
* },
|
|
58
|
+
* critical: true // Required for readiness
|
|
59
|
+
* },
|
|
60
|
+
* {
|
|
61
|
+
* name: 'cache',
|
|
62
|
+
* check: async () => {
|
|
63
|
+
* const ready = await redis.ping();
|
|
64
|
+
* return {
|
|
65
|
+
* status: ready ? 'pass' : 'warn', // Warn but don't fail
|
|
66
|
+
* details: { cached_items: await redis.dbsize() }
|
|
67
|
+
* };
|
|
68
|
+
* },
|
|
69
|
+
* critical: false // Optional, won't block readiness
|
|
70
|
+
* },
|
|
71
|
+
* {
|
|
72
|
+
* name: 'external_api',
|
|
73
|
+
* check: async () => {
|
|
74
|
+
* try {
|
|
75
|
+
* const response = await fetch('https://api.example.com/status');
|
|
76
|
+
* return { status: response.ok ? 'pass' : 'warn' };
|
|
77
|
+
* } catch (error) {
|
|
78
|
+
* return {
|
|
79
|
+
* status: 'warn',
|
|
80
|
+
* error: error.message
|
|
81
|
+
* };
|
|
82
|
+
* }
|
|
83
|
+
* },
|
|
84
|
+
* timeout: 3000
|
|
85
|
+
* }
|
|
86
|
+
* ]
|
|
87
|
+
* })
|
|
88
|
+
* class MyApp extends Boot {}
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* // Kubernetes deployment.yaml example
|
|
92
|
+
* // spec:
|
|
93
|
+
* // containers:
|
|
94
|
+
* // - name: my-app
|
|
95
|
+
* // livenessProbe:
|
|
96
|
+
* // httpGet:
|
|
97
|
+
* // path: /health/live
|
|
98
|
+
* // port: 3000
|
|
99
|
+
* // initialDelaySeconds: 30
|
|
100
|
+
* // periodSeconds: 10
|
|
101
|
+
* // readinessProbe:
|
|
102
|
+
* // httpGet:
|
|
103
|
+
* // path: /health/ready
|
|
104
|
+
* // port: 3000
|
|
105
|
+
* // initialDelaySeconds: 5
|
|
106
|
+
* // periodSeconds: 5
|
|
107
|
+
*/
|
|
108
|
+
function HealthCheck(options) {
|
|
109
|
+
return (target) => {
|
|
110
|
+
// Store health checks in metadata
|
|
111
|
+
commons_1.Metadata.set(HEALTH_CHECKS_KEY, options.checks, target);
|
|
112
|
+
return target;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get health checks from a class
|
|
117
|
+
* @param target - Target class
|
|
118
|
+
* @returns Array of health checks
|
|
119
|
+
* @since 2.0.0
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
function getHealthChecks(target) {
|
|
123
|
+
return commons_1.Metadata.get(HEALTH_CHECKS_KEY, target) || [];
|
|
124
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ExpressiveTeaModuleProps } from '@expressive-tea/commons';
|
|
2
|
+
import { type Constructor } from '../types/core';
|
|
3
|
+
import { type ModulizedClass } from '../mixins/module';
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {Object} ExpressiveTeaModuleProps
|
|
6
|
+
* @property {Object[]} controllers Controllers Assigned to Module
|
|
7
|
+
* @property {Object[]} providers Dependency Injection Providers
|
|
8
|
+
* @property {string} mountpoint Endpoint part which Module it will use as root.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @module Decorators/Module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Module Decorator is a Class Decorator which is help to register a Module into Expressive Tea. A module is a
|
|
15
|
+
* placeholder over a mountpoint. We can considerate a module like a container which provide isolation and modularity
|
|
16
|
+
* for our project. This module can be mounted in different applications and will move all the controller routes too.
|
|
17
|
+
*
|
|
18
|
+
* @decorator {ClassDecorator} Module - Module Class Register Decorator
|
|
19
|
+
* @template TBase - The base constructor type being decorated
|
|
20
|
+
* @param {ExpressiveTeaModuleProps} options - Module configuration options
|
|
21
|
+
* @returns {(target: TBase) => ModulizedClass<TBase>} Decorator function that returns a modulized class
|
|
22
|
+
* @summary Module Decorator
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* {REPLACE-AT}Module({
|
|
26
|
+
* controllers: [UserController],
|
|
27
|
+
* providers: [UserService],
|
|
28
|
+
* mountpoint: '/api'
|
|
29
|
+
* })
|
|
30
|
+
* class ApiModule {}
|
|
31
|
+
*
|
|
32
|
+
* @since 1.0.0
|
|
33
|
+
*/
|
|
34
|
+
export declare function Module<TBase extends Constructor = Constructor>(options: ExpressiveTeaModuleProps): (target: TBase) => ModulizedClass<TBase>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Module = Module;
|
|
4
|
+
const module_1 = require("../mixins/module");
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Object} ExpressiveTeaModuleProps
|
|
7
|
+
* @property {Object[]} controllers Controllers Assigned to Module
|
|
8
|
+
* @property {Object[]} providers Dependency Injection Providers
|
|
9
|
+
* @property {string} mountpoint Endpoint part which Module it will use as root.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @module Decorators/Module
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Module Decorator is a Class Decorator which is help to register a Module into Expressive Tea. A module is a
|
|
16
|
+
* placeholder over a mountpoint. We can considerate a module like a container which provide isolation and modularity
|
|
17
|
+
* for our project. This module can be mounted in different applications and will move all the controller routes too.
|
|
18
|
+
*
|
|
19
|
+
* @decorator {ClassDecorator} Module - Module Class Register Decorator
|
|
20
|
+
* @template TBase - The base constructor type being decorated
|
|
21
|
+
* @param {ExpressiveTeaModuleProps} options - Module configuration options
|
|
22
|
+
* @returns {(target: TBase) => ModulizedClass<TBase>} Decorator function that returns a modulized class
|
|
23
|
+
* @summary Module Decorator
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* {REPLACE-AT}Module({
|
|
27
|
+
* controllers: [UserController],
|
|
28
|
+
* providers: [UserService],
|
|
29
|
+
* mountpoint: '/api'
|
|
30
|
+
* })
|
|
31
|
+
* class ApiModule {}
|
|
32
|
+
*
|
|
33
|
+
* @since 1.0.0
|
|
34
|
+
*/
|
|
35
|
+
function Module(options) {
|
|
36
|
+
return (Module) => {
|
|
37
|
+
return (0, module_1.Modulize)(Module, options);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ExpressiveTeaProxyOptions, type ExpressiveTeaProxyProperty, type MethodDecorator } from '@expressive-tea/commons';
|
|
2
|
+
import { type ProxifiedClass } from '../mixins/proxy';
|
|
3
|
+
import { type Constructor } from '../types/core';
|
|
4
|
+
/**
|
|
5
|
+
* ProxyContainer decorator - Creates an HTTP proxy for a microservice
|
|
6
|
+
*
|
|
7
|
+
* Transforms a class into an HTTP proxy that forwards requests from a source path
|
|
8
|
+
* to a target URL. Supports custom request/response transformations and options.
|
|
9
|
+
*
|
|
10
|
+
* @template TBase - The base constructor type being decorated
|
|
11
|
+
* @param {string} source - The source path to proxy from (e.g., '/api')
|
|
12
|
+
* @param {string} targetUrl - The target URL to proxy to (e.g., 'http://api.example.com')
|
|
13
|
+
* @returns {(target: TBase) => ProxifiedClass<TBase>} Decorator function that returns a proxified class
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* {REPLACE-AT}ProxyContainer('/api', 'http://api.example.com')
|
|
17
|
+
* class ApiProxy {
|
|
18
|
+
* {REPLACE-AT}ProxyOption('host')
|
|
19
|
+
* getHost() {
|
|
20
|
+
* return 'http://api.example.com';
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @since 1.0.0
|
|
25
|
+
*/
|
|
26
|
+
export declare function ProxyContainer<TBase extends Constructor = Constructor>(source: string, targetUrl: string): (ProxyContainerClass: TBase) => ProxifiedClass<TBase>;
|
|
27
|
+
export declare function ProxyOption(option: ExpressiveTeaProxyOptions): MethodDecorator;
|
|
28
|
+
export declare function ProxyProperty(option: ExpressiveTeaProxyProperty, value: any): PropertyDecorator;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProxyContainer = ProxyContainer;
|
|
4
|
+
exports.ProxyOption = ProxyOption;
|
|
5
|
+
exports.ProxyProperty = ProxyProperty;
|
|
6
|
+
const commons_1 = require("@expressive-tea/commons");
|
|
7
|
+
const commons_2 = require("@expressive-tea/commons");
|
|
8
|
+
const RequestExceptions_1 = require("../exceptions/RequestExceptions");
|
|
9
|
+
const commons_3 = require("@expressive-tea/commons");
|
|
10
|
+
const proxy_1 = require("../mixins/proxy");
|
|
11
|
+
const NON_ASYNC_METHODS = new Set(['host']);
|
|
12
|
+
/**
|
|
13
|
+
* ProxyContainer decorator - Creates an HTTP proxy for a microservice
|
|
14
|
+
*
|
|
15
|
+
* Transforms a class into an HTTP proxy that forwards requests from a source path
|
|
16
|
+
* to a target URL. Supports custom request/response transformations and options.
|
|
17
|
+
*
|
|
18
|
+
* @template TBase - The base constructor type being decorated
|
|
19
|
+
* @param {string} source - The source path to proxy from (e.g., '/api')
|
|
20
|
+
* @param {string} targetUrl - The target URL to proxy to (e.g., 'http://api.example.com')
|
|
21
|
+
* @returns {(target: TBase) => ProxifiedClass<TBase>} Decorator function that returns a proxified class
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* {REPLACE-AT}ProxyContainer('/api', 'http://api.example.com')
|
|
25
|
+
* class ApiProxy {
|
|
26
|
+
* {REPLACE-AT}ProxyOption('host')
|
|
27
|
+
* getHost() {
|
|
28
|
+
* return 'http://api.example.com';
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* @since 1.0.0
|
|
33
|
+
*/
|
|
34
|
+
function ProxyContainer(source, targetUrl) {
|
|
35
|
+
return (ProxyContainerClass) => {
|
|
36
|
+
const settings = {
|
|
37
|
+
source,
|
|
38
|
+
targetUrl,
|
|
39
|
+
name: ProxyContainerClass.name
|
|
40
|
+
};
|
|
41
|
+
commons_1.Metadata.set(commons_3.PROXY_SETTING_KEY, settings, ProxyContainerClass);
|
|
42
|
+
return (0, proxy_1.Proxify)(ProxyContainerClass, source, targetUrl);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function ProxyOption(option) {
|
|
46
|
+
return (target, propertyKey, descriptor) => {
|
|
47
|
+
if (NON_ASYNC_METHODS.has(option) && (0, commons_2.isAsyncFunction)(descriptor.value)) {
|
|
48
|
+
throw new RequestExceptions_1.GenericRequestException(`${String(propertyKey)} must not be declared as Async Function.`);
|
|
49
|
+
}
|
|
50
|
+
commons_1.Metadata.set(commons_3.PROXY_SETTING_KEY, descriptor, target, option);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function ProxyProperty(option, value) {
|
|
54
|
+
return (target, propertyKey) => {
|
|
55
|
+
commons_1.Metadata.set(commons_3.PROXY_SETTING_KEY, propertyKey, target, option);
|
|
56
|
+
Object.defineProperty(target, propertyKey, {
|
|
57
|
+
get: () => value,
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { type ClassDecorator, type MethodDecorator } from '@expressive-tea/commons';
|
|
2
|
+
import { type RouterizedClass } from '../mixins/route';
|
|
3
|
+
import { type Constructor, TFunction } from '../types/core';
|
|
4
|
+
import { type RequestHandler } from 'express';
|
|
5
|
+
/**
|
|
6
|
+
* @module Decorators/Router
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Route Controller Decorator assign a router point into the module mount-point placeholder and is used just to create
|
|
10
|
+
* a bucket to contains all the endpoints defined by method of the Controller. If mount-point is not defined automati-
|
|
11
|
+
* cally this must considerate mounted on root, but is mandatory define the Controller with this decorator in order
|
|
12
|
+
* to allow Expressive Tea Setting up the Controller as part of a Module.
|
|
13
|
+
*
|
|
14
|
+
* @decorator {ClassDecorator} Route - Assign a route to controller endpoints.
|
|
15
|
+
* @template TBase - The base constructor type being decorated
|
|
16
|
+
* @param {string} mountpoint - Register the url part to mount the Controller (default: '/')
|
|
17
|
+
* @returns {(target: TBase) => RouterizedClass<TBase>} Decorator function that returns a routerized class
|
|
18
|
+
* @summary Generate a Placeholder endpoint root for controller routes.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* {REPLACE-AT}Route('/users')
|
|
22
|
+
* class UserController {
|
|
23
|
+
* {REPLACE-AT}Get('/')
|
|
24
|
+
* getUsers() { return ['user1', 'user2']; }
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* @since 1.0.0
|
|
28
|
+
*/
|
|
29
|
+
export declare function Route<TBase extends Constructor = Constructor>(mountpoint?: string): (RouterClass: TBase) => RouterizedClass<TBase>;
|
|
30
|
+
/**
|
|
31
|
+
* Define a GET Endpoint response over the controller router and can define in which route should be responds and
|
|
32
|
+
* by default this is responding to everything on the controller root path.
|
|
33
|
+
* @decorator {MethodDecorator} Get - Create an GET Response over the designed route.
|
|
34
|
+
* @summary Define a GET Controller Endpoint on Controller.
|
|
35
|
+
* @param {string} route URL Part to mount create a handler.
|
|
36
|
+
* @example
|
|
37
|
+
* {REPLACE-AT}Route('/')
|
|
38
|
+
* class GenericController {
|
|
39
|
+
* {REPLACE-AT}Get() // This Response to all GET Requests for controller route.
|
|
40
|
+
* methodError() {}
|
|
41
|
+
*
|
|
42
|
+
* {REPLACE-AT}Get('/data') // This Response to "/data" GET Requests for controller route.
|
|
43
|
+
* methodData() {}
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
export declare function Get(route?: string): (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Define a POST Endpoint response over the controller router and can define in which route should be responds and
|
|
50
|
+
* by default this is responding to everything on the controller root path.
|
|
51
|
+
* @decorator {MethodDecorator} POST - Create an POST Response over the designed route.
|
|
52
|
+
* @summary Define a POST Controller Endpoint on Controller.
|
|
53
|
+
* @param {string} route URL Part to mount create a handler.
|
|
54
|
+
* @example
|
|
55
|
+
* {REPLACE-AT}Route('/')
|
|
56
|
+
* class GenericController {
|
|
57
|
+
* {REPLACE-AT}Post() // This Response to all GET Requests for controller route.
|
|
58
|
+
* methodError() {}
|
|
59
|
+
*
|
|
60
|
+
* {REPLACE-AT}Post('/data') // This Response to "/data" GET Requests for controller route.
|
|
61
|
+
* methodData() {}
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
export declare function Post(route?: string): (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Define a PUT Endpoint response over the controller router and can define in which route should be responds and
|
|
68
|
+
* by default this is responding to everything on the controller root path.
|
|
69
|
+
* @decorator {MethodDecorator} Put - Create an PUT Response over the designed route.
|
|
70
|
+
* @summary Define a PUT Controller Endpoint on Controller.
|
|
71
|
+
* @param {string} route URL Part to mount create a handler.
|
|
72
|
+
* @example
|
|
73
|
+
* {REPLACE-AT}Route('/')
|
|
74
|
+
* class GenericController {
|
|
75
|
+
* {REPLACE-AT}Put() // This Response to all PUT Requests for controller route.
|
|
76
|
+
* methodError() {}
|
|
77
|
+
*
|
|
78
|
+
* {REPLACE-AT}Put('/data') // This Response to "/data" PUT Requests for controller route.
|
|
79
|
+
* methodData() {}
|
|
80
|
+
* }
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
export declare function Put(route?: string): (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
84
|
+
/**
|
|
85
|
+
* Define a PATCH Endpoint response over the controller router and can define in which route should be responds and
|
|
86
|
+
* by default this is responding to everything on the controller root path.
|
|
87
|
+
* @decorator {MethodDecorator} Patch - Create an PATCH Response over the designed route.
|
|
88
|
+
* @summary Define a PATCH Controller Endpoint on Controller.
|
|
89
|
+
* @param {string} route URL Part to mount create a handler.
|
|
90
|
+
* @example
|
|
91
|
+
* {REPLACE-AT}Route('/')
|
|
92
|
+
* class GenericController {
|
|
93
|
+
* {REPLACE-AT}Patch() // This Response to all PATCH Requests for controller route.
|
|
94
|
+
* methodError() {}
|
|
95
|
+
*
|
|
96
|
+
* {REPLACE-AT}Patch('/data') // This Response to "/data" PATCH Requests for controller route.
|
|
97
|
+
* methodData() {}
|
|
98
|
+
* }
|
|
99
|
+
*
|
|
100
|
+
*/
|
|
101
|
+
export declare function Patch(route?: string): (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
102
|
+
/**
|
|
103
|
+
* Define a DELETE Endpoint response over the controller router and can define in which route should be responds and
|
|
104
|
+
* by default this is responding to everything on the controller root path.
|
|
105
|
+
* @decorator {MethodDecorator} Delete - Create an DELETE Response over the designed route.
|
|
106
|
+
* @summary Define a DELETE Controller Endpoint on Controller.
|
|
107
|
+
* @param {string} route URL Part to mount create a handler.
|
|
108
|
+
* @example
|
|
109
|
+
* {REPLACE-AT}Route('/')
|
|
110
|
+
* class GenericController {
|
|
111
|
+
* {REPLACE-AT}Delete() // This Response to all DELETE Requests for controller route.
|
|
112
|
+
* methodError() {}
|
|
113
|
+
*
|
|
114
|
+
* {REPLACE-AT}Delete('/data') // This Response to "/data" DELETE Requests for controller route.
|
|
115
|
+
* methodData() {}
|
|
116
|
+
* }
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
export declare function Delete(route?: string): (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
120
|
+
/**
|
|
121
|
+
* Define a Route path parameter transformation method as mentioned on Express this is just call by controller endpoints
|
|
122
|
+
* route paths and it helps to define logic on each route path parameters. Example, you can require transform userId
|
|
123
|
+
* parameter and added to request object.
|
|
124
|
+
*
|
|
125
|
+
* The method to response this must follow the Express callback notation (Request, Response, Next, paramValue) which
|
|
126
|
+
* also must be use Next method to allow continue the process flow from Express.
|
|
127
|
+
* @decorator {MethodDecorator} Param - Create a transformation middleware for router parameters.
|
|
128
|
+
* @summary Define a Parameter transformation on router path..
|
|
129
|
+
* @param {string} route URL Part to mount create a handler.
|
|
130
|
+
* @example
|
|
131
|
+
* {REPLACE-AT}Route('/')
|
|
132
|
+
* class GenericController {
|
|
133
|
+
* {REPLACE-AT}Param('userId') // This Response to all GET Requests for controller route.
|
|
134
|
+
* async methodError(req, res, next, param, id) {
|
|
135
|
+
* const user = await User.find(id)
|
|
136
|
+
* try {
|
|
137
|
+
* if(!user) throw new Error('User not Found');
|
|
138
|
+
*
|
|
139
|
+
* req.user = user;
|
|
140
|
+
* next();
|
|
141
|
+
* } catch(e) {
|
|
142
|
+
* next(e);
|
|
143
|
+
* }
|
|
144
|
+
* }
|
|
145
|
+
*
|
|
146
|
+
* {REPLACE-AT}Get('/:userId') // This Response to "/:userId" GET Requests for controller route.
|
|
147
|
+
* methodData(req, res) {
|
|
148
|
+
* res.json(req.user);
|
|
149
|
+
* }
|
|
150
|
+
* }
|
|
151
|
+
*
|
|
152
|
+
*/
|
|
153
|
+
export declare function Param(route?: string): (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
154
|
+
/**
|
|
155
|
+
* Middleware Decorator is following the middleware functionality inheritance from Express framework itself and follow
|
|
156
|
+
* the same rules, that execute any code before response the request and can change the current request or response
|
|
157
|
+
* object, and requires use next callback to pass control to next middleware.
|
|
158
|
+
*
|
|
159
|
+
* This define the middlewares at Controller and Controller methods level, for application levels please see the
|
|
160
|
+
* Plug Decorator which can be useful to declare at that level..
|
|
161
|
+
* @decorator {MethodDecorator|ClassDecorator} Middleware - Attach a middleware definition on the root route or endpoint
|
|
162
|
+
* routes.
|
|
163
|
+
* @summary Assign a middleware to the Controller or Method route path flow.
|
|
164
|
+
* @example
|
|
165
|
+
* {REPLACE-AT}Middleware((req, res, next) {
|
|
166
|
+
* req.controllerName = 'Example';
|
|
167
|
+
* next();
|
|
168
|
+
* })
|
|
169
|
+
* class ExampleController {
|
|
170
|
+
* {REPLACE-AT}Get('/someResponse')
|
|
171
|
+
* {REPLACE-AT}Middleware((req, res, next) {
|
|
172
|
+
* req.methodName = 'someResponse';
|
|
173
|
+
* next();
|
|
174
|
+
* })
|
|
175
|
+
* someRespone(req, res) {
|
|
176
|
+
* res.send(`${req.controllerName}:${req.methodName}`);
|
|
177
|
+
* }
|
|
178
|
+
* }
|
|
179
|
+
*
|
|
180
|
+
* @param {Function} middleware Register a middleware over router.
|
|
181
|
+
*/
|
|
182
|
+
export declare function Middleware(middleware: RequestHandler | TFunction<RequestHandler>): ClassDecorator & MethodDecorator;
|
|
183
|
+
/**
|
|
184
|
+
* Will generate a GET route to respond rendering a view template setting up before; the controller method <b>MUST</b>
|
|
185
|
+
* return an object in order to fulfilled the local variables into the view.
|
|
186
|
+
* @decorator {MethodDecorator} View - Create a Vew Response over the designed route.
|
|
187
|
+
* @summary Define a View response endpoint on Controller.
|
|
188
|
+
* @param {string} viewName - View render layout name defined by configuration.
|
|
189
|
+
* @param {string} route - URL Part to mount create a handler.
|
|
190
|
+
* @return {object} Controller must return and object as local variables for the view.
|
|
191
|
+
* @example
|
|
192
|
+
* {REPLACE-AT}Route('/')
|
|
193
|
+
* class GenericController {
|
|
194
|
+
* {REPLACE-AT}View('login', '/view') // This Response to all GET Requests for controller route.
|
|
195
|
+
* methodError() {}
|
|
196
|
+
* }
|
|
197
|
+
*
|
|
198
|
+
*/
|
|
199
|
+
export declare function View(viewName: string, route?: string): MethodDecorator;
|