mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 16:55:37 +02:00
⭐ feat(www): Finish up on the onboarding (#210)
Merging this prematurely to make sure the team is on the same boat... like dang! We need to find a better way to do this. Plus it has become too big
This commit is contained in:
90
packages/zero/schema.ts
Normal file
90
packages/zero/schema.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import {
|
||||
table,
|
||||
string,
|
||||
number,
|
||||
createSchema,
|
||||
relationships,
|
||||
definePermissions,
|
||||
} from "@rocicorp/zero";
|
||||
|
||||
// TODO: Add Steam, and Machines here
|
||||
|
||||
const timestamps = {
|
||||
time_created: number(),
|
||||
time_deleted: number().optional(),
|
||||
} as const;
|
||||
|
||||
const team = table("team")
|
||||
.columns({
|
||||
id: string(),
|
||||
name: string(),
|
||||
slug: string(),
|
||||
plan_type: string<"Hosted" | "BYOG">(),
|
||||
...timestamps,
|
||||
})
|
||||
.primaryKey("id");
|
||||
|
||||
const member = table("member")
|
||||
.columns({
|
||||
id: string(),
|
||||
email: string(),
|
||||
team_id: string(),
|
||||
time_created: number(),
|
||||
time_seen: number().optional(),
|
||||
time_deleted: number().optional(),
|
||||
})
|
||||
.primaryKey("team_id", "id");
|
||||
|
||||
export const schema = createSchema(1, {
|
||||
tables: [team, member],
|
||||
relationships: [
|
||||
relationships(member, (r) => ({
|
||||
team: r.one({
|
||||
sourceField: ["team_id"],
|
||||
destSchema: team,
|
||||
destField: ["id"],
|
||||
}),
|
||||
members: r.many({
|
||||
sourceField: ["team_id"],
|
||||
destSchema: member,
|
||||
destField: ["team_id"],
|
||||
}),
|
||||
})),
|
||||
relationships(team, (r) => ({
|
||||
members: r.many({
|
||||
sourceField: ["id"],
|
||||
destSchema: member,
|
||||
destField: ["team_id"],
|
||||
}),
|
||||
})),
|
||||
],
|
||||
});
|
||||
|
||||
export type Schema = typeof schema;
|
||||
|
||||
type Auth = {
|
||||
sub: string;
|
||||
properties: {
|
||||
userID: string;
|
||||
email: string;
|
||||
};
|
||||
};
|
||||
|
||||
export const permissions = definePermissions<Auth, Schema>(schema, () => {
|
||||
return {
|
||||
member: {
|
||||
row: {
|
||||
select: [
|
||||
(auth, q) => q.exists("members", (u) => u.where("email", auth.sub)),
|
||||
],
|
||||
},
|
||||
},
|
||||
team: {
|
||||
row: {
|
||||
select: [
|
||||
(auth, q) => q.exists("members", (u) => u.where("email", auth.sub)),
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user