import { createSyncularBridgeClient, } from '@syncular/client';
export async function createSyncularNativeClient(options) {
    return createSyncularBridgeClient({
        ...options,
        bridge: createSyncularNativeBridge(options.module),
    });
}
export function createSyncularNativeBridge(module) {
    return {
        executeSql: (request) => module.executeSql(request),
        applyMutationsCommit: (batch) => module.applyMutationsCommit(batch),
        applyLeasedMutationsCommit: module.applyLeasedMutationsCommit?.bind(module),
        sync: module.sync?.bind(module),
        resumeFromBackground: module.resumeFromBackground?.bind(module),
        start: module.start?.bind(module),
        stop: module.stop?.bind(module),
        setSubscriptions: module.setSubscriptions?.bind(module),
        getStatus: module.getStatus?.bind(module),
        issueAuthLease: module.issueAuthLease?.bind(module),
        upsertAuthLease: module.upsertAuthLease?.bind(module),
        authLease: module.authLease?.bind(module),
        activeAuthLeases: module.activeAuthLeases?.bind(module),
        diagnosticSnapshot: module.diagnosticSnapshot?.bind(module),
        on: (event, listener) => removeable(module.addListener?.(event, listener)),
        presence: {
            get: (scopeKey) => module.getPresence?.(scopeKey) ?? [],
            join: (scopeKey, metadata) => module.joinPresence?.(scopeKey, metadata),
            leave: (scopeKey) => module.leavePresence?.(scopeKey),
            updateMetadata: (scopeKey, metadata) => module.updatePresenceMetadata?.(scopeKey, metadata),
            onChange: (listener) => removeable(module.addListener?.('presenceChanged', (event) => listener(event))),
        },
        conflicts: {
            list: () => module.conflictSummaries?.() ?? Promise.resolve([]),
            retryKeepLocal: (id) => module.retryConflictKeepLocal?.(id) ??
                Promise.reject(new Error('Syncular native module cannot retry conflicts.')),
            resolve: (id, resolution) => module.resolveConflict?.(id, resolution) ??
                Promise.reject(new Error('Syncular native module cannot resolve conflicts.')),
        },
    };
}
function removeable(subscription) {
    if (!subscription)
        return noop;
    return typeof subscription === 'function'
        ? subscription
        : () => subscription.remove();
}
function noop() { }
//# sourceMappingURL=index.js.map