sandforge 1.83.0 → 1.84.1

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 (254) hide show
  1. package/README.md +1 -1
  2. package/lib/chunk-23SEDORH.mjs +11 -0
  3. package/lib/{chunk-I5C4O3VA.mjs → chunk-24RFOFYT.mjs} +1 -1
  4. package/lib/chunk-26POJDIT.mjs +7 -0
  5. package/lib/{chunk-WJAZ5LHL.mjs → chunk-2AZQHBEF.mjs} +1 -1
  6. package/lib/{chunk-IHGYJZZ2.mjs → chunk-2HVOZUM4.mjs} +1 -1
  7. package/lib/{chunk-3V4YH5KO.mjs → chunk-2JDAOWUW.mjs} +1 -1
  8. package/lib/{chunk-BNKT3R3F.mjs → chunk-2METQHGG.mjs} +1 -1
  9. package/lib/chunk-2WFIVO4F.mjs +13 -0
  10. package/lib/chunk-2YHZBUZE.mjs +7 -0
  11. package/lib/{chunk-7DPHZWA4.mjs → chunk-326AJTIU.mjs} +14 -14
  12. package/lib/{chunk-UIR77ZJD.mjs → chunk-36JOHEJL.mjs} +1 -1
  13. package/lib/chunk-3PVRGTVK.mjs +7 -0
  14. package/lib/{chunk-2WMKJVD2.mjs → chunk-3Q353S2R.mjs} +1 -1
  15. package/lib/chunk-3TZSBHEY.mjs +7 -0
  16. package/lib/{chunk-T36DZJPH.mjs → chunk-43TOMFV4.mjs} +1 -1
  17. package/lib/{chunk-XAMMIPZ4.mjs → chunk-4CVUUVGJ.mjs} +1 -1
  18. package/lib/{chunk-6YC2ELCU.mjs → chunk-4EOHEDFP.mjs} +1 -1
  19. package/lib/{chunk-ZB5E7NHU.mjs → chunk-4JE4BYXK.mjs} +1 -1
  20. package/lib/{chunk-JREKJO3D.mjs → chunk-54WZUS7J.mjs} +1 -1
  21. package/lib/{chunk-CGZGL6VT.mjs → chunk-5CRLRHOJ.mjs} +1 -1
  22. package/lib/{chunk-UOHZW2L4.mjs → chunk-5IZTFMJM.mjs} +1 -1
  23. package/lib/{chunk-6VOQFISN.mjs → chunk-5M5FQ7RP.mjs} +1 -1
  24. package/lib/{chunk-U4YFYSF3.mjs → chunk-5SMWFNE7.mjs} +1 -1
  25. package/lib/{chunk-HQZUQXDC.mjs → chunk-5XTUSN72.mjs} +1 -1
  26. package/lib/chunk-6I6TWNV5.mjs +7 -0
  27. package/lib/{chunk-QLRWU3MB.mjs → chunk-6JWWSDM6.mjs} +1 -1
  28. package/lib/chunk-6O222PW6.mjs +7 -0
  29. package/lib/{chunk-J3TIHLWG.mjs → chunk-6PD6K7LP.mjs} +1 -1
  30. package/lib/{chunk-ISAUCWYK.mjs → chunk-6QE6R6RL.mjs} +1 -1
  31. package/lib/{chunk-2KTGDYUH.mjs → chunk-6WX5ZU7Q.mjs} +1 -1
  32. package/lib/{chunk-XAUQXYPW.mjs → chunk-6YL7BNYD.mjs} +1 -1
  33. package/lib/chunk-6ZLKIT3H.mjs +7 -0
  34. package/lib/{chunk-XKFHTBAB.mjs → chunk-7QYHEHMA.mjs} +1 -1
  35. package/lib/chunk-7SQSWVAU.mjs +9 -0
  36. package/lib/{chunk-NNV7IGM7.mjs → chunk-7UVKIWKV.mjs} +1 -1
  37. package/lib/{chunk-RZKJQOOC.mjs → chunk-7WATA4SB.mjs} +1 -1
  38. package/lib/{chunk-DMT5SCO3.mjs → chunk-7YNM6KFZ.mjs} +1 -1
  39. package/lib/{chunk-TMIESDE5.mjs → chunk-A3MYSOOC.mjs} +1 -1
  40. package/lib/chunk-AL4C3GFT.mjs +7 -0
  41. package/lib/chunk-B3FBHVNN.mjs +21 -0
  42. package/lib/{chunk-CDWZGQAJ.mjs → chunk-B63POIPQ.mjs} +1 -1
  43. package/lib/{chunk-YEVB7LVK.mjs → chunk-BAWCOKRW.mjs} +1 -1
  44. package/lib/{chunk-FVLFO2S6.mjs → chunk-BBRWFKS5.mjs} +1 -1
  45. package/lib/chunk-BEA27DLS.mjs +7 -0
  46. package/lib/chunk-BRY3PLIZ.mjs +7 -0
  47. package/lib/chunk-CBH3TOWK.mjs +341 -0
  48. package/lib/{chunk-7V2UYZ6S.mjs → chunk-CPQIZGG5.mjs} +1 -1
  49. package/lib/chunk-CVHNXJH3.mjs +7 -0
  50. package/lib/{chunk-ZOSESZ22.mjs → chunk-D4GF4FAB.mjs} +1 -1
  51. package/lib/chunk-DGDRQRCW.mjs +7 -0
  52. package/lib/{chunk-2N73W63D.mjs → chunk-DPMRIMUC.mjs} +1 -1
  53. package/lib/chunk-DUN2EPRC.mjs +7 -0
  54. package/lib/chunk-E3A3LOCY.mjs +7 -0
  55. package/lib/{chunk-KWAVSZ2B.mjs → chunk-EAC5QCE3.mjs} +1 -1
  56. package/lib/{chunk-JUOQUG7U.mjs → chunk-EC72TIEG.mjs} +1 -1
  57. package/lib/chunk-EPFCERGL.mjs +7 -0
  58. package/lib/{chunk-6KOUYHEY.mjs → chunk-ETDCBLGU.mjs} +1 -1
  59. package/lib/{chunk-2R6GFNKF.mjs → chunk-F3AQW6IU.mjs} +1 -1
  60. package/lib/{chunk-AHUGG3WU.mjs → chunk-FITPY3L4.mjs} +1 -1
  61. package/lib/chunk-FNJ4SGWO.mjs +7 -0
  62. package/lib/{chunk-EOQON3E5.mjs → chunk-FP7CYB2F.mjs} +1 -1
  63. package/lib/{chunk-262TP6UU.mjs → chunk-GKY2JMHY.mjs} +1 -1
  64. package/lib/{chunk-JBWJ6UEZ.mjs → chunk-GMIGWR6U.mjs} +1 -1
  65. package/lib/{chunk-OS5GE52G.mjs → chunk-GNRSF65U.mjs} +1 -1
  66. package/lib/chunk-GOOVPVWX.mjs +7 -0
  67. package/lib/{chunk-DB5RVDC5.mjs → chunk-GWZRR3MM.mjs} +1 -1
  68. package/lib/{chunk-SX6QWYCQ.mjs → chunk-H2BHESDA.mjs} +2 -2
  69. package/lib/chunk-H4CGM6YO.mjs +7 -0
  70. package/lib/{chunk-NFEBX75O.mjs → chunk-HCGXK7G7.mjs} +1 -1
  71. package/lib/{chunk-4X5D3MSV.mjs → chunk-HIDW7FNV.mjs} +1 -1
  72. package/lib/chunk-HSBXRQTI.mjs +7 -0
  73. package/lib/chunk-HUZPBE47.mjs +7 -0
  74. package/lib/{chunk-F5SBGJWW.mjs → chunk-HV7VPEXP.mjs} +1 -1
  75. package/lib/chunk-I6E6T6YY.mjs +7 -0
  76. package/lib/chunk-IUM4NFKI.mjs +10 -0
  77. package/lib/chunk-IVFVNNGB.mjs +37 -0
  78. package/lib/{chunk-L4MSL4U7.mjs → chunk-IZGCEOYO.mjs} +1 -1
  79. package/lib/{chunk-E3RQ575Y.mjs → chunk-J3DND3BC.mjs} +1 -1
  80. package/lib/{chunk-MJD6CPZZ.mjs → chunk-JAEDM4SI.mjs} +1 -1
  81. package/lib/chunk-JCFBFF4Y.mjs +7 -0
  82. package/lib/{chunk-U2CTKIPE.mjs → chunk-JE6SCT6R.mjs} +1 -1
  83. package/lib/{chunk-XJICAOAQ.mjs → chunk-JGZPD4IM.mjs} +1 -1
  84. package/lib/{chunk-XCJUNX63.mjs → chunk-JKJ74BX5.mjs} +1 -1
  85. package/lib/{chunk-WAYQLQAD.mjs → chunk-JLSIWO4Z.mjs} +1 -1
  86. package/lib/{chunk-D7XUNWWU.mjs → chunk-JSAJS3MY.mjs} +1 -1
  87. package/lib/chunk-JTJK2D36.mjs +7 -0
  88. package/lib/{chunk-OTJH6AEA.mjs → chunk-KAZS5Z6W.mjs} +1 -1
  89. package/lib/chunk-KB4ZHM4Q.mjs +10 -0
  90. package/lib/{chunk-N2HYG3BL.mjs → chunk-KGU4SVIT.mjs} +1 -1
  91. package/lib/{chunk-FKCIGJOI.mjs → chunk-KJWFYBMU.mjs} +2 -2
  92. package/lib/{chunk-KXUOHACP.mjs → chunk-KZTZDC7H.mjs} +1 -1
  93. package/lib/{chunk-S4PRKKGC.mjs → chunk-L2E5WBGD.mjs} +1 -1
  94. package/lib/{chunk-X2XZQ434.mjs → chunk-L53JWJ3S.mjs} +1 -1
  95. package/lib/{chunk-CQAFVEKP.mjs → chunk-LA4KIATH.mjs} +6 -6
  96. package/lib/chunk-LC3NDW4N.mjs +7 -0
  97. package/lib/{chunk-4V3QO7HF.mjs → chunk-LKTNQEBS.mjs} +1 -1
  98. package/lib/chunk-M2ABR4JM.mjs +7 -0
  99. package/lib/{chunk-3CM7LAPE.mjs → chunk-M4BLK6HJ.mjs} +1 -1
  100. package/lib/{chunk-Z3MGN42K.mjs → chunk-M6K34KGF.mjs} +1 -1
  101. package/lib/{chunk-TUPZY2QJ.mjs → chunk-MDMPJEV3.mjs} +1 -1
  102. package/lib/{chunk-BVZ5H3N4.mjs → chunk-MJZU3U5O.mjs} +68 -63
  103. package/lib/{chunk-OUU47Y7A.mjs → chunk-MSIEU5MR.mjs} +1 -1
  104. package/lib/{chunk-QQDZQCO2.mjs → chunk-N4WPCWJO.mjs} +1 -1
  105. package/lib/{chunk-MTM4KG3T.mjs → chunk-NCZKWSC7.mjs} +1 -1
  106. package/lib/{chunk-Y7YUNRKK.mjs → chunk-NED4MBIM.mjs} +1 -1
  107. package/lib/{chunk-QKJXIY6L.mjs → chunk-NOBQTEQD.mjs} +1 -1
  108. package/lib/{chunk-WBELLGNE.mjs → chunk-NSQWI7ZY.mjs} +1 -1
  109. package/lib/{chunk-BPHTA6KP.mjs → chunk-O677VOGO.mjs} +1 -1
  110. package/lib/chunk-OFTT7J2M.mjs +7 -0
  111. package/lib/{chunk-JH4ZTVQN.mjs → chunk-OLCVHL7I.mjs} +1 -1
  112. package/lib/chunk-OM5NORJG.mjs +7 -0
  113. package/lib/{chunk-QP3JLFIO.mjs → chunk-OMNMLKDT.mjs} +1 -1
  114. package/lib/{chunk-WABXKL4N.mjs → chunk-OPMO6I45.mjs} +1 -1
  115. package/lib/{chunk-7ZBDACVG.mjs → chunk-OUZQPYT3.mjs} +1 -1
  116. package/lib/chunk-OVNMB6Q2.mjs +7 -0
  117. package/lib/{chunk-DKDKCGXV.mjs → chunk-PAXNWTYK.mjs} +1 -1
  118. package/lib/{chunk-GLN4PI5P.mjs → chunk-PBY2O6OF.mjs} +1 -1
  119. package/lib/chunk-PEDQPM2P.mjs +926 -0
  120. package/lib/chunk-PH7SP4YK.mjs +21 -0
  121. package/lib/{chunk-BT43WSOS.mjs → chunk-PMN4PAC3.mjs} +1 -1
  122. package/lib/chunk-PMWAFDUB.mjs +48 -0
  123. package/lib/chunk-PPLVFX6N.mjs +7 -0
  124. package/lib/{chunk-L3I6DAHX.mjs → chunk-PR3XCSPO.mjs} +1 -1
  125. package/lib/{chunk-WZN36ACK.mjs → chunk-PR42EZSR.mjs} +1 -1
  126. package/lib/{chunk-NDFFIJL5.mjs → chunk-PWRJRL5U.mjs} +1 -1
  127. package/lib/{chunk-NS6ONPWL.mjs → chunk-Q7GIJBCD.mjs} +1 -1
  128. package/lib/chunk-Q7TLC3I2.mjs +7 -0
  129. package/lib/{chunk-ALBY5SOH.mjs → chunk-QAFPQ3YB.mjs} +1 -1
  130. package/lib/{chunk-KKS2KFBT.mjs → chunk-QKEKG2LD.mjs} +1 -1
  131. package/lib/{chunk-OOIDCHBQ.mjs → chunk-QO53K5W2.mjs} +2 -2
  132. package/lib/{chunk-HVX2AFYW.mjs → chunk-QTG6LUZT.mjs} +1 -1
  133. package/lib/{chunk-K7G3W7XH.mjs → chunk-RE7RYF3B.mjs} +1 -1
  134. package/lib/{chunk-JIPT5FUD.mjs → chunk-RGBGUCJA.mjs} +1 -1
  135. package/lib/{chunk-GT5ZKU6V.mjs → chunk-RGUQOSBU.mjs} +1 -1
  136. package/lib/{chunk-VXZ5PTOM.mjs → chunk-RHNTHGNU.mjs} +1 -1
  137. package/lib/chunk-RKTFFCNS.mjs +7 -0
  138. package/lib/chunk-RMFU4BAL.mjs +28 -0
  139. package/lib/{chunk-DNQKVCUV.mjs → chunk-ROV3QXEF.mjs} +11 -11
  140. package/lib/chunk-RT47RKLY.mjs +7 -0
  141. package/lib/{chunk-ISOSTAJR.mjs → chunk-S42RBRH2.mjs} +1 -1
  142. package/lib/{chunk-27BBEGUD.mjs → chunk-SI267LYR.mjs} +1 -1
  143. package/lib/chunk-T3G6VZNS.mjs +7 -0
  144. package/lib/chunk-TNT27RBG.mjs +7 -0
  145. package/lib/chunk-UBIKR5VO.mjs +7 -0
  146. package/lib/chunk-UI3JQVRU.mjs +8 -0
  147. package/lib/{chunk-RVCPQVKM.mjs → chunk-UIOMAX56.mjs} +1 -1
  148. package/lib/chunk-UX3BVH2Y.mjs +7 -0
  149. package/lib/{chunk-L4RJX7DG.mjs → chunk-VCUXCK36.mjs} +1 -1
  150. package/lib/chunk-VINGECAJ.mjs +10 -0
  151. package/lib/chunk-VOXJHJIE.mjs +7 -0
  152. package/lib/chunk-W6PN6TJG.mjs +7 -0
  153. package/lib/{chunk-D6JT4PAB.mjs → chunk-WAPSSYMT.mjs} +1 -1
  154. package/lib/{chunk-7BQMBXKX.mjs → chunk-WUUKFE2U.mjs} +1 -1
  155. package/lib/chunk-WWTCWWZI.mjs +7 -0
  156. package/lib/chunk-WXDLQT2O.mjs +10 -0
  157. package/lib/{chunk-TCEXCHXR.mjs → chunk-WY5V5PR3.mjs} +1 -1
  158. package/lib/chunk-X4BXESMQ.mjs +7 -0
  159. package/lib/chunk-XBQGZGWR.mjs +7 -0
  160. package/lib/{chunk-AXFD2OH6.mjs → chunk-XGGOUNPP.mjs} +1 -1
  161. package/lib/chunk-XKWW3GKF.mjs +7 -0
  162. package/lib/{chunk-PDRXM5WN.mjs → chunk-Y2DRK37K.mjs} +1 -1
  163. package/lib/{chunk-ZXOUWHYE.mjs → chunk-YA6ATMTB.mjs} +1 -1
  164. package/lib/{chunk-54HYHHVL.mjs → chunk-YDXMTWAT.mjs} +1 -1
  165. package/lib/chunk-YHR4WQPR.mjs +7 -0
  166. package/lib/{chunk-LWES2KZE.mjs → chunk-YTLUYSMF.mjs} +1 -1
  167. package/lib/{chunk-2K5BYZQM.mjs → chunk-YWEQQL3C.mjs} +1 -1
  168. package/lib/{chunk-C6RKM4BB.mjs → chunk-Z4LKKOFY.mjs} +1 -1
  169. package/lib/chunk-ZBAWJUG2.mjs +7 -0
  170. package/lib/{chunk-446GBKAC.mjs → chunk-ZJW6YOMV.mjs} +1 -1
  171. package/lib/chunk-ZQQXSCVI.mjs +7 -0
  172. package/lib/{chunk-L6CLN664.mjs → chunk-ZQWIVYVM.mjs} +1 -1
  173. package/lib/{chunk-CXKZ6TYV.mjs → chunk-ZV7ZFQQC.mjs} +1 -1
  174. package/lib/sandforge-autopilot.mjs +25 -25
  175. package/lib/sandforge-backup.mjs +1 -1
  176. package/lib/sandforge-checkpoint.mjs +1 -1
  177. package/lib/sandforge-cleanup.mjs +1 -1
  178. package/lib/sandforge-clone.mjs +1 -1
  179. package/lib/sandforge-compare.mjs +52 -21
  180. package/lib/sandforge-dataops.mjs +1 -1
  181. package/lib/sandforge-empty.mjs +1 -1
  182. package/lib/sandforge-env.mjs +95 -95
  183. package/lib/sandforge-frozen.mjs +1 -1
  184. package/lib/sandforge-mcp.mjs +12 -12
  185. package/lib/sandforge-monitor.mjs +1 -1
  186. package/lib/sandforge-pipeline.mjs +1 -1
  187. package/lib/sandforge-seed.mjs +1 -1
  188. package/lib/sandforge-sync.mjs +1 -1
  189. package/lib/sandforge-users.mjs +1 -1
  190. package/lib/sandforge.mjs +1 -1
  191. package/lib/sf/sandforge/compare.mjs +2 -2
  192. package/lib/sfPlugin.mjs +1 -1
  193. package/oclif.manifest.json +1 -1
  194. package/package.json +1 -1
  195. package/lib/chunk-2ADSD5WK.mjs +0 -7
  196. package/lib/chunk-2GSMHGIV.mjs +0 -7
  197. package/lib/chunk-36Y225OM.mjs +0 -7
  198. package/lib/chunk-3OVTKRS4.mjs +0 -7
  199. package/lib/chunk-4GCYGQXD.mjs +0 -7
  200. package/lib/chunk-4JKR4PTZ.mjs +0 -8
  201. package/lib/chunk-5OGNK3JP.mjs +0 -37
  202. package/lib/chunk-6QSHWIZI.mjs +0 -48
  203. package/lib/chunk-77IVKH7R.mjs +0 -7
  204. package/lib/chunk-77MZRBWX.mjs +0 -7
  205. package/lib/chunk-7WSQ65WG.mjs +0 -9
  206. package/lib/chunk-A32ISQ6M.mjs +0 -28
  207. package/lib/chunk-AG24QMSY.mjs +0 -7
  208. package/lib/chunk-BH76USTQ.mjs +0 -11
  209. package/lib/chunk-BZ24IAP5.mjs +0 -7
  210. package/lib/chunk-CN5HGFG4.mjs +0 -7
  211. package/lib/chunk-CTPLYUXA.mjs +0 -7
  212. package/lib/chunk-DIGUC7S4.mjs +0 -341
  213. package/lib/chunk-DSR2MSBH.mjs +0 -7
  214. package/lib/chunk-ETNQHIDI.mjs +0 -9
  215. package/lib/chunk-FBXH4VRQ.mjs +0 -7
  216. package/lib/chunk-FYWNSMOZ.mjs +0 -10
  217. package/lib/chunk-GEEWPTV5.mjs +0 -7
  218. package/lib/chunk-GTRU5AV5.mjs +0 -7
  219. package/lib/chunk-I3ZO76LL.mjs +0 -21
  220. package/lib/chunk-ISA2NYJV.mjs +0 -7
  221. package/lib/chunk-IXIY6Q4M.mjs +0 -7
  222. package/lib/chunk-JAV6F6OA.mjs +0 -7
  223. package/lib/chunk-JYUMD357.mjs +0 -7
  224. package/lib/chunk-L47JCNP3.mjs +0 -7
  225. package/lib/chunk-LI2XNV7F.mjs +0 -7
  226. package/lib/chunk-LP2D3JJP.mjs +0 -7
  227. package/lib/chunk-LYOGCIYD.mjs +0 -925
  228. package/lib/chunk-N5UIE4IR.mjs +0 -7
  229. package/lib/chunk-O7GCCRPW.mjs +0 -7
  230. package/lib/chunk-OO24ZYYJ.mjs +0 -7
  231. package/lib/chunk-OS6HFJ7L.mjs +0 -7
  232. package/lib/chunk-P6WRYJN3.mjs +0 -7
  233. package/lib/chunk-PGRY365W.mjs +0 -7
  234. package/lib/chunk-PPGDAUEQ.mjs +0 -7
  235. package/lib/chunk-Q4PPI3KG.mjs +0 -7
  236. package/lib/chunk-QFTF2PGS.mjs +0 -21
  237. package/lib/chunk-QO4MPHZD.mjs +0 -7
  238. package/lib/chunk-QXB6U3ZP.mjs +0 -7
  239. package/lib/chunk-R3OM3X4L.mjs +0 -8
  240. package/lib/chunk-R7GKMAT4.mjs +0 -7
  241. package/lib/chunk-SCKUIE3R.mjs +0 -7
  242. package/lib/chunk-SU65Z2BA.mjs +0 -7
  243. package/lib/chunk-T7DDS4UQ.mjs +0 -7
  244. package/lib/chunk-TQJ5NPRC.mjs +0 -7
  245. package/lib/chunk-VZLJZEV2.mjs +0 -7
  246. package/lib/chunk-W3BQGMTR.mjs +0 -7
  247. package/lib/chunk-WXU6ZJIV.mjs +0 -7
  248. package/lib/chunk-X4HZD5U2.mjs +0 -7
  249. package/lib/chunk-X6XNTOGO.mjs +0 -7
  250. package/lib/chunk-XMQ5R6TC.mjs +0 -10
  251. package/lib/chunk-XPXEQKLR.mjs +0 -7
  252. package/lib/chunk-YBZIDW6W.mjs +0 -7
  253. package/lib/chunk-ZCOSME6P.mjs +0 -7
  254. package/lib/chunk-ZTHC42X6.mjs +0 -7
@@ -4,7 +4,7 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{b as ft}from"./chunk-3OVTKRS4.mjs";import{b as lt,n as ut}from"./chunk-BH76USTQ.mjs";import{a as rt,b as K,c as dt,d as Y,f as ct,i as ht,k as me}from"./chunk-XKFHTBAB.mjs";import{f as at}from"./chunk-FYWNSMOZ.mjs";import{a as ue,b as F,c as et,f as tt}from"./chunk-OS5GE52G.mjs";import{a as wt,b as gt,c as we,d as kt,e as ge,g as bt,h as yt,i as vt,j as ke}from"./chunk-W3BQGMTR.mjs";import{q as pt}from"./chunk-QFTF2PGS.mjs";import{e as se}from"./chunk-L4MSL4U7.mjs";import{a as mt}from"./chunk-TW3N6W5Z.mjs";import{d as pe}from"./chunk-LYOGCIYD.mjs";import{a as ot,b as fe,c as it}from"./chunk-QROPNEGY.mjs";import{b as oe,e as qe}from"./chunk-BZ24IAP5.mjs";import{a as ne}from"./chunk-SCKUIE3R.mjs";import{c as V}from"./chunk-6FARZYMJ.mjs";import{hb as ze}from"./chunk-AXFD2OH6.mjs";import{a as Ke,n as Ye,o as Xe}from"./chunk-4X5D3MSV.mjs";import{B as Je}from"./chunk-IXIY6Q4M.mjs";import{I as Ze,L as Qe,e as H,i as le}from"./chunk-N2HYG3BL.mjs";import{d as Ve,j as ie}from"./chunk-7WSQ65WG.mjs";import{a as We}from"./chunk-7ZBDACVG.mjs";import{r as Ue}from"./chunk-OUU47Y7A.mjs";import{gc as nt}from"./chunk-R3OM3X4L.mjs";import{b as Me,f as B,h as st}from"./chunk-LCDPCUXS.mjs";import{k as Ge}from"./chunk-Z3MGN42K.mjs";import{da as He}from"./chunk-2GSMHGIV.mjs";import{A as ce,Ra as Te,Va as Be,Vd as he,Yd as _e,ed as Fe}from"./chunk-6QSHWIZI.mjs";import{mkdtempSync as pn,readFileSync as mn,rmSync as wn}from"node:fs";import{tmpdir as gn}from"node:os";import{join as Ot,resolve as be}from"node:path";var kn=`sandforge checkpoint \u2014 take a checkpoint of an org's data, and rewind the org to it, without the editor.
7
+ import{b as mt}from"./chunk-2YHZBUZE.mjs";import{d as ft,s as pt}from"./chunk-2WFIVO4F.mjs";import{a as ct,b as Y,c as ht,d as X,f as lt,i as ut,k as we}from"./chunk-7QYHEHMA.mjs";import{f as dt}from"./chunk-WXDLQT2O.mjs";import{a as fe,b as F,c as nt,f as ot}from"./chunk-GNRSF65U.mjs";import{a as kt,b as bt,d as ge,e as yt,f as ke,h as $t,i as vt,j as At,k as be}from"./chunk-3TZSBHEY.mjs";import{q as wt}from"./chunk-PH7SP4YK.mjs";import{e as ae}from"./chunk-IZGCEOYO.mjs";import{a as gt}from"./chunk-TW3N6W5Z.mjs";import{d as me}from"./chunk-PEDQPM2P.mjs";import{b as ie,e as Ge}from"./chunk-RKTFFCNS.mjs";import{c as V}from"./chunk-6FARZYMJ.mjs";import{hb as Ve}from"./chunk-XGGOUNPP.mjs";import{a as Xe,n as Ze,o as Qe}from"./chunk-HIDW7FNV.mjs";import{a as st,b as pe,c as at}from"./chunk-QROPNEGY.mjs";import{B as Ke,G as K}from"./chunk-H4CGM6YO.mjs";import{I as et,L as tt,e as H,i as ue}from"./chunk-KGU4SVIT.mjs";import{a as oe,c as Be}from"./chunk-AL4C3GFT.mjs";import{a as He}from"./chunk-OUZQPYT3.mjs";import{r as We}from"./chunk-MSIEU5MR.mjs";import{m as Ye,s as se,wc as it}from"./chunk-KB4ZHM4Q.mjs";import{b as qe,f as B,h as rt}from"./chunk-LCDPCUXS.mjs";import{k as Je}from"./chunk-M6K34KGF.mjs";import{da as ze}from"./chunk-TNT27RBG.mjs";import{A as he,Ra as Fe,Va as _e,Vd as le,Yd as Me,ed as Ue}from"./chunk-PMWAFDUB.mjs";import{mkdtempSync as wn,readFileSync as gn,rmSync as kn}from"node:fs";import{tmpdir as bn}from"node:os";import{join as Et,resolve as ye}from"node:path";var yn=`sandforge checkpoint \u2014 take a checkpoint of an org's data, and rewind the org to it, without the editor.
8
8
 
9
9
  Usage:
10
10
  npx sandforge checkpoint <command> --org <alias> [options]
@@ -48,7 +48,7 @@ take:
48
48
  Customize Application
49
49
  --ignore-field <Object.Field> do not compare a field, nor write it back (one your automation sets
50
50
  on every save); repeat for more
51
- --max-total <n> refuse, before reading, more than <n> records (default: ${ue},
51
+ --max-total <n> refuse, before reading, more than <n> records (default: ${fe},
52
52
  ${F} at most)
53
53
  --keep-days <n> when it expires (default: ${H}; 0 keeps it until deleted)
54
54
  --estimate say the records, API requests, time and disk it would take, then stop
@@ -462,14 +462,14 @@ were kept, each said with why); 4 unstable (someone else changed
462
462
  records during the rewind or the undo: left as they made them); 130, 143, 129 Ctrl-C, SIGTERM or
463
463
  SIGHUP stopped it \u2014 run rewind again: it takes up from what still differs, and undo still reaches
464
464
  the state before it.
