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. 65
      packages/solid/src/.ldo/solid.context.ts
  6. 22
      packages/solid/src/.ldo/solid.typings.ts
  7. 25
      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(
dom.create.property(
"@context",
dom.create.namedTypeReference("ContextDefinition"),
dom.create.namedTypeReference("LdoJsonldContext"),
dom.DeclarationFlags.Optional,
),
);

@ -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",

@ -1,17 +1,18 @@
import { ContextDefinition } from "jsonld";
import { LdoJsonldContext } from "@ldo/ldo";
/**
* =============================================================================
* solidContext: JSONLD Context for solid
* =============================================================================
*/
export const solidContext: ContextDefinition = {
export const solidContext: LdoJsonldContext = {
Container: {
"@id": "http://www.w3.org/ns/ldp#Container",
"@context": {
type: {
"@id": "@type",
"@container": "@set",
"@isCollection": true,
},
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",
@ -19,9 +20,8 @@ export const solidContext: ContextDefinition = {
contains: {
"@id": "http://www.w3.org/ns/ldp#contains",
"@type": "@id",
"@container": "@set",
"@isCollection": true,
},
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",
@ -30,9 +30,58 @@ export const solidContext: ContextDefinition = {
"@id": "http://www.w3.org/ns/posix/stat#size",
"@type": "http://www.w3.org/2001/XMLSchema#integer",
},
},
},
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",
},
},
},
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,
},
};

@ -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<Resource>;
/**
* ?
*/
@ -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;
}[];
}>;
}

@ -1,15 +1,20 @@
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: {
"@id": "http://www.w3.org/ns/auth/acl#Authorization",
"@context": {
type: {
"@id": "@type",
},
Authorization: "http://www.w3.org/ns/auth/acl#Authorization",
accessTo: {
"@id": "http://www.w3.org/ns/auth/acl#accessTo",
"@type": "@id",
@ -21,23 +26,25 @@ export const wacContext: ContextDefinition = {
agent: {
"@id": "http://www.w3.org/ns/auth/acl#agent",
"@type": "@id",
"@container": "@set",
"@isCollection": true,
},
agentGroup: {
"@id": "http://www.w3.org/ns/auth/acl#agentGroup",
"@type": "@id",
"@container": "@set",
"@isCollection": true,
},
agentClass: {
"@id": "http://www.w3.org/ns/auth/acl#agentClass",
"@container": "@set",
"@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",
"@isCollection": true,
},
},
},
AuthenticatedAgent: "http://www.w3.org/ns/auth/acl#AuthenticatedAgent",
Agent: "http://xmlns.com/foaf/0.1/Agent",
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",

@ -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";
}
)[];
>;
}

@ -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),
);

@ -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",

Loading…
Cancel
Save