@tanstack/query-async-storage-persister 5.101.4 → 5.102.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/build/legacy/asyncThrottle.cjs +31 -62
- package/build/legacy/asyncThrottle.cjs.map +1 -1
- package/build/legacy/asyncThrottle.d.cts +9 -1
- package/build/legacy/asyncThrottle.d.cts.map +1 -0
- package/build/legacy/asyncThrottle.d.ts +9 -1
- package/build/legacy/asyncThrottle.d.ts.map +1 -0
- package/build/legacy/asyncThrottle.js +28 -35
- package/build/legacy/asyncThrottle.js.map +1 -1
- package/build/legacy/index.cjs +45 -83
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +34 -2
- package/build/legacy/index.d.cts.map +1 -0
- package/build/legacy/index.d.ts +34 -2
- package/build/legacy/index.d.ts.map +1 -0
- package/build/legacy/index.js +44 -58
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/utils.cjs +5 -30
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +6 -1
- package/build/legacy/utils.d.cts.map +1 -0
- package/build/legacy/utils.d.ts +6 -1
- package/build/legacy/utils.d.ts.map +1 -0
- package/build/legacy/utils.js +5 -6
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/asyncThrottle.cjs +31 -62
- package/build/modern/asyncThrottle.cjs.map +1 -1
- package/build/modern/asyncThrottle.d.cts +9 -1
- package/build/modern/asyncThrottle.d.cts.map +1 -0
- package/build/modern/asyncThrottle.d.ts +9 -1
- package/build/modern/asyncThrottle.d.ts.map +1 -0
- package/build/modern/asyncThrottle.js +28 -35
- package/build/modern/asyncThrottle.js.map +1 -1
- package/build/modern/index.cjs +45 -83
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +34 -2
- package/build/modern/index.d.cts.map +1 -0
- package/build/modern/index.d.ts +34 -2
- package/build/modern/index.d.ts.map +1 -0
- package/build/modern/index.js +44 -58
- package/build/modern/index.js.map +1 -1
- package/build/modern/utils.cjs +5 -30
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +6 -1
- package/build/modern/utils.d.cts.map +1 -0
- package/build/modern/utils.d.ts +6 -1
- package/build/modern/utils.d.ts.map +1 -0
- package/build/modern/utils.js +5 -6
- package/build/modern/utils.js.map +1 -1
- package/package.json +5 -7
- package/build/legacy/_tsup-dts-rollup.d.cts +0 -50
- package/build/legacy/_tsup-dts-rollup.d.ts +0 -50
- package/build/modern/_tsup-dts-rollup.d.cts +0 -50
- package/build/modern/_tsup-dts-rollup.d.ts +0 -50
|
@@ -1,64 +1,33 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (typeof func !== "function") throw new Error("argument is not function.");
|
|
30
|
-
let nextExecutionTime = 0;
|
|
31
|
-
let lastArgs = null;
|
|
32
|
-
let isExecuting = false;
|
|
33
|
-
let isScheduled = false;
|
|
34
|
-
return async (...args) => {
|
|
35
|
-
lastArgs = args;
|
|
36
|
-
if (isScheduled) return;
|
|
37
|
-
isScheduled = true;
|
|
38
|
-
while (isExecuting) {
|
|
39
|
-
await new Promise((done) => import_query_core.timeoutManager.setTimeout(done, interval));
|
|
40
|
-
}
|
|
41
|
-
while (Date.now() < nextExecutionTime) {
|
|
42
|
-
await new Promise(
|
|
43
|
-
(done) => import_query_core.timeoutManager.setTimeout(done, nextExecutionTime - Date.now())
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
isScheduled = false;
|
|
47
|
-
isExecuting = true;
|
|
48
|
-
try {
|
|
49
|
-
await func(...lastArgs);
|
|
50
|
-
} catch (error) {
|
|
51
|
-
try {
|
|
52
|
-
onError(error);
|
|
53
|
-
} catch {
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
nextExecutionTime = Date.now() + interval;
|
|
57
|
-
isExecuting = false;
|
|
58
|
-
};
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils = require("./utils.cjs");
|
|
3
|
+
let _tanstack_query_core = require("@tanstack/query-core");
|
|
4
|
+
//#region src/asyncThrottle.ts
|
|
5
|
+
function asyncThrottle(func, { interval = 1e3, onError = require_utils.noop } = {}) {
|
|
6
|
+
if (typeof func !== "function") throw new Error("argument is not function.");
|
|
7
|
+
let nextExecutionTime = 0;
|
|
8
|
+
let lastArgs = null;
|
|
9
|
+
let isExecuting = false;
|
|
10
|
+
let isScheduled = false;
|
|
11
|
+
return async (...args) => {
|
|
12
|
+
lastArgs = args;
|
|
13
|
+
if (isScheduled) return;
|
|
14
|
+
isScheduled = true;
|
|
15
|
+
while (isExecuting) await new Promise((done) => _tanstack_query_core.timeoutManager.setTimeout(done, interval));
|
|
16
|
+
while (Date.now() < nextExecutionTime) await new Promise((done) => _tanstack_query_core.timeoutManager.setTimeout(done, nextExecutionTime - Date.now()));
|
|
17
|
+
isScheduled = false;
|
|
18
|
+
isExecuting = true;
|
|
19
|
+
try {
|
|
20
|
+
await func(...lastArgs);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
try {
|
|
23
|
+
onError(error);
|
|
24
|
+
} catch {}
|
|
25
|
+
}
|
|
26
|
+
nextExecutionTime = Date.now() + interval;
|
|
27
|
+
isExecuting = false;
|
|
28
|
+
};
|
|
59
29
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.asyncThrottle = asyncThrottle;
|
|
32
|
+
|
|
64
33
|
//# sourceMappingURL=asyncThrottle.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => timeoutManager.setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n timeoutManager.setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"asyncThrottle.cjs","names":["noop","timeoutManager"],"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => timeoutManager.setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n timeoutManager.setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":";;;;AAQA,SAAgB,cACd,MACA,EAAE,WAAW,KAAM,UAAUA,cAAAA,SAA+B,CAAC,GAC7D;CACA,IAAI,OAAO,SAAS,YAAY,MAAM,IAAI,MAAM,2BAA2B;CAE3E,IAAI,oBAAoB;CACxB,IAAI,WAAW;CACf,IAAI,cAAc;CAClB,IAAI,cAAc;CAElB,OAAO,OAAO,GAAG,SAAgB;EAC/B,WAAW;EACX,IAAI,aAAa;EACjB,cAAc;EACd,OAAO,aACL,MAAM,IAAI,SAAS,SAASC,qBAAAA,eAAe,WAAW,MAAM,QAAQ,CAAC;EAEvE,OAAO,KAAK,IAAI,IAAI,mBAClB,MAAM,IAAI,SAAS,SACjBA,qBAAAA,eAAe,WAAW,MAAM,oBAAoB,KAAK,IAAI,CAAC,CAChE;EAEF,cAAc;EACd,cAAc;EACd,IAAI;GACF,MAAM,KAAK,GAAG,QAAQ;EACxB,SAAS,OAAO;GACd,IAAI;IACF,QAAQ,KAAK;GACf,QAAQ,CAAC;EACX;EACA,oBAAoB,KAAK,IAAI,IAAI;EACjC,cAAc;CAChB;AACF"}
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/asyncThrottle.d.ts
|
|
2
|
+
interface AsyncThrottleOptions {
|
|
3
|
+
interval?: number;
|
|
4
|
+
onError?: (error: unknown) => void;
|
|
5
|
+
}
|
|
6
|
+
declare function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(func: (...args: TArgs) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: TArgs) => Promise<void>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { asyncThrottle };
|
|
9
|
+
//# sourceMappingURL=asyncThrottle.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncThrottle.d.cts","names":[],"sources":["../../src/asyncThrottle.ts"],"mappings":";UAGU;EACR;EACA,WAAW;;iBAGG,cAAc,cAAc,wBAC1C,UAAU,MAAM,UAAU,iBACxB,UAAiB,YAAkB,2BASpB,MAAM,UAAK"}
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/asyncThrottle.d.ts
|
|
2
|
+
interface AsyncThrottleOptions {
|
|
3
|
+
interval?: number;
|
|
4
|
+
onError?: (error: unknown) => void;
|
|
5
|
+
}
|
|
6
|
+
declare function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(func: (...args: TArgs) => Promise<void>, { interval, onError }?: AsyncThrottleOptions): (...args: TArgs) => Promise<void>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { asyncThrottle };
|
|
9
|
+
//# sourceMappingURL=asyncThrottle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncThrottle.d.ts","names":[],"sources":["../../src/asyncThrottle.ts"],"mappings":";UAGU;EACR;EACA,WAAW;;iBAGG,cAAc,cAAc,wBAC1C,UAAU,MAAM,UAAU,iBACxB,UAAiB,YAAkB,2BASpB,MAAM,UAAK"}
|
|
@@ -1,39 +1,32 @@
|
|
|
1
|
-
// src/asyncThrottle.ts
|
|
2
|
-
import { timeoutManager } from "@tanstack/query-core";
|
|
3
1
|
import { noop } from "./utils.js";
|
|
2
|
+
import { timeoutManager } from "@tanstack/query-core";
|
|
3
|
+
//#region src/asyncThrottle.ts
|
|
4
4
|
function asyncThrottle(func, { interval = 1e3, onError = noop } = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
onError(error);
|
|
29
|
-
} catch {
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
nextExecutionTime = Date.now() + interval;
|
|
33
|
-
isExecuting = false;
|
|
34
|
-
};
|
|
5
|
+
if (typeof func !== "function") throw new Error("argument is not function.");
|
|
6
|
+
let nextExecutionTime = 0;
|
|
7
|
+
let lastArgs = null;
|
|
8
|
+
let isExecuting = false;
|
|
9
|
+
let isScheduled = false;
|
|
10
|
+
return async (...args) => {
|
|
11
|
+
lastArgs = args;
|
|
12
|
+
if (isScheduled) return;
|
|
13
|
+
isScheduled = true;
|
|
14
|
+
while (isExecuting) await new Promise((done) => timeoutManager.setTimeout(done, interval));
|
|
15
|
+
while (Date.now() < nextExecutionTime) await new Promise((done) => timeoutManager.setTimeout(done, nextExecutionTime - Date.now()));
|
|
16
|
+
isScheduled = false;
|
|
17
|
+
isExecuting = true;
|
|
18
|
+
try {
|
|
19
|
+
await func(...lastArgs);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
try {
|
|
22
|
+
onError(error);
|
|
23
|
+
} catch {}
|
|
24
|
+
}
|
|
25
|
+
nextExecutionTime = Date.now() + interval;
|
|
26
|
+
isExecuting = false;
|
|
27
|
+
};
|
|
35
28
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
//#endregion
|
|
30
|
+
export { asyncThrottle };
|
|
31
|
+
|
|
39
32
|
//# sourceMappingURL=asyncThrottle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => timeoutManager.setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n timeoutManager.setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"asyncThrottle.js","names":[],"sources":["../../src/asyncThrottle.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\n\ninterface AsyncThrottleOptions {\n interval?: number\n onError?: (error: unknown) => void\n}\n\nexport function asyncThrottle<TArgs extends ReadonlyArray<unknown>>(\n func: (...args: TArgs) => Promise<void>,\n { interval = 1000, onError = noop }: AsyncThrottleOptions = {},\n) {\n if (typeof func !== 'function') throw new Error('argument is not function.')\n\n let nextExecutionTime = 0\n let lastArgs = null\n let isExecuting = false\n let isScheduled = false\n\n return async (...args: TArgs) => {\n lastArgs = args\n if (isScheduled) return\n isScheduled = true\n while (isExecuting) {\n await new Promise((done) => timeoutManager.setTimeout(done, interval))\n }\n while (Date.now() < nextExecutionTime) {\n await new Promise((done) =>\n timeoutManager.setTimeout(done, nextExecutionTime - Date.now()),\n )\n }\n isScheduled = false\n isExecuting = true\n try {\n await func(...lastArgs)\n } catch (error) {\n try {\n onError(error)\n } catch {}\n }\n nextExecutionTime = Date.now() + interval\n isExecuting = false\n }\n}\n"],"mappings":";;;AAQA,SAAgB,cACd,MACA,EAAE,WAAW,KAAM,UAAU,SAA+B,CAAC,GAC7D;CACA,IAAI,OAAO,SAAS,YAAY,MAAM,IAAI,MAAM,2BAA2B;CAE3E,IAAI,oBAAoB;CACxB,IAAI,WAAW;CACf,IAAI,cAAc;CAClB,IAAI,cAAc;CAElB,OAAO,OAAO,GAAG,SAAgB;EAC/B,WAAW;EACX,IAAI,aAAa;EACjB,cAAc;EACd,OAAO,aACL,MAAM,IAAI,SAAS,SAAS,eAAe,WAAW,MAAM,QAAQ,CAAC;EAEvE,OAAO,KAAK,IAAI,IAAI,mBAClB,MAAM,IAAI,SAAS,SACjB,eAAe,WAAW,MAAM,oBAAoB,KAAK,IAAI,CAAC,CAChE;EAEF,cAAc;EACd,cAAc;EACd,IAAI;GACF,MAAM,KAAK,GAAG,QAAQ;EACxB,SAAS,OAAO;GACd,IAAI;IACF,QAAQ,KAAK;GACf,QAAQ,CAAC;EACX;EACA,oBAAoB,KAAK,IAAI,IAAI;EACjC,cAAc;CAChB;AACF"}
|
package/build/legacy/index.cjs
CHANGED
|
@@ -1,86 +1,48 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils = require("./utils.cjs");
|
|
3
|
+
const require_asyncThrottle = require("./asyncThrottle.cjs");
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
const createAsyncStoragePersister = ({ storage, key = `REACT_QUERY_OFFLINE_CACHE`, throttleTime = 1e3, serialize = JSON.stringify, deserialize = JSON.parse, retry }) => {
|
|
6
|
+
if (storage) {
|
|
7
|
+
const trySave = async (persistedClient) => {
|
|
8
|
+
try {
|
|
9
|
+
const serialized = await serialize(persistedClient);
|
|
10
|
+
await storage.setItem(key, serialized);
|
|
11
|
+
return;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return error;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
persistClient: require_asyncThrottle.asyncThrottle(async (persistedClient) => {
|
|
18
|
+
let client = persistedClient;
|
|
19
|
+
let error = await trySave(client);
|
|
20
|
+
let errorCount = 0;
|
|
21
|
+
while (error && client) {
|
|
22
|
+
errorCount++;
|
|
23
|
+
client = await (retry === null || retry === void 0 ? void 0 : retry({
|
|
24
|
+
persistedClient: client,
|
|
25
|
+
error,
|
|
26
|
+
errorCount
|
|
27
|
+
}));
|
|
28
|
+
if (client) error = await trySave(client);
|
|
29
|
+
}
|
|
30
|
+
}, { interval: throttleTime }),
|
|
31
|
+
restoreClient: async () => {
|
|
32
|
+
const cacheString = await storage.getItem(key);
|
|
33
|
+
if (!cacheString) return;
|
|
34
|
+
return await deserialize(cacheString);
|
|
35
|
+
},
|
|
36
|
+
removeClient: () => storage.removeItem(key)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
persistClient: require_utils.noop,
|
|
41
|
+
restoreClient: () => Promise.resolve(void 0),
|
|
42
|
+
removeClient: require_utils.noop
|
|
43
|
+
};
|
|
9
44
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.createAsyncStoragePersister = createAsyncStoragePersister;
|
|
19
47
|
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
createAsyncStoragePersister: () => createAsyncStoragePersister
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(index_exports);
|
|
26
|
-
var import_asyncThrottle = require("./asyncThrottle.cjs");
|
|
27
|
-
var import_utils = require("./utils.cjs");
|
|
28
|
-
var createAsyncStoragePersister = ({
|
|
29
|
-
storage,
|
|
30
|
-
key = `REACT_QUERY_OFFLINE_CACHE`,
|
|
31
|
-
throttleTime = 1e3,
|
|
32
|
-
serialize = JSON.stringify,
|
|
33
|
-
deserialize = JSON.parse,
|
|
34
|
-
retry
|
|
35
|
-
}) => {
|
|
36
|
-
if (storage) {
|
|
37
|
-
const trySave = async (persistedClient) => {
|
|
38
|
-
try {
|
|
39
|
-
const serialized = await serialize(persistedClient);
|
|
40
|
-
await storage.setItem(key, serialized);
|
|
41
|
-
return;
|
|
42
|
-
} catch (error) {
|
|
43
|
-
return error;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
return {
|
|
47
|
-
persistClient: (0, import_asyncThrottle.asyncThrottle)(
|
|
48
|
-
async (persistedClient) => {
|
|
49
|
-
let client = persistedClient;
|
|
50
|
-
let error = await trySave(client);
|
|
51
|
-
let errorCount = 0;
|
|
52
|
-
while (error && client) {
|
|
53
|
-
errorCount++;
|
|
54
|
-
client = await (retry == null ? void 0 : retry({
|
|
55
|
-
persistedClient: client,
|
|
56
|
-
error,
|
|
57
|
-
errorCount
|
|
58
|
-
}));
|
|
59
|
-
if (client) {
|
|
60
|
-
error = await trySave(client);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
{ interval: throttleTime }
|
|
65
|
-
),
|
|
66
|
-
restoreClient: async () => {
|
|
67
|
-
const cacheString = await storage.getItem(key);
|
|
68
|
-
if (!cacheString) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
return await deserialize(cacheString);
|
|
72
|
-
},
|
|
73
|
-
removeClient: () => storage.removeItem(key)
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
persistClient: import_utils.noop,
|
|
78
|
-
restoreClient: () => Promise.resolve(void 0),
|
|
79
|
-
removeClient: import_utils.noop
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
-
0 && (module.exports = {
|
|
84
|
-
createAsyncStoragePersister
|
|
85
|
-
});
|
|
86
48
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { asyncThrottle } from './asyncThrottle'\nimport { noop } from './utils'\nimport type {\n AsyncStorage,\n MaybePromise,\n PersistedClient,\n Persister,\n Promisable,\n} from '@tanstack/query-persist-client-core'\n\nexport type AsyncPersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => Promisable<PersistedClient | undefined>\n\ninterface CreateAsyncStoragePersisterOptions {\n /** The storage client used for setting and retrieving items from cache.\n * For SSR pass in `undefined`. Note that window.localStorage can be\n * `null` in Android WebViews depending on how they are configured.\n */\n storage: AsyncStorage<string> | undefined | null\n /** The key to use when storing the cache */\n key?: string\n /** To avoid spamming,\n * pass a time in ms to throttle saving the cache to disk */\n throttleTime?: number\n /**\n * How to serialize the data to storage.\n * @default `JSON.stringify`\n */\n serialize?: (client: PersistedClient) => MaybePromise<string>\n /**\n * How to deserialize the data from storage.\n * @default `JSON.parse`\n */\n deserialize?: (cachedString: string) => MaybePromise<PersistedClient>\n\n retry?: AsyncPersistRetryer\n}\n\nexport const createAsyncStoragePersister = ({\n storage,\n key = `REACT_QUERY_OFFLINE_CACHE`,\n throttleTime = 1000,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n retry,\n}: CreateAsyncStoragePersisterOptions): Persister => {\n if (storage) {\n const trySave = async (\n persistedClient: PersistedClient,\n ): Promise<Error | undefined> => {\n try {\n const serialized = await serialize(persistedClient)\n await storage.setItem(key, serialized)\n return\n } catch (error) {\n return error as Error\n }\n }\n\n return {\n persistClient: asyncThrottle(\n async (persistedClient) => {\n let client: PersistedClient | undefined = persistedClient\n let error = await trySave(client)\n let errorCount = 0\n while (error && client) {\n errorCount++\n client = await retry?.({\n persistedClient: client,\n error,\n errorCount,\n })\n\n if (client) {\n error = await trySave(client)\n }\n }\n },\n { interval: throttleTime },\n ),\n restoreClient: async () => {\n const cacheString = await storage.getItem(key)\n\n if (!cacheString) {\n return\n }\n\n return await deserialize(cacheString)\n },\n removeClient: () => storage.removeItem(key),\n }\n }\n\n return {\n persistClient: noop,\n restoreClient: () => Promise.resolve(undefined),\n removeClient: noop,\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["asyncThrottle","noop"],"sources":["../../src/index.ts"],"sourcesContent":["import { asyncThrottle } from './asyncThrottle'\nimport { noop } from './utils'\nimport type {\n AsyncStorage,\n MaybePromise,\n PersistedClient,\n Persister,\n Promisable,\n} from '@tanstack/query-persist-client-core'\n\nexport type AsyncPersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => Promisable<PersistedClient | undefined>\n\ninterface CreateAsyncStoragePersisterOptions {\n /** The storage client used for setting and retrieving items from cache.\n * For SSR pass in `undefined`. Note that window.localStorage can be\n * `null` in Android WebViews depending on how they are configured.\n */\n storage: AsyncStorage<string> | undefined | null\n /** The key to use when storing the cache */\n key?: string\n /** To avoid spamming,\n * pass a time in ms to throttle saving the cache to disk */\n throttleTime?: number\n /**\n * How to serialize the data to storage.\n * @default `JSON.stringify`\n */\n serialize?: (client: PersistedClient) => MaybePromise<string>\n /**\n * How to deserialize the data from storage.\n * @default `JSON.parse`\n */\n deserialize?: (cachedString: string) => MaybePromise<PersistedClient>\n\n retry?: AsyncPersistRetryer\n}\n\nexport const createAsyncStoragePersister = ({\n storage,\n key = `REACT_QUERY_OFFLINE_CACHE`,\n throttleTime = 1000,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n retry,\n}: CreateAsyncStoragePersisterOptions): Persister => {\n if (storage) {\n const trySave = async (\n persistedClient: PersistedClient,\n ): Promise<Error | undefined> => {\n try {\n const serialized = await serialize(persistedClient)\n await storage.setItem(key, serialized)\n return\n } catch (error) {\n return error as Error\n }\n }\n\n return {\n persistClient: asyncThrottle(\n async (persistedClient) => {\n let client: PersistedClient | undefined = persistedClient\n let error = await trySave(client)\n let errorCount = 0\n while (error && client) {\n errorCount++\n client = await retry?.({\n persistedClient: client,\n error,\n errorCount,\n })\n\n if (client) {\n error = await trySave(client)\n }\n }\n },\n { interval: throttleTime },\n ),\n restoreClient: async () => {\n const cacheString = await storage.getItem(key)\n\n if (!cacheString) {\n return\n }\n\n return await deserialize(cacheString)\n },\n removeClient: () => storage.removeItem(key),\n }\n }\n\n return {\n persistClient: noop,\n restoreClient: () => Promise.resolve(undefined),\n removeClient: noop,\n }\n}\n"],"mappings":";;;;AAyCA,MAAa,+BAA+B,EAC1C,SACA,MAAM,6BACN,eAAe,KACf,YAAY,KAAK,WACjB,cAAc,KAAK,OACnB,YACmD;CACnD,IAAI,SAAS;EACX,MAAM,UAAU,OACd,oBAC+B;GAC/B,IAAI;IACF,MAAM,aAAa,MAAM,UAAU,eAAe;IAClD,MAAM,QAAQ,QAAQ,KAAK,UAAU;IACrC;GACF,SAAS,OAAO;IACd,OAAO;GACT;EACF;EAEA,OAAO;GACL,eAAeA,sBAAAA,cACb,OAAO,oBAAoB;IACzB,IAAI,SAAsC;IAC1C,IAAI,QAAQ,MAAM,QAAQ,MAAM;IAChC,IAAI,aAAa;IACjB,OAAO,SAAS,QAAQ;KACtB;KACA,SAAS,OAAA,UAAA,QAAA,UAAA,KAAA,IAAA,KAAA,IAAM,MAAQ;MACrB,iBAAiB;MACjB;MACA;KACF,CAAC;KAED,IAAI,QACF,QAAQ,MAAM,QAAQ,MAAM;IAEhC;GACF,GACA,EAAE,UAAU,aAAa,CAC3B;GACA,eAAe,YAAY;IACzB,MAAM,cAAc,MAAM,QAAQ,QAAQ,GAAG;IAE7C,IAAI,CAAC,aACH;IAGF,OAAO,MAAM,YAAY,WAAW;GACtC;GACA,oBAAoB,QAAQ,WAAW,GAAG;EAC5C;CACF;CAEA,OAAO;EACL,eAAeC,cAAAA;EACf,qBAAqB,QAAQ,QAAQ,KAAA,CAAS;EAC9C,cAAcA,cAAAA;CAChB;AACF"}
|
package/build/legacy/index.d.cts
CHANGED
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { AsyncStorage, MaybePromise, PersistedClient, Persister, Promisable } from "@tanstack/query-persist-client-core";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
type AsyncPersistRetryer = (props: {
|
|
4
|
+
persistedClient: PersistedClient;
|
|
5
|
+
error: Error;
|
|
6
|
+
errorCount: number;
|
|
7
|
+
}) => Promisable<PersistedClient | undefined>;
|
|
8
|
+
interface CreateAsyncStoragePersisterOptions {
|
|
9
|
+
/** The storage client used for setting and retrieving items from cache.
|
|
10
|
+
* For SSR pass in `undefined`. Note that window.localStorage can be
|
|
11
|
+
* `null` in Android WebViews depending on how they are configured.
|
|
12
|
+
*/
|
|
13
|
+
storage: AsyncStorage<string> | undefined | null;
|
|
14
|
+
/** The key to use when storing the cache */
|
|
15
|
+
key?: string;
|
|
16
|
+
/** To avoid spamming,
|
|
17
|
+
* pass a time in ms to throttle saving the cache to disk */
|
|
18
|
+
throttleTime?: number;
|
|
19
|
+
/**
|
|
20
|
+
* How to serialize the data to storage.
|
|
21
|
+
* @default `JSON.stringify`
|
|
22
|
+
*/
|
|
23
|
+
serialize?: (client: PersistedClient) => MaybePromise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* How to deserialize the data from storage.
|
|
26
|
+
* @default `JSON.parse`
|
|
27
|
+
*/
|
|
28
|
+
deserialize?: (cachedString: string) => MaybePromise<PersistedClient>;
|
|
29
|
+
retry?: AsyncPersistRetryer;
|
|
30
|
+
}
|
|
31
|
+
declare const createAsyncStoragePersister: ({ storage, key, throttleTime, serialize, deserialize, retry }: CreateAsyncStoragePersisterOptions) => Persister;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { AsyncPersistRetryer, createAsyncStoragePersister };
|
|
34
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/index.ts"],"mappings":";;KAUY,uBAAuB;EACjC,iBAAiB;EACjB,OAAO;EACP;MACI,WAAW;UAEP;;;;;EAKR,SAAS;;EAET;;;EAGA;;;;;EAKA,aAAa,QAAQ,oBAAoB;;;;;EAKzC,eAAe,yBAAyB,aAAa;EAErD,QAAQ;;cAGG,gCAA+B,SAAA,KAAA,cAAA,WAAA,aAAA,SAOzC,uCAAqC"}
|
package/build/legacy/index.d.ts
CHANGED
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { AsyncStorage, MaybePromise, PersistedClient, Persister, Promisable } from "@tanstack/query-persist-client-core";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
type AsyncPersistRetryer = (props: {
|
|
4
|
+
persistedClient: PersistedClient;
|
|
5
|
+
error: Error;
|
|
6
|
+
errorCount: number;
|
|
7
|
+
}) => Promisable<PersistedClient | undefined>;
|
|
8
|
+
interface CreateAsyncStoragePersisterOptions {
|
|
9
|
+
/** The storage client used for setting and retrieving items from cache.
|
|
10
|
+
* For SSR pass in `undefined`. Note that window.localStorage can be
|
|
11
|
+
* `null` in Android WebViews depending on how they are configured.
|
|
12
|
+
*/
|
|
13
|
+
storage: AsyncStorage<string> | undefined | null;
|
|
14
|
+
/** The key to use when storing the cache */
|
|
15
|
+
key?: string;
|
|
16
|
+
/** To avoid spamming,
|
|
17
|
+
* pass a time in ms to throttle saving the cache to disk */
|
|
18
|
+
throttleTime?: number;
|
|
19
|
+
/**
|
|
20
|
+
* How to serialize the data to storage.
|
|
21
|
+
* @default `JSON.stringify`
|
|
22
|
+
*/
|
|
23
|
+
serialize?: (client: PersistedClient) => MaybePromise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* How to deserialize the data from storage.
|
|
26
|
+
* @default `JSON.parse`
|
|
27
|
+
*/
|
|
28
|
+
deserialize?: (cachedString: string) => MaybePromise<PersistedClient>;
|
|
29
|
+
retry?: AsyncPersistRetryer;
|
|
30
|
+
}
|
|
31
|
+
declare const createAsyncStoragePersister: ({ storage, key, throttleTime, serialize, deserialize, retry }: CreateAsyncStoragePersisterOptions) => Persister;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { AsyncPersistRetryer, createAsyncStoragePersister };
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;KAUY,uBAAuB;EACjC,iBAAiB;EACjB,OAAO;EACP;MACI,WAAW;UAEP;;;;;EAKR,SAAS;;EAET;;;EAGA;;;;;EAKA,aAAa,QAAQ,oBAAoB;;;;;EAKzC,eAAe,yBAAyB,aAAa;EAErD,QAAQ;;cAGG,gCAA+B,SAAA,KAAA,cAAA,WAAA,aAAA,SAOzC,uCAAqC"}
|
package/build/legacy/index.js
CHANGED
|
@@ -1,61 +1,47 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import { asyncThrottle } from "./asyncThrottle.js";
|
|
3
1
|
import { noop } from "./utils.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
return await deserialize(cacheString);
|
|
48
|
-
},
|
|
49
|
-
removeClient: () => storage.removeItem(key)
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
persistClient: noop,
|
|
54
|
-
restoreClient: () => Promise.resolve(void 0),
|
|
55
|
-
removeClient: noop
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
export {
|
|
59
|
-
createAsyncStoragePersister
|
|
2
|
+
import { asyncThrottle } from "./asyncThrottle.js";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const createAsyncStoragePersister = ({ storage, key = `REACT_QUERY_OFFLINE_CACHE`, throttleTime = 1e3, serialize = JSON.stringify, deserialize = JSON.parse, retry }) => {
|
|
5
|
+
if (storage) {
|
|
6
|
+
const trySave = async (persistedClient) => {
|
|
7
|
+
try {
|
|
8
|
+
const serialized = await serialize(persistedClient);
|
|
9
|
+
await storage.setItem(key, serialized);
|
|
10
|
+
return;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
return error;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
persistClient: asyncThrottle(async (persistedClient) => {
|
|
17
|
+
let client = persistedClient;
|
|
18
|
+
let error = await trySave(client);
|
|
19
|
+
let errorCount = 0;
|
|
20
|
+
while (error && client) {
|
|
21
|
+
errorCount++;
|
|
22
|
+
client = await (retry === null || retry === void 0 ? void 0 : retry({
|
|
23
|
+
persistedClient: client,
|
|
24
|
+
error,
|
|
25
|
+
errorCount
|
|
26
|
+
}));
|
|
27
|
+
if (client) error = await trySave(client);
|
|
28
|
+
}
|
|
29
|
+
}, { interval: throttleTime }),
|
|
30
|
+
restoreClient: async () => {
|
|
31
|
+
const cacheString = await storage.getItem(key);
|
|
32
|
+
if (!cacheString) return;
|
|
33
|
+
return await deserialize(cacheString);
|
|
34
|
+
},
|
|
35
|
+
removeClient: () => storage.removeItem(key)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
persistClient: noop,
|
|
40
|
+
restoreClient: () => Promise.resolve(void 0),
|
|
41
|
+
removeClient: noop
|
|
42
|
+
};
|
|
60
43
|
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { createAsyncStoragePersister };
|
|
46
|
+
|
|
61
47
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { asyncThrottle } from './asyncThrottle'\nimport { noop } from './utils'\nimport type {\n AsyncStorage,\n MaybePromise,\n PersistedClient,\n Persister,\n Promisable,\n} from '@tanstack/query-persist-client-core'\n\nexport type AsyncPersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => Promisable<PersistedClient | undefined>\n\ninterface CreateAsyncStoragePersisterOptions {\n /** The storage client used for setting and retrieving items from cache.\n * For SSR pass in `undefined`. Note that window.localStorage can be\n * `null` in Android WebViews depending on how they are configured.\n */\n storage: AsyncStorage<string> | undefined | null\n /** The key to use when storing the cache */\n key?: string\n /** To avoid spamming,\n * pass a time in ms to throttle saving the cache to disk */\n throttleTime?: number\n /**\n * How to serialize the data to storage.\n * @default `JSON.stringify`\n */\n serialize?: (client: PersistedClient) => MaybePromise<string>\n /**\n * How to deserialize the data from storage.\n * @default `JSON.parse`\n */\n deserialize?: (cachedString: string) => MaybePromise<PersistedClient>\n\n retry?: AsyncPersistRetryer\n}\n\nexport const createAsyncStoragePersister = ({\n storage,\n key = `REACT_QUERY_OFFLINE_CACHE`,\n throttleTime = 1000,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n retry,\n}: CreateAsyncStoragePersisterOptions): Persister => {\n if (storage) {\n const trySave = async (\n persistedClient: PersistedClient,\n ): Promise<Error | undefined> => {\n try {\n const serialized = await serialize(persistedClient)\n await storage.setItem(key, serialized)\n return\n } catch (error) {\n return error as Error\n }\n }\n\n return {\n persistClient: asyncThrottle(\n async (persistedClient) => {\n let client: PersistedClient | undefined = persistedClient\n let error = await trySave(client)\n let errorCount = 0\n while (error && client) {\n errorCount++\n client = await retry?.({\n persistedClient: client,\n error,\n errorCount,\n })\n\n if (client) {\n error = await trySave(client)\n }\n }\n },\n { interval: throttleTime },\n ),\n restoreClient: async () => {\n const cacheString = await storage.getItem(key)\n\n if (!cacheString) {\n return\n }\n\n return await deserialize(cacheString)\n },\n removeClient: () => storage.removeItem(key),\n }\n }\n\n return {\n persistClient: noop,\n restoreClient: () => Promise.resolve(undefined),\n removeClient: noop,\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { asyncThrottle } from './asyncThrottle'\nimport { noop } from './utils'\nimport type {\n AsyncStorage,\n MaybePromise,\n PersistedClient,\n Persister,\n Promisable,\n} from '@tanstack/query-persist-client-core'\n\nexport type AsyncPersistRetryer = (props: {\n persistedClient: PersistedClient\n error: Error\n errorCount: number\n}) => Promisable<PersistedClient | undefined>\n\ninterface CreateAsyncStoragePersisterOptions {\n /** The storage client used for setting and retrieving items from cache.\n * For SSR pass in `undefined`. Note that window.localStorage can be\n * `null` in Android WebViews depending on how they are configured.\n */\n storage: AsyncStorage<string> | undefined | null\n /** The key to use when storing the cache */\n key?: string\n /** To avoid spamming,\n * pass a time in ms to throttle saving the cache to disk */\n throttleTime?: number\n /**\n * How to serialize the data to storage.\n * @default `JSON.stringify`\n */\n serialize?: (client: PersistedClient) => MaybePromise<string>\n /**\n * How to deserialize the data from storage.\n * @default `JSON.parse`\n */\n deserialize?: (cachedString: string) => MaybePromise<PersistedClient>\n\n retry?: AsyncPersistRetryer\n}\n\nexport const createAsyncStoragePersister = ({\n storage,\n key = `REACT_QUERY_OFFLINE_CACHE`,\n throttleTime = 1000,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n retry,\n}: CreateAsyncStoragePersisterOptions): Persister => {\n if (storage) {\n const trySave = async (\n persistedClient: PersistedClient,\n ): Promise<Error | undefined> => {\n try {\n const serialized = await serialize(persistedClient)\n await storage.setItem(key, serialized)\n return\n } catch (error) {\n return error as Error\n }\n }\n\n return {\n persistClient: asyncThrottle(\n async (persistedClient) => {\n let client: PersistedClient | undefined = persistedClient\n let error = await trySave(client)\n let errorCount = 0\n while (error && client) {\n errorCount++\n client = await retry?.({\n persistedClient: client,\n error,\n errorCount,\n })\n\n if (client) {\n error = await trySave(client)\n }\n }\n },\n { interval: throttleTime },\n ),\n restoreClient: async () => {\n const cacheString = await storage.getItem(key)\n\n if (!cacheString) {\n return\n }\n\n return await deserialize(cacheString)\n },\n removeClient: () => storage.removeItem(key),\n }\n }\n\n return {\n persistClient: noop,\n restoreClient: () => Promise.resolve(undefined),\n removeClient: noop,\n }\n}\n"],"mappings":";;;AAyCA,MAAa,+BAA+B,EAC1C,SACA,MAAM,6BACN,eAAe,KACf,YAAY,KAAK,WACjB,cAAc,KAAK,OACnB,YACmD;CACnD,IAAI,SAAS;EACX,MAAM,UAAU,OACd,oBAC+B;GAC/B,IAAI;IACF,MAAM,aAAa,MAAM,UAAU,eAAe;IAClD,MAAM,QAAQ,QAAQ,KAAK,UAAU;IACrC;GACF,SAAS,OAAO;IACd,OAAO;GACT;EACF;EAEA,OAAO;GACL,eAAe,cACb,OAAO,oBAAoB;IACzB,IAAI,SAAsC;IAC1C,IAAI,QAAQ,MAAM,QAAQ,MAAM;IAChC,IAAI,aAAa;IACjB,OAAO,SAAS,QAAQ;KACtB;KACA,SAAS,OAAA,UAAA,QAAA,UAAA,KAAA,IAAA,KAAA,IAAM,MAAQ;MACrB,iBAAiB;MACjB;MACA;KACF,CAAC;KAED,IAAI,QACF,QAAQ,MAAM,QAAQ,MAAM;IAEhC;GACF,GACA,EAAE,UAAU,aAAa,CAC3B;GACA,eAAe,YAAY;IACzB,MAAM,cAAc,MAAM,QAAQ,QAAQ,GAAG;IAE7C,IAAI,CAAC,aACH;IAGF,OAAO,MAAM,YAAY,WAAW;GACtC;GACA,oBAAoB,QAAQ,WAAW,GAAG;EAC5C;CACF;CAEA,OAAO;EACL,eAAe;EACf,qBAAqB,QAAQ,QAAQ,KAAA,CAAS;EAC9C,cAAc;CAChB;AACF"}
|
package/build/legacy/utils.cjs
CHANGED
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
function noop() {}
|
|
4
|
+
//#endregion
|
|
5
|
+
exports.noop = noop;
|
|
19
6
|
|
|
20
|
-
// src/utils.ts
|
|
21
|
-
var utils_exports = {};
|
|
22
|
-
__export(utils_exports, {
|
|
23
|
-
noop: () => noop
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(utils_exports);
|
|
26
|
-
function noop() {
|
|
27
|
-
}
|
|
28
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
-
0 && (module.exports = {
|
|
30
|
-
noop
|
|
31
|
-
});
|
|
32
7
|
//# sourceMappingURL=utils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["export function noop(): void\nexport function noop(): undefined\nexport function noop() {}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["export function noop(): void\nexport function noop(): undefined\nexport function noop() {}\n"],"mappings":";;AAEA,SAAgB,OAAO,CAAC"}
|