Skip to content

@sodacore/core

Provides the Application runtime, lifecycle hooks, script runner, threads/workers helpers, and the decorator/metadata glue that other packages (HTTP, WS, etc.) lean on.

Quick look

ts
import { Application } from '@sodacore/core';

const app = new Application({
	autowire: true,
});

app.start().catch(console.error);

Import surface (what you can use)

You import everything below from @sodacore/core unless noted.

Runtime & modules

  • Application — main entry point & lifecycle manager
  • Autowire — internal discovery module (usually not used directly)
  • Events — internal events dispatch (see @On below)
  • Services — runs annotated services on schedule / startup
  • Runner / Scripts — script registry & executor
  • Workers, WorkerWrapper — worker manager & per-worker helpers

Base classes (extend these)

  • BaseModule — shared module features (logging, registry helpers)
  • BasePlugin — implement a plugin (name, version, dependencies)
  • BaseService — long-running or scheduled logic
  • BaseTask — discrete unit of work (script/task)
  • BaseWorker — convenience wrapper for Node workers

Contexts

  • ScriptContext — I/O helpers for scripts (prompting, logging, sessions)
  • ThreadContext — metadata passed into threads

Providers (ready-made)

  • Logger — application logger
  • TasksProvider — register/lookup tasks
  • ThreadsProvider / WorkersProvider — manage lifecycles for threads/workers

Decorators (core glue)

  • @Hook('init' | 'start' | 'stop') — lifecycle hooks
  • @Script('key') — register a script
  • @Task('key', options?) — register a task
  • @Thread(name?, options?) / @Worker(name?, options?) — mark thread/worker providers
  • @Service(options?) — mark a service provider
  • @Autoload(glob | options) — auto-import modules for discovery
  • @Configure(schemaOrFn) — attach/validate configuration for a module/plugin
  • @Catch(mapper) — map thrown errors to structured results.

Helpers

  • Constants — common string constants / registry keys
  • Utils — small utility functions
  • WorkerUtils — worker-related utilities

Selected types

  • IConfig — Application config shape (top-level knobs; e.g., http, ws)
  • IPlugin{ name, version, dependencies? } contract for plugins
  • ILoggerType — logger interface used by Logger provider
  • IHookType'init' | 'start' | 'stop'
  • Constructor<T> — class ctor type
  • AsScript<T> — narrows a class to a script runner interface

Available Scripts

In the packages/core directory, you can run:

  • core:logs:watch - Watches the logs directory and outputs to console.
  • core:usage:info - Outputs the current memory and CPU usage of the application.
  • core:task:run - Will ask you what task you want to run, and will run it.

Notes

All features are defined properly within the Concepts section of the docs.

If you need more specific API documentation, we highly suggest reading the code directly as it's all documented inline.

Released under the Apache-2.0 License.