Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

widgets: Extract widget_schema module.

Steve Howella4b8404701f4
diff --git a/web/src/submessage.ts b/web/src/submessage.ts
index 92b98a7fc32..4b98377ad79 100644
--- a/web/src/submessage.ts
+++ b/web/src/submessage.ts
@@ -5,30 +5,15 @@ import * as channel from "./channel.ts";
import type {MessageList} from "./message_list.ts";
import * as message_store from "./message_store.ts";
import type {Message} from "./message_store.ts";
-import {poll_widget_extra_data_schema} from "./poll_data.ts";
-import type {PollWidgetOutboundData} from "./poll_data.ts";
-import {todo_widget_extra_data_schema} from "./todo_widget.ts";
-import type {TodoWidgetOutboundData} from "./todo_widget.ts";
+import {widget_data_schema} from "./widget_schema.ts";
+import type {WidgetOutboundData} from "./widget_schema.ts";
import * as widgetize from "./widgetize.ts";
-import {zform_widget_extra_data_schema} from "./zform_data.ts";
export type Submessage = z.infer<typeof message_store.submessage_schema>;
-type WidgetOutboundData = PollWidgetOutboundData | TodoWidgetOutboundData;
-
const widget_data_event_schema = z.object({
sender_id: z.number(),
- data: z.discriminatedUnion("widget_type", [
- z.object({widget_type: z.literal("poll"), extra_data: poll_widget_extra_data_schema}),
- z.object({
- widget_type: z.literal("zform"),
- extra_data: z.nullable(zform_widget_extra_data_schema),
- }),
- z.object({
- widget_type: z.literal("todo"),
- extra_data: z.nullable(todo_widget_extra_data_schema),
- }),
- ]),
+ data: widget_data_schema,
});
const inbound_data_event_schema = z.object({
diff --git a/web/src/widget_schema.ts b/web/src/widget_schema.ts
new file mode 100644
index 00000000000..cc5dcff8a8f
--- /dev/null
+++ b/web/src/widget_schema.ts
@@ -0,0 +1,29 @@
+import * as z from "zod/mini";
+
+import {poll_widget_extra_data_schema} from "./poll_data.ts";
+import type {PollWidgetOutboundData} from "./poll_data.ts";
+import {todo_widget_extra_data_schema} from "./todo_widget.ts";
+import type {TodoWidgetOutboundData} from "./todo_widget.ts";
+import {zform_widget_extra_data_schema} from "./zform_data.ts";
+
+/*
+ We can eventually unify this module with widget_data.ts,
+ but until we can extract todo_data.ts (which is on hold
+ until some functional todo-widget changes hit the main
+ branch), we need tiny modules like this one in order
+ to prevent circular dependencies.
+*/
+
+export type WidgetOutboundData = PollWidgetOutboundData | TodoWidgetOutboundData;
+
+export const widget_data_schema = z.discriminatedUnion("widget_type", [
+ z.object({widget_type: z.literal("poll"), extra_data: poll_widget_extra_data_schema}),
+ z.object({
+ widget_type: z.literal("zform"),
+ extra_data: z.nullable(zform_widget_extra_data_schema),
+ }),
+ z.object({
+ widget_type: z.literal("todo"),
+ extra_data: z.nullable(todo_widget_extra_data_schema),
+ }),
+]);