blow-data
Version:
Data access layer for Blow.
47 lines (35 loc) • 1.01 kB
text/typescript
;
import {Observable} from 'rxjs';
import {IAdapter, IAdapterOptions, IAdapterConstructor} from '../interfaces';
const DEFAULT_ID_PROPERTY_NAME = 'id';
const DEFAULT_ID_PROPERTY_TYPE = 'string';
export class Adapter implements IAdapter {
protected _options: IAdapterOptions;
constructor(options: IAdapterOptions) {
this._options = options;
}
get idPropertyName(): string {
return DEFAULT_ID_PROPERTY_NAME;
}
get idPropertyType(): any {
return DEFAULT_ID_PROPERTY_TYPE;
}
protected _connect(): Observable<IAdapter> {
return Observable.of(this);
}
connect(): Observable<IAdapter> {
return this._connect();
}
toJSON(): {[key: string]: string} {
return {
name: this.constructor.name
};
}
inspect(): {[key: string]: string} {
return this.toJSON();
}
static init(options: IAdapterOptions): Observable<IAdapter> {
const adapter = new this(options);
return adapter.connect().mapTo(adapter);
}
}