Skip to main content

Make Extension

Besides using the published extensions, you could also customize extensions by using our base extension components.

VulcanSQL provides 17 categories of extension to make you write your customized extension and put the base extension component into @vulcan-sql/core, @vulcan-sql/build, @vulcan-sql/serve separately.

You could customize your extension by extending 17 categories base extension components.

Create your extension package

  1. Create a extension folder and use npm init to set package information, e.g: my-extension.

    $ mkdir my-extension
    $ cd my-extension
    my-extension $ npm init

    Set your package name be my-first-extensions in package.json

  2. Install VulcanSQL base extension packages.

    Because base extension components existed in @vulcan-sql/core, @vulcan-sql/build, @vulcan-sql/serve separately.

    You could install these 3 packages all or according to which base extension you need to install its package.

    my-extension $ npm i @vulcan-sql/core @vulcan-sql/build @vulcan-sql/serve

Customize extension

Import the base extension class from the extension package under the my-extension folder.

Here is an sample for extending InputValidator class to MyValidator in the my-validator module file:

const { InputValidator } = require('@vulcan-sql/core');

class MyValidator extends InputValidator {
validateSchema(args) {
// implemented ...
}
validateData(value, args) {
// implemented ...
}
}

module.exports = { MyValidator };

Export customized extensions

  1. Create index file to be entry:

    my-extension $ touch index.js
  2. Export your customized extensions:

    You should export the extensions to make VulcanSQL could detect and load it for use.

    If you use module.exports to export your customized extension class.

    const { MyValidator } = require('./my-validator.js');

    module.exports = MyValidator;

    We also support 2 different way to use module.exports when you customized multiple extensions in the package:

    1. use module.exports extensions by array type when you customized multiple same type base extensions:
    const { MyValidator1 } = require('./my-validator1.js');
    const { MyValidator2 } = require('./my-validator2.js');

    module.exports = [MyValidator1, MyValidator2];
    1. use module.exports extensions by key-value type when you customized multiple different type base extensions:
    const { MyValidator1 } = require('./my-validator1.js');
    const { MyDataSource1 } = require('./my-data-source1.js');
    const { MyDataSource2 } = require('./my-data-source2.js');

    module.exports = {
    validators: MyValidator1;
    dataSources: [ MyDataSource1, MyDataSource2 ];
    }

    If you use exports to export your customized extension class, the exports is a module.exports alias, so same as above.

    const { MyValidator } = require('./my-validator.js');

    exports = MyValidator;

    You could also use exports to export multiple same type extensions.

    const { MyValidator1 } = require('./my-validator1.js');
    const { MyValidator2 } = require('./my-validator2.js');

    exports = [MyValidator1, MyValidator2];

    You could also use exports to export multiple different type extensions.

    const { MyValidator1 } = require('./my-validator1.js');
    const { MyDataSource1 } = require('./my-data-source1.js');
    const { MyDataSource2 } = require('./my-data-source2.js');

    exports = {
    validators: MyValidator1;
    dataSources: [ MyDataSource1, MyDataSource2 ];
    }

Use your customized extensions

You could use npm link to link extension package locally:

my-extension $ npm link

Or you could install local extension package by npm i <extension-package-folder>:

$ npm i /Users/<user-name>/Code/my-extension

After you installed local extension package, set the extension configuration in vulcan.yaml, same like our other extensions:

extensions:
my-extension: 'my-first-extensions' # package name

my-extension:
# my extension setting

Then use vulcan start to run it.