* Generic document sync for other platforms
( projectId: string, adapter: ReturnType<typeof useAdapter>, options?: SyncOptions, )
| 131 | * Generic document sync for other platforms |
| 132 | */ |
| 133 | async function syncGenericDocument( |
| 134 | projectId: string, |
| 135 | adapter: ReturnType<typeof useAdapter>, |
| 136 | options?: SyncOptions, |
| 137 | ): Promise<SyncResult> { |
| 138 | logInfo(`[Generic Sync] Starting sync for project: ${projectId}`); |
| 139 | options?.onProgress?.(10); |
| 140 | |
| 141 | try { |
| 142 | const fullText = await adapter.getFullText(); |
| 143 | options?.onProgress?.(50); |
| 144 | |
| 145 | const projectSnapshot: PlainMessage<UpsertProjectRequest> = { |
| 146 | projectId, |
| 147 | name: "Document", |
| 148 | rootDocId: "main", |
| 149 | docs: [ |
| 150 | { |
| 151 | id: "main", |
| 152 | version: Math.floor(Date.now() / 1000), |
| 153 | filepath: "document.txt", |
| 154 | lines: fullText.split("\n"), |
| 155 | } as PlainMessage<ProjectDoc>, |
| 156 | ], |
| 157 | }; |
| 158 | options?.onProgress?.(70); |
| 159 | |
| 160 | await upsertProject(projectSnapshot); |
| 161 | options?.onProgress?.(100); |
| 162 | logInfo("[Generic Sync] Successfully synced document to server"); |
| 163 | return { success: true }; |
| 164 | } catch (error) { |
| 165 | logError("[Generic Sync] Failed to sync:", error); |
| 166 | return { success: false, error: error as Error }; |
| 167 | } |
| 168 | } |
no test coverage detected