UNPKG

diffusion

Version:

Diffusion JavaScript client

73 lines (72 loc) 2.93 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.FullPathSelector = 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 full path selectors */ var FullPathSelector = /** @class */ (function (_super) { __extends(FullPathSelector, _super); /** * Create a new FullPathSelector instance * * @param components the path components as created by the parser */ function FullPathSelector(components) { var _this = _super.call(this, components.type, components.prefix, components.expression) || this; /** * A regular expression matcher that checks if a canonical path selects this * path */ _this.pattern = undefined; _this.qualifier = components.qualifier; if (!components.base) { throw new errors_1.IllegalArgumentError('Invalid full-path selector'); } _this.base = components.base; return _this; } /** * @inheritdoc */ FullPathSelector.prototype.doSelects = function (topicPath) { if (!this.pattern) { switch (this.qualifier) { case topic_path_utils_1.DescendantQualifier.DESCENDANTS_OF_MATCH: this.pattern = regex_1.regex(this.base + "/.+"); break; case topic_path_utils_1.DescendantQualifier.MATCH_AND_DESCENDANTS: this.pattern = regex_1.regex(this.base + "(?:$|/.+)"); break; default: case topic_path_utils_1.DescendantQualifier.MATCH: this.pattern = regex_1.regex(this.base); break; } } return this.pattern(topicPath) === true; }; return FullPathSelector; }(abstract_topic_selector_1.AbstractTopicSelector)); exports.FullPathSelector = FullPathSelector;