@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.
Files changed (597) hide show
  1. package/dist/cjs/auth.cjs +34 -44
  2. package/dist/cjs/auth.native.cjs +97 -0
  3. package/dist/cjs/auth.native.js +77 -82
  4. package/dist/cjs/auth.native.js.map +1 -1
  5. package/dist/cjs/call.cjs +31 -35
  6. package/dist/cjs/call.native.cjs +92 -0
  7. package/dist/cjs/call.native.js +72 -71
  8. package/dist/cjs/call.native.js.map +1 -1
  9. package/dist/cjs/collection.cjs +243 -287
  10. package/dist/cjs/collection.native.cjs +461 -0
  11. package/dist/cjs/collection.native.js +436 -499
  12. package/dist/cjs/collection.native.js.map +1 -1
  13. package/dist/cjs/common/types.cjs +9 -11
  14. package/dist/cjs/common/types.native.cjs +18 -0
  15. package/dist/cjs/common/types.native.js +9 -10
  16. package/dist/cjs/common/types.native.js.map +1 -1
  17. package/dist/cjs/connectionKey.cjs +18 -22
  18. package/dist/cjs/connectionKey.native.cjs +32 -0
  19. package/dist/cjs/connectionKey.native.js +19 -22
  20. package/dist/cjs/connectionKey.native.js.map +1 -1
  21. package/dist/cjs/core/http.cjs +404 -407
  22. package/dist/cjs/core/http.native.cjs +659 -0
  23. package/dist/cjs/core/http.native.js +611 -615
  24. package/dist/cjs/core/http.native.js.map +1 -1
  25. package/dist/cjs/core/serverMessages.cjs +48 -43
  26. package/dist/cjs/core/serverMessages.native.cjs +89 -0
  27. package/dist/cjs/core/serverMessages.native.js +69 -70
  28. package/dist/cjs/core/serverMessages.native.js.map +1 -1
  29. package/dist/cjs/core/sessionGate.cjs +94 -97
  30. package/dist/cjs/core/sessionGate.native.cjs +270 -0
  31. package/dist/cjs/core/sessionGate.native.js +220 -232
  32. package/dist/cjs/core/sessionGate.native.js.map +1 -1
  33. package/dist/cjs/core/types.cjs +37 -39
  34. package/dist/cjs/core/types.native.cjs +169 -0
  35. package/dist/cjs/core/types.native.js +129 -136
  36. package/dist/cjs/core/types.native.js.map +1 -1
  37. package/dist/cjs/core/wire.cjs +28 -30
  38. package/dist/cjs/core/wire.native.cjs +53 -0
  39. package/dist/cjs/core/wire.native.js +28 -29
  40. package/dist/cjs/core/wire.native.js.map +1 -1
  41. package/dist/cjs/db.cjs +434 -449
  42. package/dist/cjs/db.native.cjs +625 -0
  43. package/dist/cjs/db.native.js +583 -590
  44. package/dist/cjs/db.native.js.map +1 -1
  45. package/dist/cjs/devtools/FrappeDevtoolsPanel.cjs +774 -799
  46. package/dist/cjs/devtools/FrappeDevtoolsPanel.native.cjs +878 -0
  47. package/dist/cjs/devtools/FrappeDevtoolsPanel.native.js +821 -862
  48. package/dist/cjs/devtools/FrappeDevtoolsPanel.native.js.map +1 -1
  49. package/dist/cjs/devtools/index.cjs +15 -17
  50. package/dist/cjs/devtools/index.native.cjs +30 -0
  51. package/dist/cjs/devtools/index.native.js +15 -16
  52. package/dist/cjs/devtools/index.native.js.map +1 -1
  53. package/dist/cjs/devtools/plugin.cjs +22 -26
  54. package/dist/cjs/devtools/plugin.native.cjs +46 -0
  55. package/dist/cjs/devtools/plugin.native.js +27 -35
  56. package/dist/cjs/devtools/plugin.native.js.map +1 -1
  57. package/dist/cjs/devtools/theme.cjs +40 -44
  58. package/dist/cjs/devtools/theme.native.cjs +53 -0
  59. package/dist/cjs/devtools/theme.native.js +40 -43
  60. package/dist/cjs/devtools/theme.native.js.map +1 -1
  61. package/dist/cjs/doctype.cjs +493 -440
  62. package/dist/cjs/doctype.native.cjs +631 -0
  63. package/dist/cjs/doctype.native.js +587 -563
  64. package/dist/cjs/doctype.native.js.map +1 -1
  65. package/dist/cjs/file.cjs +27 -31
  66. package/dist/cjs/file.native.cjs +78 -0
  67. package/dist/cjs/file.native.js +58 -62
  68. package/dist/cjs/file.native.js.map +1 -1
  69. package/dist/cjs/fixtureDb.cjs +187 -209
  70. package/dist/cjs/fixtureDb.native.cjs +313 -0
  71. package/dist/cjs/fixtureDb.native.js +291 -300
  72. package/dist/cjs/fixtureDb.native.js.map +1 -1
  73. package/dist/cjs/fixtures.cjs +173 -192
  74. package/dist/cjs/fixtures.native.cjs +379 -0
  75. package/dist/cjs/fixtures.native.js +359 -381
  76. package/dist/cjs/fixtures.native.js.map +1 -1
  77. package/dist/cjs/frappeApp.cjs +94 -101
  78. package/dist/cjs/frappeApp.native.cjs +181 -0
  79. package/dist/cjs/frappeApp.native.js +153 -152
  80. package/dist/cjs/frappeApp.native.js.map +1 -1
  81. package/dist/cjs/frappeReact.cjs +555 -528
  82. package/dist/cjs/frappeReact.native.cjs +710 -0
  83. package/dist/cjs/frappeReact.native.js +637 -632
  84. package/dist/cjs/frappeReact.native.js.map +1 -1
  85. package/dist/cjs/index.cjs +128 -135
  86. package/dist/cjs/index.gnome.cjs +61 -63
  87. package/dist/cjs/index.gnome.native.cjs +87 -0
  88. package/dist/cjs/index.gnome.native.js +61 -62
  89. package/dist/cjs/index.gnome.native.js.map +1 -1
  90. package/dist/cjs/index.native.cjs +171 -0
  91. package/dist/cjs/index.native.js +130 -136
  92. package/dist/cjs/index.native.js.map +1 -1
  93. package/dist/cjs/optimistic.cjs +35 -39
  94. package/dist/cjs/optimistic.native.cjs +59 -0
  95. package/dist/cjs/optimistic.native.js +38 -41
  96. package/dist/cjs/optimistic.native.js.map +1 -1
  97. package/dist/cjs/pacer.cjs +170 -176
  98. package/dist/cjs/pacer.native.cjs +263 -0
  99. package/dist/cjs/pacer.native.js +234 -245
  100. package/dist/cjs/pacer.native.js.map +1 -1
  101. package/dist/cjs/plugin/index.cjs +104 -112
  102. package/dist/cjs/plugin/index.native.cjs +178 -0
  103. package/dist/cjs/plugin/index.native.js +164 -177
  104. package/dist/cjs/plugin/index.native.js.map +1 -1
  105. package/dist/cjs/realtime.cjs +581 -610
  106. package/dist/cjs/realtime.native.cjs +945 -0
  107. package/dist/cjs/realtime.native.js +918 -928
  108. package/dist/cjs/realtime.native.js.map +1 -1
  109. package/dist/cjs/serverLoaders.cjs +60 -78
  110. package/dist/cjs/serverLoaders.native.cjs +103 -0
  111. package/dist/cjs/serverLoaders.native.js +73 -95
  112. package/dist/cjs/serverLoaders.native.js.map +1 -1
  113. package/dist/cjs/sync/backfill.cjs +281 -301
  114. package/dist/cjs/sync/backfill.native.cjs +475 -0
  115. package/dist/cjs/sync/backfill.native.js +449 -465
  116. package/dist/cjs/sync/backfill.native.js.map +1 -1
  117. package/dist/cjs/sync/filters.cjs +309 -267
  118. package/dist/cjs/sync/filters.native.cjs +472 -0
  119. package/dist/cjs/sync/filters.native.js +426 -398
  120. package/dist/cjs/sync/filters.native.js.map +1 -1
  121. package/dist/cjs/sync/index.cjs +476 -496
  122. package/dist/cjs/sync/index.native.cjs +771 -0
  123. package/dist/cjs/sync/index.native.js +738 -737
  124. package/dist/cjs/sync/index.native.js.map +1 -1
  125. package/dist/cjs/sync/merge.cjs +392 -393
  126. package/dist/cjs/sync/merge.native.cjs +681 -0
  127. package/dist/cjs/sync/merge.native.js +642 -673
  128. package/dist/cjs/sync/merge.native.js.map +1 -1
  129. package/dist/cjs/sync/mutationEngine.cjs +785 -829
  130. package/dist/cjs/sync/mutationEngine.native.cjs +1190 -0
  131. package/dist/cjs/sync/mutationEngine.native.js +1162 -1216
  132. package/dist/cjs/sync/mutationEngine.native.js.map +1 -1
  133. package/dist/cjs/sync/mutationJournal.cjs +147 -149
  134. package/dist/cjs/sync/mutationJournal.native.cjs +302 -0
  135. package/dist/cjs/sync/mutationJournal.native.js +278 -269
  136. package/dist/cjs/sync/mutationJournal.native.js.map +1 -1
  137. package/dist/cjs/sync/normalizedCache.cjs +127 -134
  138. package/dist/cjs/sync/normalizedCache.native.cjs +232 -0
  139. package/dist/cjs/sync/normalizedCache.native.js +212 -212
  140. package/dist/cjs/sync/normalizedCache.native.js.map +1 -1
  141. package/dist/cjs/sync/persistence.cjs +649 -661
  142. package/dist/cjs/sync/persistence.native.cjs +996 -0
  143. package/dist/cjs/sync/persistence.native.js +967 -965
  144. package/dist/cjs/sync/persistence.native.js.map +1 -1
  145. package/dist/cjs/sync/realtime.cjs +307 -315
  146. package/dist/cjs/sync/realtime.native.cjs +486 -0
  147. package/dist/cjs/sync/realtime.native.js +465 -461
  148. package/dist/cjs/sync/realtime.native.js.map +1 -1
  149. package/dist/cjs/sync/rehydration.cjs +279 -321
  150. package/dist/cjs/sync/rehydration.native.cjs +495 -0
  151. package/dist/cjs/sync/rehydration.native.js +473 -515
  152. package/dist/cjs/sync/rehydration.native.js.map +1 -1
  153. package/dist/cjs/sync/storage.cjs +127 -129
  154. package/dist/cjs/sync/storage.native.cjs +211 -0
  155. package/dist/cjs/sync/storage.native.js +188 -184
  156. package/dist/cjs/sync/storage.native.js.map +1 -1
  157. package/dist/cjs/sync/subscriptionManager.cjs +686 -708
  158. package/dist/cjs/sync/subscriptionManager.native.cjs +1205 -0
  159. package/dist/cjs/sync/subscriptionManager.native.js +1179 -1220
  160. package/dist/cjs/sync/subscriptionManager.native.js.map +1 -1
  161. package/dist/cjs/sync/types.cjs +79 -81
  162. package/dist/cjs/sync/types.native.cjs +103 -0
  163. package/dist/cjs/sync/types.native.js +89 -90
  164. package/dist/cjs/sync/types.native.js.map +1 -1
  165. package/dist/cjs/sync/virtualPageManager.cjs +762 -806
  166. package/dist/cjs/sync/virtualPageManager.native.cjs +1097 -0
  167. package/dist/cjs/sync/virtualPageManager.native.js +1072 -1097
  168. package/dist/cjs/sync/virtualPageManager.native.js.map +1 -1
  169. package/dist/cjs/syncOptionsKey.cjs +38 -45
  170. package/dist/cjs/syncOptionsKey.native.cjs +69 -0
  171. package/dist/cjs/syncOptionsKey.native.js +51 -63
  172. package/dist/cjs/syncOptionsKey.native.js.map +1 -1
  173. package/dist/cjs/useLiveQuery.cjs +14 -18
  174. package/dist/cjs/useLiveQuery.native.cjs +26 -0
  175. package/dist/cjs/useLiveQuery.native.js +14 -17
  176. package/dist/cjs/useLiveQuery.native.js.map +1 -1
  177. package/dist/cjs/util.cjs +22 -24
  178. package/dist/cjs/util.native.cjs +40 -0
  179. package/dist/cjs/util.native.js +22 -28
  180. package/dist/cjs/util.native.js.map +1 -1
  181. package/dist/esm/auth.mjs +22 -27
  182. package/dist/esm/auth.mjs.map +1 -1
  183. package/dist/esm/auth.native.js +64 -65
  184. package/dist/esm/auth.native.js.map +1 -1
  185. package/dist/esm/call.mjs +19 -18
  186. package/dist/esm/call.mjs.map +1 -1
  187. package/dist/esm/call.native.js +59 -54
  188. package/dist/esm/call.native.js.map +1 -1
  189. package/dist/esm/collection.mjs +228 -268
  190. package/dist/esm/collection.mjs.map +1 -1
  191. package/dist/esm/collection.native.js +421 -481
  192. package/dist/esm/collection.native.js.map +1 -1
  193. package/dist/esm/common/types.mjs +0 -2
  194. package/dist/esm/common/types.native.js +0 -2
  195. package/dist/esm/connectionKey.mjs +5 -4
  196. package/dist/esm/connectionKey.mjs.map +1 -1
  197. package/dist/esm/connectionKey.native.js +6 -5
  198. package/dist/esm/connectionKey.native.js.map +1 -1
  199. package/dist/esm/core/http.mjs +383 -382
  200. package/dist/esm/core/http.mjs.map +1 -1
  201. package/dist/esm/core/http.native.js +590 -591
  202. package/dist/esm/core/http.native.js.map +1 -1
  203. package/dist/esm/core/serverMessages.mjs +34 -26
  204. package/dist/esm/core/serverMessages.mjs.map +1 -1
  205. package/dist/esm/core/serverMessages.native.js +55 -54
  206. package/dist/esm/core/serverMessages.native.js.map +1 -1
  207. package/dist/esm/core/sessionGate.mjs +79 -79
  208. package/dist/esm/core/sessionGate.mjs.map +1 -1
  209. package/dist/esm/core/sessionGate.native.js +205 -215
  210. package/dist/esm/core/sessionGate.native.js.map +1 -1
  211. package/dist/esm/core/types.mjs +23 -22
  212. package/dist/esm/core/types.mjs.map +1 -1
  213. package/dist/esm/core/types.native.js +114 -119
  214. package/dist/esm/core/types.native.js.map +1 -1
  215. package/dist/esm/core/wire.mjs +10 -9
  216. package/dist/esm/core/wire.mjs.map +1 -1
  217. package/dist/esm/core/wire.native.js +10 -9
  218. package/dist/esm/core/wire.native.js.map +1 -1
  219. package/dist/esm/db.mjs +421 -432
  220. package/dist/esm/db.mjs.map +1 -1
  221. package/dist/esm/db.native.js +570 -574
  222. package/dist/esm/db.native.js.map +1 -1
  223. package/dist/esm/devtools/FrappeDevtoolsPanel.mjs +762 -781
  224. package/dist/esm/devtools/FrappeDevtoolsPanel.mjs.map +1 -1
  225. package/dist/esm/devtools/FrappeDevtoolsPanel.native.js +808 -839
  226. package/dist/esm/devtools/FrappeDevtoolsPanel.native.js.map +1 -1
  227. package/dist/esm/devtools/index.mjs +2 -2
  228. package/dist/esm/devtools/index.native.js +2 -2
  229. package/dist/esm/devtools/plugin.mjs +10 -8
  230. package/dist/esm/devtools/plugin.mjs.map +1 -1
  231. package/dist/esm/devtools/plugin.native.js +14 -12
  232. package/dist/esm/devtools/plugin.native.js.map +1 -1
  233. package/dist/esm/devtools/theme.mjs +27 -26
  234. package/dist/esm/devtools/theme.mjs.map +1 -1
  235. package/dist/esm/devtools/theme.native.js +27 -26
  236. package/dist/esm/devtools/theme.native.js.map +1 -1
  237. package/dist/esm/doctype.mjs +473 -416
  238. package/dist/esm/doctype.mjs.map +1 -1
  239. package/dist/esm/doctype.native.js +566 -539
  240. package/dist/esm/doctype.native.js.map +1 -1
  241. package/dist/esm/file.mjs +15 -14
  242. package/dist/esm/file.mjs.map +1 -1
  243. package/dist/esm/file.native.js +45 -45
  244. package/dist/esm/file.native.js.map +1 -1
  245. package/dist/esm/fixtureDb.mjs +175 -191
  246. package/dist/esm/fixtureDb.mjs.map +1 -1
  247. package/dist/esm/fixtureDb.native.js +279 -283
  248. package/dist/esm/fixtureDb.native.js.map +1 -1
  249. package/dist/esm/fixtures.mjs +161 -175
  250. package/dist/esm/fixtures.mjs.map +1 -1
  251. package/dist/esm/fixtures.native.js +346 -364
  252. package/dist/esm/fixtures.native.js.map +1 -1
  253. package/dist/esm/frappeApp.mjs +82 -83
  254. package/dist/esm/frappeApp.mjs.map +1 -1
  255. package/dist/esm/frappeApp.native.js +141 -135
  256. package/dist/esm/frappeApp.native.js.map +1 -1
  257. package/dist/esm/frappeReact.mjs +535 -504
  258. package/dist/esm/frappeReact.mjs.map +1 -1
  259. package/dist/esm/frappeReact.native.js +615 -607
  260. package/dist/esm/frappeReact.native.js.map +1 -1
  261. package/dist/esm/index.gnome.mjs +5 -5
  262. package/dist/esm/index.gnome.native.js +5 -5
  263. package/dist/esm/index.mjs +17 -18
  264. package/dist/esm/index.native.js +17 -18
  265. package/dist/esm/optimistic.mjs +19 -19
  266. package/dist/esm/optimistic.mjs.map +1 -1
  267. package/dist/esm/optimistic.native.js +22 -22
  268. package/dist/esm/optimistic.native.js.map +1 -1
  269. package/dist/esm/pacer.mjs +156 -158
  270. package/dist/esm/pacer.mjs.map +1 -1
  271. package/dist/esm/pacer.native.js +220 -228
  272. package/dist/esm/pacer.native.js.map +1 -1
  273. package/dist/esm/plugin/index.mjs +91 -94
  274. package/dist/esm/plugin/index.mjs.map +1 -1
  275. package/dist/esm/plugin/index.native.js +151 -160
  276. package/dist/esm/plugin/index.native.js.map +1 -1
  277. package/dist/esm/realtime.mjs +569 -594
  278. package/dist/esm/realtime.mjs.map +1 -1
  279. package/dist/esm/realtime.native.js +905 -912
  280. package/dist/esm/realtime.native.js.map +1 -1
  281. package/dist/esm/serverLoaders.mjs +47 -61
  282. package/dist/esm/serverLoaders.mjs.map +1 -1
  283. package/dist/esm/serverLoaders.native.js +56 -75
  284. package/dist/esm/serverLoaders.native.js.map +1 -1
  285. package/dist/esm/sync/backfill.mjs +268 -284
  286. package/dist/esm/sync/backfill.mjs.map +1 -1
  287. package/dist/esm/sync/backfill.native.js +435 -448
  288. package/dist/esm/sync/backfill.native.js.map +1 -1
  289. package/dist/esm/sync/filters.mjs +286 -241
  290. package/dist/esm/sync/filters.mjs.map +1 -1
  291. package/dist/esm/sync/filters.native.js +403 -373
  292. package/dist/esm/sync/filters.native.js.map +1 -1
  293. package/dist/esm/sync/index.mjs +465 -479
  294. package/dist/esm/sync/index.mjs.map +1 -1
  295. package/dist/esm/sync/index.native.js +726 -720
  296. package/dist/esm/sync/index.native.js.map +1 -1
  297. package/dist/esm/sync/merge.mjs +368 -366
  298. package/dist/esm/sync/merge.mjs.map +1 -1
  299. package/dist/esm/sync/merge.native.js +618 -647
  300. package/dist/esm/sync/merge.native.js.map +1 -1
  301. package/dist/esm/sync/mutationEngine.mjs +775 -814
  302. package/dist/esm/sync/mutationEngine.mjs.map +1 -1
  303. package/dist/esm/sync/mutationEngine.native.js +1152 -1202
  304. package/dist/esm/sync/mutationEngine.native.js.map +1 -1
  305. package/dist/esm/sync/mutationJournal.mjs +135 -133
  306. package/dist/esm/sync/mutationJournal.mjs.map +1 -1
  307. package/dist/esm/sync/mutationJournal.native.js +265 -253
  308. package/dist/esm/sync/mutationJournal.native.js.map +1 -1
  309. package/dist/esm/sync/normalizedCache.mjs +115 -117
  310. package/dist/esm/sync/normalizedCache.mjs.map +1 -1
  311. package/dist/esm/sync/normalizedCache.native.js +199 -195
  312. package/dist/esm/sync/normalizedCache.native.js.map +1 -1
  313. package/dist/esm/sync/persistence.mjs +637 -645
  314. package/dist/esm/sync/persistence.mjs.map +1 -1
  315. package/dist/esm/sync/persistence.native.js +954 -949
  316. package/dist/esm/sync/persistence.native.js.map +1 -1
  317. package/dist/esm/sync/realtime.mjs +296 -298
  318. package/dist/esm/sync/realtime.mjs.map +1 -1
  319. package/dist/esm/sync/realtime.native.js +453 -444
  320. package/dist/esm/sync/realtime.native.js.map +1 -1
  321. package/dist/esm/sync/rehydration.mjs +268 -304
  322. package/dist/esm/sync/rehydration.mjs.map +1 -1
  323. package/dist/esm/sync/rehydration.native.js +461 -498
  324. package/dist/esm/sync/rehydration.native.js.map +1 -1
  325. package/dist/esm/sync/storage.mjs +115 -113
  326. package/dist/esm/sync/storage.mjs.map +1 -1
  327. package/dist/esm/sync/storage.native.js +175 -168
  328. package/dist/esm/sync/storage.native.js.map +1 -1
  329. package/dist/esm/sync/subscriptionManager.mjs +675 -691
  330. package/dist/esm/sync/subscriptionManager.mjs.map +1 -1
  331. package/dist/esm/sync/subscriptionManager.native.js +1168 -1204
  332. package/dist/esm/sync/subscriptionManager.native.js.map +1 -1
  333. package/dist/esm/sync/types.mjs +56 -55
  334. package/dist/esm/sync/types.mjs.map +1 -1
  335. package/dist/esm/sync/types.native.js +66 -65
  336. package/dist/esm/sync/types.native.js.map +1 -1
  337. package/dist/esm/sync/virtualPageManager.mjs +749 -789
  338. package/dist/esm/sync/virtualPageManager.mjs.map +1 -1
  339. package/dist/esm/sync/virtualPageManager.native.js +1058 -1080
  340. package/dist/esm/sync/virtualPageManager.native.js.map +1 -1
  341. package/dist/esm/syncOptionsKey.mjs +25 -27
  342. package/dist/esm/syncOptionsKey.mjs.map +1 -1
  343. package/dist/esm/syncOptionsKey.native.js +38 -46
  344. package/dist/esm/syncOptionsKey.native.js.map +1 -1
  345. package/dist/esm/useLiveQuery.mjs +2 -2
  346. package/dist/esm/useLiveQuery.native.js +2 -2
  347. package/dist/esm/util.mjs +9 -7
  348. package/dist/esm/util.mjs.map +1 -1
  349. package/dist/esm/util.native.js +8 -11
  350. package/dist/esm/util.native.js.map +1 -1
  351. package/dist/jsx/auth.mjs +22 -27
  352. package/dist/jsx/auth.mjs.map +1 -1
  353. package/dist/jsx/auth.native.cjs +97 -0
  354. package/dist/jsx/auth.native.js +77 -82
  355. package/dist/jsx/auth.native.js.map +1 -1
  356. package/dist/jsx/call.mjs +19 -18
  357. package/dist/jsx/call.mjs.map +1 -1
  358. package/dist/jsx/call.native.cjs +92 -0
  359. package/dist/jsx/call.native.js +72 -71
  360. package/dist/jsx/call.native.js.map +1 -1
  361. package/dist/jsx/collection.mjs +228 -268
  362. package/dist/jsx/collection.mjs.map +1 -1
  363. package/dist/jsx/collection.native.cjs +461 -0
  364. package/dist/jsx/collection.native.js +436 -499
  365. package/dist/jsx/collection.native.js.map +1 -1
  366. package/dist/jsx/common/types.mjs +0 -2
  367. package/dist/jsx/common/types.native.cjs +18 -0
  368. package/dist/jsx/common/types.native.js +9 -10
  369. package/dist/jsx/common/types.native.js.map +1 -1
  370. package/dist/jsx/connectionKey.mjs +5 -4
  371. package/dist/jsx/connectionKey.mjs.map +1 -1
  372. package/dist/jsx/connectionKey.native.cjs +32 -0
  373. package/dist/jsx/connectionKey.native.js +19 -22
  374. package/dist/jsx/connectionKey.native.js.map +1 -1
  375. package/dist/jsx/core/http.mjs +383 -382
  376. package/dist/jsx/core/http.mjs.map +1 -1
  377. package/dist/jsx/core/http.native.cjs +659 -0
  378. package/dist/jsx/core/http.native.js +611 -615
  379. package/dist/jsx/core/http.native.js.map +1 -1
  380. package/dist/jsx/core/serverMessages.mjs +34 -26
  381. package/dist/jsx/core/serverMessages.mjs.map +1 -1
  382. package/dist/jsx/core/serverMessages.native.cjs +89 -0
  383. package/dist/jsx/core/serverMessages.native.js +69 -70
  384. package/dist/jsx/core/serverMessages.native.js.map +1 -1
  385. package/dist/jsx/core/sessionGate.mjs +79 -79
  386. package/dist/jsx/core/sessionGate.mjs.map +1 -1
  387. package/dist/jsx/core/sessionGate.native.cjs +270 -0
  388. package/dist/jsx/core/sessionGate.native.js +220 -232
  389. package/dist/jsx/core/sessionGate.native.js.map +1 -1
  390. package/dist/jsx/core/types.mjs +23 -22
  391. package/dist/jsx/core/types.mjs.map +1 -1
  392. package/dist/jsx/core/types.native.cjs +169 -0
  393. package/dist/jsx/core/types.native.js +129 -136
  394. package/dist/jsx/core/types.native.js.map +1 -1
  395. package/dist/jsx/core/wire.mjs +10 -9
  396. package/dist/jsx/core/wire.mjs.map +1 -1
  397. package/dist/jsx/core/wire.native.cjs +53 -0
  398. package/dist/jsx/core/wire.native.js +28 -29
  399. package/dist/jsx/core/wire.native.js.map +1 -1
  400. package/dist/jsx/db.mjs +421 -432
  401. package/dist/jsx/db.mjs.map +1 -1
  402. package/dist/jsx/db.native.cjs +625 -0
  403. package/dist/jsx/db.native.js +583 -590
  404. package/dist/jsx/db.native.js.map +1 -1
  405. package/dist/jsx/devtools/FrappeDevtoolsPanel.mjs +762 -781
  406. package/dist/jsx/devtools/FrappeDevtoolsPanel.mjs.map +1 -1
  407. package/dist/jsx/devtools/FrappeDevtoolsPanel.native.cjs +878 -0
  408. package/dist/jsx/devtools/FrappeDevtoolsPanel.native.js +821 -862
  409. package/dist/jsx/devtools/FrappeDevtoolsPanel.native.js.map +1 -1
  410. package/dist/jsx/devtools/index.mjs +2 -2
  411. package/dist/jsx/devtools/index.native.cjs +30 -0
  412. package/dist/jsx/devtools/index.native.js +15 -16
  413. package/dist/jsx/devtools/index.native.js.map +1 -1
  414. package/dist/jsx/devtools/plugin.mjs +10 -8
  415. package/dist/jsx/devtools/plugin.mjs.map +1 -1
  416. package/dist/jsx/devtools/plugin.native.cjs +46 -0
  417. package/dist/jsx/devtools/plugin.native.js +27 -35
  418. package/dist/jsx/devtools/plugin.native.js.map +1 -1
  419. package/dist/jsx/devtools/theme.mjs +27 -26
  420. package/dist/jsx/devtools/theme.mjs.map +1 -1
  421. package/dist/jsx/devtools/theme.native.cjs +53 -0
  422. package/dist/jsx/devtools/theme.native.js +40 -43
  423. package/dist/jsx/devtools/theme.native.js.map +1 -1
  424. package/dist/jsx/doctype.mjs +473 -416
  425. package/dist/jsx/doctype.mjs.map +1 -1
  426. package/dist/jsx/doctype.native.cjs +631 -0
  427. package/dist/jsx/doctype.native.js +587 -563
  428. package/dist/jsx/doctype.native.js.map +1 -1
  429. package/dist/jsx/file.mjs +15 -14
  430. package/dist/jsx/file.mjs.map +1 -1
  431. package/dist/jsx/file.native.cjs +78 -0
  432. package/dist/jsx/file.native.js +58 -62
  433. package/dist/jsx/file.native.js.map +1 -1
  434. package/dist/jsx/fixtureDb.mjs +175 -191
  435. package/dist/jsx/fixtureDb.mjs.map +1 -1
  436. package/dist/jsx/fixtureDb.native.cjs +313 -0
  437. package/dist/jsx/fixtureDb.native.js +291 -300
  438. package/dist/jsx/fixtureDb.native.js.map +1 -1
  439. package/dist/jsx/fixtures.mjs +161 -175
  440. package/dist/jsx/fixtures.mjs.map +1 -1
  441. package/dist/jsx/fixtures.native.cjs +379 -0
  442. package/dist/jsx/fixtures.native.js +359 -381
  443. package/dist/jsx/fixtures.native.js.map +1 -1
  444. package/dist/jsx/frappeApp.mjs +82 -83
  445. package/dist/jsx/frappeApp.mjs.map +1 -1
  446. package/dist/jsx/frappeApp.native.cjs +181 -0
  447. package/dist/jsx/frappeApp.native.js +153 -152
  448. package/dist/jsx/frappeApp.native.js.map +1 -1
  449. package/dist/jsx/frappeReact.mjs +535 -504
  450. package/dist/jsx/frappeReact.mjs.map +1 -1
  451. package/dist/jsx/frappeReact.native.cjs +710 -0
  452. package/dist/jsx/frappeReact.native.js +636 -631
  453. package/dist/jsx/frappeReact.native.js.map +1 -1
  454. package/dist/jsx/index.gnome.mjs +5 -5
  455. package/dist/jsx/index.gnome.native.cjs +87 -0
  456. package/dist/jsx/index.gnome.native.js +61 -62
  457. package/dist/jsx/index.gnome.native.js.map +1 -1
  458. package/dist/jsx/index.js +17 -18
  459. package/dist/jsx/index.mjs +17 -18
  460. package/dist/jsx/index.native.cjs +171 -0
  461. package/dist/jsx/index.native.js +128 -134
  462. package/dist/jsx/index.native.js.map +1 -1
  463. package/dist/jsx/optimistic.mjs +19 -19
  464. package/dist/jsx/optimistic.mjs.map +1 -1
  465. package/dist/jsx/optimistic.native.cjs +59 -0
  466. package/dist/jsx/optimistic.native.js +38 -41
  467. package/dist/jsx/optimistic.native.js.map +1 -1
  468. package/dist/jsx/pacer.mjs +156 -158
  469. package/dist/jsx/pacer.mjs.map +1 -1
  470. package/dist/jsx/pacer.native.cjs +263 -0
  471. package/dist/jsx/pacer.native.js +234 -245
  472. package/dist/jsx/pacer.native.js.map +1 -1
  473. package/dist/jsx/plugin/index.mjs +91 -94
  474. package/dist/jsx/plugin/index.mjs.map +1 -1
  475. package/dist/jsx/plugin/index.native.cjs +178 -0
  476. package/dist/jsx/plugin/index.native.js +164 -177
  477. package/dist/jsx/plugin/index.native.js.map +1 -1
  478. package/dist/jsx/realtime.mjs +569 -594
  479. package/dist/jsx/realtime.mjs.map +1 -1
  480. package/dist/jsx/realtime.native.cjs +945 -0
  481. package/dist/jsx/realtime.native.js +918 -928
  482. package/dist/jsx/realtime.native.js.map +1 -1
  483. package/dist/jsx/serverLoaders.mjs +47 -61
  484. package/dist/jsx/serverLoaders.mjs.map +1 -1
  485. package/dist/jsx/serverLoaders.native.cjs +103 -0
  486. package/dist/jsx/serverLoaders.native.js +73 -95
  487. package/dist/jsx/serverLoaders.native.js.map +1 -1
  488. package/dist/jsx/sync/backfill.mjs +268 -284
  489. package/dist/jsx/sync/backfill.mjs.map +1 -1
  490. package/dist/jsx/sync/backfill.native.cjs +475 -0
  491. package/dist/jsx/sync/backfill.native.js +449 -465
  492. package/dist/jsx/sync/backfill.native.js.map +1 -1
  493. package/dist/jsx/sync/filters.mjs +286 -241
  494. package/dist/jsx/sync/filters.mjs.map +1 -1
  495. package/dist/jsx/sync/filters.native.cjs +472 -0
  496. package/dist/jsx/sync/filters.native.js +426 -398
  497. package/dist/jsx/sync/filters.native.js.map +1 -1
  498. package/dist/jsx/sync/index.mjs +465 -479
  499. package/dist/jsx/sync/index.mjs.map +1 -1
  500. package/dist/jsx/sync/index.native.cjs +771 -0
  501. package/dist/jsx/sync/index.native.js +738 -737
  502. package/dist/jsx/sync/index.native.js.map +1 -1
  503. package/dist/jsx/sync/merge.mjs +368 -366
  504. package/dist/jsx/sync/merge.mjs.map +1 -1
  505. package/dist/jsx/sync/merge.native.cjs +681 -0
  506. package/dist/jsx/sync/merge.native.js +642 -673
  507. package/dist/jsx/sync/merge.native.js.map +1 -1
  508. package/dist/jsx/sync/mutationEngine.mjs +775 -814
  509. package/dist/jsx/sync/mutationEngine.mjs.map +1 -1
  510. package/dist/jsx/sync/mutationEngine.native.cjs +1190 -0
  511. package/dist/jsx/sync/mutationEngine.native.js +1162 -1216
  512. package/dist/jsx/sync/mutationEngine.native.js.map +1 -1
  513. package/dist/jsx/sync/mutationJournal.mjs +135 -133
  514. package/dist/jsx/sync/mutationJournal.mjs.map +1 -1
  515. package/dist/jsx/sync/mutationJournal.native.cjs +302 -0
  516. package/dist/jsx/sync/mutationJournal.native.js +278 -269
  517. package/dist/jsx/sync/mutationJournal.native.js.map +1 -1
  518. package/dist/jsx/sync/normalizedCache.mjs +115 -117
  519. package/dist/jsx/sync/normalizedCache.mjs.map +1 -1
  520. package/dist/jsx/sync/normalizedCache.native.cjs +232 -0
  521. package/dist/jsx/sync/normalizedCache.native.js +212 -212
  522. package/dist/jsx/sync/normalizedCache.native.js.map +1 -1
  523. package/dist/jsx/sync/persistence.mjs +637 -645
  524. package/dist/jsx/sync/persistence.mjs.map +1 -1
  525. package/dist/jsx/sync/persistence.native.cjs +996 -0
  526. package/dist/jsx/sync/persistence.native.js +967 -965
  527. package/dist/jsx/sync/persistence.native.js.map +1 -1
  528. package/dist/jsx/sync/realtime.mjs +296 -298
  529. package/dist/jsx/sync/realtime.mjs.map +1 -1
  530. package/dist/jsx/sync/realtime.native.cjs +486 -0
  531. package/dist/jsx/sync/realtime.native.js +465 -461
  532. package/dist/jsx/sync/realtime.native.js.map +1 -1
  533. package/dist/jsx/sync/rehydration.mjs +268 -304
  534. package/dist/jsx/sync/rehydration.mjs.map +1 -1
  535. package/dist/jsx/sync/rehydration.native.cjs +495 -0
  536. package/dist/jsx/sync/rehydration.native.js +473 -515
  537. package/dist/jsx/sync/rehydration.native.js.map +1 -1
  538. package/dist/jsx/sync/storage.mjs +115 -113
  539. package/dist/jsx/sync/storage.mjs.map +1 -1
  540. package/dist/jsx/sync/storage.native.cjs +211 -0
  541. package/dist/jsx/sync/storage.native.js +188 -184
  542. package/dist/jsx/sync/storage.native.js.map +1 -1
  543. package/dist/jsx/sync/subscriptionManager.mjs +675 -691
  544. package/dist/jsx/sync/subscriptionManager.mjs.map +1 -1
  545. package/dist/jsx/sync/subscriptionManager.native.cjs +1205 -0
  546. package/dist/jsx/sync/subscriptionManager.native.js +1179 -1220
  547. package/dist/jsx/sync/subscriptionManager.native.js.map +1 -1
  548. package/dist/jsx/sync/types.mjs +56 -55
  549. package/dist/jsx/sync/types.mjs.map +1 -1
  550. package/dist/jsx/sync/types.native.cjs +103 -0
  551. package/dist/jsx/sync/types.native.js +89 -90
  552. package/dist/jsx/sync/types.native.js.map +1 -1
  553. package/dist/jsx/sync/virtualPageManager.mjs +749 -789
  554. package/dist/jsx/sync/virtualPageManager.mjs.map +1 -1
  555. package/dist/jsx/sync/virtualPageManager.native.cjs +1097 -0
  556. package/dist/jsx/sync/virtualPageManager.native.js +1072 -1097
  557. package/dist/jsx/sync/virtualPageManager.native.js.map +1 -1
  558. package/dist/jsx/syncOptionsKey.mjs +25 -27
  559. package/dist/jsx/syncOptionsKey.mjs.map +1 -1
  560. package/dist/jsx/syncOptionsKey.native.cjs +69 -0
  561. package/dist/jsx/syncOptionsKey.native.js +51 -63
  562. package/dist/jsx/syncOptionsKey.native.js.map +1 -1
  563. package/dist/jsx/useLiveQuery.mjs +2 -2
  564. package/dist/jsx/useLiveQuery.native.cjs +26 -0
  565. package/dist/jsx/useLiveQuery.native.js +14 -17
  566. package/dist/jsx/useLiveQuery.native.js.map +1 -1
  567. package/dist/jsx/util.mjs +9 -7
  568. package/dist/jsx/util.mjs.map +1 -1
  569. package/dist/jsx/util.native.cjs +40 -0
  570. package/dist/jsx/util.native.js +22 -28
  571. package/dist/jsx/util.native.js.map +1 -1
  572. package/package.json +10 -10
  573. package/src/devtools/FrappeDevtoolsPanel.stories.tsx +16 -16
  574. package/src/devtools/plugin.stories.tsx +4 -4
  575. package/src/useFrappeCollection.stories.tsx +14 -14
  576. package/src/useFrappeInfiniteList.stories.tsx +11 -11
  577. package/src/useFrappePendingMutations.stories.tsx +12 -12
  578. package/types/devtools/FrappeDevtoolsPanel.d.ts +2 -1
  579. package/types/devtools/FrappeDevtoolsPanel.d.ts.map +1 -1
  580. package/types/devtools/plugin.d.ts +2 -1
  581. package/types/devtools/plugin.d.ts.map +1 -1
  582. package/dist/esm/common/types.mjs.map +0 -1
  583. package/dist/esm/common/types.native.js.map +0 -1
  584. package/dist/esm/devtools/index.mjs.map +0 -1
  585. package/dist/esm/devtools/index.native.js.map +0 -1
  586. package/dist/esm/index.gnome.mjs.map +0 -1
  587. package/dist/esm/index.gnome.native.js.map +0 -1
  588. package/dist/esm/index.mjs.map +0 -1
  589. package/dist/esm/index.native.js.map +0 -1
  590. package/dist/esm/useLiveQuery.mjs.map +0 -1
  591. package/dist/esm/useLiveQuery.native.js.map +0 -1
  592. package/dist/jsx/common/types.mjs.map +0 -1
  593. package/dist/jsx/devtools/index.mjs.map +0 -1
  594. package/dist/jsx/index.gnome.mjs.map +0 -1
  595. package/dist/jsx/index.js.map +0 -1
  596. package/dist/jsx/index.mjs.map +0 -1
  597. package/dist/jsx/useLiveQuery.mjs.map +0 -1
