import type { DocumentSnapshot } from '@lemasc/firebase-wrapper/firestore' type BaseFields = { id: string hasPendingWrites?: boolean __snapshot?: DocumentSnapshot } export type ValidatedDocument< T extends Record = Record > = BaseFields & T & { exists: true validated: true } type UnvalidatedDocument = BaseFields & { exists: boolean validated: false } export type Document< T extends Record = Record > = ValidatedDocument | UnvalidatedDocument /** * Returns true if the given document is existed and validated against the schema. */ export const isDocumentValid = >( doc: Document ): doc is ValidatedDocument => { return doc.exists && doc.validated }