cbl-ionic 0.2.6 → 1.0.1

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.
Files changed (62) hide show
  1. package/CblIonic.podspec +1 -1
  2. package/README.md +12 -0
  3. package/android/build.gradle +1 -1
  4. package/android/src/main/java/cbl/js/kotiln/DatabaseManager.kt +19 -6
  5. package/android/src/main/java/cbl/js/kotiln/URLEndpointListenerManager.kt +143 -0
  6. package/android/src/main/java/com/couchbase/ionic/CblIonicPluginPlugin.kt +186 -30
  7. package/android/src/main/java/com/couchbase/ionic/PluginHelper.kt +27 -38
  8. package/android/src/main/java/com/couchbase/ionic/QueryHelper.kt +14 -4
  9. package/android/src/main/java/com/couchbase/ionic/ReplicatorHelper.kt +33 -11
  10. package/dist/esm/cblite-js/cblite/core-types.d.ts +148 -5
  11. package/dist/esm/cblite-js/cblite/src/collection-config.d.ts +34 -0
  12. package/dist/esm/cblite-js/cblite/src/collection-config.js +40 -0
  13. package/dist/esm/cblite-js/cblite/src/collection-config.js.map +1 -1
  14. package/dist/esm/cblite-js/cblite/src/collection.d.ts +1 -2
  15. package/dist/esm/cblite-js/cblite/src/collection.js +17 -17
  16. package/dist/esm/cblite-js/cblite/src/collection.js.map +1 -1
  17. package/dist/esm/cblite-js/cblite/src/database-logging.js +1 -1
  18. package/dist/esm/cblite-js/cblite/src/database-logging.js.map +1 -1
  19. package/dist/esm/cblite-js/cblite/src/database.d.ts +13 -2
  20. package/dist/esm/cblite-js/cblite/src/database.js +50 -34
  21. package/dist/esm/cblite-js/cblite/src/database.js.map +1 -1
  22. package/dist/esm/cblite-js/cblite/src/document.d.ts +3 -4
  23. package/dist/esm/cblite-js/cblite/src/document.js +6 -6
  24. package/dist/esm/cblite-js/cblite/src/document.js.map +1 -1
  25. package/dist/esm/cblite-js/cblite/src/index.d.ts +1 -0
  26. package/dist/esm/cblite-js/cblite/src/index.js +1 -0
  27. package/dist/esm/cblite-js/cblite/src/index.js.map +1 -1
  28. package/dist/esm/cblite-js/cblite/src/query.js +6 -11
  29. package/dist/esm/cblite-js/cblite/src/query.js.map +1 -1
  30. package/dist/esm/cblite-js/cblite/src/replicated-document.js +2 -2
  31. package/dist/esm/cblite-js/cblite/src/replicated-document.js.map +1 -1
  32. package/dist/esm/cblite-js/cblite/src/replicator-configuration.d.ts +2 -1
  33. package/dist/esm/cblite-js/cblite/src/replicator-configuration.js +29 -3
  34. package/dist/esm/cblite-js/cblite/src/replicator-configuration.js.map +1 -1
  35. package/dist/esm/cblite-js/cblite/src/replicator.js +8 -5
  36. package/dist/esm/cblite-js/cblite/src/replicator.js.map +1 -1
  37. package/dist/esm/cblite-js/cblite/src/scope.js +2 -2
  38. package/dist/esm/cblite-js/cblite/src/scope.js.map +1 -1
  39. package/dist/esm/cblite-js/cblite/src/url-endpoint-listener.d.ts +84 -0
  40. package/dist/esm/cblite-js/cblite/src/url-endpoint-listener.js +109 -0
  41. package/dist/esm/cblite-js/cblite/src/url-endpoint-listener.js.map +1 -0
  42. package/dist/esm/couchbase-lite/capacitor-engine.d.ts +17 -2
  43. package/dist/esm/couchbase-lite/capacitor-engine.js +19 -1
  44. package/dist/esm/couchbase-lite/capacitor-engine.js.map +1 -1
  45. package/dist/plugin.cjs.js +288 -82
  46. package/dist/plugin.cjs.js.map +1 -1
  47. package/dist/plugin.js +288 -82
  48. package/dist/plugin.js.map +1 -1
  49. package/ios/Plugin/CblIonicPlugin.swift +120 -7
  50. package/ios/Plugin/CblIonicPluginPlugin.m +7 -0
  51. package/ios/Plugin/cbl-js-swift/CollectionManager.swift +24 -3
  52. package/ios/Plugin/cbl-js-swift/DatabaseManager.swift +29 -13
  53. package/ios/Plugin/cbl-js-swift/FileSystemHelper.swift +0 -2
  54. package/ios/Plugin/cbl-js-swift/IndexHelper.swift +0 -2
  55. package/ios/Plugin/cbl-js-swift/LoggingManager.swift +0 -2
  56. package/ios/Plugin/cbl-js-swift/MapHelper.swift +0 -25
  57. package/ios/Plugin/cbl-js-swift/QueryHelper.swift +0 -2
  58. package/ios/Plugin/cbl-js-swift/README.md +12 -0
  59. package/ios/Plugin/cbl-js-swift/ReplicatorHelper.swift +116 -5
  60. package/ios/Plugin/cbl-js-swift/ReplicatorManager.swift +0 -2
  61. package/ios/Plugin/cbl-js-swift/URLEndpointListenerManager.swift +154 -0
  62. package/package.json +8 -3
package/dist/plugin.js CHANGED
@@ -44,6 +44,46 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
44
44
  setDocumentIDs(documentIds) {
45
45
  this.documentIds = documentIds;
46
46
  }
