@rebasepro/client-firebase 0.8.0 → 0.9.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/dist/components/RebaseFirebaseAppProps.d.ts +2 -2
- package/dist/hooks/useBuildUserManagement.d.ts +1 -0
- package/dist/hooks/useFirestoreDriver.d.ts +3 -3
- package/dist/index.es.js +141 -137
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +139 -135
- package/dist/index.umd.js.map +1 -1
- package/dist/types/text_search.d.ts +3 -3
- package/dist/utils/collections_firestore.d.ts +3 -3
- package/package.json +7 -7
- package/src/components/RebaseFirebaseApp.tsx +10 -5
- package/src/components/RebaseFirebaseAppProps.tsx +2 -2
- package/src/hooks/useBuildUserManagement.tsx +27 -28
- package/src/hooks/useFirebaseRealTimeDBDelegate.ts +47 -52
- package/src/hooks/useFirebaseStorageSource.ts +2 -2
- package/src/hooks/useFirestoreDriver.ts +113 -95
- package/src/types/text_search.ts +3 -3
- package/src/utils/collections_firestore.ts +5 -5
- package/src/utils/database.ts +2 -2
- package/src/utils/local_text_search_controller.ts +6 -6
- package/src/utils/pinecone.ts +2 -2
- package/src/utils/rebase_search_controller.ts +3 -3
- package/src/utils/text_search_controller.ts +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -292,8 +292,8 @@
|
|
|
292
292
|
}, 5e3);
|
|
293
293
|
};
|
|
294
294
|
setProgressTimeout();
|
|
295
|
-
uploadTask.on("state_changed", (
|
|
296
|
-
const progress =
|
|
295
|
+
uploadTask.on("state_changed", (entity) => {
|
|
296
|
+
const progress = entity.bytesTransferred / entity.totalBytes * 100;
|
|
297
297
|
if (progress > lastProgress) {
|
|
298
298
|
lastProgress = progress;
|
|
299
299
|
setProgressTimeout();
|
|
@@ -616,8 +616,8 @@
|
|
|
616
616
|
//#region src/utils/database.ts
|
|
617
617
|
async function getFirestoreDataInPath(firebaseApp, path, parentPaths, limit) {
|
|
618
618
|
const firestore = (0, _firebase_firestore.getFirestore)(firebaseApp);
|
|
619
|
-
if (!parentPaths || parentPaths.length === 0) return (0, _firebase_firestore.getDocs)((0, _firebase_firestore.query)((0, _firebase_firestore.collection)(firestore, path), (0, _firebase_firestore.limit)(limit))).then((
|
|
620
|
-
return
|
|
619
|
+
if (!parentPaths || parentPaths.length === 0) return (0, _firebase_firestore.getDocs)((0, _firebase_firestore.query)((0, _firebase_firestore.collection)(firestore, path), (0, _firebase_firestore.limit)(limit))).then((queryEntity) => {
|
|
620
|
+
return queryEntity.docs.map((doc) => doc.data());
|
|
621
621
|
});
|
|
622
622
|
else {
|
|
623
623
|
let currentDocs = void 0;
|
|
@@ -729,9 +729,9 @@
|
|
|
729
729
|
if (collectionProp) {
|
|
730
730
|
console.debug("Init local search controller", path);
|
|
731
731
|
listeners[path] = (0, _firebase_firestore.onSnapshot)((0, _firebase_firestore.query)((0, _firebase_firestore.collection)(databaseId ? (0, _firebase_firestore.getFirestore)(firebaseApp, databaseId) : (0, _firebase_firestore.getFirestore)(firebaseApp), path)), {
|
|
732
|
-
next: (
|
|
733
|
-
if (
|
|
734
|
-
const docs =
|
|
732
|
+
next: (entity) => {
|
|
733
|
+
if (entity.metadata.fromCache && entity.metadata.hasPendingWrites) return;
|
|
734
|
+
const docs = entity.docs.map((doc) => ({
|
|
735
735
|
id: doc.id,
|
|
736
736
|
...doc.data()
|
|
737
737
|
}));
|
|
@@ -998,6 +998,15 @@
|
|
|
998
998
|
const queryParams = [];
|
|
999
999
|
if (filter) Object.entries(filter).filter(([_, entry]) => !!entry).forEach(([key, filterParameter]) => {
|
|
1000
1000
|
const [op, value] = filterParameter;
|
|
1001
|
+
if (op === "is-null") {
|
|
1002
|
+
queryParams.push((0, _firebase_firestore.where)(key, "==", null));
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
if (op === "is-not-null") {
|
|
1006
|
+
queryParams.push((0, _firebase_firestore.where)(key, "!=", null));
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
if (op === "like" || op === "ilike" || op === "not-like" || op === "not-ilike") throw new Error(`Firestore does not support the "${op}" operator (SQL pattern matching). Use a full-text search index or the collection's searchString instead.`);
|
|
1001
1010
|
queryParams.push((0, _firebase_firestore.where)(key, op, cmsToFirestoreModel(value, firestore)));
|
|
1002
1011
|
});
|
|
1003
1012
|
if (orderBy && order) queryParams.push((0, _firebase_firestore.orderBy)(orderBy, order));
|
|
@@ -1005,19 +1014,19 @@
|
|
|
1005
1014
|
if (limit) queryParams.push((0, _firebase_firestore.limit)(limit));
|
|
1006
1015
|
return (0, _firebase_firestore.query)(collectionReference, ...queryParams);
|
|
1007
1016
|
}, [firebaseApp]);
|
|
1008
|
-
const getAndBuildEntity = (0, react.useCallback)((path,
|
|
1017
|
+
const getAndBuildEntity = (0, react.useCallback)((path, id, databaseId) => {
|
|
1009
1018
|
if (!firebaseApp) throw Error("useFirestoreDriver Firebase not initialised");
|
|
1010
|
-
return (0, _firebase_firestore.getDoc)((0, _firebase_firestore.doc)(databaseId ? (0, _firebase_firestore.getFirestore)(firebaseApp, databaseId) : (0, _firebase_firestore.getFirestore)(firebaseApp), path, String(
|
|
1011
|
-
if (!
|
|
1012
|
-
return
|
|
1019
|
+
return (0, _firebase_firestore.getDoc)((0, _firebase_firestore.doc)(databaseId ? (0, _firebase_firestore.getFirestore)(firebaseApp, databaseId) : (0, _firebase_firestore.getFirestore)(firebaseApp), path, String(id))).then((docEntity) => {
|
|
1020
|
+
if (!docEntity.exists()) return;
|
|
1021
|
+
return createRowFromDocument(docEntity);
|
|
1013
1022
|
});
|
|
1014
1023
|
}, [firebaseApp]);
|
|
1015
|
-
const
|
|
1024
|
+
const listenOne = (0, react.useCallback)(({ path, id, collection, onUpdate, onError }) => {
|
|
1016
1025
|
if (!firebaseApp) throw Error("useFirestoreDriver Firebase not initialised");
|
|
1017
1026
|
const databaseId = collection?.databaseId;
|
|
1018
|
-
return (0, _firebase_firestore.onSnapshot)((0, _firebase_firestore.doc)(databaseId ? (0, _firebase_firestore.getFirestore)(firebaseApp, databaseId) : (0, _firebase_firestore.getFirestore)(firebaseApp), path, String(
|
|
1019
|
-
next: (
|
|
1020
|
-
onUpdate(
|
|
1027
|
+
return (0, _firebase_firestore.onSnapshot)((0, _firebase_firestore.doc)(databaseId ? (0, _firebase_firestore.getFirestore)(firebaseApp, databaseId) : (0, _firebase_firestore.getFirestore)(firebaseApp), path, String(id)), {
|
|
1028
|
+
next: (docEntity) => {
|
|
1029
|
+
onUpdate(docEntity.exists() ? createRowFromDocument(docEntity) : null);
|
|
1021
1030
|
},
|
|
1022
1031
|
error: onError
|
|
1023
1032
|
});
|
|
@@ -1040,22 +1049,23 @@
|
|
|
1040
1049
|
subscriptions = [];
|
|
1041
1050
|
onUpdate([]);
|
|
1042
1051
|
}
|
|
1043
|
-
const
|
|
1052
|
+
const rows = [];
|
|
1044
1053
|
const addedEntitiesSet = /* @__PURE__ */ new Set();
|
|
1045
|
-
subscriptions = (ids ?? []).map((
|
|
1046
|
-
return
|
|
1054
|
+
subscriptions = (ids ?? []).map((id) => {
|
|
1055
|
+
return listenOne({
|
|
1047
1056
|
path,
|
|
1048
|
-
|
|
1049
|
-
onUpdate: (
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1057
|
+
id,
|
|
1058
|
+
onUpdate: (row) => {
|
|
1059
|
+
const incomingId = row?.id;
|
|
1060
|
+
if (row && incomingId !== void 0) {
|
|
1061
|
+
if (!addedEntitiesSet.has(incomingId)) {
|
|
1062
|
+
addedEntitiesSet.add(incomingId);
|
|
1063
|
+
rows.push(row);
|
|
1064
|
+
onUpdate(rows);
|
|
1055
1065
|
}
|
|
1056
|
-
} else
|
|
1057
|
-
addedEntitiesSet.delete(
|
|
1058
|
-
onUpdate([...
|
|
1066
|
+
} else {
|
|
1067
|
+
addedEntitiesSet.delete(id);
|
|
1068
|
+
onUpdate([...rows.filter((r) => r.id !== id)]);
|
|
1059
1069
|
}
|
|
1060
1070
|
}
|
|
1061
1071
|
});
|
|
@@ -1064,7 +1074,7 @@
|
|
|
1064
1074
|
return () => {
|
|
1065
1075
|
subscriptions.forEach((p) => p());
|
|
1066
1076
|
};
|
|
1067
|
-
}, [firebaseApp,
|
|
1077
|
+
}, [firebaseApp, listenOne]);
|
|
1068
1078
|
const initTextSearch = (0, react.useCallback)(async (props) => {
|
|
1069
1079
|
console.debug("Init text search controller", searchControllerRef.current, props.path);
|
|
1070
1080
|
if (!searchControllerRef.current) {
|
|
@@ -1089,7 +1099,7 @@
|
|
|
1089
1099
|
* @param orderBy
|
|
1090
1100
|
* @param order
|
|
1091
1101
|
* @return Function to cancel subscription
|
|
1092
|
-
* @see
|
|
1102
|
+
* @see useCollection if you need this functionality implemented as a hook
|
|
1093
1103
|
* @group Firestore
|
|
1094
1104
|
*/
|
|
1095
1105
|
const fetchCollection = (0, react.useCallback)(async ({ path, filter, limit, startAfter, searchString, orderBy, order, collection }) => {
|
|
@@ -1103,7 +1113,7 @@
|
|
|
1103
1113
|
orderBy,
|
|
1104
1114
|
order
|
|
1105
1115
|
});
|
|
1106
|
-
return (await (0, _firebase_firestore.getDocs)(buildQuery(resolvedPath, filter, orderBy, order, startAfter, limit, databaseId))).docs.map((doc) =>
|
|
1116
|
+
return (await (0, _firebase_firestore.getDocs)(buildQuery(resolvedPath, filter, orderBy, order, startAfter, limit, databaseId))).docs.map((doc) => createRowFromDocument(doc));
|
|
1107
1117
|
}, [buildQuery]);
|
|
1108
1118
|
/**
|
|
1109
1119
|
* Listen to a entities in a given path
|
|
@@ -1118,7 +1128,7 @@
|
|
|
1118
1128
|
* @param order
|
|
1119
1129
|
* @param onUpdate
|
|
1120
1130
|
* @return Function to cancel subscription
|
|
1121
|
-
* @see
|
|
1131
|
+
* @see useCollection if you need this functionality implemented as a hook
|
|
1122
1132
|
* @group Firestore
|
|
1123
1133
|
*/
|
|
1124
1134
|
const listenCollection = (0, react.useCallback)(({ path, filter, limit, startAfter, searchString, orderBy, order, onUpdate, onError, collection }) => {
|
|
@@ -1146,8 +1156,8 @@
|
|
|
1146
1156
|
resolvedPath
|
|
1147
1157
|
});
|
|
1148
1158
|
return (0, _firebase_firestore.onSnapshot)(buildQuery(resolvedPath, filter, orderBy, order, startAfter, limit, databaseId), {
|
|
1149
|
-
next: (
|
|
1150
|
-
if (!searchString) onUpdate(
|
|
1159
|
+
next: (entity) => {
|
|
1160
|
+
if (!searchString) onUpdate(entity.docs.map((doc) => createRowFromDocument(doc)));
|
|
1151
1161
|
},
|
|
1152
1162
|
error: onError
|
|
1153
1163
|
});
|
|
@@ -1157,38 +1167,38 @@
|
|
|
1157
1167
|
performTextSearch
|
|
1158
1168
|
]);
|
|
1159
1169
|
/**
|
|
1160
|
-
* Retrieve
|
|
1170
|
+
* Retrieve a entity given a path and a collection
|
|
1161
1171
|
* @param path
|
|
1162
|
-
* @param
|
|
1172
|
+
* @param id
|
|
1163
1173
|
* @param collection
|
|
1164
1174
|
* @group Firestore
|
|
1165
1175
|
*/
|
|
1166
|
-
const
|
|
1167
|
-
return getAndBuildEntity(path,
|
|
1176
|
+
const fetchOne = (0, react.useCallback)(({ path, id, collection }) => {
|
|
1177
|
+
return getAndBuildEntity(path, id, collection?.databaseId);
|
|
1168
1178
|
}, [getAndBuildEntity]);
|
|
1169
1179
|
/**
|
|
1170
1180
|
* Save entity to the specified path. Note that Firestore does not allow
|
|
1171
1181
|
* undefined values.
|
|
1172
1182
|
* @param path
|
|
1173
|
-
* @param
|
|
1183
|
+
* @param id
|
|
1174
1184
|
* @param values
|
|
1175
1185
|
* @param schemaId
|
|
1176
1186
|
* @param collection
|
|
1177
1187
|
* @param status
|
|
1178
1188
|
* @group Firestore
|
|
1179
1189
|
*/
|
|
1180
|
-
const
|
|
1190
|
+
const save = (0, react.useCallback)(({ path, id, values: valuesProp, collection, status }) => {
|
|
1181
1191
|
if (!firebaseApp) throw Error("useFirestoreDriver Firebase not initialised");
|
|
1182
1192
|
console.debug("1", {
|
|
1183
1193
|
path,
|
|
1184
|
-
|
|
1194
|
+
id,
|
|
1185
1195
|
values: valuesProp,
|
|
1186
1196
|
collection
|
|
1187
1197
|
});
|
|
1188
1198
|
const values = cmsToFirestoreModel(valuesProp, (0, _firebase_firestore.getFirestore)(firebaseApp));
|
|
1189
1199
|
console.debug("2", {
|
|
1190
1200
|
path,
|
|
1191
|
-
|
|
1201
|
+
id,
|
|
1192
1202
|
values: valuesProp,
|
|
1193
1203
|
collection
|
|
1194
1204
|
});
|
|
@@ -1196,18 +1206,17 @@
|
|
|
1196
1206
|
const collectionReference = (0, _firebase_firestore.collection)(databaseId ? (0, _firebase_firestore.getFirestore)(firebaseApp, databaseId) : (0, _firebase_firestore.getFirestore)(firebaseApp), path);
|
|
1197
1207
|
console.debug("Saving entity", {
|
|
1198
1208
|
path,
|
|
1199
|
-
|
|
1209
|
+
id,
|
|
1200
1210
|
values,
|
|
1201
1211
|
databaseId
|
|
1202
1212
|
});
|
|
1203
1213
|
let documentReference;
|
|
1204
|
-
if (
|
|
1214
|
+
if (id) documentReference = (0, _firebase_firestore.doc)(collectionReference, String(id));
|
|
1205
1215
|
else documentReference = (0, _firebase_firestore.doc)(collectionReference);
|
|
1206
1216
|
return (0, _firebase_firestore.setDoc)(documentReference, values, { merge: true }).then(() => {
|
|
1207
1217
|
return {
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
values: firestoreToCMSModel(values)
|
|
1218
|
+
...firestoreToCMSModel(values),
|
|
1219
|
+
id: documentReference.id
|
|
1211
1220
|
};
|
|
1212
1221
|
}).catch((error) => {
|
|
1213
1222
|
console.error("Error saving entity", error);
|
|
@@ -1215,15 +1224,15 @@
|
|
|
1215
1224
|
});
|
|
1216
1225
|
}, [firebaseApp]);
|
|
1217
1226
|
/**
|
|
1218
|
-
* Delete
|
|
1227
|
+
* Delete a entity
|
|
1219
1228
|
* @param entity
|
|
1220
1229
|
* @param collection
|
|
1221
1230
|
* @group Firestore
|
|
1222
1231
|
*/
|
|
1223
|
-
const
|
|
1232
|
+
const deleteOne = (0, react.useCallback)(({ row, collection }) => {
|
|
1224
1233
|
if (!firebaseApp) throw Error("useFirestoreDriver Firebase not initialised");
|
|
1225
|
-
const databaseId =
|
|
1226
|
-
return (0, _firebase_firestore.deleteDoc)((0, _firebase_firestore.doc)(databaseId ? (0, _firebase_firestore.getFirestore)(firebaseApp, databaseId) : (0, _firebase_firestore.getFirestore)(firebaseApp),
|
|
1234
|
+
const databaseId = collection?.databaseId;
|
|
1235
|
+
return (0, _firebase_firestore.deleteDoc)((0, _firebase_firestore.doc)(databaseId ? (0, _firebase_firestore.getFirestore)(firebaseApp, databaseId) : (0, _firebase_firestore.getFirestore)(firebaseApp), row.path, String(row.id)));
|
|
1227
1236
|
}, [firebaseApp]);
|
|
1228
1237
|
/**
|
|
1229
1238
|
* Check if the given property is unique in the given collection
|
|
@@ -1231,18 +1240,18 @@
|
|
|
1231
1240
|
* @param name of the property
|
|
1232
1241
|
* @param value
|
|
1233
1242
|
* @param property
|
|
1234
|
-
* @param
|
|
1243
|
+
* @param id
|
|
1235
1244
|
* @return `true` if there are no other fields besides the given entity
|
|
1236
1245
|
* @group Firestore
|
|
1237
1246
|
*/
|
|
1238
|
-
const checkUniqueField = (0, react.useCallback)(async (path, name, value,
|
|
1247
|
+
const checkUniqueField = (0, react.useCallback)(async (path, name, value, id, collection) => {
|
|
1239
1248
|
if (!firebaseApp) throw Error("useFirestoreDriver Firebase not initialised");
|
|
1240
1249
|
const databaseId = collection?.databaseId;
|
|
1241
1250
|
const firestore = databaseId ? (0, _firebase_firestore.getFirestore)(firebaseApp, databaseId) : (0, _firebase_firestore.getFirestore)(firebaseApp);
|
|
1242
1251
|
if (value === void 0 || value === null) return Promise.resolve(true);
|
|
1243
|
-
return (await (0, _firebase_firestore.getDocs)((0, _firebase_firestore.query)((0, _firebase_firestore.collection)(firestore, path), (0, _firebase_firestore.where)(name, "==", cmsToFirestoreModel(value, firestore))))).docs.filter((doc) => doc.id !==
|
|
1252
|
+
return (await (0, _firebase_firestore.getDocs)((0, _firebase_firestore.query)((0, _firebase_firestore.collection)(firestore, path), (0, _firebase_firestore.where)(name, "==", cmsToFirestoreModel(value, firestore))))).docs.filter((doc) => doc.id !== id).length === 0;
|
|
1244
1253
|
}, [firebaseApp]);
|
|
1245
|
-
const
|
|
1254
|
+
const count = (0, react.useCallback)(async ({ path, filter, order, orderBy, collection }) => {
|
|
1246
1255
|
if (!firebaseApp) throw Error("useFirestoreDriver Firebase not initialised");
|
|
1247
1256
|
const databaseId = collection?.databaseId;
|
|
1248
1257
|
return (await (0, _firebase_firestore.getCountFromServer)(buildQuery(path, filter, orderBy, order, void 0, void 0, databaseId))).data().count;
|
|
@@ -1271,35 +1280,31 @@
|
|
|
1271
1280
|
initTextSearch,
|
|
1272
1281
|
fetchCollection,
|
|
1273
1282
|
listenCollection,
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1283
|
+
fetchOne,
|
|
1284
|
+
listenOne,
|
|
1285
|
+
save,
|
|
1286
|
+
delete: deleteOne,
|
|
1278
1287
|
checkUniqueField,
|
|
1279
|
-
|
|
1288
|
+
count,
|
|
1280
1289
|
isFilterCombinationValid
|
|
1281
1290
|
}), [
|
|
1282
1291
|
firebaseApp,
|
|
1283
1292
|
initTextSearch,
|
|
1284
1293
|
fetchCollection,
|
|
1285
1294
|
listenCollection,
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1295
|
+
fetchOne,
|
|
1296
|
+
listenOne,
|
|
1297
|
+
save,
|
|
1298
|
+
deleteOne,
|
|
1290
1299
|
checkUniqueField,
|
|
1291
|
-
|
|
1300
|
+
count,
|
|
1292
1301
|
isFilterCombinationValid
|
|
1293
1302
|
]);
|
|
1294
1303
|
}
|
|
1295
|
-
var
|
|
1296
|
-
const values = firestoreToCMSModel(docSnap.data());
|
|
1297
|
-
const path = getCMSPathFromFirestorePath(docSnap.ref.path);
|
|
1304
|
+
var createRowFromDocument = (docSnap) => {
|
|
1298
1305
|
return {
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
values,
|
|
1302
|
-
databaseId
|
|
1306
|
+
...firestoreToCMSModel(docSnap.data()),
|
|
1307
|
+
id: docSnap.id
|
|
1303
1308
|
};
|
|
1304
1309
|
};
|
|
1305
1310
|
/**
|
|
@@ -1414,70 +1419,65 @@
|
|
|
1414
1419
|
let dbQuery = (0, _firebase_database.query)((0, _firebase_database.ref)((0, _firebase_database.getDatabase)(firebaseApp), path));
|
|
1415
1420
|
if (startAfter !== void 0) dbQuery = (0, _firebase_database.query)(dbQuery, (0, _firebase_database.orderByKey)(), (0, _firebase_database.startAt)(String(startAfter)));
|
|
1416
1421
|
if (limit !== void 0) dbQuery = (0, _firebase_database.query)(dbQuery, (0, _firebase_database.limitToFirst)(limit));
|
|
1417
|
-
const
|
|
1418
|
-
if (
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
values: delegateToCMSModel(values)
|
|
1422
|
+
const entity = await (0, _firebase_database.get)(dbQuery);
|
|
1423
|
+
if (entity.exists()) return Object.entries(entity.val()).map(([id, values]) => ({
|
|
1424
|
+
...delegateToCMSModel(values),
|
|
1425
|
+
id
|
|
1422
1426
|
}));
|
|
1423
1427
|
return [];
|
|
1424
1428
|
}, [firebaseApp]),
|
|
1425
1429
|
listenCollection: (0, react.useCallback)(({ path, onUpdate }) => {
|
|
1426
1430
|
if (!firebaseApp) throw new Error("Firebase app not provided");
|
|
1427
|
-
const unsubscribe = (0, _firebase_database.onValue)((0, _firebase_database.ref)((0, _firebase_database.getDatabase)(firebaseApp), path), (
|
|
1428
|
-
if (
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
values: delegateToCMSModel(values)
|
|
1431
|
+
const unsubscribe = (0, _firebase_database.onValue)((0, _firebase_database.ref)((0, _firebase_database.getDatabase)(firebaseApp), path), (entity) => {
|
|
1432
|
+
if (entity.exists()) onUpdate(Object.entries(entity.val()).map(([id, values]) => ({
|
|
1433
|
+
...delegateToCMSModel(values),
|
|
1434
|
+
id
|
|
1432
1435
|
})));
|
|
1433
1436
|
else onUpdate([]);
|
|
1434
1437
|
});
|
|
1435
1438
|
return () => unsubscribe();
|
|
1436
1439
|
}, [firebaseApp]),
|
|
1437
|
-
|
|
1440
|
+
fetchOne: (0, react.useCallback)(async ({ path, id }) => {
|
|
1438
1441
|
if (!firebaseApp) throw new Error("Firebase app not provided");
|
|
1439
|
-
const
|
|
1440
|
-
if (
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
values: delegateToCMSModel(snapshot.val())
|
|
1442
|
+
const entity = await (0, _firebase_database.get)((0, _firebase_database.ref)((0, _firebase_database.getDatabase)(firebaseApp), `${path}/${id}`));
|
|
1443
|
+
if (entity.exists()) return {
|
|
1444
|
+
...delegateToCMSModel(entity.val()),
|
|
1445
|
+
id
|
|
1444
1446
|
};
|
|
1445
1447
|
}, [firebaseApp]),
|
|
1446
|
-
|
|
1448
|
+
listenOne: (0, react.useCallback)(({ path, id, onUpdate, onError }) => {
|
|
1447
1449
|
if (!firebaseApp) throw new Error("Firebase app not provided");
|
|
1448
|
-
const unsubscribe = (0, _firebase_database.onValue)((0, _firebase_database.ref)((0, _firebase_database.getDatabase)(firebaseApp), `${path}/${
|
|
1449
|
-
if (
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
values: delegateToCMSModel(snapshot.val())
|
|
1450
|
+
const unsubscribe = (0, _firebase_database.onValue)((0, _firebase_database.ref)((0, _firebase_database.getDatabase)(firebaseApp), `${path}/${id}`), (entity) => {
|
|
1451
|
+
if (entity.exists()) onUpdate({
|
|
1452
|
+
...delegateToCMSModel(entity.val()),
|
|
1453
|
+
id
|
|
1453
1454
|
});
|
|
1454
1455
|
else onError?.(/* @__PURE__ */ new Error("Entity does not exist"));
|
|
1455
1456
|
});
|
|
1456
1457
|
return () => unsubscribe();
|
|
1457
1458
|
}, [firebaseApp]),
|
|
1458
|
-
|
|
1459
|
+
save: (0, react.useCallback)(async ({ path, id, values }) => {
|
|
1459
1460
|
if (!firebaseApp) throw new Error("Firebase app not provided");
|
|
1460
1461
|
const database = (0, _firebase_database.getDatabase)(firebaseApp);
|
|
1461
|
-
const finalId =
|
|
1462
|
+
const finalId = id ?? (0, _firebase_database.push)((0, _firebase_database.ref)(database, path)).key;
|
|
1462
1463
|
if (!finalId) throw new Error("Could not generate a new id");
|
|
1463
1464
|
const transformedValues = cmsToRTDBModel(values, database);
|
|
1464
1465
|
await (0, _firebase_database.set)((0, _firebase_database.ref)(database, `${path}/${finalId}`), transformedValues);
|
|
1465
1466
|
return {
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
values
|
|
1467
|
+
...values,
|
|
1468
|
+
id: finalId
|
|
1469
1469
|
};
|
|
1470
1470
|
}, [firebaseApp]),
|
|
1471
|
-
|
|
1471
|
+
delete: (0, react.useCallback)(async ({ row }) => {
|
|
1472
1472
|
if (!firebaseApp) throw new Error("Firebase app not provided");
|
|
1473
|
-
await (0, _firebase_database.remove)((0, _firebase_database.ref)((0, _firebase_database.getDatabase)(firebaseApp), `${
|
|
1473
|
+
await (0, _firebase_database.remove)((0, _firebase_database.ref)((0, _firebase_database.getDatabase)(firebaseApp), `${row.path}/${row.id}`));
|
|
1474
1474
|
}, [firebaseApp]),
|
|
1475
|
-
checkUniqueField: (0, react.useCallback)(async (slug, name, value,
|
|
1475
|
+
checkUniqueField: (0, react.useCallback)(async (slug, name, value, id) => {
|
|
1476
1476
|
if (!firebaseApp) throw new Error("Firebase app not provided");
|
|
1477
|
-
const
|
|
1478
|
-
if (!
|
|
1479
|
-
const [key, entityValue] = Object.entries(
|
|
1480
|
-
if (entityValue && typeof entityValue === "object" && entityValue[name] === value && key ===
|
|
1477
|
+
const entity = await (0, _firebase_database.get)((0, _firebase_database.query)((0, _firebase_database.ref)((0, _firebase_database.getDatabase)(firebaseApp), slug), (0, _firebase_database.orderByChild)(name), (0, _firebase_database.startAt)(value), (0, _firebase_database.limitToFirst)(1)));
|
|
1478
|
+
if (!entity.exists()) return true;
|
|
1479
|
+
const [key, entityValue] = Object.entries(entity.val())[0];
|
|
1480
|
+
if (entityValue && typeof entityValue === "object" && entityValue[name] === value && key === id) return true;
|
|
1481
1481
|
return false;
|
|
1482
1482
|
}, [firebaseApp]),
|
|
1483
1483
|
isFilterCombinationValid: (0, react.useCallback)(({ path, filter, sortBy }) => {
|
|
@@ -1567,11 +1567,11 @@
|
|
|
1567
1567
|
setRolesLoading(true);
|
|
1568
1568
|
return dataSourceDelegate.listenCollection?.({
|
|
1569
1569
|
path: rolesPath,
|
|
1570
|
-
onUpdate(
|
|
1570
|
+
onUpdate(rows) {
|
|
1571
1571
|
setRolesError(void 0);
|
|
1572
|
-
console.debug("Updating roles",
|
|
1572
|
+
console.debug("Updating roles", rows);
|
|
1573
1573
|
try {
|
|
1574
|
-
const newRoles =
|
|
1574
|
+
const newRoles = rowsToRoles(rows);
|
|
1575
1575
|
if (!(0, fast_equals.deepEqual)(newRoles, roles)) setRoles(newRoles);
|
|
1576
1576
|
} catch (e) {
|
|
1577
1577
|
setRoles([]);
|
|
@@ -1601,11 +1601,11 @@
|
|
|
1601
1601
|
setUsersLoading(true);
|
|
1602
1602
|
return dataSourceDelegate.listenCollection?.({
|
|
1603
1603
|
path: usersPath,
|
|
1604
|
-
onUpdate(
|
|
1605
|
-
console.debug("Updating users",
|
|
1604
|
+
onUpdate(rows) {
|
|
1605
|
+
console.debug("Updating users", rows);
|
|
1606
1606
|
setUsersError(void 0);
|
|
1607
1607
|
try {
|
|
1608
|
-
setUsersWithRoleIds(
|
|
1608
|
+
setUsersWithRoleIds(rowsToUsers(rows));
|
|
1609
1609
|
} catch (e) {
|
|
1610
1610
|
setUsersWithRoleIds([]);
|
|
1611
1611
|
console.error("Error loading users", e);
|
|
@@ -1640,21 +1640,21 @@
|
|
|
1640
1640
|
...userExists ? {} : { created_on: /* @__PURE__ */ new Date() }
|
|
1641
1641
|
};
|
|
1642
1642
|
if (userExists && userExists.uid !== user.uid) {
|
|
1643
|
-
const
|
|
1643
|
+
const row = {
|
|
1644
1644
|
values: {},
|
|
1645
1645
|
path: usersPath,
|
|
1646
1646
|
id: userExists.uid
|
|
1647
1647
|
};
|
|
1648
|
-
await dataSourceDelegate.
|
|
1648
|
+
await dataSourceDelegate.delete({ row }).then(() => {
|
|
1649
1649
|
console.debug("Deleted previous user", userExists);
|
|
1650
1650
|
}).catch((e) => {
|
|
1651
1651
|
console.error("Error deleting user", e);
|
|
1652
1652
|
});
|
|
1653
1653
|
}
|
|
1654
|
-
return dataSourceDelegate.
|
|
1654
|
+
return dataSourceDelegate.save({
|
|
1655
1655
|
status: "existing",
|
|
1656
1656
|
path: usersPath,
|
|
1657
|
-
|
|
1657
|
+
id: email,
|
|
1658
1658
|
values: (0, _rebasepro_utils.removeUndefined)(data)
|
|
1659
1659
|
}).then(() => user);
|
|
1660
1660
|
}, [usersPath, dataSourceDelegate?.initialised]);
|
|
@@ -1663,10 +1663,10 @@
|
|
|
1663
1663
|
if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
|
|
1664
1664
|
console.debug("Persisting role", role);
|
|
1665
1665
|
const { id, ...roleData } = role;
|
|
1666
|
-
return dataSourceDelegate.
|
|
1666
|
+
return dataSourceDelegate.save({
|
|
1667
1667
|
status: "existing",
|
|
1668
1668
|
path: rolesPath,
|
|
1669
|
-
|
|
1669
|
+
id,
|
|
1670
1670
|
values: (0, _rebasepro_utils.removeUndefined)(roleData)
|
|
1671
1671
|
}).then(() => {});
|
|
1672
1672
|
}, [rolesPath, dataSourceDelegate?.initialised]);
|
|
@@ -1675,24 +1675,24 @@
|
|
|
1675
1675
|
if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
|
|
1676
1676
|
console.debug("Deleting", user);
|
|
1677
1677
|
const { uid } = user;
|
|
1678
|
-
const
|
|
1678
|
+
const row = {
|
|
1679
1679
|
path: usersPath,
|
|
1680
1680
|
id: uid,
|
|
1681
1681
|
values: {}
|
|
1682
1682
|
};
|
|
1683
|
-
await dataSourceDelegate.
|
|
1683
|
+
await dataSourceDelegate.delete({ row });
|
|
1684
1684
|
}, [usersPath, dataSourceDelegate?.initialised]);
|
|
1685
1685
|
const deleteRole = (0, react.useCallback)(async (role) => {
|
|
1686
1686
|
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
|
1687
1687
|
if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
|
|
1688
1688
|
console.debug("Deleting", role);
|
|
1689
1689
|
const { id } = role;
|
|
1690
|
-
const
|
|
1690
|
+
const row = {
|
|
1691
1691
|
path: rolesPath,
|
|
1692
1692
|
id,
|
|
1693
1693
|
values: {}
|
|
1694
1694
|
};
|
|
1695
|
-
await dataSourceDelegate.
|
|
1695
|
+
await dataSourceDelegate.delete({ row });
|
|
1696
1696
|
}, [rolesPath, dataSourceDelegate?.initialised]);
|
|
1697
1697
|
const defineRolesFor = (0, react.useCallback)((user) => {
|
|
1698
1698
|
if (!usersWithRoleIds) throw Error("Users not loaded");
|
|
@@ -1768,22 +1768,21 @@
|
|
|
1768
1768
|
} : null
|
|
1769
1769
|
};
|
|
1770
1770
|
}
|
|
1771
|
-
var
|
|
1772
|
-
return
|
|
1773
|
-
const data =
|
|
1774
|
-
const record = data;
|
|
1771
|
+
var rowsToUsers = (rows) => {
|
|
1772
|
+
return rows.map((row) => {
|
|
1773
|
+
const { id, ...data } = row;
|
|
1775
1774
|
return {
|
|
1776
1775
|
...data,
|
|
1777
|
-
uid:
|
|
1778
|
-
created_on:
|
|
1779
|
-
updated_on:
|
|
1776
|
+
uid: id,
|
|
1777
|
+
created_on: data.created_on,
|
|
1778
|
+
updated_on: data.updated_on
|
|
1780
1779
|
};
|
|
1781
1780
|
});
|
|
1782
1781
|
};
|
|
1783
|
-
var
|
|
1784
|
-
return
|
|
1785
|
-
|
|
1786
|
-
|
|
1782
|
+
var rowsToRoles = (rows) => {
|
|
1783
|
+
return rows.map((row) => ({
|
|
1784
|
+
...row,
|
|
1785
|
+
id: row.id
|
|
1787
1786
|
}));
|
|
1788
1787
|
};
|
|
1789
1788
|
//#endregion
|
|
@@ -2611,7 +2610,12 @@
|
|
|
2611
2610
|
authController,
|
|
2612
2611
|
userConfigPersistence,
|
|
2613
2612
|
dateTimeFormat,
|
|
2614
|
-
|
|
2613
|
+
dataSources: [{
|
|
2614
|
+
key: _rebasepro_types.DEFAULT_DATA_SOURCE_KEY,
|
|
2615
|
+
engine: "firestore",
|
|
2616
|
+
transport: "direct",
|
|
2617
|
+
driver: firestoreDelegate
|
|
2618
|
+
}],
|
|
2615
2619
|
storageSource,
|
|
2616
2620
|
entityLinkBuilder: ({ entity }) => `https://console.firebase.google.com/project/${firebaseApp.options.projectId}/firestore/data/${entity.path}/${entity.id}`,
|
|
2617
2621
|
locale,
|
|
@@ -2637,7 +2641,7 @@
|
|
|
2637
2641
|
to: urlController.buildUrlCollectionPath(firstCollectionEntry.id),
|
|
2638
2642
|
replace: true
|
|
2639
2643
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_rebasepro_ui.CenteredView, { children: "No home page or collections provided." });
|
|
2640
|
-
component = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_rebasepro_admin.
|
|
2644
|
+
component = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_rebasepro_admin.SidePanelProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_rebasepro_core.RebaseRoutes, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_router_dom.Route, {
|
|
2641
2645
|
element: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_rebasepro_admin.Scaffold, {
|
|
2642
2646
|
logo: usedLogo,
|
|
2643
2647
|
autoOpenDrawer,
|