-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DataSource): simplified data structure
DataSource objects now represent a single type, rather than the bag-of-types done originally.
- Loading branch information
Showing
26 changed files
with
356 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,88 @@ | ||
import { describe, it } from 'vitest'; | ||
import { expect } from 'chai'; | ||
import { DataSource, serializeDataSource } from '@/src/io/import/dataSource'; | ||
import { | ||
getDataSourceName, | ||
isRemoteDataSource, | ||
} from '@/src/io/import/dataSource'; | ||
import { Chunk } from '@/src/core/streaming/chunk'; | ||
|
||
describe('serializeDataSource', () => { | ||
it('should remove FileSources', () => { | ||
const input: DataSource = { | ||
fileSrc: { | ||
file: new File([], '1.dcm'), | ||
fileType: 'application/dicom', | ||
}, | ||
}; | ||
const output = serializeDataSource(input); | ||
describe('isRemoteDatasource', () => { | ||
it('should work', () => { | ||
expect(isRemoteDataSource(undefined)).to.be.false; | ||
|
||
expect(output).to.deep.equal({}); | ||
}); | ||
expect( | ||
isRemoteDataSource({ | ||
type: 'file', | ||
file: new File([], 'name'), | ||
fileType: 'type', | ||
}) | ||
).to.be.false; | ||
|
||
it('should preserve archive status', () => { | ||
const input: DataSource = { | ||
fileSrc: { | ||
file: new File([], '1.dcm'), | ||
fileType: 'application/dicom', | ||
}, | ||
archiveSrc: { | ||
path: 'a/b/c', | ||
}, | ||
parent: { | ||
fileSrc: { | ||
file: new File([], 'archive.zip'), | ||
fileType: 'application/zip', | ||
expect( | ||
isRemoteDataSource({ | ||
type: 'file', | ||
file: new File([], 'name'), | ||
fileType: 'type', | ||
parent: { | ||
type: 'uri', | ||
uri: 'http://', | ||
name: 'name', | ||
}, | ||
}, | ||
}; | ||
const output = serializeDataSource(input); | ||
|
||
expect(output).to.deep.equal({ | ||
archiveSrc: { | ||
path: 'a/b/c', | ||
}, | ||
parent: {}, | ||
}); | ||
}) | ||
).to.be.true; | ||
}); | ||
}); | ||
|
||
it('should preserve UriSource', () => { | ||
const input: DataSource = { | ||
uriSrc: { | ||
uri: 'https://example.com/image.jpg', | ||
name: 'image.jpg', | ||
}, | ||
parent: { | ||
uriSrc: { | ||
uri: 's3://example/bucket', | ||
name: '', | ||
}, | ||
}, | ||
}; | ||
const output = serializeDataSource(input); | ||
describe('getDataSourceName', () => { | ||
it('should work', () => { | ||
expect( | ||
getDataSourceName({ | ||
type: 'file', | ||
file: new File([], 'name'), | ||
fileType: 'ft', | ||
}) | ||
).to.equal('name'); | ||
|
||
expect(output).to.deep.equal(input); | ||
}); | ||
expect( | ||
getDataSourceName({ | ||
type: 'uri', | ||
uri: 'http://', | ||
name: 'name', | ||
}) | ||
).to.equal('name'); | ||
|
||
it('should serialize remote archive members', () => { | ||
const input: DataSource = { | ||
fileSrc: { | ||
file: new File([], '1.dcm'), | ||
fileType: 'application/dicom', | ||
}, | ||
archiveSrc: { | ||
path: 'a/b/c', | ||
}, | ||
parent: { | ||
fileSrc: { | ||
file: new File([], 'archive.zip'), | ||
fileType: 'application/zip', | ||
}, | ||
parent: { | ||
uriSrc: { | ||
uri: 'https://example.com/archive.zip', | ||
name: 'archive.zip', | ||
expect( | ||
getDataSourceName({ | ||
type: 'collection', | ||
sources: [ | ||
{ | ||
type: 'file', | ||
file: new File([], 'name'), | ||
fileType: 'ft', | ||
}, | ||
}, | ||
}, | ||
}; | ||
const output = serializeDataSource(input); | ||
], | ||
}) | ||
).to.equal('name'); | ||
|
||
expect(output).to.deep.equal({ | ||
archiveSrc: { | ||
path: 'a/b/c', | ||
}, | ||
parent: { | ||
// empty parent b/c archive FileSource cannot be serialized | ||
expect( | ||
getDataSourceName({ | ||
type: 'chunk', | ||
chunk: {} as Chunk, | ||
mime: 'mime', | ||
}) | ||
).to.equal(null); | ||
|
||
expect( | ||
getDataSourceName({ | ||
type: 'chunk', | ||
chunk: {} as Chunk, | ||
mime: 'mime', | ||
parent: { | ||
uriSrc: { | ||
uri: 'https://example.com/archive.zip', | ||
name: 'archive.zip', | ||
}, | ||
type: 'file', | ||
file: new File([], 'name'), | ||
fileType: 'ft', | ||
}, | ||
}, | ||
}); | ||
}) | ||
).to.equal('name'); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.