@rebasepro/types 0.0.1-canary.2 → 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/README.md +1 -1
- package/dist/controllers/analytics_controller.d.ts +2 -2
- package/dist/controllers/auth.d.ts +50 -6
- package/dist/controllers/client.d.ts +58 -0
- package/dist/controllers/collection_registry.d.ts +44 -0
- package/dist/controllers/customization_controller.d.ts +5 -1
- package/dist/controllers/data.d.ts +141 -0
- package/dist/controllers/{datasource.d.ts → data_driver.d.ts} +25 -36
- package/dist/controllers/database_admin.d.ts +11 -0
- package/dist/controllers/effective_role.d.ts +4 -0
- package/dist/controllers/index.d.ts +11 -5
- package/dist/controllers/navigation.d.ts +9 -58
- package/dist/controllers/registry.d.ts +51 -0
- package/dist/controllers/side_entity_controller.d.ts +1 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.es.js +113 -12
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +112 -11
- package/dist/index.umd.js.map +1 -1
- package/dist/rebase_context.d.ts +35 -25
- package/dist/types/backend.d.ts +296 -17
- package/dist/types/builders.d.ts +14 -0
- package/dist/types/collections.d.ts +166 -241
- package/dist/types/data_source.d.ts +64 -0
- package/dist/types/entities.d.ts +29 -24
- package/dist/types/entity_actions.d.ts +7 -7
- package/dist/types/entity_callbacks.d.ts +4 -4
- package/dist/types/entity_overrides.d.ts +6 -2
- package/dist/types/entity_views.d.ts +61 -0
- package/dist/types/index.d.ts +8 -5
- package/dist/types/plugins.d.ts +170 -221
- package/dist/types/properties.d.ts +17 -29
- package/dist/types/property_config.d.ts +13 -11
- package/dist/types/slots.d.ts +228 -0
- package/dist/types/translations.d.ts +826 -0
- package/dist/types/user_management_delegate.d.ts +42 -0
- package/dist/types/websockets.d.ts +45 -0
- package/dist/users/user.d.ts +4 -0
- package/package.json +7 -39
- package/src/controllers/analytics_controller.tsx +2 -2
- package/src/controllers/auth.tsx +53 -6
- package/src/controllers/client.ts +74 -0
- package/src/controllers/collection_registry.ts +53 -0
- package/src/controllers/customization_controller.tsx +6 -1
- package/src/controllers/data.ts +153 -0
- package/src/controllers/{datasource.ts → data_driver.ts} +41 -37
- package/src/controllers/database_admin.ts +22 -0
- package/src/controllers/effective_role.ts +4 -0
- package/src/controllers/index.ts +14 -5
- package/src/controllers/navigation.ts +9 -73
- package/src/controllers/registry.ts +62 -0
- package/src/controllers/side_entity_controller.tsx +1 -2
- package/src/index.ts +0 -1
- package/src/rebase_context.tsx +37 -33
- package/src/types/backend.ts +351 -19
- package/src/types/builders.ts +16 -0
- package/src/types/collections.ts +196 -259
- package/src/types/data_source.ts +156 -0
- package/src/types/entities.ts +35 -28
- package/src/types/entity_actions.tsx +6 -6
- package/src/types/entity_callbacks.ts +4 -4
- package/src/types/entity_overrides.tsx +6 -2
- package/src/types/entity_views.tsx +77 -0
- package/src/types/index.ts +9 -5
- package/src/types/plugins.tsx +198 -256
- package/src/types/properties.ts +22 -31
- package/src/types/property_config.tsx +11 -11
- package/src/types/slots.tsx +271 -0
- package/src/types/translations.ts +923 -0
- package/src/types/user_management_delegate.ts +43 -0
- package/src/types/websockets.ts +48 -0
- 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/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
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Entity, EntityStatus } from "./entities";
|
|
3
3
|
import { EntityCallbacks } from "./entity_callbacks";
|
|
4
4
|
import { Properties } from "./properties";
|
|
5
|
-
import { FormContext } from "./fields";
|
|
6
|
-
import { EntityAction } from "./entity_actions";
|
|
7
5
|
import { ExportConfig } from "./export_import";
|
|
8
6
|
import { EntityOverrides } from "./entity_overrides";
|
|
9
7
|
import { User } from "../users";
|
|
10
8
|
import { RebaseContext } from "../rebase_context";
|
|
11
9
|
import { Relation } from "./relations";
|
|
10
|
+
import { EntityCustomView } from "./entity_views";
|
|
11
|
+
import { 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,120 +40,60 @@ 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
|
*/
|
|
@@ -162,7 +103,7 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
162
103
|
* as the title in entity related views and references.
|
|
163
104
|
* If not specified, the first property simple text property will be used.
|
|
164
105
|
*/
|
|
165
|
-
titleProperty?: Extract<keyof M, string
|
|
106
|
+
readonly titleProperty?: Extract<keyof M, string> | (string & {});
|
|
166
107
|
/**
|
|
167
108
|
* When editing an entity, you can choose to open the entity in a side dialog
|
|
168
109
|
* or in a full screen dialog. Defaults to `full_screen`.
|
|
@@ -182,14 +123,12 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
182
123
|
* - If you have subcollections, you get a column for each subcollection,
|
|
183
124
|
* with the path (or alias) as the subcollection, prefixed with
|
|
184
125
|
* `subcollection:`. e.g. `subcollection:orders`.
|
|
185
|
-
* - If you are using a collection group, you will also have an
|
|
186
|
-
* additional `collectionGroupParent` column.
|
|
187
126
|
* You can use this prop to hide some properties from the table view.
|
|
188
127
|
* Note that if you set this prop, other ways to hide fields, like
|
|
189
128
|
* `hidden` in the property definition,will be ignored.
|
|
190
129
|
* `propertiesOrder` has precedence over `hidden`.
|
|
191
130
|
*/
|
|
192
|
-
propertiesOrder?: (Extract<keyof M, string> | string | `subcollection:${string}`
|
|
131
|
+
propertiesOrder?: (Extract<keyof M, string> | (string & {}) | string | `subcollection:${string}`)[];
|
|
193
132
|
/**
|
|
194
133
|
* If enabled, content is loaded in batches. If `false` all entities in the
|
|
195
134
|
* collection are loaded. This means that when reaching the end of the
|
|
@@ -199,54 +138,12 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
199
138
|
*/
|
|
200
139
|
pagination?: boolean | number;
|
|
201
140
|
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
141
|
/**
|
|
213
142
|
* This interface defines all the callbacks that can be used when an entity
|
|
214
143
|
* is being created, updated or deleted.
|
|
215
144
|
* Useful for adding your own logic or blocking the execution of the operation.
|
|
216
145
|
*/
|
|
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)[];
|
|
146
|
+
readonly callbacks?: EntityCallbacks<M, USER>;
|
|
250
147
|
/**
|
|
251
148
|
* Pass your own selection controller if you want to control selected
|
|
252
149
|
* entities externally.
|
|
@@ -256,36 +153,29 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
256
153
|
/**
|
|
257
154
|
* Force a filter in this view. If applied, the rest of the filters will
|
|
258
155
|
* be disabled. Filters applied with this prop cannot be changed.
|
|
259
|
-
* e.g. `forceFilter: { age: ["
|
|
156
|
+
* e.g. `forceFilter: { age: [">", 18] }`
|
|
260
157
|
* e.g. `forceFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
|
|
261
158
|
*/
|
|
262
|
-
forceFilter?: FilterValues<Extract<keyof M, string
|
|
159
|
+
readonly forceFilter?: FilterValues<Extract<keyof M, string> | (string & {})>;
|
|
263
160
|
/**
|
|
264
161
|
* Initial filters applied to the collection this collection is related to.
|
|
265
162
|
* Defaults to none. Filters applied with this prop can be changed.
|
|
266
|
-
* e.g. `filter: { age: ["
|
|
163
|
+
* e.g. `filter: { age: [">", 18] }`
|
|
267
164
|
* e.g. `filter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
|
|
268
165
|
*/
|
|
269
|
-
filter?: FilterValues<Extract<keyof M, string
|
|
166
|
+
readonly filter?: FilterValues<Extract<keyof M, string> | (string & {})>;
|
|
270
167
|
/**
|
|
271
168
|
* Default sort applied to this collection.
|
|
272
169
|
* When setting this prop, entities will have a default order
|
|
273
170
|
* applied in the collection.
|
|
274
171
|
* e.g. `sort: ["order", "asc"]`
|
|
275
172
|
*/
|
|
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>)[];
|
|
173
|
+
readonly sort?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"];
|
|
284
174
|
/**
|
|
285
175
|
* You can add additional fields to the collection view by implementing
|
|
286
176
|
* an additional field delegate.
|
|
287
177
|
*/
|
|
288
|
-
additionalFields?: AdditionalFieldDelegate<M, USER>[];
|
|
178
|
+
readonly additionalFields?: AdditionalFieldDelegate<M, USER>[];
|
|
289
179
|
/**
|
|
290
180
|
* Default size of the rendered collection
|
|
291
181
|
*/
|
|
@@ -398,20 +288,114 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
398
288
|
* fractional indexing. Used by Kanban view for ordering within columns
|
|
399
289
|
* and can be used for general ordering purposes.
|
|
400
290
|
*/
|
|
401
|
-
orderProperty?: Extract<keyof M, string
|
|
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[];
|
|
402
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>;
|
|
403
387
|
/**
|
|
404
388
|
* Configuration for Kanban board view mode.
|
|
405
389
|
* @group Collections
|
|
406
390
|
*/
|
|
407
|
-
export interface KanbanConfig<M extends Record<string,
|
|
391
|
+
export interface KanbanConfig<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
408
392
|
/**
|
|
409
393
|
* Property key to use for Kanban board columns.
|
|
410
394
|
* Must reference a string property with enumValues defined.
|
|
411
395
|
* Entities will be grouped into columns based on this property's value.
|
|
412
396
|
* The column order is determined by the order of enumValues in the property.
|
|
413
397
|
*/
|
|
414
|
-
columnProperty: Extract<keyof M, string
|
|
398
|
+
columnProperty: Extract<keyof M, string> | (string & {});
|
|
415
399
|
}
|
|
416
400
|
/**
|
|
417
401
|
* View mode for displaying a collection.
|
|
@@ -425,7 +409,7 @@ export type ViewMode = "table" | "cards" | "kanban";
|
|
|
425
409
|
*
|
|
426
410
|
* @group Models
|
|
427
411
|
*/
|
|
428
|
-
export interface CollectionActionsProps<M extends Record<string,
|
|
412
|
+
export interface CollectionActionsProps<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User, EC extends EntityCollection<M> = EntityCollection<M>> {
|
|
429
413
|
/**
|
|
430
414
|
* Full collection path of this entity. This is the full path, like
|
|
431
415
|
* `users/1234/addresses`
|
|
@@ -468,12 +452,13 @@ export interface CollectionActionsProps<M extends Record<string, any> = any, USE
|
|
|
468
452
|
* an {@link EntityCollection}
|
|
469
453
|
* @group Models
|
|
470
454
|
*/
|
|
471
|
-
export
|
|
455
|
+
export interface SelectionController<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
472
456
|
selectedEntities: Entity<M>[];
|
|
473
|
-
setSelectedEntities:
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
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
|
+
}
|
|
477
462
|
/**
|
|
478
463
|
* Filter conditions in a `Query.where()` clause are specified using the
|
|
479
464
|
* strings `<`, `<=`, `==`, `>=`, `>`, `array-contains`, `in`, and `array-contains-any`.
|
|
@@ -487,7 +472,7 @@ export type WhereFilterOp = "<" | "<=" | "==" | "!=" | ">=" | ">" | "array-conta
|
|
|
487
472
|
*
|
|
488
473
|
* @group Models
|
|
489
474
|
*/
|
|
490
|
-
export type FilterValues<Key extends string> = Partial<Record<Key, [WhereFilterOp,
|
|
475
|
+
export type FilterValues<Key extends string> = Partial<Record<Key, [WhereFilterOp, unknown]>>;
|
|
491
476
|
/**
|
|
492
477
|
* Used to indicate valid filter combinations (e.g. created in Firestore)
|
|
493
478
|
* If the user selects a specific filter/sort combination, the CMS checks if it's
|
|
@@ -500,7 +485,7 @@ export type FilterCombination<Key extends string> = Partial<Record<Key, "asc" |
|
|
|
500
485
|
* @group Models
|
|
501
486
|
*/
|
|
502
487
|
export type CollectionSize = "xs" | "s" | "m" | "l" | "xl";
|
|
503
|
-
export type AdditionalFieldDelegateProps<M extends Record<string,
|
|
488
|
+
export type AdditionalFieldDelegateProps<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = {
|
|
504
489
|
entity: Entity<M>;
|
|
505
490
|
context: RebaseContext<USER>;
|
|
506
491
|
};
|
|
@@ -508,7 +493,7 @@ export type AdditionalFieldDelegateProps<M extends Record<string, any> = any, US
|
|
|
508
493
|
* Use this interface for adding additional fields to entity collection views and forms.
|
|
509
494
|
* @group Models
|
|
510
495
|
*/
|
|
511
|
-
export interface AdditionalFieldDelegate<M extends Record<string,
|
|
496
|
+
export interface AdditionalFieldDelegate<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> {
|
|
512
497
|
/**
|
|
513
498
|
* ID of this column. You can use this id in the `properties` field of the
|
|
514
499
|
* collection in any order you want
|
|
@@ -523,9 +508,12 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any, US
|
|
|
523
508
|
*/
|
|
524
509
|
width?: number;
|
|
525
510
|
/**
|
|
526
|
-
* Builder for the
|
|
511
|
+
* Builder for the custom field
|
|
527
512
|
*/
|
|
528
|
-
Builder
|
|
513
|
+
Builder?(props: {
|
|
514
|
+
entity: Entity<M>;
|
|
515
|
+
context: RebaseContext<USER>;
|
|
516
|
+
}): React.ReactNode;
|
|
529
517
|
/**
|
|
530
518
|
* If this column needs to update dynamically based on other properties,
|
|
531
519
|
* you can define an array of keys as strings with the
|
|
@@ -534,7 +522,7 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any, US
|
|
|
534
522
|
* This is a performance optimization, if you don't define dependencies
|
|
535
523
|
* it will be updated in every render.
|
|
536
524
|
*/
|
|
537
|
-
dependencies?: Extract<keyof M, string
|
|
525
|
+
dependencies?: NoInfer<Extract<keyof M, string>> | NoInfer<Extract<keyof M, string>>[] | (string & {}) | (string & {})[];
|
|
538
526
|
/**
|
|
539
527
|
* Use this prop to define the value of the column as a string or number.
|
|
540
528
|
* This is the value that will be used for exporting the collection.
|
|
@@ -542,73 +530,10 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any, US
|
|
|
542
530
|
* view.
|
|
543
531
|
* @param entity
|
|
544
532
|
*/
|
|
545
|
-
value
|
|
533
|
+
value?(props: {
|
|
546
534
|
entity: Entity<M>;
|
|
547
535
|
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[];
|
|
536
|
+
}): string | number | Promise<string | number> | undefined;
|
|
612
537
|
}
|
|
613
538
|
export type InferCollectionType<S extends EntityCollection> = S extends EntityCollection<infer M> ? M : never;
|
|
614
539
|
/**
|
|
@@ -627,15 +552,15 @@ export type DefaultSelectedViewParams = {
|
|
|
627
552
|
/**
|
|
628
553
|
* You can use this controller to control the table view of a collection.
|
|
629
554
|
*/
|
|
630
|
-
export type EntityTableController<M extends Record<string,
|
|
555
|
+
export type EntityTableController<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
631
556
|
data: Entity<M>[];
|
|
632
557
|
dataLoading: boolean;
|
|
633
558
|
noMoreToLoad: boolean;
|
|
634
559
|
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
|
|
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;
|
|
639
564
|
searchString?: string;
|
|
640
565
|
setSearchString?: (searchString?: string) => void;
|
|
641
566
|
clearFilter?: () => void;
|
|
@@ -649,13 +574,13 @@ export type EntityTableController<M extends Record<string, any> = any> = {
|
|
|
649
574
|
}) => void;
|
|
650
575
|
paginationEnabled?: boolean;
|
|
651
576
|
pageSize?: number;
|
|
652
|
-
checkFilterCombination?: (filterValues: FilterValues<
|
|
577
|
+
checkFilterCombination?: (filterValues: FilterValues<string>, sortBy?: [string, "asc" | "desc"]) => boolean;
|
|
653
578
|
popupCell?: SelectedCellProps<M>;
|
|
654
579
|
setPopupCell?: (popupCell?: SelectedCellProps<M>) => void;
|
|
655
580
|
onAddColumn?: (column: string) => void;
|
|
656
581
|
};
|
|
657
|
-
export type SelectedCellProps<M extends Record<string,
|
|
658
|
-
propertyKey: Extract<keyof M, string
|
|
582
|
+
export type SelectedCellProps<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
583
|
+
propertyKey: Extract<keyof M, string> | (string & {});
|
|
659
584
|
cellRect: DOMRect;
|
|
660
585
|
width: number;
|
|
661
586
|
height: number;
|
|
@@ -773,7 +698,7 @@ export interface SecurityRule {
|
|
|
773
698
|
* application-level roles.
|
|
774
699
|
*
|
|
775
700
|
* **Important:** These are NOT native PostgreSQL database roles. They are
|
|
776
|
-
* application roles managed by Rebase, stored in the `
|
|
701
|
+
* application roles managed by Rebase, stored in the `rebase.user_roles`
|
|
777
702
|
* table, and injected into each transaction via `auth.roles()`.
|
|
778
703
|
*
|
|
779
704
|
* Generates a condition like:
|