File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
ui/frontend/reducers/output Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 1
1
import { createAsyncThunk , createSlice } from '@reduxjs/toolkit' ;
2
+ import * as z from 'zod' ;
2
3
3
4
import { adaptFetchError , jsonPost , routes } from '../../actions' ;
4
5
import { formatRequestSelector } from '../../selectors' ;
@@ -21,19 +22,22 @@ interface FormatRequestBody {
21
22
edition : string ;
22
23
}
23
24
24
- interface FormatResponseBody {
25
- success : boolean ;
26
- code : string ;
27
- stdout : string ;
28
- stderr : string ;
29
- }
25
+ const FormatResponseBody = z . object ( {
26
+ success : z . boolean ( ) ,
27
+ code : z . string ( ) ,
28
+ stdout : z . string ( ) ,
29
+ stderr : z . string ( ) ,
30
+ } ) ;
31
+
32
+ type FormatResponseBody = z . infer < typeof FormatResponseBody > ;
30
33
31
34
export const performFormat = createAsyncThunk < FormatResponseBody , void , { state : RootState } > (
32
35
sliceName ,
33
36
async ( _arg : void , { getState } ) => {
34
37
const body : FormatRequestBody = formatRequestSelector ( getState ( ) ) ;
35
38
36
- return adaptFetchError ( ( ) => jsonPost < FormatResponseBody > ( routes . format , body ) ) ;
39
+ const d = await adaptFetchError ( ( ) => jsonPost ( routes . format , body ) ) ;
40
+ return FormatResponseBody . parseAsync ( d ) ;
37
41
} ,
38
42
) ;
39
43
You can’t perform that action at this time.
0 commit comments