You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

22 lines
785 B

import type { ContextDefinition } from "jsonld";
import type { Schema } from "shexj";
import { JsonLdContextBuilder } from "./JsonLdContextBuilder";
import { ShexJNameVisitor } from "./ShexJContextVisitor";
import { jsonld2graphobject } from "jsonld2graphobject";
export async function shexjToContext(
shexj: Schema,
): Promise<ContextDefinition> {
const processedShexj: Schema = (await jsonld2graphobject(
{
...shexj,
"@id": "SCHEMA",
"@context": "http://www.w3.org/ns/shex.jsonld",
},
"SCHEMA",
{ excludeContext: true },
)) as unknown as Schema;
const jsonLdContextBuilder = new JsonLdContextBuilder();
await ShexJNameVisitor.visit(processedShexj, "Schema", jsonLdContextBuilder);
return jsonLdContextBuilder.generateJsonldContext();
}