express-response-middleware 2.1.2 → 2.2.0
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/LICENSE +1 -1
- package/dist/{cjs/index.d.cts → index.d.mts} +20 -16
- package/dist/{esm/index.d.ts → index.d.ts} +20 -16
- package/dist/index.js +207 -0
- package/dist/index.mjs +180 -0
- package/package.json +25 -28
- package/.commitlintrc.json +0 -3
- package/.github/workflows/release.yml +0 -42
- package/.github/workflows/runTest.yml +0 -59
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.husky/pre-push +0 -1
- package/.node-version +0 -1
- package/CHANGELOG.md +0 -88
- package/biome.json +0 -36
- package/dist/cjs/index.cjs +0 -196
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/esm/index.mjs +0 -191
- package/dist/esm/index.mjs.map +0 -1
- package/docs/MIGRATE_FROM_MUNG.md +0 -153
- package/docs/V1_README.md +0 -115
- package/pnpm-workspace.yaml +0 -3
- package/renovate.json +0 -9
- package/rollup.config.js +0 -52
- package/src/endMiddleware.ts +0 -61
- package/src/index.ts +0 -12
- package/src/jsonMiddleware.ts +0 -71
- package/src/jsonpMiddleware.ts +0 -73
- package/src/sendMiddleware.ts +0 -50
- package/src/tests/endMiddleware.test.ts +0 -101
- package/src/tests/jsonMiddleware.test.ts +0 -253
- package/src/tests/jsonpMiddleware.test.ts +0 -233
- package/src/tests/mixAndMatch.test.ts +0 -261
- package/src/tests/sendMiddleware.test.ts +0 -219
- package/src/tests/testHelpers/sleep.ts +0 -2
- package/src/tests/writeMiddleware.test.ts +0 -267
- package/src/utils/asyncLocalStorage.ts +0 -3
- package/src/utils/errorHandler.ts +0 -9
- package/src/writeMiddleware.ts +0 -76
- package/tsconfig.json +0 -28
- package/vitest.config.ts +0 -14
package/.node-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
22
|
package/CHANGELOG.md
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## [2.1.2](https://github.com/marklai1998/express-response-middleware/compare/v2.1.1...v2.1.2) (2025-05-25)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
### Bug Fixes
|
|
7
|
-
|
|
8
|
-
* remove type module flag ([d2a2f9d](https://github.com/marklai1998/express-response-middleware/commit/d2a2f9d9ce23a3d35f6f2fe0f8d9b4f4792f74bc))
|
|
9
|
-
|
|
10
|
-
## [2.1.1](https://github.com/marklai1998/express-response-middleware/compare/v2.1.0...v2.1.1) (2025-03-16)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### Bug Fixes
|
|
14
|
-
|
|
15
|
-
* remove old type ([80a9eca](https://github.com/marklai1998/express-response-middleware/commit/80a9eca3e083a44b8f9cc34b5cffd59bed4b70a7))
|
|
16
|
-
|
|
17
|
-
## [2.1.0](https://github.com/marklai1998/express-response-middleware/compare/v2.0.1...v2.1.0) (2025-03-15)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
### Features
|
|
21
|
-
|
|
22
|
-
* set project type to module ([35769d7](https://github.com/marklai1998/express-response-middleware/commit/35769d740ab7d507d725ba1844516188319da759))
|
|
23
|
-
|
|
24
|
-
## [2.0.1](https://github.com/marklai1998/express-response-middleware/compare/v2.0.0...v2.0.1) (2025-03-15)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
### Bug Fixes
|
|
28
|
-
|
|
29
|
-
* build entry file ([f82450f](https://github.com/marklai1998/express-response-middleware/commit/f82450fa402ced9307bd31192ca34cfbcb9dc4a3))
|
|
30
|
-
|
|
31
|
-
## [2.0.0](https://github.com/marklai1998/express-response-middleware/compare/v1.0.0...v2.0.0) (2025-03-15)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
### ⚠ BREAKING CHANGES
|
|
35
|
-
|
|
36
|
-
* rename head middleware
|
|
37
|
-
* merge async headers
|
|
38
|
-
* set min node version
|
|
39
|
-
* merge async json
|
|
40
|
-
* rename function
|
|
41
|
-
* remove 204 handling
|
|
42
|
-
* remove scalar content type handling
|
|
43
|
-
* remove run on error option
|
|
44
|
-
* esm ([#4](https://github.com/marklai1998/express-response-middleware/issues/4))
|
|
45
|
-
|
|
46
|
-
### Features
|
|
47
|
-
|
|
48
|
-
* end handling ([f7884fd](https://github.com/marklai1998/express-response-middleware/commit/f7884fddbb6f986aa4f893cde0e8d6a1630b4cc8))
|
|
49
|
-
* esm ([#4](https://github.com/marklai1998/express-response-middleware/issues/4)) ([14ec0ed](https://github.com/marklai1998/express-response-middleware/commit/14ec0ed0f3792dedc6d3a9ae85b6c1f1dabb4cdf))
|
|
50
|
-
* jsonp support ([f724345](https://github.com/marklai1998/express-response-middleware/commit/f724345f3aa76c5b5631ace316fd283fecdb9933))
|
|
51
|
-
* merge async headers ([f7fd7c4](https://github.com/marklai1998/express-response-middleware/commit/f7fd7c4c75b57434b9eafbce18116edf94c7c36d))
|
|
52
|
-
* merge async json ([618b6f5](https://github.com/marklai1998/express-response-middleware/commit/618b6f5f0ba4d12b355583c5b99ff1b1ed9bec59))
|
|
53
|
-
* remove 204 handling ([f1c08b1](https://github.com/marklai1998/express-response-middleware/commit/f1c08b17c9f24fd7480e247508db9e7e9c0d7a96))
|
|
54
|
-
* remove run on error option ([ca8d1e3](https://github.com/marklai1998/express-response-middleware/commit/ca8d1e37ad25b346b7b17eeae6a193d4afa265cc))
|
|
55
|
-
* remove scalar content type handling ([3137434](https://github.com/marklai1998/express-response-middleware/commit/3137434c3a261f78304a449f5d7a39365f581b2d))
|
|
56
|
-
* rename function ([fae0ee9](https://github.com/marklai1998/express-response-middleware/commit/fae0ee9dbbf7b22216c5980d633c5640cccfb536))
|
|
57
|
-
* rename head middleware ([ce6c89a](https://github.com/marklai1998/express-response-middleware/commit/ce6c89a1faa234bde62315f0f9d8c364d0d0098d))
|
|
58
|
-
* send middleware ([d609cce](https://github.com/marklai1998/express-response-middleware/commit/d609ccee1bfd789ba75cbea6c8f09cfbb533a892))
|
|
59
|
-
* set min node version ([6d1a51b](https://github.com/marklai1998/express-response-middleware/commit/6d1a51b313e27095b88fbf8f3609fd518e489a5a))
|
|
60
|
-
* write async support ([4aef628](https://github.com/marklai1998/express-response-middleware/commit/4aef628b5e2f48efe2e4f6579841769a207767b8))
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### Bug Fixes
|
|
64
|
-
|
|
65
|
-
* async handler ([5ab900b](https://github.com/marklai1998/express-response-middleware/commit/5ab900b80a3d612cf74d5be2f215473e9ee6a327))
|
|
66
|
-
* async handler ([d919cb3](https://github.com/marklai1998/express-response-middleware/commit/d919cb36aea38f58e9691a9b9879797ada6fd1b4))
|
|
67
|
-
* calling end in json without chaining ([2160658](https://github.com/marklai1998/express-response-middleware/commit/216065829dd1d95593bc188086050c3121912468))
|
|
68
|
-
* end hook ([e91ad26](https://github.com/marklai1998/express-response-middleware/commit/e91ad263eb828b00f1bdb0cf96fa091849125597))
|
|
69
|
-
* json middeware stacking ([44d51f8](https://github.com/marklai1998/express-response-middleware/commit/44d51f8782d3a112964e48c72ad92c4222ac476f))
|
|
70
|
-
* json middleware stacking ([c6cd298](https://github.com/marklai1998/express-response-middleware/commit/c6cd29836c0e86ab478004a573f321f648404251))
|
|
71
|
-
* set express as peer ([6409ec1](https://github.com/marklai1998/express-response-middleware/commit/6409ec12ce7ba90c187f9d56d0e6935625ebdaa7))
|
|
72
|
-
* stop hooks from calling when header is sent ([6fff520](https://github.com/marklai1998/express-response-middleware/commit/6fff520355b82d3fe2137919c86f6c2b32ae534b))
|
|
73
|
-
|
|
74
|
-
## 1.0.0 (2025-03-03)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
### Features
|
|
78
|
-
|
|
79
|
-
* **mung:** option to allow munging of JSON errors, fixes [#7](https://github.com/marklai1998/express-response-middleware/issues/7) ([fa1b802](https://github.com/marklai1998/express-response-middleware/commit/fa1b8025aa2267d256e90d4143de3ea6e8a85a03))
|
|
80
|
-
* tests and better implementation for writeJson ([5369d3d](https://github.com/marklai1998/express-response-middleware/commit/5369d3d02848ac3c5031c75f530eef64d226c822))
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
### Bug Fixes
|
|
84
|
-
|
|
85
|
-
* args is not set ([031b0eb](https://github.com/marklai1998/express-response-middleware/commit/031b0ebde37f999295e7d2fa543933af13d5c27d))
|
|
86
|
-
* missing option change ([bcf292a](https://github.com/marklai1998/express-response-middleware/commit/bcf292a7e00b328757ce88f60282080bbf1a499d))
|
|
87
|
-
* remove mung names from public api ([c341e79](https://github.com/marklai1998/express-response-middleware/commit/c341e799d8026c60d888ce193f2660e7e1d30e09))
|
|
88
|
-
* returning a scalar number [#22](https://github.com/marklai1998/express-response-middleware/issues/22) ([dc57062](https://github.com/marklai1998/express-response-middleware/commit/dc5706214b62643893361e33fdb07075f549d402))
|
package/biome.json
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
|
|
3
|
-
"vcs": {
|
|
4
|
-
"enabled": true,
|
|
5
|
-
"clientKind": "git",
|
|
6
|
-
"useIgnoreFile": true
|
|
7
|
-
},
|
|
8
|
-
"files": {
|
|
9
|
-
"ignoreUnknown": false,
|
|
10
|
-
"ignore": []
|
|
11
|
-
},
|
|
12
|
-
"formatter": {
|
|
13
|
-
"enabled": true,
|
|
14
|
-
"indentStyle": "space"
|
|
15
|
-
},
|
|
16
|
-
"organizeImports": {
|
|
17
|
-
"enabled": true
|
|
18
|
-
},
|
|
19
|
-
"linter": {
|
|
20
|
-
"enabled": true,
|
|
21
|
-
"rules": {
|
|
22
|
-
"recommended": true,
|
|
23
|
-
"style": {
|
|
24
|
-
"noArguments": "off"
|
|
25
|
-
},
|
|
26
|
-
"suspicious": {
|
|
27
|
-
"noExplicitAny": "warn"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
"javascript": {
|
|
32
|
-
"formatter": {
|
|
33
|
-
"quoteStyle": "single"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var node_async_hooks = require('node:async_hooks');
|
|
4
|
-
|
|
5
|
-
const isInSend$1 = new node_async_hooks.AsyncLocalStorage();
|
|
6
|
-
|
|
7
|
-
const errorHandler = (err, _req, res, _next) => {
|
|
8
|
-
res.status(500).set("content-language", "en").json({ message: err.message }).end();
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const jsonMiddleware = (fn) => (req, res, next) => {
|
|
12
|
-
const originalJsonFn = res.json;
|
|
13
|
-
const originalSendFn = res.send;
|
|
14
|
-
res.send = function() {
|
|
15
|
-
return isInSend$1.run(
|
|
16
|
-
true,
|
|
17
|
-
() => originalSendFn.apply(this, arguments)
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
res.json = function(json) {
|
|
21
|
-
const originalEndFn = res.end;
|
|
22
|
-
if (res.headersSent) return res;
|
|
23
|
-
let mayBePromise;
|
|
24
|
-
try {
|
|
25
|
-
mayBePromise = fn(json, req, res);
|
|
26
|
-
} catch (e) {
|
|
27
|
-
res.json = originalJsonFn;
|
|
28
|
-
errorHandler(e, req, res);
|
|
29
|
-
return res;
|
|
30
|
-
}
|
|
31
|
-
if (mayBePromise instanceof Promise) {
|
|
32
|
-
mayBePromise.then((result) => {
|
|
33
|
-
if (res.headersSent) return;
|
|
34
|
-
res.end = originalEndFn;
|
|
35
|
-
originalJsonFn.call(this, result === void 0 ? json : result);
|
|
36
|
-
}).catch((e) => {
|
|
37
|
-
res.json = originalJsonFn;
|
|
38
|
-
res.end = originalEndFn;
|
|
39
|
-
errorHandler(e, req, res);
|
|
40
|
-
});
|
|
41
|
-
res.end = function() {
|
|
42
|
-
if (isInSend$1.getStore()) {
|
|
43
|
-
originalEndFn.apply(this, arguments);
|
|
44
|
-
}
|
|
45
|
-
return res;
|
|
46
|
-
};
|
|
47
|
-
} else {
|
|
48
|
-
const result = mayBePromise;
|
|
49
|
-
if (res.headersSent) return res;
|
|
50
|
-
originalJsonFn.call(this, result === void 0 ? json : result);
|
|
51
|
-
}
|
|
52
|
-
return res;
|
|
53
|
-
};
|
|
54
|
-
next();
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const endMiddleware = (fn) => (req, res, next) => {
|
|
58
|
-
const originalEndFn = res.end;
|
|
59
|
-
res.end = function() {
|
|
60
|
-
if (res.headersSent) return originalEndFn.apply(this, arguments);
|
|
61
|
-
let mayBePromise;
|
|
62
|
-
try {
|
|
63
|
-
mayBePromise = fn(req, res);
|
|
64
|
-
} catch (e) {
|
|
65
|
-
res.end = originalEndFn;
|
|
66
|
-
errorHandler(e, req, res);
|
|
67
|
-
return res;
|
|
68
|
-
}
|
|
69
|
-
if (mayBePromise instanceof Promise) {
|
|
70
|
-
mayBePromise.then(() => {
|
|
71
|
-
if (res.headersSent) {
|
|
72
|
-
console.error(
|
|
73
|
-
"sending response while in endMiddleware is undefined behaviour"
|
|
74
|
-
);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
originalEndFn.apply(this, arguments);
|
|
78
|
-
}).catch((e) => {
|
|
79
|
-
res.end = originalEndFn;
|
|
80
|
-
errorHandler(e, req, res);
|
|
81
|
-
});
|
|
82
|
-
res.end = function() {
|
|
83
|
-
return res;
|
|
84
|
-
};
|
|
85
|
-
} else {
|
|
86
|
-
if (res.headersSent) {
|
|
87
|
-
console.error(
|
|
88
|
-
"sending response while in endMiddleware is undefined behaviour"
|
|
89
|
-
);
|
|
90
|
-
return res;
|
|
91
|
-
}
|
|
92
|
-
return originalEndFn.apply(this, arguments);
|
|
93
|
-
}
|
|
94
|
-
return res;
|
|
95
|
-
};
|
|
96
|
-
next();
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const writeMiddleware = (fn) => (req, res, next) => {
|
|
100
|
-
const originalWrite = res.write;
|
|
101
|
-
const originalEndFn = res.end;
|
|
102
|
-
res.write = function(chunk) {
|
|
103
|
-
if (res.writableEnded) return false;
|
|
104
|
-
let mayBePromise;
|
|
105
|
-
try {
|
|
106
|
-
mayBePromise = fn(
|
|
107
|
-
chunk,
|
|
108
|
-
// Since `encoding` is an optional argument to `res.write`,
|
|
109
|
-
// make sure it is a string and not actually the callback.
|
|
110
|
-
// biome-ignore lint/style/noArguments: pass argument type
|
|
111
|
-
typeof arguments[1] === "string" ? arguments[1] : null,
|
|
112
|
-
req,
|
|
113
|
-
res
|
|
114
|
-
);
|
|
115
|
-
} catch (e) {
|
|
116
|
-
errorHandler(e, req, res);
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
if (mayBePromise instanceof Promise) {
|
|
120
|
-
mayBePromise.then((result2) => {
|
|
121
|
-
res.end = originalEndFn;
|
|
122
|
-
if (res.writableEnded) return false;
|
|
123
|
-
arguments[0] = result2 === void 0 ? chunk : result2;
|
|
124
|
-
const writeResponse = originalWrite.apply(res, arguments);
|
|
125
|
-
if (res.__isEnd) res.end();
|
|
126
|
-
return writeResponse;
|
|
127
|
-
}).catch((e) => {
|
|
128
|
-
res.end = originalEndFn;
|
|
129
|
-
errorHandler(e, req, res);
|
|
130
|
-
});
|
|
131
|
-
res.end = function() {
|
|
132
|
-
this.__isEnd = true;
|
|
133
|
-
return res;
|
|
134
|
-
};
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
const result = mayBePromise;
|
|
138
|
-
if (res.writableEnded) return false;
|
|
139
|
-
arguments[0] = result === void 0 ? chunk : result;
|
|
140
|
-
return originalWrite.apply(res, arguments);
|
|
141
|
-
};
|
|
142
|
-
next();
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const isInSend = new node_async_hooks.AsyncLocalStorage();
|
|
146
|
-
const jsonpMiddleware = (fn) => (req, res, next) => {
|
|
147
|
-
const originalJsonpFn = res.jsonp;
|
|
148
|
-
const originalSendFn = res.send;
|
|
149
|
-
res.send = function() {
|
|
150
|
-
return isInSend.run(
|
|
151
|
-
true,
|
|
152
|
-
() => originalSendFn.apply(this, arguments)
|
|
153
|
-
);
|
|
154
|
-
};
|
|
155
|
-
res.jsonp = function(json) {
|
|
156
|
-
const originalEndFn = res.end;
|
|
157
|
-
if (res.headersSent) return res;
|
|
158
|
-
let mayBePromise;
|
|
159
|
-
try {
|
|
160
|
-
mayBePromise = fn(json, req, res);
|
|
161
|
-
} catch (e) {
|
|
162
|
-
res.json = originalJsonpFn;
|
|
163
|
-
errorHandler(e, req, res);
|
|
164
|
-
return res;
|
|
165
|
-
}
|
|
166
|
-
if (mayBePromise instanceof Promise) {
|
|
167
|
-
mayBePromise.then((result) => {
|
|
168
|
-
if (res.headersSent) return;
|
|
169
|
-
res.end = originalEndFn;
|
|
170
|
-
originalJsonpFn.call(this, result === void 0 ? json : result);
|
|
171
|
-
}).catch((e) => {
|
|
172
|
-
res.jsonp = originalJsonpFn;
|
|
173
|
-
res.end = originalEndFn;
|
|
174
|
-
errorHandler(e, req, res);
|
|
175
|
-
});
|
|
176
|
-
res.end = function() {
|
|
177
|
-
if (isInSend.getStore()) {
|
|
178
|
-
originalEndFn.apply(this, arguments);
|
|
179
|
-
}
|
|
180
|
-
return res;
|
|
181
|
-
};
|
|
182
|
-
} else {
|
|
183
|
-
const result = mayBePromise;
|
|
184
|
-
if (res.headersSent) return res;
|
|
185
|
-
originalJsonpFn.call(this, result === void 0 ? json : result);
|
|
186
|
-
}
|
|
187
|
-
return res;
|
|
188
|
-
};
|
|
189
|
-
next();
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
exports.endMiddleware = endMiddleware;
|
|
193
|
-
exports.jsonMiddleware = jsonMiddleware;
|
|
194
|
-
exports.jsonpMiddleware = jsonpMiddleware;
|
|
195
|
-
exports.writeMiddleware = writeMiddleware;
|
|
196
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/utils/asyncLocalStorage.ts","../../src/utils/errorHandler.ts","../../src/jsonMiddleware.ts","../../src/endMiddleware.ts","../../src/writeMiddleware.ts","../../src/jsonpMiddleware.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\n\nexport const isInSend = new AsyncLocalStorage<boolean>();\n","import type { ErrorRequestHandler } from 'express';\n\nexport const errorHandler: ErrorRequestHandler = (err, _req, res, _next) => {\n res\n .status(500)\n .set('content-language', 'en')\n .json({ message: err.message })\n .end();\n};\n","import type { Request, RequestHandler, Response } from 'express';\nimport { isInSend } from './utils/asyncLocalStorage.js';\nimport { errorHandler } from './utils/errorHandler.js';\n\nexport type TransformJson<T = unknown, R = T> = (\n body: T,\n request: Request,\n response: Response,\n) => R | Promise<R>;\n\nexport const jsonMiddleware =\n <T = unknown>(fn: TransformJson<T>): RequestHandler =>\n (req, res, next) => {\n const originalJsonFn = res.json;\n const originalSendFn = res.send;\n\n res.send = function (this: Response) {\n return isInSend.run(true, () =>\n originalSendFn.apply(this, arguments as any),\n );\n };\n\n res.json = function (this: Response, json) {\n const originalEndFn = res.end;\n\n if (res.headersSent) return res;\n\n let mayBePromise: T | Promise<T>;\n try {\n mayBePromise = fn(json, req, res);\n } catch (e) {\n res.json = originalJsonFn;\n errorHandler(e, req, res, next);\n return res;\n }\n\n if (mayBePromise instanceof Promise) {\n mayBePromise\n .then((result) => {\n if (res.headersSent) return;\n res.end = originalEndFn;\n\n originalJsonFn.call(this, result === undefined ? json : result);\n })\n .catch((e) => {\n res.json = originalJsonFn;\n res.end = originalEndFn;\n errorHandler(e, req, res, next);\n });\n\n // Prevent end being called wile promise still running\n res.end = function (this: Response) {\n // Res.send will call Res.end, when send is call inside the middleware, do it actually\n if (isInSend.getStore()) {\n originalEndFn.apply(this, arguments as any);\n }\n return res;\n };\n } else {\n const result = mayBePromise;\n\n if (res.headersSent) return res;\n\n originalJsonFn.call(this, result === undefined ? json : result);\n }\n\n return res;\n };\n\n next();\n };\n","import type { Request, RequestHandler, Response } from 'express';\nimport { errorHandler } from './utils/errorHandler.js';\n\nexport type TransformEnd<T = unknown> = (\n request: Request,\n response: Response,\n) => T | Promise<T>;\n\nexport const endMiddleware =\n <T = unknown>(fn: TransformEnd<T>): RequestHandler =>\n (req, res, next) => {\n const originalEndFn = res.end;\n\n res.end = function (this: Response) {\n if (res.headersSent) return originalEndFn.apply(this, arguments as any);\n\n let mayBePromise: T | Promise<T>;\n try {\n mayBePromise = fn(req, res);\n } catch (e) {\n res.end = originalEndFn;\n errorHandler(e, req, res, next);\n return res;\n }\n\n if (mayBePromise instanceof Promise) {\n mayBePromise\n .then(() => {\n if (res.headersSent) {\n console.error(\n 'sending response while in endMiddleware is undefined behaviour',\n );\n return;\n }\n\n originalEndFn.apply(this, arguments as any);\n })\n .catch((e) => {\n res.end = originalEndFn;\n errorHandler(e, req, res, next);\n });\n\n res.end = function (this: Response) {\n return res;\n };\n } else {\n if (res.headersSent) {\n console.error(\n 'sending response while in endMiddleware is undefined behaviour',\n );\n return res;\n }\n\n return originalEndFn.apply(this, arguments as any);\n }\n\n return res;\n };\n\n next();\n };\n","import type { Request, RequestHandler, Response } from 'express';\nimport { errorHandler } from './utils/errorHandler.js';\n\nexport type TransformChunk = (\n chunk: string | Buffer,\n encoding: string | null,\n request: Request,\n response: Response,\n) => void | string | Buffer | Promise<void> | Promise<string> | Promise<Buffer>;\n\nexport const writeMiddleware =\n (fn: TransformChunk): RequestHandler =>\n (req, res, next) => {\n const originalWrite = res.write;\n const originalEndFn = res.end;\n\n res.write = function (this: Response, chunk) {\n if (res.writableEnded) return false;\n\n let mayBePromise: ReturnType<TransformChunk>;\n try {\n mayBePromise = fn(\n chunk,\n // Since `encoding` is an optional argument to `res.write`,\n // make sure it is a string and not actually the callback.\n // biome-ignore lint/style/noArguments: pass argument type\n typeof arguments[1] === 'string' ? arguments[1] : null,\n req,\n res,\n );\n } catch (e) {\n errorHandler(e, req, res, next);\n return false;\n }\n\n if (mayBePromise instanceof Promise) {\n mayBePromise\n .then((result) => {\n res.end = originalEndFn;\n\n if (res.writableEnded) return false;\n\n // biome-ignore lint/style/noArguments: pass argument type\n arguments[0] = result === undefined ? chunk : result;\n\n // biome-ignore lint/style/noArguments: pass argument type\n const writeResponse = originalWrite.apply(res, arguments as any);\n\n if (res.__isEnd) res.end();\n\n return writeResponse;\n })\n .catch((e) => {\n res.end = originalEndFn;\n errorHandler(e, req, res, next);\n });\n\n res.end = function (this: Response) {\n this.__isEnd = true;\n return res;\n };\n return false;\n }\n\n const result = mayBePromise;\n if (res.writableEnded) return false;\n\n // biome-ignore lint/style/noArguments: pass argument type\n arguments[0] = result === undefined ? chunk : result;\n\n // biome-ignore lint/style/noArguments: pass argument type\n return originalWrite.apply(res, arguments as any);\n };\n\n next();\n };\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport type { Request, RequestHandler, Response } from 'express';\nimport { errorHandler } from './utils/errorHandler.js';\n\nexport type TransformJsonp<T = unknown, R = T> = (\n body: T,\n request: Request,\n response: Response,\n) => R | Promise<R>;\n\nconst isInSend = new AsyncLocalStorage<boolean>();\n\nexport const jsonpMiddleware =\n <T = unknown>(fn: TransformJsonp<T>): RequestHandler =>\n (req, res, next) => {\n const originalJsonpFn = res.jsonp;\n const originalSendFn = res.send;\n\n res.send = function (this: Response) {\n return isInSend.run(true, () =>\n originalSendFn.apply(this, arguments as any),\n );\n };\n\n res.jsonp = function (this: Response, json) {\n const originalEndFn = res.end;\n\n if (res.headersSent) return res;\n\n let mayBePromise: T | Promise<T>;\n try {\n mayBePromise = fn(json, req, res);\n } catch (e) {\n res.json = originalJsonpFn;\n errorHandler(e, req, res, next);\n return res;\n }\n\n if (mayBePromise instanceof Promise) {\n mayBePromise\n .then((result) => {\n if (res.headersSent) return;\n res.end = originalEndFn;\n\n originalJsonpFn.call(this, result === undefined ? json : result);\n })\n .catch((e) => {\n res.jsonp = originalJsonpFn;\n res.end = originalEndFn;\n errorHandler(e, req, res, next);\n });\n\n // Prevent end being called wile promise still running\n res.end = function (this: Response) {\n // Res.send will call Res.end, when send is call inside the middleware, do it actually\n if (isInSend.getStore()) {\n originalEndFn.apply(this, arguments as any);\n }\n return res;\n };\n } else {\n const result = mayBePromise;\n\n if (res.headersSent) return res;\n\n originalJsonpFn.call(this, result === undefined ? json : result);\n }\n\n return res;\n };\n\n next();\n };\n"],"names":["isInSend","AsyncLocalStorage","result"],"mappings":";;;;AAEa,MAAAA,UAAA,GAAW,IAAIC,kCAA2B,EAAA;;ACAhD,MAAM,YAAoC,GAAA,CAAC,GAAK,EAAA,IAAA,EAAM,KAAK,KAAU,KAAA;AAC1E,EAAA,GAAA,CACG,MAAO,CAAA,GAAG,CACV,CAAA,GAAA,CAAI,oBAAoB,IAAI,CAAA,CAC5B,IAAK,CAAA,EAAE,OAAS,EAAA,GAAA,CAAI,OAAQ,EAAC,EAC7B,GAAI,EAAA;AACT,CAAA;;ACEO,MAAM,iBACX,CAAc,EAAA,KACd,CAAC,GAAA,EAAK,KAAK,IAAS,KAAA;AAClB,EAAA,MAAM,iBAAiB,GAAI,CAAA,IAAA;AAC3B,EAAA,MAAM,iBAAiB,GAAI,CAAA,IAAA;AAE3B,EAAA,GAAA,CAAI,OAAO,WAA0B;AACnC,IAAA,OAAOD,UAAS,CAAA,GAAA;AAAA,MAAI,IAAA;AAAA,MAAM,MACxB,cAAA,CAAe,KAAM,CAAA,IAAA,EAAM,SAAgB;AAAA,KAC7C;AAAA,GACF;AAEA,EAAI,GAAA,CAAA,IAAA,GAAO,SAA0B,IAAM,EAAA;AACzC,IAAA,MAAM,gBAAgB,GAAI,CAAA,GAAA;AAE1B,IAAI,IAAA,GAAA,CAAI,aAAoB,OAAA,GAAA;AAE5B,IAAI,IAAA,YAAA;AACJ,IAAI,IAAA;AACF,MAAe,YAAA,GAAA,EAAA,CAAG,IAAM,EAAA,GAAA,EAAK,GAAG,CAAA;AAAA,aACzB,CAAG,EAAA;AACV,MAAA,GAAA,CAAI,IAAO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AgB,IAAK,CAAA,IAAA,EAAM,MAAW,KAAA,MAAA,GAAY,OAAO,MAAM,CAAA;AAAA,OAChE,CAAA,CACA,KAAM,CAAA,CAAC,CAAM,KAAA;AACZ,QAAA,GAAA,CAAI,KAAQ,GAAA,eAAA;AACZ,QAAA,GAAA,CAAI,GAAM,GAAA,aAAA;AACV,QAAa,YAAA,CAAA,CAAA,EAAG,GAAK,EAAA,GAAS,CAAA;AAAA,OAC/B,CAAA;AAGH,MAAA,GAAA,CAAI,MAAM,WAA0B;AAElC,QAAI,IAAA,QAAA,CAAS,UAAY,EAAA;AACvB,UAAc,aAAA,CAAA,KAAA,CAAM,MAAM,SAAgB,CAAA;AAAA;AAE5C,QAAO,OAAA,GAAA;AAAA,OACT;AAAA,KACK,MAAA;AACL,MAAA,MAAM,MAAS,GAAA,YAAA;AAEf,MAAI,IAAA,GAAA,CAAI,aAAoB,OAAA,GAAA;AAE5B,MAAA,eAAA,CAAgB,IAAK,CAAA,IAAA,EAAM,MAAW,KAAA,MAAA,GAAY,OAAO,MAAM,CAAA;AAAA;AAGjE,IAAO,OAAA,GAAA;AAAA,GACT;AAEA,EAAK,IAAA,EAAA;AACP;;;;;;;"}
|
package/dist/esm/index.mjs
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
|
|
3
|
-
const isInSend$1 = new AsyncLocalStorage();
|
|
4
|
-
|
|
5
|
-
const errorHandler = (err, _req, res, _next) => {
|
|
6
|
-
res.status(500).set("content-language", "en").json({ message: err.message }).end();
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const jsonMiddleware = (fn) => (req, res, next) => {
|
|
10
|
-
const originalJsonFn = res.json;
|
|
11
|
-
const originalSendFn = res.send;
|
|
12
|
-
res.send = function() {
|
|
13
|
-
return isInSend$1.run(
|
|
14
|
-
true,
|
|
15
|
-
() => originalSendFn.apply(this, arguments)
|
|
16
|
-
);
|
|
17
|
-
};
|
|
18
|
-
res.json = function(json) {
|
|
19
|
-
const originalEndFn = res.end;
|
|
20
|
-
if (res.headersSent) return res;
|
|
21
|
-
let mayBePromise;
|
|
22
|
-
try {
|
|
23
|
-
mayBePromise = fn(json, req, res);
|
|
24
|
-
} catch (e) {
|
|
25
|
-
res.json = originalJsonFn;
|
|
26
|
-
errorHandler(e, req, res);
|
|
27
|
-
return res;
|
|
28
|
-
}
|
|
29
|
-
if (mayBePromise instanceof Promise) {
|
|
30
|
-
mayBePromise.then((result) => {
|
|
31
|
-
if (res.headersSent) return;
|
|
32
|
-
res.end = originalEndFn;
|
|
33
|
-
originalJsonFn.call(this, result === void 0 ? json : result);
|
|
34
|
-
}).catch((e) => {
|
|
35
|
-
res.json = originalJsonFn;
|
|
36
|
-
res.end = originalEndFn;
|
|
37
|
-
errorHandler(e, req, res);
|
|
38
|
-
});
|
|
39
|
-
res.end = function() {
|
|
40
|
-
if (isInSend$1.getStore()) {
|
|
41
|
-
originalEndFn.apply(this, arguments);
|
|
42
|
-
}
|
|
43
|
-
return res;
|
|
44
|
-
};
|
|
45
|
-
} else {
|
|
46
|
-
const result = mayBePromise;
|
|
47
|
-
if (res.headersSent) return res;
|
|
48
|
-
originalJsonFn.call(this, result === void 0 ? json : result);
|
|
49
|
-
}
|
|
50
|
-
return res;
|
|
51
|
-
};
|
|
52
|
-
next();
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const endMiddleware = (fn) => (req, res, next) => {
|
|
56
|
-
const originalEndFn = res.end;
|
|
57
|
-
res.end = function() {
|
|
58
|
-
if (res.headersSent) return originalEndFn.apply(this, arguments);
|
|
59
|
-
let mayBePromise;
|
|
60
|
-
try {
|
|
61
|
-
mayBePromise = fn(req, res);
|
|
62
|
-
} catch (e) {
|
|
63
|
-
res.end = originalEndFn;
|
|
64
|
-
errorHandler(e, req, res);
|
|
65
|
-
return res;
|
|
66
|
-
}
|
|
67
|
-
if (mayBePromise instanceof Promise) {
|
|
68
|
-
mayBePromise.then(() => {
|
|
69
|
-
if (res.headersSent) {
|
|
70
|
-
console.error(
|
|
71
|
-
"sending response while in endMiddleware is undefined behaviour"
|
|
72
|
-
);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
originalEndFn.apply(this, arguments);
|
|
76
|
-
}).catch((e) => {
|
|
77
|
-
res.end = originalEndFn;
|
|
78
|
-
errorHandler(e, req, res);
|
|
79
|
-
});
|
|
80
|
-
res.end = function() {
|
|
81
|
-
return res;
|
|
82
|
-
};
|
|
83
|
-
} else {
|
|
84
|
-
if (res.headersSent) {
|
|
85
|
-
console.error(
|
|
86
|
-
"sending response while in endMiddleware is undefined behaviour"
|
|
87
|
-
);
|
|
88
|
-
return res;
|
|
89
|
-
}
|
|
90
|
-
return originalEndFn.apply(this, arguments);
|
|
91
|
-
}
|
|
92
|
-
return res;
|
|
93
|
-
};
|
|
94
|
-
next();
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const writeMiddleware = (fn) => (req, res, next) => {
|
|
98
|
-
const originalWrite = res.write;
|
|
99
|
-
const originalEndFn = res.end;
|
|
100
|
-
res.write = function(chunk) {
|
|
101
|
-
if (res.writableEnded) return false;
|
|
102
|
-
let mayBePromise;
|
|
103
|
-
try {
|
|
104
|
-
mayBePromise = fn(
|
|
105
|
-
chunk,
|
|
106
|
-
// Since `encoding` is an optional argument to `res.write`,
|
|
107
|
-
// make sure it is a string and not actually the callback.
|
|
108
|
-
// biome-ignore lint/style/noArguments: pass argument type
|
|
109
|
-
typeof arguments[1] === "string" ? arguments[1] : null,
|
|
110
|
-
req,
|
|
111
|
-
res
|
|
112
|
-
);
|
|
113
|
-
} catch (e) {
|
|
114
|
-
errorHandler(e, req, res);
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
if (mayBePromise instanceof Promise) {
|
|
118
|
-
mayBePromise.then((result2) => {
|
|
119
|
-
res.end = originalEndFn;
|
|
120
|
-
if (res.writableEnded) return false;
|
|
121
|
-
arguments[0] = result2 === void 0 ? chunk : result2;
|
|
122
|
-
const writeResponse = originalWrite.apply(res, arguments);
|
|
123
|
-
if (res.__isEnd) res.end();
|
|
124
|
-
return writeResponse;
|
|
125
|
-
}).catch((e) => {
|
|
126
|
-
res.end = originalEndFn;
|
|
127
|
-
errorHandler(e, req, res);
|
|
128
|
-
});
|
|
129
|
-
res.end = function() {
|
|
130
|
-
this.__isEnd = true;
|
|
131
|
-
return res;
|
|
132
|
-
};
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
const result = mayBePromise;
|
|
136
|
-
if (res.writableEnded) return false;
|
|
137
|
-
arguments[0] = result === void 0 ? chunk : result;
|
|
138
|
-
return originalWrite.apply(res, arguments);
|
|
139
|
-
};
|
|
140
|
-
next();
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const isInSend = new AsyncLocalStorage();
|
|
144
|
-
const jsonpMiddleware = (fn) => (req, res, next) => {
|
|
145
|
-
const originalJsonpFn = res.jsonp;
|
|
146
|
-
const originalSendFn = res.send;
|
|
147
|
-
res.send = function() {
|
|
148
|
-
return isInSend.run(
|
|
149
|
-
true,
|
|
150
|
-
() => originalSendFn.apply(this, arguments)
|
|
151
|
-
);
|
|
152
|
-
};
|
|
153
|
-
res.jsonp = function(json) {
|
|
154
|
-
const originalEndFn = res.end;
|
|
155
|
-
if (res.headersSent) return res;
|
|
156
|
-
let mayBePromise;
|
|
157
|
-
try {
|
|
158
|
-
mayBePromise = fn(json, req, res);
|
|
159
|
-
} catch (e) {
|
|
160
|
-
res.json = originalJsonpFn;
|
|
161
|
-
errorHandler(e, req, res);
|
|
162
|
-
return res;
|
|
163
|
-
}
|
|
164
|
-
if (mayBePromise instanceof Promise) {
|
|
165
|
-
mayBePromise.then((result) => {
|
|
166
|
-
if (res.headersSent) return;
|
|
167
|
-
res.end = originalEndFn;
|
|
168
|
-
originalJsonpFn.call(this, result === void 0 ? json : result);
|
|
169
|
-
}).catch((e) => {
|
|
170
|
-
res.jsonp = originalJsonpFn;
|
|
171
|
-
res.end = originalEndFn;
|
|
172
|
-
errorHandler(e, req, res);
|
|
173
|
-
});
|
|
174
|
-
res.end = function() {
|
|
175
|
-
if (isInSend.getStore()) {
|
|
176
|
-
originalEndFn.apply(this, arguments);
|
|
177
|
-
}
|
|
178
|
-
return res;
|
|
179
|
-
};
|
|
180
|
-
} else {
|
|
181
|
-
const result = mayBePromise;
|
|
182
|
-
if (res.headersSent) return res;
|
|
183
|
-
originalJsonpFn.call(this, result === void 0 ? json : result);
|
|
184
|
-
}
|
|
185
|
-
return res;
|
|
186
|
-
};
|
|
187
|
-
next();
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
export { endMiddleware, jsonMiddleware, jsonpMiddleware, writeMiddleware };
|
|
191
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/utils/asyncLocalStorage.ts","../../src/utils/errorHandler.ts","../../src/jsonMiddleware.ts","../../src/endMiddleware.ts","../../src/writeMiddleware.ts","../../src/jsonpMiddleware.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\n\nexport const isInSend = new AsyncLocalStorage<boolean>();\n","import type { ErrorRequestHandler } from 'express';\n\nexport const errorHandler: ErrorRequestHandler = (err, _req, res, _next) => {\n res\n .status(500)\n .set('content-language', 'en')\n .json({ message: err.message })\n .end();\n};\n","import type { Request, RequestHandler, Response } from 'express';\nimport { isInSend } from './utils/asyncLocalStorage.js';\nimport { errorHandler } from './utils/errorHandler.js';\n\nexport type TransformJson<T = unknown, R = T> = (\n body: T,\n request: Request,\n response: Response,\n) => R | Promise<R>;\n\nexport const jsonMiddleware =\n <T = unknown>(fn: TransformJson<T>): RequestHandler =>\n (req, res, next) => {\n const originalJsonFn = res.json;\n const originalSendFn = res.send;\n\n res.send = function (this: Response) {\n return isInSend.run(true, () =>\n originalSendFn.apply(this, arguments as any),\n );\n };\n\n res.json = function (this: Response, json) {\n const originalEndFn = res.end;\n\n if (res.headersSent) return res;\n\n let mayBePromise: T | Promise<T>;\n try {\n mayBePromise = fn(json, req, res);\n } catch (e) {\n res.json = originalJsonFn;\n errorHandler(e, req, res, next);\n return res;\n }\n\n if (mayBePromise instanceof Promise) {\n mayBePromise\n .then((result) => {\n if (res.headersSent) return;\n res.end = originalEndFn;\n\n originalJsonFn.call(this, result === undefined ? json : result);\n })\n .catch((e) => {\n res.json = originalJsonFn;\n res.end = originalEndFn;\n errorHandler(e, req, res, next);\n });\n\n // Prevent end being called wile promise still running\n res.end = function (this: Response) {\n // Res.send will call Res.end, when send is call inside the middleware, do it actually\n if (isInSend.getStore()) {\n originalEndFn.apply(this, arguments as any);\n }\n return res;\n };\n } else {\n const result = mayBePromise;\n\n if (res.headersSent) return res;\n\n originalJsonFn.call(this, result === undefined ? json : result);\n }\n\n return res;\n };\n\n next();\n };\n","import type { Request, RequestHandler, Response } from 'express';\nimport { errorHandler } from './utils/errorHandler.js';\n\nexport type TransformEnd<T = unknown> = (\n request: Request,\n response: Response,\n) => T | Promise<T>;\n\nexport const endMiddleware =\n <T = unknown>(fn: TransformEnd<T>): RequestHandler =>\n (req, res, next) => {\n const originalEndFn = res.end;\n\n res.end = function (this: Response) {\n if (res.headersSent) return originalEndFn.apply(this, arguments as any);\n\n let mayBePromise: T | Promise<T>;\n try {\n mayBePromise = fn(req, res);\n } catch (e) {\n res.end = originalEndFn;\n errorHandler(e, req, res, next);\n return res;\n }\n\n if (mayBePromise instanceof Promise) {\n mayBePromise\n .then(() => {\n if (res.headersSent) {\n console.error(\n 'sending response while in endMiddleware is undefined behaviour',\n );\n return;\n }\n\n originalEndFn.apply(this, arguments as any);\n })\n .catch((e) => {\n res.end = originalEndFn;\n errorHandler(e, req, res, next);\n });\n\n res.end = function (this: Response) {\n return res;\n };\n } else {\n if (res.headersSent) {\n console.error(\n 'sending response while in endMiddleware is undefined behaviour',\n );\n return res;\n }\n\n return originalEndFn.apply(this, arguments as any);\n }\n\n return res;\n };\n\n next();\n };\n","import type { Request, RequestHandler, Response } from 'express';\nimport { errorHandler } from './utils/errorHandler.js';\n\nexport type TransformChunk = (\n chunk: string | Buffer,\n encoding: string | null,\n request: Request,\n response: Response,\n) => void | string | Buffer | Promise<void> | Promise<string> | Promise<Buffer>;\n\nexport const writeMiddleware =\n (fn: TransformChunk): RequestHandler =>\n (req, res, next) => {\n const originalWrite = res.write;\n const originalEndFn = res.end;\n\n res.write = function (this: Response, chunk) {\n if (res.writableEnded) return false;\n\n let mayBePromise: ReturnType<TransformChunk>;\n try {\n mayBePromise = fn(\n chunk,\n // Since `encoding` is an optional argument to `res.write`,\n // make sure it is a string and not actually the callback.\n // biome-ignore lint/style/noArguments: pass argument type\n typeof arguments[1] === 'string' ? arguments[1] : null,\n req,\n res,\n );\n } catch (e) {\n errorHandler(e, req, res, next);\n return false;\n }\n\n if (mayBePromise instanceof Promise) {\n mayBePromise\n .then((result) => {\n res.end = originalEndFn;\n\n if (res.writableEnded) return false;\n\n // biome-ignore lint/style/noArguments: pass argument type\n arguments[0] = result === undefined ? chunk : result;\n\n // biome-ignore lint/style/noArguments: pass argument type\n const writeResponse = originalWrite.apply(res, arguments as any);\n\n if (res.__isEnd) res.end();\n\n return writeResponse;\n })\n .catch((e) => {\n res.end = originalEndFn;\n errorHandler(e, req, res, next);\n });\n\n res.end = function (this: Response) {\n this.__isEnd = true;\n return res;\n };\n return false;\n }\n\n const result = mayBePromise;\n if (res.writableEnded) return false;\n\n // biome-ignore lint/style/noArguments: pass argument type\n arguments[0] = result === undefined ? chunk : result;\n\n // biome-ignore lint/style/noArguments: pass argument type\n return originalWrite.apply(res, arguments as any);\n };\n\n next();\n };\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport type { Request, RequestHandler, Response } from 'express';\nimport { errorHandler } from './utils/errorHandler.js';\n\nexport type TransformJsonp<T = unknown, R = T> = (\n body: T,\n request: Request,\n response: Response,\n) => R | Promise<R>;\n\nconst isInSend = new AsyncLocalStorage<boolean>();\n\nexport const jsonpMiddleware =\n <T = unknown>(fn: TransformJsonp<T>): RequestHandler =>\n (req, res, next) => {\n const originalJsonpFn = res.jsonp;\n const originalSendFn = res.send;\n\n res.send = function (this: Response) {\n return isInSend.run(true, () =>\n originalSendFn.apply(this, arguments as any),\n );\n };\n\n res.jsonp = function (this: Response, json) {\n const originalEndFn = res.end;\n\n if (res.headersSent) return res;\n\n let mayBePromise: T | Promise<T>;\n try {\n mayBePromise = fn(json, req, res);\n } catch (e) {\n res.json = originalJsonpFn;\n errorHandler(e, req, res, next);\n return res;\n }\n\n if (mayBePromise instanceof Promise) {\n mayBePromise\n .then((result) => {\n if (res.headersSent) return;\n res.end = originalEndFn;\n\n originalJsonpFn.call(this, result === undefined ? json : result);\n })\n .catch((e) => {\n res.jsonp = originalJsonpFn;\n res.end = originalEndFn;\n errorHandler(e, req, res, next);\n });\n\n // Prevent end being called wile promise still running\n res.end = function (this: Response) {\n // Res.send will call Res.end, when send is call inside the middleware, do it actually\n if (isInSend.getStore()) {\n originalEndFn.apply(this, arguments as any);\n }\n return res;\n };\n } else {\n const result = mayBePromise;\n\n if (res.headersSent) return res;\n\n originalJsonpFn.call(this, result === undefined ? json : result);\n }\n\n return res;\n };\n\n next();\n };\n"],"names":["isInSend","result"],"mappings":";;AAEa,MAAAA,UAAA,GAAW,IAAI,iBAA2B,EAAA;;ACAhD,MAAM,YAAoC,GAAA,CAAC,GAAK,EAAA,IAAA,EAAM,KAAK,KAAU,KAAA;AAC1E,EAAA,GAAA,CACG,MAAO,CAAA,GAAG,CACV,CAAA,GAAA,CAAI,oBAAoB,IAAI,CAAA,CAC5B,IAAK,CAAA,EAAE,OAAS,EAAA,GAAA,CAAI,OAAQ,EAAC,EAC7B,GAAI,EAAA;AACT,CAAA;;ACEO,MAAM,iBACX,CAAc,EAAA,KACd,CAAC,GAAA,EAAK,KAAK,IAAS,KAAA;AAClB,EAAA,MAAM,iBAAiB,GAAI,CAAA,IAAA;A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