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

Function encodeObject

packages/effect/src/ui/MessageLog.ts:2055–2091  ·  view source on GitHub ↗
(
  ast: SchemaAST.Objects,
  value: Record<PropertyKey, unknown>,
  walk: Walk
)

Source from the content-addressed store, hash-verified

2053 * here, never values.
2054 */
2055const encodeObject = (
2056 ast: SchemaAST.Objects,
2057 value: Record<PropertyKey, unknown>,
2058 walk: Walk
2059): Schema.Json => {
2060 const applies = new Map<string, Array<SchemaAST.AST>>()
2061 for (const property of ast.propertySignatures) {
2062 if (
2063 typeof property.name === "string" && Object.hasOwn(value, property.name)
2064 ) {
2065 applies.set(property.name, [property.type])
2066 }
2067 }
2068 const properties = new Set(applies.keys())
2069 for (const index of ast.indexSignatures) {
2070 for (const key of SchemaAST.getIndexSignatureKeys(value, index.parameter)) {
2071 if (typeof key !== "string") continue
2072 const types = applies.get(key)
2073 if (types === undefined) applies.set(key, [index.type])
2074 else if (!types.includes(index.type)) types.push(index.type)
2075 }
2076 }
2077 const out: Record<string, Schema.Json> = {}
2078 for (const [key, types] of applies) {
2079 // Under two Schemas, either one's redaction could apply, so it's a placeholder. Otherwise the
2080 // parser's output is kept: the property's, or else the last index signature's.
2081 const type = properties.has(key) ? types[0]! : types[types.length - 1]!
2082 InternalRecord.assignProperty(
2083 out,
2084 key,
2085 types.length > 1 && types.some(holdsRedacted)
2086 ? redacted
2087 : guarded(() => encodeAt(type, value[key], walk))
2088 )
2089 }
2090 return out
2091}
2092/** Elements, then the rest, then the trailing elements, which take the last positions. */
2093const encodeArray = (
2094 ast: SchemaAST.Arrays,

Callers 1

encodeAtFunction · 0.85

Calls 8

encodeAtFunction · 0.85
keysMethod · 0.80
someMethod · 0.80
guardedFunction · 0.70
setMethod · 0.65
getMethod · 0.65
pushMethod · 0.65
hasMethod · 0.65

Tested by

no test coverage detected