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
@@ -47,6 +47,46 @@ class CollectionConfig {
47
47
  setDocumentIDs(documentIds) {
48
48
  this.documentIds = documentIds;
49
49
  }
50
+ /**
51
+ * Set a filter function for push replication. Only documents for which the function returns true will be pushed.
52
+ * Inside filter body document and flag object methods can't be used.
53
+ * @param {ReplicationFilter} filter - Function that returns true to replicate the document
54
+ * @example
55
+ * const config = new CollectionConfig();
56
+ * config.setPushFilter((doc, flags) => {
57
+ * return doc["type"] === 'user' && !flags.includes(ReplicatedDocumentFlag.DELETED);
58
+ * });
59
+ */
60
+ setPushFilter(filter) {
61
+ // Convert function to string for bridge transport
62
+ this.pushFilter = filter.toString();
63
+ }
64
+ /**
65
+ * Set a filter function for pull replication. Only documents for which the function returns true will be pulled.
66
+ * Inside filter body document and flag object methods can't be used.
67
+ * @param {ReplicationFilter} filter - Function that returns true to replicate the document
68
+ * @example
69
+ * const config = new CollectionConfig();
70
+ * config.setPullFilter((doc, flags) => {
71
+ * return doc["type"] === 'user' && !flags.includes(ReplicatedDocumentFlag.DELETED);
72
+ * });
73
+ */
74
+ setPullFilter(filter) {
75
+ // Convert function to string for bridge transport
76
+ this.pullFilter = filter.toString();
77
+ }
78
+ /**
79
+ * Get the pull filter function string
80
+ */
81
+ getPushFilter() {
82
+ return this.pushFilter;
83
+ }
84
+ /**
85
+ * Get the pull filter function string
86
+ */
87
+ getPullFilter() {
88
+ return this.pullFilter;
89
+ }
50
90
  }
51
91
 
52
92
  exports.ReplicatorType = void 0;
@@ -77,7 +117,13 @@ class ReplicatorConfiguration {
77
117
  this.headers = undefined;
78
118
  this.pinnedServerCertificate = undefined;
79
119
  }
