Merge branch 't3code/61c5f7df' into v2/rewrite
This commit is contained in:
@@ -187,6 +187,8 @@ export type ClientSettings = z.infer<typeof import("./rpcSchemas.js").ClientSett
|
||||
|
||||
export type ServerSettings = z.infer<typeof import("./rpcSchemas.js").ServerSettingsSchema>;
|
||||
|
||||
export type UserProfile = z.infer<typeof import("./rpcSchemas.js").UserProfileSchema>;
|
||||
|
||||
export type RpcRequestMap = {
|
||||
"portfolio.get": undefined;
|
||||
"portfolio.addHolding": { ticker: string };
|
||||
|
||||
@@ -28,12 +28,20 @@ const tickerString = z.string().trim().min(1).max(16);
|
||||
const nonNegativeIndex = z.number().int().min(0);
|
||||
const unknownRecord = z.record(z.unknown());
|
||||
|
||||
export const UserProfileSchema = z.object({
|
||||
name: z.string().min(1).default(""),
|
||||
role: z.string().min(1).default(""),
|
||||
email: z.string().email().optional(),
|
||||
phone: z.string().optional(),
|
||||
});
|
||||
|
||||
export const ClientSettingsSchema = z.object({
|
||||
theme: z.enum(["light", "dark", "system"]),
|
||||
density: z.enum(["comfortable", "compact", "dense"]),
|
||||
sidebarWidth: z.number().int().min(160).max(520),
|
||||
navCollapsed: z.record(z.boolean()),
|
||||
keybindings: z.record(z.string()),
|
||||
profile: UserProfileSchema.partial().default({}),
|
||||
});
|
||||
|
||||
export const ServerSettingsSchema = z.object({
|
||||
|
||||
@@ -25,7 +25,7 @@ import type {
|
||||
ClientSettings,
|
||||
ServerSettings,
|
||||
} from "@mosaiciq/contracts/rpc";
|
||||
import { ClientSettingsSchema, ServerSettingsSchema } from "@mosaiciq/contracts/rpcSchemas";
|
||||
import { ClientSettingsSchema, ServerSettingsSchema, UserProfileSchema } from "@mosaiciq/contracts/rpcSchemas";
|
||||
|
||||
export function parseJsonWithSchema<T>(
|
||||
value: string,
|
||||
@@ -1024,6 +1024,7 @@ const DEFAULT_CLIENT_SETTINGS: ClientSettings = {
|
||||
"navigation.agents": "Cmd+4",
|
||||
"navigation.home": "Cmd+0",
|
||||
},
|
||||
profile: {},
|
||||
};
|
||||
|
||||
export function getClientSettings(db: Db): ClientSettings {
|
||||
@@ -1041,6 +1042,9 @@ export function getClientSettings(db: Db): ClientSettings {
|
||||
} else if (row.key === "navCollapsed") {
|
||||
const navCollapsed = z.record(z.boolean()).safeParse(parsed);
|
||||
if (navCollapsed.success) settings.navCollapsed = { ...settings.navCollapsed, ...navCollapsed.data };
|
||||
} else if (row.key === "profile") {
|
||||
const profile = UserProfileSchema.partial().safeParse(parsed);
|
||||
if (profile.success) settings.profile = { ...settings.profile, ...profile.data };
|
||||
} else {
|
||||
const candidate = { ...settings, [row.key]: parsed };
|
||||
const validated = ClientSettingsSchema.safeParse(candidate);
|
||||
@@ -1083,6 +1087,9 @@ export function updateClientSettings(db: Db, settings: Partial<ClientSettings>):
|
||||
if (settings.keybindings !== undefined) {
|
||||
updateClientSetting(db, "keybindings", settings.keybindings);
|
||||
}
|
||||
if (settings.profile !== undefined) {
|
||||
updateClientSetting(db, "profile", settings.profile);
|
||||
}
|
||||
}
|
||||
|
||||
export function getServerSettings(db: Db): ServerSettings {
|
||||
|
||||
Reference in New Issue
Block a user