All files / src/mock MockReadModelApi.ts

35.29% Statements 6/17
0% Branches 0/9
0% Functions 0/7
42.85% Lines 6/14

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 30 31 32 33 34        1x 1x   1x   1x 1x     1x                                        
// Package: com.lightningkite.lightningdb.mock
// Generated by Khrysalis - this file will be overwritten.
import { HasId } from '../HasId'
import { Query } from '../Query'
import { ReadModelApi } from '../ReadModelApi'
import { xListComparatorGet } from '../SortPart'
import { UUIDFor } from '../UUIDFor'
import { ItemNotFound } from './ItemNotFound'
import { MockTable } from './MockTable'
import { Comparable, compareBy } from '@lightningkite/khrysalis-runtime'
import { Observable, of, throwError } from 'rxjs'
 
//! Declares com.lightningkite.lightningdb.mock.MockReadModelApi
export class MockReadModelApi<Model extends HasId> extends ReadModelApi<Model> {
    public constructor(public readonly table: MockTable<Model>) {
        super();
    }
    
    
    public list(query: Query<Model>): Observable<Array<Model>> {
        return of(this.table
            .asList().filter((item: Model): boolean => query.condition.invoke(item)).slice().sort(xListComparatorGet(query.orderBy) ?? compareBy<Model>((it: Model): (Comparable<(any | null)> | null) => it._id)).slice(query.skip).slice(0, query.limit));
    }
    
    public get(id: UUIDFor<Model>): Observable<Model> {
        return ((): (Observable<Model> | null) => {
            const temp9 = this.table.getItem(id);
            Iif(temp9 === null) { return null }
            return ((it: Model): Observable<Model> => of(it))(temp9)
        })() ?? throwError(new ItemNotFound(`404 item with key ${id} not found`));
    }
}