@zenstackhq/tanstack-query 3.0.0 → 3.1.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/dist/common/client.d.ts +4 -0
- package/dist/common/client.js +38 -0
- package/dist/common/client.js.map +1 -0
- package/dist/common/query-key.d.ts +39 -0
- package/dist/common/query-key.js +38 -0
- package/dist/common/query-key.js.map +1 -0
- package/dist/common/types.d.ts +60 -0
- package/dist/common/types.js +2 -0
- package/dist/common/types.js.map +1 -0
- package/dist/react.d.ts +99 -150
- package/dist/react.js +248 -1178
- package/dist/react.js.map +1 -1
- package/dist/svelte/index.svelte.d.ts +79 -0
- package/dist/svelte/index.svelte.js +245 -0
- package/dist/vue.d.ts +313 -342
- package/dist/vue.js +224 -1138
- package/dist/vue.js.map +1 -1
- package/package.json +36 -48
- package/.turbo/turbo-build.log +0 -47
- package/dist/react.cjs +0 -1240
- package/dist/react.cjs.map +0 -1
- package/dist/react.d.cts +0 -616
- package/dist/svelte.cjs +0 -1224
- package/dist/svelte.cjs.map +0 -1
- package/dist/svelte.d.cts +0 -381
- package/dist/svelte.d.ts +0 -381
- package/dist/svelte.js +0 -1183
- package/dist/svelte.js.map +0 -1
- package/dist/types-C8iIZD-7.d.cts +0 -99
- package/dist/types-C8iIZD-7.d.ts +0 -99
- package/dist/vue.cjs +0 -1192
- package/dist/vue.cjs.map +0 -1
- package/dist/vue.d.cts +0 -382
- package/eslint.config.js +0 -4
- package/src/react.ts +0 -562
- package/src/svelte.ts +0 -502
- package/src/utils/common.ts +0 -448
- package/src/utils/mutator.ts +0 -441
- package/src/utils/nested-read-visitor.ts +0 -61
- package/src/utils/nested-write-visitor.ts +0 -359
- package/src/utils/query-analysis.ts +0 -116
- package/src/utils/serialization.ts +0 -39
- package/src/utils/types.ts +0 -43
- package/src/vue.ts +0 -448
- package/test/react-query.test.tsx +0 -1787
- package/test/react-typing-test.ts +0 -113
- package/test/schemas/basic/input.ts +0 -110
- package/test/schemas/basic/models.ts +0 -14
- package/test/schemas/basic/schema-lite.ts +0 -172
- package/test/schemas/basic/schema.zmodel +0 -35
- package/test/svelte-typing-test.ts +0 -111
- package/test/vue-typing-test.ts +0 -111
- package/tsconfig.json +0 -7
- package/tsconfig.test.json +0 -8
- package/tsup.config.ts +0 -15
- package/vitest.config.ts +0 -11
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { useClientQueries } from '../src/react';
|
|
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?.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?.posts[0]?.title);
|
|
17
|
-
|
|
18
|
-
check(client.user.useFindFirst().data?.email);
|
|
19
|
-
check(client.user.useFindFirst().data?.$optimistic);
|
|
20
|
-
|
|
21
|
-
check(client.user.useFindMany().data?.[0]?.email);
|
|
22
|
-
check(client.user.useFindMany().data?.[0]?.$optimistic);
|
|
23
|
-
|
|
24
|
-
check(client.user.useInfiniteFindMany().data?.pages[0]?.[0]?.email);
|
|
25
|
-
check(
|
|
26
|
-
client.user.useInfiniteFindMany(
|
|
27
|
-
{},
|
|
28
|
-
{
|
|
29
|
-
getNextPageParam: () => ({ id: '2' }),
|
|
30
|
-
},
|
|
31
|
-
).data?.pages[1]?.[0]?.email,
|
|
32
|
-
);
|
|
33
|
-
// @ts-expect-error
|
|
34
|
-
check(client.user.useInfiniteFindMany().data?.pages[0]?.[0]?.$optimistic);
|
|
35
|
-
|
|
36
|
-
check(client.user.useSuspenseFindMany().data[0]?.email);
|
|
37
|
-
check(client.user.useSuspenseInfiniteFindMany().data.pages[0]?.[0]?.email);
|
|
38
|
-
check(client.user.useCount().data?.toFixed(2));
|
|
39
|
-
check(client.user.useCount({ select: { email: true } }).data?.email.toFixed(2));
|
|
40
|
-
|
|
41
|
-
check(client.user.useAggregate({ _max: { email: true } }).data?._max.email);
|
|
42
|
-
|
|
43
|
-
check(client.user.useGroupBy({ by: ['email'], _max: { name: true } }).data?.[0]?._max.name);
|
|
44
|
-
|
|
45
|
-
// @ts-expect-error missing args
|
|
46
|
-
client.user.useCreate().mutate();
|
|
47
|
-
client.user.useCreate().mutate({ data: { email: 'test@example.com' } });
|
|
48
|
-
client.user
|
|
49
|
-
.useCreate({ optimisticUpdate: true, invalidateQueries: false, retry: 3 })
|
|
50
|
-
.mutate({ data: { email: 'test@example.com' } });
|
|
51
|
-
|
|
52
|
-
client.user
|
|
53
|
-
.useCreate()
|
|
54
|
-
.mutateAsync({ data: { email: 'test@example.com' }, include: { posts: true } })
|
|
55
|
-
.then((d) => check(d.posts[0]?.title));
|
|
56
|
-
|
|
57
|
-
client.user
|
|
58
|
-
.useCreateMany()
|
|
59
|
-
.mutateAsync({
|
|
60
|
-
data: [{ email: 'test@example.com' }, { email: 'test2@example.com' }],
|
|
61
|
-
skipDuplicates: true,
|
|
62
|
-
})
|
|
63
|
-
.then((d) => d.count);
|
|
64
|
-
|
|
65
|
-
client.user
|
|
66
|
-
.useCreateManyAndReturn()
|
|
67
|
-
.mutateAsync({
|
|
68
|
-
data: [{ email: 'test@example.com' }],
|
|
69
|
-
})
|
|
70
|
-
.then((d) => check(d[0]?.name));
|
|
71
|
-
|
|
72
|
-
client.user
|
|
73
|
-
.useCreateManyAndReturn()
|
|
74
|
-
.mutateAsync({
|
|
75
|
-
data: [{ email: 'test@example.com' }],
|
|
76
|
-
select: { email: true },
|
|
77
|
-
})
|
|
78
|
-
// @ts-expect-error unselected field
|
|
79
|
-
.then((d) => check(d[0].name));
|
|
80
|
-
|
|
81
|
-
client.user.useUpdate().mutate(
|
|
82
|
-
{ data: { email: 'updated@example.com' }, where: { id: '1' } },
|
|
83
|
-
{
|
|
84
|
-
onSuccess: (d) => {
|
|
85
|
-
check(d.email);
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
client.user.useUpdateMany().mutate({ data: { email: 'updated@example.com' } });
|
|
91
|
-
|
|
92
|
-
client.user
|
|
93
|
-
.useUpdateManyAndReturn()
|
|
94
|
-
.mutateAsync({ data: { email: 'updated@example.com' } })
|
|
95
|
-
.then((d) => check(d[0]?.email));
|
|
96
|
-
|
|
97
|
-
client.user
|
|
98
|
-
.useUpsert()
|
|
99
|
-
.mutate({ where: { id: '1' }, create: { email: 'new@example.com' }, update: { email: 'updated@example.com' } });
|
|
100
|
-
|
|
101
|
-
client.user.useDelete().mutate({ where: { id: '1' }, include: { posts: true } });
|
|
102
|
-
|
|
103
|
-
client.user.useDeleteMany().mutate({ where: { email: 'test@example.com' } });
|
|
104
|
-
|
|
105
|
-
function check(_value: unknown) {
|
|
106
|
-
// noop
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// @ts-expect-error delegate model
|
|
110
|
-
client.foo.useCreate();
|
|
111
|
-
|
|
112
|
-
client.foo.useUpdate();
|
|
113
|
-
client.bar.useCreate();
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// DO NOT MODIFY THIS FILE //
|
|
3
|
-
// This file is automatically generated by ZenStack CLI and should not be manually updated. //
|
|
4
|
-
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
|
|
6
|
-
/* eslint-disable */
|
|
7
|
-
|
|
8
|
-
import { type SchemaType as $Schema } from "./schema-lite";
|
|
9
|
-
import type { FindManyArgs as $FindManyArgs, FindUniqueArgs as $FindUniqueArgs, FindFirstArgs as $FindFirstArgs, CreateArgs as $CreateArgs, CreateManyArgs as $CreateManyArgs, CreateManyAndReturnArgs as $CreateManyAndReturnArgs, UpdateArgs as $UpdateArgs, UpdateManyArgs as $UpdateManyArgs, UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, UpsertArgs as $UpsertArgs, DeleteArgs as $DeleteArgs, DeleteManyArgs as $DeleteManyArgs, CountArgs as $CountArgs, AggregateArgs as $AggregateArgs, GroupByArgs as $GroupByArgs, WhereInput as $WhereInput, SelectInput as $SelectInput, IncludeInput as $IncludeInput, OmitInput as $OmitInput, QueryOptions as $QueryOptions } from "@zenstackhq/orm";
|
|
10
|
-
import type { SimplifiedPlainResult as $Result, SelectIncludeOmit as $SelectIncludeOmit } from "@zenstackhq/orm";
|
|
11
|
-
export type UserFindManyArgs = $FindManyArgs<$Schema, "User">;
|
|
12
|
-
export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, "User">;
|
|
13
|
-
export type UserFindFirstArgs = $FindFirstArgs<$Schema, "User">;
|
|
14
|
-
export type UserCreateArgs = $CreateArgs<$Schema, "User">;
|
|
15
|
-
export type UserCreateManyArgs = $CreateManyArgs<$Schema, "User">;
|
|
16
|
-
export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "User">;
|
|
17
|
-
export type UserUpdateArgs = $UpdateArgs<$Schema, "User">;
|
|
18
|
-
export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, "User">;
|
|
19
|
-
export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "User">;
|
|
20
|
-
export type UserUpsertArgs = $UpsertArgs<$Schema, "User">;
|
|
21
|
-
export type UserDeleteArgs = $DeleteArgs<$Schema, "User">;
|
|
22
|
-
export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, "User">;
|
|
23
|
-
export type UserCountArgs = $CountArgs<$Schema, "User">;
|
|
24
|
-
export type UserAggregateArgs = $AggregateArgs<$Schema, "User">;
|
|
25
|
-
export type UserGroupByArgs = $GroupByArgs<$Schema, "User">;
|
|
26
|
-
export type UserWhereInput = $WhereInput<$Schema, "User">;
|
|
27
|
-
export type UserSelect = $SelectInput<$Schema, "User">;
|
|
28
|
-
export type UserInclude = $IncludeInput<$Schema, "User">;
|
|
29
|
-
export type UserOmit = $OmitInput<$Schema, "User">;
|
|
30
|
-
export type UserGetPayload<Args extends $SelectIncludeOmit<$Schema, "User", true>, Options extends $QueryOptions<$Schema> = $QueryOptions<$Schema>> = $Result<$Schema, "User", Args, Options>;
|
|
31
|
-
export type PostFindManyArgs = $FindManyArgs<$Schema, "Post">;
|
|
32
|
-
export type PostFindUniqueArgs = $FindUniqueArgs<$Schema, "Post">;
|
|
33
|
-
export type PostFindFirstArgs = $FindFirstArgs<$Schema, "Post">;
|
|
34
|
-
export type PostCreateArgs = $CreateArgs<$Schema, "Post">;
|
|
35
|
-
export type PostCreateManyArgs = $CreateManyArgs<$Schema, "Post">;
|
|
36
|
-
export type PostCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Post">;
|
|
37
|
-
export type PostUpdateArgs = $UpdateArgs<$Schema, "Post">;
|
|
38
|
-
export type PostUpdateManyArgs = $UpdateManyArgs<$Schema, "Post">;
|
|
39
|
-
export type PostUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Post">;
|
|
40
|
-
export type PostUpsertArgs = $UpsertArgs<$Schema, "Post">;
|
|
41
|
-
export type PostDeleteArgs = $DeleteArgs<$Schema, "Post">;
|
|
42
|
-
export type PostDeleteManyArgs = $DeleteManyArgs<$Schema, "Post">;
|
|
43
|
-
export type PostCountArgs = $CountArgs<$Schema, "Post">;
|
|
44
|
-
export type PostAggregateArgs = $AggregateArgs<$Schema, "Post">;
|
|
45
|
-
export type PostGroupByArgs = $GroupByArgs<$Schema, "Post">;
|
|
46
|
-
export type PostWhereInput = $WhereInput<$Schema, "Post">;
|
|
47
|
-
export type PostSelect = $SelectInput<$Schema, "Post">;
|
|
48
|
-
export type PostInclude = $IncludeInput<$Schema, "Post">;
|
|
49
|
-
export type PostOmit = $OmitInput<$Schema, "Post">;
|
|
50
|
-
export type PostGetPayload<Args extends $SelectIncludeOmit<$Schema, "Post", true>, Options extends $QueryOptions<$Schema> = $QueryOptions<$Schema>> = $Result<$Schema, "Post", Args, Options>;
|
|
51
|
-
export type CategoryFindManyArgs = $FindManyArgs<$Schema, "Category">;
|
|
52
|
-
export type CategoryFindUniqueArgs = $FindUniqueArgs<$Schema, "Category">;
|
|
53
|
-
export type CategoryFindFirstArgs = $FindFirstArgs<$Schema, "Category">;
|
|
54
|
-
export type CategoryCreateArgs = $CreateArgs<$Schema, "Category">;
|
|
55
|
-
export type CategoryCreateManyArgs = $CreateManyArgs<$Schema, "Category">;
|
|
56
|
-
export type CategoryCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Category">;
|
|
57
|
-
export type CategoryUpdateArgs = $UpdateArgs<$Schema, "Category">;
|
|
58
|
-
export type CategoryUpdateManyArgs = $UpdateManyArgs<$Schema, "Category">;
|
|
59
|
-
export type CategoryUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Category">;
|
|
60
|
-
export type CategoryUpsertArgs = $UpsertArgs<$Schema, "Category">;
|
|
61
|
-
export type CategoryDeleteArgs = $DeleteArgs<$Schema, "Category">;
|
|
62
|
-
export type CategoryDeleteManyArgs = $DeleteManyArgs<$Schema, "Category">;
|
|
63
|
-
export type CategoryCountArgs = $CountArgs<$Schema, "Category">;
|
|
64
|
-
export type CategoryAggregateArgs = $AggregateArgs<$Schema, "Category">;
|
|
65
|
-
export type CategoryGroupByArgs = $GroupByArgs<$Schema, "Category">;
|
|
66
|
-
export type CategoryWhereInput = $WhereInput<$Schema, "Category">;
|
|
67
|
-
export type CategorySelect = $SelectInput<$Schema, "Category">;
|
|
68
|
-
export type CategoryInclude = $IncludeInput<$Schema, "Category">;
|
|
69
|
-
export type CategoryOmit = $OmitInput<$Schema, "Category">;
|
|
70
|
-
export type CategoryGetPayload<Args extends $SelectIncludeOmit<$Schema, "Category", true>, Options extends $QueryOptions<$Schema> = $QueryOptions<$Schema>> = $Result<$Schema, "Category", Args, Options>;
|
|
71
|
-
export type FooFindManyArgs = $FindManyArgs<$Schema, "Foo">;
|
|
72
|
-
export type FooFindUniqueArgs = $FindUniqueArgs<$Schema, "Foo">;
|
|
73
|
-
export type FooFindFirstArgs = $FindFirstArgs<$Schema, "Foo">;
|
|
74
|
-
export type FooCreateArgs = $CreateArgs<$Schema, "Foo">;
|
|
75
|
-
export type FooCreateManyArgs = $CreateManyArgs<$Schema, "Foo">;
|
|
76
|
-
export type FooCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Foo">;
|
|
77
|
-
export type FooUpdateArgs = $UpdateArgs<$Schema, "Foo">;
|
|
78
|
-
export type FooUpdateManyArgs = $UpdateManyArgs<$Schema, "Foo">;
|
|
79
|
-
export type FooUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Foo">;
|
|
80
|
-
export type FooUpsertArgs = $UpsertArgs<$Schema, "Foo">;
|
|
81
|
-
export type FooDeleteArgs = $DeleteArgs<$Schema, "Foo">;
|
|
82
|
-
export type FooDeleteManyArgs = $DeleteManyArgs<$Schema, "Foo">;
|
|
83
|
-
export type FooCountArgs = $CountArgs<$Schema, "Foo">;
|
|
84
|
-
export type FooAggregateArgs = $AggregateArgs<$Schema, "Foo">;
|
|
85
|
-
export type FooGroupByArgs = $GroupByArgs<$Schema, "Foo">;
|
|
86
|
-
export type FooWhereInput = $WhereInput<$Schema, "Foo">;
|
|
87
|
-
export type FooSelect = $SelectInput<$Schema, "Foo">;
|
|
88
|
-
export type FooInclude = $IncludeInput<$Schema, "Foo">;
|
|
89
|
-
export type FooOmit = $OmitInput<$Schema, "Foo">;
|
|
90
|
-
export type FooGetPayload<Args extends $SelectIncludeOmit<$Schema, "Foo", true>, Options extends $QueryOptions<$Schema> = $QueryOptions<$Schema>> = $Result<$Schema, "Foo", Args, Options>;
|
|
91
|
-
export type BarFindManyArgs = $FindManyArgs<$Schema, "Bar">;
|
|
92
|
-
export type BarFindUniqueArgs = $FindUniqueArgs<$Schema, "Bar">;
|
|
93
|
-
export type BarFindFirstArgs = $FindFirstArgs<$Schema, "Bar">;
|
|
94
|
-
export type BarCreateArgs = $CreateArgs<$Schema, "Bar">;
|
|
95
|
-
export type BarCreateManyArgs = $CreateManyArgs<$Schema, "Bar">;
|
|
96
|
-
export type BarCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Bar">;
|
|
97
|
-
export type BarUpdateArgs = $UpdateArgs<$Schema, "Bar">;
|
|
98
|
-
export type BarUpdateManyArgs = $UpdateManyArgs<$Schema, "Bar">;
|
|
99
|
-
export type BarUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Bar">;
|
|
100
|
-
export type BarUpsertArgs = $UpsertArgs<$Schema, "Bar">;
|
|
101
|
-
export type BarDeleteArgs = $DeleteArgs<$Schema, "Bar">;
|
|
102
|
-
export type BarDeleteManyArgs = $DeleteManyArgs<$Schema, "Bar">;
|
|
103
|
-
export type BarCountArgs = $CountArgs<$Schema, "Bar">;
|
|
104
|
-
export type BarAggregateArgs = $AggregateArgs<$Schema, "Bar">;
|
|
105
|
-
export type BarGroupByArgs = $GroupByArgs<$Schema, "Bar">;
|
|
106
|
-
export type BarWhereInput = $WhereInput<$Schema, "Bar">;
|
|
107
|
-
export type BarSelect = $SelectInput<$Schema, "Bar">;
|
|
108
|
-
export type BarInclude = $IncludeInput<$Schema, "Bar">;
|
|
109
|
-
export type BarOmit = $OmitInput<$Schema, "Bar">;
|
|
110
|
-
export type BarGetPayload<Args extends $SelectIncludeOmit<$Schema, "Bar", true>, Options extends $QueryOptions<$Schema> = $QueryOptions<$Schema>> = $Result<$Schema, "Bar", Args, Options>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// DO NOT MODIFY THIS FILE //
|
|
3
|
-
// This file is automatically generated by ZenStack CLI and should not be manually updated. //
|
|
4
|
-
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
|
|
6
|
-
/* eslint-disable */
|
|
7
|
-
|
|
8
|
-
import { type SchemaType as $Schema } from "./schema-lite";
|
|
9
|
-
import { type ModelResult as $ModelResult } from "@zenstackhq/orm";
|
|
10
|
-
export type User = $ModelResult<$Schema, "User">;
|
|
11
|
-
export type Post = $ModelResult<$Schema, "Post">;
|
|
12
|
-
export type Category = $ModelResult<$Schema, "Category">;
|
|
13
|
-
export type Foo = $ModelResult<$Schema, "Foo">;
|
|
14
|
-
export type Bar = $ModelResult<$Schema, "Bar">;
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// DO NOT MODIFY THIS FILE //
|
|
3
|
-
// This file is automatically generated by ZenStack CLI and should not be manually updated. //
|
|
4
|
-
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
|
|
6
|
-
/* eslint-disable */
|
|
7
|
-
|
|
8
|
-
import { type SchemaDef, ExpressionUtils } from "@zenstackhq/orm/schema";
|
|
9
|
-
export class SchemaType implements SchemaDef {
|
|
10
|
-
provider = {
|
|
11
|
-
type: "sqlite"
|
|
12
|
-
} as const;
|
|
13
|
-
models = {
|
|
14
|
-
User: {
|
|
15
|
-
name: "User",
|
|
16
|
-
fields: {
|
|
17
|
-
id: {
|
|
18
|
-
name: "id",
|
|
19
|
-
type: "String",
|
|
20
|
-
id: true,
|
|
21
|
-
default: ExpressionUtils.call("cuid")
|
|
22
|
-
},
|
|
23
|
-
email: {
|
|
24
|
-
name: "email",
|
|
25
|
-
type: "String",
|
|
26
|
-
unique: true
|
|
27
|
-
},
|
|
28
|
-
name: {
|
|
29
|
-
name: "name",
|
|
30
|
-
type: "String",
|
|
31
|
-
optional: true
|
|
32
|
-
},
|
|
33
|
-
posts: {
|
|
34
|
-
name: "posts",
|
|
35
|
-
type: "Post",
|
|
36
|
-
array: true,
|
|
37
|
-
relation: { opposite: "owner" }
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
idFields: ["id"],
|
|
41
|
-
uniqueFields: {
|
|
42
|
-
id: { type: "String" },
|
|
43
|
-
email: { type: "String" }
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
Post: {
|
|
47
|
-
name: "Post",
|
|
48
|
-
fields: {
|
|
49
|
-
id: {
|
|
50
|
-
name: "id",
|
|
51
|
-
type: "String",
|
|
52
|
-
id: true,
|
|
53
|
-
default: ExpressionUtils.call("cuid")
|
|
54
|
-
},
|
|
55
|
-
title: {
|
|
56
|
-
name: "title",
|
|
57
|
-
type: "String"
|
|
58
|
-
},
|
|
59
|
-
owner: {
|
|
60
|
-
name: "owner",
|
|
61
|
-
type: "User",
|
|
62
|
-
optional: true,
|
|
63
|
-
relation: { opposite: "posts", fields: ["ownerId"], references: ["id"] }
|
|
64
|
-
},
|
|
65
|
-
ownerId: {
|
|
66
|
-
name: "ownerId",
|
|
67
|
-
type: "String",
|
|
68
|
-
optional: true,
|
|
69
|
-
foreignKeyFor: [
|
|
70
|
-
"owner"
|
|
71
|
-
]
|
|
72
|
-
},
|
|
73
|
-
category: {
|
|
74
|
-
name: "category",
|
|
75
|
-
type: "Category",
|
|
76
|
-
optional: true,
|
|
77
|
-
relation: { opposite: "posts", fields: ["categoryId"], references: ["id"] }
|
|
78
|
-
},
|
|
79
|
-
categoryId: {
|
|
80
|
-
name: "categoryId",
|
|
81
|
-
type: "String",
|
|
82
|
-
optional: true,
|
|
83
|
-
foreignKeyFor: [
|
|
84
|
-
"category"
|
|
85
|
-
]
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
idFields: ["id"],
|
|
89
|
-
uniqueFields: {
|
|
90
|
-
id: { type: "String" }
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
Category: {
|
|
94
|
-
name: "Category",
|
|
95
|
-
fields: {
|
|
96
|
-
id: {
|
|
97
|
-
name: "id",
|
|
98
|
-
type: "String",
|
|
99
|
-
id: true,
|
|
100
|
-
default: ExpressionUtils.call("cuid")
|
|
101
|
-
},
|
|
102
|
-
name: {
|
|
103
|
-
name: "name",
|
|
104
|
-
type: "String",
|
|
105
|
-
unique: true
|
|
106
|
-
},
|
|
107
|
-
posts: {
|
|
108
|
-
name: "posts",
|
|
109
|
-
type: "Post",
|
|
110
|
-
array: true,
|
|
111
|
-
relation: { opposite: "category" }
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
idFields: ["id"],
|
|
115
|
-
uniqueFields: {
|
|
116
|
-
id: { type: "String" },
|
|
117
|
-
name: { type: "String" }
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
Foo: {
|
|
121
|
-
name: "Foo",
|
|
122
|
-
fields: {
|
|
123
|
-
id: {
|
|
124
|
-
name: "id",
|
|
125
|
-
type: "String",
|
|
126
|
-
id: true,
|
|
127
|
-
default: ExpressionUtils.call("cuid")
|
|
128
|
-
},
|
|
129
|
-
type: {
|
|
130
|
-
name: "type",
|
|
131
|
-
type: "String",
|
|
132
|
-
isDiscriminator: true
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
idFields: ["id"],
|
|
136
|
-
uniqueFields: {
|
|
137
|
-
id: { type: "String" }
|
|
138
|
-
},
|
|
139
|
-
isDelegate: true,
|
|
140
|
-
subModels: ["Bar"]
|
|
141
|
-
},
|
|
142
|
-
Bar: {
|
|
143
|
-
name: "Bar",
|
|
144
|
-
baseModel: "Foo",
|
|
145
|
-
fields: {
|
|
146
|
-
id: {
|
|
147
|
-
name: "id",
|
|
148
|
-
type: "String",
|
|
149
|
-
id: true,
|
|
150
|
-
default: ExpressionUtils.call("cuid")
|
|
151
|
-
},
|
|
152
|
-
type: {
|
|
153
|
-
name: "type",
|
|
154
|
-
type: "String",
|
|
155
|
-
originModel: "Foo",
|
|
156
|
-
isDiscriminator: true
|
|
157
|
-
},
|
|
158
|
-
title: {
|
|
159
|
-
name: "title",
|
|
160
|
-
type: "String"
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
idFields: ["id"],
|
|
164
|
-
uniqueFields: {
|
|
165
|
-
id: { type: "String" }
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
} as const;
|
|
169
|
-
authType = "User" as const;
|
|
170
|
-
plugins = {};
|
|
171
|
-
}
|
|
172
|
-
export const schema = new SchemaType();
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
datasource db {
|
|
2
|
-
provider = 'sqlite'
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
model User {
|
|
6
|
-
id String @id @default(cuid())
|
|
7
|
-
email String @unique
|
|
8
|
-
name String?
|
|
9
|
-
posts Post[]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
model Post {
|
|
13
|
-
id String @id @default(cuid())
|
|
14
|
-
title String
|
|
15
|
-
owner User? @relation(fields: [ownerId], references: [id])
|
|
16
|
-
ownerId String?
|
|
17
|
-
category Category? @relation(fields: [categoryId], references: [id])
|
|
18
|
-
categoryId String?
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
model Category {
|
|
22
|
-
id String @id @default(cuid())
|
|
23
|
-
name String @unique
|
|
24
|
-
posts Post[]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
model Foo {
|
|
28
|
-
id String @id @default(cuid())
|
|
29
|
-
type String
|
|
30
|
-
@@delegate(type)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
model Bar extends Foo {
|
|
34
|
-
title String
|
|
35
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
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
|
-
check(get(client.user.useFindFirst()).data?.$optimistic);
|
|
21
|
-
|
|
22
|
-
check(get(client.user.useFindMany()).data?.[0]?.email);
|
|
23
|
-
check(get(client.user.useFindMany()).data?.[0]?.$optimistic);
|
|
24
|
-
|
|
25
|
-
check(get(client.user.useInfiniteFindMany()).data?.pages[0]?.[0]?.email);
|
|
26
|
-
check(
|
|
27
|
-
get(
|
|
28
|
-
client.user.useInfiniteFindMany(
|
|
29
|
-
{},
|
|
30
|
-
{
|
|
31
|
-
getNextPageParam: () => ({ id: '2' }),
|
|
32
|
-
},
|
|
33
|
-
),
|
|
34
|
-
).data?.pages[1]?.[0]?.email,
|
|
35
|
-
);
|
|
36
|
-
// @ts-expect-error
|
|
37
|
-
check(get(client.user.useInfiniteFindMany()).data?.pages[0]?.[0]?.$optimistic);
|
|
38
|
-
|
|
39
|
-
check(get(client.user.useCount()).data?.toFixed(2));
|
|
40
|
-
check(get(client.user.useCount({ select: { email: true } })).data?.email.toFixed(2));
|
|
41
|
-
|
|
42
|
-
check(get(client.user.useAggregate({ _max: { email: true } })).data?._max.email);
|
|
43
|
-
|
|
44
|
-
check(get(client.user.useGroupBy({ by: ['email'], _max: { name: true } })).data?.[0]?._max.name);
|
|
45
|
-
|
|
46
|
-
// @ts-expect-error missing args
|
|
47
|
-
client.user.useCreate().mutate();
|
|
48
|
-
get(client.user.useCreate()).mutate({ data: { email: 'test@example.com' } });
|
|
49
|
-
get(client.user.useCreate({ optimisticUpdate: true, invalidateQueries: false, retry: 3 })).mutate({
|
|
50
|
-
data: { email: 'test@example.com' },
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
get(client.user.useCreate())
|
|
54
|
-
.mutateAsync({ data: { email: 'test@example.com' }, include: { posts: true } })
|
|
55
|
-
.then((d) => check(d.posts[0]?.title));
|
|
56
|
-
|
|
57
|
-
get(client.user.useCreateMany())
|
|
58
|
-
.mutateAsync({
|
|
59
|
-
data: [{ email: 'test@example.com' }, { email: 'test2@example.com' }],
|
|
60
|
-
skipDuplicates: true,
|
|
61
|
-
})
|
|
62
|
-
.then((d) => d.count);
|
|
63
|
-
|
|
64
|
-
get(client.user.useCreateManyAndReturn())
|
|
65
|
-
.mutateAsync({
|
|
66
|
-
data: [{ email: 'test@example.com' }],
|
|
67
|
-
})
|
|
68
|
-
.then((d) => check(d[0]?.name));
|
|
69
|
-
|
|
70
|
-
get(client.user.useCreateManyAndReturn())
|
|
71
|
-
.mutateAsync({
|
|
72
|
-
data: [{ email: 'test@example.com' }],
|
|
73
|
-
select: { email: true },
|
|
74
|
-
})
|
|
75
|
-
// @ts-expect-error unselected field
|
|
76
|
-
.then((d) => check(d[0].name));
|
|
77
|
-
|
|
78
|
-
get(client.user.useUpdate()).mutate(
|
|
79
|
-
{ data: { email: 'updated@example.com' }, where: { id: '1' } },
|
|
80
|
-
{
|
|
81
|
-
onSuccess: (d) => {
|
|
82
|
-
check(d.email);
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
get(client.user.useUpdateMany()).mutate({ data: { email: 'updated@example.com' } });
|
|
88
|
-
|
|
89
|
-
get(client.user.useUpdateManyAndReturn())
|
|
90
|
-
.mutateAsync({ data: { email: 'updated@example.com' } })
|
|
91
|
-
.then((d) => check(d[0]?.email));
|
|
92
|
-
|
|
93
|
-
get(client.user.useUpsert()).mutate({
|
|
94
|
-
where: { id: '1' },
|
|
95
|
-
create: { email: 'new@example.com' },
|
|
96
|
-
update: { email: 'updated@example.com' },
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
get(client.user.useDelete()).mutate({ where: { id: '1' }, include: { posts: true } });
|
|
100
|
-
|
|
101
|
-
get(client.user.useDeleteMany()).mutate({ where: { email: 'test@example.com' } });
|
|
102
|
-
|
|
103
|
-
function check(_value: unknown) {
|
|
104
|
-
// noop
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// @ts-expect-error delegate model
|
|
108
|
-
client.foo.useCreate();
|
|
109
|
-
|
|
110
|
-
client.foo.useUpdate();
|
|
111
|
-
client.bar.useCreate();
|
package/test/vue-typing-test.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
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
|
-
check(client.user.useFindFirst().data.value?.$optimistic);
|
|
20
|
-
|
|
21
|
-
check(client.user.useFindMany().data.value?.[0]?.email);
|
|
22
|
-
check(client.user.useFindMany().data.value?.[0]?.$optimistic);
|
|
23
|
-
|
|
24
|
-
check(client.user.useInfiniteFindMany().data.value?.pages[0]?.[0]?.email);
|
|
25
|
-
check(
|
|
26
|
-
client.user.useInfiniteFindMany(
|
|
27
|
-
{},
|
|
28
|
-
{
|
|
29
|
-
getNextPageParam: () => ({ id: '2' }),
|
|
30
|
-
},
|
|
31
|
-
).data.value?.pages[1]?.[0]?.email,
|
|
32
|
-
);
|
|
33
|
-
// @ts-expect-error
|
|
34
|
-
check(client.user.useInfiniteFindMany().data.value?.pages[0]?.[0]?.$optimistic);
|
|
35
|
-
|
|
36
|
-
check(client.user.useCount().data.value?.toFixed(2));
|
|
37
|
-
check(client.user.useCount({ select: { email: true } }).data.value?.email.toFixed(2));
|
|
38
|
-
|
|
39
|
-
check(client.user.useAggregate({ _max: { email: true } }).data.value?._max.email);
|
|
40
|
-
|
|
41
|
-
check(client.user.useGroupBy({ by: ['email'], _max: { name: true } }).data.value?.[0]?._max.name);
|
|
42
|
-
|
|
43
|
-
// @ts-expect-error missing args
|
|
44
|
-
client.user.useCreate().mutate();
|
|
45
|
-
client.user.useCreate().mutate({ data: { email: 'test@example.com' } });
|
|
46
|
-
client.user
|
|
47
|
-
.useCreate({ optimisticUpdate: true, invalidateQueries: false, retry: 3 })
|
|
48
|
-
.mutate({ data: { email: 'test@example.com' } });
|
|
49
|
-
|
|
50
|
-
client.user
|
|
51
|
-
.useCreate()
|
|
52
|
-
.mutateAsync({ data: { email: 'test@example.com' }, include: { posts: true } })
|
|
53
|
-
.then((d) => check(d.posts[0]?.title));
|
|
54
|
-
|
|
55
|
-
client.user
|
|
56
|
-
.useCreateMany()
|
|
57
|
-
.mutateAsync({
|
|
58
|
-
data: [{ email: 'test@example.com' }, { email: 'test2@example.com' }],
|
|
59
|
-
skipDuplicates: true,
|
|
60
|
-
})
|
|
61
|
-
.then((d) => d.count);
|
|
62
|
-
|
|
63
|
-
client.user
|
|
64
|
-
.useCreateManyAndReturn()
|
|
65
|
-
.mutateAsync({
|
|
66
|
-
data: [{ email: 'test@example.com' }],
|
|
67
|
-
})
|
|
68
|
-
.then((d) => check(d[0]?.name));
|
|
69
|
-
|
|
70
|
-
client.user
|
|
71
|
-
.useCreateManyAndReturn()
|
|
72
|
-
.mutateAsync({
|
|
73
|
-
data: [{ email: 'test@example.com' }],
|
|
74
|
-
select: { email: true },
|
|
75
|
-
})
|
|
76
|
-
// @ts-expect-error unselected field
|
|
77
|
-
.then((d) => check(d[0].name));
|
|
78
|
-
|
|
79
|
-
client.user.useUpdate().mutate(
|
|
80
|
-
{ data: { email: 'updated@example.com' }, where: { id: '1' } },
|
|
81
|
-
{
|
|
82
|
-
onSuccess: (d) => {
|
|
83
|
-
check(d.email);
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
client.user.useUpdateMany().mutate({ data: { email: 'updated@example.com' } });
|
|
89
|
-
|
|
90
|
-
client.user
|
|
91
|
-
.useUpdateManyAndReturn()
|
|
92
|
-
.mutateAsync({ data: { email: 'updated@example.com' } })
|
|
93
|
-
.then((d) => check(d[0]?.email));
|
|
94
|
-
|
|
95
|
-
client.user
|
|
96
|
-
.useUpsert()
|
|
97
|
-
.mutate({ where: { id: '1' }, create: { email: 'new@example.com' }, update: { email: 'updated@example.com' } });
|
|
98
|
-
|
|
99
|
-
client.user.useDelete().mutate({ where: { id: '1' }, include: { posts: true } });
|
|
100
|
-
|
|
101
|
-
client.user.useDeleteMany().mutate({ where: { email: 'test@example.com' } });
|
|
102
|
-
|
|
103
|
-
function check(_value: unknown) {
|
|
104
|
-
// noop
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// @ts-expect-error delegate model
|
|
108
|
-
client.foo.useCreate();
|
|
109
|
-
|
|
110
|
-
client.foo.useUpdate();
|
|
111
|
-
client.bar.useCreate();
|