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/lib/LoadController.js
CHANGED
|
@@ -1,66 +1,91 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
-
var
|
|
4
|
-
var view_1 = require("./view")
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
+
var http_1 = require("./http")
|
|
4
|
+
var view_1 = require("./view")
|
|
5
5
|
function getViewFunc(viewService) {
|
|
6
|
-
if (typeof viewService ===
|
|
7
|
-
return viewService
|
|
6
|
+
if (typeof viewService === "function") {
|
|
7
|
+
return viewService
|
|
8
8
|
}
|
|
9
|
-
return viewService.load
|
|
9
|
+
return viewService.load
|
|
10
10
|
}
|
|
11
11
|
function getKeysFunc(viewService, keys) {
|
|
12
12
|
if (keys) {
|
|
13
13
|
if (Array.isArray(keys)) {
|
|
14
14
|
if (keys.length > 0) {
|
|
15
|
-
if (typeof keys[0] ===
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var attr = { name: str, type: 'string' };
|
|
20
|
-
attrs.push(attr);
|
|
21
|
-
}
|
|
22
|
-
return attrs;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
return keys;
|
|
15
|
+
if (typeof keys[0] === "string") {
|
|
16
|
+
return http_1.attrs(keys)
|
|
17
|
+
} else {
|
|
18
|
+
return keys
|
|
26
19
|
}
|
|
27
20
|
}
|
|
28
|
-
return undefined
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return view_1.buildKeys(keys);
|
|
21
|
+
return undefined
|
|
22
|
+
} else {
|
|
23
|
+
return view_1.buildKeys(keys)
|
|
32
24
|
}
|
|
33
25
|
}
|
|
34
|
-
if (typeof viewService !==
|
|
35
|
-
var metadata = viewService.metadata()
|
|
26
|
+
if (typeof viewService !== "function" && viewService.metadata) {
|
|
27
|
+
var metadata = viewService.metadata()
|
|
36
28
|
if (metadata) {
|
|
37
|
-
return view_1.buildKeys(metadata
|
|
29
|
+
return view_1.buildKeys(metadata)
|
|
38
30
|
}
|
|
39
31
|
}
|
|
40
|
-
return undefined
|
|
32
|
+
return undefined
|
|
41
33
|
}
|
|
42
34
|
var LoadController = (function () {
|
|
43
|
-
function LoadController(
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.keys = getKeysFunc(viewService, keys);
|
|
35
|
+
function LoadController(viewService, keys) {
|
|
36
|
+
this.load = this.load.bind(this)
|
|
37
|
+
this.view = getViewFunc(viewService)
|
|
38
|
+
this.keys = getKeysFunc(viewService, keys)
|
|
48
39
|
}
|
|
49
40
|
LoadController.prototype.load = function (req, res) {
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
var id = view_1.buildAndCheckId(req, res, this.keys)
|
|
42
|
+
if (id) {
|
|
43
|
+
this.view(id)
|
|
44
|
+
.then(function (obj) {
|
|
45
|
+
return http_1.respondModel(http_1.minimize(obj), res)
|
|
46
|
+
})
|
|
47
|
+
.catch(function (err) {
|
|
48
|
+
return http_1.handleError(err, res)
|
|
49
|
+
})
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
}
|
|
52
|
+
return LoadController
|
|
53
|
+
})()
|
|
54
|
+
exports.LoadController = LoadController
|
|
55
|
+
var ItemController = (function () {
|
|
56
|
+
function ItemController(loadData, name, param, max, maxName) {
|
|
57
|
+
this.loadData = loadData
|
|
58
|
+
this.param = param
|
|
59
|
+
this.name = name && name.length > 0 ? name : "keyword"
|
|
60
|
+
this.max = max && max > 0 ? max : 20
|
|
61
|
+
this.maxName = maxName && maxName.length > 0 ? maxName : "max"
|
|
62
|
+
this.load = this.load.bind(this)
|
|
63
|
+
this.query = this.query.bind(this)
|
|
64
|
+
}
|
|
65
|
+
ItemController.prototype.query = function (req, res) {
|
|
66
|
+
return this.load(req, res)
|
|
67
|
+
}
|
|
68
|
+
ItemController.prototype.load = function (req, res) {
|
|
69
|
+
var v = this.param ? req.params[this.name] : req.query[this.name]
|
|
70
|
+
if (!v) {
|
|
71
|
+
res.status(400).end("'" + this.name + "' cannot be empty")
|
|
72
|
+
} else {
|
|
73
|
+
var s = v.toString()
|
|
74
|
+
if (s.length === 0) {
|
|
75
|
+
res.status(400).end("'" + this.name + "' cannot be empty")
|
|
76
|
+
} else {
|
|
77
|
+
var max = http_1.queryNumber(req, this.maxName, this.max)
|
|
78
|
+
this.loadData(s, max)
|
|
79
|
+
.then(function (result) {
|
|
80
|
+
return http_1.respondModel(http_1.minimize(result), res)
|
|
81
|
+
})
|
|
82
|
+
.catch(function (err) {
|
|
83
|
+
return http_1.handleError(err, res)
|
|
84
|
+
})
|
|
61
85
|
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return
|
|
65
|
-
}()
|
|
66
|
-
exports.
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return ItemController
|
|
89
|
+
})()
|
|
90
|
+
exports.ItemController = ItemController
|
|
91
|
+
exports.ItemHandler = ItemController
|
|
@@ -1,49 +1,121 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
var __extends =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
var __extends =
|
|
3
|
+
(this && this.__extends) ||
|
|
4
|
+
(function () {
|
|
5
|
+
var extendStatics = function (d, b) {
|
|
6
|
+
extendStatics =
|
|
7
|
+
Object.setPrototypeOf ||
|
|
8
|
+
({ __proto__: [] } instanceof Array &&
|
|
9
|
+
function (d, b) {
|
|
10
|
+
d.__proto__ = b
|
|
11
|
+
}) ||
|
|
12
|
+
function (d, b) {
|
|
13
|
+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]
|
|
14
|
+
}
|
|
15
|
+
return extendStatics(d, b)
|
|
16
|
+
}
|
|
17
|
+
return function (d, b) {
|
|
18
|
+
extendStatics(d, b)
|
|
19
|
+
function __() {
|
|
20
|
+
this.constructor = d
|
|
21
|
+
}
|
|
22
|
+
d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __())
|
|
23
|
+
}
|
|
24
|
+
})()
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
26
|
+
var http_1 = require("./http")
|
|
27
|
+
var LoadController_1 = require("./LoadController")
|
|
28
|
+
var resources_1 = require("./resources")
|
|
29
|
+
var search_1 = require("./search")
|
|
30
|
+
function useSearchController(find, viewService, array, dates, numbers, keys, config) {
|
|
31
|
+
var c = new LoadSearchController(find, viewService, keys, config, dates, numbers)
|
|
32
|
+
c.array = array
|
|
33
|
+
return c
|
|
34
|
+
}
|
|
35
|
+
exports.useSearchController = useSearchController
|
|
36
|
+
exports.useSearchHandler = useSearchController
|
|
37
|
+
exports.createSearchController = useSearchController
|
|
38
|
+
exports.createSearchHandler = useSearchController
|
|
19
39
|
var LoadSearchController = (function (_super) {
|
|
20
|
-
__extends(LoadSearchController, _super)
|
|
21
|
-
function LoadSearchController(
|
|
22
|
-
var _this = _super.call(this,
|
|
23
|
-
_this.find = find
|
|
24
|
-
_this.
|
|
25
|
-
_this.search = _this.search.bind(_this);
|
|
40
|
+
__extends(LoadSearchController, _super)
|
|
41
|
+
function LoadSearchController(find, viewService, keys, config, dates, numbers) {
|
|
42
|
+
var _this = _super.call(this, viewService, keys) || this
|
|
43
|
+
_this.find = find
|
|
44
|
+
_this.search = _this.search.bind(_this)
|
|
26
45
|
if (config) {
|
|
27
|
-
if (typeof config ===
|
|
28
|
-
_this.csv = config
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
_this.config = search_1.initializeConfig(config);
|
|
46
|
+
if (typeof config === "boolean") {
|
|
47
|
+
_this.csv = config
|
|
48
|
+
} else {
|
|
49
|
+
_this.config = search_1.initializeConfig(config)
|
|
32
50
|
if (_this.config) {
|
|
33
|
-
_this.csv = _this.config.csv
|
|
51
|
+
_this.csv = _this.config.csv
|
|
52
|
+
_this.excluding = _this.config.excluding
|
|
34
53
|
}
|
|
35
54
|
}
|
|
36
55
|
}
|
|
37
|
-
|
|
56
|
+
var m = search_1.getMetadataFunc(viewService, dates, numbers, keys)
|
|
57
|
+
if (m) {
|
|
58
|
+
_this.dates = m.dates
|
|
59
|
+
_this.numbers = m.numbers
|
|
60
|
+
}
|
|
61
|
+
return _this
|
|
38
62
|
}
|
|
39
63
|
LoadSearchController.prototype.search = function (req, res) {
|
|
40
|
-
var _this = this
|
|
41
|
-
var s = search_1.fromRequest(req, this.
|
|
42
|
-
var l = search_1.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
64
|
+
var _this = this
|
|
65
|
+
var s = search_1.fromRequest(req, search_1.buildArray(this.array, resources_1.resources.fields, this.excluding))
|
|
66
|
+
var l = search_1.getParameters(s)
|
|
67
|
+
var s2 = search_1.format(s, this.dates, this.numbers)
|
|
68
|
+
this.find(s2, l.limit, l.pageOrNextPageToken, l.fields)
|
|
69
|
+
.then(function (result) {
|
|
70
|
+
return search_1.jsonResult(res, result, _this.csv, l.fields, _this.config)
|
|
71
|
+
})
|
|
72
|
+
.catch(function (err) {
|
|
73
|
+
return http_1.handleError(err, res)
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
return LoadSearchController
|
|
77
|
+
})(LoadController_1.LoadController)
|
|
78
|
+
exports.LoadSearchController = LoadSearchController
|
|
79
|
+
var QueryController = (function (_super) {
|
|
80
|
+
__extends(QueryController, _super)
|
|
81
|
+
function QueryController(query, config, dates, numbers, array) {
|
|
82
|
+
var _this = _super.call(this, query) || this
|
|
83
|
+
_this.query = query
|
|
84
|
+
_this.search = _this.search.bind(_this)
|
|
85
|
+
_this.array = array
|
|
86
|
+
if (config) {
|
|
87
|
+
if (typeof config === "boolean") {
|
|
88
|
+
_this.csv = config
|
|
89
|
+
} else {
|
|
90
|
+
_this.config = search_1.initializeConfig(config)
|
|
91
|
+
if (_this.config) {
|
|
92
|
+
_this.csv = _this.config.csv
|
|
93
|
+
_this.excluding = _this.config.excluding
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
var m = search_1.getMetadataFunc(query, dates, numbers)
|
|
98
|
+
if (m) {
|
|
99
|
+
_this.dates = m.dates
|
|
100
|
+
_this.numbers = m.numbers
|
|
101
|
+
}
|
|
102
|
+
return _this
|
|
103
|
+
}
|
|
104
|
+
QueryController.prototype.search = function (req, res) {
|
|
105
|
+
var _this = this
|
|
106
|
+
var s = search_1.fromRequest(req, search_1.buildArray(this.array, resources_1.resources.fields, this.excluding))
|
|
107
|
+
var l = search_1.getParameters(s)
|
|
108
|
+
var s2 = search_1.format(s, this.dates, this.numbers)
|
|
109
|
+
this.query
|
|
110
|
+
.search(s2, l.limit, l.pageOrNextPageToken, l.fields)
|
|
111
|
+
.then(function (result) {
|
|
112
|
+
return search_1.jsonResult(res, result, _this.csv, l.fields, _this.config)
|
|
113
|
+
})
|
|
114
|
+
.catch(function (err) {
|
|
115
|
+
return http_1.handleError(err, res)
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
return QueryController
|
|
119
|
+
})(LoadController_1.LoadController)
|
|
120
|
+
exports.QueryController = QueryController
|
|
121
|
+
exports.QueryHandler = QueryController
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
+
exports.map = {
|
|
4
|
+
TRACE: -2,
|
|
5
|
+
DEBUG: -1,
|
|
6
|
+
INFO: 0,
|
|
7
|
+
WARN: 1,
|
|
8
|
+
ERROR: 2,
|
|
9
|
+
PANIC: 3,
|
|
10
|
+
FATAL: 4,
|
|
11
|
+
}
|
|
12
|
+
var LogController = (function () {
|
|
13
|
+
function LogController(logger, updateL, mp) {
|
|
14
|
+
this.logger = logger
|
|
15
|
+
this.map = mp ? mp : exports.map
|
|
16
|
+
this.update = updateL ? updateL : updateLog
|
|
17
|
+
this.config = this.config.bind(this)
|
|
18
|
+
}
|
|
19
|
+
LogController.prototype.config = function (req, res) {
|
|
20
|
+
var obj = req.body
|
|
21
|
+
if (!this.logger) {
|
|
22
|
+
res.status(503).end("Logger is not available")
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
if (typeof obj.level === "string" && obj.level.length > 0) {
|
|
26
|
+
if (!this.map) {
|
|
27
|
+
res.status(503).end("Map is not available")
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
var changed = this.update(this.logger, obj, this.map)
|
|
32
|
+
if (changed) {
|
|
33
|
+
res.status(200).json(true).end()
|
|
34
|
+
} else {
|
|
35
|
+
res.status(204).json(false).end()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return LogController
|
|
39
|
+
})()
|
|
40
|
+
exports.LogController = LogController
|
|
41
|
+
function updateLog(logger, obj, mp) {
|
|
42
|
+
var changed = false
|
|
43
|
+
if (typeof obj.level === "string" && obj.level.length > 0) {
|
|
44
|
+
var lv = mp[obj.level.toUpperCase()]
|
|
45
|
+
if (lv !== undefined) {
|
|
46
|
+
logger.level = lv
|
|
47
|
+
changed = true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (obj.map) {
|
|
51
|
+
if (typeof obj.map.level === "string" && obj.map.level.length > 0) {
|
|
52
|
+
logger.map.level = obj.map.level
|
|
53
|
+
changed = true
|
|
54
|
+
}
|
|
55
|
+
if (typeof obj.map.time === "string" && obj.map.time.length > 0) {
|
|
56
|
+
logger.map.time = obj.map.time
|
|
57
|
+
changed = true
|
|
58
|
+
}
|
|
59
|
+
if (typeof obj.map.msg === "string" && obj.map.msg.length > 0) {
|
|
60
|
+
logger.map.msg = obj.map.msg
|
|
61
|
+
changed = true
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (obj.constants !== undefined && typeof obj.constants === "object") {
|
|
65
|
+
var ks = Object.keys(obj.constants)
|
|
66
|
+
if (ks.length > 0) {
|
|
67
|
+
logger.constants = obj.constants
|
|
68
|
+
} else {
|
|
69
|
+
logger.constants = undefined
|
|
70
|
+
}
|
|
71
|
+
changed = true
|
|
72
|
+
}
|
|
73
|
+
if (obj.name) {
|
|
74
|
+
if (
|
|
75
|
+
typeof obj.name.trace === "string" &&
|
|
76
|
+
typeof obj.name.debug === "string" &&
|
|
77
|
+
typeof obj.name.info === "string" &&
|
|
78
|
+
typeof obj.name.warn === "string" &&
|
|
79
|
+
typeof obj.name.error === "string" &&
|
|
80
|
+
typeof obj.name.panic === "string" &&
|
|
81
|
+
typeof obj.name.fatal === "string"
|
|
82
|
+
) {
|
|
83
|
+
logger.name = obj.name
|
|
84
|
+
changed = true
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return changed
|
|
88
|
+
}
|
|
89
|
+
exports.updateLog = updateLog
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
var __extends =
|
|
3
|
+
(this && this.__extends) ||
|
|
4
|
+
(function () {
|
|
5
|
+
var extendStatics = function (d, b) {
|
|
6
|
+
extendStatics =
|
|
7
|
+
Object.setPrototypeOf ||
|
|
8
|
+
({ __proto__: [] } instanceof Array &&
|
|
9
|
+
function (d, b) {
|
|
10
|
+
d.__proto__ = b
|
|
11
|
+
}) ||
|
|
12
|
+
function (d, b) {
|
|
13
|
+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]
|
|
14
|
+
}
|
|
15
|
+
return extendStatics(d, b)
|
|
16
|
+
}
|
|
17
|
+
return function (d, b) {
|
|
18
|
+
extendStatics(d, b)
|
|
19
|
+
function __() {
|
|
20
|
+
this.constructor = d
|
|
21
|
+
}
|
|
22
|
+
d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __())
|
|
23
|
+
}
|
|
24
|
+
})()
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
26
|
+
var GenericController_1 = require("./GenericController")
|
|
27
|
+
var http_1 = require("./http")
|
|
28
|
+
var resources_1 = require("./resources")
|
|
29
|
+
var search_1 = require("./search")
|
|
30
|
+
var LowcodeController = (function (_super) {
|
|
31
|
+
__extends(LowcodeController, _super)
|
|
32
|
+
function LowcodeController(lowCodeService, config, build, validate, dates, numbers) {
|
|
33
|
+
var _this = _super.call(this, lowCodeService, build, validate) || this
|
|
34
|
+
_this.lowCodeService = lowCodeService
|
|
35
|
+
_this.search = _this.search.bind(_this)
|
|
36
|
+
_this.config = search_1.initializeConfig(config)
|
|
37
|
+
if (_this.config) {
|
|
38
|
+
_this.csv = _this.config.csv
|
|
39
|
+
_this.excluding = _this.config.excluding
|
|
40
|
+
}
|
|
41
|
+
var m = search_1.getMetadataFunc(lowCodeService, dates, numbers)
|
|
42
|
+
if (m) {
|
|
43
|
+
_this.dates = m.dates
|
|
44
|
+
_this.numbers = m.numbers
|
|
45
|
+
}
|
|
46
|
+
return _this
|
|
47
|
+
}
|
|
48
|
+
LowcodeController.prototype.search = function (req, res) {
|
|
49
|
+
var _this = this
|
|
50
|
+
var s = search_1.fromRequest(req, search_1.buildArray(this.array, resources_1.resources.fields, this.excluding))
|
|
51
|
+
var l = search_1.getParameters(s)
|
|
52
|
+
var s2 = search_1.format(s, this.dates, this.numbers)
|
|
53
|
+
this.lowCodeService
|
|
54
|
+
.search(s2, l.limit, l.pageOrNextPageToken, l.fields)
|
|
55
|
+
.then(function (result) {
|
|
56
|
+
return search_1.jsonResult(res, result, _this.csv, l.fields, _this.config)
|
|
57
|
+
})
|
|
58
|
+
.catch(function (err) {
|
|
59
|
+
return http_1.handleError(err, res)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
return LowcodeController
|
|
63
|
+
})(GenericController_1.GenericController)
|
|
64
|
+
exports.LowcodeController = LowcodeController
|
|
65
|
+
exports.LowcodeHandler = LowcodeController
|
|
66
|
+
var Controller = (function (_super) {
|
|
67
|
+
__extends(Controller, _super)
|
|
68
|
+
function Controller(log, lowCodeService, build, validate, config, dates, numbers) {
|
|
69
|
+
var _this = _super.call(this, lowCodeService, build, validate) || this
|
|
70
|
+
_this.lowCodeService = lowCodeService
|
|
71
|
+
_this.search = _this.search.bind(_this)
|
|
72
|
+
_this.config = search_1.initializeConfig(config)
|
|
73
|
+
if (_this.config) {
|
|
74
|
+
_this.csv = _this.config.csv
|
|
75
|
+
_this.excluding = _this.config.excluding
|
|
76
|
+
}
|
|
77
|
+
var m = search_1.getMetadataFunc(lowCodeService, dates, numbers)
|
|
78
|
+
if (m) {
|
|
79
|
+
_this.dates = m.dates
|
|
80
|
+
_this.numbers = m.numbers
|
|
81
|
+
}
|
|
82
|
+
return _this
|
|
83
|
+
}
|
|
84
|
+
Controller.prototype.search = function (req, res) {
|
|
85
|
+
var _this = this
|
|
86
|
+
var s = search_1.fromRequest(req, search_1.buildArray(this.array, resources_1.resources.fields, this.excluding))
|
|
87
|
+
var l = search_1.getParameters(s)
|
|
88
|
+
var s2 = search_1.format(s, this.dates, this.numbers)
|
|
89
|
+
this.lowCodeService
|
|
90
|
+
.search(s2, l.limit, l.pageOrNextPageToken, l.fields)
|
|
91
|
+
.then(function (result) {
|
|
92
|
+
return search_1.jsonResult(res, result, _this.csv, l.fields, _this.config)
|
|
93
|
+
})
|
|
94
|
+
.catch(function (err) {
|
|
95
|
+
return http_1.handleError(err, res)
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
return Controller
|
|
99
|
+
})(GenericController_1.GenericController)
|
|
100
|
+
exports.Controller = Controller
|
package/lib/SearchController.js
CHANGED
|
@@ -1,33 +1,40 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
-
var
|
|
4
|
-
var
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
+
var http_1 = require("./http")
|
|
4
|
+
var resources_1 = require("./resources")
|
|
5
|
+
var search_1 = require("./search")
|
|
5
6
|
var SearchController = (function () {
|
|
6
|
-
function SearchController(log, find, config,
|
|
7
|
-
this.log = log
|
|
8
|
-
this.find = find
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
7
|
+
function SearchController(log, find, config, dates, numbers) {
|
|
8
|
+
this.log = log
|
|
9
|
+
this.find = find
|
|
10
|
+
this.dates = dates
|
|
11
|
+
this.numbers = numbers
|
|
12
|
+
this.search = this.search.bind(this)
|
|
11
13
|
if (config) {
|
|
12
|
-
if (typeof config ===
|
|
13
|
-
this.csv = config
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
this.config = search_1.initializeConfig(config);
|
|
14
|
+
if (typeof config === "boolean") {
|
|
15
|
+
this.csv = config
|
|
16
|
+
} else {
|
|
17
|
+
this.config = search_1.initializeConfig(config)
|
|
17
18
|
if (this.config) {
|
|
18
|
-
this.csv = this.config.csv
|
|
19
|
+
this.csv = this.config.csv
|
|
20
|
+
this.excluding = this.config.excluding
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
SearchController.prototype.search = function (req, res) {
|
|
24
|
-
var _this = this
|
|
25
|
-
var s = search_1.fromRequest(req, this.
|
|
26
|
-
var l = search_1.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
var _this = this
|
|
27
|
+
var s = search_1.fromRequest(req, search_1.buildArray(this.array, resources_1.resources.fields, this.excluding))
|
|
28
|
+
var l = search_1.getParameters(s)
|
|
29
|
+
var s2 = search_1.format(s, this.dates, this.numbers)
|
|
30
|
+
this.find(s2, l.limit, l.pageOrNextPageToken, l.fields)
|
|
31
|
+
.then(function (result) {
|
|
32
|
+
return search_1.jsonResult(res, result, _this.csv, l.fields, _this.config)
|
|
33
|
+
})
|
|
34
|
+
.catch(function (err) {
|
|
35
|
+
return http_1.handleError(err, res)
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
return SearchController
|
|
39
|
+
})()
|
|
40
|
+
exports.SearchController = SearchController
|
package/lib/access.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
+
function allow(access) {
|
|
4
|
+
var ao = access.origin
|
|
5
|
+
if (typeof ao === "string") {
|
|
6
|
+
return function (req, res, next) {
|
|
7
|
+
res.header("Access-Control-Allow-Origin", access.origin)
|
|
8
|
+
res.header("Access-Control-Allow-Credentials", access.credentials)
|
|
9
|
+
res.header("Access-Control-Allow-Methods", access.methods)
|
|
10
|
+
res.setHeader("Access-Control-Allow-Headers", access.headers)
|
|
11
|
+
next()
|
|
12
|
+
}
|
|
13
|
+
} else if (Array.isArray(ao) && ao.length > 0) {
|
|
14
|
+
return function (req, res, next) {
|
|
15
|
+
var origin = req.headers.origin
|
|
16
|
+
if (origin) {
|
|
17
|
+
if (ao.includes(origin)) {
|
|
18
|
+
res.setHeader("Access-Control-Allow-Origin", origin)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
res.header("Access-Control-Allow-Credentials", access.credentials)
|
|
22
|
+
res.header("Access-Control-Allow-Methods", access.methods)
|
|
23
|
+
res.setHeader("Access-Control-Allow-Headers", access.headers)
|
|
24
|
+
next()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return function (req, res, next) {
|
|
28
|
+
res.header("Access-Control-Allow-Credentials", access.credentials)
|
|
29
|
+
res.header("Access-Control-Allow-Methods", access.methods)
|
|
30
|
+
res.setHeader("Access-Control-Allow-Headers", access.headers)
|
|
31
|
+
next()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.allow = allow
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
+
var http = require("http")
|
|
4
|
+
var https = require("https")
|
|
5
|
+
function getHealthSecure(url, timeout) {
|
|
6
|
+
return new Promise(function (resolve) {
|
|
7
|
+
https
|
|
8
|
+
.get(url, { rejectUnauthorized: false }, function (res) {
|
|
9
|
+
var data = ""
|
|
10
|
+
res.on("data", function (d) {
|
|
11
|
+
data += d
|
|
12
|
+
})
|
|
13
|
+
res.on("end", function () {
|
|
14
|
+
resolve({ statusCode: res.statusCode, data: data, statusMessage: res.statusMessage })
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
.on("error", function (e) {
|
|
18
|
+
return { statusCode: 500, statusMessage: e }
|
|
19
|
+
})
|
|
20
|
+
setTimeout(function () {
|
|
21
|
+
return resolve({ statusCode: 408, statusMessage: "Time out" })
|
|
22
|
+
}, timeout)
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
function getHealth(url, timeout) {
|
|
26
|
+
return new Promise(function (resolve) {
|
|
27
|
+
http
|
|
28
|
+
.get(url, function (res) {
|
|
29
|
+
var data = ""
|
|
30
|
+
res.on("data", function (d) {
|
|
31
|
+
data += d
|
|
32
|
+
})
|
|
33
|
+
res.on("end", function () {
|
|
34
|
+
resolve({ statusCode: res.statusCode, data: data, statusMessage: res.statusMessage })
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
.on("error", function (e) {
|
|
38
|
+
return { statusCode: 500, statusMessage: e }
|
|
39
|
+
})
|
|
40
|
+
setTimeout(function () {
|
|
41
|
+
return resolve({ statusCode: 408, statusMessage: "Time out" })
|
|
42
|
+
}, timeout)
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
var ClientChecker = (function () {
|
|
46
|
+
function ClientChecker(service, url, timeout) {
|
|
47
|
+
this.service = service
|
|
48
|
+
this.url = url
|
|
49
|
+
this.timeout = timeout ? timeout : 4200
|
|
50
|
+
this.check = this.check.bind(this)
|
|
51
|
+
this.name = this.name.bind(this)
|
|
52
|
+
this.build = this.build.bind(this)
|
|
53
|
+
}
|
|
54
|
+
ClientChecker.prototype.check = function () {
|
|
55
|
+
var obj = {}
|
|
56
|
+
if (this.url.startsWith("https://")) {
|
|
57
|
+
return getHealthSecure(this.url, this.timeout).then(function (r) {
|
|
58
|
+
return (obj = r)
|
|
59
|
+
})
|
|
60
|
+
} else {
|
|
61
|
+
return getHealth(this.url, this.timeout).then(function (r) {
|
|
62
|
+
return (obj = r)
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
ClientChecker.prototype.name = function () {
|
|
67
|
+
return this.service
|
|
68
|
+
}
|
|
69
|
+
ClientChecker.prototype.build = function (data, err) {
|
|
70
|
+
if (err) {
|
|
71
|
+
if (!data) {
|
|
72
|
+
data = {}
|
|
73
|
+
}
|
|
74
|
+
data["error"] = err
|
|
75
|
+
}
|
|
76
|
+
return data
|
|
77
|
+
}
|
|
78
|
+
return ClientChecker
|
|
79
|
+
})()
|
|
80
|
+
exports.ClientChecker = ClientChecker
|