diffusion
Version:
Diffusion JavaScript client
98 lines (97 loc) • 3.76 kB
JavaScript
;
/**
* @module TopicUpdate
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.PendingValidateStream = void 0;
var errors_1 = require("./../../errors/errors");
var invalid_unset_stream_1 = require("./../topic-update/invalid-unset-stream");
var pending_validate_and_set_stream_1 = require("./../topic-update/pending-validate-and-set-stream");
var validated_stream_1 = require("./../topic-update/validated-stream");
var topic_update_1 = require("../../topic-update/topic-update");
/**
* An update stream delegate that is used when a {@link validate} operation is called
* on a new stream. The server has not yet responded to the initial validate
* operation.
*/
var PendingValidateStream = /** @class */ (function () {
/**
* Create a new PendingValidateStream instance
*
* @param streamServices the stream services
* @param options the update stream options
* @param stream the stream that using this stream as a delegate
* @param pendingResult the pending result
*/
function PendingValidateStream(streamServices, options, stream, pendingResult) {
this.streamServices = streamServices;
this.options = options;
this.stream = stream;
this.pendingResult = pendingResult;
}
/**
* @inheritdoc
*/
PendingValidateStream.prototype.set = function (value) {
var _this = this;
this.options.checkOperation(value);
return new Promise(function (resolve, reject) {
_this.stream.setDelegate(new pending_validate_and_set_stream_1.PendingValidateAndSetStream(_this.streamServices, _this.options, _this.stream, _this.pendingResult, { value: value, resolve: resolve, reject: reject }, value));
});
};
/**
* @inheritdoc
*/
PendingValidateStream.prototype.get = function () {
throw new errors_1.IllegalStateError('The set method has not been called');
};
/**
* @inheritdoc
*/
PendingValidateStream.prototype.validate = function () {
var _this = this;
return new Promise(function (resolve, reject) {
_this.pendingResult.then(function (r) {
resolve(topic_update_1.TopicCreationResult.EXISTS);
return r;
}, function (err) {
reject(err);
});
});
};
/**
* @inheritdoc
*/
PendingValidateStream.prototype.onSetComplete = function () {
throw new errors_1.IllegalStateError('No set request has been sent');
};
/**
* @inheritdoc
*/
PendingValidateStream.prototype.onSetFailed = function () {
throw new errors_1.IllegalStateError('No set request has been sent');
};
/**
* @inheritdoc
*/
PendingValidateStream.prototype.onValidateComplete = function (streamId, retainsValue, supportsConflation) {
var _this = this;
this.options.retainsValue = retainsValue;
this.options.supportsConflation = supportsConflation;
if (!retainsValue) {
this.options.toBuffer = function (oldValue, newValue) {
return _this.options.dataType.toBytes(newValue).asArray();
};
this.options.deltaService = this.streamServices.STREAM_SET_TOPIC_SERVICE;
}
this.stream.setDelegate(new validated_stream_1.ValidatedStream(this.streamServices, this.options, this.stream, streamId));
};
/**
* @inheritdoc
*/
PendingValidateStream.prototype.onValidateFailed = function (err) {
this.stream.setDelegate(new invalid_unset_stream_1.InvalidUnsetStream(err));
};
return PendingValidateStream;
}());
exports.PendingValidateStream = PendingValidateStream;