@dforge-core/metadata

中文文档
0.0.53发布于 2026/11/11MITTypeScriptES Module零依赖近 30 天下载 3014

Canonical dForge authoring registries — field types, base datatypes, column types, traits, data-view kinds and chart types — with derivation helpers. Runtime-dependency-free; the single source of truth shared by editors, the web app and the CLI.

原始使用文档
文档目录10 节
  1. Install
  2. What's inside
  3. Registries & derivation
  4. Traits
  5. Module-file types
  6. Action DSL
  7. JSON schemas
  8. Source of truth & parity
  9. Scripts
  10. License

@dforge-core/metadata

Canonical dForge authoring registries, module-file types, and JSON schemas — the single source of truth shared by the web app, the SDK, the diagram library, the CLI, the MCP server, and the VS Code extension.

  • Runtime-dependency-free. Safe to import anywhere — editors, bundled web apps, Node CLIs, MCP servers.
  • One source of truth. The registries mirror the platform metadata seed (server/database/system-modules/metadata/seed-data/) and the structural types mirror the JSON schemas under docs/schemas/. Parity tests fail the build if either drifts.

Install

pnpm add @dforge-core/metadata

What's inside

SurfaceExports
Field typesfieldTypes, fieldTypeCds, isFieldTypeCd, getFieldType, fieldTypesByColumnType
Base datatypesbaseDatatypes, baseToDbDatatype
Column typescolumnTypes, getColumnType
Traitstraits, getTrait, expandTrait, expandTraits
DerivationderiveDbDatatype, deriveBaseDatatype, defaultParams, NUMERIC_TOTAL
AggregationAggType, AGG_TYPE_LIST
Display flagsflagDefs (V Visible · I Identity · E Editable · M Mandatory · H Hidden)
View / report kindsdataViewKinds, vizTypes, chartTypes
Scalar enumsFieldTypeCd, BaseDatatypeCd, ColumnTypeCd, FlagCd, AlignType
Module-file typesManifestDef, EntityDef, DataViewsFile, ReportsFile, MenusFile, FoldersFile, RolesFile, SettingsFile, JobsFile, TriggersFile, WebhooksFile, PrintTemplatesFile, SeedDataFile, ActionsFile, …
Filter expressionFilter, FilterCondition, FilterGroup, SortClause
DSL analyzer./dsl — checkDsl, parseDsl, tokenize, BUILTINS (see Action DSL)
JSON schemas./schemas/<name>.schema.json (see Schemas)

Registries & derivation

An author picks a friendly fieldTypeCd; the helpers derive the physical metadata so no one types a raw SQL type by hand.

import {
  getFieldType,
  isFieldTypeCd,
  deriveDbDatatype,
  deriveBaseDatatype,
  defaultParams,
} from "@dforge-core/metadata";

isFieldTypeCd("currency");          // true
isFieldTypeCd("reference");         // false — not a real code (it's `lookup`)

getFieldType("currency");
// { cd: "currency", columnType: "D", baseDatatypeCd: "number", precision: 2, ... }

deriveDbDatatype("currency");       // "numeric(18,2)"
deriveDbDatatype("text");           // "varchar"
deriveDbDatatype("textarea");       // "text"
deriveDbDatatype("lookup");         // null — relationship-backed, no own column
deriveBaseDatatype("color");        // "string"
defaultParams("flags");             // { style: "buttons" }
defaultParams("number");            // undefined — numeric types carry no defaults

Traits

import { expandTrait, expandTraits } from "@dforge-core/metadata";

// Expand a trait into the FieldDef map it contributes to an entity.
expandTrait("audit", "invoice");
expandTraits(["identity", "audit"], "invoice");

Module-file types

The structural types describe the authoring shape of every file in a .dforge module package — the same shapes the JSON schemas validate.

import type { ManifestDef, EntityDef, DataViewsFile } from "@dforge-core/metadata";

const entity: EntityDef = {
  description: "Customer",
  dbObject: "customer",
  fields: {
    /* … */
  },
};

Note: these are the authoring shapes. The resolved runtime model returned by the API (metadata.getModel) is a different contract — see @dforge/sdk's Model* types, which reuse the scalar enums from this package.

Action DSL

