@ubercode/dcmtk 0.9.3 → 0.10.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.
@@ -0,0 +1,112 @@
1
+ import { R as Result } from './types-Cgumy1N4.js';
2
+
3
+ /**
4
+ * Batch processing utility for running DCMTK operations on multiple files.
5
+ * Provides concurrency control and progress tracking.
6
+ *
7
+ * Note: Streaming APIs are not provided because DCMTK binaries operate on
8
+ * complete files, not streams. For large file processing, use {@link batch}
9
+ * to process files in parallel with concurrency control.
10
+ *
11
+ * @module utils/batch
12
+ */
13
+
14
+ /**
15
+ * Options for batch processing.
16
+ */
17
+ interface BatchOptions<T> {
18
+ /** Maximum number of concurrent operations. Defaults to 4. Min 1, max 64. */
19
+ readonly concurrency?: number | undefined;
20
+ /** Called after each item completes (success or failure). */
21
+ readonly onProgress?: ((completed: number, total: number, result: Result<T>) => void) | undefined;
22
+ /** AbortSignal for cancelling all remaining work. */
23
+ readonly signal?: AbortSignal | undefined;
24
+ }
25
+ /**
26
+ * Aggregated results from a batch operation.
27
+ */
28
+ interface BatchResult<T> {
29
+ /** Results in the same order as the input items. */
30
+ readonly results: ReadonlyArray<Result<T>>;
31
+ /** Number of successful operations. */
32
+ readonly succeeded: number;
33
+ /** Number of failed operations. */
34
+ readonly failed: number;
35
+ }
36
+ /**
37
+ * Processes items in parallel with concurrency control.
38
+ *
39
+ * Items are launched in order but may complete out of order. Results are
40
+ * always returned in the same order as the input items. When the AbortSignal
41
+ * fires, no new items are launched, but in-flight operations are allowed to
42
+ * complete.
43
+ *
44
+ * @param items - Array of input items to process
45
+ * @param operation - Async function to apply to each item, returning Result<T>
46
+ * @param options - Batch processing options
47
+ * @returns Aggregated results with success/failure counts
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { batch, dcmconv, TransferSyntax } from 'dcmtk';
52
+ *
53
+ * const files = ['a.dcm', 'b.dcm', 'c.dcm'];
54
+ * const results = await batch(
55
+ * files,
56
+ * file => dcmconv(file, `${file}.converted`, { transferSyntax: TransferSyntax.JPEG_LOSSLESS }),
57
+ * { concurrency: 2, onProgress: (done, total) => console.log(`${done}/${total}`) }
58
+ * );
59
+ * console.log(`Succeeded: ${results.succeeded}, Failed: ${results.failed}`);
60
+ * ```
61
+ */
62
+ declare function batch<TItem, TResult>(items: readonly TItem[], operation: (item: TItem) => Promise<Result<TResult>>, options?: BatchOptions<TResult>): Promise<BatchResult<TResult>>;
63
+
64
+ /**
65
+ * Retry utility with exponential backoff for unreliable operations.
66
+ *
67
+ * @module utils/retry
68
+ */
69
+
70
+ /**
71
+ * Options for retry behavior.
72
+ */
73
+ interface RetryOptions {
74
+ /** Maximum number of attempts (including initial). Defaults to 3. */
75
+ readonly maxAttempts?: number | undefined;
76
+ /** Initial delay in milliseconds before first retry. Defaults to 1000. */
77
+ readonly initialDelayMs?: number | undefined;
78
+ /** Maximum delay in milliseconds. Defaults to 30000. */
79
+ readonly maxDelayMs?: number | undefined;
80
+ /** Backoff multiplier. Defaults to 2. */
81
+ readonly backoffMultiplier?: number | undefined;
82
+ /** Optional predicate to determine if a failed result should be retried. */
83
+ readonly shouldRetry?: ((error: Error, attempt: number) => boolean) | undefined;
84
+ /** AbortSignal for cancelling retries. */
85
+ readonly signal?: AbortSignal | undefined;
86
+ /** Called before each retry attempt. */
87
+ readonly onRetry?: ((error: Error, attempt: number, delayMs: number) => void) | undefined;
88
+ }
89
+ /**
90
+ * Retries an operation with exponential backoff.
91
+ *
92
+ * The operation is called up to `maxAttempts` times. On failure, the delay
93
+ * before the next retry grows exponentially (with jitter) up to `maxDelayMs`.
94
+ * An AbortSignal can cancel the retry loop between attempts.
95
+ *
96
+ * @param operation - Async function returning Result<T>
97
+ * @param options - Retry options
98
+ * @returns The first successful result, or the last failure
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * import { retry, echoscu } from 'dcmtk';
103
+ *
104
+ * const result = await retry(
105
+ * () => echoscu({ host: 'pacs.hospital.org', port: 104 }),
106
+ * { maxAttempts: 5, initialDelayMs: 2000 }
107
+ * );
108
+ * ```
109
+ */
110
+ declare function retry<T>(operation: () => Promise<Result<T>>, options?: RetryOptions): Promise<Result<T>>;
111
+
112
+ export { type BatchOptions as B, type RetryOptions as R, type BatchResult as a, batch as b, retry as r };
@@ -0,0 +1,112 @@
1
+ import { R as Result } from './types-Cgumy1N4.cjs';
2
+
3
+ /**
4
+ * Batch processing utility for running DCMTK operations on multiple files.
5
+ * Provides concurrency control and progress tracking.
6
+ *
7
+ * Note: Streaming APIs are not provided because DCMTK binaries operate on
8
+ * complete files, not streams. For large file processing, use {@link batch}
9
+ * to process files in parallel with concurrency control.
10
+ *
11
+ * @module utils/batch
12
+ */
13
+
14
+ /**
15
+ * Options for batch processing.
16
+ */
17
+ interface BatchOptions<T> {
18
+ /** Maximum number of concurrent operations. Defaults to 4. Min 1, max 64. */
19
+ readonly concurrency?: number | undefined;
20
+ /** Called after each item completes (success or failure). */
21
+ readonly onProgress?: ((completed: number, total: number, result: Result<T>) => void) | undefined;
22
+ /** AbortSignal for cancelling all remaining work. */
23
+ readonly signal?: AbortSignal | undefined;
24
+ }
25
+ /**
26
+ * Aggregated results from a batch operation.
27
+ */
28
+ interface BatchResult<T> {
29
+ /** Results in the same order as the input items. */
30
+ readonly results: ReadonlyArray<Result<T>>;
31
+ /** Number of successful operations. */
32
+ readonly succeeded: number;
33
+ /** Number of failed operations. */
34
+ readonly failed: number;
35
+ }
36
+ /**
37
+ * Processes items in parallel with concurrency control.
38
+ *
39
+ * Items are launched in order but may complete out of order. Results are
40
+ * always returned in the same order as the input items. When the AbortSignal
41
+ * fires, no new items are launched, but in-flight operations are allowed to
42
+ * complete.
43
+ *
44
+ * @param items - Array of input items to process
45
+ * @param operation - Async function to apply to each item, returning Result<T>
46
+ * @param options - Batch processing options
47
+ * @returns Aggregated results with success/failure counts
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { batch, dcmconv, TransferSyntax } from 'dcmtk';
52
+ *
53
+ * const files = ['a.dcm', 'b.dcm', 'c.dcm'];
54
+ * const results = await batch(
55
+ * files,
56
+ * file => dcmconv(file, `${file}.converted`, { transferSyntax: TransferSyntax.JPEG_LOSSLESS }),
57
+ * { concurrency: 2, onProgress: (done, total) => console.log(`${done}/${total}`) }
58
+ * );
59
+ * console.log(`Succeeded: ${results.succeeded}, Failed: ${results.failed}`);
60
+ * ```
61
+ */
62
+ declare function batch<TItem, TResult>(items: readonly TItem[], operation: (item: TItem) => Promise<Result<TResult>>, options?: BatchOptions<TResult>): Promise<BatchResult<TResult>>;
63
+
64
+ /**
65
+ * Retry utility with exponential backoff for unreliable operations.
66
+ *
67
+ * @module utils/retry
68
+ */
69
+
70
+ /**
71
+ * Options for retry behavior.
72
+ */
73
+ interface RetryOptions {
74
+ /** Maximum number of attempts (including initial). Defaults to 3. */
75
+ readonly maxAttempts?: number | undefined;
76
+ /** Initial delay in milliseconds before first retry. Defaults to 1000. */
77
+ readonly initialDelayMs?: number | undefined;
78
+ /** Maximum delay in milliseconds. Defaults to 30000. */
79
+ readonly maxDelayMs?: number | undefined;
80
+ /** Backoff multiplier. Defaults to 2. */
81
+ readonly backoffMultiplier?: number | undefined;
82
+ /** Optional predicate to determine if a failed result should be retried. */
83
+ readonly shouldRetry?: ((error: Error, attempt: number) => boolean) | undefined;
84
+ /** AbortSignal for cancelling retries. */
85
+ readonly signal?: AbortSignal | undefined;
86
+ /** Called before each retry attempt. */
87
+ readonly onRetry?: ((error: Error, attempt: number, delayMs: number) => void) | undefined;
88
+ }
89
+ /**
90
+ * Retries an operation with exponential backoff.
91
+ *
92
+ * The operation is called up to `maxAttempts` times. On failure, the delay
93
+ * before the next retry grows exponentially (with jitter) up to `maxDelayMs`.
94
+ * An AbortSignal can cancel the retry loop between attempts.
95
+ *
96
+ * @param operation - Async function returning Result<T>
97
+ * @param options - Retry options
98
+ * @returns The first successful result, or the last failure
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * import { retry, echoscu } from 'dcmtk';
103
+ *
104
+ * const result = await retry(
105
+ * () => echoscu({ host: 'pacs.hospital.org', port: 104 }),
106
+ * { maxAttempts: 5, initialDelayMs: 2000 }
107
+ * );
108
+ * ```
109
+ */
110
+ declare function retry<T>(operation: () => Promise<Result<T>>, options?: RetryOptions): Promise<Result<T>>;
111
+
112
+ export { type BatchOptions as B, type RetryOptions as R, type BatchResult as a, batch as b, retry as r };