Skip to content

v0.1.0-alpha.4

Choose a tag to compare

@AlexTiTanium AlexTiTanium released this 07 Mar 12:12
· 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. Supports config, createState, api, onInit, onStart, and onStop.
  • 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 → createCoreConfigcreateCorecreateApp.
  • Lifecycle ordering — core plugins initialize and start before regular plugins; stop after regular plugins.
  • Self-contained by design — core plugins have no depends, events, or hooks. Their context is limited to { config, state }. Attempting to use forbidden fields is a compile error and a runtime error.
  • pluginConfigs on createCoreConfig — framework authors can override core plugin defaults at registration time.

Type System

  • New exported types: CorePluginInstance, AnyCorePluginInstance, CoreApisFromTuple
  • CoreApis generic parameter threaded through PluginContext, App, AppCallbackContext, CreateAppOptions, and BoundCreatePluginFunction (defaults to {} — fully backward compatible)
  • Phantom types on CorePluginInstance carry config, state, and api shapes 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.