@ubercode/dcmtk 0.14.0 → 0.15.1

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/tools.cjs CHANGED
@@ -14,7 +14,54 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
15
  var kill__default = /*#__PURE__*/_interopDefault(kill);
16
16
 
17
- // src/tools/dcm2xml.ts
17
+ var __defProp = Object.defineProperty;
18
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
19
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
20
+
21
+ // src/tools/_toolError.ts
22
+ var MAX_ARGS_LENGTH = 200;
23
+ var MAX_STDERR_LENGTH = 500;
24
+ function truncate(value, maxLength) {
25
+ if (value.length <= maxLength) {
26
+ return value;
27
+ }
28
+ return `${value.substring(0, maxLength)}...`;
29
+ }
30
+ var ToolExecutionError = class extends Error {
31
+ constructor(message, details) {
32
+ super(message);
33
+ __publicField(this, "stdout");
34
+ __publicField(this, "stderr");
35
+ __publicField(this, "exitCode");
36
+ this.name = "ToolExecutionError";
37
+ this.stdout = details.stdout;
38
+ this.stderr = details.stderr;
39
+ this.exitCode = details.exitCode;
40
+ }
41
+ };
42
+ function createToolError(toolName, args, exitCode, stderr3, stdout = "") {
43
+ const argsStr = truncate(args.join(" "), MAX_ARGS_LENGTH);
44
+ const stderrStr = truncate(stderr3.trim(), MAX_STDERR_LENGTH);
45
+ const parts = [`${toolName} failed (exit code ${String(exitCode)})`];
46
+ if (argsStr.length > 0) {
47
+ parts.push(`args: ${argsStr}`);
48
+ }
49
+ if (stderrStr.length > 0) {
50
+ parts.push(`stderr: ${stderrStr}`);
51
+ }
52
+ return new ToolExecutionError(parts.join(" | "), { stdout, stderr: stderr3, exitCode });
53
+ }
54
+ function createValidationError(toolName, zodError) {
55
+ const parts = [];
56
+ for (let i = 0; i < zodError.issues.length; i++) {
57
+ const issue = zodError.issues[i];
58
+ if (issue === void 0) continue;
59
+ const path = issue.path.length > 0 ? issue.path.map(String).join(".") : "(root)";
60
+ parts.push(`${path}: ${issue.message}`);
61
+ }
62
+ const detail = parts.length > 0 ? parts.join("; ") : "unknown validation error";
63
+ return new Error(`${toolName}: invalid options \u2014 ${detail}`);
64
+ }
18
65
 
19
66
  // src/types.ts
