@rebasepro/types 0.1.2 → 0.2.1

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.
Files changed (87) hide show
  1. package/LICENSE +1 -1
  2. package/dist/controllers/auth.d.ts +9 -8
  3. package/dist/controllers/client.d.ts +3 -0
  4. package/dist/index.es.js.map +1 -1
  5. package/dist/index.umd.js.map +1 -1
  6. package/dist/types/auth_adapter.d.ts +356 -0
  7. package/dist/types/collections.d.ts +67 -2
  8. package/dist/types/database_adapter.d.ts +94 -0
  9. package/dist/types/entity_actions.d.ts +7 -1
  10. package/dist/types/entity_callbacks.d.ts +1 -1
  11. package/dist/types/entity_views.d.ts +36 -1
  12. package/dist/types/index.d.ts +2 -0
  13. package/dist/types/plugins.d.ts +1 -1
  14. package/dist/types/properties.d.ts +24 -5
  15. package/dist/types/property_config.d.ts +6 -2
  16. package/dist/types/relations.d.ts +1 -1
  17. package/dist/types/translations.d.ts +8 -0
  18. package/dist/users/user.d.ts +5 -0
  19. package/package.json +13 -10
  20. package/src/controllers/analytics_controller.d.ts +7 -0
  21. package/src/controllers/auth.d.ts +125 -0
  22. package/src/controllers/auth.tsx +2 -5
  23. package/src/controllers/client.d.ts +183 -0
  24. package/src/controllers/client.ts +3 -2
  25. package/src/controllers/collection_registry.d.ts +46 -0
  26. package/src/controllers/customization_controller.d.ts +60 -0
  27. package/src/controllers/data.d.ts +168 -0
  28. package/src/controllers/data_driver.d.ts +195 -0
  29. package/src/controllers/database_admin.d.ts +11 -0
  30. package/src/controllers/dialogs_controller.d.ts +36 -0
  31. package/src/controllers/effective_role.d.ts +4 -0
  32. package/src/controllers/email.d.ts +34 -0
  33. package/src/controllers/index.d.ts +18 -0
  34. package/src/controllers/local_config_persistence.d.ts +20 -0
  35. package/src/controllers/navigation.d.ts +225 -0
  36. package/src/controllers/registry.d.ts +62 -0
  37. package/src/controllers/side_dialogs_controller.d.ts +67 -0
  38. package/src/controllers/side_entity_controller.d.ts +97 -0
  39. package/src/controllers/snackbar.d.ts +24 -0
  40. package/src/controllers/storage.d.ts +171 -0
  41. package/src/index.d.ts +4 -0
  42. package/src/rebase_context.d.ts +122 -0
  43. package/src/types/auth_adapter.d.ts +354 -0
  44. package/src/types/auth_adapter.ts +410 -0
  45. package/src/types/backend.d.ts +536 -0
  46. package/src/types/backend_hooks.d.ts +187 -0
  47. package/src/types/builders.d.ts +15 -0
  48. package/src/types/chips.d.ts +5 -0
  49. package/src/types/collections.d.ts +920 -0
  50. package/src/types/collections.ts +77 -2
  51. package/src/types/component_ref.d.ts +47 -0
  52. package/src/types/cron.d.ts +102 -0
  53. package/src/types/data_source.d.ts +64 -0
  54. package/src/types/database_adapter.d.ts +90 -0
  55. package/src/types/database_adapter.ts +120 -0
  56. package/src/types/entities.d.ts +145 -0
  57. package/src/types/entity_actions.d.ts +98 -0
  58. package/src/types/entity_actions.tsx +8 -1
  59. package/src/types/entity_callbacks.d.ts +173 -0
  60. package/src/types/entity_callbacks.ts +1 -1
  61. package/src/types/entity_link_builder.d.ts +7 -0
  62. package/src/types/entity_overrides.d.ts +10 -0
  63. package/src/types/entity_views.d.ts +60 -0
  64. package/src/types/entity_views.tsx +39 -1
  65. package/src/types/export_import.d.ts +21 -0
  66. package/src/types/formex.d.ts +40 -0
  67. package/src/types/index.d.ts +28 -0
  68. package/src/types/index.ts +2 -0
  69. package/src/types/locales.d.ts +4 -0
  70. package/src/types/modify_collections.d.ts +5 -0
  71. package/src/types/plugins.d.ts +282 -0
  72. package/src/types/plugins.tsx +1 -1
  73. package/src/types/properties.d.ts +1160 -0
  74. package/src/types/properties.ts +34 -4
  75. package/src/types/property_config.d.ts +70 -0
  76. package/src/types/property_config.tsx +6 -3
  77. package/src/types/relations.d.ts +336 -0
  78. package/src/types/relations.ts +1 -1
  79. package/src/types/slots.d.ts +262 -0
  80. package/src/types/translations.d.ts +882 -0
  81. package/src/types/translations.ts +11 -0
  82. package/src/types/user_management_delegate.d.ts +121 -0
  83. package/src/types/websockets.d.ts +78 -0
  84. package/src/users/index.d.ts +2 -0
  85. package/src/users/roles.d.ts +22 -0
  86. package/src/users/user.d.ts +46 -0
  87. package/src/users/user.ts +6 -0
