@rebasepro/client-postgresql 0.0.1-canary.09e5ec5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -0
- package/README.md +106 -0
- package/dist/client/src/admin.d.ts +94 -0
- package/dist/client/src/auth.d.ts +161 -0
- package/dist/client/src/collection.d.ts +19 -0
- package/dist/client/src/cron.d.ts +25 -0
- package/dist/client/src/index.d.ts +42 -0
- package/dist/client/src/query_builder.d.ts +53 -0
- package/dist/client/src/reviver.d.ts +1 -0
- package/dist/client/src/storage.d.ts +3 -0
- package/dist/client/src/transport.d.ts +33 -0
- package/dist/client/src/websocket.d.ts +99 -0
- package/dist/client-postgresql/src/index.d.ts +8 -0
- package/dist/client-postgresql/src/usePostgresClientDriver.d.ts +9 -0
- package/dist/index.es.js +165 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +168 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
- package/dist/types/src/controllers/auth.d.ts +119 -0
- package/dist/types/src/controllers/client.d.ts +170 -0
- package/dist/types/src/controllers/collection_registry.d.ts +45 -0
- package/dist/types/src/controllers/customization_controller.d.ts +60 -0
- package/dist/types/src/controllers/data.d.ts +168 -0
- package/dist/types/src/controllers/data_driver.d.ts +160 -0
- package/dist/types/src/controllers/database_admin.d.ts +11 -0
- package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
- package/dist/types/src/controllers/effective_role.d.ts +4 -0
- package/dist/types/src/controllers/email.d.ts +34 -0
- package/dist/types/src/controllers/index.d.ts +18 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
- package/dist/types/src/controllers/navigation.d.ts +213 -0
- package/dist/types/src/controllers/registry.d.ts +54 -0
- package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
- package/dist/types/src/controllers/side_entity_controller.d.ts +90 -0
- package/dist/types/src/controllers/snackbar.d.ts +24 -0
- package/dist/types/src/controllers/storage.d.ts +171 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/rebase_context.d.ts +105 -0
- package/dist/types/src/types/backend.d.ts +536 -0
- package/dist/types/src/types/builders.d.ts +15 -0
- package/dist/types/src/types/chips.d.ts +5 -0
- package/dist/types/src/types/collections.d.ts +856 -0
- package/dist/types/src/types/cron.d.ts +102 -0
- package/dist/types/src/types/data_source.d.ts +64 -0
- package/dist/types/src/types/entities.d.ts +145 -0
- package/dist/types/src/types/entity_actions.d.ts +98 -0
- package/dist/types/src/types/entity_callbacks.d.ts +173 -0
- package/dist/types/src/types/entity_link_builder.d.ts +7 -0
- package/dist/types/src/types/entity_overrides.d.ts +10 -0
- package/dist/types/src/types/entity_views.d.ts +61 -0
- package/dist/types/src/types/export_import.d.ts +21 -0
- package/dist/types/src/types/index.d.ts +23 -0
- package/dist/types/src/types/locales.d.ts +4 -0
- package/dist/types/src/types/modify_collections.d.ts +5 -0
- package/dist/types/src/types/plugins.d.ts +279 -0
- package/dist/types/src/types/properties.d.ts +1176 -0
- package/dist/types/src/types/property_config.d.ts +70 -0
- package/dist/types/src/types/relations.d.ts +336 -0
- package/dist/types/src/types/slots.d.ts +252 -0
- package/dist/types/src/types/translations.d.ts +870 -0
- package/dist/types/src/types/user_management_delegate.d.ts +121 -0
- package/dist/types/src/types/websockets.d.ts +78 -0
- package/dist/types/src/users/index.d.ts +2 -0
- package/dist/types/src/users/roles.d.ts +22 -0
- package/dist/types/src/users/user.d.ts +46 -0
- package/package.json +87 -0
- package/src/index.ts +11 -0
- package/src/usePostgresClientDriver.ts +153 -0
- package/tsconfig.json +44 -0
- package/tsconfig.prod.json +20 -0
- package/vite.config.ts +57 -0
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { c } from "react-compiler-runtime";
|
|
2
|
+
function usePostgresClientDriver(config) {
|
|
3
|
+
const $ = c(2);
|
|
4
|
+
const client = config.wsClient;
|
|
5
|
+
let t0;
|
|
6
|
+
if (!client) {
|
|
7
|
+
throw new Error("RebaseWebSocketClient must be provided in config.wsClient");
|
|
8
|
+
}
|
|
9
|
+
let t1;
|
|
10
|
+
if ($[0] !== client) {
|
|
11
|
+
t1 = {
|
|
12
|
+
key: "postgres",
|
|
13
|
+
name: "PostgreSQL",
|
|
14
|
+
client,
|
|
15
|
+
async fetchCollection(props) {
|
|
16
|
+
const {
|
|
17
|
+
path,
|
|
18
|
+
filter,
|
|
19
|
+
limit,
|
|
20
|
+
startAfter,
|
|
21
|
+
orderBy,
|
|
22
|
+
searchString,
|
|
23
|
+
order
|
|
24
|
+
} = props;
|
|
25
|
+
return client.fetchCollection({
|
|
26
|
+
path,
|
|
27
|
+
filter,
|
|
28
|
+
limit,
|
|
29
|
+
startAfter,
|
|
30
|
+
orderBy,
|
|
31
|
+
searchString,
|
|
32
|
+
order
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
async fetchEntity(props_0) {
|
|
36
|
+
const {
|
|
37
|
+
path: path_0,
|
|
38
|
+
entityId,
|
|
39
|
+
databaseId
|
|
40
|
+
} = props_0;
|
|
41
|
+
return client.fetchEntity({
|
|
42
|
+
path: path_0,
|
|
43
|
+
entityId,
|
|
44
|
+
databaseId
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
async saveEntity(props_1) {
|
|
48
|
+
return client.saveEntity({
|
|
49
|
+
path: props_1.path,
|
|
50
|
+
values: props_1.values,
|
|
51
|
+
entityId: props_1.entityId,
|
|
52
|
+
previousValues: props_1.previousValues,
|
|
53
|
+
status: props_1.status
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
async deleteEntity(props_2) {
|
|
57
|
+
const {
|
|
58
|
+
entity
|
|
59
|
+
} = props_2;
|
|
60
|
+
return client.deleteEntity({
|
|
61
|
+
entity
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
async checkUniqueField(path_1, name, value, entityId_0, collection) {
|
|
65
|
+
return client.checkUniqueField(path_1, name, value, entityId_0, collection);
|
|
66
|
+
},
|
|
67
|
+
async countEntities(props_3) {
|
|
68
|
+
const {
|
|
69
|
+
path: path_2,
|
|
70
|
+
filter: filter_0,
|
|
71
|
+
limit: limit_0,
|
|
72
|
+
startAfter: startAfter_0,
|
|
73
|
+
orderBy: orderBy_0,
|
|
74
|
+
searchString: searchString_0,
|
|
75
|
+
order: order_0
|
|
76
|
+
} = props_3;
|
|
77
|
+
return client.countEntities({
|
|
78
|
+
path: path_2,
|
|
79
|
+
filter: filter_0,
|
|
80
|
+
limit: limit_0,
|
|
81
|
+
startAfter: startAfter_0,
|
|
82
|
+
orderBy: orderBy_0,
|
|
83
|
+
searchString: searchString_0,
|
|
84
|
+
order: order_0
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
listenCollection(props_4) {
|
|
88
|
+
const {
|
|
89
|
+
path: path_3,
|
|
90
|
+
filter: filter_1,
|
|
91
|
+
limit: limit_1,
|
|
92
|
+
startAfter: startAfter_1,
|
|
93
|
+
orderBy: orderBy_1,
|
|
94
|
+
searchString: searchString_1,
|
|
95
|
+
order: order_1
|
|
96
|
+
} = props_4;
|
|
97
|
+
return client.listenCollection({
|
|
98
|
+
path: path_3,
|
|
99
|
+
filter: filter_1,
|
|
100
|
+
limit: limit_1,
|
|
101
|
+
startAfter: startAfter_1,
|
|
102
|
+
orderBy: orderBy_1,
|
|
103
|
+
searchString: searchString_1,
|
|
104
|
+
order: order_1
|
|
105
|
+
}, (entities) => props_4.onUpdate(entities), props_4.onError);
|
|
106
|
+
},
|
|
107
|
+
listenEntity(props_5) {
|
|
108
|
+
const {
|
|
109
|
+
path: path_4,
|
|
110
|
+
entityId: entityId_1,
|
|
111
|
+
databaseId: databaseId_0
|
|
112
|
+
} = props_5;
|
|
113
|
+
return client.listenEntity({
|
|
114
|
+
path: path_4,
|
|
115
|
+
entityId: entityId_1,
|
|
116
|
+
databaseId: databaseId_0
|
|
117
|
+
}, (entity_0) => {
|
|
118
|
+
props_5.onUpdate(entity_0);
|
|
119
|
+
}, props_5.onError);
|
|
120
|
+
},
|
|
121
|
+
isFilterCombinationValid() {
|
|
122
|
+
return true;
|
|
123
|
+
},
|
|
124
|
+
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;
|
|
161
|
+
}
|
|
162
|
+
export {
|
|
163
|
+
usePostgresClientDriver
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=index.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/usePostgresClientDriver.ts"],"sourcesContent":["import { useMemo, useEffect } from \"react\";\nimport {\n DataDriver,\n DeleteEntityProps,\n Entity,\n EntityCollection,\n EntityReference, EntityRelation,\n FetchCollectionProps,\n FetchEntityProps,\n ListenCollectionProps,\n ListenEntityProps,\n SaveEntityProps,\n 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: any, entityId?: string, collection?: EntityCollection): Promise<boolean> {\n return client.checkUniqueField(path, name, value, entityId, collection);\n },\n\n async countEntities<M extends Record<string, any>>(props: FetchCollectionProps<M>): Promise<number> {\n const { path, filter, limit, startAfter, orderBy, searchString, order } = props;\n return client.countEntities({ path,\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,2DAA2D;AAAA,EAAA;AAAA,MAAAC;AAAA,MAAAN,SAAAE,QAAA;AAEjFI,SAAA;AAAA,MAAAC,KAEF;AAAA,MAAUC,MAET;AAAA,MAAYN;AAAAA,MAAA,MAAAO,gBAAAC,OAAA;AAMd,cAAA;AAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,QAAAA,IAA0EP;AAAM,eACzER,OAAMO,gBAAA;AAAA,UAAAE;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,QAAAA,CAMlB;AAAA,MAAyB;AAAA,MAAA,MAAAC,YAAAC,SAAA;AAIpB,cAAA;AAAA,UAAAR,MAAAS;AAAAA,UAAAC;AAAAA,UAAAC;AAAAA,QAAAA,IAAuCZ;AAAM,eACtCR,OAAMgB,YAAA;AAAA,UAAAP,MAAeA;AAAAA,UAAIU;AAAAA,UAAAC;AAAAA,QAAAA,CAEhC;AAAA,MAAmC;AAAA,MAAA,MAAAC,WAAAC,SAAA;AAAA,eA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AAI;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;"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react-compiler-runtime")) : typeof define === "function" && define.amd ? define(["exports", "react-compiler-runtime"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["Rebase PostgreSQL"] = {}, global.reactCompilerRuntime));
|
|
3
|
+
})(this, function(exports2, reactCompilerRuntime) {
|
|
4
|
+
"use strict";
|
|
5
|
+
function usePostgresClientDriver(config) {
|
|
6
|
+
const $ = reactCompilerRuntime.c(2);
|
|
7
|
+
const client = config.wsClient;
|
|
8
|
+
let t0;
|
|
9
|
+
if (!client) {
|
|
10
|
+
throw new Error("RebaseWebSocketClient must be provided in config.wsClient");
|
|
11
|
+
}
|
|
12
|
+
let t1;
|
|
13
|
+
if ($[0] !== client) {
|
|
14
|
+
t1 = {
|
|
15
|
+
key: "postgres",
|
|
16
|
+
name: "PostgreSQL",
|
|
17
|
+
client,
|
|
18
|
+
async fetchCollection(props) {
|
|
19
|
+
const {
|
|
20
|
+
path,
|
|
21
|
+
filter,
|
|
22
|
+
limit,
|
|
23
|
+
startAfter,
|
|
24
|
+
orderBy,
|
|
25
|
+
searchString,
|
|
26
|
+
order
|
|
27
|
+
} = props;
|
|
28
|
+
return client.fetchCollection({
|
|
29
|
+
path,
|
|
30
|
+
filter,
|
|
31
|
+
limit,
|
|
32
|
+
startAfter,
|
|
33
|
+
orderBy,
|
|
34
|
+
searchString,
|
|
35
|
+
order
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
async fetchEntity(props_0) {
|
|
39
|
+
const {
|
|
40
|
+
path: path_0,
|
|
41
|
+
entityId,
|
|
42
|
+
databaseId
|
|
43
|
+
} = props_0;
|
|
44
|
+
return client.fetchEntity({
|
|
45
|
+
path: path_0,
|
|
46
|
+
entityId,
|
|
47
|
+
databaseId
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
async saveEntity(props_1) {
|
|
51
|
+
return client.saveEntity({
|
|
52
|
+
path: props_1.path,
|
|
53
|
+
values: props_1.values,
|
|
54
|
+
entityId: props_1.entityId,
|
|
55
|
+
previousValues: props_1.previousValues,
|
|
56
|
+
status: props_1.status
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
async deleteEntity(props_2) {
|
|
60
|
+
const {
|
|
61
|
+
entity
|
|
62
|
+
} = props_2;
|
|
63
|
+
return client.deleteEntity({
|
|
64
|
+
entity
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
async checkUniqueField(path_1, name, value, entityId_0, collection) {
|
|
68
|
+
return client.checkUniqueField(path_1, name, value, entityId_0, collection);
|
|
69
|
+
},
|
|
70
|
+
async countEntities(props_3) {
|
|
71
|
+
const {
|
|
72
|
+
path: path_2,
|
|
73
|
+
filter: filter_0,
|
|
74
|
+
limit: limit_0,
|
|
75
|
+
startAfter: startAfter_0,
|
|
76
|
+
orderBy: orderBy_0,
|
|
77
|
+
searchString: searchString_0,
|
|
78
|
+
order: order_0
|
|
79
|
+
} = props_3;
|
|
80
|
+
return client.countEntities({
|
|
81
|
+
path: path_2,
|
|
82
|
+
filter: filter_0,
|
|
83
|
+
limit: limit_0,
|
|
84
|
+
startAfter: startAfter_0,
|
|
85
|
+
orderBy: orderBy_0,
|
|
86
|
+
searchString: searchString_0,
|
|
87
|
+
order: order_0
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
listenCollection(props_4) {
|
|
91
|
+
const {
|
|
92
|
+
path: path_3,
|
|
93
|
+
filter: filter_1,
|
|
94
|
+
limit: limit_1,
|
|
95
|
+
startAfter: startAfter_1,
|
|
96
|
+
orderBy: orderBy_1,
|
|
97
|
+
searchString: searchString_1,
|
|
98
|
+
order: order_1
|
|
99
|
+
} = props_4;
|
|
100
|
+
return client.listenCollection({
|
|
101
|
+
path: path_3,
|
|
102
|
+
filter: filter_1,
|
|
103
|
+
limit: limit_1,
|
|
104
|
+
startAfter: startAfter_1,
|
|
105
|
+
orderBy: orderBy_1,
|
|
106
|
+
searchString: searchString_1,
|
|
107
|
+
order: order_1
|
|
108
|
+
}, (entities) => props_4.onUpdate(entities), props_4.onError);
|
|
109
|
+
},
|
|
110
|
+
listenEntity(props_5) {
|
|
111
|
+
const {
|
|
112
|
+
path: path_4,
|
|
113
|
+
entityId: entityId_1,
|
|
114
|
+
databaseId: databaseId_0
|
|
115
|
+
} = props_5;
|
|
116
|
+
return client.listenEntity({
|
|
117
|
+
path: path_4,
|
|
118
|
+
entityId: entityId_1,
|
|
119
|
+
databaseId: databaseId_0
|
|
120
|
+
}, (entity_0) => {
|
|
121
|
+
props_5.onUpdate(entity_0);
|
|
122
|
+
}, props_5.onError);
|
|
123
|
+
},
|
|
124
|
+
isFilterCombinationValid() {
|
|
125
|
+
return true;
|
|
126
|
+
},
|
|
127
|
+
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" });
|
|
167
|
+
});
|
|
168
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/usePostgresClientDriver.ts"],"sourcesContent":["import { useMemo, useEffect } from \"react\";\nimport {\n DataDriver,\n DeleteEntityProps,\n Entity,\n EntityCollection,\n EntityReference, EntityRelation,\n FetchCollectionProps,\n FetchEntityProps,\n ListenCollectionProps,\n ListenEntityProps,\n SaveEntityProps,\n 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: any, entityId?: string, collection?: EntityCollection): Promise<boolean> {\n return client.checkUniqueField(path, name, value, entityId, collection);\n },\n\n async countEntities<M extends Record<string, any>>(props: FetchCollectionProps<M>): Promise<number> {\n const { path, filter, limit, startAfter, orderBy, searchString, order } = props;\n return client.countEntities({ path,\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,WAAAA,wBAAAC,QAAA;AAAA,UAAAC,IAAAC,qBAAAA,EAAA,CAAA;AACH,UAAAC,SAAeH,OAAMI;AAAU,QAAAC;AAAA,QAAA,CAGtBF,QAAM;AAAA,YAAA,IAAAG,MAAkB,2DAA2D;A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SAAUzB,QAA0B;AAAA,UAAC,GAE9CpB,QAAK8C,OACT;AAAA,QAAC;AAAA,QAAAO,2BAAA;AAAA,iBAAA;AAAA,QAAA;AAAA,QAAAC,OAAA;AAAA,UAAAC,WAAAC,KAAAC,SAAA;AAAA,mBASUjE,OAAM+D,WAAYC,KAAKC,OAAO;AAAA,UAAC;AAAA,UAAAC,0BAAA;AAAA,mBAG/BlE,OAAMkE,wBAAAA;AAAAA,UAA0B;AAAA,UAAAC,sBAAA;AAAA,mBAGhCnE,OAAMmE,oBAAAA;AAAAA,UAAsB;AAAA,UAAAC,uBAAA;AAAA,mBAG5BpE,OAAMoE,qBAAAA;AAAAA,UAAuB;AAAA,UAAAC,oBAAAC,aAAA;AAAA,mBAG7BtE,OAAMqE,oBAAqBC,WAAW;AAAA,UAAC;AAAA,UAAAC,mBAAAC,WAAA;AAAA,mBAGvCxE,OAAMuE,mBAAoBC,SAAS;AAAA,UAAC;AAAA,UAAAC,aAAAC,QAAAC,WAAA;AAAA,mBAGpC3E,OAAMyE,aAAcnE,QAAM2D,SAAO;AAAA,UAAC;AAAA,UAAAW,aAAAC,QAAA;AAAA,mBAGlC7E,OAAM4E,aAActE,MAAI;AAAA,UAAC;AAAA,UAAAwE,eAAA;AAAA,mBAGzB9E,OAAM8E,aAAAA;AAAAA,UAAe;AAAA,QAAA;AAAA,MAAA;AAGvChF,aAAAE;AAAAF,aAAAM;AAAAA,IAAA,OAAA;AAAAA,WAAAN,EAAA,CAAA;AAAA,IAAA;AAtHGI,SAAOE;AAsHa,WAzHjBF;AAAAA,EA0HK;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type AnalyticsController = {
|
|
2
|
+
/**
|
|
3
|
+
* Callback used to get analytics events from the CMS
|
|
4
|
+
*/
|
|
5
|
+
onAnalyticsEvent?: (event: AnalyticsEvent, data?: object) => void;
|
|
6
|
+
};
|
|
7
|
+
export type AnalyticsEvent = "entity_click" | "entity_click_from_reference" | "reference_selection_clear" | "reference_selection_toggle" | "reference_selected_single" | "reference_selection_new_entity" | "edit_entity_clicked" | "entity_edited" | "new_entity_click" | "new_entity_saved" | "copy_entity_click" | "entity_copied" | "single_delete_dialog_open" | "multiple_delete_dialog_open" | "single_entity_deleted" | "multiple_entities_deleted" | "drawer_navigate_to_home" | "drawer_navigate_to_collection" | "drawer_navigate_to_view" | "home_navigate_to_collection" | "home_favorite_navigate_to_collection" | "home_navigate_to_view" | "home_navigate_to_admin_view" | "home_favorite_navigate_to_view" | "home_move_card" | "home_move_group" | "home_drop_new_group" | "collection_inline_editing" | "view_mode_changed" | "kanban_card_moved" | "kanban_column_reorder" | "kanban_property_changed" | "kanban_new_entity_in_column" | "kanban_backfill_order" | "card_view_entity_click" | "unmapped_event";
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { StorageSource } from "./storage";
|
|
2
|
+
import { Role, User } from "../users";
|
|
3
|
+
import { RebaseData } from "./data";
|
|
4
|
+
/**
|
|
5
|
+
* Capabilities advertised by an auth provider.
|
|
6
|
+
* UI components use this to show/hide features dynamically
|
|
7
|
+
* (e.g. password reset, registration, session management).
|
|
8
|
+
* @group Hooks and utilities
|
|
9
|
+
*/
|
|
10
|
+
export interface AuthCapabilities {
|
|
11
|
+
emailPasswordLogin?: boolean;
|
|
12
|
+
googleLogin?: boolean;
|
|
13
|
+
registration?: boolean;
|
|
14
|
+
passwordReset?: boolean;
|
|
15
|
+
sessionManagement?: boolean;
|
|
16
|
+
profileUpdate?: boolean;
|
|
17
|
+
emailVerification?: boolean;
|
|
18
|
+
/** List of enabled OAuth provider IDs (e.g. ["google", "github", "discord"]) */
|
|
19
|
+
enabledProviders?: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Controller for retrieving the logged user or performing auth related operations.
|
|
23
|
+
* Note that if you are implementing your AuthController, you probably will want
|
|
24
|
+
* to do it as the result of a hook.
|
|
25
|
+
* @group Hooks and utilities
|
|
26
|
+
*/
|
|
27
|
+
export type AuthController<USER extends User = User, ExtraData = unknown> = {
|
|
28
|
+
/**
|
|
29
|
+
* The user currently logged in
|
|
30
|
+
* The values can be: the user object, null if they skipped login
|
|
31
|
+
*/
|
|
32
|
+
user: USER | null;
|
|
33
|
+
/**
|
|
34
|
+
* Initial loading flag. It is used not to display the login screen
|
|
35
|
+
* when the app first loads, and it has not been checked whether the user
|
|
36
|
+
* is logged in or not.
|
|
37
|
+
*/
|
|
38
|
+
initialLoading?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Loading flag. It is used to display a loading screen when the user is
|
|
41
|
+
* logging in or out.
|
|
42
|
+
*/
|
|
43
|
+
authLoading: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Sign out
|
|
46
|
+
*/
|
|
47
|
+
signOut: () => Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Error initializing the authentication
|
|
50
|
+
*/
|
|
51
|
+
authError?: unknown;
|
|
52
|
+
/**
|
|
53
|
+
* Error dispatched by the auth provider
|
|
54
|
+
*/
|
|
55
|
+
authProviderError?: unknown;
|
|
56
|
+
/**
|
|
57
|
+
* You can use this method to retrieve the auth token for the current user.
|
|
58
|
+
*/
|
|
59
|
+
getAuthToken: () => Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Has the user skipped the login process
|
|
62
|
+
*/
|
|
63
|
+
loginSkipped: boolean;
|
|
64
|
+
extra: ExtraData;
|
|
65
|
+
setExtra: (extra: ExtraData) => void;
|
|
66
|
+
setUser?(user: USER | null): void;
|
|
67
|
+
setUserRoles?(roles: Role[]): void;
|
|
68
|
+
/**
|
|
69
|
+
* Capabilities advertised by the auth provider.
|
|
70
|
+
* UI components use this to feature-detect what the backend supports.
|
|
71
|
+
*/
|
|
72
|
+
capabilities?: AuthCapabilities;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Extended auth controller with common optional auth methods.
|
|
76
|
+
* Backend implementations (Rebase backend, Firebase, Supabase, etc.)
|
|
77
|
+
* extend this with their own backend-specific extras.
|
|
78
|
+
* @group Hooks and utilities
|
|
79
|
+
*/
|
|
80
|
+
export interface AuthControllerExtended<USER extends User = User, ExtraData = unknown> extends AuthController<USER, ExtraData> {
|
|
81
|
+
/** Login with email and password */
|
|
82
|
+
emailPasswordLogin?(email: string, password: string): Promise<void>;
|
|
83
|
+
/** Login with a Google ID token or trigger Google popup */
|
|
84
|
+
googleLogin?(idToken: string): Promise<void>;
|
|
85
|
+
/** Register a new user */
|
|
86
|
+
register?(email: string, password: string, displayName?: string): Promise<void>;
|
|
87
|
+
/** Skip login (for anonymous access if enabled) */
|
|
88
|
+
skipLogin?(): void;
|
|
89
|
+
/** Request password reset email */
|
|
90
|
+
forgotPassword?(email: string): Promise<void>;
|
|
91
|
+
/** Reset password using a token */
|
|
92
|
+
resetPassword?(token: string, password: string): Promise<void>;
|
|
93
|
+
/** Change password for the authenticated user */
|
|
94
|
+
changePassword?(oldPassword: string, newPassword: string): Promise<void>;
|
|
95
|
+
/** Update user profile */
|
|
96
|
+
updateProfile?(displayName?: string, photoURL?: string): Promise<USER>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Implement this function to allow access to specific users.
|
|
100
|
+
* @group Hooks and utilities
|
|
101
|
+
*/
|
|
102
|
+
export type Authenticator<USER extends User = User> = (props: {
|
|
103
|
+
/**
|
|
104
|
+
* Logged-in user or null
|
|
105
|
+
*/
|
|
106
|
+
user: USER | null;
|
|
107
|
+
/**
|
|
108
|
+
* AuthController
|
|
109
|
+
*/
|
|
110
|
+
authController: AuthController<USER>;
|
|
111
|
+
/**
|
|
112
|
+
* Unified data access API
|
|
113
|
+
*/
|
|
114
|
+
data: RebaseData;
|
|
115
|
+
/**
|
|
116
|
+
* Used storage implementation
|
|
117
|
+
*/
|
|
118
|
+
storageSource: StorageSource;
|
|
119
|
+
}) => boolean | Promise<boolean>;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { User } from "../users";
|
|
2
|
+
import { RebaseData } from "./data";
|
|
3
|
+
import { EmailService } from "./email";
|
|
4
|
+
/**
|
|
5
|
+
* Event type for authentication state changes
|
|
6
|
+
*/
|
|
7
|
+
export type AuthChangeEvent = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "USER_UPDATED";
|
|
8
|
+
/**
|
|
9
|
+
* Standard session interface representing an authenticated state
|
|
10
|
+
*/
|
|
11
|
+
export interface RebaseSession {
|
|
12
|
+
accessToken: string;
|
|
13
|
+
refreshToken: string;
|
|
14
|
+
expiresAt: number;
|
|
15
|
+
user: User;
|
|
16
|
+
}
|
|
17
|
+
import { StorageSource } from "./storage";
|
|
18
|
+
/**
|
|
19
|
+
* Unified Authentication Client Interface
|
|
20
|
+
* Pure functional SDK interface, decoupled from UI and React hooks
|
|
21
|
+
*/
|
|
22
|
+
export interface AuthClient {
|
|
23
|
+
/**
|
|
24
|
+
* Get the current user from the server or cache
|
|
25
|
+
*/
|
|
26
|
+
getUser(): Promise<User | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Get the currently active session
|
|
29
|
+
*/
|
|
30
|
+
getSession(): RebaseSession | null;
|
|
31
|
+
/**
|
|
32
|
+
* Sign out the current user and clear local session
|
|
33
|
+
*/
|
|
34
|
+
signOut(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Subscribe to authentication state changes
|
|
37
|
+
*/
|
|
38
|
+
onAuthStateChange(callback: (event: AuthChangeEvent, session: RebaseSession | null) => void): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Manually refresh the session token
|
|
41
|
+
*/
|
|
42
|
+
refreshSession(): Promise<RebaseSession>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* User record as returned by the Admin API.
|
|
46
|
+
* @group Admin
|
|
47
|
+
*/
|
|
48
|
+
export interface AdminUser {
|
|
49
|
+
uid: string;
|
|
50
|
+
email: string;
|
|
51
|
+
displayName: string | null;
|
|
52
|
+
photoURL: string | null;
|
|
53
|
+
provider: string;
|
|
54
|
+
roles: string[];
|
|
55
|
+
createdAt: string;
|
|
56
|
+
updatedAt: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Role record as returned by the Admin API.
|
|
60
|
+
* @group Admin
|
|
61
|
+
*/
|
|
62
|
+
export interface AdminRole {
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
isAdmin: boolean;
|
|
66
|
+
defaultPermissions: Record<string, unknown> | null;
|
|
67
|
+
config: Record<string, unknown> | null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Client-side Admin API interface.
|
|
71
|
+
* Provides user and role management operations.
|
|
72
|
+
* @group Admin
|
|
73
|
+
*/
|
|
74
|
+
export interface AdminAPI {
|
|
75
|
+
listUsers(): Promise<{
|
|
76
|
+
users: AdminUser[];
|
|
77
|
+
}>;
|
|
78
|
+
listUsersPaginated(options?: {
|
|
79
|
+
search?: string;
|
|
80
|
+
limit?: number;
|
|
81
|
+
offset?: number;
|
|
82
|
+
orderBy?: string;
|
|
83
|
+
orderDir?: "asc" | "desc";
|
|
84
|
+
}): Promise<{
|
|
85
|
+
users: AdminUser[];
|
|
86
|
+
total: number;
|
|
87
|
+
limit: number;
|
|
88
|
+
offset: number;
|
|
89
|
+
}>;
|
|
90
|
+
getUser(userId: string): Promise<{
|
|
91
|
+
user: AdminUser;
|
|
92
|
+
}>;
|
|
93
|
+
createUser(data: {
|
|
94
|
+
email: string;
|
|
95
|
+
displayName?: string;
|
|
96
|
+
password?: string;
|
|
97
|
+
roles?: string[];
|
|
98
|
+
}): Promise<{
|
|
99
|
+
user: AdminUser;
|
|
100
|
+
}>;
|
|
101
|
+
updateUser(userId: string, data: {
|
|
102
|
+
email?: string;
|
|
103
|
+
displayName?: string;
|
|
104
|
+
password?: string;
|
|
105
|
+
roles?: string[];
|
|
106
|
+
}): Promise<{
|
|
107
|
+
user: AdminUser;
|
|
108
|
+
}>;
|
|
109
|
+
deleteUser(userId: string): Promise<{
|
|
110
|
+
success: boolean;
|
|
111
|
+
}>;
|
|
112
|
+
listRoles(): Promise<{
|
|
113
|
+
roles: AdminRole[];
|
|
114
|
+
}>;
|
|
115
|
+
getRole(roleId: string): Promise<{
|
|
116
|
+
role: AdminRole;
|
|
117
|
+
}>;
|
|
118
|
+
createRole(data: {
|
|
119
|
+
id: string;
|
|
120
|
+
name: string;
|
|
121
|
+
isAdmin?: boolean;
|
|
122
|
+
defaultPermissions?: Record<string, unknown>;
|
|
123
|
+
config?: Record<string, unknown>;
|
|
124
|
+
}): Promise<{
|
|
125
|
+
role: AdminRole;
|
|
126
|
+
}>;
|
|
127
|
+
updateRole(roleId: string, data: {
|
|
128
|
+
name?: string;
|
|
129
|
+
isAdmin?: boolean;
|
|
130
|
+
defaultPermissions?: Record<string, unknown>;
|
|
131
|
+
config?: Record<string, unknown>;
|
|
132
|
+
}): Promise<{
|
|
133
|
+
role: AdminRole;
|
|
134
|
+
}>;
|
|
135
|
+
deleteRole(roleId: string): Promise<{
|
|
136
|
+
success: boolean;
|
|
137
|
+
}>;
|
|
138
|
+
bootstrap(): Promise<{
|
|
139
|
+
success: boolean;
|
|
140
|
+
message: string;
|
|
141
|
+
user: {
|
|
142
|
+
uid: string;
|
|
143
|
+
roles: string[];
|
|
144
|
+
};
|
|
145
|
+
}>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Overarching abstraction that unites Data, Auth, Storage, and Email.
|
|
149
|
+
* Adapters for Supabase or Firebase simply need to implement this interface.
|
|
150
|
+
*/
|
|
151
|
+
export interface RebaseClient<DB = unknown> {
|
|
152
|
+
/** Unified Data access layer */
|
|
153
|
+
data: RebaseData;
|
|
154
|
+
/** Unified Authentication layer */
|
|
155
|
+
auth: AuthClient;
|
|
156
|
+
/** Unified Storage layer */
|
|
157
|
+
storage?: StorageSource;
|
|
158
|
+
/**
|
|
159
|
+
* Server-side email service.
|
|
160
|
+
*
|
|
161
|
+
* Available when SMTP (or a custom `sendEmail` function) is configured
|
|
162
|
+
* in the backend auth config. `undefined` when email is not configured.
|
|
163
|
+
*
|
|
164
|
+
* > **Note:** This is only available on the server-side `rebase` singleton.
|
|
165
|
+
* > The client-side SDK does not include an email service.
|
|
166
|
+
*/
|
|
167
|
+
email?: EmailService;
|
|
168
|
+
/** Admin API for user and role management */
|
|
169
|
+
admin?: AdminAPI;
|
|
170
|
+
}
|