@dittolive/ditto 3.0.0 → 4.0.0-alpha2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node/ditto.cjs.js CHANGED
@@ -368,7 +368,7 @@ function ditto_collection_remove(...args) { return ditto.ditto_collection_remove
368
368
  function ditto_collection_remove_query_str(...args) { return ditto.ditto_collection_remove_query_str(...args) }
369
369
  function ditto_collection_update(...args) { return ditto.ditto_collection_update(...args) }
370
370
  function ditto_collection_update_multiple(...args) { return ditto.ditto_collection_update_multiple(...args) }
371
- function ditto_disable_sync_with_v2(...args) { return ditto.ditto_disable_sync_with_v2(...args) }
371
+ function ditto_disable_sync_with_v3(...args) { return ditto.ditto_disable_sync_with_v3(...args) }
372
372
  function ditto_document_free(...args) { return ditto.ditto_document_free(...args) }
373
373
  function ditto_document_get_cbor_with_path_type(...args) { return ditto.ditto_document_get_cbor_with_path_type(...args) }
374
374
  function ditto_document_id(...args) { return ditto.ditto_document_id(...args) }
@@ -463,12 +463,12 @@ function dittoAddInternalBLEServerTransport(ditto) {
463
463
  return ditto_add_internal_ble_server_transport(ditto);
464
464
  }
465
465
  }