465
- `,bn=["take","list","preview","rewind","undo","delete","export","import","replay","replays"],yn=e=>bn.includes(e),x={switches:["--json"],values:["--org","--store"]},vn={take:{words:1,switches:[...x.switches,"--estimate"],values:[...x.values,"--name","--object","--exclude-object","--custom-setting","--ignore-field","--max-total","--keep-days"]},list:{words:1,...x},preview:{words:1,switches:[...x.switches,"--fail-on-change"],values:[...x.values,"--checkpoint","--object"]},rewind:{words:1,switches:[...x.switches,"--dry-run","--accept-automation","--accept-emails","--mute-automation","--accept-no-undo","--accept-recreate","--accept-outside","--accept-unseen","--refuse-when-active","--yes"],values:[...x.values,"--checkpoint","--ignore-field","--object","--max-records"]},undo:{words:1,switches:[...x.switches,"--accept-automation","--accept-emails","--mute-automation","--yes"],values:[...x.values,"--checkpoint"]},delete:{words:1,switches:[...x.switches,"--all","--yes"],values:[...x.values,"--checkpoint"]},export:{words:1,switches:x.switches,values:[...x.values,"--checkpoint","--out","--key-env"]},import:{words:1,switches:x.switches,values:[...x.values,"--file","--key-env","--keep-days"]},replay:{words:1,switches:["--json","--dry-run","--verify","--remove","--preview","--sweep","--sweep-list","--sweep-late","--sweep-untied","--include-changed","--custom-settings","--mask","--keep-contact-points","--no-real-data","--again","--mute-automation","--accept-automation","--accept-emails","--yes",...pe.switches],values:["--store","--checkpoint","--from","--file","--key-env","--keep-days","--target","--objects","--exclude-object","--owners","--owner-map","--link","--replay-config","--max-records",...pe.values]},replays:{words:1,switches:["--json"],values:["--store","--target"]}},$n={name:"--name",objects:"--object",excluded:"--exclude-object",customSettings:"--custom-setting",ignoredFields:"--ignore-field",maxTotal:"--max-total",keepDays:"--keep-days"},An=/^[A-Za-z][A-Za-z0-9_]{0,79}$/;function S(e){process.stderr.write(`${e}
466
- `),process.exit(2)}function jn(e){let n=e.toISOString();return`${n.slice(0,10)} ${n.slice(11,16)} UTC`}function Rn(e,n=new Date){let t=e.slice(2);(t.includes("--help")||t.includes("-h"))&&(process.stdout.write(kn),process.exit(0));let o=t[0];if(o===void 0||o.startsWith("-"))return S("Name the command first: take, list, preview, rewind, undo, delete, export, import, replay or replays. Run with --help.");if(!yn(o))return S(`"${o}" is not a command of sandforge checkpoint: take, list, preview, rewind, undo, delete, export, import, replay or replays. Nothing was run. Run with --help.`);Me(t,vn[o]);let i=w=>{let h=[];for(let l=1;l<t.length;l++){if(t[l]!==w)continue;let k=t[l+1];if(k===void 0||k.startsWith("--"))return S(`${w} wants a value.`);h.push(k),l++}return h},s=w=>{let h=i(w);return h.length>1&&S(`${w} is given ${h.length} times: give it once.`),h[0]},d=w=>{let h=s(w);if(h!==void 0)return/^\d{1,15}$/.test(h)||S(`${w} takes a whole number, not "${h}".`),Number(h)},a=s("--store"),r={storeRoot:a!==void 0?be(a):le(),...a!==void 0?{storeNamed:!0}:{},json:t.includes("--json")},p=s("--org"),m=()=>p??S(`${o} needs --org. Run with --help.`),g=w=>{t.includes("--yes")&&(w===void 0&&S(`${o} --yes needs --checkpoint <id|name>: one that does not ask is told which checkpoint it acts on. Nothing was run.`),w==="latest"&&S(`${o} --yes needs the checkpoint named by its id or its name, not latest: a checkpoint taken since would be the one it acts on. Nothing was run.`))},$=()=>{let w=i("--object"),h=w.find(l=>!An.test(l));return h!==void 0&&S(`--object takes an object's API name, not "${h}".`),w.filter((l,k)=>w.findIndex(y=>y.toLowerCase()===l.toLowerCase())===k)};switch(o){case"list":return{...r,command:o,...p!==void 0?{org:p}:{}};case"replay":return{...r,command:o,replay:wt(t,S)};case"replays":return{...r,command:o,...gt(t,S)};case"take":{let w=m(),h=i("--object"),l=i("--exclude-object"),k=i("--custom-setting"),y=k.includes("all")?"all":k,c=i("--ignore-field"),u=d("--max-total"),j={name:s("--name")??jn(n),mode:h.length>0?"picked":"everything",...h.length>0?{objects:h}:{},...l.length>0?{excluded:l}:{},...y.length>0?{customSettings:y}:{},...c.length>0?{ignoredFields:c}:{},...u!==void 0?{maxTotal:u}:{},keepDays:d("--keep-days")??H},C=ze.safeParse({...j,orgId:"command-line"});if(!C.success){let O=C.error.issues[0],W=String(O?.path[0]??"");return S(`${$n[W]??W}: ${O?.message??"not read"}. Nothing was run.`)}return{...r,command:o,org:w,take:{...j,name:C.data.name},estimate:t.includes("--estimate")}}case"preview":return{...r,command:o,org:m(),checkpoint:s("--checkpoint")??"latest",failOnChange:t.includes("--fail-on-change"),objects:$()};case"rewind":{let w=m(),h=s("--checkpoint");g(h);let l=i("--ignore-field"),k=Be.safeParse(l);if(!k.success)return S(`--ignore-field: ${k.error.issues[0]?.message??"not read"}. Nothing was run.`);let y=d("--max-records");return y===0&&S('--max-records takes a whole number of 1 or more, not "0". Nothing was run.'),{...r,command:o,org:w,checkpoint:h??"latest",objects:$(),dryRun:t.includes("--dry-run"),acceptAutomation:t.includes("--accept-automation"),acceptEmails:t.includes("--accept-emails"),muteAutomation:t.includes("--mute-automation"),acceptNoUndo:t.includes("--accept-no-undo"),acceptRecreate:t.includes("--accept-recreate"),acceptOutside:t.includes("--accept-outside"),acceptUnseen:t.includes("--accept-unseen"),...y!==void 0?{maxRecords:y}:{},refuseWhenActive:t.includes("--refuse-when-active"),ignoreFields:l,yes:t.includes("--yes")}}case"undo":{let w=m(),h=s("--checkpoint");return g(h),{...r,command:o,org:w,...h!==void 0?{checkpoint:h}:{},acceptAutomation:t.includes("--accept-automation"),acceptEmails:t.includes("--accept-emails"),muteAutomation:t.includes("--mute-automation"),yes:t.includes("--yes")}}case"delete":{let w=m(),h=s("--checkpoint"),l=t.includes("--all");return l&&h!==void 0&&S("Give --checkpoint or --all, not both."),{...r,command:o,org:w,...l?{}:{checkpoint:h??"latest"},all:l,yes:t.includes("--yes")}}case"export":{let w=m(),h=s("--out")??S("export needs --out <file>. Run with --help."),l=$t(s("--key-env"));return{...r,command:o,org:w,checkpoint:s("--checkpoint")??"latest",out:be(h),...l!==void 0?{keyEnv:l}:{}}}case"import":{let w=m(),h=s("--file")??S("import needs --file <file>. Run with --help."),l=$t(s("--key-env"));return{...r,command:o,org:w,file:be(h),...l!==void 0?{keyEnv:l}:{},keepDays:d("--keep-days")??H}}}}function $t(e){if(e!==void 0)return!/^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(e)||se(e)!==void 0?S("--key-env takes the name of an environment variable that holds the key, never the key: a key on the command line stays in the shell\u2019s history and the list of processes. Nothing was run."):e}function xt(e,n){return e!==void 0&&n!==void 0&&e.length>=15&&e.slice(0,15)===n.slice(0,15)}function _(e,n,t){let o=t!==void 0?[t]:[];for(let i of e){let s=i.checkpoint?.org;s!==void 0&&(s.alias===n||s.username.toLowerCase()===n.toLowerCase())&&o.push(i.organizationId)}return e.filter(i=>o.some(s=>xt(s,i.organizationId)))}var Et="One kept in another folder is read with --store <folder>, or with SANDFORGE_JOURNAL_DIR set as when it was taken \u2014 in a CI job, a folder its cache restores; one taken on another machine comes here by export there, then import here.";function ae(e){return`"${ne("checkpoint")} list --org ${e}" names those it holds. ${Et}`}function G(e,n,t,o){if(Te.safeParse(t).success){let s=e.find(d=>d.checkpointId===t);return s?{entry:s}:{none:`No checkpoint ${t} is kept in the folder read. ${ae(o)}`}}if(t==="latest"){let s=n[0];return s?{entry:s}:{none:`No checkpoint of ${o} is kept in the folder read. ${ae(o)}`}}let i=n.filter(s=>s.checkpoint?.name===t);return i.length===1?{entry:i[0]}:i.length===0?{none:`No checkpoint of ${o} named '${t}' is kept in the folder read. `+ae(o)}:{ambiguous:`${i.length} checkpoints of ${o} are named '${t}': give the id of the one you mean with --checkpoint (${i.map(s=>s.checkpointId).join(", ")}).`}}function Re(e){if(e.valid)return;let n=e.checkpoint?`'${e.checkpoint.name}'`:e.checkpointId;switch(e.why){case"damaged":return{code:"DAMAGED",message:`The file of checkpoint ${e.checkpointId} cannot be read: it can only be deleted.`};case"taking":return{code:"TAKING",message:`The checkpoint ${n} is being taken, or its take never ended: it can be previewed once taken, or deleted.`};case"failed":return{code:"FAILED",message:`The take of checkpoint ${n} failed: it can only be deleted.`};case"refreshed":return{code:"OTHER_ORG",message:`This sandbox was refreshed${e.refreshedAt?` on ${e.refreshedAt.slice(0,10)}`:""}: it is another org now, and the checkpoint ${n} is of the org before it. It no longer rewinds. ${At(e)}`};case"scratchExpired":return{code:"SCRATCH_EXPIRED",message:`The scratch org of checkpoint ${n} has expired: its checkpoints no longer rewind it. ${At(e)}`};default:return{code:"INVALID",message:`The checkpoint ${n} cannot be previewed.`}}}function Ce(e){let n=e.checkpoint?.org,t=e.why==="refreshed"&&n!==void 0?n.alias??n.username:"<alias>";return`${ge(e.checkpointId,t)} --dry-run`}function At(e){return`${ce.replace(/\.$/,"")}: ${Ce(e)}`}function It(e){return!e.valid&&(e.why==="refreshed"||e.why==="scratchExpired")}var f=e=>e.toLocaleString("en-US");function E(e){let n=new Date(Date.parse(e)).toISOString();return`${n.slice(0,10)} ${n.slice(11,16)} UTC`}function ye(e){let n=new Date(Date.parse(e)).toISOString();return`${n.slice(0,10)} ${n.slice(11,19)} UTC`}var U=e=>`${nt(e/(1024*1024))} MB`;function v(e,n=8){if(e.length===0)return"\u2014";let t=e.slice(0,n).join(", ");return e.length>n?`${t} \u2026 (+${e.length-n})`:t}function Z(e){return e.objects.reduce((n,t)=>n+t.records,0)}function Se(e){return e===null?"kept until you delete it":`kept until ${E(e)}`}function z(e){return e.org.alias??e.org.username}var Cn=/^Left out(?::\s*|\s+(?=as asked\b))/;function Nt(e,n){let t=[...n,...e.flatMap(({code:s,records:d})=>s==="pastTheLimit"&&d!==void 0?[d]:[])],o=t.filter(s=>s<=F).reduce((s,d)=>s+d,0),i=new Map;for(let{objectApiName:s,reason:d,code:a,records:r}of e){let p=d;if(a==="pastTheLimit"&&r!==void 0&&r<=F){let m=tt(t,r);p=m>F?`${d} With it, every object no larger is kept, more than ${F} records in all, past any --max-total: --exclude-object <ApiName> leaves some out.`:`${d} --max-total ${m}${m===o?" or more":""} holds it.`}i.set(p,[...i.get(p)??[],s])}return[...i].map(([s,d])=>` left out: ${v(d)} \u2014 ${s.replace(Cn,"")}`)}var Sn={fls:"hidden from the user SandForge connects as by field-level security: Rewind won\u2019t put them back",encrypted:"encrypted, and the user SandForge connects as can\u2019t view encrypted data: Rewind won\u2019t touch them",base64:"the content of files and other binary values, which a checkpoint doesn\u2019t hold",compound:"compound fields, kept through the fields they are made of"};function Dt(e){let n=new Map;for(let t of e)for(let{field:o,reason:i}of t.leftOutFields)n.set(i,[...n.get(i)??[],`${t.objectApiName}.${o}`]);return[...n].map(([t,o])=>` fields left out (${o.length}): ${v(o)} \u2014 ${Sn[t]??t}`)}function Pt(e){let n=e.filter(t=>!t.undeletable).map(t=>t.objectApiName);return n.length===0?[]:[` deleted ${v(n)} records come back from the recycle bin only with their parent`]}function Lt(e){return` about ${f(e.seconds)} s \xB7 about ${f(e.apiRequests)} API requests of the ${f(e.apiRequestsLeft)} left today`+(e.bytes>0?` \xB7 about ${U(e.bytes)} on this machine`:"")}var jt={damaged:"its file cannot be read: it can only be deleted",taking:"being taken, or its take never ended: it can only be deleted unless it ends",failed:"its take failed: it can only be deleted",refreshed:"of the org before its refresh: it no longer rewinds, and replays into another org",scratchExpired:"its scratch org has expired: it no longer rewinds, and replays into another org"};function On(e,n,t){if(e.length===0&&t!==void 0){let i=t.kept===0?"":`, which keeps ${t.kept===1?"1 of another org":`${t.kept} of other orgs`}: "${ne("checkpoint")} list" names ${t.kept===1?"it":"them"}`;return[`No checkpoint of ${t.org} is kept in ${n}${i}. ${Et}`]}if(e.length===0)return[`No checkpoint is kept in ${n}.`];let o=[];for(let i of e){let s=i.checkpoint;if(!s){o.push(`${i.checkpointId} ${jt.damaged}`);continue}if(o.push(`${i.checkpointId} '${s.name}' ${z(s)} taken ${E(s.takenAt)} ${f(Z(s))} records in ${s.objects.length} objects ${U(s.bytes)} `+Se(s.expiresAt)),!i.valid){let d=i.why==="refreshed"&&i.refreshedAt?`refreshed on ${i.refreshedAt.slice(0,10)}: `:"";o.push(` ${d}${jt[i.why??""]??"it cannot be previewed"}`),It(i)&&(o.push(` replay it: ${Ce(i)}`),s.expiresAt!==null&&o.push(` deleted from this machine on ${E(s.expiresAt)}: to replay it after, Keep it in the editor, or export it and replay the file`))}i.scratchExpiresSoon&&s.org.scratchExpiresAt!==void 0&&o.push(` its scratch org expires on ${s.org.scratchExpiresAt.slice(0,10)}: its checkpoints then no longer rewind it, whatever --keep-days said, and still replay into another org`),i.expiresSoon&&s.expiresAt!==null&&o.push(` expires on ${E(s.expiresAt)}: take a new one, or keep this one in the editor`),i.binReachSince&&o.push(` records deleted before ${i.binReachSince.slice(0,10)} can't come back with their Id (recycle bin), sooner if the bin fills: a rewind makes them again, with new Ids`),i.undo&&o.push(` rewound: the rewind can be undone until ${E(i.undo.until)}`)}return o}function xn(e){let n=e.checkpoint;return{id:e.checkpointId,name:n?.name??null,org:n?z(n):null,organizationId:e.organizationId,takenAt:n?.takenAt??null,records:n?Z(n):null,bytes:n?.bytes??null,expiresAt:n?n.expiresAt:null,expiresSoon:e.expiresSoon===!0,scratchExpiresSoon:e.scratchExpiresSoon===!0,binReachSince:e.binReachSince??null,...n?.lastRewind?{lastRewind:{...n.lastRewind,undoable:e.undo!==void 0}}:{},valid:e.valid,...e.why!==void 0?{why:e.why}:{},...e.refreshedAt!==void 0?{refreshedAt:e.refreshedAt}:{},...It(e)?{replayWith:Ce(e)}:{}}}function Tt(e){return e.refusal!==void 0&&e.objects.length===0&&e.leftOut.length===0}function En(e){return Tt(e)?{mode:e.mode,refusal:e.refusal}:{...e}}function ve(e){if(e.code!=="TOO_MANY_RECORDS")return e;let n="pick fewer objects (--exclude-object <ApiName> leaves one out)",t=`(${f(ue)} unless given)`,o=e.holdingLimit,i=o===void 0?`${n}, or raise the limit with --max-total <n> ${t}`:o>F?`${n}: no --max-total holds them all, ${f(F)} at most`:`${n}, or raise the limit with --max-total ${o} ${t}`;return{...e,message:e.message.replace(/: pick fewer objects\./,`: ${i}.`)}}function In(e,n){if(Tt(n))return[`refused: ${n.refusal.message}`];let t=n.objects.filter(i=>i.records>0).length,o=new Map;for(let{namespace:i}of n.objects)i!==void 0&&o.set(i,(o.get(i)??0)+1);return[`a checkpoint of ${e} would keep ${n.objects.length} objects (${t} hold records; ${n.objects.length-t} are empty \u2014 what is created there later is caught too), about ${f(n.estimate.records)} records`,...[...o].map(([i,s])=>` includes ${s} objects of the ${i} package`),Lt(n.estimate),...Nt(n.leftOut,n.objects.map(i=>i.records)),...Dt(n.objects),...Pt(n.objects),...n.files?Dn(n.files):[],...Nn(n),...n.refusal?[`refused: ${ve(n.refusal).message}`]:[]]}function Bt(e){let n=e.records===void 0?void 0:`${f(e.records)} ${e.records===1?"row":"rows"}`,t=[e.kind,n].filter(o=>o!==void 0);return t.length>0?`${e.objectApiName} (${t.join(", ")})`:e.objectApiName}function Ft(e){return Bt({objectApiName:e.objectApiName,...e.customSetting!==void 0?{kind:e.customSetting}:{},records:e.records})}function Nn(e){let n=e.objects.filter(i=>i.customSetting!==void 0),t=new Set(n.map(i=>i.objectApiName)),o=(e.customSettings??[]).filter(i=>!t.has(i.objectApiName));return[...n.length>0?[` custom settings kept: ${v(n.map(Ft))} \u2014 a rewind sets their rows back as the checkpoint holds them, whoever changed them since`]:[],...o.length>0?[` custom settings not kept: ${v(o.map(Bt))} \u2014 --custom-setting <ApiName|all> keeps them`]:[]]}function Dn(e){return e.held?[" files: it keeps which files are attached to its records (Salesforce Files, classic attachments) and each file's latest version, not its content; a rewind deletes the files attached to them since and brings back those deleted since. A file attached to no record it holds, a user's own or a library's, is left as it is",..._t(e.addedToPicked),...e.queryAllFiles?[]:[Oe]]:[" files: not kept \u2014 a rewind leaves the files attached since as they are"]}function _t(e){return e.length>0?[` added to the objects picked: ${e.join(", ")} \u2014 without them a rewind would leave the files attached since as they are`]:[]}var Oe=" the user the alias connects as doesn't have Query All Files: other users' files that no record of the checkpoint is attached to (in a library the user is not a member of, say) are not seen, nor counted among the files left; files attached to its records are seen";function Pn(e,n,t=[]){let o=e.movedWhileTaken,i=o.changed+o.deleted+o.created;return[`taken '${e.name}' (${e.checkpointId}) of ${z(e)}: ${f(Z(e))} records in ${e.objects.length} objects, ${U(e.bytes)} on this machine, ${Se(e.expiresAt)}`,` of ${ye(e.readFrom)}, read until ${ye(e.takenAt)} on the org's clock`,...i>0?[` ${f(i)} records changed while it was taken (${o.changed} changed, ${o.deleted} deleted, ${o.created} created): it holds them as they were read, and a rewind treats them as changed since. Take checkpoints when nobody works in the org.`]:[],...Nt(e.scope.leftOut,e.objects.map(s=>s.records)),...Dt(e.objects),...e.ignoredFields.length>0?[` not compared, nor written back (you chose): ${e.ignoredFields.join(", ")}`]:[],...Pt(e.objects),...Ln(e.objects),...e.files?Tn(e,e.files,t):[],` it holds the records' values unencrypted, in files only you can read: ${n}`]}function Ln(e){let n=e.filter(t=>t.customSetting!==void 0);return n.length===0?[]:[` custom settings kept: ${v(n.map(Ft))} \u2014 a rewind sets their rows back as the checkpoint holds them`]}function Tn(e,n,t){let o=n.readByIds??[],i=new Set(t.map(a=>a.toLowerCase())),s=new Set(e.objects.map(({objectApiName:a})=>a.toLowerCase())),d=e.scope.mode==="picked"?Ge.filter(a=>s.has(a.toLowerCase())&&!i.has(a.toLowerCase())):[];return[` files: ${f(n.anchored)} attached to its records by ${f(n.links)} link(s): a rewind takes back what is attached to them since`,..._t(d),...o.length>0?[` the links of ${v(o)} were read by lists of record Ids: ${z(e)} refused one query, or answered too late`]:[],...e.takenBy.queryAllFiles===!1?[Oe]:[]]}function Bn(e,n){let t=Object.entries(e.byPhase).map(([i,s])=>{let d=n?.requestsByPhase?.[i];return d===void 0||d===s?`${i} ${s}`:`${i} ${s} (${d})`}),o=n?`, about ${f(n.apiRequests)} estimated`:"";return` sent ${f(e.total)} API requests to the org${o}: ${t.join(", ")}`}var Rt=e=>e.toDelete.createdSince+e.toDelete.broughtBackSince+e.toDelete.comesBackWithParent,J=e=>e.toBringBack.inBin+e.toBringBack.withParent+e.toBringBack.deletedWhileTaken,$e=e=>e.cannotUndo.reduce((n,t)=>n+t.count,0),X=e=>e.toRecreate??0,re=e=>e.toBringBack.carriers??0;function Ut(e){let n=e.files;return n===void 0?0:n.unlink+n.relink+n.updateLinks}function Fn(e){let n=e.files;return n===void 0?0:n.outsideAdded+n.outsideDeleted}function _n(e){let n=e.schemaDrift;return n===void 0?0:n.removed.length+(n.hidden?.length??0)+(n.uncertain?.fields.length??0)}function xe(e){let n=K(e);return n.toDelete+n.toGiveBack+n.toBringBack+n.toRecreate>0||Ut(e)+Fn(e)>0||e.objects.some(t=>$e(t)>0||t.unexplained>0||_n(t)>0)||e.unread.length>0}var Un={goneForGood:"deleted since and no longer in the recycle bin, and not made again \u2014 a file, whose body the checkpoint does not hold, or a record deleted while it was taken: they can\u2019t come back",convertedLead:"leads converted since: Salesforce can\u2019t unconvert a lead",activatedContract:"contracts activated since: Salesforce won\u2019t set them back to Draft",deletedWithCreatedParent:"deleted with a parent created since that Salesforce does not undelete on its own: they come back with that parent only",deletedWithParentOutside:"deleted with their parent, a record of an object the checkpoint does not hold: they come back with that parent only, which a checkpoint that holds its object brings back",newFileVersion:"files given a new version since: Salesforce deletes no version and won\u2019t make an older one the latest again, so they keep their new content; the content each had is still in its version history, and their titles are given back",deletedByOther:"deleted since by another user: only View All Data and Modify All Data restore those; they stay in the recycle bin, never made again",outOfReach:"out of reach: without View All Data and Modify All Data, nothing shows what others deleted of an object held through the records it hangs from; they may be in the recycle bin out of sight, and are never made again"},Mn=[{reason:"onlyWithParent",preview:"Salesforce undeletes them only with their parent, and their parent stays",result:"Salesforce undeletes them only with their parent"},{reason:"deletedBeforeParent",preview:"deleted before a record they point at, which the rewind deletes next: Salesforce cannot bring them back after that",result:"deleted before a record they point at, which the rewind deleted next: Salesforce cannot bring them back after that"}];function Mt(e){return Mn.flatMap(n=>{let t=e.filter(o=>(o.reason??"onlyWithParent")===n.reason);return t.length>0?[{words:n,of:t}]:[]})}function Wn(e,n){let{automation:t,deliverability:o}=n;if(!t||!o)return[];let i=Y(n.diff),{line:s}=Xe({act:"rewind",orgName:e,automation:t,steps:i,accepted:!0,mayMute:!1,...Ye({automation:t,steps:i}),reading:o.reading}).gate;return s!==void 0?[` ${s}`]:[]}function qn(e,n){return n.map(t=>{let o=[...new Set(t.objects.flatMap(s=>s.sentBy))],i=` emails: ${e}'s automation sends about ${Ke(t.emails,t.limit)} as the rewind writes (${v(o,4)})`+(t.alertsCounted?`, its email alerts among them: ${e} counts them against its single emails, as a Developer Edition does`:"");return t.verdict==="unread"?`${i}; what it has left today could not be read (${t.unread??""})`:t.verdict==="fits"?`${i}; ${t.remaining??0} of ${t.max??0} left today`:`${i}, more than the ${t.remaining??0} of ${t.max??0} left today: a rewind is refused`})}function Hn(e,n){if(!e||n.length===0)return"";let t=he(e,{giveBack:n}).map(o=>`${o.objectApiName}: '${o.name}'`);return t.length>0?`, on which runs ${v(t,4)}`:""}function Gn(e,n,t=[]){let o=e.objects.filter(a=>He[a.objectApiName]!==void 0),i=o.filter(a=>X(a)>0),s=o.filter(a=>J(a)>0&&!t.includes(a.objectApiName)),d=[];return i.length>0&&d.push(` made as drafts first: ${v(i.map(a=>`${a.objectApiName} ${f(X(a))}`))} \u2014 Salesforce refuses an order or a contract made past Draft, and an order takes its products only as a draft: one past Draft at the checkpoint is made at the org's Draft status, the records under it next, then given its status back, an update`+Hn(n,i.map(a=>a.objectApiName))),s.length>0&&d.push(` if Salesforce answers that an order or a contract to bring back is no longer in the recycle bin, --accept-recreate makes it again as a draft, then gives it its status back, an update: ${v(s.map(a=>`${a.objectApiName} ${f(J(a))}`))}`),d}function zn(e,n,t=!1){if(!n)return{objects:[],fired:[]};let o=Y(e),i=[],s=new Set;for(let d of e.objects){if(J(d)===0)continue;let a=ct(n,o,[d.objectApiName],t);if(!(a.fired.length===0&&!a.blind)){i.push(d.objectApiName);for(let r of a.fired)s.add(`${r.objectApiName}: '${r.name}'`)}}return{objects:i,fired:[...s]}}function Jn(e,n,t){let o=he(n,t),i=[];for(let d of n.objects){let a=o.filter(g=>g.objectApiName===d.objectApiName),r=[...new Set(a.filter(g=>g.kind!=="trigger").map(g=>`'${g.name}'`))],p=[...new Set(a.filter(g=>g.kind==="trigger").map(g=>g.name))],m=[...r.length>0?[`${r.length} flow(s) or rule(s): ${v(r,4)}`]:[],...p.length>0?[`${p.length} Apex trigger(s): ${v(p,4)}`]:[]];m.length>0&&i.push(` ${d.objectApiName}: ${m.join("; ")}`)}return[...i.length>0?[` what ${e} runs as a rewind writes (updates, deletes, records brought back):`]:[],...i,...n.unread.map(d=>` not read of its automation: ${d.part} \u2014 ${d.reason}`)]}function Wt(e,n,t,o="the user SandForge connects as",i=!1){let{diff:s}=t,d=K(s),a=[`Rewind ${e} to '${n.name}' (${E(n.takenAt)}), read at ${ye(s.readAt)}:`,` ${f(d.toDelete)} to delete \xB7 ${f(d.toGiveBack)} to give back \xB7 ${f(d.toBringBack)} to bring back`+(d.toRecreate>0?` \xB7 ${f(d.toRecreate)} to make again`:"")];!xe(s)&&!s.objects.some(c=>c.outside.length>0)&&a.push(` ${e} is as it was at '${n.name}' among the objects and fields it holds: nothing to rewind.`);let r=s.objects.filter(c=>Rt(c)+c.toGiveBack.records+J(c)+X(c)+$e(c)>0);if(r.length>0){let c=Math.max(6,...r.map(u=>u.objectApiName.length));a.push(` ${"Object".padEnd(c)} ${"Delete".padStart(8)} ${"Give back".padStart(9)} ${"Bring back".padStart(10)} ${"Can't undo".padStart(10)}`);for(let u of r)a.push(` ${u.objectApiName.padEnd(c)} ${f(Rt(u)).padStart(8)} ${f(u.toGiveBack.records).padStart(9)} ${f(J(u)).padStart(10)} ${f($e(u)).padStart(10)}`)}let p=new Map;for(let c of s.objects)for(let[u,j]of Object.entries(c.lastChangedBy))p.set(u,(p.get(u)??0)+j);p.size>0&&a.push(` last changed by: ${[...p].sort((c,u)=>u[1]-c[1]).map(([c,u])=>`${s.userNames[c]??c} ${f(u)}`).join(" \xB7 ")}`),s.activeLastHour.length>0&&a.push(` people working in ${e} in the last hour: ${s.activeLastHour.map(c=>s.userNames[c]??c).join(", ")}`);let m=s.objects.filter(c=>c.touched>0);m.length>0&&a.push(` touched since but holding their checkpoint values: ${v(m.map(c=>`${c.objectApiName} ${f(c.touched)}`))}`);let g=s.objects.filter(c=>re(c)>0);g.length>0&&a.push(` brought back for a moment: ${v(g.map(c=>`${c.objectApiName} ${f(re(c))}`))} \u2014 records the checkpoint does not hold that took records of it along when deleted since: Salesforce gives those back with them only, so they come back, then go back to the recycle bin with what came back with them; what the org runs on them runs twice`);let $=new Map;for(let c of s.objects)for(let u of c.cannotUndo)u.count!==0&&$.set(u.reason,[...$.get(u.reason)??[],`${c.objectApiName} ${f(u.count)}`]);for(let[c,u]of $)a.push(` can't be taken back: ${v(u)} \u2014 ${Un[c]??c}`);let w=s.objects.filter(c=>X(c)>0);w.length>0&&a.push(` to make again, with new Ids: ${v(w.map(c=>`${c.objectApiName} ${f(X(c))}`))} \u2014 deleted since and no longer in the recycle bin: made again from the checkpoint, the lookups it holds that named them naming the new Ids; anything outside Salesforce that names their old Ids no longer finds them`);let h=d.toBringBack>0?zn(s,t.automation,i):void 0;if(h){let c=h.fired.length>0?`making them again runs ${v(h.fired,4)}`:"what runs as they are made again could not all be read";a.push(" if Salesforce answers that a record to bring back is no longer in the recycle bin \u2014 it still lists one emptied from it as deleted \u2014, --accept-recreate makes it again with a new Id, with what was to come back with it; without it, the rewind leaves them and names them"+(h.objects.length>0?`; ${v(h.objects)} records it leaves all the same, with what was to come back with them, and names them: ${c}, which this rewind does not ask about \u2014 a rewind after it counts them to make again, and asks`:""))}a.push(...Gn(s,t.automation,h?.objects));let l=s.objects.filter(c=>c.unexplained>0);l.length>0&&a.push(` left as they are: ${v(l.map(c=>`${c.objectApiName} ${f(c.unexplained)}`))} \u2014 records the checkpoint doesn't hold although they're dated before it (a load with back-dated creation dates?); a rewind deletes nothing it cannot prove was created since`);for(let{words:c,of:u}of Mt(s.undoCannot))a.push(` undo couldn't bring back: ${v(u.map(j=>`${j.objectApiName} ${f(j.count)}`))} \u2014 ${c.preview}`);for(let{objectApiName:c,children:u,records:j}of s.unseen??[])a.push(` also deleted with them, out of sight: deleting ${f(j)} ${c} also deletes what ${o} can't see under them in ${v(u)}; Rewind can't count those, and deletes them only with --accept-unseen`);for(let c of s.objects)for(let u of c.outside)a.push(c.objectApiName===qt&&u.objectApiName===Vn?` also attached outside the checkpoint: ${f(u.parents)} file(s) it deletes, by ${f(u.count)} link(s) to a library, a group or a record of another object \u2014 deleting them removes them from there as well`:` also deleted with them, outside the checkpoint: ${f(u.count)} ${u.objectApiName} created under ${f(u.parents)} ${c.objectApiName}`);a.push(...Kn(e,s));let k=s.objects.flatMap(c=>{let u=c.schemaDrift,j=new Set([...u?.removed??[],...u?.hidden??[],...u?.uncertain?.fields??[]]);return c.notCompared.filter(C=>!j.has(C)).map(C=>`${c.objectApiName}.${C}`)});k.length>0&&a.push(` not compared (you chose): ${v(k)}`);for(let c of s.objects){let u=c.schemaDrift;if(!u)continue;let j=C=>C.map(O=>`${c.objectApiName}.${O}`);u.removed.length>0&&a.push(` fields deleted since: ${v(j(u.removed))} \u2014 restore them from Deleted Fields, then rewind`),(u.hidden??[]).length>0&&a.push(` fields hidden from ${o} by field-level security since: ${v(j(u.hidden??[]))} \u2014 rewind does not put them back; give ${o} read and edit access to them, then rewind again`),u.uncertain!==void 0&&u.uncertain.fields.length>0&&a.push(` fields gone from what ${e} shows ${o}: ${v(j(u.uncertain.fields))} \u2014 deleted since (restore them from Deleted Fields within 15 days), or hidden by field-level security (give ${o} read and edit access); rewind does not put them back`+(u.uncertain.reason!==void 0?` (which, ${e} would not say: ${u.uncertain.reason})`:"")),u.added.length>0&&a.push(` fields added since, their values left alone: ${v(j(u.added))}`),u.changed.length>0&&a.push(` fields changed since, tried one by one: ${v(j(u.changed))}`)}let y=s.fieldsNotChecked??0;y>0&&a.push(` fields not checked for changes in ${f(y)} objects nothing changed in: a rewind writes nothing there`);for(let c of s.unread)a.push(` could not be read: ${c.objectApiName} \u2014 ${c.reason} (never taken for unchanged)`);return t.automation&&a.push(...Jn(e,t.automation,Y(s))),t.emails&&a.push(...qn(e,t.emails)),t.emailsUncounted!==void 0&&a.push(` emails: not counted, ${t.emailsUncounted} could not be read \u2014 what they send as the rewind writes is not known; --accept-automation covers it`),a.push(...Wn(e,t)),a.push(Lt(t.estimate)),t.refusal&&a.push(` a rewind now would be refused (${t.refusal.code}): ${t.refusal.message}`),a}var qt="ContentDocument",Vn="ContentDocumentLink";function Kn(e,n){let t=n.files;if(t===void 0)return[];let o=[];t.unlink>0&&o.push(` links to remove: ${f(t.unlink)} added since between a file and a record that both stay \u2014 the file stays, no longer attached to that record`),t.relink>0&&o.push(` links to put back: ${f(t.relink)} removed since between a file and a record that both stay, each under a new Id: Salesforce keeps no removed link in the recycle bin`),t.updateLinks>0&&o.push(` links to give their sharing back: ${f(t.updateLinks)} \u2014 who sees the file from the record, and with what access; a link to an account keeps its access, which Salesforce doesn't let change`),t.outsideAdded>0&&o.push(` kept: ${f(t.outsideAdded)} file(s) added since, as no record of this checkpoint links to them (a user's own, a library's)`),t.outsideDeleted>0&&o.push(` left in the recycle bin: ${f(t.outsideDeleted)} file(s) deleted since, as no record of this checkpoint linked to them`);let i=n.objects.find(a=>a.objectApiName===qt),s=i===void 0?0:J(i),{storage:d}=t;return s>0&&d.bringBack>0&&o.push(` file storage: bringing back ${f(s)} file(s) takes ${U(d.bringBack)} again; `+(d.remaining===void 0?`${e} did not say how much it has left`:`${e} has ${U(d.remaining)} left`)),d.undo>0&&o.push(` undo would bring back the files this rewind deletes: ${U(d.undo)} of file storage again`),t.blindSpot&&o.push(Oe),o}function Ht(e,n,t,o,i){let s=o?.diff??i?.diff??t.diff;return{checkpoint:{id:n.checkpointId,name:n.name,takenAt:n.takenAt,org:e},...o?{objects:[...o.plan.objects]}:{},...K(s),carriers:s.objects.reduce((d,a)=>d+re(a),0),differs:xe(o?.diff??t.diff),...o?{selection:o.plan}:{},...i?{kept:i.plan.left}:{},diff:t.diff,estimate:t.estimate,...t.automation?{automation:t.automation}:{},...t.emails?{emails:t.emails}:{},...t.emailsUncounted!==void 0?{emailsUncounted:t.emailsUncounted}:{},...t.deliverability?{deliverability:t.deliverability}:{},...t.refusal?{refusal:t.refusal}:{}}}function Yn(e,n){return n&&xe(e)?3:0}var Gt={needsUnpickedParent:"they come back only with a parent this rewind leaves deleted, or look up a record it leaves deleted, which Salesforce refuses: those lookups are left, the rest written",heldByUnpicked:"records of an object not named made since hang from them and hold some of their values in place: given back but for those",outsideNotAccepted:"records of an object not named made since hang from them, which their deletion would take along: kept, unless --accept-outside",holdsLeft:"records this rewind leaves as they are hang from them, which their deletion would take along: kept",keyTaken:"rows of a custom setting whose owner or name a row made since holds: brought back once it is gone"};function zt(e){let n=[` limited to ${e.objects.join(", ")}: the other objects are left as they are, and what still differs in them is counted apart`],t=e.acts.filter(o=>!o.picked&&o.toDelete>0);t.length>0&&n.push(` also deletes again ${v(t.map(o=>`${o.objectApiName} ${f(o.toDelete)}`))} \u2014 made since, they come back with a record it brings back: leaving them would make a state that never existed`);for(let o of e.left)n.push(` left: ${f(o.count)} ${o.objectApiName} record(s) \u2014 ${Gt[o.reason]}`);return e.needs.length>0&&n.push(` to rewind those too, add ${e.needs.map(o=>`--object ${o.objectApiName} (${f(o.records)} record(s) need it)`).join(", ")}`),e.acts.some(o=>o.picked&&o.toDelete>0)&&n.push(" a record of an object not named that looks up a record it deletes has that lookup emptied by Salesforce, and is dated that second"),n}function Jt(e,n,t){return!t&&e.scope.mode==="picked"&&n.objects.some(o=>o.outside.length>0)}function Vt(e){return e.left.map(n=>` kept: ${f(n.count)} ${n.objectApiName} record(s) \u2014 `+(n.reason==="outsideNotAccepted"?"records outside the checkpoint made since hang from them, which their deletion would take along: kept, unless --accept-outside":Gt[n.reason]))}async function Kt(e,n,t,o){if(!Jt(n,t,o))return;let i=n.objects.map(({objectApiName:s})=>s);return Ee(e,t,i,!1)}function Yt(e,n){let t=new Map(e.objects.map(({objectApiName:i})=>[i.toLowerCase(),i])),o=n.filter(i=>!t.has(i.toLowerCase()));if(o.length>0)throw new b({code:"NOT_HELD",message:`--object: '${e.name}' holds no ${o.join(", ")}. It holds ${v(e.objects.map(i=>i.objectApiName))}. Nothing was run.`},2);return n.flatMap(i=>t.get(i.toLowerCase())??[])}async function Ee(e,n,t,o){let i=await e.request({type:"checkpoint:plan-selection",payload:{checkpointId:n.checkpointId,previewId:n.previewId,objects:[...t],acceptOutside:o},timeoutMs:de});if(i.outcome!=="answered")throw new b(P(i,"The plan of the objects named"));let s=D(i).plan;return{plan:s,diff:dt(n,s)}}var Q={limit:e=>`--max-records ${e}`,mutes:!0,lift:{acceptAutomation:"give --accept-automation to rewind all the same",acceptEmails:"add --accept-emails to rewind all the same",acceptNoUndo:"give --accept-no-undo to rewind all the same",acceptRecreate:"give --accept-recreate to rewind all the same",acceptUnseen:"give --accept-unseen to rewind all the same",maxRecords:"read its preview (--dry-run), then give a --max-records that holds it",refuseWhenActive:"rewind once they are done, or without --refuse-when-active"}};function Xn(e){return e.code==="AUTOMATION"?{...e,message:e.message.replace(ut,Q.lift.acceptAutomation)}:e}function Zn(e){return e.code==="AUTOMATION"?{...e,message:e.message.replace(ft,"give --accept-automation to undo the rewind all the same")}:e}function ti(e,n,t,o="the user SandForge connects as"){return ht(e,n,t,Q.lift,o,Q.mutes)}var Qn={acceptAutomation:!1,acceptNoUndo:!1,acceptRecreate:!1};function Xt(e,n){return[...e?[e]:[],...n.filter(t=>t.code!==e?.code)]}function eo(e,n,t,o){let i=o!==void 0&&o.length>0?`${o.join(", ")} of ${e}`:e,s=K(t),d=s.toRecreate>0?`, and makes ${f(s.toRecreate)} record(s) the recycle bin no longer holds again, with new Ids`:"",a=t.objects.reduce((g,$)=>g+re($),0),r=a>0?`, with ${f(a)} record(s) brought back for a moment that had taken records of the checkpoint along, then deleted again`:"",p=Ut(t),m=p>0?`, and puts ${f(p)} link(s) between files and records back as they were`:"";return`Rewind ${i} to '${n.name}': it deletes the ${f(s.toDelete)} record(s) created since ${E(n.takenAt)}, gives ${f(s.toGiveBack)} record(s) their values from then back, and brings back ${f(s.toBringBack)} record(s) from the recycle bin${r}${d}${m} \u2014 whoever made these changes. What it changes is kept, so it can be undone. Type ${e} to rewind it:`}var R=(e,n)=>e.reduce((t,o)=>t+n(o),0);function Ie(e){let n=R(e.deleted,a=>a.deleted),t=R(e.deleted,a=>a.planned),o=R(e.restored,a=>a.restored+(a.restoredWithout??0)),i=R(e.restored,a=>a.planned),s=R(e.undeleted,a=>a.undeleted+a.alreadyBack),d=R(e.undeleted,a=>a.planned);return{deleted:{planned:t,done:n,left:Math.max(0,t-n-R(e.deleted,a=>a.alreadyGone))},givenBack:{planned:i,done:o,left:Math.max(0,i-o-R(e.restored,a=>a.alreadyGone))},broughtBack:{planned:d,done:s,left:Math.max(0,d-s)}}}function Zt(e){let n=e.recreated??[],t=R(n,i=>i.planned),o=R(n,i=>i.created);return{planned:t,done:o,left:Math.max(0,t-o)}}function to(e){return(e.remade??[]).reduce((n,t)=>{let o=R(e.deleted.filter(i=>i.objectApiName===t.objectApiName),i=>i.deleted);return n+Math.min(o,t.count)},0)}function Qt(e,n){return e===void 0?"another user":n[e]??e}function no(e,n,t){switch(n.reason){case"automation":return e==="rewind"?"kept by your automation, which sets them again on save: rewind --ignore-field <Object.Field> stops comparing such a field":"set again on save by your automation, since the undo gave them back their values";case"changedDuringRewind":return`changed during the ${e} by ${Qt(n.by,t)}: left as they made them`;case"changedSincePreview":return"changed since the preview: rewind again to take them";case"refused":return`refused: ${n.message??"the org gave no reason"}`;case"notInBin":return"no longer in the recycle bin \u2014 emptied from it, or kept there for good \u2014: Salesforce still lists them as deleted but will not bring them back; --accept-recreate makes them again with new Ids";case"goneForGood":return"deleted since and no longer in the recycle bin, and not made again (a file, whose body the checkpoint does not hold, or a record deleted while it was taken): they can't come back";case"kept":return n.message??"kept as they are"}}function en(e,n){return`Stopped before it wrote anything: ${e} is as it was before this rewind. Rewind again to rewind it to '${n}'.`}function oo(e,n,t,o={},i){let s=R(t.residual,h=>h.count),d=t.residual.filter(h=>h.reason==="changedDuringRewind"),a={success:`${e} is back at '${n.name}': read again, nothing differs among the objects and fields it holds.`,partial:`${e} is back at '${n.name}' but for ${f(s)} record(s) that still differ, each said with why:`,unstable:`Someone kept writing to ${e} during the rewind: ${[...new Set(d.map(h=>Qt(h.by,o)))].join(", ")} changed ${f(R(d,h=>h.count))} record(s), left as they made them. Rewind again once they have stopped.`,failure:`Nothing of the rewind of ${e} to '${n.name}' went through: what still differs is said with why:`,cancelled:t.undo===void 0?en(e,n.name):`Stopped part way: ${e} is between '${n.name}' and now. Rewind again to finish: it takes up from what still differs, and undo still returns ${e} to how it was before the rewind.`},r=t.scope;r!==void 0&&t.status==="success"&&(a.success=`${r.objects.join(", ")} of ${e} ${r.objects.length>1?"are":"is"} back at '${n.name}': read again, nothing differs among them.`);let p=Ie(t),m=R(t.undeleted,h=>h.alreadyBack),g=[a[t.status]];if(r!==void 0){let{objects:h,records:l}=r.notRewound;g.push(l>0?` not rewound: ${f(l)} record(s) of ${v(h)} still differ, left as they are \u2014 the rewind was limited to the objects named; add them with --object`:" the objects not named match the checkpoint too")}p.deleted.done>0&&g.push(` deleted ${f(p.deleted.done)} record(s) added since the checkpoint \u2014 created, or brought back from the recycle bin they were in when it was taken \u2014 (in the recycle bin for up to 15 days)`),p.givenBack.done>0&&g.push(` gave ${f(p.givenBack.done)} record(s) back their checkpoint values`),p.broughtBack.done>0&&g.push(` brought back ${f(p.broughtBack.done-m)} record(s) deleted since the checkpoint, with their original Ids`+(m>0?`, and ${f(m)} that came back with them`:""));let $=t.status==="failure"?[]:t.carriers??[];if($.length>0){let h=v($.map(l=>`${l.objectApiName} ${f(l.count)}`));g.push(t.status==="cancelled"?` of them, brought back for a moment: ${h} \u2014 records the checkpoint does not hold that had taken records of it along; stopped before it was through, those it had not deleted again yet are still in the org: rewind again deletes them, with what came back with them`:` of them, brought back for a moment and deleted again: ${h} \u2014 records the checkpoint does not hold that had taken records of it along, back in the recycle bin with what came back with them`)}let w=Zt(t);w.done>0&&g.push(` made again ${f(w.done)} record(s) the recycle bin no longer held, with new Ids`);for(let h of t.draftsLeft??[])g.push(` left as drafts: ${h.objectApiName} ${f(h.count)} (${v(h.ids,3)}) \u2014 made again as drafts, the rewind stopped before it gave them back the status the checkpoint holds: rewind again gives it back to them, an update`);if(g.push(...nn("rewind",e,t)),g.push(...on("rewind",t,o)),t.undo){g.push(` undo it until ${E(t.undo.until)}, sooner if the recycle bin fills: ${ne("checkpoint")} undo --org ${e} --checkpoint ${n.checkpointId}`+(i!==void 0?` --store ${i}`:""));for(let{words:h,of:l}of Mt(t.undo.cannot))g.push(` undo couldn't bring back: ${v(l.map(k=>`${k.objectApiName} ${f(k.count)}`))} \u2014 ${h.result}`)}for(let h of t.removedJournals??[])g.push(` removed the journal of rewind ${h.rewindId} of '${h.name}': undo reaches the last rewind of the org alone`);return g.push(sn(t)),g}function tn(e){return`Stopped before it wrote anything: ${e} is as the rewind left it, and the rewind can still be undone.`}function io(e,n,t){let o=R(t.restored,h=>h.keptChanged)+R(t.deleted,h=>h.keptChanged),i=R([...t.deleted,...t.restored,...t.undeleted],h=>h.refused),s=R(t.residual,h=>h.count)+i,d=`${e} is back as it was before its rewind to '${n.name}'`,a={success:`${d}.`,partial:o>0&&s===0?`${d}, except ${f(o)} record(s) changed since the rewind, left as they are now.`:`${d}, except ${f(s+o)} record(s), each said with why:`,unstable:`Someone changed records of ${e} during the undo: left as they made them, each said below.`,failure:`Nothing of the undo of ${e}'s rewind went through: its reasons are said below.`,cancelled:Fe(t)?tn(e):`Stopped part way: ${e} is between the rewind and how it was before it. Undo again to finish: it takes up what this one left.`},r=Ie(t),p=[a[t.status]],m=to(t),g=R(t.wentAlong??[],h=>h.count),$=r.deleted.done-m-g;$>0&&p.push(` sent back to the recycle bin ${f($)} record(s) the rewind brought back`+(g>0?", with what came back with them":"")),m>0&&p.push(` deleted again ${f(m)} record(s) the rewind made again, with what went with them`);let w=t.carriedAlone??[];return w.length>0&&p.push(` of them, back in the recycle bin on their own: ${v(w.map(h=>`${h.objectApiName} ${f(h.count)}`))} \u2014 they had gone there with a record the rewind brought back for a moment, which stays there; they come back alone, under the parent the checkpoint gave them`),r.broughtBack.done>0&&p.push(` brought back ${f(r.broughtBack.done)} record(s) the rewind deleted`),r.givenBack.done>0&&p.push(` gave ${f(r.givenBack.done)} record(s) back the values they had before the rewind`),o>0&&p.push(` kept ${f(o)} record(s) changed since the rewind: undo leaves them as they are now`),p.push(...nn("undo",e,t)),p.push(...on("undo",t,{})),p.push(sn(t)),p}function nn(e,n,t){let o=t.files;if(o===void 0)return[];let i=e==="rewind"?{unlinked:"removed {n} link(s) added since between files and records: the files stay",relinked:"put back {n} link(s) removed since between files and records, under new Ids",linksUpdated:"gave {n} link(s) between files and records their sharing back"}:{unlinked:"removed again {n} link(s) between files and records the rewind put back",relinked:"put back {n} link(s) between files and records the rewind removed, under new Ids",linksUpdated:"gave {n} link(s) between files and records back the sharing they had before the rewind"},s=["unlinked","relinked","linksUpdated"].filter(d=>o[d]>0).map(d=>` ${i[d].replace("{n}",f(o[d]))}`);return o.linksRefused>0&&s.push(` ${n} refused to write ${f(o.linksRefused)} link(s) between files and records`),s}function on(e,n,t){let o=n.residual.map(i=>` ${i.objectApiName} ${f(i.count)} \u2014 ${no(e,i,t)}`);if(e==="undo")for(let i of[...n.deleted,...n.restored,...n.undeleted])i.refused!==0&&o.push(` ${i.objectApiName} ${f(i.refused)} \u2014 refused: ${i.reasons[0]??"the org gave no reason"}`);for(let i of n.unread??[])o.push(` could not be read again: ${i.objectApiName} \u2014 ${i.reason} (never taken for unchanged)`);return o}function sn(e){return` sent ${f(e.apiRequests.used)} API requests to the org; ${f(e.apiRequests.leftToday)} left today`}function an(e,n,t,o,i){let s=new Map,d=r=>{let p=s.get(r);return p||(p={object:r,deleted:0,givenBack:0,broughtBack:0,refused:0},s.set(r,p)),p};for(let r of o.deleted)d(r.objectApiName).deleted+=r.deleted,d(r.objectApiName).refused+=r.refused;for(let r of o.restored)d(r.objectApiName).givenBack+=r.restored+(r.restoredWithout??0),d(r.objectApiName).refused+=r.refused;for(let r of o.undeleted)d(r.objectApiName).broughtBack+=r.undeleted+r.alreadyBack,d(r.objectApiName).refused+=r.refused;for(let r of o.recreated??[])d(r.objectApiName).refused+=r.refused;let a=(o.unread??[]).map(r=>({object:r.objectApiName,reason:r.reason}));return{checkpoint:{id:t.checkpointId,name:t.name,takenAt:t.takenAt,org:n},rewindId:o.rewindId,status:o.status,...o.scope?{limitedTo:[...o.scope.objects],notRewound:{...o.scope.notRewound}}:{},...Ie(o),...e==="rewind"?{recreated:Zt(o),cannotUndo:(i?.objects??[]).flatMap(r=>r.cannotUndo.filter(p=>p.count>0).map(p=>({object:r.objectApiName,reason:p.reason,count:p.count})))}:{},...e==="rewind"&&(o.carriers??[]).length>0?{carriers:(o.carriers??[]).map(r=>({object:r.objectApiName,count:r.count}))}:{},...e==="rewind"&&(o.draftsLeft??[]).length>0?{draftsLeft:(o.draftsLeft??[]).map(r=>({object:r.objectApiName,count:r.count,ids:[...r.ids]}))}:{},...e==="undo"&&(o.carriedAlone??[]).length>0?{carriedAlone:(o.carriedAlone??[]).map(r=>({object:r.objectApiName,count:r.count}))}:{},...o.files?{files:{...o.files}}:{},...o.undo?{undo:{until:o.undo.until,cannot:o.undo.cannot.map(r=>({object:r.objectApiName,count:r.count,...r.reason!==void 0?{reason:r.reason}:{}}))}}:{},verify:{differences:R(o.residual,r=>r.count)+a.length,stable:o.status!=="unstable",passes:o.passes,notCompared:[...t.ignoredFields]},residual:o.residual.map(r=>({object:r.objectApiName,reason:r.reason,...r.by!==void 0?{by:r.by}:{},count:r.count,...r.message!==void 0?{message:r.message}:{}})),unread:a,objects:[...s.values()],apiRequests:o.apiRequests,result:o}}function rn(e,n){switch(e){case"success":return 0;case"partial":return 3;case"unstable":return 4;case"failure":return 1;case"cancelled":return n!==void 0?oe(n):1}}var so=10*6e4,ao=720*6e4,dn=60*6e4,de=5*6e4,Ct=200,b=class extends Error{constructor(t,o=1,i=[]){super(t.message);this.refusal=t;this.code=o;this.also=i;this.name="Stop"}refusal;code;also};function ro(e){let n=[e.refusal,...e.also];return{refusal:e.refusal,...e.also.length>0?{wouldBeRefused:n.map(t=>V(t)),wouldBeRefusedCodes:n.map(t=>t.code)}:{}}}function D(e){return e.message?.payload??{}}function P(e,n){let t=D(e);if(e.outcome==="unanswered")return{code:"UNANSWERED",message:`${n}: no answer came in time.`};let o=typeof t.message=="string"?t.message:JSON.stringify(t),i=typeof t.code=="string"?t.code:e.outcome.toUpperCase(),{holdingLimit:s}=t;return{code:i,message:o,...typeof s=="number"?{holdingLimit:s}:{}}}function co(e){let n=D(e).alsoRefused;return e.outcome!=="failed"||!Array.isArray(n)?[]:n.flatMap(t=>{let{code:o,message:i}=t??{};return typeof o=="string"&&typeof i=="string"?[{code:o,message:i}]:[]})}async function ho(e=process.argv,n={}){let t=Rn(e),o=h=>{process[t.json?"stderr":"stdout"].write(`${h}
467
- `)},i=h=>{t.json&&process.stdout.write(`${JSON.stringify(h,null,2)}
468
- `)},s=Qe({root:t.storeRoot,...n.locksDir!==void 0?{locksDir:n.locksDir}:{}});if("refusal"in s){let h=`The checkpoints cannot be kept in ${s.refusal.path}: `+Ze(s.refusal,t.storeRoot,"--store <folder>");process.stderr.write(`${h}
469
- `),i({refusal:{code:"STORE_REFUSED",message:h}}),B(1);return}let d=s.store,a=pn(Ot(gn(),"sandforge-checkpoint-")),r=new mt,p=!1,m,g=()=>Promise.resolve(),$,w;try{let h=(n.createHost??pt)({storeDir:a,log:c=>{p&&c.startsWith("[INFO] ")?o(c.slice(7)):c.startsWith("[WARN] ")&&o(`warning: ${c.slice(7)}`)},compose:c=>{c.handlers.setCheckpointStore(d),c.handlers.rewindCheckpointsFromPreviewsAnswered(),c.handlers.setInfraServices({backgroundRegistry:r}),g=()=>c.handlers.sweepCheckpoints(),$=c.handlers,w=c},onPost:c=>{if(c.type!=="operation:progress")return;let u=c.payload?.currentStep;typeof u!="string"||u===m||(m=u,o(` ${u}`))}});p=!0;try{await g()}finally{p=!1}let l=async()=>{let c=await h.request({type:"checkpoint:list",timeoutMs:de});if(c.outcome!=="answered")throw new b(P(c,"The list of checkpoints"));return D(c).checkpoints??[]},k=async c=>{try{return await h.connect(c)}catch(u){throw new b({code:"NOT_CONNECTED",message:u instanceof We?u.message:`${c} could not be reached: ${u instanceof Error?u.message:String(u)}`})}},y=async c=>{if(w===void 0)throw new Error("The host composed no handlers.");return et(await Ue(c.id,w.orgRegistry,w.orgManager)).userId()};switch(t.command){case"list":{let c=await l(),u=t.org!==void 0?_(c,t.org):c,j=t.org!==void 0?{org:t.org,kept:c.length}:void 0;for(let C of On(u,d.root,j))o(C);i(u.map(xn));return}case"take":await mo(t,h,await k(t.org),d,r,o,i);return;case"preview":{let c=await l(),u=ee(G(c,_(c,t.org),t.checkpoint,t.org)),j=Re(u);if(j)throw new b(j);let C=u.checkpoint,O=t.objects.length>0?Yt(C,t.objects):void 0,W=await k(t.org);Ne(W,u,C,t.org,"preview");let q=await h.request({type:"checkpoint:preview",payload:{checkpointId:u.checkpointId,...O?{objects:O}:{},acceptOutside:!1},timeoutMs:dn});if(q.outcome!=="answered")throw new b(P(q,"The preview"));let I=D(q),L=O?await Ee(h,I.diff,O,!1):void 0,N=O?void 0:await Kt(h,C,I.diff,!1),te=L??N,A=te?{...I,diff:te.diff}:I,Pe=Xt(I.refusal,await me({orgName:t.org,preview:A,bounds:{refuseWhenActive:!1},accepted:Qn,writers:()=>Promise.resolve([]),words:Q,user:W.username})),[Le]=Pe;for(let T of Wt(t.org,C,A,W.username))o(T);for(let T of L?zt(L.plan):[])o(T);for(let T of N?Vt(N.plan):[])o(T);for(let T of Pe.slice(I.refusal?1:0))o(` a rewind now would be refused (${T.code}): ${T.message}`);i(Ht(t.org,C,{...I,...Le?{refusal:Le}:{}},L,N)),B(Yn(L?.diff??I.diff,t.failOnChange));return}case"rewind":case"undo":{let c={host:h,registry:r,store:d,listAll:l,connect:k,userIdOf:y,say:o,answerJson:i};t.command==="rewind"?await go(t,c):await yo(t,c);return}case"delete":await wo(t,h,l,o,i);return;case"export":await uo(t,{transfers:St($),listAll:l,say:o,answerJson:i});return;case"import":await fo(t,{transfers:St($),connect:k,say:o,answerJson:i});return;case"replay":await bt(t.replay,{storeRoot:t.storeRoot,storeNamed:t.storeNamed===!0,store:d,...n.locksDir!==void 0?{locksDir:n.locksDir}:{},listAll:l,checkpointsOf:_,resolve:G,say:o,json:t.json});return;case"replays":await vt(t.target,{storeRoot:t.storeRoot,storeNamed:t.storeNamed===!0,say:o,answerJson:i});return}}catch(h){let l=h instanceof b?h:h instanceof we?new b(h.refusal,h.code):new b({code:"FAILED",message:h instanceof Error?h.message:String(h)});process.stderr.write(`${h instanceof we?V(h.refusal):l.message}
465
+ `,$n=["take","list","preview","rewind","undo","delete","export","import","replay","replays"],vn=e=>$n.includes(e),x={switches:["--json"],values:["--org","--store"]},An={take:{words:1,switches:[...x.switches,"--estimate"],values:[...x.values,"--name","--object","--exclude-object","--custom-setting","--ignore-field","--max-total","--keep-days"]},list:{words:1,...x},preview:{words:1,switches:[...x.switches,"--fail-on-change"],values:[...x.values,"--checkpoint","--object"]},rewind:{words:1,switches:[...x.switches,"--dry-run","--accept-automation","--accept-emails","--mute-automation","--accept-no-undo","--accept-recreate","--accept-outside","--accept-unseen","--refuse-when-active","--yes"],values:[...x.values,"--checkpoint","--ignore-field","--object","--max-records"]},undo:{words:1,switches:[...x.switches,"--accept-automation","--accept-emails","--mute-automation","--yes"],values:[...x.values,"--checkpoint"]},delete:{words:1,switches:[...x.switches,"--all","--yes"],values:[...x.values,"--checkpoint"]},export:{words:1,switches:x.switches,values:[...x.values,"--checkpoint","--out","--key-env"]},import:{words:1,switches:x.switches,values:[...x.values,"--file","--key-env","--keep-days"]},replay:{words:1,switches:["--json","--dry-run","--verify","--remove","--preview","--sweep","--sweep-list","--sweep-late","--sweep-untied","--include-changed","--custom-settings","--mask","--keep-contact-points","--no-real-data","--again","--mute-automation","--accept-automation","--accept-emails","--yes",...me.switches],values:["--store","--checkpoint","--from","--file","--key-env","--keep-days","--target","--objects","--exclude-object","--owners","--owner-map","--link","--replay-config","--max-records",...me.values]},replays:{words:1,switches:["--json"],values:["--store","--target"]}},jn={name:"--name",objects:"--object",excluded:"--exclude-object",customSettings:"--custom-setting",ignoredFields:"--ignore-field",maxTotal:"--max-total",keepDays:"--keep-days"},Rn=/^[A-Za-z][A-Za-z0-9_]{0,79}$/;function S(e){process.stderr.write(`${e}
466
+ `),process.exit(2)}function Cn(e){let n=e.toISOString();return`${n.slice(0,10)} ${n.slice(11,16)} UTC`}function Sn(e,n=new Date){let t=e.slice(2);(t.includes("--help")||t.includes("-h"))&&(process.stdout.write(yn),process.exit(0));let o=t[0];if(o===void 0||o.startsWith("-"))return S("Name the command first: take, list, preview, rewind, undo, delete, export, import, replay or replays. Run with --help.");if(!vn(o))return S(`"${o}" is not a command of sandforge checkpoint: take, list, preview, rewind, undo, delete, export, import, replay or replays. Nothing was run. Run with --help.`);qe(t,An[o]);let i=w=>{let c=[];for(let l=1;l<t.length;l++){if(t[l]!==w)continue;let k=t[l+1];if(k===void 0||k.startsWith("--"))return S(`${w} wants a value.`);c.push(k),l++}return c},s=w=>{let c=i(w);return c.length>1&&S(`${w} is given ${c.length} times: give it once.`),c[0]},d=w=>{let c=s(w);if(c!==void 0)return/^\d{1,15}$/.test(c)||S(`${w} takes a whole number, not "${c}".`),Number(c)},a=s("--store"),r={storeRoot:a!==void 0?ye(a):ue(),...a!==void 0?{storeNamed:!0}:{},json:t.includes("--json")},p=s("--org"),m=()=>p??S(`${o} needs --org. Run with --help.`),g=w=>{t.includes("--yes")&&(w===void 0&&S(`${o} --yes needs --checkpoint <id|name>: one that does not ask is told which checkpoint it acts on. Nothing was run.`),w==="latest"&&S(`${o} --yes needs the checkpoint named by its id or its name, not latest: a checkpoint taken since would be the one it acts on. Nothing was run.`))},v=()=>{let w=i("--object"),c=w.find(l=>!Rn.test(l));return c!==void 0&&S(`--object takes an object's API name, not "${c}".`),w.filter((l,k)=>w.findIndex(y=>y.toLowerCase()===l.toLowerCase())===k)};switch(o){case"list":return{...r,command:o,...p!==void 0?{org:p}:{}};case"replay":return{...r,command:o,replay:kt(t,S)};case"replays":return{...r,command:o,...bt(t,S)};case"take":{let w=m(),c=i("--object"),l=i("--exclude-object"),k=i("--custom-setting"),y=k.includes("all")?"all":k,h=i("--ignore-field"),f=d("--max-total"),j={name:s("--name")??Cn(n),mode:c.length>0?"picked":"everything",...c.length>0?{objects:c}:{},...l.length>0?{excluded:l}:{},...y.length>0?{customSettings:y}:{},...h.length>0?{ignoredFields:h}:{},...f!==void 0?{maxTotal:f}:{},keepDays:d("--keep-days")??H},C=Ve.safeParse({...j,orgId:"command-line"});if(!C.success){let O=C.error.issues[0],W=String(O?.path[0]??"");return S(`${jn[W]??W}: ${O?.message??"not read"}. Nothing was run.`)}return{...r,command:o,org:w,take:{...j,name:C.data.name},estimate:t.includes("--estimate")}}case"preview":return{...r,command:o,org:m(),checkpoint:s("--checkpoint")??"latest",failOnChange:t.includes("--fail-on-change"),objects:v()};case"rewind":{let w=m(),c=s("--checkpoint");g(c);let l=i("--ignore-field"),k=_e.safeParse(l);if(!k.success)return S(`--ignore-field: ${k.error.issues[0]?.message??"not read"}. Nothing was run.`);let y=d("--max-records");return y===0&&S('--max-records takes a whole number of 1 or more, not "0". Nothing was run.'),{...r,command:o,org:w,checkpoint:c??"latest",objects:v(),dryRun:t.includes("--dry-run"),acceptAutomation:t.includes("--accept-automation"),acceptEmails:t.includes("--accept-emails"),muteAutomation:t.includes("--mute-automation"),acceptNoUndo:t.includes("--accept-no-undo"),acceptRecreate:t.includes("--accept-recreate"),acceptOutside:t.includes("--accept-outside"),acceptUnseen:t.includes("--accept-unseen"),...y!==void 0?{maxRecords:y}:{},refuseWhenActive:t.includes("--refuse-when-active"),ignoreFields:l,yes:t.includes("--yes")}}case"undo":{let w=m(),c=s("--checkpoint");return g(c),{...r,command:o,org:w,...c!==void 0?{checkpoint:c}:{},acceptAutomation:t.includes("--accept-automation"),acceptEmails:t.includes("--accept-emails"),muteAutomation:t.includes("--mute-automation"),yes:t.includes("--yes")}}case"delete":{let w=m(),c=s("--checkpoint"),l=t.includes("--all");return l&&c!==void 0&&S("Give --checkpoint or --all, not both."),{...r,command:o,org:w,...l?{}:{checkpoint:c??"latest"},all:l,yes:t.includes("--yes")}}case"export":{let w=m(),c=s("--out")??S("export needs --out <file>. Run with --help."),l=jt(s("--key-env"));return{...r,command:o,org:w,checkpoint:s("--checkpoint")??"latest",out:ye(c),...l!==void 0?{keyEnv:l}:{}}}case"import":{let w=m(),c=s("--file")??S("import needs --file <file>. Run with --help."),l=jt(s("--key-env"));return{...r,command:o,org:w,file:ye(c),...l!==void 0?{keyEnv:l}:{},keepDays:d("--keep-days")??H}}}}function jt(e){if(e!==void 0)return!/^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(e)||ae(e)!==void 0?S("--key-env takes the name of an environment variable that holds the key, never the key: a key on the command line stays in the shell\u2019s history and the list of processes. Nothing was run."):e}function Nt(e,n){return e!==void 0&&n!==void 0&&e.length>=15&&e.slice(0,15)===n.slice(0,15)}function _(e,n,t){let o=t!==void 0?[t]:[];for(let i of e){let s=i.checkpoint?.org;s!==void 0&&(s.alias===n||s.username.toLowerCase()===n.toLowerCase())&&o.push(i.organizationId)}return e.filter(i=>o.some(s=>Nt(s,i.organizationId)))}var It="One kept in another folder is read with --store <folder>, or with SANDFORGE_JOURNAL_DIR set as when it was taken \u2014 in a CI job, a folder its cache restores; one taken on another machine comes here by export there, then import here.";function re(e){return`"${oe("checkpoint")} list --org ${e}" names those it holds. ${It}`}function G(e,n,t,o){if(Fe.safeParse(t).success){let s=e.find(d=>d.checkpointId===t);return s?{entry:s}:{none:`No checkpoint ${t} is kept in the folder read. ${re(o)}`}}if(t==="latest"){let s=n[0];return s?{entry:s}:{none:`No checkpoint of ${o} is kept in the folder read. ${re(o)}`}}let i=n.filter(s=>s.checkpoint?.name===t);return i.length===1?{entry:i[0]}:i.length===0?{none:`No checkpoint of ${o} named '${t}' is kept in the folder read. `+re(o)}:{ambiguous:`${i.length} checkpoints of ${o} are named '${t}': give the id of the one you mean with --checkpoint (${i.map(s=>s.checkpointId).join(", ")}).`}}function Ce(e){if(e.valid)return;let n=e.checkpoint?`'${e.checkpoint.name}'`:e.checkpointId;switch(e.why){case"damaged":return{code:"DAMAGED",message:`The file of checkpoint ${e.checkpointId} cannot be read: it can only be deleted.`};case"taking":return{code:"TAKING",message:`The checkpoint ${n} is being taken, or its take never ended: it can be previewed once taken, or deleted.`};case"failed":return{code:"FAILED",message:`The take of checkpoint ${n} failed: it can only be deleted.`};case"refreshed":return{code:"OTHER_ORG",message:`This sandbox was refreshed${e.refreshedAt?` on ${e.refreshedAt.slice(0,10)}`:""}: it is another org now, and the checkpoint ${n} is of the org before it. It no longer rewinds. ${Rt(e)}`};case"scratchExpired":return{code:"SCRATCH_EXPIRED",message:`The scratch org of checkpoint ${n} has expired: its checkpoints no longer rewind it. ${Rt(e)}`};default:return{code:"INVALID",message:`The checkpoint ${n} cannot be previewed.`}}}function Se(e){let n=e.checkpoint?.org,t=e.why==="refreshed"&&n!==void 0?n.alias??n.username:"<alias>";return`${ke(e.checkpointId,t)} --dry-run`}function Rt(e){return`${he.replace(/\.$/,"")}: ${Se(e)}`}function Dt(e){return!e.valid&&(e.why==="refreshed"||e.why==="scratchExpired")}var u=e=>e.toLocaleString("en-US");function E(e){let n=new Date(Date.parse(e)).toISOString();return`${n.slice(0,10)} ${n.slice(11,16)} UTC`}function $e(e){let n=new Date(Date.parse(e)).toISOString();return`${n.slice(0,10)} ${n.slice(11,19)} UTC`}var U=e=>`${it(e/(1024*1024))} MB`;function $(e,n=8){if(e.length===0)return"\u2014";let t=e.slice(0,n).join(", ");return e.length>n?`${t} \u2026 (+${e.length-n})`:t}function Q(e){return e.objects.reduce((n,t)=>n+t.records,0)}function Oe(e){return e===null?"kept until you delete it":`kept until ${E(e)}`}function z(e){return e.org.alias??e.org.username}var On=/^Left out(?::\s*|\s+(?=as asked\b))/;function Pt(e,n){let t=[...n,...e.flatMap(({code:s,records:d})=>s==="pastTheLimit"&&d!==void 0?[d]:[])],o=t.filter(s=>s<=F).reduce((s,d)=>s+d,0),i=new Map;for(let{objectApiName:s,reason:d,code:a,records:r}of e){let p=d;if(a==="pastTheLimit"&&r!==void 0&&r<=F){let m=ot(t,r);p=m>F?`${d} With it, every object no larger is kept, more than ${F} records in all, past any --max-total: --exclude-object <ApiName> leaves some out.`:`${d} --max-total ${m}${m===o?" or more":""} holds it.`}i.set(p,[...i.get(p)??[],s])}return[...i].map(([s,d])=>` left out: ${$(d)} \u2014 ${s.replace(On,"")}`)}var xn={fls:"hidden from the user SandForge connects as by field-level security: Rewind won\u2019t put them back",encrypted:"encrypted, and the user SandForge connects as can\u2019t view encrypted data: Rewind won\u2019t touch them",base64:"the content of files and other binary values, which a checkpoint doesn\u2019t hold",compound:"compound fields, kept through the fields they are made of"};function Lt(e){let n=new Map;for(let t of e)for(let{field:o,reason:i}of t.leftOutFields)n.set(i,[...n.get(i)??[],`${t.objectApiName}.${o}`]);return[...n].map(([t,o])=>` fields left out (${o.length}): ${$(o)} \u2014 ${xn[t]??t}`)}function Tt(e){let n=e.filter(t=>!t.undeletable).map(t=>t.objectApiName);return n.length===0?[]:[` deleted ${$(n)} records come back from the recycle bin only with their parent`]}function Bt(e){return` about ${u(e.seconds)} s \xB7 about ${u(e.apiRequests)} API requests of the ${u(e.apiRequestsLeft)} left today`+(e.bytes>0?` \xB7 about ${U(e.bytes)} on this machine`:"")}var Ct={damaged:"its file cannot be read: it can only be deleted",taking:"being taken, or its take never ended: it can only be deleted unless it ends",failed:"its take failed: it can only be deleted",refreshed:"of the org before its refresh: it no longer rewinds, and replays into another org",scratchExpired:"its scratch org has expired: it no longer rewinds, and replays into another org"};function En(e,n,t){if(e.length===0&&t!==void 0){let i=t.kept===0?"":`, which keeps ${t.kept===1?"1 of another org":`${t.kept} of other orgs`}: "${oe("checkpoint")} list" names ${t.kept===1?"it":"them"}`;return[`No checkpoint of ${t.org} is kept in ${n}${i}. ${It}`]}if(e.length===0)return[`No checkpoint is kept in ${n}.`];let o=[];for(let i of e){let s=i.checkpoint;if(!s){o.push(`${i.checkpointId} ${Ct.damaged}`);continue}if(o.push(`${i.checkpointId} '${s.name}' ${z(s)} taken ${E(s.takenAt)} ${u(Q(s))} records in ${s.objects.length} objects ${U(s.bytes)} `+Oe(s.expiresAt)),!i.valid){let d=i.why==="refreshed"&&i.refreshedAt?`refreshed on ${i.refreshedAt.slice(0,10)}: `:"";o.push(` ${d}${Ct[i.why??""]??"it cannot be previewed"}`),Dt(i)&&(o.push(` replay it: ${Se(i)}`),s.expiresAt!==null&&o.push(` deleted from this machine on ${E(s.expiresAt)}: to replay it after, Keep it in the editor, or export it and replay the file`))}i.scratchExpiresSoon&&s.org.scratchExpiresAt!==void 0&&o.push(` its scratch org expires on ${s.org.scratchExpiresAt.slice(0,10)}: its checkpoints then no longer rewind it, whatever --keep-days said, and still replay into another org`),i.expiresSoon&&s.expiresAt!==null&&o.push(` expires on ${E(s.expiresAt)}: take a new one, or keep this one in the editor`),i.binReachSince&&o.push(` records deleted before ${i.binReachSince.slice(0,10)} can't come back with their Id (recycle bin), sooner if the bin fills: a rewind makes them again, with new Ids`),i.undo&&o.push(` rewound: the rewind can be undone until ${E(i.undo.until)}`)}return o}function Nn(e){let n=e.checkpoint;return{id:e.checkpointId,name:n?.name??null,org:n?z(n):null,organizationId:e.organizationId,takenAt:n?.takenAt??null,records:n?Q(n):null,bytes:n?.bytes??null,expiresAt:n?n.expiresAt:null,expiresSoon:e.expiresSoon===!0,scratchExpiresSoon:e.scratchExpiresSoon===!0,binReachSince:e.binReachSince??null,...n?.lastRewind?{lastRewind:{...n.lastRewind,undoable:e.undo!==void 0}}:{},valid:e.valid,...e.why!==void 0?{why:e.why}:{},...e.refreshedAt!==void 0?{refreshedAt:e.refreshedAt}:{},...Dt(e)?{replayWith:Se(e)}:{}}}function Ft(e){return e.refusal!==void 0&&e.objects.length===0&&e.leftOut.length===0}function In(e){return Ft(e)?{mode:e.mode,refusal:e.refusal}:{...e}}function ve(e){if(e.code!=="TOO_MANY_RECORDS")return e;let n="pick fewer objects (--exclude-object <ApiName> leaves one out)",t=`(${u(fe)} unless given)`,o=e.holdingLimit,i=o===void 0?`${n}, or raise the limit with --max-total <n> ${t}`:o>F?`${n}: no --max-total holds them all, ${u(F)} at most`:`${n}, or raise the limit with --max-total ${o} ${t}`;return{...e,message:e.message.replace(/: pick fewer objects\./,`: ${i}.`)}}function Dn(e,n){if(Ft(n))return[`refused: ${n.refusal.message}`];let t=n.objects.filter(i=>i.records>0).length,o=new Map;for(let{namespace:i}of n.objects)i!==void 0&&o.set(i,(o.get(i)??0)+1);return[`a checkpoint of ${e} would keep ${n.objects.length} objects (${t} hold records; ${n.objects.length-t} are empty \u2014 what is created there later is caught too), about ${u(n.estimate.records)} records`,...[...o].map(([i,s])=>` includes ${s} objects of the ${i} package`),Bt(n.estimate),...Pt(n.leftOut,n.objects.map(i=>i.records)),...Lt(n.objects),...Tt(n.objects),...n.files?Ln(n.files):[],...Pn(n),...n.refusal?[`refused: ${ve(n.refusal).message}`]:[]]}function _t(e){let n=e.records===void 0?void 0:`${u(e.records)} ${e.records===1?"row":"rows"}`,t=[e.kind,n].filter(o=>o!==void 0);return t.length>0?`${e.objectApiName} (${t.join(", ")})`:e.objectApiName}function Ut(e){return _t({objectApiName:e.objectApiName,...e.customSetting!==void 0?{kind:e.customSetting}:{},records:e.records})}function Pn(e){let n=e.objects.filter(i=>i.customSetting!==void 0),t=new Set(n.map(i=>i.objectApiName)),o=(e.customSettings??[]).filter(i=>!t.has(i.objectApiName));return[...n.length>0?[` custom settings kept: ${$(n.map(Ut))} \u2014 a rewind sets their rows back as the checkpoint holds them, whoever changed them since`]:[],...o.length>0?[` custom settings not kept: ${$(o.map(_t))} \u2014 --custom-setting <ApiName|all> keeps them`]:[]]}function Ln(e){return e.held?[" files: it keeps which files are attached to its records (Salesforce Files, classic attachments) and each file's latest version, not its content; a rewind deletes the files attached to them since and brings back those deleted since. A file attached to no record it holds, a user's own or a library's, is left as it is",...Mt(e.addedToPicked),...e.queryAllFiles?[]:[xe]]:[" files: not kept \u2014 a rewind leaves the files attached since as they are"]}function Mt(e){return e.length>0?[` added to the objects picked: ${e.join(", ")} \u2014 without them a rewind would leave the files attached since as they are`]:[]}var xe=" the user the alias connects as doesn't have Query All Files: other users' files that no record of the checkpoint is attached to (in a library the user is not a member of, say) are not seen, nor counted among the files left; files attached to its records are seen";function Tn(e,n,t=[]){let o=e.movedWhileTaken,i=o.changed+o.deleted+o.created;return[`taken '${e.name}' (${e.checkpointId}) of ${z(e)}: ${u(Q(e))} records in ${e.objects.length} objects, ${U(e.bytes)} on this machine, ${Oe(e.expiresAt)}`,` of ${$e(e.readFrom)}, read until ${$e(e.takenAt)} on the org's clock`,...i>0?[` ${u(i)} records changed while it was taken (${o.changed} changed, ${o.deleted} deleted, ${o.created} created): it holds them as they were read, and a rewind treats them as changed since. Take checkpoints when nobody works in the org.`]:[],...Pt(e.scope.leftOut,e.objects.map(s=>s.records)),...Lt(e.objects),...e.ignoredFields.length>0?[` not compared, nor written back (you chose): ${e.ignoredFields.join(", ")}`]:[],...Tt(e.objects),...Bn(e.objects),...e.files?Fn(e,e.files,t):[],` it holds the records' values unencrypted, in files only you can read: ${n}`]}function Bn(e){let n=e.filter(t=>t.customSetting!==void 0);return n.length===0?[]:[` custom settings kept: ${$(n.map(Ut))} \u2014 a rewind sets their rows back as the checkpoint holds them`]}function Fn(e,n,t){let o=n.readByIds??[],i=new Set(t.map(a=>a.toLowerCase())),s=new Set(e.objects.map(({objectApiName:a})=>a.toLowerCase())),d=e.scope.mode==="picked"?Je.filter(a=>s.has(a.toLowerCase())&&!i.has(a.toLowerCase())):[];return[` files: ${u(n.anchored)} attached to its records by ${u(n.links)} link(s): a rewind takes back what is attached to them since`,...Mt(d),...o.length>0?[` the links of ${$(o)} were read by lists of record Ids: ${z(e)} refused one query, or answered too late`]:[],...e.takenBy.queryAllFiles===!1?[xe]:[]]}function _n(e,n){let t=Object.entries(e.byPhase).map(([i,s])=>{let d=n?.requestsByPhase?.[i];return d===void 0||d===s?`${i} ${s}`:`${i} ${s} (${d})`}),o=n?`, about ${u(n.apiRequests)} estimated`:"";return` sent ${u(e.total)} API requests to the org${o}: ${t.join(", ")}`}var St=e=>e.toDelete.createdSince+e.toDelete.broughtBackSince+e.toDelete.comesBackWithParent,J=e=>e.toBringBack.inBin+e.toBringBack.withParent+e.toBringBack.deletedWhileTaken,Ae=e=>e.cannotUndo.reduce((n,t)=>n+t.count,0),Z=e=>e.toRecreate??0,de=e=>e.toBringBack.carriers??0;function Wt(e){let n=e.files;return n===void 0?0:n.unlink+n.relink+n.updateLinks}function Un(e){let n=e.files;return n===void 0?0:n.outsideAdded+n.outsideDeleted}function Mn(e){let n=e.schemaDrift;return n===void 0?0:n.removed.length+(n.hidden?.length??0)+(n.uncertain?.fields.length??0)}function Ee(e){let n=Y(e);return n.toDelete+n.toGiveBack+n.toBringBack+n.toRecreate>0||Wt(e)+Un(e)>0||e.objects.some(t=>Ae(t)>0||t.unexplained>0||Mn(t)>0)||e.unread.length>0}var Wn={goneForGood:"deleted since and no longer in the recycle bin, and not made again \u2014 a file, whose body the checkpoint does not hold, or a record deleted while it was taken: they can\u2019t come back",convertedLead:"leads converted since: Salesforce can\u2019t unconvert a lead",activatedContract:"contracts activated since: Salesforce won\u2019t set them back to Draft",deletedWithCreatedParent:"deleted with a parent created since that Salesforce does not undelete on its own: they come back with that parent only",deletedWithParentOutside:"deleted with their parent, a record of an object the checkpoint does not hold: they come back with that parent only, which a checkpoint that holds its object brings back",newFileVersion:"files given a new version since: Salesforce deletes no version and won\u2019t make an older one the latest again, so they keep their new content; the content each had is still in its version history, and their titles are given back",deletedByOther:"deleted since by another user: only View All Data and Modify All Data restore those; they stay in the recycle bin, never made again",outOfReach:"out of reach: without View All Data and Modify All Data, nothing shows what others deleted of an object held through the records it hangs from; they may be in the recycle bin out of sight, and are never made again"},qn=[{reason:"onlyWithParent",preview:"Salesforce undeletes them only with their parent, and their parent stays",result:"Salesforce undeletes them only with their parent"},{reason:"deletedBeforeParent",preview:"deleted before a record they point at, which the rewind deletes next: Salesforce cannot bring them back after that",result:"deleted before a record they point at, which the rewind deleted next: Salesforce cannot bring them back after that"}];function qt(e){return qn.flatMap(n=>{let t=e.filter(o=>(o.reason??"onlyWithParent")===n.reason);return t.length>0?[{words:n,of:t}]:[]})}function Hn(e,n){let{automation:t,deliverability:o}=n;if(!t||!o)return[];let i=X(n.diff),{line:s}=Qe({act:"rewind",orgName:e,automation:t,steps:i,accepted:!0,mayMute:!1,...Ze({automation:t,steps:i}),reading:o.reading}).gate;return s!==void 0?[` ${s}`]:[]}function Gn(e,n){return n.map(t=>{let o=[...new Set(t.objects.flatMap(s=>s.sentBy))],i=` emails: ${e}'s automation sends about ${Xe(t.emails,t.limit)} as the rewind writes (${$(o,4)})`+(t.alertsCounted?`, its email alerts among them: ${e} counts them against its single emails, as a Developer Edition does`:"");return t.verdict==="unread"?`${i}; what it has left today could not be read (${t.unread??""})`:t.verdict==="fits"?`${i}; ${t.remaining??0} of ${t.max??0} left today`:`${i}, more than the ${t.remaining??0} of ${t.max??0} left today: a rewind is refused`})}function zn(e,n){if(!e||n.length===0)return"";let t=le(e,{giveBack:n}).map(o=>`${o.objectApiName}: '${o.name}'`);return t.length>0?`, on which runs ${$(t,4)}`:""}function Jn(e,n,t=[]){let o=e.objects.filter(a=>ze[a.objectApiName]!==void 0),i=o.filter(a=>Z(a)>0),s=o.filter(a=>J(a)>0&&!t.includes(a.objectApiName)),d=[];return i.length>0&&d.push(` made as drafts first: ${$(i.map(a=>`${a.objectApiName} ${u(Z(a))}`))} \u2014 Salesforce refuses an order or a contract made past Draft, and an order takes its products only as a draft: one past Draft at the checkpoint is made at the org's Draft status, the records under it next, then given its status back, an update`+zn(n,i.map(a=>a.objectApiName))),s.length>0&&d.push(` if Salesforce answers that an order or a contract to bring back is no longer in the recycle bin, --accept-recreate makes it again as a draft, then gives it its status back, an update: ${$(s.map(a=>`${a.objectApiName} ${u(J(a))}`))}`),d}function Vn(e,n,t=!1){if(!n)return{objects:[],fired:[]};let o=X(e),i=[],s=new Set;for(let d of e.objects){if(J(d)===0)continue;let a=lt(n,o,[d.objectApiName],t);if(!(a.fired.length===0&&!a.blind)){i.push(d.objectApiName);for(let r of a.fired)s.add(`${r.objectApiName}: '${r.name}'`)}}return{objects:i,fired:[...s]}}function Kn(e,n,t){let o=le(n,t),i=[];for(let d of n.objects){let a=o.filter(g=>g.objectApiName===d.objectApiName),r=[...new Set(a.filter(g=>g.kind!=="trigger").map(g=>`'${g.name}'`))],p=[...new Set(a.filter(g=>g.kind==="trigger").map(g=>g.name))],m=[...r.length>0?[`${r.length} flow(s) or rule(s): ${$(r,4)}`]:[],...p.length>0?[`${p.length} Apex trigger(s): ${$(p,4)}`]:[]];m.length>0&&i.push(` ${d.objectApiName}: ${m.join("; ")}`)}return[...i.length>0?[` what ${e} runs as a rewind writes (updates, deletes, records brought back):`]:[],...i,...n.unread.map(d=>` not read of its automation: ${d.part} \u2014 ${d.reason}`)]}function Ht(e,n,t,o="the user SandForge connects as",i=!1){let{diff:s}=t,d=Y(s),a=[`Rewind ${e} to '${n.name}' (${E(n.takenAt)}), read at ${$e(s.readAt)}:`,` ${u(d.toDelete)} to delete \xB7 ${u(d.toGiveBack)} to give back \xB7 ${u(d.toBringBack)} to bring back`+(d.toRecreate>0?` \xB7 ${u(d.toRecreate)} to make again`:"")];!Ee(s)&&!s.objects.some(h=>h.outside.length>0)&&a.push(` ${e} is as it was at '${n.name}' among the objects and fields it holds: nothing to rewind.`);let r=s.objects.filter(h=>St(h)+h.toGiveBack.records+J(h)+Z(h)+Ae(h)>0);if(r.length>0){let h=Math.max(6,...r.map(f=>f.objectApiName.length));a.push(` ${"Object".padEnd(h)} ${"Delete".padStart(8)} ${"Give back".padStart(9)} ${"Bring back".padStart(10)} ${"Can't undo".padStart(10)}`);for(let f of r)a.push(` ${f.objectApiName.padEnd(h)} ${u(St(f)).padStart(8)} ${u(f.toGiveBack.records).padStart(9)} ${u(J(f)).padStart(10)} ${u(Ae(f)).padStart(10)}`)}let p=new Map;for(let h of s.objects)for(let[f,j]of Object.entries(h.lastChangedBy))p.set(f,(p.get(f)??0)+j);p.size>0&&a.push(` last changed by: ${[...p].sort((h,f)=>f[1]-h[1]).map(([h,f])=>`${s.userNames[h]??h} ${u(f)}`).join(" \xB7 ")}`),s.activeLastHour.length>0&&a.push(` people working in ${e} in the last hour: ${s.activeLastHour.map(h=>s.userNames[h]??h).join(", ")}`);let m=s.objects.filter(h=>h.touched>0);m.length>0&&a.push(` touched since but holding their checkpoint values: ${$(m.map(h=>`${h.objectApiName} ${u(h.touched)}`))}`);let g=s.objects.filter(h=>de(h)>0);g.length>0&&a.push(` brought back for a moment: ${$(g.map(h=>`${h.objectApiName} ${u(de(h))}`))} \u2014 records the checkpoint does not hold that took records of it along when deleted since: Salesforce gives those back with them only, so they come back, then go back to the recycle bin with what came back with them; what the org runs on them runs twice`);let v=new Map;for(let h of s.objects)for(let f of h.cannotUndo)f.count!==0&&v.set(f.reason,[...v.get(f.reason)??[],`${h.objectApiName} ${u(f.count)}`]);for(let[h,f]of v)a.push(` can't be taken back: ${$(f)} \u2014 ${Wn[h]??h}`);let w=s.objects.filter(h=>Z(h)>0);w.length>0&&a.push(` to make again, with new Ids: ${$(w.map(h=>`${h.objectApiName} ${u(Z(h))}`))} \u2014 deleted since and no longer in the recycle bin: made again from the checkpoint, the lookups it holds that named them naming the new Ids; anything outside Salesforce that names their old Ids no longer finds them`);let c=d.toBringBack>0?Vn(s,t.automation,i):void 0;if(c){let h=c.fired.length>0?`making them again runs ${$(c.fired,4)}`:"what runs as they are made again could not all be read";a.push(" if Salesforce answers that a record to bring back is no longer in the recycle bin \u2014 it still lists one emptied from it as deleted \u2014, --accept-recreate makes it again with a new Id, with what was to come back with it; without it, the rewind leaves them and names them"+(c.objects.length>0?`; ${$(c.objects)} records it leaves all the same, with what was to come back with them, and names them: ${h}, which this rewind does not ask about \u2014 a rewind after it counts them to make again, and asks`:""))}a.push(...Jn(s,t.automation,c?.objects));let l=s.objects.filter(h=>h.unexplained>0);l.length>0&&a.push(` left as they are: ${$(l.map(h=>`${h.objectApiName} ${u(h.unexplained)}`))} \u2014 records the checkpoint doesn't hold although they're dated before it (a load with back-dated creation dates?); a rewind deletes nothing it cannot prove was created since`);for(let{words:h,of:f}of qt(s.undoCannot))a.push(` undo couldn't bring back: ${$(f.map(j=>`${j.objectApiName} ${u(j.count)}`))} \u2014 ${h.preview}`);for(let{objectApiName:h,children:f,records:j}of s.unseen??[])a.push(` also deleted with them, out of sight: deleting ${u(j)} ${h} also deletes what ${o} can't see under them in ${$(f)}; Rewind can't count those, and deletes them only with --accept-unseen`);for(let h of s.objects)for(let f of h.outside)a.push(h.objectApiName===Gt&&f.objectApiName===Yn?` also attached outside the checkpoint: ${u(f.parents)} file(s) it deletes, by ${u(f.count)} link(s) to a library, a group or a record of another object \u2014 deleting them removes them from there as well`:f.objectApiName===K?` also deleted with them, outside the checkpoint: ${u(f.count)} ${K} in which ${e}'s duplicate rules reported ${u(f.parents)} ${h.objectApiName} since the checkpoint \u2014 an undo brings ${f.count===1?"it back without its":"them back without their"} items, which Salesforce does not return`:` also deleted with them, outside the checkpoint: ${u(f.count)} ${f.objectApiName} created under ${u(f.parents)} ${h.objectApiName}`);a.push(...Xn(e,s));let k=s.objects.flatMap(h=>{let f=h.schemaDrift,j=new Set([...f?.removed??[],...f?.hidden??[],...f?.uncertain?.fields??[]]);return h.notCompared.filter(C=>!j.has(C)).map(C=>`${h.objectApiName}.${C}`)});k.length>0&&a.push(` not compared (you chose): ${$(k)}`);for(let h of s.objects){let f=h.schemaDrift;if(!f)continue;let j=C=>C.map(O=>`${h.objectApiName}.${O}`);f.removed.length>0&&a.push(` fields deleted since: ${$(j(f.removed))} \u2014 restore them from Deleted Fields, then rewind`),(f.hidden??[]).length>0&&a.push(` fields hidden from ${o} by field-level security since: ${$(j(f.hidden??[]))} \u2014 rewind does not put them back; give ${o} read and edit access to them, then rewind again`),f.uncertain!==void 0&&f.uncertain.fields.length>0&&a.push(` fields gone from what ${e} shows ${o}: ${$(j(f.uncertain.fields))} \u2014 deleted since (restore them from Deleted Fields within 15 days), or hidden by field-level security (give ${o} read and edit access); rewind does not put them back`+(f.uncertain.reason!==void 0?` (which, ${e} would not say: ${f.uncertain.reason})`:"")),f.added.length>0&&a.push(` fields added since, their values left alone: ${$(j(f.added))}`),f.changed.length>0&&a.push(` fields changed since, tried one by one: ${$(j(f.changed))}`)}let y=s.fieldsNotChecked??0;y>0&&a.push(` fields not checked for changes in ${u(y)} objects nothing changed in: a rewind writes nothing there`);for(let h of s.unread)a.push(` could not be read: ${h.objectApiName} \u2014 ${h.reason} (never taken for unchanged)`);return t.automation&&a.push(...Kn(e,t.automation,X(s))),t.emails&&a.push(...Gn(e,t.emails)),t.emailsUncounted!==void 0&&a.push(` emails: not counted, ${t.emailsUncounted} could not be read \u2014 what they send as the rewind writes is not known; --accept-automation covers it`),a.push(...Hn(e,t)),a.push(Bt(t.estimate)),t.refusal&&a.push(` a rewind now would be refused (${t.refusal.code}): ${t.refusal.message}`),a}var Gt="ContentDocument",Yn="ContentDocumentLink";function Xn(e,n){let t=n.files;if(t===void 0)return[];let o=[];t.unlink>0&&o.push(` links to remove: ${u(t.unlink)} added since between a file and a record that both stay \u2014 the file stays, no longer attached to that record`),t.relink>0&&o.push(` links to put back: ${u(t.relink)} removed since between a file and a record that both stay, each under a new Id: Salesforce keeps no removed link in the recycle bin`),t.updateLinks>0&&o.push(` links to give their sharing back: ${u(t.updateLinks)} \u2014 who sees the file from the record, and with what access; a link to an account keeps its access, which Salesforce doesn't let change`),t.outsideAdded>0&&o.push(` kept: ${u(t.outsideAdded)} file(s) added since, as no record of this checkpoint links to them (a user's own, a library's)`),t.outsideDeleted>0&&o.push(` left in the recycle bin: ${u(t.outsideDeleted)} file(s) deleted since, as no record of this checkpoint linked to them`);let i=n.objects.find(a=>a.objectApiName===Gt),s=i===void 0?0:J(i),{storage:d}=t;return s>0&&d.bringBack>0&&o.push(` file storage: bringing back ${u(s)} file(s) takes ${U(d.bringBack)} again; `+(d.remaining===void 0?`${e} did not say how much it has left`:`${e} has ${U(d.remaining)} left`)),d.undo>0&&o.push(` undo would bring back the files this rewind deletes: ${U(d.undo)} of file storage again`),t.blindSpot&&o.push(xe),o}function zt(e,n,t,o,i){let s=o?.diff??i?.diff??t.diff;return{checkpoint:{id:n.checkpointId,name:n.name,takenAt:n.takenAt,org:e},...o?{objects:[...o.plan.objects]}:{},...Y(s),carriers:s.objects.reduce((d,a)=>d+de(a),0),differs:Ee(o?.diff??t.diff),...o?{selection:o.plan}:{},...i?{kept:i.plan.left}:{},diff:t.diff,estimate:t.estimate,...t.automation?{automation:t.automation}:{},...t.emails?{emails:t.emails}:{},...t.emailsUncounted!==void 0?{emailsUncounted:t.emailsUncounted}:{},...t.deliverability?{deliverability:t.deliverability}:{},...t.refusal?{refusal:t.refusal}:{}}}function Zn(e,n){return n&&Ee(e)?3:0}var Jt={needsUnpickedParent:"they come back only with a parent this rewind leaves deleted, or look up a record it leaves deleted, which Salesforce refuses: those lookups are left, the rest written",heldByUnpicked:"records of an object not named made since hang from them and hold some of their values in place: given back but for those",outsideNotAccepted:"records of an object not named made since hang from them, which their deletion would take along: kept, unless --accept-outside",holdsLeft:"records this rewind leaves as they are hang from them, which their deletion would take along: kept",keyTaken:"rows of a custom setting whose owner or name a row made since holds: brought back once it is gone"};function Vt(e){let n=[` limited to ${e.objects.join(", ")}: the other objects are left as they are, and what still differs in them is counted apart`],t=e.acts.filter(o=>!o.picked&&o.toDelete>0);t.length>0&&n.push(` also deletes again ${$(t.map(o=>`${o.objectApiName} ${u(o.toDelete)}`))} \u2014 made since, they come back with a record it brings back: leaving them would make a state that never existed`);for(let o of e.left)n.push(` left: ${u(o.count)} ${o.objectApiName} record(s) \u2014 ${Jt[o.reason]}`);return e.needs.length>0&&n.push(` to rewind those too, add ${e.needs.map(o=>`--object ${o.objectApiName} (${u(o.records)} record(s) need it)`).join(", ")}`),e.acts.some(o=>o.picked&&o.toDelete>0)&&n.push(" a record of an object not named that looks up a record it deletes has that lookup emptied by Salesforce, and is dated that second"),n}function Kt(e,n,t){return!t&&e.scope.mode==="picked"&&n.objects.some(o=>o.outside.length>0)}function Yt(e){return e.left.map(n=>` kept: ${u(n.count)} ${n.objectApiName} record(s) \u2014 `+(n.reason==="outsideNotAccepted"?"records outside the checkpoint made since hang from them, which their deletion would take along: kept, unless --accept-outside":Jt[n.reason]))}async function Xt(e,n,t,o){if(!Kt(n,t,o))return;let i=n.objects.map(({objectApiName:s})=>s);return Ne(e,t,i,!1)}function Zt(e,n){let t=new Map(e.objects.map(({objectApiName:i})=>[i.toLowerCase(),i])),o=n.filter(i=>!t.has(i.toLowerCase()));if(o.length>0)throw new b({code:"NOT_HELD",message:`--object: '${e.name}' holds no ${o.join(", ")}. It holds ${$(e.objects.map(i=>i.objectApiName))}. Nothing was run.`},2);return n.flatMap(i=>t.get(i.toLowerCase())??[])}async function Ne(e,n,t,o){let i=await e.request({type:"checkpoint:plan-selection",payload:{checkpointId:n.checkpointId,previewId:n.previewId,objects:[...t],acceptOutside:o},timeoutMs:ce});if(i.outcome!=="answered")throw new b(P(i,"The plan of the objects named"));let s=D(i).plan;return{plan:s,diff:ht(n,s)}}var ee={limit:e=>`--max-records ${e}`,mutes:!0,lift:{acceptAutomation:"give --accept-automation to rewind all the same",acceptEmails:"add --accept-emails to rewind all the same",acceptNoUndo:"give --accept-no-undo to rewind all the same",acceptRecreate:"give --accept-recreate to rewind all the same",acceptUnseen:"give --accept-unseen to rewind all the same",maxRecords:"read its preview (--dry-run), then give a --max-records that holds it",refuseWhenActive:"rewind once they are done, or without --refuse-when-active"}};function Qn(e){return e.code==="AUTOMATION"?{...e,message:e.message.replace(pt,ee.lift.acceptAutomation)}:e}function eo(e){return e.code==="AUTOMATION"?{...e,message:e.message.replace(mt,"give --accept-automation to undo the rewind all the same")}:e}function ii(e,n,t,o="the user SandForge connects as"){return ut(e,n,t,ee.lift,o,ee.mutes)}var to={acceptAutomation:!1,acceptNoUndo:!1,acceptRecreate:!1};function Qt(e,n){return[...e?[e]:[],...n.filter(t=>t.code!==e?.code)]}function no(e,n,t,o){let i=o!==void 0&&o.length>0?`${o.join(", ")} of ${e}`:e,s=Y(t),d=s.toRecreate>0?`, and makes ${u(s.toRecreate)} record(s) the recycle bin no longer holds again, with new Ids`:"",a=t.objects.reduce((g,v)=>g+de(v),0),r=a>0?`, with ${u(a)} record(s) brought back for a moment that had taken records of the checkpoint along, then deleted again`:"",p=Wt(t),m=p>0?`, and puts ${u(p)} link(s) between files and records back as they were`:"";return`Rewind ${i} to '${n.name}': it deletes the ${u(s.toDelete)} record(s) created since ${E(n.takenAt)}, gives ${u(s.toGiveBack)} record(s) their values from then back, and brings back ${u(s.toBringBack)} record(s) from the recycle bin${r}${d}${m} \u2014 whoever made these changes. What it changes is kept, so it can be undone. Type ${e} to rewind it:`}var R=(e,n)=>e.reduce((t,o)=>t+n(o),0);function Ie(e){let n=R(e.deleted,a=>a.deleted),t=R(e.deleted,a=>a.planned),o=R(e.restored,a=>a.restored+(a.restoredWithout??0)),i=R(e.restored,a=>a.planned),s=R(e.undeleted,a=>a.undeleted+a.alreadyBack),d=R(e.undeleted,a=>a.planned);return{deleted:{planned:t,done:n,left:Math.max(0,t-n-R(e.deleted,a=>a.alreadyGone))},givenBack:{planned:i,done:o,left:Math.max(0,i-o-R(e.restored,a=>a.alreadyGone))},broughtBack:{planned:d,done:s,left:Math.max(0,d-s)}}}function en(e){let n=e.recreated??[],t=R(n,i=>i.planned),o=R(n,i=>i.created);return{planned:t,done:o,left:Math.max(0,t-o)}}function oo(e){return(e.remade??[]).reduce((n,t)=>{let o=R(e.deleted.filter(i=>i.objectApiName===t.objectApiName),i=>i.deleted);return n+Math.min(o,t.count)},0)}function tn(e,n){return e===void 0?"another user":n[e]??e}function io(e,n,t){switch(n.reason){case"automation":return e==="rewind"?"kept by your automation, which sets them again on save: rewind --ignore-field <Object.Field> stops comparing such a field":"set again on save by your automation, since the undo gave them back their values";case"changedDuringRewind":return`changed during the ${e} by ${tn(n.by,t)}: left as they made them`;case"changedSincePreview":return"changed since the preview: rewind again to take them";case"refused":return`refused: ${n.message??"the org gave no reason"}`;case"notInBin":return"no longer in the recycle bin \u2014 emptied from it, or kept there for good \u2014: Salesforce still lists them as deleted but will not bring them back; --accept-recreate makes them again with new Ids";case"goneForGood":return"deleted since and no longer in the recycle bin, and not made again (a file, whose body the checkpoint does not hold, or a record deleted while it was taken): they can't come back";case"kept":return n.message??"kept as they are";case"notBack":return"brought back without their items, gone for good"+(n.message!==void 0?` (${n.message})`:"")+": Salesforce brings a deleted duplicate record set back without its items"}}function nn(e,n){return`Stopped before it wrote anything: ${e} is as it was before this rewind. Rewind again to rewind it to '${n}'.`}function so(e,n,t,o={},i){let s=R(t.residual,c=>c.count),d=t.residual.filter(c=>c.reason==="changedDuringRewind"),a={success:`${e} is back at '${n.name}': read again, nothing differs among the objects and fields it holds.`,partial:`${e} is back at '${n.name}' but for ${u(s)} record(s) that still differ, each said with why:`,unstable:`Someone kept writing to ${e} during the rewind: ${[...new Set(d.map(c=>tn(c.by,o)))].join(", ")} changed ${u(R(d,c=>c.count))} record(s), left as they made them. Rewind again once they have stopped.`,failure:`Nothing of the rewind of ${e} to '${n.name}' went through: what still differs is said with why:`,cancelled:t.undo===void 0?nn(e,n.name):`Stopped part way: ${e} is between '${n.name}' and now. Rewind again to finish: it takes up from what still differs, and undo still returns ${e} to how it was before the rewind.`},r=t.scope;r!==void 0&&t.status==="success"&&(a.success=`${r.objects.join(", ")} of ${e} ${r.objects.length>1?"are":"is"} back at '${n.name}': read again, nothing differs among them.`);let p=Ie(t),m=R(t.undeleted,c=>c.alreadyBack),g=[a[t.status]];if(r!==void 0){let{objects:c,records:l}=r.notRewound;g.push(l>0?` not rewound: ${u(l)} record(s) of ${$(c)} still differ, left as they are \u2014 the rewind was limited to the objects named; add them with --object`:" the objects not named match the checkpoint too")}if(p.deleted.done>0){let c=R(t.wentAlong??[],l=>l.count);g.push(` deleted ${u(p.deleted.done)} record(s) added since the checkpoint \u2014 created, or brought back from the recycle bin they were in when it was taken \u2014`+(c>0?`, ${u(c)} of them with the record they hang from`:"")+" (in the recycle bin for up to 15 days)")}p.givenBack.done>0&&g.push(` gave ${u(p.givenBack.done)} record(s) back their checkpoint values`),p.broughtBack.done>0&&g.push(` brought back ${u(p.broughtBack.done-m)} record(s) deleted since the checkpoint, with their original Ids`+(m>0?`, and ${u(m)} that came back with them`:""));let v=t.status==="failure"?[]:t.carriers??[];if(v.length>0){let c=$(v.map(l=>`${l.objectApiName} ${u(l.count)}`));g.push(t.status==="cancelled"?` of them, brought back for a moment: ${c} \u2014 records the checkpoint does not hold that had taken records of it along; stopped before it was through, those it had not deleted again yet are still in the org: rewind again deletes them, with what came back with them`:` of them, brought back for a moment and deleted again: ${c} \u2014 records the checkpoint does not hold that had taken records of it along, back in the recycle bin with what came back with them`)}let w=en(t);w.done>0&&g.push(` made again ${u(w.done)} record(s) the recycle bin no longer held, with new Ids`);for(let c of t.draftsLeft??[])g.push(` left as drafts: ${c.objectApiName} ${u(c.count)} (${$(c.ids,3)}) \u2014 made again as drafts, the rewind stopped before it gave them back the status the checkpoint holds: rewind again gives it back to them, an update`);if(g.push(...sn("rewind",e,t)),g.push(...an("rewind",t,o)),t.undo){g.push(` undo it until ${E(t.undo.until)}, sooner if the recycle bin fills: ${oe("checkpoint")} undo --org ${e} --checkpoint ${n.checkpointId}`+(i!==void 0?` --store ${Be(i)}`:""));for(let{words:c,of:l}of qt(t.undo.cannot))g.push(` undo couldn't bring back: ${$(l.map(k=>`${k.objectApiName} ${u(k.count)}`))} \u2014 ${c.result}`)}for(let c of t.removedJournals??[])g.push(` removed the journal of rewind ${c.rewindId} of '${c.name}': undo reaches the last rewind of the org alone`);return g.push(rn(t)),g}function on(e){return`Stopped before it wrote anything: ${e} is as the rewind left it, and the rewind can still be undone.`}function ao(e,n,t){let o=R(t.restored,c=>c.keptChanged)+R(t.deleted,c=>c.keptChanged),i=R([...t.deleted,...t.restored,...t.undeleted],c=>c.refused),s=R(t.residual,c=>c.count)+i,d=`${e} is back as it was before its rewind to '${n.name}'`,a={success:`${d}.`,partial:o>0&&s===0?`${d}, except ${u(o)} record(s) changed since the rewind, left as they are now.`:`${d}, except ${u(s+o)} record(s), each said with why:`,unstable:`Someone changed records of ${e} during the undo: left as they made them, each said below.`,failure:`Nothing of the undo of ${e}'s rewind went through: its reasons are said below.`,cancelled:Ue(t)?on(e):`Stopped part way: ${e} is between the rewind and how it was before it. Undo again to finish: it takes up what this one left.`},r=Ie(t),p=[a[t.status]],m=oo(t),g=R(t.wentAlong??[],c=>c.count),v=r.deleted.done-m-g;v>0&&p.push(` sent back to the recycle bin ${u(v)} record(s) the rewind brought back`+(g>0?", with what came back with them":"")),m>0&&p.push(` deleted again ${u(m)} record(s) the rewind made again, with what went with them`);let w=t.carriedAlone??[];if(w.length>0&&p.push(` of them, back in the recycle bin on their own: ${$(w.map(c=>`${c.objectApiName} ${u(c.count)}`))} \u2014 they had gone there with a record the rewind brought back for a moment, which stays there; they come back alone, under the parent the checkpoint gave them`),r.broughtBack.done>0){let c=R(t.cameBackAlong??[],l=>l.count);p.push(` brought back ${u(r.broughtBack.done)} record(s) the rewind deleted`+(c>0?`, ${u(c)} of them with the record they hang from`:""))}return r.givenBack.done>0&&p.push(` gave ${u(r.givenBack.done)} record(s) back the values they had before the rewind`),o>0&&p.push(` kept ${u(o)} record(s) changed since the rewind: undo leaves them as they are now`),p.push(...sn("undo",e,t)),p.push(...an("undo",t,{})),p.push(rn(t)),p}function sn(e,n,t){let o=t.files;if(o===void 0)return[];let i=e==="rewind"?{unlinked:"removed {n} link(s) added since between files and records: the files stay",relinked:"put back {n} link(s) removed since between files and records, under new Ids",linksUpdated:"gave {n} link(s) between files and records their sharing back"}:{unlinked:"removed again {n} link(s) between files and records the rewind put back",relinked:"put back {n} link(s) between files and records the rewind removed, under new Ids",linksUpdated:"gave {n} link(s) between files and records back the sharing they had before the rewind"},s=["unlinked","relinked","linksUpdated"].filter(d=>o[d]>0).map(d=>` ${i[d].replace("{n}",u(o[d]))}`);return o.linksRefused>0&&s.push(` ${n} refused to write ${u(o.linksRefused)} link(s) between files and records`),s}function an(e,n,t){let o=n.residual.map(i=>` ${i.objectApiName} ${u(i.count)} \u2014 ${io(e,i,t)}`);if(e==="rewind")for(let i of n.deleted){if(i.objectApiName!==K)continue;let s=i.refused+i.keptChanged+i.keptDependents;s!==0&&o.push(` left: ${u(s)} ${K} its preview named among what goes along`+(i.reasons.length>0?` \u2014 ${i.reasons.join("; ")}`:""))}if(e==="undo")for(let i of[...n.deleted,...n.restored,...n.undeleted])i.refused!==0&&o.push(` ${i.objectApiName} ${u(i.refused)} \u2014 refused: ${i.reasons[0]??"the org gave no reason"}`);for(let i of n.unread??[])o.push(` could not be read again: ${i.objectApiName} \u2014 ${i.reason} (never taken for unchanged)`);return o}function rn(e){return` sent ${u(e.apiRequests.used)} API requests to the org; ${u(e.apiRequests.leftToday)} left today`}function dn(e,n,t,o,i){let s=new Map,d=r=>{let p=s.get(r);return p||(p={object:r,deleted:0,givenBack:0,broughtBack:0,refused:0},s.set(r,p)),p};for(let r of o.deleted)d(r.objectApiName).deleted+=r.deleted,d(r.objectApiName).refused+=r.refused;for(let r of o.restored)d(r.objectApiName).givenBack+=r.restored+(r.restoredWithout??0),d(r.objectApiName).refused+=r.refused;for(let r of o.undeleted)d(r.objectApiName).broughtBack+=r.undeleted+r.alreadyBack,d(r.objectApiName).refused+=r.refused;for(let r of o.recreated??[])d(r.objectApiName).refused+=r.refused;let a=(o.unread??[]).map(r=>({object:r.objectApiName,reason:r.reason}));return{checkpoint:{id:t.checkpointId,name:t.name,takenAt:t.takenAt,org:n},rewindId:o.rewindId,status:o.status,...o.scope?{limitedTo:[...o.scope.objects],notRewound:{...o.scope.notRewound}}:{},...Ie(o),...e==="rewind"?{recreated:en(o),cannotUndo:(i?.objects??[]).flatMap(r=>r.cannotUndo.filter(p=>p.count>0).map(p=>({object:r.objectApiName,reason:p.reason,count:p.count})))}:{},...e==="rewind"&&(o.carriers??[]).length>0?{carriers:(o.carriers??[]).map(r=>({object:r.objectApiName,count:r.count}))}:{},...e==="rewind"&&(o.draftsLeft??[]).length>0?{draftsLeft:(o.draftsLeft??[]).map(r=>({object:r.objectApiName,count:r.count,ids:[...r.ids]}))}:{},...e==="undo"&&(o.carriedAlone??[]).length>0?{carriedAlone:(o.carriedAlone??[]).map(r=>({object:r.objectApiName,count:r.count}))}:{},...o.files?{files:{...o.files}}:{},...o.undo?{undo:{until:o.undo.until,cannot:o.undo.cannot.map(r=>({object:r.objectApiName,count:r.count,...r.reason!==void 0?{reason:r.reason}:{}}))}}:{},verify:{differences:R(o.residual,r=>r.count)+a.length,stable:o.status!=="unstable",passes:o.passes,notCompared:[...t.ignoredFields]},residual:o.residual.map(r=>({object:r.objectApiName,reason:r.reason,...r.by!==void 0?{by:r.by}:{},count:r.count,...r.message!==void 0?{message:r.message}:{}})),unread:a,objects:[...s.values()],apiRequests:o.apiRequests,result:o}}function cn(e,n){switch(e){case"success":return 0;case"partial":return 3;case"unstable":return 4;case"failure":return 1;case"cancelled":return n!==void 0?ie(n):1}}var ro=10*6e4,co=720*6e4,hn=60*6e4,ce=5*6e4,Ot=200,b=class extends Error{constructor(t,o=1,i=[]){super(t.message);this.refusal=t;this.code=o;this.also=i;this.name="Stop"}refusal;code;also};function ho(e){let n=[e.refusal,...e.also];return{refusal:e.refusal,...e.also.length>0?{wouldBeRefused:n.map(t=>V(t)),wouldBeRefusedCodes:n.map(t=>t.code)}:{}}}function D(e){return e.message?.payload??{}}function P(e,n){let t=D(e);if(e.outcome==="unanswered")return{code:"UNANSWERED",message:`${n}: no answer came in time.`};let o=typeof t.message=="string"?t.message:JSON.stringify(t),i=typeof t.code=="string"?t.code:e.outcome.toUpperCase(),{holdingLimit:s}=t;return{code:i,message:o,...typeof s=="number"?{holdingLimit:s}:{}}}function lo(e){let n=D(e).alsoRefused;return e.outcome!=="failed"||!Array.isArray(n)?[]:n.flatMap(t=>{let{code:o,message:i}=t??{};return typeof o=="string"&&typeof i=="string"?[{code:o,message:i}]:[]})}async function uo(e=process.argv,n={}){let t=Sn(e),o=c=>{process[t.json?"stderr":"stdout"].write(`${c}
467
+ `)},i=c=>{t.json&&process.stdout.write(`${JSON.stringify(c,null,2)}
468
+ `)},s=tt({root:t.storeRoot,...n.locksDir!==void 0?{locksDir:n.locksDir}:{}});if("refusal"in s){let c=`The checkpoints cannot be kept in ${s.refusal.path}: `+et(s.refusal,t.storeRoot,"--store <folder>");process.stderr.write(`${c}
469
+ `),i({refusal:{code:"STORE_REFUSED",message:c}}),B(1);return}let d=s.store,a=wn(Et(bn(),"sandforge-checkpoint-")),r=new gt,p=!1,m,g=()=>Promise.resolve(),v,w;try{let c=(n.createHost??wt)({storeDir:a,log:h=>{p&&h.startsWith("[INFO] ")?o(h.slice(7)):h.startsWith("[WARN] ")&&o(`warning: ${h.slice(7)}`)},compose:h=>{h.handlers.setCheckpointStore(d),h.handlers.rewindCheckpointsFromPreviewsAnswered(),h.handlers.setInfraServices({backgroundRegistry:r}),g=()=>h.handlers.sweepCheckpoints(),v=h.handlers,w=h},onPost:h=>{if(h.type!=="operation:progress")return;let f=h.payload?.currentStep;typeof f!="string"||f===m||(m=f,o(` ${f}`))}});p=!0;try{await g()}finally{p=!1}let l=async()=>{let h=await c.request({type:"checkpoint:list",timeoutMs:ce});if(h.outcome!=="answered")throw new b(P(h,"The list of checkpoints"));return D(h).checkpoints??[]},k=async h=>{try{return await c.connect(h)}catch(f){throw new b({code:"NOT_CONNECTED",message:f instanceof He?f.message:`${h} could not be reached: ${f instanceof Error?f.message:String(f)}`})}},y=async h=>{if(w===void 0)throw new Error("The host composed no handlers.");return nt(await We(h.id,w.orgRegistry,w.orgManager)).userId()};switch(t.command){case"list":{let h=await l(),f=t.org!==void 0?_(h,t.org):h,j=t.org!==void 0?{org:t.org,kept:h.length}:void 0;for(let C of En(f,d.root,j))o(C);i(f.map(Nn));return}case"take":await go(t,c,await k(t.org),d,r,o,i);return;case"preview":{let h=await l(),f=te(G(h,_(h,t.org),t.checkpoint,t.org)),j=Ce(f);if(j)throw new b(j);let C=f.checkpoint,O=t.objects.length>0?Zt(C,t.objects):void 0,W=await k(t.org);De(W,f,C,t.org,"preview");let q=await c.request({type:"checkpoint:preview",payload:{checkpointId:f.checkpointId,...O?{objects:O}:{},acceptOutside:!1},timeoutMs:hn});if(q.outcome!=="answered")throw new b(P(q,"The preview"));let N=D(q),L=O?await Ne(c,N.diff,O,!1):void 0,I=O?void 0:await Xt(c,C,N.diff,!1),ne=L??I,A=ne?{...N,diff:ne.diff}:N,Le=Qt(N.refusal,await we({orgName:t.org,preview:A,bounds:{refuseWhenActive:!1},accepted:to,writers:()=>Promise.resolve([]),words:ee,user:W.username})),[Te]=Le;for(let T of Ht(t.org,C,A,W.username))o(T);for(let T of L?Vt(L.plan):[])o(T);for(let T of I?Yt(I.plan):[])o(T);for(let T of Le.slice(N.refusal?1:0))o(` a rewind now would be refused (${T.code}): ${T.message}`);i(zt(t.org,C,{...N,...Te?{refusal:Te}:{}},L,I)),B(Zn(L?.diff??N.diff,t.failOnChange));return}case"rewind":case"undo":{let h={host:c,registry:r,store:d,listAll:l,connect:k,userIdOf:y,say:o,answerJson:i};t.command==="rewind"?await bo(t,h):await vo(t,h);return}case"delete":await ko(t,c,l,o,i);return;case"export":await po(t,{transfers:xt(v),listAll:l,say:o,answerJson:i});return;case"import":await mo(t,{transfers:xt(v),connect:k,say:o,answerJson:i});return;case"replay":await $t(t.replay,{storeRoot:t.storeRoot,storeNamed:t.storeNamed===!0,store:d,...n.locksDir!==void 0?{locksDir:n.locksDir}:{},listAll:l,checkpointsOf:_,resolve:G,say:o,json:t.json});return;case"replays":await At(t.target,{storeRoot:t.storeRoot,storeNamed:t.storeNamed===!0,say:o,answerJson:i});return}}catch(c){let l=c instanceof b?c:c instanceof ge?new b(c.refusal,c.code):new b({code:"FAILED",message:c instanceof Error?c.message:String(c)});process.stderr.write(`${c instanceof ge?V(c.refusal):l.message}
470
470
  `);for(let k of l.also)process.stderr.write(`${V(k)}
