Skip to content

feat(bson-parsing)!: move parsing into web-worker COMPASS-11127 - #891

Draft
mabaasit wants to merge 9 commits into
consolidate-query-parser-in-bson-parserfrom
web-worker-parsing
Draft

mabaasit wants to merge 9 commits into
consolidate-query-parser-in-bson-parserfrom
web-worker-parsing

Conversation

@mabaasit

@mabaasit mabaasit commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

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 💬

@mabaasit
mabaasit added this pull request to stack #894 September 21, 2026 08:51
@mabaasit mabaasit changed the title feat(bson-parsin)!: move parsing into web-worker feat(bson-parsing)!: move parsing into web-worker Sep 21, 2026
@mabaasit mabaasit changed the title feat(bson-parsing)!: move parsing into web-worker feat(bson-parsing)!: move parsing into web-worker COMPASS-11127 Sep 22, 2026
Copilot AI lite review requested due to automatic review settings September 23, 2026 11:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 High severity · 1 Medium severity · 1 Low severity

Open (6)
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);
Sign up for free to 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