dexie-cloud-addon 4.0.0-beta.16 → 4.0.0-beta.17

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 (39) hide show
  1. package/dist/modern/dexie-cloud-addon.js +96 -104
  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 +95 -103
  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 +135 -150
  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/umd/dexie-cloud-addon.js +135 -150
  14. package/dist/umd/dexie-cloud-addon.js.map +1 -1
  15. package/dist/umd/dexie-cloud-addon.min.js +1 -1
  16. package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
  17. package/dist/umd/service-worker.js +94 -102
  18. package/dist/umd/service-worker.js.map +1 -1
  19. package/dist/umd/service-worker.min.js +1 -1
  20. package/dist/umd/service-worker.min.js.map +1 -1
  21. package/dist/umd-modern/dexie-cloud-addon.js +92 -100
  22. package/dist/umd-modern/dexie-cloud-addon.js.map +1 -1
  23. package/package.json +1 -1
  24. package/dist/types/DexieCloudEntity.d.ts +0 -8
  25. package/dist/types/WebSocketStatus.d.ts +0 -1
  26. package/dist/types/createMyMembersObservable.d.ts +0 -14
  27. package/dist/types/currentUserObservable.d.ts +0 -3
  28. package/dist/types/helpers/BroadcastedLocalEvent.d.ts +0 -8
  29. package/dist/types/helpers/visibleState.d.ts +0 -1
  30. package/dist/types/permissionsLookup.d.ts +0 -9
  31. package/dist/types/permissionsLookupObservable.d.ts +0 -14
  32. package/dist/types/sync/globalizePrivateIds.d.ts +0 -4
  33. package/dist/types/sync/syncServerToClientOnly.d.ts +0 -3
  34. package/dist/types/types/CloudConnectionStatus.d.ts +0 -0
  35. package/dist/types/types/ConnectionStatus.d.ts +0 -0
  36. package/dist/types/types/LoginState.d.ts +0 -41
  37. package/dist/types/types/SyncConnectionStatus.d.ts +0 -1
  38. package/dist/types/types/SyncFlowStatus.d.ts +0 -6
  39. package/dist/types/types/SyncStatus.d.ts +0 -6
@@ -4649,107 +4649,10 @@
4649
4649
  };
4650
4650
  }
4651
4651
 
