diff --git a/Changes b/Changes index a2628b6..72d53b2 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,9 @@ +2023-08-25 0.4.2 + - Supporting 'context_cache' for SendNotificationPlugin (a local cache of JSON-LD contexts) + 2023-08-25 0.4.1 - Fixing artifacts of communica rewriting of blank nodes bug - + 2023-06-28 0.4.0 - Breaking change: policy arguments are now RDF.Terms[] diff --git a/cache/README.md b/cache/README.md new file mode 100644 index 0000000..bd4d3a3 --- /dev/null +++ b/cache/README.md @@ -0,0 +1,19 @@ +# JSON-LD context cache + +This directory contains an example JSON-LD context cache that can be used with the SendNotificatioPlugin `conext_cache` option. This allows to create JSON-LD frames without requiring network activity. + +- activitystreams.jsonld : a local cache of the ActivityStreams + +Usage: + +``` + { + "@id": "http://example.org/sendNotification", + "@type": "SendNotificationPlugin", + "context": [ + "https://www.w3.org/ns/activitystreams" , + "https://purl.org/coar/notify" + ] , + "context_cache" : "cache/activitystreams.jsonld" +} +``` diff --git a/cache/activitystreams.jsonld b/cache/activitystreams.jsonld new file mode 100644 index 0000000..037026c --- /dev/null +++ b/cache/activitystreams.jsonld @@ -0,0 +1,379 @@ +{ + "@context": { + "@vocab": "_:", + "xsd": "http://www.w3.org/2001/XMLSchema#", + "as": "https://www.w3.org/ns/activitystreams#", + "ldp": "http://www.w3.org/ns/ldp#", + "vcard": "http://www.w3.org/2006/vcard/ns#", + "id": "@id", + "type": "@type", + "Accept": "as:Accept", + "Activity": "as:Activity", + "IntransitiveActivity": "as:IntransitiveActivity", + "Add": "as:Add", + "Announce": "as:Announce", + "Application": "as:Application", + "Arrive": "as:Arrive", + "Article": "as:Article", + "Audio": "as:Audio", + "Block": "as:Block", + "Collection": "as:Collection", + "CollectionPage": "as:CollectionPage", + "Relationship": "as:Relationship", + "Create": "as:Create", + "Delete": "as:Delete", + "Dislike": "as:Dislike", + "Document": "as:Document", + "Event": "as:Event", + "Follow": "as:Follow", + "Flag": "as:Flag", + "Group": "as:Group", + "Ignore": "as:Ignore", + "Image": "as:Image", + "Invite": "as:Invite", + "Join": "as:Join", + "Leave": "as:Leave", + "Like": "as:Like", + "Link": "as:Link", + "Mention": "as:Mention", + "Note": "as:Note", + "Object": "as:Object", + "Offer": "as:Offer", + "OrderedCollection": "as:OrderedCollection", + "OrderedCollectionPage": "as:OrderedCollectionPage", + "Organization": "as:Organization", + "Page": "as:Page", + "Person": "as:Person", + "Place": "as:Place", + "Profile": "as:Profile", + "Question": "as:Question", + "Reject": "as:Reject", + "Remove": "as:Remove", + "Service": "as:Service", + "TentativeAccept": "as:TentativeAccept", + "TentativeReject": "as:TentativeReject", + "Tombstone": "as:Tombstone", + "Undo": "as:Undo", + "Update": "as:Update", + "Video": "as:Video", + "View": "as:View", + "Listen": "as:Listen", + "Read": "as:Read", + "Move": "as:Move", + "Travel": "as:Travel", + "IsFollowing": "as:IsFollowing", + "IsFollowedBy": "as:IsFollowedBy", + "IsContact": "as:IsContact", + "IsMember": "as:IsMember", + "subject": { + "@id": "as:subject", + "@type": "@id" + }, + "relationship": { + "@id": "as:relationship", + "@type": "@id" + }, + "actor": { + "@id": "as:actor", + "@type": "@id" + }, + "attributedTo": { + "@id": "as:attributedTo", + "@type": "@id" + }, + "attachment": { + "@id": "as:attachment", + "@type": "@id" + }, + "bcc": { + "@id": "as:bcc", + "@type": "@id" + }, + "bto": { + "@id": "as:bto", + "@type": "@id" + }, + "cc": { + "@id": "as:cc", + "@type": "@id" + }, + "context": { + "@id": "as:context", + "@type": "@id" + }, + "current": { + "@id": "as:current", + "@type": "@id" + }, + "first": { + "@id": "as:first", + "@type": "@id" + }, + "generator": { + "@id": "as:generator", + "@type": "@id" + }, + "icon": { + "@id": "as:icon", + "@type": "@id" + }, + "image": { + "@id": "as:image", + "@type": "@id" + }, + "inReplyTo": { + "@id": "as:inReplyTo", + "@type": "@id" + }, + "items": { + "@id": "as:items", + "@type": "@id" + }, + "instrument": { + "@id": "as:instrument", + "@type": "@id" + }, + "orderedItems": { + "@id": "as:items", + "@type": "@id", + "@container": "@list" + }, + "last": { + "@id": "as:last", + "@type": "@id" + }, + "location": { + "@id": "as:location", + "@type": "@id" + }, + "next": { + "@id": "as:next", + "@type": "@id" + }, + "object": { + "@id": "as:object", + "@type": "@id" + }, + "oneOf": { + "@id": "as:oneOf", + "@type": "@id" + }, + "anyOf": { + "@id": "as:anyOf", + "@type": "@id" + }, + "closed": { + "@id": "as:closed", + "@type": "xsd:dateTime" + }, + "origin": { + "@id": "as:origin", + "@type": "@id" + }, + "accuracy": { + "@id": "as:accuracy", + "@type": "xsd:float" + }, + "prev": { + "@id": "as:prev", + "@type": "@id" + }, + "preview": { + "@id": "as:preview", + "@type": "@id" + }, + "replies": { + "@id": "as:replies", + "@type": "@id" + }, + "result": { + "@id": "as:result", + "@type": "@id" + }, + "audience": { + "@id": "as:audience", + "@type": "@id" + }, + "partOf": { + "@id": "as:partOf", + "@type": "@id" + }, + "tag": { + "@id": "as:tag", + "@type": "@id" + }, + "target": { + "@id": "as:target", + "@type": "@id" + }, + "to": { + "@id": "as:to", + "@type": "@id" + }, + "url": { + "@id": "as:url", + "@type": "@id" + }, + "altitude": { + "@id": "as:altitude", + "@type": "xsd:float" + }, + "content": "as:content", + "contentMap": { + "@id": "as:content", + "@container": "@language" + }, + "name": "as:name", + "nameMap": { + "@id": "as:name", + "@container": "@language" + }, + "duration": { + "@id": "as:duration", + "@type": "xsd:duration" + }, + "endTime": { + "@id": "as:endTime", + "@type": "xsd:dateTime" + }, + "height": { + "@id": "as:height", + "@type": "xsd:nonNegativeInteger" + }, + "href": { + "@id": "as:href", + "@type": "@id" + }, + "hreflang": "as:hreflang", + "latitude": { + "@id": "as:latitude", + "@type": "xsd:float" + }, + "longitude": { + "@id": "as:longitude", + "@type": "xsd:float" + }, + "mediaType": "as:mediaType", + "published": { + "@id": "as:published", + "@type": "xsd:dateTime" + }, + "radius": { + "@id": "as:radius", + "@type": "xsd:float" + }, + "rel": "as:rel", + "startIndex": { + "@id": "as:startIndex", + "@type": "xsd:nonNegativeInteger" + }, + "startTime": { + "@id": "as:startTime", + "@type": "xsd:dateTime" + }, + "summary": "as:summary", + "summaryMap": { + "@id": "as:summary", + "@container": "@language" + }, + "totalItems": { + "@id": "as:totalItems", + "@type": "xsd:nonNegativeInteger" + }, + "units": "as:units", + "updated": { + "@id": "as:updated", + "@type": "xsd:dateTime" + }, + "width": { + "@id": "as:width", + "@type": "xsd:nonNegativeInteger" + }, + "describes": { + "@id": "as:describes", + "@type": "@id" + }, + "formerType": { + "@id": "as:formerType", + "@type": "@id" + }, + "deleted": { + "@id": "as:deleted", + "@type": "xsd:dateTime" + }, + "inbox": { + "@id": "ldp:inbox", + "@type": "@id" + }, + "outbox": { + "@id": "as:outbox", + "@type": "@id" + }, + "following": { + "@id": "as:following", + "@type": "@id" + }, + "followers": { + "@id": "as:followers", + "@type": "@id" + }, + "streams": { + "@id": "as:streams", + "@type": "@id" + }, + "preferredUsername": "as:preferredUsername", + "endpoints": { + "@id": "as:endpoints", + "@type": "@id" + }, + "uploadMedia": { + "@id": "as:uploadMedia", + "@type": "@id" + }, + "proxyUrl": { + "@id": "as:proxyUrl", + "@type": "@id" + }, + "liked": { + "@id": "as:liked", + "@type": "@id" + }, + "oauthAuthorizationEndpoint": { + "@id": "as:oauthAuthorizationEndpoint", + "@type": "@id" + }, + "oauthTokenEndpoint": { + "@id": "as:oauthTokenEndpoint", + "@type": "@id" + }, + "provideClientKey": { + "@id": "as:provideClientKey", + "@type": "@id" + }, + "signClientKey": { + "@id": "as:signClientKey", + "@type": "@id" + }, + "sharedInbox": { + "@id": "as:sharedInbox", + "@type": "@id" + }, + "Public": { + "@id": "as:Public", + "@type": "@id" + }, + "source": "as:source", + "likes": { + "@id": "as:likes", + "@type": "@id" + }, + "shares": { + "@id": "as:shares", + "@type": "@id" + }, + "alsoKnownAs": { + "@id": "as:alsoKnownAs", + "@type": "@id" + } + } +} diff --git a/package.json b/package.json index 6ec541f..ac930c2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "koreografeye", "description": "A Solid choreography / orchestrator agent with a reasoning component", - "version": "0.4.1", + "version": "0.4.2", "homepage": "", "license": "MIT", "author": "Patrick Hochstenbach ", diff --git a/src/orch.ts b/src/orch.ts index a0b3937..57ca1f2 100755 --- a/src/orch.ts +++ b/src/orch.ts @@ -23,7 +23,7 @@ const POL_MAIN_SUBJECT = 'https://www.example.org/ns/policy#mainSubject'; const POL_ORIGIN = 'https://www.example.org/ns/policy#origin'; let orchConf = './config.jsonld'; -program.version('0.4.0') +program.version('0.4.2') .argument('') .option('-c,--config ','config file') .option('-i,--in ','input directory') diff --git a/src/pol.ts b/src/pol.ts index aad3faf..3c52ee1 100755 --- a/src/pol.ts +++ b/src/pol.ts @@ -16,7 +16,7 @@ import { ComponentsManager } from 'componentsjs'; let pluginConf = './config.jsonld'; -program.version('0.4.0') +program.version('0.4.2') .option('-c,--config ', 'configuration file') .option('-i,--in ','input directory') .option('-e,--err ','error directory') diff --git a/src/policy/plugin/SendNotificationPlugin.ts b/src/policy/plugin/SendNotificationPlugin.ts index 4bdb0c9..7bba524 100644 --- a/src/policy/plugin/SendNotificationPlugin.ts +++ b/src/policy/plugin/SendNotificationPlugin.ts @@ -9,11 +9,19 @@ import { import { PolicyPlugin , type IPolicyType } from '../PolicyPlugin'; export class SendNotificationPlugin extends PolicyPlugin { - context : string[]; + context : string[] = []; + context_cache : string | null = null; - constructor(context: string[]) { + constructor(context: string[], context_cache?: string) { super(); - this.context = context; + + if (context) { + this.context = context; + } + + if (context_cache) { + this.context_cache = context_cache; + } } public async execute(_: N3.Store, policyStore: N3.Store, policy: IPolicyType) : Promise { @@ -62,6 +70,7 @@ export class SendNotificationPlugin extends PolicyPlugin { "@context": this.context, "@id": uuid.value } + , this.context_cache ); this.logger.info(`Sending to ${thisTo.value} a ${json['type']}`); diff --git a/src/util.ts b/src/util.ts index 3c0a885..f19e274 100644 --- a/src/util.ts +++ b/src/util.ts @@ -131,12 +131,28 @@ export async function n3TransformStore(store: N3.Store): Promise { * * @param jsonstr - a JSON-LD string * @param frame - a JSON-LD frame object + * @param cache - an optional cached version of a JSON-LD frame * @returns The framed JSON */ -export async function jsonldStrFrame(jsonstr:string, frame: any): Promise { +export async function jsonldStrFrame(jsonstr:string, frame: any, cache: string|null = null): Promise { const doc = JSON.parse(jsonstr); - const framed = await jsonld.frame(doc, frame); + let framed; + let cached_frame; + if (cache && (cached_frame = readText(cache))) { + const parsed_cached_frame = JSON.parse(cached_frame); + const copy_frame = {...frame}; + copy_frame['@context'] = parsed_cached_frame['@context']; + framed = await jsonld.frame(doc, copy_frame); + + // Put the intented context back + if (frame['@context']) { + framed['@context'] = frame['@context']; + } + } + else { + framed = await jsonld.frame(doc, frame); + } return framed; }