Skip to content

Commit b80dfbc

Browse files
committed
update to v2
1 parent 409368c commit b80dfbc

16 files changed

+2225
-4166
lines changed

package-lock.json

+175-1,725
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"@trpc/next": "^10.44.1",
2828
"@trpc/react-query": "^10.5.0",
2929
"@trpc/server": "^10.5.0",
30-
"@zenstackhq/runtime": "^1.12.4",
31-
"@zenstackhq/trpc": "^1.12.4",
30+
"@zenstackhq/runtime": "^2.0.0",
31+
"@zenstackhq/trpc": "^2.0.0",
3232
"babel-plugin-superjson-next": "^0.4.5",
3333
"bcryptjs": "^2.4.3",
3434
"cross-env": "^7.0.3",
@@ -44,7 +44,6 @@
4444
"zod": "3.21.1"
4545
},
4646
"devDependencies": {
47-
"@prisma/internals": "^4.10.0",
4847
"@tailwindcss/line-clamp": "^0.4.2",
4948
"@types/bcryptjs": "^2.4.2",
5049
"@types/node": "^14.17.3",
@@ -57,6 +56,6 @@
5756
"prisma": "^5.7.1",
5857
"tailwindcss": "^3.1.8",
5958
"typescript": "^5.3.2",
60-
"zenstack": "^1.12.4"
59+
"zenstack": "^2.0.0"
6160
}
6261
}

pages/space/[slug]/[listId]/index.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { PlusIcon } from '@heroicons/react/24/outline';
2-
import { useCurrentUser } from '@lib/context';
32
import { trpc } from '@lib/trpc';
43
import { List, Space, Todo, User } from '@prisma/client';
54
import BreadCrumb from 'components/BreadCrumb';
@@ -17,7 +16,6 @@ type Props = {
1716
};
1817

