UNPKG

diffusion

Version:

Diffusion JavaScript client

87 lines (86 loc) 3.36 kB
"use strict"; /** * @module Topics */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.SplitPathSelector = void 0; var errors_1 = require("./../../errors/errors"); var abstract_topic_selector_1 = require("./../topics/abstract-topic-selector"); var topic_path_utils_1 = require("./../topics/topic-path-utils"); var regex_1 = require("./../util/regex"); /** * Implementation of {@link AbstractTopicSelector} for split path selectors */ var SplitPathSelector = /** @class */ (function (_super) { __extends(SplitPathSelector, _super); /** * Create a new SplitPathSelector instance * * @param components the path components as created by the parser */ function SplitPathSelector(components) { var _this = _super.call(this, components.type, components.prefix, components.expression) || this; /** * An array of regular expression matchers, one for each part of the path */ _this.patterns = undefined; _this.qualifier = components.qualifier; _this.parts = topic_path_utils_1.split(components.base); _this.parts.forEach(function (part) { if (!part) { throw new errors_1.IllegalArgumentError('Invalid split-path selector'); } }); return _this; } /** * @inheritdoc */ SplitPathSelector.prototype.doSelects = function (topicPath) { if (!this.patterns) { this.patterns = this.parts.map(function (p) { return regex_1.regex(p); }); } var length = this.patterns.length; var parts = topicPath.split(topic_path_utils_1.PATH_SEPARATOR); switch (this.qualifier) { case topic_path_utils_1.DescendantQualifier.MATCH: if (parts.length !== length) { return false; } break; case topic_path_utils_1.DescendantQualifier.DESCENDANTS_OF_MATCH: if (parts.length <= length) { return false; } break; case topic_path_utils_1.DescendantQualifier.MATCH_AND_DESCENDANTS: if (parts.length < length) { return false; } break; } for (var i = 0; i < length; ++i) { if (!this.patterns[i](parts[i])) { return false; } } return true; }; return SplitPathSelector; }(abstract_topic_selector_1.AbstractTopicSelector)); exports.SplitPathSelector = SplitPathSelector;