sandforge 0.0.0-stage → 1.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -2
  3. package/THIRD-PARTY-NOTICES.md +1624 -0
  4. package/bin/sandforge-autopilot.mjs +12 -0
  5. package/bin/sandforge-backup.mjs +12 -0
  6. package/bin/sandforge-checkpoint.mjs +12 -0
  7. package/bin/sandforge-cleanup.mjs +12 -0
  8. package/bin/sandforge-clone.mjs +12 -0
  9. package/bin/sandforge-compare.mjs +12 -0
  10. package/bin/sandforge-dataops.mjs +12 -0
  11. package/bin/sandforge-empty.mjs +12 -0
  12. package/bin/sandforge-env.mjs +12 -0
  13. package/bin/sandforge-frozen.mjs +12 -0
  14. package/bin/sandforge-mcp.mjs +12 -0
  15. package/bin/sandforge-monitor.mjs +12 -0
  16. package/bin/sandforge-seed.mjs +12 -0
  17. package/bin/sandforge-sync.mjs +12 -0
  18. package/bin/sandforge.mjs +12 -0
  19. package/lib/catalogue.en.json +1 -0
  20. package/lib/chunk-2BVTCNWA.mjs +7 -0
  21. package/lib/chunk-2S5OMIIA.mjs +7 -0
  22. package/lib/chunk-2YIV2OB2.mjs +7 -0
  23. package/lib/chunk-342FN7AO.mjs +9 -0
  24. package/lib/chunk-36U7IQ6Y.mjs +25 -0
  25. package/lib/chunk-3CA767QB.mjs +7 -0
  26. package/lib/chunk-3DCUADVK.mjs +7 -0
  27. package/lib/chunk-3F5YMM2F.mjs +7 -0
  28. package/lib/chunk-3OHPD72J.mjs +9 -0
  29. package/lib/chunk-3RYLICRX.mjs +7 -0
  30. package/lib/chunk-3SRXFZSD.mjs +7 -0
  31. package/lib/chunk-42RER7V4.mjs +14 -0
  32. package/lib/chunk-4GL773D5.mjs +7 -0
  33. package/lib/chunk-4HFRHFGQ.mjs +7 -0
  34. package/lib/chunk-4HW535YJ.mjs +7 -0
  35. package/lib/chunk-4NAHW2D3.mjs +7 -0
  36. package/lib/chunk-4SNDMJP2.mjs +7 -0
  37. package/lib/chunk-4TLYUZD5.mjs +7 -0
  38. package/lib/chunk-4U6NXJNL.mjs +7 -0
  39. package/lib/chunk-4XZ5YT5O.mjs +7 -0
  40. package/lib/chunk-55HEMHEG.mjs +7 -0
  41. package/lib/chunk-57VHUYNG.mjs +10 -0
  42. package/lib/chunk-5AJRHRXA.mjs +20 -0
  43. package/lib/chunk-5CD257T7.mjs +7 -0
  44. package/lib/chunk-5HMAPZBV.mjs +7 -0
  45. package/lib/chunk-5LFSFYFJ.mjs +7 -0
  46. package/lib/chunk-5MMXFWPD.mjs +7 -0
  47. package/lib/chunk-5O6JOMHS.mjs +13 -0
  48. package/lib/chunk-5P4PHJRL.mjs +9 -0
  49. package/lib/chunk-5QKTYCWE.mjs +11 -0
  50. package/lib/chunk-66NMFCWX.mjs +7 -0
  51. package/lib/chunk-6EBMEGZB.mjs +7 -0
  52. package/lib/chunk-6LAXTAVN.mjs +7 -0
  53. package/lib/chunk-6MUEPV7M.mjs +9 -0
  54. package/lib/chunk-6QSM2WIH.mjs +10 -0
  55. package/lib/chunk-75ADZS6B.mjs +7 -0
  56. package/lib/chunk-7EANH5PY.mjs +68 -0
  57. package/lib/chunk-7F54PZUS.mjs +7 -0
  58. package/lib/chunk-7UQD6V6F.mjs +7 -0
  59. package/lib/chunk-AAVJ5XVX.mjs +7 -0
  60. package/lib/chunk-ALJVEUUS.mjs +7 -0
  61. package/lib/chunk-ALUFROGA.mjs +7 -0
  62. package/lib/chunk-AR7BE5O2.mjs +7 -0
  63. package/lib/chunk-AUTM6H6Z.mjs +7 -0
  64. package/lib/chunk-AV5SWEHP.mjs +9 -0
  65. package/lib/chunk-B45CNPUX.mjs +47 -0
  66. package/lib/chunk-BILZ3SSR.mjs +7 -0
  67. package/lib/chunk-BN7A4GRQ.mjs +7 -0
  68. package/lib/chunk-BOGNK4LV.mjs +7 -0
  69. package/lib/chunk-BS5T3MOQ.mjs +7 -0
  70. package/lib/chunk-BZ24IAP5.mjs +7 -0
  71. package/lib/chunk-CA5NAXSU.mjs +7 -0
  72. package/lib/chunk-CE6ZDGBB.mjs +7 -0
  73. package/lib/chunk-CGWXQX75.mjs +7 -0
  74. package/lib/chunk-CHCHAE4B.mjs +7 -0
  75. package/lib/chunk-D3QRXG63.mjs +787 -0
  76. package/lib/chunk-DBFJB2B6.mjs +7 -0
  77. package/lib/chunk-DLDX6RRC.mjs +7 -0
  78. package/lib/chunk-EADHKH3A.mjs +7 -0
  79. package/lib/chunk-EEVVGGM6.mjs +7 -0
  80. package/lib/chunk-ENLBYECD.mjs +7 -0
  81. package/lib/chunk-EQF2IJS2.mjs +11 -0
  82. package/lib/chunk-EQOQASDQ.mjs +7 -0
  83. package/lib/chunk-F2424IKX.mjs +7 -0
  84. package/lib/chunk-F74IHMGL.mjs +7 -0
  85. package/lib/chunk-FOVVHGEP.mjs +7 -0
  86. package/lib/chunk-FQBRBBY4.mjs +7 -0
  87. package/lib/chunk-FQGHL7GR.mjs +259 -0
  88. package/lib/chunk-GAM726CK.mjs +7 -0
  89. package/lib/chunk-GCOB7K5N.mjs +7 -0
  90. package/lib/chunk-GMY5427L.mjs +7 -0
  91. package/lib/chunk-GNC27UEU.mjs +7 -0
  92. package/lib/chunk-H2PJNIYJ.mjs +7 -0
  93. package/lib/chunk-H45UXY6G.mjs +7 -0
  94. package/lib/chunk-HCIDVIOW.mjs +7 -0
  95. package/lib/chunk-HF6LAK3G.mjs +7 -0
  96. package/lib/chunk-HJC7AIBK.mjs +7 -0
  97. package/lib/chunk-HJKM3E56.mjs +7 -0
  98. package/lib/chunk-HTJ5OGP5.mjs +7 -0
  99. package/lib/chunk-HUMEKZT5.mjs +8 -0
  100. package/lib/chunk-HV2MXMGI.mjs +7 -0
  101. package/lib/chunk-HXS7ORUF.mjs +11 -0
  102. package/lib/chunk-I3JKJTLO.mjs +110 -0
  103. package/lib/chunk-I7O6C2B5.mjs +8 -0
  104. package/lib/chunk-IAZB4WIL.mjs +7 -0
  105. package/lib/chunk-IC2C2GOF.mjs +8 -0
  106. package/lib/chunk-IEYG5ATY.mjs +7 -0
  107. package/lib/chunk-INIQ23K6.mjs +7 -0
  108. package/lib/chunk-INIT2UKJ.mjs +7 -0
  109. package/lib/chunk-J7HVXMSW.mjs +7 -0
  110. package/lib/chunk-JVL444U5.mjs +7 -0
  111. package/lib/chunk-K22PA4XL.mjs +7 -0
  112. package/lib/chunk-K2FBZIXY.mjs +7 -0
  113. package/lib/chunk-KLX67VPL.mjs +7 -0
  114. package/lib/chunk-L776PUMV.mjs +7 -0
  115. package/lib/chunk-LQ4DRFUH.mjs +9 -0
  116. package/lib/chunk-LRFAIUN7.mjs +7 -0
  117. package/lib/chunk-LV6G4XTK.mjs +7 -0
  118. package/lib/chunk-M6P5ZZLE.mjs +7 -0
  119. package/lib/chunk-MTMH6H2A.mjs +8 -0
  120. package/lib/chunk-MYTIL2JD.mjs +10 -0
  121. package/lib/chunk-NEVXIGR6.mjs +10 -0
  122. package/lib/chunk-NGSMZZDA.mjs +7 -0
  123. package/lib/chunk-NHWE66K5.mjs +7 -0
  124. package/lib/chunk-NM4MDLK4.mjs +7 -0
  125. package/lib/chunk-NTDN2JQZ.mjs +19 -0
  126. package/lib/chunk-NTOVCTRS.mjs +7 -0
  127. package/lib/chunk-NZ5ZZLKS.mjs +7 -0
  128. package/lib/chunk-OQOZAPCI.mjs +7 -0
  129. package/lib/chunk-OTWRDD6L.mjs +7 -0
  130. package/lib/chunk-P2PJYWGQ.mjs +7 -0
  131. package/lib/chunk-P42X3B4D.mjs +7 -0
  132. package/lib/chunk-P7GSGFJO.mjs +7 -0
  133. package/lib/chunk-PA3MKJVH.mjs +7 -0
  134. package/lib/chunk-PBI4BYWW.mjs +7 -0
  135. package/lib/chunk-PNCONNFJ.mjs +10 -0
  136. package/lib/chunk-PTTHSSQO.mjs +7 -0
  137. package/lib/chunk-PUOX4NBJ.mjs +8 -0
  138. package/lib/chunk-PZTSVQSF.mjs +7 -0
  139. package/lib/chunk-QPF6C5MX.mjs +7 -0
  140. package/lib/chunk-QQZZMKU3.mjs +7 -0
  141. package/lib/chunk-QROPNEGY.mjs +14 -0
  142. package/lib/chunk-QRV2OSIS.mjs +7 -0
  143. package/lib/chunk-QSRAEUGZ.mjs +7 -0
  144. package/lib/chunk-QWT2C74M.mjs +7 -0
  145. package/lib/chunk-RAAANPPG.mjs +7 -0
  146. package/lib/chunk-RACDTRZA.mjs +7 -0
  147. package/lib/chunk-RFEO2KAN.mjs +7 -0
  148. package/lib/chunk-RH3N2H7P.mjs +7 -0
  149. package/lib/chunk-RSWDYIHY.mjs +37 -0
  150. package/lib/chunk-RSYICMZG.mjs +8 -0
  151. package/lib/chunk-SAR5622P.mjs +7 -0
  152. package/lib/chunk-SBIMVCXT.mjs +101 -0
  153. package/lib/chunk-SCKUIE3R.mjs +7 -0
  154. package/lib/chunk-SFURUNJM.mjs +7 -0
  155. package/lib/chunk-SIOZXPFG.mjs +7 -0
  156. package/lib/chunk-SRPWW4A2.mjs +10 -0
  157. package/lib/chunk-SRQDABQ2.mjs +15 -0
  158. package/lib/chunk-SVS6UMDU.mjs +323 -0
  159. package/lib/chunk-T63U4OZJ.mjs +7 -0
  160. package/lib/chunk-TBZMC2VV.mjs +11 -0
  161. package/lib/chunk-TEOLMRDO.mjs +7 -0
  162. package/lib/chunk-TLH7AD35.mjs +7 -0
  163. package/lib/chunk-TNXUU6W7.mjs +14 -0
  164. package/lib/chunk-TQX3PURV.mjs +7 -0
  165. package/lib/chunk-TUACWKIH.mjs +7 -0
  166. package/lib/chunk-TW3N6W5Z.mjs +7 -0
  167. package/lib/chunk-TYYOBZMU.mjs +10 -0
  168. package/lib/chunk-TZE3Y7IQ.mjs +7 -0
  169. package/lib/chunk-UNDIBZWG.mjs +7 -0
  170. package/lib/chunk-VGW4MXXZ.mjs +7 -0
  171. package/lib/chunk-VHI54FBK.mjs +441 -0
  172. package/lib/chunk-VXHDBYMI.mjs +7 -0
  173. package/lib/chunk-W7KFAY55.mjs +7 -0
  174. package/lib/chunk-WFEB5X4U.mjs +8 -0
  175. package/lib/chunk-WIO4XO4F.mjs +7 -0
  176. package/lib/chunk-WJY54JO7.mjs +13 -0
  177. package/lib/chunk-WR2GIKWE.mjs +7 -0
  178. package/lib/chunk-WRU5FJFC.mjs +7 -0
  179. package/lib/chunk-X2PY6MWZ.mjs +7 -0
  180. package/lib/chunk-X65MT4W3.mjs +7 -0
  181. package/lib/chunk-XBG5SP6Q.mjs +7 -0
  182. package/lib/chunk-XCA5AONB.mjs +7 -0
  183. package/lib/chunk-XEFDB2R4.mjs +7 -0
  184. package/lib/chunk-XETCPL7E.mjs +7 -0
  185. package/lib/chunk-Y5CGXLUB.mjs +7 -0
  186. package/lib/chunk-Y6J6QFI2.mjs +7 -0
  187. package/lib/chunk-YAZO75G2.mjs +8 -0
  188. package/lib/chunk-YBU4Z4QV.mjs +7 -0
  189. package/lib/chunk-YMJVMFPY.mjs +7 -0
  190. package/lib/chunk-YPSRZRIT.mjs +7 -0
  191. package/lib/chunk-YS4G22C2.mjs +7 -0
  192. package/lib/chunk-YW2SBL4Z.mjs +7 -0
  193. package/lib/chunk-YYZL7UGV.mjs +7 -0
  194. package/lib/chunk-Z7X534S4.mjs +10 -0
  195. package/lib/chunk-ZE6HKRR4.mjs +9 -0
  196. package/lib/chunk-ZHJP7L3K.mjs +7 -0
  197. package/lib/chunk-ZJKCWBRJ.mjs +7 -0
  198. package/lib/chunk-ZLZRU6MO.mjs +7 -0
  199. package/lib/chunk-ZOVSMN5C.mjs +7 -0
  200. package/lib/chunk-ZPYJPGDK.mjs +7 -0
  201. package/lib/chunk-ZQOZ4EFW.mjs +7 -0
  202. package/lib/chunk-ZUTYVST5.mjs +7 -0
  203. package/lib/chunk-ZXH4MBWP.mjs +7 -0
  204. package/lib/chunk-ZYEE34WO.mjs +7 -0
  205. package/lib/sandforge-autopilot.mjs +157 -0
  206. package/lib/sandforge-backup.mjs +99 -0
  207. package/lib/sandforge-checkpoint.mjs +353 -0
  208. package/lib/sandforge-cleanup.mjs +56 -0
  209. package/lib/sandforge-clone.mjs +7 -0
  210. package/lib/sandforge-compare.mjs +54 -0
  211. package/lib/sandforge-dataops.mjs +7 -0
  212. package/lib/sandforge-empty.mjs +140 -0
  213. package/lib/sandforge-env.mjs +355 -0
  214. package/lib/sandforge-frozen.mjs +263 -0
  215. package/lib/sandforge-mcp.mjs +40 -0
  216. package/lib/sandforge-monitor.mjs +43 -0
  217. package/lib/sandforge-seed.mjs +7 -0
  218. package/lib/sandforge-sync.mjs +7 -0
  219. package/lib/sandforge.mjs +28 -0
  220. package/package.json +52 -4
