15.17.15 • Published 4 months ago

@getcircuit/firestore-utils v15.17.15

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

@getcircuit/firestore-utils

A collection of utilities to work with Circuit's Firestore. This package is intended to be used by both client and server Firebase instances.

Utilities

isFirestoreError(error?: unknown, code?: FirebaseErrorCode): boolean

Checks if the given error is a Firestore error with the given code. If the code is not provided, it will check if the error is a Firestore error.

isModelDocumentRef(modelName: string, ref: DocumentReference): boolean

Checks if the given reference is a reference to a document of the given model and asserts the reference type.

function myFunction(rootRef: DocumentReference<Team | User>) {
  if (isModelDocumentRef('Team', rootRef)) {
    // rootRef is a DocumentReference<Team>
  } else if (isModelDocumentRef('User', rootRef)) {
    // rootRef is a DocumentReference<User>
  }
}

isModelCollectionRef(modelName: string, ref: CollectionReference): boolean

Checks if the given reference is a reference to a collection of the given model and asserts the reference type.

function myFunction(rootRef: CollectionReference<Team | User>) {
  if (isModelCollectionRef('Team', rootRef)) {
    // rootRef is a CollectionReference<Team>
  } else if (isModelCollectionRef('User', rootRef)) {
    // rootRef is a CollectionReference<User>
  }
}

isEqualDocumentData<Data>(data1: Data, data2: Data): boolean

Compare two document data objects and return true if they are equivalent.

  • Firestore refs are compared by their path.
  • Dates are compared by their timestamp.
  • Objects are shallowly compared.
  • Arrays and deep nested objects are compared deeply.

getQueryId(query: Query): string

Returns a unique ID for the given query. This is useful to uniquely identify a query, as in a cache.

Note: mostly used internally by our custom query snapshot watcher in Snappy.

normalizeRefPath(path: string): string

Normalizes a string Firestore path by removing leading and trailing slashes.

normalizeRefPath('/users/123/') // 'users/123'

getRefId(ref: DocumentReference | CollectionReference | string): string

Returns the ID of the given reference. If the reference is a string, it is assumed to be a Firestore path and the ID is extracted from the last segment of the path.

getRefId(userRef) // '123'
getRefId('users/123') // '123'

getRefPath(ref: DocumentReference | CollectionReference | string): string

Returns the path of the given reference. If the reference is a string path, it is assumed to be a Firestore path and the path is normalized via normalizeRefPath.

getRefPath(userRef) // 'users/123'
getRefPath('users/123') // 'users/123'

isSameRef(ref1: DocumentReference | CollectionReference | string, ref2: DocumentReference | CollectionReference | string): boolean

Checks if two references are the same by comparing their path. If the references are string paths, they are assumed to be Firestore paths and are normalized via normalizeRefPath.

const userRef = doc(firestore, 'users/123')
isSameRef(userRef, 'users/123') // true
isSameRef(userRef, 'users/456') // false

isFirestoreRef(ref: unknown): boolean

Type guard to check if the given reference is a Firestore reference. It doesn't use instance checks, but rather checks if the reference has the expected properties of a Firestore reference: firestore, id and path.

15.17.15

4 months ago

15.17.14

4 months ago

15.17.13

4 months ago

15.17.12

4 months ago

15.17.11

4 months ago

15.17.10

4 months ago

15.17.9

4 months ago

15.17.8

4 months ago

15.17.7

4 months ago

15.17.6

4 months ago

15.17.5

4 months ago

15.17.4

4 months ago

15.17.3

4 months ago

15.17.2

4 months ago

15.17.1

4 months ago

15.18.0-leo.0

4 months ago

15.17.0

4 months ago

15.16.2-leo.0

4 months ago

15.16.1

4 months ago

15.16.0

4 months ago

15.15.2

4 months ago

15.15.1

4 months ago

15.15.0

4 months ago

15.14.0

4 months ago

15.13.6

4 months ago

15.13.5

4 months ago

15.13.4

4 months ago

15.13.3

5 months ago

15.13.2

5 months ago

15.13.1

5 months ago

15.13.0

5 months ago

15.12.12

5 months ago

15.12.11

5 months ago

15.12.10

5 months ago

15.12.6

5 months ago

15.12.5

5 months ago

15.12.2

5 months ago

15.12.1

5 months ago

15.12.0

5 months ago

15.11.4-potato.0

5 months ago

15.12.0-slct.0

5 months ago

15.10.2

5 months ago

15.11.0-leo.0

5 months ago

15.8.2

5 months ago

15.8.1

5 months ago

15.9.0-sd.0

5 months ago

15.7.0-select.0

5 months ago

15.6.12

5 months ago

15.6.11

5 months ago

15.6.9-potato.1

5 months ago

15.6.9-potato.0

5 months ago

15.7.0-pow.0

5 months ago

15.6.8-potato.0

5 months ago

15.6.8-intl.0

5 months ago

15.6.8-pow.0

5 months ago

15.6.7

5 months ago

15.6.6

5 months ago

15.6.5-pow.0

5 months ago

15.6.3

5 months ago

15.6.2-pow.0

5 months ago

15.6.1

5 months ago

15.6.0

5 months ago

15.6.0-pow.0

6 months ago

15.4.0

6 months ago