47
+ /**
48
+ * Set a filter function for push replication. Only documents for which the function returns true will be pushed.
49
+ * Inside filter body document and flag object methods can't be used.
50
+ * @param {ReplicationFilter} filter - Function that returns true to replicate the document
51
+ * @example
52
+ * const config = new CollectionConfig();
53
+ * config.setPushFilter((doc, flags) => {
54
+ * return doc["type"] === 'user' && !flags.includes(ReplicatedDocumentFlag.DELETED);
55
+ * });
56
+ */
57
+ setPushFilter(filter) {
58
+ // Convert function to string for bridge transport
59
+ this.pushFilter = filter.toString();
60
+ }
61
+ /**
62
+ * Set a filter function for pull replication. Only documents for which the function returns true will be pulled.
63
+ * Inside filter body document and flag object methods can't be used.
64
+ * @param {ReplicationFilter} filter - Function that returns true to replicate the document
65
+ * @example
66
+ * const config = new CollectionConfig();
67
+ * config.setPullFilter((doc, flags) => {
68
+ * return doc["type"] === 'user' && !flags.includes(ReplicatedDocumentFlag.DELETED);
69
+ * });
70
+ */
71
+ setPullFilter(filter) {
72
+ // Convert function to string for bridge transport
73
+ this.pullFilter = filter.toString();
74
+ }
75
+ /**
76
+ * Get the pull filter function string
77
+ */
78
+ getPushFilter() {
79
+ return this.pushFilter;
80
+ }
81
+ /**
82
+ * Get the pull filter function string
83
+ */
84
+ getPullFilter() {
85
+ return this.pullFilter;
86
+ }
47
87
  }
48
88
 
49
89
  exports.ReplicatorType = void 0;
@@ -74,7 +114,13 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
74
114
  this.headers = undefined;
75
115
  this.pinnedServerCertificate = undefined;
76
116
  }
