@rebasepro/types 0.1.2 → 0.2.3

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.
@@ -8,7 +8,7 @@ import type { EntityOverrides } from "./entity_overrides";
8
8
  import type { User } from "../users";
9
9
  import type { RebaseContext } from "../rebase_context";
10
10
  import type { Relation } from "./relations";
11
- import type { EntityCustomView } from "./entity_views";
11
+ import type { EntityCustomView, EntityDetailViewConfig } from "./entity_views";
12
12
  import type { EntityAction } from "./entity_actions";
13
13
  import type { ComponentRef } from "./component_ref";
14
14
 
@@ -134,7 +134,26 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
134
134
  * When editing an entity, you can choose to open the entity in a side dialog
135
135
  * or in a full screen dialog. Defaults to `full_screen`.
136
136
  */
137
- openEntityMode?: "side_panel" | "full_screen" | "split";
137
+ openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
138
+
139
+ /**
140
+ * Controls what happens when a user clicks on an entity in the collection view.
141
+ * - `"edit"` (default): Opens the entity in the edit form.
142
+ * - `"view"`: Opens a read-only detail view with an "Edit" button.
143
+ */
144
+ defaultEntityAction?: "view" | "edit";
145
+
146
+ /**
147
+ * Customization options for the read-only detail view.
148
+ * Only used when `defaultEntityAction` is `"view"`.
149
+ */
150
+ detailView?: EntityDetailViewConfig;
151
+
152
+ /**
153
+ * Prevent default actions from being displayed or executed on this collection.
154
+ */
155
+ disableDefaultActions?: ("edit" | "copy" | "delete")[];
156
+
138
157
 
139
158
 
140
159
  /**
@@ -200,6 +219,25 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
200
219
  */
201
220
  readonly defaultFilter?: FilterValues<Extract<keyof M, string> | (string & {})>; // setting FilterValues<M> can break defining collections by code
202
221
 
222
+ /**
223
+ * Pre-defined filter presets that appear as quick-access options in the
224
+ * collection toolbar. Each preset applies a set of filters (and
225
+ * optionally a sort order) with a single click.
226
+ *
227
+ * ```ts
228
+ * filterPresets: [
229
+ * {
230
+ * label: "Shipped this month",
231
+ * filterValues: {
232
+ * status: ["==", "shipped"],
233
+ * order_date: [">=", new Date(Date.now() - 30 * 86400000)]
234
+ * }
235
+ * }
236
+ * ]
237
+ * ```
238
+ */
239
+ readonly filterPresets?: FilterPreset<Extract<keyof M, string> | (string & {})>[];
240
+
203
241
  /**
204
242
  * Default sort applied to this collection.
205
243
  * When setting this prop, entities will have a default order
@@ -386,6 +424,13 @@ export interface PostgresCollection<M extends Record<string, unknown> = Record<s
386
424
  */
387
425
  table: string;
388
426
 
