dexie-cloud-addon 4.4.6 → 4.4.7
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/DXCWebSocketStatus.d.ts +1 -1
- package/dist/modern/DexieCloudAPI.d.ts +1 -1
- package/dist/modern/authentication/AuthPersistedContext.d.ts +2 -2
- package/dist/modern/currentUserEmitter.d.ts +3 -3
- package/dist/modern/db/entities/Member.d.ts +3 -3
- package/dist/modern/db/entities/PersistedSyncState.d.ts +1 -1
- package/dist/modern/db/entities/Role.d.ts +3 -3
- package/dist/modern/default-ui/Dialog.d.ts +1 -1
- package/dist/modern/default-ui/index.d.ts +5 -5
- package/dist/modern/dexie-cloud-addon.js +636 -526
- 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/dexie-cloud-client.d.ts +1 -1
- package/dist/modern/helpers/BroadcastedAndLocalEvent.d.ts +2 -2
- package/dist/modern/helpers/getSyncableTables.d.ts +3 -3
- package/dist/modern/helpers/resolveText.d.ts +1 -1
- package/dist/modern/middleware-helpers/guardedTable.d.ts +1 -1
- package/dist/modern/service-worker.js +638 -528
- 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/modern/sync/BlobDownloadTracker.d.ts +2 -2
- package/dist/modern/sync/extractRealm.d.ts +1 -1
- package/dist/modern/sync/getTablesToSyncify.d.ts +2 -2
- package/dist/modern/sync/isSyncNeeded.d.ts +1 -1
- package/dist/modern/sync/messageConsumerIsReady.d.ts +1 -1
- package/dist/modern/sync/modifyLocalObjectsWithNewUserId.d.ts +3 -3
- package/dist/modern/sync/numUnsyncedMutations.d.ts +1 -1
- package/dist/modern/sync/performGuardedJob.d.ts +1 -1
- package/dist/modern/sync/registerSyncEvent.d.ts +1 -1
- package/dist/modern/sync/triggerSync.d.ts +2 -2
- package/dist/modern/types/DXCUserInteraction.d.ts +2 -2
- package/dist/modern/types/SyncState.d.ts +2 -2
- package/dist/modern/types/TXExpandos.d.ts +1 -1
- package/dist/modern/updateSchemaFromOptions.d.ts +2 -2
- package/dist/modern/verifyConfig.d.ts +1 -1
- package/dist/modern/verifySchema.d.ts +1 -1
- package/dist/modern/yjs/YTable.d.ts +3 -3
- package/dist/modern/yjs/getUpdatesTable.d.ts +2 -2
- package/dist/modern/yjs/reopenDocSignal.d.ts +2 -2
- package/dist/umd/dexie-cloud-addon.js +644 -534
- 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/service-worker.js +646 -536
- 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 +1 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* ==========================================================================
|
|
10
10
|
*
|
|
11
|
-
* Version 4.4.
|
|
11
|
+
* Version 4.4.7, Fri Mar 27 2026
|
|
12
12
|
*
|
|
13
13
|
* https://dexie.org
|
|
14
14
|
*
|
|
@@ -114,7 +114,7 @@ function escapeDollarProps(value) {
|
|
|
114
114
|
const keys = Object.keys(value);
|
|
115
115
|
let dollarKeys = null;
|
|
116
116
|
for (let i = 0, l = keys.length; i < l; ++i) {
|
|
117
|
-
if (keys[i][0] ===
|
|
117
|
+
if (keys[i][0] === '$') {
|
|
118
118
|
dollarKeys = dollarKeys || [];
|
|
119
119
|
dollarKeys.push(keys[i]);
|
|
120
120
|
}
|
|
@@ -126,7 +126,7 @@ function escapeDollarProps(value) {
|
|
|
126
126
|
delete clone[k];
|
|
127
127
|
}
|
|
128
128
|
for (const k of dollarKeys) {
|
|
129
|
-
clone[
|
|
129
|
+
clone['$' + k] = value[k];
|
|
130
130
|
}
|
|
131
131
|
return clone;
|
|
132
132
|
}
|
|
@@ -177,7 +177,7 @@ function TypesonSimplified(...typeDefsInputs) {
|
|
|
177
177
|
//
|
|
178
178
|
// Child part
|
|
179
179
|
//
|
|
180
|
-
if (value === undefined || (key[0] ===
|
|
180
|
+
if (value === undefined || (key[0] === '$' && key !== '$t')) {
|
|
181
181
|
top = stack[stack.length - 1];
|
|
182
182
|
let deletes;
|
|
183
183
|
let mods;
|
|
@@ -188,7 +188,7 @@ function TypesonSimplified(...typeDefsInputs) {
|
|
|
188
188
|
else {
|
|
189
189
|
stack.push([this, (deletes = []), (mods = {})]);
|
|
190
190
|
}
|
|
191
|
-
if (key[0] ===
|
|
191
|
+
if (key[0] === '$' && key !== '$t') {
|
|
192
192
|
// Unescape props (also preserves undefined if this is a combo)
|
|
193
193
|
deletes.push(key);
|
|
194
194
|
mods[key.substr(1)] = value;
|
|
@@ -205,8 +205,8 @@ function TypesonSimplified(...typeDefsInputs) {
|
|
|
205
205
|
function getTypeDef(realVal) {
|
|
206
206
|
const type = typeof realVal;
|
|
207
207
|
switch (typeof realVal) {
|
|
208
|
-
case
|
|
209
|
-
case
|
|
208
|
+
case 'object':
|
|
209
|
+
case 'function': {
|
|
210
210
|
// "object", "function", null
|
|
211
211
|
if (realVal === null)
|
|
212
212
|
return null;
|
|
@@ -222,7 +222,7 @@ function TypesonSimplified(...typeDefsInputs) {
|
|
|
222
222
|
if (!typeDef) {
|
|
223
223
|
typeDef = Array.isArray(realVal)
|
|
224
224
|
? null
|
|
225
|
-
: typeof realVal ===
|
|
225
|
+
: typeof realVal === 'function'
|
|
226
226
|
? typeDefs.function || null
|
|
227
227
|
: ObjectDef;
|
|
228
228
|
}
|
|
@@ -398,13 +398,13 @@ TSONRef.resolver = null;
|
|
|
398
398
|
|
|
399
399
|
function readBlobSync(b) {
|
|
400
400
|
const req = new XMLHttpRequest();
|
|
401
|
-
req.overrideMimeType(
|
|
401
|
+
req.overrideMimeType('text/plain; charset=x-user-defined');
|
|
402
402
|
const url = URL.createObjectURL(b);
|
|
403
403
|
try {
|
|
404
|
-
req.open(
|
|
404
|
+
req.open('GET', url, false); // Sync
|
|
405
405
|
req.send();
|
|
406
406
|
if (req.status !== 200 && req.status !== 0) {
|
|
407
|
-
throw new Error(
|
|
407
|
+
throw new Error('Bad Blob access: ' + req.status);
|
|
408
408
|
}
|
|
409
409
|
return req.responseText;
|
|
410
410
|
}
|
|
@@ -418,11 +418,11 @@ const numberTypeDef = {
|
|
|
418
418
|
replace: (num) => {
|
|
419
419
|
switch (true) {
|
|
420
420
|
case isNaN(num):
|
|
421
|
-
return { $t:
|
|
421
|
+
return { $t: 'number', v: 'NaN' };
|
|
422
422
|
case num === Infinity:
|
|
423
|
-
return { $t:
|
|
423
|
+
return { $t: 'number', v: 'Infinity' };
|
|
424
424
|
case num === -Infinity:
|
|
425
|
-
return { $t:
|
|
425
|
+
return { $t: 'number', v: '-Infinity' };
|
|
426
426
|
default:
|
|
427
427
|
return num;
|
|
428
428
|
}
|
|
@@ -434,17 +434,17 @@ const numberTypeDef = {
|
|
|
434
434
|
const dateTypeDef = {
|
|
435
435
|
Date: {
|
|
436
436
|
replace: (date) => ({
|
|
437
|
-
$t:
|
|
438
|
-
v: isNaN(date.getTime()) ?
|
|
437
|
+
$t: 'Date',
|
|
438
|
+
v: isNaN(date.getTime()) ? 'NaN' : date.toISOString(),
|
|
439
439
|
}),
|
|
440
|
-
revive: ({ v }) => new Date(v ===
|
|
440
|
+
revive: ({ v }) => new Date(v === 'NaN' ? NaN : Date.parse(v)),
|
|
441
441
|
},
|
|
442
442
|
};
|
|
443
443
|
|
|
444
444
|
const setTypeDef = {
|
|
445
445
|
Set: {
|
|
446
446
|
replace: (set) => ({
|
|
447
|
-
$t:
|
|
447
|
+
$t: 'Set',
|
|
448
448
|
v: Array.from(set),
|
|
449
449
|
}),
|
|
450
450
|
revive: ({ v }) => new Set(v),
|
|
@@ -454,34 +454,34 @@ const setTypeDef = {
|
|
|
454
454
|
const mapTypeDef = {
|
|
455
455
|
Map: {
|
|
456
456
|
replace: (map) => ({
|
|
457
|
-
$t:
|
|
457
|
+
$t: 'Map',
|
|
458
458
|
v: Array.from(map.entries()),
|
|
459
459
|
}),
|
|
460
460
|
revive: ({ v }) => new Map(v),
|
|
461
461
|
},
|
|
462
462
|
};
|
|
463
463
|
|
|
464
|
-
const _global = typeof globalThis !==
|
|
464
|
+
const _global = typeof globalThis !== 'undefined' // All modern environments (node, bun, deno, browser, workers, webview etc)
|
|
465
465
|
? globalThis
|
|
466
|
-
: typeof self !==
|
|
466
|
+
: typeof self !== 'undefined' // Older browsers, workers, webview, window etc
|
|
467
467
|
? self
|
|
468
|
-
: typeof global !==
|
|
468
|
+
: typeof global !== 'undefined' // Older versions of node
|
|
469
469
|
? global
|
|
470
470
|
: undefined; // Unsupported environment. No idea to return 'this' since we are in a module or a function scope anyway.
|
|
471
471
|
|
|
472
472
|
const typedArrayTypeDefs = [
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
473
|
+
'Int8Array',
|
|
474
|
+
'Uint8Array',
|
|
475
|
+
'Uint8ClampedArray',
|
|
476
|
+
'Int16Array',
|
|
477
|
+
'Uint16Array',
|
|
478
|
+
'Int32Array',
|
|
479
|
+
'Uint32Array',
|
|
480
|
+
'Float32Array',
|
|
481
|
+
'Float64Array',
|
|
482
|
+
'DataView',
|
|
483
|
+
'BigInt64Array',
|
|
484
|
+
'BigUint64Array',
|
|
485
485
|
].reduce((specs, typeName) => ({
|
|
486
486
|
...specs,
|
|
487
487
|
[typeName]: {
|
|
@@ -509,10 +509,10 @@ const typedArrayTypeDefs = [
|
|
|
509
509
|
},
|
|
510
510
|
}), {});
|
|
511
511
|
|
|
512
|
-
const hasArrayBufferFromBase64 =
|
|
513
|
-
const hasArrayBufferToBase64 =
|
|
514
|
-
const b64decode = typeof Buffer !==
|
|
515
|
-
? (base64) => Buffer.from(base64,
|
|
512
|
+
const hasArrayBufferFromBase64 = 'fromBase64' in Uint8Array; // https://github.com/tc39/proposal-arraybuffer-base64;
|
|
513
|
+
const hasArrayBufferToBase64 = 'toBase64' in Uint8Array.prototype; // https://github.com/tc39/proposal-arraybuffer-base64;
|
|
514
|
+
const b64decode = typeof Buffer !== 'undefined'
|
|
515
|
+
? (base64) => Buffer.from(base64, 'base64') // Node
|
|
516
516
|
: hasArrayBufferFromBase64
|
|
517
517
|
? // @ts-ignore: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64
|
|
518
518
|
(base64) => Uint8Array.fromBase64(base64) // Modern javascript standard
|
|
@@ -526,14 +526,14 @@ const b64decode = typeof Buffer !== "undefined"
|
|
|
526
526
|
}
|
|
527
527
|
return bytes;
|
|
528
528
|
};
|
|
529
|
-
const b64encode = typeof Buffer !==
|
|
529
|
+
const b64encode = typeof Buffer !== 'undefined'
|
|
530
530
|
? (b) => {
|
|
531
531
|
// Node
|
|
532
532
|
if (ArrayBuffer.isView(b)) {
|
|
533
|
-
return Buffer.from(b.buffer, b.byteOffset, b.byteLength).toString(
|
|
533
|
+
return Buffer.from(b.buffer, b.byteOffset, b.byteLength).toString('base64');
|
|
534
534
|
}
|
|
535
535
|
else {
|
|
536
|
-
return Buffer.from(b).toString(
|
|
536
|
+
return Buffer.from(b).toString('base64');
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
539
|
: hasArrayBufferToBase64
|
|
@@ -552,7 +552,7 @@ const b64encode = typeof Buffer !== "undefined"
|
|
|
552
552
|
const chunk = u8a.subarray(i, i + CHUNK_SIZE);
|
|
553
553
|
strs.push(String.fromCharCode.apply(null, Array.from(chunk)));
|
|
554
554
|
}
|
|
555
|
-
return btoa(strs.join(
|
|
555
|
+
return btoa(strs.join(''));
|
|
556
556
|
};
|
|
557
557
|
|
|
558
558
|
function b64LexEncode(b) {
|
|
@@ -562,7 +562,7 @@ function b64LexDecode(b64Lex) {
|
|
|
562
562
|
return b64decode(lexToB64(b64Lex));
|
|
563
563
|
}
|
|
564
564
|
function b64ToLex(base64) {
|
|
565
|
-
var encoded =
|
|
565
|
+
var encoded = '';
|
|
566
566
|
for (var i = 0, length = base64.length; i < length; i++) {
|
|
567
567
|
encoded += ENCODE_TABLE[base64[i]];
|
|
568
568
|
}
|
|
@@ -570,81 +570,81 @@ function b64ToLex(base64) {
|
|
|
570
570
|
}
|
|
571
571
|
function lexToB64(base64lex) {
|
|
572
572
|
// only accept string input
|
|
573
|
-
if (typeof base64lex !==
|
|
574
|
-
throw new Error(
|
|
573
|
+
if (typeof base64lex !== 'string') {
|
|
574
|
+
throw new Error('invalid decoder input: ' + base64lex);
|
|
575
575
|
}
|
|
576
|
-
var base64 =
|
|
576
|
+
var base64 = '';
|
|
577
577
|
for (var i = 0, length = base64lex.length; i < length; i++) {
|
|
578
578
|
base64 += DECODE_TABLE[base64lex[i]];
|
|
579
579
|
}
|
|
580
580
|
return base64;
|
|
581
581
|
}
|
|
582
582
|
const DECODE_TABLE = {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
A:
|
|
595
|
-
B:
|
|
596
|
-
C:
|
|
597
|
-
D:
|
|
598
|
-
E:
|
|
599
|
-
F:
|
|
600
|
-
G:
|
|
601
|
-
H:
|
|
602
|
-
I:
|
|
603
|
-
J:
|
|
604
|
-
K:
|
|
605
|
-
L:
|
|
606
|
-
M:
|
|
607
|
-
N:
|
|
608
|
-
O:
|
|
609
|
-
P:
|
|
610
|
-
Q:
|
|
611
|
-
R:
|
|
612
|
-
S:
|
|
613
|
-
T:
|
|
614
|
-
U:
|
|
615
|
-
V:
|
|
616
|
-
W:
|
|
617
|
-
X:
|
|
618
|
-
Y:
|
|
619
|
-
Z:
|
|
620
|
-
_:
|
|
621
|
-
a:
|
|
622
|
-
b:
|
|
623
|
-
c:
|
|
624
|
-
d:
|
|
625
|
-
e:
|
|
626
|
-
f:
|
|
627
|
-
g:
|
|
628
|
-
h:
|
|
629
|
-
i:
|
|
630
|
-
j:
|
|
631
|
-
k:
|
|
632
|
-
l:
|
|
633
|
-
m:
|
|
634
|
-
n:
|
|
635
|
-
o:
|
|
636
|
-
p:
|
|
637
|
-
q:
|
|
638
|
-
r:
|
|
639
|
-
s:
|
|
640
|
-
t:
|
|
641
|
-
u:
|
|
642
|
-
v:
|
|
643
|
-
w:
|
|
644
|
-
x:
|
|
645
|
-
y:
|
|
646
|
-
z:
|
|
647
|
-
|
|
583
|
+
'-': '=',
|
|
584
|
+
'0': 'A',
|
|
585
|
+
'1': 'B',
|
|
586
|
+
'2': 'C',
|
|
587
|
+
'3': 'D',
|
|
588
|
+
'4': 'E',
|
|
589
|
+
'5': 'F',
|
|
590
|
+
'6': 'G',
|
|
591
|
+
'7': 'H',
|
|
592
|
+
'8': 'I',
|
|
593
|
+
'9': 'J',
|
|
594
|
+
A: 'K',
|
|
595
|
+
B: 'L',
|
|
596
|
+
C: 'M',
|
|
597
|
+
D: 'N',
|
|
598
|
+
E: 'O',
|
|
599
|
+
F: 'P',
|
|
600
|
+
G: 'Q',
|
|
601
|
+
H: 'R',
|
|
602
|
+
I: 'S',
|
|
603
|
+
J: 'T',
|
|
604
|
+
K: 'U',
|
|
605
|
+
L: 'V',
|
|
606
|
+
M: 'W',
|
|
607
|
+
N: 'X',
|
|
608
|
+
O: 'Y',
|
|
609
|
+
P: 'Z',
|
|
610
|
+
Q: 'a',
|
|
611
|
+
R: 'b',
|
|
612
|
+
S: 'c',
|
|
613
|
+
T: 'd',
|
|
614
|
+
U: 'e',
|
|
615
|
+
V: 'f',
|
|
616
|
+
W: 'g',
|
|
617
|
+
X: 'h',
|
|
618
|
+
Y: 'i',
|
|
619
|
+
Z: 'j',
|
|
620
|
+
_: 'k',
|
|
621
|
+
a: 'l',
|
|
622
|
+
b: 'm',
|
|
623
|
+
c: 'n',
|
|
624
|
+
d: 'o',
|
|
625
|
+
e: 'p',
|
|
626
|
+
f: 'q',
|
|
627
|
+
g: 'r',
|
|
628
|
+
h: 's',
|
|
629
|
+
i: 't',
|
|
630
|
+
j: 'u',
|
|
631
|
+
k: 'v',
|
|
632
|
+
l: 'w',
|
|
633
|
+
m: 'x',
|
|
634
|
+
n: 'y',
|
|
635
|
+
o: 'z',
|
|
636
|
+
p: '0',
|
|
637
|
+
q: '1',
|
|
638
|
+
r: '2',
|
|
639
|
+
s: '3',
|
|
640
|
+
t: '4',
|
|
641
|
+
u: '5',
|
|
642
|
+
v: '6',
|
|
643
|
+
w: '7',
|
|
644
|
+
x: '8',
|
|
645
|
+
y: '9',
|
|
646
|
+
z: '+',
|
|
647
|
+
'|': '/',
|
|
648
648
|
};
|
|
649
649
|
const ENCODE_TABLE = {};
|
|
650
650
|
for (const c of Object.keys(DECODE_TABLE)) {
|
|
@@ -654,7 +654,7 @@ for (const c of Object.keys(DECODE_TABLE)) {
|
|
|
654
654
|
const arrayBufferTypeDef = {
|
|
655
655
|
ArrayBuffer: {
|
|
656
656
|
replace: (ab) => ({
|
|
657
|
-
$t:
|
|
657
|
+
$t: 'ArrayBuffer',
|
|
658
658
|
v: b64LexEncode(ab),
|
|
659
659
|
}),
|
|
660
660
|
revive: ({ v }) => {
|
|
@@ -677,9 +677,9 @@ function string2ArrayBuffer(str) {
|
|
|
677
677
|
|
|
678
678
|
const blobTypeDef = {
|
|
679
679
|
Blob: {
|
|
680
|
-
test: (blob, toStringTag) => toStringTag ===
|
|
680
|
+
test: (blob, toStringTag) => toStringTag === 'Blob' || blob instanceof FakeBlob,
|
|
681
681
|
replace: (blob) => ({
|
|
682
|
-
$t:
|
|
682
|
+
$t: 'Blob',
|
|
683
683
|
v: blob instanceof FakeBlob
|
|
684
684
|
? b64encode(blob.buf)
|
|
685
685
|
: b64encode(string2ArrayBuffer(readBlobSync(blob))),
|
|
@@ -690,7 +690,7 @@ const blobTypeDef = {
|
|
|
690
690
|
const buf = ab.buffer.byteLength === ab.byteLength
|
|
691
691
|
? ab.buffer
|
|
692
692
|
: ab.buffer.slice(ab.byteOffset, ab.byteOffset + ab.byteLength);
|
|
693
|
-
return typeof Blob !==
|
|
693
|
+
return typeof Blob !== 'undefined'
|
|
694
694
|
? new Blob([new Uint8Array(buf)], { type })
|
|
695
695
|
: new FakeBlob(buf, type);
|
|
696
696
|
},
|
|
@@ -709,15 +709,15 @@ const blobTypeDef = {
|
|
|
709
709
|
|
|
710
710
|
const fileTypeDef = {
|
|
711
711
|
File: {
|
|
712
|
-
test: (file, toStringTag) => toStringTag ===
|
|
712
|
+
test: (file, toStringTag) => toStringTag === 'File',
|
|
713
713
|
replace: (file) => ({
|
|
714
|
-
$t:
|
|
714
|
+
$t: 'File',
|
|
715
715
|
v: b64encode(string2ArrayBuffer(readBlobSync(file))),
|
|
716
716
|
type: file.type,
|
|
717
717
|
name: file.name,
|
|
718
718
|
lastModified: new Date(file.lastModified).toISOString(),
|
|
719
719
|
}),
|
|
720
|
-
revive: ({ type, v, name, lastModified }) => {
|
|
720
|
+
revive: ({ type, v, name, lastModified, }) => {
|
|
721
721
|
const ab = b64decode(v);
|
|
722
722
|
const buf = ab.buffer.byteLength === ab.byteLength
|
|
723
723
|
? ab.buffer
|
|
@@ -741,13 +741,13 @@ const fileTypeDef = {
|
|
|
741
741
|
const undefinedTypeDef = {
|
|
742
742
|
undefined: {
|
|
743
743
|
replace: () => ({
|
|
744
|
-
$t:
|
|
744
|
+
$t: 'undefined',
|
|
745
745
|
}),
|
|
746
746
|
revive: () => undefined,
|
|
747
747
|
},
|
|
748
748
|
};
|
|
749
749
|
|
|
750
|
-
const getRandomValues = typeof crypto !==
|
|
750
|
+
const getRandomValues = typeof crypto !== 'undefined'
|
|
751
751
|
? crypto.getRandomValues.bind(crypto)
|
|
752
752
|
: (buf) => {
|
|
753
753
|
for (let i = 0; i < buf.length; ++i) {
|
|
@@ -848,7 +848,7 @@ function setByKeyPath(obj, keyPath, value) {
|
|
|
848
848
|
var innerObj = obj[currentKeyPath];
|
|
849
849
|
//@ts-ignore: even if currentKeyPath would be numeric string and obj would be array - it works.
|
|
850
850
|
if (!innerObj || !hasOwn(obj, currentKeyPath))
|
|
851
|
-
innerObj =
|
|
851
|
+
innerObj = obj[currentKeyPath] = {};
|
|
852
852
|
setByKeyPath(innerObj, remainingKeyPath, value);
|
|
853
853
|
}
|
|
854
854
|
}
|
|
@@ -867,17 +867,23 @@ function setByKeyPath(obj, keyPath, value) {
|
|
|
867
867
|
}
|
|
868
868
|
}
|
|
869
869
|
}
|
|
870
|
-
const randomString$1 = typeof self !== 'undefined' && typeof crypto !== 'undefined'
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
870
|
+
const randomString$1 = typeof self !== 'undefined' && typeof crypto !== 'undefined'
|
|
871
|
+
? (bytes, randomFill = crypto.getRandomValues.bind(crypto)) => {
|
|
872
|
+
// Web
|
|
873
|
+
const buf = new Uint8Array(bytes);
|
|
874
|
+
randomFill(buf);
|
|
875
|
+
return self.btoa(String.fromCharCode.apply(null, buf));
|
|
876
|
+
}
|
|
877
|
+
: typeof Buffer !== 'undefined'
|
|
878
|
+
? (bytes, randomFill = simpleRandomFill) => {
|
|
879
|
+
// Node
|
|
880
|
+
const buf = Buffer.alloc(bytes);
|
|
881
|
+
randomFill(buf);
|
|
882
|
+
return buf.toString('base64');
|
|
883
|
+
}
|
|
884
|
+
: () => {
|
|
885
|
+
throw new Error('No implementation of randomString was found');
|
|
886
|
+
};
|
|
881
887
|
function simpleRandomFill(buf) {
|
|
882
888
|
for (let i = 0; i < buf.length; ++i) {
|
|
883
889
|
buf[i] = Math.floor(Math.random() * 256);
|
|
@@ -896,11 +902,13 @@ function simpleRandomFill(buf) {
|
|
|
896
902
|
* @returns
|
|
897
903
|
*/
|
|
898
904
|
function isValidSyncableID(id) {
|
|
899
|
-
if (typeof id ===
|
|
905
|
+
if (typeof id === 'string')
|
|
900
906
|
return true;
|
|
901
907
|
//if (validIDTypes[toStringTag(id)]) return true;
|
|
902
908
|
//if (Array.isArray(id)) return id.every((part) => isValidSyncableID(part));
|
|
903
|
-
if (Array.isArray(id) &&
|
|
909
|
+
if (Array.isArray(id) &&
|
|
910
|
+
id.some((key) => isValidSyncableID(key)) &&
|
|
911
|
+
id.every(isValidSyncableIDPart))
|
|
904
912
|
return true;
|
|
905
913
|
return false;
|
|
906
914
|
}
|
|
@@ -909,53 +917,53 @@ function isValidSyncableID(id) {
|
|
|
909
917
|
* For example, ArrayBuffer cannot be used (gives "object ArrayBuffer") but Uint8Array can be
|
|
910
918
|
* used (gives comma-delimited list of included bytes).
|
|
911
919
|
* 2: Since we store the key as a VARCHAR server side in current version, try not promote types that stringifies to become very long server side.
|
|
912
|
-
*/
|
|
920
|
+
*/
|
|
913
921
|
function isValidSyncableIDPart(part) {
|
|
914
|
-
return typeof part ===
|
|
922
|
+
return (typeof part === 'string' ||
|
|
923
|
+
typeof part === 'number' ||
|
|
924
|
+
(Array.isArray(part) && part.every(isValidSyncableIDPart)));
|
|
915
925
|
}
|
|
916
926
|
function isValidAtID(id, idPrefix) {
|
|
917
|
-
return !idPrefix || (typeof id ===
|
|
927
|
+
return !idPrefix || (typeof id === 'string' && id.startsWith(idPrefix));
|
|
918
928
|
}
|
|
919
929
|
|
|
920
930
|
function applyOperation(target, table, op) {
|
|
921
931
|
const tbl = target[table] || (target[table] = {});
|
|
922
|
-
const keys = op.keys.map(key => typeof key === 'string' ? key : JSON.stringify(key));
|
|
932
|
+
const keys = op.keys.map((key) => typeof key === 'string' ? key : JSON.stringify(key));
|
|
923
933
|
switch (op.type) {
|
|
924
|
-
case
|
|
934
|
+
case 'insert':
|
|
925
935
|
// TODO: Don't treat insert and upsert the same?
|
|
926
|
-
case
|
|
936
|
+
case 'upsert':
|
|
927
937
|
keys.forEach((key, idx) => {
|
|
928
938
|
tbl[key] = {
|
|
929
|
-
type:
|
|
939
|
+
type: 'ups',
|
|
930
940
|
val: op.values[idx],
|
|
931
941
|
};
|
|
932
942
|
});
|
|
933
943
|
break;
|
|
934
|
-
case
|
|
935
|
-
case
|
|
944
|
+
case 'update':
|
|
945
|
+
case 'modify': {
|
|
936
946
|
keys.forEach((key, idx) => {
|
|
937
|
-
const changeSpec = op.type ===
|
|
938
|
-
? op.changeSpecs[idx]
|
|
939
|
-
: op.changeSpec;
|
|
947
|
+
const changeSpec = op.type === 'update' ? op.changeSpecs[idx] : op.changeSpec;
|
|
940
948
|
const entry = tbl[key];
|
|
941
949
|
if (!entry) {
|
|
942
950
|
tbl[key] = {
|
|
943
|
-
type:
|
|
951
|
+
type: 'upd',
|
|
944
952
|
mod: changeSpec,
|
|
945
953
|
};
|
|
946
954
|
}
|
|
947
955
|
else {
|
|
948
956
|
switch (entry.type) {
|
|
949
|
-
case
|
|
957
|
+
case 'ups':
|
|
950
958
|
// Adjust the existing upsert with additional updates
|
|
951
959
|
for (const [propPath, value] of Object.entries(changeSpec)) {
|
|
952
960
|
setByKeyPath(entry.val, propPath, value);
|
|
953
961
|
}
|
|
954
962
|
break;
|
|
955
|
-
case
|
|
963
|
+
case 'del':
|
|
956
964
|
// No action.
|
|
957
965
|
break;
|
|
958
|
-
case
|
|
966
|
+
case 'upd':
|
|
959
967
|
// Adjust existing update with additional updates
|
|
960
968
|
Object.assign(entry.mod, changeSpec); // May work for deep props as well - new keys is added later, right? Does the prop order persist along TSON and all? But it will not be 100% when combined with some server code (seach for "address.city": "Stockholm" comment)
|
|
961
969
|
break;
|
|
@@ -964,10 +972,10 @@ function applyOperation(target, table, op) {
|
|
|
964
972
|
});
|
|
965
973
|
break;
|
|
966
974
|
}
|
|
967
|
-
case
|
|
975
|
+
case 'delete':
|
|
968
976
|
keys.forEach((key) => {
|
|
969
977
|
tbl[key] = {
|
|
970
|
-
type:
|
|
978
|
+
type: 'del',
|
|
971
979
|
};
|
|
972
980
|
});
|
|
973
981
|
break;
|
|
@@ -1064,30 +1072,30 @@ function toDBOperationSet(inSet, txid) {
|
|
|
1064
1072
|
};
|
|
1065
1073
|
for (const [optype, muts] of Object.entries(ops)) {
|
|
1066
1074
|
switch (optype) {
|
|
1067
|
-
case
|
|
1075
|
+
case 'ups': {
|
|
1068
1076
|
const op = {
|
|
1069
|
-
type:
|
|
1070
|
-
keys: muts.map(mut => mut.key),
|
|
1071
|
-
values: muts.map(mut => mut.val),
|
|
1072
|
-
txid
|
|
1077
|
+
type: 'upsert',
|
|
1078
|
+
keys: muts.map((mut) => mut.key),
|
|
1079
|
+
values: muts.map((mut) => mut.val),
|
|
1080
|
+
txid,
|
|
1073
1081
|
};
|
|
1074
1082
|
resultEntry.muts.push(op);
|
|
1075
1083
|
break;
|
|
1076
1084
|
}
|
|
1077
|
-
case
|
|
1085
|
+
case 'upd': {
|
|
1078
1086
|
const op = {
|
|
1079
|
-
type:
|
|
1080
|
-
keys: muts.map(mut => mut.key),
|
|
1081
|
-
changeSpecs: muts.map(mut => mut.mod),
|
|
1082
|
-
txid
|
|
1087
|
+
type: 'update',
|
|
1088
|
+
keys: muts.map((mut) => mut.key),
|
|
1089
|
+
changeSpecs: muts.map((mut) => mut.mod),
|
|
1090
|
+
txid,
|
|
1083
1091
|
};
|
|
1084
1092
|
resultEntry.muts.push(op);
|
|
1085
1093
|
break;
|
|
1086
1094
|
}
|
|
1087
|
-
case
|
|
1095
|
+
case 'del': {
|
|
1088
1096
|
const op = {
|
|
1089
|
-
type:
|
|
1090
|
-
keys: muts.map(mut => mut.key),
|
|
1097
|
+
type: 'delete',
|
|
1098
|
+
keys: muts.map((mut) => mut.key),
|
|
1091
1099
|
txid,
|
|
1092
1100
|
};
|
|
1093
1101
|
resultEntry.muts.push(op);
|
|
@@ -1102,7 +1110,7 @@ function toDBOperationSet(inSet, txid) {
|
|
|
1102
1110
|
|
|
1103
1111
|
function getDbNameFromDbUrl(dbUrl) {
|
|
1104
1112
|
const url = new URL(dbUrl);
|
|
1105
|
-
return url.pathname ===
|
|
1113
|
+
return url.pathname === '/'
|
|
1106
1114
|
? url.hostname.split('.')[0]
|
|
1107
1115
|
: url.pathname.split('/')[1];
|
|
1108
1116
|
}
|
|
@@ -1220,7 +1228,8 @@ function decodeYMessage(a) {
|
|
|
1220
1228
|
prop,
|
|
1221
1229
|
k,
|
|
1222
1230
|
u: readVarUint8Array(decoder),
|
|
1223
|
-
r: (decoder.pos < decoder.arr.length && readVarString(decoder)) ||
|
|
1231
|
+
r: (decoder.pos < decoder.arr.length && readVarString(decoder)) ||
|
|
1232
|
+
undefined,
|
|
1224
1233
|
};
|
|
1225
1234
|
default:
|
|
1226
1235
|
throw new TypeError(`Unknown message type: ${type}`);
|
|
@@ -1237,7 +1246,8 @@ async function asyncIterablePipeline(source, ...stages) {
|
|
|
1237
1246
|
}
|
|
1238
1247
|
// Start running the machine. If the last stage is a sink, it will consume the data and never emit anything
|
|
1239
1248
|
// to us here...
|
|
1240
|
-
for await (const chunk of result) {
|
|
1249
|
+
for await (const chunk of result) {
|
|
1250
|
+
}
|
|
1241
1251
|
}
|
|
1242
1252
|
|
|
1243
1253
|
async function* consumeChunkedBinaryStream(source) {
|
|
@@ -1291,7 +1301,7 @@ async function* consumeChunkedBinaryStream(source) {
|
|
|
1291
1301
|
}
|
|
1292
1302
|
if (pos + len > chunk.byteLength) {
|
|
1293
1303
|
bufs.push(chunk.slice(pos));
|
|
1294
|
-
len -=
|
|
1304
|
+
len -= chunk.byteLength - pos;
|
|
1295
1305
|
state = 2;
|
|
1296
1306
|
pos = chunk.byteLength; // will break while loop.
|
|
1297
1307
|
}
|
|
@@ -1322,7 +1332,7 @@ async function* consumeChunkedBinaryStream(source) {
|
|
|
1322
1332
|
function getFetchResponseBodyGenerator(res) {
|
|
1323
1333
|
return async function* () {
|
|
1324
1334
|
if (!res.body)
|
|
1325
|
-
throw new Error(
|
|
1335
|
+
throw new Error('Response body is not readable');
|
|
1326
1336
|
const reader = res.body.getReader();
|
|
1327
1337
|
try {
|
|
1328
1338
|
while (true) {
|
|
@@ -1391,11 +1401,11 @@ function hasBlobRefs(obj, visited = new WeakSet()) {
|
|
|
1391
1401
|
return false;
|
|
1392
1402
|
}
|
|
1393
1403
|
if (Array.isArray(obj)) {
|
|
1394
|
-
return obj.some(item => hasBlobRefs(item, visited));
|
|
1404
|
+
return obj.some((item) => hasBlobRefs(item, visited));
|
|
1395
1405
|
}
|
|
1396
1406
|
// Only traverse POJOs
|
|
1397
1407
|
if (obj.constructor === Object) {
|
|
1398
|
-
return Object.values(obj).some(value => hasBlobRefs(value, visited));
|
|
1408
|
+
return Object.values(obj).some((value) => hasBlobRefs(value, visited));
|
|
1399
1409
|
}
|
|
1400
1410
|
return false;
|
|
1401
1411
|
}
|
|
@@ -1459,7 +1469,8 @@ function convertToOriginalType(data, ref) {
|
|
|
1459
1469
|
*/
|
|
1460
1470
|
function resolveAllBlobRefs(obj_1, dbUrl_1) {
|
|
1461
1471
|
return __awaiter(this, arguments, void 0, function* (obj, dbUrl, resolvedBlobs = [], currentPath = '', visited = new WeakMap(), tracker) {
|
|
1462
|
-
if (obj == null) {
|
|
1472
|
+
if (obj == null) {
|
|
1473
|
+
// null or undefined
|
|
1463
1474
|
return obj;
|
|
1464
1475
|
}
|
|
1465
1476
|
// Check if this is a BlobRef - resolve it and track it
|
|
@@ -1508,9 +1519,7 @@ function resolveAllBlobRefs(obj_1, dbUrl_1) {
|
|
|
1508
1519
|
* Check if an object has unresolved BlobRefs
|
|
1509
1520
|
*/
|
|
1510
1521
|
function hasUnresolvedBlobRefs(obj) {
|
|
1511
|
-
return (typeof obj === 'object' &&
|
|
1512
|
-
obj !== null &&
|
|
1513
|
-
obj._hasBlobRefs === 1);
|
|
1522
|
+
return (typeof obj === 'object' && obj !== null && obj._hasBlobRefs === 1);
|
|
1514
1523
|
}
|
|
1515
1524
|
|
|
1516
1525
|
function getSyncableTables(db) {
|
|
@@ -1575,7 +1584,7 @@ function observeBlobProgress(db, downloading$) {
|
|
|
1575
1584
|
isDownloading: isDownloading && stats.blobsRemaining > 0,
|
|
1576
1585
|
blobsRemaining: stats.blobsRemaining,
|
|
1577
1586
|
bytesRemaining: stats.bytesRemaining,
|
|
1578
|
-
})), share({ resetOnRefCountZero: () => timer(2000) }) // Keep alive for 2s after last unsubscription to avoid rapid re-subscriptions during UI updates
|
|
1587
|
+
})), share({ resetOnRefCountZero: () => timer(2000) }) // Keep alive for 2s after last unsubscription to avoid rapid re-subscriptions during UI updates
|
|
1579
1588
|
);
|
|
1580
1589
|
}
|
|
1581
1590
|
/**
|
|
@@ -1659,13 +1668,13 @@ function downloadUnresolvedBlobs(db, downloading$, signal) {
|
|
|
1659
1668
|
}
|
|
1660
1669
|
setDownloadingState(downloading$, true);
|
|
1661
1670
|
try {
|
|
1662
|
-
debugLog(`Eager download: Found ${syncedTables.length} syncable tables: ${syncedTables.map(t => t.name).join(', ')}`);
|
|
1671
|
+
debugLog(`Eager download: Found ${syncedTables.length} syncable tables: ${syncedTables.map((t) => t.name).join(', ')}`);
|
|
1663
1672
|
for (const table of syncedTables) {
|
|
1664
1673
|
if (signal === null || signal === void 0 ? void 0 : signal.aborted)
|
|
1665
1674
|
;
|
|
1666
1675
|
try {
|
|
1667
1676
|
// Check if table has _hasBlobRefs index
|
|
1668
|
-
const hasIndex = table.schema.indexes.some(idx => idx.name === '_hasBlobRefs');
|
|
1677
|
+
const hasIndex = table.schema.indexes.some((idx) => idx.name === '_hasBlobRefs');
|
|
1669
1678
|
if (!hasIndex)
|
|
1670
1679
|
continue;
|
|
1671
1680
|
// Query objects with _hasBlobRefs marker
|
|
@@ -1681,7 +1690,7 @@ function downloadUnresolvedBlobs(db, downloading$, signal) {
|
|
|
1681
1690
|
const MAX_CONCURRENT = 6;
|
|
1682
1691
|
const primaryKey = table.schema.primKey;
|
|
1683
1692
|
// Filter to actionable objects first
|
|
1684
|
-
const pending = unresolvedObjects.filter(obj => {
|
|
1693
|
+
const pending = unresolvedObjects.filter((obj) => {
|
|
1685
1694
|
if (!hasUnresolvedBlobRefs(obj))
|
|
1686
1695
|
return false;
|
|
1687
1696
|
const key = primaryKey.keyPath
|
|
@@ -1742,7 +1751,7 @@ function registerSyncEvent(db, purpose) {
|
|
|
1742
1751
|
try {
|
|
1743
1752
|
// Send sync event to SW:
|
|
1744
1753
|
const sw = yield navigator.serviceWorker.ready;
|
|
1745
|
-
if (purpose ===
|
|
1754
|
+
if (purpose === 'push' && sw.sync) {
|
|
1746
1755
|
yield sw.sync.register(`dexie-cloud:${db.name}`);
|
|
1747
1756
|
}
|
|
1748
1757
|
if (sw.active) {
|
|
@@ -1751,7 +1760,7 @@ function registerSyncEvent(db, purpose) {
|
|
|
1751
1760
|
sw.active.postMessage({
|
|
1752
1761
|
type: 'dexie-cloud-sync',
|
|
1753
1762
|
dbName: db.name,
|
|
1754
|
-
purpose
|
|
1763
|
+
purpose,
|
|
1755
1764
|
});
|
|
1756
1765
|
}
|
|
1757
1766
|
else {
|
|
@@ -1876,14 +1885,15 @@ function promptForEmail(userInteraction, title, emailHint, initialAlert) {
|
|
|
1876
1885
|
// the domain extension like .com, .net, etc.
|
|
1877
1886
|
// (\sas\s[\w-+.]+@([\w-]+\.)+[\w-]{2,10})?$ : This part is optional (due to the ? at the end).
|
|
1878
1887
|
// If present, it matches " as " followed by another valid email address. This allows for the
|
|
1879
|
-
// input to be either a single email address or two email addresses separated by " as ".
|
|
1888
|
+
// input to be either a single email address or two email addresses separated by " as ".
|
|
1880
1889
|
//
|
|
1881
1890
|
// The use case for "<email1> as <email2>"" is for when a database owner with full access to the
|
|
1882
1891
|
// database needs to impersonate another user in the database in order to troubleshoot. This
|
|
1883
1892
|
// format will only be possible to use when email1 is the owner of an API client with GLOBAL_READ
|
|
1884
1893
|
// and GLOBAL_WRITE permissions on the database. The email will be checked on the server before
|
|
1885
1894
|
// allowing it and giving out a token for email2, using the OTP sent to email1.
|
|
1886
|
-
while (!email ||
|
|
1895
|
+
while (!email ||
|
|
1896
|
+
!/^[\w-+.]+@([\w-]+\.)+[\w-]{2,10}(\sas\s[\w-+.]+@([\w-]+\.)+[\w-]{2,10})?$/.test(email)) {
|
|
1887
1897
|
const alerts = [];
|
|
1888
1898
|
if (firstPrompt && initialAlert)
|
|
1889
1899
|
alerts.push(initialAlert);
|
|
@@ -1949,7 +1959,7 @@ function confirmLogout(userInteraction, currentUserId, numUnsyncedChanges) {
|
|
|
1949
1959
|
messageParams: {
|
|
1950
1960
|
currentUserId,
|
|
1951
1961
|
numUnsyncedChanges: numUnsyncedChanges.toString(),
|
|
1952
|
-
}
|
|
1962
|
+
},
|
|
1953
1963
|
},
|
|
1954
1964
|
];
|
|
1955
1965
|
return yield interactWithUser(userInteraction, {
|
|
@@ -1958,7 +1968,7 @@ function confirmLogout(userInteraction, currentUserId, numUnsyncedChanges) {
|
|
|
1958
1968
|
alerts,
|
|
1959
1969
|
fields: {},
|
|
1960
1970
|
submitLabel: 'Confirm logout',
|
|
1961
|
-
cancelLabel: 'Cancel'
|
|
1971
|
+
cancelLabel: 'Cancel',
|
|
1962
1972
|
})
|
|
1963
1973
|
.then(() => true)
|
|
1964
1974
|
.catch(() => false);
|
|
@@ -2075,7 +2085,8 @@ function loadAccessToken(db) {
|
|
|
2075
2085
|
if (!accessToken)
|
|
2076
2086
|
return null;
|
|
2077
2087
|
const expTime = (_a = accessTokenExpiration === null || accessTokenExpiration === void 0 ? void 0 : accessTokenExpiration.getTime()) !== null && _a !== void 0 ? _a : Infinity;
|
|
2078
|
-
if (expTime >
|
|
2088
|
+
if (expTime > Date.now() + 5 * MINUTES &&
|
|
2089
|
+
(((_b = currentUser.license) === null || _b === void 0 ? void 0 : _b.status) || 'ok') === 'ok') {
|
|
2079
2090
|
return currentUser;
|
|
2080
2091
|
}
|
|
2081
2092
|
if (!refreshToken) {
|
|
@@ -2235,11 +2246,13 @@ function userAuthenticate(context, fetchToken, userInteraction, hints) {
|
|
|
2235
2246
|
}
|
|
2236
2247
|
catch (error) {
|
|
2237
2248
|
// OAuth redirect is not an error - page is navigating away
|
|
2238
|
-
if (error instanceof OAuthRedirectError ||
|
|
2249
|
+
if (error instanceof OAuthRedirectError ||
|
|
2250
|
+
(error === null || error === void 0 ? void 0 : error.name) === 'OAuthRedirectError') {
|
|
2239
2251
|
throw error; // Re-throw without logging
|
|
2240
2252
|
}
|
|
2241
2253
|
// Policy rejections have already been shown to the user as a challenge
|
|
2242
|
-
if (error instanceof PolicyRejectionError ||
|
|
2254
|
+
if (error instanceof PolicyRejectionError ||
|
|
2255
|
+
(error === null || error === void 0 ? void 0 : error.name) === 'PolicyRejectionError') {
|
|
2243
2256
|
throw error;
|
|
2244
2257
|
}
|
|
2245
2258
|
if (error instanceof TokenErrorResponseError) {
|
|
@@ -2258,7 +2271,10 @@ function userAuthenticate(context, fetchToken, userInteraction, hints) {
|
|
|
2258
2271
|
if (isOffline) {
|
|
2259
2272
|
message = `You seem to be offline. Please connect to the internet and try again.`;
|
|
2260
2273
|
}
|
|
2261
|
-
else if (typeof location !== 'undefined' &&
|
|
2274
|
+
else if (typeof location !== 'undefined' &&
|
|
2275
|
+
(Dexie.debug ||
|
|
2276
|
+
location.hostname === 'localhost' ||
|
|
2277
|
+
location.hostname === '127.0.0.1')) {
|
|
2262
2278
|
// The audience is most likely the developer. Suggest to whitelist the localhost origin:
|
|
2263
2279
|
const whitelistCommand = `npx dexie-cloud whitelist ${location.origin}`;
|
|
2264
2280
|
message = `Could not connect to server. Please verify that your origin '${location.origin}' is whitelisted using \`npx dexie-cloud whitelist\``;
|
|
@@ -2308,31 +2324,31 @@ class AuthPersistedContext {
|
|
|
2308
2324
|
}
|
|
2309
2325
|
static load(db, userId) {
|
|
2310
2326
|
return db
|
|
2311
|
-
.table(
|
|
2327
|
+
.table('$logins')
|
|
2312
2328
|
.get(userId)
|
|
2313
2329
|
.then((userLogin) => new AuthPersistedContext(db, userLogin || {
|
|
2314
2330
|
userId,
|
|
2315
2331
|
claims: {
|
|
2316
|
-
sub: userId
|
|
2332
|
+
sub: userId,
|
|
2317
2333
|
},
|
|
2318
|
-
lastLogin: new Date(0)
|
|
2334
|
+
lastLogin: new Date(0),
|
|
2319
2335
|
}));
|
|
2320
2336
|
}
|
|
2321
2337
|
save() {
|
|
2322
2338
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2323
2339
|
const db = wm$3.get(this);
|
|
2324
|
-
db.table(
|
|
2340
|
+
db.table('$logins').put(this);
|
|
2325
2341
|
});
|
|
2326
2342
|
}
|
|
2327
2343
|
}
|
|
2328
2344
|
|
|
2329
2345
|
const UNAUTHORIZED_USER = {
|
|
2330
|
-
userId:
|
|
2331
|
-
name:
|
|
2346
|
+
userId: 'unauthorized',
|
|
2347
|
+
name: 'Unauthorized',
|
|
2332
2348
|
claims: {
|
|
2333
|
-
sub:
|
|
2349
|
+
sub: 'unauthorized',
|
|
2334
2350
|
},
|
|
2335
|
-
lastLogin: new Date(0)
|
|
2351
|
+
lastLogin: new Date(0),
|
|
2336
2352
|
};
|
|
2337
2353
|
try {
|
|
2338
2354
|
Object.freeze(UNAUTHORIZED_USER);
|
|
@@ -2401,7 +2417,7 @@ class HttpError extends Error {
|
|
|
2401
2417
|
this.httpStatus = res.status;
|
|
2402
2418
|
}
|
|
2403
2419
|
get name() {
|
|
2404
|
-
return
|
|
2420
|
+
return 'HttpError';
|
|
2405
2421
|
}
|
|
2406
2422
|
}
|
|
2407
2423
|
|
|
@@ -2440,7 +2456,7 @@ class OAuthError extends Error {
|
|
|
2440
2456
|
*/
|
|
2441
2457
|
function exchangeOAuthCode(options) {
|
|
2442
2458
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2443
|
-
const { databaseUrl, code, publicKey, scopes = ['ACCESS_DB'], intent } = options;
|
|
2459
|
+
const { databaseUrl, code, publicKey, scopes = ['ACCESS_DB'], intent, } = options;
|
|
2444
2460
|
const tokenRequest = Object.assign({ grant_type: 'authorization_code', code, public_key: publicKey, scopes }, (intent !== undefined ? { intent } : {}));
|
|
2445
2461
|
try {
|
|
2446
2462
|
const res = yield fetch(`${databaseUrl}/token`, {
|
|
@@ -2498,7 +2514,8 @@ function exchangeOAuthCode(options) {
|
|
|
2498
2514
|
return response;
|
|
2499
2515
|
}
|
|
2500
2516
|
catch (error) {
|
|
2501
|
-
if (error instanceof OAuthError ||
|
|
2517
|
+
if (error instanceof OAuthError ||
|
|
2518
|
+
error instanceof TokenErrorResponseError) {
|
|
2502
2519
|
throw error;
|
|
2503
2520
|
}
|
|
2504
2521
|
if (error instanceof TypeError) {
|
|
@@ -2536,7 +2553,7 @@ function fetchAuthProviders(databaseUrl_1) {
|
|
|
2536
2553
|
try {
|
|
2537
2554
|
const res = yield fetch(`${databaseUrl}/auth-providers`, {
|
|
2538
2555
|
method: 'GET',
|
|
2539
|
-
headers: {
|
|
2556
|
+
headers: { Accept: 'application/json' },
|
|
2540
2557
|
mode: 'cors',
|
|
2541
2558
|
});
|
|
2542
2559
|
if (res.status === 404) {
|
|
@@ -2866,7 +2883,7 @@ function tryParsePolicyAlert(res) {
|
|
|
2866
2883
|
* @param args
|
|
2867
2884
|
*/
|
|
2868
2885
|
function prodLog(level, ...args) {
|
|
2869
|
-
globalThis[
|
|
2886
|
+
globalThis['con' + 'sole'][level](...args);
|
|
2870
2887
|
}
|
|
2871
2888
|
|
|
2872
2889
|
/** This function changes or sets the current user as requested.
|
|
@@ -2978,8 +2995,10 @@ function login(db, hints) {
|
|
|
2978
2995
|
}
|
|
2979
2996
|
|
|
2980
2997
|
const swHolder = {};
|
|
2981
|
-
const swContainer = typeof self !== 'undefined' &&
|
|
2982
|
-
|
|
2998
|
+
const swContainer = typeof self !== 'undefined' &&
|
|
2999
|
+
self.document && // self.document is to verify we're not the SW ourself
|
|
3000
|
+
typeof navigator !== 'undefined' &&
|
|
3001
|
+
navigator.serviceWorker;
|
|
2983
3002
|
if (swContainer)
|
|
2984
3003
|
swContainer.ready.then((registration) => (swHolder.registration = registration));
|
|
2985
3004
|
if (typeof self !== 'undefined' && 'clients' in self && !self.document) {
|
|
@@ -3033,7 +3052,8 @@ class SWBroadcastChannel {
|
|
|
3033
3052
|
}
|
|
3034
3053
|
}
|
|
3035
3054
|
|
|
3036
|
-
const events = globalThis['lbc-events'] ||
|
|
3055
|
+
const events = globalThis['lbc-events'] ||
|
|
3056
|
+
(globalThis['lbc-events'] = new Map());
|
|
3037
3057
|
function addListener(name, listener) {
|
|
3038
3058
|
if (events.has(name)) {
|
|
3039
3059
|
events.get(name).push(listener);
|
|
@@ -3054,25 +3074,25 @@ function removeListener(name, listener) {
|
|
|
3054
3074
|
function dispatch(ev) {
|
|
3055
3075
|
const listeners = events.get(ev.type);
|
|
3056
3076
|
if (listeners) {
|
|
3057
|
-
listeners.forEach(listener => {
|
|
3077
|
+
listeners.forEach((listener) => {
|
|
3058
3078
|
try {
|
|
3059
3079
|
listener(ev);
|
|
3060
3080
|
}
|
|
3061
|
-
catch (_a) {
|
|
3062
|
-
}
|
|
3081
|
+
catch (_a) { }
|
|
3063
3082
|
});
|
|
3064
3083
|
}
|
|
3065
3084
|
}
|
|
3066
3085
|
class BroadcastedAndLocalEvent extends Observable {
|
|
3067
3086
|
constructor(name) {
|
|
3068
|
-
const bc = typeof BroadcastChannel ===
|
|
3069
|
-
? new SWBroadcastChannel(name)
|
|
3070
|
-
|
|
3087
|
+
const bc = typeof BroadcastChannel === 'undefined'
|
|
3088
|
+
? new SWBroadcastChannel(name)
|
|
3089
|
+
: new BroadcastChannel(name);
|
|
3090
|
+
super((subscriber) => {
|
|
3071
3091
|
function onCustomEvent(ev) {
|
|
3072
3092
|
subscriber.next(ev.detail);
|
|
3073
3093
|
}
|
|
3074
3094
|
function onMessageEvent(ev) {
|
|
3075
|
-
console.debug(
|
|
3095
|
+
console.debug('BroadcastedAndLocalEvent: onMessageEvent', ev);
|
|
3076
3096
|
subscriber.next(ev.data);
|
|
3077
3097
|
}
|
|
3078
3098
|
let unsubscribe;
|
|
@@ -3080,11 +3100,11 @@ class BroadcastedAndLocalEvent extends Observable {
|
|
|
3080
3100
|
addListener(`lbc-${name}`, onCustomEvent); // Works better in service worker
|
|
3081
3101
|
try {
|
|
3082
3102
|
if (bc instanceof SWBroadcastChannel) {
|
|
3083
|
-
unsubscribe = bc.subscribe(message => subscriber.next(message));
|
|
3103
|
+
unsubscribe = bc.subscribe((message) => subscriber.next(message));
|
|
3084
3104
|
}
|
|
3085
3105
|
else {
|
|
3086
|
-
console.debug(
|
|
3087
|
-
bc.addEventListener(
|
|
3106
|
+
console.debug('BroadcastedAndLocalEvent: bc.addEventListener()', name, 'bc is a', bc);
|
|
3107
|
+
bc.addEventListener('message', onMessageEvent);
|
|
3088
3108
|
}
|
|
3089
3109
|
}
|
|
3090
3110
|
catch (err) {
|
|
@@ -3098,7 +3118,7 @@ class BroadcastedAndLocalEvent extends Observable {
|
|
|
3098
3118
|
unsubscribe();
|
|
3099
3119
|
}
|
|
3100
3120
|
else {
|
|
3101
|
-
bc.removeEventListener(
|
|
3121
|
+
bc.removeEventListener('message', onMessageEvent);
|
|
3102
3122
|
}
|
|
3103
3123
|
};
|
|
3104
3124
|
});
|
|
@@ -3106,7 +3126,7 @@ class BroadcastedAndLocalEvent extends Observable {
|
|
|
3106
3126
|
this.bc = bc;
|
|
3107
3127
|
}
|
|
3108
3128
|
next(message) {
|
|
3109
|
-
console.debug(
|
|
3129
|
+
console.debug('BroadcastedAndLocalEvent: bc.postMessage()', Object.assign({}, message), 'bc is a', this.bc);
|
|
3110
3130
|
this.bc.postMessage(message);
|
|
3111
3131
|
const ev = new CustomEvent(`lbc-${this.name}`, { detail: message });
|
|
3112
3132
|
//self.dispatchEvent(ev);
|
|
@@ -3199,7 +3219,7 @@ function removeRedundantUpdateOps(muts) {
|
|
|
3199
3219
|
}
|
|
3200
3220
|
const strKey = '' + mut.keys[0];
|
|
3201
3221
|
const changeSpecs = mut.changeSpecs[0];
|
|
3202
|
-
if (Object.values(changeSpecs).some(v => typeof v ===
|
|
3222
|
+
if (Object.values(changeSpecs).some((v) => typeof v === 'object' && v && '@@propmod' in v)) {
|
|
3203
3223
|
continue; // Cannot optimize if any PropModification is present
|
|
3204
3224
|
}
|
|
3205
3225
|
let keyCoverage = updateCoverage.get(strKey);
|
|
@@ -3207,11 +3227,13 @@ function removeRedundantUpdateOps(muts) {
|
|
|
3207
3227
|
keyCoverage.push({ txid: mut.txid, updateSpec: changeSpecs });
|
|
3208
3228
|
}
|
|
3209
3229
|
else {
|
|
3210
|
-
updateCoverage.set(strKey, [
|
|
3230
|
+
updateCoverage.set(strKey, [
|
|
3231
|
+
{ txid: mut.txid, updateSpec: changeSpecs },
|
|
3232
|
+
]);
|
|
3211
3233
|
}
|
|
3212
3234
|
}
|
|
3213
3235
|
}
|
|
3214
|
-
muts = muts.filter(mut => {
|
|
3236
|
+
muts = muts.filter((mut) => {
|
|
3215
3237
|
// Only apply optimization to update mutations that are single-key
|
|
3216
3238
|
if (mut.type !== 'update')
|
|
3217
3239
|
return true;
|
|
@@ -3219,7 +3241,7 @@ function removeRedundantUpdateOps(muts) {
|
|
|
3219
3241
|
return true;
|
|
3220
3242
|
// Check if this has PropModifications - if so, skip optimization
|
|
3221
3243
|
const changeSpecs = mut.changeSpecs[0];
|
|
3222
|
-
if (Object.values(changeSpecs).some(v => typeof v ===
|
|
3244
|
+
if (Object.values(changeSpecs).some((v) => typeof v === 'object' && v && '@@propmod' in v)) {
|
|
3223
3245
|
return true; // Cannot optimize if any PropModification is present
|
|
3224
3246
|
}
|
|
3225
3247
|
// Keep track of properties that aren't overlapped by later transactions
|
|
@@ -3247,7 +3269,7 @@ function removeRedundantUpdateOps(muts) {
|
|
|
3247
3269
|
return muts;
|
|
3248
3270
|
}
|
|
3249
3271
|
function canonicalizeToUpdateOps(muts) {
|
|
3250
|
-
muts = muts.map(mut => {
|
|
3272
|
+
muts = muts.map((mut) => {
|
|
3251
3273
|
if (mut.type === 'modify' && mut.criteria.index === null) {
|
|
3252
3274
|
// The criteria is on primary key. Convert to an update operation instead.
|
|
3253
3275
|
// It is simpler for the server to handle and also more efficient.
|
|
@@ -3469,7 +3491,7 @@ function checkSyncRateLimitDelay(db) {
|
|
|
3469
3491
|
const delatMilliseconds = ((_b = (_a = syncRatelimitDelays.get(db)) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : 0) - Date.now();
|
|
3470
3492
|
if (delatMilliseconds > 0) {
|
|
3471
3493
|
console.debug(`Stalling sync request ${delatMilliseconds} ms to spare ratelimits`);
|
|
3472
|
-
yield new Promise(resolve => setTimeout(resolve, delatMilliseconds));
|
|
3494
|
+
yield new Promise((resolve) => setTimeout(resolve, delatMilliseconds));
|
|
3473
3495
|
}
|
|
3474
3496
|
});
|
|
3475
3497
|
}
|
|
@@ -3534,7 +3556,7 @@ function syncWithServer(changes, y, syncState, baseRevs, db, databaseUrl, schema
|
|
|
3534
3556
|
baseRevs,
|
|
3535
3557
|
changes: encodeIdsForServer(db.dx.core.schema, currentUser, changes),
|
|
3536
3558
|
y,
|
|
3537
|
-
dxcv: db.cloud.version
|
|
3559
|
+
dxcv: db.cloud.version,
|
|
3538
3560
|
};
|
|
3539
3561
|
console.debug('Sync request', syncRequest);
|
|
3540
3562
|
db.syncStateChangedEvent.next({
|
|
@@ -3574,19 +3596,22 @@ function modifyLocalObjectsWithNewUserId(syncifiedTables, currentUser, alreadySy
|
|
|
3574
3596
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3575
3597
|
const ignoredRealms = new Set(alreadySyncedRealms || []);
|
|
3576
3598
|
for (const table of syncifiedTables) {
|
|
3577
|
-
if (table.name ===
|
|
3599
|
+
if (table.name === 'members') {
|
|
3578
3600
|
// members
|
|
3579
3601
|
yield table.toCollection().modify((member) => {
|
|
3580
|
-
if (!ignoredRealms.has(member.realmId) &&
|
|
3602
|
+
if (!ignoredRealms.has(member.realmId) &&
|
|
3603
|
+
(!member.userId || member.userId === UNAUTHORIZED_USER.userId)) {
|
|
3581
3604
|
member.userId = currentUser.userId;
|
|
3582
3605
|
}
|
|
3583
3606
|
});
|
|
3584
3607
|
}
|
|
3585
|
-
else if (table.name ===
|
|
3586
|
-
else if (table.name ===
|
|
3608
|
+
else if (table.name === 'roles') ;
|
|
3609
|
+
else if (table.name === 'realms') {
|
|
3587
3610
|
// realms
|
|
3588
3611
|
yield table.toCollection().modify((realm) => {
|
|
3589
|
-
if (!ignoredRealms.has(realm.realmId) &&
|
|
3612
|
+
if (!ignoredRealms.has(realm.realmId) &&
|
|
3613
|
+
(realm.owner === undefined ||
|
|
3614
|
+
realm.owner === UNAUTHORIZED_USER.userId)) {
|
|
3590
3615
|
realm.owner = currentUser.userId;
|
|
3591
3616
|
}
|
|
3592
3617
|
});
|
|
@@ -3619,8 +3644,8 @@ function throwIfCancelled(cancelToken) {
|
|
|
3619
3644
|
let isOnline = false;
|
|
3620
3645
|
if (typeof self !== 'undefined' && typeof navigator !== 'undefined') {
|
|
3621
3646
|
isOnline = navigator.onLine;
|
|
3622
|
-
self.addEventListener('online', () => isOnline = true);
|
|
3623
|
-
self.addEventListener('offline', () => isOnline = false);
|
|
3647
|
+
self.addEventListener('online', () => (isOnline = true));
|
|
3648
|
+
self.addEventListener('offline', () => (isOnline = false));
|
|
3624
3649
|
}
|
|
3625
3650
|
|
|
3626
3651
|
function updateBaseRevs(db, schema, latestRevisions, serverRev) {
|
|
@@ -3637,7 +3662,10 @@ function updateBaseRevs(db, schema, latestRevisions, serverRev) {
|
|
|
3637
3662
|
}));
|
|
3638
3663
|
// Clean up baseRevs for tables that do not exist anymore or are no longer marked for sync
|
|
3639
3664
|
// Resolve #2168 by also cleaning up baseRevs for tables that are not marked for sync
|
|
3640
|
-
yield db.$baseRevs
|
|
3665
|
+
yield db.$baseRevs
|
|
3666
|
+
.where('tableName')
|
|
3667
|
+
.noneOf(Object.keys(schema).filter((table) => schema[table].markedForSync))
|
|
3668
|
+
.delete();
|
|
3641
3669
|
});
|
|
3642
3670
|
}
|
|
3643
3671
|
|
|
@@ -3783,10 +3811,7 @@ function applyServerChanges(changes, db) {
|
|
|
3783
3811
|
const DEXIE_CLOUD_SYNCER_ID = 'dexie-cloud-syncer';
|
|
3784
3812
|
|
|
3785
3813
|
function listUpdatesSince(yTable, sinceIncluding) {
|
|
3786
|
-
return yTable
|
|
3787
|
-
.where('i')
|
|
3788
|
-
.between(sinceIncluding, Infinity, true)
|
|
3789
|
-
.toArray();
|
|
3814
|
+
return yTable.where('i').between(sinceIncluding, Infinity, true).toArray();
|
|
3790
3815
|
}
|
|
3791
3816
|
|
|
3792
3817
|
/** Queries the local database for YMessages to send to server.
|
|
@@ -3881,7 +3906,7 @@ function listYClientMessagesAndStateVector(db, tablesToSync) {
|
|
|
3881
3906
|
}
|
|
3882
3907
|
return {
|
|
3883
3908
|
yMessages: result,
|
|
3884
|
-
lastUpdateIds
|
|
3909
|
+
lastUpdateIds,
|
|
3885
3910
|
};
|
|
3886
3911
|
});
|
|
3887
3912
|
}
|
|
@@ -3890,7 +3915,8 @@ function getUpdatesTable(db, table, ydocProp) {
|
|
|
3890
3915
|
var _a, _b, _c;
|
|
3891
3916
|
if (!db.dx._allTables[table])
|
|
3892
3917
|
return undefined;
|
|
3893
|
-
const utbl = (_c = (_b = (_a = db
|
|
3918
|
+
const utbl = (_c = (_b = (_a = db
|
|
3919
|
+
.table(table)) === null || _a === void 0 ? void 0 : _a.schema.yProps) === null || _b === void 0 ? void 0 : _b.find((p) => p.prop === ydocProp)) === null || _c === void 0 ? void 0 : _c.updatesTable;
|
|
3894
3920
|
if (!utbl) {
|
|
3895
3921
|
console.debug(`No updatesTable found for ${table}.${ydocProp}`);
|
|
3896
3922
|
return undefined;
|
|
@@ -4023,10 +4049,18 @@ const blobEndpointSupported = new Map();
|
|
|
4023
4049
|
*/
|
|
4024
4050
|
// TypedArray/DataView tags for size check
|
|
4025
4051
|
const ARRAYBUFFER_VIEW_TAGS = new Set([
|
|
4026
|
-
'Int8Array',
|
|
4027
|
-
'
|
|
4028
|
-
'
|
|
4029
|
-
'
|
|
4052
|
+
'Int8Array',
|
|
4053
|
+
'Uint8Array',
|
|
4054
|
+
'Uint8ClampedArray',
|
|
4055
|
+
'Int16Array',
|
|
4056
|
+
'Uint16Array',
|
|
4057
|
+
'Int32Array',
|
|
4058
|
+
'Uint32Array',
|
|
4059
|
+
'Float32Array',
|
|
4060
|
+
'Float64Array',
|
|
4061
|
+
'BigInt64Array',
|
|
4062
|
+
'BigUint64Array',
|
|
4063
|
+
'DataView',
|
|
4030
4064
|
]);
|
|
4031
4065
|
// Static Set for O(1) lookup of binary type tags
|
|
4032
4066
|
const BINARY_TYPE_TAGS = new Set([
|
|
@@ -4126,7 +4160,7 @@ function uploadBlob(databaseUrl, getCachedAccessToken, blob) {
|
|
|
4126
4160
|
const response = yield fetch(uploadUrl, {
|
|
4127
4161
|
method: 'PUT',
|
|
4128
4162
|
headers: {
|
|
4129
|
-
|
|
4163
|
+
Authorization: `Bearer ${accessToken}`,
|
|
4130
4164
|
'Content-Type': contentType,
|
|
4131
4165
|
},
|
|
4132
4166
|
body,
|
|
@@ -4142,8 +4176,7 @@ function uploadBlob(databaseUrl, getCachedAccessToken, blob) {
|
|
|
4142
4176
|
// The server returns the ref with version prefix (e.g., "1:blobId")
|
|
4143
4177
|
const result = yield response.json();
|
|
4144
4178
|
// Return BlobRef with server's ref (includes version) and original type preserved in _bt
|
|
4145
|
-
return Object.assign({ _bt: origType, ref: result.ref, size: size }, (origType === 'Blob' ? { ct: contentType } : {})
|
|
4146
|
-
);
|
|
4179
|
+
return Object.assign({ _bt: origType, ref: result.ref, size: size }, (origType === 'Blob' ? { ct: contentType } : {}));
|
|
4147
4180
|
});
|
|
4148
4181
|
}
|
|
4149
4182
|
function offloadBlobsAndMarkDirty(obj_1, databaseUrl_1, getCachedAccessToken_1) {
|
|
@@ -4151,7 +4184,10 @@ function offloadBlobsAndMarkDirty(obj_1, databaseUrl_1, getCachedAccessToken_1)
|
|
|
4151
4184
|
const dirtyFlag = { dirty: false };
|
|
4152
4185
|
const result = yield offloadBlobs(obj, databaseUrl, getCachedAccessToken, maxStringLength, dirtyFlag);
|
|
4153
4186
|
// Mark the object as dirty for sync if any blobs were offloaded
|
|
4154
|
-
if (dirtyFlag.dirty &&
|
|
4187
|
+
if (dirtyFlag.dirty &&
|
|
4188
|
+
typeof result === 'object' &&
|
|
4189
|
+
result !== null &&
|
|
4190
|
+
result.constructor === Object) {
|
|
4155
4191
|
result._hasBlobRefs = 1;
|
|
4156
4192
|
}
|
|
4157
4193
|
return result;
|
|
@@ -4167,7 +4203,9 @@ function offloadBlobs(obj_1, databaseUrl_1, getCachedAccessToken_1) {
|
|
|
4167
4203
|
return obj;
|
|
4168
4204
|
}
|
|
4169
4205
|
// Check if this is a long string that should be offloaded
|
|
4170
|
-
if (typeof obj === 'string' &&
|
|
4206
|
+
if (typeof obj === 'string' &&
|
|
4207
|
+
obj.length > maxStringLength &&
|
|
4208
|
+
maxStringLength !== Infinity) {
|
|
4171
4209
|
if (blobEndpointSupported.get(databaseUrl) === false) {
|
|
4172
4210
|
return obj;
|
|
4173
4211
|
}
|
|
@@ -4253,11 +4291,11 @@ function offloadBlobsInOperation(op_1, databaseUrl_1, getCachedAccessToken_1) {
|
|
|
4253
4291
|
switch (op.type) {
|
|
4254
4292
|
case 'insert':
|
|
4255
4293
|
case 'upsert': {
|
|
4256
|
-
const processedValues = yield Promise.all(op.values.map(value => offloadBlobsAndMarkDirty(value, databaseUrl, getCachedAccessToken, maxStringLength)));
|
|
4294
|
+
const processedValues = yield Promise.all(op.values.map((value) => offloadBlobsAndMarkDirty(value, databaseUrl, getCachedAccessToken, maxStringLength)));
|
|
4257
4295
|
return Object.assign(Object.assign({}, op), { values: processedValues });
|
|
4258
4296
|
}
|
|
4259
4297
|
case 'update': {
|
|
4260
|
-
const processedChangeSpecs = yield Promise.all(op.changeSpecs.map(spec => offloadBlobsAndMarkDirty(spec, databaseUrl, getCachedAccessToken, maxStringLength)));
|
|
4298
|
+
const processedChangeSpecs = yield Promise.all(op.changeSpecs.map((spec) => offloadBlobsAndMarkDirty(spec, databaseUrl, getCachedAccessToken, maxStringLength)));
|
|
4261
4299
|
return Object.assign(Object.assign({}, op), { changeSpecs: processedChangeSpecs });
|
|
4262
4300
|
}
|
|
4263
4301
|
case 'modify': {
|
|
@@ -4290,9 +4328,9 @@ function hasLargeBlobsInOperation(op, maxStringLength) {
|
|
|
4290
4328
|
switch (op.type) {
|
|
4291
4329
|
case 'insert':
|
|
4292
4330
|
case 'upsert':
|
|
4293
|
-
return op.values.some(value => hasLargeBlobs(value, maxStringLength));
|
|
4331
|
+
return op.values.some((value) => hasLargeBlobs(value, maxStringLength));
|
|
4294
4332
|
case 'update':
|
|
4295
|
-
return op.changeSpecs.some(spec => hasLargeBlobs(spec, maxStringLength));
|
|
4333
|
+
return op.changeSpecs.some((spec) => hasLargeBlobs(spec, maxStringLength));
|
|
4296
4334
|
case 'modify':
|
|
4297
4335
|
return hasLargeBlobs(op.changeSpec, maxStringLength);
|
|
4298
4336
|
default:
|
|
@@ -4304,7 +4342,9 @@ function hasLargeBlobs(obj, maxStringLength, visited = new WeakSet()) {
|
|
|
4304
4342
|
return false;
|
|
4305
4343
|
}
|
|
4306
4344
|
// Check long strings
|
|
4307
|
-
if (typeof obj === 'string' &&
|
|
4345
|
+
if (typeof obj === 'string' &&
|
|
4346
|
+
obj.length > maxStringLength &&
|
|
4347
|
+
maxStringLength !== Infinity) {
|
|
4308
4348
|
return true;
|
|
4309
4349
|
}
|
|
4310
4350
|
if (shouldOffloadBlob(obj)) {
|
|
@@ -4319,13 +4359,13 @@ function hasLargeBlobs(obj, maxStringLength, visited = new WeakSet()) {
|
|
|
4319
4359
|
}
|
|
4320
4360
|
visited.add(obj);
|
|
4321
4361
|
if (Array.isArray(obj)) {
|
|
4322
|
-
return obj.some(item => hasLargeBlobs(item, maxStringLength, visited));
|
|
4362
|
+
return obj.some((item) => hasLargeBlobs(item, maxStringLength, visited));
|
|
4323
4363
|
}
|
|
4324
4364
|
// Traverse plain objects (POJO-like) - use duck typing since IndexedDB
|
|
4325
4365
|
// may return objects where constructor !== Object
|
|
4326
4366
|
const proto = Object.getPrototypeOf(obj);
|
|
4327
4367
|
if (proto === Object.prototype || proto === null) {
|
|
4328
|
-
return Object.values(obj).some(value => hasLargeBlobs(value, maxStringLength, visited));
|
|
4368
|
+
return Object.values(obj).some((value) => hasLargeBlobs(value, maxStringLength, visited));
|
|
4329
4369
|
}
|
|
4330
4370
|
return false;
|
|
4331
4371
|
}
|
|
@@ -4379,7 +4419,7 @@ function updateYSyncStates(lastUpdateIdsBeforeSync, receivedUntilsAfterSync, db)
|
|
|
4379
4419
|
yield db.table(yTable).add({
|
|
4380
4420
|
i: DEXIE_CLOUD_SYNCER_ID,
|
|
4381
4421
|
unsentFrom,
|
|
4382
|
-
receivedUntil
|
|
4422
|
+
receivedUntil,
|
|
4383
4423
|
});
|
|
4384
4424
|
}
|
|
4385
4425
|
else {
|
|
@@ -4519,19 +4559,22 @@ function loadCachedAccessToken(db) {
|
|
|
4519
4559
|
return Promise.resolve(cached.accessToken);
|
|
4520
4560
|
}
|
|
4521
4561
|
const currentUser = db.cloud.currentUser.value;
|
|
4522
|
-
if (currentUser &&
|
|
4562
|
+
if (currentUser &&
|
|
4563
|
+
currentUser.accessToken &&
|
|
4564
|
+
((_b = (_a = currentUser.accessTokenExpiration) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : Infinity) >
|
|
4565
|
+
Date.now() + 5 * MINUTES) {
|
|
4523
4566
|
wm$2.set(db, {
|
|
4524
4567
|
accessToken: currentUser.accessToken,
|
|
4525
|
-
expiration: (_d = (_c = currentUser.accessTokenExpiration) === null || _c === void 0 ? void 0 : _c.getTime()) !== null && _d !== void 0 ? _d : Infinity
|
|
4568
|
+
expiration: (_d = (_c = currentUser.accessTokenExpiration) === null || _c === void 0 ? void 0 : _c.getTime()) !== null && _d !== void 0 ? _d : Infinity,
|
|
4526
4569
|
});
|
|
4527
4570
|
return Promise.resolve(currentUser.accessToken);
|
|
4528
4571
|
}
|
|
4529
|
-
return Dexie.ignoreTransaction(() => loadAccessToken(db).then(user => {
|
|
4572
|
+
return Dexie.ignoreTransaction(() => loadAccessToken(db).then((user) => {
|
|
4530
4573
|
var _a, _b;
|
|
4531
4574
|
if (user === null || user === void 0 ? void 0 : user.accessToken) {
|
|
4532
4575
|
wm$2.set(db, {
|
|
4533
4576
|
accessToken: user.accessToken,
|
|
4534
|
-
expiration: (_b = (_a = user.accessTokenExpiration) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : Infinity
|
|
4577
|
+
expiration: (_b = (_a = user.accessTokenExpiration) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : Infinity,
|
|
4535
4578
|
});
|
|
4536
4579
|
}
|
|
4537
4580
|
return (user === null || user === void 0 ? void 0 : user.accessToken) || null;
|
|
@@ -4542,7 +4585,8 @@ const CURRENT_SYNC_WORKER = 'currentSyncWorker';
|
|
|
4542
4585
|
function sync(db, options, schema, syncOptions) {
|
|
4543
4586
|
return _sync(db, options, schema, syncOptions)
|
|
4544
4587
|
.then((result) => {
|
|
4545
|
-
if (!(syncOptions === null || syncOptions === void 0 ? void 0 : syncOptions.justCheckIfNeeded)) {
|
|
4588
|
+
if (!(syncOptions === null || syncOptions === void 0 ? void 0 : syncOptions.justCheckIfNeeded)) {
|
|
4589
|
+
// && syncOptions?.purpose !== 'push') {
|
|
4546
4590
|
db.syncStateChangedEvent.next({
|
|
4547
4591
|
phase: 'in-sync',
|
|
4548
4592
|
});
|
|
@@ -4629,7 +4673,7 @@ function _sync(db_1, options_1, schema_1) {
|
|
|
4629
4673
|
const syncState = yield db.getPersistedSyncState();
|
|
4630
4674
|
let baseRevs = yield db.$baseRevs.toArray();
|
|
4631
4675
|
// Resolve #2168
|
|
4632
|
-
baseRevs = baseRevs.filter(br => tablesToSync.some(tbl => tbl.name === br.tableName));
|
|
4676
|
+
baseRevs = baseRevs.filter((br) => tablesToSync.some((tbl) => tbl.name === br.tableName));
|
|
4633
4677
|
let clientChanges = yield listClientChanges(mutationTables, db);
|
|
4634
4678
|
const yResults = yield listYClientMessagesAndStateVector(db, tablesToSync);
|
|
4635
4679
|
throwIfCancelled(cancelToken);
|
|
@@ -4645,7 +4689,7 @@ function _sync(db_1, options_1, schema_1) {
|
|
|
4645
4689
|
}
|
|
4646
4690
|
return [clientChanges, syncState, baseRevs, yResults];
|
|
4647
4691
|
}));
|
|
4648
|
-
const pushSyncIsNeeded = clientChangeSet.some((set) => set.muts.some((mut) => mut.keys.length > 0)) || yMessages.some(m => m.type === 'u-c');
|
|
4692
|
+
const pushSyncIsNeeded = clientChangeSet.some((set) => set.muts.some((mut) => mut.keys.length > 0)) || yMessages.some((m) => m.type === 'u-c');
|
|
4649
4693
|
if (justCheckIfNeeded) {
|
|
4650
4694
|
console.debug('Sync is needed:', pushSyncIsNeeded);
|
|
4651
4695
|
return pushSyncIsNeeded;
|
|
@@ -4789,7 +4833,7 @@ function _sync(db_1, options_1, schema_1) {
|
|
|
4789
4833
|
db.$syncState.put(newSyncState, 'syncState');
|
|
4790
4834
|
return {
|
|
4791
4835
|
done: addedClientChanges.length === 0,
|
|
4792
|
-
newSyncState
|
|
4836
|
+
newSyncState,
|
|
4793
4837
|
};
|
|
4794
4838
|
}));
|
|
4795
4839
|
if (!done) {
|
|
@@ -4797,7 +4841,7 @@ function _sync(db_1, options_1, schema_1) {
|
|
|
4797
4841
|
yield checkSyncRateLimitDelay(db);
|
|
4798
4842
|
return yield _sync(db, options, schema, { isInitialSync, cancelToken });
|
|
4799
4843
|
}
|
|
4800
|
-
const usingYProps = Object.values(schema).some(tbl => { var _a; return (_a = tbl.yProps) === null || _a === void 0 ? void 0 : _a.length; });
|
|
4844
|
+
const usingYProps = Object.values(schema).some((tbl) => { var _a; return (_a = tbl.yProps) === null || _a === void 0 ? void 0 : _a.length; });
|
|
4801
4845
|
const serverSupportsYprops = !!res.yMessages;
|
|
4802
4846
|
if (usingYProps && serverSupportsYprops) {
|
|
4803
4847
|
try {
|
|
@@ -5104,11 +5148,13 @@ class BlobDownloadTracker {
|
|
|
5104
5148
|
download(blobRef, dbUrl) {
|
|
5105
5149
|
let promise = this.inFlight.get(blobRef.ref);
|
|
5106
5150
|
if (!promise) {
|
|
5107
|
-
promise = loadCachedAccessToken(this.db)
|
|
5151
|
+
promise = loadCachedAccessToken(this.db)
|
|
5152
|
+
.then((accessToken) => {
|
|
5108
5153
|
if (!accessToken)
|
|
5109
|
-
throw new Error(
|
|
5154
|
+
throw new Error('No access token available for blob download');
|
|
5110
5155
|
return downloadBlob(blobRef, dbUrl, accessToken);
|
|
5111
|
-
})
|
|
5156
|
+
})
|
|
5157
|
+
.finally(() => this.inFlight.delete(blobRef.ref));
|
|
5112
5158
|
// When the promise settles (either fulfilled or rejected), remove it from the in-flight map
|
|
5113
5159
|
this.inFlight.set(blobRef.ref, promise);
|
|
5114
5160
|
}
|
|
@@ -5128,8 +5174,8 @@ function downloadBlob(blobRef, dbUrl, accessToken) {
|
|
|
5128
5174
|
const downloadUrl = `${dbUrl}/blob/${blobRef.ref}`;
|
|
5129
5175
|
const response = yield fetch(downloadUrl, {
|
|
5130
5176
|
headers: {
|
|
5131
|
-
|
|
5132
|
-
}
|
|
5177
|
+
Authorization: `Bearer ${accessToken}`,
|
|
5178
|
+
},
|
|
5133
5179
|
});
|
|
5134
5180
|
if (!response.ok) {
|
|
5135
5181
|
throw new Error(`Failed to download blob ${blobRef.ref}: ${response.status} ${response.statusText}`);
|
|
@@ -5221,7 +5267,9 @@ function DexieCloudDB(dx) {
|
|
|
5221
5267
|
return db.$syncState.get('schema').then((schema) => {
|
|
5222
5268
|
if (schema) {
|
|
5223
5269
|
for (const table of db.tables) {
|
|
5224
|
-
if (table.schema.primKey &&
|
|
5270
|
+
if (table.schema.primKey &&
|
|
5271
|
+
table.schema.primKey.keyPath &&
|
|
5272
|
+
schema[table.name]) {
|
|
5225
5273
|
schema[table.name].primaryKey = nameFromKeyPath(table.schema.primKey.keyPath);
|
|
5226
5274
|
}
|
|
5227
5275
|
}
|
|
@@ -5249,9 +5297,11 @@ function DexieCloudDB(dx) {
|
|
|
5249
5297
|
return db;
|
|
5250
5298
|
}
|
|
5251
5299
|
function nameFromKeyPath(keyPath) {
|
|
5252
|
-
return typeof keyPath === 'string'
|
|
5253
|
-
keyPath
|
|
5254
|
-
|
|
5300
|
+
return typeof keyPath === 'string'
|
|
5301
|
+
? keyPath
|
|
5302
|
+
: keyPath
|
|
5303
|
+
? '[' + [].join.call(keyPath, '+') + ']'
|
|
5304
|
+
: '';
|
|
5255
5305
|
}
|
|
5256
5306
|
|
|
5257
5307
|
// @ts-ignore
|
|
@@ -5273,7 +5323,7 @@ const safariVersion = isSafari
|
|
|
5273
5323
|
const DISABLE_SERVICEWORKER_STRATEGY = (isSafari && safariVersion <= 605) || // Disable for Safari for now.
|
|
5274
5324
|
isFirefox; // Disable for Firefox for now. Seems to have a bug in reading CryptoKeys from IDB from service workers
|
|
5275
5325
|
|
|
5276
|
-
const IS_SERVICE_WORKER = typeof self !==
|
|
5326
|
+
const IS_SERVICE_WORKER = typeof self !== 'undefined' && 'clients' in self && !self.document;
|
|
5277
5327
|
|
|
5278
5328
|
function throwVersionIncrementNeeded() {
|
|
5279
5329
|
throw new Dexie.SchemaError(`Version increment needed to allow dexie-cloud change tracking`);
|
|
@@ -5519,7 +5569,7 @@ function createImplicitPropSetterMiddleware(db) {
|
|
|
5519
5569
|
// We must also degrade from consistent modify operations for the
|
|
5520
5570
|
// same reason - object might be there on server. Must but put up instead.
|
|
5521
5571
|
// FUTURE: This clumpsy behavior of private IDs could be refined later.
|
|
5522
|
-
// Suggestion is to in future, treat private IDs as we treat all objects
|
|
5572
|
+
// Suggestion is to in future, treat private IDs as we treat all objects
|
|
5523
5573
|
// and sync operations normally. Only that deletions should become soft deletes
|
|
5524
5574
|
// for them - so that server knows when a private ID has been deleted on server
|
|
5525
5575
|
// not accept insert/upserts on them.
|
|
@@ -5542,19 +5592,20 @@ function createImplicitPropSetterMiddleware(db) {
|
|
|
5542
5592
|
}
|
|
5543
5593
|
|
|
5544
5594
|
function allSettled(possiblePromises) {
|
|
5545
|
-
return new Promise(resolve => {
|
|
5595
|
+
return new Promise((resolve) => {
|
|
5546
5596
|
if (possiblePromises.length === 0)
|
|
5547
5597
|
resolve([]);
|
|
5548
5598
|
let remaining = possiblePromises.length;
|
|
5549
5599
|
const results = new Array(remaining);
|
|
5550
|
-
possiblePromises.forEach((p, i) => Promise.resolve(p)
|
|
5600
|
+
possiblePromises.forEach((p, i) => Promise.resolve(p)
|
|
5601
|
+
.then((value) => (results[i] = { status: 'fulfilled', value }), (reason) => (results[i] = { status: 'rejected', reason }))
|
|
5551
5602
|
.then(() => --remaining || resolve(results)));
|
|
5552
5603
|
});
|
|
5553
5604
|
}
|
|
5554
5605
|
|
|
5555
5606
|
let counter$1 = 0;
|
|
5556
5607
|
function guardedTable(table) {
|
|
5557
|
-
const prop =
|
|
5608
|
+
const prop = '$lock' + ++counter$1;
|
|
5558
5609
|
return Object.assign(Object.assign({}, table), { count: readLock(table.count, prop), get: readLock(table.get, prop), getMany: readLock(table.getMany, prop), openCursor: readLock(table.openCursor, prop), query: readLock(table.query, prop), mutate: writeLock(table.mutate, prop) });
|
|
5559
5610
|
}
|
|
5560
5611
|
function readLock(fn, prop) {
|
|
@@ -5563,7 +5614,9 @@ function readLock(fn, prop) {
|
|
|
5563
5614
|
const numWriters = writers.length;
|
|
5564
5615
|
const promise = (numWriters > 0
|
|
5565
5616
|
? writers[numWriters - 1].then(() => fn(req), () => fn(req))
|
|
5566
|
-
: fn(req)).finally(() => {
|
|
5617
|
+
: fn(req)).finally(() => {
|
|
5618
|
+
readers.splice(readers.indexOf(promise));
|
|
5619
|
+
});
|
|
5567
5620
|
readers.push(promise);
|
|
5568
5621
|
return promise;
|
|
5569
5622
|
};
|
|
@@ -5575,7 +5628,9 @@ function writeLock(fn, prop) {
|
|
|
5575
5628
|
? writers[writers.length - 1].then(() => fn(req), () => fn(req))
|
|
5576
5629
|
: readers.length > 0
|
|
5577
5630
|
? allSettled(readers).then(() => fn(req))
|
|
5578
|
-
: fn(req)).finally(() => {
|
|
5631
|
+
: fn(req)).finally(() => {
|
|
5632
|
+
writers.shift();
|
|
5633
|
+
});
|
|
5579
5634
|
writers.push(promise);
|
|
5580
5635
|
return promise;
|
|
5581
5636
|
};
|
|
@@ -5853,16 +5908,17 @@ function createMutationTrackingMiddleware({ currentUserObservable, db, }) {
|
|
|
5853
5908
|
userId,
|
|
5854
5909
|
values,
|
|
5855
5910
|
}
|
|
5856
|
-
: upsert && updates
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5911
|
+
: upsert && updates
|
|
5912
|
+
? {
|
|
5913
|
+
type: 'upsert',
|
|
5914
|
+
ts,
|
|
5915
|
+
opNo,
|
|
5916
|
+
keys,
|
|
5917
|
+
values,
|
|
5918
|
+
changeSpecs: updates.changeSpecs.filter((_, idx) => !failures[idx]),
|
|
5919
|
+
txid,
|
|
5920
|
+
userId,
|
|
5921
|
+
}
|
|
5866
5922
|
: criteria && changeSpec
|
|
5867
5923
|
? {
|
|
5868
5924
|
// Common changeSpec for all keys
|
|
@@ -5975,7 +6031,8 @@ class BlobSavingQueue {
|
|
|
5975
6031
|
return;
|
|
5976
6032
|
}
|
|
5977
6033
|
// Atomic update of just the blob property
|
|
5978
|
-
this.db
|
|
6034
|
+
this.db
|
|
6035
|
+
.transaction('rw', item.tableName, (tx) => {
|
|
5979
6036
|
const trans = tx.idbtrans;
|
|
5980
6037
|
trans.disableChangeTracking = true; // Don't regard this as a change for sync purposes
|
|
5981
6038
|
trans.disableAccessControl = true; // Bypass any access control checks since this is an internal operation
|
|
@@ -5984,7 +6041,7 @@ class BlobSavingQueue {
|
|
|
5984
6041
|
for (const blob of item.resolvedBlobs) {
|
|
5985
6042
|
updateSpec[blob.keyPath] = blob.data;
|
|
5986
6043
|
}
|
|
5987
|
-
tx.table(item.tableName).update(item.primaryKey, obj => {
|
|
6044
|
+
tx.table(item.tableName).update(item.primaryKey, (obj) => {
|
|
5988
6045
|
// Check that object still has the same unresolved blob refs before applying update (i.e. it hasn't been modified since we read it)
|
|
5989
6046
|
for (const blob of item.resolvedBlobs) {
|
|
5990
6047
|
// Verify atomicity - none of the blob properties has been modified since we read it. If any of them was modified, skip updating this item to avoid overwriting user changes.
|
|
@@ -6005,9 +6062,11 @@ class BlobSavingQueue {
|
|
|
6005
6062
|
}
|
|
6006
6063
|
delete obj._hasBlobRefs; // Clear the _hasBlobRefs marker if all refs was resolved.
|
|
6007
6064
|
});
|
|
6008
|
-
})
|
|
6065
|
+
})
|
|
6066
|
+
.catch((error) => {
|
|
6009
6067
|
console.error(`Error saving resolved blobs on ${item.tableName}:${item.primaryKey}:`, error);
|
|
6010
|
-
})
|
|
6068
|
+
})
|
|
6069
|
+
.finally(() => {
|
|
6011
6070
|
// Process next item in the queue
|
|
6012
6071
|
return this.processQueue();
|
|
6013
6072
|
});
|
|
@@ -6058,7 +6117,7 @@ function createBlobResolveMiddleware(db) {
|
|
|
6058
6117
|
if ((_a = req.trans) === null || _a === void 0 ? void 0 : _a.disableBlobResolve) {
|
|
6059
6118
|
return downlevelTable.get(req);
|
|
6060
6119
|
}
|
|
6061
|
-
return downlevelTable.get(req).then(result => {
|
|
6120
|
+
return downlevelTable.get(req).then((result) => {
|
|
6062
6121
|
if (result && hasUnresolvedBlobRefs(result)) {
|
|
6063
6122
|
return resolveAndSave(downlevelTable, req.trans, req.key, result, blobSavingQueue, db);
|
|
6064
6123
|
}
|
|
@@ -6070,9 +6129,9 @@ function createBlobResolveMiddleware(db) {
|
|
|
6070
6129
|
if ((_a = req.trans) === null || _a === void 0 ? void 0 : _a.disableBlobResolve) {
|
|
6071
6130
|
return downlevelTable.getMany(req);
|
|
6072
6131
|
}
|
|
6073
|
-
return downlevelTable.getMany(req).then(results => {
|
|
6132
|
+
return downlevelTable.getMany(req).then((results) => {
|
|
6074
6133
|
// Check if any results need resolution
|
|
6075
|
-
const needsResolution = results.some(r => r && hasUnresolvedBlobRefs(r));
|
|
6134
|
+
const needsResolution = results.some((r) => r && hasUnresolvedBlobRefs(r));
|
|
6076
6135
|
if (!needsResolution)
|
|
6077
6136
|
return results;
|
|
6078
6137
|
return Dexie.Promise.all(results.map((result, index) => {
|
|
@@ -6088,19 +6147,19 @@ function createBlobResolveMiddleware(db) {
|
|
|
6088
6147
|
if ((_a = req.trans) === null || _a === void 0 ? void 0 : _a.disableBlobResolve) {
|
|
6089
6148
|
return downlevelTable.query(req);
|
|
6090
6149
|
}
|
|
6091
|
-
return downlevelTable.query(req).then(result => {
|
|
6150
|
+
return downlevelTable.query(req).then((result) => {
|
|
6092
6151
|
if (!result.result || !Array.isArray(result.result))
|
|
6093
6152
|
return result;
|
|
6094
6153
|
// Check if any results need resolution
|
|
6095
|
-
const needsResolution = result.result.some(r => r && hasUnresolvedBlobRefs(r));
|
|
6154
|
+
const needsResolution = result.result.some((r) => r && hasUnresolvedBlobRefs(r));
|
|
6096
6155
|
if (!needsResolution)
|
|
6097
6156
|
return result;
|
|
6098
|
-
return Dexie.Promise.all(result.result.map(item => {
|
|
6157
|
+
return Dexie.Promise.all(result.result.map((item) => {
|
|
6099
6158
|
if (item && hasUnresolvedBlobRefs(item)) {
|
|
6100
6159
|
return resolveAndSave(downlevelTable, req.trans, undefined, item, blobSavingQueue, db);
|
|
6101
6160
|
}
|
|
6102
6161
|
return item;
|
|
6103
|
-
})).then(resolved => (Object.assign(Object.assign({}, result), { result: resolved })));
|
|
6162
|
+
})).then((resolved) => (Object.assign(Object.assign({}, result), { result: resolved })));
|
|
6104
6163
|
});
|
|
6105
6164
|
},
|
|
6106
6165
|
openCursor(req) {
|
|
@@ -6108,7 +6167,7 @@ function createBlobResolveMiddleware(db) {
|
|
|
6108
6167
|
if ((_a = req.trans) === null || _a === void 0 ? void 0 : _a.disableBlobResolve) {
|
|
6109
6168
|
return downlevelTable.openCursor(req);
|
|
6110
6169
|
}
|
|
6111
|
-
return downlevelTable.openCursor(req).then(cursor => {
|
|
6170
|
+
return downlevelTable.openCursor(req).then((cursor) => {
|
|
6112
6171
|
if (!cursor)
|
|
6113
6172
|
return cursor; // No results, so no resolution needed
|
|
6114
6173
|
if (!req.values)
|
|
@@ -6138,7 +6197,7 @@ function createBlobResolvingCursor(cursor, table, blobSavingQueue, db) {
|
|
|
6138
6197
|
value: {
|
|
6139
6198
|
value: cursor.value,
|
|
6140
6199
|
enumerable: true,
|
|
6141
|
-
writable: true
|
|
6200
|
+
writable: true,
|
|
6142
6201
|
},
|
|
6143
6202
|
start: {
|
|
6144
6203
|
value(onNext) {
|
|
@@ -6150,17 +6209,17 @@ function createBlobResolvingCursor(cursor, table, blobSavingQueue, db) {
|
|
|
6150
6209
|
onNext();
|
|
6151
6210
|
return;
|
|
6152
6211
|
}
|
|
6153
|
-
resolveAndSave(table, cursor.trans, cursor.primaryKey, rawValue, blobSavingQueue, db, true).then(resolved => {
|
|
6212
|
+
resolveAndSave(table, cursor.trans, cursor.primaryKey, rawValue, blobSavingQueue, db, true).then((resolved) => {
|
|
6154
6213
|
wrappedCursor.value = resolved;
|
|
6155
6214
|
onNext();
|
|
6156
|
-
}, err => {
|
|
6215
|
+
}, (err) => {
|
|
6157
6216
|
console.error('Failed to resolve BlobRefs for cursor value:', err);
|
|
6158
6217
|
wrappedCursor.value = rawValue;
|
|
6159
6218
|
onNext();
|
|
6160
6219
|
});
|
|
6161
6220
|
});
|
|
6162
|
-
}
|
|
6163
|
-
}
|
|
6221
|
+
},
|
|
6222
|
+
},
|
|
6164
6223
|
});
|
|
6165
6224
|
return wrappedCursor;
|
|
6166
6225
|
}
|
|
@@ -6205,12 +6264,15 @@ obj, blobSavingQueue, db, isCursorValue = false // Flag to indicate if we're res
|
|
|
6205
6264
|
const resolvePromise = needsWaitFor
|
|
6206
6265
|
? Dexie.waitFor(resolutionPromise)
|
|
6207
6266
|
: Dexie.Promise.resolve(resolutionPromise);
|
|
6208
|
-
return resolvePromise
|
|
6267
|
+
return resolvePromise
|
|
6268
|
+
.then((resolved) => {
|
|
6209
6269
|
// Get primary key from the object
|
|
6210
6270
|
const primaryKey = table.schema.primaryKey;
|
|
6211
|
-
const key = pKey !== undefined
|
|
6212
|
-
?
|
|
6213
|
-
:
|
|
6271
|
+
const key = pKey !== undefined
|
|
6272
|
+
? pKey
|
|
6273
|
+
: primaryKey.keyPath
|
|
6274
|
+
? Dexie.getByKeyPath(obj, primaryKey.keyPath)
|
|
6275
|
+
: undefined;
|
|
6214
6276
|
if (key !== undefined) {
|
|
6215
6277
|
// Queue each resolved blob individually for atomic update
|
|
6216
6278
|
// This uses setTimeout(fn, 0) to completely isolate from
|
|
@@ -6221,13 +6283,16 @@ obj, blobSavingQueue, db, isCursorValue = false // Flag to indicate if we're res
|
|
|
6221
6283
|
else {
|
|
6222
6284
|
// For rw transactions, we can save directly without queueing
|
|
6223
6285
|
// since we're still in the same transaction context
|
|
6224
|
-
table
|
|
6286
|
+
table
|
|
6287
|
+
.mutate({ type: 'put', keys: [key], values: [resolved], trans })
|
|
6288
|
+
.catch((err) => {
|
|
6225
6289
|
console.error(`Failed to save resolved blob on ${table.name}:${key}:`, err);
|
|
6226
6290
|
});
|
|
6227
6291
|
}
|
|
6228
6292
|
}
|
|
6229
6293
|
return resolved;
|
|
6230
|
-
})
|
|
6294
|
+
})
|
|
6295
|
+
.catch((err) => {
|
|
6231
6296
|
console.error(`[dexie-cloud:blobResolve] Failed to resolve BlobRefs on ${table.name}:`, err);
|
|
6232
6297
|
return obj; // Return original object on error - never block the read pipeline
|
|
6233
6298
|
});
|
|
@@ -6256,9 +6321,13 @@ function overrideParseStoresSpec(origFunc, dexie) {
|
|
|
6256
6321
|
return; // Continue
|
|
6257
6322
|
}
|
|
6258
6323
|
// They have declared this table. Merge indexes in case they didn't declare all indexes we need.
|
|
6259
|
-
const requestedIndexes = schemaSrc
|
|
6260
|
-
|
|
6261
|
-
|
|
6324
|
+
const requestedIndexes = schemaSrc
|
|
6325
|
+
.split(',')
|
|
6326
|
+
.map((spec) => spec.trim());
|
|
6327
|
+
const builtInIndexes = DEXIE_CLOUD_SCHEMA[tableName]
|
|
6328
|
+
.split(',')
|
|
6329
|
+
.map((spec) => spec.trim());
|
|
6330
|
+
const requestedIndexSet = new Set(requestedIndexes.map((index) => index.replace(/([&*]|\+\+)/g, '')));
|
|
6262
6331
|
// Verify that primary key is unchanged
|
|
6263
6332
|
if (requestedIndexes[0] !== builtInIndexes[0]) {
|
|
6264
6333
|
// Primary key must match exactly
|
|
@@ -6267,7 +6336,7 @@ function overrideParseStoresSpec(origFunc, dexie) {
|
|
|
6267
6336
|
// Merge indexes
|
|
6268
6337
|
for (let i = 1; i < builtInIndexes.length; ++i) {
|
|
6269
6338
|
const builtInIndex = builtInIndexes[i];
|
|
6270
|
-
if (!requestedIndexSet.has(builtInIndex.replace(/([&*]|\+\+)/g,
|
|
6339
|
+
if (!requestedIndexSet.has(builtInIndex.replace(/([&*]|\+\+)/g, ''))) {
|
|
6271
6340
|
// Add built-in index if not already requested
|
|
6272
6341
|
storesClone[tableName] += `,${builtInIndex}`;
|
|
6273
6342
|
}
|
|
@@ -6276,7 +6345,7 @@ function overrideParseStoresSpec(origFunc, dexie) {
|
|
|
6276
6345
|
// Populate dexie.cloud.schema
|
|
6277
6346
|
const cloudSchema = dexie.cloud.schema || (dexie.cloud.schema = {});
|
|
6278
6347
|
const allPrefixes = new Set();
|
|
6279
|
-
Object.keys(storesClone).forEach(tableName => {
|
|
6348
|
+
Object.keys(storesClone).forEach((tableName) => {
|
|
6280
6349
|
var _a;
|
|
6281
6350
|
const schemaSrc = (_a = storesClone[tableName]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
6282
6351
|
const cloudTableSchema = cloudSchema[tableName] || (cloudSchema[tableName] = {});
|
|
@@ -6405,7 +6474,7 @@ if (typeof document !== 'undefined') {
|
|
|
6405
6474
|
class TokenExpiredError extends Error {
|
|
6406
6475
|
constructor() {
|
|
6407
6476
|
super(...arguments);
|
|
6408
|
-
this.name =
|
|
6477
|
+
this.name = 'TokenExpiredError';
|
|
6409
6478
|
}
|
|
6410
6479
|
}
|
|
6411
6480
|
|
|
@@ -6629,7 +6698,7 @@ class WSConnection extends Subscription {
|
|
|
6629
6698
|
// Connect the WebSocket to given url:
|
|
6630
6699
|
console.debug('dexie-cloud WebSocket create');
|
|
6631
6700
|
const ws = (this.ws = new WebSocket(`${wsUrl}/changes?${searchParams}`));
|
|
6632
|
-
ws.binaryType =
|
|
6701
|
+
ws.binaryType = 'arraybuffer';
|
|
6633
6702
|
ws.onclose = (event) => {
|
|
6634
6703
|
if (!this.pinger)
|
|
6635
6704
|
return;
|
|
@@ -6668,10 +6737,17 @@ class WSConnection extends Subscription {
|
|
|
6668
6737
|
getOpenDocSignal(doc).next(); // Make yHandler reopen the document on server.
|
|
6669
6738
|
}
|
|
6670
6739
|
}
|
|
6671
|
-
else if (msg.type === 'u-ack' ||
|
|
6740
|
+
else if (msg.type === 'u-ack' ||
|
|
6741
|
+
msg.type === 'u-reject' ||
|
|
6742
|
+
msg.type === 'u-s' ||
|
|
6743
|
+
msg.type === 'in-sync' ||
|
|
6744
|
+
msg.type === 'outdated-server-rev' ||
|
|
6745
|
+
msg.type === 'y-complete-sync-done') {
|
|
6672
6746
|
applyYServerMessages([msg], this.db).then((_a) => __awaiter(this, [_a], void 0, function* ({ resyncNeeded, yServerRevision, receivedUntils }) {
|
|
6673
6747
|
if (yServerRevision) {
|
|
6674
|
-
yield this.db.$syncState.update('syncState', {
|
|
6748
|
+
yield this.db.$syncState.update('syncState', {
|
|
6749
|
+
yServerRevision: yServerRevision,
|
|
6750
|
+
});
|
|
6675
6751
|
}
|
|
6676
6752
|
if (msg.type === 'u-s' && receivedUntils) {
|
|
6677
6753
|
const utbl = getUpdatesTable(this.db, msg.table, msg.prop);
|
|
@@ -6874,7 +6950,9 @@ function isSyncNeeded(db) {
|
|
|
6874
6950
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6875
6951
|
var _a;
|
|
6876
6952
|
return ((_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.databaseUrl) && db.cloud.schema
|
|
6877
|
-
? yield sync(db, db.cloud.options, db.cloud.schema, {
|
|
6953
|
+
? yield sync(db, db.cloud.options, db.cloud.schema, {
|
|
6954
|
+
justCheckIfNeeded: true,
|
|
6955
|
+
})
|
|
6878
6956
|
: false;
|
|
6879
6957
|
});
|
|
6880
6958
|
}
|
|
@@ -7086,243 +7164,243 @@ var n,l$1,u$1,i$1,r$1,o$1,e$1,f$1,c$1,s$1,a$1,p$1={},v$1=[],y=/acit|ex(?:s|g|n|p
|
|
|
7086
7164
|
const Styles = {
|
|
7087
7165
|
Alert: {
|
|
7088
7166
|
error: {
|
|
7089
|
-
color:
|
|
7090
|
-
fontWeight:
|
|
7167
|
+
color: 'red',
|
|
7168
|
+
fontWeight: 'bold',
|
|
7091
7169
|
},
|
|
7092
7170
|
warning: {
|
|
7093
|
-
color:
|
|
7094
|
-
fontWeight:
|
|
7171
|
+
color: '#f80',
|
|
7172
|
+
fontWeight: 'bold',
|
|
7095
7173
|
},
|
|
7096
7174
|
info: {
|
|
7097
|
-
color:
|
|
7098
|
-
}
|
|
7175
|
+
color: 'black',
|
|
7176
|
+
},
|
|
7099
7177
|
},
|
|
7100
7178
|
Darken: {
|
|
7101
|
-
position:
|
|
7179
|
+
position: 'fixed',
|
|
7102
7180
|
top: 0,
|
|
7103
7181
|
left: 0,
|
|
7104
7182
|
opacity: 0.5,
|
|
7105
|
-
backgroundColor:
|
|
7106
|
-
width:
|
|
7107
|
-
height:
|
|
7183
|
+
backgroundColor: '#000',
|
|
7184
|
+
width: '100vw',
|
|
7185
|
+
height: '100vh',
|
|
7108
7186
|
zIndex: 150,
|
|
7109
|
-
webkitBackdropFilter:
|
|
7110
|
-
backdropFilter:
|
|
7187
|
+
webkitBackdropFilter: 'blur(2px)',
|
|
7188
|
+
backdropFilter: 'blur(2px)',
|
|
7111
7189
|
},
|
|
7112
7190
|
DialogOuter: {
|
|
7113
|
-
position:
|
|
7191
|
+
position: 'fixed',
|
|
7114
7192
|
top: 0,
|
|
7115
7193
|
left: 0,
|
|
7116
|
-
width:
|
|
7117
|
-
height:
|
|
7194
|
+
width: '100vw',
|
|
7195
|
+
height: '100vh',
|
|
7118
7196
|
zIndex: 150,
|
|
7119
|
-
alignItems:
|
|
7120
|
-
display:
|
|
7121
|
-
justifyContent:
|
|
7122
|
-
padding:
|
|
7123
|
-
boxSizing:
|
|
7197
|
+
alignItems: 'center',
|
|
7198
|
+
display: 'flex',
|
|
7199
|
+
justifyContent: 'center',
|
|
7200
|
+
padding: '16px',
|
|
7201
|
+
boxSizing: 'border-box',
|
|
7124
7202
|
},
|
|
7125
7203
|
DialogInner: {
|
|
7126
|
-
position:
|
|
7127
|
-
color:
|
|
7128
|
-
backgroundColor:
|
|
7129
|
-
padding:
|
|
7130
|
-
marginBottom:
|
|
7131
|
-
maxWidth:
|
|
7132
|
-
width:
|
|
7133
|
-
maxHeight:
|
|
7134
|
-
overflowY:
|
|
7135
|
-
border:
|
|
7136
|
-
borderRadius:
|
|
7137
|
-
boxShadow:
|
|
7138
|
-
fontFamily:
|
|
7139
|
-
boxSizing:
|
|
7204
|
+
position: 'relative',
|
|
7205
|
+
color: '#222',
|
|
7206
|
+
backgroundColor: '#fff',
|
|
7207
|
+
padding: '24px',
|
|
7208
|
+
marginBottom: '2em',
|
|
7209
|
+
maxWidth: '400px',
|
|
7210
|
+
width: '100%',
|
|
7211
|
+
maxHeight: '90%',
|
|
7212
|
+
overflowY: 'auto',
|
|
7213
|
+
border: '3px solid #3d3d5d',
|
|
7214
|
+
borderRadius: '8px',
|
|
7215
|
+
boxShadow: '0 0 80px 10px #666',
|
|
7216
|
+
fontFamily: 'sans-serif',
|
|
7217
|
+
boxSizing: 'border-box',
|
|
7140
7218
|
},
|
|
7141
7219
|
Input: {
|
|
7142
|
-
height:
|
|
7143
|
-
width:
|
|
7144
|
-
maxWidth:
|
|
7145
|
-
borderColor:
|
|
7146
|
-
outline:
|
|
7147
|
-
fontSize:
|
|
7148
|
-
padding:
|
|
7149
|
-
boxSizing:
|
|
7150
|
-
backgroundColor:
|
|
7151
|
-
borderRadius:
|
|
7152
|
-
border:
|
|
7153
|
-
marginTop:
|
|
7154
|
-
fontFamily:
|
|
7220
|
+
height: '35px',
|
|
7221
|
+
width: '100%',
|
|
7222
|
+
maxWidth: '100%',
|
|
7223
|
+
borderColor: '#ccf4',
|
|
7224
|
+
outline: 'none',
|
|
7225
|
+
fontSize: '16px',
|
|
7226
|
+
padding: '8px',
|
|
7227
|
+
boxSizing: 'border-box',
|
|
7228
|
+
backgroundColor: '#f9f9f9',
|
|
7229
|
+
borderRadius: '4px',
|
|
7230
|
+
border: '1px solid #ccc',
|
|
7231
|
+
marginTop: '6px',
|
|
7232
|
+
fontFamily: 'inherit',
|
|
7155
7233
|
},
|
|
7156
7234
|
Button: {
|
|
7157
|
-
padding:
|
|
7158
|
-
margin:
|
|
7159
|
-
border:
|
|
7160
|
-
borderRadius:
|
|
7161
|
-
backgroundColor:
|
|
7162
|
-
cursor:
|
|
7163
|
-
fontSize:
|
|
7164
|
-
fontWeight:
|
|
7165
|
-
color:
|
|
7166
|
-
transition:
|
|
7235
|
+
padding: '10px 20px',
|
|
7236
|
+
margin: '0 4px',
|
|
7237
|
+
border: '1px solid #d1d5db',
|
|
7238
|
+
borderRadius: '6px',
|
|
7239
|
+
backgroundColor: '#ffffff',
|
|
7240
|
+
cursor: 'pointer',
|
|
7241
|
+
fontSize: '14px',
|
|
7242
|
+
fontWeight: '500',
|
|
7243
|
+
color: '#374151',
|
|
7244
|
+
transition: 'all 0.2s ease',
|
|
7167
7245
|
},
|
|
7168
7246
|
PrimaryButton: {
|
|
7169
|
-
padding:
|
|
7170
|
-
margin:
|
|
7171
|
-
border:
|
|
7172
|
-
borderRadius:
|
|
7173
|
-
backgroundColor:
|
|
7174
|
-
color:
|
|
7175
|
-
cursor:
|
|
7176
|
-
fontSize:
|
|
7177
|
-
fontWeight:
|
|
7178
|
-
transition:
|
|
7247
|
+
padding: '10px 20px',
|
|
7248
|
+
margin: '0 4px',
|
|
7249
|
+
border: '1px solid #3b82f6',
|
|
7250
|
+
borderRadius: '6px',
|
|
7251
|
+
backgroundColor: '#3b82f6',
|
|
7252
|
+
color: 'white',
|
|
7253
|
+
cursor: 'pointer',
|
|
7254
|
+
fontSize: '14px',
|
|
7255
|
+
fontWeight: '500',
|
|
7256
|
+
transition: 'all 0.2s ease',
|
|
7179
7257
|
},
|
|
7180
7258
|
ButtonsDiv: {
|
|
7181
|
-
display:
|
|
7182
|
-
justifyContent:
|
|
7183
|
-
gap:
|
|
7184
|
-
marginTop:
|
|
7185
|
-
paddingTop:
|
|
7259
|
+
display: 'flex',
|
|
7260
|
+
justifyContent: 'flex-end',
|
|
7261
|
+
gap: '12px',
|
|
7262
|
+
marginTop: '24px',
|
|
7263
|
+
paddingTop: '20px',
|
|
7186
7264
|
},
|
|
7187
7265
|
Label: {
|
|
7188
|
-
display:
|
|
7189
|
-
marginBottom:
|
|
7190
|
-
fontSize:
|
|
7191
|
-
fontWeight:
|
|
7192
|
-
color:
|
|
7266
|
+
display: 'block',
|
|
7267
|
+
marginBottom: '12px',
|
|
7268
|
+
fontSize: '14px',
|
|
7269
|
+
fontWeight: '500',
|
|
7270
|
+
color: '#333',
|
|
7193
7271
|
},
|
|
7194
7272
|
WindowHeader: {
|
|
7195
|
-
margin:
|
|
7196
|
-
fontSize:
|
|
7197
|
-
fontWeight:
|
|
7198
|
-
color:
|
|
7199
|
-
borderBottom:
|
|
7200
|
-
paddingBottom:
|
|
7273
|
+
margin: '0 0 20px 0',
|
|
7274
|
+
fontSize: '18px',
|
|
7275
|
+
fontWeight: '600',
|
|
7276
|
+
color: '#333',
|
|
7277
|
+
borderBottom: '1px solid #eee',
|
|
7278
|
+
paddingBottom: '10px',
|
|
7201
7279
|
},
|
|
7202
7280
|
// OAuth Provider Button Styles
|
|
7203
7281
|
ProviderButton: {
|
|
7204
|
-
display:
|
|
7205
|
-
alignItems:
|
|
7206
|
-
justifyContent:
|
|
7207
|
-
width:
|
|
7208
|
-
padding:
|
|
7209
|
-
marginBottom:
|
|
7210
|
-
border:
|
|
7211
|
-
borderRadius:
|
|
7212
|
-
backgroundColor:
|
|
7213
|
-
cursor:
|
|
7214
|
-
fontSize:
|
|
7215
|
-
fontWeight:
|
|
7216
|
-
color:
|
|
7217
|
-
transition:
|
|
7218
|
-
gap:
|
|
7282
|
+
display: 'flex',
|
|
7283
|
+
alignItems: 'center',
|
|
7284
|
+
justifyContent: 'center',
|
|
7285
|
+
width: '100%',
|
|
7286
|
+
padding: '12px 16px',
|
|
7287
|
+
marginBottom: '10px',
|
|
7288
|
+
border: '1px solid #d1d5db',
|
|
7289
|
+
borderRadius: '6px',
|
|
7290
|
+
backgroundColor: '#ffffff',
|
|
7291
|
+
cursor: 'pointer',
|
|
7292
|
+
fontSize: '14px',
|
|
7293
|
+
fontWeight: '500',
|
|
7294
|
+
color: '#374151',
|
|
7295
|
+
transition: 'all 0.2s ease',
|
|
7296
|
+
gap: '12px',
|
|
7219
7297
|
},
|
|
7220
7298
|
ProviderButtonIcon: {
|
|
7221
|
-
width:
|
|
7222
|
-
height:
|
|
7299
|
+
width: '20px',
|
|
7300
|
+
height: '20px',
|
|
7223
7301
|
flexShrink: 0,
|
|
7224
|
-
display:
|
|
7225
|
-
alignItems:
|
|
7226
|
-
justifyContent:
|
|
7302
|
+
display: 'flex',
|
|
7303
|
+
alignItems: 'center',
|
|
7304
|
+
justifyContent: 'center',
|
|
7227
7305
|
},
|
|
7228
7306
|
ProviderButtonText: {
|
|
7229
7307
|
flex: 1,
|
|
7230
|
-
textAlign:
|
|
7308
|
+
textAlign: 'left',
|
|
7231
7309
|
},
|
|
7232
7310
|
// Provider-specific colors
|
|
7233
7311
|
ProviderGoogle: {
|
|
7234
|
-
backgroundColor:
|
|
7235
|
-
border:
|
|
7236
|
-
color:
|
|
7312
|
+
backgroundColor: '#ffffff',
|
|
7313
|
+
border: '1px solid #dadce0',
|
|
7314
|
+
color: '#3c4043',
|
|
7237
7315
|
},
|
|
7238
7316
|
ProviderGitHub: {
|
|
7239
|
-
backgroundColor:
|
|
7240
|
-
border:
|
|
7241
|
-
color:
|
|
7317
|
+
backgroundColor: '#ffffff',
|
|
7318
|
+
border: '1px solid #dadce0',
|
|
7319
|
+
color: '#181717',
|
|
7242
7320
|
},
|
|
7243
7321
|
ProviderMicrosoft: {
|
|
7244
|
-
backgroundColor:
|
|
7245
|
-
border:
|
|
7246
|
-
color:
|
|
7322
|
+
backgroundColor: '#ffffff',
|
|
7323
|
+
border: '1px solid #dadce0',
|
|
7324
|
+
color: '#5e5e5e',
|
|
7247
7325
|
},
|
|
7248
7326
|
ProviderApple: {
|
|
7249
|
-
backgroundColor:
|
|
7250
|
-
border:
|
|
7251
|
-
color:
|
|
7327
|
+
backgroundColor: '#000000',
|
|
7328
|
+
border: '1px solid #000000',
|
|
7329
|
+
color: '#ffffff',
|
|
7252
7330
|
},
|
|
7253
7331
|
ProviderCustom: {
|
|
7254
|
-
backgroundColor:
|
|
7255
|
-
border:
|
|
7256
|
-
color:
|
|
7332
|
+
backgroundColor: '#ffffff',
|
|
7333
|
+
border: '1px solid #dadce0',
|
|
7334
|
+
color: '#181717',
|
|
7257
7335
|
},
|
|
7258
7336
|
// Divider styles
|
|
7259
7337
|
Divider: {
|
|
7260
|
-
display:
|
|
7261
|
-
alignItems:
|
|
7262
|
-
margin:
|
|
7263
|
-
color:
|
|
7264
|
-
fontSize:
|
|
7338
|
+
display: 'flex',
|
|
7339
|
+
alignItems: 'center',
|
|
7340
|
+
margin: '20px 0',
|
|
7341
|
+
color: '#6b7280',
|
|
7342
|
+
fontSize: '13px',
|
|
7265
7343
|
},
|
|
7266
7344
|
DividerLine: {
|
|
7267
7345
|
flex: 1,
|
|
7268
|
-
height:
|
|
7269
|
-
backgroundColor:
|
|
7346
|
+
height: '1px',
|
|
7347
|
+
backgroundColor: '#e5e7eb',
|
|
7270
7348
|
},
|
|
7271
7349
|
DividerText: {
|
|
7272
|
-
padding:
|
|
7273
|
-
color:
|
|
7350
|
+
padding: '0 12px',
|
|
7351
|
+
color: '#9ca3af',
|
|
7274
7352
|
},
|
|
7275
7353
|
// OTP Button (Continue with email)
|
|
7276
7354
|
OtpButton: {
|
|
7277
|
-
display:
|
|
7278
|
-
alignItems:
|
|
7279
|
-
justifyContent:
|
|
7280
|
-
width:
|
|
7281
|
-
padding:
|
|
7282
|
-
border:
|
|
7283
|
-
borderRadius:
|
|
7284
|
-
backgroundColor:
|
|
7285
|
-
cursor:
|
|
7286
|
-
fontSize:
|
|
7287
|
-
fontWeight:
|
|
7288
|
-
color:
|
|
7289
|
-
transition:
|
|
7290
|
-
gap:
|
|
7355
|
+
display: 'flex',
|
|
7356
|
+
alignItems: 'center',
|
|
7357
|
+
justifyContent: 'center',
|
|
7358
|
+
width: '100%',
|
|
7359
|
+
padding: '12px 16px',
|
|
7360
|
+
border: '1px solid #d1d5db',
|
|
7361
|
+
borderRadius: '6px',
|
|
7362
|
+
backgroundColor: '#f9fafb',
|
|
7363
|
+
cursor: 'pointer',
|
|
7364
|
+
fontSize: '14px',
|
|
7365
|
+
fontWeight: '500',
|
|
7366
|
+
color: '#374151',
|
|
7367
|
+
transition: 'all 0.2s ease',
|
|
7368
|
+
gap: '12px',
|
|
7291
7369
|
},
|
|
7292
7370
|
// Copy button for alerts with copyText
|
|
7293
7371
|
CopyButton: {
|
|
7294
|
-
display:
|
|
7295
|
-
alignItems:
|
|
7296
|
-
gap:
|
|
7297
|
-
padding:
|
|
7298
|
-
marginTop:
|
|
7299
|
-
border:
|
|
7300
|
-
borderRadius:
|
|
7301
|
-
backgroundColor:
|
|
7302
|
-
cursor:
|
|
7303
|
-
fontSize:
|
|
7304
|
-
fontWeight:
|
|
7305
|
-
color:
|
|
7306
|
-
transition:
|
|
7307
|
-
fontFamily:
|
|
7372
|
+
display: 'inline-flex',
|
|
7373
|
+
alignItems: 'center',
|
|
7374
|
+
gap: '4px',
|
|
7375
|
+
padding: '4px 10px',
|
|
7376
|
+
marginTop: '8px',
|
|
7377
|
+
border: '1px solid #d1d5db',
|
|
7378
|
+
borderRadius: '4px',
|
|
7379
|
+
backgroundColor: '#f9fafb',
|
|
7380
|
+
cursor: 'pointer',
|
|
7381
|
+
fontSize: '12px',
|
|
7382
|
+
fontWeight: '500',
|
|
7383
|
+
color: '#374151',
|
|
7384
|
+
transition: 'all 0.15s ease',
|
|
7385
|
+
fontFamily: 'monospace',
|
|
7308
7386
|
},
|
|
7309
7387
|
CopyButtonCopied: {
|
|
7310
|
-
display:
|
|
7311
|
-
alignItems:
|
|
7312
|
-
gap:
|
|
7313
|
-
padding:
|
|
7314
|
-
marginTop:
|
|
7315
|
-
border:
|
|
7316
|
-
borderRadius:
|
|
7317
|
-
backgroundColor:
|
|
7318
|
-
cursor:
|
|
7319
|
-
fontSize:
|
|
7320
|
-
fontWeight:
|
|
7321
|
-
color:
|
|
7322
|
-
fontFamily:
|
|
7388
|
+
display: 'inline-flex',
|
|
7389
|
+
alignItems: 'center',
|
|
7390
|
+
gap: '4px',
|
|
7391
|
+
padding: '4px 10px',
|
|
7392
|
+
marginTop: '8px',
|
|
7393
|
+
border: '1px solid #22c55e',
|
|
7394
|
+
borderRadius: '4px',
|
|
7395
|
+
backgroundColor: '#f0fdf4',
|
|
7396
|
+
cursor: 'default',
|
|
7397
|
+
fontSize: '12px',
|
|
7398
|
+
fontWeight: '500',
|
|
7399
|
+
color: '#16a34a',
|
|
7400
|
+
fontFamily: 'monospace',
|
|
7323
7401
|
}};
|
|
7324
7402
|
|
|
7325
|
-
function Dialog({ children, className }) {
|
|
7403
|
+
function Dialog({ children, className, }) {
|
|
7326
7404
|
return (_$1("div", { className: `dexie-dialog ${className || ''}` },
|
|
7327
7405
|
_$1("div", { style: Styles.Darken }),
|
|
7328
7406
|
_$1("div", { style: Styles.DialogOuter },
|
|
@@ -7346,7 +7424,7 @@ var t,r,u,i,o=0,f=[],c=l$1,e=c.__b,a=c.__r,v=c.diffed,l=c.__c,m=c.unmount,s=c.__
|
|
|
7346
7424
|
* @returns A final message where parameters have been replaced with values.
|
|
7347
7425
|
*/
|
|
7348
7426
|
function resolveText({ message, messageCode, messageParams }) {
|
|
7349
|
-
return message.replace(/\{\w+\}/
|
|
7427
|
+
return message.replace(/\{\w+\}/gi, (n) => messageParams[n.substring(1, n.length - 1)]);
|
|
7350
7428
|
}
|
|
7351
7429
|
|
|
7352
7430
|
/** Get style based on styleHint (for provider branding, etc.) */
|
|
@@ -7433,13 +7511,13 @@ function LoginDialog({ title, alerts, fields, options, submitLabel, cancelLabel,
|
|
|
7433
7511
|
alerts.map((alert, idx) => (_$1("div", { key: idx },
|
|
7434
7512
|
_$1("p", { style: Styles.Alert[alert.type] }, resolveText(alert)),
|
|
7435
7513
|
alert.copyText && _$1(CopyButton, { text: alert.copyText })))),
|
|
7436
|
-
hasOptions && (_$1("div", { class: "dxc-options" }, hasMultipleGroups
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7441
|
-
|
|
7442
|
-
|
|
7514
|
+
hasOptions && (_$1("div", { class: "dxc-options" }, hasMultipleGroups
|
|
7515
|
+
? // Render with dividers between groups
|
|
7516
|
+
Array.from(optionGroups.entries()).map(([groupName, groupOptions], groupIdx) => (_$1(k$1, { key: groupName },
|
|
7517
|
+
groupIdx > 0 && _$1(Divider, null),
|
|
7518
|
+
groupOptions.map((option) => (_$1(OptionButton, { key: `${option.name}-${option.value}`, option: option, onClick: () => handleOptionClick(option) }))))))
|
|
7519
|
+
: // Simple case: all options in one group
|
|
7520
|
+
options.map((option) => (_$1(OptionButton, { key: `${option.name}-${option.value}`, option: option, onClick: () => handleOptionClick(option) }))))),
|
|
7443
7521
|
hasOptions && hasFields && _$1(Divider, null),
|
|
7444
7522
|
hasFields && (_$1("form", { onSubmit: (ev) => {
|
|
7445
7523
|
ev.preventDefault();
|
|
@@ -7451,7 +7529,8 @@ function LoginDialog({ title, alerts, fields, options, submitLabel, cancelLabel,
|
|
|
7451
7529
|
const value = valueTransformer(type, (_a = ev.target) === null || _a === void 0 ? void 0 : _a['value']);
|
|
7452
7530
|
let updatedParams = Object.assign(Object.assign({}, params), { [fieldName]: value });
|
|
7453
7531
|
setParams(updatedParams);
|
|
7454
|
-
if (type === 'otp' &&
|
|
7532
|
+
if (type === 'otp' &&
|
|
7533
|
+
(value === null || value === void 0 ? void 0 : value.trim().length) === OTP_LENGTH) {
|
|
7455
7534
|
// Auto-submit when OTP is filled in.
|
|
7456
7535
|
onSubmit(updatedParams);
|
|
7457
7536
|
}
|
|
@@ -7493,7 +7572,10 @@ function CopyButton({ text }) {
|
|
|
7493
7572
|
const handleClick = () => {
|
|
7494
7573
|
var _a;
|
|
7495
7574
|
if (typeof navigator !== 'undefined' && ((_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText)) {
|
|
7496
|
-
navigator.clipboard
|
|
7575
|
+
navigator.clipboard
|
|
7576
|
+
.writeText(text)
|
|
7577
|
+
.then(scheduleCopiedReset)
|
|
7578
|
+
.catch(() => {
|
|
7497
7579
|
fallbackCopy(text, scheduleCopiedReset);
|
|
7498
7580
|
});
|
|
7499
7581
|
}
|
|
@@ -7564,7 +7646,7 @@ function setupDefaultGUI(db) {
|
|
|
7564
7646
|
},
|
|
7565
7647
|
get closed() {
|
|
7566
7648
|
return closed;
|
|
7567
|
-
}
|
|
7649
|
+
},
|
|
7568
7650
|
};
|
|
7569
7651
|
}
|
|
7570
7652
|
|
|
@@ -7609,14 +7691,14 @@ function computeSyncState(db) {
|
|
|
7609
7691
|
lazyWebSocketStatus,
|
|
7610
7692
|
db.syncStateChangedEvent.pipe(startWith({ phase: 'initial' })),
|
|
7611
7693
|
getCurrentUserEmitter(db.dx._novip),
|
|
7612
|
-
userIsReallyActive
|
|
7694
|
+
userIsReallyActive,
|
|
7613
7695
|
]).pipe(map(([status, syncState, user, userIsActive]) => {
|
|
7614
7696
|
var _a;
|
|
7615
7697
|
if (((_a = user.license) === null || _a === void 0 ? void 0 : _a.status) && user.license.status !== 'ok') {
|
|
7616
7698
|
return {
|
|
7617
7699
|
phase: 'offline',
|
|
7618
7700
|
status: 'offline',
|
|
7619
|
-
license: user.license.status
|
|
7701
|
+
license: user.license.status,
|
|
7620
7702
|
};
|
|
7621
7703
|
}
|
|
7622
7704
|
let { phase, error, progress } = syncState;
|
|
@@ -7636,7 +7718,8 @@ function computeSyncState(db) {
|
|
|
7636
7718
|
}
|
|
7637
7719
|
const previousPhase = db.cloud.syncState.value.phase;
|
|
7638
7720
|
//const previousStatus = db.cloud.syncState.value.status;
|
|
7639
|
-
if (previousPhase === 'error' &&
|
|
7721
|
+
if (previousPhase === 'error' &&
|
|
7722
|
+
(syncState.phase === 'pushing' || syncState.phase === 'pulling')) {
|
|
7640
7723
|
// We were in an errored state but is now doing sync. Show "connecting" icon.
|
|
7641
7724
|
adjustedStatus = 'connecting';
|
|
7642
7725
|
}
|
|
@@ -7651,7 +7734,7 @@ function computeSyncState(db) {
|
|
|
7651
7734
|
error,
|
|
7652
7735
|
progress,
|
|
7653
7736
|
status: isOnline ? adjustedStatus : 'offline',
|
|
7654
|
-
license: 'ok'
|
|
7737
|
+
license: 'ok',
|
|
7655
7738
|
};
|
|
7656
7739
|
return retState;
|
|
7657
7740
|
}));
|
|
@@ -7672,7 +7755,7 @@ function createSharedValueObservable(o, defaultValue) {
|
|
|
7672
7755
|
},
|
|
7673
7756
|
complete() {
|
|
7674
7757
|
observer.complete();
|
|
7675
|
-
}
|
|
7758
|
+
},
|
|
7676
7759
|
});
|
|
7677
7760
|
if (!didEmit && !subscription.closed) {
|
|
7678
7761
|
observer.next(currentValue);
|
|
@@ -7913,7 +7996,9 @@ function permissions(dexie, obj, tableName) {
|
|
|
7913
7996
|
const realm = permissionsLookup[realmId || dexie.cloud.currentUserId];
|
|
7914
7997
|
if (!realm)
|
|
7915
7998
|
return new PermissionChecker({}, tableName, !owner || owner === dexie.cloud.currentUserId);
|
|
7916
|
-
return new PermissionChecker(realm.permissions, tableName, realmId === undefined ||
|
|
7999
|
+
return new PermissionChecker(realm.permissions, tableName, realmId === undefined ||
|
|
8000
|
+
realmId === dexie.cloud.currentUserId ||
|
|
8001
|
+
owner === dexie.cloud.currentUserId);
|
|
7917
8002
|
};
|
|
7918
8003
|
const o = source.pipe(map(mapper));
|
|
7919
8004
|
o.getValue = () => mapper(source.getValue());
|
|
@@ -7955,7 +8040,19 @@ function createYHandler(db) {
|
|
|
7955
8040
|
return; // The table that holds the doc is not marked for sync - leave it to dexie. No syncing, no awareness.
|
|
7956
8041
|
}
|
|
7957
8042
|
let awareness;
|
|
8043
|
+
const existingDescriptor = Object.getOwnPropertyDescriptor(provider, 'awareness');
|
|
8044
|
+
if (existingDescriptor) {
|
|
8045
|
+
// Provider already initialized — likely a leaked handler from a previous db instance
|
|
8046
|
+
// (e.g. HMR where db.close() didn't fire). Destroy the stale awareness so the new
|
|
8047
|
+
// handler can take over cleanly.
|
|
8048
|
+
const staleAwareness = provider.awareness;
|
|
8049
|
+
if (staleAwareness) {
|
|
8050
|
+
staleAwareness.destroy();
|
|
8051
|
+
awarenessWeakMap.delete(doc);
|
|
8052
|
+
}
|
|
8053
|
+
}
|
|
7958
8054
|
Object.defineProperty(provider, 'awareness', {
|
|
8055
|
+
configurable: true,
|
|
7959
8056
|
get() {
|
|
7960
8057
|
if (awareness)
|
|
7961
8058
|
return awareness;
|
|
@@ -8138,10 +8235,12 @@ function parseOAuthCallback(url) {
|
|
|
8138
8235
|
const { code, provider, state, error } = payload;
|
|
8139
8236
|
// Check for error first
|
|
8140
8237
|
if (error) {
|
|
8141
|
-
if (error.toLowerCase().includes('access_denied') ||
|
|
8238
|
+
if (error.toLowerCase().includes('access_denied') ||
|
|
8239
|
+
error.toLowerCase().includes('access denied')) {
|
|
8142
8240
|
throw new OAuthError('access_denied', provider, error);
|
|
8143
8241
|
}
|
|
8144
|
-
if (error.toLowerCase().includes('email') &&
|
|
8242
|
+
if (error.toLowerCase().includes('email') &&
|
|
8243
|
+
error.toLowerCase().includes('verif')) {
|
|
8145
8244
|
throw new OAuthError('email_not_verified', provider, error);
|
|
8146
8245
|
}
|
|
8147
8246
|
throw new OAuthError('provider_error', provider, error);
|
|
@@ -8167,7 +8266,9 @@ function cleanupOAuthUrl() {
|
|
|
8167
8266
|
return;
|
|
8168
8267
|
}
|
|
8169
8268
|
url.searchParams.delete('dxc-auth');
|
|
8170
|
-
const cleanUrl = url.pathname +
|
|
8269
|
+
const cleanUrl = url.pathname +
|
|
8270
|
+
(url.searchParams.toString() ? `?${url.searchParams.toString()}` : '') +
|
|
8271
|
+
url.hash;
|
|
8171
8272
|
window.history.replaceState(null, '', cleanUrl);
|
|
8172
8273
|
}
|
|
8173
8274
|
|
|
@@ -8180,8 +8281,8 @@ function getTiedObjectId(realmId) {
|
|
|
8180
8281
|
|
|
8181
8282
|
const ydocTriggers = {};
|
|
8182
8283
|
const middlewares = new WeakMap();
|
|
8183
|
-
const txRunner = TriggerRunner(
|
|
8184
|
-
const unloadRunner = TriggerRunner(
|
|
8284
|
+
const txRunner = TriggerRunner('tx'); // Trigger registry for transaction completion. Avoids open docs.
|
|
8285
|
+
const unloadRunner = TriggerRunner('unload'); // Trigger registry for unload. Runs when a document is closed.
|
|
8185
8286
|
function TriggerRunner(name) {
|
|
8186
8287
|
let triggerExecPromise = null;
|
|
8187
8288
|
let triggerScheduled = false;
|
|
@@ -8220,7 +8321,7 @@ function TriggerRunner(name) {
|
|
|
8220
8321
|
yield triggerExecPromise.catch(() => { });
|
|
8221
8322
|
setTimeout(() => {
|
|
8222
8323
|
// setTimeout() is to escape from Promise.PSD zones and never run within liveQueries or transaction scopes
|
|
8223
|
-
console.log(
|
|
8324
|
+
console.log('Running trigger really!', name);
|
|
8224
8325
|
triggerScheduled = false;
|
|
8225
8326
|
const registryCopy = registry;
|
|
8226
8327
|
registry = new Map();
|
|
@@ -8387,7 +8488,7 @@ function dexieCloud(dexie) {
|
|
|
8387
8488
|
const downloading$ = createDownloadingState();
|
|
8388
8489
|
dexie.cloud = {
|
|
8389
8490
|
// @ts-ignore
|
|
8390
|
-
version: "4.4.
|
|
8491
|
+
version: "4.4.7",
|
|
8391
8492
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
8392
8493
|
schema: null,
|
|
8393
8494
|
get currentUserId() {
|
|
@@ -8443,7 +8544,10 @@ function dexieCloud(dexie) {
|
|
|
8443
8544
|
const callback = parseOAuthCallback();
|
|
8444
8545
|
if (callback) {
|
|
8445
8546
|
// Store the pending auth code for processing when db is ready
|
|
8446
|
-
pendingOAuthCode = {
|
|
8547
|
+
pendingOAuthCode = {
|
|
8548
|
+
code: callback.code,
|
|
8549
|
+
provider: callback.provider,
|
|
8550
|
+
};
|
|
8447
8551
|
console.debug('[dexie-cloud] OAuth callback detected, auth code stored for processing');
|
|
8448
8552
|
}
|
|
8449
8553
|
}
|
|
@@ -8560,7 +8664,7 @@ function dexieCloud(dexie) {
|
|
|
8560
8664
|
if (eagerBlobDownloadInFlight)
|
|
8561
8665
|
return;
|
|
8562
8666
|
eagerBlobDownloadInFlight = Dexie.ignoreTransaction(() => downloadUnresolvedBlobs(db, downloading$))
|
|
8563
|
-
.catch(err => {
|
|
8667
|
+
.catch((err) => {
|
|
8564
8668
|
console.error('[dexie-cloud] Eager blob download failed:', err);
|
|
8565
8669
|
})
|
|
8566
8670
|
.finally(() => {
|
|
@@ -8653,7 +8757,10 @@ function dexieCloud(dexie) {
|
|
|
8653
8757
|
// Let's assign all props as the newPersistedSchems should be what we should be working with.
|
|
8654
8758
|
Object.assign(schema, newPersistedSchema);
|
|
8655
8759
|
}
|
|
8656
|
-
return [
|
|
8760
|
+
return [
|
|
8761
|
+
persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.initiallySynced,
|
|
8762
|
+
persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms,
|
|
8763
|
+
];
|
|
8657
8764
|
}));
|
|
8658
8765
|
if (initiallySynced) {
|
|
8659
8766
|
db.setInitiallySynced(true);
|
|
@@ -8662,8 +8769,10 @@ function dexieCloud(dexie) {
|
|
|
8662
8769
|
// Manage CurrentUser observable:
|
|
8663
8770
|
throwIfClosed();
|
|
8664
8771
|
if (!db.cloud.isServiceWorkerDB) {
|
|
8665
|
-
subscriptions.push(liveQuery(() => db.getCurrentUser().then(user => {
|
|
8666
|
-
if (!user.isLoggedIn &&
|
|
8772
|
+
subscriptions.push(liveQuery(() => db.getCurrentUser().then((user) => {
|
|
8773
|
+
if (!user.isLoggedIn &&
|
|
8774
|
+
typeof location !== 'undefined' &&
|
|
8775
|
+
/dxc-auth\=/.test(location.search)) {
|
|
8667
8776
|
// Still loading user because OAuth redirect just happened.
|
|
8668
8777
|
// Keep isLoading true.
|
|
8669
8778
|
return Object.assign(Object.assign({}, user), { isLoading: true });
|
|
@@ -8701,7 +8810,7 @@ function dexieCloud(dexie) {
|
|
|
8701
8810
|
type: 'error',
|
|
8702
8811
|
messageCode: 'GENERIC_ERROR',
|
|
8703
8812
|
message: error.message,
|
|
8704
|
-
messageParams: { provider: error.provider || 'unknown' }
|
|
8813
|
+
messageParams: { provider: error.provider || 'unknown' },
|
|
8705
8814
|
});
|
|
8706
8815
|
// Clean up URL (remove dxc-auth param)
|
|
8707
8816
|
cleanupOAuthUrl();
|
|
@@ -8751,7 +8860,8 @@ function dexieCloud(dexie) {
|
|
|
8751
8860
|
}
|
|
8752
8861
|
}
|
|
8753
8862
|
}
|
|
8754
|
-
if (user.isLoggedIn &&
|
|
8863
|
+
if (user.isLoggedIn &&
|
|
8864
|
+
(!lastSyncedRealms || !lastSyncedRealms.includes(user.userId))) {
|
|
8755
8865
|
// User has been logged in but this is not reflected in the sync state.
|
|
8756
8866
|
// This can happen if page is reloaded after login but before the sync call following
|
|
8757
8867
|
// the login was complete.
|
|
@@ -8814,7 +8924,7 @@ function dexieCloud(dexie) {
|
|
|
8814
8924
|
}
|
|
8815
8925
|
}
|
|
8816
8926
|
// @ts-ignore
|
|
8817
|
-
dexieCloud.version = "4.4.
|
|
8927
|
+
dexieCloud.version = "4.4.7";
|
|
8818
8928
|
Dexie.Cloud = dexieCloud;
|
|
8819
8929
|
|
|
8820
8930
|
export { dexieCloud as default, defineYDocTrigger, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };
|