Skip to content

Commit f53c09d

Browse files
committed
fix failing tests
1 parent 9a89d0e commit f53c09d

14 files changed

Lines changed: 19 additions & 18 deletions

packages/schema-converter-shex/src/typing/ShexJTypingTransformer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface ShexJTypeTransformerContext {
1414
importIri: string,
1515
) => Promise<[TypeingReturn, ContextDefinition] | undefined>;
1616
refsToImport: Set<string>;
17-
getImportPath: (importIri: string) => string;
17+
getImportPath: (importIri: string) => string | undefined;
1818
}
1919

2020
export function commentFromAnnotations(
@@ -121,8 +121,9 @@ export const ShexJTypingTransformer = ShexJTraverser.createTransformer<
121121
const as = context.getNameFromIri(shapeId); // local rename
122122
const from = context.getImportPath(importIri); // relative import path
123123

124-
// add import to interfaces
125-
interfaces.push(dom.create.importNamed(name, as, from));
124+
if (name && as && from)
125+
// add import to interfaces
126+
interfaces.push(dom.create.importNamed(name, as, from));
126127
}
127128
}
128129
}

packages/schema-converter-shex/src/typing/shexjToTyping.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export async function shexjToTyping(
2424
nameMap,
2525
}: {
2626
imports?: Map<string, Schema>;
27-
getImportPaths: (importIri: string) => { typings: string };
27+
getImportPaths?: (importIri: string) => { typings: string };
2828
nameMap?: Record<string, string>;
29-
},
29+
} = {},
3030
): Promise<[TypeingReturn, ContextDefinition, IriNameMap | undefined]> {
3131
const processedShexj: Schema = (await jsonld2graphobject(
3232
{
@@ -56,7 +56,7 @@ export async function shexjToTyping(
5656
return [importTypings[0], importTypings[1]];
5757
},
5858
refsToImport: jsonLdContextBuilder.refsToImport,
59-
getImportPath: (importIri: string) => getImportPaths(importIri).typings,
59+
getImportPath: (importIri: string) => getImportPaths?.(importIri).typings,
6060
},
6161
);
6262

packages/schema-converter-shex/test/testData/activityPub.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/schema-converter-shex/test/testData/andSimple.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ export const andSimple: TestData = {
6565
},
6666
},
6767
successfulTypings:
68-
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainer {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "MediaContainer";\n }>;\n videoImage: Video & Image;\n}\n\nexport interface Video {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Video";\n }>;\n}\n\nexport interface Image {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Image";\n }>;\n}\n\n',
68+
'import type { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainer {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "MediaContainer";\n }>;\n videoImage: Video & Image;\n}\n\nexport interface Video {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Video";\n }>;\n}\n\nexport interface Image {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Image";\n }>;\n}\n\n',
6969
};

packages/schema-converter-shex/test/testData/circular.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ export const circular: TestData = {
7171
},
7272
},
7373
successfulTypings:
74-
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface Parent {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type?: LdSet<{\n "@id": "Parent";\n }>;\n hasChild: Child;\n}\n\nexport interface Child {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type?: LdSet<{\n "@id": "Child";\n }>;\n hasParent: Parent;\n}\n\n',
74+
'import type { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface Parent {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type?: LdSet<{\n "@id": "Parent";\n }>;\n hasChild: Child;\n}\n\nexport interface Child {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type?: LdSet<{\n "@id": "Child";\n }>;\n hasParent: Parent;\n}\n\n',
7575
};

packages/schema-converter-shex/test/testData/eachOfAndSimple.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ export const eachOfAndSimple: TestData = {
5656
},
5757
},
5858
successfulTypings:
59-
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainer {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "MediaContainer";\n }>;\n}\n\nexport interface Video {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Video";\n }>;\n}\n\nexport interface Image {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Image";\n }>;\n}\n\n',
59+
'import type { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainer {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "MediaContainer";\n }>;\n}\n\nexport interface Video {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Video";\n }>;\n}\n\nexport interface Image {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Image";\n }>;\n}\n\n',
6060
};

