@tanstack/angular-query-persist-client 5.0.0-rc.5 → 5.108.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/README.md CHANGED
@@ -5,14 +5,19 @@ Persistence integration for `@tanstack/angular-query`.
5
5
  ## Installation
6
6
 
7
7
  ```sh
8
- pnpm add @tanstack/angular-query-persist-client @tanstack/query-persist-client-core
8
+ pnpm add @tanstack/angular-query-persist-client @tanstack/query-async-storage-persister
9
9
  ```
10
10
 
11
+ `@tanstack/query-async-storage-persister` provides the persister used below. Any
12
+ other persister works as well.
13
+
11
14
  ## Usage
12
15
 
13
16
  ```ts
14
17
  import { QueryClient, provideTanStackQuery } from '@tanstack/angular-query'
15
18
  import { withPersistQueryClient } from '@tanstack/angular-query-persist-client'
19
+ import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
20
+ import type { ApplicationConfig } from '@angular/core'
16
21
 
17
22
  export const appConfig: ApplicationConfig = {
18
23
  providers: [
package/build/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { PersistQueryClientOptions } from "@tanstack/query-persist-client-core";
2
2
  import { QueryFeature } from "@tanstack/angular-query";
3
3
  export * from "@tanstack/query-persist-client-core";
4
- //#region src/with-persist-query-client.types.d.ts
5
4
  /**
6
5
  * Configures cache persistence and callbacks for completion of the initial restoration.
7
6
  */
@@ -20,25 +19,31 @@ type PersistQueryClientUserOptions = {
20
19
  * context in the browser, so it can call `inject()` and touch browser APIs.
21
20
  */
22
21
  type WithPersistQueryClientFn = () => PersistQueryClientUserOptions;
23
- //#endregion
24
- //#region src/with-persist-query-client.d.ts
25
22
  /**
26
23
  * Enables persistence. The options factory runs once per injector, only in the
27
24
  * browser, in an Angular injection context. It can call `inject()` and use
28
25
  * browser APIs such as `localStorage`.
29
26
  *
30
27
  * ```ts
31
- * withPersistQueryClient(() => ({
32
- * persistOptions: {
33
- * persister: createAsyncStoragePersister({ storage: localStorage }),
34
- * },
35
- * }))
28
+ * export const appConfig: ApplicationConfig = {
29
+ * providers: [
30
+ * provideTanStackQuery(
31
+ * () => new QueryClient(),
32
+ * withPersistQueryClient(() => ({
33
+ * persistOptions: {
34
+ * persister: createAsyncStoragePersister({ storage: localStorage }),
35
+ * },
36
+ * onSuccess: () => console.log('Restoration completed successfully.'),
37
+ * })),
38
+ * ),
39
+ * ],
40
+ * }
36
41
  * ```
37
- * @param optionsFactory - Creates the persistence options in the browser.
42
+ * @param optionsFactory - Creates the persistence options in the browser, and optional `onSuccess` and
43
+ * `onError` callbacks which get called when the restoration process is complete.
38
44
  * @returns A set of providers for use with `provideTanStackQuery`.
39
45
  * @public
40
46
  */
41
47
  export declare function withPersistQueryClient(optionsFactory: WithPersistQueryClientFn): QueryFeature;
42
- //#endregion
43
48
  export type { PersistQueryClientUserOptions, WithPersistQueryClientFn };
44
49
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["PersistQueryClientOptionsCore"],"sources":["../src/with-persist-query-client.types.ts","../src/with-persist-query-client.ts"],"mappings":";;;;;;;KAKY;;;;EAIV,gBAAgB,KAAKA;;EAErB;;EAEA;;;;;;KAOU,iCAAiC;;;;;;;;;;;;;;;;;;;wBC4B7B,uBACd,gBAAgB,2BACf"}
1
+ {"version":3,"file":"index.d.ts","names":["PersistQueryClientOptionsCore"],"sources":["../src/with-persist-query-client.types.ts","../src/with-persist-query-client.ts"],"mappings":";;;;;;KAKY;;;;EAIV,gBAAgB,KAAKA;;EAErB;;EAEA;;;;;;KAOU,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;wBCqC7B,uBACd,gBAAgB,2BACf"}
package/build/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { persistQueryClientRestore, persistQueryClientSubscribe } from "@tanstack/query-persist-client-core";
2
- import { QueryClient } from "@tanstack/angular-query";
2
+ import { isPlatformBrowser } from "@angular/common";
3
3
  import { DestroyRef, InjectionToken, PLATFORM_ID, inject, makeEnvironmentProviders, provideEnvironmentInitializer, signal } from "@angular/core";
4
+ import { QueryClient } from "@tanstack/angular-query";
4
5
  import { provideIsRestoring, queryFeature } from "@tanstack/angular-query/internal";
5
- import { isPlatformBrowser } from "@angular/common";
6
6
  export * from "@tanstack/query-persist-client-core";
7
- //#region src/with-persist-query-client.ts
7
+ // src/with-persist-query-client.ts
8
8
  const RESTORING_STATE = new InjectionToken("Query restoration state");
9
9
  /**
10
10
  * Enables persistence. The options factory runs once per injector, only in the
@@ -12,13 +12,22 @@ const RESTORING_STATE = new InjectionToken("Query restoration state");
12
12
  * browser APIs such as `localStorage`.
13
13
  *
14
14
  * ```ts
