@tanstack/angular-query-persist-client 0.0.0 → 5.0.0-rc.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Tanner Linsley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,45 +1,33 @@
1
1
  # @tanstack/angular-query-persist-client
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
4
-
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
-
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
8
-
9
- ## Purpose
10
-
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@tanstack/angular-query-persist-client`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
3
+ Persistence integration for `@tanstack/angular-query`.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ pnpm add @tanstack/angular-query-persist-client @tanstack/query-persist-client-core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { QueryClient, provideTanStackQuery } from '@tanstack/angular-query'
15
+ import { withPersistQueryClient } from '@tanstack/angular-query-persist-client'
16
+
17
+ export const appConfig: ApplicationConfig = {
18
+ providers: [
19
+ provideTanStackQuery(
20
+ () => new QueryClient(),
21
+ withPersistQueryClient(() => ({
22
+ persistOptions: {
23
+ persister: createAsyncStoragePersister({ storage: localStorage }),
24
+ },
25
+ })),
26
+ ),
27
+ ],
28
+ }
29
+ ```
30
+
31
+ The factory runs only in the browser and inside an Angular injection context.
32
+ This makes it safe to access browser-only storage and inject application
33
+ services without sharing persistence state between SSR requests.
@@ -0,0 +1,39 @@
1
+ import { PersistQueryClientOptions } from "@tanstack/query-persist-client-core";
2
+ import { QueryFeature } from "@tanstack/angular-query";
3
+ export * from "@tanstack/query-persist-client-core";
4
+ //#region src/with-persist-query-client.types.d.ts
5
+ type PersistQueryClientUserOptions = {
6
+ persistOptions: Omit<PersistQueryClientOptions, 'queryClient'>;
7
+ /** Called after restoration succeeds. A returned promise is awaited. */
8
+ onSuccess?: () => unknown;
9
+ /** Called if restoration fails. A returned promise is awaited. */
10
+ onError?: () => unknown;
11
+ };
12
+ /**
13
+ * Returns persistence options. The function runs once in an Angular injection
14
+ * context in the browser, so it can call `inject()` and touch browser APIs.
15
+ */
16
+ type WithPersistQueryClientFn = () => PersistQueryClientUserOptions;
17
+ //#endregion
18
+ //#region src/with-persist-query-client.d.ts
19
+ /**
20
+ * Enables persistence. The options factory runs once per injector, only in the
21
+ * browser, in an Angular injection context. It can call `inject()` and use
22
+ * browser APIs such as `localStorage`.
23
+ *
24
+ * ```ts
25
+ * withPersistQueryClient(() => ({
26
+ * persistOptions: {
27
+ * persister: createAsyncStoragePersister({ storage: localStorage }),
28
+ * },
29
+ * }))
30
+ * ```
31
+ *
32
+ * @param optionsFactory - Creates the persistence options in the browser.
33
+ * @returns A set of providers for use with `provideTanStackQuery`.
34
+ * @public
35
+ */
36
+ declare function withPersistQueryClient(optionsFactory: WithPersistQueryClientFn): QueryFeature;
37
+ //#endregion
38
+ export { type PersistQueryClientUserOptions, type WithPersistQueryClientFn, withPersistQueryClient };
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,62 @@
1
+ import { persistQueryClientRestore, persistQueryClientSubscribe } from "@tanstack/query-persist-client-core";
2
+ import { QueryClient } from "@tanstack/angular-query";
3
+ import { DestroyRef, InjectionToken, PLATFORM_ID, inject, makeEnvironmentProviders, provideEnvironmentInitializer, signal } from "@angular/core";
4
+ import { provideIsRestoring, queryFeature } from "@tanstack/angular-query/internal";
5
+ import { isPlatformBrowser } from "@angular/common";
6
+ export * from "@tanstack/query-persist-client-core";
7
+ //#region src/with-persist-query-client.ts
8
+ const RESTORING_STATE = new InjectionToken("Query restoration state");
9
+ /**
10
+ * Enables persistence. The options factory runs once per injector, only in the
11
+ * browser, in an Angular injection context. It can call `inject()` and use
12
+ * browser APIs such as `localStorage`.
13
+ *
14
+ * ```ts
15
+ * withPersistQueryClient(() => ({
16
+ * persistOptions: {
17
+ * persister: createAsyncStoragePersister({ storage: localStorage }),
18
+ * },
19
+ * }))
20
+ * ```
21
+ *
22
+ * @param optionsFactory - Creates the persistence options in the browser.
23
+ * @returns A set of providers for use with `provideTanStackQuery`.
24
+ * @public
25
+ */
26
+ function withPersistQueryClient(optionsFactory) {
27
+ return queryFeature(makeEnvironmentProviders([
28
+ {
29
+ provide: RESTORING_STATE,
30
+ useFactory: () => signal(true)
31
+ },
32
+ provideIsRestoring(() => inject(RESTORING_STATE).asReadonly()),
33
+ provideEnvironmentInitializer(() => {
34
+ const isRestoring = inject(RESTORING_STATE);
35
+ if (!isPlatformBrowser(inject(PLATFORM_ID))) {
36
+ isRestoring.set(false);
37
+ return;
38
+ }
39
+ const destroyRef = inject(DestroyRef);
40
+ const queryClient = inject(QueryClient);
41
+ const { onSuccess, onError, persistOptions } = optionsFactory();
42
+ const options = {
43
+ queryClient,
44
+ ...persistOptions
45
+ };
46
+ persistQueryClientRestore(options).then(() => {
47
+ return onSuccess?.();
48
+ }).catch(() => {
49
+ return onError?.();
50
+ }).finally(() => {
51
+ if (destroyRef.destroyed) return;
52
+ isRestoring.set(false);
53
+ const cleanup = persistQueryClientSubscribe(options);
54
+ destroyRef.onDestroy(cleanup);
55
+ });
56
+ })
57
+ ]));
58
+ }
59
+ //#endregion
60
+ export { withPersistQueryClient };
61
+
62
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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"}
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@tanstack/angular-query-persist-client",
3
- "version": "0.0.0",
4
- "description": "OIDC trusted publishing setup package for @tanstack/angular-query-persist-client",
5
- "keywords": ["oidc", "trusted-publishing", "setup"]
6
- }
3
+ "version": "5.0.0-rc.1",
4
+ "description": "Angular bindings to work with persisters in TanStack/angular-query",
5
+ "author": "Omer Gronich",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/TanStack/query.git",
10
+ "directory": "packages/angular-query-persist-client"
11
+ },
12
+ "homepage": "https://tanstack.com/query",
13
+ "funding": {
14
+ "type": "github",
15
+ "url": "https://github.com/sponsors/tannerlinsley"
16
+ },
17
+ "type": "module",
18
+ "types": "build/index.d.ts",
19
+ "module": "build/index.mjs",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./build/index.d.ts",
23
+ "default": "./build/index.mjs"
24
+ },
25
+ "./package.json": {
26
+ "default": "./package.json"
27
+ }
28
+ },
29
+ "sideEffects": false,
30
+ "files": [
31
+ "build",
32
+ "src",
33
+ "!src/__tests__"
34
+ ],
35
+ "dependencies": {
36
+ "@tanstack/query-persist-client-core": "5.103.2"
37
+ },
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",
45
+ "@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.1",
51
+ "@tanstack/query-test-utils": "0.0.0"
52
+ },
53
+ "peerDependencies": {
54
+ "@angular/common": ">=20.1.0",
55
+ "@angular/core": ">=20.1.0",
56
+ "@tanstack/angular-query": "^5.0.0-rc.1"
57
+ },
58
+ "scripts": {
59
+ "clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
60
+ "compile": "tsc --project tsconfig.json",
61
+ "test:eslint": "eslint --concurrency=auto ./src",
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
+ "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
+ "test:lib": "vitest",
70
+ "test:lib:dev": "pnpm run test:lib --watch",
71
+ "test:build": "publint --strict && attw --pack",
72
+ "build": "pnpm build:tsdown",
73
+ "build:tsdown": "tsdown --tsconfig tsconfig.prod.json"
74
+ }
75
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ // Re-export core
2
+ export * from '@tanstack/query-persist-client-core'
3
+
4
+ export * from './with-persist-query-client'
@@ -0,0 +1,84 @@
1
+ import { QueryClient } from '@tanstack/angular-query'
2
+ import {
3
+ DestroyRef,
4
+ InjectionToken,
5
+ PLATFORM_ID,
6
+ inject,
7
+ makeEnvironmentProviders,
8
+ provideEnvironmentInitializer,
9
+ signal,
10
+ } from '@angular/core'
11
+ import {
12
+ provideIsRestoring,
13
+ queryFeature,
14
+ } from '@tanstack/angular-query/internal'
15
+ import { isPlatformBrowser } from '@angular/common'
16
+ import {
17
+ persistQueryClientRestore,
18
+ persistQueryClientSubscribe,
19
+ } from '@tanstack/query-persist-client-core'
20
+ import type { WritableSignal } from '@angular/core'
21
+ import type { QueryFeature } from '@tanstack/angular-query'
22
+ import type { WithPersistQueryClientFn } from './with-persist-query-client.types'
23
+
24
+ const RESTORING_STATE = new InjectionToken<WritableSignal<boolean>>(
25
+ 'Query restoration state',
26
+ )
27
+
28
+ export type {
29
+ PersistQueryClientUserOptions,
30
+ WithPersistQueryClientFn,
31
+ } from './with-persist-query-client.types'
32
+
33
+ /**
34
+ * Enables persistence. The options factory runs once per injector, only in the
35
+ * browser, in an Angular injection context. It can call `inject()` and use
36
+ * browser APIs such as `localStorage`.
37
+ *
38
+ * ```ts
39
+ * withPersistQueryClient(() => ({
40
+ * persistOptions: {
41
+ * persister: createAsyncStoragePersister({ storage: localStorage }),
42
+ * },
43
+ * }))
44
+ * ```
45
+ *
46
+ * @param optionsFactory - Creates the persistence options in the browser.
47
+ * @returns A set of providers for use with `provideTanStackQuery`.
48
+ * @public
49
+ */
50
+ export function withPersistQueryClient(
51
+ optionsFactory: WithPersistQueryClientFn,
52
+ ): QueryFeature {
53
+ return queryFeature(
54
+ makeEnvironmentProviders([
55
+ { provide: RESTORING_STATE, useFactory: () => signal(true) },
56
+ provideIsRestoring(() => inject(RESTORING_STATE).asReadonly()),
57
+ provideEnvironmentInitializer(() => {
58
+ const isRestoring = inject(RESTORING_STATE)
59
+ if (!isPlatformBrowser(inject(PLATFORM_ID))) {
60
+ isRestoring.set(false)
61
+ return
62
+ }
63
+ const destroyRef = inject(DestroyRef)
64
+ const queryClient = inject(QueryClient)
65
+
66
+ const { onSuccess, onError, persistOptions } = optionsFactory()
67
+ const options = { queryClient, ...persistOptions }
68
+ void persistQueryClientRestore(options)
69
+ .then(() => {
70
+ return onSuccess?.()
71
+ })
72
+ .catch(() => {
73
+ return onError?.()
74
+ })
75
+ .finally(() => {
76
+ if (destroyRef.destroyed) return
77
+ isRestoring.set(false)
78
+ const cleanup = persistQueryClientSubscribe(options)
79
+ destroyRef.onDestroy(cleanup)
80
+ })
81
+ }),
82
+ ]),
83
+ )
84
+ }
@@ -0,0 +1,15 @@
1
+ import type { PersistQueryClientOptions as PersistQueryClientOptionsCore } from '@tanstack/query-persist-client-core'
2
+
3
+ export type PersistQueryClientUserOptions = {
4
+ persistOptions: Omit<PersistQueryClientOptionsCore, 'queryClient'>
5
+ /** Called after restoration succeeds. A returned promise is awaited. */
6
+ onSuccess?: () => unknown
7
+ /** Called if restoration fails. A returned promise is awaited. */
8
+ onError?: () => unknown
9
+ }
10
+
11
+ /**
12
+ * Returns persistence options. The function runs once in an Angular injection
13
+ * context in the browser, so it can call `inject()` and touch browser APIs.
14
+ */
15
+ export type WithPersistQueryClientFn = () => PersistQueryClientUserOptions