@net-vert/core 0.3.6 → 0.3.7

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/dist/index.d.ts CHANGED
@@ -94,6 +94,25 @@ export declare const requestExtender: {
94
94
  sync?: true;
95
95
  } & CacheRequestor<false, true>) => {
96
96
  requestor: Requestor;
97
+ store: {
98
+ has(key: string): boolean;
99
+ get<T>(key: string): T | undefined;
100
+ set<T>(key: string, value: T): T;
101
+ remove(key: string): void;
102
+ clear(): void;
103
+ } | {
104
+ has: (key: string) => Promise<boolean>;
105
+ get: <T>(key: string) => Promise<T | null>;
106
+ set: <T>(key: string, value: T) => Promise<T>;
107
+ remove: (key: string) => Promise<void>;
108
+ clear: () => Promise<void>;
109
+ } | {
110
+ has: (key: string) => boolean;
111
+ get: (key: string) => any;
112
+ set: <T>(key: string, value: T) => Map<string, any>;
113
+ remove: (key: string) => boolean;
114
+ clear: () => void;
115
+ };
97
116
  };
98
117
  };
99
118
 
package/dist/index.js CHANGED
@@ -32,9 +32,9 @@ function j(t) {
32
32
  const e = {};
33
33
  return Object.keys(k).forEach(
34
34
  (r) => {
35
- e[r] = (...n) => {
36
- const o = k[r](...n);
37
- return t(o);
35
+ e[r] = (...o) => {
36
+ const n = k[r](...o);
37
+ return t(n);
38
38
  };
39
39
  }
40
40
  ), {
@@ -59,18 +59,18 @@ class O {
59
59
  if (r)
60
60
  try {
61
61
  return JSON.parse(r);
62
- } catch (n) {
63
- console.error("Error parsing cached data", n);
62
+ } catch (o) {
63
+ console.error("Error parsing cached data", o);
64
64
  return;
65
65
  }
66
66
  }
67
67
  // 设置缓存
68
68
  set(e, r) {
69
69
  try {
70
- const n = JSON.stringify(r);
71
- localStorage.setItem(e, n);
72
- } catch (n) {
73
- console.error("Error saving data to localStorage", n);
70
+ const o = JSON.stringify(r);
71
+ localStorage.setItem(e, o);
72
+ } catch (o) {
73
+ console.error("Error saving data to localStorage", o);
74
74
  }
75
75
  return r;
76
76
  }
@@ -87,35 +87,35 @@ const T = new O(), H = ({ persist: t, name: e, sync: r }) => {
87
87
  if (t && r)
88
88
  return T;
89
89
  if (t) {
90
- const n = D.createInstance({
90
+ const o = D.createInstance({
91
91
  name: e
92
92
  // driver: sync
93
93
  // ?undefined
94
94
  // :localforage.LOCALSTORAGE,
95
95
  });
96
96
  return {
97
- has: (o) => n.keys().then((s) => s.includes(o)),
98
- get: (o) => n.getItem(o),
99
- set: (o, s) => n.setItem(o, s),
100
- remove: (o) => n.removeItem(o),
101
- clear: () => n.clear()
97
+ has: (n) => o.keys().then((s) => s.includes(n)),
98
+ get: (n) => o.getItem(n),
99
+ set: (n, s) => o.setItem(n, s),
100
+ remove: (n) => o.removeItem(n),
101
+ clear: () => o.clear()
102
102
  };
103
103
  } else {
104
- const n = /* @__PURE__ */ new Map();
104
+ const o = /* @__PURE__ */ new Map();
105
105
  return {
106
- has: (o) => n.has(o),
107
- get: (o) => n.get(o),
108
- set: (o, s) => n.set(o, s),
109
- remove: (o) => n.delete(o),
110
- clear: () => n.clear()
106
+ has: (n) => o.has(n),
107
+ get: (n) => o.get(n),
108
+ set: (n, s) => o.set(n, s),
109
+ remove: (n) => o.delete(n),
110
+ clear: () => o.clear()
111
111
  };
112
112
  }
113
113
  }, U = () => {
114
114
  const t = /* @__PURE__ */ new Map();
115
115
  return {
116
116
  getPromise: (s) => t.get(s),
117
- setPromise: (s, i) => {
118
- t.set(s, i);
117
+ setPromise: (s, u) => {
118
+ t.set(s, u);
119
119
  },
120
120
  delPromise: (s) => {
121
121
  t.delete(s);
@@ -133,68 +133,68 @@ const T = new O(), H = ({ persist: t, name: e, sync: r }) => {
133
133
  duration: 1 / 0,
134
134
  sync: !1
135
135
  }, S = (t) => {
136
- const e = { ...A, ...t }, { name: r, persist: n, sync: o } = e, s = H({ persist: n, name: r, sync: o }), { getPromise: i, setPromise: P, delPromise: f } = U();
137
- function c(a, d) {
138
- const { isValid: l } = e, h = s.get(a);
136
+ const e = { ...A, ...t }, { name: r, persist: o, sync: n } = e, s = H({ persist: o, name: r, sync: n }), { getPromise: u, setPromise: w, delPromise: q } = U();
137
+ function l(a, h) {
138
+ const { isValid: i } = e, m = s.get(a);
139
139
  let g = !1;
140
- if (h && x(h)) {
140
+ if (m && x(m)) {
141
141
  try {
142
- g = (l == null ? void 0 : l({
142
+ g = (i == null ? void 0 : i({
143
143
  key: a,
144
- config: d,
145
- cachedData: h
144
+ config: h,
145
+ cachedData: m
146
146
  })) ?? !0;
147
- } catch (u) {
148
- console.error(`校验异常 ${a}`, u);
147
+ } catch (c) {
148
+ console.error(`校验异常 ${a}`, c);
149
149
  }
150
150
  !g && s.remove(a);
151
151
  }
152
- return { shouldUseCache: g, cachedData: h };
152
+ return { shouldUseCache: g, cachedData: m };
153
153
  }
154
- async function w(a, d) {
155
- const { isValid: l } = e, h = await s.get(a);
154
+ async function d(a, h) {
155
+ const { isValid: i } = e, m = await s.get(a);
156
156
  let g = !1;
157
- if (h && x(h)) {
157
+ if (m && x(m)) {
158
158
  try {
159
- g = await (l == null ? void 0 : l({
159
+ g = await (i == null ? void 0 : i({
160
160
  key: a,
161
- config: d,
162
- cachedData: h
161
+ config: h,
162
+ cachedData: m
163
163
  })) ?? !0;
164
- } catch (u) {
165
- console.error(`校验异常 ${a}`, u);
164
+ } catch (c) {
165
+ console.error(`校验异常 ${a}`, c);
166
166
  }
167
167
  !g && s.remove(a);
168
168
  }
169
- return { shouldUseCache: g, cachedData: h };
169
+ return { shouldUseCache: g, cachedData: m };
170
170
  }
171
171
  const p = {
172
- get(a, d) {
173
- function l(u, m, ...y) {
174
- const C = Reflect.apply(a[d], a, y).then(async (q) => {
172
+ get(a, h) {
173
+ function i(c, y, ...f) {
174
+ const C = Reflect.apply(a[h], a, f).then(async (P) => {
175
175
  const R = typeof e.duration == "number" ? e.duration : e.duration({
176
- key: u,
177
- config: m,
178
- response: q
176
+ key: c,
177
+ config: y,
178
+ response: P
179
179
  });
180
- return s.set(u, _(q, R)), q;
180
+ return s.set(c, _(P, R)), P;
181
181
  }).finally(() => {
182
- f(u);
182
+ q(c);
183
183
  });
184
- return P(u, C), C;
184
+ return w(c, C), C;
185
185
  }
186
- return o ? (...u) => {
187
- const m = k[d](...u), y = e.key(m), C = i(y);
186
+ return n ? (...c) => {
187
+ const y = k[h](...c), f = e.key(y), C = u(f);
188
188
  if (C)
189
189
  return C;
190
- const { shouldUseCache: q, cachedData: R } = c(y, m);
191
- return q ? R.value : l(y, m, ...u);
192
- } : async (...u) => {
193
- const m = k[d](...u), y = e.key(m), C = i(y);
190
+ const { shouldUseCache: P, cachedData: R } = l(f, y);
191
+ return P ? R.value : i(f, y, ...c);
192
+ } : async (...c) => {
193
+ const y = k[h](...c), f = e.key(y), C = u(f);
194
194
  if (C)
195
195
  return C;
196
- const { shouldUseCache: q, cachedData: R } = await w(y, m);
197
- return q ? R.value : l(y, m, ...u);
196
+ const { shouldUseCache: P, cachedData: R } = await d(f, y);
197
+ return P ? R.value : i(f, y, ...c);
198
198
  };
199
199
  }
200
200
  };
@@ -203,8 +203,8 @@ const T = new O(), H = ({ persist: t, name: e, sync: r }) => {
203
203
  store: s
204
204
  };
205
205
  }, J = (t) => {
206
- const { method: e, url: r, params: n, data: o } = t;
207
- return [e, r, JSON.stringify(n), JSON.stringify(o)].join("|");
206
+ const { method: e, url: r, params: o, data: n } = t;
207
+ return [e, r, JSON.stringify(o), JSON.stringify(n)].join("|");
208
208
  }, N = (t) => {
209
209
  const {
210
210
  requestor: e
@@ -220,26 +220,26 @@ const T = new O(), H = ({ persist: t, name: e, sync: r }) => {
220
220
  delay: 0,
221
221
  retryCondition: () => !0
222
222
  }, $ = (t) => {
223
- const { retries: e, delay: r, retryCondition: n } = { ...b, ...t }, o = {
224
- get(s, i) {
225
- return (...f) => {
226
- let c = 0;
227
- const w = () => Reflect.apply(s[i], s, f).catch((p) => {
228
- if (c < e && n(p)) {
229
- c++;
230
- const a = typeof r == "function" ? r(c) : r;
231
- return new Promise((d) => {
232
- setTimeout(() => d(w()), a);
223
+ const { retries: e, delay: r, retryCondition: o } = { ...b, ...t }, n = {
224
+ get(s, u) {
225
+ return (...q) => {
226
+ let l = 0;
227
+ const d = () => Reflect.apply(s[u], s, q).catch((p) => {
228
+ if (l < e && o(p)) {
229
+ l++;
230
+ const a = typeof r == "function" ? r(l) : r;
231
+ return new Promise((h) => {
232
+ setTimeout(() => h(d()), a);
233
233
  });
234
234
  }
235
235
  return Promise.reject(p);
236
236
  });
237
- return w();
237
+ return d();
238
238
  };
239
239
  }
240
240
  };
241
241
  return {
242
- requestor: new Proxy(v(), o)
242
+ requestor: new Proxy(v(), n)
243
243
  };
244
244
  };
245
245
  class F {
@@ -248,11 +248,11 @@ class F {
248
248
  }
249
249
  // 加入
250
250
  add(e, r) {
251
- return new Promise((n, o) => {
251
+ return new Promise((o, n) => {
252
252
  this.tasks.enqueue(e, {
253
253
  task: r,
254
- resolve: n,
255
- reject: o
254
+ resolve: o,
255
+ reject: n
256
256
  }), this._run();
257
257
  });
258
258
  }
@@ -261,8 +261,8 @@ class F {
261
261
  this.tasks.remove(e);
262
262
  }
263
263
  execute(e) {
264
- const { task: r, resolve: n, reject: o } = e;
265
- return r().then(n).catch(o).finally(() => {
264
+ const { task: r, resolve: o, reject: n } = e;
265
+ return r().then(o).catch(n).finally(() => {
266
266
  this.runningCount--, this._run();
267
267
  });
268
268
  }
@@ -278,16 +278,16 @@ const L = {
278
278
  retries: 0,
279
279
  createId: () => z()
280
280
  }, Q = (t) => {
281
- const e = { ...L, ...t }, { parallelCount: r, createId: n, ...o } = e, s = new F(r), { requestor: i = null } = o.retries > 0 ? $(o) : {}, P = {
282
- get(f, c) {
281
+ const e = { ...L, ...t }, { parallelCount: r, createId: o, ...n } = e, s = new F(r), { requestor: u = null } = n.retries > 0 ? $(n) : {}, w = {
282
+ get(q, l) {
283
283
  return (...p) => {
284
- const a = k[c](...p), d = n(a), l = () => i ? Reflect.apply(i[c], i, p) : Reflect.apply(f[c], f, p);
285
- return s.add(d, l);
284
+ const a = k[l](...p), h = o(a), i = () => u ? Reflect.apply(u[l], u, p) : Reflect.apply(q[l], q, p);
285
+ return s.add(h, i);
286
286
  };
287
287
  }
288
288
  };
289
289
  return {
290
- requestor: new Proxy(v(), P),
290
+ requestor: new Proxy(v(), w),
291
291
  concurrentPool: s
292
292
  };
293
293
  }, W = {
@@ -295,23 +295,25 @@ const L = {
295
295
  sync: !0
296
296
  }, Y = (t) => {
297
297
  const e = { ...W, ...t }, { ...r } = e, {
298
- requestor: n
299
- } = S(r), o = {
300
- get(s, i) {
301
- return (...f) => {
298
+ requestor: o,
299
+ store: n
300
+ } = S(r), s = {
301
+ get(u, w) {
302
+ return (...l) => {
302
303
  try {
303
- const c = Reflect.apply(s[i], s, f);
304
- if (c instanceof Promise)
305
- throw c;
306
- return c;
307
- } catch (c) {
308
- throw c;
304
+ const d = Reflect.apply(u[w], u, l);
305
+ if (d instanceof Promise)
306
+ throw d;
307
+ return d;
308
+ } catch (d) {
309
+ throw d;
309
310
  }
310
311
  };
311
312
  }
312
313
  };
313
314
  return {
314
- requestor: new Proxy(n, o)
315
+ requestor: new Proxy(o, s),
316
+ store: n
315
317
  };
316
318
  }, X = {
317
319
  cacheRequestor: S,
@@ -1 +1 @@
1
- (function(h,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("localforage"),require("id-queue")):typeof define=="function"&&define.amd?define(["exports","localforage","id-queue"],w):(h=typeof globalThis<"u"?globalThis:h||self,w(h.netVertCore={},h.localforage,h.idQueue))})(this,function(h,w,D){"use strict";const R={get:(t,e)=>({url:t,method:"get",...e,params:e==null?void 0:e.params}),post:(t,e,r)=>({url:t,method:"post",data:e,headers:{"Content-Type":"application/json",...r==null?void 0:r.headers},...r}),delete:(t,e)=>({url:t,method:"delete",...e}),put:(t,e,r)=>({url:t,method:"put",data:e,headers:{"Content-Type":"application/json",...r==null?void 0:r.headers},...r}),request:t=>t};function E(t){const e={};return Object.keys(R).forEach(r=>{e[r]=(...n)=>{const o=R[r](...n);return t(o)}}),{...e,request:t}}const I="default",O=()=>`${Date.now()}_${Math.random().toString().slice(2,8)}`,j=new Map,z=(t,e=I)=>{j.set(e,E(t))},M=(t=I)=>{const e=j.get(t);if(!e)throw new Error(`Requestor实例 ${t} 未注册`);return e};class H{has(e){return!!this.get(e)}get(e){const r=localStorage.getItem(e);if(r)try{return JSON.parse(r)}catch(n){console.error("Error parsing cached data",n);return}}set(e,r){try{const n=JSON.stringify(r);localStorage.setItem(e,n)}catch(n){console.error("Error saving data to localStorage",n)}return r}remove(e){localStorage.removeItem(e)}clear(){localStorage.clear()}}const U=new H,_=({persist:t,name:e,sync:r})=>{if(t&&r)return U;if(t){const n=w.createInstance({name:e});return{has:o=>n.keys().then(s=>s.includes(o)),get:o=>n.getItem(o),set:(o,s)=>n.setItem(o,s),remove:o=>n.removeItem(o),clear:()=>n.clear()}}else{const n=new Map;return{has:o=>n.has(o),get:o=>n.get(o),set:(o,s)=>n.set(o,s),remove:o=>n.delete(o),clear:()=>n.clear()}}},A=()=>{const t=new Map;return{getPromise:s=>t.get(s),setPromise:(s,i)=>{t.set(s,i)},delPromise:s=>{t.delete(s)},clearCache:()=>{t.clear()}}},J=(t,e)=>({value:t,expiresAt:Date.now()+e}),T=t=>t.expiresAt>Date.now(),N={key:t=>t.url,persist:!1,duration:1/0,sync:!1},x=t=>{const e={...N,...t},{name:r,persist:n,sync:o}=e,s=_({persist:n,name:r,sync:o}),{getPromise:i,setPromise:S,delPromise:p}=A();function a(c,d){const{isValid:l}=e,m=s.get(c);let C=!1;if(m&&T(m)){try{C=(l==null?void 0:l({key:c,config:d,cachedData:m}))??!0}catch(u){console.error(`校验异常 ${c}`,u)}!C&&s.remove(c)}return{shouldUseCache:C,cachedData:m}}async function k(c,d){const{isValid:l}=e,m=await s.get(c);let C=!1;if(m&&T(m)){try{C=await(l==null?void 0:l({key:c,config:d,cachedData:m}))??!0}catch(u){console.error(`校验异常 ${c}`,u)}!C&&s.remove(c)}return{shouldUseCache:C,cachedData:m}}const g={get(c,d){function l(u,f,...y){const q=Reflect.apply(c[d],c,y).then(async P=>{const v=typeof e.duration=="number"?e.duration:e.duration({key:u,config:f,response:P});return s.set(u,J(P,v)),P}).finally(()=>{p(u)});return S(u,q),q}return o?(...u)=>{const f=R[d](...u),y=e.key(f),q=i(y);if(q)return q;const{shouldUseCache:P,cachedData:v}=a(y,f);return P?v.value:l(y,f,...u)}:async(...u)=>{const f=R[d](...u),y=e.key(f),q=i(y);if(q)return q;const{shouldUseCache:P,cachedData:v}=await k(y,f);return P?v.value:l(y,f,...u)}}};return{requestor:new Proxy(M(),g),store:s}},b=t=>{const{method:e,url:r,params:n,data:o}=t;return[e,r,JSON.stringify(n),JSON.stringify(o)].join("|")},Q=t=>{const{requestor:e}=x({key:r=>t?t(r):b(r),persist:!1});return{requestor:e}},F={retries:3,delay:0,retryCondition:()=>!0},$=t=>{const{retries:e,delay:r,retryCondition:n}={...F,...t},o={get(s,i){return(...p)=>{let a=0;const k=()=>Reflect.apply(s[i],s,p).catch(g=>{if(a<e&&n(g)){a++;const c=typeof r=="function"?r(a):r;return new Promise(d=>{setTimeout(()=>d(k()),c)})}return Promise.reject(g)});return k()}}};return{requestor:new Proxy(M(),o)}};class L{constructor(e=4){this.parallelCount=e,this.tasks=new D.TaskQueue,this.runningCount=0}add(e,r){return new Promise((n,o)=>{this.tasks.enqueue(e,{task:r,resolve:n,reject:o}),this._run()})}remove(e){this.tasks.remove(e)}execute(e){const{task:r,resolve:n,reject:o}=e;return r().then(n).catch(o).finally(()=>{this.runningCount--,this._run()})}_run(){for(;this.runningCount<this.parallelCount&&this.tasks.size>0;){const e=this.tasks.dequeue();this.runningCount++,this.execute(e)}}}const V={parallelCount:4,retries:0,createId:()=>O()},W=t=>{const e={...V,...t},{parallelCount:r,createId:n,...o}=e,s=new L(r),{requestor:i=null}=o.retries>0?$(o):{},S={get(p,a){return(...g)=>{const c=R[a](...g),d=n(c),l=()=>i?Reflect.apply(i[a],i,g):Reflect.apply(p[a],p,g);return s.add(d,l)}}};return{requestor:new Proxy(M(),S),concurrentPool:s}},Y={persist:!1,sync:!0},B={cacheRequestor:x,idempotencyRequestor:Q,retryRequestor:$,concurrentPoolRequestor:W,syncRequestor:t=>{const e={...Y,...t},{...r}=e,{requestor:n}=x(r),o={get(s,i){return(...p)=>{try{const a=Reflect.apply(s[i],s,p);if(a instanceof Promise)throw a;return a}catch(a){throw a}}}};return{requestor:new Proxy(n,o)}}};h.inject=z,h.requestExtender=B,h.useRequestor=M,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(m,S){typeof exports=="object"&&typeof module<"u"?S(exports,require("localforage"),require("id-queue")):typeof define=="function"&&define.amd?define(["exports","localforage","id-queue"],S):(m=typeof globalThis<"u"?globalThis:m||self,S(m.netVertCore={},m.localforage,m.idQueue))})(this,function(m,S,D){"use strict";const k={get:(t,e)=>({url:t,method:"get",...e,params:e==null?void 0:e.params}),post:(t,e,r)=>({url:t,method:"post",data:e,headers:{"Content-Type":"application/json",...r==null?void 0:r.headers},...r}),delete:(t,e)=>({url:t,method:"delete",...e}),put:(t,e,r)=>({url:t,method:"put",data:e,headers:{"Content-Type":"application/json",...r==null?void 0:r.headers},...r}),request:t=>t};function E(t){const e={};return Object.keys(k).forEach(r=>{e[r]=(...n)=>{const o=k[r](...n);return t(o)}}),{...e,request:t}}const I="default",O=()=>`${Date.now()}_${Math.random().toString().slice(2,8)}`,j=new Map,z=(t,e=I)=>{j.set(e,E(t))},M=(t=I)=>{const e=j.get(t);if(!e)throw new Error(`Requestor实例 ${t} 未注册`);return e};class H{has(e){return!!this.get(e)}get(e){const r=localStorage.getItem(e);if(r)try{return JSON.parse(r)}catch(n){console.error("Error parsing cached data",n);return}}set(e,r){try{const n=JSON.stringify(r);localStorage.setItem(e,n)}catch(n){console.error("Error saving data to localStorage",n)}return r}remove(e){localStorage.removeItem(e)}clear(){localStorage.clear()}}const U=new H,_=({persist:t,name:e,sync:r})=>{if(t&&r)return U;if(t){const n=S.createInstance({name:e});return{has:o=>n.keys().then(s=>s.includes(o)),get:o=>n.getItem(o),set:(o,s)=>n.setItem(o,s),remove:o=>n.removeItem(o),clear:()=>n.clear()}}else{const n=new Map;return{has:o=>n.has(o),get:o=>n.get(o),set:(o,s)=>n.set(o,s),remove:o=>n.delete(o),clear:()=>n.clear()}}},A=()=>{const t=new Map;return{getPromise:s=>t.get(s),setPromise:(s,u)=>{t.set(s,u)},delPromise:s=>{t.delete(s)},clearCache:()=>{t.clear()}}},J=(t,e)=>({value:t,expiresAt:Date.now()+e}),T=t=>t.expiresAt>Date.now(),N={key:t=>t.url,persist:!1,duration:1/0,sync:!1},x=t=>{const e={...N,...t},{name:r,persist:n,sync:o}=e,s=_({persist:n,name:r,sync:o}),{getPromise:u,setPromise:R,delPromise:P}=A();function l(c,h){const{isValid:i}=e,f=s.get(c);let C=!1;if(f&&T(f)){try{C=(i==null?void 0:i({key:c,config:h,cachedData:f}))??!0}catch(a){console.error(`校验异常 ${c}`,a)}!C&&s.remove(c)}return{shouldUseCache:C,cachedData:f}}async function d(c,h){const{isValid:i}=e,f=await s.get(c);let C=!1;if(f&&T(f)){try{C=await(i==null?void 0:i({key:c,config:h,cachedData:f}))??!0}catch(a){console.error(`校验异常 ${c}`,a)}!C&&s.remove(c)}return{shouldUseCache:C,cachedData:f}}const g={get(c,h){function i(a,y,...p){const q=Reflect.apply(c[h],c,p).then(async w=>{const v=typeof e.duration=="number"?e.duration:e.duration({key:a,config:y,response:w});return s.set(a,J(w,v)),w}).finally(()=>{P(a)});return R(a,q),q}return o?(...a)=>{const y=k[h](...a),p=e.key(y),q=u(p);if(q)return q;const{shouldUseCache:w,cachedData:v}=l(p,y);return w?v.value:i(p,y,...a)}:async(...a)=>{const y=k[h](...a),p=e.key(y),q=u(p);if(q)return q;const{shouldUseCache:w,cachedData:v}=await d(p,y);return w?v.value:i(p,y,...a)}}};return{requestor:new Proxy(M(),g),store:s}},b=t=>{const{method:e,url:r,params:n,data:o}=t;return[e,r,JSON.stringify(n),JSON.stringify(o)].join("|")},Q=t=>{const{requestor:e}=x({key:r=>t?t(r):b(r),persist:!1});return{requestor:e}},F={retries:3,delay:0,retryCondition:()=>!0},$=t=>{const{retries:e,delay:r,retryCondition:n}={...F,...t},o={get(s,u){return(...P)=>{let l=0;const d=()=>Reflect.apply(s[u],s,P).catch(g=>{if(l<e&&n(g)){l++;const c=typeof r=="function"?r(l):r;return new Promise(h=>{setTimeout(()=>h(d()),c)})}return Promise.reject(g)});return d()}}};return{requestor:new Proxy(M(),o)}};class L{constructor(e=4){this.parallelCount=e,this.tasks=new D.TaskQueue,this.runningCount=0}add(e,r){return new Promise((n,o)=>{this.tasks.enqueue(e,{task:r,resolve:n,reject:o}),this._run()})}remove(e){this.tasks.remove(e)}execute(e){const{task:r,resolve:n,reject:o}=e;return r().then(n).catch(o).finally(()=>{this.runningCount--,this._run()})}_run(){for(;this.runningCount<this.parallelCount&&this.tasks.size>0;){const e=this.tasks.dequeue();this.runningCount++,this.execute(e)}}}const V={parallelCount:4,retries:0,createId:()=>O()},W=t=>{const e={...V,...t},{parallelCount:r,createId:n,...o}=e,s=new L(r),{requestor:u=null}=o.retries>0?$(o):{},R={get(P,l){return(...g)=>{const c=k[l](...g),h=n(c),i=()=>u?Reflect.apply(u[l],u,g):Reflect.apply(P[l],P,g);return s.add(h,i)}}};return{requestor:new Proxy(M(),R),concurrentPool:s}},Y={persist:!1,sync:!0},B={cacheRequestor:x,idempotencyRequestor:Q,retryRequestor:$,concurrentPoolRequestor:W,syncRequestor:t=>{const e={...Y,...t},{...r}=e,{requestor:n,store:o}=x(r),s={get(u,R){return(...l)=>{try{const d=Reflect.apply(u[R],u,l);if(d instanceof Promise)throw d;return d}catch(d){throw d}}}};return{requestor:new Proxy(n,s),store:o}}};m.inject=z,m.requestExtender=B,m.useRequestor=M,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@net-vert/core",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "Dependency Inversion Network Library with Type-Safe Injection.",
5
5
  "main": "dist/index",
6
6
  "type": "module",