@net-vert/core 0.4.1 → 0.5.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/dist/index.d.ts +25 -1
- package/dist/index.js +84 -72
- package/dist/index.umd.cjs +1 -1
- package/package.json +39 -39
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,11 @@ declare type Duration = number | (({ key, config, response }: {
|
|
|
31
31
|
response: any;
|
|
32
32
|
}) => number);
|
|
33
33
|
|
|
34
|
+
declare type IdempotencyOptions = {
|
|
35
|
+
key?: (config: UnifiedConfig) => string;
|
|
36
|
+
duration?: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
34
39
|
export declare const inject: (requestor: UnifiedRequestor, instanceKey?: string) => void;
|
|
35
40
|
|
|
36
41
|
declare type IsValidParams = {
|
|
@@ -76,8 +81,27 @@ export declare const requestExtender: {
|
|
|
76
81
|
clear: () => void;
|
|
77
82
|
};
|
|
78
83
|
};
|
|
79
|
-
idempotencyRequestor: (
|
|
84
|
+
idempotencyRequestor: (config?: IdempotencyOptions) => {
|
|
80
85
|
requestor: Requestor;
|
|
86
|
+
store: {
|
|
87
|
+
has(key: string): boolean;
|
|
88
|
+
get<T>(key: string): T | undefined;
|
|
89
|
+
set<T>(key: string, value: T): T;
|
|
90
|
+
remove(key: string): void;
|
|
91
|
+
clear(): void;
|
|
92
|
+
} | {
|
|
93
|
+
has: (key: string) => Promise<boolean>;
|
|
94
|
+
get: <T>(key: string) => Promise<T | null>;
|
|
95
|
+
set: <T>(key: string, value: T) => Promise<T>;
|
|
96
|
+
remove: (key: string) => Promise<void>;
|
|
97
|
+
clear: () => Promise<void>;
|
|
98
|
+
} | {
|
|
99
|
+
has: (key: string) => boolean;
|
|
100
|
+
get: (key: string) => any;
|
|
101
|
+
set: <T>(key: string, value: T) => Map<string, any>;
|
|
102
|
+
remove: (key: string) => boolean;
|
|
103
|
+
clear: () => void;
|
|
104
|
+
};
|
|
81
105
|
};
|
|
82
106
|
retryRequestor: (config?: RetryOptions) => {
|
|
83
107
|
requestor: Requestor;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { TaskQueue as
|
|
1
|
+
import E from "localforage";
|
|
2
|
+
import { TaskQueue as j } from "id-queue";
|
|
3
3
|
const k = {
|
|
4
4
|
get: (t, e) => ({
|
|
5
5
|
url: t,
|
|
@@ -28,7 +28,7 @@ const k = {
|
|
|
28
28
|
}),
|
|
29
29
|
request: (t) => t
|
|
30
30
|
};
|
|
31
|
-
function
|
|
31
|
+
function T(t) {
|
|
32
32
|
const e = {};
|
|
33
33
|
return Object.keys(k).forEach(
|
|
34
34
|
(r) => {
|
|
@@ -39,8 +39,8 @@ function j(t) {
|
|
|
39
39
|
}
|
|
40
40
|
), e;
|
|
41
41
|
}
|
|
42
|
-
const M = "default", z = () => `${Date.now()}_${Math.random().toString().slice(2, 8)}`, I = /* @__PURE__ */ new Map(),
|
|
43
|
-
I.set(e,
|
|
42
|
+
const M = "default", z = () => `${Date.now()}_${Math.random().toString().slice(2, 8)}`, I = /* @__PURE__ */ new Map(), Z = (t, e = M) => {
|
|
43
|
+
I.set(e, T(t));
|
|
44
44
|
}, v = (t = M) => {
|
|
45
45
|
const e = I.get(t);
|
|
46
46
|
if (!e) throw new Error(`Requestor实例 ${t} 未注册`);
|
|
@@ -80,11 +80,11 @@ class O {
|
|
|
80
80
|
localStorage.clear();
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
const
|
|
83
|
+
const H = new O(), U = ({ persist: t, name: e, sync: r }) => {
|
|
84
84
|
if (t && r)
|
|
85
|
-
return
|
|
85
|
+
return H;
|
|
86
86
|
if (t) {
|
|
87
|
-
const o =
|
|
87
|
+
const o = E.createInstance({
|
|
88
88
|
name: e
|
|
89
89
|
// driver: sync
|
|
90
90
|
// ?undefined
|
|
@@ -107,7 +107,7 @@ const T = new O(), H = ({ persist: t, name: e, sync: r }) => {
|
|
|
107
107
|
clear: () => o.clear()
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
|
-
},
|
|
110
|
+
}, _ = () => {
|
|
111
111
|
const t = /* @__PURE__ */ new Map();
|
|
112
112
|
return {
|
|
113
113
|
getPromise: (s) => t.get(s),
|
|
@@ -121,77 +121,84 @@ const T = new O(), H = ({ persist: t, name: e, sync: r }) => {
|
|
|
121
121
|
t.clear();
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
|
-
},
|
|
124
|
+
}, A = (t, e) => ({
|
|
125
125
|
value: t,
|
|
126
126
|
expiresAt: Date.now() + e
|
|
127
|
-
}), x = (t) => t.expiresAt > Date.now(),
|
|
127
|
+
}), x = (t) => t.expiresAt > Date.now(), J = {
|
|
128
128
|
key: (t) => t.url,
|
|
129
129
|
persist: !1,
|
|
130
130
|
duration: 1 / 0,
|
|
131
131
|
sync: !1
|
|
132
132
|
}, S = (t) => {
|
|
133
|
-
const e = { ...
|
|
133
|
+
const e = { ...J, ...t }, { name: r, persist: o, sync: n } = e, s = U({ persist: o, name: r, sync: n }), { getPromise: u, setPromise: P, delPromise: g } = _();
|
|
134
134
|
function l(a, h) {
|
|
135
|
-
const { isValid: i } = e,
|
|
136
|
-
let
|
|
137
|
-
if (
|
|
135
|
+
const { isValid: i } = e, f = s.get(a);
|
|
136
|
+
let C = !1;
|
|
137
|
+
if (f && x(f)) {
|
|
138
138
|
try {
|
|
139
|
-
|
|
139
|
+
C = (i == null ? void 0 : i({
|
|
140
140
|
key: a,
|
|
141
141
|
config: h,
|
|
142
|
-
cachedData:
|
|
142
|
+
cachedData: f
|
|
143
143
|
})) ?? !0;
|
|
144
144
|
} catch (c) {
|
|
145
145
|
console.error(`校验异常 ${a}`, c);
|
|
146
146
|
}
|
|
147
|
-
!
|
|
147
|
+
!C && s.remove(a);
|
|
148
148
|
}
|
|
149
|
-
return { shouldUseCache:
|
|
149
|
+
return { shouldUseCache: C, cachedData: f };
|
|
150
150
|
}
|
|
151
151
|
async function d(a, h) {
|
|
152
|
-
const { isValid: i } = e,
|
|
153
|
-
let
|
|
154
|
-
if (
|
|
152
|
+
const { isValid: i } = e, f = await s.get(a);
|
|
153
|
+
let C = !1;
|
|
154
|
+
if (f && x(f)) {
|
|
155
155
|
try {
|
|
156
|
-
|
|
156
|
+
C = await (i == null ? void 0 : i({
|
|
157
157
|
key: a,
|
|
158
158
|
config: h,
|
|
159
|
-
cachedData:
|
|
159
|
+
cachedData: f
|
|
160
160
|
})) ?? !0;
|
|
161
161
|
} catch (c) {
|
|
162
162
|
console.error(`校验异常 ${a}`, c);
|
|
163
163
|
}
|
|
164
|
-
!
|
|
164
|
+
!C && s.remove(a);
|
|
165
165
|
}
|
|
166
|
-
return { shouldUseCache:
|
|
166
|
+
return { shouldUseCache: C, cachedData: f };
|
|
167
167
|
}
|
|
168
168
|
const p = {
|
|
169
169
|
get(a, h) {
|
|
170
|
-
function i(c, y, ...
|
|
171
|
-
const
|
|
170
|
+
function i(c, y, ...m) {
|
|
171
|
+
const q = Reflect.apply(a[h], a, m).then(async (w) => {
|
|
172
172
|
const R = typeof e.duration == "number" ? e.duration : e.duration({
|
|
173
173
|
key: c,
|
|
174
174
|
config: y,
|
|
175
|
-
response:
|
|
175
|
+
response: w
|
|
176
176
|
});
|
|
177
|
-
return s.set(c,
|
|
177
|
+
return s.set(c, A(w, R)), w;
|
|
178
178
|
}).finally(() => {
|
|
179
|
-
|
|
179
|
+
g(c);
|
|
180
180
|
});
|
|
181
|
-
return
|
|
181
|
+
return P(c, q), q;
|
|
182
182
|
}
|
|
183
183
|
return n ? (...c) => {
|
|
184
|
-
const y = k[h](...c),
|
|
185
|
-
if (
|
|
186
|
-
return
|
|
187
|
-
const { shouldUseCache:
|
|
188
|
-
return
|
|
189
|
-
} :
|
|
190
|
-
const y = k[h](...c),
|
|
191
|
-
if (
|
|
192
|
-
return
|
|
193
|
-
const
|
|
194
|
-
|
|
184
|
+
const y = k[h](...c), m = e.key(y), q = u(m);
|
|
185
|
+
if (q)
|
|
186
|
+
return q;
|
|
187
|
+
const { shouldUseCache: w, cachedData: R } = l(m, y);
|
|
188
|
+
return w ? R.value : i(m, y, ...c);
|
|
189
|
+
} : (...c) => {
|
|
190
|
+
const y = k[h](...c), m = e.key(y), q = u(m);
|
|
191
|
+
if (q)
|
|
192
|
+
return q;
|
|
193
|
+
const w = (async () => {
|
|
194
|
+
try {
|
|
195
|
+
const { shouldUseCache: R, cachedData: D } = await d(m, y);
|
|
196
|
+
return R ? D.value : await i(m, y, ...c);
|
|
197
|
+
} finally {
|
|
198
|
+
g(m);
|
|
199
|
+
}
|
|
200
|
+
})();
|
|
201
|
+
return P(m, w), w;
|
|
195
202
|
};
|
|
196
203
|
}
|
|
197
204
|
};
|
|
@@ -199,29 +206,34 @@ const T = new O(), H = ({ persist: t, name: e, sync: r }) => {
|
|
|
199
206
|
requestor: new Proxy(v(), p),
|
|
200
207
|
store: s
|
|
201
208
|
};
|
|
202
|
-
},
|
|
209
|
+
}, N = (t) => {
|
|
203
210
|
const { method: e, url: r, params: o, data: n } = t;
|
|
204
211
|
return [e, r, JSON.stringify(o), JSON.stringify(n)].join("|");
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
|
|
212
|
+
}, b = {
|
|
213
|
+
key: N,
|
|
214
|
+
duration: 1e3
|
|
215
|
+
}, F = (t) => {
|
|
216
|
+
const e = { ...b, ...t }, {
|
|
217
|
+
requestor: r,
|
|
218
|
+
store: o
|
|
208
219
|
} = S({
|
|
209
|
-
|
|
220
|
+
...e,
|
|
210
221
|
persist: !1
|
|
211
222
|
});
|
|
212
223
|
return {
|
|
213
|
-
requestor:
|
|
224
|
+
requestor: r,
|
|
225
|
+
store: o
|
|
214
226
|
};
|
|
215
|
-
},
|
|
227
|
+
}, L = {
|
|
216
228
|
retries: 3,
|
|
217
229
|
delay: 0,
|
|
218
230
|
retryCondition: () => !0
|
|
219
231
|
}, $ = (t) => {
|
|
220
|
-
const { retries: e, delay: r, retryCondition: o } = { ...
|
|
232
|
+
const { retries: e, delay: r, retryCondition: o } = { ...L, ...t }, n = {
|
|
221
233
|
get(s, u) {
|
|
222
|
-
return (...
|
|
234
|
+
return (...g) => {
|
|
223
235
|
let l = 0;
|
|
224
|
-
const d = () => Reflect.apply(s[u], s,
|
|
236
|
+
const d = () => Reflect.apply(s[u], s, g).catch((p) => {
|
|
225
237
|
if (l < e && o(p)) {
|
|
226
238
|
l++;
|
|
227
239
|
const a = typeof r == "function" ? r(l) : r;
|
|
@@ -239,9 +251,9 @@ const T = new O(), H = ({ persist: t, name: e, sync: r }) => {
|
|
|
239
251
|
requestor: new Proxy(v(), n)
|
|
240
252
|
};
|
|
241
253
|
};
|
|
242
|
-
class
|
|
254
|
+
class Q {
|
|
243
255
|
constructor(e = 4) {
|
|
244
|
-
this.parallelCount = e, this.tasks = new
|
|
256
|
+
this.parallelCount = e, this.tasks = new j(), this.runningCount = 0;
|
|
245
257
|
}
|
|
246
258
|
// 加入
|
|
247
259
|
add(e, r) {
|
|
@@ -270,35 +282,35 @@ class F {
|
|
|
270
282
|
}
|
|
271
283
|
}
|
|
272
284
|
}
|
|
273
|
-
const
|
|
285
|
+
const W = {
|
|
274
286
|
parallelCount: 4,
|
|
275
287
|
retries: 0,
|
|
276
288
|
createId: () => z()
|
|
277
|
-
},
|
|
278
|
-
const e = { ...
|
|
279
|
-
get(
|
|
289
|
+
}, Y = (t) => {
|
|
290
|
+
const e = { ...W, ...t }, { parallelCount: r, createId: o, ...n } = e, s = new Q(r), { requestor: u = null } = n.retries > 0 ? $(n) : {}, P = {
|
|
291
|
+
get(g, l) {
|
|
280
292
|
return (...p) => {
|
|
281
|
-
const a = k[l](...p), h = o(a), i = () => u ? Reflect.apply(u[l], u, p) : Reflect.apply(
|
|
293
|
+
const a = k[l](...p), h = o(a), i = () => u ? Reflect.apply(u[l], u, p) : Reflect.apply(g[l], g, p);
|
|
282
294
|
return s.add(h, i);
|
|
283
295
|
};
|
|
284
296
|
}
|
|
285
297
|
};
|
|
286
298
|
return {
|
|
287
|
-
requestor: new Proxy(v(),
|
|
299
|
+
requestor: new Proxy(v(), P),
|
|
288
300
|
concurrentPool: s
|
|
289
301
|
};
|
|
290
|
-
},
|
|
302
|
+
}, B = {
|
|
291
303
|
persist: !1,
|
|
292
304
|
sync: !0
|
|
293
|
-
},
|
|
294
|
-
const e = { ...
|
|
305
|
+
}, G = (t) => {
|
|
306
|
+
const e = { ...B, ...t }, { ...r } = e, {
|
|
295
307
|
requestor: o,
|
|
296
308
|
store: n
|
|
297
309
|
} = S(r), s = {
|
|
298
|
-
get(u,
|
|
310
|
+
get(u, P) {
|
|
299
311
|
return (...l) => {
|
|
300
312
|
try {
|
|
301
|
-
const d = Reflect.apply(u[
|
|
313
|
+
const d = Reflect.apply(u[P], u, l);
|
|
302
314
|
if (d instanceof Promise)
|
|
303
315
|
throw d;
|
|
304
316
|
return d;
|
|
@@ -312,15 +324,15 @@ const L = {
|
|
|
312
324
|
requestor: new Proxy(o, s),
|
|
313
325
|
store: n
|
|
314
326
|
};
|
|
315
|
-
},
|
|
327
|
+
}, K = {
|
|
316
328
|
cacheRequestor: S,
|
|
317
|
-
idempotencyRequestor:
|
|
329
|
+
idempotencyRequestor: F,
|
|
318
330
|
retryRequestor: $,
|
|
319
|
-
concurrentPoolRequestor:
|
|
320
|
-
syncRequestor:
|
|
331
|
+
concurrentPoolRequestor: Y,
|
|
332
|
+
syncRequestor: G
|
|
321
333
|
};
|
|
322
334
|
export {
|
|
323
|
-
|
|
324
|
-
|
|
335
|
+
Z as inject,
|
|
336
|
+
K as requestExtender,
|
|
325
337
|
v as useRequestor
|
|
326
338
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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}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:
|
|
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}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(a,h){const{isValid:i}=e,y=s.get(a);let q=!1;if(y&&T(y)){try{q=(i==null?void 0:i({key:a,config:h,cachedData:y}))??!0}catch(c){console.error(`校验异常 ${a}`,c)}!q&&s.remove(a)}return{shouldUseCache:q,cachedData:y}}async function d(a,h){const{isValid:i}=e,y=await s.get(a);let q=!1;if(y&&T(y)){try{q=await(i==null?void 0:i({key:a,config:h,cachedData:y}))??!0}catch(c){console.error(`校验异常 ${a}`,c)}!q&&s.remove(a)}return{shouldUseCache:q,cachedData:y}}const C={get(a,h){function i(c,g,...f){const P=Reflect.apply(a[h],a,f).then(async w=>{const v=typeof e.duration=="number"?e.duration:e.duration({key:c,config:g,response:w});return s.set(c,J(w,v)),w}).finally(()=>{p(c)});return R(c,P),P}return o?(...c)=>{const g=k[h](...c),f=e.key(g),P=u(f);if(P)return P;const{shouldUseCache:w,cachedData:v}=l(f,g);return w?v.value:i(f,g,...c)}:(...c)=>{const g=k[h](...c),f=e.key(g),P=u(f);if(P)return P;const w=(async()=>{try{const{shouldUseCache:v,cachedData:G}=await d(f,g);return v?G.value:await i(f,g,...c)}finally{p(f)}})();return R(f,w),w}}};return{requestor:new Proxy(M(),C),store:s}},b={key:t=>{const{method:e,url:r,params:n,data:o}=t;return[e,r,JSON.stringify(n),JSON.stringify(o)].join("|")},duration:1e3},Q=t=>{const e={...b,...t},{requestor:r,store:n}=x({...e,persist:!1});return{requestor:r,store:n}},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(C=>{if(l<e&&n(C)){l++;const a=typeof r=="function"?r(l):r;return new Promise(h=>{setTimeout(()=>h(d()),a)})}return Promise.reject(C)});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(...C)=>{const a=k[l](...C),h=n(a),i=()=>u?Reflect.apply(u[l],u,C):Reflect.apply(p[l],p,C);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,39 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@net-vert/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Dependency Inversion Network Library with Type-Safe Injection.",
|
|
5
|
-
"main": "dist/index",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@net-vert/core",
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "Dependency Inversion Network Library with Type-Safe Injection.",
|
|
5
|
+
"main": "dist/index",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"typescript": "^5.7.2"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"keywords": [
|
|
16
|
+
"dependency-injection",
|
|
17
|
+
"di",
|
|
18
|
+
"network-library",
|
|
19
|
+
"adapter-pattern",
|
|
20
|
+
"extensible",
|
|
21
|
+
"http-client",
|
|
22
|
+
"lightweight"
|
|
23
|
+
],
|
|
24
|
+
"author": "yuzinan <1589937631@qq.com>",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"id-queue": "^1.0.10",
|
|
31
|
+
"localforage": "^1.10.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"test": "vitest",
|
|
35
|
+
"build": "run-p type-check build-only",
|
|
36
|
+
"build-only": "vite build",
|
|
37
|
+
"type-check": "tsc --noEmit"
|
|
38
|
+
}
|
|
39
|
+
}
|