@@ -5,953 +5,943 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
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
- 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;
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 realtime_exports = {};
26
24
  __export(realtime_exports, {
27
- RealtimeModule: () => RealtimeModule,
28
- RealtimePlatform: () => RealtimePlatform
25
+ RealtimeModule: () => RealtimeModule,
26
+ RealtimePlatform: () => RealtimePlatform
29
27
  });
30
28
  module.exports = __toCommonJS(realtime_exports);
31
29
  var import_platform = require("@multiplatform.one/platform");
32
30
  var import_socket = require("socket.io-client");
33
31
  var import_util = require("./util.native.js");
34
32
  function _class_call_check(instance, Constructor) {
35
- if (!(instance instanceof Constructor)) {
36
- throw new TypeError("Cannot call a class as a function");
37
- }
33
+ if (!(instance instanceof Constructor)) {
34
+ throw new TypeError("Cannot call a class as a function");
35
+ }
38
36
  }
39
37
  function _defineProperties(target, props) {
40
- for (var i = 0; i < props.length; i++) {
41
- var descriptor = props[i];
42
- descriptor.enumerable = descriptor.enumerable || false;
43
- descriptor.configurable = true;
44
- if ("value" in descriptor) descriptor.writable = true;
45
- Object.defineProperty(target, descriptor.key, descriptor);
46
- }
38
+ for (var i = 0; i < props.length; i++) {
39
+ var descriptor = props[i];
40
+ descriptor.enumerable = descriptor.enumerable || false;
41
+ descriptor.configurable = true;
42
+ if ("value" in descriptor) descriptor.writable = true;
43
+ Object.defineProperty(target, descriptor.key, descriptor);
44
+ }
47
45
  }
