Skip to content

Commit

Permalink
Add public interface for conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanschramm committed Dec 19, 2023
1 parent 0b382bf commit fa15c6b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion retroload-lib/src/conversion/ConverterManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {getLocalPathByDirAndFile} from '../Examples.js';
import {BufferAccess} from '../common/BufferAccess.js';
import {type OptionValues} from '../encoding/Options.js';
import {convert} from './ConverterManager.js';
import {convert, getConverters} from './ConverterManager.js';
import * as fs from 'fs';

type TestDefinition = {
Expand Down Expand Up @@ -29,6 +29,10 @@ const formatTests: TestDefinition[] = [
},
];

test('getConverters() returns non empty list', () => {
expect(getConverters().length).toBeGreaterThan(0);
});

describe('Formats are converted correctly', () => {
it.each(formatTests.map((t: TestDefinition) => ({label: getTestLabel(t), definition: t})))(
'$label',
Expand Down
6 changes: 5 additions & 1 deletion retroload-lib/src/conversion/ConverterManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import {type BufferAccess} from '../common/BufferAccess.js';
import {FormatNotFoundError} from '../common/Exceptions.js';
import {OptionContainer, type OptionValues} from '../encoding/Options.js';
import {converters} from './ConverterProvider.js';
import {type ConverterDefinition} from './converter/ConverterDefinition.js';
import {type PublicConverterDefinition, type ConverterDefinition} from './converter/ConverterDefinition.js';

export function getConverters(): PublicConverterDefinition[] {
return converters;
}

export function convert(data: BufferAccess, identifier: string, options: OptionValues): BufferAccess {
const chosenConverters = converters.filter((c: ConverterDefinition) => c.identifier === identifier);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {type BufferAccess} from '../../common/BufferAccess.js';
import {type OptionContainer, type PublicOptionDefinition} from '../../encoding/Options.js';

export type ConverterDefinition = {
export type PublicConverterDefinition = {
readonly name: string;
readonly identifier: string;
readonly options: PublicOptionDefinition[];
};

export type ConverterDefinition = PublicConverterDefinition & {
readonly convert: (ba: BufferAccess, options: OptionContainer) => BufferAccess;
};
1 change: 1 addition & 0 deletions retroload-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export {WaveRecorder} from './encoding/recorder/WaveRecorder.js';
export {Logger} from './common/logging/Logger.js';
export {BufferAccess} from './common/BufferAccess.js';
export * as AdapterManager from './encoding/AdapterManager.js';
export * as ConverterManager from './conversion/ConverterManager.js';
export * as Exception from './common/Exceptions.js';
export * as DecoderManager from './decoding/DecoderManager.js';
export {tokenizers as BasicTokenizers} from './tokenizing/TokenizerProvider.js';
Expand Down

0 comments on commit fa15c6b

Please sign in to comment.