@rebasepro/firebase 0.29.1 → 0.29.3

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/index.es.js CHANGED
@@ -1432,7 +1432,8 @@ function firestoreToRebaseModel(data) {
1432
1432
  };
1433
1433
  if (data instanceof GeoPoint$1) return new GeoPoint(data.latitude, data.longitude);
1434
1434
  if (data instanceof DocumentReference) {
1435
- const databaseId = (data?.firestore)?._databaseId?.database;
1435
+ const internalId = Reflect.get(data.firestore, "_databaseId");
1436
+ const databaseId = typeof internalId === "object" && internalId !== null && "database" in internalId && typeof internalId.database === "string" ? internalId.database : void 0;
1436
1437
  return new EntityReference({
1437
1438
  id: data.id,
1438
1439
  path: getCMSPathFromFirestorePath(data.path),
@@ -1680,6 +1681,12 @@ function delegateToCMSModel(data) {
1680
1681
  if (data === null || data === void 0) return null;
1681
1682
  if (Array.isArray(data)) return data.map(delegateToCMSModel).filter((v) => v !== void 0);
1682
1683
  if (typeof data === "object") {
1684
+ if (isStoredReference(data)) return new EntityReference({
1685
+ id: data.id,
1686
+ path: data.path,
1687
+ ...typeof data.driver === "string" ? { driver: data.driver } : {},
1688
+ ...typeof data.databaseId === "string" ? { databaseId: data.databaseId } : {}
1689
+ });
1683
1690
  const result = {};
1684
1691
  for (const key of Object.keys(data)) {
1685
1692
  const childValue = delegateToCMSModel(data[key]);
@@ -1693,14 +1700,26 @@ function delegateToCMSModel(data) {
1693
1700
  * Transform data from CMS format to RTDB format
1694
1701
  * This is used internally when saving data
1695
1702
  */
1703
+ /** A reference as {@link cmsToRTDBModel} stores it. */
1704
+ function isStoredReference(data) {
1705
+ return "__type" in data && data.__type === "reference" && "id" in data && typeof data.id === "string" && "path" in data && typeof data.path === "string";
1706
+ }
1707
+ /** An `EntityReference`, recognised by its method so a second copy of the class still counts. */
1708
+ function isEntityReferenceLike(data) {
1709
+ return typeof data === "object" && data !== null && "isEntityReference" in data && typeof data.isEntityReference === "function" && data.isEntityReference() === true;
1710
+ }
1696
1711
  function cmsToRTDBModel(data, database) {
1697
1712
  if (data === void 0) return null;
1698
1713
  else if (data === null) return null;
1699
1714
  else if (Array.isArray(data)) return data.filter((v) => v !== void 0).map((v) => cmsToRTDBModel(v, database));
1700
- else if (typeof data === "object" && data !== null && "isEntityReference" in data && typeof data.isEntityReference === "function" && data.isEntityReference()) {
1701
- const entityRef = data;
1702
- return ref$1(database, `${entityRef.slug}/${entityRef.id}`);
1703
- } else if (data instanceof Date) return data.toISOString();
1715
+ else if (isEntityReferenceLike(data)) return {
1716
+ __type: "reference",
1717
+ id: data.id,
1718
+ path: data.path,
1719
+ ...data.driver !== void 0 ? { driver: data.driver } : {},
1720
+ ...data.databaseId !== void 0 ? { databaseId: data.databaseId } : {}
1721
+ };
1722
+ else if (data instanceof Date) return data.toISOString();
1704
1723
  else if (data && typeof data === "object") return cmsToRTDBRecord(data, database);
1705
1724
  return data;
1706
1725
  }