UNPKG

@dbp-topics/check-in

Version:

[GitLab Repository](https://gitlab.tugraz.at/dbp/check-in/checkin) | [npmjs package](https://www.npmjs.com/package/@dbp-topics/check-in) | [Unpkg CDN](https://unpkg.com/browse/@dbp-topics/check-in/) | [Checkin Bundle](https://gitlab.tugraz.at/dbp/check-in

28 lines (27 loc) 4.58 kB
/*! * License: LGPL-2.1-or-later * Dependencies: * * @webcomponents/scoped-custom-element-registry: 0.0.5 (BSD-3-Clause) * @dbp-toolkit/app-shell: 0.3.3 (LGPL-2.1-or-later) * @dbp-toolkit/language-select: 0.3.1 (LGPL-2.1-or-later) * @dbp-toolkit/common: 0.3.4 (LGPL-2.1-or-later) * @dbp-toolkit/auth: 0.3.1 (LGPL-2.1-or-later) * event-target-shim: 6.0.2 (MIT) * @dbp-toolkit/notification: 0.3.1 (LGPL-2.1-or-later) * @dbp-toolkit/theme-switcher: 0.0.5 (LGPL-2.1-or-later) * path-to-regexp: 6.2.0 (MIT) * universal-router: 9.1.0 (MIT) * generateUrls: 9.1.0 (MIT) * @dbp-toolkit/matomo: 0.2.6 (LGPL-2.1-or-later) * @tugraz/web-components: 0.3.6 (LGPL-2.1-or-later) * @babel/runtime: 7.18.9 (MIT) * i18next: 21.9.1 (MIT) * @lit/reactive-element: 1.4.1 (BSD-3-Clause) * lit-html: 2.3.1 (BSD-3-Clause) * lit-element: 3.2.2 (BSD-3-Clause) * @open-wc/dedupe-mixin: 1.3.1 (MIT) * @open-wc/scoped-elements: 2.1.3 (MIT) */ import{m as t,p as e,n,s as i}from"./notification.d05eb818.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 t of s.successFunctions[e])"function"==typeof t&&t(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.ff6a7155.es.js.map