Something went wrong. Try again.
an append only list
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import { sha256 } from "./utils"
export type Item = { key: string, // uuid for same logical item text: string, checked: boolean | null, created: number,}
export type Entry = { id: string, // append only log entry, content addressed sha created: number, item: Item,}
export function createItem(text: string): Item { const checkboxRegex = /^-? *\[ *\] */ const item: Item = { text, key: crypto.randomUUID(), checked: null, created: Date.now(), }
if (checkboxRegex.test(text)) { // looks like a checklist item.text = item.text.replace(checkboxRegex, '') item.checked = false }
return item}
export async function createEntry(item: Item): Promise<Entry> { const entry: Entry = { id: "", created: Date.now(), item, }
// content-addressed id for this immutable log entry // sort for stable id entry.id = await sha256(JSON.stringify(item, Object.keys(item).sort()))
return entry}