diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp index 201ce2f95..8db8c0ed4 100644 --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp @@ -1,1409 +1,1419 @@ #include "SQLiteQueryExecutor.h" #include "Logger.h" #include "sqlite_orm.h" #include "entities/Metadata.h" #include "entities/UserInfo.h" #include #include #include #ifndef EMSCRIPTEN #include "CommSecureStore.h" #endif #define ACCOUNT_ID 1 namespace comm { using namespace sqlite_orm; std::string SQLiteQueryExecutor::sqliteFilePath; std::string SQLiteQueryExecutor::encryptionKey; std::once_flag SQLiteQueryExecutor::initialized; int SQLiteQueryExecutor::sqlcipherEncryptionKeySize = 64; std::string SQLiteQueryExecutor::secureStoreEncryptionKeyID = "comm.encryptionKey"; bool create_table(sqlite3 *db, std::string query, std::string tableName) { char *error; sqlite3_exec(db, query.c_str(), nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream stringStream; stringStream << "Error creating '" << tableName << "' table: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } bool create_drafts_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS drafts (threadID TEXT UNIQUE PRIMARY KEY, " "text TEXT);"; return create_table(db, query, "drafts"); } bool rename_threadID_to_key(sqlite3 *db) { sqlite3_stmt *key_column_stmt; sqlite3_prepare_v2( db, "SELECT name AS col_name FROM pragma_table_xinfo ('drafts') WHERE " "col_name='key';", -1, &key_column_stmt, nullptr); sqlite3_step(key_column_stmt); auto num_bytes = sqlite3_column_bytes(key_column_stmt, 0); sqlite3_finalize(key_column_stmt); if (num_bytes) { return true; } char *error; sqlite3_exec( db, "ALTER TABLE drafts RENAME COLUMN `threadID` TO `key`;", nullptr, nullptr, &error); if (error) { std::ostringstream stringStream; stringStream << "Error occurred renaming threadID column in drafts table " << "to key: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } return true; } bool create_persist_account_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS olm_persist_account(" "id INTEGER UNIQUE PRIMARY KEY NOT NULL, " "account_data TEXT NOT NULL);"; return create_table(db, query, "olm_persist_account"); } bool create_persist_sessions_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS olm_persist_sessions(" "target_user_id TEXT UNIQUE PRIMARY KEY NOT NULL, " "session_data TEXT NOT NULL);"; return create_table(db, query, "olm_persist_sessions"); } bool drop_messages_table(sqlite3 *db) { char *error; sqlite3_exec(db, "DROP TABLE IF EXISTS messages;", nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream stringStream; stringStream << "Error dropping 'messages' table: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } bool recreate_messages_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS messages ( " "id TEXT UNIQUE PRIMARY KEY NOT NULL, " "local_id TEXT, " "thread TEXT NOT NULL, " "user TEXT NOT NULL, " "type INTEGER NOT NULL, " "future_type INTEGER, " "content TEXT, " "time INTEGER NOT NULL);"; return create_table(db, query, "messages"); } bool create_messages_idx_thread_time(sqlite3 *db) { char *error; sqlite3_exec( db, "CREATE INDEX IF NOT EXISTS messages_idx_thread_time " "ON messages (thread, time);", nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream stringStream; stringStream << "Error creating (thread, time) index on messages table: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } bool create_media_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS media ( " "id TEXT UNIQUE PRIMARY KEY NOT NULL, " "container TEXT NOT NULL, " "thread TEXT NOT NULL, " "uri TEXT NOT NULL, " "type TEXT NOT NULL, " "extras TEXT NOT NULL);"; return create_table(db, query, "media"); } bool create_media_idx_container(sqlite3 *db) { char *error; sqlite3_exec( db, "CREATE INDEX IF NOT EXISTS media_idx_container " "ON media (container);", nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream stringStream; stringStream << "Error creating (container) index on media table: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } bool create_threads_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS threads ( " "id TEXT UNIQUE PRIMARY KEY NOT NULL, " "type INTEGER NOT NULL, " "name TEXT, " "description TEXT, " "color TEXT NOT NULL, " "creation_time BIGINT NOT NULL, " "parent_thread_id TEXT, " "containing_thread_id TEXT, " "community TEXT, " "members TEXT NOT NULL, " "roles TEXT NOT NULL, " "current_user TEXT NOT NULL, " "source_message_id TEXT, " "replies_count INTEGER NOT NULL);"; return create_table(db, query, "threads"); } bool update_threadID_for_pending_threads_in_drafts(sqlite3 *db) { char *error; sqlite3_exec( db, "UPDATE drafts SET key = " "REPLACE(REPLACE(REPLACE(REPLACE(key, 'type4/', '')," "'type5/', ''),'type6/', ''),'type7/', '')" "WHERE key LIKE 'pending/%'", nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream stringStream; stringStream << "Error update pending threadIDs on drafts table: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } bool enable_write_ahead_logging_mode(sqlite3 *db) { char *error; sqlite3_exec(db, "PRAGMA journal_mode=wal;", nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream stringStream; stringStream << "Error enabling write-ahead logging mode: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } bool create_metadata_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS metadata ( " "name TEXT UNIQUE PRIMARY KEY NOT NULL, " "data TEXT);"; return create_table(db, query, "metadata"); } bool add_not_null_constraint_to_drafts(sqlite3 *db) { char *error; sqlite3_exec( db, "CREATE TABLE IF NOT EXISTS temporary_drafts (" "key TEXT UNIQUE PRIMARY KEY NOT NULL, " "text TEXT NOT NULL);" "INSERT INTO temporary_drafts SELECT * FROM drafts " "WHERE key IS NOT NULL AND text IS NOT NULL;" "DROP TABLE drafts;" "ALTER TABLE temporary_drafts RENAME TO drafts;", nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream stringStream; stringStream << "Error adding NOT NULL constraint to drafts table: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } bool add_not_null_constraint_to_metadata(sqlite3 *db) { char *error; sqlite3_exec( db, "CREATE TABLE IF NOT EXISTS temporary_metadata (" "name TEXT UNIQUE PRIMARY KEY NOT NULL, " "data TEXT NOT NULL);" "INSERT INTO temporary_metadata SELECT * FROM metadata " "WHERE data IS NOT NULL;" "DROP TABLE metadata;" "ALTER TABLE temporary_metadata RENAME TO metadata;", nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream stringStream; stringStream << "Error adding NOT NULL constraint to metadata table: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } bool add_avatar_column_to_threads_table(sqlite3 *db) { char *error; sqlite3_exec( db, "ALTER TABLE threads ADD COLUMN avatar TEXT;", nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream stringStream; stringStream << "Error adding avatar column to threads table: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } bool add_pinned_count_column_to_threads(sqlite3 *db) { sqlite3_stmt *pinned_column_stmt; sqlite3_prepare_v2( db, "SELECT name AS col_name FROM pragma_table_xinfo ('threads') WHERE " "col_name='pinned_count';", -1, &pinned_column_stmt, nullptr); sqlite3_step(pinned_column_stmt); auto num_bytes = sqlite3_column_bytes(pinned_column_stmt, 0); sqlite3_finalize(pinned_column_stmt); if (num_bytes) { return true; } char *error; sqlite3_exec( db, "ALTER TABLE threads ADD COLUMN pinned_count INTEGER NOT NULL DEFAULT 0;", nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream stringStream; stringStream << "Error adding pinned_count column to threads table: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } bool create_message_store_threads_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS message_store_threads (" " id TEXT UNIQUE PRIMARY KEY NOT NULL," " start_reached INTEGER NOT NULL," " last_navigated_to BIGINT NOT NULL," " last_pruned BIGINT NOT NULL" ");"; return create_table(db, query, "message_store_threads"); } bool create_reports_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS reports (" " id TEXT UNIQUE PRIMARY KEY NOT NULL," " report TEXT NOT NULL" ");"; return create_table(db, query, "reports"); } bool create_persist_storage_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS persist_storage (" " key TEXT UNIQUE PRIMARY KEY NOT NULL," " item TEXT NOT NULL" ");"; return create_table(db, query, "persist_storage"); } bool recreate_message_store_threads_table(sqlite3 *db) { char *errMsg = 0; // 1. Create table without `last_navigated_to` or `last_pruned`. std::string create_new_table_query = "CREATE TABLE IF NOT EXISTS temp_message_store_threads (" " id TEXT UNIQUE PRIMARY KEY NOT NULL," " start_reached INTEGER NOT NULL" ");"; if (sqlite3_exec(db, create_new_table_query.c_str(), NULL, NULL, &errMsg) != SQLITE_OK) { Logger::log( "Error creating temp_message_store_threads: " + std::string{errMsg}); sqlite3_free(errMsg); return false; } // 2. Dump data from existing `message_store_threads` table into temp table. std::string copy_data_query = "INSERT INTO temp_message_store_threads (id, start_reached)" "SELECT id, start_reached FROM message_store_threads;"; if (sqlite3_exec(db, copy_data_query.c_str(), NULL, NULL, &errMsg) != SQLITE_OK) { Logger::log( "Error dumping data from existing message_store_threads to " "temp_message_store_threads: " + std::string{errMsg}); sqlite3_free(errMsg); return false; } // 3. Drop the existing `message_store_threads` table. std::string drop_old_table_query = "DROP TABLE message_store_threads;"; if (sqlite3_exec(db, drop_old_table_query.c_str(), NULL, NULL, &errMsg) != SQLITE_OK) { Logger::log( "Error dropping message_store_threads table: " + std::string{errMsg}); sqlite3_free(errMsg); return false; } // 4. Rename the temp table back to `message_store_threads`. std::string rename_table_query = "ALTER TABLE temp_message_store_threads RENAME TO message_store_threads;"; if (sqlite3_exec(db, rename_table_query.c_str(), NULL, NULL, &errMsg) != SQLITE_OK) { Logger::log( "Error renaming temp_message_store_threads to message_store_threads: " + std::string{errMsg}); sqlite3_free(errMsg); return false; } return true; } bool create_users_table(sqlite3 *db) { std::string query = "CREATE TABLE IF NOT EXISTS users (" " id TEXT UNIQUE PRIMARY KEY NOT NULL," " user_info TEXT NOT NULL" ");"; return create_table(db, query, "users"); } bool create_schema(sqlite3 *db) { char *error; sqlite3_exec( db, "CREATE TABLE IF NOT EXISTS drafts (" " key TEXT UNIQUE PRIMARY KEY NOT NULL," " text TEXT NOT NULL" ");" "CREATE TABLE IF NOT EXISTS messages (" " id TEXT UNIQUE PRIMARY KEY NOT NULL," " local_id TEXT," " thread TEXT NOT NULL," " user TEXT NOT NULL," " type INTEGER NOT NULL," " future_type INTEGER," " content TEXT," " time INTEGER NOT NULL" ");" "CREATE TABLE IF NOT EXISTS olm_persist_account (" " id INTEGER UNIQUE PRIMARY KEY NOT NULL," " account_data TEXT NOT NULL" ");" "CREATE TABLE IF NOT EXISTS olm_persist_sessions (" " target_user_id TEXT UNIQUE PRIMARY KEY NOT NULL," " session_data TEXT NOT NULL" ");" "CREATE TABLE IF NOT EXISTS media (" " id TEXT UNIQUE PRIMARY KEY NOT NULL," " container TEXT NOT NULL," " thread TEXT NOT NULL," " uri TEXT NOT NULL," " type TEXT NOT NULL," " extras TEXT NOT NULL" ");" "CREATE TABLE IF NOT EXISTS threads (" " id TEXT UNIQUE PRIMARY KEY NOT NULL," " type INTEGER NOT NULL," " name TEXT," " description TEXT," " color TEXT NOT NULL," " creation_time BIGINT NOT NULL," " parent_thread_id TEXT," " containing_thread_id TEXT," " community TEXT," " members TEXT NOT NULL," " roles TEXT NOT NULL," " current_user TEXT NOT NULL," " source_message_id TEXT," " replies_count INTEGER NOT NULL," " avatar TEXT," " pinned_count INTEGER NOT NULL DEFAULT 0" ");" "CREATE TABLE IF NOT EXISTS metadata (" " name TEXT UNIQUE PRIMARY KEY NOT NULL," " data TEXT NOT NULL" ");" "CREATE TABLE IF NOT EXISTS message_store_threads (" " id TEXT UNIQUE PRIMARY KEY NOT NULL," " start_reached INTEGER NOT NULL" ");" "CREATE TABLE IF NOT EXISTS reports (" " id TEXT UNIQUE PRIMARY KEY NOT NULL," " report TEXT NOT NULL" ");" "CREATE TABLE IF NOT EXISTS persist_storage (" " key TEXT UNIQUE PRIMARY KEY NOT NULL," " item TEXT NOT NULL" ");" "CREATE TABLE IF NOT EXISTS users (" " id TEXT UNIQUE PRIMARY KEY NOT NULL," " user_info TEXT NOT NULL" ");" "CREATE INDEX IF NOT EXISTS media_idx_container" " ON media (container);" "CREATE INDEX IF NOT EXISTS messages_idx_thread_time" " ON messages (thread, time);", nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream stringStream; stringStream << "Error creating tables: " << error; Logger::log(stringStream.str()); sqlite3_free(error); return false; } void set_encryption_key(sqlite3 *db) { std::string set_encryption_key_query = "PRAGMA key = \"x'" + SQLiteQueryExecutor::encryptionKey + "'\";"; char *error_set_key; sqlite3_exec( db, set_encryption_key_query.c_str(), nullptr, nullptr, &error_set_key); if (error_set_key) { std::ostringstream error_message; error_message << "Failed to set encryption key: " << error_set_key; throw std::system_error( ECANCELED, std::generic_category(), error_message.str()); } } int get_database_version(sqlite3 *db) { sqlite3_stmt *user_version_stmt; sqlite3_prepare_v2( db, "PRAGMA user_version;", -1, &user_version_stmt, nullptr); sqlite3_step(user_version_stmt); int current_user_version = sqlite3_column_int(user_version_stmt, 0); sqlite3_finalize(user_version_stmt); return current_user_version; } bool set_database_version(sqlite3 *db, int db_version) { std::stringstream update_version; update_version << "PRAGMA user_version=" << db_version << ";"; auto update_version_str = update_version.str(); char *error; sqlite3_exec(db, update_version_str.c_str(), nullptr, nullptr, &error); if (!error) { return true; } std::ostringstream errorStream; errorStream << "Error setting database version to " << db_version << ": " << error; Logger::log(errorStream.str()); sqlite3_free(error); return false; } void trace_queries(sqlite3 *db) { int error_code = sqlite3_trace_v2( db, SQLITE_TRACE_PROFILE, [](unsigned, void *, void *preparedStatement, void *) { sqlite3_stmt *statement = (sqlite3_stmt *)preparedStatement; char *sql = sqlite3_expanded_sql(statement); if (sql != nullptr) { std::string sqlStr(sql); // TODO: send logs to backup here } return 0; }, NULL); if (error_code != SQLITE_OK) { std::ostringstream error_message; error_message << "Failed to set trace callback, error code: " << error_code; throw std::system_error( ECANCELED, std::generic_category(), error_message.str()); } } +// We don't want to run `PRAGMA key = ...;` +// on main web database. The context is here: +// https://linear.app/comm/issue/ENG-6398/issues-with-sqlcipher-on-web void on_database_open(sqlite3 *db) { +#ifndef EMSCRIPTEN set_encryption_key(db); +#endif trace_queries(db); } bool file_exists(const std::string &file_path) { std::ifstream file(file_path.c_str()); return file.good(); } void attempt_delete_file( const std::string &file_path, const char *error_message) { if (std::remove(file_path.c_str())) { throw std::system_error(errno, std::generic_category(), error_message); } } void attempt_rename_file( const std::string &old_path, const std::string &new_path, const char *error_message) { if (std::rename(old_path.c_str(), new_path.c_str())) { throw std::system_error(errno, std::generic_category(), error_message); } } bool is_database_queryable(sqlite3 *db, bool use_encryption_key) { char *err_msg; sqlite3_open(SQLiteQueryExecutor::sqliteFilePath.c_str(), &db); // According to SQLCipher documentation running some SELECT is the only way to // check for key validity if (use_encryption_key) { set_encryption_key(db); } sqlite3_exec( db, "SELECT COUNT(*) FROM sqlite_master;", nullptr, nullptr, &err_msg); sqlite3_close(db); return !err_msg; } void validate_encryption() { std::string temp_encrypted_db_path = SQLiteQueryExecutor::sqliteFilePath + "_temp_encrypted"; bool temp_encrypted_exists = file_exists(temp_encrypted_db_path); bool default_location_exists = file_exists(SQLiteQueryExecutor::sqliteFilePath); if (temp_encrypted_exists && default_location_exists) { Logger::log( "Previous encryption attempt failed. Repeating encryption process from " "the beginning."); attempt_delete_file( temp_encrypted_db_path, "Failed to delete corrupted encrypted database."); } else if (temp_encrypted_exists && !default_location_exists) { Logger::log( "Moving temporary encrypted database to default location failed in " "previous encryption attempt. Repeating rename step."); attempt_rename_file( temp_encrypted_db_path, SQLiteQueryExecutor::sqliteFilePath, "Failed to move encrypted database to default location."); return; } else if (!default_location_exists) { Logger::log( "Database not present yet. It will be created encrypted under default " "path."); return; } sqlite3 *db; if (is_database_queryable(db, true)) { Logger::log( "Database exists under default path and it is correctly encrypted."); return; } if (!is_database_queryable(db, false)) { Logger::log( "Database exists but it is encrypted with key that was lost. " "Attempting database deletion. New encrypted one will be created."); attempt_delete_file( SQLiteQueryExecutor::sqliteFilePath.c_str(), "Failed to delete database encrypted with lost key."); return; } else { Logger::log( "Database exists but it is not encrypted. Attempting encryption " "process."); } sqlite3_open(SQLiteQueryExecutor::sqliteFilePath.c_str(), &db); std::string createEncryptedCopySQL = "ATTACH DATABASE '" + temp_encrypted_db_path + "' AS encrypted_comm " "KEY \"x'" + SQLiteQueryExecutor::encryptionKey + "'\";" "SELECT sqlcipher_export('encrypted_comm');" "DETACH DATABASE encrypted_comm;"; char *encryption_error; sqlite3_exec( db, createEncryptedCopySQL.c_str(), nullptr, nullptr, &encryption_error); if (encryption_error) { throw std::system_error( ECANCELED, std::generic_category(), "Failed to create encrypted copy of the original database."); } sqlite3_close(db); attempt_delete_file( SQLiteQueryExecutor::sqliteFilePath, "Failed to delete unencrypted database."); attempt_rename_file( temp_encrypted_db_path, SQLiteQueryExecutor::sqliteFilePath, "Failed to move encrypted database to default location."); Logger::log("Encryption completed successfully."); } typedef bool ShouldBeInTransaction; typedef std::function MigrateFunction; typedef std::pair SQLiteMigration; std::vector> migrations{ {{1, {create_drafts_table, true}}, {2, {rename_threadID_to_key, true}}, {4, {create_persist_account_table, true}}, {5, {create_persist_sessions_table, true}}, {15, {create_media_table, true}}, {16, {drop_messages_table, true}}, {17, {recreate_messages_table, true}}, {18, {create_messages_idx_thread_time, true}}, {19, {create_media_idx_container, true}}, {20, {create_threads_table, true}}, {21, {update_threadID_for_pending_threads_in_drafts, true}}, {22, {enable_write_ahead_logging_mode, false}}, {23, {create_metadata_table, true}}, {24, {add_not_null_constraint_to_drafts, true}}, {25, {add_not_null_constraint_to_metadata, true}}, {26, {add_avatar_column_to_threads_table, true}}, {27, {add_pinned_count_column_to_threads, true}}, {28, {create_message_store_threads_table, true}}, {29, {create_reports_table, true}}, {30, {create_persist_storage_table, true}}, {31, {recreate_message_store_threads_table, true}}, {32, {create_users_table, true}}}}; enum class MigrationResult { SUCCESS, FAILURE, NOT_APPLIED }; MigrationResult applyMigrationWithTransaction( sqlite3 *db, const MigrateFunction &migrate, int index) { sqlite3_exec(db, "BEGIN TRANSACTION;", nullptr, nullptr, nullptr); auto db_version = get_database_version(db); if (index <= db_version) { sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr); return MigrationResult::NOT_APPLIED; } auto rc = migrate(db); if (!rc) { sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr); return MigrationResult::FAILURE; } auto database_version_set = set_database_version(db, index); if (!database_version_set) { sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr); return MigrationResult::FAILURE; } sqlite3_exec(db, "END TRANSACTION;", nullptr, nullptr, nullptr); return MigrationResult::SUCCESS; } MigrationResult applyMigrationWithoutTransaction( sqlite3 *db, const MigrateFunction &migrate, int index) { auto db_version = get_database_version(db); if (index <= db_version) { return MigrationResult::NOT_APPLIED; } auto rc = migrate(db); if (!rc) { return MigrationResult::FAILURE; } sqlite3_exec(db, "BEGIN TRANSACTION;", nullptr, nullptr, nullptr); auto inner_db_version = get_database_version(db); if (index <= inner_db_version) { sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr); return MigrationResult::NOT_APPLIED; } auto database_version_set = set_database_version(db, index); if (!database_version_set) { sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr); return MigrationResult::FAILURE; } sqlite3_exec(db, "END TRANSACTION;", nullptr, nullptr, nullptr); return MigrationResult::SUCCESS; } bool set_up_database(sqlite3 *db) { auto write_ahead_enabled = enable_write_ahead_logging_mode(db); if (!write_ahead_enabled) { return false; } sqlite3_exec(db, "BEGIN TRANSACTION;", nullptr, nullptr, nullptr); auto db_version = get_database_version(db); auto latest_version = migrations.back().first; if (db_version == latest_version) { sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr); return true; } if (db_version != 0 || !create_schema(db) || !set_database_version(db, latest_version)) { sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr); return false; } sqlite3_exec(db, "END TRANSACTION;", nullptr, nullptr, nullptr); return true; } void SQLiteQueryExecutor::migrate() { +// We don't want to run `PRAGMA key = ...;` +// on main web database. The context is here: +// https://linear.app/comm/issue/ENG-6398/issues-with-sqlcipher-on-web +#ifndef EMSCRIPTEN validate_encryption(); +#endif sqlite3 *db; sqlite3_open(SQLiteQueryExecutor::sqliteFilePath.c_str(), &db); on_database_open(db); std::stringstream db_path; db_path << "db path: " << SQLiteQueryExecutor::sqliteFilePath.c_str() << std::endl; Logger::log(db_path.str()); auto db_version = get_database_version(db); std::stringstream version_msg; version_msg << "db version: " << db_version << std::endl; Logger::log(version_msg.str()); if (db_version == 0) { auto db_created = set_up_database(db); if (!db_created) { sqlite3_close(db); Logger::log("Database structure creation error."); throw std::runtime_error("Database structure creation error"); } Logger::log("Database structure created."); sqlite3_close(db); return; } for (const auto &[idx, migration] : migrations) { const auto &[applyMigration, shouldBeInTransaction] = migration; MigrationResult migrationResult; if (shouldBeInTransaction) { migrationResult = applyMigrationWithTransaction(db, applyMigration, idx); } else { migrationResult = applyMigrationWithoutTransaction(db, applyMigration, idx); } if (migrationResult == MigrationResult::NOT_APPLIED) { continue; } std::stringstream migration_msg; if (migrationResult == MigrationResult::FAILURE) { migration_msg << "migration " << idx << " failed." << std::endl; Logger::log(migration_msg.str()); sqlite3_close(db); throw std::runtime_error(migration_msg.str()); } if (migrationResult == MigrationResult::SUCCESS) { migration_msg << "migration " << idx << " succeeded." << std::endl; Logger::log(migration_msg.str()); } } sqlite3_close(db); } auto &SQLiteQueryExecutor::getStorage() { static auto storage = make_storage( SQLiteQueryExecutor::sqliteFilePath, make_index("messages_idx_thread_time", &Message::thread, &Message::time), make_index("media_idx_container", &Media::container), make_table( "drafts", make_column("key", &Draft::key, unique(), primary_key()), make_column("text", &Draft::text)), make_table( "messages", make_column("id", &Message::id, unique(), primary_key()), make_column("local_id", &Message::local_id), make_column("thread", &Message::thread), make_column("user", &Message::user), make_column("type", &Message::type), make_column("future_type", &Message::future_type), make_column("content", &Message::content), make_column("time", &Message::time)), make_table( "olm_persist_account", make_column("id", &OlmPersistAccount::id, unique(), primary_key()), make_column("account_data", &OlmPersistAccount::account_data)), make_table( "olm_persist_sessions", make_column( "target_user_id", &OlmPersistSession::target_user_id, unique(), primary_key()), make_column("session_data", &OlmPersistSession::session_data)), make_table( "media", make_column("id", &Media::id, unique(), primary_key()), make_column("container", &Media::container), make_column("thread", &Media::thread), make_column("uri", &Media::uri), make_column("type", &Media::type), make_column("extras", &Media::extras)), make_table( "threads", make_column("id", &Thread::id, unique(), primary_key()), make_column("type", &Thread::type), make_column("name", &Thread::name), make_column("description", &Thread::description), make_column("color", &Thread::color), make_column("creation_time", &Thread::creation_time), make_column("parent_thread_id", &Thread::parent_thread_id), make_column("containing_thread_id", &Thread::containing_thread_id), make_column("community", &Thread::community), make_column("members", &Thread::members), make_column("roles", &Thread::roles), make_column("current_user", &Thread::current_user), make_column("source_message_id", &Thread::source_message_id), make_column("replies_count", &Thread::replies_count), make_column("avatar", &Thread::avatar), make_column("pinned_count", &Thread::pinned_count, default_value(0))), make_table( "metadata", make_column("name", &Metadata::name, unique(), primary_key()), make_column("data", &Metadata::data)), make_table( "message_store_threads", make_column("id", &MessageStoreThread::id, unique(), primary_key()), make_column("start_reached", &MessageStoreThread::start_reached)), make_table( "reports", make_column("id", &Report::id, unique(), primary_key()), make_column("report", &Report::report)), make_table( "persist_storage", make_column("key", &PersistItem::key, unique(), primary_key()), make_column("item", &PersistItem::item)), make_table( "users", make_column("id", &UserInfo::id, unique(), primary_key()), make_column("user_info", &UserInfo::user_info)) ); storage.on_open = on_database_open; return storage; } SQLiteQueryExecutor::SQLiteQueryExecutor() { SQLiteQueryExecutor::migrate(); } SQLiteQueryExecutor::SQLiteQueryExecutor(std::string sqliteFilePath) { SQLiteQueryExecutor::sqliteFilePath = sqliteFilePath; SQLiteQueryExecutor::migrate(); } std::string SQLiteQueryExecutor::getDraft(std::string key) const { std::unique_ptr draft = SQLiteQueryExecutor::getStorage().get_pointer(key); return (draft == nullptr) ? "" : draft->text; } std::unique_ptr SQLiteQueryExecutor::getThread(std::string threadID) const { return SQLiteQueryExecutor::getStorage().get_pointer(threadID); } void SQLiteQueryExecutor::updateDraft(std::string key, std::string text) const { Draft draft = {key, text}; SQLiteQueryExecutor::getStorage().replace(draft); } bool SQLiteQueryExecutor::moveDraft(std::string oldKey, std::string newKey) const { std::unique_ptr draft = SQLiteQueryExecutor::getStorage().get_pointer(oldKey); if (draft == nullptr) { return false; } draft->key = newKey; SQLiteQueryExecutor::getStorage().replace(*draft); SQLiteQueryExecutor::getStorage().remove(oldKey); return true; } std::vector SQLiteQueryExecutor::getAllDrafts() const { return SQLiteQueryExecutor::getStorage().get_all(); } void SQLiteQueryExecutor::removeAllDrafts() const { SQLiteQueryExecutor::getStorage().remove_all(); } void SQLiteQueryExecutor::removeAllMessages() const { SQLiteQueryExecutor::getStorage().remove_all(); } std::vector>> SQLiteQueryExecutor::getAllMessages() const { auto rows = SQLiteQueryExecutor::getStorage().select( columns( &Message::id, &Message::local_id, &Message::thread, &Message::user, &Message::type, &Message::future_type, &Message::content, &Message::time, &Media::id, &Media::container, &Media::thread, &Media::uri, &Media::type, &Media::extras), left_join(on(c(&Message::id) == &Media::container)), order_by(&Message::id)); std::vector>> allMessages; allMessages.reserve(rows.size()); std::string prev_msg_idx{}; for (auto &row : rows) { auto msg_id = std::get<0>(row); if (msg_id == prev_msg_idx) { allMessages.back().second.push_back(Media{ std::get<8>(row), std::move(std::get<9>(row)), std::move(std::get<10>(row)), std::move(std::get<11>(row)), std::move(std::get<12>(row)), std::move(std::get<13>(row)), }); } else { std::vector mediaForMsg; if (!std::get<8>(row).empty()) { mediaForMsg.push_back(Media{ std::get<8>(row), std::move(std::get<9>(row)), std::move(std::get<10>(row)), std::move(std::get<11>(row)), std::move(std::get<12>(row)), std::move(std::get<13>(row)), }); } allMessages.push_back(std::make_pair( Message{ msg_id, std::move(std::get<1>(row)), std::move(std::get<2>(row)), std::move(std::get<3>(row)), std::get<4>(row), std::move(std::get<5>(row)), std::move(std::get<6>(row)), std::get<7>(row)}, mediaForMsg)); prev_msg_idx = msg_id; } } return allMessages; } void SQLiteQueryExecutor::removeMessages( const std::vector &ids) const { SQLiteQueryExecutor::getStorage().remove_all( where(in(&Message::id, ids))); } void SQLiteQueryExecutor::removeMessagesForThreads( const std::vector &threadIDs) const { SQLiteQueryExecutor::getStorage().remove_all( where(in(&Message::thread, threadIDs))); } void SQLiteQueryExecutor::replaceMessage(const Message &message) const { SQLiteQueryExecutor::getStorage().replace(message); } void SQLiteQueryExecutor::rekeyMessage(std::string from, std::string to) const { auto msg = SQLiteQueryExecutor::getStorage().get(from); msg.id = to; SQLiteQueryExecutor::getStorage().replace(msg); SQLiteQueryExecutor::getStorage().remove(from); } void SQLiteQueryExecutor::removeAllMedia() const { SQLiteQueryExecutor::getStorage().remove_all(); } void SQLiteQueryExecutor::removeMediaForMessages( const std::vector &msg_ids) const { SQLiteQueryExecutor::getStorage().remove_all( where(in(&Media::container, msg_ids))); } void SQLiteQueryExecutor::removeMediaForMessage(std::string msg_id) const { SQLiteQueryExecutor::getStorage().remove_all( where(c(&Media::container) == msg_id)); } void SQLiteQueryExecutor::removeMediaForThreads( const std::vector &thread_ids) const { SQLiteQueryExecutor::getStorage().remove_all( where(in(&Media::thread, thread_ids))); } void SQLiteQueryExecutor::replaceMedia(const Media &media) const { SQLiteQueryExecutor::getStorage().replace(media); } void SQLiteQueryExecutor::rekeyMediaContainers(std::string from, std::string to) const { SQLiteQueryExecutor::getStorage().update_all( set(c(&Media::container) = to), where(c(&Media::container) == from)); } void SQLiteQueryExecutor::replaceMessageStoreThreads( const std::vector &threads) const { for (auto &thread : threads) { SQLiteQueryExecutor::getStorage().replace(thread); } } void SQLiteQueryExecutor::removeAllMessageStoreThreads() const { SQLiteQueryExecutor::getStorage().remove_all(); } void SQLiteQueryExecutor::removeMessageStoreThreads( const std::vector &ids) const { SQLiteQueryExecutor::getStorage().remove_all( where(in(&MessageStoreThread::id, ids))); } std::vector SQLiteQueryExecutor::getAllMessageStoreThreads() const { return SQLiteQueryExecutor::getStorage().get_all(); } std::vector SQLiteQueryExecutor::getAllThreads() const { return SQLiteQueryExecutor::getStorage().get_all(); }; void SQLiteQueryExecutor::removeThreads(std::vector ids) const { SQLiteQueryExecutor::getStorage().remove_all( where(in(&Thread::id, ids))); }; void SQLiteQueryExecutor::replaceThread(const Thread &thread) const { SQLiteQueryExecutor::getStorage().replace(thread); }; void SQLiteQueryExecutor::removeAllThreads() const { SQLiteQueryExecutor::getStorage().remove_all(); }; void SQLiteQueryExecutor::replaceReport(const Report &report) const { SQLiteQueryExecutor::getStorage().replace(report); } void SQLiteQueryExecutor::removeAllReports() const { SQLiteQueryExecutor::getStorage().remove_all(); } void SQLiteQueryExecutor::removeReports( const std::vector &ids) const { SQLiteQueryExecutor::getStorage().remove_all( where(in(&Report::id, ids))); } std::vector SQLiteQueryExecutor::getAllReports() const { return SQLiteQueryExecutor::getStorage().get_all(); } void SQLiteQueryExecutor::setPersistStorageItem( std::string key, std::string item) const { PersistItem entry{ key, item, }; SQLiteQueryExecutor::getStorage().replace(entry); } void SQLiteQueryExecutor::removePersistStorageItem(std::string key) const { SQLiteQueryExecutor::getStorage().remove(key); } std::string SQLiteQueryExecutor::getPersistStorageItem(std::string key) const { std::unique_ptr entry = SQLiteQueryExecutor::getStorage().get_pointer(key); return (entry == nullptr) ? "" : entry->item; } void SQLiteQueryExecutor::replaceUser(const UserInfo &user_info) const { SQLiteQueryExecutor::getStorage().replace(user_info); } void SQLiteQueryExecutor::removeAllUsers() const { SQLiteQueryExecutor::getStorage().remove_all(); } void SQLiteQueryExecutor::removeUsers( const std::vector &ids) const { SQLiteQueryExecutor::getStorage().remove_all( where(in(&UserInfo::id, ids))); } std::vector SQLiteQueryExecutor::getAllUsers() const { return SQLiteQueryExecutor::getStorage().get_all(); } void SQLiteQueryExecutor::beginTransaction() const { SQLiteQueryExecutor::getStorage().begin_transaction(); } void SQLiteQueryExecutor::commitTransaction() const { SQLiteQueryExecutor::getStorage().commit(); } void SQLiteQueryExecutor::rollbackTransaction() const { SQLiteQueryExecutor::getStorage().rollback(); } std::vector SQLiteQueryExecutor::getOlmPersistSessionsData() const { return SQLiteQueryExecutor::getStorage().get_all(); } std::optional SQLiteQueryExecutor::getOlmPersistAccountData() const { std::vector result = SQLiteQueryExecutor::getStorage().get_all(); if (result.size() > 1) { throw std::system_error( ECANCELED, std::generic_category(), "Multiple records found for the olm_persist_account table"); } return (result.size() == 0) ? std::nullopt : std::optional(result[0].account_data); } void SQLiteQueryExecutor::storeOlmPersistData(crypto::Persist persist) const { OlmPersistAccount persistAccount = { ACCOUNT_ID, std::string(persist.account.begin(), persist.account.end())}; SQLiteQueryExecutor::getStorage().replace(persistAccount); for (auto it = persist.sessions.begin(); it != persist.sessions.end(); it++) { OlmPersistSession persistSession = { it->first, std::string(it->second.begin(), it->second.end())}; SQLiteQueryExecutor::getStorage().replace(persistSession); } } void SQLiteQueryExecutor::setNotifyToken(std::string token) const { this->setMetadata("notify_token", token); } void SQLiteQueryExecutor::clearNotifyToken() const { this->clearMetadata("notify_token"); } void SQLiteQueryExecutor::setCurrentUserID(std::string userID) const { this->setMetadata("current_user_id", userID); } std::string SQLiteQueryExecutor::getCurrentUserID() const { return this->getMetadata("current_user_id"); } void SQLiteQueryExecutor::setMetadata(std::string entry_name, std::string data) const { Metadata entry{ entry_name, data, }; SQLiteQueryExecutor::getStorage().replace(entry); } void SQLiteQueryExecutor::clearMetadata(std::string entry_name) const { SQLiteQueryExecutor::getStorage().remove(entry_name); } std::string SQLiteQueryExecutor::getMetadata(std::string entry_name) const { std::unique_ptr entry = SQLiteQueryExecutor::getStorage().get_pointer(entry_name); return (entry == nullptr) ? "" : entry->data; } #ifdef EMSCRIPTEN std::vector SQLiteQueryExecutor::getAllThreadsWeb() const { auto threads = SQLiteQueryExecutor::getStorage().get_all(); std::vector webThreads; webThreads.reserve(threads.size()); for (const auto &thread : threads) { webThreads.emplace_back(thread); } return webThreads; }; void SQLiteQueryExecutor::replaceThreadWeb(const WebThread &thread) const { SQLiteQueryExecutor::getStorage().replace(thread.toThread()); }; #else void SQLiteQueryExecutor::clearSensitiveData() { if (file_exists(SQLiteQueryExecutor::sqliteFilePath) && std::remove(SQLiteQueryExecutor::sqliteFilePath.c_str())) { std::ostringstream errorStream; errorStream << "Failed to delete database file. Details: " << strerror(errno); throw std::system_error(errno, std::generic_category(), errorStream.str()); } SQLiteQueryExecutor::assign_encryption_key(); SQLiteQueryExecutor::migrate(); } void SQLiteQueryExecutor::initialize(std::string &databasePath) { std::call_once(SQLiteQueryExecutor::initialized, [&databasePath]() { SQLiteQueryExecutor::sqliteFilePath = databasePath; folly::Optional maybeEncryptionKey = CommSecureStore::get(SQLiteQueryExecutor::secureStoreEncryptionKeyID); if (file_exists(databasePath) && maybeEncryptionKey) { SQLiteQueryExecutor::encryptionKey = maybeEncryptionKey.value(); return; } SQLiteQueryExecutor::assign_encryption_key(); }); } void SQLiteQueryExecutor::assign_encryption_key() { std::string encryptionKey = comm::crypto::Tools::generateRandomHexString( SQLiteQueryExecutor::sqlcipherEncryptionKeySize); CommSecureStore::set( SQLiteQueryExecutor::secureStoreEncryptionKeyID, encryptionKey); SQLiteQueryExecutor::encryptionKey = encryptionKey; } #endif } // namespace comm diff --git a/web/database/_generated/comm-query-executor.js b/web/database/_generated/comm-query-executor.js index d4dbfe15c..9d4ff8378 100644 --- a/web/database/_generated/comm-query-executor.js +++ b/web/database/_generated/comm-query-executor.js @@ -1,156 +1,158 @@ // @generated var Module = (() => { var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename; return ( function(Module) { Module = Module || {}; var e;e||(e=typeof Module !== 'undefined' ? Module : {});var aa,ba;e.ready=new Promise(function(a,b){aa=a;ba=b});var ca=Object.assign({},e),da="./this.program",ea="object"==typeof window,fa="function"==typeof importScripts,ha="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,m="",ia,ja,ka,fs,la,ma; if(ha)m=fa?require("path").dirname(m)+"/":__dirname+"/",ma=()=>{la||(fs=require("fs"),la=require("path"))},ia=function(a,b){ma();a=la.normalize(a);return fs.readFileSync(a,b?void 0:"utf8")},ka=a=>{a=ia(a,!0);a.buffer||(a=new Uint8Array(a));return a},ja=(a,b,c)=>{ma();a=la.normalize(a);fs.readFile(a,function(d,f){d?c(d):b(f.buffer)})},1{var b=new XMLHttpRequest;b.open("GET",a,!1);b.send(null);return b.responseText},fa&&(ka=a=>{var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)}),ja=(a,b,c)=>{var d=new XMLHttpRequest;d.open("GET",a,!0);d.responseType="arraybuffer"; -d.onload=()=>{200==d.status||0==d.status&&d.response?b(d.response):c()};d.onerror=c;d.send(null)};var na=e.print||console.log.bind(console),u=e.printErr||console.warn.bind(console);Object.assign(e,ca);ca=null;e.thisProgram&&(da=e.thisProgram);var oa;e.wasmBinary&&(oa=e.wasmBinary);var noExitRuntime=e.noExitRuntime||!0;"object"!=typeof WebAssembly&&x("no native wasm support detected");var pa,qa=!1,ra="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0; +d.onload=()=>{200==d.status||0==d.status&&d.response?b(d.response):c()};d.onerror=c;d.send(null)};var na=e.print||console.log.bind(console),r=e.printErr||console.warn.bind(console);Object.assign(e,ca);ca=null;e.thisProgram&&(da=e.thisProgram);var oa;e.wasmBinary&&(oa=e.wasmBinary);var noExitRuntime=e.noExitRuntime||!0;"object"!=typeof WebAssembly&&v("no native wasm support detected");var pa,qa=!1,ra="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0; function sa(a,b,c){var d=b+c;for(c=b;a[c]&&!(c>=d);)++c;if(16f?d+=String.fromCharCode(f):(f-=65536,d+=String.fromCharCode(55296|f>>10,56320|f&1023))}}else d+=String.fromCharCode(f)}return d}function y(a,b){return a?sa(z,a,b):""} -function ta(a,b,c,d){if(!(0=k){var h=a.charCodeAt(++g);k=65536+((k&1023)<<10)|h&1023}if(127>=k){if(c>=d)break;b[c++]=k}else{if(2047>=k){if(c+1>=d)break;b[c++]=192|k>>6}else{if(65535>=k){if(c+2>=d)break;b[c++]=224|k>>12}else{if(c+3>=d)break;b[c++]=240|k>>18;b[c++]=128|k>>12&63}b[c++]=128|k>>6&63}b[c++]=128|k&63}}b[c]=0;return c-f} -function ua(a){for(var b=0,c=0;c=d?b++:2047>=d?b+=2:55296<=d&&57343>=d?(b+=4,++c):b+=3}return b}var va,A,z,C,wa,D,E,xa,ya;function za(){var a=pa.buffer;va=a;e.HEAP8=A=new Int8Array(a);e.HEAP16=C=new Int16Array(a);e.HEAP32=D=new Int32Array(a);e.HEAPU8=z=new Uint8Array(a);e.HEAPU16=wa=new Uint16Array(a);e.HEAPU32=E=new Uint32Array(a);e.HEAPF32=xa=new Float32Array(a);e.HEAPF64=ya=new Float64Array(a)}var Aa,Ba=[],Ca=[],Da=[]; -function Ea(){var a=e.preRun.shift();Ba.unshift(a)}var F=0,Fa=null,Ha=null;function Ia(){F++;e.monitorRunDependencies&&e.monitorRunDependencies(F)}function Ja(){F--;e.monitorRunDependencies&&e.monitorRunDependencies(F);if(0==F&&(null!==Fa&&(clearInterval(Fa),Fa=null),Ha)){var a=Ha;Ha=null;a()}}function x(a){if(e.onAbort)e.onAbort(a);a="Aborted("+a+")";u(a);qa=!0;a=new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");ba(a);throw a;}var Ka;Ka="comm-query-executor.wasm"; +function A(a,b,c,d){if(!(0=k){var h=a.charCodeAt(++g);k=65536+((k&1023)<<10)|h&1023}if(127>=k){if(c>=d)break;b[c++]=k}else{if(2047>=k){if(c+1>=d)break;b[c++]=192|k>>6}else{if(65535>=k){if(c+2>=d)break;b[c++]=224|k>>12}else{if(c+3>=d)break;b[c++]=240|k>>18;b[c++]=128|k>>12&63}b[c++]=128|k>>6&63}b[c++]=128|k&63}}b[c]=0;return c-f} +function ta(a){for(var b=0,c=0;c=d?b++:2047>=d?b+=2:55296<=d&&57343>=d?(b+=4,++c):b+=3}return b}var ua,B,z,D,va,E,F,wa,xa;function ya(){var a=pa.buffer;ua=a;e.HEAP8=B=new Int8Array(a);e.HEAP16=D=new Int16Array(a);e.HEAP32=E=new Int32Array(a);e.HEAPU8=z=new Uint8Array(a);e.HEAPU16=va=new Uint16Array(a);e.HEAPU32=F=new Uint32Array(a);e.HEAPF32=wa=new Float32Array(a);e.HEAPF64=xa=new Float64Array(a)}var za,Aa=[],Ba=[],Ca=[]; +function Da(){var a=e.preRun.shift();Aa.unshift(a)}var Ea=0,Fa=null,Ha=null;function Ia(){Ea++;e.monitorRunDependencies&&e.monitorRunDependencies(Ea)}function Ja(){Ea--;e.monitorRunDependencies&&e.monitorRunDependencies(Ea);if(0==Ea&&(null!==Fa&&(clearInterval(Fa),Fa=null),Ha)){var a=Ha;Ha=null;a()}}function v(a){if(e.onAbort)e.onAbort(a);a="Aborted("+a+")";r(a);qa=!0;a=new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");ba(a);throw a;}var Ka;Ka="comm-query-executor.wasm"; if(!Ka.startsWith("data:application/octet-stream;base64,")){var La=Ka;Ka=e.locateFile?e.locateFile(La,m):m+La} -function Ma(a){var b=Ka;try{a:{try{if(b==Ka&&oa){var c=new Uint8Array(oa);break a}if(ka){c=ka(b);break a}throw"sync fetching of the wasm failed: you can preload it to Module['wasmBinary'] manually, or emcc.py will do that for you when generating HTML (but not JS)";}catch(g){x(g)}c=void 0}var d=new WebAssembly.Module(c);var f=new WebAssembly.Instance(d,a)}catch(g){throw a=g.toString(),u("failed to compile wasm module: "+a),(a.includes("imported Memory")||a.includes("memory import"))&&u("Memory size incompatibility issues may be due to changing INITIAL_MEMORY at runtime to something too large. Use ALLOW_MEMORY_GROWTH to allow any size memory (and also make sure not to set INITIAL_MEMORY at runtime to something smaller than it was at compile time)."), -g;}return[f,d]}var G,J;function Na(a){for(;0>2]=b};this.Qc=function(b){E[this.La+8>>2]=b};this.Rc=function(){D[this.La>>2]=0};this.Ub=function(){A[this.La+12>>0]=0};this.Sc=function(){A[this.La+13>>0]=0};this.vb=function(b,c){this.Wa();this.Tc(b);this.Qc(c);this.Rc();this.Ub();this.Sc()};this.Wa=function(){E[this.La+16>>2]=0}} +function Ma(a){var b=Ka;try{a:{try{if(b==Ka&&oa){var c=new Uint8Array(oa);break a}if(ka){c=ka(b);break a}throw"sync fetching of the wasm failed: you can preload it to Module['wasmBinary'] manually, or emcc.py will do that for you when generating HTML (but not JS)";}catch(g){v(g)}c=void 0}var d=new WebAssembly.Module(c);var f=new WebAssembly.Instance(d,a)}catch(g){throw a=g.toString(),r("failed to compile wasm module: "+a),(a.includes("imported Memory")||a.includes("memory import"))&&r("Memory size incompatibility issues may be due to changing INITIAL_MEMORY at runtime to something too large. Use ALLOW_MEMORY_GROWTH to allow any size memory (and also make sure not to set INITIAL_MEMORY at runtime to something smaller than it was at compile time)."), +g;}return[f,d]}var G,J;function Na(a){for(;0>2]=b};this.Wc=function(b){F[this.Ra+8>>2]=b};this.Xc=function(){E[this.Ra>>2]=0};this.$b=function(){B[this.Ra+12>>0]=0};this.Yc=function(){B[this.Ra+13>>0]=0};this.Cb=function(b,c){this.bb();this.Zc(b);this.Wc(c);this.Xc();this.$b();this.Yc()};this.bb=function(){F[this.Ra+16>>2]=0}} var Pa=0,Qa=(a,b)=>{for(var c=0,d=a.length-1;0<=d;d--){var f=a[d];"."===f?a.splice(d,1):".."===f?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c;c--)a.unshift("..");return a},L=a=>{var b="/"===a.charAt(0),c="/"===a.substr(-1);(a=Qa(a.split("/").filter(d=>!!d),!b).join("/"))||b||(a=".");a&&c&&(a+="/");return(b?"/":"")+a},Ra=a=>{var b=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(a).slice(1);a=b[0];b=b[1];if(!a&&!b)return".";b&&(b=b.substr(0,b.length-1));return a+b},M= -a=>{if("/"===a)return"/";a=L(a);a=a.replace(/\/$/,"");var b=a.lastIndexOf("/");return-1===b?a:a.substr(b+1)},Sa=(a,b)=>L(a+"/"+b);function Ta(){if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues){var a=new Uint8Array(1);return()=>{crypto.getRandomValues(a);return a[0]}}if(ha)try{var b=require("crypto");return()=>b.randomBytes(1)[0]}catch(c){}return()=>x("randomDevice")} +a=>{if("/"===a)return"/";a=L(a);a=a.replace(/\/$/,"");var b=a.lastIndexOf("/");return-1===b?a:a.substr(b+1)},Sa=(a,b)=>L(a+"/"+b);function Ta(){if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues){var a=new Uint8Array(1);return()=>{crypto.getRandomValues(a);return a[0]}}if(ha)try{var b=require("crypto");return()=>b.randomBytes(1)[0]}catch(c){}return()=>v("randomDevice")} function Ua(){for(var a="",b=!1,c=arguments.length-1;-1<=c&&!b;c--){b=0<=c?arguments[c]:N.cwd();if("string"!=typeof b)throw new TypeError("Arguments to path.resolve must be strings");if(!b)return"";a=b+"/"+a;b="/"===b.charAt(0)}a=Qa(a.split("/").filter(d=>!!d),!b).join("/");return(b?"/":"")+a||"."} -var Va=(a,b)=>{function c(k){for(var h=0;hn?[]:k.slice(h,n-h+1)}a=Ua(a).substr(1);b=Ua(b).substr(1);a=c(a.split("/"));b=c(b.split("/"));for(var d=Math.min(a.length,b.length),f=d,g=0;g{function c(k){for(var h=0;hn?[]:k.slice(h,n-h+1)}a=Ua(a).substr(1);b=Ua(b).substr(1);a=c(a.split("/"));b=c(b.split("/"));for(var d=Math.min(a.length,b.length),f=d,g=0;g=b||(b=Math.max(b,c*(1048576>c?2:1.125)>>>0),0!=c&&(b=Math.max(b,256)),c=a.Ja,a.Ja=new Uint8Array(b),0=a.node.Pa)return 0;a=Math.min(a.node.Pa-f,d);if(8b)throw new N.Ga(28);return b},Bb:function(a,b,c){O.Ec(a.node,b+c);a.node.Pa=Math.max(a.node.Pa,b+c)},qb:function(a,b,c,d,f){if(!N.isFile(a.node.mode))throw new N.Ga(43);a=a.node.Ja;if(f&2||a.buffer!==va){if(0{f||x('Loading data file "'+a+'" failed (no arrayBuffer).');b(new Uint8Array(f));d&&Ja(d)},()=>{if(c)c();else throw'Loading data file "'+a+'" failed.';});d&&Ia(d)} -var N={root:null,Eb:[],Cc:{},streams:[],Bd:1,eb:null,Ac:"/",cc:!1,Lc:!0,Ga:null,Zb:{},md:null,Rb:0,Oa:(a,b={})=>{a=Ua(N.cwd(),a);if(!a)return{path:"",node:null};b=Object.assign({Xb:!0,nc:0},b);if(8!!k),!1);for(var c=N.root,d="/",f=0;f{for(var b;;){if(N.Nb(a))return a=a.Qa.Mc,b?"/"!==a[a.length-1]?a+"/"+b:a+b:a;b=b?a.name+"/"+b:a.name;a=a.parent}},bc:(a,b)=>{for(var c=0,d=0;d>>0)%N.eb.length},Jc:a=>{var b=N.bc(a.parent.id,a.name);a.rb=N.eb[b];N.eb[b]=a},Kc:a=>{var b=N.bc(a.parent.id,a.name);if(N.eb[b]===a)N.eb[b]=a.rb;else for(b=N.eb[b];b;){if(b.rb===a){b.rb=a.rb;break}b=b.rb}},hb:(a,b)=>{var c=N.yd(a);if(c)throw new N.Ga(c, -a);for(c=N.eb[N.bc(a.id,b)];c;c=c.rb){var d=c.name;if(c.parent.id===a.id&&d===b)return c}return N.lookup(a,b)},createNode:(a,b,c,d)=>{a=new N.Pc(a,b,c,d);N.Jc(a);return a},Wb:a=>{N.Kc(a)},Nb:a=>a===a.parent,ob:a=>!!a.Db,isFile:a=>32768===(a&61440),Sa:a=>16384===(a&61440),xb:a=>40960===(a&61440),Lb:a=>8192===(a&61440),vd:a=>24576===(a&61440),isFIFO:a=>4096===(a&61440),isSocket:a=>49152===(a&49152),nd:{r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090},Ad:a=>{var b=N.nd[a];if("undefined"==typeof b)throw Error("Unknown file open mode: "+ -a);return b},Gc:a=>{var b=["r","w","rw"][a&3];a&512&&(b+="w");return b},mb:(a,b)=>{if(N.Lc)return 0;if(!b.includes("r")||a.mode&292){if(b.includes("w")&&!(a.mode&146)||b.includes("x")&&!(a.mode&73))return 2}else return 2;return 0},yd:a=>{var b=N.mb(a,"x");return b?b:a.Ia.lookup?0:2},jc:(a,b)=>{try{return N.hb(a,b),20}catch(c){}return N.mb(a,"wx")},Pb:(a,b,c)=>{try{var d=N.hb(a,b)}catch(f){return f.Ma}if(a=N.mb(a,"wx"))return a;if(c){if(!N.Sa(d.mode))return 54;if(N.Nb(d)||N.kb(d)===N.cwd())return 10}else if(N.Sa(d.mode))return 31; -return 0},zd:(a,b)=>a?N.xb(a.mode)?32:N.Sa(a.mode)&&("r"!==N.Gc(b)||b&512)?31:N.mb(a,N.Gc(b)):44,Uc:4096,Cd:(a=0,b=N.Uc)=>{for(;a<=b;a++)if(!N.streams[a])return a;throw new N.Ga(33);},lb:a=>N.streams[a],zc:(a,b,c)=>{N.Hb||(N.Hb=function(){this.Wa={}},N.Hb.prototype={},Object.defineProperties(N.Hb.prototype,{object:{get:function(){return this.node},set:function(d){this.node=d}},flags:{get:function(){return this.Wa.flags},set:function(d){this.Wa.flags=d}},position:{get:function(){return this.Wa.position}, -set:function(d){this.Wa.position=d}}}));a=Object.assign(new N.Hb,a);b=N.Cd(b,c);a.fd=b;return N.streams[b]=a},ad:a=>{N.streams[a]=null},$c:{open:a=>{a.Ka=N.qd(a.node.rdev).Ka;a.Ka.open&&a.Ka.open(a)},cb:()=>{throw new N.Ga(70);}},ic:a=>a>>8,$d:a=>a&255,pb:(a,b)=>a<<8|b,pc:(a,b)=>{N.Cc[a]={Ka:b}},qd:a=>N.Cc[a],Hc:a=>{var b=[];for(a=[a];a.length;){var c=a.pop();b.push(c);a.push.apply(a,c.Eb)}return b},Oc:(a,b)=>{function c(k){N.Rb--;return b(k)}function d(k){if(k){if(!d.kd)return d.kd=!0,c(k)}else++g>= -f.length&&c(null)}"function"==typeof a&&(b=a,a=!1);N.Rb++;1{if(!k.type.Oc)return d(null);k.type.Oc(k,a,d)})},Qa:(a,b,c)=>{var d="/"===c,f=!c;if(d&&N.root)throw new N.Ga(10);if(!d&&!f){var g=N.Oa(c,{Xb:!1});c=g.path;g=g.node;if(N.ob(g))throw new N.Ga(10);if(!N.Sa(g.mode))throw new N.Ga(54);}b={type:a,de:b,Mc:c,Eb:[]};a=a.Qa(b);a.Qa=b;b.root=a;d?N.root=a:g&&(g.Db= -b,g.Qa&&g.Qa.Eb.push(b));return a},he:a=>{a=N.Oa(a,{Xb:!1});if(!N.ob(a.node))throw new N.Ga(28);a=a.node;var b=a.Db,c=N.Hc(b);Object.keys(N.eb).forEach(d=>{for(d=N.eb[d];d;){var f=d.rb;c.includes(d.Qa)&&N.Wb(d);d=f}});a.Db=null;a.Qa.Eb.splice(a.Qa.Eb.indexOf(b),1)},lookup:(a,b)=>a.Ia.lookup(a,b),ib:(a,b,c)=>{var d=N.Oa(a,{parent:!0}).node;a=M(a);if(!a||"."===a||".."===a)throw new N.Ga(28);var f=N.jc(d,a);if(f)throw new N.Ga(f);if(!d.Ia.ib)throw new N.Ga(63);return d.Ia.ib(d,a,b,c)},create:(a,b)=> -N.ib(a,(void 0!==b?b:438)&4095|32768,0),mkdir:(a,b)=>N.ib(a,(void 0!==b?b:511)&1023|16384,0),ae:(a,b)=>{a=a.split("/");for(var c="",d=0;d{"undefined"==typeof c&&(c=b,b=438);return N.ib(a,b|8192,c)},symlink:(a,b)=>{if(!Ua(a))throw new N.Ga(44);var c=N.Oa(b,{parent:!0}).node;if(!c)throw new N.Ga(44);b=M(b);var d=N.jc(c,b);if(d)throw new N.Ga(d);if(!c.Ia.symlink)throw new N.Ga(63);return c.Ia.symlink(c,b, -a)},rename:(a,b)=>{var c=Ra(a),d=Ra(b),f=M(a),g=M(b);var k=N.Oa(a,{parent:!0});var h=k.node;k=N.Oa(b,{parent:!0});k=k.node;if(!h||!k)throw new N.Ga(44);if(h.Qa!==k.Qa)throw new N.Ga(75);var n=N.hb(h,f);a=Va(a,d);if("."!==a.charAt(0))throw new N.Ga(28);a=Va(b,c);if("."!==a.charAt(0))throw new N.Ga(55);try{var q=N.hb(k,g)}catch(p){}if(n!==q){b=N.Sa(n.mode);if(f=N.Pb(h,f,b))throw new N.Ga(f);if(f=q?N.Pb(k,g,b):N.jc(k,g))throw new N.Ga(f);if(!h.Ia.rename)throw new N.Ga(63);if(N.ob(n)||q&&N.ob(q))throw new N.Ga(10); -if(k!==h&&(f=N.mb(h,"w")))throw new N.Ga(f);N.Kc(n);try{h.Ia.rename(n,k,g)}catch(p){throw p;}finally{N.Jc(n)}}},rmdir:a=>{var b=N.Oa(a,{parent:!0}).node;a=M(a);var c=N.hb(b,a),d=N.Pb(b,a,!0);if(d)throw new N.Ga(d);if(!b.Ia.rmdir)throw new N.Ga(63);if(N.ob(c))throw new N.Ga(10);b.Ia.rmdir(b,a);N.Wb(c)},readdir:a=>{a=N.Oa(a,{Xa:!0}).node;if(!a.Ia.readdir)throw new N.Ga(54);return a.Ia.readdir(a)},unlink:a=>{var b=N.Oa(a,{parent:!0}).node;if(!b)throw new N.Ga(44);a=M(a);var c=N.hb(b,a),d=N.Pb(b,a,!1); -if(d)throw new N.Ga(d);if(!b.Ia.unlink)throw new N.Ga(63);if(N.ob(c))throw new N.Ga(10);b.Ia.unlink(b,a);N.Wb(c)},readlink:a=>{a=N.Oa(a).node;if(!a)throw new N.Ga(44);if(!a.Ia.readlink)throw new N.Ga(28);return Ua(N.kb(a.parent),a.Ia.readlink(a))},stat:(a,b)=>{a=N.Oa(a,{Xa:!b}).node;if(!a)throw new N.Ga(44);if(!a.Ia.bb)throw new N.Ga(63);return a.Ia.bb(a)},lstat:a=>N.stat(a,!0),chmod:(a,b,c)=>{a="string"==typeof a?N.Oa(a,{Xa:!c}).node:a;if(!a.Ia.Ta)throw new N.Ga(63);a.Ia.Ta(a,{mode:b&4095|a.mode& --4096,timestamp:Date.now()})},lchmod:(a,b)=>{N.chmod(a,b,!0)},fchmod:(a,b)=>{a=N.lb(a);if(!a)throw new N.Ga(8);N.chmod(a.node,b)},chown:(a,b,c,d)=>{a="string"==typeof a?N.Oa(a,{Xa:!d}).node:a;if(!a.Ia.Ta)throw new N.Ga(63);a.Ia.Ta(a,{timestamp:Date.now()})},lchown:(a,b,c)=>{N.chown(a,b,c,!0)},fchown:(a,b,c)=>{a=N.lb(a);if(!a)throw new N.Ga(8);N.chown(a.node,b,c)},truncate:(a,b)=>{if(0>b)throw new N.Ga(28);a="string"==typeof a?N.Oa(a,{Xa:!0}).node:a;if(!a.Ia.Ta)throw new N.Ga(63);if(N.Sa(a.mode))throw new N.Ga(31); -if(!N.isFile(a.mode))throw new N.Ga(28);var c=N.mb(a,"w");if(c)throw new N.Ga(c);a.Ia.Ta(a,{size:b,timestamp:Date.now()})},od:(a,b)=>{a=N.lb(a);if(!a)throw new N.Ga(8);if(0===(a.flags&2097155))throw new N.Ga(28);N.truncate(a.node,b)},Vd:(a,b,c)=>{a=N.Oa(a,{Xa:!0}).node;a.Ia.Ta(a,{timestamp:Math.max(b,c)})},open:(a,b,c)=>{if(""===a)throw new N.Ga(44);b="string"==typeof b?N.Ad(b):b;c=b&64?("undefined"==typeof c?438:c)&4095|32768:0;if("object"==typeof a)var d=a;else{a=L(a);try{d=N.Oa(a,{Xa:!(b&131072)}).node}catch(g){}}var f= -!1;if(b&64)if(d){if(b&128)throw new N.Ga(20);}else d=N.ib(a,c,0),f=!0;if(!d)throw new N.Ga(44);N.Lb(d.mode)&&(b&=-513);if(b&65536&&!N.Sa(d.mode))throw new N.Ga(54);if(!f&&(c=N.zd(d,b)))throw new N.Ga(c);b&512&&!f&&N.truncate(d,0);b&=-131713;d=N.zc({node:d,path:N.kb(d),flags:b,seekable:!0,position:0,Ka:d.Ka,Ud:[],error:!1});d.Ka.open&&d.Ka.open(d);!e.logReadFiles||b&1||(N.mc||(N.mc={}),a in N.mc||(N.mc[a]=1));return d},close:a=>{if(N.Cb(a))throw new N.Ga(8);a.ac&&(a.ac=null);try{a.Ka.close&&a.Ka.close(a)}catch(b){throw b; -}finally{N.ad(a.fd)}a.fd=null},Cb:a=>null===a.fd,cb:(a,b,c)=>{if(N.Cb(a))throw new N.Ga(8);if(!a.seekable||!a.Ka.cb)throw new N.Ga(70);if(0!=c&&1!=c&&2!=c)throw new N.Ga(28);a.position=a.Ka.cb(a,b,c);a.Ud=[];return a.position},read:(a,b,c,d,f)=>{if(0>d||0>f)throw new N.Ga(28);if(N.Cb(a))throw new N.Ga(8);if(1===(a.flags&2097155))throw new N.Ga(8);if(N.Sa(a.node.mode))throw new N.Ga(31);if(!a.Ka.read)throw new N.Ga(28);var g="undefined"!=typeof f;if(!g)f=a.position;else if(!a.seekable)throw new N.Ga(70); -b=a.Ka.read(a,b,c,d,f);g||(a.position+=b);return b},write:(a,b,c,d,f,g)=>{if(0>d||0>f)throw new N.Ga(28);if(N.Cb(a))throw new N.Ga(8);if(0===(a.flags&2097155))throw new N.Ga(8);if(N.Sa(a.node.mode))throw new N.Ga(31);if(!a.Ka.write)throw new N.Ga(28);a.seekable&&a.flags&1024&&N.cb(a,0,2);var k="undefined"!=typeof f;if(!k)f=a.position;else if(!a.seekable)throw new N.Ga(70);b=a.Ka.write(a,b,c,d,f,g);k||(a.position+=b);return b},Bb:(a,b,c)=>{if(N.Cb(a))throw new N.Ga(8);if(0>b||0>=c)throw new N.Ga(28); -if(0===(a.flags&2097155))throw new N.Ga(8);if(!N.isFile(a.node.mode)&&!N.Sa(a.node.mode))throw new N.Ga(43);if(!a.Ka.Bb)throw new N.Ga(138);a.Ka.Bb(a,b,c)},qb:(a,b,c,d,f)=>{if(0!==(d&2)&&0===(f&2)&&2!==(a.flags&2097155))throw new N.Ga(2);if(1===(a.flags&2097155))throw new N.Ga(2);if(!a.Ka.qb)throw new N.Ga(43);return a.Ka.qb(a,b,c,d,f)},yb:(a,b,c,d,f)=>a&&a.Ka.yb?a.Ka.yb(a,b,c,d,f):0,be:()=>0,dc:(a,b,c)=>{if(!a.Ka.dc)throw new N.Ga(59);return a.Ka.dc(a,b,c)},readFile:(a,b={})=>{b.flags=b.flags||0; -b.encoding=b.encoding||"binary";if("utf8"!==b.encoding&&"binary"!==b.encoding)throw Error('Invalid encoding type "'+b.encoding+'"');var c,d=N.open(a,b.flags);a=N.stat(a).size;var f=new Uint8Array(a);N.read(d,f,0,a,0);"utf8"===b.encoding?c=sa(f,0):"binary"===b.encoding&&(c=f);N.close(d);return c},writeFile:(a,b,c={})=>{c.flags=c.flags||577;a=N.open(a,c.flags,c.mode);if("string"==typeof b){var d=new Uint8Array(ua(b)+1);b=ta(b,d,0,d.length);N.write(a,d,0,b,void 0,c.Zc)}else if(ArrayBuffer.isView(b))N.write(a, -b,0,b.byteLength,void 0,c.Zc);else throw Error("Unsupported data type");N.close(a)},cwd:()=>N.Ac,chdir:a=>{a=N.Oa(a,{Xa:!0});if(null===a.node)throw new N.Ga(44);if(!N.Sa(a.node.mode))throw new N.Ga(54);var b=N.mb(a.node,"x");if(b)throw new N.Ga(b);N.Ac=a.path},dd:()=>{N.mkdir("/tmp");N.mkdir("/home");N.mkdir("/home/web_user")},cd:()=>{N.mkdir("/dev");N.pc(N.pb(1,3),{read:()=>0,write:(b,c,d,f)=>f});N.Qb("/dev/null",N.pb(1,3));Ya(N.pb(5,0),$a);Ya(N.pb(6,0),ab);N.Qb("/dev/tty",N.pb(5,0));N.Qb("/dev/tty1", -N.pb(6,0));var a=Ta();N.$a("/dev","random",a);N.$a("/dev","urandom",a);N.mkdir("/dev/shm");N.mkdir("/dev/shm/tmp")},gd:()=>{N.mkdir("/proc");var a=N.mkdir("/proc/self");N.mkdir("/proc/self/fd");N.Qa({Qa:()=>{var b=N.createNode(a,"fd",16895,73);b.Ia={lookup:(c,d)=>{var f=N.lb(+d);if(!f)throw new N.Ga(8);c={parent:null,Qa:{Mc:"fake"},Ia:{readlink:()=>f.path}};return c.parent=c}};return b}},{},"/proc/self/fd")},hd:()=>{e.stdin?N.$a("/dev","stdin",e.stdin):N.symlink("/dev/tty","/dev/stdin");e.stdout? -N.$a("/dev","stdout",null,e.stdout):N.symlink("/dev/tty","/dev/stdout");e.stderr?N.$a("/dev","stderr",null,e.stderr):N.symlink("/dev/tty1","/dev/stderr");N.open("/dev/stdin",0);N.open("/dev/stdout",1);N.open("/dev/stderr",1)},Dc:()=>{N.Ga||(N.Ga=function(a,b){this.node=b;this.Kd=function(c){this.Ma=c};this.Kd(a);this.message="FS error"},N.Ga.prototype=Error(),N.Ga.prototype.constructor=N.Ga,[44].forEach(a=>{N.Zb[a]=new N.Ga(a);N.Zb[a].stack=""}))},Pd:()=>{N.Dc();N.eb=Array(4096); -N.Qa(O,{},"/");N.dd();N.cd();N.gd();N.md={MEMFS:O}},vb:(a,b,c)=>{N.vb.cc=!0;N.Dc();e.stdin=a||e.stdin;e.stdout=b||e.stdout;e.stderr=c||e.stderr;N.hd()},ee:()=>{N.vb.cc=!1;for(var a=0;a{var c=0;a&&(c|=365);b&&(c|=146);return c},Wd:(a,b)=>{a=N.Vb(a,b);return a.exists?a.object:null},Vb:(a,b)=>{try{var c=N.Oa(a,{Xa:!b});a=c.path}catch(f){}var d={Nb:!1,exists:!1,error:0,name:null,path:null,object:null,Dd:!1,Fd:null,Ed:null};try{c=N.Oa(a, -{parent:!0}),d.Dd=!0,d.Fd=c.path,d.Ed=c.node,d.name=M(a),c=N.Oa(a,{Xa:!b}),d.exists=!0,d.path=c.path,d.object=c.node,d.name=c.node.name,d.Nb="/"===c.path}catch(f){d.error=f.Ma}return d},xc:(a,b)=>{a="string"==typeof a?a:N.kb(a);for(b=b.split("/").reverse();b.length;){var c=b.pop();if(c){var d=L(a+"/"+c);try{N.mkdir(d)}catch(f){}a=d}}return d},ed:(a,b,c,d,f)=>{a="string"==typeof a?a:N.kb(a);b=L(a+"/"+b);return N.create(b,N.$b(d,f))},Jb:(a,b,c,d,f,g)=>{var k=b;a&&(a="string"==typeof a?a:N.kb(a),k=b? -L(a+"/"+b):a);a=N.$b(d,f);k=N.create(k,a);if(c){if("string"==typeof c){b=Array(c.length);d=0;for(f=c.length;d{a=Sa("string"==typeof a?a:N.kb(a),b);b=N.$b(!!c,!!d);N.$a.ic||(N.$a.ic=64);var f=N.pb(N.$a.ic++,0);N.pc(f,{open:g=>{g.seekable=!1},close:()=>{d&&d.buffer&&d.buffer.length&&d(10)},read:(g,k,h,n)=>{for(var q=0,p=0;p{for(var q=0;q{if(a.ec||a.wd||a.link||a.Ja)return!0;if("undefined"!=typeof XMLHttpRequest)throw Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread."); -if(ia)try{a.Ja=Wa(ia(a.url),!0),a.Pa=a.Ja.length}catch(b){throw new N.Ga(29);}else throw Error("Cannot load without read() or XMLHttpRequest.");},wc:(a,b,c,d,f)=>{function g(){this.hc=!1;this.Wa=[]}function k(p,r,w,l,t){p=p.node.Ja;if(t>=p.length)return 0;l=Math.min(p.length-t,l);if(p.slice)for(var v=0;vthis.length-1||0>p)){var r=p%this.chunkSize;return this.Kb(p/this.chunkSize|0)[r]}};g.prototype.Ub= -function(p){this.Kb=p};g.prototype.uc=function(){var p=new XMLHttpRequest;p.open("HEAD",c,!1);p.send(null);if(!(200<=p.status&&300>p.status||304===p.status))throw Error("Couldn't load "+c+". Status: "+p.status);var r=Number(p.getResponseHeader("Content-length")),w,l=(w=p.getResponseHeader("Accept-Ranges"))&&"bytes"===w;p=(w=p.getResponseHeader("Content-Encoding"))&&"gzip"===w;var t=1048576;l||(t=r);var v=this;v.Ub(B=>{var K=B*t,H=(B+1)*t-1;H=Math.min(H,r-1);if("undefined"==typeof v.Wa[B]){var Ga= -v.Wa;if(K>H)throw Error("invalid range ("+K+", "+H+") or no bytes requested!");if(H>r-1)throw Error("only "+r+" bytes available! programmer error!");var I=new XMLHttpRequest;I.open("GET",c,!1);r!==t&&I.setRequestHeader("Range","bytes="+K+"-"+H);I.responseType="arraybuffer";I.overrideMimeType&&I.overrideMimeType("text/plain; charset=x-user-defined");I.send(null);if(!(200<=I.status&&300>I.status||304===I.status))throw Error("Couldn't load "+c+". Status: "+I.status);K=void 0!==I.response?new Uint8Array(I.response|| -[]):Wa(I.responseText||"",!0);Ga[B]=K}if("undefined"==typeof v.Wa[B])throw Error("doXHR failed!");return v.Wa[B]});if(p||!r)t=r=1,t=r=this.Kb(0).length,na("LazyFiles on gzip forces download of the whole file when length is accessed");this.Wc=r;this.Vc=t;this.hc=!0};if("undefined"!=typeof XMLHttpRequest){if(!fa)throw"Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc";var h=new g;Object.defineProperties(h,{length:{get:function(){this.hc|| -this.uc();return this.Wc}},chunkSize:{get:function(){this.hc||this.uc();return this.Vc}}});h={ec:!1,Ja:h}}else h={ec:!1,url:c};var n=N.ed(a,b,h,d,f);h.Ja?n.Ja=h.Ja:h.url&&(n.Ja=null,n.url=h.url);Object.defineProperties(n,{Pa:{get:function(){return this.Ja.length}}});var q={};Object.keys(n.Ka).forEach(p=>{var r=n.Ka[p];q[p]=function(){N.Yb(n);return r.apply(null,arguments)}});q.read=(p,r,w,l,t)=>{N.Yb(n);return k(p,r,w,l,t)};q.qb=(p,r,w)=>{N.Yb(n);var l=bb(r);if(!l)throw new N.Ga(48);k(p,A,l,r,w); -return{La:l,tc:!0}};n.Ka=q;return n},yc:(a,b,c,d,f,g,k,h,n,q)=>{function p(l){function t(v){q&&q();h||N.Jb(a,b,v,d,f,n);g&&g();Ja(w)}eb.Yd(l,r,t,()=>{k&&k();Ja(w)})||t(l)}var r=b?Ua(L(a+"/"+b)):a,w="cp "+r;Ia(w);"string"==typeof c?db(c,l=>p(l),k):p(c)},indexedDB:()=>window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,rc:()=>"EM_FS_"+window.location.pathname,sc:20,Ab:"FILE_DATA",fe:(a,b,c)=>{b=b||(()=>{});c=c||(()=>{});var d=N.indexedDB();try{var f=d.open(N.rc(),N.sc)}catch(g){return c(g)}f.onupgradeneeded= -()=>{na("creating db");f.result.createObjectStore(N.Ab)};f.onsuccess=()=>{var g=f.result.transaction([N.Ab],"readwrite"),k=g.objectStore(N.Ab),h=0,n=0,q=a.length;a.forEach(p=>{p=k.put(N.Vb(p).object.Ja,p);p.onsuccess=()=>{h++;h+n==q&&(0==n?b():c())};p.onerror=()=>{n++;h+n==q&&(0==n?b():c())}});g.onerror=c};f.onerror=c},Zd:(a,b,c)=>{b=b||(()=>{});c=c||(()=>{});var d=N.indexedDB();try{var f=d.open(N.rc(),N.sc)}catch(g){return c(g)}f.onupgradeneeded=c;f.onsuccess=()=>{var g=f.result;try{var k=g.transaction([N.Ab], -"readonly")}catch(r){c(r);return}var h=k.objectStore(N.Ab),n=0,q=0,p=a.length;a.forEach(r=>{var w=h.get(r);w.onsuccess=()=>{N.Vb(r).exists&&N.unlink(r);N.Jb(Ra(r),M(r),w.result,!0,!0,!0);n++;n+q==p&&(0==q?b():c())};w.onerror=()=>{q++;n+q==p&&(0==q?b():c())}});k.onerror=c};f.onerror=c}};function P(a,b,c){if("/"===b.charAt(0))return b;if(-100===a)a=N.cwd();else{a=N.lb(a);if(!a)throw new N.Ga(8);a=a.path}if(0==b.length){if(!c)throw new N.Ga(44);return a}return L(a+"/"+b)} -function fb(a,b,c){try{var d=a(b)}catch(f){if(f&&f.node&&L(b)!==L(N.kb(f.node)))return-54;throw f;}D[c>>2]=d.dev;D[c+4>>2]=0;D[c+8>>2]=d.ino;D[c+12>>2]=d.mode;D[c+16>>2]=d.nlink;D[c+20>>2]=d.uid;D[c+24>>2]=d.gid;D[c+28>>2]=d.rdev;D[c+32>>2]=0;J=[d.size>>>0,(G=d.size,1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];D[c+40>>2]=J[0];D[c+44>>2]=J[1];D[c+48>>2]=4096;D[c+52>>2]=d.blocks;J=[Math.floor(d.atime.getTime()/1E3)>>>0,(G= -Math.floor(d.atime.getTime()/1E3),1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];D[c+56>>2]=J[0];D[c+60>>2]=J[1];D[c+64>>2]=0;J=[Math.floor(d.mtime.getTime()/1E3)>>>0,(G=Math.floor(d.mtime.getTime()/1E3),1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];D[c+72>>2]=J[0];D[c+76>>2]=J[1];D[c+80>>2]=0;J=[Math.floor(d.ctime.getTime()/1E3)>>>0,(G=Math.floor(d.ctime.getTime()/ -1E3),1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];D[c+88>>2]=J[0];D[c+92>>2]=J[1];D[c+96>>2]=0;J=[d.ino>>>0,(G=d.ino,1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];D[c+104>>2]=J[0];D[c+108>>2]=J[1];return 0}var gb=void 0;function hb(){gb+=4;return D[gb-4>>2]}function Q(a){a=N.lb(a);if(!a)throw new N.Ga(8);return a} -function ib(a){return E[a>>2]+4294967296*D[a+4>>2]}var jb={};function kb(a){for(;a.length;){var b=a.pop();a.pop()(b)}}function lb(a){return this.fromWireType(D[a>>2])}var mb={},nb={},ob={};function pb(a){if(void 0===a)return"_unknown";a=a.replace(/[^a-zA-Z0-9_]/g,"$");var b=a.charCodeAt(0);return 48<=b&&57>=b?"_"+a:a}function qb(a,b){a=pb(a);return(new Function("body","return function "+a+'() {\n "use strict"; return body.apply(this, arguments);\n};\n'))(b)} +var O={lb:null,Va:function(){return O.createNode(null,"/",16895,0)},createNode:function(a,b,c,d){if(N.Ad(c)||N.isFIFO(c))throw new N.La(63);O.lb||(O.lb={dir:{node:{ib:O.Na.ib,Ya:O.Na.Ya,lookup:O.Na.lookup,nb:O.Na.nb,rename:O.Na.rename,unlink:O.Na.unlink,rmdir:O.Na.rmdir,readdir:O.Na.readdir,symlink:O.Na.symlink},stream:{ab:O.Pa.ab}},file:{node:{ib:O.Na.ib,Ya:O.Na.Ya},stream:{ab:O.Pa.ab,read:O.Pa.read,write:O.Pa.write,Hb:O.Pa.Hb,xb:O.Pa.xb,Eb:O.Pa.Eb}},link:{node:{ib:O.Na.ib,Ya:O.Na.Ya,readlink:O.Na.readlink}, +stream:{}},Ac:{node:{ib:O.Na.ib,Ya:O.Na.Ya},stream:N.ed}});c=N.createNode(a,b,c,d);N.Xa(c.mode)?(c.Na=O.lb.dir.node,c.Pa=O.lb.dir.stream,c.Oa={}):N.isFile(c.mode)?(c.Na=O.lb.file.node,c.Pa=O.lb.file.stream,c.Ua=0,c.Oa=null):N.ub(c.mode)?(c.Na=O.lb.link.node,c.Pa=O.lb.link.stream):N.Ib(c.mode)&&(c.Na=O.lb.Ac.node,c.Pa=O.lb.Ac.stream);c.timestamp=Date.now();a&&(a.Oa[b]=c,a.timestamp=c.timestamp);return c},be:function(a){return a.Oa?a.Oa.subarray?a.Oa.subarray(0,a.Ua):new Uint8Array(a.Oa):new Uint8Array(0)}, +Jc:function(a,b){var c=a.Oa?a.Oa.length:0;c>=b||(b=Math.max(b,c*(1048576>c?2:1.125)>>>0),0!=c&&(b=Math.max(b,256)),c=a.Oa,a.Oa=new Uint8Array(b),0=a.node.Ua)return 0;a=Math.min(a.node.Ua-f,d);if(8b)throw new N.La(28);return b},Hb:function(a,b,c){O.Jc(a.node,b+c);a.node.Ua=Math.max(a.node.Ua,b+c)},xb:function(a,b,c,d,f){if(!N.isFile(a.node.mode))throw new N.La(43);a=a.node.Oa;if(f&2||a.buffer!==ua){if(0{f||v('Loading data file "'+a+'" failed (no arrayBuffer).');b(new Uint8Array(f));d&&Ja(d)},()=>{if(c)c();else throw'Loading data file "'+a+'" failed.';});d&&Ia(d)} +var N={root:null,Lb:[],Hc:{},streams:[],Gd:1,kb:null,Fc:"/",ic:!1,Qc:!0,La:null,ec:{},rd:null,Xb:0,Ta:(a,b={})=>{a=Ua(N.cwd(),a);if(!a)return{path:"",node:null};b=Object.assign({cc:!0,sc:0},b);if(8!!k),!1);for(var c=N.root,d="/",f=0;f{for(var b;;){if(N.Tb(a))return a=a.Va.Rc,b?"/"!==a[a.length-1]?a+"/"+b:a+b:a;b=b?a.name+"/"+b:a.name;a=a.parent}},hc:(a,b)=>{for(var c=0,d=0;d>>0)%N.kb.length},Oc:a=>{var b=N.hc(a.parent.id,a.name);a.yb=N.kb[b];N.kb[b]=a},Pc:a=>{var b=N.hc(a.parent.id,a.name);if(N.kb[b]===a)N.kb[b]=a.yb;else for(b=N.kb[b];b;){if(b.yb===a){b.yb=a.yb;break}b=b.yb}},jb:(a,b)=>{var c=N.Dd(a);if(c)throw new N.La(c, +a);for(c=N.kb[N.hc(a.id,b)];c;c=c.yb){var d=c.name;if(c.parent.id===a.id&&d===b)return c}return N.lookup(a,b)},createNode:(a,b,c,d)=>{a=new N.Uc(a,b,c,d);N.Oc(a);return a},bc:a=>{N.Pc(a)},Tb:a=>a===a.parent,vb:a=>!!a.Kb,isFile:a=>32768===(a&61440),Xa:a=>16384===(a&61440),ub:a=>40960===(a&61440),Ib:a=>8192===(a&61440),Ad:a=>24576===(a&61440),isFIFO:a=>4096===(a&61440),isSocket:a=>49152===(a&49152),sd:{r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090},Fd:a=>{var b=N.sd[a];if("undefined"==typeof b)throw Error("Unknown file open mode: "+ +a);return b},Lc:a=>{var b=["r","w","rw"][a&3];a&512&&(b+="w");return b},rb:(a,b)=>{if(N.Qc)return 0;if(!b.includes("r")||a.mode&292){if(b.includes("w")&&!(a.mode&146)||b.includes("x")&&!(a.mode&73))return 2}else return 2;return 0},Dd:a=>{var b=N.rb(a,"x");return b?b:a.Na.lookup?0:2},oc:(a,b)=>{try{return N.jb(a,b),20}catch(c){}return N.rb(a,"wx")},Vb:(a,b,c)=>{try{var d=N.jb(a,b)}catch(f){return f.Qa}if(a=N.rb(a,"wx"))return a;if(c){if(!N.Xa(d.mode))return 54;if(N.Tb(d)||N.pb(d)===N.cwd())return 10}else if(N.Xa(d.mode))return 31; +return 0},Ed:(a,b)=>a?N.ub(a.mode)?32:N.Xa(a.mode)&&("r"!==N.Lc(b)||b&512)?31:N.rb(a,N.Lc(b)):44,Vc:4096,Hd:(a=0,b=N.Vc)=>{for(;a<=b;a++)if(!N.streams[a])return a;throw new N.La(33);},qb:a=>N.streams[a],Ec:(a,b,c)=>{N.Ob||(N.Ob=function(){this.bb={}},N.Ob.prototype={},Object.defineProperties(N.Ob.prototype,{object:{get:function(){return this.node},set:function(d){this.node=d}},flags:{get:function(){return this.bb.flags},set:function(d){this.bb.flags=d}},position:{get:function(){return this.bb.position}, +set:function(d){this.bb.position=d}}}));a=Object.assign(new N.Ob,a);b=N.Hd(b,c);a.fd=b;return N.streams[b]=a},gd:a=>{N.streams[a]=null},ed:{open:a=>{a.Pa=N.vd(a.node.rdev).Pa;a.Pa.open&&a.Pa.open(a)},ab:()=>{throw new N.La(70);}},nc:a=>a>>8,ee:a=>a&255,wb:(a,b)=>a<<8|b,uc:(a,b)=>{N.Hc[a]={Pa:b}},vd:a=>N.Hc[a],Mc:a=>{var b=[];for(a=[a];a.length;){var c=a.pop();b.push(c);a.push.apply(a,c.Lb)}return b},Tc:(a,b)=>{function c(k){N.Xb--;return b(k)}function d(k){if(k){if(!d.pd)return d.pd=!0,c(k)}else++g>= +f.length&&c(null)}"function"==typeof a&&(b=a,a=!1);N.Xb++;1{if(!k.type.Tc)return d(null);k.type.Tc(k,a,d)})},Va:(a,b,c)=>{var d="/"===c,f=!c;if(d&&N.root)throw new N.La(10);if(!d&&!f){var g=N.Ta(c,{cc:!1});c=g.path;g=g.node;if(N.vb(g))throw new N.La(10);if(!N.Xa(g.mode))throw new N.La(54);}b={type:a,ie:b,Rc:c,Lb:[]};a=a.Va(b);a.Va=b;b.root=a;d?N.root=a:g&&(g.Kb= +b,g.Va&&g.Va.Lb.push(b));return a},me:a=>{a=N.Ta(a,{cc:!1});if(!N.vb(a.node))throw new N.La(28);a=a.node;var b=a.Kb,c=N.Mc(b);Object.keys(N.kb).forEach(d=>{for(d=N.kb[d];d;){var f=d.yb;c.includes(d.Va)&&N.bc(d);d=f}});a.Kb=null;a.Va.Lb.splice(a.Va.Lb.indexOf(b),1)},lookup:(a,b)=>a.Na.lookup(a,b),nb:(a,b,c)=>{var d=N.Ta(a,{parent:!0}).node;a=M(a);if(!a||"."===a||".."===a)throw new N.La(28);var f=N.oc(d,a);if(f)throw new N.La(f);if(!d.Na.nb)throw new N.La(63);return d.Na.nb(d,a,b,c)},create:(a,b)=> +N.nb(a,(void 0!==b?b:438)&4095|32768,0),mkdir:(a,b)=>N.nb(a,(void 0!==b?b:511)&1023|16384,0),fe:(a,b)=>{a=a.split("/");for(var c="",d=0;d{"undefined"==typeof c&&(c=b,b=438);return N.nb(a,b|8192,c)},symlink:(a,b)=>{if(!Ua(a))throw new N.La(44);var c=N.Ta(b,{parent:!0}).node;if(!c)throw new N.La(44);b=M(b);var d=N.oc(c,b);if(d)throw new N.La(d);if(!c.Na.symlink)throw new N.La(63);return c.Na.symlink(c,b, +a)},rename:(a,b)=>{var c=Ra(a),d=Ra(b),f=M(a),g=M(b);var k=N.Ta(a,{parent:!0});var h=k.node;k=N.Ta(b,{parent:!0});k=k.node;if(!h||!k)throw new N.La(44);if(h.Va!==k.Va)throw new N.La(75);var n=N.jb(h,f);a=Va(a,d);if("."!==a.charAt(0))throw new N.La(28);a=Va(b,c);if("."!==a.charAt(0))throw new N.La(55);try{var q=N.jb(k,g)}catch(p){}if(n!==q){b=N.Xa(n.mode);if(f=N.Vb(h,f,b))throw new N.La(f);if(f=q?N.Vb(k,g,b):N.oc(k,g))throw new N.La(f);if(!h.Na.rename)throw new N.La(63);if(N.vb(n)||q&&N.vb(q))throw new N.La(10); +if(k!==h&&(f=N.rb(h,"w")))throw new N.La(f);N.Pc(n);try{h.Na.rename(n,k,g)}catch(p){throw p;}finally{N.Oc(n)}}},rmdir:a=>{var b=N.Ta(a,{parent:!0}).node;a=M(a);var c=N.jb(b,a),d=N.Vb(b,a,!0);if(d)throw new N.La(d);if(!b.Na.rmdir)throw new N.La(63);if(N.vb(c))throw new N.La(10);b.Na.rmdir(b,a);N.bc(c)},readdir:a=>{a=N.Ta(a,{cb:!0}).node;if(!a.Na.readdir)throw new N.La(54);return a.Na.readdir(a)},unlink:a=>{var b=N.Ta(a,{parent:!0}).node;if(!b)throw new N.La(44);a=M(a);var c=N.jb(b,a),d=N.Vb(b,a,!1); +if(d)throw new N.La(d);if(!b.Na.unlink)throw new N.La(63);if(N.vb(c))throw new N.La(10);b.Na.unlink(b,a);N.bc(c)},readlink:a=>{a=N.Ta(a).node;if(!a)throw new N.La(44);if(!a.Na.readlink)throw new N.La(28);return Ua(N.pb(a.parent),a.Na.readlink(a))},stat:(a,b)=>{a=N.Ta(a,{cb:!b}).node;if(!a)throw new N.La(44);if(!a.Na.ib)throw new N.La(63);return a.Na.ib(a)},lstat:a=>N.stat(a,!0),chmod:(a,b,c)=>{a="string"==typeof a?N.Ta(a,{cb:!c}).node:a;if(!a.Na.Ya)throw new N.La(63);a.Na.Ya(a,{mode:b&4095|a.mode& +-4096,timestamp:Date.now()})},lchmod:(a,b)=>{N.chmod(a,b,!0)},fchmod:(a,b)=>{a=N.qb(a);if(!a)throw new N.La(8);N.chmod(a.node,b)},chown:(a,b,c,d)=>{a="string"==typeof a?N.Ta(a,{cb:!d}).node:a;if(!a.Na.Ya)throw new N.La(63);a.Na.Ya(a,{timestamp:Date.now()})},lchown:(a,b,c)=>{N.chown(a,b,c,!0)},fchown:(a,b,c)=>{a=N.qb(a);if(!a)throw new N.La(8);N.chown(a.node,b,c)},truncate:(a,b)=>{if(0>b)throw new N.La(28);a="string"==typeof a?N.Ta(a,{cb:!0}).node:a;if(!a.Na.Ya)throw new N.La(63);if(N.Xa(a.mode))throw new N.La(31); +if(!N.isFile(a.mode))throw new N.La(28);var c=N.rb(a,"w");if(c)throw new N.La(c);a.Na.Ya(a,{size:b,timestamp:Date.now()})},td:(a,b)=>{a=N.qb(a);if(!a)throw new N.La(8);if(0===(a.flags&2097155))throw new N.La(28);N.truncate(a.node,b)},$d:(a,b,c)=>{a=N.Ta(a,{cb:!0}).node;a.Na.Ya(a,{timestamp:Math.max(b,c)})},open:(a,b,c)=>{if(""===a)throw new N.La(44);b="string"==typeof b?N.Fd(b):b;c=b&64?("undefined"==typeof c?438:c)&4095|32768:0;if("object"==typeof a)var d=a;else{a=L(a);try{d=N.Ta(a,{cb:!(b&131072)}).node}catch(g){}}var f= +!1;if(b&64)if(d){if(b&128)throw new N.La(20);}else d=N.nb(a,c,0),f=!0;if(!d)throw new N.La(44);N.Ib(d.mode)&&(b&=-513);if(b&65536&&!N.Xa(d.mode))throw new N.La(54);if(!f&&(c=N.Ed(d,b)))throw new N.La(c);b&512&&!f&&N.truncate(d,0);b&=-131713;d=N.Ec({node:d,path:N.pb(d),flags:b,seekable:!0,position:0,Pa:d.Pa,Zd:[],error:!1});d.Pa.open&&d.Pa.open(d);!e.logReadFiles||b&1||(N.rc||(N.rc={}),a in N.rc||(N.rc[a]=1));return d},close:a=>{if(N.Jb(a))throw new N.La(8);a.tb&&(a.tb=null);try{a.Pa.close&&a.Pa.close(a)}catch(b){throw b; +}finally{N.gd(a.fd)}a.fd=null},Jb:a=>null===a.fd,ab:(a,b,c)=>{if(N.Jb(a))throw new N.La(8);if(!a.seekable||!a.Pa.ab)throw new N.La(70);if(0!=c&&1!=c&&2!=c)throw new N.La(28);a.position=a.Pa.ab(a,b,c);a.Zd=[];return a.position},read:(a,b,c,d,f)=>{if(0>d||0>f)throw new N.La(28);if(N.Jb(a))throw new N.La(8);if(1===(a.flags&2097155))throw new N.La(8);if(N.Xa(a.node.mode))throw new N.La(31);if(!a.Pa.read)throw new N.La(28);var g="undefined"!=typeof f;if(!g)f=a.position;else if(!a.seekable)throw new N.La(70); +b=a.Pa.read(a,b,c,d,f);g||(a.position+=b);return b},write:(a,b,c,d,f,g)=>{if(0>d||0>f)throw new N.La(28);if(N.Jb(a))throw new N.La(8);if(0===(a.flags&2097155))throw new N.La(8);if(N.Xa(a.node.mode))throw new N.La(31);if(!a.Pa.write)throw new N.La(28);a.seekable&&a.flags&1024&&N.ab(a,0,2);var k="undefined"!=typeof f;if(!k)f=a.position;else if(!a.seekable)throw new N.La(70);b=a.Pa.write(a,b,c,d,f,g);k||(a.position+=b);return b},Hb:(a,b,c)=>{if(N.Jb(a))throw new N.La(8);if(0>b||0>=c)throw new N.La(28); +if(0===(a.flags&2097155))throw new N.La(8);if(!N.isFile(a.node.mode)&&!N.Xa(a.node.mode))throw new N.La(43);if(!a.Pa.Hb)throw new N.La(138);a.Pa.Hb(a,b,c)},xb:(a,b,c,d,f)=>{if(0!==(d&2)&&0===(f&2)&&2!==(a.flags&2097155))throw new N.La(2);if(1===(a.flags&2097155))throw new N.La(2);if(!a.Pa.xb)throw new N.La(43);return a.Pa.xb(a,b,c,d,f)},Eb:(a,b,c,d,f)=>a&&a.Pa.Eb?a.Pa.Eb(a,b,c,d,f):0,ge:()=>0,jc:(a,b,c)=>{if(!a.Pa.jc)throw new N.La(59);return a.Pa.jc(a,b,c)},readFile:(a,b={})=>{b.flags=b.flags||0; +b.encoding=b.encoding||"binary";if("utf8"!==b.encoding&&"binary"!==b.encoding)throw Error('Invalid encoding type "'+b.encoding+'"');var c,d=N.open(a,b.flags);a=N.stat(a).size;var f=new Uint8Array(a);N.read(d,f,0,a,0);"utf8"===b.encoding?c=sa(f,0):"binary"===b.encoding&&(c=f);N.close(d);return c},writeFile:(a,b,c={})=>{c.flags=c.flags||577;a=N.open(a,c.flags,c.mode);if("string"==typeof b){var d=new Uint8Array(ta(b)+1);b=A(b,d,0,d.length);N.write(a,d,0,b,void 0,c.dd)}else if(ArrayBuffer.isView(b))N.write(a, +b,0,b.byteLength,void 0,c.dd);else throw Error("Unsupported data type");N.close(a)},cwd:()=>N.Fc,chdir:a=>{a=N.Ta(a,{cb:!0});if(null===a.node)throw new N.La(44);if(!N.Xa(a.node.mode))throw new N.La(54);var b=N.rb(a.node,"x");if(b)throw new N.La(b);N.Fc=a.path},kd:()=>{N.mkdir("/tmp");N.mkdir("/home");N.mkdir("/home/web_user")},jd:()=>{N.mkdir("/dev");N.uc(N.wb(1,3),{read:()=>0,write:(b,c,d,f)=>f});N.Wb("/dev/null",N.wb(1,3));Ya(N.wb(5,0),$a);Ya(N.wb(6,0),ab);N.Wb("/dev/tty",N.wb(5,0));N.Wb("/dev/tty1", +N.wb(6,0));var a=Ta();N.gb("/dev","random",a);N.gb("/dev","urandom",a);N.mkdir("/dev/shm");N.mkdir("/dev/shm/tmp")},md:()=>{N.mkdir("/proc");var a=N.mkdir("/proc/self");N.mkdir("/proc/self/fd");N.Va({Va:()=>{var b=N.createNode(a,"fd",16895,73);b.Na={lookup:(c,d)=>{var f=N.qb(+d);if(!f)throw new N.La(8);c={parent:null,Va:{Rc:"fake"},Na:{readlink:()=>f.path}};return c.parent=c}};return b}},{},"/proc/self/fd")},nd:()=>{e.stdin?N.gb("/dev","stdin",e.stdin):N.symlink("/dev/tty","/dev/stdin");e.stdout? +N.gb("/dev","stdout",null,e.stdout):N.symlink("/dev/tty","/dev/stdout");e.stderr?N.gb("/dev","stderr",null,e.stderr):N.symlink("/dev/tty1","/dev/stderr");N.open("/dev/stdin",0);N.open("/dev/stdout",1);N.open("/dev/stderr",1)},Ic:()=>{N.La||(N.La=function(a,b){this.node=b;this.Pd=function(c){this.Qa=c};this.Pd(a);this.message="FS error"},N.La.prototype=Error(),N.La.prototype.constructor=N.La,[44].forEach(a=>{N.ec[a]=new N.La(a);N.ec[a].stack=""}))},Ud:()=>{N.Ic();N.kb=Array(4096); +N.Va(O,{},"/");N.kd();N.jd();N.md();N.rd={MEMFS:O}},Cb:(a,b,c)=>{N.Cb.ic=!0;N.Ic();e.stdin=a||e.stdin;e.stdout=b||e.stdout;e.stderr=c||e.stderr;N.nd()},je:()=>{N.Cb.ic=!1;for(var a=0;a{var c=0;a&&(c|=365);b&&(c|=146);return c},ae:(a,b)=>{a=N.ac(a,b);return a.exists?a.object:null},ac:(a,b)=>{try{var c=N.Ta(a,{cb:!b});a=c.path}catch(f){}var d={Tb:!1,exists:!1,error:0,name:null,path:null,object:null,Id:!1,Kd:null,Jd:null};try{c=N.Ta(a, +{parent:!0}),d.Id=!0,d.Kd=c.path,d.Jd=c.node,d.name=M(a),c=N.Ta(a,{cb:!b}),d.exists=!0,d.path=c.path,d.object=c.node,d.name=c.node.name,d.Tb="/"===c.path}catch(f){d.error=f.Qa}return d},Cc:(a,b)=>{a="string"==typeof a?a:N.pb(a);for(b=b.split("/").reverse();b.length;){var c=b.pop();if(c){var d=L(a+"/"+c);try{N.mkdir(d)}catch(f){}a=d}}return d},ld:(a,b,c,d,f)=>{a="string"==typeof a?a:N.pb(a);b=L(a+"/"+b);return N.create(b,N.fc(d,f))},Qb:(a,b,c,d,f,g)=>{var k=b;a&&(a="string"==typeof a?a:N.pb(a),k=b? +L(a+"/"+b):a);a=N.fc(d,f);k=N.create(k,a);if(c){if("string"==typeof c){b=Array(c.length);d=0;for(f=c.length;d{a=Sa("string"==typeof a?a:N.pb(a),b);b=N.fc(!!c,!!d);N.gb.nc||(N.gb.nc=64);var f=N.wb(N.gb.nc++,0);N.uc(f,{open:g=>{g.seekable=!1},close:()=>{d&&d.buffer&&d.buffer.length&&d(10)},read:(g,k,h,n)=>{for(var q=0,p=0;p{for(var q=0;q{if(a.kc||a.Bd||a.link||a.Oa)return!0;if("undefined"!=typeof XMLHttpRequest)throw Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread."); +if(ia)try{a.Oa=Wa(ia(a.url),!0),a.Ua=a.Oa.length}catch(b){throw new N.La(29);}else throw Error("Cannot load without read() or XMLHttpRequest.");},Bc:(a,b,c,d,f)=>{function g(){this.mc=!1;this.bb=[]}function k(p,t,x,l,u){p=p.node.Oa;if(u>=p.length)return 0;l=Math.min(p.length-u,l);if(p.slice)for(var w=0;wthis.length-1||0>p)){var t=p%this.chunkSize;return this.Rb(p/this.chunkSize|0)[t]}};g.prototype.$b= +function(p){this.Rb=p};g.prototype.zc=function(){var p=new XMLHttpRequest;p.open("HEAD",c,!1);p.send(null);if(!(200<=p.status&&300>p.status||304===p.status))throw Error("Couldn't load "+c+". Status: "+p.status);var t=Number(p.getResponseHeader("Content-length")),x,l=(x=p.getResponseHeader("Accept-Ranges"))&&"bytes"===x;p=(x=p.getResponseHeader("Content-Encoding"))&&"gzip"===x;var u=1048576;l||(u=t);var w=this;w.$b(C=>{var K=C*u,H=(C+1)*u-1;H=Math.min(H,t-1);if("undefined"==typeof w.bb[C]){var Ga= +w.bb;if(K>H)throw Error("invalid range ("+K+", "+H+") or no bytes requested!");if(H>t-1)throw Error("only "+t+" bytes available! programmer error!");var I=new XMLHttpRequest;I.open("GET",c,!1);t!==u&&I.setRequestHeader("Range","bytes="+K+"-"+H);I.responseType="arraybuffer";I.overrideMimeType&&I.overrideMimeType("text/plain; charset=x-user-defined");I.send(null);if(!(200<=I.status&&300>I.status||304===I.status))throw Error("Couldn't load "+c+". Status: "+I.status);K=void 0!==I.response?new Uint8Array(I.response|| +[]):Wa(I.responseText||"",!0);Ga[C]=K}if("undefined"==typeof w.bb[C])throw Error("doXHR failed!");return w.bb[C]});if(p||!t)u=t=1,u=t=this.Rb(0).length,na("LazyFiles on gzip forces download of the whole file when length is accessed");this.ad=t;this.$c=u;this.mc=!0};if("undefined"!=typeof XMLHttpRequest){if(!fa)throw"Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc";var h=new g;Object.defineProperties(h,{length:{get:function(){this.mc|| +this.zc();return this.ad}},chunkSize:{get:function(){this.mc||this.zc();return this.$c}}});h={kc:!1,Oa:h}}else h={kc:!1,url:c};var n=N.ld(a,b,h,d,f);h.Oa?n.Oa=h.Oa:h.url&&(n.Oa=null,n.url=h.url);Object.defineProperties(n,{Ua:{get:function(){return this.Oa.length}}});var q={};Object.keys(n.Pa).forEach(p=>{var t=n.Pa[p];q[p]=function(){N.dc(n);return t.apply(null,arguments)}});q.read=(p,t,x,l,u)=>{N.dc(n);return k(p,t,x,l,u)};q.xb=(p,t,x)=>{N.dc(n);var l=bb(t);if(!l)throw new N.La(48);k(p,B,l,t,x); +return{Ra:l,yc:!0}};n.Pa=q;return n},Dc:(a,b,c,d,f,g,k,h,n,q)=>{function p(l){function u(w){q&&q();h||N.Qb(a,b,w,d,f,n);g&&g();Ja(x)}eb.ce(l,t,u,()=>{k&&k();Ja(x)})||u(l)}var t=b?Ua(L(a+"/"+b)):a,x="cp "+t;Ia(x);"string"==typeof c?db(c,l=>p(l),k):p(c)},indexedDB:()=>window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,wc:()=>"EM_FS_"+window.location.pathname,xc:20,Gb:"FILE_DATA",ke:(a,b,c)=>{b=b||(()=>{});c=c||(()=>{});var d=N.indexedDB();try{var f=d.open(N.wc(),N.xc)}catch(g){return c(g)}f.onupgradeneeded= +()=>{na("creating db");f.result.createObjectStore(N.Gb)};f.onsuccess=()=>{var g=f.result.transaction([N.Gb],"readwrite"),k=g.objectStore(N.Gb),h=0,n=0,q=a.length;a.forEach(p=>{p=k.put(N.ac(p).object.Oa,p);p.onsuccess=()=>{h++;h+n==q&&(0==n?b():c())};p.onerror=()=>{n++;h+n==q&&(0==n?b():c())}});g.onerror=c};f.onerror=c},de:(a,b,c)=>{b=b||(()=>{});c=c||(()=>{});var d=N.indexedDB();try{var f=d.open(N.wc(),N.xc)}catch(g){return c(g)}f.onupgradeneeded=c;f.onsuccess=()=>{var g=f.result;try{var k=g.transaction([N.Gb], +"readonly")}catch(t){c(t);return}var h=k.objectStore(N.Gb),n=0,q=0,p=a.length;a.forEach(t=>{var x=h.get(t);x.onsuccess=()=>{N.ac(t).exists&&N.unlink(t);N.Qb(Ra(t),M(t),x.result,!0,!0,!0);n++;n+q==p&&(0==q?b():c())};x.onerror=()=>{q++;n+q==p&&(0==q?b():c())}});k.onerror=c};f.onerror=c}};function P(a,b,c){if("/"===b.charAt(0))return b;if(-100===a)a=N.cwd();else{a=N.qb(a);if(!a)throw new N.La(8);a=a.path}if(0==b.length){if(!c)throw new N.La(44);return a}return L(a+"/"+b)} +function fb(a,b,c){try{var d=a(b)}catch(f){if(f&&f.node&&L(b)!==L(N.pb(f.node)))return-54;throw f;}E[c>>2]=d.dev;E[c+4>>2]=0;E[c+8>>2]=d.ino;E[c+12>>2]=d.mode;E[c+16>>2]=d.nlink;E[c+20>>2]=d.uid;E[c+24>>2]=d.gid;E[c+28>>2]=d.rdev;E[c+32>>2]=0;J=[d.size>>>0,(G=d.size,1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];E[c+40>>2]=J[0];E[c+44>>2]=J[1];E[c+48>>2]=4096;E[c+52>>2]=d.blocks;J=[Math.floor(d.atime.getTime()/1E3)>>>0,(G= +Math.floor(d.atime.getTime()/1E3),1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];E[c+56>>2]=J[0];E[c+60>>2]=J[1];E[c+64>>2]=0;J=[Math.floor(d.mtime.getTime()/1E3)>>>0,(G=Math.floor(d.mtime.getTime()/1E3),1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];E[c+72>>2]=J[0];E[c+76>>2]=J[1];E[c+80>>2]=0;J=[Math.floor(d.ctime.getTime()/1E3)>>>0,(G=Math.floor(d.ctime.getTime()/ +1E3),1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];E[c+88>>2]=J[0];E[c+92>>2]=J[1];E[c+96>>2]=0;J=[d.ino>>>0,(G=d.ino,1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];E[c+104>>2]=J[0];E[c+108>>2]=J[1];return 0}var gb=void 0;function hb(){gb+=4;return E[gb-4>>2]}function Q(a){a=N.qb(a);if(!a)throw new N.La(8);return a} +function ib(a){return F[a>>2]+4294967296*E[a+4>>2]}var jb={};function kb(a){for(;a.length;){var b=a.pop();a.pop()(b)}}function lb(a){return this.fromWireType(E[a>>2])}var mb={},nb={},ob={};function pb(a){if(void 0===a)return"_unknown";a=a.replace(/[^a-zA-Z0-9_]/g,"$");var b=a.charCodeAt(0);return 48<=b&&57>=b?"_"+a:a}function qb(a,b){a=pb(a);return(new Function("body","return function "+a+'() {\n "use strict"; return body.apply(this, arguments);\n};\n'))(b)} function rb(a){var b=Error,c=qb(a,function(d){this.name=a;this.message=d;d=Error(d).stack;void 0!==d&&(this.stack=this.toString()+"\n"+d.replace(/^Error(:[^\n]*)?\n/,""))});c.prototype=Object.create(b.prototype);c.prototype.constructor=c;c.prototype.toString=function(){return void 0===this.message?this.name:this.name+": "+this.message};return c}var sb=void 0;function tb(a){throw new sb(a);} function ub(a,b,c){function d(h){h=c(h);h.length!==a.length&&tb("Mismatched type converter count");for(var n=0;n{nb.hasOwnProperty(h)?f[n]=nb[h]:(g.push(h),mb.hasOwnProperty(h)||(mb[h]=[]),mb[h].push(()=>{f[n]=nb[h];++k;k===g.length&&d(f)}))});0===g.length&&d(f)} function vb(a){switch(a){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+a);}}var wb=void 0;function S(a){for(var b="";z[a];)b+=wb[z[a++]];return b}var xb=void 0;function T(a){throw new xb(a);} -function R(a,b,c={}){if(!("argPackAdvance"in b))throw new TypeError("registerType registeredInstance requires argPackAdvance");var d=b.name;a||T('type "'+d+'" must have a positive integer typeid pointer');if(nb.hasOwnProperty(a)){if(c.ud)return;T("Cannot register type '"+d+"' twice")}nb[a]=b;delete ob[a];mb.hasOwnProperty(a)&&(b=mb[a],delete mb[a],b.forEach(f=>f()))}function yb(a){T(a.Ha.Ra.Na.name+" instance already deleted")}var zb=!1;function Ab(){} -function Bb(a){--a.count.value;0===a.count.value&&(a.Va?a.Ya.jb(a.Va):a.Ra.Na.jb(a.La))}function Cb(a,b,c){if(b===c)return a;if(void 0===c.Za)return null;a=Cb(a,b,c.Za);return null===a?null:c.jd(a)}var Db={},Eb=[];function Fb(){for(;Eb.length;){var a=Eb.pop();a.Ha.ub=!1;a["delete"]()}}var Gb=void 0,Hb={};function Ib(a,b){for(void 0===b&&T("ptr should not be undefined");a.Za;)b=a.Gb(b),a=a.Za;return Hb[b]} -function Jb(a,b){b.Ra&&b.La||tb("makeClassHandle requires ptr and ptrType");!!b.Ya!==!!b.Va&&tb("Both smartPtrType and smartPtr must be specified");b.count={value:1};return Kb(Object.create(a,{Ha:{value:b}}))}function Kb(a){if("undefined"===typeof FinalizationRegistry)return Kb=b=>b,a;zb=new FinalizationRegistry(b=>{Bb(b.Ha)});Kb=b=>{var c=b.Ha;c.Va&&zb.register(b,{Ha:c},b);return b};Ab=b=>{zb.unregister(b)};return Kb(a)}function U(){} -function Lb(a,b,c){if(void 0===a[b].Ua){var d=a[b];a[b]=function(){a[b].Ua.hasOwnProperty(arguments.length)||T("Function '"+c+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+a[b].Ua+")!");return a[b].Ua[arguments.length].apply(this,arguments)};a[b].Ua=[];a[b].Ua[d.Ib]=d}} -function Mb(a,b,c){e.hasOwnProperty(a)?((void 0===c||void 0!==e[a].Ua&&void 0!==e[a].Ua[c])&&T("Cannot register public name '"+a+"' twice"),Lb(e,a,a),e.hasOwnProperty(c)&&T("Cannot register multiple overloads of a function with the same number of arguments ("+c+")!"),e[a].Ua[c]=b):(e[a]=b,void 0!==c&&(e[a].ce=c))}function Nb(a,b,c,d,f,g,k,h){this.name=a;this.constructor=b;this.wb=c;this.jb=d;this.Za=f;this.pd=g;this.Gb=k;this.jd=h;this.Hd=[]} -function Ob(a,b,c){for(;b!==c;)b.Gb||T("Expected null or instance of "+c.name+", got an instance of "+b.name),a=b.Gb(a),b=b.Za;return a}function Pb(a,b){if(null===b)return this.fc&&T("null is not a valid "+this.name),0;b.Ha||T('Cannot pass "'+Qb(b)+'" as a '+this.name);b.Ha.La||T("Cannot pass deleted object as a pointer of type "+this.name);return Ob(b.Ha.La,b.Ha.Ra.Na,this.Na)} -function Rb(a,b){if(null===b){this.fc&&T("null is not a valid "+this.name);if(this.Ob){var c=this.lc();null!==a&&a.push(this.jb,c);return c}return 0}b.Ha||T('Cannot pass "'+Qb(b)+'" as a '+this.name);b.Ha.La||T("Cannot pass deleted object as a pointer of type "+this.name);!this.Mb&&b.Ha.Ra.Mb&&T("Cannot convert argument of type "+(b.Ha.Ya?b.Ha.Ya.name:b.Ha.Ra.name)+" to parameter type "+this.name);c=Ob(b.Ha.La,b.Ha.Ra.Na,this.Na);if(this.Ob)switch(void 0===b.Ha.Va&&T("Passing raw pointer to smart pointer is illegal"), -this.Od){case 0:b.Ha.Ya===this?c=b.Ha.Va:T("Cannot convert argument of type "+(b.Ha.Ya?b.Ha.Ya.name:b.Ha.Ra.name)+" to parameter type "+this.name);break;case 1:c=b.Ha.Va;break;case 2:if(b.Ha.Ya===this)c=b.Ha.Va;else{var d=b.clone();c=this.Id(c,Sb(function(){d["delete"]()}));null!==a&&a.push(this.jb,c)}break;default:T("Unsupporting sharing policy")}return c} -function Tb(a,b){if(null===b)return this.fc&&T("null is not a valid "+this.name),0;b.Ha||T('Cannot pass "'+Qb(b)+'" as a '+this.name);b.Ha.La||T("Cannot pass deleted object as a pointer of type "+this.name);b.Ha.Ra.Mb&&T("Cannot convert argument of type "+b.Ha.Ra.name+" to parameter type "+this.name);return Ob(b.Ha.La,b.Ha.Ra.Na,this.Na)} -function V(a,b,c,d){this.name=a;this.Na=b;this.fc=c;this.Mb=d;this.Ob=!1;this.jb=this.Id=this.lc=this.Nc=this.Od=this.Gd=void 0;void 0!==b.Za?this.toWireType=Rb:(this.toWireType=d?Pb:Tb,this.ab=null)}function Ub(a,b,c){e.hasOwnProperty(a)||tb("Replacing nonexistant public symbol");void 0!==e[a].Ua&&void 0!==c?e[a].Ua[c]=b:(e[a]=b,e[a].Ib=c)} -function Vb(a,b){var c=[];return function(){c.length=0;Object.assign(c,arguments);if(a.includes("j")){var d=e["dynCall_"+a];d=c&&c.length?d.apply(null,[b].concat(c)):d.call(null,b)}else d=Aa.get(b).apply(null,c);return d}}function W(a,b){a=S(a);var c=a.includes("j")?Vb(a,b):Aa.get(b);"function"!=typeof c&&T("unknown function pointer with signature "+a+": "+b);return c}var Wb=void 0;function Xb(a){a=Yb(a);var b=S(a);X(a);return b} -function Zb(a,b){function c(g){f[g]||nb[g]||(ob[g]?ob[g].forEach(c):(d.push(g),f[g]=!0))}var d=[],f={};b.forEach(c);throw new Wb(a+": "+d.map(Xb).join([", "]));}function $b(a,b){for(var c=[],d=0;d>2]);return c} +function R(a,b,c={}){if(!("argPackAdvance"in b))throw new TypeError("registerType registeredInstance requires argPackAdvance");var d=b.name;a||T('type "'+d+'" must have a positive integer typeid pointer');if(nb.hasOwnProperty(a)){if(c.zd)return;T("Cannot register type '"+d+"' twice")}nb[a]=b;delete ob[a];mb.hasOwnProperty(a)&&(b=mb[a],delete mb[a],b.forEach(f=>f()))}function yb(a){T(a.Ma.Wa.Sa.name+" instance already deleted")}var zb=!1;function Ab(){} +function Bb(a){--a.count.value;0===a.count.value&&(a.$a?a.eb.ob(a.$a):a.Wa.Sa.ob(a.Ra))}function Cb(a,b,c){if(b===c)return a;if(void 0===c.fb)return null;a=Cb(a,b,c.fb);return null===a?null:c.od(a)}var Db={},Eb=[];function Fb(){for(;Eb.length;){var a=Eb.pop();a.Ma.Bb=!1;a["delete"]()}}var Gb=void 0,Hb={};function Ib(a,b){for(void 0===b&&T("ptr should not be undefined");a.fb;)b=a.Nb(b),a=a.fb;return Hb[b]} +function Jb(a,b){b.Wa&&b.Ra||tb("makeClassHandle requires ptr and ptrType");!!b.eb!==!!b.$a&&tb("Both smartPtrType and smartPtr must be specified");b.count={value:1};return Kb(Object.create(a,{Ma:{value:b}}))}function Kb(a){if("undefined"===typeof FinalizationRegistry)return Kb=b=>b,a;zb=new FinalizationRegistry(b=>{Bb(b.Ma)});Kb=b=>{var c=b.Ma;c.$a&&zb.register(b,{Ma:c},b);return b};Ab=b=>{zb.unregister(b)};return Kb(a)}function U(){} +function Lb(a,b,c){if(void 0===a[b].Za){var d=a[b];a[b]=function(){a[b].Za.hasOwnProperty(arguments.length)||T("Function '"+c+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+a[b].Za+")!");return a[b].Za[arguments.length].apply(this,arguments)};a[b].Za=[];a[b].Za[d.Pb]=d}} +function Mb(a,b,c){e.hasOwnProperty(a)?((void 0===c||void 0!==e[a].Za&&void 0!==e[a].Za[c])&&T("Cannot register public name '"+a+"' twice"),Lb(e,a,a),e.hasOwnProperty(c)&&T("Cannot register multiple overloads of a function with the same number of arguments ("+c+")!"),e[a].Za[c]=b):(e[a]=b,void 0!==c&&(e[a].he=c))}function Nb(a,b,c,d,f,g,k,h){this.name=a;this.constructor=b;this.Db=c;this.ob=d;this.fb=f;this.ud=g;this.Nb=k;this.od=h;this.Md=[]} +function Ob(a,b,c){for(;b!==c;)b.Nb||T("Expected null or instance of "+c.name+", got an instance of "+b.name),a=b.Nb(a),b=b.fb;return a}function Pb(a,b){if(null===b)return this.lc&&T("null is not a valid "+this.name),0;b.Ma||T('Cannot pass "'+Qb(b)+'" as a '+this.name);b.Ma.Ra||T("Cannot pass deleted object as a pointer of type "+this.name);return Ob(b.Ma.Ra,b.Ma.Wa.Sa,this.Sa)} +function Rb(a,b){if(null===b){this.lc&&T("null is not a valid "+this.name);if(this.Ub){var c=this.qc();null!==a&&a.push(this.ob,c);return c}return 0}b.Ma||T('Cannot pass "'+Qb(b)+'" as a '+this.name);b.Ma.Ra||T("Cannot pass deleted object as a pointer of type "+this.name);!this.Sb&&b.Ma.Wa.Sb&&T("Cannot convert argument of type "+(b.Ma.eb?b.Ma.eb.name:b.Ma.Wa.name)+" to parameter type "+this.name);c=Ob(b.Ma.Ra,b.Ma.Wa.Sa,this.Sa);if(this.Ub)switch(void 0===b.Ma.$a&&T("Passing raw pointer to smart pointer is illegal"), +this.Td){case 0:b.Ma.eb===this?c=b.Ma.$a:T("Cannot convert argument of type "+(b.Ma.eb?b.Ma.eb.name:b.Ma.Wa.name)+" to parameter type "+this.name);break;case 1:c=b.Ma.$a;break;case 2:if(b.Ma.eb===this)c=b.Ma.$a;else{var d=b.clone();c=this.Nd(c,Sb(function(){d["delete"]()}));null!==a&&a.push(this.ob,c)}break;default:T("Unsupporting sharing policy")}return c} +function Tb(a,b){if(null===b)return this.lc&&T("null is not a valid "+this.name),0;b.Ma||T('Cannot pass "'+Qb(b)+'" as a '+this.name);b.Ma.Ra||T("Cannot pass deleted object as a pointer of type "+this.name);b.Ma.Wa.Sb&&T("Cannot convert argument of type "+b.Ma.Wa.name+" to parameter type "+this.name);return Ob(b.Ma.Ra,b.Ma.Wa.Sa,this.Sa)} +function V(a,b,c,d){this.name=a;this.Sa=b;this.lc=c;this.Sb=d;this.Ub=!1;this.ob=this.Nd=this.qc=this.Sc=this.Td=this.Ld=void 0;void 0!==b.fb?this.toWireType=Rb:(this.toWireType=d?Pb:Tb,this.hb=null)}function Ub(a,b,c){e.hasOwnProperty(a)||tb("Replacing nonexistant public symbol");void 0!==e[a].Za&&void 0!==c?e[a].Za[c]=b:(e[a]=b,e[a].Pb=c)} +function Vb(a,b){var c=[];return function(){c.length=0;Object.assign(c,arguments);if(a.includes("j")){var d=e["dynCall_"+a];d=c&&c.length?d.apply(null,[b].concat(c)):d.call(null,b)}else d=za.get(b).apply(null,c);return d}}function W(a,b){a=S(a);var c=a.includes("j")?Vb(a,b):za.get(b);"function"!=typeof c&&T("unknown function pointer with signature "+a+": "+b);return c}var Wb=void 0;function Xb(a){a=Yb(a);var b=S(a);X(a);return b} +function Zb(a,b){function c(g){f[g]||nb[g]||(ob[g]?ob[g].forEach(c):(d.push(g),f[g]=!0))}var d=[],f={};b.forEach(c);throw new Wb(a+": "+d.map(Xb).join([", "]));}function $b(a,b){for(var c=[],d=0;d>2]);return c} function ac(a){var b=Function;if(!(b instanceof Function))throw new TypeError("new_ called with constructor type "+typeof b+" which is not a function");var c=qb(b.name||"unknownFunctionName",function(){});c.prototype=b.prototype;c=new c;a=b.apply(c,a);return a instanceof Object?a:c} -function bc(a,b,c,d,f){var g=b.length;2>g&&T("argTypes array size mismatch! Must at least get return value and 'this' types!");var k=null!==b[1]&&null!==c,h=!1;for(c=1;c{a||T("Cannot use deleted val. handle = "+a);return Y[a].value},Sb=a=>{switch(a){case void 0:return 1;case null:return 2;case !0:return 3;case !1:return 4;default:var b=cc.length?cc.pop():Y.length;Y[b]={oc:1,value:a};return b}};function Qb(a){if(null===a)return"null";var b=typeof a;return"object"===b||"array"===b||"function"===b?a.toString():""+a} -function fc(a,b){switch(b){case 2:return function(c){return this.fromWireType(xa[c>>2])};case 3:return function(c){return this.fromWireType(ya[c>>3])};default:throw new TypeError("Unknown float type: "+a);}} -function gc(a,b,c){switch(b){case 0:return c?function(d){return A[d]}:function(d){return z[d]};case 1:return c?function(d){return C[d>>1]}:function(d){return wa[d>>1]};case 2:return c?function(d){return D[d>>2]}:function(d){return E[d>>2]};default:throw new TypeError("Unknown integer type: "+a);}}var hc="undefined"!=typeof TextDecoder?new TextDecoder("utf-16le"):void 0; -function ic(a,b){var c=a>>1;for(var d=c+b/2;!(c>=d)&&wa[c];)++c;c<<=1;if(32=b/2);++d){var f=C[a+2*d>>1];if(0==f)break;c+=String.fromCharCode(f)}return c}function jc(a,b,c){void 0===c&&(c=2147483647);if(2>c)return 0;c-=2;var d=b;c=c<2*a.length?c/2:a.length;for(var f=0;f>1]=a.charCodeAt(f),b+=2;C[b>>1]=0;return b-d}function kc(a){return 2*a.length} -function lc(a,b){for(var c=0,d="";!(c>=b/4);){var f=D[a+4*c>>2];if(0==f)break;++c;65536<=f?(f-=65536,d+=String.fromCharCode(55296|f>>10,56320|f&1023)):d+=String.fromCharCode(f)}return d}function mc(a,b,c){void 0===c&&(c=2147483647);if(4>c)return 0;var d=b;c=d+c-4;for(var f=0;f=g){var k=a.charCodeAt(++f);g=65536+((g&1023)<<10)|k&1023}D[b>>2]=g;b+=4;if(b+4>c)break}D[b>>2]=0;return b-d} -function nc(a){for(var b=0,c=0;c=d&&++c;b+=4}return b}function oc(a,b){var c=nb[a];void 0===c&&T(b+" has unknown type "+Xb(a));return c}var pc={};function qc(a){var b=pc[a];return void 0===b?S(a):b}var rc=[];function sc(a){var b=rc.length;rc.push(a);return b}function tc(a,b){for(var c=Array(a),d=0;d>2],"parameter "+d);return c}var uc=[];function vc(a){var b=ua(a)+1,c=wc(b);c&&ta(a,A,c,b);return c} -function xc(a,b,c){function d(n){return(n=n.toTimeString().match(/\(([A-Za-z ]+)\)$/))?n[1]:"GMT"}var f=(new Date).getFullYear(),g=new Date(f,0,1),k=new Date(f,6,1);f=g.getTimezoneOffset();var h=k.getTimezoneOffset();D[a>>2]=60*Math.max(f,h);D[b>>2]=Number(f!=h);a=d(g);b=d(k);a=vc(a);b=vc(b);h>2]=a,E[c+4>>2]=b):(E[c>>2]=b,E[c+4>>2]=a)}function yc(a,b,c){yc.Yc||(yc.Yc=!0,xc(a,b,c))}var zc;zc=ha?()=>{var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:()=>performance.now();var Ac={}; +function bc(a,b,c,d,f){var g=b.length;2>g&&T("argTypes array size mismatch! Must at least get return value and 'this' types!");var k=null!==b[1]&&null!==c,h=!1;for(c=1;c{a||T("Cannot use deleted val. handle = "+a);return Y[a].value},Sb=a=>{switch(a){case void 0:return 1;case null:return 2;case !0:return 3;case !1:return 4;default:var b=cc.length?cc.pop():Y.length;Y[b]={tc:1,value:a};return b}};function Qb(a){if(null===a)return"null";var b=typeof a;return"object"===b||"array"===b||"function"===b?a.toString():""+a} +function fc(a,b){switch(b){case 2:return function(c){return this.fromWireType(wa[c>>2])};case 3:return function(c){return this.fromWireType(xa[c>>3])};default:throw new TypeError("Unknown float type: "+a);}} +function gc(a,b,c){switch(b){case 0:return c?function(d){return B[d]}:function(d){return z[d]};case 1:return c?function(d){return D[d>>1]}:function(d){return va[d>>1]};case 2:return c?function(d){return E[d>>2]}:function(d){return F[d>>2]};default:throw new TypeError("Unknown integer type: "+a);}}var hc="undefined"!=typeof TextDecoder?new TextDecoder("utf-16le"):void 0; +function ic(a,b){var c=a>>1;for(var d=c+b/2;!(c>=d)&&va[c];)++c;c<<=1;if(32=b/2);++d){var f=D[a+2*d>>1];if(0==f)break;c+=String.fromCharCode(f)}return c}function jc(a,b,c){void 0===c&&(c=2147483647);if(2>c)return 0;c-=2;var d=b;c=c<2*a.length?c/2:a.length;for(var f=0;f>1]=a.charCodeAt(f),b+=2;D[b>>1]=0;return b-d}function kc(a){return 2*a.length} +function lc(a,b){for(var c=0,d="";!(c>=b/4);){var f=E[a+4*c>>2];if(0==f)break;++c;65536<=f?(f-=65536,d+=String.fromCharCode(55296|f>>10,56320|f&1023)):d+=String.fromCharCode(f)}return d}function mc(a,b,c){void 0===c&&(c=2147483647);if(4>c)return 0;var d=b;c=d+c-4;for(var f=0;f=g){var k=a.charCodeAt(++f);g=65536+((g&1023)<<10)|k&1023}E[b>>2]=g;b+=4;if(b+4>c)break}E[b>>2]=0;return b-d} +function nc(a){for(var b=0,c=0;c=d&&++c;b+=4}return b}function oc(a,b){var c=nb[a];void 0===c&&T(b+" has unknown type "+Xb(a));return c}var pc={};function qc(a){var b=pc[a];return void 0===b?S(a):b}var rc=[];function sc(a){var b=rc.length;rc.push(a);return b}function tc(a,b){for(var c=Array(a),d=0;d>2],"parameter "+d);return c}var uc=[];function vc(a){var b=ta(a)+1,c=wc(b);c&&A(a,B,c,b);return c} +function xc(a,b,c){function d(n){return(n=n.toTimeString().match(/\(([A-Za-z ]+)\)$/))?n[1]:"GMT"}var f=(new Date).getFullYear(),g=new Date(f,0,1),k=new Date(f,6,1);f=g.getTimezoneOffset();var h=k.getTimezoneOffset();E[a>>2]=60*Math.max(f,h);E[b>>2]=Number(f!=h);a=d(g);b=d(k);a=vc(a);b=vc(b);h>2]=a,F[c+4>>2]=b):(F[c>>2]=b,F[c+4>>2]=a)}function yc(a,b,c){yc.cd||(yc.cd=!0,xc(a,b,c))}var zc;zc=ha?()=>{var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:()=>performance.now();var Ac={}; function Bc(){if(!Cc){var a={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:da||"./this.program"},b;for(b in Ac)void 0===Ac[b]?delete a[b]:a[b]=Ac[b];var c=[];for(b in a)c.push(b+"="+a[b]);Cc=c}return Cc}var Cc;function Dc(a){return 0===a%4&&(0!==a%100||0===a%400)}var Ec=[31,29,31,30,31,30,31,31,30,31,30,31],Fc=[31,28,31,30,31,30,31,31,30,31,30,31]; -function Gc(a,b,c,d){function f(l,t,v){for(l="number"==typeof l?l.toString():l||"";l.lengthK?-1:0B-l.getDate())t-=B-l.getDate()+1,l.setDate(1),11>v?l.setMonth(v+1):(l.setMonth(0),l.setFullYear(l.getFullYear()+1));else{l.setDate(l.getDate()+t);break}}v=new Date(l.getFullYear()+1,0,4);t=h(new Date(l.getFullYear(), -0,4));v=h(v);return 0>=k(t,l)?0>=k(v,l)?l.getFullYear()+1:l.getFullYear():l.getFullYear()-1}var q=D[d+40>>2];d={Sd:D[d>>2],Rd:D[d+4>>2],Sb:D[d+8>>2],qc:D[d+12>>2],Tb:D[d+16>>2],tb:D[d+20>>2],gb:D[d+24>>2],sb:D[d+28>>2],ge:D[d+32>>2],Qd:D[d+36>>2],Td:q?y(q):""};c=y(c);q={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d", -"%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"};for(var p in q)c=c.replace(new RegExp(p,"g"),q[p]);var r="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),w="January February March April May June July August September October November December".split(" ");q={"%a":function(l){return r[l.gb].substring(0,3)},"%A":function(l){return r[l.gb]},"%b":function(l){return w[l.Tb].substring(0,3)},"%B":function(l){return w[l.Tb]}, -"%C":function(l){return g((l.tb+1900)/100|0,2)},"%d":function(l){return g(l.qc,2)},"%e":function(l){return f(l.qc,2," ")},"%g":function(l){return n(l).toString().substring(2)},"%G":function(l){return n(l)},"%H":function(l){return g(l.Sb,2)},"%I":function(l){l=l.Sb;0==l?l=12:12l.Sb?"AM":"PM"},"%S":function(l){return g(l.Sd,2)},"%t":function(){return"\t"},"%u":function(l){return l.gb||7},"%U":function(l){return g(Math.floor((l.sb+7-l.gb)/7),2)},"%V":function(l){var t=Math.floor((l.sb+7-(l.gb+6)%7)/7);2>=(l.gb+371-l.sb-2)%7&&t++;if(t)53==t&&(v=(l.gb+371-l.sb)%7,4==v||3==v&&Dc(l.tb)||(t=1));else{t=52;var v=(l.gb+7-l.sb-1)%7;(4==v||5==v&&Dc(l.tb%400-1))&&t++}return g(t,2)},"%w":function(l){return l.gb},"%W":function(l){return g(Math.floor((l.sb+7-(l.gb+6)%7)/7),2)}, -"%y":function(l){return(l.tb+1900).toString().substring(2)},"%Y":function(l){return l.tb+1900},"%z":function(l){l=l.Qd;var t=0<=l;l=Math.abs(l)/60;return(t?"+":"-")+String("0000"+(l/60*100+l%60)).slice(-4)},"%Z":function(l){return l.Td},"%%":function(){return"%"}};c=c.replace(/%%/g,"\x00\x00");for(p in q)c.includes(p)&&(c=c.replace(new RegExp(p,"g"),q[p](d)));c=c.replace(/\0\0/g,"%");p=Wa(c,!1);if(p.length>b)return 0;A.set(p,a);return p.length-1} -function Hc(a,b,c,d){a||(a=this);this.parent=a;this.Qa=a.Qa;this.Db=null;this.id=N.Bd++;this.name=b;this.mode=c;this.Ia={};this.Ka={};this.rdev=d}Object.defineProperties(Hc.prototype,{read:{get:function(){return 365===(this.mode&365)},set:function(a){a?this.mode|=365:this.mode&=-366}},write:{get:function(){return 146===(this.mode&146)},set:function(a){a?this.mode|=146:this.mode&=-147}},wd:{get:function(){return N.Sa(this.mode)}},ec:{get:function(){return N.Lb(this.mode)}}});N.Pc=Hc;N.Pd();var eb; -e.FS_createPath=N.xc;e.FS_createDataFile=N.Jb;e.FS_createPreloadedFile=N.yc;e.FS_unlink=N.unlink;e.FS_createLazyFile=N.wc;e.FS_createDevice=N.$a;sb=e.InternalError=rb("InternalError");for(var Ic=Array(256),Jc=0;256>Jc;++Jc)Ic[Jc]=String.fromCharCode(Jc);wb=Ic;xb=e.BindingError=rb("BindingError"); -U.prototype.isAliasOf=function(a){if(!(this instanceof U&&a instanceof U))return!1;var b=this.Ha.Ra.Na,c=this.Ha.La,d=a.Ha.Ra.Na;for(a=a.Ha.La;b.Za;)c=b.Gb(c),b=b.Za;for(;d.Za;)a=d.Gb(a),d=d.Za;return b===d&&c===a}; -U.prototype.clone=function(){this.Ha.La||yb(this);if(this.Ha.Fb)return this.Ha.count.value+=1,this;var a=Kb,b=Object,c=b.create,d=Object.getPrototypeOf(this),f=this.Ha;a=a(c.call(b,d,{Ha:{value:{count:f.count,ub:f.ub,Fb:f.Fb,La:f.La,Ra:f.Ra,Va:f.Va,Ya:f.Ya}}}));a.Ha.count.value+=1;a.Ha.ub=!1;return a};U.prototype["delete"]=function(){this.Ha.La||yb(this);this.Ha.ub&&!this.Ha.Fb&&T("Object already scheduled for deletion");Ab(this);Bb(this.Ha);this.Ha.Fb||(this.Ha.Va=void 0,this.Ha.La=void 0)}; -U.prototype.isDeleted=function(){return!this.Ha.La};U.prototype.deleteLater=function(){this.Ha.La||yb(this);this.Ha.ub&&!this.Ha.Fb&&T("Object already scheduled for deletion");Eb.push(this);1===Eb.length&&Gb&&Gb(Fb);this.Ha.ub=!0;return this};e.getInheritedInstanceCount=function(){return Object.keys(Hb).length};e.getLiveInheritedInstances=function(){var a=[],b;for(b in Hb)Hb.hasOwnProperty(b)&&a.push(Hb[b]);return a};e.flushPendingDeletes=Fb;e.setDelayFunction=function(a){Gb=a;Eb.length&&Gb&&Gb(Fb)}; -V.prototype.rd=function(a){this.Nc&&(a=this.Nc(a));return a};V.prototype.Bc=function(a){this.jb&&this.jb(a)};V.prototype.argPackAdvance=8;V.prototype.readValueFromPointer=lb;V.prototype.deleteObject=function(a){if(null!==a)a["delete"]()}; -V.prototype.fromWireType=function(a){function b(){return this.Ob?Jb(this.Na.wb,{Ra:this.Gd,La:c,Ya:this,Va:a}):Jb(this.Na.wb,{Ra:this,La:a})}var c=this.rd(a);if(!c)return this.Bc(a),null;var d=Ib(this.Na,c);if(void 0!==d){if(0===d.Ha.count.value)return d.Ha.La=c,d.Ha.Va=a,d.clone();d=d.clone();this.Bc(a);return d}d=this.Na.pd(c);d=Db[d];if(!d)return b.call(this);d=this.Mb?d.bd:d.pointerType;var f=Cb(c,this.Na,d.Na);return null===f?b.call(this):this.Ob?Jb(d.Na.wb,{Ra:d,La:f,Ya:this,Va:a}):Jb(d.Na.wb, -{Ra:d,La:f})};Wb=e.UnboundTypeError=rb("UnboundTypeError");e.count_emval_handles=function(){for(var a=0,b=5;bf?-28:N.zc(d,f).fd;case 1:case 2:return 0;case 3:return d.flags;case 4:return f=hb(),d.flags|=f,0;case 5:return f=hb(),C[f+0>>1]=2,0;case 6:case 7:return 0;case 16:case 8:return-28;case 9:return D[Kc()>>2]=28,-1;default:return-28}}catch(g){if("undefined"== -typeof N||!(g instanceof N.Ga))throw g;return-g.Ma}},W:function(a,b){try{var c=Q(a);return fb(N.stat,c.path,b)}catch(d){if("undefined"==typeof N||!(d instanceof N.Ga))throw d;return-d.Ma}},B:function(a,b,c){try{b=c+2097152>>>0<4194305-!!b?(b>>>0)+4294967296*c:NaN;if(isNaN(b))return-61;N.od(a,b);return 0}catch(d){if("undefined"==typeof N||!(d instanceof N.Ga))throw d;return-d.Ma}},R:function(a,b){try{if(0===b)return-28;var c=N.cwd(),d=ua(c)+1;if(b>2]=0;case 21520:return d.tty?-28:-59;case 21531:return f=hb(),N.dc(d,b,f);case 21523:return d.tty?0:-59;case 21524:return d.tty?0:-59;default:x("bad ioctl syscall "+b)}}catch(g){if("undefined"==typeof N||!(g instanceof N.Ga))throw g; -return-g.Ma}},U:function(a,b){try{return a=y(a),fb(N.lstat,a,b)}catch(c){if("undefined"==typeof N||!(c instanceof N.Ga))throw c;return-c.Ma}},O:function(a,b,c){try{return b=y(b),b=P(a,b),b=L(b),"/"===b[b.length-1]&&(b=b.substr(0,b.length-1)),N.mkdir(b,c,0),0}catch(d){if("undefined"==typeof N||!(d instanceof N.Ga))throw d;return-d.Ma}},T:function(a,b,c,d){try{b=y(b);var f=d&256;b=P(a,b,d&4096);return fb(f?N.lstat:N.stat,b,c)}catch(g){if("undefined"==typeof N||!(g instanceof N.Ga))throw g;return-g.Ma}}, -s:function(a,b,c,d){gb=d;try{b=y(b);b=P(a,b);var f=d?hb():0;return N.open(b,c,f).fd}catch(g){if("undefined"==typeof N||!(g instanceof N.Ga))throw g;return-g.Ma}},L:function(a,b,c,d){try{b=y(b);b=P(a,b);if(0>=d)return-28;var f=N.readlink(b),g=Math.min(d,ua(f)),k=A[c+g];ta(f,z,c,d+1);A[c+g]=k;return g}catch(h){if("undefined"==typeof N||!(h instanceof N.Ga))throw h;return-h.Ma}},K:function(a,b,c,d){try{return b=y(b),d=y(d),b=P(a,b),d=P(c,d),N.rename(b,d),0}catch(f){if("undefined"==typeof N||!(f instanceof -N.Ga))throw f;return-f.Ma}},p:function(a){try{return a=y(a),N.rmdir(a),0}catch(b){if("undefined"==typeof N||!(b instanceof N.Ga))throw b;return-b.Ma}},V:function(a,b){try{return a=y(a),fb(N.stat,a,b)}catch(c){if("undefined"==typeof N||!(c instanceof N.Ga))throw c;return-c.Ma}},q:function(a,b,c){try{return b=y(b),b=P(a,b),0===c?N.unlink(b):512===c?N.rmdir(b):x("Invalid flags passed to unlinkat"),0}catch(d){if("undefined"==typeof N||!(d instanceof N.Ga))throw d;return-d.Ma}},I:function(a,b,c){try{b= -y(b);b=P(a,b,!0);if(c){var d=ib(c),f=D[c+8>>2];g=1E3*d+f/1E6;c+=16;d=ib(c);f=D[c+8>>2];k=1E3*d+f/1E6}else var g=Date.now(),k=g;N.Vd(b,g,k);return 0}catch(h){if("undefined"==typeof N||!(h instanceof N.Ga))throw h;return-h.Ma}},h:function(a){var b=jb[a];delete jb[a];var c=b.lc,d=b.jb,f=b.Fc,g=f.map(k=>k.td).concat(f.map(k=>k.Md));ub([a],g,k=>{var h={};f.forEach((n,q)=>{var p=k[q],r=n.Kb,w=n.sd,l=k[q+f.length],t=n.Ld,v=n.Nd;h[n.ld]={read:B=>p.fromWireType(r(w,B)),write:(B,K)=>{var H=[];t(v,B,l.toWireType(H, -K));kb(H)}}});return[{name:b.name,fromWireType:function(n){var q={},p;for(p in h)q[p]=h[p].read(n);d(n);return q},toWireType:function(n,q){for(var p in h)if(!(p in q))throw new TypeError('Missing field: "'+p+'"');var r=c();for(p in h)h[p].write(r,q[p]);null!==n&&n.push(d,r);return r},argPackAdvance:8,readValueFromPointer:lb,ab:d}]})},C:function(){},ca:function(a,b,c,d,f){var g=vb(c);b=S(b);R(a,{name:b,fromWireType:function(k){return!!k},toWireType:function(k,h){return h?d:f},argPackAdvance:8,readValueFromPointer:function(k){if(1=== -c)var h=A;else if(2===c)h=C;else if(4===c)h=D;else throw new TypeError("Unknown boolean type size: "+b);return this.fromWireType(h[k>>g])},ab:null})},F:function(a,b,c,d,f,g,k,h,n,q,p,r,w){p=S(p);g=W(f,g);h&&(h=W(k,h));q&&(q=W(n,q));w=W(r,w);var l=pb(p);Mb(l,function(){Zb("Cannot construct "+p+" due to unbound types",[d])});ub([a,b,c],d?[d]:[],function(t){t=t[0];if(d){var v=t.Na;var B=v.wb}else B=U.prototype;t=qb(l,function(){if(Object.getPrototypeOf(this)!==K)throw new xb("Use 'new' to construct "+ -p);if(void 0===H.nb)throw new xb(p+" has no accessible constructor");var I=H.nb[arguments.length];if(void 0===I)throw new xb("Tried to invoke ctor of "+p+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(H.nb).toString()+") parameters instead!");return I.apply(this,arguments)});var K=Object.create(B,{constructor:{value:t}});t.prototype=K;var H=new Nb(p,t,K,w,v,g,h,q);v=new V(p,H,!0,!1);B=new V(p+"*",H,!1,!1);var Ga=new V(p+" const*",H,!1,!0);Db[a]={pointerType:B, -bd:Ga};Ub(l,t);return[v,B,Ga]})},z:function(a,b,c,d,f,g){0{Zb("Cannot construct "+h.name+" due to unbound types",k)}; -ub([],k,function(q){q.splice(1,0,null);h.Na.nb[b-1]=bc(n,q,null,f,g);return[]});return[]})},d:function(a,b,c,d,f,g,k,h){var n=$b(c,d);b=S(b);g=W(f,g);ub([],[a],function(q){function p(){Zb("Cannot call "+r+" due to unbound types",n)}q=q[0];var r=q.name+"."+b;b.startsWith("@@")&&(b=Symbol[b.substring(2)]);h&&q.Na.Hd.push(b);var w=q.Na.wb,l=w[b];void 0===l||void 0===l.Ua&&l.className!==q.name&&l.Ib===c-2?(p.Ib=c-2,p.className=q.name,w[b]=p):(Lb(w,b,r),w[b].Ua[c-2]=p);ub([],n,function(t){t=bc(r,t,q,g, -k);void 0===w[b].Ua?(t.Ib=c-2,w[b]=t):w[b].Ua[c-2]=t;return[]});return[]})},ba:function(a,b){b=S(b);R(a,{name:b,fromWireType:function(c){var d=ec(c);dc(c);return d},toWireType:function(c,d){return Sb(d)},argPackAdvance:8,readValueFromPointer:lb,ab:null})},v:function(a,b,c){c=vb(c);b=S(b);R(a,{name:b,fromWireType:function(d){return d},toWireType:function(d,f){return f},argPackAdvance:8,readValueFromPointer:fc(b,c),ab:null})},da:function(a,b,c,d,f,g){var k=$b(b,c);a=S(a);f=W(d,f);Mb(a,function(){Zb("Cannot call "+ -a+" due to unbound types",k)},b-1);ub([],k,function(h){h=[h[0],null].concat(h.slice(1));Ub(a,bc(a,h,null,f,g),b-1);return[]})},g:function(a,b,c,d,f){b=S(b);-1===f&&(f=4294967295);f=vb(c);var g=h=>h;if(0===d){var k=32-8*c;g=h=>h<>>k}c=b.includes("unsigned")?function(h,n){return n>>>0}:function(h,n){return n};R(a,{name:b,fromWireType:g,toWireType:c,argPackAdvance:8,readValueFromPointer:gc(b,f,0!==d),ab:null})},c:function(a,b,c){function d(g){g>>=2;var k=E;return new f(va,k[g+1],k[g])}var f=[Int8Array, -Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][b];c=S(c);R(a,{name:c,fromWireType:d,argPackAdvance:8,readValueFromPointer:d},{ud:!0})},w:function(a,b){b=S(b);var c="std::string"===b;R(a,{name:b,fromWireType:function(d){var f=E[d>>2],g=d+4;if(c)for(var k=g,h=0;h<=f;++h){var n=g+h;if(h==f||0==z[n]){k=y(k,n-k);if(void 0===q)var q=k;else q+=String.fromCharCode(0),q+=k;k=n+1}}else{q=Array(f);for(h=0;h>2]=k;if(c&&g)ta(f,z,n,k+1);else if(g)for(g=0;gwa;var h=1}else 4===b&&(d=lc,f=mc,g=nc,k=()=>E,h=2);R(a,{name:c,fromWireType:function(n){for(var q=E[n>>2],p=k(),r,w=n+4,l=0;l<=q;++l){var t=n+4+l*b;if(l==q||0==p[t>>h])w=d(w,t-w),void 0===r?r=w:(r+=String.fromCharCode(0),r+=w),w=t+b}X(n);return r},toWireType:function(n,q){"string"!=typeof q&&T("Cannot pass non-string to C++ string type "+c);var p=g(q),r=wc(4+p+ -b);E[r>>2]=p>>h;f(q,r+4,p+b);null!==n&&n.push(X,r);return r},argPackAdvance:8,readValueFromPointer:lb,ab:function(n){X(n)}})},i:function(a,b,c,d,f,g){jb[a]={name:S(b),lc:W(c,d),jb:W(f,g),Fc:[]}},f:function(a,b,c,d,f,g,k,h,n,q){jb[a].Fc.push({ld:S(b),td:c,Kb:W(d,f),sd:g,Md:k,Ld:W(h,n),Nd:q})},ea:function(a,b){b=S(b);R(a,{xd:!0,name:b,argPackAdvance:0,fromWireType:function(){},toWireType:function(){}})},u:function(){return Date.now()},x:function(a,b,c){a=ec(a);b=oc(b,"emval::as");var d=[],f=Sb(d);E[c>> -2]=f;return b.toWireType(d,a)},ja:function(a,b,c,d){a=rc[a];b=ec(b);c=qc(c);a(b,c,null,d)},ha:dc,ia:function(a,b){var c=tc(a,b),d=c[0];b=d.name+"_$"+c.slice(1).map(function(p){return p.name}).join("_")+"$";var f=uc[b];if(void 0!==f)return f;f=["retType"];for(var g=[d],k="",h=0;h>2]=a.getSeconds();D[b+4>>2]=a.getMinutes();D[b+8>>2]=a.getHours();D[b+12>>2]=a.getDate();D[b+16>>2]=a.getMonth();D[b+20>>2]=a.getFullYear()-1900;D[b+24>>2]=a.getDay();var c=new Date(a.getFullYear(),0,1);D[b+28>>2]=(a.getTime()-c.getTime())/864E5|0;D[b+36>>2]=-(60*a.getTimezoneOffset());var d=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();c=c.getTimezoneOffset();D[b+32>>2]=(d!=c&&a.getTimezoneOffset()== -Math.min(c,d))|0},M:function(a,b,c,d,f,g){try{var k=N.lb(d);if(!k)return-8;var h=N.qb(k,a,f,b,c),n=h.La;D[g>>2]=h.tc;return n}catch(q){if("undefined"==typeof N||!(q instanceof N.Ga))throw q;return-q.Ma}},N:function(a,b,c,d,f,g){try{var k=N.lb(f);if(k&&c&2){var h=z.slice(a,a+b);N.yb(k,h,g,b,d)}}catch(n){if("undefined"==typeof N||!(n instanceof N.Ga))throw n;return-n.Ma}},$:yc,j:function(){x("")},J:function(){return 2147483648},t:zc,m:function(a){var b=z.length;a>>>=0;if(2147483648=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);var f=Math;d=Math.max(a,d);f=f.min.call(f,2147483648,d+(65536-d%65536)%65536);a:{try{pa.grow(f-va.byteLength+65535>>>16);za();var g=1;break a}catch(k){}g=void 0}if(g)return!0}return!1},P:function(a,b){var c=0;Bc().forEach(function(d,f){var g=b+c;f=E[a+4*f>>2]=g;for(g=0;g>0]=d.charCodeAt(g);A[f>>0]=0;c+=d.length+1});return 0},Q:function(a,b){var c=Bc();E[a>>2]=c.length;var d=0;c.forEach(function(f){d+=f.length+1});E[b>>2]= -d;return 0},k:function(a){try{var b=Q(a);N.close(b);return 0}catch(c){if("undefined"==typeof N||!(c instanceof N.Ga))throw c;return c.Ma}},H:function(a,b){try{var c=Q(a);A[b>>0]=c.tty?2:N.Sa(c.mode)?3:N.xb(c.mode)?7:4;return 0}catch(d){if("undefined"==typeof N||!(d instanceof N.Ga))throw d;return d.Ma}},r:function(a,b,c,d){try{a:{var f=Q(a);a=b;for(var g=b=0;g>2],h=E[a+4>>2];a+=8;var n=N.read(f,A,k,h,void 0);if(0>n){var q=-1;break a}b+=n;if(n>2]=q;return 0}catch(p){if("undefined"== -typeof N||!(p instanceof N.Ga))throw p;return p.Ma}},A:function(a,b,c,d,f){try{b=c+2097152>>>0<4194305-!!b?(b>>>0)+4294967296*c:NaN;if(isNaN(b))return 61;var g=Q(a);N.cb(g,b,d);J=[g.position>>>0,(G=g.position,1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];D[f>>2]=J[0];D[f+4>>2]=J[1];g.ac&&0===b&&0===d&&(g.ac=null);return 0}catch(k){if("undefined"==typeof N||!(k instanceof N.Ga))throw k;return k.Ma}},S:function(a){try{var b= -Q(a);return b.Ka&&b.Ka.fsync?-b.Ka.fsync(b):0}catch(c){if("undefined"==typeof N||!(c instanceof N.Ga))throw c;return c.Ma}},o:function(a,b,c,d){try{a:{var f=Q(a);a=b;for(var g=b=0;g>2],h=E[a+4>>2];a+=8;var n=N.write(f,A,k,h,void 0);if(0>n){var q=-1;break a}b+=n}q=b}E[d>>2]=q;return 0}catch(p){if("undefined"==typeof N||!(p instanceof N.Ga))throw p;return p.Ma}},D:function(){},E:function(a,b,c,d){return Gc(a,b,c,d)}},Z=function(){function a(c){e.asm=c.exports;pa=e.asm.ma;za();Aa=e.asm.ra; -Ca.unshift(e.asm.na);Ja("wasm-instantiate")}var b={a:Lc};Ia("wasm-instantiate");if(e.instantiateWasm)try{return e.instantiateWasm(b,a)}catch(c){return u("Module.instantiateWasm callback failed with error: "+c),!1}b=Ma(b);a(b[0]);return e.asm}();e.___wasm_call_ctors=Z.na;var Kc=e.___errno_location=Z.oa,wc=e._malloc=Z.pa,X=e._free=Z.qa,Yb=e.___getTypeName=Z.sa;e.___embind_register_native_and_builtin_types=Z.ta;var cb=e._emscripten_builtin_memalign=Z.ua;e.___cxa_is_pointer_type=Z.va; -e.dynCall_iiiij=Z.wa;e.dynCall_iij=Z.xa;e.dynCall_iijii=Z.ya;e.dynCall_iiji=Z.za;e.dynCall_iiiiiij=Z.Aa;e.dynCall_jiji=Z.Ba;e.dynCall_viijii=Z.Ca;e.dynCall_iiiiij=Z.Da;e.dynCall_iiiiijj=Z.Ea;e.dynCall_iiiiiijj=Z.Fa;e.addRunDependency=Ia;e.removeRunDependency=Ja;e.FS_createPath=N.xc;e.FS_createDataFile=N.Jb;e.FS_createPreloadedFile=N.yc;e.FS_createLazyFile=N.wc;e.FS_createDevice=N.$a;e.FS_unlink=N.unlink;e.FS=N;var Mc;Ha=function Nc(){Mc||Oc();Mc||(Ha=Nc)}; -function Oc(){function a(){if(!Mc&&(Mc=!0,e.calledRun=!0,!qa)){e.noFSInit||N.vb.cc||N.vb();N.Lc=!1;Na(Ca);aa(e);if(e.onRuntimeInitialized)e.onRuntimeInitialized();if(e.postRun)for("function"==typeof e.postRun&&(e.postRun=[e.postRun]);e.postRun.length;){var b=e.postRun.shift();Da.unshift(b)}Na(Da)}}if(!(0K?-1:0C-l.getDate())u-=C-l.getDate()+1,l.setDate(1),11>w?l.setMonth(w+1):(l.setMonth(0),l.setFullYear(l.getFullYear()+1));else{l.setDate(l.getDate()+u);break}}w=new Date(l.getFullYear()+1,0,4);u=h(new Date(l.getFullYear(), +0,4));w=h(w);return 0>=k(u,l)?0>=k(w,l)?l.getFullYear()+1:l.getFullYear():l.getFullYear()-1}var q=E[d+40>>2];d={Xd:E[d>>2],Wd:E[d+4>>2],Yb:E[d+8>>2],vc:E[d+12>>2],Zb:E[d+16>>2],Ab:E[d+20>>2],mb:E[d+24>>2],zb:E[d+28>>2],le:E[d+32>>2],Vd:E[d+36>>2],Yd:q?y(q):""};c=y(c);q={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d", +"%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"};for(var p in q)c=c.replace(new RegExp(p,"g"),q[p]);var t="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),x="January February March April May June July August September October November December".split(" ");q={"%a":function(l){return t[l.mb].substring(0,3)},"%A":function(l){return t[l.mb]},"%b":function(l){return x[l.Zb].substring(0,3)},"%B":function(l){return x[l.Zb]}, +"%C":function(l){return g((l.Ab+1900)/100|0,2)},"%d":function(l){return g(l.vc,2)},"%e":function(l){return f(l.vc,2," ")},"%g":function(l){return n(l).toString().substring(2)},"%G":function(l){return n(l)},"%H":function(l){return g(l.Yb,2)},"%I":function(l){l=l.Yb;0==l?l=12:12l.Yb?"AM":"PM"},"%S":function(l){return g(l.Xd,2)},"%t":function(){return"\t"},"%u":function(l){return l.mb||7},"%U":function(l){return g(Math.floor((l.zb+7-l.mb)/7),2)},"%V":function(l){var u=Math.floor((l.zb+7-(l.mb+6)%7)/7);2>=(l.mb+371-l.zb-2)%7&&u++;if(u)53==u&&(w=(l.mb+371-l.zb)%7,4==w||3==w&&Dc(l.Ab)||(u=1));else{u=52;var w=(l.mb+7-l.zb-1)%7;(4==w||5==w&&Dc(l.Ab%400-1))&&u++}return g(u,2)},"%w":function(l){return l.mb},"%W":function(l){return g(Math.floor((l.zb+7-(l.mb+6)%7)/7),2)}, +"%y":function(l){return(l.Ab+1900).toString().substring(2)},"%Y":function(l){return l.Ab+1900},"%z":function(l){l=l.Vd;var u=0<=l;l=Math.abs(l)/60;return(u?"+":"-")+String("0000"+(l/60*100+l%60)).slice(-4)},"%Z":function(l){return l.Yd},"%%":function(){return"%"}};c=c.replace(/%%/g,"\x00\x00");for(p in q)c.includes(p)&&(c=c.replace(new RegExp(p,"g"),q[p](d)));c=c.replace(/\0\0/g,"%");p=Wa(c,!1);if(p.length>b)return 0;B.set(p,a);return p.length-1} +function Hc(a,b,c,d){a||(a=this);this.parent=a;this.Va=a.Va;this.Kb=null;this.id=N.Gd++;this.name=b;this.mode=c;this.Na={};this.Pa={};this.rdev=d}Object.defineProperties(Hc.prototype,{read:{get:function(){return 365===(this.mode&365)},set:function(a){a?this.mode|=365:this.mode&=-366}},write:{get:function(){return 146===(this.mode&146)},set:function(a){a?this.mode|=146:this.mode&=-147}},Bd:{get:function(){return N.Xa(this.mode)}},kc:{get:function(){return N.Ib(this.mode)}}});N.Uc=Hc;N.Ud();var eb; +e.FS_createPath=N.Cc;e.FS_createDataFile=N.Qb;e.FS_createPreloadedFile=N.Dc;e.FS_unlink=N.unlink;e.FS_createLazyFile=N.Bc;e.FS_createDevice=N.gb;sb=e.InternalError=rb("InternalError");for(var Ic=Array(256),Jc=0;256>Jc;++Jc)Ic[Jc]=String.fromCharCode(Jc);wb=Ic;xb=e.BindingError=rb("BindingError"); +U.prototype.isAliasOf=function(a){if(!(this instanceof U&&a instanceof U))return!1;var b=this.Ma.Wa.Sa,c=this.Ma.Ra,d=a.Ma.Wa.Sa;for(a=a.Ma.Ra;b.fb;)c=b.Nb(c),b=b.fb;for(;d.fb;)a=d.Nb(a),d=d.fb;return b===d&&c===a}; +U.prototype.clone=function(){this.Ma.Ra||yb(this);if(this.Ma.Mb)return this.Ma.count.value+=1,this;var a=Kb,b=Object,c=b.create,d=Object.getPrototypeOf(this),f=this.Ma;a=a(c.call(b,d,{Ma:{value:{count:f.count,Bb:f.Bb,Mb:f.Mb,Ra:f.Ra,Wa:f.Wa,$a:f.$a,eb:f.eb}}}));a.Ma.count.value+=1;a.Ma.Bb=!1;return a};U.prototype["delete"]=function(){this.Ma.Ra||yb(this);this.Ma.Bb&&!this.Ma.Mb&&T("Object already scheduled for deletion");Ab(this);Bb(this.Ma);this.Ma.Mb||(this.Ma.$a=void 0,this.Ma.Ra=void 0)}; +U.prototype.isDeleted=function(){return!this.Ma.Ra};U.prototype.deleteLater=function(){this.Ma.Ra||yb(this);this.Ma.Bb&&!this.Ma.Mb&&T("Object already scheduled for deletion");Eb.push(this);1===Eb.length&&Gb&&Gb(Fb);this.Ma.Bb=!0;return this};e.getInheritedInstanceCount=function(){return Object.keys(Hb).length};e.getLiveInheritedInstances=function(){var a=[],b;for(b in Hb)Hb.hasOwnProperty(b)&&a.push(Hb[b]);return a};e.flushPendingDeletes=Fb;e.setDelayFunction=function(a){Gb=a;Eb.length&&Gb&&Gb(Fb)}; +V.prototype.wd=function(a){this.Sc&&(a=this.Sc(a));return a};V.prototype.Gc=function(a){this.ob&&this.ob(a)};V.prototype.argPackAdvance=8;V.prototype.readValueFromPointer=lb;V.prototype.deleteObject=function(a){if(null!==a)a["delete"]()}; +V.prototype.fromWireType=function(a){function b(){return this.Ub?Jb(this.Sa.Db,{Wa:this.Ld,Ra:c,eb:this,$a:a}):Jb(this.Sa.Db,{Wa:this,Ra:a})}var c=this.wd(a);if(!c)return this.Gc(a),null;var d=Ib(this.Sa,c);if(void 0!==d){if(0===d.Ma.count.value)return d.Ma.Ra=c,d.Ma.$a=a,d.clone();d=d.clone();this.Gc(a);return d}d=this.Sa.ud(c);d=Db[d];if(!d)return b.call(this);d=this.Sb?d.hd:d.pointerType;var f=Cb(c,this.Sa,d.Sa);return null===f?b.call(this):this.Ub?Jb(d.Sa.Db,{Wa:d,Ra:f,eb:this,$a:a}):Jb(d.Sa.Db, +{Wa:d,Ra:f})};Wb=e.UnboundTypeError=rb("UnboundTypeError");e.count_emval_handles=function(){for(var a=0,b=5;bf?-28:N.Ec(d,f).fd;case 1:case 2:return 0;case 3:return d.flags;case 4:return f=hb(),d.flags|=f,0;case 5:return f=hb(),D[f+0>>1]=2,0;case 6:case 7:return 0;case 16:case 8:return-28;case 9:return E[Kc()>>2]=28,-1;default:return-28}}catch(g){if("undefined"== +typeof N||!(g instanceof N.La))throw g;return-g.Qa}},W:function(a,b){try{var c=Q(a);return fb(N.stat,c.path,b)}catch(d){if("undefined"==typeof N||!(d instanceof N.La))throw d;return-d.Qa}},z:function(a,b,c){try{b=c+2097152>>>0<4194305-!!b?(b>>>0)+4294967296*c:NaN;if(isNaN(b))return-61;N.td(a,b);return 0}catch(d){if("undefined"==typeof N||!(d instanceof N.La))throw d;return-d.Qa}},R:function(a,b){try{if(0===b)return-28;var c=N.cwd(),d=ta(c)+1;if(b>>0,(G=h,1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>> +0:0)];E[b+a>>2]=J[0];E[b+a+4>>2]=J[1];J=[280*(g+1)>>>0,(G=280*(g+1),1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];E[b+a+8>>2]=J[0];E[b+a+12>>2]=J[1];D[b+a+16>>1]=280;B[b+a+18>>0]=n;A(k,z,b+a+19,256);a+=280;g+=1}N.ab(d,280*g,0);return a}catch(p){if("undefined"==typeof N||!(p instanceof N.La))throw p;return-p.Qa}},X:function(a,b,c){gb=c;try{var d=Q(a);switch(b){case 21509:case 21505:return d.tty?0:-59;case 21510:case 21511:case 21512:case 21506:case 21507:case 21508:return d.tty? +0:-59;case 21519:if(!d.tty)return-59;var f=hb();return E[f>>2]=0;case 21520:return d.tty?-28:-59;case 21531:return f=hb(),N.jc(d,b,f);case 21523:return d.tty?0:-59;case 21524:return d.tty?0:-59;default:v("bad ioctl syscall "+b)}}catch(g){if("undefined"==typeof N||!(g instanceof N.La))throw g;return-g.Qa}},U:function(a,b){try{return a=y(a),fb(N.lstat,a,b)}catch(c){if("undefined"==typeof N||!(c instanceof N.La))throw c;return-c.Qa}},O:function(a,b,c){try{return b=y(b),b=P(a,b),b=L(b),"/"===b[b.length- +1]&&(b=b.substr(0,b.length-1)),N.mkdir(b,c,0),0}catch(d){if("undefined"==typeof N||!(d instanceof N.La))throw d;return-d.Qa}},T:function(a,b,c,d){try{b=y(b);var f=d&256;b=P(a,b,d&4096);return fb(f?N.lstat:N.stat,b,c)}catch(g){if("undefined"==typeof N||!(g instanceof N.La))throw g;return-g.Qa}},r:function(a,b,c,d){gb=d;try{b=y(b);b=P(a,b);var f=d?hb():0;return N.open(b,c,f).fd}catch(g){if("undefined"==typeof N||!(g instanceof N.La))throw g;return-g.Qa}},K:function(a,b,c,d){try{b=y(b);b=P(a,b);if(0>= +d)return-28;var f=N.readlink(b),g=Math.min(d,ta(f)),k=B[c+g];A(f,z,c,d+1);B[c+g]=k;return g}catch(h){if("undefined"==typeof N||!(h instanceof N.La))throw h;return-h.Qa}},H:function(a,b,c,d){try{return b=y(b),d=y(d),b=P(a,b),d=P(c,d),N.rename(b,d),0}catch(f){if("undefined"==typeof N||!(f instanceof N.La))throw f;return-f.Qa}},I:function(a){try{return a=y(a),N.rmdir(a),0}catch(b){if("undefined"==typeof N||!(b instanceof N.La))throw b;return-b.Qa}},V:function(a,b){try{return a=y(a),fb(N.stat,a,b)}catch(c){if("undefined"== +typeof N||!(c instanceof N.La))throw c;return-c.Qa}},J:function(a,b,c){try{return b=y(b),b=P(a,b),0===c?N.unlink(b):512===c?N.rmdir(b):v("Invalid flags passed to unlinkat"),0}catch(d){if("undefined"==typeof N||!(d instanceof N.La))throw d;return-d.Qa}},E:function(a,b,c){try{b=y(b);b=P(a,b,!0);if(c){var d=ib(c),f=E[c+8>>2];g=1E3*d+f/1E6;c+=16;d=ib(c);f=E[c+8>>2];k=1E3*d+f/1E6}else var g=Date.now(),k=g;N.$d(b,g,k);return 0}catch(h){if("undefined"==typeof N||!(h instanceof N.La))throw h;return-h.Qa}}, +h:function(a){var b=jb[a];delete jb[a];var c=b.qc,d=b.ob,f=b.Kc,g=f.map(k=>k.yd).concat(f.map(k=>k.Rd));ub([a],g,k=>{var h={};f.forEach((n,q)=>{var p=k[q],t=n.Rb,x=n.xd,l=k[q+f.length],u=n.Qd,w=n.Sd;h[n.qd]={read:C=>p.fromWireType(t(x,C)),write:(C,K)=>{var H=[];u(w,C,l.toWireType(H,K));kb(H)}}});return[{name:b.name,fromWireType:function(n){var q={},p;for(p in h)q[p]=h[p].read(n);d(n);return q},toWireType:function(n,q){for(var p in h)if(!(p in q))throw new TypeError('Missing field: "'+p+'"');var t= +c();for(p in h)h[p].write(t,q[p]);null!==n&&n.push(d,t);return t},argPackAdvance:8,readValueFromPointer:lb,hb:d}]})},A:function(){},ea:function(a,b,c,d,f){var g=vb(c);b=S(b);R(a,{name:b,fromWireType:function(k){return!!k},toWireType:function(k,h){return h?d:f},argPackAdvance:8,readValueFromPointer:function(k){if(1===c)var h=B;else if(2===c)h=D;else if(4===c)h=E;else throw new TypeError("Unknown boolean type size: "+b);return this.fromWireType(h[k>>g])},hb:null})},G:function(a,b,c,d,f,g,k,h,n,q,p, +t,x){p=S(p);g=W(f,g);h&&(h=W(k,h));q&&(q=W(n,q));x=W(t,x);var l=pb(p);Mb(l,function(){Zb("Cannot construct "+p+" due to unbound types",[d])});ub([a,b,c],d?[d]:[],function(u){u=u[0];if(d){var w=u.Sa;var C=w.Db}else C=U.prototype;u=qb(l,function(){if(Object.getPrototypeOf(this)!==K)throw new xb("Use 'new' to construct "+p);if(void 0===H.sb)throw new xb(p+" has no accessible constructor");var I=H.sb[arguments.length];if(void 0===I)throw new xb("Tried to invoke ctor of "+p+" with invalid number of parameters ("+ +arguments.length+") - expected ("+Object.keys(H.sb).toString()+") parameters instead!");return I.apply(this,arguments)});var K=Object.create(C,{constructor:{value:u}});u.prototype=K;var H=new Nb(p,u,K,x,w,g,h,q);w=new V(p,H,!0,!1);C=new V(p+"*",H,!1,!1);var Ga=new V(p+" const*",H,!1,!0);Db[a]={pointerType:C,hd:Ga};Ub(l,u);return[w,C,Ga]})},x:function(a,b,c,d,f,g){0{Zb("Cannot construct "+h.name+" due to unbound types",k)};ub([],k,function(q){q.splice(1,0,null);h.Sa.sb[b-1]=bc(n,q,null,f,g);return[]});return[]})},d:function(a,b,c,d,f,g,k,h){var n=$b(c,d);b=S(b);g=W(f,g);ub([],[a],function(q){function p(){Zb("Cannot call "+ +t+" due to unbound types",n)}q=q[0];var t=q.name+"."+b;b.startsWith("@@")&&(b=Symbol[b.substring(2)]);h&&q.Sa.Md.push(b);var x=q.Sa.Db,l=x[b];void 0===l||void 0===l.Za&&l.className!==q.name&&l.Pb===c-2?(p.Pb=c-2,p.className=q.name,x[b]=p):(Lb(x,b,t),x[b].Za[c-2]=p);ub([],n,function(u){u=bc(t,u,q,g,k);void 0===x[b].Za?(u.Pb=c-2,x[b]=u):x[b].Za[c-2]=u;return[]});return[]})},da:function(a,b){b=S(b);R(a,{name:b,fromWireType:function(c){var d=ec(c);dc(c);return d},toWireType:function(c,d){return Sb(d)}, +argPackAdvance:8,readValueFromPointer:lb,hb:null})},t:function(a,b,c){c=vb(c);b=S(b);R(a,{name:b,fromWireType:function(d){return d},toWireType:function(d,f){return f},argPackAdvance:8,readValueFromPointer:fc(b,c),hb:null})},ga:function(a,b,c,d,f,g){var k=$b(b,c);a=S(a);f=W(d,f);Mb(a,function(){Zb("Cannot call "+a+" due to unbound types",k)},b-1);ub([],k,function(h){h=[h[0],null].concat(h.slice(1));Ub(a,bc(a,h,null,f,g),b-1);return[]})},g:function(a,b,c,d,f){b=S(b);-1===f&&(f=4294967295);f=vb(c);var g= +h=>h;if(0===d){var k=32-8*c;g=h=>h<>>k}c=b.includes("unsigned")?function(h,n){return n>>>0}:function(h,n){return n};R(a,{name:b,fromWireType:g,toWireType:c,argPackAdvance:8,readValueFromPointer:gc(b,f,0!==d),hb:null})},c:function(a,b,c){function d(g){g>>=2;var k=F;return new f(ua,k[g+1],k[g])}var f=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][b];c=S(c);R(a,{name:c,fromWireType:d,argPackAdvance:8,readValueFromPointer:d},{zd:!0})},u:function(a,b){b= +S(b);var c="std::string"===b;R(a,{name:b,fromWireType:function(d){var f=F[d>>2],g=d+4;if(c)for(var k=g,h=0;h<=f;++h){var n=g+h;if(h==f||0==z[n]){k=y(k,n-k);if(void 0===q)var q=k;else q+=String.fromCharCode(0),q+=k;k=n+1}}else{q=Array(f);for(h=0;h>2]=k;if(c&&g)A(f,z,n,k+1);else if(g)for(g=0;gva;var h=1}else 4===b&&(d=lc,f=mc,g=nc,k=()=>F,h=2);R(a,{name:c,fromWireType:function(n){for(var q= +F[n>>2],p=k(),t,x=n+4,l=0;l<=q;++l){var u=n+4+l*b;if(l==q||0==p[u>>h])x=d(x,u-x),void 0===t?t=x:(t+=String.fromCharCode(0),t+=x),x=u+b}X(n);return t},toWireType:function(n,q){"string"!=typeof q&&T("Cannot pass non-string to C++ string type "+c);var p=g(q),t=wc(4+p+b);F[t>>2]=p>>h;f(q,t+4,p+b);null!==n&&n.push(X,t);return t},argPackAdvance:8,readValueFromPointer:lb,hb:function(n){X(n)}})},i:function(a,b,c,d,f,g){jb[a]={name:S(b),qc:W(c,d),ob:W(f,g),Kc:[]}},f:function(a,b,c,d,f,g,k,h,n,q){jb[a].Kc.push({qd:S(b), +yd:c,Rb:W(d,f),xd:g,Rd:k,Qd:W(h,n),Sd:q})},fa:function(a,b){b=S(b);R(a,{Cd:!0,name:b,argPackAdvance:0,fromWireType:function(){},toWireType:function(){}})},n:function(){return Date.now()},$:function(){return!0},v:function(a,b,c){a=ec(a);b=oc(b,"emval::as");var d=[],f=Sb(d);F[c>>2]=f;return b.toWireType(d,a)},ma:function(a,b,c,d){a=rc[a];b=ec(b);c=qc(c);a(b,c,null,d)},ka:dc,la:function(a,b){var c=tc(a,b),d=c[0];b=d.name+"_$"+c.slice(1).map(function(p){return p.name}).join("_")+"$";var f=uc[b];if(void 0!== +f)return f;f=["retType"];for(var g=[d],k="",h=0;h>2]=a.getSeconds();E[b+4>>2]=a.getMinutes();E[b+8>>2]=a.getHours();E[b+12>>2]=a.getDate();E[b+16>>2]=a.getMonth();E[b+20>>2]= +a.getFullYear()-1900;E[b+24>>2]=a.getDay();var c=new Date(a.getFullYear(),0,1);E[b+28>>2]=(a.getTime()-c.getTime())/864E5|0;E[b+36>>2]=-(60*a.getTimezoneOffset());var d=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();c=c.getTimezoneOffset();E[b+32>>2]=(d!=c&&a.getTimezoneOffset()==Math.min(c,d))|0},M:function(a,b,c,d,f,g){try{var k=N.qb(d);if(!k)return-8;var h=N.xb(k,a,f,b,c),n=h.Ra;E[g>>2]=h.yc;return n}catch(q){if("undefined"==typeof N||!(q instanceof N.La))throw q;return-q.Qa}},N:function(a, +b,c,d,f,g){try{var k=N.qb(f);if(k&&c&2){var h=z.slice(a,a+b);N.Eb(k,h,g,b,d)}}catch(n){if("undefined"==typeof N||!(n instanceof N.La))throw n;return-n.Qa}},ba:yc,k:function(){v("")},F:function(){return 2147483648},s:zc,m:function(a){var b=z.length;a>>>=0;if(2147483648=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);var f=Math;d=Math.max(a,d);f=f.min.call(f,2147483648,d+(65536-d%65536)%65536);a:{try{pa.grow(f-ua.byteLength+65535>>>16);ya();var g=1;break a}catch(k){}g=void 0}if(g)return!0}return!1}, +P:function(a,b){var c=0;Bc().forEach(function(d,f){var g=b+c;f=F[a+4*f>>2]=g;for(g=0;g>0]=d.charCodeAt(g);B[f>>0]=0;c+=d.length+1});return 0},Q:function(a,b){var c=Bc();F[a>>2]=c.length;var d=0;c.forEach(function(f){d+=f.length+1});F[b>>2]=d;return 0},j:function(a){try{var b=Q(a);N.close(b);return 0}catch(c){if("undefined"==typeof N||!(c instanceof N.La))throw c;return c.Qa}},D:function(a,b){try{var c=Q(a);B[b>>0]=c.tty?2:N.Xa(c.mode)?3:N.ub(c.mode)?7:4;return 0}catch(d){if("undefined"== +typeof N||!(d instanceof N.La))throw d;return d.Qa}},q:function(a,b,c,d){try{a:{var f=Q(a);a=b;for(var g=b=0;g>2],h=F[a+4>>2];a+=8;var n=N.read(f,B,k,h,void 0);if(0>n){var q=-1;break a}b+=n;if(n>2]=q;return 0}catch(p){if("undefined"==typeof N||!(p instanceof N.La))throw p;return p.Qa}},y:function(a,b,c,d,f){try{b=c+2097152>>>0<4194305-!!b?(b>>>0)+4294967296*c:NaN;if(isNaN(b))return 61;var g=Q(a);N.ab(g,b,d);J=[g.position>>>0,(G=g.position,1<=+Math.abs(G)?0>>0:~~+Math.ceil((G-+(~~G>>>0))/4294967296)>>>0:0)];E[f>>2]=J[0];E[f+4>>2]=J[1];g.tb&&0===b&&0===d&&(g.tb=null);return 0}catch(k){if("undefined"==typeof N||!(k instanceof N.La))throw k;return k.Qa}},S:function(a){try{var b=Q(a);return b.Pa&&b.Pa.fsync?-b.Pa.fsync(b):0}catch(c){if("undefined"==typeof N||!(c instanceof N.La))throw c;return c.Qa}},p:function(a,b,c,d){try{a:{var f=Q(a);a=b;for(var g=b=0;g>2],h=F[a+4>>2];a+=8;var n=N.write(f,B,k,h,void 0);if(0> +n){var q=-1;break a}b+=n}q=b}F[d>>2]=q;return 0}catch(p){if("undefined"==typeof N||!(p instanceof N.La))throw p;return p.Qa}},B:function(){},ha:Gc,C:function(a,b,c,d){return Gc(a,b,c,d)}},Z=function(){function a(c){e.asm=c.exports;pa=e.asm.pa;ya();za=e.asm.ua;Ba.unshift(e.asm.qa);Ja("wasm-instantiate")}var b={a:Lc};Ia("wasm-instantiate");if(e.instantiateWasm)try{return e.instantiateWasm(b,a)}catch(c){return r("Module.instantiateWasm callback failed with error: "+c),!1}b=Ma(b);a(b[0]);return e.asm}(); +e.___wasm_call_ctors=Z.qa;var Kc=e.___errno_location=Z.ra,wc=e._malloc=Z.sa,X=e._free=Z.ta,Yb=e.___getTypeName=Z.va;e.___embind_register_native_and_builtin_types=Z.wa;var cb=e._emscripten_builtin_memalign=Z.xa;e.___cxa_is_pointer_type=Z.ya;e.dynCall_iiiij=Z.za;e.dynCall_iij=Z.Aa;e.dynCall_iijii=Z.Ba;e.dynCall_iiji=Z.Ca;e.dynCall_iiiiiij=Z.Da;e.dynCall_vjii=Z.Ea;e.dynCall_vji=Z.Fa;e.dynCall_jiji=Z.Ga;e.dynCall_viijii=Z.Ha;e.dynCall_iiiiij=Z.Ia;e.dynCall_iiiiijj=Z.Ja;e.dynCall_iiiiiijj=Z.Ka; +e.addRunDependency=Ia;e.removeRunDependency=Ja;e.FS_createPath=N.Cc;e.FS_createDataFile=N.Qb;e.FS_createPreloadedFile=N.Dc;e.FS_createLazyFile=N.Bc;e.FS_createDevice=N.gb;e.FS_unlink=N.unlink;e.FS=N;var Mc;Ha=function Nc(){Mc||Oc();Mc||(Ha=Nc)}; +function Oc(){function a(){if(!Mc&&(Mc=!0,e.calledRun=!0,!qa)){e.noFSInit||N.Cb.ic||N.Cb();N.Qc=!1;Na(Ba);aa(e);if(e.onRuntimeInitialized)e.onRuntimeInitialized();if(e.postRun)for("function"==typeof e.postRun&&(e.postRun=[e.postRun]);e.postRun.length;){var b=e.postRun.shift();Ca.unshift(b)}Na(Ca)}}if(!(0 /dev/null; then echo "Please install emscripten or run 'nix develop'" >&2 exit 1 fi # directories SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd -P) NATIVE_CPP_DIR="${SCRIPT_DIR}/../../native/cpp/" INPUT_DIR="${NATIVE_CPP_DIR}CommonCpp/DatabaseManagers/" SQLITE_DIR="${SCRIPT_DIR}/../database/sqlite/" WEB_CPP_DIR="${SCRIPT_DIR}/../cpp/" OUTPUT_DIR="${SCRIPT_DIR}/../database/_generated/" # files SQLITE_SOURCE="${SQLITE_DIR}sqlite3.c" SQLITE_BITCODE_FILE="${SQLITE_DIR}sqlite3.bc" OUTPUT_FILE_NAME="comm-query-executor" OUTPUT_FILE="${OUTPUT_DIR}${OUTPUT_FILE_NAME}.js" -# SQLite resources -SQLITE_AMALGAMATION="sqlite-amalgamation-3390300" -SQLITE_AMALGAMATION_URL="https://www.sqlite.org/2022/${SQLITE_AMALGAMATION}.zip" -SQLITE_AMALGAMATION_FILE="${SQLITE_DIR}${SQLITE_AMALGAMATION}.zip" +# OpenSSL resources +OPENSSL_VERSION="3.2.0" +OPENSSL_URL="https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz" +OPENSSL_FILE="${SQLITE_DIR}openssl-file" +OPENSSL_DIR="${SQLITE_DIR}openssl-${OPENSSL_VERSION}" +OPENSSL_HEADERS="${OPENSSL_DIR}/include" +OPENSSL_LIBCRYPTO="${OPENSSL_DIR}/libcrypto.a" + +# SQLCipher resources +SQLCIPHER_AMALGAMATION_VERSION="4.5.5b" +SQLCIPHER_AMALGAMATION="sqlcipher-amalgamation-${SQLCIPHER_AMALGAMATION_VERSION}" +SQLCIPHER_AMALGAMATION_URL="https://codeload.github.com/CommE2E/sqlcipher-amalgamation/zip/refs/tags/${SQLCIPHER_AMALGAMATION_VERSION}" +SQLCIPHER_AMALGAMATION_FILE="${SQLITE_DIR}${SQLCIPHER_AMALGAMATION}" SQLITE_COMPILATION_FLAGS=( -Oz -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DISABLE_LFS -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_NORMALIZE + -DSQLITE_HAS_CODEC + -DSQLITE_TEMP_STORE=2 + -DSQLCIPHER_CRYPTO_OPENSSL ) +download_openssl() { + mkdir -p "$SQLITE_DIR" + + curl "${OPENSSL_URL}" --output "${OPENSSL_FILE}" + + tar -xf "${OPENSSL_FILE}" -C "${SQLITE_DIR}" + rm -f "${OPENSSL_FILE}" +} + +build_openssl() { + pushd "${OPENSSL_DIR}" + + ./Configure \ + no-asm \ + no-async \ + no-egd \ + no-ktls \ + no-module \ + no-posix-io \ + no-secure-memory \ + no-dso \ + no-shared \ + no-sock \ + no-stdio \ + no-ui-console \ + no-weak-ssl-ciphers \ + no-engine \ + linux-generic32 + + make CC="emcc" AR="emar" RANLIB="emranlib" + + popd +} + +if [ ! -d "$OPENSSL_DIR" ]; then + echo "OpenSSL sources not found. Downloading." + download_openssl +fi + +if [ ! -f "$OPENSSL_LIBCRYPTO" ]; then + echo "OpenSSL binary not found. Building." + build_openssl +fi + download_sqlite() { mkdir -p "$SQLITE_DIR" - curl "${SQLITE_AMALGAMATION_URL}" --output "${SQLITE_AMALGAMATION_FILE}" + curl "${SQLCIPHER_AMALGAMATION_URL}" --output "${SQLCIPHER_AMALGAMATION_FILE}" - unzip -jo "${SQLITE_AMALGAMATION_FILE}" -d "${SQLITE_DIR}" - rm -f "${SQLITE_AMALGAMATION_FILE}" + unzip -jo "${SQLCIPHER_AMALGAMATION_FILE}" -d "${SQLITE_DIR}" + rm -f "${SQLCIPHER_AMALGAMATION_FILE}" } if [ ! -f "$SQLITE_BITCODE_FILE" ]; then echo "SQLite engine not found. Downloading." download_sqlite emcc "${SQLITE_COMPILATION_FLAGS[@]}" \ + -I "${OPENSSL_HEADERS}" \ -c "$SQLITE_SOURCE" \ -o "$SQLITE_BITCODE_FILE" fi EMCC_FLAGS=( # WASM files and bindings --memory-init-file 0 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s ALLOW_TABLE_GROWTH=1 -s FORCE_FILESYSTEM=1 -s SINGLE_FILE=0 -s EXPORTED_RUNTIME_METHODS=["FS"] # node/babel/webpack helpers -s NODEJS_CATCH_EXIT=0 -s NODEJS_CATCH_REJECTION=0 -s WASM_ASYNC_COMPILATION=0 -s EXPORT_ES6=1 -s USE_ES6_IMPORT_META=0 -s MODULARIZE=1 # optimization -Oz -flto --closure 1 ) CFLAGS=( -I "$INPUT_DIR" -I "$SQLITE_DIR" -I "${NATIVE_CPP_DIR}third-party/sqlite_orm/" -I "${NATIVE_CPP_DIR}CommonCpp/Tools/" ) INPUT_FILES=( "${WEB_CPP_DIR}SQLiteQueryExecutorBindings.cpp" "${WEB_CPP_DIR}Logger.cpp" "$SQLITE_BITCODE_FILE" ) mkdir -p "$OUTPUT_DIR" emcc -lembind \ "${EMCC_FLAGS[@]}" \ "${CFLAGS[@]}" \ "${INPUT_FILES[@]}" \ + "${OPENSSL_LIBCRYPTO}" \ -o "${OUTPUT_FILE}" \ -std=c++17 sed -i.bak -e '1i\/\/ \@generated' "${OUTPUT_FILE}" mv -f "${OUTPUT_DIR}${OUTPUT_FILE_NAME}.wasm" "${OUTPUT_DIR}comm_query_executor.wasm" rm -f "${OUTPUT_FILE}.bak"