@poe-platform/safe-bash 0.1.757 → 0.1.758

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 (55) hide show
  1. package/dist/image-ast/index.browser.js +72 -19
  2. package/dist/image-ast/index.js +72 -19
  3. package/dist/pdf-ast/ast.d.ts +3 -0
  4. package/dist/pdf-ast/index.js +88 -36
  5. package/dist/safe-bash/command-chunks/{chunk-F3J5ZLKF.js → chunk-522TDVLS.js} +1 -1
  6. package/dist/safe-bash/command-chunks/{chunk-VFS2MDAB.js → chunk-6YLD37NH.js} +2 -2
  7. package/dist/safe-bash/command-chunks/{chunk-YI3GKJ7Q.js → chunk-766IWMTB.js} +2 -2
  8. package/dist/safe-bash/command-chunks/{chunk-KSH2F6RG.js → chunk-CUFCNL6G.js} +1 -1
  9. package/dist/safe-bash/command-chunks/{chunk-S4MLIYSN.js → chunk-J2NPH7DO.js} +4 -0
  10. package/dist/safe-bash/command-chunks/{chunk-KBBI4CSU.js → chunk-L2C5TIII.js} +2 -2
  11. package/dist/safe-bash/command-chunks/{chunk-H2FQA4OU.js → chunk-TCAGGM44.js} +72 -19
  12. package/dist/safe-bash/command-chunks/{chunk-WI35236J.js → chunk-XYCWDGOG.js} +1 -1
  13. package/dist/safe-bash/command-chunks/{chunk-4F6PG2OT.js → chunk-YJWWRCIG.js} +8 -8
  14. package/dist/safe-bash-command-column/column.js +3 -3
  15. package/dist/safe-bash-command-column/index.js +3 -3
  16. package/dist/safe-bash-command-column/layout.js +2 -2
  17. package/dist/safe-bash-command-factor/command.js +2 -2
  18. package/dist/safe-bash-command-factor/index.js +2 -2
  19. package/dist/safe-bash-command-ffmpeg/index.js +5923 -5893
  20. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  21. package/dist/safe-bash-command-pandoc/command.js +3 -3
  22. package/dist/safe-bash-command-pandoc/index.js +3 -3
  23. package/dist/safe-bash-command-pdfimages/index.js +72 -19
  24. package/dist/safe-bash-command-pdfinfo/index.js +88 -36
  25. package/dist/safe-bash-command-pdftk/index.js +72 -19
  26. package/dist/safe-bash-command-pdftoppm/index.js +88 -36
  27. package/dist/safe-bash-command-pdftotext/index.js +72 -19
  28. package/dist/safe-bash-command-qpdf/index.js +72 -19
  29. package/dist/safe-bash-command-sips/index.js +2 -2
  30. package/dist/safe-bash-command-soffice/index.js +2 -2
  31. package/dist/safe-bash-command-ssconvert/command-bindings.d.ts +18 -0
  32. package/dist/safe-bash-command-ssconvert/command.d.ts +5 -14
  33. package/dist/safe-bash-command-ssconvert/commands.d.ts +6 -0
  34. package/dist/safe-bash-command-ssconvert/commands.js +871 -0
  35. package/dist/safe-bash-command-ssconvert/core.js +1 -1
  36. package/dist/safe-bash-command-ssconvert/index.js +269 -209
  37. package/dist/safe-bash-command-wkhtmltopdf/index.js +72 -19
  38. package/dist/safe-bash-command-yq/index.js +4 -4
  39. package/dist/safe-bash-compression-engine/files.js +2 -2
  40. package/dist/safe-bash-compression-engine/operand.js +4 -4
  41. package/dist/safe-bash-markdown-engine/commonmark-blocks.js +4 -4
  42. package/dist/safe-bash-markdown-engine/commonmark-inlines.js +4 -4
  43. package/dist/safe-bash-markdown-engine/commonmark-syntax.js +2 -2
  44. package/dist/safe-bash-markdown-engine/gfm-syntax.js +3 -3
  45. package/dist/safe-bash-markdown-engine/index.js +7 -7
  46. package/dist/safe-bash-query-engine/index.js +5 -5
  47. package/dist/safe-bash-query-engine/interpreter.js +4 -4
  48. package/dist/safe-bash-query-engine/query-core.js +5 -5
  49. package/package.json +6 -2
  50. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +16 -0
  51. package/dist/safe-bash/command-chunks/{chunk-OQVIJMBY.js → chunk-7HINP7ZK.js} +4 -4
  52. package/dist/safe-bash/command-chunks/{chunk-XAYEDOV5.js → chunk-CG4JSOK2.js} +3 -3
  53. package/dist/safe-bash/command-chunks/{chunk-YIK4ZYQ4.js → chunk-DC52GWRK.js} +9 -9
  54. package/dist/safe-bash/command-chunks/{chunk-TOTZFBDT.js → chunk-TKACIO4X.js} +4 -4
  55. package/dist/safe-bash/command-chunks/{chunk-VTWKS4RM.js → chunk-WF2LSKMI.js} +3 -3
