mirror of https://github.com/zulip/zulip.git
bot_data: Avoid deprecated ZodObject.deepPartial().
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
697c79a6cc
commit
2dce73ecfa
|
@ -1,6 +1,7 @@
|
|||
import type {z} from "zod";
|
||||
|
||||
import {server_add_bot_schema, server_update_bot_schema, services_schema} from "./bot_types";
|
||||
import type {services_schema} from "./bot_types";
|
||||
import {server_add_bot_schema, server_update_bot_schema} from "./bot_types";
|
||||
import * as people from "./people";
|
||||
import type {StateData} from "./state_data";
|
||||
|
||||
|
@ -35,16 +36,15 @@ export function update(bot_id: number, bot_update: ServerUpdateBotData): void {
|
|||
const bot = bots.get(bot_id)!;
|
||||
// TODO/typescript: Move validation to the caller when
|
||||
// server_events_dispatch.js is converted to TypeScript.
|
||||
Object.assign(bot, server_update_bot_schema.deepPartial().parse(bot_update));
|
||||
const {services: services_update, ...bot_update_rest} =
|
||||
server_update_bot_schema.parse(bot_update);
|
||||
|
||||
Object.assign(bot, bot_update_rest);
|
||||
|
||||
// We currently only support one service per bot.
|
||||
const service = services.get(bot_id)![0];
|
||||
if (
|
||||
service !== undefined &&
|
||||
bot_update.services !== undefined &&
|
||||
bot_update.services.length > 0
|
||||
) {
|
||||
Object.assign(service, services_schema.parse(bot_update.services)[0]);
|
||||
if (service !== undefined && services_update !== undefined && services_update.length > 0) {
|
||||
Object.assign(service, services_update[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,13 @@ export const services_schema = z.union([
|
|||
z.array(embedded_service_schema),
|
||||
]);
|
||||
|
||||
export const server_update_bot_schema = basic_bot_schema.extend({
|
||||
services: services_schema,
|
||||
export const server_update_bot_schema = basic_bot_schema.partial().extend({
|
||||
services: services_schema.optional(),
|
||||
});
|
||||
|
||||
export const server_add_bot_schema = server_update_bot_schema.extend({
|
||||
export const server_add_bot_schema = basic_bot_schema.extend({
|
||||
bot_type: z.number(),
|
||||
email: z.string(),
|
||||
is_active: z.boolean(),
|
||||
services: services_schema,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue