From b92996f1d5924bdb78e14c40f93790f436243d11 Mon Sep 17 00:00:00 2001
From: Jorik Schellekens <joriksch@gmail.com>
Date: Wed, 23 Sep 2020 11:56:55 +0100
Subject: [PATCH] Future proof schemas by making them nonstrict

---
 src/matrix-cypher/schemas/EventSchema.ts      | 16 +++++-----
 .../schemas/PublicRoomsSchema.ts              | 32 +++++++++----------
 src/matrix-cypher/schemas/RoomAliasSchema.ts  |  7 ++--
 src/matrix-cypher/schemas/UserSchema.ts       |  7 ++--
 src/matrix-cypher/schemas/WellKnownSchema.ts  | 14 ++++----
 5 files changed, 36 insertions(+), 40 deletions(-)

diff --git a/src/matrix-cypher/schemas/EventSchema.ts b/src/matrix-cypher/schemas/EventSchema.ts
index 2b0402a..9742c05 100644
--- a/src/matrix-cypher/schemas/EventSchema.ts
+++ b/src/matrix-cypher/schemas/EventSchema.ts
@@ -17,14 +17,14 @@ limitations under the License.
 import { object, string, TypeOf } from 'zod';
 
 const EventSchema = object({
-  content: object({}).nonstrict(),
-  type: string(),
-  event_id: string(),
-  sender: string(),
-  origin_server_ts: string(),
-  unsigned: object({}).nonstrict().optional(),
-  room_id: string(),
-});
+    content: object({}).nonstrict(),
+    type: string(),
+    event_id: string(),
+    sender: string(),
+    origin_server_ts: string(),
+    unsigned: object({}).nonstrict().optional(),
+    room_id: string(),
+}).nonstrict();
 
 export type Event = TypeOf<typeof EventSchema>;
 export default EventSchema;
diff --git a/src/matrix-cypher/schemas/PublicRoomsSchema.ts b/src/matrix-cypher/schemas/PublicRoomsSchema.ts
index b33cb31..87ec8d7 100644
--- a/src/matrix-cypher/schemas/PublicRoomsSchema.ts
+++ b/src/matrix-cypher/schemas/PublicRoomsSchema.ts
@@ -17,27 +17,25 @@ limitations under the License.
 import { object, array, string, boolean, number, TypeOf } from 'zod';
 
 export const RoomSchema = object({
-  aliases: array(string()).optional(),
-  canonical_alias: string().optional(),
-  name: string().optional(),
-  num_joined_members: number(),
-  room_id: string(),
-  topic: string().optional(),
-  world_readable: boolean(),
-  guest_can_join: boolean(),
-  avatar_url: string().optional(),
-});
-
+    aliases: array(string()).optional(),
+    canonical_alias: string().optional(),
+    name: string().optional(),
+    num_joined_members: number(),
+    room_id: string(),
+    topic: string().optional(),
+    world_readable: boolean(),
+    guest_can_join: boolean(),
+    avatar_url: string().optional(),
+}).nonstrict();
 
 const PublicRoomsSchema = object({
-  chunk: array(RoomSchema),
-  next_batch: string().optional(),
-  prev_batch: string().optional(),
-  total_room_count_estimate: number().optional(),
-});
+    chunk: array(RoomSchema),
+    next_batch: string().optional(),
+    prev_batch: string().optional(),
+    total_room_count_estimate: number().optional(),
+}).nonstrict();
 
 export type Room = TypeOf<typeof RoomSchema>;
 export type PublicRooms = TypeOf<typeof PublicRoomsSchema>;
 
 export default PublicRoomsSchema;
-
diff --git a/src/matrix-cypher/schemas/RoomAliasSchema.ts b/src/matrix-cypher/schemas/RoomAliasSchema.ts
index f662a4b..3293c35 100644
--- a/src/matrix-cypher/schemas/RoomAliasSchema.ts
+++ b/src/matrix-cypher/schemas/RoomAliasSchema.ts
@@ -17,10 +17,9 @@ limitations under the License.
 import { object, array, string, TypeOf } from 'zod';
 
 const RoomAliasSchema = object({
-  room_id: string(),
-  servers: array(string()),
-});
+    room_id: string(),
+    servers: array(string()),
+}).nonstrict();
 
 export type RoomAlias = TypeOf<typeof RoomAliasSchema>;
 export default RoomAliasSchema;
-
diff --git a/src/matrix-cypher/schemas/UserSchema.ts b/src/matrix-cypher/schemas/UserSchema.ts
index 4702e8e..7e564f1 100644
--- a/src/matrix-cypher/schemas/UserSchema.ts
+++ b/src/matrix-cypher/schemas/UserSchema.ts
@@ -17,10 +17,9 @@ limitations under the License.
 import { object, string, TypeOf } from 'zod';
 
 const UserSchema = object({
-  avatar_url: string().optional(),
-  displayname: string().optional(),
-})
+    avatar_url: string().optional(),
+    displayname: string().optional(),
+}).nonstrict();
 
 export type User = TypeOf<typeof UserSchema>;
 export default UserSchema;
-
diff --git a/src/matrix-cypher/schemas/WellKnownSchema.ts b/src/matrix-cypher/schemas/WellKnownSchema.ts
index 7cfaa29..63ad0b7 100644
--- a/src/matrix-cypher/schemas/WellKnownSchema.ts
+++ b/src/matrix-cypher/schemas/WellKnownSchema.ts
@@ -17,13 +17,13 @@ limitations under the License.
 import { object, string, TypeOf } from 'zod';
 
 const WellKnownSchema = object({
-  'm.homeserver': object({
-    'base_url': string().url(),
-  }),
-  'm.identity_server': object({
-    'base_url': string().url(),
-  }),
-});
+    'm.homeserver': object({
+        base_url: string().url(),
+    }),
+    'm.identity_server': object({
+        base_url: string().url(),
+    }).optional(),
+}).nonstrict();
 
 export type WellKnown = TypeOf<typeof WellKnownSchema>;
 export default WellKnownSchema;
-- 
GitLab