@ubercode/dcmtk 0.2.0 → 0.4.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/index.js CHANGED
@@ -36,7 +36,7 @@ function mapResult(result, fn) {
36
36
 
37
37
  // src/patterns.ts
38
38
  var DICOM_TAG_PATTERN = /^\([0-9A-Fa-f]{4},[0-9A-Fa-f]{4}\)$/;
39
- var AE_TITLE_PATTERN = /^[A-Za-z0-9 -]+$/;
39
+ var AE_TITLE_PATTERN = /^[\x20-\x5b\x5d-\x7e]+$/;
40
40
  var UID_PATTERN = /^[0-9]+(\.[0-9]+)*$/;
41
41
  var TAG_PATH_SEGMENT = /\([0-9A-Fa-f]{4},[0-9A-Fa-f]{4}\)(\[\d+\])?/;
42
42
  var DICOM_TAG_PATH_PATTERN = new RegExp(`^${TAG_PATH_SEGMENT.source}(\\.${TAG_PATH_SEGMENT.source})*$`);
@@ -69,7 +69,7 @@ function createAETitle(input) {
69
69
  return err(new Error(`Invalid AE Title: "${input}". Must be ${AE_TITLE_MIN_LENGTH}-${AE_TITLE_MAX_LENGTH} characters`));
70
70
  }
71
71
  if (!AE_TITLE_PATTERN.test(input)) {
72
- return err(new Error(`Invalid AE Title: "${input}". Only letters, digits, spaces, and hyphens are allowed`));
72
+ return err(new Error(`Invalid AE Title: "${input}". Only printable ASCII characters (no backslash) are allowed`));
73
73
  }
74
74
  return ok(input);
75
75
  }
@@ -31103,19 +31103,17 @@ var Dcm2xmlCharset = {
31103
31103
  /** Use ASCII encoding. */
31104
31104
  ASCII: "ascii"
31105
31105
  };
31106
+ var VERBOSITY_FLAGS = { verbose: "-v", debug: "-d" };
31106
31107
  var Dcm2xmlOptionsSchema = z.object({
31107
31108
  timeoutMs: z.number().int().positive().optional(),
31108
31109
  signal: z.instanceof(AbortSignal).optional(),
31109
31110
  namespace: z.boolean().optional(),
31110
31111
  charset: z.enum(["utf8", "latin1", "ascii"]).optional(),
31111
31112
  writeBinaryData: z.boolean().optional(),
31112
- encodeBinaryBase64: z.boolean().optional()
31113
+ encodeBinaryBase64: z.boolean().optional(),
31114
+ verbosity: z.enum(["verbose", "debug"]).optional()
31113
31115
  }).strict().optional();
