core-express 0.1.0 → 0.1.1
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 +1 -1
- package/lib/GenericController.js +224 -131
- package/lib/GenericSearchController.js +58 -37
- package/lib/HealthController.js +16 -58
- package/lib/LoadController.js +71 -46
- package/lib/LoadSearchController.js +113 -41
- package/lib/LogController.js +89 -0
- package/lib/LowCodeController.js +100 -0
- package/lib/SearchController.js +32 -25
- package/lib/access.js +34 -0
- package/lib/client.js +80 -0
- package/lib/edit.js +99 -84
- package/lib/health.js +157 -76
- package/lib/http.js +316 -0
- package/lib/index.js +488 -16
- package/lib/log.js +242 -0
- package/lib/resources.js +106 -6
- package/lib/search.js +766 -160
- package/lib/view.js +48 -34
- package/package.json +8 -4
- package/src/GenericController.ts +217 -106
- package/src/GenericSearchController.ts +38 -21
- package/src/HealthController.ts +9 -9
- package/src/LoadController.ts +70 -40
- package/src/LoadSearchController.ts +114 -21
- package/src/LogController.ts +137 -0
- package/src/LowCodeController.ts +88 -0
- package/src/SearchController.ts +28 -17
- package/src/access.ts +42 -0
- package/src/client.ts +69 -0
- package/src/edit.ts +93 -61
- package/src/health.ts +27 -28
- package/src/http.ts +295 -0
- package/src/index.ts +464 -13
- package/src/log.ts +245 -0
- package/src/metadata.ts +34 -23
- package/src/resources.ts +143 -4
- package/src/search.ts +782 -198
- package/src/view.ts +44 -30
- package/tsconfig.json +1 -0
- package/lib/response.js +0 -12
- package/src/response.ts +0 -10
package/src/view.ts
CHANGED
|
@@ -1,59 +1,73 @@
|
|
|
1
|
-
import {Request} from
|
|
2
|
-
import {Attribute, Attributes} from
|
|
1
|
+
import { Request, Response } from "express"
|
|
2
|
+
import { Attribute, Attributes } from "./metadata"
|
|
3
3
|
|
|
4
|
-
export function
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export function buildAndCheckId<ID>(req: Request, res: Response, keys?: Attribute[]): ID | undefined {
|
|
5
|
+
const id = buildId<ID>(req, keys)
|
|
6
|
+
if (!id) {
|
|
7
|
+
res.status(400).end("invalid parameters")
|
|
8
|
+
return undefined
|
|
9
|
+
}
|
|
10
|
+
return id
|
|
11
|
+
}
|
|
12
|
+
export function buildId<T>(req: Request, attrs?: Attribute[]): T | undefined {
|
|
13
|
+
if (!attrs || attrs.length === 0) {
|
|
14
|
+
const id = req.params["id"] as string
|
|
7
15
|
if (id && id.length > 0) {
|
|
8
|
-
return id as any
|
|
16
|
+
return id as any
|
|
9
17
|
}
|
|
10
|
-
return
|
|
18
|
+
return undefined
|
|
11
19
|
}
|
|
12
20
|
if (attrs && attrs.length === 1) {
|
|
13
|
-
|
|
14
|
-
const
|
|
21
|
+
let id = req.params["id"] as string
|
|
22
|
+
const n = attrs[0].name
|
|
23
|
+
if ((!id || id.length === 0) && n && n.length > 0) {
|
|
24
|
+
id = req.params[n] as string
|
|
25
|
+
}
|
|
15
26
|
if (id && id.length > 0) {
|
|
16
|
-
if (attrs[0].type ===
|
|
27
|
+
if (attrs[0].type === "integer" || attrs[0].type === "number") {
|
|
17
28
|
if (isNaN(id as any)) {
|
|
18
|
-
return
|
|
29
|
+
return undefined
|
|
19
30
|
}
|
|
20
|
-
const v = parseFloat(id)
|
|
21
|
-
return v as any
|
|
31
|
+
const v = parseFloat(id)
|
|
32
|
+
return v as any
|
|
22
33
|
}
|
|
23
|
-
return id as any
|
|
34
|
+
return id as any
|
|
24
35
|
}
|
|
25
36
|
}
|
|
26
|
-
const ids: any = {}
|
|
37
|
+
const ids: any = {}
|
|
27
38
|
for (const attr of attrs) {
|
|
28
|
-
|
|
39
|
+
if (!attr.name) {
|
|
40
|
+
return undefined
|
|
41
|
+
}
|
|
42
|
+
const v = req.params[attr.name]
|
|
29
43
|
if (!v) {
|
|
30
|
-
return
|
|
44
|
+
return undefined
|
|
31
45
|
}
|
|
32
|
-
if (attr.type ===
|
|
46
|
+
if (attr.type === "integer" || attr.type === "number") {
|
|
33
47
|
if (isNaN(v as any)) {
|
|
34
|
-
return
|
|
48
|
+
return undefined
|
|
35
49
|
}
|
|
36
|
-
ids[attr.name] = parseFloat(v)
|
|
50
|
+
ids[attr.name] = parseFloat(v as string)
|
|
37
51
|
} else {
|
|
38
|
-
ids[attr.name] = v
|
|
52
|
+
ids[attr.name] = v
|
|
39
53
|
}
|
|
40
|
-
return ids
|
|
54
|
+
return ids
|
|
41
55
|
}
|
|
42
56
|
}
|
|
43
|
-
export function buildKeys(attrs: Attributes): Attribute[] {
|
|
57
|
+
export function buildKeys(attrs: Attributes): Attribute[] | undefined {
|
|
44
58
|
if (!attrs) {
|
|
45
|
-
return undefined
|
|
59
|
+
return undefined
|
|
46
60
|
}
|
|
47
|
-
const keys: string[] = Object.keys(attrs)
|
|
48
|
-
const ats: Attribute[] = []
|
|
61
|
+
const keys: string[] = Object.keys(attrs)
|
|
62
|
+
const ats: Attribute[] = []
|
|
49
63
|
for (const key of keys) {
|
|
50
|
-
const attr: Attribute = attrs[key]
|
|
64
|
+
const attr: Attribute = attrs[key]
|
|
51
65
|
if (attr) {
|
|
52
66
|
if (attr.key === true) {
|
|
53
|
-
const at: Attribute = {name: key, type: attr.type}
|
|
54
|
-
ats.push(at)
|
|
67
|
+
const at: Attribute = { name: key, type: attr.type }
|
|
68
|
+
ats.push(at)
|
|
55
69
|
}
|
|
56
70
|
}
|
|
57
71
|
}
|
|
58
|
-
return ats
|
|
72
|
+
return ats
|
|
59
73
|
}
|
package/tsconfig.json
CHANGED
package/lib/response.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function handleError(err, res, log) {
|
|
4
|
-
if (log) {
|
|
5
|
-
log(err);
|
|
6
|
-
res.status(500).end('Internal Server Error');
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
res.status(500).end(err);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.handleError = handleError;
|
package/src/response.ts
DELETED