15
- * withPersistQueryClient(() => ({
16
- * persistOptions: {
17
- * persister: createAsyncStoragePersister({ storage: localStorage }),
18
- * },
19
- * }))
15
+ * export const appConfig: ApplicationConfig = {
16
+ * providers: [
17
+ * provideTanStackQuery(
18
+ * () => new QueryClient(),
19
+ * withPersistQueryClient(() => ({
20
+ * persistOptions: {
21
+ * persister: createAsyncStoragePersister({ storage: localStorage }),
22
+ * },
23
+ * onSuccess: () => console.log('Restoration completed successfully.'),
24
+ * })),
25
+ * ),
26
+ * ],
27
+ * }
20
28
  * ```
21
- * @param optionsFactory - Creates the persistence options in the browser.
29
+ * @param optionsFactory - Creates the persistence options in the browser, and optional `onSuccess` and
30
+ * `onError` callbacks which get called when the restoration process is complete.
22
31
  * @returns A set of providers for use with `provideTanStackQuery`.
23
32
  * @public
24
33
  */
@@ -55,7 +64,6 @@ function withPersistQueryClient(optionsFactory) {
55
64
  })
56
65
  ]));
57
66
  }
58
- //#endregion
59
67
  export { withPersistQueryClient };
60
68
 
61
69
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/with-persist-query-client.ts"],"sourcesContent":["import { QueryClient } from '@tanstack/angular-query'\nimport {\n DestroyRef,\n InjectionToken,\n PLATFORM_ID,\n inject,\n makeEnvironmentProviders,\n provideEnvironmentInitializer,\n signal,\n} from '@angular/core'\nimport {\n provideIsRestoring,\n queryFeature,\n} from '@tanstack/angular-query/internal'\nimport { isPlatformBrowser } from '@angular/common'\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport type { WritableSignal } from '@angular/core'\nimport type { QueryFeature } from '@tanstack/angular-query'\nimport type { WithPersistQueryClientFn } from './with-persist-query-client.types'\n\nconst RESTORING_STATE = new InjectionToken<WritableSignal<boolean>>(\n 'Query restoration state',\n)\n\nexport type {\n PersistQueryClientUserOptions,\n WithPersistQueryClientFn,\n} from './with-persist-query-client.types'\n\n/**\n * Enables persistence. The options factory runs once per injector, only in the\n * browser, in an Angular injection context. It can call `inject()` and use\n * browser APIs such as `localStorage`.\n *\n * ```ts\n * withPersistQueryClient(() => ({\n * persistOptions: {\n * persister: createAsyncStoragePersister({ storage: localStorage }),\n * },\n * }))\n * ```\n * @param optionsFactory - Creates the persistence options in the browser.\n * @returns A set of providers for use with `provideTanStackQuery`.\n * @public\n */\nexport function withPersistQueryClient(\n optionsFactory: WithPersistQueryClientFn,\n): QueryFeature {\n return queryFeature(\n makeEnvironmentProviders([\n { provide: RESTORING_STATE, useFactory: () => signal(true) },\n provideIsRestoring(() => inject(RESTORING_STATE).asReadonly()),\n provideEnvironmentInitializer(() => {\n const isRestoring = inject(RESTORING_STATE)\n if (!isPlatformBrowser(inject(PLATFORM_ID))) {\n isRestoring.set(false)\n return\n }\n const destroyRef = inject(DestroyRef)\n const queryClient = inject(QueryClient)\n\n const { onSuccess, onError, persistOptions } = optionsFactory()\n const options = { queryClient, ...persistOptions }\n void persistQueryClientRestore(options)\n .then(() => {\n return onSuccess?.()\n })\n .catch(() => {\n return onError?.()\n })\n .finally(() => {\n if (destroyRef.destroyed) return\n isRestoring.set(false)\n const cleanup = persistQueryClientSubscribe(options)\n destroyRef.onDestroy(cleanup)\n })\n }),\n ]),\n )\n}\n"],"mappings":";;;;;;;AAuBA,MAAM,kBAAkB,IAAI,eAC1B,yBACF;;;;;;;;;;;;;;;;;AAuBA,SAAgB,uBACd,gBACc;CACd,OAAO,aACL,yBAAyB;EACvB;GAAE,SAAS;GAAiB,kBAAkB,OAAO,IAAI;EAAE;EAC3D,yBAAyB,OAAO,eAAe,CAAC,CAAC,WAAW,CAAC;EAC7D,oCAAoC;GAClC,MAAM,cAAc,OAAO,eAAe;GAC1C,IAAI,CAAC,kBAAkB,OAAO,WAAW,CAAC,GAAG;IAC3C,YAAY,IAAI,KAAK;IACrB;GACF;GACA,MAAM,aAAa,OAAO,UAAU;GACpC,MAAM,cAAc,OAAO,WAAW;GAEtC,MAAM,EAAE,WAAW,SAAS,mBAAmB,eAAe;GAC9D,MAAM,UAAU;IAAE;IAAa,GAAG;GAAe;GACjD,0BAA+B,OAAO,CAAC,CACpC,WAAW;IACV,OAAO,YAAY;GACrB,CAAC,CAAC,CACD,YAAY;IACX,OAAO,UAAU;GACnB,CAAC,CAAC,CACD,cAAc;IACb,IAAI,WAAW,WAAW;IAC1B,YAAY,IAAI,KAAK;IACrB,MAAM,UAAU,4BAA4B,OAAO;IACnD,WAAW,UAAU,OAAO;GAC9B,CAAC;EACL,CAAC;CACH,CAAC,CACH;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/with-persist-query-client.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common'\nimport {\n DestroyRef,\n InjectionToken,\n PLATFORM_ID,\n inject,\n makeEnvironmentProviders,\n provideEnvironmentInitializer,\n signal,\n} from '@angular/core'\nimport { QueryClient } from '@tanstack/angular-query'\nimport {\n provideIsRestoring,\n queryFeature,\n} from '@tanstack/angular-query/internal'\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport type { WritableSignal } from '@angular/core'\nimport type { QueryFeature } from '@tanstack/angular-query'\nimport type { WithPersistQueryClientFn } from './with-persist-query-client.types'\n\nconst RESTORING_STATE = new InjectionToken<WritableSignal<boolean>>(\n 'Query restoration state',\n)\n\nexport type {\n PersistQueryClientUserOptions,\n WithPersistQueryClientFn,\n} from './with-persist-query-client.types'\n\n/**\n * Enables persistence. The options factory runs once per injector, only in the\n * browser, in an Angular injection context. It can call `inject()` and use\n * browser APIs such as `localStorage`.\n *\n * ```ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideTanStackQuery(\n * () => new QueryClient(),\n * withPersistQueryClient(() => ({\n * persistOptions: {\n * persister: createAsyncStoragePersister({ storage: localStorage }),\n * },\n * onSuccess: () => console.log('Restoration completed successfully.'),\n * })),\n * ),\n * ],\n * }\n * ```\n * @param optionsFactory - Creates the persistence options in the browser, and optional `onSuccess` and\n * `onError` callbacks which get called when the restoration process is complete.\n * @returns A set of providers for use with `provideTanStackQuery`.\n * @public\n */\nexport function withPersistQueryClient(\n optionsFactory: WithPersistQueryClientFn,\n): QueryFeature {\n return queryFeature(\n makeEnvironmentProviders([\n { provide: RESTORING_STATE, useFactory: () => signal(true) },\n provideIsRestoring(() => inject(RESTORING_STATE).asReadonly()),\n provideEnvironmentInitializer(() => {\n const isRestoring = inject(RESTORING_STATE)\n if (!isPlatformBrowser(inject(PLATFORM_ID))) {\n isRestoring.set(false)\n return\n }\n const destroyRef = inject(DestroyRef)\n const queryClient = inject(QueryClient)\n\n const { onSuccess, onError, persistOptions } = optionsFactory()\n const options = { queryClient, ...persistOptions }\n void persistQueryClientRestore(options)\n .then(() => {\n return onSuccess?.()\n })\n .catch(() => {\n return onError?.()\n })\n .finally(() => {\n if (destroyRef.destroyed) return\n isRestoring.set(false)\n const cleanup = persistQueryClientSubscribe(options)\n destroyRef.onDestroy(cleanup)\n })\n }),\n ]),\n )\n}\n"],"mappings":";;;;;;;AAuBA,MAAM,kBAAkB,IAAI,eAC1B,yBACF;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,uBACd,gBACc;CACd,OAAO,aACL,yBAAyB;EACvB;GAAE,SAAS;GAAiB,kBAAkB,OAAO,IAAI;EAAE;EAC3D,yBAAyB,OAAO,eAAe,CAAC,CAAC,WAAW,CAAC;EAC7D,oCAAoC;GAClC,MAAM,cAAc,OAAO,eAAe;GAC1C,IAAI,CAAC,kBAAkB,OAAO,WAAW,CAAC,GAAG;IAC3C,YAAY,IAAI,KAAK;IACrB;GACF;GACA,MAAM,aAAa,OAAO,UAAU;GACpC,MAAM,cAAc,OAAO,WAAW;GAEtC,MAAM,EAAE,WAAW,SAAS,mBAAmB,eAAe;GAC9D,MAAM,UAAU;IAAE;IAAa,GAAG;GAAe;GACjD,0BAA+B,OAAO,CAAC,CACpC,WAAW;IACV,OAAO,YAAY;GACrB,CAAC,CAAC,CACD,YAAY;IACX,OAAO,UAAU;GACnB,CAAC,CAAC,CACD,cAAc;IACb,IAAI,WAAW,WAAW;IAC1B,YAAY,IAAI,KAAK;IACrB,MAAM,UAAU,4BAA4B,OAAO;IACnD,WAAW,UAAU,OAAO;GAC9B,CAAC;EACL,CAAC;CACH,CAAC,CACH;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/angular-query-persist-client",
3
- "version": "5.0.0-rc.5",
3
+ "version": "5.108.0",
4
4
  "description": "Angular bindings to work with persisters in TanStack/angular-query",
5
5
  "author": "Omer Gronich",
6
6
  "license": "MIT",
@@ -33,19 +33,19 @@
33
33
  "!src/__tests__"
34
34
  ],
35
35
  "dependencies": {
36
- "@tanstack/query-persist-client-core": "5.104.3"
36
+ "@tanstack/query-persist-client-core": "5.108.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@analogjs/vite-plugin-angular": "^2.3.1",
40
- "@angular/common": "^22.0.0",
41
- "@angular/compiler": "^22.0.0",
42
- "@angular/core": "^22.0.0",
43
- "@angular/platform-browser": "^22.0.0",
44
- "@angular/router": "^22.0.0",
39
+ "@analogjs/vite-plugin-angular": "^2.7.5",
40
+ "@angular/common": "^22.2.4",
41
+ "@angular/compiler": "^22.2.4",
42
+ "@angular/core": "^22.2.4",
43
+ "@angular/platform-browser": "^22.2.4",
44
+ "@angular/router": "^22.2.4",
45
45
  "@oxc-project/runtime": "^0.151.0",
46
- "@tanstack/angular-query": "5.0.0-rc.5",
46
+ "@tanstack/angular-query": "5.108.0",
47
47
  "@tanstack/query-test-utils": "0.0.0",
48
- "@testing-library/angular": "^18.1.1",
48
+ "@testing-library/angular": "^19.6.0",
49
49
  "@testing-library/dom": "^10.4.0",
50
50
  "npm-run-all2": "^9.0.3",
51
51
  "typescript": "6.0.3",
@@ -54,7 +54,7 @@
54
54
  "peerDependencies": {
55
55
  "@angular/common": ">=20.1.0",
56
56
  "@angular/core": ">=20.1.0",
57
- "@tanstack/angular-query": "^5.0.0-rc.5"
57
+ "@tanstack/angular-query": "^5.108.0"
58
58
  },
59
59
  "scripts": {
60
60
  "clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
package/src/index.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  // Re-export core
2
+ // oxlint-disable-next-line tanstack-query/no-restricted-syntax
2
3
  export * from '@tanstack/query-persist-client-core'
3
4
 
4
- export * from './with-persist-query-client'
5
+ export type {
6
+ PersistQueryClientUserOptions,
7
+ WithPersistQueryClientFn,
8
+ } from './with-persist-query-client'
9
+ export { withPersistQueryClient } from './with-persist-query-client'
@@ -1,4 +1,4 @@
1
- import { QueryClient } from '@tanstack/angular-query'
1
+ import { isPlatformBrowser } from '@angular/common'
2
2
  import {
3
3
  DestroyRef,
4
4
  InjectionToken,
@@ -8,11 +8,11 @@ import {
8
8
  provideEnvironmentInitializer,
9
9
  signal,
10
10
  } from '@angular/core'
11
+ import { QueryClient } from '@tanstack/angular-query'
11
12
  import {
12
13
  provideIsRestoring,
13
14
  queryFeature,
14
15
  } from '@tanstack/angular-query/internal'
15
- import { isPlatformBrowser } from '@angular/common'
16
16
  import {
17
17
  persistQueryClientRestore,
18
18
  persistQueryClientSubscribe,
@@ -36,13 +36,22 @@ export type {
36
36
  * browser APIs such as `localStorage`.
37
37
  *
38
38
  * ```ts
39
- * withPersistQueryClient(() => ({
40
- * persistOptions: {
41
- * persister: createAsyncStoragePersister({ storage: localStorage }),
42
- * },
43
- * }))
39
+ * export const appConfig: ApplicationConfig = {
40
+ * providers: [
41
+ * provideTanStackQuery(
42
+ * () => new QueryClient(),
43
+ * withPersistQueryClient(() => ({
44
+ * persistOptions: {
45
+ * persister: createAsyncStoragePersister({ storage: localStorage }),
46
+ * },
47
+ * onSuccess: () => console.log('Restoration completed successfully.'),
48
+ * })),
49
+ * ),
50
+ * ],
51
+ * }
44
52
  * ```
45
- * @param optionsFactory - Creates the persistence options in the browser.
53
+ * @param optionsFactory - Creates the persistence options in the browser, and optional `onSuccess` and
54
+ * `onError` callbacks which get called when the restoration process is complete.
46
55
  * @returns A set of providers for use with `provideTanStackQuery`.
47
56
  * @public
48
57
  */