@adplorg/capacitor-firebase-firestore
v0.0.11
Published
Capacitor plugin for firebase firestore.
Readme
@adplorg/capacitor-firebase-firestore
Capacitor plugin for firebase firestore.
Install
npm install @adplorg/capacitor-firebase-firestore
npx cap syncAPI
collection(...)collectionGroup(...)query(...)where(...)orderBy(...)limit(...)startAt(...)endAt(...)startAfter(...)endBefore(...)doc(...)add(...)set(...)update(...)delete(...)getDocs(...)getDoc(...)valueChanges(...)snapshotChanges(...)docData(...)collectionData(...)batch()batchSet(...)batchUpdate(...)batchDelete(...)batchCommit()- Interfaces
- Type Aliases
collection(...)
collection<T = DocumentData>(path: string) => Promise<CollectionReference<T>>| Param | Type |
| ---------- | ------------------- |
| path | string |
Returns: Promise<CollectionReference<T, DocumentData>>
collectionGroup(...)
collectionGroup<T = DocumentData>(collectionId: string) => Promise<CollectionReference<T>>| Param | Type |
| ------------------ | ------------------- |
| collectionId | string |
Returns: Promise<CollectionReference<T, DocumentData>>
query(...)
query<T = DocumentData>(ref: CollectionReference<T>, constraints: QueryConstraints) => Promise<CollectionReference<T>>| Param | Type |
| ----------------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
| constraints | QueryConstraints |
Returns: Promise<CollectionReference<T, DocumentData>>
where(...)
where<T = DocumentData>(ref: CollectionReference<T>, field: string, opStr: WhereFilterOp, value: any) => Promise<CollectionReference<T>>| Param | Type |
| ----------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
| field | string |
| opStr | WhereFilterOp |
| value | any |
Returns: Promise<CollectionReference<T, DocumentData>>
orderBy(...)
orderBy<T = DocumentData>(ref: CollectionReference<T>, field: string, direction?: "asc" | "desc" | undefined) => Promise<CollectionReference<T>>| Param | Type |
| --------------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
| field | string |
| direction | 'asc' | 'desc' |
Returns: Promise<CollectionReference<T, DocumentData>>
limit(...)
limit<T = DocumentData>(ref: CollectionReference<T>, limit: number) => Promise<CollectionReference<T>>| Param | Type |
| ----------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
| limit | number |
Returns: Promise<CollectionReference<T, DocumentData>>
startAt(...)
startAt<T = DocumentData>(ref: CollectionReference<T>, ...fieldValues: any[]) => Promise<CollectionReference<T>>| Param | Type |
| ----------------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
| fieldValues | any[] |
Returns: Promise<CollectionReference<T, DocumentData>>
endAt(...)
endAt<T = DocumentData>(ref: CollectionReference<T>, ...fieldValues: any[]) => Promise<CollectionReference<T>>| Param | Type |
| ----------------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
| fieldValues | any[] |
Returns: Promise<CollectionReference<T, DocumentData>>
startAfter(...)
startAfter<T = DocumentData>(ref: CollectionReference<T>, ...fieldValues: any[]) => Promise<CollectionReference<T>>| Param | Type |
| ----------------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
| fieldValues | any[] |
Returns: Promise<CollectionReference<T, DocumentData>>
endBefore(...)
endBefore<T = DocumentData>(ref: CollectionReference<T>, ...fieldValues: any[]) => Promise<CollectionReference<T>>| Param | Type |
| ----------------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
| fieldValues | any[] |
Returns: Promise<CollectionReference<T, DocumentData>>
doc(...)
doc<T = DocumentData>(path: string) => Promise<FirebaseDocumentReference<T>>| Param | Type |
| ---------- | ------------------- |
| path | string |
Returns: Promise<DocumentReference<T, DocumentData>>
add(...)
add<T = DocumentData>(ref: CollectionReference<T>, data: T) => Promise<DocumentReference>| Param | Type |
| ---------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
| data | T |
Returns: Promise<DocumentReference>
set(...)
set<T = DocumentData>(ref: FirebaseDocumentReference<T>, data: T, options?: SetOptions | undefined) => Promise<void>| Param | Type |
| ------------- | ------------------------------------------------------------------------------------------------------------------ |
| ref | DocumentReference<T, DocumentData> |
| data | T |
| options | SetOptions |
update(...)
update<T = DocumentData>(ref: FirebaseDocumentReference<T>, data: UpdateData<T>) => Promise<void>| Param | Type |
| ---------- | ------------------------------------------------------------------------------------------------------------------ |
| ref | DocumentReference<T, DocumentData> |
| data | UpdateData<T> |
delete(...)
delete(ref: FirebaseDocumentReference) => Promise<void>| Param | Type |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ref | DocumentReference<DocumentData, DocumentData> |
getDocs(...)
getDocs<T = DocumentData>(ref: CollectionReference<T>) => Promise<QuerySnapshot<T>>| Param | Type |
| --------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
Returns: Promise<QuerySnapshot<T>>
getDoc(...)
getDoc<T = DocumentData>(ref: FirebaseDocumentReference<T>) => Promise<DocumentSnapshot<T>>| Param | Type |
| --------- | ------------------------------------------------------------------------------------------------------------------ |
| ref | DocumentReference<T, DocumentData> |
Returns: Promise<DocumentSnapshot<T>>
valueChanges(...)
valueChanges<T = DocumentData>(ref: CollectionReference<T>) => Observable<T[]>| Param | Type |
| --------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
Returns: Observable<T[]>
snapshotChanges(...)
snapshotChanges<T = DocumentData>(ref: CollectionReference<T>) => Observable<QuerySnapshot<T>>| Param | Type |
| --------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
Returns: Observable<QuerySnapshot<T>>
docData(...)
docData<T = DocumentData>(ref: FirebaseDocumentReference<T>) => Observable<T | undefined>| Param | Type |
| --------- | ------------------------------------------------------------------------------------------------------------------ |
| ref | DocumentReference<T, DocumentData> |
Returns: Observable<T>
collectionData(...)
collectionData<T = DocumentData>(ref: CollectionReference<T>) => Observable<T[]>| Param | Type |
| --------- | ----------------------------------------------------------------------------------- |
| ref | CollectionReference<T, DocumentData> |
Returns: Observable<T[]>
batch()
batch() => Promise<void>batchSet(...)
batchSet<T = DocumentData>(ref: FirebaseDocumentReference<T>, data: T) => Promise<void>| Param | Type |
| ---------- | ------------------------------------------------------------------------------------------------------------------ |
| ref | DocumentReference<T, DocumentData> |
| data | T |
batchUpdate(...)
batchUpdate<T = DocumentData>(ref: FirebaseDocumentReference<T>, data: UpdateData<T>) => Promise<void>| Param | Type |
| ---------- | ------------------------------------------------------------------------------------------------------------------ |
| ref | DocumentReference<T, DocumentData> |
| data | UpdateData<T> |
batchDelete(...)
batchDelete(ref: FirebaseDocumentReference) => Promise<void>| Param | Type |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ref | DocumentReference<DocumentData, DocumentData> |
batchCommit()
batchCommit() => Promise<void>Interfaces
DocumentData
Document data (for use with {@link @firebase/firestore/lite#(setDoc:1)}) consists of fields mapped to values.
QueryConstraints
| Prop | Type |
| ---------------- | ---------------------------------------------------------------------- |
| where | [string, WhereFilterOp, any] |
| orderBy | [string, string] |
| limit | number |
| startAt | any |
| endAt | any |
| startAfter | any |
| endBefore | any |
DocumentReference
| Prop | Type |
| ---------- | ------------------- |
| id | string |
| path | string |
Array
| Prop | Type | Description |
| ------------ | ------------------- | ------------------------------------------------------------------------------------------------------ |
| length | number | Gets or sets the length of the array. This is a number one higher than the highest index in the array. |
| Method | Signature | Description | | ------------------ | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | toString | () => string | Returns a string representation of an array. | | toLocaleString | () => string | Returns a string representation of an array. The elements are converted to string using their toLocalString methods. | | pop | () => T | undefined | Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. | | push | (...items: T[]) => number | Appends new elements to the end of an array, and returns the new length of the array. | | concat | (...items: ConcatArray<T>[]) => T[] | Combines two or more arrays. This method returns a new array without modifying any existing arrays. | | concat | (...items: (T | ConcatArray<T>)[]) => T[] | Combines two or more arrays. This method returns a new array without modifying any existing arrays. | | join | (separator?: string | undefined) => string | Adds all the elements of an array into a string, separated by the specified separator string. | | reverse | () => T[] | Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array. | | shift | () => T | undefined | Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. | | slice | (start?: number | undefined, end?: number | undefined) => T[] | Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array. | | sort | (compareFn?: ((a: T, b: T) => number) | undefined) => this | Sorts an array in place. This method mutates the array and returns a reference to the same array. | | splice | (start: number, deleteCount?: number | undefined) => T[] | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. | | splice | (start: number, deleteCount: number, ...items: T[]) => T[] | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. | | unshift | (...items: T[]) => number | Inserts new elements at the start of an array, and returns the new length of the array. | | indexOf | (searchElement: T, fromIndex?: number | undefined) => number | Returns the index of the first occurrence of a value in an array, or -1 if it is not present. | | lastIndexOf | (searchElement: T, fromIndex?: number | undefined) => number | Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present. | | every | <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any) => this is S[] | Determines whether all the members of an array satisfy the specified test. | | every | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => boolean | Determines whether all the members of an array satisfy the specified test. | | some | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => boolean | Determines whether the specified callback function returns true for any element of an array. | | forEach | (callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any) => void | Performs the specified action for each element in an array. | | map | <U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any) => U[] | Calls a defined callback function on each element of an array, and returns an array that contains the results. | | filter | <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any) => S[] | Returns the elements of an array that meet the condition specified in a callback function. | | filter | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => T[] | Returns the elements of an array that meet the condition specified in a callback function. | | reduce | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T) => T | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. | | reduce | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T) => T | | | reduce | <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U) => U | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. | | reduceRight | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T) => T | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. | | reduceRight | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T) => T | | | reduceRight | <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U) => U | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
ConcatArray
| Prop | Type |
| ------------ | ------------------- |
| length | number |
| Method | Signature | | --------- | ------------------------------------------------------------------ | | join | (separator?: string | undefined) => string | | slice | (start?: number | undefined, end?: number | undefined) => T[] |
QuerySnapshot
| Prop | Type |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| docs | Array<{ id: string; data: () => T; exists: boolean; ref: DocumentReference; }> |
| empty | boolean |
| size | number |
DocumentSnapshot
| Prop | Type |
| ------------ | --------------------------------------------------------------- |
| id | string |
| data | () => T |
| exists | boolean |
| ref | DocumentReference |
Observable
| Prop | Type |
| --------------- | -------------------------------------------------------- |
| subscribe | Subscribe<T> |
Subscribe
The Subscribe interface has two forms - passing the inline function callbacks, or a object interface with callback properties.
Type Aliases
WhereFilterOp
Filter conditions in a {@link where} clause are specified using the strings '<', '<=', '==', '!=', '>=', '>', 'array-contains', 'in', 'array-contains-any', and 'not-in'.
'<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in'
SetOptions
An options object that configures the behavior of {@link @firebase/firestore/lite#(setDoc:1)}, {@link
{ readonly merge?: boolean; } | { readonly mergeFields?: Array<string | FieldPath>; }
UpdateData
Update data (for use with {@link (updateDoc:1)}) that consists of field paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots reference nested fields within the document. FieldValues can be passed in as property values.
T extends Primitive ? T : T extends {} ? { [K in keyof T]?: UpdateData<T[K]> | FieldValue; } & NestedUpdateFields<T> : Partial<T>
Primitive
Primitive types.
string | number | boolean | | null
NestedUpdateFields
For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1, 'bar.qux': T2}). Intersect them together to make a single map containing all possible keys that are all marked as optional
UnionToIntersection<{ [K in keyof T & string]: ChildUpdateFields<K, T[K]>; }[keyof T & string]>
UnionToIntersection
Given a union type U = T1 | T2 | ..., returns an intersected type
(T1 & T2 & ...).
Uses distributive conditional types and inference from conditional types. This works because multiple candidates for the same type variable in contra-variant positions causes an intersection type to be inferred. https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
(U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never
ChildUpdateFields
Helper for calculating the nested fields for a given type T1. This is needed
to distribute union types such as undefined | {...} (happens for optional
props) or {a: A} | {b: B}.
In this use case, V is used to distribute the union types of T[K] on
Record, since T[K] is evaluated as an expression and not distributed.
See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
V extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<V>> : never
Record
Construct a type with a set of properties K of type T
{ [P in K]: T; }
AddPrefixToKeys
Returns a new map where every key is prefixed with the outer key appended to a dot.
{ [K in keyof T & string as ${Prefix}.${K}]+?: string extends K ? any : T[K]; }
Partial
Make all properties in T optional
{ [P in keyof T]?: T[P]; }
