@poe-platform/safe-bash 0.1.629 → 0.1.631

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 (377) hide show
  1. package/README.md +2 -2
  2. package/dist/office-package/compression.d.ts +19 -0
  3. package/dist/office-package/compression.js +186 -0
  4. package/dist/office-package/runtime.d.ts +11 -0
  5. package/dist/office-package/runtime.js +28 -0
  6. package/dist/safe-bash/chunks/{bz2-B2RXT4EX.js → bz2-ACU4EOVE.js} +2 -2
  7. package/dist/safe-bash/chunks/chunk-2E4KBFO6.js +239 -0
  8. package/dist/safe-bash/chunks/chunk-2E4KBFO6.js.map +7 -0
  9. package/dist/safe-bash/chunks/chunk-3E5M2WEL.js +33 -0
  10. package/dist/safe-bash/chunks/chunk-3E5M2WEL.js.map +7 -0
  11. package/dist/safe-bash/chunks/{chunk-WPEMUXV4.js → chunk-3LD67SER.js} +12 -10
  12. package/dist/safe-bash/chunks/{chunk-WPEMUXV4.js.map → chunk-3LD67SER.js.map} +1 -1
  13. package/dist/safe-bash/chunks/{chunk-6LSSEOG7.js → chunk-6HNK7Q66.js} +11 -7
  14. package/dist/safe-bash/chunks/{chunk-6LSSEOG7.js.map → chunk-6HNK7Q66.js.map} +1 -1
  15. package/dist/safe-bash/chunks/{chunk-AD7UAP5B.js → chunk-7EEWZY5S.js} +10 -8
  16. package/dist/safe-bash/chunks/{chunk-AD7UAP5B.js.map → chunk-7EEWZY5S.js.map} +1 -1
  17. package/dist/safe-bash/chunks/{chunk-RNKTWFEM.js → chunk-CDBQXRWL.js} +3 -3
  18. package/dist/safe-bash/chunks/{chunk-UYX72YHY.js → chunk-CHHAB5SS.js} +10 -74
  19. package/dist/safe-bash/chunks/{chunk-UYX72YHY.js.map → chunk-CHHAB5SS.js.map} +3 -3
  20. package/dist/safe-bash/chunks/{chunk-KYNRHYHP.js → chunk-EI4X5ETX.js} +15 -13
  21. package/dist/safe-bash/chunks/{chunk-KYNRHYHP.js.map → chunk-EI4X5ETX.js.map} +1 -1
  22. package/dist/safe-bash/chunks/{chunk-KZ7QCYNT.js → chunk-GIBLUW2U.js} +13 -9
  23. package/dist/safe-bash/chunks/{chunk-KZ7QCYNT.js.map → chunk-GIBLUW2U.js.map} +1 -1
  24. package/dist/safe-bash/chunks/chunk-GPV7ZFYS.js +1528 -0
  25. package/dist/safe-bash/chunks/chunk-GPV7ZFYS.js.map +7 -0
  26. package/dist/safe-bash/chunks/{chunk-N5CYTGBN.js → chunk-H3E67KTZ.js} +13 -9
  27. package/dist/safe-bash/chunks/{chunk-N5CYTGBN.js.map → chunk-H3E67KTZ.js.map} +1 -1
  28. package/dist/safe-bash/chunks/{chunk-AFH57PPL.js → chunk-IEKESMO4.js} +3 -3
  29. package/dist/safe-bash/chunks/{chunk-DPJWEGIX.js → chunk-JLBIUYT3.js} +2 -2
  30. package/dist/safe-bash/chunks/chunk-JZDO5MC3.js +77 -0
  31. package/dist/safe-bash/chunks/chunk-JZDO5MC3.js.map +7 -0
  32. package/dist/safe-bash/chunks/{chunk-GFZKQIPL.js → chunk-LA6BX562.js} +8 -6
  33. package/dist/safe-bash/chunks/{chunk-GFZKQIPL.js.map → chunk-LA6BX562.js.map} +1 -1
  34. package/dist/safe-bash/chunks/{chunk-PVJJFCGA.js → chunk-M3GPCYSP.js} +2 -2
  35. package/dist/safe-bash/chunks/{chunk-FWDMJTQO.js → chunk-NDCZ3UBP.js} +13 -9
  36. package/dist/safe-bash/chunks/{chunk-FWDMJTQO.js.map → chunk-NDCZ3UBP.js.map} +1 -1
  37. package/dist/safe-bash/chunks/{chunk-2KL6W6NB.js → chunk-O2EVBRKF.js} +1 -2
  38. package/dist/safe-bash/chunks/chunk-OFT77XIB.js +389 -0
  39. package/dist/safe-bash/chunks/chunk-OFT77XIB.js.map +7 -0
  40. package/dist/safe-bash/chunks/{chunk-PCLOK32J.js → chunk-PC6BEIAF.js} +13 -9
  41. package/dist/safe-bash/chunks/{chunk-PCLOK32J.js.map → chunk-PC6BEIAF.js.map} +1 -1
  42. package/dist/safe-bash/chunks/{chunk-3M5F7LD5.js → chunk-QWKP7ZU7.js} +13 -9
  43. package/dist/safe-bash/chunks/{chunk-3M5F7LD5.js.map → chunk-QWKP7ZU7.js.map} +1 -1
  44. package/dist/safe-bash/chunks/chunk-THXJ6CLF.js +53 -0
  45. package/dist/safe-bash/chunks/chunk-THXJ6CLF.js.map +7 -0
  46. package/dist/safe-bash/chunks/{chunk-HHJSJWUD.js → chunk-V73A742N.js} +57 -15
  47. package/dist/safe-bash/chunks/chunk-V73A742N.js.map +7 -0
  48. package/dist/safe-bash/chunks/{chunk-4BYUV5PA.js → chunk-VN3ZGME3.js} +12 -8
  49. package/dist/safe-bash/chunks/{chunk-4BYUV5PA.js.map → chunk-VN3ZGME3.js.map} +1 -1
  50. package/dist/safe-bash/chunks/chunk-WECHUK3Y.js +4285 -0
  51. package/dist/safe-bash/chunks/chunk-WECHUK3Y.js.map +7 -0
  52. package/dist/safe-bash/chunks/{chunk-X55AMTNM.js → chunk-WIOEUR7D.js} +14 -10
  53. package/dist/safe-bash/chunks/{chunk-X55AMTNM.js.map → chunk-WIOEUR7D.js.map} +1 -1
  54. package/dist/safe-bash/chunks/chunk-WPIOO4NX.js +443 -0
  55. package/dist/safe-bash/chunks/chunk-WPIOO4NX.js.map +7 -0
  56. package/dist/safe-bash/chunks/{chunk-C7QNJ3D4.js → chunk-WYTI64IU.js} +2 -2
  57. package/dist/safe-bash/chunks/{xz-AVXFDXW4.js → xz-U4QDTPZL.js} +2 -2
  58. package/dist/safe-bash/chunks/{zstd-R6RPHJYO.js → zstd-OG5RPYXO.js} +2 -2
  59. package/dist/safe-bash/commands/archive/zip/crc.d.ts +2 -0
  60. package/dist/safe-bash/commands/archive/zip/crc.d.ts.map +1 -0
  61. package/dist/safe-bash/commands/archive/zip/crc.js +7 -0
  62. package/dist/safe-bash/commands/archive/zip/crc.js.map +1 -0
  63. package/dist/safe-bash/commands/archive/zip/crypto.d.ts +4 -0
  64. package/dist/safe-bash/commands/archive/zip/crypto.d.ts.map +1 -0
  65. package/dist/safe-bash/commands/archive/zip/crypto.js +34 -0
  66. package/dist/safe-bash/commands/archive/zip/crypto.js.map +1 -0
  67. package/dist/safe-bash/commands/archive/zip/help.d.ts +3 -0
  68. package/dist/safe-bash/commands/archive/zip/help.d.ts.map +1 -0
  69. package/dist/safe-bash/commands/archive/zip/help.js +87 -0
  70. package/dist/safe-bash/commands/archive/zip/help.js.map +1 -0
  71. package/dist/safe-bash/commands/archive/zip/move.d.ts +12 -0
  72. package/dist/safe-bash/commands/archive/zip/move.d.ts.map +1 -0
  73. package/dist/safe-bash/commands/archive/zip/move.js +60 -0
  74. package/dist/safe-bash/commands/archive/zip/move.js.map +1 -0
  75. package/dist/safe-bash/commands/archive/zip/options.js +5 -5
  76. package/dist/safe-bash/commands/archive/zip/options.js.map +1 -1
  77. package/dist/safe-bash/commands/archive/zip-format.d.ts +1 -1
  78. package/dist/safe-bash/commands/archive/zip-format.d.ts.map +1 -1
  79. package/dist/safe-bash/commands/archive/zip-format.js +14 -17
  80. package/dist/safe-bash/commands/archive/zip-format.js.map +1 -1
  81. package/dist/safe-bash/commands/archive/zip.d.ts.map +1 -1
  82. package/dist/safe-bash/commands/archive/zip.js +45 -15
  83. package/dist/safe-bash/commands/archive/zip.js.map +1 -1
  84. package/dist/safe-bash/commands/bytes/compression/bounded-codec.d.ts +2 -0
  85. package/dist/safe-bash/commands/bytes/compression/bounded-codec.d.ts.map +1 -1
  86. package/dist/safe-bash/commands/bytes/compression/bounded-codec.js +4 -0
  87. package/dist/safe-bash/commands/bytes/compression/bounded-codec.js.map +1 -1
  88. package/dist/safe-bash/commands/bytes/compression/codec.d.ts +4 -24
  89. package/dist/safe-bash/commands/bytes/compression/codec.d.ts.map +1 -1
  90. package/dist/safe-bash/commands/bytes/compression/codec.js +12 -168
  91. package/dist/safe-bash/commands/bytes/compression/codec.js.map +1 -1
  92. package/dist/safe-bash/commands/cmp.js +1 -1
  93. package/dist/safe-bash/commands/cmp.js.map +1 -1
  94. package/dist/safe-bash/commands/csplit/index.browser.js +10 -7
  95. package/dist/safe-bash/commands/docx/index.browser.js +54 -0
  96. package/dist/safe-bash/commands/docx/index.browser.js.map +7 -0
  97. package/dist/safe-bash/commands/docx/index.d.ts +25 -0
  98. package/dist/safe-bash/commands/docx/index.d.ts.map +1 -0
  99. package/dist/safe-bash/commands/docx/index.js +42 -0
  100. package/dist/safe-bash/commands/docx/index.js.map +1 -0
  101. package/dist/safe-bash/commands/docx/io.d.ts +15 -0
  102. package/dist/safe-bash/commands/docx/io.d.ts.map +1 -0
  103. package/dist/safe-bash/commands/docx/io.js +16 -0
  104. package/dist/safe-bash/commands/docx/io.js.map +1 -0
  105. package/dist/safe-bash/commands/factor/index.browser.js +7 -5
  106. package/dist/safe-bash/commands/filesystem.d.ts.map +1 -1
  107. package/dist/safe-bash/commands/filesystem.js +9 -1
  108. package/dist/safe-bash/commands/filesystem.js.map +1 -1
  109. package/dist/safe-bash/commands/getopt/index.browser.js +7 -5
  110. package/dist/safe-bash/commands/hexdump/index.browser.js +8 -6
  111. package/dist/safe-bash/commands/iconv/index.browser.js +8 -6
  112. package/dist/safe-bash/commands/line-endings/index.browser.js +10 -7
  113. package/dist/safe-bash/commands/llm/index.browser.js +10 -8
  114. package/dist/safe-bash/commands/llm/providers/index.browser.js +3 -3
  115. package/dist/safe-bash/commands/network/index.browser.js +11 -8
  116. package/dist/safe-bash/commands/node/browser.d.ts +2 -0
  117. package/dist/safe-bash/commands/node/browser.d.ts.map +1 -0
  118. package/dist/safe-bash/commands/node/browser.js +2 -0
  119. package/dist/safe-bash/commands/node/browser.js.map +1 -0
  120. package/dist/safe-bash/commands/node/index.browser.js +18 -0
  121. package/dist/safe-bash/commands/node/index.browser.js.map +7 -0
  122. package/dist/safe-bash/commands/node/safejs.d.ts +6 -0
  123. package/dist/safe-bash/commands/node/safejs.d.ts.map +1 -1
  124. package/dist/safe-bash/commands/node/safejs.js +25 -1
  125. package/dist/safe-bash/commands/node/safejs.js.map +1 -1
  126. package/dist/safe-bash/commands/op/index.browser.js +3 -3
  127. package/dist/safe-bash/commands/op/index.js +0 -1
  128. package/dist/safe-bash/commands/op/index.js.map +2 -2
  129. package/dist/safe-bash/commands/pptx/index.d.ts +29 -0
  130. package/dist/safe-bash/commands/pptx/index.d.ts.map +1 -0
  131. package/dist/safe-bash/commands/pptx/index.js +153 -0
  132. package/dist/safe-bash/commands/pptx/index.js.map +1 -0
  133. package/dist/safe-bash/commands/pr/index.browser.js +8 -6
  134. package/dist/safe-bash/commands/predicates.js +1 -1
  135. package/dist/safe-bash/commands/python/execution.d.ts +3 -0
  136. package/dist/safe-bash/commands/python/execution.d.ts.map +1 -0
  137. package/dist/safe-bash/commands/python/execution.js +193 -0
  138. package/dist/safe-bash/commands/python/execution.js.map +1 -0
  139. package/dist/safe-bash/commands/python/index.browser.js +21 -0
  140. package/dist/safe-bash/commands/python/index.browser.js.map +7 -0
  141. package/dist/safe-bash/commands/python/index.d.ts +49 -0
  142. package/dist/safe-bash/commands/python/index.d.ts.map +1 -0
  143. package/dist/safe-bash/commands/python/index.js +317 -0
  144. package/dist/safe-bash/commands/python/index.js.map +1 -0
  145. package/dist/safe-bash/commands/python/installation.d.ts +9 -0
  146. package/dist/safe-bash/commands/python/installation.d.ts.map +1 -0
  147. package/dist/safe-bash/commands/python/installation.js +80 -0
  148. package/dist/safe-bash/commands/python/installation.js.map +1 -0
  149. package/dist/safe-bash/commands/python/invocation.d.ts +10 -0
  150. package/dist/safe-bash/commands/python/invocation.d.ts.map +1 -0
  151. package/dist/safe-bash/commands/python/invocation.js +81 -0
  152. package/dist/safe-bash/commands/python/invocation.js.map +1 -0
  153. package/dist/safe-bash/commands/python/node.d.ts +12 -0
  154. package/dist/safe-bash/commands/python/node.d.ts.map +1 -0
  155. package/dist/safe-bash/commands/python/node.js +33 -0
  156. package/dist/safe-bash/commands/python/node.js.map +1 -0
  157. package/dist/safe-bash/commands/python/provisioning-runtime.d.ts +5 -0
  158. package/dist/safe-bash/commands/python/provisioning-runtime.d.ts.map +1 -0
  159. package/dist/safe-bash/commands/python/provisioning-runtime.js +179 -0
  160. package/dist/safe-bash/commands/python/provisioning-runtime.js.map +1 -0
  161. package/dist/safe-bash/commands/python/provisioning.d.ts +49 -0
  162. package/dist/safe-bash/commands/python/provisioning.d.ts.map +1 -0
  163. package/dist/safe-bash/commands/python/provisioning.js +320 -0
  164. package/dist/safe-bash/commands/python/provisioning.js.map +1 -0
  165. package/dist/safe-bash/commands/python/reply.d.ts +3 -0
  166. package/dist/safe-bash/commands/python/reply.d.ts.map +1 -0
  167. package/dist/safe-bash/commands/python/reply.js +103 -0
  168. package/dist/safe-bash/commands/python/reply.js.map +1 -0
  169. package/dist/safe-bash/commands/python/worker.browser.js +736 -0
  170. package/dist/safe-bash/commands/python/worker.browser.js.map +7 -0
  171. package/dist/safe-bash/commands/python/worker.d.ts +47 -0
  172. package/dist/safe-bash/commands/python/worker.d.ts.map +1 -0
  173. package/dist/safe-bash/commands/python/worker.js +373 -0
  174. package/dist/safe-bash/commands/python/worker.js.map +1 -0
  175. package/dist/safe-bash/commands/safejs/index.d.ts +5 -17
  176. package/dist/safe-bash/commands/safejs/index.d.ts.map +1 -1
  177. package/dist/safe-bash/commands/safejs/index.js +3 -202
  178. package/dist/safe-bash/commands/safejs/index.js.map +1 -1
  179. package/dist/safe-bash/commands/safejs/runtime.d.ts +15 -0
  180. package/dist/safe-bash/commands/safejs/runtime.d.ts.map +1 -0
  181. package/dist/safe-bash/commands/safejs/runtime.js +190 -0
  182. package/dist/safe-bash/commands/safejs/runtime.js.map +1 -0
  183. package/dist/safe-bash/commands/tsort/index.browser.js +8 -6
  184. package/dist/safe-bash/commands/xml/index.browser.js +9 -7
  185. package/dist/safe-bash/commands/yq/index.browser.js +10 -8
  186. package/dist/safe-bash/commands/yq/index.d.ts.map +1 -1
  187. package/dist/safe-bash/commands/yq/index.js +32 -4
  188. package/dist/safe-bash/commands/yq/index.js.map +1 -1
  189. package/dist/safe-bash/commands/yq/parser.d.ts.map +1 -1
  190. package/dist/safe-bash/commands/yq/parser.js +21 -5
  191. package/dist/safe-bash/commands/yq/parser.js.map +1 -1
  192. package/dist/safe-bash/contracts/command.d.ts +2 -0
  193. package/dist/safe-bash/contracts/command.d.ts.map +1 -1
  194. package/dist/safe-bash/contracts/command.js +6 -2
  195. package/dist/safe-bash/contracts/command.js.map +1 -1
  196. package/dist/safe-bash/contracts/filesystem-descriptor.d.ts +13 -0
  197. package/dist/safe-bash/contracts/filesystem-descriptor.d.ts.map +1 -0
  198. package/dist/safe-bash/contracts/filesystem-descriptor.js +189 -0
  199. package/dist/safe-bash/contracts/filesystem-descriptor.js.map +1 -0
  200. package/dist/safe-bash/contracts/filesystem-output-budget.d.ts +15 -0
  201. package/dist/safe-bash/contracts/filesystem-output-budget.d.ts.map +1 -0
  202. package/dist/safe-bash/contracts/filesystem-output-budget.js +69 -0
  203. package/dist/safe-bash/contracts/filesystem-output-budget.js.map +1 -0
  204. package/dist/safe-bash/contracts/filesystem-output.d.ts +11 -5
  205. package/dist/safe-bash/contracts/filesystem-output.d.ts.map +1 -1
  206. package/dist/safe-bash/contracts/filesystem-output.js +229 -20
  207. package/dist/safe-bash/contracts/filesystem-output.js.map +1 -1
  208. package/dist/safe-bash/contracts/io.d.ts +29 -0
  209. package/dist/safe-bash/contracts/io.d.ts.map +1 -1
  210. package/dist/safe-bash/contracts/io.js +317 -37
  211. package/dist/safe-bash/contracts/io.js.map +1 -1
  212. package/dist/safe-bash/core.browser.js +5963 -6522
  213. package/dist/safe-bash/core.browser.js.map +4 -4
  214. package/dist/safe-bash/core.d.ts +2 -0
  215. package/dist/safe-bash/core.d.ts.map +1 -1
  216. package/dist/safe-bash/core.js +2 -0
  217. package/dist/safe-bash/core.js.map +1 -1
  218. package/dist/safe-bash/index.d.ts +1 -0
  219. package/dist/safe-bash/index.d.ts.map +1 -1
  220. package/dist/safe-bash/index.js +1 -0
  221. package/dist/safe-bash/index.js.map +1 -1
  222. package/dist/safe-bash/opt-in/commands/cmp/compare.js +95 -0
  223. package/dist/safe-bash/opt-in/commands/cmp/index.d.ts +6 -0
  224. package/dist/safe-bash/opt-in/commands/cmp/index.js +99 -0
  225. package/dist/safe-bash/opt-in/commands/cmp/io.js +218 -0
  226. package/dist/safe-bash/opt-in/commands/cmp/options.d.ts +24 -0
  227. package/dist/safe-bash/opt-in/commands/cmp/options.js +195 -0
  228. package/dist/safe-bash/opt-in/commands/dd/conversions.js +152 -0
  229. package/dist/safe-bash/opt-in/commands/dd/index.d.ts +18 -0
  230. package/dist/safe-bash/opt-in/commands/dd/index.js +561 -0
  231. package/dist/safe-bash/opt-in/commands/dd/io.d.ts +31 -0
  232. package/dist/safe-bash/opt-in/commands/dd/io.js +244 -0
  233. package/dist/safe-bash/opt-in/commands/dd/options.js +184 -0
  234. package/dist/safe-bash/opt-in/commands/dd/report.js +69 -0
  235. package/dist/safe-bash/opt-in/commands/install/arguments.js +224 -0
  236. package/dist/safe-bash/opt-in/commands/install/index.d.ts +6 -0
  237. package/dist/safe-bash/opt-in/commands/install/index.js +678 -0
  238. package/dist/safe-bash/opt-in/commands/install/mode.js +71 -0
  239. package/dist/safe-bash/opt-in/commands/install/options.d.ts +36 -0
  240. package/dist/safe-bash/opt-in/commands/install/options.js +27 -0
  241. package/dist/safe-bash/opt-in/commands/shuf/args.js +179 -0
  242. package/dist/safe-bash/opt-in/commands/shuf/index.d.ts +6 -0
  243. package/dist/safe-bash/opt-in/commands/shuf/index.js +20 -0
  244. package/dist/safe-bash/opt-in/commands/shuf/input.js +93 -0
  245. package/dist/safe-bash/opt-in/commands/shuf/options.d.ts +9 -0
  246. package/dist/safe-bash/opt-in/commands/shuf/options.js +8 -0
  247. package/dist/safe-bash/opt-in/commands/shuf/random.js +114 -0
  248. package/dist/safe-bash/opt-in/commands/shuf/shuf.d.ts +3 -0
  249. package/dist/safe-bash/opt-in/commands/shuf/shuf.js +230 -0
  250. package/dist/safe-bash/opt-in/commands/shuf/usage.js +24 -0
  251. package/dist/safe-bash/opt-in/commands/truncate/arguments.js +186 -0
  252. package/dist/safe-bash/opt-in/commands/truncate/index.d.ts +9 -0
  253. package/dist/safe-bash/opt-in/commands/truncate/index.js +244 -0
  254. package/dist/safe-bash/opt-in/commands/yes/index.d.ts +11 -0
  255. package/dist/safe-bash/opt-in/commands/yes/index.js +167 -0
  256. package/dist/safe-bash/opt-in/commands/yq/arguments.js +177 -0
  257. package/dist/safe-bash/opt-in/commands/yq/evaluate.js +564 -0
  258. package/dist/safe-bash/opt-in/commands/yq/expression.js +183 -0
  259. package/dist/safe-bash/opt-in/commands/yq/inplace.js +65 -0
  260. package/dist/safe-bash/opt-in/commands/yq/mike.d.ts +9 -0
  261. package/dist/safe-bash/opt-in/commands/yq/mike.js +192 -0
  262. package/dist/safe-bash/opt-in/commands/yq/native-encoder.js +165 -0
  263. package/dist/safe-bash/opt-in/commands/yq/native-work.d.ts +44 -0
  264. package/dist/safe-bash/opt-in/commands/yq/native-work.js +188 -0
  265. package/dist/safe-bash/opt-in/commands/yq/nodes.js +621 -0
  266. package/dist/safe-bash/opt-in/entrypoints/arrays.d.ts +1 -0
  267. package/dist/safe-bash/opt-in/entrypoints/arrays.js +1 -0
  268. package/dist/safe-bash/opt-in/entrypoints/cmp.d.ts +2 -0
  269. package/dist/safe-bash/opt-in/entrypoints/cmp.js +1 -0
  270. package/dist/safe-bash/opt-in/entrypoints/dd.d.ts +2 -0
  271. package/dist/safe-bash/opt-in/entrypoints/dd.js +1 -0
  272. package/dist/safe-bash/opt-in/entrypoints/devices.d.ts +2 -0
  273. package/dist/safe-bash/opt-in/entrypoints/devices.js +1 -0
  274. package/dist/safe-bash/opt-in/entrypoints/install.d.ts +2 -0
  275. package/dist/safe-bash/opt-in/entrypoints/install.js +1 -0
  276. package/dist/safe-bash/opt-in/entrypoints/jobs.d.ts +1 -0
  277. package/dist/safe-bash/opt-in/entrypoints/jobs.js +1 -0
  278. package/dist/safe-bash/opt-in/entrypoints/mapfile.d.ts +1 -0
  279. package/dist/safe-bash/opt-in/entrypoints/mapfile.js +1 -0
  280. package/dist/safe-bash/opt-in/entrypoints/read.d.ts +2 -0
  281. package/dist/safe-bash/opt-in/entrypoints/read.js +1 -0
  282. package/dist/safe-bash/opt-in/entrypoints/shuf.d.ts +2 -0
  283. package/dist/safe-bash/opt-in/entrypoints/shuf.js +1 -0
  284. package/dist/safe-bash/opt-in/entrypoints/trap.d.ts +2 -0
  285. package/dist/safe-bash/opt-in/entrypoints/trap.js +1 -0
  286. package/dist/safe-bash/opt-in/entrypoints/truncate.d.ts +2 -0
  287. package/dist/safe-bash/opt-in/entrypoints/truncate.js +1 -0
  288. package/dist/safe-bash/opt-in/entrypoints/yes.d.ts +2 -0
  289. package/dist/safe-bash/opt-in/entrypoints/yes.js +1 -0
  290. package/dist/safe-bash/opt-in/entrypoints/yq.d.ts +3 -0
  291. package/dist/safe-bash/opt-in/entrypoints/yq.js +1 -0
  292. package/dist/safe-bash/opt-in/fs/devices/index.d.ts +8 -0
  293. package/dist/safe-bash/opt-in/fs/devices/index.js +292 -0
  294. package/dist/safe-bash/opt-in/optional.d.ts +28 -0
  295. package/dist/safe-bash/opt-in/optional.js +14 -0
  296. package/dist/safe-bash/opt-in/shell/extensions/arrays/index.d.ts +2 -0
  297. package/dist/safe-bash/opt-in/shell/extensions/arrays/index.js +4 -0
  298. package/dist/safe-bash/opt-in/shell/extensions/jobs/index.d.ts +2 -0
  299. package/dist/safe-bash/opt-in/shell/extensions/jobs/index.js +291 -0
  300. package/dist/safe-bash/opt-in/shell/extensions/jobs/state.js +374 -0
  301. package/dist/safe-bash/opt-in/shell/extensions/mapfile/index.d.ts +24 -0
  302. package/dist/safe-bash/opt-in/shell/extensions/mapfile/index.js +338 -0
  303. package/dist/safe-bash/opt-in/shell/extensions/read/index.d.ts +5 -0
  304. package/dist/safe-bash/opt-in/shell/extensions/read/index.js +351 -0
  305. package/dist/safe-bash/opt-in/shell/extensions/trap/index.d.ts +9 -0
  306. package/dist/safe-bash/opt-in/shell/extensions/trap/index.js +210 -0
  307. package/dist/safe-bash/optional-host.d.ts +5 -0
  308. package/dist/safe-bash/optional-host.d.ts.map +1 -0
  309. package/dist/safe-bash/optional-host.js +3 -0
  310. package/dist/safe-bash/optional-host.js.map +1 -0
  311. package/dist/safe-bash/shell/arrays/bindings.d.ts +15 -5
  312. package/dist/safe-bash/shell/arrays/bindings.d.ts.map +1 -1
  313. package/dist/safe-bash/shell/arrays/bindings.js +131 -23
  314. package/dist/safe-bash/shell/arrays/bindings.js.map +1 -1
  315. package/dist/safe-bash/shell/arrays/ledger.d.ts +1 -0
  316. package/dist/safe-bash/shell/arrays/ledger.d.ts.map +1 -1
  317. package/dist/safe-bash/shell/arrays/ledger.js +19 -0
  318. package/dist/safe-bash/shell/arrays/ledger.js.map +1 -1
  319. package/dist/safe-bash/shell/arrays/state.d.ts.map +1 -1
  320. package/dist/safe-bash/shell/arrays/state.js +3 -1
  321. package/dist/safe-bash/shell/arrays/state.js.map +1 -1
  322. package/dist/safe-bash/shell/arrays/syntax.d.ts +4 -1
  323. package/dist/safe-bash/shell/arrays/syntax.d.ts.map +1 -1
  324. package/dist/safe-bash/shell/arrays/syntax.js +3 -3
  325. package/dist/safe-bash/shell/arrays/syntax.js.map +1 -1
  326. package/dist/safe-bash/shell/conditional.js +1 -1
  327. package/dist/safe-bash/shell/descriptors.d.ts +31 -0
  328. package/dist/safe-bash/shell/descriptors.d.ts.map +1 -0
  329. package/dist/safe-bash/shell/descriptors.js +234 -0
  330. package/dist/safe-bash/shell/descriptors.js.map +1 -0
  331. package/dist/safe-bash/shell/diagnostic-name-ranges.d.ts +2 -0
  332. package/dist/safe-bash/shell/diagnostic-name-ranges.d.ts.map +1 -0
  333. package/dist/safe-bash/shell/diagnostic-name-ranges.js +717 -0
  334. package/dist/safe-bash/shell/diagnostic-name-ranges.js.map +1 -0
  335. package/dist/safe-bash/shell/diagnostic-name.d.ts +3 -0
  336. package/dist/safe-bash/shell/diagnostic-name.d.ts.map +1 -0
  337. package/dist/safe-bash/shell/diagnostic-name.js +89 -0
  338. package/dist/safe-bash/shell/diagnostic-name.js.map +1 -0
  339. package/dist/safe-bash/shell/display.js +1 -1
  340. package/dist/safe-bash/shell/display.js.map +1 -1
  341. package/dist/safe-bash/shell/extensions.d.ts +188 -0
  342. package/dist/safe-bash/shell/extensions.d.ts.map +1 -0
  343. package/dist/safe-bash/shell/extensions.js +141 -0
  344. package/dist/safe-bash/shell/extensions.js.map +1 -0
  345. package/dist/safe-bash/shell/input.d.ts +66 -14
  346. package/dist/safe-bash/shell/input.d.ts.map +1 -1
  347. package/dist/safe-bash/shell/input.js +947 -173
  348. package/dist/safe-bash/shell/input.js.map +1 -1
  349. package/dist/safe-bash/shell/parser.d.ts +38 -6
  350. package/dist/safe-bash/shell/parser.d.ts.map +1 -1
  351. package/dist/safe-bash/shell/parser.js +339 -52
  352. package/dist/safe-bash/shell/parser.js.map +1 -1
  353. package/dist/safe-bash/shell/runtime.d.ts +92 -20
  354. package/dist/safe-bash/shell/runtime.d.ts.map +1 -1
  355. package/dist/safe-bash/shell/runtime.js +2547 -689
  356. package/dist/safe-bash/shell/runtime.js.map +1 -1
  357. package/dist/safe-bash/shell/shell.d.ts.map +1 -1
  358. package/dist/safe-bash/shell/shell.js +52 -21
  359. package/dist/safe-bash/shell/shell.js.map +1 -1
  360. package/dist/safe-bash/shell/types.d.ts +4 -0
  361. package/dist/safe-bash/shell/types.d.ts.map +1 -1
  362. package/dist/safe-bash/shell/types.js.map +1 -1
  363. package/package.json +99 -5
  364. package/dist/safe-bash/chunks/chunk-4DBWBEU7.js +0 -194
  365. package/dist/safe-bash/chunks/chunk-4DBWBEU7.js.map +0 -7
  366. package/dist/safe-bash/chunks/chunk-CXMIIXJA.js +0 -178
  367. package/dist/safe-bash/chunks/chunk-CXMIIXJA.js.map +0 -7
  368. package/dist/safe-bash/chunks/chunk-HHJSJWUD.js.map +0 -7
  369. /package/dist/safe-bash/chunks/{bz2-B2RXT4EX.js.map → bz2-ACU4EOVE.js.map} +0 -0
  370. /package/dist/safe-bash/chunks/{chunk-RNKTWFEM.js.map → chunk-CDBQXRWL.js.map} +0 -0
  371. /package/dist/safe-bash/chunks/{chunk-AFH57PPL.js.map → chunk-IEKESMO4.js.map} +0 -0
  372. /package/dist/safe-bash/chunks/{chunk-DPJWEGIX.js.map → chunk-JLBIUYT3.js.map} +0 -0
  373. /package/dist/safe-bash/chunks/{chunk-PVJJFCGA.js.map → chunk-M3GPCYSP.js.map} +0 -0
  374. /package/dist/safe-bash/chunks/{chunk-2KL6W6NB.js.map → chunk-O2EVBRKF.js.map} +0 -0
  375. /package/dist/safe-bash/chunks/{chunk-C7QNJ3D4.js.map → chunk-WYTI64IU.js.map} +0 -0
  376. /package/dist/safe-bash/chunks/{xz-AVXFDXW4.js.map → xz-U4QDTPZL.js.map} +0 -0
  377. /package/dist/safe-bash/chunks/{zstd-R6RPHJYO.js.map → zstd-OG5RPYXO.js.map} +0 -0
