@fatcherjs/middleware-aborter 1.4.0 → 1.6.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/README.md +16 -0
- package/dist/aborter.esm.js +6 -5
- package/dist/aborter.js +6 -5
- package/dist/aborter.min.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -67,6 +67,22 @@ Aborted request will throw a DOMException which can use `isAbortError` to confir
|
|
|
67
67
|
|
|
68
68
|
A callback when aborting this request.
|
|
69
69
|
|
|
70
|
+
### concurrency
|
|
71
|
+
|
|
72
|
+
- Type: `boolean`
|
|
73
|
+
- DefaultValue: `false`
|
|
74
|
+
- Description:
|
|
75
|
+
|
|
76
|
+
Request concurrency restrictions
|
|
77
|
+
|
|
78
|
+
### groupBy
|
|
79
|
+
|
|
80
|
+
- Type: `(context: Readonly<Context>) => string;`
|
|
81
|
+
- DefaultValue: `${context.url}_${context.method}_${new URLSearchParams(context.params).toString()}`
|
|
82
|
+
- Description:
|
|
83
|
+
|
|
84
|
+
Concurrency key.
|
|
85
|
+
|
|
70
86
|
## License
|
|
71
87
|
|
|
72
88
|
[MIT](https://github.com/fatcherjs/fatcher/blob/master/LICENSE)
|
package/dist/aborter.esm.js
CHANGED
|
@@ -20,12 +20,13 @@ function aborter(options = {}) {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
(_c = roadMap[group]) != null ? _c : roadMap[group] = [];
|
|
23
|
+
const trigger = (reason) => {
|
|
24
|
+
abort.call(abortController);
|
|
25
|
+
onAbort == null ? void 0 : onAbort(reason);
|
|
26
|
+
};
|
|
23
27
|
roadMap[group].push({
|
|
24
|
-
abort:
|
|
25
|
-
|
|
26
|
-
onAbort == null ? void 0 : onAbort(reason);
|
|
27
|
-
},
|
|
28
|
-
timer: _timeout ? setTimeout(() => abort("timeout"), _timeout) : null,
|
|
28
|
+
abort: trigger,
|
|
29
|
+
timer: _timeout ? setTimeout(() => trigger("timeout"), _timeout) : null,
|
|
29
30
|
signal
|
|
30
31
|
});
|
|
31
32
|
signal.addEventListener("abort", () => {
|
package/dist/aborter.js
CHANGED
|
@@ -24,12 +24,13 @@ function aborter(options = {}) {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
(_c = roadMap[group]) != null ? _c : roadMap[group] = [];
|
|
27
|
+
const trigger = (reason) => {
|
|
28
|
+
abort.call(abortController);
|
|
29
|
+
onAbort == null ? void 0 : onAbort(reason);
|
|
30
|
+
};
|
|
27
31
|
roadMap[group].push({
|
|
28
|
-
abort:
|
|
29
|
-
|
|
30
|
-
onAbort == null ? void 0 : onAbort(reason);
|
|
31
|
-
},
|
|
32
|
-
timer: _timeout ? setTimeout(() => abort("timeout"), _timeout) : null,
|
|
32
|
+
abort: trigger,
|
|
33
|
+
timer: _timeout ? setTimeout(() => trigger("timeout"), _timeout) : null,
|
|
33
34
|
signal
|
|
34
35
|
});
|
|
35
36
|
signal.addEventListener("abort", () => {
|
package/dist/aborter.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(t,e){typeof exports=="object"&&typeof module
|
|
1
|
+
(function(t,e){typeof exports=="object"&&typeof module!="undefined"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t.FatcherMiddlewareAborter={}))})(this,function(t){"use strict";const e={};function p(o={}){const{timeout:u=0,onAbort:s=null,concurrency:_,groupBy:c}=o;let l=u;return(isNaN(u)||~~u<0)&&(console.warn("[fatcher-middleware-aborter] Timeout is not a valid number."),l=0),{name:"fatcher-middleware-aborter",async use(i,v){var d,f,b;const m=new AbortController,{abort:y,signal:a}=m,w=v({signal:a}),r=(d=c==null?void 0:c(i))!=null?d:`${i.url}_${i.method}_${new URLSearchParams(i.params).toString()}`;((f=e[r])==null?void 0:f.length)&&_&&e[r].forEach(n=>{n.abort("concurrency")}),(b=e[r])!=null||(e[r]=[]);const h=n=>{y.call(m),s==null||s(n)};return e[r].push({abort:h,timer:l?setTimeout(()=>h("timeout"),l):null,signal:a}),a.addEventListener("abort",()=>{e[r]=e[r].filter(n=>n.signal===a?(n.timer&&clearTimeout(n.timer),!1):!0),e[r].length||delete e[r]}),w}}}function g(o){return o instanceof DOMException&&o.name==="AbortError"}t.aborter=p,t.isAbortError=g,Object.defineProperty(t,"__esModule",{value:!0})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fatcherjs/middleware-aborter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"main": "dist/aborter.js",
|
|
5
5
|
"module": "dist/aborter.esm.js",
|
|
6
6
|
"browser": "dist/aborter.min.js",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git+https://github.com/fatcherjs/fatcher.git"
|
|
16
16
|
},
|
|
17
|
-
"
|
|
18
|
-
"fatcher": "^1.
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"fatcher": "^1.6.0"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"dev": "rimraf dist && rollup -c rollup.config.ts -w",
|