mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 18:31:53 +00:00
chore: add prettier and reformat lib
This commit is contained in:
@@ -5,9 +5,9 @@ import { Source } from './source'
|
||||
import { RPCResponse } from './ws-source'
|
||||
|
||||
export class MockSource<T> implements Source<T> {
|
||||
constructor (private readonly seed: Observable<Update<T>>) { }
|
||||
constructor(private readonly seed: Observable<Update<T>>) {}
|
||||
|
||||
watch$ (): Observable<RPCResponse<Update<T>>> {
|
||||
return this.seed.pipe(map((result) => ({ result, jsonrpc: '2.0' })))
|
||||
watch$(): Observable<RPCResponse<Update<T>>> {
|
||||
return this.seed.pipe(map(result => ({ result, jsonrpc: '2.0' })))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import { BehaviorSubject, concat, from, Observable, of } from 'rxjs'
|
||||
import { concatMap, delay, map, skip, switchMap, take, tap } from 'rxjs/operators'
|
||||
import {
|
||||
concatMap,
|
||||
delay,
|
||||
map,
|
||||
skip,
|
||||
switchMap,
|
||||
take,
|
||||
tap,
|
||||
} from 'rxjs/operators'
|
||||
import { Store } from '../store'
|
||||
import { Http, Update } from '../types'
|
||||
import { Source } from './source'
|
||||
@@ -10,17 +18,15 @@ export type PollConfig = {
|
||||
}
|
||||
|
||||
export class PollSource<T> implements Source<T> {
|
||||
|
||||
constructor (
|
||||
constructor(
|
||||
private readonly pollConfig: PollConfig,
|
||||
private readonly http: Http<T>,
|
||||
) { }
|
||||
) {}
|
||||
|
||||
watch$ (store: Store<T>): Observable<RPCResponse<Update<T>>> {
|
||||
watch$(store: Store<T>): Observable<RPCResponse<Update<T>>> {
|
||||
const polling$ = new BehaviorSubject('')
|
||||
|
||||
const updates$ = of({ })
|
||||
.pipe(
|
||||
const updates$ = of({}).pipe(
|
||||
concatMap(_ => store.sequence$),
|
||||
concatMap(seq => this.http.getRevisions(seq)),
|
||||
take(1),
|
||||
@@ -43,8 +49,7 @@ export class PollSource<T> implements Source<T> {
|
||||
return of(res) // takes Dump<T> and converts it into Observable<Dump<T>>
|
||||
}
|
||||
}),
|
||||
map(result => ({ result,
|
||||
jsonrpc: '2.0' })),
|
||||
map(result => ({ result, jsonrpc: '2.0' })),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@ import { Update } from '../types'
|
||||
import { RPCResponse } from './ws-source'
|
||||
|
||||
export interface Source<T> {
|
||||
watch$ (store?: Store<T>): Observable<RPCResponse<Update<T>>>
|
||||
watch$(store?: Store<T>): Observable<RPCResponse<Update<T>>>
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import { Observable } from 'rxjs'
|
||||
import { webSocket, WebSocketSubject, WebSocketSubjectConfig } from 'rxjs/webSocket'
|
||||
import {
|
||||
webSocket,
|
||||
WebSocketSubject,
|
||||
WebSocketSubjectConfig,
|
||||
} from 'rxjs/webSocket'
|
||||
import { Update } from '../types'
|
||||
import { Source } from './source'
|
||||
|
||||
export class WebsocketSource<T> implements Source<T> {
|
||||
private websocket$: WebSocketSubject<RPCResponse<Update<T>>> | undefined
|
||||
|
||||
constructor (
|
||||
private readonly url: string,
|
||||
) { }
|
||||
constructor(private readonly url: string) {}
|
||||
|
||||
watch$ (): Observable<RPCResponse<Update<T>>> {
|
||||
watch$(): Observable<RPCResponse<Update<T>>> {
|
||||
const fullConfig: WebSocketSubjectConfig<RPCResponse<Update<T>>> = {
|
||||
url: this.url,
|
||||
openObserver: {
|
||||
@@ -48,7 +50,7 @@ class RpcError {
|
||||
message: string
|
||||
details: string
|
||||
|
||||
constructor (e: RPCError['error']) {
|
||||
constructor(e: RPCError['error']) {
|
||||
this.code = e.code
|
||||
this.message = e.message
|
||||
this.details = e.data.details
|
||||
|
||||
Reference in New Issue
Block a user