dexie-cloud-addon 4.0.0-beta.24 → 4.0.1-beta.27

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 (40) hide show
  1. package/dist/modern/dexie-cloud-addon.js +42 -27
  2. package/dist/modern/dexie-cloud-addon.js.map +1 -1
  3. package/dist/modern/dexie-cloud-addon.min.js +1 -1
  4. package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
  5. package/dist/modern/service-worker.js +41 -26
  6. package/dist/modern/service-worker.js.map +1 -1
  7. package/dist/modern/service-worker.min.js +1 -1
  8. package/dist/modern/service-worker.min.js.map +1 -1
  9. package/dist/module-es5/dexie-cloud-addon.js +41 -25
  10. package/dist/module-es5/dexie-cloud-addon.js.map +1 -1
  11. package/dist/module-es5/dexie-cloud-addon.min.js +1 -1
  12. package/dist/module-es5/dexie-cloud-addon.min.js.map +1 -1
  13. package/dist/types/DXCWebSocketStatus.d.ts +1 -1
  14. package/dist/types/DexieCloudTable.d.ts +18 -2
  15. package/dist/types/PermissionChecker.d.ts +1 -1
  16. package/dist/types/TSON.d.ts +1 -1
  17. package/dist/types/WSObservable.d.ts +2 -2
  18. package/dist/types/authentication/authenticate.d.ts +1 -1
  19. package/dist/types/db/DexieCloudDB.d.ts +1 -1
  20. package/dist/types/extend-dexie-interface.d.ts +5 -3
  21. package/dist/types/getInternalAccessControlObservable.d.ts +1 -1
  22. package/dist/types/getPermissionsLookupObservable.d.ts +2 -2
  23. package/dist/types/sync/getTablesToSyncify.d.ts +1 -1
  24. package/dist/types/sync/messagesFromServerQueue.d.ts +1 -1
  25. package/dist/types/types/DXCAlert.d.ts +1 -1
  26. package/dist/types/types/DXCInputField.d.ts +1 -1
  27. package/dist/types/types/DXCUserInteraction.d.ts +1 -1
  28. package/dist/types/types/SWSyncEvent.d.ts +1 -1
  29. package/dist/types/types/SyncState.d.ts +2 -2
  30. package/dist/umd/dexie-cloud-addon.js +40 -24
  31. package/dist/umd/dexie-cloud-addon.js.map +1 -1
  32. package/dist/umd/dexie-cloud-addon.min.js +1 -1
  33. package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
  34. package/dist/umd/service-worker.js +40 -25
  35. package/dist/umd/service-worker.js.map +1 -1
  36. package/dist/umd/service-worker.min.js +1 -1
  37. package/dist/umd/service-worker.min.js.map +1 -1
  38. package/dist/umd-modern/dexie-cloud-addon.js +38 -23
  39. package/dist/umd-modern/dexie-cloud-addon.js.map +1 -1
  40. package/package.json +5 -6
@@ -1941,7 +1941,7 @@
1941
1941
  }
1942
1942
 
1943
1943
  //@ts-check
1944
- const randomFillSync = crypto.getRandomValues;
1944
+ const randomFillSync = crypto.getRandomValues.bind(crypto);
1945
1945
 
1946
1946
  function assert(b) {
1947
1947
  if (!b)
@@ -2003,17 +2003,17 @@
2003
2003
  }
2004
2004
  }
2005
2005
  }
2006
- const randomString = typeof Buffer !== 'undefined' ? (bytes) => {
2007
- // Node
2008
- const buf = Buffer.alloc(bytes);
2009
- randomFillSync(buf);
2010
- return buf.toString("base64");
2011
- } : (bytes) => {
2006
+ const randomString = typeof self !== 'undefined' && typeof crypto !== 'undefined' ? (bytes) => {
2012
2007
  // Web
2013
2008
  const buf = new Uint8Array(bytes);
2014
2009
  crypto.getRandomValues(buf);
2015
2010
  return btoa(String.fromCharCode.apply(null, buf));
2016
- };
2011
+ } : typeof Buffer !== 'undefined' ? (bytes) => {
2012
+ // Node
2013
+ const buf = Buffer.alloc(bytes);
2014
+ randomFillSync(buf);
2015
+ return buf.toString("base64");
2016
+ } : () => { throw new Error("No implementation of randomString was found"); };
2017
2017
 