48
46
  function _create_class(Constructor, protoProps, staticProps) {
49
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
50
- if (staticProps) _defineProperties(Constructor, staticProps);
51
- return Constructor;
47
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
48
+ if (staticProps) _defineProperties(Constructor, staticProps);
49
+ return Constructor;
52
50
  }
53
51
  function _define_property(obj, key, value) {
54
- if (key in obj) {
55
- Object.defineProperty(obj, key, {
56
- value,
57
- enumerable: true,
58
- configurable: true,
59
- writable: true
60
- });
61
- } else {
62
- obj[key] = value;
63
- }
64
- return obj;
52
+ if (key in obj) {
53
+ Object.defineProperty(obj, key, {
54
+ value,
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true
58
+ });
59
+ } else {
60
+ obj[key] = value;
61
+ }
62
+ return obj;
65
63
  }
66
- var RealtimePlatform = /* @__PURE__ */function (RealtimePlatform2) {
67
- RealtimePlatform2["Node"] = "node";
68
- RealtimePlatform2["Web"] = "web";
69
- RealtimePlatform2["ReactNative"] = "react-native";
70
- return RealtimePlatform2;
71
- }({});
64
+ var RealtimePlatform = /* @__PURE__ */ (function(RealtimePlatform2) {
65
+ RealtimePlatform2["Node"] = "node";
66
+ RealtimePlatform2["Web"] = "web";
67
+ RealtimePlatform2["ReactNative"] = "react-native";
68
+ return RealtimePlatform2;
69
+ })({});
72
70
  function docRoomKey(doctype, name) {
73
- return `${doctype}\0${name}`;
71
+ return `${doctype}\0${name}`;
74
72
  }
