Skip to content

Collections

A collection is a TypeScript object that describes a database table and how it should appear in the admin UI. It defines:

  • Schema — Properties (columns), their types, and validation rules
  • Relations — Foreign keys, junction tables, and join paths
  • Security — Row Level Security policies
  • UI behavior — View modes, inline editing, entity views, actions
  • Lifecycle hooks — Callbacks for create, update, delete operations
import { EntityCollection } from "@rebasepro/types";
export const productsCollection: EntityCollection = {
slug: "products", // URL path and API endpoint
name: "Products", // Display name (plural)
singularName: "Product", // Display name (singular)
dbPath: "products", // PostgreSQL table name
icon: "inventory_2", // Material icon key
properties: {
name: {
type: "string",
name: "Product Name",
validation: { required: true }
},
price: {
type: "number",
name: "Price",
validation: { required: true, min: 0 }
},
category: {
type: "string",
name: "Category",
enum: [
{ id: "electronics", label: "Electronics", color: "blueDark" },
{ id: "clothing", label: "Clothing", color: "pinkLight" },
{ id: "books", label: "Books", color: "orangeDark" }
]
},
description: {
type: "string",
name: "Description",
multiline: true
},
active: {
type: "boolean",
name: "Active",
defaultValue: true
},
created_at: {
type: "date",
name: "Created At",
autoValue: "on_create",
readOnly: true
}
}
};
PropertyTypeDescription
slugstringRequired. URL-safe identifier. Used in the admin UI URL and REST API path (/api/data/{slug}).
namestringRequired. Display name (plural). Shown in navigation and page headers.
singularNamestringDisplay name for a single entity. Used in “New Product”, “Edit Product”, etc.
dbPathstringRequired. PostgreSQL table name. If different from slug, allows you to decouple URLs from table names.
iconstringMaterial icon key. See Google Fonts Icons.
PropertyTypeDescription
propertiesPropertiesRequired. Map of property key → property definition. Each key becomes a database column.
relationsRelation[]SQL relations — foreign keys, junction tables. See Relations.
securityRulesSecurityRule[]Row Level Security policies. See Security Rules.
PropertyTypeDefaultDescription
defaultViewMode"table" | "cards" | "kanban""table"Default view mode
enabledViewsViewMode[]All threeWhich view modes are available
kanbanKanbanConfigKanban configuration (column property)
openEntityMode"side_panel" | "full_screen""full_screen"How entities open for editing
inlineEditingbooleantrueEnable inline editing in the spreadsheet view
defaultSize"xs" | "s" | "m" | "l" | "xl""m"Default row height in the table
paginationboolean | numbertrue (50)Enable pagination and/or set page size
propertiesOrderstring[]Column order in the table view
hideFromNavigationbooleanfalseHide from the sidebar navigation
PropertyTypeDefaultDescription
formAutoSavebooleanfalseAuto-save on field change
hideIdFromFormbooleanfalseHide the entity ID from the form
hideIdFromCollectionbooleanfalseHide the ID column from the table
includeJsonViewbooleanfalseShow a JSON tab in the entity view
historybooleanfalseTrack changes in entity history
alwaysApplyDefaultValuesbooleanfalseApply default values on every save, not just creation
PropertyTypeDescription
callbacksEntityCallbacksLifecycle hooks (beforeSave, afterSave, beforeDelete, etc.)
entityActionsEntityAction[]Custom actions on entities (archive, publish, etc.)
ActionsReact.ComponentTypeCustom toolbar actions component
entityViewsEntityCustomView[]Custom tabs in the entity detail view
additionalFieldsAdditionalFieldDelegate[]Computed/virtual columns
subcollections() => EntityCollection[]Nested collections (e.g., order → line items)
exportableboolean | ExportConfigEnable data export
driverstringDatabase driver to use (default: "(default)")

For dynamic collections that change based on the user or external data, use a builder function:

const collectionsBuilder: EntityCollectionsBuilder = ({ user, authController }) => {
const collections = [productsCollection];
if (authController.extra?.role === "admin") {
collections.push(adminSettingsCollection);
}
return collections;
};

You can set default or forced filters:

{
// Default filter — users can change it
filter: { active: ["==", true] },
// Forced filter — cannot be changed
forceFilter: { tenant_id: ["==", currentTenantId] },
// Default sort
sort: ["created_at", "desc"]
}