@rebasepro/client-firebase 0.7.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.
@@ -1,6 +1,6 @@
1
1
  import { User as FirebaseUser } from "@firebase/auth";
2
2
  import { FirebaseApp } from "@firebase/app";
3
- import { EntityCollection } from "@rebasepro/types";
3
+ import { CollectionConfig } from "@rebasepro/types";
4
4
 
5
5
  export type FirestoreTextSearchControllerBuilder = (props: {
6
6
  firebaseApp: FirebaseApp;
@@ -25,7 +25,7 @@ export type FirestoreTextSearchController = {
25
25
  init: (props: {
26
26
  path: string,
27
27
  databaseId?: string,
28
- collection?: EntityCollection
28
+ collection?: CollectionConfig
29
29
  }) => Promise<boolean>,
30
30
  /**
31
31
  * Do the search and return a list of ids.
@@ -36,7 +36,7 @@ export type FirestoreTextSearchController = {
36
36
  path: string,
37
37
  currentUser?: FirebaseUser,
38
38
  databaseId?: string,
39
- collection?: EntityCollection
39
+ collection?: CollectionConfig
40
40
  }) => (Promise<readonly string[] | undefined>),
41
41
 
42
42
  };
@@ -1,5 +1,5 @@
1
1
  import { deleteField, DocumentSnapshot } from "@firebase/firestore";
2
- import { EntityCollection, FirebaseCollection, Properties, Property } from "@rebasepro/types";
2
+ import { CollectionConfig, FirebaseCollectionConfig, Properties, Property } from "@rebasepro/types";
3
3
  import { COLLECTION_PATH_SEPARATOR, sortProperties, stripCollectionPath } from "@rebasepro/common";
4
4
 
5
5
  export function buildCollectionId(idOrPath: string, parentCollectionSlugs?: string[], parentEntityIds?: string[]): string {
@@ -9,7 +9,7 @@ export function buildCollectionId(idOrPath: string, parentCollectionSlugs?: stri
9
9
  }
10
10
 
11
11
 
12
- export const docsToCollectionTree = (docs: DocumentSnapshot[]): EntityCollection[] => {
12
+ export const docsToCollectionTree = (docs: DocumentSnapshot[]): CollectionConfig[] => {
13
13
 
14
14
  const collectionsMap = docs.map((doc) => {
15
15
  const id: string = doc.id;
@@ -26,7 +26,7 @@ export const docsToCollectionTree = (docs: DocumentSnapshot[]): EntityCollection
26
26
  const parentId = id.split(COLLECTION_PATH_SEPARATOR).slice(0, -1).join(COLLECTION_PATH_SEPARATOR);
27
27
  const parentCollection = collectionsMap[parentId];
28
28
  if (parentCollection)
29
- (parentCollection as FirebaseCollection).subcollections = () => [...((parentCollection as FirebaseCollection).subcollections?.() ?? []), collection];
29
+ (parentCollection as FirebaseCollectionConfig).subcollections = () => [...((parentCollection as FirebaseCollectionConfig).subcollections?.() ?? []), collection];
30
30
  delete collectionsMap[id];
31
31
  }
32
32
  });
@@ -34,7 +34,7 @@ export const docsToCollectionTree = (docs: DocumentSnapshot[]): EntityCollection
34
34
  return Object.values(collectionsMap);
35
35
  }
36
36
 
37
- export const docToCollection = (doc: DocumentSnapshot): EntityCollection => {
37
+ export const docToCollection = (doc: DocumentSnapshot): CollectionConfig => {
38
38
  const data = doc.data();
39
39
  if (!data)
40
40
  throw Error("Entity collection has not been persisted correctly");
@@ -48,7 +48,7 @@ export const docToCollection = (doc: DocumentSnapshot): EntityCollection => {
48
48
  ...data,
49
49
  properties: sortedProperties,
50
50
  slug: data.id ?? data.alias ?? data.slug
51
- } as EntityCollection;
51
+ } as CollectionConfig;
52
52
  }
53
53
 
54
54
 
@@ -12,8 +12,8 @@ export async function getFirestoreDataInPath(firebaseApp: FirebaseApp, path: str
12
12
  const firestore = getFirestore(firebaseApp);
13
13
  if (!parentPaths || parentPaths.length === 0) {
14
14
  const q = query(collection(firestore, path), limitClause(limit));
15
- return getDocs(q).then((querySnapshot) => {
16
- return querySnapshot.docs.map(doc => doc.data());
15
+ return getDocs(q).then((queryEntity) => {
16
+ return queryEntity.docs.map(doc => doc.data());
17
17
  });
18
18
  } else {
19
19
  let currentDocs: QueryDocumentSnapshot[] | undefined = undefined;
@@ -2,7 +2,7 @@ import { collection, getFirestore, onSnapshot, query } from "@firebase/firestore
2
2
  import Fuse from "fuse.js"
3
3
 
4
4
  import { FirebaseApp } from "@firebase/app";
5
- import { EntityCollection } from "@rebasepro/types";
5
+ import { CollectionConfig } from "@rebasepro/types";
6
6
  import { FirestoreTextSearchController, FirestoreTextSearchControllerBuilder } from "../types";
7
7
 
8
8
  const MAX_SEARCH_RESULTS = 80;
@@ -32,7 +32,7 @@ export const localSearchControllerBuilder: FirestoreTextSearchControllerBuilder
32
32
  databaseId
33
33
  }: {
34
34
  path: string,
35
- collection?: EntityCollection,
35
+ collection?: CollectionConfig,
36
36
  databaseId?: string
37
37
  }): Promise<boolean> => {
38
38
 
@@ -49,11 +49,11 @@ export const localSearchControllerBuilder: FirestoreTextSearchControllerBuilder
49
49
  const col = collection(firestore, path);
50
50
  listeners[path] = onSnapshot(query(col),
51
51
  {
52
- next: (snapshot) => {
53
- if (snapshot.metadata.fromCache && snapshot.metadata.hasPendingWrites) {
52
+ next: (entity) => {
53
+ if (entity.metadata.fromCache && entity.metadata.hasPendingWrites) {
54
54
  return;
55
55
  }
56
- const docs = snapshot.docs.map(doc => ({
56
+ const docs = entity.docs.map(doc => ({
57
57
  id: doc.id,
58
58
  ...doc.data()
59
59
  }));
@@ -112,7 +112,7 @@ export const localSearchControllerBuilder: FirestoreTextSearchControllerBuilder
112
112
  }
113
113
  }
114
114
 
115
- function buildIndex(list: (object & { id: string })[], collection: EntityCollection) {
115
+ function buildIndex(list: (object & { id: string })[], collection: CollectionConfig) {
116
116
 
117
117
  const keys = ["id", ...Object.keys(collection.properties)];
118
118
 
@@ -1,6 +1,6 @@
1
1
  import { User as FirebaseUser } from "@firebase/auth";
2
2
  import { FirestoreTextSearchController, FirestoreTextSearchControllerBuilder } from "../types";
3
- import { EntityCollection } from "@rebasepro/types";
3
+ import { CollectionConfig } from "@rebasepro/types";
4
4
 
5
5
  const DEFAULT_SERVER = "https://api.rebase.pro";
6
6
 
@@ -60,7 +60,7 @@ export function buildPineconeSearchController({
60
60
 
61
61
  const init = (props: {
62
62
  path: string,
63
- collection?: EntityCollection
63
+ collection?: CollectionConfig
64
64
  }) => {
65
65
  // do nothing
66
66
  return Promise.resolve(isPathSupported(props.path));
@@ -1,7 +1,7 @@
1
1
  import { FirestoreTextSearchController, FirestoreTextSearchControllerBuilder } from "../types";
2
2
  import { FirebaseApp } from "@firebase/app";
3
3
  import { getFunctions, httpsCallable } from "@firebase/functions";
4
- import { EntityCollection } from "@rebasepro/types";
4
+ import { CollectionConfig } from "@rebasepro/types";
5
5
 
6
6
  /**
7
7
  * Configuration returned by the Rebase Search Extension
@@ -204,7 +204,7 @@ export function buildRebaseSearchController(
204
204
  */
205
205
  const init = async (props: {
206
206
  path: string;
207
- collection?: EntityCollection;
207
+ collection?: CollectionConfig;
208
208
  databaseId?: string;
209
209
  }): Promise<boolean> => {
210
210
  try {
@@ -289,7 +289,7 @@ export function buildRebaseSearchController(
289
289
  searchString: string;
290
290
  path: string;
291
291
  databaseId?: string;
292
- collection?: EntityCollection;
292
+ collection?: CollectionConfig;
293
293
  }): Promise<readonly string[] | undefined> => {
294
294
  if (!typesenseClient) {
295
295
  // Ensure client is initialized
@@ -1,5 +1,5 @@
1
1
  import { FirestoreTextSearchController, FirestoreTextSearchControllerBuilder } from "../types";
2
- import { EntityCollection } from "@rebasepro/types";
2
+ import { CollectionConfig } from "@rebasepro/types";
3
3
 
4
4
  /**
5
5
  * Utility function to perform a text search in an external index,
@@ -20,7 +20,7 @@ export function buildExternalSearchController({
20
20
 
21
21
  const init = (props: {
22
22
  path: string,
23
- collection?: EntityCollection
23
+ collection?: CollectionConfig
24
24
  }) => {
25
25
  return Promise.resolve(isPathSupported(props.path));
26
26
  }