@trinacria/core
v0.1.1-alpha.0
Published
`@trinacria/core` is the runtime foundation of Trinacria.
Downloads
166
Readme
@trinacria/core
@trinacria/core is the runtime foundation of Trinacria.
It provides:
- typed dependency injection via tokens
- module boundaries (
imports,providers,exports) - plugin lifecycle hooks
- application startup/shutdown orchestration
Install
npm i @trinacria/coreQuick start
import {
TrinacriaApp,
createToken,
defineModule,
classProvider,
valueProvider,
} from "@trinacria/core";
type Clock = () => Date;
const CLOCK = createToken<Clock>("CLOCK");
const MESSAGE = createToken<string>("MESSAGE");
const GREETER = createToken<Greeter>("GREETER");
class Greeter {
constructor(
private readonly clock: Clock,
private readonly message: string,
) {}
hello(name: string) {
return `${this.message}, ${name} - ${this.clock().toISOString()}`;
}
}
const AppModule = defineModule({
name: "AppModule",
providers: [
valueProvider(CLOCK, () => new Date()),
valueProvider(MESSAGE, "Hello"),
classProvider(GREETER, Greeter, [CLOCK, MESSAGE]),
],
exports: [GREETER],
});
const app = new TrinacriaApp();
await app.registerModule(AppModule);
await app.start();
const greeter = await app.resolve(GREETER);
console.log(greeter.hello("Trinacria"));
await app.shutdown();What to add next
@trinacria/httpfor HTTP APIs@trinacria/eventsfor event bus and broker transports@trinacria/cronfor scheduled jobs
Links
- Repository: https://github.com/tascaenzo/trinacria
- Docs:
docs/enanddocs/itin the repository.
