1.0.7 • Published 4 years ago
@dukai.net/hapi-repository-loader v1.0.7
hapi-repository-loader
One of the best feature of the hapi framework is the plug-in system. Usually in a case of the application not all plug-in comes from external sources. The application itself is organized into plug-ins. This component dynamically loads all data access layer (DAL) repositories from a directory structure.
Installation:
npm install @dukai.net/hapi-repository-loader
or:
yarn add @dukai.net/hapi-repository-loader
Use:
const dalLoader = require('@dukai.net/hapi-repository-loader');
// Example use, the result "dal" object will have all the plugin names as objects to access any plugin repository
const dal = await dalLoader({
args: {
myDalOption1: 'abc',
myDalOption2: 123
},
modules: ['alpha', 'beta', 'gamma']
});
// Example use of DAL object
const orders = await dal.alpha.getOrders();
// If I have plugin in the plugins folder 'inventory-check-things' (as subfolder), dal will have a camelcase object associated with it:
const inventory = await dal.inventoryCheckThings.getInventory();
Options:
// Options with their default values
const options = {
root: null, // no default, application must specify root folder.
path: 'plugins', // default directory name for plugins
subpath: '', // If repository objects are in a sub folder inside plugin subdirectory, then specified here
ext: '.js', // file extension name
name: 'repository', // default name for the repository file
org: 'dukai.net', // if the external repositories are in the node_modules folder then specify here the org scope
verbose: false, // If verbose set, then console log reports, which repository got loaded
args: {}, // Custom args to be passed down to each repository when created
modules: [] // Installed DAL module names from the node_modules directory, if different scopes used, then specify full scoped names here
};