permix

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Permix

Permix

Use this skill when work touches Permix permissions: definitions,
setup
/
check
, SSR hydration, UI adapters, server middleware, or v3→v4 migration.
当工作涉及Permix权限相关内容时使用该技能:包括权限定义、
setup
/
check
方法、SSR序列化/反序列化、UI适配器、服务器中间件,或是v3→v4版本迁移。

Workflow

工作流程

  1. Inspect the local Permix surface:
    • Package version (
      permix@4.x
      preferred; current stable snapshot 4.1.2).
    • Import path:
      permix
      (core) vs subpaths (
      permix/react
      ,
      permix/next
      ,
      permix/express
      , …).
    • Definition shape: action tuples /
      { name, type, required? }
      vs legacy v3
      { action, dataType }
      .
    • Where enforcement runs (server middleware vs client UX) and whether SSR dehydrate/hydrate is used.
  2. For day-to-day how-to, follow usage-guide.md first.
  3. Refresh docs when versions drift or the task is migration/SSR/integration-specific. Start from source-map.md.
  4. 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.
  5. Prefer Permix v4 APIs (dot paths, action tuples). Treat client checks as UX only — enforce on the server.
  6. Verify with typecheck plus focused
    setup
    /
    check
    tests (and middleware 403 paths when server-integrated).
  1. 检查本地Permix相关信息:
    • 包版本(推荐
      permix@4.x
      ;当前稳定快照版本为4.1.2)。
    • 导入路径:
      permix
      (核心包)与子路径(
      permix/react
      permix/next
      permix/express
      等)。
    • 定义格式:操作元组 /
      { name, type, required? }
      对比旧版v3的
      { action, dataType }
    • 权限校验执行位置(服务器中间件 vs 客户端用户体验)以及是否使用SSR dehydrate/hydrate功能。
  2. 日常操作指南请优先参考usage-guide.md
  3. 当版本不一致或任务涉及迁移/SSR/集成特定内容时,请查阅最新文档。可从source-map.md开始。
  4. 根据需求查阅对应详细文档:
    • 核心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
  5. 优先使用Permix v4 API(点路径、操作元组)。客户端校验仅作用户体验优化——必须在服务器端执行强制校验。
  6. 通过类型检查以及针对性的
    setup
    /
    check
    测试(集成服务器中间件时需验证403路径)进行验证。

Core Judgment

核心判断准则

  • Flow:
    createPermix<Definition>()
    setup(rules)
    check('entity.action'[, data])
    .
  • Definitions are action lists (strings or
    { name, type?, required? }
    ), optionally nested trees.
  • Rules are booleans or
    (data?) => boolean
    closures (capture the actor at
    setup
    time).
  • check
    returns
    boolean
    . Use callbacks for AND/OR; use
    '~all'
    /
    '~any'
    (or
    'post.~all'
    ) for aggregates.
  • checkAsync
    is removed
    in v4 —
    await isReadyAsync()
    then
    check()
    .
  • Before any rules:
    check
    /
    dehydrate
    throw
    PermixNotReadyError
    (not
    false
    ).
  • Invalid path throws
    PermixRuleNotDefinedError
    .
  • SSR:
    dehydrate()
    → JSON booleans (functions become
    false
    ) → client
    hydrate
    must
    setup()
    again
    for function rules; hydrate alone does not set
    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
    node: >=22
    . Optional peer deps only for the adapters you import.
  • 流程:
    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:
    dehydrate()
    → JSON布尔值(函数会转为
    false
    ) → 客户端
    hydrate
    → 函数规则必须重新执行**
    setup()
    **;仅执行hydrate不会设置
    isReady
    状态。
  • 服务器端:优先通过集成中间件创建每个请求的实例;请勿在并发请求间共享可变单例。
  • 安全:必须在服务器端执行强制校验;客户端校验仅用于隐藏UI元素。
  • 运行环境:包声明要求**
    node: >=22
    **。仅在导入对应适配器时才需要安装可选依赖。

Verification

验证步骤

Prefer repository-owned commands. For meaningful Permix work, cover the relevant subset:
  • Typecheck paths (
    $inferPath
    ),
    required: true
    data args, and shared
    ValidateDefinition
    /
    Rules
    .
  • Unit tests: allow/deny, entity-data rules with/without data,
    ~all
    /
    ~any
    , callback composition, not-ready / missing-path errors.
  • SSR: dehydrate snapshot shape; client hydrate + re-
    setup
    ;
    isReady
    gating in UI.
  • Server:
    setupMiddleware
    then
    checkMiddleware
    — assert 200 vs 403 /
    onForbidden
    .
  • Migration: no remaining
    check('entity', 'action')
    ,
    checkAsync
    , Better Auth plugin, or
    entity
    +
    action
    UI props.
Report which checks ran, which did not, and any version assumptions that remain.
优先使用仓库自带命令。针对Permix相关工作,需覆盖以下相关内容:
  • 类型检查路径(
    $inferPath
    )、
    required: true
    的数据参数,以及共享的
    ValidateDefinition
    /
    Rules
  • 单元测试:允许/拒绝校验、带/不带数据的实体数据规则、
    ~all
    /
    ~any
    聚合、回调组合、未就绪/路径缺失错误。
  • SSR:序列化快照格式;客户端反序列化 + 重新执行
    setup
    ;UI中的
    isReady
    状态校验。
  • 服务器端:先执行
    setupMiddleware
    再执行
    checkMiddleware
    ——验证200与403响应 /
    onForbidden
    处理逻辑。
  • 迁移:确保不存在遗留的
    check('entity', 'action')
    checkAsync
    、Better Auth插件,或
    entity
    +
    action
    类型的UI属性。
需报告已执行的检查项、未执行的检查项,以及所有保留的版本假设。