@rebasepro/client-postgresql 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/LICENSE +6 -0
- package/README.md +106 -0
- package/dist/client-postgresql/src/index.d.ts +8 -0
- package/dist/client-postgresql/src/usePostgresClientDriver.d.ts +9 -0
- package/dist/index.es.js +154 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +157 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
- package/dist/types/src/controllers/auth.d.ts +117 -0
- package/dist/types/src/controllers/client.d.ts +58 -0
- package/dist/types/src/controllers/collection_registry.d.ts +44 -0
- package/dist/types/src/controllers/customization_controller.d.ts +54 -0
- package/dist/types/src/controllers/data.d.ts +141 -0
- package/dist/types/src/controllers/data_driver.d.ts +168 -0
- package/dist/types/src/controllers/database_admin.d.ts +11 -0
- package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
- package/dist/types/src/controllers/effective_role.d.ts +4 -0
- package/dist/types/src/controllers/index.d.ts +17 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
- package/dist/types/src/controllers/navigation.d.ts +213 -0
- package/dist/types/src/controllers/registry.d.ts +51 -0
- package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
- package/dist/types/src/controllers/side_entity_controller.d.ts +89 -0
- package/dist/types/src/controllers/snackbar.d.ts +24 -0
- package/dist/types/src/controllers/storage.d.ts +173 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/rebase_context.d.ts +101 -0
- package/dist/types/src/types/backend.d.ts +533 -0
- package/dist/types/src/types/builders.d.ts +14 -0
- package/dist/types/src/types/chips.d.ts +5 -0
- package/dist/types/src/types/collections.d.ts +812 -0
- package/dist/types/src/types/data_source.d.ts +64 -0
- package/dist/types/src/types/entities.d.ts +145 -0
- package/dist/types/src/types/entity_actions.d.ts +98 -0
- package/dist/types/src/types/entity_callbacks.d.ts +173 -0
- package/dist/types/src/types/entity_link_builder.d.ts +7 -0
- package/dist/types/src/types/entity_overrides.d.ts +9 -0
- package/dist/types/src/types/entity_views.d.ts +61 -0
- package/dist/types/src/types/export_import.d.ts +21 -0
- package/dist/types/src/types/index.d.ts +22 -0
- package/dist/types/src/types/locales.d.ts +4 -0
- package/dist/types/src/types/modify_collections.d.ts +5 -0
- package/dist/types/src/types/plugins.d.ts +225 -0
- package/dist/types/src/types/properties.d.ts +1091 -0
- package/dist/types/src/types/property_config.d.ts +70 -0
- package/dist/types/src/types/relations.d.ts +336 -0
- package/dist/types/src/types/slots.d.ts +228 -0
- package/dist/types/src/types/translations.d.ts +826 -0
- package/dist/types/src/types/user_management_delegate.d.ts +120 -0
- package/dist/types/src/types/websockets.d.ts +78 -0
- package/dist/types/src/users/index.d.ts +2 -0
- package/dist/types/src/users/roles.d.ts +22 -0
- package/dist/types/src/users/user.d.ts +46 -0
- package/package.json +90 -0
- package/src/index.ts +11 -0
- package/src/usePostgresClientDriver.ts +125 -0
- package/tsconfig.json +43 -0
- package/tsconfig.prod.json +20 -0
- package/vite.config.ts +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Source code in this repository is variously licensed under the Business Source
|
|
2
|
+
License 1.1 (BSL), Apache version 2.0 and the MIT license. A copy of each
|
|
3
|
+
license can be found in each one of the packages under the folder packages
|
|
4
|
+
under a file called License. Source code in a given file is licensed under the
|
|
5
|
+
BSL and the copyright belongs to Rebase Authors unless otherwise noted at the
|
|
6
|
+
beginning of the file.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# @rebasepro/postgresql
|
|
2
|
+
|
|
3
|
+
PostgreSQL data source client for Rebase with real-time WebSocket connectivity.
|
|
4
|
+
|
|
5
|
+
This package provides a complete client-side implementation for connecting Rebase applications to PostgreSQL backends, featuring real-time synchronization via WebSockets.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @rebasepro/postgresql @rebasepro/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Basic Setup with React Hook
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { usePostgresDataSource } from "@rebasepro/postgresql";
|
|
19
|
+
import { Rebase } from "@rebasepro/core";
|
|
20
|
+
|
|
21
|
+
function App() {
|
|
22
|
+
const dataSource = usePostgresDataSource({
|
|
23
|
+
baseUrl: "http://localhost:3001",
|
|
24
|
+
websocketUrl: "ws://localhost:3001", // Optional, will be inferred from baseUrl
|
|
25
|
+
headers: { // Optional
|
|
26
|
+
"Authorization": "Bearer your-token"
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<Rebase
|
|
32
|
+
dataSource={dataSource}
|
|
33
|
+
collections={collections}
|
|
34
|
+
// ... other props
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Creating Data Source Directly
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { createPostgresDataSource } from "@rebasepro/postgresql";
|
|
44
|
+
|
|
45
|
+
const dataSource = createPostgresDataSource({
|
|
46
|
+
baseUrl: "http://localhost:3001",
|
|
47
|
+
websocketUrl: "ws://localhost:3001"
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- **Real-time Synchronization**: WebSocket-based real-time updates for collections and entities
|
|
54
|
+
- **Automatic Reconnection**: Built-in reconnection logic with exponential backoff
|
|
55
|
+
- **Type Safety**: Full TypeScript support with Rebase core types
|
|
56
|
+
- **Error Handling**: Comprehensive error handling with custom error types
|
|
57
|
+
- **Connection Management**: Connection status monitoring and queue management
|
|
58
|
+
|
|
59
|
+
## API
|
|
60
|
+
|
|
61
|
+
### Configuration
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
interface PostgresDataSourceConfig {
|
|
65
|
+
baseUrl: string; // Backend server URL
|
|
66
|
+
websocketUrl?: string; // WebSocket URL (optional)
|
|
67
|
+
headers?: Record<string, string>; // Custom headers (optional)
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Methods
|
|
72
|
+
|
|
73
|
+
The PostgreSQL data source implements all Rebase `DataSource` methods:
|
|
74
|
+
|
|
75
|
+
- `fetchCollection<M>(props): Promise<Entity<M>[]>`
|
|
76
|
+
- `fetchEntity<M>(props): Promise<Entity<M> | undefined>`
|
|
77
|
+
- `saveEntity<M>(props): Promise<Entity<M>>`
|
|
78
|
+
- `deleteEntity<M>(props): Promise<void>`
|
|
79
|
+
- `checkUniqueField(...): Promise<boolean>`
|
|
80
|
+
- `generateEntityId(...): string`
|
|
81
|
+
- `countEntities<M>(props): Promise<number>`
|
|
82
|
+
- `listenCollection<M>(props): () => void`
|
|
83
|
+
- `listenEntity<M>(props): () => void`
|
|
84
|
+
|
|
85
|
+
## Backend Requirements
|
|
86
|
+
|
|
87
|
+
This client expects a WebSocket-enabled backend that handles the following message types:
|
|
88
|
+
|
|
89
|
+
- `FETCH_COLLECTION`
|
|
90
|
+
- `FETCH_ENTITY`
|
|
91
|
+
- `SAVE_ENTITY`
|
|
92
|
+
- `DELETE_ENTITY`
|
|
93
|
+
- `CHECK_UNIQUE_FIELD`
|
|
94
|
+
- `GENERATE_ENTITY_ID`
|
|
95
|
+
- `COUNT_ENTITIES`
|
|
96
|
+
- `subscribe_collection`
|
|
97
|
+
- `subscribe_entity`
|
|
98
|
+
- `unsubscribe`
|
|
99
|
+
|
|
100
|
+
## Development
|
|
101
|
+
|
|
102
|
+
This package is part of the Rebase monorepo. For development instructions, see the main repository README.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @rebasepro/client-postgresql
|
|
3
|
+
*
|
|
4
|
+
* PostgreSQL data source client for Rebase
|
|
5
|
+
* This package provides a WebSocket-based client for connecting Rebase applications
|
|
6
|
+
* to PostgreSQL backends with real-time synchronization capabilities.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./usePostgresClientDriver";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DataDriver } from "@rebasepro/types";
|
|
2
|
+
import { RebaseWebSocketClient } from "@rebasepro/client";
|
|
3
|
+
export interface PostgresDataDriverConfig {
|
|
4
|
+
wsClient?: RebaseWebSocketClient;
|
|
5
|
+
}
|
|
6
|
+
export interface PostgresDataDriver extends DataDriver {
|
|
7
|
+
client?: RebaseWebSocketClient;
|
|
8
|
+
}
|
|
9
|
+
export declare function usePostgresClientDriver(config: PostgresDataDriverConfig): PostgresDataDriver;
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { c } from "react-compiler-runtime";
|
|
2
|
+
function usePostgresClientDriver(config) {
|
|
3
|
+
const $ = c(2);
|
|
4
|
+
const client = config.wsClient;
|
|
5
|
+
let t0;
|
|
6
|
+
if (!client) {
|
|
7
|
+
throw new Error("RebaseWebSocketClient must be provided in config.wsClient");
|
|
8
|
+
}
|
|
9
|
+
let t1;
|
|
10
|
+
if ($[0] !== client) {
|
|
11
|
+
t1 = {
|
|
12
|
+
key: "postgres",
|
|
13
|
+
name: "PostgreSQL",
|
|
14
|
+
client,
|
|
15
|
+
async fetchCollection(props) {
|
|
16
|
+
const {
|
|
17
|
+
path,
|
|
18
|
+
filter,
|
|
19
|
+
limit,
|
|
20
|
+
startAfter,
|
|
21
|
+
orderBy,
|
|
22
|
+
searchString,
|
|
23
|
+
order
|
|
24
|
+
} = props;
|
|
25
|
+
return client.fetchCollection({
|
|
26
|
+
path,
|
|
27
|
+
filter,
|
|
28
|
+
limit,
|
|
29
|
+
startAfter,
|
|
30
|
+
orderBy,
|
|
31
|
+
searchString,
|
|
32
|
+
order
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
async fetchEntity(props_0) {
|
|
36
|
+
const {
|
|
37
|
+
path: path_0,
|
|
38
|
+
entityId,
|
|
39
|
+
databaseId
|
|
40
|
+
} = props_0;
|
|
41
|
+
return client.fetchEntity({
|
|
42
|
+
path: path_0,
|
|
43
|
+
entityId,
|
|
44
|
+
databaseId
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
async saveEntity(props_1) {
|
|
48
|
+
return client.saveEntity({
|
|
49
|
+
path: props_1.path,
|
|
50
|
+
values: props_1.values,
|
|
51
|
+
entityId: props_1.entityId,
|
|
52
|
+
previousValues: props_1.previousValues,
|
|
53
|
+
status: props_1.status
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
async deleteEntity(props_2) {
|
|
57
|
+
const {
|
|
58
|
+
entity
|
|
59
|
+
} = props_2;
|
|
60
|
+
return client.deleteEntity({
|
|
61
|
+
entity
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
async checkUniqueField(path_1, name, value, entityId_0, collection) {
|
|
65
|
+
return client.checkUniqueField(path_1, name, value, entityId_0, collection);
|
|
66
|
+
},
|
|
67
|
+
async countEntities(props_3) {
|
|
68
|
+
const {
|
|
69
|
+
path: path_2,
|
|
70
|
+
filter: filter_0,
|
|
71
|
+
limit: limit_0,
|
|
72
|
+
startAfter: startAfter_0,
|
|
73
|
+
orderBy: orderBy_0,
|
|
74
|
+
searchString: searchString_0,
|
|
75
|
+
order: order_0
|
|
76
|
+
} = props_3;
|
|
77
|
+
return client.countEntities({
|
|
78
|
+
path: path_2,
|
|
79
|
+
filter: filter_0,
|
|
80
|
+
limit: limit_0,
|
|
81
|
+
startAfter: startAfter_0,
|
|
82
|
+
orderBy: orderBy_0,
|
|
83
|
+
searchString: searchString_0,
|
|
84
|
+
order: order_0
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
listenCollection(props_4) {
|
|
88
|
+
const {
|
|
89
|
+
path: path_3,
|
|
90
|
+
filter: filter_1,
|
|
91
|
+
limit: limit_1,
|
|
92
|
+
startAfter: startAfter_1,
|
|
93
|
+
orderBy: orderBy_1,
|
|
94
|
+
searchString: searchString_1,
|
|
95
|
+
order: order_1
|
|
96
|
+
} = props_4;
|
|
97
|
+
return client.listenCollection({
|
|
98
|
+
path: path_3,
|
|
99
|
+
filter: filter_1,
|
|
100
|
+
limit: limit_1,
|
|
101
|
+
startAfter: startAfter_1,
|
|
102
|
+
orderBy: orderBy_1,
|
|
103
|
+
searchString: searchString_1,
|
|
104
|
+
order: order_1
|
|
105
|
+
}, (entities) => props_4.onUpdate(entities), props_4.onError);
|
|
106
|
+
},
|
|
107
|
+
listenEntity(props_5) {
|
|
108
|
+
const {
|
|
109
|
+
path: path_4,
|
|
110
|
+
entityId: entityId_1,
|
|
111
|
+
databaseId: databaseId_0
|
|
112
|
+
} = props_5;
|
|
113
|
+
return client.listenEntity({
|
|
114
|
+
path: path_4,
|
|
115
|
+
entityId: entityId_1,
|
|
116
|
+
databaseId: databaseId_0
|
|
117
|
+
}, (entity_0) => {
|
|
118
|
+
props_5.onUpdate(entity_0);
|
|
119
|
+
}, props_5.onError);
|
|
120
|
+
},
|
|
121
|
+
isFilterCombinationValid() {
|
|
122
|
+
return true;
|
|
123
|
+
},
|
|
124
|
+
async executeSql(sql, options) {
|
|
125
|
+
return client.executeSql(sql, options);
|
|
126
|
+
},
|
|
127
|
+
async fetchAvailableDatabases() {
|
|
128
|
+
return client.fetchAvailableDatabases();
|
|
129
|
+
},
|
|
130
|
+
async fetchAvailableRoles() {
|
|
131
|
+
return client.fetchAvailableRoles();
|
|
132
|
+
},
|
|
133
|
+
async fetchCurrentDatabase() {
|
|
134
|
+
return client.fetchCurrentDatabase();
|
|
135
|
+
},
|
|
136
|
+
async fetchUnmappedTables(mappedPaths) {
|
|
137
|
+
return client.fetchUnmappedTables(mappedPaths);
|
|
138
|
+
},
|
|
139
|
+
async fetchTableMetadata(tableName) {
|
|
140
|
+
return client.fetchTableMetadata(tableName);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
$[0] = client;
|
|
144
|
+
$[1] = t1;
|
|
145
|
+
} else {
|
|
146
|
+
t1 = $[1];
|
|
147
|
+
}
|
|
148
|
+
t0 = t1;
|
|
149
|
+
return t0;
|
|
150
|
+
}
|
|
151
|
+
export {
|
|
152
|
+
usePostgresClientDriver
|
|
153
|
+
};
|
|
154
|
+
//# sourceMappingURL=index.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/usePostgresClientDriver.ts"],"sourcesContent":["import { useMemo, useEffect } from \"react\";\nimport {\n DataDriver,\n DeleteEntityProps,\n Entity,\n EntityCollection,\n EntityReference, EntityRelation,\n FetchCollectionProps,\n FetchEntityProps,\n ListenCollectionProps,\n ListenEntityProps,\n SaveEntityProps,\n TableMetadata\n} from \"@rebasepro/types\";\nimport { RebaseWebSocketClient } from \"@rebasepro/client\";\n\nexport interface PostgresDataDriverConfig {\n wsClient?: RebaseWebSocketClient;\n}\n\nexport interface PostgresDataDriver extends DataDriver {\n client?: RebaseWebSocketClient;\n}\n\n\nexport function usePostgresClientDriver(config: PostgresDataDriverConfig): PostgresDataDriver {\n const client = config.wsClient;\n\n return useMemo(() => {\n if (!client) throw new Error(\"RebaseWebSocketClient must be provided in config.wsClient\");\n \n return {\n\n key: \"postgres\",\n\n name: \"PostgreSQL\",\n\n client,\n\n async fetchCollection<M extends Record<string, any>>(props: FetchCollectionProps<M>): Promise<Entity<M>[]> {\n // Pick only the fields the client needs, ignoring extra fields from the CMS layer\n const { path, filter, limit, startAfter, orderBy, searchString, order } = props;\n return client.fetchCollection({ path, filter, limit, startAfter, orderBy, searchString, order }) as Promise<Entity<M>[]>;\n },\n\n async fetchEntity<M extends Record<string, any>>(props: FetchEntityProps<M>): Promise<Entity<M> | undefined> {\n const { path, entityId, databaseId } = props;\n return client.fetchEntity({ path, entityId, databaseId }) as Promise<Entity<M> | undefined>;\n },\n\n async saveEntity<M extends Record<string, any>>(props: SaveEntityProps<M>): Promise<Entity<M>> {\n return client.saveEntity({\n path: props.path,\n values: props.values,\n entityId: props.entityId,\n previousValues: props.previousValues,\n status: props.status\n }) as Promise<Entity<M>>;\n },\n\n async deleteEntity<M extends Record<string, any>>(props: DeleteEntityProps<M>): Promise<void> {\n const { entity } = props;\n return client.deleteEntity({ entity });\n },\n\n async checkUniqueField(path: string, name: string, value: any, entityId?: string, collection?: EntityCollection): Promise<boolean> {\n return client.checkUniqueField(path, name, value, entityId, collection);\n },\n\n async countEntities<M extends Record<string, any>>(props: FetchCollectionProps<M>): Promise<number> {\n const { path, filter, limit, startAfter, orderBy, searchString, order } = props;\n return client.countEntities({ path, filter, limit, startAfter, orderBy, searchString, order });\n },\n\n listenCollection<M extends Record<string, any>>(props: ListenCollectionProps<M>): () => void {\n const { path, filter, limit, startAfter, orderBy, searchString, order, onUpdate, onError } = props;\n return client.listenCollection(\n { path, filter, limit, startAfter, orderBy, searchString, order },\n (entities: Entity[]) => props.onUpdate(entities as Entity<M>[]),\n props.onError\n );\n },\n\n listenEntity<M extends Record<string, any>>(props: ListenEntityProps<M>): () => void {\n const { path, entityId, databaseId, onUpdate, onError } = props;\n return client.listenEntity(\n { path, entityId, databaseId },\n (entity: Entity | null) => {\n props.onUpdate(entity as Entity<M> | null);\n },\n props.onError\n );\n },\n\n isFilterCombinationValid(): boolean {\n return true; // PostgreSQL supports complex filter combinations\n },\n\n async executeSql(sql: string, options?: { database?: string, role?: string }): Promise<any[]> {\n return client.executeSql(sql, options);\n },\n\n async fetchAvailableDatabases(): Promise<string[]> {\n return client.fetchAvailableDatabases();\n },\n\n async fetchAvailableRoles(): Promise<string[]> {\n return client.fetchAvailableRoles();\n },\n\n async fetchCurrentDatabase(): Promise<string | undefined> {\n return client.fetchCurrentDatabase();\n },\n\n async fetchUnmappedTables(mappedPaths?: string[]): Promise<string[]> {\n return client.fetchUnmappedTables(mappedPaths);\n },\n\n async fetchTableMetadata(tableName: string): Promise<TableMetadata> {\n return client.fetchTableMetadata(tableName);\n }\n } as PostgresDataDriver;\n }, [client]);\n\n}\n"],"names":["usePostgresClientDriver","config","$","_c","client","wsClient","t0","Error","t1","key","name","fetchCollection","props","path","filter","limit","startAfter","orderBy","searchString","order","fetchEntity","props_0","path_0","entityId","databaseId","saveEntity","props_1","values","previousValues","status","deleteEntity","props_2","entity","checkUniqueField","path_1","value","entityId_0","collection","countEntities","props_3","path_2","filter_0","limit_0","startAfter_0","orderBy_0","searchString_0","order_0","listenCollection","props_4","path_3","filter_1","limit_1","startAfter_1","orderBy_1","searchString_1","order_1","entities","onUpdate","onError","listenEntity","props_5","path_4","entityId_1","databaseId_0","entity_0","isFilterCombinationValid","executeSql","sql","options","fetchAvailableDatabases","fetchAvailableRoles","fetchCurrentDatabase","fetchUnmappedTables","mappedPaths","fetchTableMetadata","tableName"],"mappings":";AAyBO,SAAAA,wBAAAC,QAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA;AACH,QAAAC,SAAeH,OAAMI;AAAU,MAAAC;AAAA,MAAA,CAGtBF,QAAM;AAAA,UAAA,IAAAG,MAAkB,2DAA2D;AAAA,EAAA;AAAA,MAAAC;AAAA,MAAAN,SAAAE,QAAA;AAEjFI,SAAA;AAAA,MAAAC,KAEF;AAAA,MAAUC,MAET;AAAA,MAAYN;AAAAA,MAAA,MAAAO,gBAAAC,OAAA;AAMd,cAAA;AAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,QAAAA,IAA0EP;AAAM,eACzER,OAAMO,gBAAA;AAAA,UAAAE;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,QAAAA,CAAkF;AAAA,MAAyB;AAAA,MAAA,MAAAC,YAAAC,SAAA;AAIx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C,WAAW;AAAA,MAAC;AAAA,MAAA,MAAAC,mBAAAC,WAAA;AAAA,eAIvCvE,OAAMsE,mBAAoBC,SAAS;AAAA,MAAC;AAAA,IAAA;AAElDzE,WAAAE;AAAAF,WAAAM;AAAAA,EAAA,OAAA;AAAAA,SAAAN,EAAA,CAAA;AAAA,EAAA;AA1FGI,OAAOE;AA0Fa,SA7FjBF;AA8FK;"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react-compiler-runtime")) : typeof define === "function" && define.amd ? define(["exports", "react-compiler-runtime"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["Rebase PostgreSQL"] = {}, global.reactCompilerRuntime));
|
|
3
|
+
})(this, function(exports2, reactCompilerRuntime) {
|
|
4
|
+
"use strict";
|
|
5
|
+
function usePostgresClientDriver(config) {
|
|
6
|
+
const $ = reactCompilerRuntime.c(2);
|
|
7
|
+
const client = config.wsClient;
|
|
8
|
+
let t0;
|
|
9
|
+
if (!client) {
|
|
10
|
+
throw new Error("RebaseWebSocketClient must be provided in config.wsClient");
|
|
11
|
+
}
|
|
12
|
+
let t1;
|
|
13
|
+
if ($[0] !== client) {
|
|
14
|
+
t1 = {
|
|
15
|
+
key: "postgres",
|
|
16
|
+
name: "PostgreSQL",
|
|
17
|
+
client,
|
|
18
|
+
async fetchCollection(props) {
|
|
19
|
+
const {
|
|
20
|
+
path,
|
|
21
|
+
filter,
|
|
22
|
+
limit,
|
|
23
|
+
startAfter,
|
|
24
|
+
orderBy,
|
|
25
|
+
searchString,
|
|
26
|
+
order
|
|
27
|
+
} = props;
|
|
28
|
+
return client.fetchCollection({
|
|
29
|
+
path,
|
|
30
|
+
filter,
|
|
31
|
+
limit,
|
|
32
|
+
startAfter,
|
|
33
|
+
orderBy,
|
|
34
|
+
searchString,
|
|
35
|
+
order
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
async fetchEntity(props_0) {
|
|
39
|
+
const {
|
|
40
|
+
path: path_0,
|
|
41
|
+
entityId,
|
|
42
|
+
databaseId
|
|
43
|
+
} = props_0;
|
|
44
|
+
return client.fetchEntity({
|
|
45
|
+
path: path_0,
|
|
46
|
+
entityId,
|
|
47
|
+
databaseId
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
async saveEntity(props_1) {
|
|
51
|
+
return client.saveEntity({
|
|
52
|
+
path: props_1.path,
|
|
53
|
+
values: props_1.values,
|
|
54
|
+
entityId: props_1.entityId,
|
|
55
|
+
previousValues: props_1.previousValues,
|
|
56
|
+
status: props_1.status
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
async deleteEntity(props_2) {
|
|
60
|
+
const {
|
|
61
|
+
entity
|
|
62
|
+
} = props_2;
|
|
63
|
+
return client.deleteEntity({
|
|
64
|
+
entity
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
async checkUniqueField(path_1, name, value, entityId_0, collection) {
|
|
68
|
+
return client.checkUniqueField(path_1, name, value, entityId_0, collection);
|
|
69
|
+
},
|
|
70
|
+
async countEntities(props_3) {
|
|
71
|
+
const {
|
|
72
|
+
path: path_2,
|
|
73
|
+
filter: filter_0,
|
|
74
|
+
limit: limit_0,
|
|
75
|
+
startAfter: startAfter_0,
|
|
76
|
+
orderBy: orderBy_0,
|
|
77
|
+
searchString: searchString_0,
|
|
78
|
+
order: order_0
|
|
79
|
+
} = props_3;
|
|
80
|
+
return client.countEntities({
|
|
81
|
+
path: path_2,
|
|
82
|
+
filter: filter_0,
|
|
83
|
+
limit: limit_0,
|
|
84
|
+
startAfter: startAfter_0,
|
|
85
|
+
orderBy: orderBy_0,
|
|
86
|
+
searchString: searchString_0,
|
|
87
|
+
order: order_0
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
listenCollection(props_4) {
|
|
91
|
+
const {
|
|
92
|
+
path: path_3,
|
|
93
|
+
filter: filter_1,
|
|
94
|
+
limit: limit_1,
|
|
95
|
+
startAfter: startAfter_1,
|
|
96
|
+
orderBy: orderBy_1,
|
|
97
|
+
searchString: searchString_1,
|
|
98
|
+
order: order_1
|
|
99
|
+
} = props_4;
|
|
100
|
+
return client.listenCollection({
|
|
101
|
+
path: path_3,
|
|
102
|
+
filter: filter_1,
|
|
103
|
+
limit: limit_1,
|
|
104
|
+
startAfter: startAfter_1,
|
|
105
|
+
orderBy: orderBy_1,
|
|
106
|
+
searchString: searchString_1,
|
|
107
|
+
order: order_1
|
|
108
|
+
}, (entities) => props_4.onUpdate(entities), props_4.onError);
|
|
109
|
+
},
|
|
110
|
+
listenEntity(props_5) {
|
|
111
|
+
const {
|
|
112
|
+
path: path_4,
|
|
113
|
+
entityId: entityId_1,
|
|
114
|
+
databaseId: databaseId_0
|
|
115
|
+
} = props_5;
|
|
116
|
+
return client.listenEntity({
|
|
117
|
+
path: path_4,
|
|
118
|
+
entityId: entityId_1,
|
|
119
|
+
databaseId: databaseId_0
|
|
120
|
+
}, (entity_0) => {
|
|
121
|
+
props_5.onUpdate(entity_0);
|
|
122
|
+
}, props_5.onError);
|
|
123
|
+
},
|
|
124
|
+
isFilterCombinationValid() {
|
|
125
|
+
return true;
|
|
126
|
+
},
|
|
127
|
+
async executeSql(sql, options) {
|
|
128
|
+
return client.executeSql(sql, options);
|
|
129
|
+
},
|
|
130
|
+
async fetchAvailableDatabases() {
|
|
131
|
+
return client.fetchAvailableDatabases();
|
|
132
|
+
},
|
|
133
|
+
async fetchAvailableRoles() {
|
|
134
|
+
return client.fetchAvailableRoles();
|
|
135
|
+
},
|
|
136
|
+
async fetchCurrentDatabase() {
|
|
137
|
+
return client.fetchCurrentDatabase();
|
|
138
|
+
},
|
|
139
|
+
async fetchUnmappedTables(mappedPaths) {
|
|
140
|
+
return client.fetchUnmappedTables(mappedPaths);
|
|
141
|
+
},
|
|
142
|
+
async fetchTableMetadata(tableName) {
|
|
143
|
+
return client.fetchTableMetadata(tableName);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
$[0] = client;
|
|
147
|
+
$[1] = t1;
|
|
148
|
+
} else {
|
|
149
|
+
t1 = $[1];
|
|
150
|
+
}
|
|
151
|
+
t0 = t1;
|
|
152
|
+
return t0;
|
|
153
|
+
}
|
|
154
|
+
exports2.usePostgresClientDriver = usePostgresClientDriver;
|
|
155
|
+
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
156
|
+
});
|
|
157
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/usePostgresClientDriver.ts"],"sourcesContent":["import { useMemo, useEffect } from \"react\";\nimport {\n DataDriver,\n DeleteEntityProps,\n Entity,\n EntityCollection,\n EntityReference, EntityRelation,\n FetchCollectionProps,\n FetchEntityProps,\n ListenCollectionProps,\n ListenEntityProps,\n SaveEntityProps,\n TableMetadata\n} from \"@rebasepro/types\";\nimport { RebaseWebSocketClient } from \"@rebasepro/client\";\n\nexport interface PostgresDataDriverConfig {\n wsClient?: RebaseWebSocketClient;\n}\n\nexport interface PostgresDataDriver extends DataDriver {\n client?: RebaseWebSocketClient;\n}\n\n\nexport function usePostgresClientDriver(config: PostgresDataDriverConfig): PostgresDataDriver {\n const client = config.wsClient;\n\n return useMemo(() => {\n if (!client) throw new Error(\"RebaseWebSocketClient must be provided in config.wsClient\");\n \n return {\n\n key: \"postgres\",\n\n name: \"PostgreSQL\",\n\n client,\n\n async fetchCollection<M extends Record<string, any>>(props: FetchCollectionProps<M>): Promise<Entity<M>[]> {\n // Pick only the fields the client needs, ignoring extra fields from the CMS layer\n const { path, filter, limit, startAfter, orderBy, searchString, order } = props;\n return client.fetchCollection({ path, filter, limit, startAfter, orderBy, searchString, order }) as Promise<Entity<M>[]>;\n },\n\n async fetchEntity<M extends Record<string, any>>(props: FetchEntityProps<M>): Promise<Entity<M> | undefined> {\n const { path, entityId, databaseId } = props;\n return client.fetchEntity({ path, entityId, databaseId }) as Promise<Entity<M> | undefined>;\n },\n\n async saveEntity<M extends Record<string, any>>(props: SaveEntityProps<M>): Promise<Entity<M>> {\n return client.saveEntity({\n path: props.path,\n values: props.values,\n entityId: props.entityId,\n previousValues: props.previousValues,\n status: props.status\n }) as Promise<Entity<M>>;\n },\n\n async deleteEntity<M extends Record<string, any>>(props: DeleteEntityProps<M>): Promise<void> {\n const { entity } = props;\n return client.deleteEntity({ entity });\n },\n\n async checkUniqueField(path: string, name: string, value: any, entityId?: string, collection?: EntityCollection): Promise<boolean> {\n return client.checkUniqueField(path, name, value, entityId, collection);\n },\n\n async countEntities<M extends Record<string, any>>(props: FetchCollectionProps<M>): Promise<number> {\n const { path, filter, limit, startAfter, orderBy, searchString, order } = props;\n return client.countEntities({ path, filter, limit, startAfter, orderBy, searchString, order });\n },\n\n listenCollection<M extends Record<string, any>>(props: ListenCollectionProps<M>): () => void {\n const { path, filter, limit, startAfter, orderBy, searchString, order, onUpdate, onError } = props;\n return client.listenCollection(\n { path, filter, limit, startAfter, orderBy, searchString, order },\n (entities: Entity[]) => props.onUpdate(entities as Entity<M>[]),\n props.onError\n );\n },\n\n listenEntity<M extends Record<string, any>>(props: ListenEntityProps<M>): () => void {\n const { path, entityId, databaseId, onUpdate, onError } = props;\n return client.listenEntity(\n { path, entityId, databaseId },\n (entity: Entity | null) => {\n props.onUpdate(entity as Entity<M> | null);\n },\n props.onError\n );\n },\n\n isFilterCombinationValid(): boolean {\n return true; // PostgreSQL supports complex filter combinations\n },\n\n async executeSql(sql: string, options?: { database?: string, role?: string }): Promise<any[]> {\n return client.executeSql(sql, options);\n },\n\n async fetchAvailableDatabases(): Promise<string[]> {\n return client.fetchAvailableDatabases();\n },\n\n async fetchAvailableRoles(): Promise<string[]> {\n return client.fetchAvailableRoles();\n },\n\n async fetchCurrentDatabase(): Promise<string | undefined> {\n return client.fetchCurrentDatabase();\n },\n\n async fetchUnmappedTables(mappedPaths?: string[]): Promise<string[]> {\n return client.fetchUnmappedTables(mappedPaths);\n },\n\n async fetchTableMetadata(tableName: string): Promise<TableMetadata> {\n return client.fetchTableMetadata(tableName);\n }\n } as PostgresDataDriver;\n }, [client]);\n\n}\n"],"names":["usePostgresClientDriver","config","$","_c","client","wsClient","t0","Error","t1","key","name","fetchCollection","props","path","filter","limit","startAfter","orderBy","searchString","order","fetchEntity","props_0","path_0","entityId","databaseId","saveEntity","props_1","values","previousValues","status","deleteEntity","props_2","entity","checkUniqueField","path_1","value","entityId_0","collection","countEntities","props_3","path_2","filter_0","limit_0","startAfter_0","orderBy_0","searchString_0","order_0","listenCollection","props_4","path_3","filter_1","limit_1","startAfter_1","orderBy_1","searchString_1","order_1","entities","onUpdate","onError","listenEntity","props_5","path_4","entityId_1","databaseId_0","entity_0","isFilterCombinationValid","executeSql","sql","options","fetchAvailableDatabases","fetchAvailableRoles","fetchCurrentDatabase","fetchUnmappedTables","mappedPaths","fetchTableMetadata","tableName"],"mappings":";;;;AAyBO,WAAAA,wBAAAC,QAAA;AAAA,UAAAC,IAAAC,qBAAAA,EAAA,CAAA;AACH,UAAAC,SAAeH,OAAMI;AAAU,QAAAC;AAAA,QAAA,CAGtBF,QAAM;AAAA,YAAA,IAAAG,MAAkB,2DAA2D;AAAA,IAAA;AAAA,QAAAC;AAAA,QAAAN,SAAAE,QAAA;AAEjFI,WAAA;AAAA,QAAAC,KAEF;AAAA,QAAUC,MAET;AAAA,QAAYN;AAAAA,QAAA,MAAAO,gBAAAC,OAAA;AAMd,gBAAA;AAAA,YAAAC;AAAAA,YAAAC;AAAAA,YAAAC;AAAAA,YAAAC;AAAAA,YAAAC;AAAAA,YAAAC;AAAAA,YAAAC;AAAAA,UAAAA,IAA0EP;AAAM,iBACzER,OAAMO,gBAAA;AAAA,YAAAE;AAAAA,YAAAC;AAAAA,YAAAC;AAAAA,YAAAC;AAAAA,YAAAC;AAAAA,YAAAC;AAAAA,YAAAC;AAAAA,UAAAA,CAAkF;AAAA,QAAyB;AAAA,QAAA,MAAAC,YAA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AA;AAAA,iBAI7BrE,OAAMoE,oBAAqBC,WAAW;AAAA,QAAC;AAAA,QAAA,MAAAC,mBAAAC,WAAA;AAAA,iBAIvCvE,OAAMsE,mBAAoBC,SAAS;AAAA,QAAC;AAAA,MAAA;AAElDzE,aAAAE;AAAAF,aAAAM;AAAAA,IAAA,OAAA;AAAAA,WAAAN,EAAA,CAAA;AAAA,IAAA;AA1FGI,SAAOE;AA0Fa,WA7FjBF;AAAAA,EA8FK;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type AnalyticsController = {
|
|
2
|
+
/**
|
|
3
|
+
* Callback used to get analytics events from the CMS
|
|
4
|
+
*/
|
|
5
|
+
onAnalyticsEvent?: (event: AnalyticsEvent, data?: object) => void;
|
|
6
|
+
};
|
|
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";
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { StorageSource } from "./storage";
|
|
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
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Controller for retrieving the logged user or performing auth related operations.
|
|
21
|
+
* Note that if you are implementing your AuthController, you probably will want
|
|
22
|
+
* to do it as the result of a hook.
|
|
23
|
+
* @group Hooks and utilities
|
|
24
|
+
*/
|
|
25
|
+
export type AuthController<USER extends User = User, ExtraData = unknown> = {
|
|
26
|
+
/**
|
|
27
|
+
* The user currently logged in
|
|
28
|
+
* The values can be: the user object, null if they skipped login
|
|
29
|
+
*/
|
|
30
|
+
user: USER | null;
|
|
31
|
+
/**
|
|
32
|
+
* Initial loading flag. It is used not to display the login screen
|
|
33
|
+
* when the app first loads, and it has not been checked whether the user
|
|
34
|
+
* is logged in or not.
|
|
35
|
+
*/
|
|
36
|
+
initialLoading?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Loading flag. It is used to display a loading screen when the user is
|
|
39
|
+
* logging in or out.
|
|
40
|
+
*/
|
|
41
|
+
authLoading: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Sign out
|
|
44
|
+
*/
|
|
45
|
+
signOut: () => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Error initializing the authentication
|
|
48
|
+
*/
|
|
49
|
+
authError?: unknown;
|
|
50
|
+
/**
|
|
51
|
+
* Error dispatched by the auth provider
|
|
52
|
+
*/
|
|
53
|
+
authProviderError?: unknown;
|
|
54
|
+
/**
|
|
55
|
+
* You can use this method to retrieve the auth token for the current user.
|
|
56
|
+
*/
|
|
57
|
+
getAuthToken: () => Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Has the user skipped the login process
|
|
60
|
+
*/
|
|
61
|
+
loginSkipped: boolean;
|
|
62
|
+
extra: ExtraData;
|
|
63
|
+
setExtra: (extra: ExtraData) => void;
|
|
64
|
+
setUser?(user: USER | null): void;
|
|
65
|
+
setUserRoles?(roles: Role[]): void;
|
|
66
|
+
/**
|
|
67
|
+
* Capabilities advertised by the auth provider.
|
|
68
|
+
* UI components use this to feature-detect what the backend supports.
|
|
69
|
+
*/
|
|
70
|
+
capabilities?: AuthCapabilities;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Extended auth controller with common optional auth methods.
|
|
74
|
+
* Backend implementations (Rebase backend, Firebase, Supabase, etc.)
|
|
75
|
+
* extend this with their own backend-specific extras.
|
|
76
|
+
* @group Hooks and utilities
|
|
77
|
+
*/
|
|
78
|
+
export interface AuthControllerExtended<USER extends User = User, ExtraData = unknown> extends AuthController<USER, ExtraData> {
|
|
79
|
+
/** Login with email and password */
|
|
80
|
+
emailPasswordLogin?(email: string, password: string): Promise<void>;
|
|
81
|
+
/** Login with a Google ID token or trigger Google popup */
|
|
82
|
+
googleLogin?(idToken: string): Promise<void>;
|
|
83
|
+
/** Register a new user */
|
|
84
|
+
register?(email: string, password: string, displayName?: string): Promise<void>;
|
|
85
|
+
/** Skip login (for anonymous access if enabled) */
|
|
86
|
+
skipLogin?(): void;
|
|
87
|
+
/** Request password reset email */
|
|
88
|
+
forgotPassword?(email: string): Promise<void>;
|
|
89
|
+
/** Reset password using a token */
|
|
90
|
+
resetPassword?(token: string, password: string): Promise<void>;
|
|
91
|
+
/** Change password for the authenticated user */
|
|
92
|
+
changePassword?(oldPassword: string, newPassword: string): Promise<void>;
|
|
93
|
+
/** Update user profile */
|
|
94
|
+
updateProfile?(displayName?: string, photoURL?: string): Promise<USER>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Implement this function to allow access to specific users.
|
|
98
|
+
* @group Hooks and utilities
|
|
99
|
+
*/
|
|
100
|
+
export type Authenticator<USER extends User = User> = (props: {
|
|
101
|
+
/**
|
|
102
|
+
* Logged-in user or null
|
|
103
|
+
*/
|
|
104
|
+
user: USER | null;
|
|
105
|
+
/**
|
|
106
|
+
* AuthController
|
|
107
|
+
*/
|
|
108
|
+
authController: AuthController<USER>;
|
|
109
|
+
/**
|
|
110
|
+
* Unified data access API
|
|
111
|
+
*/
|
|
112
|
+
data: RebaseData;
|
|
113
|
+
/**
|
|
114
|
+
* Used storage implementation
|
|
115
|
+
*/
|
|
116
|
+
storageSource: StorageSource;
|
|
117
|
+
}) => boolean | Promise<boolean>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { User } from "../users";
|
|
2
|
+
import { RebaseData } from "./data";
|
|
3
|
+
/**
|
|
4
|
+
* Event type for authentication state changes
|
|
5
|
+
*/
|
|
6
|
+
export type AuthChangeEvent = 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED' | 'USER_UPDATED';
|
|
7
|
+
/**
|
|
8
|
+
* Standard session interface representing an authenticated state
|
|
9
|
+
*/
|
|
10
|
+
export interface RebaseSession {
|
|
11
|
+
accessToken: string;
|
|
12
|
+
refreshToken: string;
|
|
13
|
+
expiresAt: number;
|
|
14
|
+
user: User;
|
|
15
|
+
}
|
|
16
|
+
import { StorageSource } from "./storage";
|
|
17
|
+
/**
|
|
18
|
+
* Unified Authentication Client Interface
|
|
19
|
+
* Pure functional SDK interface, decoupled from UI and React hooks
|
|
20
|
+
*/
|
|
21
|
+
export interface AuthClient {
|
|
22
|
+
/**
|
|
23
|
+
* Get the current user from the server or cache
|
|
24
|
+
*/
|
|
25
|
+
getUser(): Promise<User | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Get the currently active session
|
|
28
|
+
*/
|
|
29
|
+
getSession(): RebaseSession | null;
|
|
30
|
+
/**
|
|
31
|
+
* Sign out the current user and clear local session
|
|
32
|
+
*/
|
|
33
|
+
signOut(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Subscribe to authentication state changes
|
|
36
|
+
*/
|
|
37
|
+
onAuthStateChange(callback: (event: AuthChangeEvent, session: RebaseSession | null) => void): () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Manually refresh the session token
|
|
40
|
+
*/
|
|
41
|
+
refreshSession(): Promise<RebaseSession>;
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Overarching abstraction that unites Data, Auth, and Storage.
|
|
46
|
+
* Adapters for Supabase or Firebase simply need to implement this interface.
|
|
47
|
+
*/
|
|
48
|
+
export interface RebaseClient<DB = any> {
|
|
49
|
+
/** Unified Data access layer */
|
|
50
|
+
data: RebaseData;
|
|
51
|
+
/** Unified Authentication layer */
|
|
52
|
+
auth: AuthClient;
|
|
53
|
+
/** Unified Storage layer */
|
|
54
|
+
storage?: StorageSource;
|
|
55
|
+
/** Optional admin panel specific tasks */
|
|
56
|
+
admin?: any;
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
}
|