@poe-platform/safe-bash 0.1.788 → 0.1.789

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 (180) hide show
  1. package/README.md +1 -1
  2. package/dist/safe-bash/chunks/{chunk-WHURJBET.js → chunk-2MUJ7RLZ.js} +1 -1
  3. package/dist/safe-bash/chunks/{chunk-PYTLIUST.js → chunk-CTUHLNJM.js} +2 -2
  4. package/dist/safe-bash/chunks/{chunk-Z3HX3ZBA.js → chunk-D4PHJK4T.js} +1 -1
  5. package/dist/safe-bash/chunks/{chunk-O6356Z27.js → chunk-H7MMJS26.js} +2 -2
  6. package/dist/safe-bash/chunks/{chunk-Q3E6C3DX.js → chunk-KHJGUF2W.js} +14 -0
  7. package/dist/safe-bash/chunks/{chunk-FJZNUUOQ.js → chunk-VUVKC6HV.js} +1 -1
  8. package/dist/safe-bash/chunks/{chunk-ZMYVCRAF.js → chunk-X5ZCECM6.js} +2 -2
  9. package/dist/safe-bash/chunks/{git-UFNPAOYZ.js → git-HO7WDPHZ.js} +2 -2
  10. package/dist/safe-bash/command-chunks/{chunk-PFBJR2PY.js → chunk-2KRKKW5S.js} +2 -2
  11. package/dist/safe-bash/command-chunks/{chunk-4DSJDVBM.js → chunk-32F3RBUW.js} +10 -749
  12. package/dist/safe-bash/command-chunks/{chunk-L3MLMXL4.js → chunk-3ZK5F23O.js} +1 -1
  13. package/dist/safe-bash/command-chunks/{chunk-4QX6XCDD.js → chunk-4RNIZ3RT.js} +79 -0
  14. package/dist/safe-bash/command-chunks/{chunk-D7TADAYG.js → chunk-64LG3EVJ.js} +17 -0
  15. package/dist/safe-bash/command-chunks/{chunk-JUDOV5MJ.js → chunk-6F7QJMJ3.js} +1 -1
  16. package/dist/safe-bash/command-chunks/{chunk-IJ3FXP4Q.js → chunk-A3ZX6SCY.js} +1 -1
  17. package/dist/safe-bash/command-chunks/{chunk-YNT4ZJHW.js → chunk-AT6ZSOE6.js} +3 -3
  18. package/dist/safe-bash/command-chunks/{chunk-KSIGF4AG.js → chunk-BK4CMEE6.js} +1 -1
  19. package/dist/safe-bash/command-chunks/{chunk-XGMWWUHV.js → chunk-CZ5DAK4K.js} +1 -1
  20. package/dist/safe-bash/command-chunks/{chunk-Z57TV6TC.js → chunk-EZ2DTOLI.js} +4 -2
  21. package/dist/safe-bash/command-chunks/{chunk-ADCGH6A7.js → chunk-FH3D75FC.js} +1 -1
  22. package/dist/safe-bash/command-chunks/{chunk-WYJTWJZ5.js → chunk-G3G6W5ZE.js} +1 -1
  23. package/dist/safe-bash/command-chunks/{chunk-3HDIDEUJ.js → chunk-GF54KE2M.js} +1 -1
  24. package/dist/safe-bash/command-chunks/{chunk-Z7TYZG3A.js → chunk-IHHTTQX6.js} +5 -3
  25. package/dist/safe-bash/command-chunks/{chunk-INDIFLBW.js → chunk-JTAGNROA.js} +4 -0
  26. package/dist/safe-bash/command-chunks/chunk-PGEYORBZ.js +25 -0
  27. package/dist/safe-bash/command-chunks/chunk-QM4UZF3C.js +753 -0
  28. package/dist/safe-bash/command-chunks/{chunk-TOSM3T3A.js → chunk-UJOO6DKY.js} +20 -9
  29. package/dist/safe-bash/command-chunks/{chunk-2LP3VMPA.js → chunk-WFDW4XXD.js} +1 -17
  30. package/dist/safe-bash/command-chunks/chunk-WR37IS4O.js +318 -0
  31. package/dist/safe-bash/command-chunks/{chunk-Y5IHIAY3.js → chunk-XNHSCU6I.js} +7 -3
  32. package/dist/safe-bash/commands/basic.js +148 -48
  33. package/dist/safe-bash/commands/bytes/compression/index.js +5 -6
  34. package/dist/safe-bash/commands/cmp.d.ts +2 -3
  35. package/dist/safe-bash/commands/cmp.js +2 -689
  36. package/dist/safe-bash/commands/docx/index.browser.js +3 -46
  37. package/dist/safe-bash/commands/docx/index.d.ts +2 -24
  38. package/dist/safe-bash/commands/docx/index.js +2 -41
  39. package/dist/safe-bash/commands/docx/io.d.ts +1 -14
  40. package/dist/safe-bash/commands/docx/io.js +1 -15
  41. package/dist/safe-bash/commands/llm/index.browser.js +3 -3
  42. package/dist/safe-bash/commands/network/index.browser.js +3 -3
  43. package/dist/safe-bash/commands/node/index.browser.js +3 -3
  44. package/dist/safe-bash/commands/pptx/index.d.ts +2 -28
  45. package/dist/safe-bash/commands/pptx/index.js +2 -152
  46. package/dist/safe-bash/commands/printf-float.d.ts +1 -0
  47. package/dist/safe-bash/commands/printf-float.js +48 -38
  48. package/dist/safe-bash/commands/printf-format.js +9 -6
  49. package/dist/safe-bash/commands/printf-quote.d.ts +3 -0
  50. package/dist/safe-bash/commands/printf-quote.js +62 -0
  51. package/dist/safe-bash/commands/printf-wide.d.ts +5 -0
  52. package/dist/safe-bash/commands/printf-wide.js +41 -0
  53. package/dist/safe-bash/commands/python/index.browser.js +2 -2
  54. package/dist/safe-bash/commands/truncate.d.ts +2 -3
  55. package/dist/safe-bash/commands/truncate.js +2 -686
  56. package/dist/safe-bash/contracts/diagnostics.d.ts +2 -0
  57. package/dist/safe-bash/contracts/diagnostics.js +2 -0
  58. package/dist/safe-bash/contracts/runtime-control.d.ts +2 -0
  59. package/dist/safe-bash/contracts/runtime-control.js +2 -0
  60. package/dist/safe-bash/core.browser.d.ts +1 -1
  61. package/dist/safe-bash/core.browser.js +2651 -4871
  62. package/dist/safe-bash/core.d.ts +10 -0
  63. package/dist/safe-bash/opt-in/commands/cmp/index.d.ts +6 -2
  64. package/dist/safe-bash/opt-in/commands/cmp/index.js +776 -79
  65. package/dist/safe-bash/opt-in/commands/cmp/options.d.ts +0 -12
  66. package/dist/safe-bash/opt-in/commands/cmp/options.js +0 -153
  67. package/dist/safe-bash/opt-in/commands/truncate/index.d.ts +8 -3
  68. package/dist/safe-bash/opt-in/commands/truncate/index.js +790 -272
  69. package/dist/safe-bash/opt-in/commands/truncate/sync.d.ts +1 -0
  70. package/dist/safe-bash/opt-in/commands/truncate/sync.js +60 -0
  71. package/dist/safe-bash/optional-host.browser.js +9 -1
  72. package/dist/safe-bash/optional-host.d.ts +3 -1
  73. package/dist/safe-bash/optional-host.js +3 -1
  74. package/dist/safe-bash/shell/runtime.js +10 -6
  75. package/dist/safe-bash-checksum-engine/index.d.ts +1 -1
  76. package/dist/safe-bash-checksum-engine/index.js +14 -2
  77. package/dist/safe-bash-command-bzip2/index.js +2 -1
  78. package/dist/safe-bash-command-cmp/index.d.ts +10 -0
  79. package/dist/safe-bash-command-cmp/index.js +796 -0
  80. package/dist/safe-bash-command-cmp/options.d.ts +12 -0
  81. package/dist/safe-bash-command-cmp/options.js +42 -0
  82. package/dist/safe-bash-command-csvcut/index.js +11 -8
  83. package/dist/safe-bash-command-csvgrep/index.js +35 -7
  84. package/dist/safe-bash-command-csvkit/codecs/python.js +4 -3
  85. package/dist/safe-bash-command-csvkit/codecs/utf8.js +3 -2
  86. package/dist/safe-bash-command-csvkit/index.js +80 -324
  87. package/dist/safe-bash-command-csvkit/python-regex.d.ts +5 -0
  88. package/dist/safe-bash-command-csvkit/python-regex.js +14 -0
  89. package/dist/safe-bash-command-csvkit/runtime.d.ts +1 -0
  90. package/dist/safe-bash-command-csvkit/sync-support.js +4 -2
  91. package/dist/safe-bash-command-diff3/index.js +3 -0
  92. package/dist/safe-bash-command-docx/LICENSE +21 -0
  93. package/dist/safe-bash-command-docx/index.d.ts +30 -0
  94. package/dist/safe-bash-command-docx/index.js +67 -0
  95. package/dist/safe-bash-command-docx/io.d.ts +14 -0
  96. package/dist/safe-bash-command-docx/io.js +26 -0
  97. package/dist/safe-bash-command-envsubst/index.js +34 -3
  98. package/dist/safe-bash-command-exiftool/index.js +3 -0
  99. package/dist/safe-bash-command-ffmpeg/index.js +1102 -1088
  100. package/dist/safe-bash-command-fold/family.js +1 -1
  101. package/dist/safe-bash-command-fold/index.js +1 -1
  102. package/dist/safe-bash-command-htmlq/index.js +5 -0
  103. package/dist/safe-bash-command-imagemagick/index.d.ts +25 -21
  104. package/dist/safe-bash-command-imagemagick/index.js +669 -271
  105. package/dist/safe-bash-command-mmdc/index.js +48 -10
  106. package/dist/safe-bash-command-mmdc/svg.d.ts +1 -0
  107. package/dist/safe-bash-command-op/index.js +19 -14
  108. package/dist/safe-bash-command-pandoc/command.js +1 -1
  109. package/dist/safe-bash-command-pandoc/index.js +1 -1
  110. package/dist/safe-bash-command-pdfimages/index.d.ts +7 -1
  111. package/dist/safe-bash-command-pdfimages/index.js +63 -33
  112. package/dist/safe-bash-command-pdfinfo/index.d.ts +24 -20
  113. package/dist/safe-bash-command-pdfinfo/index.js +370 -161
  114. package/dist/safe-bash-command-pdftk/index.d.ts +7 -3
  115. package/dist/safe-bash-command-pdftk/index.js +114 -45
  116. package/dist/safe-bash-command-pdftoppm/index.d.ts +15 -7
  117. package/dist/safe-bash-command-pdftoppm/index.js +179 -109
  118. package/dist/safe-bash-command-pdftotext/index.d.ts +9 -5
  119. package/dist/safe-bash-command-pdftotext/index.js +90 -27
  120. package/dist/safe-bash-command-pptx/LICENSE +21 -0
  121. package/dist/safe-bash-command-pptx/index.d.ts +33 -0
  122. package/dist/safe-bash-command-pptx/index.js +168 -0
  123. package/dist/safe-bash-command-qpdf/index.d.ts +9 -3
  124. package/dist/safe-bash-command-qpdf/index.js +80 -29
  125. package/dist/safe-bash-command-sha512sum/index.js +12 -475
  126. package/dist/safe-bash-command-sips/index.d.ts +9 -5
  127. package/dist/safe-bash-command-sips/index.js +63 -44
  128. package/dist/safe-bash-command-soffice/index.d.ts +9 -3
  129. package/dist/safe-bash-command-soffice/index.js +65 -24
  130. package/dist/safe-bash-command-sqlite3/engine.d.ts +9 -0
  131. package/dist/safe-bash-command-sqlite3/index.d.ts +1 -0
  132. package/dist/safe-bash-command-sqlite3/index.js +851 -352
  133. package/dist/safe-bash-command-ssconvert/formats/xls.js +3 -3
  134. package/dist/safe-bash-command-timeout/index.js +3 -3
  135. package/dist/safe-bash-command-truncate/index.d.ts +8 -3
  136. package/dist/safe-bash-command-truncate/index.js +790 -272
  137. package/dist/safe-bash-command-truncate/sync.d.ts +1 -0
  138. package/dist/safe-bash-command-truncate/sync.js +60 -0
  139. package/dist/safe-bash-command-wkhtmltopdf/index.js +92 -38
  140. package/dist/safe-bash-command-wkhtmltopdf/pdf-renderer.d.ts +1 -1
  141. package/dist/safe-bash-command-xxd/index.js +78 -20
  142. package/dist/safe-bash-command-xz/command.d.ts +4 -0
  143. package/dist/safe-bash-command-xz/index.d.ts +1 -1
  144. package/dist/safe-bash-command-xz/index.js +1 -1
  145. package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
  146. package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
  147. package/dist/safe-bash-compression-engine/files.js +6 -6
  148. package/dist/safe-bash-compression-engine/index.js +5 -5
  149. package/dist/safe-bash-compression-engine/operand.js +6 -6
  150. package/dist/safe-bash-compression-engine/stream.js +5 -5
  151. package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
  152. package/dist/safe-bash-contracts/command.js +3 -3
  153. package/dist/safe-bash-contracts/diagnostics.js +3 -3
  154. package/dist/safe-bash-contracts/escaping.js +9 -9
  155. package/dist/safe-bash-contracts/filesystem-descriptor.js +3 -3
  156. package/dist/safe-bash-contracts/filesystem-output.js +8 -8
  157. package/dist/safe-bash-contracts/index.js +21 -19
  158. package/dist/safe-bash-contracts/io.d.ts +12 -0
  159. package/dist/safe-bash-contracts/io.js +4 -1
  160. package/dist/safe-bash-contracts/output.js +3 -2
  161. package/dist/safe-bash-contracts/runtime-control.js +2 -2
  162. package/dist/safe-bash-contracts/signals.js +1 -1
  163. package/dist/safe-bash-contracts/yield.d.ts +1 -0
  164. package/dist/safe-bash-contracts/yield.js +3 -1
  165. package/dist/safe-bash-csv-engine/index.d.ts +10 -1
  166. package/dist/safe-bash-csv-engine/index.js +78 -6
  167. package/dist/safe-bash-io-engine/commands/search/requirements.js +3 -3
  168. package/dist/safe-bash-io-engine/commands/text-programs/shared.js +3 -3
  169. package/dist/safe-bash-io-engine/gnu-information.js +1 -1
  170. package/dist/safe-bash-io-engine/internal.d.ts +1 -1
  171. package/dist/safe-bash-io-engine/internal.js +2 -2
  172. package/dist/safe-bash-query-engine/index.js +4 -4
  173. package/dist/safe-bash-query-engine/interpreter.js +2 -2
  174. package/dist/safe-bash-query-engine/query-core.js +4 -4
  175. package/package.json +2 -2
  176. package/dist/safe-bash/opt-in/commands/cmp/compare.js +0 -95
  177. package/dist/safe-bash/opt-in/commands/cmp/io.js +0 -218
  178. package/dist/safe-bash/command-chunks/{chunk-FXYWQ6S4.js → chunk-2VTMZTV3.js} +0 -0
  179. package/dist/safe-bash/command-chunks/{chunk-RTOJNFFL.js → chunk-BJ6DGYJA.js} +4 -4
  180. package/dist/safe-bash/command-chunks/{chunk-DEH3CMGL.js → chunk-QJ3ONEBI.js} +3 -3