427
+ /**
428
+ * The PostgreSQL schema name for this table.
429
+ * E.g. "public", "rebase", "auth".
430
+ * If not specified, "public" is used (or the default search path).
431
+ */
432
+ schema?: string;
433
+
389
434
  /**
390
435
  * For SQL databases, you can define the relations between collections here.
391
436
  * Relations describe JOINs, foreign keys, and junction tables.
@@ -646,6 +691,36 @@ export type WhereFilterOp =
646
691
  export type FilterValues<Key extends string> =
647
692
  Partial<Record<Key, [WhereFilterOp, unknown]>>;
648
693
 
694
+ /**
695
+ * A pre-defined filter preset for quick access in the collection toolbar.
696
+ * Users can select a preset to instantly apply a set of filters and
697
+ * optionally a sort order.
698
+ *
699
+ * @group Models
700
+ */
701
+ export interface FilterPreset<Key extends string = string> {
702
+ /**
703
+ * Display label shown in the preset menu.
704
+ * If omitted, a summary is auto-generated from the filter keys.
705
+ */
706
+ label?: string;
707
+
708
+ /**
709
+ * The filter values to apply when this preset is selected.
710
+ */
711
+ filterValues: FilterValues<Key>;
712
+
713
+ /**
714
+ * Optional sort override to apply alongside the filter values.
715
+ */
716
+ sort?: [Key, "asc" | "desc"];
717
+ }
718
+
719
+ /**
720
+ * @deprecated Use {@link FilterPreset} instead.
721
+ */
722
+ export type QuickFilter<Key extends string = string> = FilterPreset<Key>;
723
+
649
724
  /**
650
725
  * Used to indicate valid filter combinations (e.g. created in Firestore)
651
726
  * If the user selects a specific filter/sort combination, the CMS checks if it's
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @module DatabaseAdapter
3
+ *
4
+ * Pluggable database abstraction for Rebase.
5
+ *
6
+ *
7
+ * A `DatabaseAdapter` focuses purely on data persistence and related concerns (realtime, history).
8
+ * It does NOT handle authentication — auth is managed separately by an `AuthAdapter`.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { createPostgresAdapter } from "@rebasepro/server-postgresql";
13
+ *
14
+ * initializeRebaseBackend({
15
+ * database: createPostgresAdapter({ connection: db, schema }),
16
+ * auth: { jwtSecret: "..." },
17
+ * });
18
+ * ```
19
+ *
20
+ * @group Backend
21
+ */
22
+
23
+ import type { DataDriver } from "../controllers/data_driver";
24
+ import type { EntityCollection } from "./collections";
25
+ import type {
26
+ CollectionRegistryInterface,
27
+ DatabaseAdmin,
28
+ InitializedDriver,
29
+ RealtimeProvider,
30
+ BootstrappedAuth,
31
+ } from "./backend";
32
+
33
+ /**
34
+ * A `DatabaseAdapter` provides data persistence for Rebase.
35
+ *
36
+ * @group Backend
37
+ */
38
+ export interface DatabaseAdapter {
39
+ /**
40
+ * Which database engine this adapter handles.
41
+ *
42
+ * @example "postgres", "mysql", "mongodb", "sqlite"
43
+ */
44
+ readonly type: string;
45
+
46
+ /**
47
+ * Create the DataDriver for CRUD operations.
48
+ *
49
+ * This is the only **required** method.
50
+ *
51
+ * @param config - Coordinator-provided config containing registered
52
+ * collections and the collection registry.
53
+ */
54
+ initializeDriver(config: DatabaseAdapterInitConfig): Promise<InitializedDriver>;
55
+
56
+ /**
57
+ * Create a realtime provider for this database.
58
+ *
59
+ * Return `undefined` if the database does not support realtime
60
+ * change notifications.
61
+ */
62
+ initializeRealtime?(driverResult: InitializedDriver): Promise<RealtimeProvider | undefined>;
63
+
64
+ /**
65
+ * Initialize auth tables / services if this driver supports them.
66
+ */
67
+ initializeAuth?(
68
+ config: unknown,
69
+ driverResult: InitializedDriver,
70
+ ): Promise<BootstrappedAuth | undefined>;
71
+
72
+ /**
73
+ * Initialize entity history tracking.
74
+ *
75
+ * Return `undefined` if the database does not support history.
76
+ */
77
+ initializeHistory?(
78
+ config: unknown,
79
+ driverResult: InitializedDriver,
80
+ ): Promise<{ historyService: unknown } | undefined>;
81
+
82
+ /**
83
+ * Initialize WebSocket server for realtime operations.
84
+ */
85
+ initializeWebsockets?(
86
+ server: unknown,
87
+ realtimeService: RealtimeProvider,
88
+ driver: DataDriver,
89
+ config?: unknown,
90
+ ): Promise<void> | void;
91
+
92
+ /**
93
+ * Return admin capabilities for this database (SQL editor, schema browser, branching).
94
+ */
95
+ getAdmin?(driverResult: InitializedDriver): DatabaseAdmin | undefined;
96
+
97
+ /**
98
+ * Mount any database-specific HTTP routes (e.g., custom admin endpoints).
99
+ *
100
+ * Called after all adapters are initialized.
101
+ */
102
+ mountRoutes?(app: unknown, basePath: string, driverResult: InitializedDriver): void;
103
+
104
+ /**
105
+ * Graceful shutdown: close connections, release resources.
106
+ */
107
+ destroy?(): Promise<void>;
108
+ }
109
+
110
+ /**
111
+ * Configuration passed by the coordinator to `DatabaseAdapter.initializeDriver()`.
112
+ *
113
+ * @group Backend
114
+ */
115
+ export interface DatabaseAdapterInitConfig {
116
+ /** Registered collection definitions. */
117
+ collections: EntityCollection[];
118
+ /** The shared collection registry to register into. */
119
+ collectionRegistry: CollectionRegistryInterface;
120
+ }
@@ -46,6 +46,13 @@ export interface EntityAction<M extends Record<string, unknown> = Record<string,
46
46
  */
