@rebasepro/sdk-generator 0.0.1-canary.09e5ec5

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