From ed93dd099f43dd6746276a72953485de91b49c8c Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Wed, 31 Dec 2025 02:15:17 +0900
Subject: feat(sync): add sync support for note-related entities
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Extend the sync system to handle NoteType, NoteFieldType, Note, and
NoteFieldValue entities. This includes:

- Server sync repository and routes for push/pull of new entities
- Client sync queue, push, pull, and conflict resolution for notes
- Update Card sync to include noteId and isReversed fields
- Add comprehensive tests for all sync functionality

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---
 src/client/stores/sync.tsx | 54 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

(limited to 'src/client/stores/sync.tsx')

diff --git a/src/client/stores/sync.tsx b/src/client/stores/sync.tsx
index 29c6c4f..aea5c16 100644
--- a/src/client/stores/sync.tsx
+++ b/src/client/stores/sync.tsx
@@ -22,6 +22,10 @@ import {
 import type {
 	ServerCard,
 	ServerDeck,
+	ServerNote,
+	ServerNoteFieldType,
+	ServerNoteFieldValue,
+	ServerNoteType,
 	ServerReviewLog,
 	SyncPullResult,
 } from "../sync/pull";
@@ -73,6 +77,33 @@ interface PullResponse {
 			reviewedAt: string;
 		}
 	>;
+	noteTypes: Array<
+		Omit<ServerNoteType, "createdAt" | "updatedAt" | "deletedAt"> & {
+			createdAt: string;
+			updatedAt: string;
+			deletedAt: string | null;
+		}
+	>;
+	noteFieldTypes: Array<
+		Omit<ServerNoteFieldType, "createdAt" | "updatedAt" | "deletedAt"> & {
+			createdAt: string;
+			updatedAt: string;
+			deletedAt: string | null;
+		}
+	>;
+	notes: Array<
+		Omit<ServerNote, "createdAt" | "updatedAt" | "deletedAt"> & {
+			createdAt: string;
+			updatedAt: string;
+			deletedAt: string | null;
+		}
+	>;
+	noteFieldValues: Array<
+		Omit<ServerNoteFieldValue, "createdAt" | "updatedAt"> & {
+			createdAt: string;
+			updatedAt: string;
+		}
+	>;
 	currentSyncVersion: number;
 }
 
@@ -141,6 +172,29 @@ async function pullFromServer(
 			...r,
 			reviewedAt: new Date(r.reviewedAt),
 		})),
+		noteTypes: data.noteTypes.map((n) => ({
+			...n,
+			createdAt: new Date(n.createdAt),
+			updatedAt: new Date(n.updatedAt),
+			deletedAt: n.deletedAt ? new Date(n.deletedAt) : null,
+		})),
+		noteFieldTypes: data.noteFieldTypes.map((f) => ({
+			...f,
+			createdAt: new Date(f.createdAt),
+			updatedAt: new Date(f.updatedAt),
+			deletedAt: f.deletedAt ? new Date(f.deletedAt) : null,
+		})),
+		notes: data.notes.map((n) => ({
+			...n,
+			createdAt: new Date(n.createdAt),
+			updatedAt: new Date(n.updatedAt),
+			deletedAt: n.deletedAt ? new Date(n.deletedAt) : null,
+		})),
+		noteFieldValues: data.noteFieldValues.map((v) => ({
+			...v,
+			createdAt: new Date(v.createdAt),
+			updatedAt: new Date(v.updatedAt),
+		})),
 		currentSyncVersion: data.currentSyncVersion,
 	};
 }
-- 
cgit v1.2.3-70-g09d2

