express-response-middleware 2.1.0 → 2.1.3

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.
@@ -1,70 +0,0 @@
1
- import { Request, RequestHandler, Response } from 'express'
2
- import { errorHandler } from './utils/errorHandler.js'
3
-
4
- export type TransformChunk = (
5
- chunk: string | Buffer,
6
- encoding: string | null,
7
- request: Request,
8
- response: Response
9
- ) => void | string | Buffer | Promise<void> | Promise<string> | Promise<Buffer>
10
-
11
- export const writeMiddleware =
12
- (fn: TransformChunk): RequestHandler =>
13
- (req, res, next) => {
14
- const originalWrite = res.write
15
- const originalEndFn = res.end
16
-
17
- res.write = function (this: Response, chunk) {
18
- if (res.writableEnded) return false
19
-
20
- let mayBePromise
21
- try {
22
- mayBePromise = fn(
23
- chunk,
24
- // Since `encoding` is an optional argument to `res.write`,
25
- // make sure it is a string and not actually the callback.
26
- typeof arguments[1] === 'string' ? arguments[1] : null,
27
- req,
28
- res
29
- )
30
- } catch (e) {
31
- errorHandler(e, req, res, next)
32
- return false
33
- }
34
-
35
- if (mayBePromise instanceof Promise) {
36
- mayBePromise.then(result => {
37
- try {
38
- res.end = originalEndFn
39
-
40
- if (res.writableEnded) return false
41
-
42
- arguments[0] = result === undefined ? chunk : result
43
-
44
- const writeResponse = originalWrite.apply(res, arguments as any)
45
-
46
- if (res.__isEnd) res.end()
47
-
48
- return writeResponse
49
- } catch (e) {
50
- errorHandler(e, req, res, next)
51
- return false
52
- }
53
- })
54
-
55
- res.end = function (this: Response) {
56
- this.__isEnd = true
57
- return res
58
- }
59
- return false
60
- } else {
61
- const result = mayBePromise
62
- if (res.writableEnded) return false
63
-
64
- arguments[0] = result === undefined ? chunk : result
65
- return originalWrite.apply(res, arguments as any)
66
- }
67
- }
68
-
69
- next()
70
- }
package/tsconfig.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "types": ["vitest/globals", "node"],
4
-
5
- "target": "ESNext",
6
- "lib": ["ESNext"],
7
- "module": "NodeNext",
8
- "moduleResolution": "nodenext",
9
-
10
- "allowJs": false,
11
- "skipLibCheck": true,
12
- "esModuleInterop": false,
13
- "resolveJsonModule": true,
14
- "isolatedModules": true,
15
- "noEmit": true,
16
-
17
- "strict": true,
18
- "allowSyntheticDefaultImports": true,
19
- "forceConsistentCasingInFileNames": true,
20
- "allowUnreachableCode": false,
21
- "allowUnusedLabels": false,
22
- "noImplicitOverride": true,
23
- "noImplicitReturns": true,
24
- "noUnusedLocals": true,
25
- "noUnusedParameters": true,
26
- },
27
- "include": ["src"]
28
- }
package/vitest.config.ts DELETED
@@ -1,14 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- coverage: {
8
- provider: 'v8',
9
- reporter: ['lcov', 'text'],
10
- include: ['src'],
11
- exclude: ['**/tests/**', '**/*.d.ts'],
12
- },
13
- },
14
- })