diff --git a/packages/jsonld-dataset-proxy/src/ContextUtil.ts b/packages/jsonld-dataset-proxy/src/ContextUtil.ts index 887f7cf..a26e5bc 100644 --- a/packages/jsonld-dataset-proxy/src/ContextUtil.ts +++ b/packages/jsonld-dataset-proxy/src/ContextUtil.ts @@ -1,4 +1,5 @@ import type { ContextDefinition, ExpandedTermDefinition } from "jsonld"; +import type { LdoJsonldContext } from "./LdoJsonldContext"; // Create JSONLD Shorthands const shorthandToIriMap: Record = { @@ -10,10 +11,10 @@ const shorthandToIriMap: Record = { * Handles the JSON-LD context and allows conversion between IRIs and terms */ export class ContextUtil { - public readonly context: ContextDefinition; + public readonly context: ContextDefinition | LdoJsonldContext; private iriToKeyMap: Record; - constructor(context: ContextDefinition) { + constructor(context: ContextDefinition | LdoJsonldContext) { this.context = context; this.iriToKeyMap = {}; Object.entries(context).forEach(([contextKey, contextValue]) => { diff --git a/packages/jsonld-dataset-proxy/src/LdoJsonldContext.ts b/packages/jsonld-dataset-proxy/src/LdoJsonldContext.ts index 75ce20f..089ebb9 100644 --- a/packages/jsonld-dataset-proxy/src/LdoJsonldContext.ts +++ b/packages/jsonld-dataset-proxy/src/LdoJsonldContext.ts @@ -9,6 +9,6 @@ export interface LdoJsonldContext extends ContextDefinition { } export type LdoJsonldContextExpandedTermDefinition = ExpandedTermDefinition & { - "@isCollection": boolean; - "@isOptional": boolean; + "@context"?: LdoJsonldContext | undefined; + "@isCollection"?: boolean | undefined; }; diff --git a/packages/jsonld-dataset-proxy/src/jsonldDatasetProxy.ts b/packages/jsonld-dataset-proxy/src/jsonldDatasetProxy.ts index 9c49be3..e161dd0 100644 --- a/packages/jsonld-dataset-proxy/src/jsonldDatasetProxy.ts +++ b/packages/jsonld-dataset-proxy/src/jsonldDatasetProxy.ts @@ -4,6 +4,7 @@ import type { ContextDefinition } from "jsonld"; import { ContextUtil } from "./ContextUtil"; import { JsonldDatasetProxyBuilder } from "./JsonldDatasetProxyBuilder"; import { ProxyContext } from "./ProxyContext"; +import type { LdoJsonldContext } from "./LdoJsonldContext"; /** * Creates a JSON-LD Dataset Proxy @@ -14,7 +15,7 @@ import { ProxyContext } from "./ProxyContext"; */ export function jsonldDatasetProxy( inputDataset: Dataset, - context: ContextDefinition, + context: ContextDefinition | LdoJsonldContext, ): JsonldDatasetProxyBuilder { const contextUtil = new ContextUtil(context); const proxyContext = new ProxyContext({ diff --git a/packages/jsonld-dataset-proxy/test/scopedExampleData.ts b/packages/jsonld-dataset-proxy/test/scopedExampleData.ts index 57e718c..db4f1c7 100644 --- a/packages/jsonld-dataset-proxy/test/scopedExampleData.ts +++ b/packages/jsonld-dataset-proxy/test/scopedExampleData.ts @@ -39,11 +39,6 @@ export type Element = "@id": "CreativeWork"; }; -// No need to fully define the schema because this library doesn't use it -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore -export const patientSchema: Schema = {}; - export const patientContext: LdoJsonldContext = { Bender: { "@id": "https://example.com/Bender", @@ -56,46 +51,37 @@ export const patientContext: LdoJsonldContext = { }, friend: { "@id": "https://example.com/friend", - } + "@isCollection": true, + }, }, }, - - Patient: "http://hl7.org/fhir/Patient", - subject: { "@id": "http://hl7.org/fhir/subject", "@type": "@id" }, - name: { - "@id": "http://hl7.org/fhir/name", - "@type": "http://www.w3.org/2001/XMLSchema#string", - "@container": "@set", - }, - langName: { - "@id": "http://hl7.org/fhir/langName", - "@type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", - "@container": "@set", - }, - birthdate: { - "@id": "http://hl7.org/fhir/birthdate", - "@type": "http://www.w3.org/2001/XMLSchema#date", - }, - age: { - "@id": "http://hl7.org/fhir/age", - "@type": "http://www.w3.org/2001/XMLSchema#integer", - }, - isHappy: { - "@id": "http://hl7.org/fhir/isHappy", - "@type": "http://www.w3.org/2001/XMLSchema#boolean", - }, - roommate: { - "@id": "http://hl7.org/fhir/roommate", - "@type": "@id", - "@container": "@set", - }, - notes: { - "@id": "http://hl7.org/fhir/notes", - "@type": "http://www.w3.org/2001/XMLSchema#string", + Avatar: { + "@id": "https://example.com/Bender", + "@context": { + type: { + "@id": "@type", + }, + element: { + "@id": "https://example.com/element", + "@isCollection": true, + }, + friend: { + "@id": "https://example.com/friend", + "@isCollection": true, + }, + }, }, - langNotes: { - "@id": "http://hl7.org/fhir/langNotes", - "@type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", + NonBender: { + "@id": "https://example.com/NonBender", + "@context": { + type: { + "@id": "@type", + }, + friend: { + "@id": "https://example.com/friend", + "@isCollection": true, + }, + }, }, }; @@ -105,32 +91,17 @@ export const patientData = ` @prefix xsd: . @prefix rdf: . -example:Observation1 - fhir:notes "Cool Notes"^^xsd:string ; - fhir:subject example:Patient1 . +example:Aang a example:Avatar + example:element example:Air, example:Water ; + example:friend example:Sokka, example:Katara . -example:Patient1 - rdf:type fhir:Patient ; - fhir:name "Garrett"^^xsd:string, "Bobby"^^xsd:string, "Ferguson"^^xsd:string ; - fhir:birthdate "1986-01-01"^^xsd:date ; - fhir:age "35"^^xsd:integer ; - fhir:isHappy "true"^^xsd:boolean ; - fhir:roommate example:Patient2, example:Patient3 . +example:Katara a example:Avatar + example:element example:Water ; + example:friend example:Sokka, example:Aang . -example:Patient2 - rdf:type fhir:Patient ; - fhir:name "Rob"^^xsd:string ; - fhir:birthdate "1987-01-01"^^xsd:date ; - fhir:age "34"^^xsd:integer ; - fhir:isHappy "false"^^xsd:boolean ; - fhir:roommate example:Patient1, example:Patient3 . - -example:Patient3 - rdf:type fhir:Patient ; - fhir:name "Amy"^^xsd:string ; - fhir:birthdate "1988-01-01"^^xsd:date ; - fhir:age "33"^^xsd:integer ; - fhir:isHappy "true"^^xsd:boolean . +example:Sokka a example:Avatar + example:element example:Water ; + example:friend example:Sokka, example:Aang . `; export const patientDataWithBlankNodes = `