@microsoft/opentelemetry 1.3.0 → 1.5.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 (290) hide show
  1. package/README.md +130 -37
  2. package/dist/commonjs/a365/configuration/A365Configuration.d.ts +3 -0
  3. package/dist/commonjs/a365/configuration/A365Configuration.d.ts.map +1 -1
  4. package/dist/commonjs/a365/configuration/A365Configuration.js +5 -1
  5. package/dist/commonjs/a365/configuration/A365Configuration.js.map +1 -1
  6. package/dist/commonjs/a365/configuration/A365ConfigurationOptions.d.ts +3 -0
  7. package/dist/commonjs/a365/configuration/A365ConfigurationOptions.d.ts.map +1 -1
  8. package/dist/commonjs/a365/constants.d.ts +21 -1
  9. package/dist/commonjs/a365/constants.d.ts.map +1 -1
  10. package/dist/commonjs/a365/constants.js +21 -1
  11. package/dist/commonjs/a365/constants.js.map +1 -1
  12. package/dist/commonjs/a365/contracts.d.ts +53 -2
  13. package/dist/commonjs/a365/contracts.d.ts.map +1 -1
  14. package/dist/commonjs/a365/contracts.js +7 -1
  15. package/dist/commonjs/a365/contracts.js.map +1 -1
  16. package/dist/commonjs/a365/exporter/Agent365Exporter.d.ts +29 -3
  17. package/dist/commonjs/a365/exporter/Agent365Exporter.d.ts.map +1 -1
  18. package/dist/commonjs/a365/exporter/Agent365Exporter.js +327 -73
  19. package/dist/commonjs/a365/exporter/Agent365Exporter.js.map +1 -1
  20. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.d.ts +5 -0
  21. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.d.ts.map +1 -1
  22. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.js +3 -0
  23. package/dist/commonjs/a365/exporter/Agent365ExporterOptions.js.map +1 -1
  24. package/dist/commonjs/a365/exporter/durable/DurableDeliveryManager.d.ts +70 -0
  25. package/dist/commonjs/a365/exporter/durable/DurableDeliveryManager.d.ts.map +1 -0
  26. package/dist/commonjs/a365/exporter/durable/DurableDeliveryManager.js +346 -0
  27. package/dist/commonjs/a365/exporter/durable/DurableDeliveryManager.js.map +1 -0
  28. package/dist/commonjs/a365/exporter/durable/DurableDeliveryOptions.d.ts +31 -0
  29. package/dist/commonjs/a365/exporter/durable/DurableDeliveryOptions.d.ts.map +1 -0
  30. package/dist/commonjs/a365/exporter/durable/DurableDeliveryOptions.js +48 -0
  31. package/dist/commonjs/a365/exporter/durable/DurableDeliveryOptions.js.map +1 -0
  32. package/dist/commonjs/a365/exporter/durable/DurableRecord.d.ts +20 -0
  33. package/dist/commonjs/a365/exporter/durable/DurableRecord.d.ts.map +1 -0
  34. package/dist/commonjs/a365/exporter/durable/DurableRecord.js +98 -0
  35. package/dist/commonjs/a365/exporter/durable/DurableRecord.js.map +1 -0
  36. package/dist/commonjs/a365/exporter/durable/PersistentStore.d.ts +48 -0
  37. package/dist/commonjs/a365/exporter/durable/PersistentStore.d.ts.map +1 -0
  38. package/dist/commonjs/a365/exporter/durable/PersistentStore.js +637 -0
  39. package/dist/commonjs/a365/exporter/durable/PersistentStore.js.map +1 -0
  40. package/dist/commonjs/a365/exporter/durable/TransmissionGate.d.ts +24 -0
  41. package/dist/commonjs/a365/exporter/durable/TransmissionGate.d.ts.map +1 -0
  42. package/dist/commonjs/a365/exporter/durable/TransmissionGate.js +85 -0
  43. package/dist/commonjs/a365/exporter/durable/TransmissionGate.js.map +1 -0
  44. package/dist/commonjs/a365/exporter/durable/WindowsFileAccessControl.d.ts +35 -0
  45. package/dist/commonjs/a365/exporter/durable/WindowsFileAccessControl.d.ts.map +1 -0
  46. package/dist/commonjs/a365/exporter/durable/WindowsFileAccessControl.js +169 -0
  47. package/dist/commonjs/a365/exporter/durable/WindowsFileAccessControl.js.map +1 -0
  48. package/dist/commonjs/a365/exporter/durable/index.d.ts +12 -0
  49. package/dist/commonjs/a365/exporter/durable/index.d.ts.map +1 -0
  50. package/dist/commonjs/a365/exporter/durable/index.js +27 -0
  51. package/dist/commonjs/a365/exporter/durable/index.js.map +1 -0
  52. package/dist/commonjs/a365/exporter/index.d.ts +1 -1
  53. package/dist/commonjs/a365/exporter/index.d.ts.map +1 -1
  54. package/dist/commonjs/a365/exporter/index.js.map +1 -1
  55. package/dist/commonjs/a365/index.d.ts +3 -3
  56. package/dist/commonjs/a365/index.d.ts.map +1 -1
  57. package/dist/commonjs/a365/index.js +7 -2
  58. package/dist/commonjs/a365/index.js.map +1 -1
  59. package/dist/commonjs/a365/message-utils.d.ts +13 -1
  60. package/dist/commonjs/a365/message-utils.d.ts.map +1 -1
  61. package/dist/commonjs/a365/message-utils.js +272 -0
  62. package/dist/commonjs/a365/message-utils.js.map +1 -1
  63. package/dist/commonjs/a365/middleware/BaggageBuilder.d.ts +11 -1
  64. package/dist/commonjs/a365/middleware/BaggageBuilder.d.ts.map +1 -1
  65. package/dist/commonjs/a365/middleware/BaggageBuilder.js +93 -17
  66. package/dist/commonjs/a365/middleware/BaggageBuilder.js.map +1 -1
  67. package/dist/commonjs/a365/processors/A365SpanProcessor.d.ts +1 -0
  68. package/dist/commonjs/a365/processors/A365SpanProcessor.d.ts.map +1 -1
  69. package/dist/commonjs/a365/processors/A365SpanProcessor.js +61 -19
  70. package/dist/commonjs/a365/processors/A365SpanProcessor.js.map +1 -1
  71. package/dist/commonjs/a365/processors/util.d.ts.map +1 -1
  72. package/dist/commonjs/a365/processors/util.js +3 -0
  73. package/dist/commonjs/a365/processors/util.js.map +1 -1
  74. package/dist/commonjs/a365/scopes/ApplyGuardrailScope.d.ts.map +1 -1
  75. package/dist/commonjs/a365/scopes/ApplyGuardrailScope.js +1 -6
  76. package/dist/commonjs/a365/scopes/ApplyGuardrailScope.js.map +1 -1
  77. package/dist/commonjs/a365/scopes/ExecuteToolScope.d.ts +2 -1
  78. package/dist/commonjs/a365/scopes/ExecuteToolScope.d.ts.map +1 -1
  79. package/dist/commonjs/a365/scopes/ExecuteToolScope.js +7 -10
  80. package/dist/commonjs/a365/scopes/ExecuteToolScope.js.map +1 -1
  81. package/dist/commonjs/a365/scopes/InferenceScope.d.ts.map +1 -1
  82. package/dist/commonjs/a365/scopes/InferenceScope.js +1 -5
  83. package/dist/commonjs/a365/scopes/InferenceScope.js.map +1 -1
  84. package/dist/commonjs/a365/scopes/InvokeAgentScope.d.ts +6 -2
  85. package/dist/commonjs/a365/scopes/InvokeAgentScope.d.ts.map +1 -1
  86. package/dist/commonjs/a365/scopes/InvokeAgentScope.js +37 -14
  87. package/dist/commonjs/a365/scopes/InvokeAgentScope.js.map +1 -1
  88. package/dist/commonjs/a365/scopes/OpenTelemetryScope.d.ts +6 -3
  89. package/dist/commonjs/a365/scopes/OpenTelemetryScope.d.ts.map +1 -1
  90. package/dist/commonjs/a365/scopes/OpenTelemetryScope.js +23 -12
  91. package/dist/commonjs/a365/scopes/OpenTelemetryScope.js.map +1 -1
  92. package/dist/commonjs/a365/scopes/OutputScope.d.ts.map +1 -1
  93. package/dist/commonjs/a365/scopes/OutputScope.js +1 -5
  94. package/dist/commonjs/a365/scopes/OutputScope.js.map +1 -1
  95. package/dist/commonjs/a365/tool-call-models.d.ts +149 -0
  96. package/dist/commonjs/a365/tool-call-models.d.ts.map +1 -0
  97. package/dist/commonjs/a365/tool-call-models.js +69 -0
  98. package/dist/commonjs/a365/tool-call-models.js.map +1 -0
  99. package/dist/commonjs/azureMonitor/index.d.ts.map +1 -1
  100. package/dist/commonjs/azureMonitor/index.js +4 -10
  101. package/dist/commonjs/azureMonitor/index.js.map +1 -1
  102. package/dist/commonjs/azureMonitor/logs/handler.d.ts +0 -7
  103. package/dist/commonjs/azureMonitor/logs/handler.d.ts.map +1 -1
  104. package/dist/commonjs/azureMonitor/logs/handler.js +0 -27
  105. package/dist/commonjs/azureMonitor/logs/handler.js.map +1 -1
  106. package/dist/commonjs/azureMonitor/metrics/performanceCounters.d.ts +3 -0
  107. package/dist/commonjs/azureMonitor/metrics/performanceCounters.d.ts.map +1 -1
  108. package/dist/commonjs/azureMonitor/metrics/performanceCounters.js +21 -12
  109. package/dist/commonjs/azureMonitor/metrics/performanceCounters.js.map +1 -1
  110. package/dist/commonjs/azureMonitor/traces/handler.d.ts +2 -9
  111. package/dist/commonjs/azureMonitor/traces/handler.d.ts.map +1 -1
  112. package/dist/commonjs/azureMonitor/traces/handler.js +2 -54
  113. package/dist/commonjs/azureMonitor/traces/handler.js.map +1 -1
  114. package/dist/commonjs/azureMonitor/utils/common.d.ts +29 -0
  115. package/dist/commonjs/azureMonitor/utils/common.d.ts.map +1 -1
  116. package/dist/commonjs/azureMonitor/utils/common.js +55 -0
  117. package/dist/commonjs/azureMonitor/utils/common.js.map +1 -1
  118. package/dist/commonjs/distro/distro.d.ts.map +1 -1
  119. package/dist/commonjs/distro/distro.js +3 -0
  120. package/dist/commonjs/distro/distro.js.map +1 -1
  121. package/dist/commonjs/genai/instrumentations/langchain/tracer.d.ts.map +1 -1
  122. package/dist/commonjs/genai/instrumentations/langchain/tracer.js +1 -0
  123. package/dist/commonjs/genai/instrumentations/langchain/tracer.js.map +1 -1
  124. package/dist/commonjs/genai/instrumentations/langchain/utils.d.ts +1 -0
  125. package/dist/commonjs/genai/instrumentations/langchain/utils.d.ts.map +1 -1
  126. package/dist/commonjs/genai/instrumentations/langchain/utils.js +109 -0
  127. package/dist/commonjs/genai/instrumentations/langchain/utils.js.map +1 -1
  128. package/dist/commonjs/genai/semconv.d.ts +10 -0
  129. package/dist/commonjs/genai/semconv.d.ts.map +1 -1
  130. package/dist/commonjs/genai/semconv.js +11 -1
  131. package/dist/commonjs/genai/semconv.js.map +1 -1
  132. package/dist/commonjs/index.d.ts +5 -4
  133. package/dist/commonjs/index.d.ts.map +1 -1
  134. package/dist/commonjs/index.js +66 -59
  135. package/dist/commonjs/index.js.map +1 -1
  136. package/dist/commonjs/shared/config.d.ts +7 -0
  137. package/dist/commonjs/shared/config.d.ts.map +1 -1
  138. package/dist/commonjs/shared/config.js +19 -3
  139. package/dist/commonjs/shared/config.js.map +1 -1
  140. package/dist/commonjs/types.d.ts +1 -1
  141. package/dist/commonjs/types.js +1 -1
  142. package/dist/commonjs/utils/sdkStats.d.ts +7 -0
  143. package/dist/commonjs/utils/sdkStats.d.ts.map +1 -1
  144. package/dist/commonjs/utils/sdkStats.js +12 -2
  145. package/dist/commonjs/utils/sdkStats.js.map +1 -1
  146. package/dist/esm/a365/configuration/A365Configuration.d.ts +3 -0
  147. package/dist/esm/a365/configuration/A365Configuration.d.ts.map +1 -1
  148. package/dist/esm/a365/configuration/A365Configuration.js +5 -1
  149. package/dist/esm/a365/configuration/A365Configuration.js.map +1 -1
  150. package/dist/esm/a365/configuration/A365ConfigurationOptions.d.ts +3 -0
  151. package/dist/esm/a365/configuration/A365ConfigurationOptions.d.ts.map +1 -1
  152. package/dist/esm/a365/constants.d.ts +21 -1
  153. package/dist/esm/a365/constants.d.ts.map +1 -1
  154. package/dist/esm/a365/constants.js +20 -0
  155. package/dist/esm/a365/constants.js.map +1 -1
  156. package/dist/esm/a365/contracts.d.ts +53 -2
  157. package/dist/esm/a365/contracts.d.ts.map +1 -1
  158. package/dist/esm/a365/contracts.js +1 -0
  159. package/dist/esm/a365/contracts.js.map +1 -1
  160. package/dist/esm/a365/exporter/Agent365Exporter.d.ts +29 -3
  161. package/dist/esm/a365/exporter/Agent365Exporter.d.ts.map +1 -1
  162. package/dist/esm/a365/exporter/Agent365Exporter.js +325 -71
  163. package/dist/esm/a365/exporter/Agent365Exporter.js.map +1 -1
  164. package/dist/esm/a365/exporter/Agent365ExporterOptions.d.ts +5 -0
  165. package/dist/esm/a365/exporter/Agent365ExporterOptions.d.ts.map +1 -1
  166. package/dist/esm/a365/exporter/Agent365ExporterOptions.js +3 -0
  167. package/dist/esm/a365/exporter/Agent365ExporterOptions.js.map +1 -1
  168. package/dist/esm/a365/exporter/durable/DurableDeliveryManager.d.ts +70 -0
  169. package/dist/esm/a365/exporter/durable/DurableDeliveryManager.d.ts.map +1 -0
  170. package/dist/esm/a365/exporter/durable/DurableDeliveryManager.js +342 -0
  171. package/dist/esm/a365/exporter/durable/DurableDeliveryManager.js.map +1 -0
  172. package/dist/esm/a365/exporter/durable/DurableDeliveryOptions.d.ts +31 -0
  173. package/dist/esm/a365/exporter/durable/DurableDeliveryOptions.d.ts.map +1 -0
  174. package/dist/esm/a365/exporter/durable/DurableDeliveryOptions.js +44 -0
  175. package/dist/esm/a365/exporter/durable/DurableDeliveryOptions.js.map +1 -0
  176. package/dist/esm/a365/exporter/durable/DurableRecord.d.ts +20 -0
  177. package/dist/esm/a365/exporter/durable/DurableRecord.d.ts.map +1 -0
  178. package/dist/esm/a365/exporter/durable/DurableRecord.js +93 -0
  179. package/dist/esm/a365/exporter/durable/DurableRecord.js.map +1 -0
  180. package/dist/esm/a365/exporter/durable/PersistentStore.d.ts +48 -0
  181. package/dist/esm/a365/exporter/durable/PersistentStore.d.ts.map +1 -0
  182. package/dist/esm/a365/exporter/durable/PersistentStore.js +599 -0
  183. package/dist/esm/a365/exporter/durable/PersistentStore.js.map +1 -0
  184. package/dist/esm/a365/exporter/durable/TransmissionGate.d.ts +24 -0
  185. package/dist/esm/a365/exporter/durable/TransmissionGate.d.ts.map +1 -0
  186. package/dist/esm/a365/exporter/durable/TransmissionGate.js +80 -0
  187. package/dist/esm/a365/exporter/durable/TransmissionGate.js.map +1 -0
  188. package/dist/esm/a365/exporter/durable/WindowsFileAccessControl.d.ts +35 -0
  189. package/dist/esm/a365/exporter/durable/WindowsFileAccessControl.d.ts.map +1 -0
  190. package/dist/esm/a365/exporter/durable/WindowsFileAccessControl.js +164 -0
  191. package/dist/esm/a365/exporter/durable/WindowsFileAccessControl.js.map +1 -0
  192. package/dist/esm/a365/exporter/durable/index.d.ts +12 -0
  193. package/dist/esm/a365/exporter/durable/index.d.ts.map +1 -0
  194. package/dist/esm/a365/exporter/durable/index.js +9 -0
  195. package/dist/esm/a365/exporter/durable/index.js.map +1 -0
  196. package/dist/esm/a365/exporter/index.d.ts +1 -1
  197. package/dist/esm/a365/exporter/index.d.ts.map +1 -1
  198. package/dist/esm/a365/exporter/index.js.map +1 -1
  199. package/dist/esm/a365/index.d.ts +3 -3
  200. package/dist/esm/a365/index.d.ts.map +1 -1
  201. package/dist/esm/a365/index.js +1 -1
  202. package/dist/esm/a365/index.js.map +1 -1
  203. package/dist/esm/a365/message-utils.d.ts +13 -1
  204. package/dist/esm/a365/message-utils.d.ts.map +1 -1
  205. package/dist/esm/a365/message-utils.js +271 -1
  206. package/dist/esm/a365/message-utils.js.map +1 -1
  207. package/dist/esm/a365/middleware/BaggageBuilder.d.ts +11 -1
  208. package/dist/esm/a365/middleware/BaggageBuilder.d.ts.map +1 -1
  209. package/dist/esm/a365/middleware/BaggageBuilder.js +94 -18
  210. package/dist/esm/a365/middleware/BaggageBuilder.js.map +1 -1
  211. package/dist/esm/a365/processors/A365SpanProcessor.d.ts +1 -0
  212. package/dist/esm/a365/processors/A365SpanProcessor.d.ts.map +1 -1
  213. package/dist/esm/a365/processors/A365SpanProcessor.js +62 -20
  214. package/dist/esm/a365/processors/A365SpanProcessor.js.map +1 -1
  215. package/dist/esm/a365/processors/util.d.ts.map +1 -1
  216. package/dist/esm/a365/processors/util.js +3 -0
  217. package/dist/esm/a365/processors/util.js.map +1 -1
  218. package/dist/esm/a365/scopes/ApplyGuardrailScope.d.ts.map +1 -1
  219. package/dist/esm/a365/scopes/ApplyGuardrailScope.js +1 -6
  220. package/dist/esm/a365/scopes/ApplyGuardrailScope.js.map +1 -1
  221. package/dist/esm/a365/scopes/ExecuteToolScope.d.ts +2 -1
  222. package/dist/esm/a365/scopes/ExecuteToolScope.d.ts.map +1 -1
  223. package/dist/esm/a365/scopes/ExecuteToolScope.js +8 -11
  224. package/dist/esm/a365/scopes/ExecuteToolScope.js.map +1 -1
  225. package/dist/esm/a365/scopes/InferenceScope.d.ts.map +1 -1
  226. package/dist/esm/a365/scopes/InferenceScope.js +1 -5
  227. package/dist/esm/a365/scopes/InferenceScope.js.map +1 -1
  228. package/dist/esm/a365/scopes/InvokeAgentScope.d.ts +6 -2
  229. package/dist/esm/a365/scopes/InvokeAgentScope.d.ts.map +1 -1
  230. package/dist/esm/a365/scopes/InvokeAgentScope.js +37 -14
  231. package/dist/esm/a365/scopes/InvokeAgentScope.js.map +1 -1
  232. package/dist/esm/a365/scopes/OpenTelemetryScope.d.ts +6 -3
  233. package/dist/esm/a365/scopes/OpenTelemetryScope.d.ts.map +1 -1
  234. package/dist/esm/a365/scopes/OpenTelemetryScope.js +23 -12
  235. package/dist/esm/a365/scopes/OpenTelemetryScope.js.map +1 -1
  236. package/dist/esm/a365/scopes/OutputScope.d.ts.map +1 -1
  237. package/dist/esm/a365/scopes/OutputScope.js +1 -5
  238. package/dist/esm/a365/scopes/OutputScope.js.map +1 -1
  239. package/dist/esm/a365/tool-call-models.d.ts +149 -0
  240. package/dist/esm/a365/tool-call-models.d.ts.map +1 -0
  241. package/dist/esm/a365/tool-call-models.js +64 -0
  242. package/dist/esm/a365/tool-call-models.js.map +1 -0
  243. package/dist/esm/azureMonitor/index.d.ts.map +1 -1
  244. package/dist/esm/azureMonitor/index.js +4 -10
  245. package/dist/esm/azureMonitor/index.js.map +1 -1
  246. package/dist/esm/azureMonitor/logs/handler.d.ts +0 -7
  247. package/dist/esm/azureMonitor/logs/handler.d.ts.map +1 -1
  248. package/dist/esm/azureMonitor/logs/handler.js +0 -27
  249. package/dist/esm/azureMonitor/logs/handler.js.map +1 -1
  250. package/dist/esm/azureMonitor/metrics/performanceCounters.d.ts +3 -0
  251. package/dist/esm/azureMonitor/metrics/performanceCounters.d.ts.map +1 -1
  252. package/dist/esm/azureMonitor/metrics/performanceCounters.js +21 -12
  253. package/dist/esm/azureMonitor/metrics/performanceCounters.js.map +1 -1
  254. package/dist/esm/azureMonitor/traces/handler.d.ts +2 -9
  255. package/dist/esm/azureMonitor/traces/handler.d.ts.map +1 -1
  256. package/dist/esm/azureMonitor/traces/handler.js +2 -54
  257. package/dist/esm/azureMonitor/traces/handler.js.map +1 -1
  258. package/dist/esm/azureMonitor/utils/common.d.ts +29 -0
  259. package/dist/esm/azureMonitor/utils/common.d.ts.map +1 -1
  260. package/dist/esm/azureMonitor/utils/common.js +52 -0
  261. package/dist/esm/azureMonitor/utils/common.js.map +1 -1
  262. package/dist/esm/distro/distro.d.ts.map +1 -1
  263. package/dist/esm/distro/distro.js +3 -0
  264. package/dist/esm/distro/distro.js.map +1 -1
  265. package/dist/esm/genai/instrumentations/langchain/tracer.d.ts.map +1 -1
  266. package/dist/esm/genai/instrumentations/langchain/tracer.js +1 -0
  267. package/dist/esm/genai/instrumentations/langchain/tracer.js.map +1 -1
  268. package/dist/esm/genai/instrumentations/langchain/utils.d.ts +1 -0
  269. package/dist/esm/genai/instrumentations/langchain/utils.d.ts.map +1 -1
  270. package/dist/esm/genai/instrumentations/langchain/utils.js +109 -1
  271. package/dist/esm/genai/instrumentations/langchain/utils.js.map +1 -1
  272. package/dist/esm/genai/semconv.d.ts +10 -0
  273. package/dist/esm/genai/semconv.d.ts.map +1 -1
  274. package/dist/esm/genai/semconv.js +10 -0
  275. package/dist/esm/genai/semconv.js.map +1 -1
  276. package/dist/esm/index.d.ts +5 -4
  277. package/dist/esm/index.d.ts.map +1 -1
  278. package/dist/esm/index.js +2 -1
  279. package/dist/esm/index.js.map +1 -1
  280. package/dist/esm/shared/config.d.ts +7 -0
  281. package/dist/esm/shared/config.d.ts.map +1 -1
  282. package/dist/esm/shared/config.js +19 -3
  283. package/dist/esm/shared/config.js.map +1 -1
  284. package/dist/esm/types.d.ts +1 -1
  285. package/dist/esm/types.js +1 -1
  286. package/dist/esm/utils/sdkStats.d.ts +7 -0
  287. package/dist/esm/utils/sdkStats.d.ts.map +1 -1
  288. package/dist/esm/utils/sdkStats.js +12 -2
  289. package/dist/esm/utils/sdkStats.js.map +1 -1
  290. package/package.json +7 -5
