cbl-ionic 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CblIonic.podspec +18 -0
- package/LICENSE +201 -0
- package/README.md +19 -0
- package/android/build.gradle +69 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/cbl/js/kotiln/CollectionConfigDto.kt +5 -0
- package/android/src/main/java/cbl/js/kotiln/CollectionDocumentResult.kt +7 -0
- package/android/src/main/java/cbl/js/kotiln/CollectionDto.kt +9 -0
- package/android/src/main/java/cbl/js/kotiln/CollectionManager.kt +232 -0
- package/android/src/main/java/cbl/js/kotiln/ConfigDto.kt +5 -0
- package/android/src/main/java/cbl/js/kotiln/DatabaseManager.kt +183 -0
- package/android/src/main/java/cbl/js/kotiln/DocumentDto.kt +6 -0
- package/android/src/main/java/cbl/js/kotiln/FileSystemHelper.kt +18 -0
- package/android/src/main/java/cbl/js/kotiln/LoggingManager.kt +30 -0
- package/android/src/main/java/cbl/js/kotiln/ReplicatorManager.kt +123 -0
- package/android/src/main/java/cbl/js/kotiln/ScopeDto.kt +6 -0
- package/android/src/main/java/com/couchbase/ionic/CblIonicPluginPlugin.kt +1832 -0
- package/android/src/main/java/com/couchbase/ionic/IndexDto.kt +12 -0
- package/android/src/main/java/com/couchbase/ionic/IndexHelper.kt +30 -0
- package/android/src/main/java/com/couchbase/ionic/PluginHelper.kt +283 -0
- package/android/src/main/java/com/couchbase/ionic/QueryHelper.kt +62 -0
- package/android/src/main/java/com/couchbase/ionic/ReplicatorHelper.kt +174 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/esm/cblite-js/cblite/core-types.d.ts +634 -0
- package/dist/esm/cblite-js/cblite/core-types.js +2 -0
- package/dist/esm/cblite-js/cblite/core-types.js.map +1 -0
- package/dist/esm/cblite-js/cblite/index.d.ts +2 -0
- package/dist/esm/cblite-js/cblite/index.js +4 -0
- package/dist/esm/cblite-js/cblite/index.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/abstract-index.d.ts +14 -0
- package/dist/esm/cblite-js/cblite/src/abstract-index.js +12 -0
- package/dist/esm/cblite-js/cblite/src/abstract-index.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/authenticator.d.ts +6 -0
- package/dist/esm/cblite-js/cblite/src/authenticator.js +3 -0
- package/dist/esm/cblite-js/cblite/src/authenticator.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/basic-authenticator.d.ts +42 -0
- package/dist/esm/cblite-js/cblite/src/basic-authenticator.js +59 -0
- package/dist/esm/cblite-js/cblite/src/basic-authenticator.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/blob.d.ts +58 -0
- package/dist/esm/cblite-js/cblite/src/blob.js +86 -0
- package/dist/esm/cblite-js/cblite/src/blob.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/collation.d.ts +20 -0
- package/dist/esm/cblite-js/cblite/src/collation.js +64 -0
- package/dist/esm/cblite-js/cblite/src/collation.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/collection-config.d.ts +24 -0
- package/dist/esm/cblite-js/cblite/src/collection-config.js +30 -0
- package/dist/esm/cblite-js/cblite/src/collection-config.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/collection.d.ts +189 -0
- package/dist/esm/cblite-js/cblite/src/collection.js +354 -0
- package/dist/esm/cblite-js/cblite/src/collection.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/concurrency-control.d.ts +4 -0
- package/dist/esm/cblite-js/cblite/src/concurrency-control.js +8 -0
- package/dist/esm/cblite-js/cblite/src/concurrency-control.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/couchbase-lite-exception.d.ts +6 -0
- package/dist/esm/cblite-js/cblite/src/couchbase-lite-exception.js +15 -0
- package/dist/esm/cblite-js/cblite/src/couchbase-lite-exception.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/database-configuration.d.ts +52 -0
- package/dist/esm/cblite-js/cblite/src/database-configuration.js +75 -0
- package/dist/esm/cblite-js/cblite/src/database-configuration.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/database-logging.d.ts +13 -0
- package/dist/esm/cblite-js/cblite/src/database-logging.js +13 -0
- package/dist/esm/cblite-js/cblite/src/database-logging.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/database.d.ts +254 -0
- package/dist/esm/cblite-js/cblite/src/database.js +514 -0
- package/dist/esm/cblite-js/cblite/src/database.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/definitions.d.ts +7 -0
- package/dist/esm/cblite-js/cblite/src/definitions.js +2 -0
- package/dist/esm/cblite-js/cblite/src/definitions.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/document-replication.d.ts +13 -0
- package/dist/esm/cblite-js/cblite/src/document-replication.js +34 -0
- package/dist/esm/cblite-js/cblite/src/document-replication.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/document.d.ts +199 -0
- package/dist/esm/cblite-js/cblite/src/document.js +333 -0
- package/dist/esm/cblite-js/cblite/src/document.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/endpoint.d.ts +3 -0
- package/dist/esm/cblite-js/cblite/src/endpoint.js +2 -0
- package/dist/esm/cblite-js/cblite/src/endpoint.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/engine-locator.d.ts +42 -0
- package/dist/esm/cblite-js/cblite/src/engine-locator.js +50 -0
- package/dist/esm/cblite-js/cblite/src/engine-locator.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/expression.d.ts +134 -0
- package/dist/esm/cblite-js/cblite/src/expression.js +374 -0
- package/dist/esm/cblite-js/cblite/src/expression.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/file-system.d.ts +7 -0
- package/dist/esm/cblite-js/cblite/src/file-system.js +14 -0
- package/dist/esm/cblite-js/cblite/src/file-system.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/full-text-expression.d.ts +28 -0
- package/dist/esm/cblite-js/cblite/src/full-text-expression.js +38 -0
- package/dist/esm/cblite-js/cblite/src/full-text-expression.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/full-text-index.d.ts +47 -0
- package/dist/esm/cblite-js/cblite/src/full-text-index.js +77 -0
- package/dist/esm/cblite-js/cblite/src/full-text-index.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/index-builder.d.ts +20 -0
- package/dist/esm/cblite-js/cblite/src/index-builder.js +25 -0
- package/dist/esm/cblite-js/cblite/src/index-builder.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/index.d.ts +42 -0
- package/dist/esm/cblite-js/cblite/src/index.js +43 -0
- package/dist/esm/cblite-js/cblite/src/index.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/meta-expression.d.ts +10 -0
- package/dist/esm/cblite-js/cblite/src/meta-expression.js +30 -0
- package/dist/esm/cblite-js/cblite/src/meta-expression.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/meta.d.ts +7 -0
- package/dist/esm/cblite-js/cblite/src/meta.js +8 -0
- package/dist/esm/cblite-js/cblite/src/meta.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/mutable-document.d.ts +373 -0
- package/dist/esm/cblite-js/cblite/src/mutable-document.js +481 -0
- package/dist/esm/cblite-js/cblite/src/mutable-document.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/ordering.d.ts +14 -0
- package/dist/esm/cblite-js/cblite/src/ordering.js +31 -0
- package/dist/esm/cblite-js/cblite/src/ordering.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/parameter.d.ts +18 -0
- package/dist/esm/cblite-js/cblite/src/parameter.js +38 -0
- package/dist/esm/cblite-js/cblite/src/parameter.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/parameters.d.ts +17 -0
- package/dist/esm/cblite-js/cblite/src/parameters.js +61 -0
- package/dist/esm/cblite-js/cblite/src/parameters.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/query.d.ts +83 -0
- package/dist/esm/cblite-js/cblite/src/query.js +146 -0
- package/dist/esm/cblite-js/cblite/src/query.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/replicated-document.d.ts +25 -0
- package/dist/esm/cblite-js/cblite/src/replicated-document.js +51 -0
- package/dist/esm/cblite-js/cblite/src/replicated-document.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/replicator-activity-level.d.ts +7 -0
- package/dist/esm/cblite-js/cblite/src/replicator-activity-level.js +14 -0
- package/dist/esm/cblite-js/cblite/src/replicator-activity-level.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/replicator-change.d.ts +14 -0
- package/dist/esm/cblite-js/cblite/src/replicator-change.js +14 -0
- package/dist/esm/cblite-js/cblite/src/replicator-change.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/replicator-configuration.d.ts +341 -0
- package/dist/esm/cblite-js/cblite/src/replicator-configuration.js +516 -0
- package/dist/esm/cblite-js/cblite/src/replicator-configuration.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/replicator-progress.d.ts +9 -0
- package/dist/esm/cblite-js/cblite/src/replicator-progress.js +20 -0
- package/dist/esm/cblite-js/cblite/src/replicator-progress.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/replicator-status.d.ts +13 -0
- package/dist/esm/cblite-js/cblite/src/replicator-status.js +29 -0
- package/dist/esm/cblite-js/cblite/src/replicator-status.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/replicator.d.ts +108 -0
- package/dist/esm/cblite-js/cblite/src/replicator.js +224 -0
- package/dist/esm/cblite-js/cblite/src/replicator.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/result.d.ts +4 -0
- package/dist/esm/cblite-js/cblite/src/result.js +2 -0
- package/dist/esm/cblite-js/cblite/src/result.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/scope.d.ts +31 -0
- package/dist/esm/cblite-js/cblite/src/scope.js +34 -0
- package/dist/esm/cblite-js/cblite/src/scope.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/session-authenticator.d.ts +32 -0
- package/dist/esm/cblite-js/cblite/src/session-authenticator.js +52 -0
- package/dist/esm/cblite-js/cblite/src/session-authenticator.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/url-endpoint.d.ts +8 -0
- package/dist/esm/cblite-js/cblite/src/url-endpoint.js +12 -0
- package/dist/esm/cblite-js/cblite/src/url-endpoint.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/value-index.d.ts +32 -0
- package/dist/esm/cblite-js/cblite/src/value-index.js +54 -0
- package/dist/esm/cblite-js/cblite/src/value-index.js.map +1 -0
- package/dist/esm/cblite-js/cblite/src/variable-expression.d.ts +7 -0
- package/dist/esm/cblite-js/cblite/src/variable-expression.js +15 -0
- package/dist/esm/cblite-js/cblite/src/variable-expression.js.map +1 -0
- package/dist/esm/couchbase-lite/capacitor-engine.d.ts +124 -0
- package/dist/esm/couchbase-lite/capacitor-engine.js +303 -0
- package/dist/esm/couchbase-lite/capacitor-engine.js.map +1 -0
- package/dist/esm/definitions.d.ts +12 -0
- package/dist/esm/definitions.js +4 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/ionic-couchbase-lite.d.ts +3 -0
- package/dist/esm/ionic-couchbase-lite.js +4 -0
- package/dist/esm/ionic-couchbase-lite.js.map +1 -0
- package/dist/plugin.cjs.js +4400 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +4403 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/CblIonicPlugin.swift +1583 -0
- package/ios/Plugin/CblIonicPluginPlugin.h +10 -0
- package/ios/Plugin/CblIonicPluginPlugin.m +86 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/cbl-js-swift/CollectionManager.swift +489 -0
- package/ios/Plugin/cbl-js-swift/DatabaseManager.swift +319 -0
- package/ios/Plugin/cbl-js-swift/FileSystemHelper.swift +22 -0
- package/ios/Plugin/cbl-js-swift/IndexHelper.swift +36 -0
- package/ios/Plugin/cbl-js-swift/LICENSE +201 -0
- package/ios/Plugin/cbl-js-swift/LoggingManager.swift +79 -0
- package/ios/Plugin/cbl-js-swift/MapHelper.swift +92 -0
- package/ios/Plugin/cbl-js-swift/QueryHelper.swift +74 -0
- package/ios/Plugin/cbl-js-swift/README.md +9 -0
- package/ios/Plugin/cbl-js-swift/ReplicatorHelper.swift +184 -0
- package/ios/Plugin/cbl-js-swift/ReplicatorManager.swift +157 -0
- package/package.json +86 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package com.couchbase.ionic
|
|
2
|
+
|
|
3
|
+
import com.couchbase.lite.FullTextIndexItem
|
|
4
|
+
import com.couchbase.lite.ValueIndexItem
|
|
5
|
+
import org.json.JSONArray
|
|
6
|
+
import org.json.JSONException
|
|
7
|
+
|
|
8
|
+
object IndexHelper {
|
|
9
|
+
@Throws(JSONException::class)
|
|
10
|
+
fun makeValueIndexItems(items: JSONArray): Array<ValueIndexItem> {
|
|
11
|
+
return Array(items.length()) { i ->
|
|
12
|
+
val propName = items
|
|
13
|
+
.getJSONArray(i)
|
|
14
|
+
.getString(0)
|
|
15
|
+
.substring(1)
|
|
16
|
+
ValueIndexItem.property(propName)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Throws(JSONException::class)
|
|
21
|
+
fun makeFullTextIndexItems(items: JSONArray): Array<FullTextIndexItem> {
|
|
22
|
+
return Array(items.length()) { i ->
|
|
23
|
+
val propName = items
|
|
24
|
+
.getJSONArray(i)
|
|
25
|
+
.getString(0)
|
|
26
|
+
.substring(1)
|
|
27
|
+
FullTextIndexItem.property(propName)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
package com.couchbase.ionic
|
|
2
|
+
|
|
3
|
+
import cbl.js.kotiln.CollectionDto
|
|
4
|
+
import cbl.js.kotiln.DocumentDto
|
|
5
|
+
import cbl.js.kotiln.ScopeDto
|
|
6
|
+
import com.couchbase.lite.Blob
|
|
7
|
+
import com.couchbase.lite.ConcurrencyControl
|
|
8
|
+
import com.couchbase.lite.Document
|
|
9
|
+
import com.getcapacitor.JSObject
|
|
10
|
+
import com.getcapacitor.PluginCall
|
|
11
|
+
import org.json.JSONArray
|
|
12
|
+
import org.json.JSONException
|
|
13
|
+
import org.json.JSONObject
|
|
14
|
+
|
|
15
|
+
object PluginHelper {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Converts a `Document` object to a `JSObject` representation.
|
|
19
|
+
*
|
|
20
|
+
* This method transforms the given `Document` into a `JSObject` that includes its data, ID, sequence, and revision ID.
|
|
21
|
+
* It iterates through the document's map, and if a value is a `Blob`, it replaces it with its properties in the resulting JSON object.
|
|
22
|
+
*
|
|
23
|
+
* @param document The `Document` object to convert.
|
|
24
|
+
* @return A `JSObject` containing the document's data, ID, sequence, and revision ID, or `null` if an error occurs.
|
|
25
|
+
* @throws Exception If an error occurs during the conversion process.
|
|
26
|
+
*/
|
|
27
|
+
fun documentToMap(document: Document): JSObject {
|
|
28
|
+
try {
|
|
29
|
+
val dMap = document.toMap()
|
|
30
|
+
val docJson = JSONObject(dMap)
|
|
31
|
+
val keys: Iterator<*> = docJson.keys()
|
|
32
|
+
while (keys.hasNext()) {
|
|
33
|
+
val key = keys.next() as String
|
|
34
|
+
val value = dMap[key]
|
|
35
|
+
// only replace the value if it's a blob because
|
|
36
|
+
// JSONObject will not map in the blob object into the JSON object
|
|
37
|
+
// since it's not a supported JSON type
|
|
38
|
+
if (value is Blob) {
|
|
39
|
+
val blobProps = JSONObject(value.properties)
|
|
40
|
+
blobProps.put("raw", JSONArray(value.content))
|
|
41
|
+
docJson.put(key, blobProps)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
val docMap = JSObject()
|
|
45
|
+
docMap.put("_data", docJson)
|
|
46
|
+
docMap.put("_id", document.id)
|
|
47
|
+
docMap.put("_sequence", document.sequence)
|
|
48
|
+
docMap.put("_revId", document.revisionID)
|
|
49
|
+
return docMap
|
|
50
|
+
} catch (ex: Exception) {
|
|
51
|
+
throw ex
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Converts a JSON string representation of blobs into a map of Blob objects.
|
|
57
|
+
*
|
|
58
|
+
* @param value The JSON string containing blob data. The string should be in the format:
|
|
59
|
+
* {
|
|
60
|
+
* "blobKey1": {
|
|
61
|
+
* "data": {
|
|
62
|
+
* "contentType": "mime/type",
|
|
63
|
+
* "data": [byte1, byte2, ...]
|
|
64
|
+
* }
|
|
65
|
+
* },
|
|
66
|
+
* "blobKey2": {
|
|
67
|
+
* "data": {
|
|
68
|
+
* "contentType": "mime/type",
|
|
69
|
+
* "data": [byte1, byte2, ...]
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
* If the string is empty or "[]", an empty map is returned.
|
|
74
|
+
* @return A map where the keys are the blob identifiers and the values are Blob objects.
|
|
75
|
+
* @throws JSONException If the JSON string is malformed or if required fields are missing.
|
|
76
|
+
*/
|
|
77
|
+
@Throws(JSONException::class)
|
|
78
|
+
fun getBlobsFromString(
|
|
79
|
+
value: String):Map<String, Blob>
|
|
80
|
+
{
|
|
81
|
+
val items = mutableMapOf<String, Blob>()
|
|
82
|
+
if (value.isEmpty() || value == "[]") {
|
|
83
|
+
return items
|
|
84
|
+
}
|
|
85
|
+
val jsonObject = JSONObject(value)
|
|
86
|
+
val keys = jsonObject.keys()
|
|
87
|
+
while (keys.hasNext()) {
|
|
88
|
+
val key = keys.next()
|
|
89
|
+
val jsonValue = jsonObject[key]
|
|
90
|
+
if (jsonValue is JSONObject) {
|
|
91
|
+
val blobData = jsonValue.getJSONObject("data")
|
|
92
|
+
val contentType = blobData.getString("contentType")
|
|
93
|
+
val byteData = blobData.getJSONArray("data")
|
|
94
|
+
val data = ByteArray(byteData.length())
|
|
95
|
+
for (i in 0 until byteData.length()) {
|
|
96
|
+
data[i] = (byteData[i] as Int).toByte()
|
|
97
|
+
}
|
|
98
|
+
items[key] = Blob(contentType, data)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return items
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Extracts and constructs a `CollectionDto` object from the given `PluginCall`.
|
|
106
|
+
*
|
|
107
|
+
* This method retrieves the `name` (database name), `collectionName`, and `scopeName` strings from the `PluginCall` object.
|
|
108
|
+
* If any of these values are missing or empty, the method rejects the call and returns `null`.
|
|
109
|
+
* Otherwise, it constructs and returns a `CollectionDto` object containing the extracted values.
|
|
110
|
+
*
|
|
111
|
+
* @param call The `PluginCall` object from which to extract the `name`, `collectionName`, and `scopeName` strings.
|
|
112
|
+
* @return A `CollectionDto` object containing the extracted `name`, `collectionName`, and `scopeName` strings, or `null` if an error occurs.
|
|
113
|
+
*/
|
|
114
|
+
fun getCollectionDtoFromCall(call: PluginCall): CollectionDto? {
|
|
115
|
+
var isError = false
|
|
116
|
+
val (databaseName, isDatabaseNameError) = getStringFromCall(call, "name")
|
|
117
|
+
val (collectionName, isCollectionNameError) = getStringFromCall(call, "collectionName")
|
|
118
|
+
val (scopeName, isScopeNameError) = getStringFromCall(call, "scopeName")
|
|
119
|
+
if (isDatabaseNameError || isCollectionNameError || isScopeNameError) {
|
|
120
|
+
call.reject("Error: No couldn't parse collectionName, scopeName, or name (database name)")
|
|
121
|
+
isError = true
|
|
122
|
+
}
|
|
123
|
+
collectionName?.let { colName ->
|
|
124
|
+
scopeName?.let { scpName ->
|
|
125
|
+
databaseName?.let { dbName ->
|
|
126
|
+
return CollectionDto(colName, scpName, dbName, isError)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return null
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Converts an integer value to a `ConcurrencyControl` enum.
|
|
135
|
+
*
|
|
136
|
+
* This method maps the given integer value to a corresponding `ConcurrencyControl` enum value.
|
|
137
|
+
* The mapping is as follows:
|
|
138
|
+
* - 0: `ConcurrencyControl.LAST_WRITE_WINS`
|
|
139
|
+
* - 1: `ConcurrencyControl.FAIL_ON_CONFLICT`
|
|
140
|
+
* - Any other value: `ConcurrencyControl.LAST_WRITE_WINS`
|
|
141
|
+
*
|
|
142
|
+
* @param concurrencyControlValue The integer value to convert.
|
|
143
|
+
* @return The corresponding `ConcurrencyControl` enum value.
|
|
144
|
+
*/
|
|
145
|
+
fun getConcurrencyControlFromInt(concurrencyControlValue: Int): ConcurrencyControl =
|
|
146
|
+
when (concurrencyControlValue) {
|
|
147
|
+
0 -> ConcurrencyControl.LAST_WRITE_WINS
|
|
148
|
+
1 -> ConcurrencyControl.FAIL_ON_CONFLICT
|
|
149
|
+
else -> ConcurrencyControl.LAST_WRITE_WINS
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Extracts and constructs a `DocumentDto` object from the given `PluginCall`.
|
|
154
|
+
*
|
|
155
|
+
* This method retrieves the `document` and `blobs` strings from the `PluginCall` object.
|
|
156
|
+
* If either of these values is missing or empty, the method rejects the call and returns `null`.
|
|
157
|
+
* Otherwise, it constructs and returns a `DocumentDto` object containing the extracted values.
|
|
158
|
+
*
|
|
159
|
+
* @param call The `PluginCall` object from which to extract the `document` and `blobs` strings.
|
|
160
|
+
* @return A `DocumentDto` object containing the extracted `document` and `blobs` strings, or `null` if an error occurs.
|
|
161
|
+
*/
|
|
162
|
+
fun getDocumentDtoFromCall(call: PluginCall): DocumentDto? {
|
|
163
|
+
var isError = false
|
|
164
|
+
val (document, isDocumentError) = getStringFromCall(call, "document")
|
|
165
|
+
val (blobs, isBlobsError) = getStringFromCall(call, "blobs")
|
|
166
|
+
if (isDocumentError || isBlobsError) {
|
|
167
|
+
call.reject("Error: No couldn't parse document or blobs")
|
|
168
|
+
isError = true
|
|
169
|
+
}
|
|
170
|
+
document?.let { docValue ->
|
|
171
|
+
blobs?.let { blobsValue ->
|
|
172
|
+
return DocumentDto(docValue, blobsValue, isError)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return null
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Extracts and constructs an `IndexDto` object from the given `PluginCall`.
|
|
180
|
+
*
|
|
181
|
+
* This method retrieves the `indexName`, `type`, and `items` from the `index` object within the `PluginCall`.
|
|
182
|
+
* If any of these values are missing or empty, the method rejects the call and returns an `IndexDto` object with `isError` set to `true`.
|
|
183
|
+
* Otherwise, it constructs and returns an `IndexDto` object containing the extracted values.
|
|
184
|
+
*
|
|
185
|
+
* @param call The `PluginCall` object from which to extract the `indexName`, `type`, and `items`.
|
|
186
|
+
* @return An `IndexDto` object containing the extracted `indexName`, `type`, and `items`, or an `IndexDto` object with `isError` set to `true` if an error occurs.
|
|
187
|
+
*/
|
|
188
|
+
fun getIndexDtoFromCall(call: PluginCall): IndexDto? {
|
|
189
|
+
val (indexName, isIndexNameError) = getStringFromCall(call, "indexName")
|
|
190
|
+
val indexData = call.getObject("index")
|
|
191
|
+
val items = indexData?.getJSONArray("items")
|
|
192
|
+
val indexType = indexData?.getString("type")
|
|
193
|
+
if (isIndexNameError || indexData == null || items == null || indexType.isNullOrEmpty()) {
|
|
194
|
+
call.reject("Error: No couldn't parse indexName, type, or index, or items")
|
|
195
|
+
return IndexDto(
|
|
196
|
+
null,
|
|
197
|
+
null,
|
|
198
|
+
null,
|
|
199
|
+
null,
|
|
200
|
+
true,
|
|
201
|
+
)
|
|
202
|
+
} else {
|
|
203
|
+
return IndexDto(
|
|
204
|
+
indexName,
|
|
205
|
+
indexType,
|
|
206
|
+
indexData,
|
|
207
|
+
items,
|
|
208
|
+
false,
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* getIntFromCall - used to get a int value from a call JSON object
|
|
215
|
+
* passed in from Ionic
|
|
216
|
+
*
|
|
217
|
+
* @param call PluginCall object from Ionic
|
|
218
|
+
* @param varName int value of the value to get out of the call object
|
|
219
|
+
* @return Pair<Int?, Boolean> A pair of the int value and
|
|
220
|
+
* a boolean indicating if there is an error or not - if true then
|
|
221
|
+
* error, if false, no error
|
|
222
|
+
*/
|
|
223
|
+
fun getIntFromCall(
|
|
224
|
+
call: PluginCall,
|
|
225
|
+
varName: String,
|
|
226
|
+
): Pair<Int?, Boolean> {
|
|
227
|
+
val value: Int? = call.getInt(varName)
|
|
228
|
+
if (value == null) {
|
|
229
|
+
call.reject("Error: No $varName provided in call")
|
|
230
|
+
return Pair(null, true)
|
|
231
|
+
}
|
|
232
|
+
return Pair(value, false)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Extracts and constructs a `ScopeDto` object from the given `PluginCall`.
|
|
237
|
+
*
|
|
238
|
+
* This method retrieves the `name` (database name) and `scopeName` strings from the `PluginCall` object.
|
|
239
|
+
* If either of these values is missing or empty, the method rejects the call and returns `null`.
|
|
240
|
+
* Otherwise, it constructs and returns a `ScopeDto` object containing the extracted values.
|
|
241
|
+
*
|
|
242
|
+
* @param call The `PluginCall` object from which to extract the `name` and `scopeName` strings.
|
|
243
|
+
* @return A `ScopeDto` object containing the extracted `name` and `scopeName` strings, or `null` if an error occurs.
|
|
244
|
+
*/
|
|
245
|
+
fun getScopeDtoFromCall(call: PluginCall): ScopeDto? {
|
|
246
|
+
var isError = false
|
|
247
|
+
val (databaseName, isDatabaseNameError) = getStringFromCall(call, "name")
|
|
248
|
+
val (scopeName, isScopeNameError) = getStringFromCall(call, "scopeName")
|
|
249
|
+
if (isDatabaseNameError || isScopeNameError) {
|
|
250
|
+
call.reject("Error: No couldn't parse scopeName or name (database name)")
|
|
251
|
+
|
|
252
|
+
isError = true
|
|
253
|
+
}
|
|
254
|
+
scopeName?.let { scpName ->
|
|
255
|
+
databaseName?.let { dbName ->
|
|
256
|
+
return ScopeDto(scpName, dbName, isError)
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return null
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* getStringFromCall - used to get a string value from a call JSON object
|
|
264
|
+
* passed in from Ionic
|
|
265
|
+
*
|
|
266
|
+
* @param call PluginCall object from Ionic
|
|
267
|
+
* @param varName string value of the value to get out of the call object
|
|
268
|
+
* @return Pair<String?, Boolean> A pair of the string value and
|
|
269
|
+
* a boolean indicating if there is an error or not - if true then
|
|
270
|
+
* error, if false, no error
|
|
271
|
+
*/
|
|
272
|
+
fun getStringFromCall(
|
|
273
|
+
call: PluginCall,
|
|
274
|
+
varName: String,
|
|
275
|
+
): Pair<String?, Boolean> {
|
|
276
|
+
val value: String? = call.getString(varName)
|
|
277
|
+
if (value.isNullOrEmpty()) {
|
|
278
|
+
call.reject("Error: No $varName provided in call")
|
|
279
|
+
return Pair(null, true)
|
|
280
|
+
}
|
|
281
|
+
return Pair(value, false)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
package com.couchbase.ionic
|
|
2
|
+
|
|
3
|
+
import com.couchbase.lite.Parameters
|
|
4
|
+
import com.getcapacitor.JSObject
|
|
5
|
+
import java.text.SimpleDateFormat
|
|
6
|
+
|
|
7
|
+
object QueryHelper {
|
|
8
|
+
fun getQueryParameters(jsObject: JSObject): Parameters {
|
|
9
|
+
val queryParameters = Parameters()
|
|
10
|
+
for(key in jsObject.keys()){
|
|
11
|
+
val nestedObject = jsObject.getJSObject(key)
|
|
12
|
+
nestedObject?.let {
|
|
13
|
+
val type = it.getString("type")
|
|
14
|
+
val valueKey = "value"
|
|
15
|
+
when(type){
|
|
16
|
+
"string" -> {
|
|
17
|
+
val strValue = it.getString(valueKey)
|
|
18
|
+
queryParameters.setString(key, strValue)
|
|
19
|
+
}
|
|
20
|
+
"float" -> {
|
|
21
|
+
val floatValue = it.getDouble(valueKey).toFloat()
|
|
22
|
+
queryParameters.setFloat(key, floatValue)
|
|
23
|
+
}
|
|
24
|
+
"boolean" -> {
|
|
25
|
+
val boolValue = it.getBoolean(valueKey)
|
|
26
|
+
queryParameters.setBoolean(key, boolValue)
|
|
27
|
+
}
|
|
28
|
+
"double" -> {
|
|
29
|
+
val doubleValue = it.getDouble(valueKey)
|
|
30
|
+
queryParameters.setDouble(key, doubleValue)
|
|
31
|
+
}
|
|
32
|
+
"date" -> {
|
|
33
|
+
val dateValue = it.getString(valueKey)
|
|
34
|
+
dateValue?.let { strValue ->
|
|
35
|
+
//
|
|
36
|
+
//bug in SDK with Android and Date
|
|
37
|
+
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
|
|
38
|
+
val date = dateFormat.parse(strValue)
|
|
39
|
+
date?.let {d ->
|
|
40
|
+
queryParameters.setDate(key, d)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
"int" -> {
|
|
45
|
+
val intValue = it.getInt(valueKey)
|
|
46
|
+
queryParameters.setInt(key, intValue)
|
|
47
|
+
}
|
|
48
|
+
"long" -> {
|
|
49
|
+
val longValue = it.getLong(valueKey)
|
|
50
|
+
queryParameters.setLong(key, longValue)
|
|
51
|
+
}
|
|
52
|
+
"value" -> {
|
|
53
|
+
val value = it.get(valueKey)
|
|
54
|
+
queryParameters.setValue(key, value)
|
|
55
|
+
}
|
|
56
|
+
else -> throw Exception("Invalid type sent")
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return queryParameters
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
package com.couchbase.ionic
|
|
2
|
+
|
|
3
|
+
import cbl.js.kotiln.DatabaseManager
|
|
4
|
+
import com.couchbase.lite.Authenticator
|
|
5
|
+
import com.couchbase.lite.BasicAuthenticator
|
|
6
|
+
import com.couchbase.lite.CollectionConfiguration
|
|
7
|
+
import com.couchbase.lite.DocumentFlag
|
|
8
|
+
import com.couchbase.lite.DocumentReplication
|
|
9
|
+
import com.couchbase.lite.ReplicatorConfiguration
|
|
10
|
+
import com.couchbase.lite.ReplicatorConfigurationFactory
|
|
11
|
+
import com.couchbase.lite.ReplicatorStatus
|
|
12
|
+
import com.couchbase.lite.ReplicatorType
|
|
13
|
+
import com.couchbase.lite.SessionAuthenticator
|
|
14
|
+
import com.couchbase.lite.URLEndpoint
|
|
15
|
+
import com.couchbase.lite.newConfig
|
|
16
|
+
import com.getcapacitor.JSArray
|
|
17
|
+
import com.getcapacitor.JSObject
|
|
18
|
+
import org.json.JSONArray
|
|
19
|
+
import org.json.JSONObject
|
|
20
|
+
import java.net.URI
|
|
21
|
+
import com.couchbase.lite.Collection as CBLCollection
|
|
22
|
+
|
|
23
|
+
object ReplicatorHelper {
|
|
24
|
+
|
|
25
|
+
fun replicatorConfigFromJson(config: JSObject,
|
|
26
|
+
collectionConfig: JSONArray
|
|
27
|
+
)
|
|
28
|
+
: ReplicatorConfiguration {
|
|
29
|
+
val target = config.getJSObject("target")
|
|
30
|
+
val url = target?.getString("url")
|
|
31
|
+
val replicatorTypeString = config.getString("replicatorType")
|
|
32
|
+
if (url.isNullOrEmpty() || replicatorTypeString.isNullOrEmpty()){
|
|
33
|
+
throw IllegalArgumentException("Replicator target url or replicator type is required")
|
|
34
|
+
}
|
|
35
|
+
val uri = URI(url)
|
|
36
|
+
val endpoint = URLEndpoint(uri)
|
|
37
|
+
val continuous = config.getBoolean("continuous")
|
|
38
|
+
val acceptParentDomainCookies = config.getBoolean("acceptParentDomainCookies")
|
|
39
|
+
val acceptSelfSignedCerts = config.getBoolean("acceptSelfSignedCerts")
|
|
40
|
+
val autoPurgeEnabled = config.getBoolean("autoPurgeEnabled")
|
|
41
|
+
val replicatorType = getReplicatorTypeFromString(replicatorTypeString)
|
|
42
|
+
|
|
43
|
+
val configBuilder = ReplicatorConfigurationFactory.newConfig(
|
|
44
|
+
target = endpoint,
|
|
45
|
+
continuous = continuous,
|
|
46
|
+
acceptParentDomainCookies = acceptParentDomainCookies,
|
|
47
|
+
acceptOnlySelfSignedServerCertificate = acceptSelfSignedCerts,
|
|
48
|
+
enableAutoPurge = autoPurgeEnabled,
|
|
49
|
+
type = replicatorType,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
//optional values
|
|
53
|
+
val authenticatorJson = config.optJSONObject("authenticator")
|
|
54
|
+
authenticatorJson?.let {
|
|
55
|
+
val auth = getAuthenticatorFromJson(it)
|
|
56
|
+
configBuilder.setAuthenticator(auth)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//loop through the collections and configuration and add to the config
|
|
60
|
+
//the item will have two keys, collections and config
|
|
61
|
+
for (itemCounter in 0 until collectionConfig.length()) {
|
|
62
|
+
val itemObject = collectionConfig.getJSONObject(itemCounter)
|
|
63
|
+
val collections = itemObject.optJSONArray("collections")
|
|
64
|
+
val mutableCollections = mutableListOf<CBLCollection>()
|
|
65
|
+
if (collections == null || collections.length() == 0) {
|
|
66
|
+
throw IllegalArgumentException("No collections found in the config")
|
|
67
|
+
} else {
|
|
68
|
+
for(collectionCounter in 0 until collections.length()) {
|
|
69
|
+
val collectionItemObj = collections.getJSONObject(collectionCounter)
|
|
70
|
+
val collectionObj = collectionItemObj.getJSONObject("collection")
|
|
71
|
+
val collectionName = collectionObj.getString("name")
|
|
72
|
+
val scopeName = collectionObj.getString("scopeName")
|
|
73
|
+
val databaseName = collectionObj.getString("databaseName")
|
|
74
|
+
val collection = DatabaseManager.getCollection(collectionName, scopeName, databaseName)
|
|
75
|
+
if (collection == null) {
|
|
76
|
+
throw IllegalArgumentException("Collection not found")
|
|
77
|
+
} else {
|
|
78
|
+
mutableCollections.add(collection)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//get the configuration for the collections which is a collection
|
|
83
|
+
//of documentIds and channels to filter
|
|
84
|
+
//these should be optional, where at least one collection is needed to be added
|
|
85
|
+
val replicatorCollectionConfig = CollectionConfiguration()
|
|
86
|
+
val configObj = itemObject.optJSONObject("config")
|
|
87
|
+
if (configObj != null){
|
|
88
|
+
val documentIds = configObj.optJSONArray("documentIds")
|
|
89
|
+
if (documentIds != null) {
|
|
90
|
+
val ids = mutableListOf<String>()
|
|
91
|
+
for (i in 0 until documentIds.length()) {
|
|
92
|
+
ids.add(documentIds.getString(i))
|
|
93
|
+
}
|
|
94
|
+
replicatorCollectionConfig.documentIDs = ids
|
|
95
|
+
}
|
|
96
|
+
val channels = configObj.optJSONArray("channels")
|
|
97
|
+
if (channels != null) {
|
|
98
|
+
val channelsList = mutableListOf<String>()
|
|
99
|
+
for (i in 0 until channels.length()) {
|
|
100
|
+
channelsList.add(channels.getString(i))
|
|
101
|
+
}
|
|
102
|
+
replicatorCollectionConfig.channels = channelsList
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
configBuilder.addCollections(mutableCollections, replicatorCollectionConfig)
|
|
106
|
+
}
|
|
107
|
+
return configBuilder
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private fun getAuthenticatorFromJson(authenticator: JSONObject): Authenticator {
|
|
111
|
+
val type = authenticator.getString("type")
|
|
112
|
+
val data = authenticator.getJSONObject("data")
|
|
113
|
+
return when (type) {
|
|
114
|
+
"basic" -> {
|
|
115
|
+
val username = data.getString("username")
|
|
116
|
+
val password = data.getString("password")
|
|
117
|
+
BasicAuthenticator(username, password.toCharArray())
|
|
118
|
+
}
|
|
119
|
+
"session" -> {
|
|
120
|
+
val sessionId = authenticator.getString("sessionId")
|
|
121
|
+
val cookieName = authenticator.getString("cookieName")
|
|
122
|
+
SessionAuthenticator(sessionId, cookieName)
|
|
123
|
+
}
|
|
124
|
+
else -> throw IllegalArgumentException("Invalid authenticator type")
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private fun getReplicatorTypeFromString(strValue :String): ReplicatorType {
|
|
129
|
+
return when (strValue) {
|
|
130
|
+
"PUSH" -> ReplicatorType.PUSH
|
|
131
|
+
"PULL" -> ReplicatorType.PULL
|
|
132
|
+
"PUSH_AND_PULL" -> ReplicatorType.PUSH_AND_PULL
|
|
133
|
+
else -> throw IllegalArgumentException("Invalid replicator type")
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
fun generateReplicatorStatusJson(status: ReplicatorStatus): JSObject {
|
|
138
|
+
val json = JSObject()
|
|
139
|
+
val progressJson = JSObject()
|
|
140
|
+
val errorJson = JSObject()
|
|
141
|
+
status.error?.let {
|
|
142
|
+
errorJson.put("message", it.message)
|
|
143
|
+
}
|
|
144
|
+
progressJson.put("completed", status.progress.completed)
|
|
145
|
+
progressJson.put("total", status.progress.total)
|
|
146
|
+
json.put("activity", status.activityLevel.name)
|
|
147
|
+
json.put("progress", progressJson)
|
|
148
|
+
json.put("error", errorJson)
|
|
149
|
+
return json
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
fun generateReplicatorDocumentChangeJson(change: DocumentReplication) : JSObject {
|
|
153
|
+
val json = JSObject()
|
|
154
|
+
val docs = JSArray()
|
|
155
|
+
for (doc in change.documents) {
|
|
156
|
+
val docJson = JSObject()
|
|
157
|
+
val flags = JSArray()
|
|
158
|
+
if (doc.flags.contains(DocumentFlag.DELETED)) {
|
|
159
|
+
flags.put("DELETED")
|
|
160
|
+
} else if (doc.flags.contains(DocumentFlag.ACCESS_REMOVED)) {
|
|
161
|
+
flags.put("ACCESS_REMOVED")
|
|
162
|
+
}
|
|
163
|
+
docJson.put("flags", flags)
|
|
164
|
+
docJson.put("id", doc.id)
|
|
165
|
+
docJson.put("scopeName", doc.scope)
|
|
166
|
+
docJson.put("collectionName", doc.collection)
|
|
167
|
+
docJson.put("error", doc.error?.message)
|
|
168
|
+
docs.put(docJson)
|
|
169
|
+
}
|
|
170
|
+
json.put("documents", docs)
|
|
171
|
+
json.put("isPush", change.isPush)
|
|
172
|
+
return json
|
|
173
|
+
}
|
|
174
|
+
}
|
|
File without changes
|