chore: add prettier and reformat lib

This commit is contained in:
waterplea
2022-07-24 17:53:24 +03:00
parent a39f777cb0
commit 897f791a72
12 changed files with 2600 additions and 112 deletions

View File

@@ -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' })))
}
}

View File

@@ -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' })),
)
}
}

View File

@@ -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>>>
}

View File

@@ -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