@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,7 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { A_Context, A_Entity, A_TYPES__Entity_JSON, A_TYPES__EntityBaseMethods } from '@adaas/a-concept';
|
|
4
|
-
import { A_Error, A_ServerError, ASEID } from "@adaas/a-utils";
|
|
1
|
+
import { IncomingHttpHeaders, IncomingMessage } from "http";
|
|
2
|
+
import { A_Context, A_Entity, A_IdentityHelper, ASEID, } from '@adaas/a-concept';
|
|
5
3
|
import {
|
|
6
4
|
A_SERVER_TYPES__RequestConstructor,
|
|
7
5
|
A_SERVER_TYPES__RequestEvent,
|
|
@@ -9,6 +7,7 @@ import {
|
|
|
9
7
|
A_SERVER_TYPES__RequestSerialized
|
|
10
8
|
} from "./A-Request.entity.types";
|
|
11
9
|
import { A_Route } from '../A-Route/A-Route.entity';
|
|
10
|
+
import { A_ServerError } from "@adaas/a-server/components/A-ServerError/A-ServerError.class";
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
export class A_Request<
|
|
@@ -21,6 +20,11 @@ export class A_Request<
|
|
|
21
20
|
A_SERVER_TYPES__RequestConstructor,
|
|
22
21
|
A_SERVER_TYPES__RequestSerialized
|
|
23
22
|
> {
|
|
23
|
+
|
|
24
|
+
static get namespace(): string {
|
|
25
|
+
return 'a-server';
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
req!: IncomingMessage;
|
|
25
29
|
|
|
26
30
|
body: _ReqBodyType = {} as _ReqBodyType;
|
|
@@ -39,26 +43,21 @@ export class A_Request<
|
|
|
39
43
|
this.req = newEntity.request;
|
|
40
44
|
|
|
41
45
|
this.aseid = new ASEID({
|
|
42
|
-
|
|
43
|
-
scope: newEntity.scope
|
|
44
|
-
entity:
|
|
46
|
+
concept: A_Context.root.name,
|
|
47
|
+
scope: newEntity.scope,
|
|
48
|
+
entity: (this.constructor as typeof A_Request).entity,
|
|
45
49
|
id: newEntity.id
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
52
|
|
|
53
|
+
get startedAt(): Date | undefined {
|
|
54
|
+
const timeId = A_IdentityHelper.parseTimeId(this.aseid.id.split('-')[0]);
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
// Use the current time, request URL, and a few other details to create a unique ID
|
|
52
|
-
const hash = crypto.createHash('sha256');
|
|
53
|
-
const time = Date.now();
|
|
54
|
-
const method = this.method;
|
|
55
|
-
const url = this.url;
|
|
56
|
-
const randomValue = Math.random().toString(); // Adds extra randomness
|
|
57
|
-
|
|
58
|
-
hash.update(`${time}-${method}-${url}-${randomValue}`);
|
|
59
|
-
return hash.digest('hex');
|
|
56
|
+
return timeId ? new Date(timeId.timestamp) : undefined;
|
|
60
57
|
}
|
|
61
58
|
|
|
59
|
+
|
|
60
|
+
|
|
62
61
|
// Getter for request URL
|
|
63
62
|
public get url(): string {
|
|
64
63
|
return this.req.url!;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IncomingMessage
|
|
1
|
+
import { IncomingMessage } from "http";
|
|
2
2
|
import { A_Request } from "./A-Request.entity";
|
|
3
|
-
import {
|
|
3
|
+
import { A_TYPES__Entity_Serialized } from "@adaas/a-concept";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export type A_SERVER_TYPES__RequestConstructor = {
|
|
@@ -13,7 +13,7 @@ export type A_SERVER_TYPES__RequestConstructor = {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export type A_SERVER_TYPES__RequestSerialized = {
|
|
16
|
-
} &
|
|
16
|
+
} & A_TYPES__Entity_Serialized;
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
A_Context,
|
|
3
3
|
A_Entity,
|
|
4
|
-
|
|
4
|
+
A_Error,
|
|
5
5
|
A_Scope,
|
|
6
|
+
ASEID,
|
|
6
7
|
} from "@adaas/a-concept";
|
|
7
8
|
import {
|
|
8
9
|
IncomingHttpHeaders,
|
|
@@ -14,11 +15,9 @@ import {
|
|
|
14
15
|
A_SERVER_TYPES__ResponseSerialized,
|
|
15
16
|
A_SERVER_TYPES__SendResponseObject
|
|
16
17
|
} from "./A-Response.entity.types";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
ASEID
|
|
21
|
-
} from "@adaas/a-utils";
|
|
18
|
+
import { A_ServerError } from "@adaas/a-server/components/A-ServerError/A-ServerError.class";
|
|
19
|
+
import { A_Logger } from "@adaas/a-utils";
|
|
20
|
+
|
|
22
21
|
|
|
23
22
|
|
|
24
23
|
|
|
@@ -28,6 +27,9 @@ export class A_Response<
|
|
|
28
27
|
A_SERVER_TYPES__ResponseConstructor,
|
|
29
28
|
A_SERVER_TYPES__ResponseSerialized
|
|
30
29
|
> {
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
31
33
|
/**
|
|
32
34
|
* Duration of the request in milliseconds
|
|
33
35
|
*/
|
|
@@ -42,9 +44,9 @@ export class A_Response<
|
|
|
42
44
|
this.res = newEntity.response;
|
|
43
45
|
|
|
44
46
|
this.aseid = new ASEID({
|
|
45
|
-
|
|
46
|
-
scope: newEntity.scope
|
|
47
|
-
entity:
|
|
47
|
+
concept: A_Context.root.name,
|
|
48
|
+
scope: newEntity.scope,
|
|
49
|
+
entity: (this.constructor as typeof A_Response).entity,
|
|
48
50
|
id: newEntity.id
|
|
49
51
|
});
|
|
50
52
|
}
|
|
@@ -61,7 +63,7 @@ export class A_Response<
|
|
|
61
63
|
return this.res.statusCode;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
|
|
66
|
+
async init(): Promise<void> {
|
|
65
67
|
const startTime = process.hrtime();
|
|
66
68
|
|
|
67
69
|
this.res.on('finish', async () => {
|
|
@@ -80,7 +82,7 @@ export class A_Response<
|
|
|
80
82
|
|
|
81
83
|
|
|
82
84
|
|
|
83
|
-
public failed(error: A_ServerError | A_Error | Error |
|
|
85
|
+
public failed(error: A_ServerError | A_Error | Error | any): void {
|
|
84
86
|
switch (true) {
|
|
85
87
|
case error instanceof A_ServerError:
|
|
86
88
|
this.error = error;
|
|
@@ -98,7 +100,7 @@ export class A_Response<
|
|
|
98
100
|
break;
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
return this.status(this.error.
|
|
103
|
+
return this.status(this.error.status).json(this.error);
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
// Send a plain text or JSON response
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A_TYPES__Entity_Serialized } from "@adaas/a-concept";
|
|
2
2
|
import { ServerResponse } from "http";
|
|
3
3
|
|
|
4
4
|
|
|
@@ -19,7 +19,7 @@ export enum A_SERVER_TYPES__ResponseEvent {
|
|
|
19
19
|
Close = 'close',
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export type A_SERVER_TYPES__ResponseSerialized =
|
|
22
|
+
export type A_SERVER_TYPES__ResponseSerialized = A_TYPES__Entity_Serialized;
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
export type A_SERVER_TYPES__SendResponseObject<_ResponseType = any> =
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
import { A_Context, A_Entity } from "@adaas/a-concept";
|
|
3
|
-
import { ASEID } from "@adaas/a-utils";
|
|
4
1
|
import { A_SERVER_TYPES__RequestMethods } from '../A-Request/A-Request.entity.types';
|
|
5
2
|
|
|
6
3
|
|
|
@@ -33,7 +30,10 @@ export class A_Route {
|
|
|
33
30
|
* returns path only without query and hash
|
|
34
31
|
*/
|
|
35
32
|
get path(): string {
|
|
36
|
-
|
|
33
|
+
const p = this.url.split('?')[0].split('#')[0];
|
|
34
|
+
|
|
35
|
+
// ensure that last char is not /
|
|
36
|
+
return p.endsWith('/') ? p.slice(0, -1) : p;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
A_Context, A_Entity,
|
|
3
|
-
|
|
3
|
+
ASEID,
|
|
4
4
|
} from "@adaas/a-concept";
|
|
5
5
|
import {
|
|
6
6
|
A_SERVER_TYPES__A_EntityListConstructor,
|
|
7
7
|
A_SERVER_TYPES__A_EntityListPagination,
|
|
8
8
|
A_SERVER_TYPES__A_EntityListSerialized
|
|
9
9
|
} from "./A_EntityList.entity.types";
|
|
10
|
-
import { ASEID } from "@adaas/a-utils";
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
|
|
@@ -67,7 +66,7 @@ export class A_EntityList<
|
|
|
67
66
|
*/
|
|
68
67
|
fromNew(newEntity: A_SERVER_TYPES__A_EntityListConstructor): void {
|
|
69
68
|
this.aseid = new ASEID({
|
|
70
|
-
|
|
69
|
+
concept: A_Context.root.name,
|
|
71
70
|
scope: 'default',
|
|
72
71
|
entity: 'a-list' + (newEntity.name ? `.${newEntity.name}` : ''),
|
|
73
72
|
id: (new Date()).getTime().toString(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A_Entity,
|
|
1
|
+
import { A_Entity, A_TYPES__Entity_Serialized } from "@adaas/a-concept";
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
export type A_SERVER_TYPES__A_EntityListConstructor = {
|
|
@@ -15,13 +15,13 @@ export type A_SERVER_TYPES__A_EntityListSerialized<EntityTypes extends A_Entity
|
|
|
15
15
|
items: Array<ReturnType<EntityTypes['toJSON']>>,
|
|
16
16
|
type: string,
|
|
17
17
|
pagination: A_SERVER_TYPES__A_EntityListPagination
|
|
18
|
-
} &
|
|
18
|
+
} & A_TYPES__Entity_Serialized;
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
export type A_SERVER_TYPES__A_EntityListPagination = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
total: number,
|
|
24
|
+
page: number,
|
|
25
|
+
pageSize: number,
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { A_Context, A_Feature, A_Inject, A_Scope } from '@adaas/a-concept';
|
|
2
|
+
import { A_HTTPChannel } from '@adaas/a-server/channels/A-Http/A-Http.channel';
|
|
3
|
+
import { A_SERVER_CONSTANTS__A_HttpChannel_Lifecycle } from '@adaas/a-server/channels/A-Http/A-Http.channel.constants';
|
|
4
|
+
import { A_HTTPChannel_RequestContext } from '@adaas/a-server/context/A-HttpChannel/A-HttpChannel.context';
|
|
5
|
+
|
|
6
|
+
jest.retryTimes(0);
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
type MockResponse = Array<{ userId: number; id: number; title: string; body: string; customField: string }>
|
|
10
|
+
|
|
11
|
+
describe('A-HttpChannel Tests', () => {
|
|
12
|
+
it('Should be possible to create a new HttpChannel', async () => {
|
|
13
|
+
const scope = new A_Scope({
|
|
14
|
+
components: [A_HTTPChannel]
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const channel = scope.resolve(A_HTTPChannel);
|
|
19
|
+
|
|
20
|
+
expect(channel).toBeInstanceOf(A_HTTPChannel);
|
|
21
|
+
expect(channel.processing).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
it('Should be possible to create a custom Channel', async () => {
|
|
24
|
+
class myChannel extends A_HTTPChannel {
|
|
25
|
+
custom = true;
|
|
26
|
+
|
|
27
|
+
constructor() {
|
|
28
|
+
super();
|
|
29
|
+
this.baseUrl = "https://jsonplaceholder.typicode.com";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const scope = new A_Scope({
|
|
34
|
+
components: [myChannel]
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const channel = scope.resolve(myChannel);
|
|
38
|
+
expect(channel).toBeInstanceOf(myChannel);
|
|
39
|
+
expect(channel.custom).toBe(true);
|
|
40
|
+
expect(channel.processing).toBe(false);
|
|
41
|
+
|
|
42
|
+
const response = await channel.get<MockResponse>(
|
|
43
|
+
'/posts',
|
|
44
|
+
{ userId: 1 }
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(Array.isArray(response.result)).toBe(true);
|
|
48
|
+
expect(response.result?.length).toBeGreaterThan(0);
|
|
49
|
+
expect(response.result?.[0].userId).toBe(1);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('Should throw an error if baseUrl is not set', async () => {
|
|
53
|
+
const scope = new A_Scope({
|
|
54
|
+
components: [A_HTTPChannel]
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const channel = scope.resolve(A_HTTPChannel);
|
|
58
|
+
|
|
59
|
+
await expect(channel.get('/posts')).rejects.toThrow("Base URL is not set for HTTP Channel");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('Should allow to extend response handler behavior', async () => {
|
|
63
|
+
class myChannel extends A_HTTPChannel {
|
|
64
|
+
custom = true;
|
|
65
|
+
constructor() {
|
|
66
|
+
super();
|
|
67
|
+
this.baseUrl = "https://jsonplaceholder.typicode.com";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class myChannelWithCustomResponseHandler extends myChannel {
|
|
72
|
+
|
|
73
|
+
@A_Feature.Extend({
|
|
74
|
+
name: A_SERVER_CONSTANTS__A_HttpChannel_Lifecycle.onAfterRequest
|
|
75
|
+
})
|
|
76
|
+
protected async handleResponse<T>(
|
|
77
|
+
@A_Inject(A_HTTPChannel_RequestContext) context: A_HTTPChannel_RequestContext<MockResponse>
|
|
78
|
+
): Promise<void> {
|
|
79
|
+
context.result = context.result?.map(item => ({
|
|
80
|
+
...item,
|
|
81
|
+
customField: 'customValue'
|
|
82
|
+
})) || [];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const scope = new A_Scope({
|
|
87
|
+
components: [myChannel, myChannelWithCustomResponseHandler]
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const channel = scope.resolve(myChannelWithCustomResponseHandler);
|
|
91
|
+
expect(channel).toBeInstanceOf(myChannelWithCustomResponseHandler);
|
|
92
|
+
expect(channel.custom).toBe(true);
|
|
93
|
+
expect(channel.processing).toBe(false);
|
|
94
|
+
|
|
95
|
+
const response = await channel.get<MockResponse>('/posts', { userId: 1 });
|
|
96
|
+
|
|
97
|
+
expect(Array.isArray(response.result)).toBe(true);
|
|
98
|
+
expect(response.result?.length).toBeGreaterThan(0);
|
|
99
|
+
expect(response.result?.[0].userId).toBe(1);
|
|
100
|
+
expect((response.result?.[0] as any).customField).toBe('customValue');
|
|
101
|
+
});
|
|
102
|
+
it('Should allow to extend error handler behavior', async () => {
|
|
103
|
+
class myChannel extends A_HTTPChannel {
|
|
104
|
+
custom = true;
|
|
105
|
+
constructor() {
|
|
106
|
+
super();
|
|
107
|
+
this.baseUrl = "https://jsonplaceholder.typicode.com";
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
class myChannelWithCustomErrorHandler extends myChannel {
|
|
112
|
+
@A_Feature.Extend({
|
|
113
|
+
name: A_SERVER_CONSTANTS__A_HttpChannel_Lifecycle.onError
|
|
114
|
+
})
|
|
115
|
+
protected async handleError(
|
|
116
|
+
@A_Inject(A_HTTPChannel_RequestContext) context: A_HTTPChannel_RequestContext<MockResponse>,
|
|
117
|
+
error: any
|
|
118
|
+
): Promise<void> {
|
|
119
|
+
context.result = [{
|
|
120
|
+
userId: -1,
|
|
121
|
+
id: -1,
|
|
122
|
+
title: 'error',
|
|
123
|
+
body: 'error',
|
|
124
|
+
customField: 'customValue'
|
|
125
|
+
}];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const scope = new A_Scope({
|
|
130
|
+
components: [myChannel, myChannelWithCustomErrorHandler]
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const channel = scope.resolve(myChannelWithCustomErrorHandler);
|
|
134
|
+
expect(channel).toBeInstanceOf(myChannelWithCustomErrorHandler);
|
|
135
|
+
expect(channel.custom).toBe(true);
|
|
136
|
+
expect(channel.processing).toBe(false);
|
|
137
|
+
|
|
138
|
+
const response = await channel.get<MockResponse>('/posts_invalid', { userId: 1 }, { throwOnError: false });
|
|
139
|
+
|
|
140
|
+
expect(Array.isArray(response.result)).toBe(true);
|
|
141
|
+
expect(response.result?.length).toBe(1);
|
|
142
|
+
expect(response.result?.[0].userId).toBe(-1);
|
|
143
|
+
expect((response.result?.[0] as any).customField).toBe('customValue');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('Should do a proper filtering with query params', async () => {
|
|
147
|
+
class myChannel extends A_HTTPChannel {
|
|
148
|
+
custom = true;
|
|
149
|
+
constructor() {
|
|
150
|
+
super();
|
|
151
|
+
this.baseUrl = "https://jsonplaceholder.typicode.com";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const scope = new A_Scope({
|
|
156
|
+
components: [myChannel]
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const channel = scope.resolve(myChannel);
|
|
160
|
+
expect(channel).toBeInstanceOf(myChannel);
|
|
161
|
+
expect(channel.custom).toBe(true);
|
|
162
|
+
expect(channel.processing).toBe(false);
|
|
163
|
+
|
|
164
|
+
const response = await channel.get<MockResponse>('/posts', { userId: 1 });
|
|
165
|
+
|
|
166
|
+
expect(Array.isArray(response.result)).toBe(true);
|
|
167
|
+
expect(response.result?.length).toBeGreaterThan(0);
|
|
168
|
+
expect(response.result?.every(item => item.userId === 1)).toBe(true);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('Should be possible to do a POST request', async () => {
|
|
172
|
+
class myChannel extends A_HTTPChannel {
|
|
173
|
+
custom = true;
|
|
174
|
+
constructor() {
|
|
175
|
+
super();
|
|
176
|
+
this.baseUrl = "https://jsonplaceholder.typicode.com";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const scope = new A_Scope({
|
|
181
|
+
components: [myChannel]
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const channel = scope.resolve(myChannel);
|
|
185
|
+
expect(channel).toBeInstanceOf(myChannel);
|
|
186
|
+
expect(channel.custom).toBe(true);
|
|
187
|
+
expect(channel.processing).toBe(false);
|
|
188
|
+
|
|
189
|
+
const response = await channel.post<MockResponse>(
|
|
190
|
+
'/posts',
|
|
191
|
+
{
|
|
192
|
+
title: 'foo',
|
|
193
|
+
body: 'bar',
|
|
194
|
+
userId: 1,
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
expect(response.result).toBeDefined();
|
|
199
|
+
expect((response.result as any).id).toBeDefined();
|
|
200
|
+
expect((response.result as any).title).toBe('foo');
|
|
201
|
+
expect((response.result as any).body).toBe('bar');
|
|
202
|
+
expect((response.result as any).userId).toBe(1);
|
|
203
|
+
});
|
|
204
|
+
});
|
package/tests/A-Service.test.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { A_Service } from '@adaas/a-server/containers/A-Service/A-Service.container';
|
|
2
|
-
import { A_Server } from '@adaas/a-server/context/A-Server/A_Server.context';
|
|
3
2
|
|
|
4
3
|
jest.retryTimes(0);
|
|
5
4
|
|
|
@@ -13,8 +12,7 @@ describe('A-Server Tests', () => {
|
|
|
13
12
|
await server1.load();
|
|
14
13
|
|
|
15
14
|
expect(server1.name).toBe('test-server-1');
|
|
16
|
-
expect(server1.
|
|
17
|
-
expect(server1.Scope.resolve(A_Server).port).toBe(3000);
|
|
15
|
+
expect(server1.port).toBe(3000);
|
|
18
16
|
});
|
|
19
17
|
|
|
20
18
|
});
|
package/tsconfig.build.json
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@adaas/a-server/helpers/*": ["src/helpers/*"],
|
|
37
37
|
"@adaas/a-server/examples/*": ["src/examples/*"],
|
|
38
38
|
"@adaas/a-server/entities/*": ["src/entities/*"],
|
|
39
|
+
"@adaas/a-server/channels/*": ["src/channels/*"],
|
|
39
40
|
|
|
40
41
|
"@adaas/a-server/context/*": ["src/context/*"],
|
|
41
42
|
"@adaas/a-server/components/*": ["src/components/*"],
|
package/tsconfig.json
CHANGED
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
"@adaas/a-server/helpers/*": ["src/helpers/*"],
|
|
37
37
|
"@adaas/a-server/examples/*": ["src/examples/*"],
|
|
38
38
|
"@adaas/a-server/entities/*": ["src/entities/*"],
|
|
39
|
+
"@adaas/a-server/channels/*": ["src/channels/*"],
|
|
40
|
+
|
|
39
41
|
|
|
40
42
|
"@adaas/a-server/context/*": ["src/context/*"],
|
|
41
43
|
"@adaas/a-server/components/*": ["src/components/*"],
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"A_ProxyConfig.types.js","sourceRoot":"","sources":["../../../../src/context/A_ProxyConfig/A_ProxyConfig.types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Server.context.types.js","sourceRoot":"","sources":["../../../src/context/Server.context.types.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
File without changes
|
/package/dist/src/context/{A_ListQueryFilter → A-ListQueryFilter}/A_ListQueryFilter.context.d.ts
RENAMED
|
File without changes
|
/package/dist/src/context/{A_ListQueryFilter → A-ListQueryFilter}/A_ListQueryFilter.context.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|