@hisorange/kernel
TypeScript icon, indicating that this package has built-in type declarations

2.2.4 • Public • Published

Async Application Kernel

Version Build NPM GitHub Last Update License Coverage Status

Just my personal take on an async application kernel. It has injection management, simple module system, and a few other things.

Notable features are:

  • Dependency injection
  • Module with lifecycle hooks and dependency order
  • Scheduled tasks with CRON and injections
  • Built in event bus and respective decorators

Getting Started

yarn add @hisorange/kernel

Usage

const kernel = new Kernel();
kernel.register([MyModule, SecondModule]);

await kernel.boostrap();
await kernel.start();

process.on(
  'SIGINT',
  kernel.stop().then(() => process.exit(0)),
);

Module

@Module({
  providers: [],
  imports: [ConfigModule],
  dependsOn: [DatabaseModule],
})
export class MyModule implements IModule {
  public async onBoot() {
    // Executed in dependency order, you can setup your module here.
    // And the dependencies are already booted.
  }

  public async onStart() {
    // Runs after every module is booted.
    // Can do any async tasks here.
  }

  public async onStop() {
    // Called when a stop signal is received.
  }
}

Scheduler

@Scheduler()
export class MyScheduler {
  constructor(private readonly myService: MyService) {}

  @Job({
    name: 'my-named-job',
    timings: '*/5 * * * * *',
  })
  public async myJob() {
    this.myService.doSomething();
  }
}

Event Handler

@Observer()
export class MyObserver {
  constructor(private readonly myService: MyService) {}

  @On('sql.query', {
    debounce: 1_000,
  })
  public async onSqlQUery() {
    this.myService.doSomething();
  }
}

Once I gotta write a proper readme, but for now, this is it.

Readme

Keywords

none

Package Sidebar

Install

npm i @hisorange/kernel

Weekly Downloads

7

Version

2.2.4

License

GPL-3.0

Unpacked Size

109 kB

Total Files

89

Last publish

Collaborators

  • hisorangenpm