( store: LazyStore, key: string, schema: S, domain: LogScope, )
| 5 | import type { LogScope } from './logger'; |
| 6 | |
| 7 | export const loadValidated = async <S extends z.ZodType>( |
| 8 | store: LazyStore, |
| 9 | key: string, |
| 10 | schema: S, |
| 11 | domain: LogScope, |
| 12 | ): Promise<z.output<S> | null> => { |
| 13 | const raw = await store.get<unknown>(key); |
| 14 | if (raw == null) { |
| 15 | return null; |
| 16 | } |
| 17 | const result = schema.safeParse(raw); |
| 18 | if (!result.success) { |
| 19 | await reportError(domain, { |
| 20 | userMessage: `${domain} data is corrupted`, |
| 21 | error: result.error, |
| 22 | }); |
| 23 | return null; |
| 24 | } |
| 25 | return result.data; |
| 26 | }; |
no test coverage detected