@multiplatform.one/frappe 9.17.0 → 10.0.0
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/cjs/auth.cjs +34 -44
- package/dist/cjs/auth.native.cjs +97 -0
- package/dist/cjs/auth.native.js +77 -82
- package/dist/cjs/auth.native.js.map +1 -1
- package/dist/cjs/call.cjs +31 -35
- package/dist/cjs/call.native.cjs +92 -0
- package/dist/cjs/call.native.js +72 -71
- package/dist/cjs/call.native.js.map +1 -1
- package/dist/cjs/collection.cjs +243 -287
- package/dist/cjs/collection.native.cjs +461 -0
- package/dist/cjs/collection.native.js +436 -499
- package/dist/cjs/collection.native.js.map +1 -1
- package/dist/cjs/common/types.cjs +9 -11
- package/dist/cjs/common/types.native.cjs +18 -0
- package/dist/cjs/common/types.native.js +9 -10
- package/dist/cjs/common/types.native.js.map +1 -1
- package/dist/cjs/connectionKey.cjs +18 -22
- package/dist/cjs/connectionKey.native.cjs +32 -0
- package/dist/cjs/connectionKey.native.js +19 -22
- package/dist/cjs/connectionKey.native.js.map +1 -1
- package/dist/cjs/core/http.cjs +404 -407
- package/dist/cjs/core/http.native.cjs +659 -0
- package/dist/cjs/core/http.native.js +611 -615
- package/dist/cjs/core/http.native.js.map +1 -1
- package/dist/cjs/core/serverMessages.cjs +48 -43
- package/dist/cjs/core/serverMessages.native.cjs +89 -0
- package/dist/cjs/core/serverMessages.native.js +69 -70
- package/dist/cjs/core/serverMessages.native.js.map +1 -1
- package/dist/cjs/core/sessionGate.cjs +94 -97
- package/dist/cjs/core/sessionGate.native.cjs +270 -0
- package/dist/cjs/core/sessionGate.native.js +220 -232
- package/dist/cjs/core/sessionGate.native.js.map +1 -1
- package/dist/cjs/core/types.cjs +37 -39
- package/dist/cjs/core/types.native.cjs +169 -0
- package/dist/cjs/core/types.native.js +129 -136
- package/dist/cjs/core/types.native.js.map +1 -1
- package/dist/cjs/core/wire.cjs +28 -30
- package/dist/cjs/core/wire.native.cjs +53 -0
- package/dist/cjs/core/wire.native.js +28 -29
- package/dist/cjs/core/wire.native.js.map +1 -1
- package/dist/cjs/db.cjs +434 -449
- package/dist/cjs/db.native.cjs +625 -0
- package/dist/cjs/db.native.js +583 -590
- package/dist/cjs/db.native.js.map +1 -1
- package/dist/cjs/devtools/FrappeDevtoolsPanel.cjs +774 -799
- package/dist/cjs/devtools/FrappeDevtoolsPanel.native.cjs +878 -0
- package/dist/cjs/devtools/FrappeDevtoolsPanel.native.js +821 -862
- package/dist/cjs/devtools/FrappeDevtoolsPanel.native.js.map +1 -1
- package/dist/cjs/devtools/index.cjs +15 -17
- package/dist/cjs/devtools/index.native.cjs +30 -0
- package/dist/cjs/devtools/index.native.js +15 -16
- package/dist/cjs/devtools/index.native.js.map +1 -1
- package/dist/cjs/devtools/plugin.cjs +22 -26
- package/dist/cjs/devtools/plugin.native.cjs +46 -0
- package/dist/cjs/devtools/plugin.native.js +27 -35
- package/dist/cjs/devtools/plugin.native.js.map +1 -1
- package/dist/cjs/devtools/theme.cjs +40 -44
- package/dist/cjs/devtools/theme.native.cjs +53 -0
- package/dist/cjs/devtools/theme.native.js +40 -43
- package/dist/cjs/devtools/theme.native.js.map +1 -1
- package/dist/cjs/doctype.cjs +493 -440
- package/dist/cjs/doctype.native.cjs +631 -0
- package/dist/cjs/doctype.native.js +587 -563
- package/dist/cjs/doctype.native.js.map +1 -1
- package/dist/cjs/file.cjs +27 -31
- package/dist/cjs/file.native.cjs +78 -0
- package/dist/cjs/file.native.js +58 -62
- package/dist/cjs/file.native.js.map +1 -1
- package/dist/cjs/fixtureDb.cjs +187 -209
- package/dist/cjs/fixtureDb.native.cjs +313 -0
- package/dist/cjs/fixtureDb.native.js +291 -300
- package/dist/cjs/fixtureDb.native.js.map +1 -1
- package/dist/cjs/fixtures.cjs +173 -192
- package/dist/cjs/fixtures.native.cjs +379 -0
- package/dist/cjs/fixtures.native.js +359 -381
- package/dist/cjs/fixtures.native.js.map +1 -1
- package/dist/cjs/frappeApp.cjs +94 -101
- package/dist/cjs/frappeApp.native.cjs +181 -0
- package/dist/cjs/frappeApp.native.js +153 -152
- package/dist/cjs/frappeApp.native.js.map +1 -1
- package/dist/cjs/frappeReact.cjs +555 -528
- package/dist/cjs/frappeReact.native.cjs +710 -0
- package/dist/cjs/frappeReact.native.js +637 -632
- package/dist/cjs/frappeReact.native.js.map +1 -1
- package/dist/cjs/index.cjs +128 -135
- package/dist/cjs/index.gnome.cjs +61 -63
- package/dist/cjs/index.gnome.native.cjs +87 -0
- package/dist/cjs/index.gnome.native.js +61 -62
- package/dist/cjs/index.gnome.native.js.map +1 -1
- package/dist/cjs/index.native.cjs +171 -0
- package/dist/cjs/index.native.js +130 -136
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/optimistic.cjs +35 -39
- package/dist/cjs/optimistic.native.cjs +59 -0
- package/dist/cjs/optimistic.native.js +38 -41
- package/dist/cjs/optimistic.native.js.map +1 -1
- package/dist/cjs/pacer.cjs +170 -176
- package/dist/cjs/pacer.native.cjs +263 -0
- package/dist/cjs/pacer.native.js +234 -245
- package/dist/cjs/pacer.native.js.map +1 -1
- package/dist/cjs/plugin/index.cjs +104 -112
- package/dist/cjs/plugin/index.native.cjs +178 -0
- package/dist/cjs/plugin/index.native.js +164 -177
- package/dist/cjs/plugin/index.native.js.map +1 -1
- package/dist/cjs/realtime.cjs +581 -610
- package/dist/cjs/realtime.native.cjs +945 -0
- package/dist/cjs/realtime.native.js +918 -928
- package/dist/cjs/realtime.native.js.map +1 -1
- package/dist/cjs/serverLoaders.cjs +60 -78
- package/dist/cjs/serverLoaders.native.cjs +103 -0
- package/dist/cjs/serverLoaders.native.js +73 -95
- package/dist/cjs/serverLoaders.native.js.map +1 -1
- package/dist/cjs/sync/backfill.cjs +281 -301
- package/dist/cjs/sync/backfill.native.cjs +475 -0
- package/dist/cjs/sync/backfill.native.js +449 -465
- package/dist/cjs/sync/backfill.native.js.map +1 -1
- package/dist/cjs/sync/filters.cjs +309 -267
- package/dist/cjs/sync/filters.native.cjs +472 -0
- package/dist/cjs/sync/filters.native.js +426 -398
- package/dist/cjs/sync/filters.native.js.map +1 -1
- package/dist/cjs/sync/index.cjs +476 -496
- package/dist/cjs/sync/index.native.cjs +771 -0
- package/dist/cjs/sync/index.native.js +738 -737
- package/dist/cjs/sync/index.native.js.map +1 -1
- package/dist/cjs/sync/merge.cjs +392 -393
- package/dist/cjs/sync/merge.native.cjs +681 -0
- package/dist/cjs/sync/merge.native.js +642 -673
- package/dist/cjs/sync/merge.native.js.map +1 -1
- package/dist/cjs/sync/mutationEngine.cjs +785 -829
- package/dist/cjs/sync/mutationEngine.native.cjs +1190 -0
- package/dist/cjs/sync/mutationEngine.native.js +1162 -1216
- package/dist/cjs/sync/mutationEngine.native.js.map +1 -1
- package/dist/cjs/sync/mutationJournal.cjs +147 -149
- package/dist/cjs/sync/mutationJournal.native.cjs +302 -0
- package/dist/cjs/sync/mutationJournal.native.js +278 -269
- package/dist/cjs/sync/mutationJournal.native.js.map +1 -1
- package/dist/cjs/sync/normalizedCache.cjs +127 -134
- package/dist/cjs/sync/normalizedCache.native.cjs +232 -0
- package/dist/cjs/sync/normalizedCache.native.js +212 -212
- package/dist/cjs/sync/normalizedCache.native.js.map +1 -1
- package/dist/cjs/sync/persistence.cjs +649 -661
- package/dist/cjs/sync/persistence.native.cjs +996 -0
- package/dist/cjs/sync/persistence.native.js +967 -965
- package/dist/cjs/sync/persistence.native.js.map +1 -1
- package/dist/cjs/sync/realtime.cjs +307 -315
- package/dist/cjs/sync/realtime.native.cjs +486 -0
- package/dist/cjs/sync/realtime.native.js +465 -461
- package/dist/cjs/sync/realtime.native.js.map +1 -1
- package/dist/cjs/sync/rehydration.cjs +279 -321
- package/dist/cjs/sync/rehydration.native.cjs +495 -0
- package/dist/cjs/sync/rehydration.native.js +473 -515
- package/dist/cjs/sync/rehydration.native.js.map +1 -1
- package/dist/cjs/sync/storage.cjs +127 -129
- package/dist/cjs/sync/storage.native.cjs +211 -0
- package/dist/cjs/sync/storage.native.js +188 -184
- package/dist/cjs/sync/storage.native.js.map +1 -1
- package/dist/cjs/sync/subscriptionManager.cjs +686 -708
- package/dist/cjs/sync/subscriptionManager.native.cjs +1205 -0
- package/dist/cjs/sync/subscriptionManager.native.js +1179 -1220
- package/dist/cjs/sync/subscriptionManager.native.js.map +1 -1
- package/dist/cjs/sync/types.cjs +79 -81
- package/dist/cjs/sync/types.native.cjs +103 -0
- package/dist/cjs/sync/types.native.js +89 -90
- package/dist/cjs/sync/types.native.js.map +1 -1
- package/dist/cjs/sync/virtualPageManager.cjs +762 -806
- package/dist/cjs/sync/virtualPageManager.native.cjs +1097 -0
- package/dist/cjs/sync/virtualPageManager.native.js +1072 -1097
- package/dist/cjs/sync/virtualPageManager.native.js.map +1 -1
- package/dist/cjs/syncOptionsKey.cjs +38 -45
- package/dist/cjs/syncOptionsKey.native.cjs +69 -0
- package/dist/cjs/syncOptionsKey.native.js +51 -63
- package/dist/cjs/syncOptionsKey.native.js.map +1 -1
- package/dist/cjs/useLiveQuery.cjs +14 -18
- package/dist/cjs/useLiveQuery.native.cjs +26 -0
- package/dist/cjs/useLiveQuery.native.js +14 -17
- package/dist/cjs/useLiveQuery.native.js.map +1 -1
- package/dist/cjs/util.cjs +22 -24
- package/dist/cjs/util.native.cjs +40 -0
- package/dist/cjs/util.native.js +22 -28
- package/dist/cjs/util.native.js.map +1 -1
- package/dist/esm/auth.mjs +22 -27
- package/dist/esm/auth.mjs.map +1 -1
- package/dist/esm/auth.native.js +64 -65
- package/dist/esm/auth.native.js.map +1 -1
- package/dist/esm/call.mjs +19 -18
- package/dist/esm/call.mjs.map +1 -1
- package/dist/esm/call.native.js +59 -54
- package/dist/esm/call.native.js.map +1 -1
- package/dist/esm/collection.mjs +228 -268
- package/dist/esm/collection.mjs.map +1 -1
- package/dist/esm/collection.native.js +421 -481
- package/dist/esm/collection.native.js.map +1 -1
- package/dist/esm/common/types.mjs +0 -2
- package/dist/esm/common/types.native.js +0 -2
- package/dist/esm/connectionKey.mjs +5 -4
- package/dist/esm/connectionKey.mjs.map +1 -1
- package/dist/esm/connectionKey.native.js +6 -5
- package/dist/esm/connectionKey.native.js.map +1 -1
- package/dist/esm/core/http.mjs +383 -382
- package/dist/esm/core/http.mjs.map +1 -1
- package/dist/esm/core/http.native.js +590 -591
- package/dist/esm/core/http.native.js.map +1 -1
- package/dist/esm/core/serverMessages.mjs +34 -26
- package/dist/esm/core/serverMessages.mjs.map +1 -1
- package/dist/esm/core/serverMessages.native.js +55 -54
- package/dist/esm/core/serverMessages.native.js.map +1 -1
- package/dist/esm/core/sessionGate.mjs +79 -79
- package/dist/esm/core/sessionGate.mjs.map +1 -1
- package/dist/esm/core/sessionGate.native.js +205 -215
- package/dist/esm/core/sessionGate.native.js.map +1 -1
- package/dist/esm/core/types.mjs +23 -22
- package/dist/esm/core/types.mjs.map +1 -1
- package/dist/esm/core/types.native.js +114 -119
- package/dist/esm/core/types.native.js.map +1 -1
- package/dist/esm/core/wire.mjs +10 -9
- package/dist/esm/core/wire.mjs.map +1 -1
- package/dist/esm/core/wire.native.js +10 -9
- package/dist/esm/core/wire.native.js.map +1 -1
- package/dist/esm/db.mjs +421 -432
- package/dist/esm/db.mjs.map +1 -1
- package/dist/esm/db.native.js +570 -574
- package/dist/esm/db.native.js.map +1 -1
- package/dist/esm/devtools/FrappeDevtoolsPanel.mjs +762 -781
- package/dist/esm/devtools/FrappeDevtoolsPanel.mjs.map +1 -1
- package/dist/esm/devtools/FrappeDevtoolsPanel.native.js +808 -839
- package/dist/esm/devtools/FrappeDevtoolsPanel.native.js.map +1 -1
- package/dist/esm/devtools/index.mjs +2 -2
- package/dist/esm/devtools/index.native.js +2 -2
- package/dist/esm/devtools/plugin.mjs +10 -8
- package/dist/esm/devtools/plugin.mjs.map +1 -1
- package/dist/esm/devtools/plugin.native.js +14 -12
- package/dist/esm/devtools/plugin.native.js.map +1 -1
- package/dist/esm/devtools/theme.mjs +27 -26
- package/dist/esm/devtools/theme.mjs.map +1 -1
- package/dist/esm/devtools/theme.native.js +27 -26
- package/dist/esm/devtools/theme.native.js.map +1 -1
- package/dist/esm/doctype.mjs +473 -416
- package/dist/esm/doctype.mjs.map +1 -1
- package/dist/esm/doctype.native.js +566 -539
- package/dist/esm/doctype.native.js.map +1 -1
- package/dist/esm/file.mjs +15 -14
- package/dist/esm/file.mjs.map +1 -1
- package/dist/esm/file.native.js +45 -45
- package/dist/esm/file.native.js.map +1 -1
- package/dist/esm/fixtureDb.mjs +175 -191
- package/dist/esm/fixtureDb.mjs.map +1 -1
- package/dist/esm/fixtureDb.native.js +279 -283
- package/dist/esm/fixtureDb.native.js.map +1 -1
- package/dist/esm/fixtures.mjs +161 -175
- package/dist/esm/fixtures.mjs.map +1 -1
- package/dist/esm/fixtures.native.js +346 -364
- package/dist/esm/fixtures.native.js.map +1 -1
- package/dist/esm/frappeApp.mjs +82 -83
- package/dist/esm/frappeApp.mjs.map +1 -1
- package/dist/esm/frappeApp.native.js +141 -135
- package/dist/esm/frappeApp.native.js.map +1 -1
- package/dist/esm/frappeReact.mjs +535 -504
- package/dist/esm/frappeReact.mjs.map +1 -1
- package/dist/esm/frappeReact.native.js +615 -607
- package/dist/esm/frappeReact.native.js.map +1 -1
- package/dist/esm/index.gnome.mjs +5 -5
- package/dist/esm/index.gnome.native.js +5 -5
- package/dist/esm/index.mjs +17 -18
- package/dist/esm/index.native.js +17 -18
- package/dist/esm/optimistic.mjs +19 -19
- package/dist/esm/optimistic.mjs.map +1 -1
- package/dist/esm/optimistic.native.js +22 -22
- package/dist/esm/optimistic.native.js.map +1 -1
- package/dist/esm/pacer.mjs +156 -158
- package/dist/esm/pacer.mjs.map +1 -1
- package/dist/esm/pacer.native.js +220 -228
- package/dist/esm/pacer.native.js.map +1 -1
- package/dist/esm/plugin/index.mjs +91 -94
- package/dist/esm/plugin/index.mjs.map +1 -1
- package/dist/esm/plugin/index.native.js +151 -160
- package/dist/esm/plugin/index.native.js.map +1 -1
- package/dist/esm/realtime.mjs +569 -594
- package/dist/esm/realtime.mjs.map +1 -1
- package/dist/esm/realtime.native.js +905 -912
- package/dist/esm/realtime.native.js.map +1 -1
- package/dist/esm/serverLoaders.mjs +47 -61
- package/dist/esm/serverLoaders.mjs.map +1 -1
- package/dist/esm/serverLoaders.native.js +56 -75
- package/dist/esm/serverLoaders.native.js.map +1 -1
- package/dist/esm/sync/backfill.mjs +268 -284
- package/dist/esm/sync/backfill.mjs.map +1 -1
- package/dist/esm/sync/backfill.native.js +435 -448
- package/dist/esm/sync/backfill.native.js.map +1 -1
- package/dist/esm/sync/filters.mjs +286 -241
- package/dist/esm/sync/filters.mjs.map +1 -1
- package/dist/esm/sync/filters.native.js +403 -373
- package/dist/esm/sync/filters.native.js.map +1 -1
- package/dist/esm/sync/index.mjs +465 -479
- package/dist/esm/sync/index.mjs.map +1 -1
- package/dist/esm/sync/index.native.js +726 -720
- package/dist/esm/sync/index.native.js.map +1 -1
- package/dist/esm/sync/merge.mjs +368 -366
- package/dist/esm/sync/merge.mjs.map +1 -1
- package/dist/esm/sync/merge.native.js +618 -647
- package/dist/esm/sync/merge.native.js.map +1 -1
- package/dist/esm/sync/mutationEngine.mjs +775 -814
- package/dist/esm/sync/mutationEngine.mjs.map +1 -1
- package/dist/esm/sync/mutationEngine.native.js +1152 -1202
- package/dist/esm/sync/mutationEngine.native.js.map +1 -1
- package/dist/esm/sync/mutationJournal.mjs +135 -133
- package/dist/esm/sync/mutationJournal.mjs.map +1 -1
- package/dist/esm/sync/mutationJournal.native.js +265 -253
- package/dist/esm/sync/mutationJournal.native.js.map +1 -1
- package/dist/esm/sync/normalizedCache.mjs +115 -117
- package/dist/esm/sync/normalizedCache.mjs.map +1 -1
- package/dist/esm/sync/normalizedCache.native.js +199 -195
- package/dist/esm/sync/normalizedCache.native.js.map +1 -1
- package/dist/esm/sync/persistence.mjs +637 -645
- package/dist/esm/sync/persistence.mjs.map +1 -1
- package/dist/esm/sync/persistence.native.js +954 -949
- package/dist/esm/sync/persistence.native.js.map +1 -1
- package/dist/esm/sync/realtime.mjs +296 -298
- package/dist/esm/sync/realtime.mjs.map +1 -1
- package/dist/esm/sync/realtime.native.js +453 -444
- package/dist/esm/sync/realtime.native.js.map +1 -1
- package/dist/esm/sync/rehydration.mjs +268 -304
- package/dist/esm/sync/rehydration.mjs.map +1 -1
- package/dist/esm/sync/rehydration.native.js +461 -498
- package/dist/esm/sync/rehydration.native.js.map +1 -1
- package/dist/esm/sync/storage.mjs +115 -113
- package/dist/esm/sync/storage.mjs.map +1 -1
- package/dist/esm/sync/storage.native.js +175 -168
- package/dist/esm/sync/storage.native.js.map +1 -1
- package/dist/esm/sync/subscriptionManager.mjs +675 -691
- package/dist/esm/sync/subscriptionManager.mjs.map +1 -1
- package/dist/esm/sync/subscriptionManager.native.js +1168 -1204
- package/dist/esm/sync/subscriptionManager.native.js.map +1 -1
- package/dist/esm/sync/types.mjs +56 -55
- package/dist/esm/sync/types.mjs.map +1 -1
- package/dist/esm/sync/types.native.js +66 -65
- package/dist/esm/sync/types.native.js.map +1 -1
- package/dist/esm/sync/virtualPageManager.mjs +749 -789
- package/dist/esm/sync/virtualPageManager.mjs.map +1 -1
- package/dist/esm/sync/virtualPageManager.native.js +1058 -1080
- package/dist/esm/sync/virtualPageManager.native.js.map +1 -1
- package/dist/esm/syncOptionsKey.mjs +25 -27
- package/dist/esm/syncOptionsKey.mjs.map +1 -1
- package/dist/esm/syncOptionsKey.native.js +38 -46
- package/dist/esm/syncOptionsKey.native.js.map +1 -1
- package/dist/esm/useLiveQuery.mjs +2 -2
- package/dist/esm/useLiveQuery.native.js +2 -2
- package/dist/esm/util.mjs +9 -7
- package/dist/esm/util.mjs.map +1 -1
- package/dist/esm/util.native.js +8 -11
- package/dist/esm/util.native.js.map +1 -1
- package/dist/jsx/auth.mjs +22 -27
- package/dist/jsx/auth.mjs.map +1 -1
- package/dist/jsx/auth.native.cjs +97 -0
- package/dist/jsx/auth.native.js +77 -82
- package/dist/jsx/auth.native.js.map +1 -1
- package/dist/jsx/call.mjs +19 -18
- package/dist/jsx/call.mjs.map +1 -1
- package/dist/jsx/call.native.cjs +92 -0
- package/dist/jsx/call.native.js +72 -71
- package/dist/jsx/call.native.js.map +1 -1
- package/dist/jsx/collection.mjs +228 -268
- package/dist/jsx/collection.mjs.map +1 -1
- package/dist/jsx/collection.native.cjs +461 -0
- package/dist/jsx/collection.native.js +436 -499
- package/dist/jsx/collection.native.js.map +1 -1
- package/dist/jsx/common/types.mjs +0 -2
- package/dist/jsx/common/types.native.cjs +18 -0
- package/dist/jsx/common/types.native.js +9 -10
- package/dist/jsx/common/types.native.js.map +1 -1
- package/dist/jsx/connectionKey.mjs +5 -4
- package/dist/jsx/connectionKey.mjs.map +1 -1
- package/dist/jsx/connectionKey.native.cjs +32 -0
- package/dist/jsx/connectionKey.native.js +19 -22
- package/dist/jsx/connectionKey.native.js.map +1 -1
- package/dist/jsx/core/http.mjs +383 -382
- package/dist/jsx/core/http.mjs.map +1 -1
- package/dist/jsx/core/http.native.cjs +659 -0
- package/dist/jsx/core/http.native.js +611 -615
- package/dist/jsx/core/http.native.js.map +1 -1
- package/dist/jsx/core/serverMessages.mjs +34 -26
- package/dist/jsx/core/serverMessages.mjs.map +1 -1
- package/dist/jsx/core/serverMessages.native.cjs +89 -0
- package/dist/jsx/core/serverMessages.native.js +69 -70
- package/dist/jsx/core/serverMessages.native.js.map +1 -1
- package/dist/jsx/core/sessionGate.mjs +79 -79
- package/dist/jsx/core/sessionGate.mjs.map +1 -1
- package/dist/jsx/core/sessionGate.native.cjs +270 -0
- package/dist/jsx/core/sessionGate.native.js +220 -232
- package/dist/jsx/core/sessionGate.native.js.map +1 -1
- package/dist/jsx/core/types.mjs +23 -22
- package/dist/jsx/core/types.mjs.map +1 -1
- package/dist/jsx/core/types.native.cjs +169 -0
- package/dist/jsx/core/types.native.js +129 -136
- package/dist/jsx/core/types.native.js.map +1 -1
- package/dist/jsx/core/wire.mjs +10 -9
- package/dist/jsx/core/wire.mjs.map +1 -1
- package/dist/jsx/core/wire.native.cjs +53 -0
- package/dist/jsx/core/wire.native.js +28 -29
- package/dist/jsx/core/wire.native.js.map +1 -1
- package/dist/jsx/db.mjs +421 -432
- package/dist/jsx/db.mjs.map +1 -1
- package/dist/jsx/db.native.cjs +625 -0
- package/dist/jsx/db.native.js +583 -590
- package/dist/jsx/db.native.js.map +1 -1
- package/dist/jsx/devtools/FrappeDevtoolsPanel.mjs +762 -781
- package/dist/jsx/devtools/FrappeDevtoolsPanel.mjs.map +1 -1
- package/dist/jsx/devtools/FrappeDevtoolsPanel.native.cjs +878 -0
- package/dist/jsx/devtools/FrappeDevtoolsPanel.native.js +821 -862
- package/dist/jsx/devtools/FrappeDevtoolsPanel.native.js.map +1 -1
- package/dist/jsx/devtools/index.mjs +2 -2
- package/dist/jsx/devtools/index.native.cjs +30 -0
- package/dist/jsx/devtools/index.native.js +15 -16
- package/dist/jsx/devtools/index.native.js.map +1 -1
- package/dist/jsx/devtools/plugin.mjs +10 -8
- package/dist/jsx/devtools/plugin.mjs.map +1 -1
- package/dist/jsx/devtools/plugin.native.cjs +46 -0
- package/dist/jsx/devtools/plugin.native.js +27 -35
- package/dist/jsx/devtools/plugin.native.js.map +1 -1
- package/dist/jsx/devtools/theme.mjs +27 -26
- package/dist/jsx/devtools/theme.mjs.map +1 -1
- package/dist/jsx/devtools/theme.native.cjs +53 -0
- package/dist/jsx/devtools/theme.native.js +40 -43
- package/dist/jsx/devtools/theme.native.js.map +1 -1
- package/dist/jsx/doctype.mjs +473 -416
- package/dist/jsx/doctype.mjs.map +1 -1
- package/dist/jsx/doctype.native.cjs +631 -0
- package/dist/jsx/doctype.native.js +587 -563
- package/dist/jsx/doctype.native.js.map +1 -1
- package/dist/jsx/file.mjs +15 -14
- package/dist/jsx/file.mjs.map +1 -1
- package/dist/jsx/file.native.cjs +78 -0
- package/dist/jsx/file.native.js +58 -62
- package/dist/jsx/file.native.js.map +1 -1
- package/dist/jsx/fixtureDb.mjs +175 -191
- package/dist/jsx/fixtureDb.mjs.map +1 -1
- package/dist/jsx/fixtureDb.native.cjs +313 -0
- package/dist/jsx/fixtureDb.native.js +291 -300
- package/dist/jsx/fixtureDb.native.js.map +1 -1
- package/dist/jsx/fixtures.mjs +161 -175
- package/dist/jsx/fixtures.mjs.map +1 -1
- package/dist/jsx/fixtures.native.cjs +379 -0
- package/dist/jsx/fixtures.native.js +359 -381
- package/dist/jsx/fixtures.native.js.map +1 -1
- package/dist/jsx/frappeApp.mjs +82 -83
- package/dist/jsx/frappeApp.mjs.map +1 -1
- package/dist/jsx/frappeApp.native.cjs +181 -0
- package/dist/jsx/frappeApp.native.js +153 -152
- package/dist/jsx/frappeApp.native.js.map +1 -1
- package/dist/jsx/frappeReact.mjs +535 -504
- package/dist/jsx/frappeReact.mjs.map +1 -1
- package/dist/jsx/frappeReact.native.cjs +710 -0
- package/dist/jsx/frappeReact.native.js +636 -631
- package/dist/jsx/frappeReact.native.js.map +1 -1
- package/dist/jsx/index.gnome.mjs +5 -5
- package/dist/jsx/index.gnome.native.cjs +87 -0
- package/dist/jsx/index.gnome.native.js +61 -62
- package/dist/jsx/index.gnome.native.js.map +1 -1
- package/dist/jsx/index.js +17 -18
- package/dist/jsx/index.mjs +17 -18
- package/dist/jsx/index.native.cjs +171 -0
- package/dist/jsx/index.native.js +128 -134
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/optimistic.mjs +19 -19
- package/dist/jsx/optimistic.mjs.map +1 -1
- package/dist/jsx/optimistic.native.cjs +59 -0
- package/dist/jsx/optimistic.native.js +38 -41
- package/dist/jsx/optimistic.native.js.map +1 -1
- package/dist/jsx/pacer.mjs +156 -158
- package/dist/jsx/pacer.mjs.map +1 -1
- package/dist/jsx/pacer.native.cjs +263 -0
- package/dist/jsx/pacer.native.js +234 -245
- package/dist/jsx/pacer.native.js.map +1 -1
- package/dist/jsx/plugin/index.mjs +91 -94
- package/dist/jsx/plugin/index.mjs.map +1 -1
- package/dist/jsx/plugin/index.native.cjs +178 -0
- package/dist/jsx/plugin/index.native.js +164 -177
- package/dist/jsx/plugin/index.native.js.map +1 -1
- package/dist/jsx/realtime.mjs +569 -594
- package/dist/jsx/realtime.mjs.map +1 -1
- package/dist/jsx/realtime.native.cjs +945 -0
- package/dist/jsx/realtime.native.js +918 -928
- package/dist/jsx/realtime.native.js.map +1 -1
- package/dist/jsx/serverLoaders.mjs +47 -61
- package/dist/jsx/serverLoaders.mjs.map +1 -1
- package/dist/jsx/serverLoaders.native.cjs +103 -0
- package/dist/jsx/serverLoaders.native.js +73 -95
- package/dist/jsx/serverLoaders.native.js.map +1 -1
- package/dist/jsx/sync/backfill.mjs +268 -284
- package/dist/jsx/sync/backfill.mjs.map +1 -1
- package/dist/jsx/sync/backfill.native.cjs +475 -0
- package/dist/jsx/sync/backfill.native.js +449 -465
- package/dist/jsx/sync/backfill.native.js.map +1 -1
- package/dist/jsx/sync/filters.mjs +286 -241
- package/dist/jsx/sync/filters.mjs.map +1 -1
- package/dist/jsx/sync/filters.native.cjs +472 -0
- package/dist/jsx/sync/filters.native.js +426 -398
- package/dist/jsx/sync/filters.native.js.map +1 -1
- package/dist/jsx/sync/index.mjs +465 -479
- package/dist/jsx/sync/index.mjs.map +1 -1
- package/dist/jsx/sync/index.native.cjs +771 -0
- package/dist/jsx/sync/index.native.js +738 -737
- package/dist/jsx/sync/index.native.js.map +1 -1
- package/dist/jsx/sync/merge.mjs +368 -366
- package/dist/jsx/sync/merge.mjs.map +1 -1
- package/dist/jsx/sync/merge.native.cjs +681 -0
- package/dist/jsx/sync/merge.native.js +642 -673
- package/dist/jsx/sync/merge.native.js.map +1 -1
- package/dist/jsx/sync/mutationEngine.mjs +775 -814
- package/dist/jsx/sync/mutationEngine.mjs.map +1 -1
- package/dist/jsx/sync/mutationEngine.native.cjs +1190 -0
- package/dist/jsx/sync/mutationEngine.native.js +1162 -1216
- package/dist/jsx/sync/mutationEngine.native.js.map +1 -1
- package/dist/jsx/sync/mutationJournal.mjs +135 -133
- package/dist/jsx/sync/mutationJournal.mjs.map +1 -1
- package/dist/jsx/sync/mutationJournal.native.cjs +302 -0
- package/dist/jsx/sync/mutationJournal.native.js +278 -269
- package/dist/jsx/sync/mutationJournal.native.js.map +1 -1
- package/dist/jsx/sync/normalizedCache.mjs +115 -117
- package/dist/jsx/sync/normalizedCache.mjs.map +1 -1
- package/dist/jsx/sync/normalizedCache.native.cjs +232 -0
- package/dist/jsx/sync/normalizedCache.native.js +212 -212
- package/dist/jsx/sync/normalizedCache.native.js.map +1 -1
- package/dist/jsx/sync/persistence.mjs +637 -645
- package/dist/jsx/sync/persistence.mjs.map +1 -1
- package/dist/jsx/sync/persistence.native.cjs +996 -0
- package/dist/jsx/sync/persistence.native.js +967 -965
- package/dist/jsx/sync/persistence.native.js.map +1 -1
- package/dist/jsx/sync/realtime.mjs +296 -298
- package/dist/jsx/sync/realtime.mjs.map +1 -1
- package/dist/jsx/sync/realtime.native.cjs +486 -0
- package/dist/jsx/sync/realtime.native.js +465 -461
- package/dist/jsx/sync/realtime.native.js.map +1 -1
- package/dist/jsx/sync/rehydration.mjs +268 -304
- package/dist/jsx/sync/rehydration.mjs.map +1 -1
- package/dist/jsx/sync/rehydration.native.cjs +495 -0
- package/dist/jsx/sync/rehydration.native.js +473 -515
- package/dist/jsx/sync/rehydration.native.js.map +1 -1
- package/dist/jsx/sync/storage.mjs +115 -113
- package/dist/jsx/sync/storage.mjs.map +1 -1
- package/dist/jsx/sync/storage.native.cjs +211 -0
- package/dist/jsx/sync/storage.native.js +188 -184
- package/dist/jsx/sync/storage.native.js.map +1 -1
- package/dist/jsx/sync/subscriptionManager.mjs +675 -691
- package/dist/jsx/sync/subscriptionManager.mjs.map +1 -1
- package/dist/jsx/sync/subscriptionManager.native.cjs +1205 -0
- package/dist/jsx/sync/subscriptionManager.native.js +1179 -1220
- package/dist/jsx/sync/subscriptionManager.native.js.map +1 -1
- package/dist/jsx/sync/types.mjs +56 -55
- package/dist/jsx/sync/types.mjs.map +1 -1
- package/dist/jsx/sync/types.native.cjs +103 -0
- package/dist/jsx/sync/types.native.js +89 -90
- package/dist/jsx/sync/types.native.js.map +1 -1
- package/dist/jsx/sync/virtualPageManager.mjs +749 -789
- package/dist/jsx/sync/virtualPageManager.mjs.map +1 -1
- package/dist/jsx/sync/virtualPageManager.native.cjs +1097 -0
- package/dist/jsx/sync/virtualPageManager.native.js +1072 -1097
- package/dist/jsx/sync/virtualPageManager.native.js.map +1 -1
- package/dist/jsx/syncOptionsKey.mjs +25 -27
- package/dist/jsx/syncOptionsKey.mjs.map +1 -1
- package/dist/jsx/syncOptionsKey.native.cjs +69 -0
- package/dist/jsx/syncOptionsKey.native.js +51 -63
- package/dist/jsx/syncOptionsKey.native.js.map +1 -1
- package/dist/jsx/useLiveQuery.mjs +2 -2
- package/dist/jsx/useLiveQuery.native.cjs +26 -0
- package/dist/jsx/useLiveQuery.native.js +14 -17
- package/dist/jsx/useLiveQuery.native.js.map +1 -1
- package/dist/jsx/util.mjs +9 -7
- package/dist/jsx/util.mjs.map +1 -1
- package/dist/jsx/util.native.cjs +40 -0
- package/dist/jsx/util.native.js +22 -28
- package/dist/jsx/util.native.js.map +1 -1
- package/package.json +10 -10
- package/src/devtools/FrappeDevtoolsPanel.stories.tsx +16 -16
- package/src/devtools/plugin.stories.tsx +4 -4
- package/src/useFrappeCollection.stories.tsx +14 -14
- package/src/useFrappeInfiniteList.stories.tsx +11 -11
- package/src/useFrappePendingMutations.stories.tsx +12 -12
- package/types/devtools/FrappeDevtoolsPanel.d.ts +2 -1
- package/types/devtools/FrappeDevtoolsPanel.d.ts.map +1 -1
- package/types/devtools/plugin.d.ts +2 -1
- package/types/devtools/plugin.d.ts.map +1 -1
- package/dist/esm/common/types.mjs.map +0 -1
- package/dist/esm/common/types.native.js.map +0 -1
- package/dist/esm/devtools/index.mjs.map +0 -1
- package/dist/esm/devtools/index.native.js.map +0 -1
- package/dist/esm/index.gnome.mjs.map +0 -1
- package/dist/esm/index.gnome.native.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/esm/useLiveQuery.mjs.map +0 -1
- package/dist/esm/useLiveQuery.native.js.map +0 -1
- package/dist/jsx/common/types.mjs.map +0 -1
- package/dist/jsx/devtools/index.mjs.map +0 -1
- package/dist/jsx/index.gnome.mjs.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
- package/dist/jsx/useLiveQuery.mjs.map +0 -1
|
@@ -5,27 +5,25 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
12
|
};
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
21
|
};
|
|
22
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
}), mod);
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
23
|
var persistence_exports = {};
|
|
26
24
|
__export(persistence_exports, {
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
DEFAULT_STORAGE_READY_TIMEOUT_MS: () => DEFAULT_STORAGE_READY_TIMEOUT_MS,
|
|
26
|
+
PersistenceManager: () => PersistenceManager
|
|
29
27
|
});
|
|
30
28
|
module.exports = __toCommonJS(persistence_exports);
|
|
31
29
|
var import_pacer = require("@tanstack/pacer");
|
|
@@ -33,964 +31,968 @@ var import_platform = require("@multiplatform.one/platform");
|
|
|
33
31
|
var import_util = require("../util.native.js");
|
|
34
32
|
var import_storage = require("./storage.native.js");
|
|
35
33
|
function _class_call_check(instance, Constructor) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
if (!(instance instanceof Constructor)) {
|
|
35
|
+
throw new TypeError("Cannot call a class as a function");
|
|
36
|
+
}
|
|
39
37
|
}
|
|
40
38
|
function _defineProperties(target, props) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
for (var i = 0; i < props.length; i++) {
|
|
40
|
+
var descriptor = props[i];
|
|
41
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
42
|
+
descriptor.configurable = true;
|
|
43
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
44
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
45
|
+
}
|
|
48
46
|
}
|
|
49
47
|
function _create_class(Constructor, protoProps, staticProps) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
49
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
50
|
+
return Constructor;
|
|
53
51
|
}
|
|
54
52
|
function _define_property(obj, key, value) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
function _type_of(obj) {
|
|
68
|
-
"@swc/helpers - typeof";
|
|
69
|
-
|
|
70
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
53
|
+
if (key in obj) {
|
|
54
|
+
Object.defineProperty(obj, key, {
|
|
55
|
+
value,
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
obj[key] = value;
|
|
62
|
+
}
|
|
63
|
+
return obj;
|
|
71
64
|
}
|
|
72
65
|
var DEFAULT_STORAGE_READY_TIMEOUT_MS = 3e3;
|
|
73
66
|
function getLocalStorage() {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
try {
|
|
68
|
+
return typeof globalThis !== "undefined" && "localStorage" in globalThis ? globalThis.localStorage : void 0;
|
|
69
|
+
} catch (unused) {
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
79
72
|
}
|
|
80
|
-
var PersistenceManager = /* @__PURE__ */
|
|
81
|
-
|
|
73
|
+
var PersistenceManager = /* @__PURE__ */ (function() {
|
|
74
|
+
"use strict";
|
|
75
|
+
function PersistenceManager2(normalizedCache, mutationJournal, subscriptionManager, mutationEngine) {
|
|
76
|
+
var _this = this;
|
|
77
|
+
var options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {};
|
|
78
|
+
_class_call_check(this, PersistenceManager2);
|
|
79
|
+
var _ref, _ref1, _ref2;
|
|
80
|
+
var _options_tabCoordination, _options_tabCoordination1, _options_tabCoordination2;
|
|
81
|
+
_define_property(this, "persistenceStorage", void 0);
|
|
82
|
+
_define_property(this, "saveDebouncer", new import_pacer.Debouncer(function() {
|
|
83
|
+
return void _this.save();
|
|
84
|
+
}, { wait: 50 }));
|
|
85
|
+
_define_property(this, "broadcastChannel", void 0);
|
|
86
|
+
_define_property(this, "isLeader", false);
|
|
87
|
+
_define_property(this, "tabId", this.generateTabId());
|
|
88
|
+
_define_property(this, "leaderCheckInterval", void 0);
|
|
89
|
+
_define_property(this, "visibilityState", "visible");
|
|
90
|
+
_define_property(this, "lastVisibilityChange", Date.now());
|
|
91
|
+
_define_property(this, "pendingOperations", /* @__PURE__ */ new Set());
|
|
92
|
+
_define_property(this, "acceptingNewWork", true);
|
|
93
|
+
_define_property(this, "handoffInProgress", false);
|
|
94
|
+
_define_property(this, "tabCoordinationConfig", void 0);
|
|
95
|
+
_define_property(this, "leaderKey", "frappe-sync-leader");
|
|
96
|
+
_define_property(this, "cleanupVisibilityChange", void 0);
|
|
97
|
+
_define_property(this, "activeResponseTimers", /* @__PURE__ */ new Set());
|
|
98
|
+
_define_property(this, "isDestroyed", false);
|
|
99
|
+
_define_property(this, "loadPromise", Promise.resolve());
|
|
100
|
+
_define_property(this, "loadAbandoned", false);
|
|
101
|
+
_define_property(this, "loadTimer", void 0);
|
|
102
|
+
_define_property(this, "normalizedCache", void 0);
|
|
103
|
+
_define_property(this, "mutationJournal", void 0);
|
|
104
|
+
_define_property(this, "subscriptionManager", void 0);
|
|
105
|
+
_define_property(this, "mutationEngine", void 0);
|
|
106
|
+
_define_property(this, "options", void 0);
|
|
107
|
+
this.normalizedCache = normalizedCache;
|
|
108
|
+
this.mutationJournal = mutationJournal;
|
|
109
|
+
this.subscriptionManager = subscriptionManager;
|
|
110
|
+
this.mutationEngine = mutationEngine;
|
|
111
|
+
this.options = options;
|
|
112
|
+
this.tabCoordinationConfig = {
|
|
113
|
+
activeTabPriority: (_ref = (_options_tabCoordination = options.tabCoordination) === null || _options_tabCoordination === void 0 ? void 0 : _options_tabCoordination.activeTabPriority) !== null && _ref !== void 0 ? _ref : true,
|
|
114
|
+
leaderTimeout: (_ref1 = (_options_tabCoordination1 = options.tabCoordination) === null || _options_tabCoordination1 === void 0 ? void 0 : _options_tabCoordination1.leaderTimeout) !== null && _ref1 !== void 0 ? _ref1 : 5e3,
|
|
115
|
+
handoffGracePeriod: (_ref2 = (_options_tabCoordination2 = options.tabCoordination) === null || _options_tabCoordination2 === void 0 ? void 0 : _options_tabCoordination2.handoffGracePeriod) !== null && _ref2 !== void 0 ? _ref2 : 2e3
|
|
116
|
+
};
|
|
117
|
+
if (import_platform.isNative || (0, import_util.isGjs)()) {
|
|
118
|
+
this.setupPersistence();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this.setupPersistence();
|
|
125
|
+
this.setupBroadcastChannel();
|
|
126
|
+
if (this.options.persistKey && this.tabCoordinationConfig.activeTabPriority) {
|
|
127
|
+
this.setupTabCoordination();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
_create_class(PersistenceManager2, [
|
|
131
|
+
{
|
|
132
|
+
/**
|
|
133
|
+
* Resolves when the initial snapshot restore has completed (immediately if
|
|
134
|
+
* persistence is off). `SyncModule.subscribe` awaits this so a fresh mount
|
|
135
|
+
* can re-adopt a restored subscription instead of racing the async load.
|
|
136
|
+
*/
|
|
137
|
+
key: "whenReady",
|
|
138
|
+
value: function whenReady() {
|
|
139
|
+
return this.loadPromise;
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
key: "setupPersistence",
|
|
144
|
+
value: (
|
|
145
|
+
/**
|
|
146
|
+
* Sets up persistence storage based on environment and options.
|
|
147
|
+
*/
|
|
148
|
+
function setupPersistence() {
|
|
149
|
+
var _this_options_storageReadyTimeout;
|
|
150
|
+
if (!this.options.persistKey) return;
|
|
151
|
+
if (this.options.storage) {
|
|
152
|
+
this.persistenceStorage = this.options.storage;
|
|
153
|
+
} else if (typeof indexedDB !== "undefined") {
|
|
154
|
+
this.persistenceStorage = new import_storage.IndexedDBKV();
|
|
155
|
+
} else {
|
|
156
|
+
if ((0, import_util.isGjs)()) {
|
|
157
|
+
console.debug("[frappe-sync] persistKey set but no storage adapter on GJS — snapshots are in-memory only (pass SyncOptions.storage, e.g. a Gio file-backed KV, for real persistence)");
|
|
158
|
+
}
|
|
159
|
+
this.persistenceStorage = new import_storage.PlatformStorageKV();
|
|
160
|
+
}
|
|
161
|
+
this.loadPromise = this.loadWithin((_this_options_storageReadyTimeout = this.options.storageReadyTimeout) !== null && _this_options_storageReadyTimeout !== void 0 ? _this_options_storageReadyTimeout : DEFAULT_STORAGE_READY_TIMEOUT_MS);
|
|
162
|
+
})
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
key: "loadWithin",
|
|
166
|
+
value: function loadWithin(timeoutMs) {
|
|
167
|
+
var _this = this;
|
|
168
|
+
var storage = this.persistenceStorage;
|
|
169
|
+
var timedOut = new Promise(function(resolve) {
|
|
170
|
+
_this.loadTimer = setTimeout(function() {
|
|
171
|
+
return resolve("timeout");
|
|
172
|
+
}, timeoutMs);
|
|
173
|
+
});
|
|
174
|
+
return Promise.race([this.load().then(function() {
|
|
175
|
+
return "loaded";
|
|
176
|
+
}), timedOut]).then(function(outcome) {
|
|
177
|
+
clearTimeout(_this.loadTimer);
|
|
178
|
+
_this.loadTimer = void 0;
|
|
179
|
+
if (outcome !== "timeout" || _this.persistenceStorage !== storage) return;
|
|
180
|
+
_this.loadAbandoned = true;
|
|
181
|
+
_this.persistenceStorage = void 0;
|
|
182
|
+
console.warn(`[frappe-sync] the storage for persistKey "${_this.options.persistKey}" did not answer its first read within ${timeoutMs} ms; this session syncs in memory and persists nothing.`);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
key: "setupBroadcastChannel",
|
|
188
|
+
value: (
|
|
189
|
+
/**
|
|
190
|
+
* Sets up BroadcastChannel for cross-tab coordination.
|
|
191
|
+
* Handles both simple string messages and structured TabMessage types.
|
|
192
|
+
*/
|
|
193
|
+
function setupBroadcastChannel() {
|
|
194
|
+
var _this = this;
|
|
195
|
+
if (!this.options.persistKey || typeof BroadcastChannel === "undefined") return;
|
|
196
|
+
try {
|
|
197
|
+
this.broadcastChannel = new BroadcastChannel(`frappe-sync:${this.options.persistKey}`);
|
|
198
|
+
} catch (unused) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
this.broadcastChannel.onmessage = function(e) {
|
|
202
|
+
if (typeof (e === null || e === void 0 ? void 0 : e.data) === "string") {
|
|
203
|
+
if (e.data === "reset" && _this.options.onResetCache) {
|
|
204
|
+
_this.options.onResetCache();
|
|
205
|
+
}
|
|
206
|
+
if (e.data === "backfill" && _this.options.onBackfillAll) {
|
|
207
|
+
_this.options.onBackfillAll();
|
|
208
|
+
}
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
var message = e === null || e === void 0 ? void 0 : e.data;
|
|
212
|
+
if (!message || !message.type) return;
|
|
213
|
+
switch (message.type) {
|
|
214
|
+
case "visibility-check":
|
|
215
|
+
if (message.fromTab !== _this.tabId) {
|
|
216
|
+
_this.broadcastToTabs({
|
|
217
|
+
type: "visibility-response",
|
|
218
|
+
tabId: _this.tabId,
|
|
219
|
+
isVisible: _this.visibilityState === "visible"
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
case "leadership-request":
|
|
224
|
+
if (_this.isLeader && message.visibilityState === "visible" && _this.visibilityState === "hidden") {
|
|
225
|
+
_this.initiateGracefulHandoff();
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
case "leadership-handoff":
|
|
229
|
+
if (message.toTab === _this.tabId) {
|
|
230
|
+
if (message.state) {
|
|
231
|
+
_this.restoreStateFromHandoff(message.state);
|
|
232
|
+
}
|
|
233
|
+
_this.becomeLeader();
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
case "mutation":
|
|
237
|
+
if (!_this.isLeader && message.mutation) {
|
|
238
|
+
_this.handleRemoteMutation(message.mutation);
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
case "sync-state":
|
|
242
|
+
if (!_this.isLeader && message.state) {
|
|
243
|
+
_this.restoreStateFromHandoff(message.state);
|
|
244
|
+
}
|
|
245
|
+
break;
|
|
246
|
+
case "heartbeat": break;
|
|
247
|
+
case "visibility-response": break;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
})
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
key: "handleRemoteMutation",
|
|
254
|
+
value: (
|
|
255
|
+
/**
|
|
256
|
+
* Handles a mutation relayed from another tab.
|
|
257
|
+
* Updates local cache with the mutation's effects.
|
|
258
|
+
*/
|
|
259
|
+
function handleRemoteMutation(mutation) {
|
|
260
|
+
if (mutation.doc) {
|
|
261
|
+
if (mutation.operation === "delete") {
|
|
262
|
+
this.normalizedCache.remove({
|
|
263
|
+
doctype: mutation.doc.doctype,
|
|
264
|
+
name: mutation.doc.name
|
|
265
|
+
});
|
|
266
|
+
} else {
|
|
267
|
+
this.normalizedCache.upsert(mutation.doc);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
})
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
/**
|
|
274
|
+
* Broadcasts a mutation to other tabs.
|
|
275
|
+
* Called by SyncModule after a successful mutation.
|
|
276
|
+
*/
|
|
277
|
+
key: "broadcastMutation",
|
|
278
|
+
value: function broadcastMutation(mutation) {
|
|
279
|
+
if (!this.isLeader) return;
|
|
280
|
+
this.broadcastToTabs({
|
|
281
|
+
type: "mutation",
|
|
282
|
+
mutation
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
key: "restoreStateFromHandoff",
|
|
288
|
+
value: (
|
|
289
|
+
/**
|
|
290
|
+
* Restores state received from a leadership handoff or sync-state message.
|
|
291
|
+
*/
|
|
292
|
+
function restoreStateFromHandoff(state) {
|
|
293
|
+
if (!state || typeof state !== "object") return;
|
|
294
|
+
var handoffState = state;
|
|
295
|
+
if (handoffState.cache) {
|
|
296
|
+
this.normalizedCache.state = handoffState.cache;
|
|
297
|
+
}
|
|
298
|
+
if (handoffState.subscriptions && Array.isArray(handoffState.subscriptions)) {
|
|
299
|
+
var subscriptions = this.subscriptionManager.getAllSubscriptions();
|
|
300
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
301
|
+
try {
|
|
302
|
+
for (var _iterator = handoffState.subscriptions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
303
|
+
var subscription = _step.value;
|
|
304
|
+
if (subscription === null || subscription === void 0 ? void 0 : subscription.id) {
|
|
305
|
+
subscriptions.set(subscription.id, subscription);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
} catch (err) {
|
|
309
|
+
_didIteratorError = true;
|
|
310
|
+
_iteratorError = err;
|
|
311
|
+
} finally {
|
|
312
|
+
try {
|
|
313
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
314
|
+
_iterator.return();
|
|
315
|
+
}
|
|
316
|
+
} finally {
|
|
317
|
+
if (_didIteratorError) {
|
|
318
|
+
throw _iteratorError;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (handoffState.tempMappings && Array.isArray(handoffState.tempMappings)) {
|
|
324
|
+
var tempMap = this.mutationEngine.getTemporaryIdToRealNameMap();
|
|
325
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
|
326
|
+
try {
|
|
327
|
+
for (var _iterator1 = handoffState.tempMappings[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
328
|
+
var [tempId, realId] = _step1.value;
|
|
329
|
+
tempMap.set(tempId, realId);
|
|
330
|
+
}
|
|
331
|
+
} catch (err) {
|
|
332
|
+
_didIteratorError1 = true;
|
|
333
|
+
_iteratorError1 = err;
|
|
334
|
+
} finally {
|
|
335
|
+
try {
|
|
336
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
337
|
+
_iterator1.return();
|
|
338
|
+
}
|
|
339
|
+
} finally {
|
|
340
|
+
if (_didIteratorError1) {
|
|
341
|
+
throw _iteratorError1;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
})
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
/**
|
|
350
|
+
* Schedules a debounced save operation.
|
|
351
|
+
*/
|
|
352
|
+
key: "scheduleSave",
|
|
353
|
+
value: function scheduleSave() {
|
|
354
|
+
if (!this.options.persistKey) return;
|
|
355
|
+
this.saveDebouncer.maybeExecute();
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
key: "save",
|
|
360
|
+
value: (
|
|
361
|
+
/**
|
|
362
|
+
* Persists a snapshot of subscriptions, cache, journal, and temp mappings.
|
|
363
|
+
*/
|
|
364
|
+
async function save() {
|
|
365
|
+
if (!this.options.persistKey || !this.persistenceStorage) return;
|
|
366
|
+
try {
|
|
367
|
+
this.subscriptionManager.gcRestoredSubscriptions();
|
|
368
|
+
var snapshot = {
|
|
369
|
+
subs: [...this.subscriptionManager.getAllSubscriptions().values()].map(function(s) {
|
|
370
|
+
return {
|
|
371
|
+
id: s.id,
|
|
372
|
+
query: s.query,
|
|
373
|
+
checkpoint: s.checkpoint,
|
|
374
|
+
cursor: s.cursor,
|
|
375
|
+
docIds: s.docIds
|
|
376
|
+
};
|
|
377
|
+
}),
|
|
378
|
+
cache: this.normalizedCache.state,
|
|
379
|
+
journal: this.mutationJournal.listPending(),
|
|
380
|
+
temp: [...this.mutationEngine.getTemporaryIdToRealNameMap().entries()]
|
|
381
|
+
};
|
|
382
|
+
await this.persistenceStorage.setItem(this.options.persistKey, JSON.stringify(snapshot));
|
|
383
|
+
} catch (err) {
|
|
384
|
+
console.warn("Failed to save sync state:", err);
|
|
385
|
+
}
|
|
386
|
+
})
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
key: "load",
|
|
390
|
+
value: (
|
|
391
|
+
/**
|
|
392
|
+
* Loads a previously persisted snapshot if present.
|
|
393
|
+
*/
|
|
394
|
+
async function load() {
|
|
395
|
+
if (!this.options.persistKey || !this.persistenceStorage) return;
|
|
396
|
+
try {
|
|
397
|
+
var raw = await this.persistenceStorage.getItem(this.options.persistKey);
|
|
398
|
+
if (!raw || this.loadAbandoned) return;
|
|
399
|
+
var snap = JSON.parse(raw);
|
|
400
|
+
if ((snap === null || snap === void 0 ? void 0 : snap.cache) && typeof snap.cache === "object") {
|
|
401
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
402
|
+
try {
|
|
403
|
+
for (var _iterator = Object.values(snap.cache)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
404
|
+
var bucket = _step.value;
|
|
405
|
+
var byId = bucket === null || bucket === void 0 ? void 0 : bucket.byId;
|
|
406
|
+
if (!byId || typeof byId !== "object") continue;
|
|
407
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
|
408
|
+
try {
|
|
409
|
+
for (var _iterator1 = Object.values(byId)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
410
|
+
var doc = _step1.value;
|
|
411
|
+
if (!(doc === null || doc === void 0 ? void 0 : doc.doctype) || !(doc === null || doc === void 0 ? void 0 : doc.name)) continue;
|
|
412
|
+
if (this.normalizedCache.get(doc)) continue;
|
|
413
|
+
this.normalizedCache.upsert(doc, { replace: true });
|
|
414
|
+
}
|
|
415
|
+
} catch (err) {
|
|
416
|
+
_didIteratorError1 = true;
|
|
417
|
+
_iteratorError1 = err;
|
|
418
|
+
} finally {
|
|
419
|
+
try {
|
|
420
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
421
|
+
_iterator1.return();
|
|
422
|
+
}
|
|
423
|
+
} finally {
|
|
424
|
+
if (_didIteratorError1) {
|
|
425
|
+
throw _iteratorError1;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
} catch (err) {
|
|
431
|
+
_didIteratorError = true;
|
|
432
|
+
_iteratorError = err;
|
|
433
|
+
} finally {
|
|
434
|
+
try {
|
|
435
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
436
|
+
_iterator.return();
|
|
437
|
+
}
|
|
438
|
+
} finally {
|
|
439
|
+
if (_didIteratorError) {
|
|
440
|
+
throw _iteratorError;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if ((snap === null || snap === void 0 ? void 0 : snap.subs) && Array.isArray(snap.subs)) {
|
|
446
|
+
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
|
|
447
|
+
try {
|
|
448
|
+
for (var _iterator2 = snap.subs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
449
|
+
var subscription = _step2.value;
|
|
450
|
+
this.subscriptionManager.restoreSubscription(subscription);
|
|
451
|
+
}
|
|
452
|
+
} catch (err) {
|
|
453
|
+
_didIteratorError2 = true;
|
|
454
|
+
_iteratorError2 = err;
|
|
455
|
+
} finally {
|
|
456
|
+
try {
|
|
457
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
458
|
+
_iterator2.return();
|
|
459
|
+
}
|
|
460
|
+
} finally {
|
|
461
|
+
if (_didIteratorError2) {
|
|
462
|
+
throw _iteratorError2;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
if ((snap === null || snap === void 0 ? void 0 : snap.journal) && Array.isArray(snap.journal)) {
|
|
468
|
+
var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = void 0;
|
|
469
|
+
try {
|
|
470
|
+
for (var _iterator3 = snap.journal[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
471
|
+
var { id, entry } = _step3.value;
|
|
472
|
+
this.mutationJournal.add(id, entry);
|
|
473
|
+
}
|
|
474
|
+
} catch (err) {
|
|
475
|
+
_didIteratorError3 = true;
|
|
476
|
+
_iteratorError3 = err;
|
|
477
|
+
} finally {
|
|
478
|
+
try {
|
|
479
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
480
|
+
_iterator3.return();
|
|
481
|
+
}
|
|
482
|
+
} finally {
|
|
483
|
+
if (_didIteratorError3) {
|
|
484
|
+
throw _iteratorError3;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if ((snap === null || snap === void 0 ? void 0 : snap.temp) && Array.isArray(snap.temp)) {
|
|
490
|
+
var tempMap = this.mutationEngine.getTemporaryIdToRealNameMap();
|
|
491
|
+
var _iteratorNormalCompletion4 = true, _didIteratorError4 = false, _iteratorError4 = void 0;
|
|
492
|
+
try {
|
|
493
|
+
for (var _iterator4 = snap.temp[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
494
|
+
var [tempId, realId] = _step4.value;
|
|
495
|
+
tempMap.set(tempId, realId);
|
|
496
|
+
}
|
|
497
|
+
} catch (err) {
|
|
498
|
+
_didIteratorError4 = true;
|
|
499
|
+
_iteratorError4 = err;
|
|
500
|
+
} finally {
|
|
501
|
+
try {
|
|
502
|
+
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
|
|
503
|
+
_iterator4.return();
|
|
504
|
+
}
|
|
505
|
+
} finally {
|
|
506
|
+
if (_didIteratorError4) {
|
|
507
|
+
throw _iteratorError4;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
} catch (err) {
|
|
513
|
+
console.warn("Failed to load sync state:", err);
|
|
514
|
+
}
|
|
515
|
+
})
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
/**
|
|
519
|
+
* Broadcasts a reset message to other tabs.
|
|
520
|
+
*/
|
|
521
|
+
key: "broadcastReset",
|
|
522
|
+
value: function broadcastReset() {
|
|
523
|
+
if (this.broadcastChannel) {
|
|
524
|
+
this.broadcastChannel.postMessage("reset");
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
/**
|
|
530
|
+
* Broadcasts a backfill message to other tabs.
|
|
531
|
+
*/
|
|
532
|
+
key: "broadcastBackfill",
|
|
533
|
+
value: function broadcastBackfill() {
|
|
534
|
+
if (this.broadcastChannel) {
|
|
535
|
+
this.broadcastChannel.postMessage("backfill");
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
/**
|
|
541
|
+
* Broadcasts a generic change message to other tabs.
|
|
542
|
+
*/
|
|
543
|
+
key: "broadcastChange",
|
|
544
|
+
value: function broadcastChange() {
|
|
545
|
+
if (this.broadcastChannel) {
|
|
546
|
+
this.broadcastChannel.postMessage("changed");
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
key: "setupTabCoordination",
|
|
552
|
+
value: (
|
|
553
|
+
/**
|
|
554
|
+
* Sets up tab coordination with active tab priority.
|
|
555
|
+
*/
|
|
556
|
+
function setupTabCoordination() {
|
|
557
|
+
var _this = this;
|
|
558
|
+
this.visibilityState = typeof document !== "undefined" && document.hidden ? "hidden" : "visible";
|
|
559
|
+
this.cleanupVisibilityChange = (0, import_platform.onVisibilityChange)(function(visible) {
|
|
560
|
+
if (_this.isDestroyed) return;
|
|
561
|
+
var wasVisible = _this.visibilityState === "visible";
|
|
562
|
+
_this.visibilityState = visible ? "visible" : "hidden";
|
|
563
|
+
_this.lastVisibilityChange = Date.now();
|
|
564
|
+
if (!wasVisible && _this.visibilityState === "visible") {
|
|
565
|
+
_this.evaluateLeadershipPriority();
|
|
566
|
+
} else if (wasVisible && _this.visibilityState === "hidden" && _this.isLeader) {
|
|
567
|
+
_this.considerLeadershipHandoff();
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
this.tryBecomeLeader();
|
|
571
|
+
})
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
key: "tryBecomeLeader",
|
|
575
|
+
value: (
|
|
576
|
+
/**
|
|
577
|
+
* Attempts to become the leader tab.
|
|
578
|
+
*/
|
|
579
|
+
function tryBecomeLeader() {
|
|
580
|
+
var _this = this;
|
|
581
|
+
if (!getLocalStorage() || this.isDestroyed) return;
|
|
582
|
+
var now = Date.now();
|
|
583
|
+
var leaderData = this.getLeaderData();
|
|
584
|
+
if (!leaderData || now - leaderData.timestamp > this.tabCoordinationConfig.leaderTimeout || this.visibilityState === "visible" && leaderData.visibilityState === "hidden") {
|
|
585
|
+
this.becomeLeader();
|
|
586
|
+
} else {
|
|
587
|
+
if (this.leaderCheckInterval) {
|
|
588
|
+
clearInterval(this.leaderCheckInterval);
|
|
589
|
+
}
|
|
590
|
+
this.leaderCheckInterval = setInterval(function() {
|
|
591
|
+
if (!_this.isDestroyed) {
|
|
592
|
+
_this.checkLeadership();
|
|
593
|
+
}
|
|
594
|
+
}, this.tabCoordinationConfig.leaderTimeout / 2);
|
|
595
|
+
}
|
|
596
|
+
})
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
key: "becomeLeader",
|
|
600
|
+
value: (
|
|
601
|
+
/**
|
|
602
|
+
* Becomes the leader tab.
|
|
603
|
+
*/
|
|
604
|
+
function becomeLeader() {
|
|
605
|
+
var _this = this;
|
|
606
|
+
if (this.isDestroyed) return;
|
|
607
|
+
this.isLeader = true;
|
|
608
|
+
this.updateLeaderTimestamp();
|
|
609
|
+
this.onBecomeLeader();
|
|
610
|
+
if (this.leaderCheckInterval) {
|
|
611
|
+
clearInterval(this.leaderCheckInterval);
|
|
612
|
+
}
|
|
613
|
+
this.leaderCheckInterval = setInterval(function() {
|
|
614
|
+
if (!_this.isDestroyed) {
|
|
615
|
+
_this.updateLeaderTimestamp();
|
|
616
|
+
}
|
|
617
|
+
}, this.tabCoordinationConfig.leaderTimeout / 2);
|
|
618
|
+
})
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
key: "updateLeaderTimestamp",
|
|
622
|
+
value: (
|
|
623
|
+
/**
|
|
624
|
+
* Updates leader timestamp in localStorage.
|
|
625
|
+
*/
|
|
626
|
+
function updateLeaderTimestamp() {
|
|
627
|
+
var ls = getLocalStorage();
|
|
628
|
+
if (!ls) return;
|
|
629
|
+
var leaderData = {
|
|
630
|
+
tabId: this.tabId,
|
|
631
|
+
timestamp: Date.now(),
|
|
632
|
+
visibilityState: this.visibilityState,
|
|
633
|
+
lastVisibilityChange: this.lastVisibilityChange
|
|
634
|
+
};
|
|
635
|
+
try {
|
|
636
|
+
ls.setItem(this.leaderKey, JSON.stringify(leaderData));
|
|
637
|
+
} catch (error) {
|
|
638
|
+
console.warn("[PersistenceManager] Failed to update leader timestamp:", error);
|
|
639
|
+
}
|
|
640
|
+
})
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
key: "checkLeadership",
|
|
644
|
+
value: (
|
|
645
|
+
/**
|
|
646
|
+
* Checks if this tab should remain leader.
|
|
647
|
+
*/
|
|
648
|
+
function checkLeadership() {
|
|
649
|
+
var leaderData = this.getLeaderData();
|
|
650
|
+
if (!leaderData) {
|
|
651
|
+
this.tryBecomeLeader();
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
var now = Date.now();
|
|
655
|
+
if (this.isLeader) {
|
|
656
|
+
if (leaderData.tabId !== this.tabId) {
|
|
657
|
+
this.isLeader = false;
|
|
658
|
+
this.onLoseLeadership();
|
|
659
|
+
}
|
|
660
|
+
} else {
|
|
661
|
+
if (now - leaderData.timestamp > this.tabCoordinationConfig.leaderTimeout || this.visibilityState === "visible" && leaderData.visibilityState === "hidden" && now - this.lastVisibilityChange > 1e3) {
|
|
662
|
+
this.tryBecomeLeader();
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
})
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
key: "getLeaderData",
|
|
669
|
+
value: (
|
|
670
|
+
/**
|
|
671
|
+
* Gets current leader data from localStorage.
|
|
672
|
+
*/
|
|
673
|
+
function getLeaderData() {
|
|
674
|
+
var ls = getLocalStorage();
|
|
675
|
+
if (!ls) return null;
|
|
676
|
+
try {
|
|
677
|
+
var data = ls.getItem(this.leaderKey);
|
|
678
|
+
return data ? JSON.parse(data) : null;
|
|
679
|
+
} catch (unused) {
|
|
680
|
+
return null;
|
|
681
|
+
}
|
|
682
|
+
})
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
key: "evaluateLeadershipPriority",
|
|
686
|
+
value: (
|
|
687
|
+
/**
|
|
688
|
+
* Evaluates if this tab should take leadership based on visibility priority.
|
|
689
|
+
*/
|
|
690
|
+
function evaluateLeadershipPriority() {
|
|
691
|
+
if (this.isLeader) return;
|
|
692
|
+
var leaderData = this.getLeaderData();
|
|
693
|
+
if (!leaderData) {
|
|
694
|
+
this.tryBecomeLeader();
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
if (leaderData.visibilityState === "hidden" && this.visibilityState === "visible") {
|
|
698
|
+
this.requestLeadershipHandoff();
|
|
699
|
+
}
|
|
700
|
+
})
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
key: "considerLeadershipHandoff",
|
|
704
|
+
value: (
|
|
705
|
+
/**
|
|
706
|
+
* Considers handing off leadership when tab becomes hidden.
|
|
707
|
+
*/
|
|
708
|
+
function considerLeadershipHandoff() {
|
|
709
|
+
var _this = this;
|
|
710
|
+
if (!this.isLeader) return;
|
|
711
|
+
this.checkForActiveTabs(function(hasActiveTabs) {
|
|
712
|
+
if (hasActiveTabs) {
|
|
713
|
+
_this.initiateGracefulHandoff();
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
})
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
key: "requestLeadershipHandoff",
|
|
720
|
+
value: (
|
|
721
|
+
/**
|
|
722
|
+
* Requests leadership handoff from current leader.
|
|
723
|
+
*/
|
|
724
|
+
function requestLeadershipHandoff() {
|
|
725
|
+
this.broadcastToTabs({
|
|
726
|
+
type: "leadership-request",
|
|
727
|
+
tabId: this.tabId,
|
|
728
|
+
visibilityState: this.visibilityState
|
|
729
|
+
});
|
|
730
|
+
})
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
key: "initiateGracefulHandoff",
|
|
734
|
+
value: (
|
|
735
|
+
/**
|
|
736
|
+
* Initiates graceful handoff to another tab.
|
|
737
|
+
*/
|
|
738
|
+
async function initiateGracefulHandoff() {
|
|
739
|
+
if (!this.isLeader || this.handoffInProgress) return;
|
|
740
|
+
this.handoffInProgress = true;
|
|
741
|
+
this.acceptingNewWork = false;
|
|
742
|
+
await this.waitForPendingOperations();
|
|
743
|
+
var successor = await this.findSuccessor();
|
|
744
|
+
if (successor) {
|
|
745
|
+
var state = await this.captureState();
|
|
746
|
+
this.broadcastToTabs({
|
|
747
|
+
type: "leadership-handoff",
|
|
748
|
+
fromTab: this.tabId,
|
|
749
|
+
toTab: successor,
|
|
750
|
+
state
|
|
751
|
+
});
|
|
752
|
+
this.isLeader = false;
|
|
753
|
+
this.onLoseLeadership();
|
|
754
|
+
}
|
|
755
|
+
this.handoffInProgress = false;
|
|
756
|
+
this.acceptingNewWork = true;
|
|
757
|
+
})
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
key: "waitForPendingOperations",
|
|
761
|
+
value: (
|
|
762
|
+
/**
|
|
763
|
+
* Waits for all pending operations to complete.
|
|
764
|
+
*/
|
|
765
|
+
async function waitForPendingOperations() {
|
|
766
|
+
var _this = this;
|
|
767
|
+
var timeout = new Promise(function(resolve) {
|
|
768
|
+
return setTimeout(resolve, _this.tabCoordinationConfig.handoffGracePeriod);
|
|
769
|
+
});
|
|
770
|
+
var operations = Promise.all(this.pendingOperations);
|
|
771
|
+
await Promise.race([operations, timeout]);
|
|
772
|
+
})
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
key: "findSuccessor",
|
|
776
|
+
value: (
|
|
777
|
+
/**
|
|
778
|
+
* Finds a suitable successor for leadership.
|
|
779
|
+
*/
|
|
780
|
+
async function findSuccessor() {
|
|
781
|
+
var _this = this;
|
|
782
|
+
return new Promise(function(resolve) {
|
|
783
|
+
if (_this.isDestroyed || typeof document === "undefined") {
|
|
784
|
+
resolve(null);
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
var responses = [];
|
|
788
|
+
var handleResponse = function handleResponse2(event) {
|
|
789
|
+
var _event_data;
|
|
790
|
+
if (((_event_data = event.data) === null || _event_data === void 0 ? void 0 : _event_data.type) === "visibility-response") {
|
|
791
|
+
responses.push({
|
|
792
|
+
tabId: event.data.tabId,
|
|
793
|
+
isVisible: event.data.isVisible
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
window.addEventListener("message", handleResponse);
|
|
798
|
+
_this.broadcastToTabs({
|
|
799
|
+
type: "visibility-check",
|
|
800
|
+
fromTab: _this.tabId
|
|
801
|
+
});
|
|
802
|
+
var responseTimer = setTimeout(function() {
|
|
803
|
+
var _responses_;
|
|
804
|
+
_this.activeResponseTimers.delete(responseTimer);
|
|
805
|
+
window.removeEventListener("message", handleResponse);
|
|
806
|
+
var visibleTab = responses.find(function(r) {
|
|
807
|
+
return r.isVisible;
|
|
808
|
+
});
|
|
809
|
+
resolve(visibleTab ? visibleTab.tabId : ((_responses_ = responses[0]) === null || _responses_ === void 0 ? void 0 : _responses_.tabId) || null);
|
|
810
|
+
}, 500);
|
|
811
|
+
_this.activeResponseTimers.add(responseTimer);
|
|
812
|
+
});
|
|
813
|
+
})
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
key: "checkForActiveTabs",
|
|
817
|
+
value: (
|
|
818
|
+
/**
|
|
819
|
+
* Checks if there are other active tabs.
|
|
820
|
+
*/
|
|
821
|
+
function checkForActiveTabs(callback) {
|
|
822
|
+
var _this = this;
|
|
823
|
+
if (this.isDestroyed || typeof document === "undefined") {
|
|
824
|
+
callback(false);
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
var responses = [];
|
|
828
|
+
var handleResponse = function handleResponse2(event) {
|
|
829
|
+
var _event_data;
|
|
830
|
+
if (((_event_data = event.data) === null || _event_data === void 0 ? void 0 : _event_data.type) === "visibility-response") {
|
|
831
|
+
responses.push(event.data.isVisible);
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
window.addEventListener("message", handleResponse);
|
|
835
|
+
this.broadcastToTabs({
|
|
836
|
+
type: "visibility-check",
|
|
837
|
+
fromTab: this.tabId
|
|
838
|
+
});
|
|
839
|
+
var responseTimer = setTimeout(function() {
|
|
840
|
+
_this.activeResponseTimers.delete(responseTimer);
|
|
841
|
+
window.removeEventListener("message", handleResponse);
|
|
842
|
+
callback(responses.some(function(isVisible) {
|
|
843
|
+
return isVisible;
|
|
844
|
+
}));
|
|
845
|
+
}, 500);
|
|
846
|
+
this.activeResponseTimers.add(responseTimer);
|
|
847
|
+
})
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
key: "captureState",
|
|
851
|
+
value: (
|
|
852
|
+
/**
|
|
853
|
+
* Captures current state for handoff.
|
|
854
|
+
*/
|
|
855
|
+
async function captureState() {
|
|
856
|
+
return {
|
|
857
|
+
cache: this.normalizedCache.state,
|
|
858
|
+
journal: this.mutationJournal.listPending(),
|
|
859
|
+
subscriptions: [...this.subscriptionManager.getAllSubscriptions().values()],
|
|
860
|
+
tempMappings: [...this.mutationEngine.getTemporaryIdToRealNameMap().entries()]
|
|
861
|
+
};
|
|
862
|
+
})
|
|
863
|
+
},
|
|
864
|
+
{
|
|
865
|
+
key: "broadcastToTabs",
|
|
866
|
+
value: (
|
|
867
|
+
/**
|
|
868
|
+
* Broadcasts message to other tabs.
|
|
869
|
+
*/
|
|
870
|
+
function broadcastToTabs(message) {
|
|
871
|
+
if (this.broadcastChannel) {
|
|
872
|
+
this.broadcastChannel.postMessage(message);
|
|
873
|
+
}
|
|
874
|
+
var ls = getLocalStorage();
|
|
875
|
+
if (ls) {
|
|
876
|
+
try {
|
|
877
|
+
var key = `frappe-sync-msg-${Date.now()}`;
|
|
878
|
+
ls.setItem(key, JSON.stringify(message));
|
|
879
|
+
setTimeout(function() {
|
|
880
|
+
return ls.removeItem(key);
|
|
881
|
+
}, 100);
|
|
882
|
+
} catch (unused) {}
|
|
883
|
+
}
|
|
884
|
+
})
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
key: "onBecomeLeader",
|
|
888
|
+
value: (
|
|
889
|
+
/**
|
|
890
|
+
* Handles becoming the leader.
|
|
891
|
+
*/
|
|
892
|
+
function onBecomeLeader() {
|
|
893
|
+
console.debug(`[PersistenceManager] Tab ${this.tabId} became leader`);
|
|
894
|
+
if (this.options.onBecomeLeader) {
|
|
895
|
+
this.options.onBecomeLeader();
|
|
896
|
+
}
|
|
897
|
+
})
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
key: "onLoseLeadership",
|
|
901
|
+
value: (
|
|
902
|
+
/**
|
|
903
|
+
* Handles losing leadership.
|
|
904
|
+
*/
|
|
905
|
+
function onLoseLeadership() {
|
|
906
|
+
console.debug(`[PersistenceManager] Tab ${this.tabId} lost leadership`);
|
|
907
|
+
if (this.leaderCheckInterval) {
|
|
908
|
+
clearInterval(this.leaderCheckInterval);
|
|
909
|
+
this.leaderCheckInterval = void 0;
|
|
910
|
+
}
|
|
911
|
+
if (this.options.onLoseLeadership) {
|
|
912
|
+
this.options.onLoseLeadership();
|
|
913
|
+
}
|
|
914
|
+
})
|
|
915
|
+
},
|
|
916
|
+
{
|
|
917
|
+
key: "generateTabId",
|
|
918
|
+
value: (
|
|
919
|
+
/**
|
|
920
|
+
* Generates a unique tab ID.
|
|
921
|
+
*/
|
|
922
|
+
function generateTabId() {
|
|
923
|
+
return `tab-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
924
|
+
})
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
/**
|
|
928
|
+
* Tracks a pending operation.
|
|
929
|
+
*/
|
|
930
|
+
key: "trackOperation",
|
|
931
|
+
value: function trackOperation(operation) {
|
|
932
|
+
var _this = this;
|
|
933
|
+
this.pendingOperations.add(operation);
|
|
934
|
+
operation.finally(function() {
|
|
935
|
+
_this.pendingOperations.delete(operation);
|
|
936
|
+
}).catch(function() {});
|
|
937
|
+
return operation;
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
{
|
|
941
|
+
/**
|
|
942
|
+
* Gets whether this tab is the leader.
|
|
943
|
+
*/
|
|
944
|
+
key: "getIsLeader",
|
|
945
|
+
value: function getIsLeader() {
|
|
946
|
+
return this.isLeader;
|
|
947
|
+
}
|
|
948
|
+
},
|
|
949
|
+
{
|
|
950
|
+
/**
|
|
951
|
+
* Cleans up timers, event listeners, and channels.
|
|
952
|
+
*/
|
|
953
|
+
key: "destroy",
|
|
954
|
+
value: function destroy() {
|
|
955
|
+
var _this_cleanupVisibilityChange, _this;
|
|
956
|
+
this.isDestroyed = true;
|
|
957
|
+
this.saveDebouncer.cancel();
|
|
958
|
+
clearTimeout(this.loadTimer);
|
|
959
|
+
this.loadTimer = void 0;
|
|
960
|
+
if (this.leaderCheckInterval) {
|
|
961
|
+
clearInterval(this.leaderCheckInterval);
|
|
962
|
+
this.leaderCheckInterval = void 0;
|
|
963
|
+
}
|
|
964
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
965
|
+
try {
|
|
966
|
+
for (var _iterator = this.activeResponseTimers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
967
|
+
var timer = _step.value;
|
|
968
|
+
clearTimeout(timer);
|
|
969
|
+
}
|
|
970
|
+
} catch (err) {
|
|
971
|
+
_didIteratorError = true;
|
|
972
|
+
_iteratorError = err;
|
|
973
|
+
} finally {
|
|
974
|
+
try {
|
|
975
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
976
|
+
_iterator.return();
|
|
977
|
+
}
|
|
978
|
+
} finally {
|
|
979
|
+
if (_didIteratorError) {
|
|
980
|
+
throw _iteratorError;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
this.activeResponseTimers.clear();
|
|
985
|
+
(_this_cleanupVisibilityChange = (_this = this).cleanupVisibilityChange) === null || _this_cleanupVisibilityChange === void 0 ? void 0 : _this_cleanupVisibilityChange.call(_this);
|
|
986
|
+
this.cleanupVisibilityChange = void 0;
|
|
987
|
+
if (this.broadcastChannel) {
|
|
988
|
+
this.broadcastChannel.close();
|
|
989
|
+
this.broadcastChannel = void 0;
|
|
990
|
+
}
|
|
991
|
+
this.pendingOperations.clear();
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
]);
|
|
995
|
+
return PersistenceManager2;
|
|
996
|
+
})();
|
|
82
997
|
|
|
83
|
-
function PersistenceManager2(normalizedCache, mutationJournal, subscriptionManager, mutationEngine) {
|
|
84
|
-
var _this = this;
|
|
85
|
-
var options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {};
|
|
86
|
-
_class_call_check(this, PersistenceManager2);
|
|
87
|
-
var _ref, _ref1, _ref2;
|
|
88
|
-
var _options_tabCoordination, _options_tabCoordination1, _options_tabCoordination2;
|
|
89
|
-
_define_property(this, "persistenceStorage", void 0);
|
|
90
|
-
_define_property(this, "saveDebouncer", new import_pacer.Debouncer(function () {
|
|
91
|
-
return void _this.save();
|
|
92
|
-
}, {
|
|
93
|
-
wait: 50
|
|
94
|
-
}));
|
|
95
|
-
_define_property(this, "broadcastChannel", void 0);
|
|
96
|
-
_define_property(this, "isLeader", false);
|
|
97
|
-
_define_property(this, "tabId", this.generateTabId());
|
|
98
|
-
_define_property(this, "leaderCheckInterval", void 0);
|
|
99
|
-
_define_property(this, "visibilityState", "visible");
|
|
100
|
-
_define_property(this, "lastVisibilityChange", Date.now());
|
|
101
|
-
_define_property(this, "pendingOperations", /* @__PURE__ */new Set());
|
|
102
|
-
_define_property(this, "acceptingNewWork", true);
|
|
103
|
-
_define_property(this, "handoffInProgress", false);
|
|
104
|
-
_define_property(this, "tabCoordinationConfig", void 0);
|
|
105
|
-
_define_property(this, "leaderKey", "frappe-sync-leader");
|
|
106
|
-
_define_property(this, "cleanupVisibilityChange", void 0);
|
|
107
|
-
_define_property(this, "activeResponseTimers", /* @__PURE__ */new Set());
|
|
108
|
-
_define_property(this, "isDestroyed", false);
|
|
109
|
-
_define_property(this, "loadPromise", Promise.resolve());
|
|
110
|
-
_define_property(this, "loadAbandoned", false);
|
|
111
|
-
_define_property(this, "loadTimer", void 0);
|
|
112
|
-
_define_property(this, "normalizedCache", void 0);
|
|
113
|
-
_define_property(this, "mutationJournal", void 0);
|
|
114
|
-
_define_property(this, "subscriptionManager", void 0);
|
|
115
|
-
_define_property(this, "mutationEngine", void 0);
|
|
116
|
-
_define_property(this, "options", void 0);
|
|
117
|
-
this.normalizedCache = normalizedCache;
|
|
118
|
-
this.mutationJournal = mutationJournal;
|
|
119
|
-
this.subscriptionManager = subscriptionManager;
|
|
120
|
-
this.mutationEngine = mutationEngine;
|
|
121
|
-
this.options = options;
|
|
122
|
-
this.tabCoordinationConfig = {
|
|
123
|
-
activeTabPriority: (_ref = (_options_tabCoordination = options.tabCoordination) === null || _options_tabCoordination === void 0 ? void 0 : _options_tabCoordination.activeTabPriority) !== null && _ref !== void 0 ? _ref : true,
|
|
124
|
-
leaderTimeout: (_ref1 = (_options_tabCoordination1 = options.tabCoordination) === null || _options_tabCoordination1 === void 0 ? void 0 : _options_tabCoordination1.leaderTimeout) !== null && _ref1 !== void 0 ? _ref1 : 5e3,
|
|
125
|
-
handoffGracePeriod: (_ref2 = (_options_tabCoordination2 = options.tabCoordination) === null || _options_tabCoordination2 === void 0 ? void 0 : _options_tabCoordination2.handoffGracePeriod) !== null && _ref2 !== void 0 ? _ref2 : 2e3
|
|
126
|
-
};
|
|
127
|
-
if (import_platform.isNative || (0, import_util.isGjs)()) {
|
|
128
|
-
this.setupPersistence();
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
this.setupPersistence();
|
|
135
|
-
this.setupBroadcastChannel();
|
|
136
|
-
if (this.options.persistKey && this.tabCoordinationConfig.activeTabPriority) {
|
|
137
|
-
this.setupTabCoordination();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
_create_class(PersistenceManager2, [{
|
|
141
|
-
/**
|
|
142
|
-
* Resolves when the initial snapshot restore has completed (immediately if
|
|
143
|
-
* persistence is off). `SyncModule.subscribe` awaits this so a fresh mount
|
|
144
|
-
* can re-adopt a restored subscription instead of racing the async load.
|
|
145
|
-
*/
|
|
146
|
-
key: "whenReady",
|
|
147
|
-
value: function whenReady() {
|
|
148
|
-
return this.loadPromise;
|
|
149
|
-
}
|
|
150
|
-
}, {
|
|
151
|
-
key: "setupPersistence",
|
|
152
|
-
value: (
|
|
153
|
-
/**
|
|
154
|
-
* Sets up persistence storage based on environment and options.
|
|
155
|
-
*/
|
|
156
|
-
function setupPersistence() {
|
|
157
|
-
var _this_options_storageReadyTimeout;
|
|
158
|
-
if (!this.options.persistKey) return;
|
|
159
|
-
if (this.options.storage) {
|
|
160
|
-
this.persistenceStorage = this.options.storage;
|
|
161
|
-
} else if (typeof indexedDB !== "undefined") {
|
|
162
|
-
this.persistenceStorage = new import_storage.IndexedDBKV();
|
|
163
|
-
} else {
|
|
164
|
-
if ((0, import_util.isGjs)()) {
|
|
165
|
-
console.debug("[frappe-sync] persistKey set but no storage adapter on GJS \u2014 snapshots are in-memory only (pass SyncOptions.storage, e.g. a Gio file-backed KV, for real persistence)");
|
|
166
|
-
}
|
|
167
|
-
this.persistenceStorage = new import_storage.PlatformStorageKV();
|
|
168
|
-
}
|
|
169
|
-
this.loadPromise = this.loadWithin((_this_options_storageReadyTimeout = this.options.storageReadyTimeout) !== null && _this_options_storageReadyTimeout !== void 0 ? _this_options_storageReadyTimeout : DEFAULT_STORAGE_READY_TIMEOUT_MS);
|
|
170
|
-
})
|
|
171
|
-
}, {
|
|
172
|
-
key: "loadWithin",
|
|
173
|
-
value: function loadWithin(timeoutMs) {
|
|
174
|
-
var _this = this;
|
|
175
|
-
var storage = this.persistenceStorage;
|
|
176
|
-
var timedOut = new Promise(function (resolve) {
|
|
177
|
-
_this.loadTimer = setTimeout(function () {
|
|
178
|
-
return resolve("timeout");
|
|
179
|
-
}, timeoutMs);
|
|
180
|
-
});
|
|
181
|
-
return Promise.race([this.load().then(function () {
|
|
182
|
-
return "loaded";
|
|
183
|
-
}), timedOut]).then(function (outcome) {
|
|
184
|
-
clearTimeout(_this.loadTimer);
|
|
185
|
-
_this.loadTimer = void 0;
|
|
186
|
-
if (outcome !== "timeout" || _this.persistenceStorage !== storage) return;
|
|
187
|
-
_this.loadAbandoned = true;
|
|
188
|
-
_this.persistenceStorage = void 0;
|
|
189
|
-
console.warn(`[frappe-sync] the storage for persistKey "${_this.options.persistKey}" did not answer its first read within ${timeoutMs} ms; this session syncs in memory and persists nothing.`);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}, {
|
|
193
|
-
key: "setupBroadcastChannel",
|
|
194
|
-
value: (
|
|
195
|
-
/**
|
|
196
|
-
* Sets up BroadcastChannel for cross-tab coordination.
|
|
197
|
-
* Handles both simple string messages and structured TabMessage types.
|
|
198
|
-
*/
|
|
199
|
-
function setupBroadcastChannel() {
|
|
200
|
-
var _this = this;
|
|
201
|
-
if (!this.options.persistKey || typeof BroadcastChannel === "undefined") return;
|
|
202
|
-
try {
|
|
203
|
-
this.broadcastChannel = new BroadcastChannel(`frappe-sync:${this.options.persistKey}`);
|
|
204
|
-
} catch (unused) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
this.broadcastChannel.onmessage = function (e) {
|
|
208
|
-
if (typeof (e === null || e === void 0 ? void 0 : e.data) === "string") {
|
|
209
|
-
if (e.data === "reset" && _this.options.onResetCache) {
|
|
210
|
-
_this.options.onResetCache();
|
|
211
|
-
}
|
|
212
|
-
if (e.data === "backfill" && _this.options.onBackfillAll) {
|
|
213
|
-
_this.options.onBackfillAll();
|
|
214
|
-
}
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
var message = e === null || e === void 0 ? void 0 : e.data;
|
|
218
|
-
if (!message || !message.type) return;
|
|
219
|
-
switch (message.type) {
|
|
220
|
-
case "visibility-check":
|
|
221
|
-
if (message.fromTab !== _this.tabId) {
|
|
222
|
-
_this.broadcastToTabs({
|
|
223
|
-
type: "visibility-response",
|
|
224
|
-
tabId: _this.tabId,
|
|
225
|
-
isVisible: _this.visibilityState === "visible"
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
break;
|
|
229
|
-
case "leadership-request":
|
|
230
|
-
if (_this.isLeader && message.visibilityState === "visible" && _this.visibilityState === "hidden") {
|
|
231
|
-
_this.initiateGracefulHandoff();
|
|
232
|
-
}
|
|
233
|
-
break;
|
|
234
|
-
case "leadership-handoff":
|
|
235
|
-
if (message.toTab === _this.tabId) {
|
|
236
|
-
if (message.state) {
|
|
237
|
-
_this.restoreStateFromHandoff(message.state);
|
|
238
|
-
}
|
|
239
|
-
_this.becomeLeader();
|
|
240
|
-
}
|
|
241
|
-
break;
|
|
242
|
-
case "mutation":
|
|
243
|
-
if (!_this.isLeader && message.mutation) {
|
|
244
|
-
_this.handleRemoteMutation(message.mutation);
|
|
245
|
-
}
|
|
246
|
-
break;
|
|
247
|
-
case "sync-state":
|
|
248
|
-
if (!_this.isLeader && message.state) {
|
|
249
|
-
_this.restoreStateFromHandoff(message.state);
|
|
250
|
-
}
|
|
251
|
-
break;
|
|
252
|
-
case "heartbeat":
|
|
253
|
-
break;
|
|
254
|
-
case "visibility-response":
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
})
|
|
259
|
-
}, {
|
|
260
|
-
key: "handleRemoteMutation",
|
|
261
|
-
value: (
|
|
262
|
-
/**
|
|
263
|
-
* Handles a mutation relayed from another tab.
|
|
264
|
-
* Updates local cache with the mutation's effects.
|
|
265
|
-
*/
|
|
266
|
-
function handleRemoteMutation(mutation) {
|
|
267
|
-
if (mutation.doc) {
|
|
268
|
-
if (mutation.operation === "delete") {
|
|
269
|
-
this.normalizedCache.remove({
|
|
270
|
-
doctype: mutation.doc.doctype,
|
|
271
|
-
name: mutation.doc.name
|
|
272
|
-
});
|
|
273
|
-
} else {
|
|
274
|
-
this.normalizedCache.upsert(mutation.doc);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
})
|
|
278
|
-
}, {
|
|
279
|
-
/**
|
|
280
|
-
* Broadcasts a mutation to other tabs.
|
|
281
|
-
* Called by SyncModule after a successful mutation.
|
|
282
|
-
*/
|
|
283
|
-
key: "broadcastMutation",
|
|
284
|
-
value: function broadcastMutation(mutation) {
|
|
285
|
-
if (!this.isLeader) return;
|
|
286
|
-
this.broadcastToTabs({
|
|
287
|
-
type: "mutation",
|
|
288
|
-
mutation
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
}, {
|
|
292
|
-
key: "restoreStateFromHandoff",
|
|
293
|
-
value: (
|
|
294
|
-
/**
|
|
295
|
-
* Restores state received from a leadership handoff or sync-state message.
|
|
296
|
-
*/
|
|
297
|
-
function restoreStateFromHandoff(state) {
|
|
298
|
-
if (!state || (typeof state === "undefined" ? "undefined" : _type_of(state)) !== "object") return;
|
|
299
|
-
var handoffState = state;
|
|
300
|
-
if (handoffState.cache) {
|
|
301
|
-
this.normalizedCache.state = handoffState.cache;
|
|
302
|
-
}
|
|
303
|
-
if (handoffState.subscriptions && Array.isArray(handoffState.subscriptions)) {
|
|
304
|
-
var subscriptions = this.subscriptionManager.getAllSubscriptions();
|
|
305
|
-
var _iteratorNormalCompletion = true,
|
|
306
|
-
_didIteratorError = false,
|
|
307
|
-
_iteratorError = void 0;
|
|
308
|
-
try {
|
|
309
|
-
for (var _iterator = handoffState.subscriptions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
310
|
-
var subscription = _step.value;
|
|
311
|
-
if (subscription === null || subscription === void 0 ? void 0 : subscription.id) {
|
|
312
|
-
subscriptions.set(subscription.id, subscription);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
} catch (err) {
|
|
316
|
-
_didIteratorError = true;
|
|
317
|
-
_iteratorError = err;
|
|
318
|
-
} finally {
|
|
319
|
-
try {
|
|
320
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
321
|
-
_iterator.return();
|
|
322
|
-
}
|
|
323
|
-
} finally {
|
|
324
|
-
if (_didIteratorError) {
|
|
325
|
-
throw _iteratorError;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (handoffState.tempMappings && Array.isArray(handoffState.tempMappings)) {
|
|
331
|
-
var tempMap = this.mutationEngine.getTemporaryIdToRealNameMap();
|
|
332
|
-
var _iteratorNormalCompletion1 = true,
|
|
333
|
-
_didIteratorError1 = false,
|
|
334
|
-
_iteratorError1 = void 0;
|
|
335
|
-
try {
|
|
336
|
-
for (var _iterator1 = handoffState.tempMappings[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
337
|
-
var [tempId, realId] = _step1.value;
|
|
338
|
-
tempMap.set(tempId, realId);
|
|
339
|
-
}
|
|
340
|
-
} catch (err) {
|
|
341
|
-
_didIteratorError1 = true;
|
|
342
|
-
_iteratorError1 = err;
|
|
343
|
-
} finally {
|
|
344
|
-
try {
|
|
345
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
346
|
-
_iterator1.return();
|
|
347
|
-
}
|
|
348
|
-
} finally {
|
|
349
|
-
if (_didIteratorError1) {
|
|
350
|
-
throw _iteratorError1;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
})
|
|
356
|
-
}, {
|
|
357
|
-
/**
|
|
358
|
-
* Schedules a debounced save operation.
|
|
359
|
-
*/
|
|
360
|
-
key: "scheduleSave",
|
|
361
|
-
value: function scheduleSave() {
|
|
362
|
-
if (!this.options.persistKey) return;
|
|
363
|
-
this.saveDebouncer.maybeExecute();
|
|
364
|
-
}
|
|
365
|
-
}, {
|
|
366
|
-
key: "save",
|
|
367
|
-
value: (
|
|
368
|
-
/**
|
|
369
|
-
* Persists a snapshot of subscriptions, cache, journal, and temp mappings.
|
|
370
|
-
*/
|
|
371
|
-
async function save() {
|
|
372
|
-
if (!this.options.persistKey || !this.persistenceStorage) return;
|
|
373
|
-
try {
|
|
374
|
-
this.subscriptionManager.gcRestoredSubscriptions();
|
|
375
|
-
var snapshot = {
|
|
376
|
-
subs: [...this.subscriptionManager.getAllSubscriptions().values()].map(function (s) {
|
|
377
|
-
return {
|
|
378
|
-
id: s.id,
|
|
379
|
-
query: s.query,
|
|
380
|
-
checkpoint: s.checkpoint,
|
|
381
|
-
cursor: s.cursor,
|
|
382
|
-
docIds: s.docIds
|
|
383
|
-
};
|
|
384
|
-
}),
|
|
385
|
-
cache: this.normalizedCache.state,
|
|
386
|
-
journal: this.mutationJournal.listPending(),
|
|
387
|
-
temp: [...this.mutationEngine.getTemporaryIdToRealNameMap().entries()]
|
|
388
|
-
};
|
|
389
|
-
await this.persistenceStorage.setItem(this.options.persistKey, JSON.stringify(snapshot));
|
|
390
|
-
} catch (err) {
|
|
391
|
-
console.warn("Failed to save sync state:", err);
|
|
392
|
-
}
|
|
393
|
-
})
|
|
394
|
-
}, {
|
|
395
|
-
key: "load",
|
|
396
|
-
value: (
|
|
397
|
-
/**
|
|
398
|
-
* Loads a previously persisted snapshot if present.
|
|
399
|
-
*/
|
|
400
|
-
async function load() {
|
|
401
|
-
if (!this.options.persistKey || !this.persistenceStorage) return;
|
|
402
|
-
try {
|
|
403
|
-
var raw = await this.persistenceStorage.getItem(this.options.persistKey);
|
|
404
|
-
if (!raw || this.loadAbandoned) return;
|
|
405
|
-
var snap = JSON.parse(raw);
|
|
406
|
-
if ((snap === null || snap === void 0 ? void 0 : snap.cache) && _type_of(snap.cache) === "object") {
|
|
407
|
-
var _iteratorNormalCompletion = true,
|
|
408
|
-
_didIteratorError = false,
|
|
409
|
-
_iteratorError = void 0;
|
|
410
|
-
try {
|
|
411
|
-
for (var _iterator = Object.values(snap.cache)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
412
|
-
var bucket = _step.value;
|
|
413
|
-
var byId = bucket === null || bucket === void 0 ? void 0 : bucket.byId;
|
|
414
|
-
if (!byId || (typeof byId === "undefined" ? "undefined" : _type_of(byId)) !== "object") continue;
|
|
415
|
-
var _iteratorNormalCompletion1 = true,
|
|
416
|
-
_didIteratorError1 = false,
|
|
417
|
-
_iteratorError1 = void 0;
|
|
418
|
-
try {
|
|
419
|
-
for (var _iterator1 = Object.values(byId)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
420
|
-
var doc = _step1.value;
|
|
421
|
-
if (!(doc === null || doc === void 0 ? void 0 : doc.doctype) || !(doc === null || doc === void 0 ? void 0 : doc.name)) continue;
|
|
422
|
-
if (this.normalizedCache.get(doc)) continue;
|
|
423
|
-
this.normalizedCache.upsert(doc, {
|
|
424
|
-
replace: true
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
} catch (err) {
|
|
428
|
-
_didIteratorError1 = true;
|
|
429
|
-
_iteratorError1 = err;
|
|
430
|
-
} finally {
|
|
431
|
-
try {
|
|
432
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
433
|
-
_iterator1.return();
|
|
434
|
-
}
|
|
435
|
-
} finally {
|
|
436
|
-
if (_didIteratorError1) {
|
|
437
|
-
throw _iteratorError1;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
} catch (err) {
|
|
443
|
-
_didIteratorError = true;
|
|
444
|
-
_iteratorError = err;
|
|
445
|
-
} finally {
|
|
446
|
-
try {
|
|
447
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
448
|
-
_iterator.return();
|
|
449
|
-
}
|
|
450
|
-
} finally {
|
|
451
|
-
if (_didIteratorError) {
|
|
452
|
-
throw _iteratorError;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
if ((snap === null || snap === void 0 ? void 0 : snap.subs) && Array.isArray(snap.subs)) {
|
|
458
|
-
var _iteratorNormalCompletion2 = true,
|
|
459
|
-
_didIteratorError2 = false,
|
|
460
|
-
_iteratorError2 = void 0;
|
|
461
|
-
try {
|
|
462
|
-
for (var _iterator2 = snap.subs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
463
|
-
var subscription = _step2.value;
|
|
464
|
-
this.subscriptionManager.restoreSubscription(subscription);
|
|
465
|
-
}
|
|
466
|
-
} catch (err) {
|
|
467
|
-
_didIteratorError2 = true;
|
|
468
|
-
_iteratorError2 = err;
|
|
469
|
-
} finally {
|
|
470
|
-
try {
|
|
471
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
472
|
-
_iterator2.return();
|
|
473
|
-
}
|
|
474
|
-
} finally {
|
|
475
|
-
if (_didIteratorError2) {
|
|
476
|
-
throw _iteratorError2;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
if ((snap === null || snap === void 0 ? void 0 : snap.journal) && Array.isArray(snap.journal)) {
|
|
482
|
-
var _iteratorNormalCompletion3 = true,
|
|
483
|
-
_didIteratorError3 = false,
|
|
484
|
-
_iteratorError3 = void 0;
|
|
485
|
-
try {
|
|
486
|
-
for (var _iterator3 = snap.journal[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
487
|
-
var {
|
|
488
|
-
id,
|
|
489
|
-
entry
|
|
490
|
-
} = _step3.value;
|
|
491
|
-
this.mutationJournal.add(id, entry);
|
|
492
|
-
}
|
|
493
|
-
} catch (err) {
|
|
494
|
-
_didIteratorError3 = true;
|
|
495
|
-
_iteratorError3 = err;
|
|
496
|
-
} finally {
|
|
497
|
-
try {
|
|
498
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
499
|
-
_iterator3.return();
|
|
500
|
-
}
|
|
501
|
-
} finally {
|
|
502
|
-
if (_didIteratorError3) {
|
|
503
|
-
throw _iteratorError3;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
if ((snap === null || snap === void 0 ? void 0 : snap.temp) && Array.isArray(snap.temp)) {
|
|
509
|
-
var tempMap = this.mutationEngine.getTemporaryIdToRealNameMap();
|
|
510
|
-
var _iteratorNormalCompletion4 = true,
|
|
511
|
-
_didIteratorError4 = false,
|
|
512
|
-
_iteratorError4 = void 0;
|
|
513
|
-
try {
|
|
514
|
-
for (var _iterator4 = snap.temp[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
515
|
-
var [tempId, realId] = _step4.value;
|
|
516
|
-
tempMap.set(tempId, realId);
|
|
517
|
-
}
|
|
518
|
-
} catch (err) {
|
|
519
|
-
_didIteratorError4 = true;
|
|
520
|
-
_iteratorError4 = err;
|
|
521
|
-
} finally {
|
|
522
|
-
try {
|
|
523
|
-
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
|
|
524
|
-
_iterator4.return();
|
|
525
|
-
}
|
|
526
|
-
} finally {
|
|
527
|
-
if (_didIteratorError4) {
|
|
528
|
-
throw _iteratorError4;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
} catch (err) {
|
|
534
|
-
console.warn("Failed to load sync state:", err);
|
|
535
|
-
}
|
|
536
|
-
})
|
|
537
|
-
}, {
|
|
538
|
-
/**
|
|
539
|
-
* Broadcasts a reset message to other tabs.
|
|
540
|
-
*/
|
|
541
|
-
key: "broadcastReset",
|
|
542
|
-
value: function broadcastReset() {
|
|
543
|
-
if (this.broadcastChannel) {
|
|
544
|
-
this.broadcastChannel.postMessage("reset");
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}, {
|
|
548
|
-
/**
|
|
549
|
-
* Broadcasts a backfill message to other tabs.
|
|
550
|
-
*/
|
|
551
|
-
key: "broadcastBackfill",
|
|
552
|
-
value: function broadcastBackfill() {
|
|
553
|
-
if (this.broadcastChannel) {
|
|
554
|
-
this.broadcastChannel.postMessage("backfill");
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}, {
|
|
558
|
-
/**
|
|
559
|
-
* Broadcasts a generic change message to other tabs.
|
|
560
|
-
*/
|
|
561
|
-
key: "broadcastChange",
|
|
562
|
-
value: function broadcastChange() {
|
|
563
|
-
if (this.broadcastChannel) {
|
|
564
|
-
this.broadcastChannel.postMessage("changed");
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}, {
|
|
568
|
-
key: "setupTabCoordination",
|
|
569
|
-
value: (
|
|
570
|
-
/**
|
|
571
|
-
* Sets up tab coordination with active tab priority.
|
|
572
|
-
*/
|
|
573
|
-
function setupTabCoordination() {
|
|
574
|
-
var _this = this;
|
|
575
|
-
this.visibilityState = typeof document !== "undefined" && document.hidden ? "hidden" : "visible";
|
|
576
|
-
this.cleanupVisibilityChange = (0, import_platform.onVisibilityChange)(function (visible) {
|
|
577
|
-
if (_this.isDestroyed) return;
|
|
578
|
-
var wasVisible = _this.visibilityState === "visible";
|
|
579
|
-
_this.visibilityState = visible ? "visible" : "hidden";
|
|
580
|
-
_this.lastVisibilityChange = Date.now();
|
|
581
|
-
if (!wasVisible && _this.visibilityState === "visible") {
|
|
582
|
-
_this.evaluateLeadershipPriority();
|
|
583
|
-
} else if (wasVisible && _this.visibilityState === "hidden" && _this.isLeader) {
|
|
584
|
-
_this.considerLeadershipHandoff();
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
this.tryBecomeLeader();
|
|
588
|
-
})
|
|
589
|
-
}, {
|
|
590
|
-
key: "tryBecomeLeader",
|
|
591
|
-
value: (
|
|
592
|
-
/**
|
|
593
|
-
* Attempts to become the leader tab.
|
|
594
|
-
*/
|
|
595
|
-
function tryBecomeLeader() {
|
|
596
|
-
var _this = this;
|
|
597
|
-
if (!getLocalStorage() || this.isDestroyed) return;
|
|
598
|
-
var now = Date.now();
|
|
599
|
-
var leaderData = this.getLeaderData();
|
|
600
|
-
if (!leaderData || now - leaderData.timestamp > this.tabCoordinationConfig.leaderTimeout || this.visibilityState === "visible" && leaderData.visibilityState === "hidden") {
|
|
601
|
-
this.becomeLeader();
|
|
602
|
-
} else {
|
|
603
|
-
if (this.leaderCheckInterval) {
|
|
604
|
-
clearInterval(this.leaderCheckInterval);
|
|
605
|
-
}
|
|
606
|
-
this.leaderCheckInterval = setInterval(function () {
|
|
607
|
-
if (!_this.isDestroyed) {
|
|
608
|
-
_this.checkLeadership();
|
|
609
|
-
}
|
|
610
|
-
}, this.tabCoordinationConfig.leaderTimeout / 2);
|
|
611
|
-
}
|
|
612
|
-
})
|
|
613
|
-
}, {
|
|
614
|
-
key: "becomeLeader",
|
|
615
|
-
value: (
|
|
616
|
-
/**
|
|
617
|
-
* Becomes the leader tab.
|
|
618
|
-
*/
|
|
619
|
-
function becomeLeader() {
|
|
620
|
-
var _this = this;
|
|
621
|
-
if (this.isDestroyed) return;
|
|
622
|
-
this.isLeader = true;
|
|
623
|
-
this.updateLeaderTimestamp();
|
|
624
|
-
this.onBecomeLeader();
|
|
625
|
-
if (this.leaderCheckInterval) {
|
|
626
|
-
clearInterval(this.leaderCheckInterval);
|
|
627
|
-
}
|
|
628
|
-
this.leaderCheckInterval = setInterval(function () {
|
|
629
|
-
if (!_this.isDestroyed) {
|
|
630
|
-
_this.updateLeaderTimestamp();
|
|
631
|
-
}
|
|
632
|
-
}, this.tabCoordinationConfig.leaderTimeout / 2);
|
|
633
|
-
})
|
|
634
|
-
}, {
|
|
635
|
-
key: "updateLeaderTimestamp",
|
|
636
|
-
value: (
|
|
637
|
-
/**
|
|
638
|
-
* Updates leader timestamp in localStorage.
|
|
639
|
-
*/
|
|
640
|
-
function updateLeaderTimestamp() {
|
|
641
|
-
var ls = getLocalStorage();
|
|
642
|
-
if (!ls) return;
|
|
643
|
-
var leaderData = {
|
|
644
|
-
tabId: this.tabId,
|
|
645
|
-
timestamp: Date.now(),
|
|
646
|
-
visibilityState: this.visibilityState,
|
|
647
|
-
lastVisibilityChange: this.lastVisibilityChange
|
|
648
|
-
};
|
|
649
|
-
try {
|
|
650
|
-
ls.setItem(this.leaderKey, JSON.stringify(leaderData));
|
|
651
|
-
} catch (error) {
|
|
652
|
-
console.warn("[PersistenceManager] Failed to update leader timestamp:", error);
|
|
653
|
-
}
|
|
654
|
-
})
|
|
655
|
-
}, {
|
|
656
|
-
key: "checkLeadership",
|
|
657
|
-
value: (
|
|
658
|
-
/**
|
|
659
|
-
* Checks if this tab should remain leader.
|
|
660
|
-
*/
|
|
661
|
-
function checkLeadership() {
|
|
662
|
-
var leaderData = this.getLeaderData();
|
|
663
|
-
if (!leaderData) {
|
|
664
|
-
this.tryBecomeLeader();
|
|
665
|
-
return;
|
|
666
|
-
}
|
|
667
|
-
var now = Date.now();
|
|
668
|
-
if (this.isLeader) {
|
|
669
|
-
if (leaderData.tabId !== this.tabId) {
|
|
670
|
-
this.isLeader = false;
|
|
671
|
-
this.onLoseLeadership();
|
|
672
|
-
}
|
|
673
|
-
} else {
|
|
674
|
-
if (now - leaderData.timestamp > this.tabCoordinationConfig.leaderTimeout || this.visibilityState === "visible" && leaderData.visibilityState === "hidden" && now - this.lastVisibilityChange > 1e3) {
|
|
675
|
-
this.tryBecomeLeader();
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
})
|
|
679
|
-
}, {
|
|
680
|
-
key: "getLeaderData",
|
|
681
|
-
value: (
|
|
682
|
-
/**
|
|
683
|
-
* Gets current leader data from localStorage.
|
|
684
|
-
*/
|
|
685
|
-
function getLeaderData() {
|
|
686
|
-
var ls = getLocalStorage();
|
|
687
|
-
if (!ls) return null;
|
|
688
|
-
try {
|
|
689
|
-
var data = ls.getItem(this.leaderKey);
|
|
690
|
-
return data ? JSON.parse(data) : null;
|
|
691
|
-
} catch (unused) {
|
|
692
|
-
return null;
|
|
693
|
-
}
|
|
694
|
-
})
|
|
695
|
-
}, {
|
|
696
|
-
key: "evaluateLeadershipPriority",
|
|
697
|
-
value: (
|
|
698
|
-
/**
|
|
699
|
-
* Evaluates if this tab should take leadership based on visibility priority.
|
|
700
|
-
*/
|
|
701
|
-
function evaluateLeadershipPriority() {
|
|
702
|
-
if (this.isLeader) return;
|
|
703
|
-
var leaderData = this.getLeaderData();
|
|
704
|
-
if (!leaderData) {
|
|
705
|
-
this.tryBecomeLeader();
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
if (leaderData.visibilityState === "hidden" && this.visibilityState === "visible") {
|
|
709
|
-
this.requestLeadershipHandoff();
|
|
710
|
-
}
|
|
711
|
-
})
|
|
712
|
-
}, {
|
|
713
|
-
key: "considerLeadershipHandoff",
|
|
714
|
-
value: (
|
|
715
|
-
/**
|
|
716
|
-
* Considers handing off leadership when tab becomes hidden.
|
|
717
|
-
*/
|
|
718
|
-
function considerLeadershipHandoff() {
|
|
719
|
-
var _this = this;
|
|
720
|
-
if (!this.isLeader) return;
|
|
721
|
-
this.checkForActiveTabs(function (hasActiveTabs) {
|
|
722
|
-
if (hasActiveTabs) {
|
|
723
|
-
_this.initiateGracefulHandoff();
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
})
|
|
727
|
-
}, {
|
|
728
|
-
key: "requestLeadershipHandoff",
|
|
729
|
-
value:
|
|
730
|
-
// Otherwise, remain leader even though hidden
|
|
731
|
-
/**
|
|
732
|
-
* Requests leadership handoff from current leader.
|
|
733
|
-
*/
|
|
734
|
-
function requestLeadershipHandoff() {
|
|
735
|
-
this.broadcastToTabs({
|
|
736
|
-
type: "leadership-request",
|
|
737
|
-
tabId: this.tabId,
|
|
738
|
-
visibilityState: this.visibilityState
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
}, {
|
|
742
|
-
key: "initiateGracefulHandoff",
|
|
743
|
-
value: (
|
|
744
|
-
/**
|
|
745
|
-
* Initiates graceful handoff to another tab.
|
|
746
|
-
*/
|
|
747
|
-
async function initiateGracefulHandoff() {
|
|
748
|
-
if (!this.isLeader || this.handoffInProgress) return;
|
|
749
|
-
this.handoffInProgress = true;
|
|
750
|
-
this.acceptingNewWork = false;
|
|
751
|
-
await this.waitForPendingOperations();
|
|
752
|
-
var successor = await this.findSuccessor();
|
|
753
|
-
if (successor) {
|
|
754
|
-
var state = await this.captureState();
|
|
755
|
-
this.broadcastToTabs({
|
|
756
|
-
type: "leadership-handoff",
|
|
757
|
-
fromTab: this.tabId,
|
|
758
|
-
toTab: successor,
|
|
759
|
-
state
|
|
760
|
-
});
|
|
761
|
-
this.isLeader = false;
|
|
762
|
-
this.onLoseLeadership();
|
|
763
|
-
}
|
|
764
|
-
this.handoffInProgress = false;
|
|
765
|
-
this.acceptingNewWork = true;
|
|
766
|
-
})
|
|
767
|
-
}, {
|
|
768
|
-
key: "waitForPendingOperations",
|
|
769
|
-
value: (
|
|
770
|
-
/**
|
|
771
|
-
* Waits for all pending operations to complete.
|
|
772
|
-
*/
|
|
773
|
-
async function waitForPendingOperations() {
|
|
774
|
-
var _this = this;
|
|
775
|
-
var timeout = new Promise(function (resolve) {
|
|
776
|
-
return setTimeout(resolve, _this.tabCoordinationConfig.handoffGracePeriod);
|
|
777
|
-
});
|
|
778
|
-
var operations = Promise.all(this.pendingOperations);
|
|
779
|
-
await Promise.race([operations, timeout]);
|
|
780
|
-
})
|
|
781
|
-
}, {
|
|
782
|
-
key: "findSuccessor",
|
|
783
|
-
value: (
|
|
784
|
-
/**
|
|
785
|
-
* Finds a suitable successor for leadership.
|
|
786
|
-
*/
|
|
787
|
-
async function findSuccessor() {
|
|
788
|
-
var _this = this;
|
|
789
|
-
return new Promise(function (resolve) {
|
|
790
|
-
if (_this.isDestroyed || typeof document === "undefined") {
|
|
791
|
-
resolve(null);
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
var responses = [];
|
|
795
|
-
var handleResponse = function handleResponse2(event) {
|
|
796
|
-
var _event_data;
|
|
797
|
-
if (((_event_data = event.data) === null || _event_data === void 0 ? void 0 : _event_data.type) === "visibility-response") {
|
|
798
|
-
responses.push({
|
|
799
|
-
tabId: event.data.tabId,
|
|
800
|
-
isVisible: event.data.isVisible
|
|
801
|
-
});
|
|
802
|
-
}
|
|
803
|
-
};
|
|
804
|
-
window.addEventListener("message", handleResponse);
|
|
805
|
-
_this.broadcastToTabs({
|
|
806
|
-
type: "visibility-check",
|
|
807
|
-
fromTab: _this.tabId
|
|
808
|
-
});
|
|
809
|
-
var responseTimer = setTimeout(function () {
|
|
810
|
-
var _responses_;
|
|
811
|
-
_this.activeResponseTimers.delete(responseTimer);
|
|
812
|
-
window.removeEventListener("message", handleResponse);
|
|
813
|
-
var visibleTab = responses.find(function (r) {
|
|
814
|
-
return r.isVisible;
|
|
815
|
-
});
|
|
816
|
-
resolve(visibleTab ? visibleTab.tabId : ((_responses_ = responses[0]) === null || _responses_ === void 0 ? void 0 : _responses_.tabId) || null);
|
|
817
|
-
}, 500);
|
|
818
|
-
_this.activeResponseTimers.add(responseTimer);
|
|
819
|
-
});
|
|
820
|
-
})
|
|
821
|
-
}, {
|
|
822
|
-
key: "checkForActiveTabs",
|
|
823
|
-
value: (
|
|
824
|
-
/**
|
|
825
|
-
* Checks if there are other active tabs.
|
|
826
|
-
*/
|
|
827
|
-
function checkForActiveTabs(callback) {
|
|
828
|
-
var _this = this;
|
|
829
|
-
if (this.isDestroyed || typeof document === "undefined") {
|
|
830
|
-
callback(false);
|
|
831
|
-
return;
|
|
832
|
-
}
|
|
833
|
-
var responses = [];
|
|
834
|
-
var handleResponse = function handleResponse2(event) {
|
|
835
|
-
var _event_data;
|
|
836
|
-
if (((_event_data = event.data) === null || _event_data === void 0 ? void 0 : _event_data.type) === "visibility-response") {
|
|
837
|
-
responses.push(event.data.isVisible);
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
window.addEventListener("message", handleResponse);
|
|
841
|
-
this.broadcastToTabs({
|
|
842
|
-
type: "visibility-check",
|
|
843
|
-
fromTab: this.tabId
|
|
844
|
-
});
|
|
845
|
-
var responseTimer = setTimeout(function () {
|
|
846
|
-
_this.activeResponseTimers.delete(responseTimer);
|
|
847
|
-
window.removeEventListener("message", handleResponse);
|
|
848
|
-
callback(responses.some(function (isVisible) {
|
|
849
|
-
return isVisible;
|
|
850
|
-
}));
|
|
851
|
-
}, 500);
|
|
852
|
-
this.activeResponseTimers.add(responseTimer);
|
|
853
|
-
})
|
|
854
|
-
}, {
|
|
855
|
-
key: "captureState",
|
|
856
|
-
value: (
|
|
857
|
-
/**
|
|
858
|
-
* Captures current state for handoff.
|
|
859
|
-
*/
|
|
860
|
-
async function captureState() {
|
|
861
|
-
return {
|
|
862
|
-
cache: this.normalizedCache.state,
|
|
863
|
-
journal: this.mutationJournal.listPending(),
|
|
864
|
-
subscriptions: [...this.subscriptionManager.getAllSubscriptions().values()],
|
|
865
|
-
tempMappings: [...this.mutationEngine.getTemporaryIdToRealNameMap().entries()]
|
|
866
|
-
};
|
|
867
|
-
})
|
|
868
|
-
}, {
|
|
869
|
-
key: "broadcastToTabs",
|
|
870
|
-
value: (
|
|
871
|
-
/**
|
|
872
|
-
* Broadcasts message to other tabs.
|
|
873
|
-
*/
|
|
874
|
-
function broadcastToTabs(message) {
|
|
875
|
-
if (this.broadcastChannel) {
|
|
876
|
-
this.broadcastChannel.postMessage(message);
|
|
877
|
-
}
|
|
878
|
-
var ls = getLocalStorage();
|
|
879
|
-
if (ls) {
|
|
880
|
-
try {
|
|
881
|
-
var key = `frappe-sync-msg-${Date.now()}`;
|
|
882
|
-
ls.setItem(key, JSON.stringify(message));
|
|
883
|
-
setTimeout(function () {
|
|
884
|
-
return ls.removeItem(key);
|
|
885
|
-
}, 100);
|
|
886
|
-
} catch (unused) {}
|
|
887
|
-
}
|
|
888
|
-
})
|
|
889
|
-
}, {
|
|
890
|
-
key: "onBecomeLeader",
|
|
891
|
-
value: (
|
|
892
|
-
/**
|
|
893
|
-
* Handles becoming the leader.
|
|
894
|
-
*/
|
|
895
|
-
function onBecomeLeader() {
|
|
896
|
-
console.debug(`[PersistenceManager] Tab ${this.tabId} became leader`);
|
|
897
|
-
if (this.options.onBecomeLeader) {
|
|
898
|
-
this.options.onBecomeLeader();
|
|
899
|
-
}
|
|
900
|
-
})
|
|
901
|
-
}, {
|
|
902
|
-
key: "onLoseLeadership",
|
|
903
|
-
value: (
|
|
904
|
-
/**
|
|
905
|
-
* Handles losing leadership.
|
|
906
|
-
*/
|
|
907
|
-
function onLoseLeadership() {
|
|
908
|
-
console.debug(`[PersistenceManager] Tab ${this.tabId} lost leadership`);
|
|
909
|
-
if (this.leaderCheckInterval) {
|
|
910
|
-
clearInterval(this.leaderCheckInterval);
|
|
911
|
-
this.leaderCheckInterval = void 0;
|
|
912
|
-
}
|
|
913
|
-
if (this.options.onLoseLeadership) {
|
|
914
|
-
this.options.onLoseLeadership();
|
|
915
|
-
}
|
|
916
|
-
})
|
|
917
|
-
}, {
|
|
918
|
-
key: "generateTabId",
|
|
919
|
-
value: (
|
|
920
|
-
/**
|
|
921
|
-
* Generates a unique tab ID.
|
|
922
|
-
*/
|
|
923
|
-
function generateTabId() {
|
|
924
|
-
return `tab-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
925
|
-
})
|
|
926
|
-
}, {
|
|
927
|
-
/**
|
|
928
|
-
* Tracks a pending operation.
|
|
929
|
-
*/
|
|
930
|
-
key: "trackOperation",
|
|
931
|
-
value: function trackOperation(operation) {
|
|
932
|
-
var _this = this;
|
|
933
|
-
this.pendingOperations.add(operation);
|
|
934
|
-
operation.finally(function () {
|
|
935
|
-
_this.pendingOperations.delete(operation);
|
|
936
|
-
}).catch(function () {});
|
|
937
|
-
return operation;
|
|
938
|
-
}
|
|
939
|
-
}, {
|
|
940
|
-
/**
|
|
941
|
-
* Gets whether this tab is the leader.
|
|
942
|
-
*/
|
|
943
|
-
key: "getIsLeader",
|
|
944
|
-
value: function getIsLeader() {
|
|
945
|
-
return this.isLeader;
|
|
946
|
-
}
|
|
947
|
-
}, {
|
|
948
|
-
/**
|
|
949
|
-
* Cleans up timers, event listeners, and channels.
|
|
950
|
-
*/
|
|
951
|
-
key: "destroy",
|
|
952
|
-
value: function destroy() {
|
|
953
|
-
var _this_cleanupVisibilityChange, _this;
|
|
954
|
-
this.isDestroyed = true;
|
|
955
|
-
this.saveDebouncer.cancel();
|
|
956
|
-
clearTimeout(this.loadTimer);
|
|
957
|
-
this.loadTimer = void 0;
|
|
958
|
-
if (this.leaderCheckInterval) {
|
|
959
|
-
clearInterval(this.leaderCheckInterval);
|
|
960
|
-
this.leaderCheckInterval = void 0;
|
|
961
|
-
}
|
|
962
|
-
var _iteratorNormalCompletion = true,
|
|
963
|
-
_didIteratorError = false,
|
|
964
|
-
_iteratorError = void 0;
|
|
965
|
-
try {
|
|
966
|
-
for (var _iterator = this.activeResponseTimers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
967
|
-
var timer = _step.value;
|
|
968
|
-
clearTimeout(timer);
|
|
969
|
-
}
|
|
970
|
-
} catch (err) {
|
|
971
|
-
_didIteratorError = true;
|
|
972
|
-
_iteratorError = err;
|
|
973
|
-
} finally {
|
|
974
|
-
try {
|
|
975
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
976
|
-
_iterator.return();
|
|
977
|
-
}
|
|
978
|
-
} finally {
|
|
979
|
-
if (_didIteratorError) {
|
|
980
|
-
throw _iteratorError;
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
this.activeResponseTimers.clear();
|
|
985
|
-
(_this_cleanupVisibilityChange = (_this = this).cleanupVisibilityChange) === null || _this_cleanupVisibilityChange === void 0 ? void 0 : _this_cleanupVisibilityChange.call(_this);
|
|
986
|
-
this.cleanupVisibilityChange = void 0;
|
|
987
|
-
if (this.broadcastChannel) {
|
|
988
|
-
this.broadcastChannel.close();
|
|
989
|
-
this.broadcastChannel = void 0;
|
|
990
|
-
}
|
|
991
|
-
this.pendingOperations.clear();
|
|
992
|
-
}
|
|
993
|
-
}]);
|
|
994
|
-
return PersistenceManager2;
|
|
995
|
-
}();
|
|
996
998
|
//# sourceMappingURL=persistence.native.js.map
|