dexie-cloud-addon 4.0.1-beta.31 → 4.0.1-beta.33

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.
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.0.1-beta.31, Thu Mar 09 2023
11
+ * Version 4.0.1-beta.33, Sat Mar 11 2023
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -2532,7 +2532,8 @@ try {
2532
2532
  catch (_a) { }
2533
2533
 
2534
2534
  const swHolder = {};
2535
- const swContainer = typeof self !== undefined && self.document && navigator.serviceWorker; // self.document is to verify we're not the SW ourself
2535
+ const swContainer = typeof self !== 'undefined' && self.document && // self.document is to verify we're not the SW ourself
2536
+ typeof navigator !== 'undefined' && navigator.serviceWorker;
2536
2537
  if (swContainer)
2537
2538
  swContainer.ready.then((registration) => (swHolder.registration = registration));
2538
2539
  if (typeof self !== 'undefined' && 'clients' in self && !self.document) {
@@ -2544,6 +2545,12 @@ if (typeof self !== 'undefined' && 'clients' in self && !self.document) {
2544
2545
  }
2545
2546
  });
2546
2547
  }
2548
+ /** This class is a fallback for browsers that lacks BroadcastChannel but have
2549
+ * service workers (which is Safari versions 11.1 through 15.3).
2550
+ * Safari 15.4 with BroadcastChannel was released on 2022-03-14.
2551
+ * We might be able to remove this class in a near future as Safari < 15.4 is
2552
+ * already very low in market share as of 2023-03-10.
2553
+ */
2547
2554
  class SWBroadcastChannel {
2548
2555
  constructor(name) {
2549
2556
  this.name = name;
@@ -2708,8 +2715,22 @@ function listClientChanges(mutationTables, db, { since = {}, limit = Infinity }
2708
2715
 
2709
2716
  function randomString(bytes) {
2710
2717
  const buf = new Uint8Array(bytes);
2711
- crypto.getRandomValues(buf);
2712
- return btoa(String.fromCharCode.apply(null, buf));
2718
+ if (typeof crypto !== 'undefined') {
2719
+ crypto.getRandomValues(buf);
2720
+ }
2721
+ else {
2722
+ for (let i = 0; i < bytes; i++)
2723
+ buf[i] = Math.floor(Math.random() * 256);
2724
+ }
2725
+ if (typeof Buffer !== 'undefined' && Buffer.from) {
2726
+ return Buffer.from(buf).toString('base64');
2727
+ }
2728
+ else if (typeof btoa !== 'undefined') {
2729
+ return btoa(String.fromCharCode.apply(null, buf));
2730
+ }
2731
+ else {
2732
+ throw new Error('No btoa or Buffer available');
2733
+ }
2713
2734
  }
2714
2735
 
2715
2736
  function listSyncifiedChanges(tablesToSyncify, currentUser, schema, alreadySyncedRealms) {
@@ -3454,9 +3475,12 @@ function throwIfCancelled(cancelToken) {
3454
3475
  This function relies initially on navigator.onLine but then uses online and offline events
3455
3476
  which seem to be more reliable.
3456
3477
  */
3457
- let isOnline = navigator.onLine;
3458
- self.addEventListener('online', () => isOnline = true);
3459
- self.addEventListener('offline', () => isOnline = false);
3478
+ let isOnline = false;
3479
+ if (typeof self !== 'undefined' && typeof navigator !== 'undefined') {
3480
+ isOnline = navigator.onLine;
3481
+ self.addEventListener('online', () => isOnline = true);
3482
+ self.addEventListener('offline', () => isOnline = false);
3483
+ }
3460
3484
 
3461
3485
  function updateBaseRevs(db, schema, latestRevisions, serverRev) {
3462
3486
  return __awaiter(this, void 0, void 0, function* () {
@@ -5938,7 +5962,7 @@ function dexieCloud(dexie) {
5938
5962
  currentUserEmitter.next(UNAUTHORIZED_USER);
5939
5963
  });
5940
5964
  dexie.cloud = {
5941
- version: '4.0.1-beta.31',
5965
+ version: '4.0.1-beta.33',
5942
5966
  options: Object.assign({}, DEFAULT_OPTIONS),
5943
5967
  schema: null,
5944
5968
  get currentUserId() {
@@ -6193,7 +6217,7 @@ function dexieCloud(dexie) {
6193
6217
  });
6194
6218
  }
6195
6219
  }
6196
- dexieCloud.version = '4.0.1-beta.31';
6220
+ dexieCloud.version = '4.0.1-beta.33';
6197
6221
  Dexie.Cloud = dexieCloud;
6198
6222
 
6199
6223
  export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId };