@dokebi/config

中文文档
0.4.5发布于 2026/11/05MITTypeScriptES Module近 30 天下载 2990

Validated immutable YAML configuration for Dokebi applications.

原始使用文档
文档目录3 节
  1. Configuration file
  2. Loading explicitly
  3. Checks and limits

@dokebi/config

Version 0.4.2 (unpublished). It is installed automatically as a required dependency of @dokebi/core. You never call app.register for it; it loads and checks YAML and prepares each app's read-only configuration. It creates no DB, Redis or NATS connections.

Configuration file

The runtime configuration is a single dokebi.yaml with schemaVersion: 1 and an options object. The app's and the plugins' settings under options are read through core's app.config. For example options.redis.connections.cache and options.redis.connections.coordination keep the settings of two independent connections apart. Each plugin's schema and runtime contract check the actual connection names, references and required values.

Keep the real file out of Git and share only a dokebi.example.yaml without secrets. There is no environment-variable substitution and no file merging, and the example file never replaces the real configuration. Reading the file again while the app runs is core's configuration reload (D-0154), which reads it with readConfigFile as loadConfig does.

Loading explicitly

import { Application, loadConfig } from "@dokebi/core";

const document = await loadConfig("dokebi.yaml");
const app = new Application({ config: document.options });
await app.start();
try {
  app.logger.log("info", "Application started");
} finally {
  await app.stop();
}

loadConfig(path, guard?) returns Promise<ConfigDocument<T>>, and parseConfig(text, guard?) returns the same document without file I/O. An optional type guard checks the real shape of options and lets TypeScript infer the type. You cannot skip the check by giving only a type argument. Constructing an Application never searches the current folder or reads a file. The configuration is readable right after construction and after stop, and it is isolated from later changes to the input object and from other apps.

The factory's app and the context.app of setup/start are the same ApplicationView. It is created once per app, frozen, and offers only state, config, logger and runtime; it has no start, stop, register or get. A plugin gets its options from app.config[<plugin name>].

Checks and limits

YAML is limited to one 1.2 document, 1 MiB, depth 64 and 10,000 nodes. Duplicate keys, anchors, aliases, explicit tags, merge keys and __proto__ are refused; plain constructor and prototype keys are allowed. Finite numbers are allowed, but integers must be JavaScript safe integers (-9007199254740991 to 9007199254740991). Write larger identifiers as quoted strings.

The size of programmatic input is a budget that adds up the UTF-8 length of strings and keys and a cost per node; it is not the same measurement as the file's raw byte limit. Passing the file limits does not mean a plugin's settings are valid for its purpose.

ConfigValidator's check(schema, options) returns an errors array and validate(schema, options) throws ConfigError on a data mismatch. It uses JSON Schema 2020-12 objects with a 128 KiB limit, strict mode, and no external references or async schemas. It never coerces types, injects defaults or removes extra fields. parseSchema(text) and loadSchema(path) read schemas. An invalid schema fails in check too. ConfigValidator({ allErrors?: boolean }) defaults to false.

ConfigError has code, line, column, issues, plugin ('dokebi-config') and fix. The codes are CONFIG_READ_FAILED, CONFIG_LIMIT_EXCEEDED, INVALID_YAML, INVALID_CONFIG, INVALID_OPTIONS_SCHEMA and INVALID_CONFIG_OPTIONS. Diagnostics never include the original values; the original cause is kept only where it holds no configuration value (CONFIG_READ_FAILED: the file system error; INVALID_OPTIONS_SCHEMA: the schema problem; INVALID_YAML from the YAML library: its name and code only). An error that is not the YAML's fault is thrown as it is. issues hold only instancePath and keyword, plus missingProperty (a field name from the schema, never a user value) for required errors. Never print the whole configuration object to a log yourself: it can expose secrets.

It uses yaml 2.9.1 (ISC) and Ajv 8.20.0. This package is MIT licensed and does not depend on core. See the AI guide and the config design notes in the repository.

版本与发布记录

@dokebi/config 共发布 10 个版本,首次发布于 2026/10/14;过去 12 个月发布了 10 个版本。

版本发布日期距今
0.4.5latest2026/11/058 天前
0.4.42026/11/0211 天前
0.4.32026/11/0112 天前
0.4.22026/10/3113 天前
0.4.12026/10/1628 天前
0.4.02026/10/1628 天前

关于 @dokebi/config 的常见问题

@dokebi/config 是什么?

Validated immutable YAML configuration for Dokebi applications.

如何安装 @dokebi/config?

在项目目录运行 npm install @dokebi/config,或使用 pnpm add / yarn add / bun add。

@dokebi/config 支持 TypeScript 吗?

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

@dokebi/config 支持 ESM 还是 CommonJS?

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

@dokebi/config 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dokebi/config 可以商用吗?

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

@dokebi/config 的下载量有多少?

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

@dokebi/config 还在维护吗?

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