Skip to content

Commit 12b7278

Browse files
authored
chore: add missing prettier configs (#6280)
* 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
1 parent a646b08 commit 12b7278

File tree

105 files changed

+14078
-13833
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+14078
-13833
lines changed

Diff for: package-lock.json

+4-725
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/bson-transpilers/.prettierignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SyntaxError: Aliased anchor not found: ...
2+
symbols/basic_types.yaml
3+
symbols/import_templates.yaml
4+
symbols/python/symbols.yaml
5+
symbols/python/types.yaml
6+
symbols/shell/symbols.yaml
7+
symbols/shell/types.yaml
8+
symbols/syntax_templates.yaml
9+
10+
# Generated files
11+
lib/antlr/
12+
lib/symbol-table/

Diff for: packages/bson-transpilers/.prettierrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"@mongodb-js/prettier-config-compass"

Diff for: packages/bson-transpilers/CONTRIBUTING.md

+103-63
Large diffs are not rendered by default.

Diff for: packages/bson-transpilers/README.md

+75-45
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# BSON-Transpilers
2+
23
[![npm version][1]][2] [![build status][3]][4]
34
[![downloads][5]][6]
45

@@ -8,6 +9,7 @@ provided for `shell` as inputs. `java`, `c#`, `node`, `shell`, `python`, `ruby`
89
See also the original presentation: https://drive.google.com/file/d/1jvwtR3k9oBUzIjL4z_VtpHvdWahfcjTK/view
910

1011
**NOTES:**
12+
1113
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.
1214
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.
1315

@@ -19,7 +21,7 @@ const transpiler = require('bson-transpilers');
1921
const input = 'shell';
2022
const output = 'java';
2123

22-
const string =`
24+
const string = `
2325
{ item: "book", qty: Int32(10), tags: ["red", "blank"], dim_cm: [14, Int32("81")] }`;
2426

2527
try {
@@ -34,95 +36,106 @@ try {
3436
```
3537

3638
## API
39+
3740
### compiledString = transpiler\[inputLang\]\[outputLang\].compile(codeString)
41+
3842
Output a compiled string given input and output languages.
39-
- __inputLang:__ Input language of the code string. `shell` and `javascript`
43+
44+
- **inputLang:** Input language of the code string. `shell` and `javascript`
4045
are currently supported.
41-
- __outputLang:__ The language you would like the output to be. `java`,
46+
- **outputLang:** The language you would like the output to be. `java`,
4247
`python`, `shell`, `javascript`, and `csharp` are currently supported.
43-
- __codeString:__ The code string you would like to be compiled to your
48+
- **codeString:** The code string you would like to be compiled to your
4449
selected output language.
4550

4651
### importsString = transpiler\[inputLang\]\[outputLang\].getImports(mode, driverSyntax)
52+
4753
Output a string containing the set of import statements for the generated code
4854
to compile. These are all the packages that the compiled code could use so that
4955
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`
5158
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`,
5360
`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.
5663

5764
### catch (error)
65+
5866
Any transpiler errors that occur will be thrown. To catch them, wrap the
5967
`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
6170
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
6473
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.
6977

7078
### State
7179

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:
7381

7482
```yaml
75-
ObjectIdEqualsArgsTemplate: &ObjectIdEqualsArgsTemplate !!js/function >
76-
(_) => {
77-
this.oneLineStatement = "Hello World";
78-
return '';
79-
}
80-
81-
DriverTemplate: &DriverTemplate !!js/function >
82-
(_spec) => {
83-
return this.oneLineStatement;
84-
}
83+
ObjectIdEqualsArgsTemplate: !!js/function &ObjectIdEqualsArgsTemplate >
84+
(_) => {
85+
this.oneLineStatement = "Hello World";
86+
return '';
87+
}
88+
89+
DriverTemplate: !!js/function &DriverTemplate >
90+
(_spec) => {
91+
return this.oneLineStatement;
92+
}
8593
```
8694
8795
The output of the driver syntax for this language will be the one-line statement `Hello World`.
8896

8997
#### 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.
9198

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,
93102

94103
```javascript
95104
// within the args template
96105
(arg) => {
97-
return this.declarations.add("Temp", "objectID", (varName) => {
106+
return this.declarations.add('Temp', 'objectID', (varName) => {
98107
return [
99108
`${varName}, err := primitive.ObjectIDFromHex(${arg})`,
100109
'if err != nil {',
101110
' log.Fatal(err)',
102-
'}'
103-
].join('\n')
104-
})
105-
}
111+
'}',
112+
].join('\n');
113+
});
114+
};
106115
```
107116

108-
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.
109118

110119
The instance of the `DeclarationStore` constructed by the transpiler class is passed into the driver, syntax via state, for use:
111120

112121
```javascript
113122
(spec) => {
114-
const comment = '// some comment'
115-
const client = 'client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(cs.String()))'
116-
return "#{comment}\n\n#{client}\n\n${this.declarations.toString()}"
117-
}
123+
const comment = '// some comment';
124+
const client =
125+
'client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(cs.String()))';
126+
return '#{comment}\n\n#{client}\n\n${this.declarations.toString()}';
127+
};
118128
```
119129

120130
### Errors
131+
121132
There are a few different error classes thrown by `bson-transpilers`, each with
122133
their own error code:
123134

124135
#### BsonTranspilersArgumentError
136+
125137
###### code: E_BSONTRANSPILERS_ARGUMENT
138+
126139
This will occur when you're using a method with a wrong number of arguments, or
127140
the arguments are of the wrong type.
128141
For example, `ObjectId().equals()` requires one argument and it will throw if
@@ -145,21 +158,25 @@ ObjectId();
145158
```
146159

147160
#### BsonTranspilersAttributeError
161+
148162
###### code: E_BSONTRANSPILERS_ATTRIBUTE
163+
149164
Will be thrown if an invalid method or property is used on a BSON object. For
150165
example, since `new DBRef()` doesn't have a method `.foo()`, transpiler will
151166
throw:
152167

153168
```javascript
154169
// ✘: method foo doesn't exist, so this will throw a BsonTranspilersAttributeError .
155-
new DBRef('newCollection', new ObjectId()).foo()
170+
new DBRef('newCollection', new ObjectId()).foo();
156171

157172
// ✔: this won't throw, since .toString() method exists
158-
new DBRef('newCollection', new ObjectId()).toString(10)
173+
new DBRef('newCollection', new ObjectId()).toString(10);
159174
```
160175

161176
#### BsonTranspilersSyntaxError
177+
162178
###### code: E_BSONTRANSPILERS_SYNTAX
179+
163180
This will throw if you have a syntax error. For example missing a colon in
164181
Object assignment, or forgetting a comma in array definition:
165182

@@ -176,57 +193,70 @@ Object assignment, or forgetting a comma in array definition:
176193
```
177194

178195
#### BsonTranspilersTypeError
196+
179197
###### code: E_BSONTRANSPILERS_TYPE
198+
180199
This error will occur if a symbol is treated as the wrong type. For example, if
181200
a non-function is called:
182201

183202
```javascript
184203
// ✘: MAX_VALUE is a constant, not a function
185-
Long.MAX_VALUE()
204+
Long.MAX_VALUE();
186205

187206
// ✔: MAX_VALUE without a call will not throw
188-
Long.MAX_VALUE
207+
Long.MAX_VALUE;
189208
```
209+
190210
#### BsonTranspilersUnimplementedError
211+
191212
###### code: E_BSONTRANSPILERS_UNIMPLEMENTED
213+
192214
If there is a feature in the input code that is not currently supported by the
193215
transpiler.
194216

195217
#### BsonTranspilersRuntimeError
218+
196219
###### code: E_BSONTRANSPILERS_RUNTIME
220+
197221
A generic runtime error will be thrown for all errors that are not covered by the
198222
above list of errors. These are usually constructor requirements, for example
199223
when using a `RegExp()` an unsupported flag is given:
200224

201225
```javascript
202226
// ✘: these are not proper 'RegExp()' flags, a BsonTranspilersRuntimeError will be thrown.
203-
new RegExp('ab+c', 'beep')
227+
new RegExp('ab+c', 'beep');
204228

205229
// ✔: 'im' are proper 'RegExp()' flags
206-
new RegExp('ab+c', 'im')
230+
new RegExp('ab+c', 'im');
207231
```
208232

209233
#### BsonTranspilersInternalError
234+
210235
###### code: E_BSONTRANSPILERS_INTERNAL
236+
211237
In the case where something has gone wrong within compilation, and an error has
212238
occured. If you see this error, please create [an issue](https://github.com/mongodb-js/bson-transpilers/issues) on Github!
213239

214240
# Install
241+
215242
```shell
216243
npm install -S bson-transpilers
217244
```
218245

219246
## Contributing
247+
220248
Head over to the readme [on contributing](./CONTRIBUTING.md) to find out more
221249
information on project structure and setting up your environment.
222250

223251
# Authors
252+
224253
- [aherlihy](https://github.com/aherlihy) - Anna Herlihy <[email protected]>
225254
- [alenakhineika](https://github.com/alenakhineika) - Alena Khineika <[email protected]>
226255
- [lrlna](github.com/lrlna) - Irina Shestak <[email protected]>
227256

228257
# License
229-
[Apache-2.0](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
258+
259+
[Apache-2.0](<https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)>)
230260

231261
[1]: https://img.shields.io/npm/v/bson-transpilers.svg?style=flat-square
232262
[2]: https://npmjs.org/package/bson-transpilers

0 commit comments

Comments
 (0)