@cosmicdrift/kumiko-framework

中文文档
0.419.0发布于 2026/11/11MITTypeScriptES Module构建来源已验证近 30 天下载 2.7万

Framework core — engine, pipeline, API, DB, and every other bit that makes Kumiko go.

原始使用文档
文档目录6 节
  1. Install
  2. At-a-glance
  3. Package exports
  4. Core concepts
  5. Status
  6. License

@cosmicdrift/kumiko-framework

License: MIT TypeScript

Framework core for Kumiko — engine, pipeline, API, DB, event-store, and every other bit that makes Kumiko go.

Multi-tenant, command-based, event-sourced app framework for Bun + Hono + Postgres. Define features, register entities, write commands — the framework wires dispatch, persistence, projections, async subscribers, and realtime delivery.

See the monorepo root README for the broader pitch, the docs/plans directory for architecture, and samples/ for runnable examples of every feature.

Install

bun add @cosmicdrift/kumiko-framework
# peers you probably already have:
bun add hono ioredis zod

Bun is the intended runtime and test runner.

At-a-glance

import { createEntity, createTextField, defineFeature } from "@cosmicdrift/kumiko-framework/engine";

export const taskEntity = createEntity({
  table: "read_tasks",
  fields: {
    title: createTextField({ required: true, searchable: true }),
    done: createTextField(),
  },
  softDelete: true,
});

export const taskFeature = defineFeature("tasks", (r) => {
  // r.crud wires create/update/delete/restore + list/detail queries in one
  // call — events + projection in the same TX, optimistic locking, access
  // control, all explicit via the options below.
  r.crud("task", taskEntity, {
    write: { access: { roles: ["User"] } },
    read: {
      access: {
        openToAll: {
          reason: "any signed-in user may list and view tasks; only writes are role-gated",
        },
      },
    },
  });

  // Read-model fed from task events, rebuildable via the CLI
  r.projection({
    name: "tasks-per-day",
    source: "task",
    table: tasksPerDayTable,
    apply: {
      "task.created": async (event, tx) => {
        /* count++ */
      },
    },
  });

  // Async consumer — runs after commit via the event-dispatcher,
  // cursor-based, at-least-once, per-consumer dead-letter semantics.
  // Omit `table` for pure side-effect handlers (mail, webhooks, ...).
  r.multiStreamProjection({
    name: "notify-new-task",
    apply: {
      "task.created": async (event) => {
        // e.g. push to an external notification service
      },
    },
  });
});

Package exports

EntryWhat's in it
@cosmicdrift/kumiko-framework/enginedefineFeature, createEntity, field helpers, access rules, registry
@cosmicdrift/kumiko-framework/dbderiveEntityTableMeta, createEventStoreExecutor, migrations, tenant-db
@cosmicdrift/kumiko-framework/event-storeevents table, append, loadAggregate, loadAggregateAsOf
@cosmicdrift/kumiko-framework/pipelineDispatcher, event-dispatcher (AsyncDaemon), projection-rebuild, SSE + search consumers
@cosmicdrift/kumiko-framework/apibuildServer, auth middleware, SSE route, error contract
@cosmicdrift/kumiko-framework/authJWT helper, password hashing, session users
@cosmicdrift/kumiko-framework/searchSearchAdapter interface, in-memory adapter, Meili wrapper
@cosmicdrift/kumiko-framework/jobsBullMQ-backed job runner, cron scheduling
@cosmicdrift/kumiko-framework/filesSigned-URL upload/download, tenant-scoped storage
@cosmicdrift/kumiko-framework/i18ni18next setup, per-feature translation registration
@cosmicdrift/kumiko-framework/uiReact hooks (Zustand stores, SSE subscription, optimistic mutations)
@cosmicdrift/kumiko-testing/stacksetupTestStack, createTestDb, request helpers
@cosmicdrift/kumiko-framework/utilsSafe JSON, qualified-name helpers
@cosmicdrift/kumiko-framework/errorsError classes, writeFailure, reason contracts

Core concepts

  • Feature as unit of deployment. defineFeature registers entities, write/query handlers, projections, post-event subscribers, lifecycle hooks, access rules, and translations.
  • Commands in, state out. Writes are commands dispatched through HTTP; the dispatcher validates, enforces access, runs lifecycle hooks, persists events, and triggers projections in a single TX.
  • Event-sourced by default. Every write goes through createEventStoreExecutor and appends a domain event to the aggregate stream. Auto-generated CRUD events (<entity>.created/updated/deleted/restored) for record writes, explicit ctx.events.append for domain events with intent. Projections feed off the stream for same-TX read-after-write consistency.
  • Async side-effects via cursor. SSE broadcast, search indexing, and feature-registered r.multiStreamProjection consumers run on a single cursor-based dispatcher (AsyncDaemon pattern). Per-consumer checkpoints, halt-on-poison, dead-letter after N retries.
  • Multi-tenant scoping. Every event, entity, projection, and search index carries tenantId. TenantDb is a TX-scoped wrapper that refuses writes outside the current tenant.
  • Optimistic concurrency. UNIQUE(aggregate_id, version) on events gives atomic append + conflict detection; VersionConflictError surfaces races as a first-class value.
  • Idempotency + dedup. Request-id backed unique index on the events table turns retries into replays. IdempotencyGuard caches write outcomes per tenant.

Status

This framework is pre-1.0 and evolves fast. Every feature has a runnable sample under samples/; the roadmap lives in docs/plans/uebersicht.md.

License

MIT, see LICENSE.

版本与发布记录

@cosmicdrift/kumiko-framework 共发布 551 个版本,首次发布于 2026/05/07;过去 12 个月发布了 551 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.419.0latest2026/11/11今天
0.418.02026/11/101 天前
0.417.02026/11/091 天前
0.416.02026/11/082 天前
0.415.02026/11/064 天前
0.414.02026/11/055 天前

其他发布通道:kumiko-tmp → 0.355.0。

关于 @cosmicdrift/kumiko-framework 的常见问题

@cosmicdrift/kumiko-framework 是什么?

Framework core — engine, pipeline, API, DB, and every other bit that makes Kumiko go.

如何安装 @cosmicdrift/kumiko-framework?

在项目目录运行 npm install @cosmicdrift/kumiko-framework,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:bun-types(^1.4.4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cosmicdrift/kumiko-framework 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cosmicdrift/kumiko-framework 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cosmicdrift/kumiko-framework 可以商用吗?

@cosmicdrift/kumiko-framework 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cosmicdrift/kumiko-framework 的下载量有多少?

根据 npm 官方下载统计,@cosmicdrift/kumiko-framework 在 2026/10/11 – 2026/11/09 这 30 天内被下载 26,827 次,日均约 894 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cosmicdrift/kumiko-framework 还在维护吗?

最新版本 0.419.0 发布于 2026/11/11(今天);至今共发布 551 个版本,其中过去 12 个月发布了 551 个;首次发布于 2026/05/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。