471
- `);l.code!==2&&i(ro(l)),B(l.code)}finally{r.dispose(),wn(a,{recursive:!0,force:!0})}}function St(e){if(e===void 0)throw new Error("The host composed no handlers.");return e}function lo(){try{let e=JSON.parse(mn(Ot(__dirname,"..","package.json"),"utf8"));return typeof e.version=="string"?e.version:"0.0.0"}catch{return"0.0.0"}}function cn(e){let n=process.env[e];if(n===void 0||n.trim()==="")throw new b({code:"NO_KEY",message:`${e} is not set: it holds no key. Nothing was run.`},2);let t=se(n);if(t===void 0)throw new b({code:"NO_KEY",message:`${e} holds no key SandForge reads: 52 letters and digits, in groups of four as an export shows one. Nothing was run.`},2);return t}function hn(e,n){return{id:e.checkpointId,name:e.name,takenAt:e.takenAt,org:n}}async function uo(e,n){let{say:t,answerJson:o}=n,i=e.keyEnv!==void 0?cn(e.keyEnv):void 0,s=await n.listAll(),d=ee(G(s,_(s,e.org),e.checkpoint,e.org)),a=await n.transfers.exportCheckpoint({checkpointId:d.checkpointId,out:e.out,...i!==void 0?{key:i}:{},sandforgeVersion:lo()});if(!a.exported)throw new b(a.refusal);let{checkpoint:r,header:p}=a;t(`exported '${r.name}' (${r.checkpointId}) of ${e.org}, taken ${E(r.takenAt)}: ${f(p.records)} record(s) of ${f(p.objects)} object(s), ${U(a.bytes)}, to ${e.out}`),t(` sha256 ${a.sha256}`),a.key!==void 0&&process.stderr.write(` key, shown this once and kept nowhere: ${a.key}
472
- `),t(` Anyone who has this file and its key can read the ${f(p.records)} records it holds of ${e.org}, personal data among them. Send the key another way than the file, and only to people who already see all data in ${e.org}.`),t(" The file does not expire: delete it once it has served."),o({checkpoint:hn(r,e.org),file:e.out,bytes:a.bytes,sha256:a.sha256,records:p.records,objects:p.objects,keyShown:a.key!==void 0})}async function fo(e,n){let{say:t,answerJson:o}=n,i=e.keyEnv!==void 0?cn(e.keyEnv):void 0,s=await n.connect(e.org),d=await n.transfers.readCheckpointImport({orgId:s.id,file:e.file});if(d.header!==void 0){let{header:m}=d;t(`the file holds checkpoint ${m.checkpointId}, taken ${E(m.takenAt)}: ${f(m.records)} record(s) of ${f(m.objects)} object(s), ${U(m.bytes)}, exported by SandForge ${m.sandforgeVersion}`)}if(!d.allowed)throw new b(d.refusal.code==="OTHER_ORG"?{...d.refusal,message:`${d.refusal.message} Its replay into ${e.org}: ${kt(e.file,e.org)} --dry-run`}:d.refusal);let a=i??await po(),r=await n.transfers.importCheckpoint({orgId:s.id,file:e.file,key:a,keepDays:e.keepDays});if(!r.imported)throw new b(r.refusal);let{checkpoint:p}=r;t(r.outcome==="imported"?`imported '${p.name}' (${p.checkpointId}) of ${e.org}: ${f(Z(p))} record(s) of ${f(p.objects.length)} object(s), ${Se(p.expiresAt)}`:`'${p.name}' (${p.checkpointId}) is kept on this machine already, the same: left as it is`);for(let m of r.warnings)t(` ${m}`);o({outcome:r.outcome,checkpoint:hn(p,e.org),records:Z(p),objects:p.objects.length,expiresAt:p.expiresAt,warnings:r.warnings})}async function po(){let e=await it("Key of the file (not shown as you type it):","give --key-env VAR, the name of an environment variable that holds the key");if(e===void 0||e.trim()==="")throw new b({code:"DECLINED",message:"No key was typed. Nothing was imported."});let n=se(e);if(n===void 0)throw new b({code:"IMPORT_KEY",message:"That is not a key SandForge draws: 52 letters and digits, in groups of four as the export showed it. Nothing was imported."});return n}function ee(e){if("entry"in e)return e.entry;throw"ambiguous"in e?new b({code:"AMBIGUOUS",message:e.ambiguous},2):new b({code:"NOT_FOUND",message:e.none})}async function mo(e,n,t,o,i,s,d){let{take:a}=e;if(e.estimate){let l={orgId:t.id,mode:a.mode,...a.objects?{objects:a.objects}:{},...a.excluded?{excluded:a.excluded}:{},...a.customSettings?{customSettings:a.customSettings}:{},...a.maxTotal!==void 0?{maxTotal:a.maxTotal}:{}},k=await n.request({type:"checkpoint:scope",payload:l,timeoutMs:so});if(k.outcome!=="answered")throw new b(P(k,"The estimate"));let y=D(k),c={mode:y.mode,objects:y.objects,leftOut:y.leftOut,estimate:y.estimate,...y.refusal?{refusal:ve(y.refusal)}:{},...y.files?{files:y.files}:{},...y.customSettings?{customSettings:y.customSettings}:{}};for(let u of In(e.org,c))s(u);d(En(c)),B(c.refusal?1:0);return}s(`taking a checkpoint of ${e.org}: it reads every record of its objects (Ctrl-C stops it, and nothing of it is kept)`);let{answer:r,stoppedBy:p}=await De(i,"the take stops after the read under way, and keeps nothing",()=>n.request({type:"checkpoint:take",payload:{orgId:t.id,...a},timeoutMs:ao}));if(r.outcome!=="answered"){let l=ve(P(r,"The take"));throw p!==void 0&&l.code==="CANCELLED"?new b(l,oe(p)):new b(l)}let m=D(r),g=m.checkpoint,$=m.requests,w=m.estimate,h=o.folderOf(g.org.organizationId,g.checkpointId).dir;for(let l of Pn(g,h,a.objects??[]))s(l);$&&s(Bn($,w)),d({checkpoint:g,...$?{requests:$}:{},...w?{estimate:w}:{}})}async function wo(e,n,t,o,i){let s=await t(),d=_(s,e.org),a=e.checkpoint===void 0?d:[ee(G(s,d,e.checkpoint,e.org))];if(a.length===0)throw new b({code:"NOT_FOUND",message:`No checkpoint of ${e.org} is kept in the folder read. ${ae(e.org)} Nothing was deleted.`});let r=l=>l.checkpoint?`'${l.checkpoint.name}' (${l.checkpointId})`:l.checkpointId;if(!e.yes){let l=a.filter(u=>u.undo!==void 0),k=a.length===1?`Delete ${r(a[0])}${a[0].checkpoint?`, taken ${E(a[0].checkpoint.takenAt)},`:""} from this machine? ${e.org} can no longer be rewound to it`:`Delete the ${a.length} checkpoints of ${e.org} from this machine (${v(a.map(r),4)})? ${e.org} can no longer be rewound to them`,y=(await ke(a,{storeRoot:e.storeRoot,storeNamed:e.storeNamed===!0})).entries,c=`${k}${l.length>0?", and its last rewind can no longer be undone":""}. The org is not touched`+(y.length>0?`, nor the ${y.length===1?"org it was":"orgs they were"} replayed into (${v(y.map(u=>u.target.name??u.target.organizationId),4)}), each replay still taken back with --remove`:"")+".";if(!await ot(c))throw new b({code:"DECLINED",message:"Nothing was deleted."})}let p=a.map(l=>l.checkpointId);for(let l=0;l<p.length;l+=Ct){let k=await n.request({type:"checkpoint:delete",payload:{checkpointIds:p.slice(l,l+Ct)},timeoutMs:de});if(k.outcome!=="answered"){let y=P(k,"The delete");if(l===0)throw new b(y);o(`refused: ${y.message}`);break}}let m=new Set((await t()).map(l=>l.checkpointId)),g=a.filter(l=>!m.has(l.checkpointId)),$=a.filter(l=>m.has(l.checkpointId));for(let l of g)o(`deleted ${r(l)}`);for(let l of $)o(`kept ${r(l)}: a take, a rewind or an undo of its org is running; delete it once it has ended`);let w=await ke(g,{storeRoot:e.storeRoot,storeNamed:e.storeNamed===!0});for(let l of w.lines)o(l);let h=e.storeNamed?e.storeRoot:void 0;i({deleted:g.map(l=>l.checkpointId),kept:$.map(l=>l.checkpointId),...w.entries.length>0?{replaysInPlace:w.entries.map(l=>yt(l,h))}:{}}),$.length>0&&B(g.length>0?3:1)}function Ne(e,n,t,o,i){if(xt(e.orgId,n.organizationId))return;let s=_([n],o).length>0,d=i==="preview"?"preview it":i==="rewind"?"rewind to it":"undo it";throw new b({code:"OTHER_ORG",message:s?`${o} answers as another org than the one '${t.name}' was taken of: a sandbox refreshed since is another org, and this checkpoint no longer rewinds it. ${ce.replace(/\.$/,"")}: ${ge(n.checkpointId,o)} --dry-run. No record was read.`:`'${t.name}' is a checkpoint of ${z(t)}, not of ${o}: ${d} with --org ${z(t)}. No record was read.`})}async function De(e,n,t){let o,i=e.onEvent((d,a,r)=>{o!==void 0&&a==="started"&&r.module==="checkpoint"&&e.abort(d)}),s=qe(d=>{o=d,process.stderr.write(`
471
+ `);l.code!==2&&i(ho(l)),B(l.code)}finally{r.dispose(),kn(a,{recursive:!0,force:!0})}}function xt(e){if(e===void 0)throw new Error("The host composed no handlers.");return e}function fo(){try{let e=JSON.parse(gn(Et(__dirname,"..","package.json"),"utf8"));return typeof e.version=="string"?e.version:"0.0.0"}catch{return"0.0.0"}}function ln(e){let n=process.env[e];if(n===void 0||n.trim()==="")throw new b({code:"NO_KEY",message:`${e} is not set: it holds no key. Nothing was run.`},2);let t=ae(n);if(t===void 0)throw new b({code:"NO_KEY",message:`${e} holds no key SandForge reads: 52 letters and digits, in groups of four as an export shows one. Nothing was run.`},2);return t}function un(e,n){return{id:e.checkpointId,name:e.name,takenAt:e.takenAt,org:n}}async function po(e,n){let{say:t,answerJson:o}=n,i=e.keyEnv!==void 0?ln(e.keyEnv):void 0,s=await n.listAll(),d=te(G(s,_(s,e.org),e.checkpoint,e.org)),a=await n.transfers.exportCheckpoint({checkpointId:d.checkpointId,out:e.out,...i!==void 0?{key:i}:{},sandforgeVersion:fo()});if(!a.exported)throw new b(a.refusal);let{checkpoint:r,header:p}=a;t(`exported '${r.name}' (${r.checkpointId}) of ${e.org}, taken ${E(r.takenAt)}: ${u(p.records)} record(s) of ${u(p.objects)} object(s), ${U(a.bytes)}, to ${e.out}`),t(` sha256 ${a.sha256}`),a.key!==void 0&&process.stderr.write(` key, shown this once and kept nowhere: ${a.key}
472
+ `),t(` Anyone who has this file and its key can read the ${u(p.records)} records it holds of ${e.org}, personal data among them. Send the key another way than the file, and only to people who already see all data in ${e.org}.`),t(" The file does not expire: delete it once it has served."),o({checkpoint:un(r,e.org),file:e.out,bytes:a.bytes,sha256:a.sha256,records:p.records,objects:p.objects,keyShown:a.key!==void 0})}async function mo(e,n){let{say:t,answerJson:o}=n,i=e.keyEnv!==void 0?ln(e.keyEnv):void 0,s=await n.connect(e.org),d=await n.transfers.readCheckpointImport({orgId:s.id,file:e.file});if(d.header!==void 0){let{header:m}=d;t(`the file holds checkpoint ${m.checkpointId}, taken ${E(m.takenAt)}: ${u(m.records)} record(s) of ${u(m.objects)} object(s), ${U(m.bytes)}, exported by SandForge ${m.sandforgeVersion}`)}if(!d.allowed)throw new b(d.refusal.code==="OTHER_ORG"?{...d.refusal,message:`${d.refusal.message} Its replay into ${e.org}: ${yt(e.file,e.org)} --dry-run`}:d.refusal);let a=i??await wo(),r=await n.transfers.importCheckpoint({orgId:s.id,file:e.file,key:a,keepDays:e.keepDays});if(!r.imported)throw new b(r.refusal);let{checkpoint:p}=r;t(r.outcome==="imported"?`imported '${p.name}' (${p.checkpointId}) of ${e.org}: ${u(Q(p))} record(s) of ${u(p.objects.length)} object(s), ${Oe(p.expiresAt)}`:`'${p.name}' (${p.checkpointId}) is kept on this machine already, the same: left as it is`);for(let m of r.warnings)t(` ${m}`);o({outcome:r.outcome,checkpoint:un(p,e.org),records:Q(p),objects:p.objects.length,expiresAt:p.expiresAt,warnings:r.warnings})}async function wo(){let e=await at("Key of the file (not shown as you type it):","give --key-env VAR, the name of an environment variable that holds the key");if(e===void 0||e.trim()==="")throw new b({code:"DECLINED",message:"No key was typed. Nothing was imported."});let n=ae(e);if(n===void 0)throw new b({code:"IMPORT_KEY",message:"That is not a key SandForge draws: 52 letters and digits, in groups of four as the export showed it. Nothing was imported."});return n}function te(e){if("entry"in e)return e.entry;throw"ambiguous"in e?new b({code:"AMBIGUOUS",message:e.ambiguous},2):new b({code:"NOT_FOUND",message:e.none})}async function go(e,n,t,o,i,s,d){let{take:a}=e;if(e.estimate){let l={orgId:t.id,mode:a.mode,...a.objects?{objects:a.objects}:{},...a.excluded?{excluded:a.excluded}:{},...a.customSettings?{customSettings:a.customSettings}:{},...a.maxTotal!==void 0?{maxTotal:a.maxTotal}:{}},k=await n.request({type:"checkpoint:scope",payload:l,timeoutMs:ro});if(k.outcome!=="answered")throw new b(P(k,"The estimate"));let y=D(k),h={mode:y.mode,objects:y.objects,leftOut:y.leftOut,estimate:y.estimate,...y.refusal?{refusal:ve(y.refusal)}:{},...y.files?{files:y.files}:{},...y.customSettings?{customSettings:y.customSettings}:{}};for(let f of Dn(e.org,h))s(f);d(In(h)),B(h.refusal?1:0);return}s(`taking a checkpoint of ${e.org}: it reads every record of its objects (Ctrl-C stops it, and nothing of it is kept)`);let{answer:r,stoppedBy:p}=await Pe(i,"the take stops after the read under way, and keeps nothing",()=>n.request({type:"checkpoint:take",payload:{orgId:t.id,...a},timeoutMs:co}));if(r.outcome!=="answered"){let l=ve(P(r,"The take"));throw p!==void 0&&l.code==="CANCELLED"?new b(l,ie(p)):new b(l)}let m=D(r),g=m.checkpoint,v=m.requests,w=m.estimate,c=o.folderOf(g.org.organizationId,g.checkpointId).dir;for(let l of Tn(g,c,a.objects??[]))s(l);v&&s(_n(v,w)),d({checkpoint:g,...v?{requests:v}:{},...w?{estimate:w}:{}})}async function ko(e,n,t,o,i){let s=await t(),d=_(s,e.org),a=e.checkpoint===void 0?d:[te(G(s,d,e.checkpoint,e.org))];if(a.length===0)throw new b({code:"NOT_FOUND",message:`No checkpoint of ${e.org} is kept in the folder read. ${re(e.org)} Nothing was deleted.`});let r=l=>l.checkpoint?`'${l.checkpoint.name}' (${l.checkpointId})`:l.checkpointId;if(!e.yes){let l=a.filter(f=>f.undo!==void 0),k=a.length===1?`Delete ${r(a[0])}${a[0].checkpoint?`, taken ${E(a[0].checkpoint.takenAt)},`:""} from this machine? ${e.org} can no longer be rewound to it`:`Delete the ${a.length} checkpoints of ${e.org} from this machine (${$(a.map(r),4)})? ${e.org} can no longer be rewound to them`,y=(await be(a,{storeRoot:e.storeRoot,storeNamed:e.storeNamed===!0})).entries,h=`${k}${l.length>0?", and its last rewind can no longer be undone":""}. The org is not touched`+(y.length>0?`, nor the ${y.length===1?"org it was":"orgs they were"} replayed into (${$(y.map(f=>f.target.name??f.target.organizationId),4)}), each replay still taken back with --remove`:"")+".";if(!await st(h))throw new b({code:"DECLINED",message:"Nothing was deleted."})}let p=a.map(l=>l.checkpointId);for(let l=0;l<p.length;l+=Ot){let k=await n.request({type:"checkpoint:delete",payload:{checkpointIds:p.slice(l,l+Ot)},timeoutMs:ce});if(k.outcome!=="answered"){let y=P(k,"The delete");if(l===0)throw new b(y);o(`refused: ${y.message}`);break}}let m=new Set((await t()).map(l=>l.checkpointId)),g=a.filter(l=>!m.has(l.checkpointId)),v=a.filter(l=>m.has(l.checkpointId));for(let l of g)o(`deleted ${r(l)}`);for(let l of v)o(`kept ${r(l)}: a take, a rewind or an undo of its org is running; delete it once it has ended`);let w=await be(g,{storeRoot:e.storeRoot,storeNamed:e.storeNamed===!0});for(let l of w.lines)o(l);let c=e.storeNamed?e.storeRoot:void 0;i({deleted:g.map(l=>l.checkpointId),kept:v.map(l=>l.checkpointId),...w.entries.length>0?{replaysInPlace:w.entries.map(l=>vt(l,c))}:{}}),v.length>0&&B(g.length>0?3:1)}function De(e,n,t,o,i){if(Nt(e.orgId,n.organizationId))return;let s=_([n],o).length>0,d=i==="preview"?"preview it":i==="rewind"?"rewind to it":"undo it";throw new b({code:"OTHER_ORG",message:s?`${o} answers as another org than the one '${t.name}' was taken of: a sandbox refreshed since is another org, and this checkpoint no longer rewinds it. ${he.replace(/\.$/,"")}: ${ke(n.checkpointId,o)} --dry-run. No record was read.`:`'${t.name}' is a checkpoint of ${z(t)}, not of ${o}: ${d} with --org ${z(t)}. No record was read.`})}async function Pe(e,n,t){let o,i=e.onEvent((d,a,r)=>{o!==void 0&&a==="started"&&r.module==="checkpoint"&&e.abort(d)}),s=Ge(d=>{o=d,process.stderr.write(`
473
473
  interrupted: ${n} (Ctrl-C again ends it at once)
