@rebasepro/types 0.0.1-canary.0 → 0.0.1-canary.0e2f892
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 +52 -6
- package/dist/controllers/client.d.ts +170 -0
- package/dist/controllers/collection_registry.d.ts +45 -0
- package/dist/controllers/customization_controller.d.ts +11 -1
- package/dist/controllers/data.d.ts +168 -0
- package/dist/controllers/data_driver.d.ts +160 -0
- package/dist/controllers/database_admin.d.ts +11 -0
- package/dist/controllers/effective_role.d.ts +4 -0
- package/dist/controllers/email.d.ts +34 -0
- package/dist/controllers/index.d.ts +12 -5
- package/dist/controllers/local_config_persistence.d.ts +4 -4
- package/dist/controllers/navigation.d.ts +12 -61
- package/dist/controllers/registry.d.ts +54 -0
- package/dist/controllers/side_entity_controller.d.ts +7 -7
- package/dist/controllers/storage.d.ts +24 -26
- package/dist/index.d.ts +0 -1
- package/dist/index.es.js +119 -14
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +118 -13
- package/dist/index.umd.js.map +1 -1
- package/dist/rebase_context.d.ts +40 -26
- package/dist/types/backend.d.ts +300 -18
- package/dist/types/builders.d.ts +15 -0
- package/dist/types/chips.d.ts +1 -1
- package/dist/types/collections.d.ts +324 -355
- package/dist/types/cron.d.ts +102 -0
- package/dist/types/data_source.d.ts +64 -0
- package/dist/types/entities.d.ts +29 -24
- package/dist/types/entity_actions.d.ts +12 -12
- package/dist/types/entity_callbacks.d.ts +12 -12
- package/dist/types/entity_link_builder.d.ts +1 -1
- package/dist/types/entity_overrides.d.ts +7 -2
- package/dist/types/entity_views.d.ts +61 -0
- package/dist/types/export_import.d.ts +3 -3
- package/dist/types/index.d.ts +9 -5
- package/dist/types/plugins.d.ts +228 -225
- package/dist/types/properties.d.ts +135 -62
- package/dist/types/property_config.d.ts +13 -11
- package/dist/types/relations.d.ts +1 -1
- package/dist/types/slots.d.ts +252 -0
- package/dist/types/translations.d.ts +870 -0
- package/dist/types/user_management_delegate.d.ts +43 -0
- package/dist/types/websockets.d.ts +45 -0
- package/dist/users/user.d.ts +4 -0
- package/package.json +99 -131
- package/src/controllers/analytics_controller.tsx +2 -2
- package/src/controllers/auth.tsx +55 -6
- package/src/controllers/client.ts +133 -0
- package/src/controllers/collection_registry.ts +57 -0
- package/src/controllers/customization_controller.tsx +12 -1
- package/src/controllers/data.ts +191 -0
- package/src/controllers/{datasource.ts → data_driver.ts} +50 -61
- package/src/controllers/database_admin.ts +22 -0
- package/src/controllers/effective_role.ts +4 -0
- package/src/controllers/email.ts +36 -0
- package/src/controllers/index.ts +15 -5
- package/src/controllers/local_config_persistence.tsx +4 -4
- package/src/controllers/navigation.ts +13 -76
- package/src/controllers/registry.ts +65 -0
- package/src/controllers/side_entity_controller.tsx +7 -7
- package/src/controllers/storage.ts +25 -28
- package/src/index.ts +0 -1
- package/src/rebase_context.tsx +41 -39
- package/src/types/backend.ts +359 -24
- package/src/types/builders.ts +17 -0
- package/src/types/chips.ts +15 -40
- package/src/types/collections.ts +375 -383
- package/src/types/cron.ts +149 -0
- package/src/types/data_source.ts +145 -0
- package/src/types/entities.ts +40 -33
- package/src/types/entity_actions.tsx +11 -11
- package/src/types/entity_callbacks.ts +12 -12
- package/src/types/entity_link_builder.ts +1 -1
- package/src/types/entity_overrides.tsx +7 -2
- package/src/types/entity_views.tsx +77 -0
- package/src/types/export_import.ts +3 -3
- package/src/types/index.ts +10 -5
- package/src/types/plugins.tsx +280 -261
- package/src/types/properties.ts +163 -61
- package/src/types/property_config.tsx +11 -11
- package/src/types/relations.ts +1 -1
- package/src/types/slots.tsx +297 -0
- package/src/types/translations.ts +977 -0
- package/src/types/user_management_delegate.ts +50 -7
- package/src/types/websockets.ts +48 -0
- package/src/users/roles.ts +0 -1
- 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/controllers/datasource.d.ts +0 -179
- 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/README.md
CHANGED
|
@@ -138,7 +138,7 @@ You can replace the Firebase Storage implementation with your own.
|
|
|
138
138
|
## Included example
|
|
139
139
|
|
|
140
140
|
You can access the code for the demo project under
|
|
141
|
-
[`example`](https://github.com/
|
|
141
|
+
[`example`](https://github.com/rebasepro/rebase/tree/master/example). It includes
|
|
142
142
|
every feature provided by this CMS.
|
|
143
143
|
|
|
144
144
|
Keep in mind you need to update the dependencies in that project if you want to
|
|
@@ -2,6 +2,6 @@ export type AnalyticsController = {
|
|
|
2
2
|
/**
|
|
3
3
|
* Callback used to get analytics events from the CMS
|
|
4
4
|
*/
|
|
5
|
-
onAnalyticsEvent?: (event:
|
|
5
|
+
onAnalyticsEvent?: (event: AnalyticsEvent, data?: object) => void;
|
|
6
6
|
};
|
|
7
|
-
export type
|
|
7
|
+
export type AnalyticsEvent = "entity_click" | "entity_click_from_reference" | "reference_selection_clear" | "reference_selection_toggle" | "reference_selected_single" | "reference_selection_new_entity" | "edit_entity_clicked" | "entity_edited" | "new_entity_click" | "new_entity_saved" | "copy_entity_click" | "entity_copied" | "single_delete_dialog_open" | "multiple_delete_dialog_open" | "single_entity_deleted" | "multiple_entities_deleted" | "drawer_navigate_to_home" | "drawer_navigate_to_collection" | "drawer_navigate_to_view" | "home_navigate_to_collection" | "home_favorite_navigate_to_collection" | "home_navigate_to_view" | "home_navigate_to_admin_view" | "home_favorite_navigate_to_view" | "home_move_card" | "home_move_group" | "home_drop_new_group" | "collection_inline_editing" | "view_mode_changed" | "kanban_card_moved" | "kanban_column_reorder" | "kanban_property_changed" | "kanban_new_entity_in_column" | "kanban_backfill_order" | "card_view_entity_click" | "unmapped_event";
|
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
import { DataSource } from "./datasource";
|
|
2
1
|
import { StorageSource } from "./storage";
|
|
3
2
|
import { Role, User } from "../users";
|
|
3
|
+
import { RebaseData } from "./data";
|
|
4
|
+
/**
|
|
5
|
+
* Capabilities advertised by an auth provider.
|
|
6
|
+
* UI components use this to show/hide features dynamically
|
|
7
|
+
* (e.g. password reset, registration, session management).
|
|
8
|
+
* @group Hooks and utilities
|
|
9
|
+
*/
|
|
10
|
+
export interface AuthCapabilities {
|
|
11
|
+
emailPasswordLogin?: boolean;
|
|
12
|
+
googleLogin?: boolean;
|
|
13
|
+
registration?: boolean;
|
|
14
|
+
passwordReset?: boolean;
|
|
15
|
+
sessionManagement?: boolean;
|
|
16
|
+
profileUpdate?: boolean;
|
|
17
|
+
emailVerification?: boolean;
|
|
18
|
+
/** List of enabled OAuth provider IDs (e.g. ["google", "github", "discord"]) */
|
|
19
|
+
enabledProviders?: string[];
|
|
20
|
+
}
|
|
4
21
|
/**
|
|
5
22
|
* Controller for retrieving the logged user or performing auth related operations.
|
|
6
23
|
* Note that if you are implementing your AuthController, you probably will want
|
|
7
24
|
* to do it as the result of a hook.
|
|
8
25
|
* @group Hooks and utilities
|
|
9
26
|
*/
|
|
10
|
-
export type AuthController<USER extends User =
|
|
27
|
+
export type AuthController<USER extends User = User, ExtraData = unknown> = {
|
|
11
28
|
/**
|
|
12
29
|
* The user currently logged in
|
|
13
30
|
* The values can be: the user object, null if they skipped login
|
|
@@ -46,9 +63,38 @@ export type AuthController<USER extends User = any, ExtraData = unknown> = {
|
|
|
46
63
|
loginSkipped: boolean;
|
|
47
64
|
extra: ExtraData;
|
|
48
65
|
setExtra: (extra: ExtraData) => void;
|
|
49
|
-
setUser
|
|
50
|
-
setUserRoles
|
|
66
|
+
setUser?(user: USER | null): void;
|
|
67
|
+
setUserRoles?(roles: Role[]): void;
|
|
68
|
+
/**
|
|
69
|
+
* Capabilities advertised by the auth provider.
|
|
70
|
+
* UI components use this to feature-detect what the backend supports.
|
|
71
|
+
*/
|
|
72
|
+
capabilities?: AuthCapabilities;
|
|
51
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* Extended auth controller with common optional auth methods.
|
|
76
|
+
* Backend implementations (Rebase backend, Firebase, Supabase, etc.)
|
|
77
|
+
* extend this with their own backend-specific extras.
|
|
78
|
+
* @group Hooks and utilities
|
|
79
|
+
*/
|
|
80
|
+
export interface AuthControllerExtended<USER extends User = User, ExtraData = unknown> extends AuthController<USER, ExtraData> {
|
|
81
|
+
/** Login with email and password */
|
|
82
|
+
emailPasswordLogin?(email: string, password: string): Promise<void>;
|
|
83
|
+
/** Login with a Google ID token or trigger Google popup */
|
|
84
|
+
googleLogin?(idToken: string): Promise<void>;
|
|
85
|
+
/** Register a new user */
|
|
86
|
+
register?(email: string, password: string, displayName?: string): Promise<void>;
|
|
87
|
+
/** Skip login (for anonymous access if enabled) */
|
|
88
|
+
skipLogin?(): void;
|
|
89
|
+
/** Request password reset email */
|
|
90
|
+
forgotPassword?(email: string): Promise<void>;
|
|
91
|
+
/** Reset password using a token */
|
|
92
|
+
resetPassword?(token: string, password: string): Promise<void>;
|
|
93
|
+
/** Change password for the authenticated user */
|
|
94
|
+
changePassword?(oldPassword: string, newPassword: string): Promise<void>;
|
|
95
|
+
/** Update user profile */
|
|
96
|
+
updateProfile?(displayName?: string, photoURL?: string): Promise<USER>;
|
|
97
|
+
}
|
|
52
98
|
/**
|
|
53
99
|
* Implement this function to allow access to specific users.
|
|
54
100
|
* @group Hooks and utilities
|
|
@@ -63,9 +109,9 @@ export type Authenticator<USER extends User = User> = (props: {
|
|
|
63
109
|
*/
|
|
64
110
|
authController: AuthController<USER>;
|
|
65
111
|
/**
|
|
66
|
-
*
|
|
112
|
+
* Unified data access API
|
|
67
113
|
*/
|
|
68
|
-
|
|
114
|
+
data: RebaseData;
|
|
69
115
|
/**
|
|
70
116
|
* Used storage implementation
|
|
71
117
|
*/
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { User } from "../users";
|
|
2
|
+
import { RebaseData } from "./data";
|
|
3
|
+
import { EmailService } from "./email";
|
|
4
|
+
/**
|
|
5
|
+
* Event type for authentication state changes
|
|
6
|
+
*/
|
|
7
|
+
export type AuthChangeEvent = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "USER_UPDATED";
|
|
8
|
+
/**
|
|
9
|
+
* Standard session interface representing an authenticated state
|
|
10
|
+
*/
|
|
11
|
+
export interface RebaseSession {
|
|
12
|
+
accessToken: string;
|
|
13
|
+
refreshToken: string;
|
|
14
|
+
expiresAt: number;
|
|
15
|
+
user: User;
|
|
16
|
+
}
|
|
17
|
+
import { StorageSource } from "./storage";
|
|
18
|
+
/**
|
|
19
|
+
* Unified Authentication Client Interface
|
|
20
|
+
* Pure functional SDK interface, decoupled from UI and React hooks
|
|
21
|
+
*/
|
|
22
|
+
export interface AuthClient {
|
|
23
|
+
/**
|
|
24
|
+
* Get the current user from the server or cache
|
|
25
|
+
*/
|
|
26
|
+
getUser(): Promise<User | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Get the currently active session
|
|
29
|
+
*/
|
|
30
|
+
getSession(): RebaseSession | null;
|
|
31
|
+
/**
|
|
32
|
+
* Sign out the current user and clear local session
|
|
33
|
+
*/
|
|
34
|
+
signOut(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Subscribe to authentication state changes
|
|
37
|
+
*/
|
|
38
|
+
onAuthStateChange(callback: (event: AuthChangeEvent, session: RebaseSession | null) => void): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Manually refresh the session token
|
|
41
|
+
*/
|
|
42
|
+
refreshSession(): Promise<RebaseSession>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* User record as returned by the Admin API.
|
|
46
|
+
* @group Admin
|
|
47
|
+
*/
|
|
48
|
+
export interface AdminUser {
|
|
49
|
+
uid: string;
|
|
50
|
+
email: string;
|
|
51
|
+
displayName: string | null;
|
|
52
|
+
photoURL: string | null;
|
|
53
|
+
provider: string;
|
|
54
|
+
roles: string[];
|
|
55
|
+
createdAt: string;
|
|
56
|
+
updatedAt: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Role record as returned by the Admin API.
|
|
60
|
+
* @group Admin
|
|
61
|
+
*/
|
|
62
|
+
export interface AdminRole {
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
isAdmin: boolean;
|
|
66
|
+
defaultPermissions: Record<string, unknown> | null;
|
|
67
|
+
config: Record<string, unknown> | null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Client-side Admin API interface.
|
|
71
|
+
* Provides user and role management operations.
|
|
72
|
+
* @group Admin
|
|
73
|
+
*/
|
|
74
|
+
export interface AdminAPI {
|
|
75
|
+
listUsers(): Promise<{
|
|
76
|
+
users: AdminUser[];
|
|
77
|
+
}>;
|
|
78
|
+
listUsersPaginated(options?: {
|
|
79
|
+
search?: string;
|
|
80
|
+
limit?: number;
|
|
81
|
+
offset?: number;
|
|
82
|
+
orderBy?: string;
|
|
83
|
+
orderDir?: "asc" | "desc";
|
|
84
|
+
}): Promise<{
|
|
85
|
+
users: AdminUser[];
|
|
86
|
+
total: number;
|
|
87
|
+
limit: number;
|
|
88
|
+
offset: number;
|
|
89
|
+
}>;
|
|
90
|
+
getUser(userId: string): Promise<{
|
|
91
|
+
user: AdminUser;
|
|
92
|
+
}>;
|
|
93
|
+
createUser(data: {
|
|
94
|
+
email: string;
|
|
95
|
+
displayName?: string;
|
|
96
|
+
password?: string;
|
|
97
|
+
roles?: string[];
|
|
98
|
+
}): Promise<{
|
|
99
|
+
user: AdminUser;
|
|
100
|
+
}>;
|
|
101
|
+
updateUser(userId: string, data: {
|
|
102
|
+
email?: string;
|
|
103
|
+
displayName?: string;
|
|
104
|
+
password?: string;
|
|
105
|
+
roles?: string[];
|
|
106
|
+
}): Promise<{
|
|
107
|
+
user: AdminUser;
|
|
108
|
+
}>;
|
|
109
|
+
deleteUser(userId: string): Promise<{
|
|
110
|
+
success: boolean;
|
|
111
|
+
}>;
|
|
112
|
+
listRoles(): Promise<{
|
|
113
|
+
roles: AdminRole[];
|
|
114
|
+
}>;
|
|
115
|
+
getRole(roleId: string): Promise<{
|
|
116
|
+
role: AdminRole;
|
|
117
|
+
}>;
|
|
118
|
+
createRole(data: {
|
|
119
|
+
id: string;
|
|
120
|
+
name: string;
|
|
121
|
+
isAdmin?: boolean;
|
|
122
|
+
defaultPermissions?: Record<string, unknown>;
|
|
123
|
+
config?: Record<string, unknown>;
|
|
124
|
+
}): Promise<{
|
|
125
|
+
role: AdminRole;
|
|
126
|
+
}>;
|
|
127
|
+
updateRole(roleId: string, data: {
|
|
128
|
+
name?: string;
|
|
129
|
+
isAdmin?: boolean;
|
|
130
|
+
defaultPermissions?: Record<string, unknown>;
|
|
131
|
+
config?: Record<string, unknown>;
|
|
132
|
+
}): Promise<{
|
|
133
|
+
role: AdminRole;
|
|
134
|
+
}>;
|
|
135
|
+
deleteRole(roleId: string): Promise<{
|
|
136
|
+
success: boolean;
|
|
137
|
+
}>;
|
|
138
|
+
bootstrap(): Promise<{
|
|
139
|
+
success: boolean;
|
|
140
|
+
message: string;
|
|
141
|
+
user: {
|
|
142
|
+
uid: string;
|
|
143
|
+
roles: string[];
|
|
144
|
+
};
|
|
145
|
+
}>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Overarching abstraction that unites Data, Auth, Storage, and Email.
|
|
149
|
+
* Adapters for Supabase or Firebase simply need to implement this interface.
|
|
150
|
+
*/
|
|
151
|
+
export interface RebaseClient<DB = unknown> {
|
|
152
|
+
/** Unified Data access layer */
|
|
153
|
+
data: RebaseData;
|
|
154
|
+
/** Unified Authentication layer */
|
|
155
|
+
auth: AuthClient;
|
|
156
|
+
/** Unified Storage layer */
|
|
157
|
+
storage?: StorageSource;
|
|
158
|
+
/**
|
|
159
|
+
* Server-side email service.
|
|
160
|
+
*
|
|
161
|
+
* Available when SMTP (or a custom `sendEmail` function) is configured
|
|
162
|
+
* in the backend auth config. `undefined` when email is not configured.
|
|
163
|
+
*
|
|
164
|
+
* > **Note:** This is only available on the server-side `rebase` singleton.
|
|
165
|
+
* > The client-side SDK does not include an email service.
|
|
166
|
+
*/
|
|
167
|
+
email?: EmailService;
|
|
168
|
+
/** Admin API for user and role management */
|
|
169
|
+
admin?: AdminAPI;
|
|
170
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { EntityCollection } from "../types/collections";
|
|
2
|
+
import type { EntityReference } from "../types/entities";
|
|
3
|
+
/**
|
|
4
|
+
* Controller that provides access to the registered entity collections.
|
|
5
|
+
* @group Models
|
|
6
|
+
*/
|
|
7
|
+
export type CollectionRegistryController<DB = Record<string, unknown>, EC extends EntityCollection = EntityCollection<any>> = {
|
|
8
|
+
/**
|
|
9
|
+
* List of the mapped collections in the CMS.
|
|
10
|
+
* Each entry relates to a collection in the root database.
|
|
11
|
+
* Each of the navigation entries in this field
|
|
12
|
+
* generates an entry in the main menu.
|
|
13
|
+
*/
|
|
14
|
+
collections?: EntityCollection[];
|
|
15
|
+
/**
|
|
16
|
+
* Is the registry ready to be used
|
|
17
|
+
*/
|
|
18
|
+
initialised: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Get the collection configuration for a given path.
|
|
21
|
+
* The collection is resolved from the given path or alias.
|
|
22
|
+
*/
|
|
23
|
+
getCollection: <K extends keyof DB>(slugOrPath: Extract<K, string>, includeUserOverride?: boolean) => EC | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Get the raw, un-normalized collection configuration.
|
|
26
|
+
* This bypasses the `CollectionRegistry` normalization (such as injecting `relation` instances).
|
|
27
|
+
* This is strictly for the Visual Editor to manipulate AST code without persisting runtime state.
|
|
28
|
+
*/
|
|
29
|
+
getRawCollection: (slugOrPath: string) => EC | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieve all the related parent references for a given path
|
|
32
|
+
* @param path
|
|
33
|
+
*/
|
|
34
|
+
getParentReferencesFromPath: (path: string) => EntityReference[];
|
|
35
|
+
/**
|
|
36
|
+
* Retrieve all the related parent collection ids for a given path
|
|
37
|
+
* @param path
|
|
38
|
+
*/
|
|
39
|
+
getParentCollectionIds: (path: string) => string[];
|
|
40
|
+
/**
|
|
41
|
+
* Resolve paths from a list of ids
|
|
42
|
+
* @param ids
|
|
43
|
+
*/
|
|
44
|
+
convertIdsToPaths: (ids: string[]) => string[];
|
|
45
|
+
};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import type { EntityLinkBuilder } from "../types/entity_link_builder";
|
|
3
|
+
import type { Locale } from "../types/locales";
|
|
4
|
+
import type { EntityAction } from "../types/entity_actions";
|
|
5
|
+
import type { EntityCustomView } from "../types/entity_views";
|
|
6
|
+
import type { RebasePlugin } from "../types/plugins";
|
|
7
|
+
import type { PropertyConfig } from "../types/property_config";
|
|
8
|
+
import type { SlotContribution } from "../types/slots";
|
|
3
9
|
export type CustomizationController = {
|
|
4
10
|
/**
|
|
5
11
|
* Builder for generating utility links for entities
|
|
@@ -9,6 +15,10 @@ export type CustomizationController = {
|
|
|
9
15
|
* Use plugins to modify the behaviour of the CMS.
|
|
10
16
|
*/
|
|
11
17
|
plugins?: RebasePlugin[];
|
|
18
|
+
/**
|
|
19
|
+
* Pre-merged slots from plugins + direct slot contributions.
|
|
20
|
+
*/
|
|
21
|
+
resolvedSlots: SlotContribution[];
|
|
12
22
|
/**
|
|
13
23
|
* List of additional custom views for entities.
|
|
14
24
|
* You can use the key to reference the custom view in
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Entity, EntityValues } from "../types/entities";
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for querying a collection.
|
|
4
|
+
* Uses PostgREST-style filter syntax for consistency between
|
|
5
|
+
* the SDK (HTTP) and framework (in-process) contexts.
|
|
6
|
+
*
|
|
7
|
+
* @group Data
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A where-clause value for a single field.
|
|
11
|
+
*
|
|
12
|
+
* Supports three syntaxes:
|
|
13
|
+
* 1. **Equality shorthand**: raw JS values — `null`, `"active"`, `42`, `true`
|
|
14
|
+
* 2. **Tuple syntax**: `[operator, value]` — `[">", 18]`, `["in", ["a","b"]]`
|
|
15
|
+
* 3. **PostgREST string**: `"eq.published"`, `"gte.18"`, `"in.(a,b)"`
|
|
16
|
+
*
|
|
17
|
+
* @group Data
|
|
18
|
+
*/
|
|
19
|
+
export type WhereFieldValue = string | number | boolean | null | [WhereFilterOpShort, any];
|
|
20
|
+
/** Short operator strings accepted in the tuple syntax. */
|
|
21
|
+
export type WhereFilterOpShort = "==" | "!=" | ">" | ">=" | "<" | "<=" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" | "nin" | "not-in" | "array-contains" | "array-contains-any" | "cs" | "csa";
|
|
22
|
+
export interface FindParams {
|
|
23
|
+
/** Maximum number of items to return (default: 20) */
|
|
24
|
+
limit?: number;
|
|
25
|
+
/** Number of items to skip */
|
|
26
|
+
offset?: number;
|
|
27
|
+
/** Page number (1-indexed), alternative to offset */
|
|
28
|
+
page?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Filter object. Supports multiple syntaxes per field:
|
|
31
|
+
*
|
|
32
|
+
* **Equality shorthand** — raw JS values (null, string, number, boolean):
|
|
33
|
+
* ```ts
|
|
34
|
+
* { company_profile_id: null }
|
|
35
|
+
* { status: "active" }
|
|
36
|
+
* { age: 18 }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* **Tuple syntax** — `[operator, value]`:
|
|
40
|
+
* ```ts
|
|
41
|
+
* { age: [">=", 18] }
|
|
42
|
+
* { role: ["in", ["admin", "editor"]] }
|
|
43
|
+
* { deleted_at: ["!=", null] }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* **PostgREST string syntax** (original format):
|
|
47
|
+
* ```ts
|
|
48
|
+
* { status: "eq.published" }
|
|
49
|
+
* { age: "gte.18" }
|
|
50
|
+
* { role: "in.(admin,editor)" }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
where?: Record<string, WhereFieldValue>;
|
|
54
|
+
/**
|
|
55
|
+
* Sort order. Format: "field:direction".
|
|
56
|
+
* @example "created_at:desc", "name:asc"
|
|
57
|
+
*/
|
|
58
|
+
orderBy?: string;
|
|
59
|
+
/** Relations to include in the response */
|
|
60
|
+
include?: string[];
|
|
61
|
+
/** Full-text search string */
|
|
62
|
+
searchString?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Paginated response from a collection query.
|
|
66
|
+
* @group Data
|
|
67
|
+
*/
|
|
68
|
+
export interface FindResponse<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
69
|
+
/** Array of entities matching the query */
|
|
70
|
+
data: Entity<M>[];
|
|
71
|
+
/** Pagination metadata */
|
|
72
|
+
meta: {
|
|
73
|
+
total: number;
|
|
74
|
+
limit: number;
|
|
75
|
+
offset: number;
|
|
76
|
+
hasMore: boolean;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A single collection's CRUD accessor.
|
|
81
|
+
*
|
|
82
|
+
* This is the unified API surface used in both:
|
|
83
|
+
* - The generated SDK (`client.data.products.create(...)`)
|
|
84
|
+
* - Framework callbacks (`context.data.products.create(...)`)
|
|
85
|
+
*
|
|
86
|
+
* @group Data
|
|
87
|
+
*/
|
|
88
|
+
export interface CollectionAccessor<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
89
|
+
/**
|
|
90
|
+
* Find multiple records with optional filtering, pagination, and sorting.
|
|
91
|
+
*/
|
|
92
|
+
find(params?: FindParams): Promise<FindResponse<M>>;
|
|
93
|
+
/**
|
|
94
|
+
* Find a single record by its ID.
|
|
95
|
+
*/
|
|
96
|
+
findById(id: string | number): Promise<Entity<M> | undefined>;
|
|
97
|
+
/**
|
|
98
|
+
* Create a new record.
|
|
99
|
+
* @param data The entity data to create.
|
|
100
|
+
* @param id Optional specific ID to use for the new record.
|
|
101
|
+
* @returns The created entity
|
|
102
|
+
*/
|
|
103
|
+
create(data: Partial<EntityValues<M>>, id?: string | number): Promise<Entity<M>>;
|
|
104
|
+
/**
|
|
105
|
+
* Update an existing record by ID.
|
|
106
|
+
* @returns The updated entity
|
|
107
|
+
*/
|
|
108
|
+
update(id: string | number, data: Partial<EntityValues<M>>): Promise<Entity<M>>;
|
|
109
|
+
/**
|
|
110
|
+
* Delete a record by ID.
|
|
111
|
+
*/
|
|
112
|
+
delete(id: string | number): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Subscribe to a collection for real-time updates.
|
|
115
|
+
* Optional method, may not be supported by all implementations (like stateless HTTP clients).
|
|
116
|
+
*/
|
|
117
|
+
listen?(params: FindParams | undefined, onUpdate: (response: FindResponse<M>) => void, onError?: (error: Error) => void): () => void;
|
|
118
|
+
/**
|
|
119
|
+
* Subscribe to a single record for real-time updates.
|
|
120
|
+
* Optional method.
|
|
121
|
+
*/
|
|
122
|
+
listenById?(id: string | number, onUpdate: (entity: Entity<M> | undefined) => void, onError?: (error: Error) => void): () => void;
|
|
123
|
+
/**
|
|
124
|
+
* Count the number of records matching the given filter.
|
|
125
|
+
*/
|
|
126
|
+
count?(params?: FindParams): Promise<number>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The unified data access object.
|
|
130
|
+
*
|
|
131
|
+
* Access collections as dynamic properties: `data.products.find(...)`.
|
|
132
|
+
* In the SDK this is backed by HTTP transport (typed, generated per-project).
|
|
133
|
+
* In the framework this is backed by a Proxy + in-process database driver (dynamic).
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* // SDK
|
|
137
|
+
* const client = createRebaseClient({ baseUrl: "..." });
|
|
138
|
+
* await client.data.products.create({ name: "Camera", price: 299 });
|
|
139
|
+
*
|
|
140
|
+
* // Framework callback
|
|
141
|
+
* callbacks: {
|
|
142
|
+
* afterSave({ context }) {
|
|
143
|
+
* await context.data.logs.create({ action: "saved", timestamp: new Date() });
|
|
144
|
+
* }
|
|
145
|
+
* }
|
|
146
|
+
*
|
|
147
|
+
* @group Data
|
|
148
|
+
*/
|
|
149
|
+
export interface RebaseData {
|
|
150
|
+
/**
|
|
151
|
+
* Get a collection accessor by slug.
|
|
152
|
+
* Alternative to dynamic property access for cases where
|
|
153
|
+
* the collection name is a variable.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* const accessor = data.collection("products");
|
|
157
|
+
* await accessor.find({ limit: 10 });
|
|
158
|
+
*/
|
|
159
|
+
collection(slug: string): CollectionAccessor;
|
|
160
|
+
/**
|
|
161
|
+
* Dynamic collection accessor.
|
|
162
|
+
* Access any collection by its slug as a property.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* data.products.find({ where: { status: "eq.published" } })
|
|
166
|
+
*/
|
|
167
|
+
[collectionSlug: string]: CollectionAccessor | ((slug: string) => CollectionAccessor);
|
|
168
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { Entity, EntityStatus, EntityValues } from "../types/entities";
|
|
2
|
+
import type { EntityCollection, FilterValues } from "../types/collections";
|
|
3
|
+
import type { RebaseContext } from "../rebase_context";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface FetchEntityProps<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
8
|
+
path: string;
|
|
9
|
+
entityId: string | number;
|
|
10
|
+
databaseId?: string;
|
|
11
|
+
collection?: EntityCollection<M>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export type ListenEntityProps<M extends Record<string, unknown> = Record<string, unknown>> = FetchEntityProps<M> & {
|
|
17
|
+
onUpdate: (entity: Entity<M> | null) => void;
|
|
18
|
+
onError?: (error: Error) => void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export interface FetchCollectionProps<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
24
|
+
path: string;
|
|
25
|
+
collection?: EntityCollection<M>;
|
|
26
|
+
filter?: FilterValues<Extract<keyof M, string>>;
|
|
27
|
+
limit?: number;
|
|
28
|
+
offset?: number;
|
|
29
|
+
startAfter?: unknown;
|
|
30
|
+
orderBy?: string;
|
|
31
|
+
searchString?: string;
|
|
32
|
+
order?: "desc" | "asc";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export type ListenCollectionProps<M extends Record<string, unknown> = Record<string, unknown>> = FetchCollectionProps<M> & {
|
|
38
|
+
onUpdate: (entities: Entity<M>[]) => void;
|
|
39
|
+
onError?: (error: Error) => void;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export interface SaveEntityProps<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
45
|
+
path: string;
|
|
46
|
+
values: Partial<EntityValues<M>>;
|
|
47
|
+
entityId?: string | number;
|
|
48
|
+
previousValues?: Partial<EntityValues<M>>;
|
|
49
|
+
collection?: EntityCollection<M>;
|
|
50
|
+
status: EntityStatus;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
export interface DeleteEntityProps<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
56
|
+
entity: Entity<M>;
|
|
57
|
+
collection?: EntityCollection<M>;
|
|
58
|
+
}
|
|
59
|
+
export type FilterCombinationValidProps = {
|
|
60
|
+
path: string;
|
|
61
|
+
databaseId?: string;
|
|
62
|
+
collection: EntityCollection;
|
|
63
|
+
filterValues: FilterValues<string>;
|
|
64
|
+
sortBy?: [string, "asc" | "desc"];
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Internal driver interface for communicating with the data layer.
|
|
68
|
+
* This is NOT the public API — use `RebaseData` / `context.data` instead.
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export interface DataDriver {
|
|
72
|
+
/**
|
|
73
|
+
* Key that identifies this driver
|
|
74
|
+
*/
|
|
75
|
+
key?: string;
|
|
76
|
+
/**
|
|
77
|
+
* If the driver has been initialised
|
|
78
|
+
*/
|
|
79
|
+
initialised?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Fetch data from a collection
|
|
82
|
+
* @param props
|
|
83
|
+
* @return Promise of entities
|
|
84
|
+
*/
|
|
85
|
+
fetchCollection<M extends Record<string, unknown> = Record<string, unknown>>(props: FetchCollectionProps<M>): Promise<Entity<M>[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Listen to a collection in a given path. If you don't implement this method
|
|
88
|
+
* `fetchCollection` will be used instead, with no real time updates.
|
|
89
|
+
* @param props
|
|
90
|
+
* @return Function to cancel subscription
|
|
91
|
+
*/
|
|
92
|
+
listenCollection?<M extends Record<string, unknown> = Record<string, unknown>>(props: ListenCollectionProps<M>): () => void;
|
|
93
|
+
/**
|
|
94
|
+
* Retrieve an entity given a path and a collection
|
|
95
|
+
* @param props
|
|
96
|
+
*/
|
|
97
|
+
fetchEntity<M extends Record<string, unknown> = Record<string, unknown>>(props: FetchEntityProps<M>): Promise<Entity<M> | undefined>;
|
|
98
|
+
/**
|
|
99
|
+
* Get realtime updates on one entity.
|
|
100
|
+
* @param props
|
|
101
|
+
* @return Function to cancel subscription
|
|
102
|
+
*/
|
|
103
|
+
listenEntity?<M extends Record<string, unknown> = Record<string, unknown>>(props: ListenEntityProps<M>): () => void;
|
|
104
|
+
/**
|
|
105
|
+
* Save entity to the specified path
|
|
106
|
+
* @param props
|
|
107
|
+
*/
|
|
108
|
+
saveEntity<M extends Record<string, unknown> = Record<string, unknown>>(props: SaveEntityProps<M>): Promise<Entity<M>>;
|
|
109
|
+
/**
|
|
110
|
+
* Delete an entity
|
|
111
|
+
* @param props
|
|
112
|
+
* @return was the whole deletion flow successful
|
|
113
|
+
*/
|
|
114
|
+
deleteEntity<M extends Record<string, unknown> = Record<string, unknown>>(props: DeleteEntityProps<M>): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Check if the given property is unique in the given collection
|
|
117
|
+
* @param path Collection path
|
|
118
|
+
* @param name of the property
|
|
119
|
+
* @param value
|
|
120
|
+
* @param entityId
|
|
121
|
+
* @param collection
|
|
122
|
+
* @return `true` if there are no other fields besides the given entity
|
|
123
|
+
*/
|
|
124
|
+
checkUniqueField(path: string, name: string, value: unknown, entityId?: string | number, collection?: EntityCollection): Promise<boolean>;
|
|
125
|
+
/**
|
|
126
|
+
* Count the number of entities in a collection
|
|
127
|
+
*/
|
|
128
|
+
countEntities?<M extends Record<string, unknown> = Record<string, unknown>>(props: FetchCollectionProps<M>): Promise<number>;
|
|
129
|
+
/**
|
|
130
|
+
* Check if the given filter combination is valid
|
|
131
|
+
* @param props
|
|
132
|
+
*/
|
|
133
|
+
isFilterCombinationValid?(props: Omit<FilterCombinationValidProps, "collection"> & {
|
|
134
|
+
databaseId?: string;
|
|
135
|
+
}): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Get the object to generate the current time in the driver
|
|
138
|
+
*/
|
|
139
|
+
currentTime?: () => unknown;
|
|
140
|
+
delegateToCMSModel?: (data: unknown) => unknown;
|
|
141
|
+
cmsToDelegateModel?: (data: unknown) => unknown;
|
|
142
|
+
initTextSearch?: (props: {
|
|
143
|
+
context: RebaseContext;
|
|
144
|
+
path: string;
|
|
145
|
+
databaseId?: string;
|
|
146
|
+
collection: EntityCollection;
|
|
147
|
+
parentCollectionIds?: string[];
|
|
148
|
+
}) => Promise<boolean>;
|
|
149
|
+
/**
|
|
150
|
+
* Flag to indicate if the driver has requested the initialization of the text search index
|
|
151
|
+
*/
|
|
152
|
+
needsInitTextSearch?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Return the admin capabilities of this driver.
|
|
155
|
+
* @see SQLAdmin
|
|
156
|
+
* @see DocumentAdmin
|
|
157
|
+
* @see SchemaAdmin
|
|
158
|
+
*/
|
|
159
|
+
admin?: import("../types/backend").DatabaseAdmin;
|
|
160
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module database_admin
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the capability-specific admin interfaces from `@rebasepro/types/backend`.
|
|
5
|
+
* This file is kept for backwards compatibility — new code should import from
|
|
6
|
+
* `@rebasepro/types` directly.
|
|
7
|
+
*
|
|
8
|
+
* @group Admin
|
|
9
|
+
*/
|
|
10
|
+
export type { SQLAdmin, DocumentAdmin, SchemaAdmin, DatabaseAdmin, HealthCheckResult } from "../types/backend";
|
|
11
|
+
export { isSQLAdmin, isDocumentAdmin, isSchemaAdmin } from "../types/backend";
|