20
67
  function ok(value) {
@@ -210,39 +257,6 @@ function resolveBinary(toolName) {
210
257
  return ok(path.join(pathResult.value, binaryName2));
211
258
  }
212
259
 
213
- // src/tools/_toolError.ts
214
- var MAX_ARGS_LENGTH = 200;
215
- var MAX_STDERR_LENGTH = 500;
216
- function truncate(value, maxLength) {
217
- if (value.length <= maxLength) {
218
- return value;
219
- }
220
- return `${value.substring(0, maxLength)}...`;
221
- }
222
- function createToolError(toolName, args, exitCode, stderr3) {
223
- const argsStr = truncate(args.join(" "), MAX_ARGS_LENGTH);
224
- const stderrStr = truncate(stderr3.trim(), MAX_STDERR_LENGTH);
225
- const parts = [`${toolName} failed (exit code ${String(exitCode)})`];
226
- if (argsStr.length > 0) {
227
- parts.push(`args: ${argsStr}`);
228
- }
229
- if (stderrStr.length > 0) {
230
- parts.push(`stderr: ${stderrStr}`);
231
- }
232
- return new Error(parts.join(" | "));
233
- }
234
- function createValidationError(toolName, zodError) {
235
- const parts = [];
236
- for (let i = 0; i < zodError.issues.length; i++) {
237
- const issue = zodError.issues[i];
238
- if (issue === void 0) continue;
239
- const path = issue.path.length > 0 ? issue.path.map(String).join(".") : "(root)";
240
- parts.push(`${path}: ${issue.message}`);
241
- }
242
- const detail = parts.length > 0 ? parts.join("; ") : "unknown validation error";
243
- return new Error(`${toolName}: invalid options \u2014 ${detail}`);
244
- }
245
-
246
260
  // src/tools/dcm2xml.ts
247
261
  var Dcm2xmlCharset = {
248
262
  /** Use UTF-8 encoding (default). */
@@ -352,8 +366,14 @@ var KNOWN_VR_CODES = /* @__PURE__ */ new Set([
352
366
  "UT",
353
367
  "UV"
354
368
  ]);
369
+ function decodeXmlEntities(value) {
370
+ return value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
371
+ }
372
+ function decodeIfString(value) {
373
+ return typeof value === "string" ? decodeXmlEntities(value) : value;
374
+ }
355
375
  function buildPnString(comp) {
356
- const parts = [comp.FamilyName ?? "", comp.GivenName ?? "", comp.MiddleName ?? "", comp.NamePrefix ?? "", comp.NameSuffix ?? ""];
376
+ const parts = [comp.FamilyName ?? "", comp.GivenName ?? "", comp.MiddleName ?? "", comp.NamePrefix ?? "", comp.NameSuffix ?? ""].map(decodeXmlEntities);
357
377
  let last = parts.length - 1;
358
378
  for (; last >= 0; last--) {
359
379
  if (parts[last] !== "") break;
@@ -392,9 +412,9 @@ function convertBulkDataURI(attr, element) {
392
412
  const bulkArray = toArray(attr.BulkDataURI);
393
413
  const firstBulk = bulkArray[0];
394
414
  if (typeof firstBulk === "object" && firstBulk !== null && "@_uri" in firstBulk) {
395
- element.BulkDataURI = safeString(firstBulk["@_uri"]);
415
+ element.BulkDataURI = decodeXmlEntities(safeString(firstBulk["@_uri"]));
396
416
  } else {
397
- element.BulkDataURI = safeString(firstBulk);
417
+ element.BulkDataURI = decodeXmlEntities(safeString(firstBulk));
398
418
  }
399
419
  }
400
420
  function convertPNValue(attr, element) {
@@ -438,7 +458,7 @@ function convertRegularValue(attr, element, vr) {
438
458
  const values = [];
439
459
  const isNumeric = NUMERIC_JSON_VRS.has(vr);
440
460
  for (const v of valArray) {
441
- const unwrapped = unwrapValue(v);
461
+ const unwrapped = decodeIfString(unwrapValue(v));
442
462
  values.push(isNumeric ? coerceNumeric(unwrapped) : unwrapped);
443
463
  }
444
464
  if (values.length > 0) element.Value = values;
@@ -2364,7 +2384,7 @@ async function dcmsend(options) {
2364
2384
  return err(result.error);
2365
2385
  }
2366
2386
  if (result.value.exitCode !== 0) {
2367
- return err(createToolError("dcmsend", args, result.value.exitCode, result.value.stderr));
2387
+ return err(createToolError("dcmsend", args, result.value.exitCode, result.value.stderr, result.value.stdout));
2368
2388
  }
2369
2389
  return ok({ success: true, stdout: result.value.stdout, stderr: result.value.stderr });
2370
2390
  }
@@ -2519,10 +2539,10 @@ async function storescu(options) {
2519
2539
  return err(result.error);
2520
2540
  }
2521
2541
  if (result.value.exitCode !== 0) {
2522
- return err(createToolError("storescu", args, result.value.exitCode, result.value.stderr));
2542
+ return err(createToolError("storescu", args, result.value.exitCode, result.value.stderr, result.value.stdout));
2523
2543
  }
2524
2544
  if (DIMSE_ERROR_PATTERN.test(result.value.stderr)) {
2525
- return err(createToolError("storescu", args, 0, result.value.stderr));
2545
+ return err(createToolError("storescu", args, 0, result.value.stderr, result.value.stdout));
2526
2546
  }
2527
2547
  return ok({ success: true, stdout: result.value.stdout, stderr: result.value.stderr });
2528
2548
  }
@@ -3426,6 +3446,7 @@ exports.LutType = LutType;
3426
3446
  exports.MoveQueryModel = MoveQueryModel;
3427
3447
  exports.ProposedTransferSyntax = ProposedTransferSyntax;
3428
3448
  exports.QueryModel = QueryModel;
3449
+ exports.ToolExecutionError = ToolExecutionError;
3429
3450
  exports.TransferSyntax = TransferSyntax;
3430
3451
  exports.cda2dcm = cda2dcm;
3431
3452
  exports.dcm2cda = dcm2cda;