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

Function encodeWith

packages/effect/src/ui/MessageLog.ts:1460–1492  ·  view source on GitHub ↗
(schema: Schema.Top, id: string, value: unknown)

Source from the content-addressed store, hash-verified

1458 value
1459 )
1460 const encodeWith = (schema: Schema.Top, id: string, value: unknown) => {
1461 if (holdsRedactedOverlap(schema.ast)) {
1462 let rejected = false
1463 const out = guarded(() =>
1464 encodeAt(schema.ast, value, {
1465 path: new Set(),
1466 strict: true,
1467 leaf: () => {
1468 rejected = true
1469 return failed
1470 }
1471 })
1472 )
1473 if (rejected) warn(id, "a part of it didn't match its Schema")
1474 return out
1475 }
1476 let encode = encoders.get(schema)
1477 if (encode === undefined) {
1478 encode = Schema.encodeUnknownSync(
1479 Schema.toCodecJson(
1480 Schema.make<Schema.Codec<unknown, unknown>>(redactAST(schema.ast))
1481 )
1482 )
1483 encoders.set(schema, encode)
1484 }
1485 try {
1486 // `Schema.Any` can pass through values that JSON cannot serialize.
1487 return structural(encode(value))
1488 } catch (error) {
1489 warn(id, String(error))
1490 return failed
1491 }
1492 }
1493 const warn = (id: string, error: string) => {
1494 if (warned.has(id)) return
1495 warned.add(id)

Callers 5

throughFunction · 0.85
encodeQueriesFunction · 0.85
encodeSharedFunction · 0.85
encodeCollectedFunction · 0.85
encodeFunction · 0.85

Calls 10

encodeAtFunction · 0.85
structuralFunction · 0.85
guardedFunction · 0.70
warnFunction · 0.70
encodeFunction · 0.70
getMethod · 0.65
toCodecJsonMethod · 0.65
makeMethod · 0.65
setMethod · 0.65
StringFunction · 0.50

Tested by

no test coverage detected