@@ -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{b as W}from"./chunk-CA5NAXSU.mjs";import{b as I,e as z,l as F,u as U}from"./chunk-7EANH5PY.mjs";function p(n){return`${n.op}\0${n.objectApiName}`}var j=class{entries=new Map;keys=new Map;of(t){let e=this.entries.get(p(t));return!e||e.spent?200:e.size}wasRefused(t){return this.entries.has(p(t))}wasCut(t){let e=this.entries.get(p(t));return e!==void 0&&e.size<200}firstRefusal(t,e,r){if(this.entries.has(p(t)))return;let o=this.entry(t,e);o.limit=r?.limit,o.automation=r?.automation,o.event=r?.event}refusedAt(t,e,r){this.firstRefusal(t,e,r);let o=this.entry(t,e);return o.size=Math.min(o.size,Math.max(1,Math.ceil(e/2))),this.of(t)}probes(t){return this.entries.get(p(t))?.probes??0}probed(t){let e=this.entries.get(p(t));e&&e.probes++}keepWhole(t){let e=this.entries.get(p(t));e&&(e.wholeAlone=!0)}isKeptWhole(t){return this.entries.get(p(t))?.wholeAlone===!0}spend(t){let e=this.entries.get(p(t));e&&(e.spent=!0)}isSpent(t){return this.entries.get(p(t))?.spent===!0}countExtraCalls(t,e){let r=this.entries.get(p(t));r&&e>0&&(r.extraCalls+=e)}countSmallCallRows(t,e){let r=this.entries.get(p(t));r&&e>0&&(r.rows+=e)}countNoted(t,e,r=1){let o=this.entries.get(p(t));!o||r<=0||(e===T?o.alone+=r:e===L?o.notSplit+=r:o.keptWhole+=r)}report(t){let e=this.entries.get(p(t));if(e)return{objectApiName:t.objectApiName,op:t.op,from:e.from,to:e.size,rows:e.rows,extraCalls:e.extraCalls,...e.limit!==void 0?{limit:e.limit}:{},...e.automation!==void 0?{automation:e.automation}:{},...e.event!==void 0?{event:e.event}:{},alone:e.alone,notSplit:e.notSplit,keptWhole:e.keptWhole,wholeAlone:e.wholeAlone,spent:e.spent}}reports(t){let e=[];for(let r of this.keys.values()){if(t!==void 0&&r.op!==t)continue;let o=this.report(r);o&&e.push(o)}return e}entry(t,e){let r=p(t),o=this.entries.get(r);return o||(o={size:200,from:e,spent:!1,wholeAlone:!1,probes:0,rows:0,extraCalls:0,alone:0,notSplit:0,keptWhole:0},this.entries.set(r,o),this.keys.set(r,{objectApiName:t.objectApiName,op:t.op})),o}};function E(n){return Math.max(0,Math.floor(Number.isFinite(n)?n:0))}var J=class{grantedCalls;perObject;takenInAll=0;byObject=new Map;constructor(t=2e3,e=500){this.grantedCalls=E(t),this.perObject=E(e)}get granted(){return this.grantedCalls}limitTo(t){this.grantedCalls=Math.min(this.grantedCalls,E(t))}left(t){let e=this.byObject.get(t.objectApiName)??0;return Math.max(0,Math.min(this.grantedCalls-this.takenInAll,this.perObject-e))}take(t,e){let r=Math.max(0,Math.min(Math.floor(e),this.left(t)));return r>0&&(this.takenInAll+=r,this.byObject.set(t.objectApiName,(this.byObject.get(t.objectApiName)??0)+r)),r}get spent(){return this.takenInAll}taken(t){return this.byObject.get(t.objectApiName)??0}};function se(n=2e3){return{sizes:new j,allowance:new J(n)}}function D(n,t){let e=Math.floor((n-t)/2);return Number.isFinite(e)?Math.min(2e3,Math.max(0,e)):0}function oe(n){return n.remaining===void 0?{}:{splitAllowance:D(n.remaining,n.estimate)}}function N(n,t,e,r){if(r<=0||n.isSpent(e))return 0;let o=t.take(e,r);return n.countExtraCalls(e,o),o<r&&n.spend(e),o}var T="alone",L="notSplit",v="keptWhole",Q="Sent on its own, the record still made the target's automation hit a Salesforce limit: the automation does too much for this record alone \u2014 fix it, or have it honour the bypass Forge's automation mute sets.",V="Not sent in smaller calls: records of the same object sent on their own were refused for a Salesforce limit too, so a smaller call would not take it \u2014 fix the target's automation, or have it honour the bypass Forge's automation mute sets.";function B(n,t){return n>0?`the ${t} had spent the ${n} smaller calls it allows itself`:`what the org has left today allowed the ${t} none`}function q(n,t="run"){return`Not sent in smaller calls: ${B(n,t)}.`}function ie(n,t,e="run"){return n===T?Q:n===v?V:q(t,e)}function M(n){return`${n} ${n===1?"call":"calls"} more`}function X(n){return`${n} ${n===1?"record":"records"}`}function Y(n){return n.automation===void 0?"The target's automation":n.event===void 0?n.automation:`${n.automation} (${n.event})`}function ae(n){let t=`${Y(n)} hit ${n.limit??"a Salesforce limit"} on a call of ${n.from}`;return n.wholeAlone?`${t}, and ${X(n.alone)} sent on ${n.alone===1?"its":"their"} own were refused too: not sent in smaller calls, ${M(n.extraCalls)}.`:n.to<200&&n.rows>0?`${t}: sent ${n.to} at a time, ${M(n.extraCalls)}.`:n.extraCalls>0?`${t}: ${M(n.extraCalls)}.`:`${t}.`}function le(n,t,e="run"){return`${n} not sent in smaller calls: ${B(t,e)}.`}function ue(n,t){let e=n.perObject-n.taken(t),r=n.granted-n.spent;return e<r?n.perObject:n.granted}function ee(n,t,e=200){return n<=t?!1:Math.ceil(n/e)===Math.ceil((n-t)/e)}var te=new Set;async function ce(n,t){let{key:e,sizes:r,allowance:o}=t,c=Math.min(t.maxSize??200,200),h=[],m,f=0,S=()=>[...h.flatMap(s=>s.items),...m?.items??[],...n.slice(f)],K=()=>{let s=Math.min(c,r.of(e)),l=s<c,g=t.pricedAs==="job"||ee(n.length-f,s,c);l&&g&&(t.paid&&t.paid.calls>0?t.paid.calls--:N(r,o,e,1)===0&&(s=c,l=!1));let i=n.slice(f,f+s);return f+=i.length,{items:i,reduced:l}},A=async s=>{let l=m;if(m=void 0,!l||l.items.length===0)return;r.countNoted(e,s,l.items.length);let g=new Map(l.items.map((i,d)=>[d,s]));try{await t.settle(l.items,l.answers,te,g,!0)}catch(i){throw t.onThrow?.(S(),i),i}},k=async()=>{let s=m;if(!s)return;if(s.items.length===0){m=void 0;return}let l=r.refusedAt(e,s.from,s.cause),g=N(r,o,e,Math.ceil(s.items.length/l)),i=Math.min(s.items.length,g*l),d=[];for(let b=0;b<i;b+=l)d.push({items:s.items.slice(b,Math.min(i,b+l)),reduced:!0});h.unshift(...d),m={...s,items:s.items.slice(i),answers:s.answers.slice(i)},await A(L)},_=async()=>{let s=m;if(!s||s.items.length===0){m=void 0;return}if(N(r,o,e,1)===0){await A(L);return}r.probed(e),h.unshift({items:[s.items[0]],reduced:!0,probe:!0}),m={...s,items:s.items.slice(1),answers:s.answers.slice(1)}},P=!0,w=t.refusedIn;if(w&&n.length>0){if(f=n.length,P=!1,!r.wasRefused(e)){r.firstRefusal(e,w.from,w.cause);let s=r.report(e);s&&t.onFirstRefusal?.(s)}m={items:[...n],answers:[...w.answers],from:w.from,...w.cause?{cause:w.cause}:{}},r.isSpent(e)?await A(L):r.isKeptWhole(e)?await A(v):!r.wasCut(e)&&r.probes(e)<2?await _():await k()}for(;;){let s;if(P){if(n.length===0)return{};s=K()}else{if(s=h.shift()??(f<n.length?K():void 0),!s)return{};try{if(await t.beforeEachSend?.()==="stop")return{stopped:{part:s.items,rest:S(),sent:!1}}}catch(u){throw t.onThrow?.([...s.items,...S()],u),u}}P=!1;let l;try{l=await t.send(s.items)}catch(u){throw t.onThrow?.([...s.items,...S()],u),u}if(l==="stop")return{stopped:{part:s.items,rest:S(),sent:!0}};let{answers:g}=l,i=s.items,d=[],b;for(let u=0;u<i.length;u++){let a=t.limited(g[u],i[u]);a&&(d.push(u),b??=a)}let R=new Set,C=new Map,x;if(s.probe)d.length>0?(C.set(0,T),x=r.probes(e)<2&&(m?.items.length??0)>0?_:async()=>{r.probes(e)>=2&&r.keepWhole(e),await A(v)}):x=k;else if(d.length>0){if(!r.wasRefused(e)){r.firstRefusal(e,i.length,b);let a=r.report(e);a&&t.onFirstRefusal?.(a)}let u=!r.wasCut(e)&&!r.isKeptWhole(e)&&r.probes(e)<2;if(i.length===1)C.set(0,T),u&&!r.isSpent(e)&&(r.probed(e),r.probes(e)>=2&&r.keepWhole(e));else if(r.isSpent(e))for(let a of d)C.set(a,L);else if(r.isKeptWhole(e))for(let a of d)C.set(a,v);else if(u){for(let a of d)R.add(a);m={items:d.map(a=>i[a]),answers:d.map(a=>g[a]),from:i.length,...b?{cause:b}:{}},x=_}else{let a=r.refusedAt(e,i.length,b),Z=N(r,o,e,Math.ceil(d.length/a)),O=d.slice(0,Z*a);for(let y of O)R.add(y);for(let y of d.slice(O.length))C.set(y,L);let $=[];for(let y=0;y<O.length;y+=a)$.push({items:O.slice(y,y+a).map(H=>i[H]),reduced:!0});h.unshift(...$)}}for(let u of C.values())r.countNoted(e,u);s.reduced&&r.countSmallCallRows(e,i.length-R.size);try{await t.settle(i,g,R,C)}catch(u){throw t.onThrow?.(S(),u),u}await x?.()}}var ne=60*6e4,re=F({state:U(["Open","UploadComplete","InProgress","JobComplete","Failed","Aborted"]),numberRecordsProcessed:z().int().nonnegative().optional(),errorMessage:I().nullish(),systemModstamp:I().optional(),createdDate:I().optional()});function G(n,t){let e=re.safeParse(t);if(e.success)return e.data;let r=typeof t=="object"&&t!==null&&"state"in t?String(JSON.stringify(t.state)):"none";throw new Error(`The org's answer about Bulk API job ${n||"(no id)"} is not an ingest job's state (state: ${r})`)}async function fe(n,t,e={}){let r=e.now??(()=>Date.now());try{let o=n.bulk2.job("ingest",{id:t}),c=G(t,await o.check());if(c.state==="Open"){let h=Date.parse(c.createdDate??""),m=e.openGraceMs??ne,f=m-(r()-h);if(Number.isFinite(h)&&f>0)return{state:"running",info:c,openUntil:new Date(h+m).toISOString(),graceLeftMs:f};if(!await o.abort().then(()=>!1,()=>!0)&&m>0)return{state:"never-closed"};if(c=G(t,await o.check()),c.state==="Open"||c.state==="Aborted"&&c.numberRecordsProcessed===0)return{state:"never-closed"}}if(c.state==="UploadComplete"||c.state==="InProgress")return{state:"running",info:c};if(e.successfulOnly)return{state:"ended",info:c,results:{successfulResults:[...await o.getSuccessfulResults()]}};if(o.getAllResults===void 0)throw new Error(`Bulk API job ${t}: this connection reads no failed or unprocessed rows`);return{state:"ended",info:c,results:await o.getAllResults()}}catch(o){return{state:"unread",reason:W(o)}}}export{se as a,D as b,oe as c,Q as d,V as e,ie as f,ae as g,le as h,ue as i,ce as j,G as k,fe as l};