Merge pull request #139 from matrix-org/leniant-schemas
Future proof schemas by making them nonstrict
This commit is contained in:
commit
5d6e1e8b11
5 changed files with 36 additions and 40 deletions
|
@ -17,14 +17,14 @@ limitations under the License.
|
||||||
import { object, string, TypeOf } from 'zod';
|
import { object, string, TypeOf } from 'zod';
|
||||||
|
|
||||||
const EventSchema = object({
|
const EventSchema = object({
|
||||||
content: object({}).nonstrict(),
|
content: object({}).nonstrict(),
|
||||||
type: string(),
|
type: string(),
|
||||||
event_id: string(),
|
event_id: string(),
|
||||||
sender: string(),
|
sender: string(),
|
||||||
origin_server_ts: string(),
|
origin_server_ts: string(),
|
||||||
unsigned: object({}).nonstrict().optional(),
|
unsigned: object({}).nonstrict().optional(),
|
||||||
room_id: string(),
|
room_id: string(),
|
||||||
});
|
}).nonstrict();
|
||||||
|
|
||||||
export type Event = TypeOf<typeof EventSchema>;
|
export type Event = TypeOf<typeof EventSchema>;
|
||||||
export default EventSchema;
|
export default EventSchema;
|
||||||
|
|
|
@ -17,27 +17,25 @@ limitations under the License.
|
||||||
import { object, array, string, boolean, number, TypeOf } from 'zod';
|
import { object, array, string, boolean, number, TypeOf } from 'zod';
|
||||||
|
|
||||||
export const RoomSchema = object({
|
export const RoomSchema = object({
|
||||||
aliases: array(string()).optional(),
|
aliases: array(string()).optional(),
|
||||||
canonical_alias: string().optional(),
|
canonical_alias: string().optional(),
|
||||||
name: string().optional(),
|
name: string().optional(),
|
||||||
num_joined_members: number(),
|
num_joined_members: number(),
|
||||||
room_id: string(),
|
room_id: string(),
|
||||||
topic: string().optional(),
|
topic: string().optional(),
|
||||||
world_readable: boolean(),
|
world_readable: boolean(),
|
||||||
guest_can_join: boolean(),
|
guest_can_join: boolean(),
|
||||||
avatar_url: string().optional(),
|
avatar_url: string().optional(),
|
||||||
});
|
}).nonstrict();
|
||||||
|
|
||||||
|
|
||||||
const PublicRoomsSchema = object({
|
const PublicRoomsSchema = object({
|
||||||
chunk: array(RoomSchema),
|
chunk: array(RoomSchema),
|
||||||
next_batch: string().optional(),
|
next_batch: string().optional(),
|
||||||
prev_batch: string().optional(),
|
prev_batch: string().optional(),
|
||||||
total_room_count_estimate: number().optional(),
|
total_room_count_estimate: number().optional(),
|
||||||
});
|
}).nonstrict();
|
||||||
|
|
||||||
export type Room = TypeOf<typeof RoomSchema>;
|
export type Room = TypeOf<typeof RoomSchema>;
|
||||||
export type PublicRooms = TypeOf<typeof PublicRoomsSchema>;
|
export type PublicRooms = TypeOf<typeof PublicRoomsSchema>;
|
||||||
|
|
||||||
export default PublicRoomsSchema;
|
export default PublicRoomsSchema;
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,9 @@ limitations under the License.
|
||||||
import { object, array, string, TypeOf } from 'zod';
|
import { object, array, string, TypeOf } from 'zod';
|
||||||
|
|
||||||
const RoomAliasSchema = object({
|
const RoomAliasSchema = object({
|
||||||
room_id: string(),
|
room_id: string(),
|
||||||
servers: array(string()),
|
servers: array(string()),
|
||||||
});
|
}).nonstrict();
|
||||||
|
|
||||||
export type RoomAlias = TypeOf<typeof RoomAliasSchema>;
|
export type RoomAlias = TypeOf<typeof RoomAliasSchema>;
|
||||||
export default RoomAliasSchema;
|
export default RoomAliasSchema;
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,9 @@ limitations under the License.
|
||||||
import { object, string, TypeOf } from 'zod';
|
import { object, string, TypeOf } from 'zod';
|
||||||
|
|
||||||
const UserSchema = object({
|
const UserSchema = object({
|
||||||
avatar_url: string().optional(),
|
avatar_url: string().optional(),
|
||||||
displayname: string().optional(),
|
displayname: string().optional(),
|
||||||
})
|
}).nonstrict();
|
||||||
|
|
||||||
export type User = TypeOf<typeof UserSchema>;
|
export type User = TypeOf<typeof UserSchema>;
|
||||||
export default UserSchema;
|
export default UserSchema;
|
||||||
|
|
||||||
|
|
|
@ -17,13 +17,13 @@ limitations under the License.
|
||||||
import { object, string, TypeOf } from 'zod';
|
import { object, string, TypeOf } from 'zod';
|
||||||
|
|
||||||
const WellKnownSchema = object({
|
const WellKnownSchema = object({
|
||||||
'm.homeserver': object({
|
'm.homeserver': object({
|
||||||
'base_url': string().url(),
|
base_url: string().url(),
|
||||||
}),
|
}),
|
||||||
'm.identity_server': object({
|
'm.identity_server': object({
|
||||||
'base_url': string().url(),
|
base_url: string().url(),
|
||||||
}),
|
}).optional(),
|
||||||
});
|
}).nonstrict();
|
||||||
|
|
||||||
export type WellKnown = TypeOf<typeof WellKnownSchema>;
|
export type WellKnown = TypeOf<typeof WellKnownSchema>;
|
||||||
export default WellKnownSchema;
|
export default WellKnownSchema;
|
||||||
|
|
Loading…
Reference in a new issue