8000 feat: set values (#316) by adityamukho · Pull Request #19 · project-minigraf/minigraf-wasm · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
# Unreleased v3 core (format v8). Switches to version = "=3.0.0" at the v3.0.0 release.
minigraf = { git = "https://github.com/project-minigraf/minigraf", rev = "5f2ba46e0c5a9954d90e52f60daaad2128d91973", features = ["browser"] }
minigraf = { git = "https://github.com/project-minigraf/minigraf", rev = "7cdfcb483e35a5445e8f16aa854865985313002f", features = ["browser"] }

[features]
browser = ["minigraf/browser"]
Expand Down
9 changes: 9 additions & 0 deletions consumer-test/browser/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ async function run() {
}
check(typeof missing === 'string' && missing.startsWith('[API-022] '), `a missing slot is API-022 (${missing})`)

// Sets (minigraf#316): a set value comes back as an array, and binds as a
// JS Set or the typed form.
await mem.execute('(transact [[:alice :tags #{1 "x"}]])')
const tags = JSON.parse(await mem.execute('(query [:find ?t :where [?e :tags ?t]])')).results
check(JSON.stringify(tags) === '[[["x",1]]]', `a set value comes back as an array (${JSON.stringify(tags)})`)
const member = mem.prepare('(query [:find ?n :where [?e :tags ?t] [(in? 1 $s)] [?e :name ?n]])')
check(JSON.stringify(JSON.parse(member.execute({ s: new Set([1, 2]) })).results) === '[["Alice"]]', 'a JS Set binds')
check(JSON.stringify(JSON.parse(member.execute({ s: { type: 'set', value: [3] } })).results) === '[]', 'a typed set binds')

// Error type: a rejected promise whose reason starts with the error code,
// as on every other API ("[PRS-011] Unknown command: nosuchcommand").
let reason
Expand Down
13 changes: 13 additions & 0 deletions consumer-test/wasi/contract.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ function repl(lines) {
console.log("ok: in-memory transact and query");
}

// Sets (minigraf#316): a set literal is stored and printed back, and in? filters.
{
const r = repl([
'(transact [[:alice :tags #{1 "x"}]])',
"(query [:find ?t :where [?e :tags ?t]])",
"(query [:find ?t :where [?e :tags ?t] [(in? 2 ?t)]])",
]);
assert.match(r.stdout, /^#\{"?x"? 1\}$/m, `the set did not come back: ${r.stdout}`);
assert.match(r.stdout, /No results found/, "in? kept a row without 2");
assert.equal(r.stderr, "", "unexpected stderr");
console.log("ok: set values");
}

// Error type: an invalid command is reported with its code, and the REPL goes on.
{
const r = repl(["(nosuchcommand [])", "(query [:find ?n :where [?e :name ?n]])"]);
Expand Down
Loading
0