Skip to content

Commit 03da4cc

Browse files
committed
chore: sync playground with upstream
1 parent 751e758 commit 03da4cc

File tree

6 files changed

+17
-22
lines changed

6 files changed

+17
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { useQuery } from 'zero-vue'
2626
// see docs: https://zero.rocicorp.dev/docs/introduction
2727
const z = new Zero({
2828
userID,
29-
server: import.meta.env.VITE_ZERO_SERVER,
29+
server: import.meta.env.VITE_PUBLIC_SERVER,
3030
schema,
3131
kvStore: 'mem',
3232
})

playground/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ ZERO_CHANGE_DB="postgresql://user:[email protected]:5430/zstart_cdb"
44
ZERO_AUTH_SECRET="secretkey"
55
ZERO_REPLICA_FILE="/tmp/zstart_replica.db"
66

7-
VITE_ZERO_SERVER='http://localhost:4848'
7+
VITE_PUBLIC_SERVER='http://localhost:4848'

playground/docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
user: postgres
66
restart: always
77
healthcheck:
8-
test: pg_isready -U user --dbname=postgres
8+
test: 'pg_isready -U user --dbname=postgres'
99
interval: 10s
1010
timeout: 5s
1111
retries: 5

playground/docker/seed.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ CREATE TABLE "medium" (
1717

1818
CREATE TABLE "message" (
1919
"id" VARCHAR PRIMARY KEY,
20-
"senderID" VARCHAR REFERENCES "user"(id),
21-
"mediumID" VARCHAR REFERENCES "medium"(id),
20+
"sender_id" VARCHAR REFERENCES "user"(id),
21+
"medium_id" VARCHAR REFERENCES "medium"(id),
2222
"body" VARCHAR NOT NULL,
2323
"timestamp" TIMESTAMP not null
2424
);

playground/src/app.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const userID = decodedJWT?.sub ? (decodedJWT.sub as string) : 'anon'
1818
const z = new Zero({
1919
userID,
2020
auth: () => encodedJWT || undefined,
21-
server: import.meta.env.VITE_ZERO_SERVER,
21+
server: import.meta.env.VITE_PUBLIC_SERVER,
2222
schema,
2323
// This is often easier to develop with if you're frequently changing
2424
// the schema. Switch to 'idb' for local-persistence.

playground/src/db/schema.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
// See https://github.com/rocicorp/mono/blob/main/apps/zbugs/src/domain/schema.ts
66
// for more complex examples, including many-to-many.
77

8-
import type { ExpressionBuilder, Row } from '@rocicorp/zero'
8+
import type { ExpressionBuilder, PermissionsConfig, Row } from '@rocicorp/zero'
99
import {
1010
ANYONE_CAN,
1111
boolean,
1212
createSchema,
1313
definePermissions,
14-
NOBODY_CAN,
1514
number,
1615
relationships,
1716
string,
@@ -36,8 +35,8 @@ const medium = table('medium')
3635
const message = table('message')
3736
.columns({
3837
id: string(),
39-
senderID: string(),
40-
mediumID: string(),
38+
senderID: string().from('sender_id'),
39+
mediumID: string().from('medium_id'),
4140
body: string(),
4241
timestamp: number(),
4342
})
@@ -85,33 +84,29 @@ export const permissions = definePermissions<AuthData, Schema>(schema, () => {
8584
return {
8685
medium: {
8786
row: {
88-
insert: NOBODY_CAN,
89-
update: {
90-
preMutation: NOBODY_CAN,
91-
},
92-
delete: NOBODY_CAN,
87+
select: ANYONE_CAN,
9388
},
9489
},
9590
user: {
9691
row: {
97-
insert: NOBODY_CAN,
98-
update: {
99-
preMutation: NOBODY_CAN,
100-
},
101-
delete: NOBODY_CAN,
92+
select: ANYONE_CAN,
10293
},
10394
},
10495
message: {
10596
row: {
10697
// anyone can insert
10798
insert: ANYONE_CAN,
108-
// only sender can edit their own messages
10999
update: {
100+
// sender can only edit own messages
110101
preMutation: [allowIfMessageSender],
102+
// sender can only edit messages to be owned by self
103+
postMutation: [allowIfMessageSender],
111104
},
112105
// must be logged in to delete
113106
delete: [allowIfLoggedIn],
107+
// everyone can read current messages
108+
select: ANYONE_CAN,
114109
},
115110
},
116-
}
111+
} satisfies PermissionsConfig<AuthData, Schema>
117112
})

0 commit comments

Comments
 (0)