Skip to content

refactor(core): allow SyncEvent.define and BusEvent.define to accept Effect Schema - #23765

Closed
kitlangton wants to merge 4 commits into
devfrom
kit/session-schema-events
Closed

refactor(core): allow SyncEvent.define and BusEvent.define to accept Effect Schema#23765
kitlangton wants to merge 4 commits into
devfrom
kit/session-schema-events

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Stacked on #23764.

Overloads BusEvent.define and SyncEvent.define so payload schemas can be passed as Effect Schema values directly. Effect Schemas are converted to Zod via the effect-zod walker since the sync/bus pipelines still use Zod internally for serialization and JSON Schema generation.

Migrates MessageV2.Event.* payload schemas to use Schema.Struct directly instead of z.object(...) with .zod references on each field.

Design

  • BusEvent.define and SyncEvent.define gain overloads that take either Schema.Top / Schema.Struct or the original Zod shapes.
  • Runtime checks for .ast property to distinguish and converts via zod().
  • Return type applies Types.DeepMutable so inferred payload types stay mutable (matches pre-migration z.infer behavior).

Acceptance check

  • bun typecheck clean.
  • bun run test → 2010 pass / 0 fail.
  • bun dev generate byte-identical to committed packages/sdk/openapi.json.
  • packages/sdk/js/src/v2/gen/types.gen.ts unchanged after bun script/build.ts.

Follow-up

Other modules' event definitions (session/session.ts, session/status.ts, project/project.ts, permission/index.ts, question/index.ts, etc.) can now migrate to pass Schema directly whenever their payload schemas are already Schema-first. Not done in this PR to keep the diff small.

@kitlangton
kitlangtonforce-pushed the kit/session-schema-errors branch from d808041 to b2e84cfCompareApril 22, 2026 03:11
@kitlangton
kitlangtonforce-pushed the kit/session-schema-events branch from 38eaf7d to 3871125CompareApril 22, 2026 03:11
@kitlangton
kitlangtonforce-pushed the kit/session-schema-errors branch from b2e84cf to 51334b9CompareApril 22, 2026 03:12
@kitlangton
kitlangtonforce-pushed the kit/session-schema-events branch 2 times, most recently from e0c10e9 to a097c74CompareApril 22, 2026 03:18
@kitlangton
kitlangtonforce-pushed the kit/session-schema-errors branch 2 times, most recently from 63bd01a to 62d9778CompareApril 22, 2026 03:27
@kitlangton
kitlangtonforce-pushed the kit/session-schema-events branch from a097c74 to 5f7efafCompareApril 22, 2026 03:27
@kitlangton
kitlangtonforce-pushed the kit/session-schema-errors branch from 62d9778 to 68b3a39CompareApril 22, 2026 03:36
@kitlangton
kitlangtonforce-pushed the kit/session-schema-events branch from 5f7efaf to b4b7500CompareApril 22, 2026 03:36
Base automatically changed from kit/session-schema-errors to devApril 22, 2026 03:40
@kitlangton
kitlangtonforce-pushed the kit/session-schema-events branch from b4b7500 to 6430564CompareApril 23, 2026 12:45
…Effect Schema
Overloads BusEvent.define and SyncEvent.define so payload schemas can be passed as Effect Schema values directly. Effect Schemas are converted to Zod via the effect-zod walker since the sync/bus pipelines still use Zod internally. Migrates MessageV2.Event.* to use Schema.Struct directly instead of z.object with .zod references.
Exercise the new SyncEvent and BusEvent Schema overloads end to end and use Schema.isSchema for the conversion check so the mixed-schema path stays explicit and covered.
Store sync event definitions as Effect Schema and derive Zod only at the bus and OpenAPI edges. Bridge the remaining Zod-native session payloads through Schema annotations so the sync layer no longer needs mixed-schema definition helpers.
Use Schema.is to narrow converted sync events instead of asserting the payload type manually. Move the Zod-to-Effect bridge into effect-zod so remaining Zod-backed sync payloads have one explicit interop helper.
@kitlangton
kitlangtonforce-pushed the kit/session-schema-events branch from 98be292 to 53e1d7bCompareApril 23, 2026 15:45
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@kitlangton