@@ -0,0 +1,920 @@
1
+ import React from "react";
2
+ import type { Entity, EntityStatus } from "./entities";
3
+ import type { EntityCallbacks } from "./entity_callbacks";
4
+ import type { Properties } from "./properties";
5
+ import type { ExportConfig } from "./export_import";
6
+ import type { EntityOverrides } from "./entity_overrides";
7
+ import type { User } from "../users";
8
+ import type { RebaseContext } from "../rebase_context";
9
+ import type { Relation } from "./relations";
10
+ import type { EntityCustomView } from "./entity_views";
11
+ import type { EntityAction } from "./entity_actions";
12
+ import type { ComponentRef } from "./component_ref";
13
+ /**
14
+ * Base interface containing all driver-agnostic collection properties.
15
+ * Use {@link PostgresCollection} or {@link FirebaseCollection} for
16
+ * driver-specific type safety, or {@link EntityCollection} when you
17
+ * need to handle any collection regardless of backend.
18
+ *
19
+ * @group Models
20
+ */
21
+ export interface BaseEntityCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> {
22
+ /**
23
+ * You can set an alias that will be used internally instead of the collection name.
24
+ * The `slug` value will be used to determine the URL of the collection.
25
+ * Note that you can use this value in reference properties too.
26
+ */
27
+ slug: string;
28
+ /**
29
+ * Name of the collection, typically plural.
30
+ * E.g. `Products`, `Blog`
31
+ */
32
+ name: string;
33
+ /**
34
+ * Singular name of an entry in this collection
35
+ * E.g. `Product`, `Blog entry`
36
+ */
37
+ singularName?: string;
38
+ /**
39
+ * Optional description of this view. You can use Markdown.
40
+ */
41
+ description?: string;
42
+ /**
43
+ * Child collections nested under entities of this collection.
44
+ * Populated automatically during normalization from driver-specific fields
45
+ * (e.g. Firebase `subcollections`, Postgres `relations` with many-cardinality).
46
+ *
47
+ * Custom drivers can set this directly to expose child collections to the UI.
48
+ */
49
+ childCollections?: () => EntityCollection<Record<string, unknown>>[];
50
+ /**
51
+ * Which driver handles this collection.
52
+ * Use this to route collections to different backends:
53
+ * - `"postgres"` - Route to PostgreSQL backend
54
+ * - `"firestore"` - Route to Firestore (client-side)
55
+ * - `"mongodb"` - Route to MongoDB backend
56
+ * - Custom IDs for your own driver implementations
57
+ *
58
+ * If not specified, the default driver `"(default)"` is used.
59
+ *
60
+ * @example
61
+ * // Simple - no driver needed for default
62
+ * { slug: "products" }
63
+ *
64
+ * // Firestore collection (client-side real-time)
65
+ * { slug: "analytics", driver: "firestore" }
66
+ *
67
+ * // Multiple databases within a driver
68
+ * { slug: "orders", driver: "postgres", databaseId: "orders_db" }
69
+ */
70
+ driver?: string;
71
+ /**
72
+ * Which database within the driver.
73
+ * - For Firestore: The Firestore database ID (e.g., for multi-database projects)
74
+ * - For PostgreSQL: Schema or database name
75
+ * - For MongoDB: Database name
76
+ *
77
+ * If not specified, the default database of the driver is used.
78
+ */
79
+ databaseId?: string;
80
+ /**
81
+ * Set of properties that compose an entity
82
+ */
83
+ properties: Properties;
84
+ /**
85
+ * Icon for the navigation sidebar or cards.
86
+ */
87
+ icon?: string | React.ReactNode;
88
+ /**
89
+ * Navigation group for this collection.
90
+ * Collections sharing the same group name will be visually grouped
91
+ * together in the drawer and home page. If not set, the collection
92
+ * falls into the default "Views" group.
93
+ */
94
+ group?: string;
95
+ /**
96
+ * Array of entity views that this collection has.
97
+ * Can be an array of `EntityCustomView` or a string representing the key of a global `EntityCustomView`.
98
+ */
99
+ entityViews?: (string | EntityCustomView<Record<string, unknown>>)[];
100
+ /**
101
+ * Default preview properties displayed when this collection is referenced to.
102
+ */
103
+ previewProperties?: string[];
104
+ /**
105
+ * Properties to display as columns in the list view.
106
+ * If not specified, the list view uses a smart default (Title, Status, Date).
107
+ */
108
+ listProperties?: string[];
109
+ /**
110
+ * Title property of the entity. This is the property that will be used
111
+ * as the title in entity related views and references.
112
+ * If not specified, the first property simple text property will be used.
113
+ */
114
+ readonly titleProperty?: Extract<keyof M, string> | (string & {});
115
+ /**
116
+ * When editing an entity, you can choose to open the entity in a side dialog
117
+ * or in a full screen dialog. Defaults to `full_screen`.
118
+ */
119
+ openEntityMode?: "side_panel" | "full_screen" | "split";
120
+ /**
121
+ * Order in which the properties are displayed.
122
+ * If you are specifying your collection as code, the order is the same as the
123
+ * one you define in `properties`. Additional columns are added at the
124
+ * end of the list, if the order is not specified.
125
+ * You can use this prop to hide some properties from the table view.
126
+ * Note that if you set this prop, other ways to hide fields, like
127
+ * `hidden` in the property definition, will be ignored.
128
+ * `propertiesOrder` has precedence over `hidden`.
129
+ * - For properties use the property key.
130
+ * - For additional fields use the field key.
131
+ * - If you have subcollections, you get a column for each subcollection,
132
+ * with the path (or alias) as the subcollection, prefixed with
133
+ * `subcollection:`. e.g. `subcollection:orders`.
134
+ * You can use this prop to hide some properties from the table view.
135
+ * Note that if you set this prop, other ways to hide fields, like
136
+ * `hidden` in the property definition,will be ignored.
137
+ * `propertiesOrder` has precedence over `hidden`.
138
+ */
139
+ propertiesOrder?: (Extract<keyof M, string> | (string & {}) | string | `subcollection:${string}`)[];
140
+ /**
141
+ * If enabled, content is loaded in batches. If `false` all entities in the
142
+ * collection are loaded. This means that when reaching the end of the
143
+ * collection, the CMS will load more entities.
144
+ * You can specify a number to specify the pagination size (50 by default)
145
+ * Defaults to `true`
146
+ */
147
+ pagination?: boolean | number;
148
+ selectionEnabled?: boolean;
149
+ /**
150
+ * This interface defines all the callbacks that can be used when an entity
151
+ * is being created, updated or deleted.
152
+ * Useful for adding your own logic or blocking the execution of the operation.
153
+ */
154
+ readonly callbacks?: EntityCallbacks<M, USER>;
155
+ /**
156
+ * Pass your own selection controller if you want to control selected
157
+ * entities externally.
158
+ * @see useSelectionController
159
+ */
160
+ selectionController?: SelectionController<M>;
161
+ /**
162
+ * Force a filter in this view. If applied, the rest of the filters will
163
+ * be disabled. Filters applied with this prop cannot be changed.
164
+ * e.g. `fixedFilter: { age: [">", 18] }`
165
+ * e.g. `fixedFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
166
+ */
167
+ readonly fixedFilter?: FilterValues<Extract<keyof M, string> | (string & {})>;
168
+ /**
169
+ * Initial filters applied to the collection this collection is related to.
170
+ * Defaults to none. Filters applied with this prop can be changed.
171
+ * e.g. `defaultFilter: { age: [">", 18] }`
172
+ * e.g. `defaultFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
173
+ */
174
+ readonly defaultFilter?: FilterValues<Extract<keyof M, string> | (string & {})>;
175
+ /**
176
+ * Pre-defined filter presets that appear as quick-access options in the
177
+ * collection toolbar. Each preset applies a set of filters (and
178
+ * optionally a sort order) with a single click.
179
+ *
180
+ * ```ts
181
+ * filterPresets: [
182
+ * {
183
+ * label: "Shipped this month",
184
+ * filterValues: {
185
+ * status: ["==", "shipped"],
186
+ * order_date: [">=", new Date(Date.now() - 30 * 86400000)]
187
+ * }
188
+ * }
189
+ * ]
190
+ * ```
191
+ */
192
+ readonly filterPresets?: FilterPreset<Extract<keyof M, string> | (string & {})>[];
193
+ /**
194
+ * Default sort applied to this collection.
195
+ * When setting this prop, entities will have a default order
196
+ * applied in the collection.
197
+ * e.g. `sort: ["order", "asc"]`
198
+ */
199
+ readonly sort?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"];
200
+ /**
201
+ * You can add additional fields to the collection view by implementing
202
+ * an additional field delegate.
203
+ */
204
+ readonly additionalFields?: AdditionalFieldDelegate<M, USER>[];
205
+ /**
206
+ * Default size of the rendered collection
207
+ */
208
+ defaultSize?: CollectionSize;
209
+ /**
210
+ * Can the elements in this collection be edited inline in the collection
211
+ * view. If this flag is set to false but `permissions.edit` is `true`, entities
212
+ * can still be edited in the side panel
213
+ */
214
+ inlineEditing?: boolean;
215
+ /**
216
+ * Should this collection be hidden from the main navigation panel, if
217
+ * it is at the root level, or in the entity side panel if it's a
218
+ * subcollection.
219
+ * It will still be accessible if you reach the specified path.
220
+ * You can also use this collection as a reference target.
221
+ */
222
+ hideFromNavigation?: boolean;
223
+ /**
224
+ * If you want to open custom views or subcollections by default when opening the edit
225
+ * view of an entity, you can specify the path to the view here.
226
+ * The path is relative to the current collection. For example if you have a collection
227
+ * that has a custom view as well as a subcollection that refers to another entity, you can
228
+ * either specify the path to the custom view or the path to the subcollection.
229
+ */
230
+ defaultSelectedView?: string | DefaultSelectedViewBuilder;
231
+ /**
232
+ * Should the ID of this collection be hidden from the form view.
233
+ */
234
+ hideIdFromForm?: boolean;
235
+ /**
236
+ * Should the ID of this collection be hidden from the grid view.
237
+ */
238
+ hideIdFromCollection?: boolean;
239
+ /**
240
+ * If set to true, the form will be auto-saved when the user changes
241
+ * the value of a field.
242
+ * Defaults to false.
243
+ * When a new entity is created, this property can be updated to generated a new ID
244
+ */
245
+ formAutoSave?: boolean;
246
+ /**
247
+ *
248
+ */
249
+ exportable?: boolean | ExportConfig<USER>;
250
+ /**
251
+ * User id of the owner of this collection. This is used only by plugins, or if you
252
+ * are writing custom code
253
+ */
254
+ ownerId?: string;
255
+ /**
256
+ * Overrides for the entity view, like the data source or the storage source.
257
+ */
258
+ overrides?: EntityOverrides;
259
+ /**
260
+ * Width of the side dialog (in pixels) when opening an entity in this collection.
261
+ */
262
+ sideDialogWidth?: number | string;
263
+ /**
264
+ * If set to true, the default values of the properties will be applied
265
+ * to the entity every time the entity is updated (not only when created).
266
+ * Defaults to false.
267
+ */
268
+ alwaysApplyDefaultValues?: boolean;
269
+ /**
270
+ * If set to true, a tab including the JSON representation of the entity will be included.
271
+ */
272
+ includeJsonView?: boolean;
273
+ /**
274
+ * If set to true, changes to the entity will be saved in a subcollection.
275
+ * This prop has no effect if the history plugin is not enabled
276
+ */
277
+ history?: boolean;
278
+ /**
279
+ * Should local changes be backed up in local storage, to prevent data loss on
280
+ * accidental navigations.
281
+ * - `manual_apply`: When the user navigates back to an entity with local changes,
282
+ * they will be prompted to restore the changes.
283
+ * - `auto_apply`: When the user navigates back to an entity with local changes,
284
+ * the changes will be automatically applied.
285
+ * - `false`: Local changes will not be backed up.
286
+ * Defaults to `manual_apply`.
287
+ */
288
+ localChangesBackup?: "manual_apply" | "auto_apply" | false;
289
+ /**
290
+ * Default view mode for displaying this collection.
291
+ * - "table": Display entities in a table with inline editing (default)
292
+ * - "cards": Display entities as a grid of cards with thumbnails
293
+ * - "kanban": Display entities in a Kanban board grouped by a property
294
+ * Defaults to "table".
295
+ */
296
+ defaultViewMode?: ViewMode;
297
+ /**
298
+ * Which view modes are available for this collection.
299
+ * Possible values: "table", "cards", "kanban".
300
+ * Defaults to all three: ["table", "cards", "kanban"].
301
+ * Note: "kanban" will only be available if the collection has at least
302
+ * one string property with enumValues defined, regardless of this setting.
303
+ */
304
+ enabledViews?: ViewMode[];
305
+ /**
306
+ * Configuration for Kanban board view mode.
307
+ * When set, the Kanban view mode becomes available.
308
+ */
309
+ kanban?: KanbanConfig<M>;
310
+ /**
311
+ * Property key to use for ordering items.
312
+ * Must reference a string/text property. When items are reordered,
313
+ * this property will be updated with lexicographic sort keys
314
+ * (e.g. "a0", "a1", "a0V") using string-based fractional indexing.
315
+ * Used by Kanban view for ordering within columns
316
+ * and can be used for general ordering purposes.
317
+ */
318
+ readonly orderProperty?: Extract<keyof M, string> | (string & {});
319
+ /**
320
+ * Actions that can be performed on the entities in this collection.
321
+ */
322
+ entityActions?: EntityAction<M, USER>[];
323
+ /**
324
+ * Builder for the collection actions rendered in the toolbar
325
+ */
326
+ Actions?: ComponentRef<CollectionActionsProps>[];
327
+ }
328
+ /**
329
+ * A collection backed by PostgreSQL (or any SQL database).
330
+ * Adds support for SQL-style relations (JOINs) and Row Level Security.
331
+ *
332
+ * Use this type instead of {@link EntityCollection} when you want
333
+ * compile-time safety that only SQL-relevant fields appear.
334
+ *
335
+ * @group Models
336
+ */
337
+ export interface PostgresCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> extends BaseEntityCollection<M, USER> {
338
+ properties: Properties;
339
+ /**
340
+ * The driver for this collection. For Postgres collections this
341
+ * can be omitted (Postgres is the default) or set to `"postgres"`.
342
+ */
343
+ driver?: "postgres" | undefined;
344
+ /**
345
+ * The PostgreSQL table name for this collection.
346
+ */
347
+ table: string;
348
+ /**
349
+ * For SQL databases, you can define the relations between collections here.
350
+ * Relations describe JOINs, foreign keys, and junction tables.
351
+ */
352
+ relations?: Relation[];
353
+ /**
354
+ * Security rules for this collection (Supabase-style Row Level Security).
355
+ * When defined, the schema generator will enable RLS on the table and
356
+ * create the corresponding PostgreSQL policies.
357
+ *
358
+ * Supports three levels of expressiveness:
359
+ * 1. **Convenience shortcuts** — `ownerField`, `access`, `roles`
360
+ * 2. **Raw SQL** — `using` and `withCheck` for full PostgreSQL power
361
+ * 3. **Combined** — mix shortcuts with `roles` for common patterns
362
+ *
363
+ * The authenticated user context is available in raw SQL via:
364
+ * - `auth.uid()` — the current user's ID
365
+ * - `auth.roles()` — comma-separated app role IDs
366
+ * - `auth.jwt()` — full JWT claims as JSONB
367
+ */
368
+ securityRules?: SecurityRule[];
369
+ }
370
+ /**
371
+ * A collection backed by Firebase / Firestore.
372
+ * Adds support for subcollections (nested document collections).
373
+ *
374
+ * Use this type instead of {@link EntityCollection} when you want
375
+ * compile-time safety that only Firestore-relevant fields appear.
376
+ *
377
+ * @group Models
378
+ */
379
+ export interface FirebaseCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> extends BaseEntityCollection<M, USER> {
380
+ /**
381
+ * The driver for this collection. Must be set to `"firestore"`.
382
+ */
383
+ driver: "firestore";
384
+ /**
385
+ * You can add subcollections to your entity in the same way you define the root
386
+ * collections. The collections added here will be displayed when opening
387
+ * the side dialog of an entity.
388
+ */
389
+ subcollections?: () => EntityCollection<Record<string, unknown>>[];
390
+ }
391
+ /**
392
+ * A collection backed by MongoDB.
393
+ *
394
+ * Use this type instead of {@link EntityCollection} when you want
395
+ * compile-time safety that only MongoDB-relevant fields appear.
396
+ *
397
+ * @group Models
398
+ */
399
+ export interface MongoDBCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> extends BaseEntityCollection<M, USER> {
400
+ /**
401
+ * The driver for this collection. Must be set to `"mongodb"`.
402
+ */
403
+ driver: "mongodb";
404
+ }
405
+ /**
406
+ * A collection backed by any data source.
407
+ * This is a discriminated union — use {@link PostgresCollection},
408
+ * {@link FirebaseCollection}, or {@link MongoDBCollection} for
409
+ * driver-specific type safety.
410
+ *
411
+ * @group Models
412
+ */
413
+ export type EntityCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = PostgresCollection<M, USER> | FirebaseCollection<M, USER> | MongoDBCollection<M, USER>;
414
+ /** An EntityCollection that supports SQL-style relations (e.g. Postgres). */
415
+ export type CollectionWithRelations<M extends Record<string, unknown> = Record<string, unknown>> = EntityCollection<M> & {
416
+ table?: string;
417
+ relations?: Relation[];
418
+ securityRules?: SecurityRule[];
419
+ };
420
+ /** An EntityCollection that supports subcollections (e.g. Firestore). */
421
+ export type CollectionWithSubcollections<M extends Record<string, unknown> = Record<string, unknown>> = EntityCollection<M> & {
422
+ subcollections?: () => EntityCollection<Record<string, unknown>>[];
423
+ };
424
+ /**
425
+ * Type guard for PostgreSQL collections.
426
+ * Returns true if the collection uses the Postgres driver (or the default driver).
427
+ * @group Models
428
+ */
429
+ export declare function isPostgresCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>(collection: EntityCollection<M, USER>): collection is PostgresCollection<M, USER>;
430
+ /**
431
+ * Type guard for Firebase / Firestore collections.
432
+ * @group Models
433
+ */
434
+ export declare function isFirebaseCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>(collection: EntityCollection<M, USER>): collection is FirebaseCollection<M, USER>;
435
+ /**
436
+ * Type guard for MongoDB collections.
437
+ * @group Models
438
+ */
439
+ export declare function isMongoDBCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>(collection: EntityCollection<M, USER>): collection is MongoDBCollection<M, USER>;
440
+ /**
441
+ * Configuration for Kanban board view mode.
442
+ * @group Collections
443
+ */
444
+ export interface KanbanConfig<M extends Record<string, unknown> = Record<string, unknown>> {
445
+ /**
446
+ * Property key to use for Kanban board columns.
447
+ * Must reference a string property with enumValues defined.
448
+ * Entities will be grouped into columns based on this property's value.
449
+ * The column order is determined by the order of enumValues in the property.
450
+ */
451
+ columnProperty: Extract<keyof M, string> | (string & {});
452
+ }
453
+ /**
454
+ * View mode for displaying a collection.
455
+ * - "list": Simple, clean list view — the classic CMS default
456
+ * - "table": Table with inline editing
457
+ * - "cards": Grid of visual cards with thumbnails
458
+ * - "kanban": Board view grouped by a property
459
+ * @group Collections
460
+ */
461
+ export type ViewMode = "list" | "table" | "cards" | "kanban";
462
+ /**
463
+ * Parameter passed to the `Actions` prop in the collection configuration.
464
+ * The component will receive this prop when it is rendered in the collection
465
+ * toolbar.
466
+ *
467
+ * @group Models
468
+ */
469
+ export interface CollectionActionsProps<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User, EC extends EntityCollection<M> = EntityCollection<M>> {
470
+ /**
471
+ * Full collection path of this entity. This is the full path, like
472
+ * `users/1234/addresses`
473
+ */
474
+ path: string;
475
+ /**
476
+ * Path of the last collection, like `addresses`
477
+ */
478
+ relativePath: string;
479
+ /**
480
+ * Array of the parent path segments like `['users']`
481
+ */
482
+ parentCollectionSlugs: string[];
483
+ parentEntityIds: string[];
484
+ /**
485
+ * The collection configuration
486
+ */
487
+ collection: EC;
488
+ /**
489
+ * Use this controller to get the selected entities and to update the
490
+ * selected entities state.
491
+ */
492
+ selectionController: SelectionController<M>;
493
+ /**
494
+ * Use this controller to get the table controller and to update the
495
+ * table controller state.
496
+ */
497
+ tableController: EntityTableController<M>;
498
+ /**
499
+ * Context of the app status
500
+ */
501
+ context: RebaseContext<USER>;
502
+ /**
503
+ * Count of the entities in this collection.
504
+ * undefined means the count is still loading.
505
+ */
506
+ collectionEntitiesCount?: number;
507
+ /**
508
+ * Programmatically open the new-document form for this collection,
509
+ * optionally pre-populating it with initial field values.
510
+ * The form opens in the same mode configured for the collection
511
+ * (side panel, full screen, or split).
512
+ *
513
+ * This is the primary hook for workflows that need to create a document
514
+ * from external data — e.g. fetching content from a URL, importing from
515
+ * a third-party API, or duplicating from another system.
516
+ *
517
+ * @example
518
+ * // Inside a custom CollectionAction component:
519
+ * openNewDocument({ title: "Fetched title", body: "..." });
520
+ */
521
+ openNewDocument: (defaultValues?: Record<string, unknown>) => void;
522
+ }
523
+ /**
524
+ * Use this controller to retrieve the selected entities or modify them in
525
+ * an {@link EntityCollection}
526
+ * @group Models
527
+ */
528
+ export interface SelectionController<M extends Record<string, unknown> = Record<string, unknown>> {
529
+ selectedEntities: Entity<M>[];
530
+ setSelectedEntities(entities: Entity<M>[]): void;
531
+ setSelectedEntities(action: (prev: Entity<M>[]) => Entity<M>[]): void;
532
+ isEntitySelected(entity: Entity<M>): boolean;
533
+ toggleEntitySelection(entity: Entity<M>, newSelectedState?: boolean): void;
534
+ }
535
+ /**
536
+ * Filter conditions in a `Query.where()` clause are specified using the
537
+ * strings `<`, `<=`, `==`, `>=`, `>`, `array-contains`, `in`, and `array-contains-any`.
538
+ * @group Models
539
+ */
540
+ export type WhereFilterOp = "<" | "<=" | "==" | "!=" | ">=" | ">" | "array-contains" | "in" | "not-in" | "array-contains-any";
541
+ /**
542
+ * Used to define filters applied in collections
543
+ *
544
+ * e.g. `{ age: [">=", 18] }`
545
+ *
546
+ * @group Models
547
+ */
548
+ export type FilterValues<Key extends string> = Partial<Record<Key, [WhereFilterOp, unknown]>>;
549
+ /**
550
+ * A pre-defined filter preset for quick access in the collection toolbar.
551
+ * Users can select a preset to instantly apply a set of filters and
552
+ * optionally a sort order.
553
+ *
554
+ * @group Models
555
+ */
556
+ export interface FilterPreset<Key extends string = string> {
557
+ /**
558
+ * Display label shown in the preset menu.
559
+ * If omitted, a summary is auto-generated from the filter keys.
560
+ */
561
+ label?: string;
562
+ /**
563
+ * The filter values to apply when this preset is selected.
564
+ */
565
+ filterValues: FilterValues<Key>;
566
+ /**
567
+ * Optional sort override to apply alongside the filter values.
568
+ */
569
+ sort?: [Key, "asc" | "desc"];
570
+ }
571
+ /**
572
+ * @deprecated Use {@link FilterPreset} instead.
573
+ */
574
+ export type QuickFilter<Key extends string = string> = FilterPreset<Key>;
575
+ /**
576
+ * Used to indicate valid filter combinations (e.g. created in Firestore)
577
+ * If the user selects a specific filter/sort combination, the CMS checks if it's
578
+ * valid, otherwise it reverts to the simpler valid case
579
+ * @group Models
580
+ */
581
+ export type FilterCombination<Key extends string> = Partial<Record<Key, "asc" | "desc">>;
582
+ /**
583
+ * Sizes in which a collection can be rendered
584
+ * @group Models
585
+ */
586
+ export type CollectionSize = "xs" | "s" | "m" | "l" | "xl";
587
+ export type AdditionalFieldDelegateProps<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = {
588
+ entity: Entity<M>;
589
+ context: RebaseContext<USER>;
590
+ };
591
+ /**
592
+ * Use this interface for adding additional fields to entity collection views and forms.
593
+ * @group Models
594
+ */
595
+ export interface AdditionalFieldDelegate<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> {
596
+ /**
597
+ * ID of this column. You can use this id in the `properties` field of the
598
+ * collection in any order you want
599
+ */
600
+ key: string;
601
+ /**
602
+ * Header of this column
603
+ */
604
+ name: string;
605
+ /**
606
+ * Width of the generated column in pixels
607
+ */
608
+ width?: number;
609
+ /**
610
+ * Builder for the custom field
611
+ */
612
+ Builder?(props: {
613
+ entity: Entity<M>;
614
+ context: RebaseContext<USER>;
615
+ }): React.ReactNode;
616
+ /**
617
+ * If this column needs to update dynamically based on other properties,
618
+ * you can define an array of keys as strings with the
619
+ * `dependencies` prop.
620
+ * e.g. ["name", "surname"]
621
+ * This is a performance optimization, if you don't define dependencies
622
+ * it will be updated in every render.
623
+ */
624
+ dependencies?: NoInfer<Extract<keyof M, string>> | NoInfer<Extract<keyof M, string>>[] | (string & {}) | (string & {})[];
625
+ /**
626
+ * Use this prop to define the value of the column as a string or number.
627
+ * This is the value that will be used for exporting the collection.
628
+ * If `Builder` is defined, this prop will be ignored in the collection
629
+ * view.
630
+ * @param entity
631
+ */
632
+ value?(props: {
633
+ entity: Entity<M>;
634
+ context: RebaseContext;
635
+ }): string | number | Promise<string | number> | undefined;
636
+ }
637
+ export type InferCollectionType<S extends EntityCollection> = S extends EntityCollection<infer M> ? M : never;
638
+ /**
639
+ * Used in the {@link EntityCollection#defaultSelectedView} to define the default
640
+ * @group Models
641
+ */
642
+ export type DefaultSelectedViewBuilder = (params: DefaultSelectedViewParams) => string | undefined;
643
+ /**
644
+ * Used in the {@link EntityCollection#defaultSelectedView} to define the default
645
+ * @group Models
646
+ */
647
+ export type DefaultSelectedViewParams = {
648
+ status?: EntityStatus;
649
+ entityId?: string | number;
650
+ };
651
+ /**
652
+ * You can use this controller to control the table view of a collection.
653
+ */
654
+ export type EntityTableController<M extends Record<string, unknown> = Record<string, unknown>> = {
655
+ data: Entity<M>[];
656
+ dataLoading: boolean;
657
+ noMoreToLoad: boolean;
658
+ dataLoadingError?: Error;
659
+ filterValues?: FilterValues<Extract<keyof M, string> | (string & {})>;
660
+ setFilterValues?: (filterValues: FilterValues<Extract<keyof M, string> | (string & {})>) => void;
661
+ sortBy?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"];
662
+ setSortBy?: (sortBy?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"]) => void;
663
+ searchString?: string;
664
+ setSearchString?: (searchString?: string) => void;
665
+ clearFilter?: () => void;
666
+ itemCount?: number;
667
+ setItemCount?: (itemCount: number) => void;
668
+ initialScroll?: number;
669
+ onScroll?: (props: {
670
+ scrollDirection: "forward" | "backward";
671
+ scrollOffset: number;
672
+ scrollUpdateWasRequested: boolean;
673
+ }) => void;
674
+ paginationEnabled?: boolean;
675
+ pageSize?: number;
676
+ checkFilterCombination?: (filterValues: FilterValues<string>, sortBy?: [string, "asc" | "desc"]) => boolean;
677
+ popupCell?: SelectedCellProps<M>;
678
+ setPopupCell?: (popupCell?: SelectedCellProps<M>) => void;
679
+ onAddColumn?: (column: string) => void;
680
+ };
681
+ export type SelectedCellProps<M extends Record<string, unknown> = Record<string, unknown>> = {
682
+ propertyKey: Extract<keyof M, string> | (string & {});
683
+ cellRect: DOMRect;
684
+ width: number;
685
+ height: number;
686
+ entityPath: string;
687
+ entityId: string | number;
688
+ };
689
+ /**
690
+ * SQL operation that a policy applies to.
691
+ * @group Models
692
+ */
693
+ export type SecurityOperation = "select" | "insert" | "update" | "delete" | "all";
694
+ /**
695
+ * Flexible Row Level Security rule for a collection.
696
+ *
697
+ * Inspired by Supabase's approach to PostgreSQL RLS. Rules can range from
698
+ * simple convenience shortcuts to fully custom SQL expressions, giving you the
699
+ * full power of PostgreSQL Row Level Security.
700
+ *
701
+ * The authenticated user's identity is available in raw SQL via:
702
+ * - `auth.uid()` — the user's ID
703
+ * - `auth.roles()` — comma-separated app role IDs
704
+ * - `auth.jwt()` — full JWT claims as JSONB
705
+ *
706
+ * These are set automatically per-transaction by the backend.
707
+ *
708
+ * **How rules combine:** PostgreSQL evaluates all matching policies for an
709
+ * operation. Permissive rules are OR'd together (any one passing is enough).
710
+ * Restrictive rules are AND'd (all must pass). This mirrors Supabase behavior.
711
+ *
712
+ * **Mutual exclusivity:** `ownerField`, `access`, and raw SQL (`using`/`withCheck`)
713
+ * cannot be combined. The type system enforces this — attempting to set
714
+ * conflicting fields will produce a compile-time error.
715
+ *
716
+ * @group Models
717
+ */
718
+ export type SecurityRule = OwnerSecurityRule | PublicSecurityRule | RawSQLSecurityRule | RolesOnlySecurityRule;
719
+ /**
720
+ * Shared fields for all SecurityRule variants.
721
+ * @group Models
722
+ */
723
+ export interface SecurityRuleBase {
724
+ /**
725
+ * Optional human-readable name for the policy.
726
+ * If not provided, one will be auto-generated from the table name and operation.
727
+ * Must be unique per table.
728
+ *
729
+ * When using `operations` (array), each generated policy will have the
730
+ * operation name appended, e.g. `"owner_access_select"`, `"owner_access_update"`.
731
+ */
732
+ name?: string;
733
+ /**
734
+ * Which SQL operation this policy applies to.
735
+ * Use this when the policy targets a single operation or all operations.
736
+ *
737
+ * For multiple specific operations, use `operations` (array) instead.
738
+ * If neither is specified, defaults to `"all"`.
739
+ *
740
+ * @default "all"
741
+ */
742
+ operation?: SecurityOperation;
743
+ /**
744
+ * Array of SQL operations this policy applies to.
745
+ * The compiler will generate one PostgreSQL policy per operation, sharing
746
+ * the same configuration.
747
+ *
748
+ * This reduces boilerplate when the same rule applies to multiple (but not all)
749
+ * operations.
750
+ *
751
+ * Takes precedence over `operation` (singular) if both are specified.
752
+ *
753
+ * @example
754
+ * // Same rule for select and update
755
+ * { operations: ["select", "update"], ownerField: "user_id" }
756
+ *
757
+ * @example
758
+ * // Equivalent to operation: "all"
759
+ * { operations: ["all"], ownerField: "user_id" }
760
+ */
761
+ operations?: SecurityOperation[];
762
+ /**
763
+ * Whether this policy is `"permissive"` (default) or `"restrictive"`.
764
+ *
765
+ * - **permissive**: Multiple permissive policies for the same operation are
766
+ * OR'd together — if *any* passes, access is granted.
767
+ * - **restrictive**: Restrictive policies are AND'd with all permissive
768
+ * policies — they act as additional gates that *must* also pass.
769
+ *
770
+ * This is the same model as PostgreSQL / Supabase.
771
+ *
772
+ * @default "permissive"
773
+ */
774
+ mode?: "permissive" | "restrictive";
775
+ /**
776
+ * **Shortcut.** Restrict this rule to users that have one of these
777
+ * application-level roles.
778
+ *
779
+ * **Important:** These are NOT native PostgreSQL database roles. They are
780
+ * application roles managed by Rebase, stored in the `rebase.user_roles`
781
+ * table, and injected into each transaction via `auth.roles()`.
782
+ *
783
+ * Generates a condition like:
784
+ * `auth.roles() ~ '<role1>|<role2>'`
785
+ *
786
+ * Can be combined with `ownerField`, `access`, or raw `using`/`withCheck`.
787
+ * When combined, the role check is AND'd with the other condition.
788
+ *
789
+ * @example
790
+ * // Only admins can delete
791
+ * { operation: "delete", roles: ["admin"] }
792
+ *
793
+ * @example
794
+ * // Admins have unfiltered read access to all rows
795
+ * { operation: "select", roles: ["admin"], using: "true" }
796
+ */
797
+ roles?: string[];
798
+ /**
799
+ * **Advanced.** Native PostgreSQL database roles the policy applies to.
800
+ *
801
+ * By default, all generated policies target the `public` role (i.e.
802
+ * every database connection). This is correct for most setups where
803
+ * a single database role is used for all connections.
804
+ *
805
+ * **Important:** These are NOT the same as the application-level `roles`
806
+ * (admin, editor, viewer, etc.) — those are enforced in the USING/WITH
807
+ * CHECK clauses via `auth.roles()`. This field controls the PostgreSQL
808
+ * `TO` clause in `CREATE POLICY ... TO role_name`.
809
+ *
810
+ * Use this if you have dedicated PostgreSQL roles (e.g. `app_read`,
811
+ * `app_write`) and want policies to target specific ones.
812
+ *
813
+ * @default ["public"]
814
+ *
815
+ * @example
816
+ * // Only apply this policy when connected as `app_role`
817
+ * { operation: "select", access: "public", pgRoles: ["app_role"] }
818
+ */
819
+ pgRoles?: string[];
820
+ }
821
+ /**
822
+ * Security rule that grants access based on row ownership.
823
+ * Generates a USING/WITH CHECK clause like: `<column> = auth.uid()`
824
+ *
825
+ * Cannot be combined with `using`, `withCheck`, or `access`.
826
+ *
827
+ * @example
828
+ * { operation: "all", ownerField: "user_id" }
829
+ *
830
+ * @group Models
831
+ */
832
+ export interface OwnerSecurityRule extends SecurityRuleBase {
833
+ /** The property (column) that stores the owner's user ID. */
834
+ ownerField: string;
835
+ access?: never;
836
+ using?: never;
837
+ withCheck?: never;
838
+ }
839
+ /**
840
+ * Security rule that grants unrestricted row access (no row filtering).
841
+ * Generates `USING (true)`.
842
+ *
843
+ * This means "no row-level filter", NOT "anonymous/unauthenticated access".
844
+ * Authentication is still enforced at the API layer — this only controls which
845
+ * *rows* authenticated users can see.
846
+ *
847
+ * Cannot be combined with `using`, `withCheck`, or `ownerField`.
848
+ *
849
+ * @example
850
+ * // Public read (any authenticated user sees all rows)
851
+ * { operation: "select", access: "public" }
852
+ *
853
+ * @group Models
854
+ */
855
+ export interface PublicSecurityRule extends SecurityRuleBase {
856
+ /** Grant unrestricted row access for this operation. */
857
+ access: "public";
858
+ ownerField?: never;
859
+ using?: never;
860
+ withCheck?: never;
861
+ }
862
+ /**
863
+ * Security rule using raw SQL expressions for full PostgreSQL RLS power.
864
+ *
865
+ * Cannot be combined with `ownerField` or `access`.
866
+ *
867
+ * You can reference columns via `{column_name}` which will be resolved to
868
+ * `table.column_name` in the generated Drizzle code.
869
+ *
870
+ * @example
871
+ * // Rows published in the last 30 days are visible
872
+ * { operation: "select", using: "{published_at} > now() - interval '30 days'" }
873
+ *
874
+ * @example
875
+ * // Only the owner, or users with 'moderator' role
876
+ * {
877
+ * operation: "select",
878
+ * using: "{user_id} = auth.uid() OR auth.roles() ~ 'moderator'"
879
+ * }
880
+ *
881
+ * @group Models
882
+ */
883
+ export interface RawSQLSecurityRule extends SecurityRuleBase {
884
+ /**
885
+ * Raw SQL expression for the `USING` clause.
886
+ * This controls which *existing* rows are visible / can be modified / deleted.
887
+ * Applied to SELECT, UPDATE, and DELETE.
888
+ */
889
+ using: string;
890
+ /**
891
+ * Raw SQL expression for the `WITH CHECK` clause.
892
+ * This controls which *new/updated* row values are allowed.
893
+ * Applied to INSERT and UPDATE.
894
+ *
895
+ * If not provided on INSERT/UPDATE policies, falls back to `using`
896
+ * (which matches PostgreSQL's own default behavior).
897
+ */
898
+ withCheck?: string;
899
+ ownerField?: never;
900
+ access?: never;
901
+ }
902
+ /**
903
+ * Security rule that only filters by application roles, without any
904
+ * row-level condition (USING/WITH CHECK).
905
+ *
906
+ * Useful for simple "only admins can access this table" rules where
907
+ * no per-row filtering is needed.
908
+ *
909
+ * @example
910
+ * // Only admins can delete
911
+ * { operation: "delete", roles: ["admin"] }
912
+ *
913
+ * @group Models
914
+ */
915
+ export interface RolesOnlySecurityRule extends SecurityRuleBase {
916
+ ownerField?: never;
917
+ access?: never;
918
+ using?: never;
919
+ withCheck?: never;
920
+ }