Updated shex builder to handle multiple cardinality and type is always a multi cardinality

main
Jackson Morgan 2 months ago
parent 45452a32a0
commit 74e527f998
  1. 9
      packages/connected-solid/src/resources/SolidResource.ts
  2. 39
      packages/schema-converter-shex/src/context/JsonLdContextBuilder.ts
  3. 9
      packages/schema-converter-shex/src/context/ShexJContextVisitor.ts
  4. 27
      packages/schema-converter-shex/src/context/util/hashValueSetValue.ts
  5. 4
      packages/schema-converter-shex/src/typing/ShexJTypingTransformer.ts
  6. 48
      packages/schema-converter-shex/src/util/getRdfTypesForTripleConstraint.ts
  7. 58
      packages/schema-converter-shex/test/testData/activityPub.ts
  8. 24
      packages/schema-converter-shex/test/testData/andSimple.ts
  9. 5
      packages/schema-converter-shex/test/testData/circular.ts
  10. 30
      packages/schema-converter-shex/test/testData/eachOfAndSimple.ts
  11. 6
      packages/schema-converter-shex/test/testData/extendsSimple.ts
  12. 60
      packages/schema-converter-shex/test/testData/multipleSharedPredicates.ts
  13. 6
      packages/schema-converter-shex/test/testData/oldExtends.ts
  14. 24
      packages/schema-converter-shex/test/testData/orSimple.ts
  15. 16
      packages/schema-converter-shex/test/testData/profile.ts
  16. 16
      packages/schema-converter-shex/test/testData/reducedProfile.ts
  17. 7
      packages/schema-converter-shex/test/testData/reusedPredicates.ts
  18. 2
      packages/schema-converter-shex/test/testData/testData.ts

