import { QueryDocumentSnapshot } from 'firebase-admin/firestore'; import { Observable, ReplaySubject } from 'rxjs'; import * as i0 from '@angular/core'; import * as dayjs from 'dayjs'; import dayjs__default from 'dayjs'; import * as _nx_ddd_firestore from '@nx-ddd/firestore'; import Dexie from 'dexie'; import { Repository } from '@nx-ddd/common/domain'; type DocumentData = { [field: string]: any; }; interface GetOptions { readonly source?: 'default' | 'server' | 'cache'; } interface DocumentChangeAction { type: any; payload: { doc: DocumentSnapshot; }; } interface DocumentSnapshot { id: string; ref: { path: string; }; data: () => AppModelType | undefined; get: (fieldPath: string) => any; exists?: (() => boolean) | boolean; } interface QuerySnapshot { docs: Array>; } interface Timestamp { readonly seconds: number; readonly nanoseconds: number; toDate(): Date; toMillis(): number; isEqual(other: Timestamp): boolean; valueOf(): string; } interface TimestampConstructor { new (seconds: number, nanoseconds: number): Timestamp; now(): Timestamp; fromDate(date: Date): Timestamp; fromMillis(milliseconds: number): Timestamp; } type FieldValue = any; type ToFirestoreData = { [K in keyof Entity]: Entity[K] extends Date ? Timestamp | FieldValue : Entity[K]; }; interface DocumentReference { __ref?: Origin; exists(): Promise; set(data: AppModelType, options?: any): Promise; get(): Promise>; update(data: AppModelType): Promise; delete(): Promise; stateChanges?: () => Observable>; } type CollectionReference = Query; type CollectionGroup = Query; interface Query { __ref?: Origin; stateChanges?: () => Observable[]>; get(options?: GetOptions): Promise>; onSnapshot?(onNext: (snapshot: QuerySnapshot) => void, onError?: (error: Error) => void): () => void; count(): Promise; } type CollectionLike = CollectionReference | CollectionGroup | Query; declare class DateAdapter { isDate(value: any): value is D; isValid(value: any): boolean; getJsDate(value: any): D; convertToDate(value: Date): D; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } type QueryFn = (collection?: any) => R; type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in'; declare abstract class FirestoreAdapter { protected dateAdapter: DateAdapter; protected abstract isTimestamp(v: any): v is Timestamp; protected abstract isFieldValue(v: any): v is FieldValue; abstract get Timestamp(): any; abstract get FieldValue(): any; abstract get FieldPath(): any; abstract doc(path: string): DocumentReference; abstract collection(path: string): CollectionReference; abstract collectionGroup(collectionId: string): CollectionGroup; abstract query(collection: CollectionReference, ...queryFnArray: QueryFn[]): Query; abstract where(key: string, evaluation: WhereFilterOp, value: unknown): QueryFn; abstract orderBy(key: string, order: 'asc' | 'desc'): QueryFn; abstract limit(n: number): QueryFn; abstract runTransaction(fn: any): any; abstract batch(): any; toFirestoreData(entity: Entity): ToFirestoreData; fromFirestoreData(data: ToFirestoreData): Entity; toFirestore(obj: object, Entity: new () => T): object; fromFirestore(data: any, Entity: new () => T): T; /** * @description FirestoreのUpdateは通常のオブジェクトでは孫以下のプロパティが既存データとマージされないので、パスに変換する必要がある。 */ flattenForUpdate(obj: any): any; convertDateToTimestamp(date: Date): Timestamp; convertTimestampToDate(timestamp: Timestamp): Date; } declare function provideFirestoreAdapter(useClass: new () => FirestoreAdapter): { provide: typeof FirestoreAdapter; useClass: new () => FirestoreAdapter; }; interface IFirestoreConverter { fromFirestore(doc: DocumentSnapshot): E; fromFirestoreMany(docs: DocumentSnapshot[]): E[]; toFirestore(entity: Partial): object; fromObject?(obj: object): E; toObject?(entity: E): object; } declare function getConverter(Entity: new () => Entity, adapter?: FirestoreAdapter): IFirestoreConverter; declare function injectConverter(Entity: new () => Entity): IFirestoreConverter; type CollectionParamMap = Partial; type DocParamMap = CollectionParamMap & Pick; type ExtractParams = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? { [K in Param | keyof ExtractParams]: string; } : T extends `${infer _Start}:${infer Param}` ? { [K in Param]: string; } : {}; type ColParam$3 = Omit, 'id'>; type DocParam$2 = ColParam$3 & { id: string; }; declare class FirestorePathBuilder { private paths; doc(param: DocParamMap): string; collection(param?: Omit, 'id'> | {}): string; collectionGroup(): string; constructor(paths: string[]); } declare function pathBuilderFactory(path: Path): FirestorePathBuilder; declare function parsePath(path: Path): string[]; declare const resolvePaths: (obj: object, paths: string[]) => string; declare class FirestoreDAO> { protected adapter: FirestoreAdapter; protected pathBuilder: FirestorePathBuilder; constructor(adapter: FirestoreAdapter, pathBuilder: FirestorePathBuilder); collection(paramMap?: Partial): CollectionReference; collectionGroup(): CollectionGroup; doc(paramMap: Partial & { id: string; }): DocumentReference; getCollection(paramMap?: Partial): CollectionLike; } declare const FIRESTORE_ANNOTATIONS = "firestore_annotations"; type FirestoreFieldType = 'id' | 'boolean' | 'number' | 'timestamp' | 'string' | 'geopoint' | 'null' | 'map' | 'array' | 'reference'; interface FirestoreAnnotation { type: FirestoreFieldType; fieldName: string; propName: string; childType: any; } declare const createDecorator: (type: FirestoreFieldType, options?: { childType?: any; }) => (nameOrProps?: { name?: string; } | string) => (target: any, propName: string) => void; declare const createPropsDecorator: (type: FirestoreFieldType, options?: { childType?: any; }) => (nameOrProps?: { name?: string; } | string) => (target: any, propName: string) => void; declare const createClassDecorator: (type: string) => (nameOrProps: Props | string) => (target: any) => void; declare const getAnnotations: (target: any) => FirestoreAnnotation[]; /** @deprecated use getAnnotations */ declare function getFirestoreAnnotations(target: any): FirestoreAnnotation[]; declare function getCollection(target: any): string; declare const Firestore: { Collection: (nameOrProps: string | { name: string; }) => (target: any) => void; ID: (nameOrProps?: { name?: string; } | string) => (target: any, propName: string) => void; String: (nameOrProps?: { name?: string; } | string) => (target: any, propName: string) => void; Null: (nameOrProps?: { name?: string; } | string) => (target: any, propName: string) => void; Geopoint: (nameOrProps?: { name?: string; } | string) => (target: any, propName: string) => void; Boolean: (nameOrProps?: { name?: string; } | string) => (target: any, propName: string) => void; Timestamp: (nameOrProps?: { name?: string; } | string) => (target: any, propName: string) => void; Number: (nameOrProps?: { name?: string; } | string) => (target: any, propName: string) => void; Map: (childType?: () => any, props?: { name?: string; }) => (target: any, propName: string) => void; Array: (childType?: () => any, props?: { name?: string; }) => (target: any, propName: string) => void; Reference: (nameOrProps?: { name?: string; } | string) => (target: any, propName: string) => void; }; declare class FirestoreQuery$1> extends FirestoreDAO { protected converter: IFirestoreConverter; protected pathBuilder: FirestorePathBuilder; constructor(adapter: FirestoreAdapter, converter: IFirestoreConverter, pathBuilder: FirestorePathBuilder); protected readonly collection$: ReplaySubject>; protected readonly list$: Observable; /** @deprecated */ listChanges(paramMap?: Partial, options?: { switch?: boolean; }): Observable; listChangesV2(paramMap?: Partial): Observable; listChangesAfter(updatedAt: dayjs__default.Dayjs, { limit }?: { limit?: number; }): Observable; changes({ id }: Partial): Observable; changesV2(params: Partial): Observable; get({ id }: Partial & { id: string; }): Promise; list(paramMap?: Partial): Promise; protected listChangesByCollectionRef(collection: CollectionReference | CollectionGroup): Observable; protected switchCollectionRef(paramMap?: Partial): void; switchCollection(collection: CollectionLike): void; } type ColParam$2> = Omit, 'id'>; type DocParam$1> = ColParam$2 & { id: string; }; declare abstract class BaseFirestoreQuery { protected abstract readonly adapter: FirestoreAdapter; protected abstract readonly converter: IFirestoreConverter; abstract readonly collectionPath: string; protected abstract pathBuilder: FirestorePathBuilder; protected abstract dao: FirestoreDAO; count(paramMap?: ColParam$2): Promise; changes(params: DocParam$1): Observable; get(paramMap: DocParam$1): Promise; list(paramMap?: ColParam$2): Promise; listChanges(paramMap?: ColParam$2): Observable; protected getChanges$ByDocument(doc: DocumentReference): Observable; protected getListChanges$ByCollectionLike(collection: CollectionLike): Observable; } declare abstract class FirestoreQuery extends BaseFirestoreQuery { protected readonly adapter: FirestoreAdapter; abstract readonly collectionPath: string; protected abstract readonly converter: IFirestoreConverter; get pathBuilder(): FirestorePathBuilder; protected get dao(): FirestoreDAO>; static ɵfac: i0.ɵɵFactoryDeclaration, never>; static ɵprov: i0.ɵɵInjectableDeclaration>; } declare function getFirestoreQuery(entity: { new (): Entity; }, adapter?: FirestoreAdapter): BaseFirestoreQuery; declare function injectFirestoreQuery(entity: { new (): Entity; }): BaseFirestoreQuery; type ColParam$1 = Omit, 'id'>; interface EntityData { id: string; value: string; collectionPath: string; updatedAt: string; } declare class DexieAdapter extends Dexie { entities: Dexie.Table; constructor(); count$(): Observable; getLastUpdatedAt$(collectionPath: string): Observable; bulkPut(collectionPath: string, entities: E[]): Promise; listChanges(collectionPath: string): Observable; } declare class FirestoreIndexedDbCached { protected collectionPath: string; constructor(collectionPath: string); readonly adapter: DexieAdapter; getLastUpdatedAt$(): Observable; setMany(entities: E[]): Promise; listChanges(): Observable; } declare abstract class CachedFirestoreQuery extends FirestoreQuery { protected _cached: FirestoreIndexedDbCached; protected get cached(): FirestoreIndexedDbCached; protected readonly config: { throttleTime: number; loadChunkSize: number; }; listChanges(paramMap?: ColParam$1): Observable; protected _listChange(paramMap?: ColParam$1): Observable; protected _listChangesAfter(collection: CollectionLike, updatedAt: dayjs__default.Dayjs, { limit }?: { limit?: number; }): Observable; progressChanges(): Observable<{ cloud: number; local: number; }>; static ɵfac: i0.ɵɵFactoryDeclaration, never>; static ɵprov: i0.ɵɵInjectableDeclaration>; } type ExtractEntity> = T extends BaseFirestoreRepository ? Entity : never; type ColParam> = Omit, 'id'>; type DocParam, TExtra = {}> = ColParam & { id: string; } & TExtra; declare abstract class BaseFirestoreRepository extends Repository { abstract readonly collectionPath: string; protected abstract readonly adapter: FirestoreAdapter; protected abstract converter: IFirestoreConverter; abstract readonly pathBuilder: FirestorePathBuilder; list(paramMap?: ColParam, query?: any): Promise; listChanges(): Observable; count(paramMap?: ColParam): Promise; get(paramMap?: DocParam): Promise; save(entity: DocParam & Entity): Promise<[Entity, boolean]>; saveMany(entities: Entity[]): Promise; create(entity: DocParam & Entity): Promise; createMany(entities: (DocParam & Entity)[]): Promise; update(entity: DocParam & Partial): Promise; updateMany(data: Partial[]): Promise; delete(paramMap: DocParam): Promise; deleteMany(params: { id: string; }[]): Promise; deleteAll(): Promise; bulkWrite(entities: (DocParam & Entity)[], timestamps?: string[]): Promise; bulkCreate(entities: (DocParam & Entity)[]): Promise; bulkUpdate(entities: (DocParam & Partial)[]): Promise; bulkDelete(paramMaps: DocParam[]): Promise; protected collection(paramMap?: Omit, 'id'>): CollectionReference; protected collectionGroup(): CollectionGroup; protected doc(paramMap: DocParam): DocumentReference; protected genId: () => string; protected _list(collection: CollectionReference): Promise; protected _get(doc: DocumentReference): Promise; protected _save(doc: DocumentReference, entity: Entity): Promise<[Entity, boolean]>; protected _create(doc: DocumentReference, entity: Entity): Promise; protected _set(doc: DocumentReference, entity: Partial, isUpdate?: boolean): Promise>; protected buildServerTimestampObject(keys?: string[]): {}; } declare abstract class FirestoreRepository extends BaseFirestoreRepository { protected readonly adapter: FirestoreAdapter; get pathBuilder(): FirestorePathBuilder; static ɵfac: i0.ɵɵFactoryDeclaration, never>; static ɵprov: i0.ɵɵInjectableDeclaration>; } declare function getFirestoreRepository(entity: { new (): Entity; }, adapter?: FirestoreAdapter): BaseFirestoreRepository; declare function injectFirestoreRepository(entity: { new (): Entity; }): BaseFirestoreRepository; export { BaseFirestoreQuery, BaseFirestoreRepository, CachedFirestoreQuery, FIRESTORE_ANNOTATIONS, Firestore, FirestoreAdapter, FirestoreDAO, FirestorePathBuilder, FirestoreQuery$1 as FirestoreQuery, FirestoreQuery as FirestoreQueryV2, FirestoreRepository, createClassDecorator, createDecorator, createPropsDecorator, getAnnotations, getCollection, getConverter, getFirestoreAnnotations, getFirestoreQuery, getFirestoreRepository, injectConverter, injectFirestoreQuery, injectFirestoreRepository, parsePath, pathBuilderFactory, provideFirestoreAdapter, resolvePaths }; export type { ColParam$3 as ColParam, CollectionGroup, CollectionLike, CollectionReference, DocParam$2 as DocParam, DocumentChangeAction, DocumentData, DocumentReference, DocumentSnapshot, ExtractEntity, ExtractParams, FieldValue, FirestoreAnnotation, FirestoreFieldType, GetOptions, IFirestoreConverter, Query, QueryFn, QuerySnapshot, Timestamp, TimestampConstructor, ToFirestoreData, WhereFilterOp };