Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example Sync logger and censor for WatermelonDB Sync https://github.com/Nozbe/WatermelonDB/blob/master/docs/Advanced/Sync.md 🍉
// @flow
import { map, is } from 'rambdax'
import type { DirtyRaw } from '@nozbe/watermelondb/RawRecord'
import type { SyncLog } from '@nozbe/watermelondb/sync'
// beginning, end, length
const censorValue = (value: string): string =>
`${value.slice(0, 2)}***${value.slice(-2)}(${value.length})`
const shouldCensorKey = (key: string): boolean =>
key !== 'id' && !key.endsWith('_id') && key !== '_status' && key !== '_changed'
const censorRaw: DirtyRaw => DirtyRaw = map((value, key) =>
shouldCensorKey(key) && is(String, value) ? censorValue(value) : value,
)
const censorConflicts = map(map(censorRaw))
const censorLog = (log: SyncLog): SyncLog => ({
...log,
...(log.resolvedConflicts ? { resolvedConflicts: censorConflicts(log.resolvedConflicts) } : {}),
})
const censorLogs = map(censorLog)
export default class SyncLogger {
_logs: SyncLog[] = []
newLog(): SyncLog {
const log: SyncLog = {}
this._logs.push(log)
return log
}
get logs(): SyncLog[] {
// censor logs before viewing them
return censorLogs(this._logs)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.