474
- `);for(let a of e.getRunning())a.module==="checkpoint"&&e.abort(a.operationId)});try{let d=await t();return o!==void 0?{answer:d,stoppedBy:o}:{answer:d}}finally{s(),i()}}var ln=720*6e4;function un(e,n,t=o=>o){let{answer:o,stoppedBy:i}=e;if(o.outcome!=="answered"){let s=t(P(o,n));throw i!==void 0&&s.code==="CANCELLED"?new b(s,oe(i)):new b(s,1,co(o).map(t))}return D(o).result}async function go(e,n){let{host:t,say:o,answerJson:i}=n,s=await n.listAll(),d=ee(G(s,_(s,e.org),e.checkpoint,e.org)),a=Re(d);if(a)throw new b(a);let r=d.checkpoint,p=e.ignoreFields.filter(A=>!r.ignoredFields.includes(A));if(p.length>0){let A=await t.request({type:"checkpoint:ignore-fields",payload:{checkpointId:d.checkpointId,fields:[...r.ignoredFields,...p]},timeoutMs:de});if(A.outcome!=="answered")throw new b(P(A,"The fields not to compare"));r=D(A).checkpoint,o(`not compared from now on, nor written back: ${p.join(", ")} (kept in '${r.name}')`)}let m=e.objects.length>0?Yt(r,e.objects):void 0,g=await n.connect(e.org);Ne(g,d,r,e.org,"rewind");let $=await t.request({type:"checkpoint:preview",payload:{checkpointId:d.checkpointId,...m?{objects:m}:{},...e.muteAutomation?{muteAutomation:!0}:{},acceptOutside:e.acceptOutside},timeoutMs:dn});if($.outcome!=="answered")throw new b(P($,"The preview"));let w=D($),h=m?await Ee(t,w.diff,m,e.acceptOutside):void 0,l=m?void 0:await Kt(t,r,w.diff,e.acceptOutside),k=h??l,y=k?{...w,diff:k.diff}:w,c=e.muteAutomation&&y.automation?Ve(y.automation,_e(Y(y.diff))):void 0,u=c?{...y,automation:c.automation}:y;for(let A of Wt(e.org,r,u,g.username,e.acceptAutomation))o(A);for(let A of h?zt(h.plan):[])o(A);for(let A of l?Vt(l.plan):[])o(A);for(let A of c?ie(c.planned,e.org):[])o(` ${A}`);let j=rt(u.diff).length>0,C=await me({orgName:e.org,preview:u,bounds:{...e.maxRecords!==void 0?{maxRecords:e.maxRecords}:{},refuseWhenActive:e.refuseWhenActive},accepted:e,writers:async()=>at(r.takenBy,await n.userIdOf(g)),words:Q,user:g.username}),O=Xt(u.refusal,C);if(Jt(r,u.diff,e.acceptOutside)&&o(" without --accept-outside, the records they hang from stay, and so do they: each is said once the rewind is through"),e.dryRun){for(let A of O.slice(u.refusal?1:0))o(` a rewind now would be refused (${A.code}): ${A.message}`);i({...Ht(e.org,r,w,h,l),...c?{mutedAutomation:c.planned,mutePlan:c.plan}:{},...O.length>0?{wouldBeRefused:O.map(A=>V(A)),wouldBeRefusedCodes:O.map(A=>A.code)}:{}});return}let[q,...I]=O;if(q)throw new b(q,1,I);if(j&&!e.yes&&await fe(eo(e.org,r,u.diff,m))!==e.org)throw new b({code:"DECLINED",message:"Nothing was written."});let L=await De(n.registry,"the rewind stops before its next call to the org, and leaves its journal: rewind again takes up from what still differs",()=>t.request({type:"checkpoint:rewind",payload:{checkpointId:d.checkpointId,previewId:u.diff.previewId,...m?{objects:m}:{},acceptAutomation:e.acceptAutomation,...e.acceptEmails?{acceptEmails:!0}:{},...e.muteAutomation?{muteAutomation:!0}:{},acceptNoUndo:e.acceptNoUndo,acceptRecreate:e.acceptRecreate,acceptOutside:e.acceptOutside,acceptUnseen:e.acceptUnseen},timeoutMs:ln})),N=un(L,"The rewind",A=>A.code==="CANCELLED"?{...A,message:en(e.org,r.name)}:Xn(A)),te=e.storeRoot!==le()?e.storeRoot:void 0;for(let A of oo(e.org,r,N,u.diff.userNames,te))o(A);for(let A of N.mutedAutomation?ie(N.mutedAutomation,e.org):[])o(A);i(an("rewind",e.org,r,N,u.diff)),B(rn(N.status,L.stoppedBy))}function ko(e,n,t,o,i){return`undo the rewind ${t} of ${e} to '${n.name}' (open until ${E(o)}, sooner if the recycle bin fills)`+(i?`: it brings back ${f(i.bringBack)} record(s) the rewind deleted, gives ${f(i.giveBack)} record(s) back the values they had before it, and sends ${f(i.remove-i.remade)} record(s) it brought back to the recycle bin`+(i.along>0?", with what came back with them":"")+(i.remade>0?`, deleting again the ${f(i.remade)} record(s) it made again`:"")+(i.drafted>0?` \u2014 of them, ${f(i.drafted)} order(s) set back to Draft first if past it, the one way Salesforce deletes one: an update, which what runs on an order's update fires on`:"")+"; what anyone changed since the rewind stays":"")}async function bo(e,n,t,o){try{let i=e.folderOf(n.organizationId,n.checkpointId),s=await lt(i,o,t.objects);try{return{bringBack:s.bringBack.count,giveBack:s.giveBack.count,remove:s.remove.spool.count,along:s.goesWithParent.count,remade:s.remade.keys.size,drafted:s.remade.objects.filter(({objectApiName:d})=>Je([d]).length>0).reduce((d,{count:a})=>d+a,0)}}finally{await s.dispose()}}catch{return}}async function yo(e,n){let{host:t,say:o,answerJson:i}=n,s=await n.listAll(),d=_(s,e.org),a=e.checkpoint===void 0?d.find(k=>k.undo!==void 0):ee(G(s,d,e.checkpoint,e.org));if(!a)throw new b({code:"NOT_FOUND",message:`No rewind of ${e.org} can be undone from this machine: Undo is offered for the last rewind of an org, for 15 days after it, until it is undone. Nothing was written.`});let r=Re(a);if(r)throw new b(r);let p=a.checkpoint;if(!a.undo)throw new b({code:"UNDO_CLOSED",message:`'${p.name}' has no rewind that can be undone: Undo is offered for the last rewind of an org only, for 15 days after it, until it is undone. Nothing was written.`});let{rewindId:m,until:g}=a.undo,$=await bo(n.store,a,p,m);o(ko(e.org,p,m,g,$));let w=await n.connect(e.org);if(Ne(w,a,p,e.org,"undo"),!e.yes&&await fe(`Type ${e.org} to undo its rewind:`)!==e.org)throw new b({code:"DECLINED",message:"Nothing was written."});let h=await De(n.registry,"the undo stops before its next call to the org: undo again takes up what it left",()=>t.request({type:"checkpoint:undo",payload:{checkpointId:a.checkpointId,rewindId:m,acceptAutomation:e.acceptAutomation,...e.acceptEmails?{acceptEmails:!0}:{},...e.muteAutomation?{muteAutomation:!0}:{}},timeoutMs:ln})),l=un(h,"The undo",k=>k.code==="CANCELLED"?{...k,message:tn(e.org)}:Zn(k));for(let k of io(e.org,p,l))o(k);for(let k of l.mutedAutomation?ie(l.mutedAutomation,e.org):[])o(k);i(an("undo",e.org,p,l)),B(rn(l.status,h.stoppedBy))}process.argv[1]?.includes("sandforge-checkpoint")&&(st(),ho().then(()=>process.exit(process.exitCode??0)).catch(e=>{process.stderr.write(`${e instanceof Error?e.message:String(e)}
475
- `),process.exit(1)}));export{jn as a,Rn as b,_ as c,G as d,Re as e,Ce as f,On as g,xn as h,En as i,ve as j,In as k,Pn as l,Bn as m,Ut as n,xe as o,Wt as p,Ht as q,Yn as r,zt as s,Jt as t,Vt as u,Yt as v,ti as w,eo as x,oo as y,io as z,an as A,rn as B,ho as C,ko as D};
474
+ `);for(let a of e.getRunning())a.module==="checkpoint"&&e.abort(a.operationId)});try{let d=await t();return o!==void 0?{answer:d,stoppedBy:o}:{answer:d}}finally{s(),i()}}var fn=720*6e4;function pn(e,n,t=o=>o){let{answer:o,stoppedBy:i}=e;if(o.outcome!=="answered"){let s=t(P(o,n));throw i!==void 0&&s.code==="CANCELLED"?new b(s,ie(i)):new b(s,1,lo(o).map(t))}return D(o).result}async function bo(e,n){let{host:t,say:o,answerJson:i}=n,s=await n.listAll(),d=te(G(s,_(s,e.org),e.checkpoint,e.org)),a=Ce(d);if(a)throw new b(a);let r=d.checkpoint,p=e.ignoreFields.filter(A=>!r.ignoredFields.includes(A));if(p.length>0){let A=await t.request({type:"checkpoint:ignore-fields",payload:{checkpointId:d.checkpointId,fields:[...r.ignoredFields,...p]},timeoutMs:ce});if(A.outcome!=="answered")throw new b(P(A,"The fields not to compare"));r=D(A).checkpoint,o(`not compared from now on, nor written back: ${p.join(", ")} (kept in '${r.name}')`)}let m=e.objects.length>0?Zt(r,e.objects):void 0,g=await n.connect(e.org);De(g,d,r,e.org,"rewind");let v=await t.request({type:"checkpoint:preview",payload:{checkpointId:d.checkpointId,...m?{objects:m}:{},...e.muteAutomation?{muteAutomation:!0}:{},acceptOutside:e.acceptOutside},timeoutMs:hn});if(v.outcome!=="answered")throw new b(P(v,"The preview"));let w=D(v),c=m?await Ne(t,w.diff,m,e.acceptOutside):void 0,l=m?void 0:await Xt(t,r,w.diff,e.acceptOutside),k=c??l,y=k?{...w,diff:k.diff}:w,h=e.muteAutomation&&y.automation?Ye(y.automation,Me(X(y.diff))):void 0,f=h?{...y,automation:h.automation}:y;for(let A of Ht(e.org,r,f,g.username,e.acceptAutomation))o(A);for(let A of c?Vt(c.plan):[])o(A);for(let A of l?Yt(l.plan):[])o(A);for(let A of h?se(h.planned,e.org):[])o(` ${A}`);let j=ct(f.diff).length>0,C=await we({orgName:e.org,preview:f,bounds:{...e.maxRecords!==void 0?{maxRecords:e.maxRecords}:{},refuseWhenActive:e.refuseWhenActive},accepted:e,writers:async()=>dt(r.takenBy,await n.userIdOf(g)),words:ee,user:g.username}),O=Qt(f.refusal,C);if(Kt(r,f.diff,e.acceptOutside)&&o(" without --accept-outside, the records they hang from stay, and so do they: each is said once the rewind is through"),e.dryRun){for(let A of O.slice(f.refusal?1:0))o(` a rewind now would be refused (${A.code}): ${A.message}`);i({...zt(e.org,r,w,c,l),...h?{mutedAutomation:h.planned,mutePlan:h.plan}:{},...O.length>0?{wouldBeRefused:O.map(A=>V(A)),wouldBeRefusedCodes:O.map(A=>A.code)}:{}});return}let[q,...N]=O;if(q)throw new b(q,1,N);if(j&&!e.yes&&await pe(no(e.org,r,f.diff,m))!==e.org)throw new b({code:"DECLINED",message:"Nothing was written."});let L=await Pe(n.registry,"the rewind stops before its next call to the org, and leaves its journal: rewind again takes up from what still differs",()=>t.request({type:"checkpoint:rewind",payload:{checkpointId:d.checkpointId,previewId:f.diff.previewId,...m?{objects:m}:{},acceptAutomation:e.acceptAutomation,...e.acceptEmails?{acceptEmails:!0}:{},...e.muteAutomation?{muteAutomation:!0}:{},acceptNoUndo:e.acceptNoUndo,acceptRecreate:e.acceptRecreate,acceptOutside:e.acceptOutside,acceptUnseen:e.acceptUnseen},timeoutMs:fn})),I=pn(L,"The rewind",A=>A.code==="CANCELLED"?{...A,message:nn(e.org,r.name)}:Qn(A)),ne=e.storeRoot!==ue()?e.storeRoot:void 0;for(let A of so(e.org,r,I,f.diff.userNames,ne))o(A);for(let A of I.mutedAutomation?se(I.mutedAutomation,e.org):[])o(A);i(dn("rewind",e.org,r,I,f.diff)),B(cn(I.status,L.stoppedBy))}function yo(e,n,t,o,i){return`undo the rewind ${t} of ${e} to '${n.name}' (open until ${E(o)}, sooner if the recycle bin fills)`+(i?`: it brings back ${u(i.bringBack)} record(s) the rewind deleted`+((i.bringBackAlong??0)>0?`, with the ${u(i.bringBackAlong??0)} that went with them`:"")+`, gives ${u(i.giveBack)} record(s) back the values they had before it, and sends ${u(i.remove-i.remade)} record(s) it brought back to the recycle bin`+(i.along>0?", with what came back with them":"")+(i.remade>0?`, deleting again the ${u(i.remade)} record(s) it made again`:"")+(i.drafted>0?` \u2014 of them, ${u(i.drafted)} order(s) set back to Draft first if past it, the one way Salesforce deletes one: an update, which what runs on an order's update fires on`:"")+"; what anyone changed since the rewind stays":"")}async function $o(e,n,t,o){try{let i=e.folderOf(n.organizationId,n.checkpointId),s=await ft(i,o,t.objects);try{return{bringBack:s.bringBack.count,bringBackAlong:s.comesWithParent.count,giveBack:s.giveBack.count,remove:s.remove.spool.count,along:s.goesWithParent.count,remade:s.remade.keys.size,drafted:s.remade.objects.filter(({objectApiName:d})=>Ke([d]).length>0).reduce((d,{count:a})=>d+a,0)}}finally{await s.dispose()}}catch{return}}async function vo(e,n){let{host:t,say:o,answerJson:i}=n,s=await n.listAll(),d=_(s,e.org),a=e.checkpoint===void 0?d.find(k=>k.undo!==void 0):te(G(s,d,e.checkpoint,e.org));if(!a)throw new b({code:"NOT_FOUND",message:`No rewind of ${e.org} can be undone from this machine: Undo is offered for the last rewind of an org, for 15 days after it, until it is undone. Nothing was written.`});let r=Ce(a);if(r)throw new b(r);let p=a.checkpoint;if(!a.undo)throw new b({code:"UNDO_CLOSED",message:`'${p.name}' has no rewind that can be undone: Undo is offered for the last rewind of an org only, for 15 days after it, until it is undone. Nothing was written.`});let{rewindId:m,until:g}=a.undo,v=await $o(n.store,a,p,m);o(yo(e.org,p,m,g,v));let w=await n.connect(e.org);if(De(w,a,p,e.org,"undo"),!e.yes&&await pe(`Type ${e.org} to undo its rewind:`)!==e.org)throw new b({code:"DECLINED",message:"Nothing was written."});let c=await Pe(n.registry,"the undo stops before its next call to the org: undo again takes up what it left",()=>t.request({type:"checkpoint:undo",payload:{checkpointId:a.checkpointId,rewindId:m,acceptAutomation:e.acceptAutomation,...e.acceptEmails?{acceptEmails:!0}:{},...e.muteAutomation?{muteAutomation:!0}:{}},timeoutMs:fn})),l=pn(c,"The undo",k=>k.code==="CANCELLED"?{...k,message:on(e.org)}:eo(k));for(let k of ao(e.org,p,l))o(k);for(let k of l.mutedAutomation?se(l.mutedAutomation,e.org):[])o(k);i(dn("undo",e.org,p,l)),B(cn(l.status,c.stoppedBy))}process.argv[1]?.includes("sandforge-checkpoint")&&(rt(),uo().then(()=>process.exit(process.exitCode??0)).catch(e=>{process.stderr.write(`${e instanceof Error?e.message:String(e)}
475
+ `),process.exit(1)}));export{Cn as a,Sn as b,_ as c,G as d,Ce as e,Se as f,En as g,Nn as h,In as i,ve as j,Dn as k,Tn as l,_n as m,Wt as n,Ee as o,Ht as p,zt as q,Zn as r,Vt as s,Kt as t,Yt as u,Zt as v,ii as w,no as x,so as y,ao as z,dn as A,cn as B,uo as C,yo as D};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
7
+ import{a,b,c}from"./chunk-OLCVHL7I.mjs";import"./chunk-DPMRIMUC.mjs";import"./chunk-SI267LYR.mjs";import"./chunk-H4OBZIX3.mjs";import"./chunk-KAZS5Z6W.mjs";import"./chunk-BBRWFKS5.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-EPFCERGL.mjs";import"./chunk-IUM4NFKI.mjs";import"./chunk-PMN4PAC3.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-CA5NAXSU.mjs";import"./chunk-UNDIBZWG.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as DX_PROJECT_FILE,b as scenarioProjectOf,c as writeRunTestFile};
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{a as S,b as k}from"./chunk-UNDIBZWG.mjs";import{qc as m,rc as z,sc as E,tc as h}from"./chunk-6QSHWIZI.mjs";import{b as c,f as g,i as f,k as l,l as d}from"./chunk-WZQEK4WT.mjs";var D=/\bid\.?\s*:\s*([A-Za-z0-9]{18}|[A-Za-z0-9]{15})(?![A-Za-z0-9])/i;function x(e,s){let t;if(/^[A-Za-z0-9]{15}$/.test(e))t=S(e);else if(k(e))t=e;else return;if(!(s&&!t.startsWith(s)))return t}function v(e){return D.exec(e)?.[1]}var R=d({statusCode:c().optional(),errorCode:c().optional(),message:c().optional(),fields:l(f()).optional(),duplicateResult:f().optional()}).loose(),p="UNKNOWN_ERROR";function y(e){if(typeof e=="string")return{statusCode:p,message:e,fields:[]};let s=R.safeParse(e);return s.success?{statusCode:s.data.statusCode??s.data.errorCode??p,message:s.data.message??"",fields:(s.data.fields??[]).filter(t=>typeof t=="string")}:{statusCode:p,message:"Unknown error",fields:[]}}var _=/^([A-Z][A-Z0-9_]*):([\s\S]*):([A-Za-z0-9_]+(?: [A-Za-z0-9_]+)*)? ?--$/;function M(e){let s=e.trim();if(!s.endsWith("--")||s.slice(0,-2).includes("--"))return;let t=_.exec(s);if(t)return{statusCode:t[1],message:t[2],fields:t[3]===void 0?[]:t[3].split(" ")}}var b=d({matchResults:l(d({entityType:c().optional(),matchRecords:l(d({record:d({Id:c().optional(),attributes:d({type:c().optional()}).loose().optional()}).loose().optional()}).loose()).optional()}).loose()).optional()}).loose(),I=d({id:c().nullish(),success:g(),created:g().optional(),errors:l(f()).optional()}).loose();function P(e){return e.statusCode===p?e.message:`${e.statusCode}: ${e.message}`}function A(e){if(typeof e=="string")return e;let s=R.safeParse(e);if(!s.success)return"Unknown error";let t=s.data.statusCode??s.data.errorCode,n=s.data.message??"",r=t?`${t}: ${n}`:n,i=(s.data.fields??[]).filter(a=>typeof a=="string");if(i.length===0)return r;let o=`[${i.join(", ")}]`;return r.includes(o)?r:r?`${r} ${o}`:o}var C=5;function T(e){let s=(e??[]).map(r=>A(r)).filter(r=>r!==""&&r!=="Unknown error");if(s.length===0)return"Unknown insert error";let t=s.slice(0,C).join("; "),n=s.length-C;return n>0?`${t} (and ${n} more)`:t}function O(e,s){let t=R.safeParse(e);if(!t.success)return[];if((t.data.statusCode??t.data.errorCode)!==m)return[];let n=b.safeParse(t.data.duplicateResult);if(!n.success)return[];let r=[];for(let i of n.data.matchResults??[])for(let{record:o}of i.matchRecords??[]){let a=[i.entityType,o?.attributes?.type].filter(u=>typeof u=="string");a.length===0||a.some(u=>u!==s)||o?.Id&&r.push(o.Id)}return r}function w(e,s){let t=I.safeParse(e);if(!t.success){let i="Salesforce returned a save result of an unexpected shape";return{id:"",success:!1,errors:[i],errorDetails:[y(i)]}}let n=t.data.errors??[],r=n.flatMap(i=>O(i,s));return{id:t.data.id??"",success:t.data.success,...t.data.created!==void 0?{created:t.data.created}:{},errors:n.map(A),errorDetails:n.map(y),...r.length>0?{duplicateMatchIds:r}:{}}}function Z(e,s){return(Array.isArray(e)?e:[e]).map(t=>w(t,s))}function L(e,s){if(e.success||e.errors.length===0)return{kind:"none"};let t=o=>h(o)||z(o);if(!e.errors.every(t))return{kind:"none"};let n=new Set,r=!1;for(let o of e.errors){if(!o.includes(E))continue;let a=v(o),u=a?x(a,s):void 0;u?n.add(u):r=!0}let i=e.duplicateMatchIds??[];e.errors.some(o=>o.includes(m))&&i.length===0&&(r=!0);for(let o of i){let a=x(o,s);a?n.add(a):r=!0}return r||n.size!==1?{kind:"unidentified"}:{kind:"linked",id:[...n][0]}}export{x as a,p as b,y as c,M as d,P as e,A as f,T as g,O as h,w as i,Z as j,L as k};
7
+ import{a as S,b as k}from"./chunk-UNDIBZWG.mjs";import{qc as m,rc as z,sc as E,tc as h}from"./chunk-PMWAFDUB.mjs";import{b as c,f as g,i as f,k as l,l as d}from"./chunk-WZQEK4WT.mjs";var D=/\bid\.?\s*:\s*([A-Za-z0-9]{18}|[A-Za-z0-9]{15})(?![A-Za-z0-9])/i;function x(e,s){let t;if(/^[A-Za-z0-9]{15}$/.test(e))t=S(e);else if(k(e))t=e;else return;if(!(s&&!t.startsWith(s)))return t}function v(e){return D.exec(e)?.[1]}var R=d({statusCode:c().optional(),errorCode:c().optional(),message:c().optional(),fields:l(f()).optional(),duplicateResult:f().optional()}).loose(),p="UNKNOWN_ERROR";function y(e){if(typeof e=="string")return{statusCode:p,message:e,fields:[]};let s=R.safeParse(e);return s.success?{statusCode:s.data.statusCode??s.data.errorCode??p,message:s.data.message??"",fields:(s.data.fields??[]).filter(t=>typeof t=="string")}:{statusCode:p,message:"Unknown error",fields:[]}}var _=/^([A-Z][A-Z0-9_]*):([\s\S]*):([A-Za-z0-9_]+(?: [A-Za-z0-9_]+)*)? ?--$/;function M(e){let s=e.trim();if(!s.endsWith("--")||s.slice(0,-2).includes("--"))return;let t=_.exec(s);if(t)return{statusCode:t[1],message:t[2],fields:t[3]===void 0?[]:t[3].split(" ")}}var b=d({matchResults:l(d({entityType:c().optional(),matchRecords:l(d({record:d({Id:c().optional(),attributes:d({type:c().optional()}).loose().optional()}).loose().optional()}).loose()).optional()}).loose()).optional()}).loose(),I=d({id:c().nullish(),success:g(),created:g().optional(),errors:l(f()).optional()}).loose();function P(e){return e.statusCode===p?e.message:`${e.statusCode}: ${e.message}`}function A(e){if(typeof e=="string")return e;let s=R.safeParse(e);if(!s.success)return"Unknown error";let t=s.data.statusCode??s.data.errorCode,n=s.data.message??"",r=t?`${t}: ${n}`:n,i=(s.data.fields??[]).filter(a=>typeof a=="string");if(i.length===0)return r;let o=`[${i.join(", ")}]`;return r.includes(o)?r:r?`${r} ${o}`:o}var C=5;function T(e){let s=(e??[]).map(r=>A(r)).filter(r=>r!==""&&r!=="Unknown error");if(s.length===0)return"Unknown insert error";let t=s.slice(0,C).join("; "),n=s.length-C;return n>0?`${t} (and ${n} more)`:t}function O(e,s){let t=R.safeParse(e);if(!t.success)return[];if((t.data.statusCode??t.data.errorCode)!==m)return[];let n=b.safeParse(t.data.duplicateResult);if(!n.success)return[];let r=[];for(let i of n.data.matchResults??[])for(let{record:o}of i.matchRecords??[]){let a=[i.entityType,o?.attributes?.type].filter(u=>typeof u=="string");a.length===0||a.some(u=>u!==s)||o?.Id&&r.push(o.Id)}return r}function w(e,s){let t=I.safeParse(e);if(!t.success){let i="Salesforce returned a save result of an unexpected shape";return{id:"",success:!1,errors:[i],errorDetails:[y(i)]}}let n=t.data.errors??[],r=n.flatMap(i=>O(i,s));return{id:t.data.id??"",success:t.data.success,...t.data.created!==void 0?{created:t.data.created}:{},errors:n.map(A),errorDetails:n.map(y),...r.length>0?{duplicateMatchIds:r}:{}}}function Z(e,s){return(Array.isArray(e)?e:[e]).map(t=>w(t,s))}function L(e,s){if(e.success||e.errors.length===0)return{kind:"none"};let t=o=>h(o)||z(o);if(!e.errors.every(t))return{kind:"none"};let n=new Set,r=!1;for(let o of e.errors){if(!o.includes(E))continue;let a=v(o),u=a?x(a,s):void 0;u?n.add(u):r=!0}let i=e.duplicateMatchIds??[];e.errors.some(o=>o.includes(m))&&i.length===0&&(r=!0);for(let o of i){let a=x(o,s);a?n.add(a):r=!0}return r||n.size!==1?{kind:"unidentified"}:{kind:"linked",id:[...n][0]}}export{x as a,p as b,y as c,M as d,P as e,A as f,T as g,O as h,w as i,Z as j,L as k};
@@ -4,5 +4,5 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{a as w,b as x}from"./chunk-OTJH6AEA.mjs";import{b as R}from"./chunk-77MZRBWX.mjs";import{g as k}from"./chunk-BT43WSOS.mjs";import{Ia as g,La as l,Sb as h}from"./chunk-6QSHWIZI.mjs";import{b as d,m as S,s as u,v as f}from"./chunk-WZQEK4WT.mjs";import{createHash as $}from"node:crypto";import{mkdir as y,readFile as C,rename as P,writeFile as O}from"node:fs/promises";import*as a from"node:path";var A=k,N=d().regex(/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,"A record id"),p=S({version:f(1),runId:d().min(1).max(200),packId:g,packFingerprint:d().regex(/^[0-9a-f]{64}$/,"A sha256, in lower-case hexadecimal"),compile:l.refine(e=>e.seed!==void 0,{message:"The seed the pack was compiled with is kept",path:["seed"]}),openCases:u(d().min(1).max(255),N),agent:h.optional()});function F(e){return $("sha256").update(m(e)).digest("hex")}function v(e){let r={};for(let i of e.compiled.tests){let n=i.openCase?.caseKey;if(n===void 0)continue;let t=e.caseIds[n];t!==void 0&&(r[n]=t)}return p.parse({version:1,runId:e.runId,packId:e.pack.id,packFingerprint:F(e.pack),compile:{...e.options,seed:e.compiled.seed},openCases:r})}function D(e,r){return p.parse({...e,agent:r})}function U(e,r){if(r.id!==e.packId)return{ok:!1,message:`The run was seeded from the scenario ${e.packId}, not ${r.id}`};if(F(r)!==e.packFingerprint)return{ok:!1,message:`The scenario ${r.id} has changed since the run: its tests would be about subjects and addresses no record of the run holds`};try{return{ok:!0,compiled:x(r,e.compile)}}catch(i){if(i instanceof w)return{ok:!1,message:i.message};throw i}}function Z(){return{readFile:e=>C(e,"utf8"),writeFile:(e,r)=>O(e,r,"utf8"),rename:(e,r)=>P(e,r),mkdir:async e=>{await y(e,{recursive:!0})}}}function I(e,r){return a.join(e,R,`${r.replace(/[^A-Za-z0-9_-]/g,"_")}${A}`)}async function K(e,r,i){let n=p.parse(i),t=I(r,n.runId),o=`${t}.${process.pid}.tmp`;return await e.mkdir(a.dirname(t)),await e.writeFile(o,`${JSON.stringify(n,null,2)}
7
+ import{a as w,b as x}from"./chunk-KAZS5Z6W.mjs";import{b as R}from"./chunk-EPFCERGL.mjs";import{g as k}from"./chunk-PMN4PAC3.mjs";import{Ia as g,La as l,Sb as h}from"./chunk-PMWAFDUB.mjs";import{b as d,m as S,s as u,v as f}from"./chunk-WZQEK4WT.mjs";import{createHash as $}from"node:crypto";import{mkdir as y,readFile as C,rename as P,writeFile as O}from"node:fs/promises";import*as a from"node:path";var A=k,N=d().regex(/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,"A record id"),p=S({version:f(1),runId:d().min(1).max(200),packId:g,packFingerprint:d().regex(/^[0-9a-f]{64}$/,"A sha256, in lower-case hexadecimal"),compile:l.refine(e=>e.seed!==void 0,{message:"The seed the pack was compiled with is kept",path:["seed"]}),openCases:u(d().min(1).max(255),N),agent:h.optional()});function F(e){return $("sha256").update(m(e)).digest("hex")}function v(e){let r={};for(let i of e.compiled.tests){let n=i.openCase?.caseKey;if(n===void 0)continue;let t=e.caseIds[n];t!==void 0&&(r[n]=t)}return p.parse({version:1,runId:e.runId,packId:e.pack.id,packFingerprint:F(e.pack),compile:{...e.options,seed:e.compiled.seed},openCases:r})}function D(e,r){return p.parse({...e,agent:r})}function U(e,r){if(r.id!==e.packId)return{ok:!1,message:`The run was seeded from the scenario ${e.packId}, not ${r.id}`};if(F(r)!==e.packFingerprint)return{ok:!1,message:`The scenario ${r.id} has changed since the run: its tests would be about subjects and addresses no record of the run holds`};try{return{ok:!0,compiled:x(r,e.compile)}}catch(i){if(i instanceof w)return{ok:!1,message:i.message};throw i}}function Z(){return{readFile:e=>C(e,"utf8"),writeFile:(e,r)=>O(e,r,"utf8"),rename:(e,r)=>P(e,r),mkdir:async e=>{await y(e,{recursive:!0})}}}function I(e,r){return a.join(e,R,`${r.replace(/[^A-Za-z0-9_-]/g,"_")}${A}`)}async function K(e,r,i){let n=p.parse(i),t=I(r,n.runId),o=`${t}.${process.pid}.tmp`;return await e.mkdir(a.dirname(t)),await e.writeFile(o,`${JSON.stringify(n,null,2)}
8
8
  `),await e.rename(o,t),t}async function X(e,r,i){let n=I(r,i),t;try{t=await e.readFile(n)}catch(c){if(c.code==="ENOENT")return{kind:"absent"};throw c}let o;try{o=JSON.parse(t)}catch{return{kind:"invalid",message:`${a.basename(n)} is not JSON`}}let s=p.safeParse(o);if(!s.success){let c=s.error.issues[0];return{kind:"invalid",message:`${a.basename(n)}: ${c.path.join(".")||"the file"}: ${c.message}`}}return s.data.runId!==i?{kind:"invalid",message:`${a.basename(n)} is the companion of the run ${s.data.runId}, not ${i}`}:{kind:"read",sidecar:s.data}}function m(e){return Array.isArray(e)?`[${e.map(r=>m(r??null)).join(",")}]`:e!==null&&typeof e=="object"?`{${Object.entries(e).filter(([,i])=>i!==void 0).sort(([i],[n])=>i<n?-1:i>n?1:0).map(([i,n])=>`${JSON.stringify(i)}:${m(n)}`).join(",")}}`:JSON.stringify(e??null)}export{A as a,p as b,F as c,v as d,D as e,U as f,Z as g,I as h,K as i,X as j};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
7
+ import{a,b,c,d,e,f,g,h,i}from"./chunk-KZTZDC7H.mjs";import"./chunk-SI267LYR.mjs";import"./chunk-KAZS5Z6W.mjs";import"./chunk-BBRWFKS5.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-EPFCERGL.mjs";import"./chunk-IUM4NFKI.mjs";import"./chunk-PMN4PAC3.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as SCENARIO_PACK_FILE_SUFFIX,b as SCENARIO_PACK_SEARCH,i as findScenarioPack,e as findScenarioPackFiles,f as listScenarioPacks,c as nodeScenarioPackFiles,d as readScenarioPackText,h as saveScenarioPack,g as scenarioPackText};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
7
+ import{a as O,f as dt,h as C}from"./chunk-TZE3Y7IQ.mjs";import{Oc as at}from"./chunk-PMWAFDUB.mjs";var It="AccountContactRelation",v="EmailMessage",J="Task",Q="TaskRelation",q="EventRelation",j=200,en={ProductSellingModel:["SellingModelType","PricingTerm","PricingTermUnit"]},rn={objectApiName:"FeedItem",field:"Type",value:"CreateRecordEvent",parent:"ParentId"},Z={FeedItem:[{field:"Type",value:"TrackedChange",noun:"tracked change"}],[Q]:[{field:"IsWhat",value:!0,noun:"what relation",from:"the task's WhatId"}],[q]:[{field:"IsWhat",value:!0,noun:"what relation",from:"the event's WhatId"}],EmailMessageRelation:[{noun:"email relation",from:"the email's addresses"}]};function Et(t,n){return Z[t]?.find(e=>e.field===void 0||e.value!==void 0&&String(n[e.field])===String(e.value))}var ut=class{constructor(n=Et){this.rowsOf=n}rowsOf;reasons=new Map;byObject=new Map;leaveOut(n,e,r,o=[]){let i=this.reasons.get(e);if(i)return i;let s=this.reasonFor(n,r,o);if(!s)return;this.reasons.set(e,s);let d=this.byObject.get(n)??new Map,u=`${s.rows.field}=${s.rows.value}|${s.through??""}`,l=d.get(u)??{why:s,ids:new Set};return l.ids.add(e),d.set(u,l),this.byObject.set(n,d),s}keep(n,e,r=[]){return e.filter(o=>!this.leaveOut(n,String(o.Id),o,r))}has(n){return this.reasons.has(n)}counts(n){return(n===void 0?[...this.byObject]:[[n,this.byObject.get(n)]]).flatMap(([r,o])=>[...o?.values()??[]].map(({why:i,ids:s})=>({objectApiName:r,why:i,count:s.size})))}reasonFor(n,e,r){let o=this.rowsOf(n,e);if(o)return{rows:o};for(let i of r){let s=e[i],d=typeof s=="string"?this.reasons.get(s):void 0;if(d)return{rows:d.rows,through:i}}}};function on(t,n){if(n.through)return`${t} left out: ${n.through} names a ${n.rows.noun}, which the platform writes itself`;let e=n.rows.from?`, from ${n.rows.from}`:"";return`${t} ${n.rows.noun}${t===1?"":"s"} left out: the platform writes them itself${e}`}function sn(t,n){let e=`${t} record${t===1?"":"s"}`;return n.through?`${n.through} \u2192 ${n.rows.noun} (${e})`:n.rows.field===void 0?`every ${n.rows.noun} (${e})`:`${n.rows.field}=${String(n.rows.value)} (${e})`}function an(t){return t.through?`Not written: ${t.through} may not be left empty, and the ${t.rows.noun} it names is one the platform writes itself, which no copy sends.`:t.rows.from?`Not written: the platform writes each ${t.rows.noun} itself, from ${t.rows.from}.`:`Not written: the platform writes each ${t.rows.noun} itself, and refuses one a copy sends.`}function ct({field:t,value:n},e){if(t===void 0)return e==="="?"Id != null":"Id = null";let r=typeof n=="boolean"?String(n):`'${O(n??"")}'`;return`${C(t)} ${e} ${r}`}function dn(t,n,e){let r=s=>s.map(d=>ct(d,"=")).join(" OR "),o=(Z[t]??[]).map(s=>ct(s,"!=")),i=n.flatMap(s=>s.referenceTo.flatMap(d=>{let u=Z[d];if(d===t||!e.has(d)||!u||u.length===0)return[];let l=e.get(d),I=l?`(${dt(l)}) AND (${r(u)})`:`(${r(u)})`;return[`${C(s.name)} NOT IN (SELECT Id FROM ${C(d)} WHERE ${I})`]}));return[...o,...i]}var $t={[Q]:new Set(["Contact","Lead"]),[q]:new Set(["Contact","Lead","User","Calendar"])};function un(t,n,e){let r=$t[t];if(!r)return n;let o=n.IsWhat;return o!==""&&o!==null&&o!==void 0||e===void 0||r.has(e)?n:{...n,IsWhat:!0}}var Ct="500";function Pt(t){return t.startsWith(Ct)?"Case":void 0}function ht(t,n=Pt){let e=t.ParentId;if(typeof e=="string"&&e!=="")return!0;let r=t.RelatedToId;return typeof r=="string"&&r!==""&&n(r)==="Case"}function cn(t,n){return t===v&&!ht(n)?["ActivityId"]:[]}function fn(t){return!t.has(v)||!t.has(J)?[]:[{sourceObject:v,targetObject:J,relationshipName:`${v}Before${J}`,type:"lookup",required:!0}]}function ln(t,n){let e=t.ActivityId;return typeof e=="string"&&e!==""&&ht(t,n)}var S=200;async function gn(t,n){let e=new Map;for(let r=0;r<n.length;r+=S){let o=n.slice(r,r+S).map(s=>`'${O(s)}'`).join(", "),i=await t(`SELECT Id, ActivityId FROM ${v} WHERE Id IN (${o})`);for(let s of i){let d=s.ActivityId;typeof s.Id=="string"&&typeof d=="string"&&d!==""&&e.set(s.Id,d)}}return e}var N="Account",B="Contact",Y="PersonContactId",mt="IsPersonAccount";function kt(t){let n=t[mt];return n===!0||n==="true"||n===1}function pn(t,n){return kt(t)?n?"personAsBusiness":"person":"business"}function yn(t,n){return t==="person"?n==="person":n!=="person"}function Rn(t,n){return!t.has(N)||!t.has(B)?[]:n.get(N)?.some(r=>r.name===Y)===!0||n.get(B)?.some(r=>r.name===mt)===!0?[{sourceObject:N,targetObject:B,relationshipName:`${N}Before${B}`,type:"lookup",required:!0}]:[]}function Mt(t){let n=t.map(e=>`'${O(e)}'`).join(", ");return`SELECT Id, ${Y} FROM ${N} WHERE Id IN (${n})`}var At=new RegExp(`^SELECT Id, ${Y} FROM ${N} WHERE Id IN \\((.*)\\)$`);function wn(t){let n=At.exec(t);if(n)return[...n[1].matchAll(/'([^']*)'/g)].map(([,e])=>e)}async function In(t,n){let e=new Map;for(let r=0;r<n.length;r+=S){let o=await t(Mt(n.slice(r,r+S)));for(let i of o){let s=i[Y];typeof i.Id=="string"&&typeof s=="string"&&s!==""&&e.set(i.Id,s)}}return e}var D="OpportunityTeamMember",M="OpportunitySplit",Lt="Opportunity",tt="OpportunitySplitType",$="SplitTypeId",nt={[D]:"UserId",[M]:"SplitOwnerId"};function hn(t){return nt[t]!==void 0}function mn(t){return t==="Task"?"their email":t==="Contact"?"their person account":t===It?"their contact":t===Q?"their task":t===q?"their event":t===Ot?"their opportunity, for its contact":"their opportunity, for its owner"}var Ot="OpportunityContactRole",G="ContactId",ft=t=>t.IsPrimary===!0||t.IsPrimary==="true";function Nt(t,n){let e=new Map;return t.forEach((r,o)=>{let i=w(r,"OpportunityId"),s=w(r,G);if(i===void 0||s===void 0)return;let d=n(i);if(d===void 0||y(d)!==y(s))return;let u=y(i),l=e.get(u);(l===void 0||!ft(t[l])&&ft(r))&&e.set(u,o)}),[...e.values()].sort((r,o)=>r-o)}var lt=["CreatedDate","CreatedById","Opportunity.CreatedDate","Opportunity.CreatedById"];function xt(t,n=[]){let e=["Id","OpportunityId",G],r=[...e,...lt];return`SELECT ${[...e,...lt,...n.filter(i=>!r.includes(i)).map(C)].join(", ")} FROM ${Ot} WHERE OpportunityId IN ${et(t)} ORDER BY CreatedDate, Id`}var bt=/^SELECT Id, OpportunityId, ContactId, CreatedDate, CreatedById, Opportunity\.CreatedDate, Opportunity\.CreatedById((?:, \w+)*) FROM OpportunityContactRole WHERE OpportunityId IN (\(.*\)) ORDER BY CreatedDate, Id$/;function On(t){let n=bt.exec(t);if(!n)return;let[,e,r]=n;return{fields:e.split(", ").filter(o=>o!==""),opportunities:rt(r)}}async function _t(t,n,e=[]){let r=[];for(let o=0;o<n.length;o+=S)r.push(...await t(xt(n.slice(o,o+S),e)));return r}var Ft=1,gt=t=>typeof t=="string"&&t!==""?Math.floor(Date.parse(t)/1e3):Number.NaN;function Wt(t){let n=t.Opportunity;if(typeof n!="object"||n===null)return!1;let e=n,r=w(t,"CreatedById"),o=w(e,"CreatedById"),i=gt(t.CreatedDate),s=gt(e.CreatedDate);return r!==void 0&&o!==void 0&&y(r)===y(o)&&!Number.isNaN(i)&&!Number.isNaN(s)&&i-s>=0&&i-s<=Ft}function vt(t,n){let e=new Map;for(let i of n){let s=w(i,"Id"),d=w(i,"OpportunityId"),u=w(i,G);if(!s||!d||!u||!Wt(i))continue;let l=`${y(d)}:${y(u)}`;e.set(l,[...e.get(l)??[],i])}let r=new Map,o=[];for(let[i,{opportunity:s,contact:d}]of t){let u=e.get(`${y(s)}:${y(d)}`)??[];u.length>1?o.push(i):u.length===1&&r.set(i,u[0])}return{found:r,alike:o}}function Tn(t,n="read"){return`${t} contact role(s) not linked to the one the platform wrote with their opportunity, so written as ${n}: the target holds more than one role of their contact under it made with it, within a second, by the same user, and nothing tells which the platform wrote. The opportunity holds the role of its contact more than once.`}var Dt="the user the run writes as";function Sn(t,n){let e={CreatedDate:n,CreatedById:Dt};return{...t,...e,Opportunity:{...e}}}async function En(t,n,e,r=[]){let o=Nt(n,e);if(o.length===0)return{found:new Map,alike:[]};let i=new Map(o.map(d=>[d,{opportunity:String(n[d].OpportunityId),contact:String(n[d][G])}])),s=await _t(t,[...new Set([...i.values()].map(({opportunity:d})=>d))],r);return vt(i,s)}function $n(t){return!t.has(D)||!t.has(M)?[]:[{sourceObject:D,targetObject:M,relationshipName:`${D}Before${M}`,type:"lookup",required:!0}]}var Ut={[D]:{TeamMemberRole:"Opportunity Owner",OpportunityAccessLevel:"All"},[M]:{}},pt=t=>!/__c$/i.test(t),qt=new Set(["SplitPercentage","SplitAmount","CurrencyIsoCode"]),U=`SELECT Id, OwnerId FROM ${Lt} WHERE Id IN `,Kt=`SELECT Id, DeveloperName, IsTotalValidated FROM ${tt} WHERE IsActive = true`,et=t=>`(${t.map(n=>`'${O(n)}'`).join(", ")})`,rt=t=>[...t.matchAll(/'([^']*)'/g)].map(([,n])=>n);function Cn(t){return`${U}${et(t)}`}function Pn(t){if(!t.startsWith(U))return;let n=t.slice(U.length);return/^\(.*\)$/.test(n)?rt(n):void 0}function Tt(t,n){let e=nt[t];return`SELECT ${["Id","OpportunityId",...t===M?[e,$]:[e],...n].join(", ")} FROM ${t} WHERE OpportunityId IN `}function kn(t,n,e){return`${Tt(t,n)}${et(e)}`}var Ht=/^SELECT Id, OpportunityId, (?:UserId|SplitOwnerId, SplitTypeId)((?:, \w+)*) FROM (OpportunityTeamMember|OpportunitySplit) WHERE OpportunityId IN (\(.*\))$/;function Mn(t){let n=Ht.exec(t);if(!n)return;let[,e,r,o]=n;return{objectApiName:r,fields:e.split(", ").filter(i=>i!==""),opportunities:rt(o)}}var y=t=>t.slice(0,15);async function W(t,n,e){let r=[];for(let o=0;o<e.length;o+=S){let i=e.slice(o,o+S).map(s=>`'${O(s)}'`).join(", ");r.push(...await t(`${n}(${i})`))}return r}function X(t,n){let e=new Map;for(let r of t){let o=r[n];typeof r.Id=="string"&&typeof o=="string"&&o!==""&&e.set(y(r.Id),o)}return e}var w=(t,n)=>{let e=t[n];return typeof e=="string"&&e!==""?e:void 0};async function An(t,n,e){let r={lookups:new Map,linked:new Map,held:new Map,defaulted:new Set},o=nt[t];if(o===void 0)return r;let i=t===M,s=n.filter(a=>{let f=w(a,"OpportunityId");return f!==void 0&&e.targetIdOf(f)!==void 0});if(s.length===0)return r;let d=[...new Set(s.map(a=>String(a.OpportunityId)))],u=X(await W(e.source,U,d),"OwnerId"),l=a=>e.targetIdOf(String(a.OpportunityId)),I=[...new Set(s.map(l))],{simulated:T}=e,x=T?void 0:X(await W(e.target,U,I),"OwnerId"),b=a=>{let f=u.get(y(String(a.OpportunityId)));return f===void 0?{}:{source:f,target:T?T.ownerOf(f):x?.get(y(l(a)))}},_=a=>{let f=w(a,o),R=b(a).source;return f!==void 0&&R!==void 0&&y(f)===y(R)},A=[...new Set(s.flatMap(a=>{let f=w(a,o);return f===void 0||_(a)||e.mappedUser(f)!==void 0?[]:[f]}))],K=A.length>0?new Set((await W(e.target,"SELECT Id FROM User WHERE IsActive = true AND Id IN ",A)).flatMap(a=>typeof a.Id=="string"?[y(a.Id)]:[])):new Set,H=i?X(await W(e.source,`SELECT Id, DeveloperName FROM ${tt} WHERE Id IN `,[...new Set(s.flatMap(a=>w(a,$)??[]))]),"DeveloperName"):new Map,F=new Map;if(i)for(let a of await e.target(Kt))typeof a.Id=="string"&&typeof a.DeveloperName=="string"&&F.set(a.DeveloperName,{id:a.Id,total:a.IsTotalValidated===!0||a.IsTotalValidated==="true"});let c=(e.written??[]).filter(a=>a!=="Id"&&a!=="OpportunityId"&&a!==o&&a!==$&&!qt.has(a)),g=(a,f)=>{let R=a[f];return!(R==null||R===""||R===!1)},p=(a,f,R=c)=>R.filter(P=>g(a,P)&&String(a[P])!==String(f[P]??"")),m=new Map,h=(a,f,R)=>[a,f,R??""].map(y).join("|");if(!T)for(let a of await W(e.target,Tt(t,c),I)){let f=w(a,"OpportunityId"),R=w(a,o);typeof a.Id!="string"||f===void 0||R===void 0||m.set(h(f,R,i?w(a,$):void 0),a)}for(let a of s){let f=w(a,o);if(f===void 0)continue;let R=_(a),P=b(a).target,L=R?P:e.mappedUser(f)??(K.has(y(f))?f:void 0),ot=!R&&L===void 0&&e.defaultUser!==void 0;if(ot&&(L=e.defaultUser),L===void 0){r.held.set(a,{field:o,parentObject:"User",why:R?`${o} names the owner of its opportunity, whose owner in the target could not be read.`:`${o} names a user the target has no counterpart of: a team member and a split go in for the opportunity's owner, which is the owner of its copy in the target, for a user an owner mapping gives, or for a user of the same id the target holds active.`});continue}let V={[o]:L},it=!1;if(i){let E=w(a,$);if(E!==void 0){let k=H.get(y(E)),z=k===void 0?void 0:F.get(k);if(z===void 0){r.held.set(a,{field:$,parentObject:tt,why:`${$} names ${k===void 0?"a split type":`the split type ${k}`}, which the target holds no active one of by that name: sent without it, the split would go in as one of the Revenue type.`});continue}V[$]=z.id,it=z.total}}let St=l(a),st=P!==void 0&&y(L)===y(P);if(T){if(st&&(!i||it)){let E=c.filter(k=>!pt(k)&&g(a,k));r.linked.set(a,{id:T.idFor(),owners:!0,notKept:p(a,Ut[t]??{},c.filter(pt)),...E.length>0?{unread:E}:{}});continue}}else{let E=m.get(h(St,L,V[$]));if(E!==void 0){r.linked.set(a,{id:String(E.Id),owners:st,notKept:p(a,E)});continue}}r.lookups.set(a,V),ot&&r.defaulted.add(a)}return r}var Bt={[Q]:"TaskId",[q]:"EventId"};async function Ln(t,n,e){let r=new Map,o=Bt[n];if(o===void 0)return r;let i=[...new Set(e.map(d=>d[o]).filter(d=>typeof d=="string"&&d!==""))];if(i.length===0)return r;let s=new Map;for(let d=0;d<i.length;d+=S){let u=i.slice(d,d+S).map(I=>`'${O(I)}'`).join(", "),l=await t(`SELECT Id, ${o}, RelationId FROM ${n} WHERE ${o} IN (${u})`);for(let I of l)typeof I.Id=="string"&&s.set(`${String(I[o])}|${String(I.RelationId)}`,I.Id)}return e.forEach((d,u)=>{let l=s.get(`${String(d[o])}|${String(d.RelationId)}`);l&&r.set(u,l)}),r}var jt={[q]:["IsInvitee"]},yt={IsInvitee:["Status","Response","RespondedDate"]},Rt="the run was cancelled before it was updated";async function Nn(t,n,e,r,o=()=>!1){return Qt(await Yt(t,n,e,r,o))}function Qt(t){if(!(t===void 0||t.size===0))return[...t].map(([n,e])=>`${e} linked without ${n}`).join(", ")}function xn(t,n){if(n.size===0)return t;let e=new Map(t??[]);for(let[r,o]of n)e.set(r,(e.get(r)??0)+o);return e}async function Yt(t,n,e,r,o=()=>!1){let i=jt[t]??[],s=new Set(i.flatMap(c=>[c,...yt[c]??[]]).filter(c=>!e(c))),d=new Map,u=(c,g)=>{let p=`${c}: ${g}`;d.set(p,(d.get(p)??0)+1)},l=[];for(let[c,g]of n){let p={},m={};for(let h of i.filter(a=>String(c[a])==="true")){if(s.has(h)){u(h,"the target does not let it be updated");continue}p[h]=!0;for(let a of yt[h]??[]){let f=c[a];f==null||f===""||(s.has(a)?u(a,"the target does not let it be updated"):m[a]=f)}}Object.keys(p).length>0&&l.push({Id:g,flagsGiven:p,answer:m})}let I=!1,T=async c=>{let g=new Map;if(c.length===0)return g;if(o()){for(let h of c)g.set(h.Id,Rt);return g}if(I)return g;let p=await r(c);I=p.length<c.length;let m=o();return c.forEach((h,a)=>{let f=p[a];f?.success||g.set(h.Id,f===void 0&&m?Rt:`the target refused the update, ${f?.errors[0]??"without saying why"}`)}),g},x=(c,g)=>{for(let p of c){let m=g.get(p.Id);if(m!==void 0)for(let h of Object.keys(p).filter(a=>a!=="Id"))u(h,m)}},b=l.map(({Id:c,flagsGiven:g,answer:p})=>({Id:c,...g,...p})),_=await T(b),A=I||o()?[]:l.filter(({Id:c,answer:g})=>_.has(c)&&Object.keys(g).length>0);x(b.filter(c=>!A.some(({Id:g})=>g===c.Id)),_);let K=A.map(({Id:c,flagsGiven:g})=>({Id:c,...g})),H=await T(K);x(K,H);let F=A.filter(({Id:c})=>!H.has(c));for(let c of new Set(F.flatMap(({answer:g})=>Object.keys(g)))){let g=F.filter(({answer:p})=>c in p).map(({Id:p,answer:m})=>({Id:p,[c]:m[c]}));x(g,await T(g))}return d}var bn={Order:"OrderStatus",Contract:"ContractStatus"},_n=new Set(["Contract"]);function Gt(t){return t==null||t===""?"null":typeof t=="number"||typeof t=="boolean"?String(t):`'${O(String(t))}'`}async function Fn(t,n){let e=new Map,r=[...new Set(n.map(i=>i.ContactId).filter(i=>typeof i=="string"&&i!==""))];if(r.length===0)return e;let o=new Map;for(let i=0;i<r.length;i+=j){let s=r.slice(i,i+j).map(u=>`'${O(u)}'`).join(", "),d=await t(`SELECT Id, AccountId, ContactId FROM ${It} WHERE IsDirect = true AND ContactId IN (${s})`);for(let u of d)typeof u.Id=="string"&&o.set(`${String(u.AccountId)}|${String(u.ContactId)}`,u.Id)}return n.forEach((i,s)=>{let d=o.get(`${String(i.AccountId)}|${String(i.ContactId)}`);d&&e.set(s,d)}),e}async function Wn(t,n){let e=new Set;for(let r=0;r<n.length;r+=j){let o=n.slice(r,r+j).map(s=>`'${O(s)}'`).join(", "),i=await t(`SELECT Id FROM PricebookEntry WHERE Id IN (${o}) AND Pricebook2.IsStandard = true`);for(let s of i)typeof s.Id=="string"&&e.add(s.Id)}return e}var wt=200;async function vn(t,n){let e=new Map,r=[...new Set(n.map(i=>i.Product2Id).filter(i=>typeof i=="string"&&i!==""))];if(r.length===0)return e;let o=new Map;for(let i=0;i<r.length;i+=wt){let s=r.slice(i,i+wt).map(u=>`'${O(u)}'`).join(", "),d=await t(`SELECT Id, Product2Id, ProductSellingModelId FROM ${at} WHERE Product2Id IN (${s})`);for(let u of d)typeof u.Id=="string"&&o.set(`${String(u.Product2Id)}|${String(u.ProductSellingModelId)}`,u.Id)}return n.forEach((i,s)=>{let d=o.get(`${String(i.Product2Id)}|${String(i.ProductSellingModelId)}`);d&&e.set(s,d)}),e}async function Dn(t,n,e,r){let o=new Map;for(let i of r){let s=JSON.stringify(e.map(l=>i[l]??null));if(o.has(s))continue;let d=e.map(l=>`${C(l)} = ${Gt(i[l])}`).join(" AND "),u=await t(`SELECT Id FROM ${C(n)} WHERE ${d} LIMIT 2`);o.set(s,u.length===1&&typeof u[0].Id=="string"?u[0].Id:void 0)}return r.map(i=>o.get(JSON.stringify(e.map(s=>i[s]??null))))}async function Un(t,n){let e;try{e=await t(`SELECT ApiName, StatusCode FROM ${C(n)}`)}catch{return}return{categoryOf:new Map(e.map(r=>[String(r.ApiName),String(r.StatusCode)])),draft:e.filter(r=>r.StatusCode==="Draft").map(r=>String(r.ApiName)).sort()[0]}}function qn(t,n){if(typeof t!="string"||t===""||!n.draft)return;let e=n.categoryOf.get(t);if(!(e===void 0||e==="Draft"))return n.draft}export{It as a,v as b,J as c,en as d,rn as e,ut as f,on as g,sn as h,an as i,dn as j,un as k,ht as l,cn as m,fn as n,ln as o,gn as p,N as q,B as r,Y as s,kt as t,pn as u,yn as v,Rn as w,Mt as x,wn as y,In as z,D as A,M as B,nt as C,hn as D,mn as E,Ot as F,G,ft as H,Nt as I,xt as J,On as K,_t as L,vt as M,Tn as N,Sn as O,En as P,$n as Q,Ut as R,Kt as S,Cn as T,Pn as U,kn as V,Mn as W,An as X,Bt as Y,Ln as Z,jt as _,Nn as $,Qt as aa,xn as ba,Yt as ca,bn as da,_n as ea,Fn as fa,Wn as ga,vn as ha,Dn as ia,Un as ja,qn as ka};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
7
+ import{a,b,c,d,e,f,g,h,i,j}from"./chunk-SI267LYR.mjs";import"./chunk-KAZS5Z6W.mjs";import"./chunk-BBRWFKS5.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-EPFCERGL.mjs";import"./chunk-IUM4NFKI.mjs";import"./chunk-PMN4PAC3.mjs";import"./chunk-QSRAEUGZ.mjs";import"./chunk-TUACWKIH.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as SCENARIO_SIDECAR_SUFFIX,f as compiledForSidecar,g as nodeScenarioSidecarFiles,j as readScenarioRunSidecar,c as scenarioPackFingerprint,d as scenarioRunSidecar,b as scenarioRunSidecarSchema,h as scenarioSidecarPath,e as withAgentChoice,i as writeScenarioRunSidecar};
@@ -0,0 +1,8 @@
1
+ import { createRequire as __sandforgeRequire } from 'node:module';
2
+ import { fileURLToPath as __sandforgePath } from 'node:url';
3
+ import { dirname as __sandforgeDirname } from 'node:path';
4
+ const require = __sandforgeRequire(import.meta.url);
5
+ const __filename = __sandforgePath(import.meta.url);
6
+ const __dirname = __sandforgeDirname(__filename);
7
+ import{closeSync as J,fstatSync as W,openSync as $,readSync as G,writeSync as K}from"node:fs";function dt(a){let e=$(a,"a+"),t=W(e).size;return{size:()=>t,append:n=>{let i=Buffer.from(n,"utf8"),r=0;for(;r<i.length;)r+=K(e,i,r);t+=i.length},read:(n,i)=>{let r=Buffer.alloc(i),s=0;for(;s<i;){let o=G(e,r,s,i-s,n+s);if(o===0)break;s+=o}return r.subarray(0,s)},close:()=>J(e)}}function E(a,e){return e===void 0?a:`${a}/${e}`}var M=/^[A-Za-z][A-Za-z0-9]*$/,I=/^[0-9a-f]{64}$/,H=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/;function P(a){if(typeof a!="object"||a===null)return;let{objectApiName:e,ids:t,sha256:n,readAt:i,query:r}=a;if(typeof e!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,79}$/.test(e)||!Array.isArray(t)||!t.every(o=>typeof o=="string"&&H.test(o))||typeof n!="string"||!I.test(n)||typeof i!="string"||!Number.isFinite(Date.parse(i)))return;let s;if(typeof r=="object"&&r!==null){let{where:o,orderBy:c,limit:u}=r;s={...typeof o=="string"?{where:o}:{},...typeof c=="string"?{orderBy:c}:{},...typeof u=="number"&&Number.isInteger(u)?{limit:u}:{}}}return{objectApiName:e,ids:t,sha256:n,readAt:i,...s?{query:s}:{}}}var b=1,x=2,N=3,y=4,Y={created:b,existing:x,updated:N},_={[b]:"created",[x]:"existing",[N]:"updated"},U={[b]:"c",[x]:"e",[N]:"u",[y]:"i"},R={c:b,e:x,u:N,i:y},Z="x",q="a",V="j",D="d",T="n",v="t",F="found",Q="found-owed";function ct(a,e,t,n){return JSON.stringify([D,a,e,t,n])}function ft(a){if(!a.startsWith(`["${D}"`))return;let e;try{e=JSON.parse(a)}catch{return}if(!Array.isArray(e))return;let[,,,t,n]=e;if(!(typeof t!="string"||!Number.isFinite(Date.parse(t)))&&!(typeof n!="string"||!Number.isFinite(Date.parse(n))))return{orgAt:t,at:n}}function X(a,e=!1){return JSON.stringify([e?"w":"o",a.objectApiName,a.newId,a.sourceId??"",a.fieldName,a.sourceRefId,a.insertOnly?1:0])}var tt=1024*1024,et=1024*1024,nt=2e4,it=2e4,rt=.6,st=3;function p(a){let e=2166136261;for(let t=0;t<a.length;t++)e^=a.charCodeAt(t),e=Math.imul(e,16777619);return e>>>0}function m(a){let e=2538058380;for(let t=0;t<a.length;t++)e=Math.imul(e^a.charCodeAt(t),1540483477),e^=e>>>15;return e>>>0}var A=class{constructor(e){this.keyAt=e}keyAt;capacity=1024;used=0;h1=new Uint32Array(this.capacity);h2=new Uint32Array(this.capacity);at=new Float64Array(this.capacity);len=new Uint16Array(this.capacity);code=new Uint8Array(this.capacity);get size(){return this.used}get slots(){return this.capacity}find(e,t,n,i){let r=this.capacity-1,s=n&r;for(;;){let o=this.at[s];if(o===0)return~s;if(this.h1[s]===t&&this.h2[s]===n&&(i===o-1||this.keyAt(o-1,this.len[s])===e))return s;s=s+1&r}}offsetOf(e){return this.at[e]-1}lengthOf(e){return this.len[e]}codeOf(e){return this.code[e]}put(e,t,n,i,r,s){let o=e;e<0&&(this.used+1>this.capacity*rt?(this.grow(),o=this.freeSlotFor(n)):o=~e,this.used++,this.h1[o]=t,this.h2[o]=n),this.at[o]=i+1,this.len[o]=r,this.code[o]=s}freeSlotFor(e){let t=this.capacity-1,n=e&t;for(;this.at[n]!==0;)n=n+1&t;return n}grow(){let{h1:e,h2:t,at:n,len:i,code:r}=this;this.capacity*=2,this.h1=new Uint32Array(this.capacity),this.h2=new Uint32Array(this.capacity),this.at=new Float64Array(this.capacity),this.len=new Uint16Array(this.capacity),this.code=new Uint8Array(this.capacity);for(let s=0;s<n.length;s++){if(n[s]===0)continue;let o=this.freeSlotFor(t[s]);this.h1[o]=e[s],this.h2[o]=t[s],this.at[o]=n[s],this.len[o]=i[s],this.code[o]=r[s]}}};function L(a){return a?a[0]==="p"&&a.length>=3?C(String(a[1]),String(a[2])):a[0]==="g"&&a.length>=3?j(String(a[2])):a[0]===v&&a.length>=2?B(String(a[1])):"":""}function B(a){return`t\0${a}`}function C(a,e){return`p\0${a}\0${e}`}function j(a){return`g\0${a}`}function*ot(a){let e=a.size(),t=0,n=Buffer.alloc(0),i=0;for(;t<e;){let r=a.read(t,Math.min(et,e-t));if(r.length===0)break;t+=r.length;let s=n.length>0?Buffer.concat([n,r]):r,o=0;for(;;){let c=s.indexOf(10,o);if(c<0)break;c>o&&(yield{offset:i+o,length:c-o,text:s.toString("utf8",o,c)}),o=c+1}n=s.subarray(o),i+=o}}var z=class a{constructor(e){this.file=e;this.index=new A((t,n)=>this.idOfLine(t,n)),this.marks=new A((t,n)=>L(S(this.lineAt(t,n)))),this.createdTargets=new A((t,n)=>{let i=S(this.lineAt(t,n));return i?O(String(i[2]??"")):""})}file;index;cache=new Map;pending=[];pendingBytes=0;flushQueued=!1;partStart=Number.POSITIVE_INFINITY;parts=0;mappedCount=0;counts=new Map;earlierByObject=new Map;earlierPastCheckpoint=new Map;checkpointsByObject=new Map;owedCount=0;statuses=new Map;given=new Map;marks;createdTargets;createdUnattributedKeys=new Set;readsHeld=[];withTheirRecordMarked=0;callsSent=0;foundAfterStop=new Set;foundOwingUntold=new Set;plan;rootsNamed;static open(e){let t=new a(e);return t.readWhatIsThere(),t}get partCount(){return this.parts}get resumes(){return this.checkpointsByObject.size>0||this.earlierByObject.size>0||this.owedCount>0}get earlierMapped(){return this.partStart===Number.POSITIVE_INFINITY?this.mappedCount:this.mappedBeforePart}mappedBeforePart=0;beginPart(e){this.flush(),this.mappedBeforePart=this.mappedCount,this.withTheirRecordMarked=0,this.partStart=this.file.size(),this.write({part:{n:this.parts,startedAt:e.toISOString()}}),this.parts++,this.flush()}nameSamplePlan(e){if(!I.test(e.sha256))throw new Error("Not the SHA-256 of a plan.");this.write({sample:{dir:e.dir,sha256:e.sha256}}),this.plan={dir:e.dir,sha256:e.sha256},this.flush()}get samplePlan(){return this.plan?{...this.plan}:void 0}nameRoots(e){let t=P(e);if(!t)throw new Error("Not the roots of a clone from records.");this.write({roots:t}),this.rootsNamed=t,this.flush()}get roots(){return this.rootsNamed?{...this.rootsNamed,ids:[...this.rootsNamed.ids]}:void 0}setMapping(e,t,n,i){let r=Y[e],s=p(t),o=m(t),c=this.cache.get(t),u=this.index.find(t,s,o,c?.at),h=u>=0&&this.index.codeOf(u)!==y;h&&this.uncount(t,u,c);let g=JSON.stringify([U[r],t,n,i??""]),f=this.write(g);if(this.index.put(u,s,o,f,Buffer.byteLength(g),r),r===b&&this.indexCreated(n,f,Buffer.byteLength(g)),h||this.mappedCount++,i){let d=this.countsOf(i);r===b?d.created++:r===x?d.linked++:d.updated++}this.remember(t,{at:f,code:r,targetId:n,objectApiName:i??""})}uncount(e,t,n){let i=this.index.offsetOf(t);if(i<this.partStart)return;let r=this.index.codeOf(t),s=n?.at===i?n:this.recordAt(e,t),o=s?.objectApiName?this.counts.get(s.objectApiName):void 0;o&&(r===b?o.created--:r===x?o.linked--:o.updated--)}countsOf(e){let t=this.counts.get(e);return t||(t={created:0,linked:0,updated:0},this.counts.set(e,t)),t}mapping(e){let t=this.lookUp(e);if(!(!t||t.code===y))return{kind:_[t.code],sourceId:e,targetId:t.targetId,...t.objectApiName?{objectApiName:t.objectApiName}:{},earlier:t.at<this.partStart}}createdTarget(e){let t=O(e);if(this.createdUnattributedKeys.has(t))return!0;if(this.createdTargets.size===0)return!1;let n=this.createdTargets.find(t,p(t),m(t));if(n<0)return!1;let i=this.createdTargets.offsetOf(n),r=S(this.lineAt(i,this.createdTargets.lengthOf(n)));if(!r)return!1;let s=String(r[1]),o=this.index.find(s,p(s),m(s));return o>=0&&this.index.offsetOf(o)===i&&this.index.codeOf(o)===b}indexCreated(e,t,n){let i=O(e);if(!i)return;let r=p(i),s=m(i);this.createdTargets.put(this.createdTargets.find(i,r,s),r,s,t,n,b)}targetOf(e){let t=this.lookUp(e);return t&&t.code!==y?t.targetId:void 0}get mappedSize(){return this.mappedCount}countsByObject(){let e=[];for(let[t,{created:n,linked:i,updated:r}]of this.counts)n+i+r!==0&&e.push(r>0?{objectApiName:t,created:n,linked:i,updated:r}:{objectApiName:t,created:n,linked:i});return e}linkedToCreatedCount(){let e=0;for(let f of this.counts.values())e+=f.linked;if(e===0)return 0;let t=this.partStart===Number.POSITIVE_INFINITY?0:this.partStart,n=(f,d)=>{let l=S(this.lineAt(f,d));return l?String(l[2]).slice(0,15):""},i=(f,d)=>{let l=R[String(d[0])];if(l===void 0||l===y||!d[3])return;let w=String(d[1]),k=this.index.find(w,p(w),m(w),f.offset);return k>=0&&this.index.offsetOf(k)===f.offset?l:void 0},r=(f,d)=>f.offset<t?void 0:i(f,d),s=(f,d,l)=>{let w=p(d),k=m(d);f.put(f.find(d,w,k),w,k,l.offset,l.length,0)},o=(f,d)=>f.size>0&&f.find(d,p(d),m(d))>=0,c=new A(n);for(let f of this.lines()){if(!f.text.startsWith('["'))continue;let d=S(f.text);!d||r(f,d)!==x||this.markedWithTheirRecord(String(d[1]))||s(c,String(d[2]).slice(0,15),f)}if(c.size===0)return 0;let u=new A(n),h=new Set;for(let f of this.lines()){if(!f.text.startsWith('["'))continue;let d=S(f.text);if(!d)continue;if(d[0]===T&&Array.isArray(d[2])){for(let w of d[2]){let k=String(w).slice(0,15);o(c,k)&&h.add(k)}continue}if(i(f,d)!==b)continue;let l=String(d[2]).slice(0,15);o(c,l)&&s(u,l,f)}if(u.size===0&&h.size===0)return 0;let g=0;for(let f of this.lines()){if(!f.text.startsWith('["'))continue;let d=S(f.text);if(!d||r(f,d)!==x||this.markedWithTheirRecord(String(d[1])))continue;let l=String(d[2]).slice(0,15);(o(u,l)||h.has(l))&&g++}return g}earlierRecordsOf(e,t=!1){return(t?this.earlierPastCheckpoint:this.earlierByObject).get(e)??0}*mappings(){for(let e of this.lines()){if(!e.text.startsWith('["'))continue;let t=S(e.text);if(!t)continue;let n=R[String(t[0])];if(n===void 0||n===y)continue;let i=String(t[1]),r=this.index.find(i,p(i),m(i),e.offset);if(r<0||this.index.offsetOf(r)!==e.offset)continue;let s=String(t[3]??"");yield{kind:_[n],sourceId:i,targetId:String(t[2]),...s?{objectApiName:s}:{},earlier:e.offset<this.partStart}}}noteRead(e){this.readsHeld.push(e),this.readsHeld.length>=it&&this.settleReads()}settleReads(){let e=this.readsHeld;this.readsHeld=[];for(let t of e){let n=p(t),i=m(t),r=this.index.find(t,n,i,this.cache.get(t)?.at);if(r>=0)continue;let s=JSON.stringify([U[y],t]),o=this.write(s);this.index.put(r,n,i,o,Buffer.byteLength(s),y)}}wasRead(e){return this.readsHeld.includes(e)?!0:this.index.find(e,p(e),m(e),this.cache.get(e)?.at)>=0}checkpoint(e,t,n){if(n!==void 0&&!M.test(n))throw new Error(`Not the name of a pass: ${JSON.stringify(n.slice(0,40))}`);this.settleReads(),this.write({at:{object:e,...n!==void 0?{pass:n}:{},...t}}),this.checkpointsByObject.set(E(e,n),{...t}),this.flush()}checkpoints(){return new Map(this.checkpointsByObject)}owe(e,t=!1){this.owedCount++,this.write(X(e,t))}get owed(){return this.owedCount}*owedPages(e){let t=[];for(let n of this.lines()){if(!n.text.startsWith('["o"')&&!n.text.startsWith('["w"'))continue;let i=S(n.text);if(!i||i.length<7)continue;let[r,s,o,c,u,h,g]=i;t.push({update:{objectApiName:String(s),newId:String(o),sourceId:c?String(c):void 0,fieldName:String(u),sourceRefId:String(h),...g===1?{insertOnly:!0}:{}},toRowWrittenBefore:r==="w"}),t.length>=e&&(yield t,t=[])}t.length>0&&(yield t)}patched(e,t){this.mark(JSON.stringify(["p",e,t]),C(e,t))}wasPatched(e,t){return this.hasMark(C(e,t))}mark(e,t){let n=p(t),i=m(t),r=this.marks.find(t,n,i),s=this.write(e);this.marks.put(r,n,i,s,Buffer.byteLength(e),0)}hasMark(e){return this.marks.size>0&&this.marks.find(e,p(e),m(e))>=0}owedLeftByEarlierParts(){let e=new Set;for(let n of this.lines()){if(n.offset>=this.partStart)break;if(!n.text.startsWith('["p"'))continue;let i=S(n.text);i&&i.length>=3&&e.add(`${String(i[1])}\0${String(i[2])}`)}let t=[];for(let n of this.lines()){if(n.offset>=this.partStart)break;if(!n.text.startsWith('["o"'))continue;let i=S(n.text);if(!i||i.length<7)continue;let[,r,s,o,c,u,h]=i;e.has(`${String(s)}\0${String(c)}`)||t.push({objectApiName:String(r),newId:String(s),sourceId:o?String(o):void 0,fieldName:String(c),sourceRefId:String(u),...h===1?{insertOnly:!0}:{}})}return t}oweStatus(e,t,n){this.write(JSON.stringify(["s",e,t,n])),this.tallyStatus({objectApiName:e,id:t,status:n})}tallyStatus(e){let t=this.statuses.get(e.objectApiName);t||(t={count:0,samples:[]},this.statuses.set(e.objectApiName,t)),t.count++,t.samples.length<st&&t.samples.push(e)}gaveStatus(e,t){this.statusGiven(t)||(this.mark(JSON.stringify(["g",e,t]),j(t)),this.given.set(e,(this.given.get(e)??0)+1))}statusGiven(e){return this.hasMark(j(e))}statusesOwed(){let e=new Map;for(let[t,n]of this.statuses){let i=n.count-(this.given.get(t)??0);i<=0||e.set(t,{count:i,samples:n.samples.filter(({id:r})=>!this.statusGiven(r))})}return e}*statusLines(){for(let e of this.lines()){if(!e.text.startsWith('["s"'))continue;let t=S(e.text);!t||t.length<4||(yield{objectApiName:String(t[1]),id:String(t[2]),status:String(t[3])})}}withTheirRecord(e){let t=B(e),n=p(t),i=m(t),r=this.marks.find(t,n,i),s=this.partStart===Number.POSITIVE_INFINITY?0:this.partStart;if(r>=0&&this.marks.offsetOf(r)>=s)return;let o=JSON.stringify([v,e]),c=this.write(o);this.marks.put(r,n,i,c,Buffer.byteLength(o),0),this.withTheirRecordMarked++}get withTheirRecordCount(){return this.withTheirRecordMarked}markedWithTheirRecord(e){if(this.withTheirRecordMarked===0)return!1;let t=B(e),n=this.marks.find(t,p(t),m(t)),i=this.partStart===Number.POSITIVE_INFINITY?0:this.partStart;return n>=0&&this.marks.offsetOf(n)>=i}*withTheirRecordIds(){if(this.withTheirRecordMarked!==0)for(let e of this.lines()){if(e.offset<this.partStart||!e.text.startsWith(`["${v}"`))continue;let t=S(e.text);t&&t.length>=2&&(yield String(t[1]))}}sent(e,t,n,i=new Date,r){this.callsSent++;let s=`${Math.max(0,this.parts-1)}.${this.callsSent}`;return this.write(JSON.stringify([Z,s,e,i.toISOString(),t,n.map(({sourceId:o,fingerprint:c,externalKey:u,jobKey:h})=>r!==void 0&&u!==void 0?[o,c,u]:h!==void 0?[o,c,"",h]:[o,c]),n.flatMap(({owes:o},c)=>(o??[]).map(({field:u,sourceRefId:h,insertOnly:g})=>[c,u,h,g?1:0])),...r!==void 0?[r]:[]])),this.flush(),s}answered(e){this.write(JSON.stringify([q,e]))}jobOpened(e,t){this.write(JSON.stringify([V,e,t])),this.flush()}createdUnattributed(e,t){if(t.length!==0){this.write(JSON.stringify([T,e,[...t]]));for(let n of t)this.createdUnattributedKeys.add(O(n))}}wasFoundAfterStop(e){return this.foundAfterStop.has(e)}owesUntold(e){return this.foundOwingUntold.has(e)}flush(){if(this.pending.length===0)return;let e=this.pending.join("");this.pending=[],this.pendingBytes=0,this.file.append(e)}close(){this.settleReads(),this.flush(),this.file.close()}write(e){let t=typeof e=="string"?e:JSON.stringify(e),n=this.file.size()+this.pendingBytes,i=`${t}
8
+ `;return this.pending.push(i),this.pendingBytes+=Buffer.byteLength(i),this.pendingBytes>=tt?this.flush():this.flushQueued||(this.flushQueued=!0,queueMicrotask(()=>{this.flushQueued=!1,this.flush()})),n}lineAt(e,t){return e+t>this.file.size()&&this.flush(),this.file.read(e,t).toString("utf8")}idOfLine(e,t){let n=S(this.lineAt(e,t));return n?String(n[1]):""}lookUp(e){let t=this.cache.get(e);if(t)return this.cache.delete(e),this.cache.set(e,t),t;let n=this.index.find(e,p(e),m(e));if(n<0)return;let i=this.recordAt(e,n);return i&&this.remember(e,i),i}recordAt(e,t){let n=this.index.offsetOf(t),i=S(this.lineAt(n,this.index.lengthOf(t)));if(!(!i||String(i[1])!==e))return{at:n,code:this.index.codeOf(t),targetId:String(i[2]??""),objectApiName:String(i[3]??"")}}remember(e,t){if(this.cache.delete(e),this.cache.set(e,t),this.cache.size>nt){let n=this.cache.keys().next().value;n!==void 0&&this.cache.delete(n)}}*lines(){this.flush(),yield*ot(this.file)}readWhatIsThere(){for(let e of this.lines()){if(e.text.startsWith('["')){let n=S(e.text);n&&this.readRegistration(e,n);continue}let t;try{t=JSON.parse(e.text)}catch{continue}if(!(typeof t!="object"||t===null)){if("part"in t)this.parts++;else if("sample"in t){let n=t.sample;if(typeof n!="object"||n===null)continue;let{dir:i,sha256:r}=n;if(typeof i!="string"||i===""||typeof r!="string"||!I.test(r))continue;this.plan={dir:i,sha256:r}}else if("roots"in t){let n=P(t.roots);n&&(this.rootsNamed=n)}else if("at"in t){let n=t.at;if(typeof n!="object"||n===null)continue;let{object:i,pass:r,lastId:s,read:o,done:c}=n;if(typeof i!="string"||typeof s!="string"||typeof o!="number"||r!==void 0&&(typeof r!="string"||!M.test(r)))continue;this.checkpointsByObject.set(E(i,r),{lastId:s,read:o,...c===!0?{done:c}:{}}),r===void 0&&this.earlierPastCheckpoint.delete(i)}}}}readRegistration(e,t){let n=String(t[0]);if(n==="o"||n==="w"){this.owedCount++;return}if(n==="s"){t.length>=4&&this.tallyStatus({objectApiName:String(t[1]),id:String(t[2]),status:String(t[3])});return}if(n==="p"||n==="g"||n===v){let g=L(t);if(!g)return;let f=p(g),d=m(g),l=this.marks.find(g,f,d);if(n==="g"&&l<0){let w=String(t[1]);this.given.set(w,(this.given.get(w)??0)+1)}this.marks.put(l,f,d,e.offset,e.length,0);return}if(n===T){if(Array.isArray(t[2]))for(let g of t[2])this.createdUnattributedKeys.add(O(String(g)));return}let i=R[n];if(i===void 0)return;let r=String(t[1]);i===b&&(t[4]===F||t[4]===Q)&&(this.foundAfterStop.add(r),t[4]===F&&this.foundOwingUntold.add(r));let s=p(r),o=m(r),c=this.index.find(r,s,o),u=c>=0&&this.index.codeOf(c)!==y;if(i===y&&c>=0||(this.index.put(c,s,o,e.offset,e.length,i),i===y))return;i===b&&this.indexCreated(String(t[2]??""),e.offset,e.length),u||this.mappedCount++;let h=String(t[3]??"");h&&(this.earlierByObject.set(h,(this.earlierByObject.get(h)??0)+1),this.earlierPastCheckpoint.set(h,(this.earlierPastCheckpoint.get(h)??0)+1))}};function O(a){return a.slice(0,15)}function S(a){try{let e=JSON.parse(a);return Array.isArray(e)?e:void 0}catch{return}}export{dt as a,E as b,P as c,Z as d,q as e,V as f,D as g,T as h,v as i,F as j,Q as k,ct as l,ft as m,X as n,p as o,m as p,A as q,ot as r,z as s};