UNPKG

diffusion

Version:

Diffusion JavaScript client

118 lines (117 loc) 4.57 kB
"use strict"; /** * @module TopicViews */ Object.defineProperty(exports, "__esModule", { value: true }); exports.TopicViewsImpl = void 0; var errors_1 = require("./../../errors/errors"); var Services = require("./../services/topic-views-services"); var named_topic_view_specification_1 = require("./../services/topic-views/named-topic-view-specification"); var logger = require("./../util/logger"); var require_non_null_1 = require("./../util/require-non-null"); var response_success_1 = require("./../util/response-success"); var log = logger.create('TopicViews'); /** * Implementation of the {@link TopicView} feature */ var TopicViewsImpl = /** @class */ (function () { /** * Create a new instance of the TopicView feature * * @param internal the internal session */ function TopicViewsImpl(internal) { this.internal = internal; var serviceLocator = internal.getServiceLocator(); this.CREATE_TOPIC_VIEW = serviceLocator.obtain(Services.CREATE_TOPIC_VIEW); this.LIST_TOPIC_VIEWS = serviceLocator.obtain(Services.LIST_TOPIC_VIEWS); this.GET_TOPIC_VIEW = serviceLocator.obtain(Services.GET_TOPIC_VIEW); this.REMOVE_TOPIC_VIEW = serviceLocator.obtain(Services.REMOVE_TOPIC_VIEW); } /** * @inheritdoc */ TopicViewsImpl.prototype.createTopicView = function (name, specification) { var _this = this; return new Promise(function (resolve, reject) { if (require_non_null_1.requireNonNull(name, 'name').length === 0) { throw new errors_1.IllegalArgumentError("Topic View name cannot be empty"); } if (_this.internal.checkConnected(reject)) { var spec = new named_topic_view_specification_1.NamedTopicViewSpecification(name, require_non_null_1.requireNonNull(specification, 'specification')); _this.CREATE_TOPIC_VIEW.send(spec, function (err, response) { if (!response_success_1.responseSuccess(err, response)) { reject(err); log.debug('Create topic view failed'); } else if (response.errors) { reject(response.errors.errors); log.debug('Create topic view failed'); } else { resolve(response.view); } }); } }); }; /** * @inheritdoc */ TopicViewsImpl.prototype.listTopicViews = function () { var _this = this; return new Promise(function (resolve, reject) { if (_this.internal.checkConnected(reject)) { _this.LIST_TOPIC_VIEWS.send(null, function (err, response) { if (!response_success_1.responseSuccess(err, response)) { reject(err); log.debug('List topic views failed'); } else { resolve(response.result); } }); } }); }; /** * @inheritdoc */ TopicViewsImpl.prototype.getTopicView = function (name) { var _this = this; return new Promise(function (resolve, reject) { if (_this.internal.checkConnected(reject)) { _this.GET_TOPIC_VIEW.send(require_non_null_1.requireNonNull(name, 'name'), function (err, response) { if (!response_success_1.responseSuccess(err, response)) { reject(err); log.debug('Get topic view failed'); } else { resolve(response.result); } }); } }); }; /** * @inheritdoc */ TopicViewsImpl.prototype.removeTopicView = function (name) { var _this = this; return new Promise(function (resolve, reject) { if (_this.internal.checkConnected(reject)) { _this.REMOVE_TOPIC_VIEW.send(require_non_null_1.requireNonNull(name, 'name'), function (err) { if (err) { reject(err); log.debug('Remove topic view failed'); } else { resolve(); } }); } }); }; return TopicViewsImpl; }()); exports.TopicViewsImpl = TopicViewsImpl;