Public
Edited
Dec 12, 2023
Insert cell
Insert cell
Datalog = import("https://esm.sh/@datalogui/datalog")
Insert cell
People = Datalog.newTable({
id: Datalog.NumberType,
name: Datalog.StringType
})
Insert cell
People.assert({ id: 0, name: "Alice" })
Insert cell
People.assert({ id: 1, name: "Charles" })
Insert cell
People.assert({id: 2, name: "Helen"});
Insert cell
// Define a new table for the ParentOf Relation
ParentOf = Datalog.newTable({
parentID: Datalog.NumberType,
childID: Datalog.NumberType
})
Insert cell
ParentOf.assert({ parentID: 1, childID: 0 })
Insert cell
ParentOf.assert({ parentID: 2, childID: 0 })
Insert cell
Query = Datalog.query(({ parentName, parentID, childID }) => {
People({ name: "Alice", id: childID });
ParentOf({ childID, parentID });
People({ id: parentID, name: parentName });
})
Insert cell
Query.view().readAllData()
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
User = Datalog.newTable({
id: Datalog.NumberType,
name: Datalog.StringType,
email: Datalog.StringType
})
Insert cell
Comments = Datalog.newTable({
id: Datalog.NumberType,
userID: Datalog.NumberType,
comment: Datalog.StrintType
})
Insert cell
User.assert({
id: 10,
name: "Alice",
email: "alice@web.mail"
})
Insert cell
User.assert({
id: 11,
name: "Bob"
})
Insert cell
Comments.assert({
id: 101,
userID: 10,
comment: "This is cool comment"
})
Insert cell
comments = Datalog.query(({ userID, comment, id }) => {
User({ email: "alice@web.mail", id: userID });
Comments({ userID, comment, id });
})
Insert cell
comments.view().readAllData()
Insert cell
Insert cell
Proof = Datalog.newTable({
cid: Datalog.StringType,
issuer: Datalog.StringType,
audience: Datalog.StringType,
expiration: Datalog.NumberType,
notBefore: Datalog.NumberType
})
Insert cell
Capability = Datalog.newTable({
id: Datalog.StringType,
can: Datalog.StringType,
with: Datalog.StringType
// nb: Datalog.ObjectType
})
Insert cell
Delegates = Datalog.newTable({
capability: Datalog.StringType,
proof: Datalog.StringType
})
Insert cell
Delegation = ({
assert: (ucan) => {
Proof.assert({
cid: ucan.cid,
issuer: ucan.issuer,
audience: ucan.audience,
expiration: ucan.expiration,
notBefore: ucan.notBefore
});

for (const [n, capability] of ucan.capabilities.entries()) {
const id = `${ucan.cid}/capability/${n}`;
Capability.assert({
id,
can: capability.can,
with: capability.with,
nb: capability.nb
});

Delegates.assert({
capability: id,
proof: ucan.cid
});
}
}
})
Insert cell
Delegation.assert({
cid: "bafy...store",
issuer: "did:key:zAlice",
audience: "did:key:zBob",
expiration: (Date.now() / 1000) ^ (0 + 60 * 60 * 24 * 365),
capabilities: [
{
can: "store/add",
with: "did:key:zSpace"
}
]
})
Insert cell
Delegation.assert({
cid: "bafy...upload",
issuer: "did:key:zAlice",
audience: "did:key:zBob",
expiration: (Date.now() / 1000) ^ (0 + 60 * 60 * 24 * 365),
capabilities: [
{
can: "upload/add",
with: "did:key:zSpace"
}
]
})
Insert cell
proofs = Datalog.query(
({
//id,
//can
upload, store, uploadID, storeID, space
}) => {
Capability({ id: uploadID, can: "upload/add", with: space });
Capability({ id: storeID, can: "store/add", with: space });
Proof({ cid: upload });
Proof({ cid: store });
Delegates({ capability: uploadID, proof: upload });
Delegates({ capability: storeID, proof: store });
}
)
Insert cell
proofs.view().readAllData()
Insert cell
proofs.onDependencyChange(() => proofs.runQuery())
Insert cell
proofsView = proofs.view()
Insert cell
proofsView.recentData()
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