@aomex/response-time 0.0.27 → 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 CHANGED
@@ -1,59 +1,13 @@
1
1
  # @aomex/response-time
2
2
 
3
- ## 0.0.27
3
+ ## 1.0.0
4
4
 
5
- ### Patch Changes
6
-
7
- - Updated dependencies [[`59cd3f9`](https://github.com/aomex/aomex/commit/59cd3f98a0b5648a972d6118ba21501130a9ee7e), [`90ca7d5`](https://github.com/aomex/aomex/commit/90ca7d5fc736b523c4fbf7949f64653428dc413c)]:
8
- - @aomex/web@0.0.29
9
- - @aomex/core@0.0.28
10
-
11
- ## 0.0.26
12
-
13
- ### Patch Changes
14
-
15
- - [`961d2af`](https://github.com/aomex/aomex/commit/961d2af641d5c5bcdddd7e00368e136049c7fc9e) Thanks [@geekact](https://github.com/geekact)! - refactor(response-time): 重命名函数 responseTime 为 createResponseTime
16
-
17
- - 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)]:
18
- - @aomex/core@0.0.27
19
- - @aomex/web@0.0.28
20
-
21
- ## 0.0.25
22
-
23
- ### Patch Changes
24
-
25
- - Updated dependencies [[`33c3c61`](https://github.com/aomex/aomex/commit/33c3c614be9f66077f7487350b88d2db854f5fc8), [`fbcea3d`](https://github.com/aomex/aomex/commit/fbcea3d68ff033e6861130c645c8e5ad7336193f)]:
26
- - @aomex/web@0.0.27
27
- - @aomex/core@0.0.26
28
-
29
- ## 0.0.24
30
-
31
- ### Patch Changes
32
-
33
- - 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)]:
34
- - @aomex/web@0.0.26
35
- - @aomex/core@0.0.25
36
-
37
- ## 0.0.23
38
-
39
- ### Patch Changes
40
-
41
- - 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)]:
42
- - @aomex/core@0.0.24
43
- - @aomex/web@0.0.25
44
-
45
- ## 0.0.22
46
-
47
- ### Patch Changes
48
-
49
- - 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)]:
50
- - @aomex/web@0.0.24
51
- - @aomex/core@0.0.23
5
+ ### Minor Changes
52
6
 
53
- ## 0.0.21
7
+ - [`11103a2`](https://github.com/aomex/aomex/commit/11103a2aff4e081754c56b0ff18fa5130ca252e8) Thanks [@geekact](https://github.com/geekact)! - 重新制作
54
8
 
55
9
  ### Patch Changes
56
10
 
57
- - Updated dependencies [[`6f7d706`](https://github.com/aomex/aomex/commit/6f7d7066c23711abdd149eb1c9a293ab8c4284a4), [`e21007a`](https://github.com/aomex/aomex/commit/e21007a82cb8eac73e1f696340bbe986d57dc159), [`e7bf93c`](https://github.com/aomex/aomex/commit/e7bf93cee6896c61d0bf3eb0921151dc6c1bc107), [`e21007a`](https://github.com/aomex/aomex/commit/e21007a82cb8eac73e1f696340bbe986d57dc159), [`818e840`](https://github.com/aomex/aomex/commit/818e840d36c7456a863fc071968b246c123c17f5), [`fb6c72d`](https://github.com/aomex/aomex/commit/fb6c72dbb266be4db92a542afe93dfa5d8c7cd41)]:
58
- - @aomex/core@0.0.22
59
- - @aomex/web@0.0.23
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
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 geekact
3
+ Copyright (c) 2023-2024 geekact
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.d.ts CHANGED
@@ -1,11 +1,5 @@
1
- import { WebMiddleware } from '@aomex/web';
1
+ import * as _aomex_web from '@aomex/web';
2
2
 
3
- interface ResponseTimeOptions {
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 { ResponseTimeOptions, createResponseTime };
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 createResponseTime = (options = {}) => {
4
- const { hrtime = true } = options;
5
- return middleware.web(async (ctx, next) => {
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
- createResponseTime
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 { WebMiddleware } from '@aomex/web';\n\nexport interface ResponseTimeOptions {\n /**\n * 包含毫秒。默认值:`true`\n */\n hrtime?: boolean;\n}\n\nexport const createResponseTime = (\n options: ResponseTimeOptions = {},\n): WebMiddleware => {\n const { hrtime = true } = options;\n\n return middleware.web(async (ctx, next) => {\n const start = process.hrtime();\n try {\n await next();\n } finally {\n const deltas = process.hrtime(start);\n let delta = deltas[0] * 1000 + deltas[1] / 1000000;\n if (!hrtime) {\n delta = Math.round(delta);\n }\n ctx.response.setHeader('x-response-time', delta + 'ms');\n }\n });\n};\n"],"mappings":";AAAA,SAAS,kBAAkB;AAUpB,IAAM,qBAAqB,CAChC,UAA+B,CAAC,MACd;AAClB,QAAM,EAAE,SAAS,KAAK,IAAI;AAE1B,SAAO,WAAW,IAAI,OAAO,KAAK,SAAS;AACzC,UAAM,QAAQ,QAAQ,OAAO;AAC7B,QAAI;AACF,YAAM,KAAK;AAAA,IACb,UAAE;AACA,YAAM,SAAS,QAAQ,OAAO,KAAK;AACnC,UAAI,QAAQ,OAAO,CAAC,IAAI,MAAO,OAAO,CAAC,IAAI;AAC3C,UAAI,CAAC,QAAQ;AACX,gBAAQ,KAAK,MAAM,KAAK;AAAA,MAC1B;AACA,UAAI,SAAS,UAAU,mBAAmB,QAAQ,IAAI;AAAA,IACxD;AAAA,EACF,CAAC;AACH;","names":[]}
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.27",
4
- "description": "X-Response-Time header",
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.28",
31
- "@aomex/web": "^0.0.29"
30
+ "@aomex/core": "^1.0.0",
31
+ "@aomex/web": "^1.0.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@aomex/core": "^0.0.28",
35
- "@aomex/web": "^0.0.29"
34
+ "@aomex/core": "^1.0.0",
35
+ "@aomex/web": "^1.0.0"
36
36
  },
37
- "scripts": {
38
- "test": "vitest"
39
- }
37
+ "scripts": {}
40
38
  }