@ubercode/dcmtk 0.7.1 → 0.7.3

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.cjs CHANGED
@@ -33225,7 +33225,18 @@ var ProposedTransferSyntax = {
33225
33225
  J2K_LOSSLESS: "j2kLossless",
33226
33226
  J2K_LOSSY: "j2kLossy",
33227
33227
  JLS_LOSSLESS: "jlsLossless",
33228
- JLS_LOSSY: "jlsLossy"
33228
+ JLS_LOSSY: "jlsLossy",
33229
+ MPEG2: "mpeg2",
33230
+ MPEG2_HIGH: "mpeg2High",
33231
+ MPEG4: "mpeg4",
33232
+ MPEG4_BD: "mpeg4Bd",
33233
+ MPEG4_2_2D: "mpeg4_2_2d",
33234
+ MPEG4_2_3D: "mpeg4_2_3d",
33235
+ MPEG4_2_ST: "mpeg4_2_st",
33236
+ HEVC: "hevc",
33237
+ HEVC10: "hevc10",
33238
+ RLE: "rle",
33239
+ DEFLATED: "deflated"
33229
33240
  };
33230
33241
  var PROPOSED_TS_FLAG_MAP = {
33231
33242
  [ProposedTransferSyntax.UNCOMPRESSED]: "-x=",
@@ -33238,8 +33249,20 @@ var PROPOSED_TS_FLAG_MAP = {
33238
33249
  [ProposedTransferSyntax.J2K_LOSSLESS]: "-xv",
33239
33250
  [ProposedTransferSyntax.J2K_LOSSY]: "-xw",
33240
33251
  [ProposedTransferSyntax.JLS_LOSSLESS]: "-xt",
33241
- [ProposedTransferSyntax.JLS_LOSSY]: "-xu"
33252
+ [ProposedTransferSyntax.JLS_LOSSY]: "-xu",
33253
+ [ProposedTransferSyntax.MPEG2]: "-xm",
33254
+ [ProposedTransferSyntax.MPEG2_HIGH]: "-xh",
33255
+ [ProposedTransferSyntax.MPEG4]: "-xn",
33256
+ [ProposedTransferSyntax.MPEG4_BD]: "-xl",
33257
+ [ProposedTransferSyntax.MPEG4_2_2D]: "-x2",
33258
+ [ProposedTransferSyntax.MPEG4_2_3D]: "-x3",
33259
+ [ProposedTransferSyntax.MPEG4_2_ST]: "-xo",
33260
+ [ProposedTransferSyntax.HEVC]: "-x4",
33261
+ [ProposedTransferSyntax.HEVC10]: "-x5",
33262
+ [ProposedTransferSyntax.RLE]: "-xr",
33263
+ [ProposedTransferSyntax.DEFLATED]: "-xd"
33242
33264
  };
33265
+ var PROPOSED_TS_VALUES = Object.values(ProposedTransferSyntax);
33243
33266
  var StorescuOptionsSchema = zod.z.object({
33244
33267
  timeoutMs: zod.z.number().int().positive().optional(),
33245
33268
  signal: zod.z.instanceof(AbortSignal).optional(),
@@ -33257,21 +33280,21 @@ var StorescuOptionsSchema = zod.z.object({
33257
33280
  acseTimeout: zod.z.number().int().positive().optional(),
33258
33281
  dimseTimeout: zod.z.number().int().positive().optional(),
33259
33282
  noHostnameLookup: zod.z.boolean().optional(),
33260
- proposedTransferSyntax: zod.z.enum([
33261
- "uncompressed",
33262
- "littleEndian",
33263
- "bigEndian",
33264
- "implicitVR",
33265
- "jpegLossless",
33266
- "jpeg8Bit",
33267
- "jpeg12Bit",
33268
- "j2kLossless",
33269
- "j2kLossy",
33270
- "jlsLossless",
33271
- "jlsLossy"
33272
- ]).optional()
33283
+ required: zod.z.boolean().optional(),
33284
+ proposedTransferSyntax: zod.z.union([zod.z.enum(PROPOSED_TS_VALUES), zod.z.array(zod.z.enum(PROPOSED_TS_VALUES)).min(1)]).optional(),
33285
+ combineProposedTransferSyntaxes: zod.z.boolean().optional()
33273
33286
  }).strict();
33287
+ function pushProposedTsArgs(args, ts) {
33288
+ if (typeof ts === "string") {
33289
+ args.push(PROPOSED_TS_FLAG_MAP[ts]);
33290
+ } else {
33291
+ for (let i = 0; i < ts.length; i++) {
33292
+ args.push(PROPOSED_TS_FLAG_MAP[ts[i]]);
33293
+ }
33294
+ }
33295
+ }
33274
33296
  var VERBOSITY_FLAGS20 = { verbose: "-v", debug: "-d" };
33297
+ var DIMSE_ERROR_PATTERN = /^E:.*(?:DIMSE Failed|Store Failed)/m;
33275
33298
  function pushNetworkArgs3(args, options) {
33276
33299
  if (options.verbosity !== void 0) {
33277
33300
  args.push(VERBOSITY_FLAGS20[options.verbosity]);
@@ -33311,7 +33334,13 @@ function buildArgs34(options) {
33311
33334
  args.push("+r");
33312
33335
  }
33313
33336
  if (options.proposedTransferSyntax !== void 0) {
33314
- args.push(PROPOSED_TS_FLAG_MAP[options.proposedTransferSyntax]);
33337
+ pushProposedTsArgs(args, options.proposedTransferSyntax);
33338
+ }
33339
+ if (options.combineProposedTransferSyntaxes === true) {
33340
+ args.push("+C");
33341
+ }
33342
+ if (options.required === true) {
33343
+ args.push("-R");
33315
33344
  }
33316
33345
  args.push(options.host, String(options.port));
33317
33346
  args.push(...options.files);
@@ -33338,6 +33367,9 @@ async function storescu(options) {
33338
33367
  if (result.value.exitCode !== 0) {
33339
33368
  return err(createToolError("storescu", args, result.value.exitCode, result.value.stderr));
33340
33369
  }
33370
+ if (DIMSE_ERROR_PATTERN.test(result.value.stderr)) {
33371
+ return err(createToolError("storescu", args, 0, result.value.stderr));
33372
+ }
33341
33373
  return ok({ success: true, stdout: result.value.stdout, stderr: result.value.stderr });
33342
33374
  }
33343
33375
  var QueryModel = {
@@ -36863,19 +36895,8 @@ var DicomSenderOptionsSchema = zod.z.object({
36863
36895
  callingAETitle: zod.z.string().min(1).max(16).refine(isValidAETitle, { message: "AE Title contains invalid characters" }).optional(),
36864
36896
  mode: zod.z.enum(["single", "multiple", "bucket"]).optional(),
36865
36897
  maxAssociations: zod.z.number().int().min(1).max(MAX_ASSOCIATIONS_LIMIT).optional(),
36866
- proposedTransferSyntax: zod.z.enum([
36867
- "uncompressed",
36868
- "littleEndian",
36869
- "bigEndian",
36870
- "implicitVR",
36871
- "jpegLossless",
36872
- "jpeg8Bit",
36873
- "jpeg12Bit",
36874
- "j2kLossless",
36875
- "j2kLossy",
36876
- "jlsLossless",
36877
- "jlsLossy"
36878
- ]).optional(),
36898
+ proposedTransferSyntax: zod.z.union([zod.z.enum(PROPOSED_TS_VALUES), zod.z.array(zod.z.enum(PROPOSED_TS_VALUES)).min(1)]).optional(),
36899
+ combineProposedTransferSyntaxes: zod.z.boolean().optional(),
36879
36900
  maxQueueLength: zod.z.number().int().min(1).optional(),
36880
36901
  timeoutMs: zod.z.number().int().positive().optional(),
36881
36902
  maxRetries: zod.z.number().int().min(0).optional(),
@@ -36889,6 +36910,7 @@ var DicomSenderOptionsSchema = zod.z.object({
36889
36910
  dimseTimeout: zod.z.number().int().positive().optional(),
36890
36911
  noHostnameLookup: zod.z.boolean().optional(),
36891
36912
  verbosity: zod.z.enum(["verbose", "debug"]).optional(),
36913
+ required: zod.z.boolean().optional(),
36892
36914
  signal: zod.z.instanceof(AbortSignal).optional()
36893
36915
  }).strict();
36894
36916
  function resolveConfig(options) {
@@ -36987,13 +37009,19 @@ var DicomSender = class _DicomSender extends events.EventEmitter {
36987
37009
  if (files.length === 0) {
36988
37010
  return Promise.resolve(err(new Error("DicomSender: no files provided")));
36989
37011
  }
36990
- const params = {
37012
+ return this.dispatchSend(files, this.buildSendParams(options));
37013
+ }
37014
+ /** Builds SendParams from per-send options, applying instance defaults. */
37015
+ buildSendParams(options) {
37016
+ return {
36991
37017
  timeoutMs: options?.timeoutMs ?? this.defaultTimeoutMs,
36992
37018
  maxRetries: options?.maxRetries ?? this.defaultMaxRetries,
36993
37019
  calledAETitle: options?.calledAETitle,
36994
- callingAETitle: options?.callingAETitle
37020
+ callingAETitle: options?.callingAETitle,
37021
+ required: options?.required,
37022
+ proposedTransferSyntax: options?.proposedTransferSyntax,
37023
+ combineProposedTransferSyntaxes: options?.combineProposedTransferSyntaxes
36995
37024
  };
36996
- return this.dispatchSend(files, params);
36997
37025
  }
36998
37026
  /** Dispatches a send to the appropriate mode handler. */
36999
37027
  dispatchSend(files, params) {
@@ -37110,6 +37138,9 @@ var DicomSender = class _DicomSender extends events.EventEmitter {
37110
37138
  maxRetries: params.maxRetries,
37111
37139
  calledAETitle: params.calledAETitle,
37112
37140
  callingAETitle: params.callingAETitle,
37141
+ required: params.required,
37142
+ proposedTransferSyntax: params.proposedTransferSyntax,
37143
+ combineProposedTransferSyntaxes: params.combineProposedTransferSyntaxes,
37113
37144
  resolve
37114
37145
  };
37115
37146
  if (this.activeAssociations < this.effectiveMaxAssociations) {
@@ -37138,8 +37169,18 @@ var DicomSender = class _DicomSender extends events.EventEmitter {
37138
37169
  resolve(err(new Error("DicomSender: queue full")));
37139
37170
  return;
37140
37171
  }
37141
- const { timeoutMs, maxRetries, calledAETitle, callingAETitle } = params;
37142
- this.currentBucket.push({ files, resolve, timeoutMs, maxRetries, calledAETitle, callingAETitle });
37172
+ const { timeoutMs, maxRetries, calledAETitle, callingAETitle, required, proposedTransferSyntax, combineProposedTransferSyntaxes } = params;
37173
+ this.currentBucket.push({
37174
+ files,
37175
+ resolve,
37176
+ timeoutMs,
37177
+ maxRetries,
37178
+ calledAETitle,
37179
+ callingAETitle,
37180
+ required,
37181
+ proposedTransferSyntax,
37182
+ combineProposedTransferSyntaxes
37183
+ });
37143
37184
  const totalFiles = this.countBucketFiles();
37144
37185
  if (totalFiles >= this.maxBucketSize) {
37145
37186
  this.clearBucketTimer();
@@ -37157,36 +37198,41 @@ var DicomSender = class _DicomSender extends events.EventEmitter {
37157
37198
  }
37158
37199
  return count;
37159
37200
  }
37160
- /** Flushes the current bucket: combines all files, dispatches as one send. */
37161
- flushBucketInternal(reason) {
37162
- if (this.currentBucket.length === 0) return;
37163
- const entries = [...this.currentBucket];
37164
- this.currentBucket = [];
37201
+ /** Merges bucket entries into a single QueueEntry. */
37202
+ mergeBucketEntries(entries) {
37165
37203
  const allFiles = [];
37204
+ let timeoutMs = 0;
37205
+ let maxRetries = 0;
37166
37206
  for (let i = 0; i < entries.length; i++) {
37167
37207
  for (let j = 0; j < entries[i].files.length; j++) {
37168
37208
  allFiles.push(entries[i].files[j]);
37169
37209
  }
37170
- }
37171
- let timeoutMs = 0;
37172
- let maxRetries = 0;
37173
- for (let i = 0; i < entries.length; i++) {
37174
37210
  if (entries[i].timeoutMs > timeoutMs) timeoutMs = entries[i].timeoutMs;
37175
37211
  if (entries[i].maxRetries > maxRetries) maxRetries = entries[i].maxRetries;
37176
37212
  }
37177
- this.emit("BUCKET_FLUSHED", { fileCount: allFiles.length, reason });
37178
- const bucketEntry = {
37213
+ return {
37179
37214
  files: allFiles,
37180
37215
  timeoutMs,
37181
37216
  maxRetries,
37182
37217
  calledAETitle: entries[0]?.calledAETitle,
37183
37218
  callingAETitle: entries[0]?.callingAETitle,
37219
+ required: entries[0]?.required,
37220
+ proposedTransferSyntax: entries[0]?.proposedTransferSyntax,
37221
+ combineProposedTransferSyntaxes: entries[0]?.combineProposedTransferSyntaxes,
37184
37222
  resolve: (result) => {
37185
37223
  for (let i = 0; i < entries.length; i++) {
37186
37224
  entries[i].resolve(result);
37187
37225
  }
37188
37226
  }
37189
37227
  };
37228
+ }
37229
+ /** Flushes the current bucket: combines all files, dispatches as one send. */
37230
+ flushBucketInternal(reason) {
37231
+ if (this.currentBucket.length === 0) return;
37232
+ const entries = [...this.currentBucket];
37233
+ this.currentBucket = [];
37234
+ const bucketEntry = this.mergeBucketEntries(entries);
37235
+ this.emit("BUCKET_FLUSHED", { fileCount: bucketEntry.files.length, reason });
37190
37236
  if (this.activeAssociations < this.effectiveMaxAssociations) {
37191
37237
  void this.executeEntry(bucketEntry);
37192
37238
  } else {
@@ -37260,7 +37306,8 @@ var DicomSender = class _DicomSender extends events.EventEmitter {
37260
37306
  files: [...entry.files],
37261
37307
  calledAETitle: entry.calledAETitle ?? this.options.calledAETitle,
37262
37308
  callingAETitle: entry.callingAETitle ?? this.options.callingAETitle,
37263
- proposedTransferSyntax: this.options.proposedTransferSyntax,
37309
+ proposedTransferSyntax: entry.proposedTransferSyntax ?? this.options.proposedTransferSyntax,
37310
+ combineProposedTransferSyntaxes: entry.combineProposedTransferSyntaxes ?? this.options.combineProposedTransferSyntaxes,
37264
37311
  maxPduReceive: this.options.maxPduReceive,
37265
37312
  maxPduSend: this.options.maxPduSend,
37266
37313
  associationTimeout: this.options.associationTimeout,
@@ -37268,6 +37315,7 @@ var DicomSender = class _DicomSender extends events.EventEmitter {
37268
37315
  dimseTimeout: this.options.dimseTimeout,
37269
37316
  noHostnameLookup: this.options.noHostnameLookup,
37270
37317
  verbosity: this.options.verbosity,
37318
+ required: entry.required ?? this.options.required,
37271
37319
  timeoutMs: entry.timeoutMs,
37272
37320
  signal: this.options.signal
37273
37321
  });