@rebasepro/types 0.0.1-canary.0

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.
Files changed (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +174 -0
  3. package/dist/components/EntityFormActionsProps.d.ts +17 -0
  4. package/dist/components/EntityFormProps.d.ts +46 -0
  5. package/dist/components/PropertyPreviewProps.d.ts +50 -0
  6. package/dist/components/formex.d.ts +40 -0
  7. package/dist/components/index.d.ts +3 -0
  8. package/dist/controllers/analytics_controller.d.ts +7 -0
  9. package/dist/controllers/auth.d.ts +73 -0
  10. package/dist/controllers/customization_controller.d.ts +50 -0
  11. package/dist/controllers/datasource.d.ts +179 -0
  12. package/dist/controllers/dialogs_controller.d.ts +36 -0
  13. package/dist/controllers/index.d.ts +11 -0
  14. package/dist/controllers/local_config_persistence.d.ts +20 -0
  15. package/dist/controllers/navigation.d.ts +262 -0
  16. package/dist/controllers/side_dialogs_controller.d.ts +67 -0
  17. package/dist/controllers/side_entity_controller.d.ts +90 -0
  18. package/dist/controllers/snackbar.d.ts +24 -0
  19. package/dist/controllers/storage.d.ts +173 -0
  20. package/dist/index.d.ts +5 -0
  21. package/dist/index.es.js +113 -0
  22. package/dist/index.es.js.map +1 -0
  23. package/dist/index.umd.js +117 -0
  24. package/dist/index.umd.js.map +1 -0
  25. package/dist/rebase_context.d.ts +91 -0
  26. package/dist/types/backend.d.ts +254 -0
  27. package/dist/types/chips.d.ts +5 -0
  28. package/dist/types/collections.d.ts +887 -0
  29. package/dist/types/entities.d.ts +140 -0
  30. package/dist/types/entity_actions.d.ts +98 -0
  31. package/dist/types/entity_callbacks.d.ts +173 -0
  32. package/dist/types/entity_link_builder.d.ts +7 -0
  33. package/dist/types/entity_overrides.d.ts +5 -0
  34. package/dist/types/export_import.d.ts +21 -0
  35. package/dist/types/fields.d.ts +221 -0
  36. package/dist/types/index.d.ts +19 -0
  37. package/dist/types/locales.d.ts +4 -0
  38. package/dist/types/modify_collections.d.ts +5 -0
  39. package/dist/types/plugins.d.ts +276 -0
  40. package/dist/types/properties.d.ts +1103 -0
  41. package/dist/types/property_config.d.ts +68 -0
  42. package/dist/types/rebase.d.ts +180 -0
  43. package/dist/types/relations.d.ts +336 -0
  44. package/dist/types/user_management_delegate.d.ts +78 -0
  45. package/dist/types/websockets.d.ts +33 -0
  46. package/dist/users/index.d.ts +2 -0
  47. package/dist/users/roles.d.ts +22 -0
  48. package/dist/users/user.d.ts +42 -0
  49. package/package.json +137 -0
  50. package/src/components/EntityFormActionsProps.tsx +18 -0
  51. package/src/components/EntityFormProps.tsx +52 -0
  52. package/src/components/PropertyPreviewProps.tsx +61 -0
  53. package/src/components/formex.tsx +46 -0
  54. package/src/components/index.ts +3 -0
  55. package/src/controllers/analytics_controller.tsx +57 -0
  56. package/src/controllers/auth.tsx +94 -0
  57. package/src/controllers/customization_controller.tsx +61 -0
  58. package/src/controllers/datasource.ts +218 -0
  59. package/src/controllers/dialogs_controller.tsx +37 -0
  60. package/src/controllers/index.ts +11 -0
  61. package/src/controllers/local_config_persistence.tsx +22 -0
  62. package/src/controllers/navigation.ts +317 -0
  63. package/src/controllers/side_dialogs_controller.tsx +82 -0
  64. package/src/controllers/side_entity_controller.tsx +104 -0
  65. package/src/controllers/snackbar.ts +29 -0
  66. package/src/controllers/storage.ts +196 -0
  67. package/src/index.ts +5 -0
  68. package/src/rebase_context.tsx +122 -0
  69. package/src/types/backend.ts +385 -0
  70. package/src/types/chips.ts +46 -0
  71. package/src/types/collections.ts +1013 -0
  72. package/src/types/entities.ts +207 -0
  73. package/src/types/entity_actions.tsx +118 -0
  74. package/src/types/entity_callbacks.ts +217 -0
  75. package/src/types/entity_link_builder.ts +8 -0
  76. package/src/types/entity_overrides.tsx +6 -0
  77. package/src/types/export_import.ts +26 -0
  78. package/src/types/fields.tsx +298 -0
  79. package/src/types/index.ts +20 -0
  80. package/src/types/locales.ts +81 -0
  81. package/src/types/modify_collections.tsx +6 -0
  82. package/src/types/plugins.tsx +328 -0
  83. package/src/types/properties.ts +1270 -0
  84. package/src/types/property_config.tsx +93 -0
  85. package/src/types/rebase.tsx +211 -0
  86. package/src/types/relations.ts +351 -0
  87. package/src/types/user_management_delegate.ts +98 -0
  88. package/src/types/websockets.ts +37 -0
  89. package/src/users/index.ts +2 -0
  90. package/src/users/roles.ts +33 -0
  91. package/src/users/user.ts +46 -0
@@ -0,0 +1,207 @@
1
+ /**
2
+ * New or existing status
3
+ * @group Models
4
+ */
5
+ export type EntityStatus = "new" | "existing" | "copy";
6
+
7
+ /**
8
+ * Representation of an entity fetched from the datasource
9
+ * @group Models
10
+ */
11
+ export interface Entity<M extends object = object> {
12
+
13
+ /**
14
+ * ID of the entity
15
+ */
16
+ id: string | number;
17
+
18
+ /**
19
+ * A string representing the path of the referenced document (relative
20
+ * to the root of the database).
21
+ */
22
+ path: string;
23
+
24
+ /**
25
+ * Current values
26
+ */
27
+ values: EntityValues<M>;
28
+
29
+ /**
30
+ * Which datasource this entity belongs to (e.g., 'postgres', 'firestore').
31
+ * If not specified, the default datasource is assumed.
32
+ */
33
+ datasource?: string;
34
+
35
+ /**
36
+ * Which database within the datasource (e.g., for Firestore multi-database).
37
+ * If not specified, the default database of the datasource is used.
38
+ */
39
+ databaseId?: string;
40
+ }
41
+
42
+ /**
43
+ * This type represents a record of key value pairs as described in an
44
+ * entity collection.
45
+ * @group Models
46
+ */
47
+ export type EntityValues<M extends object> = M;
48
+
49
+ /**
50
+ * Props for creating an EntityReference
51
+ */
52
+ export interface EntityReferenceProps {
53
+ /** ID of the entity */
54
+ id: string;
55
+ /** Path of the collection (relative to the root of the database) */
56
+ path: string;
57
+ /** Which datasource (e.g., 'postgres', 'firestore'). Defaults to "(default)" */
58
+ datasource?: string;
59
+ /** Which database within the datasource. Defaults to "(default)" */
60
+ databaseId?: string;
61
+ }
62
+
63
+ /**
64
+ * Class used to create a reference to an entity in a different path.
65
+ *
66
+ * @example
67
+ * // Simple reference (most common case - single datasource, single db)
68
+ * new EntityReference({ id: "123", path: "users" })
69
+ *
70
+ * // Reference to a different datasource (e.g., Firestore)
71
+ * new EntityReference({ id: "123", path: "analytics", datasource: "firestore" })
72
+ *
73
+ * // Reference to a specific database within a datasource
74
+ * new EntityReference({ id: "123", path: "orders", datasource: "postgres", databaseId: "orders_db" })
75
+ */
76
+ export class EntityReference {
77
+
78
+ readonly __type = "reference";
79
+ /**
80
+ * ID of the entity
81
+ */
82
+ readonly id: string;
83
+ /**
84
+ * A string representing the path of the referenced document (relative
85
+ * to the root of the database).
86
+ */
87
+ readonly path: string;
88
+
89
+ /**
90
+ * Which datasource (e.g., 'postgres', 'firestore').
91
+ * Defaults to "(default)" if not specified.
92
+ */
93
+ readonly datasource?: string;
94
+
95
+ /**
96
+ * Which database within the datasource.
97
+ * Defaults to "(default)" if not specified.
98
+ */
99
+ readonly databaseId?: string;
100
+
101
+ /**
102
+ * Create a reference to an entity.
103
+ *
104
+ * @example
105
+ * // Simple reference (most common case)
106
+ * new EntityReference({ id: "123", path: "users" })
107
+ *
108
+ * // With datasource
109
+ * new EntityReference({ id: "123", path: "analytics", datasource: "firestore" })
110
+ */
111
+ constructor(props: EntityReferenceProps) {
112
+ this.id = props.id;
113
+ this.path = props.path;
114
+ this.datasource = props.datasource;
115
+ this.databaseId = props.databaseId;
116
+ }
117
+
118
+ get pathWithId() {
119
+ return `${this.path}/${this.id}`;
120
+ }
121
+
122
+ /**
123
+ * Get the full path including datasource and database prefixes if specified.
124
+ * For the common case (single datasource, single db), this just returns pathWithId.
125
+ */
126
+ get fullPath() {
127
+ const parts: string[] = [];
128
+
129
+ // Add datasource prefix if not default
130
+ if (this.datasource && this.datasource !== "(default)") {
131
+ parts.push(this.datasource);
132
+ }
133
+
134
+ // Add database prefix if specified
135
+ if (this.databaseId && this.databaseId !== "(default)") {
136
+ parts.push(this.databaseId);
137
+ }
138
+
139
+ if (parts.length > 0) {
140
+ return `${parts.join(":")}:::${this.path}/${this.id}`;
141
+ }
142
+ return this.pathWithId;
143
+ }
144
+
145
+ isEntityReference() {
146
+ return true;
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Class used to create a reference to an entity in a different path
152
+ */
153
+ export class EntityRelation {
154
+
155
+ readonly __type = "relation";
156
+ /**
157
+ * ID of the entity
158
+ */
159
+ readonly id: string | number;
160
+ /**
161
+ * A string representing the path of the referenced document (relative
162
+ * to the root of the database).
163
+ */
164
+ readonly path: string;
165
+
166
+ constructor(id: string | number, path: string) {
167
+ this.id = id;
168
+ this.path = path;
169
+ }
170
+
171
+ get pathWithId() {
172
+ return `${this.path}/${this.id}`;
173
+ }
174
+
175
+ isEntityReference() {
176
+ return false;
177
+ }
178
+
179
+ isEntityRelation() {
180
+ return true;
181
+ }
182
+ }
183
+
184
+ export class GeoPoint {
185
+
186
+ /**
187
+ * The latitude of this GeoPoint instance.
188
+ */
189
+ readonly latitude: number;
190
+ /**
191
+ * The longitude of this GeoPoint instance.
192
+ */
193
+ readonly longitude: number;
194
+
195
+ constructor(latitude: number, longitude: number) {
196
+ this.latitude = latitude;
197
+ this.longitude = longitude;
198
+ }
199
+ }
200
+
201
+ export class Vector {
202
+ readonly value: number[];
203
+
204
+ constructor(value: number[]) {
205
+ this.value = value;
206
+ }
207
+ }
@@ -0,0 +1,118 @@
1
+ import React from "react";
2
+ import { Entity } from "./entities";
3
+ import { EntityCollection, SelectionController } from "./collections";
4
+ import { FormContext } from "./fields";
5
+ import { User } from "../users";
6
+ import { RebaseContext } from "../rebase_context";
7
+ import { SideEntityController } from "../controllers";
8
+
9
+ /**
10
+ * An entity action is a custom action that can be performed on an entity.
11
+ * They are displayed in the entity view and in the collection view.
12
+ */
13
+ export type EntityAction<M extends object = any, USER extends User = User> = {
14
+ /**
15
+ * Title of the action
16
+ */
17
+ name: string;
18
+
19
+ /**
20
+ * Key of the action. You only need to provide this if you want to
21
+ * override the default actions, or if you are not passing the action
22
+ * directly to the `entityActions` prop of a collection.
23
+ * You can define your actions at the app level, in which case you
24
+ * must provide a key.
25
+ * The default actions are:
26
+ * - edit
27
+ * - delete
28
+ * - copy
29
+ */
30
+ key?: string;
31
+
32
+ /**
33
+ * Icon of the action
34
+ */
35
+ icon?: React.ReactElement;
36
+
37
+ /**
38
+ * Callback when the action is clicked
39
+ * @param props
40
+ */
41
+ onClick: (props: EntityActionClickProps<M, USER>) => Promise<void> | void;
42
+
43
+ /**
44
+ * Optional callback in case you want to disable the action
45
+ * @param props
46
+ */
47
+ isEnabled?: (props: EntityActionClickProps<M, USER>) => boolean;
48
+
49
+ /**
50
+ * Show this action collapsed in the menu of the collection view.
51
+ * Defaults to true
52
+ * If false, the action will be shown in the menu
53
+ */
54
+ collapsed?: boolean;
55
+
56
+ /**
57
+ * Show this action in the form, defaults to true
58
+ */
59
+ includeInForm?: boolean;
60
+
61
+ }
62
+
63
+ export type EntityActionClickProps<M extends object, USER extends User = User> = {
64
+ entity?: Entity<M>;
65
+ context: RebaseContext<USER>;
66
+
67
+ path?: string;
68
+ collection?: EntityCollection<M>;
69
+
70
+ /**
71
+ * Optional form context, present if the action is being called from a form.
72
+ * This allows you to access the form state and methods, including modifying the form values.
73
+ */
74
+ formContext?: FormContext;
75
+
76
+ /**
77
+ * Present if this actions is being called from a side dialog only
78
+ */
79
+ sideEntityController?: SideEntityController;
80
+
81
+ /**
82
+ * Is the action being called from the collection view or from the entity form view?
83
+ */
84
+ view: "collection" | "form";
85
+
86
+ /**
87
+ * If the action is rendered in the form, is it open in a side panel or full screen?
88
+ */
89
+ openEntityMode: "side_panel" | "full_screen";
90
+
91
+ /**
92
+ * Optional selection controller, present if the action is being called from a collection view
93
+ */
94
+ selectionController?: SelectionController;
95
+
96
+ /**
97
+ * Optional highlight function to highlight the entity in the collection view
98
+ * @param entity
99
+ */
100
+ highlightEntity?: (entity: Entity<Record<string, unknown>>) => void;
101
+
102
+ /**
103
+ * Optional unhighlight function to remove the highlight from the entity in the collection view
104
+ * @param entity
105
+ */
106
+ unhighlightEntity?: (entity: Entity<Record<string, unknown>>) => void;
107
+
108
+ /**
109
+ * Optional function to navigate back (e.g. when deleting an entity or navigating from a form)
110
+ */
111
+ navigateBack?: () => void;
112
+
113
+ /**
114
+ * Callback to be called when the collection changes, e.g. after an entity is deleted or created.
115
+ */
116
+ onCollectionChange?: () => void;
117
+
118
+ };
@@ -0,0 +1,217 @@
1
+ import { EntityCollection } from "./collections";
2
+ import { Entity, EntityStatus, EntityValues, } from "./entities";
3
+ import { User } from "../users";
4
+ import { RebaseCallContext } from "../rebase_context";
5
+
6
+ /**
7
+ * This interface defines all the callbacks that can be used when an entity
8
+ * is being created, updated or deleted.
9
+ * Useful for adding your own logic or blocking the execution of the operation.
10
+ * @group Models
11
+ */
12
+ export type EntityCallbacks<M extends Record<string, any> = any, USER extends User = User> = {
13
+
14
+ /**
15
+ * Callback used after fetching data
16
+ * @param props
17
+ */
18
+ afterRead?(props: EntityAfterReadProps<M, USER>)
19
+ : Promise<Entity<M>> | Entity<M>;
20
+
21
+
22
+ /**
23
+ * Callback used before saving, you need to return the values that will get
24
+ * saved. If you throw an error in this method the process stops, and an
25
+ * error snackbar gets displayed.
26
+ * This runs after schema validation.
27
+ * @param props
28
+ */
29
+ beforeSave?(props: EntityBeforeSaveProps<M, USER>)
30
+ : Promise<Partial<EntityValues<M>>> | Partial<EntityValues<M>>;
31
+
32
+ /**
33
+ * Callback used when save is successful
34
+ * @param props
35
+ */
36
+ afterSave?(props: EntityAfterSaveProps<M, USER>)
37
+ : Promise<void> | void;
38
+
39
+ /**
40
+ * Callback used when saving fails
41
+ * @param props
42
+ */
43
+ afterSaveError?(props: EntityAfterSaveErrorProps<M, USER>)
44
+ : Promise<void> | void;
45
+
46
+ /**
47
+ * Callback used before the entity is deleted.
48
+ * If you throw an error in this method the process stops, and an
49
+ * error snackbar gets displayed.
50
+ *
51
+ * @param props
52
+ */
53
+ beforeDelete?(props: EntityBeforeDeleteProps<M, USER>): void;
54
+
55
+ /**
56
+ * Callback used after the entity is deleted.
57
+ *
58
+ * @param props
59
+ */
60
+ afterDelete?(props: EntityAfterDeleteProps<M, USER>): void;
61
+
62
+ }
63
+
64
+ /**
65
+ * Parameters passed to hooks when an entity is fetched
66
+ * @group Models
67
+ */
68
+ export interface EntityAfterReadProps<M extends Record<string, any> = any, USER extends User = User> {
69
+
70
+ /**
71
+ * Collection of the entity
72
+ */
73
+ collection: EntityCollection<M, USER>;
74
+
75
+ /**
76
+ * Full path of the CMS where this collection is being fetched.
77
+ * Might contain unresolved aliases.
78
+ */
79
+ path: string;
80
+
81
+ /**
82
+ * Fetched entity
83
+ */
84
+ entity: Entity<M>
85
+
86
+ /**
87
+ * Context of the app status
88
+ */
89
+ context: RebaseCallContext<USER>;
90
+ }
91
+
92
+ /**
93
+ * Parameters passed to hooks before an entity is saved
94
+ * @group Models
95
+ */
96
+ export type EntityBeforeSaveProps<M extends Record<string, any> = any, USER extends User = User> =
97
+ Omit<EntityAfterSaveProps<M, USER>, "entityId">
98
+ & {
99
+ entityId?: string | number;
100
+ }
101
+ /**
102
+ * Parameters passed to hooks before an entity is saved
103
+ * @group Models
104
+ */
105
+ export type EntityAfterSaveErrorProps<M extends Record<string, any> = any, USER extends User = User> =
106
+ Omit<EntityAfterSaveProps<M, USER>, "entityId">
107
+ & {
108
+ entityId?: string | number;
109
+ }
110
+
111
+ /**
112
+ * Parameters passed to hooks when an entity is saved
113
+ * @group Models
114
+ */
115
+ export interface EntityAfterSaveProps<M extends Record<string, any> = any, USER extends User = User> {
116
+
117
+ /**
118
+ * Resolved collection of the entity
119
+ */
120
+ collection: EntityCollection<M>;
121
+
122
+ /**
123
+ * Full path of the CMS where this entity is being saved.
124
+ * Might contain unresolved aliases.
125
+ */
126
+ path: string;
127
+
128
+ /**
129
+ * ID of the entity
130
+ */
131
+ entityId: string | number;
132
+
133
+ /**
134
+ * Values being saved
135
+ */
136
+ values: Partial<EntityValues<M>>;
137
+
138
+ /**
139
+ * Previous values
140
+ */
141
+ previousValues?: Partial<EntityValues<M>>;
142
+
143
+ /**
144
+ * New or existing entity
145
+ */
146
+ status: EntityStatus;
147
+
148
+ /**
149
+ * Context of the app status
150
+ */
151
+ context: RebaseCallContext<USER>;
152
+ }
153
+
154
+ /**
155
+ * Parameters passed to hooks when an entity is deleted
156
+ * @group Models
157
+ */
158
+ export interface EntityBeforeDeleteProps<M extends Record<string, any> = any, USER extends User = User> {
159
+
160
+ /**
161
+ * collection of the entity being deleted
162
+ */
163
+ collection: EntityCollection<M>;
164
+
165
+ /**
166
+ * Path of the parent collection
167
+ */
168
+ path: string;
169
+
170
+ /**
171
+ * Deleted entity id
172
+ */
173
+ entityId: string | number;
174
+
175
+ /**
176
+ * Deleted entity
177
+ */
178
+ entity: Entity<M>;
179
+
180
+ /**
181
+ * Context of the app status
182
+ */
183
+ context: RebaseCallContext<USER>;
184
+ }
185
+
186
+ /**
187
+ * Parameters passed to hooks after an entity is deleted
188
+ * @group Models
189
+ */
190
+ export interface EntityAfterDeleteProps<M extends Record<string, any> = any, USER extends User = User> {
191
+
192
+ /**
193
+ * collection of the entity being deleted
194
+ */
195
+ collection: EntityCollection<M>;
196
+
197
+ /**
198
+ * Path of the parent collection
199
+ */
200
+ path: string;
201
+
202
+ /**
203
+ * Deleted entity id
204
+ */
205
+ entityId: string | number;
206
+
207
+ /**
208
+ * Deleted entity
209
+ */
210
+ entity: Entity<M>;
211
+
212
+ /**
213
+ * Context of the app status
214
+ */
215
+ context: RebaseCallContext<USER>;
216
+ }
217
+
@@ -0,0 +1,8 @@
1
+ import { Entity } from "./entities";
2
+
3
+ /**
4
+ * @group Models
5
+ */
6
+ export type EntityLinkBuilder<M extends Record<string, any> = any> = ({ entity }: {
7
+ entity: Entity<M>
8
+ }) => string;
@@ -0,0 +1,6 @@
1
+ import { DataSource, StorageSource } from "../controllers";
2
+
3
+ export type EntityOverrides = {
4
+ dataSource?: DataSource;
5
+ storageSource?: StorageSource;
6
+ };
@@ -0,0 +1,26 @@
1
+ import { Entity } from "./entities";
2
+ import { User } from "../users";
3
+ import { RebaseContext } from "../rebase_context";
4
+
5
+ /**
6
+ * You can use this configuration to add additional fields to the data
7
+ * exports
8
+ * @group Models
9
+ */
10
+ export interface ExportConfig<USER extends User = User> {
11
+ additionalFields: ExportMappingFunction<USER>[];
12
+ }
13
+
14
+ /**
15
+ * @group Models
16
+ */
17
+ export interface ExportMappingFunction<USER extends User = User> {
18
+ key: string;
19
+ builder: ({
20
+ entity,
21
+ context
22
+ }: {
23
+ entity: Entity<any>,
24
+ context: RebaseContext<USER>
25
+ }) => Promise<string> | string;
26
+ }