| 37 | import initSql from 'shared/sql.json' |
| 38 | |
| 39 | function noteToDocType(note: Note) { |
| 40 | const now = C.getDate().getTime() |
| 41 | return [ |
| 42 | { |
| 43 | id: toLDbId(note.id), |
| 44 | templateId: toLDbId(note.templateId), |
| 45 | created: now, |
| 46 | edited: now, |
| 47 | ankiNoteId: note.ankiNoteId, |
| 48 | }, |
| 49 | Array.from(note.tags).map((tag) => ({ tag, noteId: toLDbId(note.id) })), |
| 50 | objEntries(note.fieldValues).map(([field, value]) => ({ |
| 51 | noteId: note.id, |
| 52 | field, |
| 53 | value, |
| 54 | })), |
| 55 | objEntries(note.remotes).map(([nook, remote]) => ({ |
| 56 | note, |
| 57 | localId: toLDbId(note.id), |
| 58 | nook, |
| 59 | remoteId: toLDbId(remote?.remoteNoteId), |
| 60 | uploadDate: remote?.uploadDate.getTime(), |
| 61 | })), |
| 62 | ] satisfies [ |
| 63 | InsertObject<DB, 'noteBase'>, |
| 64 | Array<InsertObject<DB, 'noteTag'>>, |
| 65 | Array<InsertObject<DB, 'noteFieldValue'>>, |
| 66 | Array<InsertObject<DB, 'remoteNote'> & { note: Note }>, |
| 67 | ] |
| 68 | } |
| 69 | |
| 70 | function domainToCreateRemote( |
| 71 | { id, tags, fieldValues }: Note, |