feat(sql-editor): add JS/TS code cells with allowlisted imports#103
Merged
Conversation
Embed -- @js/-- @ts fences in the query editor so post-SQL transforms can run in a sandboxed worker with last/vars, required returns, and lodash/date-fns imports. Co-authored-by: Cursor <[email protected]>
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.
Embed -- @js/-- @ts fences in the query editor so post-SQL transforms can run in a sandboxed worker with last/vars, required returns, and lodash/date-fns imports.
Note
Medium Risk
User-supplied code runs in-browser via
new Function(mitigated by worker, timeout, and allowlist) and touches the shared statement-split/run pipeline; not server-side RCE but still untrusted script execution in the client.Overview
Adds JS/TypeScript code cells to the SQL editor so you can transform query results in the same script as SQL, using
-- @js/-- @ts…-- @endfences.Core (
@foxschema/core) extends statement splitting so fenced cells stay one statement (inner semicolons don’t split), exposesStatementKind, validates missing@end/ requiredreturn, and treats code cells as non-write statements.Execution runs cells in a Web Worker (sync fallback for tests) with a 5s timeout: TS is transpiled client-side,
lastis the prior statement’s grid,varsare non-secret editor variables, returns normalize to{ columns, rows }or object arrays with row caps. Sandboxednew Functionblocks network/DOM globals; allowlisted top-level imports only (lodash,lodash-es,date-fnsvia new deps).@setinside or above fences still applies from the first successful credential like SQL.UI & run loop: the statement strip shows JS/TS badges; results label code queries;
executebranches torunCodeCellper connection and disables paging for those steps. DataGrid styling is pinned via.fox-sql-gridso the light result table stays readable on soft-dark themes. User guide documents the feature; unit tests cover splitter, imports, and execution.Reviewed by Cursor Bugbot for commit 2a956b3. Bugbot is set up for automated code reviews on this repo. Configure here.