aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/server/routes/sync.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-12-31 02:15:17 +0900
committernsfisis <nsfisis@gmail.com>2025-12-31 02:15:17 +0900
commited93dd099f43dd6746276a72953485de91b49c8c (patch)
treedb737032e32508b7de24d94696a13e4bfebe8978 /src/server/routes/sync.ts
parent78609e0b390e9a485c8935c17db6e0093660ebef (diff)
downloadkioku-ed93dd099f43dd6746276a72953485de91b49c8c.tar.gz
kioku-ed93dd099f43dd6746276a72953485de91b49c8c.tar.zst
kioku-ed93dd099f43dd6746276a72953485de91b49c8c.zip
feat(sync): add sync support for note-related entities
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>
Diffstat (limited to 'src/server/routes/sync.ts')
-rw-r--r--src/server/routes/sync.ts46
1 files changed, 46 insertions, 0 deletions
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({