/** * Farm's declarative data schema: a serializable description of models and * fields shared by integrations, applications, ORM generation, and any feature * that needs one schema story across storage targets. * * The shape is plain data, not code, so it can be inspected at build time, * mapped onto an ORM schema, and serialized to other tooling. */ type FarmSchemaFieldType = "id" | "uuid" | "string" | "text" | "boolean" | "integer" | "number" | "datetime" | "json" | "enum"; interface FarmSchemaReference { model: string; field: string; relation?: "belongsTo" | "hasOne" | "hasMany"; onDelete?: "cascade" | "restrict" | "setNull" | "noAction"; enforced?: "db" | "app" | "none"; } interface FarmSchemaField { type: FarmSchemaFieldType; name?: string; description?: string; required?: boolean; nullable?: boolean; primaryKey?: boolean; unique?: boolean; index?: boolean; list?: boolean; default?: unknown; values?: readonly string[]; reference?: FarmSchemaReference; meta?: Record; } interface FarmSchemaConstraint { type: "unique" | "index"; fields: readonly string[]; name?: string; meta?: Record; } interface FarmSchemaModel { name?: string; description?: string; fields: Record; constraints?: readonly FarmSchemaConstraint[]; meta?: Record; } interface FarmSchemaModelExtension { name?: string; description?: string; fields?: Record; constraints?: readonly FarmSchemaConstraint[]; meta?: Record; } interface FarmSchemaModelOverride { name?: string; description?: string; fields?: Record>; constraints?: readonly FarmSchemaConstraint[]; meta?: Record; } interface FarmSchema { models: Record; meta?: Record; extend?: Record; override?: Record; } /** * Declare a data schema with full type inference preserved. * * ```ts * export const schema = defineSchema({ * models: { * tasks: { * fields: { * id: { type: "uuid", primaryKey: true }, * title: { type: "string", required: true }, * }, * }, * }, * }); * ``` */ declare function defineSchema(schema: TSchema): TSchema; export { type FarmSchema, type FarmSchemaConstraint, type FarmSchemaField, type FarmSchemaFieldType, type FarmSchemaModel, type FarmSchemaModelExtension, type FarmSchemaModelOverride, type FarmSchemaReference, defineSchema };