@tanstack/svelte-query-persist-client 5.90.2 → 6.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.
@@ -1,51 +1,56 @@
1
1
  <script lang="ts">
2
- import { onDestroy } from 'svelte'
3
- import { persistQueryClient } from '@tanstack/query-persist-client-core'
2
+ import {
3
+ persistQueryClientRestore,
4
+ persistQueryClientSubscribe,
5
+ } from '@tanstack/query-persist-client-core'
4
6
  import {
5
7
  QueryClientProvider,
6
8
  setIsRestoringContext,
7
9
  } from '@tanstack/svelte-query'
8
- import { writable } from 'svelte/store'
10
+ import { box } from './utils.svelte.js'
9
11
  import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'
10
- import type { OmitKeyof, QueryClient } from '@tanstack/svelte-query'
12
+ import type {
13
+ OmitKeyof,
14
+ QueryClientProviderProps,
15
+ } from '@tanstack/svelte-query'
16
+
17
+ type PersistQueryClientProviderProps = QueryClientProviderProps & {
18
+ persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
19
+ onSuccess?: () => void
20
+ onError?: () => void
21
+ }
22
+
23
+ let {
24
+ client,
25
+ children,
26
+ persistOptions,
27
+ ...props
28
+ }: PersistQueryClientProviderProps = $props()
11
29
 
12
- export let client: QueryClient
13
- export let onSuccess: () => Promise<unknown> | unknown = () => undefined
14
- export let onError: () => Promise<unknown> | unknown = () => undefined
15
- export let persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
30
+ let isRestoring = box(true)
16
31
 
17
- const isRestoring = writable(true)
18
32
  setIsRestoringContext(isRestoring)
19
- $: {
20
- let isStale = false
21
- isRestoring.set(true)
22
- const [unsubscribe, promise] = persistQueryClient({
23
- ...persistOptions,
24
- queryClient: client,
25
- })
26
- promise
27
- .then(async () => {
28
- if (!isStale) {
29
- await onSuccess()
30
- }
31
- })
32
- .catch(async () => {
33
- if (!isStale) {
34
- await onError()
35
- }
36
- })
33
+
34
+ const options = $derived({
35
+ ...persistOptions,
36
+ queryClient: client,
37
+ })
38
+
39
+ $effect(() => {
40
+ return isRestoring.current ? () => {} : persistQueryClientSubscribe(options)
41
+ })
42
+
43
+ $effect(() => {
44
+ isRestoring.current = true
45
+ persistQueryClientRestore(options)
46
+ .then(() => props.onSuccess?.())
47
+ .catch(() => props.onError?.())
37
48
  .finally(() => {
38
- if (!isStale) {
39
- isRestoring.set(false)
40
- }
49
+ isRestoring.current = false
41
50
  })
42
- onDestroy(() => {
43
- isStale = true
44
- unsubscribe()
45
- })
46
- }
51
+ })
47
52
  </script>
48
53
 
49
- <QueryClientProvider {client}>
50
- <slot />
54
+ <QueryClientProvider {client} {...props}>
55
+ {@render children()}
51
56
  </QueryClientProvider>
@@ -1,24 +1,11 @@
1
- import { SvelteComponentTyped } from "svelte";
2
1
  import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core';
