feat: register databases by key and validate paths at setup#52
Open
onehumandev wants to merge 1 commit into
Open
feat: register databases by key and validate paths at setup#52onehumandev wants to merge 1 commit into
onehumandev wants to merge 1 commit into
Conversation
ccf9564 to
fe23ba5
Compare
jjhafer
requested changes
Jun 15, 2026
fe23ba5 to
bb03278
Compare
velocitysystems
suggested changes
Jun 15, 2026
velocitysystems
left a comment
Contributor
There was a problem hiding this comment.
Great work carrying over the improvements from #50. Just a couple of observations:
- Keys are now indirected to paths, and nothing dedupes them. Two keys pointing at the same file create two independent
DbInstancespools over one store. remove()is frontend‑reachable and deletes the file, orphaning the other key's live pool;close()can tear down a shared handle; per‑key migrations double‑run against one file.- For named shared‑cache :memory: URIs it's worse — closing one pool can destroy the in‑memory store the other key is still using.
Should we fail‑fast on duplicate canonical paths at register_database, or guard teardown by reverse‑indexing canonical paths?
Replace path-as-identifier IPC with explicit key registration so the frontend and Rust callers open databases by stable keys (e.g. "MAIN") instead of filesystem paths. Paths are resolved once in Rust during plugin setup, validated, and cached; later opens only look up the key. Problems solved: - Security: untrusted frontend can no longer supply arbitrary paths over IPC; unknown keys fail with PATH_NOT_REGISTERED. - Cross-language identity: avoids TS/Rust path string mismatches (separators, symlinks, canonicalization) on every load. - Runtime path discovery: `on_setup` + `SetupRegistrar` register paths from `app.path()` / platform resolvers once, without repeat JNI or resolver work on each open. - Consistent open path: `load`, `Connection::connect`, and migrations share `connect_to_database` and the same `DbInstances` cache, along with assurance that migrations have completed before connecting to the database. - Safer registration: `validate_database_path` rejects relative paths, traversal, null bytes, and canonicalizes file paths at startup (fail-fast INVALID_PATH / PATH_TRAVERSAL). API changes: - `add_migrations(path, migrator)` → `register_database(key, path, migrator?)` (returns Result; adds `Builder::on_setup` / `SetupRegistrar`) - IPC/command args: `db` → `dbKey`; attached `databasePath` → `databaseKey` - `MigrationEvent`: adds `dbKey`, `dbPath` is now absolute PathBuf - `TransactionToken`: `dbPath` → `dbKey` - `Connection` trait on `AppHandle` for Rust-side opens by key Also: expose `canonicalize_database_path` from conn-mgr, tighten `is_memory_database` query-param matching, add toolkit `:memory:` tests, update README/guest-js rustdoc, and add `validate.rs` (replaces load-time path resolution in `resolve.rs`).
bb03278 to
2db8db8
Compare
Author
Addressed here |
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.
Replace path-as-identifier IPC with explicit key registration so the frontend and Rust callers open databases by stable keys (e.g. "MAIN") instead of filesystem paths. Paths are resolved once in Rust during plugin setup, validated, and cached; later opens only look up the key.
Problems solved:
on_setup+SetupRegistrarregister paths fromapp.path()/ platform resolvers once, without repeat JNI or resolver work on each open.load,Connection::connect, and migrations shareconnect_to_databaseand the sameDbInstancescache, along with assurance that migrations have completed before connecting to the database.validate_database_pathrejects relative paths, traversal, null bytes, and canonicalizes file paths at startup (fail-fast INVALID_PATH / PATH_TRAVERSAL).API changes:
add_migrations(path, migrator)→register_database(key, path, migrator?)(returns Result; addsBuilder::on_setup/SetupRegistrar)db→dbKey; attacheddatabasePath→databaseKeyMigrationEvent: addsdbKey,dbPathis now absolute PathBufTransactionToken:dbPath→dbKeyConnectiontrait onAppHandlefor Rust-side opens by keyAlso: expose
canonicalize_database_pathfrom conn-mgr, tightenis_memory_databasequery-param matching, add toolkit:memory:tests, update README/guest-js rustdoc, and addvalidate.rs(replaces load-time path resolution inresolve.rs).