packages/model/SKILL.md
@hile/model: defineModel/loadModel 定义和消费模型;services 依赖注入;pipeline 中间件链;每次 loadModel 重新执行 main
npx skillsauth add cevio/hile modelInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
与仓库根 SKILL.md 一并遵守。
defineModel 定义,loadModel 执行services 声明依赖,main 首参为加载后的实例元组main 前后执行横切逻辑loadModel 都重新执行 main,不同于 @hile/core 的容器单例| 名称 | 说明 |
|------|------|
| defineModel | 定义模型,接收 (main) 简写或 ModelProps 对象 |
| loadModel | loadModel(model, input) 执行模型 |
| isModel | 判断值是否为 defineModel 返回值 |
| ModelDefinition | 模型类型 |
| ModelProps | defineModel 入参类型 |
| ModelPipeline | readonly PipelineMiddleware[] |
| Pipeline | 中间件链类 |
| PipelineContext | 中间件上下文 |
| PipelineMiddleware | 中间件类型 (ctx, next) => Promise<void> |
| InferServiceResult | 工具类型 |
| InferredServices | 工具类型 |
// 简写:无 services、无 pipelines
defineModel(async (input: TInput) => R)
// 完整形式
defineModel({
services?: [ServiceA, ServiceB], // 可选
pipelines?: [MiddlewareA, MiddlewareB], // 可选,顺序执行
async main(
services?: [InstanceA, InstanceB], // 有 services 时首参
input: TInput, // 入参
): R | Promise<R>,
})
defineModel,export defaultloadModel 首参:必须是 defineModel 返回值,否则抛 TypeErrornext(),否则抛错next())会使 main 不执行ctx.args 改写入参ctx.state 传递数据@hile/core 容器保证单例;model 本身不缓存结果defineModel(应在模块顶层定义一次)ModelDefinition 对象(必须通过 defineModel)main 中做副作用不返回结果(model 应是有输入有输出的纯业务函数)src/model.test.ts:defineModel 各种形式(完整、简写、services、pipelines)。src/pipeline.test.ts:中间件顺序、短路、next 多次调用、并发、无中间件等。
development
Code generation and contribution rules for @hile/micro-dynamic-configs. Use when editing this package or when the user asks about dynamic config patterns or API.
development
Code generation and contribution rules for @hile/cache. Use when editing this package or when the user asks about @hile/cache API, types, patterns, or features.
development
Code generation and contribution rules for @hile/micro. Use when editing this package or when the user asks about @hile/micro API, types, patterns, or features.
tools
@hile/typeorm 的代码生成与使用规范。适用于 DataSource 服务加载、transaction 事务封装、及与 @hile/core/@hile/cli 集成场景。