Skip to content

Commit

Permalink
update to latest zenstack
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed Dec 15, 2023
1 parent b34c904 commit 79a2cba
Show file tree
Hide file tree
Showing 20 changed files with 1,094 additions and 918 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": [
"next/core-web-vitals",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"parserOptions": {
"ecmaVersion": 2020,
"project": ["tsconfig.json"]
}
}
2 changes: 1 addition & 1 deletion components/AuthGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function AuthGuard({ children }: Props) {
if (status === 'loading') {
return <p>Loading...</p>;
} else if (status === 'unauthenticated') {
router.push('/signin');
void router.push('/signin');
return <></>;
} else {
return <>{children}</>;
Expand Down
8 changes: 5 additions & 3 deletions components/ManageMembers.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { PlusIcon, TrashIcon } from '@heroicons/react/24/outline';
import { useCurrentUser } from '@lib/context';
import { useCreateSpaceUser, useDeleteSpaceUser, useFindManySpaceUser } from '@lib/hooks';
Expand Down Expand Up @@ -47,6 +48,7 @@ export default function ManageMembers({ space }: Props) {
},
});
console.log('SpaceUser created:', r);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.error(err);
if (err.info?.prisma === true) {
Expand All @@ -65,7 +67,7 @@ export default function ManageMembers({ space }: Props) {

const removeMember = (id: string) => {
if (confirm(`Are you sure to remove this member from space?`)) {
deleteSpaceUser({ where: { id } });
void deleteSpaceUser({ where: { id } });
}
};

Expand All @@ -82,7 +84,7 @@ export default function ManageMembers({ space }: Props) {
}}
onKeyUp={(e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
inviteUser();
void inviteUser();
}
}}
/>
Expand All @@ -98,7 +100,7 @@ export default function ManageMembers({ space }: Props) {
<option value={SpaceUserRole.ADMIN}>ADMIN</option>
</select>

<button onClick={() => inviteUser()}>
<button onClick={() => void inviteUser()}>
<PlusIcon className="w-6 h-6 text-gray-500" />
</button>
</div>
Expand Down
6 changes: 3 additions & 3 deletions components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type Props = {
};

export default function NavBar({ user, space }: Props) {
const onSignout = async () => {
await signOut({ callbackUrl: '/signin' });
const onSignout = () => {
void signOut({ callbackUrl: '/signin' });
};

return (
Expand All @@ -29,7 +29,7 @@ export default function NavBar({ user, space }: Props) {
<div className="flex-none">
<div className="dropdown dropdown-end">
<label tabIndex={0} className="btn btn-ghost btn-circle avatar">
{user && <Avatar user={user!} />}
{user && <Avatar user={user} />}
</label>
<ul
tabIndex={0}
Expand Down
8 changes: 4 additions & 4 deletions components/Todo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export default function TodoComponent({ value, optimistic }: Props) {
const { trigger: updateTodo } = useUpdateTodo({ optimisticUpdate: true });
const { trigger: deleteTodo } = useDeleteTodo({ optimisticUpdate: true });

const onDeleteTodo = async () => {
deleteTodo({ where: { id: value.id } });
const onDeleteTodo = () => {
void deleteTodo({ where: { id: value.id } });
};

const toggleCompleted = async (completed: boolean) => {
const toggleCompleted = (completed: boolean) => {
if (completed === !!value.completedAt) {
return;
}
updateTodo({
void updateTodo({
where: { id: value.id },
data: { completedAt: completed ? new Date() : null },
});
Expand Down
2 changes: 1 addition & 1 deletion components/TodoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function TodoList({ value }: Props) {

const onDeleteList = () => {
if (confirm('Are you sure to delete this list?')) {
deleteList({ where: { id: value.id } });
void deleteList({ where: { id: value.id } });
}
};

Expand Down
79 changes: 43 additions & 36 deletions lib/hooks/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import metadata from './__model_meta';
import * as request from '@zenstackhq/swr/runtime';

/** @deprecated Use mutation hooks (useCreateXXX, useUpdateXXX, etc.) instead. */
export function useMutateAccount() {
const { endpoint, fetch } = useHooksContext();
const invalidate = request.useInvalidation('Account', metadata);
Expand Down Expand Up @@ -133,7 +134,7 @@ export function useCreateAccount(
const mutation = request.useModelMutation('Account', 'POST', 'create', metadata, options, true);
return {
...mutation,
trigger<T extends Prisma.AccountCreateArgs>(args: Prisma.SelectSubset<T, Prisma.AccountCreateArgs>) {
trigger: <T extends Prisma.AccountCreateArgs>(args: Prisma.SelectSubset<T, Prisma.AccountCreateArgs>) => {
return mutation.trigger(args, options as any) as Promise<Prisma.AccountGetPayload<T> | undefined>;
},
};
Expand All @@ -145,7 +146,9 @@ export function useCreateManyAccount(
const mutation = request.useModelMutation('Account', 'POST', 'createMany', metadata, options, false);
return {
...mutation,
trigger<T extends Prisma.AccountCreateManyArgs>(args: Prisma.SelectSubset<T, Prisma.AccountCreateManyArgs>) {
trigger: <T extends Prisma.AccountCreateManyArgs>(
args: Prisma.SelectSubset<T, Prisma.AccountCreateManyArgs>,
) => {
return mutation.trigger(args, options as any) as Promise<Prisma.BatchPayload>;
},
};
Expand Down Expand Up @@ -192,7 +195,7 @@ export function useUpdateAccount(
const mutation = request.useModelMutation('Account', 'PUT', 'update', metadata, options, true);
return {
...mutation,
trigger<T extends Prisma.AccountUpdateArgs>(args: Prisma.SelectSubset<T, Prisma.AccountUpdateArgs>) {
trigger: <T extends Prisma.AccountUpdateArgs>(args: Prisma.SelectSubset<T, Prisma.AccountUpdateArgs>) => {
return mutation.trigger(args, options as any) as Promise<Prisma.AccountGetPayload<T> | undefined>;
},
};
Expand All @@ -204,7 +207,9 @@ export function useUpdateManyAccount(
const mutation = request.useModelMutation('Account', 'PUT', 'updateMany', metadata, options, false);
return {
...mutation,
trigger<T extends Prisma.AccountUpdateManyArgs>(args: Prisma.SelectSubset<T, Prisma.AccountUpdateManyArgs>) {
trigger: <T extends Prisma.AccountUpdateManyArgs>(
args: Prisma.SelectSubset<T, Prisma.AccountUpdateManyArgs>,
) => {
return mutation.trigger(args, options as any) as Promise<Prisma.BatchPayload>;
},
};
Expand All @@ -220,7 +225,7 @@ export function useUpsertAccount(
const mutation = request.useModelMutation('Account', 'POST', 'upsert', metadata, options, true);
return {
...mutation,
trigger<T extends Prisma.AccountUpsertArgs>(args: Prisma.SelectSubset<T, Prisma.AccountUpsertArgs>) {
trigger: <T extends Prisma.AccountUpsertArgs>(args: Prisma.SelectSubset<T, Prisma.AccountUpsertArgs>) => {
return mutation.trigger(args, options as any) as Promise<Prisma.AccountGetPayload<T> | undefined>;
},
};
Expand All @@ -236,7 +241,7 @@ export function useDeleteAccount(
const mutation = request.useModelMutation('Account', 'DELETE', 'delete', metadata, options, true);
return {
...mutation,
trigger<T extends Prisma.AccountDeleteArgs>(args: Prisma.SelectSubset<T, Prisma.AccountDeleteArgs>) {
trigger: <T extends Prisma.AccountDeleteArgs>(args: Prisma.SelectSubset<T, Prisma.AccountDeleteArgs>) => {
return mutation.trigger(args, options as any) as Promise<Prisma.AccountGetPayload<T> | undefined>;
},
};
Expand All @@ -248,7 +253,9 @@ export function useDeleteManyAccount(
const mutation = request.useModelMutation('Account', 'DELETE', 'deleteMany', metadata, options, false);
return {
...mutation,
trigger<T extends Prisma.AccountDeleteManyArgs>(args: Prisma.SelectSubset<T, Prisma.AccountDeleteManyArgs>) {
trigger: <T extends Prisma.AccountDeleteManyArgs>(
args: Prisma.SelectSubset<T, Prisma.AccountDeleteManyArgs>,
) => {
return mutation.trigger(args, options as any) as Promise<Prisma.BatchPayload>;
},
};
Expand Down Expand Up @@ -276,40 +283,40 @@ export function useGroupByAccount<
InputErrors extends ByEmpty extends Prisma.True
? `Error: "by" must not be empty.`
: HavingValid extends Prisma.False
? {
[P in HavingFields]: P extends ByFields
? never
: P extends string
? `Error: Field "${P}" used in "having" needs to be provided in "by".`
: [Error, 'Field ', P, ` in "having" needs to be provided in "by"`];
}[HavingFields]
: 'take' extends Prisma.Keys<T>
? 'orderBy' extends Prisma.Keys<T>
? ByValid extends Prisma.True
? {
[P in HavingFields]: P extends ByFields
? never
: P extends string
? `Error: Field "${P}" used in "having" needs to be provided in "by".`
: [Error, 'Field ', P, ` in "having" needs to be provided in "by"`];
}[HavingFields]
: 'take' extends Prisma.Keys<T>
? 'orderBy' extends Prisma.Keys<T>
? ByValid extends Prisma.True
? {}
: {
[P in OrderFields]: P extends ByFields
? never
: `Error: Field "${P}" in "orderBy" needs to be provided in "by"`;
}[OrderFields]
: 'Error: If you provide "take", you also need to provide "orderBy"'
: 'skip' extends Prisma.Keys<T>
? 'orderBy' extends Prisma.Keys<T>
? ByValid extends Prisma.True
? {}
: {
[P in OrderFields]: P extends ByFields
? never
: `Error: Field "${P}" in "orderBy" needs to be provided in "by"`;
}[OrderFields]
: 'Error: If you provide "skip", you also need to provide "orderBy"'
: ByValid extends Prisma.True
? {}
: {
[P in OrderFields]: P extends ByFields
? never
: `Error: Field "${P}" in "orderBy" needs to be provided in "by"`;
}[OrderFields]
: 'Error: If you provide "take", you also need to provide "orderBy"'
: 'skip' extends Prisma.Keys<T>
? 'orderBy' extends Prisma.Keys<T>
? ByValid extends Prisma.True
? {}
: {
[P in OrderFields]: P extends ByFields
? never
: `Error: Field "${P}" in "orderBy" needs to be provided in "by"`;
}[OrderFields]
: 'Error: If you provide "skip", you also need to provide "orderBy"'
: ByValid extends Prisma.True
? {}
: {
[P in OrderFields]: P extends ByFields
? never
: `Error: Field "${P}" in "orderBy" needs to be provided in "by"`;
}[OrderFields],
}[OrderFields],
>(
args?: Prisma.SubsetIntersection<T, Prisma.AccountGroupByArgs, OrderByArg> & InputErrors,
options?: QueryOptions<
Expand Down
73 changes: 37 additions & 36 deletions lib/hooks/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import metadata from './__model_meta';
import * as request from '@zenstackhq/swr/runtime';

/** @deprecated Use mutation hooks (useCreateXXX, useUpdateXXX, etc.) instead. */
export function useMutateList() {
const { endpoint, fetch } = useHooksContext();
const invalidate = request.useInvalidation('List', metadata);
Expand Down Expand Up @@ -113,7 +114,7 @@ export function useCreateList(
const mutation = request.useModelMutation('List', 'POST', 'create', metadata, options, true);
return {
...mutation,
trigger<T extends Prisma.ListCreateArgs>(args: Prisma.SelectSubset<T, Prisma.ListCreateArgs>) {
trigger: <T extends Prisma.ListCreateArgs>(args: Prisma.SelectSubset<T, Prisma.ListCreateArgs>) => {
return mutation.trigger(args, options as any) as Promise<Prisma.ListGetPayload<T> | undefined>;
},
};
Expand All @@ -123,7 +124,7 @@ export function useCreateManyList(options?: MutationOptions<Prisma.BatchPayload,
const mutation = request.useModelMutation('List', 'POST', 'createMany', metadata, options, false);
return {
...mutation,
trigger<T extends Prisma.ListCreateManyArgs>(args: Prisma.SelectSubset<T, Prisma.ListCreateManyArgs>) {
trigger: <T extends Prisma.ListCreateManyArgs>(args: Prisma.SelectSubset<T, Prisma.ListCreateManyArgs>) => {
return mutation.trigger(args, options as any) as Promise<Prisma.BatchPayload>;
},
};
Expand Down Expand Up @@ -163,7 +164,7 @@ export function useUpdateList(
const mutation = request.useModelMutation('List', 'PUT', 'update', metadata, options, true);
return {
...mutation,
trigger<T extends Prisma.ListUpdateArgs>(args: Prisma.SelectSubset<T, Prisma.ListUpdateArgs>) {
trigger: <T extends Prisma.ListUpdateArgs>(args: Prisma.SelectSubset<T, Prisma.ListUpdateArgs>) => {
return mutation.trigger(args, options as any) as Promise<Prisma.ListGetPayload<T> | undefined>;
},
};
Expand All @@ -173,7 +174,7 @@ export function useUpdateManyList(options?: MutationOptions<Prisma.BatchPayload,
const mutation = request.useModelMutation('List', 'PUT', 'updateMany', metadata, options, false);
return {
...mutation,
trigger<T extends Prisma.ListUpdateManyArgs>(args: Prisma.SelectSubset<T, Prisma.ListUpdateManyArgs>) {
trigger: <T extends Prisma.ListUpdateManyArgs>(args: Prisma.SelectSubset<T, Prisma.ListUpdateManyArgs>) => {
return mutation.trigger(args, options as any) as Promise<Prisma.BatchPayload>;
},
};
Expand All @@ -185,7 +186,7 @@ export function useUpsertList(
const mutation = request.useModelMutation('List', 'POST', 'upsert', metadata, options, true);
return {
...mutation,
trigger<T extends Prisma.ListUpsertArgs>(args: Prisma.SelectSubset<T, Prisma.ListUpsertArgs>) {
trigger: <T extends Prisma.ListUpsertArgs>(args: Prisma.SelectSubset<T, Prisma.ListUpsertArgs>) => {
return mutation.trigger(args, options as any) as Promise<Prisma.ListGetPayload<T> | undefined>;
},
};
Expand All @@ -197,7 +198,7 @@ export function useDeleteList(
const mutation = request.useModelMutation('List', 'DELETE', 'delete', metadata, options, true);
return {
...mutation,
trigger<T extends Prisma.ListDeleteArgs>(args: Prisma.SelectSubset<T, Prisma.ListDeleteArgs>) {
trigger: <T extends Prisma.ListDeleteArgs>(args: Prisma.SelectSubset<T, Prisma.ListDeleteArgs>) => {
return mutation.trigger(args, options as any) as Promise<Prisma.ListGetPayload<T> | undefined>;
},
};
Expand All @@ -207,7 +208,7 @@ export function useDeleteManyList(options?: MutationOptions<Prisma.BatchPayload,
const mutation = request.useModelMutation('List', 'DELETE', 'deleteMany', metadata, options, false);
return {
...mutation,
trigger<T extends Prisma.ListDeleteManyArgs>(args: Prisma.SelectSubset<T, Prisma.ListDeleteManyArgs>) {
trigger: <T extends Prisma.ListDeleteManyArgs>(args: Prisma.SelectSubset<T, Prisma.ListDeleteManyArgs>) => {
return mutation.trigger(args, options as any) as Promise<Prisma.BatchPayload>;
},
};
Expand Down Expand Up @@ -235,40 +236,40 @@ export function useGroupByList<
InputErrors extends ByEmpty extends Prisma.True
? `Error: "by" must not be empty.`
: HavingValid extends Prisma.False
? {
[P in HavingFields]: P extends ByFields
? never
: P extends string
? `Error: Field "${P}" used in "having" needs to be provided in "by".`
: [Error, 'Field ', P, ` in "having" needs to be provided in "by"`];
}[HavingFields]
: 'take' extends Prisma.Keys<T>
? 'orderBy' extends Prisma.Keys<T>
? ByValid extends Prisma.True
? {
[P in HavingFields]: P extends ByFields
? never
: P extends string
? `Error: Field "${P}" used in "having" needs to be provided in "by".`
: [Error, 'Field ', P, ` in "having" needs to be provided in "by"`];
}[HavingFields]
: 'take' extends Prisma.Keys<T>
? 'orderBy' extends Prisma.Keys<T>
? ByValid extends Prisma.True
? {}
: {
[P in OrderFields]: P extends ByFields
? never
: `Error: Field "${P}" in "orderBy" needs to be provided in "by"`;
}[OrderFields]
: 'Error: If you provide "take", you also need to provide "orderBy"'
: 'skip' extends Prisma.Keys<T>
? 'orderBy' extends Prisma.Keys<T>
? ByValid extends Prisma.True
? {}
: {
[P in OrderFields]: P extends ByFields
? never
: `Error: Field "${P}" in "orderBy" needs to be provided in "by"`;
}[OrderFields]
: 'Error: If you provide "skip", you also need to provide "orderBy"'
: ByValid extends Prisma.True
? {}
: {
[P in OrderFields]: P extends ByFields
? never
: `Error: Field "${P}" in "orderBy" needs to be provided in "by"`;
}[OrderFields]
: 'Error: If you provide "take", you also need to provide "orderBy"'
: 'skip' extends Prisma.Keys<T>
? 'orderBy' extends Prisma.Keys<T>
? ByValid extends Prisma.True
? {}
: {
[P in OrderFields]: P extends ByFields
? never
: `Error: Field "${P}" in "orderBy" needs to be provided in "by"`;
}[OrderFields]
: 'Error: If you provide "skip", you also need to provide "orderBy"'
: ByValid extends Prisma.True
? {}
: {
[P in OrderFields]: P extends ByFields
? never
: `Error: Field "${P}" in "orderBy" needs to be provided in "by"`;
}[OrderFields],
}[OrderFields],
>(
args?: Prisma.SubsetIntersection<T, Prisma.ListGroupByArgs, OrderByArg> & InputErrors,
options?: QueryOptions<
Expand Down
Loading

1 comment on commit 79a2cba

@vercel
Copy link

@vercel vercel bot commented on 79a2cba Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

todo-demo – ./

todo-demo-zenstack.vercel.app
zenstack-todo.vercel.app
todo-demo-git-main-zenstack.vercel.app

Please sign in to comment.