@tanstack/angular-query-persist-client 5.0.0-rc.4 → 5.0.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,8 +1,13 @@
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
4
+ /**
5
+ * Configures cache persistence and callbacks for completion of the initial restoration.
6
+ */
5
7
  type PersistQueryClientUserOptions = {
8
+ /**
9
+ * Persistence storage and lifecycle settings; the client is supplied by the Query provider.
10
+ */
6
11
  persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>;
7
12
  /** Called after restoration succeeds. A returned promise is awaited. */
8
13
  onSuccess?: () => unknown;
@@ -14,8 +19,6 @@ type PersistQueryClientUserOptions = {
14
19
  * context in the browser, so it can call `inject()` and touch browser APIs.
15
20
  */
16
21
  type WithPersistQueryClientFn = () => PersistQueryClientUserOptions;
17
- //#endregion
18
- //#region src/with-persist-query-client.d.ts
19
22
  /**
20
23
  * Enables persistence. The options factory runs once per injector, only in the
21
24
  * browser, in an Angular injection context. It can call `inject()` and use
@@ -28,12 +31,10 @@ type WithPersistQueryClientFn = () => PersistQueryClientUserOptions;
28
31
  * },
29
32
  * }))
30
33
  * ```
31
- *
32
34
  * @param optionsFactory - Creates the persistence options in the browser.
33
35
  * @returns A set of providers for use with `provideTanStackQuery`.
34
36
  * @public
35
37
  */
36
- declare function withPersistQueryClient(optionsFactory: WithPersistQueryClientFn): QueryFeature;
37
- //#endregion
38
- export { type PersistQueryClientUserOptions, type WithPersistQueryClientFn, withPersistQueryClient };
38
+ export declare function withPersistQueryClient(optionsFactory: WithPersistQueryClientFn): QueryFeature;
39
+ export type { PersistQueryClientUserOptions, WithPersistQueryClientFn };
39
40
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/with-persist-query-client.types.ts","../src/with-persist-query-client.ts"],"mappings":";;;;KAEY;EACV,gBAAgB,KAAK;;EAErB;;EAEA;;;;;;KAOU,iCAAiC;;;;;;;;;;;;;;;;;;;;iBCmC7B,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;;;;;;;;;;;;;;;;;wBC4B7B,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
@@ -18,7 +18,6 @@ const RESTORING_STATE = new InjectionToken("Query restoration state");
18
18
  * },
19
19
  * }))
20
20
  * ```
21
- *
22
21
  * @param optionsFactory - Creates the persistence options in the browser.
23
22
  * @returns A set of providers for use with `provideTanStackQuery`.
24
23
  * @public
@@ -56,7 +55,6 @@ function withPersistQueryClient(optionsFactory) {
56
55
  })
57
56
  ]));
58
57
  }
59
- //#endregion
60
58
  export { withPersistQueryClient };
61
59
 
62
60
  //# 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 *\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;;;;;;;;;;;;;;;;;;AAwBA,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 * 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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/angular-query-persist-client",
3
- "version": "5.0.0-rc.4",
3
+ "version": "5.0.0",
4
4
  "description": "Angular bindings to work with persisters in TanStack/angular-query",
5
5
  "author": "Omer Gronich",
6
6
  "license": "MIT",
@@ -33,43 +33,39 @@
33
33
  "!src/__tests__"
34
34
  ],
35
35
  "dependencies": {
36
- "@tanstack/query-persist-client-core": "5.103.2"
36
+ "@tanstack/query-persist-client-core": "5.107.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@angular/common": "^22.0.0",
40
- "@angular/compiler": "^22.0.0",
41
- "@angular/core": "^22.0.0",
42
- "@angular/platform-browser": "^22.0.0",
43
- "@angular/router": "^22.0.0",
44
- "@testing-library/angular": "^18.1.1",
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
+ "@oxc-project/runtime": "^0.151.0",
46
+ "@tanstack/angular-query": "5.0.0",
47
+ "@tanstack/query-test-utils": "0.0.0",
48
+ "@testing-library/angular": "^19.6.0",
45
49
  "@testing-library/dom": "^10.4.0",
46
- "eslint-plugin-jsdoc": "^50.5.0",
47
- "npm-run-all2": "^5.0.0",
48
- "typescript": "5.9.3",
49
- "zone.js": "^0.16.0",
50
- "@tanstack/angular-query": "5.0.0-rc.4",
51
- "@tanstack/query-test-utils": "0.0.0"
50
+ "npm-run-all2": "^9.0.3",
51
+ "typescript": "6.0.3",
52
+ "zone.js": "^0.16.0"
52
53
  },
53
54
  "peerDependencies": {
54
55
  "@angular/common": ">=20.1.0",
55
56
  "@angular/core": ">=20.1.0",
56
- "@tanstack/angular-query": "^5.0.0-rc.4"
57
+ "@tanstack/angular-query": "^5.0.0"
57
58
  },
58
59
  "scripts": {
59
60
  "clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
60
61
  "compile": "tsc --project tsconfig.json",
61
- "test:eslint": "eslint --concurrency=auto ./src",
62
62
  "test:types": "npm-run-all --serial test:types:*",
63
- "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts56 --tsBuildInfoFile .cache/test-types/ts56.tsbuildinfo",
64
- "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts57 --tsBuildInfoFile .cache/test-types/ts57.tsbuildinfo",
65
- "test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts58 --tsBuildInfoFile .cache/test-types/ts58.tsbuildinfo",
66
- "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts59 --tsBuildInfoFile .cache/test-types/ts59.tsbuildinfo",
67
63
  "test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
68
- "test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
69
64
  "test:lib": "vitest",
70
65
  "test:lib:dev": "pnpm run test:lib --watch",
71
66
  "test:build": "publint --strict && attw --pack",
72
67
  "build": "pnpm build:tsdown",
73
- "build:tsdown": "tsdown --tsconfig tsconfig.prod.json"
68
+ "build:tsdown": "tsdown --tsconfig tsconfig.prod.json",
69
+ "test:oxlint": "oxlint ./src"
74
70
  }
75
71
  }
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,
@@ -42,7 +42,6 @@ export type {
42
42
  * },
43
43
  * }))
44
44
  * ```
45
- *
46
45
  * @param optionsFactory - Creates the persistence options in the browser.
47
46
  * @returns A set of providers for use with `provideTanStackQuery`.
48
47
  * @public
@@ -1,6 +1,12 @@
1
1
  import type { PersistQueryClientOptions as PersistQueryClientOptionsCore } from '@tanstack/query-persist-client-core'
2
2
 
3
+ /**
4
+ * Configures cache persistence and callbacks for completion of the initial restoration.
5
+ */
3
6
  export type PersistQueryClientUserOptions = {
7
+ /**
8
+ * Persistence storage and lifecycle settings; the client is supplied by the Query provider.
9
+ */
4
10
  persistOptions: Omit<PersistQueryClientOptionsCore, 'queryClient'>
5
11
  /** Called after restoration succeeds. A returned promise is awaited. */
6
12
  onSuccess?: () => unknown