@aomex/response-time 3.30.7 → 3.30.8-alpha.62.sha-92b25bb
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/dist/index.d.ts +1 -5
- package/dist/index.js +19 -20
- package/dist/index.js.map +1 -1
- package/package.json +20 -18
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
1
|
import { middleware } from "@aomex/common";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var responseTime = () => {
|
|
8
|
-
return middleware.web((ctx, next) => {
|
|
9
|
-
const start = process.hrtime();
|
|
10
|
-
return next().then(() => {
|
|
11
|
-
ctx.response.setHeader("x-response-time", getDelta(start));
|
|
12
|
-
}).catch((err) => {
|
|
13
|
-
err.headers = {
|
|
14
|
-
...err.headers,
|
|
15
|
-
"x-response-time": getDelta(start)
|
|
16
|
-
};
|
|
17
|
-
return Promise.reject(err);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
2
|
+
// src/index.ts
|
|
3
|
+
const getDelta = (start) => {
|
|
4
|
+
const deltas = process.hrtime(start);
|
|
5
|
+
return deltas[0] * 1e3 + deltas[1] / 1e6 + "ms";
|
|
20
6
|
};
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
const responseTime = () => {
|
|
8
|
+
return middleware.web((ctx, next) => {
|
|
9
|
+
const start = process.hrtime();
|
|
10
|
+
return next().then(() => {
|
|
11
|
+
ctx.response.setHeader("x-response-time", getDelta(start));
|
|
12
|
+
}).catch((err) => {
|
|
13
|
+
err.headers = {
|
|
14
|
+
...err.headers,
|
|
15
|
+
"x-response-time": getDelta(start)
|
|
16
|
+
};
|
|
17
|
+
return Promise.reject(err);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
23
20
|
};
|
|
21
|
+
export { responseTime };
|
|
22
|
+
|
|
24
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { middleware } from '@aomex/common';\nimport type { HttpError } from '@aomex/web';\n\nconst getDelta = (start: [number, number]) => {\n const deltas = process.hrtime(start);\n return deltas[0] * 1_000 + deltas[1] / 1_000_000 + 'ms';\n};\n\nexport const responseTime = () => {\n return middleware.web((ctx, next) => {\n const start = process.hrtime();\n return next()\n .then(() => {\n ctx.response.setHeader('x-response-time', getDelta(start));\n })\n .catch((err: HttpError) => {\n err.headers = {\n ...err.headers,\n 'x-response-time': getDelta(start),\n };\n return Promise.reject(err);\n });\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { middleware } from '@aomex/common';\nimport type { HttpError } from '@aomex/web';\n\nconst getDelta = (start: [number, number]) => {\n const deltas = process.hrtime(start);\n return deltas[0] * 1_000 + deltas[1] / 1_000_000 + 'ms';\n};\n\nexport const responseTime = () => {\n return middleware.web((ctx, next) => {\n const start = process.hrtime();\n return next()\n .then(() => {\n ctx.response.setHeader('x-response-time', getDelta(start));\n })\n .catch((err: HttpError) => {\n err.headers = {\n ...err.headers,\n 'x-response-time': getDelta(start),\n };\n return Promise.reject(err);\n });\n });\n};\n"],"mappings":";;AAGA,MAAM,YAAY,UAA4B;CAC5C,MAAM,SAAS,QAAQ,OAAO,KAAK;CACnC,OAAO,OAAO,KAAK,MAAQ,OAAO,KAAK,MAAY;AACrD;AAEA,MAAa,qBAAqB;CAChC,OAAO,WAAW,KAAK,KAAK,SAAS;EACnC,MAAM,QAAQ,QAAQ,OAAO;EAC7B,OAAO,KAAK,CAAC,CACV,WAAW;GACV,IAAI,SAAS,UAAU,mBAAmB,SAAS,KAAK,CAAC;EAC3D,CAAC,CAAC,CACD,OAAO,QAAmB;GACzB,IAAI,UAAU;IACZ,GAAG,IAAI;IACP,mBAAmB,SAAS,KAAK;GACnC;GACA,OAAO,QAAQ,OAAO,GAAG;EAC3B,CAAC;CACL,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/response-time",
|
|
3
|
-
"version": "3.30.
|
|
3
|
+
"version": "3.30.8-alpha.62.sha-92b25bb",
|
|
4
4
|
"description": "计算请求接口所用时间",
|
|
5
5
|
"keywords": [],
|
|
6
|
-
"repository":
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git@github.com:aomex/aomex.git"
|
|
9
|
-
},
|
|
6
|
+
"repository": "git@github.com:aomex/aomex.git",
|
|
10
7
|
"homepage": "https://aomex.js.org",
|
|
11
8
|
"license": "MIT",
|
|
12
9
|
"type": "module",
|
|
13
10
|
"sideEffects": false,
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
".": {
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
|
-
"import": "./dist/index.js"
|
|
19
|
-
},
|
|
20
|
-
"./package.json": "./package.json"
|
|
11
|
+
"scripts": {
|
|
12
|
+
"prepublishOnly": "tsdown"
|
|
21
13
|
},
|
|
14
|
+
"types": "src/index.ts",
|
|
15
|
+
"exports": "./src/index.ts",
|
|
22
16
|
"files": [
|
|
23
17
|
"dist",
|
|
24
18
|
"LICENSE",
|
|
@@ -27,15 +21,23 @@
|
|
|
27
21
|
"CHANGELOG.md"
|
|
28
22
|
],
|
|
29
23
|
"publishConfig": {
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
30
32
|
"access": "public"
|
|
31
33
|
},
|
|
32
34
|
"peerDependencies": {
|
|
33
|
-
"@aomex/common": "^
|
|
34
|
-
"@aomex/web": "^
|
|
35
|
+
"@aomex/common": "^4.0.0",
|
|
36
|
+
"@aomex/web": "^4.0.0"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
|
-
"@aomex/common": "3.30.
|
|
38
|
-
"@aomex/web": "3.30.
|
|
39
|
+
"@aomex/common": "3.30.8-alpha.62.sha-92b25bb",
|
|
40
|
+
"@aomex/web": "3.30.8-alpha.62.sha-92b25bb"
|
|
39
41
|
},
|
|
40
|
-
"
|
|
41
|
-
}
|
|
42
|
+
"gitHead": "92b25bbcd6c3ae28160316117a74c88619b5bc8d"
|
|
43
|
+
}
|