Stonyx Framework Core
Stonyx is an early-stage, TypeScript-first framework module designed for building modular applications, emphasizing a structured, object-oriented approach. It provides foundational concepts such as an `Application` class, `Context` management, and decorators like `@Component` and `@Service`, hinting at a dependency injection pattern. The package is currently in a pre-release state, with version 0.2.2 being the latest stable release, but development is active with frequent `0.2.3-beta` versions being published. This rapid iteration indicates that the API is subject to change and may not be stable. Stonyx aims to provide a robust core for larger application ecosystems, though specific use cases (e.g., web server, CLI tool) are not explicitly detailed in its current minimal documentation.
Common errors
-
TypeError: app.start is not a function
cause Attempting to call `start()` on an `Application` instance before it has been properly initialized or if the `createApplication` factory function was not used correctly.fixEnsure `createApplication` is used to construct the application instance and that `await app.start()` is called to initialize services and components before attempting to resolve or use them. -
Error: Cannot resolve dependency: MyService
cause A component or service dependency could not be found or instantiated by the dependency injection container. This often happens if the class was not included in the `components` array during application creation or if a provider is missing for a primitive type.fixVerify that all `@Component()` or `@Service()` classes are listed in the `components` array passed to `createApplication`. For non-class dependencies (e.g., config objects), ensure a corresponding `provider` is defined.
Warnings
- breaking Stonyx is in a very early pre-release stage (0.2.x with frequent beta updates). APIs are not stable and are subject to frequent breaking changes without major version bumps. Always pin exact versions in `package.json`.
- gotcha The documentation for Stonyx is extremely minimal at this stage. Most functionality and intended usage patterns must be inferred directly from the source code. This increases the learning curve and risk of misinterpreting features.
- gotcha As a 'base framework module', Stonyx likely requires other companion `stonyx-*` packages (e.g., for specific server integrations, plugins) to be fully functional in a real-world application. Without these, its utility might be limited to core application structure.
Install
-
npm install stonyx -
yarn add stonyx -
pnpm add stonyx
Imports
- createApplication
const { createApplication } = require('stonyx');import { createApplication } from 'stonyx'; - Application
import Application from 'stonyx';
import { Application } from 'stonyx'; - Service
import * as Stonyx from 'stonyx'; const MyService = Stonyx.Service;
import { Service } from 'stonyx';
Quickstart
import { createApplication, Component, Service } from 'stonyx';
interface MyConfig { message: string; }
@Component()
class MyComponent {
constructor(private config: MyConfig) {}
run() {
console.log(`Component running with message: ${this.config.message}`);
}
}
@Service()
class MyService {
constructor(private myComponent: MyComponent) {}
start() {
console.log('Service starting...');
this.myComponent.run();
}
}
async function bootstrap() {
const app = createApplication({
components: [MyComponent, MyService],
providers: [
{ provide: 'MyConfig', useValue: { message: 'Hello from Stonyx!' } }
]
});
await app.start();
const service = app.resolve(MyService);
service.start();
// In a real app, you might listen for termination signals or keep the process alive
// app.stop(); // Example of stopping the application
}
bootstrap().catch(console.error);