@aomex/response-time 0.0.26 → 1.0.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/CHANGELOG.md +6 -44
- package/LICENSE +1 -1
- package/dist/index.d.ts +3 -9
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/package.json +7 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,51 +1,13 @@
|
|
|
1
1
|
# @aomex/response-time
|
|
2
2
|
|
|
3
|
-
## 0.0
|
|
3
|
+
## 1.0.0
|
|
4
4
|
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
- [`961d2af`](https://github.com/aomex/aomex/commit/961d2af641d5c5bcdddd7e00368e136049c7fc9e) Thanks [@geekact](https://github.com/geekact)! - refactor(response-time): 重命名函数 responseTime 为 createResponseTime
|
|
8
|
-
|
|
9
|
-
- Updated dependencies [[`00bafbb`](https://github.com/aomex/aomex/commit/00bafbbac2d32205b63a6bf561fb0a69c38a54bb), [`8becf8e`](https://github.com/aomex/aomex/commit/8becf8ee5ef86a5909783d0654e536db7be9bf5b), [`0776719`](https://github.com/aomex/aomex/commit/077671963401f1dafb5b03722899452d45df13fc), [`f996bf7`](https://github.com/aomex/aomex/commit/f996bf7e529e7751a5e858c579feed33f5f02d65)]:
|
|
10
|
-
- @aomex/core@0.0.27
|
|
11
|
-
- @aomex/web@0.0.28
|
|
12
|
-
|
|
13
|
-
## 0.0.25
|
|
14
|
-
|
|
15
|
-
### Patch Changes
|
|
16
|
-
|
|
17
|
-
- Updated dependencies [[`33c3c61`](https://github.com/aomex/aomex/commit/33c3c614be9f66077f7487350b88d2db854f5fc8), [`fbcea3d`](https://github.com/aomex/aomex/commit/fbcea3d68ff033e6861130c645c8e5ad7336193f)]:
|
|
18
|
-
- @aomex/web@0.0.27
|
|
19
|
-
- @aomex/core@0.0.26
|
|
20
|
-
|
|
21
|
-
## 0.0.24
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
24
|
-
|
|
25
|
-
- Updated dependencies [[`5ef2022`](https://github.com/aomex/aomex/commit/5ef202248b4320ff9076fbecb54379055cffb7db), [`8d9e9d8`](https://github.com/aomex/aomex/commit/8d9e9d8ece0bbcc7e1ac685702eacbfdfa145aa9), [`0e6ed2c`](https://github.com/aomex/aomex/commit/0e6ed2c611100dcfaafb6fb41357624ad9f5c67a)]:
|
|
26
|
-
- @aomex/web@0.0.26
|
|
27
|
-
- @aomex/core@0.0.25
|
|
28
|
-
|
|
29
|
-
## 0.0.23
|
|
30
|
-
|
|
31
|
-
### Patch Changes
|
|
32
|
-
|
|
33
|
-
- Updated dependencies [[`2ac62fd`](https://github.com/aomex/aomex/commit/2ac62fd28166a1d9dd60b3c6d5a6508a6f9ee82b), [`4258410`](https://github.com/aomex/aomex/commit/42584107ad9f7e34492ae1053fef83aa2d9d747a), [`4177cba`](https://github.com/aomex/aomex/commit/4177cba7877e38120842bd8d287eaed54e4926ca)]:
|
|
34
|
-
- @aomex/core@0.0.24
|
|
35
|
-
- @aomex/web@0.0.25
|
|
36
|
-
|
|
37
|
-
## 0.0.22
|
|
38
|
-
|
|
39
|
-
### Patch Changes
|
|
40
|
-
|
|
41
|
-
- Updated dependencies [[`6621e4f`](https://github.com/aomex/aomex/commit/6621e4ff0f3509beeb332a0571a7db9c7d6ca99a), [`7b09277`](https://github.com/aomex/aomex/commit/7b09277136910966f500c8132303c7ddee84340c), [`46c5b72`](https://github.com/aomex/aomex/commit/46c5b72785011fa181767f4c8ea0d0f5008b21ae), [`9c78999`](https://github.com/aomex/aomex/commit/9c78999ebcb2962f30344acfbf6de0733d6fdd41), [`f4b012d`](https://github.com/aomex/aomex/commit/f4b012d98cddb2918479ea05df6c266dd914e53a)]:
|
|
42
|
-
- @aomex/web@0.0.24
|
|
43
|
-
- @aomex/core@0.0.23
|
|
5
|
+
### Minor Changes
|
|
44
6
|
|
|
45
|
-
|
|
7
|
+
- [`11103a2`](https://github.com/aomex/aomex/commit/11103a2aff4e081754c56b0ff18fa5130ca252e8) Thanks [@geekact](https://github.com/geekact)! - 重新制作
|
|
46
8
|
|
|
47
9
|
### Patch Changes
|
|
48
10
|
|
|
49
|
-
- Updated dependencies [[`
|
|
50
|
-
- @aomex/core@0.0
|
|
51
|
-
- @aomex/web@0.0
|
|
11
|
+
- Updated dependencies [[`11103a2`](https://github.com/aomex/aomex/commit/11103a2aff4e081754c56b0ff18fa5130ca252e8)]:
|
|
12
|
+
- @aomex/core@1.0.0
|
|
13
|
+
- @aomex/web@1.0.0
|
package/LICENSE
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _aomex_web from '@aomex/web';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 包含毫秒。默认值:`true`
|
|
6
|
-
*/
|
|
7
|
-
hrtime?: boolean;
|
|
8
|
-
}
|
|
9
|
-
declare const createResponseTime: (options?: ResponseTimeOptions) => WebMiddleware;
|
|
3
|
+
declare const responseTime: _aomex_web.WebMiddleware<object>;
|
|
10
4
|
|
|
11
|
-
export {
|
|
5
|
+
export { responseTime };
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { middleware } from "@aomex/core";
|
|
3
|
-
var
|
|
4
|
-
const
|
|
5
|
-
return
|
|
6
|
-
const start = process.hrtime();
|
|
7
|
-
try {
|
|
8
|
-
await next();
|
|
9
|
-
} finally {
|
|
10
|
-
const deltas = process.hrtime(start);
|
|
11
|
-
let delta = deltas[0] * 1e3 + deltas[1] / 1e6;
|
|
12
|
-
if (!hrtime) {
|
|
13
|
-
delta = Math.round(delta);
|
|
14
|
-
}
|
|
15
|
-
ctx.response.setHeader("x-response-time", delta + "ms");
|
|
16
|
-
}
|
|
17
|
-
});
|
|
3
|
+
var getDelta = (start) => {
|
|
4
|
+
const deltas = process.hrtime(start);
|
|
5
|
+
return deltas[0] * 1e3 + deltas[1] / 1e6 + "ms";
|
|
18
6
|
};
|
|
7
|
+
var responseTime = middleware.web((ctx, next) => {
|
|
8
|
+
const start = process.hrtime();
|
|
9
|
+
return next().then(() => {
|
|
10
|
+
ctx.response.setHeader("x-response-time", getDelta(start));
|
|
11
|
+
}).catch((err) => {
|
|
12
|
+
err.headers = {
|
|
13
|
+
...err.headers,
|
|
14
|
+
"x-response-time": getDelta(start)
|
|
15
|
+
};
|
|
16
|
+
return Promise.reject(err);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
19
|
export {
|
|
20
|
-
|
|
20
|
+
responseTime
|
|
21
21
|
};
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { middleware } from '@aomex/core';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { middleware } from '@aomex/core';\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 = 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"],"mappings":";AAAA,SAAS,kBAAkB;AAG3B,IAAM,WAAW,CAAC,UAA4B;AAC5C,QAAM,SAAS,QAAQ,OAAO,KAAK;AACnC,SAAO,OAAO,CAAC,IAAI,MAAQ,OAAO,CAAC,IAAI,MAAY;AACrD;AAEO,IAAM,eAAe,WAAW,IAAI,CAAC,KAAK,SAAS;AACxD,QAAM,QAAQ,QAAQ,OAAO;AAC7B,SAAO,KAAK,EACT,KAAK,MAAM;AACV,QAAI,SAAS,UAAU,mBAAmB,SAAS,KAAK,CAAC;AAAA,EAC3D,CAAC,EACA,MAAM,CAAC,QAAmB;AACzB,QAAI,UAAU;AAAA,MACZ,GAAG,IAAI;AAAA,MACP,mBAAmB,SAAS,KAAK;AAAA,IACnC;AACA,WAAO,QAAQ,OAAO,GAAG;AAAA,EAC3B,CAAC;AACL,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/response-time",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "计算请求接口所用时间",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": "git@github.com:aomex/aomex.git",
|
|
7
7
|
"homepage": "https://aomex.js.org",
|
|
@@ -27,14 +27,12 @@
|
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@aomex/core": "^0.0
|
|
31
|
-
"@aomex/web": "^0.0
|
|
30
|
+
"@aomex/core": "^1.0.0",
|
|
31
|
+
"@aomex/web": "^1.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@aomex/core": "^0.0
|
|
35
|
-
"@aomex/web": "^0.0
|
|
34
|
+
"@aomex/core": "^1.0.0",
|
|
35
|
+
"@aomex/web": "^1.0.0"
|
|
36
36
|
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"test": "vitest"
|
|
39
|
-
}
|
|
37
|
+
"scripts": {}
|
|
40
38
|
}
|