@adaas/a-server 0.0.29 → 0.0.31
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/dist/browser/index.d.mts +123 -69
- package/dist/browser/index.mjs +211 -69
- package/dist/browser/index.mjs.map +1 -1
- package/dist/node/controllers/A-EntityController/A-EntityController.component.d.mts +2 -5
- package/dist/node/controllers/A-EntityController/A-EntityController.component.d.ts +2 -5
- package/dist/node/controllers/A-EntityController/A-EntityController.component.js +66 -88
- package/dist/node/controllers/A-EntityController/A-EntityController.component.js.map +1 -1
- package/dist/node/controllers/A-EntityController/A-EntityController.component.mjs +67 -89
- package/dist/node/controllers/A-EntityController/A-EntityController.component.mjs.map +1 -1
- package/dist/node/controllers/A-ListingController/A-ListingController.component.js +20 -18
- package/dist/node/controllers/A-ListingController/A-ListingController.component.js.map +1 -1
- package/dist/node/controllers/A-ListingController/A-ListingController.component.mjs +20 -18
- package/dist/node/controllers/A-ListingController/A-ListingController.component.mjs.map +1 -1
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.d.mts +0 -2
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.d.ts +0 -2
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js +10 -1
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js.map +1 -1
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.mjs +10 -1
- package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.mjs.map +1 -1
- package/dist/node/index.d.mts +3 -1
- package/dist/node/index.d.ts +3 -1
- package/dist/node/index.js +14 -0
- package/dist/node/index.mjs +2 -0
- package/dist/node/lib/A-Server/A-HttpServer.container.d.mts +4 -6
- package/dist/node/lib/A-Server/A-HttpServer.container.d.ts +4 -6
- package/dist/node/lib/A-ServerController/A-ServerController.component.js +17 -4
- package/dist/node/lib/A-ServerController/A-ServerController.component.js.map +1 -1
- package/dist/node/lib/A-ServerController/A-ServerController.component.mjs +17 -4
- package/dist/node/lib/A-ServerController/A-ServerController.component.mjs.map +1 -1
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.d.mts +52 -28
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.d.ts +52 -28
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.js +117 -44
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.js.map +1 -1
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.mjs +118 -45
- package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.mjs.map +1 -1
- package/dist/node/lib/A-ServerEntityList/A-EntityList.types.d.mts +14 -6
- package/dist/node/lib/A-ServerEntityList/A-EntityList.types.d.ts +14 -6
- package/dist/node/lib/A-ServerEntityList/A-EntityList.types.js.map +1 -1
- package/dist/node/lib/A-ServerEntityList/A-EntityList.types.mjs.map +1 -1
- package/dist/node/lib/A-ServerEntityList/A-EntityListCacheState.context.d.mts +12 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityListCacheState.context.d.ts +12 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityListCacheState.context.js +25 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityListCacheState.context.js.map +1 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityListCacheState.context.mjs +24 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityListCacheState.context.mjs.map +1 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityListPagination.context.d.mts +18 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityListPagination.context.d.ts +18 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityListPagination.context.js +48 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityListPagination.context.js.map +1 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityListPagination.context.mjs +47 -0
- package/dist/node/lib/A-ServerEntityList/A-EntityListPagination.context.mjs.map +1 -0
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.d.mts +6 -8
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.d.ts +6 -8
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.js +3 -4
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.js.map +1 -1
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.mjs +4 -5
- package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.mjs.map +1 -1
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.d.mts +0 -2
- package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.d.ts +0 -2
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.js +1 -1
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.js.map +1 -1
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.mjs +1 -1
- package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.mjs.map +1 -1
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.d.mts +1 -0
- package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.d.ts +1 -0
- package/examples/simple-server/components/Users.repository.ts +2 -2
- package/jest.config.ts +1 -0
- package/package.json +5 -5
- package/src/controllers/A-EntityController/A-EntityController.component.ts +69 -109
- package/src/controllers/A-ListingController/A-ListingController.component.ts +22 -20
- package/src/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.ts +11 -1
- package/src/index.ts +2 -0
- package/src/lib/A-ServerController/A-ServerController.component.ts +17 -8
- package/src/lib/A-ServerEntityList/A-EntityList.entity.ts +159 -55
- package/src/lib/A-ServerEntityList/A-EntityList.types.ts +17 -7
- package/src/lib/A-ServerEntityList/A-EntityListCacheState.context.ts +27 -0
- package/src/lib/A-ServerEntityList/A-EntityListPagination.context.ts +48 -0
- package/src/lib/A-ServerLogger/A-ServerLogger.component.ts +3 -4
- package/src/middlewares/A-ServerCORS/A_ServerCORS.component.ts +1 -1
- package/tests/A-Server-CORS.test.ts +542 -0
- package/tests/A-Server-Entity.test.ts +205 -0
- package/tests/A-Server-Health.test.ts +89 -0
- package/tests/A-Server-Routes.test.ts +113 -0
- package/tests/A-ServerEntityList.test.ts +416 -0
package/jest.config.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31",
|
|
4
4
|
"description": "A-Server is a powerful server framework designed to work seamlessly with the A-Concept framework. This library provides a robust and flexible server implementation of A-Server, enabling developers to create scalable and efficient server-side applications using the A-Concept architecture.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adaas",
|
|
@@ -290,14 +290,14 @@
|
|
|
290
290
|
"build": "tsup --config tsup.config.ts"
|
|
291
291
|
},
|
|
292
292
|
"peerDependencies": {
|
|
293
|
-
"@adaas/a-concept": "^0.3.
|
|
293
|
+
"@adaas/a-concept": "^0.3.17",
|
|
294
294
|
"@adaas/a-frame": "^0.1.2",
|
|
295
|
-
"@adaas/a-utils": "^0.3.
|
|
295
|
+
"@adaas/a-utils": "^0.3.23"
|
|
296
296
|
},
|
|
297
297
|
"devDependencies": {
|
|
298
|
-
"@adaas/a-concept": "^0.3.
|
|
298
|
+
"@adaas/a-concept": "^0.3.17",
|
|
299
299
|
"@adaas/a-frame": "^0.1.2",
|
|
300
|
-
"@adaas/a-utils": "^0.3.
|
|
300
|
+
"@adaas/a-utils": "^0.3.23",
|
|
301
301
|
"@types/chai": "^4.3.14",
|
|
302
302
|
"@types/jest": "^29.5.12",
|
|
303
303
|
"@types/mocha": "^10.0.6",
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { A_Component, A_Context, A_Feature, A_Inject, A_Scope,
|
|
1
|
+
import { A_Component, A_Context, A_Feature, A_Inject, A_Scope, ASEID } from "@adaas/a-concept";
|
|
2
2
|
import { A_Request } from "@adaas/a-server/request/A-Request.entity";
|
|
3
3
|
import { A_ServerRouter } from "@adaas/a-server/router/A-ServerRouter.component";
|
|
4
4
|
import { A_Response } from "@adaas/a-server/response/A-Response.entity";
|
|
5
|
-
import {
|
|
6
|
-
import { A_ServerListQueryFilter } from "@adaas/a-server/list-query/A-ServerListQueryFilter.context";
|
|
7
|
-
import { A_ServerEntityList } from "@adaas/a-server/entity-list/A-EntityList.entity";
|
|
8
|
-
import { A_Config } from "@adaas/a-utils/a-config";
|
|
5
|
+
import { A_HttpServerError } from "../../lib/A-Server/A-HttpServer.error";
|
|
9
6
|
|
|
10
7
|
|
|
11
8
|
|
|
@@ -14,46 +11,6 @@ export class A_EntityController extends A_Component {
|
|
|
14
11
|
// =======================================================
|
|
15
12
|
// ================ Method Definition=====================
|
|
16
13
|
// =======================================================
|
|
17
|
-
@A_ServerRouter.Get({
|
|
18
|
-
path: '/:type',
|
|
19
|
-
version: 'v1',
|
|
20
|
-
prefix: 'a-list'
|
|
21
|
-
})
|
|
22
|
-
async list(
|
|
23
|
-
@A_Inject(A_Request) request: A_Request<any, any, { type: string }>,
|
|
24
|
-
@A_Inject(A_Response) response: A_Response,
|
|
25
|
-
@A_Inject(A_Scope) scope: A_Scope,
|
|
26
|
-
@A_Inject(A_Config) config: A_Config<['A_LIST_ITEMS_PER_PAGE', 'A_LIST_PAGE']>
|
|
27
|
-
) {
|
|
28
|
-
|
|
29
|
-
const constructor = scope.resolveConstructor(request.params.type);
|
|
30
|
-
|
|
31
|
-
if (constructor) {
|
|
32
|
-
|
|
33
|
-
const entityList = new A_ServerEntityList({
|
|
34
|
-
name: request.params.type,
|
|
35
|
-
scope: scope.name,
|
|
36
|
-
constructor
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
scope.register(entityList);
|
|
40
|
-
|
|
41
|
-
const queryFilter = new A_ServerListQueryFilter(request.query, {
|
|
42
|
-
itemsPerPage: String(config.get('A_LIST_ITEMS_PER_PAGE') || '10'),
|
|
43
|
-
page: String(config.get('A_LIST_PAGE') || '1')
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const queryScope = new A_Scope({
|
|
47
|
-
fragments: [queryFilter]
|
|
48
|
-
}).inherit(scope);
|
|
49
|
-
|
|
50
|
-
await entityList.load(queryScope);
|
|
51
|
-
|
|
52
|
-
response.add('items', entityList.items);
|
|
53
|
-
response.add('pagination', entityList.pagination);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
14
|
|
|
58
15
|
@A_Feature.Define({
|
|
59
16
|
name: 'getEntity',
|
|
@@ -69,44 +26,29 @@ export class A_EntityController extends A_Component {
|
|
|
69
26
|
@A_Inject(A_Response) response: A_Response,
|
|
70
27
|
@A_Inject(A_Scope) scope: A_Scope
|
|
71
28
|
) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// )
|
|
78
|
-
// return;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
console.log('Request params:', request.params);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (!ASEID.isASEID(request.params.aseid)) {
|
|
85
|
-
response.add('A_EntityController.load', 'Invalid ASEID');
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
29
|
+
if (!ASEID.isASEID(request.params.aseid))
|
|
30
|
+
throw new A_HttpServerError({
|
|
31
|
+
status: 400,
|
|
32
|
+
description: `Invalid ASEID: "${request.params.aseid}"`,
|
|
33
|
+
});
|
|
89
34
|
|
|
90
35
|
const aseid = new ASEID(request.params.aseid);
|
|
91
36
|
|
|
92
37
|
const constructor = scope.resolveConstructor(aseid.entity);
|
|
93
38
|
|
|
39
|
+
if (!constructor)
|
|
40
|
+
throw new A_HttpServerError({
|
|
41
|
+
status: 404,
|
|
42
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`,
|
|
43
|
+
});
|
|
94
44
|
|
|
95
|
-
|
|
96
|
-
const entity = new constructor(request.params.aseid);
|
|
45
|
+
const entity = new constructor(request.params.aseid);
|
|
97
46
|
|
|
98
|
-
|
|
47
|
+
scope.register(entity);
|
|
99
48
|
|
|
100
|
-
|
|
49
|
+
await entity.load();
|
|
101
50
|
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
else
|
|
105
|
-
throw new A_ServerError({
|
|
106
|
-
title: 'Entity Not Found',
|
|
107
|
-
description: `Entity constructor for ASEID ${request.params.aseid} not found`,
|
|
108
|
-
status: 404,
|
|
109
|
-
});
|
|
51
|
+
return response.status(200).send(entity.toJSON());
|
|
110
52
|
}
|
|
111
53
|
|
|
112
54
|
|
|
@@ -118,17 +60,22 @@ export class A_EntityController extends A_Component {
|
|
|
118
60
|
})
|
|
119
61
|
async create(
|
|
120
62
|
@A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,
|
|
63
|
+
@A_Inject(A_Response) response: A_Response,
|
|
121
64
|
@A_Inject(A_Scope) scope: A_Scope
|
|
122
65
|
) {
|
|
123
66
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
124
67
|
|
|
125
|
-
if (constructor)
|
|
126
|
-
|
|
68
|
+
if (!constructor)
|
|
69
|
+
throw new A_HttpServerError({
|
|
70
|
+
status: 404,
|
|
71
|
+
description: `Entity type "${request.params.aseid}" not registered`,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const entity = new constructor(request.body);
|
|
127
75
|
|
|
128
|
-
|
|
76
|
+
scope.register(entity);
|
|
129
77
|
|
|
130
|
-
|
|
131
|
-
}
|
|
78
|
+
await entity.save();
|
|
132
79
|
}
|
|
133
80
|
|
|
134
81
|
|
|
@@ -143,20 +90,25 @@ export class A_EntityController extends A_Component {
|
|
|
143
90
|
@A_Inject(A_Response) response: A_Response,
|
|
144
91
|
@A_Inject(A_Scope) scope: A_Scope
|
|
145
92
|
) {
|
|
146
|
-
if (!ASEID.isASEID(request.params.aseid))
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
93
|
+
if (!ASEID.isASEID(request.params.aseid))
|
|
94
|
+
throw new A_HttpServerError({
|
|
95
|
+
status: 400,
|
|
96
|
+
description: `Invalid ASEID: "${request.params.aseid}"`,
|
|
97
|
+
});
|
|
150
98
|
|
|
151
99
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
152
100
|
|
|
153
|
-
if (constructor)
|
|
154
|
-
|
|
101
|
+
if (!constructor)
|
|
102
|
+
throw new A_HttpServerError({
|
|
103
|
+
status: 404,
|
|
104
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const entity = new constructor(request.body);
|
|
155
108
|
|
|
156
|
-
|
|
109
|
+
scope.register(entity);
|
|
157
110
|
|
|
158
|
-
|
|
159
|
-
}
|
|
111
|
+
await entity.save();
|
|
160
112
|
}
|
|
161
113
|
|
|
162
114
|
|
|
@@ -170,20 +122,25 @@ export class A_EntityController extends A_Component {
|
|
|
170
122
|
@A_Inject(A_Response) response: A_Response,
|
|
171
123
|
@A_Inject(A_Scope) scope: A_Scope
|
|
172
124
|
) {
|
|
173
|
-
if (!ASEID.isASEID(request.params.aseid))
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
125
|
+
if (!ASEID.isASEID(request.params.aseid))
|
|
126
|
+
throw new A_HttpServerError({
|
|
127
|
+
status: 400,
|
|
128
|
+
description: `Invalid ASEID: "${request.params.aseid}"`,
|
|
129
|
+
});
|
|
177
130
|
|
|
178
131
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
179
132
|
|
|
180
|
-
if (constructor)
|
|
181
|
-
|
|
133
|
+
if (!constructor)
|
|
134
|
+
throw new A_HttpServerError({
|
|
135
|
+
status: 404,
|
|
136
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`,
|
|
137
|
+
});
|
|
182
138
|
|
|
183
|
-
|
|
139
|
+
const entity = new constructor(request.params.aseid);
|
|
140
|
+
|
|
141
|
+
scope.register(entity);
|
|
184
142
|
|
|
185
|
-
|
|
186
|
-
}
|
|
143
|
+
await entity.destroy();
|
|
187
144
|
}
|
|
188
145
|
|
|
189
146
|
|
|
@@ -202,26 +159,29 @@ export class A_EntityController extends A_Component {
|
|
|
202
159
|
@A_Inject(A_Response) response: A_Response,
|
|
203
160
|
@A_Inject(A_Scope) scope: A_Scope
|
|
204
161
|
) {
|
|
205
|
-
if (!ASEID.isASEID(request.params.aseid))
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
162
|
+
if (!ASEID.isASEID(request.params.aseid))
|
|
163
|
+
throw new A_HttpServerError({
|
|
164
|
+
status: 400,
|
|
165
|
+
description: `Invalid ASEID: "${request.params.aseid}"`,
|
|
166
|
+
});
|
|
209
167
|
|
|
210
168
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
211
169
|
|
|
212
|
-
if (!constructor)
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
170
|
+
if (!constructor)
|
|
171
|
+
throw new A_HttpServerError({
|
|
172
|
+
status: 404,
|
|
173
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`,
|
|
174
|
+
});
|
|
216
175
|
|
|
217
176
|
const meta = A_Context.meta(constructor);
|
|
218
177
|
|
|
219
178
|
const targetFeature = meta.features().find(f => f.name === `${constructor.name}.${request.params.action}`);
|
|
220
179
|
|
|
221
|
-
if (!targetFeature)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
180
|
+
if (!targetFeature)
|
|
181
|
+
throw new A_HttpServerError({
|
|
182
|
+
status: 404,
|
|
183
|
+
description: `Feature "${request.params.action}" not found on entity`,
|
|
184
|
+
});
|
|
225
185
|
|
|
226
186
|
const entity = new constructor(request.params.aseid);
|
|
227
187
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { A_Component,
|
|
1
|
+
import { A_Component, A_Feature, A_Inject, A_Scope } from "@adaas/a-concept"
|
|
2
2
|
import { A_Config } from "@adaas/a-utils/a-config";
|
|
3
3
|
import { A_Request } from "@adaas/a-server/request/A-Request.entity";
|
|
4
4
|
import { A_Response } from "@adaas/a-server/response/A-Response.entity";
|
|
5
5
|
import { A_ServerRouter } from "@adaas/a-server/router/A-ServerRouter.component";
|
|
6
6
|
import { A_ServerEntityList } from "@adaas/a-server/entity-list/A-EntityList.entity";
|
|
7
7
|
import { A_ServerListQueryFilter } from "@adaas/a-server/list-query/A-ServerListQueryFilter.context";
|
|
8
|
+
import { A_HttpServerError } from "../../lib/A-Server/A-HttpServer.error";
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
@@ -26,31 +27,32 @@ export class A_ListingController extends A_Component {
|
|
|
26
27
|
@A_Inject(A_Config) config: A_Config<['A_LIST_ITEMS_PER_PAGE', 'A_LIST_PAGE']>
|
|
27
28
|
) {
|
|
28
29
|
|
|
29
|
-
const
|
|
30
|
+
const ctor = scope.resolveConstructor(request.params.type);
|
|
30
31
|
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
scope: scope.name,
|
|
36
|
-
constructor
|
|
32
|
+
if (!ctor)
|
|
33
|
+
throw new A_HttpServerError({
|
|
34
|
+
status: 404,
|
|
35
|
+
description: `Entity type "${request.params.type}" not registered`,
|
|
37
36
|
});
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
const entityList = new A_ServerEntityList({
|
|
39
|
+
entity: ctor,
|
|
40
|
+
});
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
scope.register(entityList);
|
|
43
|
+
|
|
44
|
+
const queryFilter = new A_ServerListQueryFilter(request.query, {
|
|
45
|
+
itemsPerPage: String(config.get('A_LIST_ITEMS_PER_PAGE') || '10'),
|
|
46
|
+
page: String(config.get('A_LIST_PAGE') || '1'),
|
|
47
|
+
});
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
const queryScope = new A_Scope({
|
|
50
|
+
fragments: [queryFilter],
|
|
51
|
+
}).inherit(scope);
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
await entityList.load(queryScope);
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
+
response.add('items', entityList.items);
|
|
56
|
+
response.add('pagination', entityList.pagination);
|
|
55
57
|
}
|
|
56
58
|
}
|
|
@@ -4,6 +4,7 @@ import { A_Request } from "@adaas/a-server/request/A-Request.entity";
|
|
|
4
4
|
import { A_Response } from "@adaas/a-server/response/A-Response.entity";
|
|
5
5
|
import { A_Config } from "@adaas/a-utils/a-config";
|
|
6
6
|
import { A_ServerLogger } from "@adaas/a-server/logger/A-ServerLogger.component";
|
|
7
|
+
import { A_HttpServerError } from "../../lib/A-Server/A-HttpServer.error";
|
|
7
8
|
import fs from "fs";
|
|
8
9
|
import path from "path";
|
|
9
10
|
|
|
@@ -29,8 +30,17 @@ export class A_ServerHealthMonitor extends A_Component {
|
|
|
29
30
|
): Promise<any> {
|
|
30
31
|
const rootFolder = config.get('A_CONCEPT_ROOT_FOLDER') || A_CONCEPT_ENV.A_CONCEPT_ROOT_FOLDER || process.cwd();
|
|
31
32
|
const pkgPath = path.join(rootFolder, 'package.json');
|
|
32
|
-
const packageJSON = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
33
33
|
|
|
34
|
+
let packageJSON: Record<string, unknown>;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
packageJSON = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
38
|
+
} catch {
|
|
39
|
+
throw new A_HttpServerError({
|
|
40
|
+
status: 500,
|
|
41
|
+
description: `Could not read package.json at "${pkgPath}"`,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
34
44
|
|
|
35
45
|
const exposedProperties: Array<string> = config.get('EXPOSED_PROPERTIES')?.split(',') || [
|
|
36
46
|
'name',
|
package/src/index.ts
CHANGED
|
@@ -31,6 +31,8 @@ export * from './lib/A-ServerController/A-ServerController.types';
|
|
|
31
31
|
// ── lib/A-ServerEntityList ────────────────────────────────────────────────────
|
|
32
32
|
export * from './lib/A-ServerEntityList/A-EntityList.entity';
|
|
33
33
|
export * from './lib/A-ServerEntityList/A-EntityList.types';
|
|
34
|
+
export * from './lib/A-ServerEntityList/A-EntityListPagination.context';
|
|
35
|
+
export * from './lib/A-ServerEntityList/A-EntityListCacheState.context';
|
|
34
36
|
|
|
35
37
|
// ── lib/A-ServerListQuery ─────────────────────────────────────────────────────
|
|
36
38
|
export * from './lib/A-ServerListQuery/A-ServerListQueryFilter.context';
|
|
@@ -2,6 +2,7 @@ import { A_Component, A_Container, A_Context, A_Feature, A_Inject, A_Scope } fro
|
|
|
2
2
|
import { A_ServerRouter } from "@adaas/a-server/router/A-ServerRouter.component";
|
|
3
3
|
import { A_Response } from "@adaas/a-server/response/A-Response.entity";
|
|
4
4
|
import { A_Request } from "@adaas/a-server/request/A-Request.entity";
|
|
5
|
+
import { A_HttpServerError } from "../A-Server/A-HttpServer.error";
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
@@ -22,14 +23,17 @@ export class A_ServerController extends A_Component {
|
|
|
22
23
|
@A_Inject(A_Scope) scope: A_Scope
|
|
23
24
|
) {
|
|
24
25
|
|
|
25
|
-
// check step by step each parameter to ensure they are valid
|
|
26
|
-
|
|
27
26
|
if (!scope.has(request.params.component))
|
|
28
|
-
|
|
27
|
+
throw new A_HttpServerError({
|
|
28
|
+
status: 404,
|
|
29
|
+
description: `Component "${request.params.component}" not found`,
|
|
30
|
+
});
|
|
29
31
|
|
|
30
32
|
if (!request.params.operation || typeof request.params.operation !== 'string')
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
throw new A_HttpServerError({
|
|
34
|
+
status: 400,
|
|
35
|
+
description: 'Missing or invalid "operation" parameter',
|
|
36
|
+
});
|
|
33
37
|
|
|
34
38
|
const possibleComponent = scope.resolve(request.params.component);
|
|
35
39
|
|
|
@@ -39,7 +43,10 @@ export class A_ServerController extends A_Component {
|
|
|
39
43
|
![A_Component, A_Container]
|
|
40
44
|
.some(c => possibleComponent instanceof c)
|
|
41
45
|
)
|
|
42
|
-
|
|
46
|
+
throw new A_HttpServerError({
|
|
47
|
+
status: 404,
|
|
48
|
+
description: `"${request.params.component}" is not a valid component`,
|
|
49
|
+
});
|
|
43
50
|
|
|
44
51
|
const component = possibleComponent as A_Component | A_Container;
|
|
45
52
|
|
|
@@ -48,8 +55,10 @@ export class A_ServerController extends A_Component {
|
|
|
48
55
|
const targetFeature = meta.features().find(f => f.name === `${component.constructor.name}.${request.params.operation}`);
|
|
49
56
|
|
|
50
57
|
if (!targetFeature)
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
throw new A_HttpServerError({
|
|
59
|
+
status: 404,
|
|
60
|
+
description: `Operation "${request.params.operation}" not found on component "${request.params.component}"`,
|
|
61
|
+
});
|
|
53
62
|
|
|
54
63
|
await component.call(request.params.operation, scope);
|
|
55
64
|
}
|