4.2.0 • Published 7 years ago

cogs-pubsub-dialect v4.2.0

Weekly downloads
5
License
BSD-3-Clause
Repository
github
Last release
7 years ago

Cogswell Pub-Sub Dialect

This package is a collection of JavaScript object validators to validate cogswell pub-sub request/response objects. This package uses the Joi library for validation.

Pub/Sub JSON Dialect

The dialect definition can be found at the Pub/Sub Dialect page.

Usage

const validators = require('cogs-pubsub-dialect');

const exampleObject = {
  sequence: 12345,
  code: 404,
  message: 'Not Found',
  details: 'There are no subscribers to the specified channel, so the message could not be delivered.'
}

//without callback
const result = validators.validate(exampleObject, validators.publish.noSubscriptionsError);
result == {err: null, value: exampleObject}; //true

//with callback
const result = validators.validate(exampleObject, validators.publish.noSubscriptionsError, function(err, value) {
  err == null; //true
  //value will not necessarily equal the original object, for example, if Joi validates a date,
  //it will also parse it into a JS date object
});

//the validate function is a direct alias to Joi's validate therefore you can do this (or the callback version):
const result = Joi.validate(exampleObject, validators.publish.noSubscriptionsError);
result == {err: null, value: exampleObject}; //true

Validators

Use the following validators to validate their respective objects

  • general

    • catchAllError
    • invalidFormatError
  • subscribe

    • directive
    • success
    • incorrectPermissionsError
  • unsubscribe

    • directive
    • success
    • incorrectPermissionsError
    • notFoundError
  • publish

    • directive
    • incorrectPermissionsError
    • noSubscriptionsError
  • message

Testing

To run the unit tests, run the following command

npm test
4.2.0

7 years ago

4.1.0

7 years ago

4.0.0

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago