import { firebase } from '../externals/firebase' ; import { User , BattleRecord , Pokemon } from '../../types/struct' ; type Document = firebase . firestore . DocumentSnapshot < firebase . firestore . DocumentData > ; type Key < T > = keyof T ; export function toObject < T > ( doc , omit ? ) { const obj = { id : doc . id , ... doc . data ( ) , } ; ( omit || [ ] ) . forEach ( ( k ) => { delete obj [ k ] ; } ) ; return obj as T ; } export function toUserDocument ( doc , omit ? ) { return toObject < User > ( doc , omit ) ; } export function toPokemonDocument ( doc , omit ? ) { return toObject < Pokemon > ( doc , omit ) ; } export function toBattleRecordDocument ( doc , omit ? ) { return toObject < BattleRecord > ( doc , omit ) ; }