import type { RxDocumentData, WithDeleted, WithDeletedAndAttachments } from '../../types'; import { flatClone } from '../utils/index.ts'; export function appwriteDocToRxDB( appwriteDoc: any, primaryKey: string, deletedField: string ): WithDeleted { const useDoc: any = {}; Object.keys(appwriteDoc).forEach(key => { if (!key.startsWith('$')) { useDoc[key] = appwriteDoc[key]; } }); useDoc[primaryKey] = appwriteDoc.$id; useDoc._deleted = appwriteDoc[deletedField]; if (deletedField !== '_deleted') { delete useDoc[deletedField]; } return useDoc; } export function rxdbDocToAppwrite( rxdbDoc: WithDeletedAndAttachments, primaryKey: string, deletedField: string ) { const writeDoc: any = flatClone(rxdbDoc); delete (writeDoc as WithDeletedAndAttachments)._attachments; delete writeDoc[primaryKey]; writeDoc[deletedField] = writeDoc._deleted; if (deletedField !== '_deleted') { delete writeDoc._deleted; } return writeDoc; }