75
- var RealtimeModule = /* @__PURE__ */function () {
76
- "use strict";
73
+ var RealtimeModule = /* @__PURE__ */ (function() {
74
+ "use strict";
75
+ function RealtimeModule2(config) {
76
+ _class_call_check(this, RealtimeModule2);
77
+ _define_property(this, "socket", void 0);
78
+ _define_property(this, "eventSource", void 0);
79
+ _define_property(this, "handlerMap", /* @__PURE__ */ new Map());
80
+ _define_property(this, "attachedSocketEvents", /* @__PURE__ */ new Set());
81
+ _define_property(this, "socketEventHandlers", /* @__PURE__ */ new Map());
82
+ _define_property(this, "attachedSseEvents", /* @__PURE__ */ new Set());
83
+ _define_property(this, "sseListeners", /* @__PURE__ */ new Map());
84
+ _define_property(this, "sseRoomNoticeLogged", false);
85
+ _define_property(this, "sseEmitNoticeLogged", false);
86
+ _define_property(this, "docRooms", /* @__PURE__ */ new Map());
87
+ _define_property(this, "listRooms", /* @__PURE__ */ new Map());
88
+ _define_property(this, "socketHealthy", false);
89
+ _define_property(this, "isConnecting", false);
90
+ _define_property(this, "healthyWaiters", /* @__PURE__ */ new Set());
91
+ _define_property(this, "config", void 0);
92
+ _define_property(this, "authRefreshInflight", void 0);
93
+ this.config = {
94
+ ...config,
95
+ platform: config.platform || this.detectPlatform()
96
+ };
97
+ }
98
+ _create_class(RealtimeModule2, [
99
+ {
100
+ key: "detectPlatform",
101
+ value: function detectPlatform() {
102
+ var _navigator_userAgent;
103
+ if ((0, import_util.isGjs)()) return "node";
104
+ if (import_platform.isNative || typeof navigator !== "undefined" && (navigator.product === "ReactNative" || ((_navigator_userAgent = navigator.userAgent) === null || _navigator_userAgent === void 0 ? void 0 : _navigator_userAgent.includes("ReactNative")))) {
105
+ return "react-native";
106
+ }
107
+ if (!(0, import_util.isBrowser)()) return "node";
108
+ return "web";
109
+ }
110
+ },
111
+ {
112
+ key: "getSocketURL",
113
+ value: function getSocketURL() {
114
+ var base = this.config.baseURL.replace(/\/$/, "");
115
+ if (this.config.socketBaseURL) {
116
+ var socketBase = this.config.socketBaseURL.replace(/\/$/, "");
117
+ var siteName = this.config.siteName;
118
+ if (!siteName) {
119
+ try {
120
+ siteName = new URL(base).hostname;
121
+ } catch (unused) {
122
+ siteName = base.replace(/^https?:\/\//, "").split(/[/:]/)[0];
123
+ }
124
+ }
125
+ return `${socketBase}/${siteName}`;
126
+ }
127
+ try {
128
+ var url = new URL(base);
129
+ var port = this.config.socketPort ? String(this.config.socketPort) : url.port;
130
+ var host = port ? `${url.hostname}:${port}` : url.hostname;
131
+ var siteName1 = this.config.siteName || url.hostname;
132
+ return `${url.protocol}//${host}/${siteName1}`;
133
+ } catch (unused) {
134
+ var result = base;
135
+ if (this.config.socketPort) {
136
+ result = result.replace(/(:\d+)/, `:${this.config.socketPort}`);
137
+ }
138
+ var siteName2 = this.config.siteName || result.replace(/^https?:\/\//, "").split(/[/:]/)[0];
139
+ return `${result}/${siteName2}`;
140
+ }
141
+ }
142
+ },
143
+ {
144
+ key: "getAuthOptions",
145
+ value: async function getAuthOptions() {
146
+ var _this_config_auth, _this_config_auth1;
147
+ var authOptions = {};
148
+ if (this.config.platform !== "web") {
149
+ try {
150
+ authOptions.extraHeaders = { Origin: new URL(this.config.baseURL).origin };
151
+ } catch (unused) {
152
+ authOptions.extraHeaders = { Origin: this.config.baseURL.replace(/\/$/, "") };
153
+ }
154
+ }
155
+ if (this.config.platform !== "web" && ((_this_config_auth = this.config.auth) === null || _this_config_auth === void 0 ? void 0 : _this_config_auth.sessionId)) {
156
+ var sessionId = typeof this.config.auth.sessionId === "function" ? await this.config.auth.sessionId() : this.config.auth.sessionId;
157
+ var Cookie = `sid=${sessionId}`;
158
+ authOptions.extraHeaders = {
159
+ ...authOptions.extraHeaders,
160
+ Cookie
161
+ };
162
+ }
163
+ if (((_this_config_auth1 = this.config.auth) === null || _this_config_auth1 === void 0 ? void 0 : _this_config_auth1.useToken) && this.config.auth.token) {
164
+ var token = typeof this.config.auth.token === "function" ? await this.config.auth.token() : this.config.auth.token;
165
+ if (token) {
166
+ var authType = this.config.auth.type || "Bearer";
167
+ if (!authOptions.extraHeaders) authOptions.extraHeaders = {};
168
+ authOptions.extraHeaders.Authorization = authType === "Bearer" ? `Bearer ${token}` : `token ${token}`;
169
+ }
170
+ }
171
+ if (authOptions.extraHeaders) {
172
+ authOptions.transportOptions = {
173
+ websocket: { extraHeaders: { ...authOptions.extraHeaders } },
174
+ polling: { extraHeaders: { ...authOptions.extraHeaders } }
175
+ };
176
+ }
177
+ return authOptions;
178
+ }
179
+ },
180
+ {
181
+ key: "refreshSocketAuth",
182
+ value: (
183
+ /**
184
+ * Re-resolve credentials (token function / session id) and swap them into
185
+ * the LIVE manager options in place. Socket.IO constructs a fresh engine
186
+ * from `manager.opts` on every (re)connect attempt, so mutating the opts
187
+ * makes the next handshake carry the refreshed token — without tearing
188
+ * down handlers or room subscriptions. Called on disconnect and before
189
+ * reconnect attempts so a token that rotated mid-session (e.g. Keycloak
190
+ * refresh) never strands the socket in an auth-rejected retry loop.
191
+ */
192
+ function refreshSocketAuth() {
193
+ var _this = this;
194
+ var socket = this.socket;
195
+ if (!socket) return Promise.resolve();
196
+ if (this.authRefreshInflight) return this.authRefreshInflight;
197
+ this.authRefreshInflight = (async function() {
198
+ try {
199
+ var authOptions = await _this.getAuthOptions();
200
+ var manager = socket.io;
201
+ if (manager === null || manager === void 0 ? void 0 : manager.opts) Object.assign(manager.opts, authOptions);
202
+ } catch (unused) {} finally {
203
+ _this.authRefreshInflight = void 0;
204
+ }
205
+ })();
206
+ return this.authRefreshInflight;
207
+ })
208
+ },
209
+ {
210
+ key: "resolveHealthyWaiters",
211
+ value: function resolveHealthyWaiters(ok) {
212
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
213
+ try {
214
+ for (var _iterator = this.healthyWaiters[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
215
+ var resolve = _step.value;
216
+ resolve(ok);
217
+ }
218
+ } catch (err) {
219
+ _didIteratorError = true;
220
+ _iteratorError = err;
221
+ } finally {
222
+ try {
223
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
224
+ _iterator.return();
225
+ }
226
+ } finally {
227
+ if (_didIteratorError) {
228
+ throw _iteratorError;
229
+ }
230
+ }
231
+ }
232
+ this.healthyWaiters.clear();
233
+ }
234
+ },
235
+ {
236
+ key: "isSSE",
237
+ value: function isSSE() {
238
+ return this.config.transport === "sse";
239
+ }
240
+ },
241
+ {
242
+ key: "waitUntilHealthy",
243
+ value: function waitUntilHealthy() {
244
+ var _this = this;
245
+ var timeoutMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 2e4;
246
+ if (this.isHealthy()) return Promise.resolve(true);
247
+ return new Promise(function(resolve) {
248
+ var timer = setTimeout(function() {
249
+ _this.healthyWaiters.delete(onReady);
250
+ resolve(false);
251
+ }, timeoutMs);
252
+ var onReady = function onReady2(ok) {
253
+ clearTimeout(timer);
254
+ resolve(ok);
255
+ };
256
+ _this.healthyWaiters.add(onReady);
257
+ });
258
+ }
259
+ },
260
+ {
261
+ key: "ensureConnected",
262
+ value: async function ensureConnected() {
263
+ if (this.isHealthy()) return;
264
+ if (!this.socket && !this.eventSource && !this.isConnecting) {
265
+ await this.connect();
266
+ }
267
+ await this.waitUntilHealthy();
268
+ }
269
+ },
270
+ {
271
+ key: "resubscribeRooms",
272
+ value: function resubscribeRooms() {
273
+ if (!this.socket || !this.socketHealthy) return;
274
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
275
+ try {
276
+ for (var _iterator = this.docRooms.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
277
+ var room = _step.value;
278
+ this.socket.emit("doc_subscribe", room.doctype, room.name);
279
+ }
280
+ } catch (err) {
281
+ _didIteratorError = true;
282
+ _iteratorError = err;
283
+ } finally {
284
+ try {
285
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
286
+ _iterator.return();
287
+ }
288
+ } finally {
289
+ if (_didIteratorError) {
290
+ throw _iteratorError;
291
+ }
292
+ }
293
+ }
294
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
295
+ try {
296
+ for (var _iterator1 = this.listRooms.values()[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
297
+ var room1 = _step1.value;
298
+ this.socket.emit("doctype_subscribe", room1.doctype);
299
+ }
300
+ } catch (err) {
301
+ _didIteratorError1 = true;
302
+ _iteratorError1 = err;
303
+ } finally {
304
+ try {
305
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
306
+ _iterator1.return();
307
+ }
308
+ } finally {
309
+ if (_didIteratorError1) {
310
+ throw _iteratorError1;
311
+ }
312
+ }
313
+ }
314
+ }
315
+ },
316
+ {
317
+ key: "connect",
318
+ value: (
319
+ /**
320
+ * Open the realtime transport now. Room-driven auto-connect
321
+ * (subscribeDoc/subscribeList) remains the primary lifecycle in both
322
+ * transports — this is public for SSE consumers that use no doc/list room
323
+ * bookkeeping: a one-way stream has nothing to emit on join, so nothing
324
+ * else would ever open it. Idempotent while a transport exists or a
325
+ * connect is in flight.
326
+ */
327
+ async function connect() {
328
+ if (this.isSSE()) return this.connectSSE();
329
+ if (this.socket || this.isConnecting) return;
330
+ this.isConnecting = true;
331
+ try {
332
+ var authOptions = await this.getAuthOptions();
333
+ var socketURL = this.getSocketURL();
334
+ var transports = this.config.platform === "web" ? ["polling", "websocket"] : ["websocket", "polling"];
335
+ this.socket = (0, import_socket.io)(socketURL, {
336
+ autoConnect: false,
337
+ path: "/socket.io",
338
+ randomizationFactor: .5,
339
+ reconnection: true,
340
+ reconnectionAttempts: Number.POSITIVE_INFINITY,
341
+ reconnectionDelay: 1e3,
342
+ reconnectionDelayMax: 5e3,
343
+ timeout: 2e4,
344
+ transports,
345
+ withCredentials: true,
346
+ ...authOptions,
347
+ ...this.config.socketOptions
348
+ });
349
+ this.initHandlers();
350
+ this.socket.connect();
351
+ } catch (err) {
352
+ this.isConnecting = false;
353
+ this.resolveHealthyWaiters(false);
354
+ throw err;
355
+ }
356
+ })
357
+ },
358
+ {
359
+ key: "connectSSE",
360
+ value: (
361
+ /**
362
+ * SSE branch of connect(): construct an EventSource against the configured
363
+ * stream URL. EventSource connects at construction, auto-reconnects on
364
+ * failure, and resumes missed frames itself by sending the stream's last
365
+ * `id:` as the `Last-Event-ID` request header — none of that is
366
+ * reimplemented here.
367
+ */
368
+ async function connectSSE() {
369
+ if (this.eventSource || this.isConnecting) return;
370
+ this.isConnecting = true;
371
+ try {
372
+ var _ref;
373
+ var sse = this.config.sse;
374
+ var EventSourceCtor = (_ref = sse === null || sse === void 0 ? void 0 : sse.EventSource) !== null && _ref !== void 0 ? _ref : globalThis.EventSource;
375
+ if (!EventSourceCtor) {
376
+ throw new Error("[RealtimeModule] transport \"sse\" needs an EventSource implementation, and this runtime has no global EventSource (React Native and Node < 22 ship none). Pass a constructor via config.sse.EventSource — e.g. the \"eventsource\" npm package on Node or \"react-native-sse\" on React Native.");
377
+ }
378
+ var url = await this.buildSSEURL();
379
+ this.eventSource = new EventSourceCtor(url, { withCredentials: sse === null || sse === void 0 ? void 0 : sse.withCredentials });
380
+ this.initSSEHandlers();
381
+ } catch (err) {
382
+ this.isConnecting = false;
383
+ this.resolveHealthyWaiters(false);
384
+ throw err;
385
+ }
386
+ })
387
+ },
388
+ {
389
+ key: "buildSSEURL",
390
+ value: async function buildSSEURL() {
391
+ var _ref;
392
+ var _this_config_sse;
393
+ var sse = this.config.sse;
394
+ var url;
395
+ if (sse === null || sse === void 0 ? void 0 : sse.url) {
396
+ url = sse.url;
397
+ } else if (sse === null || sse === void 0 ? void 0 : sse.path) {
398
+ var base = this.config.baseURL.replace(/\/$/, "");
399
+ url = `${base}${sse.path.startsWith("/") ? "" : "/"}${sse.path}`;
400
+ } else {
401
+ throw new Error("[RealtimeModule] transport \"sse\" requires config.sse.url or config.sse.path. There is no default stream path: SSE endpoints are server-specific (the SHC daemon serves \"/api/method/shc.events.stream\"; a real Frappe bench has no SSE endpoint at all), so a framework default would only ever 404.");
402
+ }
403
+ var params = Object.entries((_ref = (_this_config_sse = this.config.sse) === null || _this_config_sse === void 0 ? void 0 : _this_config_sse.queryParams) !== null && _ref !== void 0 ? _ref : {});
404
+ if (params.length === 0) return url;
405
+ var parts = [];
406
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
407
+ try {
408
+ for (var _iterator = params[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
409
+ var [key, value] = _step.value;
410
+ var resolved = typeof value === "function" ? await value() : value;
411
+ parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(resolved)}`);
412
+ }
413
+ } catch (err) {
414
+ _didIteratorError = true;
415
+ _iteratorError = err;
416
+ } finally {
417
+ try {
418
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
419
+ _iterator.return();
420
+ }
421
+ } finally {
422
+ if (_didIteratorError) {
423
+ throw _iteratorError;
424
+ }
425
+ }
426
+ }
427
+ return `${url}${url.includes("?") ? "&" : "?"}${parts.join("&")}`;
428
+ }
429
+ },
430
+ {
431
+ key: "initSSEHandlers",
432
+ value: function initSSEHandlers() {
433
+ var _ref;
434
+ var _this_config_sse;
435
+ this.attachedSseEvents.clear();
436
+ this.sseListeners.clear();
437
+ this.attachSSEListener("open");
438
+ this.attachSSEListener("error");
439
+ this.attachSSEListener("message");
440
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
441
+ try {
442
+ for (var _iterator = ((_ref = (_this_config_sse = this.config.sse) === null || _this_config_sse === void 0 ? void 0 : _this_config_sse.events) !== null && _ref !== void 0 ? _ref : [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
443
+ var type = _step.value;
444
+ this.attachSSEListener(type);
445
+ }
446
+ } catch (err) {
447
+ _didIteratorError = true;
448
+ _iteratorError = err;
449
+ } finally {
450
+ try {
451
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
452
+ _iterator.return();
453
+ }
454
+ } finally {
455
+ if (_didIteratorError) {
456
+ throw _iteratorError;
457
+ }
458
+ }
459
+ }
460
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
461
+ try {
462
+ for (var _iterator1 = this.handlerMap.keys()[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
463
+ var event = _step1.value;
464
+ this.attachSSEListener(event);
465
+ }
466
+ } catch (err) {
467
+ _didIteratorError1 = true;
468
+ _iteratorError1 = err;
469
+ } finally {
470
+ try {
471
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
472
+ _iterator1.return();
473
+ }
474
+ } finally {
475
+ if (_didIteratorError1) {
476
+ throw _iteratorError1;
477
+ }
478
+ }
479
+ }
480
+ }
481
+ },
482
+ {
483
+ key: "attachSSEListener",
484
+ value: function attachSSEListener(type) {
485
+ var _this = this;
486
+ if (!this.eventSource || this.attachedSseEvents.has(type)) return;
487
+ var listener = function listener2(event) {
488
+ _this.handleSSEEvent(type, event);
489
+ };
490
+ this.sseListeners.set(type, listener);
491
+ this.attachedSseEvents.add(type);
492
+ this.eventSource.addEventListener(type, listener);
493
+ }
494
+ },
495
+ {
496
+ key: "detachSSEListener",
497
+ value: function detachSSEListener(type) {
498
+ if (this.isCoreSSEType(type)) return;
499
+ if (!this.eventSource || !this.attachedSseEvents.has(type)) return;
500
+ var listener = this.sseListeners.get(type);
501
+ if (listener) {
502
+ this.eventSource.removeEventListener(type, listener);
503
+ this.sseListeners.delete(type);
504
+ }
505
+ this.attachedSseEvents.delete(type);
506
+ }
507
+ },
508
+ {
509
+ key: "isCoreSSEType",
510
+ value: function isCoreSSEType(type) {
511
+ var _ref;
512
+ var _this_config_sse;
513
+ return type === "open" || type === "error" || type === "message" || ((_ref = (_this_config_sse = this.config.sse) === null || _this_config_sse === void 0 ? void 0 : _this_config_sse.events) !== null && _ref !== void 0 ? _ref : []).includes(type);
514
+ }
515
+ },
516
+ {
517
+ key: "handleSSEEvent",
518
+ value: (
519
+ /**
520
+ * Single entry point for everything the EventSource dispatches. Dataless
521
+ * events are transport lifecycle (`open`/`error` as plain Events); anything
522
+ * carrying `data` is a server frame — including frames the server
523
+ * classified `event: error`, which arrive as MessageEvents WITH data and
524
+ * must not be mistaken for connection errors.
525
+ */
526
+ function handleSSEEvent(type, event) {
527
+ var _event_lastEventId;
528
+ var _this_config_sse;
529
+ if ((event === null || event === void 0 ? void 0 : event.data) === void 0) {
530
+ if (type === "open") {
531
+ this.isConnecting = false;
532
+ this.socketHealthy = true;
533
+ this.emitToHandlers("connected", { transport: "sse" });
534
+ this.resolveHealthyWaiters(true);
535
+ } else if (type === "error") {
536
+ this.isConnecting = false;
537
+ this.socketHealthy = false;
538
+ this.emitToHandlers("disconnect", { reason: "sse-error" });
539
+ this.resolveHealthyWaiters(false);
540
+ }
541
+ return;
542
+ }
543
+ var frame = {
544
+ type,
545
+ data: String(event.data),
546
+ lastEventId: (_event_lastEventId = event.lastEventId) !== null && _event_lastEventId !== void 0 ? _event_lastEventId : ""
547
+ };
548
+ var mapFrame = (_this_config_sse = this.config.sse) === null || _this_config_sse === void 0 ? void 0 : _this_config_sse.mapFrame;
549
+ if (mapFrame) {
550
+ var mapped;
551
+ try {
552
+ mapped = mapFrame(frame);
553
+ } catch (err) {
554
+ console.warn("[RealtimeModule] sse.mapFrame threw; frame dropped:", err);
555
+ return;
556
+ }
557
+ if (!mapped) return;
558
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
559
+ try {
560
+ for (var _iterator = mapped[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
561
+ var { event: mappedEvent, payload } = _step.value;
562
+ this.emitToHandlers(mappedEvent, payload);
563
+ }
564
+ } catch (err) {
565
+ _didIteratorError = true;
566
+ _iteratorError = err;
567
+ } finally {
568
+ try {
569
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
570
+ _iterator.return();
571
+ }
572
+ } finally {
573
+ if (_didIteratorError) {
574
+ throw _iteratorError;
575
+ }
576
+ }
577
+ }
578
+ return;
579
+ }
580
+ var payload1 = frame.data;
581
+ try {
582
+ payload1 = JSON.parse(frame.data);
583
+ } catch (unused) {}
584
+ this.emitToHandlers(frame.type, payload1);
585
+ })
586
+ },
587
+ {
588
+ key: "logSSERoomNoticeOnce",
589
+ value: (
590
+ /**
591
+ * Logged once: SSE is one-way, so doc/list room membership can't be sent
592
+ * upstream — rooms are recorded client-side (see getDocRooms/getListRooms)
593
+ * for mapFrame-driven filtering and for a future two-way transport.
594
+ */
595
+ function logSSERoomNoticeOnce() {
596
+ if (this.sseRoomNoticeLogged) return;
597
+ this.sseRoomNoticeLogged = true;
598
+ console.debug("[RealtimeModule] SSE transport is one-way: doc/list room subscriptions are recorded client-side only (getDocRooms()/getListRooms()) and nothing is sent to the server — filter server-side via sse.queryParams or route frames with sse.mapFrame.");
599
+ })
600
+ },
601
+ {
602
+ key: "softDisconnect",
603
+ value: (
604
+ /**
605
+ * Tear down the socket without clearing app handlers or room subscriptions.
606
+ * Used by auth refresh so listeners/rooms survive credential rotation.
607
+ */
608
+ function softDisconnect() {
609
+ if (this.socket) {
610
+ if (typeof this.socket.removeAllListeners === "function") {
611
+ this.socket.removeAllListeners();
612
+ }
613
+ this.socket.disconnect();
614
+ this.socket = void 0;
615
+ }
616
+ if (this.eventSource) {
617
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
618
+ try {
619
+ for (var _iterator = this.sseListeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
620
+ var [type, listener] = _step.value;
621
+ this.eventSource.removeEventListener(type, listener);
622
+ }
623
+ } catch (err) {
624
+ _didIteratorError = true;
625
+ _iteratorError = err;
626
+ } finally {
627
+ try {
628
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
629
+ _iterator.return();
630
+ }
631
+ } finally {
632
+ if (_didIteratorError) {
633
+ throw _iteratorError;
634
+ }
635
+ }
636
+ }
637
+ this.eventSource.close();
638
+ this.eventSource = void 0;
639
+ }
640
+ this.attachedSocketEvents.clear();
641
+ this.socketEventHandlers.clear();
642
+ this.attachedSseEvents.clear();
643
+ this.sseListeners.clear();
644
+ this.socketHealthy = false;
645
+ this.isConnecting = false;
646
+ this.resolveHealthyWaiters(false);
647
+ })
648
+ },
649
+ {
650
+ key: "initHandlers",
651
+ value: function initHandlers() {
652
+ var _this = this;
653
+ var _manager_on;
654
+ if (!this.socket) return;
655
+ this.attachedSocketEvents.clear();
656
+ this.socketEventHandlers.clear();
657
+ this.socket.on("connect", function() {
658
+ var _this_socket;
659
+ _this.isConnecting = false;
660
+ _this.socketHealthy = true;
661
+ _this.resubscribeRooms();
662
+ _this.emitToHandlers("connected", { sid: (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.id });
663
+ _this.resolveHealthyWaiters(true);
664
+ });
665
+ this.socket.on("disconnect", function(reason) {
666
+ _this.socketHealthy = false;
667
+ void _this.refreshSocketAuth();
668
+ _this.emitToHandlers("disconnect", { reason });
669
+ });
670
+ this.socket.on("connect_error", function(error) {
671
+ _this.isConnecting = false;
672
+ void _this.refreshSocketAuth();
673
+ _this.emitToHandlers("connect_error", error);
674
+ _this.resolveHealthyWaiters(false);
675
+ });
676
+ var manager = this.socket.io;
677
+ manager === null || manager === void 0 ? void 0 : (_manager_on = manager.on) === null || _manager_on === void 0 ? void 0 : _manager_on.call(manager, "reconnect_attempt", function() {
678
+ void _this.refreshSocketAuth();
679
+ });
680
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
681
+ try {
682
+ for (var _iterator = this.handlerMap.keys()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
683
+ var event = _step.value;
684
+ this.attachSocketListener(event);
685
+ }
686
+ } catch (err) {
687
+ _didIteratorError = true;
688
+ _iteratorError = err;
689
+ } finally {
690
+ try {
691
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
692
+ _iterator.return();
693
+ }
694
+ } finally {
695
+ if (_didIteratorError) {
696
+ throw _iteratorError;
697
+ }
698
+ }
699
+ }
700
+ }
701
+ },
702
+ {
703
+ key: "attachSocketListener",
704
+ value: (
705
+ /**
706
+ * Attaches a socket listener for an event, storing the reference to prevent duplicates.
707
+ */
708
+ function attachSocketListener(event) {
709
+ var _this = this;
710
+ if (!this.socket || this.attachedSocketEvents.has(event)) return;
711
+ var handler = function handler2(payload) {
712
+ _this.emitToHandlers(event, payload);
713
+ };
714
+ this.socketEventHandlers.set(event, handler);
715
+ this.attachedSocketEvents.add(event);
716
+ this.socket.on(event, handler);
717
+ })
718
+ },
719
+ {
720
+ key: "detachSocketListener",
721
+ value: (
722
+ /**
723
+ * Removes a socket listener for an event.
724
+ */
725
+ function detachSocketListener(event) {
726
+ if (!this.socket || !this.attachedSocketEvents.has(event)) return;
727
+ var handler = this.socketEventHandlers.get(event);
728
+ if (handler) {
729
+ this.socket.off(event, handler);
730
+ this.socketEventHandlers.delete(event);
731
+ }
732
+ this.attachedSocketEvents.delete(event);
733
+ })
734
+ },
735
+ {
736
+ key: "emitToHandlers",
737
+ value: function emitToHandlers(event, payload) {
738
+ var handlerSet = this.handlerMap.get(event);
739
+ if (!handlerSet) return;
740
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
741
+ try {
742
+ for (var _iterator = handlerSet[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
743
+ var handler = _step.value;
744
+ handler(payload);
745
+ }
746
+ } catch (err) {
747
+ _didIteratorError = true;
748
+ _iteratorError = err;
749
+ } finally {
750
+ try {
751
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
752
+ _iterator.return();
753
+ }
754
+ } finally {
755
+ if (_didIteratorError) {
756
+ throw _iteratorError;
757
+ }
758
+ }
759
+ }
760
+ }
761
+ },
762
+ {
763
+ key: "on",
764
+ value: async function on(event, handler) {
765
+ var handlerSet = this.handlerMap.get(event);
766
+ if (!handlerSet) {
767
+ handlerSet = /* @__PURE__ */ new Set();
768
+ this.handlerMap.set(event, handlerSet);
769
+ }
770
+ handlerSet.add(handler);
771
+ if (this.isSSE()) {
772
+ this.attachSSEListener(event);
773
+ } else {
774
+ this.attachSocketListener(event);
775
+ }
776
+ }
777
+ },
778
+ {
779
+ key: "off",
780
+ value: function off(event, handler) {
781
+ var handlerSet = this.handlerMap.get(event);
782
+ if (!handlerSet) return;
783
+ handlerSet.delete(handler);
784
+ if (handlerSet.size === 0) {
785
+ this.handlerMap.delete(event);
786
+ if (this.isSSE()) {
787
+ this.detachSSEListener(event);
788
+ } else {
789
+ this.detachSocketListener(event);
790
+ }
791
+ }
792
+ }
793
+ },
794
+ {
795
+ key: "subscribeDoc",
796
+ value: async function subscribeDoc(doctype, name) {
797
+ this.docRooms.set(docRoomKey(doctype, name), {
798
+ doctype,
799
+ name
800
+ });
801
+ if (this.isSSE()) this.logSSERoomNoticeOnce();
802
+ await this.ensureConnected();
803
+ if (!this.isSSE() && this.socket && this.socketHealthy) {
804
+ this.socket.emit("doc_subscribe", doctype, name);
805
+ }
806
+ }
807
+ },
808
+ {
809
+ key: "unsubscribeDoc",
810
+ value: function unsubscribeDoc(doctype, name) {
811
+ this.docRooms.delete(docRoomKey(doctype, name));
812
+ if (!this.isSSE() && this.socket && this.socketHealthy) {
813
+ this.socket.emit("doc_unsubscribe", doctype, name);
814
+ }
815
+ this.teardownWhenIdle();
816
+ }
817
+ },
818
+ {
819
+ key: "subscribeList",
820
+ value: (
821
+ /**
822
+ * Subscribe to list-level updates for a doctype (`list_update` events).
823
+ *
824
+ * `filters` are tracked client-side only: frappe's realtime server has a
825
+ * single room per doctype (`doctype_subscribe`) and does not support
826
+ * filtered list rooms.
827
+ */
828
+ async function subscribeList(doctype, filters) {
829
+ this.listRooms.set(doctype, {
830
+ doctype,
831
+ filters
832
+ });
833
+ if (this.isSSE()) this.logSSERoomNoticeOnce();
834
+ await this.ensureConnected();
835
+ if (!this.isSSE() && this.socket && this.socketHealthy) {
836
+ this.socket.emit("doctype_subscribe", doctype);
837
+ }
838
+ })
839
+ },
840
+ {
841
+ key: "unsubscribeList",
842
+ value: function unsubscribeList(doctype) {
843
+ this.listRooms.delete(doctype);
844
+ if (!this.isSSE() && this.socket && this.socketHealthy) {
845
+ this.socket.emit("doctype_unsubscribe", doctype);
846
+ }
847
+ this.teardownWhenIdle();
848
+ }
849
+ },
850
+ {
851
+ key: "teardownWhenIdle",
852
+ value: (
853
+ /**
854
+ * Tears the socket down when the last room is released. Room membership is
855
+ * the socket's reason to exist: while any subscription holds a room, the
856
+ * infinite Socket.IO reconnection loop is the reconnect catch-up protocol
857
+ * working as designed — but once nothing is subscribed, that same loop is
858
+ * a leak (unmounted consumers leaving a dead-host socket reconnect-polling
859
+ * forever). Handlers and any re-added rooms survive: the next
860
+ * subscribeDoc/subscribeList reconnects and re-attaches everything.
861
+ */
862
+ function teardownWhenIdle() {
863
+ if (this.docRooms.size > 0 || this.listRooms.size > 0) return;
864
+ if (!this.socket && !this.eventSource && !this.isConnecting) return;
865
+ this.emitToHandlers("disconnect", { reason: "idle-teardown" });
866
+ this.softDisconnect();
867
+ })
868
+ },
869
+ {
870
+ key: "isHealthy",
871
+ value: function isHealthy() {
872
+ var _this_socket;
873
+ if (this.isSSE()) return this.socketHealthy && this.eventSource !== void 0;
874
+ return this.socketHealthy && ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) === true;
875
+ }
876
+ },
877
+ {
878
+ key: "disconnect",
879
+ value: function disconnect() {
880
+ this.softDisconnect();
881
+ this.handlerMap.clear();
882
+ this.docRooms.clear();
883
+ this.listRooms.clear();
884
+ }
885
+ },
886
+ {
887
+ key: "updateAuth",
888
+ value: async function updateAuth(auth) {
889
+ this.config.auth = auth;
890
+ var shouldReconnect = this.docRooms.size > 0 || this.listRooms.size > 0 || this.isSSE() && this.eventSource !== void 0;
891
+ this.softDisconnect();
892
+ if (shouldReconnect) {
893
+ await this.connect();
894
+ }
895
+ }
896
+ },
897
+ {
898
+ key: "emit",
899
+ value: function emit(event, data) {
900
+ if (this.isSSE()) {
901
+ if (!this.sseEmitNoticeLogged) {
902
+ this.sseEmitNoticeLogged = true;
903
+ console.debug("[RealtimeModule] emit() is a no-op under the SSE transport — SSE is one-way (server → client). Use HTTP calls for client → server communication.");
904
+ }
905
+ return;
906
+ }
907
+ if (this.socket && this.socketHealthy) {
908
+ this.socket.emit(event, data);
909
+ }
910
+ }
911
+ },
912
+ {
913
+ key: "getSocket",
914
+ value: function getSocket() {
915
+ return this.socket;
916
+ }
917
+ },
918
+ {
919
+ /** Live EventSource when the SSE transport is connected (undefined otherwise). */
920
+ key: "getEventSource",
921
+ value: function getEventSource() {
922
+ return this.eventSource;
923
+ }
924
+ },
925
+ {
926
+ /**
927
+ * Doc rooms recorded by subscribeDoc. Under SSE these are client-side
928
+ * bookkeeping only (nothing is emitted upstream) — mapFrame-driven apps
929
+ * consult them to filter or route frames.
930
+ */
931
+ key: "getDocRooms",
932
+ value: function getDocRooms() {
933
+ return [...this.docRooms.values()];
934
+ }
935
+ },
936
+ {
937
+ /** List rooms recorded by subscribeList — same client-side semantics as getDocRooms. */
938
+ key: "getListRooms",
939
+ value: function getListRooms() {
940
+ return [...this.listRooms.values()];
941
+ }
942
+ }
943
+ ]);
944
+ return RealtimeModule2;
945
+ })();
77
946
 
78
- function RealtimeModule2(config) {
79
- _class_call_check(this, RealtimeModule2);
80
- _define_property(this, "socket", void 0);
81
- _define_property(this, "eventSource", void 0);
82
- _define_property(this, "handlerMap", /* @__PURE__ */new Map());
83
- _define_property(this, "attachedSocketEvents", /* @__PURE__ */new Set());
84
- _define_property(this, "socketEventHandlers", /* @__PURE__ */new Map());
85
- _define_property(this, "attachedSseEvents", /* @__PURE__ */new Set());
86
- _define_property(this, "sseListeners", /* @__PURE__ */new Map());
87
- _define_property(this, "sseRoomNoticeLogged", false);
88
- _define_property(this, "sseEmitNoticeLogged", false);
89
- _define_property(this, "docRooms", /* @__PURE__ */new Map());
90
- _define_property(this, "listRooms", /* @__PURE__ */new Map());
91
- _define_property(this, "socketHealthy", false);
92
- _define_property(this, "isConnecting", false);
93
- _define_property(this, "healthyWaiters", /* @__PURE__ */new Set());
94
- _define_property(this, "config", void 0);
95
- _define_property(this, "authRefreshInflight", void 0);
96
- this.config = {
97
- ...config,
98
- platform: config.platform || this.detectPlatform()
99
- };
100
- }
101
- _create_class(RealtimeModule2, [{
102
- key: "detectPlatform",
103
- value: function detectPlatform() {
104
- var _navigator_userAgent;
105
- if ((0, import_util.isGjs)()) return "node";
106
- if (import_platform.isNative || typeof navigator !== "undefined" && (navigator.product === "ReactNative" || ((_navigator_userAgent = navigator.userAgent) === null || _navigator_userAgent === void 0 ? void 0 : _navigator_userAgent.includes("ReactNative")))) {
107
- return "react-native";
108
- }
109
- if (!(0, import_util.isBrowser)()) return "node";
110
- return "web";
111
- }
112
- }, {
113
- key: "getSocketURL",
114
- value: function getSocketURL() {
115
- var base = this.config.baseURL.replace(/\/$/, "");
116
- if (this.config.socketBaseURL) {
117
- var socketBase = this.config.socketBaseURL.replace(/\/$/, "");
118
- var siteName = this.config.siteName;
119
- if (!siteName) {
120
- try {
121
- siteName = new URL(base).hostname;
122
- } catch (unused) {
123
- siteName = base.replace(/^https?:\/\//, "").split(/[/:]/)[0];
124
- }
125
- }
126
- return `${socketBase}/${siteName}`;
127
- }
128
- try {
129
- var url = new URL(base);
130
- var port = this.config.socketPort ? String(this.config.socketPort) : url.port;
131
- var host = port ? `${url.hostname}:${port}` : url.hostname;
132
- var siteName1 = this.config.siteName || url.hostname;
133
- return `${url.protocol}//${host}/${siteName1}`;
134
- } catch (unused) {
135
- var result = base;
136
- if (this.config.socketPort) {
137
- result = result.replace(/(:\d+)/, `:${this.config.socketPort}`);
138
- }
139
- var siteName2 = this.config.siteName || result.replace(/^https?:\/\//, "").split(/[/:]/)[0];
140
- return `${result}/${siteName2}`;
141
- }
142
- }
143
- }, {
144
- key: "getAuthOptions",
145
- value: async function getAuthOptions() {
146
- var _this_config_auth, _this_config_auth1;
147
- var authOptions = {};
148
- if (this.config.platform !== "web") {
149
- try {
150
- authOptions.extraHeaders = {
151
- Origin: new URL(this.config.baseURL).origin
152
- };
153
- } catch (unused) {
154
- authOptions.extraHeaders = {
155
- Origin: this.config.baseURL.replace(/\/$/, "")
156
- };
157
- }
158
- }
159
- if (this.config.platform !== "web" && ((_this_config_auth = this.config.auth) === null || _this_config_auth === void 0 ? void 0 : _this_config_auth.sessionId)) {
160
- var sessionId = typeof this.config.auth.sessionId === "function" ? await this.config.auth.sessionId() : this.config.auth.sessionId;
161
- var Cookie = `sid=${sessionId}`;
162
- authOptions.extraHeaders = {
163
- ...authOptions.extraHeaders,
164
- Cookie
165
- };
166
- }
167
- if (((_this_config_auth1 = this.config.auth) === null || _this_config_auth1 === void 0 ? void 0 : _this_config_auth1.useToken) && this.config.auth.token) {
168
- var token = typeof this.config.auth.token === "function" ? await this.config.auth.token() : this.config.auth.token;
169
- if (token) {
170
- var authType = this.config.auth.type || "Bearer";
171
- if (!authOptions.extraHeaders) authOptions.extraHeaders = {};
172
- authOptions.extraHeaders.Authorization = authType === "Bearer" ? `Bearer ${token}` : `token ${token}`;
173
- }
174
- }
175
- if (authOptions.extraHeaders) {
176
- authOptions.transportOptions = {
177
- websocket: {
178
- extraHeaders: {
179
- ...authOptions.extraHeaders
180
- }
181
- },
182
- polling: {
183
- extraHeaders: {
184
- ...authOptions.extraHeaders
185
- }
186
- }
187
- };
188
- }
189
- return authOptions;
190
- }
191
- }, {
192
- key: "refreshSocketAuth",
193
- value: (
194
- /**
195
- * Re-resolve credentials (token function / session id) and swap them into
196
- * the LIVE manager options in place. Socket.IO constructs a fresh engine
197
- * from `manager.opts` on every (re)connect attempt, so mutating the opts
198
- * makes the next handshake carry the refreshed token — without tearing
199
- * down handlers or room subscriptions. Called on disconnect and before
200
- * reconnect attempts so a token that rotated mid-session (e.g. Keycloak
201
- * refresh) never strands the socket in an auth-rejected retry loop.
202
- */
203
- function refreshSocketAuth() {
204
- var _this = this;
205
- var socket = this.socket;
206
- if (!socket) return Promise.resolve();
207
- if (this.authRefreshInflight) return this.authRefreshInflight;
208
- this.authRefreshInflight = async function () {
209
- try {
210
- var authOptions = await _this.getAuthOptions();
211
- var manager = socket.io;
212
- if (manager === null || manager === void 0 ? void 0 : manager.opts) Object.assign(manager.opts, authOptions);
213
- } catch (unused) {} finally {
214
- _this.authRefreshInflight = void 0;
215
- }
216
- }();
217
- return this.authRefreshInflight;
218
- })
219
- }, {
220
- key: "resolveHealthyWaiters",
221
- value: function resolveHealthyWaiters(ok) {
222
- var _iteratorNormalCompletion = true,
223
- _didIteratorError = false,
224
- _iteratorError = void 0;
225
- try {
226
- for (var _iterator = this.healthyWaiters[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
227
- var resolve = _step.value;
228
- resolve(ok);
229
- }
230
- } catch (err) {
231
- _didIteratorError = true;
232
- _iteratorError = err;
233
- } finally {
234
- try {
235
- if (!_iteratorNormalCompletion && _iterator.return != null) {
236
- _iterator.return();
237
- }
238
- } finally {
239
- if (_didIteratorError) {
240
- throw _iteratorError;
241
- }
242
- }
243
- }
244
- this.healthyWaiters.clear();
245
- }
246
- }, {
247
- key: "isSSE",
248
- value: function isSSE() {
249
- return this.config.transport === "sse";
250
- }
251
- }, {
252
- key: "waitUntilHealthy",
253
- value: function waitUntilHealthy() {
254
- var _this = this;
255
- var timeoutMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 2e4;
256
- if (this.isHealthy()) return Promise.resolve(true);
257
- return new Promise(function (resolve) {
258
- var timer = setTimeout(function () {
259
- _this.healthyWaiters.delete(onReady);
260
- resolve(false);
261
- }, timeoutMs);
262
- var onReady = function onReady2(ok) {
263
- clearTimeout(timer);
264
- resolve(ok);
265
- };
266
- _this.healthyWaiters.add(onReady);
267
- });
268
- }
269
- }, {
270
- key: "ensureConnected",
271
- value: async function ensureConnected() {
272
- if (this.isHealthy()) return;
273
- if (!this.socket && !this.eventSource && !this.isConnecting) {
274
- await this.connect();
275
- }
276
- await this.waitUntilHealthy();
277
- }
278
- }, {
279
- key: "resubscribeRooms",
280
- value: function resubscribeRooms() {
281
- if (!this.socket || !this.socketHealthy) return;
282
- var _iteratorNormalCompletion = true,
283
- _didIteratorError = false,
284
- _iteratorError = void 0;
285
- try {
286
- for (var _iterator = this.docRooms.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
287
- var room = _step.value;
288
- this.socket.emit("doc_subscribe", room.doctype, room.name);
289
- }
290
- } catch (err) {
291
- _didIteratorError = true;
292
- _iteratorError = err;
293
- } finally {
294
- try {
295
- if (!_iteratorNormalCompletion && _iterator.return != null) {
296
- _iterator.return();
297
- }
298
- } finally {
299
- if (_didIteratorError) {
300
- throw _iteratorError;
301
- }
302
- }
303
- }
304
- var _iteratorNormalCompletion1 = true,
305
- _didIteratorError1 = false,
306
- _iteratorError1 = void 0;
307
- try {
308
- for (var _iterator1 = this.listRooms.values()[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
309
- var room1 = _step1.value;
310
- this.socket.emit("doctype_subscribe", room1.doctype);
311
- }
312
- } catch (err) {
313
- _didIteratorError1 = true;
314
- _iteratorError1 = err;
315
- } finally {
316
- try {
317
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
318
- _iterator1.return();
319
- }
320
- } finally {
321
- if (_didIteratorError1) {
322
- throw _iteratorError1;
323
- }
324
- }
325
- }
326
- }
327
- }, {
328
- key: "connect",
329
- value: (
330
- /**
331
- * Open the realtime transport now. Room-driven auto-connect
332
- * (subscribeDoc/subscribeList) remains the primary lifecycle in both
333
- * transports — this is public for SSE consumers that use no doc/list room
334
- * bookkeeping: a one-way stream has nothing to emit on join, so nothing
335
- * else would ever open it. Idempotent while a transport exists or a
336
- * connect is in flight.
337
- */
338
- async function connect() {
339
- if (this.isSSE()) return this.connectSSE();
340
- if (this.socket || this.isConnecting) return;
341
- this.isConnecting = true;
342
- try {
343
- var authOptions = await this.getAuthOptions();
344
- var socketURL = this.getSocketURL();
345
- var transports = this.config.platform === "web" ? ["polling", "websocket"] : ["websocket", "polling"];
346
- this.socket = (0, import_socket.io)(socketURL, {
347
- autoConnect: false,
348
- path: "/socket.io",
349
- randomizationFactor: 0.5,
350
- reconnection: true,
351
- reconnectionAttempts: Number.POSITIVE_INFINITY,
352
- reconnectionDelay: 1e3,
353
- reconnectionDelayMax: 5e3,
354
- timeout: 2e4,
355
- transports,
356
- withCredentials: true,
357
- ...authOptions,
358
- ...this.config.socketOptions
359
- });
360
- this.initHandlers();
361
- this.socket.connect();
362
- } catch (err) {
363
- this.isConnecting = false;
364
- this.resolveHealthyWaiters(false);
365
- throw err;
366
- }
367
- })
368
- }, {
369
- key: "connectSSE",
370
- value: (
371
- /**
372
- * SSE branch of connect(): construct an EventSource against the configured
373
- * stream URL. EventSource connects at construction, auto-reconnects on
374
- * failure, and resumes missed frames itself by sending the stream's last
375
- * `id:` as the `Last-Event-ID` request header — none of that is
376
- * reimplemented here.
377
- */
378
- async function connectSSE() {
379
- if (this.eventSource || this.isConnecting) return;
380
- this.isConnecting = true;
381
- try {
382
- var _ref;
383
- var sse = this.config.sse;
384
- var EventSourceCtor = (_ref = sse === null || sse === void 0 ? void 0 : sse.EventSource) !== null && _ref !== void 0 ? _ref : globalThis.EventSource;
385
- if (!EventSourceCtor) {
386
- throw new Error('[RealtimeModule] transport "sse" needs an EventSource implementation, and this runtime has no global EventSource (React Native and Node < 22 ship none). Pass a constructor via config.sse.EventSource \u2014 e.g. the "eventsource" npm package on Node or "react-native-sse" on React Native.');
387
- }
388
- var url = await this.buildSSEURL();
389
- this.eventSource = new EventSourceCtor(url, {
390
- withCredentials: sse === null || sse === void 0 ? void 0 : sse.withCredentials
391
- });
392
- this.initSSEHandlers();
393
- } catch (err) {
394
- this.isConnecting = false;
395
- this.resolveHealthyWaiters(false);
396
- throw err;
397
- }
398
- })
399
- }, {
400
- key: "buildSSEURL",
401
- value: async function buildSSEURL() {
402
- var _ref;
403
- var _this_config_sse;
404
- var sse = this.config.sse;
405
- var url;
406
- if (sse === null || sse === void 0 ? void 0 : sse.url) {
407
- url = sse.url;
408
- } else if (sse === null || sse === void 0 ? void 0 : sse.path) {
409
- var base = this.config.baseURL.replace(/\/$/, "");
410
- url = `${base}${sse.path.startsWith("/") ? "" : "/"}${sse.path}`;
411
- } else {
412
- throw new Error('[RealtimeModule] transport "sse" requires config.sse.url or config.sse.path. There is no default stream path: SSE endpoints are server-specific (the SHC daemon serves "/api/method/shc.events.stream"; a real Frappe bench has no SSE endpoint at all), so a framework default would only ever 404.');
413
- }
414
- var params = Object.entries((_ref = (_this_config_sse = this.config.sse) === null || _this_config_sse === void 0 ? void 0 : _this_config_sse.queryParams) !== null && _ref !== void 0 ? _ref : {});
415
- if (params.length === 0) return url;
416
- var parts = [];
417
- var _iteratorNormalCompletion = true,
418
- _didIteratorError = false,
419
- _iteratorError = void 0;
420
- try {
421
- for (var _iterator = params[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
422
- var [key, value] = _step.value;
423
- var resolved = typeof value === "function" ? await value() : value;
424
- parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(resolved)}`);
425
- }
426
- } catch (err) {
427
- _didIteratorError = true;
428
- _iteratorError = err;
429
- } finally {
430
- try {
431
- if (!_iteratorNormalCompletion && _iterator.return != null) {
432
- _iterator.return();
433
- }
434
- } finally {
435
- if (_didIteratorError) {
436
- throw _iteratorError;
437
- }
438
- }
439
- }
440
- return `${url}${url.includes("?") ? "&" : "?"}${parts.join("&")}`;
441
- }
442
- }, {
443
- key: "initSSEHandlers",
444
- value: function initSSEHandlers() {
445
- var _ref;
446
- var _this_config_sse;
447
- this.attachedSseEvents.clear();
448
- this.sseListeners.clear();
449
- this.attachSSEListener("open");
450
- this.attachSSEListener("error");
451
- this.attachSSEListener("message");
452
- var _iteratorNormalCompletion = true,
453
- _didIteratorError = false,
454
- _iteratorError = void 0;
455
- try {
456
- for (var _iterator = ((_ref = (_this_config_sse = this.config.sse) === null || _this_config_sse === void 0 ? void 0 : _this_config_sse.events) !== null && _ref !== void 0 ? _ref : [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
457
- var type = _step.value;
458
- this.attachSSEListener(type);
459
- }
460
- } catch (err) {
461
- _didIteratorError = true;
462
- _iteratorError = err;
463
- } finally {
464
- try {
465
- if (!_iteratorNormalCompletion && _iterator.return != null) {
466
- _iterator.return();
467
- }
468
- } finally {
469
- if (_didIteratorError) {
470
- throw _iteratorError;
471
- }
472
- }
473
- }
474
- var _iteratorNormalCompletion1 = true,
475
- _didIteratorError1 = false,
476
- _iteratorError1 = void 0;
477
- try {
478
- for (var _iterator1 = this.handlerMap.keys()[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
479
- var event = _step1.value;
480
- this.attachSSEListener(event);
481
- }
482
- } catch (err) {
483
- _didIteratorError1 = true;
484
- _iteratorError1 = err;
485
- } finally {
486
- try {
487
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
488
- _iterator1.return();
489
- }
490
- } finally {
491
- if (_didIteratorError1) {
492
- throw _iteratorError1;
493
- }
494
- }
495
- }
496
- }
497
- }, {
498
- key: "attachSSEListener",
499
- value: function attachSSEListener(type) {
500
- var _this = this;
501
- if (!this.eventSource || this.attachedSseEvents.has(type)) return;
502
- var listener = function listener2(event) {
503
- _this.handleSSEEvent(type, event);
504
- };
505
- this.sseListeners.set(type, listener);
506
- this.attachedSseEvents.add(type);
507
- this.eventSource.addEventListener(type, listener);
508
- }
509
- }, {
510
- key: "detachSSEListener",
511
- value: function detachSSEListener(type) {
512
- if (this.isCoreSSEType(type)) return;
513
- if (!this.eventSource || !this.attachedSseEvents.has(type)) return;
514
- var listener = this.sseListeners.get(type);
515
- if (listener) {
516
- this.eventSource.removeEventListener(type, listener);
517
- this.sseListeners.delete(type);
518
- }
519
- this.attachedSseEvents.delete(type);
520
- }
521
- }, {
522
- key: "isCoreSSEType",
523
- value: function isCoreSSEType(type) {
524
- var _ref;
525
- var _this_config_sse;
526
- return type === "open" || type === "error" || type === "message" || ((_ref = (_this_config_sse = this.config.sse) === null || _this_config_sse === void 0 ? void 0 : _this_config_sse.events) !== null && _ref !== void 0 ? _ref : []).includes(type);
527
- }
528
- }, {
529
- key: "handleSSEEvent",
530
- value: (
531
- /**
532
- * Single entry point for everything the EventSource dispatches. Dataless
533
- * events are transport lifecycle (`open`/`error` as plain Events); anything
534
- * carrying `data` is a server frame — including frames the server
535
- * classified `event: error`, which arrive as MessageEvents WITH data and
536
- * must not be mistaken for connection errors.
537
- */
538
- function handleSSEEvent(type, event) {
539
- var _event_lastEventId;
540
- var _this_config_sse;
541
- if ((event === null || event === void 0 ? void 0 : event.data) === void 0) {
542
- if (type === "open") {
543
- this.isConnecting = false;
544
- this.socketHealthy = true;
545
- this.emitToHandlers("connected", {
546
- transport: "sse"
547
- });
548
- this.resolveHealthyWaiters(true);
549
- } else if (type === "error") {
550
- this.isConnecting = false;
551
- this.socketHealthy = false;
552
- this.emitToHandlers("disconnect", {
553
- reason: "sse-error"
554
- });
555
- this.resolveHealthyWaiters(false);
556
- }
557
- return;
558
- }
559
- var frame = {
560
- type,
561
- data: String(event.data),
562
- lastEventId: (_event_lastEventId = event.lastEventId) !== null && _event_lastEventId !== void 0 ? _event_lastEventId : ""
563
- };
564
- var mapFrame = (_this_config_sse = this.config.sse) === null || _this_config_sse === void 0 ? void 0 : _this_config_sse.mapFrame;
565
- if (mapFrame) {
566
- var mapped;
567
- try {
568
- mapped = mapFrame(frame);
569
- } catch (err) {
570
- console.warn("[RealtimeModule] sse.mapFrame threw; frame dropped:", err);
571
- return;
572
- }
573
- if (!mapped) return;
574
- var _iteratorNormalCompletion = true,
575
- _didIteratorError = false,
576
- _iteratorError = void 0;
577
- try {
578
- for (var _iterator = mapped[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
579
- var {
580
- event: mappedEvent,
581
- payload
582
- } = _step.value;
583
- this.emitToHandlers(mappedEvent, payload);
584
- }
585
- } catch (err) {
586
- _didIteratorError = true;
587
- _iteratorError = err;
588
- } finally {
589
- try {
590
- if (!_iteratorNormalCompletion && _iterator.return != null) {
591
- _iterator.return();
592
- }
593
- } finally {
594
- if (_didIteratorError) {
595
- throw _iteratorError;
596
- }
597
- }
598
- }
599
- return;
600
- }
601
- var payload1 = frame.data;
602
- try {
603
- payload1 = JSON.parse(frame.data);
604
- } catch (unused) {}
605
- this.emitToHandlers(frame.type, payload1);
606
- })
607
- }, {
608
- key: "logSSERoomNoticeOnce",
609
- value: (
610
- /**
611
- * Logged once: SSE is one-way, so doc/list room membership can't be sent
612
- * upstream — rooms are recorded client-side (see getDocRooms/getListRooms)
613
- * for mapFrame-driven filtering and for a future two-way transport.
614
- */
615
- function logSSERoomNoticeOnce() {
616
- if (this.sseRoomNoticeLogged) return;
617
- this.sseRoomNoticeLogged = true;
618
- console.debug("[RealtimeModule] SSE transport is one-way: doc/list room subscriptions are recorded client-side only (getDocRooms()/getListRooms()) and nothing is sent to the server \u2014 filter server-side via sse.queryParams or route frames with sse.mapFrame.");
619
- })
620
- }, {
621
- key: "softDisconnect",
622
- value: (
623
- /**
624
- * Tear down the socket without clearing app handlers or room subscriptions.
625
- * Used by auth refresh so listeners/rooms survive credential rotation.
626
- */
627
- function softDisconnect() {
628
- if (this.socket) {
629
- if (typeof this.socket.removeAllListeners === "function") {
630
- this.socket.removeAllListeners();
631
- }
632
- this.socket.disconnect();
633
- this.socket = void 0;
634
- }
635
- if (this.eventSource) {
636
- var _iteratorNormalCompletion = true,
637
- _didIteratorError = false,
638
- _iteratorError = void 0;
639
- try {
640
- for (var _iterator = this.sseListeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
641
- var [type, listener] = _step.value;
642
- this.eventSource.removeEventListener(type, listener);
643
- }
644
- } catch (err) {
645
- _didIteratorError = true;
646
- _iteratorError = err;
647
- } finally {
648
- try {
649
- if (!_iteratorNormalCompletion && _iterator.return != null) {
650
- _iterator.return();
651
- }
652
- } finally {
653
- if (_didIteratorError) {
654
- throw _iteratorError;
655
- }
656
- }
657
- }
658
- this.eventSource.close();
659
- this.eventSource = void 0;
660
- }
661
- this.attachedSocketEvents.clear();
662
- this.socketEventHandlers.clear();
663
- this.attachedSseEvents.clear();
664
- this.sseListeners.clear();
665
- this.socketHealthy = false;
666
- this.isConnecting = false;
667
- this.resolveHealthyWaiters(false);
668
- })
669
- }, {
670
- key: "initHandlers",
671
- value: function initHandlers() {
672
- var _this = this;
673
- var _manager_on;
674
- if (!this.socket) return;
675
- this.attachedSocketEvents.clear();
676
- this.socketEventHandlers.clear();
677
- this.socket.on("connect", function () {
678
- var _this_socket;
679
- _this.isConnecting = false;
680
- _this.socketHealthy = true;
681
- _this.resubscribeRooms();
682
- _this.emitToHandlers("connected", {
683
- sid: (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.id
684
- });
685
- _this.resolveHealthyWaiters(true);
686
- });
687
- this.socket.on("disconnect", function (reason) {
688
- _this.socketHealthy = false;
689
- void _this.refreshSocketAuth();
690
- _this.emitToHandlers("disconnect", {
691
- reason
692
- });
693
- });
694
- this.socket.on("connect_error", function (error) {
695
- _this.isConnecting = false;
696
- void _this.refreshSocketAuth();
697
- _this.emitToHandlers("connect_error", error);
698
- _this.resolveHealthyWaiters(false);
699
- });
700
- var manager = this.socket.io;
701
- manager === null || manager === void 0 ? void 0 : (_manager_on = manager.on) === null || _manager_on === void 0 ? void 0 : _manager_on.call(manager, "reconnect_attempt", function () {
702
- void _this.refreshSocketAuth();
703
- });
704
- var _iteratorNormalCompletion = true,
705
- _didIteratorError = false,
706
- _iteratorError = void 0;
707
- try {
708
- for (var _iterator = this.handlerMap.keys()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
709
- var event = _step.value;
710
- this.attachSocketListener(event);
711
- }
712
- } catch (err) {
713
- _didIteratorError = true;
714
- _iteratorError = err;
715
- } finally {
716
- try {
717
- if (!_iteratorNormalCompletion && _iterator.return != null) {
718
- _iterator.return();
719
- }
720
- } finally {
721
- if (_didIteratorError) {
722
- throw _iteratorError;
723
- }
724
- }
725
- }
726
- }
727
- }, {
728
- key: "attachSocketListener",
729
- value: (
730
- /**
731
- * Attaches a socket listener for an event, storing the reference to prevent duplicates.
732
- */
733
- function attachSocketListener(event) {
734
- var _this = this;
735
- if (!this.socket || this.attachedSocketEvents.has(event)) return;
736
- var handler = function handler2(payload) {
737
- _this.emitToHandlers(event, payload);
738
- };
739
- this.socketEventHandlers.set(event, handler);
740
- this.attachedSocketEvents.add(event);
741
- this.socket.on(event, handler);
742
- })
743
- }, {
744
- key: "detachSocketListener",
745
- value: (
746
- /**
747
- * Removes a socket listener for an event.
748
- */
749
- function detachSocketListener(event) {
750
- if (!this.socket || !this.attachedSocketEvents.has(event)) return;
751
- var handler = this.socketEventHandlers.get(event);
752
- if (handler) {
753
- this.socket.off(event, handler);
754
- this.socketEventHandlers.delete(event);
755
- }
756
- this.attachedSocketEvents.delete(event);
757
- })
758
- }, {
759
- key: "emitToHandlers",
760
- value: function emitToHandlers(event, payload) {
761
- var handlerSet = this.handlerMap.get(event);
762
- if (!handlerSet) return;
763
- var _iteratorNormalCompletion = true,
764
- _didIteratorError = false,
765
- _iteratorError = void 0;
766
- try {
767
- for (var _iterator = handlerSet[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
768
- var handler = _step.value;
769
- handler(payload);
770
- }
771
- } catch (err) {
772
- _didIteratorError = true;
773
- _iteratorError = err;
774
- } finally {
775
- try {
776
- if (!_iteratorNormalCompletion && _iterator.return != null) {
777
- _iterator.return();
778
- }
779
- } finally {
780
- if (_didIteratorError) {
781
- throw _iteratorError;
782
- }
783
- }
784
- }
785
- }
786
- }, {
787
- key: "on",
788
- value: async function on(event, handler) {
789
- var handlerSet = this.handlerMap.get(event);
790
- if (!handlerSet) {
791
- handlerSet = /* @__PURE__ */new Set();
792
- this.handlerMap.set(event, handlerSet);
793
- }
794
- handlerSet.add(handler);
795
- if (this.isSSE()) {
796
- this.attachSSEListener(event);
797
- } else {
798
- this.attachSocketListener(event);
799
- }
800
- }
801
- }, {
802
- key: "off",
803
- value: function off(event, handler) {
804
- var handlerSet = this.handlerMap.get(event);
805
- if (!handlerSet) return;
806
- handlerSet.delete(handler);
807
- if (handlerSet.size === 0) {
808
- this.handlerMap.delete(event);
809
- if (this.isSSE()) {
810
- this.detachSSEListener(event);
811
- } else {
812
- this.detachSocketListener(event);
813
- }
814
- }
815
- }
816
- }, {
817
- key: "subscribeDoc",
818
- value: async function subscribeDoc(doctype, name) {
819
- this.docRooms.set(docRoomKey(doctype, name), {
820
- doctype,
821
- name
822
- });
823
- if (this.isSSE()) this.logSSERoomNoticeOnce();
824
- await this.ensureConnected();
825
- if (!this.isSSE() && this.socket && this.socketHealthy) {
826
- this.socket.emit("doc_subscribe", doctype, name);
827
- }
828
- }
829
- }, {
830
- key: "unsubscribeDoc",
831
- value: function unsubscribeDoc(doctype, name) {
832
- this.docRooms.delete(docRoomKey(doctype, name));
833
- if (!this.isSSE() && this.socket && this.socketHealthy) {
834
- this.socket.emit("doc_unsubscribe", doctype, name);
835
- }
836
- this.teardownWhenIdle();
837
- }
838
- }, {
839
- key: "subscribeList",
840
- value: (
841
- /**
842
- * Subscribe to list-level updates for a doctype (`list_update` events).
843
- *
844
- * `filters` are tracked client-side only: frappe's realtime server has a
845
- * single room per doctype (`doctype_subscribe`) and does not support
846
- * filtered list rooms.
847
- */
848
- async function subscribeList(doctype, filters) {
849
- this.listRooms.set(doctype, {
850
- doctype,
851
- filters
852
- });
853
- if (this.isSSE()) this.logSSERoomNoticeOnce();
854
- await this.ensureConnected();
855
- if (!this.isSSE() && this.socket && this.socketHealthy) {
856
- this.socket.emit("doctype_subscribe", doctype);
857
- }
858
- })
859
- }, {
860
- key: "unsubscribeList",
861
- value: function unsubscribeList(doctype) {
862
- this.listRooms.delete(doctype);
863
- if (!this.isSSE() && this.socket && this.socketHealthy) {
864
- this.socket.emit("doctype_unsubscribe", doctype);
865
- }
866
- this.teardownWhenIdle();
867
- }
868
- }, {
869
- key: "teardownWhenIdle",
870
- value: (
871
- /**
872
- * Tears the socket down when the last room is released. Room membership is
873
- * the socket's reason to exist: while any subscription holds a room, the
874
- * infinite Socket.IO reconnection loop is the reconnect catch-up protocol
875
- * working as designed — but once nothing is subscribed, that same loop is
876
- * a leak (unmounted consumers leaving a dead-host socket reconnect-polling
877
- * forever). Handlers and any re-added rooms survive: the next
878
- * subscribeDoc/subscribeList reconnects and re-attaches everything.
879
- */
880
- function teardownWhenIdle() {
881
- if (this.docRooms.size > 0 || this.listRooms.size > 0) return;
882
- if (!this.socket && !this.eventSource && !this.isConnecting) return;
883
- this.emitToHandlers("disconnect", {
884
- reason: "idle-teardown"
885
- });
886
- this.softDisconnect();
887
- })
888
- }, {
889
- key: "isHealthy",
890
- value: function isHealthy() {
891
- var _this_socket;
892
- if (this.isSSE()) return this.socketHealthy && this.eventSource !== void 0;
893
- return this.socketHealthy && ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) === true;
894
- }
895
- }, {
896
- key: "disconnect",
897
- value: function disconnect() {
898
- this.softDisconnect();
899
- this.handlerMap.clear();
900
- this.docRooms.clear();
901
- this.listRooms.clear();
902
- }
903
- }, {
904
- key: "updateAuth",
905
- value: async function updateAuth(auth) {
906
- this.config.auth = auth;
907
- var shouldReconnect = this.docRooms.size > 0 || this.listRooms.size > 0 || this.isSSE() && this.eventSource !== void 0;
908
- this.softDisconnect();
909
- if (shouldReconnect) {
910
- await this.connect();
911
- }
912
- }
913
- }, {
914
- key: "emit",
915
- value: function emit(event, data) {
916
- if (this.isSSE()) {
917
- if (!this.sseEmitNoticeLogged) {
918
- this.sseEmitNoticeLogged = true;
919
- console.debug("[RealtimeModule] emit() is a no-op under the SSE transport \u2014 SSE is one-way (server \u2192 client). Use HTTP calls for client \u2192 server communication.");
920
- }
921
- return;
922
- }
923
- if (this.socket && this.socketHealthy) {
924
- this.socket.emit(event, data);
925
- }
926
- }
927
- }, {
928
- key: "getSocket",
929
- value: function getSocket() {
930
- return this.socket;
931
- }
932
- }, {
933
- /** Live EventSource when the SSE transport is connected (undefined otherwise). */
934
- key: "getEventSource",
935
- value: function getEventSource() {
936
- return this.eventSource;
937
- }
938
- }, {
939
- /**
940
- * Doc rooms recorded by subscribeDoc. Under SSE these are client-side
941
- * bookkeeping only (nothing is emitted upstream) — mapFrame-driven apps
942
- * consult them to filter or route frames.
943
- */
944
- key: "getDocRooms",
945
- value: function getDocRooms() {
946
- return [...this.docRooms.values()];
947
- }
948
- }, {
949
- /** List rooms recorded by subscribeList — same client-side semantics as getDocRooms. */
950
- key: "getListRooms",
951
- value: function getListRooms() {
952
- return [...this.listRooms.values()];
953
- }
954
- }]);
955
- return RealtimeModule2;
956
- }();
957
947
  //# sourceMappingURL=realtime.native.js.map