80
- // eslint-disable-next-line no-dupe-class-members
120
+ /**
121
+ * Add a collection used for the replication with an optional collection configuration. If the collection has
122
+ * 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.
123
+ *
124
+ * @function
125
+ */
126
+ // eslint-disable-next-line
81
127
  addCollection(collection, config) {
82
128
  const cols = [];
83
129
  cols.push(collection);
@@ -456,6 +502,26 @@ class ReplicatorConfiguration {
456
502
  setReplicatorType(replicatorType) {
457
503
  this.replicatorType = replicatorType;
458
504
  }
505
+ clone() {
506
+ const clonedConfig = new ReplicatorConfiguration(this.target);
507
+ // Copy primitive and object properties
508
+ clonedConfig.setContinuous(this.getContinuous());
509
+ clonedConfig.setHeaders({ ...this.getHeaders() }); // Deep copy headers
510
+ clonedConfig.setAuthenticator(this.getAuthenticator());
511
+ clonedConfig.setPinnedServerCertificate(this.getPinnedServerCertificate());
512
+ clonedConfig.setAllowReplicatingInBackground(this.getAllowReplicatingInBackground());
513
+ clonedConfig.setAutoPurgeEnabled(this.getAutoPurgeEnabled());
514
+ clonedConfig.setAcceptParentDomainCookies(this.getAcceptParentDomainCookies());
515
+ clonedConfig.setMaxAttempts(this.getMaxAttempts());
516
+ clonedConfig.setMaxAttemptWaitTime(this.getMaxAttemptWaitTime());
517
+ clonedConfig.setHeartbeat(this.getHeartbeat());
518
+ clonedConfig.setReplicatorType(this.getReplicatorType());
519
+ // Clone collections
520
+ for (const [collections, config] of this.collections) {
521
+ clonedConfig.addCollections([...collections], config);
522
+ }
523
+ return clonedConfig;
524
+ }
459
525
  toJson() {
460
526
  const config = {
461
527
  acceptParentDomainCookies: this.acceptParentDomainCookies,
@@ -530,10 +596,10 @@ class ReplicatorConfiguration {
530
596
  for (const [collections, _] of this.collections) {
531
597
  for (const collection of collections) {
532
598
  if (databaseName === null && scopeName === null) {
533
- databaseName = collection.database.getName();
599
+ databaseName = collection.database.getUniqueName();
534
600
  scopeName = collection.scope.name;
535
601
  }
536
- else if (collection.database.getName() !== databaseName ||
602
+ else if (collection.database.getUniqueName() !== databaseName ||
537
603
  collection.scope.name !== scopeName) {
538
604
  return false;
539
605
  }
@@ -834,7 +900,7 @@ class Scope {
834
900
  */
835
901
  async collections() {
836
902
  const results = await this._engine.collection_GetCollections({
837
- name: this.database.getName(),
903
+ name: this.database.getUniqueName(),
838
904
  scopeName: this.name,
839
905
  });
840
906
  return results.collections;
@@ -847,7 +913,7 @@ class Scope {
847
913
  */
848
914
  async collection(collectionName) {
849
915
  return this._engine.collection_GetCollection({
850
- name: this.database.getName(),
916
+ name: this.database.getUniqueName(),
851
917
  collectionName: collectionName,
852
918
  scopeName: this.name,
853
919
  });
@@ -911,16 +977,18 @@ class Document {
911
977
  return null;
912
978
  }
913
979
  /**
914
- * Returns metadata associated with the Blob. Use getBlobContent() to get the Blob’s data.
980
+ * Returns the Blob associated with the given key, including its content.
981
+ * Returns null if the property doesn’t exist, or its value is not a blob.
915
982
  * Throws an error if the collection is deleted or the database is closed.
916
983
  *
917
984
  * @function
918
985
  */
919
- getBlob(key) {
986
+ async getBlob(key) {
920
987
  if (key in this.doc) {
921
988
  const data = this._get(key);
922
989
  if (data && typeof data === 'object' && 'content_type' in data) {
923
- const b = new Blob(data.content_type, data.raw);
990
+ const blobContent = await this.getBlobContent(key);
991
+ const b = new Blob(data.content_type, blobContent);
924
992
  b.digest = data.digest;
925
993
  b.length = data.length;
926
994
  return b;
@@ -929,8 +997,6 @@ class Document {
929
997
  return null;
930
998
  }
931
999
  /**
932
- * @deprecated - use the Blob API getBytes() function instead
933
- *
934
1000
  * Get a property’s value as a ArrayBuffer. Returns null if the property doesn’t exist,
935
1001
  * or its value is not a blob.
936
1002
  *
@@ -944,7 +1010,7 @@ class Document {
944
1010
  key: key,
945
1011
  collectionName: this.collection.name,
946
1012
  scopeName: this.collection.scope.name,
947
- name: this.collection.scope.database.getName(),
1013
+ name: this.collection.scope.database.getUniqueName(),
948
1014
  });
949
1015
  return data.data;
950
1016
  }
@@ -1212,7 +1278,7 @@ class Collection {
1212
1278
  const token = this.uuid();
1213
1279
  if (!this._didStartListener) {
1214
1280
  await this._engine.collection_AddChangeListener({
1215
- name: this.scope.database.getName(),
1281
+ name: this.scope.database.getUniqueName(),
1216
1282
  scopeName: this.scope.name,
1217
1283
  collectionName: this.name,
1218
1284
  changeListenerToken: token,
@@ -1239,7 +1305,7 @@ class Collection {
1239
1305
  if (!this._didStartDocumentListener.has(documentId) &&
1240
1306
  !this._documentChangeListener[documentId]) {
1241
1307
  await this._engine.collection_AddDocumentChangeListener({
1242
- name: this.scope.database.getName(),
1308
+ name: this.scope.database.getUniqueName(),
1243
1309
  scopeName: this.scope.name,
1244
1310
  collectionName: this.name,
1245
1311
  changeListenerToken: token,
@@ -1265,7 +1331,7 @@ class Collection {
1265
1331
  */
1266
1332
  count() {
1267
1333
  return this._engine.collection_GetCount({
1268
- name: this.scope.database.getName(),
1334
+ name: this.scope.database.getUniqueName(),
1269
1335
  scopeName: this.scope.name,
1270
1336
  collectionName: this.name,
1271
1337
  });
@@ -1277,7 +1343,7 @@ class Collection {
1277
1343
  */
1278
1344
  createIndex(indexName, index) {
1279
1345
  return this._engine.collection_CreateIndex({
1280
- name: this.scope.database.getName(),
1346
+ name: this.scope.database.getUniqueName(),
1281
1347
  scopeName: this.scope.name,
1282
1348
  collectionName: this.name,
1283
1349
  indexName: indexName,
@@ -1300,7 +1366,7 @@ class Collection {
1300
1366
  deleteDocument(document, concurrencyControl = null) {
1301
1367
  const id = document.getId();
1302
1368
  return this._engine.collection_DeleteDocument({
1303
- name: this.scope.database.getName(),
1369
+ name: this.scope.database.getUniqueName(),
1304
1370
  scopeName: this.scope.name,
1305
1371
  collectionName: this.name,
1306
1372
  docId: id,
@@ -1314,7 +1380,7 @@ class Collection {
1314
1380
  */
1315
1381
  deleteIndex(indexName) {
1316
1382
  return this._engine.collection_DeleteIndex({
1317
- name: this.scope.database.getName(),
1383
+ name: this.scope.database.getUniqueName(),
1318
1384
  scopeName: this.scope.name,
1319
1385
  collectionName: this.name,
1320
1386
  indexName: indexName,
@@ -1330,7 +1396,7 @@ class Collection {
1330
1396
  async document(id) {
1331
1397
  const docJson = await this._engine.collection_GetDocument({
1332
1398
  docId: id,
1333
- name: this.scope.database.getName(),
1399
+ name: this.scope.database.getUniqueName(),
1334
1400
  scopeName: this.scope.name,
1335
1401
  collectionName: this.name,
1336
1402
  });
@@ -1370,11 +1436,11 @@ class Collection {
1370
1436
  async getDocumentExpiration(id) {
1371
1437
  const date = await this._engine.collection_GetDocumentExpiration({
1372
1438
  docId: id,
1373
- name: this.scope.database.getName(),
1439
+ name: this.scope.database.getUniqueName(),
1374
1440
  scopeName: this.scope.name,
1375
1441
  collectionName: this.name,
1376
1442
  });
1377
- if (date !== null && date.date !== null) {
1443
+ if (!!date && date?.date) {
1378
1444
  return date.date;
1379
1445
  }
1380
1446
  else {
@@ -1396,7 +1462,7 @@ class Collection {
1396
1462
  */
1397
1463
  async indexes() {
1398
1464
  const indexes = await this._engine.collection_GetIndexes({
1399
- name: this.scope.database.getName(),
1465
+ name: this.scope.database.getUniqueName(),
1400
1466
  scopeName: this.scope.name,
1401
1467
  collectionName: this.name,
1402
1468
  });
@@ -1434,7 +1500,7 @@ class Collection {
1434
1500
  */
1435
1501
  purge(document) {
1436
1502
  return this._engine.collection_PurgeDocument({
1437
- name: this.database.getName(),
1503
+ name: this.database.getUniqueName(),
1438
1504
  scopeName: this.scope.name,
1439
1505
  collectionName: this.name,
1440
1506
  docId: document.getId(),
@@ -1450,7 +1516,7 @@ class Collection {
1450
1516
  */
1451
1517
  purgeById(documentId) {
1452
1518
  return this._engine.collection_PurgeDocument({
1453
- name: this.database.getName(),
1519
+ name: this.database.getUniqueName(),
1454
1520
  scopeName: this.scope.name,
1455
1521
  collectionName: this.name,
1456
1522
  docId: documentId,
@@ -1465,7 +1531,7 @@ class Collection {
1465
1531
  */
1466
1532
  async removeChangeListener(token) {
1467
1533
  await this._engine.collection_RemoveChangeListener({
1468
- name: this.database.getName(),
1534
+ name: this.database.getUniqueName(),
1469
1535
  scopeName: this.scope.name,
1470
1536
  collectionName: this.name,
1471
1537
  changeListenerToken: token,
@@ -1480,7 +1546,7 @@ class Collection {
1480
1546
  */
1481
1547
  async removeDocumentChangeListener(token) {
1482
1548
  await this._engine.collection_RemoveDocumentChangeListener({
1483
- name: this.database.getName(),
1549
+ name: this.database.getUniqueName(),
1484
1550
  scopeName: this.scope.name,
1485
1551
  collectionName: this.name,
1486
1552
  changeListenerToken: token,
@@ -1506,7 +1572,7 @@ class Collection {
1506
1572
  document: documentString,
1507
1573
  blobs: blobString,
1508
1574
  concurrencyControl: concurrencyControl,
1509
- name: this.scope.database.getName(),
1575
+ name: this.scope.database.getUniqueName(),
1510
1576
  scopeName: this.scope.name,
1511
1577
  collectionName: this.name,
1512
1578
  });
@@ -1518,7 +1584,7 @@ class Collection {
1518
1584
  async setDocumentExpiration(id, expiration) {
1519
1585
  await this._engine.collection_SetDocumentExpiration({
1520
1586
  docId: id,
1521
- name: this.database.getName(),
1587
+ name: this.database.getUniqueName(),
1522
1588
  scopeName: this.scope.name,
1523
1589
  collectionName: this.name,
1524
1590
  expiration: expiration,
@@ -1528,7 +1594,7 @@ class Collection {
1528
1594
  return {
1529
1595
  name: this.name,
1530
1596
  scopeName: this.scope.name,
1531
- databaseName: this.database.getName(),
1597
+ databaseName: this.database.getUniqueName(),
1532
1598
  };
1533
1599
  }
1534
1600
  uuid() {
@@ -1641,7 +1707,7 @@ class DatabaseLogging {
1641
1707
  }
1642
1708
  setFileConfig(config) {
1643
1709
  return this.database.getEngine().database_SetFileLoggingConfig({
1644
- name: this.database.getName(),
1710
+ name: this.database.getUniqueName(),
1645
1711
  config: config,
1646
1712
  });
1647
1713
  }
@@ -1751,6 +1817,7 @@ class Parameters {
1751
1817
  */
1752
1818
  class Query {
1753
1819
  constructor(queryString, database) {
1820
+ this.parameters = new Parameters();
1754
1821
  //used for engine calls
1755
1822
  this._engine = EngineLocator.getEngine(EngineLocator.key);
1756
1823
  this._queryString = queryString;
@@ -1767,9 +1834,9 @@ class Query {
1767
1834
  const token = this._engine.getUUID();
1768
1835
  if (!this._didStartQueryListener) {
1769
1836
  await this._engine.query_AddChangeListener({
1770
- name: this._database.getName(),
1837
+ name: this._database.getUniqueName(),
1771
1838
  query: this._queryString,
1772
- parameters: this.parameters,
1839
+ parameters: this.parameters.get(),
1773
1840
  changeListenerToken: token,
1774
1841
  }, (data, err) => {
1775
1842
  if (err) {
@@ -1800,11 +1867,8 @@ class Query {
1800
1867
  * @function
1801
1868
  */
1802
1869
  async execute() {
1803
- if (this.parameters === undefined) {
1804
- this.parameters = new Parameters();
1805
- }
1806
1870
  const queryResults = await this._database.getEngine().query_Execute({
1807
- name: this._database.getName(),
1871
+ name: this._database.getUniqueName(),
1808
1872
  query: this._queryString,
1809
1873
  parameters: this.parameters.get(),
1810
1874
  });
@@ -1823,11 +1887,8 @@ class Query {
1823
1887
  * @function
1824
1888
  */
1825
1889
  async explain() {
1826
- if (this.parameters === undefined) {
1827
- this.parameters = new Parameters();
1828
- }
1829
1890
  const queryResults = await this._database.getEngine().query_Explain({
1830
- name: this._database.getName(),
1891
+ name: this._database.getUniqueName(),
1831
1892
  query: this._queryString,
1832
1893
  parameters: this.parameters.get(),
1833
1894
  });
@@ -1867,7 +1928,7 @@ class Query {
1867
1928
  async removeChangeListener(token) {
1868
1929
  await this._database.getEngine().query_RemoveChangeListener({
1869
1930
  changeListenerToken: token,
1870
- name: this._database.getName(),
1931
+ name: this._database.getUniqueName(),
1871
1932
  });
1872
1933
  }
1873
1934
  setDatabase(database) {
@@ -1938,9 +1999,12 @@ class Database {
1938
1999
  // eslint-disable-next-line
1939
2000
  _databaseName,
1940
2001
  // eslint-disable-next-line
1941
- _databaseConfig = null) {
2002
+ _databaseConfig = null,
2003
+ // eslint-disable-next-line
2004
+ _databaseUniqueName = null) {
1942
2005
  this._databaseName = _databaseName;
1943
2006
  this._databaseConfig = _databaseConfig;
2007
+ this._databaseUniqueName = _databaseUniqueName;
1944
2008
  this._isClosed = false;
1945
2009
  this._engine = EngineLocator.getEngine(EngineLocator.key);
1946
2010
  this.log = new DatabaseLogging(this);
@@ -1950,16 +2014,19 @@ class Database {
1950
2014
  }
1951
2015
  /**
1952
2016
  * Open a database with the given name and configuration.
2017
+ * Returns the unique internal name of the database which consists of the provided name and nanoId.
2018
+ * The unique name is used to allow multiple instances of the same database to be opened at the same time.
1953
2019
  *
1954
2020
  * @function
1955
2021
  */
1956
- open() {
1957
- const result = this._engine.database_Open({
2022
+ async open() {
2023
+ const { databaseUniqueName } = await this._engine.database_Open({
1958
2024
  name: this._databaseName,
1959
2025
  config: this._databaseConfig,
1960
2026
  });
2027
+ this._databaseUniqueName = databaseUniqueName;
1961
2028
  this._isClosed = false;
1962
- return result;
2029
+ return databaseUniqueName;
1963
2030
  }
1964
2031
  /**
1965
2032
  * Changes the database’s encryption key, or removes
@@ -1969,7 +2036,7 @@ class Database {
1969
2036
  */
1970
2037
  async changeEncryptionKey(newKey) {
1971
2038
  await this._engine.database_ChangeEncryptionKey({
1972
- name: this._databaseName,
2039
+ name: this._databaseUniqueName,
1973
2040
  newKey: newKey,
1974
2041
  });
1975
2042
  this._databaseConfig.setEncryptionKey(newKey);
@@ -1980,7 +2047,7 @@ class Database {
1980
2047
  * @function
1981
2048
  */
1982
2049
  close() {
1983
- const result = this._engine.database_Close({ name: this._databaseName });
2050
+ const result = this._engine.database_Close({ name: this._databaseUniqueName });
1984
2051
  this._isClosed = true;
1985
2052
  return result;
1986
2053
  }
@@ -1991,7 +2058,7 @@ class Database {
1991
2058
  */
1992
2059
  compact() {
1993
2060
  const args = {
1994
- name: this._databaseName,
2061
+ name: this._databaseUniqueName,
1995
2062
  maintenanceType: exports.MaintenanceType.COMPACT,
1996
2063
  };
1997
2064
  return this._engine.database_PerformMaintenance(args);
@@ -2002,7 +2069,7 @@ class Database {
2002
2069
  * @function
2003
2070
  */
2004
2071
  performMaintenance(maintenanceType) {
2005
- const args = { name: this._databaseName, maintenanceType: maintenanceType };
2072
+ const args = { name: this._databaseUniqueName, maintenanceType: maintenanceType };
2006
2073
  return this._engine.database_PerformMaintenance(args);
2007
2074
  }
2008
2075
  /**
@@ -2012,7 +2079,7 @@ class Database {
2012
2079
  */
2013
2080
  copy(path, name, config) {
2014
2081
  return this._engine.database_Copy({
2015
- name: this._databaseName,
2082
+ name: this._databaseUniqueName,
2016
2083
  path: path,
2017
2084
  newName: name,
2018
2085
  config: config,
@@ -2027,7 +2094,7 @@ class Database {
2027
2094
  if (this._isClosed) {
2028
2095
  throw new Error('Cannot delete a closed database using this API. Open the database first.');
2029
2096
  }
2030
- return this._engine.database_Delete({ name: this._databaseName });
2097
+ return this._engine.database_Delete({ name: this._databaseUniqueName });
2031
2098
  }
2032
2099
  /**
2033
2100
  * Deletes a database.
@@ -2048,7 +2115,7 @@ class Database {
2048
2115
  * @function
2049
2116
  */
2050
2117
  async getPath() {
2051
- return (await this._engine.database_GetPath({ name: this._databaseName }))
2118
+ return (await this._engine.database_GetPath({ name: this._databaseUniqueName }))
2052
2119
  .path;
2053
2120
  }
2054
2121
  /**
@@ -2073,6 +2140,16 @@ class Database {
2073
2140
  getName() {
2074
2141
  return this._databaseName;
2075
2142
  }
2143
+ /**
2144
+ * Return the database unique name.
2145
+ * Unique name is generated by adding a nanoId to the database name.
2146
+ * This is used to allow multiple instances of the same database to be opened at the same time.
2147
+ *
2148
+ * @function
2149
+ */
2150
+ getUniqueName() {
2151
+ return this._databaseUniqueName;
2152
+ }
2076
2153
  /**
2077
2154
  * Returns a READONLY config object which will throw a runtime exception when any setter methods are called.
2078
2155
  *
@@ -2118,7 +2195,7 @@ class Database {
2118
2195
  */
2119
2196
  async defaultScope() {
2120
2197
  const scope = await this._engine.scope_GetDefault({
2121
- name: this._databaseName,
2198
+ name: this._databaseUniqueName,
2122
2199
  });
2123
2200
  return new Scope(scope.name, this);
2124
2201
  }
@@ -2130,7 +2207,7 @@ class Database {
2130
2207
  async scope(scopeName) {
2131
2208
  try {
2132
2209
  const scope = await this._engine.scope_GetScope({
2133
- name: this._databaseName,
2210
+ name: this._databaseUniqueName,
2134
2211
  scopeName: scopeName,
2135
2212
  });
2136
2213
  return new Scope(scope.name, this);
@@ -2146,7 +2223,7 @@ class Database {
2146
2223
  */
2147
2224
  async scopes() {
2148
2225
  const results = await this._engine.scope_GetScopes({
2149
- name: this._databaseName,
2226
+ name: this._databaseUniqueName,
2150
2227
  });
2151
2228
  const scopes = [];
2152
2229
  for (const scope of results.scopes) {
@@ -2161,7 +2238,7 @@ class Database {
2161
2238
  */
2162
2239
  async defaultCollection() {
2163
2240
  const col = await this._engine.collection_GetDefault({
2164
- name: this._databaseName,
2241
+ name: this._databaseUniqueName,
2165
2242
  });
2166
2243
  const scope = new Scope(col.scope.name, this);
2167
2244
  return new Collection(col.name, scope, this);
@@ -2171,21 +2248,21 @@ class Database {
2171
2248
  let col;
2172
2249
  if (typeof scopeOrName === 'string') {
2173
2250
  col = await this._engine.collection_GetCollection({
2174
- name: this._databaseName,
2251
+ name: this._databaseUniqueName,
2175
2252
  collectionName: collectionName,
2176
2253
  scopeName: scopeOrName,
2177
2254
  });
2178
2255
  }
2179
2256
  else if (scopeOrName instanceof Scope) {
2180
2257
  col = await this._engine.collection_GetCollection({
2181
- name: this._databaseName,
2258
+ name: this._databaseUniqueName,
2182
2259
  collectionName: collectionName,
2183
2260
  scopeName: scopeOrName.name,
2184
2261
  });
2185
2262
  }
2186
2263
  else {
2187
2264
  col = await this._engine.collection_GetCollection({
2188
- name: this._databaseName,
2265
+ name: this._databaseUniqueName,
2189
2266
  collectionName: collectionName,
2190
2267
  scopeName: Database.defaultScopeName,
2191
2268
  });
@@ -2199,19 +2276,19 @@ class Database {
2199
2276
  let colResults;
2200
2277
  if (typeof scopeOrName === 'string') {
2201
2278
  colResults = await this._engine.collection_GetCollections({
2202
- name: this._databaseName,
2279
+ name: this._databaseUniqueName,
2203
2280
  scopeName: scopeOrName,
2204
2281
  });
2205
2282
  }
2206
2283
  else if (scopeOrName instanceof Scope) {
2207
2284
  colResults = await this._engine.collection_GetCollections({
2208
- name: this._databaseName,
2285
+ name: this._databaseUniqueName,
2209
2286
  scopeName: scopeOrName.name,
2210
2287
  });
2211
2288
  }
2212
2289
  else {
2213
2290
  colResults = await this._engine.collection_GetCollections({
2214
- name: this._databaseName,
2291
+ name: this._databaseUniqueName,
2215
2292
  scopeName: Database.defaultScopeName,
2216
2293
  });
2217
2294
  }
@@ -2226,21 +2303,21 @@ class Database {
2226
2303
  let col;
2227
2304
  if (typeof scopeOrName === 'string') {
2228
2305
  col = await this._engine.collection_CreateCollection({
2229
- name: this._databaseName,
2306
+ name: this._databaseUniqueName,
2230
2307
  collectionName: collectionName,
2231
2308
  scopeName: scopeOrName,
2232
2309
  });
2233
2310
  }
2234
2311
  else if (scopeOrName instanceof Scope) {
2235
2312
  col = await this._engine.collection_CreateCollection({
2236
- name: this._databaseName,
2313
+ name: this._databaseUniqueName,
2237
2314
  collectionName: collectionName,
2238
2315
  scopeName: scopeOrName.name,
2239
2316
  });
2240
2317
  }
2241
2318
  else {
2242
2319
  col = await this._engine.collection_CreateCollection({
2243
- name: this._databaseName,
2320
+ name: this._databaseUniqueName,
2244
2321
  collectionName: collectionName,
2245
2322
  scopeName: Database.defaultScopeName,
2246
2323
  });
@@ -2252,14 +2329,14 @@ class Database {
2252
2329
  deleteCollection(collectionOrName, scopeName) {
2253
2330
  if (typeof collectionOrName === 'string' && scopeName !== undefined) {
2254
2331
  return this._engine.collection_DeleteCollection({
2255
- name: this._databaseName,
2332
+ name: this._databaseUniqueName,
2256
2333
  collectionName: collectionOrName,
2257
2334
  scopeName: scopeName,
2258
2335
  });
2259
2336
  }
2260
2337
  else if (collectionOrName instanceof Collection) {
2261
2338
  return this._engine.collection_DeleteCollection({
2262
- name: this._databaseName,
2339
+ name: this._databaseUniqueName,
2263
2340
  collectionName: collectionOrName.name,
2264
2341
  scopeName: collectionOrName.scope.name,
2265
2342
  });
@@ -2276,7 +2353,7 @@ class Database {
2276
2353
  deleteDocument(document, concurrencyControl = null) {
2277
2354
  const id = document.getId();
2278
2355
  return this._engine.database_DeleteDocument({
2279
- name: this._databaseName,
2356
+ name: this._databaseUniqueName,
2280
2357
  docId: id,
2281
2358
  concurrencyControl: concurrencyControl,
2282
2359
  });
@@ -2288,7 +2365,7 @@ class Database {
2288
2365
  */
2289
2366
  purgeDocument(document) {
2290
2367
  return this._engine.database_PurgeDocument({
2291
- name: this._databaseName,
2368
+ name: this._databaseUniqueName,
2292
2369
  docId: document.getId(),
2293
2370
  });
2294
2371
  }
@@ -2299,7 +2376,7 @@ class Database {
2299
2376
  */
2300
2377
  async getCount() {
2301
2378
  const count = await this._engine.database_GetCount({
2302
- name: this._databaseName,
2379
+ name: this._databaseUniqueName,
2303
2380
  });
2304
2381
  return Promise.resolve(count.count);
2305
2382
  }
@@ -2311,7 +2388,7 @@ class Database {
2311
2388
  async getDocument(id) {
2312
2389
  const docJson = await this._engine.collection_GetDocument({
2313
2390
  docId: id,
2314
- name: this._databaseName,
2391
+ name: this._databaseUniqueName,
2315
2392
  scopeName: "_default",
2316
2393
  collectionName: "_default",
2317
2394
  });
@@ -2343,7 +2420,7 @@ class Database {
2343
2420
  document: document.toJsonString(),
2344
2421
  blobs: document.blobsToJsonString(),
2345
2422
  concurrencyControl: concurrencyControl,
2346
- name: this._databaseName,
2423
+ name: this._databaseUniqueName,
2347
2424
  scopeName: "_default",
2348
2425
  collectionName: "_default",
2349
2426
  });
@@ -2358,7 +2435,7 @@ class Database {
2358
2435
  */
2359
2436
  createIndex(indexName, index) {
2360
2437
  return this._engine.database_CreateIndex({
2361
- name: this._databaseName,
2438
+ name: this._databaseUniqueName,
2362
2439
  indexName: indexName,
2363
2440
  index: index.toJson(),
2364
2441
  });
@@ -2370,7 +2447,7 @@ class Database {
2370
2447
  */
2371
2448
  async getIndexes() {
2372
2449
  return (await this._engine.database_GetIndexes({
2373
- name: this._databaseName,
2450
+ name: this._databaseUniqueName,
2374
2451
  })).indexes;
2375
2452
  }
2376
2453
  /**
@@ -2380,7 +2457,7 @@ class Database {
2380
2457
  */
2381
2458
  deleteIndex(indexName) {
2382
2459
  return this._engine.database_DeleteIndex({
2383
- name: this._databaseName,
2460
+ name: this._databaseUniqueName,
2384
2461
  indexName: indexName,
2385
2462
  });
2386
2463
  }
@@ -2444,8 +2521,8 @@ function isReplicatedDocumentRepresentation(obj) {
2444
2521
  if (object.id === null) {
2445
2522
  throw 'document id cannot be null';
2446
2523
  }
2447
- if (object.error !== null) {
2448
- if (object.error.message === null) {
2524
+ if (object.error) {
2525
+ if (!object.error.message) {
2449
2526
  throw 'document error is incomplete';
2450
2527
  }
2451
2528
  }
@@ -3675,7 +3752,7 @@ class Replicator {
3675
3752
  this._engine = EngineLocator.getEngine(EngineLocator.key);
3676
3753
  this._didStartStatusChangeListener = false;
3677
3754
  this._replicatorId = replicatorId;
3678
- this._config = config;
3755
+ this._config = config.clone();
3679
3756
  this._documentChangeListener = new Map();
3680
3757
  }
3681
3758
  /**
@@ -3705,7 +3782,7 @@ class Replicator {
3705
3782
  }
3706
3783
  }
3707
3784
  async addDocumentChangeListener(listener) {
3708
- const token = this._engine.getUUID();
3785
+ const token = this._engine.getUUID() + "_doc";
3709
3786
  this._documentChangeListener.set(token, listener);
3710
3787
  await this._engine.replicator_AddDocumentChangeListener({
3711
3788
  replicatorId: this._replicatorId,
@@ -3736,7 +3813,7 @@ class Replicator {
3736
3813
  const engine = EngineLocator.getEngine(EngineLocator.key);
3737
3814
  const configJson = config.toJson();
3738
3815
  const ret = await engine.replicator_Create({ config: configJson });
3739
- const replicator = new Replicator(ret.replicatorId, config);
3816
+ const replicator = new Replicator(ret.replicatorId, config.clone());
3740
3817
  return replicator;
3741
3818
  }
3742
3819
  /**
@@ -3792,7 +3869,7 @@ class Replicator {
3792
3869
  replicatorId: this._replicatorId,
3793
3870
  collectionName: collection.name,
3794
3871
  scopeName: collection.scope.name,
3795
- name: collection.database.getName(),
3872
+ name: collection.database.getUniqueName(),
3796
3873
  });
3797
3874
  }
3798
3875
  /**
@@ -3810,7 +3887,7 @@ class Replicator {
3810
3887
  documentId: documentId,
3811
3888
  collectionName: collection.name,
3812
3889
  scopeName: collection.scope.name,
3813
- name: collection.database.getName(),
3890
+ name: collection.database.getUniqueName(),
3814
3891
  });
3815
3892
  }
3816
3893
  notifyDocumentChange(data, token) {
@@ -3845,6 +3922,9 @@ class Replicator {
3845
3922
  * @function
3846
3923
  */
3847
3924
  async removeChangeListener(token) {
3925
+ if (this._documentChangeListener.has(token)) {
3926
+ this._documentChangeListener.delete(token);
3927
+ }
3848
3928
  await this._engine.replicator_RemoveChangeListener({
3849
3929
  replicatorId: this._replicatorId,
3850
3930
  changeListenerToken: token,
@@ -3988,6 +4068,114 @@ class VariableExpression extends Expression {
3988
4068
  }
3989
4069
  }
3990
4070
 
4071
+ /**
4072
+ * URLEndpointListener manages the lifecycle of a Couchbase Lite URL Endpoint Listener.
4073
+ * Use the static `create` method to instantiate and configure a listener.
4074
+ *
4075
+ * Example usage:
4076
+ * ```typescript
4077
+ * const listener = await URLEndpointListener.create({
4078
+ * collections: [...],
4079
+ * port: 55990,
4080
+ * networkInterface: '0.0.0.0',
4081
+ * disableTLS: false, // Optional: disables TLS if true
4082
+ * enableDeltaSync: true // Optional: enables delta sync if true
4083
+ * });
4084
+ * await listener.start();
4085
+ * ```
4086
+ *
4087
+ * - If `disableTLS` is not provided, TLS is enabled by default.
4088
+ * - If `enableDeltaSync` is not provided, delta sync is disabled by default.
4089
+ * - Use `listener.stop()` to stop the listener.
4090
+ */
4091
+ class URLEndpointListener {
4092
+ /**
4093
+ * Private constructor. Use the static `create` method to instantiate.
4094
+ */
4095
+ constructor(args, listenerId) {
4096
+ this._engine = EngineLocator.getEngine(EngineLocator.key);
4097
+ this._collections = args.collections;
4098
+ this._port = args.port;
4099
+ this._networkInterface = args.networkInterface;
4100
+ this._disableTLS = args.disableTLS;
4101
+ this._enableDeltaSync = args.enableDeltaSync;
4102
+ this._listenerId = listenerId;
4103
+ this._authenticatorConfig = args.authenticatorConfig;
4104
+ }
4105
+ /**
4106
+ * Asynchronously creates and configures a new URLEndpointListener.
4107
+ * @param args Listener configuration arguments.
4108
+ * @returns A Promise that resolves to a URLEndpointListener instance.
4109
+ */
4110
+ static async create(args) {
4111
+ const engine = EngineLocator.getEngine(EngineLocator.key);
4112
+ const { listenerId } = await engine.URLEndpointListener_createListener(args);
4113
+ return new URLEndpointListener(args, listenerId);
4114
+ }
4115
+ /**
4116
+ * Starts the listener.
4117
+ */
4118
+ async start() {
4119
+ await this._engine.URLEndpointListener_startListener({ listenerId: this._listenerId });
4120
+ }
4121
+ /**
4122
+ * Stops the listener.
4123
+ */
4124
+ async stop() {
4125
+ await this._engine.URLEndpointListener_stopListener({ listenerId: this._listenerId });
4126
+ }
4127
+ /**
4128
+ * Returns the listener ID.
4129
+ */
4130
+ getId() {
4131
+ return this._listenerId;
4132
+ }
4133
+ /**
4134
+ * Returns the collections associated with this listener.
4135
+ */
4136
+ getCollections() {
4137
+ return this._collections;
4138
+ }
4139
+ /**
4140
+ * Returns the port the listener is configured to use.
4141
+ */
4142
+ getPort() {
4143
+ return this._port;
4144
+ }
4145
+ /**
4146
+ * Returns the network interface the listener is bound to, if set.
4147
+ */
4148
+ getNetworkInterface() {
4149
+ return this._networkInterface;
4150
+ }
4151
+ /**
4152
+ * Returns whether TLS is disabled for this listener.
4153
+ */
4154
+ getDisableTLS() {
4155
+ return !!this._disableTLS;
4156
+ }
4157
+ /**
4158
+ * Returns whether delta sync is enabled for this listener.
4159
+ */
4160
+ getEnableDeltaSync() {
4161
+ return !!this._enableDeltaSync;
4162
+ }
4163
+ /**
4164
+ * Gets the current status of the listener from the native engine.
4165
+ * @returns A promise that resolves to the listener status.
4166
+ */
4167
+ async getStatus() {
4168
+ return await this._engine.URLEndpointListener_getStatus({ listenerId: this._listenerId });
4169
+ }
4170
+ /**
4171
+ * Deletes the listener identity from the native engine.
4172
+ * @param args The arguments for deleting the listener identity.
4173
+ */
4174
+ static async deleteIdentity(args) {
4175
+ return await EngineLocator.getEngine(EngineLocator.key).URLEndpointListener_deleteIdentity(args);
4176
+ }
4177
+ }
4178
+
3991
4179
  const IonicCouchbaseLite = core.registerPlugin('CblIonicPlugin');
3992
4180
 
3993
4181
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
@@ -4060,6 +4248,7 @@ class CapacitorEngine {
4060
4248
  constructor() {
4061
4249
  this._defaultCollectionName = '_default';
4062
4250
  this._defaultScopeName = '_default';
4251
+ this.platform = core.Capacitor.getPlatform();
4063
4252
  EngineLocator.registerEngine(EngineLocator.key, this);
4064
4253
  }
4065
4254
  collection_AddChangeListener(args, cb) {
@@ -4126,7 +4315,7 @@ class CapacitorEngine {
4126
4315
  return IonicCouchbaseLite.collection_RemoveChangeListener(args);
4127
4316
  }
4128
4317
  async collection_RemoveDocumentChangeListener(args) {
4129
- return IonicCouchbaseLite.collection_RemoveChangeListener(args);
4318
+ return IonicCouchbaseLite.collection_RemoveDocumentChangeListener(args);
4130
4319
  }
4131
4320
  async collection_Save(args) {
4132
4321
  return IonicCouchbaseLite.collection_Save(args);
@@ -4353,6 +4542,22 @@ class CapacitorEngine {
4353
4542
  getUUID() {
4354
4543
  return v4().toString();
4355
4544
  }
4545
+ async URLEndpointListener_createListener(args) {
4546
+ const result = await IonicCouchbaseLite.URLEndpointListener_createListener(args);
4547
+ return { listenerId: result.listenerId };
4548
+ }
4549
+ async URLEndpointListener_startListener(args) {
4550
+ return await IonicCouchbaseLite.URLEndpointListener_startListener(args);
4551
+ }
4552
+ async URLEndpointListener_stopListener(args) {
4553
+ return await IonicCouchbaseLite.URLEndpointListener_stopListener(args);
4554
+ }
4555
+ async URLEndpointListener_getStatus(args) {
4556
+ return await IonicCouchbaseLite.URLEndpointListener_getStatus(args);
4557
+ }
4558
+ async URLEndpointListener_deleteIdentity(args) {
4559
+ return await IonicCouchbaseLite.URLEndpointListener_deleteIdentity(args);
4560
+ }
4356
4561
  }
4357
4562
 
4358
4563
  exports.AbstractIndex = AbstractIndex;
@@ -4403,6 +4608,7 @@ exports.Scope = Scope;
4403
4608
  exports.SessionAuthenticator = SessionAuthenticator;
4404
4609
  exports.SortOrder = SortOrder;
4405
4610
  exports.URLEndpoint = URLEndpoint;
4611
+ exports.URLEndpointListener = URLEndpointListener;
4406
4612
  exports.UnaryExpression = UnaryExpression;
4407
4613
  exports.ValueExpression = ValueExpression;
4408
4614
  exports.ValueIndex = ValueIndex;