unfire
Version:
⚡️ Utilities for Firebase 🔥 built with Composition API, Typescript and ❤️
68 lines (65 loc) • 4.31 kB
TypeScript
import * as _firebase_firestore from '@firebase/firestore';
import * as zod from 'zod';
import { ZodObject, ZodError } from 'zod';
import * as vue from 'vue';
import { Ref } from 'vue';
import { SnapshotListenOptions, PartialWithFieldValue } from 'firebase/firestore';
import { QueryOption, OnErrorFn, MapWhereQueriesArrayToRecord, ObjectToZodTypes } from '../firebase/firestore.js';
export { deleteDoc, upsertDoc, whereFilterOps } from '../firebase/firestore.js';
import { MaybeRef } from '../types.js';
import '@firebase/rules-unit-testing';
import '@unfire-init';
declare const createPathRef: <CollectionPath extends keyof FirestoreCollectionTypes>(path: CollectionPath) => Ref<vue.UnwrapRef<CollectionPath>>;
declare const toReactiveQueryOption: <CollectionPath extends keyof FirestoreCollectionTypes>(queryOption: QueryOption<CollectionPath>) => QueryOption<CollectionPath>;
declare const useCollection: <CollectionPath extends keyof FirestoreCollectionTypes, InferredQueryOption extends QueryOption<CollectionPath>>(options: {
collectionPath: MaybeRef<CollectionPath>;
resultsRef?: Ref<(FirestoreCollectionTypes[CollectionPath] & {
id: string;
})[]> | undefined;
onError?: OnErrorFn | undefined;
queryOption?: InferredQueryOption | undefined;
snapshotListenOptions?: SnapshotListenOptions | undefined;
optionsWatchDebounce?: MaybeRef<number> | undefined;
}) => {
results: Ref<(FirestoreCollectionTypes[CollectionPath] & {
id: string;
})[]>;
stop: () => void;
whereQueries: Ref<MapWhereQueriesArrayToRecord<InferredQueryOption extends {
whereQueries: (...arg: any[]) => infer T;
} ? T : never, CollectionPath>>;
orderByQuery: Ref<InferredQueryOption["orderByQuery"] | undefined>;
limitBy: Ref<number | undefined>;
};
declare const useDoc: <CollectionPath extends keyof FirestoreCollectionTypes>(options: {
collectionPath: MaybeRef<CollectionPath>;
docId: MaybeRef<string>;
onError?: OnErrorFn | undefined;
snapshotListenOptions?: SnapshotListenOptions | undefined;
optionsWatchDebounce?: MaybeRef<number> | undefined;
}) => {
result: Ref<(FirestoreCollectionTypes[CollectionPath] & {
id: string;
}) | undefined>;
stop: () => void;
};
declare const useDocBiDirection: <CollectionPath extends keyof FirestoreCollectionTypes>(options: {
collectionPath: MaybeRef<CollectionPath>;
docId: MaybeRef<string>;
onError?: OnErrorFn | undefined;
onUpdateSuccess?: ((updateData: PartialWithFieldValue<FirestoreCollectionTypes[CollectionPath]>) => void) | undefined;
snapshotListenOptions?: SnapshotListenOptions | undefined;
refWatchUpdateDebounce?: MaybeRef<number> | undefined;
optionsWatchDebounce?: MaybeRef<number> | undefined;
updateValidation?: MaybeRef<Boolean> | undefined;
updateCustomSchema?: ZodObject<ObjectToZodTypes<FirestoreCollectionTypes[CollectionPath]>, "strip", zod.ZodTypeAny, { [k_1 in keyof zod.objectUtil.addQuestionMarks<{ [k in keyof ObjectToZodTypes<FirestoreCollectionTypes[CollectionPath]>]: ObjectToZodTypes<FirestoreCollectionTypes[CollectionPath]>[k]["_output"]; }>]: zod.objectUtil.addQuestionMarks<{ [k in keyof ObjectToZodTypes<FirestoreCollectionTypes[CollectionPath]>]: ObjectToZodTypes<FirestoreCollectionTypes[CollectionPath]>[k]["_output"]; }>[k_1]; }, { [k_3 in keyof zod.objectUtil.addQuestionMarks<{ [k_2 in keyof ObjectToZodTypes<FirestoreCollectionTypes[CollectionPath]>]: ObjectToZodTypes<FirestoreCollectionTypes[CollectionPath]>[k_2]["_input"]; }>]: zod.objectUtil.addQuestionMarks<{ [k_2 in keyof ObjectToZodTypes<FirestoreCollectionTypes[CollectionPath]>]: ObjectToZodTypes<FirestoreCollectionTypes[CollectionPath]>[k_2]["_input"]; }>[k_3]; }> | undefined;
}) => {
result: Ref<(FirestoreCollectionTypes[CollectionPath] & {
id: string;
}) | undefined>;
validationError: Ref<ZodError<any> | undefined>;
updateDoc: (data: PartialWithFieldValue<FirestoreCollectionTypes[CollectionPath]>) => Promise<_firebase_firestore.DocumentReference<FirestoreCollectionTypes[CollectionPath]>>;
resetValidationError: () => void;
stop: () => void;
};
export { createPathRef, toReactiveQueryOption, useCollection, useDoc, useDocBiDirection };