Before JsonLdContextBuilder redo

main
Jackson Morgan 6 months ago
parent 4905197d23
commit 2b92fb47a9
  1. 2
      packages/cli/src/templates/context.ejs
  2. 2
      packages/cli/src/templates/typings.ejs
  3. 2
      packages/schema-converter-shex/src/typing/ShexJTypingTransformer.ts
  4. 2
      packages/solid/package.json
  5. 97
      packages/solid/src/.ldo/solid.context.ts
  6. 22
      packages/solid/src/.ldo/solid.typings.ts
  7. 63
      packages/solid/src/.ldo/wac.context.ts
  8. 20
      packages/solid/src/.ldo/wac.typings.ts
  9. 2
      packages/solid/src/SolidLdoDataset.ts
  10. 17
      packages/solid/src/resource/wac/setWacRule.ts

@ -1,4 +1,4 @@
import { LdoJsonldContext } from "@ldo/jsonld-dataset-proxy"; import { LdoJsonldContext } from "@ldo/ldo";
/** /**
* ============================================================================= * =============================================================================

@ -1,4 +1,4 @@
import { ContextDefinition } from "jsonld"; import { LdoJsonldContext, LdSet } from "@ldo/ldo";
/** /**
* ============================================================================= * =============================================================================

@ -115,7 +115,7 @@ export const ShexJTypingTransformer = ShexJTraverser.createTransformer<
newInterface.members.push( newInterface.members.push(
dom.create.property( dom.create.property(
"@context", "@context",
dom.create.namedTypeReference("ContextDefinition"), dom.create.namedTypeReference("LdoJsonldContext"),
dom.DeclarationFlags.Optional, dom.DeclarationFlags.Optional,
), ),
); );

@ -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", "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage -t \"sets wac rules for a resource that\"",
"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",

@ -1,38 +1,87 @@
import { ContextDefinition } from "jsonld"; import { LdoJsonldContext } from "@ldo/ldo";
/** /**
* ============================================================================= * =============================================================================
* solidContext: JSONLD Context for solid * solidContext: JSONLD Context for solid
* ============================================================================= * =============================================================================
*/ */
export const solidContext: ContextDefinition = { export const solidContext: LdoJsonldContext = {
type: { Container: {
"@id": "@type", "@id": "http://www.w3.org/ns/ldp#Container",
"@container": "@set", "@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: {
Resource: "http://www.w3.org/ns/ldp#Resource", "@id": "http://www.w3.org/ns/ldp#Resource",
modified: { "@context": {
"@id": "http://purl.org/dc/terms/modified", type: {
"@type": "http://www.w3.org/2001/XMLSchema#string", "@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: { Resource2: {
"@id": "http://www.w3.org/ns/ldp#contains", "@id": "http://www.w3.org/ns/iana/media-types/text/turtle#Resource",
"@type": "@id", "@context": {
"@container": "@set", type: {
}, "@id": "@type",
Resource2: "http://www.w3.org/ns/iana/media-types/text/turtle#Resource", "@isCollection": true,
mtime: { },
"@id": "http://www.w3.org/ns/posix/stat#mtime", modified: {
"@type": "http://www.w3.org/2001/XMLSchema#decimal", "@id": "http://purl.org/dc/terms/modified",
}, "@type": "http://www.w3.org/2001/XMLSchema#string",
size: { },
"@id": "http://www.w3.org/ns/posix/stat#size", mtime: {
"@type": "http://www.w3.org/2001/XMLSchema#integer", "@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",
"@container": "@set", "@isCollection": true,
}, },
}; };

@ -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 { export interface Container {
"@id"?: string; "@id"?: string;
"@context"?: ContextDefinition; "@context"?: LdoJsonldContext;
/** /**
* A container on a Solid server * A container on a Solid server
*/ */
type?: ( type?: LdSet<
| { | {
"@id": "Container"; "@id": "Container";
} }
| { | {
"@id": "Resource"; "@id": "Resource";
} }
)[]; >;
/** /**
* Date modified * Date modified
*/ */
@ -30,7 +30,7 @@ export interface Container {
/** /**
* Defines a Solid Resource * Defines a Solid Resource
*/ */
contains?: Resource[]; contains?: LdSet<Resource>;
/** /**
* ? * ?
*/ */
@ -46,18 +46,18 @@ export interface Container {
*/ */
export interface Resource { export interface Resource {
"@id"?: string; "@id"?: string;
"@context"?: ContextDefinition; "@context"?: LdoJsonldContext;
/** /**
* Any resource on a Solid server * Any resource on a Solid server
*/ */
type?: ( type?: LdSet<
| { | {
"@id": "Resource"; "@id": "Resource";
} }
| { | {
"@id": "Resource2"; "@id": "Resource2";
} }
)[]; >;
/** /**
* Date modified * Date modified
*/ */
@ -77,8 +77,8 @@ export interface Resource {
*/ */
export interface ProfileWithStorage { export interface ProfileWithStorage {
"@id"?: string; "@id"?: string;
"@context"?: ContextDefinition; "@context"?: LdoJsonldContext;
storage?: { storage?: LdSet<{
"@id": string; "@id": string;
}[]; }>;
} }

@ -1,43 +1,50 @@
import { ContextDefinition } from "jsonld"; import { LdoJsonldContext } from "@ldo/ldo";
/** /**
* ============================================================================= * =============================================================================
* wacContext: JSONLD Context for wac * wacContext: JSONLD Context for wac
* ============================================================================= * =============================================================================
*/ */
export const wacContext: ContextDefinition = { export const wacContext: LdoJsonldContext = {
type: { type: {
"@id": "@type", "@id": "@type",
}, },
Authorization: "http://www.w3.org/ns/auth/acl#Authorization", Authorization: {
accessTo: { "@id": "http://www.w3.org/ns/auth/acl#Authorization",
"@id": "http://www.w3.org/ns/auth/acl#accessTo", "@context": {
"@type": "@id", type: {
}, "@id": "@type",
default: { },
"@id": "http://www.w3.org/ns/auth/acl#default", accessTo: {
"@type": "@id", "@id": "http://www.w3.org/ns/auth/acl#accessTo",
}, "@type": "@id",
agent: { },
"@id": "http://www.w3.org/ns/auth/acl#agent", default: {
"@type": "@id", "@id": "http://www.w3.org/ns/auth/acl#default",
"@container": "@set", "@type": "@id",
}, },
agentGroup: { agent: {
"@id": "http://www.w3.org/ns/auth/acl#agentGroup", "@id": "http://www.w3.org/ns/auth/acl#agent",
"@type": "@id", "@type": "@id",
"@container": "@set", "@isCollection": true,
}, },
agentClass: { agentGroup: {
"@id": "http://www.w3.org/ns/auth/acl#agentClass", "@id": "http://www.w3.org/ns/auth/acl#agentGroup",
"@container": "@set", "@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", 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",
"@container": "@set",
},
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",

@ -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 { export interface Authorization {
"@id"?: string; "@id"?: string;
"@context"?: ContextDefinition; "@context"?: LdoJsonldContext;
/** /**
* Denotes this as an acl:Authorization * 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 * 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; "@id": string;
}[]; }>;
/** /**
* Denotes a group of agents being given the access permission * Denotes a group of agents being given the access permission
*/ */
agentGroup?: { agentGroup?: LdSet<{
"@id": string; "@id": string;
}[]; }>;
/** /**
* An agent class is a class of persons or entities identified by a URI. * An agent class is a class of persons or entities identified by a URI.
*/ */
agentClass?: ( agentClass?: LdSet<
| { | {
"@id": "AuthenticatedAgent"; "@id": "AuthenticatedAgent";
} }
| { | {
"@id": "Agent"; "@id": "Agent";
} }
)[]; >;
/** /**
* Denotes a class of operations that the agents can perform on a resource. * Denotes a class of operations that the agents can perform on a resource.
*/ */
mode?: ( mode?: LdSet<
| { | {
"@id": "Read"; "@id": "Read";
} }
@ -69,5 +69,5 @@ export interface Authorization {
| { | {
"@id": "Control"; "@id": "Control";
} }
)[]; >;
} }

@ -148,7 +148,7 @@ export class SolidLdoDataset extends LdoDataset implements ISolidLdoDataset {
const profile = this.usingType(ProfileWithStorageShapeType).fromSubject( const profile = this.usingType(ProfileWithStorageShapeType).fromSubject(
webId, webId,
); );
if (profile.storage && profile.storage.length > 0) { if (profile.storage && profile.storage.size > 0) {
const containers = profile.storage.map((storageNode) => const containers = profile.storage.map((storageNode) =>
this.getResource(storageNode["@id"] as ContainerUri), this.getResource(storageNode["@id"] as ContainerUri),
); );

@ -52,11 +52,10 @@ export async function setWacRuleForAclUri(
.usingType(AuthorizationShapeType) .usingType(AuthorizationShapeType)
.fromSubject(`${aclUri}#${v4()}`); .fromSubject(`${aclUri}#${v4()}`);
authorization.type = { "@id": "Authorization" }; authorization.type = { "@id": "Authorization" };
if (accessModeList.read) authorization.mode?.push({ "@id": "Read" }); if (accessModeList.read) authorization.mode?.add({ "@id": "Read" });
if (accessModeList.write) authorization.mode?.push({ "@id": "Write" }); if (accessModeList.write) authorization.mode?.add({ "@id": "Write" });
if (accessModeList.append) authorization.mode?.push({ "@id": "Append" }); if (accessModeList.append) authorization.mode?.add({ "@id": "Append" });
if (accessModeList.control) if (accessModeList.control) authorization.mode?.add({ "@id": "Control" });
authorization.mode?.push({ "@id": "Control" });
authorization.accessTo = { "@id": accessTo }; authorization.accessTo = { "@id": accessTo };
if (isContainerUri(accessTo)) { if (isContainerUri(accessTo)) {
authorization.default = { "@id": accessTo }; authorization.default = { "@id": accessTo };
@ -66,11 +65,11 @@ export async function setWacRuleForAclUri(
const authorization = ruleMap[accessModeListHash]; const authorization = ruleMap[accessModeListHash];
// Add agents to the rule // Add agents to the rule
if (type === "public") { if (type === "public") {
authorization.agentClass?.push({ "@id": "Agent" }); authorization.agentClass?.add({ "@id": "Agent" });
} else if (type === "authenticated") { } else if (type === "authenticated") {
authorization.agentClass?.push({ "@id": "AuthenticatedAgent" }); authorization.agentClass?.add({ "@id": "AuthenticatedAgent" });
} else if (type === "agent" && agentId) { } 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); 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