/* Metro module 1926; source: modules/app_database/system/DatabaseManager.tsx; dependencies: [5, 6, 7, 15, 17, 18, 1226, 3, 694, 1927, 1911, 566, 2] */ import Logger from '../../debug/Logger.tsx'; /* Metro dependency 3 */ import Module00005 from '../../../by-id/module-00005.js'; /* Metro dependency 5 */ import ClassCallCheck from '../../../by-id/module-00006-ClassCallCheck.js'; /* Metro dependency 6 */ import CreateClass from '../../../by-id/module-00007-CreateClass.js'; /* Metro dependency 7 */ import PossibleConstructorReturn from '../../../by-id/module-00015-PossibleConstructorReturn.js'; /* Metro dependency 15 */ import Module00017 from '../../../by-id/module-00017.js'; /* Metro dependency 17 */ import Inherits from '../../../by-id/module-00018-Inherits.js'; /* Metro dependency 18 */ import Flux from '../../../external/discord_common/js/packages/flux/index.tsx'; /* Metro dependency 566 */ import Dispatcher from '../../../Dispatcher.tsx'; /* Metro dependency 694 */ import AuthenticationStore from '../../../stores/AuthenticationStore.tsx'; /* Metro dependency 1226 */ import * as FileImportTrackerModule from '../../../by-id/module-00002-FileImportTracker.js'; /* Metro dependency 2 */ import * as DispatcherModule from '../../../Dispatcher.tsx'; /* Metro dependency 694 */ import * as JsModule from '../../../external/discord_common/js/packages/kv-storage/js/index.tsx'; /* Metro dependency 1911 */ function _fun21293(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#21293, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:6, offset: 0x00eed014, size: 349 bytes, params: 8, frame: 19 const env0_0 = require; const _arrayLikeToArray_21296 = function(a0, a1) { var r0; var r1; var r2; var value3; var length; var value5; var value = undefined; var value2 = value == null; reducibleJoin2: while (true) { if (value2) { r0 = value2; break reducibleJoin2; } value3 = value > a0.length; r0 = value3; break reducibleJoin2; } reducibleJoin4: while (true) { if (r0) { length = a0.length; r1 = length; break reducibleJoin4; } r1 = value; break reducibleJoin4; } value = (0, global.Array)(r1); var value4 = 0; if (value4 < r1) { r2 = value4; reducibleLoop5: while (true) { value[r2] = a0[r2]; value5 = typeof r2 === 'bigint' ? r2 + 1n : +r2 + 1; if (value5 < r1) { r2 = value5; continue reducibleLoop5; } break reducibleLoop5; } } return value; }; const _databaseName = function(a0) { return '@account.' + a0; }; const Object = global.Object; Object.defineProperty(exports, '__esModule', {value: true}); let value = Logger; value = new value('DatabaseManager'); const Store = (Flux).Store; value = _fun21304(Store); value = new value(); (FileImportTrackerModule).fileFinishedImporting('modules/app_database/system/DatabaseManager.tsx'); exports.default = value; function _createForOfIteratorHelperLoose_21294(a0, a1) { // fn#21294, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:178, offset: 0x00eed171, size: 370 bytes, params: 3, frame: 20 var r6; var r9; var r5; var value3; var regexp; const env0_0 = a0; const Symbol = global.Symbol; let value = typeof Symbol !== 'undefined'; let r1 = value && a0[global.Symbol.iterator]; r1 = !r1 ? a0['@@iterator'] : r1; if (r1) { value = r1.call(a0); return value.next.bind(value); } const Array = global.Array; if (Array.isArray(a0)) { if (r1) { } return _fun21295; } value = undefined; if (a0) { if (typeof a0 === 'string') { value = _arrayLikeToArray_21296(a0, value); r5 = value; } else { value3 = ({}).toString.call(a0).slice(8, -1); r6 = value3 === 'Object' && a0.constructor; r9 = r6 ? a0.constructor.name : value3; if (r9 === 'Map') { r6 = global.Array.from(a0); } else if (r9 === 'Set') { r6 = global.Array.from(a0); } else if (r9 === 'Arguments') { value = _arrayLikeToArray_21296(a0, value); r6 = value; } else { regexp = RegExp('^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$', ''); if (regexp.test(r9)) { value = _arrayLikeToArray_21296(a0, value); r6 = value; } else { r6 = value; } } r5 = r6; } } else { r5 = value; } if (r5) { if (r5) { } return _fun21295; } const TypeError = global.TypeError; throw new TypeError('Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'); function _fun21295() { // fn#21295, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:749, offset: 0x00c39d73, size: 69 bytes, params: 1, frame: 5 return env0_1 >= env0_0.length ? {done: true} : {done: false, value: env0_0[typeof env0_1 === 'bigint' ? env0_1 : +env0_1]}; } } function _isNativeReflectConstruct_21297() { // fn#21297, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:1088, offset: 0x00eed2e3, size: 94 bytes, params: 1, frame: 18 var Boolean; var prototype; var valueOf; var call; var Reflect; var construct; var closure; var value; var error; try { Boolean = global.Boolean; prototype = Boolean.prototype; valueOf = prototype.valueOf; call = valueOf.call; Reflect = global.Reflect; construct = Reflect.construct; Boolean = global.Boolean; closure = function() { }; value = Reflect.apply(construct, Reflect, [Boolean, [], closure]); value = Reflect.apply(call, valueOf, [value]); var result = !value; } catch (error) { } return (_isNativeReflectConstruct_21297_isNativeReflectConstruct = function() { return !!result; })(); } function _trySpeculativelyOpenDatabaseAsync() { // fn#21301, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:4788, offset: 0x00eed35e, size: 48 bytes, params: 1, frame: 14 return Module00005(_fun21303).apply(this, arguments); function* _fun21303(a0) { // fn#21303, original name: ?anon_0_, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:4879, offset: 0x00eed397, size: 155 bytes, params: 2, frame: 18 var binding2; var property; var value4; var Database; var open; var value5; var value6; var value7; var error; if (false) { return undefined; } value = environment.__proto__.__proto__; const value3 = env2_15(a0); let binding = env2_11; binding.verbose('speculatively opening ' + value3); try { binding = env2_0; } catch (error) { binding = env2_11; binding.warn("couldn't speculatively open database.", error); return null; } try { binding2 = env2_3; } catch (error) { binding = env2_11; binding.warn("couldn't speculatively open database.", error); return null; } try { property = binding2[10]; } catch (error) { binding = env2_11; binding.warn("couldn't speculatively open database.", error); return null; } try { value4 = binding(property); } catch (error) { binding = env2_11; binding.warn("couldn't speculatively open database.", error); return null; } try { Database = value4.Database; } catch (error) { binding = env2_11; binding.warn("couldn't speculatively open database.", error); return null; } try { open = Database.open; } catch (error) { binding = env2_11; binding.warn("couldn't speculatively open database.", error); return null; } try { value5 = Reflect.apply(open, Database, [value3]); } catch (error) { binding = env2_11; binding.warn("couldn't speculatively open database.", error); return null; } yield value5; try { value6 = undefined; value7 = false; } catch (error) { binding = env2_11; binding.warn("couldn't speculatively open database.", error); return null; } return value7 ? value6 : value6; } } function _fun21304(a0) { // fn#21304, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:1322, offset: 0x00eed432, size: 297 bytes, params: 2, frame: 17 const DatabaseManager2 = DatabaseManager; Inherits(DatabaseManager2, a0); const items2 = [{key: 'initialize', value: value_21310}]; items2[1] = {key: 'databaseName', value: function(a0) { return _databaseName(a0); }}; items2[2] = {key: 'database', value: function(a0) { var r0; var value2; var value = null; if (value != a0) { value2 = this.databases.get(a0); r0 = value != value2 ? value2 : value; } else { r0 = value; } return r0; }}; items2[3] = {key: 'carefullyOpenDatabase', value: value_21314}; items2[4] = {key: 'replaceDisableAllDatabases', value: value_21317}; items2[5] = {key: 'remove', value: value_21318}; items2[6] = {key: 'handleClearCaches', value: function(a0) { if (a0.preventWritingCachesAgainThisSession) { this.preventWritingCachesAgainThisSession = true; } this.replaceDisableAllDatabases('DatabaseManager (' + a0.reason + ')'); }}; items2[7] = {key: 'handleConnectionOpen', value: value_21320}; items2[8] = {key: 'handleAuthenticationStoreChanged', value: value_21321}; const env0_0 = Module00005(_fun21323); items2[9] = {key: 'carefullySpeculativelyOpen', value: value_21325}; return CreateClass(DatabaseManager2, items2); function DatabaseManager() { // fn#21305, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:1334, offset: 0x00eed55b, size: 263 bytes, params: 1, frame: 20 var environment; let value = environment.__proto__; env1_5(this, DatabaseManager); const items2 = [Dispatcher]; items2[1] = {CLEAR_CACHES: CLEAR_CACHES_21306, CONNECTION_CLOSED: CONNECTION_CLOSED_21307, CONNECTION_OPEN: CONNECTION_OPEN_21308, LOGOUT: LOGOUT_21309}; const DispatchBand = (DispatcherModule).DispatchBand; const Early = DispatchBand.Early; items2[2] = Early; const value3 = env1_8(DatabaseManager); value = env1_7(this, _isNativeReflectConstruct_21297() ? global.Reflect.construct(value3, items2, env1_8(this).constructor) : value3.apply(this, items2)); const Map = global.Map; const value4 = Object.create(Map.prototype, {constructor: {value: Map}}); const map = new Map(); value.databases = map instanceof Object ? map : value4; value.activeUserId = null; value.preventWritingCachesAgainThisSession = false; return value; function DatabaseManagerCLEAR_CACHES(a0) { // fn#21306, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:1578, owner: DatabaseManager.CLEAR_CACHES, offset: 0x00eed662, size: 25 bytes, params: 2, frame: 11 return env0_0.handleClearCaches(a0); } function DatabaseManagerCONNECTION_CLOSED() { // fn#21307, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:1622, owner: DatabaseManager.CONNECTION_CLOSED, offset: 0x00eed67b, size: 19 bytes, params: 1, frame: 9 return env0_0.handleAuthenticationStoreChanged(); } function DatabaseManagerCONNECTION_OPEN() { // fn#21308, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:1679, owner: DatabaseManager.CONNECTION_OPEN, offset: 0x00eed68e, size: 19 bytes, params: 1, frame: 9 return env0_0.handleConnectionOpen(); } function DatabaseManagerLOGOUT() { // fn#21309, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:1715, owner: DatabaseManager.LOGOUT, offset: 0x00eed67b, size: 19 bytes, params: 1, frame: 9 return env0_0.handleAuthenticationStoreChanged(); } } function value_21310() { // fn#21310, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:1941, offset: 0x00eed6a1, size: 100 bytes, params: 1, frame: 15 var environment; const waitFor = this.waitFor; let value = environment.__proto__; const authenticationStoreBinding = AuthenticationStore; Reflect.apply(waitFor, this, [authenticationStoreBinding]); const carefullySpeculativelyOpen = this.carefullySpeculativelyOpen; value = importAll(1927) /* metro dependency 1927: StartupDataNative */; const getUserId = value.getUserId; Reflect.apply(carefullySpeculativelyOpen, this, [Reflect.apply(getUserId, value, [])]); this.handleAuthenticationStoreChanged(); authenticationStoreBinding.addChangeListener(_fun21311); function _fun21311() { // fn#21311, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:2083, offset: 0x00eed67b, size: 19 bytes, params: 1, frame: 9 return env0_0.handleAuthenticationStoreChanged(); } } function value_21314(a0) { // fn#21314, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:2327, offset: 0x00eed747, size: 184 bytes, params: 2, frame: 20 var environment; var databases; var value; var value2; if (this.preventWritingCachesAgainThisSession) { value = environment.__proto__; env1_11.verbose('Not opening database because caches have been manually cleared.'); return null; } if (a0 != null) { databases = this.databases; if (!databases.has(a0)) { value = tryOpenDatabase(a0); value2 = environment.__proto__; env1_11.verbose('added database (' + a0 + ' → ' + value + ')'); this.databases.set(a0, value); this.emitChange(); } } return this.database(a0); function tryOpenDatabase(a0) { // fn#21315, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:2515, owner: value_21314.tryOpenDatabase, offset: 0x00eed7ff, size: 140 bytes, params: 2, frame: 23 var r0; var value4; var error; var error2; var value5; var value6; const value2 = _databaseName(a0); let binding = env2_11; const verbose = binding.verbose; let HermesInternal = global.HermesInternal; Reflect.apply(verbose, binding, ['synchronously opening ' + value2]); const closure = _fun21316; let r7 = 0; exceptionMain1: while (true) { try { value4 = closure(); } catch (error) { while (true) { binding = env2_11; error2 = binding.error; HermesInternal = global.HermesInternal; concat = HermesInternal.concat; Reflect.apply(error2, binding, ['tryUntil ' + r7, error]); value5 = typeof r7 === 'bigint' ? r7 + 1n : +r7 + 1; value6 = null; if (value5 < 50) { r7 = value5; break; } r0 = value6; continue; return r0; continue exceptionMain1; } } r0 = value4; return r0; } function _fun21316() { // fn#21316, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:2724, offset: 0x00eed88b, size: 61 bytes, params: 1, frame: 14 const Database = (JsModule).Database; return Database.openSyncUnsafe(env0_0, {invalidateDisabledHandles: true}); } } } function value_21317(a0) { // fn#21317, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:2954, offset: 0x00eed8c8, size: 189 bytes, params: 2, frame: 18 var r3; var value3; var value4; var value5; let value = environment.__proto__; env1_11.info('disabling and nulling all databases (reason: ' + a0 + ')'); const _createForOfIteratorHelperLoose_21294Binding = _createForOfIteratorHelperLoose_21294; let databases = this.databases; value = databases.keys(); value = _createForOfIteratorHelperLoose_21294Binding(value); const value2 = value(); let done = value2.done; if (!done) { r3 = value2; while (true) { value3 = r3.value; databases = this.databases; value4 = databases.get(value3); if (value4 != null) { value4.disable(a0); } if (value4 == null) { continue; } value4.close(); databases = this.databases; databases.set(value3, null); value5 = value(); done = value5.done; if (done) { break; } r3 = value5; continue; } } this.emitChange(); } function value_21318(a0) { // fn#21318, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:3256, offset: 0x00eed985, size: 127 bytes, params: 2, frame: 20 const value = this.databases.get(a0); env1_11.log('removing database (user: ' + a0 + ', database: ' + value + ')'); if (value != null) { value.close(); } this.databases.delete(a0); this.emitChange(); } function value_21320() { // fn#21320, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:3647, offset: 0x00eeda4f, size: 128 bytes, params: 1, frame: 16 const value = environment.__proto__; const id = AuthenticationStore.getId(); const value3 = this.databases.get(id); const value4 = undefined; if (value3 == null && (value3 == null ? value4 : value3.state()) !== (require(1911) /* metro dependency 1911: js */).DatabaseState.Open) { this.remove(id); } this.carefullyOpenDatabase(id); return value4; } function value_21321() { // fn#21321, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:3861, offset: 0x00eedacf, size: 189 bytes, params: 1, frame: 24 var databases; var value3; const value = environment.__proto__; const id = AuthenticationStore.getId(); const activeUserId = this.activeUserId; if (id !== activeUserId) { databases = this.databases; value3 = databases.get(activeUserId); env1_11.verbose('active user changed (now: ' + id + ', was: ' + activeUserId + ', was: ' + value3 + ')'); if (value3 != null) { value3.close(); } (importAll(1927) /* metro dependency 1927: StartupDataNative */).setUserId(id); this.activeUserId = id; databases = this.databases; databases.delete(activeUserId); } } function* _fun21323(a0) { // fn#21323, original name: ?anon_0_, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:4148, offset: 0x00eedb95, size: 285 bytes, params: 2, frame: 22 var environment; var databases; var value4; var value5; let value = undefined; if (false) { return value; } if (this.preventWritingCachesAgainThisSession) { value = environment.__proto__.__proto__; env2_11.verbose('Not opening database because caches have been manually cleared.'); } else { if (a0 == null) { return undefined; } yield trySpeculativelyOpenDatabaseAsync(a0); value = undefined; if (false) { return value; } if (value == null) { value5 = environment.__proto__.__proto__; env2_11.verbose('discarding speculative database (' + a0 + ' → ' + value + ')'); if (value != null) { value.close(); } } else { databases = this.databases; if (databases.has(a0)) { value5 = environment.__proto__.__proto__; env2_11.verbose('discarding speculative database (' + a0 + ' → ' + value + ')'); if (value != null) { value.close(); } } else { value4 = environment.__proto__.__proto__; env2_11.verbose('added speculative database (' + a0 + ' → ' + value + ')'); this.databases.set(a0, value); this.emitChange(); } } } function trySpeculativelyOpenDatabaseAsync() { // fn#21324, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:4312, offset: 0x00eedcb2, size: 30 bytes, params: 1, frame: 13 return env3_16.apply(this, arguments); } } function value_21325() { // fn#21325, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:2053:4642, offset: 0x00c3945f, size: 30 bytes, params: 1, frame: 13 return env0_0.apply(this, arguments); } } } global.__d(_fun21293, 1926, [5, 6, 7, 15, 17, 18, 1226, 3, 694, 1927, 1911, 566, 2]) /* metro module 1926, dependencies: [5, 6, 7, 15, 17, 18, 1226, 3, 694, 1927, 1911, 566, 2] */;