A JavaScript library that web pages should import in order to use the Qworum features of web browsers.
This library contains:
-
Classes for creating Qworum scripts —
Json,SemanticData,Return,Sequence,Data,Try,Goto,Call,Fault,Script. -
The
Qworumclass, for executing Qworum scripts, reading and writing session data, and checking that a browser provides Qworum capabilities.
This library will only work for websites that are part of Qworum's Service Web, which requires a subscription.
Importing this library into a web page:
Importing this library into a web page:
import { // For using the browsers' Qworum features Qworum, // For creating Qworum scripts and session data QworumScript as qs, // For manipulating semantic RDF data in scripts and session data iri, irl, url, urn, IRI, IRL, URN, rdfTermFactory } from 'https://esm.sh/gh/doga/qworum-for-web-pages@1.8.4/mod.mjs'; const // Shortcuts for building Qworum scripts and session data Json = qs.Json.build, SemanticData = qs.SemanticData.build, Return = qs.Return.build, Sequence = qs.Sequence.build, Data = qs.Data.build, Try = qs.Try.build, Goto = qs.Goto.build, Call = qs.Call.build, Fault = qs.Fault.build, Script = qs.Script.build;
Checking that Qworum is enabled in the Web browser:
Checking that Qworum is enabled in the Web browser:
try{ await Qworum.checkAvailability(); }catch(error){ console.error('Install the Qworum browser extension or enable it.'); }
Running a simple Qworum script:
Running a simple Qworum script:
await Qworum.eval( Script( Sequence( // Call a method of the current Qworum object Call('@', `../view-item`, { name: 'item id', value: Json(1) }), // Return to the current page in the current call Goto() ), ) ) );
Running a more complex Qworum script:
Running a more complex Qworum script:
const pathOfQworumObject = ['@', 'a qworum object'], script = Script( Try( Sequence( // Initialise the Qworum object ? (May be required for Qworum classes that have instance properties) Try( // If the state of the Qworum object is readable, then the object exists. Data([...pathOfQworumObject, 'version']), { catch: '* reference', do: // the Qworum object does not exist; initialise it Call( pathOfQworumObject, 'https://a-qworum-service.example/a-qworum-class/new/', { name: 'initial state', value: Json({state: {xyz: '…'}}) } ) } ), // Call the `edit` method of the Qworum object. Call(pathOfQworumObject, 'https://a-qworum-service.example/a-qworum-class/edit/'), // If the call to `edit` hasn't raised a fault, then the caller resumes its execution here. Goto('group-updated.html') ), { do: // If the call to `edit` has raised a fault, then go back to the current web page. Goto() } ) ); // Run the Qworum script in the web page. The end-user will experience this as a redirection. await Qworum.eval(script);