31114
- function buildArgs(inputPath, options) {
31115
- const args = [];
31116
- if (options?.namespace === true) {
31117
- args.push("+Xn");
31118
- }
31116
+ function pushEncodingArgs(args, options) {
31119
31117
  if (options?.charset === "latin1") {
31120
31118
  args.push("+Cl");
31121
31119
  } else if (options?.charset === "ascii") {
@@ -31127,6 +31125,16 @@ function buildArgs(inputPath, options) {
31127
31125
  args.push("+Eb");
31128
31126
  }
31129
31127
  }
31128
+ }
31129
+ function buildArgs(inputPath, options) {
31130
+ const args = [];
31131
+ if (options?.verbosity !== void 0) {
31132
+ args.push(VERBOSITY_FLAGS[options.verbosity]);
31133
+ }
31134
+ if (options?.namespace === true) {
31135
+ args.push("+Xn");
31136
+ }
31137
+ pushEncodingArgs(args, options);
31130
31138
  args.push(inputPath);
31131
31139
  return args;
31132
31140
  }
@@ -31357,19 +31365,28 @@ function repairJson(raw) {
31357
31365
  var Dcm2jsonOptionsSchema = z.object({
31358
31366
  timeoutMs: z.number().int().positive().optional(),
31359
31367
  signal: z.instanceof(AbortSignal).optional(),
31360
- directOnly: z.boolean().optional()
31368
+ directOnly: z.boolean().optional(),
31369
+ verbosity: z.enum(["verbose", "debug"]).optional()
31361
31370
  }).strict().optional();
31362
- async function tryXmlPath(inputPath, timeoutMs, signal) {
31371
+ var VERBOSITY_FLAGS2 = { verbose: "-v", debug: "-d" };
31372
+ function buildVerbosityArgs(verbosity) {
31373
+ if (verbosity !== void 0) {
31374
+ return [VERBOSITY_FLAGS2[verbosity]];
31375
+ }
31376
+ return [];
31377
+ }
31378
+ async function tryXmlPath(inputPath, timeoutMs, signal, verbosity) {
31363
31379
  const xmlBinary = resolveBinary("dcm2xml");
31364
31380
  if (!xmlBinary.ok) {
31365
31381
  return err(xmlBinary.error);
31366
31382
  }
31367
- const xmlResult = await execCommand(xmlBinary.value, ["-nat", inputPath], { timeoutMs, signal });
31383
+ const xmlArgs = [...buildVerbosityArgs(verbosity), "-nat", inputPath];
31384
+ const xmlResult = await execCommand(xmlBinary.value, xmlArgs, { timeoutMs, signal });
31368
31385
  if (!xmlResult.ok) {
31369
31386
  return err(xmlResult.error);
31370
31387
  }
31371
31388
  if (xmlResult.value.exitCode !== 0) {
31372
- return err(createToolError("dcm2xml", ["-nat", inputPath], xmlResult.value.exitCode, xmlResult.value.stderr));
31389
+ return err(createToolError("dcm2xml", xmlArgs, xmlResult.value.exitCode, xmlResult.value.stderr));
31373
31390
  }
31374
31391
  const jsonResult = xmlToJson(xmlResult.value.stdout);
31375
31392
  if (!jsonResult.ok) {
@@ -31377,17 +31394,18 @@ async function tryXmlPath(inputPath, timeoutMs, signal) {
31377
31394
  }
31378
31395
  return ok({ data: jsonResult.value, source: "xml" });
31379
31396
  }
31380
- async function tryDirectPath(inputPath, timeoutMs, signal) {
31397
+ async function tryDirectPath(inputPath, timeoutMs, signal, verbosity) {
31381
31398
  const jsonBinary = resolveBinary("dcm2json");
31382
31399
  if (!jsonBinary.ok) {
31383
31400
  return err(jsonBinary.error);
31384
31401
  }
31385
- const result = await execCommand(jsonBinary.value, [inputPath], { timeoutMs, signal });
31402
+ const directArgs = [...buildVerbosityArgs(verbosity), inputPath];
31403
+ const result = await execCommand(jsonBinary.value, directArgs, { timeoutMs, signal });
31386
31404
  if (!result.ok) {
31387
31405
  return err(result.error);
31388
31406
  }
31389
31407
  if (result.value.exitCode !== 0) {
31390
- return err(createToolError("dcm2json", [inputPath], result.value.exitCode, result.value.stderr));
31408
+ return err(createToolError("dcm2json", directArgs, result.value.exitCode, result.value.stderr));
31391
31409
  }
31392
31410
  try {
31393
31411
  const repaired = repairJson(result.value.stdout);
@@ -31404,14 +31422,15 @@ async function dcm2json(inputPath, options) {
31404
31422
  }
31405
31423
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31406
31424
  const signal = options?.signal;
31425
+ const verbosity = options?.verbosity;
31407
31426
  if (options?.directOnly === true) {
31408
- return tryDirectPath(inputPath, timeoutMs, signal);
31427
+ return tryDirectPath(inputPath, timeoutMs, signal, verbosity);
31409
31428
  }
31410
- const xmlResult = await tryXmlPath(inputPath, timeoutMs, signal);
31429
+ const xmlResult = await tryXmlPath(inputPath, timeoutMs, signal, verbosity);
31411
31430
  if (xmlResult.ok) {
31412
31431
  return xmlResult;
31413
31432
  }
31414
- return tryDirectPath(inputPath, timeoutMs, signal);
31433
+ return tryDirectPath(inputPath, timeoutMs, signal, verbosity);
31415
31434
  }
31416
31435
  var DcmdumpFormat = {
31417
31436
  /** Print standard DCMTK format. */
@@ -31419,16 +31438,17 @@ var DcmdumpFormat = {
31419
31438
  /** Print tag and value only. */
31420
31439
  SHORT: "short"
31421
31440
  };
31441
+ var VERBOSITY_FLAGS3 = { verbose: "-v", debug: "-d" };
31422
31442
  var DcmdumpOptionsSchema = z.object({
31423
31443
  timeoutMs: z.number().int().positive().optional(),
31424
31444
  signal: z.instanceof(AbortSignal).optional(),
31425
31445
  format: z.enum(["standard", "short"]).optional(),
31426
31446
  allTags: z.boolean().optional(),
31427
31447
  searchTag: z.string().regex(/^\([0-9A-Fa-f]{4},[0-9A-Fa-f]{4}\)$/).optional(),
31428
- printValues: z.boolean().optional()
31448
+ printValues: z.boolean().optional(),
31449
+ verbosity: z.enum(["verbose", "debug"]).optional()
31429
31450
  }).strict().optional();
31430
- function buildArgs2(inputPath, options) {
31431
- const args = [];
31451
+ function pushDisplayArgs(args, options) {
31432
31452
  if (options?.format === "short") {
31433
31453
  args.push("+L");
31434
31454
  }
@@ -31442,6 +31462,13 @@ function buildArgs2(inputPath, options) {
31442
31462
  if (options?.printValues === true) {
31443
31463
  args.push("+Vr");
31444
31464
  }
31465
+ }
31466
+ function buildArgs2(inputPath, options) {
31467
+ const args = [];
31468
+ if (options?.verbosity !== void 0) {
31469
+ args.push(VERBOSITY_FLAGS3[options.verbosity]);
31470
+ }
31471
+ pushDisplayArgs(args, options);
31445
31472
  args.push(inputPath);
31446
31473
  return args;
31447
31474
  }
@@ -31488,7 +31515,8 @@ var VALID_TRANSFER_SYNTAXES = ["+ti", "+te", "+tb", "+tl", "+t2", "+tr", "+td"];
31488
31515
  var DcmconvOptionsSchema = z.object({
31489
31516
  timeoutMs: z.number().int().positive().optional(),
31490
31517
  signal: z.instanceof(AbortSignal).optional(),
31491
- transferSyntax: z.enum(VALID_TRANSFER_SYNTAXES)
31518
+ transferSyntax: z.enum(VALID_TRANSFER_SYNTAXES),
31519
+ verbosity: z.enum(["verbose", "debug"]).optional()
31492
31520
  }).strict();
31493
31521
  async function dcmconv(inputPath, outputPath, options) {
31494
31522
  const validation = DcmconvOptionsSchema.safeParse(options);
@@ -31499,7 +31527,13 @@ async function dcmconv(inputPath, outputPath, options) {
31499
31527
  if (!binaryResult.ok) {
31500
31528
  return err(binaryResult.error);
31501
31529
  }
31502
- const args = [options.transferSyntax, inputPath, outputPath];
31530
+ const args = [];
31531
+ if (options.verbosity === "verbose") {
31532
+ args.push("-v");
31533
+ } else if (options.verbosity === "debug") {
31534
+ args.push("-d");
31535
+ }
31536
+ args.push(options.transferSyntax, inputPath, outputPath);
31503
31537
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31504
31538
  const result = await execCommand(binaryResult.value, args, {
31505
31539
  timeoutMs,
@@ -31518,6 +31552,7 @@ var TagModificationSchema = z.object({
31518
31552
  tag: z.string().regex(TAG_OR_PATH_PATTERN),
31519
31553
  value: z.string()
31520
31554
  });
31555
+ var VERBOSITY_FLAGS4 = { verbose: "-v", debug: "-d" };
31521
31556
  var DcmodifyOptionsSchema = z.object({
31522
31557
  timeoutMs: z.number().int().positive().optional(),
31523
31558
  signal: z.instanceof(AbortSignal).optional(),
@@ -31526,12 +31561,16 @@ var DcmodifyOptionsSchema = z.object({
31526
31561
  erasePrivateTags: z.boolean().optional(),
31527
31562
  noBackup: z.boolean().optional(),
31528
31563
  insertIfMissing: z.boolean().optional(),
31529
- ignoreMissingTags: z.boolean().optional()
31564
+ ignoreMissingTags: z.boolean().optional(),
31565
+ verbosity: z.enum(["verbose", "debug"]).optional()
31530
31566
  }).strict().refine((data) => data.modifications.length > 0 || data.erasures !== void 0 && data.erasures.length > 0 || data.erasePrivateTags === true, {
31531
31567
  message: "At least one of modifications, erasures, or erasePrivateTags is required"
31532
31568
  });
31533
31569
  function buildArgs3(inputPath, options) {
31534
31570
  const args = [];
31571
+ if (options.verbosity !== void 0) {
31572
+ args.push(VERBOSITY_FLAGS4[options.verbosity]);
31573
+ }
31535
31574
  if (options.noBackup !== false) {
31536
31575
  args.push("-nb");
31537
31576
  }
@@ -31579,8 +31618,18 @@ async function dcmodify(inputPath, options) {
31579
31618
  }
31580
31619
  var DcmftestOptionsSchema = z.object({
31581
31620
  timeoutMs: z.number().int().positive().optional(),
31582
- signal: z.instanceof(AbortSignal).optional()
31621
+ signal: z.instanceof(AbortSignal).optional(),
31622
+ verbosity: z.enum(["verbose", "debug"]).optional()
31583
31623
  }).strict().optional();
31624
+ var VERBOSITY_FLAGS5 = { verbose: "-v", debug: "-d" };
31625
+ function buildArgs4(inputPath, options) {
31626
+ const args = [];
31627
+ if (options?.verbosity !== void 0) {
31628
+ args.push(VERBOSITY_FLAGS5[options.verbosity]);
31629
+ }
31630
+ args.push(inputPath);
31631
+ return args;
31632
+ }
31584
31633
  async function dcmftest(inputPath, options) {
31585
31634
  const validation = DcmftestOptionsSchema.safeParse(options);
31586
31635
  if (!validation.success) {
@@ -31590,7 +31639,7 @@ async function dcmftest(inputPath, options) {
31590
31639
  if (!binaryResult.ok) {
31591
31640
  return err(binaryResult.error);
31592
31641
  }
31593
- const args = [inputPath];
31642
+ const args = buildArgs4(inputPath, options);
31594
31643
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31595
31644
  const result = await execCommand(binaryResult.value, args, {
31596
31645
  timeoutMs,
@@ -31614,10 +31663,16 @@ var DcmgpdirOptionsSchema = z.object({
31614
31663
  filesetId: z.string().min(1).optional(),
31615
31664
  inputDirectory: z.string().min(1).optional(),
31616
31665
  mapFilenames: z.boolean().optional(),
31617
- inventAttributes: z.boolean().optional()
31666
+ inventAttributes: z.boolean().optional(),
31667
+ verbosity: z.enum(["verbose", "debug"]).optional()
31618
31668
  }).strict();
31619
- function buildArgs4(options) {
31669
+ function buildArgs5(options) {
31620
31670
  const args = [];
31671
+ if (options.verbosity === "verbose") {
31672
+ args.push("-v");
31673
+ } else if (options.verbosity === "debug") {
31674
+ args.push("-d");
31675
+ }
31621
31676
  if (options.outputFile !== void 0) {
31622
31677
  args.push("+D", options.outputFile);
31623
31678
  }
@@ -31645,7 +31700,7 @@ async function dcmgpdir(options) {
31645
31700
  if (!binaryResult.ok) {
31646
31701
  return err(binaryResult.error);
31647
31702
  }
31648
- const args = buildArgs4(options);
31703
+ const args = buildArgs5(options);
31649
31704
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31650
31705
  const result = await execCommand(binaryResult.value, args, {
31651
31706
  timeoutMs,
@@ -31670,10 +31725,16 @@ var DcmmkdirOptionsSchema = z.object({
31670
31725
  append: z.boolean().optional(),
31671
31726
  inputDirectory: z.string().min(1).optional(),
31672
31727
  mapFilenames: z.boolean().optional(),
31673
- inventAttributes: z.boolean().optional()
31728
+ inventAttributes: z.boolean().optional(),
31729
+ verbosity: z.enum(["verbose", "debug"]).optional()
31674
31730
  }).strict();
31675
- function buildArgs5(options) {
31731
+ function buildArgs6(options) {
31676
31732
  const args = [];
31733
+ if (options.verbosity === "verbose") {
31734
+ args.push("-v");
31735
+ } else if (options.verbosity === "debug") {
31736
+ args.push("-d");
31737
+ }
31677
31738
  if (options.outputFile !== void 0) {
31678
31739
  args.push("+D", options.outputFile);
31679
31740
  }
@@ -31704,7 +31765,7 @@ async function dcmmkdir(options) {
31704
31765
  if (!binaryResult.ok) {
31705
31766
  return err(binaryResult.error);
31706
31767
  }
31707
- const args = buildArgs5(options);
31768
+ const args = buildArgs6(options);
31708
31769
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31709
31770
  const result = await execCommand(binaryResult.value, args, {
31710
31771
  timeoutMs,
@@ -31725,12 +31786,18 @@ var DcmqridxOptionsSchema = z.object({
31725
31786
  indexDirectory: z.string().min(1),
31726
31787
  inputFiles: z.array(z.string().min(1)).min(1).optional(),
31727
31788
  print: z.boolean().optional(),
31728
- notNew: z.boolean().optional()
31789
+ notNew: z.boolean().optional(),
31790
+ verbosity: z.enum(["verbose", "debug"]).optional()
31729
31791
  }).strict().refine((data) => data.inputFiles !== void 0 && data.inputFiles.length > 0 || data.print === true, {
31730
31792
  message: "Either inputFiles (non-empty) or print must be specified"
31731
31793
  });
31732
- function buildArgs6(options) {
31794
+ function buildArgs7(options) {
31733
31795
  const args = [];
31796
+ if (options.verbosity === "verbose") {
31797
+ args.push("-v");
31798
+ } else if (options.verbosity === "debug") {
31799
+ args.push("-d");
31800
+ }
31734
31801
  if (options.print === true) {
31735
31802
  args.push("-p");
31736
31803
  }
@@ -31752,7 +31819,7 @@ async function dcmqridx(options) {
31752
31819
  if (!binaryResult.ok) {
31753
31820
  return err(binaryResult.error);
31754
31821
  }
31755
- const args = buildArgs6(options);
31822
+ const args = buildArgs7(options);
31756
31823
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31757
31824
  const result = await execCommand(binaryResult.value, args, {
31758
31825
  timeoutMs,
@@ -31772,11 +31839,17 @@ async function dcmqridx(options) {
31772
31839
  var Xml2dcmOptionsSchema = z.object({
31773
31840
  timeoutMs: z.number().int().positive().optional(),
31774
31841
  signal: z.instanceof(AbortSignal).optional(),
31842
+ verbosity: z.enum(["verbose", "debug"]).optional(),
31775
31843
  generateNewUIDs: z.boolean().optional(),
31776
31844
  validateDocument: z.boolean().optional()
31777
31845
  }).strict().optional();
31778
- function buildArgs7(inputPath, outputPath, options) {
31846
+ function buildArgs8(inputPath, outputPath, options) {
31779
31847
  const args = [];
31848
+ if (options?.verbosity === "verbose") {
31849
+ args.push("-v");
31850
+ } else if (options?.verbosity === "debug") {
31851
+ args.push("-d");
31852
+ }
31780
31853
  if (options?.generateNewUIDs === true) {
31781
31854
  args.push("+Ug");
31782
31855
  }
@@ -31795,7 +31868,7 @@ async function xml2dcm(inputPath, outputPath, options) {
31795
31868
  if (!binaryResult.ok) {
31796
31869
  return err(binaryResult.error);
31797
31870
  }
31798
- const args = buildArgs7(inputPath, outputPath, options);
31871
+ const args = buildArgs8(inputPath, outputPath, options);
31799
31872
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31800
31873
  const result = await execCommand(binaryResult.value, args, {
31801
31874
  timeoutMs,
@@ -31811,8 +31884,18 @@ async function xml2dcm(inputPath, outputPath, options) {
31811
31884
  }
31812
31885
  var Json2dcmOptionsSchema = z.object({
31813
31886
  timeoutMs: z.number().int().positive().optional(),
31814
- signal: z.instanceof(AbortSignal).optional()
31887
+ signal: z.instanceof(AbortSignal).optional(),
31888
+ verbosity: z.enum(["verbose", "debug"]).optional()
31815
31889
  }).strict().optional();
31890
+ var VERBOSITY_FLAGS6 = { verbose: "-v", debug: "-d" };
31891
+ function buildArgs9(inputPath, outputPath, options) {
31892
+ const args = [];
31893
+ if (options?.verbosity !== void 0) {
31894
+ args.push(VERBOSITY_FLAGS6[options.verbosity]);
31895
+ }
31896
+ args.push(inputPath, outputPath);
31897
+ return args;
31898
+ }
31816
31899
  async function json2dcm(inputPath, outputPath, options) {
31817
31900
  const validation = Json2dcmOptionsSchema.safeParse(options);
31818
31901
  if (!validation.success) {
@@ -31822,7 +31905,7 @@ async function json2dcm(inputPath, outputPath, options) {
31822
31905
  if (!binaryResult.ok) {
31823
31906
  return err(binaryResult.error);
31824
31907
  }
31825
- const args = [inputPath, outputPath];
31908
+ const args = buildArgs9(inputPath, outputPath, options);
31826
31909
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31827
31910
  const result = await execCommand(binaryResult.value, args, {
31828
31911
  timeoutMs,
@@ -31839,11 +31922,17 @@ async function json2dcm(inputPath, outputPath, options) {
31839
31922
  var Dump2dcmOptionsSchema = z.object({
31840
31923
  timeoutMs: z.number().int().positive().optional(),
31841
31924
  signal: z.instanceof(AbortSignal).optional(),
31925
+ verbosity: z.enum(["verbose", "debug"]).optional(),
31842
31926
  generateNewUIDs: z.boolean().optional(),
31843
31927
  writeFileFormat: z.boolean().optional()
31844
31928
  }).strict().optional();
31845
- function buildArgs8(inputPath, outputPath, options) {
31929
+ function buildArgs10(inputPath, outputPath, options) {
31846
31930
  const args = [];
31931
+ if (options?.verbosity === "verbose") {
31932
+ args.push("-v");
31933
+ } else if (options?.verbosity === "debug") {
31934
+ args.push("-d");
31935
+ }
31847
31936
  if (options?.generateNewUIDs === true) {
31848
31937
  args.push("+Ug");
31849
31938
  }
@@ -31862,7 +31951,7 @@ async function dump2dcm(inputPath, outputPath, options) {
31862
31951
  if (!binaryResult.ok) {
31863
31952
  return err(binaryResult.error);
31864
31953
  }
31865
- const args = buildArgs8(inputPath, outputPath, options);
31954
+ const args = buildArgs10(inputPath, outputPath, options);
31866
31955
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31867
31956
  const result = await execCommand(binaryResult.value, args, {
31868
31957
  timeoutMs,
@@ -31885,6 +31974,7 @@ var Img2dcmInputFormat = {
31885
31974
  var Img2dcmOptionsSchema = z.object({
31886
31975
  timeoutMs: z.number().int().positive().optional(),
31887
31976
  signal: z.instanceof(AbortSignal).optional(),
31977
+ verbosity: z.enum(["verbose", "debug"]).optional(),
31888
31978
  inputFormat: z.enum(["jpeg", "bmp"]).optional(),
31889
31979
  datasetFrom: z.string().min(1).optional()
31890
31980
  }).strict().optional();
@@ -31892,8 +31982,13 @@ var FORMAT_FLAG_MAP = {
31892
31982
  jpeg: "JPEG",
31893
31983
  bmp: "BMP"
31894
31984
  };
31895
- function buildArgs9(inputPath, outputPath, options) {
31985
+ function buildArgs11(inputPath, outputPath, options) {
31896
31986
  const args = [];
31987
+ if (options?.verbosity === "verbose") {
31988
+ args.push("-v");
31989
+ } else if (options?.verbosity === "debug") {
31990
+ args.push("-d");
31991
+ }
31897
31992
  if (options?.inputFormat !== void 0) {
31898
31993
  args.push("-i", FORMAT_FLAG_MAP[options.inputFormat]);
31899
31994
  }
@@ -31912,7 +32007,7 @@ async function img2dcm(inputPath, outputPath, options) {
31912
32007
  if (!binaryResult.ok) {
31913
32008
  return err(binaryResult.error);
31914
32009
  }
31915
- const args = buildArgs9(inputPath, outputPath, options);
32010
+ const args = buildArgs11(inputPath, outputPath, options);
31916
32011
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31917
32012
  const result = await execCommand(binaryResult.value, args, {
31918
32013
  timeoutMs,
@@ -31928,8 +32023,18 @@ async function img2dcm(inputPath, outputPath, options) {
31928
32023
  }
31929
32024
  var Pdf2dcmOptionsSchema = z.object({
31930
32025
  timeoutMs: z.number().int().positive().optional(),
31931
- signal: z.instanceof(AbortSignal).optional()
32026
+ signal: z.instanceof(AbortSignal).optional(),
32027
+ verbosity: z.enum(["verbose", "debug"]).optional()
31932
32028
  }).strict().optional();
32029
+ var VERBOSITY_FLAGS7 = { verbose: "-v", debug: "-d" };
32030
+ function buildArgs12(inputPath, outputPath, options) {
32031
+ const args = [];
32032
+ if (options?.verbosity !== void 0) {
32033
+ args.push(VERBOSITY_FLAGS7[options.verbosity]);
32034
+ }
32035
+ args.push(inputPath, outputPath);
32036
+ return args;
32037
+ }
31933
32038
  async function pdf2dcm(inputPath, outputPath, options) {
31934
32039
  const validation = Pdf2dcmOptionsSchema.safeParse(options);
31935
32040
  if (!validation.success) {
@@ -31939,7 +32044,7 @@ async function pdf2dcm(inputPath, outputPath, options) {
31939
32044
  if (!binaryResult.ok) {
31940
32045
  return err(binaryResult.error);
31941
32046
  }
31942
- const args = [inputPath, outputPath];
32047
+ const args = buildArgs12(inputPath, outputPath, options);
31943
32048
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31944
32049
  const result = await execCommand(binaryResult.value, args, {
31945
32050
  timeoutMs,
@@ -31955,8 +32060,18 @@ async function pdf2dcm(inputPath, outputPath, options) {
31955
32060
  }
31956
32061
  var Dcm2pdfOptionsSchema = z.object({
31957
32062
  timeoutMs: z.number().int().positive().optional(),
31958
- signal: z.instanceof(AbortSignal).optional()
32063
+ signal: z.instanceof(AbortSignal).optional(),
32064
+ verbosity: z.enum(["verbose", "debug"]).optional()
31959
32065
  }).strict().optional();
32066
+ var VERBOSITY_FLAGS8 = { verbose: "-v", debug: "-d" };
32067
+ function buildArgs13(inputPath, outputPath, options) {
32068
+ const args = [];
32069
+ if (options?.verbosity !== void 0) {
32070
+ args.push(VERBOSITY_FLAGS8[options.verbosity]);
32071
+ }
32072
+ args.push(inputPath, outputPath);
32073
+ return args;
32074
+ }
31960
32075
  async function dcm2pdf(inputPath, outputPath, options) {
31961
32076
  const validation = Dcm2pdfOptionsSchema.safeParse(options);
31962
32077
  if (!validation.success) {
@@ -31966,7 +32081,7 @@ async function dcm2pdf(inputPath, outputPath, options) {
31966
32081
  if (!binaryResult.ok) {
31967
32082
  return err(binaryResult.error);
31968
32083
  }
31969
- const args = [inputPath, outputPath];
32084
+ const args = buildArgs13(inputPath, outputPath, options);
31970
32085
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31971
32086
  const result = await execCommand(binaryResult.value, args, {
31972
32087
  timeoutMs,
@@ -31982,8 +32097,18 @@ async function dcm2pdf(inputPath, outputPath, options) {
31982
32097
  }
31983
32098
  var Cda2dcmOptionsSchema = z.object({
31984
32099
  timeoutMs: z.number().int().positive().optional(),
31985
- signal: z.instanceof(AbortSignal).optional()
32100
+ signal: z.instanceof(AbortSignal).optional(),
32101
+ verbosity: z.enum(["verbose", "debug"]).optional()
31986
32102
  }).strict().optional();
32103
+ var VERBOSITY_FLAGS9 = { verbose: "-v", debug: "-d" };
32104
+ function buildArgs14(inputPath, outputPath, options) {
32105
+ const args = [];
32106
+ if (options?.verbosity !== void 0) {
32107
+ args.push(VERBOSITY_FLAGS9[options.verbosity]);
32108
+ }
32109
+ args.push(inputPath, outputPath);
32110
+ return args;
32111
+ }
31987
32112
  async function cda2dcm(inputPath, outputPath, options) {
31988
32113
  const validation = Cda2dcmOptionsSchema.safeParse(options);
31989
32114
  if (!validation.success) {
@@ -31993,7 +32118,7 @@ async function cda2dcm(inputPath, outputPath, options) {
31993
32118
  if (!binaryResult.ok) {
31994
32119
  return err(binaryResult.error);
31995
32120
  }
31996
- const args = [inputPath, outputPath];
32121
+ const args = buildArgs14(inputPath, outputPath, options);
31997
32122
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31998
32123
  const result = await execCommand(binaryResult.value, args, {
31999
32124
  timeoutMs,
@@ -32009,8 +32134,18 @@ async function cda2dcm(inputPath, outputPath, options) {
32009
32134
  }
32010
32135
  var Dcm2cdaOptionsSchema = z.object({
32011
32136
  timeoutMs: z.number().int().positive().optional(),
32012
- signal: z.instanceof(AbortSignal).optional()
32137
+ signal: z.instanceof(AbortSignal).optional(),
32138
+ verbosity: z.enum(["verbose", "debug"]).optional()
32013
32139
  }).strict().optional();
32140
+ var VERBOSITY_FLAGS10 = { verbose: "-v", debug: "-d" };
32141
+ function buildArgs15(inputPath, outputPath, options) {
32142
+ const args = [];
32143
+ if (options?.verbosity !== void 0) {
32144
+ args.push(VERBOSITY_FLAGS10[options.verbosity]);
32145
+ }
32146
+ args.push(inputPath, outputPath);
32147
+ return args;
32148
+ }
32014
32149
  async function dcm2cda(inputPath, outputPath, options) {
32015
32150
  const validation = Dcm2cdaOptionsSchema.safeParse(options);
32016
32151
  if (!validation.success) {
@@ -32020,7 +32155,7 @@ async function dcm2cda(inputPath, outputPath, options) {
32020
32155
  if (!binaryResult.ok) {
32021
32156
  return err(binaryResult.error);
32022
32157
  }
32023
- const args = [inputPath, outputPath];
32158
+ const args = buildArgs15(inputPath, outputPath, options);
32024
32159
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32025
32160
  const result = await execCommand(binaryResult.value, args, {
32026
32161
  timeoutMs,
@@ -32036,8 +32171,18 @@ async function dcm2cda(inputPath, outputPath, options) {
32036
32171
  }
32037
32172
  var Stl2dcmOptionsSchema = z.object({
32038
32173
  timeoutMs: z.number().int().positive().optional(),
32039
- signal: z.instanceof(AbortSignal).optional()
32174
+ signal: z.instanceof(AbortSignal).optional(),
32175
+ verbosity: z.enum(["verbose", "debug"]).optional()
32040
32176
  }).strict().optional();
32177
+ var VERBOSITY_FLAGS11 = { verbose: "-v", debug: "-d" };
32178
+ function buildArgs16(inputPath, outputPath, options) {
32179
+ const args = [];
32180
+ if (options?.verbosity !== void 0) {
32181
+ args.push(VERBOSITY_FLAGS11[options.verbosity]);
32182
+ }
32183
+ args.push(inputPath, outputPath);
32184
+ return args;
32185
+ }
32041
32186
  async function stl2dcm(inputPath, outputPath, options) {
32042
32187
  const validation = Stl2dcmOptionsSchema.safeParse(options);
32043
32188
  if (!validation.success) {
@@ -32047,7 +32192,7 @@ async function stl2dcm(inputPath, outputPath, options) {
32047
32192
  if (!binaryResult.ok) {
32048
32193
  return err(binaryResult.error);
32049
32194
  }
32050
- const args = [inputPath, outputPath];
32195
+ const args = buildArgs16(inputPath, outputPath, options);
32051
32196
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32052
32197
  const result = await execCommand(binaryResult.value, args, {
32053
32198
  timeoutMs,
@@ -32064,10 +32209,16 @@ async function stl2dcm(inputPath, outputPath, options) {
32064
32209
  var DcmcrleOptionsSchema = z.object({
32065
32210
  timeoutMs: z.number().int().positive().optional(),
32066
32211
  signal: z.instanceof(AbortSignal).optional(),
32067
- uidAlways: z.boolean().optional()
32212
+ uidAlways: z.boolean().optional(),
32213
+ verbosity: z.enum(["verbose", "debug"]).optional()
32068
32214
  }).strict().optional();
32069
- function buildArgs10(inputPath, outputPath, options) {
32215
+ function buildArgs17(inputPath, outputPath, options) {
32070
32216
  const args = [];
32217
+ if (options?.verbosity === "verbose") {
32218
+ args.push("-v");
32219
+ } else if (options?.verbosity === "debug") {
32220
+ args.push("-d");
32221
+ }
32071
32222
  if (options?.uidAlways === true) {
32072
32223
  args.push("+ua");
32073
32224
  }
@@ -32083,7 +32234,7 @@ async function dcmcrle(inputPath, outputPath, options) {
32083
32234
  if (!binaryResult.ok) {
32084
32235
  return err(binaryResult.error);
32085
32236
  }
32086
- const args = buildArgs10(inputPath, outputPath, options);
32237
+ const args = buildArgs17(inputPath, outputPath, options);
32087
32238
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32088
32239
  const result = await execCommand(binaryResult.value, args, {
32089
32240
  timeoutMs,
@@ -32100,10 +32251,16 @@ async function dcmcrle(inputPath, outputPath, options) {
32100
32251
  var DcmdrleOptionsSchema = z.object({
32101
32252
  timeoutMs: z.number().int().positive().optional(),
32102
32253
  signal: z.instanceof(AbortSignal).optional(),
32103
- uidAlways: z.boolean().optional()
32254
+ uidAlways: z.boolean().optional(),
32255
+ verbosity: z.enum(["verbose", "debug"]).optional()
32104
32256
  }).strict().optional();
32105
- function buildArgs11(inputPath, outputPath, options) {
32257
+ function buildArgs18(inputPath, outputPath, options) {
32106
32258
  const args = [];
32259
+ if (options?.verbosity === "verbose") {
32260
+ args.push("-v");
32261
+ } else if (options?.verbosity === "debug") {
32262
+ args.push("-d");
32263
+ }
32107
32264
  if (options?.uidAlways === true) {
32108
32265
  args.push("+ua");
32109
32266
  }
@@ -32119,7 +32276,7 @@ async function dcmdrle(inputPath, outputPath, options) {
32119
32276
  if (!binaryResult.ok) {
32120
32277
  return err(binaryResult.error);
32121
32278
  }
32122
- const args = buildArgs11(inputPath, outputPath, options);
32279
+ const args = buildArgs18(inputPath, outputPath, options);
32123
32280
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32124
32281
  const result = await execCommand(binaryResult.value, args, {
32125
32282
  timeoutMs,
@@ -32136,10 +32293,16 @@ async function dcmdrle(inputPath, outputPath, options) {
32136
32293
  var DcmencapOptionsSchema = z.object({
32137
32294
  timeoutMs: z.number().int().positive().optional(),
32138
32295
  signal: z.instanceof(AbortSignal).optional(),
32139
- documentTitle: z.string().optional()
32296
+ documentTitle: z.string().optional(),
32297
+ verbosity: z.enum(["verbose", "debug"]).optional()
32140
32298
  }).strict().optional();
32141
- function buildArgs12(inputPath, outputPath, options) {
32299
+ function buildArgs19(inputPath, outputPath, options) {
32142
32300
  const args = [];
32301
+ if (options?.verbosity === "verbose") {
32302
+ args.push("-v");
32303
+ } else if (options?.verbosity === "debug") {
32304
+ args.push("-d");
32305
+ }
32143
32306
  if (options?.documentTitle !== void 0) {
32144
32307
  args.push("--title", options.documentTitle);
32145
32308
  }
@@ -32155,7 +32318,7 @@ async function dcmencap(inputPath, outputPath, options) {
32155
32318
  if (!binaryResult.ok) {
32156
32319
  return err(binaryResult.error);
32157
32320
  }
32158
- const args = buildArgs12(inputPath, outputPath, options);
32321
+ const args = buildArgs19(inputPath, outputPath, options);
32159
32322
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32160
32323
  const result = await execCommand(binaryResult.value, args, {
32161
32324
  timeoutMs,
@@ -32171,8 +32334,19 @@ async function dcmencap(inputPath, outputPath, options) {
32171
32334
  }
32172
32335
  var DcmdecapOptionsSchema = z.object({
32173
32336
  timeoutMs: z.number().int().positive().optional(),
32174
- signal: z.instanceof(AbortSignal).optional()
32337
+ signal: z.instanceof(AbortSignal).optional(),
32338
+ verbosity: z.enum(["verbose", "debug"]).optional()
32175
32339
  }).strict().optional();
32340
+ function buildArgs20(inputPath, outputPath, options) {
32341
+ const args = [];
32342
+ if (options?.verbosity === "verbose") {
32343
+ args.push("-v");
32344
+ } else if (options?.verbosity === "debug") {
32345
+ args.push("-d");
32346
+ }
32347
+ args.push(inputPath, outputPath);
32348
+ return args;
32349
+ }
32176
32350
  async function dcmdecap(inputPath, outputPath, options) {
32177
32351
  const validation = DcmdecapOptionsSchema.safeParse(options);
32178
32352
  if (!validation.success) {
@@ -32182,7 +32356,7 @@ async function dcmdecap(inputPath, outputPath, options) {
32182
32356
  if (!binaryResult.ok) {
32183
32357
  return err(binaryResult.error);
32184
32358
  }
32185
- const args = [inputPath, outputPath];
32359
+ const args = buildArgs20(inputPath, outputPath, options);
32186
32360
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32187
32361
  const result = await execCommand(binaryResult.value, args, {
32188
32362
  timeoutMs,
@@ -32200,10 +32374,19 @@ var DcmcjpegOptionsSchema = z.object({
32200
32374
  timeoutMs: z.number().int().positive().optional(),
32201
32375
  signal: z.instanceof(AbortSignal).optional(),
32202
32376
  quality: z.number().int().min(1).max(100).optional(),
32203
- lossless: z.boolean().optional()
32377
+ lossless: z.boolean().optional(),
32378
+ progressive: z.boolean().optional(),
32379
+ verbosity: z.enum(["verbose", "debug"]).optional()
32204
32380
  }).strict().optional();
32205
- function buildArgs13(inputPath, outputPath, options) {
32381
+ var VERBOSITY_FLAGS12 = { verbose: "-v", debug: "-d" };
32382
+ function buildArgs21(inputPath, outputPath, options) {
32206
32383
  const args = [];
32384
+ if (options?.verbosity !== void 0) {
32385
+ args.push(VERBOSITY_FLAGS12[options.verbosity]);
32386
+ }
32387
+ if (options?.progressive === true) {
32388
+ args.push("+p");
32389
+ }
32207
32390
  if (options?.lossless === true) {
32208
32391
  args.push("+e1");
32209
32392
  }
@@ -32222,7 +32405,7 @@ async function dcmcjpeg(inputPath, outputPath, options) {
32222
32405
  if (!binaryResult.ok) {
32223
32406
  return err(binaryResult.error);
32224
32407
  }
32225
- const args = buildArgs13(inputPath, outputPath, options);
32408
+ const args = buildArgs21(inputPath, outputPath, options);
32226
32409
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32227
32410
  const result = await execCommand(binaryResult.value, args, {
32228
32411
  timeoutMs,
@@ -32252,10 +32435,16 @@ var COLOR_CONVERSION_FLAGS = {
32252
32435
  var DcmdjpegOptionsSchema = z.object({
32253
32436
  timeoutMs: z.number().int().positive().optional(),
32254
32437
  signal: z.instanceof(AbortSignal).optional(),
32255
- colorConversion: z.enum(["photometric", "always", "never"]).optional()
32438
+ colorConversion: z.enum(["photometric", "always", "never"]).optional(),
32439
+ verbosity: z.enum(["verbose", "debug"]).optional()
32256
32440
  }).strict().optional();
32257
- function buildArgs14(inputPath, outputPath, options) {
32441
+ function buildArgs22(inputPath, outputPath, options) {
32258
32442
  const args = [];
32443
+ if (options?.verbosity === "verbose") {
32444
+ args.push("-v");
32445
+ } else if (options?.verbosity === "debug") {
32446
+ args.push("-d");
32447
+ }
32259
32448
  if (options?.colorConversion !== void 0) {
32260
32449
  args.push(COLOR_CONVERSION_FLAGS[options.colorConversion]);
32261
32450
  }
@@ -32271,7 +32460,7 @@ async function dcmdjpeg(inputPath, outputPath, options) {
32271
32460
  if (!binaryResult.ok) {
32272
32461
  return err(binaryResult.error);
32273
32462
  }
32274
- const args = buildArgs14(inputPath, outputPath, options);
32463
+ const args = buildArgs22(inputPath, outputPath, options);
32275
32464
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32276
32465
  const result = await execCommand(binaryResult.value, args, {
32277
32466
  timeoutMs,
@@ -32289,10 +32478,15 @@ var DcmcjplsOptionsSchema = z.object({
32289
32478
  timeoutMs: z.number().int().positive().optional(),
32290
32479
  signal: z.instanceof(AbortSignal).optional(),
32291
32480
  lossless: z.boolean().optional(),
32292
- maxDeviation: z.number().int().min(0).optional()
32481
+ maxDeviation: z.number().int().min(0).optional(),
32482
+ verbosity: z.enum(["verbose", "debug"]).optional()
32293
32483
  }).strict().optional();
32294
- function buildArgs15(inputPath, outputPath, options) {
32484
+ var VERBOSITY_FLAGS13 = { verbose: "-v", debug: "-d" };
32485
+ function buildArgs23(inputPath, outputPath, options) {
32295
32486
  const args = [];
32487
+ if (options?.verbosity !== void 0) {
32488
+ args.push(VERBOSITY_FLAGS13[options.verbosity]);
32489
+ }
32296
32490
  if (options?.lossless === false) {
32297
32491
  args.push("+en");
32298
32492
  } else if (options?.lossless === true) {
@@ -32313,7 +32507,7 @@ async function dcmcjpls(inputPath, outputPath, options) {
32313
32507
  if (!binaryResult.ok) {
32314
32508
  return err(binaryResult.error);
32315
32509
  }
32316
- const args = buildArgs15(inputPath, outputPath, options);
32510
+ const args = buildArgs23(inputPath, outputPath, options);
32317
32511
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32318
32512
  const result = await execCommand(binaryResult.value, args, {
32319
32513
  timeoutMs,
@@ -32343,10 +32537,16 @@ var JPLS_COLOR_CONVERSION_FLAGS = {
32343
32537
  var DcmdjplsOptionsSchema = z.object({
32344
32538
  timeoutMs: z.number().int().positive().optional(),
32345
32539
  signal: z.instanceof(AbortSignal).optional(),
32346
- colorConversion: z.enum(["photometric", "always", "never"]).optional()
32540
+ colorConversion: z.enum(["photometric", "always", "never"]).optional(),
32541
+ verbosity: z.enum(["verbose", "debug"]).optional()
32347
32542
  }).strict().optional();
32348
- function buildArgs16(inputPath, outputPath, options) {
32543
+ function buildArgs24(inputPath, outputPath, options) {
32349
32544
  const args = [];
32545
+ if (options?.verbosity === "verbose") {
32546
+ args.push("-v");
32547
+ } else if (options?.verbosity === "debug") {
32548
+ args.push("-d");
32549
+ }
32350
32550
  if (options?.colorConversion !== void 0) {
32351
32551
  args.push(JPLS_COLOR_CONVERSION_FLAGS[options.colorConversion]);
32352
32552
  }
@@ -32362,7 +32562,7 @@ async function dcmdjpls(inputPath, outputPath, options) {
32362
32562
  if (!binaryResult.ok) {
32363
32563
  return err(binaryResult.error);
32364
32564
  }
32365
- const args = buildArgs16(inputPath, outputPath, options);
32565
+ const args = buildArgs24(inputPath, outputPath, options);
32366
32566
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32367
32567
  const result = await execCommand(binaryResult.value, args, {
32368
32568
  timeoutMs,
@@ -32381,6 +32581,8 @@ var Dcmj2pnmOutputFormat = {
32381
32581
  PNM: "pnm",
32382
32582
  /** PNG format. */
32383
32583
  PNG: "png",
32584
+ /** 16-bit PNG format. */
32585
+ PNG_16BIT: "png16",
32384
32586
  /** BMP format. */
32385
32587
  BMP: "bmp",
32386
32588
  /** TIFF format. */
@@ -32391,6 +32593,7 @@ var Dcmj2pnmOutputFormat = {
32391
32593
  var OUTPUT_FORMAT_FLAGS = {
32392
32594
  pnm: "+op",
32393
32595
  png: "+on",
32596
+ png16: "+on2",
32394
32597
  bmp: "+ob",
32395
32598
  tiff: "+ot",
32396
32599
  jpeg: "+oj"
@@ -32398,17 +32601,32 @@ var OUTPUT_FORMAT_FLAGS = {
32398
32601
  var Dcmj2pnmOptionsSchema = z.object({
32399
32602
  timeoutMs: z.number().int().positive().optional(),
32400
32603
  signal: z.instanceof(AbortSignal).optional(),
32401
- outputFormat: z.enum(["pnm", "png", "bmp", "tiff", "jpeg"]).optional(),
32402
- frame: z.number().int().min(0).max(65535).optional()
32403
- }).strict().optional();
32404
- function buildArgs17(inputPath, outputPath, options) {
32604
+ outputFormat: z.enum(["pnm", "png", "png16", "bmp", "tiff", "jpeg"]).optional(),
32605
+ frame: z.number().int().min(0).max(65535).optional(),
32606
+ windowCenter: z.number().optional(),
32607
+ windowWidth: z.number().optional(),
32608
+ verbosity: z.enum(["verbose", "debug"]).optional()
32609
+ }).strict().refine((data) => data?.windowCenter === void 0 === (data?.windowWidth === void 0), {
32610
+ message: "windowCenter and windowWidth must be provided together"
32611
+ }).optional();
32612
+ var VERBOSITY_FLAGS14 = { verbose: "-v", debug: "-d" };
32613
+ function pushWindowArgs(args, options) {
32614
+ if (options?.windowCenter !== void 0 && options?.windowWidth !== void 0) {
32615
+ args.push("+Wl", String(options.windowCenter), String(options.windowWidth));
32616
+ }
32617
+ }
32618
+ function buildArgs25(inputPath, outputPath, options) {
32405
32619
  const args = [];
32620
+ if (options?.verbosity !== void 0) {
32621
+ args.push(VERBOSITY_FLAGS14[options.verbosity]);
32622
+ }
32406
32623
  if (options?.outputFormat !== void 0) {
32407
32624
  args.push(OUTPUT_FORMAT_FLAGS[options.outputFormat]);
32408
32625
  }
32409
32626
  if (options?.frame !== void 0) {
32410
32627
  args.push("+F", String(options.frame));
32411
32628
  }
32629
+ pushWindowArgs(args, options);
32412
32630
  args.push(inputPath, outputPath);
32413
32631
  return args;
32414
32632
  }
@@ -32417,11 +32635,12 @@ async function dcmj2pnm(inputPath, outputPath, options) {
32417
32635
  if (!validation.success) {
32418
32636
  return err(createValidationError("dcmj2pnm", validation.error));
32419
32637
  }
32420
- const binaryResult = resolveBinary("dcmj2pnm");
32638
+ const dcm2imgResult = resolveBinary("dcm2img");
32639
+ const binaryResult = dcm2imgResult.ok ? dcm2imgResult : resolveBinary("dcmj2pnm");
32421
32640
  if (!binaryResult.ok) {
32422
32641
  return err(binaryResult.error);
32423
32642
  }
32424
- const args = buildArgs17(inputPath, outputPath, options);
32643
+ const args = buildArgs25(inputPath, outputPath, options);
32425
32644
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32426
32645
  const result = await execCommand(binaryResult.value, args, {
32427
32646
  timeoutMs,
@@ -32440,6 +32659,8 @@ var Dcm2pnmOutputFormat = {
32440
32659
  PNM: "pnm",
32441
32660
  /** PNG format. */
32442
32661
  PNG: "png",
32662
+ /** 16-bit PNG format. */
32663
+ PNG_16BIT: "png16",
32443
32664
  /** BMP format. */
32444
32665
  BMP: "bmp",
32445
32666
  /** TIFF format. */
@@ -32448,23 +32669,39 @@ var Dcm2pnmOutputFormat = {
32448
32669
  var DCM2PNM_FORMAT_FLAGS = {
32449
32670
  pnm: "+op",
32450
32671
  png: "+on",
32672
+ png16: "+on2",
32451
32673
  bmp: "+ob",
32452
32674
  tiff: "+ot"
32453
32675
  };
32454
32676
  var Dcm2pnmOptionsSchema = z.object({
32455
32677
  timeoutMs: z.number().int().positive().optional(),
32456
32678
  signal: z.instanceof(AbortSignal).optional(),
32457
- outputFormat: z.enum(["pnm", "png", "bmp", "tiff"]).optional(),
32458
- frame: z.number().int().min(0).max(65535).optional()
32459
- }).strict().optional();
32460
- function buildArgs18(inputPath, outputPath, options) {
32679
+ outputFormat: z.enum(["pnm", "png", "png16", "bmp", "tiff"]).optional(),
32680
+ frame: z.number().int().min(0).max(65535).optional(),
32681
+ windowCenter: z.number().optional(),
32682
+ windowWidth: z.number().optional(),
32683
+ verbosity: z.enum(["verbose", "debug"]).optional()
32684
+ }).strict().refine((data) => data?.windowCenter === void 0 === (data?.windowWidth === void 0), {
32685
+ message: "windowCenter and windowWidth must be provided together"
32686
+ }).optional();
32687
+ var VERBOSITY_FLAGS15 = { verbose: "-v", debug: "-d" };
32688
+ function pushWindowArgs2(args, options) {
32689
+ if (options?.windowCenter !== void 0 && options?.windowWidth !== void 0) {
32690
+ args.push("+Wl", String(options.windowCenter), String(options.windowWidth));
32691
+ }
32692
+ }
32693
+ function buildArgs26(inputPath, outputPath, options) {
32461
32694
  const args = [];
32695
+ if (options?.verbosity !== void 0) {
32696
+ args.push(VERBOSITY_FLAGS15[options.verbosity]);
32697
+ }
32462
32698
  if (options?.outputFormat !== void 0) {
32463
32699
  args.push(DCM2PNM_FORMAT_FLAGS[options.outputFormat]);
32464
32700
  }
32465
32701
  if (options?.frame !== void 0) {
32466
32702
  args.push("+F", String(options.frame));
32467
32703
  }
32704
+ pushWindowArgs2(args, options);
32468
32705
  args.push(inputPath, outputPath);
32469
32706
  return args;
32470
32707
  }
@@ -32473,11 +32710,12 @@ async function dcm2pnm(inputPath, outputPath, options) {
32473
32710
  if (!validation.success) {
32474
32711
  return err(createValidationError("dcm2pnm", validation.error));
32475
32712
  }
32476
- const binaryResult = resolveBinary("dcm2pnm");
32713
+ const dcm2imgResult = resolveBinary("dcm2img");
32714
+ const binaryResult = dcm2imgResult.ok ? dcm2imgResult : resolveBinary("dcm2pnm");
32477
32715
  if (!binaryResult.ok) {
32478
32716
  return err(binaryResult.error);
32479
32717
  }
32480
- const args = buildArgs18(inputPath, outputPath, options);
32718
+ const args = buildArgs26(inputPath, outputPath, options);
32481
32719
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32482
32720
  const result = await execCommand(binaryResult.value, args, {
32483
32721
  timeoutMs,
@@ -32497,10 +32735,11 @@ var DcmscaleOptionsSchema = z.object({
32497
32735
  xFactor: z.number().positive().max(100).optional(),
32498
32736
  yFactor: z.number().positive().max(100).optional(),
32499
32737
  xSize: z.number().int().positive().optional(),
32500
- ySize: z.number().int().positive().optional()
32738
+ ySize: z.number().int().positive().optional(),
32739
+ verbosity: z.enum(["verbose", "debug"]).optional()
32501
32740
  }).strict().optional();
32502
- function buildArgs19(inputPath, outputPath, options) {
32503
- const args = [];
32741
+ var VERBOSITY_FLAGS16 = { verbose: "-v", debug: "-d" };
32742
+ function pushScalingArgs(args, options) {
32504
32743
  if (options?.xFactor !== void 0) {
32505
32744
  args.push("+Sxf", String(options.xFactor));
32506
32745
  }
@@ -32513,6 +32752,13 @@ function buildArgs19(inputPath, outputPath, options) {
32513
32752
  if (options?.ySize !== void 0) {
32514
32753
  args.push("+Syv", String(options.ySize));
32515
32754
  }
32755
+ }
32756
+ function buildArgs27(inputPath, outputPath, options) {
32757
+ const args = [];
32758
+ if (options?.verbosity !== void 0) {
32759
+ args.push(VERBOSITY_FLAGS16[options.verbosity]);
32760
+ }
32761
+ pushScalingArgs(args, options);
32516
32762
  args.push(inputPath, outputPath);
32517
32763
  return args;
32518
32764
  }
@@ -32525,7 +32771,7 @@ async function dcmscale(inputPath, outputPath, options) {
32525
32771
  if (!binaryResult.ok) {
32526
32772
  return err(binaryResult.error);
32527
32773
  }
32528
- const args = buildArgs19(inputPath, outputPath, options);
32774
+ const args = buildArgs27(inputPath, outputPath, options);
32529
32775
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32530
32776
  const result = await execCommand(binaryResult.value, args, {
32531
32777
  timeoutMs,
@@ -32543,10 +32789,16 @@ var DcmquantOptionsSchema = z.object({
32543
32789
  timeoutMs: z.number().int().positive().optional(),
32544
32790
  signal: z.instanceof(AbortSignal).optional(),
32545
32791
  colors: z.number().int().min(2).max(65536).optional(),
32546
- frame: z.number().int().min(0).max(65535).optional()
32792
+ frame: z.number().int().min(0).max(65535).optional(),
32793
+ verbosity: z.enum(["verbose", "debug"]).optional()
32547
32794
  }).strict().optional();
32548
- function buildArgs20(inputPath, outputPath, options) {
32795
+ function buildArgs28(inputPath, outputPath, options) {
32549
32796
  const args = [];
32797
+ if (options?.verbosity === "verbose") {
32798
+ args.push("-v");
32799
+ } else if (options?.verbosity === "debug") {
32800
+ args.push("-d");
32801
+ }
32550
32802
  if (options?.colors !== void 0) {
32551
32803
  args.push("+pc", String(options.colors));
32552
32804
  }
@@ -32565,7 +32817,7 @@ async function dcmquant(inputPath, outputPath, options) {
32565
32817
  if (!binaryResult.ok) {
32566
32818
  return err(binaryResult.error);
32567
32819
  }
32568
- const args = buildArgs20(inputPath, outputPath, options);
32820
+ const args = buildArgs28(inputPath, outputPath, options);
32569
32821
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32570
32822
  const result = await execCommand(binaryResult.value, args, {
32571
32823
  timeoutMs,
@@ -32585,10 +32837,11 @@ var DcmdspfnOptionsSchema = z.object({
32585
32837
  monitorFile: z.string().min(1).optional(),
32586
32838
  cameraFile: z.string().min(1).optional(),
32587
32839
  printerFile: z.string().min(1).optional(),
32588
- ambientLight: z.number().positive().optional()
32840
+ ambientLight: z.number().positive().optional(),
32841
+ verbosity: z.enum(["verbose", "debug"]).optional()
32589
32842
  }).strict().optional();
32590
- function buildArgs21(options) {
32591
- const args = [];
32843
+ var VERBOSITY_FLAGS17 = { verbose: "-v", debug: "-d" };
32844
+ function pushDeviceArgs(args, options) {
32592
32845
  if (options?.monitorFile !== void 0) {
32593
32846
  args.push("+Im", options.monitorFile);
32594
32847
  }
@@ -32601,6 +32854,13 @@ function buildArgs21(options) {
32601
32854
  if (options?.ambientLight !== void 0) {
32602
32855
  args.push("+Ca", String(options.ambientLight));
32603
32856
  }
32857
+ }
32858
+ function buildArgs29(options) {
32859
+ const args = [];
32860
+ if (options?.verbosity !== void 0) {
32861
+ args.push(VERBOSITY_FLAGS17[options.verbosity]);
32862
+ }
32863
+ pushDeviceArgs(args, options);
32604
32864
  return args;
32605
32865
  }
32606
32866
  async function dcmdspfn(options) {
@@ -32612,7 +32872,7 @@ async function dcmdspfn(options) {
32612
32872
  if (!binaryResult.ok) {
32613
32873
  return err(binaryResult.error);
32614
32874
  }
32615
- const args = buildArgs21(options);
32875
+ const args = buildArgs29(options);
32616
32876
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32617
32877
  const result = await execCommand(binaryResult.value, args, {
32618
32878
  timeoutMs,
@@ -32628,8 +32888,19 @@ async function dcmdspfn(options) {
32628
32888
  }
32629
32889
  var Dcod2lumOptionsSchema = z.object({
32630
32890
  timeoutMs: z.number().int().positive().optional(),
32631
- signal: z.instanceof(AbortSignal).optional()
32891
+ signal: z.instanceof(AbortSignal).optional(),
32892
+ verbosity: z.enum(["verbose", "debug"]).optional()
32632
32893
  }).strict().optional();
32894
+ function buildArgs30(inputPath, outputPath, options) {
32895
+ const args = [];
32896
+ if (options?.verbosity === "verbose") {
32897
+ args.push("-v");
32898
+ } else if (options?.verbosity === "debug") {
32899
+ args.push("-d");
32900
+ }
32901
+ args.push(inputPath, outputPath);
32902
+ return args;
32903
+ }
32633
32904
  async function dcod2lum(inputPath, outputPath, options) {
32634
32905
  const validation = Dcod2lumOptionsSchema.safeParse(options);
32635
32906
  if (!validation.success) {
@@ -32639,7 +32910,7 @@ async function dcod2lum(inputPath, outputPath, options) {
32639
32910
  if (!binaryResult.ok) {
32640
32911
  return err(binaryResult.error);
32641
32912
  }
32642
- const args = [inputPath, outputPath];
32913
+ const args = buildArgs30(inputPath, outputPath, options);
32643
32914
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32644
32915
  const result = await execCommand(binaryResult.value, args, {
32645
32916
  timeoutMs,
@@ -32656,10 +32927,16 @@ async function dcod2lum(inputPath, outputPath, options) {
32656
32927
  var DconvlumOptionsSchema = z.object({
32657
32928
  timeoutMs: z.number().int().positive().optional(),
32658
32929
  signal: z.instanceof(AbortSignal).optional(),
32659
- ambientLight: z.number().positive().optional()
32930
+ ambientLight: z.number().positive().optional(),
32931
+ verbosity: z.enum(["verbose", "debug"]).optional()
32660
32932
  }).strict().optional();
32661
- function buildArgs22(inputPath, outputPath, options) {
32933
+ function buildArgs31(inputPath, outputPath, options) {
32662
32934
  const args = [];
32935
+ if (options?.verbosity === "verbose") {
32936
+ args.push("-v");
32937
+ } else if (options?.verbosity === "debug") {
32938
+ args.push("-d");
32939
+ }
32663
32940
  if (options?.ambientLight !== void 0) {
32664
32941
  args.push("+Ca", String(options.ambientLight));
32665
32942
  }
@@ -32675,7 +32952,7 @@ async function dconvlum(inputPath, outputPath, options) {
32675
32952
  if (!binaryResult.ok) {
32676
32953
  return err(binaryResult.error);
32677
32954
  }
32678
- const args = buildArgs22(inputPath, outputPath, options);
32955
+ const args = buildArgs31(inputPath, outputPath, options);
32679
32956
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32680
32957
  const result = await execCommand(binaryResult.value, args, {
32681
32958
  timeoutMs,
@@ -32695,10 +32972,42 @@ var EchoscuOptionsSchema = z.object({
32695
32972
  host: z.string().min(1),
32696
32973
  port: z.number().int().min(1).max(65535),
32697
32974
  callingAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
32698
- calledAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional()
32975
+ calledAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
32976
+ verbosity: z.enum(["verbose", "debug"]).optional(),
32977
+ maxPduReceive: z.number().int().min(4096).max(131072).optional(),
32978
+ maxPduSend: z.number().int().min(4096).max(131072).optional(),
32979
+ associationTimeout: z.number().int().positive().optional(),
32980
+ acseTimeout: z.number().int().positive().optional(),
32981
+ dimseTimeout: z.number().int().positive().optional(),
32982
+ noHostnameLookup: z.boolean().optional()
32699
32983
  }).strict();
32700
- function buildArgs23(options) {
32984
+ var VERBOSITY_FLAGS18 = { verbose: "-v", debug: "-d" };
32985
+ function pushNetworkArgs(args, options) {
32986
+ if (options.verbosity !== void 0) {
32987
+ args.push(VERBOSITY_FLAGS18[options.verbosity]);
32988
+ }
32989
+ if (options.maxPduReceive !== void 0) {
32990
+ args.push("--max-pdu", String(options.maxPduReceive));
32991
+ }
32992
+ if (options.maxPduSend !== void 0) {
32993
+ args.push("--max-send-pdu", String(options.maxPduSend));
32994
+ }
32995
+ if (options.associationTimeout !== void 0) {
32996
+ args.push("-to", String(options.associationTimeout));
32997
+ }
32998
+ if (options.acseTimeout !== void 0) {
32999
+ args.push("-ta", String(options.acseTimeout));
33000
+ }
33001
+ if (options.dimseTimeout !== void 0) {
33002
+ args.push("-td", String(options.dimseTimeout));
33003
+ }
33004
+ if (options.noHostnameLookup === true) {
33005
+ args.push("-nh");
33006
+ }
33007
+ }
33008
+ function buildArgs32(options) {
32701
33009
  const args = [];
33010
+ pushNetworkArgs(args, options);
32702
33011
  if (options.callingAETitle !== void 0) {
32703
33012
  args.push("-aet", options.callingAETitle);
32704
33013
  }
@@ -32717,7 +33026,7 @@ async function echoscu(options) {
32717
33026
  if (!binaryResult.ok) {
32718
33027
  return err(binaryResult.error);
32719
33028
  }
32720
- const args = buildArgs23(options);
33029
+ const args = buildArgs32(options);
32721
33030
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32722
33031
  const result = await execCommand(binaryResult.value, args, {
32723
33032
  timeoutMs,
@@ -32731,6 +33040,7 @@ async function echoscu(options) {
32731
33040
  }
32732
33041
  return ok({ success: true, stderr: result.value.stderr });
32733
33042
  }
33043
+ var VERBOSITY_FLAGS19 = { verbose: "-v", debug: "-d" };
32734
33044
  var DcmsendOptionsSchema = z.object({
32735
33045
  timeoutMs: z.number().int().positive().optional(),
32736
33046
  signal: z.instanceof(AbortSignal).optional(),
@@ -32739,16 +33049,51 @@ var DcmsendOptionsSchema = z.object({
32739
33049
  files: z.array(z.string().min(1).refine(isSafePath, { message: "path traversal detected in file path" })).min(1),
32740
33050
  callingAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
32741
33051
  calledAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
32742
- scanDirectory: z.boolean().optional()
33052
+ scanDirectory: z.boolean().optional(),
33053
+ verbosity: z.enum(["verbose", "debug"]).optional(),
33054
+ noUidChecks: z.boolean().optional(),
33055
+ maxPduReceive: z.number().int().min(4096).max(131072).optional(),
33056
+ maxPduSend: z.number().int().min(4096).max(131072).optional(),
33057
+ noHostnameLookup: z.boolean().optional(),
33058
+ associationTimeout: z.number().int().positive().optional(),
33059
+ acseTimeout: z.number().int().positive().optional(),
33060
+ dimseTimeout: z.number().int().positive().optional()
32743
33061
  }).strict();
32744
- function buildArgs24(options) {
32745
- const args = [];
33062
+ function pushNetworkArgs2(args, options) {
32746
33063
  if (options.callingAETitle !== void 0) {
32747
33064
  args.push("-aet", options.callingAETitle);
32748
33065
  }
32749
33066
  if (options.calledAETitle !== void 0) {
32750
33067
  args.push("-aec", options.calledAETitle);
32751
33068
  }
33069
+ if (options.noUidChecks === true) {
33070
+ args.push("--no-uid-checks");
33071
+ }
33072
+ if (options.maxPduReceive !== void 0) {
33073
+ args.push("--max-pdu", String(options.maxPduReceive));
33074
+ }
33075
+ if (options.maxPduSend !== void 0) {
33076
+ args.push("--max-send-pdu", String(options.maxPduSend));
33077
+ }
33078
+ if (options.noHostnameLookup === true) {
33079
+ args.push("-nh");
33080
+ }
33081
+ if (options.associationTimeout !== void 0) {
33082
+ args.push("-to", String(options.associationTimeout));
33083
+ }
33084
+ if (options.acseTimeout !== void 0) {
33085
+ args.push("-ta", String(options.acseTimeout));
33086
+ }
33087
+ if (options.dimseTimeout !== void 0) {
33088
+ args.push("-td", String(options.dimseTimeout));
33089
+ }
33090
+ }
33091
+ function buildArgs33(options) {
33092
+ const args = [];
33093
+ if (options.verbosity !== void 0) {
33094
+ args.push(VERBOSITY_FLAGS19[options.verbosity]);
33095
+ }
33096
+ pushNetworkArgs2(args, options);
32752
33097
  if (options.scanDirectory === true) {
32753
33098
  args.push("--scan-directories");
32754
33099
  }
@@ -32765,7 +33110,7 @@ async function dcmsend(options) {
32765
33110
  if (!binaryResult.ok) {
32766
33111
  return err(binaryResult.error);
32767
33112
  }
32768
- const args = buildArgs24(options);
33113
+ const args = buildArgs33(options);
32769
33114
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32770
33115
  const result = await execCommand(binaryResult.value, args, {
32771
33116
  timeoutMs,
@@ -32777,7 +33122,7 @@ async function dcmsend(options) {
32777
33122
  if (result.value.exitCode !== 0) {
32778
33123
  return err(createToolError("dcmsend", args, result.value.exitCode, result.value.stderr));
32779
33124
  }
32780
- return ok({ success: true, stderr: result.value.stderr });
33125
+ return ok({ success: true, stdout: result.value.stdout, stderr: result.value.stderr });
32781
33126
  }
32782
33127
  var ProposedTransferSyntax = {
32783
33128
  UNCOMPRESSED: "uncompressed",
@@ -32815,6 +33160,14 @@ var StorescuOptionsSchema = z.object({
32815
33160
  calledAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
32816
33161
  scanDirectories: z.boolean().optional(),
32817
33162
  recurse: z.boolean().optional(),
33163
+ verbosity: z.enum(["verbose", "debug"]).optional(),
33164
+ maxPduReceive: z.number().int().min(4096).max(131072).optional(),
33165
+ maxPduSend: z.number().int().min(4096).max(131072).optional(),
33166
+ associationTimeout: z.number().int().positive().optional(),
33167
+ acseTimeout: z.number().int().positive().optional(),
33168
+ dimseTimeout: z.number().int().positive().optional(),
33169
+ noHostnameLookup: z.boolean().optional(),
33170
+ noUidChecks: z.boolean().optional(),
32818
33171
  proposedTransferSyntax: z.enum([
32819
33172
  "uncompressed",
32820
33173
  "littleEndian",
@@ -32829,8 +33182,36 @@ var StorescuOptionsSchema = z.object({
32829
33182
  "jlsLossy"
32830
33183
  ]).optional()
32831
33184
  }).strict();
32832
- function buildArgs25(options) {
33185
+ var VERBOSITY_FLAGS20 = { verbose: "-v", debug: "-d" };
33186
+ function pushNetworkArgs3(args, options) {
33187
+ if (options.verbosity !== void 0) {
33188
+ args.push(VERBOSITY_FLAGS20[options.verbosity]);
33189
+ }
33190
+ if (options.maxPduReceive !== void 0) {
33191
+ args.push("--max-pdu", String(options.maxPduReceive));
33192
+ }
33193
+ if (options.maxPduSend !== void 0) {
33194
+ args.push("--max-send-pdu", String(options.maxPduSend));
33195
+ }
33196
+ if (options.associationTimeout !== void 0) {
33197
+ args.push("-to", String(options.associationTimeout));
33198
+ }
33199
+ if (options.acseTimeout !== void 0) {
33200
+ args.push("-ta", String(options.acseTimeout));
33201
+ }
33202
+ if (options.dimseTimeout !== void 0) {
33203
+ args.push("-td", String(options.dimseTimeout));
33204
+ }
33205
+ if (options.noHostnameLookup === true) {
33206
+ args.push("-nh");
33207
+ }
33208
+ }
33209
+ function buildArgs34(options) {
32833
33210
  const args = [];
33211
+ pushNetworkArgs3(args, options);
33212
+ if (options.noUidChecks === true) {
33213
+ args.push("--no-uid-checks");
33214
+ }
32834
33215
  if (options.callingAETitle !== void 0) {
32835
33216
  args.push("-aet", options.callingAETitle);
32836
33217
  }
@@ -32859,7 +33240,7 @@ async function storescu(options) {
32859
33240
  if (!binaryResult.ok) {
32860
33241
  return err(binaryResult.error);
32861
33242
  }
32862
- const args = buildArgs25(options);
33243
+ const args = buildArgs34(options);
32863
33244
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32864
33245
  const result = await execCommand(binaryResult.value, args, {
32865
33246
  timeoutMs,
@@ -32893,12 +33274,44 @@ var FindscuOptionsSchema = z.object({
32893
33274
  queryModel: z.enum(["worklist", "patient", "study"]).optional(),
32894
33275
  keys: z.array(z.string().min(1).refine(isValidDicomKey, { message: "invalid DICOM query key format (expected XXXX,XXXX[=value])" })).optional(),
32895
33276
  extract: z.boolean().optional(),
32896
- outputDirectory: z.string().min(1).refine(isSafePath, { message: "path traversal detected in outputDirectory" }).optional()
33277
+ outputDirectory: z.string().min(1).refine(isSafePath, { message: "path traversal detected in outputDirectory" }).optional(),
33278
+ verbosity: z.enum(["verbose", "debug"]).optional(),
33279
+ maxPduReceive: z.number().int().min(4096).max(131072).optional(),
33280
+ maxPduSend: z.number().int().min(4096).max(131072).optional(),
33281
+ associationTimeout: z.number().int().positive().optional(),
33282
+ acseTimeout: z.number().int().positive().optional(),
33283
+ dimseTimeout: z.number().int().positive().optional(),
33284
+ noHostnameLookup: z.boolean().optional()
32897
33285
  }).strict().refine((data) => data.extract !== true || data.outputDirectory !== void 0, {
32898
33286
  message: "outputDirectory is required when extract is true"
32899
33287
  });
32900
- function buildArgs26(options) {
33288
+ var VERBOSITY_FLAGS21 = { verbose: "-v", debug: "-d" };
33289
+ function pushNetworkArgs4(args, options) {
33290
+ if (options.verbosity !== void 0) {
33291
+ args.push(VERBOSITY_FLAGS21[options.verbosity]);
33292
+ }
33293
+ if (options.maxPduReceive !== void 0) {
33294
+ args.push("--max-pdu", String(options.maxPduReceive));
33295
+ }
33296
+ if (options.maxPduSend !== void 0) {
33297
+ args.push("--max-send-pdu", String(options.maxPduSend));
33298
+ }
33299
+ if (options.associationTimeout !== void 0) {
33300
+ args.push("-to", String(options.associationTimeout));
33301
+ }
33302
+ if (options.acseTimeout !== void 0) {
33303
+ args.push("-ta", String(options.acseTimeout));
33304
+ }
33305
+ if (options.dimseTimeout !== void 0) {
33306
+ args.push("-td", String(options.dimseTimeout));
33307
+ }
33308
+ if (options.noHostnameLookup === true) {
33309
+ args.push("-nh");
33310
+ }
33311
+ }
33312
+ function buildArgs35(options) {
32901
33313
  const args = [];
33314
+ pushNetworkArgs4(args, options);
32902
33315
  if (options.callingAETitle !== void 0) {
32903
33316
  args.push("-aet", options.callingAETitle);
32904
33317
  }
@@ -32931,7 +33344,7 @@ async function findscu(options) {
32931
33344
  if (!binaryResult.ok) {
32932
33345
  return err(binaryResult.error);
32933
33346
  }
32934
- const args = buildArgs26(options);
33347
+ const args = buildArgs35(options);
32935
33348
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
32936
33349
  const result = await execCommand(binaryResult.value, args, {
32937
33350
  timeoutMs,
@@ -32963,10 +33376,42 @@ var MovescuOptionsSchema = z.object({
32963
33376
  queryModel: z.enum(["patient", "study"]).optional(),
32964
33377
  keys: z.array(z.string().min(1).refine(isValidDicomKey, { message: "invalid DICOM query key format (expected XXXX,XXXX[=value])" })).optional(),
32965
33378
  moveDestination: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
32966
- outputDirectory: z.string().min(1).refine(isSafePath, { message: "path traversal detected in outputDirectory" }).optional()
33379
+ outputDirectory: z.string().min(1).refine(isSafePath, { message: "path traversal detected in outputDirectory" }).optional(),
33380
+ verbosity: z.enum(["verbose", "debug"]).optional(),
33381
+ maxPduReceive: z.number().int().min(4096).max(131072).optional(),
33382
+ maxPduSend: z.number().int().min(4096).max(131072).optional(),
33383
+ associationTimeout: z.number().int().positive().optional(),
33384
+ acseTimeout: z.number().int().positive().optional(),
33385
+ dimseTimeout: z.number().int().positive().optional(),
33386
+ noHostnameLookup: z.boolean().optional()
32967
33387
  }).strict();
32968
- function buildArgs27(options) {
33388
+ var VERBOSITY_FLAGS22 = { verbose: "-v", debug: "-d" };
33389
+ function pushNetworkArgs5(args, options) {
33390
+ if (options.verbosity !== void 0) {
33391
+ args.push(VERBOSITY_FLAGS22[options.verbosity]);
33392
+ }
33393
+ if (options.maxPduReceive !== void 0) {
33394
+ args.push("--max-pdu", String(options.maxPduReceive));
33395
+ }
33396
+ if (options.maxPduSend !== void 0) {
33397
+ args.push("--max-send-pdu", String(options.maxPduSend));
33398
+ }
33399
+ if (options.associationTimeout !== void 0) {
33400
+ args.push("-to", String(options.associationTimeout));
33401
+ }
33402
+ if (options.acseTimeout !== void 0) {
33403
+ args.push("-ta", String(options.acseTimeout));
33404
+ }
33405
+ if (options.dimseTimeout !== void 0) {
33406
+ args.push("-td", String(options.dimseTimeout));
33407
+ }
33408
+ if (options.noHostnameLookup === true) {
33409
+ args.push("-nh");
33410
+ }
33411
+ }
33412
+ function buildArgs36(options) {
32969
33413
  const args = [];
33414
+ pushNetworkArgs5(args, options);
32970
33415
  if (options.callingAETitle !== void 0) {
32971
33416
  args.push("-aet", options.callingAETitle);
32972
33417
  }
@@ -32999,7 +33444,7 @@ async function movescu(options) {
32999
33444
  if (!binaryResult.ok) {
33000
33445
  return err(binaryResult.error);
33001
33446
  }
33002
- const args = buildArgs27(options);
33447
+ const args = buildArgs36(options);
33003
33448
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33004
33449
  const result = await execCommand(binaryResult.value, args, {
33005
33450
  timeoutMs,
@@ -33030,10 +33475,42 @@ var GetscuOptionsSchema = z.object({
33030
33475
  calledAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
33031
33476
  queryModel: z.enum(["patient", "study"]).optional(),
33032
33477
  keys: z.array(z.string().min(1).refine(isValidDicomKey, { message: "invalid DICOM query key format (expected XXXX,XXXX[=value])" })).optional(),
33033
- outputDirectory: z.string().min(1).refine(isSafePath, { message: "path traversal detected in outputDirectory" }).optional()
33478
+ outputDirectory: z.string().min(1).refine(isSafePath, { message: "path traversal detected in outputDirectory" }).optional(),
33479
+ verbosity: z.enum(["verbose", "debug"]).optional(),
33480
+ maxPduReceive: z.number().int().min(4096).max(131072).optional(),
33481
+ maxPduSend: z.number().int().min(4096).max(131072).optional(),
33482
+ associationTimeout: z.number().int().positive().optional(),
33483
+ acseTimeout: z.number().int().positive().optional(),
33484
+ dimseTimeout: z.number().int().positive().optional(),
33485
+ noHostnameLookup: z.boolean().optional()
33034
33486
  }).strict();
33035
- function buildArgs28(options) {
33487
+ var VERBOSITY_FLAGS23 = { verbose: "-v", debug: "-d" };
33488
+ function pushNetworkArgs6(args, options) {
33489
+ if (options.verbosity !== void 0) {
33490
+ args.push(VERBOSITY_FLAGS23[options.verbosity]);
33491
+ }
33492
+ if (options.maxPduReceive !== void 0) {
33493
+ args.push("--max-pdu", String(options.maxPduReceive));
33494
+ }
33495
+ if (options.maxPduSend !== void 0) {
33496
+ args.push("--max-send-pdu", String(options.maxPduSend));
33497
+ }
33498
+ if (options.associationTimeout !== void 0) {
33499
+ args.push("-to", String(options.associationTimeout));
33500
+ }
33501
+ if (options.acseTimeout !== void 0) {
33502
+ args.push("-ta", String(options.acseTimeout));
33503
+ }
33504
+ if (options.dimseTimeout !== void 0) {
33505
+ args.push("-td", String(options.dimseTimeout));
33506
+ }
33507
+ if (options.noHostnameLookup === true) {
33508
+ args.push("-nh");
33509
+ }
33510
+ }
33511
+ function buildArgs37(options) {
33036
33512
  const args = [];
33513
+ pushNetworkArgs6(args, options);
33037
33514
  if (options.callingAETitle !== void 0) {
33038
33515
  args.push("-aet", options.callingAETitle);
33039
33516
  }
@@ -33063,7 +33540,7 @@ async function getscu(options) {
33063
33540
  if (!binaryResult.ok) {
33064
33541
  return err(binaryResult.error);
33065
33542
  }
33066
- const args = buildArgs28(options);
33543
+ const args = buildArgs37(options);
33067
33544
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33068
33545
  const result = await execCommand(binaryResult.value, args, {
33069
33546
  timeoutMs,
@@ -33083,10 +33560,42 @@ var TermscuOptionsSchema = z.object({
33083
33560
  host: z.string().min(1),
33084
33561
  port: z.number().int().min(1).max(65535),
33085
33562
  callingAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
33086
- calledAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional()
33563
+ calledAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
33564
+ verbosity: z.enum(["verbose", "debug"]).optional(),
33565
+ maxPduReceive: z.number().int().min(4096).max(131072).optional(),
33566
+ maxPduSend: z.number().int().min(4096).max(131072).optional(),
33567
+ associationTimeout: z.number().int().positive().optional(),
33568
+ acseTimeout: z.number().int().positive().optional(),
33569
+ dimseTimeout: z.number().int().positive().optional(),
33570
+ noHostnameLookup: z.boolean().optional()
33087
33571
  }).strict();
33088
- function buildArgs29(options) {
33572
+ var VERBOSITY_FLAGS24 = { verbose: "-v", debug: "-d" };
33573
+ function pushNetworkArgs7(args, options) {
33574
+ if (options.verbosity !== void 0) {
33575
+ args.push(VERBOSITY_FLAGS24[options.verbosity]);
33576
+ }
33577
+ if (options.maxPduReceive !== void 0) {
33578
+ args.push("--max-pdu", String(options.maxPduReceive));
33579
+ }
33580
+ if (options.maxPduSend !== void 0) {
33581
+ args.push("--max-send-pdu", String(options.maxPduSend));
33582
+ }
33583
+ if (options.associationTimeout !== void 0) {
33584
+ args.push("-to", String(options.associationTimeout));
33585
+ }
33586
+ if (options.acseTimeout !== void 0) {
33587
+ args.push("-ta", String(options.acseTimeout));
33588
+ }
33589
+ if (options.dimseTimeout !== void 0) {
33590
+ args.push("-td", String(options.dimseTimeout));
33591
+ }
33592
+ if (options.noHostnameLookup === true) {
33593
+ args.push("-nh");
33594
+ }
33595
+ }
33596
+ function buildArgs38(options) {
33089
33597
  const args = [];
33598
+ pushNetworkArgs7(args, options);
33090
33599
  if (options.callingAETitle !== void 0) {
33091
33600
  args.push("-aet", options.callingAETitle);
33092
33601
  }
@@ -33105,7 +33614,7 @@ async function termscu(options) {
33105
33614
  if (!binaryResult.ok) {
33106
33615
  return err(binaryResult.error);
33107
33616
  }
33108
- const args = buildArgs29(options);
33617
+ const args = buildArgs38(options);
33109
33618
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33110
33619
  const result = await execCommand(binaryResult.value, args, {
33111
33620
  timeoutMs,
@@ -33119,15 +33628,17 @@ async function termscu(options) {
33119
33628
  }
33120
33629
  return ok({ success: true, stderr: result.value.stderr });
33121
33630
  }
33631
+ var VERBOSITY_FLAGS25 = { verbose: "-v", debug: "-d" };
33122
33632
  var DsrdumpOptionsSchema = z.object({
33123
33633
  timeoutMs: z.number().int().positive().optional(),
33124
33634
  signal: z.instanceof(AbortSignal).optional(),
33125
33635
  printFilename: z.boolean().optional(),
33126
33636
  printLong: z.boolean().optional(),
33127
- printCodes: z.boolean().optional()
33637
+ printCodes: z.boolean().optional(),
33638
+ charsetAssume: z.string().min(1).optional(),
33639
+ verbosity: z.enum(["verbose", "debug"]).optional()
33128
33640
  }).strict().optional();
33129
- function buildArgs30(inputPath, options) {
33130
- const args = [];
33641
+ function pushDisplayArgs2(args, options) {
33131
33642
  if (options?.printFilename === true) {
33132
33643
  args.push("+Pf");
33133
33644
  }
@@ -33137,6 +33648,16 @@ function buildArgs30(inputPath, options) {
33137
33648
  if (options?.printCodes === true) {
33138
33649
  args.push("+Pc");
33139
33650
  }
33651
+ if (options?.charsetAssume !== void 0) {
33652
+ args.push("+Ca", options.charsetAssume);
33653
+ }
33654
+ }
33655
+ function buildArgs39(inputPath, options) {
33656
+ const args = [];
33657
+ if (options?.verbosity !== void 0) {
33658
+ args.push(VERBOSITY_FLAGS25[options.verbosity]);
33659
+ }
33660
+ pushDisplayArgs2(args, options);
33140
33661
  args.push(inputPath);
33141
33662
  return args;
33142
33663
  }
@@ -33149,7 +33670,7 @@ async function dsrdump(inputPath, options) {
33149
33670
  if (!binaryResult.ok) {
33150
33671
  return err(binaryResult.error);
33151
33672
  }
33152
- const args = buildArgs30(inputPath, options);
33673
+ const args = buildArgs39(inputPath, options);
33153
33674
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33154
33675
  const result = await execCommand(binaryResult.value, args, {
33155
33676
  timeoutMs,
@@ -33163,20 +33684,29 @@ async function dsrdump(inputPath, options) {
33163
33684
  }
33164
33685
  return ok({ text: result.value.stdout });
33165
33686
  }
33687
+ var VERBOSITY_FLAGS26 = { verbose: "-v", debug: "-d" };
33166
33688
  var Dsr2xmlOptionsSchema = z.object({
33167
33689
  timeoutMs: z.number().int().positive().optional(),
33168
33690
  signal: z.instanceof(AbortSignal).optional(),
33169
33691
  useNamespace: z.boolean().optional(),
33170
- addSchemaRef: z.boolean().optional()
33692
+ addSchemaRef: z.boolean().optional(),
33693
+ charsetAssume: z.string().min(1).optional(),
33694
+ verbosity: z.enum(["verbose", "debug"]).optional()
33171
33695
  }).strict().optional();
33172
- function buildArgs31(inputPath, options) {
33696
+ function buildArgs40(inputPath, options) {
33173
33697
  const args = [];
33698
+ if (options?.verbosity !== void 0) {
33699
+ args.push(VERBOSITY_FLAGS26[options.verbosity]);
33700
+ }
33174
33701
  if (options?.useNamespace === true) {
33175
33702
  args.push("+Xn");
33176
33703
  }
33177
33704
  if (options?.addSchemaRef === true) {
33178
33705
  args.push("+Xs");
33179
33706
  }
33707
+ if (options?.charsetAssume !== void 0) {
33708
+ args.push("+Ca", options.charsetAssume);
33709
+ }
33180
33710
  args.push(inputPath);
33181
33711
  return args;
33182
33712
  }
@@ -33189,7 +33719,7 @@ async function dsr2xml(inputPath, options) {
33189
33719
  if (!binaryResult.ok) {
33190
33720
  return err(binaryResult.error);
33191
33721
  }
33192
- const args = buildArgs31(inputPath, options);
33722
+ const args = buildArgs40(inputPath, options);
33193
33723
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33194
33724
  const result = await execCommand(binaryResult.value, args, {
33195
33725
  timeoutMs,
@@ -33207,10 +33737,16 @@ var Xml2dsrOptionsSchema = z.object({
33207
33737
  timeoutMs: z.number().int().positive().optional(),
33208
33738
  signal: z.instanceof(AbortSignal).optional(),
33209
33739
  generateNewUIDs: z.boolean().optional(),
33210
- validateDocument: z.boolean().optional()
33740
+ validateDocument: z.boolean().optional(),
33741
+ verbosity: z.enum(["verbose", "debug"]).optional()
33211
33742
  }).strict().optional();
33212
- function buildArgs32(inputPath, outputPath, options) {
33743
+ function buildArgs41(inputPath, outputPath, options) {
33213
33744
  const args = [];
33745
+ if (options?.verbosity === "verbose") {
33746
+ args.push("-v");
33747
+ } else if (options?.verbosity === "debug") {
33748
+ args.push("-d");
33749
+ }
33214
33750
  if (options?.generateNewUIDs === true) {
33215
33751
  args.push("+Ug");
33216
33752
  }
@@ -33229,7 +33765,7 @@ async function xml2dsr(inputPath, outputPath, options) {
33229
33765
  if (!binaryResult.ok) {
33230
33766
  return err(binaryResult.error);
33231
33767
  }
33232
- const args = buildArgs32(inputPath, outputPath, options);
33768
+ const args = buildArgs41(inputPath, outputPath, options);
33233
33769
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33234
33770
  const result = await execCommand(binaryResult.value, args, {
33235
33771
  timeoutMs,
@@ -33246,10 +33782,16 @@ async function xml2dsr(inputPath, outputPath, options) {
33246
33782
  var DrtdumpOptionsSchema = z.object({
33247
33783
  timeoutMs: z.number().int().positive().optional(),
33248
33784
  signal: z.instanceof(AbortSignal).optional(),
33249
- printFilename: z.boolean().optional()
33785
+ printFilename: z.boolean().optional(),
33786
+ verbosity: z.enum(["verbose", "debug"]).optional()
33250
33787
  }).strict().optional();
33251
- function buildArgs33(inputPath, options) {
33788
+ function buildArgs42(inputPath, options) {
33252
33789
  const args = [];
33790
+ if (options?.verbosity === "verbose") {
33791
+ args.push("-v");
33792
+ } else if (options?.verbosity === "debug") {
33793
+ args.push("-d");
33794
+ }
33253
33795
  if (options?.printFilename === true) {
33254
33796
  args.push("+Pf");
33255
33797
  }
@@ -33265,7 +33807,7 @@ async function drtdump(inputPath, options) {
33265
33807
  if (!binaryResult.ok) {
33266
33808
  return err(binaryResult.error);
33267
33809
  }
33268
- const args = buildArgs33(inputPath, options);
33810
+ const args = buildArgs42(inputPath, options);
33269
33811
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33270
33812
  const result = await execCommand(binaryResult.value, args, {
33271
33813
  timeoutMs,
@@ -33281,8 +33823,18 @@ async function drtdump(inputPath, options) {
33281
33823
  }
33282
33824
  var DcmpsmkOptionsSchema = z.object({
33283
33825
  timeoutMs: z.number().int().positive().optional(),
33284
- signal: z.instanceof(AbortSignal).optional()
33826
+ signal: z.instanceof(AbortSignal).optional(),
33827
+ verbosity: z.enum(["verbose", "debug"]).optional()
33285
33828
  }).strict().optional();
33829
+ var VERBOSITY_FLAGS27 = { verbose: "-v", debug: "-d" };
33830
+ function buildArgs43(inputPath, outputPath, options) {
33831
+ const args = [];
33832
+ if (options?.verbosity !== void 0) {
33833
+ args.push(VERBOSITY_FLAGS27[options.verbosity]);
33834
+ }
33835
+ args.push(inputPath, outputPath);
33836
+ return args;
33837
+ }
33286
33838
  async function dcmpsmk(inputPath, outputPath, options) {
33287
33839
  const validation = DcmpsmkOptionsSchema.safeParse(options);
33288
33840
  if (!validation.success) {
@@ -33292,7 +33844,7 @@ async function dcmpsmk(inputPath, outputPath, options) {
33292
33844
  if (!binaryResult.ok) {
33293
33845
  return err(binaryResult.error);
33294
33846
  }
33295
- const args = [inputPath, outputPath];
33847
+ const args = buildArgs43(inputPath, outputPath, options);
33296
33848
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33297
33849
  const result = await execCommand(binaryResult.value, args, {
33298
33850
  timeoutMs,
@@ -33308,8 +33860,18 @@ async function dcmpsmk(inputPath, outputPath, options) {
33308
33860
  }
33309
33861
  var DcmpschkOptionsSchema = z.object({
33310
33862
  timeoutMs: z.number().int().positive().optional(),
33311
- signal: z.instanceof(AbortSignal).optional()
33863
+ signal: z.instanceof(AbortSignal).optional(),
33864
+ verbosity: z.enum(["verbose", "debug"]).optional()
33312
33865
  }).strict().optional();
33866
+ var VERBOSITY_FLAGS28 = { verbose: "-v", debug: "-d" };
33867
+ function buildArgs44(inputPath, options) {
33868
+ const args = [];
33869
+ if (options?.verbosity !== void 0) {
33870
+ args.push(VERBOSITY_FLAGS28[options.verbosity]);
33871
+ }
33872
+ args.push(inputPath);
33873
+ return args;
33874
+ }
33313
33875
  async function dcmpschk(inputPath, options) {
33314
33876
  const validation = DcmpschkOptionsSchema.safeParse(options);
33315
33877
  if (!validation.success) {
@@ -33319,7 +33881,7 @@ async function dcmpschk(inputPath, options) {
33319
33881
  if (!binaryResult.ok) {
33320
33882
  return err(binaryResult.error);
33321
33883
  }
33322
- const args = [inputPath];
33884
+ const args = buildArgs44(inputPath, options);
33323
33885
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33324
33886
  const result = await execCommand(binaryResult.value, args, {
33325
33887
  timeoutMs,
@@ -33340,10 +33902,16 @@ var DcmprscuOptionsSchema = z.object({
33340
33902
  port: z.number().int().min(1).max(65535),
33341
33903
  callingAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
33342
33904
  calledAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
33343
- configFile: z.string().min(1).optional()
33905
+ configFile: z.string().min(1).optional(),
33906
+ verbosity: z.enum(["verbose", "debug"]).optional()
33344
33907
  }).strict();
33345
- function buildArgs34(options) {
33908
+ function buildArgs45(options) {
33346
33909
  const args = [];
33910
+ if (options.verbosity === "verbose") {
33911
+ args.push("-v");
33912
+ } else if (options.verbosity === "debug") {
33913
+ args.push("-d");
33914
+ }
33347
33915
  if (options.callingAETitle !== void 0) {
33348
33916
  args.push("-aet", options.callingAETitle);
33349
33917
  }
@@ -33365,7 +33933,7 @@ async function dcmprscu(options) {
33365
33933
  if (!binaryResult.ok) {
33366
33934
  return err(binaryResult.error);
33367
33935
  }
33368
- const args = buildArgs34(options);
33936
+ const args = buildArgs45(options);
33369
33937
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33370
33938
  const result = await execCommand(binaryResult.value, args, {
33371
33939
  timeoutMs,
@@ -33382,10 +33950,16 @@ async function dcmprscu(options) {
33382
33950
  var DcmpsprtOptionsSchema = z.object({
33383
33951
  timeoutMs: z.number().int().positive().optional(),
33384
33952
  signal: z.instanceof(AbortSignal).optional(),
33385
- configFile: z.string().min(1).optional()
33953
+ configFile: z.string().min(1).optional(),
33954
+ verbosity: z.enum(["verbose", "debug"]).optional()
33386
33955
  }).strict().optional();
33387
- function buildArgs35(inputPath, options) {
33956
+ function buildArgs46(inputPath, options) {
33388
33957
  const args = [];
33958
+ if (options?.verbosity === "verbose") {
33959
+ args.push("-v");
33960
+ } else if (options?.verbosity === "debug") {
33961
+ args.push("-d");
33962
+ }
33389
33963
  if (options?.configFile !== void 0) {
33390
33964
  args.push("-c", options.configFile);
33391
33965
  }
@@ -33401,7 +33975,7 @@ async function dcmpsprt(inputPath, options) {
33401
33975
  if (!binaryResult.ok) {
33402
33976
  return err(binaryResult.error);
33403
33977
  }
33404
- const args = buildArgs35(inputPath, options);
33978
+ const args = buildArgs46(inputPath, options);
33405
33979
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33406
33980
  const result = await execCommand(binaryResult.value, args, {
33407
33981
  timeoutMs,
@@ -33419,10 +33993,16 @@ var Dcmp2pgmOptionsSchema = z.object({
33419
33993
  timeoutMs: z.number().int().positive().optional(),
33420
33994
  signal: z.instanceof(AbortSignal).optional(),
33421
33995
  presentationState: z.string().min(1).optional(),
33422
- frame: z.number().int().min(0).max(65535).optional()
33996
+ frame: z.number().int().min(0).max(65535).optional(),
33997
+ verbosity: z.enum(["verbose", "debug"]).optional()
33423
33998
  }).strict().optional();
33424
- function buildArgs36(inputPath, outputPath, options) {
33999
+ function buildArgs47(inputPath, outputPath, options) {
33425
34000
  const args = [];
34001
+ if (options?.verbosity === "verbose") {
34002
+ args.push("-v");
34003
+ } else if (options?.verbosity === "debug") {
34004
+ args.push("-d");
34005
+ }
33426
34006
  if (options?.presentationState !== void 0) {
33427
34007
  args.push("-p", options.presentationState);
33428
34008
  }
@@ -33441,7 +34021,7 @@ async function dcmp2pgm(inputPath, outputPath, options) {
33441
34021
  if (!binaryResult.ok) {
33442
34022
  return err(binaryResult.error);
33443
34023
  }
33444
- const args = buildArgs36(inputPath, outputPath, options);
34024
+ const args = buildArgs47(inputPath, outputPath, options);
33445
34025
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33446
34026
  const result = await execCommand(binaryResult.value, args, {
33447
34027
  timeoutMs,
@@ -33457,8 +34037,18 @@ async function dcmp2pgm(inputPath, outputPath, options) {
33457
34037
  }
33458
34038
  var DcmmkcrvOptionsSchema = z.object({
33459
34039
  timeoutMs: z.number().int().positive().optional(),
33460
- signal: z.instanceof(AbortSignal).optional()
34040
+ signal: z.instanceof(AbortSignal).optional(),
34041
+ verbosity: z.enum(["verbose", "debug"]).optional()
33461
34042
  }).strict().optional();
34043
+ var VERBOSITY_FLAGS29 = { verbose: "-v", debug: "-d" };
34044
+ function buildArgs48(inputPath, outputPath, options) {
34045
+ const args = [];
34046
+ if (options?.verbosity !== void 0) {
34047
+ args.push(VERBOSITY_FLAGS29[options.verbosity]);
34048
+ }
34049
+ args.push(inputPath, outputPath);
34050
+ return args;
34051
+ }
33462
34052
  async function dcmmkcrv(inputPath, outputPath, options) {
33463
34053
  const validation = DcmmkcrvOptionsSchema.safeParse(options);
33464
34054
  if (!validation.success) {
@@ -33468,7 +34058,7 @@ async function dcmmkcrv(inputPath, outputPath, options) {
33468
34058
  if (!binaryResult.ok) {
33469
34059
  return err(binaryResult.error);
33470
34060
  }
33471
- const args = [inputPath, outputPath];
34061
+ const args = buildArgs48(inputPath, outputPath, options);
33472
34062
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33473
34063
  const result = await execCommand(binaryResult.value, args, {
33474
34064
  timeoutMs,
@@ -33495,16 +34085,17 @@ var LUT_TYPE_FLAGS = {
33495
34085
  presentation: "+Tp",
33496
34086
  voi: "+Tv"
33497
34087
  };
34088
+ var VERBOSITY_FLAGS30 = { verbose: "-v", debug: "-d" };
33498
34089
  var DcmmklutOptionsSchema = z.object({
33499
34090
  timeoutMs: z.number().int().positive().optional(),
33500
34091
  signal: z.instanceof(AbortSignal).optional(),
33501
34092
  lutType: z.enum(["modality", "presentation", "voi"]).optional(),
33502
34093
  gamma: z.number().positive().optional(),
33503
34094
  entries: z.number().int().positive().optional(),
33504
- bits: z.number().int().min(8).max(16).optional()
34095
+ bits: z.number().int().min(8).max(16).optional(),
34096
+ verbosity: z.enum(["verbose", "debug"]).optional()
33505
34097
  }).strict().optional();
33506
- function buildArgs37(outputPath, options) {
33507
- const args = [];
34098
+ function pushLutArgs(args, options) {
33508
34099
  if (options?.lutType !== void 0) {
33509
34100
  args.push(LUT_TYPE_FLAGS[options.lutType]);
33510
34101
  }
@@ -33517,6 +34108,13 @@ function buildArgs37(outputPath, options) {
33517
34108
  if (options?.bits !== void 0) {
33518
34109
  args.push("-b", String(options.bits));
33519
34110
  }
34111
+ }
34112
+ function buildArgs49(outputPath, options) {
34113
+ const args = [];
34114
+ if (options?.verbosity !== void 0) {
34115
+ args.push(VERBOSITY_FLAGS30[options.verbosity]);
34116
+ }
34117
+ pushLutArgs(args, options);
33520
34118
  args.push(outputPath);
33521
34119
  return args;
33522
34120
  }
@@ -33529,7 +34127,7 @@ async function dcmmklut(outputPath, options) {
33529
34127
  if (!binaryResult.ok) {
33530
34128
  return err(binaryResult.error);
33531
34129
  }
33532
- const args = buildArgs37(outputPath, options);
34130
+ const args = buildArgs49(outputPath, options);
33533
34131
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33534
34132
  const result = await execCommand(binaryResult.value, args, {
33535
34133
  timeoutMs,
@@ -34447,7 +35045,7 @@ var DcmrecvOptionsSchema = z.object({
34447
35045
  drainTimeoutMs: z.number().int().positive().optional(),
34448
35046
  signal: z.instanceof(AbortSignal).optional()
34449
35047
  }).strict();
34450
- function buildArgs38(options) {
35048
+ function buildArgs50(options) {
34451
35049
  const args = ["--verbose"];
34452
35050
  if (options.aeTitle !== void 0) {
34453
35051
  args.push("--aetitle", options.aeTitle);
@@ -34581,7 +35179,7 @@ var Dcmrecv = class _Dcmrecv extends DcmtkProcess {
34581
35179
  if (!binaryResult.ok) {
34582
35180
  return err(binaryResult.error);
34583
35181
  }
34584
- const args = buildArgs38(options);
35182
+ const args = buildArgs50(options);
34585
35183
  const parser2 = new LineParser();
34586
35184
  for (const pattern of DCMRECV_PATTERNS) {
34587
35185
  const addResult = parser2.addPattern(pattern);
@@ -34694,7 +35292,7 @@ var StoreSCPOptionsSchema = z.object({
34694
35292
  drainTimeoutMs: z.number().int().positive().optional(),
34695
35293
  signal: z.instanceof(AbortSignal).optional()
34696
35294
  }).strict();
34697
- function buildArgs39(options) {
35295
+ function buildArgs51(options) {
34698
35296
  const args = ["--verbose"];
34699
35297
  if (options.aeTitle !== void 0) {
34700
35298
  args.push("--aetitle", options.aeTitle);
@@ -34858,7 +35456,7 @@ var StoreSCP = class _StoreSCP extends DcmtkProcess {
34858
35456
  if (!binaryResult.ok) {
34859
35457
  return err(binaryResult.error);
34860
35458
  }
34861
- const args = buildArgs39(options);
35459
+ const args = buildArgs51(options);
34862
35460
  const parser2 = new LineParser();
34863
35461
  for (const pattern of STORESCP_PATTERNS) {
34864
35462
  const addResult = parser2.addPattern(pattern);
@@ -34937,7 +35535,7 @@ var DcmprsCPOptionsSchema = z.object({
34937
35535
  drainTimeoutMs: z.number().int().positive().optional(),
34938
35536
  signal: z.instanceof(AbortSignal).optional()
34939
35537
  }).strict();
34940
- function buildArgs40(options) {
35538
+ function buildArgs52(options) {
34941
35539
  const args = ["--verbose", "--config", options.configFile];
34942
35540
  if (options.printer !== void 0) {
34943
35541
  args.push("--printer", options.printer);
@@ -35016,7 +35614,7 @@ var DcmprsCP = class _DcmprsCP extends DcmtkProcess {
35016
35614
  if (!binaryResult.ok) {
35017
35615
  return err(binaryResult.error);
35018
35616
  }
35019
- const args = buildArgs40(options);
35617
+ const args = buildArgs52(options);
35020
35618
  const parser2 = new LineParser();
35021
35619
  for (const pattern of DCMPRSCP_PATTERNS) {
35022
35620
  const addResult = parser2.addPattern(pattern);
@@ -35068,7 +35666,7 @@ var DcmpsrcvOptionsSchema = z.object({
35068
35666
  drainTimeoutMs: z.number().int().positive().optional(),
35069
35667
  signal: z.instanceof(AbortSignal).optional()
35070
35668
  }).strict();
35071
- function buildArgs41(options) {
35669
+ function buildArgs53(options) {
35072
35670
  const args = ["--verbose"];
35073
35671
  if (options.logLevel !== void 0) {
35074
35672
  args.push("--log-level", options.logLevel);
@@ -35145,7 +35743,7 @@ var Dcmpsrcv = class _Dcmpsrcv extends DcmtkProcess {
35145
35743
  if (!binaryResult.ok) {
35146
35744
  return err(binaryResult.error);
35147
35745
  }
35148
- const args = buildArgs41(options);
35746
+ const args = buildArgs53(options);
35149
35747
  const parser2 = new LineParser();
35150
35748
  for (const pattern of DCMPSRCV_PATTERNS) {
35151
35749
  const addResult = parser2.addPattern(pattern);
@@ -35203,7 +35801,7 @@ var DcmQRSCPOptionsSchema = z.object({
35203
35801
  drainTimeoutMs: z.number().int().positive().optional(),
35204
35802
  signal: z.instanceof(AbortSignal).optional()
35205
35803
  }).strict();
35206
- function buildArgs42(options) {
35804
+ function buildArgs54(options) {
35207
35805
  const args = [];
35208
35806
  if (options.verbose !== false) {
35209
35807
  args.push("--verbose");
@@ -35301,7 +35899,7 @@ var DcmQRSCP = class _DcmQRSCP extends DcmtkProcess {
35301
35899
  if (!binaryResult.ok) {
35302
35900
  return err(binaryResult.error);
35303
35901
  }
35304
- const args = buildArgs42(options);
35902
+ const args = buildArgs54(options);
35305
35903
  const parser2 = new LineParser();
35306
35904
  for (const pattern of DCMQRSCP_PATTERNS) {
35307
35905
  const addResult = parser2.addPattern(pattern);
@@ -35356,7 +35954,7 @@ var WlmscpfsOptionsSchema = z.object({
35356
35954
  drainTimeoutMs: z.number().int().positive().optional(),
35357
35955
  signal: z.instanceof(AbortSignal).optional()
35358
35956
  }).strict();
35359
- function buildArgs43(options) {
35957
+ function buildArgs55(options) {
35360
35958
  const args = [];
35361
35959
  if (options.verbose !== false) {
35362
35960
  args.push("--verbose");
@@ -35448,7 +36046,7 @@ var Wlmscpfs = class _Wlmscpfs extends DcmtkProcess {
35448
36046
  if (!binaryResult.ok) {
35449
36047
  return err(binaryResult.error);
35450
36048
  }
35451
- const args = buildArgs43(options);
36049
+ const args = buildArgs55(options);
35452
36050
  const parser2 = new LineParser();
35453
36051
  for (const pattern of WLMSCPFS_PATTERNS) {
35454
36052
  const addResult = parser2.addPattern(pattern);
@@ -35992,6 +36590,532 @@ function delay(ms) {
35992
36590
  });
35993
36591
  }
35994
36592
 
36593
+ // src/senders/types.ts
36594
+ var SenderMode = {
36595
+ /** One association at a time, queued FIFO. */
36596
+ SINGLE: "single",
36597
+ /** Up to N concurrent associations, each send() gets its own. */
36598
+ MULTIPLE: "multiple",
36599
+ /** Files accumulated into buckets, each bucket = one association. */
36600
+ BUCKET: "bucket"
36601
+ };
36602
+ var SenderHealth = {
36603
+ /** All associations succeeding normally. */
36604
+ HEALTHY: "healthy",
36605
+ /** Recent failures detected; effective concurrency reduced. */
36606
+ DEGRADED: "degraded",
36607
+ /** Remote endpoint appears down; minimal concurrency. */
36608
+ DOWN: "down"
36609
+ };
36610
+
36611
+ // src/senders/DicomSender.ts
36612
+ var DEFAULT_MAX_ASSOCIATIONS = 4;
36613
+ var DEFAULT_MAX_QUEUE_LENGTH = 1e3;
36614
+ var DEFAULT_MAX_RETRIES = 3;
36615
+ var DEFAULT_RETRY_DELAY_MS = 1e3;
36616
+ var DEFAULT_BUCKET_FLUSH_MS = 5e3;
36617
+ var DEFAULT_MAX_BUCKET_SIZE = 50;
36618
+ var MAX_ASSOCIATIONS_LIMIT = 64;
36619
+ var DEGRADE_THRESHOLD = 3;
36620
+ var DOWN_THRESHOLD = 10;
36621
+ var RECOVERY_THRESHOLD = 3;
36622
+ var DicomSenderOptionsSchema = z.object({
36623
+ host: z.string().min(1),
36624
+ port: z.number().int().min(1).max(65535),
36625
+ calledAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
36626
+ callingAETitle: z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
36627
+ mode: z.enum(["single", "multiple", "bucket"]).optional(),
36628
+ maxAssociations: z.number().int().min(1).max(MAX_ASSOCIATIONS_LIMIT).optional(),
36629
+ proposedTransferSyntax: z.enum([
36630
+ "uncompressed",
36631
+ "littleEndian",
36632
+ "bigEndian",
36633
+ "implicitVR",
36634
+ "jpegLossless",
36635
+ "jpeg8Bit",
36636
+ "jpeg12Bit",
36637
+ "j2kLossless",
36638
+ "j2kLossy",
36639
+ "jlsLossless",
36640
+ "jlsLossy"
36641
+ ]).optional(),
36642
+ maxQueueLength: z.number().int().min(1).optional(),
36643
+ timeoutMs: z.number().int().positive().optional(),
36644
+ maxRetries: z.number().int().min(0).optional(),
36645
+ retryDelayMs: z.number().int().min(0).optional(),
36646
+ bucketFlushMs: z.number().int().positive().optional(),
36647
+ maxBucketSize: z.number().int().min(1).optional(),
36648
+ signal: z.instanceof(AbortSignal).optional()
36649
+ }).strict();
36650
+ function resolveConfig(options) {
36651
+ const mode = options.mode ?? "multiple";
36652
+ const rawMax = options.maxAssociations ?? DEFAULT_MAX_ASSOCIATIONS;
36653
+ return {
36654
+ mode,
36655
+ configuredMaxAssociations: mode === "single" ? 1 : rawMax,
36656
+ maxQueueLength: options.maxQueueLength ?? DEFAULT_MAX_QUEUE_LENGTH,
36657
+ defaultTimeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,
36658
+ defaultMaxRetries: options.maxRetries ?? DEFAULT_MAX_RETRIES,
36659
+ retryDelayMs: options.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS,
36660
+ bucketFlushMs: options.bucketFlushMs ?? DEFAULT_BUCKET_FLUSH_MS,
36661
+ maxBucketSize: options.maxBucketSize ?? DEFAULT_MAX_BUCKET_SIZE
36662
+ };
36663
+ }
36664
+ var DicomSender = class _DicomSender extends EventEmitter {
36665
+ constructor(options) {
36666
+ super();
36667
+ __publicField(this, "options");
36668
+ __publicField(this, "mode");
36669
+ __publicField(this, "configuredMaxAssociations");
36670
+ __publicField(this, "maxQueueLength");
36671
+ __publicField(this, "defaultTimeoutMs");
36672
+ __publicField(this, "defaultMaxRetries");
36673
+ __publicField(this, "retryDelayMs");
36674
+ __publicField(this, "bucketFlushMs");
36675
+ __publicField(this, "maxBucketSize");
36676
+ // Queue and concurrency state
36677
+ __publicField(this, "queue", []);
36678
+ __publicField(this, "activeAssociations", 0);
36679
+ __publicField(this, "isStopped", false);
36680
+ // Backpressure state
36681
+ __publicField(this, "health", SenderHealth.HEALTHY);
36682
+ __publicField(this, "effectiveMaxAssociations");
36683
+ __publicField(this, "consecutiveFailures", 0);
36684
+ __publicField(this, "consecutiveSuccesses", 0);
36685
+ // Bucket state (bucket mode only)
36686
+ __publicField(this, "currentBucket", []);
36687
+ __publicField(this, "bucketTimer");
36688
+ // AbortSignal
36689
+ __publicField(this, "abortHandler");
36690
+ this.setMaxListeners(20);
36691
+ this.on("error", () => {
36692
+ });
36693
+ this.options = options;
36694
+ const cfg = resolveConfig(options);
36695
+ this.mode = cfg.mode;
36696
+ this.configuredMaxAssociations = cfg.configuredMaxAssociations;
36697
+ this.effectiveMaxAssociations = cfg.configuredMaxAssociations;
36698
+ this.maxQueueLength = cfg.maxQueueLength;
36699
+ this.defaultTimeoutMs = cfg.defaultTimeoutMs;
36700
+ this.defaultMaxRetries = cfg.defaultMaxRetries;
36701
+ this.retryDelayMs = cfg.retryDelayMs;
36702
+ this.bucketFlushMs = cfg.bucketFlushMs;
36703
+ this.maxBucketSize = cfg.maxBucketSize;
36704
+ if (options.signal !== void 0) {
36705
+ this.wireAbortSignal(options.signal);
36706
+ }
36707
+ }
36708
+ // -----------------------------------------------------------------------
36709
+ // Public API
36710
+ // -----------------------------------------------------------------------
36711
+ /**
36712
+ * Creates a new DicomSender instance.
36713
+ *
36714
+ * @param options - Configuration options
36715
+ * @returns A Result containing the instance or a validation error
36716
+ */
36717
+ static create(options) {
36718
+ const validation = DicomSenderOptionsSchema.safeParse(options);
36719
+ if (!validation.success) {
36720
+ return err(createValidationError("DicomSender", validation.error));
36721
+ }
36722
+ return ok(new _DicomSender(options));
36723
+ }
36724
+ /**
36725
+ * Sends one or more DICOM files to the remote endpoint.
36726
+ *
36727
+ * In single/multiple mode, files are sent as one storescu call.
36728
+ * In bucket mode, files are accumulated into a bucket and flushed
36729
+ * when the bucket reaches maxBucketSize or the flush timer fires.
36730
+ *
36731
+ * The returned promise resolves when the files are actually sent
36732
+ * (not just queued). Callers can await for confirmation or
36733
+ * fire-and-forget with `void sender.send(files)`.
36734
+ *
36735
+ * @param files - One or more DICOM file paths
36736
+ * @param options - Per-send overrides
36737
+ * @returns A Result containing the send result or an error
36738
+ */
36739
+ send(files, options) {
36740
+ if (this.isStopped) {
36741
+ return Promise.resolve(err(new Error("DicomSender: sender is stopped")));
36742
+ }
36743
+ if (files.length === 0) {
36744
+ return Promise.resolve(err(new Error("DicomSender: no files provided")));
36745
+ }
36746
+ const timeoutMs = options?.timeoutMs ?? this.defaultTimeoutMs;
36747
+ const maxRetries = options?.maxRetries ?? this.defaultMaxRetries;
36748
+ switch (this.mode) {
36749
+ case "single":
36750
+ case "multiple":
36751
+ return this.enqueueSend(files, timeoutMs, maxRetries);
36752
+ case "bucket":
36753
+ return this.enqueueBucket(files, timeoutMs, maxRetries);
36754
+ default:
36755
+ assertUnreachable(this.mode);
36756
+ }
36757
+ }
36758
+ /**
36759
+ * Flushes the current bucket immediately (bucket mode only).
36760
+ * In single/multiple mode this is a no-op.
36761
+ */
36762
+ flush() {
36763
+ if (this.mode !== "bucket") return;
36764
+ if (this.currentBucket.length === 0) return;
36765
+ this.clearBucketTimer();
36766
+ this.flushBucketInternal("timer");
36767
+ }
36768
+ /**
36769
+ * Gracefully stops the sender. Rejects all queued items and
36770
+ * waits for active associations to complete.
36771
+ */
36772
+ async stop() {
36773
+ if (this.isStopped) return;
36774
+ this.isStopped = true;
36775
+ if (this.options.signal !== void 0 && this.abortHandler !== void 0) {
36776
+ this.options.signal.removeEventListener("abort", this.abortHandler);
36777
+ }
36778
+ this.clearBucketTimer();
36779
+ this.rejectBucket("DicomSender: sender stopped");
36780
+ this.rejectQueue("DicomSender: sender stopped");
36781
+ await this.waitForActive();
36782
+ }
36783
+ /** Current sender status. */
36784
+ get status() {
36785
+ return {
36786
+ health: this.health,
36787
+ activeAssociations: this.activeAssociations,
36788
+ effectiveMaxAssociations: this.effectiveMaxAssociations,
36789
+ queueLength: this.queue.length,
36790
+ consecutiveFailures: this.consecutiveFailures,
36791
+ consecutiveSuccesses: this.consecutiveSuccesses,
36792
+ stopped: this.isStopped
36793
+ };
36794
+ }
36795
+ // -----------------------------------------------------------------------
36796
+ // Typed event listener convenience methods
36797
+ // -----------------------------------------------------------------------
36798
+ /**
36799
+ * Registers a typed listener for a DicomSender-specific event.
36800
+ *
36801
+ * @param event - The event name from DicomSenderEventMap
36802
+ * @param listener - Callback receiving typed event data
36803
+ * @returns this for chaining
36804
+ */
36805
+ onEvent(event, listener) {
36806
+ return this.on(event, listener);
36807
+ }
36808
+ /**
36809
+ * Registers a listener for successful sends.
36810
+ *
36811
+ * @param listener - Callback receiving send complete data
36812
+ * @returns this for chaining
36813
+ */
36814
+ onSendComplete(listener) {
36815
+ return this.on("SEND_COMPLETE", listener);
36816
+ }
36817
+ /**
36818
+ * Registers a listener for failed sends.
36819
+ *
36820
+ * @param listener - Callback receiving send failed data
36821
+ * @returns this for chaining
36822
+ */
36823
+ onSendFailed(listener) {
36824
+ return this.on("SEND_FAILED", listener);
36825
+ }
36826
+ /**
36827
+ * Registers a listener for health state changes.
36828
+ *
36829
+ * @param listener - Callback receiving health change data
36830
+ * @returns this for chaining
36831
+ */
36832
+ onHealthChanged(listener) {
36833
+ return this.on("HEALTH_CHANGED", listener);
36834
+ }
36835
+ /**
36836
+ * Registers a listener for bucket flushes (bucket mode only).
36837
+ *
36838
+ * @param listener - Callback receiving bucket flush data
36839
+ * @returns this for chaining
36840
+ */
36841
+ onBucketFlushed(listener) {
36842
+ return this.on("BUCKET_FLUSHED", listener);
36843
+ }
36844
+ // -----------------------------------------------------------------------
36845
+ // Single/Multiple mode: queue-based dispatch
36846
+ // -----------------------------------------------------------------------
36847
+ /** Enqueues a send and dispatches immediately if capacity allows. */
36848
+ enqueueSend(files, timeoutMs, maxRetries) {
36849
+ return new Promise((resolve) => {
36850
+ const totalQueued = this.queue.length + this.currentBucket.length;
36851
+ if (totalQueued >= this.maxQueueLength) {
36852
+ resolve(err(new Error("DicomSender: queue full")));
36853
+ return;
36854
+ }
36855
+ const entry = { files, timeoutMs, maxRetries, resolve };
36856
+ if (this.activeAssociations < this.effectiveMaxAssociations) {
36857
+ void this.executeEntry(entry);
36858
+ } else {
36859
+ this.queue.push(entry);
36860
+ }
36861
+ });
36862
+ }
36863
+ /** Drains queued entries up to available capacity. */
36864
+ drainQueue() {
36865
+ while (this.queue.length > 0 && this.activeAssociations < this.effectiveMaxAssociations) {
36866
+ const entry = this.queue.shift();
36867
+ if (entry === void 0) break;
36868
+ void this.executeEntry(entry);
36869
+ }
36870
+ }
36871
+ // -----------------------------------------------------------------------
36872
+ // Bucket mode: accumulate-then-flush
36873
+ // -----------------------------------------------------------------------
36874
+ /** Adds files to the current bucket and triggers flush if full. */
36875
+ enqueueBucket(files, timeoutMs, maxRetries) {
36876
+ return new Promise((resolve) => {
36877
+ const totalQueued = this.queue.length + this.currentBucket.length;
36878
+ if (totalQueued >= this.maxQueueLength) {
36879
+ resolve(err(new Error("DicomSender: queue full")));
36880
+ return;
36881
+ }
36882
+ this.currentBucket.push({ files, resolve, timeoutMs, maxRetries });
36883
+ const totalFiles = this.countBucketFiles();
36884
+ if (totalFiles >= this.maxBucketSize) {
36885
+ this.clearBucketTimer();
36886
+ void this.flushBucketInternal("maxSize");
36887
+ } else {
36888
+ this.resetBucketTimer();
36889
+ }
36890
+ });
36891
+ }
36892
+ /** Counts total files in the current bucket. */
36893
+ countBucketFiles() {
36894
+ let count = 0;
36895
+ for (let i = 0; i < this.currentBucket.length; i++) {
36896
+ count += this.currentBucket[i].files.length;
36897
+ }
36898
+ return count;
36899
+ }
36900
+ /** Flushes the current bucket: combines all files, dispatches as one send. */
36901
+ flushBucketInternal(reason) {
36902
+ if (this.currentBucket.length === 0) return;
36903
+ const entries = [...this.currentBucket];
36904
+ this.currentBucket = [];
36905
+ const allFiles = [];
36906
+ for (let i = 0; i < entries.length; i++) {
36907
+ for (let j = 0; j < entries[i].files.length; j++) {
36908
+ allFiles.push(entries[i].files[j]);
36909
+ }
36910
+ }
36911
+ let timeoutMs = 0;
36912
+ let maxRetries = 0;
36913
+ for (let i = 0; i < entries.length; i++) {
36914
+ if (entries[i].timeoutMs > timeoutMs) timeoutMs = entries[i].timeoutMs;
36915
+ if (entries[i].maxRetries > maxRetries) maxRetries = entries[i].maxRetries;
36916
+ }
36917
+ this.emit("BUCKET_FLUSHED", { fileCount: allFiles.length, reason });
36918
+ const bucketEntry = {
36919
+ files: allFiles,
36920
+ timeoutMs,
36921
+ maxRetries,
36922
+ resolve: (result) => {
36923
+ for (let i = 0; i < entries.length; i++) {
36924
+ entries[i].resolve(result);
36925
+ }
36926
+ }
36927
+ };
36928
+ if (this.activeAssociations < this.effectiveMaxAssociations) {
36929
+ void this.executeEntry(bucketEntry);
36930
+ } else {
36931
+ this.queue.push(bucketEntry);
36932
+ }
36933
+ }
36934
+ /** Resets the bucket flush timer. */
36935
+ resetBucketTimer() {
36936
+ this.clearBucketTimer();
36937
+ this.bucketTimer = setTimeout(() => {
36938
+ this.bucketTimer = void 0;
36939
+ void this.flushBucketInternal("timer");
36940
+ }, this.bucketFlushMs);
36941
+ }
36942
+ /** Clears the bucket flush timer. */
36943
+ clearBucketTimer() {
36944
+ if (this.bucketTimer !== void 0) {
36945
+ clearTimeout(this.bucketTimer);
36946
+ this.bucketTimer = void 0;
36947
+ }
36948
+ }
36949
+ // -----------------------------------------------------------------------
36950
+ // Core send execution with retry
36951
+ // -----------------------------------------------------------------------
36952
+ /** Executes a single queue entry: calls storescu with retry. */
36953
+ async executeEntry(entry) {
36954
+ this.activeAssociations++;
36955
+ const startMs = Date.now();
36956
+ const maxAttempts = entry.maxRetries + 1;
36957
+ const lastError = await this.attemptSend(entry, maxAttempts, startMs);
36958
+ if (lastError === void 0) return;
36959
+ this.activeAssociations--;
36960
+ this.recordFailure();
36961
+ this.emit("SEND_FAILED", { files: entry.files, error: lastError, attempts: maxAttempts });
36962
+ entry.resolve(err(lastError));
36963
+ this.drainQueue();
36964
+ }
36965
+ /** Attempts storescu up to maxAttempts times. Returns undefined on success, or the last error. */
36966
+ async attemptSend(entry, maxAttempts, startMs) {
36967
+ let lastError;
36968
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
36969
+ if (this.isStopped) {
36970
+ this.activeAssociations--;
36971
+ entry.resolve(err(new Error("DicomSender: sender stopped")));
36972
+ return void 0;
36973
+ }
36974
+ const result = await this.callStorescu(entry);
36975
+ if (result.ok) {
36976
+ this.handleSendSuccess(entry, startMs);
36977
+ return void 0;
36978
+ }
36979
+ lastError = result.error;
36980
+ if (attempt < maxAttempts - 1) {
36981
+ await delay2(this.retryDelayMs * (attempt + 1));
36982
+ }
36983
+ }
36984
+ return lastError ?? new Error("DicomSender: send failed");
36985
+ }
36986
+ /** Calls storescu with the configured options. */
36987
+ callStorescu(entry) {
36988
+ return storescu({
36989
+ host: this.options.host,
36990
+ port: this.options.port,
36991
+ files: [...entry.files],
36992
+ calledAETitle: this.options.calledAETitle,
36993
+ callingAETitle: this.options.callingAETitle,
36994
+ proposedTransferSyntax: this.options.proposedTransferSyntax,
36995
+ timeoutMs: entry.timeoutMs,
36996
+ signal: this.options.signal
36997
+ });
36998
+ }
36999
+ /** Handles a successful send: updates state, emits event, resolves promise. */
37000
+ handleSendSuccess(entry, startMs) {
37001
+ this.activeAssociations--;
37002
+ const durationMs = Date.now() - startMs;
37003
+ this.recordSuccess();
37004
+ this.emit("SEND_COMPLETE", { files: entry.files, fileCount: entry.files.length, durationMs });
37005
+ entry.resolve(ok({ files: entry.files, fileCount: entry.files.length, durationMs }));
37006
+ this.drainQueue();
37007
+ }
37008
+ // -----------------------------------------------------------------------
37009
+ // Backpressure state machine
37010
+ // -----------------------------------------------------------------------
37011
+ /** Records a successful send and adjusts health upward if needed. */
37012
+ recordSuccess() {
37013
+ this.consecutiveFailures = 0;
37014
+ this.consecutiveSuccesses++;
37015
+ if (this.health === SenderHealth.HEALTHY) return;
37016
+ if (this.consecutiveSuccesses >= RECOVERY_THRESHOLD) {
37017
+ this.consecutiveSuccesses = 0;
37018
+ const previousHealth = this.health;
37019
+ if (this.health === SenderHealth.DOWN) {
37020
+ this.health = SenderHealth.DEGRADED;
37021
+ } else {
37022
+ this.effectiveMaxAssociations = Math.min(this.effectiveMaxAssociations * 2, this.configuredMaxAssociations);
37023
+ if (this.effectiveMaxAssociations >= this.configuredMaxAssociations) {
37024
+ this.health = SenderHealth.HEALTHY;
37025
+ }
37026
+ }
37027
+ this.emitHealthChanged(previousHealth);
37028
+ this.drainQueue();
37029
+ }
37030
+ }
37031
+ /** Records a failed send and adjusts health downward if needed. */
37032
+ recordFailure() {
37033
+ this.consecutiveSuccesses = 0;
37034
+ this.consecutiveFailures++;
37035
+ const previousHealth = this.health;
37036
+ if (this.consecutiveFailures >= DOWN_THRESHOLD) {
37037
+ if (this.health !== SenderHealth.DOWN) {
37038
+ this.health = SenderHealth.DOWN;
37039
+ this.effectiveMaxAssociations = 1;
37040
+ this.emitHealthChanged(previousHealth);
37041
+ }
37042
+ } else if (this.consecutiveFailures >= DEGRADE_THRESHOLD && this.consecutiveFailures % DEGRADE_THRESHOLD === 0) {
37043
+ if (this.health === SenderHealth.HEALTHY) {
37044
+ this.health = SenderHealth.DEGRADED;
37045
+ this.effectiveMaxAssociations = Math.max(1, Math.floor(this.configuredMaxAssociations / 2));
37046
+ this.emitHealthChanged(previousHealth);
37047
+ } else if (this.health === SenderHealth.DEGRADED) {
37048
+ const newMax = Math.max(1, Math.floor(this.effectiveMaxAssociations / 2));
37049
+ if (newMax !== this.effectiveMaxAssociations) {
37050
+ this.effectiveMaxAssociations = newMax;
37051
+ this.emitHealthChanged(previousHealth);
37052
+ }
37053
+ }
37054
+ }
37055
+ }
37056
+ /** Emits a HEALTH_CHANGED event. */
37057
+ emitHealthChanged(previousHealth) {
37058
+ this.emit("HEALTH_CHANGED", {
37059
+ previousHealth,
37060
+ newHealth: this.health,
37061
+ effectiveMaxAssociations: this.effectiveMaxAssociations,
37062
+ consecutiveFailures: this.consecutiveFailures
37063
+ });
37064
+ }
37065
+ // -----------------------------------------------------------------------
37066
+ // Lifecycle helpers
37067
+ // -----------------------------------------------------------------------
37068
+ /** Rejects all queued entries with the given message. */
37069
+ rejectQueue(message) {
37070
+ while (this.queue.length > 0) {
37071
+ const entry = this.queue.shift();
37072
+ if (entry === void 0) break;
37073
+ entry.resolve(err(new Error(message)));
37074
+ }
37075
+ }
37076
+ /** Rejects all bucket entries with the given message. */
37077
+ rejectBucket(message) {
37078
+ while (this.currentBucket.length > 0) {
37079
+ const entry = this.currentBucket.shift();
37080
+ if (entry === void 0) break;
37081
+ entry.resolve(err(new Error(message)));
37082
+ }
37083
+ }
37084
+ /** Waits for all active associations to complete. */
37085
+ waitForActive() {
37086
+ if (this.activeAssociations === 0) return Promise.resolve();
37087
+ return new Promise((resolve) => {
37088
+ const check = () => {
37089
+ if (this.activeAssociations === 0) {
37090
+ resolve();
37091
+ } else {
37092
+ setTimeout(check, 50);
37093
+ }
37094
+ };
37095
+ check();
37096
+ });
37097
+ }
37098
+ // -----------------------------------------------------------------------
37099
+ // Abort signal
37100
+ // -----------------------------------------------------------------------
37101
+ /** Wires an AbortSignal to stop the sender. */
37102
+ wireAbortSignal(signal) {
37103
+ if (signal.aborted) {
37104
+ void this.stop();
37105
+ return;
37106
+ }
37107
+ this.abortHandler = () => {
37108
+ void this.stop();
37109
+ };
37110
+ signal.addEventListener("abort", this.abortHandler, { once: true });
37111
+ }
37112
+ };
37113
+ function delay2(ms) {
37114
+ return new Promise((resolve) => {
37115
+ setTimeout(resolve, ms);
37116
+ });
37117
+ }
37118
+
35995
37119
  // src/pacs/types.ts
35996
37120
  var QueryLevel = {
35997
37121
  STUDY: "STUDY",
@@ -36541,7 +37665,7 @@ var DEFAULT_CONFIG = {
36541
37665
  signal: void 0,
36542
37666
  onRetry: void 0
36543
37667
  };
36544
- function resolveConfig(opts) {
37668
+ function resolveConfig2(opts) {
36545
37669
  if (!opts) return DEFAULT_CONFIG;
36546
37670
  return {
36547
37671
  ...DEFAULT_CONFIG,
@@ -36586,7 +37710,7 @@ function shouldBreakAfterFailure(attempt, lastError, config) {
36586
37710
  return false;
36587
37711
  }
36588
37712
  async function retry(operation, options) {
36589
- const config = resolveConfig(options);
37713
+ const config = resolveConfig2(options);
36590
37714
  let lastResult = err(new Error("No attempts executed"));
36591
37715
  for (let attempt = 0; attempt < config.maxAttempts; attempt += 1) {
36592
37716
  lastResult = await operation();
@@ -36600,6 +37724,6 @@ async function retry(operation, options) {
36600
37724
  return lastResult;
36601
37725
  }
36602
37726
 
36603
- export { AETitleSchema, AssociationTracker, ChangeSet, ColorConversion, DCMPRSCP_FATAL_EVENTS, DCMPRSCP_PATTERNS, DCMPSRCV_FATAL_EVENTS, DCMPSRCV_PATTERNS, DCMQRSCP_FATAL_EVENTS, DCMQRSCP_PATTERNS, DCMRECV_FATAL_EVENTS, DCMRECV_PATTERNS, DEFAULT_BLOCK_TIMEOUT_MS, DEFAULT_DICOM_PORT, DEFAULT_DRAIN_TIMEOUT_MS, DEFAULT_PARSE_CONCURRENCY, DEFAULT_START_TIMEOUT_MS, DEFAULT_TIMEOUT_MS, Dcm2pnmOutputFormat, Dcm2xmlCharset, DcmQRSCP, DcmdumpFormat, Dcmj2pnmOutputFormat, DcmprsCP, DcmprscpEvent, Dcmpsrcv, DcmpsrcvEvent, DcmqrscpEvent, Dcmrecv, DcmrecvEvent, DcmtkProcess, DicomDataset, DicomInstance, DicomReceiver, DicomTagPathSchema, DicomTagSchema, FilenameMode, GetQueryModel, Img2dcmInputFormat, JplsColorConversion, LineParser, LutType, MAX_BLOCK_LINES, MAX_CHANGESET_OPERATIONS, MAX_EVENT_PATTERNS, MAX_TRAVERSAL_DEPTH, MoveQueryModel, PDU_SIZE, PacsClient, PortSchema, PreferredTransferSyntax, ProcessState, ProposedTransferSyntax, QueryLevel, QueryModel, REQUIRED_BINARIES, RetrieveMode, SOP_CLASSES, STORESCP_FATAL_EVENTS, STORESCP_PATTERNS, StorageMode, StoreSCP, StoreSCPPreset, StorescpEvent, SubdirectoryMode, TransferSyntax, UIDSchema, UNIX_SEARCH_PATHS, VR, VR_CATEGORY, VR_CATEGORY_NAME, VR_META, WINDOWS_SEARCH_PATHS, WLMSCPFS_FATAL_EVENTS, WLMSCPFS_PATTERNS, Wlmscpfs, WlmscpfsEvent, assertUnreachable, batch, cda2dcm, clearDcmtkPathCache, createAETitle, createDicomFilePath, createDicomTag, createDicomTagPath, createPort, createSOPClassUID, createTransferSyntaxUID, dcm2cda, dcm2json, dcm2pdf, dcm2pnm, dcm2xml, dcmcjpeg, dcmcjpls, dcmconv, dcmcrle, dcmdecap, dcmdjpeg, dcmdjpls, dcmdrle, dcmdspfn, dcmdump, dcmencap, dcmftest, dcmgpdir, dcmj2pnm, dcmmkcrv, dcmmkdir, dcmmklut, dcmodify, dcmp2pgm, dcmprscu, dcmpschk, dcmpsmk, dcmpsprt, dcmqridx, dcmquant, dcmscale, dcmsend, dcod2lum, dconvlum, drtdump, dsr2xml, dsrdump, dump2dcm, echoscu, err, execCommand, findDcmtkPath, findscu, getVRCategory, getscu, img2dcm, isBinaryVR, isNumericVR, isStringVR, json2dcm, lookupTag, lookupTagByKeyword, lookupTagByName, mapResult, movescu, ok, parseAETitle, parseDicomTag, parseDicomTagPath, parsePort, parseSOPClassUID, parseTransferSyntaxUID, pdf2dcm, retry, segmentsToModifyPath, segmentsToString, sopClassNameFromUID, spawnCommand, stl2dcm, storescu, tag, tagPathToSegments, termscu, xml2dcm, xml2dsr, xmlToJson };
37727
+ export { AETitleSchema, AssociationTracker, ChangeSet, ColorConversion, DCMPRSCP_FATAL_EVENTS, DCMPRSCP_PATTERNS, DCMPSRCV_FATAL_EVENTS, DCMPSRCV_PATTERNS, DCMQRSCP_FATAL_EVENTS, DCMQRSCP_PATTERNS, DCMRECV_FATAL_EVENTS, DCMRECV_PATTERNS, DEFAULT_BLOCK_TIMEOUT_MS, DEFAULT_DICOM_PORT, DEFAULT_DRAIN_TIMEOUT_MS, DEFAULT_PARSE_CONCURRENCY, DEFAULT_START_TIMEOUT_MS, DEFAULT_TIMEOUT_MS, Dcm2pnmOutputFormat, Dcm2xmlCharset, DcmQRSCP, DcmdumpFormat, Dcmj2pnmOutputFormat, DcmprsCP, DcmprscpEvent, Dcmpsrcv, DcmpsrcvEvent, DcmqrscpEvent, Dcmrecv, DcmrecvEvent, DcmtkProcess, DicomDataset, DicomInstance, DicomReceiver, DicomSender, DicomTagPathSchema, DicomTagSchema, FilenameMode, GetQueryModel, Img2dcmInputFormat, JplsColorConversion, LineParser, LutType, MAX_BLOCK_LINES, MAX_CHANGESET_OPERATIONS, MAX_EVENT_PATTERNS, MAX_TRAVERSAL_DEPTH, MoveQueryModel, PDU_SIZE, PacsClient, PortSchema, PreferredTransferSyntax, ProcessState, ProposedTransferSyntax, QueryLevel, QueryModel, REQUIRED_BINARIES, RetrieveMode, SOP_CLASSES, STORESCP_FATAL_EVENTS, STORESCP_PATTERNS, SenderHealth, SenderMode, StorageMode, StoreSCP, StoreSCPPreset, StorescpEvent, SubdirectoryMode, TransferSyntax, UIDSchema, UNIX_SEARCH_PATHS, VR, VR_CATEGORY, VR_CATEGORY_NAME, VR_META, WINDOWS_SEARCH_PATHS, WLMSCPFS_FATAL_EVENTS, WLMSCPFS_PATTERNS, Wlmscpfs, WlmscpfsEvent, assertUnreachable, batch, cda2dcm, clearDcmtkPathCache, createAETitle, createDicomFilePath, createDicomTag, createDicomTagPath, createPort, createSOPClassUID, createTransferSyntaxUID, dcm2cda, dcm2json, dcm2pdf, dcm2pnm, dcm2xml, dcmcjpeg, dcmcjpls, dcmconv, dcmcrle, dcmdecap, dcmdjpeg, dcmdjpls, dcmdrle, dcmdspfn, dcmdump, dcmencap, dcmftest, dcmgpdir, dcmj2pnm, dcmmkcrv, dcmmkdir, dcmmklut, dcmodify, dcmp2pgm, dcmprscu, dcmpschk, dcmpsmk, dcmpsprt, dcmqridx, dcmquant, dcmscale, dcmsend, dcod2lum, dconvlum, drtdump, dsr2xml, dsrdump, dump2dcm, echoscu, err, execCommand, findDcmtkPath, findscu, getVRCategory, getscu, img2dcm, isBinaryVR, isNumericVR, isStringVR, json2dcm, lookupTag, lookupTagByKeyword, lookupTagByName, mapResult, movescu, ok, parseAETitle, parseDicomTag, parseDicomTagPath, parsePort, parseSOPClassUID, parseTransferSyntaxUID, pdf2dcm, retry, segmentsToModifyPath, segmentsToString, sopClassNameFromUID, spawnCommand, stl2dcm, storescu, tag, tagPathToSegments, termscu, xml2dcm, xml2dsr, xmlToJson };
36604
37728
  //# sourceMappingURL=index.js.map
36605
37729
  //# sourceMappingURL=index.js.map