@@ -0,0 +1,244 @@
1
+ import { FsError, readBytes, toByteSource } from "@poe-platform/safe-fs";
2
+ import { writeBytes } from "@poe-platform/safe-bash/contracts/io";
3
+ import { openFileOutput, writeFileOutputCounted } from "@poe-platform/safe-bash/contracts/filesystem-output";
4
+ import { openCommandFile } from "@poe-platform/safe-bash/contracts/filesystem-descriptor";
5
+ import { yieldTurn } from "@poe-platform/safe-bash/contracts/yield";
6
+ import { DdError } from "./options.js";
7
+ const countedHandles = new WeakSet();
8
+ export async function writeDdOutput(context, handle, chunk, options, named) {
9
+ if (!handle.write)
10
+ throw new FsError("EBADF");
11
+ return named && !countedHandles.has(handle)
12
+ ? writeFileOutputCounted(context, chunk, () => handle.write(chunk, options)) : handle.write(chunk, options);
13
+ }
14
+ async function openDescriptor(context, path, request) {
15
+ const input = request.direction === "input";
16
+ const descriptor = await openCommandFile(context, path, {
17
+ access: input ? "read" : "write",
18
+ creation: input || request.creation === "never" ? "never" : request.creation === "exclusive" ? "exclusive" : "ifMissing",
19
+ truncate: request.truncate,
20
+ append: !input && request.flags.has("append"),
21
+ ...(request.synchronization === undefined ? {} : { synchronization: request.synchronization }),
22
+ });
23
+ try {
24
+ const stat = await descriptor.stat();
25
+ if (!Number.isSafeInteger(stat.size) || stat.size < 0)
26
+ throw new FsError("EIO", { path, syscall: "fstat" });
27
+ const positioned = input ? descriptor.capabilities.positionedRead : descriptor.capabilities.positionedWrite;
28
+ let position = 0;
29
+ let closed = false;
30
+ const handle = {
31
+ size: BigInt(stat.size), type: stat.type,
32
+ async getSize(options) {
33
+ const current = await descriptor.stat(options);
34
+ if (!Number.isSafeInteger(current.size) || current.size < 0)
35
+ throw new FsError("EIO", { path, syscall: "fstat" });
36
+ return BigInt(current.size);
37
+ },
38
+ ...(descriptor.capabilities.position === true && descriptor.getPosition ? {
39
+ async getPosition(options) {
40
+ const cursor = await descriptor.getPosition(options);
41
+ if (!Number.isSafeInteger(position) || position < 0)
42
+ throw new FsError("EIO", { path, syscall: "getPosition" });
43
+ return BigInt(positioned ? position : cursor);
44
+ },
45
+ } : {}),
46
+ ...(input ? { async read(size, options) {
47
+ const buffer = new Uint8Array(size);
48
+ const count = await descriptor.read(buffer, positioned ? position : null, options);
49
+ if (!Number.isSafeInteger(count) || count < 0 || count > size)
50
+ throw new FsError("EIO", { path, syscall: "read" });
51
+ position += count;
52
+ return buffer.subarray(0, count);
53
+ } } : { async write(chunk, options) {
54
+ const count = await descriptor.write(chunk, positioned ? position : null, options);
55
+ position += count;
56
+ return count;
57
+ } }),
58
+ ...(positioned ? { async seek(offset, options) {
59
+ context.signal.throwIfAborted();
60
+ options.signal?.throwIfAborted();
61
+ if (closed)
62
+ throw new FsError("EBADF", { path, syscall: "seek" });
63
+ if (offset < 0n || offset > BigInt(Number.MAX_SAFE_INTEGER))
64
+ throw new DdError(`${input ? "input" : "output"} offset limit exceeded`);
65
+ position = Number(offset);
66
+ } } : {}),
67
+ ...(descriptor.capabilities.truncate ? { async truncate(length, options) {
68
+ if (length < 0n || length > BigInt(Number.MAX_SAFE_INTEGER))
69
+ throw new DdError("output offset limit exceeded");
70
+ await descriptor.truncate(Number(length), options);
71
+ } } : {}),
72
+ ...(descriptor.capabilities.synchronization !== "none" ? { sync: descriptor.sync } : {}),
73
+ close() { closed = true; return descriptor.close(); },
74
+ acknowledgeCloseFailure: descriptor.acknowledgeCloseFailure,
75
+ };
76
+ if (!input)
77
+ countedHandles.add(handle);
78
+ return handle;
79
+ }
80
+ catch (error) {
81
+ try {
82
+ await descriptor.close();
83
+ }
84
+ catch { }
85
+ context.signal.throwIfAborted();
86
+ throw error;
87
+ }
88
+ }
89
+ export function errorMessage(error) {
90
+ const descriptions = {
91
+ ENOENT: "No such file or directory", EACCES: "Permission denied", EPERM: "Operation not permitted",
92
+ EEXIST: "File exists", EISDIR: "Is a directory", ENOTDIR: "Not a directory", ELOOP: "Too many levels of symbolic links",
93
+ EIO: "Input/output error", ENOTSUP: "Operation not supported", EROFS: "Read-only file system",
94
+ EFBIG: "File too large", ENOSPC: "No space left on device", EPIPE: "Broken pipe", EINVAL: "Invalid argument",
95
+ EAGAIN: "Resource temporarily unavailable", ESPIPE: "Illegal seek", EBADF: "Bad file descriptor",
96
+ };
97
+ if (error instanceof DdError)
98
+ return error.message;
99
+ if (typeof error === "object" && error !== null && "code" in error) {
100
+ const description = descriptions[String(error.code)];
101
+ if (description)
102
+ return description;
103
+ }
104
+ return error instanceof Error ? error.message : String(error);
105
+ }
106
+ export async function openDdFile(context, request) {
107
+ const signal = context.signal;
108
+ signal.throwIfAborted();
109
+ for (const flag of request.flags) {
110
+ if (["binary", "text", "noctty", "count_bytes", "skip_bytes", "seek_bytes", "fullblock"].includes(flag))
111
+ continue;
112
+ if (flag === "append")
113
+ continue;
114
+ if (request.path === undefined && flag === "nofollow")
115
+ continue;
116
+ throw new DdError(`${flag}: Operation not supported by the filesystem stream adapter`);
117
+ }
118
+ const path = request.path === undefined || request.path === "" ? request.path
119
+ : request.path.startsWith("/") ? request.path : `${context.cwd}/${request.path}`;
120
+ if (path !== undefined && context.fs.open) {
121
+ const capabilities = await context.fs.capabilitiesFor?.(path, { signal }) ?? context.fs.capabilities;
122
+ if (capabilities.open !== false && (request.direction !== "input" || (await context.fs.stat(path, { signal })).type !== "directory"))
123
+ return openDescriptor(context, path, request);
124
+ }
125
+ if (request.synchronization)
126
+ throw new DdError(`${request.synchronization === "all" ? "fsync" : "fdatasync"}: Operation not supported by the filesystem stream adapter`);
127
+ if (request.direction === "output" && request.flags.has("append") && request.truncate)
128
+ throw new DdError("append with truncation: Operation not supported by the filesystem stream adapter");
129
+ if (request.direction === "input") {
130
+ const stat = path === undefined ? undefined : await context.fs.stat(path, { signal });
131
+ if (path !== undefined)
132
+ await context.fs.access(path, 4, { signal });
133
+ let position = 0n;
134
+ let iterator;
135
+ let pending = new Uint8Array();
136
+ let consumed = 0;
137
+ let pulls = 0;
138
+ let closed = false;
139
+ const capabilities = path === undefined ? undefined : await context.fs.capabilitiesFor?.(path, { signal }) ?? context.fs.capabilities;
140
+ const streaming = path !== undefined && context.fs.readStream && capabilities?.streamingRead !== false;
141
+ const source = () => {
142
+ if (path === undefined)
143
+ return context.stdin;
144
+ if (stat?.type === "directory")
145
+ return { async *[Symbol.asyncIterator]() { yield* []; throw new FsError("EISDIR", { path }); } };
146
+ if (streaming)
147
+ return context.fs.readStream(path, { signal, start: Number(position), chunkSize: request.blockSize });
148
+ return { async *[Symbol.asyncIterator]() {
149
+ const value = await context.fs.readFile(path, { signal, maxBytes: request.maxBufferBytes });
150
+ yield* toByteSource(value);
151
+ } };
152
+ };
153
+ const closeIterator = async () => {
154
+ const current = iterator;
155
+ iterator = undefined;
156
+ pending = new Uint8Array();
157
+ consumed = 0;
158
+ await current?.return?.();
159
+ };
160
+ return {
161
+ ...(stat === undefined ? {} : { size: BigInt(stat.size), type: stat.type }),
162
+ async read(size) {
163
+ signal.throwIfAborted();
164
+ if (closed)
165
+ throw new FsError("EBADF");
166
+ iterator ??= readBytes(source(), signal)[Symbol.asyncIterator]();
167
+ while (consumed === pending.length) {
168
+ if (++pulls > request.maxReadOperations)
169
+ throw new DdError("input operation limit exceeded");
170
+ const result = await iterator.next();
171
+ if (result.done)
172
+ return new Uint8Array();
173
+ if (result.value.byteLength > request.maxBufferBytes)
174
+ throw new DdError("input buffer limit exceeded");
175
+ pending = new Uint8Array(result.value);
176
+ consumed = 0;
177
+ if (pending.length === 0)
178
+ await yieldTurn(signal);
179
+ }
180
+ const count = Math.min(size, pending.length - consumed);
181
+ const result = new Uint8Array(pending.subarray(consumed, consumed + count));
182
+ consumed += count;
183
+ position += BigInt(count);
184
+ return result;
185
+ },
186
+ ...(streaming && stat?.type === "file" ? { async seek(offset) {
187
+ signal.throwIfAborted();
188
+ if (offset < 0n || offset > BigInt(Number.MAX_SAFE_INTEGER))
189
+ throw new DdError("input offset limit exceeded");
190
+ await closeIterator();
191
+ position = offset;
192
+ } } : {}),
193
+ async close() { closed = true; await closeIterator(); },
194
+ };
195
+ }
196
+ if (request.seek !== 0n || path !== undefined && (!request.truncate && !request.flags.has("append") || request.creation === "never")) {
197
+ throw new DdError("positioned or existing-only output: Operation not supported by the filesystem stream adapter");
198
+ }
199
+ if (path === undefined)
200
+ return {
201
+ async write(chunk) { await writeBytes(context.stdout, chunk, signal); return chunk.length; },
202
+ async close() { },
203
+ };
204
+ const capabilities = await context.fs.capabilitiesFor?.(path, { signal }) ?? context.fs.capabilities;
205
+ const flag = request.creation === "exclusive" ? request.flags.has("append") ? "ax" : "wx" : request.flags.has("append") ? "a" : "w";
206
+ if (!context.fs.writeStream || capabilities.streamingWrite === false)
207
+ throw new DdError("streaming output: Operation not supported by the filesystem");
208
+ if (request.creation === "exclusive" && capabilities.exclusiveCreate !== true)
209
+ throw new DdError("exclusive creation: Operation not supported by the filesystem");
210
+ if (request.flags.has("append") && capabilities.streamingAppend === false)
211
+ throw new DdError("streaming append: Operation not supported by the filesystem");
212
+ const fs = new Proxy(context.fs, { get(target, property) {
213
+ if (property === "writeStream")
214
+ return (destination, source, options) => target.writeStream(destination, source, { ...options, flag });
215
+ if (property === "appendFile" || property === "writeFile")
216
+ return () => { throw new FsError("ENOTSUP", { path }); };
217
+ const value = Reflect.get(target, property, target);
218
+ return typeof value === "function" ? value.bind(target) : value;
219
+ } });
220
+ const target = await openFileOutput({ ...context, fs }, path, request.creation === "exclusive" ? { flag: "wx" } : request.flags.has("append") ? "a" : "w");
221
+ let closed;
222
+ let failed;
223
+ const handle = {
224
+ async write(chunk) {
225
+ signal.throwIfAborted();
226
+ if (closed)
227
+ throw new FsError("EBADF");
228
+ try {
229
+ await target.sink.write(chunk);
230
+ }
231
+ catch (reason) {
232
+ failed ??= { reason };
233
+ throw reason;
234
+ }
235
+ return chunk.length;
236
+ },
237
+ close() {
238
+ closed ??= signal.aborted ? target.abort(signal.reason) : failed ? target.abort(failed.reason) : target.finish();
239
+ return closed;
240
+ },
241
+ };
242
+ countedHandles.add(handle);
243
+ return handle;
244
+ }
@@ -0,0 +1,184 @@
1
+ export const conversions = new Set(["ascii", "ebcdic", "ibm", "block", "unblock", "lcase", "ucase", "sparse", "swab", "sync", "noerror", "notrunc", "excl", "nocreat", "fdatasync", "fsync"]);
2
+ export const flags = new Set(["append", "binary", "text", "cio", "direct", "directory", "dsync", "noatime", "nocache", "noctty", "nofollow", "nolinks", "nonblock", "sync", "fullblock", "count_bytes", "skip_bytes", "seek_bytes"]);
3
+ const maxInteger = (1n << 63n) - 1n;
4
+ export class DdError extends Error {
5
+ usage;
6
+ warnings;
7
+ constructor(message, usage = false, warnings = []) {
8
+ super(message);
9
+ this.usage = usage;
10
+ this.warnings = warnings;
11
+ }
12
+ }
13
+ export function quote(text, style = "shell") {
14
+ if (style === "shell" && text.includes("'") && !["$", "`", "\\", '"'].some(character => text.includes(character))
15
+ && [...text].every(character => character >= " " && character <= "~"))
16
+ return `"${text}"`;
17
+ let result = "'";
18
+ let escaped = false;
19
+ const escapes = new Map([[7, "a"], [8, "b"], [9, "t"], [10, "n"], [11, "v"], [12, "f"], [13, "r"]]);
20
+ for (const byte of new TextEncoder().encode(text)) {
21
+ const special = byte < 32 || byte >= 127;
22
+ if (style === "locale") {
23
+ result += special ? `\\${escapes.get(byte) ?? byte.toString(8).padStart(3, "0")}`
24
+ : byte === 39 || byte === 92 ? `\\${String.fromCharCode(byte)}` : String.fromCharCode(byte);
25
+ continue;
26
+ }
27
+ if (special !== escaped) {
28
+ result += special ? "'$'" : "''";
29
+ escaped = special;
30
+ }
31
+ result += special ? `\\${escapes.get(byte) ?? byte.toString(8).padStart(3, "0")}`
32
+ : byte === 39 ? "'\\''" : String.fromCharCode(byte);
33
+ }
34
+ return `${result}'`;
35
+ }
36
+ function numberValue(text, warnings) {
37
+ let product = 1n;
38
+ let overflow = false;
39
+ const invalid = () => { throw new DdError(`invalid number: ${quote(text)}`, false, warnings); };
40
+ for (const factor of text.split("x")) {
41
+ let offset = 0;
42
+ while (offset < factor.length && " \t\r\n\v\f".includes(factor[offset]))
43
+ offset++;
44
+ if (factor[offset] === "+")
45
+ offset++;
46
+ const start = offset;
47
+ let value = 0n;
48
+ while (offset < factor.length && factor[offset] >= "0" && factor[offset] <= "9") {
49
+ if (value <= maxInteger)
50
+ value = value * 10n + BigInt(factor[offset]);
51
+ offset++;
52
+ }
53
+ const suffix = factor.slice(offset);
54
+ if (offset === start) {
55
+ if (!suffix || !"bcEGkKMPQRTwYZ".includes(suffix[0]))
56
+ invalid();
57
+ value = 1n;
58
+ }
59
+ let multiplier = 1n;
60
+ if (suffix === "b" || suffix === "bB")
61
+ multiplier = 512n;
62
+ else if (suffix === "w" || suffix === "wB")
63
+ multiplier = 2n;
64
+ else if (suffix !== "" && suffix !== "B" && suffix !== "c" && suffix !== "cB") {
65
+ const power = "KMGTPEZYRQ".indexOf(suffix[0].toUpperCase()) + 1;
66
+ const tail = suffix.slice(1);
67
+ if (!power || !["", "B", "iB", "D"].includes(tail) || !"kKMGTPEZYRQ".includes(suffix[0]))
68
+ invalid();
69
+ multiplier = (tail === "B" || tail === "D" ? 1000n : 1024n) ** BigInt(power);
70
+ }
71
+ value *= multiplier;
72
+ if (value > maxInteger)
73
+ overflow = true;
74
+ product *= value > maxInteger ? maxInteger + 1n : value;
75
+ if (product > maxInteger) {
76
+ overflow = true;
77
+ product = maxInteger + 1n;
78
+ }
79
+ }
80
+ for (const factor of text.split("x").slice(0, -1)) {
81
+ if (factor === "0" && product === 0n)
82
+ warnings.push("warning: '0x' is a zero multiplier; use '00x' if that is intended");
83
+ }
84
+ if (product !== 0n && overflow)
85
+ throw new DdError(`invalid number: ${quote(text)}: Value too large to be stored in data type`, false, warnings);
86
+ return product;
87
+ }
88
+ export function parseDd(args) {
89
+ for (const argument of args) {
90
+ if (argument === "--")
91
+ break;
92
+ if (argument.startsWith("--") && argument.length > 2) {
93
+ const option = argument.split("=")[0];
94
+ for (const name of ["help", "version"]) {
95
+ if (`--${name}`.startsWith(option)) {
96
+ if (argument.includes("="))
97
+ throw new DdError(`option '--${name}' doesn't allow an argument`, true);
98
+ return name;
99
+ }
100
+ }
101
+ throw new DdError(`unrecognized option \`${argument}'`, true);
102
+ }
103
+ if (argument.startsWith("-") && argument !== "-")
104
+ throw new DdError(`invalid option -- ${quote(argument[1], "locale")}`, true);
105
+ }
106
+ const plan = { ibs: 512n, obs: 512n, cbs: 0n, countBytes: false, skip: 0n, seek: 0n,
107
+ skipBytes: false, seekBytes: false, convert: new Set(), inputFlags: new Set(), outputFlags: new Set(),
108
+ status: "default", twoBuffers: true, warnings: [] };
109
+ let blockSize;
110
+ let delimiter = false;
111
+ for (const argument of args) {
112
+ if (argument === "--" && !delimiter) {
113
+ delimiter = true;
114
+ continue;
115
+ }
116
+ const boundary = argument.indexOf("=");
117
+ const name = argument.slice(0, boundary), value = argument.slice(boundary + 1);
118
+ if (boundary < 0)
119
+ throw new DdError(`unrecognized operand ${quote(argument)}`, true, plan.warnings);
120
+ if (name === "if")
121
+ plan.input = value;
122
+ else if (name === "of")
123
+ plan.output = value;
124
+ else if (["conv", "iflag", "oflag", "status"].includes(name)) {
125
+ const allowed = name === "conv" ? conversions : name === "status" ? new Set(["none", "noxfer", "progress"]) : flags;
126
+ const category = name === "conv" ? "conversion" : name === "status" ? "status level" : name === "iflag" ? "input flag" : "output flag";
127
+ for (const symbol of value.split(",")) {
128
+ if (!allowed.has(symbol) || name === "oflag" && symbol === "fullblock")
129
+ throw new DdError(`invalid ${category}: ${quote(symbol, "locale")}`, true, plan.warnings);
130
+ if (name === "status")
131
+ plan.status = symbol;
132
+ else
133
+ (name === "conv" ? plan.convert : name === "iflag" ? plan.inputFlags : plan.outputFlags).add(symbol);
134
+ }
135
+ }
136
+ else {
137
+ if (!["bs", "ibs", "obs", "cbs", "count", "skip", "iseek", "seek", "oseek"].includes(name)) {
138
+ throw new DdError(`unrecognized operand ${quote(argument)}`, true, plan.warnings);
139
+ }
140
+ const number = numberValue(value, plan.warnings);
141
+ if (["bs", "ibs", "obs", "cbs"].includes(name) && number === 0n)
142
+ throw new DdError(`invalid number: ${quote(value)}`, false, plan.warnings);
143
+ if (["bs", "ibs", "obs"].includes(name) && number === maxInteger)
144
+ throw new DdError(`invalid number: ${quote(value)}: Value too large to be stored in data type`, false, plan.warnings);
145
+ if (name === "bs")
146
+ blockSize = number;
147
+ else if (name === "ibs" || name === "obs" || name === "cbs")
148
+ plan[name] = number;
149
+ else if (name === "count") {
150
+ plan.count = number;
151
+ plan.countBytes = value.includes("B");
152
+ }
153
+ else if (name === "skip" || name === "iseek") {
154
+ plan.skip = number;
155
+ plan.skipBytes = value.includes("B");
156
+ }
157
+ else {
158
+ plan.seek = number;
159
+ plan.seekBytes = value.includes("B");
160
+ }
161
+ }
162
+ }
163
+ if (blockSize !== undefined)
164
+ plan.ibs = plan.obs = blockSize;
165
+ plan.twoBuffers = blockSize === undefined || [...plan.convert].some(value => ["ascii", "ebcdic", "ibm", "block", "unblock", "lcase", "ucase", "swab"].includes(value));
166
+ if (plan.convert.has("ascii"))
167
+ plan.convert.add("unblock");
168
+ if (plan.convert.has("ebcdic") || plan.convert.has("ibm"))
169
+ plan.convert.add("block");
170
+ if (plan.cbs === 0n) {
171
+ plan.convert.delete("block");
172
+ plan.convert.delete("unblock");
173
+ }
174
+ for (const group of [["ascii", "ebcdic", "ibm"], ["block", "unblock"], ["lcase", "ucase"], ["excl", "nocreat"]]) {
175
+ if (group.filter(value => plan.convert.has(value)).length > 1)
176
+ throw new DdError(`cannot combine ${group.length === 3 ? "any two of {ascii,ebcdic,ibm}" : group.join(" and ")}`, false, plan.warnings);
177
+ }
178
+ if ([plan.inputFlags, plan.outputFlags].some(values => values.has("direct") && values.has("nocache")))
179
+ throw new DdError("cannot combine direct and nocache", false, plan.warnings);
180
+ plan.countBytes ||= plan.inputFlags.has("count_bytes");
181
+ plan.skipBytes ||= plan.inputFlags.has("skip_bytes");
182
+ plan.seekBytes ||= plan.outputFlags.has("seek_bytes");
183
+ return plan;
184
+ }
@@ -0,0 +1,69 @@
1
+ import { writeBytes } from "@poe-platform/safe-bash/contracts/io";
2
+ function human(value, base) {
3
+ let exponent = 0;
4
+ while (value >= base && exponent < 10) {
5
+ value /= base;
6
+ exponent++;
7
+ }
8
+ if (Math.round(value) >= base && exponent < 10) {
9
+ value /= base;
10
+ exponent++;
11
+ }
12
+ const tenths = Math.round(value * 10);
13
+ const number = exponent > 0 && tenths < 100 ? (tenths / 10).toFixed(1) : Math.round(value).toString();
14
+ const unit = exponent === 0 ? "B" : `${(base === 1000 ? "kMGTPEZYRQ" : "KMGTPEZYRQ")[exponent - 1]}${base === 1024 ? "i" : ""}B`;
15
+ return `${number} ${unit}`;
16
+ }
17
+ export function transferReport(bytes, elapsedMs, progress = false) {
18
+ const seconds = Math.max(0, elapsedMs) / 1000;
19
+ const size = Number(bytes);
20
+ const decimal = human(size, 1000), binary = human(size, 1024);
21
+ const suffix = size < 1000 ? "" : size < 1024 ? ` (${decimal})` : ` (${decimal}, ${binary})`;
22
+ const rounded = Number(seconds.toPrecision(6));
23
+ let elapsed = progress ? Math.round(seconds).toString() : rounded.toString();
24
+ if (!progress && rounded && (rounded < 0.0001 || rounded >= 1000000)) {
25
+ const [significand, exponent] = rounded.toExponential().split("e");
26
+ const power = Number(exponent);
27
+ elapsed = `${significand}e${power < 0 ? "-" : "+"}${Math.abs(power).toString().padStart(2, "0")}`;
28
+ }
29
+ const rate = seconds > 0 ? `${human(size / seconds, 1000)}/s` : "Infinity B/s";
30
+ return `${bytes} ${bytes === 1n ? "byte" : "bytes"}${suffix} copied, ${elapsed} s, ${rate}`;
31
+ }
32
+ export class DdReporter {
33
+ context;
34
+ status;
35
+ now;
36
+ stats = { inputFull: 0n, inputPartial: 0n, outputFull: 0n, outputPartial: 0n, truncated: 0n, bytes: 0n };
37
+ start;
38
+ next = 1000;
39
+ progressLength = 0;
40
+ constructor(context, status, now) {
41
+ this.context = context;
42
+ this.status = status;
43
+ this.now = now;
44
+ this.start = now();
45
+ }
46
+ async progress() {
47
+ if (this.status !== "progress")
48
+ return;
49
+ const elapsed = this.now() - this.start;
50
+ if (elapsed < this.next)
51
+ return;
52
+ this.next += 1000;
53
+ const line = transferReport(this.stats.bytes, elapsed, true);
54
+ await writeBytes(this.context.stderr, new TextEncoder().encode(`\r${line}${" ".repeat(Math.max(0, this.progressLength - line.length))}`), this.context.signal);
55
+ this.progressLength = line.length;
56
+ }
57
+ async report() {
58
+ if (this.status === "none")
59
+ return;
60
+ let text = this.progressLength ? "\n" : "";
61
+ this.progressLength = 0;
62
+ text += `${this.stats.inputFull}+${this.stats.inputPartial} records in\n${this.stats.outputFull}+${this.stats.outputPartial} records out\n`;
63
+ if (this.stats.truncated)
64
+ text += `${this.stats.truncated} truncated record${this.stats.truncated === 1n ? "" : "s"}\n`;
65
+ if (this.status !== "noxfer")
66
+ text += `${transferReport(this.stats.bytes, this.now() - this.start)}\n`;
67
+ await writeBytes(this.context.stderr, new TextEncoder().encode(text), this.context.signal);
68
+ }
69
+ }