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
@@ -1,5 +1,5 @@
1
1
  import Dexie, { cmp, liveQuery } from 'dexie';
2
- import { Observable as Observable$1, BehaviorSubject, Subject, fromEvent, of, merge, Subscription as Subscription$1, from as from$1, throwError, combineLatest, map as map$1, share, timer as timer$1, switchMap as switchMap$1 } from 'rxjs';
2
+ import { Observable as Observable$1, BehaviorSubject, Subject, fromEvent, of, merge, Subscription as Subscription$1, from as from$1, throwError, combineLatest, map as map$1, share, timer as timer$1 } from 'rxjs';
3
3
 
4
4
  /******************************************************************************
5
5
  Copyright (c) Microsoft Corporation.
@@ -1934,7 +1934,7 @@ function randomString$1(bytes) {
1934
1934
  }
1935
1935
 
1936
1936
  //@ts-check
1937
- const randomFillSync = crypto.getRandomValues;
1937
+ const randomFillSync = crypto.getRandomValues.bind(crypto);
1938
1938
 
1939
1939
  function assert(b) {
1940
1940
  if (!b)
@@ -1996,17 +1996,17 @@ function setByKeyPath(obj, keyPath, value) {
1996
1996
  }
1997
1997
  }
1998
1998
  }
1999
- const randomString = typeof Buffer !== 'undefined' ? (bytes) => {
2000
- // Node
2001
- const buf = Buffer.alloc(bytes);
2002
- randomFillSync(buf);
2003
- return buf.toString("base64");
2004
- } : (bytes) => {
1999
+ const randomString = typeof self !== 'undefined' && typeof crypto !== 'undefined' ? (bytes) => {
2005
2000
  // Web
2006
2001
  const buf = new Uint8Array(bytes);
2007
2002
  crypto.getRandomValues(buf);
2008
2003
  return btoa(String.fromCharCode.apply(null, buf));
2009
- };
2004
+ } : typeof Buffer !== 'undefined' ? (bytes) => {
2005
+ // Node
2006
+ const buf = Buffer.alloc(bytes);
2007
+ randomFillSync(buf);
2008
+ return buf.toString("base64");
2009
+ } : () => { throw new Error("No implementation of randomString was found"); };
2010
2010
 
2011
2011
  /** Verifies that given primary key is valid.
2012
2012
  * The reason we narrow validity for valid keys are twofold:
@@ -3032,14 +3032,14 @@ var undefinedDef = {
3032
3032
  // serverRev.rev = bigIntDef.bigint.revive(server.rev)
3033
3033
  // else
3034
3034
  // serverRev.rev = new FakeBigInt(server.rev)
3035
- const hasBigIntSupport = typeof BigInt(0) === 'bigint';
3035
+ const hasBigIntSupport = typeof BigInt === 'function' && typeof BigInt(0) === 'bigint';
3036
3036
  class FakeBigInt {
3037
- constructor(value) {
3038
- this.v = value;
3039
- }
3040
3037
  toString() {
3041
3038
  return this.v;
3042
3039
  }
3040
+ constructor(value) {
3041
+ this.v = value;
3042
+ }
3043
3043
  }
3044
3044
  const defs = Object.assign(Object.assign({}, undefinedDef), (hasBigIntSupport
3045
3045
  ? {}
@@ -3910,7 +3910,16 @@ function DexieCloudDB(dx) {
3910
3910
  return db.$syncState.get('syncState');
3911
3911
  },
3912
3912
  getSchema() {
3913
- return db.$syncState.get('schema');
3913
+ return db.$syncState.get('schema').then((schema) => {
3914
+ if (schema) {
3915
+ for (const table of db.tables) {
3916
+ if (table.schema.primKey && table.schema.primKey.keyPath && schema[table.name]) {
3917
+ schema[table.name].primaryKey = nameFromKeyPath(table.schema.primKey.keyPath);
3918
+ }
3919
+ }
3920
+ }
3921
+ return schema;
3922
+ });
3914
3923
  },
3915
3924
  getOptions() {
3916
3925
  return db.$syncState.get('options');
@@ -3928,6 +3937,11 @@ function DexieCloudDB(dx) {
3928
3937
  }
3929
3938
  return db;
3930
3939
  }
3940
+ function nameFromKeyPath(keyPath) {
3941
+ return typeof keyPath === 'string' ?
3942
+ keyPath :
3943
+ keyPath ? ('[' + [].join.call(keyPath, '+') + ']') : "";
3944
+ }
3931
3945
 
3932
3946
  // Emulate true-private property db. Why? So it's not stored in DB.
3933
3947
  const wm = new WeakMap();
@@ -4398,7 +4412,7 @@ function createImplicitPropSetterMiddleware(db) {
4398
4412
  // modify operations. Reason: Server may not have
4399
4413
  // the object. Object should be created on server only
4400
4414
  // if is being updated. An update operation won't create it
4401
- // so we must delete req.changeSpec to decrate operation to
4415
+ // so we must delete req.changeSpec to degrade operation to
4402
4416
  // an upsert operation with timestamp so that it will be created.
4403
4417
  // We must also degrade from consistent modify operations for the
4404
4418
  // same reason - object might be there on server. Must but put up instead.
@@ -4410,7 +4424,7 @@ function createImplicitPropSetterMiddleware(db) {
4410
4424
  if (req.type === 'put') {
4411
4425
  delete req.criteria;
4412
4426
  delete req.changeSpec;
4413
- delete req.changeSpecs;
4427
+ delete req.updates;
4414
4428
  obj.$ts = Date.now();
4415
4429
  }
4416
4430
  }
@@ -4615,11 +4629,10 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
4615
4629
  const { numFailures: hasFailures, failures } = res;
4616
4630
  let keys = type === 'delete' ? req.keys : res.results;
4617
4631
  let values = 'values' in req ? req.values : [];
4618
- let changeSpecs = 'changeSpecs' in req ? req.changeSpecs : [];
4632
+ let updates = 'updates' in req && req.updates;
4619
4633
  if (hasFailures) {
4620
4634
  keys = keys.filter((_, idx) => !failures[idx]);
4621
4635
  values = values.filter((_, idx) => !failures[idx]);
4622
- changeSpecs = changeSpecs.filter((_, idx) => !failures[idx]);
4623
4636
  }
4624
4637
  const ts = Date.now();
4625
4638
  const mut = req.type === 'delete'
@@ -4651,13 +4664,13 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
4651
4664
  txid,
4652
4665
  userId
4653
4666
  }
4654
- : req.changeSpecs
4667
+ : updates
4655
4668
  ? {
4656
4669
  // One changeSpec per key
4657
4670
  type: 'update',
4658
4671
  ts,
4659
- keys,
4660
- changeSpecs,
4672
+ keys: updates.keys,
4673
+ changeSpecs: updates.changeSpecs,
4661
4674
  txid,
4662
4675
  userId
4663
4676
  }
@@ -5838,10 +5851,10 @@ function permissions(dexie, obj, tableName) {
5838
5851
  }
5839
5852
 
5840
5853
  const getInvitesObservable = associate((db) => {
5841
- const membersByEmail = getCurrentUserEmitter(db._novip).pipe(switchMap$1((currentUser) => liveQuery(() => db.members.where({ email: currentUser.email || '' }).toArray())));
5854
+ const membersByEmail = getCurrentUserEmitter(db._novip).pipe(switchMap((currentUser) => liveQuery(() => db.members.where({ email: currentUser.email || '' }).toArray())));
5842
5855
  const permissions = getPermissionsLookupObservable(db._novip);
5843
5856
  const accessControl = getInternalAccessControlObservable(db._novip);
5844
- return createSharedValueObservable(combineLatest([membersByEmail, accessControl, permissions]).pipe(map$1(([membersByEmail, accessControl, realmLookup]) => {
5857
+ return createSharedValueObservable(combineLatest([membersByEmail, accessControl, permissions]).pipe(map(([membersByEmail, accessControl, realmLookup]) => {
5845
5858
  const reducer = (result, m) => (Object.assign(Object.assign({}, result), { [m.id]: Object.assign(Object.assign({}, m), { realm: realmLookup[m.realmId] }) }));
5846
5859
  const emailMembersById = membersByEmail.reduce(reducer, {});
5847
5860
  const membersById = accessControl.selfMembers.reduce(reducer, emailMembersById);
@@ -5897,7 +5910,7 @@ function dexieCloud(dexie) {
5897
5910
  currentUserEmitter.next(UNAUTHORIZED_USER);
5898
5911
  });
5899
5912
  dexie.cloud = {
5900
- version: '4.0.0-beta.24',
5913
+ version: '4.0.1-beta.27',
5901
5914
  options: Object.assign({}, DEFAULT_OPTIONS),
5902
5915
  schema: null,
5903
5916
  get currentUserId() {
@@ -6027,7 +6040,9 @@ function dexieCloud(dexie) {
6027
6040
  // Update persisted options:
6028
6041
  if (!options)
6029
6042
  throw new Error(`Internal error`); // options cannot be null if configuredProgramatically is set.
6030
- yield db.$syncState.put(options, 'options');
6043
+ const newPersistedOptions = Object.assign({}, options);
6044
+ delete newPersistedOptions.fetchTokens;
6045
+ yield db.$syncState.put(newPersistedOptions, 'options');
6031
6046
  }
6032
6047
  if (((_h = db.cloud.options) === null || _h === void 0 ? void 0 : _h.tryUseServiceWorker) &&
6033
6048
  'serviceWorker' in navigator &&
@@ -6150,7 +6165,7 @@ function dexieCloud(dexie) {
6150
6165
  });
6151
6166
  }
6152
6167
  }
6153
- dexieCloud.version = '4.0.0-beta.24';
6168
+ dexieCloud.version = '4.0.1-beta.27';
6154
6169
  Dexie.Cloud = dexieCloud;
6155
6170
 
6156
6171
  // In case the SW lives for a while, let it reuse already opened connections: