UNPKG

sparnatural

Version:

Visual client-side SPARQL query builder and knowledge graph exploration tool

82 lines 5.25 kB
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _SparnaturalAttributes_instances, _SparnaturalAttributes_read, _SparnaturalAttributes_parsePrefixes, _SparnaturalAttributes_isJSON; export class SparnaturalAttributes { constructor(element) { _SparnaturalAttributes_instances.add(this); this.typePredicate = "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>"; _SparnaturalAttributes_isJSON.set(this, (json) => { let is_json = true; //true at first // Check if config is given as JSON string or as URL try { JSON.parse(json); } catch (error) { is_json = false; } return is_json; }); // not the differences in attribute names this.src = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "src", __classPrivateFieldGet(this, _SparnaturalAttributes_isJSON, "f").call(this, element.getAttribute("src"))); if (!this.src) { throw Error("No src provided!"); } let endpointParam = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "endpoint"); this.endpoints = endpointParam.split(" "); if (!this.endpoints) { throw Error("No endpoint provided!"); } this.catalog = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "catalog"); this.language = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "lang"); this.defaultLanguage = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "defaultLang"); // use the singular to match RDFa attribute name this.sparqlPrefixes = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_parsePrefixes).call(this, element); this.addDistinct = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "distinct", true); this.limit = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "limit", true); this.typePredicate = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "typePredicate"); this.maxDepth = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "maxDepth"); this.maxOr = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "maxOr"); this.localCacheDataTtl = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "localCacheDataTtl", true); this.debug = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "debug", true); this.submitButton = __classPrivateFieldGet(this, _SparnaturalAttributes_instances, "m", _SparnaturalAttributes_read).call(this, element, "submitButton", true); } } _SparnaturalAttributes_isJSON = new WeakMap(), _SparnaturalAttributes_instances = new WeakSet(), _SparnaturalAttributes_read = function _SparnaturalAttributes_read(element, attribute, asJson = false) { return element.getAttribute(attribute) ? asJson ? JSON.parse(element.getAttribute(attribute)) : element.getAttribute(attribute) : undefined; }, _SparnaturalAttributes_parsePrefixes = function _SparnaturalAttributes_parsePrefixes(element) { if (!element.getAttribute("prefixes")) { return; } let sparqlPrefixes = {}; // use the singular to match RDFa attribute name let prefixArray = element .getAttribute("prefixes") .trim() .split(/:\s+|\s+/); for (let i = 0; i < prefixArray.length; i++) { try { const prefixPair = { prefix: prefixArray[i].split(":")[0], iri: prefixArray[i].split(":").slice(1).join(":"), }; Object.defineProperty(sparqlPrefixes, prefixPair.prefix, { value: prefixPair.iri, writable: true, enumerable: true, }); } catch (e) { console.error("Parsing of attribute prefixes failed!"); console.error(`Can not parse ${prefixArray[i]}`); } } return sparqlPrefixes; }; //# sourceMappingURL=SparnaturalAttributes.js.map