@ -39,10 +39,8 @@ import type { NoRootContainerError } from "../requester/results/error/NoRootCont
import type { SolidLeaf } from "./SolidLeaf.js"; import type { SolidLeaf } from "./SolidLeaf.js";
import type { GetWacUriError } from "../wac/getWacUri.js"; import type { GetWacUriError } from "../wac/getWacUri.js";
import { getWacUri, type GetWacUriResult } from "../wac/getWacUri.js"; import { getWacUri, type GetWacUriResult } from "../wac/getWacUri.js";
import { import type { GetWacRuleError } from "../wac/getWacRule.js";
getWacRuleWithAclUri, import { getWacRuleWithAclUri } from "../wac/getWacRule.js";
type GetWacRuleResult,
} from "../wac/getWacRule.js";
import type { SetWacRuleResult } from "../wac/setWacRule.js"; import type { SetWacRuleResult } from "../wac/setWacRule.js";
import { setWacRuleForAclUri } from "../wac/setWacRule.js"; import { setWacRuleForAclUri } from "../wac/setWacRule.js";
import { NoncompliantPodError } from "../requester/results/error/NoncompliantPodError.js"; import { NoncompliantPodError } from "../requester/results/error/NoncompliantPodError.js";
@ -664,7 +662,8 @@ export abstract class SolidResource
ignoreCache: boolean; ignoreCache: boolean;
}): Promise< }): Promise<
| GetWacUriError<SolidContainer | SolidLeaf> | GetWacUriError<SolidContainer | SolidLeaf>
| GetWacRuleResult<SolidContainer | SolidLeaf> | GetWacRuleError<SolidContainer | SolidLeaf>
| GetWacRuleSuccess<SolidContainer | SolidLeaf>
> { > {
const thisAsLeafOrContainer = this as unknown as SolidLeaf | SolidContainer; const thisAsLeafOrContainer = this as unknown as SolidLeaf | SolidContainer;
// Return the wac rule if it's already cached // Return the wac rule if it's already cached

@ -1,6 +1,7 @@
import type { Annotation } from "shexj"; import type { Annotation, valueSetValue } from "shexj";
import type { ExpandedTermDefinition } from "jsonld"; import type { ExpandedTermDefinition } from "jsonld";
import type { LdoJsonldContext } from "@ldo/jsonld-dataset-proxy"; import type { LdoJsonldContext } from "@ldo/jsonld-dataset-proxy";
import { hashValueSetValue } from "./util/hashValueSetValue";
/** /**
* Name functions * Name functions
@ -59,7 +60,7 @@ export function isJsonLdContextBuilder(
*/ */
export class JsonLdContextBuilder { export class JsonLdContextBuilder {
protected iriAnnotations: Record<string, Annotation[]> = {}; protected iriAnnotations: Record<string, Annotation[]> = {};
protected iriTypes: Record< public iriTypes: Record<
string, string,
ExpandedTermDefinition | JsonLdContextBuilder ExpandedTermDefinition | JsonLdContextBuilder
> = {}; > = {};
@ -99,21 +100,50 @@ export class JsonLdContextBuilder {
isContainer: boolean, isContainer: boolean,
rdfType?: string, rdfType?: string,
annotations?: Annotation[], annotations?: Annotation[],
associatedValues?: valueSetValue[],
) { ) {
const relevantBuilders = this.getRelevantBuilders(rdfType); const relevantBuilders = this.getRelevantBuilders(rdfType);
relevantBuilders.forEach((relevantBuilder) => { relevantBuilders.forEach((relevantBuilder) => {
relevantBuilder.addSubject(iri, undefined, annotations); relevantBuilder.addSubject(iri, undefined, annotations);
// If there are multiple associated
const associatedValuesSet = new Set(
associatedValues?.map((val) => hashValueSetValue(val)),
);
if (!relevantBuilder.iriTypes[iri]) { if (!relevantBuilder.iriTypes[iri]) {
relevantBuilder.iriTypes[iri] = expandedTermDefinition; relevantBuilder.iriTypes[iri] = { ...expandedTermDefinition };
if (isContainer) { if (
isContainer ||
associatedValuesSet.size > 1 ||
iri === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
) {
relevantBuilder.iriTypes[iri]["@isCollection"] = true; relevantBuilder.iriTypes[iri]["@isCollection"] = true;
} }
if (associatedValuesSet.size > 0) {
relevantBuilder.iriTypes[iri]["@associatedValues"] =
associatedValuesSet;
}
} else { } else {
const curDef = relevantBuilder.iriTypes[iri]; const curDef = relevantBuilder.iriTypes[iri];
const newDef = expandedTermDefinition; const newDef = expandedTermDefinition;
if (isContainer) { if (isContainer) {
curDef["@isCollection"] = true; curDef["@isCollection"] = true;
} }
// If there's a different associated value, it must be a collection because you can have multiple types
if (associatedValuesSet.size > 0) {
if (associatedValuesSet.size > 1) {
relevantBuilder.iriTypes[iri]["@isCollection"] = true;
}
const oldAssociatedValueSetSize = curDef["@associatedValues"].size;
associatedValuesSet.forEach((val) =>
curDef["@associatedValues"].add(val),
);
if (curDef["@associatedValues"].size !== oldAssociatedValueSetSize) {
curDef["@isCollection"] = true;
}
}
// If the old and new versions both have types // If the old and new versions both have types
if (curDef["@type"] && newDef["@type"]) { if (curDef["@type"] && newDef["@type"]) {
if (curDef["@type"] !== newDef["@type"]) { if (curDef["@type"] !== newDef["@type"]) {
@ -203,6 +233,7 @@ export class JsonLdContextBuilder {
...this.iriTypes[iri], ...this.iriTypes[iri],
}; };
} }
delete subContext["@associatedValues"];
contextDefnition[name] = subContext; contextDefnition[name] = subContext;
} else { } else {

@ -45,6 +45,15 @@ export const ShexJNameVisitor =
rdfType, rdfType,
tripleConstraint.annotations, tripleConstraint.annotations,
); );
} else if (tripleConstraint.valueExpr.values) {
context.addPredicate(
tripleConstraint.predicate,
{},
isContainer,
rdfType,
tripleConstraint.annotations,
tripleConstraint.valueExpr.values,
);
} else { } else {
context.addPredicate( context.addPredicate(
tripleConstraint.predicate, tripleConstraint.predicate,

@ -0,0 +1,27 @@
import type { ObjectLiteral, valueSetValue } from "shexj";
export function hashValueSetValue(vsv: valueSetValue) {
if (typeof vsv === "string") return `string|${vsv}`;
const vsvol = vsv as ObjectLiteral;
if (vsvol.value) return `objectLiteral|${vsvol.value}|${vsvol.language}`;
const vsvnol = vsv as Exclude<valueSetValue, ObjectLiteral | string>;
switch (vsvnol.type) {
case "IriStem":
return `IriStem|${vsvnol.stem}`;
case "IriStemRange":
return `IriStemRange|${vsvnol.stem}|${vsvnol.exclusions}`;
case "LiteralStem":
return `LiteralStem|${vsvnol.stem}`;
case "LiteralStemRange":
return `LiteralStemRange|${vsvnol.stem}|${vsvnol.exclusions}`;
case "Language":
return `Language|${vsvnol.languageTag}`;
case "LanguageStem":
return `LanguageStem|${vsvnol.stem}`;
case "LanguageStemRange":
return `LanguageStemRange|${vsvnol.stem}|${vsvnol.exclusions}`;
}
}

@ -223,7 +223,9 @@ export const ShexJTypingTransformer = ShexJTraverser.createTransformer<
rdfTypes[0], rdfTypes[0],
); );
const isSet = const isSet =
tripleConstraint.max !== undefined && tripleConstraint.max !== 1; (tripleConstraint.max !== undefined && tripleConstraint.max !== 1) ||
tripleConstraint.predicate ===
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
const isOptional = tripleConstraint.min === 0; const isOptional = tripleConstraint.min === 0;
let type: dom.Type = dom.type.any; let type: dom.Type = dom.type.any;
if (transformedChildren.valueExpr) { if (transformedChildren.valueExpr) {

@ -1,6 +1,29 @@
import type { ShexJTraverserTypes } from "@ldo/traverser-shexj"; import type {
ShexJTraverserTypes,
tripleExprOrRef,
} from "@ldo/traverser-shexj";
import type { InterfaceInstanceNode } from "@ldo/type-traverser"; import type { InterfaceInstanceNode } from "@ldo/type-traverser";
function addRdfTypeFromTripleExpr(
tripleExpr: tripleExprOrRef,
rdfTypeSet: Set<string>,
) {
if (
typeof tripleExpr === "object" &&
tripleExpr.type === "TripleConstraint" &&
tripleExpr.predicate ===
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type" &&
typeof tripleExpr.valueExpr === "object" &&
tripleExpr.valueExpr.type === "NodeConstraint" &&
tripleExpr.valueExpr.values
) {
tripleExpr.valueExpr.values.forEach((val) => {
if (typeof val === "string") rdfTypeSet.add(val);
// TODO handle other edge cases like IRIStem
});
}
}
function recursivelyGatherTypesFromShapeNodes( function recursivelyGatherTypesFromShapeNodes(
shapeNode: InterfaceInstanceNode< shapeNode: InterfaceInstanceNode<
ShexJTraverserTypes, ShexJTraverserTypes,
@ -9,6 +32,9 @@ function recursivelyGatherTypesFromShapeNodes(
>, >,
rdfTypeSet: Set<string>, rdfTypeSet: Set<string>,
): void { ): void {
const tripleExpr = shapeNode.instance.expression;
if (tripleExpr) addRdfTypeFromTripleExpr(tripleExpr, rdfTypeSet);
shapeNode.parent("shapeExpr").forEach((parentShapeExpr) => { shapeNode.parent("shapeExpr").forEach((parentShapeExpr) => {
parentShapeExpr parentShapeExpr
.parent("ShapeDecl", "shapeExpr") .parent("ShapeDecl", "shapeExpr")
@ -52,20 +78,7 @@ function recursivelyGatherTypesFromEachOfNodes(
): void { ): void {
const tripleExprs = eachOfNode.instance.expressions; const tripleExprs = eachOfNode.instance.expressions;
tripleExprs.forEach((tripleExpr) => { tripleExprs.forEach((tripleExpr) => {
if ( addRdfTypeFromTripleExpr(tripleExpr, rdfTypeSet);
typeof tripleExpr === "object" &&
tripleExpr.type === "TripleConstraint" &&
tripleExpr.predicate ===
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type" &&
typeof tripleExpr.valueExpr === "object" &&
tripleExpr.valueExpr.type === "NodeConstraint" &&
tripleExpr.valueExpr.values
) {
tripleExpr.valueExpr.values.forEach((val) => {
if (typeof val === "string") rdfTypeSet.add(val);
// TODO handle other edge cases like IRIStem
});
}
}); });
eachOfNode.parent("tripleExpr").forEach((tripleExprNode) => { eachOfNode.parent("tripleExpr").forEach((tripleExprNode) => {
@ -103,6 +116,11 @@ export function getRdfTypesForTripleConstraint(
.forEach((eachOfParent) => { .forEach((eachOfParent) => {
recursivelyGatherTypesFromEachOfNodes(eachOfParent, rdfTypeSet); recursivelyGatherTypesFromEachOfNodes(eachOfParent, rdfTypeSet);
}); });
tripleExprOrRefParent
.parent("Shape", "expression")
.forEach((shapeParent) => {
recursivelyGatherTypesFromShapeNodes(shapeParent, rdfTypeSet);
});
}); });
}); });
const rdfTypes = rdfTypeSet.size > 0 ? Array.from(rdfTypeSet) : [undefined]; const rdfTypes = rdfTypeSet.size > 0 ? Array.from(rdfTypeSet) : [undefined];

File diff suppressed because one or more lines are too long

@ -26,12 +26,14 @@ export const andSimple: TestData = {
successfulContext: { successfulContext: {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
MediaContainer: { MediaContainer: {
"@id": "https://example.com/MediaContainer", "@id": "https://example.com/MediaContainer",
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
videoImage: { videoImage: {
"@id": "https://example.com/videoImage", "@id": "https://example.com/videoImage",
@ -43,9 +45,25 @@ export const andSimple: TestData = {
"@id": "https://example.com/videoImage", "@id": "https://example.com/videoImage",
"@type": "@id", "@type": "@id",
}, },
Video: "https://example.com/Video", Video: {
Image: "https://example.com/Image", "@id": "https://example.com/Video",
"@context": {
type: {
"@id": "@type",
"@isCollection": true,
},
},
},
Image: {
"@id": "https://example.com/Image",
"@context": {
type: {
"@id": "@type",
"@isCollection": true,
},
},
},
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainerShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "MediaContainer";\n };\n videoImage: VideoShape & ImageShape;\n}\n\nexport interface VideoShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "Video";\n };\n}\n\nexport interface ImageShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "Image";\n };\n}\n\n', 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainerShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "MediaContainer";\n }>;\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',
}; };

@ -33,12 +33,14 @@ export const circular: TestData = {
successfulContext: { successfulContext: {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
Parent: { Parent: {
"@id": "http://example.com/Parent", "@id": "http://example.com/Parent",
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
hasChild: { hasChild: {
"@id": "http://example.com/hasChild", "@id": "http://example.com/hasChild",
@ -55,6 +57,7 @@ export const circular: TestData = {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
hasParent: { hasParent: {
"@id": "http://example.com/hasParent", "@id": "http://example.com/hasParent",
@ -68,5 +71,5 @@ export const circular: TestData = {
}, },
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface ParentShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type?: {\n "@id": "Parent";\n };\n hasChild: ChildShape;\n}\n\nexport interface ChildShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type?: {\n "@id": "Child";\n };\n hasParent: ParentShape;\n}\n\n', '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',
}; };

@ -10,8 +10,6 @@ export const eachOfAndSimple: TestData = {
ex:MediaContainerShape { ex:MediaContainerShape {
a [ ex:MediaContainer ]; a [ ex:MediaContainer ];
ex:videoImage @ex:VideoShape * ;
ex:videoImage @ex:ImageShape * ;
} }
ex:VideoShape { ex:VideoShape {
@ -27,28 +25,36 @@ export const eachOfAndSimple: TestData = {
successfulContext: { successfulContext: {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
MediaContainer: { MediaContainer: {
"@id": "https://example.com/MediaContainer", "@id": "https://example.com/MediaContainer",
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
videoImage: { },
"@id": "https://example.com/videoImage", },
"@type": "@id", Video: {
"@id": "https://example.com/Video",
"@context": {
type: {
"@id": "@type",
"@isCollection": true, "@isCollection": true,
}, },
}, },
}, },
videoImage: { Image: {
"@id": "https://example.com/videoImage", "@id": "https://example.com/Image",
"@type": "@id", "@context": {
"@isCollection": true, type: {
"@id": "@type",
"@isCollection": true,
},
},
}, },
Video: "https://example.com/Video",
Image: "https://example.com/Image",
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainerShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "MediaContainer";\n };\n videoImage?: LdSet<VideoShape | ImageShape>;\n}\n\nexport interface VideoShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "Video";\n };\n}\n\nexport interface ImageShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "Image";\n };\n}\n\n', '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',
}; };

@ -39,12 +39,14 @@ export const extendsSimple: TestData = {
successfulContext: { successfulContext: {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
Entity: { Entity: {
"@id": "https://example.com/Entity", "@id": "https://example.com/Entity",
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
entityId: "https://example.com/entityId", entityId: "https://example.com/entityId",
}, },
@ -55,6 +57,7 @@ export const extendsSimple: TestData = {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
entityId: "https://example.com/entityId", entityId: "https://example.com/entityId",
name: "http://xmlns.com/foaf/0.1/name", name: "http://xmlns.com/foaf/0.1/name",
@ -66,6 +69,7 @@ export const extendsSimple: TestData = {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
entityId: "https://example.com/entityId", entityId: "https://example.com/entityId",
name: "http://xmlns.com/foaf/0.1/name", name: "http://xmlns.com/foaf/0.1/name",
@ -75,5 +79,5 @@ export const extendsSimple: TestData = {
employeeNumber: "https://example.com/employeeNumber", employeeNumber: "https://example.com/employeeNumber",
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface EntityShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "Entity";\n };\n entityId: any;\n}\n\nexport interface PersonShape {\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 EmployeeShape {\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', '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<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 EmployeeShape {\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',
}; };

@ -0,0 +1,60 @@
import type { TestData } from "./testData.js";
/**
* MULTIPLE CONSTRAINTS
*/
export const multipleSharedPredicates: TestData = {
name: "multipleSharedPredicates",
shexc: `
PREFIX ex: <https://example.com/>
ex:MediaContainerShape {
a [ ex:Media ];
a [ ex:Video ];
ex:something [ ex:OtherThing ];
ex:something [ ex:Thing3 ];
}
`,
sampleTurtle: "",
baseNode: "",
successfulContext: {
type: {
"@id": "@type",
"@isCollection": true,
},
Media: {
"@id": "https://example.com/Media",
"@context": {
type: {
"@id": "@type",
"@isCollection": true,
},
something: {
"@id": "https://example.com/something",
"@isCollection": true,
},
},
},
Video: {
"@id": "https://example.com/Video",
"@context": {
type: {
"@id": "@type",
"@isCollection": true,
},
something: {
"@id": "https://example.com/something",
"@isCollection": true,
},
},
},
something: {
"@id": "https://example.com/something",
"@isCollection": true,
},
OtherThing: "https://example.com/OtherThing",
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',
};

@ -44,12 +44,14 @@ export const oldExtends: TestData = {
successfulContext: { successfulContext: {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
Entity: { Entity: {
"@id": "https://example.com/Entity", "@id": "https://example.com/Entity",
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
entityId: "https://example.com/entityId", entityId: "https://example.com/entityId",
}, },
@ -60,6 +62,7 @@ export const oldExtends: TestData = {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
entityId: "https://example.com/entityId", entityId: "https://example.com/entityId",
name: "http://xmlns.com/foaf/0.1/name", name: "http://xmlns.com/foaf/0.1/name",
@ -71,6 +74,7 @@ export const oldExtends: TestData = {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
entityId: "https://example.com/entityId", entityId: "https://example.com/entityId",
name: "http://xmlns.com/foaf/0.1/name", name: "http://xmlns.com/foaf/0.1/name",
@ -80,5 +84,5 @@ export const oldExtends: TestData = {
employeeNumber: "https://example.com/employeeNumber", employeeNumber: "https://example.com/employeeNumber",
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface EntityShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\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 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',
}; };

@ -27,12 +27,14 @@ export const orSimple: TestData = {
successfulContext: { successfulContext: {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
MediaContainer: { MediaContainer: {
"@id": "https://example.com/MediaContainer", "@id": "https://example.com/MediaContainer",
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
primaryMedia: { primaryMedia: {
"@id": "https://example.com/primaryMedia", "@id": "https://example.com/primaryMedia",
@ -49,8 +51,24 @@ export const orSimple: TestData = {
"@id": "https://example.com/primaryMedia", "@id": "https://example.com/primaryMedia",
"@type": "@id", "@type": "@id",
}, },
Video: "https://example.com/Video", Video: {
Image: "https://example.com/Image", "@id": "https://example.com/Video",
"@context": {
type: {
"@id": "@type",
"@isCollection": true,
},
},
},
Image: {
"@id": "https://example.com/Image",
"@context": {
type: {
"@id": "@type",
"@isCollection": true,
},
},
},
media: { media: {
"@id": "https://example.com/media", "@id": "https://example.com/media",
"@type": "@id", "@type": "@id",
@ -58,5 +76,5 @@ export const orSimple: TestData = {
}, },
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainerShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "MediaContainer";\n };\n primaryMedia: VideoShape | ImageShape;\n media?: LdSet<VideoShape | ImageShape>;\n}\n\nexport interface VideoShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "Video";\n };\n}\n\nexport interface ImageShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "Image";\n };\n}\n\n', '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<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',
}; };

File diff suppressed because one or more lines are too long

@ -53,12 +53,14 @@ srs:EmailShape EXTRA a {
successfulContext: { successfulContext: {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
Person: { Person: {
"@id": "http://schema.org/Person", "@id": "http://schema.org/Person",
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
hasEmail: { hasEmail: {
"@id": "http://www.w3.org/2006/vcard/ns#hasEmail", "@id": "http://www.w3.org/2006/vcard/ns#hasEmail",
@ -76,6 +78,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
hasEmail: { hasEmail: {
"@id": "http://www.w3.org/2006/vcard/ns#hasEmail", "@id": "http://www.w3.org/2006/vcard/ns#hasEmail",
@ -98,6 +101,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
value: { value: {
"@id": "http://www.w3.org/2006/vcard/ns#value", "@id": "http://www.w3.org/2006/vcard/ns#value",
@ -110,6 +114,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
value: { value: {
"@id": "http://www.w3.org/2006/vcard/ns#value", "@id": "http://www.w3.org/2006/vcard/ns#value",
@ -122,6 +127,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
value: { value: {
"@id": "http://www.w3.org/2006/vcard/ns#value", "@id": "http://www.w3.org/2006/vcard/ns#value",
@ -134,6 +140,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
value: { value: {
"@id": "http://www.w3.org/2006/vcard/ns#value", "@id": "http://www.w3.org/2006/vcard/ns#value",
@ -146,6 +153,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
value: { value: {
"@id": "http://www.w3.org/2006/vcard/ns#value", "@id": "http://www.w3.org/2006/vcard/ns#value",
@ -158,6 +166,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
value: { value: {
"@id": "http://www.w3.org/2006/vcard/ns#value", "@id": "http://www.w3.org/2006/vcard/ns#value",
@ -170,6 +179,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
value: { value: {
"@id": "http://www.w3.org/2006/vcard/ns#value", "@id": "http://www.w3.org/2006/vcard/ns#value",
@ -182,6 +192,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
value: { value: {
"@id": "http://www.w3.org/2006/vcard/ns#value", "@id": "http://www.w3.org/2006/vcard/ns#value",
@ -194,6 +205,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
value: { value: {
"@id": "http://www.w3.org/2006/vcard/ns#value", "@id": "http://www.w3.org/2006/vcard/ns#value",
@ -206,6 +218,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
value: { value: {
"@id": "http://www.w3.org/2006/vcard/ns#value", "@id": "http://www.w3.org/2006/vcard/ns#value",
@ -218,6 +231,7 @@ srs:EmailShape EXTRA a {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
value: { value: {
"@id": "http://www.w3.org/2006/vcard/ns#value", "@id": "http://www.w3.org/2006/vcard/ns#value",
@ -235,5 +249,5 @@ srs:EmailShape EXTRA a {
}, },
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface SolidProfileShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n /**\n * Defines the node as a Person | Defines the node as a Person\n */\n type: LdSet<{\n "@id": "Person";\n } | {\n "@id": "Person2";\n }>;\n /**\n * The person\'s email.\n */\n hasEmail?: LdSet<EmailShape>;\n /**\n * An alternate way to define a person\'s name\n */\n name?: string;\n}\n\nexport interface EmailShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n /**\n * The type of email.\n */\n type?: {\n "@id": "Dom";\n } | {\n "@id": "Home";\n } | {\n "@id": "ISDN";\n } | {\n "@id": "Internet";\n } | {\n "@id": "Intl";\n } | {\n "@id": "Label";\n } | {\n "@id": "Parcel";\n } | {\n "@id": "Postal";\n } | {\n "@id": "Pref";\n } | {\n "@id": "Work";\n } | {\n "@id": "X400";\n };\n /**\n * The value of an email as a mailto link (Example <mailto:jane@example.com>)\n */\n value: {\n "@id": string;\n };\n}\n\n', 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface SolidProfileShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n /**\n * Defines the node as a Person | Defines the node as a Person\n */\n type: LdSet<{\n "@id": "Person";\n } | {\n "@id": "Person2";\n }>;\n /**\n * The person\'s email.\n */\n hasEmail?: LdSet<EmailShape>;\n /**\n * An alternate way to define a person\'s name\n */\n name?: string;\n}\n\nexport interface EmailShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n /**\n * The type of email.\n */\n type?: LdSet<{\n "@id": "Dom";\n } | {\n "@id": "Home";\n } | {\n "@id": "ISDN";\n } | {\n "@id": "Internet";\n } | {\n "@id": "Intl";\n } | {\n "@id": "Label";\n } | {\n "@id": "Parcel";\n } | {\n "@id": "Postal";\n } | {\n "@id": "Pref";\n } | {\n "@id": "Work";\n } | {\n "@id": "X400";\n }>;\n /**\n * The value of an email as a mailto link (Example <mailto:jane@example.com>)\n */\n value: {\n "@id": string;\n };\n}\n\n',
}; };

@ -33,12 +33,14 @@ export const reusedPredicates: TestData = {
successfulContext: { successfulContext: {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
Document: { Document: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Document", "@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Document",
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
vocabulary: { vocabulary: {
"@id": "@id":
@ -64,11 +66,11 @@ export const reusedPredicates: TestData = {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
name: { name: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name", "@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name",
"@type": "http://www.w3.org/2001/XMLSchema#string", "@type": "http://www.w3.org/2001/XMLSchema#string",
"@isCollection": true,
}, },
path: { path: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#path", "@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#path",
@ -96,6 +98,7 @@ export const reusedPredicates: TestData = {
"@context": { "@context": {
type: { type: {
"@id": "@type", "@id": "@type",
"@isCollection": true,
}, },
name: { name: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name", "@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name",
@ -110,5 +113,5 @@ export const reusedPredicates: TestData = {
}, },
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface DocumentShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "Document";\n };\n vocabulary?: LdSet<VocabularyShape>;\n law: LawShape;\n}\n\nexport interface LawShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "Law";\n };\n name?: LdSet<string>;\n path: {\n "@id": string;\n };\n}\n\nexport interface VocabularyShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: {\n "@id": "Vocabulary";\n };\n name: string;\n path?: LdSet<{\n "@id": string;\n }>;\n}\n\n', 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface DocumentShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Document";\n }>;\n vocabulary?: LdSet<VocabularyShape>;\n law: LawShape;\n}\n\nexport interface LawShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Law";\n }>;\n name?: LdSet<string>;\n path: {\n "@id": string;\n };\n}\n\nexport interface VocabularyShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n type: LdSet<{\n "@id": "Vocabulary";\n }>;\n name: string;\n path?: LdSet<{\n "@id": string;\n }>;\n}\n\n',
}; };

@ -10,6 +10,7 @@ import { oldExtends } from "./oldExtends.js";
import { orSimple } from "./orSimple.js"; import { orSimple } from "./orSimple.js";
import { andSimple } from "./andSimple.js"; import { andSimple } from "./andSimple.js";
import { eachOfAndSimple } from "./eachOfAndSimple.js"; import { eachOfAndSimple } from "./eachOfAndSimple.js";
import { multipleSharedPredicates } from "./multipleSharedPredicates.js";
export interface TestData { export interface TestData {
name: string; name: string;
@ -32,4 +33,5 @@ export const testData: TestData[] = [
orSimple, orSimple,
andSimple, andSimple,
eachOfAndSimple, eachOfAndSimple,
multipleSharedPredicates,
]; ];

Loading…
Cancel
Save