node-exist
Mostly a shallow wrapper for eXist's XML-RPC API. Attempts to translate terminologies into node world. Uses promises.
Install
npm install @existdb/node-exist
Use
Creating, reading and removing a collection:
const exist = const db = exist dbcollections
Uploading an XML file into the database
const exist = const db = exist dbdocuments
Since all interactions with the database are promises you can also use async functions
const exist = const db = exist { const fileHandle = await dbdocuments await dbdocuments return filePath} // top-level await is not available everywhere, yet
You can also have a look at the examples for more use-cases.
Configuration
Connect as someone else than guest
exist
Connect to a local development server using HTTP
exist
Connect to a server with an invalid or expired certificate
exist
Defaults
host: 'localhost' port: '8443' path: '/exist/xmlrpc' // you most likely do not need to change that basic_auth: user: 'guest' pass: 'guest' secure: true
Components
The methods are grouped into components by what they operate on. Every method returns a promise.
Queries
Status: working
execute
dbqueries
read
dbqueries
readAll
This convenience function calls queries.count then retrieves all result pages and returns them in an array.
dbqueries
Example:
const query = `xquery version "3.1";xmldb:get-child-collections($collection) => string-join(",\n")`const options = variables: collection: "/db/apps" dbqueries
count
dbqueries
retrieve
dbqueries
retrieveAll
dbqueries
releaseResult
free result on server
dbqueries
Documents
A document can be seen as a file. It might be indexed if it's type is not binary.
upload
Resolves into a file handle which can then be used by db.documents.parseLocal
.
dbdocuments
parseLocal
dbdocuments
read
dbdocuments
remove
dbdocuments
Resources
Status: working
A resource is identified by its path in the database. Documents and collections are resources.
describe
dbresources
setPermissions
dbresources
getPermissions
dbresources
Collections
Status: working
create
dbcollections
remove
dbcollections
describe
dbcollections
read
dbcollections
App
Status: working
upload
After uploading a XAR you can install it
dbapp
Example:
const xarContents = fs dbapp
install
Install an uploaded XAR (this will call repo:install-and-deploy-from-db
).
For extra safety a previously installed version will be removed before
installing the new version.
Dependencies will be resolved from http://exist-db.org/exist/apps/public-repo
by default.
If you want to use a different repository provide the optional customPackageRepoUrl
.
dbapp
Example:
dbapp
Returns
"success": true "result": "update": false // true if a previous version was found "target": "/db/apps/test-app"
Error
"success": false "error": "code": "err:EXPATH00" "value": "Missing descriptor from package: /db/system/repo/test-app.xar"
remove
Uninstall and remove the application identified by its namespace URL.
If no app with packageUri
could be found then this counts as success.
dbapp
Example:
dbapp
Returns
success: true
Error
success: false error: Object | Error
Indices
Status: TODO
Users
Status: failing
byName
dbusers
list
dbusers
server
Status: working
syncToDisk
dbserver
shutdown
dbserver
Note: There is no way to bring it up again.
Test
All tests are in spec/tests and written for tape
npm test
Roadmap
- switch to use eXist-db's REST-API.
- refactor to ES6 modules
Compatibility
node-exist is tested to be compatible with eXist-db 4 and 5. It should be compatible with version 3, except XAR installation.
Disclaimer
Use at your own risk.
This software is safe for development. It may be used to work with a production instance, but think twice before your data is lost.