diffusion
Version:
Diffusion JavaScript client
67 lines (65 loc) • 2.62 kB
JavaScript
var _interface = require('util/interface')._interface;
/**
* {@link diffusion.datatypes.RecordV2} structural delta.
* <p>
* A RecordV2Delta describes the differences between two {@link diffusion.datatypes.RecordV2}
* values. Unlike a {@link diffusion.datatypes.BinaryDelta binary delta}, a structural delta
* can be queried to determine its effect. The
* {@link diffusion.datatypes.RecordV2Delta#changes} method provides details of which values
* have changed.
*
* <p>
* An instance can be created from two RecordV2 values using
* {@link diffusion.datatypes.RecordV2#diff(RecordV2)}.
*
* <p>
* RecordV2Deltas are useful for identifying small changes to complex RecordV2
* values. Here's any example of how to use this class to filter interesting
* changes from a value stream.
* <pre>
* var datatype = diffusion.datatypes.recordv2();
*
* session.subscribe("topic").asType(datatype).on('value', (path, spec, newValue, oldValue) => {
* var schema = datatype.parseSchema(spec.properties.SCHEMA);
*
* newValue.diff(oldValue).changes(schema).forEach((change) => {
* if (change.fieldName === "address") {
* // Do something with the changed address
* console.log(newValue.getFields());
* }
* });
* });
* </pre>
*
* @author Push Technology Limited
* @since 6.0
* @see diffusion.datatypes.RecordV2#diff
* @class diffusion.datatypes.RecordV2Delta
* @since 6.0
*/
module.exports = _interface('RecordV2Delta', [
/**
* Returns a list of the changes represented by the delta with reference to
* a specified schema.
* <P>
* The schema supplied must comply with the data format of the delta. No
* validation takes place, so if the schema does not match the data then the
* results may be unpredictable.
*
* @param {diffusion.datatypes.RecordV2.Schema} schema - the schema
* @return {Array<diffusion.datatypes.RecordV2Delta.Change>} the list of changes
*/
'changes'
]);
/**
* Represents a single change to a Record value.
*
* @typedef diffusion.datatypes.RecordV2Delta.Change
* @property {String} recordName - The name of the affected record
* @property {Number} recordIndex - The index of the affected record
* @property {String} fieldName - The name of the affected field
* @property {Number} fieldIndex - The index of the affected field
* @property {String} key - Returns the string key representation of the affected item in
* the form recordName(recordIndex).fieldName(fieldIndex).
* @property {String} type - String denoting the type of change that this represents
*/