Skip to content

Commit e69b644

Browse files
committed
feat(DataSource): simplified data structure
DataSource objects now represent a single type, rather than the bag-of-types done originally.
1 parent 382c45e commit e69b644

26 files changed

Lines changed: 356 additions & 526 deletions
Lines changed: 72 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,88 @@
11
import { describe, it } from 'vitest';
22
import { expect } from 'chai';
3-
import { DataSource, serializeDataSource } from '@/src/io/import/dataSource';
3+
import {
4+
getDataSourceName,
5+
isRemoteDataSource,
6+
} from '@/src/io/import/dataSource';
7+
import { Chunk } from '@/src/core/streaming/chunk';
48

5-
describe('serializeDataSource', () => {
6-
it('should remove FileSources', () => {
7-
const input: DataSource = {
8-
fileSrc: {
9-
file: new File([], '1.dcm'),
10-
fileType: 'application/dicom',
11-
},
12-
};
13-
const output = serializeDataSource(input);
9+
describe('isRemoteDatasource', () => {
10+
it('should work', () => {
11+
expect(isRemoteDataSource(undefined)).to.be.false;
1412

15-
expect(output).to.deep.equal({});
16-
});
13+
expect(
14+
isRemoteDataSource({
15+
type: 'file',
16+
file: new File([], 'name'),
17+
fileType: 'type',
18+
})
19+
).to.be.false;
1720

18-
it('should preserve archive status', () => {
19-
const input: DataSource = {
20-
fileSrc: {
21-
file: new File([], '1.dcm'),
22-
fileType: 'application/dicom',
23-
},
24-
archiveSrc: {
25-
path: 'a/b/c',
26-
},
27-
parent: {
28-
fileSrc: {
29-
file: new File([], 'archive.zip'),
30-
fileType: 'application/zip',
21+
expect(
22+
isRemoteDataSource({
23+
type: 'file',
24+
file: new File([], 'name'),
25+
fileType: 'type',
26+
parent: {
27+
type: 'uri',
28+
uri: 'http://',
29+
name: 'name',
3130
},
32-
},
33-
};
34-
const output = serializeDataSource(input);
35-
36-
expect(output).to.deep.equal({
37-
archiveSrc: {
38-
path: 'a/b/c',
39-
},
40-
parent: {},
41-
});
31+
})
32+
).to.be.true;
4233
});
34+
});
4335

44-
it('should preserve UriSource', () => {
45-
const input: DataSource = {
46-
uriSrc: {
47-
uri: 'https://example.com/image.jpg',
48-
name: 'image.jpg',
49-
},
50-
parent: {
51-
uriSrc: {
52-
uri: 's3://example/bucket',
53-
name: '',
54-
},
55-
},
56-
};
57-
const output = serializeDataSource(input);
36+
describe('getDataSourceName', () => {
37+
it('should work', () => {
38+
expect(
39+
getDataSourceName({
40+
type: 'file',
41+
file: new File([], 'name'),
42+
fileType: 'ft',
43+
})
44+
).to.equal('name');
5845

59-
expect(output).to.deep.equal(input);
60-
});
46+
expect(
47+
getDataSourceName({
48+
type: 'uri',
49+
uri: 'http://',
50+
name: 'name',
51+
})
52+
).to.equal('name');
6153

62-
it('should serialize remote archive members', () => {
63-
const input: DataSource = {
64-
fileSrc: {
65-
file: new File([], '1.dcm'),
66-
fileType: 'application/dicom',
67-
},
68-
archiveSrc: {
69-
path: 'a/b/c',
70-
},
71-
parent: {
72-
fileSrc: {
73-
file: new File([], 'archive.zip'),
74-
fileType: 'application/zip',
75-
},
76-
parent: {
77-
uriSrc: {
78-
uri: 'https://example.com/archive.zip',
79-
name: 'archive.zip',
54+
expect(
55+
getDataSourceName({
56+
type: 'collection',
57+
sources: [
58+
{
59+
type: 'file',
60+
file: new File([], 'name'),
61+
fileType: 'ft',
8062
},
81-
},
82-
},
83-
};
84-
const output = serializeDataSource(input);
63+
],
64+
})
65+
).to.equal('name');
8566

86-
expect(output).to.deep.equal({
87-
archiveSrc: {
88-
path: 'a/b/c',
89-
},
90-
parent: {
91-
// empty parent b/c archive FileSource cannot be serialized
67+
expect(
68+
getDataSourceName({
69+
type: 'chunk',
70+
chunk: {} as Chunk,
71+
mime: 'mime',
72+
})
73+
).to.equal(null);
74+
75+
expect(
76+
getDataSourceName({
77+
type: 'chunk',
78+
chunk: {} as Chunk,
79+
mime: 'mime',
9280
parent: {
93-
uriSrc: {
94-
uri: 'https://example.com/archive.zip',
95-
name: 'archive.zip',
96-
},
81+
type: 'file',
82+
file: new File([], 'name'),
83+
fileType: 'ft',
9784
},
98-
},
99-
});
85+
})
86+
).to.equal('name');
10087
});
10188
});

src/io/import/__tests__/importDataSources.spec.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/io/import/common.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ export type ImportHandler = ChainHandler<
121121
ImportContext
122122
>;
123123

124-
export function isArchive(
125-
ds: DataSource
126-
): ds is DataSource & { fileSrc: FileSource } {
127-
return !!ds.fileSrc && ARCHIVE_FILE_TYPES.has(ds.fileSrc.fileType);
124+
export function isArchive(ds: DataSource): ds is FileSource {
125+
return ds.type === 'file' && ARCHIVE_FILE_TYPES.has(ds.fileType);
128126
}
129127

130128
export function isLoadableResult(

0 commit comments

Comments
 (0)