packages/schema-converter-shex/test/testData/extendsSimple.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ export const extendsSimple: TestData = {
7979
employeeNumber: "https://example.com/employeeNumber",
8080
},
8181
successfulTypings:
82-
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface Entity {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Entity";\n }>;\n entityId: any;\n}\n\nexport interface Person {\n "@id"?: LdSet<string | string>;\n "@context"?: LdSet<LdoJsonldContext | LdoJsonldContext>;\n type: LdSet<{\n "@id": "Entity";\n } | {\n "@id": "Person";\n }>;\n entityId: any;\n name: any;\n}\n\nexport interface Employee {\n "@id"?: LdSet<string | string | string>;\n "@context"?: LdSet<LdoJsonldContext | LdoJsonldContext | LdoJsonldContext>;\n type: LdSet<{\n "@id": "Entity";\n } | {\n "@id": "Person";\n } | {\n "@id": "Employee";\n }>;\n entityId: any;\n name: any;\n employeeNumber: any;\n}\n\n',
82+
'import type { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface Entity {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Entity";\n }>;\n entityId: any;\n}\n\nexport interface Person {\n "@id"?: LdSet<string | string>;\n "@context"?: LdSet<LdoJsonldContext | LdoJsonldContext>;\n type: LdSet<{\n "@id": "Entity";\n } | {\n "@id": "Person";\n }>;\n entityId: any;\n name: any;\n}\n\nexport interface Employee {\n "@id"?: LdSet<string | string | string>;\n "@context"?: LdSet<LdoJsonldContext | LdoJsonldContext | LdoJsonldContext>;\n type: LdSet<{\n "@id": "Entity";\n } | {\n "@id": "Person";\n } | {\n "@id": "Employee";\n }>;\n entityId: any;\n name: any;\n employeeNumber: any;\n}\n\n',
8383
};

packages/schema-converter-shex/test/testData/multipleSharedPredicates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ export const multipleSharedPredicates: TestData = {
5656
Thing3: "https://example.com/Thing3",
5757
},
5858
successfulTypings:
59-
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainer {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Media";\n } | {\n "@id": "Video";\n }>;\n something: LdSet<{\n "@id": "OtherThing";\n } | {\n "@id": "Thing3";\n }>;\n}\n\n',
59+
'import type { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainer {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Media";\n } | {\n "@id": "Video";\n }>;\n something: LdSet<{\n "@id": "OtherThing";\n } | {\n "@id": "Thing3";\n }>;\n}\n\n',
6060
};

packages/schema-converter-shex/test/testData/oldExtends.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ export const oldExtends: TestData = {
8484
employeeNumber: "https://example.com/employeeNumber",
8585
},
8686
successfulTypings:
87-
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface Entity {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Entity";\n }>;\n entityId: any;\n}\n\nexport interface Person {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Entity";\n } | {\n "@id": "Person";\n }>;\n entityId: any;\n name: any;\n}\n\nexport interface Employee {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Entity";\n } | {\n "@id": "Person";\n } | {\n "@id": "Employee";\n }>;\n entityId: any;\n name: any;\n employeeNumber: any;\n}\n\n',
87+
'import type { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface Entity {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Entity";\n }>;\n entityId: any;\n}\n\nexport interface Person {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Entity";\n } | {\n "@id": "Person";\n }>;\n entityId: any;\n name: any;\n}\n\nexport interface Employee {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Entity";\n } | {\n "@id": "Person";\n } | {\n "@id": "Employee";\n }>;\n entityId: any;\n name: any;\n employeeNumber: any;\n}\n\n',
8888
};

packages/schema-converter-shex/test/testData/orSimple.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,5 @@ export const orSimple: TestData = {
7676
},
7777
},
7878
successfulTypings:
79-
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainer {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "MediaContainer";\n }>;\n primaryMedia: Video | Image;\n media?: LdSet<Video | Image>;\n}\n\nexport interface Video {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Video";\n }>;\n}\n\nexport interface Image {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Image";\n }>;\n}\n\n',
79+
'import type { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainer {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "MediaContainer";\n }>;\n primaryMedia: Video | Image;\n media?: LdSet<Video | Image>;\n}\n\nexport interface Video {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Video";\n }>;\n}\n\nexport interface Image {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Image";\n }>;\n}\n\n',
8080
};

0 commit comments

Comments
 (0)