dexie-cloud-addon 4.1.0-alpha.19 → 4.1.0-alpha.20
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/modern/TSON.d.ts +1 -1
- package/dist/modern/dexie-cloud-addon.js +41 -40
- package/dist/modern/dexie-cloud-addon.js.map +1 -1
- package/dist/modern/dexie-cloud-addon.min.js +1 -1
- package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
- package/dist/modern/getInvitesObservable.d.ts +11 -11
- package/dist/modern/service-worker.js +42 -41
- package/dist/modern/service-worker.js.map +1 -1
- package/dist/modern/service-worker.min.js +1 -1
- package/dist/modern/service-worker.min.js.map +1 -1
- package/dist/umd/TSON.d.ts +1 -1
- package/dist/umd/dexie-cloud-addon.js +41 -40
- package/dist/umd/dexie-cloud-addon.js.map +1 -1
- package/dist/umd/dexie-cloud-addon.min.js +1 -1
- package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
- package/dist/umd/getInvitesObservable.d.ts +11 -11
- package/dist/umd/service-worker.js +42 -41
- package/dist/umd/service-worker.js.map +1 -1
- package/dist/umd/service-worker.min.js +1 -1
- package/dist/umd/service-worker.min.js.map +1 -1
- package/package.json +2 -2
|
@@ -3,21 +3,21 @@ export declare const getInvitesObservable: (x: Dexie) => import("./mapValueObser
|
|
|
3
3
|
accept(): Promise<void>;
|
|
4
4
|
reject(): Promise<void>;
|
|
5
5
|
id: string;
|
|
6
|
-
userId?: string
|
|
7
|
-
email?: string
|
|
8
|
-
name?: string
|
|
9
|
-
invite?: boolean
|
|
10
|
-
invitedDate?: Date
|
|
6
|
+
userId?: string;
|
|
7
|
+
email?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
invite?: boolean;
|
|
10
|
+
invitedDate?: Date;
|
|
11
11
|
invitedBy?: {
|
|
12
12
|
name: string;
|
|
13
13
|
email: string;
|
|
14
14
|
userId: string;
|
|
15
|
-
}
|
|
16
|
-
accepted?: Date
|
|
17
|
-
rejected?: Date
|
|
18
|
-
roles?: string[]
|
|
19
|
-
permissions?: import("dexie-cloud-common").DBPermissionSet
|
|
15
|
+
};
|
|
16
|
+
accepted?: Date;
|
|
17
|
+
rejected?: Date;
|
|
18
|
+
roles?: string[];
|
|
19
|
+
permissions?: import("dexie-cloud-common").DBPermissionSet;
|
|
20
20
|
realmId: string;
|
|
21
21
|
owner: string;
|
|
22
|
-
$ts?: number
|
|
22
|
+
$ts?: number;
|
|
23
23
|
}[]>;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* ==========================================================================
|
|
10
10
|
*
|
|
11
|
-
* Version 4.1.0-alpha.
|
|
11
|
+
* Version 4.1.0-alpha.20, Wed Oct 23 2024
|
|
12
12
|
*
|
|
13
13
|
* https://dexie.org
|
|
14
14
|
*
|
|
@@ -1765,8 +1765,8 @@ function registerSyncEvent(db, purpose) {
|
|
|
1765
1765
|
});
|
|
1766
1766
|
}
|
|
1767
1767
|
function registerPeriodicSyncEvent(db) {
|
|
1768
|
-
var _a;
|
|
1769
1768
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1769
|
+
var _a;
|
|
1770
1770
|
try {
|
|
1771
1771
|
// Register periodicSync event to SW:
|
|
1772
1772
|
// @ts-ignore
|
|
@@ -1831,8 +1831,8 @@ const b64encode = typeof Buffer !== "undefined"
|
|
|
1831
1831
|
return btoa(strs.join(""));
|
|
1832
1832
|
};
|
|
1833
1833
|
|
|
1834
|
-
function computeRealmSetHash(
|
|
1835
|
-
return __awaiter(this,
|
|
1834
|
+
function computeRealmSetHash(_a) {
|
|
1835
|
+
return __awaiter(this, arguments, void 0, function* ({ realms, inviteRealms, }) {
|
|
1836
1836
|
const data = JSON.stringify([
|
|
1837
1837
|
...realms.map((realmId) => ({ realmId, accepted: true })),
|
|
1838
1838
|
...inviteRealms.map((realmId) => ({ realmId, accepted: false })),
|
|
@@ -1868,8 +1868,8 @@ function flatten(a) {
|
|
|
1868
1868
|
return concat.apply([], a);
|
|
1869
1869
|
}
|
|
1870
1870
|
|
|
1871
|
-
function listClientChanges(
|
|
1872
|
-
return __awaiter(this,
|
|
1871
|
+
function listClientChanges(mutationTables_1, db_1) {
|
|
1872
|
+
return __awaiter(this, arguments, void 0, function* (mutationTables, db, { since = {}, limit = Infinity } = {}) {
|
|
1873
1873
|
const allMutsOnTables = yield Promise.all(mutationTables.map((mutationTable) => __awaiter(this, void 0, void 0, function* () {
|
|
1874
1874
|
const tableName = getTableFromMutationTable(mutationTable.name);
|
|
1875
1875
|
const lastRevision = since[tableName];
|
|
@@ -3516,8 +3516,8 @@ function confirmLogout(userInteraction, currentUserId, numUnsyncedChanges) {
|
|
|
3516
3516
|
}
|
|
3517
3517
|
|
|
3518
3518
|
function loadAccessToken(db) {
|
|
3519
|
-
var _a, _b, _c;
|
|
3520
3519
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3520
|
+
var _a, _b, _c;
|
|
3521
3521
|
const currentUser = yield db.getCurrentUser();
|
|
3522
3522
|
const { accessToken, accessTokenExpiration, refreshToken, refreshTokenExpiration, claims, } = currentUser;
|
|
3523
3523
|
if (!accessToken)
|
|
@@ -4347,8 +4347,8 @@ function cloneChange(change, rewriteValues) {
|
|
|
4347
4347
|
// seconds (given that there is a Ratelimit-Reset header).
|
|
4348
4348
|
let syncRatelimitDelays = new WeakMap();
|
|
4349
4349
|
function checkSyncRateLimitDelay(db) {
|
|
4350
|
-
var _a, _b;
|
|
4351
4350
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4351
|
+
var _a, _b;
|
|
4352
4352
|
const delatMilliseconds = ((_b = (_a = syncRatelimitDelays.get(db)) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : 0) - Date.now();
|
|
4353
4353
|
if (delatMilliseconds > 0) {
|
|
4354
4354
|
console.debug(`Stalling sync request ${delatMilliseconds} ms to spare ratelimits`);
|
|
@@ -4752,8 +4752,8 @@ function getUpdatesTable(db, table, ydocProp) {
|
|
|
4752
4752
|
}
|
|
4753
4753
|
|
|
4754
4754
|
function applyYServerMessages(yMessages, db) {
|
|
4755
|
-
var _a;
|
|
4756
4755
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4756
|
+
var _a;
|
|
4757
4757
|
const result = {};
|
|
4758
4758
|
for (const m of yMessages) {
|
|
4759
4759
|
switch (m.type) {
|
|
@@ -4818,8 +4818,8 @@ function applyYServerMessages(yMessages, db) {
|
|
|
4818
4818
|
}
|
|
4819
4819
|
|
|
4820
4820
|
function updateYSyncStates(lastUpdateIdsBeforeSync, receivedUntilsAfterSync, db, serverRevision) {
|
|
4821
|
-
var _a, _b, _c, _d, _e;
|
|
4822
4821
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4822
|
+
var _a, _b, _c, _d, _e;
|
|
4823
4823
|
// We want to update unsentFrom for each yTable to the value specified in first argument
|
|
4824
4824
|
// because we got those values before we synced with server and here we are back from server
|
|
4825
4825
|
// that has successfully received all those messages - no matter if the last update was a client or server update,
|
|
@@ -4884,8 +4884,8 @@ function updateYSyncStates(lastUpdateIdsBeforeSync, receivedUntilsAfterSync, db,
|
|
|
4884
4884
|
const BINSTREAM_TYPE_REALMID = 1;
|
|
4885
4885
|
const BINSTREAM_TYPE_TABLE_AND_PROP = 2;
|
|
4886
4886
|
const BINSTREAM_TYPE_DOCUMENT = 3;
|
|
4887
|
-
function downloadYDocsFromServer(
|
|
4888
|
-
return __awaiter(this,
|
|
4887
|
+
function downloadYDocsFromServer(db_1, databaseUrl_1, _a) {
|
|
4888
|
+
return __awaiter(this, arguments, void 0, function* (db, databaseUrl, { yDownloadedRealms, realms }) {
|
|
4889
4889
|
if (yDownloadedRealms &&
|
|
4890
4890
|
realms &&
|
|
4891
4891
|
realms.every((realmId) => yDownloadedRealms[realmId] === '*')) {
|
|
@@ -5043,11 +5043,11 @@ function sync(db, options, schema, syncOptions) {
|
|
|
5043
5043
|
return Promise.reject(error);
|
|
5044
5044
|
}));
|
|
5045
5045
|
}
|
|
5046
|
-
function _sync(
|
|
5047
|
-
isInitialSync
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5046
|
+
function _sync(db_1, options_1, schema_1) {
|
|
5047
|
+
return __awaiter(this, arguments, void 0, function* (db, options, schema, { isInitialSync, cancelToken, justCheckIfNeeded, purpose } = {
|
|
5048
|
+
isInitialSync: false,
|
|
5049
|
+
}) {
|
|
5050
|
+
var _a;
|
|
5051
5051
|
if (!justCheckIfNeeded) {
|
|
5052
5052
|
console.debug('SYNC STARTED', { isInitialSync, purpose });
|
|
5053
5053
|
}
|
|
@@ -5089,7 +5089,7 @@ function _sync(db, options, schema, { isInitialSync, cancelToken, justCheckIfNee
|
|
|
5089
5089
|
const [clientChangeSet, syncState, baseRevs, { yMessages, lastUpdateIds }] = yield db.transaction('r', db.tables, () => __awaiter(this, void 0, void 0, function* () {
|
|
5090
5090
|
const syncState = yield db.getPersistedSyncState();
|
|
5091
5091
|
const baseRevs = yield db.$baseRevs.toArray();
|
|
5092
|
-
let clientChanges = yield listClientChanges(mutationTables);
|
|
5092
|
+
let clientChanges = yield listClientChanges(mutationTables, db);
|
|
5093
5093
|
const yResults = yield listYClientMessagesAndStateVector(db, tablesToSync);
|
|
5094
5094
|
throwIfCancelled(cancelToken);
|
|
5095
5095
|
if (doSyncify) {
|
|
@@ -5358,8 +5358,8 @@ function MessagesFromServerConsumer(db) {
|
|
|
5358
5358
|
event.next(null);
|
|
5359
5359
|
}
|
|
5360
5360
|
function consumeQueue() {
|
|
5361
|
-
var _a, _b, _c, _d, _e, _f;
|
|
5362
5361
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5362
|
+
var _a, _b, _c, _d, _e, _f;
|
|
5363
5363
|
while (queue.length > 0) {
|
|
5364
5364
|
const msg = queue.shift();
|
|
5365
5365
|
try {
|
|
@@ -5674,8 +5674,8 @@ function logout(db) {
|
|
|
5674
5674
|
}
|
|
5675
5675
|
});
|
|
5676
5676
|
}
|
|
5677
|
-
function _logout(
|
|
5678
|
-
return __awaiter(this,
|
|
5677
|
+
function _logout(db_1) {
|
|
5678
|
+
return __awaiter(this, arguments, void 0, function* (db, { deleteUnsyncedData = false } = {}) {
|
|
5679
5679
|
// Clear the database without emptying configuration options.
|
|
5680
5680
|
const [numUnsynced, loggedOut] = yield db.dx.transaction('rw', db.dx.tables, (tx) => __awaiter(this, void 0, void 0, function* () {
|
|
5681
5681
|
// @ts-ignore
|
|
@@ -5713,11 +5713,11 @@ function _logout(db, { deleteUnsyncedData = false } = {}) {
|
|
|
5713
5713
|
|
|
5714
5714
|
function otpFetchTokenCallback(db) {
|
|
5715
5715
|
const { userInteraction } = db.cloud;
|
|
5716
|
-
return function otpAuthenticate(
|
|
5717
|
-
|
|
5718
|
-
|
|
5716
|
+
return function otpAuthenticate(_a) {
|
|
5717
|
+
return __awaiter(this, arguments, void 0, function* ({ public_key, hints }) {
|
|
5718
|
+
var _b;
|
|
5719
5719
|
let tokenRequest;
|
|
5720
|
-
const url = (
|
|
5720
|
+
const url = (_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.databaseUrl;
|
|
5721
5721
|
if (!url)
|
|
5722
5722
|
throw new Error(`No database URL given.`);
|
|
5723
5723
|
if ((hints === null || hints === void 0 ? void 0 : hints.grant_type) === 'demo') {
|
|
@@ -5883,8 +5883,8 @@ function setCurrentUser(db, user) {
|
|
|
5883
5883
|
}
|
|
5884
5884
|
|
|
5885
5885
|
function login(db, hints) {
|
|
5886
|
-
var _a;
|
|
5887
5886
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5887
|
+
var _a;
|
|
5888
5888
|
const currentUser = yield db.getCurrentUser();
|
|
5889
5889
|
const origUserId = currentUser.userId;
|
|
5890
5890
|
if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
|
|
@@ -7097,7 +7097,7 @@ function connectWebSocket(db) {
|
|
|
7097
7097
|
return db.cloud.persistedSyncState.pipe(filter((syncState) => (syncState === null || syncState === void 0 ? void 0 : syncState.realms.includes(userLogin.userId)) || false), take(1), map((syncState) => [userLogin, syncState]));
|
|
7098
7098
|
}
|
|
7099
7099
|
return new BehaviorSubject([userLogin, syncState]);
|
|
7100
|
-
}), switchMap((
|
|
7100
|
+
}), switchMap((_a) => __awaiter(this, [_a], void 0, function* ([userLogin, syncState]) { return [userLogin, yield computeRealmSetHash(syncState)]; })), distinctUntilChanged(([prevUser, prevHash], [currUser, currHash]) => prevUser === currUser && prevHash === currHash), switchMap(([userLogin, realmSetHash]) => {
|
|
7101
7101
|
var _a;
|
|
7102
7102
|
if (!((_a = db.cloud.persistedSyncState) === null || _a === void 0 ? void 0 : _a.value)) {
|
|
7103
7103
|
// Restart the flow if persistedSyncState is not yet available.
|
|
@@ -7158,8 +7158,8 @@ function connectWebSocket(db) {
|
|
|
7158
7158
|
}
|
|
7159
7159
|
|
|
7160
7160
|
function isSyncNeeded(db) {
|
|
7161
|
-
var _a;
|
|
7162
7161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
7162
|
+
var _a;
|
|
7163
7163
|
return ((_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.databaseUrl) && db.cloud.schema
|
|
7164
7164
|
? yield sync(db, db.cloud.options, db.cloud.schema, { justCheckIfNeeded: true })
|
|
7165
7165
|
: false;
|
|
@@ -7843,6 +7843,7 @@ class PermissionChecker {
|
|
|
7843
7843
|
// If user can update any prop in any table in this realm, return true unless
|
|
7844
7844
|
// it regards to ownership change:
|
|
7845
7845
|
if (this.permissions.update === '*') {
|
|
7846
|
+
// @ts-ignore
|
|
7846
7847
|
return props.every((prop) => prop !== 'owner');
|
|
7847
7848
|
}
|
|
7848
7849
|
const tablePermissions = (_b = this.permissions.update) === null || _b === void 0 ? void 0 : _b[this.tableName];
|
|
@@ -7926,8 +7927,8 @@ function createYHandler(db) {
|
|
|
7926
7927
|
get() {
|
|
7927
7928
|
if (awareness)
|
|
7928
7929
|
return awareness;
|
|
7929
|
-
awarenessWeakMap.set(doc, awareness);
|
|
7930
7930
|
awareness = createAwareness(db, doc, provider);
|
|
7931
|
+
awarenessWeakMap.set(doc, awareness);
|
|
7931
7932
|
return awareness;
|
|
7932
7933
|
}
|
|
7933
7934
|
});
|
|
@@ -8089,7 +8090,7 @@ function dexieCloud(dexie) {
|
|
|
8089
8090
|
const syncComplete = new Subject();
|
|
8090
8091
|
dexie.cloud = {
|
|
8091
8092
|
// @ts-ignore
|
|
8092
|
-
version: "4.1.0-alpha.
|
|
8093
|
+
version: "4.1.0-alpha.20",
|
|
8093
8094
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
8094
8095
|
schema: null,
|
|
8095
8096
|
get currentUserId() {
|
|
@@ -8125,16 +8126,16 @@ function dexieCloud(dexie) {
|
|
|
8125
8126
|
}
|
|
8126
8127
|
updateSchemaFromOptions(dexie.cloud.schema, dexie.cloud.options);
|
|
8127
8128
|
},
|
|
8128
|
-
logout(
|
|
8129
|
-
return __awaiter(this,
|
|
8129
|
+
logout() {
|
|
8130
|
+
return __awaiter(this, arguments, void 0, function* ({ force } = {}) {
|
|
8130
8131
|
force
|
|
8131
8132
|
? yield _logout(DexieCloudDB(dexie), { deleteUnsyncedData: true })
|
|
8132
8133
|
: yield logout(DexieCloudDB(dexie));
|
|
8133
8134
|
});
|
|
8134
8135
|
},
|
|
8135
|
-
sync(
|
|
8136
|
-
|
|
8137
|
-
|
|
8136
|
+
sync() {
|
|
8137
|
+
return __awaiter(this, arguments, void 0, function* ({ wait, purpose } = { wait: true, purpose: 'push' }) {
|
|
8138
|
+
var _a;
|
|
8138
8139
|
if (wait === undefined)
|
|
8139
8140
|
wait = true;
|
|
8140
8141
|
const db = DexieCloudDB(dexie);
|
|
@@ -8192,8 +8193,8 @@ function dexieCloud(dexie) {
|
|
|
8192
8193
|
dexie.use(createImplicitPropSetterMiddleware(DexieCloudDB(dexie)));
|
|
8193
8194
|
dexie.use(createIdGenerationMiddleware(DexieCloudDB(dexie)));
|
|
8194
8195
|
function onDbReady(dexie) {
|
|
8195
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
8196
8196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
8197
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
8197
8198
|
closed = false; // As Dexie calls us, we are not closed anymore. Maybe reopened? Remember db.ready event is registered with sticky flag!
|
|
8198
8199
|
const db = DexieCloudDB(dexie);
|
|
8199
8200
|
// Setup default GUI:
|
|
@@ -8216,7 +8217,7 @@ function dexieCloud(dexie) {
|
|
|
8216
8217
|
? yield navigator.serviceWorker.getRegistrations()
|
|
8217
8218
|
: [];
|
|
8218
8219
|
const [initiallySynced, lastSyncedRealms] = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
|
|
8219
|
-
var
|
|
8220
|
+
var _a, _b;
|
|
8220
8221
|
const { options, schema } = db.cloud;
|
|
8221
8222
|
const [persistedOptions, persistedSchema, persistedSyncState] = yield Promise.all([
|
|
8222
8223
|
db.getOptions(),
|
|
@@ -8238,7 +8239,7 @@ function dexieCloud(dexie) {
|
|
|
8238
8239
|
delete newPersistedOptions.awarenessProtocol;
|
|
8239
8240
|
yield db.$syncState.put(newPersistedOptions, 'options');
|
|
8240
8241
|
}
|
|
8241
|
-
if (((
|
|
8242
|
+
if (((_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.tryUseServiceWorker) &&
|
|
8242
8243
|
'serviceWorker' in navigator &&
|
|
8243
8244
|
swRegistrations.length > 0 &&
|
|
8244
8245
|
!DISABLE_SERVICEWORKER_STRATEGY) {
|
|
@@ -8252,7 +8253,7 @@ function dexieCloud(dexie) {
|
|
|
8252
8253
|
// Not configured for using service worker or no service worker
|
|
8253
8254
|
// registration exists. Don't rely on service worker to do any job.
|
|
8254
8255
|
// Use LocalSyncWorker instead.
|
|
8255
|
-
if (((
|
|
8256
|
+
if (((_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.tryUseServiceWorker) &&
|
|
8256
8257
|
!db.cloud.isServiceWorkerDB) {
|
|
8257
8258
|
console.debug('dexie-cloud-addon: Not using service worker.', swRegistrations.length === 0
|
|
8258
8259
|
? 'No SW registrations found.'
|
|
@@ -8391,7 +8392,7 @@ function dexieCloud(dexie) {
|
|
|
8391
8392
|
}
|
|
8392
8393
|
}
|
|
8393
8394
|
// @ts-ignore
|
|
8394
|
-
dexieCloud.version = "4.1.0-alpha.
|
|
8395
|
+
dexieCloud.version = "4.1.0-alpha.20";
|
|
8395
8396
|
Dexie.Cloud = dexieCloud;
|
|
8396
8397
|
|
|
8397
8398
|
// In case the SW lives for a while, let it reuse already opened connections:
|
|
@@ -8421,8 +8422,8 @@ function syncDB(dbName, purpose) {
|
|
|
8421
8422
|
}
|
|
8422
8423
|
return promise;
|
|
8423
8424
|
function _syncDB(dbName, purpose) {
|
|
8424
|
-
var _a;
|
|
8425
8425
|
return __awaiter(this, void 0, void 0, function* () {
|
|
8426
|
+
var _a;
|
|
8426
8427
|
let db = managedDBs.get(dbName);
|
|
8427
8428
|
if (!db) {
|
|
8428
8429
|
console.debug('Dexie Cloud SW: Creating new Dexie instance for', dbName);
|