@ubercode/dcmtk 0.13.0 → 0.13.2

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/servers.cjs CHANGED
@@ -2863,6 +2863,7 @@ var DicomReceiverOptionsSchema = zod.z.object({
2863
2863
  charsetAssume: zod.z.string().min(1).optional(),
2864
2864
  charsetFallback: zod.z.string().min(1).optional()
2865
2865
  }).strict().optional(),
2866
+ parseInstances: zod.z.boolean().optional(),
2866
2867
  signal: zod.z.instanceof(AbortSignal).optional()
2867
2868
  }).strict().refine((data) => (data.minPoolSize ?? DEFAULT_MIN_POOL_SIZE) <= (data.maxPoolSize ?? DEFAULT_MAX_POOL_SIZE), {
2868
2869
  message: "minPoolSize must be <= maxPoolSize"
@@ -2919,10 +2920,14 @@ var Worker = class {
2919
2920
  this._instancesReceived = 0;
2920
2921
  this._instanceErrors = 0;
2921
2922
  }
2922
- /** Returns the worker to idle and clears all association state. */
2923
+ /**
2924
+ * Returns the worker to idle. Context is intentionally preserved so that
2925
+ * late FILE_RECEIVED events (arriving in a subsequent pipe chunk after
2926
+ * ASSOCIATION_RELEASE) still have valid association info. Context is
2927
+ * cleared on the next {@link beginAssociation} call.
2928
+ */
2923
2929
  endAssociation() {
2924
2930
  this._state = "idle";
2925
- this._context = void 0;
2926
2931
  this._files.length = 0;
2927
2932
  this._fileSizes.length = 0;
2928
2933
  this._outputLines.length = 0;
@@ -3033,6 +3038,7 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
3033
3038
  __publicField(this, "maxPoolSize");
3034
3039
  __publicField(this, "connectionTimeoutMs");
3035
3040
  __publicField(this, "resolvedInstanceOpenOptions");
3041
+ __publicField(this, "parseInstances");
3036
3042
  __publicField(this, "workers", /* @__PURE__ */ new Map());
3037
3043
  __publicField(this, "tcpServer");
3038
3044
  __publicField(this, "associationCounter", 0);
@@ -3045,6 +3051,7 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
3045
3051
  this.maxPoolSize = options.maxPoolSize ?? DEFAULT_MAX_POOL_SIZE;
3046
3052
  this.connectionTimeoutMs = options.connectionTimeoutMs ?? DEFAULT_CONNECTION_TIMEOUT_MS;
3047
3053
  this.resolvedInstanceOpenOptions = { charsetFallback: "Latin1", ...options.instanceOpenOptions };
3054
+ this.parseInstances = options.parseInstances ?? true;
3048
3055
  }
3049
3056
  // -----------------------------------------------------------------------
3050
3057
  // Public API
@@ -3497,16 +3504,18 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
3497
3504
  calledAE: data.calledAE,
3498
3505
  source: data.source
3499
3506
  });
3500
- const instanceCtx = {
3501
- filePath: finalPath,
3502
- fileSize,
3503
- associationId: ctx.associationId,
3504
- associationDir: ctx.associationDir,
3505
- callingAE: data.callingAE,
3506
- calledAE: data.calledAE,
3507
- source: data.source
3508
- };
3509
- worker.trackInstance(this.parseAndEmitInstance(worker, instanceCtx));
3507
+ if (this.parseInstances) {
3508
+ const instanceCtx = {
3509
+ filePath: finalPath,
3510
+ fileSize,
3511
+ associationId: ctx.associationId,
3512
+ associationDir: ctx.associationDir,
3513
+ callingAE: data.callingAE,
3514
+ calledAE: data.calledAE,
3515
+ source: data.source
3516
+ };
3517
+ worker.trackInstance(this.parseAndEmitInstance(worker, instanceCtx));
3518
+ }
3510
3519
  }
3511
3520
  /** Parses a DICOM file and emits INSTANCE_RECEIVED or INSTANCE_ERROR. */
3512
3521
  async parseAndEmitInstance(worker, ctx) {
@@ -3528,7 +3537,9 @@ var DicomReceiver = class _DicomReceiver extends events.EventEmitter {
3528
3537
  /** Returns worker to idle pool on association complete, emits summary. */
3529
3538
  wireAssociationComplete(worker) {
3530
3539
  worker.dcmrecv.onAssociationComplete((data) => {
3531
- void this.finalizeAssociation(worker, data);
3540
+ setImmediate(() => {
3541
+ void this.finalizeAssociation(worker, data);
3542
+ });
3532
3543
  });
3533
3544
  }
3534
3545
  /** Awaits file ops, emits ASSOCIATION_COMPLETE, awaits parsing, emits ASSOCIATION_FINALIZED. */