diff --git a/packages/cli/src/templates/context.ejs b/packages/cli/src/templates/context.ejs index e70eb97..4f9ccf2 100644 --- a/packages/cli/src/templates/context.ejs +++ b/packages/cli/src/templates/context.ejs @@ -1,4 +1,4 @@ -import { LdoJsonldContext } from "@ldo/jsonld-dataset-proxy"; +import { LdoJsonldContext } from "@ldo/ldo"; /** * ============================================================================= diff --git a/packages/cli/src/templates/typings.ejs b/packages/cli/src/templates/typings.ejs index fe71323..2ec78c8 100644 --- a/packages/cli/src/templates/typings.ejs +++ b/packages/cli/src/templates/typings.ejs @@ -1,4 +1,4 @@ -import { ContextDefinition } from "jsonld"; +import { LdoJsonldContext, LdSet } from "@ldo/ldo"; /** * ============================================================================= diff --git a/packages/schema-converter-shex/src/typing/ShexJTypingTransformer.ts b/packages/schema-converter-shex/src/typing/ShexJTypingTransformer.ts index 37d14ca..05cff51 100644 --- a/packages/schema-converter-shex/src/typing/ShexJTypingTransformer.ts +++ b/packages/schema-converter-shex/src/typing/ShexJTypingTransformer.ts @@ -115,7 +115,7 @@ export const ShexJTypingTransformer = ShexJTraverser.createTransformer< newInterface.members.push( dom.create.property( "@context", - dom.create.namedTypeReference("ContextDefinition"), + dom.create.namedTypeReference("LdoJsonldContext"), dom.DeclarationFlags.Optional, ), ); diff --git a/packages/solid/package.json b/packages/solid/package.json index 20c21e7..31ccfc8 100644 --- a/packages/solid/package.json +++ b/packages/solid/package.json @@ -7,7 +7,7 @@ "example": "ts-node ./example/example.ts", "build": "tsc --project tsconfig.build.json", "watch": "tsc --watch", - "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage", + "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage -t \"sets wac rules for a resource that\"", "test:watch": "jest --watch", "prepublishOnly": "npm run test && npm run build", "build:ldo": "ldo build --input src/.shapes --output src/.ldo", diff --git a/packages/solid/src/.ldo/solid.context.ts b/packages/solid/src/.ldo/solid.context.ts index 8244ade..6fb1a73 100644 --- a/packages/solid/src/.ldo/solid.context.ts +++ b/packages/solid/src/.ldo/solid.context.ts @@ -1,38 +1,87 @@ -import { ContextDefinition } from "jsonld"; +import { LdoJsonldContext } from "@ldo/ldo"; /** * ============================================================================= * solidContext: JSONLD Context for solid * ============================================================================= */ -export const solidContext: ContextDefinition = { - type: { - "@id": "@type", - "@container": "@set", +export const solidContext: LdoJsonldContext = { + Container: { + "@id": "http://www.w3.org/ns/ldp#Container", + "@context": { + type: { + "@id": "@type", + "@isCollection": true, + }, + 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, + }, + 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", + }, + }, }, - Container: "http://www.w3.org/ns/ldp#Container", - Resource: "http://www.w3.org/ns/ldp#Resource", - modified: { - "@id": "http://purl.org/dc/terms/modified", - "@type": "http://www.w3.org/2001/XMLSchema#string", + Resource: { + "@id": "http://www.w3.org/ns/ldp#Resource", + "@context": { + type: { + "@id": "@type", + "@isCollection": true, + }, + 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, + }, + 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", + }, + }, }, - contains: { - "@id": "http://www.w3.org/ns/ldp#contains", - "@type": "@id", - "@container": "@set", - }, - Resource2: "http://www.w3.org/ns/iana/media-types/text/turtle#Resource", - 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", + Resource2: { + "@id": "http://www.w3.org/ns/iana/media-types/text/turtle#Resource", + "@context": { + type: { + "@id": "@type", + "@isCollection": true, + }, + modified: { + "@id": "http://purl.org/dc/terms/modified", + "@type": "http://www.w3.org/2001/XMLSchema#string", + }, + 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: { "@id": "http://www.w3.org/ns/pim/space#storage", "@type": "@id", - "@container": "@set", + "@isCollection": true, }, }; diff --git a/packages/solid/src/.ldo/solid.typings.ts b/packages/solid/src/.ldo/solid.typings.ts index b5e6276..0405e75 100644 --- a/packages/solid/src/.ldo/solid.typings.ts +++ b/packages/solid/src/.ldo/solid.typings.ts @@ -1,4 +1,4 @@ -import { ContextDefinition } from "jsonld"; +import { LdoJsonldContext, LdSet } from "@ldo/ldo"; /** * ============================================================================= @@ -11,18 +11,18 @@ import { ContextDefinition } from "jsonld"; */ export interface Container { "@id"?: string; - "@context"?: ContextDefinition; + "@context"?: LdoJsonldContext; /** * A container on a Solid server */ - type?: ( + type?: LdSet< | { "@id": "Container"; } | { "@id": "Resource"; } - )[]; + >; /** * Date modified */ @@ -30,7 +30,7 @@ export interface Container { /** * Defines a Solid Resource */ - contains?: Resource[]; + contains?: LdSet; /** * ? */ @@ -46,18 +46,18 @@ export interface Container { */ export interface Resource { "@id"?: string; - "@context"?: ContextDefinition; + "@context"?: LdoJsonldContext; /** * Any resource on a Solid server */ - type?: ( + type?: LdSet< | { "@id": "Resource"; } | { "@id": "Resource2"; } - )[]; + >; /** * Date modified */ @@ -77,8 +77,8 @@ export interface Resource { */ export interface ProfileWithStorage { "@id"?: string; - "@context"?: ContextDefinition; - storage?: { + "@context"?: LdoJsonldContext; + storage?: LdSet<{ "@id": string; - }[]; + }>; } diff --git a/packages/solid/src/.ldo/wac.context.ts b/packages/solid/src/.ldo/wac.context.ts index 22df8b2..6f19691 100644 --- a/packages/solid/src/.ldo/wac.context.ts +++ b/packages/solid/src/.ldo/wac.context.ts @@ -1,43 +1,50 @@ -import { ContextDefinition } from "jsonld"; +import { LdoJsonldContext } from "@ldo/ldo"; /** * ============================================================================= * wacContext: JSONLD Context for wac * ============================================================================= */ -export const wacContext: ContextDefinition = { +export const wacContext: LdoJsonldContext = { type: { "@id": "@type", }, - Authorization: "http://www.w3.org/ns/auth/acl#Authorization", - 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", - "@container": "@set", - }, - agentGroup: { - "@id": "http://www.w3.org/ns/auth/acl#agentGroup", - "@type": "@id", - "@container": "@set", - }, - agentClass: { - "@id": "http://www.w3.org/ns/auth/acl#agentClass", - "@container": "@set", + Authorization: { + "@id": "http://www.w3.org/ns/auth/acl#Authorization", + "@context": { + type: { + "@id": "@type", + }, + 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, + }, + mode: { + "@id": "http://www.w3.org/ns/auth/acl#mode", + "@isCollection": true, + }, + }, }, AuthenticatedAgent: "http://www.w3.org/ns/auth/acl#AuthenticatedAgent", Agent: "http://xmlns.com/foaf/0.1/Agent", - mode: { - "@id": "http://www.w3.org/ns/auth/acl#mode", - "@container": "@set", - }, Read: "http://www.w3.org/ns/auth/acl#Read", Write: "http://www.w3.org/ns/auth/acl#Write", Append: "http://www.w3.org/ns/auth/acl#Append", diff --git a/packages/solid/src/.ldo/wac.typings.ts b/packages/solid/src/.ldo/wac.typings.ts index 456c5ed..40860e0 100644 --- a/packages/solid/src/.ldo/wac.typings.ts +++ b/packages/solid/src/.ldo/wac.typings.ts @@ -1,4 +1,4 @@ -import { ContextDefinition } from "jsonld"; +import { LdoJsonldContext, LdSet } from "@ldo/ldo"; /** * ============================================================================= @@ -11,7 +11,7 @@ import { ContextDefinition } from "jsonld"; */ export interface Authorization { "@id"?: string; - "@context"?: ContextDefinition; + "@context"?: LdoJsonldContext; /** * Denotes this as an acl:Authorization */ @@ -33,30 +33,30 @@ export interface Authorization { /** * An agent is a person, social entity or software identified by a URI, e.g., a WebID denotes an agent */ - agent?: { + agent?: LdSet<{ "@id": string; - }[]; + }>; /** * Denotes a group of agents being given the access permission */ - agentGroup?: { + agentGroup?: LdSet<{ "@id": string; - }[]; + }>; /** * An agent class is a class of persons or entities identified by a URI. */ - agentClass?: ( + agentClass?: LdSet< | { "@id": "AuthenticatedAgent"; } | { "@id": "Agent"; } - )[]; + >; /** * Denotes a class of operations that the agents can perform on a resource. */ - mode?: ( + mode?: LdSet< | { "@id": "Read"; } @@ -69,5 +69,5 @@ export interface Authorization { | { "@id": "Control"; } - )[]; + >; } diff --git a/packages/solid/src/SolidLdoDataset.ts b/packages/solid/src/SolidLdoDataset.ts index d95bf44..cfd46f4 100644 --- a/packages/solid/src/SolidLdoDataset.ts +++ b/packages/solid/src/SolidLdoDataset.ts @@ -148,7 +148,7 @@ export class SolidLdoDataset extends LdoDataset implements ISolidLdoDataset { const profile = this.usingType(ProfileWithStorageShapeType).fromSubject( webId, ); - if (profile.storage && profile.storage.length > 0) { + if (profile.storage && profile.storage.size > 0) { const containers = profile.storage.map((storageNode) => this.getResource(storageNode["@id"] as ContainerUri), ); diff --git a/packages/solid/src/resource/wac/setWacRule.ts b/packages/solid/src/resource/wac/setWacRule.ts index adbac93..70a0c30 100644 --- a/packages/solid/src/resource/wac/setWacRule.ts +++ b/packages/solid/src/resource/wac/setWacRule.ts @@ -52,11 +52,10 @@ export async function setWacRuleForAclUri( .usingType(AuthorizationShapeType) .fromSubject(`${aclUri}#${v4()}`); authorization.type = { "@id": "Authorization" }; - if (accessModeList.read) authorization.mode?.push({ "@id": "Read" }); - if (accessModeList.write) authorization.mode?.push({ "@id": "Write" }); - if (accessModeList.append) authorization.mode?.push({ "@id": "Append" }); - if (accessModeList.control) - authorization.mode?.push({ "@id": "Control" }); + if (accessModeList.read) authorization.mode?.add({ "@id": "Read" }); + if (accessModeList.write) authorization.mode?.add({ "@id": "Write" }); + if (accessModeList.append) authorization.mode?.add({ "@id": "Append" }); + if (accessModeList.control) authorization.mode?.add({ "@id": "Control" }); authorization.accessTo = { "@id": accessTo }; if (isContainerUri(accessTo)) { authorization.default = { "@id": accessTo }; @@ -66,11 +65,11 @@ export async function setWacRuleForAclUri( const authorization = ruleMap[accessModeListHash]; // Add agents to the rule if (type === "public") { - authorization.agentClass?.push({ "@id": "Agent" }); + authorization.agentClass?.add({ "@id": "Agent" }); } else if (type === "authenticated") { - authorization.agentClass?.push({ "@id": "AuthenticatedAgent" }); + authorization.agentClass?.add({ "@id": "AuthenticatedAgent" }); } else if (type === "agent" && agentId) { - authorization.agent?.push({ "@id": agentId }); + authorization.agent?.add({ "@id": agentId }); } } @@ -81,6 +80,8 @@ export async function setWacRuleForAclUri( addRuleToDataset("agent", accessModeList, agentUri); }); + console.log(dataset.toString()); + // Save to Pod const response = await fetch(aclUri, { method: "PUT",