Repository navigation
feat(browser): BrowserDb.registerPredicate / registerAggregate (#180, PR 7) - #757
Merged
Merged
Conversation
… PR 7)
JS user functions in BrowserDb. Values reach JS as {type, value} objects
(Node's FactValue shape); finish's result is read as a bind value. A throw,
a non-boolean predicate result or a bad finish result fails the query with
QRY-014. Re-entry: query/prepare/register* run synchronously from a UDF;
execute/checkpoint/importGraph run after the outer query.
The crate forbids unsafe, so the registry holds ids into a thread-local
table of JS values instead of an unsafe Send + Sync wrapper; spec §6.2
updated. udf_aggregate/udf_predicate move to functions.rs, shared with
Minigraf's register methods.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Urda7FD9CYYoxdeGGJa11x
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Urda7FD9CYYoxdeGGJa11x
# Conflicts: # CHANGELOG.md
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Oct 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #180 (PR 7 of the plan, steps 21; step 22 is
minigraf-wasm's pin after this merges). Docs: project-minigraf/minigraf-docs (PR linked below), merge after this.What
BrowserDb.registerPredicate(name, fn)andBrowserDb.registerAggregate(name, { init, step, finish })(src/browser/udfs.rs), synchronous.{ type, value }objects, Node'sFactValueshape (integer →bigint, ref → UUID string, set → array of these).finish's result is read bybinds.rsas a bind value (plain or typed form).message, elseString(e)), a non-boolean predicate result, or afinishresult that is not a value →QRY-014.udf_aggregate/udf_predicatemove fromdb.rsintofunctions.rs, shared byMinigraf::register_*andBrowserDb.binds.rs:read_bind_valuetakes the full label (slot $x) so a UDF result can reuse it; bind error messages are unchanged.Deviation from the spec (§6.2 updated in this PR)
The spec had an
unsafe impl Send + Syncwrapper overjs_sys::Function. The crate is#![forbid(unsafe_code)], so instead the registry holds no JS value: functions and live accumulators sit in athread_local!table keyed by an id unique across threads, and the closures/accumulators hold only the id (Held, removing its entry on drop). A call on a thread whose table lacks the id fails withcalled off the JavaScript thread, as in Node. Nocfg(atomics)gating needed.borrow_mutauditgrep -n borrow_mut src/browser/mod.rs:checkpoint(async),import_graph(async),apply_write(async, underexecute), and one test. No synchronous method takesborrow_mut, so from inside a UDFquery,prepare,exportGraphandregister*run at once;execute/checkpoint/importGraphstart from a microtask after the outer query. Tests cover a nested query, a registration, andexecute+checkpointandimportGraphstarted inside a UDF.Tests
15 new
#[wasm_bindgen_test]s;wasm-pack test --headless --firefox --features browser: 58 passed locally (Chrome in CI).cargo clippy --all-featuresand wasm32 clippy clean;cargo test --test udf_test14/14. Codex review: two findings, both checked against the code and not reproduced (the failed-registration leak case now has an assertion).🤖 Generated with Claude Code
https://claude.ai/code/session_01Urda7FD9CYYoxdeGGJa11x