466
- function BLEClientFreeHandle(handle) {
466
+ function bleClientFreeHandle(handle) {
467
467
  {
468
468
  return ble_client_free_handle(handle);
469
469
  }
470
470
  }
471
- function BLEServerFreeHandle(handle) {
471
+ function bleServerFreeHandle(handle) {
472
472
  {
473
473
  return ble_server_free_handle(handle);
474
474
  }
@@ -478,7 +478,7 @@ function dittoAddInternalMdnsTransport(ditto) {
478
478
  return ditto_add_internal_mdns_transport(ditto);
479
479
  }
480
480
  }
481
- function MdnsClientFreeHandle(handle) {
481
+ function mdnsClientFreeHandle(handle) {
482
482
  {
483
483
  return mdns_client_free_handle(handle);
484
484
  }
@@ -488,26 +488,26 @@ function dittoAddInternalMdnsAdvertiser(ditto) {
488
488
  return ditto_add_internal_mdns_advertiser(ditto);
489
489
  }
490
490
  }
491
- function MdnsServerFreeHandle(handle) {
491
+ function mdnsServerFreeHandle(handle) {
492
492
  {
493
493
  return mdns_server_free_handle(handle);
494
494
  }
495
495
  }
496
496
  // ------------------------------------------------------------- Document ------
497
497
  /** @internal */
498
- function documentSetCBORWithTimestamp(document, path, cbor, createPath, timestamp) {
498
+ function documentSetCBORWithTimestamp(document, path, cbor, timestamp) {
499
499
  ensureInitialized();
500
500
  const pathX = bytesFromString(path);
501
- const errorCode = ditto_document_set_cbor_with_timestamp(document, pathX, cbor, createPath, timestamp);
501
+ const errorCode = ditto_document_set_cbor_with_timestamp(document, pathX, cbor, timestamp);
502
502
  if (errorCode !== 0)
503
503
  throw new Error(errorMessage() || `ditto_document_set_cbor_with_timestamp() failed with error code: ${errorCode}`);
504
504
  }
505
505
  /** @internal */
506
- function documentSetCBOR(document, path, cbor, createPath) {
506
+ function documentSetCBOR(document, path, cbor) {
507
507
  ensureInitialized();
508
508
  // NOTE: not sure if this should be async or not.
509
509
  const pathX = bytesFromString(path);
510
- const errorCode = ditto_document_set_cbor(document, pathX, cbor, createPath);
510
+ const errorCode = ditto_document_set_cbor(document, pathX, cbor);
511
511
  if (errorCode !== 0)
512
512
  throw new Error(errorMessage() || `ditto_document_set_cbor() failed with error code: ${errorCode}`);
513
513
  }
@@ -769,10 +769,10 @@ function staticTCPClientFreeHandle(self) {
769
769
  }
770
770
  // ------------------------------------------------------ WebsocketClient ------
771
771
  /** @internal */
772
- function addWebsocketClient(ditto, address) {
772
+ function addWebsocketClient(ditto, address, routingHint) {
773
773
  ensureInitialized();
774
774
  const addressBuffer = bytesFromString(address);
775
- return ditto_add_websocket_client(ditto, addressBuffer);
775
+ return ditto_add_websocket_client(ditto, addressBuffer, routingHint);
776
776
  }
777
777
  /** @internal */
778
778
  function websocketClientFreeHandle(self) {
@@ -1151,11 +1151,11 @@ function dittoRunGarbageCollection(dittoPointer) {
1151
1151
  return ditto_run_garbage_collection(dittoPointer);
1152
1152
  }
1153
1153
  /** @internal */
1154
- async function dittoDisableSyncWithV2(dittoPointer) {
1154
+ async function dittoDisableSyncWithV3(dittoPointer) {
1155
1155
  ensureInitialized();
1156
- const errorCode = await ditto_disable_sync_with_v2(dittoPointer);
1156
+ const errorCode = await ditto_disable_sync_with_v3(dittoPointer);
1157
1157
  if (errorCode !== 0)
1158
- throw new Error(errorMessage() || `ditto_disable_sync_with_v2() failed with error code: ${errorCode}`);
1158
+ throw new Error(errorMessage() || `ditto_disable_sync_with_v3() failed with error code: ${errorCode}`);
1159
1159
  }
1160
1160
  // ------------------------------------------------------ Hash & Mnemonic ------
1161
1161
  /** @internal */
@@ -1434,7 +1434,7 @@ function awdlDestroy(awdl) {
1434
1434
 
1435
1435
  // NOTE: this is patched up with the actual build version by Jake task
1436
1436
  // build:package and has to be a valid semantic version as defined here: https://semver.org.
1437
- const fullBuildVersionString = '3.0.0';
1437
+ const fullBuildVersionString = '4.0.0-alpha2';
1438
1438
 
1439
1439
  //
1440
1440
  /**
@@ -1471,16 +1471,16 @@ async function init(options = {}) {
1471
1471
  //
1472
1472
  /** @internal */
1473
1473
  class KeepAlive {
1474
+ /** @internal */
1475
+ get isActive() {
1476
+ return this.intervalID !== null;
1477
+ }
1474
1478
  /** @internal */
1475
1479
  constructor() {
1476
1480
  this.countsByID = {};
1477
1481
  this.intervalID = null;
1478
1482
  }
1479
1483
  /** @internal */
1480
- get isActive() {
1481
- return this.intervalID !== null;
1482
- }
1483
- /** @internal */
1484
1484
  retain(id) {
1485
1485
  if (typeof this.countsByID[id] === 'undefined') {
1486
1486
  this.countsByID[id] = 0;
@@ -1532,10 +1532,6 @@ KeepAlive.finalizationRegistry = new FinalizationRegistry(clearInterval);
1532
1532
  * log messages with the Ditto logging infrastructure.
1533
1533
  */
1534
1534
  class Logger {
1535
- // ------------------------------------------------------------ Private ------
1536
- constructor() {
1537
- throw new Error("Logger can't be instantiated, use it's static properties & methods directly instead.");
1538
- }
1539
1535
  /**
1540
1536
  * On Node, registers a file path where logs will be written to, whenever
1541
1537
  * Ditto wants to issue a log (on _top_ of emitting the log to the console).
@@ -1666,6 +1662,10 @@ class Logger {
1666
1662
  static verbose(message) {
1667
1663
  this.log('Verbose', message);
1668
1664
  }
1665
+ // ------------------------------------------------------------ Private ------
1666
+ constructor() {
1667
+ throw new Error("Logger can't be instantiated, use it's static properties & methods directly instead.");
1668
+ }
1669
1669
  }
1670
1670
 
1671
1671
  //
@@ -1821,13 +1821,6 @@ Observer.finalizationRegistry = new FinalizationRegistry(Observer.finalize);
1821
1821
  * `OnlineWithAuthentication` or an `Online` identity.
1822
1822
  */
1823
1823
  class Authenticator {
1824
- /** @internal */
1825
- constructor(keepAlive) {
1826
- this.keepAlive = keepAlive;
1827
- this.status = { isAuthenticated: false, userID: null };
1828
- this.loginSupported = false;
1829
- this.observerManager = new ObserverManager('AuthenticationStatusObservation', { keepAlive });
1830
- }
1831
1824
  /**
1832
1825
  * Log in to Ditto with a third-party token. Throws if authentication is not
1833
1826
  * available, which can be checked with {@link loginSupported}.
@@ -1874,6 +1867,13 @@ class Authenticator {
1874
1867
  return new Observer(this.observerManager, token, { stopsWhenFinalized: true });
1875
1868
  }
1876
1869
  /** @internal */
1870
+ constructor(keepAlive) {
1871
+ this.keepAlive = keepAlive;
1872
+ this.status = { isAuthenticated: false, userID: null };
1873
+ this.loginSupported = false;
1874
+ this.observerManager = new ObserverManager('AuthenticationStatusObservation', { keepAlive });
1875
+ }
1876
+ /** @internal */
1877
1877
  '@ditto.authenticationExpiring'(number) {
1878
1878
  throw new Error(`Authenticator['@ditto.authenticationExpiring']() is abstract and must be implemented by subclasses.`);
1879
1879
  }
@@ -1885,19 +1885,6 @@ class Authenticator {
1885
1885
  // -----------------------------------------------------------------------------
1886
1886
  /** @internal */
1887
1887
  class OnlineAuthenticator extends Authenticator {
1888
- constructor(keepAlive, authClientPointer, ditto, authenticationHandler) {
1889
- super(keepAlive);
1890
- this['loginSupported'] = true;
1891
- this['status'] = { isAuthenticated: false, userID: null };
1892
- this.authClientPointer = authClientPointer;
1893
- this.ditto = new WeakRef(ditto);
1894
- this.authenticationHandler = authenticationHandler;
1895
- this.updateAndNotify(false);
1896
- // NOTE: The ownership of the auth client is transferred to us (from Ditto),
1897
- // so we have to free the auth client once this instance is garbage
1898
- // collected.
1899
- OnlineAuthenticator.finalizationRegistry.register(this, authClientPointer);
1900
- }
1901
1888
  async loginWithToken(token, provider) {
1902
1889
  await dittoAuthClientLoginWithToken(this.authClientPointer, token, provider);
1903
1890
  }
@@ -1915,6 +1902,19 @@ class OnlineAuthenticator extends Authenticator {
1915
1902
  Logger.warning('Unable to logout, related Ditto object does not exist anymore.');
1916
1903
  }
1917
1904
  }
1905
+ constructor(keepAlive, authClientPointer, ditto, authenticationHandler) {
1906
+ super(keepAlive);
1907
+ this['loginSupported'] = true;
1908
+ this['status'] = { isAuthenticated: false, userID: null };
1909
+ this.authClientPointer = authClientPointer;
1910
+ this.ditto = new WeakRef(ditto);
1911
+ this.authenticationHandler = authenticationHandler;
1912
+ this.updateAndNotify(false);
1913
+ // NOTE: The ownership of the auth client is transferred to us (from Ditto),
1914
+ // so we have to free the auth client once this instance is garbage
1915
+ // collected.
1916
+ OnlineAuthenticator.finalizationRegistry.register(this, authClientPointer);
1917
+ }
1918
1918
  '@ditto.authenticationExpiring'(secondsRemaining) {
1919
1919
  const authenticationHandler = this.authenticationHandler;
1920
1920
  if (secondsRemaining > 0) {
@@ -1977,6 +1977,7 @@ const IdentityTypesRequiringOfflineLicenseToken = ['manual', 'sharedKey', 'offli
1977
1977
  //
1978
1978
  // Copyright © 2021 DittoLive Incorporated. All rights reserved.
1979
1979
  //
1980
+ const NO_PREFERRED_ROUTE_HINT = 0;
1980
1981
  /**
1981
1982
  * A configuration object specifying which network transports Ditto should
1982
1983
  * use to sync data.
@@ -2034,6 +2035,7 @@ class TransportConfig {
2034
2035
  };
2035
2036
  this.global = {
2036
2037
  syncGroup: 0,
2038
+ routingHint: NO_PREFERRED_ROUTE_HINT,
2037
2039
  };
2038
2040
  }
2039
2041
  /**
@@ -2079,6 +2081,7 @@ class TransportConfig {
2079
2081
  copy.listen['tcp'] = { ...this.listen.tcp };
2080
2082
  copy.listen['http'] = { ...this.listen.http };
2081
2083
  copy.global.syncGroup = this.global.syncGroup;
2084
+ copy.global.routingHint = this.global.routingHint;
2082
2085
  return copy;
2083
2086
  }
2084
2087
  /**
@@ -2580,6 +2583,18 @@ class CBOR {
2580
2583
  //
2581
2584
  /** Represents a unique identifier for a {@link Document}. */
2582
2585
  class DocumentID {
2586
+ /**
2587
+ * Returns the value of the receiver, lazily decoded from its CBOR
2588
+ * representation if needed.
2589
+ */
2590
+ get value() {
2591
+ let value = this['@ditto.value'];
2592
+ if (typeof value === 'undefined') {
2593
+ value = CBOR.decode(this['@ditto.cbor']);
2594
+ this['@ditto.value'] = value;
2595
+ }
2596
+ return value;
2597
+ }
2583
2598
  /**
2584
2599
  * Creates a new `DocumentID`.
2585
2600
  *
@@ -2618,18 +2633,6 @@ class DocumentID {
2618
2633
  this.isValidated = !skipValidation;
2619
2634
  this['@ditto.cbor'] = validatedCBOR;
2620
2635
  }
2621
- /**
2622
- * Returns the value of the receiver, lazily decoded from its CBOR
2623
- * representation if needed.
2624
- */
2625
- get value() {
2626
- let value = this['@ditto.value'];
2627
- if (typeof value === 'undefined') {
2628
- value = CBOR.decode(this['@ditto.cbor']);
2629
- this['@ditto.value'] = value;
2630
- }
2631
- return value;
2632
- }
2633
2636
  /**
2634
2637
  * Returns `true` if passed in `documentID` is equal to the receiver,
2635
2638
  * otherwise returns `false`.
@@ -2712,11 +2715,6 @@ function validateDocumentIDCBOR(idCBOR) {
2712
2715
  * method of {@link Collection} instead.
2713
2716
  */
2714
2717
  class Attachment {
2715
- /** @internal */
2716
- constructor(ditto, token) {
2717
- this.ditto = ditto;
2718
- this.token = token;
2719
- }
2720
2718
  /** The attachment's metadata. */
2721
2719
  get metadata() {
2722
2720
  return this.token.metadata;
@@ -2750,6 +2748,11 @@ class Attachment {
2750
2748
  return fs.copyFile(attachmentPath, path, fs.COPYFILE_EXCL);
2751
2749
  }
2752
2750
  }
2751
+ /** @internal */
2752
+ constructor(ditto, token) {
2753
+ this.ditto = ditto;
2754
+ this.token = token;
2755
+ }
2753
2756
  }
2754
2757
  /** @internal */
2755
2758
  const attachmentBridge = new Bridge(Attachment, freeAttachmentHandle);
@@ -2792,6 +2795,26 @@ class AttachmentToken {
2792
2795
  * and allow you to stop an in-flight attachment fetch.
2793
2796
  */
2794
2797
  class AttachmentFetcher {
2798
+ /**
2799
+ * Stops fetching the associated attachment and cleans up any associated
2800
+ * resources.
2801
+ *
2802
+ * Note that you are not required to call `stop()` once your attachment fetch
2803
+ * operation has finished. The method primarily exists to allow you to cancel
2804
+ * an attachment fetch request while it is ongoing if you no longer wish for
2805
+ * the attachment to be made available locally to the device.
2806
+ */
2807
+ stop() {
2808
+ AttachmentFetcher.stopWithContextInfo({
2809
+ ditto: this.ditto,
2810
+ attachmentTokenID: this.token.id,
2811
+ cancelTokenPromise: this.cancelTokenPromise,
2812
+ });
2813
+ }
2814
+ /** @internal */
2815
+ then(onfulfilled, onrejected) {
2816
+ return this.attachment.then(onfulfilled, onrejected);
2817
+ }
2795
2818
  /** @internal */
2796
2819
  constructor(ditto, token, eventHandler) {
2797
2820
  this.ditto = ditto;
@@ -2837,26 +2860,6 @@ class AttachmentFetcher {
2837
2860
  };
2838
2861
  AttachmentFetcher.finalizationRegistry.register(this, contextInfo, contextInfo);
2839
2862
  }
2840
- /**
2841
- * Stops fetching the associated attachment and cleans up any associated
2842
- * resources.
2843
- *
2844
- * Note that you are not required to call `stop()` once your attachment fetch
2845
- * operation has finished. The method primarily exists to allow you to cancel
2846
- * an attachment fetch request while it is ongoing if you no longer wish for
2847
- * the attachment to be made available locally to the device.
2848
- */
2849
- stop() {
2850
- AttachmentFetcher.stopWithContextInfo({
2851
- ditto: this.ditto,
2852
- attachmentTokenID: this.token.id,
2853
- cancelTokenPromise: this.cancelTokenPromise,
2854
- });
2855
- }
2856
- /** @internal */
2857
- then(onfulfilled, onrejected) {
2858
- return this.attachment.then(onfulfilled, onrejected);
2859
- }
2860
2863
  static stopWithContextInfo(contextInfo) {
2861
2864
  // No need for synchronicity, here: we let the "stop promise", float / run
2862
2865
  // in a detached fashion since there is no point in awaiting the
@@ -2883,6 +2886,21 @@ AttachmentFetcher.finalizationRegistry = new FinalizationRegistry(AttachmentFetc
2883
2886
  * try to be kept up-to-date with the latest changes from remote peers.
2884
2887
  */
2885
2888
  class Subscription {
2889
+ /**
2890
+ * The name of the collection that the subscription is based on.
2891
+ */
2892
+ get collectionName() {
2893
+ return this.collection.name;
2894
+ }
2895
+ /**
2896
+ * Cancels a subscription and releases all associated resources.
2897
+ */
2898
+ cancel() {
2899
+ if (!this.isCancelled) {
2900
+ this['isCancelled'] = true;
2901
+ Subscription.remove(this, this.contextInfo);
2902
+ }
2903
+ }
2886
2904
  // ----------------------------------------------------------- Internal ------
2887
2905
  /** @internal */
2888
2906
  constructor(collection, query, queryArgsCBOR, orderBys, limit, offset) {
@@ -2906,21 +2924,6 @@ class Subscription {
2906
2924
  };
2907
2925
  Subscription.add(this, this.contextInfo);
2908
2926
  }
2909
- /**
2910
- * The name of the collection that the subscription is based on.
2911
- */
2912
- get collectionName() {
2913
- return this.collection.name;
2914
- }
2915
- /**
2916
- * Cancels a subscription and releases all associated resources.
2917
- */
2918
- cancel() {
2919
- if (!this.isCancelled) {
2920
- this['isCancelled'] = true;
2921
- Subscription.remove(this, this.contextInfo);
2922
- }
2923
- }
2924
2927
  static add(subscription, contextInfo) {
2925
2928
  const dittoX = dittoBridge.pointerFor(contextInfo.ditto);
2926
2929
  addSubscription(dittoX, contextInfo.collectionName, contextInfo.query, contextInfo.queryArgsCBOR, contextInfo.orderBys, contextInfo.limit, contextInfo.offset);
@@ -3015,16 +3018,16 @@ const privateToken = '@ditto.ff82dae89821c5ab822a8b539056bce4';
3015
3018
  * assigned to a property during an update of a document.
3016
3019
  */
3017
3020
  class Register {
3021
+ /** Returns the value of the register. */
3022
+ get value() {
3023
+ return this['@ditto.value'];
3024
+ }
3018
3025
  /**
3019
3026
  * Creates a new Register that can be used as part of a document's content.
3020
3027
  */
3021
3028
  constructor(value) {
3022
3029
  this['@ditto.value'] = value;
3023
3030
  }
3024
- /** Returns the value of the register. */
3025
- get value() {
3026
- return this['@ditto.value'];
3027
- }
3028
3031
  /** @internal */
3029
3032
  static '@ditto.create'(mutableDocument, path, value) {
3030
3033
  const register = mutableDocument ? new MutableRegister(value, privateToken) : new Register(value);
@@ -3080,33 +3083,6 @@ class MutableRegister extends Register {
3080
3083
  }
3081
3084
  }
3082
3085
 
3083
- //
3084
- // Copyright © 2022 DittoLive Incorporated. All rights reserved.
3085
- //
3086
- /**
3087
- * Represents a CRDT Replicated Growable Array (RGA).
3088
- *
3089
- * RGAs are deprecated and you should instead use a `Register` containing an
3090
- * array.
3091
- */
3092
- class RGA {
3093
- /** @internal */
3094
- constructor(array = []) {
3095
- this['@ditto.value'] = array;
3096
- }
3097
- /** The array representation of the RGA. */
3098
- get value() {
3099
- return this['@ditto.value'];
3100
- }
3101
- /** @internal */
3102
- static '@ditto.create'(path, value) {
3103
- const rga = new RGA(value);
3104
- rga['@ditto.path'] = path;
3105
- rga['@ditto.value'] = value;
3106
- return rga;
3107
- }
3108
- }
3109
-
3110
3086
  //
3111
3087
  // Copyright © 2021 DittoLive Incorporated. All rights reserved.
3112
3088
  //
@@ -3119,16 +3095,6 @@ class RGA {
3119
3095
  * - `incremented`
3120
3096
  */
3121
3097
  class UpdateResult {
3122
- /** @internal */
3123
- constructor(type, docID, path, value, amount) {
3124
- this.type = type;
3125
- this.docID = docID;
3126
- this.path = path;
3127
- if (value !== undefined)
3128
- this.value = value;
3129
- if (amount !== undefined)
3130
- this.amount = amount;
3131
- }
3132
3098
  // ----------------------------------------------------------- Internal ------
3133
3099
  /** @internal */
3134
3100
  static set(docID, path, value) {
@@ -3142,6 +3108,16 @@ class UpdateResult {
3142
3108
  static removed(docID, path) {
3143
3109
  return new UpdateResult('removed', docID, path, undefined, undefined);
3144
3110
  }
3111
+ /** @internal */
3112
+ constructor(type, docID, path, value, amount) {
3113
+ this.type = type;
3114
+ this.docID = docID;
3115
+ this.path = path;
3116
+ if (value !== undefined)
3117
+ this.value = value;
3118
+ if (amount !== undefined)
3119
+ this.amount = amount;
3120
+ }
3145
3121
  }
3146
3122
 
3147
3123
  //
@@ -3161,10 +3137,6 @@ function augmentJSONValue(json, mutDoc, workingPath) {
3161
3137
  else if (json[DittoCRDTTypeKey] === DittoCRDTType.register) {
3162
3138
  return Register['@ditto.create'](mutDoc, workingPath, json[DittoCRDTValueKey]);
3163
3139
  }
3164
- else if (json[DittoCRDTTypeKey] === DittoCRDTType.rga) {
3165
- const augmentedValue = augmentJSONValue(json[DittoCRDTValueKey], mutDoc, workingPath);
3166
- return RGA['@ditto.create'](workingPath, augmentedValue);
3167
- }
3168
3140
  else if (json[DittoCRDTTypeKey] === DittoCRDTType.attachment) {
3169
3141
  return new AttachmentToken(json);
3170
3142
  }
@@ -3199,12 +3171,6 @@ function desugarJSObject(jsObj, atRoot = false) {
3199
3171
  registerJSON[DittoCRDTValueKey] = jsObj.value;
3200
3172
  return registerJSON;
3201
3173
  }
3202
- else if (jsObj instanceof RGA) {
3203
- const rgaJSON = {};
3204
- rgaJSON[DittoCRDTTypeKey] = DittoCRDTType.rga;
3205
- rgaJSON[DittoCRDTValueKey] = desugarJSObject(jsObj.value);
3206
- return rgaJSON;
3207
- }
3208
3174
  else if (jsObj instanceof Attachment) {
3209
3175
  const attachmentJSON = {
3210
3176
  _id: jsObj.token.id,
@@ -3390,11 +3356,6 @@ class KeyPath {
3390
3356
  * method of {@link Document}.
3391
3357
  */
3392
3358
  class DocumentPath {
3393
- /** @internal */
3394
- constructor(document, path, validate) {
3395
- this.document = document;
3396
- this.path = validate ? KeyPath.validate(path, { isInitial: true }) : path;
3397
- }
3398
3359
  /**
3399
3360
  * Returns a new document path instance with the passed in key-path or
3400
3361
  * index appended.
@@ -3452,17 +3413,6 @@ class DocumentPath {
3452
3413
  const underlyingValue = this.underlyingValueForPathType('Register');
3453
3414
  return typeof underlyingValue !== 'undefined' ? Register['@ditto.create'](null, this.path, underlyingValue) : null;
3454
3415
  }
3455
- /**
3456
- * Returns the value at the previously specified key in the document as an
3457
- * {@link RGA} if possible, otherwise returns `null`.
3458
- *
3459
- * @deprecated RGA usage should be replaced. Use arrays inside Registers
3460
- * instead.
3461
- */
3462
- get rga() {
3463
- const underlyingValue = this.underlyingValueForPathType('Rga');
3464
- return typeof underlyingValue !== 'undefined' ? RGA['@ditto.create'](this.path, underlyingValue) : null;
3465
- }
3466
3416
  /**
3467
3417
  * Returns the value at the previously specified key in the document as an
3468
3418
  * {@link AttachmentToken} if possible, otherwise returns `null`.
@@ -3472,6 +3422,11 @@ class DocumentPath {
3472
3422
  return typeof underlyingValue !== 'undefined' ? new AttachmentToken(underlyingValue) : null;
3473
3423
  }
3474
3424
  /** @internal */
3425
+ constructor(document, path, validate) {
3426
+ this.document = document;
3427
+ this.path = validate ? KeyPath.validate(path, { isInitial: true }) : path;
3428
+ }
3429
+ /** @internal */
3475
3430
  underlyingValueForPathType(pathType) {
3476
3431
  const path = this.path;
3477
3432
  const document = this.document;
@@ -3488,11 +3443,6 @@ class DocumentPath {
3488
3443
  * {@link MutableDocument.at | at()} method of {@link MutableDocument}.
3489
3444
  */
3490
3445
  class MutableDocumentPath {
3491
- /** @internal */
3492
- constructor(mutableDocument, path, validate) {
3493
- this.mutableDocument = mutableDocument;
3494
- this.path = validate ? KeyPath.validate(path, { isInitial: true }) : path;
3495
- }
3496
3446
  /**
3497
3447
  * Returns a new mutable document path instance with the passed in key-path or
3498
3448
  * index appended.
@@ -3550,21 +3500,6 @@ class MutableDocumentPath {
3550
3500
  const underlyingValue = this.underlyingValueForPathType('Register');
3551
3501
  return typeof underlyingValue !== 'undefined' ? Register['@ditto.create'](this.mutableDocument, this.path, underlyingValue) : null;
3552
3502
  }
3553
- /**
3554
- * Returns the value at the previously specified key in the document as a
3555
- * {@link RGA} if possible, otherwise returns `null`.
3556
- *
3557
- * Note that the returned type, {@link RGA}, is deprecated and does not allow
3558
- * any mutation. RGAs cannot be created or mutated with this version of the
3559
- * SDK; they can only be read and this is for backwards compatibility reasons.
3560
- *
3561
- * @deprecated RGA usage should be replaced. Use arrays inside Registers
3562
- * instead.
3563
- */
3564
- get rga() {
3565
- const underlyingValue = this.underlyingValueForPathType('Rga');
3566
- return typeof underlyingValue !== 'undefined' ? RGA['@ditto.create'](this.path, underlyingValue) : null;
3567
- }
3568
3503
  /**
3569
3504
  * Returns the value at the previously specified key in the document as a
3570
3505
  * {@link AttachmentToken} if possible, otherwise returns `null`.
@@ -3586,13 +3521,16 @@ class MutableDocumentPath {
3586
3521
  }
3587
3522
  /**
3588
3523
  * Removes a value at the document's key-path defined by the receiver.
3589
- * If removing an index from an `RGA`, any subsequent indexes will be shifted
3590
- * left to fill the gap.
3591
3524
  */
3592
3525
  remove() {
3593
3526
  return this['@ditto.remove']();
3594
3527
  }
3595
3528
  /** @internal */
3529
+ constructor(mutableDocument, path, validate) {
3530
+ this.mutableDocument = mutableDocument;
3531
+ this.path = validate ? KeyPath.validate(path, { isInitial: true }) : path;
3532
+ }
3533
+ /** @internal */
3596
3534
  underlyingValueForPathType(pathType) {
3597
3535
  const path = this.path;
3598
3536
  const document = this.mutableDocument;
@@ -3616,10 +3554,10 @@ class MutableDocumentPath {
3616
3554
  const valueJSON = desugarJSObject(value, false);
3617
3555
  const valueCBOR = CBOR.encode(valueJSON);
3618
3556
  if (isDefault) {
3619
- documentSetCBORWithTimestamp(documentX, this.path, valueCBOR, true, 0);
3557
+ documentSetCBORWithTimestamp(documentX, this.path, valueCBOR, 0);
3620
3558
  }
3621
3559
  else {
3622
- documentSetCBOR(documentX, this.path, valueCBOR, true);
3560
+ documentSetCBOR(documentX, this.path, valueCBOR);
3623
3561
  }
3624
3562
  // HACK: we need a copy of value because the original value can be mutated
3625
3563
  // later on and an update result needs the state of the value at this
@@ -3756,11 +3694,6 @@ class Document {
3756
3694
  * {@link PendingIDSpecificOperation.update | PendingIDSpecificOperation}.
3757
3695
  */
3758
3696
  class MutableDocument {
3759
- /** @internal */
3760
- constructor() {
3761
- /** @internal */
3762
- this['@ditto.updateResults'] = [];
3763
- }
3764
3697
  /**
3765
3698
  * Returns the ID of the document.
3766
3699
  */
@@ -3792,6 +3725,11 @@ class MutableDocument {
3792
3725
  at(keyPathOrIndex) {
3793
3726
  return this.path.at(keyPathOrIndex);
3794
3727
  }
3728
+ /** @internal */
3729
+ constructor() {
3730
+ /** @internal */
3731
+ this['@ditto.updateResults'] = [];
3732
+ }
3795
3733
  // TEMPORARY: helpers to deal with non-canonical IDs.
3796
3734
  /** @internal */
3797
3735
  static idCBOR(mutableDocument) {
@@ -3832,6 +3770,22 @@ function documentsFrom(documentOrMany) {
3832
3770
  * with detailed info about the performed updates.
3833
3771
  */
3834
3772
  class UpdateResultsMap {
3773
+ /**
3774
+ * Returns an array of {@link UpdateResult | update results} associated with
3775
+ * the `documentID` or undefined if not found.
3776
+ */
3777
+ get(documentIDOrValue) {
3778
+ const documentID = documentIDOrValue instanceof DocumentID ? documentIDOrValue : new DocumentID(documentIDOrValue);
3779
+ const documentIDString = documentID.toString();
3780
+ return this.updateResultsByDocumentIDString[documentIDString];
3781
+ }
3782
+ /**
3783
+ * Returns all contained keys, i.e. {@link DocumentID | document IDs}
3784
+ * contained in this map.
3785
+ */
3786
+ keys() {
3787
+ return this.documentIDs.slice();
3788
+ }
3835
3789
  // ----------------------------------------------------------- Internal ------
3836
3790
  /** @internal */
3837
3791
  constructor(documentIDs, updateResultsByDocumentIDString) {
@@ -3853,22 +3807,6 @@ class UpdateResultsMap {
3853
3807
  this.documentIDs = documentIDs.slice();
3854
3808
  this.updateResultsByDocumentIDString = { ...updateResultsByDocumentIDString };
3855
3809
  }
3856
- /**
3857
- * Returns an array of {@link UpdateResult | update results} associated with
3858
- * the `documentID` or undefined if not found.
3859
- */
3860
- get(documentIDOrValue) {
3861
- const documentID = documentIDOrValue instanceof DocumentID ? documentIDOrValue : new DocumentID(documentIDOrValue);
3862
- const documentIDString = documentID.toString();
3863
- return this.updateResultsByDocumentIDString[documentIDString];
3864
- }
3865
- /**
3866
- * Returns all contained keys, i.e. {@link DocumentID | document IDs}
3867
- * contained in this map.
3868
- */
3869
- keys() {
3870
- return this.documentIDs.slice();
3871
- }
3872
3810
  }
3873
3811
 
3874
3812
  //
@@ -3905,19 +3843,6 @@ class LiveQueryEventInitial {
3905
3843
  * covered by a (live) query.
3906
3844
  */
3907
3845
  class LiveQueryEventUpdate {
3908
- /** @internal */
3909
- constructor(params) {
3910
- /**
3911
- * Whether or not this is the initial event being delivered. Always `false`
3912
- * for `LiveQueryEventUpdate`.
3913
- */
3914
- this.isInitial = false;
3915
- this.oldDocuments = params.oldDocuments;
3916
- this.insertions = params.insertions;
3917
- this.deletions = params.deletions;
3918
- this.updates = params.updates;
3919
- this.moves = params.moves;
3920
- }
3921
3846
  /**
3922
3847
  * Returns a hash that represents the set of matching documents.
3923
3848
  */
@@ -3931,6 +3856,19 @@ class LiveQueryEventUpdate {
3931
3856
  hashMnemonic(documents) {
3932
3857
  return documentsHashMnemonic(documents.map((doc) => documentBridge.pointerFor(doc)));
3933
3858
  }
3859
+ /** @internal */
3860
+ constructor(params) {
3861
+ /**
3862
+ * Whether or not this is the initial event being delivered. Always `false`
3863
+ * for `LiveQueryEventUpdate`.
3864
+ */
3865
+ this.isInitial = false;
3866
+ this.oldDocuments = params.oldDocuments;
3867
+ this.insertions = params.insertions;
3868
+ this.deletions = params.deletions;
3869
+ this.updates = params.updates;
3870
+ this.moves = params.moves;
3871
+ }
3934
3872
  }
3935
3873
  // -----------------------------------------------------------------------------
3936
3874
  /**
@@ -3938,11 +3876,6 @@ class LiveQueryEventUpdate {
3938
3876
  * live query.
3939
3877
  */
3940
3878
  class SingleDocumentLiveQueryEvent {
3941
- /** @internal */
3942
- constructor(isInitial, oldDocument) {
3943
- this.isInitial = isInitial;
3944
- this.oldDocument = oldDocument;
3945
- }
3946
3879
  /**
3947
3880
  * Returns a hash that represents the set of matching documents.
3948
3881
  */
@@ -3956,6 +3889,11 @@ class SingleDocumentLiveQueryEvent {
3956
3889
  hashMnemonic(document) {
3957
3890
  return documentsHashMnemonic(document === null ? [] : [documentBridge.pointerFor(document)]);
3958
3891
  }
3892
+ /** @internal */
3893
+ constructor(isInitial, oldDocument) {
3894
+ this.isInitial = isInitial;
3895
+ this.oldDocument = oldDocument;
3896
+ }
3959
3897
  }
3960
3898
 
3961
3899
  //
@@ -3974,6 +3912,28 @@ class SingleDocumentLiveQueryEvent {
3974
3912
  * documents matching a query then you must call {@link stop | stop()}.
3975
3913
  */
3976
3914
  class LiveQuery {
3915
+ /** The name of the collection that the live query is based on. */
3916
+ get collectionName() {
3917
+ return this.collection.name;
3918
+ }
3919
+ /** Returns true if the receiver has been stopped. */
3920
+ get isStopped() {
3921
+ return this.liveQueryID === null;
3922
+ }
3923
+ /**
3924
+ * Stop the live query from delivering updates.
3925
+ */
3926
+ stop() {
3927
+ var _a;
3928
+ const liveQueryID = this.liveQueryID;
3929
+ if (liveQueryID !== null) {
3930
+ this.collection.store.ditto.keepAlive.release(`LiveQuery.${liveQueryID}`);
3931
+ this.liveQueryID = null;
3932
+ const dittoPointer = dittoBridge.pointerFor(this.collection.store.ditto);
3933
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.cancel();
3934
+ liveQueryStop(dittoPointer, liveQueryID);
3935
+ }
3936
+ }
3977
3937
  /** @internal */
3978
3938
  constructor(query, queryArgs, queryArgsCBOR, orderBys, limit, offset, collection, subscription, handler) {
3979
3939
  // Query should be validated at this point.
@@ -4026,28 +3986,6 @@ class LiveQuery {
4026
3986
  step(async () => await liveQueryStart(dittoPointer, liveQueryID));
4027
3987
  collection.store.ditto.keepAlive.retain(`LiveQuery.${liveQueryID}`);
4028
3988
  }
4029
- /** The name of the collection that the live query is based on. */
4030
- get collectionName() {
4031
- return this.collection.name;
4032
- }
4033
- /** Returns true if the receiver has been stopped. */
4034
- get isStopped() {
4035
- return this.liveQueryID === null;
4036
- }
4037
- /**
4038
- * Stop the live query from delivering updates.
4039
- */
4040
- stop() {
4041
- var _a;
4042
- const liveQueryID = this.liveQueryID;
4043
- if (liveQueryID !== null) {
4044
- this.collection.store.ditto.keepAlive.release(`LiveQuery.${liveQueryID}`);
4045
- this.liveQueryID = null;
4046
- const dittoPointer = dittoBridge.pointerFor(this.collection.store.ditto);
4047
- (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.cancel();
4048
- liveQueryStop(dittoPointer, liveQueryID);
4049
- }
4050
- }
4051
3989
  /** @internal */
4052
3990
  async signalNext() {
4053
3991
  // IDEA: make this public?
@@ -4084,17 +4022,6 @@ class LiveQuery {
4084
4022
  * Update and remove functionality is also exposed through this object.
4085
4023
  */
4086
4024
  class PendingCursorOperation {
4087
- // ----------------------------------------------------------- Internal ------
4088
- /** @internal */
4089
- constructor(query, queryArgs, collection) {
4090
- this.currentLimit = -1;
4091
- this.currentOffset = 0;
4092
- this.orderBys = [];
4093
- this.query = validateQuery(query);
4094
- this.queryArgs = queryArgs ? Object.freeze({ ...queryArgs }) : null;
4095
- this.collection = collection;
4096
- this.queryArgsCBOR = queryArgs ? CBOR.encode(queryArgs) : null;
4097
- }
4098
4025
  /**
4099
4026
  * Sorts the documents that match the query provided in the preceding
4100
4027
  * `find`-like function call.
@@ -4350,6 +4277,17 @@ class PendingCursorOperation {
4350
4277
  return new UpdateResultsMap(updateResultsDocumentIDs, updateResultsByDocumentIDString);
4351
4278
  });
4352
4279
  }
4280
+ // ----------------------------------------------------------- Internal ------
4281
+ /** @internal */
4282
+ constructor(query, queryArgs, collection) {
4283
+ this.currentLimit = -1;
4284
+ this.currentOffset = 0;
4285
+ this.orderBys = [];
4286
+ this.query = validateQuery(query);
4287
+ this.queryArgs = queryArgs ? Object.freeze({ ...queryArgs }) : null;
4288
+ this.collection = collection;
4289
+ this.queryArgsCBOR = queryArgs ? CBOR.encode(queryArgs) : null;
4290
+ }
4353
4291
  /** @internal */
4354
4292
  _observe(handler, createSubscription, waitForNextSignal) {
4355
4293
  const subscription = createSubscription ? this.subscribe() : null;
@@ -4393,13 +4331,6 @@ class PendingCursorOperation {
4393
4331
  * Update and remove functionality is also exposed through this object.
4394
4332
  */
4395
4333
  class PendingIDSpecificOperation {
4396
- // ----------------------------------------------------------- Internal ------
4397
- /** @internal */
4398
- constructor(documentID, collection) {
4399
- this.documentID = documentID;
4400
- this.collection = collection;
4401
- this.documentIDCBOR = documentID.toCBOR();
4402
- }
4403
4334
  /**
4404
4335
  * Enables you to subscribe to changes that occur in relation to a document
4405
4336
  * remotely.
@@ -4545,6 +4476,13 @@ class PendingIDSpecificOperation {
4545
4476
  await writeTransactionCommit(dittoX, writeTransactionX);
4546
4477
  return mutableDocument['@ditto.updateResults'].slice();
4547
4478
  }
4479
+ // ----------------------------------------------------------- Internal ------
4480
+ /** @internal */
4481
+ constructor(documentID, collection) {
4482
+ this.documentID = documentID;
4483
+ this.collection = collection;
4484
+ this.documentIDCBOR = documentID.toCBOR();
4485
+ }
4548
4486
  /** @internal */
4549
4487
  _observe(handler, createSubscription, waitForNextSignal) {
4550
4488
  const subscription = createSubscription ? this.subscribe() : null;
@@ -4603,11 +4541,6 @@ class PendingIDSpecificOperation {
4603
4541
  * object.
4604
4542
  */
4605
4543
  class Collection {
4606
- /** @internal */
4607
- constructor(name, store) {
4608
- this.name = name;
4609
- this.store = store;
4610
- }
4611
4544
  /**
4612
4545
  * Generates a {@link PendingCursorOperation} using the provided query.
4613
4546
  *
@@ -4762,6 +4695,11 @@ class Collection {
4762
4695
  const ditto = this.store.ditto;
4763
4696
  return new AttachmentFetcher(ditto, token, eventHandler);
4764
4697
  }
4698
+ /** @internal */
4699
+ constructor(name, store) {
4700
+ this.name = name;
4701
+ this.store = store;
4702
+ }
4765
4703
  // TEMPORARY: helpers to deal with non-canonical IDs.
4766
4704
  /** @internal */
4767
4705
  findByIDCBOR(idCBOR) {
@@ -4784,16 +4722,6 @@ class Collection {
4784
4722
  * or moved since the last event.
4785
4723
  */
4786
4724
  class CollectionsEvent {
4787
- /** @internal */
4788
- constructor(params) {
4789
- this.isInitial = params.isInitial;
4790
- this.collections = params.collections;
4791
- this.oldCollections = params.oldCollections;
4792
- this.insertions = params.insertions;
4793
- this.deletions = params.deletions;
4794
- this.updates = params.updates;
4795
- this.moves = params.moves;
4796
- }
4797
4725
  /** @internal */
4798
4726
  static initial(collections) {
4799
4727
  return new CollectionsEvent({
@@ -4806,6 +4734,16 @@ class CollectionsEvent {
4806
4734
  moves: [],
4807
4735
  });
4808
4736
  }
4737
+ /** @internal */
4738
+ constructor(params) {
4739
+ this.isInitial = params.isInitial;
4740
+ this.collections = params.collections;
4741
+ this.oldCollections = params.oldCollections;
4742
+ this.insertions = params.insertions;
4743
+ this.deletions = params.deletions;
4744
+ this.updates = params.updates;
4745
+ this.moves = params.moves;
4746
+ }
4809
4747
  }
4810
4748
 
4811
4749
  //
@@ -4829,11 +4767,6 @@ class CollectionsEvent {
4829
4767
  * like to receive updates from them about the collections that they know about.
4830
4768
  */
4831
4769
  class PendingCollectionsOperation {
4832
- /** @internal */
4833
- constructor(store) {
4834
- this.store = store;
4835
- this.pendingCursorOperation = new PendingCursorOperation('true', null, new Collection('__collections', store));
4836
- }
4837
4770
  /**
4838
4771
  * Sort the collections based on a property of the collection.
4839
4772
  *
@@ -4948,24 +4881,30 @@ class PendingCollectionsOperation {
4948
4881
  return collectionsFromDocuments(documents, this.store);
4949
4882
  }
4950
4883
  /** @internal */
4884
+ constructor(store) {
4885
+ this.store = store;
4886
+ this.pendingCursorOperation = new PendingCursorOperation('true', null, new Collection('__collections', store));
4887
+ }
4888
+ /** @internal */
4951
4889
  then(onfulfilled, onrejected) {
4952
4890
  return this.exec().then(onfulfilled, onrejected);
4953
4891
  }
4954
4892
  // ----------------------------------------------------------- Internal ------
4955
4893
  /** @internal */
4956
4894
  _observe(handler, createSubscription, waitForNextSignal) {
4957
- const weakThis = new WeakRef(this);
4895
+ const weakStore = new WeakRef(this.store);
4958
4896
  const collectionsObservationHandler = function (documents, event, nextSignal) {
4959
- const strongThis = weakThis.deref();
4960
- if (strongThis === null)
4897
+ const strongStore = weakStore.deref();
4898
+ if (!strongStore) {
4961
4899
  return;
4962
- const collections = collectionsFromDocuments(documents, strongThis.store);
4900
+ }
4901
+ const collections = collectionsFromDocuments(documents, strongStore);
4963
4902
  let collEvent;
4964
4903
  if (event.isInitial === true) {
4965
4904
  collEvent = CollectionsEvent.initial(collections);
4966
4905
  }
4967
4906
  else {
4968
- const oldCollections = collectionsFromDocuments(event.oldDocuments, strongThis.store);
4907
+ const oldCollections = collectionsFromDocuments(event.oldDocuments, strongStore);
4969
4908
  collEvent = new CollectionsEvent({
4970
4909
  isInitial: false,
4971
4910
  collections,
@@ -5007,11 +4946,6 @@ function collectionsFromDocuments(documents, store) {
5007
4946
  * instance via its {@link Ditto.store | store} property.
5008
4947
  */
5009
4948
  class Store {
5010
- // ----------------------------------------------------------- Internal ------
5011
- /** @internal */
5012
- constructor(ditto) {
5013
- this.ditto = ditto;
5014
- }
5015
4949
  /**
5016
4950
  * Returns the collection for the given name. If the collection doesn't
5017
4951
  * exist yet, it will be created automatically as soon as the first
@@ -5037,6 +4971,11 @@ class Store {
5037
4971
  collectionNames() {
5038
4972
  return dittoGetCollectionNames(dittoBridge.pointerFor(this.ditto));
5039
4973
  }
4974
+ // ----------------------------------------------------------- Internal ------
4975
+ /** @internal */
4976
+ constructor(ditto) {
4977
+ this.ditto = ditto;
4978
+ }
5040
4979
  /**
5041
4980
  * Private method, used only by the Portal https://github.com/getditto/ditto/pull/3652
5042
4981
  * @internal
@@ -5067,25 +5006,6 @@ function addressToString(address) {
5067
5006
  * instance via its `presence` property.
5068
5007
  */
5069
5008
  class Presence {
5070
- /** @internal */
5071
- constructor(ditto) {
5072
- this.ditto = ditto;
5073
- this.observerManager = new ObserverManager('PresenceObservation', {
5074
- keepAlive: ditto.keepAlive,
5075
- register: (callback) => {
5076
- const dittoPointer = dittoBridge.pointerFor(this.ditto);
5077
- dittoRegisterPresenceV3Callback(dittoPointer, callback);
5078
- },
5079
- unregister: () => {
5080
- const dittoPointer = dittoBridge.pointerFor(this.ditto);
5081
- dittoClearPresenceV3Callback(dittoPointer);
5082
- },
5083
- process: (presenceGraphJSONString) => {
5084
- const presenceGraph = JSON.parse(presenceGraphJSONString);
5085
- return [presenceGraph];
5086
- },
5087
- });
5088
- }
5089
5009
  /**
5090
5010
  * Returns the current presence graph capturing all known peers and
5091
5011
  * connections between them.
@@ -5114,6 +5034,25 @@ class Presence {
5114
5034
  didChangeHandler(this.graph);
5115
5035
  return observer;
5116
5036
  }
5037
+ /** @internal */
5038
+ constructor(ditto) {
5039
+ this.ditto = ditto;
5040
+ this.observerManager = new ObserverManager('PresenceObservation', {
5041
+ keepAlive: ditto.keepAlive,
5042
+ register: (callback) => {
5043
+ const dittoPointer = dittoBridge.pointerFor(this.ditto);
5044
+ dittoRegisterPresenceV3Callback(dittoPointer, callback);
5045
+ },
5046
+ unregister: () => {
5047
+ const dittoPointer = dittoBridge.pointerFor(this.ditto);
5048
+ dittoClearPresenceV3Callback(dittoPointer);
5049
+ },
5050
+ process: (presenceGraphJSONString) => {
5051
+ const presenceGraph = JSON.parse(presenceGraphJSONString);
5052
+ return [presenceGraph];
5053
+ },
5054
+ });
5055
+ }
5117
5056
  }
5118
5057
 
5119
5058
  //
@@ -5342,8 +5281,8 @@ class Sync {
5342
5281
  if (shouldStop && !this.bluetoothLETransportPointer)
5343
5282
  throw new Error(`Internal inconsistency, when stopping BLE transport, a BLE transport pointer should exist.`);
5344
5283
  {
5345
- // HACK: quick & dirty Linux hack. A proper implementation should
5346
- // encapsulate everything behind the transports module. To undo,
5284
+ // HACK: quick & dirty Linux & Windows hack. A proper implementation
5285
+ // should encapsulate everything behind the transports module. To undo,
5347
5286
  // remove the whole if block.
5348
5287
  if (process.platform === 'linux' || process.platform === 'win32') {
5349
5288
  if (shouldStart) {
@@ -5355,8 +5294,8 @@ class Sync {
5355
5294
  if (shouldStop) {
5356
5295
  const blePlatform = this.bluetoothLETransportPointer;
5357
5296
  const { clientTransport, serverTransport } = blePlatform;
5358
- BLEServerFreeHandle(serverTransport);
5359
- BLEClientFreeHandle(clientTransport);
5297
+ bleServerFreeHandle(serverTransport);
5298
+ bleClientFreeHandle(clientTransport);
5360
5299
  this.bluetoothLETransportPointer = null;
5361
5300
  }
5362
5301
  return;
@@ -5392,58 +5331,41 @@ class Sync {
5392
5331
  this.awdlTransportPointer = null;
5393
5332
  }
5394
5333
  }
5395
- startLan(newConfig, { lanStartsServer }) {
5396
- const dittoPointer = dittoBridge.pointerFor(this.ditto);
5397
- if (lanStartsServer) {
5398
- dittoStartTCPServer(dittoPointer, null);
5399
- }
5400
- if (newConfig.isMdnsEnabled) {
5401
- const clientHandle = dittoAddInternalMdnsTransport(dittoPointer);
5402
- this.mdnsClientTransportPointer = clientHandle;
5403
- const serverHandle = dittoAddInternalMdnsAdvertiser(dittoPointer);
5404
- this.mdnsServerAdvertiserPointer = serverHandle;
5405
- }
5406
- if (newConfig.isMulticastEnabled) {
5407
- dittoAddMulticastTransport(dittoPointer);
5408
- }
5409
- }
5410
- stopLan({ lanStopsServer }) {
5411
- const dittoPointer = dittoBridge.pointerFor(this.ditto);
5412
- if (lanStopsServer) {
5413
- dittoStopTCPServer(dittoPointer);
5414
- }
5415
- if (this.mdnsClientTransportPointer) {
5416
- MdnsClientFreeHandle(this.mdnsClientTransportPointer);
5417
- this.mdnsClientTransportPointer = null;
5418
- }
5419
- if (this.mdnsServerAdvertiserPointer) {
5420
- MdnsServerFreeHandle(this.mdnsServerAdvertiserPointer);
5421
- this.mdnsServerAdvertiserPointer = null;
5422
- }
5423
- dittoRemoveMulticastTransport(dittoPointer);
5424
- }
5425
5334
  updatePeerToPeerLAN(stateOld, stateNew) {
5426
5335
  const dittoPointer = dittoBridge.pointerFor(this.ditto);
5427
5336
  const lanOld = stateOld.effectiveTransportConfig.peerToPeer.lan;
5428
5337
  const lanNew = stateNew.effectiveTransportConfig.peerToPeer.lan;
5429
5338
  {
5339
+ // HACK: quick & dirty Linux & Windows hack. A proper implementation
5340
+ // should encapsulate everything behind the transports module. To undo,
5341
+ // remove the whole if block.
5430
5342
  // FIXME: include 'linux' as well
5431
5343
  if (process.platform === 'win32') {
5432
- if (stateOld.effectiveTransportConfig.listen.tcp !== stateNew.effectiveTransportConfig.listen.tcp || lanOld !== lanNew) {
5433
- this.stopLan({
5434
- lanStopsServer: !stateOld.effectiveTransportConfig.listen.tcp.isEnabled,
5435
- });
5436
- if (lanNew.isEnabled) {
5437
- this.startLan(lanNew, {
5438
- lanStartsServer: !stateNew.effectiveTransportConfig.listen.tcp.isEnabled,
5439
- });
5344
+ if (lanOld.isEnabled) {
5345
+ if (lanOld.isMdnsEnabled) {
5346
+ mdnsClientFreeHandle(this.mdnsClientTransportPointer);
5347
+ this.mdnsClientTransportPointer = null;
5348
+ mdnsServerFreeHandle(this.mdnsServerAdvertiserPointer);
5349
+ this.mdnsServerAdvertiserPointer = null;
5350
+ }
5351
+ if (lanOld.isMulticastEnabled) {
5352
+ dittoRemoveMulticastTransport(dittoPointer);
5353
+ }
5354
+ }
5355
+ if (lanNew.isEnabled) {
5356
+ if (lanNew.isMdnsEnabled) {
5357
+ this.mdnsClientTransportPointer = dittoAddInternalMdnsTransport(dittoPointer);
5358
+ this.mdnsServerAdvertiserPointer = dittoAddInternalMdnsAdvertiser(dittoPointer);
5359
+ }
5360
+ if (lanNew.isMulticastEnabled) {
5361
+ dittoAddMulticastTransport(dittoPointer);
5440
5362
  }
5441
5363
  }
5442
5364
  return;
5443
5365
  }
5444
5366
  }
5445
5367
  // IDEA: move the logic for this dance into stateFrom() signal
5446
- // via some additional state what needs to be done here?
5368
+ // via some additional state signaling the actions here.
5447
5369
  if (lanOld.isEnabled) {
5448
5370
  if (lanOld.isMdnsEnabled) {
5449
5371
  lanDestroy(this.lanTransportPointer);
@@ -5532,8 +5454,9 @@ class Sync {
5532
5454
  websocketURLsToDisconnectFromSet.delete(websocketURL);
5533
5455
  const websocketURLsToConnectTo = websocketURLsToConnectToSet.values();
5534
5456
  const websocketURLsToDisconnectFrom = websocketURLsToDisconnectFromSet.values();
5457
+ const routingHint = stateNew.effectiveTransportConfig.global.routingHint;
5535
5458
  for (const websocketURL of websocketURLsToConnectTo) {
5536
- const websocketClientPointer = addWebsocketClient(dittoBridge.pointerFor(this.ditto), websocketURL);
5459
+ const websocketClientPointer = addWebsocketClient(dittoBridge.pointerFor(this.ditto), websocketURL, routingHint);
5537
5460
  const websocketClient = websocketClientBridge.bridge(websocketClientPointer);
5538
5461
  this.websocketClientsByURL[websocketURL] = websocketClient;
5539
5462
  }
@@ -5604,8 +5527,7 @@ function stateFrom(parameters) {
5604
5527
  // TCP listening is explicitly enabled. This means we also have to stop it
5605
5528
  // if we started it previously due to this condition.
5606
5529
  if (transportConfig.peerToPeer.lan.isEnabled && !transportConfig.listen.tcp.isEnabled) {
5607
- // FIXME(Daniel): Having this enabled messes up with the logic of `startLan`; so let's avoid this.
5608
- // transportConfig.listen.tcp.isEnabled = true
5530
+ transportConfig.listen.tcp.isEnabled = true;
5609
5531
  transportConfig.listen.tcp.interfaceIP = '0.0.0.0';
5610
5532
  transportConfig.listen.tcp.port = 0;
5611
5533
  }
@@ -5621,6 +5543,11 @@ function stateFrom(parameters) {
5621
5543
  * Ditto is the entry point for accessing Ditto-related functionality.
5622
5544
  */
5623
5545
  class Ditto {
5546
+ /** Returns a string identifying the version of the Ditto SDK. */
5547
+ get sdkVersion() {
5548
+ const dittoPointer = dittoBridge.pointerFor(this);
5549
+ return dittoGetSDKVersion(dittoPointer);
5550
+ }
5624
5551
  /**
5625
5552
  * Initializes a new `Ditto` instance.
5626
5553
  *
@@ -5761,11 +5688,6 @@ class Ditto {
5761
5688
  this.auth['@ditto.authenticationExpiring'](secondsRemainingUntilAuthenticationExpires);
5762
5689
  }
5763
5690
  }
5764
- /** Returns a string identifying the version of the Ditto SDK. */
5765
- get sdkVersion() {
5766
- const dittoPointer = dittoBridge.pointerFor(this);
5767
- return dittoGetSDKVersion(dittoPointer);
5768
- }
5769
5691
  /**
5770
5692
  * Activate a `Ditto` instance by setting an offline only license token. You cannot initiate sync
5771
5693
  * with `Ditto` before you have activated it. The offline license token is only valid for identities
@@ -5908,16 +5830,16 @@ class Ditto {
5908
5830
  }
5909
5831
  /**
5910
5832
  * Explicitly opt-in to disabling the ability to sync with Ditto peers running
5911
- * any version of the SDK in the v2 series of releases.
5833
+ * any version of the SDK in the v3 series of releases.
5912
5834
  *
5913
5835
  * Assuming this succeeds then this peer will only be able to sync with other
5914
- * peers using SDKs in the v3 series of releases. Note that this disabling of
5836
+ * peers using SDKs in the v4 series of releases. Note that this disabling of
5915
5837
  * sync spreads to peers that sync with a peer that has disabled, or has
5916
- * (transitively) had disabled, syncing with v2 SDK peers.
5838
+ * (transitively) had disabled, syncing with v3 SDK peers.
5917
5839
  */
5918
- disableSyncWithV2() {
5840
+ disableSyncWithV3() {
5919
5841
  const dittoPointer = dittoBridge.pointerFor(this);
5920
- dittoDisableSyncWithV2(dittoPointer);
5842
+ dittoDisableSyncWithV3(dittoPointer);
5921
5843
  }
5922
5844
  authClientValidityChanged(isWebValid, isX509Valid) {
5923
5845
  const transportConfig = this.transportConfig;
@@ -6062,7 +5984,6 @@ exports.PendingCollectionsOperation = PendingCollectionsOperation;
6062
5984
  exports.PendingCursorOperation = PendingCursorOperation;
6063
5985
  exports.PendingIDSpecificOperation = PendingIDSpecificOperation;
6064
5986
  exports.Presence = Presence;
6065
- exports.RGA = RGA;
6066
5987
  exports.Register = Register;
6067
5988
  exports.SingleDocumentLiveQueryEvent = SingleDocumentLiveQueryEvent;
6068
5989
  exports.Store = Store;