The Core was created to load and manage SlimIO addons, it will create/handle communication between each addons.
Each addon are isolated from each others (designed like container above). You may be interested by the Gate addon as well if you want to learn how the core work and behave at higher level.
- Node.js v12 or higher
- (Re)loading addons.
- Manage communication between addons.
- Retention of communications in case of anomalies.
- Monitoring isolation.
The core as clean and well defined roles to be as much stable possible. Behavior related to addons communication and data exposition will be all related to the Gate addon (which is the right hand of the core). As an addon there is no way to talk to the core directly.
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @slimio/core
# or
$ yarn add @slimio/core
A script that demonstrate how to load a default core (Configuration will be created dynamically).
import "make-promises-safe";
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import Core from "@slimio/core";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
async function main() {
console.time("start_core");
const core = await (new Core(__dirname)).initialize();
console.timeEnd("start_core");
// Handle exit signal!
process.on("SIGINT", () => {
console.error("Exiting SlimIO Agent (please wait)");
core.exit().then(() => {
setImmediate(process.exit);
}).catch(function mainErrorHandler(error) {
console.error(error);
process.exit(1);
});
});
}
main().catch(console.error);
👀 Not that we use make-promises-safe to enforce Node.js DEP 00018.
The core register himself as a global with the name slimio_core
.
console.log(global.slimio_core);
The current core version is also available as global.coreVersion
.
constructor(dirname: string, options?: Core.ConstructorOptions)
Create a new instance of Core Object. The argument dirname
is the root directory where the core have to load his configuration and all addons.
The constructor take an optional options object which contain all options to configure the core Agent.
interface ConstructorOptions {
silent?: boolean;
autoReload?: number;
toml?: boolean;
}
initialize(): Promise< this >
Initialize the Core (it will load configuration and addons). The loading of addons is lazy, so the response will be returned before the addons have had time to fully load.
searchForLockedAddons(addonName: string): IterableIterator< string >
Search locked addons for a given addonName.
exit(): Promise< void >
Stop the core and all affiliated ressources (addons, config etc..).
Note: Think to exit the process with an iteration + 1 (with setImmediate).
Name | Refactoring | Security Risk | Usage |
---|---|---|---|
@slimio/addon | High | Addon default class | |
@slimio/config | Minor | High | Configuration interaction |
@slimio/ipc | High | Inter-process communication | |
@slimio/is | Minor | Low | Type checker |
@slimio/logger | Minor | Low | Sonic Logger with low overhead for SlimIO |
@slimio/safe-emitter | Minor | High | Safe emittter |
@slimio/scheduler | Minor | Low | Scheduler |
@slimio/utils | Minor | High | Bunch of useful functions |
is-stream | Minor | Low | TBC |
make-promises-safe | High | Promise not exit process when fail | |
semver | Low | Semver parser/utilities for node | |
@lukeed/uuid | Minor | Low | A tiny (230B), fast, and cryptographically secure UUID (v4) generator for Node and the browser |
MIT