dicom-curate 0.28.0 → 0.28.1
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/esm/applyMappingsWorker.js +50 -44
- package/dist/esm/curateOne.js +1 -1
- package/dist/esm/index.js +16 -21
- package/dist/esm/mappingWorkerPool.js +15 -17
- package/dist/types/applyMappingsWorker.d.ts +6 -4
- package/dist/types/curateOne.d.ts +2 -2
- package/dist/umd/dicom-curate.umd.js +87 -62
- package/dist/umd/dicom-curate.umd.js.map +1 -1
- package/dist/umd/dicom-curate.umd.min.js +2 -2
- package/dist/umd/dicom-curate.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -80039,7 +80039,7 @@ async function curateOne({
|
|
|
80039
80039
|
hashPartSize
|
|
80040
80040
|
);
|
|
80041
80041
|
fileArrayBuffer = null;
|
|
80042
|
-
const previousPostMappedHash = previousMappedFileInfo ? previousMappedFileInfo(clonedMapResults.outputFilePath)?.postMappedHash : void 0;
|
|
80042
|
+
const previousPostMappedHash = previousMappedFileInfo ? (await previousMappedFileInfo(clonedMapResults.outputFilePath))?.postMappedHash : void 0;
|
|
80043
80043
|
if (previousPostMappedHash !== void 0 && previousPostMappedHash === postMappedHash) {
|
|
80044
80044
|
return noMapResult(clonedMapResults.outputFilePath);
|
|
80045
80045
|
}
|
|
@@ -85792,9 +85792,6 @@ function deserializeMappingOptions(serializedMappingOptions) {
|
|
|
85792
85792
|
return { ...rest, curationSpec };
|
|
85793
85793
|
}
|
|
85794
85794
|
|
|
85795
|
-
// src/types.ts
|
|
85796
|
-
var OUTPUT_FILE_PREFIX = "output#";
|
|
85797
|
-
|
|
85798
85795
|
// src/worker.ts
|
|
85799
85796
|
var wt = null;
|
|
85800
85797
|
async function initializeNodeWorker() {
|
|
@@ -85848,51 +85845,60 @@ function postErrorResponse(error2, fileInfo) {
|
|
|
85848
85845
|
});
|
|
85849
85846
|
}
|
|
85850
85847
|
}
|
|
85851
|
-
var
|
|
85848
|
+
var pendingLookupResolve = null;
|
|
85849
|
+
function lookupMappedFileInfo(outputPath) {
|
|
85850
|
+
return new Promise((resolve) => {
|
|
85851
|
+
pendingLookupResolve = resolve;
|
|
85852
|
+
globalThis.postMessage({
|
|
85853
|
+
response: "lookup",
|
|
85854
|
+
outputPath
|
|
85855
|
+
});
|
|
85856
|
+
});
|
|
85857
|
+
}
|
|
85852
85858
|
fixupNodeWorkerEnvironment().then(() => {
|
|
85853
85859
|
globalThis.addEventListener(
|
|
85854
85860
|
"message",
|
|
85855
85861
|
(event) => {
|
|
85856
|
-
|
|
85857
|
-
|
|
85858
|
-
|
|
85859
|
-
|
|
85860
|
-
|
|
85861
|
-
|
|
85862
|
-
const { serializedMappingOptions } = event.data;
|
|
85863
|
-
const mappingOptions = deserializeMappingOptions(
|
|
85864
|
-
serializedMappingOptions
|
|
85865
|
-
);
|
|
85866
|
-
const fileInfo = event.data.fileInfo;
|
|
85867
|
-
try {
|
|
85868
|
-
curateOne({
|
|
85869
|
-
fileInfo,
|
|
85870
|
-
outputTarget: event.data.outputTarget ?? {},
|
|
85871
|
-
hashMethod: event.data.hashMethod,
|
|
85872
|
-
hashPartSize: event.data.hashPartSize,
|
|
85873
|
-
mappingOptions,
|
|
85874
|
-
previousSourceFileInfo: event.data.previousFileInfo,
|
|
85875
|
-
previousMappedFileInfo: (targetName) => {
|
|
85876
|
-
const hash2 = postMappedFileInfo?.[OUTPUT_FILE_PREFIX + targetName];
|
|
85877
|
-
return hash2;
|
|
85878
|
-
}
|
|
85879
|
-
}).then((mapResults) => {
|
|
85880
|
-
globalThis.postMessage({
|
|
85881
|
-
response: "finished",
|
|
85882
|
-
mapResults
|
|
85883
|
-
});
|
|
85884
|
-
}).catch((error2) => {
|
|
85885
|
-
postErrorResponse(error2, fileInfo);
|
|
85886
|
-
});
|
|
85887
|
-
} catch (error2) {
|
|
85888
|
-
postErrorResponse(error2, fileInfo);
|
|
85889
|
-
}
|
|
85890
|
-
break;
|
|
85862
|
+
if ("response" in event.data && event.data.response === "lookupResult") {
|
|
85863
|
+
const resolve = pendingLookupResolve;
|
|
85864
|
+
pendingLookupResolve = null;
|
|
85865
|
+
if (resolve) {
|
|
85866
|
+
const hash2 = event.data.postMappedHash;
|
|
85867
|
+
resolve(hash2 ? { postMappedHash: hash2 } : void 0);
|
|
85891
85868
|
}
|
|
85892
|
-
|
|
85893
|
-
|
|
85894
|
-
|
|
85895
|
-
|
|
85869
|
+
return;
|
|
85870
|
+
}
|
|
85871
|
+
const data10 = event.data;
|
|
85872
|
+
if (data10.request !== "apply") {
|
|
85873
|
+
console.error(
|
|
85874
|
+
`Unknown request ${data10.request}`
|
|
85875
|
+
);
|
|
85876
|
+
return;
|
|
85877
|
+
}
|
|
85878
|
+
const { serializedMappingOptions } = data10;
|
|
85879
|
+
const mappingOptions = deserializeMappingOptions(
|
|
85880
|
+
serializedMappingOptions
|
|
85881
|
+
);
|
|
85882
|
+
const fileInfo = data10.fileInfo;
|
|
85883
|
+
try {
|
|
85884
|
+
curateOne({
|
|
85885
|
+
fileInfo,
|
|
85886
|
+
outputTarget: data10.outputTarget ?? {},
|
|
85887
|
+
hashMethod: data10.hashMethod,
|
|
85888
|
+
hashPartSize: data10.hashPartSize,
|
|
85889
|
+
mappingOptions,
|
|
85890
|
+
previousSourceFileInfo: data10.previousFileInfo,
|
|
85891
|
+
previousMappedFileInfo: lookupMappedFileInfo
|
|
85892
|
+
}).then((mapResults) => {
|
|
85893
|
+
globalThis.postMessage({
|
|
85894
|
+
response: "finished",
|
|
85895
|
+
mapResults
|
|
85896
|
+
});
|
|
85897
|
+
}).catch((error2) => {
|
|
85898
|
+
postErrorResponse(error2, fileInfo);
|
|
85899
|
+
});
|
|
85900
|
+
} catch (error2) {
|
|
85901
|
+
postErrorResponse(error2, fileInfo);
|
|
85896
85902
|
}
|
|
85897
85903
|
}
|
|
85898
85904
|
);
|
package/dist/esm/curateOne.js
CHANGED
|
@@ -73748,7 +73748,7 @@ async function curateOne({
|
|
|
73748
73748
|
hashPartSize
|
|
73749
73749
|
);
|
|
73750
73750
|
fileArrayBuffer = null;
|
|
73751
|
-
const previousPostMappedHash = previousMappedFileInfo ? previousMappedFileInfo(clonedMapResults.outputFilePath)?.postMappedHash : void 0;
|
|
73751
|
+
const previousPostMappedHash = previousMappedFileInfo ? (await previousMappedFileInfo(clonedMapResults.outputFilePath))?.postMappedHash : void 0;
|
|
73752
73752
|
if (previousPostMappedHash !== void 0 && previousPostMappedHash === postMappedHash) {
|
|
73753
73753
|
return noMapResult(clonedMapResults.outputFilePath);
|
|
73754
73754
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -81599,7 +81599,7 @@ async function curateOne({
|
|
|
81599
81599
|
hashPartSize
|
|
81600
81600
|
);
|
|
81601
81601
|
fileArrayBuffer = null;
|
|
81602
|
-
const previousPostMappedHash = previousMappedFileInfo ? previousMappedFileInfo(clonedMapResults.outputFilePath)?.postMappedHash : void 0;
|
|
81602
|
+
const previousPostMappedHash = previousMappedFileInfo ? (await previousMappedFileInfo(clonedMapResults.outputFilePath))?.postMappedHash : void 0;
|
|
81603
81603
|
if (previousPostMappedHash !== void 0 && previousPostMappedHash === postMappedHash) {
|
|
81604
81604
|
return noMapResult(clonedMapResults.outputFilePath);
|
|
81605
81605
|
}
|
|
@@ -87465,6 +87465,9 @@ async function getHttpOutputHeaders(outputTarget) {
|
|
|
87465
87465
|
return outputTarget;
|
|
87466
87466
|
}
|
|
87467
87467
|
|
|
87468
|
+
// src/types.ts
|
|
87469
|
+
var OUTPUT_FILE_PREFIX = "output#";
|
|
87470
|
+
|
|
87468
87471
|
// src/mappingWorkerPool.ts
|
|
87469
87472
|
var mappingWorkerOptions = {};
|
|
87470
87473
|
var availableMappingWorkers = [];
|
|
@@ -87512,10 +87515,7 @@ async function initializeMappingWorkers(skipCollectingMappings, fileInfoIndex, p
|
|
|
87512
87515
|
progressCallback = progressCb;
|
|
87513
87516
|
const effectiveWorkerCount = workerCount ?? Math.min(await getHardwareConcurrency(), 8);
|
|
87514
87517
|
const workers = await Promise.all(
|
|
87515
|
-
Array.from(
|
|
87516
|
-
{ length: effectiveWorkerCount },
|
|
87517
|
-
() => createMappingWorker(fileInfoIndex)
|
|
87518
|
-
)
|
|
87518
|
+
Array.from({ length: effectiveWorkerCount }, () => createMappingWorker())
|
|
87519
87519
|
);
|
|
87520
87520
|
availableMappingWorkers.push(...workers);
|
|
87521
87521
|
}
|
|
@@ -87615,7 +87615,7 @@ function recoverCrashedWorker(mappingWorker, errorMessage) {
|
|
|
87615
87615
|
});
|
|
87616
87616
|
dispatchMappingJobs();
|
|
87617
87617
|
pendingReplacements += 1;
|
|
87618
|
-
void createMappingWorker(
|
|
87618
|
+
void createMappingWorker().then((worker) => {
|
|
87619
87619
|
pendingReplacements -= 1;
|
|
87620
87620
|
availableMappingWorkers.push(worker);
|
|
87621
87621
|
dispatchMappingJobs();
|
|
@@ -87625,7 +87625,7 @@ function recoverCrashedWorker(mappingWorker, errorMessage) {
|
|
|
87625
87625
|
dispatchMappingJobs();
|
|
87626
87626
|
});
|
|
87627
87627
|
}
|
|
87628
|
-
async function createMappingWorker(
|
|
87628
|
+
async function createMappingWorker() {
|
|
87629
87629
|
const mappingWorker = await createWorker(
|
|
87630
87630
|
new URL("./applyMappingsWorker.js", import.meta.url),
|
|
87631
87631
|
{ type: "module" }
|
|
@@ -87645,18 +87645,16 @@ async function createMappingWorker(fileInfoIndex) {
|
|
|
87645
87645
|
}
|
|
87646
87646
|
});
|
|
87647
87647
|
}
|
|
87648
|
-
if (fileInfoIndex !== void 0) {
|
|
87649
|
-
const postMappedOnly = Object.fromEntries(
|
|
87650
|
-
Object.entries(fileInfoIndex).filter(
|
|
87651
|
-
([_key, value]) => !!value.postMappedHash
|
|
87652
|
-
)
|
|
87653
|
-
);
|
|
87654
|
-
mappingWorker.postMessage({
|
|
87655
|
-
request: "fileInfoIndex",
|
|
87656
|
-
fileInfoIndex: postMappedOnly
|
|
87657
|
-
});
|
|
87658
|
-
}
|
|
87659
87648
|
mappingWorker.addEventListener("message", (event) => {
|
|
87649
|
+
if (event.data.response === "lookup") {
|
|
87650
|
+
const outputPath = event.data.outputPath;
|
|
87651
|
+
const entry = currentFileInfoIndex?.[OUTPUT_FILE_PREFIX + outputPath];
|
|
87652
|
+
mappingWorker.postMessage({
|
|
87653
|
+
response: "lookupResult",
|
|
87654
|
+
postMappedHash: entry?.postMappedHash
|
|
87655
|
+
});
|
|
87656
|
+
return;
|
|
87657
|
+
}
|
|
87660
87658
|
lastWorkerProgressTime = Date.now();
|
|
87661
87659
|
workerCurrentFile.delete(mappingWorker);
|
|
87662
87660
|
switch (event.data.response) {
|
|
@@ -87715,9 +87713,6 @@ function getLastWorkerProgressTime() {
|
|
|
87715
87713
|
return lastWorkerProgressTime;
|
|
87716
87714
|
}
|
|
87717
87715
|
|
|
87718
|
-
// src/types.ts
|
|
87719
|
-
var OUTPUT_FILE_PREFIX = "output#";
|
|
87720
|
-
|
|
87721
87716
|
// src/index.ts
|
|
87722
87717
|
function requiresDateOffset(deIdOpts) {
|
|
87723
87718
|
return deIdOpts !== "Off" && deIdOpts.retainLongitudinalTemporalInformationOptions === "Offset";
|
|
@@ -12043,6 +12043,9 @@ function dataURLToBlobURL(dataURL) {
|
|
|
12043
12043
|
return URL.createObjectURL(blob);
|
|
12044
12044
|
}
|
|
12045
12045
|
|
|
12046
|
+
// src/types.ts
|
|
12047
|
+
var OUTPUT_FILE_PREFIX = "output#";
|
|
12048
|
+
|
|
12046
12049
|
// src/mappingWorkerPool.ts
|
|
12047
12050
|
var mappingWorkerOptions = {};
|
|
12048
12051
|
var availableMappingWorkers = [];
|
|
@@ -12090,10 +12093,7 @@ async function initializeMappingWorkers(skipCollectingMappings, fileInfoIndex, p
|
|
|
12090
12093
|
progressCallback = progressCb;
|
|
12091
12094
|
const effectiveWorkerCount = workerCount ?? Math.min(await getHardwareConcurrency(), 8);
|
|
12092
12095
|
const workers = await Promise.all(
|
|
12093
|
-
Array.from(
|
|
12094
|
-
{ length: effectiveWorkerCount },
|
|
12095
|
-
() => createMappingWorker(fileInfoIndex)
|
|
12096
|
-
)
|
|
12096
|
+
Array.from({ length: effectiveWorkerCount }, () => createMappingWorker())
|
|
12097
12097
|
);
|
|
12098
12098
|
availableMappingWorkers.push(...workers);
|
|
12099
12099
|
}
|
|
@@ -12193,7 +12193,7 @@ function recoverCrashedWorker(mappingWorker, errorMessage) {
|
|
|
12193
12193
|
});
|
|
12194
12194
|
dispatchMappingJobs();
|
|
12195
12195
|
pendingReplacements += 1;
|
|
12196
|
-
void createMappingWorker(
|
|
12196
|
+
void createMappingWorker().then((worker) => {
|
|
12197
12197
|
pendingReplacements -= 1;
|
|
12198
12198
|
availableMappingWorkers.push(worker);
|
|
12199
12199
|
dispatchMappingJobs();
|
|
@@ -12203,7 +12203,7 @@ function recoverCrashedWorker(mappingWorker, errorMessage) {
|
|
|
12203
12203
|
dispatchMappingJobs();
|
|
12204
12204
|
});
|
|
12205
12205
|
}
|
|
12206
|
-
async function createMappingWorker(
|
|
12206
|
+
async function createMappingWorker() {
|
|
12207
12207
|
const mappingWorker = await createWorker(
|
|
12208
12208
|
new URL("./applyMappingsWorker.js", import.meta.url),
|
|
12209
12209
|
{ type: "module" }
|
|
@@ -12223,18 +12223,16 @@ async function createMappingWorker(fileInfoIndex) {
|
|
|
12223
12223
|
}
|
|
12224
12224
|
});
|
|
12225
12225
|
}
|
|
12226
|
-
if (fileInfoIndex !== void 0) {
|
|
12227
|
-
const postMappedOnly = Object.fromEntries(
|
|
12228
|
-
Object.entries(fileInfoIndex).filter(
|
|
12229
|
-
([_key, value]) => !!value.postMappedHash
|
|
12230
|
-
)
|
|
12231
|
-
);
|
|
12232
|
-
mappingWorker.postMessage({
|
|
12233
|
-
request: "fileInfoIndex",
|
|
12234
|
-
fileInfoIndex: postMappedOnly
|
|
12235
|
-
});
|
|
12236
|
-
}
|
|
12237
12226
|
mappingWorker.addEventListener("message", (event) => {
|
|
12227
|
+
if (event.data.response === "lookup") {
|
|
12228
|
+
const outputPath = event.data.outputPath;
|
|
12229
|
+
const entry = currentFileInfoIndex?.[OUTPUT_FILE_PREFIX + outputPath];
|
|
12230
|
+
mappingWorker.postMessage({
|
|
12231
|
+
response: "lookupResult",
|
|
12232
|
+
postMappedHash: entry?.postMappedHash
|
|
12233
|
+
});
|
|
12234
|
+
return;
|
|
12235
|
+
}
|
|
12238
12236
|
lastWorkerProgressTime = Date.now();
|
|
12239
12237
|
workerCurrentFile.delete(mappingWorker);
|
|
12240
12238
|
switch (event.data.response) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TFileInfo, type
|
|
1
|
+
import { type TFileInfo, type THashMethod, type TOutputTarget, type TSerializedMappingOptions } from './types';
|
|
2
2
|
export type MappingRequest = {
|
|
3
3
|
request: 'apply';
|
|
4
4
|
fileInfo: TFileInfo;
|
|
@@ -11,7 +11,9 @@ export type MappingRequest = {
|
|
|
11
11
|
hashMethod?: THashMethod;
|
|
12
12
|
hashPartSize?: number;
|
|
13
13
|
serializedMappingOptions: TSerializedMappingOptions;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
};
|
|
15
|
+
/** Response sent back from the main thread for a fileInfoIndex lookup. */
|
|
16
|
+
export type LookupResponse = {
|
|
17
|
+
response: 'lookupResult';
|
|
18
|
+
postMappedHash?: string;
|
|
17
19
|
};
|
|
@@ -10,9 +10,9 @@ export type TCurateOneArgs = {
|
|
|
10
10
|
mtime?: string;
|
|
11
11
|
preMappedHash?: string;
|
|
12
12
|
};
|
|
13
|
-
previousMappedFileInfo?: (mappedFileName: string) => {
|
|
13
|
+
previousMappedFileInfo?: (mappedFileName: string) => Promise<{
|
|
14
14
|
postMappedHash?: string;
|
|
15
|
-
} | undefined
|
|
15
|
+
} | undefined>;
|
|
16
16
|
};
|
|
17
17
|
export declare function curateOne({ fileInfo, outputTarget, mappingOptions, hashMethod, hashPartSize, previousSourceFileInfo, previousMappedFileInfo, }: TCurateOneArgs): Promise<Omit<Partial<TMapResults>, 'anomalies'> & {
|
|
18
18
|
anomalies: TMapResults['anomalies'];
|
|
@@ -49170,7 +49170,8 @@
|
|
|
49170
49170
|
// allocation that can now be GC'd.
|
|
49171
49171
|
fileArrayBuffer = null;
|
|
49172
49172
|
const previousPostMappedHash = previousMappedFileInfo
|
|
49173
|
-
? previousMappedFileInfo(clonedMapResults.outputFilePath)
|
|
49173
|
+
? (await previousMappedFileInfo(clonedMapResults.outputFilePath))
|
|
49174
|
+
?.postMappedHash
|
|
49174
49175
|
: undefined;
|
|
49175
49176
|
if (previousPostMappedHash !== undefined &&
|
|
49176
49177
|
previousPostMappedHash === postMappedHash) {
|
|
@@ -62473,9 +62474,6 @@
|
|
|
62473
62474
|
return { ...rest, curationSpec };
|
|
62474
62475
|
}
|
|
62475
62476
|
|
|
62476
|
-
// Kept here, because it is also imported from the worker
|
|
62477
|
-
const OUTPUT_FILE_PREFIX = 'output#';
|
|
62478
|
-
|
|
62479
62477
|
let wt = null;
|
|
62480
62478
|
// Lazy initialization for Node.js worker_threads
|
|
62481
62479
|
async function initializeNodeWorker() {
|
|
@@ -62544,52 +62542,72 @@
|
|
|
62544
62542
|
});
|
|
62545
62543
|
}
|
|
62546
62544
|
}
|
|
62547
|
-
|
|
62545
|
+
/**
|
|
62546
|
+
* Pending lookup resolve function. At most one lookup is in flight at a time
|
|
62547
|
+
* because each worker processes one file at a time sequentially.
|
|
62548
|
+
*/
|
|
62549
|
+
let pendingLookupResolve = null;
|
|
62550
|
+
/**
|
|
62551
|
+
* Request a postMappedHash lookup from the main thread.
|
|
62552
|
+
* Returns a Promise that resolves when the main thread replies with
|
|
62553
|
+
* a 'lookupResult' message.
|
|
62554
|
+
*/
|
|
62555
|
+
function lookupMappedFileInfo(outputPath) {
|
|
62556
|
+
return new Promise((resolve) => {
|
|
62557
|
+
pendingLookupResolve = resolve;
|
|
62558
|
+
globalThis.postMessage({
|
|
62559
|
+
response: 'lookup',
|
|
62560
|
+
outputPath,
|
|
62561
|
+
});
|
|
62562
|
+
});
|
|
62563
|
+
}
|
|
62548
62564
|
fixupNodeWorkerEnvironment()
|
|
62549
62565
|
.then(() => {
|
|
62550
62566
|
globalThis.addEventListener('message', (event) => {
|
|
62551
|
-
|
|
62552
|
-
|
|
62553
|
-
|
|
62554
|
-
|
|
62555
|
-
|
|
62556
|
-
|
|
62557
|
-
const
|
|
62558
|
-
|
|
62559
|
-
const fileInfo = event.data.fileInfo;
|
|
62560
|
-
try {
|
|
62561
|
-
curateOne({
|
|
62562
|
-
fileInfo,
|
|
62563
|
-
outputTarget: event.data.outputTarget ?? {},
|
|
62564
|
-
hashMethod: event.data.hashMethod,
|
|
62565
|
-
hashPartSize: event.data.hashPartSize,
|
|
62566
|
-
mappingOptions,
|
|
62567
|
-
previousSourceFileInfo: event.data.previousFileInfo,
|
|
62568
|
-
previousMappedFileInfo: (targetName) => {
|
|
62569
|
-
const hash = postMappedFileInfo?.[OUTPUT_FILE_PREFIX + targetName];
|
|
62570
|
-
return hash;
|
|
62571
|
-
},
|
|
62572
|
-
})
|
|
62573
|
-
.then((mapResults) => {
|
|
62574
|
-
// Send finished message for completion
|
|
62575
|
-
globalThis.postMessage({
|
|
62576
|
-
response: 'finished',
|
|
62577
|
-
mapResults: mapResults,
|
|
62578
|
-
});
|
|
62579
|
-
})
|
|
62580
|
-
.catch((error) => {
|
|
62581
|
-
// also catch promise rejections
|
|
62582
|
-
postErrorResponse(error, fileInfo);
|
|
62583
|
-
});
|
|
62584
|
-
}
|
|
62585
|
-
catch (error) {
|
|
62586
|
-
postErrorResponse(error, fileInfo);
|
|
62587
|
-
// no need to throw here, it would terminate the worker
|
|
62588
|
-
}
|
|
62589
|
-
break;
|
|
62567
|
+
// Handle lookup response from main thread
|
|
62568
|
+
if ('response' in event.data &&
|
|
62569
|
+
event.data.response === 'lookupResult') {
|
|
62570
|
+
const resolve = pendingLookupResolve;
|
|
62571
|
+
pendingLookupResolve = null;
|
|
62572
|
+
if (resolve) {
|
|
62573
|
+
const hash = event.data.postMappedHash;
|
|
62574
|
+
resolve(hash ? { postMappedHash: hash } : undefined);
|
|
62590
62575
|
}
|
|
62591
|
-
|
|
62592
|
-
|
|
62576
|
+
return;
|
|
62577
|
+
}
|
|
62578
|
+
const data = event.data;
|
|
62579
|
+
if (data.request !== 'apply') {
|
|
62580
|
+
console.error(`Unknown request ${data.request}`);
|
|
62581
|
+
return;
|
|
62582
|
+
}
|
|
62583
|
+
const { serializedMappingOptions } = data;
|
|
62584
|
+
const mappingOptions = deserializeMappingOptions(serializedMappingOptions);
|
|
62585
|
+
const fileInfo = data.fileInfo;
|
|
62586
|
+
try {
|
|
62587
|
+
curateOne({
|
|
62588
|
+
fileInfo,
|
|
62589
|
+
outputTarget: data.outputTarget ?? {},
|
|
62590
|
+
hashMethod: data.hashMethod,
|
|
62591
|
+
hashPartSize: data.hashPartSize,
|
|
62592
|
+
mappingOptions,
|
|
62593
|
+
previousSourceFileInfo: data.previousFileInfo,
|
|
62594
|
+
previousMappedFileInfo: lookupMappedFileInfo,
|
|
62595
|
+
})
|
|
62596
|
+
.then((mapResults) => {
|
|
62597
|
+
// Send finished message for completion
|
|
62598
|
+
globalThis.postMessage({
|
|
62599
|
+
response: 'finished',
|
|
62600
|
+
mapResults: mapResults,
|
|
62601
|
+
});
|
|
62602
|
+
})
|
|
62603
|
+
.catch((error) => {
|
|
62604
|
+
// also catch promise rejections
|
|
62605
|
+
postErrorResponse(error, fileInfo);
|
|
62606
|
+
});
|
|
62607
|
+
}
|
|
62608
|
+
catch (error) {
|
|
62609
|
+
postErrorResponse(error, fileInfo);
|
|
62610
|
+
// no need to throw here, it would terminate the worker
|
|
62593
62611
|
}
|
|
62594
62612
|
});
|
|
62595
62613
|
})
|
|
@@ -111283,7 +111301,8 @@
|
|
|
111283
111301
|
// allocation that can now be GC'd.
|
|
111284
111302
|
fileArrayBuffer = null;
|
|
111285
111303
|
const previousPostMappedHash = previousMappedFileInfo
|
|
111286
|
-
? previousMappedFileInfo(clonedMapResults.outputFilePath)
|
|
111304
|
+
? (await previousMappedFileInfo(clonedMapResults.outputFilePath))
|
|
111305
|
+
?.postMappedHash
|
|
111287
111306
|
: undefined;
|
|
111288
111307
|
if (previousPostMappedHash !== undefined &&
|
|
111289
111308
|
previousPostMappedHash === postMappedHash) {
|
|
@@ -126881,6 +126900,9 @@
|
|
|
126881
126900
|
return outputTarget;
|
|
126882
126901
|
}
|
|
126883
126902
|
|
|
126903
|
+
// Kept here, because it is also imported from the worker
|
|
126904
|
+
const OUTPUT_FILE_PREFIX = 'output#';
|
|
126905
|
+
|
|
126884
126906
|
/**
|
|
126885
126907
|
* Mapping worker pool management.
|
|
126886
126908
|
*
|
|
@@ -126906,8 +126928,8 @@
|
|
|
126906
126928
|
// The termination condition in dispatchMappingJobs() waits for this to reach 0
|
|
126907
126929
|
// before finishing, to avoid orphaning in-flight replacements.
|
|
126908
126930
|
let pendingReplacements = 0;
|
|
126909
|
-
// Stored fileInfoIndex from initializeMappingWorkers,
|
|
126910
|
-
//
|
|
126931
|
+
// Stored fileInfoIndex from initializeMappingWorkers, used for lookup
|
|
126932
|
+
// responses when workers query for previousMappedFileInfo.
|
|
126911
126933
|
let currentFileInfoIndex;
|
|
126912
126934
|
// Shared state accessed by both scan worker (in index.ts) and dispatch (here).
|
|
126913
126935
|
// Exported so index.ts can push items and set the scan-finished flag.
|
|
@@ -126968,7 +126990,7 @@
|
|
|
126968
126990
|
if (progressCb)
|
|
126969
126991
|
progressCallback = progressCb;
|
|
126970
126992
|
const effectiveWorkerCount = workerCount ?? Math.min(await getHardwareConcurrency(), 8);
|
|
126971
|
-
const workers = await Promise.all(Array.from({ length: effectiveWorkerCount }, () => createMappingWorker(
|
|
126993
|
+
const workers = await Promise.all(Array.from({ length: effectiveWorkerCount }, () => createMappingWorker()));
|
|
126972
126994
|
availableMappingWorkers.push(...workers);
|
|
126973
126995
|
}
|
|
126974
126996
|
/**
|
|
@@ -127100,7 +127122,7 @@
|
|
|
127100
127122
|
// Spawn a replacement worker so the pool doesn't shrink permanently.
|
|
127101
127123
|
// A directory with many problematic files could otherwise kill all workers.
|
|
127102
127124
|
pendingReplacements += 1;
|
|
127103
|
-
void createMappingWorker(
|
|
127125
|
+
void createMappingWorker()
|
|
127104
127126
|
.then((worker) => {
|
|
127105
127127
|
pendingReplacements -= 1;
|
|
127106
127128
|
availableMappingWorkers.push(worker);
|
|
@@ -127117,7 +127139,7 @@
|
|
|
127117
127139
|
* Used by both initializeMappingWorkers (initial pool) and recoverCrashedWorker
|
|
127118
127140
|
* (replacement after crash).
|
|
127119
127141
|
*/
|
|
127120
|
-
async function createMappingWorker(
|
|
127142
|
+
async function createMappingWorker() {
|
|
127121
127143
|
const mappingWorker = await createWorker(new URL('./applyMappingsWorker.js', (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('dicom-curate.umd.js', document.baseURI).href))), { type: 'module' });
|
|
127122
127144
|
// Handle worker-level errors (uncaught exceptions, DataCloneError, etc.).
|
|
127123
127145
|
// The previous `onerror = console.error` only logged and did not recover
|
|
@@ -127139,14 +127161,20 @@
|
|
|
127139
127161
|
}
|
|
127140
127162
|
});
|
|
127141
127163
|
}
|
|
127142
|
-
if (fileInfoIndex !== undefined) {
|
|
127143
|
-
const postMappedOnly = Object.fromEntries(Object.entries(fileInfoIndex).filter(([_key, value]) => !!value.postMappedHash));
|
|
127144
|
-
mappingWorker.postMessage({
|
|
127145
|
-
request: 'fileInfoIndex',
|
|
127146
|
-
fileInfoIndex: postMappedOnly,
|
|
127147
|
-
});
|
|
127148
|
-
}
|
|
127149
127164
|
mappingWorker.addEventListener('message', (event) => {
|
|
127165
|
+
// Handle lookup requests from the worker. The worker sends these when
|
|
127166
|
+
// curateOne needs to check if a mapped file was already uploaded
|
|
127167
|
+
// (previousMappedFileInfo). The index is kept on the main thread to
|
|
127168
|
+
// avoid copying 200k+ entries to every worker.
|
|
127169
|
+
if (event.data.response === 'lookup') {
|
|
127170
|
+
const outputPath = event.data.outputPath;
|
|
127171
|
+
const entry = currentFileInfoIndex?.[OUTPUT_FILE_PREFIX + outputPath];
|
|
127172
|
+
mappingWorker.postMessage({
|
|
127173
|
+
response: 'lookupResult',
|
|
127174
|
+
postMappedHash: entry?.postMappedHash,
|
|
127175
|
+
});
|
|
127176
|
+
return;
|
|
127177
|
+
}
|
|
127150
127178
|
// Any message from a worker means progress is being made.
|
|
127151
127179
|
lastWorkerProgressTime = Date.now();
|
|
127152
127180
|
workerCurrentFile.delete(mappingWorker);
|
|
@@ -127218,9 +127246,6 @@
|
|
|
127218
127246
|
return lastWorkerProgressTime;
|
|
127219
127247
|
}
|
|
127220
127248
|
|
|
127221
|
-
// Kept here, because it is also imported from the worker
|
|
127222
|
-
const OUTPUT_FILE_PREFIX = 'output#';
|
|
127223
|
-
|
|
127224
127249
|
function requiresDateOffset(deIdOpts) {
|
|
127225
127250
|
return (deIdOpts !== 'Off' &&
|
|
127226
127251
|
deIdOpts.retainLongitudinalTemporalInformationOptions === 'Offset');
|