@dforge-core/metadata/dsl is a separate entry point holding the lexer, parser and static rules for an action body (logic/actions/*.dsl). One implementation serves both hosts that check these files: the language server, which turns issues into squiggles, and the module validator, which gates a pack.

import { checkDsl } from "@dforge-core/metadata/dsl";

const issues = checkDsl(source, {
  moduleCode: "wms",
  action: { code: "transfer_stock", executionMode: "single" },
  currentEntity: { qualified: "wms.stock_movement", columns: entityColumns },
});
// → [{ rule: "dsl/unknown-column", severity: "error", message, start, end, line, column }]

What a rule knows about the module arrives through that context — a module code, the action, and a column lookup (any Set or Map will do) — rather than through a module loader, which is what lets the same rule run in an editor and in a file walker. Every field is optional and every rule that reads one fails open: with an empty context the text-only rules still run and the rest stand down silently. A false "unknown column" underlines working code and blocks a pack; a missed one costs an install round trip.

One obligation comes with currentEntity: columns must be trait-expanded, built-in traits and the module's own traits.json alike, because the identity PK and [status] live in traits rather than in fields. An unexpanded set turns the rule into a wall of false errors. When the entity can't be resolved — a bridge module acting on another module's entity — pass null rather than the fragment you do have.

Issues carry both byte offsets and a 1-indexed line/column, so a range-based host and a file.dsl:12 reporter each get what they need.

The blocks, the [field] lookbehind and the case rules follow ActionDslCompiler rather than the prose docs: five block kinds including schema:, headers anchored at column 0 (an indented one is body text, and is reported), and execute: running to end-of-file.

It is not re-exported from the package root: importing @dforge-core/metadata in a browser bundle must not pull a tokenizer in behind it.

JSON schemas

The 14 canonical schemas are shipped alongside the types and stay byte-identical to docs/schemas/ (a parity test enforces it; prepack re-syncs before publish). Import them directly or point a validator / editor at the files.

import entitySchema from "@dforge-core/metadata/schemas/entity.schema.json" with { type: "json" };
// VS Code settings.json — validate module files against the shipped schemas
"json.schemas": [
  {
    "fileMatch": ["entities/*.json"],
    "url": "./node_modules/@dforge-core/metadata/schemas/entity.schema.json"
  }
]

Available: manifest, entity, data_views, folders, menus, roles, settings, reports, jobs, triggers, webhooks, print_templates, traits, seed_data, demo_vars.

Source of truth & parity

This package never edits the canonical sources — it mirrors them and guards the mirror:

  • Registries mirror the platform metadata seed; test/registries.test.ts fails if a code drifts from field_types.json (and a compile-time coverage guard fails if the FieldTypeCd union and the fieldTypes array diverge).
  • Schemas are copied from docs/schemas/ by pnpm sync-schemas; test/schemas.test.ts fails if the shipped copy drifts. prepack re-syncs.

When consumed standalone (no monorepo around the package) the parity checks are skipped — the shipped data is authoritative on its own.

Scripts

pnpm build          # tsc → dist/
pnpm test           # vitest (registry + schema parity)
pnpm sync-schemas   # refresh schemas/ from docs/schemas/

License

MIT

版本与发布记录

@dforge-core/metadata 共发布 51 个版本,首次发布于 2026/06/14;过去 12 个月发布了 51 个版本。

版本发布日期距今
0.0.53latest2026/11/111 天前
0.0.522026/11/101 天前
0.0.512026/11/083 天前
0.0.502026/11/057 天前
0.0.492026/11/048 天前
0.0.482026/11/039 天前

关于 @dforge-core/metadata 的常见问题

@dforge-core/metadata 是什么?

Canonical dForge authoring registries — field types, base datatypes, column types, traits, data-view kinds and chart types — with derivation helpers. Runtime-dependency-free; the single source of truth shared by editors, the web app and the CLI.

如何安装 @dforge-core/metadata?

在项目目录运行 npm install @dforge-core/metadata,或使用 pnpm add / yarn add / bun add。

@dforge-core/metadata 支持 TypeScript 吗?

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

@dforge-core/metadata 支持 ESM 还是 CommonJS?

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

@dforge-core/metadata 可以商用吗?

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

@dforge-core/metadata 的下载量有多少?

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

@dforge-core/metadata 还在维护吗?

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