permix
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePermix
Permix
Use this skill when work touches Permix permissions: definitions, /, SSR hydration, UI adapters, server middleware, or v3→v4 migration.
setupcheck当工作涉及Permix权限相关内容时使用该技能:包括权限定义、/方法、SSR序列化/反序列化、UI适配器、服务器中间件,或是v3→v4版本迁移。
setupcheckWorkflow
工作流程
- Inspect the local Permix surface:
- Package version (preferred; current stable snapshot 4.1.2).
permix@4.x - Import path: (core) vs subpaths (
permix,permix/react,permix/next, …).permix/express - Definition shape: action tuples / vs legacy v3
{ name, type, required? }.{ action, dataType } - Where enforcement runs (server middleware vs client UX) and whether SSR dehydrate/hydrate is used.
- Package version (
- For day-to-day how-to, follow usage-guide.md first.
- Refresh docs when versions drift or the task is migration/SSR/integration-specific. Start from source-map.md.
- Route deeper detail:
- Core API, rules, check, template, ReBAC, errors: core-api.md.
- React/Vue/Solid/Svelte, Next, TanStack Start, hydration: frameworks-ssr.md.
- Express/Hono/Elysia/Fastify/Node/server/tRPC/oRPC/Drizzle/Effect: server-integrations.md.
- v3→v4 breaking changes: migration-v4.md.
- Prefer Permix v4 APIs (dot paths, action tuples). Treat client checks as UX only — enforce on the server.
- Verify with typecheck plus focused /
setuptests (and middleware 403 paths when server-integrated).check
- 检查本地Permix相关信息:
- 包版本(推荐;当前稳定快照版本为4.1.2)。
permix@4.x - 导入路径:(核心包)与子路径(
permix、permix/react、permix/next等)。permix/express - 定义格式:操作元组 / 对比旧版v3的
{ name, type, required? }。{ action, dataType } - 权限校验执行位置(服务器中间件 vs 客户端用户体验)以及是否使用SSR dehydrate/hydrate功能。
- 包版本(推荐
- 日常操作指南请优先参考usage-guide.md。
- 当版本不一致或任务涉及迁移/SSR/集成特定内容时,请查阅最新文档。可从source-map.md开始。
- 根据需求查阅对应详细文档:
- 核心API、规则、check方法、模板、ReBAC、错误处理:core-api.md。
- React/Vue/Solid/Svelte、Next、TanStack Start、序列化/反序列化:frameworks-ssr.md。
- Express/Hono/Elysia/Fastify/Node/server/tRPC/oRPC/Drizzle/Effect:server-integrations.md。
- v3→v4破坏性变更:migration-v4.md。
- 优先使用Permix v4 API(点路径、操作元组)。客户端校验仅作用户体验优化——必须在服务器端执行强制校验。
- 通过类型检查以及针对性的/
setup测试(集成服务器中间件时需验证403路径)进行验证。check
Core Judgment
核心判断准则
- Flow: →
createPermix<Definition>()→setup(rules).check('entity.action'[, data]) - Definitions are action lists (strings or ), optionally nested trees.
{ name, type?, required? } - Rules are booleans or closures (capture the actor at
(data?) => booleantime).setup - returns
check. Use callbacks for AND/OR; useboolean/'~all'(or'~any') for aggregates.'post.~all' - is removed in v4 —
checkAsyncthenawait isReadyAsync().check() - Before any rules: /
checkthrowdehydrate(notPermixNotReadyError).false - Invalid path throws .
PermixRuleNotDefinedError - SSR: → JSON booleans (functions become
dehydrate()) → clientfalse→ musthydrateagain for function rules; hydrate alone does not setsetup().isReady - Server: prefer per-request instances via integration middleware; do not share mutable singletons across concurrent requests.
- Security: server enforcement is mandatory; hide UI with client checks only.
- Engines: package declares . Optional peer deps only for the adapters you import.
node: >=22
- 流程:→
createPermix<Definition>()→setup(rules)。check('entity.action'[, data]) - 定义为操作列表(字符串或),可选择嵌套结构。
{ name, type?, required? } - 规则为布尔值或****闭包(在
(data?) => boolean阶段捕获角色信息)。setup - 返回**
check**。使用回调实现与/或逻辑;使用boolean/'~all'(或'~any')实现聚合校验。'post.~all' - v4中已移除****——需先执行
checkAsync再调用await isReadyAsync()。check() - 在规则初始化前调用/
check会抛出**dehydrate**(而非返回PermixNotReadyError)。false - 无效路径会抛出****。
PermixRuleNotDefinedError - SSR:→ JSON布尔值(函数会转为
dehydrate()) → 客户端false→ 函数规则必须重新执行**hydrate**;仅执行hydrate不会设置setup()状态。isReady - 服务器端:优先通过集成中间件创建每个请求的实例;请勿在并发请求间共享可变单例。
- 安全:必须在服务器端执行强制校验;客户端校验仅用于隐藏UI元素。
- 运行环境:包声明要求****。仅在导入对应适配器时才需要安装可选依赖。
node: >=22
Verification
验证步骤
Prefer repository-owned commands. For meaningful Permix work, cover the relevant subset:
- Typecheck paths (),
$inferPathdata args, and sharedrequired: true/ValidateDefinition.Rules - Unit tests: allow/deny, entity-data rules with/without data, /
~all, callback composition, not-ready / missing-path errors.~any - SSR: dehydrate snapshot shape; client hydrate + re-;
setupgating in UI.isReady - Server: then
setupMiddleware— assert 200 vs 403 /checkMiddleware.onForbidden - Migration: no remaining ,
check('entity', 'action'), Better Auth plugin, orcheckAsync+entityUI props.action
Report which checks ran, which did not, and any version assumptions that remain.
优先使用仓库自带命令。针对Permix相关工作,需覆盖以下相关内容:
- 类型检查路径()、
$inferPath的数据参数,以及共享的required: true/ValidateDefinition。Rules - 单元测试:允许/拒绝校验、带/不带数据的实体数据规则、/
~all聚合、回调组合、未就绪/路径缺失错误。~any - SSR:序列化快照格式;客户端反序列化 + 重新执行;UI中的
setup状态校验。isReady - 服务器端:先执行再执行
setupMiddleware——验证200与403响应 /checkMiddleware处理逻辑。onForbidden - 迁移:确保不存在遗留的、
check('entity', 'action')、Better Auth插件,或checkAsync+entity类型的UI属性。action
需报告已执行的检查项、未执行的检查项,以及所有保留的版本假设。