diff --git a/packages/schema-converter-shex/src/context/JsonLdContextBuilder.ts b/packages/schema-converter-shex/src/context/JsonLdContextBuilder.ts index e61ffdf..bd99c0d 100644 --- a/packages/schema-converter-shex/src/context/JsonLdContextBuilder.ts +++ b/packages/schema-converter-shex/src/context/JsonLdContextBuilder.ts @@ -9,12 +9,14 @@ import { hashValueSetValue } from "./util/hashValueSetValue.js"; export function iriToName(iri: string): string { try { const url = new URL(iri); + let name: string if (url.hash) { - return url.hash.slice(1); + name = url.hash.slice(1); } else { const splitPathname = url.pathname.split("/"); - return splitPathname[splitPathname.length - 1]; + name = splitPathname[splitPathname.length - 1]; } + return name.replace(/(?;\n videoImage: VideoShape & ImageShape;\n}\n\nexport interface VideoShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Video";\n }>;\n}\n\nexport interface ImageShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Image";\n }>;\n}\n\n', + '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', }; diff --git a/packages/schema-converter-shex/test/testData/circular.ts b/packages/schema-converter-shex/test/testData/circular.ts index 8612d57..886bea5 100644 --- a/packages/schema-converter-shex/test/testData/circular.ts +++ b/packages/schema-converter-shex/test/testData/circular.ts @@ -71,5 +71,5 @@ export const circular: TestData = { }, }, successfulTypings: - 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface ParentShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type?: LdSet<{\n "@id": "Parent";\n }>;\n hasChild: ChildShape;\n}\n\nexport interface ChildShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type?: LdSet<{\n "@id": "Child";\n }>;\n hasParent: ParentShape;\n}\n\n', + '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', }; diff --git a/packages/schema-converter-shex/test/testData/eachOfAndSimple.ts b/packages/schema-converter-shex/test/testData/eachOfAndSimple.ts index ed192df..d4983dc 100644 --- a/packages/schema-converter-shex/test/testData/eachOfAndSimple.ts +++ b/packages/schema-converter-shex/test/testData/eachOfAndSimple.ts @@ -56,5 +56,5 @@ export const eachOfAndSimple: TestData = { }, }, successfulTypings: - 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainerShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "MediaContainer";\n }>;\n}\n\nexport interface VideoShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Video";\n }>;\n}\n\nexport interface ImageShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Image";\n }>;\n}\n\n', + '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', }; diff --git a/packages/schema-converter-shex/test/testData/extendsSimple.ts b/packages/schema-converter-shex/test/testData/extendsSimple.ts index bc0ae4f..b391d00 100644 --- a/packages/schema-converter-shex/test/testData/extendsSimple.ts +++ b/packages/schema-converter-shex/test/testData/extendsSimple.ts @@ -79,5 +79,5 @@ export const extendsSimple: TestData = { employeeNumber: "https://example.com/employeeNumber", }, successfulTypings: - 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface EntityShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Entity";\n }>;\n entityId: any;\n}\n\nexport interface PersonShape {\n "@id"?: LdSet;\n "@context"?: LdSet;\n type: LdSet<{\n "@id": "Entity";\n } | {\n "@id": "Person";\n }>;\n entityId: any;\n name: any;\n}\n\nexport interface EmployeeShape {\n "@id"?: LdSet;\n "@context"?: LdSet;\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', + '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;\n "@context"?: LdSet;\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;\n "@context"?: LdSet;\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', }; diff --git a/packages/schema-converter-shex/test/testData/multipleSharedPredicates.ts b/packages/schema-converter-shex/test/testData/multipleSharedPredicates.ts index f9245fe..ebb1c5a 100644 --- a/packages/schema-converter-shex/test/testData/multipleSharedPredicates.ts +++ b/packages/schema-converter-shex/test/testData/multipleSharedPredicates.ts @@ -56,5 +56,5 @@ export const multipleSharedPredicates: TestData = { Thing3: "https://example.com/Thing3", }, successfulTypings: - 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainerShape {\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', + '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', }; diff --git a/packages/schema-converter-shex/test/testData/oldExtends.ts b/packages/schema-converter-shex/test/testData/oldExtends.ts index 5aeebff..08bd89b 100644 --- a/packages/schema-converter-shex/test/testData/oldExtends.ts +++ b/packages/schema-converter-shex/test/testData/oldExtends.ts @@ -84,5 +84,5 @@ export const oldExtends: TestData = { employeeNumber: "https://example.com/employeeNumber", }, successfulTypings: - 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface EntityShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Entity";\n }>;\n entityId: any;\n}\n\nexport interface PersonShape {\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 EmployeeShape {\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', + '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', }; diff --git a/packages/schema-converter-shex/test/testData/orSimple.ts b/packages/schema-converter-shex/test/testData/orSimple.ts index 9f9613e..55dadcf 100644 --- a/packages/schema-converter-shex/test/testData/orSimple.ts +++ b/packages/schema-converter-shex/test/testData/orSimple.ts @@ -76,5 +76,5 @@ export const orSimple: TestData = { }, }, successfulTypings: - 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainerShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "MediaContainer";\n }>;\n primaryMedia: VideoShape | ImageShape;\n media?: LdSet;\n}\n\nexport interface VideoShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Video";\n }>;\n}\n\nexport interface ImageShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Image";\n }>;\n}\n\n', + '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