UNPKG

2.8 kBMarkdownView Raw
1# mongodb-ace-autocompleter [![][travis_img]][travis_url] [![][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 'brace';
13import { StageAutoCompleter } from 'mongodb-ace-autocompleter';
14
15// Get the basic text completer from Ace for fallback suggestions.
16const tools = ace.acequire('ace/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 'brace';
42import { QueryAutoCompleter } from 'mongodb-ace-autocompleter';
43
44// Get the basic text completer from Ace for fallback suggestions.
45const tools = ace.acequire('ace/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.
67- [`mongodb-js/ace-theme`](https://github.com/mongodb-js/ace-theme) MongoDB syntax highlighting rules for ACE.
68- [`mongodb-js/stage-validator`](https://github.com/mongodb-js/stage-validator) Aggregation Pipeline Stage grammar.
69
70## Misc
71
72Utility function to convert from the fields returned from the field store to the
73Ace friendly format. (Can be done in a reducer in the app).
74
75```javascript
76const process = (fields) => {
77 return Object.keys(fields).map((key) => {
78 const field = key.indexOf('.') > -1 ? `"${key}"` : key;
79 return {
80 name: key,
81 value: field,
82 score: 1,
83 meta: 'field',
84 version: '0.0.0'
85 };
86 });
87};
88```
89
90## License
91
92Apache 2.0
93
94[travis_img]: https://travis-ci.org/mongodb-js/ace-autocompleter.svg?branch=master
95[travis_url]: https://travis-ci.org/mongodb-js/ace-autocompleter
96[npm_img]: https://img.shields.io/npm/v/mongodb-ace-autocompleter.svg?style=flat-square
97[npm_url]: https://www.npmjs.org/package/mongodb-ace-autocompleter