@fatcherjs/middleware-aborter 3.0.0-alpha-10 → 3.0.0-alpha-11
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/README.md +3 -3
- package/dist/index.d.ts +6 -6
- package/dist/index.esm.js +12 -11
- package/dist/index.js +12 -11
- package/dist/index.min.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ import { aborter, timeout } from '@fatcherjs/middleware-aborter';
|
|
|
69
69
|
fatcher('https://foo.bar', {
|
|
70
70
|
onAbort: () => console.log('aborted'),
|
|
71
71
|
timeout: 1000 * 10, // 10s
|
|
72
|
-
middlewares: [aborter
|
|
72
|
+
middlewares: [aborter, timeout /* must call after aborter */],
|
|
73
73
|
});
|
|
74
74
|
```
|
|
75
75
|
|
|
@@ -84,7 +84,7 @@ const abortController = new AbortController();
|
|
|
84
84
|
fatcher('https://foo.bar', {
|
|
85
85
|
onAbort: () => console.log('aborted'),
|
|
86
86
|
abortController,
|
|
87
|
-
middlewares: [aborter
|
|
87
|
+
middlewares: [aborter],
|
|
88
88
|
}).catch(error => {
|
|
89
89
|
// abort error
|
|
90
90
|
});
|
|
@@ -103,7 +103,7 @@ const abortController = new AbortController();
|
|
|
103
103
|
fatcher('https://foo.bar', {
|
|
104
104
|
onAbort: () => console.log('aborted'),
|
|
105
105
|
abortController,
|
|
106
|
-
middlewares: [aborter
|
|
106
|
+
middlewares: [aborter],
|
|
107
107
|
}).catch(error => {
|
|
108
108
|
if (isAbortError(error)) {
|
|
109
109
|
// do something..
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FatcherMiddleware } from 'fatcher';
|
|
2
2
|
|
|
3
|
-
declare const aborter:
|
|
3
|
+
declare const aborter: FatcherMiddleware;
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Confirm an error whether is DOMException
|
|
@@ -9,16 +9,16 @@ declare const aborter: () => FatcherMiddleware;
|
|
|
9
9
|
*/
|
|
10
10
|
declare function isAbortError(error: unknown): error is DOMException;
|
|
11
11
|
|
|
12
|
-
declare const timeout:
|
|
12
|
+
declare const timeout: FatcherMiddleware;
|
|
13
13
|
|
|
14
14
|
declare module 'fatcher' {
|
|
15
|
-
interface FatcherRequest {
|
|
16
|
-
abort: (reason?: string) => void;
|
|
17
|
-
}
|
|
18
15
|
interface FatcherOptions {
|
|
19
|
-
timeout?: number;
|
|
20
16
|
onAbort?: (reason?: string) => void;
|
|
21
17
|
abortController?: AbortController;
|
|
18
|
+
timeout?: number;
|
|
19
|
+
}
|
|
20
|
+
interface FatcherContext {
|
|
21
|
+
abort: (reason?: string) => void;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import 'fatcher';
|
|
2
|
+
|
|
3
|
+
const aborter = {
|
|
4
|
+
name: "fatcher-middleware-aborter",
|
|
5
|
+
use: async (request, next) => {
|
|
6
|
+
const { onAbort, abortController = new AbortController() } = request;
|
|
4
7
|
const handler = () => {
|
|
5
8
|
onAbort?.(abortController.signal.reason);
|
|
6
9
|
abortController.signal.removeEventListener("abort", handler);
|
|
@@ -16,19 +19,17 @@ const aborter = () => {
|
|
|
16
19
|
abortController.signal.removeEventListener("abort", handler);
|
|
17
20
|
}
|
|
18
21
|
return response;
|
|
19
|
-
}
|
|
22
|
+
}
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
function isAbortError(error) {
|
|
23
26
|
return error instanceof DOMException && error.name === "AbortError";
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
const timeout =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
options: { timeout: _timeout }
|
|
31
|
-
} = req;
|
|
29
|
+
const timeout = {
|
|
30
|
+
name: "fatcher-middleware-timeout",
|
|
31
|
+
use: async (context, next) => {
|
|
32
|
+
const { abort, timeout: _timeout } = context;
|
|
32
33
|
let timer = null;
|
|
33
34
|
if (_timeout) {
|
|
34
35
|
timer = setTimeout(() => {
|
|
@@ -45,7 +46,7 @@ const timeout = () => {
|
|
|
45
46
|
throw error;
|
|
46
47
|
}
|
|
47
48
|
return response;
|
|
48
|
-
}
|
|
49
|
+
}
|
|
49
50
|
};
|
|
50
51
|
|
|
51
52
|
export { aborter, isAbortError, timeout };
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
require('fatcher');
|
|
6
|
+
|
|
7
|
+
const aborter = {
|
|
8
|
+
name: "fatcher-middleware-aborter",
|
|
9
|
+
use: async (request, next) => {
|
|
10
|
+
const { onAbort, abortController = new AbortController() } = request;
|
|
8
11
|
const handler = () => {
|
|
9
12
|
onAbort?.(abortController.signal.reason);
|
|
10
13
|
abortController.signal.removeEventListener("abort", handler);
|
|
@@ -20,19 +23,17 @@ const aborter = () => {
|
|
|
20
23
|
abortController.signal.removeEventListener("abort", handler);
|
|
21
24
|
}
|
|
22
25
|
return response;
|
|
23
|
-
}
|
|
26
|
+
}
|
|
24
27
|
};
|
|
25
28
|
|
|
26
29
|
function isAbortError(error) {
|
|
27
30
|
return error instanceof DOMException && error.name === "AbortError";
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
const timeout =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
options: { timeout: _timeout }
|
|
35
|
-
} = req;
|
|
33
|
+
const timeout = {
|
|
34
|
+
name: "fatcher-middleware-timeout",
|
|
35
|
+
use: async (context, next) => {
|
|
36
|
+
const { abort, timeout: _timeout } = context;
|
|
36
37
|
let timer = null;
|
|
37
38
|
if (_timeout) {
|
|
38
39
|
timer = setTimeout(() => {
|
|
@@ -49,7 +50,7 @@ const timeout = () => {
|
|
|
49
50
|
throw error;
|
|
50
51
|
}
|
|
51
52
|
return response;
|
|
52
|
-
}
|
|
53
|
+
}
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
exports.aborter = aborter;
|
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(t,i){typeof exports=="object"&&typeof module!="undefined"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(t=typeof globalThis!="undefined"?globalThis:t||self,i(t.FatcherMiddlewareAborter={}))})(this,function(t){"use strict";const i=
|
|
1
|
+
(function(t,i){typeof exports=="object"&&typeof module!="undefined"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(t=typeof globalThis!="undefined"?globalThis:t||self,i(t.FatcherMiddlewareAborter={}))})(this,function(t){"use strict";const i={name:"fatcher-middleware-aborter",use:async(o,s)=>{const{onAbort:r,abortController:e=new AbortController}=o,n=()=>{r==null||r(e.signal.reason),e.signal.removeEventListener("abort",n)};r&&e.signal.addEventListener("abort",n);const a=await s({abort:e.abort.bind(e),signal:e.signal});return r&&e.signal.removeEventListener("abort",n),a}};function u(o){return o instanceof DOMException&&o.name==="AbortError"}const l={name:"fatcher-middleware-timeout",use:async(o,s)=>{const{abort:r,timeout:e}=o;let n=null;e&&(n=setTimeout(()=>{r()},e));let a;try{a=await s()}catch(c){throw n&&clearTimeout(n),c}return a}};t.aborter=i,t.isAbortError=u,t.timeout=l,Object.defineProperty(t,"__esModule",{value:!0})});
|
package/package.json
CHANGED
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"fatcher": "3.0.0-alpha-
|
|
16
|
+
"fatcher": "3.0.0-alpha-11"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"fatcher": "3.0.0-alpha-
|
|
19
|
+
"fatcher": "3.0.0-alpha-11"
|
|
20
20
|
},
|
|
21
|
-
"version": "3.0.0-alpha-
|
|
21
|
+
"version": "3.0.0-alpha-11",
|
|
22
22
|
"scripts": {
|
|
23
23
|
"clean": "rimraf dist",
|
|
24
24
|
"build": "npm run clean && rollup -c rollup.config.ts",
|