@@ -57,21 +57,22 @@ export const ProjectTokenSchema = z.object({
5757} ) ;
5858export type IProjectToken = z . infer < typeof ProjectTokenSchema > ;
5959
60- // `id` is required when reading from the API (the backend never returns
61- // experiments without one). It is allowed to be absent only on the
62- // create path — see `ExperimentInputSchema` below.
60+ // Backend's `Optional[...]` fields are serialized as JSON `null` (Pydantic
61+ // default, no `exclude_none`). Zod's `.optional()` accepts `undefined`
62+ // only — `.nullish()` accepts `null | undefined`, which is what we need
63+ // for every column the backend marks as nullable.
6364export const ExperimentSchema = z . object ( {
6465 id : z . string ( ) . min ( 1 ) ,
65- timestamp : z . string ( ) . optional ( ) ,
66+ timestamp : z . string ( ) . nullish ( ) ,
6667 name : z . string ( ) ,
6768 description : z . string ( ) ,
68- on_cloud : z . boolean ( ) . optional ( ) ,
69+ on_cloud : z . boolean ( ) . nullish ( ) ,
6970 project_id : z . string ( ) ,
70- country_name : z . string ( ) . optional ( ) ,
71- country_iso_code : z . string ( ) . optional ( ) ,
72- region : z . string ( ) . optional ( ) ,
73- cloud_provider : z . string ( ) . optional ( ) ,
74- cloud_region : z . string ( ) . optional ( ) ,
71+ country_name : z . string ( ) . nullish ( ) ,
72+ country_iso_code : z . string ( ) . nullish ( ) ,
73+ region : z . string ( ) . nullish ( ) ,
74+ cloud_provider : z . string ( ) . nullish ( ) ,
75+ cloud_region : z . string ( ) . nullish ( ) ,
7576} ) ;
7677export type Experiment = z . infer < typeof ExperimentSchema > ;
7778
@@ -86,7 +87,7 @@ export const ExperimentReportSchema = z.object({
8687 emissions : z . number ( ) ,
8788 energy_consumed : z . number ( ) ,
8889 duration : z . number ( ) ,
89- description : z . string ( ) . optional ( ) ,
90+ description : z . string ( ) . nullish ( ) ,
9091} ) ;
9192export type ExperimentReport = z . infer < typeof ExperimentReportSchema > ;
9293
@@ -117,19 +118,19 @@ export type Emission = z.infer<typeof EmissionSchema>;
117118export const RunMetadataSchema = z . object ( {
118119 timestamp : z . string ( ) ,
119120 experiment_id : z . string ( ) ,
120- os : z . string ( ) ,
121- python_version : z . string ( ) ,
122- codecarbon_version : z . string ( ) ,
123- cpu_count : z . number ( ) ,
124- cpu_model : z . string ( ) ,
125- gpu_count : z . number ( ) ,
126- gpu_model : z . string ( ) ,
127- longitude : z . number ( ) ,
128- latitude : z . number ( ) ,
129- region : z . string ( ) ,
130- provider : z . string ( ) ,
131- ram_total_size : z . number ( ) ,
132- tracking_mode : z . string ( ) ,
121+ os : z . string ( ) . nullish ( ) ,
122+ python_version : z . string ( ) . nullish ( ) ,
123+ codecarbon_version : z . string ( ) . nullish ( ) ,
124+ cpu_count : z . number ( ) . nullish ( ) ,
125+ cpu_model : z . string ( ) . nullish ( ) ,
126+ gpu_count : z . number ( ) . nullish ( ) ,
127+ gpu_model : z . string ( ) . nullish ( ) ,
128+ longitude : z . number ( ) . nullish ( ) ,
129+ latitude : z . number ( ) . nullish ( ) ,
130+ region : z . string ( ) . nullish ( ) ,
131+ provider : z . string ( ) . nullish ( ) ,
132+ ram_total_size : z . number ( ) . nullish ( ) ,
133+ tracking_mode : z . string ( ) . nullish ( ) ,
133134} ) ;
134135export type RunMetadata = z . infer < typeof RunMetadataSchema > ;
135136
0 commit comments