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