Repository navigation
feat(rpc): add defect schema option to Rpc.make #6065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tim-smart
merged 5 commits into
Effect-TS:main
from
marbemac:feat/support-defect-on-rpc-make
Feb 15, 2026
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@effect/rpc": minor | ||
| --- | ||
|
|
||
| Add optional `defect` parameter to `Rpc.make` for customizing defect serialization per-RPC. Defaults to `Schema.Defect`, preserving existing behavior. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ export interface Rpc< | |
| readonly payloadSchema: Payload | ||
| readonly successSchema: Success | ||
| readonly errorSchema: Error | ||
| readonly defectSchema: Schema.Schema.Any | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The schema will have to have no requirements as well |
||
| readonly annotations: Context_.Context<never> | ||
| readonly middlewares: ReadonlySet<Middleware> | ||
|
|
||
|
|
@@ -171,6 +172,7 @@ export interface AnyWithProps { | |
| readonly payloadSchema: AnySchema | ||
| readonly successSchema: Schema.Schema.Any | ||
| readonly errorSchema: Schema.Schema.All | ||
| readonly defectSchema: Schema.Schema.Any | ||
|
tim-smart marked this conversation as resolved.
Resolved
|
||
| readonly annotations: Context_.Context<never> | ||
| readonly middlewares: ReadonlySet<RpcMiddleware.TagClassAnyWithProps> | ||
| } | ||
|
|
@@ -541,6 +543,7 @@ const Proto = { | |
| payloadSchema: this.payloadSchema, | ||
| successSchema, | ||
| errorSchema: this.errorSchema, | ||
| defectSchema: this.defectSchema, | ||
| annotations: this.annotations, | ||
| middlewares: this.middlewares | ||
| }) | ||
|
|
@@ -551,6 +554,7 @@ const Proto = { | |
| payloadSchema: this.payloadSchema, | ||
| successSchema: this.successSchema, | ||
| errorSchema, | ||
| defectSchema: this.defectSchema, | ||
| annotations: this.annotations, | ||
| middlewares: this.middlewares | ||
| }) | ||
|
|
@@ -561,6 +565,7 @@ const Proto = { | |
| payloadSchema: Schema.isSchema(payloadSchema) ? payloadSchema as any : Schema.Struct(payloadSchema as any), | ||
| successSchema: this.successSchema, | ||
| errorSchema: this.errorSchema, | ||
| defectSchema: this.defectSchema, | ||
| annotations: this.annotations, | ||
| middlewares: this.middlewares | ||
| }) | ||
|
|
@@ -571,6 +576,7 @@ const Proto = { | |
| payloadSchema: this.payloadSchema, | ||
| successSchema: this.successSchema, | ||
| errorSchema: this.errorSchema, | ||
| defectSchema: this.defectSchema, | ||
| annotations: this.annotations, | ||
| middlewares: new Set([...this.middlewares, middleware]) | ||
| }) | ||
|
|
@@ -581,6 +587,7 @@ const Proto = { | |
| payloadSchema: this.payloadSchema, | ||
| successSchema: this.successSchema, | ||
| errorSchema: this.errorSchema, | ||
| defectSchema: this.defectSchema, | ||
| annotations: this.annotations, | ||
| middlewares: this.middlewares | ||
| }) | ||
|
|
@@ -591,6 +598,7 @@ const Proto = { | |
| payloadSchema: this.payloadSchema, | ||
| successSchema: this.successSchema, | ||
| errorSchema: this.errorSchema, | ||
| defectSchema: this.defectSchema, | ||
| middlewares: this.middlewares, | ||
| annotations: Context_.add(this.annotations, tag, value) | ||
| }) | ||
|
|
@@ -601,6 +609,7 @@ const Proto = { | |
| payloadSchema: this.payloadSchema, | ||
| successSchema: this.successSchema, | ||
| errorSchema: this.errorSchema, | ||
| defectSchema: this.defectSchema, | ||
| middlewares: this.middlewares, | ||
| annotations: Context_.merge(this.annotations, context) | ||
| }) | ||
|
|
@@ -618,6 +627,7 @@ const makeProto = < | |
| readonly payloadSchema: Payload | ||
| readonly successSchema: Success | ||
| readonly errorSchema: Error | ||
| readonly defectSchema: Schema.Schema.Any | ||
| readonly annotations: Context_.Context<never> | ||
| readonly middlewares: ReadonlySet<Middleware> | ||
| }): Rpc<Tag, Payload, Success, Error, Middleware> => { | ||
|
|
@@ -643,6 +653,7 @@ export const make = < | |
| readonly success?: Success | ||
| readonly error?: Error | ||
| readonly stream?: Stream | ||
| readonly defect?: Schema.Schema.Any | ||
| readonly primaryKey?: [Payload] extends [Schema.Struct.Fields] ? | ||
| ((payload: Schema.Simplify<Schema.Struct.Type<NoInfer<Payload>>>) => string) : | ||
| never | ||
|
|
@@ -678,6 +689,7 @@ export const make = < | |
| }) : | ||
| successSchema, | ||
| errorSchema: options?.stream ? Schema.Never : errorSchema, | ||
| defectSchema: options?.defect ?? Schema.Defect, | ||
| annotations: Context_.empty(), | ||
| middlewares: new Set<never>() | ||
| }) as any | ||
|
|
@@ -719,6 +731,7 @@ export const fromTaggedRequest = <S extends AnyTaggedRequestSchema>( | |
| payloadSchema: schema as any, | ||
| successSchema: schema.success as any, | ||
| errorSchema: schema.failure, | ||
| defectSchema: Schema.Defect, | ||
| annotations: Context_.empty(), | ||
| middlewares: new Set() | ||
| }) | ||
|
|
@@ -747,7 +760,7 @@ export const exitSchema = <R extends Any>( | |
| const schema = Schema.Exit({ | ||
| success: Option.isSome(streamSchemas) ? Schema.Void : rpc.successSchema, | ||
| failure: Schema.Union(...failures), | ||
| defect: Schema.Defect | ||
| defect: rpc.defectSchema | ||
| }) | ||
| exitSchemaCache.set(self, schema) | ||
| return schema as any | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.