@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
package/src/types/collections.ts
CHANGED
|
@@ -3,34 +3,32 @@ import { Entity, EntityStatus, EntityValues } from "./entities";
|
|
|
3
3
|
import { EntityCallbacks } from "./entity_callbacks";
|
|
4
4
|
|
|
5
5
|
import { EnumValues, Properties } from "./properties";
|
|
6
|
-
import { FormContext } from "./fields";
|
|
7
|
-
import { EntityAction } from "./entity_actions";
|
|
8
6
|
import { ExportConfig } from "./export_import";
|
|
9
7
|
import { EntityOverrides } from "./entity_overrides";
|
|
10
8
|
import { User } from "../users";
|
|
11
9
|
import { RebaseContext } from "../rebase_context";
|
|
12
10
|
import { Relation } from "./relations";
|
|
11
|
+
import { EntityCustomView } from "./entity_views";
|
|
12
|
+
import { EntityAction } from "./entity_actions";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Base interface containing all driver-agnostic collection properties.
|
|
16
|
+
* Use {@link PostgresCollection} or {@link FirebaseCollection} for
|
|
17
|
+
* driver-specific type safety, or {@link EntityCollection} when you
|
|
18
|
+
* need to handle any collection regardless of backend.
|
|
18
19
|
*
|
|
19
20
|
* @group Models
|
|
20
21
|
*/
|
|
21
|
-
export interface
|
|
22
|
+
export interface BaseEntityCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> {
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* You can set an alias that will be used internally instead of the `path`.
|
|
25
26
|
* The `alias` value will be used to determine the URL of the collection,
|
|
26
|
-
* while `path` will still be used in the
|
|
27
|
+
* while `path` will still be used in the driver.
|
|
27
28
|
* Note that you can use this value in reference properties too.
|
|
28
29
|
*/
|
|
29
30
|
slug: string;
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
32
|
/**
|
|
35
33
|
* Name of the collection, typically plural.
|
|
36
34
|
* E.g. `Products`, `Blog`
|
|
@@ -49,127 +47,68 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
49
47
|
description?: string;
|
|
50
48
|
|
|
51
49
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
50
|
+
* Child collections nested under entities of this collection.
|
|
51
|
+
* Populated automatically during normalization from driver-specific fields
|
|
52
|
+
* (e.g. Firebase `subcollections`, Postgres `relations` with many-cardinality).
|
|
53
|
+
*
|
|
54
|
+
* Custom drivers can set this directly to expose child collections to the UI.
|
|
54
55
|
*/
|
|
55
|
-
|
|
56
|
+
childCollections?: () => EntityCollection<Record<string, unknown>>[];
|
|
57
|
+
|
|
58
|
+
|
|
56
59
|
|
|
57
60
|
/**
|
|
58
|
-
* Which
|
|
61
|
+
* Which driver handles this collection.
|
|
59
62
|
* Use this to route collections to different backends:
|
|
60
63
|
* - `"postgres"` - Route to PostgreSQL backend
|
|
61
64
|
* - `"firestore"` - Route to Firestore (client-side)
|
|
62
65
|
* - `"mongodb"` - Route to MongoDB backend
|
|
63
|
-
* - Custom IDs for your own
|
|
66
|
+
* - Custom IDs for your own driver implementations
|
|
64
67
|
*
|
|
65
|
-
* If not specified, the default
|
|
68
|
+
* If not specified, the default driver `"(default)"` is used.
|
|
66
69
|
*
|
|
67
70
|
* @example
|
|
68
|
-
* // Simple - no
|
|
71
|
+
* // Simple - no driver needed for default
|
|
69
72
|
* { slug: "products" }
|
|
70
73
|
*
|
|
71
74
|
* // Firestore collection (client-side real-time)
|
|
72
|
-
* { slug: "analytics",
|
|
75
|
+
* { slug: "analytics", driver: "firestore" }
|
|
73
76
|
*
|
|
74
|
-
* // Multiple databases within a
|
|
75
|
-
* { slug: "orders",
|
|
77
|
+
* // Multiple databases within a driver
|
|
78
|
+
* { slug: "orders", driver: "postgres", databaseId: "orders_db" }
|
|
76
79
|
*/
|
|
77
|
-
|
|
80
|
+
driver?: string;
|
|
78
81
|
|
|
79
82
|
/**
|
|
80
|
-
* Which database within the
|
|
83
|
+
* Which database within the driver.
|
|
81
84
|
* - For Firestore: The Firestore database ID (e.g., for multi-database projects)
|
|
82
85
|
* - For PostgreSQL: Schema or database name
|
|
83
86
|
* - For MongoDB: Database name
|
|
84
87
|
*
|
|
85
|
-
* If not specified, the default database of the
|
|
88
|
+
* If not specified, the default database of the driver is used.
|
|
86
89
|
*/
|
|
87
90
|
databaseId?: string;
|
|
88
91
|
|
|
89
92
|
/**
|
|
90
|
-
*
|
|
91
|
-
* When defined, the schema generator will enable RLS on the table and
|
|
92
|
-
* create the corresponding PostgreSQL policies.
|
|
93
|
-
*
|
|
94
|
-
* Supports three levels of expressiveness:
|
|
95
|
-
* 1. **Convenience shortcuts** — `ownerField`, `access`, `roles`
|
|
96
|
-
* 2. **Raw SQL** — `using` and `withCheck` for full PostgreSQL power
|
|
97
|
-
* 3. **Combined** — mix shortcuts with `roles` for common patterns
|
|
98
|
-
*
|
|
99
|
-
* The authenticated user context is available in raw SQL via:
|
|
100
|
-
* - `auth.uid()` — the current user's ID
|
|
101
|
-
* - `auth.roles()` — comma-separated app role IDs
|
|
102
|
-
* - `auth.jwt()` — full JWT claims as JSONB
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* // Simple: only owners can access their own rows
|
|
106
|
-
* securityRules: [
|
|
107
|
-
* { operation: "all", ownerField: "user_id" }
|
|
108
|
-
* ]
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* // Public read, owner-only write (using operations array to reduce boilerplate)
|
|
112
|
-
* securityRules: [
|
|
113
|
-
* { operation: "select", access: "public" },
|
|
114
|
-
* { operations: ["insert", "update", "delete"], ownerField: "created_by" }
|
|
115
|
-
* ]
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* // Role-based: admins read all rows, users read own
|
|
119
|
-
* securityRules: [
|
|
120
|
-
* { operation: "select", roles: ["admin"], using: "true" },
|
|
121
|
-
* { operation: "all", ownerField: "user_id" }
|
|
122
|
-
* ]
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* // Raw SQL: cross-table check with subquery
|
|
126
|
-
* securityRules: [
|
|
127
|
-
* {
|
|
128
|
-
* operation: "select",
|
|
129
|
-
* using: "EXISTS (SELECT 1 FROM org_members WHERE org_members.org_id = {org_id} AND org_members.user_id = auth.uid())"
|
|
130
|
-
* }
|
|
131
|
-
* ]
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* // Restrictive policy with both USING and WITH CHECK to constrain old AND new row states
|
|
135
|
-
* securityRules: [
|
|
136
|
-
* { operation: "all", ownerField: "user_id" },
|
|
137
|
-
* { operation: "update", mode: "restrictive", using: "{is_locked} = false", withCheck: "{is_locked} = false" }
|
|
138
|
-
* ]
|
|
139
|
-
*/
|
|
140
|
-
securityRules?: SecurityRule[];
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* If this collection is a top level navigation entry, you can set this
|
|
144
|
-
* property to `true` to indicate that this collection is a collection group.
|
|
93
|
+
* Set of properties that compose an entity
|
|
145
94
|
*/
|
|
146
|
-
|
|
95
|
+
properties: Properties;
|
|
147
96
|
|
|
148
97
|
/**
|
|
149
|
-
* Icon
|
|
150
|
-
* You can use any of the icons in the Material specs:
|
|
151
|
-
* https://fonts.google.com/icons
|
|
152
|
-
* e.g. 'account_tree' or 'person'.
|
|
153
|
-
* Find all the icons in https://rebase.pro/docs/icons
|
|
154
|
-
* You can also pass a React node if you want to render a custom icon.
|
|
155
|
-
* If not specified, a default icon will be used.
|
|
98
|
+
* Icon for the navigation sidebar or cards.
|
|
156
99
|
*/
|
|
157
100
|
icon?: string | React.ReactNode;
|
|
158
101
|
|
|
159
102
|
/**
|
|
160
|
-
*
|
|
161
|
-
* navigation view. If you set this value in a subcollection it has no
|
|
162
|
-
* effect.
|
|
163
|
-
* @deprecated This prop is deprecated and will be removed in the future.
|
|
164
|
-
* You can apply grouping by using the `navigationGroupMappings` prop in the
|
|
165
|
-
* {@link useBuildNavigationController} hook instead.
|
|
103
|
+
* Navigation group for this collection.
|
|
166
104
|
*/
|
|
167
105
|
group?: string;
|
|
168
106
|
|
|
169
107
|
/**
|
|
170
|
-
*
|
|
108
|
+
* Array of entity views that this collection has.
|
|
109
|
+
* Can be an array of `EntityCustomView` or a string representing the key of a global `EntityCustomView`.
|
|
171
110
|
*/
|
|
172
|
-
|
|
111
|
+
entityViews?: (string | EntityCustomView<Record<string, unknown>>)[];
|
|
173
112
|
|
|
174
113
|
/**
|
|
175
114
|
* Default preview properties displayed when this collection is referenced to.
|
|
@@ -181,7 +120,7 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
181
120
|
* as the title in entity related views and references.
|
|
182
121
|
* If not specified, the first property simple text property will be used.
|
|
183
122
|
*/
|
|
184
|
-
titleProperty?: Extract<keyof M, string
|
|
123
|
+
readonly titleProperty?: Extract<keyof M, string> | (string & {});
|
|
185
124
|
|
|
186
125
|
/**
|
|
187
126
|
* When editing an entity, you can choose to open the entity in a side dialog
|
|
@@ -203,14 +142,12 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
203
142
|
* - If you have subcollections, you get a column for each subcollection,
|
|
204
143
|
* with the path (or alias) as the subcollection, prefixed with
|
|
205
144
|
* `subcollection:`. e.g. `subcollection:orders`.
|
|
206
|
-
* - If you are using a collection group, you will also have an
|
|
207
|
-
* additional `collectionGroupParent` column.
|
|
208
145
|
* You can use this prop to hide some properties from the table view.
|
|
209
146
|
* Note that if you set this prop, other ways to hide fields, like
|
|
210
147
|
* `hidden` in the property definition,will be ignored.
|
|
211
148
|
* `propertiesOrder` has precedence over `hidden`.
|
|
212
149
|
*/
|
|
213
|
-
propertiesOrder?: (Extract<keyof M, string> | string | `subcollection:${string}`
|
|
150
|
+
propertiesOrder?: (Extract<keyof M, string> | (string & {}) | string | `subcollection:${string}`)[];
|
|
214
151
|
|
|
215
152
|
/**
|
|
216
153
|
* If enabled, content is loaded in batches. If `false` all entities in the
|
|
@@ -224,58 +161,12 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
224
161
|
|
|
225
162
|
selectionEnabled?: boolean;
|
|
226
163
|
|
|
227
|
-
/**
|
|
228
|
-
* You can add subcollections to your entity in the same way you define the root
|
|
229
|
-
* collections. The collections added here will be displayed when opening
|
|
230
|
-
* the side dialog of an entity.
|
|
231
|
-
*/
|
|
232
|
-
subcollections?: () => EntityCollection<any>[];
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* For SQL databases, you can define the relations between collections here.
|
|
236
|
-
*/
|
|
237
|
-
relations?: Relation[];
|
|
238
|
-
|
|
239
164
|
/**
|
|
240
165
|
* This interface defines all the callbacks that can be used when an entity
|
|
241
166
|
* is being created, updated or deleted.
|
|
242
167
|
* Useful for adding your own logic or blocking the execution of the operation.
|
|
243
168
|
*/
|
|
244
|
-
callbacks?: EntityCallbacks<M, USER>;
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Builder for rendering additional components such as buttons in the
|
|
248
|
-
* collection toolbar
|
|
249
|
-
*/
|
|
250
|
-
Actions?: React.ComponentType<CollectionActionsProps> | React.ComponentType<CollectionActionsProps>[];
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* You can define additional actions that can be performed on the entities
|
|
254
|
-
* in this collection. These actions can be displayed in the collection
|
|
255
|
-
* view or in the entity view.
|
|
256
|
-
*
|
|
257
|
-
* You can use the `onClick` method to implement your own logic.
|
|
258
|
-
* In the `context` prop you can access all the controllers of Rebase.
|
|
259
|
-
*
|
|
260
|
-
* ```
|
|
261
|
-
* const archiveEntityAction: EntityAction = {
|
|
262
|
-
* icon: <ArchiveIcon/>,
|
|
263
|
-
* name: "Archive",
|
|
264
|
-
* onClick({
|
|
265
|
-
* entity,
|
|
266
|
-
* collection,
|
|
267
|
-
* context,
|
|
268
|
-
* }): Promise<void> {
|
|
269
|
-
* // Add your code here
|
|
270
|
-
* return Promise.resolve(undefined);
|
|
271
|
-
* }
|
|
272
|
-
* }
|
|
273
|
-
* ```
|
|
274
|
-
*
|
|
275
|
-
* You can also pass the action as a string that represents the `key`, in which case it will
|
|
276
|
-
* use the action defined in the main configuration under `entityActions`.
|
|
277
|
-
*/
|
|
278
|
-
entityActions?: (EntityAction<M, USER> | string)[];
|
|
169
|
+
readonly callbacks?: EntityCallbacks<M, USER>;
|
|
279
170
|
|
|
280
171
|
/**
|
|
281
172
|
* Pass your own selection controller if you want to control selected
|
|
@@ -287,18 +178,18 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
287
178
|
/**
|
|
288
179
|
* Force a filter in this view. If applied, the rest of the filters will
|
|
289
180
|
* be disabled. Filters applied with this prop cannot be changed.
|
|
290
|
-
* e.g. `forceFilter: { age: ["
|
|
181
|
+
* e.g. `forceFilter: { age: [">", 18] }`
|
|
291
182
|
* e.g. `forceFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
|
|
292
183
|
*/
|
|
293
|
-
forceFilter?: FilterValues<Extract<keyof M, string
|
|
184
|
+
readonly forceFilter?: FilterValues<Extract<keyof M, string> | (string & {})>;
|
|
294
185
|
|
|
295
186
|
/**
|
|
296
187
|
* Initial filters applied to the collection this collection is related to.
|
|
297
188
|
* Defaults to none. Filters applied with this prop can be changed.
|
|
298
|
-
* e.g. `filter: { age: ["
|
|
189
|
+
* e.g. `filter: { age: [">", 18] }`
|
|
299
190
|
* e.g. `filter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
|
|
300
191
|
*/
|
|
301
|
-
filter?: FilterValues<Extract<keyof M, string
|
|
192
|
+
readonly filter?: FilterValues<Extract<keyof M, string> | (string & {})>; // setting FilterValues<M> can break defining collections by code
|
|
302
193
|
|
|
303
194
|
/**
|
|
304
195
|
* Default sort applied to this collection.
|
|
@@ -306,21 +197,13 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
306
197
|
* applied in the collection.
|
|
307
198
|
* e.g. `sort: ["order", "asc"]`
|
|
308
199
|
*/
|
|
309
|
-
sort?: [Extract<keyof M, string
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Array of builders for rendering additional panels in an entity view.
|
|
313
|
-
* Useful if you need to render custom views.
|
|
314
|
-
* You can either define the custom view inline or pass a reference to
|
|
315
|
-
* a custom view defined in the main configuration under `entityViews`
|
|
316
|
-
*/
|
|
317
|
-
entityViews?: (string | EntityCustomView<M>)[];
|
|
200
|
+
readonly sort?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"];
|
|
318
201
|
|
|
319
202
|
/**
|
|
320
203
|
* You can add additional fields to the collection view by implementing
|
|
321
204
|
* an additional field delegate.
|
|
322
205
|
*/
|
|
323
|
-
additionalFields?: AdditionalFieldDelegate<M, USER>[];
|
|
206
|
+
readonly additionalFields?: AdditionalFieldDelegate<M, USER>[];
|
|
324
207
|
|
|
325
208
|
/**
|
|
326
209
|
* Default size of the rendered collection
|
|
@@ -452,21 +335,147 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
|
|
|
452
335
|
* fractional indexing. Used by Kanban view for ordering within columns
|
|
453
336
|
* and can be used for general ordering purposes.
|
|
454
337
|
*/
|
|
455
|
-
orderProperty?: Extract<keyof M, string
|
|
338
|
+
readonly orderProperty?: Extract<keyof M, string> | (string & {});
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Actions that can be performed on the entities in this collection.
|
|
342
|
+
*/
|
|
343
|
+
entityActions?: EntityAction<M, USER>[];
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Builder for the collection actions rendered in the toolbar
|
|
347
|
+
*/
|
|
348
|
+
Actions?: React.ComponentType<any>[];
|
|
349
|
+
|
|
456
350
|
}
|
|
457
351
|
|
|
352
|
+
// ── Driver-specific collection types ──────────────────────────────────
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* A collection backed by PostgreSQL (or any SQL database).
|
|
356
|
+
* Adds support for SQL-style relations (JOINs) and Row Level Security.
|
|
357
|
+
*
|
|
358
|
+
* Use this type instead of {@link EntityCollection} when you want
|
|
359
|
+
* compile-time safety that only SQL-relevant fields appear.
|
|
360
|
+
*
|
|
361
|
+
* @group Models
|
|
362
|
+
*/
|
|
363
|
+
export interface PostgresCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>
|
|
364
|
+
extends BaseEntityCollection<M, USER> {
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* The driver for this collection. For Postgres collections this
|
|
368
|
+
* can be omitted (Postgres is the default) or set to `"postgres"`.
|
|
369
|
+
*/
|
|
370
|
+
driver?: "postgres" | undefined;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* The PostgreSQL table name for this collection.
|
|
374
|
+
*/
|
|
375
|
+
table: string;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Set by the backend when the resolved table name doesn't match
|
|
379
|
+
* an actual table in the database schema.
|
|
380
|
+
*/
|
|
381
|
+
isTableMissing?: boolean;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* For SQL databases, you can define the relations between collections here.
|
|
385
|
+
* Relations describe JOINs, foreign keys, and junction tables.
|
|
386
|
+
*/
|
|
387
|
+
relations?: Relation[];
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Security rules for this collection (Supabase-style Row Level Security).
|
|
391
|
+
* When defined, the schema generator will enable RLS on the table and
|
|
392
|
+
* create the corresponding PostgreSQL policies.
|
|
393
|
+
*
|
|
394
|
+
* Supports three levels of expressiveness:
|
|
395
|
+
* 1. **Convenience shortcuts** — `ownerField`, `access`, `roles`
|
|
396
|
+
* 2. **Raw SQL** — `using` and `withCheck` for full PostgreSQL power
|
|
397
|
+
* 3. **Combined** — mix shortcuts with `roles` for common patterns
|
|
398
|
+
*
|
|
399
|
+
* The authenticated user context is available in raw SQL via:
|
|
400
|
+
* - `auth.uid()` — the current user's ID
|
|
401
|
+
* - `auth.roles()` — comma-separated app role IDs
|
|
402
|
+
* - `auth.jwt()` — full JWT claims as JSONB
|
|
403
|
+
*/
|
|
404
|
+
securityRules?: SecurityRule[];
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* A collection backed by Firebase / Firestore.
|
|
409
|
+
* Adds support for subcollections (nested document collections).
|
|
410
|
+
*
|
|
411
|
+
* Use this type instead of {@link EntityCollection} when you want
|
|
412
|
+
* compile-time safety that only Firestore-relevant fields appear.
|
|
413
|
+
*
|
|
414
|
+
* @group Models
|
|
415
|
+
*/
|
|
416
|
+
export interface FirebaseCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>
|
|
417
|
+
extends BaseEntityCollection<M, USER> {
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* The driver for this collection. Must be set to `"firestore"`.
|
|
421
|
+
*/
|
|
422
|
+
driver: "firestore";
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* You can add subcollections to your entity in the same way you define the root
|
|
426
|
+
* collections. The collections added here will be displayed when opening
|
|
427
|
+
* the side dialog of an entity.
|
|
428
|
+
*/
|
|
429
|
+
subcollections?: () => EntityCollection<Record<string, unknown>>[];
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* A collection backed by any data source.
|
|
434
|
+
* This is a discriminated union — use {@link PostgresCollection} or
|
|
435
|
+
* {@link FirebaseCollection} for driver-specific type safety.
|
|
436
|
+
*
|
|
437
|
+
* @group Models
|
|
438
|
+
*/
|
|
439
|
+
export type EntityCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> =
|
|
440
|
+
| PostgresCollection<M, USER>
|
|
441
|
+
| FirebaseCollection<M, USER>;
|
|
442
|
+
|
|
443
|
+
// ── Type guards ───────────────────────────────────────────────────────
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Type guard for PostgreSQL collections.
|
|
447
|
+
* Returns true if the collection uses the Postgres driver (or the default driver).
|
|
448
|
+
* @group Models
|
|
449
|
+
*/
|
|
450
|
+
export function isPostgresCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>(
|
|
451
|
+
collection: EntityCollection<M, USER>
|
|
452
|
+
): collection is PostgresCollection<M, USER> {
|
|
453
|
+
return !collection.driver || collection.driver === "postgres";
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Type guard for Firebase / Firestore collections.
|
|
458
|
+
* @group Models
|
|
459
|
+
*/
|
|
460
|
+
export function isFirebaseCollection<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User>(
|
|
461
|
+
collection: EntityCollection<M, USER>
|
|
462
|
+
): collection is FirebaseCollection<M, USER> {
|
|
463
|
+
return collection.driver === "firestore";
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
|
|
458
467
|
/**
|
|
459
468
|
* Configuration for Kanban board view mode.
|
|
460
469
|
* @group Collections
|
|
461
470
|
*/
|
|
462
|
-
export interface KanbanConfig<M extends Record<string,
|
|
471
|
+
export interface KanbanConfig<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
463
472
|
/**
|
|
464
473
|
* Property key to use for Kanban board columns.
|
|
465
474
|
* Must reference a string property with enumValues defined.
|
|
466
475
|
* Entities will be grouped into columns based on this property's value.
|
|
467
476
|
* The column order is determined by the order of enumValues in the property.
|
|
468
477
|
*/
|
|
469
|
-
columnProperty: Extract<keyof M, string
|
|
478
|
+
columnProperty: Extract<keyof M, string> | (string & {});
|
|
470
479
|
}
|
|
471
480
|
|
|
472
481
|
/**
|
|
@@ -482,7 +491,7 @@ export type ViewMode = "table" | "cards" | "kanban";
|
|
|
482
491
|
*
|
|
483
492
|
* @group Models
|
|
484
493
|
*/
|
|
485
|
-
export interface CollectionActionsProps<M extends Record<string,
|
|
494
|
+
export interface CollectionActionsProps<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User, EC extends EntityCollection<M> = EntityCollection<M>> {
|
|
486
495
|
/**
|
|
487
496
|
* Full collection path of this entity. This is the full path, like
|
|
488
497
|
* `users/1234/addresses`
|
|
@@ -534,11 +543,12 @@ export interface CollectionActionsProps<M extends Record<string, any> = any, USE
|
|
|
534
543
|
* an {@link EntityCollection}
|
|
535
544
|
* @group Models
|
|
536
545
|
*/
|
|
537
|
-
export
|
|
546
|
+
export interface SelectionController<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
538
547
|
selectedEntities: Entity<M>[];
|
|
539
|
-
setSelectedEntities:
|
|
540
|
-
|
|
541
|
-
|
|
548
|
+
setSelectedEntities(entities: Entity<M>[]): void;
|
|
549
|
+
setSelectedEntities(action: (prev: Entity<M>[]) => Entity<M>[]): void;
|
|
550
|
+
isEntitySelected(entity: Entity<M>): boolean;
|
|
551
|
+
toggleEntitySelection(entity: Entity<M>, newSelectedState?: boolean): void;
|
|
542
552
|
}
|
|
543
553
|
|
|
544
554
|
/**
|
|
@@ -566,7 +576,7 @@ export type WhereFilterOp =
|
|
|
566
576
|
* @group Models
|
|
567
577
|
*/
|
|
568
578
|
export type FilterValues<Key extends string> =
|
|
569
|
-
Partial<Record<Key, [WhereFilterOp,
|
|
579
|
+
Partial<Record<Key, [WhereFilterOp, unknown]>>;
|
|
570
580
|
|
|
571
581
|
/**
|
|
572
582
|
* Used to indicate valid filter combinations (e.g. created in Firestore)
|
|
@@ -582,7 +592,7 @@ export type FilterCombination<Key extends string> = Partial<Record<Key, "asc" |
|
|
|
582
592
|
*/
|
|
583
593
|
export type CollectionSize = "xs" | "s" | "m" | "l" | "xl";
|
|
584
594
|
|
|
585
|
-
export type AdditionalFieldDelegateProps<M extends Record<string,
|
|
595
|
+
export type AdditionalFieldDelegateProps<M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User> = {
|
|
586
596
|
entity: Entity<M>,
|
|
587
597
|
context: RebaseContext<USER>
|
|
588
598
|
};
|
|
@@ -591,7 +601,7 @@ export type AdditionalFieldDelegateProps<M extends Record<string, any> = any, US
|
|
|
591
601
|
* Use this interface for adding additional fields to entity collection views and forms.
|
|
592
602
|
* @group Models
|
|
593
603
|
*/
|
|
594
|
-
export interface AdditionalFieldDelegate<M extends Record<string,
|
|
604
|
+
export interface AdditionalFieldDelegate<M extends Record<string, unknown> = Record<string, unknown>,
|
|
595
605
|
USER extends User = User> {
|
|
596
606
|
|
|
597
607
|
/**
|
|
@@ -611,9 +621,11 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any,
|
|
|
611
621
|
width?: number;
|
|
612
622
|
|
|
613
623
|
/**
|
|
614
|
-
* Builder for the
|
|
624
|
+
* Builder for the custom field
|
|
615
625
|
*/
|
|
616
|
-
Builder
|
|
626
|
+
Builder?(props: { entity: Entity<M>, context: RebaseContext<USER> }): React.ReactNode;
|
|
627
|
+
|
|
628
|
+
|
|
617
629
|
|
|
618
630
|
/**
|
|
619
631
|
* If this column needs to update dynamically based on other properties,
|
|
@@ -623,7 +635,7 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any,
|
|
|
623
635
|
* This is a performance optimization, if you don't define dependencies
|
|
624
636
|
* it will be updated in every render.
|
|
625
637
|
*/
|
|
626
|
-
dependencies?: Extract<keyof M, string
|
|
638
|
+
dependencies?: NoInfer<Extract<keyof M, string>> | NoInfer<Extract<keyof M, string>>[] | (string & {}) | (string & {})[];
|
|
627
639
|
|
|
628
640
|
/**
|
|
629
641
|
* Use this prop to define the value of the column as a string or number.
|
|
@@ -632,87 +644,12 @@ export interface AdditionalFieldDelegate<M extends Record<string, any> = any,
|
|
|
632
644
|
* view.
|
|
633
645
|
* @param entity
|
|
634
646
|
*/
|
|
635
|
-
value
|
|
647
|
+
value?(props: {
|
|
636
648
|
entity: Entity<M>,
|
|
637
649
|
context: RebaseContext
|
|
638
|
-
})
|
|
650
|
+
}): string | number | Promise<string | number> | undefined;
|
|
639
651
|
}
|
|
640
652
|
|
|
641
|
-
/**
|
|
642
|
-
* You can use this builder to render a custom panel in the entity detail view.
|
|
643
|
-
* It gets rendered as a tab.
|
|
644
|
-
* @group Models
|
|
645
|
-
*/
|
|
646
|
-
export type EntityCustomView<M extends Record<string, any> = any> =
|
|
647
|
-
{
|
|
648
|
-
/**
|
|
649
|
-
* Key of this custom view.
|
|
650
|
-
*/
|
|
651
|
-
key: string;
|
|
652
|
-
|
|
653
|
-
/**
|
|
654
|
-
* Name of this custom view.
|
|
655
|
-
*/
|
|
656
|
-
name: string;
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* Render this custom view in the tab of the entity view, instead of the name
|
|
660
|
-
*/
|
|
661
|
-
tabComponent?: React.ReactNode;
|
|
662
|
-
|
|
663
|
-
/**
|
|
664
|
-
* If set to true, the actions of the entity (save, discard,delete) will be
|
|
665
|
-
* included in the view. By default the actions are located in the right or bottom,
|
|
666
|
-
* based on the screen size. You can force the actions to be located at the bottom
|
|
667
|
-
* by setting this prop to "bottom".
|
|
668
|
-
*/
|
|
669
|
-
includeActions?: boolean | "bottom";
|
|
670
|
-
|
|
671
|
-
/**
|
|
672
|
-
* Builder for rendering the custom view
|
|
673
|
-
*/
|
|
674
|
-
Builder?: React.ComponentType<EntityCustomViewParams<M>>;
|
|
675
|
-
|
|
676
|
-
/**
|
|
677
|
-
* Position of this tab in the entity view. Defaults to `end`.
|
|
678
|
-
*/
|
|
679
|
-
position?: "start" | "end";
|
|
680
|
-
};
|
|
681
|
-
|
|
682
|
-
/**
|
|
683
|
-
* Parameters passed to the builder in charge of rendering a custom panel for
|
|
684
|
-
* an entity view.
|
|
685
|
-
* @group Models
|
|
686
|
-
*/
|
|
687
|
-
export interface EntityCustomViewParams<M extends Record<string, any> = any> {
|
|
688
|
-
|
|
689
|
-
/**
|
|
690
|
-
* collection used by this entity
|
|
691
|
-
*/
|
|
692
|
-
collection: EntityCollection<M>;
|
|
693
|
-
|
|
694
|
-
/**
|
|
695
|
-
* Entity that this view refers to. It can be undefined if the entity is new
|
|
696
|
-
*/
|
|
697
|
-
entity?: Entity<M>;
|
|
698
|
-
|
|
699
|
-
/**
|
|
700
|
-
* Modified values in the form that have not been saved yet.
|
|
701
|
-
* If the entity is not new and the values are not modified, these values
|
|
702
|
-
* are the same as in `entity`
|
|
703
|
-
*/
|
|
704
|
-
modifiedValues?: EntityValues<M>;
|
|
705
|
-
|
|
706
|
-
/**
|
|
707
|
-
* Use the form context to access the form state and methods
|
|
708
|
-
*/
|
|
709
|
-
formContext: FormContext;
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* If this is a subcollection, this is the path of the parent collections
|
|
713
|
-
*/
|
|
714
|
-
parentCollectionIds?: string[];
|
|
715
|
-
}
|
|
716
653
|
|
|
717
654
|
export type InferCollectionType<S extends EntityCollection> = S extends EntityCollection<infer M> ? M : never;
|
|
718
655
|
|
|
@@ -733,15 +670,15 @@ export type DefaultSelectedViewParams = {
|
|
|
733
670
|
/**
|
|
734
671
|
* You can use this controller to control the table view of a collection.
|
|
735
672
|
*/
|
|
736
|
-
export type EntityTableController<M extends Record<string,
|
|
673
|
+
export type EntityTableController<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
737
674
|
data: Entity<M>[];
|
|
738
675
|
dataLoading: boolean;
|
|
739
676
|
noMoreToLoad: boolean;
|
|
740
677
|
dataLoadingError?: Error;
|
|
741
|
-
filterValues?: FilterValues<Extract<keyof M, string
|
|
742
|
-
setFilterValues?: (filterValues: FilterValues<Extract<keyof M, string
|
|
743
|
-
sortBy?: [Extract<keyof M, string
|
|
744
|
-
setSortBy?: (sortBy?: [Extract<keyof M, string
|
|
678
|
+
filterValues?: FilterValues<Extract<keyof M, string> | (string & {})>;
|
|
679
|
+
setFilterValues?: (filterValues: FilterValues<Extract<keyof M, string> | (string & {})>) => void;
|
|
680
|
+
sortBy?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"];
|
|
681
|
+
setSortBy?: (sortBy?: [Extract<keyof M, string> | (string & {}), "asc" | "desc"]) => void;
|
|
745
682
|
searchString?: string;
|
|
746
683
|
setSearchString?: (searchString?: string) => void;
|
|
747
684
|
clearFilter?: () => void;
|
|
@@ -755,7 +692,7 @@ export type EntityTableController<M extends Record<string, any> = any> = {
|
|
|
755
692
|
}) => void;
|
|
756
693
|
paginationEnabled?: boolean;
|
|
757
694
|
pageSize?: number;
|
|
758
|
-
checkFilterCombination?: (filterValues: FilterValues<
|
|
695
|
+
checkFilterCombination?: (filterValues: FilterValues<string>,
|
|
759
696
|
sortBy?: [string, "asc" | "desc"]) => boolean;
|
|
760
697
|
popupCell?: SelectedCellProps<M>;
|
|
761
698
|
setPopupCell?: (popupCell?: SelectedCellProps<M>) => void;
|
|
@@ -763,8 +700,8 @@ export type EntityTableController<M extends Record<string, any> = any> = {
|
|
|
763
700
|
onAddColumn?: (column: string) => void;
|
|
764
701
|
}
|
|
765
702
|
|
|
766
|
-
export type SelectedCellProps<M extends Record<string,
|
|
767
|
-
propertyKey: Extract<keyof M, string
|
|
703
|
+
export type SelectedCellProps<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
704
|
+
propertyKey: Extract<keyof M, string> | (string & {});
|
|
768
705
|
cellRect: DOMRect;
|
|
769
706
|
width: number;
|
|
770
707
|
height: number;
|
|
@@ -892,7 +829,7 @@ export interface SecurityRule {
|
|
|
892
829
|
* application-level roles.
|
|
893
830
|
*
|
|
894
831
|
* **Important:** These are NOT native PostgreSQL database roles. They are
|
|
895
|
-
* application roles managed by Rebase, stored in the `
|
|
832
|
+
* application roles managed by Rebase, stored in the `rebase.user_roles`
|
|
896
833
|
* table, and injected into each transaction via `auth.roles()`.
|
|
897
834
|
*
|
|
898
835
|
* Generates a condition like:
|