2.2.4 • Published 5 months ago

@hisorange/kernel v2.2.4

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
5 months ago

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.

2.2.1

5 months ago

2.2.0

5 months ago

2.2.3

5 months ago

2.2.2

5 months ago

2.2.4

5 months ago

2.1.0

5 months ago

2.0.0

10 months ago

1.4.1

12 months ago

1.4.0

1 year ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.0

2 years ago