feat: add collectCasRefs — schema-level CAS ref annotation (Phase 1) #288

Merged
xiaomo merged 1 commits from feat/285-cas-ref-annotation into main 2026-05-16 10:43:16 +00:00
Owner

What

Add collectCasRefs(schema, meta) function that extracts CAS hash references from Zod v4 schemas annotated with .meta({ casRef: true }).

Why

Replace manual extractRefs functions on RoleDefinition with declarative schema annotations. This is Phase 1 of RFC #285 — moving WorkflowDefinition closer to pure data.

Changes

  • packages/workflow-runtime/src/collect-cas-refs.ts — new function, recursively walks Zod schema (object, array, union, nullable/optional) collecting annotated string values
  • packages/workflow-runtime/src/index.ts — export collectCasRefs
  • packages/workflow-runtime/__tests__/collect-cas-refs.test.ts — 8 test cases (flat, nested array, discriminatedUnion, null, mixed)

Testing

All 8 steps in #286 verified

Refs #285, addresses #286

## What Add `collectCasRefs(schema, meta)` function that extracts CAS hash references from Zod v4 schemas annotated with `.meta({ casRef: true })`. ## Why Replace manual `extractRefs` functions on RoleDefinition with declarative schema annotations. This is Phase 1 of RFC #285 — moving WorkflowDefinition closer to pure data. ## Changes - `packages/workflow-runtime/src/collect-cas-refs.ts` — new function, recursively walks Zod schema (object, array, union, nullable/optional) collecting annotated string values - `packages/workflow-runtime/src/index.ts` — export collectCasRefs - `packages/workflow-runtime/__tests__/collect-cas-refs.test.ts` — 8 test cases (flat, nested array, discriminatedUnion, null, mixed) ## Testing All 8 steps in #286 verified ✅ Refs #285, addresses #286
xiaoju added 1 commit 2026-05-16 10:38:49 +00:00
Replaces manual extractRefs functions with declarative schema-level
casRef annotations. Walks Zod v4 schemas recursively, collecting
string values from fields marked with .meta({ casRef: true }).

Supports: objects, arrays, discriminatedUnion, nullable/optional.

8/8 test cases pass (flat, nested, union, null, mixed).

Refs #285, addresses #286
xiaomo approved these changes 2026-05-16 10:40:58 +00:00
xiaomo left a comment
Owner

LGTM Zod v4 meta({ casRef: true }) + 递归 schema walker,覆盖 object/array/union/nullable/optional/default/pipe 等所有 wrapper 类型。测试 7 个场景全面。

LGTM ✅ Zod v4 `meta({ casRef: true })` + 递归 schema walker,覆盖 object/array/union/nullable/optional/default/pipe 等所有 wrapper 类型。测试 7 个场景全面。
xiaoju force-pushed feat/285-cas-ref-annotation from 0133adc8af to 93b7947d7c 2026-05-16 10:42:28 +00:00 Compare
xiaomo merged commit 6bb8cf8315 into main 2026-05-16 10:43:16 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#288