npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-exist

v0.5.0

Published

Node module providing promisified API to interact with eXist-db's REST API

Downloads

15

Readme

Easy-Exist

Node module providing promisified API to interact with eXist-db's REST API.

Code Example

var exist = require('easy-exist');

// connect
var db = new exist.DB('http://localhost', {
    username: "test-user",
    password: "password"
});

body = '<message><body>Hello World</body></message>'

// PUT a document
db.put('/my-collection/my-document', body)

    // Get the body of a document
    .then(function() {
        return db.get('/my-collection/my-document');
    })
    .then(function(doc) {
        console.log('Document Body:', doc);
    })

    // Execute xQuery
    .then(function() {
        return db.query('collection("my-collection")/message/body');
    })
    .then(function(result) {
        console.log('xQuery result:', result);
    })

    // Delete document
    .then(function() {
        return db.delete('/my-collection/my-document');
    })
    .then(function() {
        console.log('Document Deleted');
    });

Installation

Install via NPM

npm install easy-exist --save

Then require

var exist = require('easy-exist');

API

new exist.DB(url, options)

Parameters
  • url - string
  • options - object - configuration options
Options

The options object supports the following properties:

  • username - string - Username for HTTP Basic Auth
  • password - string - Password for HTTP Basic Auth
  • collection - string - Name of collection under which all subsequent requests will apply to

.put(uri, body)

Stores an XML document at the given URI.

Parameters
  • uri - string - the URI at which to store the given body
  • body - string - the document body
Returns

A request-promise Promise. If a non-2xx response is returned, the promise is rejected.


.get(uri)

Retrieves the body of the document at the given URI.

Parameters
  • uri - string - the URI of the document to fetch
Returns

A request-promise Promise. If a non-2xx response is returned, the promise is rejected, otherwise it is resolved with the body of the specified document.


.delete(uri)

Deletes the document at the given URI.

Parameters
  • uri - string - the URI of the document to delete
Returns

A request-promise Promise. If a non-2xx response is returned, the promise is rejected.


.query(query, options)

Executes given query against store and returns result

Parameters
  • query - string - xQuery to execute agains the store
  • options - object - Query options
Options

The options object supports the following properties:

  • start - integer - Specifies the index position of the first item in the result sequence to be returned. The default value is 1
  • max - integer - The maximum number of items to be returned
  • wrap - string - (yes|no) - Specifies whether the returned query results are to be wrapped into a surrounding exist:result element. The default value is yes
Returns

A request-promise Promise. If a non-2xx response is returned, the promise is rejected, otherwise it is resolved with the xQuery result.


.storeQuery(uri, query)

Stores the given xQuery at the specified URI

Parameters
  • uri - string - the URI at which to store the given xQuery
  • query - string - the xQuery body
Returns

A request-promise Promise. If a non-2xx response is returned, the promise is rejected.


.executeStoredQuery(uri)

Executes the xQuery stored at the given URI and returns the results.

Syntactic Sugar. This function simply calls through to .get(uri)

Parameters
  • uri - string - the URI of the xQuery to execute
Returns

A request-promise Promise. If a non-2xx response is returned, the promise is rejected, otherwise it is resolved with the result of executing the specified specified xQuery.


.exists(uri)

Determines if a document exists at the given URI

Parameters
  • uri - string - the URI of the document to check
Returns

A Promise. Resolves with true if a document exists at the given uri, false if it does not. If a non 2xx and non 404 status code is returned, the promise is rejected.


Contributing

  1. Fork the project.
  2. Create your branch
  3. Make your changes with tests
    1. Run tests: grunt test
    2. Run hint: grunt hint
  4. Create a Pull Request

Test setup

The tests run against a local exist-db instance under a "test-user" account. If you want to run the tests yourself, ensure that this test-user account has been created. You can update the connection properties in spec/lib/db-spec.js

var DB_HOST = 'http://localhost';
// ...
var db = new DB(DB_HOST, { username: 'test-user', password: 'password'} );