All files / src/client/live LiveReadModelApi.ts

33.33% Statements 3/9
100% Branches 0/0
0% Functions 0/3
42.85% Lines 3/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29          1x   1x       1x                                  
// Package: com.lightningkite.lightningdb.live
// Generated by Khrysalis - this file will be overwritten.
import { HasId } from '../../shared/HasId'
import { Query } from '../../shared/Query'
import { UUIDFor } from '../../shared/UUIDFor'
import { ReadModelApi } from '../ReadModelApi'
import { ReifiedType } from '@lightningkite/khrysalis-runtime'
import { HttpBody, HttpClient, fromJSON, unsuccessfulAsError } from '@lightningkite/rxjs-plus'
import { Observable } from 'rxjs'
 
//! Declares com.lightningkite.lightningdb.live.LiveReadModelApi
export class LiveReadModelApi<Model extends HasId> extends ReadModelApi<Model> {
    public constructor(public readonly url: string, public readonly token: string, public readonly serializer: ReifiedType) {
        super();
    }
    
    
    public list(query: Query<Model>): Observable<Array<Model>> {
        return HttpClient.INSTANCE.call(`${this.url}/query`, HttpClient.INSTANCE.POST, new Map([["Authorization", `Bearer ${this.token}`]]), HttpBody.json(query), undefined).pipe(unsuccessfulAsError, fromJSON<Array<Model>>([Array, this.serializer]));
    }
    
    
    public get(id: UUIDFor<Model>): Observable<Model> {
        return HttpClient.INSTANCE.call(`${this.url}/${id}`, HttpClient.INSTANCE.GET, new Map([["Authorization", `Bearer ${this.token}`]]), undefined, undefined).pipe(unsuccessfulAsError, fromJSON<Model>(this.serializer));
    }
    
}