@rebasepro/types 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,34 +58,44 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
58
58
 
59
59
 
60
60
  /**
61
- * Which driver handles this collection.
62
- * Use this to route collections to different backends:
63
- * - `"postgres"` - Route to PostgreSQL backend
64
- * - `"firestore"` - Route to Firestore (client-side)
65
- * - `"mongodb"` - Route to MongoDB backend
66
- * - Custom IDs for your own driver implementations
61
+ * The data source this collection belongs to — the routing key shared by
62
+ * the frontend router and the backend driver registry. It points at a
63
+ * {@link DataSourceDefinition} registered on `<Rebase dataSources>` (front)
64
+ * and `initRebase({ dataSources })` (back).
67
65
  *
68
- * If not specified, the default driver `"(default)"` is used.
66
+ * If not specified, the default data source `"(default)"` is used, which
67
+ * for a standard Rebase app is the server-mediated Postgres backend.
69
68
  *
70
69
  * @example
71
- * // Simple - no driver needed for default
70
+ * // Default data source (server-mediated Postgres)
72
71
  * { slug: "products" }
73
72
  *
74
- * // Firestore collection (client-side real-time)
75
- * { slug: "analytics", driver: "firestore" }
73
+ * // A direct-transport Firestore data source registered as "analytics"
74
+ * { slug: "events", dataSource: "analytics" }
75
+ */
76
+ dataSource?: string;
77
+
78
+ /**
79
+ * The engine backing this collection (`"postgres"`, `"firestore"`,
80
+ * `"mongodb"`, or a custom id). Drives editor capabilities (relations vs
81
+ * subcollections, RLS, column types).
82
+ *
83
+ * @deprecated Prefer {@link dataSource} for routing. `driver` is retained
84
+ * as an engine hint and for backward compatibility: when `dataSource` is
85
+ * omitted it also acts as the data-source key.
76
86
  *
77
- * // Multiple databases within a driver
78
- * { slug: "orders", driver: "postgres", databaseId: "orders_db" }
87
+ * If not specified, `"postgres"` is assumed.
79
88
  */
80
89
  driver?: string;
81
90
 
82
91
  /**
83
- * Which database within the driver.
92
+ * Which database within the engine.
84
93
  * - For Firestore: The Firestore database ID (e.g., for multi-database projects)
85
94
  * - For PostgreSQL: Schema or database name
86
95
  * - For MongoDB: Database name
87
96
  *
88
- * If not specified, the default database of the driver is used.
97
+ * If not specified, the default database of the engine is used. Resolved
98
+ * from the collection's {@link DataSourceDefinition} when omitted here.
89
99
  */
90
100
  databaseId?: string;
91
101
 
@@ -165,6 +175,26 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
165
175
  */
166
176
  auth?: boolean | AuthCollectionConfig;
167
177
 
178
+ /**
179
+ * Opt out of the framework's default Row Level Security policies for
180
+ * authentication collections.
181
+ *
182
+ * When a collection has `auth` enabled, the schema generator automatically
183
+ * injects an admin-only write policy (INSERT/UPDATE/DELETE require the
184
+ * `admin` role, or the trusted server context) for any write operation that
185
+ * the collection does not already cover with an explicit `securityRules`
186
+ * entry. This makes privileged columns such as `roles` safe by default — a
187
+ * non-admin cannot modify the user row through the data API regardless of
188
+ * which code path issues the write.
189
+ *
190
+ * Defining your own write rule for an operation overrides the default for
191
+ * that operation. Set this flag to `true` to remove the default policies
192
+ * entirely and take full responsibility for the collection's RLS.
193
+ *
194
+ * @default false
195
+ */
196
+ disableDefaultAuthPolicies?: boolean;
197
+
168
198
 
169
199
  /**
170
200
  * Order in which the properties are displayed.
@@ -321,6 +351,13 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
321
351
  */
322
352
  ownerId?: string;
323
353
 
354
+ /**
355
+ * Arbitrary key-value metadata for external consumers.
356
+ * Not interpreted by Rebase — passed through serialization unchanged.
357
+ * Used by domain apps to store custom per-collection config.
358
+ */
359
+ metadata?: Record<string, unknown>;
360
+
324
361
  /**
325
362
  * Overrides for the entity view, like the data source or the storage source.
326
363
  */
@@ -375,7 +412,7 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
375
412
  * Possible values: "table", "cards", "kanban".
