tianji/prisma/zod/workspace.ts

45 lines
1.8 KiB
TypeScript
Raw Normal View History

import * as z from "zod"
2023-12-13 10:21:04 +00:00
import * as imports from "./schemas"
import { CompleteWorkspacesOnUsers, RelatedWorkspacesOnUsersModelSchema, CompleteWebsite, RelatedWebsiteModelSchema, CompleteNotification, RelatedNotificationModelSchema, CompleteMonitor, RelatedMonitorModelSchema, CompleteMonitorStatusPage, RelatedMonitorStatusPageModelSchema, CompleteUser, RelatedUserModelSchema } from "./index"
// Helper schema for JSON fields
type Literal = boolean | number | string
type Json = Literal | { [key: string]: Json } | Json[]
const literalSchema = z.union([z.string(), z.number(), z.boolean()])
const jsonSchema: z.ZodSchema<Json> = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]))
export const WorkspaceModelSchema = z.object({
id: z.string(),
name: z.string(),
dashboardOrder: z.string().array(),
/**
* [DashboardLayout]
*/
dashboardLayout: jsonSchema,
createdAt: z.date(),
updatedAt: z.date(),
})
export interface CompleteWorkspace extends z.infer<typeof WorkspaceModelSchema> {
users: CompleteWorkspacesOnUsers[]
websites: CompleteWebsite[]
notifications: CompleteNotification[]
monitors: CompleteMonitor[]
2023-12-13 10:21:04 +00:00
monitorStatusPages: CompleteMonitorStatusPage[]
selectedUsers: CompleteUser[]
}
/**
* RelatedWorkspaceModelSchema contains all relations on your model in addition to the scalars
*
* NOTE: Lazy required in case of potential circular dependencies within schema
*/
export const RelatedWorkspaceModelSchema: z.ZodSchema<CompleteWorkspace> = z.lazy(() => WorkspaceModelSchema.extend({
users: RelatedWorkspacesOnUsersModelSchema.array(),
websites: RelatedWebsiteModelSchema.array(),
notifications: RelatedNotificationModelSchema.array(),
monitors: RelatedMonitorModelSchema.array(),
2023-12-13 10:21:04 +00:00
monitorStatusPages: RelatedMonitorStatusPageModelSchema.array(),
selectedUsers: RelatedUserModelSchema.array(),
}))