import { Observable } from "rxjs" ; import { filter } from "rxjs/operators" ; import { CoatyObject , Controller , ObjectFilter , ObjectJoinCondition , QueryEvent , RetrieveEvent } from "../.." ; import { DbContext } from "../../db" ; export const OBJECT_TYPE_NAME_DB_TEST_OBJECT = "coaty.test.DbTestObject" ; export interface DbTestObject extends CoatyObject { testId : number ; testValue : any ; testText : string ; testBool : boolean ; testObj : { "" : number ; name : string ; testId : number ; testValue : any ; testText : string ; testBool : boolean ; } ; testUpdate ? : string ; " " : string ; "" : { "" : { "" : number ; } ; } ; "." : { "." : { "." : number ; } ; } ; } export class MockQueryingController extends Controller { query ( objectFilter , objectJoinConditions ) { return this . communicationManager . publishQuery ( QueryEvent . withObjectTypes ( [ OBJECT_TYPE_NAME_DB_TEST_OBJECT ] , objectFilter , objectJoinConditions ) ) ; } } export class DbTestObjectManagementController extends Controller { onInit ( ) { super . onInit ( ) ; this . _handleQueryEvents ( ) ; } private _handleQueryEvents ( ) { this . communicationManager . observeQuery ( ) . pipe ( filter ( event => event . data . isObjectTypeCompatible ( OBJECT_TYPE_NAME_DB_TEST_OBJECT ) ) ) . subscribe ( event => { this . _retrieveTestObjects ( event ) ; } ) ; } private _retrieveTestObjects ( event ) { const connectionInfo = this . runtime . databaseOptions [ "testdb" ] ; const dbContext = new DbContext ( connectionInfo ) ; const objectFilter = event . data . objectFilter ; const joinConditions = dbContext . getDbJoinConditionsFrom ( event . data . objectJoinConditions , { localProperty : "testId" , fromCollection : "testobjects" , fromProperty : "testId" , } , { localProperty : "externalId" , fromCollection : "testobjects" , fromProperty : "externalId" , } , { localProperty : "testValue" , fromCollection : "testobjects" , fromProperty : "testId" , } ) ; dbContext . findObjects < DbTestObject > ( "testobjects" , objectFilter , joinConditions ) . then ( iterator => iterator . forBatch ( batch => { event . retrieve ( RetrieveEvent . withObjects ( batch ) ) ; } ) ) . catch ( error => { } ) ; } }