anchor.diff:  (in-package :cldm-registry.model)
  +
   
   (defun create-library (&key name
   			 description
  
positive.code: (defun find-library-by-name (name)
    (first (docs (db.find "libraries" (kv "name" name)))))
  
  (defun create-library-version (&key library
  				 version
  				 repositories)
  
negative.code:   (let ((repo (make-document)))
      (add-element "name" (cldm::name repository) repo)
      (add-element "address" (cldm::unparse (cldm::repository-address repository)))
      repo))
  
  
  (defun publish (cldm-library)
    (let ((stored-library (find-library-by-name (cldm::library-name cldm-library))))
      (if stored-library
  	(let ((cldm-library-version (first (cldm::library-versions cldm-library)))
  	      (library-versions (library-versions stored-library)))
  	  ;; If the library version to publish already exists, or is inferior
  	  ;; to the currently published one, error
  	  (if (or (member (cldm::version cldm-library-version) library-versions
  			  :key #'library-version-version
  			  :test #'semver:version=)
  		  (semver:version< (cldm::version cldm-library-version)
  				   (library-version-version (first library-versions))))
  	      (error "Invalid version ~A" cldm-library-version))
  	  ;; Update the current library
  	  (add-element  (description stored-library)
  		(cldm::library-description cldm-library))
  	  (setf (cld stored-library) (cldm::library-cld cldm-library))
  	  (setf (licence stored-library) (cldm::library-licence cldm-library))
  	  (setf (keywords stored-library) (cldm::library-keywords cldm-library)))
  	;; else, create the library
  	(let ((library (make-instance 'library 
  				      :name (cldm::library-name cldm-library)
  				      :cld (cldm::library-cld cldm-library)
  				      :description (cldm::library-description cldm-library)
  				      :keywords (cldm::library-keywords cldm-library)
  				      :licence (cldm::library-licence cldm-library))))
  	  (store library)
  	  (let* ((cldm-library-version (first (cldm::library-versions cldm-library)))
  		 (library-version (make-instance 'library-version
  						 :library library
  						 :libraryid (id library)
  						 :description (cldm::description cldm-library-version)
  						 :stability (cldm::stability cldm-library-version)
  						 :version (cldm::version cldm-library-version)
  						 :repositories (cldm::repositories cldm-library-version))))
  	    (store library-version))))))
  				 
  			 
  