Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch @triniwiz/nativescript-couchbase@3.0.0 for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/@triniwiz/nativescript-couchbase/index.android.js b/node_modules/@triniwiz/nativescript-couchbase/index.android.js
index 23533a1..c815234 100644
--- a/node_modules/@triniwiz/nativescript-couchbase/index.android.js
+++ b/node_modules/@triniwiz/nativescript-couchbase/index.android.js
@@ -935,6 +935,10 @@ export class MutableDocument extends Document {
this.native.setBlob(key, value.native);
return this;
}
+ setJSON(value) {
+ this.native.setJSON(JSON.stringify(value));
+ return this;
+ }
toJSON() {
const keys = this.getKeys();
const ret = {};
diff --git a/node_modules/@triniwiz/nativescript-couchbase/index.d.ts b/node_modules/@triniwiz/nativescript-couchbase/index.d.ts
index 175ef6b..5a458dc 100644
--- a/node_modules/@triniwiz/nativescript-couchbase/index.d.ts
+++ b/node_modules/@triniwiz/nativescript-couchbase/index.d.ts
@@ -239,6 +239,8 @@ export class MutableDocument extends Omit<Document, 'toMutable'> {
setArray(key: string, value: Array): this;
+ setJSON(value: { [key: string]: ValueType }): this;
+
toJSON();
}
diff --git a/node_modules/@triniwiz/nativescript-couchbase/index.ios.js b/node_modules/@triniwiz/nativescript-couchbase/index.ios.js
index fd85a0c..9aa201c 100644
--- a/node_modules/@triniwiz/nativescript-couchbase/index.ios.js
+++ b/node_modules/@triniwiz/nativescript-couchbase/index.ios.js
@@ -891,6 +891,10 @@ export class MutableDocument extends Document {
this.native.setBlobForKey(value.native, key);
return this;
}
+ setJSON(value) {
+ this.native.setJSONError(JSON.stringify(value));
+ return this;
+ }
toJSON() {
const keys = this.getKeys();
const ret = {};
diff --git a/node_modules/@triniwiz/nativescript-couchbase/platforms/android/java/com/github/triniwiz/couchbase/Couchbase.kt b/node_modules/@triniwiz/nativescript-couchbase/platforms/android/java/com/github/triniwiz/couchbase/Couchbase.kt
index 52287c2..23591c0 100644
--- a/node_modules/@triniwiz/nativescript-couchbase/platforms/android/java/com/github/triniwiz/couchbase/Couchbase.kt
+++ b/node_modules/@triniwiz/nativescript-couchbase/platforms/android/java/com/github/triniwiz/couchbase/Couchbase.kt
@@ -22,136 +22,6 @@ class Couchbase {
}
}
- @JvmStatic
- fun getDocument(database: Database, id: String?): String? {
- return id?.let {
- database.getDocument(it)?.let {
- return toJSON(it)
- } ?: run {
- null
- }
- } ?: run {
- null
- }
- }
-
-
- @JvmStatic
- fun getDocuments(database: Database, ids: kotlin.Array<String>): String {
- val args = mutableListOf<Expression>()
- ids.forEach {
- args.add(Expression.string(it))
- }
- return queryResultsToJSON(QueryBuilder.select(SelectResult.all(), SelectResult.expression(Meta.id)).from(DataSource.database(database)).where(
- Meta.id.`in`(*args.toTypedArray())
- ), true)
- }
-
-
- @JvmStatic
- fun queryResultsToJSON(query: Query, isAll: Boolean): String {
- val json = JSONArray()
- try {
- query.execute().allResults().forEach { item ->
- val keys = item.keys
- val obj = JSONObject()
- for (key in keys) {
- val nativeItem = item.getValue(key)
- if (isAll && nativeItem as? Dictionary != null) {
- (nativeItem as? Dictionary)?.let {
- for (cblKey in it.keys) {
- obj.put(cblKey, deserialize(nativeItem.getValue(cblKey)))
- }
- }
- } else {
- obj.put(key, deserialize(nativeItem))
- }
- }
- json.put(obj)
- }
- } catch (e: java.lang.Exception) {
- }
- return json.toString()
- }
-
- @JvmStatic
- fun toJSON(document: Document): String? {
- val json = JSONObject()
- return try {
- json.put("id", document.id)
- json.put("revisionID", document.revisionID)
- for (key in document.keys) {
- json.put(key, deserialize(document.getValue(key)))
- }
- json.toString()
- } catch (e: Exception) {
- null
- }
- }
-
- @JvmStatic
- fun fromJSON(json: String): MutableDocument? {
- return fromJSON(json, null)
- }
-
- @JvmStatic
- fun fromJSON(json: String, id: String?): MutableDocument? {
- return try {
- val doc = id?.let {
- MutableDocument(id)
- } ?: MutableDocument()
- val jsonObject = JSONObject(json)
- for (key in jsonObject.keys()) {
- serialize(jsonObject[key], doc, key)
- }
- doc
- } catch (e: Exception) {
- null
- }
- }
-
- @JvmStatic
- fun updateFromJSON(database: Database, json: String, id: String): Boolean {
- return updateFromJSON(database, json, id, ConcurrencyControl.LAST_WRITE_WINS)
- }
-
- @JvmStatic
- fun updateFromJSON(database: Database, json: String, id: String, concurrencyMode: ConcurrencyControl): Boolean {
- return database.getDocument(id)?.let {
- return try {
- val jsonObject = JSONObject(json)
- val doc = it.toMutable()
- for (key in jsonObject.keys()) {
- serialize(jsonObject[key], doc, key)
- }
- database.save(doc, concurrencyMode)
- } catch (e: java.lang.Exception) {
- false
- }
- } ?: false
- }
-
- @JvmStatic
- fun saveFromJSON(database: Database, json: String, id: String?): String? {
- return saveFromJSON(database, json, id, ConcurrencyControl.LAST_WRITE_WINS)
- }
-
- @JvmStatic
- fun saveFromJSON(database: Database, json: String, id: String?, concurrencyMode: ConcurrencyControl): String? {
- return fromJSON(json, id)?.let {
- return try {
- val saved = database.save(it, concurrencyMode)
- if (saved) {
- it.id
- } else {
- null
- }
- } catch (e: CouchbaseLiteException) {
- null
- }
- }
- }
-
@JvmStatic
private var _dateFormat: SimpleDateFormat? = null
diff --git a/node_modules/@triniwiz/nativescript-couchbase/platforms/android/nativescript_couchbase.aar b/node_modules/@triniwiz/nativescript-couchbase/platforms/android/nativescript_couchbase.aar
index d03cf5b..9fe02dd 100644
Binary files a/node_modules/@triniwiz/nativescript-couchbase/platforms/android/nativescript_couchbase.aar and b/node_modules/@triniwiz/nativescript-couchbase/platforms/android/nativescript_couchbase.aar differ
This issue body was partially generated by patch-package.
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
@triniwiz/nativescript-couchbase@3.0.0for the project I'm working on.Here is the diff that solved my problem:
This issue body was partially generated by patch-package.