A JavaScript library that web pages should import in order to use the Qworum features of web browsers.
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);
Call instructions in a Qworum script starts a new Qworum method call when evaluated by the Qworum interpreter in a web browser.
-
build()object,href,parameters,objectParameters
Builder for Call instructions.
- href()
- object()
- objectParameters()
- parameters()
-
toString()
Serialises the object to string for informational purposes.
A container for data (Json or SemanticData).
-
build()path,statement
Builder for Data instructions.
- path()
-
toString()
Serialises the object to string for informational purposes.
Exceptions that disrupt the execution flow are called faults on Qworum. They are used in Qworum scripts.
-
build(type)
Builder for Fault instructions. Suitable for service-specific faults only.
-
toString()
Serialises the object to string for informational purposes.
- type()
Goto instructions are used in Qworum scripts for starting a new phase in the current Qworum method call.
-
build(href)
Builder for Goto instructions.
- fromJsonable(encoded)
- href()
-
toString()
Serialises the object to string for informational purposes.
In-memory JSON data. Can be stored in Data containers.
-
build(value)
Builder for Json data values.
-
toString()
Serialises the object to string for informational purposes.
- value()
Web pages can use the Qworum capabilities of web browsers through this JavaScript class.
-
checkAvailability()
Checks that:
-
eval(script)
Evaluates a Qworum script.
-
getData(path)
Reads a value contained in a data container.
-
setData()path,value
Sets the value contained in a data container.
Return instructions end the current Qworum method call in a Qworum script.
-
build(statement)
Builder for Return instructions.
-
toString()
Serialises the object to string for informational purposes.
The Qworum platform uses scripts as its linking mechanism. This is much more suitable for application use cases than simple URLs. Websites ask web browsers to execute Qworum scripts for navigation.
-
build(instruction)
Builder for Qworum scripts.
- instruction()
-
toString()
Serialises the object to string for informational purposes.
In-memory RDF dataset. Conformant with RDF 1.1, RDF-Star and the RDF/JS Dataset interface. Can be stored in Data containers.
-
build()
Builder for semantic data values.
-
readFromText()text,baseIRI
Async RDF dataset reader.
-
readFromUrl(url)
Async RDF dataset reader.
-
toRawString(type)
RDF dataset serialiser.
-
toString()
Serialises the object to string for informational purposes.
-
value()
An in-memory RDF dataset that is conformant with the Dataset specification.
A sequence of instructions and/or data values (Json or SemanticData) in a Qworum script.
-
build(...statements)
Builder for Sequence instructions.
- statements()
-
toString()
Serialises the object to string for informational purposes.
Try instructions are used for catching faults that may be raised when the browser's Qworum interpreter executes a Qworum script.
-
build()statement,catchClauses
Builder function for Try instructions.
-
toString()
Serialises the object to string for informational purposes.
A class that represents an IRI. IRL and URN have this class as their parent class.
A string-to-IRI converter. Returns null if the string is not an IRI.
A class that represents a IRL. An IRL is a non-standard yet useful way of representing URLs in Unicode. IRI is IRL's parent class.
A string-to-IRL converter. Returns null if the string is not a IRL. An IRL is a non-standard yet useful way of representing URLs in Unicode.
A JavaScript object for easily importing all script-related classes in one go. Note that those classes can also be imported individually.
A JavaScript object that contains factory functions for different types of RDF terms, such as namedNode and literal
A string-to-URL converter. Returns null if the string is not a URL.
A class that represents a URN.
A string-to-URN converter. Returns null if the string is not a URN.