@@ -198781,7 +198781,7 @@ var ParsedCosDocument = class {
198781
198781
  return void 0;
198782
198782
  }
198783
198783
  };
198784
- function parseNodeFromLexer(lexer, bytes, maxDepth, recoverEmptyObject = false) {
198784
+ function parseNodeFromLexer(lexer, bytes, maxDepth, repair = false) {
198785
198785
  const stack = [];
198786
198786
  while (true) {
198787
198787
  const tok = lexer.nextToken();
@@ -198790,7 +198790,7 @@ function parseNodeFromLexer(lexer, bytes, maxDepth, recoverEmptyObject = false)
198790
198790
  if (!parent) return void 0;
198791
198791
  throw new PdfError2("E_PARSE", parent.kind === "array" ? "Unterminated PDF array" : "Unterminated PDF dictionary");
198792
198792
  }
198793
- if (!parent && recoverEmptyObject && tok.kind === "keyword" && tok.value === "endobj") {
198793
+ if (!parent && repair && tok.kind === "keyword" && tok.value === "endobj") {
198794
198794
  return { kind: "null", span: tok.span };
198795
198795
  }
198796
198796
  let node3;
@@ -198805,6 +198805,7 @@ function parseNodeFromLexer(lexer, bytes, maxDepth, recoverEmptyObject = false)
198805
198805
  parent.key = { kind: "name", rawBytes: tok.rawBytes, decoded: tok.decoded, span: tok.span };
198806
198806
  continue;
198807
198807
  } else {
198808
+ if (repair) continue;
198808
198809
  throw new PdfError2("E_PARSE", `Expected dictionary key /Name, got ${tok.kind}`);
198809
198810
  }
198810
198811
  } else {
@@ -198973,7 +198974,7 @@ function parseHeaderVersion(bytes) {
198973
198974
  }
198974
198975
  return head.slice(idx + 5, idx + 8);
198975
198976
  }
198976
- function parseObjectAtOffset(bytes, offset, maxRecursionDepth, recoverEmptyObject = false) {
198977
+ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, repair = false) {
198977
198978
  const lexer = new CosByteLexer(bytes, offset);
198978
198979
  const objNumTok = lexer.nextToken();
198979
198980
  const genNumTok = lexer.nextToken();
@@ -198981,7 +198982,7 @@ function parseObjectAtOffset(bytes, offset, maxRecursionDepth, recoverEmptyObjec
198981
198982
  if (objNumTok?.kind !== "number" || genNumTok?.kind !== "number" || objKwTok?.kind !== "keyword" || objKwTok.value !== "obj") {
198982
198983
  throw new PdfError2("E_PARSE", `Malformed indirect object header at byte offset ${offset}`);
198983
198984
  }
198984
- const value3 = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, recoverEmptyObject);
198985
+ const value3 = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, repair);
198985
198986
  if (!value3) {
198986
198987
  throw new PdfError2("E_PARSE", `Empty indirect object ${objNumTok.value} at offset ${offset}`);
198987
198988
  }
@@ -199170,7 +199171,7 @@ function repairScanCosDocument(bytes, maxObjects, maxRecursionDepth) {
199170
199171
  try {
199171
199172
  const token = lexer.nextToken();
199172
199173
  if (token?.kind === "keyword" && token.value === "trailer") {
199173
- const trailer = parseNodeFromLexer(lexer, bytes, maxRecursionDepth);
199174
+ const trailer = parseNodeFromLexer(lexer, bytes, maxRecursionDepth, true);
199174
199175
  if (trailer?.kind === "dict") trailers.push(trailer);
199175
199176
  pos = lexer.offset;
199176
199177
  continue;
@@ -199226,7 +199227,7 @@ function unpackRecoveredObjects(objects, maxObjects, maxDecompressedBytes, maxRe
199226
199227
  const t = dictGet(obj.value.dict, "Type");
199227
199228
  if (t?.kind === "name" && t.decoded === "ObjStm") {
199228
199229
  try {
199229
- for (const [unpackedNum, unpackedVal] of unpackObjectStream(obj.value, maxDecompressedBytes, maxRecursionDepth).entries()) {
199230
+ for (const [unpackedNum, unpackedVal] of unpackObjectStream(obj.value, maxDecompressedBytes, maxRecursionDepth, true).entries()) {
199230
199231
  if (!objects.has(unpackedNum)) {
199231
199232
  objects.set(unpackedNum, {
199232
199233
  objectNumber: unpackedNum,
@@ -199262,7 +199263,7 @@ function recoveredReferences(objects) {
199262
199263
  }
199263
199264
  return { ...rootRef ? { rootRef } : {}, ...infoRef ? { infoRef } : {} };
199264
199265
  }
199265
- function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth) {
199266
+ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth, repair = false) {
199266
199267
  const nNode = dictGet(streamObj.dict, "N");
199267
199268
  const firstNode = dictGet(streamObj.dict, "First");
199268
199269
  if (nNode?.kind !== "number" || firstNode?.kind !== "number") {
@@ -199282,7 +199283,7 @@ function unpackObjectStream(streamObj, maxDecompressedBytes, maxRecursionDepth)
199282
199283
  for (const pair of pairs) {
199283
199284
  try {
199284
199285
  const valLexer = new CosByteLexer(decoded, firstNode.value + pair.relativeOffset);
199285
- const node3 = parseNodeFromLexer(valLexer, decoded, maxRecursionDepth);
199286
+ const node3 = parseNodeFromLexer(valLexer, decoded, maxRecursionDepth, repair);
199286
199287
  if (node3) {
199287
199288
  result2.set(pair.objectNumber, node3);
199288
199289
  }
@@ -199465,7 +199466,7 @@ function parseCosDocument(bytes, options = {}) {
199465
199466
  if (!unpacked) {
199466
199467
  const stmObj = objects.get(entry2.objectStreamNumber)?.value;
199467
199468
  if (stmObj?.kind === "stream") {
199468
- unpacked = unpackObjectStream(stmObj, maxDecompressedBytes, maxRecursionDepth);
199469
+ unpacked = unpackObjectStream(stmObj, maxDecompressedBytes, maxRecursionDepth, recovery === "repair");
199469
199470
  objStmCache.set(entry2.objectStreamNumber, unpacked);
199470
199471
  }
199471
199472
  }
@@ -207937,7 +207938,11 @@ function resolvePageFonts(doc, resourcesDict) {
207937
207938
  let cmap;
207938
207939
  const toUniNode = doc.resolve(dictGet(fObj, "ToUnicode"));
207939
207940
  if (toUniNode?.kind === "stream") {
207940
- cmap = parseToUnicodeCMap(doc.decodeStream(toUniNode));
207941
+ try {
207942
+ cmap = parseToUnicodeCMap(doc.decodeStream(toUniNode));
207943
+ } catch (error2) {
207944
+ if (error2 instanceof PdfError2 && error2.code === "E_LIMIT") throw error2;
207945
+ }
207941
207946
  }
207942
207947
  const encNode = doc.resolve(dictGet(fObj, "Encoding"));
207943
207948
  if (encNode?.kind === "dict") {
@@ -209061,8 +209066,12 @@ function evaluateContentStreamToDisplayList(params) {
209061
209066
  const images = [];
209062
209067
  const operations = [];
209063
209068
  const emit = (operation) => {
209064
- const clipPaths = curState().clipPaths;
209065
- if (clipPaths) operation = { ...operation, value: { ...operation.value, clipPaths } };
209069
+ const { clipPaths, clipImages } = curState();
209070
+ if (clipPaths || clipImages) operation = { ...operation, value: {
209071
+ ...operation.value,
209072
+ ...clipPaths ? { clipPaths } : {},
209073
+ ...clipImages ? { clipImages } : {}
209074
+ } };
209066
209075
  operations.push(operation);
209067
209076
  switch (operation.kind) {
209068
209077
  case "path":
@@ -209326,6 +209335,18 @@ function evaluateContentStreamToDisplayList(params) {
209326
209335
  let hasTextClip = false;
209327
209336
  let activeTm = [1, 0, 0, 1, 0, 0];
209328
209337
  let activeTlm = [1, 0, 0, 1, 0, 0];
209338
+ const paintImage = (image, patternMask, resources, activeFonts, depth) => {
209339
+ if (!patternMask) {
209340
+ emit({ kind: "image", value: image });
209341
+ return;
209342
+ }
209343
+ const st = curState();
209344
+ stateStack.push({ ...st, clipImages: [...st.clipImages ?? [], image] });
209345
+ walkNodes([{ kind: "path-op", paint: "f", segments: [
209346
+ { kind: "rect", x: 0, y: 0, width: 1, height: 1 }
209347
+ ] }], void 0, void 0, resources, activeFonts, depth);
209348
+ stateStack.pop();
209349
+ };
209329
209350
  const walkNodes = (nodes, mcid, actualText, activeResources = params.resourcesDict, activeFonts = fonts, depth = 0) => {
209330
209351
  for (const node3 of nodes) {
209331
209352
  switch (node3.kind) {
@@ -209509,7 +209530,8 @@ function evaluateContentStreamToDisplayList(params) {
209509
209530
  st.fillAlpha,
209510
209531
  "PatternShading_" + st.fillPatternName,
209511
209532
  patClip,
209512
- shading?.kind === "stream" ? shading : void 0
209533
+ shading?.kind === "stream" ? shading : void 0,
209534
+ st.blendMode
209513
209535
  );
209514
209536
  if (shImg) {
209515
209537
  emit({ kind: "image", value: shImg });
@@ -209618,18 +209640,20 @@ function evaluateContentStreamToDisplayList(params) {
209618
209640
  const subNode = params.cosDoc.resolve(dictGet(xobjNode.dict, "Subtype"));
209619
209641
  const sub = subNode?.kind === "name" ? subNode.decoded : "";
209620
209642
  if (sub === "Image") {
209643
+ const maskNode = params.cosDoc.resolve(dictGet(xobjNode.dict, "ImageMask"));
209644
+ const patternMask = !!st.fillPatternName && maskNode?.kind === "boolean" && maskNode.value;
209621
209645
  const decoded = decodeXObjectImageToRgba(
209622
209646
  params.cosDoc,
209623
209647
  xobjNode,
209624
209648
  activeResources,
209625
- {
209649
+ patternMask ? { r: 1, g: 1, b: 1, alpha: 1 } : {
209626
209650
  r: st.fillColor.r,
209627
209651
  g: st.fillColor.g,
209628
209652
  b: st.fillColor.b,
209629
209653
  alpha: st.fillAlpha
209630
209654
  }
209631
209655
  );
209632
- emit({ kind: "image", value: {
209656
+ paintImage({
209633
209657
  name: node3.name,
209634
209658
  matrix: [...st.ctm],
209635
209659
  width: decoded.width,
@@ -209639,7 +209663,7 @@ function evaluateContentStreamToDisplayList(params) {
209639
209663
  decodedRgba: decoded.rgba,
209640
209664
  ...st.blendMode && st.blendMode !== "Normal" ? { blendMode: st.blendMode } : {},
209641
209665
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
209642
- } });
209666
+ }, patternMask, activeResources, activeFonts, depth);
209643
209667
  } else if (sub === "Form" && depth < 8) {
209644
209668
  const formStreamBytes = params.cosDoc.decodeStream(xobjNode);
209645
209669
  const formNodes = parseContentStream(formStreamBytes);
@@ -209695,19 +209719,22 @@ function evaluateContentStreamToDisplayList(params) {
209695
209719
  }
209696
209720
  case "inline-image": {
209697
209721
  const st = curState();
209722
+ const maskEntry = dictGet(node3.dict, "ImageMask") ?? dictGet(node3.dict, "IM");
209723
+ const maskNode = params.cosDoc ? params.cosDoc.resolve(maskEntry) : maskEntry;
209724
+ const patternMask = !!st.fillPatternName && maskNode?.kind === "boolean" && maskNode.value;
209698
209725
  const decoded = decodeInlineImageNodeToRgba(
209699
209726
  params.cosDoc,
209700
209727
  node3.dict,
209701
209728
  node3.data,
209702
209729
  activeResources,
209703
- {
209730
+ patternMask ? { r: 1, g: 1, b: 1, alpha: 1 } : {
209704
209731
  r: st.fillColor.r,
209705
209732
  g: st.fillColor.g,
209706
209733
  b: st.fillColor.b,
209707
209734
  alpha: st.fillAlpha
209708
209735
  }
209709
209736
  );
209710
- emit({ kind: "image", value: {
209737
+ paintImage({
209711
209738
  name: "InlineImage",
209712
209739
  matrix: [...st.ctm],
209713
209740
  width: decoded.width,
@@ -209717,7 +209744,7 @@ function evaluateContentStreamToDisplayList(params) {
209717
209744
  decodedRgba: decoded.rgba,
209718
209745
  ...st.blendMode && st.blendMode !== "Normal" ? { blendMode: st.blendMode } : {},
209719
209746
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
209720
- } });
209747
+ }, patternMask, activeResources, activeFonts, depth);
209721
209748
  break;
209722
209749
  }
209723
209750
  case "text-object": {
@@ -213067,6 +213094,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213067
213094
  const aaVec = options.antialiasVector !== false;
213068
213095
  const aaTxt = options.antialiasText !== false;
213069
213096
  const clipMasks = /* @__PURE__ */ new Map();
213097
+ const imageClipMasks = /* @__PURE__ */ new Map();
213070
213098
  for (const original of paintOperations(displayList)) {
213071
213099
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
213072
213100
  const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
@@ -213081,6 +213109,31 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213081
213109
  }
213082
213110
  clipMasks.set(clips, clipMask);
213083
213111
  }
213112
+ const imageClips = original.value.clipImages;
213113
+ if (imageClips) {
213114
+ let imageMask = imageClipMasks.get(imageClips);
213115
+ if (!imageMask) {
213116
+ imageMask = new Uint8Array(width2 * height * 4).fill(255);
213117
+ for (const image of imageClips) {
213118
+ const layer = renderDisplayListToBitmap({
213119
+ ...displayList,
213120
+ rotation: 0,
213121
+ paths: [],
213122
+ glyphs: [],
213123
+ images: [image],
213124
+ operations: [{ kind: "image", value: image }]
213125
+ }, { scale: scale2, transparent: true }).data;
213126
+ for (let i = 3; i < layer.length; i += 4) imageMask[i] = Math.round(imageMask[i] * layer[i] / 255);
213127
+ }
213128
+ imageClipMasks.set(imageClips, imageMask);
213129
+ }
213130
+ if (clipMask) {
213131
+ clipMask = clipMask.slice();
213132
+ for (let i = 3; i < clipMask.length; i += 4) clipMask[i] = Math.round(clipMask[i] * imageMask[i] / 255);
213133
+ } else {
213134
+ clipMask = imageMask;
213135
+ }
213136
+ }
213084
213137
  if (operation.kind === "path") {
213085
213138
  const path2 = operation.value;
213086
213139
  if (path2.fillColor) {
@@ -233295,209 +233348,216 @@ function createDatabaseFunctions(query) {
233295
233348
  }
233296
233349
  }])));
233297
233350
  }
233298
- function createSsconvertCommand(options = {}) {
233299
- const configured = { ...options };
233300
- if (configured.replace !== void 0 && typeof configured.replace !== "boolean")
233301
- throw new TypeError("ssconvert replace must be boolean");
233302
- const binding = {
233303
- ...configured,
233304
- ...configured.io === void 0 ? {} : { io: Object.freeze({
233305
- ...configured.io.descriptors === void 0 ? {} : { descriptors: Object.freeze(Object.fromEntries(
233306
- Object.entries(configured.io.descriptors).map(([key, descriptor3]) => [key, Object.freeze({ ...descriptor3 })])
233307
- )) },
233308
- ...configured.io.adapters === void 0 ? {} : { adapters: Object.freeze({ ...configured.io.adapters }) },
233309
- ...configured.io.transport === void 0 ? {} : { transport: Object.freeze({
233310
- authorize: configured.io.transport.authorize.bind(configured.io.transport),
233311
- request: configured.io.transport.request.bind(configured.io.transport),
233312
- redirects: configured.io.transport.redirects
233313
- }) }
233314
- }) },
233315
- ...configured.runtimeFunctions === void 0 ? {} : { runtimeFunctions: snapshotRuntimeFunctions(configured.runtimeFunctions) },
233316
- ...configured.profile === void 0 ? {} : { profile: Object.freeze({
233317
- ...configured.profile,
233318
- ...configured.profile.groups === void 0 ? {} : { groups: Object.freeze({ ...configured.profile.groups }) },
233319
- ...configured.profile.configurationRoots === void 0 ? {} : {
233320
- configurationRoots: Object.freeze({ ...configured.profile.configurationRoots })
233321
- }
233322
- }) },
233323
- codecs: Object.freeze([...configured.codecs ?? []]),
233324
- ...configured.formats === void 0 ? {} : { formats: snapshotFormats(configured.formats) },
233325
- limits: Object.freeze({ ...defaultSsconvertLimits, ...configured.limits }),
233326
- environment: Object.freeze({
233327
- locale: "C",
233328
- timezone: "UTC",
233329
- ...configured.environment,
233330
- env: Object.freeze({ ...configured.environment?.env })
233331
- })
233332
- };
233333
- const command = {
233334
- name: "ssconvert",
233335
- description: "Explicitly bound TypeScript spreadsheet conversion engine",
233336
- async execute(context) {
233337
- context.signal.throwIfAborted();
233338
- const owner = createOutputOperation(context, { async write() {
233339
- } });
233340
- const inputBytes = Math.min(
233341
- binding.limits.inputBytes,
233342
- context.inputBudget?.maxBytes ?? Infinity
233343
- );
233344
- let stdout;
233345
- const standardOutput = { async write(bytes) {
233346
- stdout ??= owner.child(context.stdout);
233347
- await stdout.output.write(bytes);
233348
- } };
233349
- let stderr;
233350
- const standardError = { async write(bytes) {
233351
- stderr ??= owner.child(context.stderr);
233352
- await stderr.output.write(bytes);
233353
- } };
233354
- const openOutput = createVfsOutput(context.fs, async (path2, bytes, signal) => {
233355
- await owner.acquire(() => writeFileOutput(
233356
- context,
233357
- bytes,
233358
- async (data3) => {
233359
- const capabilities = await context.fs.capabilitiesFor?.(path2, { signal }) ?? context.fs.capabilities;
233360
- signal.throwIfAborted();
233361
- if (context.fs.writeStream && capabilities.streamingWrite !== false)
233362
- await context.fs.writeStream(path2, (async function* () {
233363
- yield data3;
233364
- })(), { signal });
233365
- else await context.fs.writeFile(path2, data3, { signal });
233366
- }
233367
- ), () => {
233368
- });
233369
- }, (cleanup) => retainFileSystemCleanup(
233370
- context.fs,
233371
- (view2) => cleanup((path2) => view2.rm(path2)),
233372
- { maxOperations: 1 }
233373
- ));
233374
- let engine;
233375
- try {
233376
- const cwd = await owner.acquire(() => resolveVfsCwd(context.cwd, context.env.PWD, context.fs, owner.signal), () => {
233377
- });
233378
- engine = createEngine2({
233379
- ...binding,
233380
- environment: {
233381
- ...binding.environment,
233382
- cwd,
233383
- env: Object.freeze({ ...context.env })
233384
- },
233385
- limits: { ...binding.limits, inputBytes },
233386
- filesystem: createResourceIO({
233387
- ...binding.io,
233388
- cwd,
233389
- descriptors: {
233390
- ...binding.io?.descriptors,
233391
- 0: { source: context.stdin },
233392
- 1: { sink: standardOutput }
233351
+ function createCommandBindings(createEngine3, compatibilityDefaults = false) {
233352
+ function createSsconvertCommand2(options = {}) {
233353
+ const configured = { ...options };
233354
+ if (configured.replace !== void 0 && typeof configured.replace !== "boolean")
233355
+ throw new TypeError("ssconvert replace must be boolean");
233356
+ const binding = {
233357
+ ...configured,
233358
+ ...configured.io === void 0 ? {} : { io: Object.freeze({
233359
+ ...configured.io.descriptors === void 0 ? {} : { descriptors: Object.freeze(Object.fromEntries(
233360
+ Object.entries(configured.io.descriptors).map(([key, descriptor3]) => [key, Object.freeze({ ...descriptor3 })])
233361
+ )) },
233362
+ ...configured.io.adapters === void 0 ? {} : { adapters: Object.freeze({ ...configured.io.adapters }) },
233363
+ ...configured.io.transport === void 0 ? {} : { transport: Object.freeze({
233364
+ authorize: configured.io.transport.authorize.bind(configured.io.transport),
233365
+ request: configured.io.transport.request.bind(configured.io.transport),
233366
+ redirects: configured.io.transport.redirects
233367
+ }) }
233368
+ }) },
233369
+ ...configured.runtimeFunctions === void 0 ? {} : { runtimeFunctions: snapshotRuntimeFunctions(configured.runtimeFunctions) },
233370
+ ...configured.profile === void 0 ? {} : { profile: Object.freeze({
233371
+ ...configured.profile,
233372
+ ...configured.profile.groups === void 0 ? {} : { groups: Object.freeze({ ...configured.profile.groups }) },
233373
+ ...configured.profile.configurationRoots === void 0 ? {} : {
233374
+ configurationRoots: Object.freeze({ ...configured.profile.configurationRoots })
233375
+ }
233376
+ }) },
233377
+ codecs: Object.freeze([...configured.codecs ?? []]),
233378
+ ...configured.formats === void 0 ? {} : { formats: snapshotFormats(configured.formats) },
233379
+ limits: Object.freeze({ ...defaultSsconvertLimits, ...configured.limits }),
233380
+ environment: Object.freeze({
233381
+ locale: "C",
233382
+ timezone: "UTC",
233383
+ ...configured.environment,
233384
+ env: Object.freeze({ ...configured.environment?.env })
233385
+ })
233386
+ };
233387
+ const command = {
233388
+ name: "ssconvert",
233389
+ description: "Explicitly bound TypeScript spreadsheet conversion engine",
233390
+ async execute(context) {
233391
+ context.signal.throwIfAborted();
233392
+ const owner = createOutputOperation(context, { async write() {
233393
+ } });
233394
+ const inputBytes = Math.min(
233395
+ binding.limits.inputBytes,
233396
+ context.inputBudget?.maxBytes ?? Infinity
233397
+ );
233398
+ let stdout;
233399
+ const standardOutput = { async write(bytes) {
233400
+ stdout ??= owner.child(context.stdout);
233401
+ await stdout.output.write(bytes);
233402
+ } };
233403
+ let stderr;
233404
+ const standardError = { async write(bytes) {
233405
+ stderr ??= owner.child(context.stderr);
233406
+ await stderr.output.write(bytes);
233407
+ } };
233408
+ const openOutput = createVfsOutput(context.fs, async (path2, bytes, signal) => {
233409
+ await owner.acquire(() => writeFileOutput(
233410
+ context,
233411
+ bytes,
233412
+ async (data3) => {
233413
+ const capabilities = await context.fs.capabilitiesFor?.(path2, { signal }) ?? context.fs.capabilities;
233414
+ signal.throwIfAborted();
233415
+ if (context.fs.writeStream && capabilities.streamingWrite !== false)
233416
+ await context.fs.writeStream(path2, (async function* () {
233417
+ yield data3;
233418
+ })(), { signal });
233419
+ else await context.fs.writeFile(path2, data3, { signal });
233420
+ }
233421
+ ), () => {
233422
+ });
233423
+ }, (cleanup) => retainFileSystemCleanup(
233424
+ context.fs,
233425
+ (view2) => cleanup((path2) => view2.rm(path2)),
233426
+ { maxOperations: 1 }
233427
+ ));
233428
+ let engine;
233429
+ try {
233430
+ const cwd = await owner.acquire(() => resolveVfsCwd(context.cwd, context.env.PWD, context.fs, owner.signal), () => {
233431
+ });
233432
+ engine = createEngine3({
233433
+ ...binding,
233434
+ environment: {
233435
+ ...binding.environment,
233436
+ cwd,
233437
+ env: Object.freeze({ ...context.env })
233393
233438
  },
233394
- filesystem: {
233395
- openOutput,
233396
- async read(uri, signal) {
233397
- try {
233398
- const capabilities = await context.fs.capabilitiesFor?.(uri, { signal }) ?? context.fs.capabilities;
233399
- signal.throwIfAborted();
233400
- if (context.fs.readStream && capabilities.streamingRead !== false)
233401
- return context.fs.readStream(uri, { signal });
233402
- const bytes = await owner.acquire(
233403
- () => context.fs.readFile(uri, {
233404
- signal,
233405
- ...inputBytes === Infinity ? {} : { maxBytes: inputBytes }
233406
- }),
233407
- () => {
233408
- }
233409
- );
233410
- context.inputBudget?.check(bytes.byteLength);
233411
- return [bytes];
233412
- } catch (error2) {
233413
- signal.throwIfAborted();
233414
- throw error2;
233415
- }
233439
+ limits: { ...binding.limits, inputBytes },
233440
+ filesystem: createResourceIO({
233441
+ ...binding.io,
233442
+ cwd,
233443
+ descriptors: {
233444
+ ...binding.io?.descriptors,
233445
+ 0: { source: context.stdin },
233446
+ 1: { sink: standardOutput }
233416
233447
  },
233417
- async write(uri, bytes, signal) {
233418
- try {
233419
- await owner.acquire(
233420
- () => writeFileOutput(context, bytes, async (data3) => {
233421
- const capabilities = await context.fs.capabilitiesFor?.(uri, { signal }) ?? context.fs.capabilities;
233422
- signal.throwIfAborted();
233423
- if (context.fs.writeStream && capabilities.streamingWrite !== false)
233424
- await context.fs.writeStream(uri, (async function* () {
233425
- yield data3;
233426
- })(), { signal });
233427
- else await context.fs.writeFile(uri, data3, { signal });
233428
- }),
233429
- () => {
233430
- }
233431
- );
233432
- } catch (error2) {
233433
- signal.throwIfAborted();
233434
- throw error2;
233448
+ filesystem: {
233449
+ openOutput,
233450
+ async read(uri, signal) {
233451
+ try {
233452
+ const capabilities = await context.fs.capabilitiesFor?.(uri, { signal }) ?? context.fs.capabilities;
233453
+ signal.throwIfAborted();
233454
+ if (context.fs.readStream && capabilities.streamingRead !== false)
233455
+ return context.fs.readStream(uri, { signal });
233456
+ const bytes = await owner.acquire(
233457
+ () => context.fs.readFile(uri, {
233458
+ signal,
233459
+ ...inputBytes === Infinity ? {} : { maxBytes: inputBytes }
233460
+ }),
233461
+ () => {
233462
+ }
233463
+ );
233464
+ context.inputBudget?.check(bytes.byteLength);
233465
+ return [bytes];
233466
+ } catch (error2) {
233467
+ signal.throwIfAborted();
233468
+ throw error2;
233469
+ }
233470
+ },
233471
+ async write(uri, bytes, signal) {
233472
+ try {
233473
+ await owner.acquire(
233474
+ () => writeFileOutput(context, bytes, async (data3) => {
233475
+ const capabilities = await context.fs.capabilitiesFor?.(uri, { signal }) ?? context.fs.capabilities;
233476
+ signal.throwIfAborted();
233477
+ if (context.fs.writeStream && capabilities.streamingWrite !== false)
233478
+ await context.fs.writeStream(uri, (async function* () {
233479
+ yield data3;
233480
+ })(), { signal });
233481
+ else await context.fs.writeFile(uri, data3, { signal });
233482
+ }),
233483
+ () => {
233484
+ }
233485
+ );
233486
+ } catch (error2) {
233487
+ signal.throwIfAborted();
233488
+ throw error2;
233489
+ }
233435
233490
  }
233436
233491
  }
233492
+ })
233493
+ });
233494
+ const maximumArguments = binding.limits.argumentBytes ?? Infinity;
233495
+ const values2 = context.argumentValues?.values ?? context.args;
233496
+ let argumentBytes = 0;
233497
+ let refusal;
233498
+ if (values2.length > maximumArguments) refusal = "ssconvert arguments limit exceeded";
233499
+ for (const value3 of values2) {
233500
+ if (refusal) break;
233501
+ if (typeof value3 === "string" && value3.length > maximumArguments - argumentBytes) {
233502
+ refusal = "ssconvert argument bytes limit exceeded";
233503
+ break;
233437
233504
  }
233438
- })
233439
- });
233440
- const maximumArguments = binding.limits.argumentBytes ?? Infinity;
233441
- const values2 = context.argumentValues?.values ?? context.args;
233442
- let argumentBytes = 0;
233443
- let refusal;
233444
- if (values2.length > maximumArguments) refusal = "ssconvert arguments limit exceeded";
233445
- for (const value3 of values2) {
233446
- if (refusal) break;
233447
- if (typeof value3 === "string" && value3.length > maximumArguments - argumentBytes) {
233448
- refusal = "ssconvert argument bytes limit exceeded";
233449
- break;
233505
+ argumentBytes += shellValueByteLength(value3);
233506
+ if (argumentBytes > maximumArguments) refusal = "ssconvert argument bytes limit exceeded";
233450
233507
  }
233451
- argumentBytes += shellValueByteLength(value3);
233452
- if (argumentBytes > maximumArguments) refusal = "ssconvert argument bytes limit exceeded";
233453
- }
233454
- if (refusal) {
233455
- await standardError.write(new TextEncoder().encode(`${refusal}
233508
+ if (refusal) {
233509
+ await standardError.write(new TextEncoder().encode(`${refusal}
233456
233510
  `));
233457
- owner.signal.throwIfAborted();
233458
- return { exitCode: 1 };
233459
- }
233460
- const carrier = getCommandArguments(context);
233461
- return await runCommand(
233462
- carrier.args.map((_, index2) => carrier.bytes(index2)),
233463
- engine,
233464
- {
233465
- signal: owner.signal,
233466
- ...context.stdinIsDefault === void 0 ? {} : { stdinIsDefault: context.stdinIsDefault },
233467
- stdout: standardOutput,
233468
- stderr: standardError,
233469
- registerCleanup: (cleanup) => owner.registerCleanup(cleanup)
233470
- },
233471
- binding.profile
233472
- );
233473
- } finally {
233474
- try {
233475
- await engine?.dispose();
233511
+ owner.signal.throwIfAborted();
233512
+ return { exitCode: 1 };
233513
+ }
233514
+ const carrier = getCommandArguments(context);
233515
+ return await runCommand(
233516
+ carrier.args.map((_, index2) => carrier.bytes(index2)),
233517
+ engine,
233518
+ {
233519
+ signal: owner.signal,
233520
+ ...context.stdinIsDefault === void 0 ? {} : { stdinIsDefault: context.stdinIsDefault },
233521
+ stdout: standardOutput,
233522
+ stderr: standardError,
233523
+ registerCleanup: (cleanup) => owner.registerCleanup(cleanup)
233524
+ },
233525
+ binding.profile
233526
+ );
233476
233527
  } finally {
233477
- await owner.close();
233528
+ try {
233529
+ await engine?.dispose();
233530
+ } finally {
233531
+ await owner.close();
233532
+ }
233478
233533
  }
233479
233534
  }
233535
+ };
233536
+ if (compatibilityDefaults && Object.entries(configured).every(([key, value3]) => key === "replace" || value3 === void 0)) {
233537
+ builtInDirectContextExecutors.add(command.execute);
233480
233538
  }
233481
- };
233482
- if (Object.entries(configured).every(([key, value3]) => key === "replace" || value3 === void 0)) {
233483
- builtInDirectContextExecutors.add(command.execute);
233539
+ return command;
233484
233540
  }
233485
- return command;
233486
- }
233487
- function ssconvertCommands(options = {}) {
233488
- const commands = createSsconvertCommands(options), replace = options.replace ?? false;
233489
- return {
233490
- name: "ssconvert-commands",
233491
- setup(host) {
233492
- if (!replace && commands.some((command) => host.commands.has(command.name)))
233493
- throw new Error("Command already registered: ssconvert");
233494
- for (const command of commands) host.commands.register(command, { replace });
233495
- }
233496
- };
233497
- }
233498
- function createSsconvertCommands(options = {}) {
233499
- return Object.freeze([createSsconvertCommand(options)]);
233541
+ function ssconvertCommands2(options = {}) {
233542
+ const commands = createSsconvertCommands2(options), replace = options.replace ?? false;
233543
+ return {
233544
+ name: "ssconvert-commands",
233545
+ setup(host) {
233546
+ if (!replace && commands.some((command) => host.commands.has(command.name)))
233547
+ throw new Error("Command already registered: ssconvert");
233548
+ for (const command of commands) host.commands.register(command, { replace });
233549
+ }
233550
+ };
233551
+ }
233552
+ function createSsconvertCommands2(options = {}) {
233553
+ return Object.freeze([createSsconvertCommand2(options)]);
233554
+ }
233555
+ return { createSsconvertCommand: createSsconvertCommand2, createSsconvertCommands: createSsconvertCommands2, ssconvertCommands: ssconvertCommands2 };
233500
233556
  }
233557
+ var bindings = createCommandBindings(createEngine2, true);
233558
+ var createSsconvertCommand = bindings.createSsconvertCommand;
233559
+ var createSsconvertCommands = bindings.createSsconvertCommands;
233560
+ var ssconvertCommands = bindings.ssconvertCommands;
233501
233561
  function parseSimpleSeparatedRows(text2, sep) {
233502
233562
  const rows = [];
233503
233563
  let row = [];