Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 21 lines 753 Bytes
Raw
1 import { Option } from 'effect';
2
3 /**
4 * Decode a record's entries one by one, keeping only the entries that decode
5 * successfully. Used for tolerant cache-file reads: one stale or
6 * version-skewed entry drops only itself instead of discarding the whole
7 * file (which would also be persisted back on the next write, permanently
8 * destroying the good entries).
9 */
10 export const collectDecodedEntries = <A>(
11 entries: Readonly<Record<string, unknown>> | undefined,
12 decode: (value: unknown) => Option.Option<A>
13 ): Record<string, A> =>
14 Object.fromEntries(
15 Object.entries(entries ?? {}).flatMap(([key, value]) =>
16 Option.match(decode(value), {
17 onNone: () => [],
18 onSome: entry => [[key, entry] as const],
19 })
20 )
21 );