Fixed problems with the generator

main
Jackson Morgan 6 months ago
parent 2b92fb47a9
commit d8a68fa829
  1. 76
      packages/schema-converter-shex/src/context/JsonLdContextBuilder.ts
  2. 2
      packages/schema-converter-shex/test/context.test.ts
  3. 1342
      packages/schema-converter-shex/test/testData/activityPub.ts
  4. 10
      packages/schema-converter-shex/test/testData/andSimple.ts
  5. 31
      packages/schema-converter-shex/test/testData/circular.ts
  6. 11
      packages/schema-converter-shex/test/testData/eachOfAndSimple.ts
  7. 8
      packages/schema-converter-shex/test/testData/extendsSimple.ts
  8. 8
      packages/schema-converter-shex/test/testData/oldExtends.ts
  9. 15
      packages/schema-converter-shex/test/testData/orSimple.ts
  10. 94
      packages/schema-converter-shex/test/testData/profile.ts
  11. 18
      packages/schema-converter-shex/test/testData/reducedProfile.ts
  12. 26
      packages/schema-converter-shex/test/testData/reusedPredicates.ts
  13. 7
      packages/schema-converter-shex/test/testData/simple.ts
  14. 2
      packages/schema-converter-shex/test/typing.test.ts
  15. 2
      packages/solid/package.json
  16. 21
      packages/solid/src/.ldo/solid.context.ts
  17. 26
      packages/solid/src/.ldo/wac.context.ts
  18. 2
      packages/solid/src/resource/wac/setWacRule.ts

