@adaas/a-server 0.0.29 → 0.0.30
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 +1 -1
- 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
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { A_Component, A_Scope } from '@adaas/a-concept';
|
|
2
2
|
import { A as A_Request } from '../../A-Request.entity-r905O60G.mjs';
|
|
3
3
|
import { A as A_Response } from '../../A-Response.entity-6qhiV7BE.mjs';
|
|
4
|
-
import { A_Config } from '@adaas/a-utils/a-config';
|
|
5
4
|
import 'http';
|
|
6
5
|
import '../../lib/A-Server/A-HttpServer.error.mjs';
|
|
7
6
|
import '../../lib/A-Server/A-HttpServer.types.mjs';
|
|
@@ -12,6 +11,7 @@ import '../../lib/A-Request/A-HttpServerRequest.context.mjs';
|
|
|
12
11
|
import '@adaas/a-utils/a-operation';
|
|
13
12
|
import '../../lib/A-Request/A-HttpRequestData.context.mjs';
|
|
14
13
|
import '@adaas/a-utils/a-execution';
|
|
14
|
+
import '@adaas/a-utils/a-config';
|
|
15
15
|
import '../../lib/A-ServerRoute/A-ServerRoute.entity.mjs';
|
|
16
16
|
import '@adaas/a-utils/a-route';
|
|
17
17
|
import '../../lib/A-ServerRoute/A-ServerRoute.types.mjs';
|
|
@@ -20,15 +20,12 @@ import 'stream';
|
|
|
20
20
|
import '../../lib/A-Response/A-Response.constants.mjs';
|
|
21
21
|
|
|
22
22
|
declare class A_EntityController extends A_Component {
|
|
23
|
-
list(request: A_Request<any, any, {
|
|
24
|
-
type: string;
|
|
25
|
-
}>, response: A_Response, scope: A_Scope, config: A_Config<['A_LIST_ITEMS_PER_PAGE', 'A_LIST_PAGE']>): Promise<void>;
|
|
26
23
|
load(request: A_Request<any, any, {
|
|
27
24
|
aseid: string;
|
|
28
25
|
}>, response: A_Response, scope: A_Scope): Promise<void>;
|
|
29
26
|
create(request: A_Request<any, any, {
|
|
30
27
|
aseid: string;
|
|
31
|
-
}>, scope: A_Scope): Promise<void>;
|
|
28
|
+
}>, response: A_Response, scope: A_Scope): Promise<void>;
|
|
32
29
|
update(request: A_Request<any, any, {
|
|
33
30
|
aseid: string;
|
|
34
31
|
}>, response: A_Response, scope: A_Scope): Promise<void>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { A_Component, A_Scope } from '@adaas/a-concept';
|
|
2
2
|
import { A as A_Request } from '../../A-Request.entity-8_9MCXT2.js';
|
|
3
3
|
import { A as A_Response } from '../../A-Response.entity-bjh6bofZ.js';
|
|
4
|
-
import { A_Config } from '@adaas/a-utils/a-config';
|
|
5
4
|
import 'http';
|
|
6
5
|
import '../../lib/A-Server/A-HttpServer.error.js';
|
|
7
6
|
import '../../lib/A-Server/A-HttpServer.types.js';
|
|
@@ -12,6 +11,7 @@ import '../../lib/A-Request/A-HttpServerRequest.context.js';
|
|
|
12
11
|
import '@adaas/a-utils/a-operation';
|
|
13
12
|
import '../../lib/A-Request/A-HttpRequestData.context.js';
|
|
14
13
|
import '@adaas/a-utils/a-execution';
|
|
14
|
+
import '@adaas/a-utils/a-config';
|
|
15
15
|
import '../../lib/A-ServerRoute/A-ServerRoute.entity.js';
|
|
16
16
|
import '@adaas/a-utils/a-route';
|
|
17
17
|
import '../../lib/A-ServerRoute/A-ServerRoute.types.js';
|
|
@@ -20,15 +20,12 @@ import 'stream';
|
|
|
20
20
|
import '../../lib/A-Response/A-Response.constants.js';
|
|
21
21
|
|
|
22
22
|
declare class A_EntityController extends A_Component {
|
|
23
|
-
list(request: A_Request<any, any, {
|
|
24
|
-
type: string;
|
|
25
|
-
}>, response: A_Response, scope: A_Scope, config: A_Config<['A_LIST_ITEMS_PER_PAGE', 'A_LIST_PAGE']>): Promise<void>;
|
|
26
23
|
load(request: A_Request<any, any, {
|
|
27
24
|
aseid: string;
|
|
28
25
|
}>, response: A_Response, scope: A_Scope): Promise<void>;
|
|
29
26
|
create(request: A_Request<any, any, {
|
|
30
27
|
aseid: string;
|
|
31
|
-
}>, scope: A_Scope): Promise<void>;
|
|
28
|
+
}>, response: A_Response, scope: A_Scope): Promise<void>;
|
|
32
29
|
update(request: A_Request<any, any, {
|
|
33
30
|
aseid: string;
|
|
34
31
|
}>, response: A_Response, scope: A_Scope): Promise<void>;
|
|
@@ -4,10 +4,7 @@ var aConcept = require('@adaas/a-concept');
|
|
|
4
4
|
var ARequest_entity = require('@adaas/a-server/request/A-Request.entity');
|
|
5
5
|
var AServerRouter_component = require('@adaas/a-server/router/A-ServerRouter.component');
|
|
6
6
|
var AResponse_entity = require('@adaas/a-server/response/A-Response.entity');
|
|
7
|
-
var
|
|
8
|
-
var AServerListQueryFilter_context = require('@adaas/a-server/list-query/A-ServerListQueryFilter.context');
|
|
9
|
-
var AEntityList_entity = require('@adaas/a-server/entity-list/A-EntityList.entity');
|
|
10
|
-
var aConfig = require('@adaas/a-utils/a-config');
|
|
7
|
+
var AHttpServer_error = require('../../lib/A-Server/A-HttpServer.error');
|
|
11
8
|
|
|
12
9
|
var __defProp = Object.defineProperty;
|
|
13
10
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -21,95 +18,86 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
21
18
|
};
|
|
22
19
|
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
23
20
|
class A_EntityController extends aConcept.A_Component {
|
|
24
|
-
async list(request, response, scope, config) {
|
|
25
|
-
const constructor = scope.resolveConstructor(request.params.type);
|
|
26
|
-
if (constructor) {
|
|
27
|
-
const entityList = new AEntityList_entity.A_ServerEntityList({
|
|
28
|
-
name: request.params.type,
|
|
29
|
-
scope: scope.name,
|
|
30
|
-
constructor
|
|
31
|
-
});
|
|
32
|
-
scope.register(entityList);
|
|
33
|
-
const queryFilter = new AServerListQueryFilter_context.A_ServerListQueryFilter(request.query, {
|
|
34
|
-
itemsPerPage: String(config.get("A_LIST_ITEMS_PER_PAGE") || "10"),
|
|
35
|
-
page: String(config.get("A_LIST_PAGE") || "1")
|
|
36
|
-
});
|
|
37
|
-
const queryScope = new aConcept.A_Scope({
|
|
38
|
-
fragments: [queryFilter]
|
|
39
|
-
}).inherit(scope);
|
|
40
|
-
await entityList.load(queryScope);
|
|
41
|
-
response.add("items", entityList.items);
|
|
42
|
-
response.add("pagination", entityList.pagination);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
21
|
async load(request, response, scope) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
22
|
+
if (!aConcept.ASEID.isASEID(request.params.aseid))
|
|
23
|
+
throw new AHttpServer_error.A_HttpServerError({
|
|
24
|
+
status: 400,
|
|
25
|
+
description: `Invalid ASEID: "${request.params.aseid}"`
|
|
26
|
+
});
|
|
51
27
|
const aseid = new aConcept.ASEID(request.params.aseid);
|
|
52
28
|
const constructor = scope.resolveConstructor(aseid.entity);
|
|
53
|
-
if (constructor)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return response.status(200).send(entity.toJSON());
|
|
58
|
-
} else
|
|
59
|
-
throw new AServer_error.A_ServerError({
|
|
60
|
-
title: "Entity Not Found",
|
|
61
|
-
description: `Entity constructor for ASEID ${request.params.aseid} not found`,
|
|
62
|
-
status: 404
|
|
29
|
+
if (!constructor)
|
|
30
|
+
throw new AHttpServer_error.A_HttpServerError({
|
|
31
|
+
status: 404,
|
|
32
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`
|
|
63
33
|
});
|
|
34
|
+
const entity = new constructor(request.params.aseid);
|
|
35
|
+
scope.register(entity);
|
|
36
|
+
await entity.load();
|
|
37
|
+
return response.status(200).send(entity.toJSON());
|
|
64
38
|
}
|
|
65
|
-
async create(request, scope) {
|
|
39
|
+
async create(request, response, scope) {
|
|
66
40
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
67
|
-
if (constructor)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
41
|
+
if (!constructor)
|
|
42
|
+
throw new AHttpServer_error.A_HttpServerError({
|
|
43
|
+
status: 404,
|
|
44
|
+
description: `Entity type "${request.params.aseid}" not registered`
|
|
45
|
+
});
|
|
46
|
+
const entity = new constructor(request.body);
|
|
47
|
+
scope.register(entity);
|
|
48
|
+
await entity.save();
|
|
72
49
|
}
|
|
73
50
|
async update(request, response, scope) {
|
|
74
|
-
if (!aConcept.ASEID.isASEID(request.params.aseid))
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
51
|
+
if (!aConcept.ASEID.isASEID(request.params.aseid))
|
|
52
|
+
throw new AHttpServer_error.A_HttpServerError({
|
|
53
|
+
status: 400,
|
|
54
|
+
description: `Invalid ASEID: "${request.params.aseid}"`
|
|
55
|
+
});
|
|
78
56
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
79
|
-
if (constructor)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
57
|
+
if (!constructor)
|
|
58
|
+
throw new AHttpServer_error.A_HttpServerError({
|
|
59
|
+
status: 404,
|
|
60
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`
|
|
61
|
+
});
|
|
62
|
+
const entity = new constructor(request.body);
|
|
63
|
+
scope.register(entity);
|
|
64
|
+
await entity.save();
|
|
84
65
|
}
|
|
85
66
|
async delete(request, response, scope) {
|
|
86
|
-
if (!aConcept.ASEID.isASEID(request.params.aseid))
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
67
|
+
if (!aConcept.ASEID.isASEID(request.params.aseid))
|
|
68
|
+
throw new AHttpServer_error.A_HttpServerError({
|
|
69
|
+
status: 400,
|
|
70
|
+
description: `Invalid ASEID: "${request.params.aseid}"`
|
|
71
|
+
});
|
|
90
72
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
91
|
-
if (constructor)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
73
|
+
if (!constructor)
|
|
74
|
+
throw new AHttpServer_error.A_HttpServerError({
|
|
75
|
+
status: 404,
|
|
76
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`
|
|
77
|
+
});
|
|
78
|
+
const entity = new constructor(request.params.aseid);
|
|
79
|
+
scope.register(entity);
|
|
80
|
+
await entity.destroy();
|
|
96
81
|
}
|
|
97
82
|
async callEntity(request, response, scope) {
|
|
98
|
-
if (!aConcept.ASEID.isASEID(request.params.aseid))
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
83
|
+
if (!aConcept.ASEID.isASEID(request.params.aseid))
|
|
84
|
+
throw new AHttpServer_error.A_HttpServerError({
|
|
85
|
+
status: 400,
|
|
86
|
+
description: `Invalid ASEID: "${request.params.aseid}"`
|
|
87
|
+
});
|
|
102
88
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
103
|
-
if (!constructor)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
89
|
+
if (!constructor)
|
|
90
|
+
throw new AHttpServer_error.A_HttpServerError({
|
|
91
|
+
status: 404,
|
|
92
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`
|
|
93
|
+
});
|
|
107
94
|
const meta = aConcept.A_Context.meta(constructor);
|
|
108
95
|
const targetFeature = meta.features().find((f) => f.name === `${constructor.name}.${request.params.action}`);
|
|
109
|
-
if (!targetFeature)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
96
|
+
if (!targetFeature)
|
|
97
|
+
throw new AHttpServer_error.A_HttpServerError({
|
|
98
|
+
status: 404,
|
|
99
|
+
description: `Feature "${request.params.action}" not found on entity`
|
|
100
|
+
});
|
|
113
101
|
const entity = new constructor(request.params.aseid);
|
|
114
102
|
scope.register(entity);
|
|
115
103
|
await entity.load(scope);
|
|
@@ -119,17 +107,6 @@ class A_EntityController extends aConcept.A_Component {
|
|
|
119
107
|
response.add("type", entity.aseid.entity);
|
|
120
108
|
}
|
|
121
109
|
}
|
|
122
|
-
__decorateClass([
|
|
123
|
-
AServerRouter_component.A_ServerRouter.Get({
|
|
124
|
-
path: "/:type",
|
|
125
|
-
version: "v1",
|
|
126
|
-
prefix: "a-list"
|
|
127
|
-
}),
|
|
128
|
-
__decorateParam(0, aConcept.A_Inject(ARequest_entity.A_Request)),
|
|
129
|
-
__decorateParam(1, aConcept.A_Inject(AResponse_entity.A_Response)),
|
|
130
|
-
__decorateParam(2, aConcept.A_Inject(aConcept.A_Scope)),
|
|
131
|
-
__decorateParam(3, aConcept.A_Inject(aConfig.A_Config))
|
|
132
|
-
], A_EntityController.prototype, "list");
|
|
133
110
|
__decorateClass([
|
|
134
111
|
aConcept.A_Feature.Define({
|
|
135
112
|
name: "getEntity",
|
|
@@ -151,7 +128,8 @@ __decorateClass([
|
|
|
151
128
|
prefix: "a-entity"
|
|
152
129
|
}),
|
|
153
130
|
__decorateParam(0, aConcept.A_Inject(ARequest_entity.A_Request)),
|
|
154
|
-
__decorateParam(1, aConcept.A_Inject(
|
|
131
|
+
__decorateParam(1, aConcept.A_Inject(AResponse_entity.A_Response)),
|
|
132
|
+
__decorateParam(2, aConcept.A_Inject(aConcept.A_Scope))
|
|
155
133
|
], A_EntityController.prototype, "create");
|
|
156
134
|
__decorateClass([
|
|
157
135
|
AServerRouter_component.A_ServerRouter.Put({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/controllers/A-EntityController/A-EntityController.component.ts"],"names":["A_Component","A_ServerEntityList","A_ServerListQueryFilter","A_Scope","ASEID","A_ServerError","A_Context","A_ServerRouter","A_Request","A_Response","A_Config","A_Feature"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAWO,MAAM,2BAA2BA,oBAAA,CAAY;AAAA,EAUhD,MAAM,IAAA,CACmB,OAAA,EACC,QAAA,EACH,OACC,MAAA,EACtB;AAEE,IAAA,MAAM,WAAA,GAAc,KAAA,CAAM,kBAAA,CAAmB,OAAA,CAAQ,OAAO,IAAI,CAAA;AAEhE,IAAA,IAAI,WAAA,EAAa;AAEb,MAAA,MAAM,UAAA,GAAa,IAAIC,qCAAA,CAAmB;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,QAAA,CAAA;AAgCA,eAAA,CAAA;AAAA,EALLI,uCAAe,IAAA,CAAK;AAAA,IACjB,IAAA,EAAM,iBAAA;AAAA,IACN,OAAA,EAAS,IAAA;AAAA,IACT,MAAA,EAAQ;AAAA,GACX,CAAA;AAAA,EAEI,qCAASC,yBAAS,CAAA,CAAA;AAAA,EAClB,qCAASC,2BAAU,CAAA,CAAA;AAAA,EACnB,qCAASN,gBAAO,CAAA;AAAA,CAAA,EA/LZ,kBAAA,CA4LH,SAAA,EAAA,YAAA,CAAA","file":"A-EntityController.component.js","sourcesContent":["import { A_Component, A_Context, A_Feature, A_Inject, A_Scope, A_TYPES__Entity_Constructor, ASEID } from \"@adaas/a-concept\";\nimport { A_Request } from \"@adaas/a-server/request/A-Request.entity\";\nimport { A_ServerRouter } from \"@adaas/a-server/router/A-ServerRouter.component\";\nimport { A_Response } from \"@adaas/a-server/response/A-Response.entity\";\nimport { A_ServerError } from \"../../lib/A-Server/A-Server.error\";\nimport { A_ServerListQueryFilter } from \"@adaas/a-server/list-query/A-ServerListQueryFilter.context\";\nimport { A_ServerEntityList } from \"@adaas/a-server/entity-list/A-EntityList.entity\";\nimport { A_Config } from \"@adaas/a-utils/a-config\";\n\n\n\nexport class A_EntityController extends A_Component {\n\n // =======================================================\n // ================ Method Definition=====================\n // =======================================================\n @A_ServerRouter.Get({\n path: '/:type',\n version: 'v1',\n prefix: 'a-list'\n })\n async list(\n @A_Inject(A_Request) request: A_Request<any, any, { type: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope,\n @A_Inject(A_Config) config: A_Config<['A_LIST_ITEMS_PER_PAGE', 'A_LIST_PAGE']>\n ) {\n\n const constructor = scope.resolveConstructor(request.params.type);\n\n if (constructor) {\n\n const entityList = new A_ServerEntityList({\n name: request.params.type,\n scope: scope.name,\n constructor\n });\n\n scope.register(entityList);\n\n const queryFilter = new A_ServerListQueryFilter(request.query, {\n itemsPerPage: String(config.get('A_LIST_ITEMS_PER_PAGE') || '10'),\n page: String(config.get('A_LIST_PAGE') || '1')\n });\n\n const queryScope = new A_Scope({\n fragments: [queryFilter]\n }).inherit(scope);\n\n await entityList.load(queryScope);\n\n response.add('items', entityList.items);\n response.add('pagination', entityList.pagination);\n }\n }\n\n\n @A_Feature.Define({\n name: 'getEntity',\n invoke: false\n })\n @A_ServerRouter.Get({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async load(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n // Check if the scope has a manifest and if the entity is allowed to save\n // if (\n // scope.has(A_Manifest) && !scope.resolve(A_Manifest)\n // .isAllowed(entity.constructor, 'save')\n // .for(entity.constructor as A_TYPES__Entity_Constructor)\n // )\n // return;\n\n\n console.log('Request params:', request.params);\n\n\n if (!ASEID.isASEID(request.params.aseid)) {\n response.add('A_EntityController.load', 'Invalid ASEID');\n return;\n }\n\n\n const aseid = new ASEID(request.params.aseid);\n\n const constructor = scope.resolveConstructor(aseid.entity);\n\n\n if (constructor) {\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.load();\n\n return response.status(200).send(entity.toJSON());\n }\n else\n throw new A_ServerError({\n title: 'Entity Not Found',\n description: `Entity constructor for ASEID ${request.params.aseid} not found`,\n status: 404,\n });\n }\n\n\n\n @A_ServerRouter.Post({\n path: '/',\n version: 'v1',\n prefix: 'a-entity'\n })\n async create(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (constructor) {\n const entity = new constructor(request.body);\n\n scope.register(entity);\n\n await entity.save();\n }\n }\n\n\n\n @A_ServerRouter.Put({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async update(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid)) {\n response.add('A_EntityController.update', 'Invalid ASEID');\n return;\n }\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (constructor) {\n const entity = new constructor(request.body);\n\n scope.register(entity);\n\n await entity.save();\n }\n }\n\n\n @A_ServerRouter.Delete({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async delete(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid)) {\n response.add('A_EntityController.delete', 'Invalid ASEID');\n return;\n }\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (constructor) {\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.destroy();\n }\n }\n\n\n\n // @A_Feature.Define({\n // name: 'callEntity',\n // invoke: false\n // })\n @A_ServerRouter.Post({\n path: '/:aseid/:action',\n version: 'v1',\n prefix: 'a-entity'\n })\n async callEntity(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string, action: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid)) {\n response.add('A_EntityController.callEntity', 'Invalid ASEID');\n return;\n }\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (!constructor) {\n response.add('A_EntityController.callEntity', 'Entity not found');\n return;\n }\n\n const meta = A_Context.meta(constructor);\n\n const targetFeature = meta.features().find(f => f.name === `${constructor.name}.${request.params.action}`);\n\n if (!targetFeature) {\n response.add('A_EntityController.callEntity', 'Feature not found');\n return;\n }\n\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.load(scope);\n\n await entity[targetFeature.handler](scope);\n\n response.add('result', scope.toJSON());\n response.add('entity', entity);\n response.add('type', entity.aseid.entity);\n }\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/controllers/A-EntityController/A-EntityController.component.ts"],"names":["A_Component","ASEID","A_HttpServerError","A_Context","A_Feature","A_ServerRouter","A_Request","A_Response","A_Scope"],"mappings":";;;;;;;;;;;;;;;;;;;AAQO,MAAM,2BAA2BA,oBAAA,CAAY;AAAA,EAehD,MAAM,IAAA,CACmB,OAAA,EACC,QAAA,EACH,KAAA,EACrB;AACE,IAAA,IAAI,CAACC,cAAA,CAAM,OAAA,CAAQ,OAAA,CAAQ,OAAO,KAAK,CAAA;AACnC,MAAA,MAAM,IAAIC,mCAAA,CAAkB;AAAA,QACxB,MAAA,EAAQ,GAAA;AAAA,QACR,WAAA,EAAa,CAAA,gBAAA,EAAmB,OAAA,CAAQ,MAAA,CAAO,KAAK,CAAA,CAAA;AAAA,OACvD,CAAA;AAEL,IAAA,MAAM,KAAA,GAAQ,IAAID,cAAA,CAAM,OAAA,CAAQ,OAAO,KAAK,CAAA;AAE5C,IAAA,MAAM,WAAA,GAAc,KAAA,CAAM,kBAAA,CAAmB,KAAA,CAAM,MAAM,CAAA;AAEzD,IAAA,IAAI,CAAC,WAAA;AACD,MAAA,MAAM,IAAIC,mCAAA,CAAkB;AAAA,QACxB,MAAA,EAAQ,GAAA;AAAA,QACR,WAAA,EAAa,CAAA,6BAAA,EAAgC,OAAA,CAAQ,MAAA,CAAO,KAAK,CAAA,UAAA;AAAA,OACpE,CAAA;AAEL,IAAA,MAAM,MAAA,GAAS,IAAI,WAAA,CAAY,OAAA,CAAQ,OAAO,KAAK,CAAA;AAEnD,IAAA,KAAA,CAAM,SAAS,MAAM,CAAA;AAErB,IAAA,MAAM,OAAO,IAAA,EAAK;AAElB,IAAA,OAAO,SAAS,MAAA,CAAO,GAAG,EAAE,IAAA,CAAK,MAAA,CAAO,QAAQ,CAAA;AAAA,EACpD;AAAA,EASA,MAAM,MAAA,CACmB,OAAA,EACC,QAAA,EACH,KAAA,EACrB;AACE,IAAA,MAAM,WA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AAA,QAAA,CAAA;AAqCA,eAAA,CAAA;AAAA,EALLH,uCAAe,IAAA,CAAK;AAAA,IACjB,IAAA,EAAM,iBAAA;AAAA,IACN,OAAA,EAAS,IAAA;AAAA,IACT,MAAA,EAAQ;AAAA,GACX,CAAA;AAAA,EAEI,qCAASC,yBAAS,CAAA,CAAA;AAAA,EAClB,qCAASC,2BAAU,CAAA,CAAA;AAAA,EACnB,qCAASC,gBAAO,CAAA;AAAA,CAAA,EAvJZ,kBAAA,CAoJH,SAAA,EAAA,YAAA,CAAA","file":"A-EntityController.component.js","sourcesContent":["import { A_Component, A_Context, A_Feature, A_Inject, A_Scope, ASEID } from \"@adaas/a-concept\";\nimport { A_Request } from \"@adaas/a-server/request/A-Request.entity\";\nimport { A_ServerRouter } from \"@adaas/a-server/router/A-ServerRouter.component\";\nimport { A_Response } from \"@adaas/a-server/response/A-Response.entity\";\nimport { A_HttpServerError } from \"../../lib/A-Server/A-HttpServer.error\";\n\n\n\nexport class A_EntityController extends A_Component {\n\n // =======================================================\n // ================ Method Definition=====================\n // =======================================================\n\n @A_Feature.Define({\n name: 'getEntity',\n invoke: false\n })\n @A_ServerRouter.Get({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async load(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid))\n throw new A_HttpServerError({\n status: 400,\n description: `Invalid ASEID: \"${request.params.aseid}\"`,\n });\n\n const aseid = new ASEID(request.params.aseid);\n\n const constructor = scope.resolveConstructor(aseid.entity);\n\n if (!constructor)\n throw new A_HttpServerError({\n status: 404,\n description: `Entity constructor for ASEID ${request.params.aseid} not found`,\n });\n\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.load();\n\n return response.status(200).send(entity.toJSON());\n }\n\n\n\n @A_ServerRouter.Post({\n path: '/',\n version: 'v1',\n prefix: 'a-entity'\n })\n async create(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (!constructor)\n throw new A_HttpServerError({\n status: 404,\n description: `Entity type \"${request.params.aseid}\" not registered`,\n });\n\n const entity = new constructor(request.body);\n\n scope.register(entity);\n\n await entity.save();\n }\n\n\n\n @A_ServerRouter.Put({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async update(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid))\n throw new A_HttpServerError({\n status: 400,\n description: `Invalid ASEID: \"${request.params.aseid}\"`,\n });\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (!constructor)\n throw new A_HttpServerError({\n status: 404,\n description: `Entity constructor for ASEID ${request.params.aseid} not found`,\n });\n\n const entity = new constructor(request.body);\n\n scope.register(entity);\n\n await entity.save();\n }\n\n\n @A_ServerRouter.Delete({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async delete(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid))\n throw new A_HttpServerError({\n status: 400,\n description: `Invalid ASEID: \"${request.params.aseid}\"`,\n });\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (!constructor)\n throw new A_HttpServerError({\n status: 404,\n description: `Entity constructor for ASEID ${request.params.aseid} not found`,\n });\n\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.destroy();\n }\n\n\n\n // @A_Feature.Define({\n // name: 'callEntity',\n // invoke: false\n // })\n @A_ServerRouter.Post({\n path: '/:aseid/:action',\n version: 'v1',\n prefix: 'a-entity'\n })\n async callEntity(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string, action: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid))\n throw new A_HttpServerError({\n status: 400,\n description: `Invalid ASEID: \"${request.params.aseid}\"`,\n });\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (!constructor)\n throw new A_HttpServerError({\n status: 404,\n description: `Entity constructor for ASEID ${request.params.aseid} not found`,\n });\n\n const meta = A_Context.meta(constructor);\n\n const targetFeature = meta.features().find(f => f.name === `${constructor.name}.${request.params.action}`);\n\n if (!targetFeature)\n throw new A_HttpServerError({\n status: 404,\n description: `Feature \"${request.params.action}\" not found on entity`,\n });\n\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.load(scope);\n\n await entity[targetFeature.handler](scope);\n\n response.add('result', scope.toJSON());\n response.add('entity', entity);\n response.add('type', entity.aseid.entity);\n }\n}"]}
|
|
@@ -1,103 +1,91 @@
|
|
|
1
1
|
import { __decorateClass, __decorateParam } from '../../chunk-EQQGB2QZ.mjs';
|
|
2
|
-
import { A_Inject, A_Scope,
|
|
2
|
+
import { A_Feature, A_Inject, A_Scope, A_Component, ASEID, A_Context } from '@adaas/a-concept';
|
|
3
3
|
import { A_Request } from '@adaas/a-server/request/A-Request.entity';
|
|
4
4
|
import { A_ServerRouter } from '@adaas/a-server/router/A-ServerRouter.component';
|
|
5
5
|
import { A_Response } from '@adaas/a-server/response/A-Response.entity';
|
|
6
|
-
import {
|
|
7
|
-
import { A_ServerListQueryFilter } from '@adaas/a-server/list-query/A-ServerListQueryFilter.context';
|
|
8
|
-
import { A_ServerEntityList } from '@adaas/a-server/entity-list/A-EntityList.entity';
|
|
9
|
-
import { A_Config } from '@adaas/a-utils/a-config';
|
|
6
|
+
import { A_HttpServerError } from '../../lib/A-Server/A-HttpServer.error';
|
|
10
7
|
|
|
11
8
|
class A_EntityController extends A_Component {
|
|
12
|
-
async list(request, response, scope, config) {
|
|
13
|
-
const constructor = scope.resolveConstructor(request.params.type);
|
|
14
|
-
if (constructor) {
|
|
15
|
-
const entityList = new A_ServerEntityList({
|
|
16
|
-
name: request.params.type,
|
|
17
|
-
scope: scope.name,
|
|
18
|
-
constructor
|
|
19
|
-
});
|
|
20
|
-
scope.register(entityList);
|
|
21
|
-
const queryFilter = new A_ServerListQueryFilter(request.query, {
|
|
22
|
-
itemsPerPage: String(config.get("A_LIST_ITEMS_PER_PAGE") || "10"),
|
|
23
|
-
page: String(config.get("A_LIST_PAGE") || "1")
|
|
24
|
-
});
|
|
25
|
-
const queryScope = new A_Scope({
|
|
26
|
-
fragments: [queryFilter]
|
|
27
|
-
}).inherit(scope);
|
|
28
|
-
await entityList.load(queryScope);
|
|
29
|
-
response.add("items", entityList.items);
|
|
30
|
-
response.add("pagination", entityList.pagination);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
9
|
async load(request, response, scope) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
10
|
+
if (!ASEID.isASEID(request.params.aseid))
|
|
11
|
+
throw new A_HttpServerError({
|
|
12
|
+
status: 400,
|
|
13
|
+
description: `Invalid ASEID: "${request.params.aseid}"`
|
|
14
|
+
});
|
|
39
15
|
const aseid = new ASEID(request.params.aseid);
|
|
40
16
|
const constructor = scope.resolveConstructor(aseid.entity);
|
|
41
|
-
if (constructor)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return response.status(200).send(entity.toJSON());
|
|
46
|
-
} else
|
|
47
|
-
throw new A_ServerError({
|
|
48
|
-
title: "Entity Not Found",
|
|
49
|
-
description: `Entity constructor for ASEID ${request.params.aseid} not found`,
|
|
50
|
-
status: 404
|
|
17
|
+
if (!constructor)
|
|
18
|
+
throw new A_HttpServerError({
|
|
19
|
+
status: 404,
|
|
20
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`
|
|
51
21
|
});
|
|
22
|
+
const entity = new constructor(request.params.aseid);
|
|
23
|
+
scope.register(entity);
|
|
24
|
+
await entity.load();
|
|
25
|
+
return response.status(200).send(entity.toJSON());
|
|
52
26
|
}
|
|
53
|
-
async create(request, scope) {
|
|
27
|
+
async create(request, response, scope) {
|
|
54
28
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
55
|
-
if (constructor)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
29
|
+
if (!constructor)
|
|
30
|
+
throw new A_HttpServerError({
|
|
31
|
+
status: 404,
|
|
32
|
+
description: `Entity type "${request.params.aseid}" not registered`
|
|
33
|
+
});
|
|
34
|
+
const entity = new constructor(request.body);
|
|
35
|
+
scope.register(entity);
|
|
36
|
+
await entity.save();
|
|
60
37
|
}
|
|
61
38
|
async update(request, response, scope) {
|
|
62
|
-
if (!ASEID.isASEID(request.params.aseid))
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
39
|
+
if (!ASEID.isASEID(request.params.aseid))
|
|
40
|
+
throw new A_HttpServerError({
|
|
41
|
+
status: 400,
|
|
42
|
+
description: `Invalid ASEID: "${request.params.aseid}"`
|
|
43
|
+
});
|
|
66
44
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
67
|
-
if (constructor)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
45
|
+
if (!constructor)
|
|
46
|
+
throw new A_HttpServerError({
|
|
47
|
+
status: 404,
|
|
48
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`
|
|
49
|
+
});
|
|
50
|
+
const entity = new constructor(request.body);
|
|
51
|
+
scope.register(entity);
|
|
52
|
+
await entity.save();
|
|
72
53
|
}
|
|
73
54
|
async delete(request, response, scope) {
|
|
74
|
-
if (!ASEID.isASEID(request.params.aseid))
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
55
|
+
if (!ASEID.isASEID(request.params.aseid))
|
|
56
|
+
throw new A_HttpServerError({
|
|
57
|
+
status: 400,
|
|
58
|
+
description: `Invalid ASEID: "${request.params.aseid}"`
|
|
59
|
+
});
|
|
78
60
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
79
|
-
if (constructor)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
61
|
+
if (!constructor)
|
|
62
|
+
throw new A_HttpServerError({
|
|
63
|
+
status: 404,
|
|
64
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`
|
|
65
|
+
});
|
|
66
|
+
const entity = new constructor(request.params.aseid);
|
|
67
|
+
scope.register(entity);
|
|
68
|
+
await entity.destroy();
|
|
84
69
|
}
|
|
85
70
|
async callEntity(request, response, scope) {
|
|
86
|
-
if (!ASEID.isASEID(request.params.aseid))
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
71
|
+
if (!ASEID.isASEID(request.params.aseid))
|
|
72
|
+
throw new A_HttpServerError({
|
|
73
|
+
status: 400,
|
|
74
|
+
description: `Invalid ASEID: "${request.params.aseid}"`
|
|
75
|
+
});
|
|
90
76
|
const constructor = scope.resolveConstructor(request.params.aseid);
|
|
91
|
-
if (!constructor)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
77
|
+
if (!constructor)
|
|
78
|
+
throw new A_HttpServerError({
|
|
79
|
+
status: 404,
|
|
80
|
+
description: `Entity constructor for ASEID ${request.params.aseid} not found`
|
|
81
|
+
});
|
|
95
82
|
const meta = A_Context.meta(constructor);
|
|
96
83
|
const targetFeature = meta.features().find((f) => f.name === `${constructor.name}.${request.params.action}`);
|
|
97
|
-
if (!targetFeature)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
84
|
+
if (!targetFeature)
|
|
85
|
+
throw new A_HttpServerError({
|
|
86
|
+
status: 404,
|
|
87
|
+
description: `Feature "${request.params.action}" not found on entity`
|
|
88
|
+
});
|
|
101
89
|
const entity = new constructor(request.params.aseid);
|
|
102
90
|
scope.register(entity);
|
|
103
91
|
await entity.load(scope);
|
|
@@ -107,17 +95,6 @@ class A_EntityController extends A_Component {
|
|
|
107
95
|
response.add("type", entity.aseid.entity);
|
|
108
96
|
}
|
|
109
97
|
}
|
|
110
|
-
__decorateClass([
|
|
111
|
-
A_ServerRouter.Get({
|
|
112
|
-
path: "/:type",
|
|
113
|
-
version: "v1",
|
|
114
|
-
prefix: "a-list"
|
|
115
|
-
}),
|
|
116
|
-
__decorateParam(0, A_Inject(A_Request)),
|
|
117
|
-
__decorateParam(1, A_Inject(A_Response)),
|
|
118
|
-
__decorateParam(2, A_Inject(A_Scope)),
|
|
119
|
-
__decorateParam(3, A_Inject(A_Config))
|
|
120
|
-
], A_EntityController.prototype, "list", 1);
|
|
121
98
|
__decorateClass([
|
|
122
99
|
A_Feature.Define({
|
|
123
100
|
name: "getEntity",
|
|
@@ -139,7 +116,8 @@ __decorateClass([
|
|
|
139
116
|
prefix: "a-entity"
|
|
140
117
|
}),
|
|
141
118
|
__decorateParam(0, A_Inject(A_Request)),
|
|
142
|
-
__decorateParam(1, A_Inject(
|
|
119
|
+
__decorateParam(1, A_Inject(A_Response)),
|
|
120
|
+
__decorateParam(2, A_Inject(A_Scope))
|
|
143
121
|
], A_EntityController.prototype, "create", 1);
|
|
144
122
|
__decorateClass([
|
|
145
123
|
A_ServerRouter.Put({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/controllers/A-EntityController/A-EntityController.component.ts"],"names":[],"mappings":";;;;;;;;;;AAWO,MAAM,2BAA2B,WAAA,CAAY;AAAA,EAUhD,MAAM,IAAA,CACmB,OAAA,EACC,QAAA,EACH,OACC,MAAA,EACtB;AAEE,IAAA,MAAM,WAAA,GAAc,KAAA,CAAM,kBAAA,CAAmB,OAAA,CAAQ,OAAO,IAAI,CAAA;AAEhE,IAAA,IAAI,WAAA,EAAa;AAEb,MAAA,MAAM,UAAA,GAAa,IAAI,kBAAA,CAAmB;AAAA,QACtC,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EAAA,CAAA,CAAA;AAgCA,eAAA,CAAA;AAAA,EALL,eAAe,IAAA,CAAK;AAAA,IACjB,IAAA,EAAM,iBAAA;AAAA,IACN,OAAA,EAAS,IAAA;AAAA,IACT,MAAA,EAAQ;AAAA,GACX,CAAA;AAAA,EAEI,4BAAS,SAAS,CAAA,CAAA;AAAA,EAClB,4BAAS,UAAU,CAAA,CAAA;AAAA,EACnB,4BAAS,OAAO,CAAA;AAAA,CAAA,EA/LZ,kBAAA,CA4LH,SAAA,EAAA,YAAA,EAAA,CAAA,CAAA","file":"A-EntityController.component.mjs","sourcesContent":["import { A_Component, A_Context, A_Feature, A_Inject, A_Scope, A_TYPES__Entity_Constructor, ASEID } from \"@adaas/a-concept\";\nimport { A_Request } from \"@adaas/a-server/request/A-Request.entity\";\nimport { A_ServerRouter } from \"@adaas/a-server/router/A-ServerRouter.component\";\nimport { A_Response } from \"@adaas/a-server/response/A-Response.entity\";\nimport { A_ServerError } from \"../../lib/A-Server/A-Server.error\";\nimport { A_ServerListQueryFilter } from \"@adaas/a-server/list-query/A-ServerListQueryFilter.context\";\nimport { A_ServerEntityList } from \"@adaas/a-server/entity-list/A-EntityList.entity\";\nimport { A_Config } from \"@adaas/a-utils/a-config\";\n\n\n\nexport class A_EntityController extends A_Component {\n\n // =======================================================\n // ================ Method Definition=====================\n // =======================================================\n @A_ServerRouter.Get({\n path: '/:type',\n version: 'v1',\n prefix: 'a-list'\n })\n async list(\n @A_Inject(A_Request) request: A_Request<any, any, { type: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope,\n @A_Inject(A_Config) config: A_Config<['A_LIST_ITEMS_PER_PAGE', 'A_LIST_PAGE']>\n ) {\n\n const constructor = scope.resolveConstructor(request.params.type);\n\n if (constructor) {\n\n const entityList = new A_ServerEntityList({\n name: request.params.type,\n scope: scope.name,\n constructor\n });\n\n scope.register(entityList);\n\n const queryFilter = new A_ServerListQueryFilter(request.query, {\n itemsPerPage: String(config.get('A_LIST_ITEMS_PER_PAGE') || '10'),\n page: String(config.get('A_LIST_PAGE') || '1')\n });\n\n const queryScope = new A_Scope({\n fragments: [queryFilter]\n }).inherit(scope);\n\n await entityList.load(queryScope);\n\n response.add('items', entityList.items);\n response.add('pagination', entityList.pagination);\n }\n }\n\n\n @A_Feature.Define({\n name: 'getEntity',\n invoke: false\n })\n @A_ServerRouter.Get({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async load(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n // Check if the scope has a manifest and if the entity is allowed to save\n // if (\n // scope.has(A_Manifest) && !scope.resolve(A_Manifest)\n // .isAllowed(entity.constructor, 'save')\n // .for(entity.constructor as A_TYPES__Entity_Constructor)\n // )\n // return;\n\n\n console.log('Request params:', request.params);\n\n\n if (!ASEID.isASEID(request.params.aseid)) {\n response.add('A_EntityController.load', 'Invalid ASEID');\n return;\n }\n\n\n const aseid = new ASEID(request.params.aseid);\n\n const constructor = scope.resolveConstructor(aseid.entity);\n\n\n if (constructor) {\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.load();\n\n return response.status(200).send(entity.toJSON());\n }\n else\n throw new A_ServerError({\n title: 'Entity Not Found',\n description: `Entity constructor for ASEID ${request.params.aseid} not found`,\n status: 404,\n });\n }\n\n\n\n @A_ServerRouter.Post({\n path: '/',\n version: 'v1',\n prefix: 'a-entity'\n })\n async create(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (constructor) {\n const entity = new constructor(request.body);\n\n scope.register(entity);\n\n await entity.save();\n }\n }\n\n\n\n @A_ServerRouter.Put({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async update(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid)) {\n response.add('A_EntityController.update', 'Invalid ASEID');\n return;\n }\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (constructor) {\n const entity = new constructor(request.body);\n\n scope.register(entity);\n\n await entity.save();\n }\n }\n\n\n @A_ServerRouter.Delete({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async delete(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid)) {\n response.add('A_EntityController.delete', 'Invalid ASEID');\n return;\n }\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (constructor) {\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.destroy();\n }\n }\n\n\n\n // @A_Feature.Define({\n // name: 'callEntity',\n // invoke: false\n // })\n @A_ServerRouter.Post({\n path: '/:aseid/:action',\n version: 'v1',\n prefix: 'a-entity'\n })\n async callEntity(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string, action: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid)) {\n response.add('A_EntityController.callEntity', 'Invalid ASEID');\n return;\n }\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (!constructor) {\n response.add('A_EntityController.callEntity', 'Entity not found');\n return;\n }\n\n const meta = A_Context.meta(constructor);\n\n const targetFeature = meta.features().find(f => f.name === `${constructor.name}.${request.params.action}`);\n\n if (!targetFeature) {\n response.add('A_EntityController.callEntity', 'Feature not found');\n return;\n }\n\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.load(scope);\n\n await entity[targetFeature.handler](scope);\n\n response.add('result', scope.toJSON());\n response.add('entity', entity);\n response.add('type', ent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AK;AAAA,IACjB,IAAA,EAAM,iBAAA;AAAA,IACN,OAAA,EAAS,IAAA;AAAA,IACT,MAAA,EAAQ;AAAA,GACX,CAAA;AAAA,EAEI,4BAAS,SAAS,CAAA,CAAA;AAAA,EAClB,4BAAS,UAAU,CAAA,CAAA;AAAA,EACnB,4BAAS,OAAO,CAAA;AAAA,CAAA,EAvJZ,kBAAA,CAoJH,SAAA,EAAA,YAAA,EAAA,CAAA,CAAA","file":"A-EntityController.component.mjs","sourcesContent":["import { A_Component, A_Context, A_Feature, A_Inject, A_Scope, ASEID } from \"@adaas/a-concept\";\nimport { A_Request } from \"@adaas/a-server/request/A-Request.entity\";\nimport { A_ServerRouter } from \"@adaas/a-server/router/A-ServerRouter.component\";\nimport { A_Response } from \"@adaas/a-server/response/A-Response.entity\";\nimport { A_HttpServerError } from \"../../lib/A-Server/A-HttpServer.error\";\n\n\n\nexport class A_EntityController extends A_Component {\n\n // =======================================================\n // ================ Method Definition=====================\n // =======================================================\n\n @A_Feature.Define({\n name: 'getEntity',\n invoke: false\n })\n @A_ServerRouter.Get({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async load(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid))\n throw new A_HttpServerError({\n status: 400,\n description: `Invalid ASEID: \"${request.params.aseid}\"`,\n });\n\n const aseid = new ASEID(request.params.aseid);\n\n const constructor = scope.resolveConstructor(aseid.entity);\n\n if (!constructor)\n throw new A_HttpServerError({\n status: 404,\n description: `Entity constructor for ASEID ${request.params.aseid} not found`,\n });\n\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.load();\n\n return response.status(200).send(entity.toJSON());\n }\n\n\n\n @A_ServerRouter.Post({\n path: '/',\n version: 'v1',\n prefix: 'a-entity'\n })\n async create(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (!constructor)\n throw new A_HttpServerError({\n status: 404,\n description: `Entity type \"${request.params.aseid}\" not registered`,\n });\n\n const entity = new constructor(request.body);\n\n scope.register(entity);\n\n await entity.save();\n }\n\n\n\n @A_ServerRouter.Put({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async update(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid))\n throw new A_HttpServerError({\n status: 400,\n description: `Invalid ASEID: \"${request.params.aseid}\"`,\n });\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (!constructor)\n throw new A_HttpServerError({\n status: 404,\n description: `Entity constructor for ASEID ${request.params.aseid} not found`,\n });\n\n const entity = new constructor(request.body);\n\n scope.register(entity);\n\n await entity.save();\n }\n\n\n @A_ServerRouter.Delete({\n path: '/:aseid',\n version: 'v1',\n prefix: 'a-entity'\n })\n async delete(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid))\n throw new A_HttpServerError({\n status: 400,\n description: `Invalid ASEID: \"${request.params.aseid}\"`,\n });\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (!constructor)\n throw new A_HttpServerError({\n status: 404,\n description: `Entity constructor for ASEID ${request.params.aseid} not found`,\n });\n\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.destroy();\n }\n\n\n\n // @A_Feature.Define({\n // name: 'callEntity',\n // invoke: false\n // })\n @A_ServerRouter.Post({\n path: '/:aseid/:action',\n version: 'v1',\n prefix: 'a-entity'\n })\n async callEntity(\n @A_Inject(A_Request) request: A_Request<any, any, { aseid: string, action: string }>,\n @A_Inject(A_Response) response: A_Response,\n @A_Inject(A_Scope) scope: A_Scope\n ) {\n if (!ASEID.isASEID(request.params.aseid))\n throw new A_HttpServerError({\n status: 400,\n description: `Invalid ASEID: \"${request.params.aseid}\"`,\n });\n\n const constructor = scope.resolveConstructor(request.params.aseid);\n\n if (!constructor)\n throw new A_HttpServerError({\n status: 404,\n description: `Entity constructor for ASEID ${request.params.aseid} not found`,\n });\n\n const meta = A_Context.meta(constructor);\n\n const targetFeature = meta.features().find(f => f.name === `${constructor.name}.${request.params.action}`);\n\n if (!targetFeature)\n throw new A_HttpServerError({\n status: 404,\n description: `Feature \"${request.params.action}\" not found on entity`,\n });\n\n const entity = new constructor(request.params.aseid);\n\n scope.register(entity);\n\n await entity.load(scope);\n\n await entity[targetFeature.handler](scope);\n\n response.add('result', scope.toJSON());\n response.add('entity', entity);\n response.add('type', entity.aseid.entity);\n }\n}"]}
|