47
47
  isEnabled?(props: EntityActionClickProps<M, USER>): boolean;
48
48
 
49
+ /**
50
+ * When true, this action is rendered inline on each row in the list view.
51
+ * By default, entity actions only appear in the table view and entity form.
52
+ * Use this for actions that should be easily accessible regardless of view mode.
53
+ */
54
+ showActionsInListView?: boolean;
55
+
49
56
  /**
50
57
  * Show this action collapsed in the menu of the collection view.
51
58
  * Defaults to true
@@ -86,7 +93,7 @@ export type EntityActionClickProps<M extends Record<string, unknown>, USER exten
86
93
  /**
87
94
  * If the action is rendered in the form, is it open in a side panel or full screen?
88
95
  */
89
- openEntityMode: "side_panel" | "full_screen" | "split";
96
+ openEntityMode: "side_panel" | "full_screen" | "split" | "dialog";
90
97
 
91
98
  /**
92
99
  * Optional selection controller, present if the action is being called from a collection view
@@ -50,7 +50,7 @@ export type EntityCallbacks<M extends Record<string, unknown> = Record<string, u
50
50
  *
51
51
  * @param props
52
52
  */
53
- beforeDelete?(props: EntityBeforeDeleteProps<M, USER>): void;
53
+ beforeDelete?(props: EntityBeforeDeleteProps<M, USER>): Promise<boolean | void> | boolean | void;
54
54
 
55
55
  /**
56
56
  * Callback used after the entity is deleted.
@@ -46,7 +46,7 @@ export interface FormContext<M extends Record<string, unknown> = Record<string,
46
46
 
47
47
  savingError?: Error;
48
48
 
49
- openEntityMode: "side_panel" | "full_screen" | "split";
49
+ openEntityMode: "side_panel" | "full_screen" | "split" | "dialog";
50
50
 
51
51
  /**
52
52
  * The underlying formex controller that powers the form.
@@ -54,6 +54,12 @@ export interface FormContext<M extends Record<string, unknown> = Record<string,
54
54
  formex: FormexController<M>;
55
55
 
56
56
  disabled: boolean;
57
+
58
+ /**
59
+ * Whether the form context is in read-only detail view mode.
60
+ * Custom entity views can use this to adjust their rendering.
61
+ */
62
+ readOnly?: boolean;
57
63
  }
58
64
 
59
65
 
@@ -74,3 +80,35 @@ export interface EntityCustomViewParams<M extends Record<string, unknown> = Reco
74
80
  parentCollectionSlugs?: string[];
75
81
  parentEntityIds?: string[];
76
82
  }
