@rebasepro/types 0.10.0 → 0.10.1-canary.0a881d4
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.
- package/dist/call_context.d.ts +51 -0
- package/dist/controllers/auth_state.d.ts +23 -0
- package/dist/controllers/client.d.ts +3 -1
- package/dist/controllers/collection_registry.d.ts +5 -1
- package/dist/controllers/data_driver.d.ts +31 -2
- package/dist/controllers/index.d.ts +1 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +374 -1
- package/dist/index.es.js.map +1 -1
- package/dist/types/admin_block.d.ts +34 -0
- package/dist/types/backend.d.ts +30 -1
- package/dist/types/channel_bus.d.ts +192 -0
- package/dist/types/collection_contract.d.ts +43 -0
- package/dist/types/collections.d.ts +17 -789
- package/dist/types/component_ref.d.ts +39 -6
- package/dist/types/entity_callbacks.d.ts +1 -1
- package/dist/types/index.d.ts +7 -15
- package/dist/types/project_manifest.d.ts +336 -0
- package/dist/types/properties.d.ts +12 -157
- package/dist/types/schema_version.d.ts +18 -0
- package/dist/types/security_rules.d.ts +320 -0
- package/dist/types/storage_authorize.d.ts +74 -0
- package/package.json +3 -6
- package/src/call_context.ts +56 -0
- package/src/controllers/auth_state.ts +24 -0
- package/src/controllers/client.ts +3 -2
- package/src/controllers/collection_registry.ts +5 -1
- package/src/controllers/data_driver.ts +58 -2
- package/src/controllers/index.ts +1 -10
- package/src/index.ts +1 -1
- package/src/types/admin_block.ts +75 -0
- package/src/types/backend.ts +33 -1
- package/src/types/channel_bus.ts +202 -0
- package/src/types/collection_contract.ts +278 -0
- package/src/types/collections.ts +25 -848
- package/src/types/component_ref.ts +40 -6
- package/src/types/entity_callbacks.ts +1 -1
- package/src/types/index.ts +7 -15
- package/src/types/policy.ts +25 -11
- package/src/types/project_manifest.ts +362 -0
- package/src/types/properties.ts +11 -169
- package/src/types/schema_version.ts +112 -0
- package/src/types/security_rules.ts +344 -0
- package/src/types/storage_authorize.ts +77 -0
- package/dist/controllers/analytics_controller.d.ts +0 -7
- package/dist/controllers/auth.d.ts +0 -110
- package/dist/controllers/customization_controller.d.ts +0 -61
- package/dist/controllers/dialogs_controller.d.ts +0 -36
- package/dist/controllers/local_config_persistence.d.ts +0 -20
- package/dist/controllers/navigation.d.ts +0 -225
- package/dist/controllers/registry.d.ts +0 -80
- package/dist/controllers/side_dialogs_controller.d.ts +0 -67
- package/dist/controllers/side_panel_controller.d.ts +0 -97
- package/dist/controllers/snackbar.d.ts +0 -24
- package/dist/rebase_context.d.ts +0 -110
- package/dist/types/breadcrumbs.d.ts +0 -26
- package/dist/types/builders.d.ts +0 -15
- package/dist/types/component_overrides.d.ts +0 -196
- package/dist/types/entity_actions.d.ts +0 -104
- package/dist/types/entity_link_builder.d.ts +0 -7
- package/dist/types/entity_views.d.ts +0 -95
- package/dist/types/export_import.d.ts +0 -21
- package/dist/types/formex.d.ts +0 -40
- package/dist/types/locales.d.ts +0 -4
- package/dist/types/modify_collections.d.ts +0 -5
- package/dist/types/plugins.d.ts +0 -277
- package/dist/types/property_config.d.ts +0 -74
- package/dist/types/slots.d.ts +0 -262
- package/dist/types/translations.d.ts +0 -915
- package/dist/types/user_management_delegate.d.ts +0 -22
- package/src/controllers/analytics_controller.tsx +0 -57
- package/src/controllers/auth.tsx +0 -121
- package/src/controllers/customization_controller.tsx +0 -72
- package/src/controllers/dialogs_controller.tsx +0 -37
- package/src/controllers/local_config_persistence.tsx +0 -22
- package/src/controllers/navigation.ts +0 -267
- package/src/controllers/registry.ts +0 -95
- package/src/controllers/side_dialogs_controller.tsx +0 -82
- package/src/controllers/side_panel_controller.tsx +0 -112
- package/src/controllers/snackbar.ts +0 -29
- package/src/rebase_context.tsx +0 -130
- package/src/types/breadcrumbs.ts +0 -27
- package/src/types/builders.ts +0 -17
- package/src/types/component_overrides.ts +0 -244
- package/src/types/entity_actions.tsx +0 -125
- package/src/types/entity_link_builder.ts +0 -8
- package/src/types/entity_views.tsx +0 -114
- package/src/types/export_import.ts +0 -26
- package/src/types/formex.ts +0 -45
- package/src/types/locales.ts +0 -81
- package/src/types/modify_collections.tsx +0 -6
- package/src/types/plugins.tsx +0 -346
- package/src/types/property_config.tsx +0 -95
- package/src/types/slots.tsx +0 -307
- package/src/types/translations.ts +0 -1026
- package/src/types/user_management_delegate.ts +0 -23
package/src/types/collections.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import React, { Dispatch, SetStateAction } from "react";
|
|
2
|
-
import type { Entity, EntityStatus, EntityValues } from "./entities";
|
|
3
1
|
import type { CollectionCallbacks } from "./entity_callbacks";
|
|
4
2
|
|
|
5
3
|
import type { EnumValues, Properties, PostgresProperties, FirebaseProperties, MongoProperties } from "./properties";
|
|
6
|
-
import type { ExportConfig } from "./export_import";
|
|
7
4
|
|
|
8
5
|
import type { User } from "../users";
|
|
9
|
-
import type { RebaseContext } from "../rebase_context";
|
|
10
6
|
import type { Relation } from "./relations";
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
import type { PolicyExpression } from "./policy";
|
|
14
|
-
import type { ComponentRef } from "./component_ref";
|
|
15
|
-
import type { CollectionComponentOverrideMap } from "./component_overrides";
|
|
16
|
-
import type { WhereFilterOp, FilterValues, FilterPreset, OrderByTuple } from "./filter-operators";
|
|
7
|
+
import type { SecurityRule } from "./security_rules";
|
|
8
|
+
import type { WhereFilterOp, FilterValues, FilterPreset } from "./filter-operators";
|
|
17
9
|
|
|
18
10
|
/**
|
|
19
11
|
* Base interface containing all driver-agnostic collection properties.
|
|
@@ -107,70 +99,16 @@ export interface BaseCollectionConfig<M extends Record<string, unknown> = Record
|
|
|
107
99
|
*/
|
|
108
100
|
properties: Properties;
|
|
109
101
|
|
|
110
|
-
/**
|
|
111
|
-
* Icon for the navigation sidebar or cards.
|
|
112
|
-
*/
|
|
113
|
-
icon?: string | React.ReactNode;
|
|
114
102
|
|
|
115
|
-
/**
|
|
116
|
-
* Navigation group for this collection.
|
|
117
|
-
* Collections sharing the same group name will be visually grouped
|
|
118
|
-
* together in the drawer and home page. If not set, the collection
|
|
119
|
-
* falls into the default "Views" group.
|
|
120
|
-
*/
|
|
121
|
-
group?: string;
|
|
122
103
|
|
|
123
|
-
/**
|
|
124
|
-
* Array of entity views that this collection has.
|
|
125
|
-
* Can be an array of `EntityCustomView` or a string representing the key of a global `EntityCustomView`.
|
|
126
|
-
*/
|
|
127
|
-
entityViews?: (string | EntityCustomView<Record<string, unknown>>)[];
|
|
128
104
|
|
|
129
|
-
/**
|
|
130
|
-
* Default preview properties displayed when this collection is referenced to.
|
|
131
|
-
*/
|
|
132
|
-
previewProperties?: string[];
|
|
133
105
|
|
|
134
|
-
/**
|
|
135
|
-
* Properties to display as columns in the list view.
|
|
136
|
-
* If not specified, the list view uses a smart default (Title, Status, Date).
|
|
137
|
-
*/
|
|
138
|
-
listProperties?: string[];
|
|
139
106
|
|
|
140
|
-
/**
|
|
141
|
-
* Title property of the entity. This is the property that will be used
|
|
142
|
-
* as the title in entity related views and references.
|
|
143
|
-
* If not specified, the first property simple text property will be used.
|
|
144
|
-
*/
|
|
145
|
-
readonly titleProperty?: Extract<keyof M, string> | (string & {});
|
|
146
107
|
|
|
147
|
-
/**
|
|
148
|
-
* When editing a entity, you can choose to open the entity in a side dialog
|
|
149
|
-
* or in a full screen dialog. Defaults to `full_screen`.
|
|
150
|
-
*/
|
|
151
|
-
openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
|
|
152
108
|
|
|
153
|
-
/**
|
|
154
|
-
* Controls what happens when a user clicks on a entity in the collection view.
|
|
155
|
-
* - `"edit"` (default): Opens the entity in the edit form.
|
|
156
|
-
* - `"view"`: Opens a read-only detail view with an "Edit" button.
|
|
157
|
-
*/
|
|
158
|
-
defaultEntityAction?: "view" | "edit";
|
|
159
109
|
|
|
160
|
-
/**
|
|
161
|
-
* Replace the default entity form with a custom component.
|
|
162
|
-
* The Builder receives the same props as entity view tabs
|
|
163
|
-
* (entity, formContext, collection, etc.) and has full control over the UI.
|
|
164
|
-
*
|
|
165
|
-
* Works in both edit mode and read-only mode (when `defaultEntityAction`
|
|
166
|
-
* is `"view"`). In read-only mode, `formContext.readOnly` will be `true`.
|
|
167
|
-
*/
|
|
168
|
-
formView?: FormViewConfig;
|
|
169
110
|
|
|
170
|
-
|
|
171
|
-
* Prevent default actions from being displayed or executed on this collection.
|
|
172
|
-
*/
|
|
173
|
-
disableDefaultActions?: ("edit" | "copy" | "delete")[];
|
|
111
|
+
|
|
174
112
|
|
|
175
113
|
/**
|
|
176
114
|
* Mark this collection as an authentication collection.
|
|
@@ -198,37 +136,9 @@ export interface BaseCollectionConfig<M extends Record<string, unknown> = Record
|
|
|
198
136
|
disableDefaultPolicies?: boolean;
|
|
199
137
|
|
|
200
138
|
|
|
201
|
-
/**
|
|
202
|
-
* Order in which the properties are displayed.
|
|
203
|
-
* If you are specifying your collection as code, the order is the same as the
|
|
204
|
-
* one you define in `properties`. Additional columns are added at the
|
|
205
|
-
* end of the list, if the order is not specified.
|
|
206
|
-
*
|
|
207
|
-
* You can use this prop to hide some properties from the table view.
|
|
208
|
-
* Note that if you set this prop, other ways to hide fields, like
|
|
209
|
-
* `hidden` in the property definition, will be ignored.
|
|
210
|
-
* `propertiesOrder` has precedence over `hidden`.
|
|
211
|
-
*
|
|
212
|
-
* Supported entry formats:
|
|
213
|
-
* - For properties, use the property key.
|
|
214
|
-
* - For additional fields, use the field key.
|
|
215
|
-
* - Child collections (Firestore subcollections, or Postgres relations
|
|
216
|
-
* with `many` cardinality) each get a column with id
|
|
217
|
-
* `subcollection:<slug>`, e.g. `subcollection:orders`.
|
|
218
|
-
*/
|
|
219
|
-
propertiesOrder?: (Extract<keyof M, string> | (string & {}) | string | `subcollection:${string}`)[];
|
|
220
139
|
|
|
221
|
-
/**
|
|
222
|
-
* If enabled, content is loaded in batches. If `false` all entities in the
|
|
223
|
-
* collection are loaded. This means that when reaching the end of the
|
|
224
|
-
* collection, the CMS will load more entities.
|
|
225
|
-
* You can specify a number to specify the pagination size (50 by default)
|
|
226
|
-
* Defaults to `true`
|
|
227
|
-
*/
|
|
228
|
-
pagination?: boolean | number;
|
|
229
140
|
|
|
230
141
|
|
|
231
|
-
selectionEnabled?: boolean;
|
|
232
142
|
|
|
233
143
|
/**
|
|
234
144
|
* This interface defines all the callbacks that can be used when a entity
|
|
@@ -237,114 +147,19 @@ export interface BaseCollectionConfig<M extends Record<string, unknown> = Record
|
|
|
237
147
|
*/
|
|
238
148
|
readonly callbacks?: CollectionCallbacks<M, USER>;
|
|
239
149
|
|
|
240
|
-
/**
|
|
241
|
-
* Pass your own selection controller if you want to control selected
|
|
242
|
-
* entities externally.
|
|
243
|
-
* @see useSelectionController
|
|
244
|
-
*/
|
|
245
|
-
selectionController?: SelectionController<M>;
|
|
246
150
|
|
|
247
|
-
/**
|
|
248
|
-
* Force a filter in this view. If applied, the rest of the filters will
|
|
249
|
-
* be disabled. Filters applied with this prop cannot be changed.
|
|
250
|
-
* e.g. `fixedFilter: { age: [">", 18] }`
|
|
251
|
-
* e.g. `fixedFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
|
|
252
|
-
*/
|
|
253
|
-
readonly fixedFilter?: FilterValues<Extract<keyof M, string> | (string & {})>;
|
|
254
151
|
|
|
255
|
-
/**
|
|
256
|
-
* Initial filters applied to the collection this collection is related to.
|
|
257
|
-
* Defaults to none. Filters applied with this prop can be changed.
|
|
258
|
-
* e.g. `defaultFilter: { age: [">", 18] }`
|
|
259
|
-
* e.g. `defaultFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
|
|
260
|
-
*/
|
|
261
|
-
readonly defaultFilter?: FilterValues<Extract<keyof M, string> | (string & {})>; // setting FilterValues<M> can break defining collections by code
|
|
262
152
|
|
|
263
|
-
/**
|
|
264
|
-
* Pre-defined filter presets that appear as quick-access options in the
|
|
265
|
-
* collection toolbar. Each preset applies a set of filters (and
|
|
266
|
-
* optionally a sort order) with a single click.
|
|
267
|
-
*
|
|
268
|
-
* ```ts
|
|
269
|
-
* filterPresets: [
|
|
270
|
-
* {
|
|
271
|
-
* label: "Shipped this month",
|
|
272
|
-
* filterValues: {
|
|
273
|
-
* status: ["==", "shipped"],
|
|
274
|
-
* order_date: [">=", new Date(Date.now() - 30 * 86400000)]
|
|
275
|
-
* }
|
|
276
|
-
* }
|
|
277
|
-
* ]
|
|
278
|
-
* ```
|
|
279
|
-
*/
|
|
280
|
-
readonly filterPresets?: FilterPreset<Extract<keyof M, string> | (string & {})>[];
|
|
281
153
|
|
|
282
|
-
/**
|
|
283
|
-
* Default sort applied to this collection.
|
|
284
|
-
* When setting this prop, entities will have a default order
|
|
285
|
-
* applied in the collection.
|
|
286
|
-
* e.g. `sort: ["order", "asc"]`
|
|
287
|
-
*/
|
|
288
|
-
readonly sort?: OrderByTuple<Extract<keyof M, string> | (string & {})>;
|
|
289
154
|
|
|
290
|
-
/**
|
|
291
|
-
* You can add additional fields to the collection view by implementing
|
|
292
|
-
* an additional field delegate.
|
|
293
|
-
*/
|
|
294
|
-
readonly additionalFields?: AdditionalFieldDelegate<M, USER>[];
|
|
295
155
|
|
|
296
|
-
/**
|
|
297
|
-
* Default size of the rendered collection
|
|
298
|
-
*/
|
|
299
|
-
defaultSize?: CollectionSize;
|
|
300
156
|
|
|
301
|
-
/**
|
|
302
|
-
* Can the elements in this collection be edited inline in the collection
|
|
303
|
-
* view. Even when inline editing is disabled, entities can still be
|
|
304
|
-
* edited in the side panel (subject to `securityRules`).
|
|
305
|
-
*/
|
|
306
|
-
inlineEditing?: boolean;
|
|
307
157
|
|
|
308
|
-
/**
|
|
309
|
-
* Should this collection be hidden from the main navigation panel, if
|
|
310
|
-
* it is at the root level, or in the entity side panel if it's a
|
|
311
|
-
* subcollection.
|
|
312
|
-
* It will still be accessible if you reach the specified path.
|
|
313
|
-
* You can also use this collection as a reference target.
|
|
314
|
-
*/
|
|
315
|
-
hideFromNavigation?: boolean;
|
|
316
158
|
|
|
317
|
-
/**
|
|
318
|
-
* If you want to open custom views or subcollections by default when opening the edit
|
|
319
|
-
* view of a entity, you can specify the path to the view here.
|
|
320
|
-
* The path is relative to the current collection. For example if you have a collection
|
|
321
|
-
* that has a custom view as well as a subcollection that refers to another entity, you can
|
|
322
|
-
* either specify the path to the custom view or the path to the subcollection.
|
|
323
|
-
*/
|
|
324
|
-
defaultSelectedView?: string | DefaultSelectedViewBuilder;
|
|
325
159
|
|
|
326
|
-
/**
|
|
327
|
-
* Should the ID of this collection be hidden from the form view.
|
|
328
|
-
*/
|
|
329
|
-
hideIdFromForm?: boolean;
|
|
330
160
|
|
|
331
|
-
/**
|
|
332
|
-
* Should the ID of this collection be hidden from the grid view.
|
|
333
|
-
*/
|
|
334
|
-
hideIdFromCollection?: boolean;
|
|
335
161
|
|
|
336
|
-
/**
|
|
337
|
-
* If set to true, the form will be auto-saved when the user changes
|
|
338
|
-
* the value of a field.
|
|
339
|
-
* Defaults to false.
|
|
340
|
-
* When a new entity is created, this property can be updated to generated a new ID
|
|
341
|
-
*/
|
|
342
|
-
formAutoSave?: boolean;
|
|
343
162
|
|
|
344
|
-
/**
|
|
345
|
-
*
|
|
346
|
-
*/
|
|
347
|
-
exportable?: boolean | ExportConfig<USER>;
|
|
348
163
|
|
|
349
164
|
/**
|
|
350
165
|
* User id of the owner of this collection. This is used only by plugins, or if you
|
|
@@ -359,22 +174,8 @@ export interface BaseCollectionConfig<M extends Record<string, unknown> = Record
|
|
|
359
174
|
*/
|
|
360
175
|
metadata?: Record<string, unknown>;
|
|
361
176
|
|
|
362
|
-
/**
|
|
363
|
-
* Width of the side dialog (in pixels) when opening a entity in this collection.
|
|
364
|
-
*/
|
|
365
|
-
sideDialogWidth?: number | string;
|
|
366
177
|
|
|
367
|
-
/**
|
|
368
|
-
* If set to true, the default values of the properties will be applied
|
|
369
|
-
* to the entity every time the entity is updated (not only when created).
|
|
370
|
-
* Defaults to false.
|
|
371
|
-
*/
|
|
372
|
-
alwaysApplyDefaultValues?: boolean;
|
|
373
178
|
|
|
374
|
-
/**
|
|
375
|
-
* If set to true, a tab including the JSON representation of the entity will be included.
|
|
376
|
-
*/
|
|
377
|
-
includeJsonView?: boolean;
|
|
378
179
|
|
|
379
180
|
/**
|
|
380
181
|
* If set to true, changes to the entity will be saved in a subcollection.
|
|
@@ -394,61 +195,12 @@ export interface BaseCollectionConfig<M extends Record<string, unknown> = Record
|
|
|
394
195
|
*/
|
|
395
196
|
strictWrites?: boolean;
|
|
396
197
|
|
|
397
|
-
/**
|
|
398
|
-
* Should local changes be backed up in local storage, to prevent data loss on
|
|
399
|
-
* accidental navigations.
|
|
400
|
-
* - `manual_apply`: When the user navigates back to a entity with local changes,
|
|
401
|
-
* they will be prompted to restore the changes.
|
|
402
|
-
* - `auto_apply`: When the user navigates back to a entity with local changes,
|
|
403
|
-
* the changes will be automatically applied.
|
|
404
|
-
* - `false`: Local changes will not be backed up.
|
|
405
|
-
* Defaults to `manual_apply`.
|
|
406
|
-
*/
|
|
407
|
-
localChangesBackup?: "manual_apply" | "auto_apply" | false;
|
|
408
198
|
|
|
409
|
-
/**
|
|
410
|
-
* Default view mode for displaying this collection.
|
|
411
|
-
* - "table": Display entities in a table with inline editing (default)
|
|
412
|
-
* - "cards": Display entities as a grid of cards with thumbnails
|
|
413
|
-
* - "kanban": Display entities in a Kanban board grouped by a property
|
|
414
|
-
* Defaults to "table".
|
|
415
|
-
*/
|
|
416
|
-
defaultViewMode?: ViewMode;
|
|
417
199
|
|
|
418
|
-
/**
|
|
419
|
-
* Which view modes are available for this collection.
|
|
420
|
-
* Possible values: "table", "cards", "kanban".
|
|
421
|
-
* Defaults to all three: ["table", "cards", "kanban"].
|
|
422
|
-
* Note: "kanban" will only be available if the collection has at least
|
|
423
|
-
* one string property with `enum` defined, regardless of this setting.
|
|
424
|
-
*/
|
|
425
|
-
enabledViews?: ViewMode[];
|
|
426
200
|
|
|
427
|
-
/**
|
|
428
|
-
* Configuration for Kanban board view mode.
|
|
429
|
-
* When set, the Kanban view mode becomes available.
|
|
430
|
-
*/
|
|
431
|
-
kanban?: KanbanConfig<M>;
|
|
432
201
|
|
|
433
|
-
/**
|
|
434
|
-
* Property key to use for ordering items.
|
|
435
|
-
* Must reference a string/text property. When items are reordered,
|
|
436
|
-
* this property will be updated with lexicographic sort keys
|
|
437
|
-
* (e.g. "a0", "a1", "a0V") using string-based fractional indexing.
|
|
438
|
-
* Used by Kanban view for ordering within columns
|
|
439
|
-
* and can be used for general ordering purposes.
|
|
440
|
-
*/
|
|
441
|
-
readonly orderProperty?: Extract<keyof M, string> | (string & {});
|
|
442
202
|
|
|
443
|
-
/**
|
|
444
|
-
* Actions that can be performed on the entities in this collection.
|
|
445
|
-
*/
|
|
446
|
-
entityActions?: EntityAction<M, USER>[];
|
|
447
203
|
|
|
448
|
-
/**
|
|
449
|
-
* Builder for the collection actions rendered in the toolbar
|
|
450
|
-
*/
|
|
451
|
-
Actions?: ComponentRef<CollectionActionsProps>[];
|
|
452
204
|
|
|
453
205
|
/**
|
|
454
206
|
* The database table name for this collection.
|
|
@@ -470,30 +222,6 @@ export interface BaseCollectionConfig<M extends Record<string, unknown> = Record
|
|
|
470
222
|
*/
|
|
471
223
|
securityRules?: readonly SecurityRule[];
|
|
472
224
|
|
|
473
|
-
/**
|
|
474
|
-
* Collection-scoped component overrides. These take precedence over
|
|
475
|
-
* global overrides set on `<Rebase>`, but only within this collection's
|
|
476
|
-
* views (entity form, detail view, table, empty state, etc.).
|
|
477
|
-
*
|
|
478
|
-
* Only collection-scoped components (like `Entity.Form`, `Collection.EmptyState`,
|
|
479
|
-
* `Collection.Card`, etc.) can be overridden here. App-level components
|
|
480
|
-
* (like `Shell.AppBar`, `HomePage`) can only be overridden at the `<Rebase>` level.
|
|
481
|
-
*
|
|
482
|
-
* @example
|
|
483
|
-
* ```tsx
|
|
484
|
-
* const productsCollection: PostgresCollectionConfig = {
|
|
485
|
-
* name: "Products",
|
|
486
|
-
* slug: "products",
|
|
487
|
-
* table: "products",
|
|
488
|
-
* components: {
|
|
489
|
-
* "Entity.Form": { Component: ProductCustomForm },
|
|
490
|
-
* "Collection.Card": { Component: ProductCard },
|
|
491
|
-
* },
|
|
492
|
-
* properties: { ... }
|
|
493
|
-
* };
|
|
494
|
-
* ```
|
|
495
|
-
*/
|
|
496
|
-
components?: CollectionComponentOverrideMap;
|
|
497
225
|
}
|
|
498
226
|
|
|
499
227
|
// ── Driver-specific collection types ──────────────────────────────────
|
|
@@ -658,11 +386,18 @@ export type CollectionConfig<M extends Record<string, unknown> = Record<string,
|
|
|
658
386
|
/**
|
|
659
387
|
* Type guard for PostgreSQL collections.
|
|
660
388
|
* Returns true if the collection uses the Postgres engine (or the default engine).
|
|
389
|
+
*
|
|
390
|
+
* Generic over the *input* type, and narrows by intersection rather than
|
|
391
|
+
* replacement. Narrowing to a bare `PostgresCollectionConfig` discarded whatever
|
|
392
|
+
* the caller actually had — most visibly the admin panel's view model, whose
|
|
393
|
+
* flattened presentation fields vanished the moment a collection passed through
|
|
394
|
+
* one of these guards.
|
|
395
|
+
*
|
|
661
396
|
* @group Models
|
|
662
397
|
*/
|
|
663
|
-
export function isPostgresCollectionConfig<
|
|
664
|
-
collection:
|
|
665
|
-
): collection is PostgresCollectionConfig<
|
|
398
|
+
export function isPostgresCollectionConfig<C extends CollectionConfig<any, any>>(
|
|
399
|
+
collection: C
|
|
400
|
+
): collection is C & PostgresCollectionConfig<any, any> {
|
|
666
401
|
return !collection.engine || collection.engine === "postgres";
|
|
667
402
|
}
|
|
668
403
|
|
|
@@ -670,9 +405,9 @@ export function isPostgresCollectionConfig<M extends Record<string, unknown> = R
|
|
|
670
405
|
* Type guard for Firebase / Firestore collections.
|
|
671
406
|
* @group Models
|
|
672
407
|
*/
|
|
673
|
-
export function isFirebaseCollectionConfig<
|
|
674
|
-
collection:
|
|
675
|
-
): collection is FirebaseCollectionConfig<
|
|
408
|
+
export function isFirebaseCollectionConfig<C extends CollectionConfig<any, any>>(
|
|
409
|
+
collection: C
|
|
410
|
+
): collection is C & FirebaseCollectionConfig<any, any> {
|
|
676
411
|
return collection.engine === "firestore";
|
|
677
412
|
}
|
|
678
413
|
|
|
@@ -680,9 +415,9 @@ export function isFirebaseCollectionConfig<M extends Record<string, unknown> = R
|
|
|
680
415
|
* Type guard for MongoDB collections.
|
|
681
416
|
* @group Models
|
|
682
417
|
*/
|
|
683
|
-
export function isMongoDBCollectionConfig<
|
|
684
|
-
collection:
|
|
685
|
-
): collection is MongoDBCollectionConfig<
|
|
418
|
+
export function isMongoDBCollectionConfig<C extends CollectionConfig<any, any>>(
|
|
419
|
+
collection: C
|
|
420
|
+
): collection is C & MongoDBCollectionConfig<any, any> {
|
|
686
421
|
return collection.engine === "mongodb";
|
|
687
422
|
}
|
|
688
423
|
|
|
@@ -720,574 +455,11 @@ export function getDeclaredSubcollections<M extends Record<string, unknown> = Re
|
|
|
720
455
|
}
|
|
721
456
|
|
|
722
457
|
|
|
723
|
-
/**
|
|
724
|
-
* Configuration for Kanban board view mode.
|
|
725
|
-
* @group Collections
|
|
726
|
-
*/
|
|
727
|
-
export interface KanbanConfig<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
728
|
-
/**
|
|
729
|
-
* Property key to use for Kanban board columns.
|
|
730
|
-
* Must reference a string property with `enum` values defined.
|
|
731
|
-
* Entities will be grouped into columns based on this property's value.
|
|
732
|
-
* The column order is determined by the order of `enum` values in the property.
|
|
733
|
-
*/
|
|
734
|
-
columnProperty: Extract<keyof M, string> | (string & {});
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* View mode for displaying a collection.
|
|
739
|
-
* - "list": Simple, clean list view — the classic CMS default
|
|
740
|
-
* - "table": Table with inline editing
|
|
741
|
-
* - "cards": Grid of visual cards with thumbnails
|
|
742
|
-
* - "kanban": Board view grouped by a property
|
|
743
|
-
* @group Collections
|
|
744
|
-
*/
|
|
745
|
-
export type ViewMode = "list" | "table" | "cards" | "kanban";
|
|
746
|
-
|
|
747
|
-
/**
|
|
748
|
-
* Parameter passed to the `Actions` prop in the collection configuration.
|
|
749
|
-
* The component will receive this prop when it is rendered in the collection
|
|
750
|
-
* toolbar.
|
|
751
|
-
*
|
|
752
|
-
* @group Models
|
|
753
|
-
*/
|
|
754
|
-
export interface CollectionActionsProps<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User, EC extends CollectionConfig<M> = CollectionConfig<M>> {
|
|
755
|
-
/**
|
|
756
|
-
* Full collection path of this entity. This is the full path, like
|
|
757
|
-
* `users/1234/addresses`
|
|
758
|
-
*/
|
|
759
|
-
path: string;
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* Path of the last collection, like `addresses`
|
|
763
|
-
*/
|
|
764
|
-
relativePath: string;
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
* Array of the parent path segments like `['users']`
|
|
768
|
-
*/
|
|
769
|
-
parentCollectionSlugs: string[];
|
|
770
|
-
parentEntityIds: string[];
|
|
771
|
-
|
|
772
|
-
/**
|
|
773
|
-
* The collection configuration
|
|
774
|
-
*/
|
|
775
|
-
collection: EC;
|
|
776
|
-
|
|
777
|
-
/**
|
|
778
|
-
* Use this controller to get the selected entities and to update the
|
|
779
|
-
* selected entities state.
|
|
780
|
-
*/
|
|
781
|
-
selectionController: SelectionController<M>;
|
|
782
|
-
|
|
783
|
-
/**
|
|
784
|
-
* Use this controller to get the table controller and to update the
|
|
785
|
-
* table controller state.
|
|
786
|
-
*/
|
|
787
|
-
tableController: EntityTableController<M>;
|
|
788
|
-
|
|
789
|
-
/**
|
|
790
|
-
* Context of the app status
|
|
791
|
-
*/
|
|
792
|
-
context: RebaseContext<USER>;
|
|
793
|
-
|
|
794
|
-
/**
|
|
795
|
-
* Count of the entities in this collection.
|
|
796
|
-
* undefined means the count is still loading.
|
|
797
|
-
*/
|
|
798
|
-
collectionEntitiesCount?: number;
|
|
799
|
-
|
|
800
|
-
/**
|
|
801
|
-
* Programmatically open the new-document form for this collection,
|
|
802
|
-
* optionally pre-populating it with initial field values.
|
|
803
|
-
* The form opens in the same mode configured for the collection
|
|
804
|
-
* (side panel, full screen, or split).
|
|
805
|
-
*
|
|
806
|
-
* This is the primary hook for workflows that need to create a document
|
|
807
|
-
* from external data — e.g. fetching content from a URL, importing from
|
|
808
|
-
* a third-party API, or duplicating from another system.
|
|
809
|
-
*
|
|
810
|
-
* @example
|
|
811
|
-
* // Inside a custom CollectionAction component:
|
|
812
|
-
* openNewDocument({ title: "Fetched title", body: "..." });
|
|
813
|
-
*/
|
|
814
|
-
openNewDocument: (defaultValues?: Record<string, unknown>) => void;
|
|
815
|
-
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
/**
|
|
819
|
-
* Use this controller to retrieve the selected entities or modify them in
|
|
820
|
-
* an {@link CollectionConfig}
|
|
821
|
-
* @group Models
|
|
822
|
-
*/
|
|
823
|
-
export interface SelectionController<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
824
|
-
selectedEntities: Entity<M>[];
|
|
825
|
-
setSelectedEntities(entities: Entity<M>[]): void;
|
|
826
|
-
setSelectedEntities(action: (prev: Entity<M>[]) => Entity<M>[]): void;
|
|
827
|
-
isEntitySelected(entity: Entity<M>): boolean;
|
|
828
|
-
toggleEntitySelection(entity: Entity<M>, newSelectedState?: boolean): void;
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
// Canonical filter types — re-exported from the single source-of-truth.
|
|
832
458
|
export type { WhereFilterOp, FilterValues, WireFilterValues, FilterPreset } from "./filter-operators";
|
|
833
459
|
|
|
834
460
|
|
|
835
|
-
/**
|
|
836
|
-
* Used to indicate valid filter combinations (e.g. created in Firestore)
|
|
837
|
-
* If the user selects a specific filter/sort combination, the CMS checks if it's
|
|
838
|
-
* valid, otherwise it reverts to the simpler valid case
|
|
839
|
-
* @group Models
|
|
840
|
-
*/
|
|
841
|
-
export type FilterCombination<Key extends string> = Partial<Record<Key, "asc" | "desc">>;
|
|
842
|
-
|
|
843
|
-
/**
|
|
844
|
-
* Sizes in which a collection can be rendered
|
|
845
|
-
* @group Models
|
|
846
|
-
*/
|
|
847
|
-
export type CollectionSize = "xs" | "s" | "m" | "l" | "xl";
|
|
848
|
-
|
|
849
|
-
export type AdditionalFieldDelegateProps<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = {
|
|
850
|
-
entity: Entity<M>,
|
|
851
|
-
context: RebaseContext<USER>
|
|
852
|
-
};
|
|
853
|
-
|
|
854
|
-
/**
|
|
855
|
-
* Use this interface for adding additional fields to entity collection views and forms.
|
|
856
|
-
* @group Models
|
|
857
|
-
*/
|
|
858
|
-
export interface AdditionalFieldDelegate<M extends Record<string, unknown> = Record<string, unknown>,
|
|
859
|
-
USER extends User = User> {
|
|
860
|
-
|
|
861
|
-
/**
|
|
862
|
-
* ID of this column. You can use this id in the `properties` field of the
|
|
863
|
-
* collection in any order you want
|
|
864
|
-
*/
|
|
865
|
-
key: string;
|
|
866
|
-
|
|
867
|
-
/**
|
|
868
|
-
* Header of this column
|
|
869
|
-
*/
|
|
870
|
-
name: string;
|
|
871
|
-
|
|
872
|
-
/**
|
|
873
|
-
* Width of the generated column in pixels
|
|
874
|
-
*/
|
|
875
|
-
width?: number;
|
|
876
|
-
|
|
877
|
-
/**
|
|
878
|
-
* Builder for the custom field
|
|
879
|
-
*/
|
|
880
|
-
Builder?(props: { entity: Entity<M>, context: RebaseContext<USER> }): React.ReactNode;
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
/**
|
|
884
|
-
* If this column needs to update dynamically based on other properties,
|
|
885
|
-
* you can define an array of keys as strings with the
|
|
886
|
-
* `dependencies` prop.
|
|
887
|
-
* e.g. ["name", "surname"]
|
|
888
|
-
* This is a performance optimization, if you don't define dependencies
|
|
889
|
-
* it will be updated in every render.
|
|
890
|
-
*/
|
|
891
|
-
dependencies?: NoInfer<Extract<keyof M, string>> | NoInfer<Extract<keyof M, string>>[] | (string & {}) | (string & {})[];
|
|
892
|
-
|
|
893
|
-
/**
|
|
894
|
-
* Use this prop to define the value of the column as a string or number.
|
|
895
|
-
* This is the value that will be used for exporting the collection.
|
|
896
|
-
* If `Builder` is defined, this prop will be ignored in the collection
|
|
897
|
-
* view.
|
|
898
|
-
* @param entity
|
|
899
|
-
*/
|
|
900
|
-
value?(props: {
|
|
901
|
-
entity: Entity<M>,
|
|
902
|
-
context: RebaseContext
|
|
903
|
-
}): string | number | Promise<string | number> | undefined;
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
|
|
907
461
|
export type InferCollectionConfigType<S extends CollectionConfig> = S extends CollectionConfig<infer M> ? M : never;
|
|
908
462
|
|
|
909
|
-
/**
|
|
910
|
-
* Used in the {@link CollectionConfig#defaultSelectedView} to define the default
|
|
911
|
-
* @group Models
|
|
912
|
-
*/
|
|
913
|
-
export type DefaultSelectedViewBuilder = (params: DefaultSelectedViewParams) => string | undefined;
|
|
914
|
-
|
|
915
|
-
/**
|
|
916
|
-
* Used in the {@link CollectionConfig#defaultSelectedView} to define the default
|
|
917
|
-
* @group Models
|
|
918
|
-
*/
|
|
919
|
-
export type DefaultSelectedViewParams = {
|
|
920
|
-
status?: EntityStatus;
|
|
921
|
-
entityId?: string | number;
|
|
922
|
-
};
|
|
923
|
-
/**
|
|
924
|
-
* You can use this controller to control the table view of a collection.
|
|
925
|
-
*/
|
|
926
|
-
export type EntityTableController<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
927
|
-
data: Entity<M>[];
|
|
928
|
-
dataLoading: boolean;
|
|
929
|
-
noMoreToLoad: boolean;
|
|
930
|
-
dataLoadingError?: Error;
|
|
931
|
-
filterValues?: FilterValues<Extract<keyof M, string> | (string & {})>;
|
|
932
|
-
setFilterValues?: (filterValues: FilterValues<Extract<keyof M, string> | (string & {})>) => void;
|
|
933
|
-
sortBy?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"];
|
|
934
|
-
setSortBy?: (sortBy?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"]) => void;
|
|
935
|
-
searchString?: string;
|
|
936
|
-
setSearchString?: (searchString?: string) => void;
|
|
937
|
-
clearFilter?: () => void;
|
|
938
|
-
itemCount?: number;
|
|
939
|
-
setItemCount?: (itemCount: number) => void;
|
|
940
|
-
initialScroll?: number;
|
|
941
|
-
onScroll?: (props: {
|
|
942
|
-
scrollDirection: "forward" | "backward",
|
|
943
|
-
scrollOffset: number,
|
|
944
|
-
scrollUpdateWasRequested: boolean
|
|
945
|
-
}) => void;
|
|
946
|
-
paginationEnabled?: boolean;
|
|
947
|
-
pageSize?: number;
|
|
948
|
-
checkFilterCombination?: (filterValues: FilterValues<string>,
|
|
949
|
-
sortBy?: [string, "asc" | "desc"]) => boolean;
|
|
950
|
-
popupCell?: SelectedCellProps<M>;
|
|
951
|
-
setPopupCell?: (popupCell?: SelectedCellProps<M>) => void;
|
|
952
|
-
|
|
953
|
-
onAddColumn?: (column: string) => void;
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
export type SelectedCellProps<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
957
|
-
propertyKey: Extract<keyof M, string> | (string & {});
|
|
958
|
-
cellRect: DOMRect;
|
|
959
|
-
width: number;
|
|
960
|
-
height: number;
|
|
961
|
-
entityPath: string;
|
|
962
|
-
entityId: string | number;
|
|
963
|
-
};
|
|
964
|
-
|
|
965
|
-
/**
|
|
966
|
-
* SQL operation that a policy applies to.
|
|
967
|
-
* @group Models
|
|
968
|
-
*/
|
|
969
|
-
export type SecurityOperation = "select" | "insert" | "update" | "delete" | "all";
|
|
970
|
-
|
|
971
|
-
/**
|
|
972
|
-
* Flexible Row Level Security rule for a collection.
|
|
973
|
-
*
|
|
974
|
-
* Built on PostgreSQL Row Level Security. Rules can range from
|
|
975
|
-
* simple convenience shortcuts to fully custom SQL expressions, giving you the
|
|
976
|
-
* full power of PostgreSQL Row Level Security.
|
|
977
|
-
*
|
|
978
|
-
* The authenticated user's identity is available in raw SQL via:
|
|
979
|
-
* - `auth.uid()` — the user's ID
|
|
980
|
-
* - `auth.roles()` — comma-separated app role IDs
|
|
981
|
-
* - `auth.jwt()` — full JWT claims as JSONB
|
|
982
|
-
*
|
|
983
|
-
* These are set automatically per-transaction by the backend.
|
|
984
|
-
*
|
|
985
|
-
* **How rules combine:** PostgreSQL evaluates all matching policies for an
|
|
986
|
-
* operation. Permissive rules are OR'd together (any one passing is enough).
|
|
987
|
-
* Restrictive rules are AND'd (all must pass). This is standard PostgreSQL RLS behavior.
|
|
988
|
-
*
|
|
989
|
-
* **Mutual exclusivity:** `ownerField`, `access`, structured `condition`, and
|
|
990
|
-
* raw SQL (`using`/`withCheck`) cannot be combined. The type system enforces
|
|
991
|
-
* this — attempting to set conflicting fields will produce a compile-time
|
|
992
|
-
* error.
|
|
993
|
-
*
|
|
994
|
-
* **Which form to reach for:** prefer the structured {@link StructuredSecurityRule}
|
|
995
|
-
* (`condition`/`check`) or the shortcuts (`ownerField`, `access`, `roles`). These
|
|
996
|
-
* are engine-agnostic and evaluated identically by the database and the admin UI,
|
|
997
|
-
* so the UI never shows an action the database will reject. Raw SQL
|
|
998
|
-
* ({@link RawSQLSecurityRule}) keeps full PostgreSQL power but is Postgres-only
|
|
999
|
-
* and server-authoritative (the UI cannot evaluate arbitrary SQL locally).
|
|
1000
|
-
*
|
|
1001
|
-
* @group Models
|
|
1002
|
-
*/
|
|
1003
|
-
export type SecurityRule =
|
|
1004
|
-
| OwnerSecurityRule
|
|
1005
|
-
| PublicSecurityRule
|
|
1006
|
-
| StructuredSecurityRule
|
|
1007
|
-
| RawSQLSecurityRule
|
|
1008
|
-
| RolesOnlySecurityRule;
|
|
1009
|
-
|
|
1010
|
-
/**
|
|
1011
|
-
* Shared fields for all SecurityRule variants.
|
|
1012
|
-
* @group Models
|
|
1013
|
-
*/
|
|
1014
|
-
export interface SecurityRuleBase {
|
|
1015
|
-
/**
|
|
1016
|
-
* Optional human-readable name for the policy.
|
|
1017
|
-
* If not provided, one will be auto-generated from the table name and operation.
|
|
1018
|
-
* Must be unique per table.
|
|
1019
|
-
*
|
|
1020
|
-
* When using `operations` (array), each generated policy will have the
|
|
1021
|
-
* operation name appended, e.g. `"owner_access_select"`, `"owner_access_update"`.
|
|
1022
|
-
*/
|
|
1023
|
-
name?: string;
|
|
1024
|
-
|
|
1025
|
-
/**
|
|
1026
|
-
* Which SQL operation this policy applies to.
|
|
1027
|
-
* Use this when the policy targets a single operation or all operations.
|
|
1028
|
-
*
|
|
1029
|
-
* For multiple specific operations, use `operations` (array) instead.
|
|
1030
|
-
* If neither is specified, defaults to `"all"`.
|
|
1031
|
-
*
|
|
1032
|
-
* @default "all"
|
|
1033
|
-
*/
|
|
1034
|
-
operation?: SecurityOperation;
|
|
1035
|
-
|
|
1036
|
-
/**
|
|
1037
|
-
* Array of SQL operations this policy applies to.
|
|
1038
|
-
* The compiler will generate one PostgreSQL policy per operation, sharing
|
|
1039
|
-
* the same configuration.
|
|
1040
|
-
*
|
|
1041
|
-
* This reduces boilerplate when the same rule applies to multiple (but not all)
|
|
1042
|
-
* operations.
|
|
1043
|
-
*
|
|
1044
|
-
* Takes precedence over `operation` (singular) if both are specified.
|
|
1045
|
-
*
|
|
1046
|
-
* @example
|
|
1047
|
-
* // Same rule for select and update
|
|
1048
|
-
* { operations: ["select", "update"], ownerField: "user_id" }
|
|
1049
|
-
*
|
|
1050
|
-
* @example
|
|
1051
|
-
* // Equivalent to operation: "all"
|
|
1052
|
-
* { operations: ["all"], ownerField: "user_id" }
|
|
1053
|
-
*/
|
|
1054
|
-
operations?: readonly SecurityOperation[];
|
|
1055
|
-
|
|
1056
|
-
/**
|
|
1057
|
-
* Whether this policy is `"permissive"` (default) or `"restrictive"`.
|
|
1058
|
-
*
|
|
1059
|
-
* - **permissive**: Multiple permissive policies for the same operation are
|
|
1060
|
-
* OR'd together — if *any* passes, access is granted.
|
|
1061
|
-
* - **restrictive**: Restrictive policies are AND'd with all permissive
|
|
1062
|
-
* policies — they act as additional gates that *must* also pass.
|
|
1063
|
-
*
|
|
1064
|
-
* This is the standard PostgreSQL RLS model.
|
|
1065
|
-
*
|
|
1066
|
-
* @default "permissive"
|
|
1067
|
-
*/
|
|
1068
|
-
mode?: "permissive" | "restrictive";
|
|
1069
|
-
|
|
1070
|
-
/**
|
|
1071
|
-
* **Shortcut.** Restrict this rule to users that have one of these
|
|
1072
|
-
* application-level roles.
|
|
1073
|
-
*
|
|
1074
|
-
* **Important:** These are NOT native PostgreSQL database roles — names
|
|
1075
|
-
* like `public`, `anon` or `authenticated` belong to {@link pgRoles} and
|
|
1076
|
-
* produce a condition no user can satisfy if used here. These are
|
|
1077
|
-
* application roles managed by Rebase, stored as an inline `roles TEXT[]`
|
|
1078
|
-
* column on the users table, and injected into each transaction as
|
|
1079
|
-
* `app.user_roles` — which `auth.roles()` reads.
|
|
1080
|
-
*
|
|
1081
|
-
* There is no roles registry: a role exists once it is assigned to a user.
|
|
1082
|
-
*
|
|
1083
|
-
* Generates a safe array-overlap condition — the user passes if they hold
|
|
1084
|
-
* *any* of the listed roles:
|
|
1085
|
-
* `string_to_array(auth.roles(), ',') && ARRAY['<role1>', '<role2>']`
|
|
1086
|
-
*
|
|
1087
|
-
* (Note: this is a true set intersection, NOT a regex/substring match, so
|
|
1088
|
-
* a role named `admin` never matches `nonadmin` or `superadmin`.)
|
|
1089
|
-
*
|
|
1090
|
-
* Can be combined with `ownerField`, `access`, `condition`, or raw
|
|
1091
|
-
* `using`/`withCheck`. When combined, the role check is AND'd with the
|
|
1092
|
-
* other condition.
|
|
1093
|
-
*
|
|
1094
|
-
* @example
|
|
1095
|
-
* // Only admins can delete
|
|
1096
|
-
* { operation: "delete", roles: ["admin"] }
|
|
1097
|
-
*
|
|
1098
|
-
* @example
|
|
1099
|
-
* // Admins have unfiltered read access to all rows
|
|
1100
|
-
* { operation: "select", roles: ["admin"], using: "true" }
|
|
1101
|
-
*/
|
|
1102
|
-
roles?: readonly string[];
|
|
1103
|
-
|
|
1104
|
-
// ── Advanced: native PostgreSQL role targeting ───────────────────────
|
|
1105
|
-
|
|
1106
|
-
/**
|
|
1107
|
-
* **Advanced.** Native PostgreSQL database roles the policy applies to.
|
|
1108
|
-
*
|
|
1109
|
-
* By default, all generated policies target the `public` role (i.e.
|
|
1110
|
-
* every database connection). This is correct for most setups where
|
|
1111
|
-
* a single database role is used for all connections.
|
|
1112
|
-
*
|
|
1113
|
-
* **Important:** These are NOT the same as the application-level
|
|
1114
|
-
* {@link roles} (admin, editor, viewer, etc.) — those are enforced in the
|
|
1115
|
-
* USING/WITH CHECK clauses via `auth.roles()`. This field controls the
|
|
1116
|
-
* PostgreSQL `TO` clause in `CREATE POLICY ... TO role_name`.
|
|
1117
|
-
*
|
|
1118
|
-
* Use this if you have dedicated PostgreSQL roles (e.g. `app_read`,
|
|
1119
|
-
* `app_write`) and want policies to target specific ones.
|
|
1120
|
-
*
|
|
1121
|
-
* @default ["public"]
|
|
1122
|
-
*
|
|
1123
|
-
* @example
|
|
1124
|
-
* // Only apply this policy when connected as `app_role`
|
|
1125
|
-
* { operation: "select", access: "public", pgRoles: ["app_role"] }
|
|
1126
|
-
*/
|
|
1127
|
-
pgRoles?: readonly string[];
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
/**
|
|
1131
|
-
* Security rule that grants access based on row ownership.
|
|
1132
|
-
* Generates a USING/WITH CHECK clause like: `<column> = auth.uid()`
|
|
1133
|
-
*
|
|
1134
|
-
* Cannot be combined with `using`, `withCheck`, or `access`.
|
|
1135
|
-
*
|
|
1136
|
-
* @example
|
|
1137
|
-
* { operation: "all", ownerField: "user_id" }
|
|
1138
|
-
*
|
|
1139
|
-
* @group Models
|
|
1140
|
-
*/
|
|
1141
|
-
export interface OwnerSecurityRule extends SecurityRuleBase {
|
|
1142
|
-
/** The property (column) that stores the owner's user ID. */
|
|
1143
|
-
ownerField: string;
|
|
1144
|
-
access?: never;
|
|
1145
|
-
using?: never;
|
|
1146
|
-
withCheck?: never;
|
|
1147
|
-
condition?: never;
|
|
1148
|
-
check?: never;
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
/**
|
|
1152
|
-
* Security rule that grants unrestricted row access (no row filtering).
|
|
1153
|
-
* Generates `USING (true)`.
|
|
1154
|
-
*
|
|
1155
|
-
* This means "no row-level filter", NOT "anonymous/unauthenticated access".
|
|
1156
|
-
* Authentication is still enforced at the API layer — this only controls which
|
|
1157
|
-
* *rows* authenticated users can see.
|
|
1158
|
-
*
|
|
1159
|
-
* Cannot be combined with `using`, `withCheck`, or `ownerField`.
|
|
1160
|
-
*
|
|
1161
|
-
* @example
|
|
1162
|
-
* // Public read (any authenticated user sees all rows)
|
|
1163
|
-
* { operation: "select", access: "public" }
|
|
1164
|
-
*
|
|
1165
|
-
* @group Models
|
|
1166
|
-
*/
|
|
1167
|
-
export interface PublicSecurityRule extends SecurityRuleBase {
|
|
1168
|
-
/** Grant unrestricted row access for this operation. */
|
|
1169
|
-
access: "public";
|
|
1170
|
-
ownerField?: never;
|
|
1171
|
-
using?: never;
|
|
1172
|
-
withCheck?: never;
|
|
1173
|
-
condition?: never;
|
|
1174
|
-
check?: never;
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
/**
|
|
1178
|
-
* Security rule expressed as a structured, engine-agnostic
|
|
1179
|
-
* {@link PolicyExpression}. This is the **recommended** way to write a
|
|
1180
|
-
* non-trivial condition: it compiles to PostgreSQL `USING`/`WITH CHECK` SQL
|
|
1181
|
-
* *and* is evaluated identically by the admin UI, so the UI can never show an
|
|
1182
|
-
* action the database will reject.
|
|
1183
|
-
*
|
|
1184
|
-
* Cannot be combined with `ownerField`, `access`, or raw `using`/`withCheck`.
|
|
1185
|
-
*
|
|
1186
|
-
* @example
|
|
1187
|
-
* // Owner, or any user holding the `moderator` role
|
|
1188
|
-
* {
|
|
1189
|
-
* operation: "update",
|
|
1190
|
-
* condition: policy.or(
|
|
1191
|
-
* policy.compare(policy.field("user_id"), "eq", policy.authUid()),
|
|
1192
|
-
* policy.rolesOverlap(["moderator"])
|
|
1193
|
-
* )
|
|
1194
|
-
* }
|
|
1195
|
-
*
|
|
1196
|
-
* @group Models
|
|
1197
|
-
*/
|
|
1198
|
-
export interface StructuredSecurityRule extends SecurityRuleBase {
|
|
1199
|
-
/**
|
|
1200
|
-
* Structured condition for the `USING` clause — which *existing* rows are
|
|
1201
|
-
* visible / can be modified / deleted (SELECT, UPDATE, DELETE).
|
|
1202
|
-
*/
|
|
1203
|
-
condition: PolicyExpression;
|
|
1204
|
-
|
|
1205
|
-
/**
|
|
1206
|
-
* Structured condition for the `WITH CHECK` clause — which *new/updated*
|
|
1207
|
-
* row values are allowed (INSERT, UPDATE). Defaults to `condition` when
|
|
1208
|
-
* omitted, mirroring PostgreSQL's own behavior.
|
|
1209
|
-
*/
|
|
1210
|
-
check?: PolicyExpression;
|
|
1211
|
-
|
|
1212
|
-
ownerField?: never;
|
|
1213
|
-
access?: never;
|
|
1214
|
-
using?: never;
|
|
1215
|
-
withCheck?: never;
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
/**
|
|
1219
|
-
* Security rule using raw SQL expressions for full PostgreSQL RLS power.
|
|
1220
|
-
*
|
|
1221
|
-
* **Postgres-only and server-authoritative.** Arbitrary SQL cannot be
|
|
1222
|
-
* evaluated by the admin UI, so a rule using this form is treated as *unknown*
|
|
1223
|
-
* client-side (never silently allowed) and its effect on visible actions is
|
|
1224
|
-
* reflected from the server. For conditions that should also drive the UI
|
|
1225
|
-
* precisely, prefer the structured {@link StructuredSecurityRule}.
|
|
1226
|
-
*
|
|
1227
|
-
* Cannot be combined with `ownerField`, `access`, or structured `condition`.
|
|
1228
|
-
*
|
|
1229
|
-
* You can reference columns via `{column_name}` which will be resolved to
|
|
1230
|
-
* `table.column_name` in the generated Drizzle code.
|
|
1231
|
-
*
|
|
1232
|
-
* @example
|
|
1233
|
-
* // Rows published in the last 30 days are visible
|
|
1234
|
-
* { operation: "select", using: "{published_at} > now() - interval '30 days'" }
|
|
1235
|
-
*
|
|
1236
|
-
* @example
|
|
1237
|
-
* // Only the owner, or users with 'moderator' role
|
|
1238
|
-
* {
|
|
1239
|
-
* operation: "select",
|
|
1240
|
-
* using: "{user_id} = auth.uid() OR auth.roles() ~ 'moderator'"
|
|
1241
|
-
* }
|
|
1242
|
-
*
|
|
1243
|
-
* @group Models
|
|
1244
|
-
*/
|
|
1245
|
-
export interface RawSQLSecurityRule extends SecurityRuleBase {
|
|
1246
|
-
/**
|
|
1247
|
-
* Raw SQL expression for the `USING` clause.
|
|
1248
|
-
* This controls which *existing* rows are visible / can be modified / deleted.
|
|
1249
|
-
* Applied to SELECT, UPDATE, and DELETE.
|
|
1250
|
-
*/
|
|
1251
|
-
using: string;
|
|
1252
|
-
|
|
1253
|
-
/**
|
|
1254
|
-
* Raw SQL expression for the `WITH CHECK` clause.
|
|
1255
|
-
* This controls which *new/updated* row values are allowed.
|
|
1256
|
-
* Applied to INSERT and UPDATE.
|
|
1257
|
-
*
|
|
1258
|
-
* If not provided on INSERT/UPDATE policies, falls back to `using`
|
|
1259
|
-
* (which matches PostgreSQL's own default behavior).
|
|
1260
|
-
*/
|
|
1261
|
-
withCheck?: string;
|
|
1262
|
-
|
|
1263
|
-
ownerField?: never;
|
|
1264
|
-
access?: never;
|
|
1265
|
-
condition?: never;
|
|
1266
|
-
check?: never;
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
/**
|
|
1270
|
-
* Security rule that only filters by application roles, without any
|
|
1271
|
-
* row-level condition (USING/WITH CHECK).
|
|
1272
|
-
*
|
|
1273
|
-
* Useful for simple "only admins can access this table" rules where
|
|
1274
|
-
* no per-row filtering is needed.
|
|
1275
|
-
*
|
|
1276
|
-
* @example
|
|
1277
|
-
* // Only admins can delete
|
|
1278
|
-
* { operation: "delete", roles: ["admin"] }
|
|
1279
|
-
*
|
|
1280
|
-
* @group Models
|
|
1281
|
-
*/
|
|
1282
|
-
export interface RolesOnlySecurityRule extends SecurityRuleBase {
|
|
1283
|
-
ownerField?: never;
|
|
1284
|
-
access?: never;
|
|
1285
|
-
using?: never;
|
|
1286
|
-
withCheck?: never;
|
|
1287
|
-
condition?: never;
|
|
1288
|
-
check?: never;
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
463
|
/**
|
|
1292
464
|
* Configuration for authentication collections.
|
|
1293
465
|
*
|
|
@@ -1355,9 +527,14 @@ export interface AuthCollectionConfig {
|
|
|
1355
527
|
* the built-in `resetPasswordAction` into the collection's entity actions.
|
|
1356
528
|
*
|
|
1357
529
|
* Set to `false` to disable, or pass a custom `EntityAction` to replace the UI.
|
|
530
|
+
*
|
|
531
|
+
* The object form is an `EntityAction` from `@rebasepro/admin-types`, typed
|
|
532
|
+
* here as `object` because it is a React component with admin controllers in
|
|
533
|
+
* its props and nothing on the server reads it — only whether the built-in
|
|
534
|
+
* action is injected, which is the boolean.
|
|
1358
535
|
*/
|
|
1359
536
|
actions?: {
|
|
1360
|
-
resetPassword?: boolean |
|
|
537
|
+
resetPassword?: boolean | object;
|
|
1361
538
|
};
|
|
1362
539
|
}
|
|
1363
540
|
|