express-ext 0.2.3 → 0.2.4

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,89 @@
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 buildPageQuery(query) {
79
+ var qr = removePageQuery(query);
80
+ return qr.length == 0 ? qr : '&' + qr;
81
+ }
82
+ exports.buildPageQuery = buildPageQuery;
4
83
  function jsonResult(res, result, quick, fields, config) {
5
84
  if (quick && fields && fields.length > 0) {
6
85
  res.status(200).json(toCsv(fields, result)).end();
7
- }
8
- else {
86
+ } else {
9
87
  res.status(200).json(buildResult(result, config)).end();
10
88
  }
11
89
  }
@@ -15,16 +93,16 @@ function buildResult(r, conf) {
15
93
  return r;
16
94
  }
17
95
  var x = {};
18
- var li = (conf.list ? conf.list : 'list');
96
+ var li = conf.list ? conf.list : 'list';
19
97
  x[li] = http_1.minimizeArray(r.list);
20
- var to = (conf.total ? conf.total : 'total');
98
+ var to = conf.total ? conf.total : 'total';
21
99
  x[to] = r.total;
22
100
  if (r.nextPageToken && r.nextPageToken.length > 0) {
23
- var t = (conf.token ? conf.token : 'token');
101
+ var t = conf.token ? conf.token : 'token';
24
102
  x[t] = r.nextPageToken;
25
103
  }
26
104
  if (r.last) {
27
- var l = (conf.last ? conf.last : 'last');
105
+ var l = conf.last ? conf.last : 'last';
28
106
  x[l] = r.last;
29
107
  }
30
108
  return x;
@@ -46,7 +124,7 @@ function initializeConfig(conf) {
46
124
  limit: conf.limit,
47
125
  skip: conf.skip,
48
126
  refId: conf.refId,
49
- firstLimit: conf.firstLimit
127
+ firstLimit: conf.firstLimit,
50
128
  };
