Skip to content

Commit 6e0e234

Browse files
authored
refactor(vnext): extract realm-neutral parser backend (#179)
## Summary - extract module decoding, parser invocation, result validation, and error normalization into an internal realm-neutral backend - preserve Node-specific realm validation, module loading, cleanup, parser authority, and private AST ownership in the existing adapter - add exhaustive backend contract tests covering bounds, cancellation checkpoints, retry caching, hostile values, and ambient neutrality - document the host/engine responsibility boundary No public export, session wiring, worker protocol, or user-visible API is added. ## Validation - 1,041 unit tests passed; 1 intentional expected failure - vNext coverage: 98.54% statements, 97.06% branches, 100% functions, 98.53% lines - new backend coverage: 100% statements, branches, functions, and lines - source and test TypeScript checks - oxlint and test-integrity checks - Chromium browser tests - exact packed-consumer smoke test - isolated worker placement and bundle-budget harness - demo production build - parser adapter benchmark - git diff check ## Independent review Two independent adversarial reviewers approved exact commit 96bd2ce with zero actionable findings. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Extracted a new internal backend for `node-sql-parser` and rewired the Node adapter to call it. No public API changes. - **Refactors** - New `node-sql-parser-backend`: decodes module, runs `astify`, validates output, and normalizes errors; no Node/window/worker refs. - Node adapter now only handles realm checks, `require` loading, cleanup, parser authority, and private AST ownership; uses backend outcomes. - Unified backend outcomes; concurrent load de‑dup and retry cache; enforces `MAX_NODE_SQL_PARSER_STATEMENT_LENGTH`. - Accepts constructor/`default`/`module.exports`/named `Parser`; ignores accessors/proxies and redacts private data. - Added backend tests (bounds, cancellation, retry, hostile values, ambient neutrality) and documented the host/engine boundary. - **Bug Fixes** - Validate AST array lengths, rejecting spoofed or non‑integer length descriptors. <sup>Written for commit 08a9d67. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/179?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
1 parent a775bf4 commit 6e0e234

4 files changed

Lines changed: 1366 additions & 390 deletions

File tree

docs/vnext/node-sql-parser-adapter.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ statement slice. Locations remain partial: PostgreSQL commonly omits root and
4545
identifier locations, while BigQuery provides broader but still incomplete
4646
coverage.
4747

48+
Module-shape decoding, parser invocation, result validation, and error
49+
normalization live in a realm-neutral internal backend engine. That engine has
50+
no Node, browser-window, or worker dependency. The Node adapter remains
51+
responsible for realm validation, module loading, cleanup, parser authority,
52+
and private AST ownership. A browser worker can therefore reuse the same
53+
backend semantics without importing Node globals or weakening main-realm
54+
artifact authenticity.
55+
4856
Loading the distributed bundles may write `NodeSQLParser` or `global` on a
4957
global object. The adapter rejects parser loads whenever `window` or `self`
5058
exists, or `global` does not resolve exactly to `globalThis`, before loading a

0 commit comments

Comments
 (0)