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,6 +1,23 @@
|
|
|
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
|
+
*/
|
|
18
|
+
|
|
1
19
|
import Dexie, { cmp, liveQuery } from 'dexie';
|
|
2
|
-
import { Observable, BehaviorSubject, Subject,
|
|
3
|
-
import { filter, take, switchMap, delay, distinctUntilChanged, map, tap, catchError, timeout, debounceTime, startWith, skip } from 'rxjs/operators';
|
|
20
|
+
import { Observable as Observable$1, BehaviorSubject, Subject, firstValueFrom, from as from$1, filter as filter$1, fromEvent, of, merge, Subscription as Subscription$1, throwError, combineLatest, map as map$1, share, timer as timer$1 } from 'rxjs';
|
|
4
21
|
|
|
5
22
|
/******************************************************************************
|
|
6
23
|
Copyright (c) Microsoft Corporation.
|
|
@@ -16,6 +33,22 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
16
33
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
34
|
PERFORMANCE OF THIS SOFTWARE.
|
|
18
35
|
***************************************************************************** */
|
|
36
|
+
/* global Reflect, Promise */
|
|
37
|
+
|
|
38
|
+
var extendStatics = function(d, b) {
|
|
39
|
+
extendStatics = Object.setPrototypeOf ||
|
|
40
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
41
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
42
|
+
return extendStatics(d, b);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function __extends(d, b) {
|
|
46
|
+
if (typeof b !== "function" && b !== null)
|
|
47
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
48
|
+
extendStatics(d, b);
|
|
49
|
+
function __() { this.constructor = d; }
|
|
50
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
51
|
+
}
|
|
19
52
|
|
|
20
53
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
21
54
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -25,6 +58,97 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
25
58
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26
59
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
60
|
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function __generator(thisArg, body) {
|
|
64
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
65
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
66
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
67
|
+
function step(op) {
|
|
68
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
69
|
+
while (_) try {
|
|
70
|
+
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;
|
|
71
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
72
|
+
switch (op[0]) {
|
|
73
|
+
case 0: case 1: t = op; break;
|
|
74
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
75
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
76
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
77
|
+
default:
|
|
78
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
79
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
80
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
81
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
82
|
+
if (t[2]) _.ops.pop();
|
|
83
|
+
_.trys.pop(); continue;
|
|
84
|
+
}
|
|
85
|
+
op = body.call(thisArg, _);
|
|
86
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
87
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function __values(o) {
|
|
92
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
93
|
+
if (m) return m.call(o);
|
|
94
|
+
if (o && typeof o.length === "number") return {
|
|
95
|
+
next: function () {
|
|
96
|
+
if (o && i >= o.length) o = void 0;
|
|
97
|
+
return { value: o && o[i++], done: !o };
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function __read(o, n) {
|
|
104
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
105
|
+
if (!m) return o;
|
|
106
|
+
var i = m.call(o), r, ar = [], e;
|
|
107
|
+
try {
|
|
108
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
109
|
+
}
|
|
110
|
+
catch (error) { e = { error: error }; }
|
|
111
|
+
finally {
|
|
112
|
+
try {
|
|
113
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
114
|
+
}
|
|
115
|
+
finally { if (e) throw e.error; }
|
|
116
|
+
}
|
|
117
|
+
return ar;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function __spreadArray(to, from, pack) {
|
|
121
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
122
|
+
if (ar || !(i in from)) {
|
|
123
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
124
|
+
ar[i] = from[i];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function __await(v) {
|
|
131
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
135
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
136
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
137
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
138
|
+
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); }); }; }
|
|
139
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
140
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
141
|
+
function fulfill(value) { resume("next", value); }
|
|
142
|
+
function reject(value) { resume("throw", value); }
|
|
143
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function __asyncValues(o) {
|
|
147
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
148
|
+
var m = o[Symbol.asyncIterator], i;
|
|
149
|
+
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);
|
|
150
|
+
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); }); }; }
|
|
151
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
28
152
|
}
|
|
29
153
|
|
|
30
154
|
const UNAUTHORIZED_USER = {
|
|
@@ -127,7 +251,7 @@ function dispatch(ev) {
|
|
|
127
251
|
});
|
|
128
252
|
}
|
|
129
253
|
}
|
|
130
|
-
class BroadcastedAndLocalEvent extends Observable {
|
|
254
|
+
class BroadcastedAndLocalEvent extends Observable$1 {
|
|
131
255
|
constructor(name) {
|
|
132
256
|
const bc = typeof BroadcastChannel === "undefined"
|
|
133
257
|
? new SWBroadcastChannel(name) : new BroadcastChannel(name);
|
|
@@ -164,18 +288,1436 @@ class BroadcastedAndLocalEvent extends Observable {
|
|
|
164
288
|
else {
|
|
165
289
|
bc.removeEventListener("message", onMessageEvent);
|
|
166
290
|
}
|
|
167
|
-
};
|
|
291
|
+
};
|
|
292
|
+
});
|
|
293
|
+
this.name = name;
|
|
294
|
+
this.bc = bc;
|
|
295
|
+
}
|
|
296
|
+
next(message) {
|
|
297
|
+
console.debug("BroadcastedAndLocalEvent: bc.postMessage()", Object.assign({}, message), "bc is a", this.bc);
|
|
298
|
+
this.bc.postMessage(message);
|
|
299
|
+
const ev = new CustomEvent(`lbc-${this.name}`, { detail: message });
|
|
300
|
+
//self.dispatchEvent(ev);
|
|
301
|
+
dispatch(ev);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function isFunction(value) {
|
|
306
|
+
return typeof value === 'function';
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function hasLift(source) {
|
|
310
|
+
return isFunction(source === null || source === void 0 ? void 0 : source.lift);
|
|
311
|
+
}
|
|
312
|
+
function operate(init) {
|
|
313
|
+
return function (source) {
|
|
314
|
+
if (hasLift(source)) {
|
|
315
|
+
return source.lift(function (liftedSource) {
|
|
316
|
+
try {
|
|
317
|
+
return init(liftedSource, this);
|
|
318
|
+
}
|
|
319
|
+
catch (err) {
|
|
320
|
+
this.error(err);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
throw new TypeError('Unable to lift unknown Observable type');
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
|
|
329
|
+
|
|
330
|
+
function isPromise(value) {
|
|
331
|
+
return isFunction(value === null || value === void 0 ? void 0 : value.then);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function createErrorClass(createImpl) {
|
|
335
|
+
var _super = function (instance) {
|
|
336
|
+
Error.call(instance);
|
|
337
|
+
instance.stack = new Error().stack;
|
|
338
|
+
};
|
|
339
|
+
var ctorFunc = createImpl(_super);
|
|
340
|
+
ctorFunc.prototype = Object.create(Error.prototype);
|
|
341
|
+
ctorFunc.prototype.constructor = ctorFunc;
|
|
342
|
+
return ctorFunc;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
var UnsubscriptionError = createErrorClass(function (_super) {
|
|
346
|
+
return function UnsubscriptionErrorImpl(errors) {
|
|
347
|
+
_super(this);
|
|
348
|
+
this.message = errors
|
|
349
|
+
? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
|
|
350
|
+
: '';
|
|
351
|
+
this.name = 'UnsubscriptionError';
|
|
352
|
+
this.errors = errors;
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
function arrRemove(arr, item) {
|
|
357
|
+
if (arr) {
|
|
358
|
+
var index = arr.indexOf(item);
|
|
359
|
+
0 <= index && arr.splice(index, 1);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
var Subscription = (function () {
|
|
364
|
+
function Subscription(initialTeardown) {
|
|
365
|
+
this.initialTeardown = initialTeardown;
|
|
366
|
+
this.closed = false;
|
|
367
|
+
this._parentage = null;
|
|
368
|
+
this._finalizers = null;
|
|
369
|
+
}
|
|
370
|
+
Subscription.prototype.unsubscribe = function () {
|
|
371
|
+
var e_1, _a, e_2, _b;
|
|
372
|
+
var errors;
|
|
373
|
+
if (!this.closed) {
|
|
374
|
+
this.closed = true;
|
|
375
|
+
var _parentage = this._parentage;
|
|
376
|
+
if (_parentage) {
|
|
377
|
+
this._parentage = null;
|
|
378
|
+
if (Array.isArray(_parentage)) {
|
|
379
|
+
try {
|
|
380
|
+
for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
|
381
|
+
var parent_1 = _parentage_1_1.value;
|
|
382
|
+
parent_1.remove(this);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
386
|
+
finally {
|
|
387
|
+
try {
|
|
388
|
+
if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
|
|
389
|
+
}
|
|
390
|
+
finally { if (e_1) throw e_1.error; }
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
_parentage.remove(this);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
var initialFinalizer = this.initialTeardown;
|
|
398
|
+
if (isFunction(initialFinalizer)) {
|
|
399
|
+
try {
|
|
400
|
+
initialFinalizer();
|
|
401
|
+
}
|
|
402
|
+
catch (e) {
|
|
403
|
+
errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
var _finalizers = this._finalizers;
|
|
407
|
+
if (_finalizers) {
|
|
408
|
+
this._finalizers = null;
|
|
409
|
+
try {
|
|
410
|
+
for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
|
|
411
|
+
var finalizer = _finalizers_1_1.value;
|
|
412
|
+
try {
|
|
413
|
+
execFinalizer(finalizer);
|
|
414
|
+
}
|
|
415
|
+
catch (err) {
|
|
416
|
+
errors = errors !== null && errors !== void 0 ? errors : [];
|
|
417
|
+
if (err instanceof UnsubscriptionError) {
|
|
418
|
+
errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
errors.push(err);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
427
|
+
finally {
|
|
428
|
+
try {
|
|
429
|
+
if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
|
|
430
|
+
}
|
|
431
|
+
finally { if (e_2) throw e_2.error; }
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (errors) {
|
|
435
|
+
throw new UnsubscriptionError(errors);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
Subscription.prototype.add = function (teardown) {
|
|
440
|
+
var _a;
|
|
441
|
+
if (teardown && teardown !== this) {
|
|
442
|
+
if (this.closed) {
|
|
443
|
+
execFinalizer(teardown);
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
if (teardown instanceof Subscription) {
|
|
447
|
+
if (teardown.closed || teardown._hasParent(this)) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
teardown._addParent(this);
|
|
451
|
+
}
|
|
452
|
+
(this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
Subscription.prototype._hasParent = function (parent) {
|
|
457
|
+
var _parentage = this._parentage;
|
|
458
|
+
return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
|
|
459
|
+
};
|
|
460
|
+
Subscription.prototype._addParent = function (parent) {
|
|
461
|
+
var _parentage = this._parentage;
|
|
462
|
+
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
463
|
+
};
|
|
464
|
+
Subscription.prototype._removeParent = function (parent) {
|
|
465
|
+
var _parentage = this._parentage;
|
|
466
|
+
if (_parentage === parent) {
|
|
467
|
+
this._parentage = null;
|
|
468
|
+
}
|
|
469
|
+
else if (Array.isArray(_parentage)) {
|
|
470
|
+
arrRemove(_parentage, parent);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
Subscription.prototype.remove = function (teardown) {
|
|
474
|
+
var _finalizers = this._finalizers;
|
|
475
|
+
_finalizers && arrRemove(_finalizers, teardown);
|
|
476
|
+
if (teardown instanceof Subscription) {
|
|
477
|
+
teardown._removeParent(this);
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
Subscription.EMPTY = (function () {
|
|
481
|
+
var empty = new Subscription();
|
|
482
|
+
empty.closed = true;
|
|
483
|
+
return empty;
|
|
484
|
+
})();
|
|
485
|
+
return Subscription;
|
|
486
|
+
}());
|
|
487
|
+
Subscription.EMPTY;
|
|
488
|
+
function isSubscription(value) {
|
|
489
|
+
return (value instanceof Subscription ||
|
|
490
|
+
(value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
|
|
491
|
+
}
|
|
492
|
+
function execFinalizer(finalizer) {
|
|
493
|
+
if (isFunction(finalizer)) {
|
|
494
|
+
finalizer();
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
finalizer.unsubscribe();
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
var config = {
|
|
502
|
+
onUnhandledError: null,
|
|
503
|
+
onStoppedNotification: null,
|
|
504
|
+
Promise: undefined,
|
|
505
|
+
useDeprecatedSynchronousErrorHandling: false,
|
|
506
|
+
useDeprecatedNextContext: false,
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
var timeoutProvider = {
|
|
510
|
+
setTimeout: function (handler, timeout) {
|
|
511
|
+
var args = [];
|
|
512
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
513
|
+
args[_i - 2] = arguments[_i];
|
|
514
|
+
}
|
|
515
|
+
var delegate = timeoutProvider.delegate;
|
|
516
|
+
if (delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) {
|
|
517
|
+
return delegate.setTimeout.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
518
|
+
}
|
|
519
|
+
return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
520
|
+
},
|
|
521
|
+
clearTimeout: function (handle) {
|
|
522
|
+
var delegate = timeoutProvider.delegate;
|
|
523
|
+
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
|
|
524
|
+
},
|
|
525
|
+
delegate: undefined,
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
function reportUnhandledError(err) {
|
|
529
|
+
timeoutProvider.setTimeout(function () {
|
|
530
|
+
{
|
|
531
|
+
throw err;
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function noop() { }
|
|
537
|
+
|
|
538
|
+
function errorContext(cb) {
|
|
539
|
+
{
|
|
540
|
+
cb();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
var Subscriber = (function (_super) {
|
|
545
|
+
__extends(Subscriber, _super);
|
|
546
|
+
function Subscriber(destination) {
|
|
547
|
+
var _this = _super.call(this) || this;
|
|
548
|
+
_this.isStopped = false;
|
|
549
|
+
if (destination) {
|
|
550
|
+
_this.destination = destination;
|
|
551
|
+
if (isSubscription(destination)) {
|
|
552
|
+
destination.add(_this);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
_this.destination = EMPTY_OBSERVER;
|
|
557
|
+
}
|
|
558
|
+
return _this;
|
|
559
|
+
}
|
|
560
|
+
Subscriber.create = function (next, error, complete) {
|
|
561
|
+
return new SafeSubscriber(next, error, complete);
|
|
562
|
+
};
|
|
563
|
+
Subscriber.prototype.next = function (value) {
|
|
564
|
+
if (this.isStopped) ;
|
|
565
|
+
else {
|
|
566
|
+
this._next(value);
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
Subscriber.prototype.error = function (err) {
|
|
570
|
+
if (this.isStopped) ;
|
|
571
|
+
else {
|
|
572
|
+
this.isStopped = true;
|
|
573
|
+
this._error(err);
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
Subscriber.prototype.complete = function () {
|
|
577
|
+
if (this.isStopped) ;
|
|
578
|
+
else {
|
|
579
|
+
this.isStopped = true;
|
|
580
|
+
this._complete();
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
Subscriber.prototype.unsubscribe = function () {
|
|
584
|
+
if (!this.closed) {
|
|
585
|
+
this.isStopped = true;
|
|
586
|
+
_super.prototype.unsubscribe.call(this);
|
|
587
|
+
this.destination = null;
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
Subscriber.prototype._next = function (value) {
|
|
591
|
+
this.destination.next(value);
|
|
592
|
+
};
|
|
593
|
+
Subscriber.prototype._error = function (err) {
|
|
594
|
+
try {
|
|
595
|
+
this.destination.error(err);
|
|
596
|
+
}
|
|
597
|
+
finally {
|
|
598
|
+
this.unsubscribe();
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
Subscriber.prototype._complete = function () {
|
|
602
|
+
try {
|
|
603
|
+
this.destination.complete();
|
|
604
|
+
}
|
|
605
|
+
finally {
|
|
606
|
+
this.unsubscribe();
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
return Subscriber;
|
|
610
|
+
}(Subscription));
|
|
611
|
+
var _bind = Function.prototype.bind;
|
|
612
|
+
function bind(fn, thisArg) {
|
|
613
|
+
return _bind.call(fn, thisArg);
|
|
614
|
+
}
|
|
615
|
+
var ConsumerObserver = (function () {
|
|
616
|
+
function ConsumerObserver(partialObserver) {
|
|
617
|
+
this.partialObserver = partialObserver;
|
|
618
|
+
}
|
|
619
|
+
ConsumerObserver.prototype.next = function (value) {
|
|
620
|
+
var partialObserver = this.partialObserver;
|
|
621
|
+
if (partialObserver.next) {
|
|
622
|
+
try {
|
|
623
|
+
partialObserver.next(value);
|
|
624
|
+
}
|
|
625
|
+
catch (error) {
|
|
626
|
+
handleUnhandledError(error);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
ConsumerObserver.prototype.error = function (err) {
|
|
631
|
+
var partialObserver = this.partialObserver;
|
|
632
|
+
if (partialObserver.error) {
|
|
633
|
+
try {
|
|
634
|
+
partialObserver.error(err);
|
|
635
|
+
}
|
|
636
|
+
catch (error) {
|
|
637
|
+
handleUnhandledError(error);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
handleUnhandledError(err);
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
ConsumerObserver.prototype.complete = function () {
|
|
645
|
+
var partialObserver = this.partialObserver;
|
|
646
|
+
if (partialObserver.complete) {
|
|
647
|
+
try {
|
|
648
|
+
partialObserver.complete();
|
|
649
|
+
}
|
|
650
|
+
catch (error) {
|
|
651
|
+
handleUnhandledError(error);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
return ConsumerObserver;
|
|
656
|
+
}());
|
|
657
|
+
var SafeSubscriber = (function (_super) {
|
|
658
|
+
__extends(SafeSubscriber, _super);
|
|
659
|
+
function SafeSubscriber(observerOrNext, error, complete) {
|
|
660
|
+
var _this = _super.call(this) || this;
|
|
661
|
+
var partialObserver;
|
|
662
|
+
if (isFunction(observerOrNext) || !observerOrNext) {
|
|
663
|
+
partialObserver = {
|
|
664
|
+
next: (observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined),
|
|
665
|
+
error: error !== null && error !== void 0 ? error : undefined,
|
|
666
|
+
complete: complete !== null && complete !== void 0 ? complete : undefined,
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
var context_1;
|
|
671
|
+
if (_this && config.useDeprecatedNextContext) {
|
|
672
|
+
context_1 = Object.create(observerOrNext);
|
|
673
|
+
context_1.unsubscribe = function () { return _this.unsubscribe(); };
|
|
674
|
+
partialObserver = {
|
|
675
|
+
next: observerOrNext.next && bind(observerOrNext.next, context_1),
|
|
676
|
+
error: observerOrNext.error && bind(observerOrNext.error, context_1),
|
|
677
|
+
complete: observerOrNext.complete && bind(observerOrNext.complete, context_1),
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
partialObserver = observerOrNext;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
_this.destination = new ConsumerObserver(partialObserver);
|
|
685
|
+
return _this;
|
|
686
|
+
}
|
|
687
|
+
return SafeSubscriber;
|
|
688
|
+
}(Subscriber));
|
|
689
|
+
function handleUnhandledError(error) {
|
|
690
|
+
{
|
|
691
|
+
reportUnhandledError(error);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
function defaultErrorHandler(err) {
|
|
695
|
+
throw err;
|
|
696
|
+
}
|
|
697
|
+
var EMPTY_OBSERVER = {
|
|
698
|
+
closed: true,
|
|
699
|
+
next: noop,
|
|
700
|
+
error: defaultErrorHandler,
|
|
701
|
+
complete: noop,
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
|
|
705
|
+
|
|
706
|
+
function identity(x) {
|
|
707
|
+
return x;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
function pipeFromArray(fns) {
|
|
711
|
+
if (fns.length === 0) {
|
|
712
|
+
return identity;
|
|
713
|
+
}
|
|
714
|
+
if (fns.length === 1) {
|
|
715
|
+
return fns[0];
|
|
716
|
+
}
|
|
717
|
+
return function piped(input) {
|
|
718
|
+
return fns.reduce(function (prev, fn) { return fn(prev); }, input);
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
var Observable = (function () {
|
|
723
|
+
function Observable(subscribe) {
|
|
724
|
+
if (subscribe) {
|
|
725
|
+
this._subscribe = subscribe;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
Observable.prototype.lift = function (operator) {
|
|
729
|
+
var observable = new Observable();
|
|
730
|
+
observable.source = this;
|
|
731
|
+
observable.operator = operator;
|
|
732
|
+
return observable;
|
|
733
|
+
};
|
|
734
|
+
Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
|
735
|
+
var _this = this;
|
|
736
|
+
var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
|
737
|
+
errorContext(function () {
|
|
738
|
+
var _a = _this, operator = _a.operator, source = _a.source;
|
|
739
|
+
subscriber.add(operator
|
|
740
|
+
?
|
|
741
|
+
operator.call(subscriber, source)
|
|
742
|
+
: source
|
|
743
|
+
?
|
|
744
|
+
_this._subscribe(subscriber)
|
|
745
|
+
:
|
|
746
|
+
_this._trySubscribe(subscriber));
|
|
747
|
+
});
|
|
748
|
+
return subscriber;
|
|
749
|
+
};
|
|
750
|
+
Observable.prototype._trySubscribe = function (sink) {
|
|
751
|
+
try {
|
|
752
|
+
return this._subscribe(sink);
|
|
753
|
+
}
|
|
754
|
+
catch (err) {
|
|
755
|
+
sink.error(err);
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
Observable.prototype.forEach = function (next, promiseCtor) {
|
|
759
|
+
var _this = this;
|
|
760
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
761
|
+
return new promiseCtor(function (resolve, reject) {
|
|
762
|
+
var subscriber = new SafeSubscriber({
|
|
763
|
+
next: function (value) {
|
|
764
|
+
try {
|
|
765
|
+
next(value);
|
|
766
|
+
}
|
|
767
|
+
catch (err) {
|
|
768
|
+
reject(err);
|
|
769
|
+
subscriber.unsubscribe();
|
|
770
|
+
}
|
|
771
|
+
},
|
|
772
|
+
error: reject,
|
|
773
|
+
complete: resolve,
|
|
774
|
+
});
|
|
775
|
+
_this.subscribe(subscriber);
|
|
776
|
+
});
|
|
777
|
+
};
|
|
778
|
+
Observable.prototype._subscribe = function (subscriber) {
|
|
779
|
+
var _a;
|
|
780
|
+
return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
|
|
781
|
+
};
|
|
782
|
+
Observable.prototype[observable] = function () {
|
|
783
|
+
return this;
|
|
784
|
+
};
|
|
785
|
+
Observable.prototype.pipe = function () {
|
|
786
|
+
var operations = [];
|
|
787
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
788
|
+
operations[_i] = arguments[_i];
|
|
789
|
+
}
|
|
790
|
+
return pipeFromArray(operations)(this);
|
|
791
|
+
};
|
|
792
|
+
Observable.prototype.toPromise = function (promiseCtor) {
|
|
793
|
+
var _this = this;
|
|
794
|
+
promiseCtor = getPromiseCtor(promiseCtor);
|
|
795
|
+
return new promiseCtor(function (resolve, reject) {
|
|
796
|
+
var value;
|
|
797
|
+
_this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
|
|
798
|
+
});
|
|
799
|
+
};
|
|
800
|
+
Observable.create = function (subscribe) {
|
|
801
|
+
return new Observable(subscribe);
|
|
802
|
+
};
|
|
803
|
+
return Observable;
|
|
804
|
+
}());
|
|
805
|
+
function getPromiseCtor(promiseCtor) {
|
|
806
|
+
var _a;
|
|
807
|
+
return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
|
|
808
|
+
}
|
|
809
|
+
function isObserver(value) {
|
|
810
|
+
return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
|
|
811
|
+
}
|
|
812
|
+
function isSubscriber(value) {
|
|
813
|
+
return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
function isInteropObservable(input) {
|
|
817
|
+
return isFunction(input[observable]);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
function isAsyncIterable(obj) {
|
|
821
|
+
return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
function createInvalidObservableTypeError(input) {
|
|
825
|
+
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.");
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
function getSymbolIterator() {
|
|
829
|
+
if (typeof Symbol !== 'function' || !Symbol.iterator) {
|
|
830
|
+
return '@@iterator';
|
|
831
|
+
}
|
|
832
|
+
return Symbol.iterator;
|
|
833
|
+
}
|
|
834
|
+
var iterator = getSymbolIterator();
|
|
835
|
+
|
|
836
|
+
function isIterable(input) {
|
|
837
|
+
return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
function readableStreamLikeToAsyncGenerator(readableStream) {
|
|
841
|
+
return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
|
|
842
|
+
var reader, _a, value, done;
|
|
843
|
+
return __generator(this, function (_b) {
|
|
844
|
+
switch (_b.label) {
|
|
845
|
+
case 0:
|
|
846
|
+
reader = readableStream.getReader();
|
|
847
|
+
_b.label = 1;
|
|
848
|
+
case 1:
|
|
849
|
+
_b.trys.push([1, , 9, 10]);
|
|
850
|
+
_b.label = 2;
|
|
851
|
+
case 2:
|
|
852
|
+
return [4, __await(reader.read())];
|
|
853
|
+
case 3:
|
|
854
|
+
_a = _b.sent(), value = _a.value, done = _a.done;
|
|
855
|
+
if (!done) return [3, 5];
|
|
856
|
+
return [4, __await(void 0)];
|
|
857
|
+
case 4: return [2, _b.sent()];
|
|
858
|
+
case 5: return [4, __await(value)];
|
|
859
|
+
case 6: return [4, _b.sent()];
|
|
860
|
+
case 7:
|
|
861
|
+
_b.sent();
|
|
862
|
+
return [3, 2];
|
|
863
|
+
case 8: return [3, 10];
|
|
864
|
+
case 9:
|
|
865
|
+
reader.releaseLock();
|
|
866
|
+
return [7];
|
|
867
|
+
case 10: return [2];
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
function isReadableStreamLike(obj) {
|
|
873
|
+
return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
function innerFrom(input) {
|
|
877
|
+
if (input instanceof Observable) {
|
|
878
|
+
return input;
|
|
879
|
+
}
|
|
880
|
+
if (input != null) {
|
|
881
|
+
if (isInteropObservable(input)) {
|
|
882
|
+
return fromInteropObservable(input);
|
|
883
|
+
}
|
|
884
|
+
if (isArrayLike(input)) {
|
|
885
|
+
return fromArrayLike(input);
|
|
886
|
+
}
|
|
887
|
+
if (isPromise(input)) {
|
|
888
|
+
return fromPromise(input);
|
|
889
|
+
}
|
|
890
|
+
if (isAsyncIterable(input)) {
|
|
891
|
+
return fromAsyncIterable(input);
|
|
892
|
+
}
|
|
893
|
+
if (isIterable(input)) {
|
|
894
|
+
return fromIterable(input);
|
|
895
|
+
}
|
|
896
|
+
if (isReadableStreamLike(input)) {
|
|
897
|
+
return fromReadableStreamLike(input);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
throw createInvalidObservableTypeError(input);
|
|
901
|
+
}
|
|
902
|
+
function fromInteropObservable(obj) {
|
|
903
|
+
return new Observable(function (subscriber) {
|
|
904
|
+
var obs = obj[observable]();
|
|
905
|
+
if (isFunction(obs.subscribe)) {
|
|
906
|
+
return obs.subscribe(subscriber);
|
|
907
|
+
}
|
|
908
|
+
throw new TypeError('Provided object does not correctly implement Symbol.observable');
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
function fromArrayLike(array) {
|
|
912
|
+
return new Observable(function (subscriber) {
|
|
913
|
+
for (var i = 0; i < array.length && !subscriber.closed; i++) {
|
|
914
|
+
subscriber.next(array[i]);
|
|
915
|
+
}
|
|
916
|
+
subscriber.complete();
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
function fromPromise(promise) {
|
|
920
|
+
return new Observable(function (subscriber) {
|
|
921
|
+
promise
|
|
922
|
+
.then(function (value) {
|
|
923
|
+
if (!subscriber.closed) {
|
|
924
|
+
subscriber.next(value);
|
|
925
|
+
subscriber.complete();
|
|
926
|
+
}
|
|
927
|
+
}, function (err) { return subscriber.error(err); })
|
|
928
|
+
.then(null, reportUnhandledError);
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
function fromIterable(iterable) {
|
|
932
|
+
return new Observable(function (subscriber) {
|
|
933
|
+
var e_1, _a;
|
|
934
|
+
try {
|
|
935
|
+
for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
|
|
936
|
+
var value = iterable_1_1.value;
|
|
937
|
+
subscriber.next(value);
|
|
938
|
+
if (subscriber.closed) {
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
944
|
+
finally {
|
|
945
|
+
try {
|
|
946
|
+
if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
|
|
947
|
+
}
|
|
948
|
+
finally { if (e_1) throw e_1.error; }
|
|
949
|
+
}
|
|
950
|
+
subscriber.complete();
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
function fromAsyncIterable(asyncIterable) {
|
|
954
|
+
return new Observable(function (subscriber) {
|
|
955
|
+
process(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
function fromReadableStreamLike(readableStream) {
|
|
959
|
+
return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
|
|
960
|
+
}
|
|
961
|
+
function process(asyncIterable, subscriber) {
|
|
962
|
+
var asyncIterable_1, asyncIterable_1_1;
|
|
963
|
+
var e_2, _a;
|
|
964
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
965
|
+
var value, e_2_1;
|
|
966
|
+
return __generator(this, function (_b) {
|
|
967
|
+
switch (_b.label) {
|
|
968
|
+
case 0:
|
|
969
|
+
_b.trys.push([0, 5, 6, 11]);
|
|
970
|
+
asyncIterable_1 = __asyncValues(asyncIterable);
|
|
971
|
+
_b.label = 1;
|
|
972
|
+
case 1: return [4, asyncIterable_1.next()];
|
|
973
|
+
case 2:
|
|
974
|
+
if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
|
|
975
|
+
value = asyncIterable_1_1.value;
|
|
976
|
+
subscriber.next(value);
|
|
977
|
+
if (subscriber.closed) {
|
|
978
|
+
return [2];
|
|
979
|
+
}
|
|
980
|
+
_b.label = 3;
|
|
981
|
+
case 3: return [3, 1];
|
|
982
|
+
case 4: return [3, 11];
|
|
983
|
+
case 5:
|
|
984
|
+
e_2_1 = _b.sent();
|
|
985
|
+
e_2 = { error: e_2_1 };
|
|
986
|
+
return [3, 11];
|
|
987
|
+
case 6:
|
|
988
|
+
_b.trys.push([6, , 9, 10]);
|
|
989
|
+
if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
|
|
990
|
+
return [4, _a.call(asyncIterable_1)];
|
|
991
|
+
case 7:
|
|
992
|
+
_b.sent();
|
|
993
|
+
_b.label = 8;
|
|
994
|
+
case 8: return [3, 10];
|
|
995
|
+
case 9:
|
|
996
|
+
if (e_2) throw e_2.error;
|
|
997
|
+
return [7];
|
|
998
|
+
case 10: return [7];
|
|
999
|
+
case 11:
|
|
1000
|
+
subscriber.complete();
|
|
1001
|
+
return [2];
|
|
1002
|
+
}
|
|
1003
|
+
});
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
|
|
1008
|
+
return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
|
|
1009
|
+
}
|
|
1010
|
+
var OperatorSubscriber = (function (_super) {
|
|
1011
|
+
__extends(OperatorSubscriber, _super);
|
|
1012
|
+
function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
|
|
1013
|
+
var _this = _super.call(this, destination) || this;
|
|
1014
|
+
_this.onFinalize = onFinalize;
|
|
1015
|
+
_this.shouldUnsubscribe = shouldUnsubscribe;
|
|
1016
|
+
_this._next = onNext
|
|
1017
|
+
? function (value) {
|
|
1018
|
+
try {
|
|
1019
|
+
onNext(value);
|
|
1020
|
+
}
|
|
1021
|
+
catch (err) {
|
|
1022
|
+
destination.error(err);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
: _super.prototype._next;
|
|
1026
|
+
_this._error = onError
|
|
1027
|
+
? function (err) {
|
|
1028
|
+
try {
|
|
1029
|
+
onError(err);
|
|
1030
|
+
}
|
|
1031
|
+
catch (err) {
|
|
1032
|
+
destination.error(err);
|
|
1033
|
+
}
|
|
1034
|
+
finally {
|
|
1035
|
+
this.unsubscribe();
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
: _super.prototype._error;
|
|
1039
|
+
_this._complete = onComplete
|
|
1040
|
+
? function () {
|
|
1041
|
+
try {
|
|
1042
|
+
onComplete();
|
|
1043
|
+
}
|
|
1044
|
+
catch (err) {
|
|
1045
|
+
destination.error(err);
|
|
1046
|
+
}
|
|
1047
|
+
finally {
|
|
1048
|
+
this.unsubscribe();
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
: _super.prototype._complete;
|
|
1052
|
+
return _this;
|
|
1053
|
+
}
|
|
1054
|
+
OperatorSubscriber.prototype.unsubscribe = function () {
|
|
1055
|
+
var _a;
|
|
1056
|
+
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
|
1057
|
+
var closed_1 = this.closed;
|
|
1058
|
+
_super.prototype.unsubscribe.call(this);
|
|
1059
|
+
!closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
return OperatorSubscriber;
|
|
1063
|
+
}(Subscriber));
|
|
1064
|
+
|
|
1065
|
+
var Action = (function (_super) {
|
|
1066
|
+
__extends(Action, _super);
|
|
1067
|
+
function Action(scheduler, work) {
|
|
1068
|
+
return _super.call(this) || this;
|
|
1069
|
+
}
|
|
1070
|
+
Action.prototype.schedule = function (state, delay) {
|
|
1071
|
+
return this;
|
|
1072
|
+
};
|
|
1073
|
+
return Action;
|
|
1074
|
+
}(Subscription));
|
|
1075
|
+
|
|
1076
|
+
var intervalProvider = {
|
|
1077
|
+
setInterval: function (handler, timeout) {
|
|
1078
|
+
var args = [];
|
|
1079
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1080
|
+
args[_i - 2] = arguments[_i];
|
|
1081
|
+
}
|
|
1082
|
+
var delegate = intervalProvider.delegate;
|
|
1083
|
+
if (delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) {
|
|
1084
|
+
return delegate.setInterval.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
1085
|
+
}
|
|
1086
|
+
return setInterval.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
1087
|
+
},
|
|
1088
|
+
clearInterval: function (handle) {
|
|
1089
|
+
var delegate = intervalProvider.delegate;
|
|
1090
|
+
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle);
|
|
1091
|
+
},
|
|
1092
|
+
delegate: undefined,
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
var AsyncAction = (function (_super) {
|
|
1096
|
+
__extends(AsyncAction, _super);
|
|
1097
|
+
function AsyncAction(scheduler, work) {
|
|
1098
|
+
var _this = _super.call(this, scheduler, work) || this;
|
|
1099
|
+
_this.scheduler = scheduler;
|
|
1100
|
+
_this.work = work;
|
|
1101
|
+
_this.pending = false;
|
|
1102
|
+
return _this;
|
|
1103
|
+
}
|
|
1104
|
+
AsyncAction.prototype.schedule = function (state, delay) {
|
|
1105
|
+
if (delay === void 0) { delay = 0; }
|
|
1106
|
+
if (this.closed) {
|
|
1107
|
+
return this;
|
|
1108
|
+
}
|
|
1109
|
+
this.state = state;
|
|
1110
|
+
var id = this.id;
|
|
1111
|
+
var scheduler = this.scheduler;
|
|
1112
|
+
if (id != null) {
|
|
1113
|
+
this.id = this.recycleAsyncId(scheduler, id, delay);
|
|
1114
|
+
}
|
|
1115
|
+
this.pending = true;
|
|
1116
|
+
this.delay = delay;
|
|
1117
|
+
this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
|
|
1118
|
+
return this;
|
|
1119
|
+
};
|
|
1120
|
+
AsyncAction.prototype.requestAsyncId = function (scheduler, _id, delay) {
|
|
1121
|
+
if (delay === void 0) { delay = 0; }
|
|
1122
|
+
return intervalProvider.setInterval(scheduler.flush.bind(scheduler, this), delay);
|
|
1123
|
+
};
|
|
1124
|
+
AsyncAction.prototype.recycleAsyncId = function (_scheduler, id, delay) {
|
|
1125
|
+
if (delay === void 0) { delay = 0; }
|
|
1126
|
+
if (delay != null && this.delay === delay && this.pending === false) {
|
|
1127
|
+
return id;
|
|
1128
|
+
}
|
|
1129
|
+
intervalProvider.clearInterval(id);
|
|
1130
|
+
return undefined;
|
|
1131
|
+
};
|
|
1132
|
+
AsyncAction.prototype.execute = function (state, delay) {
|
|
1133
|
+
if (this.closed) {
|
|
1134
|
+
return new Error('executing a cancelled action');
|
|
1135
|
+
}
|
|
1136
|
+
this.pending = false;
|
|
1137
|
+
var error = this._execute(state, delay);
|
|
1138
|
+
if (error) {
|
|
1139
|
+
return error;
|
|
1140
|
+
}
|
|
1141
|
+
else if (this.pending === false && this.id != null) {
|
|
1142
|
+
this.id = this.recycleAsyncId(this.scheduler, this.id, null);
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
AsyncAction.prototype._execute = function (state, _delay) {
|
|
1146
|
+
var errored = false;
|
|
1147
|
+
var errorValue;
|
|
1148
|
+
try {
|
|
1149
|
+
this.work(state);
|
|
1150
|
+
}
|
|
1151
|
+
catch (e) {
|
|
1152
|
+
errored = true;
|
|
1153
|
+
errorValue = e ? e : new Error('Scheduled action threw falsy error');
|
|
1154
|
+
}
|
|
1155
|
+
if (errored) {
|
|
1156
|
+
this.unsubscribe();
|
|
1157
|
+
return errorValue;
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
AsyncAction.prototype.unsubscribe = function () {
|
|
1161
|
+
if (!this.closed) {
|
|
1162
|
+
var _a = this, id = _a.id, scheduler = _a.scheduler;
|
|
1163
|
+
var actions = scheduler.actions;
|
|
1164
|
+
this.work = this.state = this.scheduler = null;
|
|
1165
|
+
this.pending = false;
|
|
1166
|
+
arrRemove(actions, this);
|
|
1167
|
+
if (id != null) {
|
|
1168
|
+
this.id = this.recycleAsyncId(scheduler, id, null);
|
|
1169
|
+
}
|
|
1170
|
+
this.delay = null;
|
|
1171
|
+
_super.prototype.unsubscribe.call(this);
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
return AsyncAction;
|
|
1175
|
+
}(Action));
|
|
1176
|
+
|
|
1177
|
+
var dateTimestampProvider = {
|
|
1178
|
+
now: function () {
|
|
1179
|
+
return (dateTimestampProvider.delegate || Date).now();
|
|
1180
|
+
},
|
|
1181
|
+
delegate: undefined,
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
var Scheduler = (function () {
|
|
1185
|
+
function Scheduler(schedulerActionCtor, now) {
|
|
1186
|
+
if (now === void 0) { now = Scheduler.now; }
|
|
1187
|
+
this.schedulerActionCtor = schedulerActionCtor;
|
|
1188
|
+
this.now = now;
|
|
1189
|
+
}
|
|
1190
|
+
Scheduler.prototype.schedule = function (work, delay, state) {
|
|
1191
|
+
if (delay === void 0) { delay = 0; }
|
|
1192
|
+
return new this.schedulerActionCtor(this, work).schedule(state, delay);
|
|
1193
|
+
};
|
|
1194
|
+
Scheduler.now = dateTimestampProvider.now;
|
|
1195
|
+
return Scheduler;
|
|
1196
|
+
}());
|
|
1197
|
+
|
|
1198
|
+
var AsyncScheduler = (function (_super) {
|
|
1199
|
+
__extends(AsyncScheduler, _super);
|
|
1200
|
+
function AsyncScheduler(SchedulerAction, now) {
|
|
1201
|
+
if (now === void 0) { now = Scheduler.now; }
|
|
1202
|
+
var _this = _super.call(this, SchedulerAction, now) || this;
|
|
1203
|
+
_this.actions = [];
|
|
1204
|
+
_this._active = false;
|
|
1205
|
+
_this._scheduled = undefined;
|
|
1206
|
+
return _this;
|
|
1207
|
+
}
|
|
1208
|
+
AsyncScheduler.prototype.flush = function (action) {
|
|
1209
|
+
var actions = this.actions;
|
|
1210
|
+
if (this._active) {
|
|
1211
|
+
actions.push(action);
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
var error;
|
|
1215
|
+
this._active = true;
|
|
1216
|
+
do {
|
|
1217
|
+
if ((error = action.execute(action.state, action.delay))) {
|
|
1218
|
+
break;
|
|
1219
|
+
}
|
|
1220
|
+
} while ((action = actions.shift()));
|
|
1221
|
+
this._active = false;
|
|
1222
|
+
if (error) {
|
|
1223
|
+
while ((action = actions.shift())) {
|
|
1224
|
+
action.unsubscribe();
|
|
1225
|
+
}
|
|
1226
|
+
throw error;
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
return AsyncScheduler;
|
|
1230
|
+
}(Scheduler));
|
|
1231
|
+
|
|
1232
|
+
var asyncScheduler = new AsyncScheduler(AsyncAction);
|
|
1233
|
+
var async = asyncScheduler;
|
|
1234
|
+
|
|
1235
|
+
function isScheduler(value) {
|
|
1236
|
+
return value && isFunction(value.schedule);
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
function isValidDate(value) {
|
|
1240
|
+
return value instanceof Date && !isNaN(value);
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
function timer(dueTime, intervalOrScheduler, scheduler) {
|
|
1244
|
+
if (dueTime === void 0) { dueTime = 0; }
|
|
1245
|
+
if (scheduler === void 0) { scheduler = async; }
|
|
1246
|
+
var intervalDuration = -1;
|
|
1247
|
+
if (intervalOrScheduler != null) {
|
|
1248
|
+
if (isScheduler(intervalOrScheduler)) {
|
|
1249
|
+
scheduler = intervalOrScheduler;
|
|
1250
|
+
}
|
|
1251
|
+
else {
|
|
1252
|
+
intervalDuration = intervalOrScheduler;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
return new Observable(function (subscriber) {
|
|
1256
|
+
var due = isValidDate(dueTime) ? +dueTime - scheduler.now() : dueTime;
|
|
1257
|
+
if (due < 0) {
|
|
1258
|
+
due = 0;
|
|
1259
|
+
}
|
|
1260
|
+
var n = 0;
|
|
1261
|
+
return scheduler.schedule(function () {
|
|
1262
|
+
if (!subscriber.closed) {
|
|
1263
|
+
subscriber.next(n++);
|
|
1264
|
+
if (0 <= intervalDuration) {
|
|
1265
|
+
this.schedule(undefined, intervalDuration);
|
|
1266
|
+
}
|
|
1267
|
+
else {
|
|
1268
|
+
subscriber.complete();
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}, due);
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
function last(arr) {
|
|
1276
|
+
return arr[arr.length - 1];
|
|
1277
|
+
}
|
|
1278
|
+
function popScheduler(args) {
|
|
1279
|
+
return isScheduler(last(args)) ? args.pop() : undefined;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
|
|
1283
|
+
if (delay === void 0) { delay = 0; }
|
|
1284
|
+
if (repeat === void 0) { repeat = false; }
|
|
1285
|
+
var scheduleSubscription = scheduler.schedule(function () {
|
|
1286
|
+
work();
|
|
1287
|
+
if (repeat) {
|
|
1288
|
+
parentSubscription.add(this.schedule(null, delay));
|
|
1289
|
+
}
|
|
1290
|
+
else {
|
|
1291
|
+
this.unsubscribe();
|
|
1292
|
+
}
|
|
1293
|
+
}, delay);
|
|
1294
|
+
parentSubscription.add(scheduleSubscription);
|
|
1295
|
+
if (!repeat) {
|
|
1296
|
+
return scheduleSubscription;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
function catchError(selector) {
|
|
1301
|
+
return operate(function (source, subscriber) {
|
|
1302
|
+
var innerSub = null;
|
|
1303
|
+
var syncUnsub = false;
|
|
1304
|
+
var handledResult;
|
|
1305
|
+
innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, undefined, function (err) {
|
|
1306
|
+
handledResult = innerFrom(selector(err, catchError(selector)(source)));
|
|
1307
|
+
if (innerSub) {
|
|
1308
|
+
innerSub.unsubscribe();
|
|
1309
|
+
innerSub = null;
|
|
1310
|
+
handledResult.subscribe(subscriber);
|
|
1311
|
+
}
|
|
1312
|
+
else {
|
|
1313
|
+
syncUnsub = true;
|
|
1314
|
+
}
|
|
1315
|
+
}));
|
|
1316
|
+
if (syncUnsub) {
|
|
1317
|
+
innerSub.unsubscribe();
|
|
1318
|
+
innerSub = null;
|
|
1319
|
+
handledResult.subscribe(subscriber);
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
function observeOn(scheduler, delay) {
|
|
1325
|
+
if (delay === void 0) { delay = 0; }
|
|
1326
|
+
return operate(function (source, subscriber) {
|
|
1327
|
+
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); }));
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
function subscribeOn(scheduler, delay) {
|
|
1332
|
+
if (delay === void 0) { delay = 0; }
|
|
1333
|
+
return operate(function (source, subscriber) {
|
|
1334
|
+
subscriber.add(scheduler.schedule(function () { return source.subscribe(subscriber); }, delay));
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
function scheduleObservable(input, scheduler) {
|
|
1339
|
+
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
function schedulePromise(input, scheduler) {
|
|
1343
|
+
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
function scheduleArray(input, scheduler) {
|
|
1347
|
+
return new Observable(function (subscriber) {
|
|
1348
|
+
var i = 0;
|
|
1349
|
+
return scheduler.schedule(function () {
|
|
1350
|
+
if (i === input.length) {
|
|
1351
|
+
subscriber.complete();
|
|
1352
|
+
}
|
|
1353
|
+
else {
|
|
1354
|
+
subscriber.next(input[i++]);
|
|
1355
|
+
if (!subscriber.closed) {
|
|
1356
|
+
this.schedule();
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
});
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
function scheduleIterable(input, scheduler) {
|
|
1364
|
+
return new Observable(function (subscriber) {
|
|
1365
|
+
var iterator$1;
|
|
1366
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1367
|
+
iterator$1 = input[iterator]();
|
|
1368
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1369
|
+
var _a;
|
|
1370
|
+
var value;
|
|
1371
|
+
var done;
|
|
1372
|
+
try {
|
|
1373
|
+
(_a = iterator$1.next(), value = _a.value, done = _a.done);
|
|
1374
|
+
}
|
|
1375
|
+
catch (err) {
|
|
1376
|
+
subscriber.error(err);
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
if (done) {
|
|
1380
|
+
subscriber.complete();
|
|
1381
|
+
}
|
|
1382
|
+
else {
|
|
1383
|
+
subscriber.next(value);
|
|
1384
|
+
}
|
|
1385
|
+
}, 0, true);
|
|
1386
|
+
});
|
|
1387
|
+
return function () { return isFunction(iterator$1 === null || iterator$1 === void 0 ? void 0 : iterator$1.return) && iterator$1.return(); };
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
function scheduleAsyncIterable(input, scheduler) {
|
|
1392
|
+
if (!input) {
|
|
1393
|
+
throw new Error('Iterable cannot be null');
|
|
1394
|
+
}
|
|
1395
|
+
return new Observable(function (subscriber) {
|
|
1396
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1397
|
+
var iterator = input[Symbol.asyncIterator]();
|
|
1398
|
+
executeSchedule(subscriber, scheduler, function () {
|
|
1399
|
+
iterator.next().then(function (result) {
|
|
1400
|
+
if (result.done) {
|
|
1401
|
+
subscriber.complete();
|
|
1402
|
+
}
|
|
1403
|
+
else {
|
|
1404
|
+
subscriber.next(result.value);
|
|
1405
|
+
}
|
|
1406
|
+
});
|
|
1407
|
+
}, 0, true);
|
|
1408
|
+
});
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
function scheduleReadableStreamLike(input, scheduler) {
|
|
1413
|
+
return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
function scheduled(input, scheduler) {
|
|
1417
|
+
if (input != null) {
|
|
1418
|
+
if (isInteropObservable(input)) {
|
|
1419
|
+
return scheduleObservable(input, scheduler);
|
|
1420
|
+
}
|
|
1421
|
+
if (isArrayLike(input)) {
|
|
1422
|
+
return scheduleArray(input, scheduler);
|
|
1423
|
+
}
|
|
1424
|
+
if (isPromise(input)) {
|
|
1425
|
+
return schedulePromise(input, scheduler);
|
|
1426
|
+
}
|
|
1427
|
+
if (isAsyncIterable(input)) {
|
|
1428
|
+
return scheduleAsyncIterable(input, scheduler);
|
|
1429
|
+
}
|
|
1430
|
+
if (isIterable(input)) {
|
|
1431
|
+
return scheduleIterable(input, scheduler);
|
|
1432
|
+
}
|
|
1433
|
+
if (isReadableStreamLike(input)) {
|
|
1434
|
+
return scheduleReadableStreamLike(input, scheduler);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
throw createInvalidObservableTypeError(input);
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
function from(input, scheduler) {
|
|
1441
|
+
return scheduler ? scheduled(input, scheduler) : innerFrom(input);
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
function map(project, thisArg) {
|
|
1445
|
+
return operate(function (source, subscriber) {
|
|
1446
|
+
var index = 0;
|
|
1447
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1448
|
+
subscriber.next(project.call(thisArg, value, index++));
|
|
1449
|
+
}));
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
|
|
1454
|
+
var buffer = [];
|
|
1455
|
+
var active = 0;
|
|
1456
|
+
var index = 0;
|
|
1457
|
+
var isComplete = false;
|
|
1458
|
+
var checkComplete = function () {
|
|
1459
|
+
if (isComplete && !buffer.length && !active) {
|
|
1460
|
+
subscriber.complete();
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
var outerNext = function (value) { return (active < concurrent ? doInnerSub(value) : buffer.push(value)); };
|
|
1464
|
+
var doInnerSub = function (value) {
|
|
1465
|
+
expand && subscriber.next(value);
|
|
1466
|
+
active++;
|
|
1467
|
+
var innerComplete = false;
|
|
1468
|
+
innerFrom(project(value, index++)).subscribe(createOperatorSubscriber(subscriber, function (innerValue) {
|
|
1469
|
+
onBeforeNext === null || onBeforeNext === void 0 ? void 0 : onBeforeNext(innerValue);
|
|
1470
|
+
if (expand) {
|
|
1471
|
+
outerNext(innerValue);
|
|
1472
|
+
}
|
|
1473
|
+
else {
|
|
1474
|
+
subscriber.next(innerValue);
|
|
1475
|
+
}
|
|
1476
|
+
}, function () {
|
|
1477
|
+
innerComplete = true;
|
|
1478
|
+
}, undefined, function () {
|
|
1479
|
+
if (innerComplete) {
|
|
1480
|
+
try {
|
|
1481
|
+
active--;
|
|
1482
|
+
var _loop_1 = function () {
|
|
1483
|
+
var bufferedValue = buffer.shift();
|
|
1484
|
+
if (innerSubScheduler) {
|
|
1485
|
+
executeSchedule(subscriber, innerSubScheduler, function () { return doInnerSub(bufferedValue); });
|
|
1486
|
+
}
|
|
1487
|
+
else {
|
|
1488
|
+
doInnerSub(bufferedValue);
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
while (buffer.length && active < concurrent) {
|
|
1492
|
+
_loop_1();
|
|
1493
|
+
}
|
|
1494
|
+
checkComplete();
|
|
1495
|
+
}
|
|
1496
|
+
catch (err) {
|
|
1497
|
+
subscriber.error(err);
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
}));
|
|
1501
|
+
};
|
|
1502
|
+
source.subscribe(createOperatorSubscriber(subscriber, outerNext, function () {
|
|
1503
|
+
isComplete = true;
|
|
1504
|
+
checkComplete();
|
|
1505
|
+
}));
|
|
1506
|
+
return function () {
|
|
1507
|
+
additionalFinalizer === null || additionalFinalizer === void 0 ? void 0 : additionalFinalizer();
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
function mergeMap(project, resultSelector, concurrent) {
|
|
1512
|
+
if (concurrent === void 0) { concurrent = Infinity; }
|
|
1513
|
+
if (isFunction(resultSelector)) {
|
|
1514
|
+
return mergeMap(function (a, i) { return map(function (b, ii) { return resultSelector(a, b, i, ii); })(innerFrom(project(a, i))); }, concurrent);
|
|
1515
|
+
}
|
|
1516
|
+
else if (typeof resultSelector === 'number') {
|
|
1517
|
+
concurrent = resultSelector;
|
|
1518
|
+
}
|
|
1519
|
+
return operate(function (source, subscriber) { return mergeInternals(source, subscriber, project, concurrent); });
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
function mergeAll(concurrent) {
|
|
1523
|
+
if (concurrent === void 0) { concurrent = Infinity; }
|
|
1524
|
+
return mergeMap(identity, concurrent);
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
function concatAll() {
|
|
1528
|
+
return mergeAll(1);
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
function debounceTime(dueTime, scheduler) {
|
|
1532
|
+
if (scheduler === void 0) { scheduler = asyncScheduler; }
|
|
1533
|
+
return operate(function (source, subscriber) {
|
|
1534
|
+
var activeTask = null;
|
|
1535
|
+
var lastValue = null;
|
|
1536
|
+
var lastTime = null;
|
|
1537
|
+
var emit = function () {
|
|
1538
|
+
if (activeTask) {
|
|
1539
|
+
activeTask.unsubscribe();
|
|
1540
|
+
activeTask = null;
|
|
1541
|
+
var value = lastValue;
|
|
1542
|
+
lastValue = null;
|
|
1543
|
+
subscriber.next(value);
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
function emitWhenIdle() {
|
|
1547
|
+
var targetTime = lastTime + dueTime;
|
|
1548
|
+
var now = scheduler.now();
|
|
1549
|
+
if (now < targetTime) {
|
|
1550
|
+
activeTask = this.schedule(undefined, targetTime - now);
|
|
1551
|
+
subscriber.add(activeTask);
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
emit();
|
|
1555
|
+
}
|
|
1556
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1557
|
+
lastValue = value;
|
|
1558
|
+
lastTime = scheduler.now();
|
|
1559
|
+
if (!activeTask) {
|
|
1560
|
+
activeTask = scheduler.schedule(emitWhenIdle, dueTime);
|
|
1561
|
+
subscriber.add(activeTask);
|
|
1562
|
+
}
|
|
1563
|
+
}, function () {
|
|
1564
|
+
emit();
|
|
1565
|
+
subscriber.complete();
|
|
1566
|
+
}, undefined, function () {
|
|
1567
|
+
lastValue = activeTask = null;
|
|
1568
|
+
}));
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
function concat$1() {
|
|
1573
|
+
var args = [];
|
|
1574
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1575
|
+
args[_i] = arguments[_i];
|
|
1576
|
+
}
|
|
1577
|
+
return concatAll()(from(args, popScheduler(args)));
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
var EMPTY = new Observable(function (subscriber) { return subscriber.complete(); });
|
|
1581
|
+
|
|
1582
|
+
function take(count) {
|
|
1583
|
+
return count <= 0
|
|
1584
|
+
?
|
|
1585
|
+
function () { return EMPTY; }
|
|
1586
|
+
: operate(function (source, subscriber) {
|
|
1587
|
+
var seen = 0;
|
|
1588
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1589
|
+
if (++seen <= count) {
|
|
1590
|
+
subscriber.next(value);
|
|
1591
|
+
if (count <= seen) {
|
|
1592
|
+
subscriber.complete();
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
}));
|
|
168
1596
|
});
|
|
169
|
-
|
|
170
|
-
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
function ignoreElements() {
|
|
1600
|
+
return operate(function (source, subscriber) {
|
|
1601
|
+
source.subscribe(createOperatorSubscriber(subscriber, noop));
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
function mapTo(value) {
|
|
1606
|
+
return map(function () { return value; });
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
function delayWhen(delayDurationSelector, subscriptionDelay) {
|
|
1610
|
+
if (subscriptionDelay) {
|
|
1611
|
+
return function (source) {
|
|
1612
|
+
return concat$1(subscriptionDelay.pipe(take(1), ignoreElements()), source.pipe(delayWhen(delayDurationSelector)));
|
|
1613
|
+
};
|
|
171
1614
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
1615
|
+
return mergeMap(function (value, index) { return delayDurationSelector(value, index).pipe(take(1), mapTo(value)); });
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
function delay(due, scheduler) {
|
|
1619
|
+
if (scheduler === void 0) { scheduler = asyncScheduler; }
|
|
1620
|
+
var duration = timer(due, scheduler);
|
|
1621
|
+
return delayWhen(function () { return duration; });
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
function distinctUntilChanged(comparator, keySelector) {
|
|
1625
|
+
if (keySelector === void 0) { keySelector = identity; }
|
|
1626
|
+
comparator = comparator !== null && comparator !== void 0 ? comparator : defaultCompare;
|
|
1627
|
+
return operate(function (source, subscriber) {
|
|
1628
|
+
var previousKey;
|
|
1629
|
+
var first = true;
|
|
1630
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1631
|
+
var currentKey = keySelector(value);
|
|
1632
|
+
if (first || !comparator(previousKey, currentKey)) {
|
|
1633
|
+
first = false;
|
|
1634
|
+
previousKey = currentKey;
|
|
1635
|
+
subscriber.next(value);
|
|
1636
|
+
}
|
|
1637
|
+
}));
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
function defaultCompare(a, b) {
|
|
1641
|
+
return a === b;
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
function filter(predicate, thisArg) {
|
|
1645
|
+
return operate(function (source, subscriber) {
|
|
1646
|
+
var index = 0;
|
|
1647
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return predicate.call(thisArg, value, index++) && subscriber.next(value); }));
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
function skip(count) {
|
|
1652
|
+
return filter(function (_, index) { return count <= index; });
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
function startWith() {
|
|
1656
|
+
var values = [];
|
|
1657
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1658
|
+
values[_i] = arguments[_i];
|
|
178
1659
|
}
|
|
1660
|
+
var scheduler = popScheduler(values);
|
|
1661
|
+
return operate(function (source, subscriber) {
|
|
1662
|
+
(scheduler ? concat$1(values, source, scheduler) : concat$1(values, source)).subscribe(subscriber);
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
function switchMap(project, resultSelector) {
|
|
1667
|
+
return operate(function (source, subscriber) {
|
|
1668
|
+
var innerSubscriber = null;
|
|
1669
|
+
var index = 0;
|
|
1670
|
+
var isComplete = false;
|
|
1671
|
+
var checkComplete = function () { return isComplete && !innerSubscriber && subscriber.complete(); };
|
|
1672
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1673
|
+
innerSubscriber === null || innerSubscriber === void 0 ? void 0 : innerSubscriber.unsubscribe();
|
|
1674
|
+
var innerIndex = 0;
|
|
1675
|
+
var outerIndex = index++;
|
|
1676
|
+
innerFrom(project(value, outerIndex)).subscribe((innerSubscriber = createOperatorSubscriber(subscriber, function (innerValue) { return subscriber.next(resultSelector ? resultSelector(value, innerValue, outerIndex, innerIndex++) : innerValue); }, function () {
|
|
1677
|
+
innerSubscriber = null;
|
|
1678
|
+
checkComplete();
|
|
1679
|
+
})));
|
|
1680
|
+
}, function () {
|
|
1681
|
+
isComplete = true;
|
|
1682
|
+
checkComplete();
|
|
1683
|
+
}));
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
function tap(observerOrNext, error, complete) {
|
|
1688
|
+
var tapObserver = isFunction(observerOrNext) || error || complete
|
|
1689
|
+
?
|
|
1690
|
+
{ next: observerOrNext, error: error, complete: complete }
|
|
1691
|
+
: observerOrNext;
|
|
1692
|
+
return tapObserver
|
|
1693
|
+
? operate(function (source, subscriber) {
|
|
1694
|
+
var _a;
|
|
1695
|
+
(_a = tapObserver.subscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1696
|
+
var isUnsub = true;
|
|
1697
|
+
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1698
|
+
var _a;
|
|
1699
|
+
(_a = tapObserver.next) === null || _a === void 0 ? void 0 : _a.call(tapObserver, value);
|
|
1700
|
+
subscriber.next(value);
|
|
1701
|
+
}, function () {
|
|
1702
|
+
var _a;
|
|
1703
|
+
isUnsub = false;
|
|
1704
|
+
(_a = tapObserver.complete) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1705
|
+
subscriber.complete();
|
|
1706
|
+
}, function (err) {
|
|
1707
|
+
var _a;
|
|
1708
|
+
isUnsub = false;
|
|
1709
|
+
(_a = tapObserver.error) === null || _a === void 0 ? void 0 : _a.call(tapObserver, err);
|
|
1710
|
+
subscriber.error(err);
|
|
1711
|
+
}, function () {
|
|
1712
|
+
var _a, _b;
|
|
1713
|
+
if (isUnsub) {
|
|
1714
|
+
(_a = tapObserver.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1715
|
+
}
|
|
1716
|
+
(_b = tapObserver.finalize) === null || _b === void 0 ? void 0 : _b.call(tapObserver);
|
|
1717
|
+
}));
|
|
1718
|
+
})
|
|
1719
|
+
:
|
|
1720
|
+
identity;
|
|
179
1721
|
}
|
|
180
1722
|
|
|
181
1723
|
//const hasSW = 'serviceWorker' in navigator;
|
|
@@ -238,6 +1780,7 @@ function registerPeriodicSyncEvent(db) {
|
|
|
238
1780
|
|
|
239
1781
|
function triggerSync(db, purpose) {
|
|
240
1782
|
if (db.cloud.usingServiceWorker) {
|
|
1783
|
+
console.debug('registering sync event');
|
|
241
1784
|
registerSyncEvent(db, purpose);
|
|
242
1785
|
}
|
|
243
1786
|
else {
|
|
@@ -266,7 +1809,14 @@ const b64encode = typeof Buffer !== "undefined"
|
|
|
266
1809
|
}
|
|
267
1810
|
}
|
|
268
1811
|
: (b) => {
|
|
269
|
-
|
|
1812
|
+
const u8a = ArrayBuffer.isView(b) ? b : new Uint8Array(b);
|
|
1813
|
+
const CHUNK_SIZE = 0x1000;
|
|
1814
|
+
const strs = [];
|
|
1815
|
+
for (let i = 0, l = u8a.length; i < l; i += CHUNK_SIZE) {
|
|
1816
|
+
const chunk = u8a.subarray(i, i + CHUNK_SIZE);
|
|
1817
|
+
strs.push(String.fromCharCode.apply(null, chunk));
|
|
1818
|
+
}
|
|
1819
|
+
return btoa(strs.join(""));
|
|
270
1820
|
};
|
|
271
1821
|
|
|
272
1822
|
function computeRealmSetHash({ realms, inviteRealms, }) {
|
|
@@ -739,14 +2289,24 @@ function getTablesToSyncify(db, syncState) {
|
|
|
739
2289
|
return tablesToSyncify;
|
|
740
2290
|
}
|
|
741
2291
|
|
|
2292
|
+
class TokenErrorResponseError extends Error {
|
|
2293
|
+
constructor({ title, message, messageCode, messageParams, }) {
|
|
2294
|
+
super(message);
|
|
2295
|
+
this.name = 'TokenErrorResponseError';
|
|
2296
|
+
this.title = title;
|
|
2297
|
+
this.messageCode = messageCode;
|
|
2298
|
+
this.messageParams = messageParams;
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
|
|
742
2302
|
function interactWithUser(userInteraction, req) {
|
|
743
2303
|
return new Promise((resolve, reject) => {
|
|
744
|
-
const interactionProps = Object.assign(Object.assign({}, req), { onSubmit: (res) => {
|
|
2304
|
+
const interactionProps = Object.assign(Object.assign({ submitLabel: 'Submit', cancelLabel: 'Cancel' }, req), { onSubmit: (res) => {
|
|
745
2305
|
userInteraction.next(undefined);
|
|
746
2306
|
resolve(res);
|
|
747
2307
|
}, onCancel: () => {
|
|
748
2308
|
userInteraction.next(undefined);
|
|
749
|
-
reject(new Dexie.AbortError(
|
|
2309
|
+
reject(new Dexie.AbortError('User cancelled'));
|
|
750
2310
|
} });
|
|
751
2311
|
userInteraction.next(interactionProps);
|
|
752
2312
|
// Start subscribing for external updates to db.cloud.userInteraction, and if so, cancel this request.
|
|
@@ -765,7 +2325,9 @@ function alertUser(userInteraction, title, ...alerts) {
|
|
|
765
2325
|
type: 'message-alert',
|
|
766
2326
|
title,
|
|
767
2327
|
alerts,
|
|
768
|
-
fields: {}
|
|
2328
|
+
fields: {},
|
|
2329
|
+
submitLabel: 'OK',
|
|
2330
|
+
cancelLabel: null,
|
|
769
2331
|
});
|
|
770
2332
|
}
|
|
771
2333
|
function promptForEmail(userInteraction, title, emailHint) {
|
|
@@ -824,22 +2386,48 @@ function promptForOTP(userInteraction, email, alert) {
|
|
|
824
2386
|
return otp;
|
|
825
2387
|
});
|
|
826
2388
|
}
|
|
2389
|
+
function confirmLogout(userInteraction, currentUserId, numUnsyncedChanges) {
|
|
2390
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2391
|
+
const alerts = [
|
|
2392
|
+
{
|
|
2393
|
+
type: 'warning',
|
|
2394
|
+
messageCode: 'LOGOUT_CONFIRMATION',
|
|
2395
|
+
message: `{numUnsyncedChanges} unsynced changes will get lost!
|
|
2396
|
+
Logout anyway?`,
|
|
2397
|
+
messageParams: {
|
|
2398
|
+
currentUserId,
|
|
2399
|
+
numUnsyncedChanges: numUnsyncedChanges.toString(),
|
|
2400
|
+
}
|
|
2401
|
+
},
|
|
2402
|
+
];
|
|
2403
|
+
return yield interactWithUser(userInteraction, {
|
|
2404
|
+
type: 'logout-confirmation',
|
|
2405
|
+
title: 'Confirm Logout',
|
|
2406
|
+
alerts,
|
|
2407
|
+
fields: {},
|
|
2408
|
+
submitLabel: 'Confirm logout',
|
|
2409
|
+
cancelLabel: 'Cancel'
|
|
2410
|
+
})
|
|
2411
|
+
.then(() => true)
|
|
2412
|
+
.catch(() => false);
|
|
2413
|
+
});
|
|
2414
|
+
}
|
|
827
2415
|
|
|
828
2416
|
function loadAccessToken(db) {
|
|
829
|
-
var _a, _b;
|
|
2417
|
+
var _a, _b, _c;
|
|
830
2418
|
return __awaiter(this, void 0, void 0, function* () {
|
|
831
2419
|
const currentUser = yield db.getCurrentUser();
|
|
832
2420
|
const { accessToken, accessTokenExpiration, refreshToken, refreshTokenExpiration, claims, } = currentUser;
|
|
833
2421
|
if (!accessToken)
|
|
834
|
-
return;
|
|
2422
|
+
return null;
|
|
835
2423
|
const expTime = (_a = accessTokenExpiration === null || accessTokenExpiration === void 0 ? void 0 : accessTokenExpiration.getTime()) !== null && _a !== void 0 ? _a : Infinity;
|
|
836
|
-
if (expTime > Date.now()) {
|
|
837
|
-
return
|
|
2424
|
+
if (expTime > Date.now() && (((_b = currentUser.license) === null || _b === void 0 ? void 0 : _b.status) || 'ok') === 'ok') {
|
|
2425
|
+
return currentUser;
|
|
838
2426
|
}
|
|
839
2427
|
if (!refreshToken) {
|
|
840
2428
|
throw new Error(`Refresh token missing`);
|
|
841
2429
|
}
|
|
842
|
-
const refreshExpTime = (
|
|
2430
|
+
const refreshExpTime = (_c = refreshTokenExpiration === null || refreshTokenExpiration === void 0 ? void 0 : refreshTokenExpiration.getTime()) !== null && _c !== void 0 ? _c : Infinity;
|
|
843
2431
|
if (refreshExpTime <= Date.now()) {
|
|
844
2432
|
throw new Error(`Refresh token has expired`);
|
|
845
2433
|
}
|
|
@@ -847,8 +2435,10 @@ function loadAccessToken(db) {
|
|
|
847
2435
|
yield db.table('$logins').update(claims.sub, {
|
|
848
2436
|
accessToken: refreshedLogin.accessToken,
|
|
849
2437
|
accessTokenExpiration: refreshedLogin.accessTokenExpiration,
|
|
2438
|
+
claims: refreshedLogin.claims,
|
|
2439
|
+
license: refreshedLogin.license,
|
|
850
2440
|
});
|
|
851
|
-
return refreshedLogin
|
|
2441
|
+
return refreshedLogin;
|
|
852
2442
|
});
|
|
853
2443
|
}
|
|
854
2444
|
function authenticate(url, context, fetchToken, userInteraction, hints) {
|
|
@@ -896,10 +2486,24 @@ function refreshAccessToken(url, login) {
|
|
|
896
2486
|
if (res.status !== 200)
|
|
897
2487
|
throw new Error(`RefreshToken: Status ${res.status} from ${url}/token`);
|
|
898
2488
|
const response = yield res.json();
|
|
2489
|
+
if (response.type === 'error') {
|
|
2490
|
+
throw new TokenErrorResponseError(response);
|
|
2491
|
+
}
|
|
899
2492
|
login.accessToken = response.accessToken;
|
|
900
2493
|
login.accessTokenExpiration = response.accessTokenExpiration
|
|
901
2494
|
? new Date(response.accessTokenExpiration)
|
|
902
2495
|
: undefined;
|
|
2496
|
+
login.claims = response.claims;
|
|
2497
|
+
login.license = {
|
|
2498
|
+
type: response.userType,
|
|
2499
|
+
status: response.claims.license || 'ok',
|
|
2500
|
+
};
|
|
2501
|
+
if (response.evalDaysLeft != null) {
|
|
2502
|
+
login.license.evalDaysLeft = response.evalDaysLeft;
|
|
2503
|
+
}
|
|
2504
|
+
if (response.userValidUntil != null) {
|
|
2505
|
+
login.license.validUntil = new Date(response.userValidUntil);
|
|
2506
|
+
}
|
|
903
2507
|
return login;
|
|
904
2508
|
});
|
|
905
2509
|
}
|
|
@@ -931,8 +2535,15 @@ function userAuthenticate(context, fetchToken, userInteraction, hints) {
|
|
|
931
2535
|
public_key: publicKeyPEM,
|
|
932
2536
|
hints,
|
|
933
2537
|
});
|
|
2538
|
+
if (response2.type === 'error') {
|
|
2539
|
+
throw new TokenErrorResponseError(response2);
|
|
2540
|
+
}
|
|
934
2541
|
if (response2.type !== 'tokens')
|
|
935
2542
|
throw new Error(`Unexpected response type from token endpoint: ${response2.type}`);
|
|
2543
|
+
/*const licenseStatus = response2.claims.license || 'ok';
|
|
2544
|
+
if (licenseStatus !== 'ok') {
|
|
2545
|
+
throw new InvalidLicenseError(licenseStatus);
|
|
2546
|
+
}*/
|
|
936
2547
|
context.accessToken = response2.accessToken;
|
|
937
2548
|
context.accessTokenExpiration = new Date(response2.accessTokenExpiration);
|
|
938
2549
|
context.refreshToken = response2.refreshToken;
|
|
@@ -943,6 +2554,16 @@ function userAuthenticate(context, fetchToken, userInteraction, hints) {
|
|
|
943
2554
|
context.email = response2.claims.email;
|
|
944
2555
|
context.name = response2.claims.name;
|
|
945
2556
|
context.claims = response2.claims;
|
|
2557
|
+
context.license = {
|
|
2558
|
+
type: response2.userType,
|
|
2559
|
+
status: response2.claims.license || 'ok',
|
|
2560
|
+
};
|
|
2561
|
+
if (response2.evalDaysLeft != null) {
|
|
2562
|
+
context.license.evalDaysLeft = response2.evalDaysLeft;
|
|
2563
|
+
}
|
|
2564
|
+
if (response2.userValidUntil != null) {
|
|
2565
|
+
context.license.validUntil = new Date(response2.userValidUntil);
|
|
2566
|
+
}
|
|
946
2567
|
if (response2.alerts && response2.alerts.length > 0) {
|
|
947
2568
|
yield interactWithUser(userInteraction, {
|
|
948
2569
|
type: 'message-alert',
|
|
@@ -954,12 +2575,36 @@ function userAuthenticate(context, fetchToken, userInteraction, hints) {
|
|
|
954
2575
|
return context;
|
|
955
2576
|
}
|
|
956
2577
|
catch (error) {
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
2578
|
+
if (error instanceof TokenErrorResponseError) {
|
|
2579
|
+
yield alertUser(userInteraction, error.title, {
|
|
2580
|
+
type: 'error',
|
|
2581
|
+
messageCode: error.messageCode,
|
|
2582
|
+
message: error.message,
|
|
2583
|
+
messageParams: {},
|
|
2584
|
+
});
|
|
2585
|
+
throw error;
|
|
2586
|
+
}
|
|
2587
|
+
let message = `We're having a problem authenticating right now.`;
|
|
2588
|
+
console.error(`Error authenticating`, error);
|
|
2589
|
+
if (error instanceof TypeError) {
|
|
2590
|
+
const isOffline = typeof navigator !== undefined && !navigator.onLine;
|
|
2591
|
+
if (isOffline) {
|
|
2592
|
+
message = `You seem to be offline. Please connect to the internet and try again.`;
|
|
2593
|
+
}
|
|
2594
|
+
else if (Dexie.debug || (typeof location !== 'undefined' && (location.hostname === 'localhost' || location.hostname === '127.0.0.1'))) {
|
|
2595
|
+
// The audience is most likely the developer. Suggest to whitelist the localhost origin:
|
|
2596
|
+
message = `Could not connect to server. Please verify that your origin '${location.origin}' is whitelisted using \`npx dexie-cloud whitelist\``;
|
|
2597
|
+
}
|
|
2598
|
+
else {
|
|
2599
|
+
message = `Could not connect to server. Please verify the connection.`;
|
|
2600
|
+
}
|
|
2601
|
+
yield alertUser(userInteraction, 'Authentication Failed', {
|
|
2602
|
+
type: 'error',
|
|
2603
|
+
messageCode: 'GENERIC_ERROR',
|
|
2604
|
+
message,
|
|
2605
|
+
messageParams: {},
|
|
2606
|
+
}).catch(() => { });
|
|
2607
|
+
}
|
|
963
2608
|
throw error;
|
|
964
2609
|
}
|
|
965
2610
|
});
|
|
@@ -1181,13 +2826,13 @@ var MapDef = {
|
|
|
1181
2826
|
},
|
|
1182
2827
|
};
|
|
1183
2828
|
|
|
1184
|
-
const _global = typeof globalThis !== "undefined"
|
|
2829
|
+
const _global = typeof globalThis !== "undefined" // All modern environments (node, bun, deno, browser, workers, webview etc)
|
|
1185
2830
|
? globalThis
|
|
1186
|
-
: typeof self !== "undefined"
|
|
2831
|
+
: typeof self !== "undefined" // Older browsers, workers, webview, window etc
|
|
1187
2832
|
? self
|
|
1188
|
-
: typeof global
|
|
2833
|
+
: typeof global !== "undefined" // Older versions of node
|
|
1189
2834
|
? global
|
|
1190
|
-
: undefined;
|
|
2835
|
+
: undefined; // Unsupported environment. No idea to return 'this' since we are in a module or a function scope anyway.
|
|
1191
2836
|
|
|
1192
2837
|
var TypedArraysDefs = [
|
|
1193
2838
|
"Int8Array",
|
|
@@ -1582,6 +3227,40 @@ function cloneChange(change, rewriteValues) {
|
|
|
1582
3227
|
: change.muts.map((m) => (Object.assign(Object.assign({}, m), { keys: m.keys.slice() }))) });
|
|
1583
3228
|
}
|
|
1584
3229
|
|
|
3230
|
+
// If we get Ratelimit-Limit and Ratelimit-Remaining where Ratelimit-Remaining is below
|
|
3231
|
+
// (Ratelimit-Limit / 2), we should delay the next sync by (Ratelimit-Reset / Ratelimit-Remaining)
|
|
3232
|
+
// seconds (given that there is a Ratelimit-Reset header).
|
|
3233
|
+
let syncRatelimitDelays = new WeakMap();
|
|
3234
|
+
function checkSyncRateLimitDelay(db) {
|
|
3235
|
+
var _a, _b;
|
|
3236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3237
|
+
const delatMilliseconds = ((_b = (_a = syncRatelimitDelays.get(db)) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : 0) - Date.now();
|
|
3238
|
+
if (delatMilliseconds > 0) {
|
|
3239
|
+
console.debug(`Stalling sync request ${delatMilliseconds} ms to spare ratelimits`);
|
|
3240
|
+
yield new Promise(resolve => setTimeout(resolve, delatMilliseconds));
|
|
3241
|
+
}
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
function updateSyncRateLimitDelays(db, res) {
|
|
3245
|
+
const limit = res.headers.get('Ratelimit-Limit');
|
|
3246
|
+
const remaining = res.headers.get('Ratelimit-Remaining');
|
|
3247
|
+
const reset = res.headers.get('Ratelimit-Reset');
|
|
3248
|
+
if (limit && remaining && reset) {
|
|
3249
|
+
const limitNum = Number(limit);
|
|
3250
|
+
const remainingNum = Math.max(0, Number(remaining));
|
|
3251
|
+
const willResetInSeconds = Number(reset);
|
|
3252
|
+
if (remainingNum < limitNum / 2) {
|
|
3253
|
+
const delay = Math.ceil(willResetInSeconds / (remainingNum + 1));
|
|
3254
|
+
syncRatelimitDelays.set(db, new Date(Date.now() + delay * 1000));
|
|
3255
|
+
console.debug(`Sync ratelimit delay set to ${delay} seconds`);
|
|
3256
|
+
}
|
|
3257
|
+
else {
|
|
3258
|
+
syncRatelimitDelays.delete(db);
|
|
3259
|
+
console.debug(`Sync ratelimit delay cleared`);
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
|
|
1585
3264
|
//import {BisonWebStreamReader} from "dreambase-library/dist/typeson-simplified/BisonWebStreamReader";
|
|
1586
3265
|
function syncWithServer(changes, syncState, baseRevs, db, databaseUrl, schema, clientIdentity, currentUser) {
|
|
1587
3266
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1590,9 +3269,20 @@ function syncWithServer(changes, syncState, baseRevs, db, databaseUrl, schema, c
|
|
|
1590
3269
|
//
|
|
1591
3270
|
const headers = {
|
|
1592
3271
|
Accept: 'application/json, application/x-bison, application/x-bison-stream',
|
|
1593
|
-
'Content-Type': 'application/tson'
|
|
3272
|
+
'Content-Type': 'application/tson',
|
|
1594
3273
|
};
|
|
1595
|
-
const
|
|
3274
|
+
const updatedUser = yield loadAccessToken(db);
|
|
3275
|
+
/*
|
|
3276
|
+
if (updatedUser?.license && changes.length > 0) {
|
|
3277
|
+
if (updatedUser.license.status === 'expired') {
|
|
3278
|
+
throw new Error(`License has expired`);
|
|
3279
|
+
}
|
|
3280
|
+
if (updatedUser.license.status === 'deactivated') {
|
|
3281
|
+
throw new Error(`License deactivated`);
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
*/
|
|
3285
|
+
const accessToken = updatedUser === null || updatedUser === void 0 ? void 0 : updatedUser.accessToken;
|
|
1596
3286
|
if (accessToken) {
|
|
1597
3287
|
headers.Authorization = `Bearer ${accessToken}`;
|
|
1598
3288
|
}
|
|
@@ -1601,27 +3291,31 @@ function syncWithServer(changes, syncState, baseRevs, db, databaseUrl, schema, c
|
|
|
1601
3291
|
dbID: syncState === null || syncState === void 0 ? void 0 : syncState.remoteDbId,
|
|
1602
3292
|
clientIdentity,
|
|
1603
3293
|
schema: schema || {},
|
|
1604
|
-
lastPull: syncState
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
3294
|
+
lastPull: syncState
|
|
3295
|
+
? {
|
|
3296
|
+
serverRevision: syncState.serverRevision,
|
|
3297
|
+
realms: syncState.realms,
|
|
3298
|
+
inviteRealms: syncState.inviteRealms,
|
|
3299
|
+
}
|
|
3300
|
+
: undefined,
|
|
1609
3301
|
baseRevs,
|
|
1610
|
-
changes: encodeIdsForServer(db.dx.core.schema, currentUser, changes)
|
|
3302
|
+
changes: encodeIdsForServer(db.dx.core.schema, currentUser, changes),
|
|
1611
3303
|
};
|
|
1612
|
-
console.debug(
|
|
3304
|
+
console.debug('Sync request', syncRequest);
|
|
1613
3305
|
db.syncStateChangedEvent.next({
|
|
1614
3306
|
phase: 'pushing',
|
|
1615
3307
|
});
|
|
1616
3308
|
const res = yield fetch(`${databaseUrl}/sync`, {
|
|
1617
3309
|
method: 'post',
|
|
1618
3310
|
headers,
|
|
1619
|
-
|
|
3311
|
+
credentials: 'include',
|
|
3312
|
+
body: TSON.stringify(syncRequest),
|
|
1620
3313
|
});
|
|
1621
3314
|
//const contentLength = Number(res.headers.get('content-length'));
|
|
1622
3315
|
db.syncStateChangedEvent.next({
|
|
1623
|
-
phase: 'pulling'
|
|
3316
|
+
phase: 'pulling',
|
|
1624
3317
|
});
|
|
3318
|
+
updateSyncRateLimitDelays(db, res);
|
|
1625
3319
|
if (!res.ok) {
|
|
1626
3320
|
throw new HttpError(res);
|
|
1627
3321
|
}
|
|
@@ -1823,12 +3517,13 @@ const CURRENT_SYNC_WORKER = 'currentSyncWorker';
|
|
|
1823
3517
|
function sync(db, options, schema, syncOptions) {
|
|
1824
3518
|
return _sync
|
|
1825
3519
|
.apply(this, arguments)
|
|
1826
|
-
.then(() => {
|
|
3520
|
+
.then((result) => {
|
|
1827
3521
|
if (!(syncOptions === null || syncOptions === void 0 ? void 0 : syncOptions.justCheckIfNeeded)) { // && syncOptions?.purpose !== 'push') {
|
|
1828
3522
|
db.syncStateChangedEvent.next({
|
|
1829
3523
|
phase: 'in-sync',
|
|
1830
3524
|
});
|
|
1831
3525
|
}
|
|
3526
|
+
return result;
|
|
1832
3527
|
})
|
|
1833
3528
|
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
1834
3529
|
if (syncOptions === null || syncOptions === void 0 ? void 0 : syncOptions.justCheckIfNeeded)
|
|
@@ -2043,6 +3738,7 @@ function _sync(db, options, schema, { isInitialSync, cancelToken, justCheckIfNee
|
|
|
2043
3738
|
}));
|
|
2044
3739
|
if (!done) {
|
|
2045
3740
|
console.debug('MORE SYNC NEEDED. Go for it again!');
|
|
3741
|
+
yield checkSyncRateLimitDelay(db);
|
|
2046
3742
|
return yield _sync(db, options, schema, { isInitialSync, cancelToken });
|
|
2047
3743
|
}
|
|
2048
3744
|
console.debug('SYNC DONE', { isInitialSync });
|
|
@@ -2179,6 +3875,8 @@ function MessagesFromServerConsumer(db) {
|
|
|
2179
3875
|
yield db.table('$logins').update(user.userId, {
|
|
2180
3876
|
accessToken: refreshedLogin.accessToken,
|
|
2181
3877
|
accessTokenExpiration: refreshedLogin.accessTokenExpiration,
|
|
3878
|
+
claims: refreshedLogin.claims,
|
|
3879
|
+
license: refreshedLogin.license,
|
|
2182
3880
|
});
|
|
2183
3881
|
// Updating $logins will trigger emission of db.cloud.currentUser observable, which
|
|
2184
3882
|
// in turn will lead to that connectWebSocket.ts will reconnect the socket with the
|
|
@@ -2449,6 +4147,61 @@ class AuthPersistedContext {
|
|
|
2449
4147
|
}
|
|
2450
4148
|
}
|
|
2451
4149
|
|
|
4150
|
+
function waitUntil(o, // Works with Dexie's liveQuery observables if we'd need that
|
|
4151
|
+
predicate) {
|
|
4152
|
+
return firstValueFrom(from$1(o).pipe(filter$1(predicate)));
|
|
4153
|
+
}
|
|
4154
|
+
|
|
4155
|
+
function logout(db) {
|
|
4156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4157
|
+
const numUnsyncedChanges = yield _logout(db);
|
|
4158
|
+
if (numUnsyncedChanges) {
|
|
4159
|
+
if (yield confirmLogout(db.cloud.userInteraction, db.cloud.currentUserId, numUnsyncedChanges)) {
|
|
4160
|
+
yield _logout(db, { deleteUnsyncedData: true });
|
|
4161
|
+
}
|
|
4162
|
+
else {
|
|
4163
|
+
throw new Error(`User cancelled logout due to unsynced changes`);
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
4166
|
+
});
|
|
4167
|
+
}
|
|
4168
|
+
function _logout(db, { deleteUnsyncedData = false } = {}) {
|
|
4169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4170
|
+
// Clear the database without emptying configuration options.
|
|
4171
|
+
const [numUnsynced, loggedOut] = yield db.dx.transaction('rw', db.dx.tables, (tx) => __awaiter(this, void 0, void 0, function* () {
|
|
4172
|
+
// @ts-ignore
|
|
4173
|
+
const idbtrans = tx.idbtrans;
|
|
4174
|
+
idbtrans.disableChangeTracking = true;
|
|
4175
|
+
idbtrans.disableAccessControl = true;
|
|
4176
|
+
const mutationTables = tx.storeNames.filter((tableName) => tableName.endsWith('_mutations'));
|
|
4177
|
+
// Count unsynced changes
|
|
4178
|
+
const unsyncCounts = yield Promise.all(mutationTables.map((mutationTable) => tx.table(mutationTable).count()));
|
|
4179
|
+
const sumUnSynced = unsyncCounts.reduce((a, b) => a + b, 0);
|
|
4180
|
+
if (sumUnSynced > 0 && !deleteUnsyncedData) {
|
|
4181
|
+
// Let caller ask user if they want to delete unsynced data.
|
|
4182
|
+
return [sumUnSynced, false];
|
|
4183
|
+
}
|
|
4184
|
+
// Either there are no unsynched changes, or caller provided flag deleteUnsynchedData = true.
|
|
4185
|
+
// Clear all tables except $jobs and $syncState (except the persisted sync state which is
|
|
4186
|
+
// also cleared because we're going to rebuild it using a fresh sync).
|
|
4187
|
+
db.$syncState.delete('syncState');
|
|
4188
|
+
for (const table of db.dx.tables) {
|
|
4189
|
+
if (table.name !== '$jobs' && table.name !== '$syncState') {
|
|
4190
|
+
table.clear();
|
|
4191
|
+
}
|
|
4192
|
+
}
|
|
4193
|
+
return [sumUnSynced, true];
|
|
4194
|
+
}));
|
|
4195
|
+
if (loggedOut) {
|
|
4196
|
+
// Wait for currentUser observable to emit UNAUTHORIZED_USER
|
|
4197
|
+
yield waitUntil(db.cloud.currentUser, (user) => user.userId === UNAUTHORIZED_USER.userId);
|
|
4198
|
+
// Then perform an initial sync
|
|
4199
|
+
yield db.cloud.sync({ purpose: 'pull', wait: true });
|
|
4200
|
+
}
|
|
4201
|
+
return numUnsynced;
|
|
4202
|
+
});
|
|
4203
|
+
}
|
|
4204
|
+
|
|
2452
4205
|
function otpFetchTokenCallback(db) {
|
|
2453
4206
|
const { userInteraction } = db.cloud;
|
|
2454
4207
|
return function otpAuthenticate({ public_key, hints }) {
|
|
@@ -2492,8 +4245,9 @@ function otpFetchTokenCallback(db) {
|
|
|
2492
4245
|
throw new HttpError(res1, errMsg);
|
|
2493
4246
|
}
|
|
2494
4247
|
const response = yield res1.json();
|
|
2495
|
-
if (response.type === 'tokens') {
|
|
4248
|
+
if (response.type === 'tokens' || response.type === 'error') {
|
|
2496
4249
|
// Demo user request can get a "tokens" response right away
|
|
4250
|
+
// Error can also be returned right away.
|
|
2497
4251
|
return response;
|
|
2498
4252
|
}
|
|
2499
4253
|
else if (tokenRequest.grant_type === 'otp') {
|
|
@@ -2525,12 +4279,6 @@ function otpFetchTokenCallback(db) {
|
|
|
2525
4279
|
}
|
|
2526
4280
|
if (res2.status !== 200) {
|
|
2527
4281
|
const errMsg = yield res2.text();
|
|
2528
|
-
yield alertUser(userInteraction, "OTP Authentication Failed", {
|
|
2529
|
-
type: 'error',
|
|
2530
|
-
messageCode: 'GENERIC_ERROR',
|
|
2531
|
-
message: errMsg,
|
|
2532
|
-
messageParams: {}
|
|
2533
|
-
}).catch(() => { });
|
|
2534
4282
|
throw new HttpError(res2, errMsg);
|
|
2535
4283
|
}
|
|
2536
4284
|
const response2 = yield res2.json();
|
|
@@ -2543,6 +4291,18 @@ function otpFetchTokenCallback(db) {
|
|
|
2543
4291
|
};
|
|
2544
4292
|
}
|
|
2545
4293
|
|
|
4294
|
+
/** A way to log to console in production without terser stripping out
|
|
4295
|
+
* it from the release bundle.
|
|
4296
|
+
* This should be used very rarely and only in places where it's
|
|
4297
|
+
* absolutely necessary to log something in production.
|
|
4298
|
+
*
|
|
4299
|
+
* @param level
|
|
4300
|
+
* @param args
|
|
4301
|
+
*/
|
|
4302
|
+
function prodLog(level, ...args) {
|
|
4303
|
+
globalThis["con" + "sole"][level](...args);
|
|
4304
|
+
}
|
|
4305
|
+
|
|
2546
4306
|
/** This function changes or sets the current user as requested.
|
|
2547
4307
|
*
|
|
2548
4308
|
* Use cases:
|
|
@@ -2569,85 +4329,73 @@ function setCurrentUser(db, user) {
|
|
|
2569
4329
|
}));
|
|
2570
4330
|
user.isLoggedIn = true;
|
|
2571
4331
|
user.lastLogin = new Date();
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
}));
|
|
2575
|
-
yield new Promise((resolve) => {
|
|
2576
|
-
if (db.cloud.currentUserId === user.userId) {
|
|
2577
|
-
resolve(null);
|
|
4332
|
+
try {
|
|
4333
|
+
yield user.save();
|
|
2578
4334
|
}
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
if (
|
|
2582
|
-
|
|
2583
|
-
|
|
4335
|
+
catch (e) {
|
|
4336
|
+
try {
|
|
4337
|
+
if (e.name === 'DataCloneError') {
|
|
4338
|
+
// We've seen this buggy behavior in some browsers and in case it happens
|
|
4339
|
+
// again we really need to collect the details to understand what's going on.
|
|
4340
|
+
prodLog('debug', `Login context property names:`, Object.keys(user));
|
|
4341
|
+
prodLog('debug', `Login context property names:`, Object.keys(user));
|
|
4342
|
+
prodLog('debug', `Login context:`, user);
|
|
4343
|
+
prodLog('debug', `Login context JSON:`, JSON.stringify(user));
|
|
2584
4344
|
}
|
|
2585
|
-
}
|
|
4345
|
+
}
|
|
4346
|
+
catch (_a) { }
|
|
4347
|
+
throw e;
|
|
2586
4348
|
}
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
// V: Samma med andra windows.
|
|
2591
|
-
// V: Så kanske göra om den till att häröra från liveQuery som läser $logins.orderBy('lastLogin').last().
|
|
2592
|
-
// V: Då bara vara medveten om:
|
|
2593
|
-
// V: En sån observable börjar hämta data vid första subscribe
|
|
2594
|
-
// V: Vi har inget "inital value" men kan emulera det till att vara ANONYMOUS_USER
|
|
2595
|
-
// V: Om requireAuth är true, så borde db.on(ready) hålla databasen stängd för alla utom denna observable.
|
|
2596
|
-
// V: Om inte så behöver den inte blocka.
|
|
2597
|
-
// Andra tankar:
|
|
2598
|
-
// * Man kan inte byta användare när man är offline. Skulle gå att flytta realms till undanstuff-tabell vid user-change.
|
|
2599
|
-
// men troligen inte värt det.
|
|
2600
|
-
// * Istället: sälj inte inte switch-user funktionalitet utan tala enbart om inloggat vs icke inloggat läge.
|
|
2601
|
-
// * populate $logins med ANONYMOUS så att en påbörjad inloggning inte räknas, alternativt ha en boolean prop!
|
|
2602
|
-
// Kanske bäst ha en boolean prop!
|
|
2603
|
-
// * Alternativ switch-user funktionalitet:
|
|
2604
|
-
// * DBCore gömmer data från realms man inte har tillgång till.
|
|
2605
|
-
// * Cursor impl behövs också då.
|
|
2606
|
-
// * Då blir det snabba user switch.
|
|
2607
|
-
// * claims-settet som skickas till servern blir summan av alla claims. Då måste servern stödja multipla tokens eller
|
|
2608
|
-
// att ens token är ett samlad.
|
|
4349
|
+
console.debug('Saved new user', user.email);
|
|
4350
|
+
}));
|
|
4351
|
+
yield waitUntil(db.cloud.currentUser, (currentUser) => currentUser.userId === user.userId);
|
|
2609
4352
|
});
|
|
2610
4353
|
}
|
|
2611
4354
|
|
|
2612
4355
|
function login(db, hints) {
|
|
4356
|
+
var _a;
|
|
2613
4357
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2614
4358
|
const currentUser = yield db.getCurrentUser();
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
throw new Error(`Must logout before changing user`);
|
|
2622
|
-
}
|
|
4359
|
+
const origUserId = currentUser.userId;
|
|
4360
|
+
if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
|
|
4361
|
+
const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
|
|
4362
|
+
if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
|
|
4363
|
+
// Already authenticated according to given hints. And license is valid.
|
|
4364
|
+
return false;
|
|
2623
4365
|
}
|
|
2624
|
-
|
|
2625
|
-
|
|
4366
|
+
if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
|
|
4367
|
+
// Refresh the token
|
|
4368
|
+
yield loadAccessToken(db);
|
|
4369
|
+
return false;
|
|
4370
|
+
}
|
|
4371
|
+
// No refresh token - must re-authenticate:
|
|
2626
4372
|
}
|
|
2627
4373
|
const context = new AuthPersistedContext(db, {
|
|
2628
4374
|
claims: {},
|
|
2629
4375
|
lastLogin: new Date(0),
|
|
2630
4376
|
});
|
|
2631
4377
|
yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
|
|
2632
|
-
|
|
2633
|
-
|
|
4378
|
+
if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
|
|
4379
|
+
// User was logged in before, but now logged in as another user.
|
|
4380
|
+
yield logout(db);
|
|
2634
4381
|
}
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
4382
|
+
/*try {
|
|
4383
|
+
await context.save();
|
|
4384
|
+
} catch (e) {
|
|
4385
|
+
try {
|
|
4386
|
+
if (e.name === 'DataCloneError') {
|
|
4387
|
+
console.debug(`Login context property names:`, Object.keys(context));
|
|
4388
|
+
console.debug(`Login context:`, context);
|
|
4389
|
+
console.debug(`Login context JSON:`, JSON.stringify(context));
|
|
2642
4390
|
}
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
}
|
|
4391
|
+
} catch {}
|
|
4392
|
+
throw e;
|
|
4393
|
+
}*/
|
|
2646
4394
|
yield setCurrentUser(db, context);
|
|
2647
4395
|
// Make sure to resync as the new login will be authorized
|
|
2648
4396
|
// for new realms.
|
|
2649
4397
|
triggerSync(db, "pull");
|
|
2650
|
-
return
|
|
4398
|
+
return context.userId !== origUserId;
|
|
2651
4399
|
});
|
|
2652
4400
|
}
|
|
2653
4401
|
|
|
@@ -2976,6 +4724,13 @@ function writeLock(fn, prop) {
|
|
|
2976
4724
|
|
|
2977
4725
|
const outstandingTransactions = new BehaviorSubject(new Set());
|
|
2978
4726
|
|
|
4727
|
+
function isEagerSyncDisabled(db) {
|
|
4728
|
+
var _a, _b, _c, _d;
|
|
4729
|
+
return (((_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.disableEagerSync) ||
|
|
4730
|
+
((_c = (_b = db.cloud.currentUser.value) === null || _b === void 0 ? void 0 : _b.license) === null || _c === void 0 ? void 0 : _c.status) !== 'ok' ||
|
|
4731
|
+
!((_d = db.cloud.options) === null || _d === void 0 ? void 0 : _d.databaseUrl));
|
|
4732
|
+
}
|
|
4733
|
+
|
|
2979
4734
|
/** Tracks all mutations in the same transaction as the mutations -
|
|
2980
4735
|
* so it is guaranteed that no mutation goes untracked - and if transaction
|
|
2981
4736
|
* aborts, the mutations won't be tracked.
|
|
@@ -2984,7 +4739,7 @@ const outstandingTransactions = new BehaviorSubject(new Set());
|
|
|
2984
4739
|
* changes to server and cleanup the tracked mutations once the server has
|
|
2985
4740
|
* ackowledged that it got them.
|
|
2986
4741
|
*/
|
|
2987
|
-
function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
4742
|
+
function createMutationTrackingMiddleware({ currentUserObservable, db, }) {
|
|
2988
4743
|
return {
|
|
2989
4744
|
stack: 'dbcore',
|
|
2990
4745
|
name: 'MutationTrackingMiddleware',
|
|
@@ -2995,7 +4750,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
|
2995
4750
|
try {
|
|
2996
4751
|
mutTableMap = new Map(ordinaryTables.map((tbl) => [
|
|
2997
4752
|
tbl.name,
|
|
2998
|
-
core.table(`$${tbl.name}_mutations`)
|
|
4753
|
+
core.table(`$${tbl.name}_mutations`),
|
|
2999
4754
|
]));
|
|
3000
4755
|
}
|
|
3001
4756
|
catch (_a) {
|
|
@@ -3029,15 +4784,9 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
|
3029
4784
|
outstandingTransactions.next(outstandingTransactions.value);
|
|
3030
4785
|
};
|
|
3031
4786
|
const txComplete = () => {
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
console.debug('registering sync event');
|
|
3036
|
-
registerSyncEvent(db, "push");
|
|
3037
|
-
}
|
|
3038
|
-
else {
|
|
3039
|
-
db.localSyncEvent.next({ purpose: "push" });
|
|
3040
|
-
}
|
|
4787
|
+
if (tx.mutationsAdded &&
|
|
4788
|
+
!isEagerSyncDisabled(db)) {
|
|
4789
|
+
triggerSync(db, 'push');
|
|
3041
4790
|
}
|
|
3042
4791
|
removeTransaction();
|
|
3043
4792
|
};
|
|
@@ -3104,7 +4853,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
|
3104
4853
|
.query({
|
|
3105
4854
|
query: { range: req.range, index: schema.primaryKey },
|
|
3106
4855
|
trans: req.trans,
|
|
3107
|
-
values: false
|
|
4856
|
+
values: false,
|
|
3108
4857
|
})
|
|
3109
4858
|
// Do a delete request instead, but keep the criteria info for the server to execute
|
|
3110
4859
|
.then((res) => {
|
|
@@ -3112,7 +4861,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
|
3112
4861
|
type: 'delete',
|
|
3113
4862
|
keys: res.result,
|
|
3114
4863
|
trans: req.trans,
|
|
3115
|
-
criteria: { index: null, range: req.range }
|
|
4864
|
+
criteria: { index: null, range: req.range },
|
|
3116
4865
|
});
|
|
3117
4866
|
})
|
|
3118
4867
|
: mutateAndLog(req);
|
|
@@ -3120,7 +4869,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
|
3120
4869
|
function mutateAndLog(req) {
|
|
3121
4870
|
const trans = req.trans;
|
|
3122
4871
|
trans.mutationsAdded = true;
|
|
3123
|
-
const { txid, currentUser: { userId } } = trans;
|
|
4872
|
+
const { txid, currentUser: { userId }, } = trans;
|
|
3124
4873
|
const { type } = req;
|
|
3125
4874
|
const opNo = ++trans.opCount;
|
|
3126
4875
|
return table.mutate(req).then((res) => {
|
|
@@ -3141,7 +4890,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
|
3141
4890
|
keys,
|
|
3142
4891
|
criteria: req.criteria,
|
|
3143
4892
|
txid,
|
|
3144
|
-
userId
|
|
4893
|
+
userId,
|
|
3145
4894
|
}
|
|
3146
4895
|
: req.type === 'add'
|
|
3147
4896
|
? {
|
|
@@ -3151,7 +4900,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
|
3151
4900
|
keys,
|
|
3152
4901
|
txid,
|
|
3153
4902
|
userId,
|
|
3154
|
-
values
|
|
4903
|
+
values,
|
|
3155
4904
|
}
|
|
3156
4905
|
: req.criteria && req.changeSpec
|
|
3157
4906
|
? {
|
|
@@ -3163,7 +4912,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
|
3163
4912
|
criteria: req.criteria,
|
|
3164
4913
|
changeSpec: req.changeSpec,
|
|
3165
4914
|
txid,
|
|
3166
|
-
userId
|
|
4915
|
+
userId,
|
|
3167
4916
|
}
|
|
3168
4917
|
: updates
|
|
3169
4918
|
? {
|
|
@@ -3174,7 +4923,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
|
3174
4923
|
keys: updates.keys,
|
|
3175
4924
|
changeSpecs: updates.changeSpecs,
|
|
3176
4925
|
txid,
|
|
3177
|
-
userId
|
|
4926
|
+
userId,
|
|
3178
4927
|
}
|
|
3179
4928
|
: {
|
|
3180
4929
|
type: 'upsert',
|
|
@@ -3183,7 +4932,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
|
3183
4932
|
keys,
|
|
3184
4933
|
values,
|
|
3185
4934
|
txid,
|
|
3186
|
-
userId
|
|
4935
|
+
userId,
|
|
3187
4936
|
};
|
|
3188
4937
|
return keys.length > 0 || ('criteria' in req && req.criteria)
|
|
3189
4938
|
? mutsTable
|
|
@@ -3193,7 +4942,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
|
|
|
3193
4942
|
});
|
|
3194
4943
|
}
|
|
3195
4944
|
} });
|
|
3196
|
-
}
|
|
4945
|
+
},
|
|
3197
4946
|
};
|
|
3198
4947
|
}
|
|
3199
4948
|
|
|
@@ -3347,13 +5096,13 @@ class TokenExpiredError extends Error {
|
|
|
3347
5096
|
const SERVER_PING_TIMEOUT = 20000;
|
|
3348
5097
|
const CLIENT_PING_INTERVAL = 30000;
|
|
3349
5098
|
const FAIL_RETRY_WAIT_TIME = 60000;
|
|
3350
|
-
class WSObservable extends Observable {
|
|
5099
|
+
class WSObservable extends Observable$1 {
|
|
3351
5100
|
constructor(databaseUrl, rev, realmSetHash, clientIdentity, messageProducer, webSocketStatus, token, tokenExpiration) {
|
|
3352
5101
|
super((subscriber) => new WSConnection(databaseUrl, rev, realmSetHash, clientIdentity, token, tokenExpiration, subscriber, messageProducer, webSocketStatus));
|
|
3353
5102
|
}
|
|
3354
5103
|
}
|
|
3355
5104
|
let counter = 0;
|
|
3356
|
-
class WSConnection extends Subscription {
|
|
5105
|
+
class WSConnection extends Subscription$1 {
|
|
3357
5106
|
constructor(databaseUrl, rev, realmSetHash, clientIdentity, token, tokenExpiration, subscriber, messageProducer, webSocketStatus) {
|
|
3358
5107
|
super(() => this.teardown());
|
|
3359
5108
|
this.id = ++counter;
|
|
@@ -3552,6 +5301,20 @@ class WSConnection extends Subscription {
|
|
|
3552
5301
|
}
|
|
3553
5302
|
}
|
|
3554
5303
|
|
|
5304
|
+
class InvalidLicenseError extends Error {
|
|
5305
|
+
constructor(license) {
|
|
5306
|
+
super(license === 'expired'
|
|
5307
|
+
? `License expired`
|
|
5308
|
+
: license === 'deactivated'
|
|
5309
|
+
? `User deactivated`
|
|
5310
|
+
: 'Invalid license');
|
|
5311
|
+
this.name = 'InvalidLicenseError';
|
|
5312
|
+
if (license) {
|
|
5313
|
+
this.license = license;
|
|
5314
|
+
}
|
|
5315
|
+
}
|
|
5316
|
+
}
|
|
5317
|
+
|
|
3555
5318
|
function sleep$1(ms) {
|
|
3556
5319
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3557
5320
|
}
|
|
@@ -3585,7 +5348,12 @@ function connectWebSocket(db) {
|
|
|
3585
5348
|
function createObservable() {
|
|
3586
5349
|
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.
|
|
3587
5350
|
take(1), // Don't continue waking up whenever syncState change
|
|
3588
|
-
switchMap((syncState) => db.cloud.currentUser.pipe(map((userLogin) => [userLogin, syncState]))), switchMap(([userLogin, syncState]) =>
|
|
5351
|
+
switchMap((syncState) => db.cloud.currentUser.pipe(map((userLogin) => [userLogin, syncState]))), switchMap(([userLogin, syncState]) => {
|
|
5352
|
+
/*if (userLogin.license?.status && userLogin.license.status !== 'ok') {
|
|
5353
|
+
throw new InvalidLicenseError();
|
|
5354
|
+
}*/
|
|
5355
|
+
return userIsReallyActive.pipe(map((isActive) => [isActive ? userLogin : null, syncState]));
|
|
5356
|
+
}), switchMap(([userLogin, syncState]) => {
|
|
3589
5357
|
if ((userLogin === null || userLogin === void 0 ? void 0 : userLogin.isLoggedIn) && !(syncState === null || syncState === void 0 ? void 0 : syncState.realms.includes(userLogin.userId))) {
|
|
3590
5358
|
// We're in an in-between state when user is logged in but the user's realms are not yet synced.
|
|
3591
5359
|
// Don't make this change reconnect the websocket just yet. Wait till syncState is updated
|
|
@@ -3601,7 +5369,7 @@ function connectWebSocket(db) {
|
|
|
3601
5369
|
return new WSObservable(db.cloud.options.databaseUrl, db.cloud.persistedSyncState.value.serverRevision, realmSetHash, db.cloud.persistedSyncState.value.clientIdentity, messageProducer, db.cloud.webSocketStatus, userLogin.accessToken, userLogin.accessTokenExpiration);
|
|
3602
5370
|
}
|
|
3603
5371
|
else {
|
|
3604
|
-
return from([]);
|
|
5372
|
+
return from$1([]);
|
|
3605
5373
|
}
|
|
3606
5374
|
}), catchError((error) => {
|
|
3607
5375
|
if ((error === null || error === void 0 ? void 0 : error.name) === 'TokenExpiredError') {
|
|
@@ -3614,15 +5382,21 @@ function connectWebSocket(db) {
|
|
|
3614
5382
|
yield db.table('$logins').update(user.userId, {
|
|
3615
5383
|
accessToken: refreshedLogin.accessToken,
|
|
3616
5384
|
accessTokenExpiration: refreshedLogin.accessTokenExpiration,
|
|
5385
|
+
claims: refreshedLogin.claims,
|
|
5386
|
+
license: refreshedLogin.license,
|
|
3617
5387
|
});
|
|
3618
5388
|
})), switchMap(() => createObservable()));
|
|
3619
5389
|
}
|
|
3620
5390
|
else {
|
|
3621
|
-
return throwError(error);
|
|
5391
|
+
return throwError(() => error);
|
|
3622
5392
|
}
|
|
3623
5393
|
}), catchError((error) => {
|
|
3624
5394
|
db.cloud.webSocketStatus.next("error");
|
|
3625
|
-
|
|
5395
|
+
if (error instanceof InvalidLicenseError) {
|
|
5396
|
+
// Don't retry. Just throw and don't try connect again.
|
|
5397
|
+
return throwError(() => error);
|
|
5398
|
+
}
|
|
5399
|
+
return from$1(waitAndReconnectWhenUserDoesSomething(error)).pipe(switchMap(() => createObservable()));
|
|
3626
5400
|
}));
|
|
3627
5401
|
}
|
|
3628
5402
|
return createObservable().subscribe({
|
|
@@ -3650,97 +5424,12 @@ function isSyncNeeded(db) {
|
|
|
3650
5424
|
});
|
|
3651
5425
|
}
|
|
3652
5426
|
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
const GUARDED_JOB_TIMEOUT = 1 * MINUTES;
|
|
3660
|
-
function performGuardedJob(db, jobName, jobsTableName, job, { awaitRemoteJob } = {}) {
|
|
3661
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3662
|
-
// Start working.
|
|
3663
|
-
//
|
|
3664
|
-
// Check if someone else is working on this already.
|
|
3665
|
-
//
|
|
3666
|
-
const jobsTable = db.table(jobsTableName);
|
|
3667
|
-
function aquireLock() {
|
|
3668
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3669
|
-
const gotTheLock = yield db.transaction('rw!', jobsTableName, () => __awaiter(this, void 0, void 0, function* () {
|
|
3670
|
-
const currentWork = yield jobsTable.get(jobName);
|
|
3671
|
-
if (!currentWork) {
|
|
3672
|
-
// No one else is working. Let's record that we are.
|
|
3673
|
-
yield jobsTable.add({
|
|
3674
|
-
nodeId: myId,
|
|
3675
|
-
started: new Date(),
|
|
3676
|
-
heartbeat: new Date()
|
|
3677
|
-
}, jobName);
|
|
3678
|
-
return true;
|
|
3679
|
-
}
|
|
3680
|
-
else if (currentWork.heartbeat.getTime() <
|
|
3681
|
-
Date.now() - GUARDED_JOB_TIMEOUT) {
|
|
3682
|
-
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!`);
|
|
3683
|
-
// Now, take over!
|
|
3684
|
-
yield jobsTable.put({
|
|
3685
|
-
nodeId: myId,
|
|
3686
|
-
started: new Date(),
|
|
3687
|
-
heartbeat: new Date()
|
|
3688
|
-
}, jobName);
|
|
3689
|
-
return true;
|
|
3690
|
-
}
|
|
3691
|
-
return false;
|
|
3692
|
-
}));
|
|
3693
|
-
if (gotTheLock)
|
|
3694
|
-
return true;
|
|
3695
|
-
// Someone else took the job.
|
|
3696
|
-
if (awaitRemoteJob) {
|
|
3697
|
-
try {
|
|
3698
|
-
const jobDoneObservable = from(liveQuery(() => jobsTable.get(jobName))).pipe(timeout(GUARDED_JOB_TIMEOUT), filter((job) => !job)); // Wait til job is not there anymore.
|
|
3699
|
-
yield jobDoneObservable.toPromise();
|
|
3700
|
-
return false;
|
|
3701
|
-
}
|
|
3702
|
-
catch (err) {
|
|
3703
|
-
if (err.name !== 'TimeoutError') {
|
|
3704
|
-
throw err;
|
|
3705
|
-
}
|
|
3706
|
-
// Timeout stopped us! Try aquire the lock now.
|
|
3707
|
-
// It will likely succeed this time unless
|
|
3708
|
-
// another client took it.
|
|
3709
|
-
return yield aquireLock();
|
|
3710
|
-
}
|
|
3711
|
-
}
|
|
3712
|
-
return false;
|
|
3713
|
-
});
|
|
3714
|
-
}
|
|
3715
|
-
if (yield aquireLock()) {
|
|
3716
|
-
// We own the lock entry and can do our job undisturbed.
|
|
3717
|
-
// We're not within a transaction, but these type of locks
|
|
3718
|
-
// spans over transactions.
|
|
3719
|
-
// Start our heart beat during the job.
|
|
3720
|
-
// Use setInterval to make sure we are updating heartbeat even during long-lived fetch calls.
|
|
3721
|
-
const heartbeat = setInterval(() => {
|
|
3722
|
-
jobsTable.update(jobName, (job) => {
|
|
3723
|
-
if (job.nodeId === myId) {
|
|
3724
|
-
job.heartbeat = new Date();
|
|
3725
|
-
}
|
|
3726
|
-
});
|
|
3727
|
-
}, GUARDED_JOB_HEARTBEAT);
|
|
3728
|
-
try {
|
|
3729
|
-
return yield job();
|
|
3730
|
-
}
|
|
3731
|
-
finally {
|
|
3732
|
-
// Stop heartbeat
|
|
3733
|
-
clearInterval(heartbeat);
|
|
3734
|
-
// Remove the persisted job state:
|
|
3735
|
-
yield db.transaction('rw!', jobsTableName, () => __awaiter(this, void 0, void 0, function* () {
|
|
3736
|
-
const currentWork = yield jobsTable.get(jobName);
|
|
3737
|
-
if (currentWork && currentWork.nodeId === myId) {
|
|
3738
|
-
yield jobsTable.delete(jobName);
|
|
3739
|
-
}
|
|
3740
|
-
}));
|
|
3741
|
-
}
|
|
3742
|
-
}
|
|
3743
|
-
});
|
|
5427
|
+
function performGuardedJob(db, jobName, job) {
|
|
5428
|
+
if (typeof navigator === 'undefined' || !navigator.locks) {
|
|
5429
|
+
// No support for guarding jobs. IE11, node.js, etc.
|
|
5430
|
+
return job();
|
|
5431
|
+
}
|
|
5432
|
+
return navigator.locks.request(db.name + '|' + jobName, () => job());
|
|
3744
5433
|
}
|
|
3745
5434
|
|
|
3746
5435
|
const ongoingSyncs = new WeakMap();
|
|
@@ -3794,6 +5483,9 @@ function syncIfPossible(db, cloudOptions, cloudSchema, options) {
|
|
|
3794
5483
|
function _syncIfPossible() {
|
|
3795
5484
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3796
5485
|
try {
|
|
5486
|
+
// Check if should delay sync due to ratelimit:
|
|
5487
|
+
yield checkSyncRateLimitDelay(db);
|
|
5488
|
+
// Check if we need to lock the sync job. Not needed if we are the service worker.
|
|
3797
5489
|
if (db.cloud.isServiceWorkerDB) {
|
|
3798
5490
|
// We are the dedicated sync SW:
|
|
3799
5491
|
yield sync(db, cloudOptions, cloudSchema, options);
|
|
@@ -3801,7 +5493,7 @@ function syncIfPossible(db, cloudOptions, cloudSchema, options) {
|
|
|
3801
5493
|
else if (!db.cloud.usingServiceWorker) {
|
|
3802
5494
|
// We use a flow that is better suited for the case when multiple workers want to
|
|
3803
5495
|
// do the same thing.
|
|
3804
|
-
yield performGuardedJob(db, CURRENT_SYNC_WORKER,
|
|
5496
|
+
yield performGuardedJob(db, CURRENT_SYNC_WORKER, () => sync(db, cloudOptions, cloudSchema, options));
|
|
3805
5497
|
}
|
|
3806
5498
|
else {
|
|
3807
5499
|
assert(false);
|
|
@@ -3823,19 +5515,29 @@ function syncIfPossible(db, cloudOptions, cloudSchema, options) {
|
|
|
3823
5515
|
}
|
|
3824
5516
|
}
|
|
3825
5517
|
|
|
5518
|
+
const SECONDS = 1000;
|
|
5519
|
+
const MINUTES = 60 * SECONDS;
|
|
5520
|
+
|
|
3826
5521
|
function LocalSyncWorker(db, cloudOptions, cloudSchema) {
|
|
3827
5522
|
let localSyncEventSubscription = null;
|
|
3828
5523
|
//let syncHandler: ((event: Event) => void) | null = null;
|
|
3829
5524
|
//let periodicSyncHandler: ((event: Event) => void) | null = null;
|
|
3830
5525
|
let cancelToken = { cancelled: false };
|
|
5526
|
+
let retryHandle = null;
|
|
5527
|
+
let retryPurpose = null; // "pull" is superset of "push"
|
|
3831
5528
|
function syncAndRetry(purpose, retryNum = 1) {
|
|
3832
5529
|
// Use setTimeout() to get onto a clean stack and
|
|
3833
5530
|
// break free from possible active transaction:
|
|
3834
5531
|
setTimeout(() => {
|
|
5532
|
+
if (retryHandle)
|
|
5533
|
+
clearTimeout(retryHandle);
|
|
5534
|
+
const combPurpose = retryPurpose === 'pull' ? 'pull' : purpose;
|
|
5535
|
+
retryHandle = null;
|
|
5536
|
+
retryPurpose = null;
|
|
3835
5537
|
syncIfPossible(db, cloudOptions, cloudSchema, {
|
|
3836
5538
|
cancelToken,
|
|
3837
5539
|
retryImmediatelyOnFetchError: true,
|
|
3838
|
-
purpose,
|
|
5540
|
+
purpose: combPurpose,
|
|
3839
5541
|
}).catch((e) => {
|
|
3840
5542
|
console.error('error in syncIfPossible()', e);
|
|
3841
5543
|
if (cancelToken.cancelled) {
|
|
@@ -3845,7 +5547,13 @@ function LocalSyncWorker(db, cloudOptions, cloudSchema) {
|
|
|
3845
5547
|
// Mimic service worker sync event: retry 3 times
|
|
3846
5548
|
// * first retry after 5 minutes
|
|
3847
5549
|
// * second retry 15 minutes later
|
|
3848
|
-
|
|
5550
|
+
const combinedPurpose = retryPurpose && retryPurpose === 'pull' ? 'pull' : purpose;
|
|
5551
|
+
const handle = setTimeout(() => syncAndRetry(combinedPurpose, retryNum + 1), [0, 5, 15][retryNum] * MINUTES);
|
|
5552
|
+
// Cancel the previous retryHandle if it exists to avoid scheduling loads of retries.
|
|
5553
|
+
if (retryHandle)
|
|
5554
|
+
clearTimeout(retryHandle);
|
|
5555
|
+
retryHandle = handle;
|
|
5556
|
+
retryPurpose = combinedPurpose;
|
|
3849
5557
|
}
|
|
3850
5558
|
});
|
|
3851
5559
|
}, 0);
|
|
@@ -3912,10 +5620,12 @@ const Styles = {
|
|
|
3912
5620
|
},
|
|
3913
5621
|
Alert: {
|
|
3914
5622
|
error: {
|
|
3915
|
-
color: "red"
|
|
5623
|
+
color: "red",
|
|
5624
|
+
fontWeight: "bold"
|
|
3916
5625
|
},
|
|
3917
5626
|
warning: {
|
|
3918
|
-
color: "
|
|
5627
|
+
color: "#f80",
|
|
5628
|
+
fontWeight: "bold"
|
|
3919
5629
|
},
|
|
3920
5630
|
info: {
|
|
3921
5631
|
color: "black"
|
|
@@ -3956,7 +5666,8 @@ const Styles = {
|
|
|
3956
5666
|
border: "3px solid #3d3d5d",
|
|
3957
5667
|
borderRadius: "8px",
|
|
3958
5668
|
boxShadow: "0 0 80px 10px #666",
|
|
3959
|
-
width: "auto"
|
|
5669
|
+
width: "auto",
|
|
5670
|
+
fontFamily: "sans-serif",
|
|
3960
5671
|
},
|
|
3961
5672
|
Input: {
|
|
3962
5673
|
height: "35px",
|
|
@@ -3977,11 +5688,26 @@ function Dialog({ children, className }) {
|
|
|
3977
5688
|
|
|
3978
5689
|
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}
|
|
3979
5690
|
|
|
5691
|
+
/** Resolve a message template with parameters.
|
|
5692
|
+
*
|
|
5693
|
+
* Example:
|
|
5694
|
+
* resolveText({
|
|
5695
|
+
* message: "Hello {name}!",
|
|
5696
|
+
* messageCode: "HELLO",
|
|
5697
|
+
* messageParams: {name: "David"}
|
|
5698
|
+
* }) => "Hello David!"
|
|
5699
|
+
*
|
|
5700
|
+
* @param message Template message with {vars} in it.
|
|
5701
|
+
* @param messageCode Unique code for the message. Can be used for translation.
|
|
5702
|
+
* @param messageParams Parameters to be used in the message.
|
|
5703
|
+
* @returns A final message where parameters have been replaced with values.
|
|
5704
|
+
*/
|
|
3980
5705
|
function resolveText({ message, messageCode, messageParams }) {
|
|
3981
|
-
return message.replace(/\{\w+\}/ig, n => messageParams[n.
|
|
5706
|
+
return message.replace(/\{\w+\}/ig, n => messageParams[n.substring(1, n.length - 1)]);
|
|
3982
5707
|
}
|
|
3983
5708
|
|
|
3984
|
-
|
|
5709
|
+
const OTP_LENGTH = 8;
|
|
5710
|
+
function LoginDialog({ title, type, alerts, fields, submitLabel, cancelLabel, onCancel, onSubmit, }) {
|
|
3985
5711
|
const [params, setParams] = p({});
|
|
3986
5712
|
const firstFieldRef = _(null);
|
|
3987
5713
|
s(() => { var _a; return (_a = firstFieldRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, []);
|
|
@@ -3989,21 +5715,34 @@ function LoginDialog({ title, alerts, fields, onCancel, onSubmit, }) {
|
|
|
3989
5715
|
h(p$1, null,
|
|
3990
5716
|
h("h3", { style: Styles.WindowHeader }, title),
|
|
3991
5717
|
alerts.map((alert) => (h("p", { style: Styles.Alert[alert.type] }, resolveText(alert)))),
|
|
3992
|
-
h("form", { onSubmit: ev => {
|
|
5718
|
+
h("form", { onSubmit: (ev) => {
|
|
3993
5719
|
ev.preventDefault();
|
|
3994
5720
|
onSubmit(params);
|
|
3995
|
-
} }, Object.entries(fields).map(([fieldName, { type, label, placeholder }], idx) => (h("label", { style: Styles.Label },
|
|
5721
|
+
} }, Object.entries(fields).map(([fieldName, { type, label, placeholder }], idx) => (h("label", { style: Styles.Label, key: idx },
|
|
3996
5722
|
label ? `${label}: ` : '',
|
|
3997
|
-
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) => {
|
|
5723
|
+
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) => {
|
|
5724
|
+
var _a;
|
|
5725
|
+
const value = valueTransformer(type, (_a = ev.target) === null || _a === void 0 ? void 0 : _a['value']);
|
|
5726
|
+
let updatedParams = Object.assign(Object.assign({}, params), { [fieldName]: value });
|
|
5727
|
+
setParams(updatedParams);
|
|
5728
|
+
if (type === 'otp' && (value === null || value === void 0 ? void 0 : value.trim().length) === OTP_LENGTH) {
|
|
5729
|
+
// Auto-submit when OTP is filled in.
|
|
5730
|
+
onSubmit(updatedParams);
|
|
5731
|
+
}
|
|
5732
|
+
} })))))),
|
|
3998
5733
|
h("div", { style: Styles.ButtonsDiv },
|
|
3999
|
-
h(
|
|
4000
|
-
|
|
5734
|
+
h(p$1, null,
|
|
5735
|
+
h("button", { type: "submit", style: Styles.Button, onClick: () => onSubmit(params) }, submitLabel),
|
|
5736
|
+
cancelLabel && (h("button", { style: Styles.Button, onClick: onCancel }, cancelLabel))))));
|
|
4001
5737
|
}
|
|
4002
5738
|
function valueTransformer(type, value) {
|
|
4003
5739
|
switch (type) {
|
|
4004
|
-
case
|
|
4005
|
-
|
|
4006
|
-
|
|
5740
|
+
case 'email':
|
|
5741
|
+
return value.toLowerCase();
|
|
5742
|
+
case 'otp':
|
|
5743
|
+
return value.toUpperCase();
|
|
5744
|
+
default:
|
|
5745
|
+
return value;
|
|
4007
5746
|
}
|
|
4008
5747
|
}
|
|
4009
5748
|
|
|
@@ -4014,7 +5753,7 @@ class LoginGui extends d$1 {
|
|
|
4014
5753
|
this.state = { userInteraction: undefined };
|
|
4015
5754
|
}
|
|
4016
5755
|
componentDidMount() {
|
|
4017
|
-
this.subscription = from(this.props.db.cloud.userInteraction).subscribe(this.observer);
|
|
5756
|
+
this.subscription = from$1(this.props.db.cloud.userInteraction).subscribe(this.observer);
|
|
4018
5757
|
}
|
|
4019
5758
|
componentWillUnmount() {
|
|
4020
5759
|
if (this.subscription) {
|
|
@@ -4057,11 +5796,20 @@ function setupDefaultGUI(db) {
|
|
|
4057
5796
|
}
|
|
4058
5797
|
};
|
|
4059
5798
|
}
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
5799
|
+
|
|
5800
|
+
function associate(factory) {
|
|
5801
|
+
const wm = new WeakMap();
|
|
5802
|
+
return (x) => {
|
|
5803
|
+
let rv = wm.get(x);
|
|
5804
|
+
if (!rv) {
|
|
5805
|
+
rv = factory(x);
|
|
5806
|
+
wm.set(x, rv);
|
|
5807
|
+
}
|
|
5808
|
+
return rv;
|
|
5809
|
+
};
|
|
5810
|
+
}
|
|
5811
|
+
|
|
5812
|
+
const getCurrentUserEmitter = associate((db) => new BehaviorSubject(UNAUTHORIZED_USER));
|
|
4065
5813
|
|
|
4066
5814
|
function computeSyncState(db) {
|
|
4067
5815
|
let _prevStatus = db.cloud.webSocketStatus.value;
|
|
@@ -4089,8 +5837,17 @@ function computeSyncState(db) {
|
|
|
4089
5837
|
return combineLatest([
|
|
4090
5838
|
lazyWebSocketStatus,
|
|
4091
5839
|
db.syncStateChangedEvent.pipe(startWith({ phase: 'initial' })),
|
|
5840
|
+
getCurrentUserEmitter(db.dx._novip),
|
|
4092
5841
|
userIsReallyActive
|
|
4093
|
-
]).pipe(map(([status, syncState, userIsActive]) => {
|
|
5842
|
+
]).pipe(map(([status, syncState, user, userIsActive]) => {
|
|
5843
|
+
var _a;
|
|
5844
|
+
if (((_a = user.license) === null || _a === void 0 ? void 0 : _a.status) && user.license.status !== 'ok') {
|
|
5845
|
+
return {
|
|
5846
|
+
phase: 'offline',
|
|
5847
|
+
status: 'offline',
|
|
5848
|
+
license: user.license.status
|
|
5849
|
+
};
|
|
5850
|
+
}
|
|
4094
5851
|
let { phase, error, progress } = syncState;
|
|
4095
5852
|
let adjustedStatus = status;
|
|
4096
5853
|
if (phase === 'error') {
|
|
@@ -4123,27 +5880,16 @@ function computeSyncState(db) {
|
|
|
4123
5880
|
error,
|
|
4124
5881
|
progress,
|
|
4125
5882
|
status: isOnline ? adjustedStatus : 'offline',
|
|
5883
|
+
license: 'ok'
|
|
4126
5884
|
};
|
|
4127
5885
|
return retState;
|
|
4128
5886
|
}));
|
|
4129
5887
|
}
|
|
4130
5888
|
|
|
4131
|
-
function associate(factory) {
|
|
4132
|
-
const wm = new WeakMap();
|
|
4133
|
-
return (x) => {
|
|
4134
|
-
let rv = wm.get(x);
|
|
4135
|
-
if (!rv) {
|
|
4136
|
-
rv = factory(x);
|
|
4137
|
-
wm.set(x, rv);
|
|
4138
|
-
}
|
|
4139
|
-
return rv;
|
|
4140
|
-
};
|
|
4141
|
-
}
|
|
4142
|
-
|
|
4143
5889
|
function createSharedValueObservable(o, defaultValue) {
|
|
4144
5890
|
let currentValue = defaultValue;
|
|
4145
|
-
let shared = from(o).pipe(map$1((x) => (currentValue = x)), share({ resetOnRefCountZero: () => timer(1000) }));
|
|
4146
|
-
const rv = new Observable((observer) => {
|
|
5891
|
+
let shared = from$1(o).pipe(map$1((x) => (currentValue = x)), share({ resetOnRefCountZero: () => timer$1(1000) }));
|
|
5892
|
+
const rv = new Observable$1((observer) => {
|
|
4147
5893
|
let didEmit = false;
|
|
4148
5894
|
const subscription = shared.subscribe({
|
|
4149
5895
|
next(value) {
|
|
@@ -4181,8 +5927,6 @@ const getGlobalRolesObservable = associate((db) => {
|
|
|
4181
5927
|
})), {});
|
|
4182
5928
|
});
|
|
4183
5929
|
|
|
4184
|
-
const getCurrentUserEmitter = associate((db) => new BehaviorSubject(UNAUTHORIZED_USER));
|
|
4185
|
-
|
|
4186
5930
|
const getInternalAccessControlObservable = associate((db) => {
|
|
4187
5931
|
return createSharedValueObservable(getCurrentUserEmitter(db._novip).pipe(switchMap((currentUser) => liveQuery(() => db.transaction('r', 'realms', 'members', () => Promise.all([
|
|
4188
5932
|
db.members.where({ userId: currentUser.userId }).toArray(),
|
|
@@ -4465,7 +6209,7 @@ function dexieCloud(dexie) {
|
|
|
4465
6209
|
});
|
|
4466
6210
|
const syncComplete = new Subject();
|
|
4467
6211
|
dexie.cloud = {
|
|
4468
|
-
version: '
|
|
6212
|
+
version: '{version}',
|
|
4469
6213
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
4470
6214
|
schema: null,
|
|
4471
6215
|
get currentUserId() {
|
|
@@ -4501,11 +6245,24 @@ function dexieCloud(dexie) {
|
|
|
4501
6245
|
}
|
|
4502
6246
|
updateSchemaFromOptions(dexie.cloud.schema, dexie.cloud.options);
|
|
4503
6247
|
},
|
|
6248
|
+
logout({ force } = {}) {
|
|
6249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
6250
|
+
force
|
|
6251
|
+
? yield _logout(DexieCloudDB(dexie), { deleteUnsyncedData: true })
|
|
6252
|
+
: yield logout(DexieCloudDB(dexie));
|
|
6253
|
+
});
|
|
6254
|
+
},
|
|
4504
6255
|
sync({ wait, purpose } = { wait: true, purpose: 'push' }) {
|
|
6256
|
+
var _a;
|
|
4505
6257
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4506
6258
|
if (wait === undefined)
|
|
4507
6259
|
wait = true;
|
|
4508
6260
|
const db = DexieCloudDB(dexie);
|
|
6261
|
+
const licenseStatus = ((_a = db.cloud.currentUser.value.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
|
|
6262
|
+
if (licenseStatus !== 'ok') {
|
|
6263
|
+
// Refresh access token to check for updated license
|
|
6264
|
+
yield loadAccessToken(db);
|
|
6265
|
+
}
|
|
4509
6266
|
if (purpose === 'pull') {
|
|
4510
6267
|
const syncState = db.cloud.persistedSyncState.value;
|
|
4511
6268
|
triggerSync(db, purpose);
|
|
@@ -4524,7 +6281,7 @@ function dexieCloud(dexie) {
|
|
|
4524
6281
|
triggerSync(db, purpose);
|
|
4525
6282
|
if (wait) {
|
|
4526
6283
|
console.debug('db.cloud.login() is waiting for sync completion...');
|
|
4527
|
-
yield from(liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6284
|
+
yield from$1(liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
4528
6285
|
const syncNeeded = yield isSyncNeeded(db);
|
|
4529
6286
|
const newSyncState = yield db.getPersistedSyncState();
|
|
4530
6287
|
if ((newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) !== (syncState === null || syncState === void 0 ? void 0 : syncState.timestamp) &&
|
|
@@ -4709,7 +6466,9 @@ function dexieCloud(dexie) {
|
|
|
4709
6466
|
db.syncStateChangedEvent.next({
|
|
4710
6467
|
phase: 'not-in-sync',
|
|
4711
6468
|
});
|
|
4712
|
-
|
|
6469
|
+
if (!isEagerSyncDisabled(db)) {
|
|
6470
|
+
triggerSync(db, 'push');
|
|
6471
|
+
}
|
|
4713
6472
|
}), fromEvent(self, 'offline').subscribe(() => {
|
|
4714
6473
|
console.debug('offline!');
|
|
4715
6474
|
db.syncStateChangedEvent.next({
|
|
@@ -4726,7 +6485,7 @@ function dexieCloud(dexie) {
|
|
|
4726
6485
|
});
|
|
4727
6486
|
}
|
|
4728
6487
|
}
|
|
4729
|
-
dexieCloud.version = '
|
|
6488
|
+
dexieCloud.version = '{version}';
|
|
4730
6489
|
Dexie.Cloud = dexieCloud;
|
|
4731
6490
|
|
|
4732
6491
|
// In case the SW lives for a while, let it reuse already opened connections:
|