376
413
  * Defaults to all three: ["table", "cards", "kanban"].
377
414
  * Note: "kanban" will only be available if the collection has at least
378
- * one string property with enumValues defined, regardless of this setting.
415
+ * one string property with `enum` defined, regardless of this setting.
379
416
  */
380
417
  enabledViews?: ViewMode[];
381
418
 
@@ -619,9 +656,9 @@ export function isMongoDBCollection<M extends Record<string, unknown> = Record<s
619
656
  export interface KanbanConfig<M extends Record<string, unknown> = Record<string, unknown>> {
620
657
  /**
621
658
  * Property key to use for Kanban board columns.
622
- * Must reference a string property with enumValues defined.
659
+ * Must reference a string property with `enum` values defined.
623
660
  * Entities will be grouped into columns based on this property's value.
624
- * The column order is determined by the order of enumValues in the property.
661
+ * The column order is determined by the order of `enum` values in the property.
625
662
  */
626
663
  columnProperty: Extract<keyof M, string> | (string & {});
627
664
  }
@@ -53,6 +53,90 @@ export interface DataSourceCapabilities {
53
53
  */
54
54
  export type DataSourceFeatures = Omit<DataSourceCapabilities, "key" | "label">;
55
55
 
56
+ /**
57
+ * The default data-source key, used when a collection does not name a
58
+ * `dataSource`. Shared by the frontend router and the backend driver
59
+ * registry so both agree on "the default database".
60
+ * @group Models
61
+ */
62
+ export const DEFAULT_DATA_SOURCE_KEY = "(default)";
63
+
64
+ /**
65
+ * How the *frontend* reaches a data source.
66
+ *
67
+ * - `"server"` — through the Rebase backend (the `RebaseClient`). The backend
68
+ * holds the actual database adapter and routes by data-source key. This is
69
+ * the default and covers Postgres, MongoDB, and any other server-mediated
70
+ * engine.
71
+ * - `"direct"` — straight from the client to the external backend via its own
72
+ * SDK driver (e.g. Firestore). The Rebase backend is not in the data path.
73
+ * - `"custom"` — a developer-supplied {@link DataDriver}, transport unspecified.
74
+ *
75
+ * @group Models
76
+ */
77
+ export type DataSourceTransport = "server" | "direct" | "custom";
78
+
79
+ /**
80
+ * Declarative definition of a data source — a named place data lives.
81
+ *
82
+ * Declared once and shared front and back: the frontend uses it to decide
83
+ * transport (client vs direct driver), the backend uses the same `key` to
84
+ * resolve a database adapter, and the editor derives capabilities from
85
+ * `engine`. Collections reference a definition by its `key` via
86
+ * `collection.dataSource`.
87
+ *
88
+ * @group Models
89
+ */
90
+ export interface DataSourceDefinition {
91
+ /**
92
+ * Unique identifier for this data source. Collections point at it via
93
+ * `dataSource`. Defaults to {@link DEFAULT_DATA_SOURCE_KEY}.
94
+ */
95
+ key: string;
96
+
97
+ /**
98
+ * The engine backing this data source (e.g. `"postgres"`, `"mongodb"`,
99
+ * `"firestore"`, or a custom id). Determines the
100
+ * {@link DataSourceCapabilities} surfaced in the editor.
101
+ */
102
+ engine: string;
103
+
104
+ /**
105
+ * How the frontend reaches this source. Defaults to `"server"`.
106
+ */
107
+ transport: DataSourceTransport;
108
+
109
+ /**
110
+ * The physical database/schema/Firestore-database within the engine.
111
+ * Threaded to drivers/adapters as the existing `databaseId` runtime
112
+ * parameter. Defaults to the engine's own default.
113
+ */
114
+ databaseId?: string;
115
+
116
+ /** Human-readable label for the UI. */
117
+ label?: string;
118
+ }
119
+
120
+ /**
121
+ * The resolved data source for a collection: the single source of truth that
122
+ * the frontend router, backend registry, and editor all derive from.
123
+ * Produced by `resolveDataSource(collection, registry)`.
124
+ *
125
+ * @group Models
126
+ */
127
+ export interface ResolvedDataSource {
128
+ /** Data-source key (routing key, shared front + back). */
129
+ key: string;
130
+ /** Engine backing the source (drives capabilities). */
131
+ engine: string;
132
+ /** Frontend transport. */
133
+ transport: DataSourceTransport;
134
+ /** Within-engine instance, if any (the `databaseId` runtime param). */
135
+ databaseId?: string;
136
+ /** Capabilities derived from {@link engine}. */
137
+ capabilities: DataSourceCapabilities;
138
+ }
139
+
56
140
  // ── Built-in driver capabilities ─────────────────────────────────────
57
141
 
58
142
  /** @group Models */
@@ -69,7 +69,7 @@ export interface EntityAction<M extends Record<string, unknown> = Record<string,
69
69
 
70
70
  export type EntityActionClickProps<M extends Record<string, unknown>, USER extends User = User> = {
71
71
  entity?: Entity<M>;
72
- context: RebaseContext<USER>;
72
+ context?: RebaseContext<USER>;
73
73
 
74
74
  path?: string;
75
75
  collection?: EntityCollection<M>;
@@ -93,7 +93,7 @@ export type EntityActionClickProps<M extends Record<string, unknown>, USER exten
93
93
  /**
94
94
  * If the action is rendered in the form, is it open in a side panel or full screen?
95
95
  */
96
- openEntityMode: "side_panel" | "full_screen" | "split" | "dialog";
96
+ openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
97
97
 
98
98
  /**
99
99
  * Optional selection controller, present if the action is being called from a collection view
@@ -55,7 +55,7 @@ export interface FormContext<M extends Record<string, unknown> = Record<string,
55
55
 
56
56
  savingError?: Error;
57
57
 
58
- openEntityMode: "side_panel" | "full_screen" | "split" | "dialog";
58
+ openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
59
59
 
60
60
  /**
61
61
  * The underlying formex controller that powers the form.
@@ -30,3 +30,5 @@ export * from "./auth_adapter";
30
30
  export * from "./database_adapter";
31
31
  export * from "./breadcrumbs";
32
32
  export * from "./component_overrides";
33
+ export * from "./api_keys";
34
+
@@ -311,7 +311,7 @@ export interface PluginFormActionProps<USER extends User = User, EC extends Enti
311
311
  disabled: boolean;
312
312
  formContext?: FormContext;
313
313
  context: RebaseContext<USER>;
314
- openEntityMode: "side_panel" | "full_screen" | "split" | "dialog";
314
+ openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
315
315
  }
316
316
 
317
317
  /**
@@ -221,6 +221,14 @@ export interface BaseProperty<CustomProps = unknown> {
221
221
  */
222
222
  callbacks?: PropertyCallbacks;
223
223
 
224
+ /**
225
+ * Arbitrary key-value metadata for external consumers.
226
+ * Not interpreted by Rebase — passed through serialization unchanged.
227
+ * Used by domain apps to store custom per-property config
228
+ * (e.g. CRM visibility flags, display hints).
229
+ */
230
+ metadata?: Record<string, unknown>;
231
+
224
232
  }
225
233
 
226
234
  /**
@@ -1244,7 +1252,7 @@ export interface PropertyConditions {
1244
1252
  defaultValue?: JsonLogicRule;
1245
1253
 
1246
1254
  // ═══════════════════════════════════════════════════════════════════════
1247
- // ENUM CONDITIONS (for string/number properties with enumValues)
1255
+ // ENUM CONDITIONS (for string/number properties with enum values)
1248
1256
  // ═══════════════════════════════════════════════════════════════════════
1249
1257
 
1250
1258
  /**
@@ -47,6 +47,12 @@ export interface RebaseTranslations {
47
47
  unsaved_changes_body: string;
48
48
  discard_changes: string;
49
49
  keep_editing: string;
50
+ /** Dialog title when clearing a new/copy form */
51
+ clear_form?: string;
52
+ /** Confirmation body when discarding changes on an existing entity */
53
+ discard_changes_confirmation?: string;
54
+ /** Confirmation body when clearing a new/copy form */
55
+ clear_form_confirmation?: string;
50
56
 
51
57
  // ─── Collection table / toolbar ──────────────────────────────
52
58
  search: string;
@@ -175,6 +181,8 @@ export interface RebaseTranslations {
175
181
  form_modified: string;
176
182
  /** Tooltip when the form is in sync with the database */
177
183
  form_in_sync: string;
184
+ /** Tooltip/alert shown when form has validation errors */
185
+ fix_errors_before_saving?: string;
178
186
 
179
187
  admin: string;
180
188
  home: string;