@utk09/ui-observability 0.10.0 → 0.11.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 (186) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/README.md +50 -11
  3. package/dist/{batch-BHXypM1j.cjs → batch-C8OcWR2L.cjs} +2 -2
  4. package/dist/{batch-BHXypM1j.cjs.map → batch-C8OcWR2L.cjs.map} +1 -1
  5. package/dist/{batch-BMdT9mKm.js → batch-CL9uWYY3.js} +4 -5
  6. package/dist/{batch-BMdT9mKm.js.map → batch-CL9uWYY3.js.map} +1 -1
  7. package/dist/{bus-DKfBaica.js → bus-BZ0GldpT.js} +23 -27
  8. package/dist/{bus-DKfBaica.js.map → bus-BZ0GldpT.js.map} +1 -1
  9. package/dist/{bus-Dea9rVhy.cjs → bus-VWlmM5xs.cjs} +2 -2
  10. package/dist/{bus-Dea9rVhy.cjs.map → bus-VWlmM5xs.cjs.map} +1 -1
  11. package/dist/console-BPZCuSLc.cjs +2 -0
  12. package/dist/{console-DZEcs7FL.cjs.map → console-BPZCuSLc.cjs.map} +1 -1
  13. package/dist/{console-BX_0UCV7.js → console-BeCF7n59.js} +14 -15
  14. package/dist/{console-BX_0UCV7.js.map → console-BeCF7n59.js.map} +1 -1
  15. package/dist/{constants-CL0ZdI2f.cjs → constants-DqKJH_MP.cjs} +2 -2
  16. package/dist/{constants-CL0ZdI2f.cjs.map → constants-DqKJH_MP.cjs.map} +1 -1
  17. package/dist/{constants-CU60FG4w.js → constants-zyrqveN4.js} +3 -4
  18. package/dist/{constants-CU60FG4w.js.map → constants-zyrqveN4.js.map} +1 -1
  19. package/dist/context-storage-BjzeBSxH.cjs.map +1 -1
  20. package/dist/{context-storage-DxZf4Gfh.js → context-storage-BzkoHzkQ.js} +2 -3
  21. package/dist/{context-storage-DxZf4Gfh.js.map → context-storage-BzkoHzkQ.js.map} +1 -1
  22. package/dist/{deadline-5_PecIl5.js → deadline-BOjOxNHj.js} +3 -5
  23. package/dist/{deadline-5_PecIl5.js.map → deadline-BOjOxNHj.js.map} +1 -1
  24. package/dist/deadline-XSnm95pg.cjs.map +1 -1
  25. package/dist/{debug-bundle-yRkrU1ny.cjs → debug-bundle-BzJNpbF0.cjs} +2 -2
  26. package/dist/{debug-bundle-yRkrU1ny.cjs.map → debug-bundle-BzJNpbF0.cjs.map} +1 -1
  27. package/dist/{debug-bundle-CZZ6SQQh.js → debug-bundle-C7UkHZ-q.js} +5 -6
  28. package/dist/{debug-bundle-CZZ6SQQh.js.map → debug-bundle-C7UkHZ-q.js.map} +1 -1
  29. package/dist/doctor.cjs +1 -1
  30. package/dist/doctor.cjs.map +1 -1
  31. package/dist/doctor.js +3 -4
  32. package/dist/{emergency-queue-CQ-9acZf.cjs → emergency-queue-CNTRui5t.cjs} +2 -2
  33. package/dist/{emergency-queue-CQ-9acZf.cjs.map → emergency-queue-CNTRui5t.cjs.map} +1 -1
  34. package/dist/{emergency-queue-Cs8-i2xw.js → emergency-queue-Zy6lNafo.js} +15 -17
  35. package/dist/{emergency-queue-Cs8-i2xw.js.map → emergency-queue-Zy6lNafo.js.map} +1 -1
  36. package/dist/{error-like-Ywo5uRHo.js → error-like-B11pB4aL.js} +2 -3
  37. package/dist/{error-like-Ywo5uRHo.js.map → error-like-B11pB4aL.js.map} +1 -1
  38. package/dist/error-like-gGRx2s36.cjs.map +1 -1
  39. package/dist/{errors-oyxrpHjY.js → errors-Dh7kef0i.js} +5 -6
  40. package/dist/{errors-oyxrpHjY.js.map → errors-Dh7kef0i.js.map} +1 -1
  41. package/dist/{errors-CigX45pL.cjs → errors-tfEr48bS.cjs} +2 -2
  42. package/dist/{errors-CigX45pL.cjs.map → errors-tfEr48bS.cjs.map} +1 -1
  43. package/dist/{factory-Bgsky_e0.js → factory-BonqI3NL.js} +9 -13
  44. package/dist/{factory-Bgsky_e0.js.map → factory-BonqI3NL.js.map} +1 -1
  45. package/dist/{factory-BkjNzPYL.cjs → factory-CJXVYp0R.cjs} +2 -2
  46. package/dist/{factory-BkjNzPYL.cjs.map → factory-CJXVYp0R.cjs.map} +1 -1
  47. package/dist/fixed-window-CvESpFYV.cjs.map +1 -1
  48. package/dist/{fixed-window-CtaFHanJ.js → fixed-window-Dq3MLUUv.js} +2 -3
  49. package/dist/{fixed-window-CtaFHanJ.js.map → fixed-window-Dq3MLUUv.js.map} +1 -1
  50. package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
  51. package/dist/{global-scope-dp2jADRl.js → global-scope-D9I8s-oN.js} +2 -3
  52. package/dist/{global-scope-dp2jADRl.js.map → global-scope-D9I8s-oN.js.map} +1 -1
  53. package/dist/{guards-CpvOpJL6.js → guards-Cidk71ME.js} +2 -3
  54. package/dist/{guards-CpvOpJL6.js.map → guards-Cidk71ME.js.map} +1 -1
  55. package/dist/guards-nJ70syPt.cjs.map +1 -1
  56. package/dist/{identity-BMlKGHUM.cjs → identity-Cxgj6pZX.cjs} +2 -2
  57. package/dist/{identity-BMlKGHUM.cjs.map → identity-Cxgj6pZX.cjs.map} +1 -1
  58. package/dist/{identity-DOaHdfhT.js → identity-DT5VmvXy.js} +3 -4
  59. package/dist/{identity-DOaHdfhT.js.map → identity-DT5VmvXy.js.map} +1 -1
  60. package/dist/index.cjs +1 -1
  61. package/dist/index.cjs.map +1 -1
  62. package/dist/index.js +46 -56
  63. package/dist/index.js.map +1 -1
  64. package/dist/{indexeddb-storage-D-lUW_5P.js → indexeddb-storage-BJVtiQKm.js} +5 -6
  65. package/dist/{indexeddb-storage-D-lUW_5P.js.map → indexeddb-storage-BJVtiQKm.js.map} +1 -1
  66. package/dist/{indexeddb-storage-CaXGJqDD.cjs → indexeddb-storage-CIoW21Xd.cjs} +2 -2
  67. package/dist/{indexeddb-storage-CaXGJqDD.cjs.map → indexeddb-storage-CIoW21Xd.cjs.map} +1 -1
  68. package/dist/{interactions-CqDNrtIR.js → interactions-DTgKy_6K.js} +10 -11
  69. package/dist/{interactions-CqDNrtIR.js.map → interactions-DTgKy_6K.js.map} +1 -1
  70. package/dist/{interactions-8DgxtmgO.cjs → interactions-fEN6FbVo.cjs} +2 -2
  71. package/dist/{interactions-8DgxtmgO.cjs.map → interactions-fEN6FbVo.cjs.map} +1 -1
  72. package/dist/{journey-DgIjhrIc.js → journey-CuJrHzEg.js} +9 -10
  73. package/dist/{journey-DgIjhrIc.js.map → journey-CuJrHzEg.js.map} +1 -1
  74. package/dist/{journey-5tcxEbnG.cjs → journey-pffMVMfa.cjs} +2 -2
  75. package/dist/{journey-5tcxEbnG.cjs.map → journey-pffMVMfa.cjs.map} +1 -1
  76. package/dist/keys-BHhw_0Wh.cjs.map +1 -1
  77. package/dist/{keys-D5r_GH9q.js → keys-BU9j5YqW.js} +2 -3
  78. package/dist/{keys-D5r_GH9q.js.map → keys-BU9j5YqW.js.map} +1 -1
  79. package/dist/library-console-C1m6g1BR.js +13 -0
  80. package/dist/{library-console-CabK2j2-.js.map → library-console-C1m6g1BR.js.map} +1 -1
  81. package/dist/{library-console-g_VU-wzP.cjs → library-console-D2GY9Or6.cjs} +2 -2
  82. package/dist/{library-console-g_VU-wzP.cjs.map → library-console-D2GY9Or6.cjs.map} +1 -1
  83. package/dist/{library-request-FQaiWjCP.cjs → library-request-1BX_UlaX.cjs} +2 -2
  84. package/dist/{library-request-FQaiWjCP.cjs.map → library-request-1BX_UlaX.cjs.map} +1 -1
  85. package/dist/{library-request-CyC-9IOk.js → library-request-BQBT9N9Q.js} +4 -5
  86. package/dist/{library-request-CyC-9IOk.js.map → library-request-BQBT9N9Q.js.map} +1 -1
  87. package/dist/{lifecycle-C2z_d8OX.cjs → lifecycle-2EtUaRpo.cjs} +2 -2
  88. package/dist/{lifecycle-C2z_d8OX.cjs.map → lifecycle-2EtUaRpo.cjs.map} +1 -1
  89. package/dist/{lifecycle-BLC4VU7c.js → lifecycle-BaKx_-32.js} +3 -4
  90. package/dist/{lifecycle-BLC4VU7c.js.map → lifecycle-BaKx_-32.js.map} +1 -1
  91. package/dist/{log-record-CndanC-p.js → log-record-CAoGBBf3.js} +3 -4
  92. package/dist/{log-record-CndanC-p.js.map → log-record-CAoGBBf3.js.map} +1 -1
  93. package/dist/{log-record-DKvo-B-d.cjs → log-record-i9zOTkpQ.cjs} +2 -2
  94. package/dist/{log-record-DKvo-B-d.cjs.map → log-record-i9zOTkpQ.cjs.map} +1 -1
  95. package/dist/{long-frames-CV5ZG2cx.cjs → long-frames-BVg4i5SC.cjs} +2 -2
  96. package/dist/{long-frames-CV5ZG2cx.cjs.map → long-frames-BVg4i5SC.cjs.map} +1 -1
  97. package/dist/{long-frames-BQef9rXR.js → long-frames-Czk7IupC.js} +4 -5
  98. package/dist/{long-frames-BQef9rXR.js.map → long-frames-Czk7IupC.js.map} +1 -1
  99. package/dist/{network-CvkvYzRU.js → network-DBNwApoF.js} +22 -24
  100. package/dist/{network-CvkvYzRU.js.map → network-DBNwApoF.js.map} +1 -1
  101. package/dist/{network-CqnQOqon.cjs → network-xbbuvG_6.cjs} +2 -2
  102. package/dist/{network-CqnQOqon.cjs.map → network-xbbuvG_6.cjs.map} +1 -1
  103. package/dist/openfin-Bxelt0yg.js +7 -0
  104. package/dist/{openfin-BwEN0uj4.js.map → openfin-Bxelt0yg.js.map} +1 -1
  105. package/dist/openfin-DtH2f7zX.cjs.map +1 -1
  106. package/dist/{otlp-RVbkNQRh.cjs → otlp-BDvFrLnc.cjs} +2 -2
  107. package/dist/{otlp-RVbkNQRh.cjs.map → otlp-BDvFrLnc.cjs.map} +1 -1
  108. package/dist/{otlp-CYIL7MOE.js → otlp-BTJdIa6F.js} +4 -6
  109. package/dist/{otlp-CYIL7MOE.js.map → otlp-BTJdIa6F.js.map} +1 -1
  110. package/dist/patch-BX8KrPCT.cjs.map +1 -1
  111. package/dist/{patch-CCWfuEY7.js → patch-UdPz1ea8.js} +2 -3
  112. package/dist/{patch-CCWfuEY7.js.map → patch-UdPz1ea8.js.map} +1 -1
  113. package/dist/{platform-KMWkoI-v.cjs → platform-C2Ez5kDc.cjs} +2 -2
  114. package/dist/{platform-KMWkoI-v.cjs.map → platform-C2Ez5kDc.cjs.map} +1 -1
  115. package/dist/{platform-wcAkkv9F.js → platform-DkcuXwe-.js} +4 -5
  116. package/dist/{platform-wcAkkv9F.js.map → platform-DkcuXwe-.js.map} +1 -1
  117. package/dist/{remote-rules-CH_7PphT.js → remote-rules-Cfb4K-Nl.js} +5 -6
  118. package/dist/{remote-rules-CH_7PphT.js.map → remote-rules-Cfb4K-Nl.js.map} +1 -1
  119. package/dist/{remote-rules-BL8km4xk.cjs → remote-rules-vzvk7aKf.cjs} +2 -2
  120. package/dist/{remote-rules-BL8km4xk.cjs.map → remote-rules-vzvk7aKf.cjs.map} +1 -1
  121. package/dist/{reports-Bh_-KpZ2.cjs → reports-Dk2YhKIh.cjs} +2 -2
  122. package/dist/{reports-Bh_-KpZ2.cjs.map → reports-Dk2YhKIh.cjs.map} +1 -1
  123. package/dist/{reports-BOKyY3_A.js → reports-TA-zInnq.js} +4 -5
  124. package/dist/{reports-BOKyY3_A.js.map → reports-TA-zInnq.js.map} +1 -1
  125. package/dist/{resource-timing-BROnEJ0E.js → resource-timing-BLv3EA2A.js} +6 -7
  126. package/dist/{resource-timing-BROnEJ0E.js.map → resource-timing-BLv3EA2A.js.map} +1 -1
  127. package/dist/{resource-timing-CbgwNpog.cjs → resource-timing-Cysw1S1f.cjs} +2 -2
  128. package/dist/{resource-timing-CbgwNpog.cjs.map → resource-timing-Cysw1S1f.cjs.map} +1 -1
  129. package/dist/{sampling-BLO_pcV4.js → sampling-C4VV-1MS.js} +4 -5
  130. package/dist/{sampling-BLO_pcV4.js.map → sampling-C4VV-1MS.js.map} +1 -1
  131. package/dist/{sampling-ECGVYiDD.cjs → sampling-Ckh2yW9k.cjs} +2 -2
  132. package/dist/{sampling-ECGVYiDD.cjs.map → sampling-Ckh2yW9k.cjs.map} +1 -1
  133. package/dist/{sanitize-DS0G4_ea.js → sanitize-6ymPlVvP.js} +4 -5
  134. package/dist/{sanitize-DS0G4_ea.js.map → sanitize-6ymPlVvP.js.map} +1 -1
  135. package/dist/{sanitize-Bsn8HQWC.cjs → sanitize-BAWzkZt0.cjs} +2 -2
  136. package/dist/{sanitize-Bsn8HQWC.cjs.map → sanitize-BAWzkZt0.cjs.map} +1 -1
  137. package/dist/{select-DWO0-w8_.cjs → select-ZF4by-lF.cjs} +2 -2
  138. package/dist/{select-DWO0-w8_.cjs.map → select-ZF4by-lF.cjs.map} +1 -1
  139. package/dist/{select-wqt9Wxio.js → select-xtQaenIi.js} +7 -10
  140. package/dist/{select-wqt9Wxio.js.map → select-xtQaenIi.js.map} +1 -1
  141. package/dist/{sender-BkAVt-Rq.js → sender-CiMHC9YG.js} +92 -96
  142. package/dist/{sender-BkAVt-Rq.js.map → sender-CiMHC9YG.js.map} +1 -1
  143. package/dist/{sender-D82PxlCY.cjs → sender-D5wBoXA8.cjs} +2 -2
  144. package/dist/{sender-D82PxlCY.cjs.map → sender-D5wBoXA8.cjs.map} +1 -1
  145. package/dist/storage-BA9RqRO-.cjs.map +1 -1
  146. package/dist/{storage-w7Tslvlq.js → storage-DZwed89z.js} +2 -3
  147. package/dist/{storage-w7Tslvlq.js.map → storage-DZwed89z.js.map} +1 -1
  148. package/dist/{storm-DCEsqViG.cjs → storm-CYi9Swpx.cjs} +2 -2
  149. package/dist/{storm-DCEsqViG.cjs.map → storm-CYi9Swpx.cjs.map} +1 -1
  150. package/dist/{storm-DD4cUkoL.js → storm-VR024_QN.js} +4 -5
  151. package/dist/{storm-DD4cUkoL.js.map → storm-VR024_QN.js.map} +1 -1
  152. package/dist/{types-BR9t_w28.js → types-BAerHgCq.js} +2 -3
  153. package/dist/{types-BR9t_w28.js.map → types-BAerHgCq.js.map} +1 -1
  154. package/dist/types-C7WNpnG1.cjs.map +1 -1
  155. package/dist/{unclean-exit-BYZ5yaSI.js → unclean-exit-CwcUhFOn.js} +3 -4
  156. package/dist/{unclean-exit-BYZ5yaSI.js.map → unclean-exit-CwcUhFOn.js.map} +1 -1
  157. package/dist/{unclean-exit-CwdpbUDg.cjs → unclean-exit-DFUN57wY.cjs} +2 -2
  158. package/dist/{unclean-exit-CwdpbUDg.cjs.map → unclean-exit-DFUN57wY.cjs.map} +1 -1
  159. package/dist/{user-timing-C1kB3JEg.cjs → user-timing-C9kfRq3J.cjs} +2 -2
  160. package/dist/{user-timing-C1kB3JEg.cjs.map → user-timing-C9kfRq3J.cjs.map} +1 -1
  161. package/dist/{user-timing-Di2ra5DB.js → user-timing-_jZIhDKI.js} +4 -5
  162. package/dist/{user-timing-Di2ra5DB.js.map → user-timing-_jZIhDKI.js.map} +1 -1
  163. package/dist/{web-socket-DwBNhgre.cjs → web-socket-BWUoqBh8.cjs} +2 -2
  164. package/dist/{web-socket-DwBNhgre.cjs.map → web-socket-BWUoqBh8.cjs.map} +1 -1
  165. package/dist/{web-socket-B-5qqPy7.js → web-socket-CV7yIMnm.js} +14 -15
  166. package/dist/{web-socket-B-5qqPy7.js.map → web-socket-CV7yIMnm.js.map} +1 -1
  167. package/dist/{web-vitals-Bflr5jSA.js → web-vitals-Bq4WFHQo.js} +2 -3
  168. package/dist/{web-vitals-Bflr5jSA.js.map → web-vitals-Bq4WFHQo.js.map} +1 -1
  169. package/dist/web-vitals-DFuoTQbZ.cjs.map +1 -1
  170. package/dist/{worker-protocol-DXekoADQ.cjs → worker-protocol-Bai7GAIA.cjs} +2 -2
  171. package/dist/{worker-protocol-DXekoADQ.cjs.map → worker-protocol-Bai7GAIA.cjs.map} +1 -1
  172. package/dist/{worker-protocol-0HMf4-kY.js → worker-protocol-CrsdSDLn.js} +6 -7
  173. package/dist/{worker-protocol-0HMf4-kY.js.map → worker-protocol-CrsdSDLn.js.map} +1 -1
  174. package/dist/worker-server-BrIYkfoa.cjs +2 -0
  175. package/dist/{worker-server-BQK5z2yl.cjs.map → worker-server-BrIYkfoa.cjs.map} +1 -1
  176. package/dist/{worker-server-CKcmX5m5.js → worker-server-Dp5HYm4b.js} +25 -26
  177. package/dist/{worker-server-CKcmX5m5.js.map → worker-server-Dp5HYm4b.js.map} +1 -1
  178. package/dist/{worker-transport-Dj2yCQN5.cjs → worker-transport-Bwej4N2e.cjs} +2 -2
  179. package/dist/{worker-transport-Dj2yCQN5.cjs.map → worker-transport-Bwej4N2e.cjs.map} +1 -1
  180. package/dist/{worker-transport-2220ghFZ.js → worker-transport-D6jtgpqN.js} +9 -11
  181. package/dist/{worker-transport-2220ghFZ.js.map → worker-transport-D6jtgpqN.js.map} +1 -1
  182. package/package.json +27 -41
  183. package/dist/console-DZEcs7FL.cjs +0 -2
  184. package/dist/library-console-CabK2j2-.js +0 -14
  185. package/dist/openfin-BwEN0uj4.js +0 -8
  186. package/dist/worker-server-BQK5z2yl.cjs +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"factory-Bgsky_e0.js","names":["STORAGE_NAME_MEMORY","BATCH_STORAGE_KEY_PREFIX","STORAGE_NAME_LOCAL","STORAGE_NAME_NONE","STORAGE_DB_NAME","STORAGE_PROBE_KEY","isLogBatch","countRecords","isActionRecord","keysWithPrefix","batchKey","hasAction","batch","EvictionPick","howMany","isAudit","item","pickEvictable","pick","items","addDrop","batches","records","reason","reportEviction","gap","diagnostics","onGap","dropped","createdAtOf","start","prefix","at","key","LocalStorageStorage","limits","out","limit","id","count","attempts","cutoff","result","expired","alive","createdAt","excess","context","keys","entry","entries","raw","parsed","MemoryStorage","index","stored","found","evicted","storageName","namespace","noop","hasIndexedDb","hasLocalStorage","createStorage","strategy","adapter","storage","IndexedDbStorage","dbName"],"sources":["../src/storage/eviction.ts","../src/storage/gap.ts","../src/storage/local-storage.ts","../src/storage/memory-storage.ts","../src/storage/factory.ts"],"sourcesContent":["// src/storage/eviction.ts\n//\n// This module selects the stored batches to evict. An action is an audit fact. The batches without\n// an action go first. The walk stops early. A read of the full store at each save blocks the page.\n\nimport { isActionRecord, type LogBatch } from \"../models/batch\";\n\n/**\n * Tests if a batch holds an action. An eviction removes such a batch last.\n * @param batch Batch to test.\n * @returns True if one record of the batch is an action.\n */\nexport function hasAction(batch: LogBatch): boolean {\n // Another script on the origin can write to the database. A throw in a cursor handler stops\n // the eviction walk. The walk then never settles.\n return Array.isArray(batch.records) && batch.records.some(isActionRecord);\n}\n\n/** Collects the items to evict from a walk in age order, oldest first. */\nexport class EvictionPick<T> {\n /** Items without an audit fact. */\n private readonly plain: T[] = [];\n\n /** Oldest items with an audit fact. The pick uses them only when too few plain items exist. */\n private readonly audit: T[] = [];\n\n /**\n * @param howMany Number of items to evict.\n * @param isAudit Tests if an item holds an audit fact.\n */\n constructor(\n private readonly howMany: number,\n private readonly isAudit: (item: T) => boolean,\n ) {}\n\n /**\n * Adds the next item of the walk.\n * @param item Next oldest item.\n * @returns False when the pick has enough items without an audit fact. The walk then stops.\n */\n add(item: T): boolean {\n if (!this.isAudit(item)) {\n this.plain.push(item);\n } else if (this.audit.length < this.howMany) {\n this.audit.push(item);\n }\n\n return this.plain.length < this.howMany;\n }\n\n /**\n * Gives the items to evict. The items without an audit fact come first.\n * @returns The picked items.\n */\n picked(): T[] {\n return [...this.plain, ...this.audit].slice(0, this.howMany);\n }\n}\n\n/**\n * Picks the items to evict from a walk in age order. It stops the walk early.\n * @param items Items, oldest first. A generator reads each item only when the walk needs it.\n * @param howMany Number of items to evict.\n * @param isAudit Tests if an item holds an audit fact.\n * @returns The picked items. The items without an audit fact come first.\n */\nexport function pickEvictable<T>(\n items: Iterable<T>,\n howMany: number,\n isAudit: (item: T) => boolean,\n): T[] {\n const pick = new EvictionPick(howMany, isAudit);\n\n for (const item of items) {\n if (!pick.add(item)) {\n break;\n }\n }\n\n return pick.picked();\n}\n","// src/storage/gap.ts\n//\n// This module counts and reports the batches that a storage adapter drops. Each dropped batch is a\n// loss. The gap handler gives it to onDrop.\n\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult } from \"../models/storage\";\n\n/**\n * Adds the drop of one rule to the prune result.\n * @param result Prune result of all rules.\n * @param reason Rule that dropped the batches.\n * @param batches Number of dropped batches.\n * @param records Number of dropped records.\n * @returns The counts of this rule alone, for the gap report.\n */\nexport function addDrop(\n result: PruneResult,\n reason: PruneResult[\"reason\"],\n batches: number,\n records: number,\n): PruneResult {\n result.batches += batches;\n result.records += records;\n result.reason = reason;\n return { batches, records, reason };\n}\n\n/**\n * Reports dropped batches to diagnostics and to the gap handler. An empty drop reports nothing.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Gap handler of the adapter.\n * @param gap Counts and reason of the drop.\n * @param dropped The dropped batches that the adapter could read.\n */\nexport function reportEviction(\n diagnostics: Diagnostics,\n onGap: GapReporter | undefined,\n gap: PruneResult,\n dropped: readonly LogBatch[],\n): void {\n if (gap.batches === 0) {\n return;\n }\n\n diagnostics.report(\n \"storage.evicted\",\n `The library dropped ${String(gap.batches)} stored batches (${String(gap.records)} records).`,\n { ...gap },\n );\n onGap?.(gap, dropped);\n}\n","// src/storage/local-storage.ts\n//\n// This module stores batches in localStorage with time-ordered keys. The padding makes\n// keys().sort() a sort by creation time. Without padding, the sort uses hex order. take()\n// then does not return the oldest batch first.\n\nimport {\n BATCH_KEY_TIME_WIDTH,\n BATCH_STORAGE_KEY_PREFIX,\n QUOTA_EVICTION_DIVISOR,\n STORAGE_NAME_LOCAL,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { countRecords, isLogBatch, type LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { hasAction, pickEvictable } from \"./eviction\";\nimport { addDrop, reportEviction } from \"./gap\";\nimport { batchKey, keysWithPrefix } from \"./keys\";\n\n/** A stored entry. A corrupt entry has no batch. */\ninterface Entry {\n key: string;\n batch: LogBatch | null;\n}\n\n/**\n * Reads the creation time from a storage key. prune() runs after each save. A\n * read from the batch parses the full store for each save.\n * @param key Prefixed storage key.\n * @returns Creation time in epoch milliseconds, or null for a malformed key.\n */\nfunction createdAtOf(key: string, prefix: string): number | null {\n const start = prefix.length;\n const at = Number(key.slice(start, start + BATCH_KEY_TIME_WIDTH));\n\n return Number.isFinite(at) ? at : null;\n}\n\n/** This StorageAdapter keeps batches in localStorage. */\nexport class LocalStorageStorage implements StorageAdapter {\n /** This field holds the storage strategy name. */\n readonly name = STORAGE_NAME_LOCAL;\n\n /**\n * @param limits Storage capacity and retention thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Optional callback for dropped record reporting.\n */\n constructor(\n private readonly limits: StorageLimits,\n private readonly diagnostics: Diagnostics,\n private readonly onGap?: GapReporter,\n private readonly prefix = BATCH_STORAGE_KEY_PREFIX,\n ) {}\n\n /**\n * Writes a batch to localStorage. It removes the oldest entries on a quota error.\n * @param batch Batch to store.\n */\n async save(batch: LogBatch): Promise<void> {\n if (this.write(batch, \"localStorage refused a batch, evicting the oldest\")) {\n await this.prune();\n return;\n }\n\n this.evictForQuota();\n\n // The eviction makes room for this batch. Without a second write, save() resolves.\n // The library then loses the batch. No counter shows the loss.\n if (!this.write(batch, \"localStorage refused a batch even after evicting\")) {\n const gap: PruneResult = { batches: 1, records: batch.records.length, reason: \"quota\" };\n reportEviction(this.diagnostics, this.onGap, gap, [batch]);\n }\n }\n\n /**\n * Returns up to `limit` batches in FIFO order. It does not delete them.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to an array of valid batches.\n */\n take(limit: number): Promise<LogBatch[]> {\n const out: LogBatch[] = [];\n\n for (const key of this.keys().slice(0, limit)) {\n const batch = this.read(key);\n // The entry is corrupt. The library cannot recover it. Remove it without a gap count. It has\n // no readable record count.\n if (batch === null) {\n this.removeKey(key);\n continue;\n }\n out.push(batch);\n }\n\n return Promise.resolve(out);\n }\n\n /**\n * Returns up to `limit` batches of one context in FIFO order. It does not delete them.\n * It stops at the limit. The later entries then stay unparsed.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to the batches of this context.\n */\n takeContext(id: string, limit: number): Promise<LogBatch[]> {\n const out: LogBatch[] = [];\n\n for (const batch of this.batches()) {\n if (out.length >= limit) {\n break;\n }\n if (batch.routingContextId === id) {\n out.push(batch);\n }\n }\n\n return Promise.resolve(out);\n }\n\n /**\n * Counts the stored batches of one context. The context id is not in the key. Each entry is read.\n * @param id Delivery context id.\n * @returns Promise that resolves to the batch count of this context.\n */\n countContext(id: string): Promise<number> {\n let count = 0;\n\n for (const batch of this.batches()) {\n if (batch.routingContextId === id) {\n count++;\n }\n }\n\n return Promise.resolve(count);\n }\n\n /**\n * Reads the valid batches one at a time, oldest first. It removes a corrupt entry.\n * @yields Each valid batch.\n */\n private *batches(): Generator<LogBatch> {\n for (const key of this.keys()) {\n const batch = this.read(key);\n if (batch === null) {\n this.removeKey(key);\n continue;\n }\n yield batch;\n }\n }\n\n /**\n * Deletes the batch with the given ID from localStorage.\n * @param id Batch identifier.\n */\n remove(id: string): Promise<void> {\n const key = this.keyOf(id);\n if (key !== null) {\n this.removeKey(key);\n }\n return Promise.resolve();\n }\n\n /**\n * Sets the delivery attempt count of a stored batch. It does not change the key.\n * @param id Batch identifier.\n * @param attempts New absolute attempt count.\n */\n bumpAttempts(id: string, attempts: number): Promise<void> {\n const key = this.keyOf(id);\n if (key === null) {\n return Promise.resolve();\n }\n\n const batch = this.read(key);\n if (batch === null) {\n return Promise.resolve();\n }\n\n batch.attempts = attempts;\n this.diagnostics.guard(\n \"storage.degraded\",\n \"The library could not update the attempt count.\",\n () => {\n localStorage.setItem(key, JSON.stringify(batch));\n },\n );\n\n return Promise.resolve();\n }\n\n /**\n * Deletes expired batches. It then removes the oldest batches above the\n * capacity limit.\n * @returns Promise that resolves to prune summary metrics.\n */\n prune(): Promise<PruneResult> {\n const cutoff = Date.now() - this.limits.maxAgeMs;\n const result: PruneResult = { batches: 0, records: 0, reason: \"expired\" };\n const expired: string[] = [];\n const alive: string[] = [];\n\n for (const key of this.keys()) {\n const createdAt = createdAtOf(key, this.prefix);\n // A key with no readable time also has no position in the sort order.\n if (createdAt === null || createdAt < cutoff) {\n expired.push(key);\n continue;\n }\n alive.push(key);\n }\n\n // The record count is the one field that the key does not contain. Parse only the\n // deleted batches.\n this.drop(result, \"expired\", [...this.entries(expired)]);\n\n const excess = alive.length - this.limits.maxBatches;\n if (excess > 0) {\n this.drop(result, \"over_capacity\", this.evictable(alive, excess));\n }\n\n return Promise.resolve(result);\n }\n\n /**\n * Returns the number of stored batch keys. It does not deserialize the batches.\n * @returns Promise that resolves to batch count.\n */\n count(): Promise<number> {\n return Promise.resolve(this.keys().length);\n }\n\n /** This method deletes all batch keys from localStorage. */\n clear(): Promise<void> {\n this.evict(this.keys());\n return Promise.resolve();\n }\n\n /** This method does nothing. localStorage has no connection to close. */\n close(): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Writes a batch to localStorage.\n * @param batch Batch to store.\n * @param context Text that diagnostics reports when the write fails.\n * @returns True if the write succeeded.\n */\n private write(batch: LogBatch, context: string): boolean {\n const written = this.diagnostics.guard(\"storage.quota_exceeded\", context, () => {\n localStorage.setItem(batchKey(this.prefix, batch), JSON.stringify(batch));\n return true;\n });\n\n return written === true;\n }\n\n /** This method removes a quarter of the store to free quota. It counts the loss. */\n private evictForQuota(): void {\n const keys = this.keys();\n const result: PruneResult = { batches: 0, records: 0, reason: \"quota\" };\n const howMany = Math.ceil(keys.length / QUOTA_EVICTION_DIVISOR);\n\n this.drop(result, \"quota\", this.evictable(keys, howMany));\n }\n\n /**\n * Picks the entries to evict. Entries without an action go first. An action is an audit fact.\n * A corrupt entry has no action. It goes first.\n * @param keys Batch keys, oldest first.\n * @param howMany Number of entries to evict.\n * @returns The picked entries.\n */\n private evictable(keys: string[], howMany: number): Entry[] {\n return pickEvictable(\n this.entries(keys),\n howMany,\n (entry) => entry.batch !== null && hasAction(entry.batch),\n );\n }\n\n /**\n * Reads the entries one at a time. The eviction walk stops early. The later entries then stay\n * unparsed.\n * @param keys Batch keys.\n * @yields Each key with its batch.\n */\n private *entries(keys: string[]): Generator<Entry> {\n for (const key of keys) {\n yield { key, batch: this.read(key) };\n }\n }\n\n /**\n * Removes entries. It reports them with their own reason.\n * @param result Prune result of all rules.\n * @param reason Rule that removes the entries.\n * @param entries Entries to remove.\n */\n private drop(result: PruneResult, reason: PruneResult[\"reason\"], entries: Entry[]): void {\n if (entries.length === 0) {\n return;\n }\n\n const dropped: LogBatch[] = [];\n\n for (const { key, batch } of entries) {\n this.removeKey(key);\n if (batch) {\n dropped.push(batch);\n }\n }\n\n // A corrupt entry counts as a batch with no records.\n const gap = addDrop(result, reason, entries.length, countRecords(dropped));\n reportEviction(this.diagnostics, this.onGap, gap, dropped);\n }\n\n /**\n * Reads and validates the stored batch at a key.\n * @param key Storage key to read.\n * @returns Validated LogBatch or null if missing or malformed.\n */\n private read(key: string): LogBatch | null {\n const raw = this.diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read a stored batch.\",\n () => localStorage.getItem(key),\n );\n if (!raw) {\n return null;\n }\n\n const parsed = this.diagnostics.guard(\n \"storage.degraded\",\n \"A stored batch is corrupt. The library removed it.\",\n () => JSON.parse(raw) as unknown,\n );\n // The guard above already reported a parse failure. A second report counts one corrupt\n // entry twice.\n if (parsed === undefined) {\n return null;\n }\n\n if (!isLogBatch(parsed)) {\n this.diagnostics.report(\n \"storage.degraded\",\n \"A stored entry is not a batch. The library dropped it.\",\n );\n return null;\n }\n\n return parsed;\n }\n\n /**\n * Finds the storage key that ends with the batch ID.\n * @param id Batch identifier.\n * @returns Matching storage key string or null.\n */\n private keyOf(id: string): string | null {\n return this.keys().find((key) => key.endsWith(`.${id}`)) ?? null;\n }\n\n /**\n * Deletes a list of storage keys.\n * @param keys Keys to delete.\n */\n private evict(keys: string[]): void {\n for (const key of keys) {\n this.removeKey(key);\n }\n }\n\n /**\n * Deletes one storage key inside a guard.\n * @param key Storage key to remove.\n */\n private removeKey(key: string): void {\n this.diagnostics.guard(\n \"storage.degraded\",\n \"The library could not remove a stored batch.\",\n () => {\n localStorage.removeItem(key);\n },\n );\n }\n\n /**\n * Returns all batch storage keys in sorted order.\n * @returns Sorted array of storage keys.\n */\n private keys(): string[] {\n return keysWithPrefix(this.prefix, this.diagnostics);\n }\n}\n","// src/storage/memory-storage.ts\n//\n// This module keeps batches in volatile memory during offline periods. A reload loses all of\n// them. This adapter is the last fallback.\n\nimport { STORAGE_NAME_MEMORY } from \"../constants\";\nimport { countRecords, type LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { hasAction, pickEvictable } from \"./eviction\";\nimport { addDrop } from \"./gap\";\n\n/** This StorageAdapter keeps batches in volatile memory. */\nexport class MemoryStorage implements StorageAdapter {\n /** This field holds the storage strategy name. */\n readonly name = STORAGE_NAME_MEMORY;\n\n /** This array holds the batches in FIFO order. */\n private batches: LogBatch[] = [];\n\n /**\n * @param limits Storage capacity and retention thresholds.\n * @param onGap Optional callback for dropped record reporting.\n */\n constructor(\n private readonly limits: StorageLimits,\n private readonly onGap?: GapReporter,\n ) {}\n\n /**\n * Appends a batch and applies retention pruning.\n * @param batch Batch to store.\n */\n async save(batch: LogBatch): Promise<void> {\n // A batch with a known id replaces the old copy in place, as IndexedDB put() does.\n const index = this.batches.findIndex((stored) => stored.id === batch.id);\n if (index >= 0) {\n this.batches[index] = batch;\n } else {\n this.batches.push(batch);\n }\n await this.prune();\n }\n\n /**\n * Returns up to `limit` batches in FIFO order. It does not delete them.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to an array of batches.\n */\n take(limit: number): Promise<LogBatch[]> {\n return Promise.resolve(this.batches.slice(0, limit));\n }\n\n /**\n * Returns up to `limit` batches of one context in FIFO order. It does not delete them.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to the batches of this context.\n */\n takeContext(id: string, limit: number): Promise<LogBatch[]> {\n return Promise.resolve(\n this.batches.filter((batch) => batch.routingContextId === id).slice(0, limit),\n );\n }\n\n /**\n * Counts the stored batches of one context.\n * @param id Delivery context id.\n * @returns Promise that resolves to the batch count of this context.\n */\n countContext(id: string): Promise<number> {\n return Promise.resolve(this.batches.filter((batch) => batch.routingContextId === id).length);\n }\n\n /**\n * Deletes the batch with the given ID.\n * @param id Batch identifier.\n */\n remove(id: string): Promise<void> {\n this.batches = this.batches.filter((batch) => batch.id !== id);\n return Promise.resolve();\n }\n\n /**\n * Sets the delivery attempt count of a stored batch.\n * @param id Batch identifier.\n * @param attempts New absolute attempt count.\n */\n bumpAttempts(id: string, attempts: number): Promise<void> {\n const found = this.batches.find((batch) => batch.id === id);\n if (found) {\n found.attempts = attempts;\n }\n return Promise.resolve();\n }\n\n /**\n * Removes expired batches. It then removes the oldest batches above the\n * capacity limit.\n * @returns Promise that resolves to prune summary metrics.\n */\n prune(): Promise<PruneResult> {\n const cutoff = Date.now() - this.limits.maxAgeMs;\n const result: PruneResult = { batches: 0, records: 0, reason: \"expired\" };\n\n const expired = this.batches.filter((batch) => batch.createdAt < cutoff);\n this.batches = this.batches.filter((batch) => batch.createdAt >= cutoff);\n this.report(result, \"expired\", expired);\n\n const excess = this.batches.length - this.limits.maxBatches;\n if (excess > 0) {\n // An action is an audit fact. Evict each batch without an action first.\n const evicted = pickEvictable(this.batches, excess, hasAction);\n this.batches = this.batches.filter((batch) => !evicted.includes(batch));\n this.report(result, \"over_capacity\", evicted);\n }\n\n return Promise.resolve(result);\n }\n\n /**\n * Adds dropped batches to the prune result. It reports them with their own reason.\n * @param result Prune result of all rules.\n * @param reason Rule that dropped the batches.\n * @param dropped The dropped batches.\n */\n private report(result: PruneResult, reason: PruneResult[\"reason\"], dropped: LogBatch[]): void {\n if (dropped.length === 0) {\n return;\n }\n\n const gap = addDrop(result, reason, dropped.length, countRecords(dropped));\n this.onGap?.(gap, dropped);\n }\n\n /**\n * Returns the number of stored batches.\n * @returns Promise that resolves to batch count.\n */\n count(): Promise<number> {\n return Promise.resolve(this.batches.length);\n }\n\n /** This method deletes all stored batches. */\n clear(): Promise<void> {\n this.batches = [];\n return Promise.resolve();\n }\n\n /** This method deletes all stored batches when the storage closes. */\n close(): Promise<void> {\n this.batches = [];\n return Promise.resolve();\n }\n}\n","// src/storage/factory.ts\n//\n// This module selects a storage adapter. It falls back from IndexedDB to localStorage to memory.\n// It falls back and does not throw. IndexedDB is unavailable in private mode and sandboxed\n// frames.\n\nimport {\n STORAGE_DB_NAME,\n STORAGE_NAME_INDEXEDDB,\n STORAGE_NAME_MEMORY,\n STORAGE_NAME_NONE,\n STORAGE_PROBE_KEY,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { StorageStrategy } from \"../models/config\";\nimport type { GapReporter, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { LocalStorageStorage } from \"./local-storage\";\nimport { MemoryStorage } from \"./memory-storage\";\n\n/**\n * Gives the database name of one application namespace. The sender and the deletion use one rule.\n * @param namespace Application namespace. An empty value keeps the name before namespaces.\n * @returns Name of the IndexedDB database.\n */\nexport function storageName(namespace: string): string {\n return namespace ? `${STORAGE_DB_NAME}:${namespace}` : STORAGE_DB_NAME;\n}\n\n/**\n * Builds the adapter that keeps nothing. The factory returns it for the \"none\" strategy. Each\n * method resolves. A sender that calls close() on shutdown must not crash.\n * @param onGap Receives each batch that the adapter does not keep. That batch is a loss.\n * @returns The adapter.\n */\nconst noop = (onGap?: GapReporter): StorageAdapter => ({\n name: STORAGE_NAME_NONE,\n save: (batch) => {\n onGap?.({ batches: 1, records: batch.records.length, reason: \"not_stored\" }, [batch]);\n return Promise.resolve();\n },\n take: () => Promise.resolve([]),\n remove: () => Promise.resolve(),\n bumpAttempts: () => Promise.resolve(),\n prune: () => Promise.resolve({ batches: 0, records: 0, reason: \"expired\" as const }),\n count: () => Promise.resolve(0),\n clear: () => Promise.resolve(),\n close: () => Promise.resolve(),\n});\n\n/**\n * Checks if IndexedDB is available in the current context.\n * @param diagnostics Diagnostics reporter.\n * @returns True if IDBFactory is available.\n */\nfunction hasIndexedDb(diagnostics: Diagnostics): boolean {\n const available = diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read indexedDB.\",\n () => {\n const factory = (globalThis as { indexedDB?: IDBFactory | null }).indexedDB;\n return factory !== undefined && factory !== null;\n },\n );\n\n return available === true;\n}\n\n/**\n * Checks if localStorage is available and accepts writes.\n * @param diagnostics Diagnostics reporter.\n * @returns True if localStorage probe write succeeds.\n */\nfunction hasLocalStorage(diagnostics: Diagnostics): boolean {\n const usable = diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not write a test key to localStorage.\",\n () => {\n localStorage.setItem(STORAGE_PROBE_KEY, \"1\");\n localStorage.removeItem(STORAGE_PROBE_KEY);\n return true;\n },\n );\n\n return usable === true;\n}\n\n/**\n * Creates the requested storage adapter. It falls back to the next adapter when\n * a dependency is unavailable.\n * @param strategy Configured persistence strategy.\n * @param dbName IndexedDB database name.\n * @param limits Storage retention and capacity thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Optional callback for telemetry gap reporting.\n * @returns Promise that resolves to the selected StorageAdapter instance.\n */\nexport async function createStorage(\n strategy: StorageStrategy,\n dbName: string,\n limits: StorageLimits,\n diagnostics: Diagnostics,\n onGap?: GapReporter,\n namespace = \"\",\n): Promise<StorageAdapter> {\n if (strategy === STORAGE_NAME_NONE) {\n return noop(onGap);\n }\n if (strategy === STORAGE_NAME_MEMORY) {\n return new MemoryStorage(limits, onGap);\n }\n\n if (strategy === STORAGE_NAME_INDEXEDDB || strategy === \"auto\") {\n if (hasIndexedDb(diagnostics)) {\n // Import IndexedDbStorage dynamically. This keeps the driver out of the main bundle. A\n // chunk that does not load falls back to the next adapter.\n const adapter = await diagnostics.guardAsync(\n \"storage.unavailable\",\n \"The library could not open IndexedDB.\",\n async () => {\n const { IndexedDbStorage } = await import(\"./indexeddb-storage\");\n const storage = new IndexedDbStorage(dbName, limits, diagnostics, onGap);\n // Open the database here, not on first use. Private mode, a corrupt profile and\n // some WebViews define indexedDB but reject open(). Only a rejection in this\n // block selects the next adapter.\n await storage.open();\n return storage;\n },\n );\n if (adapter) {\n return adapter;\n }\n }\n\n if (strategy === STORAGE_NAME_INDEXEDDB) {\n diagnostics.report(\n \"storage.degraded\",\n \"IndexedDB is not available. The library uses memory storage instead.\",\n );\n return new MemoryStorage(limits, onGap);\n }\n }\n\n if (hasLocalStorage(diagnostics)) {\n return new LocalStorageStorage(\n limits,\n diagnostics,\n onGap,\n namespace ? `ui-observability:namespaced:${encodeURIComponent(namespace)}:batch:` : undefined,\n );\n }\n\n diagnostics.report(\n \"storage.degraded\",\n \"No persistent storage is available. The library keeps undelivered records in memory only.\",\n );\n return new MemoryStorage(limits, onGap);\n}\n"],"mappings":";;;;AAYA,SAAgBW,EAAU,GAA0B;CAGlD,OAAO,MAAM,QAAQC,EAAM,OAAO,KAAKA,EAAM,QAAQ,KAAKJ,CAAc;AAC1E;AAGA,IAAaK,IAAb,MAA6B;CAYR;CACA;CAXnB,QAA8B,CAAC;CAG/B,QAA8B,CAAC;CAM/B,YACE,GACA,GACA;EADiB,AADA,KAAA,UAAAC,GACA,KAAA,UAAAC;CAChB;CAOH,IAAI,GAAkB;EAOpB,OANK,KAAK,QAAQC,CAAI,IAEX,KAAK,MAAM,SAAS,KAAK,WAClC,KAAK,MAAM,KAAKA,CAAI,IAFpB,KAAK,MAAM,KAAKA,CAAI,GAKf,KAAK,MAAM,SAAS,KAAK;CAClC;CAMA,SAAc;EACZ,OAAO,CAAC,GAAG,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,CAAC,MAAM,GAAG,KAAK,OAAO;CAC7D;AACF;AASA,SAAgBC,EACd,GACA,GACA,GACK;CACL,IAAMC,IAAO,IAAIL,EAAaC,GAASC,CAAO;CAE9C,KAAK,IAAMC,KAAQG,GACjB,IAAI,CAACD,EAAK,IAAIF,CAAI,GAChB;CAIJ,OAAOE,EAAK,OAAO;AACrB;;;AC/DA,SAAgBE,EACd,GACA,GACA,GACA,GACa;CAIb,OAHA,EAAO,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OA,SAASoC,EAAgB,GAAmC;CAW1D,OAVepC,EAAY,MACzB,uBACA,kEAEE,aAAa,QAAQrB,GAAmB,GAAG,GAC3C,aAAa,WAAWA,CAAiB,GAClC,GAIJ,MAAW;AACpB;AAYA,eAAsB0D,EACpB,GACA,GACA,GACA,GACA,GACA,IAAY,IACa;CACzB,IAAIC,MAAA,QACF,OAAOJ,EAAKjC,CAAK;CAEnB,IAAIqC,MAAA,UACF,OAAO,IAAIX,EAAclB,GAAQR,CAAK;CAGxC,IAAIqC,MAAA,eAAuCA,MAAa,QAAQ;EAC9D,IAAIH,EAAanC,CAAW,GAAG;GAG7B,IAAMuC,IAAU,MAAMvC,EAAY,WAChC,uBACA,yCACA,YAAY;IACV,IAAM,EAAE,wBAAqB,MAAM,OAAO,oCACpCwC,IAAU,IAAIC,EAAiBC,GAAQjC,GAAQT,GAAaC,CAAK;IAKvE,OADA,MAAMuC,EAAQ,KAAK,GACZA;GACT,CACF;GACA,IAAID,GACF,OAAOA;EAEX;EAEA,IAAID,MAAA,aAKF,OAJAtC,EAAY,OACV,oBACA,sEACF,GACO,IAAI2B,EAAclB,GAAQR,CAAK;CAE1C;CAeA,OAbImC,EAAgBpC,CAAW,IACtB,IAAIQ,EACTC,GACAT,GACAC,GACAgC,IAAY,+BAA+B,mBAAmBA,CAAS,EAAE,WAAW,KAAA,CACtF,KAGFjC,EAAY,OACV,oBACA,2FACF,GACO,IAAI2B,EAAclB,GAAQR,CAAK;AACxC"}