2018
2018
  /** Verifies that given primary key is valid.
2019
2019
  * The reason we narrow validity for valid keys are twofold:
@@ -3039,14 +3039,14 @@
3039
3039
  // serverRev.rev = bigIntDef.bigint.revive(server.rev)
3040
3040
  // else
3041
3041
  // serverRev.rev = new FakeBigInt(server.rev)
3042
- const hasBigIntSupport = typeof BigInt(0) === 'bigint';
3042
+ const hasBigIntSupport = typeof BigInt === 'function' && typeof BigInt(0) === 'bigint';
3043
3043
  class FakeBigInt {
3044
- constructor(value) {
3045
- this.v = value;
3046
- }
3047
3044
  toString() {
3048
3045
  return this.v;
3049
3046
  }
3047
+ constructor(value) {
3048
+ this.v = value;
3049
+ }
3050
3050
  }
3051
3051
  const defs = Object.assign(Object.assign({}, undefinedDef), (hasBigIntSupport
3052
3052
  ? {}
@@ -3917,7 +3917,16 @@
3917
3917
  return db.$syncState.get('syncState');
3918
3918
  },
3919
3919
  getSchema() {
3920
- return db.$syncState.get('schema');
3920
+ return db.$syncState.get('schema').then((schema) => {
3921
+ if (schema) {
3922
+ for (const table of db.tables) {
3923
+ if (table.schema.primKey && table.schema.primKey.keyPath && schema[table.name]) {
3924
+ schema[table.name].primaryKey = nameFromKeyPath(table.schema.primKey.keyPath);
3925
+ }
3926
+ }
3927
+ }
3928
+ return schema;
3929
+ });
3921
3930
  },
3922
3931
  getOptions() {
3923
3932
  return db.$syncState.get('options');
@@ -3935,6 +3944,11 @@
3935
3944
  }
3936
3945
  return db;
3937
3946
  }
3947
+ function nameFromKeyPath(keyPath) {
3948
+ return typeof keyPath === 'string' ?
3949
+ keyPath :
3950
+ keyPath ? ('[' + [].join.call(keyPath, '+') + ']') : "";
3951
+ }
3938
3952
 
3939
3953
  // Emulate true-private property db. Why? So it's not stored in DB.
3940
3954
  const wm = new WeakMap();
@@ -4405,7 +4419,7 @@
4405
4419
  // modify operations. Reason: Server may not have
4406
4420
  // the object. Object should be created on server only
4407
4421
  // if is being updated. An update operation won't create it
4408
- // so we must delete req.changeSpec to decrate operation to
4422
+ // so we must delete req.changeSpec to degrade operation to
4409
4423
  // an upsert operation with timestamp so that it will be created.
4410
4424
  // We must also degrade from consistent modify operations for the
4411
4425
  // same reason - object might be there on server. Must but put up instead.
@@ -4417,7 +4431,7 @@
4417
4431
  if (req.type === 'put') {
4418
4432
  delete req.criteria;
4419
4433
  delete req.changeSpec;
4420
- delete req.changeSpecs;
4434
+ delete req.updates;
4421
4435
  obj.$ts = Date.now();
4422
4436
  }
4423
4437
  }
@@ -4622,11 +4636,10 @@
4622
4636
  const { numFailures: hasFailures, failures } = res;
4623
4637
  let keys = type === 'delete' ? req.keys : res.results;
4624
4638
  let values = 'values' in req ? req.values : [];
4625
- let changeSpecs = 'changeSpecs' in req ? req.changeSpecs : [];
4639
+ let updates = 'updates' in req && req.updates;
4626
4640
  if (hasFailures) {
4627
4641
  keys = keys.filter((_, idx) => !failures[idx]);
4628
4642
  values = values.filter((_, idx) => !failures[idx]);
4629
- changeSpecs = changeSpecs.filter((_, idx) => !failures[idx]);
4630
4643
  }
4631
4644
  const ts = Date.now();
4632
4645
  const mut = req.type === 'delete'
@@ -4658,13 +4671,13 @@
4658
4671
  txid,
4659
4672
  userId
4660
4673
  }
4661
- : req.changeSpecs
4674
+ : updates
4662
4675
  ? {
4663
4676
  // One changeSpec per key
4664
4677
  type: 'update',
4665
4678
  ts,
4666
- keys,
4667
- changeSpecs,
4679
+ keys: updates.keys,
4680
+ changeSpecs: updates.changeSpecs,
4668
4681
  txid,
4669
4682
  userId
4670
4683
  }
@@ -5845,10 +5858,10 @@
5845
5858
  }
5846
5859
 
5847
5860
  const getInvitesObservable = associate((db) => {
5848
- const membersByEmail = getCurrentUserEmitter(db._novip).pipe(rxjs.switchMap((currentUser) => Dexie.liveQuery(() => db.members.where({ email: currentUser.email || '' }).toArray())));
5861
+ const membersByEmail = getCurrentUserEmitter(db._novip).pipe(switchMap((currentUser) => Dexie.liveQuery(() => db.members.where({ email: currentUser.email || '' }).toArray())));
5849
5862
  const permissions = getPermissionsLookupObservable(db._novip);
5850
5863
  const accessControl = getInternalAccessControlObservable(db._novip);
5851
- return createSharedValueObservable(rxjs.combineLatest([membersByEmail, accessControl, permissions]).pipe(rxjs.map(([membersByEmail, accessControl, realmLookup]) => {
5864
+ return createSharedValueObservable(rxjs.combineLatest([membersByEmail, accessControl, permissions]).pipe(map(([membersByEmail, accessControl, realmLookup]) => {
5852
5865
  const reducer = (result, m) => (Object.assign(Object.assign({}, result), { [m.id]: Object.assign(Object.assign({}, m), { realm: realmLookup[m.realmId] }) }));
5853
5866
  const emailMembersById = membersByEmail.reduce(reducer, {});
5854
5867
  const membersById = accessControl.selfMembers.reduce(reducer, emailMembersById);
@@ -5904,7 +5917,7 @@
5904
5917
  currentUserEmitter.next(UNAUTHORIZED_USER);
5905
5918
  });
5906
5919
  dexie.cloud = {
5907
- version: '4.0.0-beta.24',
5920
+ version: '4.0.1-beta.27',
5908
5921
  options: Object.assign({}, DEFAULT_OPTIONS),
5909
5922
  schema: null,
5910
5923
  get currentUserId() {
@@ -6034,7 +6047,9 @@
6034
6047
  // Update persisted options:
6035
6048
  if (!options)
6036
6049
  throw new Error(`Internal error`); // options cannot be null if configuredProgramatically is set.
6037
- yield db.$syncState.put(options, 'options');
6050
+ const newPersistedOptions = Object.assign({}, options);
6051
+ delete newPersistedOptions.fetchTokens;
6052
+ yield db.$syncState.put(newPersistedOptions, 'options');
6038
6053
  }
6039
6054
  if (((_h = db.cloud.options) === null || _h === void 0 ? void 0 : _h.tryUseServiceWorker) &&
6040
6055
  'serviceWorker' in navigator &&
@@ -6157,7 +6172,7 @@
6157
6172
  });
6158
6173
  }
6159
6174
  }
6160
- dexieCloud.version = '4.0.0-beta.24';
6175
+ dexieCloud.version = '4.0.1-beta.27';
6161
6176
  Dexie__default["default"].Cloud = dexieCloud;
6162
6177
 
6163
6178
  // In case the SW lives for a while, let it reuse already opened connections: