@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.
Files changed (75) hide show
  1. package/README.md +51 -83
  2. package/dist/index.es.js +117 -163
  3. package/dist/index.es.js.map +1 -1
  4. package/dist/index.umd.js +121 -166
  5. package/dist/index.umd.js.map +1 -1
  6. package/package.json +12 -10
  7. package/test/usePostgresClientDriver.test.tsx +101 -0
  8. package/tsconfig.json +2 -0
  9. package/tsconfig.prod.json +4 -1
  10. package/vite.config.ts +0 -1
  11. package/dist/client/src/admin.d.ts +0 -61
  12. package/dist/client/src/auth.d.ts +0 -178
  13. package/dist/client/src/collection.d.ts +0 -21
  14. package/dist/client/src/cron.d.ts +0 -25
  15. package/dist/client/src/functions.d.ts +0 -49
  16. package/dist/client/src/index.d.ts +0 -48
  17. package/dist/client/src/query_builder.d.ts +0 -1
  18. package/dist/client/src/reviver.d.ts +0 -1
  19. package/dist/client/src/storage.d.ts +0 -3
  20. package/dist/client/src/transport.d.ts +0 -33
  21. package/dist/client/src/websocket.d.ts +0 -105
  22. package/dist/types/src/controllers/analytics_controller.d.ts +0 -7
  23. package/dist/types/src/controllers/auth.d.ts +0 -104
  24. package/dist/types/src/controllers/client.d.ts +0 -168
  25. package/dist/types/src/controllers/collection_registry.d.ts +0 -46
  26. package/dist/types/src/controllers/customization_controller.d.ts +0 -60
  27. package/dist/types/src/controllers/data.d.ts +0 -207
  28. package/dist/types/src/controllers/data_driver.d.ts +0 -218
  29. package/dist/types/src/controllers/database_admin.d.ts +0 -11
  30. package/dist/types/src/controllers/dialogs_controller.d.ts +0 -36
  31. package/dist/types/src/controllers/effective_role.d.ts +0 -4
  32. package/dist/types/src/controllers/email.d.ts +0 -36
  33. package/dist/types/src/controllers/index.d.ts +0 -18
  34. package/dist/types/src/controllers/local_config_persistence.d.ts +0 -20
  35. package/dist/types/src/controllers/navigation.d.ts +0 -225
  36. package/dist/types/src/controllers/registry.d.ts +0 -63
  37. package/dist/types/src/controllers/side_dialogs_controller.d.ts +0 -67
  38. package/dist/types/src/controllers/side_entity_controller.d.ts +0 -97
  39. package/dist/types/src/controllers/snackbar.d.ts +0 -24
  40. package/dist/types/src/controllers/storage.d.ts +0 -171
  41. package/dist/types/src/index.d.ts +0 -4
  42. package/dist/types/src/rebase_context.d.ts +0 -122
  43. package/dist/types/src/types/auth_adapter.d.ts +0 -301
  44. package/dist/types/src/types/backend.d.ts +0 -536
  45. package/dist/types/src/types/backend_hooks.d.ts +0 -172
  46. package/dist/types/src/types/builders.d.ts +0 -15
  47. package/dist/types/src/types/chips.d.ts +0 -5
  48. package/dist/types/src/types/collections.d.ts +0 -941
  49. package/dist/types/src/types/component_ref.d.ts +0 -47
  50. package/dist/types/src/types/cron.d.ts +0 -102
  51. package/dist/types/src/types/data_source.d.ts +0 -64
  52. package/dist/types/src/types/database_adapter.d.ts +0 -94
  53. package/dist/types/src/types/entities.d.ts +0 -145
  54. package/dist/types/src/types/entity_actions.d.ts +0 -104
  55. package/dist/types/src/types/entity_callbacks.d.ts +0 -173
  56. package/dist/types/src/types/entity_link_builder.d.ts +0 -7
  57. package/dist/types/src/types/entity_overrides.d.ts +0 -10
  58. package/dist/types/src/types/entity_views.d.ts +0 -87
  59. package/dist/types/src/types/export_import.d.ts +0 -21
  60. package/dist/types/src/types/formex.d.ts +0 -40
  61. package/dist/types/src/types/index.d.ts +0 -28
  62. package/dist/types/src/types/locales.d.ts +0 -4
  63. package/dist/types/src/types/modify_collections.d.ts +0 -5
  64. package/dist/types/src/types/plugins.d.ts +0 -282
  65. package/dist/types/src/types/properties.d.ts +0 -1181
  66. package/dist/types/src/types/property_config.d.ts +0 -74
  67. package/dist/types/src/types/relations.d.ts +0 -336
  68. package/dist/types/src/types/slots.d.ts +0 -262
  69. package/dist/types/src/types/translations.d.ts +0 -900
  70. package/dist/types/src/types/user_management_delegate.d.ts +0 -86
  71. package/dist/types/src/types/websockets.d.ts +0 -78
  72. package/dist/types/src/users/index.d.ts +0 -1
  73. package/dist/types/src/users/user.d.ts +0 -50
  74. /package/dist/{client-postgresql/src/index.d.ts → index.d.ts} +0 -0
  75. /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 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.
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
- npm install @rebasepro/postgresql @rebasepro/core
8
+ pnpm add @rebasepro/client-postgresql
11
9
  ```
12
10
 
13
- ## Usage
11
+ **Peer dependencies:** `react >= 19.0.0`, `react-dom >= 19.0.0`
14
12
 
15
- ### Basic Setup with React Hook
13
+ ## What This Package Does
16
14
 
17
- ```typescript
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
- 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
- });
17
+ ## Key Exports
29
18
 
