ObjectStack Core Runtime & Query Engine
The runtime package provides the ObjectStackKernel - the central orchestrator for ObjectStack applications. It manages the application lifecycle, plugins, and the ObjectQL data engine.
npm install @objectstack/runtimeimport { ObjectStackKernel, ObjectQLPlugin } from '@objectstack/runtime';
import { InMemoryDriver } from '@objectstack/driver-memory';
const kernel = new ObjectStackKernel([
// Register ObjectQL engine
new ObjectQLPlugin(),
// Add database driver
new InMemoryDriver(),
// Add your app configurations
// appConfig,
]);
await kernel.start();If you have a separate ObjectQL implementation or need custom configuration:
import { ObjectStackKernel, ObjectQLPlugin, ObjectQL } from '@objectstack/runtime';
// Create custom ObjectQL instance
const customQL = new ObjectQL({
env: 'production',
customConfig: true
});
// Pre-configure with custom hooks
customQL.registerHook('beforeInsert', async (ctx) => {
console.log(`Inserting into ${ctx.object}`);
});
const kernel = new ObjectStackKernel([
// Use your custom ObjectQL instance
new ObjectQLPlugin(customQL),
// ... other plugins
]);
await kernel.start();For backward compatibility, the kernel will automatically initialize ObjectQL if no ObjectQLPlugin is provided:
// This still works, but will show a deprecation warning
const kernel = new ObjectStackKernel([
new InMemoryDriver(),
// ... other plugins
]);The kernel is responsible for:
- Orchestrating application lifecycle
- Managing plugins
- Coordinating the ObjectQL engine
- Handling data operations
The ObjectQLPlugin provides:
- Explicit ObjectQL engine registration
- Support for custom ObjectQL instances
- Clean separation of concerns
- Better testability
constructor(plugins: any[] = [])start(): Initialize and start the kernelfind(objectName, query): Query dataget(objectName, id): Get single recordcreate(objectName, data): Create recordupdate(objectName, id, data): Update recorddelete(objectName, id): Delete recordgetMetadata(objectName): Get object metadatagetView(objectName, viewType): Get UI view definition
constructor(ql?: ObjectQL, hostContext?: Record<string, any>)ql(optional): Custom ObjectQL instancehostContext(optional): Host context configuration
See the examples/ directory for complete examples:
examples/host/- Full server setup with Honoexamples/msw-react-crud/- Browser-based setup with MSWexamples/custom-objectql-example.ts- Custom ObjectQL instance
Before:
const kernel = new ObjectStackKernel([appConfig, driver]);After (Recommended):
const kernel = new ObjectStackKernel([
new ObjectQLPlugin(),
appConfig,
driver
]);After (Custom Instance):
const customQL = new ObjectQL({ /* config */ });
const kernel = new ObjectStackKernel([
new ObjectQLPlugin(customQL),
appConfig,
driver
]);MIT