0.3.0 • Published 2 months ago

@canvas-js/okra v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@canvas-js/okra

NPM version TypeScript types

Install

npm i @canvas-js/okra

Usage

import { sync } from "@canvas-js/okra"
import { MemoryTree } from "@canvas-js/okra-memory"

const source = await MemoryTree.open()
const target = await MemoryTree.open()

const hex = (hex: string) => Buffer.from(hex, "hex")

await source.set(hex("00"), hex("aa"))
await target.set(hex("00"), hex("aa"))

await source.set(hex("01"), hex("bb"))

await source.set(hex("02"), hex("cc"))
await target.set(hex("02"), hex("dd"))

async function collect<T>(iter: AsyncIterable<T>): Promise<T[]> {
	const values = []
	for await (const value of iter) {
		values.push(value)
	}
	return values
}

const delta = await collect(sync(source, target))
console.log(delta)
// [
//   { key: <Buffer 01>, source: <Buffer bb>, target: null },
//   { key: <Buffer 02>, source: <Buffer cc>, target: <Buffer dd> }
// ]