@fatcherjs/middleware-aborter 1.4.0 → 1.4.1

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 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)
@@ -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: (reason) => {
25
- abort.call(abortController);
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: (reason) => {
29
- abort.call(abortController);
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", () => {
@@ -1 +1 @@
1
- (function(t,e){typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t.FatcherMiddlewareAborter={}))})(this,function(t){"use strict";const e={};function p(o={}){const{timeout:u=0,onAbort:s=null,concurrency:g,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:h,signal:a}=m,y=v({signal:a}),r=(d=c?.(i))!=null?d:`${i.url}_${i.method}_${new URLSearchParams(i.params).toString()}`;return((f=e[r])==null?void 0:f.length)&&g&&e[r].forEach(n=>{n.abort("concurrency")}),(b=e[r])!=null||(e[r]=[]),e[r].push({abort:n=>{h.call(m),s?.(n)},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]}),y}}}function _(o){return o instanceof DOMException&&o.name==="AbortError"}t.aborter=p,t.isAbortError=_,Object.defineProperty(t,"__esModule",{value:!0})});
1
+ (function(t,e){typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis<"u"?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?.(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?.(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.4.0",
3
+ "version": "1.4.1",
4
4
  "main": "dist/aborter.js",
5
5
  "module": "dist/aborter.esm.js",
6
6
  "browser": "dist/aborter.min.js",