83
+
84
+ /**
85
+ * Configuration for customizing the read-only detail view of an entity.
86
+ * Only used when `defaultEntityAction` is set to `"view"` on the collection.
87
+ * @group Models
88
+ */
89
+ export type EntityDetailViewConfig<M extends Record<string, unknown> = Record<string, unknown>> = {
90
+ /**
91
+ * Custom component rendered above the property display in the detail view.
92
+ */
93
+ Header?: ComponentRef<EntityDetailViewParams<M>>;
94
+ /**
95
+ * Custom component rendered below the property display in the detail view.
96
+ */
97
+ Footer?: ComponentRef<EntityDetailViewParams<M>>;
98
+ /**
99
+ * Completely replace the default detail view with a custom component.
100
+ * When set, Header and Footer are ignored.
101
+ */
102
+ Builder?: ComponentRef<EntityDetailViewParams<M>>;
103
+ };
104
+
105
+ /**
106
+ * Props passed to detail view customization components (Header, Footer, Builder).
107
+ * @group Models
108
+ */
109
+ export interface EntityDetailViewParams<M extends Record<string, unknown> = Record<string, unknown>> {
110
+ collection: EntityCollection<M>;
111
+ entity: Entity<M>;
112
+ path: string;
113
+ onEditClick: () => void;
114
+ }
@@ -26,3 +26,5 @@ export * from "./data_source";
26
26
  export * from "./cron";
27
27
  export * from "./backend_hooks";
28
28
  export * from "./component_ref";
29
+ export * from "./auth_adapter";
30
+ export * from "./database_adapter";
@@ -315,7 +315,7 @@ export interface PluginFormActionProps<USER extends User = User, EC extends Enti
315
315
  disabled: boolean;
316
316
  formContext?: FormContext;
317
317
  context: RebaseContext<USER>;
318
- openEntityMode: "side_panel" | "full_screen" | "split";
318
+ openEntityMode: "side_panel" | "full_screen" | "split" | "dialog";
319
319
  }
320
320
 
321
321
  /**
@@ -2,7 +2,7 @@ import React from "react";
2
2
 
3
3
  import type { ComponentRef } from "./component_ref";
4
4
 
5
- import type { EntityReference, EntityRelation, EntityValues, GeoPoint, Entity } from "./entities";
5
+ import type { EntityReference, EntityRelation, EntityValues, GeoPoint, Entity, Vector } from "./entities";
6
6
  import type { Relation, JoinStep, OnAction } from "./relations";
7
7
  import type { EntityCollection, FilterValues } from "./collections";
8
8
  import type { ColorKey, ColorScheme } from "./chips";
@@ -48,7 +48,9 @@ export type DataType =
48
48
  | "reference"
49
49
  | "relation"
50
50
  | "array"
51
- | "map";
51
+ | "map"
52
+ | "vector"
53
+ | "binary";
52
54
 
53
55
  export type Property =
54
56
  | StringProperty
@@ -59,7 +61,9 @@ export type Property =
59
61
  | ReferenceProperty
60
62
  | RelationProperty
61
63
  | ArrayProperty
62
- | MapProperty;
64
+ | MapProperty
65
+ | VectorProperty
66
+ | BinaryProperty;
63
67
 
64
68
  export type Properties = {
65
69
  [key: string]: Property;
@@ -89,6 +93,8 @@ export type InferPropertyType<P extends Property> =
89
93
  P extends RelationProperty ? EntityRelation | EntityRelation[] :
90
94
  P extends ArrayProperty ? (P["of"] extends Property ? InferPropertyType<P["of"]>[] : unknown[]) :
91
95
  P extends MapProperty ? (P["properties"] extends Properties ? InferEntityType<P["properties"]> : Record<string, unknown>) :
96
+ P extends VectorProperty ? Vector :
97
+ P extends BinaryProperty ? string :
92
98
  never;
93
99
 
94
100
  /**
@@ -185,6 +191,8 @@ export interface BaseProperty<CustomProps = unknown> {
185
191
 
186
192
 
187
193
 
194
+
195
+
188
196
  /**
189
197
  * Rules for validating this property
190
198
  */
@@ -378,6 +386,28 @@ export interface BooleanProperty extends BaseProperty {
378
386
  validation?: PropertyValidationSchema;
379
387
  }
380
388
 
389
+ /**
390
+ * @group Entity properties
391
+ */
392
+ export interface VectorUIConfig extends BaseUIConfig {
393
+ clearable?: boolean;
394
+ }
395
+
396
+ export interface VectorProperty extends BaseProperty {
397
+ ui?: VectorUIConfig;
398
+ type: "vector";
399
+ dimensions: number;
400
+ validation?: PropertyValidationSchema;
401
+ }
402
+
403
+ /**
404
+ * @group Entity properties
405
+ */
406
+ export interface BinaryProperty extends BaseProperty {
407
+ type: "binary";
408
+ validation?: PropertyValidationSchema;
409
+ }
410
+
381
411
  /**
382
412
  * @group Entity properties
383
413
  */
