@zenstackhq/tanstack-query 3.0.0-beta.17 → 3.0.0-beta.18
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/.turbo/turbo-build.log +27 -13
- package/dist/react.cjs +35 -33
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +26 -106
- package/dist/react.d.ts +26 -106
- package/dist/react.js +35 -33
- package/dist/react.js.map +1 -1
- package/dist/svelte.cjs +1224 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +381 -0
- package/dist/svelte.d.ts +381 -0
- package/dist/svelte.js +1183 -0
- package/dist/svelte.js.map +1 -0
- package/dist/types-BRIDXxNC.d.cts +92 -0
- package/dist/types-BRIDXxNC.d.ts +92 -0
- package/dist/vue.cjs +1192 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +382 -0
- package/dist/vue.d.ts +382 -0
- package/dist/vue.js +1152 -0
- package/dist/vue.js.map +1 -0
- package/package.json +43 -11
- package/src/react.ts +168 -155
- package/src/svelte.ts +483 -0
- package/src/utils/common.ts +4 -13
- package/src/utils/types.ts +13 -0
- package/src/vue.ts +429 -0
- package/test/react-typing-test.ts +109 -0
- package/test/schemas/basic/input.ts +40 -0
- package/test/schemas/basic/models.ts +2 -0
- package/test/schemas/basic/schema-lite.ts +48 -0
- package/test/schemas/basic/schema.zmodel +11 -1
- package/test/svelte-typing-test.ts +106 -0
- package/test/vue-typing-test.ts +107 -0
- package/tsup.config.ts +2 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { get } from 'svelte/store';
|
|
2
|
+
import { useClientQueries } from '../src/svelte';
|
|
3
|
+
import { schema } from './schemas/basic/schema-lite';
|
|
4
|
+
|
|
5
|
+
const client = useClientQueries(schema);
|
|
6
|
+
|
|
7
|
+
// @ts-expect-error missing args
|
|
8
|
+
client.user.useFindUnique();
|
|
9
|
+
|
|
10
|
+
check(get(client.user.useFindUnique({ where: { id: '1' } })).data?.email);
|
|
11
|
+
check(get(client.user.useFindUnique({ where: { id: '1' } })).queryKey);
|
|
12
|
+
check(get(client.user.useFindUnique({ where: { id: '1' } }, { optimisticUpdate: true, enabled: false })));
|
|
13
|
+
|
|
14
|
+
// @ts-expect-error unselected field
|
|
15
|
+
check(get(client.user.useFindUnique({ select: { email: true } })).data.name);
|
|
16
|
+
|
|
17
|
+
check(get(client.user.useFindUnique({ where: { id: '1' }, include: { posts: true } })).data?.posts[0]?.title);
|
|
18
|
+
|
|
19
|
+
check(get(client.user.useFindFirst()).data?.email);
|
|
20
|
+
|
|
21
|
+
check(get(client.user.useFindMany()).data?.[0]?.email);
|
|
22
|
+
check(get(client.user.useInfiniteFindMany()).data?.pages[0]?.[0]?.email);
|
|
23
|
+
check(
|
|
24
|
+
get(
|
|
25
|
+
client.user.useInfiniteFindMany(
|
|
26
|
+
{},
|
|
27
|
+
{
|
|
28
|
+
getNextPageParam: () => ({ id: '2' }),
|
|
29
|
+
},
|
|
30
|
+
),
|
|
31
|
+
).data?.pages[1]?.[0]?.email,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
check(get(client.user.useCount()).data?.toFixed(2));
|
|
35
|
+
check(get(client.user.useCount({ select: { email: true } })).data?.email.toFixed(2));
|
|
36
|
+
|
|
37
|
+
check(get(client.user.useAggregate({ _max: { email: true } })).data?._max.email);
|
|
38
|
+
|
|
39
|
+
check(get(client.user.useGroupBy({ by: ['email'], _max: { name: true } })).data?.[0]?._max.name);
|
|
40
|
+
|
|
41
|
+
// @ts-expect-error missing args
|
|
42
|
+
client.user.useCreate().mutate();
|
|
43
|
+
get(client.user.useCreate()).mutate({ data: { email: 'test@example.com' } });
|
|
44
|
+
get(client.user.useCreate({ optimisticUpdate: true, invalidateQueries: false, retry: 3 })).mutate({
|
|
45
|
+
data: { email: 'test@example.com' },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
get(client.user.useCreate())
|
|
49
|
+
.mutateAsync({ data: { email: 'test@example.com' }, include: { posts: true } })
|
|
50
|
+
.then((d) => check(d.posts[0]?.title));
|
|
51
|
+
|
|
52
|
+
get(client.user.useCreateMany())
|
|
53
|
+
.mutateAsync({
|
|
54
|
+
data: [{ email: 'test@example.com' }, { email: 'test2@example.com' }],
|
|
55
|
+
skipDuplicates: true,
|
|
56
|
+
})
|
|
57
|
+
.then((d) => d.count);
|
|
58
|
+
|
|
59
|
+
get(client.user.useCreateManyAndReturn())
|
|
60
|
+
.mutateAsync({
|
|
61
|
+
data: [{ email: 'test@example.com' }],
|
|
62
|
+
})
|
|
63
|
+
.then((d) => check(d[0]?.name));
|
|
64
|
+
|
|
65
|
+
get(client.user.useCreateManyAndReturn())
|
|
66
|
+
.mutateAsync({
|
|
67
|
+
data: [{ email: 'test@example.com' }],
|
|
68
|
+
select: { email: true },
|
|
69
|
+
})
|
|
70
|
+
// @ts-expect-error unselected field
|
|
71
|
+
.then((d) => check(d[0].name));
|
|
72
|
+
|
|
73
|
+
get(client.user.useUpdate()).mutate(
|
|
74
|
+
{ data: { email: 'updated@example.com' }, where: { id: '1' } },
|
|
75
|
+
{
|
|
76
|
+
onSuccess: (d) => {
|
|
77
|
+
check(d.email);
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
get(client.user.useUpdateMany()).mutate({ data: { email: 'updated@example.com' } });
|
|
83
|
+
|
|
84
|
+
get(client.user.useUpdateManyAndReturn())
|
|
85
|
+
.mutateAsync({ data: { email: 'updated@example.com' } })
|
|
86
|
+
.then((d) => check(d[0]?.email));
|
|
87
|
+
|
|
88
|
+
get(client.user.useUpsert()).mutate({
|
|
89
|
+
where: { id: '1' },
|
|
90
|
+
create: { email: 'new@example.com' },
|
|
91
|
+
update: { email: 'updated@example.com' },
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
get(client.user.useDelete()).mutate({ where: { id: '1' }, include: { posts: true } });
|
|
95
|
+
|
|
96
|
+
get(client.user.useDeleteMany()).mutate({ where: { email: 'test@example.com' } });
|
|
97
|
+
|
|
98
|
+
function check(_value: unknown) {
|
|
99
|
+
// noop
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// @ts-expect-error delegate model
|
|
103
|
+
client.foo.useCreate();
|
|
104
|
+
|
|
105
|
+
client.foo.useUpdate();
|
|
106
|
+
client.bar.useCreate();
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { useClientQueries } from '../src/vue';
|
|
2
|
+
import { schema } from './schemas/basic/schema-lite';
|
|
3
|
+
|
|
4
|
+
const client = useClientQueries(schema);
|
|
5
|
+
|
|
6
|
+
// @ts-expect-error missing args
|
|
7
|
+
client.user.useFindUnique();
|
|
8
|
+
|
|
9
|
+
check(client.user.useFindUnique({ where: { id: '1' } }).data.value?.email);
|
|
10
|
+
check(client.user.useFindUnique({ where: { id: '1' } }).queryKey);
|
|
11
|
+
check(client.user.useFindUnique({ where: { id: '1' } }, { optimisticUpdate: true, enabled: false }));
|
|
12
|
+
|
|
13
|
+
// @ts-expect-error unselected field
|
|
14
|
+
check(client.user.useFindUnique({ select: { email: true } }).data.name);
|
|
15
|
+
|
|
16
|
+
check(client.user.useFindUnique({ where: { id: '1' }, include: { posts: true } }).data.value?.posts[0]?.title);
|
|
17
|
+
|
|
18
|
+
check(client.user.useFindFirst().data.value?.email);
|
|
19
|
+
|
|
20
|
+
check(client.user.useFindMany().data.value?.[0]?.email);
|
|
21
|
+
|
|
22
|
+
check(client.user.useInfiniteFindMany().data.value?.pages[0]?.[0]?.email);
|
|
23
|
+
check(
|
|
24
|
+
client.user.useInfiniteFindMany(
|
|
25
|
+
{},
|
|
26
|
+
{
|
|
27
|
+
getNextPageParam: () => ({ id: '2' }),
|
|
28
|
+
},
|
|
29
|
+
).data.value?.pages[1]?.[0]?.email,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
check(client.user.useCount().data.value?.toFixed(2));
|
|
33
|
+
check(client.user.useCount({ select: { email: true } }).data.value?.email.toFixed(2));
|
|
34
|
+
|
|
35
|
+
check(client.user.useAggregate({ _max: { email: true } }).data.value?._max.email);
|
|
36
|
+
|
|
37
|
+
check(client.user.useGroupBy({ by: ['email'], _max: { name: true } }).data.value?.[0]?._max.name);
|
|
38
|
+
|
|
39
|
+
// @ts-expect-error missing args
|
|
40
|
+
client.user.useCreate().mutate();
|
|
41
|
+
client.user.useCreate().mutate({ data: { email: 'test@example.com' } });
|
|
42
|
+
client.user
|
|
43
|
+
.useCreate({ optimisticUpdate: true, invalidateQueries: false, retry: 3 })
|
|
44
|
+
.mutate({ data: { email: 'test@example.com' } });
|
|
45
|
+
|
|
46
|
+
client.user
|
|
47
|
+
.useCreate()
|
|
48
|
+
.mutateAsync({ data: { email: 'test@example.com' }, include: { posts: true } })
|
|
49
|
+
.then((d) => check(d.posts[0]?.title));
|
|
50
|
+
|
|
51
|
+
client.user
|
|
52
|
+
.useCreateMany()
|
|
53
|
+
.mutateAsync({
|
|
54
|
+
data: [{ email: 'test@example.com' }, { email: 'test2@example.com' }],
|
|
55
|
+
skipDuplicates: true,
|
|
56
|
+
})
|
|
57
|
+
.then((d) => d.count);
|
|
58
|
+
|
|
59
|
+
client.user
|
|
60
|
+
.useCreateManyAndReturn()
|
|
61
|
+
.mutateAsync({
|
|
62
|
+
data: [{ email: 'test@example.com' }],
|
|
63
|
+
})
|
|
64
|
+
.then((d) => check(d[0]?.name));
|
|
65
|
+
|
|
66
|
+
client.user
|
|
67
|
+
.useCreateManyAndReturn()
|
|
68
|
+
.mutateAsync({
|
|
69
|
+
data: [{ email: 'test@example.com' }],
|
|
70
|
+
select: { email: true },
|
|
71
|
+
})
|
|
72
|
+
// @ts-expect-error unselected field
|
|
73
|
+
.then((d) => check(d[0].name));
|
|
74
|
+
|
|
75
|
+
client.user.useUpdate().mutate(
|
|
76
|
+
{ data: { email: 'updated@example.com' }, where: { id: '1' } },
|
|
77
|
+
{
|
|
78
|
+
onSuccess: (d) => {
|
|
79
|
+
check(d.email);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
client.user.useUpdateMany().mutate({ data: { email: 'updated@example.com' } });
|
|
85
|
+
|
|
86
|
+
client.user
|
|
87
|
+
.useUpdateManyAndReturn()
|
|
88
|
+
.mutateAsync({ data: { email: 'updated@example.com' } })
|
|
89
|
+
.then((d) => check(d[0]?.email));
|
|
90
|
+
|
|
91
|
+
client.user
|
|
92
|
+
.useUpsert()
|
|
93
|
+
.mutate({ where: { id: '1' }, create: { email: 'new@example.com' }, update: { email: 'updated@example.com' } });
|
|
94
|
+
|
|
95
|
+
client.user.useDelete().mutate({ where: { id: '1' }, include: { posts: true } });
|
|
96
|
+
|
|
97
|
+
client.user.useDeleteMany().mutate({ where: { email: 'test@example.com' } });
|
|
98
|
+
|
|
99
|
+
function check(_value: unknown) {
|
|
100
|
+
// noop
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// @ts-expect-error delegate model
|
|
104
|
+
client.foo.useCreate();
|
|
105
|
+
|
|
106
|
+
client.foo.useUpdate();
|
|
107
|
+
client.bar.useCreate();
|