@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/dist/index.umd.js
CHANGED
|
@@ -1,168 +1,123 @@
|
|
|
1
1
|
(function(global, factory) {
|
|
2
|
-
|
|
3
|
-
})(this, function(
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
props_5.onUpdate(entity_0);
|
|
122
|
-
}, props_5.onError);
|
|
123
|
-
},
|
|
124
|
-
isFilterCombinationValid() {
|
|
125
|
-
return true;
|
|
126
|
-
},
|
|
127
|
-
admin: {
|
|
128
|
-
executeSql(sql, options) {
|
|
129
|
-
return client.executeSql(sql, options);
|
|
130
|
-
},
|
|
131
|
-
fetchAvailableDatabases() {
|
|
132
|
-
return client.fetchAvailableDatabases();
|
|
133
|
-
},
|
|
134
|
-
fetchAvailableRoles() {
|
|
135
|
-
return client.fetchAvailableRoles();
|
|
136
|
-
},
|
|
137
|
-
fetchCurrentDatabase() {
|
|
138
|
-
return client.fetchCurrentDatabase();
|
|
139
|
-
},
|
|
140
|
-
fetchUnmappedTables(mappedPaths) {
|
|
141
|
-
return client.fetchUnmappedTables(mappedPaths);
|
|
142
|
-
},
|
|
143
|
-
fetchTableMetadata(tableName) {
|
|
144
|
-
return client.fetchTableMetadata(tableName);
|
|
145
|
-
},
|
|
146
|
-
createBranch(name_0, options_0) {
|
|
147
|
-
return client.createBranch(name_0, options_0);
|
|
148
|
-
},
|
|
149
|
-
deleteBranch(name_1) {
|
|
150
|
-
return client.deleteBranch(name_1);
|
|
151
|
-
},
|
|
152
|
-
listBranches() {
|
|
153
|
-
return client.listBranches();
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
$[0] = client;
|
|
158
|
-
$[1] = t1;
|
|
159
|
-
} else {
|
|
160
|
-
t1 = $[1];
|
|
161
|
-
}
|
|
162
|
-
t0 = t1;
|
|
163
|
-
return t0;
|
|
164
|
-
}
|
|
165
|
-
exports2.usePostgresClientDriver = usePostgresClientDriver;
|
|
166
|
-
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react")) : typeof define === "function" && define.amd ? define(["exports", "react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["Rebase PostgreSQL"] = {}, global.react));
|
|
3
|
+
})(this, function(exports, react) {
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
5
|
+
//#region src/usePostgresClientDriver.ts
|
|
6
|
+
function usePostgresClientDriver(config) {
|
|
7
|
+
const client = config.wsClient;
|
|
8
|
+
return (0, react.useMemo)(() => {
|
|
9
|
+
if (!client) throw new Error("RebaseWebSocketClient must be provided in config.wsClient");
|
|
10
|
+
return {
|
|
11
|
+
key: "postgres",
|
|
12
|
+
name: "PostgreSQL",
|
|
13
|
+
client,
|
|
14
|
+
async fetchCollection(props) {
|
|
15
|
+
const { path, filter, limit, startAfter, orderBy, searchString, order } = props;
|
|
16
|
+
return client.fetchCollection({
|
|
17
|
+
path,
|
|
18
|
+
filter,
|
|
19
|
+
limit,
|
|
20
|
+
startAfter,
|
|
21
|
+
orderBy,
|
|
22
|
+
searchString,
|
|
23
|
+
order
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
async fetchEntity(props) {
|
|
27
|
+
const { path, entityId, databaseId } = props;
|
|
28
|
+
return client.fetchEntity({
|
|
29
|
+
path,
|
|
30
|
+
entityId,
|
|
31
|
+
databaseId
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
async saveEntity(props) {
|
|
35
|
+
return client.saveEntity({
|
|
36
|
+
path: props.path,
|
|
37
|
+
values: props.values,
|
|
38
|
+
entityId: props.entityId,
|
|
39
|
+
previousValues: props.previousValues,
|
|
40
|
+
status: props.status
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
async deleteEntity(props) {
|
|
44
|
+
const { entity } = props;
|
|
45
|
+
return client.deleteEntity({ entity });
|
|
46
|
+
},
|
|
47
|
+
async checkUniqueField(path, name, value, entityId, collection) {
|
|
48
|
+
return client.checkUniqueField(path, name, value, entityId, collection);
|
|
49
|
+
},
|
|
50
|
+
async countEntities(props) {
|
|
51
|
+
const { path, filter, limit, startAfter, orderBy, searchString, order } = props;
|
|
52
|
+
return client.countEntities({
|
|
53
|
+
path,
|
|
54
|
+
filter,
|
|
55
|
+
limit,
|
|
56
|
+
startAfter,
|
|
57
|
+
orderBy,
|
|
58
|
+
searchString,
|
|
59
|
+
order
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
listenCollection(props) {
|
|
63
|
+
const { path, filter, limit, startAfter, orderBy, searchString, order, onUpdate, onError } = props;
|
|
64
|
+
return client.listenCollection({
|
|
65
|
+
path,
|
|
66
|
+
filter,
|
|
67
|
+
limit,
|
|
68
|
+
startAfter,
|
|
69
|
+
orderBy,
|
|
70
|
+
searchString,
|
|
71
|
+
order
|
|
72
|
+
}, (entities) => props.onUpdate(entities), props.onError);
|
|
73
|
+
},
|
|
74
|
+
listenEntity(props) {
|
|
75
|
+
const { path, entityId, databaseId, onUpdate, onError } = props;
|
|
76
|
+
return client.listenEntity({
|
|
77
|
+
path,
|
|
78
|
+
entityId,
|
|
79
|
+
databaseId
|
|
80
|
+
}, (entity) => {
|
|
81
|
+
props.onUpdate(entity);
|
|
82
|
+
}, props.onError);
|
|
83
|
+
},
|
|
84
|
+
isFilterCombinationValid() {
|
|
85
|
+
return true;
|
|
86
|
+
},
|
|
87
|
+
admin: {
|
|
88
|
+
executeSql(sql, options) {
|
|
89
|
+
return client.executeSql(sql, options);
|
|
90
|
+
},
|
|
91
|
+
fetchAvailableDatabases() {
|
|
92
|
+
return client.fetchAvailableDatabases();
|
|
93
|
+
},
|
|
94
|
+
fetchAvailableRoles() {
|
|
95
|
+
return client.fetchAvailableRoles();
|
|
96
|
+
},
|
|
97
|
+
fetchCurrentDatabase() {
|
|
98
|
+
return client.fetchCurrentDatabase();
|
|
99
|
+
},
|
|
100
|
+
fetchUnmappedTables(mappedPaths) {
|
|
101
|
+
return client.fetchUnmappedTables(mappedPaths);
|
|
102
|
+
},
|
|
103
|
+
fetchTableMetadata(tableName) {
|
|
104
|
+
return client.fetchTableMetadata(tableName);
|
|
105
|
+
},
|
|
106
|
+
createBranch(name, options) {
|
|
107
|
+
return client.createBranch(name, options);
|
|
108
|
+
},
|
|
109
|
+
deleteBranch(name) {
|
|
110
|
+
return client.deleteBranch(name);
|
|
111
|
+
},
|
|
112
|
+
listBranches() {
|
|
113
|
+
return client.listBranches();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}, [client]);
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
exports.usePostgresClientDriver = usePostgresClientDriver;
|
|
167
121
|
});
|
|
168
|
-
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +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 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.umd.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":";;;;;CAyBA,SAAgB,wBAAwB,QAAsD;EAC1F,MAAM,SAAS,OAAO;EAEtB,QAAA,GAAA,MAAA,eAAqB;GACjB,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,2DAA2D;GAExF,OAAO;IAEP,KAAK;IAEL,MAAM;IAEN;IAEA,MAAM,gBAA+C,OAAsD;KAEvG,MAAM,EAAE,MAAM,QAAQ,OAAO,YAAY,SAAS,cAAc,UAAU;KAC1E,OAAO,OAAO,gBAAgB;MAAE;MAC5C;MACA;MACA;MACA;MACA;MACA;KAAM,CAAC;IACC;IAEA,MAAM,YAA2C,OAA4D;KACzG,MAAM,EAAE,MAAM,UAAU,eAAe;KACvC,OAAO,OAAO,YAAY;MAAE;MACxC;MACA;KAAW,CAAC;IACJ;IAEA,MAAM,WAA0C,OAA+C;KAC3F,OAAO,OAAO,WAAW;MACrB,MAAM,MAAM;MACZ,QAAQ,MAAM;MACd,UAAU,MAAM;MAChB,gBAAgB,MAAM;MACtB,QAAQ,MAAM;KAClB,CAAC;IACL;IAEA,MAAM,aAA4C,OAA4C;KAC1F,MAAM,EAAE,WAAW;KACnB,OAAO,OAAO,aAAa,EAAE,OAAO,CAAC;IACzC;IAEA,MAAM,iBAAiB,MAAc,MAAc,OAAgB,UAAmB,YAAiD;KACnI,OAAO,OAAO,iBAAiB,MAAM,MAAM,OAAO,UAAU,UAAU;IAC1E;IAEA,MAAM,cAA6C,OAAiD;KAChG,MAAM,EAAE,MAAM,QAAQ,OAAO,YAAY,SAAS,cAAc,UAAU;KAC1E,OAAO,OAAO,cAAc;MAAE;MAC1C;MACA;MACA;MACA;MACA;MACA;KAAM,CAAC;IACC;IAEA,iBAAgD,OAA6C;KACzF,MAAM,EAAE,MAAM,QAAQ,OAAO,YAAY,SAAS,cAAc,OAAO,UAAU,YAAY;KAC7F,OAAO,OAAO,iBACV;MAAE;MAClB;MACA;MACA;MACA;MACA;MACA;KAAM,IACW,aAAuB,MAAM,SAAS,QAAuB,GAC9D,MAAM,OACV;IACJ;IAEA,aAA4C,OAAyC;KACjF,MAAM,EAAE,MAAM,UAAU,YAAY,UAAU,YAAY;KAC1D,OAAO,OAAO,aACV;MAAE;MAClB;MACA;KAAW,IACM,WAA0B;MACvB,MAAM,SAAS,MAA0B;KAC7C,GACA,MAAM,OACV;IACJ;IAEA,2BAAoC;KAChC,OAAO;IACX;IAEA,OAAO;KACH,WAAW,KAAa,SAAoF;MACxG,OAAO,OAAO,WAAW,KAAK,OAAO;KACzC;KACA,0BAA6C;MACzC,OAAO,OAAO,wBAAwB;KAC1C;KACA,sBAAyC;MACrC,OAAO,OAAO,oBAAoB;KACtC;KACA,uBAAoD;MAChD,OAAO,OAAO,qBAAqB;KACvC;KACA,oBAAoB,aAA2C;MAC3D,OAAO,OAAO,oBAAoB,WAAW;KACjD;KACA,mBAAmB,WAAqC;MACpD,OAAO,OAAO,mBAAmB,SAAS;KAC9C;KACA,aAAa,MAAc,SAAoD;MAC3E,OAAO,OAAO,aAAa,MAAM,OAAO;KAC5C;KACA,aAAa,MAA6B;MACtC,OAAO,OAAO,aAAa,IAAI;KACnC;KACA,eAAsC;MAClC,OAAO,OAAO,aAAa;KAC/B;IACJ;GACJ;EACA,GAAG,CAAC,MAAM,CAAC;CAEf"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/client-postgresql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"description": "PostgreSQL data source client for Rebase",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/rebaseco"
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"transform": {
|
|
33
33
|
"^.+\\.tsx?$": "ts-jest"
|
|
34
34
|
},
|
|
35
|
+
"testEnvironment": "jsdom",
|
|
35
36
|
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
|
|
36
37
|
"moduleFileExtensions": [
|
|
37
38
|
"ts",
|
|
@@ -57,22 +58,23 @@
|
|
|
57
58
|
"./package.json": "./package.json"
|
|
58
59
|
},
|
|
59
60
|
"dependencies": {
|
|
60
|
-
"@rebasepro/client": "0.
|
|
61
|
-
"@rebasepro/types": "0.
|
|
61
|
+
"@rebasepro/client": "0.6.0",
|
|
62
|
+
"@rebasepro/types": "0.6.0"
|
|
62
63
|
},
|
|
63
64
|
"peerDependencies": {
|
|
64
65
|
"react": ">=19.0.0",
|
|
65
66
|
"react-dom": ">=19.0.0"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
|
-
"@types/jest": "^
|
|
69
|
-
"@types/react": "^19.2.
|
|
69
|
+
"@types/jest": "^30.0.0",
|
|
70
|
+
"@types/react": "^19.2.17",
|
|
70
71
|
"@types/react-dom": "^19.2.3",
|
|
71
|
-
"@vitejs/plugin-react": "^
|
|
72
|
-
"jest": "^
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
72
|
+
"@vitejs/plugin-react": "^6.0.2",
|
|
73
|
+
"jest": "^30.4.2",
|
|
74
|
+
"jest-environment-jsdom": "^30.4.1",
|
|
75
|
+
"ts-jest": "^29.4.11",
|
|
76
|
+
"typescript": "^6.0.3",
|
|
77
|
+
"vite": "^8.0.16"
|
|
76
78
|
},
|
|
77
79
|
"gitHead": "d935eefa5aa8d1009a2398cfac2c1e4ee9aeb6b6",
|
|
78
80
|
"publishConfig": {
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { renderHook } from "@testing-library/react";
|
|
3
|
+
import { usePostgresClientDriver } from "../src/usePostgresClientDriver";
|
|
4
|
+
|
|
5
|
+
describe("usePostgresClientDriver hook", () => {
|
|
6
|
+
let mockWsClient: any;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockWsClient = {
|
|
10
|
+
fetchCollection: jest.fn().mockResolvedValue([{ id: "1",
|
|
11
|
+
name: "Entity 1" }]),
|
|
12
|
+
fetchEntity: jest.fn().mockResolvedValue({ id: "1",
|
|
13
|
+
name: "Entity 1" }),
|
|
14
|
+
saveEntity: jest.fn().mockResolvedValue({ id: "1",
|
|
15
|
+
name: "Saved Entity" }),
|
|
16
|
+
deleteEntity: jest.fn().mockResolvedValue(undefined),
|
|
17
|
+
checkUniqueField: jest.fn().mockResolvedValue(true),
|
|
18
|
+
countEntities: jest.fn().mockResolvedValue(42),
|
|
19
|
+
listenCollection: jest.fn(() => jest.fn()),
|
|
20
|
+
listenEntity: jest.fn(() => jest.fn()),
|
|
21
|
+
executeSql: jest.fn().mockResolvedValue([]),
|
|
22
|
+
fetchAvailableDatabases: jest.fn().mockResolvedValue(["db1"]),
|
|
23
|
+
fetchAvailableRoles: jest.fn().mockResolvedValue(["role1"]),
|
|
24
|
+
fetchCurrentDatabase: jest.fn().mockResolvedValue("db1"),
|
|
25
|
+
fetchUnmappedTables: jest.fn().mockResolvedValue([]),
|
|
26
|
+
fetchTableMetadata: jest.fn().mockResolvedValue({}),
|
|
27
|
+
createBranch: jest.fn().mockResolvedValue({ name: "branch1" }),
|
|
28
|
+
deleteBranch: jest.fn().mockResolvedValue(undefined),
|
|
29
|
+
listBranches: jest.fn().mockResolvedValue([])
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("throws error if wsClient is not provided", () => {
|
|
34
|
+
expect(() => {
|
|
35
|
+
renderHook(() => usePostgresClientDriver({} as any));
|
|
36
|
+
}).toThrow("RebaseWebSocketClient must be provided in config.wsClient");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("returns active database driver object", () => {
|
|
40
|
+
const { result } = renderHook(() => usePostgresClientDriver({ wsClient: mockWsClient }));
|
|
41
|
+
|
|
42
|
+
expect(result.current.key).toBe("postgres");
|
|
43
|
+
expect(result.current.name).toBe("PostgreSQL");
|
|
44
|
+
expect(result.current.client).toBe(mockWsClient);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("correctly routes fetchCollection, fetchEntity, saveEntity, deleteEntity", async () => {
|
|
48
|
+
const { result } = renderHook(() => usePostgresClientDriver({ wsClient: mockWsClient }));
|
|
49
|
+
const driver = result.current;
|
|
50
|
+
|
|
51
|
+
// fetchCollection
|
|
52
|
+
const list = await driver.fetchCollection({ path: "posts" });
|
|
53
|
+
expect(mockWsClient.fetchCollection).toHaveBeenCalledWith({ path: "posts" });
|
|
54
|
+
expect(list).toEqual([{ id: "1",
|
|
55
|
+
name: "Entity 1" }]);
|
|
56
|
+
|
|
57
|
+
// fetchEntity
|
|
58
|
+
const item = await driver.fetchEntity({ path: "posts",
|
|
59
|
+
entityId: "1" });
|
|
60
|
+
expect(mockWsClient.fetchEntity).toHaveBeenCalledWith({ path: "posts",
|
|
61
|
+
entityId: "1" });
|
|
62
|
+
expect(item).toEqual({ id: "1",
|
|
63
|
+
name: "Entity 1" });
|
|
64
|
+
|
|
65
|
+
// saveEntity
|
|
66
|
+
const saved = await driver.saveEntity({ path: "posts",
|
|
67
|
+
values: { name: "Test" } });
|
|
68
|
+
expect(mockWsClient.saveEntity).toHaveBeenCalledWith({
|
|
69
|
+
path: "posts",
|
|
70
|
+
values: { name: "Test" },
|
|
71
|
+
entityId: undefined,
|
|
72
|
+
previousValues: undefined,
|
|
73
|
+
status: undefined
|
|
74
|
+
});
|
|
75
|
+
expect(saved).toEqual({ id: "1",
|
|
76
|
+
name: "Saved Entity" });
|
|
77
|
+
|
|
78
|
+
// deleteEntity
|
|
79
|
+
await driver.deleteEntity({ entity: { id: "1",
|
|
80
|
+
name: "Test" } });
|
|
81
|
+
expect(mockWsClient.deleteEntity).toHaveBeenCalledWith({ entity: { id: "1",
|
|
82
|
+
name: "Test" } });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("correctly routes admin database branching operations", async () => {
|
|
86
|
+
const { result } = renderHook(() => usePostgresClientDriver({ wsClient: mockWsClient }));
|
|
87
|
+
const driver = result.current;
|
|
88
|
+
|
|
89
|
+
// createBranch
|
|
90
|
+
await driver.admin.createBranch("branch_test");
|
|
91
|
+
expect(mockWsClient.createBranch).toHaveBeenCalledWith("branch_test", undefined);
|
|
92
|
+
|
|
93
|
+
// deleteBranch
|
|
94
|
+
await driver.admin.deleteBranch("branch_test");
|
|
95
|
+
expect(mockWsClient.deleteBranch).toHaveBeenCalledWith("branch_test");
|
|
96
|
+
|
|
97
|
+
// listBranches
|
|
98
|
+
await driver.admin.listBranches();
|
|
99
|
+
expect(mockWsClient.listBranches).toHaveBeenCalled();
|
|
100
|
+
});
|
|
101
|
+
});
|
package/tsconfig.json
CHANGED
package/tsconfig.prod.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "./tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
+
"ignoreDeprecations": "6.0",
|
|
5
|
+
"rootDir": "./src",
|
|
4
6
|
"noEmit": false,
|
|
5
7
|
"declaration": true,
|
|
6
8
|
"emitDeclarationOnly": true,
|
|
7
|
-
"declarationDir": "dist"
|
|
9
|
+
"declarationDir": "dist",
|
|
10
|
+
"paths": {}
|
|
8
11
|
},
|
|
9
12
|
"include": [
|
|
10
13
|
"src/**/*"
|
package/vite.config.ts
CHANGED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Transport } from "./transport";
|
|
2
|
-
export interface AdminUser {
|
|
3
|
-
uid: string;
|
|
4
|
-
email: string;
|
|
5
|
-
displayName: string | null;
|
|
6
|
-
photoURL: string | null;
|
|
7
|
-
provider: string;
|
|
8
|
-
roles: string[];
|
|
9
|
-
createdAt: string;
|
|
10
|
-
updatedAt: string;
|
|
11
|
-
}
|
|
12
|
-
export interface CreateAdminOptions {
|
|
13
|
-
adminPath?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function createAdmin(transport: Transport, options?: CreateAdminOptions): {
|
|
16
|
-
listUsers: () => Promise<{
|
|
17
|
-
users: AdminUser[];
|
|
18
|
-
}>;
|
|
19
|
-
listUsersPaginated: (options?: {
|
|
20
|
-
search?: string;
|
|
21
|
-
limit?: number;
|
|
22
|
-
offset?: number;
|
|
23
|
-
orderBy?: string;
|
|
24
|
-
orderDir?: "asc" | "desc";
|
|
25
|
-
}) => Promise<{
|
|
26
|
-
users: AdminUser[];
|
|
27
|
-
total: number;
|
|
28
|
-
limit: number;
|
|
29
|
-
offset: number;
|
|
30
|
-
}>;
|
|
31
|
-
getUser: (userId: string) => Promise<{
|
|
32
|
-
user: AdminUser;
|
|
33
|
-
}>;
|
|
34
|
-
createUser: (data: {
|
|
35
|
-
email: string;
|
|
36
|
-
displayName?: string;
|
|
37
|
-
password?: string;
|
|
38
|
-
roles?: string[];
|
|
39
|
-
}) => Promise<{
|
|
40
|
-
user: AdminUser;
|
|
41
|
-
}>;
|
|
42
|
-
updateUser: (userId: string, data: {
|
|
43
|
-
email?: string;
|
|
44
|
-
displayName?: string;
|
|
45
|
-
password?: string;
|
|
46
|
-
roles?: string[];
|
|
47
|
-
}) => Promise<{
|
|
48
|
-
user: AdminUser;
|
|
49
|
-
}>;
|
|
50
|
-
deleteUser: (userId: string) => Promise<{
|
|
51
|
-
success: boolean;
|
|
52
|
-
}>;
|
|
53
|
-
bootstrap: () => Promise<{
|
|
54
|
-
success: boolean;
|
|
55
|
-
message: string;
|
|
56
|
-
user: {
|
|
57
|
-
uid: string;
|
|
58
|
-
roles: string[];
|
|
59
|
-
};
|
|
60
|
-
}>;
|
|
61
|
-
};
|