express-ext 0.5.7 → 0.5.8

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
@@ -132,8 +132,7 @@ function queryPage(req, filter) {
132
132
  }
133
133
  exports.queryPage = queryPage
134
134
  function getOffset(limit, page) {
135
- var offset = limit * (page - 1)
136
- return offset < 0 ? 0 : offset
135
+ return !page || page <= 1 || limit <= 0 ? 0 : limit * (page - 1)
137
136
  }
138
137
  exports.getOffset = getOffset
139
138
  function getPageTotal(pageSize, total) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-ext",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
4
4
  "description": "express-ext",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/log.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { NextFunction } from "express"
2
- import { ParamsDictionary, Request, Response } from "express-serve-static-core"
3
- import { ParsedQs } from "qs"
1
+ import { NextFunction, Request, Response } from "express"
4
2
  import { PassThrough } from "stream"
5
3
  import { resources } from "./resources"
6
4
 
@@ -64,16 +62,12 @@ export interface Middleware {
64
62
  }
65
63
  const o = "OPTIONS"
66
64
  export class MiddlewareLogger {
67
- constructor(
68
- public write: (msg: string, m?: SimpleMap) => void,
69
- conf?: LogConf,
70
- public build?: (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, m: SimpleMap) => SimpleMap,
71
- ) {
65
+ constructor(public write: (msg: string, m?: SimpleMap) => void, conf?: LogConf, public build?: (req: Request, m: SimpleMap) => SimpleMap) {
72
66
  this.log = this.log.bind(this)
73
67
  this.conf = createConfig(conf)
74
68
  }
75
69
  conf: MiddleLog
76
- log(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) {
70
+ log(req: Request, res: Response, next: NextFunction) {
77
71
  const m = req.method
78
72
  if (m !== o && this.conf.log && !skip(this.conf.skips, req.originalUrl)) {
79
73
  const start = process.hrtime()
@@ -134,18 +128,16 @@ export class MiddlewareLogger {
134
128
  }
135
129
  }
136
130
  }
137
- const mapResponseBody = (res: Response<any, Record<string, any>, number>, chunks: Uint8Array[]) => {
131
+ const mapResponseBody = (res: Response, chunks: Uint8Array[]) => {
138
132
  const defaultWrite = res.write.bind(res)
139
133
  const defaultEnd = res.end.bind(res)
140
134
  const ps = new PassThrough()
141
135
 
142
136
  ps.on("data", (data: any) => chunks.push(data))
143
-
144
137
  ;(res as any).write = (...args: any) => {
145
138
  ;(ps as any).write(...args)
146
139
  ;(defaultWrite as any)(...args)
147
140
  }
148
-
149
141
  ;(res as any).end = (...args: any) => {
150
142
  ps.end(...args)
151
143
  defaultEnd(...args)
package/src/search.ts CHANGED
@@ -160,9 +160,8 @@ export function queryPage<F extends Filter>(req: Request, filter?: F): number {
160
160
  ;(filter as any)[resources.page] = n
161
161
  return n
162
162
  }
163
- export function getOffset(limit: number, page: number): number {
164
- const offset = limit * (page - 1)
165
- return offset < 0 ? 0 : offset
163
+ export function getOffset(limit: number, page?: number): number {
164
+ return !page || page <= 1 || limit <= 0 ? 0 : limit * (page - 1)
166
165
  }
167
166
 
168
167
  export function getPageTotal(pageSize?: number, total?: number): number {