30
- return (
31
- <Rebase
32
- dataSource={dataSource}
33
- collections={collections}
34
- // ... other props
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
- ### Creating Data Source Directly
25
+ ### `PostgresDataDriver` Methods
41
26
 
42
- ```typescript
43
- import { createPostgresDataSource } from "@rebasepro/postgresql";
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
- const dataSource = createPostgresDataSource({
46
- baseUrl: "http://localhost:3001",
47
- websocketUrl: "ws://localhost:3001"
48
- });
49
- ```
39
+ ### Admin Methods (`driver.admin`)
50
40
 
51
- ## Features
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
- - **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
53
+ ## Quick Start
58
54
 
59
- ## API
55
+ ```tsx
56
+ import { usePostgresClientDriver } from "@rebasepro/client-postgresql";
57
+ import { RebaseWebSocketClient } from "@rebasepro/client";
60
58
 
61
- ### Configuration
59
+ const wsClient = new RebaseWebSocketClient({ url: "ws://localhost:4100" });
62
60
 
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)
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
- ### 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
71
+ ## Related Packages
105
72
 
106
- MIT
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 { c } from "react-compiler-runtime";
1
+ import { useMemo } from "react";
2
+ //#region src/usePostgresClientDriver.ts
2
3
  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
- 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
- export {
163
- usePostgresClientDriver
164
- };
165
- //# sourceMappingURL=index.es.js.map
116
+ //#endregion
117
+ export { usePostgresClientDriver };
118
+
119
+ //# sourceMappingURL=index.es.js.map
@@ -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"],"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","admin","executeSql","sql","options","fetchAvailableDatabases","fetchAvailableRoles","fetchCurrentDatabase","fetchUnmappedTables","mappedPaths","fetchTableMetadata","tableName","createBranch","name_0","options_0","deleteBranch","name_1","listBranches"],"mappings":";AAyBO,SAAAA,wBAAAC,QAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA;AACH,QAAAC,SAAeH,OAAMI;AAAU,MAAAC;AAAA,MAAA,CAGtBF,QAAM;AAAA,UAAA,IAAAG,MAAkB,2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QAA0B;AAAA,QAAC,GAE9CpB,QAAK8C,OACT;AAAA,MAAC;AAAA,MAAAO,2BAAA;AAAA,eAAA;AAAA,MAAA;AAAA,MAAAC,OAAA;AAAA,QAAAC,WAAAC,KAAAC,SAAA;AAAA,iBASUjE,OAAM+D,WAAYC,KAAKC,OAAO;AAAA,QAAC;AAAA,QAAAC,0BAAA;AAAA,iBAG/BlE,OAAMkE,wBAAAA;AAAAA,QAA0B;AAAA,QAAAC,sBAAA;AAAA,iBAGhCnE,OAAMmE,oBAAAA;AAAAA,QAAsB;AAAA,QAAAC,uBAAA;AAAA,iBAG5BpE,OAAMoE,qBAAAA;AAAAA,QAAuB;AAAA,QAAAC,oBAAAC,aAAA;AAAA,iBAG7BtE,OAAMqE,oBAAqBC,WAAW;AAAA,QAAC;AAAA,QAAAC,mBAAAC,WAAA;AAAA,iBAGvCxE,OAAMuE,mBAAoBC,SAAS;AAAA,QAAC;AAAA,QAAAC,aAAAC,QAAAC,WAAA;AAAA,iBAGpC3E,OAAMyE,aAAcnE,QAAM2D,SAAO;AAAA,QAAC;AAAA,QAAAW,aAAAC,QAAA;AAAA,iBAGlC7E,OAAM4E,aAActE,MAAI;AAAA,QAAC;AAAA,QAAAwE,eAAA;AAAA,iBAGzB9E,OAAM8E,aAAAA;AAAAA,QAAe;AAAA,MAAA;AAAA,IAAA;AAGvChF,WAAAE;AAAAF,WAAAM;AAAAA,EAAA,OAAA;AAAAA,SAAAN,EAAA,CAAA;AAAA,EAAA;AAtHGI,OAAOE;AAsHa,SAzHjBF;AA0HK;"}
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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