express-ext 0.2.3 → 0.2.5

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/search.js CHANGED
@@ -1,11 +1,103 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var http_1 = require("./http");
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ var http_1 = require('./http');
4
+ function getOffset(limit, page) {
5
+ var offset = limit * (page - 1);
6
+ return offset < 0 ? 0 : offset;
7
+ }
8
+ exports.getOffset = getOffset;
9
+ function getPageTotal(pageSize, total) {
10
+ if (!pageSize || pageSize <= 0) {
11
+ return 1;
12
+ } else {
13
+ if (!total) {
14
+ total = 0;
15
+ }
16
+ if (total % pageSize === 0) {
17
+ return Math.floor(total / pageSize);
18
+ }
19
+ return Math.floor(total / pageSize + 1);
20
+ }
21
+ }
22
+ exports.getPageTotal = getPageTotal;
23
+ function buildPages(pageSize, total) {
24
+ var pageTotal = getPageTotal(pageSize, total);
25
+ if (pageTotal <= 1) {
26
+ return [1];
27
+ }
28
+ var arr = [];
29
+ for (var i = 1; i <= pageTotal; i++) {
30
+ arr.push(i);
31
+ }
32
+ return arr;
33
+ }
34
+ exports.buildPages = buildPages;
35
+ function getPageQuery(query, page) {
36
+ var s = page && page.length > 0 ? page : 'page';
37
+ var i = query.indexOf(s + '=');
38
+ if (i < 0) {
39
+ return '';
40
+ }
41
+ var j = query.indexOf('&', i + s.length);
42
+ return j < 0 ? query.substring(i) : query.substring(i, j);
43
+ }
44
+ exports.getPageQuery = getPageQuery;
45
+ var PartialTrue = 'partial=true';
46
+ function removePageQuery(query, page, partialIsTrue) {
47
+ if (query.length == 0) {
48
+ return query;
49
+ }
50
+ var partialTrue = partialIsTrue && partialIsTrue.length > 0 ? partialIsTrue : PartialTrue;
51
+ var p1 = '&' + partialTrue;
52
+ var q1 = query.indexOf(p1);
53
+ if (q1 >= 0) {
54
+ query = query.substring(0, q1) + query.substring(q1 + partialTrue.length + 2);
55
+ } else {
56
+ var p2 = partialTrue + '&';
57
+ var q2 = query.indexOf(p2);
58
+ if (q2 >= 0) {
59
+ query = query.substring(0, q1) + query.substring(q1 + partialTrue.length + 2);
60
+ }
61
+ }
62
+ var pageQuery = getPageQuery(query, page);
63
+ if (pageQuery.length == 0) {
64
+ return query;
65
+ } else {
66
+ var x = pageQuery + '&';
67
+ if (query.indexOf(x) >= 0) {
68
+ return query.replace(x, '');
69
+ }
70
+ var x2 = '&' + pageQuery;
71
+ if (query.indexOf(x2) >= 0) {
72
+ return query.replace(x2, '');
73
+ }
74
+ return query.replace(pageQuery, '');
75
+ }
76
+ }
77
+ exports.removePageQuery = removePageQuery;
78
+ function hasQuery(req) {
79
+ return req.url.indexOf('?') >= 0;
80
+ }
81
+ exports.hasQuery = hasQuery;
82
+ function getQuery(url) {
83
+ var i = url.indexOf('?');
84
+ return i < 0 ? '' : url.substring(i + 1);
85
+ }
86
+ exports.getQuery = getQuery;
87
+ function buildPageQuery(query) {
88
+ var qr = removePageQuery(query);
89
+ return qr.length == 0 ? qr : '&' + qr;
90
+ }
91
+ exports.buildPageQuery = buildPageQuery;
92
+ function buildPageQueryFromUrl(url) {
93
+ var query = getQuery(url);
94
+ return buildPageQuery(query);
95
+ }
96
+ exports.buildPageQueryFromUrl = buildPageQueryFromUrl;
4
97
  function jsonResult(res, result, quick, fields, config) {
5
98
  if (quick && fields && fields.length > 0) {
6
99
  res.status(200).json(toCsv(fields, result)).end();
7
- }
8
- else {
100
+ } else {
9
101
  res.status(200).json(buildResult(result, config)).end();
10
102
  }
11
103
  }
@@ -15,16 +107,16 @@ function buildResult(r, conf) {
15
107
  return r;
16
108
  }