@@ -503,7 +533,7 @@ export interface RelationProperty extends BaseProperty {
503
533
  * When set, the framework treats this property as a self-contained relation
504
534
  * definition and no separate `relations[]` entry is needed.
505
535
  */
506
- target?: () => EntityCollection;
536
+ target?: string | (() => EntityCollection | string);
507
537
 
508
538
  /**
509
539
  * Whether this property references one or many records.
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { ArrayProperty, MapProperty, Property, StringProperty, NumberProperty, BooleanProperty, DateProperty, GeopointProperty, ReferenceProperty, RelationProperty } from "./properties";import { BaseProperty } from "./properties";
2
+ import { ArrayProperty, MapProperty, Property, StringProperty, NumberProperty, BooleanProperty, DateProperty, GeopointProperty, ReferenceProperty, RelationProperty, VectorProperty, BinaryProperty } from "./properties";import { BaseProperty } from "./properties";
3
3
 
4
4
  type CMSBasePropertyNoName = Omit<BaseProperty, "name">;
5
5
 
@@ -19,7 +19,9 @@ export type ConfigProperty =
19
19
  | (Omit<MapProperty, "name" | "properties"> & {
20
20
  name?: string;
21
21
  properties?: Record<string, ConfigProperty>
22
- } & CMSBasePropertyNoName);
22
+ } & CMSBasePropertyNoName)
23
+ | (Omit<VectorProperty, "name"> & { name?: string } & CMSBasePropertyNoName)
24
+ | (Omit<BinaryProperty, "name"> & { name?: string } & CMSBasePropertyNoName);
23
25
 
24
26
  /**
25
27
  * This is the configuration object for a property.
@@ -90,4 +92,5 @@ export type PropertyConfigId =
90
92
  "date_time" |
91
93
  "repeat" |
92
94
  "custom_array" |
93
- "block";
95
+ "block" |
96
+ "vector_input";
@@ -20,7 +20,7 @@ export interface Relation {
20
20
  /**
21
21
  * The final collection you want to retrieve records from.
22
22
  */
23
- target: () => EntityCollection;
23
+ target: (() => EntityCollection) | any;
24
24
 
25
25
  /**
26
26
  * The nature of the relationship, determining if one or many records are returned.
@@ -34,6 +34,8 @@ export interface RebaseTranslations {
34
34
  copy: string;
35
35
  delete: string;
36
36
  delete_not_allowed: string;
37
+ edit_entity?: string;
38
+ back_to_detail?: string;
37
39
 
38
40
  // ─── Delete dialog ───────────────────────────────────────────
39
41
  delete_confirmation_title: string;
@@ -446,6 +448,15 @@ export interface RebaseTranslations {
446
448
 
447
449
  no_filterable_properties: string;
448
450
  apply_filters: string;
451
+
452
+ // ─── Filter Presets ──────────────────────────────────────────
453
+ /** Label shown on the filter presets dropdown trigger */
454
+ filter_presets?: string;
455
+ /** Tooltip shown when hovering over a preset entry */
456
+ filter_preset_apply?: string;
457
+ /** Shown when a preset is active, with {{label}} interpolation */
458
+ filter_preset_active?: string;
459
+
449
460
  list: string;
450
461
  table_view_mode: string;
451
462
  cards: string;
package/src/users/user.ts CHANGED
@@ -46,6 +46,12 @@ export type User = {
46
46
  */
47
47
  createdAt?: Date | string | null;
48
48
 
49
+ /**
50
+ * Additional metadata/custom claims associated with the user.
51
+ * Accessible by the frontend, but only writable by the backend.
52
+ */
53
+ readonly metadata?: Record<string, any>;
54
+
49
55
  getIdToken?: (forceRefresh?: boolean) => Promise<string>;
50
56
 
51
57
  };