ismx-nexo-node-app 0.3.28 → 0.3.29
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.
|
@@ -2,22 +2,22 @@ import { HttpRequest, HttpResponse } from "./Service";
|
|
|
2
2
|
import ServiceRestFormal from "./ServiceRestFormal";
|
|
3
3
|
import { Pagination } from "../repository/RepositoryDatabase";
|
|
4
4
|
import RepositoryDatabase from "../repository/RepositoryDatabase";
|
|
5
|
-
export default class ServiceRestFormalTemplate<
|
|
5
|
+
export default class ServiceRestFormalTemplate<Model = any> {
|
|
6
6
|
readonly resource: string;
|
|
7
7
|
readonly tableName: string;
|
|
8
8
|
readonly database: RepositoryDatabase;
|
|
9
|
-
readonly get: ServiceRestFormal<
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
12
|
-
readonly
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
18
|
-
readonly page: ServiceRestFormal<
|
|
19
|
-
readonly map: ServiceRestFormal<
|
|
20
|
-
[key: string]:
|
|
9
|
+
readonly get: ServiceRestFormal<any, Model>;
|
|
10
|
+
readonly getList: ServiceRestFormal<any, Model[]>;
|
|
11
|
+
readonly post: ServiceRestFormal<Model, Model>;
|
|
12
|
+
readonly postList: ServiceRestFormal<Model[], Model[]>;
|
|
13
|
+
readonly put: ServiceRestFormal<Model, Model>;
|
|
14
|
+
readonly del: ServiceRestFormal<any, Model>;
|
|
15
|
+
readonly select: ServiceRestFormal<any, string[]>;
|
|
16
|
+
readonly exist: ServiceRestFormal<any, Boolean>;
|
|
17
|
+
readonly count: ServiceRestFormal<any, Number>;
|
|
18
|
+
readonly page: ServiceRestFormal<any, Pagination<Model>>;
|
|
19
|
+
readonly map: ServiceRestFormal<any, {
|
|
20
|
+
[key: string]: Model;
|
|
21
21
|
}>;
|
|
22
22
|
constructor(resource: string, database: RepositoryDatabase, tableName: string);
|
|
23
23
|
protected indexer: string;
|
|
@@ -26,19 +26,19 @@ export default class ServiceRestFormalTemplate<Req = any, Res = any> {
|
|
|
26
26
|
maxResults: number;
|
|
27
27
|
pageNumber: number;
|
|
28
28
|
};
|
|
29
|
-
protected serveGet(request: HttpRequest
|
|
30
|
-
protected serveGetList(request: HttpRequest
|
|
31
|
-
protected servePostList(request: HttpRequest<
|
|
32
|
-
protected servePage(request: HttpRequest
|
|
33
|
-
protected serveMap(request: HttpRequest
|
|
34
|
-
[key: string]:
|
|
29
|
+
protected serveGet(request: HttpRequest): Promise<HttpResponse<Model>>;
|
|
30
|
+
protected serveGetList(request: HttpRequest): Promise<HttpResponse<Model[]>>;
|
|
31
|
+
protected servePostList(request: HttpRequest<Model[]>): Promise<HttpResponse<Model[]>>;
|
|
32
|
+
protected servePage(request: HttpRequest): Promise<HttpResponse<Pagination<Model>>>;
|
|
33
|
+
protected serveMap(request: HttpRequest): Promise<HttpResponse<{
|
|
34
|
+
[key: string]: Model;
|
|
35
35
|
}>>;
|
|
36
|
-
protected serveSelect(request: HttpRequest
|
|
37
|
-
protected serveExist(request: HttpRequest
|
|
38
|
-
protected serveCount(request: HttpRequest
|
|
39
|
-
protected servePost(request: HttpRequest<
|
|
40
|
-
protected servePut(request: HttpRequest<
|
|
41
|
-
protected serveDel(request: HttpRequest
|
|
36
|
+
protected serveSelect(request: HttpRequest): Promise<HttpResponse<string[]>>;
|
|
37
|
+
protected serveExist(request: HttpRequest): Promise<HttpResponse<Boolean>>;
|
|
38
|
+
protected serveCount(request: HttpRequest): Promise<HttpResponse<Number>>;
|
|
39
|
+
protected servePost(request: HttpRequest<Model>): Promise<HttpResponse<Model>>;
|
|
40
|
+
protected servePut(request: HttpRequest<Model>): Promise<HttpResponse<Model>>;
|
|
41
|
+
protected serveDel(request: HttpRequest): Promise<HttpResponse<Model>>;
|
|
42
42
|
protected readonly unwrap: typeof ServiceRestFormal.unwrap;
|
|
43
43
|
protected readonly fullSelect: typeof ServiceRestFormal.fullSelect;
|
|
44
44
|
}
|
package/package.json
CHANGED
|
@@ -3,25 +3,24 @@ import ServiceRestFormal from "./ServiceRestFormal";
|
|
|
3
3
|
import {Pagination} from "../repository/RepositoryDatabase";
|
|
4
4
|
import RepositoryDatabase from "../repository/RepositoryDatabase";
|
|
5
5
|
|
|
6
|
-
export default class ServiceRestFormalTemplate<
|
|
6
|
+
export default class ServiceRestFormalTemplate<Model=any>
|
|
7
7
|
{
|
|
8
8
|
readonly resource: string;
|
|
9
9
|
readonly tableName: string;
|
|
10
10
|
readonly database!: RepositoryDatabase;
|
|
11
11
|
|
|
12
|
-
readonly get!: ServiceRestFormal<
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
12
|
+
readonly get!: ServiceRestFormal<any, Model>;
|
|
13
|
+
readonly getList!: ServiceRestFormal<any, Model[]>;
|
|
14
|
+
readonly post!: ServiceRestFormal<Model, Model>;
|
|
15
|
+
readonly postList!: ServiceRestFormal<Model[], Model[]>;
|
|
16
|
+
readonly put!: ServiceRestFormal<Model, Model>;
|
|
17
|
+
readonly del!: ServiceRestFormal<any, Model>;
|
|
18
18
|
|
|
19
|
-
readonly
|
|
20
|
-
readonly
|
|
21
|
-
|
|
22
|
-
readonly
|
|
23
|
-
readonly
|
|
24
|
-
readonly map!: ServiceRestFormal<Req, { [key:string]: Res }>;
|
|
19
|
+
readonly select!: ServiceRestFormal<any, string[]>;
|
|
20
|
+
readonly exist!: ServiceRestFormal<any, Boolean>;
|
|
21
|
+
readonly count!: ServiceRestFormal<any, Number>;
|
|
22
|
+
readonly page!: ServiceRestFormal<any, Pagination<Model>>;
|
|
23
|
+
readonly map!: ServiceRestFormal<any, { [key:string]: Model }>;
|
|
25
24
|
|
|
26
25
|
constructor(resource: string, database: RepositoryDatabase, tableName: string) {
|
|
27
26
|
this.resource = resource;
|
|
@@ -79,31 +78,31 @@ export default class ServiceRestFormalTemplate<Req=any, Res=any>
|
|
|
79
78
|
return { maxResults, pageNumber }
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
protected async serveGet(request: HttpRequest
|
|
81
|
+
protected async serveGet(request: HttpRequest): Promise<HttpResponse<Model>> {
|
|
83
82
|
let id = this.getFormalId(request);
|
|
84
|
-
let result = await this.database.one<
|
|
83
|
+
let result = await this.database.one<Model>(this.tableName, id);
|
|
85
84
|
return HttpResponse.ok(result);
|
|
86
85
|
}
|
|
87
86
|
|
|
88
|
-
protected async serveGetList(request: HttpRequest
|
|
89
|
-
return HttpResponse.ok(await this.database.find<
|
|
87
|
+
protected async serveGetList(request: HttpRequest): Promise<HttpResponse<Model[]>> {
|
|
88
|
+
return HttpResponse.ok(await this.database.find<Model>(this.tableName, { ...request.query }));
|
|
90
89
|
}
|
|
91
90
|
|
|
92
|
-
protected async servePostList(request: HttpRequest<
|
|
91
|
+
protected async servePostList(request: HttpRequest<Model[]>): Promise<HttpResponse<Model[]>> {
|
|
93
92
|
let list = request.body
|
|
94
93
|
if (!(list instanceof Array)) throw new Error("body must be a list");
|
|
95
|
-
return HttpResponse.ok(this.database.addAll(this.tableName, list));
|
|
94
|
+
return HttpResponse.ok(this.database.addAll<Model>(this.tableName, list as any));
|
|
96
95
|
}
|
|
97
96
|
|
|
98
|
-
protected async servePage(request: HttpRequest
|
|
97
|
+
protected async servePage(request: HttpRequest): Promise<HttpResponse<Pagination<Model>>> {
|
|
99
98
|
let { maxResults, pageNumber } = this.getFormalPage(request);
|
|
100
|
-
let results = await this.database.page(this.tableName, "timestamp", maxResults, pageNumber);
|
|
99
|
+
let results = await this.database.page<Model>(this.tableName, "timestamp", maxResults, pageNumber);
|
|
101
100
|
return HttpResponse.ok(results);
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
protected async serveMap(request: HttpRequest
|
|
105
|
-
let results = await this.database.find<
|
|
106
|
-
let response: {[key: string]:
|
|
103
|
+
protected async serveMap(request: HttpRequest): Promise<HttpResponse<{[key: string]: Model}>> {
|
|
104
|
+
let results = await this.database.find<Model>(this.tableName, { ...request.query });
|
|
105
|
+
let response: {[key: string]: Model} = {}; for (let result of results) {
|
|
107
106
|
let key = (result as any)[this.indexer];
|
|
108
107
|
if (!key) return HttpResponse.ok({});
|
|
109
108
|
else response[key] = result;
|
|
@@ -111,31 +110,31 @@ export default class ServiceRestFormalTemplate<Req=any, Res=any>
|
|
|
111
110
|
return HttpResponse.ok(response);
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
protected async serveSelect(request: HttpRequest
|
|
113
|
+
protected async serveSelect(request: HttpRequest): Promise<HttpResponse<string[]>> {
|
|
115
114
|
let selection = request.query?.["selection"] ?? this.indexer;
|
|
116
115
|
delete request.query?.["selection"];
|
|
117
116
|
let select = await this.database.select(this.tableName, selection, { ...request.query });
|
|
118
117
|
return HttpResponse.ok(select);
|
|
119
118
|
}
|
|
120
119
|
|
|
121
|
-
protected async serveExist(request: HttpRequest
|
|
120
|
+
protected async serveExist(request: HttpRequest): Promise<HttpResponse<Boolean>> {
|
|
122
121
|
return HttpResponse.ok((await this.database.count(this.tableName, { ...request.query })) > 0);
|
|
123
122
|
}
|
|
124
123
|
|
|
125
|
-
protected async serveCount(request: HttpRequest
|
|
124
|
+
protected async serveCount(request: HttpRequest): Promise<HttpResponse<Number>> {
|
|
126
125
|
return HttpResponse.ok((await this.database.count(this.tableName, { ...request.query })));
|
|
127
126
|
}
|
|
128
127
|
|
|
129
|
-
protected async servePost(request: HttpRequest<
|
|
130
|
-
let entity = this.database.add(this.tableName, request.body);
|
|
128
|
+
protected async servePost(request: HttpRequest<Model>): Promise<HttpResponse<Model>> {
|
|
129
|
+
let entity = this.database.add<Model>(this.tableName, request.body);
|
|
131
130
|
return HttpResponse.ok(entity);
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
protected async servePut(request: HttpRequest<
|
|
133
|
+
protected async servePut(request: HttpRequest<Model>): Promise<HttpResponse<Model>> {
|
|
135
134
|
return HttpResponse.ok("not implemented yet");
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
protected async serveDel(request: HttpRequest
|
|
137
|
+
protected async serveDel(request: HttpRequest): Promise<HttpResponse<Model>> {
|
|
139
138
|
return HttpResponse.ok("not implemented yet");
|
|
140
139
|
}
|
|
141
140
|
|