Conversation
mabaasit
added this pull request to stack #894
September 21, 2026 08:51
mabaasit
force-pushed
the
web-worker-parsing
branch
from
September 23, 2026 11:19
e5d8ab7 to
a596dfa
Compare
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Critical API, compatibility, browser-runtime, and BSON-cloning issues remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 4
Open (6)
Removing CommonJS entry breaks CommonJS consumers · New Synchronous query-parser consumer breaks with async default API · New Duck-typed BSON detection corrupts valid documents · New Unguarded process access crashes browser parsing · New Concurrent worker initialization leaks duplicate workers · New README documents outdated synchronous parse API · New
What changed in this PR
Moves BSON parsing into a web worker while adding structured-clone support, an explicit synchronous API, and ESM/Webpack tooling.
Changes:
- Adds worker communication, lifecycle management, and BSON serialization.
- Makes default parsing asynchronous while retaining synchronous parsing.
- Updates tests, packaging, build configuration, and the MQL docs crawler.
| File | Review summary |
|---|---|
packages/shell-bson-parser/webpack.worker.config.cjs |
Bundles the worker target. |
packages/shell-bson-parser/tsconfig.json |
Enables NodeNext resolution. |
packages/shell-bson-parser/test/parse-test-cases.ts |
Updates ESM imports and test typing. |
packages/shell-bson-parser/src/worker.ts |
Handles worker parse requests. |
packages/shell-bson-parser/src/worker-types.ts |
Defines worker messages. |
packages/shell-bson-parser/src/worker-client.ts |
Critical: browser process access can throw. Moderate: concurrent initialization can leak workers, and termination can leave requests unresolved. |
packages/shell-bson-parser/src/structured-clone-bson.ts |
Critical: _bsontype duck typing can corrupt valid plain documents after cloning. |
packages/shell-bson-parser/src/structured-clone-bson.spec.ts |
Tests BSON round trips. |
packages/shell-bson-parser/src/stringify.spec.ts |
Updates ESM imports. |
packages/shell-bson-parser/src/parse.ts |
Updates internal ESM imports. |
packages/shell-bson-parser/src/parse.spec.ts |
Updates imports and Sinon usage. |
packages/shell-bson-parser/src/index.ts |
Critical: the async default API breaks synchronous query-parser usage. Nit: README examples remain synchronous. |
packages/shell-bson-parser/src/index.spec.ts |
Moderate: tests bypass the bundled worker path and do not cover the real worker artifact. |
packages/shell-bson-parser/src/eval.ts |
Updates an internal import. |
packages/shell-bson-parser/src/check.ts |
Updates internal imports. |
packages/shell-bson-parser/package.json |
Critical: removing the CommonJS condition breaks CommonJS consumers. Moderate: type: module breaks the existing CommonJS benchmark. |
packages/shell-bson-parser/.mocharc.cjs |
Adds shared Mocha configuration. |
packages/shell-bson-parser/.eslintrc.cjs |
Ignores the Webpack configuration. |
packages/mql-typescript/src/driverSchema/docs-crawler.ts |
Uses the synchronous parser API. |
package-lock.json |
Locks updated Webpack dependencies. |
configs/mocha-config-devtools/register/tsnode-register.js |
Adds NodeNext test-loader support. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+25
to
+29
| "type": "module", | ||
| "main": "dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "exports": { | ||
| "require": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| }, | ||
| "import": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/.esm-wrapper.mjs" | ||
| } | ||
| "types": "./dist/index.d.ts", |
|
|
||
| export const parse = ( | ||
| ...args: Parameters<typeof parseSync> | ||
| ): Promise<ReturnType<typeof parseSync>> => callWorker(args); |
Comment on lines
+25
to
+26
| function isBsonValue(value: object): value is { _bsontype: string } { | ||
| return typeof (value as { _bsontype?: unknown })._bsontype === 'string'; |
| } | ||
|
|
||
| async function getWorkerBlobUrl(): Promise<string> { | ||
| if (process.env.TEST_SKIP_WORKER_SCRIPT_FETCH) { |
Comment on lines
+48
to
+52
| if (worker) { | ||
| return worker; | ||
| } | ||
|
|
||
| blobUrl = await getWorkerBlobUrl(); |
Comment on lines
+6
to
+8
| export const parse = ( | ||
| ...args: Parameters<typeof parseSync> | ||
| ): Promise<ReturnType<typeof parseSync>> => callWorker(args); |
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.



In draft because
I need to spend a bit more on (de)serialization (Neal is working on something very similar) and bundling.I need to figure out the sync -> async api change for mongodb-query-parser package. This changes happened in this PR and for monorepo, it resolves to the local export and not the one pinned in package.json file.
Description
COMPASS-11127
Open Questions
Checklist
Stack created with GitHub Stacks CLI • Give Feedback 💬