Skip to content
Source
Sign inSign up
fuko/trytanstackdb-v2
Open History to see the last commit

schema.ts

59 lines1.8 KB

1import { z } from "zod";
2​
3/**
4 * The records the API serves. The fixtures, the fake server and the
5 * collections all share these schemas, so there's one set of types.
6 */
7​
8/** Folders with a role get special treatment in the sidebar. */
9export const folderRoleSchema = z.enum(["quick-notes", "default"]).nullable();
10​
11export const folderSchema = z.object({
12 id: z.string(),
13 name: z.string().min(1),
14 role: folderRoleSchema,
15 /** Sort order in the sidebar. */
16 position: z.number().int(),
17 createdAt: z.iso.datetime(),
18});
19​
20export const noteSchema = z.object({
21 id: z.string(),
22 folderId: z.string(),
23 title: z.string(),
24 /**
25 * Plain text, one block per line:
26 * `# Heading`, `- bullet`, `[ ] todo`, `[x] done`, anything else is a paragraph.
27 */
28 body: z.string(),
29 pinned: z.boolean(),
30 shared: z.boolean(),
31 createdAt: z.iso.datetime(),
32 updatedAt: z.iso.datetime(),
33 /** Set when the note is in Recently Deleted. */
34 deletedAt: z.iso.datetime().nullable(),
35});
36​
37export const sortNotesBySchema = z.enum(["dateEdited", "dateCreated", "title"]);
38export const newNoteStyleSchema = z.enum(["title", "heading", "body"]);
39​
40export const accountSchema = z.object({
41 id: z.string(),
42 name: z.string().min(1, "Name can't be empty"),
43 email: z.email("Enter a valid email address"),
44 plan: z.string(),
45 storageUsedGb: z.number(),
46 storageTotalGb: z.number(),
47 defaultFolderId: z.string(),
48 sortNotesBy: sortNotesBySchema,
49 newNotesStartWith: newNoteStyleSchema,
50 groupNotesByDate: z.boolean(),
51 createdAt: z.iso.datetime(),
52});
53​
54export type FolderRole = z.infer<typeof folderRoleSchema>;
55export type Folder = z.infer<typeof folderSchema>;
56export type Note = z.infer<typeof noteSchema>;
57export type SortNotesBy = z.infer<typeof sortNotesBySchema>;
58export type NewNoteStyle = z.infer<typeof newNoteStyleSchema>;
59export type Account = z.infer<typeof accountSchema>;