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

Function decodeState

packages/effect/src/ui/Query.ts:3724–3789  ·  view source on GitHub ↗
(
    tuple: any,
    options: SchemaAST.ParseOptions
  )

Source from the content-addressed store, hash-verified

3722 })
3723 }
3724 const decodeState = (
3725 tuple: any,
3726 options: SchemaAST.ParseOptions
3727 ): Effect.Effect<SnapshotImpl, SchemaIssue.Issue> => {
3728 const [key, tag, payload, fourth, fifth, sixth] = tuple
3729 if (tag === 2) {
3730 return Effect.flatMap(Effect.context(), (ctx) => {
3731 const shipped = Context.get(ctx, queryCore.Shipped)
3732 if (shipped === undefined) {
3733 return Effect.fail(
3734 invalid("the referenced ~query entry wasn't shipped")
3735 )
3736 }
3737 return Effect.flatMap(fromKey(key, options), (args) =>
3738 Effect.map(
3739 shipped.decode(def, key),
3740 (hit) =>
3741 new SnapshotImpl({
3742 def,
3743 label,
3744 argsKey: key as string,
3745 args,
3746 result: hit,
3747 patched: false,
3748 more: def.list === undefined
3749 ? undefined
3750 : payload === true
3751 ? moreAvailable
3752 : moreEnd
3753 })
3754 ))
3755 })
3756 }
3757 return Effect.map(fromKey(key, options), (args) => {
3758 const data = { def, label, argsKey: key as string, args }
3759 if (tag === 0) {
3760 return new SnapshotImpl({
3761 ...data,
3762 result: AsyncResult.success(payload, { timestamp: fourth }),
3763 patched: fifth === true,
3764 more: def.list === undefined
3765 ? undefined
3766 : sixth === true
3767 ? moreAvailable
3768 : moreEnd
3769 })
3770 }
3771 return new SnapshotImpl({
3772 ...data,
3773 result: AsyncResult.failure(
3774 Cause.fromReasons(
3775 (payload as ReadonlyArray<unknown>).map((e) => Cause.makeFailReason(e))
3776 ),
3777 {
3778 previousSuccess: fourth === null
3779 ? Option.none()
3780 : Option.some(
3781 AsyncResult.success(fourth[0], { timestamp: fourth[1] })

Callers 1

decodeSettledFunction · 0.85

Calls 8

fromKeyFunction · 0.85
contextMethod · 0.80
someMethod · 0.80
invalidFunction · 0.70
getMethod · 0.65
failMethod · 0.65
mapMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected