yalento
Version:
An awesome integration of Google Firebase for Angular and Node
241 lines (240 loc) • 6.46 kB
TypeScript
import 'reflect-metadata';
import { Subject } from 'rxjs';
import { IConnectorInterface } from './connector/ConnectorInterface';
import { Firebase, Firestore, IConnectionFirestore } from './connector/FirestoreConnector';
import { IConnectionLocalStorage, IStorage } from './connector/LocalStorageConnector';
import { IQueryPaginatorDefaults } from './query/QueryPaginator';
import { IStatement } from './QuerySubject';
import { Select } from './select/select';
export interface IRepositoryData {
_ref: any;
__removed: boolean;
__uuid: string;
__owner: string[];
__viewer: string[];
}
export interface IConnections<T> {
[key: string]: IConnectorInterface<T>;
}
export declare type IRepositoryDataCreate<T> = IBaseIRepositoryDataCreate<T> & {
[P in keyof T]?: T[P];
};
export interface IClassProperty {
name: string;
}
interface IBaseEntityInner {
save(): void;
}
interface IBaseIRepositoryDataCreate<T> {
__uuid?: any;
}
interface IBaseEntity<T> {
save(): void;
remove(): void;
getUuid(): string;
getModel(): T;
toJson(): string;
revert(): Promise<IEntity<T>>;
setProperty(property: keyof T, value: any): IBaseEntityInner;
setGeoPoint(latitude: number, longitude: number): IBaseEntityInner;
getDistance(): number;
isLoaded(): boolean;
isRemoved(): boolean;
getGeoData(): GeoData;
_toPlain(): Record<any, any>;
}
export declare type IEntity<T> = IBaseEntity<T> & {
[P in keyof T]?: T[P];
};
export declare type IConnectionsKeys = ['firestore'];
declare class GeoData {
private readonly geohash;
private readonly latitude;
private readonly longitude;
constructor(hash: string, lat: number, lng: number);
getHash(): string;
getLat(): number;
getLng(): number;
}
/**
* Repository class
* This class can be instantiated by new constructor.
* You can use the class as singleton, if you share repository data, otherwise initiate new instance for every sql statement
*/
export declare class Repository<T> {
/**
*
*/
static generateUuid(): string;
_zone: any;
private readonly _creationTimestamp;
private readonly _instanceIdentifier;
private readonly _class;
private readonly _classProperties;
private readonly _constructorArguments;
private readonly _subjects;
private readonly _selects;
private _subscriptions;
private _tempData;
private _excludeSerializeProperties;
private _connections;
private _className;
private userUuid;
private userUuid$;
private privateMode;
private geoQuery;
/**
* construct new repository instance
* @param model
* @param className
* @param constructorArguments
*/
constructor(model: any, className: string, ...constructorArguments: any[]);
/**
* destroy repository instance
*/
destroy(): void;
unsubscribe(): void;
getUserUuid(): string;
getUserUuidObservable(): Subject<any>;
isPrivateMode(): boolean;
/**
*
* @param storage
* @param options
*/
connectLocalStorage(storage: IStorage, options?: IConnectionLocalStorage): void;
/**
*
* @param firestore
* @param options
*/
connectFirestore(firestore: Firestore | Firebase, options?: IConnectionFirestore): Repository<T>;
/**
* set ngZone
* @param ngZone
*/
setNgZone(ngZone: any): this;
/**
*
*/
loadQueryFromConnectors(query: string): void;
/**
*
* @param sql
* @param paginatorDefaults
*/
select(sql?: IStatement, paginatorDefaults?: IQueryPaginatorDefaults): Select<T>;
getOneByIdentifier(identifier: string): Promise<IEntity<T>>;
exec(sql: IStatement, skipGeolocation?: boolean): Promise<IEntity<T>[]>;
/**
*
* @param data
* @param id
* @param readDefaultsFromSelectStatement
* @param skipConnector
* @param owners
*/
create(data?: IRepositoryDataCreate<T>, id?: string | number, readDefaultsFromSelectStatement?: string, skipConnector?: string, owners?: string[]): Promise<IEntity<T>>;
/**
*
* @param data
* @param skipConnector
*/
remove(data: IEntity<T> | T, skipConnector?: string): Promise<IEntity<T>>;
/**
*
* @param data
* @param skipConnector
*/
update(data: IEntity<T>, skipConnector?: string): Promise<IEntity<T>>;
/**
*
* @param data
* @param skipConnector
*/
updateMultiple(data: IEntity<T>[], skipConnector?: string): Promise<IEntity<T>[]>;
/**
*
* @param data
* @param skipConnector
*/
removeMultiple(data: IEntity<T>[] | T[], skipConnector?: string): Promise<IEntity<T>[]>;
/**
*
* @param data
* @param readDefaultsFromSelectStatement
* @param skipConnector
*/
createMany(data: IRepositoryDataCreate<T>[], readDefaultsFromSelectStatement?: string, skipConnector?: string): Promise<IEntity<T>[]>;
updateGeoLocations(nearByFound: T[], currentLat: number, currentLng: number): void;
/**
* INTERNAL USE ONLY: return temporary identifier
*/
getInstanceIdentifier(): string;
/**
* INTERNAL USE ONLY: return temporary identifier
*/
getClassProperties(): IClassProperty[];
/**
* get assql table name
*/
getTableName(): string;
/**
*
*/
getCreationTimestamp(): number;
/**
*
*/
getClassName(): string;
/**
* count temporary data
*/
count(): number;
setGeoQuery(geoQuery?: string): void;
getGeoQuery(): string;
/**
*
* @param id
* @param data
*/
createClassInstance(id?: string | number, data?: any): IEntity<T>;
private createObjectFromClass;
/**
*
* @param data
* @param id
* @param readDefaultsFromSelectStatement
*/
private createOneFromMany;
/**
* create temporary database if not exists
*/
private createDatabase;
/**
*
* @param readDefaultsFromSelectStatement
*/
private getDataFromSelectStatement;
private createEmptyEntity;
/**
*
* @param data
* @param id
*/
private updateProperties;
/**
*
* @param lat1
* @param lon1
* @param lat2
* @param lon2
*/
private distance;
/**
* check properties that can to be serialized
*/
private initSerializer;
}
export {};