From ed93dd099f43dd6746276a72953485de91b49c8c Mon Sep 17 00:00:00 2001 From: nsfisis 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 --- src/server/routes/sync.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/server/routes/sync.ts') diff --git a/src/server/routes/sync.ts b/src/server/routes/sync.ts index ff95bf4..f05a7ba 100644 --- a/src/server/routes/sync.ts +++ b/src/server/routes/sync.ts @@ -26,6 +26,8 @@ const syncDeckSchema = z.object({ const syncCardSchema = z.object({ id: z.uuid(), deckId: z.uuid(), + noteId: z.uuid().nullable(), + isReversed: z.boolean().nullable(), front: z.string().min(1), back: z.string().min(1), state: z.number().int().min(0).max(3), @@ -53,10 +55,54 @@ const syncReviewLogSchema = z.object({ durationMs: z.number().int().min(0).nullable(), }); +const syncNoteTypeSchema = z.object({ + id: z.uuid(), + name: z.string().min(1).max(255), + frontTemplate: z.string(), + backTemplate: z.string(), + isReversible: z.boolean(), + createdAt: z.string().datetime(), + updatedAt: z.string().datetime(), + deletedAt: z.string().datetime().nullable(), +}); + +const syncNoteFieldTypeSchema = z.object({ + id: z.uuid(), + noteTypeId: z.uuid(), + name: z.string().min(1).max(255), + order: z.number().int().min(0), + fieldType: z.string(), + createdAt: z.string().datetime(), + updatedAt: z.string().datetime(), + deletedAt: z.string().datetime().nullable(), +}); + +const syncNoteSchema = z.object({ + id: z.uuid(), + deckId: z.uuid(), + noteTypeId: z.uuid(), + createdAt: z.string().datetime(), + updatedAt: z.string().datetime(), + deletedAt: z.string().datetime().nullable(), +}); + +const syncNoteFieldValueSchema = z.object({ + id: z.uuid(), + noteId: z.uuid(), + noteFieldTypeId: z.uuid(), + value: z.string(), + createdAt: z.string().datetime(), + updatedAt: z.string().datetime(), +}); + const syncPushSchema = z.object({ decks: z.array(syncDeckSchema).default([]), cards: z.array(syncCardSchema).default([]), reviewLogs: z.array(syncReviewLogSchema).default([]), + noteTypes: z.array(syncNoteTypeSchema).default([]), + noteFieldTypes: z.array(syncNoteFieldTypeSchema).default([]), + notes: z.array(syncNoteSchema).default([]), + noteFieldValues: z.array(syncNoteFieldValueSchema).default([]), }); const syncPullQuerySchema = z.object({ -- cgit v1.2.3-70-g09d2