@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
package/index.ts
CHANGED
|
@@ -1,22 +1,51 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
//
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// ADAAS A-Server SDK - Complete Export Manifest
|
|
5
|
+
// ============================================================================
|
|
6
|
+
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Channels Export
|
|
9
|
+
// ============================================================================
|
|
10
|
+
export { A_HTTPChannel } from './src/channels/A-Http/A-Http.channel';
|
|
11
|
+
export { A_HTTPChannelError } from './src/channels/A-Http/A-Http.channel.error';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Constants Export
|
|
16
|
+
// ============================================================================
|
|
17
|
+
export * from './src/constants/env.constants';
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
// ============================================================================
|
|
21
|
+
// Containers Export
|
|
22
|
+
// ============================================================================
|
|
5
23
|
export { A_Service } from './src/containers/A-Service/A-Service.container';
|
|
6
24
|
|
|
7
|
-
|
|
25
|
+
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// Contexts Export
|
|
28
|
+
// ============================================================================
|
|
8
29
|
export { A_Server } from './src/context/A-Server/A_Server.context';
|
|
9
|
-
export { A_ProxyConfig } from './src/context/
|
|
30
|
+
export { A_ProxyConfig } from './src/context/A-ProxyConfig/A_ProxyConfig.context';
|
|
10
31
|
export { A_StaticConfig } from './src/context/A-StaticConfig/A-StaticConfig.context';
|
|
11
|
-
export { A_ListQueryFilter } from './src/context/
|
|
32
|
+
export { A_ListQueryFilter } from './src/context/A-ListQueryFilter/A_ListQueryFilter.context';
|
|
33
|
+
export { A_EntityFactory } from './src/context/A-EntityFactory/A-EntityFactory.context';
|
|
34
|
+
export { A_HTTPChannel_RequestContext } from './src/context/A-HttpChannel/A-HttpChannel.context';
|
|
12
35
|
|
|
13
|
-
|
|
36
|
+
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// Entities Export
|
|
39
|
+
// ============================================================================
|
|
14
40
|
export { A_Request } from './src/entities/A-Request/A-Request.entity';
|
|
15
41
|
export { A_Response } from './src/entities/A-Response/A-Response.entity';
|
|
16
42
|
export { A_Route } from './src/entities/A-Route/A-Route.entity';
|
|
17
43
|
export { A_EntityList } from './src/entities/A_EntityList/A_EntityList.entity';
|
|
18
44
|
|
|
19
|
-
|
|
45
|
+
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// Components Export
|
|
48
|
+
// ============================================================================
|
|
20
49
|
export { A_ServerLogger } from './src/components/A-ServerLogger/A_ServerLogger.component';
|
|
21
50
|
export { A_EntityController } from './src/components/A-EntityController/A-EntityController.component';
|
|
22
51
|
export { A_Router } from './src/components/A-Router/A-Router.component';
|
|
@@ -26,20 +55,21 @@ export { A_ServerCORS } from './src/components/A-ServerCORS/A_ServerCORS.compone
|
|
|
26
55
|
export { A_StaticLoader } from './src/components/A-StaticLoader/A-StaticLoader.component';
|
|
27
56
|
export { A_Controller } from './src/components/A-Controller/A-Controller.component';
|
|
28
57
|
export { A_ListingController } from './src/components/A-ListingController/A-ListingController.component';
|
|
58
|
+
export { A_CommandController } from './src/components/A-CommandController/A-CommandController.component';
|
|
59
|
+
export { A_EntityRepository } from './src/components/A-EntityRepository/A-EntityRepository.component';
|
|
60
|
+
export { A_ServerError } from './src/components/A-ServerError/A-ServerError.class';
|
|
29
61
|
|
|
30
|
-
|
|
31
|
-
|
|
62
|
+
|
|
63
|
+
// ============================================================================
|
|
64
|
+
// Types Export
|
|
65
|
+
// ============================================================================
|
|
32
66
|
export * from './src/containers/A-Service/A-Service.container.types';
|
|
33
|
-
export * from './src/context/
|
|
67
|
+
export * from './src/context/A-ProxyConfig/A_ProxyConfig.types';
|
|
68
|
+
export * from './src/context/A-EntityFactory/A-EntityFactory.context.types';
|
|
34
69
|
export * from './src/entities/A-Request/A-Request.entity.types';
|
|
35
70
|
export * from './src/entities/A-Response/A-Response.entity.types';
|
|
36
71
|
export * from './src/components/A-ServerCORS/A_ServerCORS.component.types';
|
|
37
|
-
export * from
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// export * from './src/components/A-ServerLogger/A_ServerLogger.component.types';
|
|
42
|
-
// export * from './src/components/A-EntityController/A-EntityController.component.types';
|
|
43
|
-
// export * from './src/components/A-Router/A-Router.component.types';
|
|
44
|
-
// export * from './src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.types';
|
|
45
|
-
// export * from './src/components/A-ServerProxy/A-ServerProxy.component.types';
|
|
72
|
+
export * from './src/components/A-Router/A-Router.component.types';
|
|
73
|
+
export * from './src/components/A-ServerError/A-ServerError.types';
|
|
74
|
+
export * from './src/channels/A-Http/A-Http.channel.types';
|
|
75
|
+
export * from './src/channels/A-Http/A-Http.channel.constants';
|
package/jest.config.ts
CHANGED
|
@@ -18,6 +18,7 @@ const config: Config.InitialOptions = {
|
|
|
18
18
|
"@adaas/a-server/components/(.*)": ["<rootDir>/src/components/$1"],
|
|
19
19
|
"@adaas/a-server/containers/(.*)": ["<rootDir>/src/containers/$1"],
|
|
20
20
|
"@adaas/a-server/entities/(.*)": ["<rootDir>/src/entities/$1"],
|
|
21
|
+
"@adaas/a-server/channels/(.*)": ["<rootDir>/src/channels/$1"],
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "SDK to create a server with ease. Build your backend server with modular structure and use it within or outside the ADAAS ecosystem.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://github.com/ADAAS-org/adaas-a-server#readme",
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@adaas/a-concept": "^0.
|
|
51
|
-
"@adaas/a-utils": "^0.
|
|
52
|
-
"@types/node": "^20.10.0"
|
|
50
|
+
"@adaas/a-concept": "^0.1.24",
|
|
51
|
+
"@adaas/a-utils": "^0.1.10"
|
|
53
52
|
},
|
|
54
53
|
"devDependencies": {
|
|
55
54
|
"@types/chai": "^4.3.14",
|
|
56
55
|
"@types/jest": "^29.5.12",
|
|
57
56
|
"@types/mocha": "^10.0.6",
|
|
57
|
+
"@types/node": "^24.9.1",
|
|
58
58
|
"axios": "^1.7.2",
|
|
59
59
|
"chai": "^5.1.0",
|
|
60
60
|
"dotenv": "^16.4.5",
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { A_Context, A_Scope } from "@adaas/a-concept";
|
|
2
|
+
import { A_SERVER_TYPES__ServerMethod } from "../../containers/A-Service/A-Service.container.types";
|
|
3
|
+
import { A_HTTPChannel_RequestContext } from "../../context/A-HttpChannel/A-HttpChannel.context";
|
|
4
|
+
import { A_SERVER_CONSTANTS__A_HttpChannel_Lifecycle } from "./A-Http.channel.constants";
|
|
5
|
+
import { A_ServerError } from "@adaas/a-server/components/A-ServerError/A-ServerError.class";
|
|
6
|
+
import { A_Channel } from "@adaas/a-utils";
|
|
7
|
+
import { A_HTTPChannelError } from "./A-Http.channel.error";
|
|
8
|
+
import { A_SERVER_TYPES__HttpChannelRequestConfig, A_SERVER_TYPES__HttpChannelRequestParams, A_SERVER_TYPES__HttpChannelSendParams } from "./A-Http.channel.types";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export class A_HTTPChannel extends A_Channel {
|
|
13
|
+
|
|
14
|
+
protected baseUrl?: string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Allows to send an HTTP request without expecting a response
|
|
18
|
+
*
|
|
19
|
+
* @param params
|
|
20
|
+
*/
|
|
21
|
+
async send(params: A_SERVER_TYPES__HttpChannelSendParams): Promise<void> {
|
|
22
|
+
this.request(params);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Makes an HTTP request
|
|
27
|
+
*
|
|
28
|
+
* @param params
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
async request<T = any, M extends Record<string, any> = any>(
|
|
32
|
+
/**
|
|
33
|
+
* Provide request parameters
|
|
34
|
+
*/
|
|
35
|
+
params: A_SERVER_TYPES__HttpChannelRequestParams<M>
|
|
36
|
+
): Promise<A_HTTPChannel_RequestContext<T>> {
|
|
37
|
+
const { method, url, data, config } = params;
|
|
38
|
+
|
|
39
|
+
await this.initialize;
|
|
40
|
+
|
|
41
|
+
this._processing = true;
|
|
42
|
+
|
|
43
|
+
const fullUrl = this.buildURL(url, config?.params);
|
|
44
|
+
|
|
45
|
+
const requestScope = new A_Scope({ name: `a-http-channel-request-scope-${method}-${url}-${Date.now()}` });
|
|
46
|
+
const context = new A_HTTPChannel_RequestContext({
|
|
47
|
+
method,
|
|
48
|
+
url,
|
|
49
|
+
data,
|
|
50
|
+
config
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
requestScope.inherit(A_Context.scope(this));
|
|
54
|
+
requestScope.register(context);
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
await this.call(A_SERVER_CONSTANTS__A_HttpChannel_Lifecycle.onBeforeRequest, requestScope);
|
|
58
|
+
|
|
59
|
+
const headers: Record<string, string> = {
|
|
60
|
+
"Content-Type": "application/json",
|
|
61
|
+
...config?.headers,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const options: RequestInit = {
|
|
65
|
+
method,
|
|
66
|
+
headers,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (data && method !== A_SERVER_TYPES__ServerMethod.GET) {
|
|
70
|
+
options.body = JSON.stringify(data);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const response = await fetch(fullUrl, options);
|
|
74
|
+
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
throw new A_ServerError({
|
|
77
|
+
status: response.status,
|
|
78
|
+
title: response.statusText,
|
|
79
|
+
description: `HTTP request to ${fullUrl} failed with status ${response.status}`,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
context.result =
|
|
84
|
+
config?.params?.responseType === "text"
|
|
85
|
+
? await response.text()
|
|
86
|
+
: config?.params?.responseType === "blob"
|
|
87
|
+
? await response.blob()
|
|
88
|
+
: await response.json();
|
|
89
|
+
|
|
90
|
+
await this.call(A_SERVER_CONSTANTS__A_HttpChannel_Lifecycle.onAfterRequest, requestScope);
|
|
91
|
+
|
|
92
|
+
this._processing = false;
|
|
93
|
+
|
|
94
|
+
return context as A_HTTPChannel_RequestContext<T>;
|
|
95
|
+
|
|
96
|
+
} catch (error) {
|
|
97
|
+
|
|
98
|
+
this._processing = false;
|
|
99
|
+
|
|
100
|
+
context.error = error;
|
|
101
|
+
|
|
102
|
+
await this.call(A_SERVER_CONSTANTS__A_HttpChannel_Lifecycle.onError, requestScope);
|
|
103
|
+
|
|
104
|
+
if (config?.throwOnError === false)
|
|
105
|
+
return context as A_HTTPChannel_RequestContext<T>;
|
|
106
|
+
else
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async post<T, M extends Record<string, any> = any>(
|
|
112
|
+
url: string,
|
|
113
|
+
body?: any,
|
|
114
|
+
config?: Partial<A_SERVER_TYPES__HttpChannelRequestConfig>,
|
|
115
|
+
): Promise<A_HTTPChannel_RequestContext<T>> {
|
|
116
|
+
return this.request<T, M>(
|
|
117
|
+
{
|
|
118
|
+
method: A_SERVER_TYPES__ServerMethod.POST,
|
|
119
|
+
url,
|
|
120
|
+
data: body,
|
|
121
|
+
config,
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async get<T, M extends Record<string, any> = any>(
|
|
127
|
+
url: string,
|
|
128
|
+
params?: any,
|
|
129
|
+
config?: Partial<A_SERVER_TYPES__HttpChannelRequestConfig>,
|
|
130
|
+
): Promise<A_HTTPChannel_RequestContext<T>> {
|
|
131
|
+
return this.request<T, M>(
|
|
132
|
+
{
|
|
133
|
+
method: A_SERVER_TYPES__ServerMethod.GET,
|
|
134
|
+
url,
|
|
135
|
+
config: {
|
|
136
|
+
...config,
|
|
137
|
+
params,
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async put<T, M extends Record<string, any> = any>(
|
|
144
|
+
url: string,
|
|
145
|
+
body?: any,
|
|
146
|
+
config?: Partial<A_SERVER_TYPES__HttpChannelRequestConfig>,
|
|
147
|
+
): Promise<A_HTTPChannel_RequestContext<T>> {
|
|
148
|
+
return this.request<T, M>({
|
|
149
|
+
method: A_SERVER_TYPES__ServerMethod.PUT,
|
|
150
|
+
url,
|
|
151
|
+
data: body,
|
|
152
|
+
config,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async delete<T, M extends Record<string, any> = any>(
|
|
157
|
+
url: string,
|
|
158
|
+
params?: any,
|
|
159
|
+
config?: Partial<A_SERVER_TYPES__HttpChannelRequestConfig>,
|
|
160
|
+
): Promise<A_HTTPChannel_RequestContext<T>> {
|
|
161
|
+
return this.request<T, M>({
|
|
162
|
+
method: A_SERVER_TYPES__ServerMethod.DELETE,
|
|
163
|
+
url,
|
|
164
|
+
data: params,
|
|
165
|
+
config,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
protected buildURL(path: string = '', params: Record<string, any> = {}): string {
|
|
171
|
+
|
|
172
|
+
if (!this.baseUrl)
|
|
173
|
+
throw new A_HTTPChannelError(
|
|
174
|
+
A_HTTPChannelError.HttpRequestError,
|
|
175
|
+
"Base URL is not set for HTTP Channel"
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
const url = new URL(`${this.baseUrl}${path.startsWith('/') ? path : `/${path}`}`);
|
|
179
|
+
|
|
180
|
+
Object.keys(params).forEach(key => {
|
|
181
|
+
if (params[key] !== undefined && params[key] !== null) {
|
|
182
|
+
url.searchParams.append(key, params[key]);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return url.toString()
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { A_SERVER_TYPES__ServerMethod } from "@adaas/a-server/containers/A-Service/A-Service.container.types";
|
|
2
|
+
|
|
3
|
+
export type A_SERVER_TYPES__HttpChannelSendParams<M extends Record<string, any> = any> = {
|
|
4
|
+
/**
|
|
5
|
+
* HTTP Method
|
|
6
|
+
*/
|
|
7
|
+
method: A_SERVER_TYPES__ServerMethod,
|
|
8
|
+
/**
|
|
9
|
+
* Request URL
|
|
10
|
+
*/
|
|
11
|
+
url: string,
|
|
12
|
+
/**
|
|
13
|
+
* Request Body or Query Parameters
|
|
14
|
+
*/
|
|
15
|
+
data?: any,
|
|
16
|
+
/**
|
|
17
|
+
* Request Configuration
|
|
18
|
+
*/
|
|
19
|
+
config?: Partial<A_SERVER_TYPES__HttpChannelRequestConfig<M>>,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export type A_SERVER_TYPES__HttpChannelRequestParams<M extends Record<string, any> = any> = {
|
|
24
|
+
/**
|
|
25
|
+
* HTTP Method
|
|
26
|
+
*/
|
|
27
|
+
method: A_SERVER_TYPES__ServerMethod,
|
|
28
|
+
/**
|
|
29
|
+
* Request URL
|
|
30
|
+
*/
|
|
31
|
+
url: string,
|
|
32
|
+
/**
|
|
33
|
+
* Request Body or Query Parameters
|
|
34
|
+
*/
|
|
35
|
+
data?: any,
|
|
36
|
+
/**
|
|
37
|
+
* Request Configuration
|
|
38
|
+
*/
|
|
39
|
+
config?: Partial<A_SERVER_TYPES__HttpChannelRequestConfig<M>>,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export type A_SERVER_TYPES__HttpChannelRequestConfig<M extends Record<string, any> = any> = {
|
|
44
|
+
/**
|
|
45
|
+
* Response Type
|
|
46
|
+
*/
|
|
47
|
+
responseType: "json" | "text" | "blob";
|
|
48
|
+
/**
|
|
49
|
+
* Request Headers
|
|
50
|
+
*/
|
|
51
|
+
headers: Record<string, string>;
|
|
52
|
+
/**
|
|
53
|
+
* Query Parameters
|
|
54
|
+
*/
|
|
55
|
+
params: Record<string, any>;
|
|
56
|
+
/**
|
|
57
|
+
* Metadata
|
|
58
|
+
*/
|
|
59
|
+
meta: M;
|
|
60
|
+
/**
|
|
61
|
+
* Throw on Error
|
|
62
|
+
*/
|
|
63
|
+
throwOnError: boolean;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A_Component, A_Container, A_Inject, A_Scope } 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_Command } from "@adaas/a-utils";
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
export class A_CommandController extends A_Component {
|
|
@@ -15,10 +16,10 @@ export class A_CommandController extends A_Component {
|
|
|
15
16
|
@A_Inject(A_Request) req: A_Request<any, any, { command: string }>,
|
|
16
17
|
@A_Inject(A_Response) res: A_Response,
|
|
17
18
|
@A_Inject(A_Scope) scope: A_Scope,
|
|
19
|
+
@A_Inject(A_Container) container: A_Container,
|
|
18
20
|
): Promise<void> {
|
|
19
21
|
|
|
20
22
|
const commandName = req.params.command;
|
|
21
|
-
|
|
22
23
|
|
|
23
24
|
const CommandConstructor = scope.resolveConstructor<A_Command>(commandName);
|
|
24
25
|
|
|
@@ -30,6 +31,10 @@ export class A_CommandController extends A_Component {
|
|
|
30
31
|
|
|
31
32
|
const command = new CommandConstructor(req.body);
|
|
32
33
|
|
|
34
|
+
container.scope.register(command);
|
|
35
|
+
|
|
36
|
+
console.log(`1) Executing command: ${commandName}`);
|
|
37
|
+
|
|
33
38
|
await command.execute();
|
|
34
39
|
|
|
35
40
|
const serialized = command.toJSON();
|
|
@@ -8,10 +8,6 @@ import { A_Request } from "@adaas/a-server/entities/A-Request/A-Request.entity";
|
|
|
8
8
|
export class A_Controller extends A_Component {
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
@A_Feature.Define({
|
|
12
|
-
name: 'callEntityMethod',
|
|
13
|
-
invoke: false,
|
|
14
|
-
})
|
|
15
11
|
@A_Router.Post({
|
|
16
12
|
path: '/:component/:operation',
|
|
17
13
|
version: 'v1',
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { A_Component, A_Context, A_Feature, A_Inject, A_Scope } from "@adaas/a-concept";
|
|
1
|
+
import { A_Component, A_Context, A_Feature, A_Inject, A_Scope, A_TYPES__Entity_Constructor, ASEID } from "@adaas/a-concept";
|
|
2
2
|
import { A_Request } from "@adaas/a-server/entities/A-Request/A-Request.entity";
|
|
3
3
|
import { A_Router } from "../A-Router/A-Router.component";
|
|
4
4
|
import { A_EntityFactory } from "@adaas/a-server/context/A-EntityFactory/A-EntityFactory.context";
|
|
5
5
|
import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entity";
|
|
6
|
-
import {
|
|
6
|
+
import { A_ServerError } from "../A-ServerError/A-ServerError.class";
|
|
7
|
+
import { A_Manifest } from "@adaas/a-utils";
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
@@ -24,15 +25,27 @@ export class A_EntityController extends A_Component {
|
|
|
24
25
|
async load(
|
|
25
26
|
@A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,
|
|
26
27
|
@A_Inject(A_Response) response: A_Response,
|
|
27
|
-
@A_Inject(A_EntityFactory) factory: A_EntityFactory,
|
|
28
28
|
@A_Inject(A_Scope) scope: A_Scope
|
|
29
29
|
) {
|
|
30
|
+
// Check if the scope has a manifest and if the entity is allowed to save
|
|
31
|
+
// if (
|
|
32
|
+
// scope.has(A_Manifest) && !scope.resolve(A_Manifest)
|
|
33
|
+
// .isAllowed(entity.constructor, 'save')
|
|
34
|
+
// .for(entity.constructor as A_TYPES__Entity_Constructor)
|
|
35
|
+
// )
|
|
36
|
+
// return;
|
|
37
|
+
|
|
38
|
+
|
|
30
39
|
if (!ASEID.isASEID(request.params.aseid)) {
|
|
31
40
|
response.add('A_EntityController.load', 'Invalid ASEID');
|
|
32
41
|
return;
|
|
33
42
|
}
|
|
34
43
|
|
|
35
|
-
|
|
44
|
+
|
|
45
|
+
const aseid = new ASEID(request.params.aseid);
|
|
46
|
+
|
|
47
|
+
const constructor = scope.resolveConstructor(aseid.entity);
|
|
48
|
+
|
|
36
49
|
|
|
37
50
|
if (constructor) {
|
|
38
51
|
const entity = new constructor(request.params.aseid);
|
|
@@ -44,7 +57,11 @@ export class A_EntityController extends A_Component {
|
|
|
44
57
|
return response.status(200).json(entity.toJSON());
|
|
45
58
|
}
|
|
46
59
|
else
|
|
47
|
-
throw new
|
|
60
|
+
throw new A_ServerError({
|
|
61
|
+
title: 'Entity Not Found',
|
|
62
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`,
|
|
63
|
+
status: 404,
|
|
64
|
+
});
|
|
48
65
|
}
|
|
49
66
|
|
|
50
67
|
|
|
@@ -130,10 +147,10 @@ export class A_EntityController extends A_Component {
|
|
|
130
147
|
|
|
131
148
|
|
|
132
149
|
|
|
133
|
-
@A_Feature.Define({
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
})
|
|
150
|
+
// @A_Feature.Define({
|
|
151
|
+
// name: 'callEntity',
|
|
152
|
+
// invoke: false
|
|
153
|
+
// })
|
|
137
154
|
@A_Router.Post({
|
|
138
155
|
path: '/:aseid/:action',
|
|
139
156
|
version: 'v1',
|
|
@@ -176,6 +193,6 @@ export class A_EntityController extends A_Component {
|
|
|
176
193
|
|
|
177
194
|
response.add('result', scope.toJSON());
|
|
178
195
|
response.add('entity', entity);
|
|
179
|
-
response.add('type', entity.entity);
|
|
196
|
+
response.add('type', entity.aseid.entity);
|
|
180
197
|
}
|
|
181
198
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { A_Caller, A_Component, A_Entity, A_Feature, A_Inject, A_Scope, A_TYPES__Entity_Constructor } from "@adaas/a-concept";
|
|
2
|
+
import { A_TYPES__EntityFeatures } from "@adaas/a-concept/dist/src/global/A-Entity/A-Entity.constants";
|
|
3
|
+
import { A_HTTPChannel } from "@adaas/a-server/channels/A-Http/A-Http.channel";
|
|
4
|
+
import { A_EntityList } from "@adaas/a-server/entities/A_EntityList/A_EntityList.entity";
|
|
5
|
+
import { A_Channel, A_Manifest } from "@adaas/a-utils";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export class A_EntityRepository extends A_Component {
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@A_Feature.Extend({
|
|
14
|
+
name: A_TYPES__EntityFeatures.LOAD,
|
|
15
|
+
scope: {
|
|
16
|
+
exclude: [A_EntityList]
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
async load(
|
|
20
|
+
@A_Inject(A_HTTPChannel) channel: A_HTTPChannel,
|
|
21
|
+
@A_Inject(A_Caller) entity: A_Entity,
|
|
22
|
+
@A_Inject(A_Scope) scope: A_Scope,
|
|
23
|
+
) {
|
|
24
|
+
// Check if the scope has a manifest and if the entity is allowed to load
|
|
25
|
+
if (
|
|
26
|
+
scope.has(A_Manifest) && !scope.resolve(A_Manifest)
|
|
27
|
+
.isAllowed(entity.constructor, 'load')
|
|
28
|
+
.for(entity.constructor as A_TYPES__Entity_Constructor)
|
|
29
|
+
)
|
|
30
|
+
return;
|
|
31
|
+
|
|
32
|
+
const response = await channel.get(`/a-entity/${entity.aseid.toString()}`);
|
|
33
|
+
|
|
34
|
+
entity.fromJSON(response.data);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@A_Feature.Extend({
|
|
39
|
+
name: A_TYPES__EntityFeatures.SAVE,
|
|
40
|
+
scope: {
|
|
41
|
+
exclude: [A_EntityList]
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
async save(
|
|
45
|
+
@A_Inject(A_HTTPChannel) channel: A_HTTPChannel,
|
|
46
|
+
@A_Inject(A_Caller) entity: A_Entity,
|
|
47
|
+
@A_Inject(A_Scope) scope: A_Scope,
|
|
48
|
+
) {
|
|
49
|
+
// Check if the scope has a manifest and if the entity is allowed to save
|
|
50
|
+
if (
|
|
51
|
+
scope.has(A_Manifest) && !scope.resolve(A_Manifest)
|
|
52
|
+
.isAllowed(entity.constructor, 'save')
|
|
53
|
+
.for(entity.constructor as A_TYPES__Entity_Constructor)
|
|
54
|
+
)
|
|
55
|
+
return;
|
|
56
|
+
|
|
57
|
+
const response = await channel.post(`/a-entity/${entity.aseid.toString()}`, entity.toJSON());
|
|
58
|
+
|
|
59
|
+
entity.fromJSON(response.data);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@A_Feature.Extend({
|
|
64
|
+
name: A_TYPES__EntityFeatures.DESTROY,
|
|
65
|
+
scope: {
|
|
66
|
+
exclude: [A_EntityList]
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
async destroy(
|
|
70
|
+
@A_Inject(A_HTTPChannel) channel: A_HTTPChannel,
|
|
71
|
+
@A_Inject(A_Caller) entity: A_Entity,
|
|
72
|
+
@A_Inject(A_Scope) scope: A_Scope,
|
|
73
|
+
) {
|
|
74
|
+
// Check if the scope has a manifest and if the entity is allowed to destroy
|
|
75
|
+
if (
|
|
76
|
+
scope.has(A_Manifest) && !scope.resolve(A_Manifest)
|
|
77
|
+
.isAllowed(entity.constructor, 'destroy')
|
|
78
|
+
.for(entity.constructor as A_TYPES__Entity_Constructor)
|
|
79
|
+
)
|
|
80
|
+
return;
|
|
81
|
+
|
|
82
|
+
const response = await channel.delete(`/a-entity/${entity.aseid.toString()}`);
|
|
83
|
+
|
|
84
|
+
entity.fromJSON(response.data);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { A_Component,
|
|
1
|
+
import { A_Component, A_Feature, A_Inject, A_Scope } from "@adaas/a-concept"
|
|
2
2
|
import { A_EntityFactory } from "@adaas/a-server/context/A-EntityFactory/A-EntityFactory.context";
|
|
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
5
|
import { A_Router } from "../A-Router/A-Router.component";
|
|
6
6
|
import { A_EntityList } from "@adaas/a-server/entities/A_EntityList/A_EntityList.entity";
|
|
7
|
-
import { A_ListQueryFilter } from "@adaas/a-server/context/
|
|
7
|
+
import { A_ListQueryFilter } from "@adaas/a-server/context/A-ListQueryFilter/A_ListQueryFilter.context";
|
|
8
|
+
import { A_Config } from "@adaas/a-utils";
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
export class A_ListingController extends A_Component {
|
|
12
13
|
|
|
13
|
-
@A_Feature.Define({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})
|
|
14
|
+
// @A_Feature.Define({
|
|
15
|
+
// name: 'listEntities',
|
|
16
|
+
// invoke: false
|
|
17
|
+
// })
|
|
17
18
|
@A_Router.Get({
|
|
18
19
|
path: '/:type',
|
|
19
20
|
version: 'v1',
|