@tanstack/query-sync-storage-persister 5.104.1 → 5.104.3
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/index.cjs +13 -0
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +12 -3
- package/build/legacy/index.d.cts.map +1 -1
- package/build/legacy/index.d.ts +12 -3
- package/build/legacy/index.d.ts.map +1 -1
- package/build/legacy/index.js +13 -0
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +3 -0
- package/build/legacy/utils.d.cts.map +1 -1
- package/build/legacy/utils.d.ts +3 -0
- package/build/legacy/utils.d.ts.map +1 -1
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/index.cjs +13 -0
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +12 -3
- package/build/modern/index.d.cts.map +1 -1
- package/build/modern/index.d.ts +12 -3
- package/build/modern/index.d.ts.map +1 -1
- package/build/modern/index.js +13 -0
- package/build/modern/index.js.map +1 -1
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +3 -0
- package/build/modern/utils.d.cts.map +1 -1
- package/build/modern/utils.d.ts +3 -0
- package/build/modern/utils.d.ts.map +1 -1
- package/build/modern/utils.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +19 -3
- package/src/utils.ts +3 -0
package/build/legacy/index.cjs
CHANGED
|
@@ -3,6 +3,12 @@ const require_utils = require("./utils.cjs");
|
|
|
3
3
|
let _tanstack_query_core = require("@tanstack/query-core");
|
|
4
4
|
//#region src/index.ts
|
|
5
5
|
/**
|
|
6
|
+
* Creates a persister that stores the client in a synchronous storage such as
|
|
7
|
+
* `window.localStorage`.
|
|
8
|
+
* @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,
|
|
9
|
+
* `deserialize`, and `retry` options.
|
|
10
|
+
* @returns A persister that saves, restores, and removes the client in `storage`. Without
|
|
11
|
+
* `storage`, its methods do nothing.
|
|
6
12
|
* @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.
|
|
7
13
|
*/
|
|
8
14
|
function createSyncStoragePersister({ storage, key = `REACT_QUERY_OFFLINE_CACHE`, throttleTime = 1e3, serialize = JSON.stringify, deserialize = JSON.parse, retry }) {
|
|
@@ -46,6 +52,13 @@ function createSyncStoragePersister({ storage, key = `REACT_QUERY_OFFLINE_CACHE`
|
|
|
46
52
|
removeClient: require_utils.noop
|
|
47
53
|
};
|
|
48
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Wraps a function so it runs at most once per `wait` milliseconds, with the arguments of the latest
|
|
57
|
+
* call.
|
|
58
|
+
* @param func - The function to throttle.
|
|
59
|
+
* @param wait - The time to wait before running `func`, in milliseconds.
|
|
60
|
+
* @returns The throttled function.
|
|
61
|
+
*/
|
|
49
62
|
function throttle(func, wait = 100) {
|
|
50
63
|
let timer = null;
|
|
51
64
|
let params;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["noop","timeoutManager"],"sources":["../../src/index.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\nimport type { ManagedTimerId } from '@tanstack/query-core'\nimport type {\n PersistRetryer,\n PersistedClient,\n Persister,\n} from '@tanstack/query-persist-client-core'\n\ninterface Storage {\n getItem: (key: string) => string | null\n setItem: (key: string, value: string) => void\n removeItem: (key: string) => void\n}\n\ninterface CreateSyncStoragePersisterOptions {\n
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["noop","timeoutManager"],"sources":["../../src/index.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\nimport type { ManagedTimerId } from '@tanstack/query-core'\nimport type {\n PersistRetryer,\n PersistedClient,\n Persister,\n} from '@tanstack/query-persist-client-core'\n\ninterface Storage {\n getItem: (key: string) => string | null\n setItem: (key: string, value: string) => void\n removeItem: (key: string) => void\n}\n\ninterface CreateSyncStoragePersisterOptions {\n /**\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: Storage | undefined | null\n /** The key to use when storing the cache */\n key?: string\n /**\n * To avoid spamming,\n * pass a time in ms to throttle saving the cache to disk\n */\n throttleTime?: number\n /**\n * How to serialize the data to storage.\n * @default `JSON.stringify`\n */\n serialize?: (client: PersistedClient) => string\n /**\n * How to deserialize the data from storage.\n * @default `JSON.parse`\n */\n deserialize?: (cachedString: string) => PersistedClient\n\n retry?: PersistRetryer\n}\n\n/**\n * Creates a persister that stores the client in a synchronous storage such as\n * `window.localStorage`.\n * @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,\n * `deserialize`, and `retry` options.\n * @returns A persister that saves, restores, and removes the client in `storage`. Without\n * `storage`, its methods do nothing.\n * @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.\n */\nexport function createSyncStoragePersister({\n storage,\n key = `REACT_QUERY_OFFLINE_CACHE`,\n throttleTime = 1000,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n retry,\n}: CreateSyncStoragePersisterOptions): Persister {\n if (storage) {\n const trySave = (persistedClient: PersistedClient): Error | undefined => {\n try {\n storage.setItem(key, serialize(persistedClient))\n return\n } catch (error) {\n return error as Error\n }\n }\n return {\n persistClient: throttle((persistedClient) => {\n let client: PersistedClient | undefined = persistedClient\n let error = trySave(client)\n let errorCount = 0\n while (error && client) {\n errorCount++\n client = retry?.({\n persistedClient: client,\n error,\n errorCount,\n })\n\n if (client) {\n error = trySave(client)\n }\n }\n }, throttleTime),\n restoreClient: () => {\n const cacheString = storage.getItem(key)\n\n if (!cacheString) {\n return\n }\n\n return deserialize(cacheString)\n },\n removeClient: () => {\n storage.removeItem(key)\n },\n }\n }\n\n return {\n persistClient: noop,\n restoreClient: noop,\n removeClient: noop,\n }\n}\n\n/**\n * Wraps a function so it runs at most once per `wait` milliseconds, with the arguments of the latest\n * call.\n * @param func - The function to throttle.\n * @param wait - The time to wait before running `func`, in milliseconds.\n * @returns The throttled function.\n */\nfunction throttle<TArgs extends Array<any>>(\n func: (...args: TArgs) => any,\n wait = 100,\n) {\n let timer: ManagedTimerId | null = null\n let params: TArgs\n return function (...args: TArgs) {\n params = args\n if (timer === null) {\n timer = timeoutManager.setTimeout(() => {\n func(...params)\n timer = null\n }, wait)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAoDA,SAAgB,2BAA2B,EACzC,SACA,MAAM,6BACN,eAAe,KACf,YAAY,KAAK,WACjB,cAAc,KAAK,OACnB,SAC+C;CAC/C,IAAI,SAAS;EACX,MAAM,WAAW,oBAAwD;GACvE,IAAI;IACF,QAAQ,QAAQ,KAAK,UAAU,eAAe,CAAC;IAC/C;GACF,SAAS,OAAO;IACd,OAAO;GACT;EACF;EACA,OAAO;GACL,eAAe,UAAU,oBAAoB;IAC3C,IAAI,SAAsC;IAC1C,IAAI,QAAQ,QAAQ,MAAM;IAC1B,IAAI,aAAa;IACjB,OAAO,SAAS,QAAQ;KACtB;KACA,SAAA,UAAA,QAAA,UAAA,KAAA,IAAA,KAAA,IAAS,MAAQ;MACf,iBAAiB;MACjB;MACA;KACF,CAAC;KAED,IAAI,QACF,QAAQ,QAAQ,MAAM;IAE1B;GACF,GAAG,YAAY;GACf,qBAAqB;IACnB,MAAM,cAAc,QAAQ,QAAQ,GAAG;IAEvC,IAAI,CAAC,aACH;IAGF,OAAO,YAAY,WAAW;GAChC;GACA,oBAAoB;IAClB,QAAQ,WAAW,GAAG;GACxB;EACF;CACF;CAEA,OAAO;EACL,eAAeA,cAAAA;EACf,eAAeA,cAAAA;EACf,cAAcA,cAAAA;CAChB;AACF;;;;;;;;AASA,SAAS,SACP,MACA,OAAO,KACP;CACA,IAAI,QAA+B;CACnC,IAAI;CACJ,OAAO,SAAU,GAAG,MAAa;EAC/B,SAAS;EACT,IAAI,UAAU,MACZ,QAAQC,qBAAAA,eAAe,iBAAiB;GACtC,KAAK,GAAG,MAAM;GACd,QAAQ;EACV,GAAG,IAAI;CAEX;AACF"}
|
package/build/legacy/index.d.cts
CHANGED
|
@@ -6,15 +6,18 @@ interface Storage {
|
|
|
6
6
|
removeItem: (key: string) => void;
|
|
7
7
|
}
|
|
8
8
|
interface CreateSyncStoragePersisterOptions {
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The storage client used for setting and retrieving items from cache.
|
|
10
11
|
* For SSR pass in `undefined`. Note that window.localStorage can be
|
|
11
12
|
* `null` in Android WebViews depending on how they are configured.
|
|
12
13
|
*/
|
|
13
14
|
storage: Storage | undefined | null;
|
|
14
15
|
/** The key to use when storing the cache */
|
|
15
16
|
key?: string;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
17
|
+
/**
|
|
18
|
+
* To avoid spamming,
|
|
19
|
+
* pass a time in ms to throttle saving the cache to disk
|
|
20
|
+
*/
|
|
18
21
|
throttleTime?: number;
|
|
19
22
|
/**
|
|
20
23
|
* How to serialize the data to storage.
|
|
@@ -29,6 +32,12 @@ interface CreateSyncStoragePersisterOptions {
|
|
|
29
32
|
retry?: PersistRetryer;
|
|
30
33
|
}
|
|
31
34
|
/**
|
|
35
|
+
* Creates a persister that stores the client in a synchronous storage such as
|
|
36
|
+
* `window.localStorage`.
|
|
37
|
+
* @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,
|
|
38
|
+
* `deserialize`, and `retry` options.
|
|
39
|
+
* @returns A persister that saves, restores, and removes the client in `storage`. Without
|
|
40
|
+
* `storage`, its methods do nothing.
|
|
32
41
|
* @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.
|
|
33
42
|
*/
|
|
34
43
|
export declare function createSyncStoragePersister({ storage, key, throttleTime, serialize, deserialize, retry }: CreateSyncStoragePersisterOptions): Persister;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/index.ts"],"mappings":";;UASU;EACR,UAAU;EACV,UAAU,aAAa;EACvB,aAAa;;UAGL
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/index.ts"],"mappings":";;UASU;EACR,UAAU;EACV,UAAU,aAAa;EACvB,aAAa;;UAGL;;;;;;EAMR,SAAS;;EAET;;;;;EAKA;;;;;EAKA,aAAa,QAAQ;;;;;EAKrB,eAAe,yBAAyB;EAExC,QAAQ;;;;;;;;;;;wBAYM,6BACd,SACA,KACA,cACA,WACA,aACA,SACC,oCAAoC"}
|
package/build/legacy/index.d.ts
CHANGED
|
@@ -6,15 +6,18 @@ interface Storage {
|
|
|
6
6
|
removeItem: (key: string) => void;
|
|
7
7
|
}
|
|
8
8
|
interface CreateSyncStoragePersisterOptions {
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The storage client used for setting and retrieving items from cache.
|
|
10
11
|
* For SSR pass in `undefined`. Note that window.localStorage can be
|
|
11
12
|
* `null` in Android WebViews depending on how they are configured.
|
|
12
13
|
*/
|
|
13
14
|
storage: Storage | undefined | null;
|
|
14
15
|
/** The key to use when storing the cache */
|
|
15
16
|
key?: string;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
17
|
+
/**
|
|
18
|
+
* To avoid spamming,
|
|
19
|
+
* pass a time in ms to throttle saving the cache to disk
|
|
20
|
+
*/
|
|
18
21
|
throttleTime?: number;
|
|
19
22
|
/**
|
|
20
23
|
* How to serialize the data to storage.
|
|
@@ -29,6 +32,12 @@ interface CreateSyncStoragePersisterOptions {
|
|
|
29
32
|
retry?: PersistRetryer;
|
|
30
33
|
}
|
|
31
34
|
/**
|
|
35
|
+
* Creates a persister that stores the client in a synchronous storage such as
|
|
36
|
+
* `window.localStorage`.
|
|
37
|
+
* @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,
|
|
38
|
+
* `deserialize`, and `retry` options.
|
|
39
|
+
* @returns A persister that saves, restores, and removes the client in `storage`. Without
|
|
40
|
+
* `storage`, its methods do nothing.
|
|
32
41
|
* @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.
|
|
33
42
|
*/
|
|
34
43
|
export declare function createSyncStoragePersister({ storage, key, throttleTime, serialize, deserialize, retry }: CreateSyncStoragePersisterOptions): Persister;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;UASU;EACR,UAAU;EACV,UAAU,aAAa;EACvB,aAAa;;UAGL
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;UASU;EACR,UAAU;EACV,UAAU,aAAa;EACvB,aAAa;;UAGL;;;;;;EAMR,SAAS;;EAET;;;;;EAKA;;;;;EAKA,aAAa,QAAQ;;;;;EAKrB,eAAe,yBAAyB;EAExC,QAAQ;;;;;;;;;;;wBAYM,6BACd,SACA,KACA,cACA,WACA,aACA,SACC,oCAAoC"}
|
package/build/legacy/index.js
CHANGED
|
@@ -2,6 +2,12 @@ import { noop } from "./utils.js";
|
|
|
2
2
|
import { timeoutManager } from "@tanstack/query-core";
|
|
3
3
|
//#region src/index.ts
|
|
4
4
|
/**
|
|
5
|
+
* Creates a persister that stores the client in a synchronous storage such as
|
|
6
|
+
* `window.localStorage`.
|
|
7
|
+
* @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,
|
|
8
|
+
* `deserialize`, and `retry` options.
|
|
9
|
+
* @returns A persister that saves, restores, and removes the client in `storage`. Without
|
|
10
|
+
* `storage`, its methods do nothing.
|
|
5
11
|
* @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.
|
|
6
12
|
*/
|
|
7
13
|
function createSyncStoragePersister({ storage, key = `REACT_QUERY_OFFLINE_CACHE`, throttleTime = 1e3, serialize = JSON.stringify, deserialize = JSON.parse, retry }) {
|
|
@@ -45,6 +51,13 @@ function createSyncStoragePersister({ storage, key = `REACT_QUERY_OFFLINE_CACHE`
|
|
|
45
51
|
removeClient: noop
|
|
46
52
|
};
|
|
47
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Wraps a function so it runs at most once per `wait` milliseconds, with the arguments of the latest
|
|
56
|
+
* call.
|
|
57
|
+
* @param func - The function to throttle.
|
|
58
|
+
* @param wait - The time to wait before running `func`, in milliseconds.
|
|
59
|
+
* @returns The throttled function.
|
|
60
|
+
*/
|
|
48
61
|
function throttle(func, wait = 100) {
|
|
49
62
|
let timer = null;
|
|
50
63
|
let params;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\nimport type { ManagedTimerId } from '@tanstack/query-core'\nimport type {\n PersistRetryer,\n PersistedClient,\n Persister,\n} from '@tanstack/query-persist-client-core'\n\ninterface Storage {\n getItem: (key: string) => string | null\n setItem: (key: string, value: string) => void\n removeItem: (key: string) => void\n}\n\ninterface CreateSyncStoragePersisterOptions {\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\nimport type { ManagedTimerId } from '@tanstack/query-core'\nimport type {\n PersistRetryer,\n PersistedClient,\n Persister,\n} from '@tanstack/query-persist-client-core'\n\ninterface Storage {\n getItem: (key: string) => string | null\n setItem: (key: string, value: string) => void\n removeItem: (key: string) => void\n}\n\ninterface CreateSyncStoragePersisterOptions {\n /**\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: Storage | undefined | null\n /** The key to use when storing the cache */\n key?: string\n /**\n * To avoid spamming,\n * pass a time in ms to throttle saving the cache to disk\n */\n throttleTime?: number\n /**\n * How to serialize the data to storage.\n * @default `JSON.stringify`\n */\n serialize?: (client: PersistedClient) => string\n /**\n * How to deserialize the data from storage.\n * @default `JSON.parse`\n */\n deserialize?: (cachedString: string) => PersistedClient\n\n retry?: PersistRetryer\n}\n\n/**\n * Creates a persister that stores the client in a synchronous storage such as\n * `window.localStorage`.\n * @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,\n * `deserialize`, and `retry` options.\n * @returns A persister that saves, restores, and removes the client in `storage`. Without\n * `storage`, its methods do nothing.\n * @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.\n */\nexport function createSyncStoragePersister({\n storage,\n key = `REACT_QUERY_OFFLINE_CACHE`,\n throttleTime = 1000,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n retry,\n}: CreateSyncStoragePersisterOptions): Persister {\n if (storage) {\n const trySave = (persistedClient: PersistedClient): Error | undefined => {\n try {\n storage.setItem(key, serialize(persistedClient))\n return\n } catch (error) {\n return error as Error\n }\n }\n return {\n persistClient: throttle((persistedClient) => {\n let client: PersistedClient | undefined = persistedClient\n let error = trySave(client)\n let errorCount = 0\n while (error && client) {\n errorCount++\n client = retry?.({\n persistedClient: client,\n error,\n errorCount,\n })\n\n if (client) {\n error = trySave(client)\n }\n }\n }, throttleTime),\n restoreClient: () => {\n const cacheString = storage.getItem(key)\n\n if (!cacheString) {\n return\n }\n\n return deserialize(cacheString)\n },\n removeClient: () => {\n storage.removeItem(key)\n },\n }\n }\n\n return {\n persistClient: noop,\n restoreClient: noop,\n removeClient: noop,\n }\n}\n\n/**\n * Wraps a function so it runs at most once per `wait` milliseconds, with the arguments of the latest\n * call.\n * @param func - The function to throttle.\n * @param wait - The time to wait before running `func`, in milliseconds.\n * @returns The throttled function.\n */\nfunction throttle<TArgs extends Array<any>>(\n func: (...args: TArgs) => any,\n wait = 100,\n) {\n let timer: ManagedTimerId | null = null\n let params: TArgs\n return function (...args: TArgs) {\n params = args\n if (timer === null) {\n timer = timeoutManager.setTimeout(() => {\n func(...params)\n timer = null\n }, wait)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAoDA,SAAgB,2BAA2B,EACzC,SACA,MAAM,6BACN,eAAe,KACf,YAAY,KAAK,WACjB,cAAc,KAAK,OACnB,SAC+C;CAC/C,IAAI,SAAS;EACX,MAAM,WAAW,oBAAwD;GACvE,IAAI;IACF,QAAQ,QAAQ,KAAK,UAAU,eAAe,CAAC;IAC/C;GACF,SAAS,OAAO;IACd,OAAO;GACT;EACF;EACA,OAAO;GACL,eAAe,UAAU,oBAAoB;IAC3C,IAAI,SAAsC;IAC1C,IAAI,QAAQ,QAAQ,MAAM;IAC1B,IAAI,aAAa;IACjB,OAAO,SAAS,QAAQ;KACtB;KACA,SAAA,UAAA,QAAA,UAAA,KAAA,IAAA,KAAA,IAAS,MAAQ;MACf,iBAAiB;MACjB;MACA;KACF,CAAC;KAED,IAAI,QACF,QAAQ,QAAQ,MAAM;IAE1B;GACF,GAAG,YAAY;GACf,qBAAqB;IACnB,MAAM,cAAc,QAAQ,QAAQ,GAAG;IAEvC,IAAI,CAAC,aACH;IAGF,OAAO,YAAY,WAAW;GAChC;GACA,oBAAoB;IAClB,QAAQ,WAAW,GAAG;GACxB;EACF;CACF;CAEA,OAAO;EACL,eAAe;EACf,eAAe;EACf,cAAc;CAChB;AACF;;;;;;;;AASA,SAAS,SACP,MACA,OAAO,KACP;CACA,IAAI,QAA+B;CACnC,IAAI;CACJ,OAAO,SAAU,GAAG,MAAa;EAC/B,SAAS;EACT,IAAI,UAAU,MACZ,QAAQ,eAAe,iBAAiB;GACtC,KAAK,GAAG,MAAM;GACd,QAAQ;EACV,GAAG,IAAI;CAEX;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * A function that does nothing.\n */\nexport function noop(): void\nexport function noop(): undefined\nexport function noop() {}\n"],"mappings":";;AAKA,SAAgB,OAAO,CAAC"}
|
package/build/legacy/utils.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","names":[],"sources":["../../src/utils.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"utils.d.cts","names":[],"sources":["../../src/utils.ts"],"mappings":";;;;wBAGgB;wBACA"}
|
package/build/legacy/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/utils.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/utils.ts"],"mappings":";;;;wBAGgB;wBACA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * A function that does nothing.\n */\nexport function noop(): void\nexport function noop(): undefined\nexport function noop() {}\n"],"mappings":";AAKA,SAAgB,OAAO,CAAC"}
|
package/build/modern/index.cjs
CHANGED
|
@@ -3,6 +3,12 @@ const require_utils = require("./utils.cjs");
|
|
|
3
3
|
let _tanstack_query_core = require("@tanstack/query-core");
|
|
4
4
|
//#region src/index.ts
|
|
5
5
|
/**
|
|
6
|
+
* Creates a persister that stores the client in a synchronous storage such as
|
|
7
|
+
* `window.localStorage`.
|
|
8
|
+
* @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,
|
|
9
|
+
* `deserialize`, and `retry` options.
|
|
10
|
+
* @returns A persister that saves, restores, and removes the client in `storage`. Without
|
|
11
|
+
* `storage`, its methods do nothing.
|
|
6
12
|
* @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.
|
|
7
13
|
*/
|
|
8
14
|
function createSyncStoragePersister({ storage, key = `REACT_QUERY_OFFLINE_CACHE`, throttleTime = 1e3, serialize = JSON.stringify, deserialize = JSON.parse, retry }) {
|
|
@@ -46,6 +52,13 @@ function createSyncStoragePersister({ storage, key = `REACT_QUERY_OFFLINE_CACHE`
|
|
|
46
52
|
removeClient: require_utils.noop
|
|
47
53
|
};
|
|
48
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Wraps a function so it runs at most once per `wait` milliseconds, with the arguments of the latest
|
|
57
|
+
* call.
|
|
58
|
+
* @param func - The function to throttle.
|
|
59
|
+
* @param wait - The time to wait before running `func`, in milliseconds.
|
|
60
|
+
* @returns The throttled function.
|
|
61
|
+
*/
|
|
49
62
|
function throttle(func, wait = 100) {
|
|
50
63
|
let timer = null;
|
|
51
64
|
let params;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["noop","timeoutManager"],"sources":["../../src/index.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\nimport type { ManagedTimerId } from '@tanstack/query-core'\nimport type {\n PersistRetryer,\n PersistedClient,\n Persister,\n} from '@tanstack/query-persist-client-core'\n\ninterface Storage {\n getItem: (key: string) => string | null\n setItem: (key: string, value: string) => void\n removeItem: (key: string) => void\n}\n\ninterface CreateSyncStoragePersisterOptions {\n
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["noop","timeoutManager"],"sources":["../../src/index.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\nimport type { ManagedTimerId } from '@tanstack/query-core'\nimport type {\n PersistRetryer,\n PersistedClient,\n Persister,\n} from '@tanstack/query-persist-client-core'\n\ninterface Storage {\n getItem: (key: string) => string | null\n setItem: (key: string, value: string) => void\n removeItem: (key: string) => void\n}\n\ninterface CreateSyncStoragePersisterOptions {\n /**\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: Storage | undefined | null\n /** The key to use when storing the cache */\n key?: string\n /**\n * To avoid spamming,\n * pass a time in ms to throttle saving the cache to disk\n */\n throttleTime?: number\n /**\n * How to serialize the data to storage.\n * @default `JSON.stringify`\n */\n serialize?: (client: PersistedClient) => string\n /**\n * How to deserialize the data from storage.\n * @default `JSON.parse`\n */\n deserialize?: (cachedString: string) => PersistedClient\n\n retry?: PersistRetryer\n}\n\n/**\n * Creates a persister that stores the client in a synchronous storage such as\n * `window.localStorage`.\n * @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,\n * `deserialize`, and `retry` options.\n * @returns A persister that saves, restores, and removes the client in `storage`. Without\n * `storage`, its methods do nothing.\n * @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.\n */\nexport function createSyncStoragePersister({\n storage,\n key = `REACT_QUERY_OFFLINE_CACHE`,\n throttleTime = 1000,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n retry,\n}: CreateSyncStoragePersisterOptions): Persister {\n if (storage) {\n const trySave = (persistedClient: PersistedClient): Error | undefined => {\n try {\n storage.setItem(key, serialize(persistedClient))\n return\n } catch (error) {\n return error as Error\n }\n }\n return {\n persistClient: throttle((persistedClient) => {\n let client: PersistedClient | undefined = persistedClient\n let error = trySave(client)\n let errorCount = 0\n while (error && client) {\n errorCount++\n client = retry?.({\n persistedClient: client,\n error,\n errorCount,\n })\n\n if (client) {\n error = trySave(client)\n }\n }\n }, throttleTime),\n restoreClient: () => {\n const cacheString = storage.getItem(key)\n\n if (!cacheString) {\n return\n }\n\n return deserialize(cacheString)\n },\n removeClient: () => {\n storage.removeItem(key)\n },\n }\n }\n\n return {\n persistClient: noop,\n restoreClient: noop,\n removeClient: noop,\n }\n}\n\n/**\n * Wraps a function so it runs at most once per `wait` milliseconds, with the arguments of the latest\n * call.\n * @param func - The function to throttle.\n * @param wait - The time to wait before running `func`, in milliseconds.\n * @returns The throttled function.\n */\nfunction throttle<TArgs extends Array<any>>(\n func: (...args: TArgs) => any,\n wait = 100,\n) {\n let timer: ManagedTimerId | null = null\n let params: TArgs\n return function (...args: TArgs) {\n params = args\n if (timer === null) {\n timer = timeoutManager.setTimeout(() => {\n func(...params)\n timer = null\n }, wait)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAoDA,SAAgB,2BAA2B,EACzC,SACA,MAAM,6BACN,eAAe,KACf,YAAY,KAAK,WACjB,cAAc,KAAK,OACnB,SAC+C;CAC/C,IAAI,SAAS;EACX,MAAM,WAAW,oBAAwD;GACvE,IAAI;IACF,QAAQ,QAAQ,KAAK,UAAU,eAAe,CAAC;IAC/C;GACF,SAAS,OAAO;IACd,OAAO;GACT;EACF;EACA,OAAO;GACL,eAAe,UAAU,oBAAoB;IAC3C,IAAI,SAAsC;IAC1C,IAAI,QAAQ,QAAQ,MAAM;IAC1B,IAAI,aAAa;IACjB,OAAO,SAAS,QAAQ;KACtB;KACA,SAAS,QAAQ;MACf,iBAAiB;MACjB;MACA;KACF,CAAC;KAED,IAAI,QACF,QAAQ,QAAQ,MAAM;IAE1B;GACF,GAAG,YAAY;GACf,qBAAqB;IACnB,MAAM,cAAc,QAAQ,QAAQ,GAAG;IAEvC,IAAI,CAAC,aACH;IAGF,OAAO,YAAY,WAAW;GAChC;GACA,oBAAoB;IAClB,QAAQ,WAAW,GAAG;GACxB;EACF;CACF;CAEA,OAAO;EACL,eAAeA,cAAAA;EACf,eAAeA,cAAAA;EACf,cAAcA,cAAAA;CAChB;AACF;;;;;;;;AASA,SAAS,SACP,MACA,OAAO,KACP;CACA,IAAI,QAA+B;CACnC,IAAI;CACJ,OAAO,SAAU,GAAG,MAAa;EAC/B,SAAS;EACT,IAAI,UAAU,MACZ,QAAQC,qBAAAA,eAAe,iBAAiB;GACtC,KAAK,GAAG,MAAM;GACd,QAAQ;EACV,GAAG,IAAI;CAEX;AACF"}
|
package/build/modern/index.d.cts
CHANGED
|
@@ -6,15 +6,18 @@ interface Storage {
|
|
|
6
6
|
removeItem: (key: string) => void;
|
|
7
7
|
}
|
|
8
8
|
interface CreateSyncStoragePersisterOptions {
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The storage client used for setting and retrieving items from cache.
|
|
10
11
|
* For SSR pass in `undefined`. Note that window.localStorage can be
|
|
11
12
|
* `null` in Android WebViews depending on how they are configured.
|
|
12
13
|
*/
|
|
13
14
|
storage: Storage | undefined | null;
|
|
14
15
|
/** The key to use when storing the cache */
|
|
15
16
|
key?: string;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
17
|
+
/**
|
|
18
|
+
* To avoid spamming,
|
|
19
|
+
* pass a time in ms to throttle saving the cache to disk
|
|
20
|
+
*/
|
|
18
21
|
throttleTime?: number;
|
|
19
22
|
/**
|
|
20
23
|
* How to serialize the data to storage.
|
|
@@ -29,6 +32,12 @@ interface CreateSyncStoragePersisterOptions {
|
|
|
29
32
|
retry?: PersistRetryer;
|
|
30
33
|
}
|
|
31
34
|
/**
|
|
35
|
+
* Creates a persister that stores the client in a synchronous storage such as
|
|
36
|
+
* `window.localStorage`.
|
|
37
|
+
* @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,
|
|
38
|
+
* `deserialize`, and `retry` options.
|
|
39
|
+
* @returns A persister that saves, restores, and removes the client in `storage`. Without
|
|
40
|
+
* `storage`, its methods do nothing.
|
|
32
41
|
* @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.
|
|
33
42
|
*/
|
|
34
43
|
export declare function createSyncStoragePersister({ storage, key, throttleTime, serialize, deserialize, retry }: CreateSyncStoragePersisterOptions): Persister;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/index.ts"],"mappings":";;UASU;EACR,UAAU;EACV,UAAU,aAAa;EACvB,aAAa;;UAGL
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/index.ts"],"mappings":";;UASU;EACR,UAAU;EACV,UAAU,aAAa;EACvB,aAAa;;UAGL;;;;;;EAMR,SAAS;;EAET;;;;;EAKA;;;;;EAKA,aAAa,QAAQ;;;;;EAKrB,eAAe,yBAAyB;EAExC,QAAQ;;;;;;;;;;;wBAYM,6BACd,SACA,KACA,cACA,WACA,aACA,SACC,oCAAoC"}
|
package/build/modern/index.d.ts
CHANGED
|
@@ -6,15 +6,18 @@ interface Storage {
|
|
|
6
6
|
removeItem: (key: string) => void;
|
|
7
7
|
}
|
|
8
8
|
interface CreateSyncStoragePersisterOptions {
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The storage client used for setting and retrieving items from cache.
|
|
10
11
|
* For SSR pass in `undefined`. Note that window.localStorage can be
|
|
11
12
|
* `null` in Android WebViews depending on how they are configured.
|
|
12
13
|
*/
|
|
13
14
|
storage: Storage | undefined | null;
|
|
14
15
|
/** The key to use when storing the cache */
|
|
15
16
|
key?: string;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
17
|
+
/**
|
|
18
|
+
* To avoid spamming,
|
|
19
|
+
* pass a time in ms to throttle saving the cache to disk
|
|
20
|
+
*/
|
|
18
21
|
throttleTime?: number;
|
|
19
22
|
/**
|
|
20
23
|
* How to serialize the data to storage.
|
|
@@ -29,6 +32,12 @@ interface CreateSyncStoragePersisterOptions {
|
|
|
29
32
|
retry?: PersistRetryer;
|
|
30
33
|
}
|
|
31
34
|
/**
|
|
35
|
+
* Creates a persister that stores the client in a synchronous storage such as
|
|
36
|
+
* `window.localStorage`.
|
|
37
|
+
* @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,
|
|
38
|
+
* `deserialize`, and `retry` options.
|
|
39
|
+
* @returns A persister that saves, restores, and removes the client in `storage`. Without
|
|
40
|
+
* `storage`, its methods do nothing.
|
|
32
41
|
* @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.
|
|
33
42
|
*/
|
|
34
43
|
export declare function createSyncStoragePersister({ storage, key, throttleTime, serialize, deserialize, retry }: CreateSyncStoragePersisterOptions): Persister;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;UASU;EACR,UAAU;EACV,UAAU,aAAa;EACvB,aAAa;;UAGL
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;UASU;EACR,UAAU;EACV,UAAU,aAAa;EACvB,aAAa;;UAGL;;;;;;EAMR,SAAS;;EAET;;;;;EAKA;;;;;EAKA,aAAa,QAAQ;;;;;EAKrB,eAAe,yBAAyB;EAExC,QAAQ;;;;;;;;;;;wBAYM,6BACd,SACA,KACA,cACA,WACA,aACA,SACC,oCAAoC"}
|
package/build/modern/index.js
CHANGED
|
@@ -2,6 +2,12 @@ import { noop } from "./utils.js";
|
|
|
2
2
|
import { timeoutManager } from "@tanstack/query-core";
|
|
3
3
|
//#region src/index.ts
|
|
4
4
|
/**
|
|
5
|
+
* Creates a persister that stores the client in a synchronous storage such as
|
|
6
|
+
* `window.localStorage`.
|
|
7
|
+
* @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,
|
|
8
|
+
* `deserialize`, and `retry` options.
|
|
9
|
+
* @returns A persister that saves, restores, and removes the client in `storage`. Without
|
|
10
|
+
* `storage`, its methods do nothing.
|
|
5
11
|
* @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.
|
|
6
12
|
*/
|
|
7
13
|
function createSyncStoragePersister({ storage, key = `REACT_QUERY_OFFLINE_CACHE`, throttleTime = 1e3, serialize = JSON.stringify, deserialize = JSON.parse, retry }) {
|
|
@@ -45,6 +51,13 @@ function createSyncStoragePersister({ storage, key = `REACT_QUERY_OFFLINE_CACHE`
|
|
|
45
51
|
removeClient: noop
|
|
46
52
|
};
|
|
47
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Wraps a function so it runs at most once per `wait` milliseconds, with the arguments of the latest
|
|
56
|
+
* call.
|
|
57
|
+
* @param func - The function to throttle.
|
|
58
|
+
* @param wait - The time to wait before running `func`, in milliseconds.
|
|
59
|
+
* @returns The throttled function.
|
|
60
|
+
*/
|
|
48
61
|
function throttle(func, wait = 100) {
|
|
49
62
|
let timer = null;
|
|
50
63
|
let params;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\nimport type { ManagedTimerId } from '@tanstack/query-core'\nimport type {\n PersistRetryer,\n PersistedClient,\n Persister,\n} from '@tanstack/query-persist-client-core'\n\ninterface Storage {\n getItem: (key: string) => string | null\n setItem: (key: string, value: string) => void\n removeItem: (key: string) => void\n}\n\ninterface CreateSyncStoragePersisterOptions {\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { timeoutManager } from '@tanstack/query-core'\nimport { noop } from './utils'\nimport type { ManagedTimerId } from '@tanstack/query-core'\nimport type {\n PersistRetryer,\n PersistedClient,\n Persister,\n} from '@tanstack/query-persist-client-core'\n\ninterface Storage {\n getItem: (key: string) => string | null\n setItem: (key: string, value: string) => void\n removeItem: (key: string) => void\n}\n\ninterface CreateSyncStoragePersisterOptions {\n /**\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: Storage | undefined | null\n /** The key to use when storing the cache */\n key?: string\n /**\n * To avoid spamming,\n * pass a time in ms to throttle saving the cache to disk\n */\n throttleTime?: number\n /**\n * How to serialize the data to storage.\n * @default `JSON.stringify`\n */\n serialize?: (client: PersistedClient) => string\n /**\n * How to deserialize the data from storage.\n * @default `JSON.parse`\n */\n deserialize?: (cachedString: string) => PersistedClient\n\n retry?: PersistRetryer\n}\n\n/**\n * Creates a persister that stores the client in a synchronous storage such as\n * `window.localStorage`.\n * @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,\n * `deserialize`, and `retry` options.\n * @returns A persister that saves, restores, and removes the client in `storage`. Without\n * `storage`, its methods do nothing.\n * @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.\n */\nexport function createSyncStoragePersister({\n storage,\n key = `REACT_QUERY_OFFLINE_CACHE`,\n throttleTime = 1000,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n retry,\n}: CreateSyncStoragePersisterOptions): Persister {\n if (storage) {\n const trySave = (persistedClient: PersistedClient): Error | undefined => {\n try {\n storage.setItem(key, serialize(persistedClient))\n return\n } catch (error) {\n return error as Error\n }\n }\n return {\n persistClient: throttle((persistedClient) => {\n let client: PersistedClient | undefined = persistedClient\n let error = trySave(client)\n let errorCount = 0\n while (error && client) {\n errorCount++\n client = retry?.({\n persistedClient: client,\n error,\n errorCount,\n })\n\n if (client) {\n error = trySave(client)\n }\n }\n }, throttleTime),\n restoreClient: () => {\n const cacheString = storage.getItem(key)\n\n if (!cacheString) {\n return\n }\n\n return deserialize(cacheString)\n },\n removeClient: () => {\n storage.removeItem(key)\n },\n }\n }\n\n return {\n persistClient: noop,\n restoreClient: noop,\n removeClient: noop,\n }\n}\n\n/**\n * Wraps a function so it runs at most once per `wait` milliseconds, with the arguments of the latest\n * call.\n * @param func - The function to throttle.\n * @param wait - The time to wait before running `func`, in milliseconds.\n * @returns The throttled function.\n */\nfunction throttle<TArgs extends Array<any>>(\n func: (...args: TArgs) => any,\n wait = 100,\n) {\n let timer: ManagedTimerId | null = null\n let params: TArgs\n return function (...args: TArgs) {\n params = args\n if (timer === null) {\n timer = timeoutManager.setTimeout(() => {\n func(...params)\n timer = null\n }, wait)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAoDA,SAAgB,2BAA2B,EACzC,SACA,MAAM,6BACN,eAAe,KACf,YAAY,KAAK,WACjB,cAAc,KAAK,OACnB,SAC+C;CAC/C,IAAI,SAAS;EACX,MAAM,WAAW,oBAAwD;GACvE,IAAI;IACF,QAAQ,QAAQ,KAAK,UAAU,eAAe,CAAC;IAC/C;GACF,SAAS,OAAO;IACd,OAAO;GACT;EACF;EACA,OAAO;GACL,eAAe,UAAU,oBAAoB;IAC3C,IAAI,SAAsC;IAC1C,IAAI,QAAQ,QAAQ,MAAM;IAC1B,IAAI,aAAa;IACjB,OAAO,SAAS,QAAQ;KACtB;KACA,SAAS,QAAQ;MACf,iBAAiB;MACjB;MACA;KACF,CAAC;KAED,IAAI,QACF,QAAQ,QAAQ,MAAM;IAE1B;GACF,GAAG,YAAY;GACf,qBAAqB;IACnB,MAAM,cAAc,QAAQ,QAAQ,GAAG;IAEvC,IAAI,CAAC,aACH;IAGF,OAAO,YAAY,WAAW;GAChC;GACA,oBAAoB;IAClB,QAAQ,WAAW,GAAG;GACxB;EACF;CACF;CAEA,OAAO;EACL,eAAe;EACf,eAAe;EACf,cAAc;CAChB;AACF;;;;;;;;AASA,SAAS,SACP,MACA,OAAO,KACP;CACA,IAAI,QAA+B;CACnC,IAAI;CACJ,OAAO,SAAU,GAAG,MAAa;EAC/B,SAAS;EACT,IAAI,UAAU,MACZ,QAAQ,eAAe,iBAAiB;GACtC,KAAK,GAAG,MAAM;GACd,QAAQ;EACV,GAAG,IAAI;CAEX;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * A function that does nothing.\n */\nexport function noop(): void\nexport function noop(): undefined\nexport function noop() {}\n"],"mappings":";;AAKA,SAAgB,OAAO,CAAC"}
|
package/build/modern/utils.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","names":[],"sources":["../../src/utils.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"utils.d.cts","names":[],"sources":["../../src/utils.ts"],"mappings":";;;;wBAGgB;wBACA"}
|
package/build/modern/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/utils.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"utils.d.ts","names":[],"sources":["../../src/utils.ts"],"mappings":";;;;wBAGgB;wBACA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * A function that does nothing.\n */\nexport function noop(): void\nexport function noop(): undefined\nexport function noop() {}\n"],"mappings":";AAKA,SAAgB,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/query-sync-storage-persister",
|
|
3
|
-
"version": "5.104.
|
|
3
|
+
"version": "5.104.3",
|
|
4
4
|
"description": "A persister for synchronous storages, to be used with TanStack/Query",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"!src/__tests__"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@tanstack/query-core": "5.104.
|
|
44
|
-
"@tanstack/query-persist-client-core": "5.104.
|
|
43
|
+
"@tanstack/query-core": "5.104.3",
|
|
44
|
+
"@tanstack/query-persist-client-core": "5.104.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@tanstack/query-test-utils": "0.0.0",
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
"scripts": {
|
|
51
51
|
"clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
|
|
52
52
|
"compile": "tsc --project tsconfig.json",
|
|
53
|
-
"test:
|
|
53
|
+
"test:oxlint": "oxlint ./src",
|
|
54
54
|
"test:types": "npm-run-all --serial test:types:*",
|
|
55
|
-
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts56 --tsBuildInfoFile .cache/test-types/ts56.tsbuildinfo",
|
|
56
55
|
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts57 --tsBuildInfoFile .cache/test-types/ts57.tsbuildinfo",
|
|
57
56
|
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts58 --tsBuildInfoFile .cache/test-types/ts58.tsbuildinfo",
|
|
58
57
|
"test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts59 --tsBuildInfoFile .cache/test-types/ts59.tsbuildinfo",
|
|
59
58
|
"test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
|
|
60
59
|
"test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
|
|
60
|
+
"test:types:ts71": "node ../../node_modules/typescript71/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts71 --tsBuildInfoFile .cache/test-types/ts71.tsbuildinfo",
|
|
61
61
|
"test:lib": "vitest",
|
|
62
62
|
"test:lib:dev": "pnpm run test:lib --watch",
|
|
63
63
|
"test:build": "publint --strict && attw --pack",
|
package/src/index.ts
CHANGED
|
@@ -14,15 +14,18 @@ interface Storage {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
interface CreateSyncStoragePersisterOptions {
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* The storage client used for setting and retrieving items from cache.
|
|
18
19
|
* For SSR pass in `undefined`. Note that window.localStorage can be
|
|
19
20
|
* `null` in Android WebViews depending on how they are configured.
|
|
20
21
|
*/
|
|
21
22
|
storage: Storage | undefined | null
|
|
22
23
|
/** The key to use when storing the cache */
|
|
23
24
|
key?: string
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
25
|
+
/**
|
|
26
|
+
* To avoid spamming,
|
|
27
|
+
* pass a time in ms to throttle saving the cache to disk
|
|
28
|
+
*/
|
|
26
29
|
throttleTime?: number
|
|
27
30
|
/**
|
|
28
31
|
* How to serialize the data to storage.
|
|
@@ -39,6 +42,12 @@ interface CreateSyncStoragePersisterOptions {
|
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
/**
|
|
45
|
+
* Creates a persister that stores the client in a synchronous storage such as
|
|
46
|
+
* `window.localStorage`.
|
|
47
|
+
* @param options - The `storage` to persist to, the `key`, `throttleTime`, `serialize`,
|
|
48
|
+
* `deserialize`, and `retry` options.
|
|
49
|
+
* @returns A persister that saves, restores, and removes the client in `storage`. Without
|
|
50
|
+
* `storage`, its methods do nothing.
|
|
42
51
|
* @deprecated use `createAsyncStoragePersister` from `@tanstack/query-async-storage-persister` instead.
|
|
43
52
|
*/
|
|
44
53
|
export function createSyncStoragePersister({
|
|
@@ -98,6 +107,13 @@ export function createSyncStoragePersister({
|
|
|
98
107
|
}
|
|
99
108
|
}
|
|
100
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Wraps a function so it runs at most once per `wait` milliseconds, with the arguments of the latest
|
|
112
|
+
* call.
|
|
113
|
+
* @param func - The function to throttle.
|
|
114
|
+
* @param wait - The time to wait before running `func`, in milliseconds.
|
|
115
|
+
* @returns The throttled function.
|
|
116
|
+
*/
|
|
101
117
|
function throttle<TArgs extends Array<any>>(
|
|
102
118
|
func: (...args: TArgs) => any,
|
|
103
119
|
wait = 100,
|