51
129
  if (!c.excluding || c.excluding.length === 0) {
52
130
  c.excluding = 'excluding';
@@ -85,7 +163,7 @@ function initializeConfig(conf) {
85
163
  }
86
164
  exports.initializeConfig = initializeConfig;
87
165
  function fromRequest(req, arr) {
88
- var s = (req.method === 'GET' ? fromUrl(req, arr) : req.body);
166
+ var s = req.method === 'GET' ? fromUrl(req, arr) : req.body;
89
167
  return s;
90
168
  }
91
169
  exports.fromRequest = fromRequest;
@@ -118,8 +196,7 @@ function fromUrl(req, arr) {
118
196
  if (inArray(key, arr)) {
119
197
  var x = obj[key].split(',');
120
198
  setValue(s, key, x);
121
- }
122
- else {
199
+ } else {
123
200
  setValue(s, key, obj[key]);
124
201
  }
125
202
  }
@@ -163,12 +240,10 @@ var setKey = function (_object, _isArrayKey, _key, _nextValue) {
163
240
  if (_isArrayKey) {
164
241
  if (_object.length > _key) {
165
242
  _object[_key] = _nextValue;
166
- }
167
- else {
243
+ } else {
168
244
  _object.push(_nextValue);
169
245
  }
170
- }
171
- else {
246
+ } else {
172
247
  _object[_key] = _nextValue;
173
248
  }
174
249
  return _object;
@@ -187,7 +262,7 @@ function getParameters(obj, config) {
187
262
  if (!refId) {
188
263
  refId = o['nextPageToken'];
189
264
  }
190
- var r = { fields: fields, refId: refId };
265
+ var r = { fields: fields, nextPageToken: refId };
191
266
  var pageSize = o['limit'];
192
267
  if (!pageSize) {
193
268
  pageSize = o['pageSize'];
@@ -200,8 +275,8 @@ function getParameters(obj, config) {
200
275
  if (skip && !isNaN(skip)) {
201
276
  var iskip = Math.floor(parseFloat(skip));
202
277
  if (iskip >= 0) {
203
- r.skip = iskip;
204
- r.skipOrRefId = r.skip;
278
+ r.offset = iskip;
279
+ r.offsetOrNextPageToken = r.offset;
205
280
  deletePageInfo(o);
206
281
  return r;
207
282
  }
@@ -228,32 +303,31 @@ function getParameters(obj, config) {
228
303
  if (firstPageSize && !isNaN(firstPageSize)) {
229
304
  var ifirstPageSize = Math.floor(parseFloat(firstPageSize));
230
305
  if (ifirstPageSize > 0) {
231
- r.skip = ipageSize * (ipageIndex - 2) + ifirstPageSize;
232
- r.skipOrRefId = r.skip;
306
+ r.offset = ipageSize * (ipageIndex - 2) + ifirstPageSize;
307
+ r.offsetOrNextPageToken = r.offset;
233
308
  deletePageInfo(o);
234
309
  return r;
235
310
  }
236
311
  }
237
- r.skip = ipageSize * (ipageIndex - 1);
238
- r.skipOrRefId = r.skip;
312
+ r.offset = ipageSize * (ipageIndex - 1);
313
+ r.offsetOrNextPageToken = r.offset;
239
314
  deletePageInfo(o);
240
315
  return r;
241
316
  }
242
- r.skip = 0;
243
- if (r.refId && r.refId.length > 0) {
244
- r.skipOrRefId = r.refId;
317
+ r.offset = 0;
318
+ if (r.nextPageToken && r.nextPageToken.length > 0) {
319
+ r.offsetOrNextPageToken = r.nextPageToken;
245
320
  }
246
321
  deletePageInfo(o);
247
322
  return r;
248
323
  }
249
324
  }
250
- if (r.refId && r.refId.length > 0) {
251
- r.skipOrRefId = r.refId;
325
+ if (r.nextPageToken && r.nextPageToken.length > 0) {
326
+ r.offsetOrNextPageToken = r.nextPageToken;
252
327
  }
253
328
  deletePageInfo(o);
254
329
  return r;
255
- }
256
- else {
330
+ } else {
257
331
  var sfield = config.fields;
258
332
  if (!sfield || sfield.length === 0) {
259
333
  sfield = 'fields';
@@ -269,7 +343,7 @@ function getParameters(obj, config) {
269
343
  strRefId = 'refId';
270
344
  }
271
345
  var refId = o[strRefId];
272
- var r = { fields: fields, refId: refId };
346
+ var r = { fields: fields, nextPageToken: refId };
273
347
  var strLimit = config.limit;
274
348
  if (!strLimit || strLimit.length === 0) {
275
349
  strLimit = 'limit';
@@ -288,8 +362,8 @@ function getParameters(obj, config) {
288
362
  if (skip && !isNaN(skip)) {
289
363
  var iskip = Math.floor(parseFloat(skip));
290
364
  if (iskip >= 0) {
291
- r.skip = iskip;
292
- r.skipOrRefId = r.skip;
365
+ r.offset = iskip;
366
+ r.offsetOrNextPageToken = r.offset;
293
367
  deletePageInfo(o, arr);
294
368
  return r;
295
369
  }
@@ -312,27 +386,27 @@ function getParameters(obj, config) {
312
386
  if (firstPageSize && !isNaN(firstPageSize)) {
313
387
  var ifirstPageSize = Math.floor(parseFloat(firstPageSize));
314
388
  if (ifirstPageSize > 0) {
315
- r.skip = ipageSize * (ipageIndex - 2) + ifirstPageSize;
316
- r.skipOrRefId = r.skip;
389
+ r.offset = ipageSize * (ipageIndex - 2) + ifirstPageSize;
390
+ r.offsetOrNextPageToken = r.offset;
317
391
  deletePageInfo(o, arr);
318
392
  return r;
319
393
  }
320
394
  }
321
- r.skip = ipageSize * (ipageIndex - 1);
322
- r.skipOrRefId = r.skip;
395
+ r.offset = ipageSize * (ipageIndex - 1);
396
+ r.offsetOrNextPageToken = r.offset;
323
397
  deletePageInfo(o, arr);
324
398
  return r;
325
399
  }
326
- r.skip = 0;
327
- if (r.refId && r.refId.length > 0) {
328
- r.skipOrRefId = r.refId;
400
+ r.offset = 0;
401
+ if (r.nextPageToken && r.nextPageToken.length > 0) {
402
+ r.offsetOrNextPageToken = r.nextPageToken;
329
403
  }
330
404
  deletePageInfo(o, arr);
331
405
  return r;
332
406
  }
333
407
  }
334
- if (r.refId && r.refId.length > 0) {
335
- r.skipOrRefId = r.refId;
408
+ if (r.nextPageToken && r.nextPageToken.length > 0) {
409
+ r.offsetOrNextPageToken = r.nextPageToken;
336
410
  }
337
411
  deletePageInfo(o, arr);
338
412
  return r;
@@ -352,8 +426,7 @@ function deletePageInfo(obj, arr) {
352
426
  delete obj['firstPageSize'];
353
427
  delete obj['refId'];
354
428
  delete obj['nextPageToken'];
355
- }
356
- else {
429
+ } else {
357
430
  for (var _i = 0, arr_3 = arr; _i < arr_3.length; _i++) {
358
431
  var o = arr_3[_i];
359
432
  if (o && o.length > 0) {
@@ -367,8 +440,7 @@ var re = /"/g;
367
440
  function toCsv(fields, r) {
368
441
  if (!r || r.list.length === 0) {
369
442
  return '0';
370
- }
371
- else {
443
+ } else {
372
444
  var e = '';
373
445
  var s = 'string';
374
446
  var n = 'number';
@@ -383,23 +455,18 @@ function toCsv(fields, r) {
383
455
  var v = item[name];
384
456
  if (!v) {
385
457
  cols.push(e);
386
- }
387
- else {
458
+ } else {
388
459
  if (typeof v === s) {
389
460
  if (s.indexOf(',') >= 0) {
390
461
  cols.push('"' + v.replace(re, b) + '"');
391
- }
392
- else {
462
+ } else {
393
463
  cols.push(v);
394
464
  }
395
- }
396
- else if (v instanceof Date) {
465
+ } else if (v instanceof Date) {
397
466
  cols.push(v.toISOString());
398
- }
399
- else if (typeof v === n) {
467
+ } else if (typeof v === n) {
400
468
  cols.push(v.toString());
401
- }
402
- else {
469
+ } else {
403
470
  cols.push('');
404
471
  }
405
472
  }
@@ -419,8 +486,7 @@ function buildMetadata(attributes, includeDate) {
419
486
  var attr = attributes[key];
420
487
  if (attr.type === 'number' || attr.type === 'integer') {
421
488
  numbers.push(key);
422
- }
423
- else if (attr.type === 'datetime' || (includeDate === true && attr.type === 'date')) {
489
+ } else if (attr.type === 'datetime' || (includeDate === true && attr.type === 'date')) {
424
490
  dates.push(key);
425
491
  }
426
492
  }
@@ -442,8 +508,7 @@ function toDate(v) {
442
508
  }
443
509
  if (v instanceof Date) {
444
510
  return v;
445
- }
446
- else if (typeof v === 'number') {
511
+ } else if (typeof v === 'number') {
447
512
  return new Date(v);
448
513
  }
449
514
  var i = v.indexOf(_datereg);
@@ -452,16 +517,13 @@ function toDate(v) {
452
517
  if (m !== null) {
453
518
  var d = parseInt(m[0], 10);
454
519
  return new Date(d);
455
- }
456
- else {
520
+ } else {
457
521
  return null;
458
522
  }
459
- }
460
- else {
523
+ } else {
461
524
  if (isNaN(v)) {
462
525
  return new Date(v);
463
- }
464
- else {
526
+ } else {
465
527
  var d = parseInt(v, 10);
466
528
  return new Date(d);
467
529
  }
@@ -482,13 +544,11 @@ function format(obj, dates, nums) {
482
544
  if (d) {
483
545
  if (!(d instanceof Date) || d.toString() === 'Invalid Date') {
484
546
  delete o[s];
485
- }
486
- else {
547
+ } else {
487
548
  o[s] = d;
488
549
  }
489
550
  }
490
- }
491
- else if (typeof v === 'object') {
551
+ } else if (typeof v === 'object') {
492
552
  var keys = Object.keys(v);
493
553
  for (var _a = 0, keys_3 = keys; _a < keys_3.length; _a++) {
494
554
  var key = keys_3[_a];
@@ -501,8 +561,7 @@ function format(obj, dates, nums) {
501
561
  if (d2) {
502
562
  if (!(d2 instanceof Date) || d2.toString() === 'Invalid Date') {
503
563
  delete v[key];
504
- }
505
- else {
564
+ } else {
506
565
  v[key] = d2;
507
566
  }
508
567
  }
@@ -528,13 +587,11 @@ function format(obj, dates, nums) {
528
587
  if (!isNaN(v)) {
529
588
  delete o[s];
530
589
  continue;
531
- }
532
- else {
590
+ } else {
533
591
  var i = parseFloat(v);
534
592
  o[s] = i;
535
593
  }
536
- }
537
- else if (typeof v === 'object') {
594
+ } else if (typeof v === 'object') {
538
595
  var keys = Object.keys(v);
539
596
  for (var _c = 0, keys_4 = keys; _c < keys_4.length; _c++) {
540
597
  var key = keys_4[_c];
@@ -549,8 +606,7 @@ function format(obj, dates, nums) {
549
606
  if (typeof v2 === 'string') {
550
607
  if (!isNaN(v2)) {
551
608
  delete v[key];
552
- }
553
- else {
609
+ } else {
554
610
  var i = parseFloat(v2);
555
611
  v[key] = i;
556
612
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-ext",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
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
  }