77
- // eslint-disable-next-line no-dupe-class-members
117
+ /**
118
+ * Add a collection used for the replication with an optional collection configuration. If the collection has
119
+ * been added before, the previous added and its configuration if specified will be replaced. If the config is omitted or a null or undefined configuration is specified, a default empty configuration will be applied.
120
+ *
121
+ * @function
122
+ */
123
+ // eslint-disable-next-line
78
124
  addCollection(collection, config) {
79
125
  const cols = [];
80
126
  cols.push(collection);
@@ -453,6 +499,26 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
453
499
  setReplicatorType(replicatorType) {
454
500
  this.replicatorType = replicatorType;
455
501
  }
502
+ clone() {
503
+ const clonedConfig = new ReplicatorConfiguration(this.target);
504
+ // Copy primitive and object properties
505
+ clonedConfig.setContinuous(this.getContinuous());
506
+ clonedConfig.setHeaders({ ...this.getHeaders() }); // Deep copy headers
507
+ clonedConfig.setAuthenticator(this.getAuthenticator());
508
+ clonedConfig.setPinnedServerCertificate(this.getPinnedServerCertificate());
509
+ clonedConfig.setAllowReplicatingInBackground(this.getAllowReplicatingInBackground());
510
+ clonedConfig.setAutoPurgeEnabled(this.getAutoPurgeEnabled());
511
+ clonedConfig.setAcceptParentDomainCookies(this.getAcceptParentDomainCookies());
512
+ clonedConfig.setMaxAttempts(this.getMaxAttempts());
513
+ clonedConfig.setMaxAttemptWaitTime(this.getMaxAttemptWaitTime());
514
+ clonedConfig.setHeartbeat(this.getHeartbeat());
515
+ clonedConfig.setReplicatorType(this.getReplicatorType());
516
+ // Clone collections
517
+ for (const [collections, config] of this.collections) {
518
+ clonedConfig.addCollections([...collections], config);
519
+ }
520
+ return clonedConfig;
521
+ }
456
522
  toJson() {
457
523
  const config = {
458
524
  acceptParentDomainCookies: this.acceptParentDomainCookies,
@@ -527,10 +593,10 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
527
593
  for (const [collections, _] of this.collections) {
528
594
  for (const collection of collections) {
529
595
  if (databaseName === null && scopeName === null) {
530
- databaseName = collection.database.getName();
596
+ databaseName = collection.database.getUniqueName();
531
597
  scopeName = collection.scope.name;
532
598
  }
533
- else if (collection.database.getName() !== databaseName ||
599
+ else if (collection.database.getUniqueName() !== databaseName ||
534
600
  collection.scope.name !== scopeName) {
535
601
  return false;
536
602
  }
@@ -831,7 +897,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
831
897
  */
832
898
  async collections() {
833
899
  const results = await this._engine.collection_GetCollections({
834
- name: this.database.getName(),
900
+ name: this.database.getUniqueName(),
835
901
  scopeName: this.name,
836
902
  });
837
903
  return results.collections;
@@ -844,7 +910,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
844
910
  */
845
911
  async collection(collectionName) {
846
912
  return this._engine.collection_GetCollection({
847
- name: this.database.getName(),
913
+ name: this.database.getUniqueName(),
848
914
  collectionName: collectionName,
849
915
  scopeName: this.name,
850
916
  });
@@ -908,16 +974,18 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
908
974
  return null;
909
975
  }
910
976
  /**
911
- * Returns metadata associated with the Blob. Use getBlobContent() to get the Blob’s data.
977
+ * Returns the Blob associated with the given key, including its content.
978
+ * Returns null if the property doesn’t exist, or its value is not a blob.
912
979
  * Throws an error if the collection is deleted or the database is closed.
913
980
  *
914
981
  * @function
915
982
  */
916
- getBlob(key) {
983
+ async getBlob(key) {
917
984
  if (key in this.doc) {
918
985
  const data = this._get(key);
919
986
  if (data && typeof data === 'object' && 'content_type' in data) {
920
- const b = new Blob(data.content_type, data.raw);
987
+ const blobContent = await this.getBlobContent(key);
988
+ const b = new Blob(data.content_type, blobContent);
921
989
  b.digest = data.digest;
922
990
  b.length = data.length;
923
991
  return b;
@@ -926,8 +994,6 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
926
994
  return null;
927
995
  }
928
996
  /**
929
- * @deprecated - use the Blob API getBytes() function instead
930
- *
931
997
  * Get a property’s value as a ArrayBuffer. Returns null if the property doesn’t exist,
932
998
  * or its value is not a blob.
933
999
  *
@@ -941,7 +1007,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
941
1007
  key: key,
942
1008
  collectionName: this.collection.name,
943
1009
  scopeName: this.collection.scope.name,
944
- name: this.collection.scope.database.getName(),
1010
+ name: this.collection.scope.database.getUniqueName(),
945
1011
  });
946
1012
  return data.data;
947
1013
  }
@@ -1209,7 +1275,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1209
1275
  const token = this.uuid();
1210
1276
  if (!this._didStartListener) {
1211
1277
  await this._engine.collection_AddChangeListener({
1212
- name: this.scope.database.getName(),
1278
+ name: this.scope.database.getUniqueName(),
1213
1279
  scopeName: this.scope.name,
1214
1280
  collectionName: this.name,
1215
1281
  changeListenerToken: token,
@@ -1236,7 +1302,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1236
1302
  if (!this._didStartDocumentListener.has(documentId) &&
1237
1303
  !this._documentChangeListener[documentId]) {
1238
1304
  await this._engine.collection_AddDocumentChangeListener({
1239
- name: this.scope.database.getName(),
1305
+ name: this.scope.database.getUniqueName(),
1240
1306
  scopeName: this.scope.name,
1241
1307
  collectionName: this.name,
1242
1308
  changeListenerToken: token,
@@ -1262,7 +1328,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1262
1328
  */
1263
1329
  count() {
1264
1330
  return this._engine.collection_GetCount({
1265
- name: this.scope.database.getName(),
1331
+ name: this.scope.database.getUniqueName(),
1266
1332
  scopeName: this.scope.name,
1267
1333
  collectionName: this.name,
1268
1334
  });
@@ -1274,7 +1340,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1274
1340
  */
1275
1341
  createIndex(indexName, index) {
1276
1342
  return this._engine.collection_CreateIndex({
1277
- name: this.scope.database.getName(),
1343
+ name: this.scope.database.getUniqueName(),
1278
1344
  scopeName: this.scope.name,
1279
1345
  collectionName: this.name,
1280
1346
  indexName: indexName,
@@ -1297,7 +1363,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1297
1363
  deleteDocument(document, concurrencyControl = null) {
1298
1364
  const id = document.getId();
1299
1365
  return this._engine.collection_DeleteDocument({
1300
- name: this.scope.database.getName(),
1366
+ name: this.scope.database.getUniqueName(),
1301
1367
  scopeName: this.scope.name,
1302
1368
  collectionName: this.name,
1303
1369
  docId: id,
@@ -1311,7 +1377,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1311
1377
  */
1312
1378
  deleteIndex(indexName) {
1313
1379
  return this._engine.collection_DeleteIndex({
1314
- name: this.scope.database.getName(),
1380
+ name: this.scope.database.getUniqueName(),
1315
1381
  scopeName: this.scope.name,
1316
1382
  collectionName: this.name,
1317
1383
  indexName: indexName,
@@ -1327,7 +1393,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1327
1393
  async document(id) {
1328
1394
  const docJson = await this._engine.collection_GetDocument({
1329
1395
  docId: id,
1330
- name: this.scope.database.getName(),
1396
+ name: this.scope.database.getUniqueName(),
1331
1397
  scopeName: this.scope.name,
1332
1398
  collectionName: this.name,
1333
1399
  });
@@ -1367,11 +1433,11 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1367
1433
  async getDocumentExpiration(id) {
1368
1434
  const date = await this._engine.collection_GetDocumentExpiration({
1369
1435
  docId: id,
1370
- name: this.scope.database.getName(),
1436
+ name: this.scope.database.getUniqueName(),
1371
1437
  scopeName: this.scope.name,
1372
1438
  collectionName: this.name,
1373
1439
  });
1374
- if (date !== null && date.date !== null) {
1440
+ if (!!date && date?.date) {
1375
1441
  return date.date;
1376
1442
  }
1377
1443
  else {
@@ -1393,7 +1459,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1393
1459
  */
1394
1460
  async indexes() {
1395
1461
  const indexes = await this._engine.collection_GetIndexes({
1396
- name: this.scope.database.getName(),
1462
+ name: this.scope.database.getUniqueName(),
1397
1463
  scopeName: this.scope.name,
1398
1464
  collectionName: this.name,
1399
1465
  });
@@ -1431,7 +1497,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1431
1497
  */
1432
1498
  purge(document) {
1433
1499
  return this._engine.collection_PurgeDocument({
1434
- name: this.database.getName(),
1500
+ name: this.database.getUniqueName(),
1435
1501
  scopeName: this.scope.name,
1436
1502
  collectionName: this.name,
1437
1503
  docId: document.getId(),
@@ -1447,7 +1513,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1447
1513
  */
1448
1514
  purgeById(documentId) {
1449
1515
  return this._engine.collection_PurgeDocument({
1450
- name: this.database.getName(),
1516
+ name: this.database.getUniqueName(),
1451
1517
  scopeName: this.scope.name,
1452
1518
  collectionName: this.name,
1453
1519
  docId: documentId,
@@ -1462,7 +1528,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1462
1528
  */
1463
1529
  async removeChangeListener(token) {
1464
1530
  await this._engine.collection_RemoveChangeListener({
1465
- name: this.database.getName(),
1531
+ name: this.database.getUniqueName(),
1466
1532
  scopeName: this.scope.name,
1467
1533
  collectionName: this.name,
1468
1534
  changeListenerToken: token,
@@ -1477,7 +1543,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1477
1543
  */
1478
1544
  async removeDocumentChangeListener(token) {
1479
1545
  await this._engine.collection_RemoveDocumentChangeListener({
1480
- name: this.database.getName(),
1546
+ name: this.database.getUniqueName(),
1481
1547
  scopeName: this.scope.name,
1482
1548
  collectionName: this.name,
1483
1549
  changeListenerToken: token,
@@ -1503,7 +1569,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1503
1569
  document: documentString,
1504
1570
  blobs: blobString,
1505
1571
  concurrencyControl: concurrencyControl,
1506
- name: this.scope.database.getName(),
1572
+ name: this.scope.database.getUniqueName(),
1507
1573
  scopeName: this.scope.name,
1508
1574
  collectionName: this.name,
1509
1575
  });
@@ -1515,7 +1581,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1515
1581
  async setDocumentExpiration(id, expiration) {
1516
1582
  await this._engine.collection_SetDocumentExpiration({
1517
1583
  docId: id,
1518
- name: this.database.getName(),
1584
+ name: this.database.getUniqueName(),
1519
1585
  scopeName: this.scope.name,
1520
1586
  collectionName: this.name,
1521
1587
  expiration: expiration,
@@ -1525,7 +1591,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1525
1591
  return {
1526
1592
  name: this.name,
1527
1593
  scopeName: this.scope.name,
1528
- databaseName: this.database.getName(),
1594
+ databaseName: this.database.getUniqueName(),
1529
1595
  };
1530
1596
  }
1531
1597
  uuid() {
@@ -1638,7 +1704,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1638
1704
  }
1639
1705
  setFileConfig(config) {
1640
1706
  return this.database.getEngine().database_SetFileLoggingConfig({
1641
- name: this.database.getName(),
1707
+ name: this.database.getUniqueName(),
1642
1708
  config: config,
1643
1709
  });
1644
1710
  }
@@ -1748,6 +1814,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1748
1814
  */
1749
1815
  class Query {
1750
1816
  constructor(queryString, database) {
1817
+ this.parameters = new Parameters();
1751
1818
  //used for engine calls
1752
1819
  this._engine = EngineLocator.getEngine(EngineLocator.key);
1753
1820
  this._queryString = queryString;
@@ -1764,9 +1831,9 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1764
1831
  const token = this._engine.getUUID();
1765
1832
  if (!this._didStartQueryListener) {
1766
1833
  await this._engine.query_AddChangeListener({
1767
- name: this._database.getName(),
1834
+ name: this._database.getUniqueName(),
1768
1835
  query: this._queryString,
1769
- parameters: this.parameters,
1836
+ parameters: this.parameters.get(),
1770
1837
  changeListenerToken: token,
1771
1838
  }, (data, err) => {
1772
1839
  if (err) {
@@ -1797,11 +1864,8 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1797
1864
  * @function
1798
1865
  */
1799
1866
  async execute() {
1800
- if (this.parameters === undefined) {
1801
- this.parameters = new Parameters();
1802
- }
1803
1867
  const queryResults = await this._database.getEngine().query_Execute({
1804
- name: this._database.getName(),
1868
+ name: this._database.getUniqueName(),
1805
1869
  query: this._queryString,
1806
1870
  parameters: this.parameters.get(),
1807
1871
  });
@@ -1820,11 +1884,8 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1820
1884
  * @function
1821
1885
  */
1822
1886
  async explain() {
1823
- if (this.parameters === undefined) {
1824
- this.parameters = new Parameters();
1825
- }
1826
1887
  const queryResults = await this._database.getEngine().query_Explain({
1827
- name: this._database.getName(),
1888
+ name: this._database.getUniqueName(),
1828
1889
  query: this._queryString,
1829
1890
  parameters: this.parameters.get(),
1830
1891
  });
@@ -1864,7 +1925,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1864
1925
  async removeChangeListener(token) {
1865
1926
  await this._database.getEngine().query_RemoveChangeListener({
1866
1927
  changeListenerToken: token,
1867
- name: this._database.getName(),
1928
+ name: this._database.getUniqueName(),
1868
1929
  });
1869
1930
  }
1870
1931
  setDatabase(database) {
@@ -1935,9 +1996,12 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1935
1996
  // eslint-disable-next-line
1936
1997
  _databaseName,
1937
1998
  // eslint-disable-next-line
1938
- _databaseConfig = null) {
1999
+ _databaseConfig = null,
2000
+ // eslint-disable-next-line
2001
+ _databaseUniqueName = null) {
1939
2002
  this._databaseName = _databaseName;
1940
2003
  this._databaseConfig = _databaseConfig;
2004
+ this._databaseUniqueName = _databaseUniqueName;
1941
2005
  this._isClosed = false;
1942
2006
  this._engine = EngineLocator.getEngine(EngineLocator.key);
1943
2007
  this.log = new DatabaseLogging(this);
@@ -1947,16 +2011,19 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1947
2011
  }
1948
2012
  /**
1949
2013
  * Open a database with the given name and configuration.
2014
+ * Returns the unique internal name of the database which consists of the provided name and nanoId.
2015
+ * The unique name is used to allow multiple instances of the same database to be opened at the same time.
1950
2016
  *
1951
2017
  * @function
1952
2018
  */
1953
- open() {
1954
- const result = this._engine.database_Open({
2019
+ async open() {
2020
+ const { databaseUniqueName } = await this._engine.database_Open({
1955
2021
  name: this._databaseName,
1956
2022
  config: this._databaseConfig,
1957
2023
  });
2024
+ this._databaseUniqueName = databaseUniqueName;
1958
2025
  this._isClosed = false;
1959
- return result;
2026
+ return databaseUniqueName;
1960
2027
  }
1961
2028
  /**
1962
2029
  * Changes the database’s encryption key, or removes
@@ -1966,7 +2033,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1966
2033
  */
1967
2034
  async changeEncryptionKey(newKey) {
1968
2035
  await this._engine.database_ChangeEncryptionKey({
1969
- name: this._databaseName,
2036
+ name: this._databaseUniqueName,
1970
2037
  newKey: newKey,
1971
2038
  });
1972
2039
  this._databaseConfig.setEncryptionKey(newKey);
@@ -1977,7 +2044,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1977
2044
  * @function
1978
2045
  */
1979
2046
  close() {
1980
- const result = this._engine.database_Close({ name: this._databaseName });
2047
+ const result = this._engine.database_Close({ name: this._databaseUniqueName });
1981
2048
  this._isClosed = true;
1982
2049
  return result;
1983
2050
  }
@@ -1988,7 +2055,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1988
2055
  */
1989
2056
  compact() {
1990
2057
  const args = {
1991
- name: this._databaseName,
2058
+ name: this._databaseUniqueName,
1992
2059
  maintenanceType: exports.MaintenanceType.COMPACT,
1993
2060
  };
1994
2061
  return this._engine.database_PerformMaintenance(args);
@@ -1999,7 +2066,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1999
2066
  * @function
2000
2067
  */
2001
2068
  performMaintenance(maintenanceType) {
2002
- const args = { name: this._databaseName, maintenanceType: maintenanceType };
2069
+ const args = { name: this._databaseUniqueName, maintenanceType: maintenanceType };
2003
2070
  return this._engine.database_PerformMaintenance(args);
2004
2071
  }
2005
2072
  /**
@@ -2009,7 +2076,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2009
2076
  */
2010
2077
  copy(path, name, config) {
2011
2078
  return this._engine.database_Copy({
2012
- name: this._databaseName,
2079
+ name: this._databaseUniqueName,
2013
2080
  path: path,
2014
2081
  newName: name,
2015
2082
  config: config,
@@ -2024,7 +2091,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2024
2091
  if (this._isClosed) {
2025
2092
  throw new Error('Cannot delete a closed database using this API. Open the database first.');
2026
2093
  }
2027
- return this._engine.database_Delete({ name: this._databaseName });
2094
+ return this._engine.database_Delete({ name: this._databaseUniqueName });
2028
2095
  }
2029
2096
  /**
2030
2097
  * Deletes a database.
@@ -2045,7 +2112,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2045
2112
  * @function
2046
2113
  */
2047
2114
  async getPath() {
2048
- return (await this._engine.database_GetPath({ name: this._databaseName }))
2115
+ return (await this._engine.database_GetPath({ name: this._databaseUniqueName }))
2049
2116
  .path;
2050
2117
  }
2051
2118
  /**
@@ -2070,6 +2137,16 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2070
2137
  getName() {
2071
2138
  return this._databaseName;
2072
2139
  }
2140
+ /**
2141
+ * Return the database unique name.
2142
+ * Unique name is generated by adding a nanoId to the database name.
2143
+ * This is used to allow multiple instances of the same database to be opened at the same time.
2144
+ *
2145
+ * @function
2146
+ */
2147
+ getUniqueName() {
2148
+ return this._databaseUniqueName;
2149
+ }
2073
2150
  /**
2074
2151
  * Returns a READONLY config object which will throw a runtime exception when any setter methods are called.
2075
2152
  *
@@ -2115,7 +2192,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2115
2192
  */
2116
2193
  async defaultScope() {
2117
2194
  const scope = await this._engine.scope_GetDefault({
2118
- name: this._databaseName,
2195
+ name: this._databaseUniqueName,
2119
2196
  });
2120
2197
  return new Scope(scope.name, this);
2121
2198
  }
@@ -2127,7 +2204,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2127
2204
  async scope(scopeName) {
2128
2205
  try {
2129
2206
  const scope = await this._engine.scope_GetScope({
2130
- name: this._databaseName,
2207
+ name: this._databaseUniqueName,
2131
2208
  scopeName: scopeName,
2132
2209
  });
2133
2210
  return new Scope(scope.name, this);
@@ -2143,7 +2220,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2143
2220
  */
2144
2221
  async scopes() {
2145
2222
  const results = await this._engine.scope_GetScopes({
2146
- name: this._databaseName,
2223
+ name: this._databaseUniqueName,
2147
2224
  });
2148
2225
  const scopes = [];
2149
2226
  for (const scope of results.scopes) {
@@ -2158,7 +2235,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2158
2235
  */
2159
2236
  async defaultCollection() {
2160
2237
  const col = await this._engine.collection_GetDefault({
2161
- name: this._databaseName,
2238
+ name: this._databaseUniqueName,
2162
2239
  });
2163
2240
  const scope = new Scope(col.scope.name, this);
2164
2241
  return new Collection(col.name, scope, this);
@@ -2168,21 +2245,21 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2168
2245
  let col;
2169
2246
  if (typeof scopeOrName === 'string') {
2170
2247
  col = await this._engine.collection_GetCollection({
2171
- name: this._databaseName,
2248
+ name: this._databaseUniqueName,
2172
2249
  collectionName: collectionName,
2173
2250
  scopeName: scopeOrName,
2174
2251
  });
2175
2252
  }
2176
2253
  else if (scopeOrName instanceof Scope) {
2177
2254
  col = await this._engine.collection_GetCollection({
2178
- name: this._databaseName,
2255
+ name: this._databaseUniqueName,
2179
2256
  collectionName: collectionName,
2180
2257
  scopeName: scopeOrName.name,
2181
2258
  });
2182
2259
  }
2183
2260
  else {
2184
2261
  col = await this._engine.collection_GetCollection({
2185
- name: this._databaseName,
2262
+ name: this._databaseUniqueName,
2186
2263
  collectionName: collectionName,
2187
2264
  scopeName: Database.defaultScopeName,
2188
2265
  });
@@ -2196,19 +2273,19 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2196
2273
  let colResults;
2197
2274
  if (typeof scopeOrName === 'string') {
2198
2275
  colResults = await this._engine.collection_GetCollections({
2199
- name: this._databaseName,
2276
+ name: this._databaseUniqueName,
2200
2277
  scopeName: scopeOrName,
2201
2278
  });
2202
2279
  }
2203
2280
  else if (scopeOrName instanceof Scope) {
2204
2281
  colResults = await this._engine.collection_GetCollections({
2205
- name: this._databaseName,
2282
+ name: this._databaseUniqueName,
2206
2283
  scopeName: scopeOrName.name,
2207
2284
  });
2208
2285
  }
2209
2286
  else {
2210
2287
  colResults = await this._engine.collection_GetCollections({
2211
- name: this._databaseName,
2288
+ name: this._databaseUniqueName,
2212
2289
  scopeName: Database.defaultScopeName,
2213
2290
  });
2214
2291
  }
@@ -2223,21 +2300,21 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2223
2300
  let col;
2224
2301
  if (typeof scopeOrName === 'string') {
2225
2302
  col = await this._engine.collection_CreateCollection({
2226
- name: this._databaseName,
2303
+ name: this._databaseUniqueName,
2227
2304
  collectionName: collectionName,
2228
2305
  scopeName: scopeOrName,
2229
2306
  });
2230
2307
  }
2231
2308
  else if (scopeOrName instanceof Scope) {
2232
2309
  col = await this._engine.collection_CreateCollection({
2233
- name: this._databaseName,
2310
+ name: this._databaseUniqueName,
2234
2311
  collectionName: collectionName,
2235
2312
  scopeName: scopeOrName.name,
2236
2313
  });
2237
2314
  }
2238
2315
  else {
2239
2316
  col = await this._engine.collection_CreateCollection({
2240
- name: this._databaseName,
2317
+ name: this._databaseUniqueName,
2241
2318
  collectionName: collectionName,
2242
2319
  scopeName: Database.defaultScopeName,
2243
2320
  });
@@ -2249,14 +2326,14 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2249
2326
  deleteCollection(collectionOrName, scopeName) {
2250
2327
  if (typeof collectionOrName === 'string' && scopeName !== undefined) {
2251
2328
  return this._engine.collection_DeleteCollection({
2252
- name: this._databaseName,
2329
+ name: this._databaseUniqueName,
2253
2330
  collectionName: collectionOrName,
2254
2331
  scopeName: scopeName,
2255
2332
  });
2256
2333
  }
2257
2334
  else if (collectionOrName instanceof Collection) {
2258
2335
  return this._engine.collection_DeleteCollection({
2259
- name: this._databaseName,
2336
+ name: this._databaseUniqueName,
2260
2337
  collectionName: collectionOrName.name,
2261
2338
  scopeName: collectionOrName.scope.name,
2262
2339
  });
@@ -2273,7 +2350,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2273
2350
  deleteDocument(document, concurrencyControl = null) {
2274
2351
  const id = document.getId();
2275
2352
  return this._engine.database_DeleteDocument({
2276
- name: this._databaseName,
2353
+ name: this._databaseUniqueName,
2277
2354
  docId: id,
2278
2355
  concurrencyControl: concurrencyControl,
2279
2356
  });
@@ -2285,7 +2362,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2285
2362
  */
2286
2363
  purgeDocument(document) {
2287
2364
  return this._engine.database_PurgeDocument({
2288
- name: this._databaseName,
2365
+ name: this._databaseUniqueName,
2289
2366
  docId: document.getId(),
2290
2367
  });
2291
2368
  }
@@ -2296,7 +2373,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2296
2373
  */
2297
2374
  async getCount() {
2298
2375
  const count = await this._engine.database_GetCount({
2299
- name: this._databaseName,
2376
+ name: this._databaseUniqueName,
2300
2377
  });
2301
2378
  return Promise.resolve(count.count);
2302
2379
  }
@@ -2308,7 +2385,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2308
2385
  async getDocument(id) {
2309
2386
  const docJson = await this._engine.collection_GetDocument({
2310
2387
  docId: id,
2311
- name: this._databaseName,
2388
+ name: this._databaseUniqueName,
2312
2389
  scopeName: "_default",
2313
2390
  collectionName: "_default",
2314
2391
  });
@@ -2340,7 +2417,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2340
2417
  document: document.toJsonString(),
2341
2418
  blobs: document.blobsToJsonString(),
2342
2419
  concurrencyControl: concurrencyControl,
2343
- name: this._databaseName,
2420
+ name: this._databaseUniqueName,
2344
2421
  scopeName: "_default",
2345
2422
  collectionName: "_default",
2346
2423
  });
@@ -2355,7 +2432,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2355
2432
  */
2356
2433
  createIndex(indexName, index) {
2357
2434
  return this._engine.database_CreateIndex({
2358
- name: this._databaseName,
2435
+ name: this._databaseUniqueName,
2359
2436
  indexName: indexName,
2360
2437
  index: index.toJson(),
2361
2438
  });
@@ -2367,7 +2444,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2367
2444
  */
2368
2445
  async getIndexes() {
2369
2446
  return (await this._engine.database_GetIndexes({
2370
- name: this._databaseName,
2447
+ name: this._databaseUniqueName,
2371
2448
  })).indexes;
2372
2449
  }
2373
2450
  /**
@@ -2377,7 +2454,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2377
2454
  */
2378
2455
  deleteIndex(indexName) {
2379
2456
  return this._engine.database_DeleteIndex({
2380
- name: this._databaseName,
2457
+ name: this._databaseUniqueName,
2381
2458
  indexName: indexName,
2382
2459
  });
2383
2460
  }
@@ -2441,8 +2518,8 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
2441
2518
  if (object.id === null) {
2442
2519
  throw 'document id cannot be null';
2443
2520
  }
2444
- if (object.error !== null) {
2445
- if (object.error.message === null) {
2521
+ if (object.error) {
2522
+ if (!object.error.message) {
2446
2523
  throw 'document error is incomplete';
2447
2524
  }
2448
2525
  }
@@ -3672,7 +3749,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
3672
3749
  this._engine = EngineLocator.getEngine(EngineLocator.key);
3673
3750
  this._didStartStatusChangeListener = false;
3674
3751
  this._replicatorId = replicatorId;
3675
- this._config = config;
3752
+ this._config = config.clone();
3676
3753
  this._documentChangeListener = new Map();
3677
3754
  }
3678
3755
  /**
@@ -3702,7 +3779,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
3702
3779
  }
3703
3780
  }
3704
3781
  async addDocumentChangeListener(listener) {
3705
- const token = this._engine.getUUID();
3782
+ const token = this._engine.getUUID() + "_doc";
3706
3783
  this._documentChangeListener.set(token, listener);
3707
3784
  await this._engine.replicator_AddDocumentChangeListener({
3708
3785
  replicatorId: this._replicatorId,
@@ -3733,7 +3810,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
3733
3810
  const engine = EngineLocator.getEngine(EngineLocator.key);
3734
3811
  const configJson = config.toJson();
3735
3812
  const ret = await engine.replicator_Create({ config: configJson });
3736
- const replicator = new Replicator(ret.replicatorId, config);
3813
+ const replicator = new Replicator(ret.replicatorId, config.clone());
3737
3814
  return replicator;
3738
3815
  }
3739
3816
  /**
@@ -3789,7 +3866,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
3789
3866
  replicatorId: this._replicatorId,
3790
3867
  collectionName: collection.name,
3791
3868
  scopeName: collection.scope.name,
3792
- name: collection.database.getName(),
3869
+ name: collection.database.getUniqueName(),
3793
3870
  });
3794
3871
  }
3795
3872
  /**
@@ -3807,7 +3884,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
3807
3884
  documentId: documentId,
3808
3885
  collectionName: collection.name,
3809
3886
  scopeName: collection.scope.name,
3810
- name: collection.database.getName(),
3887
+ name: collection.database.getUniqueName(),
3811
3888
  });
3812
3889
  }
3813
3890
  notifyDocumentChange(data, token) {
@@ -3842,6 +3919,9 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
3842
3919
  * @function
3843
3920
  */
3844
3921
  async removeChangeListener(token) {
3922
+ if (this._documentChangeListener.has(token)) {
3923
+ this._documentChangeListener.delete(token);
3924
+ }
3845
3925
  await this._engine.replicator_RemoveChangeListener({
3846
3926
  replicatorId: this._replicatorId,
3847
3927
  changeListenerToken: token,
@@ -3985,6 +4065,114 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
3985
4065
  }
3986
4066
  }
3987
4067
 
4068
+ /**
4069
+ * URLEndpointListener manages the lifecycle of a Couchbase Lite URL Endpoint Listener.
4070
+ * Use the static `create` method to instantiate and configure a listener.
4071
+ *
4072
+ * Example usage:
4073
+ * ```typescript
4074
+ * const listener = await URLEndpointListener.create({
4075
+ * collections: [...],
4076
+ * port: 55990,
4077
+ * networkInterface: '0.0.0.0',
4078
+ * disableTLS: false, // Optional: disables TLS if true
4079
+ * enableDeltaSync: true // Optional: enables delta sync if true
4080
+ * });
4081
+ * await listener.start();
4082
+ * ```
4083
+ *
4084
+ * - If `disableTLS` is not provided, TLS is enabled by default.
4085
+ * - If `enableDeltaSync` is not provided, delta sync is disabled by default.
4086
+ * - Use `listener.stop()` to stop the listener.
4087
+ */
4088
+ class URLEndpointListener {
4089
+ /**
4090
+ * Private constructor. Use the static `create` method to instantiate.
4091
+ */
4092
+ constructor(args, listenerId) {
4093
+ this._engine = EngineLocator.getEngine(EngineLocator.key);
4094
+ this._collections = args.collections;
4095
+ this._port = args.port;
4096
+ this._networkInterface = args.networkInterface;
4097
+ this._disableTLS = args.disableTLS;
4098
+ this._enableDeltaSync = args.enableDeltaSync;
4099
+ this._listenerId = listenerId;
4100
+ this._authenticatorConfig = args.authenticatorConfig;
4101
+ }
4102
+ /**
4103
+ * Asynchronously creates and configures a new URLEndpointListener.
4104
+ * @param args Listener configuration arguments.
4105
+ * @returns A Promise that resolves to a URLEndpointListener instance.
4106
+ */
4107
+ static async create(args) {
4108
+ const engine = EngineLocator.getEngine(EngineLocator.key);
4109
+ const { listenerId } = await engine.URLEndpointListener_createListener(args);
4110
+ return new URLEndpointListener(args, listenerId);
4111
+ }
4112
+ /**
4113
+ * Starts the listener.
4114
+ */
4115
+ async start() {
4116
+ await this._engine.URLEndpointListener_startListener({ listenerId: this._listenerId });
4117
+ }
4118
+ /**
4119
+ * Stops the listener.
4120
+ */
4121
+ async stop() {
4122
+ await this._engine.URLEndpointListener_stopListener({ listenerId: this._listenerId });
4123
+ }
4124
+ /**
4125
+ * Returns the listener ID.
4126
+ */
4127
+ getId() {
4128
+ return this._listenerId;
4129
+ }
4130
+ /**
4131
+ * Returns the collections associated with this listener.
4132
+ */
4133
+ getCollections() {
4134
+ return this._collections;
4135
+ }
4136
+ /**
4137
+ * Returns the port the listener is configured to use.
4138
+ */
4139
+ getPort() {
4140
+ return this._port;
4141
+ }
4142
+ /**
4143
+ * Returns the network interface the listener is bound to, if set.
4144
+ */
4145
+ getNetworkInterface() {
4146
+ return this._networkInterface;
4147
+ }
4148
+ /**
4149
+ * Returns whether TLS is disabled for this listener.
4150
+ */
4151
+ getDisableTLS() {
4152
+ return !!this._disableTLS;
4153
+ }
4154
+ /**
4155
+ * Returns whether delta sync is enabled for this listener.
4156
+ */
4157
+ getEnableDeltaSync() {
4158
+ return !!this._enableDeltaSync;
4159
+ }
4160
+ /**
4161
+ * Gets the current status of the listener from the native engine.
4162
+ * @returns A promise that resolves to the listener status.
4163
+ */
4164
+ async getStatus() {
4165
+ return await this._engine.URLEndpointListener_getStatus({ listenerId: this._listenerId });
4166
+ }
4167
+ /**
4168
+ * Deletes the listener identity from the native engine.
4169
+ * @param args The arguments for deleting the listener identity.
4170
+ */
4171
+ static async deleteIdentity(args) {
4172
+ return await EngineLocator.getEngine(EngineLocator.key).URLEndpointListener_deleteIdentity(args);
4173
+ }
4174
+ }
4175
+
3988
4176
  const IonicCouchbaseLite = core.registerPlugin('CblIonicPlugin');
3989
4177
 
3990
4178
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
@@ -4057,6 +4245,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
4057
4245
  constructor() {
4058
4246
  this._defaultCollectionName = '_default';
4059
4247
  this._defaultScopeName = '_default';
4248
+ this.platform = core.Capacitor.getPlatform();
4060
4249
  EngineLocator.registerEngine(EngineLocator.key, this);
4061
4250
  }
4062
4251
  collection_AddChangeListener(args, cb) {
@@ -4123,7 +4312,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
4123
4312
  return IonicCouchbaseLite.collection_RemoveChangeListener(args);
4124
4313
  }
4125
4314
  async collection_RemoveDocumentChangeListener(args) {
4126
- return IonicCouchbaseLite.collection_RemoveChangeListener(args);
4315
+ return IonicCouchbaseLite.collection_RemoveDocumentChangeListener(args);
4127
4316
  }
4128
4317
  async collection_Save(args) {
4129
4318
  return IonicCouchbaseLite.collection_Save(args);
@@ -4350,6 +4539,22 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
4350
4539
  getUUID() {
4351
4540
  return v4().toString();
4352
4541
  }
4542
+ async URLEndpointListener_createListener(args) {
4543
+ const result = await IonicCouchbaseLite.URLEndpointListener_createListener(args);
4544
+ return { listenerId: result.listenerId };
4545
+ }
4546
+ async URLEndpointListener_startListener(args) {
4547
+ return await IonicCouchbaseLite.URLEndpointListener_startListener(args);
4548
+ }
4549
+ async URLEndpointListener_stopListener(args) {
4550
+ return await IonicCouchbaseLite.URLEndpointListener_stopListener(args);
4551
+ }
4552
+ async URLEndpointListener_getStatus(args) {
4553
+ return await IonicCouchbaseLite.URLEndpointListener_getStatus(args);
4554
+ }
4555
+ async URLEndpointListener_deleteIdentity(args) {
4556
+ return await IonicCouchbaseLite.URLEndpointListener_deleteIdentity(args);
4557
+ }
4353
4558
  }
4354
4559
 
4355
4560
  exports.AbstractIndex = AbstractIndex;
@@ -4400,6 +4605,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
4400
4605
  exports.SessionAuthenticator = SessionAuthenticator;
4401
4606
  exports.SortOrder = SortOrder;
4402
4607
  exports.URLEndpoint = URLEndpoint;
4608
+ exports.URLEndpointListener = URLEndpointListener;
4403
4609
  exports.UnaryExpression = UnaryExpression;
4404
4610
  exports.ValueExpression = ValueExpression;
4405
4611
  exports.ValueIndex = ValueIndex;