import type { Database } from "./database.js"; import type { DateFormat, Icon, NumberFormat, SelectOption, StatusGroup } from "./types.js"; export type TitleProperty = { type: "title" }; export type TextProperty = { type: "text" }; export type PropertyConfiguration = | TitleProperty | TextProperty | { type: "url" } | { type: "email" } | { type: "phone_number" } | { type: "checkbox" } | { type: "file" } | { type: "number"; format?: NumberFormat } | { type: "date"; date_format?: DateFormat } | { type: "select"; options: SelectOption[] } | { type: "multi_select"; options: SelectOption[] } | { type: "status"; groups: StatusGroup[] } | { type: "people" } | { type: "place" } | { type: "relation"; database: Database; config: { twoWay: false } | { twoWay: true; relatedPropertyName: string }; }; export type DatabaseSchema = Record; export type DatabaseSchemaOptions = { databaseIcon?: Icon; subItems?: { parentPropertyName: string; childPropertyName: string }; }; export const Schema = { title: (): TitleProperty => ({ type: "title" }), richText: (): TextProperty => ({ type: "text" }), url: (): { type: "url" } => ({ type: "url" }), email: (): { type: "email" } => ({ type: "email" }), phoneNumber: (): { type: "phone_number" } => ({ type: "phone_number" }), checkbox: (): { type: "checkbox" } => ({ type: "checkbox" }), file: (): { type: "file" } => ({ type: "file" }), number: (format?: NumberFormat): { type: "number"; format?: NumberFormat } => ({ type: "number", ...(format === undefined ? {} : { format }), }), date: (date_format?: DateFormat): { type: "date"; date_format?: DateFormat } => ({ type: "date", ...(date_format === undefined ? {} : { date_format }), }), select: (options: SelectOption[]): { type: "select"; options: SelectOption[] } => ({ type: "select", options, }), multiSelect: (options: SelectOption[]): { type: "multi_select"; options: SelectOption[] } => ({ type: "multi_select", options, }), status: (config: { groups: StatusGroup[] }): { type: "status"; groups: StatusGroup[] } => ({ type: "status", groups: config.groups, }), people: (): { type: "people" } => ({ type: "people" }), place: (): { type: "place" } => ({ type: "place" }), relation: ( database: Database, config?: { twoWay: false } | { twoWay: true; relatedPropertyName: string }, ): Extract => ({ type: "relation", database, config: config ?? { twoWay: false }, }), };