@rebasepro/types 0.0.1-canary.0 → 0.0.1-canary.0e2f892
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/README.md +1 -1
- package/dist/controllers/analytics_controller.d.ts +2 -2
- package/dist/controllers/auth.d.ts +52 -6
- package/dist/controllers/client.d.ts +170 -0
- package/dist/controllers/collection_registry.d.ts +45 -0
- package/dist/controllers/customization_controller.d.ts +11 -1
- package/dist/controllers/data.d.ts +168 -0
- package/dist/controllers/data_driver.d.ts +160 -0
- package/dist/controllers/database_admin.d.ts +11 -0
- package/dist/controllers/effective_role.d.ts +4 -0
- package/dist/controllers/email.d.ts +34 -0
- package/dist/controllers/index.d.ts +12 -5
- package/dist/controllers/local_config_persistence.d.ts +4 -4
- package/dist/controllers/navigation.d.ts +12 -61
- package/dist/controllers/registry.d.ts +54 -0
- package/dist/controllers/side_entity_controller.d.ts +7 -7
- package/dist/controllers/storage.d.ts +24 -26
- package/dist/index.d.ts +0 -1
- package/dist/index.es.js +119 -14
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +118 -13
- package/dist/index.umd.js.map +1 -1
- package/dist/rebase_context.d.ts +40 -26
- package/dist/types/backend.d.ts +300 -18
- package/dist/types/builders.d.ts +15 -0
- package/dist/types/chips.d.ts +1 -1
- package/dist/types/collections.d.ts +324 -355
- package/dist/types/cron.d.ts +102 -0
- package/dist/types/data_source.d.ts +64 -0
- package/dist/types/entities.d.ts +29 -24
- package/dist/types/entity_actions.d.ts +12 -12
- package/dist/types/entity_callbacks.d.ts +12 -12
- package/dist/types/entity_link_builder.d.ts +1 -1
- package/dist/types/entity_overrides.d.ts +7 -2
- package/dist/types/entity_views.d.ts +61 -0
- package/dist/types/export_import.d.ts +3 -3
- package/dist/types/index.d.ts +9 -5
- package/dist/types/plugins.d.ts +228 -225
- package/dist/types/properties.d.ts +135 -62
- package/dist/types/property_config.d.ts +13 -11
- package/dist/types/relations.d.ts +1 -1
- package/dist/types/slots.d.ts +252 -0
- package/dist/types/translations.d.ts +870 -0
- package/dist/types/user_management_delegate.d.ts +43 -0
- package/dist/types/websockets.d.ts +45 -0
- package/dist/users/user.d.ts +4 -0
- package/package.json +99 -131
- package/src/controllers/analytics_controller.tsx +2 -2
- package/src/controllers/auth.tsx +55 -6
- package/src/controllers/client.ts +133 -0
- package/src/controllers/collection_registry.ts +57 -0
- package/src/controllers/customization_controller.tsx +12 -1
- package/src/controllers/data.ts +191 -0
- package/src/controllers/{datasource.ts → data_driver.ts} +50 -61
- package/src/controllers/database_admin.ts +22 -0
- package/src/controllers/effective_role.ts +4 -0
- package/src/controllers/email.ts +36 -0
- package/src/controllers/index.ts +15 -5
- package/src/controllers/local_config_persistence.tsx +4 -4
- package/src/controllers/navigation.ts +13 -76
- package/src/controllers/registry.ts +65 -0
- package/src/controllers/side_entity_controller.tsx +7 -7
- package/src/controllers/storage.ts +25 -28
- package/src/index.ts +0 -1
- package/src/rebase_context.tsx +41 -39
- package/src/types/backend.ts +359 -24
- package/src/types/builders.ts +17 -0
- package/src/types/chips.ts +15 -40
- package/src/types/collections.ts +375 -383
- package/src/types/cron.ts +149 -0
- package/src/types/data_source.ts +145 -0
- package/src/types/entities.ts +40 -33
- package/src/types/entity_actions.tsx +11 -11
- package/src/types/entity_callbacks.ts +12 -12
- package/src/types/entity_link_builder.ts +1 -1
- package/src/types/entity_overrides.tsx +7 -2
- package/src/types/entity_views.tsx +77 -0
- package/src/types/export_import.ts +3 -3
- package/src/types/index.ts +10 -5
- package/src/types/plugins.tsx +280 -261
- package/src/types/properties.ts +163 -61
- package/src/types/property_config.tsx +11 -11
- package/src/types/relations.ts +1 -1
- package/src/types/slots.tsx +297 -0
- package/src/types/translations.ts +977 -0
- package/src/types/user_management_delegate.ts +50 -7
- package/src/types/websockets.ts +48 -0
- package/src/users/roles.ts +0 -1
- package/src/users/user.ts +5 -0
- package/dist/components/EntityFormActionsProps.d.ts +0 -17
- package/dist/components/EntityFormProps.d.ts +0 -46
- package/dist/components/PropertyPreviewProps.d.ts +0 -50
- package/dist/components/formex.d.ts +0 -40
- package/dist/components/index.d.ts +0 -3
- package/dist/controllers/datasource.d.ts +0 -179
- package/dist/types/fields.d.ts +0 -221
- package/dist/types/rebase.d.ts +0 -180
- package/src/components/EntityFormActionsProps.tsx +0 -18
- package/src/components/EntityFormProps.tsx +0 -52
- package/src/components/PropertyPreviewProps.tsx +0 -61
- package/src/components/formex.tsx +0 -46
- package/src/components/index.ts +0 -3
- package/src/types/fields.tsx +0 -298
- package/src/types/rebase.tsx +0 -211
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { Entity, EntityStatus
|
|
3
|
-
import { EntityCallbacks } from "./entity_callbacks";
|
|
4
|
-
import { Properties } from "./properties";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Entity, EntityStatus } from "./entities";
|
|
3
|
+
import type { EntityCallbacks } from "./entity_callbacks";
|
|
4
|
+
import type { Properties } from "./properties";
|
|
5
|
+
import type { ExportConfig } from "./export_import";
|
|
6
|
+
import type { EntityOverrides } from "./entity_overrides";
|
|
7
|
+
import type { User } from "../users";
|
|
8
|
+
import type { RebaseContext } from "../rebase_context";
|
|
9
|
+
import type { Relation } from "./relations";
|
|
10
|
+
import type { EntityCustomView } from "./entity_views";
|
|
11
|
+
import type { EntityAction } from "./entity_actions";
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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.
|
|
16
17
|
*
|
|
17
18
|
* @group Models
|
|
18
19
|
*/
|
|
19
|
-
export interface
|
|
20
|
+
export interface BaseEntityCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> {
|
|
20
21
|
/**
|
|
21
22
|
* You can set an alias that will be used internally instead of the `path`.
|
|
22
23
|
* The `alias` value will be used to determine the URL of the collection,
|
|
23
|
-
* while `path` will still be used in the
|
|
24
|
+
* while `path` will still be used in the driver.
|
|
24
25
|
* Note that you can use this value in reference properties too.
|
|
25
26
|
*/
|
|
26
27
|
slug: string;
|
|
@@ -39,135 +40,80 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
39
40
|
*/
|
|
40
41
|
description?: string;
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
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.
|
|
44
48
|
*/
|
|
45
|
-
|
|
49
|
+
childCollections?: () => EntityCollection<Record<string, unknown>>[];
|
|
46
50
|
/**
|
|
47
|
-
* Which
|
|
51
|
+
* Which driver handles this collection.
|
|
48
52
|
* Use this to route collections to different backends:
|
|
49
53
|
* - `"postgres"` - Route to PostgreSQL backend
|
|
50
54
|
* - `"firestore"` - Route to Firestore (client-side)
|
|
51
55
|
* - `"mongodb"` - Route to MongoDB backend
|
|
52
|
-
* - Custom IDs for your own
|
|
56
|
+
* - Custom IDs for your own driver implementations
|
|
53
57
|
*
|
|
54
|
-
* If not specified, the default
|
|
58
|
+
* If not specified, the default driver `"(default)"` is used.
|
|
55
59
|
*
|
|
56
60
|
* @example
|
|
57
|
-
* // Simple - no
|
|
61
|
+
* // Simple - no driver needed for default
|
|
58
62
|
* { slug: "products" }
|
|
59
63
|
*
|
|
60
64
|
* // Firestore collection (client-side real-time)
|
|
61
|
-
* { slug: "analytics",
|
|
65
|
+
* { slug: "analytics", driver: "firestore" }
|
|
62
66
|
*
|
|
63
|
-
* // Multiple databases within a
|
|
64
|
-
* { slug: "orders",
|
|
67
|
+
* // Multiple databases within a driver
|
|
68
|
+
* { slug: "orders", driver: "postgres", databaseId: "orders_db" }
|
|
65
69
|
*/
|
|
66
|
-
|
|
70
|
+
driver?: string;
|
|
67
71
|
/**
|
|
68
|
-
* Which database within the
|
|
72
|
+
* Which database within the driver.
|
|
69
73
|
* - For Firestore: The Firestore database ID (e.g., for multi-database projects)
|
|
70
74
|
* - For PostgreSQL: Schema or database name
|
|
71
75
|
* - For MongoDB: Database name
|
|
72
76
|
*
|
|
73
|
-
* If not specified, the default database of the
|
|
77
|
+
* If not specified, the default database of the driver is used.
|
|
74
78
|
*/
|
|
75
79
|
databaseId?: string;
|
|
76
80
|
/**
|
|
77
|
-
*
|
|
78
|
-
* When defined, the schema generator will enable RLS on the table and
|
|
79
|
-
* create the corresponding PostgreSQL policies.
|
|
80
|
-
*
|
|
81
|
-
* Supports three levels of expressiveness:
|
|
82
|
-
* 1. **Convenience shortcuts** — `ownerField`, `access`, `roles`
|
|
83
|
-
* 2. **Raw SQL** — `using` and `withCheck` for full PostgreSQL power
|
|
84
|
-
* 3. **Combined** — mix shortcuts with `roles` for common patterns
|
|
85
|
-
*
|
|
86
|
-
* The authenticated user context is available in raw SQL via:
|
|
87
|
-
* - `auth.uid()` — the current user's ID
|
|
88
|
-
* - `auth.roles()` — comma-separated app role IDs
|
|
89
|
-
* - `auth.jwt()` — full JWT claims as JSONB
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* // Simple: only owners can access their own rows
|
|
93
|
-
* securityRules: [
|
|
94
|
-
* { operation: "all", ownerField: "user_id" }
|
|
95
|
-
* ]
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* // Public read, owner-only write (using operations array to reduce boilerplate)
|
|
99
|
-
* securityRules: [
|
|
100
|
-
* { operation: "select", access: "public" },
|
|
101
|
-
* { operations: ["insert", "update", "delete"], ownerField: "created_by" }
|
|
102
|
-
* ]
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* // Role-based: admins read all rows, users read own
|
|
106
|
-
* securityRules: [
|
|
107
|
-
* { operation: "select", roles: ["admin"], using: "true" },
|
|
108
|
-
* { operation: "all", ownerField: "user_id" }
|
|
109
|
-
* ]
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* // Raw SQL: cross-table check with subquery
|
|
113
|
-
* securityRules: [
|
|
114
|
-
* {
|
|
115
|
-
* operation: "select",
|
|
116
|
-
* using: "EXISTS (SELECT 1 FROM org_members WHERE org_members.org_id = {org_id} AND org_members.user_id = auth.uid())"
|
|
117
|
-
* }
|
|
118
|
-
* ]
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* // Restrictive policy with both USING and WITH CHECK to constrain old AND new row states
|
|
122
|
-
* securityRules: [
|
|
123
|
-
* { operation: "all", ownerField: "user_id" },
|
|
124
|
-
* { operation: "update", mode: "restrictive", using: "{is_locked} = false", withCheck: "{is_locked} = false" }
|
|
125
|
-
* ]
|
|
126
|
-
*/
|
|
127
|
-
securityRules?: SecurityRule[];
|
|
128
|
-
/**
|
|
129
|
-
* If this collection is a top level navigation entry, you can set this
|
|
130
|
-
* property to `true` to indicate that this collection is a collection group.
|
|
81
|
+
* Set of properties that compose an entity
|
|
131
82
|
*/
|
|
132
|
-
|
|
83
|
+
properties: Properties;
|
|
133
84
|
/**
|
|
134
|
-
* Icon
|
|
135
|
-
* You can use any of the icons in the Material specs:
|
|
136
|
-
* https://fonts.google.com/icons
|
|
137
|
-
* e.g. 'account_tree' or 'person'.
|
|
138
|
-
* Find all the icons in https://rebase.pro/docs/icons
|
|
139
|
-
* You can also pass a React node if you want to render a custom icon.
|
|
140
|
-
* If not specified, a default icon will be used.
|
|
85
|
+
* Icon for the navigation sidebar or cards.
|
|
141
86
|
*/
|
|
142
87
|
icon?: string | React.ReactNode;
|
|
143
88
|
/**
|
|
144
|
-
*
|
|
145
|
-
* navigation view. If you set this value in a subcollection it has no
|
|
146
|
-
* effect.
|
|
147
|
-
* @deprecated This prop is deprecated and will be removed in the future.
|
|
148
|
-
* You can apply grouping by using the `navigationGroupMappings` prop in the
|
|
149
|
-
* {@link useBuildNavigationController} hook instead.
|
|
89
|
+
* Navigation group for this collection.
|
|
150
90
|
*/
|
|
151
91
|
group?: string;
|
|
152
92
|
/**
|
|
153
|
-
*
|
|
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`.
|
|
154
95
|
*/
|
|
155
|
-
|
|
96
|
+
entityViews?: (string | EntityCustomView<Record<string, unknown>>)[];
|
|
156
97
|
/**
|
|
157
98
|
* Default preview properties displayed when this collection is referenced to.
|
|
158
99
|
*/
|
|
159
100
|
previewProperties?: string[];
|
|
101
|
+
/**
|
|
102
|
+
* Properties to display as columns in the list view.
|
|
103
|
+
* If not specified, the list view uses a smart default (Title, Status, Date).
|
|
104
|
+
*/
|
|
105
|
+
listProperties?: string[];
|
|
160
106
|
/**
|
|
161
107
|
* Title property of the entity. This is the property that will be used
|
|
162
108
|
* as the title in entity related views and references.
|
|
163
109
|
* If not specified, the first property simple text property will be used.
|
|
164
110
|
*/
|
|
165
|
-
titleProperty?: Extract<keyof M, string
|
|
111
|
+
readonly titleProperty?: Extract<keyof M, string> | (string & {});
|
|
166
112
|
/**
|
|
167
113
|
* When editing an entity, you can choose to open the entity in a side dialog
|
|
168
114
|
* or in a full screen dialog. Defaults to `full_screen`.
|
|
169
115
|
*/
|
|
170
|
-
openEntityMode?: "side_panel" | "full_screen";
|
|
116
|
+
openEntityMode?: "side_panel" | "full_screen" | "split";
|
|
171
117
|
/**
|
|
172
118
|
* Order in which the properties are displayed.
|
|
173
119
|
* If you are specifying your collection as code, the order is the same as the
|
|
@@ -182,14 +128,12 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
182
128
|
* - If you have subcollections, you get a column for each subcollection,
|
|
183
129
|
* with the path (or alias) as the subcollection, prefixed with
|
|
184
130
|
* `subcollection:`. e.g. `subcollection:orders`.
|
|
185
|
-
* - If you are using a collection group, you will also have an
|
|
186
|
-
* additional `collectionGroupParent` column.
|
|
187
131
|
* You can use this prop to hide some properties from the table view.
|
|
188
132
|
* Note that if you set this prop, other ways to hide fields, like
|
|
189
133
|
* `hidden` in the property definition,will be ignored.
|
|
190
134
|
* `propertiesOrder` has precedence over `hidden`.
|
|
191
135
|
*/
|
|
192
|
-
propertiesOrder?: (Extract<keyof M, string> | string | `subcollection:${string}`
|
|
136
|
+
propertiesOrder?: (Extract<keyof M, string> | (string & {}) | string | `subcollection:${string}`)[];
|
|
193
137
|
/**
|
|
194
138
|
* If enabled, content is loaded in batches. If `false` all entities in the
|
|
195
139
|
* collection are loaded. This means that when reaching the end of the
|
|
@@ -199,54 +143,12 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
199
143
|
*/
|
|
200
144
|
pagination?: boolean | number;
|
|
201
145
|
selectionEnabled?: boolean;
|
|
202
|
-
/**
|
|
203
|
-
* You can add subcollections to your entity in the same way you define the root
|
|
204
|
-
* collections. The collections added here will be displayed when opening
|
|
205
|
-
* the side dialog of an entity.
|
|
206
|
-
*/
|
|
207
|
-
subcollections?: () => EntityCollection<any>[];
|
|
208
|
-
/**
|
|
209
|
-
* For SQL databases, you can define the relations between collections here.
|
|
210
|
-
*/
|
|
211
|
-
relations?: Relation[];
|
|
212
146
|
/**
|
|
213
147
|
* This interface defines all the callbacks that can be used when an entity
|
|
214
148
|
* is being created, updated or deleted.
|
|
215
149
|
* Useful for adding your own logic or blocking the execution of the operation.
|
|
216
150
|
*/
|
|
217
|
-
callbacks?: EntityCallbacks<M, USER>;
|
|
218
|
-
/**
|
|
219
|
-
* Builder for rendering additional components such as buttons in the
|
|
220
|
-
* collection toolbar
|
|
221
|
-
*/
|
|
222
|
-
Actions?: React.ComponentType<CollectionActionsProps> | React.ComponentType<CollectionActionsProps>[];
|
|
223
|
-
/**
|
|
224
|
-
* You can define additional actions that can be performed on the entities
|
|
225
|
-
* in this collection. These actions can be displayed in the collection
|
|
226
|
-
* view or in the entity view.
|
|
227
|
-
*
|
|
228
|
-
* You can use the `onClick` method to implement your own logic.
|
|
229
|
-
* In the `context` prop you can access all the controllers of Rebase.
|
|
230
|
-
*
|
|
231
|
-
* ```
|
|
232
|
-
* const archiveEntityAction: EntityAction = {
|
|
233
|
-
* icon: <ArchiveIcon/>,
|
|
234
|
-
* name: "Archive",
|
|
235
|
-
* onClick({
|
|
236
|
-
* entity,
|
|
237
|
-
* collection,
|
|
238
|
-
* context,
|
|
239
|
-
* }): Promise<void> {
|
|
240
|
-
* // Add your code here
|
|
241
|
-
* return Promise.resolve(undefined);
|
|
242
|
-
* }
|
|
243
|
-
* }
|
|
244
|
-
* ```
|
|
245
|
-
*
|
|
246
|
-
* You can also pass the action as a string that represents the `key`, in which case it will
|
|
247
|
-
* use the action defined in the main configuration under `entityActions`.
|
|
248
|
-
*/
|
|
249
|
-
entityActions?: (EntityAction<M, USER> | string)[];
|
|
151
|
+
readonly callbacks?: EntityCallbacks<M, USER>;
|
|
250
152
|
/**
|
|
251
153
|
* Pass your own selection controller if you want to control selected
|
|
252
154
|
* entities externally.
|
|
@@ -256,36 +158,29 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
256
158
|
/**
|
|
257
159
|
* Force a filter in this view. If applied, the rest of the filters will
|
|
258
160
|
* be disabled. Filters applied with this prop cannot be changed.
|
|
259
|
-
* e.g. `forceFilter: { age: ["
|
|
161
|
+
* e.g. `forceFilter: { age: [">", 18] }`
|
|
260
162
|
* e.g. `forceFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
|
|
261
163
|
*/
|
|
262
|
-
forceFilter?: FilterValues<Extract<keyof M, string
|
|
164
|
+
readonly forceFilter?: FilterValues<Extract<keyof M, string> | (string & {})>;
|
|
263
165
|
/**
|
|
264
166
|
* Initial filters applied to the collection this collection is related to.
|
|
265
167
|
* Defaults to none. Filters applied with this prop can be changed.
|
|
266
|
-
* e.g. `filter: { age: ["
|
|
168
|
+
* e.g. `filter: { age: [">", 18] }`
|
|
267
169
|
* e.g. `filter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
|
|
268
170
|
*/
|
|
269
|
-
filter?: FilterValues<Extract<keyof M, string
|
|
171
|
+
readonly filter?: FilterValues<Extract<keyof M, string> | (string & {})>;
|
|
270
172
|
/**
|
|
271
173
|
* Default sort applied to this collection.
|
|
272
174
|
* When setting this prop, entities will have a default order
|
|
273
175
|
* applied in the collection.
|
|
274
176
|
* e.g. `sort: ["order", "asc"]`
|
|
275
177
|
*/
|
|
276
|
-
sort?: [Extract<keyof M, string
|
|
277
|
-
/**
|
|
278
|
-
* Array of builders for rendering additional panels in an entity view.
|
|
279
|
-
* Useful if you need to render custom views.
|
|
280
|
-
* You can either define the custom view inline or pass a reference to
|
|
281
|
-
* a custom view defined in the main configuration under `entityViews`
|
|
282
|
-
*/
|
|
283
|
-
entityViews?: (string | EntityCustomView<M>)[];
|
|
178
|
+
readonly sort?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"];
|
|
284
179
|
/**
|
|
285
180
|
* You can add additional fields to the collection view by implementing
|
|
286
181
|
* an additional field delegate.
|
|
287
182
|
*/
|
|
288
|
-
additionalFields?: AdditionalFieldDelegate<M, USER>[];
|
|
183
|
+
readonly additionalFields?: AdditionalFieldDelegate<M, USER>[];
|
|
289
184
|
/**
|
|
290
185
|
* Default size of the rendered collection
|
|
291
186
|
*/
|
|
@@ -372,7 +267,7 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
372
267
|
localChangesBackup?: "manual_apply" | "auto_apply" | false;
|
|
373
268
|
/**
|
|
374
269
|
* Default view mode for displaying this collection.
|
|
375
|
-
* - "table": Display entities in a
|
|
270
|
+
* - "table": Display entities in a table with inline editing (default)
|
|
376
271
|
* - "cards": Display entities as a grid of cards with thumbnails
|
|
377
272
|
* - "kanban": Display entities in a Kanban board grouped by a property
|
|
378
273
|
* Defaults to "table".
|
|
@@ -393,31 +288,155 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
393
288
|
kanban?: KanbanConfig<M>;
|
|
394
289
|
/**
|
|
395
290
|
* Property key to use for ordering items.
|
|
396
|
-
* Must reference a
|
|
397
|
-
* this property will be updated
|
|
398
|
-
*
|
|
291
|
+
* Must reference a string/text property. When items are reordered,
|
|
292
|
+
* this property will be updated with lexicographic sort keys
|
|
293
|
+
* (e.g. "a0", "a1", "a0V") using string-based fractional indexing.
|
|
294
|
+
* Used by Kanban view for ordering within columns
|
|
399
295
|
* and can be used for general ordering purposes.
|
|
400
296
|
*/
|
|
401
|
-
orderProperty?: Extract<keyof M, string
|
|
297
|
+
readonly orderProperty?: Extract<keyof M, string> | (string & {});
|
|
298
|
+
/**
|
|
299
|
+
* Actions that can be performed on the entities in this collection.
|
|
300
|
+
*/
|
|
301
|
+
entityActions?: EntityAction<M, USER>[];
|
|
302
|
+
/**
|
|
303
|
+
* Builder for the collection actions rendered in the toolbar
|
|
304
|
+
*/
|
|
305
|
+
Actions?: React.ComponentType<any>[];
|
|
402
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* A collection backed by PostgreSQL (or any SQL database).
|
|
309
|
+
* Adds support for SQL-style relations (JOINs) and Row Level Security.
|
|
310
|
+
*
|
|
311
|
+
* Use this type instead of {@link EntityCollection} when you want
|
|
312
|
+
* compile-time safety that only SQL-relevant fields appear.
|
|
313
|
+
*
|
|
314
|
+
* @group Models
|
|
315
|
+
*/
|
|
316
|
+
export interface PostgresCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> extends BaseEntityCollection<M, USER> {
|
|
317
|
+
/**
|
|
318
|
+
* The driver for this collection. For Postgres collections this
|
|
319
|
+
* can be omitted (Postgres is the default) or set to `"postgres"`.
|
|
320
|
+
*/
|
|
321
|
+
driver?: "postgres" | undefined;
|
|
322
|
+
/**
|
|
323
|
+
* The PostgreSQL table name for this collection.
|
|
324
|
+
*/
|
|
325
|
+
table: string;
|
|
326
|
+
/**
|
|
327
|
+
* For SQL databases, you can define the relations between collections here.
|
|
328
|
+
* Relations describe JOINs, foreign keys, and junction tables.
|
|
329
|
+
*/
|
|
330
|
+
relations?: Relation[];
|
|
331
|
+
/**
|
|
332
|
+
* Security rules for this collection (Supabase-style Row Level Security).
|
|
333
|
+
* When defined, the schema generator will enable RLS on the table and
|
|
334
|
+
* create the corresponding PostgreSQL policies.
|
|
335
|
+
*
|
|
336
|
+
* Supports three levels of expressiveness:
|
|
337
|
+
* 1. **Convenience shortcuts** — `ownerField`, `access`, `roles`
|
|
338
|
+
* 2. **Raw SQL** — `using` and `withCheck` for full PostgreSQL power
|
|
339
|
+
* 3. **Combined** — mix shortcuts with `roles` for common patterns
|
|
340
|
+
*
|
|
341
|
+
* The authenticated user context is available in raw SQL via:
|
|
342
|
+
* - `auth.uid()` — the current user's ID
|
|
343
|
+
* - `auth.roles()` — comma-separated app role IDs
|
|
344
|
+
* - `auth.jwt()` — full JWT claims as JSONB
|
|
345
|
+
*/
|
|
346
|
+
securityRules?: SecurityRule[];
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* A collection backed by Firebase / Firestore.
|
|
350
|
+
* Adds support for subcollections (nested document collections).
|
|
351
|
+
*
|
|
352
|
+
* Use this type instead of {@link EntityCollection} when you want
|
|
353
|
+
* compile-time safety that only Firestore-relevant fields appear.
|
|
354
|
+
*
|
|
355
|
+
* @group Models
|
|
356
|
+
*/
|
|
357
|
+
export interface FirebaseCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> extends BaseEntityCollection<M, USER> {
|
|
358
|
+
/**
|
|
359
|
+
* The driver for this collection. Must be set to `"firestore"`.
|
|
360
|
+
*/
|
|
361
|
+
driver: "firestore";
|
|
362
|
+
/**
|
|
363
|
+
* You can add subcollections to your entity in the same way you define the root
|
|
364
|
+
* collections. The collections added here will be displayed when opening
|
|
365
|
+
* the side dialog of an entity.
|
|
366
|
+
*/
|
|
367
|
+
subcollections?: () => EntityCollection<Record<string, unknown>>[];
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* A collection backed by MongoDB.
|
|
371
|
+
*
|
|
372
|
+
* Use this type instead of {@link EntityCollection} when you want
|
|
373
|
+
* compile-time safety that only MongoDB-relevant fields appear.
|
|
374
|
+
*
|
|
375
|
+
* @group Models
|
|
376
|
+
*/
|
|
377
|
+
export interface MongoDBCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> extends BaseEntityCollection<M, USER> {
|
|
378
|
+
/**
|
|
379
|
+
* The driver for this collection. Must be set to `"mongodb"`.
|
|
380
|
+
*/
|
|
381
|
+
driver: "mongodb";
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* A collection backed by any data source.
|
|
385
|
+
* This is a discriminated union — use {@link PostgresCollection},
|
|
386
|
+
* {@link FirebaseCollection}, or {@link MongoDBCollection} for
|
|
387
|
+
* driver-specific type safety.
|
|
388
|
+
*
|
|
389
|
+
* @group Models
|
|
390
|
+
*/
|
|
391
|
+
export type EntityCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = PostgresCollection<M, USER> | FirebaseCollection<M, USER> | MongoDBCollection<M, USER>;
|
|
392
|
+
/** An EntityCollection that supports SQL-style relations (e.g. Postgres). */
|
|
393
|
+
export type CollectionWithRelations<M extends Record<string, unknown> = Record<string, unknown>> = EntityCollection<M> & {
|
|
394
|
+
table?: string;
|
|
395
|
+
relations?: Relation[];
|
|
396
|
+
securityRules?: SecurityRule[];
|
|
397
|
+
};
|
|
398
|
+
/** An EntityCollection that supports subcollections (e.g. Firestore). */
|
|
399
|
+
export type CollectionWithSubcollections<M extends Record<string, unknown> = Record<string, unknown>> = EntityCollection<M> & {
|
|
400
|
+
subcollections?: () => EntityCollection<Record<string, unknown>>[];
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* Type guard for PostgreSQL collections.
|
|
404
|
+
* Returns true if the collection uses the Postgres driver (or the default driver).
|
|
405
|
+
* @group Models
|
|
406
|
+
*/
|
|
407
|
+
export declare function isPostgresCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>(collection: EntityCollection<M, USER>): collection is PostgresCollection<M, USER>;
|
|
408
|
+
/**
|
|
409
|
+
* Type guard for Firebase / Firestore collections.
|
|
410
|
+
* @group Models
|
|
411
|
+
*/
|
|
412
|
+
export declare function isFirebaseCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>(collection: EntityCollection<M, USER>): collection is FirebaseCollection<M, USER>;
|
|
413
|
+
/**
|
|
414
|
+
* Type guard for MongoDB collections.
|
|
415
|
+
* @group Models
|
|
416
|
+
*/
|
|
417
|
+
export declare function isMongoDBCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>(collection: EntityCollection<M, USER>): collection is MongoDBCollection<M, USER>;
|
|
403
418
|
/**
|
|
404
419
|
* Configuration for Kanban board view mode.
|
|
405
420
|
* @group Collections
|
|
406
421
|
*/
|
|
407
|
-
export interface KanbanConfig<M extends Record<string,
|
|
422
|
+
export interface KanbanConfig<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
408
423
|
/**
|
|
409
424
|
* Property key to use for Kanban board columns.
|
|
410
425
|
* Must reference a string property with enumValues defined.
|
|
411
426
|
* Entities will be grouped into columns based on this property's value.
|
|
412
427
|
* The column order is determined by the order of enumValues in the property.
|
|
413
428
|
*/
|
|
414
|
-
columnProperty: Extract<keyof M, string
|
|
429
|
+
columnProperty: Extract<keyof M, string> | (string & {});
|
|
415
430
|
}
|
|
416
431
|
/**
|
|
417
432
|
* View mode for displaying a collection.
|
|
433
|
+
* - "list": Simple, clean list view — the classic CMS default
|
|
434
|
+
* - "table": Table with inline editing
|
|
435
|
+
* - "cards": Grid of visual cards with thumbnails
|
|
436
|
+
* - "kanban": Board view grouped by a property
|
|
418
437
|
* @group Collections
|
|
419
438
|
*/
|
|
420
|
-
export type ViewMode = "table" | "cards" | "kanban";
|
|
439
|
+
export type ViewMode = "list" | "table" | "cards" | "kanban";
|
|
421
440
|
/**
|
|
422
441
|
* Parameter passed to the `Actions` prop in the collection configuration.
|
|
423
442
|
* The component will receive this prop when it is rendered in the collection
|
|
@@ -425,7 +444,7 @@ export type ViewMode = "table" | "cards" | "kanban";
|
|
|
425
444
|
*
|
|
426
445
|
* @group Models
|
|
427
446
|
*/
|
|
428
|
-
export interface CollectionActionsProps<M extends Record<string,
|
|
447
|
+
export interface CollectionActionsProps<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User, EC extends EntityCollection<M> = EntityCollection<M>> {
|
|
429
448
|
/**
|
|
430
449
|
* Full collection path of this entity. This is the full path, like
|
|
431
450
|
* `users/1234/addresses`
|
|
@@ -468,12 +487,13 @@ export interface CollectionActionsProps<M extends Record<string, any> = any, USE
|
|
|
468
487
|
* an {@link EntityCollection}
|
|
469
488
|
* @group Models
|
|
470
489
|
*/
|
|
471
|
-
export
|
|
490
|
+
export interface SelectionController<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
472
491
|
selectedEntities: Entity<M>[];
|
|
473
|
-
setSelectedEntities:
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
492
|
+
setSelectedEntities(entities: Entity<M>[]): void;
|
|
493
|
+
setSelectedEntities(action: (prev: Entity<M>[]) => Entity<M>[]): void;
|
|
494
|
+
isEntitySelected(entity: Entity<M>): boolean;
|
|
495
|
+
toggleEntitySelection(entity: Entity<M>, newSelectedState?: boolean): void;
|
|
496
|
+
}
|
|
477
497
|
/**
|
|
478
498
|
* Filter conditions in a `Query.where()` clause are specified using the
|
|
479
499
|
* strings `<`, `<=`, `==`, `>=`, `>`, `array-contains`, `in`, and `array-contains-any`.
|
|
@@ -487,7 +507,7 @@ export type WhereFilterOp = "<" | "<=" | "==" | "!=" | ">=" | ">" | "array-conta
|
|
|
487
507
|
*
|
|
488
508
|
* @group Models
|
|
489
509
|
*/
|
|
490
|
-
export type FilterValues<Key extends string> = Partial<Record<Key, [WhereFilterOp,
|
|
510
|
+
export type FilterValues<Key extends string> = Partial<Record<Key, [WhereFilterOp, unknown]>>;
|
|
491
511
|
/**
|
|
492
512
|
* Used to indicate valid filter combinations (e.g. created in Firestore)
|
|
493
513
|
* If the user selects a specific filter/sort combination, the CMS checks if it's
|
|
@@ -500,7 +520,7 @@ export type FilterCombination<Key extends string> = Partial<Record<Key, "asc" |
|
|
|
500
520
|
* @group Models
|
|
501
521
|
*/
|
|
502
522
|
export type CollectionSize = "xs" | "s" | "m" | "l" | "xl";
|
|
503
|
-
export type AdditionalFieldDelegateProps<M extends Record<string,
|
|
523
|
+
export type AdditionalFieldDelegateProps<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = {
|
|
504
524
|
entity: Entity<M>;
|
|
505
525
|
context: RebaseContext<USER>;
|
|
506
526
|
};
|
|
@@ -508,7 +528,7 @@ export type AdditionalFieldDelegateProps<M extends Record<string, any> = any, US
|
|
|
508
528
|
* Use this interface for adding additional fields to entity collection views and forms.
|
|
509
529
|
* @group Models
|
|
510
530
|
*/
|
|
511
|
-
export interface AdditionalFieldDelegate<M extends Record<string,
|
|
531
|
+
export interface AdditionalFieldDelegate<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> {
|
|
512
532
|
/**
|
|
513
533
|
* ID of this column. You can use this id in the `properties` field of the
|
|
514
534
|
* collection in any order you want
|
|
@@ -523,9 +543,12 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any, US
|
|
|
523
543
|
*/
|
|
524
544
|
width?: number;
|
|
525
545
|
/**
|
|
526
|
-
* Builder for the
|
|
546
|
+
* Builder for the custom field
|
|
527
547
|
*/
|
|
528
|
-
Builder
|
|
548
|
+
Builder?(props: {
|
|
549
|
+
entity: Entity<M>;
|
|
550
|
+
context: RebaseContext<USER>;
|
|
551
|
+
}): React.ReactNode;
|
|
529
552
|
/**
|
|
530
553
|
* If this column needs to update dynamically based on other properties,
|
|
531
554
|
* you can define an array of keys as strings with the
|
|
@@ -534,7 +557,7 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any, US
|
|
|
534
557
|
* This is a performance optimization, if you don't define dependencies
|
|
535
558
|
* it will be updated in every render.
|
|
536
559
|
*/
|
|
537
|
-
dependencies?: Extract<keyof M, string
|
|
560
|
+
dependencies?: NoInfer<Extract<keyof M, string>> | NoInfer<Extract<keyof M, string>>[] | (string & {}) | (string & {})[];
|
|
538
561
|
/**
|
|
539
562
|
* Use this prop to define the value of the column as a string or number.
|
|
540
563
|
* This is the value that will be used for exporting the collection.
|
|
@@ -542,73 +565,10 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any, US
|
|
|
542
565
|
* view.
|
|
543
566
|
* @param entity
|
|
544
567
|
*/
|
|
545
|
-
value
|
|
568
|
+
value?(props: {
|
|
546
569
|
entity: Entity<M>;
|
|
547
570
|
context: RebaseContext;
|
|
548
|
-
})
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* You can use this builder to render a custom panel in the entity detail view.
|
|
552
|
-
* It gets rendered as a tab.
|
|
553
|
-
* @group Models
|
|
554
|
-
*/
|
|
555
|
-
export type EntityCustomView<M extends Record<string, any> = any> = {
|
|
556
|
-
/**
|
|
557
|
-
* Key of this custom view.
|
|
558
|
-
*/
|
|
559
|
-
key: string;
|
|
560
|
-
/**
|
|
561
|
-
* Name of this custom view.
|
|
562
|
-
*/
|
|
563
|
-
name: string;
|
|
564
|
-
/**
|
|
565
|
-
* Render this custom view in the tab of the entity view, instead of the name
|
|
566
|
-
*/
|
|
567
|
-
tabComponent?: React.ReactNode;
|
|
568
|
-
/**
|
|
569
|
-
* If set to true, the actions of the entity (save, discard,delete) will be
|
|
570
|
-
* included in the view. By default the actions are located in the right or bottom,
|
|
571
|
-
* based on the screen size. You can force the actions to be located at the bottom
|
|
572
|
-
* by setting this prop to "bottom".
|
|
573
|
-
*/
|
|
574
|
-
includeActions?: boolean | "bottom";
|
|
575
|
-
/**
|
|
576
|
-
* Builder for rendering the custom view
|
|
577
|
-
*/
|
|
578
|
-
Builder?: React.ComponentType<EntityCustomViewParams<M>>;
|
|
579
|
-
/**
|
|
580
|
-
* Position of this tab in the entity view. Defaults to `end`.
|
|
581
|
-
*/
|
|
582
|
-
position?: "start" | "end";
|
|
583
|
-
};
|
|
584
|
-
/**
|
|
585
|
-
* Parameters passed to the builder in charge of rendering a custom panel for
|
|
586
|
-
* an entity view.
|
|
587
|
-
* @group Models
|
|
588
|
-
*/
|
|
589
|
-
export interface EntityCustomViewParams<M extends Record<string, any> = any> {
|
|
590
|
-
/**
|
|
591
|
-
* collection used by this entity
|
|
592
|
-
*/
|
|
593
|
-
collection: EntityCollection<M>;
|
|
594
|
-
/**
|
|
595
|
-
* Entity that this view refers to. It can be undefined if the entity is new
|
|
596
|
-
*/
|
|
597
|
-
entity?: Entity<M>;
|
|
598
|
-
/**
|
|
599
|
-
* Modified values in the form that have not been saved yet.
|
|
600
|
-
* If the entity is not new and the values are not modified, these values
|
|
601
|
-
* are the same as in `entity`
|
|
602
|
-
*/
|
|
603
|
-
modifiedValues?: EntityValues<M>;
|
|
604
|
-
/**
|
|
605
|
-
* Use the form context to access the form state and methods
|
|
606
|
-
*/
|
|
607
|
-
formContext: FormContext;
|
|
608
|
-
/**
|
|
609
|
-
* If this is a subcollection, this is the path of the parent collections
|
|
610
|
-
*/
|
|
611
|
-
parentCollectionIds?: string[];
|
|
571
|
+
}): string | number | Promise<string | number> | undefined;
|
|
612
572
|
}
|
|
613
573
|
export type InferCollectionType<S extends EntityCollection> = S extends EntityCollection<infer M> ? M : never;
|
|
614
574
|
/**
|
|
@@ -627,15 +587,15 @@ export type DefaultSelectedViewParams = {
|
|
|
627
587
|
/**
|
|
628
588
|
* You can use this controller to control the table view of a collection.
|
|
629
589
|
*/
|
|
630
|
-
export type EntityTableController<M extends Record<string,
|
|
590
|
+
export type EntityTableController<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
631
591
|
data: Entity<M>[];
|
|
632
592
|
dataLoading: boolean;
|
|
633
593
|
noMoreToLoad: boolean;
|
|
634
594
|
dataLoadingError?: Error;
|
|
635
|
-
filterValues?: FilterValues<Extract<keyof M, string
|
|
636
|
-
setFilterValues?: (filterValues: FilterValues<Extract<keyof M, string
|
|
637
|
-
sortBy?: [Extract<keyof M, string
|
|
638
|
-
setSortBy?: (sortBy?: [Extract<keyof M, string
|
|
595
|
+
filterValues?: FilterValues<Extract<keyof M, string> | (string & {})>;
|
|
596
|
+
setFilterValues?: (filterValues: FilterValues<Extract<keyof M, string> | (string & {})>) => void;
|
|
597
|
+
sortBy?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"];
|
|
598
|
+
setSortBy?: (sortBy?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"]) => void;
|
|
639
599
|
searchString?: string;
|
|
640
600
|
setSearchString?: (searchString?: string) => void;
|
|
641
601
|
clearFilter?: () => void;
|
|
@@ -649,13 +609,13 @@ export type EntityTableController<M extends Record<string, any> = any> = {
|
|
|
649
609
|
}) => void;
|
|
650
610
|
paginationEnabled?: boolean;
|
|
651
611
|
pageSize?: number;
|
|
652
|
-
checkFilterCombination?: (filterValues: FilterValues<
|
|
612
|
+
checkFilterCombination?: (filterValues: FilterValues<string>, sortBy?: [string, "asc" | "desc"]) => boolean;
|
|
653
613
|
popupCell?: SelectedCellProps<M>;
|
|
654
614
|
setPopupCell?: (popupCell?: SelectedCellProps<M>) => void;
|
|
655
615
|
onAddColumn?: (column: string) => void;
|
|
656
616
|
};
|
|
657
|
-
export type SelectedCellProps<M extends Record<string,
|
|
658
|
-
propertyKey: Extract<keyof M, string
|
|
617
|
+
export type SelectedCellProps<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
618
|
+
propertyKey: Extract<keyof M, string> | (string & {});
|
|
659
619
|
cellRect: DOMRect;
|
|
660
620
|
width: number;
|
|
661
621
|
height: number;
|
|
@@ -685,9 +645,18 @@ export type SecurityOperation = "select" | "insert" | "update" | "delete" | "all
|
|
|
685
645
|
* operation. Permissive rules are OR'd together (any one passing is enough).
|
|
686
646
|
* Restrictive rules are AND'd (all must pass). This mirrors Supabase behavior.
|
|
687
647
|
*
|
|
648
|
+
* **Mutual exclusivity:** `ownerField`, `access`, and raw SQL (`using`/`withCheck`)
|
|
649
|
+
* cannot be combined. The type system enforces this — attempting to set
|
|
650
|
+
* conflicting fields will produce a compile-time error.
|
|
651
|
+
*
|
|
652
|
+
* @group Models
|
|
653
|
+
*/
|
|
654
|
+
export type SecurityRule = OwnerSecurityRule | PublicSecurityRule | RawSQLSecurityRule | RolesOnlySecurityRule;
|
|
655
|
+
/**
|
|
656
|
+
* Shared fields for all SecurityRule variants.
|
|
688
657
|
* @group Models
|
|
689
658
|
*/
|
|
690
|
-
export interface
|
|
659
|
+
export interface SecurityRuleBase {
|
|
691
660
|
/**
|
|
692
661
|
* Optional human-readable name for the policy.
|
|
693
662
|
* If not provided, one will be auto-generated from the table name and operation.
|
|
@@ -739,41 +708,12 @@ export interface SecurityRule {
|
|
|
739
708
|
* @default "permissive"
|
|
740
709
|
*/
|
|
741
710
|
mode?: "permissive" | "restrictive";
|
|
742
|
-
/**
|
|
743
|
-
* **Shortcut.** The property (column) that stores the owner's user ID.
|
|
744
|
-
* Generates a USING/WITH CHECK clause like:
|
|
745
|
-
* `<column> = auth.uid()`
|
|
746
|
-
*
|
|
747
|
-
* Cannot be combined with `using` / `withCheck` / `access`.
|
|
748
|
-
*
|
|
749
|
-
* @example
|
|
750
|
-
* { operation: "all", ownerField: "user_id" }
|
|
751
|
-
*/
|
|
752
|
-
ownerField?: string;
|
|
753
|
-
/**
|
|
754
|
-
* **Shortcut.** Grant unrestricted row access (no row filtering) for this operation.
|
|
755
|
-
* Generates `USING (true)`.
|
|
756
|
-
*
|
|
757
|
-
* This means "no row-level filter", NOT "anonymous/unauthenticated access".
|
|
758
|
-
* Authentication is still enforced at the API layer — this only controls which
|
|
759
|
-
* *rows* authenticated users can see.
|
|
760
|
-
*
|
|
761
|
-
* Typically used alone for genuinely public read endpoints, or combined with
|
|
762
|
-
* `roles` to give certain roles an unfiltered view of the table.
|
|
763
|
-
*
|
|
764
|
-
* Cannot be combined with `using` / `withCheck` / `ownerField`.
|
|
765
|
-
*
|
|
766
|
-
* @example
|
|
767
|
-
* // Public read (any authenticated user sees all rows)
|
|
768
|
-
* { operation: "select", access: "public" }
|
|
769
|
-
*/
|
|
770
|
-
access?: "public";
|
|
771
711
|
/**
|
|
772
712
|
* **Shortcut.** Restrict this rule to users that have one of these
|
|
773
713
|
* application-level roles.
|
|
774
714
|
*
|
|
775
715
|
* **Important:** These are NOT native PostgreSQL database roles. They are
|
|
776
|
-
* application roles managed by Rebase, stored in the `
|
|
716
|
+
* application roles managed by Rebase, stored in the `rebase.user_roles`
|
|
777
717
|
* table, and injected into each transaction via `auth.roles()`.
|
|
778
718
|
*
|
|
779
719
|
* Generates a condition like:
|
|
@@ -791,77 +731,6 @@ export interface SecurityRule {
|
|
|
791
731
|
* { operation: "select", roles: ["admin"], using: "true" }
|
|
792
732
|
*/
|
|
793
733
|
roles?: string[];
|
|
794
|
-
/**
|
|
795
|
-
* Raw SQL expression for the `USING` clause.
|
|
796
|
-
* This controls which *existing* rows are visible / can be modified / deleted.
|
|
797
|
-
* Applied to SELECT, UPDATE, and DELETE.
|
|
798
|
-
*
|
|
799
|
-
* You can reference columns via `{column_name}` which will be resolved to
|
|
800
|
-
* `table.column_name` in the generated Drizzle code. You can also use any
|
|
801
|
-
* valid PostgreSQL expression.
|
|
802
|
-
*
|
|
803
|
-
* Cannot be combined with `ownerField` or `access`.
|
|
804
|
-
*
|
|
805
|
-
* @example
|
|
806
|
-
* // Rows published in the last 30 days are visible
|
|
807
|
-
* { operation: "select", using: "{published_at} > now() - interval '30 days'" }
|
|
808
|
-
*
|
|
809
|
-
* @example
|
|
810
|
-
* // Only the owner, or users with 'moderator' role
|
|
811
|
-
* {
|
|
812
|
-
* operation: "select",
|
|
813
|
-
* using: "{user_id} = auth.uid() OR auth.roles() ~ 'moderator'"
|
|
814
|
-
* }
|
|
815
|
-
*
|
|
816
|
-
* @example
|
|
817
|
-
* // Cross-table subquery: only if user belongs to the org
|
|
818
|
-
* {
|
|
819
|
-
* operation: "select",
|
|
820
|
-
* using: "EXISTS (SELECT 1 FROM org_members WHERE org_members.org_id = {org_id} AND org_members.user_id = auth.uid())"
|
|
821
|
-
* }
|
|
822
|
-
*/
|
|
823
|
-
using?: string;
|
|
824
|
-
/**
|
|
825
|
-
* Raw SQL expression for the `WITH CHECK` clause.
|
|
826
|
-
* This controls which *new/updated* row values are allowed.
|
|
827
|
-
* Applied to INSERT and UPDATE.
|
|
828
|
-
*
|
|
829
|
-
* Same syntax as `using` — use `{column_name}` to reference columns.
|
|
830
|
-
*
|
|
831
|
-
* **Important for UPDATE:** PostgreSQL evaluates two row states — the
|
|
832
|
-
* *existing* row (`USING`) and the *incoming new* row (`WITH CHECK`).
|
|
833
|
-
* If you only specify `using`, the same expression is used for both.
|
|
834
|
-
* For security-sensitive updates, always specify `withCheck` explicitly
|
|
835
|
-
* to constrain what the new row values can be.
|
|
836
|
-
*
|
|
837
|
-
* If not provided on INSERT/UPDATE policies, falls back to `using`
|
|
838
|
-
* (which matches PostgreSQL's own default behavior).
|
|
839
|
-
*
|
|
840
|
-
* Cannot be combined with `ownerField` or `access`.
|
|
841
|
-
*
|
|
842
|
-
* @example
|
|
843
|
-
* // Users can only insert rows where they are the owner
|
|
844
|
-
* { operation: "insert", withCheck: "{user_id} = auth.uid()" }
|
|
845
|
-
*
|
|
846
|
-
* @example
|
|
847
|
-
* // Prevent changing the status to 'archived' unless admin
|
|
848
|
-
* {
|
|
849
|
-
* operation: "update",
|
|
850
|
-
* using: "{user_id} = auth.uid()",
|
|
851
|
-
* withCheck: "{status} != 'archived' OR auth.roles() ~ 'admin'"
|
|
852
|
-
* }
|
|
853
|
-
*
|
|
854
|
-
* @example
|
|
855
|
-
* // Restrictive gate: prevent locking AND unlocking unless admin.
|
|
856
|
-
* // `using` checks the old row state, `withCheck` checks the new.
|
|
857
|
-
* {
|
|
858
|
-
* operation: "update",
|
|
859
|
-
* mode: "restrictive",
|
|
860
|
-
* using: "{is_locked} = false",
|
|
861
|
-
* withCheck: "{is_locked} = false"
|
|
862
|
-
* }
|
|
863
|
-
*/
|
|
864
|
-
withCheck?: string;
|
|
865
734
|
/**
|
|
866
735
|
* **Advanced.** Native PostgreSQL database roles the policy applies to.
|
|
867
736
|
*
|
|
@@ -885,3 +754,103 @@ export interface SecurityRule {
|
|
|
885
754
|
*/
|
|
886
755
|
pgRoles?: string[];
|
|
887
756
|
}
|
|
757
|
+
/**
|
|
758
|
+
* Security rule that grants access based on row ownership.
|
|
759
|
+
* Generates a USING/WITH CHECK clause like: `<column> = auth.uid()`
|
|
760
|
+
*
|
|
761
|
+
* Cannot be combined with `using`, `withCheck`, or `access`.
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* { operation: "all", ownerField: "user_id" }
|
|
765
|
+
*
|
|
766
|
+
* @group Models
|
|
767
|
+
*/
|
|
768
|
+
export interface OwnerSecurityRule extends SecurityRuleBase {
|
|
769
|
+
/** The property (column) that stores the owner's user ID. */
|
|
770
|
+
ownerField: string;
|
|
771
|
+
access?: never;
|
|
772
|
+
using?: never;
|
|
773
|
+
withCheck?: never;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Security rule that grants unrestricted row access (no row filtering).
|
|
777
|
+
* Generates `USING (true)`.
|
|
778
|
+
*
|
|
779
|
+
* This means "no row-level filter", NOT "anonymous/unauthenticated access".
|
|
780
|
+
* Authentication is still enforced at the API layer — this only controls which
|
|
781
|
+
* *rows* authenticated users can see.
|
|
782
|
+
*
|
|
783
|
+
* Cannot be combined with `using`, `withCheck`, or `ownerField`.
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* // Public read (any authenticated user sees all rows)
|
|
787
|
+
* { operation: "select", access: "public" }
|
|
788
|
+
*
|
|
789
|
+
* @group Models
|
|
790
|
+
*/
|
|
791
|
+
export interface PublicSecurityRule extends SecurityRuleBase {
|
|
792
|
+
/** Grant unrestricted row access for this operation. */
|
|
793
|
+
access: "public";
|
|
794
|
+
ownerField?: never;
|
|
795
|
+
using?: never;
|
|
796
|
+
withCheck?: never;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Security rule using raw SQL expressions for full PostgreSQL RLS power.
|
|
800
|
+
*
|
|
801
|
+
* Cannot be combined with `ownerField` or `access`.
|
|
802
|
+
*
|
|
803
|
+
* You can reference columns via `{column_name}` which will be resolved to
|
|
804
|
+
* `table.column_name` in the generated Drizzle code.
|
|
805
|
+
*
|
|
806
|
+
* @example
|
|
807
|
+
* // Rows published in the last 30 days are visible
|
|
808
|
+
* { operation: "select", using: "{published_at} > now() - interval '30 days'" }
|
|
809
|
+
*
|
|
810
|
+
* @example
|
|
811
|
+
* // Only the owner, or users with 'moderator' role
|
|
812
|
+
* {
|
|
813
|
+
* operation: "select",
|
|
814
|
+
* using: "{user_id} = auth.uid() OR auth.roles() ~ 'moderator'"
|
|
815
|
+
* }
|
|
816
|
+
*
|
|
817
|
+
* @group Models
|
|
818
|
+
*/
|
|
819
|
+
export interface RawSQLSecurityRule extends SecurityRuleBase {
|
|
820
|
+
/**
|
|
821
|
+
* Raw SQL expression for the `USING` clause.
|
|
822
|
+
* This controls which *existing* rows are visible / can be modified / deleted.
|
|
823
|
+
* Applied to SELECT, UPDATE, and DELETE.
|
|
824
|
+
*/
|
|
825
|
+
using: string;
|
|
826
|
+
/**
|
|
827
|
+
* Raw SQL expression for the `WITH CHECK` clause.
|
|
828
|
+
* This controls which *new/updated* row values are allowed.
|
|
829
|
+
* Applied to INSERT and UPDATE.
|
|
830
|
+
*
|
|
831
|
+
* If not provided on INSERT/UPDATE policies, falls back to `using`
|
|
832
|
+
* (which matches PostgreSQL's own default behavior).
|
|
833
|
+
*/
|
|
834
|
+
withCheck?: string;
|
|
835
|
+
ownerField?: never;
|
|
836
|
+
access?: never;
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Security rule that only filters by application roles, without any
|
|
840
|
+
* row-level condition (USING/WITH CHECK).
|
|
841
|
+
*
|
|
842
|
+
* Useful for simple "only admins can access this table" rules where
|
|
843
|
+
* no per-row filtering is needed.
|
|
844
|
+
*
|
|
845
|
+
* @example
|
|
846
|
+
* // Only admins can delete
|
|
847
|
+
* { operation: "delete", roles: ["admin"] }
|
|
848
|
+
*
|
|
849
|
+
* @group Models
|
|
850
|
+
*/
|
|
851
|
+
export interface RolesOnlySecurityRule extends SecurityRuleBase {
|
|
852
|
+
ownerField?: never;
|
|
853
|
+
access?: never;
|
|
854
|
+
using?: never;
|
|
855
|
+
withCheck?: never;
|
|
856
|
+
}
|