From f6dc40f2099f5754f5a3e0d72c9beaefe168eb8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tadeusz=20Miesi=C4=85c?= <tadeusz.miesiac@gmail.com>
Date: Mon, 23 Oct 2023 20:21:33 +0800
Subject: [PATCH] refactor(models): changed union with null to nullable to
 follow zod guidlines

---
 src/models/bioEntitySchema.ts            | 40 ++++++++++++------------
 src/models/modelSchema.ts                |  8 ++---
 src/models/modificationResiduesSchema.ts |  2 +-
 src/models/products.ts                   |  4 +--
 src/models/referenceSchema.ts            |  2 +-
 5 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/src/models/bioEntitySchema.ts b/src/models/bioEntitySchema.ts
index fc1e935a..fd0ee6a1 100644
--- a/src/models/bioEntitySchema.ts
+++ b/src/models/bioEntitySchema.ts
@@ -18,7 +18,7 @@ export const bioEntitySchema = z.object({
   references: z.array(referenceSchema),
   z: z.number(),
   notes: z.string(),
-  symbol: z.union([z.string(), z.null()]),
+  symbol: z.string().nullable(),
   homodimer: z.number(),
   nameX: z.number(),
   nameY: z.number(),
@@ -33,23 +33,23 @@ export const bioEntitySchema = z.object({
   synonyms: z.array(z.string()),
   formerSymbols: z.array(z.string()),
   fullName: z.string(),
-  abbreviation: z.union([z.string(), z.null()]),
-  formula: z.union([z.string(), z.null()]),
-  glyph: z.union([glyphSchema, z.null()]),
+  abbreviation: z.string().nullable(),
+  formula: z.string().nullable(),
+  glyph: glyphSchema.nullable(),
   activity: z.boolean(),
-  structuralState: z.union([structuralStateSchema, z.null()]),
-  hypothetical: z.union([z.boolean(), z.null()]),
+  structuralState: structuralStateSchema.nullable(),
+  hypothetical: z.boolean().nullable(),
   boundaryCondition: z.boolean(),
   constant: z.boolean(),
-  initialAmount: z.union([z.number(), z.null()]),
-  initialConcentration: z.union([z.number(), z.null()]),
-  charge: z.union([z.number(), z.null()]),
-  substanceUnits: z.union([z.string(), z.null()]),
+  initialAmount: z.number().nullable(),
+  initialConcentration: z.number().nullable(),
+  charge: z.number().nullable(),
+  substanceUnits: z.string().nullable(),
   onlySubstanceUnits: z.boolean(),
   modificationResidues: z.optional(z.array(modificationResiduesSchema)),
-  complex: z.union([z.number(), z.null()]),
-  compartment: z.union([z.number(), z.null()]),
-  submodel: z.union([submodelSchema, z.null()]),
+  complex: z.number().nullable(),
+  compartment: z.number().nullable(),
+  submodel: submodelSchema.nullable(),
   x: z.number(),
   y: z.number(),
   lineWidth: z.number(),
@@ -70,11 +70,11 @@ export const bioEntitySchema = z.object({
   upperBound: z.optional(z.boolean()),
   subsystem: z.optional(z.string()),
   geneProteinReaction: z.optional(z.string()),
-  kinetics: z.union([z.null(), z.undefined()]),
-  products: z.union([z.array(productsSchema), z.undefined()]),
-  reactants: z.union([z.array(productsSchema), z.undefined()]),
-  modifiers: z.union([z.array(productsSchema), z.undefined()]),
-  processCoordinates: z.union([z.null(), z.undefined()]),
-  line: z.union([lineSchema, z.undefined()]),
-  operators: z.union([z.array(operatorSchema), z.undefined()]),
+  kinetics: z.optional(z.null()),
+  products: z.optional(z.array(productsSchema)),
+  reactants: z.optional(z.array(productsSchema)),
+  modifiers: z.optional(z.array(productsSchema)),
+  processCoordinates: z.optional(z.null()),
+  line: z.optional(lineSchema),
+  operators: z.optional(z.array(operatorSchema)),
 });
diff --git a/src/models/modelSchema.ts b/src/models/modelSchema.ts
index 64752c8c..0c8a488d 100644
--- a/src/models/modelSchema.ts
+++ b/src/models/modelSchema.ts
@@ -15,17 +15,17 @@ export const modelSchema = z.object({
   /** size of the png tile used to visualize in frontend */
   tileSize: z.number(),
   /** default x center used in frontend visualization */
-  defaultCenterX: z.union([z.number(), z.null()]),
+  defaultCenterX: z.number().nullable(),
   /** default y center used in frontend visualization */
-  defaultCenterY: z.union([z.number(), z.null()]),
+  defaultCenterY: z.number().nullable(),
   /** default zoom level used in frontend visualization */
-  defaultZoomLevel: z.union([z.number(), z.null()]),
+  defaultZoomLevel: z.number().nullable(),
   /** minimum zoom level availbale for the map */
   minZoom: z.number(),
   /** maximum zoom level available for the map */
   maxZoom: z.number(),
   authors: z.array(authorSchema),
   references: z.array(referenceSchema),
-  creationDate: z.union([z.string(), z.null()]),
+  creationDate: z.string().nullable(),
   modificationDates: z.array(z.string()),
 });
diff --git a/src/models/modificationResiduesSchema.ts b/src/models/modificationResiduesSchema.ts
index 4b71bf72..884ebe4b 100644
--- a/src/models/modificationResiduesSchema.ts
+++ b/src/models/modificationResiduesSchema.ts
@@ -9,7 +9,7 @@ export const modificationResiduesSchema = z.object({
   position: positionSchema,
   z: z.number(),
   borderColor: colorSchema,
-  state: z.union([z.string(), z.number(), z.null()]),
+  state: z.union([z.string(), z.number()]).nullable(),
   size: z.number(),
   elementId: z.string(),
 });
diff --git a/src/models/products.ts b/src/models/products.ts
index cfc9b6b5..4807c486 100644
--- a/src/models/products.ts
+++ b/src/models/products.ts
@@ -2,6 +2,6 @@ import { z } from 'zod';
 
 export const productsSchema = z.object({
   aliasId: z.number(),
-  stoichiometry: z.union([z.number(), z.null()]),
-  type: z.union([z.string(), z.undefined()]),
+  stoichiometry: z.number().nullable(),
+  type: z.optional(z.string()),
 });
diff --git a/src/models/referenceSchema.ts b/src/models/referenceSchema.ts
index 432f0eec..30a31e28 100644
--- a/src/models/referenceSchema.ts
+++ b/src/models/referenceSchema.ts
@@ -2,7 +2,7 @@ import { z } from 'zod';
 import { articleSchema } from './articleSchema';
 
 export const referenceSchema = z.object({
-  link: z.union([z.string(), z.null()]),
+  link: z.string().nullable(),
   article: articleSchema.optional(),
   type: z.string(),
   resource: z.string(),
-- 
GitLab