src/type-registry.js
/**
 * Adds an RDF class to a user's type index registry, and returns the
 * profile (with the appropriate type registry index updated).
 * Called by `registerTypeIndex()`, which does all the argument validation.
 * @method addToTypeIndex
 * @param profile {SolidProfile} User's WebID profile
 * @param rdfClass {NamedNode} RDF type to register in the index.
 * @param location {String} Absolute URI to the location you want the class
 *   registered to.
 * @param locationType {String} Either 'instance' or 'container'
 * @param isListed {Boolean} Whether to register in a listed or unlisted index).
 * @return {Promise<SolidProfile>}
 */
Adds an RDF class to a user's type index registry, and returns the
profile (with the appropriate type registry index updated).
Called by `registerTypeIndex()`, which does all the argument validation.
@method addToTypeIndex
@param profile {SolidProfile} User's WebID profile
@param rdfClass {NamedNode} RDF type to register in the index.
@param location {String} Absolute URI to the location you want the class
registered to.
@param locationType {String} Either 'instance' or 'container'
@param isListed {Boolean} Whether to register in a listed or unlisted index).
@return {Promise}
Adds an RDF class to a user ' s type index registry and returns the profile ( with the appropriate type registry index updated ) . Called by ` registerTypeIndex () ` which does all the argument validation . @method addToTypeIndex @param profile { SolidProfile } User ' s WebID profile @param rdfClass { NamedNode } RDF type to register in the index . @param location { String } Absolute URI to the location you want the class registered to . @param locationType { String } Either ' instance ' or ' container ' @param isListed { Boolean } Whether to register in a listed or unlisted index ) . @return { Promise }
function addToTypeIndex (profile, rdfClass, location, webClient,
                         locationType, isListed) {
  var hash = require('shorthash')
  var rdf = webClient.rdf
  var ns = vocab(rdf)
  var fragmentId = hash.unique(rdfClass.uri)
  var registryUri
  var registryGraph
  if (isListed) {
    registryUri = profile.typeIndexListed.uri
    registryGraph = profile.typeIndexListed.graph
  } else {
    registryUri = profile.typeIndexUnlisted.uri
    registryGraph = profile.typeIndexUnlisted.graph
  }
  if (!registryUri) {
    throw new Error('Cannot register type, registry URL missing')
  }
  var registrationUri = rdf.namedNode(registryUri + '#' + fragmentId)
  var locationTypeClass
  if (locationType === 'instance') {
    locationTypeClass = ns.solid('instance')
  } else {
    locationTypeClass = ns.solid('instanceContainer')
    if (location.lastIndexOf('/') !== location.length - 1) {
      location += '/'
    }
  }
  var toDel = []
  var toAdd = [
    rdf.triple(registrationUri, ns.rdf('type'), ns.solid('TypeRegistration')),
    rdf.triple(registrationUri, ns.solid('forClass'), rdfClass),
    rdf.triple(registrationUri, locationTypeClass, rdf.namedNode(location))
  ]
  return webClient.patch(registryUri, toDel, toAdd)
    .then(function (response) {
      var newRegistration = graphUtil.graphFromStatements(toAdd, rdf)
      if (registryGraph) {
        graphUtil.appendGraph(registryGraph, newRegistration)
      } else {
        profile[isListed ? 'typeIndexListed' : 'typeIndexUnlisted'].graph = newRegistration
      }
      return profile
    })
}
function addToTypeIndex ( profile , rdfClass , location , webClient , locationType , isListed ) { var hash = require ( 'shorthash' ) var rdf = webClient . rdf var ns = vocab ( rdf ) var fragmentId = hash . unique ( rdfClass . uri ) var registryUri var registryGraph if ( isListed ) { registryUri = profile . typeIndexListed . uri registryGraph = profile . typeIndexListed . graph } else { registryUri = profile . typeIndexUnlisted . uri registryGraph = profile . typeIndexUnlisted . graph } if ( ! registryUri ) { throw new Error ( 'Cannot register type, registry URL missing' ) } var registrationUri = rdf . namedNode ( registryUri + '#' + fragmentId ) var locationTypeClass if ( locationType === 'instance' ) { locationTypeClass = ns . solid ( 'instance' ) } else { locationTypeClass = ns . solid ( 'instanceContainer' ) if ( location . lastIndexOf ( '/' ) !== location . length - 1 ) { location += '/' } } var toDel = [ ] var toAdd = [ rdf . triple ( registrationUri , ns . rdf ( 'type' ) , ns . solid ( 'TypeRegistration' ) ) , rdf . triple ( registrationUri , ns . solid ( 'forClass' ) , rdfClass ) , rdf . triple ( registrationUri , locationTypeClass , rdf . namedNode ( location ) ) ] return webClient . patch ( registryUri , toDel , toAdd ) . then ( function ( response ) { var newRegistration = graphUtil . graphFromStatements ( toAdd , rdf ) if ( registryGraph ) { graphUtil . appendGraph ( registryGraph , newRegistration ) } else { profile [ isListed ? 'typeIndexListed' : 'typeIndexUnlisted' ] . graph = newRegistration } return profile } ) }
Adds an RDF class to a user's type index registry, and returns the
 profile (with the appropriate type registry index updated).
Adds an RDF class to a user ' s type index registry and returns the profile ( with the appropriate type registry index updated ) .
// TODO: Check to see if a registry entry for this type already exists. // Generate a fragment identifier for the new registration // Set the class for the location type // Add trailing slash if it's missing and is a container // triples to delete (none for the moment) // Create the list of triples to add in the PATCH operation // example: '<#ab09fd> a solid:TypeRegistration;' // example: 'solid:forClass sioc:Post;' // example: 'solid:instanceContainer </posts/>.' // Update the profile object with the new registry without reloading