| 1121 | * @since 4.0.0 |
| 1122 | */ |
| 1123 | export const exitSchema = <R extends Any>( |
| 1124 | self: R |
| 1125 | ): Schema.Exit< |
| 1126 | SuccessExitSchema<R>, |
| 1127 | ErrorExitSchema<R>, |
| 1128 | DefectSchema |
| 1129 | > => { |
| 1130 | if (exitSchemaCache.has(self)) { |
| 1131 | return exitSchemaCache.get(self) as any |
| 1132 | } |
| 1133 | const rpc = self as any as AnyWithProps |
| 1134 | const failures = new Set<Schema.Top>([rpc.errorSchema]) |
| 1135 | const streamSchemas = RpcSchema.getStreamSchemas(rpc.successSchema) |
| 1136 | if (Option.isSome(streamSchemas)) { |
| 1137 | failures.add(streamSchemas.value.error) |
| 1138 | } |
| 1139 | for (const middleware of rpc.middlewares) { |
| 1140 | failures.add(middleware.error) |
| 1141 | } |
| 1142 | const schema = Schema.Exit( |
| 1143 | Option.isSome(streamSchemas) ? Schema.Void : rpc.successSchema, |
| 1144 | Schema.Union([...failures]), |
| 1145 | rpc.defectSchema |
| 1146 | ) |
| 1147 | exitSchemaCache.set(self, schema as any) |
| 1148 | return schema as any |
| 1149 | } |
| 1150 | |
| 1151 | const WrapperTypeId = "~effect/rpc/Rpc/Wrapper" |
| 1152 | |