@@ -4,6 +4,7 @@ import {
4
4
 
5
5
  // packages/safe-bash-csv-engine/dist/index.js
6
6
  init_buffer();
7
+ import { yieldTurn } from "../safe-bash-contracts/yield.js";
7
8
  var CsvError = class extends Error {
8
9
  code;
9
10
  constructor(code, message) {
@@ -28,6 +29,7 @@ var defaultCsvLimits = Object.freeze({
28
29
  var CsvBudget = class {
29
30
  signal;
30
31
  disposed = false;
32
+ lastYieldWork = 0;
31
33
  aborted = false;
32
34
  pollSignal;
33
35
  limits;
@@ -52,6 +54,14 @@ var CsvBudget = class {
52
54
  getUsage(key) {
53
55
  return this.usage[key];
54
56
  }
57
+ async checkpoint() {
58
+ this.signal.throwIfAborted();
59
+ if (this.usage.work - this.lastYieldWork < 4096)
60
+ return;
61
+ this.lastYieldWork = this.usage.work;
62
+ await yieldTurn(this.signal);
63
+ this.signal.throwIfAborted();
64
+ }
55
65
  remaining(key) {
56
66
  return this.limits[key] - this.usage[key];
57
67
  }
@@ -135,7 +145,10 @@ var typedArrayByteLength = Object.getOwnPropertyDescriptor(Object.getPrototypeOf
135
145
  var CsvParser = class {
136
146
  dialect;
137
147
  budget;
138
- decoder = new TextDecoder("utf-8", { fatal: true });
148
+ decoder;
149
+ encoding;
150
+ fieldCharacters = 0;
151
+ quotedField = false;
139
152
  delimiter;
140
153
  field = "";
141
154
  row = [];
@@ -151,12 +164,18 @@ var CsvParser = class {
151
164
  this.dialect = dialect;
152
165
  this.budget = budget;
153
166
  this.dialect = Object.freeze({ ...dialect });
167
+ this.encoding = (dialect.encoding ?? "utf-8-sig").toLowerCase().replaceAll("_", "-");
168
+ if (!["utf-8-sig", "utf8-sig", "utf-8", "utf8", "ascii", "us-ascii", "latin1", "latin-1", "iso-8859-1"].includes(this.encoding))
169
+ throw new CsvError("UNSUPPORTED", "Unsupported CSV encoding");
170
+ this.decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: !["utf-8-sig", "utf8-sig"].includes(this.encoding) });
171
+ if (dialect.fieldCharacters !== void 0 && (!Number.isSafeInteger(dialect.fieldCharacters) || dialect.fieldCharacters < 0))
172
+ throw new CsvError("ARGUMENT", "Field size must be a nonnegative safe integer");
154
173
  this.delimiter = dialect.tabs ? " " : dialect.delimiter ?? ",";
155
174
  budget.charge("work", 0);
156
175
  if (dialect.profile !== void 0 && dialect.profile !== "utf8-sig-permissive-v1" && dialect.profile !== "utf8-sig-strict-v1")
157
176
  throw new CsvError("UNSUPPORTED", "Unsupported CSV reader profile");
158
- if (dialect.quoting !== void 0 && dialect.quoting !== 0 && dialect.quoting !== 3)
159
- throw new CsvError("UNSUPPORTED", "Only quoting modes 0 and 3 are qualified");
177
+ if (dialect.quoting !== void 0 && ![0, 1, 2, 3].includes(dialect.quoting))
178
+ throw new CsvError("UNSUPPORTED", "Only quoting modes 0, 1, 2 and 3 are supported");
160
179
  for (const char of [
161
180
  this.delimiter,
162
181
  dialect.quote ?? '"',
@@ -169,6 +188,14 @@ var CsvParser = class {
169
188
  if (dialect.skipLines !== void 0 && (!Number.isSafeInteger(dialect.skipLines) || dialect.skipLines < 0))
170
189
  throw new CsvError("ARGUMENT", "Skip lines must be nonnegative");
171
190
  }
191
+ /** Consume a borrowed producer chunk in bounded units before its next pull. */
192
+ async *pushAsync(bytes) {
193
+ for (let offset = 0; offset < bytes.byteLength; offset += 4096) {
194
+ await yieldTurn(this.budget.signal);
195
+ this.budget.signal.throwIfAborted();
196
+ yield* this.push(bytes.subarray(offset, offset + 4096));
197
+ }
198
+ }
172
199
  push(bytes) {
173
200
  if (this.ended)
174
201
  throw new CsvError("INPUT", "CSV parser is closed");
@@ -184,8 +211,18 @@ var CsvParser = class {
184
211
  this.budget.charge("retainedBytes", byteLength * 2 + 8);
185
212
  let text;
186
213
  try {
187
- text = this.decoder.decode(bytes, { stream: true });
188
- } catch {
214
+ if (["ascii", "us-ascii", "latin1", "latin-1", "iso-8859-1"].includes(this.encoding)) {
215
+ text = "";
216
+ for (const byte of bytes) {
217
+ if ((this.encoding === "ascii" || this.encoding === "us-ascii") && byte > 127)
218
+ throw new CsvError("INPUT", "Invalid ASCII input");
219
+ text += String.fromCharCode(byte);
220
+ }
221
+ } else
222
+ text = this.decoder.decode(bytes, { stream: true });
223
+ } catch (error) {
224
+ if (error instanceof CsvError)
225
+ throw error;
189
226
  throw new CsvError("INPUT", "Invalid UTF-8 input");
190
227
  }
191
228
  this.budget.charge("decodedBytes", text.length * 2);
@@ -223,13 +260,46 @@ var CsvParser = class {
223
260
  this.active = false;
224
261
  }
225
262
  append(char) {
263
+ if (++this.fieldCharacters > (this.dialect.fieldCharacters ?? Infinity))
264
+ throw new CsvError("INPUT", "Field character limit exceeded");
226
265
  this.budget.chargeAppend(this.field.length + char.length);
227
266
  this.field += char;
228
267
  }
229
268
  finishField() {
230
269
  this.budget.charge("cells", 1);
231
270
  this.budget.charge("retainedBytes", 32);
232
- this.row.push(this.field);
271
+ let value = this.field;
272
+ if (this.dialect.quoting === 2 && !this.quotedField && value.length) {
273
+ this.budget.charge("work", value.length);
274
+ const raw = value.trim().toLowerCase();
275
+ const unsigned = raw.startsWith("+") || raw.startsWith("-") ? raw.slice(1) : raw;
276
+ const negative = raw.startsWith("-");
277
+ if (["inf", "infinity", "nan"].includes(unsigned))
278
+ value = unsigned === "nan" ? "nan" : negative ? "-inf" : "inf";
279
+ else {
280
+ const digit = (char) => char !== void 0 && char >= "0" && char <= "9";
281
+ for (let i = 0; i < raw.length; i++) {
282
+ const char = raw[i];
283
+ if (char === "_" && !(digit(raw[i - 1]) && digit(raw[i + 1])) || !digit(char) && !".+-e_".includes(char))
284
+ throw new CsvError("INPUT", "Could not convert unquoted field to float");
285
+ }
286
+ const number = Number(raw.replaceAll("_", ""));
287
+ if (!raw || Number.isNaN(number))
288
+ throw new CsvError("INPUT", "Could not convert unquoted field to float");
289
+ const absolute = Math.abs(number);
290
+ if (!Number.isFinite(number))
291
+ value = number < 0 ? "-inf" : "inf";
292
+ else if (absolute !== 0 && (absolute < 1e-4 || absolute >= 1e16)) {
293
+ const [mantissa, exponent] = number.toExponential().split("e");
294
+ value = mantissa + "e" + exponent[0] + exponent.slice(1).padStart(2, "0");
295
+ } else
296
+ value = Object.is(number, -0) ? "-0.0" : Number.isInteger(number) ? number.toFixed(1) : String(number);
297
+ }
298
+ this.budget.charge("retainedBytes", value.length * 2);
299
+ }
300
+ this.row.push(value);
301
+ this.fieldCharacters = 0;
302
+ this.quotedField = false;
233
303
  this.field = "";
234
304
  this.state = "start";
235
305
  }
@@ -296,6 +366,7 @@ var CsvParser = class {
296
366
  if (this.state === "closed" && char === quote && this.dialect.doubleQuote !== false) {
297
367
  this.append(char);
298
368
  this.state = "quoted";
369
+ this.quotedField = true;
299
370
  continue;
300
371
  }
301
372
  if (this.dialect.profile === "utf8-sig-strict-v1" && this.state === "closed" && !newline && char !== this.delimiter)
@@ -315,6 +386,7 @@ var CsvParser = class {
315
386
  continue;
316
387
  if (this.state === "start" && char === quote) {
317
388
  this.state = "quoted";
389
+ this.quotedField = true;
318
390
  continue;
319
391
  }
320
392
  if (this.dialect.profile === "utf8-sig-strict-v1" && char === quote)
@@ -5,10 +5,10 @@ import {
5
5
  requiredFileInput,
6
6
  searchRequirements,
7
7
  sedRequirements
8
- } from "../../../safe-bash/command-chunks/chunk-JUDOV5MJ.js";
9
- import "../../../safe-bash/command-chunks/chunk-TOSM3T3A.js";
8
+ } from "../../../safe-bash/command-chunks/chunk-6F7QJMJ3.js";
9
+ import "../../../safe-bash/command-chunks/chunk-UJOO6DKY.js";
10
10
  import "../../../safe-bash/command-chunks/chunk-OTYUNKT5.js";
11
- import "../../../safe-bash/command-chunks/chunk-Y5IHIAY3.js";
11
+ import "../../../safe-bash/command-chunks/chunk-XNHSCU6I.js";
12
12
  import "../../../safe-bash/command-chunks/chunk-YAFQG4SC.js";
13
13
  import "../../../safe-bash/command-chunks/chunk-3746OSHN.js";
14
14
  import "../../../safe-bash/command-chunks/chunk-HX3SHTCE.js";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  requiredFileInput
3
- } from "../../../safe-bash/command-chunks/chunk-JUDOV5MJ.js";
3
+ } from "../../../safe-bash/command-chunks/chunk-6F7QJMJ3.js";
4
4
  import {
5
5
  RESOLVED_EXIT_ONE,
6
6
  RESOLVED_EXIT_ZERO,
7
7
  builtInDirectContextExecutors
8
- } from "../../../safe-bash/command-chunks/chunk-TOSM3T3A.js";
8
+ } from "../../../safe-bash/command-chunks/chunk-UJOO6DKY.js";
9
9
  import "../../../safe-bash/command-chunks/chunk-OTYUNKT5.js";
10
- import "../../../safe-bash/command-chunks/chunk-Y5IHIAY3.js";
10
+ import "../../../safe-bash/command-chunks/chunk-XNHSCU6I.js";
11
11
  import {
12
12
  inputRequirements
13
13
  } from "../../../safe-bash/command-chunks/chunk-YAFQG4SC.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  gnuInformation,
3
3
  gnuInformationSync
4
- } from "../safe-bash/command-chunks/chunk-Y5IHIAY3.js";
4
+ } from "../safe-bash/command-chunks/chunk-XNHSCU6I.js";
5
5
  import "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
6
6
  export {
7
7
  gnuInformation,
@@ -121,7 +121,7 @@ export declare function replaceArgument(source: string | Uint8Array, pattern: st
121
121
  export declare function escapeBytes(text: string | Uint8Array, zeroOctal?: boolean, bareOctal?: boolean, unicode?: {
122
122
  utf8: boolean;
123
123
  missingDigit: (escape: string) => void;
124
- }): {
124
+ }, literalFormat?: boolean): {
125
125
  bytes: Uint8Array;
126
126
  stop: boolean;
127
127
  };
@@ -44,9 +44,9 @@ import {
44
44
  requireOperands,
45
45
  syncCommandEvaluators,
46
46
  value
47
- } from "../safe-bash/command-chunks/chunk-TOSM3T3A.js";
47
+ } from "../safe-bash/command-chunks/chunk-UJOO6DKY.js";
48
48
  import "../safe-bash/command-chunks/chunk-OTYUNKT5.js";
49
- import "../safe-bash/command-chunks/chunk-Y5IHIAY3.js";
49
+ import "../safe-bash/command-chunks/chunk-XNHSCU6I.js";
50
50
  import "../safe-bash/command-chunks/chunk-YAFQG4SC.js";
51
51
  import "../safe-bash/command-chunks/chunk-3746OSHN.js";
52
52
  import "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  YqValueFailure,
3
3
  createYqQuerySession
4
- } from "../safe-bash/command-chunks/chunk-YNT4ZJHW.js";
5
- import "../safe-bash/command-chunks/chunk-RTOJNFFL.js";
4
+ } from "../safe-bash/command-chunks/chunk-AT6ZSOE6.js";
5
+ import "../safe-bash/command-chunks/chunk-JUMF6JDJ.js";
6
+ import "../safe-bash/command-chunks/chunk-BJ6DGYJA.js";
6
7
  import "../safe-bash/command-chunks/chunk-5PM5TEPM.js";
7
8
  import "../safe-bash/command-chunks/chunk-CXMOCPPH.js";
8
9
  import "../safe-bash/command-chunks/chunk-3KROFHBT.js";
10
+ import "../safe-bash/command-chunks/chunk-SNXWY3KV.js";
9
11
  import "../safe-bash/command-chunks/chunk-VQLFJCG7.js";
10
12
  import "../safe-bash/command-chunks/chunk-HETU7MYN.js";
11
13
  import "../safe-bash/command-chunks/chunk-MYKK3Q5G.js";
12
- import "../safe-bash/command-chunks/chunk-JUMF6JDJ.js";
13
14
  import "../safe-bash/command-chunks/chunk-OYZ534IK.js";
14
15
  import "../safe-bash/command-chunks/chunk-5L62A5RO.js";
15
16
  import "../safe-bash/command-chunks/chunk-NYUMOVF2.js";
16
17
  import "../safe-bash/command-chunks/chunk-VUG324ER.js";
17
- import "../safe-bash/command-chunks/chunk-SNXWY3KV.js";
18
18
  import "../safe-bash/command-chunks/chunk-UPOI7O7Y.js";
19
19
  import "../safe-bash/command-chunks/chunk-744EDSWN.js";
20
20
  import "../safe-bash/command-chunks/chunk-W3UCANZ3.js";
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  Interpreter
3
- } from "../safe-bash/command-chunks/chunk-RTOJNFFL.js";
3
+ } from "../safe-bash/command-chunks/chunk-BJ6DGYJA.js";
4
4
  import "../safe-bash/command-chunks/chunk-5PM5TEPM.js";
5
5
  import "../safe-bash/command-chunks/chunk-CXMOCPPH.js";
6
6
  import "../safe-bash/command-chunks/chunk-3KROFHBT.js";
7
+ import "../safe-bash/command-chunks/chunk-SNXWY3KV.js";
7
8
  import "../safe-bash/command-chunks/chunk-VQLFJCG7.js";
8
9
  import "../safe-bash/command-chunks/chunk-HETU7MYN.js";
9
10
  import "../safe-bash/command-chunks/chunk-MYKK3Q5G.js";
@@ -11,7 +12,6 @@ import "../safe-bash/command-chunks/chunk-OYZ534IK.js";
11
12
  import "../safe-bash/command-chunks/chunk-5L62A5RO.js";
12
13
  import "../safe-bash/command-chunks/chunk-NYUMOVF2.js";
13
14
  import "../safe-bash/command-chunks/chunk-VUG324ER.js";
14
- import "../safe-bash/command-chunks/chunk-SNXWY3KV.js";
15
15
  import "../safe-bash/command-chunks/chunk-UPOI7O7Y.js";
16
16
  import "../safe-bash/command-chunks/chunk-744EDSWN.js";
17
17
  import "../safe-bash/command-chunks/chunk-W3UCANZ3.js";
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  YqValueFailure,
3
3
  createYqQuerySession
4
- } from "../safe-bash/command-chunks/chunk-YNT4ZJHW.js";
5
- import "../safe-bash/command-chunks/chunk-RTOJNFFL.js";
4
+ } from "../safe-bash/command-chunks/chunk-AT6ZSOE6.js";
5
+ import "../safe-bash/command-chunks/chunk-JUMF6JDJ.js";
6
+ import "../safe-bash/command-chunks/chunk-BJ6DGYJA.js";
6
7
  import "../safe-bash/command-chunks/chunk-5PM5TEPM.js";
7
8
  import "../safe-bash/command-chunks/chunk-CXMOCPPH.js";
8
9
  import "../safe-bash/command-chunks/chunk-3KROFHBT.js";
10
+ import "../safe-bash/command-chunks/chunk-SNXWY3KV.js";
9
11
  import "../safe-bash/command-chunks/chunk-VQLFJCG7.js";
10
12
  import "../safe-bash/command-chunks/chunk-HETU7MYN.js";
11
13
  import "../safe-bash/command-chunks/chunk-MYKK3Q5G.js";
12
- import "../safe-bash/command-chunks/chunk-JUMF6JDJ.js";
13
14
  import "../safe-bash/command-chunks/chunk-OYZ534IK.js";
14
15
  import "../safe-bash/command-chunks/chunk-5L62A5RO.js";
15
16
  import "../safe-bash/command-chunks/chunk-NYUMOVF2.js";
16
17
  import "../safe-bash/command-chunks/chunk-VUG324ER.js";
17
- import "../safe-bash/command-chunks/chunk-SNXWY3KV.js";
18
18
  import "../safe-bash/command-chunks/chunk-UPOI7O7Y.js";
19
19
  import "../safe-bash/command-chunks/chunk-744EDSWN.js";
20
20
  import "../safe-bash/command-chunks/chunk-W3UCANZ3.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-bash",
3
- "version": "0.1.788",
3
+ "version": "0.1.789",
4
4
  "description": "Extensible virtual shell with pluggable filesystems and streaming commands",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -847,7 +847,7 @@
847
847
  "access": "public"
848
848
  },
849
849
  "dependencies": {
850
- "@poe-platform/safe-fs": "0.1.788",
850
+ "@poe-platform/safe-fs": "0.1.789",
851
851
  "pdf-lib": "1.17.1",
852
852
  "@noble/hashes": "2.4.0",
853
853
  "pako": "3.0.1",
@@ -1,95 +0,0 @@
1
- import { InputError, observe } from "./io.js";
2
- import { integerMaximum, quote } from "./options.js";
3
- import { yieldTurn } from "@poe-platform/safe-bash/contracts/yield";
4
- function displayByte(byte) {
5
- const high = byte >= 128;
6
- const value = high ? byte - 128 : byte;
7
- return `${high ? "M-" : ""}${value < 32 ? `^${String.fromCharCode(value + 64)}` : value === 127 ? "^?" : String.fromCharCode(value)}`;
8
- }
9
- function remaining(input, skip) {
10
- if (input.stat?.type !== "file" || !Number.isSafeInteger(input.stat.size) || input.stat.size < 0)
11
- return undefined;
12
- const size = BigInt(input.stat.size);
13
- return skip < size ? size - skip : 0n;
14
- }
15
- export async function compare(session, args) {
16
- const left = await session.open(args.files[0]);
17
- if (args.files[0] === args.files[1] && (args.files[0] === "-" || args.skips[0] === args.skips[1] && args.skips[0] <= integerMaximum))
18
- return 0;
19
- const right = await session.open(args.files[1]);
20
- if (left.path !== undefined && right.path !== undefined && args.skips[0] === args.skips[1] && args.skips[0] <= integerMaximum
21
- && session.context.fs.compareEntry && await observe(() => session.context.fs.compareEntry(left.path, session.context.fs, right.path, { signal: session.signal }), session.signal) === "same")
22
- return 0;
23
- const sizes = [remaining(left, args.skips[0]), remaining(right, args.skips[1])];
24
- if (args.mode === "silent" && sizes[0] !== undefined && sizes[1] !== undefined && sizes[0] !== sizes[1]
25
- && (sizes[0] < sizes[1] ? sizes[0] : sizes[1]) < args.count)
26
- return 1;
27
- const comparisonBlockBytes = session.comparisonBlockBytes ?? left.stat?.ioBlockSize ?? 65536;
28
- if (!Number.isSafeInteger(comparisonBlockBytes) || comparisonBlockBytes < 1) {
29
- throw new InputError(left.name, new Error("invalid preferred I/O block size"), false);
30
- }
31
- let maximum = args.count;
32
- for (const size of sizes)
33
- if (size !== undefined && size < maximum)
34
- maximum = size;
35
- const width = maximum.toString().length;
36
- const inputs = [left, right];
37
- const cursors = inputs.map((input, index) => session.cursor(input, args.skips[index]));
38
- for (let index = 0; index < 2; index++) {
39
- const skip = args.skips[index];
40
- if (skip > integerMaximum && inputs[index].stat?.type !== "file")
41
- throw new InputError(inputs[index].name, new Error("Value too large to be stored in data type"), false);
42
- if (inputs[index].path === undefined || session.context.fs.readStream && (inputs[index].stat?.type !== "file" || inputs[index].stat.size < 0))
43
- await cursors[index].skip(skip);
44
- if (inputs[index].stat?.type === "directory")
45
- await cursors[index].available();
46
- }
47
- let compared = 0n, line = 1n, atLineStart = true, work = 0;
48
- while (true) {
49
- const remaining = args.count - compared;
50
- const requested = Number(remaining < BigInt(comparisonBlockBytes) ? remaining : BigInt(comparisonBlockBytes));
51
- const first = await cursors[0].block(requested), second = await cursors[1].block(requested);
52
- const count = Math.min(first.length, second.length);
53
- let different = false, output = "";
54
- for (let offset = 0; offset < count; offset++) {
55
- const byteLeft = first[offset], byteRight = second[offset];
56
- compared++;
57
- if (byteLeft !== byteRight) {
58
- different = true;
59
- if (args.mode === "silent")
60
- return 1;
61
- const octalLeft = byteLeft.toString(8).padStart(3, " "), octalRight = byteRight.toString(8).padStart(3, " ");
62
- if (args.mode === "first") {
63
- await session.output(`${left.name} ${right.name} differ: ${args.printBytes ? "byte" : "char"} ${compared}, line ${line}${args.printBytes ? ` is ${octalLeft} ${displayByte(byteLeft)} ${octalRight} ${displayByte(byteRight)}` : ""}\n`);
64
- return 1;
65
- }
66
- output += `${compared.toString().padStart(width, " ")} ${octalLeft} ${args.printBytes ? `${displayByte(byteLeft).padEnd(4, " ")} ` : ""}${octalRight}${args.printBytes ? ` ${displayByte(byteRight)}` : ""}\n`;
67
- if (output.length >= 16384) {
68
- await session.output(output);
69
- output = "";
70
- }
71
- }
72
- if (byteLeft === 10)
73
- line++;
74
- atLineStart = byteLeft === 10;
75
- }
76
- if (output)
77
- await session.output(output);
78
- if (first.length !== second.length) {
79
- if (args.mode !== "silent") {
80
- const name = first.length < second.length ? left.name : right.name;
81
- const extra = compared === 0n ? "which is empty" : args.mode === "all" ? `after byte ${compared}`
82
- : `after byte ${compared}, ${atLineStart ? "line" : "in line"} ${atLineStart ? line - 1n : line}`;
83
- await session.output(`cmp: EOF on ${quote(name)} ${extra}\n`, true);
84
- }
85
- return 1;
86
- }
87
- if (first.length !== comparisonBlockBytes)
88
- return different ? 1 : 0;
89
- work += count;
90
- if (work >= 65536) {
91
- await yieldTurn(session.signal);
92
- work = 0;
93
- }
94
- }
95
- }
@@ -1,218 +0,0 @@
1
- import { FsError, readBytes, resolvePath, writeBytes } from "@poe-platform/safe-bash/contracts";
2
- import { integerMaximum, pathQuote } from "./options.js";
3
- import { yieldTurn } from "@poe-platform/safe-bash/contracts/yield";
4
- export async function observe(operation, signal) {
5
- signal.throwIfAborted();
6
- return new Promise((resolve, reject) => {
7
- const abort = () => { signal.removeEventListener("abort", abort); reject(signal.reason); };
8
- signal.addEventListener("abort", abort, { once: true });
9
- Promise.resolve().then(() => { signal.throwIfAborted(); return operation(); }).then(value => {
10
- signal.removeEventListener("abort", abort);
11
- resolve(value);
12
- }, error => {
13
- signal.removeEventListener("abort", abort);
14
- reject(error);
15
- });
16
- });
17
- }
18
- export class InputError extends Error {
19
- operand;
20
- reason;
21
- opening;
22
- constructor(operand, reason, opening) {
23
- super("cmp input failure");
24
- this.operand = operand;
25
- this.reason = reason;
26
- this.opening = opening;
27
- }
28
- }
29
- const errnoMessages = {
30
- ENOENT: "No such file or directory", EACCES: "Permission denied", EPERM: "Operation not permitted",
31
- EISDIR: "Is a directory", ENOTDIR: "Not a directory", EIO: "Input/output error", EBADF: "Bad file descriptor",
32
- ELOOP: "Too many levels of symbolic links", ENAMETOOLONG: "File name too long", ENOSPC: "No space left on device",
33
- EMFILE: "Too many open files", ENFILE: "Too many open files in system", EPIPE: "Broken pipe",
34
- EOVERFLOW: "Value too large to be stored in data type", ENOTSUP: "Operation not supported", EFBIG: "File too large",
35
- };
36
- export function errorText(error) {
37
- if (error instanceof FsError)
38
- return errnoMessages[error.code] ?? error.message;
39
- return error instanceof Error ? error.message : String(error);
40
- }
41
- export class Cursor {
42
- operand;
43
- signal;
44
- maxChunkBytes;
45
- reader;
46
- chunk = new Uint8Array();
47
- offset = 0;
48
- done = false;
49
- closed;
50
- returned;
51
- untilYield = 65536;
52
- constructor(operand, source, signal, maxChunkBytes) {
53
- this.operand = operand;
54
- this.signal = signal;
55
- this.maxChunkBytes = maxChunkBytes;
56
- this.reader = readBytes({
57
- [Symbol.asyncIterator]: () => {
58
- const iterator = source[Symbol.asyncIterator]();
59
- return {
60
- next: () => iterator.next(),
61
- return: () => {
62
- this.returned ??= Promise.resolve().then(() => iterator.return ? iterator.return() : { value: undefined, done: true });
63
- return this.returned;
64
- },
65
- };
66
- },
67
- }, signal);
68
- }
69
- async available() {
70
- try {
71
- this.signal.throwIfAborted();
72
- while (!this.done && this.offset === this.chunk.length) {
73
- if (this.untilYield <= 0) {
74
- await yieldTurn(this.signal);
75
- this.untilYield = 65536;
76
- }
77
- const next = await this.reader.next();
78
- this.done = Boolean(next.done);
79
- if (next.done) {
80
- this.chunk = new Uint8Array();
81
- this.offset = 0;
82
- break;
83
- }
84
- if (next.value.byteLength > this.maxChunkBytes)
85
- throw new Error("input chunk bytes limit exceeded");
86
- this.untilYield -= Math.max(64, next.value.byteLength);
87
- this.chunk = new Uint8Array(next.value);
88
- this.offset = 0;
89
- }
90
- return this.chunk.subarray(this.offset);
91
- }
92
- catch (error) {
93
- this.signal.throwIfAborted();
94
- throw new InputError(this.operand, error, false);
95
- }
96
- }
97
- consume(count) { this.offset += count; }
98
- async block(count) {
99
- const bytes = new Uint8Array(count);
100
- let size = 0;
101
- while (size < count) {
102
- const chunk = await this.available();
103
- if (!chunk.length)
104
- break;
105
- const length = Math.min(count - size, chunk.length);
106
- bytes.set(chunk.subarray(0, length), size);
107
- this.consume(length);
108
- size += length;
109
- }
110
- return bytes.subarray(0, size);
111
- }
112
- async skip(count) {
113
- while (count > 0n) {
114
- const chunk = await this.available();
115
- if (!chunk.length)
116
- break;
117
- const amount = Number(count < BigInt(chunk.length) ? count : BigInt(chunk.length));
118
- this.consume(amount);
119
- count -= BigInt(amount);
120
- }
121
- }
122
- close() {
123
- this.closed ??= (async () => {
124
- try {
125
- await this.reader.return(undefined);
126
- await this.returned;
127
- }
128
- catch (error) {
129
- throw new InputError(this.operand, error, false);
130
- }
131
- finally {
132
- this.chunk = new Uint8Array();
133
- }
134
- })();
135
- return this.closed;
136
- }
137
- }
138
- export class Session {
139
- context;
140
- limits;
141
- comparisonBlockBytes;
142
- controller = new AbortController();
143
- signal;
144
- cursors = [];
145
- closed;
146
- constructor(context, limits, comparisonBlockBytes) {
147
- this.context = context;
148
- this.limits = limits;
149
- this.comparisonBlockBytes = comparisonBlockBytes;
150
- this.signal = AbortSignal.any([context.signal, this.controller.signal]);
151
- context.registerCleanup?.(() => this.close());
152
- }
153
- async open(name) {
154
- this.signal.throwIfAborted();
155
- if (name === "-")
156
- return { name };
157
- try {
158
- if (!name)
159
- throw new FsError("ENOENT");
160
- const path = resolvePath(this.context.cwd, name);
161
- const stat = await observe(() => this.context.fs.stat(path, { signal: this.signal }), this.signal);
162
- this.signal.throwIfAborted();
163
- await observe(() => this.context.fs.access(path, 4, { signal: this.signal }), this.signal);
164
- this.signal.throwIfAborted();
165
- return { name, path, stat };
166
- }
167
- catch (error) {
168
- this.signal.throwIfAborted();
169
- throw new InputError(name, error, true);
170
- }
171
- }
172
- cursor(input, skip) {
173
- this.signal.throwIfAborted();
174
- const { context, signal, limits } = this;
175
- const source = input.path === undefined ? context.stdin : (async function* () {
176
- if (input.stat?.type === "directory")
177
- throw new FsError("EISDIR");
178
- if (skip > integerMaximum && input.stat?.type === "file")
179
- return;
180
- if (context.fs.readStream) {
181
- const start = input.stat?.type === "file" && input.stat.size >= 0 ? Number(skip < BigInt(Number.MAX_SAFE_INTEGER) ? skip : BigInt(Number.MAX_SAFE_INTEGER)) : 0;
182
- yield* context.fs.readStream(input.path, { signal, start, chunkSize: Math.min(65536, limits.maxChunkBytes) });
183
- }
184
- else {
185
- if (!input.stat || !Number.isSafeInteger(input.stat.size) || input.stat.size < 0 || input.stat.size > limits.maxFallbackBytes) {
186
- throw new Error("bounded comparison requires readStream or a file within maxFallbackBytes");
187
- }
188
- const bytes = await observe(() => context.fs.readFile(input.path, { signal, ...(Number.isFinite(limits.maxFallbackBytes) ? { maxBytes: limits.maxFallbackBytes } : {}) }), signal);
189
- if (bytes.length > limits.maxFallbackBytes)
190
- throw new Error("input fallback bytes limit exceeded");
191
- for (let offset = Number(skip < BigInt(bytes.length) ? skip : BigInt(bytes.length)); offset < bytes.length; offset += limits.maxChunkBytes)
192
- yield bytes.subarray(offset, offset + limits.maxChunkBytes);
193
- }
194
- })();
195
- const cursor = new Cursor(input.name, source, signal, limits.maxChunkBytes);
196
- this.cursors.push(cursor);
197
- return cursor;
198
- }
199
- async output(text, stderr = false) {
200
- await writeBytes(stderr ? this.context.stderr : this.context.stdout, new TextEncoder().encode(text), this.signal);
201
- }
202
- close(cancel = true) {
203
- if (!this.closed) {
204
- this.closed = Promise.resolve().then(async () => {
205
- const results = await Promise.allSettled(this.cursors.map(cursor => cursor.close()));
206
- const failure = results.find(result => result.status === "rejected");
207
- if (failure?.status === "rejected")
208
- throw failure.reason;
209
- });
210
- if (cancel)
211
- this.controller.abort(new Error("cmp invocation closed"));
212
- }
213
- return this.closed;
214
- }
215
- }
216
- export function inputDiagnostic(error) {
217
- return `cmp: ${pathQuote(error.operand)}: ${errorText(error.reason)}\n`;
218
- }
@@ -8,6 +8,10 @@ import {
8
8
  scanRegex,
9
9
  substituteRegex
10
10
  } from "./chunk-3KROFHBT.js";
11
+ import {
12
+ fromDateIso8601,
13
+ toDateIso8601
14
+ } from "./chunk-SNXWY3KV.js";
11
15
  import {
12
16
  delpaths
13
17
  } from "./chunk-VQLFJCG7.js";
@@ -43,10 +47,6 @@ import {
43
47
  parseJson,
44
48
  stringify
45
49
  } from "./chunk-VUG324ER.js";
46
- import {
47
- fromDateIso8601,
48
- toDateIso8601
49
- } from "./chunk-SNXWY3KV.js";
50
50
  import {
51
51
  JqError,
52
52
  JqHalt,