express-ext 0.1.26 → 0.1.27
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.
|
@@ -67,3 +67,44 @@ var LoadSearchController = (function (_super) {
|
|
|
67
67
|
return LoadSearchController;
|
|
68
68
|
}(LoadController_1.LoadController));
|
|
69
69
|
exports.LoadSearchController = LoadSearchController;
|
|
70
|
+
var ViewController = (function (_super) {
|
|
71
|
+
__extends(ViewController, _super);
|
|
72
|
+
function ViewController(log, query, config, dates, numbers) {
|
|
73
|
+
var _this = _super.call(this, log, query) || this;
|
|
74
|
+
_this.query = query;
|
|
75
|
+
_this.search = _this.search.bind(_this);
|
|
76
|
+
if (config) {
|
|
77
|
+
if (typeof config === 'boolean') {
|
|
78
|
+
_this.csv = config;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
_this.config = search_1.initializeConfig(config);
|
|
82
|
+
if (_this.config) {
|
|
83
|
+
_this.csv = _this.config.csv;
|
|
84
|
+
_this.fields = _this.config.fields;
|
|
85
|
+
_this.excluding = _this.config.excluding;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!_this.fields || _this.fields.length === 0) {
|
|
90
|
+
_this.fields = 'fields';
|
|
91
|
+
}
|
|
92
|
+
var m = search_func_1.getMetadataFunc(query, dates, numbers);
|
|
93
|
+
if (m) {
|
|
94
|
+
_this.dates = m.dates;
|
|
95
|
+
_this.numbers = m.numbers;
|
|
96
|
+
}
|
|
97
|
+
return _this;
|
|
98
|
+
}
|
|
99
|
+
ViewController.prototype.search = function (req, res) {
|
|
100
|
+
var _this = this;
|
|
101
|
+
var s = search_1.fromRequest(req, search_1.buildArray(this.array, this.fields, this.excluding));
|
|
102
|
+
var l = search_1.getParameters(s, this.config);
|
|
103
|
+
var s2 = search_1.format(s, this.dates, this.numbers);
|
|
104
|
+
this.query.search(s2, l.limit, l.skipOrRefId, l.fields)
|
|
105
|
+
.then(function (result) { return search_1.jsonResult(res, result, _this.csv, l.fields, _this.config); })
|
|
106
|
+
.catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
107
|
+
};
|
|
108
|
+
return ViewController;
|
|
109
|
+
}(LoadController_1.LoadController));
|
|
110
|
+
exports.ViewController = ViewController;
|
package/lib/LowCodeController.js
CHANGED
|
@@ -17,9 +17,43 @@ var GenericController_1 = require("./GenericController");
|
|
|
17
17
|
var http_1 = require("./http");
|
|
18
18
|
var search_1 = require("./search");
|
|
19
19
|
var search_func_1 = require("./search_func");
|
|
20
|
+
var LowcodeController = (function (_super) {
|
|
21
|
+
__extends(LowcodeController, _super);
|
|
22
|
+
function LowcodeController(log, lowCodeService, config, build, validate, dates, numbers) {
|
|
23
|
+
var _this = _super.call(this, log, lowCodeService, config, build, validate) || this;
|
|
24
|
+
_this.lowCodeService = lowCodeService;
|
|
25
|
+
_this.search = _this.search.bind(_this);
|
|
26
|
+
_this.config = search_1.initializeConfig(config);
|
|
27
|
+
if (_this.config) {
|
|
28
|
+
_this.csv = _this.config.csv;
|
|
29
|
+
_this.fields = _this.config.fields;
|
|
30
|
+
_this.excluding = _this.config.excluding;
|
|
31
|
+
}
|
|
32
|
+
if (!_this.fields || _this.fields.length === 0) {
|
|
33
|
+
_this.fields = 'fields';
|
|
34
|
+
}
|
|
35
|
+
var m = search_func_1.getMetadataFunc(lowCodeService, dates, numbers);
|
|
36
|
+
if (m) {
|
|
37
|
+
_this.dates = m.dates;
|
|
38
|
+
_this.numbers = m.numbers;
|
|
39
|
+
}
|
|
40
|
+
return _this;
|
|
41
|
+
}
|
|
42
|
+
LowcodeController.prototype.search = function (req, res) {
|
|
43
|
+
var _this = this;
|
|
44
|
+
var s = search_1.fromRequest(req, search_1.buildArray(this.array, this.fields, this.excluding));
|
|
45
|
+
var l = search_1.getParameters(s, this.config);
|
|
46
|
+
var s2 = search_1.format(s, this.dates, this.numbers);
|
|
47
|
+
this.lowCodeService.search(s2, l.limit, l.skipOrRefId, l.fields)
|
|
48
|
+
.then(function (result) { return search_1.jsonResult(res, result, _this.csv, l.fields, _this.config); })
|
|
49
|
+
.catch(function (err) { return http_1.handleError(err, res, _this.log); });
|
|
50
|
+
};
|
|
51
|
+
return LowcodeController;
|
|
52
|
+
}(GenericController_1.GenericController));
|
|
53
|
+
exports.LowcodeController = LowcodeController;
|
|
20
54
|
var Controller = (function (_super) {
|
|
21
55
|
__extends(Controller, _super);
|
|
22
|
-
function Controller(log, lowCodeService,
|
|
56
|
+
function Controller(log, lowCodeService, build, validate, config, dates, numbers) {
|
|
23
57
|
var _this = _super.call(this, log, lowCodeService, config, build, validate) || this;
|
|
24
58
|
_this.lowCodeService = lowCodeService;
|
|
25
59
|
_this.search = _this.search.bind(_this);
|
package/package.json
CHANGED
|
@@ -9,6 +9,11 @@ export interface Search {
|
|
|
9
9
|
search(req: Request, res: Response): void;
|
|
10
10
|
load(req: Request, res: Response): void;
|
|
11
11
|
}
|
|
12
|
+
export interface Query<T, ID, S> extends ViewService<T, ID> {
|
|
13
|
+
search: (s: S, limit?: number, skip?: number|string, fields?: string[]) => Promise<SearchResult<T>>;
|
|
14
|
+
metadata?(): Attributes|undefined;
|
|
15
|
+
load(id: ID, ctx?: any): Promise<T|null>;
|
|
16
|
+
}
|
|
12
17
|
export interface SearchManager {
|
|
13
18
|
search(req: Request, res: Response): void;
|
|
14
19
|
load(req: Request, res: Response): void;
|
|
@@ -62,3 +67,44 @@ export class LoadSearchController<T, ID, S extends Filter> extends LoadControlle
|
|
|
62
67
|
.catch(err => handleError(err, res, this.log));
|
|
63
68
|
}
|
|
64
69
|
}
|
|
70
|
+
export class ViewController<T, ID, S extends Filter> extends LoadController<T, ID> {
|
|
71
|
+
config?: SearchConfig;
|
|
72
|
+
csv?: boolean;
|
|
73
|
+
dates?: string[];
|
|
74
|
+
numbers?: string[];
|
|
75
|
+
fields?: string;
|
|
76
|
+
excluding?: string;
|
|
77
|
+
array?: string[];
|
|
78
|
+
constructor(log: Log, protected query: Query<T, ID, S>, config?: SearchConfig|boolean, dates?: string[], numbers?: string[]) {
|
|
79
|
+
super(log, query);
|
|
80
|
+
this.search = this.search.bind(this);
|
|
81
|
+
if (config) {
|
|
82
|
+
if (typeof config === 'boolean') {
|
|
83
|
+
this.csv = config;
|
|
84
|
+
} else {
|
|
85
|
+
this.config = initializeConfig(config);
|
|
86
|
+
if (this.config) {
|
|
87
|
+
this.csv = this.config.csv;
|
|
88
|
+
this.fields = this.config.fields;
|
|
89
|
+
this.excluding = this.config.excluding;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (!this.fields || this.fields.length === 0) {
|
|
94
|
+
this.fields = 'fields';
|
|
95
|
+
}
|
|
96
|
+
const m = getMetadataFunc(query, dates, numbers);
|
|
97
|
+
if (m) {
|
|
98
|
+
this.dates = m.dates;
|
|
99
|
+
this.numbers = m.numbers;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
search(req: Request, res: Response): void {
|
|
103
|
+
const s = fromRequest<S>(req, buildArray(this.array, this.fields, this.excluding));
|
|
104
|
+
const l = getParameters(s, this.config);
|
|
105
|
+
const s2 = format(s, this.dates, this.numbers);
|
|
106
|
+
this.query.search(s2, l.limit, l.skipOrRefId, l.fields)
|
|
107
|
+
.then(result => jsonResult(res, result, this.csv, l.fields, this.config))
|
|
108
|
+
.catch(err => handleError(err, res, this.log));
|
|
109
|
+
}
|
|
110
|
+
}
|
package/src/LowCodeController.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface LowCodeConfig extends StatusConfig, SearchConfig {
|
|
|
11
11
|
export interface Service<T, ID, R, S extends Filter> extends GenericService<T, ID, R> {
|
|
12
12
|
search: (s: S, limit?: number, skip?: number|string, fields?: string[]) => Promise<SearchResult<T>>;
|
|
13
13
|
}
|
|
14
|
-
export class
|
|
14
|
+
export class LowcodeController<T, ID, S extends Filter> extends GenericController<T, ID> {
|
|
15
15
|
config?: SearchConfig;
|
|
16
16
|
csv?: boolean;
|
|
17
17
|
dates?: string[];
|
|
@@ -46,3 +46,38 @@ export class Controller<T, ID, S extends Filter> extends GenericController<T, ID
|
|
|
46
46
|
.catch(err => handleError(err, res, this.log));
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
export class Controller<T, ID, S extends Filter> extends GenericController<T, ID> {
|
|
50
|
+
config?: SearchConfig;
|
|
51
|
+
csv?: boolean;
|
|
52
|
+
dates?: string[];
|
|
53
|
+
numbers?: string[];
|
|
54
|
+
fields?: string;
|
|
55
|
+
excluding?: string;
|
|
56
|
+
array?: string[];
|
|
57
|
+
constructor(log: Log, public lowCodeService: Service<T, ID, number|ResultInfo<T>, S>, build?: Build<T>, validate?: (obj: T, patch?: boolean) => Promise<ErrorMessage[]>, config?: LowCodeConfig, dates?: string[], numbers?: string[]) {
|
|
58
|
+
super(log, lowCodeService, config, build, validate);
|
|
59
|
+
this.search = this.search.bind(this);
|
|
60
|
+
this.config = initializeConfig(config);
|
|
61
|
+
if (this.config) {
|
|
62
|
+
this.csv = this.config.csv;
|
|
63
|
+
this.fields = this.config.fields;
|
|
64
|
+
this.excluding = this.config.excluding;
|
|
65
|
+
}
|
|
66
|
+
if (!this.fields || this.fields.length === 0) {
|
|
67
|
+
this.fields = 'fields';
|
|
68
|
+
}
|
|
69
|
+
const m = getMetadataFunc(lowCodeService, dates, numbers);
|
|
70
|
+
if (m) {
|
|
71
|
+
this.dates = m.dates;
|
|
72
|
+
this.numbers = m.numbers;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
search(req: Request, res: Response) {
|
|
76
|
+
const s = fromRequest<S>(req, buildArray(this.array, this.fields, this.excluding));
|
|
77
|
+
const l = getParameters(s, this.config);
|
|
78
|
+
const s2 = format(s, this.dates, this.numbers);
|
|
79
|
+
this.lowCodeService.search(s2, l.limit, l.skipOrRefId, l.fields)
|
|
80
|
+
.then(result => jsonResult(res, result, this.csv, l.fields, this.config))
|
|
81
|
+
.catch(err => handleError(err, res, this.log));
|
|
82
|
+
}
|
|
83
|
+
}
|