@adaas/a-server 0.0.15 → 0.0.17
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 +504 -18
- package/dist/index.d.ts +16 -5
- package/dist/index.js +47 -17
- package/dist/index.js.map +1 -1
- package/dist/src/channels/A-Http/A-Http.channel.constants.d.ts +5 -0
- package/dist/src/channels/A-Http/A-Http.channel.constants.js +10 -0
- package/dist/src/channels/A-Http/A-Http.channel.constants.js.map +1 -0
- package/dist/src/channels/A-Http/A-Http.channel.d.ts +28 -0
- package/dist/src/channels/A-Http/A-Http.channel.error.d.ts +4 -0
- package/dist/src/channels/A-Http/A-Http.channel.error.js +9 -0
- package/dist/src/channels/A-Http/A-Http.channel.error.js.map +1 -0
- package/dist/src/channels/A-Http/A-Http.channel.js +148 -0
- package/dist/src/channels/A-Http/A-Http.channel.js.map +1 -0
- package/dist/src/channels/A-Http/A-Http.channel.types.d.ts +59 -0
- package/dist/src/channels/A-Http/A-Http.channel.types.js +3 -0
- package/dist/src/channels/A-Http/A-Http.channel.types.js.map +1 -0
- package/dist/src/components/A-CommandController/A-CommandController.component.d.ts +2 -2
- package/dist/src/components/A-CommandController/A-CommandController.component.js +5 -2
- package/dist/src/components/A-CommandController/A-CommandController.component.js.map +1 -1
- package/dist/src/components/A-Controller/A-Controller.component.js +0 -4
- package/dist/src/components/A-Controller/A-Controller.component.js.map +1 -1
- package/dist/src/components/A-EntityController/A-EntityController.component.d.ts +1 -1
- package/dist/src/components/A-EntityController/A-EntityController.component.js +26 -15
- package/dist/src/components/A-EntityController/A-EntityController.component.js.map +1 -1
- package/dist/src/components/A-EntityRepository/A-EntityRepository.component.d.ts +7 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.component.js +96 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.component.js.map +1 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.error.js +2 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.error.js.map +1 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.types.js +2 -0
- package/dist/src/components/A-EntityRepository/A-EntityRepository.types.js.map +1 -0
- package/dist/src/components/A-ListingController/A-ListingController.component.d.ts +2 -1
- package/dist/src/components/A-ListingController/A-ListingController.component.js +7 -6
- package/dist/src/components/A-ListingController/A-ListingController.component.js.map +1 -1
- package/dist/src/components/A-Router/A-Router.component.d.ts +3 -2
- package/dist/src/components/A-Router/A-Router.component.js +17 -10
- package/dist/src/components/A-Router/A-Router.component.js.map +1 -1
- package/dist/src/components/A-ServerCORS/A_ServerCORS.component.d.ts +2 -1
- package/dist/src/components/A-ServerCORS/A_ServerCORS.component.js +2 -1
- package/dist/src/components/A-ServerCORS/A_ServerCORS.component.js.map +1 -1
- package/dist/src/components/A-ServerError/A-ServerError.class.d.ts +7 -0
- package/dist/src/components/A-ServerError/A-ServerError.class.js +88 -0
- package/dist/src/components/A-ServerError/A-ServerError.class.js.map +1 -0
- package/dist/src/components/A-ServerError/A-ServerError.constants.d.ts +0 -0
- package/dist/src/components/A-ServerError/A-ServerError.constants.js +2 -0
- package/dist/src/components/A-ServerError/A-ServerError.constants.js.map +1 -0
- package/dist/src/components/A-ServerError/A-ServerError.types.d.ts +13 -0
- package/dist/src/components/A-ServerError/A-ServerError.types.js +3 -0
- package/dist/src/components/A-ServerError/A-ServerError.types.js.map +1 -0
- package/dist/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.d.ts +2 -1
- package/dist/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js +7 -3
- package/dist/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js.map +1 -1
- package/dist/src/components/A-ServerLogger/A_ServerLogger.component.d.ts +3 -2
- package/dist/src/components/A-ServerLogger/A_ServerLogger.component.js +6 -7
- package/dist/src/components/A-ServerLogger/A_ServerLogger.component.js.map +1 -1
- package/dist/src/components/A-ServerLogger/A_ServerLogger.component.types.d.ts +2 -1
- package/dist/src/components/A-ServerProxy/A-ServerProxy.component.d.ts +3 -2
- package/dist/src/components/A-ServerProxy/A-ServerProxy.component.js +4 -3
- package/dist/src/components/A-ServerProxy/A-ServerProxy.component.js.map +1 -1
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.d.ts +2 -1
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.js +3 -2
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.js.map +1 -1
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.types.d.ts +2 -1
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.types.js +2 -1
- package/dist/src/components/A-StaticLoader/A-StaticLoader.component.types.js.map +1 -1
- package/dist/src/containers/A-Service/A-Service.container.d.ts +4 -2
- package/dist/src/containers/A-Service/A-Service.container.js +41 -35
- package/dist/src/containers/A-Service/A-Service.container.js.map +1 -1
- package/dist/src/context/A-EntityFactory/A-EntityFactory.context.d.ts +1 -2
- package/dist/src/context/A-EntityFactory/A-EntityFactory.context.js +6 -7
- package/dist/src/context/A-EntityFactory/A-EntityFactory.context.js.map +1 -1
- package/dist/src/context/A-HttpChannel/A-HttpChannel.context.d.ts +12 -0
- package/dist/src/context/A-HttpChannel/A-HttpChannel.context.js +16 -0
- package/dist/src/context/A-HttpChannel/A-HttpChannel.context.js.map +1 -0
- package/dist/src/context/{A_ListQueryFilter → A-ListQueryFilter}/A_ListQueryFilter.context.js.map +1 -1
- package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.constants.js.map +1 -1
- package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.context.js.map +1 -1
- package/dist/src/context/A-ProxyConfig/A_ProxyConfig.types.js.map +1 -0
- package/dist/src/context/A-Server/A_Server.context.d.ts +1 -1
- package/dist/src/context/A-Server/A_Server.context.js.map +1 -1
- package/dist/src/entities/A-Request/A-Request.entity.d.ts +3 -2
- package/dist/src/entities/A-Request/A-Request.entity.js +12 -19
- package/dist/src/entities/A-Request/A-Request.entity.js.map +1 -1
- package/dist/src/entities/A-Request/A-Request.entity.types.d.ts +2 -2
- package/dist/src/entities/A-Response/A-Response.entity.d.ts +3 -3
- package/dist/src/entities/A-Response/A-Response.entity.js +12 -11
- package/dist/src/entities/A-Response/A-Response.entity.js.map +1 -1
- package/dist/src/entities/A-Response/A-Response.entity.types.d.ts +2 -2
- package/dist/src/entities/A-Route/A-Route.entity.js +3 -1
- package/dist/src/entities/A-Route/A-Route.entity.js.map +1 -1
- package/dist/src/entities/A_EntityList/A_EntityList.entity.js +2 -3
- package/dist/src/entities/A_EntityList/A_EntityList.entity.js.map +1 -1
- package/dist/src/entities/A_EntityList/A_EntityList.entity.types.d.ts +2 -2
- package/examples/simple-server/commands/SignIn.command.ts +2 -2
- package/examples/simple-server/components/Test.controller.ts +19 -5
- package/examples/simple-server/components/Users.repository.ts +10 -7
- package/examples/simple-server/concept.ts +19 -20
- package/examples/simple-server/entities/User/User.entity.ts +10 -7
- package/examples/simple-server/entities/User/User.entity.types.ts +2 -2
- package/index.ts +49 -19
- package/jest.config.ts +1 -0
- package/package.json +4 -4
- package/src/channels/A-Http/A-Http.channel.constants.ts +8 -0
- package/src/channels/A-Http/A-Http.channel.error.ts +8 -0
- package/src/channels/A-Http/A-Http.channel.ts +188 -0
- package/src/channels/A-Http/A-Http.channel.types.ts +66 -0
- package/src/components/A-CommandController/A-CommandController.component.ts +7 -2
- package/src/components/A-Controller/A-Controller.component.ts +0 -4
- package/src/components/A-EntityController/A-EntityController.component.ts +27 -10
- package/src/components/A-EntityRepository/A-EntityRepository.component.ts +88 -0
- package/src/components/A-EntityRepository/A-EntityRepository.error.ts +0 -0
- package/src/components/A-EntityRepository/A-EntityRepository.types.ts +0 -0
- package/src/components/A-ListingController/A-ListingController.component.ts +7 -6
- package/src/components/A-Router/A-Router.component.ts +25 -14
- package/src/components/A-Router/A-Router.component.types.ts +1 -1
- package/src/components/A-ServerCORS/A_ServerCORS.component.ts +2 -1
- package/src/components/A-ServerError/A-ServerError.class.ts +98 -0
- package/src/components/A-ServerError/A-ServerError.constants.ts +0 -0
- package/src/components/A-ServerError/A-ServerError.types.ts +22 -0
- package/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.ts +8 -3
- package/src/components/A-ServerLogger/A_ServerLogger.component.ts +6 -9
- package/src/components/A-ServerLogger/A_ServerLogger.component.types.ts +2 -9
- package/src/components/A-ServerProxy/A-ServerProxy.component.ts +3 -2
- package/src/components/A-StaticLoader/A-StaticLoader.component.ts +2 -1
- package/src/components/A-StaticLoader/A-StaticLoader.component.types.ts +2 -3
- package/src/containers/A-Service/A-Service.container.ts +37 -35
- package/src/context/A-EntityFactory/A-EntityFactory.context.ts +1 -2
- package/src/context/A-HttpChannel/A-HttpChannel.context.ts +36 -0
- package/src/context/A-Server/A_Server.context.ts +2 -3
- package/src/entities/A-Request/A-Request.entity.ts +16 -17
- package/src/entities/A-Request/A-Request.entity.types.ts +3 -3
- package/src/entities/A-Response/A-Response.entity.ts +14 -12
- package/src/entities/A-Response/A-Response.entity.types.ts +2 -2
- package/src/entities/A-Route/A-Route.entity.ts +4 -4
- package/src/entities/A_EntityList/A_EntityList.entity.ts +2 -3
- package/src/entities/A_EntityList/A_EntityList.entity.types.ts +5 -5
- package/tests/A-HttpChannel.test.ts +204 -0
- package/tests/A-Service.test.ts +1 -3
- package/tsconfig.build.json +1 -0
- package/tsconfig.json +2 -0
- package/dist/src/context/A_ProxyConfig/A_ProxyConfig.types.js.map +0 -1
- package/dist/src/context/Server.context.types.js +0 -2
- package/dist/src/context/Server.context.types.js.map +0 -1
- /package/dist/src/{context/Server.context.types.d.ts → components/A-EntityRepository/A-EntityRepository.error.d.ts} +0 -0
- /package/{src/context/Server.context.types.ts → dist/src/components/A-EntityRepository/A-EntityRepository.types.d.ts} +0 -0
- /package/dist/src/context/{A_ListQueryFilter → A-ListQueryFilter}/A_ListQueryFilter.context.d.ts +0 -0
- /package/dist/src/context/{A_ListQueryFilter → A-ListQueryFilter}/A_ListQueryFilter.context.js +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.constants.d.ts +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.constants.js +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.context.d.ts +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.context.js +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.types.d.ts +0 -0
- /package/dist/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.types.js +0 -0
- /package/src/context/{A_ListQueryFilter → A-ListQueryFilter}/A_ListQueryFilter.context.ts +0 -0
- /package/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.constants.ts +0 -0
- /package/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.context.ts +0 -0
- /package/src/context/{A_ProxyConfig → A-ProxyConfig}/A_ProxyConfig.types.ts +0 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
A_Component,
|
|
3
3
|
A_Concept,
|
|
4
|
-
A_Config,
|
|
5
4
|
A_Context,
|
|
6
5
|
A_Feature,
|
|
7
6
|
A_Feature_Define,
|
|
8
7
|
A_Feature_Extend,
|
|
8
|
+
A_IdentityHelper,
|
|
9
9
|
A_Inject,
|
|
10
|
-
A_Logger,
|
|
11
10
|
A_Meta,
|
|
12
|
-
A_Scope
|
|
11
|
+
A_Scope,
|
|
12
|
+
A_TypeGuards
|
|
13
13
|
} from "@adaas/a-concept";
|
|
14
14
|
import { A_Service } from "@adaas/a-server/containers/A-Service/A-Service.container";
|
|
15
15
|
import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Service/A-Service.container.types";
|
|
@@ -24,7 +24,8 @@ import {
|
|
|
24
24
|
import { A_Route } from "@adaas/a-server/entities/A-Route/A-Route.entity";
|
|
25
25
|
import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entity";
|
|
26
26
|
import { A_ServerLogger } from "../A-ServerLogger/A_ServerLogger.component";
|
|
27
|
-
import { A_TYPES__Required } from "@adaas/a-
|
|
27
|
+
import { A_TYPES__Required } from "@adaas/a-concept/dist/src/types/A_Common.types";
|
|
28
|
+
import { A_Config, A_Logger } from "@adaas/a-utils";
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
|
|
@@ -142,7 +143,7 @@ export class A_Router extends A_Component {
|
|
|
142
143
|
const route = typeof config.path === 'string' || config.path instanceof RegExp
|
|
143
144
|
? new A_Route(
|
|
144
145
|
`/${config.prefix}/${config.version}${config.path instanceof RegExp ? config.path.source : config.path.startsWith('/') ? config.path : `/${config.path}`}`,
|
|
145
|
-
|
|
146
|
+
config.method)
|
|
146
147
|
: config.path;
|
|
147
148
|
|
|
148
149
|
this.routes.push(route);
|
|
@@ -193,9 +194,9 @@ export class A_Router extends A_Component {
|
|
|
193
194
|
// =======================================================
|
|
194
195
|
// ================ Feature Definition=====================
|
|
195
196
|
// =======================================================
|
|
196
|
-
@A_Feature.Define({
|
|
197
|
-
|
|
198
|
-
})
|
|
197
|
+
// @A_Feature.Define({
|
|
198
|
+
// invoke: false
|
|
199
|
+
// })
|
|
199
200
|
@A_Feature.Extend({
|
|
200
201
|
name: A_SERVER_TYPES__ServerFeature.onRequest,
|
|
201
202
|
scope: [A_Service],
|
|
@@ -225,18 +226,21 @@ export class A_Router extends A_Component {
|
|
|
225
226
|
* And it will return all stages that are similar to the feature name
|
|
226
227
|
*/
|
|
227
228
|
|
|
228
|
-
const feature =
|
|
229
|
+
const feature = new A_Feature({
|
|
230
|
+
name: route.toString(),
|
|
231
|
+
component: this,
|
|
232
|
+
})
|
|
229
233
|
|
|
230
|
-
for (const stage of feature) {
|
|
231
234
|
|
|
232
|
-
|
|
235
|
+
for (const stage of feature) {
|
|
236
|
+
if (A_TypeGuards.isComponentConstructor(stage.definition.component)) {
|
|
233
237
|
|
|
234
|
-
const meta: A_Meta<A_TYPES__ARouterComponentMeta> = A_Context.meta<A_TYPES__ARouterComponentMeta>(
|
|
238
|
+
const meta: A_Meta<A_TYPES__ARouterComponentMeta> = A_Context.meta<A_TYPES__ARouterComponentMeta>(stage.definition.component);
|
|
235
239
|
|
|
236
240
|
const routes = meta.get(A_SERVER_TYPES__ARouterComponentMetaKey.ROUTES);
|
|
237
241
|
|
|
238
242
|
if (routes) {
|
|
239
|
-
const currentRoute = routes.get(
|
|
243
|
+
const currentRoute = routes.get(stage.definition.name || '');
|
|
240
244
|
|
|
241
245
|
if (currentRoute) {
|
|
242
246
|
request.params = {
|
|
@@ -248,10 +252,17 @@ export class A_Router extends A_Component {
|
|
|
248
252
|
}
|
|
249
253
|
|
|
250
254
|
const stageScope = new A_Scope({
|
|
251
|
-
name: `a-route
|
|
255
|
+
name: `a-route--${A_IdentityHelper.generateTimeId()}`,
|
|
252
256
|
entities: [request],
|
|
257
|
+
}, {
|
|
258
|
+
parent: scope
|
|
253
259
|
});
|
|
260
|
+
|
|
261
|
+
|
|
254
262
|
await stage.process(stageScope);
|
|
255
263
|
}
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
console.log('Finished processing route for request:', request.method, request.url);
|
|
256
267
|
}
|
|
257
268
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { A_Component,
|
|
1
|
+
import { A_Component, A_Feature, A_Inject } from '@adaas/a-concept';
|
|
2
2
|
import { A_SERVER_TYPES__CorsConfig } from './A_ServerCORS.component.types';
|
|
3
3
|
import { A_SERVER_DEFAULTS__CorsConfig } from './A_ServerCORS.component.defaults';
|
|
4
4
|
import { A_SERVER_TYPES__ServerFeature } from '@adaas/a-server/containers/A-Service/A-Service.container.types';
|
|
5
5
|
import { A_Request } from '@adaas/a-server/entities/A-Request/A-Request.entity';
|
|
6
6
|
import { A_Response } from '@adaas/a-server/entities/A-Response/A-Response.entity';
|
|
7
|
+
import { A_Config } from '@adaas/a-utils';
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
export class A_ServerCORS extends A_Component {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { A_Error } from '@adaas/a-concept';
|
|
2
|
+
import { A_SERVER_TYPES__ServerError_Init, A_SERVER_TYPES__ServerError_Serialized } from './A-ServerError.types';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export class A_ServerError extends A_Error<A_SERVER_TYPES__ServerError_Init, A_SERVER_TYPES__ServerError_Serialized> {
|
|
6
|
+
|
|
7
|
+
status: number = 500;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
// constructor(
|
|
11
|
+
// /**
|
|
12
|
+
// * A_Error Constructor params
|
|
13
|
+
// */
|
|
14
|
+
// params: A_SERVER_TYPES__ServerError_Init
|
|
15
|
+
// )
|
|
16
|
+
// constructor(
|
|
17
|
+
// /**
|
|
18
|
+
// * HTTP Status Code of the error
|
|
19
|
+
// */
|
|
20
|
+
// status: number,
|
|
21
|
+
// /**
|
|
22
|
+
// * Error message
|
|
23
|
+
// */
|
|
24
|
+
// message: string
|
|
25
|
+
// )
|
|
26
|
+
// constructor(
|
|
27
|
+
// /**
|
|
28
|
+
// * Original JS Error
|
|
29
|
+
// */
|
|
30
|
+
// error: Error
|
|
31
|
+
// )
|
|
32
|
+
// constructor(
|
|
33
|
+
// /**
|
|
34
|
+
// * HTTP Status Code of the error
|
|
35
|
+
// */
|
|
36
|
+
// status: number,
|
|
37
|
+
// /**
|
|
38
|
+
// * Error message
|
|
39
|
+
// */
|
|
40
|
+
// title: string,
|
|
41
|
+
// /**
|
|
42
|
+
// * Detailed description of the error
|
|
43
|
+
// */
|
|
44
|
+
// description: string
|
|
45
|
+
// )
|
|
46
|
+
// constructor(
|
|
47
|
+
// param1: A_SERVER_TYPES__ServerError_Init | Error | string | A_Error | number,
|
|
48
|
+
// param2?: string | A_Error,
|
|
49
|
+
// param3?: string
|
|
50
|
+
// ) {
|
|
51
|
+
// switch (true) {
|
|
52
|
+
// case typeof param1 === 'number':
|
|
53
|
+
// if (typeof param2 === 'string' && param3) {
|
|
54
|
+
// super({
|
|
55
|
+
// title: param2,
|
|
56
|
+
// description: param3
|
|
57
|
+
// });
|
|
58
|
+
// }
|
|
59
|
+
// else if (param2 instanceof A_Error) {
|
|
60
|
+
// super(param2);
|
|
61
|
+
// }
|
|
62
|
+
// else {
|
|
63
|
+
// super();
|
|
64
|
+
// }
|
|
65
|
+
// this.status = param1;
|
|
66
|
+
// break;
|
|
67
|
+
|
|
68
|
+
// case param1 instanceof A_Error:
|
|
69
|
+
// super (param1);
|
|
70
|
+
// break;
|
|
71
|
+
// case param1 instanceof Error:
|
|
72
|
+
// super (param1);
|
|
73
|
+
// break;
|
|
74
|
+
|
|
75
|
+
// default:
|
|
76
|
+
// break;
|
|
77
|
+
// }
|
|
78
|
+
|
|
79
|
+
// }
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
protected fromConstructor(params: A_SERVER_TYPES__ServerError_Init): void {
|
|
83
|
+
super.fromConstructor(params);
|
|
84
|
+
if (params.status) {
|
|
85
|
+
this.status = params.status;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
toJSON(): A_SERVER_TYPES__ServerError_Serialized {
|
|
91
|
+
return {
|
|
92
|
+
...super.toJSON(),
|
|
93
|
+
status: this.status
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { A_TYPES__Error_Init, A_TYPES__Error_Serialized } from "@adaas/a-concept"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export type A_SERVER_TYPES__ServerError_Init = {
|
|
6
|
+
/**
|
|
7
|
+
* HTTP Status Code of the error
|
|
8
|
+
*/
|
|
9
|
+
status?: number
|
|
10
|
+
} & A_TYPES__Error_Init
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export type A_SERVER_TYPES__ServerError_Serialized = {
|
|
16
|
+
/**
|
|
17
|
+
* HTTP Status Code of the error
|
|
18
|
+
*/
|
|
19
|
+
status: number
|
|
20
|
+
} & A_TYPES__Error_Serialized
|
|
21
|
+
|
|
22
|
+
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { A_Component,
|
|
1
|
+
import { A_Component, A_Inject } from "@adaas/a-concept";
|
|
2
2
|
import { A_Router } from "../A-Router/A-Router.component";
|
|
3
3
|
import { A_Request } from "@adaas/a-server/entities/A-Request/A-Request.entity";
|
|
4
4
|
import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entity";
|
|
5
|
+
import { A_Config, A_Logger } from "@adaas/a-utils";
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
export class A_ServerHealthMonitor extends A_Component {
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
|
|
12
12
|
// =======================================================
|
|
13
13
|
// ================ Method Definition=====================
|
|
14
14
|
// =======================================================
|
|
15
15
|
|
|
16
16
|
@A_Router.Get({
|
|
17
|
-
path: '/
|
|
17
|
+
path: '/',
|
|
18
|
+
prefix: 'health',
|
|
18
19
|
version: 'v1',
|
|
19
20
|
})
|
|
20
21
|
async get(
|
|
@@ -23,6 +24,8 @@ export class A_ServerHealthMonitor extends A_Component {
|
|
|
23
24
|
@A_Inject(A_Response) response: A_Response,
|
|
24
25
|
@A_Inject(A_Logger) logger: A_Logger
|
|
25
26
|
): Promise<any> {
|
|
27
|
+
logger.log('Health check requested', config.get('A_CONCEPT_ROOT_FOLDER'));
|
|
28
|
+
|
|
26
29
|
const packageJSON = await import(`${config.get('A_CONCEPT_ROOT_FOLDER')}/package.json`);
|
|
27
30
|
const exposedProperties: Array<string> = config.get('EXPOSED_PROPERTIES')?.split(',') || [
|
|
28
31
|
'name',
|
|
@@ -31,5 +34,7 @@ export class A_ServerHealthMonitor extends A_Component {
|
|
|
31
34
|
];
|
|
32
35
|
|
|
33
36
|
exposedProperties.forEach(prop => response.add(prop, packageJSON[prop]));
|
|
37
|
+
|
|
38
|
+
console.log(`Health check accessed: ${request.method} ${request.url}`);
|
|
34
39
|
}
|
|
35
40
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A_Container, A_Feature, A_Inject, } from "@adaas/a-concept";
|
|
2
2
|
import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Service/A-Service.container.types";
|
|
3
3
|
import { A_Server } from "@adaas/a-server/context/A-Server/A_Server.context";
|
|
4
4
|
import { A_SERVER_TYPES__ServerLoggerEnvVariables, A_SERVER_TYPES__ServerLoggerRouteParams } from "./A_ServerLogger.component.types";
|
|
@@ -8,7 +8,7 @@ import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entit
|
|
|
8
8
|
import { A_SERVER_TYPES__ResponseEvent } from "@adaas/a-server/entities/A-Response/A-Response.entity.types";
|
|
9
9
|
import { A_Route } from "@adaas/a-server/entities/A-Route/A-Route.entity";
|
|
10
10
|
import { A_SERVER_TYPES__RequestEvent } from "@adaas/a-server/entities/A-Request/A-Request.entity.types";
|
|
11
|
-
import {
|
|
11
|
+
import { A_Config, A_Logger } from "@adaas/a-utils";
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
export class A_ServerLogger extends A_Logger {
|
|
@@ -16,7 +16,6 @@ export class A_ServerLogger extends A_Logger {
|
|
|
16
16
|
protected config!: A_Config<A_SERVER_TYPES__ServerLoggerEnvVariables>
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
@A_Feature.Extend({
|
|
21
20
|
name: A_SERVER_TYPES__ResponseEvent.Finish,
|
|
22
21
|
scope: [A_Response]
|
|
@@ -44,19 +43,17 @@ export class A_ServerLogger extends A_Logger {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
|
|
47
|
-
@A_Feature.Define({ invoke: false })
|
|
48
46
|
@A_Feature.Extend({
|
|
49
47
|
name: A_SERVER_TYPES__ServerFeature.afterStart,
|
|
50
48
|
scope: [A_Service]
|
|
51
49
|
})
|
|
52
50
|
logStart(
|
|
53
|
-
@A_Inject(
|
|
54
|
-
) {
|
|
51
|
+
@A_Inject(A_Service) container: A_Service,
|
|
52
|
+
): void {
|
|
55
53
|
this.serverReady({
|
|
56
|
-
port:
|
|
54
|
+
port: container.port,
|
|
57
55
|
app: {
|
|
58
|
-
name:
|
|
59
|
-
version: server.version
|
|
56
|
+
name: container.name,
|
|
60
57
|
}
|
|
61
58
|
})
|
|
62
59
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A_TYPES__ConceptENVVariables } from "@adaas/a-concept/dist/src/constants/env.constants"
|
|
2
|
-
|
|
2
|
+
import { A_SERVER__A_SERVER_LOGGER_ENV_VARIABLES } from "./A-ServerLogger.constants";
|
|
3
3
|
|
|
4
4
|
export type A_SERVER_TYPES__ServerLoggerRouteParams = {
|
|
5
5
|
method: string,
|
|
@@ -10,12 +10,5 @@ export type A_SERVER_TYPES__ServerLoggerRouteParams = {
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
export type A_SERVER_TYPES__ServerLoggerEnvVariables = Array<
|
|
13
|
-
|
|
14
|
-
'SERVER_IGNORE_LOG_200'
|
|
15
|
-
| 'SERVER_IGNORE_LOG_404'
|
|
16
|
-
| 'SERVER_IGNORE_LOG_500'
|
|
17
|
-
| 'SERVER_IGNORE_LOG_400'
|
|
18
|
-
| 'SERVER_IGNORE_LOG_DEFAULT'
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
keyof typeof A_SERVER__A_SERVER_LOGGER_ENV_VARIABLES
|
|
21
14
|
> | A_TYPES__ConceptENVVariables
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { A_Component, A_Concept, A_Feature, A_Inject
|
|
1
|
+
import { A_Component, A_Concept, A_Feature, A_Inject } from "@adaas/a-concept";
|
|
2
2
|
import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Service/A-Service.container.types";
|
|
3
|
-
import { A_ProxyConfig } from "@adaas/a-server/context/
|
|
3
|
+
import { A_ProxyConfig } from "@adaas/a-server/context/A-ProxyConfig/A_ProxyConfig.context";
|
|
4
4
|
import { A_Request } from "@adaas/a-server/entities/A-Request/A-Request.entity";
|
|
5
5
|
import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entity";
|
|
6
6
|
import { A_Route } from "@adaas/a-server/entities/A-Route/A-Route.entity";
|
|
7
|
+
import { A_Logger } from "@adaas/a-utils";
|
|
7
8
|
import http from "http";
|
|
8
9
|
import https from "https";
|
|
9
10
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A_Component, A_Concept, A_Feature, A_Inject
|
|
1
|
+
import { A_Component, A_Concept, A_Feature, A_Inject } from "@adaas/a-concept"
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { URL } from "url";
|
|
@@ -7,6 +7,7 @@ import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entit
|
|
|
7
7
|
import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Service/A-Service.container.types";
|
|
8
8
|
import { A_Route } from "@adaas/a-server/entities/A-Route/A-Route.entity";
|
|
9
9
|
import { A_StaticConfig } from "@adaas/a-server/context/A-StaticConfig/A-StaticConfig.context";
|
|
10
|
+
import { A_Logger } from "@adaas/a-utils";
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
export class A_StaticLoader extends A_Component {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { A_Component, A_Feature, A_Inject
|
|
2
|
-
import http, { IncomingMessage, ServerResponse } from "http";
|
|
1
|
+
import { A_Component, A_Feature, A_Inject } from "@adaas/a-concept"
|
|
3
2
|
import fs from "fs";
|
|
4
3
|
import path from "path";
|
|
5
4
|
import { URL } from "url";
|
|
6
5
|
import { A_Request } from "@adaas/a-server/entities/A-Request/A-Request.entity";
|
|
7
6
|
import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entity";
|
|
8
7
|
import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Service/A-Service.container.types";
|
|
9
|
-
import {
|
|
8
|
+
import { A_Logger } from "@adaas/a-utils";
|
|
10
9
|
|
|
11
10
|
|
|
12
11
|
export class A_StaticLoader extends A_Component {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { A_Concept, A_Config, A_Container, A_Context, A_Errors, A_Feature, A_Inject, A_Logger, A_Scope, A_TYPES__ComponentMetaKey, } from "@adaas/a-concept";
|
|
2
1
|
import { createServer, IncomingMessage, Server, ServerResponse } from "http";
|
|
3
2
|
import { A_SERVER_TYPES__ServerFeature, A_SERVER_TYPES__ServerFeatures } from "./A-Service.container.types";
|
|
4
3
|
import { A_Server } from "@adaas/a-server/context/A-Server/A_Server.context";
|
|
@@ -6,6 +5,8 @@ import { A_Request } from "@adaas/a-server/entities/A-Request/A-Request.entity";
|
|
|
6
5
|
import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entity";
|
|
7
6
|
import crypto from 'crypto';
|
|
8
7
|
import { A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_TYPES__ServerENVVariables } from "@adaas/a-server/constants/env.constants";
|
|
8
|
+
import { A_Concept, A_Container, A_Feature, A_IdentityHelper, A_Scope } from "@adaas/a-concept";
|
|
9
|
+
import { A_Config, A_Logger } from "@adaas/a-utils";
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
|
|
@@ -18,20 +19,15 @@ import { A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_TYPES__ServerENVVari
|
|
|
18
19
|
export class A_Service extends A_Container {
|
|
19
20
|
|
|
20
21
|
private server!: Server;
|
|
21
|
-
|
|
22
|
+
port!: number;
|
|
22
23
|
|
|
23
24
|
@A_Concept.Load()
|
|
24
25
|
async load() {
|
|
25
|
-
if (!this.Scope.has(A_Errors)) {
|
|
26
|
-
const errorsRegistry = new A_Errors({});
|
|
27
|
-
|
|
28
|
-
this.Scope.register(errorsRegistry);
|
|
29
|
-
}
|
|
30
26
|
|
|
31
27
|
let config: A_Config<A_TYPES__ServerENVVariables>;
|
|
32
28
|
let aServer: A_Server;
|
|
33
29
|
|
|
34
|
-
if (!this.
|
|
30
|
+
if (!this.scope.has(A_Config<A_TYPES__ServerENVVariables>)) {
|
|
35
31
|
const config = new A_Config<A_TYPES__ServerENVVariables>({
|
|
36
32
|
variables: [...Array.from(A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY)],
|
|
37
33
|
defaults: {
|
|
@@ -39,13 +35,13 @@ export class A_Service extends A_Container {
|
|
|
39
35
|
}
|
|
40
36
|
});
|
|
41
37
|
|
|
42
|
-
this.
|
|
38
|
+
this.scope.register(config);
|
|
43
39
|
}
|
|
44
40
|
|
|
45
|
-
config = this.
|
|
41
|
+
config = this.scope.resolve(A_Config) as A_Config<A_TYPES__ServerENVVariables>;
|
|
46
42
|
|
|
47
43
|
|
|
48
|
-
if (!this.
|
|
44
|
+
if (!this.scope.has(A_Server)) {
|
|
49
45
|
aServer = new A_Server({
|
|
50
46
|
port: config.get('A_SERVER_PORT'),
|
|
51
47
|
name: this.name,
|
|
@@ -53,21 +49,12 @@ export class A_Service extends A_Container {
|
|
|
53
49
|
});
|
|
54
50
|
}
|
|
55
51
|
|
|
56
|
-
|
|
57
|
-
|
|
58
52
|
// Set the server to listen on port 3000
|
|
59
|
-
|
|
53
|
+
this.port = config.get('A_SERVER_PORT');
|
|
60
54
|
|
|
61
55
|
// Create the HTTP server
|
|
62
56
|
this.server = createServer(this.onRequest.bind(this));
|
|
63
57
|
|
|
64
|
-
const newServer = new A_Server({
|
|
65
|
-
port,
|
|
66
|
-
name: this.name,
|
|
67
|
-
version: 'v1'
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
this.Scope.register(newServer);
|
|
71
58
|
}
|
|
72
59
|
|
|
73
60
|
protected listen(): Promise<void> {
|
|
@@ -120,35 +107,50 @@ export class A_Service extends A_Container {
|
|
|
120
107
|
await this.call(A_SERVER_TYPES__ServerFeature.afterStop)
|
|
121
108
|
}
|
|
122
109
|
|
|
110
|
+
@A_Feature.Define({
|
|
111
|
+
name: A_SERVER_TYPES__ServerFeature.beforeRequest,
|
|
112
|
+
invoke: true
|
|
113
|
+
})
|
|
114
|
+
async beforeRequest(scope: A_Scope) { }
|
|
123
115
|
|
|
116
|
+
@A_Feature.Define({
|
|
117
|
+
name: A_SERVER_TYPES__ServerFeature.beforeRequest,
|
|
118
|
+
invoke: true
|
|
119
|
+
})
|
|
120
|
+
async afterRequest(scope: A_Scope) { }
|
|
124
121
|
|
|
125
122
|
@A_Feature.Define({
|
|
126
123
|
name: A_SERVER_TYPES__ServerFeature.onRequest,
|
|
127
124
|
invoke: false
|
|
128
125
|
})
|
|
129
|
-
/**
|
|
130
|
-
* Handle incoming requests
|
|
131
|
-
*/
|
|
132
126
|
async onRequest(
|
|
133
127
|
request: IncomingMessage,
|
|
134
128
|
response: ServerResponse
|
|
135
129
|
) {
|
|
130
|
+
const scope = new A_Scope({
|
|
131
|
+
name: `a-server-request::${Date.now()}`,
|
|
132
|
+
});
|
|
133
|
+
|
|
136
134
|
// We need it to stop feature execution in case request ends
|
|
137
135
|
const { req, res } = await this.convertToAServer(request, response);
|
|
138
136
|
|
|
139
137
|
try {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
entities: [req, res],
|
|
143
|
-
});
|
|
138
|
+
scope.register(req);
|
|
139
|
+
scope.register(res);
|
|
144
140
|
|
|
145
|
-
|
|
141
|
+
scope.inherit(this.scope);
|
|
142
|
+
|
|
143
|
+
await this.beforeRequest(scope);
|
|
146
144
|
await this.call(A_SERVER_TYPES__ServerFeature.onRequest, scope);
|
|
147
|
-
await this.
|
|
145
|
+
await this.afterRequest(scope);
|
|
148
146
|
|
|
149
147
|
await res.status(200).send();
|
|
150
148
|
|
|
151
149
|
} catch (error) {
|
|
150
|
+
|
|
151
|
+
const logger = this.scope.resolve(A_Logger);
|
|
152
|
+
|
|
153
|
+
logger.error(error);
|
|
152
154
|
|
|
153
155
|
return res.failed(error);
|
|
154
156
|
}
|
|
@@ -166,8 +168,8 @@ export class A_Service extends A_Container {
|
|
|
166
168
|
|
|
167
169
|
const id = this.generateRequestId(request.method, request.url);
|
|
168
170
|
|
|
169
|
-
const req = new A_Request({ id, request, scope: this.
|
|
170
|
-
const res = new A_Response({ id, response, scope: this.
|
|
171
|
+
const req = new A_Request({ id, request, scope: this.scope.name });
|
|
172
|
+
const res = new A_Response({ id, response, scope: this.scope.name });
|
|
171
173
|
|
|
172
174
|
await req.init();
|
|
173
175
|
await res.init();
|
|
@@ -181,11 +183,11 @@ export class A_Service extends A_Container {
|
|
|
181
183
|
): string {
|
|
182
184
|
// Use the current time, request URL, and a few other details to create a unique ID
|
|
183
185
|
const hash = crypto.createHash('sha256');
|
|
184
|
-
const
|
|
186
|
+
const timeId = A_IdentityHelper.generateTimeId();
|
|
185
187
|
const randomValue = Math.random().toString(); // Adds extra randomness
|
|
186
188
|
|
|
187
|
-
hash.update(`${
|
|
188
|
-
return hash.digest('hex')
|
|
189
|
+
hash.update(`${timeId}-${method}-${url}-${randomValue}`);
|
|
190
|
+
return `${timeId}-${hash.digest('hex')}`;
|
|
189
191
|
}
|
|
190
192
|
|
|
191
193
|
@A_Feature.Define({ invoke: true })
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { A_Entity, A_Fragment } from "@adaas/a-concept"
|
|
1
|
+
import { A_Entity, A_Fragment, ASEID } from "@adaas/a-concept"
|
|
2
2
|
import { A_SERVER_TYPES__AEntityFactoryConstructor1, A_SERVER_TYPES__AEntityFactoryConstructor2 } from "./A-EntityFactory.context.types";
|
|
3
|
-
import { ASEID } from "@adaas/a-utils";
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
export class A_EntityFactory extends A_Fragment {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { A_Fragment } from "@adaas/a-concept";
|
|
2
|
+
import { A_SERVER_TYPES__ServerMethod } from "@adaas/a-server/containers/A-Service/A-Service.container.types";
|
|
3
|
+
import { A_SERVER_TYPES__HttpChannelRequestParams } from "@adaas/a-server/channels/A-Http/A-Http.channel.types";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class A_HTTPChannel_RequestContext<
|
|
10
|
+
T extends any = any
|
|
11
|
+
> extends A_Fragment {
|
|
12
|
+
url: string;
|
|
13
|
+
method: A_SERVER_TYPES__ServerMethod;
|
|
14
|
+
data?: any;
|
|
15
|
+
config?: Partial<A_SERVER_TYPES__HttpChannelRequestParams['config']>;
|
|
16
|
+
|
|
17
|
+
constructor(params: A_SERVER_TYPES__HttpChannelRequestParams) {
|
|
18
|
+
super();
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
method,
|
|
22
|
+
url,
|
|
23
|
+
data,
|
|
24
|
+
config,
|
|
25
|
+
} = params;
|
|
26
|
+
|
|
27
|
+
this.url = url;
|
|
28
|
+
this.method = method;
|
|
29
|
+
this.data = data;
|
|
30
|
+
this.config = config;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
result?: T;
|
|
34
|
+
error?: any;
|
|
35
|
+
|
|
36
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createServer, Server } from "http";
|
|
1
|
+
import { A_Fragment } from "@adaas/a-concept";
|
|
3
2
|
import { A_SERVER_TYPES__ServerConstructor } from "./A_Server.context.types";
|
|
4
|
-
import { A_TYPES__Required } from "@adaas/a-utils";
|
|
5
3
|
import { A_Route } from "@adaas/a-server/entities/A-Route/A-Route.entity";
|
|
4
|
+
import { A_TYPES__Required } from "@adaas/a-concept/dist/src/types/A_Common.types";
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
export class A_Server extends A_Fragment {
|