15.1.1

6 months ago

15.2.0-pow.0

6 months ago

15.0.2

6 months ago

15.1.0-dws.0

6 months ago

15.0.0

6 months ago

14.67.6

7 months ago

14.67.5

7 months ago

14.67.1

7 months ago

14.66.0

7 months ago

14.65.3

7 months ago

14.64.1

7 months ago

14.62.8

7 months ago

14.62.0

8 months ago

14.60.0-ttp.0

8 months ago

14.59.1

8 months ago

14.60.0-pow.0

8 months ago

14.57.8

8 months ago

14.57.4

8 months ago

14.57.3

8 months ago

14.57.2

8 months ago

14.55.0

8 months ago

14.54.3

8 months ago

14.54.2

8 months ago

14.52.3

8 months ago

14.49.0-zoning.0

8 months ago

14.45.3

8 months ago

14.45.1-pow.0

8 months ago

14.45.0

8 months ago

14.44.0

9 months ago

14.42.1

9 months ago

14.39.8

9 months ago

14.39.3

9 months ago

14.39.2-potato.0

9 months ago

14.39.2

9 months ago

14.39.0-potato.0

9 months ago

14.39.0

9 months ago

14.36.0-alpha.0

9 months ago

14.35.0

9 months ago

14.34.2

9 months ago

14.33.1

9 months ago

14.32.0

9 months ago

14.31.0

9 months ago

14.30.0

9 months ago

14.29.0-potato.0

9 months ago

14.29.0

9 months ago

14.27.2

9 months ago

14.27.1

9 months ago

14.26.2

9 months ago

14.26.1

9 months ago

14.26.0

9 months ago

14.25.0

10 months ago

14.23.0

10 months ago

14.21.0-tll.0

10 months ago

14.20.0

10 months ago

14.19.0-react18.0

10 months ago

14.18.0-react18.0

10 months ago

14.13.0-pow.0

11 months ago

14.12.0-yam.0

11 months ago

14.11.0

11 months ago

14.5.0

11 months ago

14.4.0-alpha.0

11 months ago

14.3.0-alpha.7

11 months ago

14.3.0-alpha.6

11 months ago

14.2.6-pow.0

11 months ago

14.3.0-yam.1.0

11 months ago

14.2.4

11 months ago

14.3.0-read-only.0

11 months ago

14.2.0

12 months ago

14.0.1

12 months ago

14.0.0

12 months ago

13.13.1

12 months ago

13.14.0-pow.0

12 months ago

13.5.0-yam.1.0

1 year ago

13.5.0-yam.0

1 year ago

13.4.0

1 year ago

13.4.0-yam.0

1 year ago

13.3.0

1 year ago

13.0.0

1 year ago

12.18.0-pow.0

1 year ago

12.17.4

1 year ago

12.17.0

1 year ago

12.16.2

1 year ago

12.17.0-pow.0

1 year ago

12.15.0-yam.1

1 year ago

12.15.0-yam.0

1 year ago

12.15.0-pow.0

1 year ago

12.12.0-leo.0

1 year ago

12.12.0-pim.0

1 year ago

12.7.0-yam.1

1 year ago

12.9.0-rows.0

1 year ago

12.7.0-yam.0

1 year ago

12.7.0-rows.0

1 year ago

12.5.0-rows.0

1 year ago

12.5.0-row.0

1 year ago

12.4.0-row.0

1 year ago

12.3.0

1 year ago

12.3.0-clx.0

1 year ago

12.2.10

1 year ago

12.2.9

1 year ago

12.2.8

1 year ago

12.3.0-cll.0

1 year ago

12.2.7

1 year ago

12.3.0-ico.0

1 year ago

12.2.5

1 year ago

12.2.5-kiwi.0

1 year ago

12.3.0-cells.0

1 year ago

12.3.0-cell.0

1 year ago

12.2.0

1 year ago

12.1.0-cell.0

1 year ago

12.0.0

1 year ago

11.0.0

1 year ago

10.2.0

1 year ago

10.2.0-kiwi.0

1 year ago

10.0.0

1 year ago

9.0.1-kiwi.1

1 year ago

9.0.1-kiwi.0

1 year ago

9.1.0-badge.0

1 year ago

9.0.0

1 year ago

8.2.0-input.0

1 year ago

8.2.0-yam.0

1 year ago

8.1.0-yam.0

1 year ago

8.0.0

1 year ago

7.2.0

1 year ago

8.0.0-kiwi.0

1 year ago

7.2.0-yam.0

1 year ago

7.1.0-alpha.0

1 year ago

7.1.0-gamma.0

1 year ago

7.1.0-inputs.0

1 year ago

8.0.0-input.0

1 year ago

7.0.0

1 year ago

7.0.0-kiwi.6

1 year ago

6.3.0-input.0

1 year ago

6.0.1

1 year ago

6.0.0

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.3-input.0

1 year ago

0.4.2

1 year ago

0.4.1-input.0

1 year ago

0.4.1-yam.8.6.0

1 year ago

0.4.1-yam.8.5.0

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.2-yam.7.7.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.0-patcher.0

1 year ago

0.1.1-patcher.1

1 year ago

0.1.1-patcher.0

1 year ago

0.0.2-patcher.0

1 year ago

0.1.0

1 year ago