Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
sub_store: Generate StreamSubscription type from a schema.
evykassirerc133f7f21969
diff --git a/web/src/state_data.ts b/web/src/state_data.tsindex 7b5b40319b0..f593f87259d 100644--- a/web/src/state_data.ts+++ b/web/src/state_data.ts@@ -3,9 +3,9 @@ import {z} from "zod";import {server_add_bot_schema} from "./bot_types";import {realm_default_settings_schema} from "./realm_user_settings_defaults";import {+ api_stream_subscription_schema,never_subscribed_stream_schema,stream_schema,- stream_subscription_schema,} from "./stream_types";import {user_settings_schema} from "./user_settings";import {user_status_schema} from "./user_status_types";@@ -473,8 +473,8 @@ export const state_data_schema = z.and(z.object({- subscriptions: z.array(stream_subscription_schema),- unsubscribed: z.array(stream_subscription_schema),+ subscriptions: z.array(api_stream_subscription_schema),+ unsubscribed: z.array(api_stream_subscription_schema),never_subscribed: z.array(never_subscribed_stream_schema),realm_default_streams: z.array(stream_schema),})diff --git a/web/src/stream_types.ts b/web/src/stream_types.tsindex 5cd3eb0dcb0..cb6b37455f5 100644--- a/web/src/stream_types.ts+++ b/web/src/stream_types.ts@@ -50,7 +50,7 @@ export const stream_properties_schema = stream_specific_notification_settings_sc});// This is the raw data we get from the server for a subscription.-export const stream_subscription_schema = stream_schema.merge(stream_properties_schema).extend({+export const api_stream_subscription_schema = stream_schema.merge(stream_properties_schema).extend({email_address: z.string().optional(),stream_weekly_traffic: z.number().nullable(),subscribers: z.array(z.number()).optional(),diff --git a/web/src/sub_store.ts b/web/src/sub_store.tsindex beac48f5eaa..4a7d388ef49 100644--- a/web/src/sub_store.ts+++ b/web/src/sub_store.ts@@ -1,4 +1,4 @@-import type {z} from "zod";+import {z} from "zod";import * as blueslip from "./blueslip";import type {@@ -6,8 +6,8 @@ import type {stream_properties_schema,stream_schema,stream_specific_notification_settings_schema,- stream_subscription_schema,} from "./stream_types";+import {api_stream_subscription_schema} from "./stream_types";export type Stream = z.infer<typeof stream_schema>;export type StreamSpecificNotificationSettings = z.infer<@@ -15,18 +15,21 @@ export type StreamSpecificNotificationSettings = z.infer<>;export type NeverSubscribedStream = z.infer<typeof never_subscribed_stream_schema>;export type StreamProperties = z.infer<typeof stream_properties_schema>;-export type ApiStreamSubscription = z.infer<typeof stream_subscription_schema>;--// These properties are added in `stream_data` when hydrating the streams and are not present in the data we get from the server.-export type ExtraStreamAttrs = {- render_subscribers: boolean;- newly_subscribed: boolean;- subscribed: boolean;- previously_subscribed: boolean;-};+export type ApiStreamSubscription = z.infer<typeof api_stream_subscription_schema>;// This is the actual type of subscription objects we use in the app.-export type StreamSubscription = Omit<ApiStreamSubscription, "subscribers"> & ExtraStreamAttrs;+export const stream_subscription_schema = api_stream_subscription_schema+ .omit({+ subscribers: true,+ })+ .extend({+ // These properties are added in `stream_data` when hydrating the streams and are not present in the data we get from the server.+ render_subscribers: z.boolean(),+ newly_subscribed: z.boolean(),+ subscribed: z.boolean(),+ previously_subscribed: z.boolean(),+ });+export type StreamSubscription = z.infer<typeof stream_subscription_schema>;const subs_by_stream_id = new Map<number, StreamSubscription>();