1.0.5 • Published 11 months ago

@mysa/messaging-bus-cbm v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

Cloud Bus Message - Interfaces, Generator and Validator

This package contains interfaces that belong to cloud bus message. It also contains a generator and a validator. The generator is responsible to generate the CBM base message. The validator on the other hand validates whether the message follows the interface it should follow. This includes validating optional arguments, base message and details of the message.

Usage

Currently you can import the following interfaces:

CBMOptionalArgs: Interface for optional arguments of cbm CBMv1: Interface for version 1 of cloud base message CBMBase: Base interface for cloud base message DetailBase: Base interface for detail property of cbm DetailsBody: Interface of different type of detail body joined by OR operator DevicesPairedDetailsBody: Interface of the body of devices paired detail DevicesPairedDetails: Interface consisting of the body of devices paired detail and the detail type SetpointChangesDetailsBody: Interface of the body of setpoint changes detail SetpointChangesDetails: Interface consisting of the body of setpoint changes detail and the detail type TelemetryDetailsBody: Interface of the body of telemetry detail TelemetryDetails: Interface consisting of the body of telemetry detail and the detail type UserSignupDetailsBody: Interface of the body of user signup detail UserSignupDetails Interface consisting of the body of user signup detail and the detail type Details: Interfaces for different types of details joined by OR operator

import { generateCBMv1, validateCBM } from '@mysa/messaging-bus-cbm';

const details: Details = {
    detailType: // detail type
    detail: {
        // body of the detail
    }
};

const optionalArgs: CBMOptionalArgs = {
    // optional fields and their values
};

// to generate cbmV1
// CBM generated through the generator does not need to call the validator separately
// calling the generator calls the validator from within.
// the generator either returns the cbm or throws an error if something goes wrong during the validation process.
const cbm = generateCBMv1(details, optionalArgs);
if(cbm){

}
else {
    // an error has occurred during the validation
}

// to call validator function separetely
const validation = validateCBM(cbm);
if(validation.success){
    // if validation succeeded
}
else {
    console.log(validation.errorMsg);
}
1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

12 months ago