@tanstack/svelte-query 5.0.0-alpha.5 → 5.0.0-alpha.51
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/lib/HydrationBoundary.svelte.d.ts +4 -3
- package/build/lib/HydrationBoundary.svelte.d.ts.map +1 -0
- package/build/lib/QueryClientProvider.svelte.d.ts +4 -3
- package/build/lib/QueryClientProvider.svelte.d.ts.map +1 -0
- package/build/lib/__tests__/CreateMutation.svelte +10 -0
- package/build/lib/__tests__/CreateMutation.svelte.d.ts +18 -0
- package/build/lib/__tests__/CreateMutation.svelte.d.ts.map +1 -0
- package/build/lib/__tests__/CreateQueries.svelte +16 -0
- package/build/lib/__tests__/CreateQueries.svelte.d.ts +20 -0
- package/build/lib/__tests__/CreateQueries.svelte.d.ts.map +1 -0
- package/build/lib/__tests__/CreateQuery.svelte +22 -0
- package/build/lib/__tests__/CreateQuery.svelte.d.ts +18 -0
- package/build/lib/__tests__/CreateQuery.svelte.d.ts.map +1 -0
- package/build/lib/__tests__/createMutation.test.d.ts +2 -0
- package/build/lib/__tests__/createMutation.test.d.ts.map +1 -0
- package/build/lib/__tests__/createMutation.test.js +19 -0
- package/build/lib/__tests__/createQueries.test.d.ts +2 -0
- package/build/lib/__tests__/createQueries.test.d.ts.map +1 -0
- package/build/lib/__tests__/createQueries.test.js +38 -0
- package/build/lib/__tests__/createQuery.test.d.ts +2 -0
- package/build/lib/__tests__/createQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/createQuery.test.js +57 -0
- package/build/lib/__tests__/utils.d.ts +10 -0
- package/build/lib/__tests__/utils.d.ts.map +1 -0
- package/build/lib/__tests__/utils.js +33 -0
- package/build/lib/context.d.ts +1 -0
- package/build/lib/context.d.ts.map +1 -0
- package/build/lib/createBaseQuery.d.ts +3 -2
- package/build/lib/createBaseQuery.d.ts.map +1 -0
- package/build/lib/createBaseQuery.js +1 -11
- package/build/lib/createInfiniteQuery.d.ts +3 -2
- package/build/lib/createInfiniteQuery.d.ts.map +1 -0
- package/build/lib/createMutation.d.ts +3 -2
- package/build/lib/createMutation.d.ts.map +1 -0
- package/build/lib/createQueries.d.ts +17 -16
- package/build/lib/createQueries.d.ts.map +1 -0
- package/build/lib/createQueries.js +7 -6
- package/build/lib/createQuery.d.ts +6 -5
- package/build/lib/createQuery.d.ts.map +1 -0
- package/build/lib/index.d.ts +1 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/types.d.ts +27 -29
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/useHydrate.d.ts +1 -0
- package/build/lib/useHydrate.d.ts.map +1 -0
- package/build/lib/useIsFetching.d.ts +1 -0
- package/build/lib/useIsFetching.d.ts.map +1 -0
- package/build/lib/useIsMutating.d.ts +1 -0
- package/build/lib/useIsMutating.d.ts.map +1 -0
- package/build/lib/useQueryClient.d.ts +1 -0
- package/build/lib/useQueryClient.d.ts.map +1 -0
- package/build/lib/utils.d.ts +1 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/package.json +34 -29
- package/src/createBaseQuery.ts +9 -28
- package/src/createInfiniteQuery.ts +7 -10
- package/src/createMutation.ts +1 -4
- package/src/createQueries.ts +54 -32
- package/src/createQuery.ts +3 -10
- package/src/types.ts +39 -36
- package/build/lib/.gitignore +0 -9
- package/src/__tests__/CreateMutation.svelte +0 -17
- package/src/__tests__/CreateQueries.svelte +0 -20
- package/src/__tests__/CreateQuery.svelte +0 -30
- package/src/__tests__/createMutation.test.ts +0 -24
- package/src/__tests__/createQueries.test.ts +0 -41
- package/src/__tests__/createQuery.test.ts +0 -64
- package/src/__tests__/utils.ts +0 -40
|
@@ -13,9 +13,10 @@ declare const __propDef: {
|
|
|
13
13
|
default: {};
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
16
|
+
export type HydrationBoundaryProps = typeof __propDef.props;
|
|
17
|
+
export type HydrationBoundaryEvents = typeof __propDef.events;
|
|
18
|
+
export type HydrationBoundarySlots = typeof __propDef.slots;
|
|
19
19
|
export default class HydrationBoundary extends SvelteComponentTyped<HydrationBoundaryProps, HydrationBoundaryEvents, HydrationBoundarySlots> {
|
|
20
20
|
}
|
|
21
21
|
export {};
|
|
22
|
+
//# sourceMappingURL=HydrationBoundary.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HydrationBoundary.svelte.d.ts","sourceRoot":"","sources":["../../../src/HydrationBoundary.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAG7C,OAAO,KAAK,EACR,eAAe,EACf,cAAc,EACd,WAAW,EACZ,MAAM,sBAAsB,CAAA;AAc/B,QAAA,MAAM,SAAS;;eADyE,eAAe;kBAAY,cAAc,GAAG,SAAS;sBAAgB,WAAW,GAAG,SAAS;;;;;;;;CAC7H,CAAC;AACxD,MAAM,MAAM,sBAAsB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAC5D,MAAM,MAAM,uBAAuB,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AAC9D,MAAM,MAAM,sBAAsB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAE5D,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,oBAAoB,CAAC,sBAAsB,EAAE,uBAAuB,EAAE,sBAAsB,CAAC;CAC3I"}
|
|
@@ -11,9 +11,10 @@ declare const __propDef: {
|
|
|
11
11
|
default: {};
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
14
|
+
export type QueryClientProviderProps = typeof __propDef.props;
|
|
15
|
+
export type QueryClientProviderEvents = typeof __propDef.events;
|
|
16
|
+
export type QueryClientProviderSlots = typeof __propDef.slots;
|
|
17
17
|
export default class QueryClientProvider extends SvelteComponentTyped<QueryClientProviderProps, QueryClientProviderEvents, QueryClientProviderSlots> {
|
|
18
18
|
}
|
|
19
19
|
export {};
|
|
20
|
+
//# sourceMappingURL=QueryClientProvider.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryClientProvider.svelte.d.ts","sourceRoot":"","sources":["../../../src/QueryClientProvider.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAI7C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAqBlD,QAAA,MAAM,SAAS;;;;;;;;;;CAAwC,CAAC;AACxD,MAAM,MAAM,wBAAwB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAC9D,MAAM,MAAM,yBAAyB,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AAChE,MAAM,MAAM,wBAAwB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAE9D,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,oBAAoB,CAAC,wBAAwB,EAAE,yBAAyB,EAAE,wBAAwB,CAAC;CACnJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<script>import { QueryClient } from "@tanstack/query-core";
|
|
2
|
+
import { setQueryClientContext } from "../context";
|
|
3
|
+
import { createMutation } from "../createMutation";
|
|
4
|
+
export let options;
|
|
5
|
+
const queryClient = new QueryClient();
|
|
6
|
+
setQueryClientContext(queryClient);
|
|
7
|
+
const mutation = createMutation(options);
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<button on:click={() => $mutation.mutate()}>Click</button>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { CreateMutationOptions } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
options: CreateMutationOptions;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {};
|
|
11
|
+
};
|
|
12
|
+
export type CreateMutationProps = typeof __propDef.props;
|
|
13
|
+
export type CreateMutationEvents = typeof __propDef.events;
|
|
14
|
+
export type CreateMutationSlots = typeof __propDef.slots;
|
|
15
|
+
export default class CreateMutation extends SvelteComponentTyped<CreateMutationProps, CreateMutationEvents, CreateMutationSlots> {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=CreateMutation.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateMutation.svelte.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/CreateMutation.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAM7C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAgBrD,QAAA,MAAM,SAAS;;iBADiC,qBAAqB;;;;;;CACd,CAAC;AACxD,MAAM,MAAM,mBAAmB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AACzD,MAAM,MAAM,oBAAoB,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AAC3D,MAAM,MAAM,mBAAmB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAEzD,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,oBAAoB,CAAC,mBAAmB,EAAE,oBAAoB,EAAE,mBAAmB,CAAC;CAC/H"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script>import { QueryClient } from "@tanstack/query-core";
|
|
2
|
+
import { setQueryClientContext } from "../context";
|
|
3
|
+
import { createQueries } from "../createQueries";
|
|
4
|
+
export let options;
|
|
5
|
+
const queryClient = new QueryClient();
|
|
6
|
+
setQueryClientContext(queryClient);
|
|
7
|
+
const queries = createQueries(options);
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
{#each $queries as query, index}
|
|
11
|
+
{#if query.isPending}
|
|
12
|
+
<p>Loading {index + 1}</p>
|
|
13
|
+
{:else if query.isSuccess}
|
|
14
|
+
<p>{query.data}</p>
|
|
15
|
+
{/if}
|
|
16
|
+
{/each}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { QueriesOptions } from '../createQueries';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
options: {
|
|
6
|
+
queries: [...QueriesOptions<any>];
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
events: {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {};
|
|
13
|
+
};
|
|
14
|
+
export type CreateQueriesProps = typeof __propDef.props;
|
|
15
|
+
export type CreateQueriesEvents = typeof __propDef.events;
|
|
16
|
+
export type CreateQueriesSlots = typeof __propDef.slots;
|
|
17
|
+
export default class CreateQueries extends SvelteComponentTyped<CreateQueriesProps, CreateQueriesEvents, CreateQueriesSlots> {
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=CreateQueries.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateQueries.svelte.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/CreateQueries.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAM7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAgBtD,QAAA,MAAM,SAAS;;;qBAD4C,CAAC,GAAG,eAAe,GAAG,CAAC,CAAC;;;;;;;CAC5B,CAAC;AACxD,MAAM,MAAM,kBAAkB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AACxD,MAAM,MAAM,mBAAmB,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AAC1D,MAAM,MAAM,kBAAkB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAExD,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,oBAAoB,CAAC,kBAAkB,EAAE,mBAAmB,EAAE,kBAAkB,CAAC;CAC3H"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script>import { QueryClient } from "@tanstack/query-core";
|
|
2
|
+
import { setQueryClientContext } from "../context";
|
|
3
|
+
import { createQuery } from "../createQuery";
|
|
4
|
+
export let options;
|
|
5
|
+
const queryClient = new QueryClient();
|
|
6
|
+
setQueryClientContext(queryClient);
|
|
7
|
+
const query = createQuery(options);
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
{#if $query.isPending}
|
|
11
|
+
<p>Loading</p>
|
|
12
|
+
{:else if $query.isError}
|
|
13
|
+
<p>Error</p>
|
|
14
|
+
{:else if $query.isSuccess}
|
|
15
|
+
<p>Success</p>
|
|
16
|
+
{/if}
|
|
17
|
+
|
|
18
|
+
<ul>
|
|
19
|
+
{#each $query.data ?? [] as entry}
|
|
20
|
+
<li>id: {entry.id}</li>
|
|
21
|
+
{/each}
|
|
22
|
+
</ul>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { CreateQueryOptions } from '../types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
options: CreateQueryOptions<any>;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {};
|
|
11
|
+
};
|
|
12
|
+
export type CreateQueryProps = typeof __propDef.props;
|
|
13
|
+
export type CreateQueryEvents = typeof __propDef.events;
|
|
14
|
+
export type CreateQuerySlots = typeof __propDef.slots;
|
|
15
|
+
export default class CreateQuery extends SvelteComponentTyped<CreateQueryProps, CreateQueryEvents, CreateQuerySlots> {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=CreateQuery.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateQuery.svelte.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/CreateQuery.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAM7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAgBlD,QAAA,MAAM,SAAS;;iBADiC,mBAAmB,GAAG,CAAC;;;;;;CAChB,CAAC;AACxD,MAAM,MAAM,gBAAgB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AACtD,MAAM,MAAM,iBAAiB,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AACxD,MAAM,MAAM,gBAAgB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAEtD,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,oBAAoB,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,CAAC;CACnH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMutation.test.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/createMutation.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { fireEvent, render, waitFor } from '@testing-library/svelte';
|
|
3
|
+
import CreateMutation from './CreateMutation.svelte';
|
|
4
|
+
describe('createMutation', () => {
|
|
5
|
+
it('Call mutate and check function runs', async () => {
|
|
6
|
+
const mutationFn = vi.fn();
|
|
7
|
+
const rendered = render(CreateMutation, {
|
|
8
|
+
props: {
|
|
9
|
+
options: {
|
|
10
|
+
mutationFn,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
fireEvent.click(rendered.getByRole('button'));
|
|
15
|
+
await waitFor(() => {
|
|
16
|
+
expect(mutationFn).toHaveBeenCalledTimes(1);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQueries.test.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/createQueries.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, waitFor } from '@testing-library/svelte';
|
|
3
|
+
import CreateQueries from './CreateQueries.svelte';
|
|
4
|
+
import { sleep } from './utils';
|
|
5
|
+
describe('createQueries', () => {
|
|
6
|
+
it('Render and wait for success', async () => {
|
|
7
|
+
const rendered = render(CreateQueries, {
|
|
8
|
+
props: {
|
|
9
|
+
options: {
|
|
10
|
+
queries: [
|
|
11
|
+
{
|
|
12
|
+
queryKey: ['key-1'],
|
|
13
|
+
queryFn: async () => {
|
|
14
|
+
await sleep(10);
|
|
15
|
+
return 'Success 1';
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
queryKey: ['key-2'],
|
|
20
|
+
queryFn: async () => {
|
|
21
|
+
await sleep(10);
|
|
22
|
+
return 'Success 2';
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
await waitFor(() => {
|
|
30
|
+
expect(rendered.getByText('Loading 1')).toBeInTheDocument();
|
|
31
|
+
expect(rendered.getByText('Loading 2')).toBeInTheDocument();
|
|
32
|
+
});
|
|
33
|
+
await waitFor(() => {
|
|
34
|
+
expect(rendered.getByText('Success 1')).toBeInTheDocument();
|
|
35
|
+
expect(rendered.getByText('Success 2')).toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQuery.test.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/createQuery.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, waitFor } from '@testing-library/svelte';
|
|
3
|
+
import { writable } from 'svelte/store';
|
|
4
|
+
import CreateQuery from './CreateQuery.svelte';
|
|
5
|
+
import { sleep } from './utils';
|
|
6
|
+
describe('createQuery', () => {
|
|
7
|
+
it('Render and wait for success', async () => {
|
|
8
|
+
const rendered = render(CreateQuery, {
|
|
9
|
+
props: {
|
|
10
|
+
options: {
|
|
11
|
+
queryKey: ['test'],
|
|
12
|
+
queryFn: async () => {
|
|
13
|
+
await sleep(10);
|
|
14
|
+
return 'Success';
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
await waitFor(() => {
|
|
20
|
+
expect(rendered.getByText('Loading')).toBeInTheDocument();
|
|
21
|
+
});
|
|
22
|
+
await waitFor(() => {
|
|
23
|
+
expect(rendered.getByText('Success')).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
it('should keep previous data when returned as placeholder data', async () => {
|
|
27
|
+
const options = writable({
|
|
28
|
+
queryKey: ['test', [1]],
|
|
29
|
+
queryFn: async ({ queryKey }) => {
|
|
30
|
+
await sleep(10);
|
|
31
|
+
const ids = queryKey[1];
|
|
32
|
+
if (!ids || !Array.isArray(ids))
|
|
33
|
+
return [];
|
|
34
|
+
return ids.map((id) => ({ id }));
|
|
35
|
+
},
|
|
36
|
+
placeholderData: (previousData) => previousData,
|
|
37
|
+
});
|
|
38
|
+
const rendered = render(CreateQuery, { props: { options } });
|
|
39
|
+
await waitFor(() => {
|
|
40
|
+
expect(rendered.queryByText('id: 1')).not.toBeInTheDocument();
|
|
41
|
+
expect(rendered.queryByText('id: 2')).not.toBeInTheDocument();
|
|
42
|
+
});
|
|
43
|
+
await waitFor(() => {
|
|
44
|
+
expect(rendered.queryByText('id: 1')).toBeInTheDocument();
|
|
45
|
+
expect(rendered.queryByText('id: 2')).not.toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
options.update((o) => ({ ...o, queryKey: ['test', [1, 2]] }));
|
|
48
|
+
await waitFor(() => {
|
|
49
|
+
expect(rendered.queryByText('id: 1')).toBeInTheDocument();
|
|
50
|
+
expect(rendered.queryByText('id: 2')).not.toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
await waitFor(() => {
|
|
53
|
+
expect(rendered.queryByText('id: 1')).toBeInTheDocument();
|
|
54
|
+
expect(rendered.queryByText('id: 2')).toBeInTheDocument();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { QueryClient, type QueryClientConfig } from '../index';
|
|
3
|
+
export declare function createQueryClient(config?: QueryClientConfig): QueryClient;
|
|
4
|
+
export declare function mockVisibilityState(value: DocumentVisibilityState): import("vitest/dist/index-2dd51af4").S<[], DocumentVisibilityState>;
|
|
5
|
+
export declare function mockNavigatorOnLine(value: boolean): import("vitest/dist/index-2dd51af4").S<[], boolean>;
|
|
6
|
+
export declare function queryKey(): Array<string>;
|
|
7
|
+
export declare function sleep(timeout: number): Promise<void>;
|
|
8
|
+
export declare function simplefetcher(): Promise<string>;
|
|
9
|
+
export declare function setActTimeout(fn: () => void, ms?: number): NodeJS.Timeout;
|
|
10
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/utils.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAE9D,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,WAAW,CAEzE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,uBAAuB,uEAEjE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,uDAEjD;AAGD,wBAAgB,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,CAGxC;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpD;AAED,wBAAsB,aAAa,oBAGlC;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,EAAE,CAAC,EAAE,MAAM,kBAMxD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import { act } from '@testing-library/svelte';
|
|
3
|
+
import { QueryClient } from '../index';
|
|
4
|
+
export function createQueryClient(config) {
|
|
5
|
+
return new QueryClient(config);
|
|
6
|
+
}
|
|
7
|
+
export function mockVisibilityState(value) {
|
|
8
|
+
return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value);
|
|
9
|
+
}
|
|
10
|
+
export function mockNavigatorOnLine(value) {
|
|
11
|
+
return vi.spyOn(navigator, 'onLine', 'get').mockReturnValue(value);
|
|
12
|
+
}
|
|
13
|
+
let queryKeyCount = 0;
|
|
14
|
+
export function queryKey() {
|
|
15
|
+
queryKeyCount++;
|
|
16
|
+
return [`query_${queryKeyCount}`];
|
|
17
|
+
}
|
|
18
|
+
export function sleep(timeout) {
|
|
19
|
+
return new Promise((resolve, _reject) => {
|
|
20
|
+
setTimeout(resolve, timeout);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export async function simplefetcher() {
|
|
24
|
+
await sleep(10);
|
|
25
|
+
return 'test';
|
|
26
|
+
}
|
|
27
|
+
export function setActTimeout(fn, ms) {
|
|
28
|
+
return setTimeout(() => {
|
|
29
|
+
act(() => {
|
|
30
|
+
fn();
|
|
31
|
+
});
|
|
32
|
+
}, ms);
|
|
33
|
+
}
|
package/build/lib/context.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ import type { QueryClient } from '@tanstack/query-core';
|
|
|
3
3
|
export declare const getQueryClientContext: () => QueryClient;
|
|
4
4
|
/** Sets a QueryClient on Svelte's context */
|
|
5
5
|
export declare const setQueryClientContext: (client: QueryClient) => void;
|
|
6
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAIvD,+CAA+C;AAC/C,eAAO,MAAM,qBAAqB,QAAO,WASxC,CAAA;AAED,6CAA6C;AAC7C,eAAO,MAAM,qBAAqB,WAAY,WAAW,KAAG,IAE3D,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core';
|
|
2
|
-
import type { CreateBaseQueryOptions, CreateBaseQueryResult
|
|
3
|
-
export declare function createBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options:
|
|
2
|
+
import type { CreateBaseQueryOptions, CreateBaseQueryResult } from './types';
|
|
3
|
+
export declare function createBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options: CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, Observer: typeof QueryObserver, queryClient?: QueryClient): CreateBaseQueryResult<TData, TError>;
|
|
4
|
+
//# sourceMappingURL=createBaseQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBaseQuery.d.ts","sourceRoot":"","sources":["../../../src/createBaseQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAI5E,wBAAgB,eAAe,CAC7B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,SAAS,QAAQ,EAE1B,OAAO,EAAE,sBAAsB,CAC7B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,CACV,EACD,QAAQ,EAAE,OAAO,aAAa,EAC9B,WAAW,CAAC,EAAE,WAAW,GACxB,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,CAsCtC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { derived, get, readable, writable } from 'svelte/store';
|
|
1
2
|
import { notifyManager } from '@tanstack/query-core';
|
|
2
3
|
import { useQueryClient } from './useQueryClient';
|
|
3
|
-
import { derived, get, readable, writable } from 'svelte/store';
|
|
4
4
|
import { isWritable } from './utils';
|
|
5
5
|
export function createBaseQuery(options, Observer, queryClient) {
|
|
6
6
|
const client = useQueryClient(queryClient);
|
|
@@ -8,16 +8,6 @@ export function createBaseQuery(options, Observer, queryClient) {
|
|
|
8
8
|
const defaultedOptionsStore = derived(optionsStore, ($options) => {
|
|
9
9
|
const defaultedOptions = client.defaultQueryOptions($options);
|
|
10
10
|
defaultedOptions._optimisticResults = 'optimistic';
|
|
11
|
-
// Include callbacks in batch renders
|
|
12
|
-
if (defaultedOptions.onError) {
|
|
13
|
-
defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
|
|
14
|
-
}
|
|
15
|
-
if (defaultedOptions.onSuccess) {
|
|
16
|
-
defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
|
|
17
|
-
}
|
|
18
|
-
if (defaultedOptions.onSettled) {
|
|
19
|
-
defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
|
|
20
|
-
}
|
|
21
11
|
return defaultedOptions;
|
|
22
12
|
});
|
|
23
13
|
const observer = new Observer(client, get(defaultedOptionsStore));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { QueryKey, QueryClient, DefaultError, InfiniteData } from '@tanstack/query-core';
|
|
2
|
-
import type { CreateInfiniteQueryOptions, CreateInfiniteQueryResult
|
|
3
|
-
export declare function createInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options:
|
|
2
|
+
import type { CreateInfiniteQueryOptions, CreateInfiniteQueryResult } from './types';
|
|
3
|
+
export declare function createInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, TPageParam>, queryClient?: QueryClient): CreateInfiniteQueryResult<TData, TError>;
|
|
4
|
+
//# sourceMappingURL=createInfiniteQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createInfiniteQuery.d.ts","sourceRoot":"","sources":["../../../src/createInfiniteQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EACV,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,SAAS,CAAA;AAGhB,wBAAgB,mBAAmB,CACjC,YAAY,EACZ,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,CAAC,YAAY,CAAC,EAClC,SAAS,SAAS,QAAQ,GAAG,QAAQ,EACrC,UAAU,GAAG,OAAO,EAEpB,OAAO,EAAE,0BAA0B,CACjC,YAAY,EACZ,MAAM,EACN,KAAK,EACL,YAAY,EACZ,SAAS,EACT,UAAU,CACX,EACD,WAAW,CAAC,EAAE,WAAW,GACxB,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,CAO1C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { QueryClient, DefaultError } from '@tanstack/query-core';
|
|
2
|
-
import type { CreateMutationOptions, CreateMutationResult
|
|
3
|
-
export declare function createMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options:
|
|
2
|
+
import type { CreateMutationOptions, CreateMutationResult } from './types';
|
|
3
|
+
export declare function createMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: CreateMutationOptions<TData, TError, TVariables, TContext>, queryClient?: QueryClient): CreateMutationResult<TData, TError, TVariables, TContext>;
|
|
4
|
+
//# sourceMappingURL=createMutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMutation.d.ts","sourceRoot":"","sources":["../../../src/createMutation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAErE,OAAO,KAAK,EAEV,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,SAAS,CAAA;AAIhB,wBAAgB,cAAc,CAC5B,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,YAAY,EACrB,UAAU,GAAG,IAAI,EACjB,QAAQ,GAAG,OAAO,EAElB,OAAO,EAAE,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EACnE,WAAW,CAAC,EAAE,WAAW,GACxB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CA6B3D"}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import type { QueryKey, QueryFunction, QueryClient, QueriesPlaceholderDataFunction, QueryObserverResult, DefaultError } from '@tanstack/query-core';
|
|
1
|
+
import type { QueryKey, QueryFunction, QueryClient, QueriesPlaceholderDataFunction, QueryObserverResult, DefaultError, QueryObserverOptions } from '@tanstack/query-core';
|
|
2
2
|
import { type Readable } from 'svelte/store';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type { WritableOrVal } from './types';
|
|
4
|
+
type QueryObserverOptionsForCreateQueries<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'placeholderData'> & {
|
|
5
5
|
placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
type MAXIMUM_DEPTH = 20;
|
|
8
|
+
type GetOptions<T> = T extends {
|
|
9
9
|
queryFnData: infer TQueryFnData;
|
|
10
10
|
error?: infer TError;
|
|
11
11
|
data: infer TData;
|
|
12
|
-
} ?
|
|
12
|
+
} ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData> : T extends {
|
|
13
13
|
queryFnData: infer TQueryFnData;
|
|
14
14
|
error?: infer TError;
|
|
15
|
-
} ?
|
|
15
|
+
} ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError> : T extends {
|
|
16
16
|
data: infer TData;
|
|
17
17
|
error?: infer TError;
|
|
18
|
-
} ?
|
|
18
|
+
} ? QueryObserverOptionsForCreateQueries<unknown, TError, TData> : T extends [infer TQueryFnData, infer TError, infer TData] ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData> : T extends [infer TQueryFnData, infer TError] ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError> : T extends [infer TQueryFnData] ? QueryObserverOptionsForCreateQueries<TQueryFnData> : T extends {
|
|
19
19
|
queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey>;
|
|
20
20
|
select: (data: any) => infer TData;
|
|
21
|
-
} ?
|
|
21
|
+
} ? QueryObserverOptionsForCreateQueries<TQueryFnData, Error, TData, TQueryKey> : T extends {
|
|
22
22
|
queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey>;
|
|
23
|
-
} ?
|
|
24
|
-
|
|
23
|
+
} ? QueryObserverOptionsForCreateQueries<TQueryFnData, Error, TQueryFnData, TQueryKey> : QueryObserverOptionsForCreateQueries;
|
|
24
|
+
type GetResults<T> = T extends {
|
|
25
25
|
queryFnData: any;
|
|
26
26
|
error?: infer TError;
|
|
27
27
|
data: infer TData;
|
|
@@ -40,13 +40,14 @@ declare type GetResults<T> = T extends {
|
|
|
40
40
|
/**
|
|
41
41
|
* QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
|
|
42
42
|
*/
|
|
43
|
-
export
|
|
43
|
+
export type QueriesOptions<T extends any[], Result extends any[] = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? QueryObserverOptionsForCreateQueries[] : T extends [] ? [] : T extends [infer Head] ? [...Result, GetOptions<Head>] : T extends [infer Head, ...infer Tail] ? QueriesOptions<[...Tail], [...Result, GetOptions<Head>], [...Depth, 1]> : unknown[] extends T ? T : T extends QueryObserverOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>[] ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData, TQueryKey>[] : QueryObserverOptionsForCreateQueries[];
|
|
44
44
|
/**
|
|
45
45
|
* QueriesResults reducer recursively maps type param to results
|
|
46
46
|
*/
|
|
47
|
-
export
|
|
48
|
-
export declare
|
|
49
|
-
export declare function createQueries<T extends any[]>({ queries, }: {
|
|
47
|
+
export type QueriesResults<T extends any[], Result extends any[] = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? QueryObserverResult[] : T extends [] ? [] : T extends [infer Head] ? [...Result, GetResults<Head>] : T extends [infer Head, ...infer Tail] ? QueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]> : T extends QueryObserverOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, any>[] ? QueryObserverResult<unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError>[] : QueryObserverResult[];
|
|
48
|
+
export declare function createQueries<T extends any[], TCombinedResult = QueriesResults<T>>({ queries, ...options }: {
|
|
50
49
|
queries: WritableOrVal<[...QueriesOptions<T>]>;
|
|
51
|
-
|
|
50
|
+
combine?: (result: QueriesResults<T>) => TCombinedResult;
|
|
51
|
+
}, queryClient?: QueryClient): Readable<TCombinedResult>;
|
|
52
52
|
export {};
|
|
53
|
+
//# sourceMappingURL=createQueries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQue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AG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,eAAe,CAAA;CACzD,EACD,WAAW,CAAC,EAAE,WAAW,GACxB,QAAQ,CAAC,eAAe,CAAC,CAwC3B"}
|
|
@@ -2,25 +2,26 @@ import { notifyManager, QueriesObserver } from '@tanstack/query-core';
|
|
|
2
2
|
import { derived, get, readable, writable } from 'svelte/store';
|
|
3
3
|
import { useQueryClient } from './useQueryClient';
|
|
4
4
|
import { isWritable } from './utils';
|
|
5
|
-
export function createQueries({ queries, }, queryClient) {
|
|
5
|
+
export function createQueries({ queries, ...options }, queryClient) {
|
|
6
6
|
const client = useQueryClient(queryClient);
|
|
7
7
|
// const isRestoring = useIsRestoring()
|
|
8
8
|
const queriesStore = isWritable(queries) ? queries : writable(queries);
|
|
9
9
|
const defaultedQueriesStore = derived(queriesStore, ($queries) => {
|
|
10
|
-
return $queries.map((
|
|
11
|
-
const defaultedOptions = client.defaultQueryOptions(
|
|
10
|
+
return $queries.map((opts) => {
|
|
11
|
+
const defaultedOptions = client.defaultQueryOptions(opts);
|
|
12
12
|
// Make sure the results are already in fetching state before subscribing or updating options
|
|
13
13
|
defaultedOptions._optimisticResults = 'optimistic';
|
|
14
14
|
return defaultedOptions;
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
-
const observer = new QueriesObserver(client, get(defaultedQueriesStore));
|
|
17
|
+
const observer = new QueriesObserver(client, get(defaultedQueriesStore), options);
|
|
18
18
|
defaultedQueriesStore.subscribe(($defaultedQueries) => {
|
|
19
19
|
// Do not notify on updates because of changes in the options because
|
|
20
20
|
// these changes should already be reflected in the optimistic result.
|
|
21
|
-
observer.setQueries($defaultedQueries, { listeners: false });
|
|
21
|
+
observer.setQueries($defaultedQueries, options, { listeners: false });
|
|
22
22
|
});
|
|
23
|
-
const
|
|
23
|
+
const [, getCombinedResult] = observer.getOptimisticResult(get(defaultedQueriesStore));
|
|
24
|
+
const { subscribe } = readable(getCombinedResult(), (set) => {
|
|
24
25
|
return observer.subscribe(notifyManager.batchCalls(set));
|
|
25
26
|
});
|
|
26
27
|
return { subscribe };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { QueryKey, QueryClient, DefaultError } from '@tanstack/query-core';
|
|
2
|
-
import type { DefinedCreateQueryResult, CreateQueryOptions, CreateQueryResult
|
|
3
|
-
|
|
2
|
+
import type { DefinedCreateQueryResult, CreateQueryOptions, CreateQueryResult } from './types';
|
|
3
|
+
type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
4
4
|
initialData?: undefined;
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
7
7
|
initialData: TQueryFnData | (() => TQueryFnData);
|
|
8
8
|
};
|
|
9
|
-
export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options:
|
|
10
|
-
export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options:
|
|
9
|
+
export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): CreateQueryResult<TData, TError>;
|
|
10
|
+
export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): DefinedCreateQueryResult<TData, TError>;
|
|
11
11
|
export {};
|
|
12
|
+
//# sourceMappingURL=createQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQuery.d.ts","sourceRoot":"","sources":["../../../src/createQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAE/E,OAAO,KAAK,EACV,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAEhB,KAAK,2BAA2B,CAC9B,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,IACnC,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,GAAG;IAC/D,WAAW,CAAC,EAAE,SAAS,CAAA;CACxB,CAAA;AAED,KAAK,yBAAyB,CAC5B,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,IACnC,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,GAAG;IAC/D,WAAW,EAAE,YAAY,GAAG,CAAC,MAAM,YAAY,CAAC,CAAA;CACjD,CAAA;AAED,wBAAgB,WAAW,CACzB,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,OAAO,EAAE,2BAA2B,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAC5E,WAAW,CAAC,EAAE,WAAW,GACxB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AAEnC,wBAAgB,WAAW,CACzB,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,OAAO,EAAE,yBAAyB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAC1E,WAAW,CAAC,EAAE,WAAW,GACxB,wBAAwB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA"}
|
package/build/lib/index.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export { useIsMutating } from './useIsMutating';
|
|
|
10
10
|
export { useHydrate } from './useHydrate';
|
|
11
11
|
export { default as HydrationBoundary } from './HydrationBoundary.svelte';
|
|
12
12
|
export { default as QueryClientProvider } from './QueryClientProvider.svelte';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,sBAAsB,CAAA;AAGpC,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACzE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,8BAA8B,CAAA"}
|