@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,104 @@
1
+ import { Entity, EntityCollection } from "../types";
2
+ import { EntityFormProps } from "../components";
3
+
4
+ /**
5
+ * Props used to open a side dialog
6
+ * @group Hooks and utilities
7
+ */
8
+ export interface EntitySidePanelProps<M extends Record<string, any> = any> {
9
+
10
+ /**
11
+ * Absolute path of the entity
12
+ */
13
+ path: string;
14
+
15
+ /**
16
+ * ID of the entity, if not set, it means we are creating a new entity
17
+ */
18
+ entityId?: string | number;
19
+
20
+ /**
21
+ * Set this flag to true if you want to make a copy of an existing entity
22
+ */
23
+ copy?: boolean;
24
+
25
+ /**
26
+ * Open the entity with a selected sub-collection view. If the panel for this
27
+ * entity was already open, it is replaced.
28
+ */
29
+ selectedTab?: string;
30
+
31
+ /**
32
+ * Use this prop to override the width of the form view.
33
+ * e.g. "600px"
34
+ */
35
+ width?: number | string;
36
+
37
+ /**
38
+ * Collection representing the entities of this view.
39
+ * If you leave it blank it will be induced by your navigation
40
+ */
41
+ collection?: EntityCollection<M>;
42
+
43
+ /**
44
+ * Should update the URL when opening the dialog.
45
+ * Consider that if the collection that you provide is not defined in the base
46
+ * config of your `Rebase` component, you will not be able to recreate
47
+ * the state if copying the URL to a different window.
48
+ */
49
+ updateUrl?: boolean;
50
+
51
+ /**
52
+ * Callback when the entity is updated
53
+ * @param params
54
+ */
55
+ onUpdate?: (params: { entity: Entity<any> }) => void;
56
+
57
+ /**
58
+ * Callback when the dialog is closed
59
+ */
60
+ onClose?: () => void;
61
+
62
+ /**
63
+ * Should this panel close when saving
64
+ */
65
+ closeOnSave?: boolean;
66
+
67
+ /**
68
+ * Override some form properties
69
+ */
70
+ formProps?: Partial<EntityFormProps<M>>;
71
+
72
+ /**
73
+ * Allow the user to open the entity fullscreen
74
+ */
75
+ allowFullScreen?: boolean;
76
+ }
77
+
78
+ /**
79
+ * Controller to open the side dialog displaying entity forms
80
+ * @group Hooks and utilities
81
+ */
82
+ export interface SideEntityController {
83
+ /**
84
+ * Close the last panel
85
+ */
86
+ close: () => void;
87
+
88
+ /**
89
+ * Open a new entity sideDialog. By default, the collection and configuration
90
+ * of the view is fetched from the collections you have specified in the
91
+ * navigation.
92
+ * At least you need to pass the path of the entity you would like
93
+ * to edit. You can set an entityId if you would like to edit and existing one
94
+ * (or a new one with that id).
95
+ * @param props
96
+ */
97
+ open: <M extends Record<string, any> = any>(props: EntitySidePanelProps<M>) => void;
98
+
99
+ /**
100
+ * Replace the last open entity panel with the given one.
101
+ * @param props
102
+ */
103
+ replace: <M extends Record<string, any> = any>(props: EntitySidePanelProps<M>) => void;
104
+ }
@@ -0,0 +1,29 @@
1
+
2
+ /**
3
+ * Possible snackbar types
4
+ * @group Hooks and utilities
5
+ */
6
+ export type SnackbarMessageType = "success" | "info" | "warning" | "error";
7
+
8
+ /**
9
+ * Controller to display snackbars
10
+ * @group Hooks and utilities
11
+ */
12
+ export interface SnackbarController {
13
+
14
+ /**
15
+ * Close the currently open snackbar
16
+ */
17
+ close: () => void;
18
+
19
+ /**
20
+ * Display a new snackbar. You need to specify the type and message.
21
+ * You can optionally specify a title
22
+ */
23
+ open: (props: {
24
+ type: SnackbarMessageType;
25
+ message: React.ReactNode;
26
+ autoHideDuration?: number;
27
+ }) => void;
28
+
29
+ }
@@ -0,0 +1,196 @@
1
+ /**
2
+ * @group Models
3
+ */
4
+ export interface UploadFileProps {
5
+ file: File,
6
+ fileName?: string,
7
+ path?: string,
8
+ metadata?: Record<string, unknown>,
9
+ bucket?: string
10
+ }
11
+
12
+ /**
13
+ * @group Models
14
+ */
15
+ export interface UploadFileResult {
16
+ /**
17
+ * Storage path including the file name where the file was uploaded.
18
+ */
19
+ path: string;
20
+ /**
21
+ * Bucket where the file was uploaded
22
+ */
23
+ bucket: string;
24
+
25
+ /**
26
+ * Fully qualified storage URL for the uploaded file.
27
+ *
28
+ * For example: `gs://my-bucket/path/to/file.png`.
29
+ *
30
+ * This is optional for backwards compatibility.
31
+ */
32
+ storageUrl?: string;
33
+ }
34
+
35
+ /**
36
+ * @group Models
37
+ */
38
+ export interface DownloadConfig {
39
+ /**
40
+ * Temporal url that can be used to download the file
41
+ */
42
+ url: string | null;
43
+
44
+ metadata?: DownloadMetadata;
45
+
46
+ fileNotFound?: boolean;
47
+ }
48
+
49
+ /**
50
+ * The full set of object metadata, including read-only properties.
51
+ * @public
52
+ */
53
+ export declare interface DownloadMetadata {
54
+ /**
55
+ * The bucket this object is contained in.
56
+ */
57
+ bucket: string;
58
+ /**
59
+ * The full path of this object.
60
+ */
61
+ fullPath: string;
62
+ /**
63
+ * The short name of this object, which is the last component of the full path.
64
+ * For example, if path is 'full/path/image.png', name is 'image.png'.
65
+ */
66
+ name: string;
67
+ /**
68
+ * The size of this object, in bytes.
69
+ */
70
+ size: number;
71
+ /**
72
+ * Type of the uploaded file
73
+ * e.g. "image/jpeg"
74
+ */
75
+ contentType: string;
76
+
77
+ customMetadata: Record<string, unknown>;
78
+ }
79
+
80
+ /**
81
+ * @group Models
82
+ */
83
+ export interface StorageSource {
84
+ /**
85
+ * Upload a file, specifying a name and a path
86
+ * @param file
87
+ * @param fileName
88
+ * @param path
89
+ * @param metadata
90
+ * @param bucket
91
+ */
92
+ uploadFile: ({
93
+ file,
94
+ fileName,
95
+ path,
96
+ metadata,
97
+ bucket
98
+ }: UploadFileProps) => Promise<UploadFileResult>;
99
+
100
+ /**
101
+ * Convert a storage path or URL into a download configuration
102
+ * @param path
103
+ * @param bucket
104
+ */
105
+ getDownloadURL: (pathOrUrl: string, bucket?: string) => Promise<DownloadConfig>;
106
+
107
+ /**
108
+ * Get a file from a storage path.
109
+ * It returns null if the file does not exist.
110
+ * @param props
111
+ * @param bucket
112
+ */
113
+ getFile: (path: string, bucket?: string) => Promise<File | null>;
114
+
115
+ /**
116
+ * Delete a file.
117
+ * @param path
118
+ * @param bucket
119
+ */
120
+ deleteFile: (path: string, bucket?: string) => Promise<void>;
121
+
122
+ /**
123
+ * List the contents of a path.
124
+ * @param path
125
+ * @param options
126
+ */
127
+ list: (path: string, options?: {
128
+ bucket?: string,
129
+ maxResults?: number,
130
+ pageToken?: string
131
+ }) => Promise<StorageListResult>;
132
+
133
+ }
134
+
135
+ /**
136
+ * Result returned by list().
137
+ * @public
138
+ */
139
+ export declare interface StorageListResult {
140
+ /**
141
+ * References to prefixes (sub-folders). You can call list() on them to
142
+ * get its contents.
143
+ *
144
+ * Folders are implicit based on '/' in the object paths.
145
+ * For example, if a bucket has two objects '/a/b/1' and '/a/b/2', list('/a')
146
+ * will return '/a/b' as a prefix.
147
+ */
148
+ prefixes: StorageReference[];
149
+ /**
150
+ * Objects in this directory.
151
+ * You can call getMetadata() and getDownloadUrl() on them.
152
+ */
153
+ items: StorageReference[];
154
+ /**
155
+ * If set, there might be more results for this list. Use this token to resume the list.
156
+ */
157
+ nextPageToken?: string;
158
+ }
159
+
160
+ /**
161
+ * Represents a reference to a Google Cloud Storage object. Developers can
162
+ * upload, download, and delete objects, as well as get/set object metadata.
163
+ * @public
164
+ */
165
+ export declare interface StorageReference {
166
+ /**
167
+ * Returns a gs:// URL for this object in the form
168
+ * `gs://<bucket>/<path>/<to>/<object>`
169
+ * @returns The gs:// URL.
170
+ */
171
+ toString(): string;
172
+
173
+ /**
174
+ * A reference to the root of this object's bucket.
175
+ */
176
+ root: StorageReference;
177
+ /**
178
+ * The name of the bucket containing this reference's object.
179
+ */
180
+ bucket: string;
181
+ /**
182
+ * The full path of this object.
183
+ */
184
+ fullPath: string;
185
+ /**
186
+ * The short name of this object, which is the last component of the full path.
187
+ * For example, if path is 'full/path/image.png', name is 'image.png'.
188
+ */
189
+ name: string;
190
+
191
+ /**
192
+ * A reference pointing to the parent location of this reference, or null if
193
+ * this reference is the root.
194
+ */
195
+ parent: StorageReference | null;
196
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./rebase_context";
2
+ export * from "./types";
3
+ export * from "./components";
4
+ export * from "./controllers";
5
+ export * from "./users";
@@ -0,0 +1,122 @@
1
+ import {
2
+ AnalyticsController,
3
+ AuthController,
4
+ CustomizationController,
5
+ DataSource,
6
+ DialogsController,
7
+ NavigationController,
8
+ SideDialogsController,
9
+ SideEntityController,
10
+ SnackbarController,
11
+ StorageSource,
12
+ UserConfigurationPersistence
13
+ } from "./controllers";
14
+ import { User } from "./users";
15
+ import { UserManagementDelegate, EffectiveRoleController } from "./types";
16
+
17
+ /**
18
+ * Context that is provided to entity callbacks (hooks).
19
+ * It contains only the dependencies that are available in both the frontend and the backend.
20
+ * @group Hooks and utilities
21
+ */
22
+ export type RebaseCallContext<USER extends User = User> = {
23
+
24
+ /**
25
+ * Connector to your database, e.g. your Firestore database
26
+ */
27
+ dataSource: DataSource;
28
+
29
+ /**
30
+ * Used storage implementation
31
+ */
32
+ storageSource: StorageSource;
33
+
34
+ /**
35
+ * Set by the backend when callbacks are executed on the server.
36
+ */
37
+ user?: USER;
38
+ }
39
+
40
+ /**
41
+ * Context that includes the internal controllers and contexts used by the app.
42
+ * Some controllers and context included in this context can be accessed
43
+ * directly from their respective hooks.
44
+ * @group Hooks and utilities
45
+ * @see useRebaseContext
46
+ */
47
+ export type RebaseContext<USER extends User = User, AuthControllerType extends AuthController<USER> = AuthController<USER>> = RebaseCallContext<USER> & {
48
+
49
+ /**
50
+ * Context that includes the resolved navigation and utility methods and
51
+ * attributes.
52
+ * @see useNavigation
53
+ */
54
+ navigation?: NavigationController;
55
+
56
+ /**
57
+ * Controller to open the side dialog displaying entity forms
58
+ * @see useSideEntityController
59
+ */
60
+ sideEntityController?: SideEntityController;
61
+
62
+ /**
63
+ * Controller used to open side dialogs
64
+ * This is the controller used internally by side entity dialogs
65
+ * or reference dialogs.
66
+ */
67
+ sideDialogsController?: SideDialogsController;
68
+
69
+ /**
70
+ * Controller used to open regular dialogs
71
+ */
72
+ dialogsController?: DialogsController;
73
+
74
+ /**
75
+ * Used auth controller
76
+ */
77
+ authController?: AuthControllerType;
78
+
79
+
80
+
81
+ /**
82
+ * This controller holds the customization options for the CMS.
83
+ */
84
+ customizationController?: CustomizationController;
85
+
86
+ /**
87
+ * Use this controller to display snackbars
88
+ */
89
+ snackbarController?: SnackbarController;
90
+
91
+ /**
92
+ * Use this controller to access data stored in the browser for the user
93
+ */
94
+ userConfigPersistence?: UserConfigurationPersistence;
95
+
96
+ /**
97
+ * Callback to send analytics events
98
+ */
99
+ analyticsController?: AnalyticsController;
100
+
101
+ /**
102
+ * This section is used to manage users in the CMS.
103
+ * It is used to show user information in various places of the CMS,
104
+ * for example, to show who created or modified an entity,
105
+ * or to assign ownership of an entity.
106
+ *
107
+ * In the base CMS, this information is not used for access control.
108
+ * You can pass your own implementation of this section, to populate
109
+ * the dropdown of users when assigning ownership of an entity,
110
+ * or to show more information about the user.
111
+ *
112
+ * If you are using the Rebase user management plugin, this
113
+ * section will be implemented automatically.
114
+ */
115
+ userManagement?: UserManagementDelegate<USER>;
116
+
117
+ /**
118
+ * Controller to simulate different roles when dev mode is active.
119
+ */
120
+ effectiveRoleController?: EffectiveRoleController;
121
+
122
+ };