express-ext 0.4.0 → 0.4.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/lib/GenericSearchController.js +38 -41
- package/lib/LoadSearchController.js +73 -80
- package/lib/LowCodeController.js +61 -68
- package/lib/SearchController.js +26 -29
- package/lib/resources.js +58 -56
- package/lib/search.js +348 -477
- package/package.json +1 -1
- package/src/GenericController.ts +101 -101
- package/src/GenericSearchController.ts +25 -30
- package/src/HealthController.ts +8 -8
- package/src/LoadController.ts +55 -48
- package/src/LoadSearchController.ts +63 -72
- package/src/LogController.ts +86 -84
- package/src/LowCodeController.ts +44 -54
- package/src/SearchController.ts +19 -23
- package/src/client.ts +46 -46
- package/src/edit.ts +45 -45
- package/src/health.ts +26 -26
- package/src/http.ts +139 -139
- package/src/index.ts +197 -197
- package/src/log.ts +155 -151
- package/src/metadata.ts +44 -27
- package/src/resources.ts +71 -69
- package/src/search.ts +342 -502
- package/src/view.ts +33 -33
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import { Request, Response } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { Request, Response } from "express"
|
|
2
|
+
import { resources } from "resources"
|
|
3
|
+
import { handleError, Log } from "./http"
|
|
4
|
+
import { LoadController, ViewService } from "./LoadController"
|
|
5
|
+
import { Attribute, Attributes } from "./metadata"
|
|
6
|
+
import { buildArray, Filter, format, fromRequest, getMetadataFunc, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult } from "./search"
|
|
6
7
|
|
|
7
8
|
export interface Search {
|
|
8
|
-
search(req: Request, res: Response): void
|
|
9
|
-
load(req: Request, res: Response): void
|
|
9
|
+
search(req: Request, res: Response): void
|
|
10
|
+
load(req: Request, res: Response): void
|
|
10
11
|
}
|
|
11
12
|
export interface Query<T, ID, S> extends ViewService<T, ID> {
|
|
12
|
-
search: (s: S, limit
|
|
13
|
-
metadata?(): Attributes | undefined
|
|
14
|
-
load(id: ID, ctx?: any): Promise<T | null
|
|
13
|
+
search: (s: S, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>
|
|
14
|
+
metadata?(): Attributes | undefined
|
|
15
|
+
load(id: ID, ctx?: any): Promise<T | null>
|
|
15
16
|
}
|
|
16
17
|
export interface SearchManager {
|
|
17
|
-
search(req: Request, res: Response): void
|
|
18
|
-
load(req: Request, res: Response): void
|
|
18
|
+
search(req: Request, res: Response): void
|
|
19
|
+
load(req: Request, res: Response): void
|
|
19
20
|
}
|
|
20
21
|
export function useSearchController<T, ID, S extends Filter>(
|
|
21
22
|
log: Log,
|
|
22
|
-
find: (s: S, limit
|
|
23
|
+
find: (s: S, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>,
|
|
23
24
|
viewService: ViewService<T, ID> | ((id: ID, ctx?: any) => Promise<T>),
|
|
24
25
|
array?: string[],
|
|
25
26
|
dates?: string[],
|
|
@@ -27,103 +28,93 @@ export function useSearchController<T, ID, S extends Filter>(
|
|
|
27
28
|
keys?: Attributes | Attribute[] | string[],
|
|
28
29
|
config?: SearchConfig | boolean,
|
|
29
30
|
): Search {
|
|
30
|
-
const c = new LoadSearchController(log, find, viewService, keys, config, dates, numbers)
|
|
31
|
-
c.array = array
|
|
32
|
-
return c
|
|
31
|
+
const c = new LoadSearchController(log, find, viewService, keys, config, dates, numbers)
|
|
32
|
+
c.array = array
|
|
33
|
+
return c
|
|
33
34
|
}
|
|
34
|
-
export const useSearchHandler = useSearchController
|
|
35
|
-
export const createSearchController = useSearchController
|
|
36
|
-
export const createSearchHandler = useSearchController
|
|
35
|
+
export const useSearchHandler = useSearchController
|
|
36
|
+
export const createSearchController = useSearchController
|
|
37
|
+
export const createSearchHandler = useSearchController
|
|
37
38
|
export class LoadSearchController<T, ID, S extends Filter> extends LoadController<T, ID> {
|
|
38
|
-
config?: SearchConfig
|
|
39
|
-
csv?: boolean
|
|
40
|
-
dates?: string[]
|
|
41
|
-
numbers?: string[]
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
array?: string[];
|
|
39
|
+
config?: SearchConfig
|
|
40
|
+
csv?: boolean
|
|
41
|
+
dates?: string[]
|
|
42
|
+
numbers?: string[]
|
|
43
|
+
excluding?: string
|
|
44
|
+
array?: string[]
|
|
45
45
|
constructor(
|
|
46
46
|
log: Log,
|
|
47
|
-
public find: (s: S, limit
|
|
47
|
+
public find: (s: S, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>,
|
|
48
48
|
viewService: ViewService<T, ID> | ((id: ID, ctx?: any) => Promise<T>),
|
|
49
49
|
keys?: Attributes | Attribute[] | string[],
|
|
50
50
|
config?: SearchConfig | boolean,
|
|
51
51
|
dates?: string[],
|
|
52
52
|
numbers?: string[],
|
|
53
53
|
) {
|
|
54
|
-
super(log, viewService, keys)
|
|
55
|
-
this.search = this.search.bind(this)
|
|
54
|
+
super(log, viewService, keys)
|
|
55
|
+
this.search = this.search.bind(this)
|
|
56
56
|
if (config) {
|
|
57
|
-
if (typeof config ===
|
|
58
|
-
this.csv = config
|
|
57
|
+
if (typeof config === "boolean") {
|
|
58
|
+
this.csv = config
|
|
59
59
|
} else {
|
|
60
|
-
this.config = initializeConfig(config)
|
|
60
|
+
this.config = initializeConfig(config)
|
|
61
61
|
if (this.config) {
|
|
62
|
-
this.csv = this.config.csv
|
|
63
|
-
this.
|
|
64
|
-
this.excluding = this.config.excluding;
|
|
62
|
+
this.csv = this.config.csv
|
|
63
|
+
this.excluding = this.config.excluding
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
|
-
|
|
69
|
-
this.fields = 'fields';
|
|
70
|
-
}
|
|
71
|
-
const m = getMetadataFunc(viewService, dates, numbers, keys);
|
|
67
|
+
const m = getMetadataFunc(viewService, dates, numbers, keys)
|
|
72
68
|
if (m) {
|
|
73
|
-
this.dates = m.dates
|
|
74
|
-
this.numbers = m.numbers
|
|
69
|
+
this.dates = m.dates
|
|
70
|
+
this.numbers = m.numbers
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
73
|
search(req: Request, res: Response): void {
|
|
78
|
-
const s = fromRequest<S>(req, buildArray(this.array,
|
|
79
|
-
const l = getParameters(s, this.config)
|
|
80
|
-
const s2 = format(s, this.dates, this.numbers)
|
|
74
|
+
const s = fromRequest<S>(req, buildArray(this.array, resources.fields, this.excluding))
|
|
75
|
+
const l = getParameters(s, this.config)
|
|
76
|
+
const s2 = format(s, this.dates, this.numbers)
|
|
81
77
|
this.find(s2, l.limit, l.pageOrNextPageToken, l.fields)
|
|
82
78
|
.then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
|
|
83
|
-
.catch((err) => handleError(err, res, this.log))
|
|
79
|
+
.catch((err) => handleError(err, res, this.log))
|
|
84
80
|
}
|
|
85
81
|
}
|
|
86
82
|
export class QueryController<T, ID, S extends Filter> extends LoadController<T, ID> {
|
|
87
|
-
config?: SearchConfig
|
|
88
|
-
csv?: boolean
|
|
89
|
-
dates?: string[]
|
|
90
|
-
numbers?: string[]
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
array?: string[];
|
|
83
|
+
config?: SearchConfig
|
|
84
|
+
csv?: boolean
|
|
85
|
+
dates?: string[]
|
|
86
|
+
numbers?: string[]
|
|
87
|
+
excluding?: string
|
|
88
|
+
array?: string[]
|
|
94
89
|
constructor(log: Log, protected query: Query<T, ID, S>, config?: SearchConfig | boolean, dates?: string[], numbers?: string[], array?: string[]) {
|
|
95
|
-
super(log, query)
|
|
96
|
-
this.search = this.search.bind(this)
|
|
97
|
-
this.array = array
|
|
90
|
+
super(log, query)
|
|
91
|
+
this.search = this.search.bind(this)
|
|
92
|
+
this.array = array
|
|
98
93
|
if (config) {
|
|
99
|
-
if (typeof config ===
|
|
100
|
-
this.csv = config
|
|
94
|
+
if (typeof config === "boolean") {
|
|
95
|
+
this.csv = config
|
|
101
96
|
} else {
|
|
102
|
-
this.config = initializeConfig(config)
|
|
97
|
+
this.config = initializeConfig(config)
|
|
103
98
|
if (this.config) {
|
|
104
|
-
this.csv = this.config.csv
|
|
105
|
-
this.
|
|
106
|
-
this.excluding = this.config.excluding;
|
|
99
|
+
this.csv = this.config.csv
|
|
100
|
+
this.excluding = this.config.excluding
|
|
107
101
|
}
|
|
108
102
|
}
|
|
109
103
|
}
|
|
110
|
-
|
|
111
|
-
this.fields = 'fields';
|
|
112
|
-
}
|
|
113
|
-
const m = getMetadataFunc(query, dates, numbers);
|
|
104
|
+
const m = getMetadataFunc(query, dates, numbers)
|
|
114
105
|
if (m) {
|
|
115
|
-
this.dates = m.dates
|
|
116
|
-
this.numbers = m.numbers
|
|
106
|
+
this.dates = m.dates
|
|
107
|
+
this.numbers = m.numbers
|
|
117
108
|
}
|
|
118
109
|
}
|
|
119
110
|
search(req: Request, res: Response): void {
|
|
120
|
-
const s = fromRequest<S>(req, buildArray(this.array,
|
|
121
|
-
const l = getParameters(s, this.config)
|
|
122
|
-
const s2 = format(s, this.dates, this.numbers)
|
|
111
|
+
const s = fromRequest<S>(req, buildArray(this.array, resources.fields, this.excluding))
|
|
112
|
+
const l = getParameters(s, this.config)
|
|
113
|
+
const s2 = format(s, this.dates, this.numbers)
|
|
123
114
|
this.query
|
|
124
115
|
.search(s2, l.limit, l.pageOrNextPageToken, l.fields)
|
|
125
116
|
.then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
|
|
126
|
-
.catch((err) => handleError(err, res, this.log))
|
|
117
|
+
.catch((err) => handleError(err, res, this.log))
|
|
127
118
|
}
|
|
128
119
|
}
|
|
129
|
-
export { QueryController as QueryHandler }
|
|
120
|
+
export { QueryController as QueryHandler }
|
package/src/LogController.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { Request, Response } from
|
|
2
|
-
import { SimpleMap } from
|
|
1
|
+
import { Request, Response } from "express"
|
|
2
|
+
import { SimpleMap } from "./log"
|
|
3
3
|
|
|
4
4
|
export interface NumberMap {
|
|
5
|
-
[key: string]: number
|
|
5
|
+
[key: string]: number
|
|
6
6
|
}
|
|
7
7
|
export interface LogConfig {
|
|
8
|
-
level?: string
|
|
9
|
-
map?: LogMapConfig
|
|
10
|
-
constants?: SimpleMap
|
|
11
|
-
name?: Name
|
|
8
|
+
level?: string
|
|
9
|
+
map?: LogMapConfig
|
|
10
|
+
constants?: SimpleMap
|
|
11
|
+
name?: Name
|
|
12
12
|
}
|
|
13
13
|
export interface LogMapConfig {
|
|
14
|
-
time?: string
|
|
15
|
-
level?: string
|
|
16
|
-
msg?: string
|
|
14
|
+
time?: string
|
|
15
|
+
level?: string
|
|
16
|
+
msg?: string
|
|
17
17
|
}
|
|
18
18
|
export interface LogMap {
|
|
19
|
-
time: string
|
|
20
|
-
level: string
|
|
21
|
-
msg: string
|
|
19
|
+
time: string
|
|
20
|
+
level: string
|
|
21
|
+
msg: string
|
|
22
22
|
}
|
|
23
23
|
export interface Name {
|
|
24
|
-
trace: string
|
|
25
|
-
debug: string
|
|
26
|
-
info: string
|
|
27
|
-
warn: string
|
|
28
|
-
error: string
|
|
29
|
-
panic: string
|
|
30
|
-
fatal: string
|
|
24
|
+
trace: string
|
|
25
|
+
debug: string
|
|
26
|
+
info: string
|
|
27
|
+
warn: string
|
|
28
|
+
error: string
|
|
29
|
+
panic: string
|
|
30
|
+
fatal: string
|
|
31
31
|
}
|
|
32
32
|
export interface Logger {
|
|
33
|
-
name: Name
|
|
34
|
-
level: number
|
|
35
|
-
map: LogMap
|
|
36
|
-
constants?: SimpleMap
|
|
37
|
-
trace(msg: string, m?: SimpleMap, ctx?: any): void
|
|
38
|
-
debug(msg: string, m?: SimpleMap, ctx?: any): void
|
|
39
|
-
info(msg: string, m?: SimpleMap, ctx?: any): void
|
|
40
|
-
warn(msg: string, m?: SimpleMap, ctx?: any): void
|
|
41
|
-
error(msg: string, m?: SimpleMap, ctx?: any): void
|
|
42
|
-
panic(msg: string, m?: SimpleMap, ctx?: any): void
|
|
43
|
-
fatal(msg: string, m?: SimpleMap, ctx?: any): void
|
|
44
|
-
isLevelEnabled(level: number): boolean
|
|
45
|
-
isTraceEnabled(): boolean
|
|
46
|
-
isDebugEnabled(): boolean
|
|
47
|
-
isInfoEnabled(): boolean
|
|
48
|
-
isWarnEnabled(): boolean
|
|
49
|
-
isErrorEnabled(): boolean
|
|
50
|
-
isPanicEnabled(): boolean
|
|
51
|
-
isFatalEnabled(): boolean
|
|
33
|
+
name: Name
|
|
34
|
+
level: number
|
|
35
|
+
map: LogMap
|
|
36
|
+
constants?: SimpleMap
|
|
37
|
+
trace(msg: string, m?: SimpleMap, ctx?: any): void
|
|
38
|
+
debug(msg: string, m?: SimpleMap, ctx?: any): void
|
|
39
|
+
info(msg: string, m?: SimpleMap, ctx?: any): void
|
|
40
|
+
warn(msg: string, m?: SimpleMap, ctx?: any): void
|
|
41
|
+
error(msg: string, m?: SimpleMap, ctx?: any): void
|
|
42
|
+
panic(msg: string, m?: SimpleMap, ctx?: any): void
|
|
43
|
+
fatal(msg: string, m?: SimpleMap, ctx?: any): void
|
|
44
|
+
isLevelEnabled(level: number): boolean
|
|
45
|
+
isTraceEnabled(): boolean
|
|
46
|
+
isDebugEnabled(): boolean
|
|
47
|
+
isInfoEnabled(): boolean
|
|
48
|
+
isWarnEnabled(): boolean
|
|
49
|
+
isErrorEnabled(): boolean
|
|
50
|
+
isPanicEnabled(): boolean
|
|
51
|
+
isFatalEnabled(): boolean
|
|
52
52
|
}
|
|
53
53
|
export const map: NumberMap = {
|
|
54
54
|
TRACE: -2,
|
|
@@ -57,80 +57,82 @@ export const map: NumberMap = {
|
|
|
57
57
|
WARN: 1,
|
|
58
58
|
ERROR: 2,
|
|
59
59
|
PANIC: 3,
|
|
60
|
-
FATAL: 4
|
|
61
|
-
}
|
|
60
|
+
FATAL: 4,
|
|
61
|
+
}
|
|
62
62
|
export class LogController {
|
|
63
|
-
map: NumberMap
|
|
64
|
-
update: (logger: Logger, obj: LogConfig, mp: NumberMap) => boolean
|
|
63
|
+
map: NumberMap
|
|
64
|
+
update: (logger: Logger, obj: LogConfig, mp: NumberMap) => boolean
|
|
65
65
|
constructor(public logger: Logger, updateL?: (logger: Logger, obj: LogConfig, mp: NumberMap) => boolean, mp?: NumberMap) {
|
|
66
|
-
this.map =
|
|
67
|
-
this.update = updateL ? updateL : updateLog
|
|
68
|
-
this.config = this.config.bind(this)
|
|
66
|
+
this.map = mp ? mp : map
|
|
67
|
+
this.update = updateL ? updateL : updateLog
|
|
68
|
+
this.config = this.config.bind(this)
|
|
69
69
|
}
|
|
70
70
|
config(req: Request, res: Response) {
|
|
71
|
-
const obj: LogConfig = req.body
|
|
72
|
-
if (!obj || (obj as any) ===
|
|
73
|
-
return res.status(400).end(
|
|
71
|
+
const obj: LogConfig = req.body
|
|
72
|
+
if (!obj || (obj as any) === "") {
|
|
73
|
+
return res.status(400).end("The request body cannot be empty")
|
|
74
74
|
}
|
|
75
75
|
if (!this.logger) {
|
|
76
|
-
return res.status(503).end(
|
|
76
|
+
return res.status(503).end("Logger is not available")
|
|
77
77
|
}
|
|
78
|
-
if (typeof obj.level ===
|
|
78
|
+
if (typeof obj.level === "string" && obj.level.length > 0) {
|
|
79
79
|
if (!this.map) {
|
|
80
|
-
return res.status(503).end(
|
|
80
|
+
return res.status(503).end("Map is not available")
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
const changed = this.update(this.logger, obj, this.map)
|
|
83
|
+
const changed = this.update(this.logger, obj, this.map)
|
|
84
84
|
if (changed) {
|
|
85
|
-
return res.status(200).json(true).end()
|
|
85
|
+
return res.status(200).json(true).end()
|
|
86
86
|
} else {
|
|
87
|
-
return res.status(204).json(false).end()
|
|
87
|
+
return res.status(204).json(false).end()
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
export function updateLog(logger: Logger, obj: LogConfig, mp: NumberMap): boolean {
|
|
92
|
-
let changed = false
|
|
93
|
-
if (typeof obj.level ===
|
|
94
|
-
const lv = mp[obj.level.toUpperCase()]
|
|
92
|
+
let changed = false
|
|
93
|
+
if (typeof obj.level === "string" && obj.level.length > 0) {
|
|
94
|
+
const lv = mp[obj.level.toUpperCase()]
|
|
95
95
|
if (lv !== undefined) {
|
|
96
|
-
logger.level = lv
|
|
97
|
-
changed = true
|
|
96
|
+
logger.level = lv
|
|
97
|
+
changed = true
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
if (obj.map) {
|
|
101
|
-
if (typeof obj.map.level ===
|
|
102
|
-
logger.map.level = obj.map.level
|
|
103
|
-
changed = true
|
|
101
|
+
if (typeof obj.map.level === "string" && obj.map.level.length > 0) {
|
|
102
|
+
logger.map.level = obj.map.level
|
|
103
|
+
changed = true
|
|
104
104
|
}
|
|
105
|
-
if (typeof obj.map.time ===
|
|
106
|
-
logger.map.time = obj.map.time
|
|
107
|
-
changed = true
|
|
105
|
+
if (typeof obj.map.time === "string" && obj.map.time.length > 0) {
|
|
106
|
+
logger.map.time = obj.map.time
|
|
107
|
+
changed = true
|
|
108
108
|
}
|
|
109
|
-
if (typeof obj.map.msg ===
|
|
110
|
-
logger.map.msg = obj.map.msg
|
|
111
|
-
changed = true
|
|
109
|
+
if (typeof obj.map.msg === "string" && obj.map.msg.length > 0) {
|
|
110
|
+
logger.map.msg = obj.map.msg
|
|
111
|
+
changed = true
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
if (obj.constants !== undefined && typeof obj.constants ===
|
|
115
|
-
const ks = Object.keys(obj.constants)
|
|
114
|
+
if (obj.constants !== undefined && typeof obj.constants === "object") {
|
|
115
|
+
const ks = Object.keys(obj.constants)
|
|
116
116
|
if (ks.length > 0) {
|
|
117
|
-
logger.constants = obj.constants
|
|
117
|
+
logger.constants = obj.constants
|
|
118
118
|
} else {
|
|
119
|
-
logger.constants = undefined
|
|
119
|
+
logger.constants = undefined
|
|
120
120
|
}
|
|
121
|
-
changed = true
|
|
121
|
+
changed = true
|
|
122
122
|
}
|
|
123
123
|
if (obj.name) {
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
if (
|
|
125
|
+
typeof obj.name.trace === "string" &&
|
|
126
|
+
typeof obj.name.debug === "string" &&
|
|
127
|
+
typeof obj.name.info === "string" &&
|
|
128
|
+
typeof obj.name.warn === "string" &&
|
|
129
|
+
typeof obj.name.error === "string" &&
|
|
130
|
+
typeof obj.name.panic === "string" &&
|
|
131
|
+
typeof obj.name.fatal === "string"
|
|
132
|
+
) {
|
|
133
|
+
logger.name = obj.name
|
|
134
|
+
changed = true
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
|
-
return changed
|
|
137
|
+
return changed
|
|
136
138
|
}
|
package/src/LowCodeController.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { Request, Response } from
|
|
2
|
-
import { Build, GenericController, GenericService } from
|
|
3
|
-
import { handleError, Log } from
|
|
4
|
-
import { ErrorMessage } from
|
|
5
|
-
import { StringMap } from
|
|
6
|
-
import { buildArray, Filter, format, fromRequest, getMetadataFunc, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult } from
|
|
1
|
+
import { Request, Response } from "express"
|
|
2
|
+
import { Build, GenericController, GenericService } from "./GenericController"
|
|
3
|
+
import { handleError, Log } from "./http"
|
|
4
|
+
import { ErrorMessage } from "./metadata"
|
|
5
|
+
import { resources, StringMap } from "./resources"
|
|
6
|
+
import { buildArray, Filter, format, fromRequest, getMetadataFunc, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult } from "./search"
|
|
7
7
|
|
|
8
8
|
export interface Service<T, ID, R, S extends Filter> extends GenericService<T, ID, R> {
|
|
9
|
-
search: (s: S, limit
|
|
9
|
+
search: (s: S, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>
|
|
10
10
|
}
|
|
11
11
|
export class LowcodeController<T, ID, S extends Filter> extends GenericController<T, ID> {
|
|
12
|
-
config?: SearchConfig
|
|
13
|
-
csv?: boolean
|
|
14
|
-
dates?: string[]
|
|
15
|
-
numbers?: string[]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
array?: string[];
|
|
12
|
+
config?: SearchConfig
|
|
13
|
+
csv?: boolean
|
|
14
|
+
dates?: string[]
|
|
15
|
+
numbers?: string[]
|
|
16
|
+
excluding?: string
|
|
17
|
+
array?: string[]
|
|
19
18
|
constructor(
|
|
20
19
|
log: Log,
|
|
21
20
|
public lowCodeService: Service<T, ID, number | ErrorMessage[], S>,
|
|
@@ -25,42 +24,37 @@ export class LowcodeController<T, ID, S extends Filter> extends GenericControlle
|
|
|
25
24
|
dates?: string[],
|
|
26
25
|
numbers?: string[],
|
|
27
26
|
) {
|
|
28
|
-
super(log, lowCodeService, build, validate)
|
|
29
|
-
this.search = this.search.bind(this)
|
|
30
|
-
this.config = initializeConfig(config)
|
|
27
|
+
super(log, lowCodeService, build, validate)
|
|
28
|
+
this.search = this.search.bind(this)
|
|
29
|
+
this.config = initializeConfig(config)
|
|
31
30
|
if (this.config) {
|
|
32
|
-
this.csv = this.config.csv
|
|
33
|
-
this.
|
|
34
|
-
this.excluding = this.config.excluding;
|
|
31
|
+
this.csv = this.config.csv
|
|
32
|
+
this.excluding = this.config.excluding
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
this.fields = 'fields';
|
|
38
|
-
}
|
|
39
|
-
const m = getMetadataFunc(lowCodeService, dates, numbers);
|
|
34
|
+
const m = getMetadataFunc(lowCodeService, dates, numbers)
|
|
40
35
|
if (m) {
|
|
41
|
-
this.dates = m.dates
|
|
42
|
-
this.numbers = m.numbers
|
|
36
|
+
this.dates = m.dates
|
|
37
|
+
this.numbers = m.numbers
|
|
43
38
|
}
|
|
44
39
|
}
|
|
45
40
|
search(req: Request, res: Response) {
|
|
46
|
-
const s = fromRequest<S>(req, buildArray(this.array,
|
|
47
|
-
const l = getParameters(s, this.config)
|
|
48
|
-
const s2 = format(s, this.dates, this.numbers)
|
|
41
|
+
const s = fromRequest<S>(req, buildArray(this.array, resources.fields, this.excluding))
|
|
42
|
+
const l = getParameters(s, this.config)
|
|
43
|
+
const s2 = format(s, this.dates, this.numbers)
|
|
49
44
|
this.lowCodeService
|
|
50
45
|
.search(s2, l.limit, l.pageOrNextPageToken, l.fields)
|
|
51
46
|
.then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
|
|
52
|
-
.catch((err) => handleError(err, res, this.log))
|
|
47
|
+
.catch((err) => handleError(err, res, this.log))
|
|
53
48
|
}
|
|
54
49
|
}
|
|
55
|
-
export { LowcodeController as LowcodeHandler }
|
|
50
|
+
export { LowcodeController as LowcodeHandler }
|
|
56
51
|
export class Controller<T, ID, S extends Filter> extends GenericController<T, ID> {
|
|
57
|
-
config?: SearchConfig
|
|
58
|
-
csv?: boolean
|
|
59
|
-
dates?: string[]
|
|
60
|
-
numbers?: string[]
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
array?: string[];
|
|
52
|
+
config?: SearchConfig
|
|
53
|
+
csv?: boolean
|
|
54
|
+
dates?: string[]
|
|
55
|
+
numbers?: string[]
|
|
56
|
+
excluding?: string
|
|
57
|
+
array?: string[]
|
|
64
58
|
constructor(
|
|
65
59
|
log: Log,
|
|
66
60
|
public lowCodeService: Service<T, ID, number | T | ErrorMessage[], S>,
|
|
@@ -70,30 +64,26 @@ export class Controller<T, ID, S extends Filter> extends GenericController<T, ID
|
|
|
70
64
|
dates?: string[],
|
|
71
65
|
numbers?: string[],
|
|
72
66
|
) {
|
|
73
|
-
super(log, lowCodeService, build, validate)
|
|
74
|
-
this.search = this.search.bind(this)
|
|
75
|
-
this.config = initializeConfig(config)
|
|
67
|
+
super(log, lowCodeService, build, validate)
|
|
68
|
+
this.search = this.search.bind(this)
|
|
69
|
+
this.config = initializeConfig(config)
|
|
76
70
|
if (this.config) {
|
|
77
|
-
this.csv = this.config.csv
|
|
78
|
-
this.
|
|
79
|
-
this.excluding = this.config.excluding;
|
|
80
|
-
}
|
|
81
|
-
if (!this.fields || this.fields.length === 0) {
|
|
82
|
-
this.fields = 'fields';
|
|
71
|
+
this.csv = this.config.csv
|
|
72
|
+
this.excluding = this.config.excluding
|
|
83
73
|
}
|
|
84
|
-
const m = getMetadataFunc(lowCodeService, dates, numbers)
|
|
74
|
+
const m = getMetadataFunc(lowCodeService, dates, numbers)
|
|
85
75
|
if (m) {
|
|
86
|
-
this.dates = m.dates
|
|
87
|
-
this.numbers = m.numbers
|
|
76
|
+
this.dates = m.dates
|
|
77
|
+
this.numbers = m.numbers
|
|
88
78
|
}
|
|
89
79
|
}
|
|
90
80
|
search(req: Request, res: Response) {
|
|
91
|
-
const s = fromRequest<S>(req, buildArray(this.array,
|
|
92
|
-
const l = getParameters(s, this.config)
|
|
93
|
-
const s2 = format(s, this.dates, this.numbers)
|
|
81
|
+
const s = fromRequest<S>(req, buildArray(this.array, resources.fields, this.excluding))
|
|
82
|
+
const l = getParameters(s, this.config)
|
|
83
|
+
const s2 = format(s, this.dates, this.numbers)
|
|
94
84
|
this.lowCodeService
|
|
95
85
|
.search(s2, l.limit, l.pageOrNextPageToken, l.fields)
|
|
96
86
|
.then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
|
|
97
|
-
.catch((err) => handleError(err, res, this.log))
|
|
87
|
+
.catch((err) => handleError(err, res, this.log))
|
|
98
88
|
}
|
|
99
89
|
}
|
package/src/SearchController.ts
CHANGED
|
@@ -1,43 +1,39 @@
|
|
|
1
|
-
import { Request, Response } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Request, Response } from "express"
|
|
2
|
+
import { resources } from "resources"
|
|
3
|
+
import { handleError, Log } from "./http"
|
|
4
|
+
import { buildArray, Filter, format, fromRequest, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult } from "./search"
|
|
4
5
|
|
|
5
6
|
export class SearchController<T, S extends Filter> {
|
|
6
|
-
config?: SearchConfig
|
|
7
|
-
csv?: boolean
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
array?: string[];
|
|
7
|
+
config?: SearchConfig
|
|
8
|
+
csv?: boolean
|
|
9
|
+
excluding?: string
|
|
10
|
+
array?: string[]
|
|
11
11
|
constructor(
|
|
12
12
|
protected log: Log,
|
|
13
|
-
public find: (s: S, limit
|
|
13
|
+
public find: (s: S, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>,
|
|
14
14
|
config?: SearchConfig | boolean,
|
|
15
15
|
public dates?: string[],
|
|
16
16
|
public numbers?: string[],
|
|
17
17
|
) {
|
|
18
|
-
this.search = this.search.bind(this)
|
|
18
|
+
this.search = this.search.bind(this)
|
|
19
19
|
if (config) {
|
|
20
|
-
if (typeof config ===
|
|
21
|
-
this.csv = config
|
|
20
|
+
if (typeof config === "boolean") {
|
|
21
|
+
this.csv = config
|
|
22
22
|
} else {
|
|
23
|
-
this.config = initializeConfig(config)
|
|
23
|
+
this.config = initializeConfig(config)
|
|
24
24
|
if (this.config) {
|
|
25
|
-
this.csv = this.config.csv
|
|
26
|
-
this.
|
|
27
|
-
this.excluding = this.config.excluding;
|
|
25
|
+
this.csv = this.config.csv
|
|
26
|
+
this.excluding = this.config.excluding
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
if (!this.fields || this.fields.length === 0) {
|
|
32
|
-
this.fields = 'fields';
|
|
33
|
-
}
|
|
34
30
|
}
|
|
35
31
|
search(req: Request, res: Response) {
|
|
36
|
-
const s = fromRequest<S>(req, buildArray(this.array,
|
|
37
|
-
const l = getParameters(s, this.config)
|
|
38
|
-
const s2 = format(s, this.dates, this.numbers)
|
|
32
|
+
const s = fromRequest<S>(req, buildArray(this.array, resources.fields, this.excluding))
|
|
33
|
+
const l = getParameters(s, this.config)
|
|
34
|
+
const s2 = format(s, this.dates, this.numbers)
|
|
39
35
|
this.find(s2, l.limit, l.pageOrNextPageToken, l.fields)
|
|
40
36
|
.then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
|
|
41
|
-
.catch((err) => handleError(err, res, this.log))
|
|
37
|
+
.catch((err) => handleError(err, res, this.log))
|
|
42
38
|
}
|
|
43
39
|
}
|