Skip to content

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

Open
kitlangton wants to merge 2 commits intodevfrom
kit/session-schema-events
Open

refactor(core): allow SyncEvent.define and BusEvent.define to accept Effect Schema#23765
kitlangton wants to merge 2 commits intodevfrom
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 kitlangton force-pushed the kit/session-schema-errors branch from d808041 to b2e84cf Compare April 22, 2026 03:11
@kitlangton kitlangton force-pushed the kit/session-schema-events branch from 38eaf7d to 3871125 Compare April 22, 2026 03:11
@kitlangton kitlangton force-pushed the kit/session-schema-errors branch from b2e84cf to 51334b9 Compare April 22, 2026 03:12
@kitlangton kitlangton force-pushed the kit/session-schema-events branch 2 times, most recently from e0c10e9 to a097c74 Compare April 22, 2026 03:18
@kitlangton kitlangton force-pushed the kit/session-schema-errors branch 2 times, most recently from 63bd01a to 62d9778 Compare April 22, 2026 03:27
@kitlangton kitlangton force-pushed the kit/session-schema-events branch from a097c74 to 5f7efaf Compare April 22, 2026 03:27
Adds namedSchemaError helper that preserves the existing NamedError API surface (.Schema, .isInstance, .toObject, new X({...}, { cause })) while backing the schema with Schema.Struct under the hood. Wire shape stays {name, data}, so the OpenAPI output is byte-identical.
…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.
@kitlangton kitlangton force-pushed the kit/session-schema-errors branch from 62d9778 to 68b3a39 Compare April 22, 2026 03:36
@kitlangton kitlangton force-pushed the kit/session-schema-events branch from 5f7efaf to b4b7500 Compare April 22, 2026 03:36
Base automatically changed from kit/session-schema-errors to dev April 22, 2026 03:40
Sign up for free to 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