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

Function toCodecJson

packages/effect/src/ui/Query.ts:3991–4033  ·  view source on GitHub ↗
(typeParameters: ReadonlyArray<Schema.Top>)

Source from the content-addressed store, hash-verified

3989 }
3990 }
3991 const toCodecJson = (typeParameters: ReadonlyArray<Schema.Top>) => {
3992 const wire = snapshotWire(def, label, typeParameters, log)
3993 return Schema.link<SnapshotMapImpl>()(
3994 Schema.Array(wire.tuple),
3995 SchemaTransformation.transformEffect<SnapshotMapImpl, ReadonlyArray<any>>(
3996 {
3997 decode: (tuples, options) =>
3998 Effect.flatMap(
3999 Effect.forEach(tuples, (tuple) => wire.decode(tuple, options)),
4000 (snapshots) => {
4001 const keys = new Set<string>()
4002 for (const snapshot of snapshots) {
4003 const key = snapshot[SnapshotTypeId].argsKey
4004 if (key === undefined) {
4005 return Effect.fail(
4006 snapshotIssue(
4007 def,
4008 "a keyed field holds an empty snapshot"
4009 )
4010 )
4011 }
4012 if (keys.has(key)) {
4013 return Effect.fail(
4014 snapshotIssue(
4015 def,
4016 "a keyed field holds one args key twice"
4017 )
4018 )
4019 }
4020 keys.add(key)
4021 }
4022 return Effect.succeed(makeSnapshotMap(def, label, snapshots))
4023 }
4024 ),
4025 encode: (map, options) =>
4026 Effect.forEach(
4027 map[SnapshotMapTypeId].entries.values(),
4028 (snapshot) => wire.encode(snapshot, options)
4029 )
4030 }
4031 )
4032 )
4033 }
4034 return Schema.make(
4035 new SchemaAST.Declaration(
4036 [def.args.ast, def.success.ast, def.error.ast],

Callers

nothing calls this directly

Calls 10

snapshotWireFunction · 0.85
snapshotIssueFunction · 0.85
makeSnapshotMapFunction · 0.85
encodeMethod · 0.80
forEachMethod · 0.65
failMethod · 0.65
hasMethod · 0.65
addMethod · 0.65
decodeMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected