UNPKG

2.84 kBMarkdownView Raw
1# mongodb-ace-autocompleter [![][npm_img]][npm_url]
2
3> Provides MongoDB [custom ACE Editor auto-completers](https://github.com/ajaxorg/ace/wiki/How-to-enable-Autocomplete-in-the-Ace-editor)
4
5## Usage
6
7### Aggregation Pipelines
8
9Provides completions within the context of an individual aggregation pipeline stage:
10
11```javascript
12import ace from 'ace-builds';
13import { StageAutoCompleter } from 'mongodb-ace-autocompleter';
14
15// Get the basic text completer from Ace for fallback suggestions.
16import tools from 'ace-builds/src-noconflict/ext-language_tools';
17const textCompleter = tools.textCompleter;
18
19// For auto completion of agg pipeline stages, pass the server version,
20// the text completer, the processed schema fields, and the stage operator.
21const stageAutoCompleter = new StageAutoCompleter(
22 '3.6.0',
23 textCompleter,
24 [{
25 name: 'name',
26 value: 'name',
27 score: 1,
28 meta: 'field',
29 version: '0.0.0'
30 }],
31 '$match'
32);
33tools.setCompleters([ stageAutoCompleter ]);
34```
35
36### Queries
37
38Provides completions within the context of a `find(query)`:
39
40```javascript
41import ace from 'ace-builds';
42import { QueryAutoCompleter } from 'mongodb-ace-autocompleter';
43
44// Get the basic text completer from Ace for fallback suggestions.
45import tools from 'ace-builds/src-noconflict/ext-language_tools';
46const textCompleter = tools.textCompleter;
47
48// For auto completion of queries, pass the server version,
49// the text completer, and the processed schema fields
50const queryAutoCompleter = new QueryAutoCompleter(
51 '3.6.0',
52 textCompleter,
53 [{
54 name: 'name',
55 value: 'name',
56 score: 1,
57 meta: 'field',
58 version: '0.0.0'
59 }]
60);
61tools.setCompleters([ queryAutoCompleter ]);
62```
63
64## Related
65
66- [`mongodb-js/ace-mode`](https://github.com/mongodb-js/ace-mode) MongoDB highlighting rules for ACE Editor.
67- [`mongodb-js/ace-theme`](https://github.com/mongodb-js/ace-theme) CSS highlighting styles for multiline ACE Editor.
68- [`mongodb-js/ace-theme-query`](https://github.com/mongodb-js/ace-theme-query) CSS highlighting styles for ACE Editor as single line input.
69- [`mongodb-js/stage-validator`](https://github.com/mongodb-js/stage-validator) Aggregation Pipeline Stage grammar.
70
71## Misc
72
73Utility function to convert from the fields returned from the field store to the
74Ace friendly format. (Can be done in a reducer in the app).
75
76```javascript
77const process = (fields) => {
78 return Object.keys(fields).map((key) => {
79 const field = key.indexOf('.') > -1 ? `"${key}"` : key;
80 return {
81 name: key,
82 value: field,
83 score: 1,
84 meta: 'field',
85 version: '0.0.0'
86 };
87 });
88};
89```
90
91## Release
92```npm run release```
93
94## License
95
96Apache 2.0
97
98[npm_img]: https://img.shields.io/npm/v/mongodb-ace-autocompleter.svg?style=flat-square
99[npm_url]: https://www.npmjs.org/package/mongodb-ace-autocompleter
100
\No newline at end of file