@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.
@@ -1,7 +1,7 @@
1
1
  import { L as LineSource, R as Result } from './types-Cgumy1N4.cjs';
2
2
  import { EventEmitter } from 'node:events';
3
- import { d as DicomInstance } from './DicomInstance-By9zd7GM.cjs';
4
- import './dcmodify-Gds9u5Vj.cjs';
3
+ import { d as DicomInstance } from './DicomInstance-DWOjhccQ.cjs';
4
+ import './dcmodify-B9js5K1f.cjs';
5
5
 
6
6
  /**
7
7
  * Base class for long-lived DCMTK processes (servers).
package/dist/servers.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { L as LineSource, R as Result } from './types-Cgumy1N4.js';
2
2
  import { EventEmitter } from 'node:events';
3
- import { d as DicomInstance } from './DicomInstance-CQEIuF_x.js';
4
- import './dcmodify-B-_uUIKB.js';
3
+ import { d as DicomInstance } from './DicomInstance-CGBr3a-C.js';
4
+ import './dcmodify-BvaIeyJg.js';
5
5
 
6
6
  /**
7
7
  * Base class for long-lived DCMTK processes (servers).
package/dist/servers.js CHANGED
@@ -384,7 +384,7 @@ var LineParser = class extends EventEmitter {
384
384
 
385
385
  // src/patterns.ts
386
386
  var DICOM_TAG_PATTERN = /^\([0-9A-Fa-f]{4},[0-9A-Fa-f]{4}\)$/;
387
- var AE_TITLE_PATTERN = /^[A-Za-z0-9 -]+$/;
387
+ var AE_TITLE_PATTERN = /^[\x20-\x5b\x5d-\x7e]+$/;
388
388
  var UID_PATTERN = /^[0-9]+(\.[0-9]+)*$/;
389
389
  var UID_MAX_LENGTH = 64;
390
390
  var PATH_TRAVERSAL_PATTERN = /(?:^|[\\/])\.\.(?:[\\/]|$)/;
@@ -2175,19 +2175,28 @@ function repairJson(raw) {
2175
2175
  var Dcm2jsonOptionsSchema = z.object({
2176
2176
  timeoutMs: z.number().int().positive().optional(),
2177
2177
  signal: z.instanceof(AbortSignal).optional(),
2178
- directOnly: z.boolean().optional()
2178
+ directOnly: z.boolean().optional(),
2179
+ verbosity: z.enum(["verbose", "debug"]).optional()
2179
2180
  }).strict().optional();
2180
- async function tryXmlPath(inputPath, timeoutMs, signal) {
2181
+ var VERBOSITY_FLAGS = { verbose: "-v", debug: "-d" };
2182
+ function buildVerbosityArgs(verbosity) {
2183
+ if (verbosity !== void 0) {
2184
+ return [VERBOSITY_FLAGS[verbosity]];
2185
+ }
2186
+ return [];
2187
+ }
2188
+ async function tryXmlPath(inputPath, timeoutMs, signal, verbosity) {
2181
2189
  const xmlBinary = resolveBinary("dcm2xml");
2182
2190
  if (!xmlBinary.ok) {
2183
2191
  return err(xmlBinary.error);
2184
2192
  }
2185
- const xmlResult = await execCommand(xmlBinary.value, ["-nat", inputPath], { timeoutMs, signal });
2193
+ const xmlArgs = [...buildVerbosityArgs(verbosity), "-nat", inputPath];
2194
+ const xmlResult = await execCommand(xmlBinary.value, xmlArgs, { timeoutMs, signal });
2186
2195
  if (!xmlResult.ok) {
2187
2196
  return err(xmlResult.error);
2188
2197
  }
2189
2198
  if (xmlResult.value.exitCode !== 0) {
2190
- return err(createToolError("dcm2xml", ["-nat", inputPath], xmlResult.value.exitCode, xmlResult.value.stderr));
2199
+ return err(createToolError("dcm2xml", xmlArgs, xmlResult.value.exitCode, xmlResult.value.stderr));
2191
2200
  }
2192
2201
  const jsonResult = xmlToJson(xmlResult.value.stdout);
2193
2202
  if (!jsonResult.ok) {
@@ -2195,17 +2204,18 @@ async function tryXmlPath(inputPath, timeoutMs, signal) {
2195
2204
  }
2196
2205
  return ok({ data: jsonResult.value, source: "xml" });
2197
2206
  }
2198
- async function tryDirectPath(inputPath, timeoutMs, signal) {
2207
+ async function tryDirectPath(inputPath, timeoutMs, signal, verbosity) {
2199
2208
  const jsonBinary = resolveBinary("dcm2json");
2200
2209
  if (!jsonBinary.ok) {
2201
2210
  return err(jsonBinary.error);
2202
2211
  }
2203
- const result = await execCommand(jsonBinary.value, [inputPath], { timeoutMs, signal });
2212
+ const directArgs = [...buildVerbosityArgs(verbosity), inputPath];
2213
+ const result = await execCommand(jsonBinary.value, directArgs, { timeoutMs, signal });
2204
2214
  if (!result.ok) {
2205
2215
  return err(result.error);
2206
2216
  }
2207
2217
  if (result.value.exitCode !== 0) {
2208
- return err(createToolError("dcm2json", [inputPath], result.value.exitCode, result.value.stderr));
2218
+ return err(createToolError("dcm2json", directArgs, result.value.exitCode, result.value.stderr));
2209
2219
  }
2210
2220
  try {
2211
2221
  const repaired = repairJson(result.value.stdout);
@@ -2222,20 +2232,22 @@ async function dcm2json(inputPath, options) {
2222
2232
  }
2223
2233
  const timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
2224
2234
  const signal = options?.signal;
2235
+ const verbosity = options?.verbosity;
2225
2236
  if (options?.directOnly === true) {
2226
- return tryDirectPath(inputPath, timeoutMs, signal);
2237
+ return tryDirectPath(inputPath, timeoutMs, signal, verbosity);
2227
2238
  }
2228
- const xmlResult = await tryXmlPath(inputPath, timeoutMs, signal);
2239
+ const xmlResult = await tryXmlPath(inputPath, timeoutMs, signal, verbosity);
2229
2240
  if (xmlResult.ok) {
2230
2241
  return xmlResult;
2231
2242
  }
2232
- return tryDirectPath(inputPath, timeoutMs, signal);
2243
+ return tryDirectPath(inputPath, timeoutMs, signal, verbosity);
2233
2244
  }
2234
2245
  var TAG_OR_PATH_PATTERN = /^\([0-9A-Fa-f]{4},[0-9A-Fa-f]{4}\)(\[\d+\](\.\([0-9A-Fa-f]{4},[0-9A-Fa-f]{4}\)(\[\d+\])?)*)?$/;
2235
2246
  var TagModificationSchema = z.object({
2236
2247
  tag: z.string().regex(TAG_OR_PATH_PATTERN),
2237
2248
  value: z.string()
2238
2249
  });
2250
+ var VERBOSITY_FLAGS2 = { verbose: "-v", debug: "-d" };
2239
2251
  var DcmodifyOptionsSchema = z.object({
2240
2252
  timeoutMs: z.number().int().positive().optional(),
2241
2253
  signal: z.instanceof(AbortSignal).optional(),
@@ -2244,12 +2256,16 @@ var DcmodifyOptionsSchema = z.object({
2244
2256
  erasePrivateTags: z.boolean().optional(),
2245
2257
  noBackup: z.boolean().optional(),
2246
2258
  insertIfMissing: z.boolean().optional(),
2247
- ignoreMissingTags: z.boolean().optional()
2259
+ ignoreMissingTags: z.boolean().optional(),
2260
+ verbosity: z.enum(["verbose", "debug"]).optional()
2248
2261
  }).strict().refine((data) => data.modifications.length > 0 || data.erasures !== void 0 && data.erasures.length > 0 || data.erasePrivateTags === true, {
2249
2262
  message: "At least one of modifications, erasures, or erasePrivateTags is required"
2250
2263
  });
2251
2264
  function buildArgs3(inputPath, options) {
2252
2265
  const args = [];
2266
+ if (options.verbosity !== void 0) {
2267
+ args.push(VERBOSITY_FLAGS2[options.verbosity]);
2268
+ }
2253
2269
  if (options.noBackup !== false) {
2254
2270
  args.push("-nb");
2255
2271
  }