mongodb-ace-autocompleter

    0.1.0 • Public • Published

    mongodb-ace-autocompleter

    MongoDB Ace Autocompleter

    Usage with Ace editor

    Autocompletion on aggregation pipeline stages:

    import ace from 'brace';
    import { StageAutoCompleter } from 'mongodb-ace-autocompleter';
     
    // Get the basic text completer from Ace for fallback suggestions.
    const tools = ace.acequire('ace/ext/language_tools');
    const textCompleter = tools.textCompleter;
     
    // For auto completion of agg pipeline stages, pass the server version,
    // the text completer, the processed schema fields, and the stage operator.
    const stageAutoCompleter = new StageAutoCompleter(
      '3.6.0',
      textCompleter,
      [{
        name: 'name',
        value: 'name',
        score: 1,
        meta: 'field',
        version: '0.0.0'
      }],
      '$match'
    );
    tools.setCompleters([ stageAutoCompleter ]);

    Autocompletion on queries:

    import ace from 'brace';
    import { QueryAutoCompleter } from 'mongodb-ace-autocompleter';
     
    // Get the basic text completer from Ace for fallback suggestions.
    const tools = ace.acequire('ace/ext/language_tools');
    const textCompleter = tools.textCompleter;
     
    // For auto completion of queries, pass the server version,
    // the text completer, and the processed schema fields
    const queryAutoCompleter = new QueryAutoCompleter(
      '3.6.0',
      textCompleter,
      [{
        name: 'name',
        value: 'name',
        score: 1,
        meta: 'field',
        version: '0.0.0'
      }]
    );
    tools.setCompleters([ queryAutoCompleter ]);

    Utility function to convert from the fields returned from the field store to the Ace friendly format. (Can be done in a reducer in the app).

    const process = (fields) => {
      return Object.keys(fields).map((key) => {
        const field = key.indexOf('.') > -1 ? `"${key}"` : key;
        return {
          name: key,
          value: field,
          score: 1,
          meta: 'field',
          version: '0.0.0'
        };
      });
    };

    License

    Apache 2.0

    Keywords

    Install

    npm i mongodb-ace-autocompleter@0.1.0

    Version

    0.1.0

    License

    Apache-2.0

    Unpacked Size

    122 kB

    Total Files

    21

    Last publish

    Collaborators

    • chuck.kalmanek
    • mongodb-js-user
    • rueckstiess
    • durran
    • lerouxb
    • fredtruman
    • mbroadst
    • hswolff
    • satyasinha
    • matt_d_rat
    • rhysm
    • tomhollander
    • alena.khineika
    • jeff-allen-mongo
    • mmarcon
    • jonathan.balsano
    • mongodb-build
    • jack.weir
    • stennie
    • mcasimir
    • kristina.stefano
    • jarjee
    • shaketbaby
    • devtoolsbot
    • addaleax
    • rosem
    • gribnoysup
    • mutukrish