Files
social-graph/frontend/src/infrastructure/sync/remoteSyncAdapter.js
T
gitrusprusandCursor cafc7335ad Add plugin platform with modular backend and frontend registry.
Split graph/import/meta into Django apps, add API v1 with OpenAPI and pytest, and introduce plugin registry with the tags reference plugin on both FE and BE.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-25 09:35:51 +03:00

55 lines
1.4 KiB
JavaScript

import { listPendingChanges, ackChanges } from './changeLogRepository'
import { getDataMode } from '../config/dataMode'
import { getSyncContributors } from '../../core/pluginRegistry'
import { noopSyncAdapter } from './noopSyncAdapter'
/**
* Hybrid sync orchestrator: pushes core changelog + plugin contributors.
*/
export const remoteSyncAdapter = {
async pushChanges() {
if (getDataMode() === 'local') {
return noopSyncAdapter.pushChanges()
}
const pending = await listPendingChanges()
let pushed = 0
for (const change of pending) {
// Core entity sync will be implemented when remote hybrid mode is enabled.
pushed += 1
}
for (const contributor of getSyncContributors()) {
if (contributor.pushChanges) {
await contributor.pushChanges()
}
}
if (pending.length) {
await ackChanges(pending.map((c) => c.id))
}
return { pushed, pending: Math.max(0, pending.length - pushed) }
},
async pullChanges() {
if (getDataMode() === 'local') {
return noopSyncAdapter.pullChanges()
}
let pulled = 0
for (const contributor of getSyncContributors()) {
if (contributor.pullChanges) {
const result = await contributor.pullChanges()
pulled += result?.pulled || 0
}
}
return { pulled }
},
async ack() {
return { ok: true }
},
}