dexie-cloud-addon 4.0.1-beta.46 → 4.0.1-beta.48
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.
- package/dist/{types → modern}/DexieCloudAPI.d.ts +3 -0
- package/dist/{types → modern}/DexieCloudOptions.d.ts +1 -0
- package/dist/modern/InvalidLicenseError.d.ts +5 -0
- package/dist/{types → modern}/TSON.d.ts +1 -1
- package/dist/modern/authentication/TokenErrorResponseError.d.ts +10 -0
- package/dist/{types → modern}/authentication/authenticate.d.ts +3 -3
- package/dist/{types → modern}/authentication/interactWithUser.d.ts +3 -0
- package/dist/modern/authentication/logout.d.ts +5 -0
- package/dist/modern/authentication/waitUntil.d.ts +3 -0
- package/dist/{types → modern}/currentUserEmitter.d.ts +1 -1
- package/dist/{types → modern}/db/entities/UserLogin.d.ts +6 -0
- package/dist/modern/default-ui/LoginDialog.d.ts +3 -0
- package/dist/modern/dexie-cloud-addon.d.ts +3 -0
- package/dist/modern/dexie-cloud-addon.js +488 -367
- package/dist/modern/dexie-cloud-addon.js.map +1 -1
- package/dist/modern/dexie-cloud-addon.min.js +2 -2
- package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
- package/dist/{types → modern}/dexie-cloud-client.d.ts +2 -0
- package/dist/modern/helpers/resolveText.d.ts +16 -0
- package/dist/modern/isEagerSyncDisabled.d.ts +2 -0
- package/dist/{types → modern}/middlewares/createMutationTrackingMiddleware.d.ts +1 -1
- package/dist/modern/prodLog.d.ts +9 -0
- package/dist/modern/service-worker.js +2027 -268
- package/dist/modern/service-worker.js.map +1 -1
- package/dist/modern/service-worker.min.js +2 -2
- package/dist/modern/service-worker.min.js.map +1 -1
- package/dist/modern/sync/performGuardedJob.d.ts +2 -0
- package/dist/modern/sync/ratelimit.d.ts +3 -0
- package/dist/{types → modern}/sync/sync.d.ts +0 -1
- package/dist/{types → modern}/types/DXCAlert.d.ts +1 -1
- package/dist/{types → modern}/types/DXCUserInteraction.d.ts +40 -2
- package/dist/{types → modern}/types/SyncState.d.ts +1 -0
- package/dist/umd/DISABLE_SERVICEWORKER_STRATEGY.d.ts +1 -0
- package/dist/umd/DXCWebSocketStatus.d.ts +1 -0
- package/dist/umd/DexieCloudAPI.d.ts +72 -0
- package/dist/umd/DexieCloudOptions.d.ts +22 -0
- package/dist/umd/DexieCloudSyncOptions.d.ts +4 -0
- package/dist/umd/DexieCloudTable.d.ts +18 -0
- package/dist/umd/InvalidLicenseError.d.ts +5 -0
- package/dist/umd/Invite.d.ts +8 -0
- package/dist/umd/PermissionChecker.d.ts +15 -0
- package/dist/umd/TSON.d.ts +17 -0
- package/dist/umd/WSObservable.d.ts +68 -0
- package/dist/umd/associate.d.ts +1 -0
- package/dist/umd/authentication/AuthPersistedContext.d.ts +9 -0
- package/dist/umd/authentication/TokenErrorResponseError.d.ts +10 -0
- package/dist/umd/authentication/TokenExpiredError.d.ts +3 -0
- package/dist/umd/authentication/UNAUTHORIZED_USER.d.ts +2 -0
- package/dist/umd/authentication/authenticate.d.ts +20 -0
- package/dist/umd/authentication/currentUserObservable.d.ts +1 -0
- package/dist/umd/authentication/interactWithUser.d.ts +21 -0
- package/dist/umd/authentication/login.d.ts +6 -0
- package/dist/umd/authentication/logout.d.ts +5 -0
- package/dist/umd/authentication/otpFetchTokenCallback.d.ts +3 -0
- package/dist/umd/authentication/setCurrentUser.d.ts +14 -0
- package/dist/umd/authentication/waitUntil.d.ts +3 -0
- package/dist/umd/computeSyncState.d.ts +4 -0
- package/dist/umd/createSharedValueObservable.d.ts +3 -0
- package/dist/umd/currentUserEmitter.d.ts +3 -0
- package/dist/umd/db/DexieCloudDB.d.ts +59 -0
- package/dist/umd/db/entities/BaseRevisionMapEntry.d.ts +5 -0
- package/dist/umd/db/entities/EntityCommon.d.ts +5 -0
- package/dist/umd/db/entities/GuardedJob.d.ts +5 -0
- package/dist/umd/db/entities/Member.d.ts +19 -0
- package/dist/umd/db/entities/PersistedSyncState.d.ts +14 -0
- package/dist/umd/db/entities/Realm.d.ts +16 -0
- package/dist/umd/db/entities/Role.d.ts +11 -0
- package/dist/umd/db/entities/UserLogin.d.ts +22 -0
- package/dist/umd/default-ui/Dialog.d.ts +5 -0
- package/dist/umd/default-ui/LoginDialog.d.ts +3 -0
- package/dist/umd/default-ui/Styles.d.ts +3 -0
- package/dist/umd/default-ui/index.d.ts +24 -0
- package/dist/umd/dexie-cloud-addon.d.ts +3 -0
- package/dist/umd/dexie-cloud-addon.js +505 -388
- package/dist/umd/dexie-cloud-addon.js.map +1 -1
- package/dist/umd/dexie-cloud-client.d.ts +13 -0
- package/dist/umd/errors/HttpError.d.ts +5 -0
- package/dist/umd/extend-dexie-interface.d.ts +23 -0
- package/dist/umd/getGlobalRolesObservable.d.ts +5 -0
- package/dist/umd/getInternalAccessControlObservable.d.ts +12 -0
- package/dist/umd/getInvitesObservable.d.ts +23 -0
- package/dist/umd/getPermissionsLookupObservable.d.ts +16 -0
- package/dist/umd/getTiedRealmId.d.ts +2 -0
- package/dist/umd/helpers/BroadcastedAndLocalEvent.d.ts +8 -0
- package/dist/umd/helpers/CancelToken.d.ts +4 -0
- package/dist/umd/helpers/IS_SERVICE_WORKER.d.ts +1 -0
- package/dist/umd/helpers/SWBroadcastChannel.d.ts +12 -0
- package/dist/umd/helpers/allSettled.d.ts +1 -0
- package/dist/umd/helpers/bulkUpdate.d.ts +4 -0
- package/dist/umd/helpers/computeRealmSetHash.d.ts +2 -0
- package/dist/umd/helpers/date-constants.d.ts +5 -0
- package/dist/umd/helpers/dbOnClosed.d.ts +2 -0
- package/dist/umd/helpers/flatten.d.ts +1 -0
- package/dist/umd/helpers/getMutationTable.d.ts +1 -0
- package/dist/umd/helpers/getSyncableTables.d.ts +4 -0
- package/dist/umd/helpers/getTableFromMutationTable.d.ts +1 -0
- package/dist/umd/helpers/makeArray.d.ts +1 -0
- package/dist/umd/helpers/randomString.d.ts +1 -0
- package/dist/umd/helpers/resolveText.d.ts +16 -0
- package/dist/umd/helpers/throwVersionIncrementNeeded.d.ts +1 -0
- package/dist/umd/helpers/visibilityState.d.ts +1 -0
- package/dist/umd/isEagerSyncDisabled.d.ts +2 -0
- package/dist/umd/isFirefox.d.ts +1 -0
- package/dist/umd/isSafari.d.ts +2 -0
- package/dist/umd/mapValueObservable.d.ts +5 -0
- package/dist/umd/mergePermissions.d.ts +2 -0
- package/dist/umd/middleware-helpers/guardedTable.d.ts +11 -0
- package/dist/umd/middleware-helpers/idGenerationHelpers.d.ts +18 -0
- package/dist/umd/middlewares/createIdGenerationMiddleware.d.ts +3 -0
- package/dist/umd/middlewares/createImplicitPropSetterMiddleware.d.ts +3 -0
- package/dist/umd/middlewares/createMutationTrackingMiddleware.d.ts +17 -0
- package/dist/umd/middlewares/outstandingTransaction.d.ts +4 -0
- package/dist/umd/overrideParseStoresSpec.d.ts +4 -0
- package/dist/umd/performInitialSync.d.ts +4 -0
- package/dist/umd/permissions.d.ts +9 -0
- package/dist/umd/prodLog.d.ts +9 -0
- package/dist/umd/service-worker.d.ts +1 -0
- package/dist/umd/service-worker.js +2078 -322
- package/dist/umd/service-worker.js.map +1 -1
- package/dist/umd/sync/LocalSyncWorker.d.ts +7 -0
- package/dist/umd/sync/SyncRequiredError.d.ts +3 -0
- package/dist/umd/sync/applyServerChanges.d.ts +3 -0
- package/dist/umd/sync/connectWebSocket.d.ts +2 -0
- package/dist/umd/sync/encodeIdsForServer.d.ts +4 -0
- package/dist/umd/sync/extractRealm.d.ts +2 -0
- package/dist/umd/sync/getLatestRevisionsPerTable.d.ts +6 -0
- package/dist/umd/sync/getTablesToSyncify.d.ts +3 -0
- package/dist/umd/sync/isOnline.d.ts +1 -0
- package/dist/umd/sync/isSyncNeeded.d.ts +2 -0
- package/dist/umd/sync/listClientChanges.d.ts +9 -0
- package/dist/umd/sync/listSyncifiedChanges.d.ts +5 -0
- package/dist/umd/sync/messageConsumerIsReady.d.ts +2 -0
- package/dist/umd/sync/messagesFromServerQueue.d.ts +8 -0
- package/dist/umd/sync/modifyLocalObjectsWithNewUserId.d.ts +4 -0
- package/dist/umd/sync/myId.d.ts +1 -0
- package/dist/umd/sync/numUnsyncedMutations.d.ts +2 -0
- package/dist/umd/sync/old_startSyncingClientChanges.d.ts +39 -0
- package/dist/umd/sync/performGuardedJob.d.ts +2 -0
- package/dist/umd/sync/ratelimit.d.ts +3 -0
- package/dist/umd/sync/registerSyncEvent.d.ts +3 -0
- package/dist/umd/sync/sync.d.ts +15 -0
- package/dist/umd/sync/syncIfPossible.d.ts +5 -0
- package/dist/umd/sync/syncWithServer.d.ts +6 -0
- package/dist/umd/sync/triggerSync.d.ts +2 -0
- package/dist/umd/sync/updateBaseRevs.d.ts +5 -0
- package/dist/umd/types/DXCAlert.d.ts +25 -0
- package/dist/umd/types/DXCInputField.d.ts +11 -0
- package/dist/umd/types/DXCUserInteraction.d.ts +93 -0
- package/dist/umd/types/NewIdOptions.d.ts +3 -0
- package/dist/umd/types/SWMessageEvent.d.ts +3 -0
- package/dist/umd/types/SWSyncEvent.d.ts +4 -0
- package/dist/umd/types/SyncState.d.ts +9 -0
- package/dist/umd/types/TXExpandos.d.ts +11 -0
- package/dist/umd/updateSchemaFromOptions.d.ts +3 -0
- package/dist/umd/userIsActive.d.ts +7 -0
- package/dist/umd/verifyConfig.d.ts +2 -0
- package/dist/umd/verifySchema.d.ts +2 -0
- package/package.json +14 -48
- package/LICENSE +0 -202
- package/copydts.sh +0 -5
- package/dist/types/default-ui/LoginDialog.d.ts +0 -6
- package/dist/types/helpers/resolveText.d.ts +0 -2
- package/dist/types/sync/performGuardedJob.d.ts +0 -4
- package/dist/umd/dexie-cloud-addon.min.js +0 -2
- package/dist/umd/dexie-cloud-addon.min.js.map +0 -1
- package/dist/umd/service-worker.min.js +0 -2
- package/dist/umd/service-worker.min.js.map +0 -1
- /package/dist/{types → modern}/DISABLE_SERVICEWORKER_STRATEGY.d.ts +0 -0
- /package/dist/{types → modern}/DXCWebSocketStatus.d.ts +0 -0
- /package/dist/{types → modern}/DexieCloudSyncOptions.d.ts +0 -0
- /package/dist/{types → modern}/DexieCloudTable.d.ts +0 -0
- /package/dist/{types → modern}/Invite.d.ts +0 -0
- /package/dist/{types → modern}/PermissionChecker.d.ts +0 -0
- /package/dist/{types → modern}/WSObservable.d.ts +0 -0
- /package/dist/{types → modern}/associate.d.ts +0 -0
- /package/dist/{types → modern}/authentication/AuthPersistedContext.d.ts +0 -0
- /package/dist/{types → modern}/authentication/TokenExpiredError.d.ts +0 -0
- /package/dist/{types → modern}/authentication/UNAUTHORIZED_USER.d.ts +0 -0
- /package/dist/{types → modern}/authentication/currentUserObservable.d.ts +0 -0
- /package/dist/{types → modern}/authentication/login.d.ts +0 -0
- /package/dist/{types → modern}/authentication/otpFetchTokenCallback.d.ts +0 -0
- /package/dist/{types → modern}/authentication/setCurrentUser.d.ts +0 -0
- /package/dist/{types → modern}/computeSyncState.d.ts +0 -0
- /package/dist/{types → modern}/createSharedValueObservable.d.ts +0 -0
- /package/dist/{types → modern}/db/DexieCloudDB.d.ts +0 -0
- /package/dist/{types → modern}/db/entities/BaseRevisionMapEntry.d.ts +0 -0
- /package/dist/{types → modern}/db/entities/EntityCommon.d.ts +0 -0
- /package/dist/{types → modern}/db/entities/GuardedJob.d.ts +0 -0
- /package/dist/{types → modern}/db/entities/Member.d.ts +0 -0
- /package/dist/{types → modern}/db/entities/PersistedSyncState.d.ts +0 -0
- /package/dist/{types → modern}/db/entities/Realm.d.ts +0 -0
- /package/dist/{types → modern}/db/entities/Role.d.ts +0 -0
- /package/dist/{types → modern}/default-ui/Dialog.d.ts +0 -0
- /package/dist/{types → modern}/default-ui/Styles.d.ts +0 -0
- /package/dist/{types → modern}/default-ui/index.d.ts +0 -0
- /package/dist/{types → modern}/errors/HttpError.d.ts +0 -0
- /package/dist/{types → modern}/extend-dexie-interface.d.ts +0 -0
- /package/dist/{types → modern}/getGlobalRolesObservable.d.ts +0 -0
- /package/dist/{types → modern}/getInternalAccessControlObservable.d.ts +0 -0
- /package/dist/{types → modern}/getInvitesObservable.d.ts +0 -0
- /package/dist/{types → modern}/getPermissionsLookupObservable.d.ts +0 -0
- /package/dist/{types → modern}/getTiedRealmId.d.ts +0 -0
- /package/dist/{types → modern}/helpers/BroadcastedAndLocalEvent.d.ts +0 -0
- /package/dist/{types → modern}/helpers/CancelToken.d.ts +0 -0
- /package/dist/{types → modern}/helpers/IS_SERVICE_WORKER.d.ts +0 -0
- /package/dist/{types → modern}/helpers/SWBroadcastChannel.d.ts +0 -0
- /package/dist/{types → modern}/helpers/allSettled.d.ts +0 -0
- /package/dist/{types → modern}/helpers/bulkUpdate.d.ts +0 -0
- /package/dist/{types → modern}/helpers/computeRealmSetHash.d.ts +0 -0
- /package/dist/{types → modern}/helpers/date-constants.d.ts +0 -0
- /package/dist/{types → modern}/helpers/dbOnClosed.d.ts +0 -0
- /package/dist/{types → modern}/helpers/flatten.d.ts +0 -0
- /package/dist/{types → modern}/helpers/getMutationTable.d.ts +0 -0
- /package/dist/{types → modern}/helpers/getSyncableTables.d.ts +0 -0
- /package/dist/{types → modern}/helpers/getTableFromMutationTable.d.ts +0 -0
- /package/dist/{types → modern}/helpers/makeArray.d.ts +0 -0
- /package/dist/{types → modern}/helpers/randomString.d.ts +0 -0
- /package/dist/{types → modern}/helpers/throwVersionIncrementNeeded.d.ts +0 -0
- /package/dist/{types → modern}/helpers/visibilityState.d.ts +0 -0
- /package/dist/{types → modern}/isFirefox.d.ts +0 -0
- /package/dist/{types → modern}/isSafari.d.ts +0 -0
- /package/dist/{types → modern}/mapValueObservable.d.ts +0 -0
- /package/dist/{types → modern}/mergePermissions.d.ts +0 -0
- /package/dist/{types → modern}/middleware-helpers/guardedTable.d.ts +0 -0
- /package/dist/{types → modern}/middleware-helpers/idGenerationHelpers.d.ts +0 -0
- /package/dist/{types → modern}/middlewares/createIdGenerationMiddleware.d.ts +0 -0
- /package/dist/{types → modern}/middlewares/createImplicitPropSetterMiddleware.d.ts +0 -0
- /package/dist/{types → modern}/middlewares/outstandingTransaction.d.ts +0 -0
- /package/dist/{types → modern}/overrideParseStoresSpec.d.ts +0 -0
- /package/dist/{types → modern}/performInitialSync.d.ts +0 -0
- /package/dist/{types → modern}/permissions.d.ts +0 -0
- /package/dist/{types → modern}/service-worker.d.ts +0 -0
- /package/dist/{types → modern}/sync/LocalSyncWorker.d.ts +0 -0
- /package/dist/{types → modern}/sync/SyncRequiredError.d.ts +0 -0
- /package/dist/{types → modern}/sync/applyServerChanges.d.ts +0 -0
- /package/dist/{types → modern}/sync/connectWebSocket.d.ts +0 -0
- /package/dist/{types → modern}/sync/encodeIdsForServer.d.ts +0 -0
- /package/dist/{types → modern}/sync/extractRealm.d.ts +0 -0
- /package/dist/{types → modern}/sync/getLatestRevisionsPerTable.d.ts +0 -0
- /package/dist/{types → modern}/sync/getTablesToSyncify.d.ts +0 -0
- /package/dist/{types → modern}/sync/isOnline.d.ts +0 -0
- /package/dist/{types → modern}/sync/isSyncNeeded.d.ts +0 -0
- /package/dist/{types → modern}/sync/listClientChanges.d.ts +0 -0
- /package/dist/{types → modern}/sync/listSyncifiedChanges.d.ts +0 -0
- /package/dist/{types → modern}/sync/messageConsumerIsReady.d.ts +0 -0
- /package/dist/{types → modern}/sync/messagesFromServerQueue.d.ts +0 -0
- /package/dist/{types → modern}/sync/modifyLocalObjectsWithNewUserId.d.ts +0 -0
- /package/dist/{types → modern}/sync/myId.d.ts +0 -0
- /package/dist/{types → modern}/sync/numUnsyncedMutations.d.ts +0 -0
- /package/dist/{types → modern}/sync/old_startSyncingClientChanges.d.ts +0 -0
- /package/dist/{types → modern}/sync/registerSyncEvent.d.ts +0 -0
- /package/dist/{types → modern}/sync/syncIfPossible.d.ts +0 -0
- /package/dist/{types → modern}/sync/syncWithServer.d.ts +0 -0
- /package/dist/{types → modern}/sync/triggerSync.d.ts +0 -0
- /package/dist/{types → modern}/sync/updateBaseRevs.d.ts +0 -0
- /package/dist/{types → modern}/types/DXCInputField.d.ts +0 -0
- /package/dist/{types → modern}/types/NewIdOptions.d.ts +0 -0
- /package/dist/{types → modern}/types/SWMessageEvent.d.ts +0 -0
- /package/dist/{types → modern}/types/SWSyncEvent.d.ts +0 -0
- /package/dist/{types → modern}/types/TXExpandos.d.ts +0 -0
- /package/dist/{types → modern}/updateSchemaFromOptions.d.ts +0 -0
- /package/dist/{types → modern}/userIsActive.d.ts +0 -0
- /package/dist/{types → modern}/verifyConfig.d.ts +0 -0
- /package/dist/{types → modern}/verifySchema.d.ts +0 -0
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/* ==========================================================================
|
|
2
|
+
* dexie-cloud-addom.js
|
|
3
|
+
* ==========================================================================
|
|
4
|
+
*
|
|
5
|
+
* Dexie addon that syncs IndexedDB with Dexie Cloud.
|
|
6
|
+
*
|
|
7
|
+
* By David Fahlander, david@dexie.org
|
|
8
|
+
*
|
|
9
|
+
* ==========================================================================
|
|
10
|
+
*
|
|
11
|
+
* Version 4.0.1-beta.48, Tue Oct 17 2023
|
|
12
|
+
*
|
|
13
|
+
* https://dexie.org
|
|
14
|
+
*
|
|
15
|
+
* Apache License Version 2.0, January 2004, http://www.apache.org/licenses/
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
8
18
|
|
|
9
|
-
|
|
19
|
+
(function (global, factory) {
|
|
20
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('dexie'), require('rxjs')) :
|
|
21
|
+
typeof define === 'function' && define.amd ? define(['dexie', 'rxjs'], factory) :
|
|
22
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Dexie, global.rxjs));
|
|
23
|
+
})(this, (function (Dexie, rxjs) { 'use strict';
|
|
10
24
|
|
|
11
25
|
/******************************************************************************
|
|
12
26
|
Copyright (c) Microsoft Corporation.
|
|
@@ -22,6 +36,22 @@
|
|
|
22
36
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
23
37
|
PERFORMANCE OF THIS SOFTWARE.
|
|
24
38
|
***************************************************************************** */
|
|
39
|
+
/* global Reflect, Promise */
|
|
40
|
+
|
|
41
|
+
var extendStatics = function(d, b) {
|
|
42
|
+
extendStatics = Object.setPrototypeOf ||
|
|
43
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
44
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
45
|
+
return extendStatics(d, b);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function __extends(d, b) {
|
|
49
|
+
if (typeof b !== "function" && b !== null)
|
|
50
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
51
|
+
extendStatics(d, b);
|
|
52
|
+
function __() { this.constructor = d; }
|
|
53
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
54
|
+
}
|
|
25
55
|
|
|
26
56
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
27
57
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -31,6 +61,97 @@
|
|
|
31
61
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
32
62
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
63
|
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function __generator(thisArg, body) {
|
|
67
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
68
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
69
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
70
|
+
function step(op) {
|
|
71
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
72
|
+
while (_) try {
|
|
73
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
74
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
75
|
+
switch (op[0]) {
|
|
76
|
+
case 0: case 1: t = op; break;
|
|
77
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
78
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
79
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
80
|
+
default:
|
|
81
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
82
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
83
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
84
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
85
|
+
if (t[2]) _.ops.pop();
|
|
86
|
+
_.trys.pop(); continue;
|
|
87
|
+
}
|
|
88
|
+
op = body.call(thisArg, _);
|
|
89
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
90
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function __values(o) {
|
|
95
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
96
|
+
if (m) return m.call(o);
|
|
97
|
+
if (o && typeof o.length === "number") return {
|
|
98
|
+
next: function () {
|
|
99
|
+
if (o && i >= o.length) o = void 0;
|
|
100
|
+
return { value: o && o[i++], done: !o };
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function __read(o, n) {
|
|
107
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
108
|
+
if (!m) return o;
|
|
109
|
+
var i = m.call(o), r, ar = [], e;
|
|
110
|
+
try {
|
|
111
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
112
|
+
}
|
|
113
|
+
catch (error) { e = { error: error }; }
|
|
114
|
+
finally {
|
|
115
|
+
try {
|
|
116
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
117
|
+
}
|
|
118
|
+
finally { if (e) throw e.error; }
|
|
119
|
+
}
|
|
120
|
+
return ar;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function __spreadArray(to, from, pack) {
|
|
124
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
125
|
+
if (ar || !(i in from)) {
|
|
126
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
127
|
+
ar[i] = from[i];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function __await(v) {
|
|
134
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
138
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
139
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
140
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
141
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
142
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
143
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
144
|
+
function fulfill(value) { resume("next", value); }
|
|
145
|
+
function reject(value) { resume("throw", value); }
|
|
146
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function __asyncValues(o) {
|
|
150
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
151
|
+
var m = o[Symbol.asyncIterator], i;
|
|
152
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
153
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
154
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
34
155
|
}
|
|
35
156
|
|
|
36
157
|
const UNAUTHORIZED_USER = {
|
|
@@ -170,18 +291,1436 @@
|
|
|
170
291
|
else {
|
|
171
292
|
bc.removeEventListener("message", onMessageEvent);
|
|
172
293
|
}
|
|
173
|
-
};
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
this.name = name;
|
|
297
|
+
this.bc = bc;
|
|
298
|
+
}
|
|
299
|
+
next(message) {
|
|
300
|
+
console.debug("BroadcastedAndLocalEvent: bc.postMessage()", Object.assign({}, message), "bc is a", this.bc);
|
|
301
|
+
this.bc.postMessage(message);
|
|
302
|
+
const ev = new CustomEvent(`lbc-${this.name}`, { detail: message });
|
|
303
|
+
//self.dispatchEvent(ev);
|
|
304
|
+
dispatch(ev);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function isFunction(value) {
|
|
309
|
+
return typeof value === 'function';
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function hasLift(source) {
|
|
313
|
+
return isFunction(source === null || source === void 0 ? void 0 : source.lift);
|
|
314
|
+
}
|
|
315
|
+
function operate(init) {
|
|
316
|
+
return function (source) {
|
|
317
|
+
if (hasLift(source)) {
|
|
318
|
+
return source.lift(function (liftedSource) {
|
|
319
|
+
try {
|
|
320
|
+
return init(liftedSource, this);
|
|
321
|
+
}
|
|
322
|
+
catch (err) {
|
|
323
|
+
this.error(err);
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
throw new TypeError('Unable to lift unknown Observable type');
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
|
|
332
|
+
|
|
333
|
+
function isPromise(value) {
|
|
334
|
+
return isFunction(value === null || value === void 0 ? void 0 : value.then);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function createErrorClass(createImpl) {
|
|
338
|
+
var _super = function (instance) {
|
|
339
|
+
Error.call(instance);
|
|
340
|
+
instance.stack = new Error().stack;
|
|
341
|
+
};
|
|
342
|
+
var ctorFunc = createImpl(_super);
|
|
343
|
+
ctorFunc.prototype = Object.create(Error.prototype);
|
|
344
|
+
ctorFunc.prototype.constructor = ctorFunc;
|
|
345
|
+
return ctorFunc;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
var UnsubscriptionError = createErrorClass(function (_super) {
|
|
349
|
+
return function UnsubscriptionErrorImpl(errors) {
|
|
350
|
+
_super(this);
|
|
351
|
+
this.message = errors
|
|
352
|
+
? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
|
|
353
|
+
: '';
|
|
354
|
+
this.name = 'UnsubscriptionError';
|
|
355
|
+
this.errors = errors;
|
|
356
|
+
};
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
function arrRemove(arr, item) {
|
|
360
|
+
if (arr) {
|
|
361
|
+
var index = arr.indexOf(item);
|
|
362
|
+
0 <= index && arr.splice(index, 1);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
var Subscription = (function () {
|
|
367
|
+
function Subscription(initialTeardown) {
|
|
368
|
+
this.initialTeardown = initialTeardown;
|
|
369
|
+
this.closed = false;
|
|
370
|
+
this._parentage = null;
|
|
371
|
+
this._finalizers = null;
|
|
372
|
+
}
|
|
373
|
+
Subscription.prototype.unsubscribe = function () {
|
|
374
|
+
var e_1, _a, e_2, _b;
|
|
375
|
+
var errors;
|
|
376
|
+
if (!this.closed) {
|
|
377
|
+
this.closed = true;
|
|
378
|
+
var _parentage = this._parentage;
|
|
379
|
+
if (_parentage) {
|
|
380
|
+
this._parentage = null;
|
|
381
|
+
if (Array.isArray(_parentage)) {
|
|
382
|
+
try {
|
|
383
|
+
for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
|
384
|
+
var parent_1 = _parentage_1_1.value;
|
|
385
|
+
parent_1.remove(this);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
389
|
+
finally {
|
|
390
|
+
try {
|
|
391
|
+
if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
|
|
392
|
+
}
|
|
393
|
+
finally { if (e_1) throw e_1.error; }
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
_parentage.remove(this);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
var initialFinalizer = this.initialTeardown;
|
|
401
|
+
if (isFunction(initialFinalizer)) {
|
|
402
|
+
try {
|
|
403
|
+
initialFinalizer();
|
|
404
|
+
}
|
|
405
|
+
catch (e) {
|
|
406
|
+
errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
var _finalizers = this._finalizers;
|
|
410
|
+
if (_finalizers) {
|
|
411
|
+
this._finalizers = null;
|
|
412
|
+
try {
|
|
413
|
+
for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
|
|
414
|
+
var finalizer = _finalizers_1_1.value;
|
|
415
|
+
try {
|
|
416
|
+
execFinalizer(finalizer);
|
|
417
|
+
}
|
|
418
|
+
catch (err) {
|
|
419
|
+
errors = errors !== null && errors !== void 0 ? errors : [];
|
|
420
|
+
if (err instanceof UnsubscriptionError) {
|
|
421
|
+
errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
errors.push(err);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
430
|
+
finally {
|
|
431
|
+
try {
|
|
432
|
+
if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
|
|
433
|
+
}
|
|
434
|
+
finally { if (e_2) throw e_2.error; }
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (errors) {
|
|
438
|
+
throw new UnsubscriptionError(errors);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
Subscription.prototype.add = function (teardown) {
|
|
443
|
+
var _a;
|
|
444
|
+
if (teardown && teardown !== this) {
|
|
445
|
+
if (this.closed) {
|
|
446
|
+
execFinalizer(teardown);
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
if (teardown instanceof Subscription) {
|
|
450
|
+
if (teardown.closed || teardown._hasParent(this)) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
teardown._addParent(this);
|
|
454
|
+
}
|
|
455
|
+
(this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
Subscription.prototype._hasParent = function (parent) {
|
|
460
|
+
var _parentage = this._parentage;
|
|
461
|
+
return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
|
|
462
|
+
};
|
|
463
|
+
Subscription.prototype._addParent = function (parent) {
|
|
464
|
+
var _parentage = this._parentage;
|
|
465
|
+
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
466
|
+
};
|
|
467
|
+
Subscription.prototype._removeParent = function (parent) {
|
|
468
|
+
var _parentage = this._parentage;
|
|
469
|
+
if (_parentage === parent) {
|
|
470
|
+
this._parentage = null;
|
|
471
|
+
}
|
|
472
|
+
else if (Array.isArray(_parentage)) {
|
|
473
|
+
arrRemove(_parentage, parent);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
Subscription.prototype.remove = function (teardown) {
|
|
477
|
+
var _finalizers = this._finalizers;
|
|
478
|
+
_finalizers && arrRemove(_finalizers, teardown);
|
|
479
|
+
if (teardown instanceof Subscription) {
|
|
480
|
+
teardown._removeParent(this);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
Subscription.EMPTY = (function () {
|
|
484
|
+
var empty = new Subscription();
|
|
485
|
+
empty.closed = true;
|
|
486
|
+
return empty;
|
|
487
|
+
})();
|
|
488
|
+
return Subscription;
|
|
489
|
+
}());
|
|
490
|
+
Subscription.EMPTY;
|
|
491
|
+
function isSubscription(value) {
|
|
492
|
+
return (value instanceof Subscription ||
|
|
493
|
+
(value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
|
|
494
|
+
}
|
|
495
|
+
function execFinalizer(finalizer) {
|
|
496
|
+
if (isFunction(finalizer)) {
|
|
497
|
+
finalizer();
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
finalizer.unsubscribe();
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
var config = {
|
|
505
|
+
onUnhandledError: null,
|
|
506
|
+
onStoppedNotification: null,
|
|
507
|
+
Promise: undefined,
|
|
508
|
+
useDeprecatedSynchronousErrorHandling: false,
|
|
509
|
+
useDeprecatedNextContext: false,
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
var timeoutProvider = {
|
|
513
|
+
setTimeout: function (handler, timeout) {
|
|
514
|
+
var args = [];
|
|
515
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
516
|
+
args[_i - 2] = arguments[_i];
|
|
517
|
+
}
|
|
518
|
+
var delegate = timeoutProvider.delegate;
|
|
519
|
+
if (delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) {
|
|
520
|
+
return delegate.setTimeout.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
521
|
+
}
|
|
522
|
+
return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
523
|
+
},
|
|
524
|
+
clearTimeout: function (handle) {
|
|
525
|
+
var delegate = timeoutProvider.delegate;
|
|
526
|
+
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
|
|
527
|
+
},
|
|
528
|
+
delegate: undefined,
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
function reportUnhandledError(err) {
|
|
532
|
+
timeoutProvider.setTimeout(function () {
|
|
533
|
+
{
|
|
534
|
+
throw err;
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function noop() { }
|
|
540
|
+
|
|
541
|
+
function errorContext(cb) {
|
|
542
|
+
{
|
|
543
|
+
cb();
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
var Subscriber = (function (_super) {
|
|
548
|
+
__extends(Subscriber, _super);
|
|
549
|
+
function Subscriber(destination) {
|
|
550
|
+
var _this = _super.call(this) || this;
|
|
551
|
+
_this.isStopped = false;
|
|
552
|
+
if (destination) {
|
|
553
|
+
_this.destination = destination;
|
|
554
|
+
if (isSubscription(destination)) {
|
|
555
|
+
destination.add(_this);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
_this.destination = EMPTY_OBSERVER;
|
|
560
|
+
}
|
|
561
|
+
return _this;
|
|
562
|
+
}
|
|
563
|
+
Subscriber.create = function (next, error, complete) {
|
|
564
|
+
return new SafeSubscriber(next, error, complete);
|
|
565
|
+
};
|
|
566
|
+
Subscriber.prototype.next = function (value) {
|
|
567
|
+
if (this.isStopped) ;
|
|
568
|
+
else {
|
|
569
|
+
this._next(value);
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
Subscriber.prototype.error = function (err) {
|
|
573
|
+
if (this.isStopped) ;
|
|
574
|
+
else {
|
|
575
|
+
this.isStopped = true;
|
|
576
|
+
this._error(err);
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
Subscriber.prototype.complete = function () {
|
|
580
|
+
if (this.isStopped) ;
|
|
581
|
+
else {
|
|
582
|
+
this.isStopped = true;
|
|
583
|
+
this._complete();
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
Subscriber.prototype.unsubscribe = function () {
|
|
587
|
+
if (!this.closed) {
|
|
588
|
+
this.isStopped = true;
|
|
589
|
+
_super.prototype.unsubscribe.call(this);
|
|
590
|
+
this.destination = null;
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
Subscriber.prototype._next = function (value) {
|
|
594
|
+
this.destination.next(value);
|
|
595
|
+
};
|
|
596
|
+
Subscriber.prototype._error = function (err) {
|
|
597
|
+
try {
|
|
598
|
+
this.destination.error(err);
|
|
599
|
+
}
|
|
600
|
+
finally {
|
|
601
|
+
this.unsubscribe();
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
Subscriber.prototype._complete = function () {
|
|
605
|
+
try {
|
|
606
|
+
this.destination.complete();
|
|
607
|
+
}
|
|
608
|
+
finally {
|
|
609
|
+
this.unsubscribe();
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
return Subscriber;
|
|
613
|
+
}(Subscription));
|
|
614
|
+
var _bind = Function.prototype.bind;
|
|
615
|
+
function bind(fn, thisArg) {
|
|
616
|
+
return _bind.call(fn, thisArg);
|
|
617
|
+
}
|
|
618
|
+
var ConsumerObserver = (function () {
|
|
619
|
+
function ConsumerObserver(partialObserver) {
|
|
620
|
+
this.partialObserver = partialObserver;
|
|
621
|
+
}
|
|
622
|
+
ConsumerObserver.prototype.next = function (value) {
|
|
623
|
+
var partialObserver = this.partialObserver;
|
|
624
|
+
if (partialObserver.next) {
|
|
625
|
+
try {
|
|
626
|
+
partialObserver.next(value);
|
|
627
|
+
}
|
|
628
|
+
catch (error) {
|
|
629
|
+
handleUnhandledError(error);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
ConsumerObserver.prototype.error = function (err) {
|
|
634
|
+
var partialObserver = this.partialObserver;
|
|
635
|
+
if (partialObserver.error) {
|
|
636
|
+
try {
|
|
637
|
+
partialObserver.error(err);
|
|
638
|
+
}
|
|
639
|
+
catch (error) {
|
|
640
|
+
handleUnhandledError(error);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
else {
|
|
644
|
+
handleUnhandledError(err);
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
ConsumerObserver.prototype.complete = function () {
|
|
648
|
+
var partialObserver = this.partialObserver;
|
|
649
|
+
if (partialObserver.complete) {
|
|
650
|
+
try {
|
|
651
|
+
partialObserver.complete();
|
|
652
|
+
}
|
|
653
|
+
catch (error) {
|
|
654
|
+
handleUnhandledError(error);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
return ConsumerObserver;
|
|
659
|
+
}());
|
|
660
|
+
var SafeSubscriber = (function (_super) {
|
|
661
|
+
__extends(SafeSubscriber, _super);
|
|
662
|
+
function SafeSubscriber(observerOrNext, error, complete) {
|
|
663
|
+
var _this = _super.call(this) || this;
|
|
664
|
+
var partialObserver;
|
|
665
|
+
if (isFunction(observerOrNext) || !observerOrNext) {
|
|
666
|
+
partialObserver = {
|
|
667
|
+
next: (observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined),
|
|
668
|
+
error: error !== null && error !== void 0 ? error : undefined,
|
|
669
|
+
complete: complete !== null && complete !== void 0 ? complete : undefined,
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
var context_1;
|
|
674
|
+
if (_this && config.useDeprecatedNextContext) {
|
|
675
|
+
context_1 = Object.create(observerOrNext);
|
|
676
|
+
context_1.unsubscribe = function () { return _this.unsubscribe(); };
|
|
677
|
+
partialObserver = {
|
|
678
|
+
next: observerOrNext.next && bind(observerOrNext.next, context_1),
|
|
679
|
+
error: observerOrNext.error && bind(observerOrNext.error, context_1),
|
|
680
|
+
complete: observerOrNext.complete && bind(observerOrNext.complete, context_1),
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
partialObserver = observerOrNext;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
_this.destination = new ConsumerObserver(partialObserver);
|
|
688
|
+
return _this;
|
|
689
|
+
}
|
|
690
|
+
return SafeSubscriber;
|
|
691
|
+
}(Subscriber));
|
|
692
|
+
function handleUnhandledError(error) {
|
|
693
|
+
{
|
|
694
|
+
reportUnhandledError(error);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
function defaultErrorHandler(err) {
|
|
698
|
+
throw err;
|
|
699
|
+
}
|
|
700
|
+
var EMPTY_OBSERVER = {
|
|
701
|
+
closed: true,
|
|
702
|
+
next: noop,
|
|
703
|
+
error: defaultErrorHandler,
|
|
704
|
+
complete: noop,
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
|
|
708
|
+
|
|
709
|
+
function identity(x) {
|
|
710
|
+
return x;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function pipeFromArray(fns) {
|
|
714
|
+
if (fns.length === 0) {
|
|
715
|
+
return identity;
|
|
716
|
+
}
|
|
717
|
+
if (fns.length === 1) {
|
|
718
|
+
return fns[0];
|
|
719
|
+
}
|
|
720
|
+
return function piped(input) {
|
|
721
|
+
return fns.reduce(function (prev, fn) { return fn(prev); }, input);
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
var Observable = (function () {
|
|
726
|
+
function Observable(subscribe) {
|
|
727
|
+
if (subscribe) {
|
|
728
|
+
this._subscribe = subscribe;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
Observable.prototype.lift = function (operator) {
|
|
732
|
+
var observable = new Observable();
|
|
733
|
+
observable.source = this;
|
|
734
|
+
observable.operator = operator;
|
|
735
|
+
return observable;
|
|
736
|
+
};
|
|
737
|
+
Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
|
738
|
+
var _this = this;
|
|
739
|
+
var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
|
740
|
+
errorContext(function () {
|
|
741
|
+
var _a = _this, operator = _a.operator, source = _a.source;
|
|
742
|
+
subscriber.add(operator
|
|
743
|
+
?
|
|
744
|
+
operator.call(subscriber, source)
|
|
745
|
+
: source
|
|
746
|
+
?
|
|
747
|
+
_this._subscribe(subscriber)
|
|
748
|
+
:
|
|
749
|
+
_this._trySubscribe(subscriber));
|
|
750
|
+
});
|
|
751
|
+
return subscriber;
|
|
752
|
+
};
|
|
753
|
+
Observable.prototype._trySubscribe = function (sink) {
|
|
754
|
+
try {
|
|
755
|
+
return this._subscribe(sink);
|
|
756
|
+
}
|
|
757
|
+
catch (err) {
|
|
758
|
+
sink.error(err);
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
Observable.prototype.forEach = function (next, promiseCtor) {
|
|
762
|
+
var _this = this;
|
|
763
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
764
|
+
return new promiseCtor(function (resolve, reject) {
|
|
765
|
+
var subscriber = new SafeSubscriber({
|
|
766
|
+
next: function (value) {
|
|
767
|
+
try {
|
|
768
|
+
next(value);
|
|
769
|
+
}
|
|
770
|
+
catch (err) {
|
|
771
|
+
reject(err);
|
|
772
|
+
subscriber.unsubscribe();
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
error: reject,
|
|
776
|
+
complete: resolve,
|
|
777
|
+
});
|
|
778
|
+
_this.subscribe(subscriber);
|
|
779
|
+
});
|
|
780
|
+
};
|
|
781
|
+
Observable.prototype._subscribe = function (subscriber) {
|
|
782
|
+
var _a;
|
|
783
|
+
return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
|
|
784
|
+
};
|
|
785
|
+
Observable.prototype[observable] = function () {
|
|
786
|
+
return this;
|
|
787
|
+
};
|
|
788
|
+
Observable.prototype.pipe = function () {
|
|
789
|
+
var operations = [];
|
|
790
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
791
|
+
operations[_i] = arguments[_i];
|
|
792
|
+
}
|
|
793
|
+
return pipeFromArray(operations)(this);
|
|
794
|
+
};
|
|
795
|
+
Observable.prototype.toPromise = function (promiseCtor) {
|
|
796
|
+
var _this = this;
|
|
797
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
798
|
+
return new promiseCtor(function (resolve, reject) {
|
|
799
|
+
var value;
|
|
800
|
+
_this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
|
|
801
|
+
});
|
|
802
|
+
};
|
|
803
|
+
Observable.create = function (subscribe) {
|
|
804
|
+
return new Observable(subscribe);
|
|
805
|
+
};
|
|
806
|
+
return Observable;
|
|
807
|
+
}());
|
|
808
|
+
function getPromiseCtor(promiseCtor) {
|
|
809
|
+
var _a;
|
|
810
|
+
return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
|
|
811
|
+
}
|
|
812
|
+
function isObserver(value) {
|
|
813
|
+
return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
|
|
814
|
+
}
|
|
815
|
+
function isSubscriber(value) {
|
|
816
|
+
return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
function isInteropObservable(input) {
|
|
820
|
+
return isFunction(input[observable]);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
function isAsyncIterable(obj) {
|
|
824
|
+
return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
function createInvalidObservableTypeError(input) {
|
|
828
|
+
return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function getSymbolIterator() {
|
|
832
|
+
if (typeof Symbol !== 'function' || !Symbol.iterator) {
|
|
833
|
+
return '@@iterator';
|
|
834
|
+
}
|
|
835
|
+
return Symbol.iterator;
|
|
836
|
+
}
|
|
837
|
+
var iterator = getSymbolIterator();
|
|
838
|
+
|
|
839
|
+
function isIterable(input) {
|
|
840
|
+
return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
function readableStreamLikeToAsyncGenerator(readableStream) {
|
|
844
|
+
return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
|
|
845
|
+
var reader, _a, value, done;
|
|
846
|
+
return __generator(this, function (_b) {
|
|
847
|
+
switch (_b.label) {
|
|
848
|
+
case 0:
|
|
849
|
+
reader = readableStream.getReader();
|
|
850
|
+
_b.label = 1;
|
|
851
|
+
case 1:
|
|
852
|
+
_b.trys.push([1, , 9, 10]);
|
|
853
|
+
_b.label = 2;
|
|
854
|
+
case 2:
|
|
855
|
+
return [4, __await(reader.read())];
|
|
856
|
+
case 3:
|
|
857
|
+
_a = _b.sent(), value = _a.value, done = _a.done;
|
|
858
|
+
if (!done) return [3, 5];
|
|
859
|
+
return [4, __await(void 0)];
|
|
860
|
+
case 4: return [2, _b.sent()];
|
|
861
|
+
case 5: return [4, __await(value)];
|
|
862
|
+
case 6: return [4, _b.sent()];
|
|
863
|
+
case 7:
|
|
864
|
+
_b.sent();
|
|
865
|
+
return [3, 2];
|
|
866
|
+
case 8: return [3, 10];
|
|
867
|
+
case 9:
|
|
868
|
+
reader.releaseLock();
|
|
869
|
+
return [7];
|
|
870
|
+
case 10: return [2];
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
function isReadableStreamLike(obj) {
|
|
876
|
+
return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
function innerFrom(input) {
|
|
880
|
+
if (input instanceof Observable) {
|
|
881
|
+
return input;
|
|
882
|
+
}
|
|
883
|
+
if (input != null) {
|
|
884
|
+
if (isInteropObservable(input)) {
|
|
885
|
+
return fromInteropObservable(input);
|
|
886
|
+
}
|
|
887
|
+
if (isArrayLike(input)) {
|
|
888
|
+
return fromArrayLike(input);
|
|
889
|
+
}
|
|
890
|
+
if (isPromise(input)) {
|
|
891
|
+
return fromPromise(input);
|
|
892
|
+
}
|
|
893
|
+
if (isAsyncIterable(input)) {
|
|
894
|
+
return fromAsyncIterable(input);
|
|
895
|
+
}
|
|
896
|
+
if (isIterable(input)) {
|
|
897
|
+
return fromIterable(input);
|
|
898
|
+
}
|
|
899
|
+
if (isReadableStreamLike(input)) {
|
|
900
|
+
return fromReadableStreamLike(input);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
throw createInvalidObservableTypeError(input);
|
|
904
|
+
}
|
|
905
|
+
function fromInteropObservable(obj) {
|
|
906
|
+
return new Observable(function (subscriber) {
|
|
907
|
+
var obs = obj[observable]();
|
|
908
|
+
if (isFunction(obs.subscribe)) {
|
|
909
|
+
return obs.subscribe(subscriber);
|
|
910
|
+
}
|
|
911
|
+
throw new TypeError('Provided object does not correctly implement Symbol.observable');
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
function fromArrayLike(array) {
|
|
915
|
+
return new Observable(function (subscriber) {
|
|
916
|
+
for (var i = 0; i < array.length && !subscriber.closed; i++) {
|
|
917
|
+
subscriber.next(array[i]);
|
|
918
|
+
}
|
|
919
|
+
subscriber.complete();
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
function fromPromise(promise) {
|
|
923
|
+
return new Observable(function (subscriber) {
|
|
924
|
+
promise
|
|
925
|
+
.then(function (value) {
|
|
926
|
+
if (!subscriber.closed) {
|
|
927
|
+
subscriber.next(value);
|
|
928
|
+
subscriber.complete();
|
|
929
|
+
}
|
|
930
|
+
}, function (err) { return subscriber.error(err); })
|
|
931
|
+
.then(null, reportUnhandledError);
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
function fromIterable(iterable) {
|
|
935
|
+
return new Observable(function (subscriber) {
|
|
936
|
+
var e_1, _a;
|
|
937
|
+
try {
|
|
938
|
+
for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
|
|
939
|
+
var value = iterable_1_1.value;
|
|
940
|
+
subscriber.next(value);
|
|
941
|
+
if (subscriber.closed) {
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
947
|
+
finally {
|
|
948
|
+
try {
|
|
949
|
+
if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
|
|
950
|
+
}
|
|
951
|
+
finally { if (e_1) throw e_1.error; }
|
|
952
|
+
}
|
|
953
|
+
subscriber.complete();
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
function fromAsyncIterable(asyncIterable) {
|
|
957
|
+
return new Observable(function (subscriber) {
|
|
958
|
+
process(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
function fromReadableStreamLike(readableStream) {
|
|
962
|
+
return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
|
|
963
|
+
}
|
|
964
|
+
function process(asyncIterable, subscriber) {
|
|
965
|
+
var asyncIterable_1, asyncIterable_1_1;
|
|
966
|
+
var e_2, _a;
|
|
967
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
968
|
+
var value, e_2_1;
|
|
969
|
+
return __generator(this, function (_b) {
|
|
970
|
+
switch (_b.label) {
|
|
971
|
+
case 0:
|
|
972
|
+
_b.trys.push([0, 5, 6, 11]);
|
|
973
|
+
asyncIterable_1 = __asyncValues(asyncIterable);
|
|
974
|
+
_b.label = 1;
|
|
975
|
+
case 1: return [4, asyncIterable_1.next()];
|
|
976
|
+
case 2:
|
|
977
|
+
if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
|
|
978
|
+
value = asyncIterable_1_1.value;
|
|
979
|
+
subscriber.next(value);
|
|
980
|
+
if (subscriber.closed) {
|
|
981
|
+
return [2];
|
|
982
|
+
}
|
|
983
|
+
_b.label = 3;
|
|
984
|
+
case 3: return [3, 1];
|
|
985
|
+
case 4: return [3, 11];
|
|
986
|
+
case 5:
|
|
987
|
+
e_2_1 = _b.sent();
|
|
988
|
+
e_2 = { error: e_2_1 };
|
|
989
|
+
return [3, 11];
|
|
990
|
+
case 6:
|
|
991
|
+
_b.trys.push([6, , 9, 10]);
|
|
992
|
+
if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
|
|
993
|
+
return [4, _a.call(asyncIterable_1)];
|
|
994
|
+
case 7:
|
|
995
|
+
_b.sent();
|
|
996
|
+
_b.label = 8;
|
|
997
|
+
case 8: return [3, 10];
|
|
998
|
+
case 9:
|
|
999
|
+
if (e_2) throw e_2.error;
|
|
1000
|
+
return [7];
|
|
1001
|
+
case 10: return [7];
|
|
1002
|
+
case 11:
|
|
1003
|
+
subscriber.complete();
|
|
1004
|
+
return [2];
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
|
|
1011
|
+
return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
|
|
1012
|
+
}
|
|
1013
|
+
var OperatorSubscriber = (function (_super) {
|
|
1014
|
+
__extends(OperatorSubscriber, _super);
|
|
1015
|
+
function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
|
|
1016
|
+
var _this = _super.call(this, destination) || this;
|
|
1017
|
+
_this.onFinalize = onFinalize;
|
|
1018
|
+
_this.shouldUnsubscribe = shouldUnsubscribe;
|
|
1019
|
+
_this._next = onNext
|
|
1020
|
+
? function (value) {
|
|
1021
|
+
try {
|
|
1022
|
+
onNext(value);
|
|
1023
|
+
}
|
|
1024
|
+
catch (err) {
|
|
1025
|
+
destination.error(err);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
: _super.prototype._next;
|
|
1029
|
+
_this._error = onError
|
|
1030
|
+
? function (err) {
|
|
1031
|
+
try {
|
|
1032
|
+
onError(err);
|
|
1033
|
+
}
|
|
1034
|
+
catch (err) {
|
|
1035
|
+
destination.error(err);
|
|
1036
|
+
}
|
|
1037
|
+
finally {
|
|
1038
|
+
this.unsubscribe();
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
: _super.prototype._error;
|
|
1042
|
+
_this._complete = onComplete
|
|
1043
|
+
? function () {
|
|
1044
|
+
try {
|
|
1045
|
+
onComplete();
|
|
1046
|
+
}
|
|
1047
|
+
catch (err) {
|
|
1048
|
+
destination.error(err);
|
|
1049
|
+
}
|
|
1050
|
+
finally {
|
|
1051
|
+
this.unsubscribe();
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
: _super.prototype._complete;
|
|
1055
|
+
return _this;
|
|
1056
|
+
}
|
|
1057
|
+
OperatorSubscriber.prototype.unsubscribe = function () {
|
|
1058
|
+
var _a;
|
|
1059
|
+
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
|
1060
|
+
var closed_1 = this.closed;
|
|
1061
|
+
_super.prototype.unsubscribe.call(this);
|
|
1062
|
+
!closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
return OperatorSubscriber;
|
|
1066
|
+
}(Subscriber));
|
|
1067
|
+
|
|
1068
|
+
var Action = (function (_super) {
|
|
1069
|
+
__extends(Action, _super);
|
|
1070
|
+
function Action(scheduler, work) {
|
|
1071
|
+
return _super.call(this) || this;
|
|
1072
|
+
}
|
|
1073
|
+
Action.prototype.schedule = function (state, delay) {
|
|
1074
|
+
return this;
|
|
1075
|
+
};
|
|
1076
|
+
return Action;
|
|
1077
|
+
}(Subscription));
|
|
1078
|
+
|
|
1079
|
+
var intervalProvider = {
|
|
1080
|
+
setInterval: function (handler, timeout) {
|
|
1081
|
+
var args = [];
|
|
1082
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1083
|
+
args[_i - 2] = arguments[_i];
|
|
1084
|
+
}
|
|
1085
|
+
var delegate = intervalProvider.delegate;
|
|
1086
|
+
if (delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) {
|
|
1087
|
+
return delegate.setInterval.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
1088
|
+
}
|
|
1089
|
+
return setInterval.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
1090
|
+
},
|
|
1091
|
+
clearInterval: function (handle) {
|
|
1092
|
+
var delegate = intervalProvider.delegate;
|
|
1093
|
+
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle);
|
|
1094
|
+
},
|
|
1095
|
+
delegate: undefined,
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
var AsyncAction = (function (_super) {
|
|
1099
|
+
__extends(AsyncAction, _super);
|
|
1100
|
+
function AsyncAction(scheduler, work) {
|
|
1101
|
+
var _this = _super.call(this, scheduler, work) || this;
|
|
1102
|
+
_this.scheduler = scheduler;
|
|
1103
|
+
_this.work = work;
|
|
1104
|
+
_this.pending = false;
|
|
1105
|
+
return _this;
|
|
1106
|
+
}
|
|
1107
|
+
AsyncAction.prototype.schedule = function (state, delay) {
|
|
1108
|
+
if (delay === void 0) { delay = 0; }
|
|
1109
|
+
if (this.closed) {
|
|
1110
|
+
return this;
|
|
1111
|
+
}
|
|
1112
|
+
this.state = state;
|
|
1113
|
+
var id = this.id;
|
|
1114
|
+
var scheduler = this.scheduler;
|
|
1115
|
+
if (id != null) {
|
|
1116
|
+
this.id = this.recycleAsyncId(scheduler, id, delay);
|
|
1117
|
+
}
|
|
1118
|
+
this.pending = true;
|
|
1119
|
+
this.delay = delay;
|
|
1120
|
+
this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
|
|
1121
|
+
return this;
|
|
1122
|
+
};
|
|
1123
|
+
AsyncAction.prototype.requestAsyncId = function (scheduler, _id, delay) {
|
|
1124
|
+
if (delay === void 0) { delay = 0; }
|
|
1125
|
+
return intervalProvider.setInterval(scheduler.flush.bind(scheduler, this), delay);
|
|
1126
|
+
};
|
|
1127
|
+
AsyncAction.prototype.recycleAsyncId = function (_scheduler, id, delay) {
|
|
1128
|
+
if (delay === void 0) { delay = 0; }
|
|
1129
|
+
if (delay != null && this.delay === delay && this.pending === false) {
|
|
1130
|
+
return id;
|
|
1131
|
+
}
|
|
1132
|
+
intervalProvider.clearInterval(id);
|
|
1133
|
+
return undefined;
|
|
1134
|
+
};
|
|
1135
|
+
AsyncAction.prototype.execute = function (state, delay) {
|
|
1136
|
+
if (this.closed) {
|
|
1137
|
+
return new Error('executing a cancelled action');
|
|
1138
|
+
}
|
|
1139
|
+
this.pending = false;
|
|
1140
|
+
var error = this._execute(state, delay);
|
|
1141
|
+
if (error) {
|
|
1142
|
+
return error;
|
|
1143
|
+
}
|
|
1144
|
+
else if (this.pending === false && this.id != null) {
|
|
1145
|
+
this.id = this.recycleAsyncId(this.scheduler, this.id, null);
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
AsyncAction.prototype._execute = function (state, _delay) {
|
|
1149
|
+
var errored = false;
|
|
1150
|
+
var errorValue;
|
|
1151
|
+
try {
|
|
1152
|
+
this.work(state);
|
|
1153
|
+
}
|
|
1154
|
+
catch (e) {
|
|
1155
|
+
errored = true;
|
|
1156
|
+
errorValue = e ? e : new Error('Scheduled action threw falsy error');
|
|
1157
|
+
}
|
|
1158
|
+
if (errored) {
|
|
1159
|
+
this.unsubscribe();
|
|
1160
|
+
return errorValue;
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
AsyncAction.prototype.unsubscribe = function () {
|
|
1164
|
+
if (!this.closed) {
|
|
1165
|
+
var _a = this, id = _a.id, scheduler = _a.scheduler;
|
|
1166
|
+
var actions = scheduler.actions;
|
|
1167
|
+
this.work = this.state = this.scheduler = null;
|
|
1168
|
+
this.pending = false;
|
|
1169
|
+
arrRemove(actions, this);
|
|
1170
|
+
if (id != null) {
|
|
1171
|
+
this.id = this.recycleAsyncId(scheduler, id, null);
|
|
1172
|
+
}
|
|
1173
|
+
this.delay = null;
|
|
1174
|
+
_super.prototype.unsubscribe.call(this);
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
return AsyncAction;
|
|
1178
|
+
}(Action));
|
|
1179
|
+
|
|
1180
|
+
var dateTimestampProvider = {
|
|
1181
|
+
now: function () {
|
|
1182
|
+
return (dateTimestampProvider.delegate || Date).now();
|
|
1183
|
+
},
|
|
1184
|
+
delegate: undefined,
|
|
1185
|
+
};
|
|
1186
|
+
|
|
1187
|
+
var Scheduler = (function () {
|
|
1188
|
+
function Scheduler(schedulerActionCtor, now) {
|
|
1189
|
+
if (now === void 0) { now = Scheduler.now; }
|
|
1190
|
+
this.schedulerActionCtor = schedulerActionCtor;
|
|
1191
|
+
this.now = now;
|
|
1192
|
+
}
|
|
1193
|
+
Scheduler.prototype.schedule = function (work, delay, state) {
|
|
1194
|
+
if (delay === void 0) { delay = 0; }
|
|
1195
|
+
return new this.schedulerActionCtor(this, work).schedule(state, delay);
|
|
1196
|
+
};
|
|
1197
|
+
Scheduler.now = dateTimestampProvider.now;
|
|
1198
|
+
return Scheduler;
|
|
1199
|
+
}());
|
|
1200
|
+
|
|
1201
|
+
var AsyncScheduler = (function (_super) {
|
|
1202
|
+
__extends(AsyncScheduler, _super);
|
|
1203
|
+
function AsyncScheduler(SchedulerAction, now) {
|
|
1204
|
+
if (now === void 0) { now = Scheduler.now; }
|
|
1205
|
+
var _this = _super.call(this, SchedulerAction, now) || this;
|
|
1206
|
+
_this.actions = [];
|
|
1207
|
+
_this._active = false;
|
|
1208
|
+
_this._scheduled = undefined;
|
|
1209
|
+
return _this;
|
|
1210
|
+
}
|
|
1211
|
+
AsyncScheduler.prototype.flush = function (action) {
|
|
1212
|
+
var actions = this.actions;
|
|
1213
|
+
if (this._active) {
|
|
1214
|
+
actions.push(action);
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
var error;
|
|
1218
|
+
this._active = true;
|
|
1219
|
+
do {
|
|
1220
|
+
if ((error = action.execute(action.state, action.delay))) {
|
|
1221
|
+
break;
|
|
1222
|
+
}
|
|
1223
|
+
} while ((action = actions.shift()));
|
|
1224
|
+
this._active = false;
|
|
1225
|
+
if (error) {
|
|
1226
|
+
while ((action = actions.shift())) {
|
|
1227
|
+
action.unsubscribe();
|
|
1228
|
+
}
|
|
1229
|
+
throw error;
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
return AsyncScheduler;
|
|
1233
|
+
}(Scheduler));
|
|
1234
|
+
|
|
1235
|
+
var asyncScheduler = new AsyncScheduler(AsyncAction);
|
|
1236
|
+
var async = asyncScheduler;
|
|
1237
|
+
|
|
1238
|
+
function isScheduler(value) {
|
|
1239
|
+
return value && isFunction(value.schedule);
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
function isValidDate(value) {
|
|
1243
|
+
return value instanceof Date && !isNaN(value);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
function timer(dueTime, intervalOrScheduler, scheduler) {
|
|
1247
|
+
if (dueTime === void 0) { dueTime = 0; }
|
|
1248
|
+
if (scheduler === void 0) { scheduler = async; }
|
|
1249
|
+
var intervalDuration = -1;
|
|
1250
|
+
if (intervalOrScheduler != null) {
|
|
1251
|
+
if (isScheduler(intervalOrScheduler)) {
|
|
1252
|
+
scheduler = intervalOrScheduler;
|
|
1253
|
+
}
|
|
1254
|
+
else {
|
|
1255
|
+
intervalDuration = intervalOrScheduler;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
return new Observable(function (subscriber) {
|
|
1259
|
+
var due = isValidDate(dueTime) ? +dueTime - scheduler.now() : dueTime;
|
|
1260
|
+
if (due < 0) {
|
|
1261
|
+
due = 0;
|
|
1262
|
+
}
|
|
1263
|
+
var n = 0;
|
|
1264
|
+
return scheduler.schedule(function () {
|
|
1265
|
+
if (!subscriber.closed) {
|
|
1266
|
+
subscriber.next(n++);
|
|
1267
|
+
if (0 <= intervalDuration) {
|
|
1268
|
+
this.schedule(undefined, intervalDuration);
|
|
1269
|
+
}
|
|
1270
|
+
else {
|
|
1271
|
+
subscriber.complete();
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}, due);
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
function last(arr) {
|
|
1279
|
+
return arr[arr.length - 1];
|
|
1280
|
+
}
|
|
1281
|
+
function popScheduler(args) {
|
|
1282
|
+
return isScheduler(last(args)) ? args.pop() : undefined;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
|
|
1286
|
+
if (delay === void 0) { delay = 0; }
|
|
1287
|
+
if (repeat === void 0) { repeat = false; }
|
|
1288
|
+
var scheduleSubscription = scheduler.schedule(function () {
|
|
1289
|
+
work();
|
|
1290
|
+
if (repeat) {
|
|
1291
|
+
parentSubscription.add(this.schedule(null, delay));
|
|
1292
|
+
}
|
|
1293
|
+
else {
|
|
1294
|
+
this.unsubscribe();
|
|
1295
|
+
}
|
|
1296
|
+
}, delay);
|
|
1297
|
+
parentSubscription.add(scheduleSubscription);
|
|
1298
|
+
if (!repeat) {
|
|
1299
|
+
return scheduleSubscription;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
function catchError(selector) {
|
|
1304
|
+
return operate(function (source, subscriber) {
|
|
1305
|
+
var innerSub = null;
|
|
1306
|
+
var syncUnsub = false;
|
|
1307
|
+
var handledResult;
|
|
1308
|
+
innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, undefined, function (err) {
|
|
1309
|
+
handledResult = innerFrom(selector(err, catchError(selector)(source)));
|
|
1310
|
+
if (innerSub) {
|
|
1311
|
+
innerSub.unsubscribe();
|
|
1312
|
+
innerSub = null;
|
|
1313
|
+
handledResult.subscribe(subscriber);
|
|
1314
|
+
}
|
|
1315
|
+
else {
|
|
1316
|
+
syncUnsub = true;
|
|
1317
|
+
}
|
|
1318
|
+
}));
|
|
1319
|
+
if (syncUnsub) {
|
|
1320
|
+
innerSub.unsubscribe();
|
|
1321
|
+
innerSub = null;
|
|
1322
|
+
handledResult.subscribe(subscriber);
|
|
1323
|
+
}
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
function observeOn(scheduler, delay) {
|
|
1328
|
+
if (delay === void 0) { delay = 0; }
|
|
1329
|
+
return operate(function (source, subscriber) {
|
|
1330
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return executeSchedule(subscriber, scheduler, function () { return subscriber.next(value); }, delay); }, function () { return executeSchedule(subscriber, scheduler, function () { return subscriber.complete(); }, delay); }, function (err) { return executeSchedule(subscriber, scheduler, function () { return subscriber.error(err); }, delay); }));
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
function subscribeOn(scheduler, delay) {
|
|
1335
|
+
if (delay === void 0) { delay = 0; }
|
|
1336
|
+
return operate(function (source, subscriber) {
|
|
1337
|
+
subscriber.add(scheduler.schedule(function () { return source.subscribe(subscriber); }, delay));
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
function scheduleObservable(input, scheduler) {
|
|
1342
|
+
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
function schedulePromise(input, scheduler) {
|
|
1346
|
+
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
function scheduleArray(input, scheduler) {
|
|
1350
|
+
return new Observable(function (subscriber) {
|
|
1351
|
+
var i = 0;
|
|
1352
|
+
return scheduler.schedule(function () {
|
|
1353
|
+
if (i === input.length) {
|
|
1354
|
+
subscriber.complete();
|
|
1355
|
+
}
|
|
1356
|
+
else {
|
|
1357
|
+
subscriber.next(input[i++]);
|
|
1358
|
+
if (!subscriber.closed) {
|
|
1359
|
+
this.schedule();
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
function scheduleIterable(input, scheduler) {
|
|
1367
|
+
return new Observable(function (subscriber) {
|
|
1368
|
+
var iterator$1;
|
|
1369
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1370
|
+
iterator$1 = input[iterator]();
|
|
1371
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1372
|
+
var _a;
|
|
1373
|
+
var value;
|
|
1374
|
+
var done;
|
|
1375
|
+
try {
|
|
1376
|
+
(_a = iterator$1.next(), value = _a.value, done = _a.done);
|
|
1377
|
+
}
|
|
1378
|
+
catch (err) {
|
|
1379
|
+
subscriber.error(err);
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
1382
|
+
if (done) {
|
|
1383
|
+
subscriber.complete();
|
|
1384
|
+
}
|
|
1385
|
+
else {
|
|
1386
|
+
subscriber.next(value);
|
|
1387
|
+
}
|
|
1388
|
+
}, 0, true);
|
|
1389
|
+
});
|
|
1390
|
+
return function () { return isFunction(iterator$1 === null || iterator$1 === void 0 ? void 0 : iterator$1.return) && iterator$1.return(); };
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
function scheduleAsyncIterable(input, scheduler) {
|
|
1395
|
+
if (!input) {
|
|
1396
|
+
throw new Error('Iterable cannot be null');
|
|
1397
|
+
}
|
|
1398
|
+
return new Observable(function (subscriber) {
|
|
1399
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1400
|
+
var iterator = input[Symbol.asyncIterator]();
|
|
1401
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1402
|
+
iterator.next().then(function (result) {
|
|
1403
|
+
if (result.done) {
|
|
1404
|
+
subscriber.complete();
|
|
1405
|
+
}
|
|
1406
|
+
else {
|
|
1407
|
+
subscriber.next(result.value);
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1410
|
+
}, 0, true);
|
|
1411
|
+
});
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
function scheduleReadableStreamLike(input, scheduler) {
|
|
1416
|
+
return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
function scheduled(input, scheduler) {
|
|
1420
|
+
if (input != null) {
|
|
1421
|
+
if (isInteropObservable(input)) {
|
|
1422
|
+
return scheduleObservable(input, scheduler);
|
|
1423
|
+
}
|
|
1424
|
+
if (isArrayLike(input)) {
|
|
1425
|
+
return scheduleArray(input, scheduler);
|
|
1426
|
+
}
|
|
1427
|
+
if (isPromise(input)) {
|
|
1428
|
+
return schedulePromise(input, scheduler);
|
|
1429
|
+
}
|
|
1430
|
+
if (isAsyncIterable(input)) {
|
|
1431
|
+
return scheduleAsyncIterable(input, scheduler);
|
|
1432
|
+
}
|
|
1433
|
+
if (isIterable(input)) {
|
|
1434
|
+
return scheduleIterable(input, scheduler);
|
|
1435
|
+
}
|
|
1436
|
+
if (isReadableStreamLike(input)) {
|
|
1437
|
+
return scheduleReadableStreamLike(input, scheduler);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
throw createInvalidObservableTypeError(input);
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
function from(input, scheduler) {
|
|
1444
|
+
return scheduler ? scheduled(input, scheduler) : innerFrom(input);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
function map(project, thisArg) {
|
|
1448
|
+
return operate(function (source, subscriber) {
|
|
1449
|
+
var index = 0;
|
|
1450
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1451
|
+
subscriber.next(project.call(thisArg, value, index++));
|
|
1452
|
+
}));
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
|
|
1457
|
+
var buffer = [];
|
|
1458
|
+
var active = 0;
|
|
1459
|
+
var index = 0;
|
|
1460
|
+
var isComplete = false;
|
|
1461
|
+
var checkComplete = function () {
|
|
1462
|
+
if (isComplete && !buffer.length && !active) {
|
|
1463
|
+
subscriber.complete();
|
|
1464
|
+
}
|
|
1465
|
+
};
|
|
1466
|
+
var outerNext = function (value) { return (active < concurrent ? doInnerSub(value) : buffer.push(value)); };
|
|
1467
|
+
var doInnerSub = function (value) {
|
|
1468
|
+
expand && subscriber.next(value);
|
|
1469
|
+
active++;
|
|
1470
|
+
var innerComplete = false;
|
|
1471
|
+
innerFrom(project(value, index++)).subscribe(createOperatorSubscriber(subscriber, function (innerValue) {
|
|
1472
|
+
onBeforeNext === null || onBeforeNext === void 0 ? void 0 : onBeforeNext(innerValue);
|
|
1473
|
+
if (expand) {
|
|
1474
|
+
outerNext(innerValue);
|
|
1475
|
+
}
|
|
1476
|
+
else {
|
|
1477
|
+
subscriber.next(innerValue);
|
|
1478
|
+
}
|
|
1479
|
+
}, function () {
|
|
1480
|
+
innerComplete = true;
|
|
1481
|
+
}, undefined, function () {
|
|
1482
|
+
if (innerComplete) {
|
|
1483
|
+
try {
|
|
1484
|
+
active--;
|
|
1485
|
+
var _loop_1 = function () {
|
|
1486
|
+
var bufferedValue = buffer.shift();
|
|
1487
|
+
if (innerSubScheduler) {
|
|
1488
|
+
executeSchedule(subscriber, innerSubScheduler, function () { return doInnerSub(bufferedValue); });
|
|
1489
|
+
}
|
|
1490
|
+
else {
|
|
1491
|
+
doInnerSub(bufferedValue);
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
while (buffer.length && active < concurrent) {
|
|
1495
|
+
_loop_1();
|
|
1496
|
+
}
|
|
1497
|
+
checkComplete();
|
|
1498
|
+
}
|
|
1499
|
+
catch (err) {
|
|
1500
|
+
subscriber.error(err);
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
}));
|
|
1504
|
+
};
|
|
1505
|
+
source.subscribe(createOperatorSubscriber(subscriber, outerNext, function () {
|
|
1506
|
+
isComplete = true;
|
|
1507
|
+
checkComplete();
|
|
1508
|
+
}));
|
|
1509
|
+
return function () {
|
|
1510
|
+
additionalFinalizer === null || additionalFinalizer === void 0 ? void 0 : additionalFinalizer();
|
|
1511
|
+
};
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
function mergeMap(project, resultSelector, concurrent) {
|
|
1515
|
+
if (concurrent === void 0) { concurrent = Infinity; }
|
|
1516
|
+
if (isFunction(resultSelector)) {
|
|
1517
|
+
return mergeMap(function (a, i) { return map(function (b, ii) { return resultSelector(a, b, i, ii); })(innerFrom(project(a, i))); }, concurrent);
|
|
1518
|
+
}
|
|
1519
|
+
else if (typeof resultSelector === 'number') {
|
|
1520
|
+
concurrent = resultSelector;
|
|
1521
|
+
}
|
|
1522
|
+
return operate(function (source, subscriber) { return mergeInternals(source, subscriber, project, concurrent); });
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
function mergeAll(concurrent) {
|
|
1526
|
+
if (concurrent === void 0) { concurrent = Infinity; }
|
|
1527
|
+
return mergeMap(identity, concurrent);
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
function concatAll() {
|
|
1531
|
+
return mergeAll(1);
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
function debounceTime(dueTime, scheduler) {
|
|
1535
|
+
if (scheduler === void 0) { scheduler = asyncScheduler; }
|
|
1536
|
+
return operate(function (source, subscriber) {
|
|
1537
|
+
var activeTask = null;
|
|
1538
|
+
var lastValue = null;
|
|
1539
|
+
var lastTime = null;
|
|
1540
|
+
var emit = function () {
|
|
1541
|
+
if (activeTask) {
|
|
1542
|
+
activeTask.unsubscribe();
|
|
1543
|
+
activeTask = null;
|
|
1544
|
+
var value = lastValue;
|
|
1545
|
+
lastValue = null;
|
|
1546
|
+
subscriber.next(value);
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
function emitWhenIdle() {
|
|
1550
|
+
var targetTime = lastTime + dueTime;
|
|
1551
|
+
var now = scheduler.now();
|
|
1552
|
+
if (now < targetTime) {
|
|
1553
|
+
activeTask = this.schedule(undefined, targetTime - now);
|
|
1554
|
+
subscriber.add(activeTask);
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
emit();
|
|
1558
|
+
}
|
|
1559
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1560
|
+
lastValue = value;
|
|
1561
|
+
lastTime = scheduler.now();
|
|
1562
|
+
if (!activeTask) {
|
|
1563
|
+
activeTask = scheduler.schedule(emitWhenIdle, dueTime);
|
|
1564
|
+
subscriber.add(activeTask);
|
|
1565
|
+
}
|
|
1566
|
+
}, function () {
|
|
1567
|
+
emit();
|
|
1568
|
+
subscriber.complete();
|
|
1569
|
+
}, undefined, function () {
|
|
1570
|
+
lastValue = activeTask = null;
|
|
1571
|
+
}));
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
function concat$1() {
|
|
1576
|
+
var args = [];
|
|
1577
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1578
|
+
args[_i] = arguments[_i];
|
|
1579
|
+
}
|
|
1580
|
+
return concatAll()(from(args, popScheduler(args)));
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
var EMPTY = new Observable(function (subscriber) { return subscriber.complete(); });
|
|
1584
|
+
|
|
1585
|
+
function take(count) {
|
|
1586
|
+
return count <= 0
|
|
1587
|
+
?
|
|
1588
|
+
function () { return EMPTY; }
|
|
1589
|
+
: operate(function (source, subscriber) {
|
|
1590
|
+
var seen = 0;
|
|
1591
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1592
|
+
if (++seen <= count) {
|
|
1593
|
+
subscriber.next(value);
|
|
1594
|
+
if (count <= seen) {
|
|
1595
|
+
subscriber.complete();
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
}));
|
|
174
1599
|
});
|
|
175
|
-
|
|
176
|
-
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
function ignoreElements() {
|
|
1603
|
+
return operate(function (source, subscriber) {
|
|
1604
|
+
source.subscribe(createOperatorSubscriber(subscriber, noop));
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
function mapTo(value) {
|
|
1609
|
+
return map(function () { return value; });
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
function delayWhen(delayDurationSelector, subscriptionDelay) {
|
|
1613
|
+
if (subscriptionDelay) {
|
|
1614
|
+
return function (source) {
|
|
1615
|
+
return concat$1(subscriptionDelay.pipe(take(1), ignoreElements()), source.pipe(delayWhen(delayDurationSelector)));
|
|
1616
|
+
};
|
|
177
1617
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
1618
|
+
return mergeMap(function (value, index) { return delayDurationSelector(value, index).pipe(take(1), mapTo(value)); });
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
function delay(due, scheduler) {
|
|
1622
|
+
if (scheduler === void 0) { scheduler = asyncScheduler; }
|
|
1623
|
+
var duration = timer(due, scheduler);
|
|
1624
|
+
return delayWhen(function () { return duration; });
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
function distinctUntilChanged(comparator, keySelector) {
|
|
1628
|
+
if (keySelector === void 0) { keySelector = identity; }
|
|
1629
|
+
comparator = comparator !== null && comparator !== void 0 ? comparator : defaultCompare;
|
|
1630
|
+
return operate(function (source, subscriber) {
|
|
1631
|
+
var previousKey;
|
|
1632
|
+
var first = true;
|
|
1633
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1634
|
+
var currentKey = keySelector(value);
|
|
1635
|
+
if (first || !comparator(previousKey, currentKey)) {
|
|
1636
|
+
first = false;
|
|
1637
|
+
previousKey = currentKey;
|
|
1638
|
+
subscriber.next(value);
|
|
1639
|
+
}
|
|
1640
|
+
}));
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
function defaultCompare(a, b) {
|
|
1644
|
+
return a === b;
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
function filter(predicate, thisArg) {
|
|
1648
|
+
return operate(function (source, subscriber) {
|
|
1649
|
+
var index = 0;
|
|
1650
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return predicate.call(thisArg, value, index++) && subscriber.next(value); }));
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
function skip(count) {
|
|
1655
|
+
return filter(function (_, index) { return count <= index; });
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
function startWith() {
|
|
1659
|
+
var values = [];
|
|
1660
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1661
|
+
values[_i] = arguments[_i];
|
|
184
1662
|
}
|
|
1663
|
+
var scheduler = popScheduler(values);
|
|
1664
|
+
return operate(function (source, subscriber) {
|
|
1665
|
+
(scheduler ? concat$1(values, source, scheduler) : concat$1(values, source)).subscribe(subscriber);
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
function switchMap(project, resultSelector) {
|
|
1670
|
+
return operate(function (source, subscriber) {
|
|
1671
|
+
var innerSubscriber = null;
|
|
1672
|
+
var index = 0;
|
|
1673
|
+
var isComplete = false;
|
|
1674
|
+
var checkComplete = function () { return isComplete && !innerSubscriber && subscriber.complete(); };
|
|
1675
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1676
|
+
innerSubscriber === null || innerSubscriber === void 0 ? void 0 : innerSubscriber.unsubscribe();
|
|
1677
|
+
var innerIndex = 0;
|
|
1678
|
+
var outerIndex = index++;
|
|
1679
|
+
innerFrom(project(value, outerIndex)).subscribe((innerSubscriber = createOperatorSubscriber(subscriber, function (innerValue) { return subscriber.next(resultSelector ? resultSelector(value, innerValue, outerIndex, innerIndex++) : innerValue); }, function () {
|
|
1680
|
+
innerSubscriber = null;
|
|
1681
|
+
checkComplete();
|
|
1682
|
+
})));
|
|
1683
|
+
}, function () {
|
|
1684
|
+
isComplete = true;
|
|
1685
|
+
checkComplete();
|
|
1686
|
+
}));
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
function tap(observerOrNext, error, complete) {
|
|
1691
|
+
var tapObserver = isFunction(observerOrNext) || error || complete
|
|
1692
|
+
?
|
|
1693
|
+
{ next: observerOrNext, error: error, complete: complete }
|
|
1694
|
+
: observerOrNext;
|
|
1695
|
+
return tapObserver
|
|
1696
|
+
? operate(function (source, subscriber) {
|
|
1697
|
+
var _a;
|
|
1698
|
+
(_a = tapObserver.subscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1699
|
+
var isUnsub = true;
|
|
1700
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1701
|
+
var _a;
|
|
1702
|
+
(_a = tapObserver.next) === null || _a === void 0 ? void 0 : _a.call(tapObserver, value);
|
|
1703
|
+
subscriber.next(value);
|
|
1704
|
+
}, function () {
|
|
1705
|
+
var _a;
|
|
1706
|
+
isUnsub = false;
|
|
1707
|
+
(_a = tapObserver.complete) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1708
|
+
subscriber.complete();
|
|
1709
|
+
}, function (err) {
|
|
1710
|
+
var _a;
|
|
1711
|
+
isUnsub = false;
|
|
1712
|
+
(_a = tapObserver.error) === null || _a === void 0 ? void 0 : _a.call(tapObserver, err);
|
|
1713
|
+
subscriber.error(err);
|
|
1714
|
+
}, function () {
|
|
1715
|
+
var _a, _b;
|
|
1716
|
+
if (isUnsub) {
|
|
1717
|
+
(_a = tapObserver.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1718
|
+
}
|
|
1719
|
+
(_b = tapObserver.finalize) === null || _b === void 0 ? void 0 : _b.call(tapObserver);
|
|
1720
|
+
}));
|
|
1721
|
+
})
|
|
1722
|
+
:
|
|
1723
|
+
identity;
|
|
185
1724
|
}
|
|
186
1725
|
|
|
187
1726
|
//const hasSW = 'serviceWorker' in navigator;
|
|
@@ -244,6 +1783,7 @@
|
|
|
244
1783
|
|
|
245
1784
|
function triggerSync(db, purpose) {
|
|
246
1785
|
if (db.cloud.usingServiceWorker) {
|
|
1786
|
+
console.debug('registering sync event');
|
|
247
1787
|
registerSyncEvent(db, purpose);
|
|
248
1788
|
}
|
|
249
1789
|
else {
|
|
@@ -272,7 +1812,14 @@
|
|
|
272
1812
|
}
|
|
273
1813
|
}
|
|
274
1814
|
: (b) => {
|
|
275
|
-
|
|
1815
|
+
const u8a = ArrayBuffer.isView(b) ? b : new Uint8Array(b);
|
|
1816
|
+
const CHUNK_SIZE = 0x1000;
|
|
1817
|
+
const strs = [];
|
|
1818
|
+
for (let i = 0, l = u8a.length; i < l; i += CHUNK_SIZE) {
|
|
1819
|
+
const chunk = u8a.subarray(i, i + CHUNK_SIZE);
|
|
1820
|
+
strs.push(String.fromCharCode.apply(null, chunk));
|
|
1821
|
+
}
|
|
1822
|
+
return btoa(strs.join(""));
|
|
276
1823
|
};
|
|
277
1824
|
|
|
278
1825
|
function computeRealmSetHash({ realms, inviteRealms, }) {
|
|
@@ -745,14 +2292,24 @@
|
|
|
745
2292
|
return tablesToSyncify;
|
|
746
2293
|
}
|
|
747
2294
|
|
|
2295
|
+
class TokenErrorResponseError extends Error {
|
|
2296
|
+
constructor({ title, message, messageCode, messageParams, }) {
|
|
2297
|
+
super(message);
|
|
2298
|
+
this.name = 'TokenErrorResponseError';
|
|
2299
|
+
this.title = title;
|
|
2300
|
+
this.messageCode = messageCode;
|
|
2301
|
+
this.messageParams = messageParams;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
|
|
748
2305
|
function interactWithUser(userInteraction, req) {
|
|
749
2306
|
return new Promise((resolve, reject) => {
|
|
750
|
-
const interactionProps = Object.assign(Object.assign({}, req), { onSubmit: (res) => {
|
|
2307
|
+
const interactionProps = Object.assign(Object.assign({ submitLabel: 'Submit', cancelLabel: 'Cancel' }, req), { onSubmit: (res) => {
|
|
751
2308
|
userInteraction.next(undefined);
|
|
752
2309
|
resolve(res);
|
|
753
2310
|
}, onCancel: () => {
|
|
754
2311
|
userInteraction.next(undefined);
|
|
755
|
-
reject(new
|
|
2312
|
+
reject(new Dexie.AbortError('User cancelled'));
|
|
756
2313
|
} });
|
|
757
2314
|
userInteraction.next(interactionProps);
|
|
758
2315
|
// Start subscribing for external updates to db.cloud.userInteraction, and if so, cancel this request.
|
|
@@ -771,7 +2328,9 @@
|
|
|
771
2328
|
type: 'message-alert',
|
|
772
2329
|
title,
|
|
773
2330
|
alerts,
|
|
774
|
-
fields: {}
|
|
2331
|
+
fields: {},
|
|
2332
|
+
submitLabel: 'OK',
|
|
2333
|
+
cancelLabel: null,
|
|
775
2334
|
});
|
|
776
2335
|
}
|
|
777
2336
|
function promptForEmail(userInteraction, title, emailHint) {
|
|
@@ -830,22 +2389,48 @@
|
|
|
830
2389
|
return otp;
|
|
831
2390
|
});
|
|
832
2391
|
}
|
|
2392
|
+
function confirmLogout(userInteraction, currentUserId, numUnsyncedChanges) {
|
|
2393
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2394
|
+
const alerts = [
|
|
2395
|
+
{
|
|
2396
|
+
type: 'warning',
|
|
2397
|
+
messageCode: 'LOGOUT_CONFIRMATION',
|
|
2398
|
+
message: `{numUnsyncedChanges} unsynced changes will get lost!
|
|
2399
|
+
Logout anyway?`,
|
|
2400
|
+
messageParams: {
|
|
2401
|
+
currentUserId,
|
|
2402
|
+
numUnsyncedChanges: numUnsyncedChanges.toString(),
|
|
2403
|
+
}
|
|
2404
|
+
},
|
|
2405
|
+
];
|
|
2406
|
+
return yield interactWithUser(userInteraction, {
|
|
2407
|
+
type: 'logout-confirmation',
|
|
2408
|
+
title: 'Confirm Logout',
|
|
2409
|
+
alerts,
|
|
2410
|
+
fields: {},
|
|
2411
|
+
submitLabel: 'Confirm logout',
|
|
2412
|
+
cancelLabel: 'Cancel'
|
|
2413
|
+
})
|
|
2414
|
+
.then(() => true)
|
|
2415
|
+
.catch(() => false);
|
|
2416
|
+
});
|
|
2417
|
+
}
|
|
833
2418
|
|
|
834
2419
|
function loadAccessToken(db) {
|
|
835
|
-
var _a, _b;
|
|
2420
|
+
var _a, _b, _c;
|
|
836
2421
|
return __awaiter(this, void 0, void 0, function* () {
|
|
837
2422
|
const currentUser = yield db.getCurrentUser();
|
|
838
2423
|
const { accessToken, accessTokenExpiration, refreshToken, refreshTokenExpiration, claims, } = currentUser;
|
|
839
2424
|
if (!accessToken)
|
|
840
|
-
return;
|
|
2425
|
+
return null;
|
|
841
2426
|
const expTime = (_a = accessTokenExpiration === null || accessTokenExpiration === void 0 ? void 0 : accessTokenExpiration.getTime()) !== null && _a !== void 0 ? _a : Infinity;
|
|
842
|
-
if (expTime > Date.now()) {
|
|
843
|
-
return
|
|
2427
|
+
if (expTime > Date.now() && (((_b = currentUser.license) === null || _b === void 0 ? void 0 : _b.status) || 'ok') === 'ok') {
|
|
2428
|
+
return currentUser;
|
|
844
2429
|
}
|
|
845
2430
|
if (!refreshToken) {
|
|
846
2431
|
throw new Error(`Refresh token missing`);
|
|
847
2432
|
}
|
|
848
|
-
const refreshExpTime = (
|
|
2433
|
+
const refreshExpTime = (_c = refreshTokenExpiration === null || refreshTokenExpiration === void 0 ? void 0 : refreshTokenExpiration.getTime()) !== null && _c !== void 0 ? _c : Infinity;
|
|
849
2434
|
if (refreshExpTime <= Date.now()) {
|
|
850
2435
|
throw new Error(`Refresh token has expired`);
|
|
851
2436
|
}
|
|
@@ -853,8 +2438,10 @@
|
|
|
853
2438
|
yield db.table('$logins').update(claims.sub, {
|
|
854
2439
|
accessToken: refreshedLogin.accessToken,
|
|
855
2440
|
accessTokenExpiration: refreshedLogin.accessTokenExpiration,
|
|
2441
|
+
claims: refreshedLogin.claims,
|
|
2442
|
+
license: refreshedLogin.license,
|
|
856
2443
|
});
|
|
857
|
-
return refreshedLogin
|
|
2444
|
+
return refreshedLogin;
|
|
858
2445
|
});
|
|
859
2446
|
}
|
|
860
2447
|
function authenticate(url, context, fetchToken, userInteraction, hints) {
|
|
@@ -902,10 +2489,24 @@
|
|
|
902
2489
|
if (res.status !== 200)
|
|
903
2490
|
throw new Error(`RefreshToken: Status ${res.status} from ${url}/token`);
|
|
904
2491
|
const response = yield res.json();
|
|
2492
|
+
if (response.type === 'error') {
|
|
2493
|
+
throw new TokenErrorResponseError(response);
|
|
2494
|
+
}
|
|
905
2495
|
login.accessToken = response.accessToken;
|
|
906
2496
|
login.accessTokenExpiration = response.accessTokenExpiration
|
|
907
2497
|
? new Date(response.accessTokenExpiration)
|
|
908
2498
|
: undefined;
|
|
2499
|
+
login.claims = response.claims;
|
|
2500
|
+
login.license = {
|
|
2501
|
+
type: response.userType,
|
|
2502
|
+
status: response.claims.license || 'ok',
|
|
2503
|
+
};
|
|
2504
|
+
if (response.evalDaysLeft != null) {
|
|
2505
|
+
login.license.evalDaysLeft = response.evalDaysLeft;
|
|
2506
|
+
}
|
|
2507
|
+
if (response.userValidUntil != null) {
|
|
2508
|
+
login.license.validUntil = new Date(response.userValidUntil);
|
|
2509
|
+
}
|
|
909
2510
|
return login;
|
|
910
2511
|
});
|
|
911
2512
|
}
|
|
@@ -937,8 +2538,15 @@
|
|
|
937
2538
|
public_key: publicKeyPEM,
|
|
938
2539
|
hints,
|
|
939
2540
|
});
|
|
2541
|
+
if (response2.type === 'error') {
|
|
2542
|
+
throw new TokenErrorResponseError(response2);
|
|
2543
|
+
}
|
|
940
2544
|
if (response2.type !== 'tokens')
|
|
941
2545
|
throw new Error(`Unexpected response type from token endpoint: ${response2.type}`);
|
|
2546
|
+
/*const licenseStatus = response2.claims.license || 'ok';
|
|
2547
|
+
if (licenseStatus !== 'ok') {
|
|
2548
|
+
throw new InvalidLicenseError(licenseStatus);
|
|
2549
|
+
}*/
|
|
942
2550
|
context.accessToken = response2.accessToken;
|
|
943
2551
|
context.accessTokenExpiration = new Date(response2.accessTokenExpiration);
|
|
944
2552
|
context.refreshToken = response2.refreshToken;
|
|
@@ -949,6 +2557,16 @@
|
|
|
949
2557
|
context.email = response2.claims.email;
|
|
950
2558
|
context.name = response2.claims.name;
|
|
951
2559
|
context.claims = response2.claims;
|
|
2560
|
+
context.license = {
|
|
2561
|
+
type: response2.userType,
|
|
2562
|
+
status: response2.claims.license || 'ok',
|
|
2563
|
+
};
|
|
2564
|
+
if (response2.evalDaysLeft != null) {
|
|
2565
|
+
context.license.evalDaysLeft = response2.evalDaysLeft;
|
|
2566
|
+
}
|
|
2567
|
+
if (response2.userValidUntil != null) {
|
|
2568
|
+
context.license.validUntil = new Date(response2.userValidUntil);
|
|
2569
|
+
}
|
|
952
2570
|
if (response2.alerts && response2.alerts.length > 0) {
|
|
953
2571
|
yield interactWithUser(userInteraction, {
|
|
954
2572
|
type: 'message-alert',
|
|
@@ -960,12 +2578,36 @@
|
|
|
960
2578
|
return context;
|
|
961
2579
|
}
|
|
962
2580
|
catch (error) {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
2581
|
+
if (error instanceof TokenErrorResponseError) {
|
|
2582
|
+
yield alertUser(userInteraction, error.title, {
|
|
2583
|
+
type: 'error',
|
|
2584
|
+
messageCode: error.messageCode,
|
|
2585
|
+
message: error.message,
|
|
2586
|
+
messageParams: {},
|
|
2587
|
+
});
|
|
2588
|
+
throw error;
|
|
2589
|
+
}
|
|
2590
|
+
let message = `We're having a problem authenticating right now.`;
|
|
2591
|
+
console.error(`Error authenticating`, error);
|
|
2592
|
+
if (error instanceof TypeError) {
|
|
2593
|
+
const isOffline = typeof navigator !== undefined && !navigator.onLine;
|
|
2594
|
+
if (isOffline) {
|
|
2595
|
+
message = `You seem to be offline. Please connect to the internet and try again.`;
|
|
2596
|
+
}
|
|
2597
|
+
else if (Dexie.debug || (typeof location !== 'undefined' && (location.hostname === 'localhost' || location.hostname === '127.0.0.1'))) {
|
|
2598
|
+
// The audience is most likely the developer. Suggest to whitelist the localhost origin:
|
|
2599
|
+
message = `Could not connect to server. Please verify that your origin '${location.origin}' is whitelisted using \`npx dexie-cloud whitelist\``;
|
|
2600
|
+
}
|
|
2601
|
+
else {
|
|
2602
|
+
message = `Could not connect to server. Please verify the connection.`;
|
|
2603
|
+
}
|
|
2604
|
+
yield alertUser(userInteraction, 'Authentication Failed', {
|
|
2605
|
+
type: 'error',
|
|
2606
|
+
messageCode: 'GENERIC_ERROR',
|
|
2607
|
+
message,
|
|
2608
|
+
messageParams: {},
|
|
2609
|
+
}).catch(() => { });
|
|
2610
|
+
}
|
|
969
2611
|
throw error;
|
|
970
2612
|
}
|
|
971
2613
|
});
|
|
@@ -1187,13 +2829,13 @@
|
|
|
1187
2829
|
},
|
|
1188
2830
|
};
|
|
1189
2831
|
|
|
1190
|
-
const _global = typeof globalThis !== "undefined"
|
|
2832
|
+
const _global = typeof globalThis !== "undefined" // All modern environments (node, bun, deno, browser, workers, webview etc)
|
|
1191
2833
|
? globalThis
|
|
1192
|
-
: typeof self !== "undefined"
|
|
2834
|
+
: typeof self !== "undefined" // Older browsers, workers, webview, window etc
|
|
1193
2835
|
? self
|
|
1194
|
-
: typeof global
|
|
2836
|
+
: typeof global !== "undefined" // Older versions of node
|
|
1195
2837
|
? global
|
|
1196
|
-
: undefined;
|
|
2838
|
+
: undefined; // Unsupported environment. No idea to return 'this' since we are in a module or a function scope anyway.
|
|
1197
2839
|
|
|
1198
2840
|
var TypedArraysDefs = [
|
|
1199
2841
|
"Int8Array",
|
|
@@ -1569,7 +3211,7 @@
|
|
|
1569
3211
|
const rewrittenKey = `${key}:${currentUser.userId}`;
|
|
1570
3212
|
mutClone.keys[keyIndex] = rewrittenKey;
|
|
1571
3213
|
if (rewriteValues) {
|
|
1572
|
-
|
|
3214
|
+
Dexie.setByKeyPath(mutClone.values[keyIndex], primaryKey.keyPath, rewrittenKey);
|
|
1573
3215
|
}
|
|
1574
3216
|
}
|
|
1575
3217
|
});
|
|
@@ -1588,6 +3230,40 @@
|
|
|
1588
3230
|
: change.muts.map((m) => (Object.assign(Object.assign({}, m), { keys: m.keys.slice() }))) });
|
|
1589
3231
|
}
|
|
1590
3232
|
|
|
3233
|
+
// If we get Ratelimit-Limit and Ratelimit-Remaining where Ratelimit-Remaining is below
|
|
3234
|
+
// (Ratelimit-Limit / 2), we should delay the next sync by (Ratelimit-Reset / Ratelimit-Remaining)
|
|
3235
|
+
// seconds (given that there is a Ratelimit-Reset header).
|
|
3236
|
+
let syncRatelimitDelays = new WeakMap();
|
|
3237
|
+
function checkSyncRateLimitDelay(db) {
|
|
3238
|
+
var _a, _b;
|
|
3239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3240
|
+
const delatMilliseconds = ((_b = (_a = syncRatelimitDelays.get(db)) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : 0) - Date.now();
|
|
3241
|
+
if (delatMilliseconds > 0) {
|
|
3242
|
+
console.debug(`Stalling sync request ${delatMilliseconds} ms to spare ratelimits`);
|
|
3243
|
+
yield new Promise(resolve => setTimeout(resolve, delatMilliseconds));
|
|
3244
|
+
}
|
|
3245
|
+
});
|
|
3246
|
+
}
|
|
3247
|
+
function updateSyncRateLimitDelays(db, res) {
|
|
3248
|
+
const limit = res.headers.get('Ratelimit-Limit');
|
|
3249
|
+
const remaining = res.headers.get('Ratelimit-Remaining');
|
|
3250
|
+
const reset = res.headers.get('Ratelimit-Reset');
|
|
3251
|
+
if (limit && remaining && reset) {
|
|
3252
|
+
const limitNum = Number(limit);
|
|
3253
|
+
const remainingNum = Math.max(0, Number(remaining));
|
|
3254
|
+
const willResetInSeconds = Number(reset);
|
|
3255
|
+
if (remainingNum < limitNum / 2) {
|
|
3256
|
+
const delay = Math.ceil(willResetInSeconds / (remainingNum + 1));
|
|
3257
|
+
syncRatelimitDelays.set(db, new Date(Date.now() + delay * 1000));
|
|
3258
|
+
console.debug(`Sync ratelimit delay set to ${delay} seconds`);
|
|
3259
|
+
}
|
|
3260
|
+
else {
|
|
3261
|
+
syncRatelimitDelays.delete(db);
|
|
3262
|
+
console.debug(`Sync ratelimit delay cleared`);
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
|
|
1591
3267
|
//import {BisonWebStreamReader} from "dreambase-library/dist/typeson-simplified/BisonWebStreamReader";
|
|
1592
3268
|
function syncWithServer(changes, syncState, baseRevs, db, databaseUrl, schema, clientIdentity, currentUser) {
|
|
1593
3269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1596,9 +3272,20 @@
|
|
|
1596
3272
|
//
|
|
1597
3273
|
const headers = {
|
|
1598
3274
|
Accept: 'application/json, application/x-bison, application/x-bison-stream',
|
|
1599
|
-
'Content-Type': 'application/tson'
|
|
3275
|
+
'Content-Type': 'application/tson',
|
|
1600
3276
|
};
|
|
1601
|
-
const
|
|
3277
|
+
const updatedUser = yield loadAccessToken(db);
|
|
3278
|
+
/*
|
|
3279
|
+
if (updatedUser?.license && changes.length > 0) {
|
|
3280
|
+
if (updatedUser.license.status === 'expired') {
|
|
3281
|
+
throw new Error(`License has expired`);
|
|
3282
|
+
}
|
|
3283
|
+
if (updatedUser.license.status === 'deactivated') {
|
|
3284
|
+
throw new Error(`License deactivated`);
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
*/
|
|
3288
|
+
const accessToken = updatedUser === null || updatedUser === void 0 ? void 0 : updatedUser.accessToken;
|
|
1602
3289
|
if (accessToken) {
|
|
1603
3290
|
headers.Authorization = `Bearer ${accessToken}`;
|
|
1604
3291
|
}
|
|
@@ -1607,27 +3294,31 @@
|
|
|
1607
3294
|
dbID: syncState === null || syncState === void 0 ? void 0 : syncState.remoteDbId,
|
|
1608
3295
|
clientIdentity,
|
|
1609
3296
|
schema: schema || {},
|
|
1610
|
-
lastPull: syncState
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
3297
|
+
lastPull: syncState
|
|
3298
|
+
? {
|
|
3299
|
+
serverRevision: syncState.serverRevision,
|
|
3300
|
+
realms: syncState.realms,
|
|
3301
|
+
inviteRealms: syncState.inviteRealms,
|
|
3302
|
+
}
|
|
3303
|
+
: undefined,
|
|
1615
3304
|
baseRevs,
|
|
1616
|
-
changes: encodeIdsForServer(db.dx.core.schema, currentUser, changes)
|
|
3305
|
+
changes: encodeIdsForServer(db.dx.core.schema, currentUser, changes),
|
|
1617
3306
|
};
|
|
1618
|
-
console.debug(
|
|
3307
|
+
console.debug('Sync request', syncRequest);
|
|
1619
3308
|
db.syncStateChangedEvent.next({
|
|
1620
3309
|
phase: 'pushing',
|
|
1621
3310
|
});
|
|
1622
3311
|
const res = yield fetch(`${databaseUrl}/sync`, {
|
|
1623
3312
|
method: 'post',
|
|
1624
3313
|
headers,
|
|
1625
|
-
|
|
3314
|
+
credentials: 'include',
|
|
3315
|
+
body: TSON.stringify(syncRequest),
|
|
1626
3316
|
});
|
|
1627
3317
|
//const contentLength = Number(res.headers.get('content-length'));
|
|
1628
3318
|
db.syncStateChangedEvent.next({
|
|
1629
|
-
phase: 'pulling'
|
|
3319
|
+
phase: 'pulling',
|
|
1630
3320
|
});
|
|
3321
|
+
updateSyncRateLimitDelays(db, res);
|
|
1631
3322
|
if (!res.ok) {
|
|
1632
3323
|
throw new HttpError(res);
|
|
1633
3324
|
}
|
|
@@ -1684,7 +3375,7 @@
|
|
|
1684
3375
|
|
|
1685
3376
|
function throwIfCancelled(cancelToken) {
|
|
1686
3377
|
if (cancelToken === null || cancelToken === void 0 ? void 0 : cancelToken.cancelled)
|
|
1687
|
-
throw new
|
|
3378
|
+
throw new Dexie.AbortError(`Operation was cancelled`);
|
|
1688
3379
|
}
|
|
1689
3380
|
|
|
1690
3381
|
/* Need this because navigator.onLine seems to say "false" when it is actually online.
|
|
@@ -1736,7 +3427,7 @@
|
|
|
1736
3427
|
}
|
|
1737
3428
|
}
|
|
1738
3429
|
else {
|
|
1739
|
-
|
|
3430
|
+
Dexie.setByKeyPath(obj, keyPath, value);
|
|
1740
3431
|
}
|
|
1741
3432
|
}
|
|
1742
3433
|
resultKeys.push(key);
|
|
@@ -1751,7 +3442,7 @@
|
|
|
1751
3442
|
|
|
1752
3443
|
function applyServerChanges(changes, db) {
|
|
1753
3444
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1754
|
-
console.debug('Applying server changes', changes,
|
|
3445
|
+
console.debug('Applying server changes', changes, Dexie.currentTransaction);
|
|
1755
3446
|
for (const { table: tableName, muts } of changes) {
|
|
1756
3447
|
const table = db.table(tableName);
|
|
1757
3448
|
if (!table)
|
|
@@ -1788,7 +3479,7 @@
|
|
|
1788
3479
|
else {
|
|
1789
3480
|
keys.forEach((key, i) => {
|
|
1790
3481
|
// Make sure inbound keys are consistent
|
|
1791
|
-
|
|
3482
|
+
Dexie.setByKeyPath(mut.values[i], primaryKey.keyPath, key);
|
|
1792
3483
|
});
|
|
1793
3484
|
yield table.bulkAdd(mut.values);
|
|
1794
3485
|
}
|
|
@@ -1800,7 +3491,7 @@
|
|
|
1800
3491
|
else {
|
|
1801
3492
|
keys.forEach((key, i) => {
|
|
1802
3493
|
// Make sure inbound keys are consistent
|
|
1803
|
-
|
|
3494
|
+
Dexie.setByKeyPath(mut.values[i], primaryKey.keyPath, key);
|
|
1804
3495
|
});
|
|
1805
3496
|
yield table.bulkPut(mut.values);
|
|
1806
3497
|
}
|
|
@@ -1829,12 +3520,13 @@
|
|
|
1829
3520
|
function sync(db, options, schema, syncOptions) {
|
|
1830
3521
|
return _sync
|
|
1831
3522
|
.apply(this, arguments)
|
|
1832
|
-
.then(() => {
|
|
3523
|
+
.then((result) => {
|
|
1833
3524
|
if (!(syncOptions === null || syncOptions === void 0 ? void 0 : syncOptions.justCheckIfNeeded)) { // && syncOptions?.purpose !== 'push') {
|
|
1834
3525
|
db.syncStateChangedEvent.next({
|
|
1835
3526
|
phase: 'in-sync',
|
|
1836
3527
|
});
|
|
1837
3528
|
}
|
|
3529
|
+
return result;
|
|
1838
3530
|
})
|
|
1839
3531
|
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
1840
3532
|
if (syncOptions === null || syncOptions === void 0 ? void 0 : syncOptions.justCheckIfNeeded)
|
|
@@ -2049,6 +3741,7 @@
|
|
|
2049
3741
|
}));
|
|
2050
3742
|
if (!done) {
|
|
2051
3743
|
console.debug('MORE SYNC NEEDED. Go for it again!');
|
|
3744
|
+
yield checkSyncRateLimitDelay(db);
|
|
2052
3745
|
return yield _sync(db, options, schema, { isInitialSync, cancelToken });
|
|
2053
3746
|
}
|
|
2054
3747
|
console.debug('SYNC DONE', { isInitialSync });
|
|
@@ -2168,7 +3861,7 @@
|
|
|
2168
3861
|
// It's no need to have two channels at the same time - even though it wouldnt
|
|
2169
3862
|
// be a problem - this is an optimization.
|
|
2170
3863
|
yield db.cloud.syncState
|
|
2171
|
-
.pipe(
|
|
3864
|
+
.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error'), take(1))
|
|
2172
3865
|
.toPromise();
|
|
2173
3866
|
console.debug('processing msg', msg);
|
|
2174
3867
|
const persistedSyncState = db.cloud.persistedSyncState.value;
|
|
@@ -2185,6 +3878,8 @@
|
|
|
2185
3878
|
yield db.table('$logins').update(user.userId, {
|
|
2186
3879
|
accessToken: refreshedLogin.accessToken,
|
|
2187
3880
|
accessTokenExpiration: refreshedLogin.accessTokenExpiration,
|
|
3881
|
+
claims: refreshedLogin.claims,
|
|
3882
|
+
license: refreshedLogin.license,
|
|
2188
3883
|
});
|
|
2189
3884
|
// Updating $logins will trigger emission of db.cloud.currentUser observable, which
|
|
2190
3885
|
// in turn will lead to that connectWebSocket.ts will reconnect the socket with the
|
|
@@ -2261,7 +3956,7 @@
|
|
|
2261
3956
|
return; // Ignore message
|
|
2262
3957
|
}
|
|
2263
3958
|
// Verify also that the message is based on the exact same set of realms
|
|
2264
|
-
const ourRealmSetHash = yield
|
|
3959
|
+
const ourRealmSetHash = yield Dexie.waitFor(
|
|
2265
3960
|
// Keep TX in non-IDB work
|
|
2266
3961
|
computeRealmSetHash(syncState));
|
|
2267
3962
|
console.debug('ourRealmSetHash', ourRealmSetHash);
|
|
@@ -2455,6 +4150,61 @@
|
|
|
2455
4150
|
}
|
|
2456
4151
|
}
|
|
2457
4152
|
|
|
4153
|
+
function waitUntil(o, // Works with Dexie's liveQuery observables if we'd need that
|
|
4154
|
+
predicate) {
|
|
4155
|
+
return rxjs.firstValueFrom(rxjs.from(o).pipe(rxjs.filter(predicate)));
|
|
4156
|
+
}
|
|
4157
|
+
|
|
4158
|
+
function logout(db) {
|
|
4159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4160
|
+
const numUnsyncedChanges = yield _logout(db);
|
|
4161
|
+
if (numUnsyncedChanges) {
|
|
4162
|
+
if (yield confirmLogout(db.cloud.userInteraction, db.cloud.currentUserId, numUnsyncedChanges)) {
|
|
4163
|
+
yield _logout(db, { deleteUnsyncedData: true });
|
|
4164
|
+
}
|
|
4165
|
+
else {
|
|
4166
|
+
throw new Error(`User cancelled logout due to unsynced changes`);
|
|
4167
|
+
}
|
|
4168
|
+
}
|
|
4169
|
+
});
|
|
4170
|
+
}
|
|
4171
|
+
function _logout(db, { deleteUnsyncedData = false } = {}) {
|
|
4172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4173
|
+
// Clear the database without emptying configuration options.
|
|
4174
|
+
const [numUnsynced, loggedOut] = yield db.dx.transaction('rw', db.dx.tables, (tx) => __awaiter(this, void 0, void 0, function* () {
|
|
4175
|
+
// @ts-ignore
|
|
4176
|
+
const idbtrans = tx.idbtrans;
|
|
4177
|
+
idbtrans.disableChangeTracking = true;
|
|
4178
|
+
idbtrans.disableAccessControl = true;
|
|
4179
|
+
const mutationTables = tx.storeNames.filter((tableName) => tableName.endsWith('_mutations'));
|
|
4180
|
+
// Count unsynced changes
|
|
4181
|
+
const unsyncCounts = yield Promise.all(mutationTables.map((mutationTable) => tx.table(mutationTable).count()));
|
|
4182
|
+
const sumUnSynced = unsyncCounts.reduce((a, b) => a + b, 0);
|
|
4183
|
+
if (sumUnSynced > 0 && !deleteUnsyncedData) {
|
|
4184
|
+
// Let caller ask user if they want to delete unsynced data.
|
|
4185
|
+
return [sumUnSynced, false];
|
|
4186
|
+
}
|
|
4187
|
+
// Either there are no unsynched changes, or caller provided flag deleteUnsynchedData = true.
|
|
4188
|
+
// Clear all tables except $jobs and $syncState (except the persisted sync state which is
|
|
4189
|
+
// also cleared because we're going to rebuild it using a fresh sync).
|
|
4190
|
+
db.$syncState.delete('syncState');
|
|
4191
|
+
for (const table of db.dx.tables) {
|
|
4192
|
+
if (table.name !== '$jobs' && table.name !== '$syncState') {
|
|
4193
|
+
table.clear();
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
return [sumUnSynced, true];
|
|
4197
|
+
}));
|
|
4198
|
+
if (loggedOut) {
|
|
4199
|
+
// Wait for currentUser observable to emit UNAUTHORIZED_USER
|
|
4200
|
+
yield waitUntil(db.cloud.currentUser, (user) => user.userId === UNAUTHORIZED_USER.userId);
|
|
4201
|
+
// Then perform an initial sync
|
|
4202
|
+
yield db.cloud.sync({ purpose: 'pull', wait: true });
|
|
4203
|
+
}
|
|
4204
|
+
return numUnsynced;
|
|
4205
|
+
});
|
|
4206
|
+
}
|
|
4207
|
+
|
|
2458
4208
|
function otpFetchTokenCallback(db) {
|
|
2459
4209
|
const { userInteraction } = db.cloud;
|
|
2460
4210
|
return function otpAuthenticate({ public_key, hints }) {
|
|
@@ -2498,8 +4248,9 @@
|
|
|
2498
4248
|
throw new HttpError(res1, errMsg);
|
|
2499
4249
|
}
|
|
2500
4250
|
const response = yield res1.json();
|
|
2501
|
-
if (response.type === 'tokens') {
|
|
4251
|
+
if (response.type === 'tokens' || response.type === 'error') {
|
|
2502
4252
|
// Demo user request can get a "tokens" response right away
|
|
4253
|
+
// Error can also be returned right away.
|
|
2503
4254
|
return response;
|
|
2504
4255
|
}
|
|
2505
4256
|
else if (tokenRequest.grant_type === 'otp') {
|
|
@@ -2531,12 +4282,6 @@
|
|
|
2531
4282
|
}
|
|
2532
4283
|
if (res2.status !== 200) {
|
|
2533
4284
|
const errMsg = yield res2.text();
|
|
2534
|
-
yield alertUser(userInteraction, "OTP Authentication Failed", {
|
|
2535
|
-
type: 'error',
|
|
2536
|
-
messageCode: 'GENERIC_ERROR',
|
|
2537
|
-
message: errMsg,
|
|
2538
|
-
messageParams: {}
|
|
2539
|
-
}).catch(() => { });
|
|
2540
4285
|
throw new HttpError(res2, errMsg);
|
|
2541
4286
|
}
|
|
2542
4287
|
const response2 = yield res2.json();
|
|
@@ -2549,6 +4294,18 @@
|
|
|
2549
4294
|
};
|
|
2550
4295
|
}
|
|
2551
4296
|
|
|
4297
|
+
/** A way to log to console in production without terser stripping out
|
|
4298
|
+
* it from the release bundle.
|
|
4299
|
+
* This should be used very rarely and only in places where it's
|
|
4300
|
+
* absolutely necessary to log something in production.
|
|
4301
|
+
*
|
|
4302
|
+
* @param level
|
|
4303
|
+
* @param args
|
|
4304
|
+
*/
|
|
4305
|
+
function prodLog(level, ...args) {
|
|
4306
|
+
globalThis["con" + "sole"][level](...args);
|
|
4307
|
+
}
|
|
4308
|
+
|
|
2552
4309
|
/** This function changes or sets the current user as requested.
|
|
2553
4310
|
*
|
|
2554
4311
|
* Use cases:
|
|
@@ -2575,85 +4332,73 @@
|
|
|
2575
4332
|
}));
|
|
2576
4333
|
user.isLoggedIn = true;
|
|
2577
4334
|
user.lastLogin = new Date();
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
}));
|
|
2581
|
-
yield new Promise((resolve) => {
|
|
2582
|
-
if (db.cloud.currentUserId === user.userId) {
|
|
2583
|
-
resolve(null);
|
|
4335
|
+
try {
|
|
4336
|
+
yield user.save();
|
|
2584
4337
|
}
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
if (
|
|
2588
|
-
|
|
2589
|
-
|
|
4338
|
+
catch (e) {
|
|
4339
|
+
try {
|
|
4340
|
+
if (e.name === 'DataCloneError') {
|
|
4341
|
+
// We've seen this buggy behavior in some browsers and in case it happens
|
|
4342
|
+
// again we really need to collect the details to understand what's going on.
|
|
4343
|
+
prodLog('debug', `Login context property names:`, Object.keys(user));
|
|
4344
|
+
prodLog('debug', `Login context property names:`, Object.keys(user));
|
|
4345
|
+
prodLog('debug', `Login context:`, user);
|
|
4346
|
+
prodLog('debug', `Login context JSON:`, JSON.stringify(user));
|
|
2590
4347
|
}
|
|
2591
|
-
}
|
|
4348
|
+
}
|
|
4349
|
+
catch (_a) { }
|
|
4350
|
+
throw e;
|
|
2592
4351
|
}
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
// V: Samma med andra windows.
|
|
2597
|
-
// V: Så kanske göra om den till att häröra från liveQuery som läser $logins.orderBy('lastLogin').last().
|
|
2598
|
-
// V: Då bara vara medveten om:
|
|
2599
|
-
// V: En sån observable börjar hämta data vid första subscribe
|
|
2600
|
-
// V: Vi har inget "inital value" men kan emulera det till att vara ANONYMOUS_USER
|
|
2601
|
-
// V: Om requireAuth är true, så borde db.on(ready) hålla databasen stängd för alla utom denna observable.
|
|
2602
|
-
// V: Om inte så behöver den inte blocka.
|
|
2603
|
-
// Andra tankar:
|
|
2604
|
-
// * Man kan inte byta användare när man är offline. Skulle gå att flytta realms till undanstuff-tabell vid user-change.
|
|
2605
|
-
// men troligen inte värt det.
|
|
2606
|
-
// * Istället: sälj inte inte switch-user funktionalitet utan tala enbart om inloggat vs icke inloggat läge.
|
|
2607
|
-
// * populate $logins med ANONYMOUS så att en påbörjad inloggning inte räknas, alternativt ha en boolean prop!
|
|
2608
|
-
// Kanske bäst ha en boolean prop!
|
|
2609
|
-
// * Alternativ switch-user funktionalitet:
|
|
2610
|
-
// * DBCore gömmer data från realms man inte har tillgång till.
|
|
2611
|
-
// * Cursor impl behövs också då.
|
|
2612
|
-
// * Då blir det snabba user switch.
|
|
2613
|
-
// * claims-settet som skickas till servern blir summan av alla claims. Då måste servern stödja multipla tokens eller
|
|
2614
|
-
// att ens token är ett samlad.
|
|
4352
|
+
console.debug('Saved new user', user.email);
|
|
4353
|
+
}));
|
|
4354
|
+
yield waitUntil(db.cloud.currentUser, (currentUser) => currentUser.userId === user.userId);
|
|
2615
4355
|
});
|
|
2616
4356
|
}
|
|
2617
4357
|
|
|
2618
4358
|
function login(db, hints) {
|
|
4359
|
+
var _a;
|
|
2619
4360
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2620
4361
|
const currentUser = yield db.getCurrentUser();
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
throw new Error(`Must logout before changing user`);
|
|
2628
|
-
}
|
|
4362
|
+
const origUserId = currentUser.userId;
|
|
4363
|
+
if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
|
|
4364
|
+
const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
|
|
4365
|
+
if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
|
|
4366
|
+
// Already authenticated according to given hints. And license is valid.
|
|
4367
|
+
return false;
|
|
2629
4368
|
}
|
|
2630
|
-
|
|
2631
|
-
|
|
4369
|
+
if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
|
|
4370
|
+
// Refresh the token
|
|
4371
|
+
yield loadAccessToken(db);
|
|
4372
|
+
return false;
|
|
4373
|
+
}
|
|
4374
|
+
// No refresh token - must re-authenticate:
|
|
2632
4375
|
}
|
|
2633
4376
|
const context = new AuthPersistedContext(db, {
|
|
2634
4377
|
claims: {},
|
|
2635
4378
|
lastLogin: new Date(0),
|
|
2636
4379
|
});
|
|
2637
4380
|
yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
|
|
2638
|
-
|
|
2639
|
-
|
|
4381
|
+
if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
|
|
4382
|
+
// User was logged in before, but now logged in as another user.
|
|
4383
|
+
yield logout(db);
|
|
2640
4384
|
}
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
4385
|
+
/*try {
|
|
4386
|
+
await context.save();
|
|
4387
|
+
} catch (e) {
|
|
4388
|
+
try {
|
|
4389
|
+
if (e.name === 'DataCloneError') {
|
|
4390
|
+
console.debug(`Login context property names:`, Object.keys(context));
|
|
4391
|
+
console.debug(`Login context:`, context);
|
|
4392
|
+
console.debug(`Login context JSON:`, JSON.stringify(context));
|
|
2648
4393
|
}
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
}
|
|
4394
|
+
} catch {}
|
|
4395
|
+
throw e;
|
|
4396
|
+
}*/
|
|
2652
4397
|
yield setCurrentUser(db, context);
|
|
2653
4398
|
// Make sure to resync as the new login will be authorized
|
|
2654
4399
|
// for new realms.
|
|
2655
4400
|
triggerSync(db, "pull");
|
|
2656
|
-
return
|
|
4401
|
+
return context.userId !== origUserId;
|
|
2657
4402
|
});
|
|
2658
4403
|
}
|
|
2659
4404
|
|
|
@@ -2697,7 +4442,7 @@
|
|
|
2697
4442
|
const IS_SERVICE_WORKER = typeof self !== "undefined" && "clients" in self && !self.document;
|
|
2698
4443
|
|
|
2699
4444
|
function throwVersionIncrementNeeded() {
|
|
2700
|
-
throw new
|
|
4445
|
+
throw new Dexie.SchemaError(`Version increment needed to allow dexie-cloud change tracking`);
|
|
2701
4446
|
}
|
|
2702
4447
|
|
|
2703
4448
|
const { toString } = {};
|
|
@@ -2813,14 +4558,14 @@
|
|
|
2813
4558
|
if (!table.schema.primaryKey.outbound) {
|
|
2814
4559
|
if (!valueClones)
|
|
2815
4560
|
valueClones = req.values.slice();
|
|
2816
|
-
valueClones[idx] =
|
|
2817
|
-
|
|
4561
|
+
valueClones[idx] = Dexie.deepClone(valueClones[idx]);
|
|
4562
|
+
Dexie.setByKeyPath(valueClones[idx], table.schema.primaryKey.keyPath, keys[idx]);
|
|
2818
4563
|
}
|
|
2819
4564
|
}
|
|
2820
4565
|
else if (typeof key !== 'string' ||
|
|
2821
4566
|
(!key.startsWith(idPrefix) && !key.startsWith('#' + idPrefix))) {
|
|
2822
4567
|
// Key was specified by caller. Verify it complies with id prefix.
|
|
2823
|
-
throw new
|
|
4568
|
+
throw new Dexie.ConstraintError(`The ID "${key}" is not valid for table "${tableName}". ` +
|
|
2824
4569
|
`Primary '@' keys requires the key to be prefixed with "${idPrefix}" (or "#${idPrefix}).\n` +
|
|
2825
4570
|
`If you want to generate IDs programmatically, remove '@' from the schema to get rid of this constraint. Dexie Cloud supports custom IDs as long as they are random and globally unique.`);
|
|
2826
4571
|
}
|
|
@@ -2845,7 +4590,7 @@
|
|
|
2845
4590
|
const type = Array.isArray(key)
|
|
2846
4591
|
? key.map(toStringTag).join(',')
|
|
2847
4592
|
: toStringTag(key);
|
|
2848
|
-
throw new
|
|
4593
|
+
throw new Dexie.ConstraintError(`Invalid primary key type ${type} for table ${tableName}. Tables marked for sync has primary keys of type string or Array of string (and optional numbers)`);
|
|
2849
4594
|
}
|
|
2850
4595
|
});
|
|
2851
4596
|
}
|
|
@@ -2982,6 +4727,13 @@
|
|
|
2982
4727
|
|
|
2983
4728
|
const outstandingTransactions = new rxjs.BehaviorSubject(new Set());
|
|
2984
4729
|
|
|
4730
|
+
function isEagerSyncDisabled(db) {
|
|
4731
|
+
var _a, _b, _c, _d;
|
|
4732
|
+
return (((_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.disableEagerSync) ||
|
|
4733
|
+
((_c = (_b = db.cloud.currentUser.value) === null || _b === void 0 ? void 0 : _b.license) === null || _c === void 0 ? void 0 : _c.status) !== 'ok' ||
|
|
4734
|
+
!((_d = db.cloud.options) === null || _d === void 0 ? void 0 : _d.databaseUrl));
|
|
4735
|
+
}
|
|
4736
|
+
|
|
2985
4737
|
/** Tracks all mutations in the same transaction as the mutations -
|
|
2986
4738
|
* so it is guaranteed that no mutation goes untracked - and if transaction
|
|
2987
4739
|
* aborts, the mutations won't be tracked.
|
|
@@ -2990,7 +4742,7 @@
|
|
|
2990
4742
|
* changes to server and cleanup the tracked mutations once the server has
|
|
2991
4743
|
* ackowledged that it got them.
|
|
2992
4744
|
*/
|
|
2993
|
-
function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
4745
|
+
function createMutationTrackingMiddleware({ currentUserObservable, db, }) {
|
|
2994
4746
|
return {
|
|
2995
4747
|
stack: 'dbcore',
|
|
2996
4748
|
name: 'MutationTrackingMiddleware',
|
|
@@ -3001,7 +4753,7 @@
|
|
|
3001
4753
|
try {
|
|
3002
4754
|
mutTableMap = new Map(ordinaryTables.map((tbl) => [
|
|
3003
4755
|
tbl.name,
|
|
3004
|
-
core.table(`$${tbl.name}_mutations`)
|
|
4756
|
+
core.table(`$${tbl.name}_mutations`),
|
|
3005
4757
|
]));
|
|
3006
4758
|
}
|
|
3007
4759
|
catch (_a) {
|
|
@@ -3035,15 +4787,9 @@
|
|
|
3035
4787
|
outstandingTransactions.next(outstandingTransactions.value);
|
|
3036
4788
|
};
|
|
3037
4789
|
const txComplete = () => {
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
console.debug('registering sync event');
|
|
3042
|
-
registerSyncEvent(db, "push");
|
|
3043
|
-
}
|
|
3044
|
-
else {
|
|
3045
|
-
db.localSyncEvent.next({ purpose: "push" });
|
|
3046
|
-
}
|
|
4790
|
+
if (tx.mutationsAdded &&
|
|
4791
|
+
!isEagerSyncDisabled(db)) {
|
|
4792
|
+
triggerSync(db, 'push');
|
|
3047
4793
|
}
|
|
3048
4794
|
removeTransaction();
|
|
3049
4795
|
};
|
|
@@ -3110,7 +4856,7 @@
|
|
|
3110
4856
|
.query({
|
|
3111
4857
|
query: { range: req.range, index: schema.primaryKey },
|
|
3112
4858
|
trans: req.trans,
|
|
3113
|
-
values: false
|
|
4859
|
+
values: false,
|
|
3114
4860
|
})
|
|
3115
4861
|
// Do a delete request instead, but keep the criteria info for the server to execute
|
|
3116
4862
|
.then((res) => {
|
|
@@ -3118,7 +4864,7 @@
|
|
|
3118
4864
|
type: 'delete',
|
|
3119
4865
|
keys: res.result,
|
|
3120
4866
|
trans: req.trans,
|
|
3121
|
-
criteria: { index: null, range: req.range }
|
|
4867
|
+
criteria: { index: null, range: req.range },
|
|
3122
4868
|
});
|
|
3123
4869
|
})
|
|
3124
4870
|
: mutateAndLog(req);
|
|
@@ -3126,7 +4872,7 @@
|
|
|
3126
4872
|
function mutateAndLog(req) {
|
|
3127
4873
|
const trans = req.trans;
|
|
3128
4874
|
trans.mutationsAdded = true;
|
|
3129
|
-
const { txid, currentUser: { userId } } = trans;
|
|
4875
|
+
const { txid, currentUser: { userId }, } = trans;
|
|
3130
4876
|
const { type } = req;
|
|
3131
4877
|
const opNo = ++trans.opCount;
|
|
3132
4878
|
return table.mutate(req).then((res) => {
|
|
@@ -3147,7 +4893,7 @@
|
|
|
3147
4893
|
keys,
|
|
3148
4894
|
criteria: req.criteria,
|
|
3149
4895
|
txid,
|
|
3150
|
-
userId
|
|
4896
|
+
userId,
|
|
3151
4897
|
}
|
|
3152
4898
|
: req.type === 'add'
|
|
3153
4899
|
? {
|
|
@@ -3157,7 +4903,7 @@
|
|
|
3157
4903
|
keys,
|
|
3158
4904
|
txid,
|
|
3159
4905
|
userId,
|
|
3160
|
-
values
|
|
4906
|
+
values,
|
|
3161
4907
|
}
|
|
3162
4908
|
: req.criteria && req.changeSpec
|
|
3163
4909
|
? {
|
|
@@ -3169,7 +4915,7 @@
|
|
|
3169
4915
|
criteria: req.criteria,
|
|
3170
4916
|
changeSpec: req.changeSpec,
|
|
3171
4917
|
txid,
|
|
3172
|
-
userId
|
|
4918
|
+
userId,
|
|
3173
4919
|
}
|
|
3174
4920
|
: updates
|
|
3175
4921
|
? {
|
|
@@ -3180,7 +4926,7 @@
|
|
|
3180
4926
|
keys: updates.keys,
|
|
3181
4927
|
changeSpecs: updates.changeSpecs,
|
|
3182
4928
|
txid,
|
|
3183
|
-
userId
|
|
4929
|
+
userId,
|
|
3184
4930
|
}
|
|
3185
4931
|
: {
|
|
3186
4932
|
type: 'upsert',
|
|
@@ -3189,7 +4935,7 @@
|
|
|
3189
4935
|
keys,
|
|
3190
4936
|
values,
|
|
3191
4937
|
txid,
|
|
3192
|
-
userId
|
|
4938
|
+
userId,
|
|
3193
4939
|
};
|
|
3194
4940
|
return keys.length > 0 || ('criteria' in req && req.criteria)
|
|
3195
4941
|
? mutsTable
|
|
@@ -3199,7 +4945,7 @@
|
|
|
3199
4945
|
});
|
|
3200
4946
|
}
|
|
3201
4947
|
} });
|
|
3202
|
-
}
|
|
4948
|
+
},
|
|
3203
4949
|
};
|
|
3204
4950
|
}
|
|
3205
4951
|
|
|
@@ -3291,13 +5037,13 @@
|
|
|
3291
5037
|
// for just a short time.
|
|
3292
5038
|
const userIsReallyActive = new rxjs.BehaviorSubject(true);
|
|
3293
5039
|
userIsActive
|
|
3294
|
-
.pipe(
|
|
5040
|
+
.pipe(switchMap((isActive) => {
|
|
3295
5041
|
//console.debug('SyncStatus: DUBB: isActive changed to', isActive);
|
|
3296
5042
|
return isActive
|
|
3297
5043
|
? rxjs.of(true)
|
|
3298
|
-
: rxjs.of(false).pipe(
|
|
5044
|
+
: rxjs.of(false).pipe(delay(INACTIVE_WAIT_TIME))
|
|
3299
5045
|
;
|
|
3300
|
-
}),
|
|
5046
|
+
}), distinctUntilChanged())
|
|
3301
5047
|
.subscribe(userIsReallyActive);
|
|
3302
5048
|
//
|
|
3303
5049
|
// First create some corner-stone observables to build the flow on
|
|
@@ -3307,9 +5053,9 @@
|
|
|
3307
5053
|
? rxjs.fromEvent(document, 'visibilitychange')
|
|
3308
5054
|
: rxjs.of({});
|
|
3309
5055
|
// document.onvisibilitychange makes document hidden:
|
|
3310
|
-
const documentBecomesHidden = visibilityStateIsChanged.pipe(
|
|
5056
|
+
const documentBecomesHidden = visibilityStateIsChanged.pipe(filter(() => document.visibilityState === 'hidden'));
|
|
3311
5057
|
// document.onvisibilitychange makes document visible
|
|
3312
|
-
const documentBecomesVisible = visibilityStateIsChanged.pipe(
|
|
5058
|
+
const documentBecomesVisible = visibilityStateIsChanged.pipe(filter(() => document.visibilityState === 'visible'));
|
|
3313
5059
|
// Any of various user-activity-related events happen:
|
|
3314
5060
|
const userDoesSomething = typeof window !== 'undefined'
|
|
3315
5061
|
? rxjs.merge(documentBecomesVisible, rxjs.fromEvent(window, 'mousedown'), rxjs.fromEvent(window, 'mousemove'), rxjs.fromEvent(window, 'keydown'), rxjs.fromEvent(window, 'wheel'), rxjs.fromEvent(window, 'touchmove'))
|
|
@@ -3327,9 +5073,9 @@
|
|
|
3327
5073
|
userDoesSomething)
|
|
3328
5074
|
.pipe(
|
|
3329
5075
|
// No matter event source, compute whether user is visible using visibilityState:
|
|
3330
|
-
|
|
5076
|
+
map(() => document.visibilityState === 'visible'),
|
|
3331
5077
|
// Make sure to emit it
|
|
3332
|
-
|
|
5078
|
+
tap((isActive) => {
|
|
3333
5079
|
if (userIsActive.value !== isActive) {
|
|
3334
5080
|
// Emit new value unless it already has that value
|
|
3335
5081
|
userIsActive.next(isActive);
|
|
@@ -3337,8 +5083,8 @@
|
|
|
3337
5083
|
}),
|
|
3338
5084
|
// Now, if true was emitted, make sure to set a timeout to emit false
|
|
3339
5085
|
// unless new user activity things happen (in that case, the timeout will be cancelled!)
|
|
3340
|
-
|
|
3341
|
-
? rxjs.of(0).pipe(
|
|
5086
|
+
switchMap((isActive) => isActive
|
|
5087
|
+
? rxjs.of(0).pipe(delay(USER_INACTIVITY_TIMEOUT - INACTIVE_WAIT_TIME), tap(() => userIsActive.next(false)))
|
|
3342
5088
|
: rxjs.of(0)))
|
|
3343
5089
|
.subscribe(() => { }); // Unless we subscribe nothing will be propagated to userIsActive observable
|
|
3344
5090
|
}
|
|
@@ -3558,6 +5304,20 @@
|
|
|
3558
5304
|
}
|
|
3559
5305
|
}
|
|
3560
5306
|
|
|
5307
|
+
class InvalidLicenseError extends Error {
|
|
5308
|
+
constructor(license) {
|
|
5309
|
+
super(license === 'expired'
|
|
5310
|
+
? `License expired`
|
|
5311
|
+
: license === 'deactivated'
|
|
5312
|
+
? `User deactivated`
|
|
5313
|
+
: 'Invalid license');
|
|
5314
|
+
this.name = 'InvalidLicenseError';
|
|
5315
|
+
if (license) {
|
|
5316
|
+
this.license = license;
|
|
5317
|
+
}
|
|
5318
|
+
}
|
|
5319
|
+
}
|
|
5320
|
+
|
|
3561
5321
|
function sleep$1(ms) {
|
|
3562
5322
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3563
5323
|
}
|
|
@@ -3568,7 +5328,7 @@
|
|
|
3568
5328
|
yield sleep$1(3000);
|
|
3569
5329
|
// Wait til user does something (move mouse, tap, scroll, click etc)
|
|
3570
5330
|
console.debug('waiting for someone to do something');
|
|
3571
|
-
yield userDoesSomething.pipe(
|
|
5331
|
+
yield userDoesSomething.pipe(take(1)).toPromise();
|
|
3572
5332
|
console.debug('someone did something!');
|
|
3573
5333
|
});
|
|
3574
5334
|
}
|
|
@@ -3577,10 +5337,10 @@
|
|
|
3577
5337
|
if (!((_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.databaseUrl)) {
|
|
3578
5338
|
throw new Error(`No database URL to connect WebSocket to`);
|
|
3579
5339
|
}
|
|
3580
|
-
const messageProducer = db.messageConsumer.readyToServe.pipe(
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
5340
|
+
const messageProducer = db.messageConsumer.readyToServe.pipe(filter((isReady) => isReady), // When consumer is ready for new messages, produce such a message to inform server about it
|
|
5341
|
+
switchMap(() => db.getPersistedSyncState()), // We need the info on which server revision we are at:
|
|
5342
|
+
filter((syncState) => syncState && syncState.serverRevision), // We wont send anything to server before inital sync has taken place
|
|
5343
|
+
switchMap((syncState) => __awaiter(this, void 0, void 0, function* () {
|
|
3584
5344
|
return ({
|
|
3585
5345
|
// Produce the message to trigger server to send us new messages to consume:
|
|
3586
5346
|
type: 'ready',
|
|
@@ -3589,17 +5349,22 @@
|
|
|
3589
5349
|
});
|
|
3590
5350
|
})));
|
|
3591
5351
|
function createObservable() {
|
|
3592
|
-
return db.cloud.persistedSyncState.pipe(
|
|
3593
|
-
|
|
3594
|
-
|
|
5352
|
+
return db.cloud.persistedSyncState.pipe(filter((syncState) => syncState === null || syncState === void 0 ? void 0 : syncState.serverRevision), // Don't connect before there's no initial sync performed.
|
|
5353
|
+
take(1), // Don't continue waking up whenever syncState change
|
|
5354
|
+
switchMap((syncState) => db.cloud.currentUser.pipe(map((userLogin) => [userLogin, syncState]))), switchMap(([userLogin, syncState]) => {
|
|
5355
|
+
/*if (userLogin.license?.status && userLogin.license.status !== 'ok') {
|
|
5356
|
+
throw new InvalidLicenseError();
|
|
5357
|
+
}*/
|
|
5358
|
+
return userIsReallyActive.pipe(map((isActive) => [isActive ? userLogin : null, syncState]));
|
|
5359
|
+
}), switchMap(([userLogin, syncState]) => {
|
|
3595
5360
|
if ((userLogin === null || userLogin === void 0 ? void 0 : userLogin.isLoggedIn) && !(syncState === null || syncState === void 0 ? void 0 : syncState.realms.includes(userLogin.userId))) {
|
|
3596
5361
|
// We're in an in-between state when user is logged in but the user's realms are not yet synced.
|
|
3597
5362
|
// Don't make this change reconnect the websocket just yet. Wait till syncState is updated
|
|
3598
5363
|
// to iclude the user's realm.
|
|
3599
|
-
return db.cloud.persistedSyncState.pipe(
|
|
5364
|
+
return db.cloud.persistedSyncState.pipe(filter((syncState) => (syncState === null || syncState === void 0 ? void 0 : syncState.realms.includes(userLogin.userId)) || false), take(1), map((syncState) => [userLogin, syncState]));
|
|
3600
5365
|
}
|
|
3601
5366
|
return new rxjs.BehaviorSubject([userLogin, syncState]);
|
|
3602
|
-
}),
|
|
5367
|
+
}), switchMap(([userLogin, syncState]) => __awaiter(this, void 0, void 0, function* () { return [userLogin, yield computeRealmSetHash(syncState)]; })), distinctUntilChanged(([prevUser, prevHash], [currUser, currHash]) => prevUser === currUser && prevHash === currHash), switchMap(([userLogin, realmSetHash]) => {
|
|
3603
5368
|
// Let server end query changes from last entry of same client-ID and forward.
|
|
3604
5369
|
// If no new entries, server won't bother the client. If new entries, server sends only those
|
|
3605
5370
|
// and the baseRev of the last from same client-ID.
|
|
@@ -3609,10 +5374,10 @@
|
|
|
3609
5374
|
else {
|
|
3610
5375
|
return rxjs.from([]);
|
|
3611
5376
|
}
|
|
3612
|
-
}),
|
|
5377
|
+
}), catchError((error) => {
|
|
3613
5378
|
if ((error === null || error === void 0 ? void 0 : error.name) === 'TokenExpiredError') {
|
|
3614
5379
|
console.debug('WebSocket observable: Token expired. Refreshing token...');
|
|
3615
|
-
return rxjs.of(true).pipe(
|
|
5380
|
+
return rxjs.of(true).pipe(switchMap(() => __awaiter(this, void 0, void 0, function* () {
|
|
3616
5381
|
// Refresh access token
|
|
3617
5382
|
const user = yield db.getCurrentUser();
|
|
3618
5383
|
const refreshedLogin = yield refreshAccessToken(db.cloud.options.databaseUrl, user);
|
|
@@ -3620,15 +5385,21 @@
|
|
|
3620
5385
|
yield db.table('$logins').update(user.userId, {
|
|
3621
5386
|
accessToken: refreshedLogin.accessToken,
|
|
3622
5387
|
accessTokenExpiration: refreshedLogin.accessTokenExpiration,
|
|
5388
|
+
claims: refreshedLogin.claims,
|
|
5389
|
+
license: refreshedLogin.license,
|
|
3623
5390
|
});
|
|
3624
|
-
})),
|
|
5391
|
+
})), switchMap(() => createObservable()));
|
|
3625
5392
|
}
|
|
3626
5393
|
else {
|
|
3627
|
-
return rxjs.throwError(error);
|
|
5394
|
+
return rxjs.throwError(() => error);
|
|
3628
5395
|
}
|
|
3629
|
-
}),
|
|
5396
|
+
}), catchError((error) => {
|
|
3630
5397
|
db.cloud.webSocketStatus.next("error");
|
|
3631
|
-
|
|
5398
|
+
if (error instanceof InvalidLicenseError) {
|
|
5399
|
+
// Don't retry. Just throw and don't try connect again.
|
|
5400
|
+
return rxjs.throwError(() => error);
|
|
5401
|
+
}
|
|
5402
|
+
return rxjs.from(waitAndReconnectWhenUserDoesSomething(error)).pipe(switchMap(() => createObservable()));
|
|
3632
5403
|
}));
|
|
3633
5404
|
}
|
|
3634
5405
|
return createObservable().subscribe({
|
|
@@ -3656,97 +5427,12 @@
|
|
|
3656
5427
|
});
|
|
3657
5428
|
}
|
|
3658
5429
|
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
const GUARDED_JOB_TIMEOUT = 1 * MINUTES;
|
|
3666
|
-
function performGuardedJob(db, jobName, jobsTableName, job, { awaitRemoteJob } = {}) {
|
|
3667
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3668
|
-
// Start working.
|
|
3669
|
-
//
|
|
3670
|
-
// Check if someone else is working on this already.
|
|
3671
|
-
//
|
|
3672
|
-
const jobsTable = db.table(jobsTableName);
|
|
3673
|
-
function aquireLock() {
|
|
3674
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3675
|
-
const gotTheLock = yield db.transaction('rw!', jobsTableName, () => __awaiter(this, void 0, void 0, function* () {
|
|
3676
|
-
const currentWork = yield jobsTable.get(jobName);
|
|
3677
|
-
if (!currentWork) {
|
|
3678
|
-
// No one else is working. Let's record that we are.
|
|
3679
|
-
yield jobsTable.add({
|
|
3680
|
-
nodeId: myId,
|
|
3681
|
-
started: new Date(),
|
|
3682
|
-
heartbeat: new Date()
|
|
3683
|
-
}, jobName);
|
|
3684
|
-
return true;
|
|
3685
|
-
}
|
|
3686
|
-
else if (currentWork.heartbeat.getTime() <
|
|
3687
|
-
Date.now() - GUARDED_JOB_TIMEOUT) {
|
|
3688
|
-
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!`);
|
|
3689
|
-
// Now, take over!
|
|
3690
|
-
yield jobsTable.put({
|
|
3691
|
-
nodeId: myId,
|
|
3692
|
-
started: new Date(),
|
|
3693
|
-
heartbeat: new Date()
|
|
3694
|
-
}, jobName);
|
|
3695
|
-
return true;
|
|
3696
|
-
}
|
|
3697
|
-
return false;
|
|
3698
|
-
}));
|
|
3699
|
-
if (gotTheLock)
|
|
3700
|
-
return true;
|
|
3701
|
-
// Someone else took the job.
|
|
3702
|
-
if (awaitRemoteJob) {
|
|
3703
|
-
try {
|
|
3704
|
-
const jobDoneObservable = rxjs.from(Dexie.liveQuery(() => jobsTable.get(jobName))).pipe(operators.timeout(GUARDED_JOB_TIMEOUT), operators.filter((job) => !job)); // Wait til job is not there anymore.
|
|
3705
|
-
yield jobDoneObservable.toPromise();
|
|
3706
|
-
return false;
|
|
3707
|
-
}
|
|
3708
|
-
catch (err) {
|
|
3709
|
-
if (err.name !== 'TimeoutError') {
|
|
3710
|
-
throw err;
|
|
3711
|
-
}
|
|
3712
|
-
// Timeout stopped us! Try aquire the lock now.
|
|
3713
|
-
// It will likely succeed this time unless
|
|
3714
|
-
// another client took it.
|
|
3715
|
-
return yield aquireLock();
|
|
3716
|
-
}
|
|
3717
|
-
}
|
|
3718
|
-
return false;
|
|
3719
|
-
});
|
|
3720
|
-
}
|
|
3721
|
-
if (yield aquireLock()) {
|
|
3722
|
-
// We own the lock entry and can do our job undisturbed.
|
|
3723
|
-
// We're not within a transaction, but these type of locks
|
|
3724
|
-
// spans over transactions.
|
|
3725
|
-
// Start our heart beat during the job.
|
|
3726
|
-
// Use setInterval to make sure we are updating heartbeat even during long-lived fetch calls.
|
|
3727
|
-
const heartbeat = setInterval(() => {
|
|
3728
|
-
jobsTable.update(jobName, (job) => {
|
|
3729
|
-
if (job.nodeId === myId) {
|
|
3730
|
-
job.heartbeat = new Date();
|
|
3731
|
-
}
|
|
3732
|
-
});
|
|
3733
|
-
}, GUARDED_JOB_HEARTBEAT);
|
|
3734
|
-
try {
|
|
3735
|
-
return yield job();
|
|
3736
|
-
}
|
|
3737
|
-
finally {
|
|
3738
|
-
// Stop heartbeat
|
|
3739
|
-
clearInterval(heartbeat);
|
|
3740
|
-
// Remove the persisted job state:
|
|
3741
|
-
yield db.transaction('rw!', jobsTableName, () => __awaiter(this, void 0, void 0, function* () {
|
|
3742
|
-
const currentWork = yield jobsTable.get(jobName);
|
|
3743
|
-
if (currentWork && currentWork.nodeId === myId) {
|
|
3744
|
-
yield jobsTable.delete(jobName);
|
|
3745
|
-
}
|
|
3746
|
-
}));
|
|
3747
|
-
}
|
|
3748
|
-
}
|
|
3749
|
-
});
|
|
5430
|
+
function performGuardedJob(db, jobName, job) {
|
|
5431
|
+
if (typeof navigator === 'undefined' || !navigator.locks) {
|
|
5432
|
+
// No support for guarding jobs. IE11, node.js, etc.
|
|
5433
|
+
return job();
|
|
5434
|
+
}
|
|
5435
|
+
return navigator.locks.request(db.name + '|' + jobName, () => job());
|
|
3750
5436
|
}
|
|
3751
5437
|
|
|
3752
5438
|
const ongoingSyncs = new WeakMap();
|
|
@@ -3800,6 +5486,9 @@
|
|
|
3800
5486
|
function _syncIfPossible() {
|
|
3801
5487
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3802
5488
|
try {
|
|
5489
|
+
// Check if should delay sync due to ratelimit:
|
|
5490
|
+
yield checkSyncRateLimitDelay(db);
|
|
5491
|
+
// Check if we need to lock the sync job. Not needed if we are the service worker.
|
|
3803
5492
|
if (db.cloud.isServiceWorkerDB) {
|
|
3804
5493
|
// We are the dedicated sync SW:
|
|
3805
5494
|
yield sync(db, cloudOptions, cloudSchema, options);
|
|
@@ -3807,7 +5496,7 @@
|
|
|
3807
5496
|
else if (!db.cloud.usingServiceWorker) {
|
|
3808
5497
|
// We use a flow that is better suited for the case when multiple workers want to
|
|
3809
5498
|
// do the same thing.
|
|
3810
|
-
yield performGuardedJob(db, CURRENT_SYNC_WORKER,
|
|
5499
|
+
yield performGuardedJob(db, CURRENT_SYNC_WORKER, () => sync(db, cloudOptions, cloudSchema, options));
|
|
3811
5500
|
}
|
|
3812
5501
|
else {
|
|
3813
5502
|
assert(false);
|
|
@@ -3829,19 +5518,29 @@
|
|
|
3829
5518
|
}
|
|
3830
5519
|
}
|
|
3831
5520
|
|
|
5521
|
+
const SECONDS = 1000;
|
|
5522
|
+
const MINUTES = 60 * SECONDS;
|
|
5523
|
+
|
|
3832
5524
|
function LocalSyncWorker(db, cloudOptions, cloudSchema) {
|
|
3833
5525
|
let localSyncEventSubscription = null;
|
|
3834
5526
|
//let syncHandler: ((event: Event) => void) | null = null;
|
|
3835
5527
|
//let periodicSyncHandler: ((event: Event) => void) | null = null;
|
|
3836
5528
|
let cancelToken = { cancelled: false };
|
|
5529
|
+
let retryHandle = null;
|
|
5530
|
+
let retryPurpose = null; // "pull" is superset of "push"
|
|
3837
5531
|
function syncAndRetry(purpose, retryNum = 1) {
|
|
3838
5532
|
// Use setTimeout() to get onto a clean stack and
|
|
3839
5533
|
// break free from possible active transaction:
|
|
3840
5534
|
setTimeout(() => {
|
|
5535
|
+
if (retryHandle)
|
|
5536
|
+
clearTimeout(retryHandle);
|
|
5537
|
+
const combPurpose = retryPurpose === 'pull' ? 'pull' : purpose;
|
|
5538
|
+
retryHandle = null;
|
|
5539
|
+
retryPurpose = null;
|
|
3841
5540
|
syncIfPossible(db, cloudOptions, cloudSchema, {
|
|
3842
5541
|
cancelToken,
|
|
3843
5542
|
retryImmediatelyOnFetchError: true,
|
|
3844
|
-
purpose,
|
|
5543
|
+
purpose: combPurpose,
|
|
3845
5544
|
}).catch((e) => {
|
|
3846
5545
|
console.error('error in syncIfPossible()', e);
|
|
3847
5546
|
if (cancelToken.cancelled) {
|
|
@@ -3851,7 +5550,13 @@
|
|
|
3851
5550
|
// Mimic service worker sync event: retry 3 times
|
|
3852
5551
|
// * first retry after 5 minutes
|
|
3853
5552
|
// * second retry 15 minutes later
|
|
3854
|
-
|
|
5553
|
+
const combinedPurpose = retryPurpose && retryPurpose === 'pull' ? 'pull' : purpose;
|
|
5554
|
+
const handle = setTimeout(() => syncAndRetry(combinedPurpose, retryNum + 1), [0, 5, 15][retryNum] * MINUTES);
|
|
5555
|
+
// Cancel the previous retryHandle if it exists to avoid scheduling loads of retries.
|
|
5556
|
+
if (retryHandle)
|
|
5557
|
+
clearTimeout(retryHandle);
|
|
5558
|
+
retryHandle = handle;
|
|
5559
|
+
retryPurpose = combinedPurpose;
|
|
3855
5560
|
}
|
|
3856
5561
|
});
|
|
3857
5562
|
}, 0);
|
|
@@ -3899,11 +5604,11 @@
|
|
|
3899
5604
|
for (const table of db.tables) {
|
|
3900
5605
|
if ((_b = (_a = db.cloud.schema) === null || _a === void 0 ? void 0 : _a[table.name]) === null || _b === void 0 ? void 0 : _b.markedForSync) {
|
|
3901
5606
|
if (table.schema.primKey.auto) {
|
|
3902
|
-
throw new
|
|
5607
|
+
throw new Dexie.SchemaError(`Table ${table.name} is both autoIncremented and synced. ` +
|
|
3903
5608
|
`Use db.cloud.configure({unsyncedTables: [${JSON.stringify(table.name)}]}) to blacklist it from sync`);
|
|
3904
5609
|
}
|
|
3905
5610
|
if (!table.schema.primKey.keyPath) {
|
|
3906
|
-
throw new
|
|
5611
|
+
throw new Dexie.SchemaError(`Table ${table.name} cannot be both synced and outbound. ` +
|
|
3907
5612
|
`Use db.cloud.configure({unsyncedTables: [${JSON.stringify(table.name)}]}) to blacklist it from sync`);
|
|
3908
5613
|
}
|
|
3909
5614
|
}
|
|
@@ -3918,10 +5623,12 @@
|
|
|
3918
5623
|
},
|
|
3919
5624
|
Alert: {
|
|
3920
5625
|
error: {
|
|
3921
|
-
color: "red"
|
|
5626
|
+
color: "red",
|
|
5627
|
+
fontWeight: "bold"
|
|
3922
5628
|
},
|
|
3923
5629
|
warning: {
|
|
3924
|
-
color: "
|
|
5630
|
+
color: "#f80",
|
|
5631
|
+
fontWeight: "bold"
|
|
3925
5632
|
},
|
|
3926
5633
|
info: {
|
|
3927
5634
|
color: "black"
|
|
@@ -3962,7 +5669,8 @@
|
|
|
3962
5669
|
border: "3px solid #3d3d5d",
|
|
3963
5670
|
borderRadius: "8px",
|
|
3964
5671
|
boxShadow: "0 0 80px 10px #666",
|
|
3965
|
-
width: "auto"
|
|
5672
|
+
width: "auto",
|
|
5673
|
+
fontFamily: "sans-serif",
|
|
3966
5674
|
},
|
|
3967
5675
|
Input: {
|
|
3968
5676
|
height: "35px",
|
|
@@ -3983,11 +5691,26 @@
|
|
|
3983
5691
|
|
|
3984
5692
|
var t,r,u,i,o=0,c=[],f=[],e=l$1.__b,a=l$1.__r,v=l$1.diffed,l=l$1.__c,m=l$1.unmount;function d(t,u){l$1.__h&&l$1.__h(r,t,o||u),o=0;var i=r.__H||(r.__H={__:[],__h:[]});return t>=i.__.length&&i.__.push({__V:f}),i.__[t]}function p(n){return o=1,y(z,n)}function y(n,u,i){var o=d(t++,2);if(o.t=n,!o.__c&&(o.__=[i?i(u):z(void 0,u),function(n){var t=o.__N?o.__N[0]:o.__[0],r=o.t(t,n);t!==r&&(o.__N=[r,o.__[1]],o.__c.setState({}));}],o.__c=r,!r.u)){r.u=!0;var c=r.shouldComponentUpdate;r.shouldComponentUpdate=function(n,t,r){if(!o.__c.__H)return !0;var u=o.__c.__H.__.filter(function(n){return n.__c});if(u.every(function(n){return !n.__N}))return !c||c.call(this,n,t,r);var i=!1;return u.forEach(function(n){if(n.__N){var t=n.__[0];n.__=n.__N,n.__N=void 0,t!==n.__[0]&&(i=!0);}}),!!i&&(!c||c.call(this,n,t,r))};}return o.__N||o.__}function s(u,i){var o=d(t++,4);!l$1.__s&&w(o.__H,i)&&(o.__=u,o.i=i,r.__h.push(o));}function _(n){return o=5,F(function(){return {current:n}},[])}function F(n,r){var u=d(t++,7);return w(u.__H,r)?(u.__V=n(),u.i=r,u.__h=n,u.__V):u.__}function b(){for(var t;t=c.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(j),t.__H.__h.forEach(k),t.__H.__h=[];}catch(r){t.__H.__h=[],l$1.__e(r,t.__v);}}l$1.__b=function(n){r=null,e&&e(n);},l$1.__r=function(n){a&&a(n),t=0;var i=(r=n.__c).__H;i&&(u===r?(i.__h=[],r.__h=[],i.__.forEach(function(n){n.__N&&(n.__=n.__N),n.__V=f,n.__N=n.i=void 0;})):(i.__h.forEach(j),i.__h.forEach(k),i.__h=[])),u=r;},l$1.diffed=function(t){v&&v(t);var o=t.__c;o&&o.__H&&(o.__H.__h.length&&(1!==c.push(o)&&i===l$1.requestAnimationFrame||((i=l$1.requestAnimationFrame)||function(n){var t,r=function(){clearTimeout(u),g&&cancelAnimationFrame(t),setTimeout(n);},u=setTimeout(r,100);g&&(t=requestAnimationFrame(r));})(b)),o.__H.__.forEach(function(n){n.i&&(n.__H=n.i),n.__V!==f&&(n.__=n.__V),n.i=void 0,n.__V=f;})),u=r=null;},l$1.__c=function(t,r){r.some(function(t){try{t.__h.forEach(j),t.__h=t.__h.filter(function(n){return !n.__||k(n)});}catch(u){r.some(function(n){n.__h&&(n.__h=[]);}),r=[],l$1.__e(u,t.__v);}}),l&&l(t,r);},l$1.unmount=function(t){m&&m(t);var r,u=t.__c;u&&u.__H&&(u.__H.__.forEach(function(n){try{j(n);}catch(n){r=n;}}),r&&l$1.__e(r,u.__v));};var g="function"==typeof requestAnimationFrame;function j(n){var t=r,u=n.__c;"function"==typeof u&&(n.__c=void 0,u()),r=t;}function k(n){var t=r;n.__c=n.__(),r=t;}function w(n,t){return !n||n.length!==t.length||t.some(function(t,r){return t!==n[r]})}function z(n,t){return "function"==typeof t?t(n):t}
|
|
3985
5693
|
|
|
5694
|
+
/** Resolve a message template with parameters.
|
|
5695
|
+
*
|
|
5696
|
+
* Example:
|
|
5697
|
+
* resolveText({
|
|
5698
|
+
* message: "Hello {name}!",
|
|
5699
|
+
* messageCode: "HELLO",
|
|
5700
|
+
* messageParams: {name: "David"}
|
|
5701
|
+
* }) => "Hello David!"
|
|
5702
|
+
*
|
|
5703
|
+
* @param message Template message with {vars} in it.
|
|
5704
|
+
* @param messageCode Unique code for the message. Can be used for translation.
|
|
5705
|
+
* @param messageParams Parameters to be used in the message.
|
|
5706
|
+
* @returns A final message where parameters have been replaced with values.
|
|
5707
|
+
*/
|
|
3986
5708
|
function resolveText({ message, messageCode, messageParams }) {
|
|
3987
|
-
return message.replace(/\{\w+\}/ig, n => messageParams[n.
|
|
5709
|
+
return message.replace(/\{\w+\}/ig, n => messageParams[n.substring(1, n.length - 1)]);
|
|
3988
5710
|
}
|
|
3989
5711
|
|
|
3990
|
-
|
|
5712
|
+
const OTP_LENGTH = 8;
|
|
5713
|
+
function LoginDialog({ title, type, alerts, fields, submitLabel, cancelLabel, onCancel, onSubmit, }) {
|
|
3991
5714
|
const [params, setParams] = p({});
|
|
3992
5715
|
const firstFieldRef = _(null);
|
|
3993
5716
|
s(() => { var _a; return (_a = firstFieldRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, []);
|
|
@@ -3995,21 +5718,34 @@
|
|
|
3995
5718
|
h(p$1, null,
|
|
3996
5719
|
h("h3", { style: Styles.WindowHeader }, title),
|
|
3997
5720
|
alerts.map((alert) => (h("p", { style: Styles.Alert[alert.type] }, resolveText(alert)))),
|
|
3998
|
-
h("form", { onSubmit: ev => {
|
|
5721
|
+
h("form", { onSubmit: (ev) => {
|
|
3999
5722
|
ev.preventDefault();
|
|
4000
5723
|
onSubmit(params);
|
|
4001
|
-
} }, Object.entries(fields).map(([fieldName, { type, label, placeholder }], idx) => (h("label", { style: Styles.Label },
|
|
5724
|
+
} }, Object.entries(fields).map(([fieldName, { type, label, placeholder }], idx) => (h("label", { style: Styles.Label, key: idx },
|
|
4002
5725
|
label ? `${label}: ` : '',
|
|
4003
|
-
h("input", { ref: idx === 0 ? firstFieldRef : undefined, type: type, name: fieldName, autoComplete: "on", style: Styles.Input, autoFocus: true, placeholder: placeholder, value: params[fieldName] || '', onInput: (ev) => {
|
|
5726
|
+
h("input", { ref: idx === 0 ? firstFieldRef : undefined, type: type, name: fieldName, autoComplete: "on", style: Styles.Input, autoFocus: true, placeholder: placeholder, value: params[fieldName] || '', onInput: (ev) => {
|
|
5727
|
+
var _a;
|
|
5728
|
+
const value = valueTransformer(type, (_a = ev.target) === null || _a === void 0 ? void 0 : _a['value']);
|
|
5729
|
+
let updatedParams = Object.assign(Object.assign({}, params), { [fieldName]: value });
|
|
5730
|
+
setParams(updatedParams);
|
|
5731
|
+
if (type === 'otp' && (value === null || value === void 0 ? void 0 : value.trim().length) === OTP_LENGTH) {
|
|
5732
|
+
// Auto-submit when OTP is filled in.
|
|
5733
|
+
onSubmit(updatedParams);
|
|
5734
|
+
}
|
|
5735
|
+
} })))))),
|
|
4004
5736
|
h("div", { style: Styles.ButtonsDiv },
|
|
4005
|
-
h(
|
|
4006
|
-
|
|
5737
|
+
h(p$1, null,
|
|
5738
|
+
h("button", { type: "submit", style: Styles.Button, onClick: () => onSubmit(params) }, submitLabel),
|
|
5739
|
+
cancelLabel && (h("button", { style: Styles.Button, onClick: onCancel }, cancelLabel))))));
|
|
4007
5740
|
}
|
|
4008
5741
|
function valueTransformer(type, value) {
|
|
4009
5742
|
switch (type) {
|
|
4010
|
-
case
|
|
4011
|
-
|
|
4012
|
-
|
|
5743
|
+
case 'email':
|
|
5744
|
+
return value.toLowerCase();
|
|
5745
|
+
case 'otp':
|
|
5746
|
+
return value.toUpperCase();
|
|
5747
|
+
default:
|
|
5748
|
+
return value;
|
|
4013
5749
|
}
|
|
4014
5750
|
}
|
|
4015
5751
|
|
|
@@ -4063,15 +5799,24 @@
|
|
|
4063
5799
|
}
|
|
4064
5800
|
};
|
|
4065
5801
|
}
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
5802
|
+
|
|
5803
|
+
function associate(factory) {
|
|
5804
|
+
const wm = new WeakMap();
|
|
5805
|
+
return (x) => {
|
|
5806
|
+
let rv = wm.get(x);
|
|
5807
|
+
if (!rv) {
|
|
5808
|
+
rv = factory(x);
|
|
5809
|
+
wm.set(x, rv);
|
|
5810
|
+
}
|
|
5811
|
+
return rv;
|
|
5812
|
+
};
|
|
5813
|
+
}
|
|
5814
|
+
|
|
5815
|
+
const getCurrentUserEmitter = associate((db) => new rxjs.BehaviorSubject(UNAUTHORIZED_USER));
|
|
4071
5816
|
|
|
4072
5817
|
function computeSyncState(db) {
|
|
4073
5818
|
let _prevStatus = db.cloud.webSocketStatus.value;
|
|
4074
|
-
const lazyWebSocketStatus = db.cloud.webSocketStatus.pipe(
|
|
5819
|
+
const lazyWebSocketStatus = db.cloud.webSocketStatus.pipe(switchMap((status) => {
|
|
4075
5820
|
const prevStatus = _prevStatus;
|
|
4076
5821
|
_prevStatus = status;
|
|
4077
5822
|
const rv = rxjs.of(status);
|
|
@@ -4081,22 +5826,31 @@
|
|
|
4081
5826
|
// Only show disconnected if disconnected more than 500ms, or if we can
|
|
4082
5827
|
// see that the user is indeed not active.
|
|
4083
5828
|
case 'disconnected':
|
|
4084
|
-
return userIsActive.value ? rv.pipe(
|
|
5829
|
+
return userIsActive.value ? rv.pipe(debounceTime(500)) : rv;
|
|
4085
5830
|
// Only show connecting if previous state was 'not-started' or 'error', or if
|
|
4086
5831
|
// the time it takes to connect goes beyond 4 seconds.
|
|
4087
5832
|
case 'connecting':
|
|
4088
5833
|
return prevStatus === 'not-started' || prevStatus === 'error'
|
|
4089
5834
|
? rv
|
|
4090
|
-
: rv.pipe(
|
|
5835
|
+
: rv.pipe(debounceTime(4000));
|
|
4091
5836
|
default:
|
|
4092
5837
|
return rv;
|
|
4093
5838
|
}
|
|
4094
5839
|
}));
|
|
4095
5840
|
return rxjs.combineLatest([
|
|
4096
5841
|
lazyWebSocketStatus,
|
|
4097
|
-
db.syncStateChangedEvent.pipe(
|
|
5842
|
+
db.syncStateChangedEvent.pipe(startWith({ phase: 'initial' })),
|
|
5843
|
+
getCurrentUserEmitter(db.dx._novip),
|
|
4098
5844
|
userIsReallyActive
|
|
4099
|
-
]).pipe(
|
|
5845
|
+
]).pipe(map(([status, syncState, user, userIsActive]) => {
|
|
5846
|
+
var _a;
|
|
5847
|
+
if (((_a = user.license) === null || _a === void 0 ? void 0 : _a.status) && user.license.status !== 'ok') {
|
|
5848
|
+
return {
|
|
5849
|
+
phase: 'offline',
|
|
5850
|
+
status: 'offline',
|
|
5851
|
+
license: user.license.status
|
|
5852
|
+
};
|
|
5853
|
+
}
|
|
4100
5854
|
let { phase, error, progress } = syncState;
|
|
4101
5855
|
let adjustedStatus = status;
|
|
4102
5856
|
if (phase === 'error') {
|
|
@@ -4129,23 +5883,12 @@
|
|
|
4129
5883
|
error,
|
|
4130
5884
|
progress,
|
|
4131
5885
|
status: isOnline ? adjustedStatus : 'offline',
|
|
5886
|
+
license: 'ok'
|
|
4132
5887
|
};
|
|
4133
5888
|
return retState;
|
|
4134
5889
|
}));
|
|
4135
5890
|
}
|
|
4136
5891
|
|
|
4137
|
-
function associate(factory) {
|
|
4138
|
-
const wm = new WeakMap();
|
|
4139
|
-
return (x) => {
|
|
4140
|
-
let rv = wm.get(x);
|
|
4141
|
-
if (!rv) {
|
|
4142
|
-
rv = factory(x);
|
|
4143
|
-
wm.set(x, rv);
|
|
4144
|
-
}
|
|
4145
|
-
return rv;
|
|
4146
|
-
};
|
|
4147
|
-
}
|
|
4148
|
-
|
|
4149
5892
|
function createSharedValueObservable(o, defaultValue) {
|
|
4150
5893
|
let currentValue = defaultValue;
|
|
4151
5894
|
let shared = rxjs.from(o).pipe(rxjs.map((x) => (currentValue = x)), rxjs.share({ resetOnRefCountZero: () => rxjs.timer(1000) }));
|
|
@@ -4187,10 +5930,8 @@
|
|
|
4187
5930
|
})), {});
|
|
4188
5931
|
});
|
|
4189
5932
|
|
|
4190
|
-
const getCurrentUserEmitter = associate((db) => new rxjs.BehaviorSubject(UNAUTHORIZED_USER));
|
|
4191
|
-
|
|
4192
5933
|
const getInternalAccessControlObservable = associate((db) => {
|
|
4193
|
-
return createSharedValueObservable(getCurrentUserEmitter(db._novip).pipe(
|
|
5934
|
+
return createSharedValueObservable(getCurrentUserEmitter(db._novip).pipe(switchMap((currentUser) => Dexie.liveQuery(() => db.transaction('r', 'realms', 'members', () => Promise.all([
|
|
4194
5935
|
db.members.where({ userId: currentUser.userId }).toArray(),
|
|
4195
5936
|
db.realms.toArray(),
|
|
4196
5937
|
currentUser.userId,
|
|
@@ -4291,7 +6032,7 @@
|
|
|
4291
6032
|
const o = createSharedValueObservable(rxjs.combineLatest([
|
|
4292
6033
|
getInternalAccessControlObservable(db._novip),
|
|
4293
6034
|
getGlobalRolesObservable(db._novip),
|
|
4294
|
-
]).pipe(
|
|
6035
|
+
]).pipe(map(([{ selfMembers, realms, userId }, globalRoles]) => ({
|
|
4295
6036
|
selfMembers,
|
|
4296
6037
|
realms,
|
|
4297
6038
|
userId,
|
|
@@ -4405,16 +6146,16 @@
|
|
|
4405
6146
|
return new PermissionChecker({}, tableName, !owner || owner === dexie.cloud.currentUserId);
|
|
4406
6147
|
return new PermissionChecker(realm.permissions, tableName, realmId === dexie.cloud.currentUserId || owner === dexie.cloud.currentUserId);
|
|
4407
6148
|
};
|
|
4408
|
-
const o = source.pipe(
|
|
6149
|
+
const o = source.pipe(map(mapper));
|
|
4409
6150
|
o.getValue = () => mapper(source.getValue());
|
|
4410
6151
|
return o;
|
|
4411
6152
|
}
|
|
4412
6153
|
|
|
4413
6154
|
const getInvitesObservable = associate((db) => {
|
|
4414
|
-
const membersByEmail = getCurrentUserEmitter(db._novip).pipe(
|
|
6155
|
+
const membersByEmail = getCurrentUserEmitter(db._novip).pipe(switchMap((currentUser) => Dexie.liveQuery(() => db.members.where({ email: currentUser.email || '' }).toArray())));
|
|
4415
6156
|
const permissions = getPermissionsLookupObservable(db._novip);
|
|
4416
6157
|
const accessControl = getInternalAccessControlObservable(db._novip);
|
|
4417
|
-
return createSharedValueObservable(rxjs.combineLatest([membersByEmail, accessControl, permissions]).pipe(
|
|
6158
|
+
return createSharedValueObservable(rxjs.combineLatest([membersByEmail, accessControl, permissions]).pipe(map(([membersByEmail, accessControl, realmLookup]) => {
|
|
4418
6159
|
const reducer = (result, m) => (Object.assign(Object.assign({}, result), { [m.id]: Object.assign(Object.assign({}, m), { realm: realmLookup[m.realmId] }) }));
|
|
4419
6160
|
const emailMembersById = membersByEmail.reduce(reducer, {});
|
|
4420
6161
|
const membersById = accessControl.selfMembers.reduce(reducer, emailMembersById);
|
|
@@ -4460,7 +6201,7 @@
|
|
|
4460
6201
|
let closed = false;
|
|
4461
6202
|
function throwIfClosed() {
|
|
4462
6203
|
if (closed)
|
|
4463
|
-
throw new
|
|
6204
|
+
throw new Dexie.DatabaseClosedError();
|
|
4464
6205
|
}
|
|
4465
6206
|
dbOnClosed(dexie, () => {
|
|
4466
6207
|
subscriptions.forEach((subscription) => subscription.unsubscribe());
|
|
@@ -4471,7 +6212,7 @@
|
|
|
4471
6212
|
});
|
|
4472
6213
|
const syncComplete = new rxjs.Subject();
|
|
4473
6214
|
dexie.cloud = {
|
|
4474
|
-
version: '
|
|
6215
|
+
version: '{version}',
|
|
4475
6216
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
4476
6217
|
schema: null,
|
|
4477
6218
|
get currentUserId() {
|
|
@@ -4507,18 +6248,31 @@
|
|
|
4507
6248
|
}
|
|
4508
6249
|
updateSchemaFromOptions(dexie.cloud.schema, dexie.cloud.options);
|
|
4509
6250
|
},
|
|
6251
|
+
logout({ force } = {}) {
|
|
6252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6253
|
+
force
|
|
6254
|
+
? yield _logout(DexieCloudDB(dexie), { deleteUnsyncedData: true })
|
|
6255
|
+
: yield logout(DexieCloudDB(dexie));
|
|
6256
|
+
});
|
|
6257
|
+
},
|
|
4510
6258
|
sync({ wait, purpose } = { wait: true, purpose: 'push' }) {
|
|
6259
|
+
var _a;
|
|
4511
6260
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4512
6261
|
if (wait === undefined)
|
|
4513
6262
|
wait = true;
|
|
4514
6263
|
const db = DexieCloudDB(dexie);
|
|
6264
|
+
const licenseStatus = ((_a = db.cloud.currentUser.value.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
|
|
6265
|
+
if (licenseStatus !== 'ok') {
|
|
6266
|
+
// Refresh access token to check for updated license
|
|
6267
|
+
yield loadAccessToken(db);
|
|
6268
|
+
}
|
|
4515
6269
|
if (purpose === 'pull') {
|
|
4516
6270
|
const syncState = db.cloud.persistedSyncState.value;
|
|
4517
6271
|
triggerSync(db, purpose);
|
|
4518
6272
|
if (wait) {
|
|
4519
6273
|
const newSyncState = yield db.cloud.persistedSyncState
|
|
4520
|
-
.pipe(
|
|
4521
|
-
(!syncState || newSyncState.timestamp > syncState.timestamp)),
|
|
6274
|
+
.pipe(filter((newSyncState) => (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) != null &&
|
|
6275
|
+
(!syncState || newSyncState.timestamp > syncState.timestamp)), take(1))
|
|
4522
6276
|
.toPromise();
|
|
4523
6277
|
if (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error) {
|
|
4524
6278
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
@@ -4538,7 +6292,7 @@
|
|
|
4538
6292
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
4539
6293
|
return syncNeeded;
|
|
4540
6294
|
})))
|
|
4541
|
-
.pipe(
|
|
6295
|
+
.pipe(filter((isNeeded) => !isNeeded), take(1))
|
|
4542
6296
|
.toPromise();
|
|
4543
6297
|
console.debug('Done waiting for sync completion because we have nothing to push anymore');
|
|
4544
6298
|
}
|
|
@@ -4549,7 +6303,7 @@
|
|
|
4549
6303
|
return permissions(dexie._novip, obj, tableName);
|
|
4550
6304
|
},
|
|
4551
6305
|
};
|
|
4552
|
-
dexie.Version.prototype['_parseStoresSpec'] =
|
|
6306
|
+
dexie.Version.prototype['_parseStoresSpec'] = Dexie.override(dexie.Version.prototype['_parseStoresSpec'], (origFunc) => overrideParseStoresSpec(origFunc, dexie));
|
|
4553
6307
|
dexie.Table.prototype.newId = function ({ colocateWith } = {}) {
|
|
4554
6308
|
const shardKey = colocateWith && colocateWith.substr(colocateWith.length - 3);
|
|
4555
6309
|
return generateKey(dexie.cloud.schema[this.name].idPrefix || '', shardKey);
|
|
@@ -4682,8 +6436,8 @@
|
|
|
4682
6436
|
// This is so that when db.open() completes, user should be safe
|
|
4683
6437
|
// to subscribe to these observables and get actual data.
|
|
4684
6438
|
yield rxjs.combineLatest([
|
|
4685
|
-
currentUserEmitter.pipe(
|
|
4686
|
-
db.cloud.persistedSyncState.pipe(
|
|
6439
|
+
currentUserEmitter.pipe(skip(1), take(1)),
|
|
6440
|
+
db.cloud.persistedSyncState.pipe(skip(1), take(1)),
|
|
4687
6441
|
]).toPromise();
|
|
4688
6442
|
}
|
|
4689
6443
|
// HERE: If requireAuth, do athentication now.
|
|
@@ -4715,7 +6469,9 @@
|
|
|
4715
6469
|
db.syncStateChangedEvent.next({
|
|
4716
6470
|
phase: 'not-in-sync',
|
|
4717
6471
|
});
|
|
4718
|
-
|
|
6472
|
+
if (!isEagerSyncDisabled(db)) {
|
|
6473
|
+
triggerSync(db, 'push');
|
|
6474
|
+
}
|
|
4719
6475
|
}), rxjs.fromEvent(self, 'offline').subscribe(() => {
|
|
4720
6476
|
console.debug('offline!');
|
|
4721
6477
|
db.syncStateChangedEvent.next({
|
|
@@ -4732,8 +6488,8 @@
|
|
|
4732
6488
|
});
|
|
4733
6489
|
}
|
|
4734
6490
|
}
|
|
4735
|
-
dexieCloud.version = '
|
|
4736
|
-
|
|
6491
|
+
dexieCloud.version = '{version}';
|
|
6492
|
+
Dexie.Cloud = dexieCloud;
|
|
4737
6493
|
|
|
4738
6494
|
// In case the SW lives for a while, let it reuse already opened connections:
|
|
4739
6495
|
const managedDBs = new Map();
|
|
@@ -4767,7 +6523,7 @@
|
|
|
4767
6523
|
let db = managedDBs.get(dbName);
|
|
4768
6524
|
if (!db) {
|
|
4769
6525
|
console.debug('Dexie Cloud SW: Creating new Dexie instance for', dbName);
|
|
4770
|
-
const dexie = new
|
|
6526
|
+
const dexie = new Dexie(dbName, { addons: [dexieCloud] });
|
|
4771
6527
|
db = DexieCloudDB(dexie);
|
|
4772
6528
|
db.cloud.isServiceWorkerDB = true;
|
|
4773
6529
|
dexie.on('versionchange', stopManagingDB);
|
|
@@ -4810,7 +6566,7 @@
|
|
|
4810
6566
|
// Error occured. Stop managing this DB until we wake up again by a sync event,
|
|
4811
6567
|
// which will open a new Dexie and start trying to sync it.
|
|
4812
6568
|
stopManagingDB();
|
|
4813
|
-
if (e.name !==
|
|
6569
|
+
if (e.name !== Dexie.errnames.NoSuchDatabase) {
|
|
4814
6570
|
// Unless the error was that DB doesn't exist, rethrow to trigger sync retry.
|
|
4815
6571
|
throw e; // Throw e to make syncEvent.waitUntil() receive a rejected promis, so it will retry.
|
|
4816
6572
|
}
|