Skip to content

Commit 1fe73f4

Browse files
committed
feat(vnext): add private parser worker protocol
1 parent 6e0e234 commit 1fe73f4

11 files changed

Lines changed: 2641 additions & 2 deletions

docs/adr/0004-isolated-parser-execution.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ The initial response contains only one closed outcome:
139139
- Parsed normalized statement kind
140140
- Syntax rejection
141141
- Bounded unsupported reason
142-
- Bounded failure code plus retryability
142+
- Bounded failure code; retryability is derived from that code
143143

144144
Messages do not contain:
145145

@@ -150,6 +150,11 @@ Messages do not contain:
150150
- Absolute document ranges
151151
- Raw ASTs or generic payload bags
152152

153+
The wire does not transport an independently supplied retryability boolean.
154+
The host treats only `module-load` as retryable; `backend` and
155+
`malformed-output` are terminal. A module-load failure closes the current
156+
worker generation so a retry cannot reuse a rejected dynamic-import realm.
157+
153158
The host requires the current protocol version and correlation ID, validates
154159
all keys and closed values, and copies accepted data into new frozen objects.
155160
It then constructs an authentic `SqlParserAnalysis` with the exact pending

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,43 @@ bundle. This blocks browser windows and Node DOM shims from exposing an
6060
unguarded secondary target. Pure Node loads restore the exact prior descriptors
6161
synchronously after module evaluation, including removing names that were
6262
previously absent. Cleanup failure permanently poisons loading. A
63-
dedicated-worker loader remains future work.
63+
dedicated-worker loader uses the same exact descriptor restoration rule within
64+
its isolated realm.
65+
66+
### Private browser worker endpoint
67+
68+
The package contains a production-shaped but private module-worker endpoint.
69+
It is not exported from the package and is not reachable through `/vnext`.
70+
There is no public worker constructor, executor, queue, language-service
71+
module, or session integration yet.
72+
73+
The endpoint:
74+
75+
- uses only the extension-qualified PostgreSQL and BigQuery builds above;
76+
- loads each grammar lazily after a valid request;
77+
- reuses the realm-neutral backend engine for module, AST, and parser-error
78+
normalization;
79+
- accepts and emits only a closed, versioned plain-data protocol;
80+
- returns normalized statement kind, bounded unsupported or failure evidence,
81+
and never returns source text, raw errors, or backend ASTs;
82+
- derives retryability from the closed failure code instead of trusting a
83+
separate wire flag;
84+
- restores the exact prior `NodeSQLParser` and `global` descriptors around
85+
each dynamic import; and
86+
- permanently poisons and closes its worker realm if cleanup cannot be proven
87+
exact.
88+
89+
The endpoint accepts only one request at a time. Overlap and malformed messages
90+
fail closed instead of creating an implicit worker-side queue. The future
91+
service-owned executor is responsible for serialization, correlation,
92+
deadlines, cancellation, generation replacement, and disposal.
93+
94+
Direct Chromium tests construct this source module worker and exercise both
95+
real grammar builds. The separate worker-placement fixture remains
96+
diagnostic packaging evidence: it records resource timing, emitted chunk
97+
reachability, and bundle sizes with a fixture-owned protocol. It is not the
98+
public integration boundary and must not be read as evidence that an executor
99+
or session API already exists.
64100

65101
Approximate local Node 24 arm64 measurements for the installed package were:
66102

scripts/package-smoke.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,21 @@ try {
169169
if (typeof packedPackage.dependencies?.["node-sql-parser"] !== "string") {
170170
throw new Error("Packed manifest does not declare node-sql-parser");
171171
}
172+
const privateWorkerArtifacts = [
173+
"dist/vnext/node-sql-parser-browser-worker.d.ts",
174+
"dist/vnext/node-sql-parser-browser-worker.js",
175+
"dist/vnext/node-sql-parser-browser-worker-endpoint.d.ts",
176+
"dist/vnext/node-sql-parser-browser-worker-endpoint.js",
177+
"dist/vnext/node-sql-parser-wire.d.ts",
178+
"dist/vnext/node-sql-parser-wire.js",
179+
];
180+
for (const artifact of privateWorkerArtifacts) {
181+
if (!existsSync(join(packageDirectory, artifact))) {
182+
throw new Error(
183+
`Packed archive omitted private worker artifact ${artifact}`,
184+
);
185+
}
186+
}
172187

173188
writeFileSync(
174189
join(temporaryDirectory, "vnext-consumer.mjs"),

0 commit comments

Comments
 (0)