express-ext 0.5.5 → 0.5.7

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.
@@ -48,7 +48,7 @@ var GenericSearchController = (function (_super) {
48
48
  GenericSearchController.prototype.search = function (req, res) {
49
49
  var _this = this
50
50
  var s = search_1.fromRequest(req, search_1.buildArray(this.array, resources_1.resources.fields, this.excluding))
51
- var l = search_1.getParameters(s, this.config)
51
+ var l = search_1.getParameters(s)
52
52
  var s2 = search_1.format(s, this.dates, this.numbers)
53
53
  this.find(s2, l.limit, l.pageOrNextPageToken, l.fields)
54
54
  .then(function (result) {
@@ -63,7 +63,7 @@ var LoadSearchController = (function (_super) {
63
63
  LoadSearchController.prototype.search = function (req, res) {
64
64
  var _this = this
65
65
  var s = search_1.fromRequest(req, search_1.buildArray(this.array, resources_1.resources.fields, this.excluding))
66
- var l = search_1.getParameters(s, this.config)
66
+ var l = search_1.getParameters(s)
67
67
  var s2 = search_1.format(s, this.dates, this.numbers)
68
68
  this.find(s2, l.limit, l.pageOrNextPageToken, l.fields)
69
69
  .then(function (result) {
@@ -104,7 +104,7 @@ var QueryController = (function (_super) {
104
104
  QueryController.prototype.search = function (req, res) {
105
105
  var _this = this
106
106
  var s = search_1.fromRequest(req, search_1.buildArray(this.array, resources_1.resources.fields, this.excluding))
107
- var l = search_1.getParameters(s, this.config)
107
+ var l = search_1.getParameters(s)
108
108
  var s2 = search_1.format(s, this.dates, this.numbers)
109
109
  this.query
110
110
  .search(s2, l.limit, l.pageOrNextPageToken, l.fields)
@@ -48,7 +48,7 @@ var LowcodeController = (function (_super) {
48
48
  LowcodeController.prototype.search = function (req, res) {
49
49
  var _this = this
50
50
  var s = search_1.fromRequest(req, search_1.buildArray(this.array, resources_1.resources.fields, this.excluding))
51
- var l = search_1.getParameters(s, this.config)
51
+ var l = search_1.getParameters(s)
52
52
  var s2 = search_1.format(s, this.dates, this.numbers)
53
53
  this.lowCodeService
54
54
  .search(s2, l.limit, l.pageOrNextPageToken, l.fields)
@@ -84,7 +84,7 @@ var Controller = (function (_super) {
84
84
  Controller.prototype.search = function (req, res) {
85
85
  var _this = this
86
86
  var s = search_1.fromRequest(req, search_1.buildArray(this.array, resources_1.resources.fields, this.excluding))
87
- var l = search_1.getParameters(s, this.config)
87
+ var l = search_1.getParameters(s)
88
88
  var s2 = search_1.format(s, this.dates, this.numbers)
89
89
  this.lowCodeService
90
90
  .search(s2, l.limit, l.pageOrNextPageToken, l.fields)
@@ -25,7 +25,7 @@ var SearchController = (function () {
25
25
  SearchController.prototype.search = function (req, res) {
26
26
  var _this = this
27
27
  var s = search_1.fromRequest(req, search_1.buildArray(this.array, resources_1.resources.fields, this.excluding))
28
- var l = search_1.getParameters(s, this.config)
28
+ var l = search_1.getParameters(s)
29
29
  var s2 = search_1.format(s, this.dates, this.numbers)
30
30
  this.find(s2, l.limit, l.pageOrNextPageToken, l.fields)
31
31
  .then(function (result) {
package/lib/search.js CHANGED
@@ -398,10 +398,6 @@ function buildResult(r, conf) {
398
398
  var t = conf.token ? conf.token : "token"
399
399
  x[t] = r.nextPageToken
400
400
  }
401
- if (r.last) {
402
- var l = conf.last ? conf.last : "last"
403
- x[l] = r.last
404
- }
405
401
  return x
406
402
  }
407
403
  exports.buildResult = buildResult
@@ -414,7 +410,6 @@ function initializeConfig(conf) {
414
410
  list: conf.list,
415
411
  total: conf.total,
416
412
  token: conf.token,
417
- last: conf.last,
418
413
  csv: conf.csv,
419
414
  }
420
415
  if (!c.excluding || c.excluding.length === 0) {
@@ -426,9 +421,6 @@ function initializeConfig(conf) {
426
421
  if (!c.total || c.total.length === 0) {
427
422
  c.total = "total"
428
423
  }
429
- if (!c.last || c.last.length === 0) {
430
- c.last = "last"
431
- }
432
424
  if (!c.token || c.token.length === 0) {
433
425
  c.token = "nextPageToken"
434
426
  }
@@ -453,14 +445,14 @@ function fromRequest(req, arr) {
453
445
  }
454
446
  var limit = s[resources_1.resources.limit]
455
447
  if (limit) {
456
- if (isNaN(page)) {
448
+ if (isNaN(limit)) {
457
449
  s[resources_1.resources.limit] = resources_1.resources.defaultLimit
458
450
  } else {
459
451
  var n = parseFloat(limit)
460
452
  if (n < 1) {
461
453
  n = resources_1.resources.defaultLimit
462
454
  }
463
- s[resources_1.resources.page] = n
455
+ s[resources_1.resources.limit] = n
464
456
  }
465
457
  } else {
466
458
  s[resources_1.resources.limit] = resources_1.resources.defaultLimit
@@ -552,7 +544,7 @@ var setKey = function (_object, _isArrayKey, _key, _nextValue) {
552
544
  }
553
545
  return _object
554
546
  }
555
- function getParameters(obj, config) {
547
+ function getParameters(obj) {
556
548
  var o = obj
557
549
  var fields
558
550
  var fs = o[resources_1.resources.fields]
@@ -570,17 +562,17 @@ function getParameters(obj, config) {
570
562
  }
571
563
  }
572
564
  }
573
- var pageSize = resources_1.resources.defaultLimit
574
- var spageSize = o[resources_1.resources.limit]
575
- if (spageSize && typeof spageSize === "string") {
576
- if (!isNaN(spageSize)) {
577
- var ipageSize = Math.floor(parseFloat(spageSize))
578
- if (ipageSize > 0) {
579
- pageSize = ipageSize
565
+ var limit = resources_1.resources.defaultLimit
566
+ var slimit = o[resources_1.resources.limit]
567
+ if (slimit && typeof slimit === "string") {
568
+ if (!isNaN(slimit)) {
569
+ var ilimit = Math.floor(parseFloat(slimit))
570
+ if (ilimit > 0) {
571
+ limit = ilimit
580
572
  }
581
573
  }
582
574
  }
583
- var r = { limit: pageSize, fields: fields, page: page, nextPageToken: nextPageToken, pageOrNextPageToken: page }
575
+ var r = { limit: limit, fields: fields, page: page, nextPageToken: nextPageToken, pageOrNextPageToken: page }
584
576
  if (r.nextPageToken && r.nextPageToken.length > 0) {
585
577
  r.pageOrNextPageToken = r.nextPageToken
586
578
  }
@@ -619,7 +611,7 @@ function toCsv(fields, r) {
619
611
  var n = "number"
620
612
  var b = '""'
621
613
  var rows = []
622
- rows.push("" + (r.total ? r.total : "") + "," + (r.nextPageToken ? r.nextPageToken : "") + "," + (r.last ? "1" : ""))
614
+ rows.push("" + (r.total ? r.total : "") + "," + (r.nextPageToken ? r.nextPageToken : ""))
623
615
  for (var _i = 0, _a = r.list; _i < _a.length; _i++) {
624
616
  var item = _a[_i]
625
617
  var cols = []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-ext",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "description": "express-ext",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
@@ -37,7 +37,7 @@ export class GenericSearchController<T, ID, S extends Filter> extends GenericCon
37
37
  }
38
38
  search(req: Request, res: Response) {
39
39
  const s = fromRequest<S>(req, buildArray(this.array, resources.fields, this.excluding))
40
- const l = getParameters(s, this.config)
40
+ const l = getParameters(s)
41
41
  const s2 = format(s, this.dates, this.numbers)
42
42
  this.find(s2, l.limit, l.pageOrNextPageToken, l.fields)
43
43
  .then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
@@ -72,7 +72,7 @@ export class LoadSearchController<T, ID, S extends Filter> extends LoadControlle
72
72
  }
73
73
  search(req: Request, res: Response): void {
74
74
  const s = fromRequest<S>(req, buildArray(this.array, resources.fields, this.excluding))
75
- const l = getParameters(s, this.config)
75
+ const l = getParameters(s)
76
76
  const s2 = format(s, this.dates, this.numbers)
77
77
  this.find(s2, l.limit, l.pageOrNextPageToken, l.fields)
78
78
  .then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
@@ -109,7 +109,7 @@ export class QueryController<T, ID, S extends Filter> extends LoadController<T,
109
109
  }
110
110
  search(req: Request, res: Response): void {
111
111
  const s = fromRequest<S>(req, buildArray(this.array, resources.fields, this.excluding))
112
- const l = getParameters(s, this.config)
112
+ const l = getParameters(s)
113
113
  const s2 = format(s, this.dates, this.numbers)
114
114
  this.query
115
115
  .search(s2, l.limit, l.pageOrNextPageToken, l.fields)
@@ -39,7 +39,7 @@ export class LowcodeController<T, ID, S extends Filter> extends GenericControlle
39
39
  }
40
40
  search(req: Request, res: Response) {
41
41
  const s = fromRequest<S>(req, buildArray(this.array, resources.fields, this.excluding))
42
- const l = getParameters(s, this.config)
42
+ const l = getParameters(s)
43
43
  const s2 = format(s, this.dates, this.numbers)
44
44
  this.lowCodeService
45
45
  .search(s2, l.limit, l.pageOrNextPageToken, l.fields)
@@ -79,7 +79,7 @@ export class Controller<T, ID, S extends Filter> extends GenericController<T, ID
79
79
  }
80
80
  search(req: Request, res: Response) {
81
81
  const s = fromRequest<S>(req, buildArray(this.array, resources.fields, this.excluding))
82
- const l = getParameters(s, this.config)
82
+ const l = getParameters(s)
83
83
  const s2 = format(s, this.dates, this.numbers)
84
84
  this.lowCodeService
85
85
  .search(s2, l.limit, l.pageOrNextPageToken, l.fields)
@@ -30,7 +30,7 @@ export class SearchController<T, S extends Filter> {
30
30
  }
31
31
  search(req: Request, res: Response) {
32
32
  const s = fromRequest<S>(req, buildArray(this.array, resources.fields, this.excluding))
33
- const l = getParameters(s, this.config)
33
+ const l = getParameters(s)
34
34
  const s2 = format(s, this.dates, this.numbers)
35
35
  this.find(s2, l.limit, l.pageOrNextPageToken, l.fields)
36
36
  .then((result) => jsonResult(res, result, this.csv, l.fields, this.config))
package/src/search.ts CHANGED
@@ -21,7 +21,7 @@ export interface SearchConfig {
21
21
  list?: string
22
22
  total?: string
23
23
  token?: string
24
- last?: string
24
+ // last?: string
25
25
  csv?: boolean
26
26
  // page?: string
27
27
  // limit?: string
@@ -33,7 +33,6 @@ export interface SearchResult<T> {
33
33
  list: T[]
34
34
  total?: number
35
35
  nextPageToken?: string
36
- last?: boolean
37
36
  }
38
37
 
39
38
  export function getPage<F extends Filter>(req: Request, filter?: F): number {
@@ -413,10 +412,6 @@ export function buildResult<T>(r: SearchResult<T>, conf?: SearchConfig): any {
413
412
  const t = conf.token ? conf.token : "token"
414
413
  x[t] = r.nextPageToken
415
414
  }
416
- if (r.last) {
417
- const l = conf.last ? conf.last : "last"
418
- x[l] = r.last
419
- }
420
415
  return x
421
416
  }
422
417
  export function initializeConfig(conf?: SearchConfig): SearchConfig | undefined {
@@ -428,7 +423,6 @@ export function initializeConfig(conf?: SearchConfig): SearchConfig | undefined
428
423
  list: conf.list,
429
424
  total: conf.total,
430
425
  token: conf.token,
431
- last: conf.last,
432
426
  csv: conf.csv,
433
427
  }
434
428
  if (!c.excluding || c.excluding.length === 0) {
@@ -440,9 +434,6 @@ export function initializeConfig(conf?: SearchConfig): SearchConfig | undefined
440
434
  if (!c.total || c.total.length === 0) {
441
435
  c.total = "total"
442
436
  }
443
- if (!c.last || c.last.length === 0) {
444
- c.last = "last"
445
- }
446
437
  if (!c.token || c.token.length === 0) {
447
438
  c.token = "nextPageToken"
448
439
  }
@@ -467,14 +458,14 @@ export function fromRequest<S>(req: Request, arr?: string[]): S {
467
458
 
468
459
  const limit = s[resources.limit]
469
460
  if (limit) {
470
- if (isNaN(page as any)) {
461
+ if (isNaN(limit as any)) {
471
462
  s[resources.limit] = resources.defaultLimit
472
463
  } else {
473
464
  let n = parseFloat(limit)
474
465
  if (n < 1) {
475
466
  n = resources.defaultLimit
476
467
  }
477
- s[resources.page] = n
468
+ s[resources.limit] = n
478
469
  }
479
470
  } else {
480
471
  s[resources.limit] = resources.defaultLimit
@@ -589,7 +580,7 @@ export interface Limit {
589
580
  fields?: string[]
590
581
  pageOrNextPageToken?: string | number
591
582
  }
592
- export function getParameters<T>(obj: T, config?: SearchConfig): Limit {
583
+ export function getParameters<T>(obj: T): Limit {
593
584
  const o: any = obj
594
585
  let fields: string[] | undefined
595
586
  const fs = o[resources.fields]
@@ -607,17 +598,17 @@ export function getParameters<T>(obj: T, config?: SearchConfig): Limit {
607
598
  }
608
599
  }
609
600
  }
610
- let pageSize = resources.defaultLimit
611
- let spageSize = o[resources.limit]
612
- if (spageSize && typeof spageSize === "string") {
613
- if (!isNaN(spageSize as any)) {
614
- const ipageSize = Math.floor(parseFloat(spageSize))
615
- if (ipageSize > 0) {
616
- pageSize = ipageSize
601
+ let limit = resources.defaultLimit
602
+ let slimit = o[resources.limit]
603
+ if (slimit && typeof slimit === "string") {
604
+ if (!isNaN(slimit as any)) {
605
+ const ilimit = Math.floor(parseFloat(slimit))
606
+ if (ilimit > 0) {
607
+ limit = ilimit
617
608
  }
618
609
  }
619
610
  }
620
- const r: Limit = { limit: pageSize, fields, page, nextPageToken, pageOrNextPageToken: page }
611
+ const r: Limit = { limit: limit, fields, page, nextPageToken, pageOrNextPageToken: page }
621
612
  if (r.nextPageToken && r.nextPageToken.length > 0) {
622
613
  r.pageOrNextPageToken = r.nextPageToken
623
614
  }
@@ -654,7 +645,7 @@ export function toCsv<T>(fields: string[], r: SearchResult<T>): string {
654
645
  const n = "number"
655
646
  const b = '""'
656
647
  const rows: string[] = []
657
- rows.push("" + (r.total ? r.total : "") + "," + (r.nextPageToken ? r.nextPageToken : "") + "," + (r.last ? "1" : ""))
648
+ rows.push("" + (r.total ? r.total : "") + "," + (r.nextPageToken ? r.nextPageToken : ""))
658
649
  for (const item of r.list) {
659
650
  const cols: string[] = []
660
651
  for (const name of fields) {