( entity: Entity.Entity<Type, Rpcs> )
| 62 | * @since 4.0.0 |
| 63 | */ |
| 64 | export const toRpcGroup = <Type extends string, Rpcs extends Rpc.Any>( |
| 65 | entity: Entity.Entity<Type, Rpcs> |
| 66 | ): RpcGroup.RpcGroup<ConvertRpcs<Rpcs, Type>> => { |
| 67 | const rpcs: Array<Rpc.Any> = [] |
| 68 | for (const parentRpc_ of entity.protocol.requests.values()) { |
| 69 | const parentRpc = parentRpc_ as any as Rpc.AnyWithProps |
| 70 | const payloadSchema = Schema.Struct({ |
| 71 | entityId: Schema.String, |
| 72 | payload: parentRpc.payloadSchema |
| 73 | }) |
| 74 | const oldMake = payloadSchema.make |
| 75 | payloadSchema.make = (input: any, options?: Schema.MakeOptions) => { |
| 76 | return oldMake({ |
| 77 | entityId: input.entityId, |
| 78 | payload: parentRpc.payloadSchema.make(input.payload, options) |
| 79 | }, options) |
| 80 | } |
| 81 | const rpc = Rpc.make(`${entity.type}.${parentRpc._tag}`, { |
| 82 | payload: payloadSchema, |
| 83 | error: Schema.Union([parentRpc.errorSchema, ...requestErrors]), |
| 84 | success: parentRpc.successSchema |
| 85 | }).annotateMerge(parentRpc.annotations) |
| 86 | const rpcDiscard = Rpc.make(`${entity.type}.${parentRpc._tag}Discard`, { |
| 87 | payload: payloadSchema, |
| 88 | error: Schema.Union(clientErrors) |
| 89 | }).annotateMerge(parentRpc.annotations) |
| 90 | rpcs.push(rpc, rpcDiscard) |
| 91 | } |
| 92 | return RpcGroup.make(...rpcs) as any as RpcGroup.RpcGroup<ConvertRpcs<Rpcs, Type>> |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Type-level conversion used by `toRpcGroup`. |
nothing calls this directly
no test coverage detected