@ -76,14 +76,21 @@ export class JsonLdContextBuilder {
return this.iriTypes[rdfType] as JsonLdContextBuilder; return this.iriTypes[rdfType] as JsonLdContextBuilder;
} }
addSubject(iri: string, rdfType?: string, annotations?: Annotation[]) { private getRelevantBuilders(rdfType?: string): JsonLdContextBuilder[] {
const relevantBuilder = this.getRelevantBuilder(rdfType); const relevantBuilder = this.getRelevantBuilder(rdfType);
if (!relevantBuilder.iriAnnotations[iri]) { return relevantBuilder === this ? [this] : [this, relevantBuilder];
relevantBuilder.iriAnnotations[iri] = []; }
}
if (annotations && annotations.length > 0) { addSubject(iri: string, rdfType?: string, annotations?: Annotation[]) {
relevantBuilder.iriAnnotations[iri].push(...annotations); const relevantBuilders = this.getRelevantBuilders(rdfType);
} relevantBuilders.forEach((relevantBuilder) => {
if (!relevantBuilder.iriAnnotations[iri]) {
relevantBuilder.iriAnnotations[iri] = [];
}
if (annotations && annotations.length > 0) {
relevantBuilder.iriAnnotations[iri].push(...annotations);
}
});
} }
addPredicate( addPredicate(
@ -93,41 +100,30 @@ export class JsonLdContextBuilder {
rdfType?: string, rdfType?: string,
annotations?: Annotation[], annotations?: Annotation[],
) { ) {
const relevantBuilder = this.getRelevantBuilder(rdfType); const relevantBuilders = this.getRelevantBuilders(rdfType);
relevantBuilder.addSubject(iri, undefined, annotations); relevantBuilders.forEach((relevantBuilder) => {
if (!relevantBuilder.iriTypes[iri]) { relevantBuilder.addSubject(iri, undefined, annotations);
relevantBuilder.iriTypes[iri] = expandedTermDefinition; if (!relevantBuilder.iriTypes[iri]) {
if (isContainer) { relevantBuilder.iriTypes[iri] = expandedTermDefinition;
relevantBuilder.iriTypes[iri]["@isCollection"] = true; if (isContainer) {
} relevantBuilder.iriTypes[iri]["@isCollection"] = true;
} else { }
const curDef = relevantBuilder.iriTypes[iri]; } else {
const newDef = expandedTermDefinition; const curDef = relevantBuilder.iriTypes[iri];
// TODO: if you reuse the same predicate with a different cardinality, const newDef = expandedTermDefinition;
// it will overwrite the past cardinality. Perhapse we might want to if (isContainer) {
// split contexts in the various shapes. curDef["@isCollection"] = true;
if (isContainer) { }
curDef["@isCollection"] = true; // If the old and new versions both have types
} if (curDef["@type"] && newDef["@type"]) {
// If the old and new versions both have types if (curDef["@type"] !== newDef["@type"]) {
if (curDef["@type"] && newDef["@type"]) { console.warn(
if ( `You've specified that a specific field "${iri}" can have an object of multiple literal types (${curDef["@type"]} or ${newDef["@type"]}). This is not expressable in JSON-LD context, and we will randomly select one type to use.`,
Array.isArray(curDef["@type"]) && );
!(curDef["@type"] as string[]).includes(newDef["@type"]) }
) {
curDef["@type"].push(newDef["@type"]);
} else if (
typeof curDef["@type"] === "string" &&
curDef["@type"] !== newDef["@type"]
) {
// The typings are incorrect. String arrays are allowed on @type
// see https://w3c.github.io/json-ld-syntax/#example-specifying-multiple-types-for-a-node
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
curDef["@type"] = [curDef["@type"], newDef["@type"]];
} }
} }
} });
} }
generateNames(): Record<string, string> { generateNames(): Record<string, string> {

@ -3,6 +3,8 @@ import { shexjToContext } from "../src/context/shexjToContext";
import parser from "@shexjs/parser"; import parser from "@shexjs/parser";
import type { Schema } from "shexj"; import type { Schema } from "shexj";
console.warn = () => {};
describe("context", () => { describe("context", () => {
testData.forEach(({ name, shexc, successfulContext }) => { testData.forEach(({ name, shexc, successfulContext }) => {
it(`Creates a context for ${name}`, async () => { it(`Creates a context for ${name}`, async () => {

File diff suppressed because one or more lines are too long

@ -24,6 +24,9 @@ export const andSimple: TestData = {
sampleTurtle: "", sampleTurtle: "",
baseNode: "", baseNode: "",
successfulContext: { successfulContext: {
type: {
"@id": "@type",
},
MediaContainer: { MediaContainer: {
"@id": "https://example.com/MediaContainer", "@id": "https://example.com/MediaContainer",
"@context": { "@context": {
@ -36,12 +39,13 @@ export const andSimple: TestData = {
}, },
}, },
}, },
type: { videoImage: {
"@id": "@type", "@id": "https://example.com/videoImage",
"@type": "@id",
}, },
Video: "https://example.com/Video", Video: "https://example.com/Video",
Image: "https://example.com/Image", Image: "https://example.com/Image",
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainerShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\n type: {\n "@id": "MediaContainer";\n };\n videoImage: VideoShape & ImageShape;\n}\n\nexport interface VideoShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\n type: {\n "@id": "Video";\n };\n}\n\nexport interface ImageShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\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: {\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',
}; };

@ -31,21 +31,42 @@ export const circular: TestData = {
`, `,
baseNode: "http://example.com/SampleParent", baseNode: "http://example.com/SampleParent",
successfulContext: { successfulContext: {
type: {
"@id": "@type",
},
Parent: { Parent: {
"@id": "http://example.com/Parent", "@id": "http://example.com/Parent",
"@context": { "@context": {
type: { "@id": "@type" }, type: {
hasChild: { "@id": "http://example.com/hasChild", "@type": "@id" }, "@id": "@type",
},
hasChild: {
"@id": "http://example.com/hasChild",
"@type": "@id",
},
}, },
}, },
hasChild: {
"@id": "http://example.com/hasChild",
"@type": "@id",
},
Child: { Child: {
"@id": "http://example.com/Child", "@id": "http://example.com/Child",
"@context": { "@context": {
type: { "@id": "@type" }, type: {
hasParent: { "@id": "http://example.com/hasParent", "@type": "@id" }, "@id": "@type",
},
hasParent: {
"@id": "http://example.com/hasParent",
"@type": "@id",
},
}, },
}, },
hasParent: {
"@id": "http://example.com/hasParent",
"@type": "@id",
},
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface ParentShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\n type?: {\n "@id": "Parent";\n };\n hasChild: ChildShape;\n}\n\nexport interface ChildShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\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?: {\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',
}; };

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

@ -37,6 +37,9 @@ export const extendsSimple: TestData = {
`, `,
baseNode: "http://example.com/SampleParent", baseNode: "http://example.com/SampleParent",
successfulContext: { successfulContext: {
type: {
"@id": "@type",
},
Entity: { Entity: {
"@id": "https://example.com/Entity", "@id": "https://example.com/Entity",
"@context": { "@context": {
@ -46,6 +49,7 @@ export const extendsSimple: TestData = {
entityId: "https://example.com/entityId", entityId: "https://example.com/entityId",
}, },
}, },
entityId: "https://example.com/entityId",
Person: { Person: {
"@id": "https://example.com/Person", "@id": "https://example.com/Person",
"@context": { "@context": {
@ -56,6 +60,7 @@ export const extendsSimple: TestData = {
name: "http://xmlns.com/foaf/0.1/name", name: "http://xmlns.com/foaf/0.1/name",
}, },
}, },
name: "http://xmlns.com/foaf/0.1/name",
Employee: { Employee: {
"@id": "https://example.com/Employee", "@id": "https://example.com/Employee",
"@context": { "@context": {
@ -67,7 +72,8 @@ export const extendsSimple: TestData = {
employeeNumber: "https://example.com/employeeNumber", 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"?: ContextDefinition;\n type: {\n "@id": "Entity";\n };\n entityId: any;\n}\n\nexport interface PersonShape {\n "@id"?: LdSet<string | string>;\n "@context"?: LdSet<ContextDefinition | ContextDefinition>;\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<ContextDefinition | ContextDefinition | ContextDefinition>;\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: {\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',
}; };

@ -42,6 +42,9 @@ export const oldExtends: TestData = {
`, `,
baseNode: "http://example.com/SampleParent", baseNode: "http://example.com/SampleParent",
successfulContext: { successfulContext: {
type: {
"@id": "@type",
},
Entity: { Entity: {
"@id": "https://example.com/Entity", "@id": "https://example.com/Entity",
"@context": { "@context": {
@ -51,6 +54,7 @@ export const oldExtends: TestData = {
entityId: "https://example.com/entityId", entityId: "https://example.com/entityId",
}, },
}, },
entityId: "https://example.com/entityId",
Person: { Person: {
"@id": "https://example.com/Person", "@id": "https://example.com/Person",
"@context": { "@context": {
@ -61,6 +65,7 @@ export const oldExtends: TestData = {
name: "http://xmlns.com/foaf/0.1/name", name: "http://xmlns.com/foaf/0.1/name",
}, },
}, },
name: "http://xmlns.com/foaf/0.1/name",
Employee: { Employee: {
"@id": "https://example.com/Employee", "@id": "https://example.com/Employee",
"@context": { "@context": {
@ -72,7 +77,8 @@ export const oldExtends: TestData = {
employeeNumber: "https://example.com/employeeNumber", 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"?: ContextDefinition;\n type: {\n "@id": "Entity";\n };\n entityId: any;\n}\n\nexport interface PersonShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\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"?: ContextDefinition;\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: {\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',
}; };

@ -25,6 +25,9 @@ export const orSimple: TestData = {
sampleTurtle: "", sampleTurtle: "",
baseNode: "", baseNode: "",
successfulContext: { successfulContext: {
type: {
"@id": "@type",
},
MediaContainer: { MediaContainer: {
"@id": "https://example.com/MediaContainer", "@id": "https://example.com/MediaContainer",
"@context": { "@context": {
@ -42,12 +45,18 @@ export const orSimple: TestData = {
}, },
}, },
}, },
type: { primaryMedia: {
"@id": "@type", "@id": "https://example.com/primaryMedia",
"@type": "@id",
}, },
Video: "https://example.com/Video", Video: "https://example.com/Video",
Image: "https://example.com/Image", Image: "https://example.com/Image",
media: {
"@id": "https://example.com/media",
"@type": "@id",
"@isCollection": true,
},
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface MediaContainerShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\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"?: ContextDefinition;\n type: {\n "@id": "Video";\n };\n}\n\nexport interface ImageShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\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: {\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',
}; };

File diff suppressed because one or more lines are too long

@ -51,6 +51,9 @@ srs:EmailShape EXTRA a {
sampleTurtle: ``, sampleTurtle: ``,
baseNode: "", baseNode: "",
successfulContext: { successfulContext: {
type: {
"@id": "@type",
},
Person: { Person: {
"@id": "http://schema.org/Person", "@id": "http://schema.org/Person",
"@context": { "@context": {
@ -85,6 +88,11 @@ srs:EmailShape EXTRA a {
}, },
}, },
}, },
hasEmail: {
"@id": "http://www.w3.org/2006/vcard/ns#hasEmail",
"@type": "@id",
"@isCollection": true,
},
Dom: { Dom: {
"@id": "http://www.w3.org/2006/vcard/ns#Dom", "@id": "http://www.w3.org/2006/vcard/ns#Dom",
"@context": { "@context": {
@ -217,7 +225,15 @@ srs:EmailShape EXTRA a {
}, },
}, },
}, },
value: {
"@id": "http://www.w3.org/2006/vcard/ns#value",
"@type": "@id",
},
name: {
"@id": "http://xmlns.com/foaf/0.1/name",
"@type": "http://www.w3.org/2001/XMLSchema#string",
},
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface SolidProfileShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\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"?: ContextDefinition;\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?: {\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',
}; };

@ -31,6 +31,9 @@ export const reusedPredicates: TestData = {
sampleTurtle: ``, sampleTurtle: ``,
baseNode: "http://example.com/SampleParent", baseNode: "http://example.com/SampleParent",
successfulContext: { successfulContext: {
type: {
"@id": "@type",
},
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": {
@ -49,6 +52,12 @@ export const reusedPredicates: TestData = {
}, },
}, },
}, },
vocabulary: {
"@id":
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#vocabulary",
"@type": "@id",
"@isCollection": true,
},
Vocabulary: { Vocabulary: {
"@id": "@id":
"https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Vocabulary", "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Vocabulary",
@ -59,6 +68,7 @@ export const reusedPredicates: TestData = {
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",
@ -67,6 +77,20 @@ export const reusedPredicates: TestData = {
}, },
}, },
}, },
name: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#name",
"@type": "http://www.w3.org/2001/XMLSchema#string",
"@isCollection": true,
},
path: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#path",
"@type": "@id",
"@isCollection": true,
},
law: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#law",
"@type": "@id",
},
Law: { Law: {
"@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Law", "@id": "https://www.forsakringskassan.se/vocabs/fk-sem-poc.ttl#Law",
"@context": { "@context": {
@ -86,5 +110,5 @@ export const reusedPredicates: TestData = {
}, },
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface DocumentShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\n type: {\n "@id": "Document";\n };\n vocabulary?: LdSet<VocabularyShape>;\n law: LawShape;\n}\n\nexport interface LawShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\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"?: ContextDefinition;\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: {\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',
}; };

@ -43,8 +43,11 @@ export const simple: TestData = {
"@type": "@id", "@type": "@id",
"@isCollection": true, "@isCollection": true,
}, },
mbox: { "@id": "http://xmlns.com/foaf/0.1/mbox", "@type": "@id" }, mbox: {
"@id": "http://xmlns.com/foaf/0.1/mbox",
"@type": "@id",
},
}, },
successfulTypings: successfulTypings:
'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface EmployeeShape {\n "@id"?: string;\n "@context"?: ContextDefinition;\n givenName: LdSet<string>;\n familyName: string;\n phone?: LdSet<{\n "@id": string;\n }>;\n mbox: {\n "@id": string;\n };\n}\n\n', 'import { LdSet, LdoJsonldContext } from "@ldo/ldo"\n\nexport interface EmployeeShape {\n "@id"?: string;\n "@context"?: LdoJsonldContext;\n givenName: LdSet<string>;\n familyName: string;\n phone?: LdSet<{\n "@id": string;\n }>;\n mbox: {\n "@id": string;\n };\n}\n\n',
}; };

@ -3,6 +3,8 @@ import { testData } from "./testData/testData";
import { shexjToTyping } from "../src/typing/shexjToTyping"; import { shexjToTyping } from "../src/typing/shexjToTyping";
import type { Schema } from "shexj"; import type { Schema } from "shexj";
console.warn = () => {};
describe("typing", () => { describe("typing", () => {
testData.forEach(({ name, shexc, successfulTypings }) => { testData.forEach(({ name, shexc, successfulTypings }) => {
it(`Creates a typings for ${name}`, async () => { it(`Creates a typings for ${name}`, async () => {

@ -7,7 +7,7 @@
"example": "ts-node ./example/example.ts", "example": "ts-node ./example/example.ts",
"build": "tsc --project tsconfig.build.json", "build": "tsc --project tsconfig.build.json",
"watch": "tsc --watch", "watch": "tsc --watch",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage -t \"sets wac rules for a resource that\"", "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
"test:watch": "jest --watch", "test:watch": "jest --watch",
"prepublishOnly": "npm run test && npm run build", "prepublishOnly": "npm run test && npm run build",
"build:ldo": "ldo build --input src/.shapes --output src/.ldo", "build:ldo": "ldo build --input src/.shapes --output src/.ldo",

@ -6,6 +6,10 @@ import { LdoJsonldContext } from "@ldo/ldo";
* ============================================================================= * =============================================================================
*/ */
export const solidContext: LdoJsonldContext = { export const solidContext: LdoJsonldContext = {
type: {
"@id": "@type",
"@isCollection": true,
},
Container: { Container: {
"@id": "http://www.w3.org/ns/ldp#Container", "@id": "http://www.w3.org/ns/ldp#Container",
"@context": { "@context": {
@ -58,6 +62,15 @@ export const solidContext: LdoJsonldContext = {
}, },
}, },
}, },
modified: {
"@id": "http://purl.org/dc/terms/modified",
"@type": "http://www.w3.org/2001/XMLSchema#string",
},
contains: {
"@id": "http://www.w3.org/ns/ldp#contains",
"@type": "@id",
"@isCollection": true,
},
Resource2: { Resource2: {
"@id": "http://www.w3.org/ns/iana/media-types/text/turtle#Resource", "@id": "http://www.w3.org/ns/iana/media-types/text/turtle#Resource",
"@context": { "@context": {
@ -79,6 +92,14 @@ export const solidContext: LdoJsonldContext = {
}, },
}, },
}, },
mtime: {
"@id": "http://www.w3.org/ns/posix/stat#mtime",
"@type": "http://www.w3.org/2001/XMLSchema#decimal",
},
size: {
"@id": "http://www.w3.org/ns/posix/stat#size",
"@type": "http://www.w3.org/2001/XMLSchema#integer",
},
storage: { storage: {
"@id": "http://www.w3.org/ns/pim/space#storage", "@id": "http://www.w3.org/ns/pim/space#storage",
"@type": "@id", "@type": "@id",

@ -43,8 +43,34 @@ export const wacContext: LdoJsonldContext = {
}, },
}, },
}, },
accessTo: {
"@id": "http://www.w3.org/ns/auth/acl#accessTo",
"@type": "@id",
},
default: {
"@id": "http://www.w3.org/ns/auth/acl#default",
"@type": "@id",
},
agent: {
"@id": "http://www.w3.org/ns/auth/acl#agent",
"@type": "@id",
"@isCollection": true,
},
agentGroup: {
"@id": "http://www.w3.org/ns/auth/acl#agentGroup",
"@type": "@id",
"@isCollection": true,
},
agentClass: {
"@id": "http://www.w3.org/ns/auth/acl#agentClass",
"@isCollection": true,
},
AuthenticatedAgent: "http://www.w3.org/ns/auth/acl#AuthenticatedAgent", AuthenticatedAgent: "http://www.w3.org/ns/auth/acl#AuthenticatedAgent",
Agent: "http://xmlns.com/foaf/0.1/Agent", Agent: "http://xmlns.com/foaf/0.1/Agent",
mode: {
"@id": "http://www.w3.org/ns/auth/acl#mode",
"@isCollection": true,
},
Read: "http://www.w3.org/ns/auth/acl#Read", Read: "http://www.w3.org/ns/auth/acl#Read",
Write: "http://www.w3.org/ns/auth/acl#Write", Write: "http://www.w3.org/ns/auth/acl#Write",
Append: "http://www.w3.org/ns/auth/acl#Append", Append: "http://www.w3.org/ns/auth/acl#Append",

@ -80,8 +80,6 @@ export async function setWacRuleForAclUri(
addRuleToDataset("agent", accessModeList, agentUri); addRuleToDataset("agent", accessModeList, agentUri);
}); });
console.log(dataset.toString());
// Save to Pod // Save to Pod
const response = await fetch(aclUri, { const response = await fetch(aclUri, {
method: "PUT", method: "PUT",

Loading…
Cancel
Save