Public
Edited
Sep 2, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
toID("value")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
toID("name")
Insert cell
record({ x: "Uint32", y: "Uint32" })
Insert cell
toID("x")
Insert cell
record = (members) => {
const names = Object.keys(members);
const ids = names.map(toID).sort();
const fields = mapKeys(members, toID);
const body = [];
for (const [label, member] of Object.entries(members)) {
body.push({ id: toID(label), label, type: member });
}
return [
"record",
...body.sort((a, b) => (a.id < b.id ? 1 : a.id === b.id ? 0 : -1))
];
}
Insert cell
mapValues = (object, f) =>
Object.fromEntries(
Object.entries(object).map(([key, value]) => [key, f(value)])
)
Insert cell
mapKeys = (object, f) =>
Object.fromEntries(
Object.entries(object).map(([key, value]) => [f(key), value])
)
Insert cell
toID = (label) => {
const bytes = new TextEncoder().encode(label);
const { digest } = murmur3.murmur332.digest(bytes);
return base58.base58btc.encode(digest);
}
Insert cell
identify({ u8: {} })
Insert cell
identify = (syntax) =>
String(Link.create(CBOR.code, sha256.digest(CBOR.encode(syntax))))
Insert cell
toBuiltinID = (code) =>
String(Link.create(0x77, identity.digest(new Uint8Array([code]))))
Insert cell
murmur3 = import("https://esm.sh/@multiformats/murmur3")
Insert cell
base58 = import("https://esm.sh/multiformats/bases/base58")
Insert cell
sha256 = import("https://esm.sh/sync-multihash-sha2/sha256")
Insert cell
identity = (await import("https://esm.sh/multiformats/hashes/identity"))
.identity
Insert cell
Insert cell
import { CBOR } from "@gozala/ucanto"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more