cbl-ionic 1.0.0 → 1.0.2

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 (43) hide show
  1. package/CblIonic.podspec +2 -2
  2. package/README.md +5 -0
  3. package/android/build.gradle +7 -2
  4. package/android/src/main/java/cbl/js/kotiln/URLEndpointListenerManager.kt +143 -0
  5. package/android/src/main/java/com/couchbase/ionic/CblIonicPluginPlugin.kt +164 -18
  6. package/android/src/main/java/com/couchbase/ionic/PluginHelper.kt +27 -38
  7. package/android/src/main/java/com/couchbase/ionic/QueryHelper.kt +14 -4
  8. package/android/src/main/java/com/couchbase/ionic/ReplicatorHelper.kt +25 -7
  9. package/dist/esm/cblite-js/cblite/core-types.d.ts +143 -4
  10. package/dist/esm/cblite-js/cblite/src/collection-config.d.ts +34 -0
  11. package/dist/esm/cblite-js/cblite/src/collection-config.js +40 -0
  12. package/dist/esm/cblite-js/cblite/src/collection-config.js.map +1 -1
  13. package/dist/esm/cblite-js/cblite/src/collection.d.ts +1 -2
  14. package/dist/esm/cblite-js/cblite/src/document.d.ts +3 -4
  15. package/dist/esm/cblite-js/cblite/src/document.js +5 -5
  16. package/dist/esm/cblite-js/cblite/src/document.js.map +1 -1
  17. package/dist/esm/cblite-js/cblite/src/index.d.ts +1 -0
  18. package/dist/esm/cblite-js/cblite/src/index.js +1 -0
  19. package/dist/esm/cblite-js/cblite/src/index.js.map +1 -1
  20. package/dist/esm/cblite-js/cblite/src/query.js +2 -7
  21. package/dist/esm/cblite-js/cblite/src/query.js.map +1 -1
  22. package/dist/esm/cblite-js/cblite/src/replicator-configuration.d.ts +1 -0
  23. package/dist/esm/cblite-js/cblite/src/replicator-configuration.js +20 -0
  24. package/dist/esm/cblite-js/cblite/src/replicator-configuration.js.map +1 -1
  25. package/dist/esm/cblite-js/cblite/src/replicator.js +2 -2
  26. package/dist/esm/cblite-js/cblite/src/replicator.js.map +1 -1
  27. package/dist/esm/cblite-js/cblite/src/url-endpoint-listener.d.ts +84 -0
  28. package/dist/esm/cblite-js/cblite/src/url-endpoint-listener.js +109 -0
  29. package/dist/esm/cblite-js/cblite/src/url-endpoint-listener.js.map +1 -0
  30. package/dist/esm/couchbase-lite/capacitor-engine.d.ts +13 -1
  31. package/dist/esm/couchbase-lite/capacitor-engine.js +19 -1
  32. package/dist/esm/couchbase-lite/capacitor-engine.js.map +1 -1
  33. package/dist/plugin.cjs.js +196 -15
  34. package/dist/plugin.cjs.js.map +1 -1
  35. package/dist/plugin.js +196 -15
  36. package/dist/plugin.js.map +1 -1
  37. package/ios/Plugin/CblIonicPlugin.swift +115 -4
  38. package/ios/Plugin/CblIonicPluginPlugin.m +7 -0
  39. package/ios/Plugin/cbl-js-swift/CollectionManager.swift +22 -0
  40. package/ios/Plugin/cbl-js-swift/MapHelper.swift +0 -23
  41. package/ios/Plugin/cbl-js-swift/ReplicatorHelper.swift +116 -3
  42. package/ios/Plugin/cbl-js-swift/URLEndpointListenerManager.swift +154 -0
  43. package/package.json +5 -4
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;
@@ -459,6 +499,26 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
459
499
  setReplicatorType(replicatorType) {
460
500
  this.replicatorType = replicatorType;
461
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
+ }
462
522
  toJson() {
463
523
  const config = {
464
524
  acceptParentDomainCookies: this.acceptParentDomainCookies,
@@ -914,16 +974,18 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
914
974
  return null;
915
975
  }
916
976
  /**
917
- * 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.
918
979
  * Throws an error if the collection is deleted or the database is closed.
919
980
  *
920
981
  * @function
921
982
  */
922
- getBlob(key) {
983
+ async getBlob(key) {
923
984
  if (key in this.doc) {
924
985
  const data = this._get(key);
925
986
  if (data && typeof data === 'object' && 'content_type' in data) {
926
- 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);
927
989
  b.digest = data.digest;
928
990
  b.length = data.length;
929
991
  return b;
@@ -932,8 +994,6 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
932
994
  return null;
933
995
  }
934
996
  /**
935
- * @deprecated - use the Blob API getBytes() function instead
936
- *
937
997
  * Get a property’s value as a ArrayBuffer. Returns null if the property doesn’t exist,
938
998
  * or its value is not a blob.
939
999
  *
@@ -1754,6 +1814,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1754
1814
  */
1755
1815
  class Query {
1756
1816
  constructor(queryString, database) {
1817
+ this.parameters = new Parameters();
1757
1818
  //used for engine calls
1758
1819
  this._engine = EngineLocator.getEngine(EngineLocator.key);
1759
1820
  this._queryString = queryString;
@@ -1772,7 +1833,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1772
1833
  await this._engine.query_AddChangeListener({
1773
1834
  name: this._database.getUniqueName(),
1774
1835
  query: this._queryString,
1775
- parameters: this.parameters,
1836
+ parameters: this.parameters.get(),
1776
1837
  changeListenerToken: token,
1777
1838
  }, (data, err) => {
1778
1839
  if (err) {
@@ -1803,9 +1864,6 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1803
1864
  * @function
1804
1865
  */
1805
1866
  async execute() {
1806
- if (this.parameters === undefined) {
1807
- this.parameters = new Parameters();
1808
- }
1809
1867
  const queryResults = await this._database.getEngine().query_Execute({
1810
1868
  name: this._database.getUniqueName(),
1811
1869
  query: this._queryString,
@@ -1826,9 +1884,6 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
1826
1884
  * @function
1827
1885
  */
1828
1886
  async explain() {
1829
- if (this.parameters === undefined) {
1830
- this.parameters = new Parameters();
1831
- }
1832
1887
  const queryResults = await this._database.getEngine().query_Explain({
1833
1888
  name: this._database.getUniqueName(),
1834
1889
  query: this._queryString,
@@ -3694,7 +3749,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
3694
3749
  this._engine = EngineLocator.getEngine(EngineLocator.key);
3695
3750
  this._didStartStatusChangeListener = false;
3696
3751
  this._replicatorId = replicatorId;
3697
- this._config = config;
3752
+ this._config = config.clone();
3698
3753
  this._documentChangeListener = new Map();
3699
3754
  }
3700
3755
  /**
@@ -3755,7 +3810,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
3755
3810
  const engine = EngineLocator.getEngine(EngineLocator.key);
3756
3811
  const configJson = config.toJson();
3757
3812
  const ret = await engine.replicator_Create({ config: configJson });
3758
- const replicator = new Replicator(ret.replicatorId, config);
3813
+ const replicator = new Replicator(ret.replicatorId, config.clone());
3759
3814
  return replicator;
3760
3815
  }
3761
3816
  /**
@@ -4010,6 +4065,114 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
4010
4065
  }
4011
4066
  }
4012
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
+
4013
4176
  const IonicCouchbaseLite = core.registerPlugin('CblIonicPlugin');
4014
4177
 
4015
4178
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
@@ -4082,6 +4245,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
4082
4245
  constructor() {
4083
4246
  this._defaultCollectionName = '_default';
4084
4247
  this._defaultScopeName = '_default';
4248
+ this.platform = core.Capacitor.getPlatform();
4085
4249
  EngineLocator.registerEngine(EngineLocator.key, this);
4086
4250
  }
4087
4251
  collection_AddChangeListener(args, cb) {
@@ -4148,7 +4312,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
4148
4312
  return IonicCouchbaseLite.collection_RemoveChangeListener(args);
4149
4313
  }
4150
4314
  async collection_RemoveDocumentChangeListener(args) {
4151
- return IonicCouchbaseLite.collection_RemoveChangeListener(args);
4315
+ return IonicCouchbaseLite.collection_RemoveDocumentChangeListener(args);
4152
4316
  }
4153
4317
  async collection_Save(args) {
4154
4318
  return IonicCouchbaseLite.collection_Save(args);
@@ -4375,6 +4539,22 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
4375
4539
  getUUID() {
4376
4540
  return v4().toString();
4377
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
+ }
4378
4558
  }
4379
4559
 
4380
4560
  exports.AbstractIndex = AbstractIndex;
@@ -4425,6 +4605,7 @@ var capacitorIonicCouchbaseLite = (function (exports, core) {
4425
4605
  exports.SessionAuthenticator = SessionAuthenticator;
4426
4606
  exports.SortOrder = SortOrder;
4427
4607
  exports.URLEndpoint = URLEndpoint;
4608
+ exports.URLEndpointListener = URLEndpointListener;
4428
4609
  exports.UnaryExpression = UnaryExpression;
4429
4610
  exports.ValueExpression = ValueExpression;
4430
4611
  exports.ValueIndex = ValueIndex;