@rebasepro/client-postgresql 0.4.0 → 0.6.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.
- package/README.md +51 -83
- package/dist/index.es.js +117 -163
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +121 -166
- package/dist/index.umd.js.map +1 -1
- package/package.json +12 -10
- package/test/usePostgresClientDriver.test.tsx +101 -0
- package/tsconfig.json +2 -0
- package/tsconfig.prod.json +4 -1
- package/vite.config.ts +0 -1
- package/dist/client/src/admin.d.ts +0 -61
- package/dist/client/src/auth.d.ts +0 -178
- package/dist/client/src/collection.d.ts +0 -21
- package/dist/client/src/cron.d.ts +0 -25
- package/dist/client/src/functions.d.ts +0 -49
- package/dist/client/src/index.d.ts +0 -48
- package/dist/client/src/query_builder.d.ts +0 -1
- package/dist/client/src/reviver.d.ts +0 -1
- package/dist/client/src/storage.d.ts +0 -3
- package/dist/client/src/transport.d.ts +0 -33
- package/dist/client/src/websocket.d.ts +0 -105
- package/dist/types/src/controllers/analytics_controller.d.ts +0 -7
- package/dist/types/src/controllers/auth.d.ts +0 -104
- package/dist/types/src/controllers/client.d.ts +0 -168
- package/dist/types/src/controllers/collection_registry.d.ts +0 -46
- package/dist/types/src/controllers/customization_controller.d.ts +0 -60
- package/dist/types/src/controllers/data.d.ts +0 -207
- package/dist/types/src/controllers/data_driver.d.ts +0 -218
- package/dist/types/src/controllers/database_admin.d.ts +0 -11
- package/dist/types/src/controllers/dialogs_controller.d.ts +0 -36
- package/dist/types/src/controllers/effective_role.d.ts +0 -4
- package/dist/types/src/controllers/email.d.ts +0 -36
- package/dist/types/src/controllers/index.d.ts +0 -18
- package/dist/types/src/controllers/local_config_persistence.d.ts +0 -20
- package/dist/types/src/controllers/navigation.d.ts +0 -225
- package/dist/types/src/controllers/registry.d.ts +0 -63
- package/dist/types/src/controllers/side_dialogs_controller.d.ts +0 -67
- package/dist/types/src/controllers/side_entity_controller.d.ts +0 -97
- package/dist/types/src/controllers/snackbar.d.ts +0 -24
- package/dist/types/src/controllers/storage.d.ts +0 -171
- package/dist/types/src/index.d.ts +0 -4
- package/dist/types/src/rebase_context.d.ts +0 -122
- package/dist/types/src/types/auth_adapter.d.ts +0 -301
- package/dist/types/src/types/backend.d.ts +0 -536
- package/dist/types/src/types/backend_hooks.d.ts +0 -172
- package/dist/types/src/types/builders.d.ts +0 -15
- package/dist/types/src/types/chips.d.ts +0 -5
- package/dist/types/src/types/collections.d.ts +0 -941
- package/dist/types/src/types/component_ref.d.ts +0 -47
- package/dist/types/src/types/cron.d.ts +0 -102
- package/dist/types/src/types/data_source.d.ts +0 -64
- package/dist/types/src/types/database_adapter.d.ts +0 -94
- package/dist/types/src/types/entities.d.ts +0 -145
- package/dist/types/src/types/entity_actions.d.ts +0 -104
- package/dist/types/src/types/entity_callbacks.d.ts +0 -173
- package/dist/types/src/types/entity_link_builder.d.ts +0 -7
- package/dist/types/src/types/entity_overrides.d.ts +0 -10
- package/dist/types/src/types/entity_views.d.ts +0 -87
- package/dist/types/src/types/export_import.d.ts +0 -21
- package/dist/types/src/types/formex.d.ts +0 -40
- package/dist/types/src/types/index.d.ts +0 -28
- package/dist/types/src/types/locales.d.ts +0 -4
- package/dist/types/src/types/modify_collections.d.ts +0 -5
- package/dist/types/src/types/plugins.d.ts +0 -282
- package/dist/types/src/types/properties.d.ts +0 -1181
- package/dist/types/src/types/property_config.d.ts +0 -74
- package/dist/types/src/types/relations.d.ts +0 -336
- package/dist/types/src/types/slots.d.ts +0 -262
- package/dist/types/src/types/translations.d.ts +0 -900
- package/dist/types/src/types/user_management_delegate.d.ts +0 -86
- package/dist/types/src/types/websockets.d.ts +0 -78
- package/dist/types/src/users/index.d.ts +0 -1
- package/dist/types/src/users/user.d.ts +0 -50
- /package/dist/{client-postgresql/src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{client-postgresql/src/usePostgresClientDriver.d.ts → usePostgresClientDriver.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,106 +1,74 @@
|
|
|
1
|
-
# @rebasepro/postgresql
|
|
1
|
+
# @rebasepro/client-postgresql
|
|
2
2
|
|
|
3
|
-
PostgreSQL data source client for Rebase
|
|
4
|
-
|
|
5
|
-
This package provides a complete client-side implementation for connecting Rebase applications to PostgreSQL backends, featuring real-time synchronization via WebSockets.
|
|
3
|
+
PostgreSQL data source client for Rebase — connects the Rebase admin panel to a PostgreSQL backend via WebSocket.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
|
-
|
|
8
|
+
pnpm add @rebasepro/client-postgresql
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
**Peer dependencies:** `react >= 19.0.0`, `react-dom >= 19.0.0`
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
## What This Package Does
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
import { usePostgresDataSource } from "@rebasepro/postgresql";
|
|
19
|
-
import { Rebase } from "@rebasepro/core";
|
|
15
|
+
This package provides a `DataDriver` implementation that bridges Rebase's data layer to a PostgreSQL backend through `@rebasepro/client`'s WebSocket client. It supports full CRUD, realtime collection/entity listeners, unique field validation, entity counting, and admin operations (SQL execution, branch management, table introspection).
|
|
20
16
|
|
|
21
|
-
|
|
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
|
-
});
|
|
17
|
+
## Key Exports
|
|
29
18
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
```
|
|
19
|
+
| Export | Type | Description |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `usePostgresClientDriver` | Hook | Creates a `PostgresDataDriver` from a `RebaseWebSocketClient` |
|
|
22
|
+
| `PostgresDataDriverConfig` | Type | Config object: `{ wsClient: RebaseWebSocketClient }` |
|
|
23
|
+
| `PostgresDataDriver` | Type | Extends `DataDriver` with a `client` reference and `admin` methods |
|
|
39
24
|
|
|
40
|
-
###
|
|
25
|
+
### `PostgresDataDriver` Methods
|
|
41
26
|
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
| Method | Description |
|
|
28
|
+
|---|---|
|
|
29
|
+
| `fetchCollection(props)` | Fetch a list of entities with filtering, sorting, pagination, and search |
|
|
30
|
+
| `fetchEntity(props)` | Fetch a single entity by path and ID |
|
|
31
|
+
| `saveEntity(props)` | Create or update an entity |
|
|
32
|
+
| `deleteEntity(props)` | Delete an entity |
|
|
33
|
+
| `checkUniqueField(path, name, value, entityId?, collection?)` | Check if a field value is unique |
|
|
34
|
+
| `countEntities(props)` | Count entities matching filter criteria |
|
|
35
|
+
| `listenCollection(props)` | Subscribe to realtime collection updates. Returns an unsubscribe function |
|
|
36
|
+
| `listenEntity(props)` | Subscribe to realtime entity updates. Returns an unsubscribe function |
|
|
37
|
+
| `isFilterCombinationValid()` | Always returns `true` — PostgreSQL supports complex filter combinations |
|
|
44
38
|
|
|
45
|
-
|
|
46
|
-
baseUrl: "http://localhost:3001",
|
|
47
|
-
websocketUrl: "ws://localhost:3001"
|
|
48
|
-
});
|
|
49
|
-
```
|
|
39
|
+
### Admin Methods (`driver.admin`)
|
|
50
40
|
|
|
51
|
-
|
|
41
|
+
| Method | Description |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `executeSql(sql, options?)` | Execute raw SQL. Options: `{ database?, role? }` |
|
|
44
|
+
| `fetchAvailableDatabases()` | List available databases |
|
|
45
|
+
| `fetchAvailableRoles()` | List available roles |
|
|
46
|
+
| `fetchCurrentDatabase()` | Get the current database name |
|
|
47
|
+
| `fetchUnmappedTables(mappedPaths?)` | Find tables not yet mapped to collections |
|
|
48
|
+
| `fetchTableMetadata(tableName)` | Get column/constraint metadata for a table |
|
|
49
|
+
| `createBranch(name, options?)` | Create a database branch. Options: `{ source? }` |
|
|
50
|
+
| `deleteBranch(name)` | Delete a database branch |
|
|
51
|
+
| `listBranches()` | List all branches |
|
|
52
52
|
|
|
53
|
-
|
|
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
|
|
53
|
+
## Quick Start
|
|
58
54
|
|
|
59
|
-
|
|
55
|
+
```tsx
|
|
56
|
+
import { usePostgresClientDriver } from "@rebasepro/client-postgresql";
|
|
57
|
+
import { RebaseWebSocketClient } from "@rebasepro/client";
|
|
60
58
|
|
|
61
|
-
|
|
59
|
+
const wsClient = new RebaseWebSocketClient({ url: "ws://localhost:4100" });
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
function App() {
|
|
62
|
+
const driver = usePostgresClientDriver({ wsClient });
|
|
63
|
+
|
|
64
|
+
// Pass to your Rebase app as the data driver
|
|
65
|
+
return (
|
|
66
|
+
<Rebase driver={driver} /* ...other props */ />
|
|
67
|
+
);
|
|
68
68
|
}
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
|
|
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
|
|
71
|
+
## Related Packages
|
|
105
72
|
|
|
106
|
-
|
|
73
|
+
- `@rebasepro/client` — Provides `RebaseWebSocketClient` used for communication
|
|
74
|
+
- `@rebasepro/types` — Shared types (`DataDriver`, `Entity`, `EntityCollection`, etc.)
|
package/dist/index.es.js
CHANGED
|
@@ -1,165 +1,119 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
//#region src/usePostgresClientDriver.ts
|
|
2
3
|
function usePostgresClientDriver(config) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
admin: {
|
|
125
|
-
executeSql(sql, options) {
|
|
126
|
-
return client.executeSql(sql, options);
|
|
127
|
-
},
|
|
128
|
-
fetchAvailableDatabases() {
|
|
129
|
-
return client.fetchAvailableDatabases();
|
|
130
|
-
},
|
|
131
|
-
fetchAvailableRoles() {
|
|
132
|
-
return client.fetchAvailableRoles();
|
|
133
|
-
},
|
|
134
|
-
fetchCurrentDatabase() {
|
|
135
|
-
return client.fetchCurrentDatabase();
|
|
136
|
-
},
|
|
137
|
-
fetchUnmappedTables(mappedPaths) {
|
|
138
|
-
return client.fetchUnmappedTables(mappedPaths);
|
|
139
|
-
},
|
|
140
|
-
fetchTableMetadata(tableName) {
|
|
141
|
-
return client.fetchTableMetadata(tableName);
|
|
142
|
-
},
|
|
143
|
-
createBranch(name_0, options_0) {
|
|
144
|
-
return client.createBranch(name_0, options_0);
|
|
145
|
-
},
|
|
146
|
-
deleteBranch(name_1) {
|
|
147
|
-
return client.deleteBranch(name_1);
|
|
148
|
-
},
|
|
149
|
-
listBranches() {
|
|
150
|
-
return client.listBranches();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
$[0] = client;
|
|
155
|
-
$[1] = t1;
|
|
156
|
-
} else {
|
|
157
|
-
t1 = $[1];
|
|
158
|
-
}
|
|
159
|
-
t0 = t1;
|
|
160
|
-
return t0;
|
|
4
|
+
const client = config.wsClient;
|
|
5
|
+
return useMemo(() => {
|
|
6
|
+
if (!client) throw new Error("RebaseWebSocketClient must be provided in config.wsClient");
|
|
7
|
+
return {
|
|
8
|
+
key: "postgres",
|
|
9
|
+
name: "PostgreSQL",
|
|
10
|
+
client,
|
|
11
|
+
async fetchCollection(props) {
|
|
12
|
+
const { path, filter, limit, startAfter, orderBy, searchString, order } = props;
|
|
13
|
+
return client.fetchCollection({
|
|
14
|
+
path,
|
|
15
|
+
filter,
|
|
16
|
+
limit,
|
|
17
|
+
startAfter,
|
|
18
|
+
orderBy,
|
|
19
|
+
searchString,
|
|
20
|
+
order
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
async fetchEntity(props) {
|
|
24
|
+
const { path, entityId, databaseId } = props;
|
|
25
|
+
return client.fetchEntity({
|
|
26
|
+
path,
|
|
27
|
+
entityId,
|
|
28
|
+
databaseId
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
async saveEntity(props) {
|
|
32
|
+
return client.saveEntity({
|
|
33
|
+
path: props.path,
|
|
34
|
+
values: props.values,
|
|
35
|
+
entityId: props.entityId,
|
|
36
|
+
previousValues: props.previousValues,
|
|
37
|
+
status: props.status
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
async deleteEntity(props) {
|
|
41
|
+
const { entity } = props;
|
|
42
|
+
return client.deleteEntity({ entity });
|
|
43
|
+
},
|
|
44
|
+
async checkUniqueField(path, name, value, entityId, collection) {
|
|
45
|
+
return client.checkUniqueField(path, name, value, entityId, collection);
|
|
46
|
+
},
|
|
47
|
+
async countEntities(props) {
|
|
48
|
+
const { path, filter, limit, startAfter, orderBy, searchString, order } = props;
|
|
49
|
+
return client.countEntities({
|
|
50
|
+
path,
|
|
51
|
+
filter,
|
|
52
|
+
limit,
|
|
53
|
+
startAfter,
|
|
54
|
+
orderBy,
|
|
55
|
+
searchString,
|
|
56
|
+
order
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
listenCollection(props) {
|
|
60
|
+
const { path, filter, limit, startAfter, orderBy, searchString, order, onUpdate, onError } = props;
|
|
61
|
+
return client.listenCollection({
|
|
62
|
+
path,
|
|
63
|
+
filter,
|
|
64
|
+
limit,
|
|
65
|
+
startAfter,
|
|
66
|
+
orderBy,
|
|
67
|
+
searchString,
|
|
68
|
+
order
|
|
69
|
+
}, (entities) => props.onUpdate(entities), props.onError);
|
|
70
|
+
},
|
|
71
|
+
listenEntity(props) {
|
|
72
|
+
const { path, entityId, databaseId, onUpdate, onError } = props;
|
|
73
|
+
return client.listenEntity({
|
|
74
|
+
path,
|
|
75
|
+
entityId,
|
|
76
|
+
databaseId
|
|
77
|
+
}, (entity) => {
|
|
78
|
+
props.onUpdate(entity);
|
|
79
|
+
}, props.onError);
|
|
80
|
+
},
|
|
81
|
+
isFilterCombinationValid() {
|
|
82
|
+
return true;
|
|
83
|
+
},
|
|
84
|
+
admin: {
|
|
85
|
+
executeSql(sql, options) {
|
|
86
|
+
return client.executeSql(sql, options);
|
|
87
|
+
},
|
|
88
|
+
fetchAvailableDatabases() {
|
|
89
|
+
return client.fetchAvailableDatabases();
|
|
90
|
+
},
|
|
91
|
+
fetchAvailableRoles() {
|
|
92
|
+
return client.fetchAvailableRoles();
|
|
93
|
+
},
|
|
94
|
+
fetchCurrentDatabase() {
|
|
95
|
+
return client.fetchCurrentDatabase();
|
|
96
|
+
},
|
|
97
|
+
fetchUnmappedTables(mappedPaths) {
|
|
98
|
+
return client.fetchUnmappedTables(mappedPaths);
|
|
99
|
+
},
|
|
100
|
+
fetchTableMetadata(tableName) {
|
|
101
|
+
return client.fetchTableMetadata(tableName);
|
|
102
|
+
},
|
|
103
|
+
createBranch(name, options) {
|
|
104
|
+
return client.createBranch(name, options);
|
|
105
|
+
},
|
|
106
|
+
deleteBranch(name) {
|
|
107
|
+
return client.deleteBranch(name);
|
|
108
|
+
},
|
|
109
|
+
listBranches() {
|
|
110
|
+
return client.listBranches();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}, [client]);
|
|
161
115
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
//# sourceMappingURL=index.es.js.map
|
|
116
|
+
//#endregion
|
|
117
|
+
export { usePostgresClientDriver };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +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 BranchInfo\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,\nfilter,\nlimit,\nstartAfter,\norderBy,\nsearchString,\norder }) 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,\nentityId,\ndatabaseId }) 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: unknown, 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,\nfilter,\nlimit,\nstartAfter,\norderBy,\nsearchString,\norder });\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,\nfilter,\nlimit,\nstartAfter,\norderBy,\nsearchString,\norder },\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,\nentityId,\ndatabaseId },\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 admin: {\n executeSql(sql: string, options?: { database?: string; role?: string }): Promise<Record<string, unknown>[]> {\n return client.executeSql(sql, options);\n },\n fetchAvailableDatabases(): Promise<string[]> {\n return client.fetchAvailableDatabases();\n },\n fetchAvailableRoles(): Promise<string[]> {\n return client.fetchAvailableRoles();\n },\n fetchCurrentDatabase(): Promise<string | undefined> {\n return client.fetchCurrentDatabase();\n },\n fetchUnmappedTables(mappedPaths?: string[]): Promise<string[]> {\n return client.fetchUnmappedTables(mappedPaths);\n },\n fetchTableMetadata(tableName: string): Promise<unknown> {\n return client.fetchTableMetadata(tableName);\n },\n createBranch(name: string, options?: { source?: string }): Promise<BranchInfo> {\n return client.createBranch(name, options);\n },\n deleteBranch(name: string): Promise<void> {\n return client.deleteBranch(name);\n },\n listBranches(): Promise<BranchInfo[]> {\n return client.listBranches();\n }\n }\n } as PostgresDataDriver;\n }, [client]);\n\n}\n"],"
|
|
1
|
+
{"version":3,"file":"index.es.js","names":[],"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 BranchInfo\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,\nfilter,\nlimit,\nstartAfter,\norderBy,\nsearchString,\norder }) 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,\nentityId,\ndatabaseId }) 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: unknown, 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,\nfilter,\nlimit,\nstartAfter,\norderBy,\nsearchString,\norder });\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,\nfilter,\nlimit,\nstartAfter,\norderBy,\nsearchString,\norder },\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,\nentityId,\ndatabaseId },\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 admin: {\n executeSql(sql: string, options?: { database?: string; role?: string }): Promise<Record<string, unknown>[]> {\n return client.executeSql(sql, options);\n },\n fetchAvailableDatabases(): Promise<string[]> {\n return client.fetchAvailableDatabases();\n },\n fetchAvailableRoles(): Promise<string[]> {\n return client.fetchAvailableRoles();\n },\n fetchCurrentDatabase(): Promise<string | undefined> {\n return client.fetchCurrentDatabase();\n },\n fetchUnmappedTables(mappedPaths?: string[]): Promise<string[]> {\n return client.fetchUnmappedTables(mappedPaths);\n },\n fetchTableMetadata(tableName: string): Promise<unknown> {\n return client.fetchTableMetadata(tableName);\n },\n createBranch(name: string, options?: { source?: string }): Promise<BranchInfo> {\n return client.createBranch(name, options);\n },\n deleteBranch(name: string): Promise<void> {\n return client.deleteBranch(name);\n },\n listBranches(): Promise<BranchInfo[]> {\n return client.listBranches();\n }\n }\n } as PostgresDataDriver;\n }, [client]);\n\n}\n"],"mappings":";;AAyBA,SAAgB,wBAAwB,QAAsD;CAC1F,MAAM,SAAS,OAAO;CAEtB,OAAO,cAAc;EACjB,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,2DAA2D;EAExF,OAAO;GAEP,KAAK;GAEL,MAAM;GAEN;GAEA,MAAM,gBAA+C,OAAsD;IAEvG,MAAM,EAAE,MAAM,QAAQ,OAAO,YAAY,SAAS,cAAc,UAAU;IAC1E,OAAO,OAAO,gBAAgB;KAAE;KAC5C;KACA;KACA;KACA;KACA;KACA;IAAM,CAAC;GACC;GAEA,MAAM,YAA2C,OAA4D;IACzG,MAAM,EAAE,MAAM,UAAU,eAAe;IACvC,OAAO,OAAO,YAAY;KAAE;KACxC;KACA;IAAW,CAAC;GACJ;GAEA,MAAM,WAA0C,OAA+C;IAC3F,OAAO,OAAO,WAAW;KACrB,MAAM,MAAM;KACZ,QAAQ,MAAM;KACd,UAAU,MAAM;KAChB,gBAAgB,MAAM;KACtB,QAAQ,MAAM;IAClB,CAAC;GACL;GAEA,MAAM,aAA4C,OAA4C;IAC1F,MAAM,EAAE,WAAW;IACnB,OAAO,OAAO,aAAa,EAAE,OAAO,CAAC;GACzC;GAEA,MAAM,iBAAiB,MAAc,MAAc,OAAgB,UAAmB,YAAiD;IACnI,OAAO,OAAO,iBAAiB,MAAM,MAAM,OAAO,UAAU,UAAU;GAC1E;GAEA,MAAM,cAA6C,OAAiD;IAChG,MAAM,EAAE,MAAM,QAAQ,OAAO,YAAY,SAAS,cAAc,UAAU;IAC1E,OAAO,OAAO,cAAc;KAAE;KAC1C;KACA;KACA;KACA;KACA;KACA;IAAM,CAAC;GACC;GAEA,iBAAgD,OAA6C;IACzF,MAAM,EAAE,MAAM,QAAQ,OAAO,YAAY,SAAS,cAAc,OAAO,UAAU,YAAY;IAC7F,OAAO,OAAO,iBACV;KAAE;KAClB;KACA;KACA;KACA;KACA;KACA;IAAM,IACW,aAAuB,MAAM,SAAS,QAAuB,GAC9D,MAAM,OACV;GACJ;GAEA,aAA4C,OAAyC;IACjF,MAAM,EAAE,MAAM,UAAU,YAAY,UAAU,YAAY;IAC1D,OAAO,OAAO,aACV;KAAE;KAClB;KACA;IAAW,IACM,WAA0B;KACvB,MAAM,SAAS,MAA0B;IAC7C,GACA,MAAM,OACV;GACJ;GAEA,2BAAoC;IAChC,OAAO;GACX;GAEA,OAAO;IACH,WAAW,KAAa,SAAoF;KACxG,OAAO,OAAO,WAAW,KAAK,OAAO;IACzC;IACA,0BAA6C;KACzC,OAAO,OAAO,wBAAwB;IAC1C;IACA,sBAAyC;KACrC,OAAO,OAAO,oBAAoB;IACtC;IACA,uBAAoD;KAChD,OAAO,OAAO,qBAAqB;IACvC;IACA,oBAAoB,aAA2C;KAC3D,OAAO,OAAO,oBAAoB,WAAW;IACjD;IACA,mBAAmB,WAAqC;KACpD,OAAO,OAAO,mBAAmB,SAAS;IAC9C;IACA,aAAa,MAAc,SAAoD;KAC3E,OAAO,OAAO,aAAa,MAAM,OAAO;IAC5C;IACA,aAAa,MAA6B;KACtC,OAAO,OAAO,aAAa,IAAI;IACnC;IACA,eAAsC;KAClC,OAAO,OAAO,aAAa;IAC/B;GACJ;EACJ;CACA,GAAG,CAAC,MAAM,CAAC;AAEf"}
|