17
109
  var x = {};
18
- var li = (conf.list ? conf.list : 'list');
110
+ var li = conf.list ? conf.list : 'list';
19
111
  x[li] = http_1.minimizeArray(r.list);
20
- var to = (conf.total ? conf.total : 'total');
112
+ var to = conf.total ? conf.total : 'total';
21
113
  x[to] = r.total;
22
114
  if (r.nextPageToken && r.nextPageToken.length > 0) {
23
- var t = (conf.token ? conf.token : 'token');
115
+ var t = conf.token ? conf.token : 'token';
24
116
  x[t] = r.nextPageToken;
25
117
  }
26
118
  if (r.last) {
27
- var l = (conf.last ? conf.last : 'last');
119
+ var l = conf.last ? conf.last : 'last';
28
120
  x[l] = r.last;
29
121
  }
30
122
  return x;
@@ -46,7 +138,7 @@ function initializeConfig(conf) {
46
138
  limit: conf.limit,
47
139
  skip: conf.skip,
48
140
  refId: conf.refId,
49
- firstLimit: conf.firstLimit
141
+ firstLimit: conf.firstLimit,
50
142
  };
51
143
  if (!c.excluding || c.excluding.length === 0) {
52
144
  c.excluding = 'excluding';
@@ -85,7 +177,7 @@ function initializeConfig(conf) {
85
177
  }
86
178
  exports.initializeConfig = initializeConfig;
87
179
  function fromRequest(req, arr) {
88
- var s = (req.method === 'GET' ? fromUrl(req, arr) : req.body);
180
+ var s = req.method === 'GET' ? fromUrl(req, arr) : req.body;
89
181
  return s;
90
182
  }
91
183
  exports.fromRequest = fromRequest;
@@ -118,8 +210,7 @@ function fromUrl(req, arr) {
118
210
  if (inArray(key, arr)) {
119
211
  var x = obj[key].split(',');
120
212
  setValue(s, key, x);
121
- }
122
- else {
213
+ } else {
123
214
  setValue(s, key, obj[key]);
124
215
  }
125
216
  }
@@ -163,12 +254,10 @@ var setKey = function (_object, _isArrayKey, _key, _nextValue) {
163
254
  if (_isArrayKey) {
164
255
  if (_object.length > _key) {
165
256
  _object[_key] = _nextValue;
166
- }
167
- else {
257
+ } else {
168
258
  _object.push(_nextValue);
169
259
  }
170
- }
171
- else {
260
+ } else {
172
261
  _object[_key] = _nextValue;
173
262
  }
174
263
  return _object;
@@ -187,7 +276,7 @@ function getParameters(obj, config) {
187
276
  if (!refId) {
188
277
  refId = o['nextPageToken'];
189
278
  }
190
- var r = { fields: fields, refId: refId };
279
+ var r = { fields: fields, nextPageToken: refId };
191
280
  var pageSize = o['limit'];
192
281
  if (!pageSize) {
193
282
  pageSize = o['pageSize'];
@@ -200,8 +289,8 @@ function getParameters(obj, config) {
200
289
  if (skip && !isNaN(skip)) {
201
290
  var iskip = Math.floor(parseFloat(skip));
202
291
  if (iskip >= 0) {
203
- r.skip = iskip;
204
- r.skipOrRefId = r.skip;
292
+ r.offset = iskip;
293
+ r.offsetOrNextPageToken = r.offset;
205
294
  deletePageInfo(o);
206
295
  return r;
207
296
  }
@@ -228,32 +317,31 @@ function getParameters(obj, config) {
228
317
  if (firstPageSize && !isNaN(firstPageSize)) {
229
318
  var ifirstPageSize = Math.floor(parseFloat(firstPageSize));
230
319
  if (ifirstPageSize > 0) {
231
- r.skip = ipageSize * (ipageIndex - 2) + ifirstPageSize;
232
- r.skipOrRefId = r.skip;
320
+ r.offset = ipageSize * (ipageIndex - 2) + ifirstPageSize;
321
+ r.offsetOrNextPageToken = r.offset;
233
322
  deletePageInfo(o);
234
323
  return r;
235
324
  }
236
325
  }
237
- r.skip = ipageSize * (ipageIndex - 1);
238
- r.skipOrRefId = r.skip;
326
+ r.offset = ipageSize * (ipageIndex - 1);
327
+ r.offsetOrNextPageToken = r.offset;
239
328
  deletePageInfo(o);
240
329
  return r;
241
330
  }
242
- r.skip = 0;
243
- if (r.refId && r.refId.length > 0) {
244
- r.skipOrRefId = r.refId;
331
+ r.offset = 0;
332
+ if (r.nextPageToken && r.nextPageToken.length > 0) {
333
+ r.offsetOrNextPageToken = r.nextPageToken;
245
334
  }
246
335
  deletePageInfo(o);
247
336
  return r;
248
337
  }
249
338
  }
250
- if (r.refId && r.refId.length > 0) {
251
- r.skipOrRefId = r.refId;
339
+ if (r.nextPageToken && r.nextPageToken.length > 0) {
340
+ r.offsetOrNextPageToken = r.nextPageToken;
252
341
  }
253
342
  deletePageInfo(o);
254
343
  return r;
255
- }
256
- else {
344
+ } else {
257
345
  var sfield = config.fields;
258
346
  if (!sfield || sfield.length === 0) {
259
347
  sfield = 'fields';
@@ -269,7 +357,7 @@ function getParameters(obj, config) {
269
357
  strRefId = 'refId';
270
358
  }
271
359
  var refId = o[strRefId];
272
- var r = { fields: fields, refId: refId };
360
+ var r = { fields: fields, nextPageToken: refId };
273
361
  var strLimit = config.limit;
274
362
  if (!strLimit || strLimit.length === 0) {
275
363
  strLimit = 'limit';
@@ -288,8 +376,8 @@ function getParameters(obj, config) {
288
376
  if (skip && !isNaN(skip)) {
289
377
  var iskip = Math.floor(parseFloat(skip));
290
378
  if (iskip >= 0) {
291
- r.skip = iskip;
292
- r.skipOrRefId = r.skip;
379
+ r.offset = iskip;
380
+ r.offsetOrNextPageToken = r.offset;
293
381
  deletePageInfo(o, arr);
294
382
  return r;
295
383
  }
@@ -312,27 +400,27 @@ function getParameters(obj, config) {
312
400
  if (firstPageSize && !isNaN(firstPageSize)) {
313
401
  var ifirstPageSize = Math.floor(parseFloat(firstPageSize));
314
402
  if (ifirstPageSize > 0) {
315
- r.skip = ipageSize * (ipageIndex - 2) + ifirstPageSize;
316
- r.skipOrRefId = r.skip;
403
+ r.offset = ipageSize * (ipageIndex - 2) + ifirstPageSize;
404
+ r.offsetOrNextPageToken = r.offset;
317
405
  deletePageInfo(o, arr);
318
406
  return r;
319
407
  }
320
408
  }
321
- r.skip = ipageSize * (ipageIndex - 1);
322
- r.skipOrRefId = r.skip;
409
+ r.offset = ipageSize * (ipageIndex - 1);
410
+ r.offsetOrNextPageToken = r.offset;
323
411
  deletePageInfo(o, arr);
324
412
  return r;
325
413
  }
326
- r.skip = 0;
327
- if (r.refId && r.refId.length > 0) {
328
- r.skipOrRefId = r.refId;
414
+ r.offset = 0;
415
+ if (r.nextPageToken && r.nextPageToken.length > 0) {
416
+ r.offsetOrNextPageToken = r.nextPageToken;
329
417
  }
330
418
  deletePageInfo(o, arr);
331
419
  return r;
332
420
  }
333
421
  }
334
- if (r.refId && r.refId.length > 0) {
335
- r.skipOrRefId = r.refId;
422
+ if (r.nextPageToken && r.nextPageToken.length > 0) {
423
+ r.offsetOrNextPageToken = r.nextPageToken;
336
424
  }
337
425
  deletePageInfo(o, arr);
338
426
  return r;
@@ -352,8 +440,7 @@ function deletePageInfo(obj, arr) {
352
440
  delete obj['firstPageSize'];
353
441
  delete obj['refId'];
354
442
  delete obj['nextPageToken'];
355
- }
356
- else {
443
+ } else {
357
444
  for (var _i = 0, arr_3 = arr; _i < arr_3.length; _i++) {
358
445
  var o = arr_3[_i];
359
446
  if (o && o.length > 0) {
@@ -367,8 +454,7 @@ var re = /"/g;
367
454
  function toCsv(fields, r) {
368
455
  if (!r || r.list.length === 0) {
369
456
  return '0';
370
- }
371
- else {
457
+ } else {
372
458
  var e = '';
373
459
  var s = 'string';
374
460
  var n = 'number';
@@ -383,23 +469,18 @@ function toCsv(fields, r) {
383
469
  var v = item[name];
384
470
  if (!v) {
385
471
  cols.push(e);
386
- }
387
- else {
472
+ } else {
388
473
  if (typeof v === s) {
389
474
  if (s.indexOf(',') >= 0) {
390
475
  cols.push('"' + v.replace(re, b) + '"');
391
- }
392
- else {
476
+ } else {
393
477
  cols.push(v);
394
478
  }
395
- }
396
- else if (v instanceof Date) {
479
+ } else if (v instanceof Date) {
397
480
  cols.push(v.toISOString());
398
- }
399
- else if (typeof v === n) {
481
+ } else if (typeof v === n) {
400
482
  cols.push(v.toString());
401
- }
402
- else {
483
+ } else {
403
484
  cols.push('');
404
485
  }
405
486
  }
@@ -419,8 +500,7 @@ function buildMetadata(attributes, includeDate) {
419
500
  var attr = attributes[key];
420
501
  if (attr.type === 'number' || attr.type === 'integer') {
421
502
  numbers.push(key);
422
- }
423
- else if (attr.type === 'datetime' || (includeDate === true && attr.type === 'date')) {
503
+ } else if (attr.type === 'datetime' || (includeDate === true && attr.type === 'date')) {
424
504
  dates.push(key);
425
505
  }
426
506
  }
@@ -442,8 +522,7 @@ function toDate(v) {
442
522
  }
443
523
  if (v instanceof Date) {
444
524
  return v;
445
- }
446
- else if (typeof v === 'number') {
525
+ } else if (typeof v === 'number') {
447
526
  return new Date(v);
448
527
  }
449
528
  var i = v.indexOf(_datereg);
@@ -452,16 +531,13 @@ function toDate(v) {
452
531
  if (m !== null) {
453
532
  var d = parseInt(m[0], 10);
454
533
  return new Date(d);
455
- }
456
- else {
534
+ } else {
457
535
  return null;
458
536
  }
459
- }
460
- else {
537
+ } else {
461
538
  if (isNaN(v)) {
462
539
  return new Date(v);
463
- }
464
- else {
540
+ } else {
465
541
  var d = parseInt(v, 10);
466
542
  return new Date(d);
467
543
  }
@@ -482,13 +558,11 @@ function format(obj, dates, nums) {
482
558
  if (d) {
483
559
  if (!(d instanceof Date) || d.toString() === 'Invalid Date') {
484
560
  delete o[s];
485
- }
486
- else {
561
+ } else {
487
562
  o[s] = d;
488
563
  }
489
564
  }
490
- }
491
- else if (typeof v === 'object') {
565
+ } else if (typeof v === 'object') {
492
566
  var keys = Object.keys(v);
493
567
  for (var _a = 0, keys_3 = keys; _a < keys_3.length; _a++) {
494
568
  var key = keys_3[_a];
@@ -501,8 +575,7 @@ function format(obj, dates, nums) {
501
575
  if (d2) {
502
576
  if (!(d2 instanceof Date) || d2.toString() === 'Invalid Date') {
503
577
  delete v[key];
504
- }
505
- else {
578
+ } else {
506
579
  v[key] = d2;
507
580
  }
508
581
  }
@@ -528,13 +601,11 @@ function format(obj, dates, nums) {
528
601
  if (!isNaN(v)) {
529
602
  delete o[s];
530
603
  continue;
531
- }
532
- else {
604
+ } else {
533
605
  var i = parseFloat(v);
534
606
  o[s] = i;
535
607
  }
536
- }
537
- else if (typeof v === 'object') {
608
+ } else if (typeof v === 'object') {
538
609
  var keys = Object.keys(v);
539
610
  for (var _c = 0, keys_4 = keys; _c < keys_4.length; _c++) {
540
611
  var key = keys_4[_c];
@@ -549,8 +620,7 @@ function format(obj, dates, nums) {
549
620
  if (typeof v2 === 'string') {
550
621
  if (!isNaN(v2)) {
551
622
  delete v[key];
552
- }
553
- else {
623
+ } else {
554
624
  var i = parseFloat(v2);
555
625
  v[key] = i;
556
626
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-ext",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "express-ext",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
@@ -1,9 +1,9 @@
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 {buildArray, Filter, format, fromRequest, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult} from './search';
6
- import {getMetadataFunc} from './search_func';
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 { buildArray, Filter, format, fromRequest, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult } from './search';
6
+ import { getMetadataFunc } from './search_func';
7
7
 
8
8
  export class GenericSearchController<T, ID, S extends Filter> extends GenericController<T, ID> {
9
9
  config?: SearchConfig;
@@ -13,7 +13,16 @@ export class GenericSearchController<T, ID, S extends Filter> extends GenericCon
13
13
  fields?: string;
14
14
  excluding?: string;
15
15
  array?: string[];
16
- constructor(log: Log, public find: (s: S, limit?: number, skip?: number|string, fields?: string[]) => Promise<SearchResult<T>>, service: GenericService<T, ID, number|ErrorMessage[]>, config?: SearchConfig, build?: Build<T>, validate?: (obj: T, patch?: boolean) => Promise<ErrorMessage[]>, dates?: string[], numbers?: string[]) {
16
+ constructor(
17
+ log: Log,
18
+ public find: (s: S, limit?: number, skip?: number | string, fields?: string[]) => Promise<SearchResult<T>>,
19
+ service: GenericService<T, ID, number | ErrorMessage[]>,
20
+ config?: SearchConfig,
21
+ build?: Build<T>,
22
+ validate?: (obj: T, patch?: boolean) => Promise<ErrorMessage[]>,
23
+ dates?: string[],
24
+ numbers?: string[],
25
+ ) {
17
26
  super(log, service, build, validate);
18
27
  this.search = this.search.bind(this);
19
28
  this.config = initializeConfig(config);
@@ -35,8 +44,8 @@ export class GenericSearchController<T, ID, S extends Filter> extends GenericCon
35
44
  const s = fromRequest<S>(req, buildArray(this.array, this.fields, this.excluding));
36
45
  const l = getParameters(s, this.config);
37
46
  const s2 = format(s, this.dates, this.numbers);
38
- this.find(s2, l.limit, l.skipOrRefId, l.fields)
39
- .then(result => jsonResult(res, result, this.csv, l.fields, this.config))
40
- .catch(err => handleError(err, res, this.log));
47
+ this.find(s2, l.limit, l.offsetOrNextPageToken, l.fields)
48
+ .then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
49
+ .catch((err) => handleError(err, res, this.log));
41
50
  }
42
51
  }
@@ -1,24 +1,33 @@
1
- import {Request, Response} from 'express';
2
- import {handleError, Log} from './http';
3
- import {LoadController, ViewService} from './LoadController';
4
- import {Attribute, Attributes} from './metadata';
5
- import {buildArray, Filter, format, fromRequest, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult} from './search';
6
- import {getMetadataFunc} from './search_func';
1
+ import { Request, Response } from 'express';
2
+ import { handleError, Log } from './http';
3
+ import { LoadController, ViewService } from './LoadController';
4
+ import { Attribute, Attributes } from './metadata';
5
+ import { buildArray, Filter, format, fromRequest, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult } from './search';
6
+ import { getMetadataFunc } from './search_func';
7
7
 
8
8
  export interface Search {
9
9
  search(req: Request, res: Response): void;
10
10
  load(req: Request, res: Response): void;
11
11
  }
12
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>;
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
16
  }
17
17
  export interface SearchManager {
18
18
  search(req: Request, res: Response): void;
19
19
  load(req: Request, res: Response): void;
20
20
  }
21
- export function useSearchController<T, ID, S extends Filter>(log: Log, find: (s: S, limit?: number, skip?: number|string, fields?: string[]) => Promise<SearchResult<T>>, viewService: ViewService<T, ID> | ((id: ID, ctx?: any) => Promise<T>), array?: string[], dates?: string[], numbers?: string[], keys?: Attributes|Attribute[]|string[], config?: SearchConfig|boolean): Search {
21
+ export function useSearchController<T, ID, S extends Filter>(
22
+ log: Log,
23
+ find: (s: S, limit?: number, skip?: number | string, fields?: string[]) => Promise<SearchResult<T>>,
24
+ viewService: ViewService<T, ID> | ((id: ID, ctx?: any) => Promise<T>),
25
+ array?: string[],
26
+ dates?: string[],
27
+ numbers?: string[],
28
+ keys?: Attributes | Attribute[] | string[],
29
+ config?: SearchConfig | boolean,
30
+ ): Search {
22
31
  const c = new LoadSearchController(log, find, viewService, keys, config, dates, numbers);
23
32
  c.array = array;
24
33
  return c;
@@ -34,7 +43,15 @@ export class LoadSearchController<T, ID, S extends Filter> extends LoadControlle
34
43
  fields?: string;
35
44
  excluding?: string;
36
45
  array?: string[];
37
- constructor(log: Log, public find: (s: S, limit?: number, skip?: number|string, fields?: string[]) => Promise<SearchResult<T>>, viewService: ViewService<T, ID> | ((id: ID, ctx?: any) => Promise<T>), keys?: Attributes|Attribute[]|string[], config?: SearchConfig|boolean, dates?: string[], numbers?: string[]) {
46
+ constructor(
47
+ log: Log,
48
+ public find: (s: S, limit?: number, skip?: number | string, fields?: string[]) => Promise<SearchResult<T>>,
49
+ viewService: ViewService<T, ID> | ((id: ID, ctx?: any) => Promise<T>),
50
+ keys?: Attributes | Attribute[] | string[],
51
+ config?: SearchConfig | boolean,
52
+ dates?: string[],
53
+ numbers?: string[],
54
+ ) {
38
55
  super(log, viewService, keys);
39
56
  this.search = this.search.bind(this);
40
57
  if (config) {
@@ -62,9 +79,9 @@ export class LoadSearchController<T, ID, S extends Filter> extends LoadControlle
62
79
  const s = fromRequest<S>(req, buildArray(this.array, this.fields, this.excluding));
63
80
  const l = getParameters(s, this.config);
64
81
  const s2 = format(s, this.dates, this.numbers);
65
- this.find(s2, l.limit, l.skipOrRefId, l.fields)
66
- .then(result => jsonResult(res, result, this.csv, l.fields, this.config))
67
- .catch(err => handleError(err, res, this.log));
82
+ this.find(s2, l.limit, l.offsetOrNextPageToken, l.fields)
83
+ .then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
84
+ .catch((err) => handleError(err, res, this.log));
68
85
  }
69
86
  }
70
87
  export class QueryController<T, ID, S extends Filter> extends LoadController<T, ID> {
@@ -75,7 +92,7 @@ export class QueryController<T, ID, S extends Filter> extends LoadController<T,
75
92
  fields?: string;
76
93
  excluding?: string;
77
94
  array?: string[];
78
- constructor(log: Log, protected query: Query<T, ID, S>, config?: SearchConfig|boolean, dates?: string[], numbers?: string[], array?: string[]) {
95
+ constructor(log: Log, protected query: Query<T, ID, S>, config?: SearchConfig | boolean, dates?: string[], numbers?: string[], array?: string[]) {
79
96
  super(log, query);
80
97
  this.search = this.search.bind(this);
81
98
  this.array = array;
@@ -104,9 +121,10 @@ export class QueryController<T, ID, S extends Filter> extends LoadController<T,
104
121
  const s = fromRequest<S>(req, buildArray(this.array, this.fields, this.excluding));
105
122
  const l = getParameters(s, this.config);
106
123
  const s2 = format(s, this.dates, this.numbers);
107
- this.query.search(s2, l.limit, l.skipOrRefId, l.fields)
108
- .then(result => jsonResult(res, result, this.csv, l.fields, this.config))
109
- .catch(err => handleError(err, res, this.log));
124
+ this.query
125
+ .search(s2, l.limit, l.offsetOrNextPageToken, l.fields)
126
+ .then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
127
+ .catch((err) => handleError(err, res, this.log));
110
128
  }
111
129
  }
112
- export {QueryController as QueryHandler};
130
+ export { QueryController as QueryHandler };
@@ -1,12 +1,12 @@
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 {buildArray, Filter, format, fromRequest, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult} from './search';
6
- import {getMetadataFunc} from './search_func';
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 { buildArray, Filter, format, fromRequest, getParameters, initializeConfig, jsonResult, SearchConfig, SearchResult } from './search';
6
+ import { getMetadataFunc } from './search_func';
7
7
 
8
8
  export interface Service<T, ID, R, S extends Filter> extends GenericService<T, ID, R> {
9
- search: (s: S, limit?: number, skip?: number|string, fields?: string[]) => Promise<SearchResult<T>>;
9
+ search: (s: S, limit?: number, skip?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
10
10
  }
11
11
  export class LowcodeController<T, ID, S extends Filter> extends GenericController<T, ID> {
12
12
  config?: SearchConfig;
@@ -16,7 +16,15 @@ export class LowcodeController<T, ID, S extends Filter> extends GenericControlle
16
16
  fields?: string;
17
17
  excluding?: string;
18
18
  array?: string[];
19
- constructor(log: Log, public lowCodeService: Service<T, ID, number|ErrorMessage[], S>, config?: SearchConfig, build?: Build<T>, validate?: (obj: T, patch?: boolean) => Promise<ErrorMessage[]>, dates?: string[], numbers?: string[]) {
19
+ constructor(
20
+ log: Log,
21
+ public lowCodeService: Service<T, ID, number | ErrorMessage[], S>,
22
+ config?: SearchConfig,
23
+ build?: Build<T>,
24
+ validate?: (obj: T, patch?: boolean) => Promise<ErrorMessage[]>,
25
+ dates?: string[],
26
+ numbers?: string[],
27
+ ) {
20
28
  super(log, lowCodeService, build, validate);
21
29
  this.search = this.search.bind(this);
22
30
  this.config = initializeConfig(config);
@@ -38,12 +46,13 @@ export class LowcodeController<T, ID, S extends Filter> extends GenericControlle
38
46
  const s = fromRequest<S>(req, buildArray(this.array, this.fields, this.excluding));
39
47
  const l = getParameters(s, this.config);
40
48
  const s2 = format(s, this.dates, this.numbers);
41
- this.lowCodeService.search(s2, l.limit, l.skipOrRefId, l.fields)
42
- .then(result => jsonResult(res, result, this.csv, l.fields, this.config))
43
- .catch(err => handleError(err, res, this.log));
49
+ this.lowCodeService
50
+ .search(s2, l.limit, l.offsetOrNextPageToken, l.fields)
51
+ .then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
52
+ .catch((err) => handleError(err, res, this.log));
44
53
  }
45
54
  }
46
- export {LowcodeController as LowcodeHandler};
55
+ export { LowcodeController as LowcodeHandler };
47
56
  export class Controller<T, ID, S extends Filter> extends GenericController<T, ID> {
48
57
  config?: SearchConfig;
49
58
  csv?: boolean;
@@ -52,7 +61,15 @@ export class Controller<T, ID, S extends Filter> extends GenericController<T, ID
52
61
  fields?: string;
53
62
  excluding?: string;
54
63
  array?: string[];
55
- constructor(log: Log, public lowCodeService: Service<T, ID, number|T|ErrorMessage[], S>, build?: Build<T>, validate?: (obj: T, patch?: boolean) => Promise<ErrorMessage[]>, config?: SearchConfig, dates?: string[], numbers?: string[]) {
64
+ constructor(
65
+ log: Log,
66
+ public lowCodeService: Service<T, ID, number | T | ErrorMessage[], S>,
67
+ build?: Build<T>,
68
+ validate?: (obj: T, patch?: boolean) => Promise<ErrorMessage[]>,
69
+ config?: SearchConfig,
70
+ dates?: string[],
71
+ numbers?: string[],
72
+ ) {
56
73
  super(log, lowCodeService, build, validate);
57
74
  this.search = this.search.bind(this);
58
75
  this.config = initializeConfig(config);
@@ -74,8 +91,9 @@ export class Controller<T, ID, S extends Filter> extends GenericController<T, ID
74
91
  const s = fromRequest<S>(req, buildArray(this.array, this.fields, this.excluding));
75
92
  const l = getParameters(s, this.config);
76
93
  const s2 = format(s, this.dates, this.numbers);
77
- this.lowCodeService.search(s2, l.limit, l.skipOrRefId, l.fields)
78
- .then(result => jsonResult(res, result, this.csv, l.fields, this.config))
79
- .catch(err => handleError(err, res, this.log));
94
+ this.lowCodeService
95
+ .search(s2, l.limit, l.offsetOrNextPageToken, l.fields)
96
+ .then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
97
+ .catch((err) => handleError(err, res, this.log));
80
98
  }
81
99
  }