MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / patchAPIInstance

Function patchAPIInstance

web/src/helpers/api.js:15–41  ·  view source on GitHub ↗
(instance)

Source from the content-addressed store, hash-verified

13});
14
15function patchAPIInstance(instance) {
16 const originalGet = instance.get.bind(instance);
17 const inFlightGetRequests = new Map();
18
19 const genKey = (url, config = {}) => {
20 const params = config.params ? JSON.stringify(config.params) : '{}';
21 return `${url}?${params}`;
22 };
23
24 instance.get = (url, config = {}) => {
25 if (config?.disableDuplicate) {
26 return originalGet(url, config);
27 }
28
29 const key = genKey(url, config);
30 if (inFlightGetRequests.has(key)) {
31 return inFlightGetRequests.get(key);
32 }
33
34 const reqPromise = originalGet(url, config).finally(() => {
35 inFlightGetRequests.delete(key);
36 });
37
38 inFlightGetRequests.set(key, reqPromise);
39 return reqPromise;
40 };
41}
42
43patchAPIInstance(API);
44

Callers 2

api.jsFile · 0.85
updateAPIFunction · 0.85

Calls 1

genKeyFunction · 0.85

Tested by

no test coverage detected