@rebasepro/client-postgresql 0.6.1 → 0.7.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/package.json +11 -11
- package/dist/index.d.ts +0 -8
- package/dist/index.es.js +0 -119
- package/dist/index.es.js.map +0 -1
- package/dist/index.umd.js +0 -123
- package/dist/index.umd.js.map +0 -1
- package/dist/usePostgresClientDriver.d.ts +0 -9
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.7.0",
|
|
5
5
|
"description": "PostgreSQL data source client for Rebase",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/rebaseco"
|
|
@@ -28,6 +28,13 @@
|
|
|
28
28
|
"typescript",
|
|
29
29
|
"admin"
|
|
30
30
|
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"watch": "vite build --watch",
|
|
33
|
+
"build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json",
|
|
34
|
+
"test:lint": "eslint \"src/**\" --quiet",
|
|
35
|
+
"test": "jest --passWithNoTests",
|
|
36
|
+
"clean": "rm -rf dist && find ./src -name '*.js' -type f | xargs rm -f"
|
|
37
|
+
},
|
|
31
38
|
"jest": {
|
|
32
39
|
"transform": {
|
|
33
40
|
"^.+\\.tsx?$": "ts-jest"
|
|
@@ -58,8 +65,8 @@
|
|
|
58
65
|
"./package.json": "./package.json"
|
|
59
66
|
},
|
|
60
67
|
"dependencies": {
|
|
61
|
-
"@rebasepro/client": "
|
|
62
|
-
"@rebasepro/types": "
|
|
68
|
+
"@rebasepro/client": "workspace:*",
|
|
69
|
+
"@rebasepro/types": "workspace:*"
|
|
63
70
|
},
|
|
64
71
|
"peerDependencies": {
|
|
65
72
|
"react": ">=19.0.0",
|
|
@@ -79,12 +86,5 @@
|
|
|
79
86
|
"gitHead": "d935eefa5aa8d1009a2398cfac2c1e4ee9aeb6b6",
|
|
80
87
|
"publishConfig": {
|
|
81
88
|
"access": "public"
|
|
82
|
-
},
|
|
83
|
-
"scripts": {
|
|
84
|
-
"watch": "vite build --watch",
|
|
85
|
-
"build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json",
|
|
86
|
-
"test:lint": "eslint \"src/**\" --quiet",
|
|
87
|
-
"test": "jest --passWithNoTests",
|
|
88
|
-
"clean": "rm -rf dist && find ./src -name '*.js' -type f | xargs rm -f"
|
|
89
89
|
}
|
|
90
|
-
}
|
|
90
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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";
|
package/dist/index.es.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
//#region src/usePostgresClientDriver.ts
|
|
3
|
-
function usePostgresClientDriver(config) {
|
|
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]);
|
|
115
|
-
}
|
|
116
|
-
//#endregion
|
|
117
|
-
export { usePostgresClientDriver };
|
|
118
|
-
|
|
119
|
-
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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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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"}
|
package/dist/index.umd.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
(function(global, factory) {
|
|
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;
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,Q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,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"}
|
|
@@ -1,9 +0,0 @@
|
|
|
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;
|