3
- import type { OmitKeyof, QueryClient } from '@tanstack/svelte-query';
4
- declare const __propDef: {
5
- props: {
6
- client: QueryClient;
7
- onSuccess?: () => Promise<unknown> | unknown;
8
- onError?: () => Promise<unknown> | unknown;
9
- persistOptions: OmitKeyof<PersistQueryClientOptions, "queryClient">;
10
- };
11
- events: {
12
- [evt: string]: CustomEvent<any>;
13
- };
14
- slots: {
15
- default: {};
16
- };
2
+ import type { OmitKeyof, QueryClientProviderProps } from '@tanstack/svelte-query';
3
+ type PersistQueryClientProviderProps = QueryClientProviderProps & {
4
+ persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>;
5
+ onSuccess?: () => void;
6
+ onError?: () => void;
17
7
  };
18
- export type PersistQueryClientProviderProps = typeof __propDef.props;
19
- export type PersistQueryClientProviderEvents = typeof __propDef.events;
20
- export type PersistQueryClientProviderSlots = typeof __propDef.slots;
21
- export default class PersistQueryClientProvider extends SvelteComponentTyped<PersistQueryClientProviderProps, PersistQueryClientProviderEvents, PersistQueryClientProviderSlots> {
22
- }
23
- export {};
8
+ declare const PersistQueryClientProvider: import("svelte").Component<PersistQueryClientProviderProps, {}, "">;
9
+ type PersistQueryClientProvider = ReturnType<typeof PersistQueryClientProvider>;
10
+ export default PersistQueryClientProvider;
24
11
  //# sourceMappingURL=PersistQueryClientProvider.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.svelte.d.ts","sourceRoot":"","sources":["../src/PersistQueryClientProvider.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAE5C;AAQD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AACpF,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAqDrE,QAAA,MAAM,SAAS;;gBADyG,WAAW;oBAAc,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO;kBAAY,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO;wBAAkB,SAAS,CAAC,yBAAyB,EAAE,aAAa,CAAC;;;;;;;;CACzO,CAAC;AAC1D,MAAM,MAAM,+BAA+B,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AACrE,MAAM,MAAM,gCAAgC,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AACvE,MAAM,MAAM,+BAA+B,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAErE,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,oBAAoB,CAAC,+BAA+B,EAAE,gCAAgC,EAAE,+BAA+B,CAAC;CAC/K"}
1
+ {"version":3,"file":"PersistQueryClientProvider.svelte.d.ts","sourceRoot":"","sources":["../src/PersistQueryClientProvider.svelte.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AACpF,OAAO,KAAK,EACR,SAAS,EACT,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAGhC,KAAK,+BAA+B,GAAG,wBAAwB,GAAG;IAChE,cAAc,EAAE,SAAS,CAAC,yBAAyB,EAAE,aAAa,CAAC,CAAA;IACnE,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB,CAAC;AA8CJ,QAAA,MAAM,0BAA0B,qEAAwC,CAAC;AACzE,KAAK,0BAA0B,GAAG,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAChF,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,6 @@
1
+ type Box<T> = {
2
+ current: T;
3
+ };
4
+ export declare function box<T>(initial: T): Box<T>;
5
+ export {};
6
+ //# sourceMappingURL=utils.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.svelte.d.ts","sourceRoot":"","sources":["../src/utils.svelte.ts"],"names":[],"mappings":"AAAA,KAAK,GAAG,CAAC,CAAC,IAAI;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAA;AAE5B,wBAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAWzC"}
@@ -0,0 +1,11 @@
1
+ export function box(initial) {
2
+ let current = $state(initial);
3
+ return {
4
+ get current() {
5
+ return current;
6
+ },
7
+ set current(newValue) {
8
+ current = newValue;
9
+ },
10
+ };
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-query-persist-client",
3
- "version": "5.90.2",
3
+ "version": "6.0.0",
4
4
  "description": "Svelte bindings to work with persisters in TanStack/svelte-query",
5
5
  "author": "Lachlan Collins",
6
6
  "license": "MIT",
@@ -14,6 +14,11 @@
14
14
  "type": "github",
15
15
  "url": "https://github.com/sponsors/tannerlinsley"
16
16
  },
17
+ "keywords": [
18
+ "tanstack",
19
+ "query",
20
+ "svelte"
21
+ ],
17
22
  "type": "module",
18
23
  "types": "dist/index.d.ts",
19
24
  "module": "dist/index.js",
@@ -40,15 +45,16 @@
40
45
  "@sveltejs/package": "^2.4.0",
41
46
  "@sveltejs/vite-plugin-svelte": "^5.1.1",
42
47
  "@testing-library/svelte": "^5.2.8",
48
+ "@typescript-eslint/parser": "^8.44.1",
43
49
  "eslint-plugin-svelte": "^3.11.0",
44
50
  "svelte": "^5.39.3",
45
51
  "svelte-check": "^4.3.1",
46
- "@tanstack/svelte-query": "5.90.2",
47
- "@tanstack/query-test-utils": "0.0.0"
52
+ "@tanstack/query-test-utils": "0.0.0",
53
+ "@tanstack/svelte-query": "6.0.0"
48
54
  },
49
55
  "peerDependencies": {
50
- "svelte": "^3.54.0 || ^4.0.0 || ^5.0.0",
51
- "@tanstack/svelte-query": "^5.90.2"
56
+ "svelte": "^5.25.0",
57
+ "@tanstack/svelte-query": "^6.0.0"
52
58
  },
53
59
  "scripts": {
54
60
  "clean": "premove ./dist ./coverage ./.svelte-kit ./dist-ts",
@@ -1,51 +1,56 @@
1
1
  <script lang="ts">
2
- import { onDestroy } from 'svelte'
3
- import { persistQueryClient } from '@tanstack/query-persist-client-core'
2
+ import {
3
+ persistQueryClientRestore,
4
+ persistQueryClientSubscribe,
5
+ } from '@tanstack/query-persist-client-core'
4
6
  import {
5
7
  QueryClientProvider,
6
8
  setIsRestoringContext,
7
9
  } from '@tanstack/svelte-query'
8
- import { writable } from 'svelte/store'
10
+ import { box } from './utils.svelte.js'
9
11
  import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'
10
- import type { OmitKeyof, QueryClient } from '@tanstack/svelte-query'
12
+ import type {
13
+ OmitKeyof,
14
+ QueryClientProviderProps,
15
+ } from '@tanstack/svelte-query'
16
+
17
+ type PersistQueryClientProviderProps = QueryClientProviderProps & {
18
+ persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
19
+ onSuccess?: () => void
20
+ onError?: () => void
21
+ }
22
+
23
+ let {
24
+ client,
25
+ children,
26
+ persistOptions,
27
+ ...props
28
+ }: PersistQueryClientProviderProps = $props()
11
29
 
12
- export let client: QueryClient
13
- export let onSuccess: () => Promise<unknown> | unknown = () => undefined
14
- export let onError: () => Promise<unknown> | unknown = () => undefined
15
- export let persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
30
+ let isRestoring = box(true)
16
31
 
17
- const isRestoring = writable(true)
18
32
  setIsRestoringContext(isRestoring)
19
- $: {
20
- let isStale = false
21
- isRestoring.set(true)
22
- const [unsubscribe, promise] = persistQueryClient({
23
- ...persistOptions,
24
- queryClient: client,
25
- })
26
- promise
27
- .then(async () => {
28
- if (!isStale) {
29
- await onSuccess()
30
- }
31
- })
32
- .catch(async () => {
33
- if (!isStale) {
34
- await onError()
35
- }
36
- })
33
+
34
+ const options = $derived({
35
+ ...persistOptions,
36
+ queryClient: client,
37
+ })
38
+
39
+ $effect(() => {
40
+ return isRestoring.current ? () => {} : persistQueryClientSubscribe(options)
41
+ })
42
+
43
+ $effect(() => {
44
+ isRestoring.current = true
45
+ persistQueryClientRestore(options)
46
+ .then(() => props.onSuccess?.())
47
+ .catch(() => props.onError?.())
37
48
  .finally(() => {
38
- if (!isStale) {
39
- isRestoring.set(false)
40
- }
49
+ isRestoring.current = false
41
50
  })
42
- onDestroy(() => {
43
- isStale = true
44
- unsubscribe()
45
- })
46
- }
51
+ })
47
52
  </script>
48
53
 
49
- <QueryClientProvider {client}>
50
- <slot />
54
+ <QueryClientProvider {client} {...props}>
55
+ {@render children()}
51
56
  </QueryClientProvider>
@@ -0,0 +1,14 @@
1
+ type Box<T> = { current: T }
2
+
3
+ export function box<T>(initial: T): Box<T> {
4
+ let current = $state(initial)
5
+
6
+ return {
7
+ get current() {
8
+ return current
9
+ },
10
+ set current(newValue) {
11
+ current = newValue
12
+ },
13
+ }
14
+ }