1918
export default function TodoList(props: Props) {
20-
const user = useCurrentUser();
2119
const [title, setTitle] = useState('');
2220

2321
const { data: todos, refetch } = trpc.todo.findMany.useQuery(
@@ -40,7 +38,6 @@ export default function TodoList(props: Props) {
4038
const todo = await createTodo({
4139
data: {
4240
title,
43-
owner: { connect: { id: user!.id } },
4441
list: { connect: { id: props.list.id } },
4542
},
4643
});

pages/space/[slug]/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SpaceContext, UserContext } from '@lib/context';
1+
import { SpaceContext } from '@lib/context';
22
import { trpc } from '@lib/trpc';
33
import { List, Space, User } from '@prisma/client';
44
import BreadCrumb from 'components/BreadCrumb';
@@ -19,7 +19,6 @@ import { toast } from 'react-toastify';
1919
import { getEnhancedPrisma } from 'server/db/enhanced';
2020

2121
function CreateDialog({ created }: { created: (list: List) => void }) {
22-
const user = useContext(UserContext);
2322
const space = useContext(SpaceContext);
2423

2524
const [modalOpen, setModalOpen] = useState(false);
@@ -44,7 +43,6 @@ function CreateDialog({ created }: { created: (list: List) => void }) {
4443
title,
4544
private: _private,
4645
space: { connect: { id: space!.id } },
47-
owner: { connect: { id: user!.id } },
4846
},
4947
});
5048

prisma/schema.prisma

+77-77
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,72 @@
44
//////////////////////////////////////////////////////////////////////////////////////////////
55

66
datasource db {
7-
provider = "postgresql"
8-
url = env("POSTGRES_PRISMA_URL")
9-
directUrl = env("POSTGRES_URL_NON_POOLING")
7+
provider = "postgresql"
8+
url = env("POSTGRES_PRISMA_URL")
9+
directUrl = env("POSTGRES_URL_NON_POOLING")
1010
}
1111

1212
generator js {
13-
provider = "prisma-client-js"
13+
provider = "prisma-client-js"
1414
}
1515

1616
enum SpaceUserRole {
17-
USER
18-
ADMIN
17+
USER
18+
ADMIN
1919
}
2020

2121
/// @@deny('all', auth() == null)
2222
/// @@allow('create', true)
2323
/// @@allow('read', members?[user == auth()])
2424
/// @@allow('update,delete', members?[user == auth() && role == ADMIN])
2525
model Space {
26-
id String @id() @default(uuid())
27-
createdAt DateTime @default(now())
28-
updatedAt DateTime @updatedAt()
29-
/// @length(4, 50)
30-
name String
31-
/// @regex('^[0-9a-zA-Z]{4,16}$')
32-
slug String @unique()
33-
members SpaceUser[]
34-
lists List[]
26+
id String @id() @default(uuid())
27+
createdAt DateTime @default(now())
28+
updatedAt DateTime @updatedAt()
29+
/// @length(4, 50)
30+
name String
31+
/// @regex('^[0-9a-zA-Z]{4,16}$')
32+
slug String @unique()
33+
members SpaceUser[]
34+
lists List[]
3535
}
3636

3737
/// @@deny('all', auth() == null)
3838
/// @@allow('create,update,delete', space.members?[user == auth() && role == ADMIN])
3939
/// @@allow('read', space.members?[user == auth()])
4040
model SpaceUser {
41-
id String @id() @default(uuid())
42-
createdAt DateTime @default(now())
43-
updatedAt DateTime @updatedAt()
44-
space Space @relation(fields: [spaceId], references: [id], onDelete: Cascade)
45-
spaceId String
46-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
47-
userId String
48-
role SpaceUserRole
41+
id String @id() @default(uuid())
42+
createdAt DateTime @default(now())
43+
updatedAt DateTime @updatedAt()
44+
space Space @relation(fields: [spaceId], references: [id], onDelete: Cascade)
45+
spaceId String
46+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
47+
userId String
48+
role SpaceUserRole
4949
50-
@@unique([userId, spaceId])
50+
@@unique([userId, spaceId])
5151
}
5252

5353
/// @@allow('create', true)
5454
/// @@allow('read', spaces?[space.members?[user == auth()]])
5555
/// @@allow('all', auth() == this)
5656
model User {
57-
id String @id() @default(uuid())
58-
createdAt DateTime @default(now())
59-
updatedAt DateTime @updatedAt()
60-
/// @email
61-
email String @unique()
62-
emailVerified DateTime?
63-
/// @password
64-
/// @omit
65-
password String?
66-
name String?
67-
spaces SpaceUser[]
68-
/// @url
69-
image String?
70-
lists List[]
71-
todos Todo[]
72-
accounts Account[]
57+
id String @id() @default(uuid())
58+
createdAt DateTime @default(now())
59+
updatedAt DateTime @updatedAt()
60+
/// @email
61+
email String @unique()
62+
emailVerified DateTime?
63+
/// @password
64+
/// @omit
65+
password String?
66+
name String?
67+
spaces SpaceUser[]
68+
/// @url
69+
image String?
70+
lists List[]
71+
todos Todo[]
72+
accounts Account[]
7373
}
7474

7575
/// @@deny('all', auth() == null)
@@ -78,51 +78,51 @@ model User {
7878
/// @@allow('update', owner == auth() && space.members?[user == auth()] && future().owner == owner)
7979
/// @@allow('delete', owner == auth())
8080
model List {
81-
id String @id() @default(uuid())
82-
createdAt DateTime @default(now())
83-
updatedAt DateTime @updatedAt()
84-
space Space @relation(fields: [spaceId], references: [id], onDelete: Cascade)
85-
spaceId String
86-
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
87-
ownerId String
88-
/// @length(1, 100)
89-
title String
90-
private Boolean @default(false)
91-
todos Todo[]
81+
id String @id() @default(uuid())
82+
createdAt DateTime @default(now())
83+
updatedAt DateTime @updatedAt()
84+
space Space @relation(fields: [spaceId], references: [id], onDelete: Cascade)
85+
spaceId String
86+
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
87+
ownerId String
88+
/// @length(1, 100)
89+
title String
90+
private Boolean @default(false)
91+
todos Todo[]
9292
}
9393

9494
/// @@deny('all', auth() == null)
9595
/// @@allow('all', list.owner == auth())
9696
/// @@allow('all', list.space.members?[user == auth()] && !list.private)
9797
/// @@deny('update', future().owner != owner)
9898
model Todo {
99-
id String @id() @default(uuid())
100-
createdAt DateTime @default(now())
101-
updatedAt DateTime @updatedAt()
102-
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
103-
ownerId String
104-
list List @relation(fields: [listId], references: [id], onDelete: Cascade)
105-
listId String
106-
/// @length(1, 100)
107-
title String
108-
completedAt DateTime?
99+
id String @id() @default(uuid())
100+
createdAt DateTime @default(now())
101+
updatedAt DateTime @updatedAt()
102+
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
103+
ownerId String
104+
list List @relation(fields: [listId], references: [id], onDelete: Cascade)
105+
listId String
106+
/// @length(1, 100)
107+
title String
108+
completedAt DateTime?
109109
}
110110

111111
model Account {
112-
id String @id() @default(uuid())
113-
userId String
114-
type String
115-
provider String
116-
providerAccountId String
117-
refresh_token String?
118-
refresh_token_expires_in Int?
119-
access_token String?
120-
expires_at Int?
121-
token_type String?
122-
scope String?
123-
id_token String?
124-
session_state String?
125-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
112+
id String @id() @default(uuid())
113+
userId String
114+
type String
115+
provider String
116+
providerAccountId String
117+
refresh_token String?
118+
refresh_token_expires_in Int?
119+
access_token String?
120+
expires_at Int?
121+
token_type String?
122+
scope String?
123+
id_token String?
124+
session_state String?
125+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
126126
127-
@@unique([provider, providerAccountId])
128-
}
127+
@@unique([provider, providerAccountId])
128+
}

0 commit comments

Comments
 (0)