@dbp-topics/sublibrary
Version:
[GitLab Repository](https://github.com/digital-blueprint/sublibrary-app) | [npmjs package](https://www.npmjs.com/package/@dbp-topics/sublibrary) | [Unpkg CDN](https://unpkg.com/browse/@dbp-topics/sublibrary/) | [Sublibrary Bundle](https://gitlab.tugraz.at
150 lines (149 loc) • 5.38 kB
JavaScript
/*!
* License: LGPL-2.1-or-later
* Dependencies:
*
* @dbp-toolkit/common: LGPL-2.1-or-later
* jquery: MIT
* select2: MIT
* @dbp-toolkit/resource-select: LGPL-2.1-or-later
* @babel/runtime: MIT
* i18next: MIT
* @lit/reactive-element: BSD-3-Clause
* lit-html: BSD-3-Clause
* lit-element: BSD-3-Clause
* @open-wc/dedupe-mixin: MIT
* @open-wc/scoped-elements: MIT
* datatables.net: MIT
* datatables.net-responsive: MIT
* datatables.net-responsive-dt: MIT
* datatables.net-dt: MIT
* jszip: (MIT OR GPL-3.0-or-later)
* datatables.net-buttons-dt: MIT
* datatables.net-buttons: MIT
* @dbp-toolkit/data-table-view: LGPL-2.1-or-later
* @dbp-toolkit/person-select: LGPL-2.1-or-later
*/
import { h as t, v as e, w as n, s as i } from "./_commonjsHelpers.01af1198.es.js";
class s {
constructor(t, e) {
this.entities = e, this.baseApiUrl = t;
let n = {};
for (const _t in e) {
n[e[_t]["@id"]] = _t;
}
this.idToEntityNameMatchList = n;
}
static async getInstance(t, e = "de") {
let n = s.promises[t];
return void 0 === n && (n = new Promise((n, i) => {
s._initialize(t, t => n(t), t => i(t), e);
}), s.promises[t] = n), n;
}
static initialize(t, e, n, i = "de") {
console.warn("DEPRECATED: JSONLD.initialize(), use JSONLD.getInstance() instead"), s._initialize(t, e, n, i);
}
static doInitializationOnce(t) {
console.warn("DEPRECATED: JSONLD.doInitializationOnce() calls can be removed");
}
static _initialize(t, e, n, i = "de") {
s._i18n.changeLanguage(i), void 0 === s.instances[t] ? (void 0 === s.successFunctions[t] && (s.successFunctions[t] = []), void 0 === s.failureFunctions[t] && (s.failureFunctions[t] = []), "function" == typeof e && s.successFunctions[t].push(e), "function" == typeof n && s.failureFunctions[t].push(n), t && void 0 === s.initStarted[t] && (s.initStarted[t] = !0, s._doInitialization(t))) : "function" == typeof e && e(s.instances[t]);
}
static _doInitialization(t) {
const n = new XMLHttpRequest(),
i = s._i18n;
n.open("GET", t, !0), n.onreadystatechange = function () {
if (4 === n.readyState) if (200 === n.status) {
const o = JSON.parse(n.responseText);
let r = {};
for (let t in o) t.startsWith("@") || (r[t.toLowerCase()] = o[t]);
const a = e(this.getResponseHeader("link"))["http://www.w3.org/ns/hydra/core#apiDocumentation"];
if (void 0 !== a) {
const e = new XMLHttpRequest();
e.open("GET", a, !0), e.setRequestHeader("Content-Type", "application/json"), e.onreadystatechange = function () {
4 === e.readyState && (200 === e.status ? s._gatherEntities(e, t, r) : s._executeFailureFunctions(t, i.t("jsonld.api-documentation-server", {
apiUrl: a
})));
}, e.send();
} else s._executeFailureFunctions(t, i.t("jsonld.error-hydra-documentation-url-not-set", {
apiUrl: t
}));
} else s._executeFailureFunctions(t, i.t("jsonld.error-api-server", {
apiUrl: t
}));
}, n.send();
}
static _gatherEntities(t, e, i) {
const o = JSON.parse(t.responseText)["hydra:supportedClass"];
let r = {};
const a = n(e);
o.forEach(function (t) {
const e = t["hydra:title"];
let n = i[e.toLowerCase()];
void 0 === n || n.startsWith("http") || (n = a + n), t["@entryPoint"] = n, r[e] = t;
});
const c = new s(a, r);
if (s.instances[e] = c, void 0 !== s.successFunctions[e]) for (const _t2 of s.successFunctions[e]) "function" == typeof _t2 && _t2(c);
s.successFunctions[e] = [];
}
static _executeFailureFunctions(t, e = "") {
const n = s._i18n;
if (void 0 !== s.failureFunctions[t]) for (const _n of s.failureFunctions[t]) "function" == typeof _n && _n(new Error(e));
s.failureFunctions[t] = [], "" !== e && i({
summary: n.t("error.summary"),
body: e,
type: "danger"
});
}
getEntityForIdentifier(t) {
let e = this.getEntityNameForIdentifier(t);
return this.getEntityForEntityName(e);
}
getEntityForEntityName(t) {
return this.entities[t];
}
getApiUrlForEntityName(t) {
const e = this.getEntityForEntityName(t);
if (void 0 === e || void 0 === e["@entryPoint"]) throw new Error(`Entity "${t}" not found!`);
return e["@entryPoint"];
}
getEntityNameForIdentifier(t) {
return this.idToEntityNameMatchList[t];
}
getApiIdentifierList() {
let t = [];
for (const e in this.idToEntityNameMatchList) t.push(e);
return t;
}
expandMember(t, e) {
void 0 === e && (e = t["@context"]);
let n = {
"@id": t["@id"]
};
for (const i of Object.keys(e)) {
const s = e[i];
void 0 !== t[i] && (n[s] = t[i]);
}
return n;
}
compactMember(t, e) {
let n = {};
for (const i in e) {
const s = t[e[i]];
void 0 !== s && (n[i] = s);
}
return n;
}
transformMembers(t, e) {
const n = t["hydra:member"];
if (void 0 === n || 0 === n.length) return [];
const i = t["@context"];
let s = [],
o = this;
return n.forEach(function (t) {
s.push(o.compactMember(o.expandMember(t, i), e));
}), s;
}
}
s._i18n = t(), s.instances = {}, s.successFunctions = {}, s.failureFunctions = {}, s.initStarted = {}, s.promises = {};
export { s as J };
//# sourceMappingURL=jsonld.3c83677b.es.js.map