4652
- const SECONDS = 1000;
4653
- const MINUTES = 60 * SECONDS;
4654
-
4655
- const myId = randomString$1(16);
4656
-
4657
- const GUARDED_JOB_HEARTBEAT = 1 * SECONDS;
4658
- const GUARDED_JOB_TIMEOUT = 1 * MINUTES;
4659
- async function performGuardedJob(db, jobName, jobsTableName, job, { awaitRemoteJob } = {}) {
4660
- // Start working.
4661
- //
4662
- // Check if someone else is working on this already.
4663
- //
4664
- const jobsTable = db.table(jobsTableName);
4665
- async function aquireLock() {
4666
- const gotTheLock = await db.transaction('rw!', jobsTableName, async () => {
4667
- const currentWork = await jobsTable.get(jobName);
4668
- if (!currentWork) {
4669
- // No one else is working. Let's record that we are.
4670
- await jobsTable.add({
4671
- nodeId: myId,
4672
- started: new Date(),
4673
- heartbeat: new Date()
4674
- }, jobName);
4675
- return true;
4676
- }
4677
- else if (currentWork.heartbeat.getTime() <
4678
- Date.now() - GUARDED_JOB_TIMEOUT) {
4679
- console.warn(`Latest ${jobName} worker seem to have died.\n`, `The dead job started:`, currentWork.started, `\n`, `Last heart beat was:`, currentWork.heartbeat, '\n', `We're now taking over!`);
4680
- // Now, take over!
4681
- await jobsTable.put({
4682
- nodeId: myId,
4683
- started: new Date(),
4684
- heartbeat: new Date()
4685
- }, jobName);
4686
- return true;
4687
- }
4688
- return false;
4689
- });
4690
- if (gotTheLock)
4691
- return true;
4692
- // Someone else took the job.
4693
- if (awaitRemoteJob) {
4694
- try {
4695
- const jobDoneObservable = rxjs.from(Dexie.liveQuery(() => jobsTable.get(jobName))).pipe(timeout(GUARDED_JOB_TIMEOUT), filter((job) => !job)); // Wait til job is not there anymore.
4696
- await jobDoneObservable.toPromise();
4697
- return false;
4698
- }
4699
- catch (err) {
4700
- if (err.name !== 'TimeoutError') {
4701
- throw err;
4702
- }
4703
- // Timeout stopped us! Try aquire the lock now.
4704
- // It will likely succeed this time unless
4705
- // another client took it.
4706
- return await aquireLock();
4707
- }
4708
- }
4709
- return false;
4710
- }
4711
- if (await aquireLock()) {
4712
- // We own the lock entry and can do our job undisturbed.
4713
- // We're not within a transaction, but these type of locks
4714
- // spans over transactions.
4715
- // Start our heart beat during the job.
4716
- // Use setInterval to make sure we are updating heartbeat even during long-lived fetch calls.
4717
- const heartbeat = setInterval(() => {
4718
- jobsTable.update(jobName, (job) => {
4719
- if (job.nodeId === myId) {
4720
- job.heartbeat = new Date();
4721
- }
4722
- });
4723
- }, GUARDED_JOB_HEARTBEAT);
4724
- try {
4725
- return await job();
4726
- }
4727
- finally {
4728
- // Stop heartbeat
4729
- clearInterval(heartbeat);
4730
- // Remove the persisted job state:
4731
- await db.transaction('rw!', jobsTableName, async () => {
4732
- const currentWork = await jobsTable.get(jobName);
4733
- if (currentWork && currentWork.nodeId === myId) {
4734
- jobsTable.delete(jobName);
4735
- }
4736
- });
4737
- }
4738
- }
4739
- }
4740
-
4741
4652
  async function performInitialSync(db, cloudOptions, cloudSchema) {
4742
- console.debug("Performing initial sync");
4743
- await performGuardedJob(db, 'initialSync', '$jobs', async () => {
4744
- // Even though caller has already checked it,
4745
- // Do check again (now within a transaction) that we really do not have a sync state:
4746
- const syncState = await db.getPersistedSyncState();
4747
- if (!syncState?.initiallySynced) {
4748
- await sync(db, cloudOptions, cloudSchema, { isInitialSync: true });
4749
- }
4750
- }, { awaitRemoteJob: true } // Don't return until the job is done!
4751
- );
4752
- console.debug("Done initial sync");
4653
+ console.debug('Performing initial sync');
4654
+ await sync(db, cloudOptions, cloudSchema, { isInitialSync: true });
4655
+ console.debug('Done initial sync');
4753
4656
  }
4754
4657
 
4755
4658
  const USER_INACTIVITY_TIMEOUT = 180000; // 3 minutes
@@ -5103,6 +5006,95 @@
5103
5006
  : false;
5104
5007
  }
5105
5008
 
