Skip to content

Commit

Permalink
feat(bson-transpiler)!: bump bson and remove unused inputs (#5410)
Browse files Browse the repository at this point in the history
* feat(bson-transpiler)!: remove unused inputs

* delete commented code

* chore: keep some of the js tests as shell

* feat: align js with shell

* chore: bump bson

* revert number decimal
  • Loading branch information
mcasimir committed Feb 15, 2024
1 parent c7f8cff commit 1c016da
Show file tree
Hide file tree
Showing 74 changed files with 6,366 additions and 34,289 deletions.
31 changes: 6 additions & 25 deletions package-lock.json

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

10 changes: 6 additions & 4 deletions packages/bson-transpilers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
[![downloads][5]][6]

Transpilers for building BSON documents in any language. Current support
provided for `shell` `javascript` and `python` as inputs. `java`, `c#`, `node`, `shell`, `python`, `ruby` and `go` as outputs.

> ⚠️  `shell` output produces code that is compatible only with legacy `mongo` shell not the new `mongosh` shell. See [COMPASS-4930](https://jira.mongodb.org/browse/COMPASS-4930) for some additional context
provided for `shell` as inputs. `java`, `c#`, `node`, `shell`, `python`, `ruby` and `go` as outputs.

See also the original presentation: https://drive.google.com/file/d/1jvwtR3k9oBUzIjL4z_VtpHvdWahfcjTK/view

**NOTES:**
1. A version of the code with support for `python` with corresponding test cases has been removed to avoid bundling and supporting unused code, however it can be still be found in https://github.com/mongodb-js/compass/tree/80cf701e44cd966207f956fac69e8233861b1cd5/packages/bson-transpilers.
2. The `shell` output is disabled as is essentially the only input in use and it produces code that is compatible only with legacy `mongo` shell not the new `mongosh` shell. See [COMPASS-4930](https://jira.mongodb.org/browse/COMPASS-4930) for some additional context.

# Usage

```js
const transpiler = require('bson-transpilers');

const input = 'javascript';
const input = 'shell';
const output = 'java';

const string =`
Expand Down
5 changes: 4 additions & 1 deletion packages/bson-transpilers/codegeneration/shell/Visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ module.exports = (JavascriptVisitor) => class Visitor extends JavascriptVisitor
ObjectId: bson.ObjectId,
BSONSymbol: bson.BSONSymbol,
Timestamp: bson.Timestamp,
Decimal128: bson.Decimal128,
Long: bson.Long,
Int32: bson.Int32,
Double: bson.Double,
Code: function(c, s) {
return new bson.Code(c, s);
},
Expand Down Expand Up @@ -94,7 +98,6 @@ module.exports = (JavascriptVisitor) => class Visitor extends JavascriptVisitor
} catch (error) {
throw new BsonTranspilersRuntimeError(error.message);
}

if ('emitNumberDecimal' in this) {
return this.emitNumberDecimal(ctx, decstr);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bson-transpilers/compile-symbol-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const loadSymbolTable = (dir, inputLang, outputLang) => {

const loadAll = () => {
const dir = path.join(__dirname, 'lib', 'symbol-table');
const inputLangs = ['javascript', 'shell', 'python'];
const inputLangs = ['shell'];
const outputLangs = ['java', 'shell', 'python', 'csharp', 'javascript', 'object', 'ruby', 'go', 'rust', 'php'];
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
Expand Down
Loading

0 comments on commit 1c016da

Please sign in to comment.