(function (root, factory) { if (typeof define === 'function' && define.amd) define(['exports', './kotlin-kotlin-stdlib.js', './kotlinx-coroutines-core.js', './Napier-napier-js-ir.js', './door-door-testdb.js', './door-door-runtime.js', './ktor-ktor-client-core.js', './ktor-ktor-http.js', './ktor-ktor-utils.js', './kotlinx-serialization-kotlinx-serialization-json.js'], factory); else if (typeof exports === 'object') factory(module.exports, require('./kotlin-kotlin-stdlib.js'), require('./kotlinx-coroutines-core.js'), require('./Napier-napier-js-ir.js'), require('./door-door-testdb.js'), require('./door-door-runtime.js'), require('./ktor-ktor-client-core.js'), require('./ktor-ktor-http.js'), require('./ktor-ktor-utils.js'), require('./kotlinx-serialization-kotlinx-serialization-json.js')); else { if (typeof this['kotlin-kotlin-stdlib'] === 'undefined') { throw new Error("Error loading module 'com.github.UstadMobile.door:app-testdb'. Its dependency 'kotlin-kotlin-stdlib' was not found. Please, check whether 'kotlin-kotlin-stdlib' is loaded prior to 'com.github.UstadMobile.door:app-testdb'."); } if (typeof this['kotlinx-coroutines-core'] === 'undefined') { throw new Error("Error loading module 'com.github.UstadMobile.door:app-testdb'. Its dependency 'kotlinx-coroutines-core' was not found. Please, check whether 'kotlinx-coroutines-core' is loaded prior to 'com.github.UstadMobile.door:app-testdb'."); } if (typeof this['Napier-napier-js-ir'] === 'undefined') { throw new Error("Error loading module 'com.github.UstadMobile.door:app-testdb'. Its dependency 'Napier-napier-js-ir' was not found. Please, check whether 'Napier-napier-js-ir' is loaded prior to 'com.github.UstadMobile.door:app-testdb'."); } if (typeof this['door-door-testdb'] === 'undefined') { throw new Error("Error loading module 'com.github.UstadMobile.door:app-testdb'. Its dependency 'door-door-testdb' was not found. Please, check whether 'door-door-testdb' is loaded prior to 'com.github.UstadMobile.door:app-testdb'."); } if (typeof this['door-door-runtime'] === 'undefined') { throw new Error("Error loading module 'com.github.UstadMobile.door:app-testdb'. Its dependency 'door-door-runtime' was not found. Please, check whether 'door-door-runtime' is loaded prior to 'com.github.UstadMobile.door:app-testdb'."); } if (typeof this['ktor-ktor-client-core'] === 'undefined') { throw new Error("Error loading module 'com.github.UstadMobile.door:app-testdb'. Its dependency 'ktor-ktor-client-core' was not found. Please, check whether 'ktor-ktor-client-core' is loaded prior to 'com.github.UstadMobile.door:app-testdb'."); } if (typeof this['ktor-ktor-http'] === 'undefined') { throw new Error("Error loading module 'com.github.UstadMobile.door:app-testdb'. Its dependency 'ktor-ktor-http' was not found. Please, check whether 'ktor-ktor-http' is loaded prior to 'com.github.UstadMobile.door:app-testdb'."); } if (typeof this['ktor-ktor-utils'] === 'undefined') { throw new Error("Error loading module 'com.github.UstadMobile.door:app-testdb'. Its dependency 'ktor-ktor-utils' was not found. Please, check whether 'ktor-ktor-utils' is loaded prior to 'com.github.UstadMobile.door:app-testdb'."); } if (typeof this['kotlinx-serialization-kotlinx-serialization-json'] === 'undefined') { throw new Error("Error loading module 'com.github.UstadMobile.door:app-testdb'. Its dependency 'kotlinx-serialization-kotlinx-serialization-json' was not found. Please, check whether 'kotlinx-serialization-kotlinx-serialization-json' is loaded prior to 'com.github.UstadMobile.door:app-testdb'."); } root['com.github.UstadMobile.door:app-testdb'] = factory(typeof this['com.github.UstadMobile.door:app-testdb'] === 'undefined' ? {} : this['com.github.UstadMobile.door:app-testdb'], this['kotlin-kotlin-stdlib'], this['kotlinx-coroutines-core'], this['Napier-napier-js-ir'], this['door-door-testdb'], this['door-door-runtime'], this['ktor-ktor-client-core'], this['ktor-ktor-http'], this['ktor-ktor-utils'], this['kotlinx-serialization-kotlinx-serialization-json']); } }(this, function (_, kotlin_kotlin, kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core, kotlin_io_github_aakira_napier, kotlin_com_github_UstadMobile_door_door_testdb, kotlin_com_github_UstadMobile_door_door_runtime, kotlin_io_ktor_ktor_client_core, kotlin_io_ktor_ktor_http, kotlin_io_ktor_ktor_utils, kotlin_org_jetbrains_kotlinx_kotlinx_serialization_json) { 'use strict'; //region block: imports var throwUninitializedPropertyAccessException = kotlin_kotlin.$_$.ae; var Unit_instance = kotlin_kotlin.$_$.p4; var GlobalScope_instance = kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.$_$.m; var VOID = kotlin_kotlin.$_$.d; var launch = kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.$_$.p1; var CoroutineImpl = kotlin_kotlin.$_$.f8; var protoOf = kotlin_kotlin.$_$.w9; var THROW_CCE = kotlin_kotlin.$_$.bd; var CoroutineScope = kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.$_$.d1; var isInterface = kotlin_kotlin.$_$.i9; var get_COROUTINE_SUSPENDED = kotlin_kotlin.$_$.r7; var classMeta = kotlin_kotlin.$_$.q8; var setMetadataFor = kotlin_kotlin.$_$.x9; var Napier_getInstance = kotlin_io_github_aakira_napier.$_$.g; var RepEntity = kotlin_com_github_UstadMobile_door_door_testdb.$_$.d; var Long = kotlin_kotlin.$_$.xc; var delay = kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.$_$.b; var systemTimeInMillis = kotlin_com_github_UstadMobile_door_door_runtime.$_$.x; var HttpRequestBuilder = kotlin_io_ktor_ktor_client_core.$_$.c; var url = kotlin_io_ktor_ktor_client_core.$_$.f; var parameter = kotlin_io_ktor_ktor_client_core.$_$.e; var Companion_getInstance = kotlin_io_ktor_ktor_http.$_$.f; var HttpStatement = kotlin_io_ktor_ktor_client_core.$_$.g; var JsType_instance = kotlin_io_ktor_ktor_utils.$_$.b; var PrimitiveClasses_getInstance = kotlin_kotlin.$_$.g4; var arrayOf = kotlin_kotlin.$_$.nd; var createKType = kotlin_kotlin.$_$.a; var typeInfoImpl = kotlin_io_ktor_ktor_utils.$_$.k; var CompletableDeferred = kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.$_$.z; var withTimeout = kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.$_$.d; var RepEntityWithAttachment = kotlin_com_github_UstadMobile_door_door_testdb.$_$.c; var DebugAntilog = kotlin_io_github_aakira_napier.$_$.h; var await_0 = kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.$_$.a; var RepDb = kotlin_com_github_UstadMobile_door_door_testdb.$_$.b; var getKClass = kotlin_kotlin.$_$.c; var RepDbJsImplementations_getInstance = kotlin_com_github_UstadMobile_door_door_testdb.$_$.a; var DatabaseBuilderOptions = kotlin_com_github_UstadMobile_door_door_runtime.$_$.y; var Js_instance = kotlin_io_ktor_ktor_client_core.$_$.b; var HttpClient = kotlin_io_ktor_ktor_client_core.$_$.h; var Companion_getInstance_0 = kotlin_com_github_UstadMobile_door_door_runtime.$_$.o1; var get_rootDatabase = kotlin_com_github_UstadMobile_door_door_runtime.$_$.i; var DoorDatabaseJdbc = kotlin_com_github_UstadMobile_door_door_runtime.$_$.z; var DoorDatabaseWrapper = kotlin_com_github_UstadMobile_door_door_runtime.$_$.b1; var Default_getInstance = kotlin_kotlin.$_$.f4; var Companion_getInstance_1 = kotlin_kotlin.$_$.j4; var Companion_instance = kotlin_com_github_UstadMobile_door_door_runtime.$_$.p1; var NapierDoorLogger = kotlin_com_github_UstadMobile_door_door_runtime.$_$.n; var Json = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_json.$_$.h; var IllegalArgumentException_init_$Create$ = kotlin_kotlin.$_$.h1; var unwrap = kotlin_com_github_UstadMobile_door_door_runtime.$_$.j; var get_js = kotlin_kotlin.$_$.m9; var createInstance = kotlin_com_github_UstadMobile_door_door_runtime.$_$.d; var Companion_instance_0 = kotlin_com_github_UstadMobile_door_door_runtime.$_$.n1; //endregion //region block: pre-declaration setMetadataFor(main$lambda$slambda$slambda, 'main$lambda$slambda$slambda', classMeta, CoroutineImpl, VOID, VOID, VOID, VOID, [1]); setMetadataFor(main$lambda$slambda, 'main$lambda$slambda', classMeta, CoroutineImpl, VOID, VOID, VOID, VOID, [1]); setMetadataFor($openRepoDbCOROUTINE$0, '$openRepoDbCOROUTINE$0', classMeta, CoroutineImpl); //endregion function get_repDb() { var tmp = repDb; if (!(tmp == null)) return tmp; else { throwUninitializedPropertyAccessException('repDb'); } } var repDb; var repRepo; function get_httpClient() { var tmp = httpClient; if (!(tmp == null)) return tmp; else { throwUninitializedPropertyAccessException('httpClient'); } } var httpClient; function openRepoDb($completion) { var tmp = new $openRepoDbCOROUTINE$0($completion); tmp.ha_1 = Unit_instance; tmp.ia_1 = null; return tmp.sa(); } function main() { var tmp = window; tmp.onload = main$lambda; } function openRepoDb$lambda($this$HttpClient) { return Unit_instance; } function openRepoDb$lambda_0($this$Json) { $this$Json.a1p_1 = true; return Unit_instance; } function openRepoDb$lambda_1($this$repositoryConfig) { return Unit_instance; } function main$lambda(it) { var tmp = GlobalScope_instance; launch(tmp, VOID, VOID, main$lambda$slambda_0(null)); return Unit_instance; } function main$lambda$slambda$slambda($completableDeferred, resultContinuation) { this.t5q_1 = $completableDeferred; CoroutineImpl.call(this, resultContinuation); } protoOf(main$lambda$slambda$slambda).v5q = function ($this$withTimeout, $completion) { var tmp = this.d27($this$withTimeout, $completion); tmp.ha_1 = Unit_instance; tmp.ia_1 = null; return tmp.sa(); }; protoOf(main$lambda$slambda$slambda).fb = function (p1, $completion) { return this.v5q((!(p1 == null) ? isInterface(p1, CoroutineScope) : false) ? p1 : THROW_CCE(), $completion); }; protoOf(main$lambda$slambda$slambda).sa = function () { var suspendResult = this.ha_1; $sm: do try { var tmp = this.fa_1; switch (tmp) { case 0: this.ga_1 = 2; this.fa_1 = 1; suspendResult = this.t5q_1.zk(this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 1: return suspendResult; case 2: throw this.ia_1; } } catch ($p) { var e = $p; if (this.ga_1 === 2) { throw e; } else { this.fa_1 = this.ga_1; this.ia_1 = e; } } while (true); }; protoOf(main$lambda$slambda$slambda).d27 = function ($this$withTimeout, completion) { var i = new main$lambda$slambda$slambda(this.t5q_1, completion); i.u5q_1 = $this$withTimeout; return i; }; function main$lambda$slambda$slambda_0($completableDeferred, resultContinuation) { var i = new main$lambda$slambda$slambda($completableDeferred, resultContinuation); var l = function ($this$withTimeout, $completion) { return i.v5q($this$withTimeout, $completion); }; l.$arity = 1; return l; } function main$lambda$slambda(resultContinuation) { CoroutineImpl.call(this, resultContinuation); } protoOf(main$lambda$slambda).c27 = function ($this$launch, $completion) { var tmp = this.d27($this$launch, $completion); tmp.ha_1 = Unit_instance; tmp.ia_1 = null; return tmp.sa(); }; protoOf(main$lambda$slambda).fb = function (p1, $completion) { return this.c27((!(p1 == null) ? isInterface(p1, CoroutineScope) : false) ? p1 : THROW_CCE(), $completion); }; protoOf(main$lambda$slambda).sa = function () { var suspendResult = this.ha_1; $sm: do try { var tmp = this.fa_1; switch (tmp) { case 0: this.ga_1 = 9; this.fa_1 = 1; suspendResult = openRepoDb(this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 1: Napier_getInstance().k3v('IndexTest: Inserting into repDb'); this.fa_1 = 2; var tmp_0 = get_repDb().y5l(); var this_0 = new RepEntity(); this_0.c5j_1 = 'From client at ' + (new Date()).toUTCString() + ' UTC'; this_0.b5j_1 = 500; suspendResult = tmp_0.e5j(this_0, this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 2: Napier_getInstance().k3v('IndexTest: Inserted into repDb'); this.fa_1 = 3; suspendResult = delay(new Long(5000, 0), this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 3: this.fa_1 = 4; suspendResult = get_repDb().y5l().f5j(new Long(42, 0), this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 4: this.f5r_1 = suspendResult; console.log('IndexTest: GOT ENTITY FROM SERVER:? ' + this.f5r_1); console.log('IndexTest: Asking server to make something'); this.g5r_1 = systemTimeInMillis(); var tmp_1 = this; tmp_1.h5r_1 = get_httpClient(); var tmp_2 = this; tmp_2.i5r_1 = 'http://localhost:8098/insertRepEntity'; var tmp_3 = this; tmp_3.j5r_1 = this.h5r_1; var tmp_4 = this; tmp_4.k5r_1 = this.j5r_1; var tmp_5 = this; var this_1 = new HttpRequestBuilder(); url(this_1, this.i5r_1); parameter(this_1, 'rePrimaryKey', this.g5r_1); parameter(this_1, 'reString', 'From server at ' + (new Date()).toUTCString()); tmp_5.l5r_1 = this_1; this.l5r_1.p2y_1 = Companion_getInstance().v2p_1; var tmp_6 = this; tmp_6.m5r_1 = this.k5r_1; var tmp_7 = this; tmp_7.n5r_1 = this.l5r_1; this.fa_1 = 5; suspendResult = (new HttpStatement(this.n5r_1, this.m5r_1)).z3o(this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 5: this.o5r_1 = suspendResult; this.fa_1 = 6; var tmp_8 = this.o5r_1.w31(); var tmp_9 = JsType_instance; var tmp_10 = PrimitiveClasses_getInstance().c7(); var tmp_11; try { tmp_11 = createKType(PrimitiveClasses_getInstance().c7(), arrayOf([]), false); } catch ($p) { var tmp_12; if ($p instanceof Error) { var cause = $p; tmp_12 = null; } else { throw $p; } tmp_11 = tmp_12; } suspendResult = tmp_8.z30(typeInfoImpl(tmp_9, tmp_10, tmp_11), this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 6: var tmp_13 = this; tmp_13.p5r_1 = (!(suspendResult == null) ? typeof suspendResult === 'string' : false) ? suspendResult : THROW_CCE(); console.log('IndexTest: Server says: ' + this.p5r_1 + ' ... Waiting...'); this.q5r_1 = CompletableDeferred(); this.fa_1 = 7; var tmp_14 = new Long(5000, 0); suspendResult = withTimeout(tmp_14, main$lambda$slambda$slambda_0(this.q5r_1, null), this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 7: this.r5r_1 = suspendResult; console.log('IndexTest: Got it back! ' + this.r5r_1); var tmp_15 = this; var this_2 = ['Hello World ' + systemTimeInMillis().toString()]; var type = 'text/string'; var o = {}; o['type'] = type; tmp_15.s5r_1 = new Blob(this_2, o); console.log('IndexTest: Stored attachment'); var tmp_16 = this; var this_3 = new RepEntityWithAttachment(); this_3.a5o_1 = URL.createObjectURL(this.s5r_1); tmp_16.t5r_1 = this_3; this.fa_1 = 8; suspendResult = get_repDb().z5l().j5n(this.t5r_1, this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 8: console.log('IndexTest: Stored attachment'); return Unit_instance; case 9: throw this.ia_1; } } catch ($p) { var e = $p; if (this.ga_1 === 9) { throw e; } else { this.fa_1 = this.ga_1; this.ia_1 = e; } } while (true); }; protoOf(main$lambda$slambda).d27 = function ($this$launch, completion) { var i = new main$lambda$slambda(completion); i.e5r_1 = $this$launch; return i; }; function main$lambda$slambda_0(resultContinuation) { var i = new main$lambda$slambda(resultContinuation); var l = function ($this$launch, $completion) { return i.c27($this$launch, $completion); }; l.$arity = 1; return l; } function $openRepoDbCOROUTINE$0(resultContinuation) { CoroutineImpl.call(this, resultContinuation); } protoOf($openRepoDbCOROUTINE$0).sa = function () { var suspendResult = this.ha_1; $sm: do try { var tmp = this.fa_1; switch (tmp) { case 0: this.ga_1 = 5; Napier_getInstance().b3v(new DebugAntilog()); this.fa_1 = 1; var tmp_0 = window.fetch('https://raw.githubusercontent.com/UstadMobile/door/dev-js-2/app-testdb/src/main/resources/worker.sql-asm.js'); suspendResult = await_0(tmp_0 instanceof Promise ? tmp_0 : THROW_CCE(), this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 1: this.f5q_1 = suspendResult; this.fa_1 = 2; var tmp_1 = this.f5q_1.blob(); suspendResult = await_0(tmp_1 instanceof Promise ? tmp_1 : THROW_CCE(), this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 2: this.g5q_1 = suspendResult; var tmp_2 = this; var tmp_3 = URL; var tmp_4 = this.g5q_1; tmp_2.h5q_1 = tmp_3.createObjectURL(tmp_4 instanceof Blob ? tmp_4 : THROW_CCE()); this.i5q_1 = new DatabaseBuilderOptions(getKClass(RepDb), RepDbJsImplementations_getInstance(), new Long(1, 0), 'sqlite:resDb', this.h5q_1); var tmp_5 = Js_instance; httpClient = HttpClient(tmp_5, openRepoDb$lambda); Napier_getInstance().m3v('Creating db and repo'); this.fa_1 = 3; suspendResult = Companion_getInstance_0().q53(this.i5q_1).f58(this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 3: this.j5q_1 = suspendResult; var tmp_6 = this; tmp_6.k5q_1 = this.j5q_1; this.fa_1 = 4; suspendResult = this.k5q_1.p5b(this); if (suspendResult === get_COROUTINE_SUSPENDED()) { return suspendResult; } continue $sm; case 4: var ARGUMENT = this.j5q_1; repDb = ARGUMENT; Napier_getInstance().m3v('Created db'); var tmp_7 = Napier_getInstance(); var tmp_8 = get_rootDatabase(get_repDb()); tmp_7.m3v('Db name = ' + (isInterface(tmp_8, DoorDatabaseJdbc) ? tmp_8 : THROW_CCE()).p4c() + '\n'); var tmp_9 = Napier_getInstance(); var tmp_10 = get_repDb(); tmp_9.m3v('Replicate wrapper name = ' + (isInterface(tmp_10, DoorDatabaseWrapper) ? tmp_10 : THROW_CCE()).p4c() + '\n'); Napier_getInstance().m3v('repDb toString = ' + get_repDb() + '\n'); var tmp_11 = Default_getInstance(); var tmp_12 = new Long(0, 0); Companion_getInstance_1(); var nodeId = tmp_11.td(tmp_12, new Long(-1, 2147483647)); var this_0 = get_repDb(); var tmp_13 = Companion_instance; var tmp_14 = new Object(); var tmp_15 = get_httpClient(); var tmp_16 = new NapierDoorLogger(); var tmp_17 = Json(VOID, openRepoDb$lambda_0); var repositoryConfig = tmp_13.w58(tmp_14, 'http://localhost:8098/RepDb/', 'secret', nodeId, tmp_15, tmp_16, VOID, tmp_17, openRepoDb$lambda_1); var dbClass = getKClass(RepDb); var tmp0_elvis_lhs = Companion_getInstance_0().r53(dbClass).v53(); var tmp_18; if (tmp0_elvis_lhs == null) { throw IllegalArgumentException_init_$Create$('Database ' + dbClass.g6() + ' does not have a repository!'); } else { tmp_18 = tmp0_elvis_lhs; } var repoClass = tmp_18; var tmp_19; if (isInterface(this_0, DoorDatabaseWrapper)) { tmp_19 = unwrap(this_0, dbClass); } else { tmp_19 = this_0; } var dbUnwrapped = tmp_19; var tmp_20 = createInstance(get_js(repoClass), [this_0, dbUnwrapped, repositoryConfig, true]); var repo = tmp_20 instanceof RepDb ? tmp_20 : THROW_CCE(); var tmp_21 = Napier_getInstance(); var tmp_22 = 'Created JS repo ' + repo + ' Node Id ' + repositoryConfig.l4l_1.toString(); tmp_21.m3v(tmp_22, VOID, 'DoorLog'); repRepo = repo; Napier_getInstance().m3v('Created repo'); return Unit_instance; case 5: throw this.ia_1; } } catch ($p) { var e = $p; if (this.ga_1 === 5) { throw e; } else { this.fa_1 = this.ga_1; this.ia_1 = e; } } while (true); }; main(); return _; })); //# sourceMappingURL=door-app-testdb.js.map