default

A JavaScript library that web pages should import in order to use the Qworum features of web browsers.

Examples

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:

try{
  await Qworum.checkAvailability();
}catch(error){
  console.error('Install the Qworum browser extension or enable it.');
}

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:

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

Reading/writing data from within web pages:

let data = await Qworum.getData(['path', 'to', 'data']);

if(!data) {
  data = Json('some data');
  await Qworum.setData(['path', 'to', 'data'], data);
}

data.value === "some data"; // true

Classes

c
Call

Call instructions in a Qworum script starts a new Qworum method call when evaluated by the Qworum interpreter in a web browser.

c
Data

A container for data (Json or SemanticData).

c
Fault

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()
c
Goto

Goto instructions are used in Qworum scripts for starting a new phase in the current Qworum method call.

c
Json

In-memory JSON data. Can be stored in Data containers.

c
Qworum

Web pages can use the Qworum capabilities of web browsers through this JavaScript class.

c
Return

Return instructions end the current Qworum method call in a Qworum script.

c
Script

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.

c
SemanticData

In-memory RDF dataset. Conformant with RDF 1.1, RDF-Star and the RDF/JS Dataset interface. Can be stored in Data containers.

c
Sequence

A sequence of instructions and/or data values (Json or SemanticData) in a Qworum script.

c
Try

Try instructions are used for catching faults that may be raised when the browser's Qworum interpreter executes a Qworum script.

Variables

v
IRI

A class that represents an IRI. IRL and URN have this class as their parent class.

v
iri

A string-to-IRI converter. Returns null if the string is not an IRI.

v
IRL

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.

v
irl

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.

v
rdfTermFactory

A JavaScript object that contains factory functions for different types of RDF terms, such as namedNode and literal

v
url

A string-to-URL converter. Returns null if the string is not a URL.

v
URN

A class that represents a URN.

v
urn

A string-to-URN converter. Returns null if the string is not a URN.