@@ -0,0 +1,48 @@
1
+ import type { ILogger } from "../../logging.js";
2
+ import { ResolvedDurableDeliveryOptions } from "./DurableDeliveryOptions.js";
3
+ import { type DurableRecordV1 } from "./DurableRecord.js";
4
+ import { type DirectoryAccessControl } from "./WindowsFileAccessControl.js";
5
+ export interface ClaimedRecord {
6
+ record: DurableRecordV1;
7
+ leasePath: string;
8
+ }
9
+ export interface ClaimBatchOptions {
10
+ /**
11
+ * Record ids to skip during this claim scan. Matching pending records are
12
+ * left in place (released back to pending if already leased for
13
+ * inspection) so callers can exclude records they already determined are
14
+ * temporarily unusable without starving unrelated records that sort later.
15
+ */
16
+ excludeRecordIds?: ReadonlySet<string>;
17
+ }
18
+ export interface PersistentStoreDependencies {
19
+ directoryAccessControl?: DirectoryAccessControl;
20
+ }
21
+ export declare class PersistentStore {
22
+ private readonly root;
23
+ private readonly options;
24
+ private readonly logger;
25
+ private static readonly persistenceQueues;
26
+ private claimQueue;
27
+ private constructor();
28
+ static create(options: ResolvedDurableDeliveryOptions, logger: ILogger, dependencies?: PersistentStoreDependencies): Promise<PersistentStore>;
29
+ persist(record: DurableRecordV1): Promise<string>;
30
+ private persistInternal;
31
+ claimBatch(limit: number, options?: ClaimBatchOptions): Promise<ClaimedRecord[]>;
32
+ complete(claim: ClaimedRecord): Promise<void>;
33
+ release(claim: ClaimedRecord): Promise<void>;
34
+ private quarantinePendingFile;
35
+ private pruneForCapacity;
36
+ private recoverStaleLeases;
37
+ private pendingPath;
38
+ private recoveredPendingPath;
39
+ private leasePath;
40
+ private migratedLeasePath;
41
+ private temporaryPath;
42
+ private readManagedFiles;
43
+ private listManagedFilePaths;
44
+ private withClaimLock;
45
+ private withPersistenceLock;
46
+ }
47
+ export declare function applicationPartition(): string;
48
+ //# sourceMappingURL=PersistentStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersistentStore.d.ts","sourceRoot":"","sources":["../../../../../src/a365/exporter/durable/PersistentStore.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,+BAA+B,CAAC;AAiBvC,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACxC;AAUD,MAAM,WAAW,2BAA2B;IAC1C,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD;AAED,qBAAa,eAAe;IAKxB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IANzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAoC;IAC7E,OAAO,CAAC,UAAU,CAAoC;IAEtD,OAAO;WAMa,MAAM,CACxB,OAAO,EAAE,8BAA8B,EACvC,MAAM,EAAE,OAAO,EACf,YAAY,GAAE,2BAAgC,GAC7C,OAAO,CAAC,eAAe,CAAC;IASpB,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;YAI1C,eAAe;IA8BhB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAsHhF,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAW7C,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;YAW3C,qBAAqB;YAkBrB,gBAAgB;YAsDhB,kBAAkB;IAqChC,OAAO,CAAC,WAAW;YAQL,oBAAoB;IAUlC,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,aAAa;YAOP,gBAAgB;YA2BhB,oBAAoB;YAcpB,aAAa;YAeb,mBAAmB;CAkBlC;AAgID,wBAAgB,oBAAoB,IAAI,MAAM,CAQ7C"}
@@ -0,0 +1,599 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { createHash, randomUUID } from "node:crypto";
4
+ import * as fs from "node:fs/promises";
5
+ import * as os from "node:os";
6
+ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
7
+ import { parseDurableRecord } from "./DurableRecord.js";
8
+ import { WindowsFileAccessControl, } from "./WindowsFileAccessControl.js";
9
+ const OWNER_DIRECTORY_MODE = 0o700;
10
+ const OWNER_FILE_MODE = 0o600;
11
+ const PENDING_SUFFIX = ".pending";
12
+ const QUARANTINE_SUFFIX = ".quarantine";
13
+ const TEMPORARY_SUFFIX = ".tmp";
14
+ // NAME_MAX: the largest single path component most filesystems (ext4, NTFS,
15
+ // APFS, etc.) accept. Renaming a pending file to its lease name appends
16
+ // lease metadata to the basename, so a pending basename that itself fits
17
+ // can still overflow this limit once that metadata is appended.
18
+ const MAX_FILENAME_COMPONENT_BYTES = 255;
19
+ const WINDOWS_PROBE_DIRECTORY = ["Microsoft", "A365", "otel-durable"];
20
+ const POSIX_DEFAULT_LEAF_PREFIX = "a365-otel-durable";
21
+ const APPLICATION_PARTITION_PREFIX = "app-";
22
+ const PROCESS_START_CWD = process.cwd();
23
+ export class PersistentStore {
24
+ root;
25
+ options;
26
+ logger;
27
+ static persistenceQueues = new Map();
28
+ claimQueue = Promise.resolve();
29
+ constructor(root, options, logger) {
30
+ this.root = root;
31
+ this.options = options;
32
+ this.logger = logger;
33
+ }
34
+ static async create(options, logger, dependencies = {}) {
35
+ const root = await resolveStorageRoot(options, logger, resolveDirectoryAccessControl(dependencies.directoryAccessControl));
36
+ return new PersistentStore(root, options, logger);
37
+ }
38
+ persist(record) {
39
+ return this.withPersistenceLock(() => this.persistInternal(record));
40
+ }
41
+ async persistInternal(record) {
42
+ const serialized = JSON.stringify(record);
43
+ const recordBytes = Buffer.byteLength(serialized, "utf8");
44
+ if (recordBytes > this.options.maxStorageBytes) {
45
+ throw new RangeError("Durable record exceeds maxStorageBytes");
46
+ }
47
+ await this.pruneForCapacity(recordBytes);
48
+ const temporaryPath = this.temporaryPath(record);
49
+ const pendingPath = this.pendingPath(record);
50
+ const handle = await fs.open(temporaryPath, "wx", OWNER_FILE_MODE);
51
+ try {
52
+ try {
53
+ await handle.writeFile(serialized, "utf8");
54
+ await handle.sync();
55
+ }
56
+ finally {
57
+ await handle.close();
58
+ }
59
+ await this.pruneForCapacity(0);
60
+ await fs.rename(temporaryPath, pendingPath);
61
+ await syncDirectory(this.root);
62
+ return pendingPath;
63
+ }
64
+ catch (error) {
65
+ await ignoreEnoent(() => fs.unlink(temporaryPath));
66
+ throw error;
67
+ }
68
+ }
69
+ async claimBatch(limit, options) {
70
+ return this.withClaimLock(async () => {
71
+ if (limit <= 0) {
72
+ return [];
73
+ }
74
+ await this.recoverStaleLeases();
75
+ const excludeRecordIds = options?.excludeRecordIds;
76
+ const claims = [];
77
+ const pendingFiles = await this.listManagedFilePaths((name) => name.endsWith(PENDING_SUFFIX));
78
+ pendingFiles.sort();
79
+ for (const pendingPath of pendingFiles) {
80
+ if (claims.length >= limit) {
81
+ break;
82
+ }
83
+ const leasePath = this.leasePath(pendingPath);
84
+ // Preflight before ever attempting the pending -> lease rename:
85
+ // appending lease metadata to an already-near-limit pending
86
+ // basename can push it past the filesystem's per-component name
87
+ // limit, and that failure surfaces inconsistently across platforms
88
+ // (ENAMETOOLONG on POSIX; an unhelpful ENOENT on this Windows/NTFS
89
+ // setup that the benign-race handling below would otherwise
90
+ // swallow silently). Validating basename length and content here,
91
+ // before the rename, guarantees a poison pending file is always
92
+ // quarantined -- deterministically, regardless of OS-specific
93
+ // rename errno behavior -- instead of wedging replay or aborting
94
+ // the batch.
95
+ if (!isSafeLeaseBasename(leasePath)) {
96
+ await this.quarantinePendingFile(pendingPath);
97
+ this.logger.warn("[PersistentStore] Quarantined pending durable record with an oversized basename", { path: pendingPath });
98
+ continue;
99
+ }
100
+ let preflightText;
101
+ try {
102
+ preflightText = await fs.readFile(pendingPath, "utf8");
103
+ }
104
+ catch (error) {
105
+ if (isEnoent(error)) {
106
+ continue;
107
+ }
108
+ throw error;
109
+ }
110
+ try {
111
+ parseDurableRecord(preflightText);
112
+ }
113
+ catch (error) {
114
+ await this.quarantinePendingFile(pendingPath);
115
+ this.logger.warn("[PersistentStore] Quarantined malformed pending durable record", error);
116
+ continue;
117
+ }
118
+ try {
119
+ await fs.rename(pendingPath, leasePath);
120
+ await syncDirectory(this.root);
121
+ }
122
+ catch (error) {
123
+ if (isEnoent(error)) {
124
+ continue;
125
+ }
126
+ if (isEnametoolong(error)) {
127
+ // Defense in depth: the dynamic-length preflight above should
128
+ // make this unreachable, but an OS-specific errno must never be
129
+ // the only guard against aborting the batch.
130
+ await this.quarantinePendingFile(pendingPath);
131
+ this.logger.warn("[PersistentStore] Quarantined pending durable record after an unexpected ENAMETOOLONG", error);
132
+ continue;
133
+ }
134
+ throw error;
135
+ }
136
+ // Re-read and re-parse from the claimed lease path rather than
137
+ // trusting the preflight-parsed content above: the preflight read
138
+ // and this rename are not atomic with each other, so a same-user
139
+ // actor could have replaced the pending file's content in between.
140
+ // The rename is the atomic claim boundary; only content observed
141
+ // after it succeeds is trustworthy.
142
+ let text;
143
+ try {
144
+ text = await fs.readFile(leasePath, "utf8");
145
+ }
146
+ catch (error) {
147
+ if (isEnoent(error)) {
148
+ continue;
149
+ }
150
+ throw error;
151
+ }
152
+ let record;
153
+ try {
154
+ record = parseDurableRecord(text);
155
+ }
156
+ catch (error) {
157
+ await quarantineFile(leasePath);
158
+ this.logger.warn("[PersistentStore] Quarantined malformed durable record", error);
159
+ continue;
160
+ }
161
+ if (excludeRecordIds?.has(record.id)) {
162
+ // Leave this record for a later pass instead of starving records
163
+ // that sort after it: release it back to pending and keep scanning.
164
+ await this.release({ record, leasePath });
165
+ continue;
166
+ }
167
+ claims.push({ record, leasePath });
168
+ }
169
+ return claims;
170
+ });
171
+ }
172
+ async complete(claim) {
173
+ try {
174
+ await fs.unlink(claim.leasePath);
175
+ await syncDirectory(this.root);
176
+ }
177
+ catch (error) {
178
+ if (!isEnoent(error)) {
179
+ throw error;
180
+ }
181
+ }
182
+ }
183
+ async release(claim) {
184
+ try {
185
+ await fs.rename(claim.leasePath, this.pendingPath(claim.record, `release-${randomUUID()}`));
186
+ await syncDirectory(this.root);
187
+ }
188
+ catch (error) {
189
+ if (!isEnoent(error)) {
190
+ throw error;
191
+ }
192
+ }
193
+ }
194
+ async quarantinePendingFile(pendingPath) {
195
+ // The quarantine destination is always a short, fixed-shape name built
196
+ // only from the current timestamp/pid/a fresh UUID -- never derived
197
+ // from the poison file's basename or content -- so it can never exceed
198
+ // filesystem name limits and can never escape this.root, no matter how
199
+ // large or unsafe the source basename/id is. An ENOENT here means
200
+ // another process already claimed or quarantined this exact pending
201
+ // file first, which is a benign race, not a failure.
202
+ try {
203
+ await fs.rename(pendingPath, join(this.root, poisonQuarantineName()));
204
+ await syncDirectory(this.root);
205
+ }
206
+ catch (error) {
207
+ if (!isEnoent(error)) {
208
+ throw error;
209
+ }
210
+ }
211
+ }
212
+ async pruneForCapacity(incomingBytes) {
213
+ const minimumCreatedAt = Date.now() - this.options.maxRecordAgeMilliseconds;
214
+ let files = await this.readManagedFiles();
215
+ let usedBytes = sumBytes(files);
216
+ for (const file of files.sort((left, right) => left.createdAt - right.createdAt)) {
217
+ if (!file.removableWhenExpired || file.createdAt >= minimumCreatedAt) {
218
+ continue;
219
+ }
220
+ if (await unlinkIfExists(file.path)) {
221
+ this.logger.warn("[PersistentStore] Evicted expired durable record", {
222
+ path: file.path,
223
+ bytes: file.size,
224
+ });
225
+ }
226
+ usedBytes -= file.size;
227
+ }
228
+ if (usedBytes + incomingBytes <= this.options.maxStorageBytes) {
229
+ return;
230
+ }
231
+ files = await this.readManagedFiles();
232
+ usedBytes = sumBytes(files);
233
+ for (const file of files.sort((left, right) => left.createdAt - right.createdAt)) {
234
+ if (usedBytes + incomingBytes <= this.options.maxStorageBytes) {
235
+ break;
236
+ }
237
+ if (!file.evictable) {
238
+ continue;
239
+ }
240
+ if (await unlinkIfExists(file.path)) {
241
+ this.logger.warn("[PersistentStore] Evicted durable record for capacity", {
242
+ path: file.path,
243
+ bytes: file.size,
244
+ });
245
+ }
246
+ usedBytes -= file.size;
247
+ }
248
+ if (usedBytes + incomingBytes <= this.options.maxStorageBytes) {
249
+ return;
250
+ }
251
+ const survivingFiles = await this.readManagedFiles();
252
+ if (sumBytes(survivingFiles) + incomingBytes <= this.options.maxStorageBytes) {
253
+ return;
254
+ }
255
+ throw new RangeError("Durable storage capacity is occupied by active durable files");
256
+ }
257
+ async recoverStaleLeases() {
258
+ const now = Date.now();
259
+ const leasePaths = await this.listManagedFilePaths(isActiveLeaseFileName);
260
+ for (const leasePath of leasePaths) {
261
+ const claimedAt = parseLeaseClaimedAt(leasePath);
262
+ if (claimedAt === undefined) {
263
+ const migratedLeasePath = this.migratedLeasePath(leasePath, now);
264
+ try {
265
+ await fs.rename(leasePath, migratedLeasePath);
266
+ await syncDirectory(this.root);
267
+ }
268
+ catch (error) {
269
+ if (isEnoent(error)) {
270
+ continue;
271
+ }
272
+ throw error;
273
+ }
274
+ continue;
275
+ }
276
+ if (now - claimedAt <= this.options.leaseDurationMilliseconds) {
277
+ continue;
278
+ }
279
+ try {
280
+ const recoveredPath = await this.recoveredPendingPath(leasePath);
281
+ await fs.rename(leasePath, recoveredPath);
282
+ await syncDirectory(this.root);
283
+ }
284
+ catch (error) {
285
+ if (isEnoent(error)) {
286
+ continue;
287
+ }
288
+ throw error;
289
+ }
290
+ }
291
+ }
292
+ pendingPath(record, suffix) {
293
+ const baseName = recordBasename(record);
294
+ return join(this.root, suffix ? `${baseName}.${suffix}${PENDING_SUFFIX}` : `${baseName}${PENDING_SUFFIX}`);
295
+ }
296
+ async recoveredPendingPath(leasePath) {
297
+ const text = await fs.readFile(leasePath, "utf8");
298
+ const suffix = `recovered-${randomUUID()}`;
299
+ try {
300
+ return this.pendingPath(parseDurableRecord(text), suffix);
301
+ }
302
+ catch {
303
+ return join(this.root, `${stableRecordBasename(leasePath)}.${suffix}${PENDING_SUFFIX}`);
304
+ }
305
+ }
306
+ leasePath(pendingPath) {
307
+ return pendingPath.replace(/\.pending$/, `.lease-at-${Date.now()}-${process.pid}-${randomUUID()}`);
308
+ }
309
+ migratedLeasePath(leasePath, claimedAt) {
310
+ return join(this.root, `${leasePrefix(leasePath)}.lease-at-${claimedAt}-${process.pid}-${randomUUID()}`);
311
+ }
312
+ temporaryPath(record) {
313
+ return join(this.root, `${Date.now()}-${record.id}.${process.pid}-${randomUUID()}${TEMPORARY_SUFFIX}`);
314
+ }
315
+ async readManagedFiles() {
316
+ const names = await this.listManagedFilePaths(isManagedFileName);
317
+ const files = [];
318
+ for (const fullPath of names) {
319
+ try {
320
+ const stats = await fs.stat(fullPath);
321
+ const name = basename(fullPath);
322
+ const activeLease = isActiveLeaseFileName(name);
323
+ files.push({
324
+ path: fullPath,
325
+ size: stats.size,
326
+ createdAt: parseCreatedAt(fullPath) ?? Math.floor(stats.mtimeMs),
327
+ evictable: isEvictableFileName(name),
328
+ removableWhenExpired: !activeLease,
329
+ });
330
+ }
331
+ catch (error) {
332
+ if (isEnoent(error)) {
333
+ continue;
334
+ }
335
+ throw error;
336
+ }
337
+ }
338
+ return files;
339
+ }
340
+ async listManagedFilePaths(predicate) {
341
+ try {
342
+ const entries = await fs.readdir(this.root, { withFileTypes: true });
343
+ return entries
344
+ .filter((entry) => entry.isFile() && predicate(entry.name))
345
+ .map((entry) => join(this.root, entry.name));
346
+ }
347
+ catch (error) {
348
+ if (isEnoent(error)) {
349
+ return [];
350
+ }
351
+ throw error;
352
+ }
353
+ }
354
+ async withClaimLock(callback) {
355
+ const previous = this.claimQueue;
356
+ let release = () => { };
357
+ this.claimQueue = new Promise((resolve) => {
358
+ release = resolve;
359
+ });
360
+ await previous;
361
+ try {
362
+ return await callback();
363
+ }
364
+ finally {
365
+ release();
366
+ }
367
+ }
368
+ async withPersistenceLock(callback) {
369
+ const previous = PersistentStore.persistenceQueues.get(this.root) ?? Promise.resolve();
370
+ let release = () => { };
371
+ const current = new Promise((resolve) => {
372
+ release = resolve;
373
+ });
374
+ PersistentStore.persistenceQueues.set(this.root, current);
375
+ await previous;
376
+ try {
377
+ return await callback();
378
+ }
379
+ finally {
380
+ release();
381
+ if (PersistentStore.persistenceQueues.get(this.root) === current) {
382
+ PersistentStore.persistenceQueues.delete(this.root);
383
+ }
384
+ }
385
+ }
386
+ }
387
+ async function resolveStorageRoot(options, logger, directoryAccessControl) {
388
+ if (options.storageDirectory !== undefined) {
389
+ return initializeExplicitRoot(options.storageDirectory, directoryAccessControl);
390
+ }
391
+ let lastError;
392
+ for (const candidate of storageRootCandidates()) {
393
+ const root = defaultStorageBaseRoot(candidate);
394
+ try {
395
+ return await initializeDefaultRoot(root, directoryAccessControl);
396
+ }
397
+ catch (error) {
398
+ lastError = error;
399
+ logger.warn("[PersistentStore] Durable storage candidate unavailable", partitionedStorageRoot(root), error);
400
+ }
401
+ }
402
+ if (lastError instanceof Error) {
403
+ throw lastError;
404
+ }
405
+ throw new Error("Unable to initialize durable storage root");
406
+ }
407
+ async function initializeRoot(root, recursive = true, directoryAccessControl) {
408
+ try {
409
+ await fs.mkdir(root, { recursive, mode: OWNER_DIRECTORY_MODE });
410
+ }
411
+ catch (error) {
412
+ if (error.code !== "EEXIST") {
413
+ throw error;
414
+ }
415
+ }
416
+ return verifyRoot(root, directoryAccessControl);
417
+ }
418
+ async function initializeExplicitRoot(root, directoryAccessControl) {
419
+ const baseRoot = await initializeRoot(root, true, directoryAccessControl);
420
+ return initializeRoot(partitionedStorageRoot(baseRoot), false, directoryAccessControl);
421
+ }
422
+ async function initializeDefaultRoot(root, directoryAccessControl) {
423
+ const baseRoot = await initializeRoot(root, process.platform === "win32", directoryAccessControl);
424
+ return initializeRoot(partitionedStorageRoot(baseRoot), false, directoryAccessControl);
425
+ }
426
+ async function verifyRoot(root, directoryAccessControl) {
427
+ let stats = await fs.lstat(root);
428
+ if (stats.isSymbolicLink() || !stats.isDirectory()) {
429
+ throw new Error(`Durable storage root must be a real directory: ${root}`);
430
+ }
431
+ if (process.platform === "win32") {
432
+ await directoryAccessControl?.hardenDirectory(root);
433
+ stats = await fs.lstat(root);
434
+ if (stats.isSymbolicLink() || !stats.isDirectory()) {
435
+ throw new Error(`Durable storage root must be a real directory: ${root}`);
436
+ }
437
+ }
438
+ else {
439
+ const uid = process.getuid?.();
440
+ if (uid !== undefined && stats.uid !== uid) {
441
+ throw new Error(`Durable storage root must be owned by the current user: ${root}`);
442
+ }
443
+ await fs.chmod(root, OWNER_DIRECTORY_MODE);
444
+ stats = await fs.lstat(root);
445
+ if (stats.isSymbolicLink() ||
446
+ !stats.isDirectory() ||
447
+ (uid !== undefined && stats.uid !== uid)) {
448
+ throw new Error(`Durable storage root must be a real directory owned by the current user: ${root}`);
449
+ }
450
+ }
451
+ await probeRoot(root);
452
+ return root;
453
+ }
454
+ let defaultDirectoryAccessControl;
455
+ function resolveDirectoryAccessControl(directoryAccessControl) {
456
+ if (directoryAccessControl !== undefined) {
457
+ return directoryAccessControl;
458
+ }
459
+ if (process.platform !== "win32") {
460
+ return undefined;
461
+ }
462
+ defaultDirectoryAccessControl ??= new WindowsFileAccessControl();
463
+ return defaultDirectoryAccessControl;
464
+ }
465
+ function defaultStorageBaseRoot(candidate) {
466
+ if (process.platform === "win32") {
467
+ return join(candidate, ...WINDOWS_PROBE_DIRECTORY);
468
+ }
469
+ return join(candidate, `${POSIX_DEFAULT_LEAF_PREFIX}-${process.getuid?.() ?? "unknown"}`);
470
+ }
471
+ export function applicationPartition() {
472
+ const identity = [
473
+ process.getuid?.() ?? "unknown",
474
+ process.execPath,
475
+ stableApplicationIdentityBase(),
476
+ ].join("\0");
477
+ const partition = createHash("sha256").update(identity).digest("hex").slice(0, 16);
478
+ return `${APPLICATION_PARTITION_PREFIX}${partition}`;
479
+ }
480
+ function stableApplicationIdentityBase() {
481
+ const entryPoint = process.argv[1];
482
+ if (typeof entryPoint === "string" && entryPoint.length > 0) {
483
+ return isAbsolute(entryPoint) ? entryPoint : resolve(PROCESS_START_CWD, entryPoint);
484
+ }
485
+ return PROCESS_START_CWD;
486
+ }
487
+ function partitionedStorageRoot(root) {
488
+ return join(root, applicationPartition());
489
+ }
490
+ function storageRootCandidates() {
491
+ const candidates = process.platform === "win32"
492
+ ? [process.env.LOCALAPPDATA, process.env.TEMP, os.tmpdir()]
493
+ : [process.env.TMPDIR, "/var/tmp", "/tmp"];
494
+ return [...new Set(candidates.filter(isNonEmptyString))];
495
+ }
496
+ function isNonEmptyString(value) {
497
+ return typeof value === "string" && value.length > 0;
498
+ }
499
+ async function probeRoot(root) {
500
+ const probePath = join(root, `.probe-${process.pid}-${randomUUID()}`);
501
+ const handle = await fs.open(probePath, "wx", OWNER_FILE_MODE);
502
+ try {
503
+ await handle.writeFile("probe", "utf8");
504
+ await handle.sync();
505
+ }
506
+ finally {
507
+ await handle.close();
508
+ }
509
+ await fs.unlink(probePath);
510
+ await syncDirectory(root);
511
+ }
512
+ async function quarantineFile(path) {
513
+ await fs.rename(path, join(dirname(path), `${leasePrefix(path)}${QUARANTINE_SUFFIX}`));
514
+ await syncDirectory(dirname(path));
515
+ }
516
+ async function syncDirectory(root) {
517
+ if (process.platform === "win32") {
518
+ return;
519
+ }
520
+ const handle = await fs.open(root, "r");
521
+ try {
522
+ await handle.sync();
523
+ }
524
+ finally {
525
+ await handle.close();
526
+ }
527
+ }
528
+ function parseCreatedAt(path) {
529
+ const match = /^(\d+)-/.exec(basename(path));
530
+ if (!match) {
531
+ return undefined;
532
+ }
533
+ const createdAt = Number.parseInt(match[1], 10);
534
+ return Number.isFinite(createdAt) ? createdAt : undefined;
535
+ }
536
+ function leasePrefix(path) {
537
+ return basename(path).split(".lease-")[0];
538
+ }
539
+ function recordBasename(record) {
540
+ return `${record.createdAt}-${record.id}`;
541
+ }
542
+ function stableRecordBasename(path) {
543
+ return leasePrefix(path).split(".")[0];
544
+ }
545
+ function parseLeaseClaimedAt(path) {
546
+ const match = /\.lease-at-(\d+)-\d+-[^.]+$/.exec(basename(path));
547
+ if (!match) {
548
+ return undefined;
549
+ }
550
+ const claimedAt = Number.parseInt(match[1], 10);
551
+ return Number.isFinite(claimedAt) ? claimedAt : undefined;
552
+ }
553
+ function isActiveLeaseFileName(name) {
554
+ return /\.lease-[^.]+$/.test(name);
555
+ }
556
+ function isEvictableFileName(name) {
557
+ return name.endsWith(PENDING_SUFFIX) || name.endsWith(QUARANTINE_SUFFIX);
558
+ }
559
+ function isManagedFileName(name) {
560
+ return (isEvictableFileName(name) || name.endsWith(TEMPORARY_SUFFIX) || isActiveLeaseFileName(name));
561
+ }
562
+ function isEnoent(error) {
563
+ return error.code === "ENOENT";
564
+ }
565
+ function isEnametoolong(error) {
566
+ return error.code === "ENAMETOOLONG";
567
+ }
568
+ function isSafeLeaseBasename(candidateLeasePath) {
569
+ return Buffer.byteLength(basename(candidateLeasePath), "utf8") <= MAX_FILENAME_COMPONENT_BYTES;
570
+ }
571
+ function poisonQuarantineName() {
572
+ return `${Date.now()}-quarantined-${process.pid}-${randomUUID()}${QUARANTINE_SUFFIX}`;
573
+ }
574
+ async function unlinkIfExists(path) {
575
+ try {
576
+ await fs.unlink(path);
577
+ return true;
578
+ }
579
+ catch (error) {
580
+ if (isEnoent(error)) {
581
+ return false;
582
+ }
583
+ throw error;
584
+ }
585
+ }
586
+ async function ignoreEnoent(action) {
587
+ try {
588
+ await action();
589
+ }
590
+ catch (error) {
591
+ if (!isEnoent(error)) {
592
+ throw error;
593
+ }
594
+ }
595
+ }
596
+ function sumBytes(files) {
597
+ return files.reduce((total, file) => total + file.size, 0);
598
+ }
599
+ //# sourceMappingURL=PersistentStore.js.map