(schema: Schema.Top, value: unknown)
| 2122 | * @internal |
| 2123 | */ |
| 2124 | export const encodeArgs = (schema: Schema.Top, value: unknown): Schema.Json => { |
| 2125 | const walk: Walk = { path: new Set(), strict: false, leaf: fallback } |
| 2126 | // A struct or a class is encoded field by field. |
| 2127 | const fields = (schema as { readonly fields?: Schema.Struct.Fields }).fields |
| 2128 | if (fields !== undefined && isPlainRecord(value)) { |
| 2129 | return within(walk.path, value, () => { |
| 2130 | const out: Record<string, Schema.Json> = {} |
| 2131 | for (const key of Object.keys(fields)) { |
| 2132 | if (!Object.hasOwn(value, key)) continue |
| 2133 | InternalRecord.assignProperty( |
| 2134 | out, |
| 2135 | key, |
| 2136 | guarded(() => encodeAt((fields[key] as Schema.Top).ast, value[key], walk)) |
| 2137 | ) |
| 2138 | } |
| 2139 | return out |
| 2140 | }) |
| 2141 | } |
| 2142 | return guarded(() => encodeAt(schema.ast, value, walk)) |
| 2143 | } |
| 2144 | |
| 2145 | const encodeCause = (cause: Cause.Cause<unknown>): typeof CauseWire.Type => ({ |
| 2146 | pretty: Cause.pretty(cause), |
no test coverage detected