Open History to see the last commit
1import accountJson from "./account.json";
2import foldersJson from "./folders.json";
3import notesJson from "./notes.json";
4import { accountSchema, folderSchema, noteSchema } from "./schema";
5import type { Account, Folder, Note } from "./schema";
6
7export * from "./schema";
8
9/**
10 * The fixtures were written as if "now" was this moment. When seeding, every
11 * timestamp is shifted by the same amount so "Today", "Yesterday" and
12 * "Previous 7 Days" still make sense whenever the app is opened.
13 */
14export const FIXTURES_WRITTEN_AT = "2026-11-03T19:40:00.000Z";
15
16export interface SeedData {
17 folders: Folder[];
18 notes: Note[];
19 account: Account;
20}
21
22export function createSeedData(now: Date = new Date()): SeedData {
23 const offset = now.getTime() - Date.parse(FIXTURES_WRITTEN_AT);
24 const shift = (iso: string) => new Date(Date.parse(iso) + offset).toISOString();
25
26 const folders = folderSchema.array().parse(foldersJson);
27 const notes = noteSchema.array().parse(notesJson);
28 const account = accountSchema.parse(accountJson);
29
30 return {
31 folders: folders.map((folder) => ({ ...folder, createdAt: shift(folder.createdAt) })),
32 notes: notes.map((note) => ({
33 ...note,
34 createdAt: shift(note.createdAt),
35 updatedAt: shift(note.updatedAt),
36 deletedAt: note.deletedAt ? shift(note.deletedAt) : null,
37 })),
38 account: { ...account, createdAt: shift(account.createdAt) },
39 };
40}