@@ -2,6 +2,7 @@ import { decode } from '@msgpack/msgpack'
22import camelcaseKeys from 'camelcase-keys'
33import { z } from 'zod'
44import { createServerFn } from '@tanstack/react-start'
5+ import { parseWithPrettify } from '@/utils/zod'
56import {
67 FeatureCompactSchema ,
78 FeatureSampleCompactSchema ,
@@ -12,7 +13,7 @@ export const fetchDictionaries = createServerFn({ method: 'GET' }).handler(
1213 async ( ) => {
1314 const response = await fetch ( `${ process . env . BACKEND_URL } /dictionaries` )
1415 const data = await response . json ( )
15- return z . array ( z . string ( ) ) . parse ( data )
16+ return parseWithPrettify ( z . array ( z . string ( ) ) , data )
1617 } ,
1718)
1819
@@ -23,7 +24,8 @@ export const fetchMetrics = createServerFn({ method: 'GET' })
2324 `${ process . env . BACKEND_URL } /dictionaries/${ dictionary } /metrics` ,
2425 )
2526 const data = await response . json ( )
26- return z . object ( { metrics : z . array ( z . string ( ) ) } ) . parse ( data ) . metrics
27+ return parseWithPrettify ( z . object ( { metrics : z . array ( z . string ( ) ) } ) , data )
28+ . metrics
2729 } )
2830
2931export type MetricFilters = Record < string , { min ?: number ; max ?: number } >
@@ -81,7 +83,7 @@ export const fetchFeature = createServerFn({ method: 'GET' })
8183 ] ,
8284 } )
8385
84- return FeatureSchema . parse ( camelCased )
86+ return parseWithPrettify ( FeatureSchema , camelCased )
8587 } )
8688
8789export const fetchSamplings = createServerFn ( { method : 'GET' } )
@@ -100,9 +102,10 @@ export const fetchSamplings = createServerFn({ method: 'GET' })
100102 deep : true ,
101103 } )
102104
103- return z
104- . array ( z . object ( { name : z . string ( ) , length : z . number ( ) } ) )
105- . parse ( camelCased )
105+ return parseWithPrettify (
106+ z . array ( z . object ( { name : z . string ( ) , length : z . number ( ) } ) ) ,
107+ camelCased ,
108+ )
106109 } )
107110
108111export const fetchSamples = createServerFn ( { method : 'GET' } )
@@ -150,7 +153,7 @@ export const fetchSamples = createServerFn({ method: 'GET' })
150153 const decoded = decode ( new Uint8Array ( arrayBuffer ) ) as any
151154 const camelCased = camelcaseKeys ( decoded )
152155
153- return z . array ( FeatureSampleCompactSchema ) . parse ( camelCased )
156+ return parseWithPrettify ( z . array ( FeatureSampleCompactSchema ) , camelCased )
154157 } ,
155158 )
156159
@@ -188,7 +191,7 @@ export const countFeatures = createServerFn({ method: 'GET' })
188191 }
189192
190193 const data = await response . json ( )
191- return z . object ( { count : z . number ( ) } ) . parse ( data ) . count
194+ return parseWithPrettify ( z . object ( { count : z . number ( ) } ) , data ) . count
192195 } )
193196
194197export const fetchFeatures = createServerFn ( { method : 'GET' } )
@@ -224,7 +227,7 @@ export const fetchFeatures = createServerFn({ method: 'GET' })
224227 ] ,
225228 } )
226229
227- return z . array ( FeatureCompactSchema ) . parse ( camelCased )
230+ return parseWithPrettify ( z . array ( FeatureCompactSchema ) , camelCased )
228231 } )
229232
230233export const submitCustomInput = createServerFn ( { method : 'POST' } )
@@ -257,7 +260,7 @@ export const submitCustomInput = createServerFn({ method: 'POST' })
257260 stopPaths : [ 'context' ] ,
258261 } )
259262
260- return FeatureSampleCompactSchema . parse ( camelCased )
263+ return parseWithPrettify ( FeatureSampleCompactSchema , camelCased )
261264 } )
262265
263266export const toggleBookmark = createServerFn ( { method : 'POST' } )
@@ -343,12 +346,13 @@ export const dictionaryInference = createServerFn({ method: 'POST' })
343346 ] ,
344347 } )
345348
346- return z
347- . array (
349+ return parseWithPrettify (
350+ z . array (
348351 z . object ( {
349352 feature : FeatureCompactSchema ,
350353 inference : FeatureSampleCompactSchema ,
351354 } ) ,
352- )
353- . parse ( camelCased )
355+ ) ,
356+ camelCased ,
357+ )
354358 } )
0 commit comments