') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Ryan capnweb compat by ryanrasti · Pull Request #83 · ryanrasti/typegres · GitHub
Skip to content

Ryan capnweb compat - #83

Merged
ryanrasti merged 1 commit into
mainfrom
ryan_capnweb_compat
Jul 14, 2026
Merged

Ryan capnweb compat#83
ryanrasti merged 1 commit into
mainfrom
ryan_capnweb_compat

Conversation

@ryanrasti

Copy link
Copy Markdown
Owner

No description provided.

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds end-to-end RPC coverage for typegres query-builder usage over two RPC mechanisms (exoeval-evaluated closures and capnweb record/replay closures), plus a capnweb shim that enforces the existing @expose capability surface across the RPC boundary.

Changes:

  • Added comprehensive integration tests for “typegres over exoeval RPC” and “typegres over capnweb RPC”, including @expose-gating scenarios and scalar/hydrate behaviors.
  • Introduced a capnweb toRpc/fromRpc shim + in-memory harness to adapt @expose capability objects to capnweb’s RPC model.
  • Updated query hydration to preserve the @expose field-marker (toolFieldsSymbol) on hydrated instances.

Reviewed changes

Copilot reviewed 8 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
src/rpc-exoeval.test.tsNew exoeval RPC end-to-end tests for query-builder composition and @expose gating.
src/rpc-capnweb.test.tsNew capnweb RPC end-to-end tests mirroring the exoeval scenarios.
src/capnweb/shim.tsNew capnweb shim to wrap/unwrap @expose objects/functions across RPC.
src/capnweb/shim.test.tsUnit + end-to-end tests validating shim behavior and RPC closure replay.
src/capnweb/harness.tsTest-only in-memory capnweb wiring for client/server session pairs.
src/builder/query.tsPreserve toolFieldsSymbol marker during hydrateRows instance construction.
package.jsonAdds local capnweb dependency via file:packages/capnweb.
.gitmodulesAdds packages/capnweb as a git submodule.
.gitignoreStops ignoring all packages/, only ignores packages/exoagent/.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/capnweb/shim.ts
Comment on lines +74 to +102
export const toRpc = (value: unknown): unknown => {
if (value === null || (typeof value !== "object" && typeof value !== "function")) {
return value;
}
if (typeof value === "function") {
return wrapOutgoingFunction(value as (...args: unknown[]) => unknown);
}
if (proxyTargets.has(value)) {
// Already a wrapper (e.g. a value that round-tripped through fromRpc and back).
return value;
}
if (value instanceof RpcTarget) {
// Already a native capnweb capability (stub, promise, or hand-written RpcTarget).
return value;
}
if (isThenable(value)) {
return value.then(toRpc);
}
if (Array.isArray(value)) {
return value.map(toRpc);
}
if (isPlainObject(value)) {
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, toRpc(v)]));
}
if (isRpcSerializableBuiltin(value)) {
return value;
}
return wrapInstance(value);
};
Comment threadpackage.json
Comment on lines 89 to 92
"dependencies": {
"camelcase": "^9.0.0"
"camelcase": "^9.0.0",
"capnweb": "file:packages/capnweb"
}
Comment thread.gitmodules
Comment on lines +1 to +3
[submodule "packages/capnweb"]
path = packages/capnweb
url = https://github.com/ryanrasti/capnweb.git

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 16 changed files in this pull request and generated 3 comments.

Comment threadsrc/exoeval/expr.ts Outdated
const proto = Object.getPrototypeOf(value)
return proto === null || proto === Object.prototype
}
import { isPlainObject } from '../util'
Comment threadpackage.json
Comment on lines 89 to 92
"dependencies": {
"camelcase": "^9.0.0"
"camelcase": "^9.0.0",
"capnweb": "file:packages/capnweb"
}
Comment thread.gitmodules
Comment on lines +1 to +3
[submodule "packages/capnweb"]
path = packages/capnweb
url = https://github.com/ryanrasti/capnweb.git
- Cap'n Web upstream based on cloudflare/capnweb#162, with extra commits to:
- (a) unwrap RpcStubs that point back to local objects (getLocalTarget)
- (b) replay record/replay closures synchronously instead of eagerly Promisifying them (so fully-local chains run sync end to end), plus allow zero-arg closures
- @expose <-> RpcTarget translation exposing only the members we manually @expose, and crucially unwrapping RpcStubs that point to local objects (the record-replay closures) back to their raw builder objects
@ryanrasti
ryanrastiforce-pushed the ryan_capnweb_compat branch from 3664982 to 4dc56fcCompareJuly 14, 2026 22:21
@ryanrasti
ryanrasti merged commit 30848e8 into mainJul 14, 2026
3 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@ryanrasti