Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions packages/sparql-qlever/src/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import { basename, dirname } from 'path';
import { writeFile } from 'node:fs/promises';
import { TaskRunner } from '@lde/task-runner';

type fileFormat = 'nt' | 'nq' | 'ttl';

const supportedFormats = new Map<string, fileFormat>([
['application/n-triples', 'nt'],
['application/n-quads', 'nq'],
['text/turtle', 'ttl'],
]);

export interface Options {
taskRunner: TaskRunner<unknown>;
indexName?: string;
Expand Down Expand Up @@ -52,7 +60,8 @@ export class Importer implements ImporterInterface {
.getDownloadDistributions()
.filter(
(distribution): distribution is Distribution & { mimeType: string } =>
distribution.mimeType !== undefined,
distribution.mimeType !== undefined &&
supportedFormats.has(distribution.mimeType),
);
if (downloadDistributions.length === 0) {
return new NotSupported();
Expand Down Expand Up @@ -92,16 +101,11 @@ export class Importer implements ImporterInterface {
}

private fileFormatFromMimeType(mimeType: string): fileFormat {
switch (mimeType) {
case 'application/n-triples':
return 'nt';
case 'application/n-quads':
return 'nq';
case 'text/turtle':
return 'ttl';
default:
throw new Error(`Unsupported media type: ${mimeType}`);
const format = supportedFormats.get(mimeType);
if (format === undefined) {
throw new Error(`Unsupported media type: ${mimeType}`);
}
return format;
}

private async index(file: string, format: fileFormat): Promise<void> {
Expand All @@ -127,5 +131,3 @@ export class Importer implements ImporterInterface {
await this.taskRunner.wait(indexTask);
}
}

type fileFormat = 'nt' | 'nq' | 'ttl';
8 changes: 4 additions & 4 deletions packages/sparql-qlever/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default mergeConfig(
},
coverage: {
thresholds: {
lines: 78.04,
lines: 82.92,
functions: 100,
branches: 45.45,
statements: 78.04,
branches: 54.54,
statements: 82.92,
},
},
},
})
}),
);