SPB Git
3.9 KB · 49 lines typescript
1/** Shared (client-safe) types of the database engine. Values are keyed by property id in database_rows.values. */2export const PROPERTY_TYPES = ["title", "text", "number", "date", "checkbox", "status", "select", "multi_select", "url", "file", "relation", "rollup", "formula", "created_time", "last_edited_time", "ai"] as const;3export type PropertyType = (typeof PROPERTY_TYPES)[number];4export const COMPUTED_TYPES = new Set<PropertyType>(["rollup", "formula", "created_time", "last_edited_time"]);5export const READONLY_TYPES = new Set<PropertyType>(["rollup", "formula", "created_time", "last_edited_time", "ai"]);6export const VIEW_TYPES = ["table", "board", "calendar", "gallery", "timeline", "list"] as const;7export type ViewType = (typeof VIEW_TYPES)[number];8export const AGGREGATES = ["count", "count_values", "sum", "avg", "min", "max", "unique", "show"] as const;9export type Aggregate = (typeof AGGREGATES)[number];10export const OPTION_COLORS = ["gray", "blue", "green", "yellow", "orange", "red", "purple", "pink", "teal"] as const;11export type OptionColor = (typeof OPTION_COLORS)[number];12export type StatusGroup = "todo" | "in_progress" | "done";1314export interface SelectOption { id: string; name: string; color: OptionColor; group?: StatusGroup }15export interface PropertyConfig {16  options?: SelectOption[];17  format?: "number" | "integer" | "percent" | "currency";18  includeTime?: boolean;19  targetDatabaseId?: string; syncedPropertyId?: string; twoWay?: boolean; single?: boolean;20  relationPropertyId?: string; targetPropertyId?: string; aggregate?: Aggregate;21  expression?: string;22  prompt?: string;23  [k: string]: unknown;24}25export interface Property { id: string; databaseId: string; name: string; type: PropertyType; config: PropertyConfig; position: number; width: number | null }2627export const FILTER_OPS = ["eq", "neq", "contains", "not_contains", "starts_with", "ends_with", "empty", "not_empty", "gt", "gte", "lt", "lte", "before", "after", "on"] as const;28export type FilterOp = (typeof FILTER_OPS)[number];29export interface FilterRule { property: string; op: FilterOp; value?: unknown }30export interface FilterGroup { and?: FilterNode[]; or?: FilterNode[] }31export type FilterNode = FilterRule | FilterGroup;32export const isGroup = (n: FilterNode): n is FilterGroup => !("property" in n);33export interface Sort { property: string; dir: "asc" | "desc" }34export interface ViewConfig {35  filter?: FilterGroup | null; sorts?: Sort[]; groupBy?: string | null; hidden?: string[]; order?: string[]; widths?: Record<string, number>;36  dateProperty?: string | null; startProperty?: string | null; endProperty?: string | null; coverProperty?: string | null; scale?: "week" | "month";37  [k: string]: unknown;38}39export interface View { id: string; databaseId: string; name: string; type: ViewType; config: ViewConfig; position: number; isDefault: boolean }40export interface Database { id: string; pageId: string; name: string; description: string | null; icon: string | null; isTemplate: boolean; templateOf: string | null; properties: Property[]; views: View[] }41export interface RelationRef { rowId: string; pageId: string; title: string; icon?: string | null }42export interface RowOut { id: string; pageId: string; title: string; icon: string | null; values: Record<string, unknown>; position: number; createdAt: string; updatedAt: string }43export interface FileRef { id: string; url: string; name: string; mime?: string }44export interface QueryInput { viewId?: string; filter?: FilterGroup | null; sorts?: Sort[]; search?: string; limit?: number; offset?: number }45export interface QueryResult { rows: RowOut[]; total: number; limit: number; offset: number }46export interface AiPending { pending: true; at: string }47export const isError = (v: unknown): v is { error: string } => typeof v === "object" && v !== null && "error" in v && typeof (v as any).error === "string";48export const isPending = (v: unknown): v is AiPending => typeof v === "object" && v !== null && (v as any).pending === true;49
Files · 2c37cb5a3e2af18e5ba361996d453cab97da82c2
Menu

Theme