{"version":3,"file":"angularity-fire-firestore.mjs","sources":["../../../packages/fire/firestore/src/converter.ts","../../../packages/fire/firestore/src/resource.ts","../../../packages/fire/firestore/src/angularity-fire-firestore.ts"],"sourcesContent":["import {\n  DocumentData,\n  FirestoreDataConverter,\n  PartialWithFieldValue,\n} from 'firebase/firestore';\n\nexport interface SimpleFirestoreDataConverterConfig<\n  Model extends DocumentData,\n  Record extends DocumentData,\n> {\n  toRecord: (\n    model: PartialWithFieldValue<Model>,\n  ) => PartialWithFieldValue<Record>;\n  toModel(record: object): Model;\n}\n\nexport function createSimpleFirestoreDataConverter<\n  Model extends DocumentData,\n  Record extends DocumentData,\n>(\n  config: SimpleFirestoreDataConverterConfig<Model, Record>,\n): FirestoreDataConverter<Model, Record> {\n  return {\n    fromFirestore: (snapshot, options) =>\n      config.toModel(snapshot.data(options)),\n    toFirestore: (model) => config.toRecord(model) as Record,\n  };\n}\n","import {\n  collection,\n  CollectionReference,\n  doc,\n  DocumentData,\n  DocumentReference,\n  Firestore,\n  FirestoreDataConverter,\n  Query,\n} from 'firebase/firestore';\nimport { collectionData, docData } from 'rxfire/firestore';\nimport { Observable } from 'rxjs';\n\nexport interface FirestoreResourceConfig<\n  ModelWithId extends DocumentData,\n  Record extends DocumentData,\n  IdField extends keyof ModelWithId,\n> {\n  readonly path: string;\n  readonly idField: IdField;\n  readonly converter: FirestoreDataConverter<\n    Omit<ModelWithId, IdField>,\n    Record\n  >;\n}\n\n/**\n * A class that provides type-safe access to the Firestore collection and\n * documents of a specific model.\n */\nexport class FirestoreResource<\n  ModelWithId extends DocumentData,\n  Record extends DocumentData,\n  IdField extends keyof ModelWithId,\n> {\n  constructor(\n    protected firestore: Firestore,\n    protected config: FirestoreResourceConfig<ModelWithId, Record, IdField>,\n  ) {}\n\n  readonly path = this.config.path;\n  readonly idField = this.config.idField;\n  readonly converter = this.config.converter;\n\n  refDoc(id: string): DocumentReference<Omit<ModelWithId, IdField>, Record> {\n    const { path, converter } = this;\n    return doc(this.firestore, path, id).withConverter(converter);\n  }\n\n  refNewDoc(): DocumentReference<Omit<ModelWithId, IdField>, Record> {\n    const { converter } = this;\n    const collectionRef = this.refCollection();\n    return doc(collectionRef).withConverter(converter);\n  }\n\n  refCollection(): CollectionReference<Omit<ModelWithId, IdField>, Record> {\n    const { path, converter } = this;\n    return collection(this.firestore, path).withConverter(converter);\n  }\n\n  resolveQuery(\n    query: Query<Omit<ModelWithId, IdField>>,\n  ): Observable<ModelWithId[]> {\n    const { idField } = this;\n    // Type-assert required because of the incorrect typing of the `idField` option\n    return collectionData(query as Query<ModelWithId>, { idField });\n  }\n\n  resolveDoc(\n    ref: DocumentReference<Omit<ModelWithId, IdField>>,\n  ): Observable<ModelWithId | undefined> {\n    const { idField } = this;\n    // Type-assert required because of the incorrect typing of the `idField` option\n    return docData(ref as DocumentReference<ModelWithId>, { idField });\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAgBM,SAAU,kCAAkC,CAIhD,MAAyD,EAAA;IAEzD,OAAO;AACL,QAAA,aAAa,EAAE,CAAC,QAAQ,EAAE,OAAO,KAC/B,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxC,WAAW,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAW;KACzD;AACH;;ACDA;;;AAGG;MACU,iBAAiB,CAAA;IAK5B,WAAA,CACY,SAAoB,EACpB,MAA6D,EAAA;QAD7D,IAAA,CAAA,SAAS,GAAT,SAAS;QACT,IAAA,CAAA,MAAM,GAAN,MAAM;AAGT,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI;AACvB,QAAA,IAAA,CAAA,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO;AAC7B,QAAA,IAAA,CAAA,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS;IAJvC;AAMH,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