Files
mattermost-mobile/patches/@nozbe+watermelondb+0.24.0.patch

123 lines
5.2 KiB
Diff

diff --git a/node_modules/@nozbe/watermelondb/Database/index.js b/node_modules/@nozbe/watermelondb/Database/index.js
index 8d71c6f..9ad75d6 100644
--- a/node_modules/@nozbe/watermelondb/Database/index.js
+++ b/node_modules/@nozbe/watermelondb/Database/index.js
@@ -126,6 +126,10 @@ var Database = /*#__PURE__*/function () {
// subsequent changes to the record don't trip up the invariant
// TODO: What if this fails?
record._preparedState = null;
+
+ if ('update' === preparedState) {
+ record.__original = null;
+ }
}
if (!changeNotifications[table]) {
diff --git a/node_modules/@nozbe/watermelondb/Model/index.d.ts b/node_modules/@nozbe/watermelondb/Model/index.d.ts
index 1a7c99e..0cb7b87 100644
--- a/node_modules/@nozbe/watermelondb/Model/index.d.ts
+++ b/node_modules/@nozbe/watermelondb/Model/index.d.ts
@@ -44,6 +44,8 @@ declare module '@nozbe/watermelondb/Model' {
public update(recordUpdater?: (record: this) => void): Promise<this>
+ public cancelPrepareUpdate(): void;
+
public prepareUpdate(recordUpdater?: (record: this) => void): this
public markAsDeleted(): Promise<void>
diff --git a/node_modules/@nozbe/watermelondb/Model/index.js b/node_modules/@nozbe/watermelondb/Model/index.js
index 075a047..e5e52fa 100644
--- a/node_modules/@nozbe/watermelondb/Model/index.js
+++ b/node_modules/@nozbe/watermelondb/Model/index.js
@@ -78,6 +78,16 @@ var Model = /*#__PURE__*/function () {
// database.batch()
;
+ _proto.cancelPrepareUpdate = function cancelPrepareUpdate() {
+ if ('test' !== process.env.NODE_ENV && 'undefined' !== typeof process && process) {
+ (0, _invariant.default)('update' !== _this._preparedState, "Cannot cancel an update on a model that has not been prepared");
+ }
+ this.__changes = null;
+ this._preparedState = null;
+ this._raw = this.original;
+ this.__original = undefined;
+ }
+
_proto.prepareUpdate = function prepareUpdate(recordUpdater = _noop.default) {
var _this = this;
@@ -92,6 +102,7 @@ var Model = /*#__PURE__*/function () {
} // Perform updates
+ this.__original = Object.assign({}, this._raw);
(0, _ensureSync.default)(recordUpdater(this));
this._isEditing = false;
this._preparedState = 'update'; // TODO: `process.nextTick` doesn't work on React Native
diff --git a/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt b/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt
index ca31e20..b45c753 100644
--- a/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt
+++ b/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt
@@ -22,6 +22,21 @@ class Database(
if (name == ":memory:" || name.contains("mode=memory")) {
context.cacheDir.delete()
File(context.cacheDir, name).path
+ } else if (name.contains("/") || name.contains("file")) {
+ // Extracts the database name from the path
+ val dbName = name.substringAfterLast("/")
+
+ // Extracts the real path where the *.db file will be created
+ val truePath = name.substringAfterLast("file://").substringBeforeLast("/")
+
+ // Creates the directory
+ if (!truePath.contains("databases")) {
+ val fileObj = File(truePath, "databases")
+ fileObj.mkdir()
+ File("${truePath}/databases", dbName).path
+ } else {
+ File(truePath, dbName).path
+ }
} else {
// On some systems there is some kind of lock on `/databases` folder ¯\_(ツ)_/¯
context.getDatabasePath("$name.db").path.replace("/databases", "")
diff --git a/node_modules/@nozbe/watermelondb/native/shared/Database.cpp b/node_modules/@nozbe/watermelondb/native/shared/Database.cpp
index a2bd410..44e1a58 100644
--- a/node_modules/@nozbe/watermelondb/native/shared/Database.cpp
+++ b/node_modules/@nozbe/watermelondb/native/shared/Database.cpp
@@ -54,6 +54,7 @@ void Database::destroy() {
const std::lock_guard<std::mutex> lock(mutex_);
if (isDestroyed_) {
+ db_->markAsDestroyed();
return;
}
isDestroyed_ = true;
diff --git a/node_modules/@nozbe/watermelondb/native/shared/Sqlite.cpp b/node_modules/@nozbe/watermelondb/native/shared/Sqlite.cpp
index 4108e6c..0fa554c 100644
--- a/node_modules/@nozbe/watermelondb/native/shared/Sqlite.cpp
+++ b/node_modules/@nozbe/watermelondb/native/shared/Sqlite.cpp
@@ -69,6 +69,10 @@ void SqliteDb::destroy() {
}
}
+void SqliteDb::markAsDestroyed() {
+ isDestroyed_ = true;
+}
+
SqliteDb::~SqliteDb() {
destroy();
}
diff --git a/node_modules/@nozbe/watermelondb/native/shared/Sqlite.h b/node_modules/@nozbe/watermelondb/native/shared/Sqlite.h
index 22cffa7..4b74a7f 100644
--- a/node_modules/@nozbe/watermelondb/native/shared/Sqlite.h
+++ b/node_modules/@nozbe/watermelondb/native/shared/Sqlite.h
@@ -11,6 +11,7 @@ public:
SqliteDb(std::string path);
~SqliteDb();
void destroy();
+ void markAsDestroyed();
sqlite3 *sqlite;