You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add .prettierrc.json config files
* Ran prettier --write in hadron-build
* Ran prettier --write in hadron-type-checker
* Ran prettier --write in mongodb-explain-compat
* Ran prettier --write in bson-transpilers
* Make "check" happy: Generated files
* Make "check" happy: Common eslint config
* Make "check" happy: Eslint fix
Copy file name to clipboardExpand all lines: packages/bson-transpilers/README.md
+75-45
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
1
# BSON-Transpilers
2
+
2
3
[![npm version][1]][2][![build status][3]][4]
3
4
[![downloads][5]][6]
4
5
@@ -8,6 +9,7 @@ provided for `shell` as inputs. `java`, `c#`, `node`, `shell`, `python`, `ruby`
8
9
See also the original presentation: https://drive.google.com/file/d/1jvwtR3k9oBUzIjL4z_VtpHvdWahfcjTK/view
9
10
10
11
**NOTES:**
12
+
11
13
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.
12
14
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.
Output a string containing the set of import statements for the generated code
48
54
to compile. These are all the packages that the compiled code could use so that
49
55
the transpiler output will be runnable.
50
-
-__inputLang:__ Input language of the code string. `shell` and `javascript`
56
+
57
+
-**inputLang:** Input language of the code string. `shell` and `javascript`
51
58
are currently supported.
52
-
-__outputLang:__ The language you would like the output to be. `java`,
59
+
-**outputLang:** The language you would like the output to be. `java`,
53
60
`python`, `shell`, `javascript`, and `csharp` are currently supported.
54
-
-__mode:__ Either 'Query' for the `.find()` method or 'Pipeline' for `.aggregate()`.
55
-
-__driverSyntax:__ Whether or not you want to include Driver Syntax into your output string.
61
+
-**mode:** Either 'Query' for the `.find()` method or 'Pipeline' for `.aggregate()`.
62
+
-**driverSyntax:** Whether or not you want to include Driver Syntax into your output string.
56
63
57
64
### catch (error)
65
+
58
66
Any transpiler errors that occur will be thrown. To catch them, wrap the
59
67
`transpiler` in a `try/catch` block.
60
-
-__error.message:__ Message `bson-transpilers` will send back letting you know
68
+
69
+
-**error.message:** Message `bson-transpilers` will send back letting you know
61
70
the transpiler error.
62
-
-__error.stack:__ The usual error stacktrace.
63
-
-__error.code:__[Error code]() that `bson-transpilers` adds to the error object to
71
+
-**error.stack:** The usual error stacktrace.
72
+
-**error.code:**[Error code]() that `bson-transpilers` adds to the error object to
64
73
help you distinguish error types.
65
-
-__error.line:__ If it is a syntax error, will have the line.
66
-
-__error.column:__ If it is a syntax error, will have the column.
67
-
-__error.symbol:__ If it is a syntax error, will have the symbol associated with the error.
68
-
74
+
-**error.line:** If it is a syntax error, will have the line.
75
+
-**error.column:** If it is a syntax error, will have the column.
76
+
-**error.symbol:** If it is a syntax error, will have the symbol associated with the error.
69
77
70
78
### State
71
79
72
-
The `CodeGenerationVisitor` class manages a global state which is bound to the `argsTemplate` functions. This state is intended to be used as a solution for the `argsTemplate` functions to communicate with the `DriverTemplate` function. For example:
80
+
The `CodeGenerationVisitor` class manages a global state which is bound to the `argsTemplate` functions. This state is intended to be used as a solution for the `argsTemplate` functions to communicate with the `DriverTemplate` function. For example:
The output of the driver syntax for this language will be the one-line statement `Hello World`.
88
96
89
97
#### DeclarationStore
90
-
A more practical use-case of state is to accumulate variable declarations throughout the `argsTemplate` to be rendered by the `DriverTemplate`. That is, the motivation for using `DeclarationStore` is to prepend the driver syntax with variable declarations rather than using non-idiomatic solutions such as closures.
91
98
92
-
The `DeclarationStore` class maintains an internal state concerning variable declarations. For example,
99
+
A more practical use-case of state is to accumulate variable declarations throughout the `argsTemplate` to be rendered by the `DriverTemplate`. That is, the motivation for using `DeclarationStore` is to prepend the driver syntax with variable declarations rather than using non-idiomatic solutions such as closures.
100
+
101
+
The `DeclarationStore` class maintains an internal state concerning variable declarations. For example,
Note that each use of the same variable name will result in an increment being added to the declaration statement. For example, if the variable name `objectIDForTemp` is used two times the resulting declaration statements will use `objectIDForTemp` for the first declaration and `objectID2ForTemp` for the second declaration. The `add` method returns the incremented variable name, and is therefore what would be expected as the right-hand side of the statement defined by the `argsTemplate` function.
117
+
Note that each use of the same variable name will result in an increment being added to the declaration statement. For example, if the variable name `objectIDForTemp` is used two times the resulting declaration statements will use `objectIDForTemp` for the first declaration and `objectID2ForTemp` for the second declaration. The `add` method returns the incremented variable name, and is therefore what would be expected as the right-hand side of the statement defined by the `argsTemplate` function.
109
118
110
119
The instance of the `DeclarationStore` constructed by the transpiler class is passed into the driver, syntax via state, for use:
0 commit comments