From 48df8d8e7655ab9a7d982fc8809b9692c605b924 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 9 Jul 2024 14:59:50 +0200 Subject: [PATCH 1/2] Point to moved repo in README.md --- README.md | 84 ++----------------------------------------------------- 1 file changed, 2 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index 5128c3f..d340422 100644 --- a/README.md +++ b/README.md @@ -1,84 +1,4 @@ # ejson-shell-parser -Parses valid MongoDB EJSON 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. - -This library creates an AST from the proposed input, and then traverses this AST to check if it looks like a valid MongoDB query. If it does, the library will then evaluate the code to produce the parsed query. - -This library currently supports three different modes for parsing queries: - -**strict**: [default] Disallows comments and calling methods - -```javascript -import parse from 'ejson-shell-parser'; - -const query = parse( - `{ - _id: ObjectID("132323"), - simpleCalc: 6, - date: new Date(1578974885017) - }`, - { mode: 'strict' } -); - -/* - query = { _id: ObjectID("132323"), simpleCalc: 6, date: Date('1578974885017') } -*/ -``` - -**weak**: Disallows comments, allows calling methods - -```javascript -import parse from 'ejson-shell-parser'; - -const query = parse( - `{ - _id: ObjectID("132323"), - simpleCalc: Math.max(1,2,3) * Math.min(4,3,2) - }`, - { mode: 'weak' } -); - -/* - query = { _id: ObjectID("132323"), simpleCalc: 6 } -*/ -``` - -**loose**: Supports calling methods on Math, Date and ISODate, allows comments - -```javascript -import parse from 'ejson-shell-parser'; - -const query = parse( - `{ - _id: ObjectID("132323"), // a helpful comment - simpleCalc: Math.max(1,2,3) * Math.min(4,3,2) - }`, - { mode: 'loose' } -); - -/* - query = { _id: ObjectID("132323"), simpleCalc: 6 } -*/ -``` - -The options object passed into parse has the following parameters: - -```javascript -{ - mode: ('loose' || 'weak' || 'strict') // Will assign (allowMethods & allowComments) for you - allowMethods: true, // Allow function calls, ie Date.now(), Math.Max(), (new Date()).getFullYear() - allowComments: true, // Allow comments (// and /* */) -} -``` - -The flags can be set to override the default value from a given mode, ie: - -```javascript -{ - mode: 'strict', - allowComments: true -} -``` - -This options object will disallow method calls, but will allow comments +> [!IMPORTANT] +> This package has been moved to https://github.com/mongodb-js/devtools-shared/tree/main/packages/ejson-shell-parser. From b7aa52ff6ea48f780234192510ef324c15a6ce83 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 9 Jul 2024 15:23:48 +0200 Subject: [PATCH 2/2] account for package rename to @mongodb-js/shell-bson-parser --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d340422..db42a87 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # ejson-shell-parser > [!IMPORTANT] -> This package has been moved to https://github.com/mongodb-js/devtools-shared/tree/main/packages/ejson-shell-parser. +> This package has been moved to https://github.com/mongodb-js/devtools-shared/tree/main/packages/shell-bson-parser +> and renamed to `@mongodb-js/shell-bson-parser`.