Skip to content

Commit

Permalink
Add type annotations to TS import/export methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaehring committed Oct 30, 2024
1 parent 2c8507a commit 24251d5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"devDependencies": {
"@types/jsonld": "^1.5.7",
"@types/node": "^22.7.6",
"@types/rdf-ext": "^2.5.0",
"@types/rdfjs__serializer-jsonld-ext": "^2.0.5",
"typescript": "^4.5"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Semanticable } from "@virtual-assembly/semantizer";
import SerializerJsonld from '@rdfjs/serializer-jsonld-ext';
import { ContextDefinition } from "jsonld";
import Quad from "rdf-ext/lib/Quad";
import { ContextDefinition, ExpandedTermDefinition } from "jsonld";
import { Readable } from 'readable-stream';

import IConnectorExporter from "./IConnectorExporter";
Expand All @@ -24,16 +25,16 @@ export default class ConnectorExporterJsonldStream implements IConnectorExporter
const input = new Readable({
objectMode: true,
read: () => {
semanticObjets.forEach((semanticObject) => semanticObject.toRdfDatasetExt().forEach((quad) => input.push(quad)));
semanticObjets.forEach((semanticObject) => semanticObject.toRdfDatasetExt().forEach((quad: Quad) => input.push(quad)));
input.push(null)
}
});

const output = serializer.import(input);

return new Promise<string>((resolve, reject) => {
output.on('error', (error) => reject(error));
output.on('data', (json) => {
output.on('error', (error: Error) => reject(error));
output.on('data', (json: ExpandedTermDefinition) => {
if (outputContext) {
json["@context"] = outputContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class ConnectorImporterJsonldStream implements IConnectorImporter
// On each quad imported we fill the appropriate datasets.
// If the quad is a blank node we add it to the blankNodes array,
// otherwise we add it to the datasets array.
output.on('data', (quad) => {
output.on('data', (quad: QuadExt) => {
const subject: string = quad.subject.value;
const isBlankNode: boolean = (quad.subject.termType === "BlankNode");

Expand Down Expand Up @@ -82,7 +82,7 @@ export default class ConnectorImporterJsonldStream implements IConnectorImporter

return new Promise((resolve, reject) => {
// If an error occured during the import process, we reject the promise.
output.on('error', (error) => reject(error));
output.on('error', (error: Error) => reject(error));

// When the import is done without any error.
output.on('finish', () => {
Expand All @@ -93,7 +93,7 @@ export default class ConnectorImporterJsonldStream implements IConnectorImporter

// We should find a blank node index associated to the blank node name.
if (blankNodeIndex !== undefined) {
const blankNodeDataset: DatasetExt | undefined = blankNodes.at(blankNodeIndex);
const blankNodeDataset: DatasetExt | undefined = blankNodes.at(blankNodeIndex); // FIXME: requires tsconfig target >= es2022

// When we find the blank node we add its quads to the corresponding dataset.
if (blankNodeDataset) dataset.addAll(blankNodeDataset);
Expand Down

0 comments on commit 24251d5

Please sign in to comment.