src/type-registry.js
/**
 * Removes an RDF class from a user's type index registry.
 * Called by `unregisterTypeIndex()`, which does all the argument validation.
 * @param profile {SolidProfile} User's WebID profile
 * @param rdfClass {NamedNode} Type to remove from the registry
 * @param webClient {SolidWebClient}
 * @param [isListed=false] {Boolean} Whether to remove from a listed or
 *   unlisted index
 * @param [location] {String} If present, only unregister the class from this
 *   location (absolute URI).
 * @return {Promise<SolidProfile>}
 */
Removes an RDF class from a user's type index registry.
Called by `unregisterTypeIndex()`, which does all the argument validation.
Removes an RDF class from a user ' s type index registry . Called by ` unregisterTypeIndex () ` which does all the argument validation .
function removeFromTypeIndex (profile, rdfClass, webClient, isListed,
                              location) {
  var rdf = webClient.rdf
  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 unregister type, registry URL missing')
  }
  var registrations = registrationsFromGraph(registryGraph, rdfClass,
    isListed, rdf)
  if (registrations.length === 0) {
    return Promise.resolve(profile)
  }
  if (location) {
    registrations = registrations.filter(function (registration) {
      return registration.locationUri === location
    })
  }
  var toDel = []
  registrations.forEach(function (registration) {
    registryGraph.statementsMatching(rdf.namedNode(registration.registrationUri))
      .forEach(function (statement) {
        toDel.push(statement)
      })
  })
  var toAdd = []
  return webClient.patch(registryUri, toDel, toAdd)
    .then(function (result) {
      return profile.reloadTypeRegistry(webClient)
    })
}
function removeFromTypeIndex ( profile , rdfClass , webClient , isListed , location ) { var rdf = webClient . rdf 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 unregister type, registry URL missing' ) } var registrations = registrationsFromGraph ( registryGraph , rdfClass , isListed , rdf ) if ( registrations . length === 0 ) { return Promise . resolve ( profile ) } if ( location ) { registrations = registrations . filter ( function ( registration ) { return registration . locationUri === location } ) } var toDel = [ ] registrations . forEach ( function ( registration ) { registryGraph . statementsMatching ( rdf . namedNode ( registration . registrationUri ) ) . forEach ( function ( statement ) { toDel . push ( statement ) } ) } ) var toAdd = [ ] return webClient . patch ( registryUri , toDel , toAdd ) . then ( function ( result ) { return profile . reloadTypeRegistry ( webClient ) } ) }
Removes an RDF class from a user's type index registry.
Removes an RDF class from a user ' s type index registry .
// Get the existing registrations // No existing registrations, no need to do anything, just return profile // If location is present, filter the to-remove list only to registrations // that are in that location. // Generate triples to delete // Nothing to add // Update the registry, to reflect new state