5009
+ const SECONDS = 1000;
5010
+ const MINUTES = 60 * SECONDS;
5011
+
5012
+ const myId = randomString$1(16);
5013
+
5014
+ const GUARDED_JOB_HEARTBEAT = 1 * SECONDS;
5015
+ const GUARDED_JOB_TIMEOUT = 1 * MINUTES;
5016
+ async function performGuardedJob(db, jobName, jobsTableName, job, { awaitRemoteJob } = {}) {
5017
+ // Start working.
5018
+ //
5019
+ // Check if someone else is working on this already.
5020
+ //
5021
+ const jobsTable = db.table(jobsTableName);
5022
+ async function aquireLock() {
5023
+ const gotTheLock = await db.transaction('rw!', jobsTableName, async () => {
5024
+ const currentWork = await jobsTable.get(jobName);
5025
+ if (!currentWork) {
5026
+ // No one else is working. Let's record that we are.
5027
+ await jobsTable.add({
5028
+ nodeId: myId,
5029
+ started: new Date(),
5030
+ heartbeat: new Date()
5031
+ }, jobName);
5032
+ return true;
5033
+ }
5034
+ else if (currentWork.heartbeat.getTime() <
5035
+ Date.now() - GUARDED_JOB_TIMEOUT) {
5036
+ console.warn(`Latest ${jobName} worker seem to have died.\n`, `The dead job started:`, currentWork.started, `\n`, `Last heart beat was:`, currentWork.heartbeat, '\n', `We're now taking over!`);
5037
+ // Now, take over!
5038
+ await jobsTable.put({
5039
+ nodeId: myId,
5040
+ started: new Date(),
5041
+ heartbeat: new Date()
5042
+ }, jobName);
5043
+ return true;
5044
+ }
5045
+ return false;
5046
+ });
5047
+ if (gotTheLock)
5048
+ return true;
5049
+ // Someone else took the job.
5050
+ if (awaitRemoteJob) {
5051
+ try {
5052
+ const jobDoneObservable = rxjs.from(Dexie.liveQuery(() => jobsTable.get(jobName))).pipe(timeout(GUARDED_JOB_TIMEOUT), filter((job) => !job)); // Wait til job is not there anymore.
5053
+ await jobDoneObservable.toPromise();
5054
+ return false;
5055
+ }
5056
+ catch (err) {
5057
+ if (err.name !== 'TimeoutError') {
5058
+ throw err;
5059
+ }
5060
+ // Timeout stopped us! Try aquire the lock now.
5061
+ // It will likely succeed this time unless
5062
+ // another client took it.
5063
+ return await aquireLock();
5064
+ }
5065
+ }
5066
+ return false;
5067
+ }
5068
+ if (await aquireLock()) {
5069
+ // We own the lock entry and can do our job undisturbed.
5070
+ // We're not within a transaction, but these type of locks
5071
+ // spans over transactions.
5072
+ // Start our heart beat during the job.
5073
+ // Use setInterval to make sure we are updating heartbeat even during long-lived fetch calls.
5074
+ const heartbeat = setInterval(() => {
5075
+ jobsTable.update(jobName, (job) => {
5076
+ if (job.nodeId === myId) {
5077
+ job.heartbeat = new Date();
5078
+ }
5079
+ });
5080
+ }, GUARDED_JOB_HEARTBEAT);
5081
+ try {
5082
+ return await job();
5083
+ }
5084
+ finally {
5085
+ // Stop heartbeat
5086
+ clearInterval(heartbeat);
5087
+ // Remove the persisted job state:
5088
+ await db.transaction('rw!', jobsTableName, async () => {
5089
+ const currentWork = await jobsTable.get(jobName);
5090
+ if (currentWork && currentWork.nodeId === myId) {
5091
+ await jobsTable.delete(jobName);
5092
+ }
5093
+ });
5094
+ }
5095
+ }
5096
+ }
5097
+
5106
5098
  const ongoingSyncs = new WeakMap();
5107
5099
  function syncIfPossible(db, cloudOptions, cloudSchema, options) {
5108
5100
  const ongoing = ongoingSyncs.get(db);
@@ -5794,7 +5786,7 @@
5794
5786
  currentUserEmitter.next(UNAUTHORIZED_USER);
5795
5787
  });
5796
5788
  dexie.cloud = {
5797
- version: '4.0.0-beta.16',
5789
+ version: '4.0.0-beta.17',
5798
5790
  options: { ...DEFAULT_OPTIONS },
5799
5791
  schema: null,
5800
5792
  serverState: null,
@@ -6036,7 +6028,7 @@
6036
6028
  }
6037
6029
  }
6038
6030
  }
6039
- dexieCloud.version = '4.0.0-beta.16';
6031
+ dexieCloud.version = '4.0.0-beta.17';
6040
6032
  Dexie__default["default"].Cloud = dexieCloud;
6041
6033
 
6042
6034
  // In case the SW lives for a while, let it reuse already opened connections: