Skip to content

Commit

Permalink
feat: rename ejson-shell-parser to @mongodb-js/shell-bson-parser (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax authored Jul 9, 2024
1 parent 58a36ff commit 37f3bf9
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 93 deletions.
189 changes: 110 additions & 79 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/query-parser/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Please refer to [the list of BSON changes](https://github.com/mongodb/js-bson/bl

MongoDB Query Parser was making use of [`safer-eval`](https://www.npmjs.com/package/safer-eval) to parse difficult queries, which has been removed as this dependency is insecure.

We've replaced this dependency with [`ejson-shell-parser`](https://github.com/mongodb-js/ejson-shell-parser), which instead walks the AST of the query, and only attempts to evaluate the query if it considered safe and well-formed.
We've replaced this dependency with [`@mongodb-js/shell-bson-parser`](https://github.com/mongodb-js/devtools-shared/tree/main/packages/shell-bson-parser), which instead walks the AST of the query, and only attempts to evaluate the query if it considered safe and well-formed.

Because of this change, some queries that would validate are no longer valid.

Expand Down
2 changes: 1 addition & 1 deletion packages/query-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"dependencies": {
"debug": "^4.3.4",
"ejson-shell-parser": "^2.0.2",
"@mongodb-js/shell-bson-parser": "^1.0.0",
"javascript-stringify": "^2.1.0",
"lodash": "^4.17.21"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/query-parser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import parseShellStringToEJSON, { ParseMode } from 'ejson-shell-parser';
import parseShellStringToEJSON, {
ParseMode,
} from '@mongodb-js/shell-bson-parser';

import _ from 'lodash';
import _debug from 'debug';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# ejson-shell-parser

> [!CAUTION]
> Despite its name, this package does _not_ handle MongoDB Extended JSON (EJSON). It only parses shell syntax representations of BSON.
> For example, it parses `ObjectId("668d112bafd4c98000a17f44")` but not `{ "$oid": "668d112bafd4c98000a17f44" }`.
# @mongodb-js/shell-bson-parser

Parses valid MongoDB Shell queries.
This library does not validate that these queries are correct. It's focus is on parsing untrusted input. You may wish to use something like https://github.com/mongodb-js/mongodb-language-model to achieve this.
Expand All @@ -14,7 +10,7 @@ This library currently supports three different modes for parsing queries:
**strict**: [default] Disallows comments and calling methods

```javascript
import parse from 'ejson-shell-parser';
import parse from '@mongodb-js/shell-bson-parser';

const query = parse(
`{
Expand All @@ -33,7 +29,7 @@ const query = parse(
**weak**: Disallows comments, allows calling methods

```javascript
import parse from 'ejson-shell-parser';
import parse from '@mongodb-js/shell-bson-parser';

const query = parse(
`{
Expand All @@ -51,7 +47,7 @@ const query = parse(
**loose**: Supports calling methods on Math, Date and ISODate, allows comments

```javascript
import parse from 'ejson-shell-parser';
import parse from '@mongodb-js/shell-bson-parser';

const query = parse(
`{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ejson-shell-parser",
"name": "@mongodb-js/shell-bson-parser",
"description": "Parse valid MongoDB shell syntax queries",
"author": {
"name": "MongoDB Inc",
Expand All @@ -13,7 +13,7 @@
"email": "[email protected]"
},
"homepage": "https://github.com/mongodb-js/devtools-shared",
"version": "2.0.2",
"version": "1.0.0",
"repository": {
"type": "git",
"url": "https://github.com/mongodb-js/devtools-shared.git"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { expect } from 'chai';
import type { SinonSandbox } from 'sinon';
import { createSandbox } from 'sinon';

describe('ejson-shell-parser', function () {
describe('@mongodb-js/shell-bson-parser', function () {
it('should correctly parse a valid object', function () {
expect(parse('{_id:"hello"}')).to.deep.equal({ _id: 'hello' });
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 37f3bf9

Please sign in to comment.