@ubercode/dcmtk 0.13.2 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dicom.cjs CHANGED
@@ -30370,6 +30370,51 @@ var ChangeSet = class _ChangeSet {
30370
30370
  return result;
30371
30371
  }
30372
30372
  };
30373
+
30374
+ // src/tools/_toolError.ts
30375
+ var MAX_ARGS_LENGTH = 200;
30376
+ var MAX_STDERR_LENGTH = 500;
30377
+ function truncate(value, maxLength) {
30378
+ if (value.length <= maxLength) {
30379
+ return value;
30380
+ }
30381
+ return `${value.substring(0, maxLength)}...`;
30382
+ }
30383
+ var ToolExecutionError = class extends Error {
30384
+ constructor(message, details) {
30385
+ super(message);
30386
+ __publicField(this, "stdout");
30387
+ __publicField(this, "stderr");
30388
+ __publicField(this, "exitCode");
30389
+ this.name = "ToolExecutionError";
30390
+ this.stdout = details.stdout;
30391
+ this.stderr = details.stderr;
30392
+ this.exitCode = details.exitCode;
30393
+ }
30394
+ };
30395
+ function createToolError(toolName, args, exitCode, stderr4, stdout = "") {
30396
+ const argsStr = truncate(args.join(" "), MAX_ARGS_LENGTH);
30397
+ const stderrStr = truncate(stderr4.trim(), MAX_STDERR_LENGTH);
30398
+ const parts = [`${toolName} failed (exit code ${String(exitCode)})`];
30399
+ if (argsStr.length > 0) {
30400
+ parts.push(`args: ${argsStr}`);
30401
+ }
30402
+ if (stderrStr.length > 0) {
30403
+ parts.push(`stderr: ${stderrStr}`);
30404
+ }
30405
+ return new ToolExecutionError(parts.join(" | "), { stdout, stderr: stderr4, exitCode });
30406
+ }
30407
+ function createValidationError(toolName, zodError) {
30408
+ const parts = [];
30409
+ for (let i = 0; i < zodError.issues.length; i++) {
30410
+ const issue = zodError.issues[i];
30411
+ if (issue === void 0) continue;
30412
+ const path = issue.path.length > 0 ? issue.path.map(String).join(".") : "(root)";
30413
+ parts.push(`${path}: ${issue.message}`);
30414
+ }
30415
+ const detail = parts.length > 0 ? parts.join("; ") : "unknown validation error";
30416
+ return new Error(`${toolName}: invalid options \u2014 ${detail}`);
30417
+ }
30373
30418
  function killTree(pid) {
30374
30419
  try {
30375
30420
  kill__default.default(pid);
@@ -30531,39 +30576,6 @@ function resolveBinary(toolName) {
30531
30576
  const binaryName2 = isWindows2 ? `${toolName}.exe` : toolName;
30532
30577
  return ok(path.join(pathResult.value, binaryName2));
30533
30578
  }
30534
-
30535
- // src/tools/_toolError.ts
30536
- var MAX_ARGS_LENGTH = 200;
30537
- var MAX_STDERR_LENGTH = 500;
30538
- function truncate(value, maxLength) {
30539
- if (value.length <= maxLength) {
30540
- return value;
30541
- }
30542
- return `${value.substring(0, maxLength)}...`;
30543
- }
30544
- function createToolError(toolName, args, exitCode, stderr4) {
30545
- const argsStr = truncate(args.join(" "), MAX_ARGS_LENGTH);
30546
- const stderrStr = truncate(stderr4.trim(), MAX_STDERR_LENGTH);
30547
- const parts = [`${toolName} failed (exit code ${String(exitCode)})`];
30548
- if (argsStr.length > 0) {
30549
- parts.push(`args: ${argsStr}`);
30550
- }
30551
- if (stderrStr.length > 0) {
30552
- parts.push(`stderr: ${stderrStr}`);
30553
- }
30554
- return new Error(parts.join(" | "));
30555
- }
30556
- function createValidationError(toolName, zodError) {
30557
- const parts = [];
30558
- for (let i = 0; i < zodError.issues.length; i++) {
30559
- const issue = zodError.issues[i];
30560
- if (issue === void 0) continue;
30561
- const path = issue.path.length > 0 ? issue.path.map(String).join(".") : "(root)";
30562
- parts.push(`${path}: ${issue.message}`);
30563
- }
30564
- const detail = parts.length > 0 ? parts.join("; ") : "unknown validation error";
30565
- return new Error(`${toolName}: invalid options \u2014 ${detail}`);
30566
- }
30567
30579
  var PN_REPS = ["Alphabetic", "Ideographic", "Phonetic"];
30568
30580
  var ARRAY_TAG_NAMES = /* @__PURE__ */ new Set(["DicomAttribute", "Value", "PersonName", "Item"]);
30569
30581
  var KNOWN_VR_CODES = /* @__PURE__ */ new Set([
@@ -30876,15 +30888,17 @@ async function dcm2json(inputPath, options) {
30876
30888
  }
30877
30889
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
30878
30890
  const signal = options?.signal;
30891
+ const startTime = Date.now();
30892
+ const remaining = () => Math.max(1e3, timeoutMs - (Date.now() - startTime));
30879
30893
  const verbosity = options?.verbosity;
30880
30894
  if (options?.directOnly === true) {
30881
- return tryDirectPath(inputPath, timeoutMs, signal, verbosity);
30895
+ return tryDirectPath(inputPath, remaining(), signal, verbosity);
30882
30896
  }
30883
- const xmlResult = await tryXmlPath(inputPath, timeoutMs, signal, buildXmlOpts(options));
30897
+ const xmlResult = await tryXmlPath(inputPath, remaining(), signal, buildXmlOpts(options));
30884
30898
  if (xmlResult.ok) {
30885
30899
  return xmlResult;
30886
30900
  }
30887
- return tryDirectPath(inputPath, timeoutMs, signal, verbosity);
30901
+ return tryDirectPath(inputPath, remaining(), signal, verbosity);
30888
30902
  }
30889
30903
  var TAG_OR_PATH_PATTERN = /^\([0-9A-Fa-f]{4},[0-9A-Fa-f]{4}\)(\[\d+\]\.\([0-9A-Fa-f]{4},[0-9A-Fa-f]{4}\))*(\[\d+\])?$/;
30890
30904
  var TagModificationSchema = zod.z.object({