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

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.
@@ -158,9 +158,6 @@
158
158
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
159
159
  }
160
160
 
161
- //@ts-check
162
- const randomFillSync = crypto.getRandomValues.bind(crypto);
163
-
164
161
  function assert(b) {
165
162
  if (!b)
166
163
  throw new Error('Assertion Failed');
@@ -221,17 +218,22 @@
221
218
  }
222
219
  }
223
220
  }
224
- const randomString$1 = typeof self !== 'undefined' && typeof crypto !== 'undefined' ? (bytes) => {
221
+ const randomString$1 = typeof self !== 'undefined' && typeof crypto !== 'undefined' ? (bytes, randomFill = crypto.getRandomValues.bind(crypto)) => {
225
222
  // Web
226
223
  const buf = new Uint8Array(bytes);
227
- crypto.getRandomValues(buf);
228
- return btoa(String.fromCharCode.apply(null, buf));
229
- } : typeof Buffer !== 'undefined' ? (bytes) => {
224
+ randomFill(buf);
225
+ return self.btoa(String.fromCharCode.apply(null, buf));
226
+ } : typeof Buffer !== 'undefined' ? (bytes, randomFill = simpleRandomFill) => {
230
227
  // Node
231
228
  const buf = Buffer.alloc(bytes);
232
- randomFillSync(buf);
229
+ randomFill(buf);
233
230
  return buf.toString("base64");
234
231
  } : () => { throw new Error("No implementation of randomString was found"); };
232
+ function simpleRandomFill(buf) {
233
+ for (let i = 0; i < buf.length; ++i) {
234
+ buf[i] = Math.floor(Math.random() * 256);
235
+ }
236
+ }
235
237
 
236
238
  /** Verifies that given primary key is valid.
237
239
  * The reason we narrow validity for valid keys are twofold:
@@ -395,9 +397,10 @@
395
397
  * @param inSet
396
398
  * @returns DBOperationsSet representing inSet
397
399
  */
398
- function toDBOperationSet(inSet) {
400
+ function toDBOperationSet(inSet, txid = "") {
399
401
  // Fictive transaction:
400
- const txid = randomString$1(16);
402
+ if (!txid)
403
+ txid = randomString$1(16);
401
404
  // Convert data into a temporary map to collect mutations of same table and type
402
405
  const map = {};
403
406
  for (const [table, ops] of Object.entries(inSet)) {
@@ -2536,7 +2539,7 @@
2536
2539
  catch (_a) { }
2537
2540
 
2538
2541
  const swHolder = {};
2539
- const swContainer = self.document && navigator.serviceWorker; // self.document is to verify we're not the SW ourself
2542
+ const swContainer = typeof self !== undefined && self.document && navigator.serviceWorker; // self.document is to verify we're not the SW ourself
2540
2543
  if (swContainer)
2541
2544
  swContainer.ready.then((registration) => (swHolder.registration = registration));
2542
2545
  if (typeof self !== 'undefined' && 'clients' in self && !self.document) {
@@ -2570,7 +2573,7 @@
2570
2573
  // We're a service worker. Propagate to our browser clients.
2571
2574
  [...self['clients'].matchAll({ includeUncontrolled: true })].forEach((client) => client.postMessage({
2572
2575
  type: `sw-broadcast-${this.name}`,
2573
- message
2576
+ message,
2574
2577
  }));
2575
2578
  }
2576
2579
  else if (swHolder.registration) {
@@ -2578,7 +2581,7 @@
2578
2581
  // Post to SW so it can repost to all its clients and to itself
2579
2582
  (_a = swHolder.registration.active) === null || _a === void 0 ? void 0 : _a.postMessage({
2580
2583
  type: `sw-broadcast-${this.name}`,
2581
- message
2584
+ message,
2582
2585
  });
2583
2586
  }
2584
2587
  }
@@ -3187,7 +3190,7 @@
3187
3190
  ...MapDef,
3188
3191
  ...TypedArraysDefs,
3189
3192
  ...ArrayBufferDef,
3190
- ...BlobDef,
3193
+ ...BlobDef, // Should be moved to another preset for DOM types (or universal? since it supports node as well with FakeBlob)
3191
3194
  };
3192
3195
 
3193
3196
  function Bison(...typeDefsInputs) {