MCPcopy Create free account
hub / github.com/Effect-TS/effect / deserializeLocal

Function deserializeLocal

packages/effect/src/unstable/cluster/Message.ts:280–314  ·  view source on GitHub ↗
(
  self: Outgoing<Rpc>,
  encoded: Envelope.Partial
)

Source from the content-addressed store, hash-verified

278 * @since 4.0.0
279 */
280export const deserializeLocal = <Rpc extends Rpc.Any>(
281 self: Outgoing<Rpc>,
282 encoded: Envelope.Partial
283): Effect.Effect<
284 IncomingLocal<Rpc>,
285 MalformedMessage
286> => {
287 if (encoded._tag !== "Request") {
288 return Effect.succeed(new IncomingEnvelope({ envelope: encoded }))
289 } else if (self._tag !== "OutgoingRequest") {
290 return Effect.fail(
291 new MalformedMessage({ cause: new Error("Can only deserialize a Request with an OutgoingRequest message") })
292 )
293 }
294 const rpc = self.rpc as any as Rpc.AnyWithProps
295 return Schema.decodeEffect(Schema.toCodecJson(rpc.payloadSchema))(encoded.payload).pipe(
296 Effect.provideContext(self.context),
297 MalformedMessage.refail,
298 Effect.map((payload) => {
299 const envelope = Envelope.makeRequest({
300 ...encoded,
301 payload
302 } as any) as Envelope.Request<Rpc>
303 return new IncomingRequestLocal({
304 envelope,
305 lastSentReply: Option.none(),
306 respond: self.respond,
307 annotations: Context.get(rpc.annotations, ClusterSchema.Dynamic)(
308 rpc.annotations,
309 envelope as any
310 )
311 })
312 })
313 ) as Effect.Effect<IncomingRequestLocal<Rpc>, MalformedMessage>
314}

Callers

nothing calls this directly

Calls 6

pipeMethod · 0.65
getMethod · 0.65
succeedMethod · 0.45
failMethod · 0.45
toCodecJsonMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected