express-ext 0.1.13 → 0.1.17
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 +1 -1
- package/lib/HealthController.js +4 -4
- package/lib/LoadController.js +1 -1
- package/lib/LoadSearchController.js +1 -1
- package/lib/LogController.js +67 -28
- package/lib/LowCodeController.js +1 -1
- package/lib/SearchController.js +1 -1
- package/lib/health.js +2 -2
- package/lib/http.js +38 -0
- package/lib/index.js +3 -1
- package/lib/log.js +127 -23
- package/lib/resources.js +55 -2
- package/lib/search.js +41 -14
- package/package.json +1 -1
- package/src/GenericSearchController.ts +3 -2
- package/src/HealthController.ts +5 -5
- package/src/LoadController.ts +2 -2
- package/src/LoadSearchController.ts +3 -2
- package/src/LogController.ts +100 -34
- package/src/LowCodeController.ts +3 -2
- package/src/SearchController.ts +3 -2
- package/src/health.ts +1 -1
- package/src/http.ts +32 -0
- package/src/index.ts +18 -0
- package/src/log.ts +124 -23
- package/src/metadata.ts +6 -4
- package/src/resources.ts +56 -1
- package/src/search.ts +38 -9
package/src/search.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {Request, Response} from 'express';
|
|
2
|
+
import {minimizeArray} from './http';
|
|
2
3
|
import {Attribute, Attributes} from './metadata';
|
|
3
4
|
|
|
4
5
|
export interface Filter {
|
|
@@ -41,7 +42,7 @@ export function buildResult<T>(r: SearchResult<T>, conf?: SearchConfig): any {
|
|
|
41
42
|
}
|
|
42
43
|
const x: any = {};
|
|
43
44
|
const li = (conf.list ? conf.list : 'list');
|
|
44
|
-
x[li] = r.list;
|
|
45
|
+
x[li] = minimizeArray(r.list);
|
|
45
46
|
const to = (conf.total ? conf.total : 'total');
|
|
46
47
|
x[to] = r.total;
|
|
47
48
|
if (r.nextPageToken && r.nextPageToken.length > 0) {
|
|
@@ -107,30 +108,58 @@ export function initializeConfig(conf?: SearchConfig): SearchConfig | undefined
|
|
|
107
108
|
}
|
|
108
109
|
return c;
|
|
109
110
|
}
|
|
110
|
-
export function fromRequest<S>(req: Request,
|
|
111
|
-
const s: any = (req.method === 'GET' ? fromUrl(req,
|
|
111
|
+
export function fromRequest<S>(req: Request, arr?: string[]): S {
|
|
112
|
+
const s: any = (req.method === 'GET' ? fromUrl(req, arr) : req.body);
|
|
112
113
|
return s;
|
|
113
114
|
}
|
|
114
|
-
export function
|
|
115
|
+
export function buildArray(arr?: string[], s0?: string, s1?: string, s2?: string): string[] {
|
|
116
|
+
const r: string[] = [];
|
|
117
|
+
if (arr && arr.length > 0) {
|
|
118
|
+
for (const a of arr) {
|
|
119
|
+
r.push(a);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (s0 && s0.length > 0) {
|
|
123
|
+
r.push(s0);
|
|
124
|
+
}
|
|
125
|
+
if (s1 && s1.length > 0) {
|
|
126
|
+
r.push(s1);
|
|
127
|
+
}
|
|
128
|
+
if (s2 && s2.length > 0) {
|
|
129
|
+
r.push(s2);
|
|
130
|
+
}
|
|
131
|
+
return r;
|
|
132
|
+
}
|
|
133
|
+
export function fromUrl<S>(req: Request, arr?: string[]): S {
|
|
134
|
+
/*
|
|
115
135
|
if (!fields || fields.length === 0) {
|
|
116
136
|
fields = 'fields';
|
|
117
137
|
}
|
|
138
|
+
*/
|
|
118
139
|
const s: any = {};
|
|
119
140
|
const obj = req.query;
|
|
120
141
|
const keys = Object.keys(obj);
|
|
121
142
|
for (const key of keys) {
|
|
122
|
-
if (key
|
|
143
|
+
if (inArray(key, arr)) {
|
|
123
144
|
const x = (obj[key] as string).split(',');
|
|
124
|
-
s
|
|
125
|
-
} else if (key === excluding) {
|
|
126
|
-
const x = (obj[key] as string).split(',');
|
|
127
|
-
s[key] = x;
|
|
145
|
+
setValue(s, key, x);
|
|
128
146
|
} else {
|
|
129
147
|
setValue(s, key, obj[key] as string);
|
|
130
148
|
}
|
|
131
149
|
}
|
|
132
150
|
return s;
|
|
133
151
|
}
|
|
152
|
+
export function inArray(s: string, arr?: string[]): boolean {
|
|
153
|
+
if (!arr || arr.length === 0) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
for (const a of arr) {
|
|
157
|
+
if (s === a) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
134
163
|
/*
|
|
135
164
|
export function setValue<T>(obj: T, path: string, value: string): void {
|
|
136
165
|
const paths = path.split('.');
|