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