v0.1.0-alpha.4
·
36 commits
to main
since this release
What's New
Core Plugins — a new plugin tier for self-contained infrastructure services (logging, storage, environment) whose APIs are injected directly onto every regular plugin's context.
import { createCoreConfig, createCorePlugin } from "@moku-labs/core";
const logPlugin = createCorePlugin("log", {
config: { level: "info" },
createState: () => ({ entries: [] as string[] }),
api: ctx => ({
info: (msg: string) => { ctx.state.entries.push(msg); },
error: (msg: string) => { ctx.state.entries.push(`[ERROR] ${msg}`); },
}),
});
const { createPlugin, createCore } = createCoreConfig("my-app", {
config: { siteName: "My Site" },
plugins: [logPlugin],
pluginConfigs: { log: { level: "debug" } },
});
// Every regular plugin gets typed core APIs on context — no require() needed
const router = createPlugin("router", {
api: ctx => ({
navigate: (path: string) => {
ctx.log.info(`navigating to ${path}`); // fully typed
}
}),
});Features
createCorePlugin(name, spec)— new factory for core plugin instances. Supportsconfig,createState,api,onInit,onStart, andonStop.- Context injection — core plugin APIs are spread directly onto every regular plugin's context (
ctx.log,ctx.env, etc.) with full type inference. - 4-level config cascade — core plugin configs merge through all factory chain levels: spec defaults →
createCoreConfig→createCore→createApp. - Lifecycle ordering — core plugins initialize and start before regular plugins; stop after regular plugins.
- Self-contained by design — core plugins have no
depends,events, orhooks. Their context is limited to{ config, state }. Attempting to use forbidden fields is a compile error and a runtime error. pluginConfigsoncreateCoreConfig— framework authors can override core plugin defaults at registration time.
Type System
- New exported types:
CorePluginInstance,AnyCorePluginInstance,CoreApisFromTuple CoreApisgeneric parameter threaded throughPluginContext,App,AppCallbackContext,CreateAppOptions, andBoundCreatePluginFunction(defaults to{}— fully backward compatible)- Phantom types on
CorePluginInstancecarryconfig,state, andapishapes at compile time
Constraints
Core plugins are intentionally limited:
| Feature | Core Plugin | Regular Plugin |
|---|---|---|
config / createState / api |
✅ | ✅ |
onInit / onStart / onStop |
✅ | ✅ |
depends |
❌ | ✅ |
events |
❌ | ✅ |
hooks |
❌ | ✅ |
ctx.global / ctx.emit / ctx.require / ctx.has |
❌ | ✅ |
Breaking Changes
None. The CoreApis = {} default is the identity element for type intersection — all existing code compiles and behaves identically.