1
+ {"version":3,"file":"factory-BonqI3NL.js","names":["STORAGE_NAME_MEMORY","BATCH_STORAGE_KEY_PREFIX","STORAGE_NAME_LOCAL","STORAGE_NAME_NONE","STORAGE_DB_NAME","STORAGE_PROBE_KEY","isLogBatch","countRecords","isActionRecord","keysWithPrefix","batchKey","hasAction","batch","EvictionPick","howMany","isAudit","item","pickEvictable","pick","items","addDrop","batches","records","reason","reportEviction","gap","diagnostics","onGap","dropped","createdAtOf","start","prefix","at","key","LocalStorageStorage","limits","out","limit","id","count","attempts","cutoff","result","expired","alive","createdAt","excess","context","keys","entry","entries","raw","parsed","MemoryStorage","index","stored","found","evicted","storageName","namespace","noop","hasIndexedDb","hasLocalStorage","createStorage","strategy","adapter","storage","IndexedDbStorage","dbName"],"sources":["../src/storage/eviction.ts","../src/storage/gap.ts","../src/storage/local-storage.ts","../src/storage/memory-storage.ts","../src/storage/factory.ts"],"sourcesContent":["// src/storage/eviction.ts\n//\n// This module selects the stored batches to evict. An action is an audit fact. The batches without\n// an action go first. The walk stops early. A read of the full store at each save blocks the page.\n\nimport { isActionRecord, type LogBatch } from \"../models/batch\";\n\n/**\n * Tests if a batch holds an action. An eviction removes such a batch last.\n * @param batch Batch to test.\n * @returns True if one record of the batch is an action.\n */\nexport function hasAction(batch: LogBatch): boolean {\n // Another script on the origin can write to the database. A throw in a cursor handler stops\n // the eviction walk. The walk then never settles.\n return Array.isArray(batch.records) && batch.records.some(isActionRecord);\n}\n\n/** Collects the items to evict from a walk in age order, oldest first. */\nexport class EvictionPick<T> {\n /** Items without an audit fact. */\n private readonly plain: T[] = [];\n\n /** Oldest items with an audit fact. The pick uses them only when too few plain items exist. */\n private readonly audit: T[] = [];\n\n /**\n * @param howMany Number of items to evict.\n * @param isAudit Tests if an item holds an audit fact.\n */\n constructor(\n private readonly howMany: number,\n private readonly isAudit: (item: T) => boolean,\n ) {}\n\n /**\n * Adds the next item of the walk.\n * @param item Next oldest item.\n * @returns False when the pick has enough items without an audit fact. The walk then stops.\n */\n add(item: T): boolean {\n if (!this.isAudit(item)) {\n this.plain.push(item);\n } else if (this.audit.length < this.howMany) {\n this.audit.push(item);\n }\n\n return this.plain.length < this.howMany;\n }\n\n /**\n * Gives the items to evict. The items without an audit fact come first.\n * @returns The picked items.\n */\n picked(): T[] {\n return [...this.plain, ...this.audit].slice(0, this.howMany);\n }\n}\n\n/**\n * Picks the items to evict from a walk in age order. It stops the walk early.\n * @param items Items, oldest first. A generator reads each item only when the walk needs it.\n * @param howMany Number of items to evict.\n * @param isAudit Tests if an item holds an audit fact.\n * @returns The picked items. The items without an audit fact come first.\n */\nexport function pickEvictable<T>(\n items: Iterable<T>,\n howMany: number,\n isAudit: (item: T) => boolean,\n): T[] {\n const pick = new EvictionPick(howMany, isAudit);\n\n for (const item of items) {\n if (!pick.add(item)) {\n break;\n }\n }\n\n return pick.picked();\n}\n","// src/storage/gap.ts\n//\n// This module counts and reports the batches that a storage adapter drops. Each dropped batch is a\n// loss. The gap handler gives it to onDrop.\n\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult } from \"../models/storage\";\n\n/**\n * Adds the drop of one rule to the prune result.\n * @param result Prune result of all rules.\n * @param reason Rule that dropped the batches.\n * @param batches Number of dropped batches.\n * @param records Number of dropped records.\n * @returns The counts of this rule alone, for the gap report.\n */\nexport function addDrop(\n result: PruneResult,\n reason: PruneResult[\"reason\"],\n batches: number,\n records: number,\n): PruneResult {\n result.batches += batches;\n result.records += records;\n result.reason = reason;\n return { batches, records, reason };\n}\n\n/**\n * Reports dropped batches to diagnostics and to the gap handler. An empty drop reports nothing.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Gap handler of the adapter.\n * @param gap Counts and reason of the drop.\n * @param dropped The dropped batches that the adapter could read.\n */\nexport function reportEviction(\n diagnostics: Diagnostics,\n onGap: GapReporter | undefined,\n gap: PruneResult,\n dropped: readonly LogBatch[],\n): void {\n if (gap.batches === 0) {\n return;\n }\n\n diagnostics.report(\n \"storage.evicted\",\n `The library dropped ${String(gap.batches)} stored batches (${String(gap.records)} records).`,\n { ...gap },\n );\n onGap?.(gap, dropped);\n}\n","// src/storage/local-storage.ts\n//\n// This module stores batches in localStorage with time-ordered keys. The padding makes\n// keys().sort() a sort by creation time. Without padding, the sort uses hex order. take()\n// then does not return the oldest batch first.\n\nimport {\n BATCH_KEY_TIME_WIDTH,\n BATCH_STORAGE_KEY_PREFIX,\n QUOTA_EVICTION_DIVISOR,\n STORAGE_NAME_LOCAL,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { countRecords, isLogBatch, type LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { hasAction, pickEvictable } from \"./eviction\";\nimport { addDrop, reportEviction } from \"./gap\";\nimport { batchKey, keysWithPrefix } from \"./keys\";\n\n/** A stored entry. A corrupt entry has no batch. */\ninterface Entry {\n key: string;\n batch: LogBatch | null;\n}\n\n/**\n * Reads the creation time from a storage key. prune() runs after each save. A\n * read from the batch parses the full store for each save.\n * @param key Prefixed storage key.\n * @returns Creation time in epoch milliseconds, or null for a malformed key.\n */\nfunction createdAtOf(key: string, prefix: string): number | null {\n const start = prefix.length;\n const at = Number(key.slice(start, start + BATCH_KEY_TIME_WIDTH));\n\n return Number.isFinite(at) ? at : null;\n}\n\n/** This StorageAdapter keeps batches in localStorage. */\nexport class LocalStorageStorage implements StorageAdapter {\n /** This field holds the storage strategy name. */\n readonly name = STORAGE_NAME_LOCAL;\n\n /**\n * @param limits Storage capacity and retention thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Optional callback for dropped record reporting.\n */\n constructor(\n private readonly limits: StorageLimits,\n private readonly diagnostics: Diagnostics,\n private readonly onGap?: GapReporter,\n private readonly prefix = BATCH_STORAGE_KEY_PREFIX,\n ) {}\n\n /**\n * Writes a batch to localStorage. It removes the oldest entries on a quota error.\n * @param batch Batch to store.\n */\n async save(batch: LogBatch): Promise<void> {\n if (this.write(batch, \"localStorage refused a batch, evicting the oldest\")) {\n await this.prune();\n return;\n }\n\n this.evictForQuota();\n\n // The eviction makes room for this batch. Without a second write, save() resolves.\n // The library then loses the batch. No counter shows the loss.\n if (!this.write(batch, \"localStorage refused a batch even after evicting\")) {\n const gap: PruneResult = { batches: 1, records: batch.records.length, reason: \"quota\" };\n reportEviction(this.diagnostics, this.onGap, gap, [batch]);\n }\n }\n\n /**\n * Returns up to `limit` batches in FIFO order. It does not delete them.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to an array of valid batches.\n */\n take(limit: number): Promise<LogBatch[]> {\n const out: LogBatch[] = [];\n\n for (const key of this.keys().slice(0, limit)) {\n const batch = this.read(key);\n // The entry is corrupt. The library cannot recover it. Remove it without a gap count. It has\n // no readable record count.\n if (batch === null) {\n this.removeKey(key);\n continue;\n }\n out.push(batch);\n }\n\n return Promise.resolve(out);\n }\n\n /**\n * Returns up to `limit` batches of one context in FIFO order. It does not delete them.\n * It stops at the limit. The later entries then stay unparsed.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to the batches of this context.\n */\n takeContext(id: string, limit: number): Promise<LogBatch[]> {\n const out: LogBatch[] = [];\n\n for (const batch of this.batches()) {\n if (out.length >= limit) {\n break;\n }\n if (batch.routingContextId === id) {\n out.push(batch);\n }\n }\n\n return Promise.resolve(out);\n }\n\n /**\n * Counts the stored batches of one context. The context id is not in the key. Each entry is read.\n * @param id Delivery context id.\n * @returns Promise that resolves to the batch count of this context.\n */\n countContext(id: string): Promise<number> {\n let count = 0;\n\n for (const batch of this.batches()) {\n if (batch.routingContextId === id) {\n count++;\n }\n }\n\n return Promise.resolve(count);\n }\n\n /**\n * Reads the valid batches one at a time, oldest first. It removes a corrupt entry.\n * @yields Each valid batch.\n */\n private *batches(): Generator<LogBatch> {\n for (const key of this.keys()) {\n const batch = this.read(key);\n if (batch === null) {\n this.removeKey(key);\n continue;\n }\n yield batch;\n }\n }\n\n /**\n * Deletes the batch with the given ID from localStorage.\n * @param id Batch identifier.\n */\n remove(id: string): Promise<void> {\n const key = this.keyOf(id);\n if (key !== null) {\n this.removeKey(key);\n }\n return Promise.resolve();\n }\n\n /**\n * Sets the delivery attempt count of a stored batch. It does not change the key.\n * @param id Batch identifier.\n * @param attempts New absolute attempt count.\n */\n bumpAttempts(id: string, attempts: number): Promise<void> {\n const key = this.keyOf(id);\n if (key === null) {\n return Promise.resolve();\n }\n\n const batch = this.read(key);\n if (batch === null) {\n return Promise.resolve();\n }\n\n batch.attempts = attempts;\n this.diagnostics.guard(\n \"storage.degraded\",\n \"The library could not update the attempt count.\",\n () => {\n localStorage.setItem(key, JSON.stringify(batch));\n },\n );\n\n return Promise.resolve();\n }\n\n /**\n * Deletes expired batches. It then removes the oldest batches above the\n * capacity limit.\n * @returns Promise that resolves to prune summary metrics.\n */\n prune(): Promise<PruneResult> {\n const cutoff = Date.now() - this.limits.maxAgeMs;\n const result: PruneResult = { batches: 0, records: 0, reason: \"expired\" };\n const expired: string[] = [];\n const alive: string[] = [];\n\n for (const key of this.keys()) {\n const createdAt = createdAtOf(key, this.prefix);\n // A key with no readable time also has no position in the sort order.\n if (createdAt === null || createdAt < cutoff) {\n expired.push(key);\n continue;\n }\n alive.push(key);\n }\n\n // The record count is the one field that the key does not contain. Parse only the\n // deleted batches.\n this.drop(result, \"expired\", [...this.entries(expired)]);\n\n const excess = alive.length - this.limits.maxBatches;\n if (excess > 0) {\n this.drop(result, \"over_capacity\", this.evictable(alive, excess));\n }\n\n return Promise.resolve(result);\n }\n\n /**\n * Returns the number of stored batch keys. It does not deserialize the batches.\n * @returns Promise that resolves to batch count.\n */\n count(): Promise<number> {\n return Promise.resolve(this.keys().length);\n }\n\n /** This method deletes all batch keys from localStorage. */\n clear(): Promise<void> {\n this.evict(this.keys());\n return Promise.resolve();\n }\n\n /** This method does nothing. localStorage has no connection to close. */\n close(): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Writes a batch to localStorage.\n * @param batch Batch to store.\n * @param context Text that diagnostics reports when the write fails.\n * @returns True if the write succeeded.\n */\n private write(batch: LogBatch, context: string): boolean {\n const written = this.diagnostics.guard(\"storage.quota_exceeded\", context, () => {\n localStorage.setItem(batchKey(this.prefix, batch), JSON.stringify(batch));\n return true;\n });\n\n return written === true;\n }\n\n /** This method removes a quarter of the store to free quota. It counts the loss. */\n private evictForQuota(): void {\n const keys = this.keys();\n const result: PruneResult = { batches: 0, records: 0, reason: \"quota\" };\n const howMany = Math.ceil(keys.length / QUOTA_EVICTION_DIVISOR);\n\n this.drop(result, \"quota\", this.evictable(keys, howMany));\n }\n\n /**\n * Picks the entries to evict. Entries without an action go first. An action is an audit fact.\n * A corrupt entry has no action. It goes first.\n * @param keys Batch keys, oldest first.\n * @param howMany Number of entries to evict.\n * @returns The picked entries.\n */\n private evictable(keys: string[], howMany: number): Entry[] {\n return pickEvictable(\n this.entries(keys),\n howMany,\n (entry) => entry.batch !== null && hasAction(entry.batch),\n );\n }\n\n /**\n * Reads the entries one at a time. The eviction walk stops early. The later entries then stay\n * unparsed.\n * @param keys Batch keys.\n * @yields Each key with its batch.\n */\n private *entries(keys: string[]): Generator<Entry> {\n for (const key of keys) {\n yield { key, batch: this.read(key) };\n }\n }\n\n /**\n * Removes entries. It reports them with their own reason.\n * @param result Prune result of all rules.\n * @param reason Rule that removes the entries.\n * @param entries Entries to remove.\n */\n private drop(result: PruneResult, reason: PruneResult[\"reason\"], entries: Entry[]): void {\n if (entries.length === 0) {\n return;\n }\n\n const dropped: LogBatch[] = [];\n\n for (const { key, batch } of entries) {\n this.removeKey(key);\n if (batch) {\n dropped.push(batch);\n }\n }\n\n // A corrupt entry counts as a batch with no records.\n const gap = addDrop(result, reason, entries.length, countRecords(dropped));\n reportEviction(this.diagnostics, this.onGap, gap, dropped);\n }\n\n /**\n * Reads and validates the stored batch at a key.\n * @param key Storage key to read.\n * @returns Validated LogBatch or null if missing or malformed.\n */\n private read(key: string): LogBatch | null {\n const raw = this.diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read a stored batch.\",\n () => localStorage.getItem(key),\n );\n if (!raw) {\n return null;\n }\n\n const parsed = this.diagnostics.guard(\n \"storage.degraded\",\n \"A stored batch is corrupt. The library removed it.\",\n () => JSON.parse(raw) as unknown,\n );\n // The guard above already reported a parse failure. A second report counts one corrupt\n // entry twice.\n if (parsed === undefined) {\n return null;\n }\n\n if (!isLogBatch(parsed)) {\n this.diagnostics.report(\n \"storage.degraded\",\n \"A stored entry is not a batch. The library dropped it.\",\n );\n return null;\n }\n\n return parsed;\n }\n\n /**\n * Finds the storage key that ends with the batch ID.\n * @param id Batch identifier.\n * @returns Matching storage key string or null.\n */\n private keyOf(id: string): string | null {\n return this.keys().find((key) => key.endsWith(`.${id}`)) ?? null;\n }\n\n /**\n * Deletes a list of storage keys.\n * @param keys Keys to delete.\n */\n private evict(keys: string[]): void {\n for (const key of keys) {\n this.removeKey(key);\n }\n }\n\n /**\n * Deletes one storage key inside a guard.\n * @param key Storage key to remove.\n */\n private removeKey(key: string): void {\n this.diagnostics.guard(\n \"storage.degraded\",\n \"The library could not remove a stored batch.\",\n () => {\n localStorage.removeItem(key);\n },\n );\n }\n\n /**\n * Returns all batch storage keys in sorted order.\n * @returns Sorted array of storage keys.\n */\n private keys(): string[] {\n return keysWithPrefix(this.prefix, this.diagnostics);\n }\n}\n","// src/storage/memory-storage.ts\n//\n// This module keeps batches in volatile memory during offline periods. A reload loses all of\n// them. This adapter is the last fallback.\n\nimport { STORAGE_NAME_MEMORY } from \"../constants\";\nimport { countRecords, type LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { hasAction, pickEvictable } from \"./eviction\";\nimport { addDrop } from \"./gap\";\n\n/** This StorageAdapter keeps batches in volatile memory. */\nexport class MemoryStorage implements StorageAdapter {\n /** This field holds the storage strategy name. */\n readonly name = STORAGE_NAME_MEMORY;\n\n /** This array holds the batches in FIFO order. */\n private batches: LogBatch[] = [];\n\n /**\n * @param limits Storage capacity and retention thresholds.\n * @param onGap Optional callback for dropped record reporting.\n */\n constructor(\n private readonly limits: StorageLimits,\n private readonly onGap?: GapReporter,\n ) {}\n\n /**\n * Appends a batch and applies retention pruning.\n * @param batch Batch to store.\n */\n async save(batch: LogBatch): Promise<void> {\n // A batch with a known id replaces the old copy in place, as IndexedDB put() does.\n const index = this.batches.findIndex((stored) => stored.id === batch.id);\n if (index >= 0) {\n this.batches[index] = batch;\n } else {\n this.batches.push(batch);\n }\n await this.prune();\n }\n\n /**\n * Returns up to `limit` batches in FIFO order. It does not delete them.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to an array of batches.\n */\n take(limit: number): Promise<LogBatch[]> {\n return Promise.resolve(this.batches.slice(0, limit));\n }\n\n /**\n * Returns up to `limit` batches of one context in FIFO order. It does not delete them.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to the batches of this context.\n */\n takeContext(id: string, limit: number): Promise<LogBatch[]> {\n return Promise.resolve(\n this.batches.filter((batch) => batch.routingContextId === id).slice(0, limit),\n );\n }\n\n /**\n * Counts the stored batches of one context.\n * @param id Delivery context id.\n * @returns Promise that resolves to the batch count of this context.\n */\n countContext(id: string): Promise<number> {\n return Promise.resolve(this.batches.filter((batch) => batch.routingContextId === id).length);\n }\n\n /**\n * Deletes the batch with the given ID.\n * @param id Batch identifier.\n */\n remove(id: string): Promise<void> {\n this.batches = this.batches.filter((batch) => batch.id !== id);\n return Promise.resolve();\n }\n\n /**\n * Sets the delivery attempt count of a stored batch.\n * @param id Batch identifier.\n * @param attempts New absolute attempt count.\n */\n bumpAttempts(id: string, attempts: number): Promise<void> {\n const found = this.batches.find((batch) => batch.id === id);\n if (found) {\n found.attempts = attempts;\n }\n return Promise.resolve();\n }\n\n /**\n * Removes expired batches. It then removes the oldest batches above the\n * capacity limit.\n * @returns Promise that resolves to prune summary metrics.\n */\n prune(): Promise<PruneResult> {\n const cutoff = Date.now() - this.limits.maxAgeMs;\n const result: PruneResult = { batches: 0, records: 0, reason: \"expired\" };\n\n const expired = this.batches.filter((batch) => batch.createdAt < cutoff);\n this.batches = this.batches.filter((batch) => batch.createdAt >= cutoff);\n this.report(result, \"expired\", expired);\n\n const excess = this.batches.length - this.limits.maxBatches;\n if (excess > 0) {\n // An action is an audit fact. Evict each batch without an action first.\n const evicted = pickEvictable(this.batches, excess, hasAction);\n this.batches = this.batches.filter((batch) => !evicted.includes(batch));\n this.report(result, \"over_capacity\", evicted);\n }\n\n return Promise.resolve(result);\n }\n\n /**\n * Adds dropped batches to the prune result. It reports them with their own reason.\n * @param result Prune result of all rules.\n * @param reason Rule that dropped the batches.\n * @param dropped The dropped batches.\n */\n private report(result: PruneResult, reason: PruneResult[\"reason\"], dropped: LogBatch[]): void {\n if (dropped.length === 0) {\n return;\n }\n\n const gap = addDrop(result, reason, dropped.length, countRecords(dropped));\n this.onGap?.(gap, dropped);\n }\n\n /**\n * Returns the number of stored batches.\n * @returns Promise that resolves to batch count.\n */\n count(): Promise<number> {\n return Promise.resolve(this.batches.length);\n }\n\n /** This method deletes all stored batches. */\n clear(): Promise<void> {\n this.batches = [];\n return Promise.resolve();\n }\n\n /** This method deletes all stored batches when the storage closes. */\n close(): Promise<void> {\n this.batches = [];\n return Promise.resolve();\n }\n}\n","// src/storage/factory.ts\n//\n// This module selects a storage adapter. It falls back from IndexedDB to localStorage to memory.\n// It falls back and does not throw. IndexedDB is unavailable in private mode and sandboxed\n// frames.\n\nimport {\n STORAGE_DB_NAME,\n STORAGE_NAME_INDEXEDDB,\n STORAGE_NAME_MEMORY,\n STORAGE_NAME_NONE,\n STORAGE_PROBE_KEY,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { StorageStrategy } from \"../models/config\";\nimport type { GapReporter, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { LocalStorageStorage } from \"./local-storage\";\nimport { MemoryStorage } from \"./memory-storage\";\n\n/**\n * Gives the database name of one application namespace. The sender and the deletion use one rule.\n * @param namespace Application namespace. An empty value keeps the name before namespaces.\n * @returns Name of the IndexedDB database.\n */\nexport function storageName(namespace: string): string {\n return namespace ? `${STORAGE_DB_NAME}:${namespace}` : STORAGE_DB_NAME;\n}\n\n/**\n * Builds the adapter that keeps nothing. The factory returns it for the \"none\" strategy. Each\n * method resolves. A sender that calls close() on shutdown must not crash.\n * @param onGap Receives each batch that the adapter does not keep. That batch is a loss.\n * @returns The adapter.\n */\nconst noop = (onGap?: GapReporter): StorageAdapter => ({\n name: STORAGE_NAME_NONE,\n save: (batch) => {\n onGap?.({ batches: 1, records: batch.records.length, reason: \"not_stored\" }, [batch]);\n return Promise.resolve();\n },\n take: () => Promise.resolve([]),\n remove: () => Promise.resolve(),\n bumpAttempts: () => Promise.resolve(),\n prune: () => Promise.resolve({ batches: 0, records: 0, reason: \"expired\" as const }),\n count: () => Promise.resolve(0),\n clear: () => Promise.resolve(),\n close: () => Promise.resolve(),\n});\n\n/**\n * Checks if IndexedDB is available in the current context.\n * @param diagnostics Diagnostics reporter.\n * @returns True if IDBFactory is available.\n */\nfunction hasIndexedDb(diagnostics: Diagnostics): boolean {\n const available = diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read indexedDB.\",\n () => {\n const factory = (globalThis as { indexedDB?: IDBFactory | null }).indexedDB;\n return factory !== undefined && factory !== null;\n },\n );\n\n return available === true;\n}\n\n/**\n * Checks if localStorage is available and accepts writes.\n * @param diagnostics Diagnostics reporter.\n * @returns True if localStorage probe write succeeds.\n */\nfunction hasLocalStorage(diagnostics: Diagnostics): boolean {\n const usable = diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not write a test key to localStorage.\",\n () => {\n localStorage.setItem(STORAGE_PROBE_KEY, \"1\");\n localStorage.removeItem(STORAGE_PROBE_KEY);\n return true;\n },\n );\n\n return usable === true;\n}\n\n/**\n * Creates the requested storage adapter. It falls back to the next adapter when\n * a dependency is unavailable.\n * @param strategy Configured persistence strategy.\n * @param dbName IndexedDB database name.\n * @param limits Storage retention and capacity thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Optional callback for telemetry gap reporting.\n * @returns Promise that resolves to the selected StorageAdapter instance.\n */\nexport async function createStorage(\n strategy: StorageStrategy,\n dbName: string,\n limits: StorageLimits,\n diagnostics: Diagnostics,\n onGap?: GapReporter,\n namespace = \"\",\n): Promise<StorageAdapter> {\n if (strategy === STORAGE_NAME_NONE) {\n return noop(onGap);\n }\n if (strategy === STORAGE_NAME_MEMORY) {\n return new MemoryStorage(limits, onGap);\n }\n\n if (strategy === STORAGE_NAME_INDEXEDDB || strategy === \"auto\") {\n if (hasIndexedDb(diagnostics)) {\n // Import IndexedDbStorage dynamically. This keeps the driver out of the main bundle. A\n // chunk that does not load falls back to the next adapter.\n const adapter = await diagnostics.guardAsync(\n \"storage.unavailable\",\n \"The library could not open IndexedDB.\",\n async () => {\n const { IndexedDbStorage } = await import(\"./indexeddb-storage\");\n const storage = new IndexedDbStorage(dbName, limits, diagnostics, onGap);\n // Open the database here, not on first use. Private mode, a corrupt profile and\n // some WebViews define indexedDB but reject open(). Only a rejection in this\n // block selects the next adapter.\n await storage.open();\n return storage;\n },\n );\n if (adapter) {\n return adapter;\n }\n }\n\n if (strategy === STORAGE_NAME_INDEXEDDB) {\n diagnostics.report(\n \"storage.degraded\",\n \"IndexedDB is not available. The library uses memory storage instead.\",\n );\n return new MemoryStorage(limits, onGap);\n }\n }\n\n if (hasLocalStorage(diagnostics)) {\n return new LocalStorageStorage(\n limits,\n diagnostics,\n onGap,\n namespace ? `ui-observability:namespaced:${encodeURIComponent(namespace)}:batch:` : undefined,\n );\n }\n\n diagnostics.report(\n \"storage.degraded\",\n \"No persistent storage is available. The library keeps undelivered records in memory only.\",\n );\n return new MemoryStorage(limits, onGap);\n}\n"],"mappings":";;;;AAYA,SAAgBW,EAAU,GAA0B;CAGlD,OAAO,MAAM,QAAQC,EAAM,OAAO,KAAKA,EAAM,QAAQ,KAAKJ,CAAc;AAC1E;AAGA,IAAaK,IAAb,MAA6B;CAYR;CACA;CAXnB,QAA8B,CAAC;CAG/B,QAA8B,CAAC;CAM/B,YACE,GACA,GACA;EADiB,AADA,KAAA,UAAAC,GACA,KAAA,UAAAC;CAChB;CAOH,IAAI,GAAkB;EAOpB,OANK,KAAK,QAAQC,CAAI,IAEX,KAAK,MAAM,SAAS,KAAK,WAClC,KAAK,MAAM,KAAKA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AmBA,CAAS,EAAE,WAAW,KAAA,CACtF,KAGFjC,EAAY,OACV,oBACA,2FACF,GACO,IAAI2B,EAAclB,GAAQR,CAAK;AACxC"}
@@ -1,2 +1,2 @@
1
- const e=require("./constants-CL0ZdI2f.cjs"),t=require("./batch-BHXypM1j.cjs"),n=require("./keys-BHhw_0Wh.cjs");function r(e){return Array.isArray(e.records)&&e.records.some(t.r)}var i=class{howMany;isAudit;plain=[];audit=[];constructor(e,t){this.howMany=e,this.isAudit=t}add(e){return this.isAudit(e)?this.audit.length<this.howMany&&this.audit.push(e):this.plain.push(e),this.plain.length<this.howMany}picked(){return[...this.plain,...this.audit].slice(0,this.howMany)}};function a(e,t,n){let r=new i(t,n);for(let t of e)if(!r.add(t))break;return r.picked()}function o(e,t,n,r){return e.batches+=n,e.records+=r,e.reason=t,{batches:n,records:r,reason:t}}function s(e,t,n,r){n.batches!==0&&(e.report(`storage.evicted`,`The library dropped ${String(n.batches)} stored batches (${String(n.records)} records).`,{...n}),t?.(n,r))}function c(e,t){let n=t.length,r=Number(e.slice(n,n+14));return Number.isFinite(r)?r:null}var l=class{limits;diagnostics;onGap;prefix;name=e.En;constructor(t,n,r,i=e.E){this.limits=t,this.diagnostics=n,this.onGap=r,this.prefix=i}async save(e){if(this.write(e,`localStorage refused a batch, evicting the oldest`))await this.prune();else if(this.evictForQuota(),!this.write(e,`localStorage refused a batch even after evicting`)){let t={batches:1,records:e.records.length,reason:`quota`};s(this.diagnostics,this.onGap,t,[e])}}take(e){let t=[];for(let n of this.keys().slice(0,e)){let e=this.read(n);e===null?this.removeKey(n):t.push(e)}return Promise.resolve(t)}takeContext(e,t){let n=[];for(let r of this.batches()){if(n.length>=t)break;r.routingContextId===e&&n.push(r)}return Promise.resolve(n)}countContext(e){let t=0;for(let n of this.batches())n.routingContextId===e&&t++;return Promise.resolve(t)}*batches(){for(let e of this.keys()){let t=this.read(e);t===null?this.removeKey(e):yield t}}remove(e){let t=this.keyOf(e);return t!==null&&this.removeKey(t),Promise.resolve()}bumpAttempts(e,t){let n=this.keyOf(e);if(n===null)return Promise.resolve();let r=this.read(n);return r===null||(r.attempts=t,this.diagnostics.guard(`storage.degraded`,`The library could not update the attempt count.`,()=>{localStorage.setItem(n,JSON.stringify(r))})),Promise.resolve()}prune(){let e=Date.now()-this.limits.maxAgeMs,t={batches:0,records:0,reason:`expired`},n=[],r=[];for(let t of this.keys()){let i=c(t,this.prefix);i===null||i<e?n.push(t):r.push(t)}this.drop(t,`expired`,[...this.entries(n)]);let i=r.length-this.limits.maxBatches;return i>0&&this.drop(t,`over_capacity`,this.evictable(r,i)),Promise.resolve(t)}count(){return Promise.resolve(this.keys().length)}clear(){return this.evict(this.keys()),Promise.resolve()}close(){return Promise.resolve()}write(e,t){return this.diagnostics.guard(`storage.quota_exceeded`,t,()=>(localStorage.setItem(n.t(this.prefix,e),JSON.stringify(e)),!0))===!0}evictForQuota(){let e=this.keys(),t={batches:0,records:0,reason:`quota`},n=Math.ceil(e.length/4);this.drop(t,`quota`,this.evictable(e,n))}evictable(e,t){return a(this.entries(e),t,e=>e.batch!==null&&r(e.batch))}*entries(e){for(let t of e)yield{key:t,batch:this.read(t)}}drop(e,n,r){if(r.length===0)return;let i=[];for(let{key:e,batch:t}of r)this.removeKey(e),t&&i.push(t);let a=o(e,n,r.length,t.n(i));s(this.diagnostics,this.onGap,a,i)}read(e){let n=this.diagnostics.guard(`storage.unavailable`,`The library could not read a stored batch.`,()=>localStorage.getItem(e));if(!n)return null;let r=this.diagnostics.guard(`storage.degraded`,`A stored batch is corrupt. The library removed it.`,()=>JSON.parse(n));return r===void 0?null:t.i(r)?r:(this.diagnostics.report(`storage.degraded`,`A stored entry is not a batch. The library dropped it.`),null)}keyOf(e){return this.keys().find(t=>t.endsWith(`.${e}`))??null}evict(e){for(let t of e)this.removeKey(t)}removeKey(e){this.diagnostics.guard(`storage.degraded`,`The library could not remove a stored batch.`,()=>{localStorage.removeItem(e)})}keys(){return n.n(this.prefix,this.diagnostics)}},u=class{limits;onGap;name=e.Dn;batches=[];constructor(e,t){this.limits=e,this.onGap=t}async save(e){let t=this.batches.findIndex(t=>t.id===e.id);t>=0?this.batches[t]=e:this.batches.push(e),await this.prune()}take(e){return Promise.resolve(this.batches.slice(0,e))}takeContext(e,t){return Promise.resolve(this.batches.filter(t=>t.routingContextId===e).slice(0,t))}countContext(e){return Promise.resolve(this.batches.filter(t=>t.routingContextId===e).length)}remove(e){return this.batches=this.batches.filter(t=>t.id!==e),Promise.resolve()}bumpAttempts(e,t){let n=this.batches.find(t=>t.id===e);return n&&(n.attempts=t),Promise.resolve()}prune(){let e=Date.now()-this.limits.maxAgeMs,t={batches:0,records:0,reason:`expired`},n=this.batches.filter(t=>t.createdAt<e);this.batches=this.batches.filter(t=>t.createdAt>=e),this.report(t,`expired`,n);let i=this.batches.length-this.limits.maxBatches;if(i>0){let e=a(this.batches,i,r);this.batches=this.batches.filter(t=>!e.includes(t)),this.report(t,`over_capacity`,e)}return Promise.resolve(t)}report(e,n,r){if(r.length===0)return;let i=o(e,n,r.length,t.n(r));this.onGap?.(i,r)}count(){return Promise.resolve(this.batches.length)}clear(){return this.batches=[],Promise.resolve()}close(){return this.batches=[],Promise.resolve()}};function d(t){return t?`${e.Sn}:${t}`:e.Sn}var f=t=>({name:e.On,save:e=>(t?.({batches:1,records:e.records.length,reason:`not_stored`},[e]),Promise.resolve()),take:()=>Promise.resolve([]),remove:()=>Promise.resolve(),bumpAttempts:()=>Promise.resolve(),prune:()=>Promise.resolve({batches:0,records:0,reason:`expired`}),count:()=>Promise.resolve(0),clear:()=>Promise.resolve(),close:()=>Promise.resolve()});function p(e){return e.guard(`storage.unavailable`,`The library could not read indexedDB.`,()=>globalThis.indexedDB!=null)===!0}function m(t){return t.guard(`storage.unavailable`,`The library could not write a test key to localStorage.`,()=>(localStorage.setItem(e.kn,`1`),localStorage.removeItem(e.kn),!0))===!0}async function h(e,t,n,r,i,a=``){if(e===`none`)return f(i);if(e===`memory`)return new u(n,i);if(e===`indexeddb`||e===`auto`){if(p(r)){let e=await r.guardAsync(`storage.unavailable`,`The library could not open IndexedDB.`,async()=>{let{IndexedDbStorage:e}=await Promise.resolve().then(()=>require("./indexeddb-storage-CaXGJqDD.cjs")),a=new e(t,n,r,i);return await a.open(),a});if(e)return e}if(e===`indexeddb`)return r.report(`storage.degraded`,`IndexedDB is not available. The library uses memory storage instead.`),new u(n,i)}return m(r)?new l(n,r,i,a?`ui-observability:namespaced:${encodeURIComponent(a)}:batch:`:void 0):(r.report(`storage.degraded`,`No persistent storage is available. The library keeps undelivered records in memory only.`),new u(n,i))}exports.createStorage=h,exports.i=r,exports.n=s,exports.r=i,exports.storageName=d,exports.t=o;
2
- //# sourceMappingURL=factory-BkjNzPYL.cjs.map
1
+ const e=require("./constants-DqKJH_MP.cjs"),t=require("./batch-C8OcWR2L.cjs"),n=require("./keys-BHhw_0Wh.cjs");function r(e){return Array.isArray(e.records)&&e.records.some(t.r)}var i=class{howMany;isAudit;plain=[];audit=[];constructor(e,t){this.howMany=e,this.isAudit=t}add(e){return this.isAudit(e)?this.audit.length<this.howMany&&this.audit.push(e):this.plain.push(e),this.plain.length<this.howMany}picked(){return[...this.plain,...this.audit].slice(0,this.howMany)}};function a(e,t,n){let r=new i(t,n);for(let t of e)if(!r.add(t))break;return r.picked()}function o(e,t,n,r){return e.batches+=n,e.records+=r,e.reason=t,{batches:n,records:r,reason:t}}function s(e,t,n,r){n.batches!==0&&(e.report(`storage.evicted`,`The library dropped ${String(n.batches)} stored batches (${String(n.records)} records).`,{...n}),t?.(n,r))}function c(e,t){let n=t.length,r=Number(e.slice(n,n+14));return Number.isFinite(r)?r:null}var l=class{limits;diagnostics;onGap;prefix;name=e.En;constructor(t,n,r,i=e.E){this.limits=t,this.diagnostics=n,this.onGap=r,this.prefix=i}async save(e){if(this.write(e,`localStorage refused a batch, evicting the oldest`))await this.prune();else if(this.evictForQuota(),!this.write(e,`localStorage refused a batch even after evicting`)){let t={batches:1,records:e.records.length,reason:`quota`};s(this.diagnostics,this.onGap,t,[e])}}take(e){let t=[];for(let n of this.keys().slice(0,e)){let e=this.read(n);e===null?this.removeKey(n):t.push(e)}return Promise.resolve(t)}takeContext(e,t){let n=[];for(let r of this.batches()){if(n.length>=t)break;r.routingContextId===e&&n.push(r)}return Promise.resolve(n)}countContext(e){let t=0;for(let n of this.batches())n.routingContextId===e&&t++;return Promise.resolve(t)}*batches(){for(let e of this.keys()){let t=this.read(e);t===null?this.removeKey(e):yield t}}remove(e){let t=this.keyOf(e);return t!==null&&this.removeKey(t),Promise.resolve()}bumpAttempts(e,t){let n=this.keyOf(e);if(n===null)return Promise.resolve();let r=this.read(n);return r===null||(r.attempts=t,this.diagnostics.guard(`storage.degraded`,`The library could not update the attempt count.`,()=>{localStorage.setItem(n,JSON.stringify(r))})),Promise.resolve()}prune(){let e=Date.now()-this.limits.maxAgeMs,t={batches:0,records:0,reason:`expired`},n=[],r=[];for(let t of this.keys()){let i=c(t,this.prefix);i===null||i<e?n.push(t):r.push(t)}this.drop(t,`expired`,[...this.entries(n)]);let i=r.length-this.limits.maxBatches;return i>0&&this.drop(t,`over_capacity`,this.evictable(r,i)),Promise.resolve(t)}count(){return Promise.resolve(this.keys().length)}clear(){return this.evict(this.keys()),Promise.resolve()}close(){return Promise.resolve()}write(e,t){return this.diagnostics.guard(`storage.quota_exceeded`,t,()=>(localStorage.setItem(n.t(this.prefix,e),JSON.stringify(e)),!0))===!0}evictForQuota(){let e=this.keys(),t={batches:0,records:0,reason:`quota`},n=Math.ceil(e.length/4);this.drop(t,`quota`,this.evictable(e,n))}evictable(e,t){return a(this.entries(e),t,e=>e.batch!==null&&r(e.batch))}*entries(e){for(let t of e)yield{key:t,batch:this.read(t)}}drop(e,n,r){if(r.length===0)return;let i=[];for(let{key:e,batch:t}of r)this.removeKey(e),t&&i.push(t);let a=o(e,n,r.length,t.n(i));s(this.diagnostics,this.onGap,a,i)}read(e){let n=this.diagnostics.guard(`storage.unavailable`,`The library could not read a stored batch.`,()=>localStorage.getItem(e));if(!n)return null;let r=this.diagnostics.guard(`storage.degraded`,`A stored batch is corrupt. The library removed it.`,()=>JSON.parse(n));return r===void 0?null:t.i(r)?r:(this.diagnostics.report(`storage.degraded`,`A stored entry is not a batch. The library dropped it.`),null)}keyOf(e){return this.keys().find(t=>t.endsWith(`.${e}`))??null}evict(e){for(let t of e)this.removeKey(t)}removeKey(e){this.diagnostics.guard(`storage.degraded`,`The library could not remove a stored batch.`,()=>{localStorage.removeItem(e)})}keys(){return n.n(this.prefix,this.diagnostics)}},u=class{limits;onGap;name=e.Dn;batches=[];constructor(e,t){this.limits=e,this.onGap=t}async save(e){let t=this.batches.findIndex(t=>t.id===e.id);t>=0?this.batches[t]=e:this.batches.push(e),await this.prune()}take(e){return Promise.resolve(this.batches.slice(0,e))}takeContext(e,t){return Promise.resolve(this.batches.filter(t=>t.routingContextId===e).slice(0,t))}countContext(e){return Promise.resolve(this.batches.filter(t=>t.routingContextId===e).length)}remove(e){return this.batches=this.batches.filter(t=>t.id!==e),Promise.resolve()}bumpAttempts(e,t){let n=this.batches.find(t=>t.id===e);return n&&(n.attempts=t),Promise.resolve()}prune(){let e=Date.now()-this.limits.maxAgeMs,t={batches:0,records:0,reason:`expired`},n=this.batches.filter(t=>t.createdAt<e);this.batches=this.batches.filter(t=>t.createdAt>=e),this.report(t,`expired`,n);let i=this.batches.length-this.limits.maxBatches;if(i>0){let e=a(this.batches,i,r);this.batches=this.batches.filter(t=>!e.includes(t)),this.report(t,`over_capacity`,e)}return Promise.resolve(t)}report(e,n,r){if(r.length===0)return;let i=o(e,n,r.length,t.n(r));this.onGap?.(i,r)}count(){return Promise.resolve(this.batches.length)}clear(){return this.batches=[],Promise.resolve()}close(){return this.batches=[],Promise.resolve()}};function d(t){return t?`${e.Sn}:${t}`:e.Sn}var f=t=>({name:e.On,save:e=>(t?.({batches:1,records:e.records.length,reason:`not_stored`},[e]),Promise.resolve()),take:()=>Promise.resolve([]),remove:()=>Promise.resolve(),bumpAttempts:()=>Promise.resolve(),prune:()=>Promise.resolve({batches:0,records:0,reason:`expired`}),count:()=>Promise.resolve(0),clear:()=>Promise.resolve(),close:()=>Promise.resolve()});function p(e){return e.guard(`storage.unavailable`,`The library could not read indexedDB.`,()=>globalThis.indexedDB!=null)===!0}function m(t){return t.guard(`storage.unavailable`,`The library could not write a test key to localStorage.`,()=>(localStorage.setItem(e.kn,`1`),localStorage.removeItem(e.kn),!0))===!0}async function h(e,t,n,r,i,a=``){if(e===`none`)return f(i);if(e===`memory`)return new u(n,i);if(e===`indexeddb`||e===`auto`){if(p(r)){let e=await r.guardAsync(`storage.unavailable`,`The library could not open IndexedDB.`,async()=>{let{IndexedDbStorage:e}=await Promise.resolve().then(()=>require("./indexeddb-storage-CIoW21Xd.cjs")),a=new e(t,n,r,i);return await a.open(),a});if(e)return e}if(e===`indexeddb`)return r.report(`storage.degraded`,`IndexedDB is not available. The library uses memory storage instead.`),new u(n,i)}return m(r)?new l(n,r,i,a?`ui-observability:namespaced:${encodeURIComponent(a)}:batch:`:void 0):(r.report(`storage.degraded`,`No persistent storage is available. The library keeps undelivered records in memory only.`),new u(n,i))}exports.createStorage=h,exports.i=r,exports.n=s,exports.r=i,exports.storageName=d,exports.t=o;
2
+ //# sourceMappingURL=factory-CJXVYp0R.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory-BkjNzPYL.cjs","names":["isActionRecord","STORAGE_NAME_LOCAL","BATCH_STORAGE_KEY_PREFIX","batchKey","countRecords","isLogBatch","keysWithPrefix","STORAGE_NAME_MEMORY","countRecords","STORAGE_DB_NAME","STORAGE_NAME_NONE","STORAGE_PROBE_KEY","require_constants","require_batch","require_keys","hasAction","batch","EvictionPick","howMany","isAudit","item","pickEvictable","pick","items","addDrop","batches","records","reason","reportEviction","gap","diagnostics","onGap","dropped","createdAtOf","start","prefix","at","key","LocalStorageStorage","limits","out","limit","id","count","attempts","cutoff","result","expired","alive","createdAt","excess","context","keys","entry","entries","raw","parsed","MemoryStorage","index","stored","found","evicted","storageName","namespace","noop","hasIndexedDb","hasLocalStorage","createStorage","strategy","adapter","storage","IndexedDbStorage","dbName"],"sources":["../src/storage/eviction.ts","../src/storage/gap.ts","../src/storage/local-storage.ts","../src/storage/memory-storage.ts","../src/storage/factory.ts"],"sourcesContent":["// src/storage/eviction.ts\n//\n// This module selects the stored batches to evict. An action is an audit fact. The batches without\n// an action go first. The walk stops early. A read of the full store at each save blocks the page.\n\nimport { isActionRecord, type LogBatch } from \"../models/batch\";\n\n/**\n * Tests if a batch holds an action. An eviction removes such a batch last.\n * @param batch Batch to test.\n * @returns True if one record of the batch is an action.\n */\nexport function hasAction(batch: LogBatch): boolean {\n // Another script on the origin can write to the database. A throw in a cursor handler stops\n // the eviction walk. The walk then never settles.\n return Array.isArray(batch.records) && batch.records.some(isActionRecord);\n}\n\n/** Collects the items to evict from a walk in age order, oldest first. */\nexport class EvictionPick<T> {\n /** Items without an audit fact. */\n private readonly plain: T[] = [];\n\n /** Oldest items with an audit fact. The pick uses them only when too few plain items exist. */\n private readonly audit: T[] = [];\n\n /**\n * @param howMany Number of items to evict.\n * @param isAudit Tests if an item holds an audit fact.\n */\n constructor(\n private readonly howMany: number,\n private readonly isAudit: (item: T) => boolean,\n ) {}\n\n /**\n * Adds the next item of the walk.\n * @param item Next oldest item.\n * @returns False when the pick has enough items without an audit fact. The walk then stops.\n */\n add(item: T): boolean {\n if (!this.isAudit(item)) {\n this.plain.push(item);\n } else if (this.audit.length < this.howMany) {\n this.audit.push(item);\n }\n\n return this.plain.length < this.howMany;\n }\n\n /**\n * Gives the items to evict. The items without an audit fact come first.\n * @returns The picked items.\n */\n picked(): T[] {\n return [...this.plain, ...this.audit].slice(0, this.howMany);\n }\n}\n\n/**\n * Picks the items to evict from a walk in age order. It stops the walk early.\n * @param items Items, oldest first. A generator reads each item only when the walk needs it.\n * @param howMany Number of items to evict.\n * @param isAudit Tests if an item holds an audit fact.\n * @returns The picked items. The items without an audit fact come first.\n */\nexport function pickEvictable<T>(\n items: Iterable<T>,\n howMany: number,\n isAudit: (item: T) => boolean,\n): T[] {\n const pick = new EvictionPick(howMany, isAudit);\n\n for (const item of items) {\n if (!pick.add(item)) {\n break;\n }\n }\n\n return pick.picked();\n}\n","// src/storage/gap.ts\n//\n// This module counts and reports the batches that a storage adapter drops. Each dropped batch is a\n// loss. The gap handler gives it to onDrop.\n\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult } from \"../models/storage\";\n\n/**\n * Adds the drop of one rule to the prune result.\n * @param result Prune result of all rules.\n * @param reason Rule that dropped the batches.\n * @param batches Number of dropped batches.\n * @param records Number of dropped records.\n * @returns The counts of this rule alone, for the gap report.\n */\nexport function addDrop(\n result: PruneResult,\n reason: PruneResult[\"reason\"],\n batches: number,\n records: number,\n): PruneResult {\n result.batches += batches;\n result.records += records;\n result.reason = reason;\n return { batches, records, reason };\n}\n\n/**\n * Reports dropped batches to diagnostics and to the gap handler. An empty drop reports nothing.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Gap handler of the adapter.\n * @param gap Counts and reason of the drop.\n * @param dropped The dropped batches that the adapter could read.\n */\nexport function reportEviction(\n diagnostics: Diagnostics,\n onGap: GapReporter | undefined,\n gap: PruneResult,\n dropped: readonly LogBatch[],\n): void {\n if (gap.batches === 0) {\n return;\n }\n\n diagnostics.report(\n \"storage.evicted\",\n `The library dropped ${String(gap.batches)} stored batches (${String(gap.records)} records).`,\n { ...gap },\n );\n onGap?.(gap, dropped);\n}\n","// src/storage/local-storage.ts\n//\n// This module stores batches in localStorage with time-ordered keys. The padding makes\n// keys().sort() a sort by creation time. Without padding, the sort uses hex order. take()\n// then does not return the oldest batch first.\n\nimport {\n BATCH_KEY_TIME_WIDTH,\n BATCH_STORAGE_KEY_PREFIX,\n QUOTA_EVICTION_DIVISOR,\n STORAGE_NAME_LOCAL,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { countRecords, isLogBatch, type LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { hasAction, pickEvictable } from \"./eviction\";\nimport { addDrop, reportEviction } from \"./gap\";\nimport { batchKey, keysWithPrefix } from \"./keys\";\n\n/** A stored entry. A corrupt entry has no batch. */\ninterface Entry {\n key: string;\n batch: LogBatch | null;\n}\n\n/**\n * Reads the creation time from a storage key. prune() runs after each save. A\n * read from the batch parses the full store for each save.\n * @param key Prefixed storage key.\n * @returns Creation time in epoch milliseconds, or null for a malformed key.\n */\nfunction createdAtOf(key: string, prefix: string): number | null {\n const start = prefix.length;\n const at = Number(key.slice(start, start + BATCH_KEY_TIME_WIDTH));\n\n return Number.isFinite(at) ? at : null;\n}\n\n/** This StorageAdapter keeps batches in localStorage. */\nexport class LocalStorageStorage implements StorageAdapter {\n /** This field holds the storage strategy name. */\n readonly name = STORAGE_NAME_LOCAL;\n\n /**\n * @param limits Storage capacity and retention thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Optional callback for dropped record reporting.\n */\n constructor(\n private readonly limits: StorageLimits,\n private readonly diagnostics: Diagnostics,\n private readonly onGap?: GapReporter,\n private readonly prefix = BATCH_STORAGE_KEY_PREFIX,\n ) {}\n\n /**\n * Writes a batch to localStorage. It removes the oldest entries on a quota error.\n * @param batch Batch to store.\n */\n async save(batch: LogBatch): Promise<void> {\n if (this.write(batch, \"localStorage refused a batch, evicting the oldest\")) {\n await this.prune();\n return;\n }\n\n this.evictForQuota();\n\n // The eviction makes room for this batch. Without a second write, save() resolves.\n // The library then loses the batch. No counter shows the loss.\n if (!this.write(batch, \"localStorage refused a batch even after evicting\")) {\n const gap: PruneResult = { batches: 1, records: batch.records.length, reason: \"quota\" };\n reportEviction(this.diagnostics, this.onGap, gap, [batch]);\n }\n }\n\n /**\n * Returns up to `limit` batches in FIFO order. It does not delete them.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to an array of valid batches.\n */\n take(limit: number): Promise<LogBatch[]> {\n const out: LogBatch[] = [];\n\n for (const key of this.keys().slice(0, limit)) {\n const batch = this.read(key);\n // The entry is corrupt. The library cannot recover it. Remove it without a gap count. It has\n // no readable record count.\n if (batch === null) {\n this.removeKey(key);\n continue;\n }\n out.push(batch);\n }\n\n return Promise.resolve(out);\n }\n\n /**\n * Returns up to `limit` batches of one context in FIFO order. It does not delete them.\n * It stops at the limit. The later entries then stay unparsed.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to the batches of this context.\n */\n takeContext(id: string, limit: number): Promise<LogBatch[]> {\n const out: LogBatch[] = [];\n\n for (const batch of this.batches()) {\n if (out.length >= limit) {\n break;\n }\n if (batch.routingContextId === id) {\n out.push(batch);\n }\n }\n\n return Promise.resolve(out);\n }\n\n /**\n * Counts the stored batches of one context. The context id is not in the key. Each entry is read.\n * @param id Delivery context id.\n * @returns Promise that resolves to the batch count of this context.\n */\n countContext(id: string): Promise<number> {\n let count = 0;\n\n for (const batch of this.batches()) {\n if (batch.routingContextId === id) {\n count++;\n }\n }\n\n return Promise.resolve(count);\n }\n\n /**\n * Reads the valid batches one at a time, oldest first. It removes a corrupt entry.\n * @yields Each valid batch.\n */\n private *batches(): Generator<LogBatch> {\n for (const key of this.keys()) {\n const batch = this.read(key);\n if (batch === null) {\n this.removeKey(key);\n continue;\n }\n yield batch;\n }\n }\n\n /**\n * Deletes the batch with the given ID from localStorage.\n * @param id Batch identifier.\n */\n remove(id: string): Promise<void> {\n const key = this.keyOf(id);\n if (key !== null) {\n this.removeKey(key);\n }\n return Promise.resolve();\n }\n\n /**\n * Sets the delivery attempt count of a stored batch. It does not change the key.\n * @param id Batch identifier.\n * @param attempts New absolute attempt count.\n */\n bumpAttempts(id: string, attempts: number): Promise<void> {\n const key = this.keyOf(id);\n if (key === null) {\n return Promise.resolve();\n }\n\n const batch = this.read(key);\n if (batch === null) {\n return Promise.resolve();\n }\n\n batch.attempts = attempts;\n this.diagnostics.guard(\n \"storage.degraded\",\n \"The library could not update the attempt count.\",\n () => {\n localStorage.setItem(key, JSON.stringify(batch));\n },\n );\n\n return Promise.resolve();\n }\n\n /**\n * Deletes expired batches. It then removes the oldest batches above the\n * capacity limit.\n * @returns Promise that resolves to prune summary metrics.\n */\n prune(): Promise<PruneResult> {\n const cutoff = Date.now() - this.limits.maxAgeMs;\n const result: PruneResult = { batches: 0, records: 0, reason: \"expired\" };\n const expired: string[] = [];\n const alive: string[] = [];\n\n for (const key of this.keys()) {\n const createdAt = createdAtOf(key, this.prefix);\n // A key with no readable time also has no position in the sort order.\n if (createdAt === null || createdAt < cutoff) {\n expired.push(key);\n continue;\n }\n alive.push(key);\n }\n\n // The record count is the one field that the key does not contain. Parse only the\n // deleted batches.\n this.drop(result, \"expired\", [...this.entries(expired)]);\n\n const excess = alive.length - this.limits.maxBatches;\n if (excess > 0) {\n this.drop(result, \"over_capacity\", this.evictable(alive, excess));\n }\n\n return Promise.resolve(result);\n }\n\n /**\n * Returns the number of stored batch keys. It does not deserialize the batches.\n * @returns Promise that resolves to batch count.\n */\n count(): Promise<number> {\n return Promise.resolve(this.keys().length);\n }\n\n /** This method deletes all batch keys from localStorage. */\n clear(): Promise<void> {\n this.evict(this.keys());\n return Promise.resolve();\n }\n\n /** This method does nothing. localStorage has no connection to close. */\n close(): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Writes a batch to localStorage.\n * @param batch Batch to store.\n * @param context Text that diagnostics reports when the write fails.\n * @returns True if the write succeeded.\n */\n private write(batch: LogBatch, context: string): boolean {\n const written = this.diagnostics.guard(\"storage.quota_exceeded\", context, () => {\n localStorage.setItem(batchKey(this.prefix, batch), JSON.stringify(batch));\n return true;\n });\n\n return written === true;\n }\n\n /** This method removes a quarter of the store to free quota. It counts the loss. */\n private evictForQuota(): void {\n const keys = this.keys();\n const result: PruneResult = { batches: 0, records: 0, reason: \"quota\" };\n const howMany = Math.ceil(keys.length / QUOTA_EVICTION_DIVISOR);\n\n this.drop(result, \"quota\", this.evictable(keys, howMany));\n }\n\n /**\n * Picks the entries to evict. Entries without an action go first. An action is an audit fact.\n * A corrupt entry has no action. It goes first.\n * @param keys Batch keys, oldest first.\n * @param howMany Number of entries to evict.\n * @returns The picked entries.\n */\n private evictable(keys: string[], howMany: number): Entry[] {\n return pickEvictable(\n this.entries(keys),\n howMany,\n (entry) => entry.batch !== null && hasAction(entry.batch),\n );\n }\n\n /**\n * Reads the entries one at a time. The eviction walk stops early. The later entries then stay\n * unparsed.\n * @param keys Batch keys.\n * @yields Each key with its batch.\n */\n private *entries(keys: string[]): Generator<Entry> {\n for (const key of keys) {\n yield { key, batch: this.read(key) };\n }\n }\n\n /**\n * Removes entries. It reports them with their own reason.\n * @param result Prune result of all rules.\n * @param reason Rule that removes the entries.\n * @param entries Entries to remove.\n */\n private drop(result: PruneResult, reason: PruneResult[\"reason\"], entries: Entry[]): void {\n if (entries.length === 0) {\n return;\n }\n\n const dropped: LogBatch[] = [];\n\n for (const { key, batch } of entries) {\n this.removeKey(key);\n if (batch) {\n dropped.push(batch);\n }\n }\n\n // A corrupt entry counts as a batch with no records.\n const gap = addDrop(result, reason, entries.length, countRecords(dropped));\n reportEviction(this.diagnostics, this.onGap, gap, dropped);\n }\n\n /**\n * Reads and validates the stored batch at a key.\n * @param key Storage key to read.\n * @returns Validated LogBatch or null if missing or malformed.\n */\n private read(key: string): LogBatch | null {\n const raw = this.diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read a stored batch.\",\n () => localStorage.getItem(key),\n );\n if (!raw) {\n return null;\n }\n\n const parsed = this.diagnostics.guard(\n \"storage.degraded\",\n \"A stored batch is corrupt. The library removed it.\",\n () => JSON.parse(raw) as unknown,\n );\n // The guard above already reported a parse failure. A second report counts one corrupt\n // entry twice.\n if (parsed === undefined) {\n return null;\n }\n\n if (!isLogBatch(parsed)) {\n this.diagnostics.report(\n \"storage.degraded\",\n \"A stored entry is not a batch. The library dropped it.\",\n );\n return null;\n }\n\n return parsed;\n }\n\n /**\n * Finds the storage key that ends with the batch ID.\n * @param id Batch identifier.\n * @returns Matching storage key string or null.\n */\n private keyOf(id: string): string | null {\n return this.keys().find((key) => key.endsWith(`.${id}`)) ?? null;\n }\n\n /**\n * Deletes a list of storage keys.\n * @param keys Keys to delete.\n */\n private evict(keys: string[]): void {\n for (const key of keys) {\n this.removeKey(key);\n }\n }\n\n /**\n * Deletes one storage key inside a guard.\n * @param key Storage key to remove.\n */\n private removeKey(key: string): void {\n this.diagnostics.guard(\n \"storage.degraded\",\n \"The library could not remove a stored batch.\",\n () => {\n localStorage.removeItem(key);\n },\n );\n }\n\n /**\n * Returns all batch storage keys in sorted order.\n * @returns Sorted array of storage keys.\n */\n private keys(): string[] {\n return keysWithPrefix(this.prefix, this.diagnostics);\n }\n}\n","// src/storage/memory-storage.ts\n//\n// This module keeps batches in volatile memory during offline periods. A reload loses all of\n// them. This adapter is the last fallback.\n\nimport { STORAGE_NAME_MEMORY } from \"../constants\";\nimport { countRecords, type LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { hasAction, pickEvictable } from \"./eviction\";\nimport { addDrop } from \"./gap\";\n\n/** This StorageAdapter keeps batches in volatile memory. */\nexport class MemoryStorage implements StorageAdapter {\n /** This field holds the storage strategy name. */\n readonly name = STORAGE_NAME_MEMORY;\n\n /** This array holds the batches in FIFO order. */\n private batches: LogBatch[] = [];\n\n /**\n * @param limits Storage capacity and retention thresholds.\n * @param onGap Optional callback for dropped record reporting.\n */\n constructor(\n private readonly limits: StorageLimits,\n private readonly onGap?: GapReporter,\n ) {}\n\n /**\n * Appends a batch and applies retention pruning.\n * @param batch Batch to store.\n */\n async save(batch: LogBatch): Promise<void> {\n // A batch with a known id replaces the old copy in place, as IndexedDB put() does.\n const index = this.batches.findIndex((stored) => stored.id === batch.id);\n if (index >= 0) {\n this.batches[index] = batch;\n } else {\n this.batches.push(batch);\n }\n await this.prune();\n }\n\n /**\n * Returns up to `limit` batches in FIFO order. It does not delete them.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to an array of batches.\n */\n take(limit: number): Promise<LogBatch[]> {\n return Promise.resolve(this.batches.slice(0, limit));\n }\n\n /**\n * Returns up to `limit` batches of one context in FIFO order. It does not delete them.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to the batches of this context.\n */\n takeContext(id: string, limit: number): Promise<LogBatch[]> {\n return Promise.resolve(\n this.batches.filter((batch) => batch.routingContextId === id).slice(0, limit),\n );\n }\n\n /**\n * Counts the stored batches of one context.\n * @param id Delivery context id.\n * @returns Promise that resolves to the batch count of this context.\n */\n countContext(id: string): Promise<number> {\n return Promise.resolve(this.batches.filter((batch) => batch.routingContextId === id).length);\n }\n\n /**\n * Deletes the batch with the given ID.\n * @param id Batch identifier.\n */\n remove(id: string): Promise<void> {\n this.batches = this.batches.filter((batch) => batch.id !== id);\n return Promise.resolve();\n }\n\n /**\n * Sets the delivery attempt count of a stored batch.\n * @param id Batch identifier.\n * @param attempts New absolute attempt count.\n */\n bumpAttempts(id: string, attempts: number): Promise<void> {\n const found = this.batches.find((batch) => batch.id === id);\n if (found) {\n found.attempts = attempts;\n }\n return Promise.resolve();\n }\n\n /**\n * Removes expired batches. It then removes the oldest batches above the\n * capacity limit.\n * @returns Promise that resolves to prune summary metrics.\n */\n prune(): Promise<PruneResult> {\n const cutoff = Date.now() - this.limits.maxAgeMs;\n const result: PruneResult = { batches: 0, records: 0, reason: \"expired\" };\n\n const expired = this.batches.filter((batch) => batch.createdAt < cutoff);\n this.batches = this.batches.filter((batch) => batch.createdAt >= cutoff);\n this.report(result, \"expired\", expired);\n\n const excess = this.batches.length - this.limits.maxBatches;\n if (excess > 0) {\n // An action is an audit fact. Evict each batch without an action first.\n const evicted = pickEvictable(this.batches, excess, hasAction);\n this.batches = this.batches.filter((batch) => !evicted.includes(batch));\n this.report(result, \"over_capacity\", evicted);\n }\n\n return Promise.resolve(result);\n }\n\n /**\n * Adds dropped batches to the prune result. It reports them with their own reason.\n * @param result Prune result of all rules.\n * @param reason Rule that dropped the batches.\n * @param dropped The dropped batches.\n */\n private report(result: PruneResult, reason: PruneResult[\"reason\"], dropped: LogBatch[]): void {\n if (dropped.length === 0) {\n return;\n }\n\n const gap = addDrop(result, reason, dropped.length, countRecords(dropped));\n this.onGap?.(gap, dropped);\n }\n\n /**\n * Returns the number of stored batches.\n * @returns Promise that resolves to batch count.\n */\n count(): Promise<number> {\n return Promise.resolve(this.batches.length);\n }\n\n /** This method deletes all stored batches. */\n clear(): Promise<void> {\n this.batches = [];\n return Promise.resolve();\n }\n\n /** This method deletes all stored batches when the storage closes. */\n close(): Promise<void> {\n this.batches = [];\n return Promise.resolve();\n }\n}\n","// src/storage/factory.ts\n//\n// This module selects a storage adapter. It falls back from IndexedDB to localStorage to memory.\n// It falls back and does not throw. IndexedDB is unavailable in private mode and sandboxed\n// frames.\n\nimport {\n STORAGE_DB_NAME,\n STORAGE_NAME_INDEXEDDB,\n STORAGE_NAME_MEMORY,\n STORAGE_NAME_NONE,\n STORAGE_PROBE_KEY,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { StorageStrategy } from \"../models/config\";\nimport type { GapReporter, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { LocalStorageStorage } from \"./local-storage\";\nimport { MemoryStorage } from \"./memory-storage\";\n\n/**\n * Gives the database name of one application namespace. The sender and the deletion use one rule.\n * @param namespace Application namespace. An empty value keeps the name before namespaces.\n * @returns Name of the IndexedDB database.\n */\nexport function storageName(namespace: string): string {\n return namespace ? `${STORAGE_DB_NAME}:${namespace}` : STORAGE_DB_NAME;\n}\n\n/**\n * Builds the adapter that keeps nothing. The factory returns it for the \"none\" strategy. Each\n * method resolves. A sender that calls close() on shutdown must not crash.\n * @param onGap Receives each batch that the adapter does not keep. That batch is a loss.\n * @returns The adapter.\n */\nconst noop = (onGap?: GapReporter): StorageAdapter => ({\n name: STORAGE_NAME_NONE,\n save: (batch) => {\n onGap?.({ batches: 1, records: batch.records.length, reason: \"not_stored\" }, [batch]);\n return Promise.resolve();\n },\n take: () => Promise.resolve([]),\n remove: () => Promise.resolve(),\n bumpAttempts: () => Promise.resolve(),\n prune: () => Promise.resolve({ batches: 0, records: 0, reason: \"expired\" as const }),\n count: () => Promise.resolve(0),\n clear: () => Promise.resolve(),\n close: () => Promise.resolve(),\n});\n\n/**\n * Checks if IndexedDB is available in the current context.\n * @param diagnostics Diagnostics reporter.\n * @returns True if IDBFactory is available.\n */\nfunction hasIndexedDb(diagnostics: Diagnostics): boolean {\n const available = diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read indexedDB.\",\n () => {\n const factory = (globalThis as { indexedDB?: IDBFactory | null }).indexedDB;\n return factory !== undefined && factory !== null;\n },\n );\n\n return available === true;\n}\n\n/**\n * Checks if localStorage is available and accepts writes.\n * @param diagnostics Diagnostics reporter.\n * @returns True if localStorage probe write succeeds.\n */\nfunction hasLocalStorage(diagnostics: Diagnostics): boolean {\n const usable = diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not write a test key to localStorage.\",\n () => {\n localStorage.setItem(STORAGE_PROBE_KEY, \"1\");\n localStorage.removeItem(STORAGE_PROBE_KEY);\n return true;\n },\n );\n\n return usable === true;\n}\n\n/**\n * Creates the requested storage adapter. It falls back to the next adapter when\n * a dependency is unavailable.\n * @param strategy Configured persistence strategy.\n * @param dbName IndexedDB database name.\n * @param limits Storage retention and capacity thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Optional callback for telemetry gap reporting.\n * @returns Promise that resolves to the selected StorageAdapter instance.\n */\nexport async function createStorage(\n strategy: StorageStrategy,\n dbName: string,\n limits: StorageLimits,\n diagnostics: Diagnostics,\n onGap?: GapReporter,\n namespace = \"\",\n): Promise<StorageAdapter> {\n if (strategy === STORAGE_NAME_NONE) {\n return noop(onGap);\n }\n if (strategy === STORAGE_NAME_MEMORY) {\n return new MemoryStorage(limits, onGap);\n }\n\n if (strategy === STORAGE_NAME_INDEXEDDB || strategy === \"auto\") {\n if (hasIndexedDb(diagnostics)) {\n // Import IndexedDbStorage dynamically. This keeps the driver out of the main bundle. A\n // chunk that does not load falls back to the next adapter.\n const adapter = await diagnostics.guardAsync(\n \"storage.unavailable\",\n \"The library could not open IndexedDB.\",\n async () => {\n const { IndexedDbStorage } = await import(\"./indexeddb-storage\");\n const storage = new IndexedDbStorage(dbName, limits, diagnostics, onGap);\n // Open the database here, not on first use. Private mode, a corrupt profile and\n // some WebViews define indexedDB but reject open(). Only a rejection in this\n // block selects the next adapter.\n await storage.open();\n return storage;\n },\n );\n if (adapter) {\n return adapter;\n }\n }\n\n if (strategy === STORAGE_NAME_INDEXEDDB) {\n diagnostics.report(\n \"storage.degraded\",\n \"IndexedDB is not available. The library uses memory storage instead.\",\n );\n return new MemoryStorage(limits, onGap);\n }\n }\n\n if (hasLocalStorage(diagnostics)) {\n return new LocalStorageStorage(\n limits,\n diagnostics,\n onGap,\n namespace ? `ui-observability:namespaced:${encodeURIComponent(namespace)}:batch:` : undefined,\n );\n }\n\n diagnostics.report(\n \"storage.degraded\",\n \"No persistent storage is available. The library keeps undelivered records in memory only.\",\n );\n return new MemoryStorage(limits, onGap);\n}\n"],"mappings":"+GAYA,SAAgBe,EAAU,EAA0B,CAGlD,OAAO,MAAM,QAAQC,EAAM,OAAO,GAAKA,EAAM,QAAQ,KAAKhB,EAAAA,CAAc,CAC1E,CAGA,IAAaiB,EAAb,KAA6B,CAYR,QACA,QAXnB,MAA8B,CAAC,EAG/B,MAA8B,CAAC,EAM/B,YACE,EACA,EACA,CAFiB,KAAA,QAAAC,EACA,KAAA,QAAAC,CAChB,CAOH,IAAI,EAAkB,CAOpB,OANK,KAAK,QAAQC,CAAI,EAEX,KAAK,MAAM,OAAS,KAAK,SAClC,KAAK,MAAM,KAAKA,CAAI,EAFpB,KAAK,MAAM,KAAKA,CAAI,EAKf,KAAK,MAAM,O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BAAmBA,CAAS,EAAE,SAAW,IAAA,EACtF,GAGFjC,EAAY,OACV,mBACA,2FACF,EACO,IAAI2B,EAAclB,EAAQR,CAAK,EACxC"}
1
+ {"version":3,"file":"factory-CJXVYp0R.cjs","names":["isActionRecord","STORAGE_NAME_LOCAL","BATCH_STORAGE_KEY_PREFIX","batchKey","countRecords","isLogBatch","keysWithPrefix","STORAGE_NAME_MEMORY","countRecords","STORAGE_DB_NAME","STORAGE_NAME_NONE","STORAGE_PROBE_KEY","require_constants","require_batch","require_keys","hasAction","batch","EvictionPick","howMany","isAudit","item","pickEvictable","pick","items","addDrop","batches","records","reason","reportEviction","gap","diagnostics","onGap","dropped","createdAtOf","start","prefix","at","key","LocalStorageStorage","limits","out","limit","id","count","attempts","cutoff","result","expired","alive","createdAt","excess","context","keys","entry","entries","raw","parsed","MemoryStorage","index","stored","found","evicted","storageName","namespace","noop","hasIndexedDb","hasLocalStorage","createStorage","strategy","adapter","storage","IndexedDbStorage","dbName"],"sources":["../src/storage/eviction.ts","../src/storage/gap.ts","../src/storage/local-storage.ts","../src/storage/memory-storage.ts","../src/storage/factory.ts"],"sourcesContent":["// src/storage/eviction.ts\n//\n// This module selects the stored batches to evict. An action is an audit fact. The batches without\n// an action go first. The walk stops early. A read of the full store at each save blocks the page.\n\nimport { isActionRecord, type LogBatch } from \"../models/batch\";\n\n/**\n * Tests if a batch holds an action. An eviction removes such a batch last.\n * @param batch Batch to test.\n * @returns True if one record of the batch is an action.\n */\nexport function hasAction(batch: LogBatch): boolean {\n // Another script on the origin can write to the database. A throw in a cursor handler stops\n // the eviction walk. The walk then never settles.\n return Array.isArray(batch.records) && batch.records.some(isActionRecord);\n}\n\n/** Collects the items to evict from a walk in age order, oldest first. */\nexport class EvictionPick<T> {\n /** Items without an audit fact. */\n private readonly plain: T[] = [];\n\n /** Oldest items with an audit fact. The pick uses them only when too few plain items exist. */\n private readonly audit: T[] = [];\n\n /**\n * @param howMany Number of items to evict.\n * @param isAudit Tests if an item holds an audit fact.\n */\n constructor(\n private readonly howMany: number,\n private readonly isAudit: (item: T) => boolean,\n ) {}\n\n /**\n * Adds the next item of the walk.\n * @param item Next oldest item.\n * @returns False when the pick has enough items without an audit fact. The walk then stops.\n */\n add(item: T): boolean {\n if (!this.isAudit(item)) {\n this.plain.push(item);\n } else if (this.audit.length < this.howMany) {\n this.audit.push(item);\n }\n\n return this.plain.length < this.howMany;\n }\n\n /**\n * Gives the items to evict. The items without an audit fact come first.\n * @returns The picked items.\n */\n picked(): T[] {\n return [...this.plain, ...this.audit].slice(0, this.howMany);\n }\n}\n\n/**\n * Picks the items to evict from a walk in age order. It stops the walk early.\n * @param items Items, oldest first. A generator reads each item only when the walk needs it.\n * @param howMany Number of items to evict.\n * @param isAudit Tests if an item holds an audit fact.\n * @returns The picked items. The items without an audit fact come first.\n */\nexport function pickEvictable<T>(\n items: Iterable<T>,\n howMany: number,\n isAudit: (item: T) => boolean,\n): T[] {\n const pick = new EvictionPick(howMany, isAudit);\n\n for (const item of items) {\n if (!pick.add(item)) {\n break;\n }\n }\n\n return pick.picked();\n}\n","// src/storage/gap.ts\n//\n// This module counts and reports the batches that a storage adapter drops. Each dropped batch is a\n// loss. The gap handler gives it to onDrop.\n\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult } from \"../models/storage\";\n\n/**\n * Adds the drop of one rule to the prune result.\n * @param result Prune result of all rules.\n * @param reason Rule that dropped the batches.\n * @param batches Number of dropped batches.\n * @param records Number of dropped records.\n * @returns The counts of this rule alone, for the gap report.\n */\nexport function addDrop(\n result: PruneResult,\n reason: PruneResult[\"reason\"],\n batches: number,\n records: number,\n): PruneResult {\n result.batches += batches;\n result.records += records;\n result.reason = reason;\n return { batches, records, reason };\n}\n\n/**\n * Reports dropped batches to diagnostics and to the gap handler. An empty drop reports nothing.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Gap handler of the adapter.\n * @param gap Counts and reason of the drop.\n * @param dropped The dropped batches that the adapter could read.\n */\nexport function reportEviction(\n diagnostics: Diagnostics,\n onGap: GapReporter | undefined,\n gap: PruneResult,\n dropped: readonly LogBatch[],\n): void {\n if (gap.batches === 0) {\n return;\n }\n\n diagnostics.report(\n \"storage.evicted\",\n `The library dropped ${String(gap.batches)} stored batches (${String(gap.records)} records).`,\n { ...gap },\n );\n onGap?.(gap, dropped);\n}\n","// src/storage/local-storage.ts\n//\n// This module stores batches in localStorage with time-ordered keys. The padding makes\n// keys().sort() a sort by creation time. Without padding, the sort uses hex order. take()\n// then does not return the oldest batch first.\n\nimport {\n BATCH_KEY_TIME_WIDTH,\n BATCH_STORAGE_KEY_PREFIX,\n QUOTA_EVICTION_DIVISOR,\n STORAGE_NAME_LOCAL,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { countRecords, isLogBatch, type LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { hasAction, pickEvictable } from \"./eviction\";\nimport { addDrop, reportEviction } from \"./gap\";\nimport { batchKey, keysWithPrefix } from \"./keys\";\n\n/** A stored entry. A corrupt entry has no batch. */\ninterface Entry {\n key: string;\n batch: LogBatch | null;\n}\n\n/**\n * Reads the creation time from a storage key. prune() runs after each save. A\n * read from the batch parses the full store for each save.\n * @param key Prefixed storage key.\n * @returns Creation time in epoch milliseconds, or null for a malformed key.\n */\nfunction createdAtOf(key: string, prefix: string): number | null {\n const start = prefix.length;\n const at = Number(key.slice(start, start + BATCH_KEY_TIME_WIDTH));\n\n return Number.isFinite(at) ? at : null;\n}\n\n/** This StorageAdapter keeps batches in localStorage. */\nexport class LocalStorageStorage implements StorageAdapter {\n /** This field holds the storage strategy name. */\n readonly name = STORAGE_NAME_LOCAL;\n\n /**\n * @param limits Storage capacity and retention thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Optional callback for dropped record reporting.\n */\n constructor(\n private readonly limits: StorageLimits,\n private readonly diagnostics: Diagnostics,\n private readonly onGap?: GapReporter,\n private readonly prefix = BATCH_STORAGE_KEY_PREFIX,\n ) {}\n\n /**\n * Writes a batch to localStorage. It removes the oldest entries on a quota error.\n * @param batch Batch to store.\n */\n async save(batch: LogBatch): Promise<void> {\n if (this.write(batch, \"localStorage refused a batch, evicting the oldest\")) {\n await this.prune();\n return;\n }\n\n this.evictForQuota();\n\n // The eviction makes room for this batch. Without a second write, save() resolves.\n // The library then loses the batch. No counter shows the loss.\n if (!this.write(batch, \"localStorage refused a batch even after evicting\")) {\n const gap: PruneResult = { batches: 1, records: batch.records.length, reason: \"quota\" };\n reportEviction(this.diagnostics, this.onGap, gap, [batch]);\n }\n }\n\n /**\n * Returns up to `limit` batches in FIFO order. It does not delete them.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to an array of valid batches.\n */\n take(limit: number): Promise<LogBatch[]> {\n const out: LogBatch[] = [];\n\n for (const key of this.keys().slice(0, limit)) {\n const batch = this.read(key);\n // The entry is corrupt. The library cannot recover it. Remove it without a gap count. It has\n // no readable record count.\n if (batch === null) {\n this.removeKey(key);\n continue;\n }\n out.push(batch);\n }\n\n return Promise.resolve(out);\n }\n\n /**\n * Returns up to `limit` batches of one context in FIFO order. It does not delete them.\n * It stops at the limit. The later entries then stay unparsed.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to the batches of this context.\n */\n takeContext(id: string, limit: number): Promise<LogBatch[]> {\n const out: LogBatch[] = [];\n\n for (const batch of this.batches()) {\n if (out.length >= limit) {\n break;\n }\n if (batch.routingContextId === id) {\n out.push(batch);\n }\n }\n\n return Promise.resolve(out);\n }\n\n /**\n * Counts the stored batches of one context. The context id is not in the key. Each entry is read.\n * @param id Delivery context id.\n * @returns Promise that resolves to the batch count of this context.\n */\n countContext(id: string): Promise<number> {\n let count = 0;\n\n for (const batch of this.batches()) {\n if (batch.routingContextId === id) {\n count++;\n }\n }\n\n return Promise.resolve(count);\n }\n\n /**\n * Reads the valid batches one at a time, oldest first. It removes a corrupt entry.\n * @yields Each valid batch.\n */\n private *batches(): Generator<LogBatch> {\n for (const key of this.keys()) {\n const batch = this.read(key);\n if (batch === null) {\n this.removeKey(key);\n continue;\n }\n yield batch;\n }\n }\n\n /**\n * Deletes the batch with the given ID from localStorage.\n * @param id Batch identifier.\n */\n remove(id: string): Promise<void> {\n const key = this.keyOf(id);\n if (key !== null) {\n this.removeKey(key);\n }\n return Promise.resolve();\n }\n\n /**\n * Sets the delivery attempt count of a stored batch. It does not change the key.\n * @param id Batch identifier.\n * @param attempts New absolute attempt count.\n */\n bumpAttempts(id: string, attempts: number): Promise<void> {\n const key = this.keyOf(id);\n if (key === null) {\n return Promise.resolve();\n }\n\n const batch = this.read(key);\n if (batch === null) {\n return Promise.resolve();\n }\n\n batch.attempts = attempts;\n this.diagnostics.guard(\n \"storage.degraded\",\n \"The library could not update the attempt count.\",\n () => {\n localStorage.setItem(key, JSON.stringify(batch));\n },\n );\n\n return Promise.resolve();\n }\n\n /**\n * Deletes expired batches. It then removes the oldest batches above the\n * capacity limit.\n * @returns Promise that resolves to prune summary metrics.\n */\n prune(): Promise<PruneResult> {\n const cutoff = Date.now() - this.limits.maxAgeMs;\n const result: PruneResult = { batches: 0, records: 0, reason: \"expired\" };\n const expired: string[] = [];\n const alive: string[] = [];\n\n for (const key of this.keys()) {\n const createdAt = createdAtOf(key, this.prefix);\n // A key with no readable time also has no position in the sort order.\n if (createdAt === null || createdAt < cutoff) {\n expired.push(key);\n continue;\n }\n alive.push(key);\n }\n\n // The record count is the one field that the key does not contain. Parse only the\n // deleted batches.\n this.drop(result, \"expired\", [...this.entries(expired)]);\n\n const excess = alive.length - this.limits.maxBatches;\n if (excess > 0) {\n this.drop(result, \"over_capacity\", this.evictable(alive, excess));\n }\n\n return Promise.resolve(result);\n }\n\n /**\n * Returns the number of stored batch keys. It does not deserialize the batches.\n * @returns Promise that resolves to batch count.\n */\n count(): Promise<number> {\n return Promise.resolve(this.keys().length);\n }\n\n /** This method deletes all batch keys from localStorage. */\n clear(): Promise<void> {\n this.evict(this.keys());\n return Promise.resolve();\n }\n\n /** This method does nothing. localStorage has no connection to close. */\n close(): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Writes a batch to localStorage.\n * @param batch Batch to store.\n * @param context Text that diagnostics reports when the write fails.\n * @returns True if the write succeeded.\n */\n private write(batch: LogBatch, context: string): boolean {\n const written = this.diagnostics.guard(\"storage.quota_exceeded\", context, () => {\n localStorage.setItem(batchKey(this.prefix, batch), JSON.stringify(batch));\n return true;\n });\n\n return written === true;\n }\n\n /** This method removes a quarter of the store to free quota. It counts the loss. */\n private evictForQuota(): void {\n const keys = this.keys();\n const result: PruneResult = { batches: 0, records: 0, reason: \"quota\" };\n const howMany = Math.ceil(keys.length / QUOTA_EVICTION_DIVISOR);\n\n this.drop(result, \"quota\", this.evictable(keys, howMany));\n }\n\n /**\n * Picks the entries to evict. Entries without an action go first. An action is an audit fact.\n * A corrupt entry has no action. It goes first.\n * @param keys Batch keys, oldest first.\n * @param howMany Number of entries to evict.\n * @returns The picked entries.\n */\n private evictable(keys: string[], howMany: number): Entry[] {\n return pickEvictable(\n this.entries(keys),\n howMany,\n (entry) => entry.batch !== null && hasAction(entry.batch),\n );\n }\n\n /**\n * Reads the entries one at a time. The eviction walk stops early. The later entries then stay\n * unparsed.\n * @param keys Batch keys.\n * @yields Each key with its batch.\n */\n private *entries(keys: string[]): Generator<Entry> {\n for (const key of keys) {\n yield { key, batch: this.read(key) };\n }\n }\n\n /**\n * Removes entries. It reports them with their own reason.\n * @param result Prune result of all rules.\n * @param reason Rule that removes the entries.\n * @param entries Entries to remove.\n */\n private drop(result: PruneResult, reason: PruneResult[\"reason\"], entries: Entry[]): void {\n if (entries.length === 0) {\n return;\n }\n\n const dropped: LogBatch[] = [];\n\n for (const { key, batch } of entries) {\n this.removeKey(key);\n if (batch) {\n dropped.push(batch);\n }\n }\n\n // A corrupt entry counts as a batch with no records.\n const gap = addDrop(result, reason, entries.length, countRecords(dropped));\n reportEviction(this.diagnostics, this.onGap, gap, dropped);\n }\n\n /**\n * Reads and validates the stored batch at a key.\n * @param key Storage key to read.\n * @returns Validated LogBatch or null if missing or malformed.\n */\n private read(key: string): LogBatch | null {\n const raw = this.diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read a stored batch.\",\n () => localStorage.getItem(key),\n );\n if (!raw) {\n return null;\n }\n\n const parsed = this.diagnostics.guard(\n \"storage.degraded\",\n \"A stored batch is corrupt. The library removed it.\",\n () => JSON.parse(raw) as unknown,\n );\n // The guard above already reported a parse failure. A second report counts one corrupt\n // entry twice.\n if (parsed === undefined) {\n return null;\n }\n\n if (!isLogBatch(parsed)) {\n this.diagnostics.report(\n \"storage.degraded\",\n \"A stored entry is not a batch. The library dropped it.\",\n );\n return null;\n }\n\n return parsed;\n }\n\n /**\n * Finds the storage key that ends with the batch ID.\n * @param id Batch identifier.\n * @returns Matching storage key string or null.\n */\n private keyOf(id: string): string | null {\n return this.keys().find((key) => key.endsWith(`.${id}`)) ?? null;\n }\n\n /**\n * Deletes a list of storage keys.\n * @param keys Keys to delete.\n */\n private evict(keys: string[]): void {\n for (const key of keys) {\n this.removeKey(key);\n }\n }\n\n /**\n * Deletes one storage key inside a guard.\n * @param key Storage key to remove.\n */\n private removeKey(key: string): void {\n this.diagnostics.guard(\n \"storage.degraded\",\n \"The library could not remove a stored batch.\",\n () => {\n localStorage.removeItem(key);\n },\n );\n }\n\n /**\n * Returns all batch storage keys in sorted order.\n * @returns Sorted array of storage keys.\n */\n private keys(): string[] {\n return keysWithPrefix(this.prefix, this.diagnostics);\n }\n}\n","// src/storage/memory-storage.ts\n//\n// This module keeps batches in volatile memory during offline periods. A reload loses all of\n// them. This adapter is the last fallback.\n\nimport { STORAGE_NAME_MEMORY } from \"../constants\";\nimport { countRecords, type LogBatch } from \"../models/batch\";\nimport type { GapReporter, PruneResult, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { hasAction, pickEvictable } from \"./eviction\";\nimport { addDrop } from \"./gap\";\n\n/** This StorageAdapter keeps batches in volatile memory. */\nexport class MemoryStorage implements StorageAdapter {\n /** This field holds the storage strategy name. */\n readonly name = STORAGE_NAME_MEMORY;\n\n /** This array holds the batches in FIFO order. */\n private batches: LogBatch[] = [];\n\n /**\n * @param limits Storage capacity and retention thresholds.\n * @param onGap Optional callback for dropped record reporting.\n */\n constructor(\n private readonly limits: StorageLimits,\n private readonly onGap?: GapReporter,\n ) {}\n\n /**\n * Appends a batch and applies retention pruning.\n * @param batch Batch to store.\n */\n async save(batch: LogBatch): Promise<void> {\n // A batch with a known id replaces the old copy in place, as IndexedDB put() does.\n const index = this.batches.findIndex((stored) => stored.id === batch.id);\n if (index >= 0) {\n this.batches[index] = batch;\n } else {\n this.batches.push(batch);\n }\n await this.prune();\n }\n\n /**\n * Returns up to `limit` batches in FIFO order. It does not delete them.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to an array of batches.\n */\n take(limit: number): Promise<LogBatch[]> {\n return Promise.resolve(this.batches.slice(0, limit));\n }\n\n /**\n * Returns up to `limit` batches of one context in FIFO order. It does not delete them.\n * @param id Delivery context id.\n * @param limit Maximum number of batches to retrieve.\n * @returns Promise that resolves to the batches of this context.\n */\n takeContext(id: string, limit: number): Promise<LogBatch[]> {\n return Promise.resolve(\n this.batches.filter((batch) => batch.routingContextId === id).slice(0, limit),\n );\n }\n\n /**\n * Counts the stored batches of one context.\n * @param id Delivery context id.\n * @returns Promise that resolves to the batch count of this context.\n */\n countContext(id: string): Promise<number> {\n return Promise.resolve(this.batches.filter((batch) => batch.routingContextId === id).length);\n }\n\n /**\n * Deletes the batch with the given ID.\n * @param id Batch identifier.\n */\n remove(id: string): Promise<void> {\n this.batches = this.batches.filter((batch) => batch.id !== id);\n return Promise.resolve();\n }\n\n /**\n * Sets the delivery attempt count of a stored batch.\n * @param id Batch identifier.\n * @param attempts New absolute attempt count.\n */\n bumpAttempts(id: string, attempts: number): Promise<void> {\n const found = this.batches.find((batch) => batch.id === id);\n if (found) {\n found.attempts = attempts;\n }\n return Promise.resolve();\n }\n\n /**\n * Removes expired batches. It then removes the oldest batches above the\n * capacity limit.\n * @returns Promise that resolves to prune summary metrics.\n */\n prune(): Promise<PruneResult> {\n const cutoff = Date.now() - this.limits.maxAgeMs;\n const result: PruneResult = { batches: 0, records: 0, reason: \"expired\" };\n\n const expired = this.batches.filter((batch) => batch.createdAt < cutoff);\n this.batches = this.batches.filter((batch) => batch.createdAt >= cutoff);\n this.report(result, \"expired\", expired);\n\n const excess = this.batches.length - this.limits.maxBatches;\n if (excess > 0) {\n // An action is an audit fact. Evict each batch without an action first.\n const evicted = pickEvictable(this.batches, excess, hasAction);\n this.batches = this.batches.filter((batch) => !evicted.includes(batch));\n this.report(result, \"over_capacity\", evicted);\n }\n\n return Promise.resolve(result);\n }\n\n /**\n * Adds dropped batches to the prune result. It reports them with their own reason.\n * @param result Prune result of all rules.\n * @param reason Rule that dropped the batches.\n * @param dropped The dropped batches.\n */\n private report(result: PruneResult, reason: PruneResult[\"reason\"], dropped: LogBatch[]): void {\n if (dropped.length === 0) {\n return;\n }\n\n const gap = addDrop(result, reason, dropped.length, countRecords(dropped));\n this.onGap?.(gap, dropped);\n }\n\n /**\n * Returns the number of stored batches.\n * @returns Promise that resolves to batch count.\n */\n count(): Promise<number> {\n return Promise.resolve(this.batches.length);\n }\n\n /** This method deletes all stored batches. */\n clear(): Promise<void> {\n this.batches = [];\n return Promise.resolve();\n }\n\n /** This method deletes all stored batches when the storage closes. */\n close(): Promise<void> {\n this.batches = [];\n return Promise.resolve();\n }\n}\n","// src/storage/factory.ts\n//\n// This module selects a storage adapter. It falls back from IndexedDB to localStorage to memory.\n// It falls back and does not throw. IndexedDB is unavailable in private mode and sandboxed\n// frames.\n\nimport {\n STORAGE_DB_NAME,\n STORAGE_NAME_INDEXEDDB,\n STORAGE_NAME_MEMORY,\n STORAGE_NAME_NONE,\n STORAGE_PROBE_KEY,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { StorageStrategy } from \"../models/config\";\nimport type { GapReporter, StorageAdapter, StorageLimits } from \"../models/storage\";\nimport { LocalStorageStorage } from \"./local-storage\";\nimport { MemoryStorage } from \"./memory-storage\";\n\n/**\n * Gives the database name of one application namespace. The sender and the deletion use one rule.\n * @param namespace Application namespace. An empty value keeps the name before namespaces.\n * @returns Name of the IndexedDB database.\n */\nexport function storageName(namespace: string): string {\n return namespace ? `${STORAGE_DB_NAME}:${namespace}` : STORAGE_DB_NAME;\n}\n\n/**\n * Builds the adapter that keeps nothing. The factory returns it for the \"none\" strategy. Each\n * method resolves. A sender that calls close() on shutdown must not crash.\n * @param onGap Receives each batch that the adapter does not keep. That batch is a loss.\n * @returns The adapter.\n */\nconst noop = (onGap?: GapReporter): StorageAdapter => ({\n name: STORAGE_NAME_NONE,\n save: (batch) => {\n onGap?.({ batches: 1, records: batch.records.length, reason: \"not_stored\" }, [batch]);\n return Promise.resolve();\n },\n take: () => Promise.resolve([]),\n remove: () => Promise.resolve(),\n bumpAttempts: () => Promise.resolve(),\n prune: () => Promise.resolve({ batches: 0, records: 0, reason: \"expired\" as const }),\n count: () => Promise.resolve(0),\n clear: () => Promise.resolve(),\n close: () => Promise.resolve(),\n});\n\n/**\n * Checks if IndexedDB is available in the current context.\n * @param diagnostics Diagnostics reporter.\n * @returns True if IDBFactory is available.\n */\nfunction hasIndexedDb(diagnostics: Diagnostics): boolean {\n const available = diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read indexedDB.\",\n () => {\n const factory = (globalThis as { indexedDB?: IDBFactory | null }).indexedDB;\n return factory !== undefined && factory !== null;\n },\n );\n\n return available === true;\n}\n\n/**\n * Checks if localStorage is available and accepts writes.\n * @param diagnostics Diagnostics reporter.\n * @returns True if localStorage probe write succeeds.\n */\nfunction hasLocalStorage(diagnostics: Diagnostics): boolean {\n const usable = diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not write a test key to localStorage.\",\n () => {\n localStorage.setItem(STORAGE_PROBE_KEY, \"1\");\n localStorage.removeItem(STORAGE_PROBE_KEY);\n return true;\n },\n );\n\n return usable === true;\n}\n\n/**\n * Creates the requested storage adapter. It falls back to the next adapter when\n * a dependency is unavailable.\n * @param strategy Configured persistence strategy.\n * @param dbName IndexedDB database name.\n * @param limits Storage retention and capacity thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param onGap Optional callback for telemetry gap reporting.\n * @returns Promise that resolves to the selected StorageAdapter instance.\n */\nexport async function createStorage(\n strategy: StorageStrategy,\n dbName: string,\n limits: StorageLimits,\n diagnostics: Diagnostics,\n onGap?: GapReporter,\n namespace = \"\",\n): Promise<StorageAdapter> {\n if (strategy === STORAGE_NAME_NONE) {\n return noop(onGap);\n }\n if (strategy === STORAGE_NAME_MEMORY) {\n return new MemoryStorage(limits, onGap);\n }\n\n if (strategy === STORAGE_NAME_INDEXEDDB || strategy === \"auto\") {\n if (hasIndexedDb(diagnostics)) {\n // Import IndexedDbStorage dynamically. This keeps the driver out of the main bundle. A\n // chunk that does not load falls back to the next adapter.\n const adapter = await diagnostics.guardAsync(\n \"storage.unavailable\",\n \"The library could not open IndexedDB.\",\n async () => {\n const { IndexedDbStorage } = await import(\"./indexeddb-storage\");\n const storage = new IndexedDbStorage(dbName, limits, diagnostics, onGap);\n // Open the database here, not on first use. Private mode, a corrupt profile and\n // some WebViews define indexedDB but reject open(). Only a rejection in this\n // block selects the next adapter.\n await storage.open();\n return storage;\n },\n );\n if (adapter) {\n return adapter;\n }\n }\n\n if (strategy === STORAGE_NAME_INDEXEDDB) {\n diagnostics.report(\n \"storage.degraded\",\n \"IndexedDB is not available. The library uses memory storage instead.\",\n );\n return new MemoryStorage(limits, onGap);\n }\n }\n\n if (hasLocalStorage(diagnostics)) {\n return new LocalStorageStorage(\n limits,\n diagnostics,\n onGap,\n namespace ? `ui-observability:namespaced:${encodeURIComponent(namespace)}:batch:` : undefined,\n );\n }\n\n diagnostics.report(\n \"storage.degraded\",\n \"No persistent storage is available. The library keeps undelivered records in memory only.\",\n );\n return new MemoryStorage(limits, onGap);\n}\n"],"mappings":"A,+GAYA,SAAgBe,EAAU,EAA0B,CAGlD,OAAO,MAAM,QAAQC,EAAM,OAAO,GAAKA,EAAM,QAAQ,KAAKhB,EAAAA,CAAc,CAC1E,CAGA,IAAaiB,EAAb,KAA6B,CAYR,QACA,QAXnB,MAA8B,CAAC,EAG/B,MAA8B,CAAC,EAM/B,YACE,EACA,EACA,CAFiB,KAAA,QAAAC,EACA,KAAA,QAAAC,CAChB,CAOH,IAAI,EAAkB,CAOpB,OANK,KAAK,QAAQC,CAAI,EAEX,KAAK,MAAM,OAAS,KAAK,SAClC,KAAK,MAAM,KAAKA,CAAI,EAFpB,KAAK,MAAM,KAAKA,CAAI,EAKf,KAAK,MAAM,OAAS,KAAK,OAClC,CAMA,QAAc,CACZ,MAAO,CAAC,GAAG,KAAK,MAAO,GAAG,KAAK,KAAK,CAAC,CAAC,MAAM,EAAG,KAAK,OAAO,CAC7D,CACF,EASA,SAAgBC,EACd,EACA,EACA,EACK,CACL,IAAMC,EAAO,IAAIL,EAAaC,EAASC,CAAO,EAE9C,IAAK,IAAMC,KAAQG,EACjB,GAAI,CAACD,EAAK,IAAIF,CAAI,EAChB,MAIJ,OAAOE,EAAK,OAAO,CACrB,CC/DA,SAAgBE,EACd,EACA,EACA,EACA,EACa,CAIb,MAHA,GAAO,SAAWC,EAClB,EAAO,SAAWC,EAClB,EAAO,OAASC,EACT,CAAE,UAAS,UAAS,QAAO,CACpC,CASA,SAAgBC,EACd,EACA,EACA,EACA,EACM,CACFC,EAAI,UAAY,IAIpBC,EAAY,OACV,kBACA,uBAAuB,OAAOD,EAAI,OAAO,EAAE,mBAAmB,OAAOA,EAAI,OAAO,EAAE,YAClF,CAAE,GAAGA,CAAI,CACX,EACAE,IAAQF,EAAKG,CAAO,EACtB,CCrBA,SAASC,EAAY,EAAa,EAA+B,CAC/D,IAAMC,EAAQ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IAAA,aAAuCA,IAAa,OAAQ,CAC9D,GAAIH,EAAanC,CAAW,EAAG,CAG7B,IAAMuC,EAAU,MAAMvC,EAAY,WAChC,sBACA,wCACA,SAAY,CACV,GAAM,CAAE,oBAAqB,MAAA,QAAA,QAAA,CAAA,CAAA,SAAA,QAAM,kCAAA,CAAA,EAC7BwC,EAAU,IAAIC,EAAiBC,EAAQjC,EAAQT,EAAaC,CAAK,EAKvE,OADA,MAAMuC,EAAQ,KAAK,EACZA,CACT,CACF,EACA,GAAID,EACF,OAAOA,CAEX,CAEA,GAAID,IAAA,YAKF,OAJAtC,EAAY,OACV,mBACA,sEACF,EACO,IAAI2B,EAAclB,EAAQR,CAAK,CAE1C,CAeA,OAbImC,EAAgBpC,CAAW,EACtB,IAAIQ,EACTC,EACAT,EACAC,EACAgC,EAAY,+BAA+B,mBAAmBA,CAAS,EAAE,SAAW,IAAA,EACtF,GAGFjC,EAAY,OACV,mBACA,2FACF,EACO,IAAI2B,EAAclB,EAAQR,CAAK,EACxC,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"fixed-window-CvESpFYV.cjs","names":["countInWindow","now","windowEnded","window","windowMs","limit"],"sources":["../src/utils/fixed-window.ts"],"sourcesContent":["// src/utils/fixed-window.ts\n//\n// Counts events in a fixed time window. A quiet period adds no allowance. The capture modules and\n// the error ceiling use it to stop a storm of records.\n\n/** State of one fixed window. Counters that share a limit share one object. */\nexport interface StormWindow {\n /** Start of the current window, in epoch milliseconds. */\n start: number;\n /** Events counted in the current window. */\n count: number;\n}\n\n/**\n * Counts one event in a fixed window.\n * @param window Window state to change.\n * @param limit Maximum events in each window.\n * @param windowMs Length of the window, in milliseconds.\n * @returns False when the window has no allowance left. The caller must drop the event.\n */\nexport function countInWindow(window: StormWindow, limit: number, windowMs: number): boolean {\n const now = Date.now();\n\n if (windowEnded(window, windowMs, now)) {\n window.start = now;\n window.count = 0;\n }\n\n window.count++;\n\n return window.count <= limit;\n}\n\n/**\n * Tells if a fixed window has ended. The bus uses the same rule to expire its source entries.\n * @param window Window state.\n * @param windowMs Length of the window, in milliseconds.\n * @param now Current epoch time, in milliseconds.\n * @returns True after the window length, or when the clock moved back. Without the second\n * check, a clock that moves back keeps the window open.\n */\nexport function windowEnded(window: StormWindow, windowMs: number, now: number): boolean {\n return now < window.start || now - window.start > windowMs;\n}\n"],"mappings":"AAoBA,SAAgBA,EAAc,EAAqB,EAAe,EAA2B,CAC3F,IAAMC,EAAM,KAAK,IAAI,EASrB,OAPIC,EAAYC,EAAQC,EAAUH,CAAG,IACnC,EAAO,MAAQA,EACf,EAAO,MAAQ,GAGjB,EAAO,QAEAE,EAAO,OAASE,CACzB,CAUA,SAAgBH,EAAY,EAAqB,EAAkB,EAAsB,CACvF,OAAOD,EAAME,EAAO,OAASF,EAAME,EAAO,MAAQC,CACpD"}
1
+ {"version":3,"file":"fixed-window-CvESpFYV.cjs","names":["countInWindow","now","windowEnded","window","windowMs","limit"],"sources":["../src/utils/fixed-window.ts"],"sourcesContent":["// src/utils/fixed-window.ts\n//\n// Counts events in a fixed time window. A quiet period adds no allowance. The capture modules and\n// the error ceiling use it to stop a storm of records.\n\n/** State of one fixed window. Counters that share a limit share one object. */\nexport interface StormWindow {\n /** Start of the current window, in epoch milliseconds. */\n start: number;\n /** Events counted in the current window. */\n count: number;\n}\n\n/**\n * Counts one event in a fixed window.\n * @param window Window state to change.\n * @param limit Maximum events in each window.\n * @param windowMs Length of the window, in milliseconds.\n * @returns False when the window has no allowance left. The caller must drop the event.\n */\nexport function countInWindow(window: StormWindow, limit: number, windowMs: number): boolean {\n const now = Date.now();\n\n if (windowEnded(window, windowMs, now)) {\n window.start = now;\n window.count = 0;\n }\n\n window.count++;\n\n return window.count <= limit;\n}\n\n/**\n * Tells if a fixed window has ended. The bus uses the same rule to expire its source entries.\n * @param window Window state.\n * @param windowMs Length of the window, in milliseconds.\n * @param now Current epoch time, in milliseconds.\n * @returns True after the window length, or when the clock moved back. Without the second\n * check, a clock that moves back keeps the window open.\n */\nexport function windowEnded(window: StormWindow, windowMs: number, now: number): boolean {\n return now < window.start || now - window.start > windowMs;\n}\n"],"mappings":"AAoBA,SAAgBA,EAAc,EAAqB,EAAe,EAA2B,CAC3F,IAAMC,EAAM,KAAK,IAAI,EASrB,OAPIC,EAAYC,EAAQC,EAAUH,CAAG,IACnC,EAAO,MAAQA,EACf,EAAO,MAAQ,GAGjB,EAAO,QAEAE,EAAO,OAASE,CACzB,CAUA,SAAgBH,EAAY,EAAqB,EAAkB,EAAsB,CACvF,OAAOD,EAAME,EAAO,OAASF,EAAME,EAAO,MAAQC,CACpD,C"}
@@ -1,4 +1,4 @@
1
- //#region src/utils/fixed-window.ts
1
+ // src/utils/fixed-window.ts
2
2
  function e(e, n, r) {
3
3
  let i = Date.now();
4
4
  return t(e, r, i) && (e.start = i, e.count = 0), e.count++, e.count <= n;
@@ -6,7 +6,6 @@ function e(e, n, r) {
6
6
  function t(e, t, n) {
7
7
  return n < e.start || n - e.start > t;
8
8
  }
9
- //#endregion
10
9
  export { t as n, e as t };
11
10
 
12
- //# sourceMappingURL=fixed-window-CtaFHanJ.js.map
11
+ //# sourceMappingURL=fixed-window-Dq3MLUUv.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fixed-window-CtaFHanJ.js","names":["countInWindow","now","windowEnded","window","windowMs","limit"],"sources":["../src/utils/fixed-window.ts"],"sourcesContent":["// src/utils/fixed-window.ts\n//\n// Counts events in a fixed time window. A quiet period adds no allowance. The capture modules and\n// the error ceiling use it to stop a storm of records.\n\n/** State of one fixed window. Counters that share a limit share one object. */\nexport interface StormWindow {\n /** Start of the current window, in epoch milliseconds. */\n start: number;\n /** Events counted in the current window. */\n count: number;\n}\n\n/**\n * Counts one event in a fixed window.\n * @param window Window state to change.\n * @param limit Maximum events in each window.\n * @param windowMs Length of the window, in milliseconds.\n * @returns False when the window has no allowance left. The caller must drop the event.\n */\nexport function countInWindow(window: StormWindow, limit: number, windowMs: number): boolean {\n const now = Date.now();\n\n if (windowEnded(window, windowMs, now)) {\n window.start = now;\n window.count = 0;\n }\n\n window.count++;\n\n return window.count <= limit;\n}\n\n/**\n * Tells if a fixed window has ended. The bus uses the same rule to expire its source entries.\n * @param window Window state.\n * @param windowMs Length of the window, in milliseconds.\n * @param now Current epoch time, in milliseconds.\n * @returns True after the window length, or when the clock moved back. Without the second\n * check, a clock that moves back keeps the window open.\n */\nexport function windowEnded(window: StormWindow, windowMs: number, now: number): boolean {\n return now < window.start || now - window.start > windowMs;\n}\n"],"mappings":";AAoBA,SAAgBA,EAAc,GAAqB,GAAe,GAA2B;CAC3F,IAAMC,IAAM,KAAK,IAAI;CASrB,OAPIC,EAAYC,GAAQC,GAAUH,CAAG,MACnC,EAAO,QAAQA,GACf,EAAO,QAAQ,IAGjB,EAAO,SAEAE,EAAO,SAASE;AACzB;AAUA,SAAgBH,EAAY,GAAqB,GAAkB,GAAsB;CACvF,OAAOD,IAAME,EAAO,SAASF,IAAME,EAAO,QAAQC;AACpD"}
1
+ {"version":3,"file":"fixed-window-Dq3MLUUv.js","names":["countInWindow","now","windowEnded","window","windowMs","limit"],"sources":["../src/utils/fixed-window.ts"],"sourcesContent":["// src/utils/fixed-window.ts\n//\n// Counts events in a fixed time window. A quiet period adds no allowance. The capture modules and\n// the error ceiling use it to stop a storm of records.\n\n/** State of one fixed window. Counters that share a limit share one object. */\nexport interface StormWindow {\n /** Start of the current window, in epoch milliseconds. */\n start: number;\n /** Events counted in the current window. */\n count: number;\n}\n\n/**\n * Counts one event in a fixed window.\n * @param window Window state to change.\n * @param limit Maximum events in each window.\n * @param windowMs Length of the window, in milliseconds.\n * @returns False when the window has no allowance left. The caller must drop the event.\n */\nexport function countInWindow(window: StormWindow, limit: number, windowMs: number): boolean {\n const now = Date.now();\n\n if (windowEnded(window, windowMs, now)) {\n window.start = now;\n window.count = 0;\n }\n\n window.count++;\n\n return window.count <= limit;\n}\n\n/**\n * Tells if a fixed window has ended. The bus uses the same rule to expire its source entries.\n * @param window Window state.\n * @param windowMs Length of the window, in milliseconds.\n * @param now Current epoch time, in milliseconds.\n * @returns True after the window length, or when the clock moved back. Without the second\n * check, a clock that moves back keeps the window open.\n */\nexport function windowEnded(window: StormWindow, windowMs: number, now: number): boolean {\n return now < window.start || now - window.start > windowMs;\n}\n"],"mappings":";AAoBA,SAAgBA,EAAc,GAAqB,GAAe,GAA2B;CAC3F,IAAMC,IAAM,KAAK,IAAI;CASrB,OAPIC,EAAYC,GAAQC,GAAUH,CAAG,MACnC,EAAO,QAAQA,GACf,EAAO,QAAQ,IAGjB,EAAO,SAEAE,EAAO,SAASE;AACzB;AAUA,SAAgBH,EAAY,GAAqB,GAAkB,GAAsB;CACvF,OAAOD,IAAME,EAAO,SAASF,IAAME,EAAO,QAAQC;AACpD"}
@@ -1 +1 @@
1
- {"version":3,"file":"global-scope-BN-Io_yv.cjs","names":["globalScope","symbol","key","store","depth","fn"],"sources":["../src/utils/global-scope.ts"],"sourcesContent":["// src/utils/global-scope.ts\n//\n// Counts open scopes on a global symbol. Two copies of the library on one page then share the\n// count. Without it, one copy captures the requests and the console lines of the other copy.\n\n/** Scope that a function runs inside. */\nexport interface GlobalScope {\n /**\n * Runs a function inside the scope. The scope covers only the synchronous part of the function.\n * @param fn Function to run.\n * @returns The return value of the function.\n */\n run<T>(fn: () => T): T;\n /**\n * Tests if a scope is open.\n * @returns True while a function runs inside the scope.\n */\n open(): boolean;\n}\n\n/**\n * Makes a scope whose count is on a global symbol.\n * @param key Key of the global symbol.\n * @returns The scope.\n */\nexport function globalScope(key: string): GlobalScope {\n const symbol = Symbol.for(key);\n const store = globalThis as unknown as Record<symbol, number | undefined>;\n const depth = (): number => store[symbol] ?? 0;\n\n return {\n run(fn) {\n // A count stays correct when one scope opens inside another.\n store[symbol] = depth() + 1;\n\n try {\n return fn();\n } finally {\n store[symbol] = depth() - 1;\n }\n },\n open: () => depth() > 0,\n };\n}\n"],"mappings":"AAyBA,SAAgBA,EAAY,EAA0B,CACpD,IAAMC,EAAS,OAAO,IAAIC,CAAG,EACvBC,EAAQ,WACRC,MAAsBD,EAAMF,IAAW,EAE7C,MAAO,CACL,IAAI,EAAI,CAEN,EAAMA,GAAUG,EAAM,EAAI,EAE1B,GAAI,CACF,OAAOC,EAAG,CACZ,QAAU,CACR,EAAMJ,GAAUG,EAAM,EAAI,CAC5B,CACF,EACA,SAAYA,EAAM,EAAI,CACxB,CACF"}
1
+ {"version":3,"file":"global-scope-BN-Io_yv.cjs","names":["globalScope","symbol","key","store","depth","fn"],"sources":["../src/utils/global-scope.ts"],"sourcesContent":["// src/utils/global-scope.ts\n//\n// Counts open scopes on a global symbol. Two copies of the library on one page then share the\n// count. Without it, one copy captures the requests and the console lines of the other copy.\n\n/** Scope that a function runs inside. */\nexport interface GlobalScope {\n /**\n * Runs a function inside the scope. The scope covers only the synchronous part of the function.\n * @param fn Function to run.\n * @returns The return value of the function.\n */\n run<T>(fn: () => T): T;\n /**\n * Tests if a scope is open.\n * @returns True while a function runs inside the scope.\n */\n open(): boolean;\n}\n\n/**\n * Makes a scope whose count is on a global symbol.\n * @param key Key of the global symbol.\n * @returns The scope.\n */\nexport function globalScope(key: string): GlobalScope {\n const symbol = Symbol.for(key);\n const store = globalThis as unknown as Record<symbol, number | undefined>;\n const depth = (): number => store[symbol] ?? 0;\n\n return {\n run(fn) {\n // A count stays correct when one scope opens inside another.\n store[symbol] = depth() + 1;\n\n try {\n return fn();\n } finally {\n store[symbol] = depth() - 1;\n }\n },\n open: () => depth() > 0,\n };\n}\n"],"mappings":"AAyBA,SAAgBA,EAAY,EAA0B,CACpD,IAAMC,EAAS,OAAO,IAAIC,CAAG,EACvBC,EAAQ,WACRC,MAAsBD,EAAMF,IAAW,EAE7C,MAAO,CACL,IAAI,EAAI,CAEN,EAAMA,GAAUG,EAAM,EAAI,EAE1B,GAAI,CACF,OAAOC,EAAG,CACZ,QAAU,CACR,EAAMJ,GAAUG,EAAM,EAAI,CAC5B,CACF,EACA,SAAYA,EAAM,EAAI,CACxB,CACF,C"}
@@ -1,4 +1,4 @@
1
- //#region src/utils/global-scope.ts
1
+ // src/utils/global-scope.ts
2
2
  function e(e) {
3
3
  let t = Symbol.for(e), n = globalThis, r = () => n[t] ?? 0;
4
4
  return {
@@ -13,7 +13,6 @@ function e(e) {
13
13
  open: () => r() > 0
14
14
  };
15
15
  }
16
- //#endregion
17
16
  export { e as t };
18
17
 
19
- //# sourceMappingURL=global-scope-dp2jADRl.js.map
18
+ //# sourceMappingURL=global-scope-D9I8s-oN.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"global-scope-dp2jADRl.js","names":["globalScope","symbol","key","store","depth","fn"],"sources":["../src/utils/global-scope.ts"],"sourcesContent":["// src/utils/global-scope.ts\n//\n// Counts open scopes on a global symbol. Two copies of the library on one page then share the\n// count. Without it, one copy captures the requests and the console lines of the other copy.\n\n/** Scope that a function runs inside. */\nexport interface GlobalScope {\n /**\n * Runs a function inside the scope. The scope covers only the synchronous part of the function.\n * @param fn Function to run.\n * @returns The return value of the function.\n */\n run<T>(fn: () => T): T;\n /**\n * Tests if a scope is open.\n * @returns True while a function runs inside the scope.\n */\n open(): boolean;\n}\n\n/**\n * Makes a scope whose count is on a global symbol.\n * @param key Key of the global symbol.\n * @returns The scope.\n */\nexport function globalScope(key: string): GlobalScope {\n const symbol = Symbol.for(key);\n const store = globalThis as unknown as Record<symbol, number | undefined>;\n const depth = (): number => store[symbol] ?? 0;\n\n return {\n run(fn) {\n // A count stays correct when one scope opens inside another.\n store[symbol] = depth() + 1;\n\n try {\n return fn();\n } finally {\n store[symbol] = depth() - 1;\n }\n },\n open: () => depth() > 0,\n };\n}\n"],"mappings":";AAyBA,SAAgBA,EAAY,GAA0B;CACpD,IAAMC,IAAS,OAAO,IAAIC,CAAG,GACvBC,IAAQ,YACRC,UAAsBD,EAAMF,MAAW;CAE7C,OAAO;EACL,IAAI,GAAI;GAEN,EAAMA,KAAUG,EAAM,IAAI;GAE1B,IAAI;IACF,OAAOC,EAAG;GACZ,UAAU;IACR,EAAMJ,KAAUG,EAAM,IAAI;GAC5B;EACF;EACA,YAAYA,EAAM,IAAI;CACxB;AACF"}
1
+ {"version":3,"file":"global-scope-D9I8s-oN.js","names":["globalScope","symbol","key","store","depth","fn"],"sources":["../src/utils/global-scope.ts"],"sourcesContent":["// src/utils/global-scope.ts\n//\n// Counts open scopes on a global symbol. Two copies of the library on one page then share the\n// count. Without it, one copy captures the requests and the console lines of the other copy.\n\n/** Scope that a function runs inside. */\nexport interface GlobalScope {\n /**\n * Runs a function inside the scope. The scope covers only the synchronous part of the function.\n * @param fn Function to run.\n * @returns The return value of the function.\n */\n run<T>(fn: () => T): T;\n /**\n * Tests if a scope is open.\n * @returns True while a function runs inside the scope.\n */\n open(): boolean;\n}\n\n/**\n * Makes a scope whose count is on a global symbol.\n * @param key Key of the global symbol.\n * @returns The scope.\n */\nexport function globalScope(key: string): GlobalScope {\n const symbol = Symbol.for(key);\n const store = globalThis as unknown as Record<symbol, number | undefined>;\n const depth = (): number => store[symbol] ?? 0;\n\n return {\n run(fn) {\n // A count stays correct when one scope opens inside another.\n store[symbol] = depth() + 1;\n\n try {\n return fn();\n } finally {\n store[symbol] = depth() - 1;\n }\n },\n open: () => depth() > 0,\n };\n}\n"],"mappings":";AAyBA,SAAgBA,EAAY,GAA0B;CACpD,IAAMC,IAAS,OAAO,IAAIC,CAAG,GACvBC,IAAQ,YACRC,UAAsBD,EAAMF,MAAW;CAE7C,OAAO;EACL,IAAI,GAAI;GAEN,EAAMA,KAAUG,EAAM,IAAI;GAE1B,IAAI;IACF,OAAOC,EAAG;GACZ,UAAU;IACR,EAAMJ,KAAUG,EAAM,IAAI;GAC5B;EACF;EACA,YAAYA,EAAM,IAAI;CACxB;AACF"}
@@ -1,8 +1,7 @@
1
- //#region src/utils/guards.ts
1
+ // src/utils/guards.ts
2
2
  function e(e) {
3
3
  return typeof e == "object" && !!e && !Array.isArray(e);
4
4
  }
5
- //#endregion
6
5
  export { e as t };
7
6
 
8
- //# sourceMappingURL=guards-CpvOpJL6.js.map
7
+ //# sourceMappingURL=guards-Cidk71ME.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"guards-CpvOpJL6.js","names":["isObject","value"],"sources":["../src/utils/guards.ts"],"sourcesContent":["// src/utils/guards.ts\n//\n// Type guards for values from outside the library, for example config input, a server answer or\n// the payload of a call.\n\n/**\n * Tests if a value is an object that is not null and not an array.\n * @param value Value to test.\n * @returns True for an object with string keys.\n */\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":";AAUA,SAAgBA,EAAS,GAAkD;CACzE,OAAO,OAAOC,KAAU,cAAYA,KAAkB,CAAC,MAAM,QAAQA,CAAK;AAC5E"}
1
+ {"version":3,"file":"guards-Cidk71ME.js","names":["isObject","value"],"sources":["../src/utils/guards.ts"],"sourcesContent":["// src/utils/guards.ts\n//\n// Type guards for values from outside the library, for example config input, a server answer or\n// the payload of a call.\n\n/**\n * Tests if a value is an object that is not null and not an array.\n * @param value Value to test.\n * @returns True for an object with string keys.\n */\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":";AAUA,SAAgBA,EAAS,GAAkD;CACzE,OAAO,OAAOC,KAAU,cAAYA,KAAkB,CAAC,MAAM,QAAQA,CAAK;AAC5E"}
@@ -1 +1 @@
1
- {"version":3,"file":"guards-nJ70syPt.cjs","names":["isObject","value"],"sources":["../src/utils/guards.ts"],"sourcesContent":["// src/utils/guards.ts\n//\n// Type guards for values from outside the library, for example config input, a server answer or\n// the payload of a call.\n\n/**\n * Tests if a value is an object that is not null and not an array.\n * @param value Value to test.\n * @returns True for an object with string keys.\n */\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":"AAUA,SAAgBA,EAAS,EAAkD,CACzE,OAAO,OAAOC,GAAU,YAAYA,GAAkB,CAAC,MAAM,QAAQA,CAAK,CAC5E"}
1
+ {"version":3,"file":"guards-nJ70syPt.cjs","names":["isObject","value"],"sources":["../src/utils/guards.ts"],"sourcesContent":["// src/utils/guards.ts\n//\n// Type guards for values from outside the library, for example config input, a server answer or\n// the payload of a call.\n\n/**\n * Tests if a value is an object that is not null and not an array.\n * @param value Value to test.\n * @returns True for an object with string keys.\n */\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":"AAUA,SAAgBA,EAAS,EAAkD,CACzE,OAAO,OAAOC,GAAU,YAAYA,GAAkB,CAAC,MAAM,QAAQA,CAAK,CAC5E,C"}
@@ -1,2 +1,2 @@
1
- const e=require("./constants-CL0ZdI2f.cjs");var t={local:()=>localStorage,session:()=>sessionStorage};function n(){let e=e=>({getItem:t=>e.get(t)??null,setItem:(t,n)=>{e.set(t,n)},removeItem:t=>{e.delete(t)}}),t=e(new Map),n=e(new Map);return{local:()=>t,session:()=>n}}function r(e){let t=new Uint8Array(e);if(typeof crypto<`u`&&typeof crypto.getRandomValues==`function`)crypto.getRandomValues(t);else for(let n=0;n<e;n++)t[n]=Math.floor(Math.random()*256);return Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}function i(e){try{if(typeof crypto<`u`&&typeof crypto.randomUUID==`function`)return crypto.randomUUID()}catch{e.count(`platform.api_blocked`)}return r(16)}function a(e,t,n,r){return r.guard(`storage.unavailable`,`The library could not read ${t}Storage.`,()=>e[t]().getItem(n))??null}function o(e,t,n,r,i){i.guard(`storage.unavailable`,`The library could not write to ${t}Storage.`,()=>{e[t]().setItem(n,r)})}function s(t,n,r,i){let o=a(t,`local`,e.vn,n);if(o)try{let e=JSON.parse(o);return e.id&&(i===0||r-(e.lastSeenAt??0)<i)?e.id:void 0}catch{n.report(`storage.degraded`,`The session record is not valid JSON. The library starts a new session.`);return}}function c(n,r=t,c=e._n){let l=i(n),u=Date.now(),d=i(n),f=s(r,n,u,c)??d,p=JSON.stringify({id:f,lastSeenAt:u});o(r,`local`,e.vn,p,n);let m=a(r,`session`,`ui-observability.tab`,n)??``;return m||(m=i(n),o(r,`session`,e.An,m,n)),{sessionId:f,tabId:m,contextId:l}}function l(t,n,r){o(r,`session`,e.An,t,n)}var u=class{diagnostics;stores;touchMs;idleMs;lastTouchAt=0;constructor(n,r=t,i=e.yn,a=e._n){this.diagnostics=n,this.stores=r,this.touchMs=i,this.idleMs=a}touch(e){let t=Date.now();if(t-this.lastTouchAt<this.touchMs)return;let n=s(this.stores,this.diagnostics,t,this.idleMs);n!==void 0&&n!==e?this.lastTouchAt=t:this.write(e,t)}stored(){return s(this.stores,this.diagnostics,Date.now(),this.idleMs)}restart(e){this.write(e,Date.now())}write(t,n){this.lastTouchAt=n;let r=JSON.stringify({id:t,lastSeenAt:n});o(this.stores,`local`,e.vn,r,this.diagnostics)}};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
2
- //# sourceMappingURL=identity-BMlKGHUM.cjs.map
1
+ const e=require("./constants-DqKJH_MP.cjs");var t={local:()=>localStorage,session:()=>sessionStorage};function n(){let e=e=>({getItem:t=>e.get(t)??null,setItem:(t,n)=>{e.set(t,n)},removeItem:t=>{e.delete(t)}}),t=e(new Map),n=e(new Map);return{local:()=>t,session:()=>n}}function r(e){let t=new Uint8Array(e);if(typeof crypto<`u`&&typeof crypto.getRandomValues==`function`)crypto.getRandomValues(t);else for(let n=0;n<e;n++)t[n]=Math.floor(Math.random()*256);return Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}function i(e){try{if(typeof crypto<`u`&&typeof crypto.randomUUID==`function`)return crypto.randomUUID()}catch{e.count(`platform.api_blocked`)}return r(16)}function a(e,t,n,r){return r.guard(`storage.unavailable`,`The library could not read ${t}Storage.`,()=>e[t]().getItem(n))??null}function o(e,t,n,r,i){i.guard(`storage.unavailable`,`The library could not write to ${t}Storage.`,()=>{e[t]().setItem(n,r)})}function s(t,n,r,i){let o=a(t,`local`,e.vn,n);if(o)try{let e=JSON.parse(o);return e.id&&(i===0||r-(e.lastSeenAt??0)<i)?e.id:void 0}catch{n.report(`storage.degraded`,`The session record is not valid JSON. The library starts a new session.`);return}}function c(n,r=t,c=e._n){let l=i(n),u=Date.now(),d=i(n),f=s(r,n,u,c)??d,p=JSON.stringify({id:f,lastSeenAt:u});o(r,`local`,e.vn,p,n);let m=a(r,`session`,`ui-observability.tab`,n)??``;return m||(m=i(n),o(r,`session`,e.An,m,n)),{sessionId:f,tabId:m,contextId:l}}function l(t,n,r){o(r,`session`,e.An,t,n)}var u=class{diagnostics;stores;touchMs;idleMs;lastTouchAt=0;constructor(n,r=t,i=e.yn,a=e._n){this.diagnostics=n,this.stores=r,this.touchMs=i,this.idleMs=a}touch(e){let t=Date.now();if(t-this.lastTouchAt<this.touchMs)return;let n=s(this.stores,this.diagnostics,t,this.idleMs);n!==void 0&&n!==e?this.lastTouchAt=t:this.write(e,t)}stored(){return s(this.stores,this.diagnostics,Date.now(),this.idleMs)}restart(e){this.write(e,Date.now())}write(t,n){this.lastTouchAt=n;let r=JSON.stringify({id:t,lastSeenAt:n});o(this.stores,`local`,e.vn,r,this.diagnostics)}};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
2
+ //# sourceMappingURL=identity-Cxgj6pZX.cjs.map