mftsccs-node 0.0.79-dev → 0.0.80-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{ALLID:()=>ji,AccessControlService:()=>bi,AddGhostConcept:()=>jo,AddGhostConnection:()=>Wo,BaseUrl:()=>n,BinaryTree:()=>G,CCSConfig:()=>hi,Composition:()=>yo,CompositionBinaryTree:()=>lo,CompositionNode:()=>so,Concept:()=>F,ConceptsData:()=>M,Connection:()=>ee,ConnectionData:()=>se,CreateComposition:()=>Ut,CreateConnection:()=>Tt,CreateConnectionBetweenTwoConcepts:()=>tn,CreateConnectionBetweenTwoConceptsGeneral:()=>on,CreateDefaultConcept:()=>b,CreateDefaultLConcept:()=>hn,CreateSession:()=>Ro,CreateSessionVisit:()=>Uo,CreateTheCompositionWithCache:()=>vo,CreateTheConnectionGeneral:()=>mt,CreateTypeConcept:()=>sn,DATAID:()=>Oi,DATAIDDATE:()=>Mi,DATAV2:()=>Ji,DeleteConceptById:()=>Pn,DeleteConnectionById:()=>Ot,DeleteConnectionByIdBulk:()=>Vt,DeleteConnectionByTypeBulk:()=>ri,FilterSearch:()=>li,FormatFromConnections:()=>Qo,FreeSchemaResponse:()=>K,FreeschemaQuery:()=>ar,GetAllConnectionsOfComposition:()=>we,GetAllConnectionsOfCompositionBulk:()=>ve,GetAllTheConnectionsByTypeAndOfTheConcept:()=>dr,GetComposition:()=>Ae,GetCompositionBulk:()=>Hn,GetCompositionBulkWithDataId:()=>jn,GetCompositionFromConnectionsWithDataId:()=>Wn,GetCompositionFromConnectionsWithDataIdInObject:()=>qn,GetCompositionList:()=>$e,GetCompositionListWithId:()=>Oe,GetCompositionWithAllIds:()=>ke,GetCompositionWithCache:()=>Ao,GetCompositionWithDataIdBulk:()=>xo,GetCompositionWithDataIdWithCache:()=>So,GetCompositionWithId:()=>Ue,GetCompositionWithIdFromMemory:()=>xe,GetCompositionWithIdFromMemoryFromConnections:()=>Re,GetConceptBulk:()=>le,GetConceptByCharacter:()=>be,GetConceptByCharacterAndCategoryDirectApi:()=>He,GetConceptByCharacterAndType:()=>Nt,GetConceptByTypeBulk:()=>At,GetConnectionBulk:()=>Vn,GetConnectionById:()=>Dt,GetConnectionByTypeBulk:()=>ci,GetConnectionOfTheConcept:()=>Lt,GetConnectionsBetweenApi:()=>fr,GetLink:()=>ln,GetLinkRaw:()=>dn,GetLinkerConnectionFromConcepts:()=>Rn,GetLinkerConnectionToConcepts:()=>En,GetRelation:()=>Go,GetRelationRaw:()=>Fo,GetRequestHeader:()=>q,GetRequestHeaderWithAuthorization:()=>z,GetTheConcept:()=>Ht,GetUserGhostConnectionId:()=>Ho,GetUserGhostId:()=>Mo,GiveConnection:()=>ur,HandleHttpError:()=>Q,HttpResponse:()=>l,JUSTDATA:()=>Vi,LConcept:()=>un,LConnection:()=>Do,LISTNORMAL:()=>Wi,LoginToBackend:()=>Yn,MakeTheInstanceConcept:()=>Rt,MakeTheTimestamp:()=>Dn,MakeTheTypeConcept:()=>Nn,MakeTheTypeConceptApi:()=>Ke,NORMAL:()=>$i,PatcherStructure:()=>si,PermissionSet:()=>Li,RAW:()=>Hi,RecursiveSearchApi:()=>Kn,ReservedConnectionIds:()=>at,ReservedIds:()=>st,SchemaQueryListener:()=>sr,SearchAllConcepts:()=>To,SearchLinkInternal:()=>oi,SearchLinkMultipleAll:()=>Ko,SearchLinkMultipleApi:()=>qo,SearchQuery:()=>$n,SearchStructure:()=>di,SearchWithLinker:()=>Io,SessionData:()=>ai,Signin:()=>to,Signup:()=>Zn,SplitStrings:()=>W,SyncData:()=>vt,TokenRefreshError:()=>a,TokenStorage:()=>o,Transaction:()=>vr,TrashTheConcept:()=>Fn,UpdateComposition:()=>Co,UserBinaryTree:()=>Oo,ViewInternalData:()=>Zo,buildFetchConnection:()=>yr,convertFromLConceptToConcept:()=>ei,deleteWithRetry:()=>v,fetchWithCacheServerFallback:()=>T,fetchWithRetry:()=>h,getFromDatabaseWithType:()=>S,getFromDatabaseWithTypeOld:()=>x,getOAuthToken:()=>r,getWithRetry:()=>y,init:()=>mr,patchWithRetry:()=>g,postWithRetry:()=>f,putWithRetry:()=>p,recursiveFetch:()=>Be,recursiveFetchNew:()=>ho,refreshOAuthToken:()=>c,requestWithRetry:()=>u,storeToDatabase:()=>k,updateAccessToken:()=>Cr});class n{static setNodeCacheUrl(e=""){this.NODE_CACHE_URL=e,this.isNearestCache=!0}static setCacheServers(e=[]){this.CACHE_SERVERS=e.filter((e=>"string"==typeof e&&""!==e.trim())),this.NODE_CACHE_URL=this.CACHE_SERVERS.length>0?this.CACHE_SERVERS[0]:"",this.isNearestCache=!0}static GetReadBaseUrl(){return this.NODE_CACHE_URL&&""!==this.NODE_CACHE_URL.trim()?this.NODE_CACHE_URL:this.BASE_URL}static GetNodeBaseUrl(){return this.NODE_URL&&""!==this.NODE_URL.trim()?this.NODE_URL:this.BASE_URL}static GetReadBaseUrlCandidates(){const e=[this.NODE_CACHE_URL,...this.CACHE_SERVERS,this.GetNodeBaseUrl(),this.BASE_URL].filter((e=>"string"==typeof e&&""!==e.trim())).map((e=>e.trim()));return Array.from(new Set(e))}static GetConceptUrl(){return this.BASE_URL+"/api/getConcept"}static GetConnectionUrl(){return this.BASE_URL+"/api/get-connection-by-id"}static GetConceptBulkUrl(){return this.GetNodeBaseUrl()+"/api/get_concept_bulk"}static GetConnectionBulkUrl(){return this.GetNodeBaseUrl()+"/api/get_connection_bulk"}static GetAllConceptsOfUserUrl(){return this.BASE_URL+"/api/get_all_concepts_of_user"}static GetAllConnectionsOfUserUrl(){return this.BASE_URL+"/api/get_all_connections_of_user"}static GetConnectionsBetweenUrl(){return this.BASE_URL+"/api/get-connection-between"}static GetAllConnectionsOfCompositionUrl(){return this.BASE_URL+"/api/get_all_connections_of_composition"}static GetAllConnectionsOfCompositionBulkUrl(){return this.BASE_URL+"/api/get_all_connections_of_composition_bulk"}static GetConceptByCharacterValueUrl(){return this.BASE_URL+"/api/get_concept_by_character_value"}static GetConceptByCharacterAndTypeUrl(){return this.BASE_URL+"/api/get_concept_by_character_and_type"}static GetConceptByCharacterAndCategoryUrl(){return this.BASE_URL+"/api/get_concept_by_character_and_category"}static GetConceptByCharacterAndCategoryDirectUrl(){return this.BASE_URL+"/api/get_concept_by_character_and_category_direct"}static GetCharacterByCharacterUrl(){return this.BASE_URL+"/api/get_character_by_character"}static GetAllConceptsByTypeUrl(){return this.BASE_URL+"/api/get_all_concepts_by_type"}static GetAllConnectionsOfConceptUrl(){return this.BASE_URL+"/api/get-link-connections"}static GetAllConnectionsToConceptUrl(){return this.BASE_URL+"/api/get-link-reverse-connections"}static GetAllAiData(){return this.BASE_URL+"/api/get-preloaded-concepts"}static GetAllPrefetchConnectionsUrl(){return this.BASE_URL+"/api/get_all_connections_of_user?inpage=500"}static GetAllLinkerConnectionOfConceptUrl(){return this.BASE_URL+"/api/get-all-linkers-from-concept"}static GetAllLinkerConnectionToConceptUrl(){return this.BASE_URL+"/api/get-all-linkers-to-concept"}static DeleteConceptUrl(){return this.BASE_URL+"/api/delete_concept"}static RecursiveSearchUrl(){return this.BASE_URL+"/api/recursivesearch-concept-connection"}static SearchLinkMultipleAllApiUrl(){return this.BASE_URL+"/api/Connection/search-link-multiple-all-ccs"}static MakeTheNameInBackendUrl(){return this.BASE_URL+"/api/make-name-from-frontend"}static LoginUrl(){return this.BASE_URL+"/api/auth/login"}static SignupUrl(){return this.BASE_URL+"/api/auth/signup"}static GetCompositionConnectionBetweenTwoConceptsUrl(){return this.BASE_URL+"/api/get-composition-connection-between-two-concepts"}static SearchCompositionsUrl(){return this.BASE_URL+"/api/search-compositions"}static SearchLinkMultipleAll(){return this.BASE_URL+"/api/Connection/search-link-multiple-all"}static CreateSessionId(){return this.BASE_URL+"/api/create-session-id-remote"}static CreateSessionVisitUrl(){return this.BASE_URL+"/api/create-remote-session-visit"}static ViewInternalDataUrl(){return this.BASE_URL+"/api/view-api-internal-data-ccs-id-bulk"}static SearchInternalWithAuthenticatedCcsUrl(){return this.BASE_URL+"/api/search-composition-internal-authenticated-ccs"}static GetReservedIdUrl(){return this.BASE_URL+"/api/get_reserved_ids"}static GetReservedConnectionIdUrl(){return this.BASE_URL+"/api/get_reserved_connection_ids"}static CreateTheTextDataUrl(){return this.BASE_URL+"/api/create_text_data"}static CreateTheCharacterDataUrl(){return this.BASE_URL+"/api/create_character_data"}static CreateTheConceptUrl(){return this.BASE_URL+"/api/create_the_concept"}static CreateTheConnectionUrl(){return this.BASE_URL+"/api/create_the_connection"}static CreateTheConnectionNewUrl(){return this.BASE_URL+"/api/create_the_connection_new"}static MakeTheTypeConceptUrl(){return this.BASE_URL+"/api/make_the_type_concept"}static CreateTypeConceptUrl(){return this.BASE_URL+"/api/create_type_concept"}static DeleteTheConnectionUrl(){return this.BASE_URL+"/api/delete_connection"}static DeleteTheConnectionBulkUrl(){return this.BASE_URL+"/api/delete_connection_bulk"}static FreeschemaQueryUrl(){return this.BASE_URL+"/api/freeschema-query"}static GetConceptConnectionByType(){return this.BASE_URL+"/api/get_type_concept_by_character_bulk"}static OAuthTokenUrl(){return this.BASE_URL+"/api/oauth/token"}static OAuthRefreshUrl(){return this.BASE_URL+"/api/oauth/refresh"}}n.BASE_URL="https://localhost:7053/",n.NODE_CACHE_URL="",n.CACHE_SERVERS=[],n.isNearestCache=!0,n.AI_URL="https://ai.freeschema.com",n.MQTT_URL="192.168.1.249",n.NODE_URL="";class o{static getAuthHeader(){return this.BearerAccessToken?{Authorization:`Bearer ${this.BearerAccessToken}`}:{}}static setToken(e,t){this.BearerAccessToken=e,this.TOKEN_EXPIRY=t&&t>0?Date.now()+1e3*t:Date.now()+36e5}static isTokenExpiredOrNearExpiry(){return!!this.TOKEN_EXPIRY&&Date.now()>=this.TOKEN_EXPIRY-this.EXPIRY_BUFFER_MS}static getTimeUntilExpiry(){if(!this.TOKEN_EXPIRY)return-1;const e=Date.now(),t=this.TOKEN_EXPIRY-e;return t>0?Math.floor(t/1e3):-1}static hasOAuthCredentials(){return!!(this.CLIENT_ID&&this.CLIENT_SECRET&&this.APPLICATION_NAME)}static setOAuthCredentials(e,t,n){this.CLIENT_ID=e,this.CLIENT_SECRET=t,this.APPLICATION_NAME=n}}o.BearerAccessToken="",o.CLIENT_ID="",o.CLIENT_SECRET="",o.APPLICATION_NAME="",o.TOKEN_EXPIRY=0,o.EXPIRY_BUFFER_MS=3e5;var i=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function r(e,t,r){return i(this,arguments,void 0,(function*(e,t,i,r=!0){try{const c=n.OAuthTokenUrl(),s=new URLSearchParams;s.append("client_id",e),s.append("client_secret",t),s.append("application_name",i);const a=yield fetch(c,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s.toString()});if(a.ok){let e="",t="Bearer",n=0;const i=a.headers.get("content-type");if(i&&i.includes("application/json"))try{const o=yield a.json();e=o.access_token||"",t=o.token_type||"Bearer",n=o.expires_in||0}catch(t){e=yield a.text()}else e=yield a.text();return e?(r&&o.setToken(e,n),{success:!0,access_token:e,token_type:t,expires_in:n}):{success:!1,error:"No access token in response"}}{const e=yield a.text();return{success:!1,error:`HTTP ${a.status}: ${e}`}}}catch(e){return e instanceof TypeError?{success:!1,error:`Network error: ${e.message}`}:{success:!1,error:`Unexpected error: ${e instanceof Error?e.message:String(e)}`}}}))}function c(e,t,r){return i(this,arguments,void 0,(function*(e,t,i,r=!0){try{const c=n.OAuthRefreshUrl(),s=new URLSearchParams;s.append("client_id",e),s.append("client_secret",t),s.append("refresh_token",i),s.append("grant_type","refresh_token");const a=yield fetch(c,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s.toString()});if(a.ok){let e="",t="Bearer",n=0;const i=a.headers.get("content-type");if(i&&i.includes("application/json"))try{const o=yield a.json();e=o.access_token||"",t=o.token_type||"Bearer",n=o.expires_in||0}catch(t){e=yield a.text()}else e=yield a.text();return e?(r&&o.setToken(e,n),{success:!0,access_token:e,token_type:t,expires_in:n}):{success:!1,error:"No access token in response"}}{const e=yield a.text();return{success:!1,error:`HTTP ${a.status}: ${e}`}}}catch(e){return e instanceof TypeError?{success:!1,error:`Network error: ${e.message}`}:{success:!1,error:`Unexpected error: ${e instanceof Error?e.message:String(e)}`}}}))}var s=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class a extends Error{constructor(e){super(e),this.name="TokenRefreshError"}}class l{constructor(e,t,n){this.status=e,this.body=t,this.headers=n}json(){return s(this,void 0,void 0,(function*(){return JSON.parse(this.body)}))}text(){return s(this,void 0,void 0,(function*(){return this.body}))}get ok(){return this.status>=200&&this.status<300}}function d(){return s(this,void 0,void 0,(function*(){if(!o.hasOAuthCredentials())return!1;try{return(yield r(o.CLIENT_ID,o.CLIENT_SECRET,o.APPLICATION_NAME,!0)).success}catch(e){return console.error("Token refresh failed:",e),!1}}))}function u(e,t,n,i){return s(this,arguments,void 0,(function*(e,t,n,i,r=1){var c,s;const u=Object.assign(Object.assign({},n),o.getAuthHeader()),h=["GET","HEAD","OPTIONS"].includes(e.toUpperCase());for(let n=0;n<=r;n++)try{const h={method:e,headers:u};void 0!==i&&("object"==typeof i?(u["Content-Type"]||u["content-type"]||(u["Content-Type"]="application/json"),(null===(c=u["Content-Type"])||void 0===c?void 0:c.includes("application/json"))||(null===(s=u["content-type"])||void 0===s?void 0:s.includes("application/json"))?h.body=JSON.stringify(i):h.body=i):h.body=i),h.headers=u;const f=yield fetch(t,h),y=yield f.text(),p={};if(f.headers.forEach(((e,t)=>{p[t]=e})),401!==f.status)return new l(f.status,y,p);if(n<r){if(yield d()){Object.assign(u,o.getAuthHeader());continue}throw new a("Token refresh failed. Please check OAuth credentials.")}return new l(f.status,y,p)}catch(e){if(e instanceof a)throw e;if(n>=r||!h)throw e;console.error(`Request failed (attempt ${n+1}/${r+1}):`,e)}throw new Error("Request failed after all retry attempts")}))}function h(e){return s(this,arguments,void 0,(function*(e,t={},n=1){return u(t.method||"GET",e,function(e){if(e){if(e instanceof Headers){const t={};return e.forEach(((e,n)=>{t[n]=e})),t}return Array.isArray(e)?e.reduce(((e,[t,n])=>(e[t]=n,e)),{}):e}}(t.headers),t.body,n)}))}function f(e,t,n){return s(this,void 0,void 0,(function*(){return u("POST",e,t,n)}))}function y(e,t,n){return s(this,void 0,void 0,(function*(){let o=e;if(n){const t=[];for(const e in n)n.hasOwnProperty(e)&&t.push(`${encodeURIComponent(e)}=${encodeURIComponent(String(n[e]))}`);t.length>0&&(o=`${e}?${t.join("&")}`)}return u("GET",o,t)}))}function p(e,t,n){return s(this,void 0,void 0,(function*(){return u("PUT",e,t,n)}))}function v(e,t){return s(this,void 0,void 0,(function*(){return u("DELETE",e,t)}))}function g(e,t,n){return s(this,void 0,void 0,(function*(){return u("PATCH",e,t,n)}))}var C=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function m(e,t){return`${e.replace(/\/+$/,"")}${t}`}function T(e){return C(this,arguments,void 0,(function*(e,t={},o=1){const i=n.GetReadBaseUrlCandidates();let r;for(const c of i){try{const i=yield h(m(c,e),t,o);if(c.replace(/\/+$/,"")===n.BASE_URL.replace(/\/+$/,""))return i;if(i.ok)return n.NODE_CACHE_URL=c,i;r=new Error(`Cache server ${c} returned status ${i.status}`)}catch(e){r=e}n.isNearestCache=!1}throw r instanceof Error?r:new Error("All cache servers failed")}))}class w{constructor(e){this.id=1,this.isOnlineSync=!1,this.isOnlineSync=e}}var I=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const N={};function A(e){return N[e]||(N[e]=[]),N[e]}function k(e,t){const n=A(e);if(t&&"number"==typeof t.id){const e=n.findIndex((e=>e&&e.id===t.id));if(e>=0)return void(n[e]=t)}n.push(t)}function S(e,t,n){return I(this,void 0,void 0,(function*(){return A(e).filter((e=>e&&e[t]===n))}))}function x(e){return I(this,void 0,void 0,(function*(){return A(e).slice()}))}function _(e,t){const n=A(e),o=n.findIndex((e=>e&&e.id===t));o>=0&&n.splice(o,1)}function R(e){return I(this,void 0,void 0,(function*(){return A(e).slice()}))}class E{}E.isTypeLoaded=!1,E.isCharacterLoaded=!1,E.isDataLoaded=!1,E.isLocalDataLoaded=!1,E.isLocalCharacterLoaded=!1,E.isLocalTypeLoaded=!1,E.isConnectionLoaded=!1,E.isConnectionTypeLoaded=!1,E.isLocalConnectionLoaded=!1;class U{constructor(e,t,n,o){this.variants=[],this.height=1,this.key=e,this.value=t,this.leftNode=n,this.rightNode=o,this.currentNode=null}addCurrentNode(e,t){return null==t?t=e:(e.value.typeId!=t.value.typeId&&(t.currentNode=this.addCurrentNode(e,t.currentNode)),t)}addCurrentNodeType(e,t){if(null==t)return e;var n=!1;for(let o=0;o<t.variants.length;o++)t.variants[o].value.id==e.value.id&&(n=!0);return n||t.variants.push(e),t}addNode(e,t,n){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addNode(e,o,n);else{if(!(t.key<e.key))return t;t.rightNode=this.addNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}return t}addCharacterNode(e,t,n){if(""!=e.value.characterValue){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addCharacterNode(e,o,n);else{if(!(t.key<e.key))return t.key==e.key&&""!=t.key&&t.value.id!=e.value.id&&t.addCurrentNodeType(e,t),t;t.rightNode=this.addCharacterNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}}return t}addTypeNode(e,t,n){if(0!=e.value.typeId){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addTypeNode(e,o,n);else{if(!(t.key<e.key))return t.key==e.key&&0!=t.key&&t.value.id!=e.value.id&&t.addCurrentNodeType(e,t),t;t.rightNode=this.addTypeNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}}return t}rightRotate(e){if(e){let t=e.leftNode;if(t){let n=t.rightNode;return e.leftNode=n,t.rightNode=e,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}leftRotate(e){if(e){let t=e.rightNode;if(t){let n=t.leftNode;return t.leftNode=e,e.rightNode=n,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}getHeight(e){return e?e.height:0}getBalanceFactor(e){return null==e?0:this.getHeight(e.leftNode)-this.getHeight(e.rightNode)}getFromNode(e,t){return t?e==t.key?t:e<t.key?this.getFromNode(e,t.leftNode):e>t.key?this.getFromNode(e,t.rightNode):t:t}getCharacterFromNode(e,t){return t?e==t.key?t:e<t.key?this.getCharacterFromNode(e,t.leftNode):e>t.key?this.getCharacterFromNode(e,t.rightNode):t:t}getCharacterFromNodeUpdated(e,t){var n;return t?e==t.key||51==(null===(n=t.value)||void 0===n?void 0:n.typeId)?t:e<t.key?this.getCharacterFromNode(e,t.leftNode):e>t.key?this.getCharacterFromNode(e,t.rightNode):t:t}getFromNodeWithCharacterAndType(e,t,n){if(e=`${e}`,n){if(e==n.key){if(e==n.value.characterValue&&t==n.value.typeId)return n;for(let e=0;e<n.variants.length;e++)if(n.variants[e].value.typeId==t)return n.variants[e]}else{if(e<n.key)return this.getFromNodeWithCharacterAndType(e,t,n.leftNode);if(e>n.key)return this.getFromNodeWithCharacterAndType(e,t,n.rightNode)}return null}return n}getFromNodeWithCharacterAndCategory(e,t,n){if(e=`${e}`,n){if(e==n.key){if(e==n.value.characterValue&&t==n.value.categoryId)return n;for(let e=0;e<n.variants.length;e++)if(n.variants[e].value.categoryId==t)return n.variants[e]}else{if(e<n.key)return this.getFromNodeWithCharacterAndCategory(e,t,n.leftNode);if(e>n.key)return this.getFromNodeWithCharacterAndCategory(e,t,n.rightNode)}return null}return n}removeNode(e,t){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNode(e.leftNode,t),e;if(e.key<t)return e.rightNode=this.removeNode(e.rightNode,t),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var n=this.inOrderSuccessor(e.rightNode);return e.value=n.value,e.key=n.key,e.variants=n.variants,e.currentNode=n.currentNode,e.rightNode=this.removeNode(e.rightNode,n.key),e}removeNodeWithVariants(e,t,n){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNodeWithVariants(e.leftNode,t,n),e;if(e.key<t)return e.rightNode=this.removeNodeWithVariants(e.rightNode,t,n),e;if(e.variants.length>0)if(e.value.id==n){var o=e.variants[0];if(o)return e.value=o.value,e.key=o.key,e.currentNode=o.currentNode,e.variants.splice(0,1),e}else for(let t=0;t<e.variants.length;t++)if(n==e.variants[t].value.id)return e.variants.splice(t,1),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var i=this.inOrderSuccessor(e.rightNode);return e.value=i.value,e.key=i.key,e.variants=i.variants,e.currentNode=i.currentNode,e.rightNode=this.removeNodeWithVariants(e.rightNode,i.key,n),e}countNodeBelow(e){return null==e?0:1+this.countNodeBelow(e.leftNode)+this.countNodeBelow(e.rightNode)}inOrderSuccessor(e){for(;null!=e.leftNode;)e=e.leftNode;return e}}var B=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class L{static waitForDataToLoad(){return B(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isCharacterLoaded)return e("done");setTimeout(L.checkFlag,1e3,e)}static addNodeToTree(e){return B(this,void 0,void 0,(function*(){return null==this.characterRoot?(this.characterRoot=e,this.characterRoot):(this.characterRoot=this.characterRoot.addCharacterNode(e,this.characterRoot,this.characterRoot.height),this.characterRoot)}))}static removeNodeByCharacter(e,t){return B(this,void 0,void 0,(function*(){this.characterRoot&&this.characterRoot.removeNodeWithVariants(this.characterRoot,e,t)}))}static countNumberOfNodes(){return this.characterRoot?this.characterRoot.countNodeBelow(this.characterRoot):0}static addConceptToTree(e){if(""!=e.characterValue){var t=new U(e.characterValue,e,null,null);this.addNodeToTree(t)}}static getNodeFromTree(e){return this.characterRoot?this.characterRoot.getCharacterFromNode(e,this.characterRoot):this.characterRoot}static getNodeFromTreeUpdated(e){return this.characterRoot?this.characterRoot.getCharacterFromNode(e,this.characterRoot):this.characterRoot}static getCharacterAndTypeFromTree(e,t){return B(this,void 0,void 0,(function*(){return this.characterRoot?this.characterRoot.getFromNodeWithCharacterAndType(e,t,this.characterRoot):this.characterRoot}))}static getCharacterAndCategoryFromTree(e,t){return B(this,void 0,void 0,(function*(){return this.characterRoot?this.characterRoot.getFromNodeWithCharacterAndCategory(e,t,this.characterRoot):this.characterRoot}))}static removeConceptCharacter(e){this.characterRoot&&(this.characterRoot=this.characterRoot.removeNode(this.characterRoot,e))}}L.characterRoot=null;var P=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class G{static addNodeToTree(e){if(null==this.root)return this.root=e,this.root;this.root=this.root.addNode(e,this.root,this.root.height)}static waitForDataToLoad(){return P(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isDataLoaded)return e("done");setTimeout(G.checkFlag,1e3,e)}static addConceptToTree(e){var t=new U(e.id,e,null,null),n=new U(e.characterValue,e,null,null);L.addNodeToTree(n),this.addNodeToTree(t)}static getNodeFromTree(e){return P(this,void 0,void 0,(function*(){return this.root?this.root.getFromNode(e,this.root):null}))}static removeNodeFromTree(e){return P(this,void 0,void 0,(function*(){this.root&&(this.root=this.root.removeNode(this.root,e))}))}static countNumberOfNodes(){return this.root?this.root.countNodeBelow(this.root):0}}G.root=null;class F{constructor(e,t,n,o,i,r,c,s,a,l,d,u,h,f,y,p=!1,v,g){this.referent=null,this.updateRecursion=!1,this.isTemp=!1,this.id=e,this.userId=t,this.typeId=n,this.typeUserId=o,this.ghostId=e,this.categoryId=i,this.categoryUserId=r,this.referentId=c,this.referentUserId=s,this.characterValue=`${a}`,this.securityId=l,this.securityUserId=d,this.accessId=u,this.accessUserId=h,this.sessionInformationId=f,this.sessionInformationUserId=y,this.x=0,this.y=0,this.type=null,this.isNew=p,this.entryTimeStamp=v,this.updatedTimeStamp=g}getType(){console.log(this.typeId)}}function b(){let e=D(new Date),t=D(new Date);return new F(0,0,0,0,0,0,0,0,"0",0,0,0,0,0,0,!1,e,t)}function D(e){const t=e.getMonth()+1,n=e.getDate(),o=e.getFullYear();let i=e.getHours();const r=e.getMinutes(),c=e.getSeconds(),s=i>=12?"PM":"AM";i%=12,i=i||12;const a=e=>e.toString().padStart(2,"0");return`${t}/${n}/${o} ${i}:${a(r)}:${a(c)} ${s}`}var $=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class O{static addNodeToTree(e){return $(this,void 0,void 0,(function*(){return null==this.typeRoot?(this.typeRoot=e,this.typeRoot):(this.typeRoot=this.typeRoot.addTypeNode(e,this.typeRoot,this.typeRoot.height),this.typeRoot)}))}static addConceptToTree(e){if(0!=e.typeId){var t=new U(e.typeId,e,null,null);this.addNodeToTree(t)}}static removeTypeConcept(e,t){this.typeRoot&&(this.typeRoot=this.typeRoot.removeNodeWithVariants(this.typeRoot,e,t))}static getNodeFromTree(e){return this.typeRoot?this.typeRoot.getFromNode(e,this.typeRoot):this.typeRoot}static getTypeVariantsFromTree(e){var t=this.getNodeFromTree(e),n=[];if(t){n.push(null==t?void 0:t.value);for(let e=0;e<t.variants.length;e++)n.push(t.variants[e].value);return n}}static waitForDataToLoad(){return $(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isTypeLoaded)return e("done");setTimeout(O.checkFlag,1e3,e)}static getTypeVariantsFromTreeWithUserId(e,t){return $(this,void 0,void 0,(function*(){var n=[],o=this.getNodeFromTree(e);if(o){o.value.userId==t&&n.push(null==o?void 0:o.value);for(let e=0;e<o.variants.length;e++)if(o.variants[e].value.userId==t){var i=!1;for(let t=0;t<n.length;t++)n[t].id==o.variants[e].value.id&&(i=!0);i||n.push(o.variants[e].value)}}return n}))}static getTypeVariantsWithCharacterValue(e,t){return $(this,void 0,void 0,(function*(){let n=b();var o=this.getNodeFromTree(t);if(o){o.value.characterValue==e&&(n=o.value);for(let t=0;t<o.variants.length;t++)o.variants[t].value.characterValue==e&&(n=o.variants[t].value)}return n}))}static countNumberOfNodes(){return this.typeRoot?this.typeRoot.countNodeBelow(this.typeRoot):0}}O.typeRoot=null;var V=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class M{constructor(){this.name="conceptsArray"}static RemoveExpiredNpc(e=Date.now()){this.NPC=this.NPC.filter((t=>{const n=this.NPCMeta.get(t);return n&&n.expiresAt>e}))}static CheckContains(e){for(var t=!1,n=0;n<this.conceptsArray.length;n++)this.conceptsArray[n].id==e.id&&(t=!0);return t}static AddNpc(e){var t;const n=Date.now();this.RemoveExpiredNpc(n),this.NPC.includes(e)||this.NPC.push(e);const o=this.NPCMeta.get(e),i=(null!==(t=null==o?void 0:o.attempts)&&void 0!==t?t:0)+1;this.NPCMeta.set(e,{attempts:i,expiresAt:n+i*this.NPC_BACKOFF_SECONDS*1e3})}static GetNpc(e){const t=Date.now();this.RemoveExpiredNpc(t);const n=this.NPCMeta.get(e);return!!(n&&n.expiresAt>t)}static AddConceptToStorage(e){e.id>0&&k("concept",e)}static AddConcept(e){e.id>0&&(k("concept",e),G.addConceptToTree(e),O.addConceptToTree(e),L.addConceptToTree(e))}static AddConceptToMemory(e){e.id>0&&(G.addConceptToTree(e),O.addConceptToTree(e),L.addConceptToTree(e))}static AddConceptTemporary(e){var t=this.CheckContains(e);this.conceptDictionary[e.id]=e,t&&this.RemoveConcept(e),this.conceptsArray.push(e)}static RemoveConcept(e){for(var t=0;t<this.conceptsArray.length;t++)this.conceptsArray[t].id==e.id&&this.conceptsArray.splice(t,1);G.removeNodeFromTree(e.id),_("concept",e.id)}static GetConcept(e){return V(this,void 0,void 0,(function*(){var t=b(),n=yield G.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConceptByCharacter(e){return V(this,void 0,void 0,(function*(){var t=b(),n=L.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterUpdated(e){return V(this,void 0,void 0,(function*(){var t=b(),n=L.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterAndTypeLocal(e,t){return V(this,void 0,void 0,(function*(){return b(),yield O.getTypeVariantsWithCharacterValue(e,t)}))}static GetConceptByCharacterAndCategoryLocal(e,t){return V(this,void 0,void 0,(function*(){var n=b(),o=yield L.getCharacterAndCategoryFromTree(e,t);return o&&(n=o.value),n}))}static GetConceptsByTypeId(e){let t=[];for(var n=0;n<this.conceptsArray.length;n++)this.conceptsArray[n].typeId==e&&t.push(this.conceptsArray[n]);return t}static GetConceptsByTypeIdAndUser(e,t){return V(this,void 0,void 0,(function*(){let n=[];return n=yield O.getTypeVariantsFromTreeWithUserId(e,t),n}))}static GetBinaryCharacterTree(){return L.characterRoot}getName(){return this.name}}M.conceptsArray=[],M.NPC=[],M.NPCMeta=new Map,M.NPC_BACKOFF_SECONDS=30,M.conceptDictionary=[];var H=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function j(){return H(this,void 0,void 0,(function*(){(new Date).getTime();var e=yield x("concept");if(Array.isArray(e))for(var t=0;t<e.length;t++){let n=e[t];M.AddConceptToMemory(n)}(new Date).getTime()}))}function W(e){const t=e.lastIndexOf("_");let n=[];return n=t>0?[e.substring(0,t),e.substring(t+1,e.length)]:[e],n}var J=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function q(){return J(this,arguments,void 0,(function*(e="application/json",t="application/json"){if(o.isTokenExpiredOrNearExpiry()&&o.hasOAuthCredentials()){const e=yield r(o.CLIENT_ID,o.CLIENT_SECRET,o.APPLICATION_NAME,!0);e.success||console.error("Failed to refresh token:",e.error)}return{"Content-Type":e,Authorization:"Bearer "+o.BearerAccessToken,Accept:t}}))}function z(){return J(this,arguments,void 0,(function*(e="application/json",t="",n="application/json"){if(""!==t)return{"Content-Type":e,Authorization:"Bearer "+t,Accept:n};if(o.isTokenExpiredOrNearExpiry()&&o.hasOAuthCredentials()){const e=yield r(o.CLIENT_ID,o.CLIENT_SECRET,o.APPLICATION_NAME,!0);e.success||console.error("Failed to refresh token:",e.error)}return{"Content-Type":e,Authorization:"Bearer "+o.BearerAccessToken,Accept:n}}))}class K{constructor(e,t,o,i){this.url=n.BASE_URL,this.message=e,this.ok=t,this.status=o,this.data=i}getMessage(){return this.message}setMessage(e){return this.message=e,this}getStatus(){return this.status}setStatus(e){return this.status=e,this}getData(){return this.data}setData(e){return this.data=e,this}getOk(){return this.ok}setOk(e){return this.ok=e,this}getUrl(){return this.url}setUrl(e){return this.url=e,this}}function Q(e){if(!e.ok){const t=e instanceof l,n=t?e.body||`HTTP error ${e.status}`:e.statusText||`HTTP error ${e.status}`;let o=new K(n,!1,e.status,"");throw o.setUrl(t?e.headers.url||"":e.url),o}}function Y(e){if(!e.ok){const t=e.body||`HTTP error ${e.status}`;let n=new K(t,!1,e.status,e.body);throw n.setUrl(e.headers.url||""),n}}var X=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Z(e,t){return X(this,void 0,void 0,(function*(){try{var o=new URLSearchParams;o.append("type",e),o.append("user_id",t.toString());var i=yield q("application/x-www-form-urlencoded");const c=yield h(n.GetAllConceptsByTypeUrl(),{method:"POST",headers:i,body:o});if(c.ok){const e=yield c.json();for(var r=0;r<e.length;r++)M.AddConcept(e[r])}console.log("GetAllConceptsByType error",c.status),Q(c)}catch(e){throw e instanceof Error?console.log("GetAllConceptsByType error message: ",e.message):console.log("GetAllConceptsByType unexpected error: ",e),e}}))}class ee{constructor(e=0,t,n,o,i,r,c,s,a,l,d,u,h,f,y,p){this.isTemp=!1,this.toUpdate=!1,this.type=b(),this.id=e,this.ofTheConceptId=t,this.toTheConceptId=n,this.ofTheConceptUserId=o,this.toTheConceptUserId=i,this.userId=r,this.typeId=c,this.ghostId=e,this.typeUserId=s,this.orderId=a,this.orderUserId=l,this.securityId=d,this.securityUserId=u,this.accessId=h,this.accessUserId=f,this.sessionInformationId=y,this.sessionInformationUserId=p,this.entryTimeStamp=D(new Date),this.terminationDateTime=new Date,this.localSyncTime=new Date}}class te{constructor(e,t,n,o){this.variants=[],this.height=1,this.key=e,this.value=t,this.leftNode=n,this.rightNode=o,this.currentNode=null}addCurrentNode(e,t){return null==t?t=e:(e.value.typeId!=t.value.typeId&&(t.currentNode=this.addCurrentNode(e,t.currentNode)),t)}addCurrentNodeType(e,t){if(null==t)return e;var n=!1;e.value.id==t.value.id&&(n=!0);for(let o=0;o<t.variants.length;o++)t.variants[o].value.id==e.value.id&&(n=!0);return n||t.variants.push(e),t}addNode(e,t,n){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addNode(e,o,n);else{if(!(t.key<e.key))return t;t.rightNode=this.addNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}return t}addTypeNode(e,t,n){if(0!=e.value.typeId){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addTypeNode(e,o,n);else{if(!(t.key<e.key))return t.key==e.key&&0!=t.key&&t.addCurrentNodeType(e,t),t;t.rightNode=this.addTypeNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}}return t}rightRotate(e){if(e){let t=e.leftNode;if(t){let n=t.rightNode;return e.leftNode=n,t.rightNode=e,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}leftRotate(e){if(e){let t=e.rightNode;if(t){let n=t.leftNode;return t.leftNode=e,e.rightNode=n,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}getHeight(e){return e?e.height:0}getBalanceFactor(e){return null==e?0:this.getHeight(e.leftNode)-this.getHeight(e.rightNode)}getFromNode(e,t){return t?e==t.key?t:e<t.key?this.getFromNode(e,t.leftNode):e>t.key?this.getFromNode(e,t.rightNode):t:t}getCharacterFromNode(e,t){return t?e==t.key?t:e<t.key?this.getCharacterFromNode(e,t.leftNode):e>t.key?this.getCharacterFromNode(e,t.rightNode):t:t}removeNode(e,t){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNode(e.leftNode,t),e;if(e.key<t)return e.rightNode=this.removeNode(e.rightNode,t),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var n=this.inOrderSuccessor(e.rightNode);return e.value=n.value,e.key=n.key,e.variants=n.variants,e.currentNode=n.currentNode,e.rightNode=this.removeNode(e.rightNode,n.key),e}removeNodeWithVariants(e,t,n){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNodeWithVariants(e.leftNode,t,n),e;if(e.key<t)return e.rightNode=this.removeNodeWithVariants(e.rightNode,t,n),e;if(e.variants.length>0)if(e.value.id==n){var o=e.variants[0];if(o)return e.value=o.value,e.key=o.key,e.currentNode=o.currentNode,e.variants.splice(0,1),e}else for(let t=0;t<e.variants.length;t++)if(n==e.variants[t].value.id)return e.variants.splice(t,1),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var i=this.inOrderSuccessor(e.rightNode);return e.value=i.value,e.key=i.key,e.variants=i.variants,e.currentNode=i.currentNode,e.rightNode=this.removeNodeWithVariants(e.rightNode,i.key,n),e}inOrderSuccessor(e){for(;null!=e.leftNode;)e=e.leftNode;return e}}var ne=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class oe{static addNodeToTree(e){if(null==this.connectionroot)return this.connectionroot=e,this.connectionroot;this.connectionroot=this.connectionroot.addNode(e,this.connectionroot,this.connectionroot.height)}static addConnectionToTree(e){var t=new te(e.id,e,null,null);this.addNodeToTree(t)}static waitForDataToLoad(){return ne(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isConnectionLoaded)return e("done");setTimeout(oe.checkFlag,1e3,e)}static removeNodeFromTree(e){return ne(this,void 0,void 0,(function*(){this.connectionroot&&(this.connectionroot=this.connectionroot.removeNode(this.connectionroot,e))}))}static getNodeFromTree(e){return ne(this,void 0,void 0,(function*(){return this.connectionroot?this.connectionroot.getFromNode(e,this.connectionroot):this.connectionroot}))}}oe.connectionroot=null;var ie=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class re{static addNodeToTree(e){return ie(this,void 0,void 0,(function*(){return null==this.connectionTypeRoot?(this.connectionTypeRoot=e,this.connectionTypeRoot):(this.connectionTypeRoot=this.connectionTypeRoot.addTypeNode(e,this.connectionTypeRoot,this.connectionTypeRoot.height),this.connectionTypeRoot)}))}static waitForDataToLoad(){return ie(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isConnectionTypeLoaded)return e("done");setTimeout(re.checkFlag,1e3,e)}static addConnectionToTree(e){if(0!=e.typeId){var t=new te(e.typeId,e,null,null);this.addNodeToTree(t)}}static removeTypeConcept(e,t){this.connectionTypeRoot&&(this.connectionTypeRoot=this.connectionTypeRoot.removeNodeWithVariants(this.connectionTypeRoot,e,t))}static getNodeFromTree(e){return this.connectionTypeRoot?this.connectionTypeRoot.getFromNode(e,this.connectionTypeRoot):this.connectionTypeRoot}static getTypeVariantsFromTree(e){return ie(this,void 0,void 0,(function*(){var t=[],n=this.getNodeFromTree(e);if(n){t.push(null==n?void 0:n.value);for(let e=0;e<n.variants.length;e++)t.push(n.variants[e].value);return t}}))}static getTypeVariantsFromTreeWithUserId(e,t){return ie(this,void 0,void 0,(function*(){var n=[],o=this.getNodeFromTree(e);if(o){o.value.userId==t&&n.push(null==o?void 0:o.value);for(let e=0;e<o.variants.length;e++)o.variants[e].value.userId==t&&n.push(o.variants[e].value)}return n}))}}re.connectionTypeRoot=null;var ce=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class se{constructor(){this.name="Connection Array"}static CheckContains(e){for(var t=!1,n=0;n<this.connectionArray.length;n++)this.connectionArray[n].id==e.id&&(t=!0);return t}static AddConnectionToStorage(e){k("connection",e)}static AddConnection(e){e.isTemp||(k("connection",e),oe.addConnectionToTree(e),re.addConnectionToTree(e))}static AddConnectionToMemory(e){e.isTemp||(oe.addConnectionToTree(e),re.addConnectionToTree(e))}static AddToDictionary(e){this.connectionDictionary[e.id]=e}static RemoveConnection(e){0!=e.id&&(_("connection",e.id),oe.removeNodeFromTree(e.id),re.removeTypeConcept(e.typeId,e.id))}static GetConnectionTree(){return oe.connectionroot}static GetConnectionTypeTree(){return re.connectionTypeRoot}static GetConnection(e){return ce(this,void 0,void 0,(function*(){var t=new ee(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),n=yield oe.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConnectionsOfCompositionLocal(e){return ce(this,void 0,void 0,(function*(){var t=[],n=yield re.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;if(o){let e=o;t.push(e);for(let e=0;e<n.variants.length;e++)t.push(n.variants[e].value)}}return t}))}getName(){return this.name}}se.connectionArray=[],se.connectionDictionary=[];var ae=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function le(e){return ae(this,void 0,void 0,(function*(){let t=[];try{var n=[];for(let o=0;o<e.length;o++){let i=yield M.GetConcept(e[o]);0==i.id?n.push(e[o]):t.push(i)}if(0==n.length)return t;{const e=JSON.stringify(n);var o=yield q();const i=yield T("/api/get_concept_bulk",{method:"POST",headers:o,body:e});if(console.log("[DEBUG] GetConceptBulk response:",{status:i.status,ok:i.ok}),i.ok){let e=yield i.json();if(e.length>0)for(let n=0;n<e.length;n++){let o=e[n];t.push(o),M.AddConcept(o)}}else console.log("Get Concept Bulk error",i.status),Q(i);return t}}catch(e){throw e instanceof Error?console.log("Get Concept Bulk error message: ",e.message):console.log("Get Concept Bulk unexpected error: ",e),e}}))}var de=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ue(){return de(this,arguments,void 0,(function*(e=[]){var t=[];if(e.length>0){for(let n=0;n<e.length;n++)t.includes(e[n].ofTheConceptId)||t.push(e[n].ofTheConceptId),t.includes(e[n].toTheConceptId)||t.push(e[n].toTheConceptId);yield le(t)}}))}var he=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function fe(){return he(this,arguments,void 0,(function*(e=[]){var t=[];for(let o=0;o<e.length;o++){var n=yield se.GetConnectionsOfCompositionLocal(e[o]);t.push(...n)}return t}))}function ye(e=[],t=[]){for(let n=0;n<t.length;n++)Array.isArray(e)&&(e.find((e=>e.id===t[n].id))||se.RemoveConnection(t[n]))}var pe=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ve(){return pe(this,arguments,void 0,(function*(e=[]){var t=[];if(e.length<=0)return t;var o=yield fe(e),i=yield function(){return pe(this,arguments,void 0,(function*(e=[]){var t=[];try{var o=yield q();const r=yield h(n.GetAllConnectionsOfCompositionBulkUrl(),{method:"POST",headers:o,body:JSON.stringify(e)});if(r.ok){const e=yield r.json();for(var i=0;i<e.length;i++)se.AddConnection(e[i]),t.push(e[i])}else console.log("Get all connections of composition bulk error message: ","Cannot get response"),Q(r);return t}catch(e){throw e instanceof Error?console.log("Get all connections of composition bulk error message: ",e.message):console.log("Get all connections of composition bulk unexpected error: ",e),e}}))}(e);return ye(t=i,o),yield ue(t),t}))}var ge=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const Ce=new Map;function me(e){return ge(this,void 0,void 0,(function*(){let t=b();if(Ce.has(e))return Ce.get(e)||t;const o=(()=>ge(this,void 0,void 0,(function*(){try{var o=yield M.GetConcept(e);let r=M.GetNpc(e);if(0!=o.id||r)return o;{var i=yield q("application/x-www-form-urlencoded");const o=n.GetConceptUrl();console.log("[DEBUG] GetConcept request:",{url:o,method:"POST",headers:i,conceptId:e});const r=yield h(n.GetConceptUrl(),{method:"POST",headers:i,body:`id=${e}`});return console.log("[DEBUG] GetConcept response:",{status:r.status,ok:r.ok,conceptId:e}),r.ok?(t=yield r.json(),t.id>0?M.AddConcept(t):M.AddNpc(e)):(console.log("Get the concept error",r.status,e),Q(r)),t}}catch(t){throw t instanceof Error?console.log("Get the concept error message: ",t.message,e):console.log("Get the concept unexpected error: ",t,e),t}finally{Ce.delete(e)}})))();return Ce.set(e,o),o}))}var Te=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function we(e){return Te(this,void 0,void 0,(function*(){var t=[];if(0==(t=yield se.GetConnectionsOfCompositionLocal(e)).length)t=yield Ie(e);else{var n=yield Ie(e);ye(n,t),t=n}return t}))}function Ie(e){return Te(this,void 0,void 0,(function*(){var t=[];try{var o=yield q("application/x-www-form-urlencoded");const r=yield h(n.GetAllConnectionsOfCompositionUrl(),{method:"POST",headers:o,body:`composition_id=${e}`});if(!r.ok)throw Q(r),new Error(`Error! status: ${r.status}`);const c=yield r.json();for(var i=0;i<c.length;i++)se.AddConnection(c[i]),t.push(c[i]);return t}catch(e){throw e instanceof Error?console.log("Get all connection of composition error : ",e.message):console.log("Get all connection of composition error : ",e),e}}))}var Ne=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ae(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield we(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Be(e,o,r);return i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a,i}))}function ke(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield we(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Le(e,o,r);return i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a,i}))}function Se(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield se.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Be(e,o,r);return i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a,i}))}function xe(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield se.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Be(e,o,r);i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a;var l={};return l.created_at=s.entryTimeStamp,l.data=i,l.id=e,l}))}function _e(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield se.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Be(e,o,r);i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a;var l={};return l.data=i,l.id=e,l.created_at=s.entryTimeStamp,l}))}function Re(e,t){return Ne(this,void 0,void 0,(function*(){for(var n,o,i={},r=[],c=0;c<t.length;c++)r.includes(t[c].ofTheConceptId)||r.push(t[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Be(e,t,r);i[null!==(o=null===(n=null==s?void 0:s.type)||void 0===n?void 0:n.characterValue)&&void 0!==o?o:""]=a;var l={};return l.created_at=s.entryTimeStamp,l.data=i,l.id=e,l}))}function Ee(e,t){return Ne(this,arguments,void 0,(function*(e,t,n=[]){var o,i,r={},c=yield M.GetConcept(e);0==c.id&&null!=e&&null!=e&&(c=yield me(e));var s=yield Be(e,t,n);r[null!==(i=null===(o=null==c?void 0:c.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:""]=s;var a={};return a.created_at=c.entryTimeStamp,a.data=r,a.id=e,a}))}function Ue(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield we(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Be(e,o,r);i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a;var l={};return l.data=i,l.id=e,l}))}function Be(e,t,n){return Ne(this,arguments,void 0,(function*(e,t,n,o=[]){var i,r,c,s={},a=[];if(0==e)return null;var l=yield M.GetConcept(e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield me(e)),0!=l.id&&null==l.type){var d=l.typeId,u=yield M.GetConcept(d);l.type=u,null==u&&null!=d&&null!=d&&(u=yield me(d),l.type=u)}if(null===(i=null==l?void 0:l.type)||void 0===i?void 0:i.characterValue,!n.includes(e))return null==l?void 0:l.characterValue;if(o.includes(e))return"";o.push(e);for(var h=0;h<t.length;h++)if(t[h].ofTheConceptId==e){var f=t[h].toTheConceptId,y=yield M.GetConcept(f);null!=y&&0!=y.id||null==f||null==f||(y=yield me(f)),y&&null==(null==y?void 0:y.type)&&(d=y.typeId,u=yield M.GetConcept(d),y.type=u,null==u&&null!=d&&null!=d&&(u=yield me(d),y.type=u));var p=(null!==(c=null===(r=null==y?void 0:y.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"").replace("the_","");if(isNaN(Number(p))){if(p){const e=yield Be(f,t,n,o);s[p]=e}}else{const e=yield Be(f,t,n,o);a[p]=e,s=a}}return s}))}function Le(e,t,n){return Ne(this,arguments,void 0,(function*(e,t,n,o=[]){var i,r,c,s={},a=[];if(0==e)return null;var l=yield M.GetConcept(e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield me(e)),0!=l.id&&null==l.type){var d=l.typeId,u=yield M.GetConcept(d);l.type=u,null==u&&null!=d&&null!=d&&(u=yield me(d),l.type=u)}if(null===(i=null==l?void 0:l.type)||void 0===i?void 0:i.characterValue,!n.includes(e))return null==l?void 0:l.characterValue;if(o.includes(e))return"";o.push(e),s.id=e;for(var h=0;h<t.length;h++)if(t[h].ofTheConceptId==e){var f=t[h].toTheConceptId,y=yield M.GetConcept(f);null!=y&&0!=y.id||null==f||null==f||(y=yield me(f)),y&&null==(null==y?void 0:y.type)&&(d=y.typeId,u=yield M.GetConcept(d),y.type=u,null==u&&null!=d&&null!=d&&(u=yield me(d),y.type=u));var p=(null!==(c=null===(r=null==y?void 0:y.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"").replace("the_","");if(isNaN(Number(p))){if(p){const e=yield Le(f,t,n);s[p]=e}}else{const e=yield Le(f,t,n);a[p]=e,s=a}}return s}))}var Pe=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ge(e){return Pe(this,void 0,void 0,(function*(){let t=b();try{var o=yield q("application/x-www-form-urlencoded");const i=yield h(n.GetConceptByCharacterValueUrl(),{method:"POST",headers:o,body:`character_value=${e}`});return i.ok?(t=yield i.json(),t.id>0&&M.AddConcept(t)):(console.log("Error in Getting concept by character value Error",i.status),Q(i)),t}catch(e){throw e instanceof Error?console.log("Error in Getting concept by character value error message: ",e):console.log("Error in Getting concept by character value unexpected error: ",e),e}}))}var Fe=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function be(e){return Fe(this,void 0,void 0,(function*(){var t=yield M.GetConceptByCharacter(e),n=`${e}`;return null!=t&&0!=(null==t?void 0:t.id)||!n||(yield Ge(e),t=yield M.GetConceptByCharacter(e)),t}))}var De=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function $e(e,t){return De(this,arguments,void 0,(function*(e,t,n=10,o=1){var i=yield be(e),r=[];if(i){yield Z(e,t);for(var c=yield M.GetConceptsByTypeIdAndUser(i.id,t),s=n*(o-1),a=[],l=s;l<s+n;l++)c[l]&&a.push(c[l].id);for(yield ve(a),l=s;l<s+n;l++)if(c[l]){var d=yield Se(c[l].id);r.push(d)}}return r}))}function Oe(e,t){return De(this,arguments,void 0,(function*(e,t,n=10,o=1){var i=yield be(e),r=[];if(i){yield Z(e,t);for(var c=yield M.GetConceptsByTypeIdAndUser(i.id,t),s=n*(o-1),a=[],l=s;l<s+n;l++)c[l]&&a.push(c[l].id);for(yield ve(a),l=s;l<s+n;l++)if(c[l]){var d=yield xe(c[l].id);r.push(d)}}return r}))}var Ve=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const Me=new Map;function He(e,t){return Ve(this,void 0,void 0,(function*(){let o=b();if(Me.has(e+t))return Me.get(e+t)||o;const i=(()=>Ve(this,void 0,void 0,(function*(){try{var i=yield q("application/x-www-form-urlencoded");const r=yield h(n.GetConceptByCharacterAndCategoryDirectUrl(),{method:"POST",headers:i,body:`character_value=${e}&category_id=${t}`});if(r.ok){let e=yield r.json();o=e,M.AddConcept(o)}else console.log("This is the concept by category and character direct api error",r.status),Q(r);return o}catch(o){throw o instanceof Error?console.log(" This is the concept by category and character direct api error message: ",o.message,e,t,n.GetConceptByCharacterAndCategoryDirectUrl()):console.log(" This is the concept by category and character unexpected direct api error: ",o,e,t,n.GetConceptByCharacterAndCategoryDirectUrl()),o}finally{Me.delete(e+t)}})))();return Me.set(e+t,i),i}))}var je=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function We(e){return je(this,void 0,void 0,(function*(){let t=b();if("the"==e)return t.id=1,t.typeId=5,t.characterValue="the",t;let n=e.length;var o=W(e);if(o.length>1){let n=1,i=yield We(o[0]);0!=i.id&&(n=i.id),t=yield function(e,t){return je(this,void 0,void 0,(function*(){let n=yield M.GetConceptByCharacterAndCategoryLocal(e,t);return 0==n.id&&(n=yield He(e,t)),n}))}(e,n)}else o[0]==e&&1==n?t=yield function(e){return je(this,void 0,void 0,(function*(){var t=yield M.GetConceptByCharacterAndTypeLocal(e,49);return 0==t.id&&(t=yield Ge(e)),t}))}(e):o[0]==e&&(t=yield function(e){return je(this,void 0,void 0,(function*(){var t=yield M.GetConceptByCharacterAndTypeLocal(e,51);return 0==t.id&&(t=yield Ge(e)),t}))}(e));return t}))}var Je=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const qe=new Map,ze=new Map;function Ke(e,t){return Je(this,void 0,void 0,(function*(){let t=b();if(ze.has(e))return ze.get(e);if(qe.has(e))return qe.get(e)||t;const o=(()=>Je(this,void 0,void 0,(function*(){try{if(t=yield We(e),0==t.id||4==t.typeId){var o=yield q("application/x-www-form-urlencoded");const i=yield h(n.MakeTheTypeConceptUrl(),{method:"POST",headers:o,body:`type=${e}`});if(!i.ok)throw Q(i),new Error(`Error! status: ${i.status}`);let r=yield i.json();t=r,t.id>0&&M.AddConcept(t)}return t.id>0&&ze.set(e,t),t}catch(e){throw e instanceof Error?console.log("Make The Type Concept Api error : ",e.message):console.log("Make The Type Concept Api error : ",e),e}finally{qe.delete(e)}})))();return qe.set(e,o),o}))}var Qe=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};let Ye=!1,Xe=[];const Ze=()=>{Xe.length>0&&!Ye&&Xe.shift()()};function et(e){return Qe(this,void 0,void 0,(function*(){return new Promise(((t,o)=>{Xe.push((()=>Qe(this,void 0,void 0,(function*(){try{if(Ye)return;if(Ye=!0,!e&&at.connectionIds.length>10)return Ye=!1,Ze(),t();const o=e?`${n.GetReservedConnectionIdUrl()}?${new URLSearchParams({count:String(e)}).toString()}`:n.GetReservedConnectionIdUrl();var i=yield q("application/x-www-form-urlencoded");const c=yield h(o,{method:"GET",headers:i});if(!c.ok)throw Q(c),new Error(`Error! status: ${c.status}`);const s=yield c.json();for(var r=0;r<s.length;r++)at.AddId(s[r]);t()}catch(e){e instanceof Error?console.log("get reserved connection ids error message: ",e.message):console.log("get reserved connection ids unexpected error: ",e),o(e)}finally{Ye=!1,Ze()}})))),Ze()}))}))}var tt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};let nt=!1,ot=[];const it=()=>{ot.length>0&&!nt&&ot.shift()()};function rt(){return tt(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{ot.push((()=>tt(this,void 0,void 0,(function*(){try{if(nt)return;if(nt=!0,st.ids.length>10)return nt=!1,it(),e();var o=yield q("application/x-www-form-urlencoded");const t=yield h(n.GetReservedIdUrl(),{method:"GET",headers:o});if(!t.ok)throw Q(t),new Error(`Error! status: ${t.status}`);const r=yield t.json();for(var i=0;i<r.length;i++)st.AddId(r[i]);e()}catch(e){t(e)}finally{nt=!1,it()}})))),it()}))}))}var ct=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class st{static getId(){return ct(this,void 0,void 0,(function*(){for(this.ids.length<10&&!this.pendingFetch&&(this.pendingFetch=(()=>ct(this,void 0,void 0,(function*(){try{yield rt()}finally{this.pendingFetch=null}})))(),this.ids.length>0&&this.pendingFetch.catch((e=>console.error("Reserved ID refill failed:",e))));0===this.ids.length;)if(this.pendingFetch||(this.pendingFetch=(()=>ct(this,void 0,void 0,(function*(){try{yield rt()}finally{this.pendingFetch=null}})))()),yield this.pendingFetch,0===this.ids.length)throw new Error("No reserved concept IDs were returned by the backend.");return this.ids.shift()}))}static AddId(e){Number.isFinite(e)&&e>0&&!this.ids.includes(e)&&this.ids.push(e)}}st.ids=[],st.pendingFetch=null;class at{static getId(){return ct(this,void 0,void 0,(function*(){for(this.connectionIds.length<10&&!this.pendingFetch&&(this.pendingFetch=(()=>ct(this,void 0,void 0,(function*(){try{yield et()}finally{this.pendingFetch=null}})))());0===this.connectionIds.length;)if(this.pendingFetch||(this.pendingFetch=(()=>ct(this,void 0,void 0,(function*(){try{yield et()}finally{this.pendingFetch=null}})))()),yield this.pendingFetch,0===this.connectionIds.length)throw new Error("No reserved connection IDs were returned by the backend.");return this.connectionIds.shift()}))}static AddId(e){Number.isFinite(e)&&e>0&&!this.connectionIds.includes(e)&&this.connectionIds.push(e)}static warmUp(e){return ct(this,void 0,void 0,(function*(){const t=e-this.connectionIds.length;t<=0||(this.pendingFetch||(this.pendingFetch=(()=>ct(this,void 0,void 0,(function*(){try{yield et(t)}finally{this.pendingFetch=null}})))()),yield this.pendingFetch)}))}}at.connectionIds=[],at.pendingFetch=null;function lt(e){return{id:e.id,userId:e.userId,characterValue:e.characterValue,typeId:e.typeId,categoryId:e.categoryId,accessId:e.accessId,referentId:e.referentId,sessionInformationId:e.sessionInformationId}}function dt(e){return t=this,o=void 0,r=function*(){let t=b();try{var o=yield q();const i=function(e){return Array.isArray(e)?e.map((e=>lt(e))):lt(e)}(e),r=yield f(n.CreateTheConceptUrl(),o,i);if(!r.ok)throw Y(r),new Error(`Error! status: ${r.status}`);return t=yield r.json(),t}catch(e){throw e instanceof Error?console.log("Create the concept api error message: ",e):console.log("Create the concept api unexpected error: ",e),e}},new((i=void 0)||(i=Promise))((function(e,n){function c(e){try{a(r.next(e))}catch(e){n(e)}}function s(e){try{a(r.throw(e))}catch(e){n(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i((function(e){e(n)}))).then(c,s)}a((r=r.apply(t,o||[])).next())}));var t,o,i,r}function ut(e){return t=this,o=void 0,r=function*(){let t=new ee(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);try{var o=yield q();const i=function(e){return e.map((e=>function(e){return{id:e.id,ofTheConceptId:e.ofTheConceptId,toTheConceptId:e.toTheConceptId,ofTheConceptUserId:e.ofTheConceptUserId,toTheConceptUserId:e.toTheConceptUserId,typeId:e.typeId,userId:e.userId,orderId:e.orderId,accessId:e.accessId,sessionInformationId:e.sessionInformationId}}(e)))}(e),r=yield f(n.CreateTheConnectionUrl(),o,i);if(!r.ok)throw console.log("Create the connection error message: ",r),Y(r),new Error(`Error! status: ${r.status}`);return t=yield r.json(),t}catch(e){throw e instanceof Error?console.log("Create the connection error message: ",e.message):console.log(" Create the connection unexpected error: ",e),e}},new((i=void 0)||(i=Promise))((function(e,n){function c(e){try{a(r.next(e))}catch(e){n(e)}}function s(e){try{a(r.throw(e))}catch(e){n(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i((function(e){e(n)}))).then(c,s)}a((r=r.apply(t,o||[])).next())}));var t,o,i,r}var ht=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ft(e){return e?`[SyncData:${e}]`:"[SyncData]"}function yt(e,t){console.log(`${ft(t)} ${e}`)}function pt(e,t,n,o,i){o<100&&n!==o||n!==o&&1!==n&&n%100!=0||console.log(`${ft(i)} ${e} ${t}: ${n}/${o} done, ${o-n} remaining`)}class vt{static CheckContains(e){for(var t=!1,n=0;n<this.conceptsSyncArray.length;n++)this.conceptsSyncArray[n].id==e.id&&(t=!0);return t}static SyncDataDelete(e){for(var t=0;t<this.conceptsSyncArray.length;t++)e==this.conceptsSyncArray[t].id&&this.conceptsSyncArray.splice(t,1);for(t=0;t<this.connectionSyncArray.length;t++)this.connectionSyncArray[t].ofTheConceptId!=e&&this.connectionSyncArray[t].toTheConceptId!=e&&this.connectionSyncArray[t].typeId!=e||this.connectionSyncArray.splice(t,1)}static CheckContainsConnection(e){for(var t=!1,n=0;n<this.connectionSyncArray.length;n++)this.connectionSyncArray[n].id==e.id&&(t=!0);return t}static AddConcept(e){this.conceptsSyncArray.push(e)}static RemoveConcept(e){for(var t=0;t<this.conceptsSyncArray.length;t++)this.conceptsSyncArray[t].id==e.id&&this.conceptsSyncArray.splice(t,1)}static AddConnection(e){this.connectionSyncArray.push(e)}static RemoveConnection(e){for(var t=0;t<this.connectionSyncArray.length;t++)this.connectionSyncArray[t].id==e.id&&this.connectionSyncArray.splice(t,1)}static SyncDataOnline(e){return ht(this,void 0,void 0,(function*(){try{let t=[],n=[];if(e&&this.transactionCollections.some((t=>t.id==e))){const o=this.transactionCollections.find((t=>t.id==e));if(this.transactionCollections=this.transactionCollections.filter((t=>t.id==e||new Date(t.createdDate).getTime()>(new Date).getTime()-6048e5)),!o)return;t=o.data.concepts.slice(),n=o.data.connections.slice(),yt(`starting online sync with ${t.length} concepts and ${n.length} connections`,e),t.length>0&&(yt(`sending ${t.length} concepts to backend`,e),yield dt(t),pt("synced","concepts",t.length,t.length,e)),n.length>0&&(yt(`sending ${n.length} connections to backend`,e),yield ut(n),pt("synced","connections",n.length,n.length,e)),this.transactionCollections=this.transactionCollections.filter((t=>t.id!=e)),yt("online sync complete",e)}else{const e=this.conceptsSyncArray.length,o=this.connectionSyncArray.length;yt(`starting online sync with ${e} queued concepts and ${o} queued connections`);for(let t=0;t<this.conceptsSyncArray.length;t++)M.AddConcept(this.conceptsSyncArray[t]),pt("prepared local cache for","concepts",t+1,e);for(let e=0;e<this.connectionSyncArray.length;e++)se.AddConnection(this.connectionSyncArray[e]),pt("prepared local cache for","connections",e+1,o);this.conceptsSyncArray.length>0&&(t=this.conceptsSyncArray.slice(),yt(`sending ${t.length} concepts to backend`),yield dt(t),this.conceptsSyncArray=this.conceptsSyncArray.filter((e=>!t.some((t=>t.id===e.id)))),pt("synced","concepts",t.length,t.length)),this.connectionSyncArray.length>0&&(n=this.connectionSyncArray.slice(),yt(`sending ${n.length} connections to backend`),yield ut(n),this.connectionSyncArray=this.connectionSyncArray.filter((e=>!n.some((t=>t.id===e.id)))),pt("synced","connections",n.length,n.length)),yt(`online sync complete; ${this.conceptsSyncArray.length} concepts and ${this.connectionSyncArray.length} connections remain queued`)}return"done"}catch(e){throw e}}))}static initializeTransaction(e){return ht(this,void 0,void 0,(function*(){try{if(this.transactionCollections.some((t=>t.id==e)))return;this.transactionCollections.push({id:e,data:{concepts:[],connections:[]},createdDate:(new Date).toISOString()})}catch(e){console.log("error in initializeTransaction",e)}}))}static markTransactionActions(e,t){return ht(this,void 0,void 0,(function*(){try{this.transactionCollections=this.transactionCollections.map((n=>n.id==e?Object.assign(Object.assign({},n),{data:JSON.parse(JSON.stringify(t))}):n)),this.conceptsSyncArray=this.conceptsSyncArray.filter((e=>!t.concepts.some((t=>t.id==e.id||t.ghostId==e.id)))),this.connectionSyncArray=this.connectionSyncArray.filter((e=>!t.connections.some((t=>t.id==e.id||t.ghostId==e.id))))}catch(e){console.log("error in markTransactionActions",e)}}))}static rollbackTransaction(e,t){return ht(this,void 0,void 0,(function*(){try{if(!this.transactionCollections.some((t=>t.id==e)))return;this.transactionCollections=this.transactionCollections.filter((t=>t.id!=e))}catch(e){console.log("LocalSyncData, roll",e)}}))}static syncDataLocalDb(){return ht(this,void 0,void 0,(function*(){if(yt(`starting local sync with ${this.conceptsSyncArray.length} queued concepts and ${this.connectionSyncArray.length} queued connections`),this.conceptsSyncArray.length>0){const e=this.conceptsSyncArray.length;for(let t=0;t<this.conceptsSyncArray.length;t++)k("localconcept",this.conceptsSyncArray[t]),pt("stored locally","concepts",t+1,e);this.conceptsSyncArray=[]}if(this.connectionSyncArray.length>0){const e=this.connectionSyncArray.length;for(let t=0;t<this.connectionSyncArray.length;t++)k("localconnection",this.connectionSyncArray[t]),pt("stored locally","connections",t+1,e);this.connectionSyncArray=[]}return yt("local sync complete"),"done"}))}}function gt(e,t){const n=Number(e);if(!Number.isFinite(n)||n<=0)throw new Error(`Cannot create a connection: ${t} must be a positive finite number. Received ${JSON.stringify(e)}.`);return n}vt.conceptsSyncArray=[],vt.connectionSyncArray=[],vt.transactionCollections=[];var Ct=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function mt(e,t,n,o,i,r,c){return Ct(this,arguments,void 0,(function*(e,t,n,o,i,r,c,s=1,a=4,l=999,d={concepts:[],connections:[]}){const u=function(e,t){const n=gt(e,"ofTheConceptId"),o=gt(t,"toTheConceptId");if(n===o)throw new Error(`Cannot create a self-connection for concept ${n}.`);return{ofTheConceptId:n,toTheConceptId:o}}(e,n);e=u.ofTheConceptId,n=u.toTheConceptId;let h=t,f=t,y=t;999!=l&&(y=l);let p=t,v=t,g=yield at.getId(),C=new ee(g,e,n,t,o,y,i,f,s,h,0,p,a,v,r,c);return C.toUpdate=!0,C.isTemp=!1,vt.AddConnection(C),d.connections.push(C),C}))}function Tt(e,t,n){return Ct(this,arguments,void 0,(function*(e,t,n,o={concepts:[],connections:[]}){let i=yield Ke(n),r=e.userId;return yield mt(e.id,e.userId,t.id,t.userId,i.id,999,999,1e3,4,r,o)}))}var wt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const It=new Map;function Nt(e,t){return wt(this,void 0,void 0,(function*(){let o=yield M.GetConceptByCharacterAndTypeLocal(e,t),i=e+t;if(It.has(i))return It.get(i)||o;const r=(()=>wt(this,void 0,void 0,(function*(){try{if(null==o||0==o.id){var r={character_value:`${e}`,type_id:t},c=JSON.stringify(r),s=yield q();const i=yield h(n.GetConceptByCharacterAndTypeUrl(),{method:"POST",headers:s,body:c});if(i.ok){let e=yield i.json();o=e,M.AddConcept(o)}else console.log("This is the concept by type and character error",i.status),Q(i)}return o}catch(e){throw e instanceof Error?console.log(" This is the concept by type and character error message: ",e.message):console.log(" This is the concept by type and character unexpected error: ",e),e}finally{It.delete(i)}})))();return It.set(i,r),r}))}function At(e){return wt(this,void 0,void 0,(function*(){let t=[],o=JSON.stringify(e);var i=yield q();const r=yield h(n.GetConceptConnectionByType(),{method:"POST",headers:i,body:o});if(r.ok){let e=yield r.json();t=yield le(e)}else console.log("This is the concept by type and character error",r.status),Q(r);return t}))}var kt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function St(e,t,n,o,i,r,c,s,a,l,d,u,h,f){return kt(this,arguments,void 0,(function*(e,t,n,o,i,r,c,s,a,l,d,u,h,f,y={concepts:[],connections:[]}){var p=yield st.getId();let v=new Date,g=new Date;var C=new F(p,t,i,r,n,o,c,s,e,a,l,d,u,h,f,!0,v,g);return C.isTemp=!1,vt.AddConcept(C),y.concepts.push(C),C}))}function xt(e,t,n,o,i,r,c,s,a,l,d,u,h,f){return kt(this,arguments,void 0,(function*(e,t,n,o,i,r,c,s,a,l,d,u,h,f,y={concepts:[],connections:[]}){var p=yield st.getId();let v=new Date,g=new Date;var C=new F(p,t,i,r,n,o,c,s,e,a,l,d,u,h,f,!1,v,g);return M.AddConcept(C),C.updateRecursion=!0,vt.AddConcept(C),y.concepts.push(C),C}))}var _t=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Rt(e,t){return _t(this,arguments,void 0,(function*(e,t,n=!1,o,i,r=999,c=0,s={concepts:[],connections:[]}){let a,l=r,d=o=n?o:999,u=o,h=i,f=o,y=e.startsWith("the_")?e:"the_"+e,p=b();return n?(p=yield Ke(e),a=yield St(t,o,4,o,p.id,p.userId,c,999,999,d,h,f,l,u,s)):(p=yield Ke(y),a=yield Nt(t,p.id),0==a.id&&0==a.userId&&(a=yield xt(t,o,4,o,p.id,p.userId,c,999,999,d,h,f,l,u,s))),a.type=p,a}))}var Et=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ut(e){return Et(this,arguments,void 0,(function*(e,t=null,n=null,o=null,i=null,r=null,c=null){var s=null!=i?i:999,a=null!=r?r:4,l=null!=c?c:999,d=null!=o?o:0,u=b();for(const o in e)if("string"!=typeof e[o]&&"number"!=typeof e[o])if(null==t&&null==n){var h=d;u=p=yield Rt(o,"",!0,s,a,l),h=p.id,d=p.id,yield Ut(e[o],p.id,p.userId,h,i,r,c)}else{var f=null!=t?t:999,y=null!=n?n:999;h=d,u=p=yield Rt(o,"",!0,s,a,l),yield mt(f,y,p.id,p.userId,h,l,p.userId),yield Ut(e[o],p.id,p.userId,h,i,r,c)}else{f=null!=t?t:999,y=null!=n?n:10267,h=d;var p=yield Rt(o,e[o].toString(),!1,s,a,l);yield mt(f,y,p.id,p.userId,h,l,p.userId)}return u}))}var Bt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Lt(e,t,o){return Bt(this,arguments,void 0,(function*(e,t,o,i=10,r=1){let c=[];try{var s=new URLSearchParams;s.append("typeId",`${e}`),s.append("ofTheConceptId",`${t}`),s.append("userId",`${o}`),s.append("inpage",`${i}`),s.append("page",`${r}`);var a=yield q("application/x-www-form-urlencoded");const l=yield h(n.GetAllConnectionsOfConceptUrl(),{method:"POST",headers:a,body:s});return l.ok?c=yield l.json():(console.log("Get connection of concept error",l.status),Q(l)),c}catch(e){throw e instanceof Error?console.log("Get connection of concept error message: ",e.message):console.log("Get connection of concept unexpected error: ",e),e}}))}var Pt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},Gt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},Ft=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},bt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Dt(e){return bt(this,void 0,void 0,(function*(){var t=yield se.GetConnection(e);if((null==t||0==t.id)&&null!=e&&null!=e){var o=yield function(e){return Ft(this,void 0,void 0,(function*(){var t=yield se.GetConnection(e);try{if(0!=t.id)return t;{var o=yield q("application/x-www-form-urlencoded");const i=yield h(n.GetConnectionUrl(),{method:"POST",headers:o,body:`id=${e}`});return i.ok?(t=yield i.json(),se.AddConnection(t)):(console.log("Get Connection Error",i.status),Q(i)),t}}catch(e){throw e instanceof Error?console.log("Get Connection error message: ",e.message):console.log("Get Connection unexpected error: ",e),e}}))}(e);t=o}return t}))}var $t=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ot(e){return $t(this,arguments,void 0,(function*(e,t=""){let o=!1;var i=yield Dt(e);return o=yield function(e){return Gt(this,arguments,void 0,(function*(e,t=""){let o=!1;try{let i=yield yield z("",t),r=yield{Authorization:i.Authorization,Accept:"application/json"};const c=new URLSearchParams;c.append("id",e.toString()),c.append("apiKey","nodeserver");const s=yield h(n.DeleteTheConnectionUrl(),{method:"POST",headers:r,body:c,redirect:"follow"});s.ok?o=(yield s.json()).success:(console.log("Delete connection error status: ",s.status),Q(s))}catch(e){throw e instanceof Error?console.log("Delete connection error message: ",e.message):console.log("Delete connection unexpected error: ",e),e}return o}))}(e,t),_("connection",e),oe.removeNodeFromTree(e),re.removeTypeConcept(i.typeId,e),o}))}function Vt(e){return $t(this,void 0,void 0,(function*(){let t=yield function(e){return Pt(this,void 0,void 0,(function*(){let t=!1;try{let o=yield z();const i=yield h(n.DeleteTheConnectionBulkUrl(),{method:"POST",headers:o,body:JSON.stringify(e)});i.ok?t=(yield i.json()).success:(console.log("Delete connection Bulk Api error status: ",i.status),Q(i))}catch(e){e instanceof Error?console.log("Delete connection Bulk Api error message: ",e.message):console.log("Delete connection Bulk Api unexpected error: ",e)}return t}))}(e);if(t)for(let t=0;t<e.length;t++){let n=e[t];n>0&&oe.removeNodeFromTree(n)}return t}))}var Mt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ht(e){return Mt(this,arguments,void 0,(function*(e,t=999){var n=b();if(e<0)return ei(yield Mo(t,e));if(null!=(n=yield M.GetConcept(e))&&0!=n.id||null==e||null==e||(n=yield me(e)),0!=n.id&&null==n.type&&null!=n.typeId&&null!=n.typeId){var o=yield M.GetConcept(n.typeId);if(0!=o.id)n.type=o;else{var i=yield me(n.typeId);0!=i.id&&(n.type=i)}}return n}))}var jt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const Wt=999,Jt=4,qt=999,zt=999,Kt=1e3;function Qt(e){const t=`${null!=e?e:""}`.trim();if(0===t.length)throw new Error("Cannot create a typed connection without a linker name.");return t}function Yt(e,t){return jt(this,void 0,void 0,(function*(){var n,o,i;if(null==e||null==e.id||0===e.id)throw new Error(`Cannot create a typed connection: ${t} must be a persisted concept.`);const r=e.type;if(null===(n=null==r?void 0:r.characterValue)||void 0===n?void 0:n.trim())return r.characterValue.trim();const c=(yield Ht(e.id,e.userId)).type;if(null===(o=null==c?void 0:c.characterValue)||void 0===o?void 0:o.trim())return e.type=c,c.characterValue.trim();if(null!=e.typeId&&0!==e.typeId){const t=yield Ht(e.typeId,e.typeUserId);if(0!==t.id&&(null===(i=t.characterValue)||void 0===i?void 0:i.trim()))return e.type=t,t.characterValue.trim()}throw new Error(`Cannot create a typed connection: ${t} concept ${e.id} has no resolvable type.`)}))}function Xt(e){return jt(this,void 0,void 0,(function*(){return yield Rt("connection",e,!1,Wt,Wt,qt)}))}function Zt(e,t,n){return jt(this,void 0,void 0,(function*(){return yield mt(e.id,e.userId,t.id,t.userId,n.id,qt,zt,Kt,Jt)}))}function en(e,t,n){return jt(this,arguments,void 0,(function*(e,t,n,o=!1,i=!1){const r=Qt(n),c=e.userId;if(o){const n=yield function(e,t){return jt(this,void 0,void 0,(function*(){return`${yield Yt(e,"toTheConcept")}_s_${t}_by`}))}(t,r);i&&(yield nn(`${r}_by`,t,c));const o=yield Xt(n);yield Zt(t,e,o)}const s=yield function(e,t){return jt(this,void 0,void 0,(function*(){return`${yield Yt(e,"ofTheConcept")}_s_${t}_s`}))}(e,r);i&&(yield nn(`${r}_s`,e,c));const a=yield Xt(s);return yield Zt(e,t,a)}))}function tn(e,t,n){return jt(this,arguments,void 0,(function*(e,t,n,o=!1,i=!1){return yield en(e,t,n,o,i)}))}function nn(e,t){return jt(this,arguments,void 0,(function*(e,t,n=null){for(var o=t,i=null!=n?n:t.userId,r=999,c=Qt(e)+"_count",s=(yield Yt(t,"concept"))+"_s_"+c,a=yield Rt("connection",s,!1,i,4,r),l=yield Lt(a.id,t.id,i,10,1),d=[],u=b(),h=0;h<l.length;h++){let e=yield Ht(l[h].toTheConceptId);d.push(e)}if(d.length<1)u=yield Rt("count","1",!1,i,4,r);else{var f=d[0];let e=Number(f.characterValue),t=Number.isFinite(e)?e+1:1;u=yield Rt("count",t.toString(),!1,i,4,r);for(let e=0;e<l.length;e++)yield Ot(l[e].id)}yield mt(o.id,o.userId,u.id,u.userId,a.id,r,zt,Kt,4,i)}))}function on(e,t,n){return jt(this,arguments,void 0,(function*(e,t,n,o=!1,i=!1){return yield en(e,t,n,o,i)}))}var rn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function cn(e){return encodeURIComponent(String(e))}function sn(e,t){return rn(this,arguments,void 0,(function*(e,t,o=("number"==typeof e?999:e.userId),i=("number"==typeof e?4:e.accessId),r=999){const c="number"==typeof e?e:e.id,s="number"==typeof e?o:e.userId,a=yield q("application/x-www-form-urlencoded"),l=[`character_value=${cn(t)}`,`type_id=${cn(c)}`,`type_user_id=${cn(s)}`,`access_id=${cn(i)}`,`session_information_id=${cn(r)}`].join("&"),d=yield h(n.CreateTypeConceptUrl(),{method:"POST",headers:a,body:l});if(!d.ok)throw Q(d),new Error(`Error! status: ${d.status}`);const u=yield d.json();return"number"!=typeof e&&(u.type=e),M.AddConcept(u),u}))}var an=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ln(e,t){return an(this,arguments,void 0,(function*(e,t,n=10,o=1){var i,r=[],c=yield Ht(e),s=(null===(i=c.type)||void 0===i?void 0:i.characterValue)+"_s_"+t,a=yield Nt(s,16);if(a.id>0){for(var l=yield Lt(a.id,c.id,c.userId,n,o),d=[],u=0;u<l.length;u++)d.push(l[u].toTheConceptId);for(yield ve(d),u=0;u<l.length;u++){let e=l[u].toTheConceptId,t=yield Ht(e),n=yield _e(t.id);r.push(n)}}return r}))}function dn(e,t){return an(this,arguments,void 0,(function*(e,t,n=10,o=1){var i,r=[],c=yield Ht(e),s=(null===(i=c.type)||void 0===i?void 0:i.characterValue)+"_s_"+t,a=yield Nt(s,16);if(a.id>0){for(var l=yield Lt(a.id,c.id,c.userId,n,o),d=[],u=0;u<l.length;u++)d.push(l[u].toTheConceptId);for(u=0;u<l.length;u++){let e=l[u].toTheConceptId,t=yield Ht(e);r.push(t)}}return r}))}class un{constructor(e,t,n,o,i,r,c,s=!1,a,l,d,u=999){this.isComposition=!1,this.isTemp=!1,this.applicationId=999,this.id=e,this.userId=t,this.typeId=n,this.ghostId=e,this.categoryId=o,this.characterValue=r,this.accessId=i,this.type=null,this.isNew=s,this.typeCharacter=c,this.entryTimeStamp=a,this.updatedTimeStamp=l,this.referentId=d,this.applicationId=u}getType(){console.log(this.typeId)}}function hn(){let e=new Date,t=new Date;return new un(0,0,0,0,0,"0","0",!1,e,t,0)}class fn{constructor(e,t,n,o,i,r,c,s,a,l){this.id=0,this.isNew=!1,this.userId=e,this.data=`${t}`,this.securityId=n,this.securityUserId=o,this.accessId=i,this.accessUserId=r,this.sessionId=c,this.sessionUserId=s,this.isNew=l}}class yn{constructor(){this.name="character Repository"}static AddCharacter(e){this.characterData[e.id]=e}static GetCharacter(e){for(var t=new fn(0,"0",0,0,0,0,0,0,"0",!1),n=0;n<this.characterData.length;n++)this.characterData[n].data==e&&(t=this.characterData[n]);return t}}yn.characterData=[];class pn{constructor(e,t,n,o){this.id=e,this.userId=t,this.referentId=n,this.isNew=o}}var vn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},gn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Cn(e,t,o,i,r){return gn(this,void 0,void 0,(function*(){return new fn(t,e,o,t,i,t,r,t,"",!1),yield function(){return vn(this,void 0,void 0,(function*(){var e;try{if(0==(e=yn.GetCharacter(e.data)).id){var t=yield q();const i=yield h(n.CreateTheCharacterDataUrl(),{method:"POST",headers:t,body:JSON.stringify(e)});if(!i.ok)throw Q(i),new Error(`Error! status: ${i.status}`);const r=yield i.json();var o=new fn(r.userId,e.data,0,0,4,4,999,999,"",!1);return o.id=r.id,yn.AddCharacter(o),r}return new pn(e.id,e.userId,0,!1)}catch(e){throw e instanceof Error?console.log("create the character error message: ",e.message):console.log("create the character unexpected error: ",e),e}}))}()}))}var mn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Tn(e,t,n,o,i,r,c,s,a,l,d,u,h,f){return mn(this,void 0,void 0,(function*(){var y=yield Nt(e,i),p=y;return 0==p.id&&(p=y=yield St(e,t,n,o,i,r,c,s,a,l,d,u,h,f)),p}))}var wn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},In=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Nn(e,t,n,o){return In(this,arguments,void 0,(function*(e,t,n,o,i={concepts:[],connections:[]}){var r=yield be(e);if(r&&(0==r.id||0==r.userId)){var c=W(e);if(c.length>0)if(c[0]==e){var s=yield function(e,t,n,o,i,r){return wn(this,void 0,void 0,(function*(){var i,c=t,s=t;i=t;var a,l=t,d=t,u=t;if(1==e.length){var h=e.charCodeAt(0);yield Cn(e,t,n,o,r),a=yield Tn(e,t,4,c,49,l,h,u,n,s,o,i,r,d)}else{var f=yield Cn(e,t,n,o,r);f.isNew,a=yield Tn(e,t,4,c,51,l,f.id,f.userId,n,s,o,i,r,d)}return a}))}(e,o,999,999,0,t);r=s}else{var a=yield Nn(c[0],t,n,o,i),l=yield Nn(c[1],t,n,o,i);l&&(r=yield xt(e,o,a.id,o,l.id,o,999,o,999,o,999,o,t,o,i))}}return r}))}var An=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function kn(e){return An(this,void 0,void 0,(function*(){var t=[];try{(new Date).getTime();var o=yield q("application/x-www-form-urlencoded");const c=new URLSearchParams({conceptId:String(e)}),s=yield h(`${n.GetAllLinkerConnectionOfConceptUrl()}?${c.toString()}`,{method:"GET",headers:o});if(s.ok){const e=yield s.json();for(var i=0;i<e.length;i++){var r=e[i];t.push(r)}}else console.log("Get all linker connection from the concepts error","cannot get respone"),Q(s);return t}catch(e){throw e instanceof Error?console.log("Get all linker connection from the concepts error: ",e.message):console.log("Get all linker connection from the concepts error(Unexpected): ",e),e}}))}var Sn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function xn(e){return Sn(this,void 0,void 0,(function*(){var t=[];try{(new Date).getTime();var o=yield q("application/x-www-form-urlencoded");const c=new URLSearchParams({conceptId:String(e)}),s=yield h(`${n.GetAllLinkerConnectionToConceptUrl()}?${c.toString()}`,{method:"GET",headers:o});if(s.ok){const e=yield s.json();for(var i=0;i<e.length;i++){var r=e[i];t.push(r)}}else console.log("Get all linker connection To the concepts error","cannot get respone"),Q(s);return t}catch(e){throw e instanceof Error?console.log("Get all linker connection To the concepts error: ",e.message):console.log("Get all linker connection To the concepts error(Unexpected): ",e),e}}))}var _n=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Rn(e){return _n(this,void 0,void 0,(function*(){for(var t=yield kn(e),n=0;n<t.length;n++){let e=t[n];var o=e.typeId;let i=yield Ht(o);e.type=i}return t}))}function En(e){return _n(this,void 0,void 0,(function*(){for(var t=yield xn(e),n=0;n<t.length;n++){let e=t[n];var o=e.typeId;let i=yield Ht(o);e.type=i}return t}))}var Un=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},Bn=function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n},Ln=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Pn(e){return Ln(this,arguments,void 0,(function*(e,t=""){var o=yield Ht(e);yield G.removeNodeFromTree(e);var i=o.typeId,r=o.characterValue;yield O.removeTypeConcept(i,e),yield L.removeNodeByCharacter(r,e),_("concept",e);let c=yield function(e){return Un(this,arguments,void 0,(function*(e,t=""){let o=!1;try{let i=yield yield yield z("application/x-www-form-urlencoded",t);const r=new FormData;r.append("id",e.toString()),r.append("apiKey","nodeserver");const{"Content-Type":c}=i,s=Bn(i,["Content-Type"]),a=yield h(n.DeleteConceptUrl(),{method:"POST",headers:s,body:r});if(!a.ok)throw Q(a),new Error(`Error! status: ${a.status}`);o=(yield a.json()).success}catch(e){throw e instanceof Error?console.log("Delete concept error message: ",e.message):console.log("Delete concept unexpected error: ",e),e}return o}))}(e,t);return c}))}var Gn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Fn(e,t){return Gn(this,void 0,void 0,(function*(){try{const o=new Headers;o.append("Authorization","Bearer "+t);const i=new FormData;i.append("id",e.toString());const r=yield h(n.DeleteConceptUrl(),{method:"POST",body:i,headers:o});if(!r.ok)throw Q(r),new Error(`Delete composition Error! status: ${r.status}`)}catch(e){throw e instanceof Error?console.log("Delete composition error message: ",e.message):console.log("Delete composition unexpected error: ",e),e}}))}var bn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Dn(e,t,n,o){return bn(this,arguments,void 0,(function*(e,t,n,o,i=999){var r,c=n,s=n,a=n,l=e.startsWith("the_"),d=b();return r=l?e:"the_"+e,d=yield Ke(r),yield Tn(t,n,4,n,d.id,d.userId,0,999,999,c,o,a,i,s)}))}class $n{constructor(){this.composition=0,this.type="",this.linker="",this.inpage=10,this.page=1,this.listLinkers=[],this.fullLinkers=[],this.textSearch="",this.logic="or",this.reverse=!1,this.doFilter=!1,this.filterSearches=[],this.selectors=[]}}var On=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Vn(){return On(this,arguments,void 0,(function*(e=[]){var t=[];try{var n=[];for(let o=0;o<e.length;o++){let i=yield se.GetConnection(e[o]);0==i.id?n.push(e[o]):t.push(i)}if(0==n.length)return t;{var o=yield q();const e=yield T("/api/get_connection_bulk",{method:"POST",headers:o,body:JSON.stringify(n)});if(e.ok){const n=yield e.json();if(n.length>0){for(let e=0;e<n.length;e++){let o=n[e];t.push(o),se.AddConnection(o)}yield ue(t)}}else console.log("Get Connection Bulk error",e.status),Q(e);return t}}catch(e){throw e instanceof Error?console.log("Get Connection Bulk error message: ",e.message):console.log("Get Connection Bulk unexpected error: ",e),e}}))}var Mn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Hn(){return Mn(this,arguments,void 0,(function*(e=[]){yield ve(e);var t=[];for(let o=0;o<e.length;o++){var n=yield Se(e[o]);t.push(n)}return t}))}function jn(){return Mn(this,arguments,void 0,(function*(e=[]){yield ve(e);var t=[];for(let o=0;o<e.length;o++){var n=yield xe(e[o]);t.push(n)}return t}))}function Wn(){return Mn(this,arguments,void 0,(function*(e=[],t=[]){yield Vn(t),function(e=[],t=[]){for(let n=0;n<t.length;n++)e.includes(t[n].id)||se.RemoveConnection(t[n])}(t,yield fe(e));var n=[];for(let t=0;t<e.length;t++){var o=yield xe(e[t]);n.push(o)}return n}))}function Jn(){return Mn(this,arguments,void 0,(function*(e=[]){let t=[],n=[],o={};for(let o=0;o<(null==e?void 0:e.length);o++){let i=yield se.GetConnection(e[o]);0==i.id?t.push(e[o]):n.push(i)}for(let n=0;n<t.length;n++)o[e[n]]=!1;let i=[],r=yield Vn(t);n=[...n,...r];for(let e=0;e<n.length;e++)i.push(n[e].ofTheConceptId),i.push(n[e].toTheConceptId),i.push(n[e].typeId);return yield le(i),n}))}function qn(){return Mn(this,arguments,void 0,(function*(e=[],t=[]){let n=[],o=[];for(let e=0;e<t.length;e++){let i=yield se.GetConnection(t[e]);0==i.id?n.push(t[e]):o.push(i)}let i=yield Vn(n);for(let e=0;e<i.length;e++)o.push(i[e]);let r={},c=[];for(var s=0;s<o.length;s++)c.includes(o[s].ofTheConceptId)||c.push(o[s].ofTheConceptId);for(let t=0;t<e.length;t++){let n=yield Ee(e[t],o,c);r[e[t]]=n}return r}))}var zn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Kn(){return zn(this,arguments,void 0,(function*(e=0,t=[],o="",i=[]){var r=[];try{var c=new $n;c.composition=e,c.listLinkers=t,c.textSearch=o,c.fullLinkers=i;var s=JSON.stringify(c),a=yield q();const u=yield h(n.RecursiveSearchUrl(),{method:"POST",headers:a,body:s});if(u.ok){const e=yield u.json();var l=e.compositionIds,d=e.internalConnections;e.externalConnections,r=yield Wn(l,d)}else console.log("recursive search error ",u.status),Q(u);return r}catch(e){throw e instanceof Error?console.log("recursive search error message: ",e.message):console.log("recursive search unexpected error: ",e),e}}))}var Qn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Yn(e,t){return Qn(this,void 0,void 0,(function*(){try{var i={email:e,password:t},r=new Headers;r.append("Content-Type","application/json");var c=JSON.stringify(i);const s=yield h(n.LoginUrl(),{method:"POST",headers:r,body:c});if(s.ok){const e=yield s.json();return o.BearerAccessToken=e.data.token,e}console.log("Login tsccs error message: ",s.status),Q(s)}catch(e){throw e instanceof Error?console.log("Login tsccs error message: ",e.message):console.log(" Login tsccs unexpected error: ",e),e}}))}var Xn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Zn(e){return Xn(this,void 0,void 0,(function*(){const t=yield function(){return Xn(this,arguments,void 0,(function*(e="",t={}){let n={message:"success",status:!1,statusCode:200,data:""};try{const o=yield h(e,{method:"POST",mode:"cors",cache:"no-cache",credentials:"same-origin",headers:{"Content-Type":"application/json"},redirect:"follow",referrerPolicy:"no-referrer",body:JSON.stringify(t)}),i=yield o.json();return o.ok?n={message:"success",status:!0,statusCode:200,data:i}:Q(o),n}catch(e){throw console.log("Signup Error: ",e),e}}))}(n.SignupUrl(),e);return t}))}var eo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function to(e){return eo(this,void 0,void 0,(function*(){const t=JSON.stringify({email:e.email,password:e.password});let o={message:"success",status:!1,statusCode:200,data:""};const i=new Headers;i.append("Content-Type","application/json");const r=n.LoginUrl();try{const e=yield h(r,{method:"POST",headers:i,body:t,redirect:"follow"}),n=yield e.json();return e.ok?o={message:"success",status:!0,statusCode:200,data:null==n?void 0:n.data}:Q(e),o}catch(e){throw console.log("Sign in api error",e),e}}))}function no(e,t){return-1===e.indexOf(t)&&e.push(t),e}function oo(e=[],t){var n,o;let i=[],r=null===(n=t.type)||void 0===n?void 0:n.characterValue;if((null==r?void 0:r.startsWith("the_"))||(r="the_"+r),Array.isArray(e))for(let n=0;n<e.length;n++){let c=null===(o=e[n].type)||void 0===o?void 0:o.characterValue;(null==c?void 0:c.startsWith("the_"))||(c="the_"+c),t.typeId!=e[n].typeId&&r!=c||i.push(e[n])}return i}function io(e=[],t){let n=[];if(Array.isArray(e)){const o=e.find((e=>e.toTheConceptId==t));o&&n.push(o);const i=e.find((e=>e.ofTheConceptId==t));i&&n.push(i)}return n}function ro(e=[],t){Array.isArray(e)&&e.splice(e.findIndex((function(e){return e.id===t.id})),1)}function co(e=[],t){Array.isArray(e)&&e.splice(e.findIndex((function(e){return e.id===t.id})),1)}class so{constructor(e,t,n,o){this.expiryTime=new Date(Date.now()+6e5),this.height=1,this.key=e,this.value=t,this.leftNode=n,this.rightNode=o}isValid(){const e=new Date(Date.now());return!(this.expiryTime<e&&(lo.removeNodeFromTree(this.key),1))}saveToCache(e){this.value.cached=e}addNode(e,t,n){if(null==t)return e;const o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addNode(e,o,n);else{if(!(t.key<e.key))return this.isValid(),e;t.rightNode=this.addNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));const r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}return this.isValid(),t}rightRotate(e){if(e){const t=e.leftNode;if(t){const n=t.rightNode;return e.leftNode=n,t.rightNode=e,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}leftRotate(e){if(e){const t=e.rightNode;if(t){const n=t.leftNode;return t.leftNode=e,e.rightNode=n,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}getHeight(e){return e?e.height:0}getBalanceFactor(e){return null==e?0:this.getHeight(e.leftNode)-this.getHeight(e.rightNode)}getFromNode(e,t){return t?e==t.key&&t.isValid()?t:e<t.key?this.getFromNode(e,t.leftNode):e>t.key?this.getFromNode(e,t.rightNode):t:t}removeNode(e,t){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNode(e.leftNode,t),e;if(e.key<t)return e.rightNode=this.removeNode(e.rightNode,t),e;if(null==e.leftNode){const t=e.rightNode;return e=null,t}if(null==e.rightNode){const t=e.leftNode;return e=null,t}{const t=this.inOrderSuccessor(e.rightNode);return e.value=t.value,e.key=t.key,e.rightNode=this.removeNode(e.rightNode,t.key),e}}countNodeBelow(e){return null==e?0:1+this.countNodeBelow(e.leftNode)+this.countNodeBelow(e.rightNode)}inOrderSuccessor(e){for(;null!=e.leftNode;)e=e.leftNode;return e}}var ao=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class lo{static addNodeToTree(e){if(null==this.root)return this.root=e,this.root;this.root=this.root.addNode(e,this.root,this.root.height)}static addCompositionToTree(e){const t=new so(e.id,e,null,null);this.addNodeToTree(t)}static getNodeFromTree(e){return ao(this,void 0,void 0,(function*(){return this.root?this.root.getFromNode(e,this.root):null}))}static removeNodeFromTree(e){return ao(this,void 0,void 0,(function*(){this.root&&(this.root=this.root.removeNode(this.root,e))}))}static countNumberOfNodes(){return this.root?this.root.countNodeBelow(this.root):0}}lo.root=null;var uo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ho(e,t,n,o){return uo(this,arguments,void 0,(function*(e,t,n,o,i=[]){var r,c;let s={};const a=[];if(0==e)return"";let l=fo(n,e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield Ht(e)),0!=l.id&&null==l.type){const e=l.typeId;let t=fo(n,e);l.type=t,null==t&&null!=e&&null!=e&&(t=yield Ht(e),l.type=t)}if(!o.includes(e))return null==l?void 0:l.characterValue;if(i.includes(e))return"";i.push(e);for(let l=0;l<t.length;l++)if(t[l].ofTheConceptId==e){const d=t[l].toTheConceptId;if(o.includes(e)){let e=fo(n,d);if(null!=e&&0!=e.id||null==d||null==d||(e=yield Ht(d)),0!=e.id&&null==(null==e?void 0:e.type)){const t=e.typeId;let n=yield M.GetConcept(t);e.type=n,null==n&&null!=t&&null!=t&&(n=yield Ht(t),e.type=n)}const l="the_",u=(null!==(c=null===(r=null==e?void 0:e.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"").replace(l,"");if(isNaN(Number(u))){if(u){const e=yield ho(d,t,n,o,i);s[u]=e}}else{const e=yield ho(d,t,n,o,i);a[u]=e,s=a}}}return s}))}function fo(e,t){let n=b();for(let o=0;o<e.length;o++)if(t==e[o].id)return n=e[o],n;return n}class yo{constructor(){this.id=0,this.mainConcept=b(),this.connections=[],this.concepts=[],this.subcompositions=[],this.cached={}}updateCache(){return e=this,t=void 0,o=function*(){if(0==this.mainConcept.id)for(let e=0;e<this.concepts.length;e++)this.concepts[e].id==this.id&&(this.mainConcept=this.concepts[e]);this.cached=yield ho(this.id,this.connections,this.concepts,this.subcompositions,[])},new((n=void 0)||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}));var e,t,n,o}UpdateAcrossDistributedSystem(){var e,t;try{0!=this.id&&(t=null===(e=this.id)||void 0===e?void 0:e.toString(),n.MQTT_CONNECTION&&n.MQTT_CONNECTION.publish("compositionUpdate",t))}catch(e){console.log("Error while publishing message",e)}}isUpdating(){this.UpdateAcrossDistributedSystem()}GetDataCache(){var e,t,n;const o={};o[null!==(n=null===(t=null===(e=this.mainConcept)||void 0===e?void 0:e.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=this.cached;const i={};return i.data=o,i.id=this.id,i}}var po=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function vo(e){return po(this,arguments,void 0,(function*(e,t=null,n=null,o=null,i=null,r=null,c=null,s=null){const a=null!=i?i:999,l=null!=r?r:4,d=null!=c?c:999;let u=null!=o?o:0,h=b();null==s&&(s=new yo);for(const o in e)if("object"==typeof e[o]||Array.isArray(e[o])){const f=yield Rt(o,"",!0,a,l,d);if(null==t&&null==n){let t=u;h=f,t=f.id,u=f.id,s.concepts.push(f),s.id=f.id,yield vo(e[o],f.id,f.userId,t,i,r,c,s)}else{const a=null!=t?t:999,l=null!=n?n:999,y=u;h=f,s.concepts.push(f);const p=yield mt(a,l,f.id,f.userId,y,d,f.userId);s.connections.push(p),yield vo(e[o],f.id,f.userId,y,i,r,c,s)}null!=e[o]&&null!=e[o]&&s.subcompositions.push(f.id)}else{const i=null!=t?t:999,r=null!=n?n:999,c=u,h=yield Rt(o,e[o],!1,a,l,d);s.concepts.push(h);const f=yield mt(i,r,h.id,h.userId,c,d,h.userId);s.connections.push(f)}return h}))}var go=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Co(e){return go(this,void 0,void 0,(function*(){const t=e.userId,n=e.sessionId,o=e.accessId;let i=[];const r=[];let c=b(),s=b();const a=[];let l=e.compositionId;const d=e.ofTheCompositionId;let u=[];if(l<0){let e=yield Ht(l,t);if(!(e.id>0))return null;l=e.id}i=yield we(l);const h=[],f=new yo,y=[];f.id=l,f.isUpdating();let p=[];for(let e=0;e<i.length;e++)no(y,i[e].ofTheConceptId),no(h,i[e].ofTheConceptId),no(h,i[e].toTheConceptId),p.push(i[e].ofTheConceptId);f.subcompositions=y,f.connections=i;for(let e=0;e<h.length;e++){const t=yield Ht(h[e]);l==h[e]&&(c=t),d==h[e]&&(s=t),r.push(t)}const v=e.patchObject;for(const e in v){let i=b();const l=v[e];let d=c;if(s.id>0&&(d=s),Array.isArray(l)||"object"==typeof l){i=yield Rt(e,"",!0,c.userId,4,999),f.subcompositions.push(i.id);const t=oo(r,i);for(let e=0;e<t.length;e++)if(t[e].id>0){const n=io(f.connections,t[e].id);u=u.concat(n),a.push(t[e])}yield vo(v[e],i.id,i.userId,c.id,c.userId,4,999,f)}else{i=yield Rt(e,l,!1,t,o,n);const c=oo(r,i);for(let e=0;e<c.length;e++)if(c[e].id>0){const t=io(f.connections,c[e].id);u=u.concat(t),a.push(c[e])}}const h=yield mt(d.id,d.userId,i.id,i.userId,c.id,n,t);r.push(i),f.connections.push(h)}for(let e=0;e<u.length;e++)co(f.connections,u[e]),Ot(u[e].id);for(let e=0;e<a.length;e++)ro(r,a[e]);return f.concepts=f.concepts.concat(r),f.mainConcept=c,f.id=c.id,yield f.updateCache(),lo.addCompositionToTree(f),yield vt.SyncDataOnline(),f.GetDataCache()}))}var mo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function To(e,t,o,i){return mo(this,arguments,void 0,(function*(e,t,o,i,r=10,c=1){var s=yield z("application/x-www-form-urlencoded",i),a=new URLSearchParams;a.append("type",e),a.append("search",t),a.append("composition",o),a.append("inpage",r.toString()),a.append("page",c.toString());const l=n.SearchCompositionsUrl()+"?"+a.toString();try{const e=yield h(l,{method:"GET",headers:s});if(e.ok)return yield e.json();Q(e)}catch(e){throw e}}))}var wo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Io(e){return wo(this,arguments,void 0,(function*(e,t=""){var o=yield z("application/json",t);const i=n.SearchLinkMultipleAll(),r=JSON.stringify(e);try{const e=yield h(i,{method:"POST",headers:o,body:r});if(e.ok)return yield e.json();Q(e)}catch(e){throw e}}))}var No=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ao(e){return No(this,arguments,void 0,(function*(e,t=[]){var n,o;let i=[];const r=[];let c={},s={};const a=[];let l=yield M.GetConcept(e);0==l.id&&null!=e&&null!=e&&(l=yield me(e));let d=[];d=t.length>0?ko(e,t):yield we(e),i=d;for(let e=0;e<i.length;e++)a.includes(i[e].ofTheConceptId)||(a.push(i[e].ofTheConceptId),r.push(i[e].ofTheConceptId)),r.includes(i[e].toTheConceptId)||r.push(i[e].toTheConceptId);return s=yield Be(e,i,a,[]),c[null!==(o=null===(n=null==l?void 0:l.type)||void 0===n?void 0:n.characterValue)&&void 0!==o?o:""]=s,0==l.id?"":c}))}function ko(e,t){const n=[];for(let o=0;o<t.length;o++)t[o].typeId==e&&n.push(t[o]);return n}function So(e){return No(this,arguments,void 0,(function*(e,t=[]){var n,o;let i={},r=[];const c=[];let s;const a={},l=[];let d=yield M.GetConcept(e);0==d.id&&null!=e&&null!=e&&(d=yield me(e));let u=[];u=t.length>0?ko(e,t):yield we(e),r=u;for(let e=0;e<r.length;e++)l.includes(r[e].ofTheConceptId)||(l.push(r[e].ofTheConceptId),c.push(r[e].ofTheConceptId)),c.includes(r[e].toTheConceptId)||c.push(r[e].toTheConceptId);return s=yield Be(e,r,l),a[null!==(o=null===(n=null==d?void 0:d.type)||void 0===n?void 0:n.characterValue)&&void 0!==o?o:""]=s,i.created_at=d.entryTimeStamp,i.data=a,i.id=e,0==d.id?"":i}))}function xo(e,t){return No(this,void 0,void 0,(function*(){let n=[];const o=[];n=yield Vn(t);for(let t=0;t<e.length;t++){const i=yield So(e[t],n);i&&o.push(i)}return o}))}var _o=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ro(e){return _o(this,void 0,void 0,(function*(){try{var t=yield q();const o=JSON.stringify(e),i=yield h(n.CreateSessionId(),{method:"POST",headers:t,body:o});return i.ok?i.json():(console.log("Creating session failed",yield i.json()),Q(i),null)}catch(e){throw console.log("Creating session failed",e),e}}))}var Eo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Uo(e,t){return Eo(this,void 0,void 0,(function*(){try{var o=yield q("application/x-www-form-urlencoded");const i=new URLSearchParams;i.append("sessionId",e.toString()),i.append("url",t);const r=yield h(n.CreateSessionVisitUrl(),{method:"POST",headers:o,body:i});return r.ok?r.json():(console.log("Creating session url failed",yield r.json()),Q(r),null)}catch(e){throw console.log("Creating session url failed",e),e}}))}var Bo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Lo(e,t,o){return Bo(this,arguments,void 0,(function*(e,t,o,i=10,r=1){let c=[];try{var s=new URLSearchParams;s.append("typeId",`${e}`),s.append("toTheConceptId",`${t}`),s.append("userId",`${o}`),s.append("inpage",`${i}`),s.append("page",`${r}`);var a=yield q("application/x-www-form-urlencoded");const l=yield h(n.GetAllConnectionsToConceptUrl(),{method:"POST",headers:a,body:s});return l.ok?c=yield l.json():(console.log("Get connection of concept error",l.status),Q(l)),c}catch(e){throw e instanceof Error?console.log("Get connection of concept error message: ",e.message):console.log("Get connection of concept unexpected error: ",e),e}}))}var Po=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Go(e,t){return Po(this,arguments,void 0,(function*(e,t,n=10,o=1,i=!1){let r=[],c=yield Ht(e),s=yield We(t);if(s.id>0){let e=[],t=[];if(i){t=yield Lo(s.id,c.id,c.userId,n,o);let e=[];for(let n=0;n<t.length;n++)e.push(t[n].ofTheConceptId);yield ve(e);for(let e=0;e<t.length;e++){let n=t[e].ofTheConceptId,o=yield Ht(n),i=yield _e(o.id);r.push(i)}}else{t=yield Lt(s.id,c.id,c.userId,n,o);for(let n=0;n<t.length;n++)e.push(t[n].toTheConceptId);yield ve(e);for(let e=0;e<t.length;e++){let n=t[e].toTheConceptId,o=yield Ht(n),i=yield _e(o.id);r.push(i)}}}return r}))}function Fo(e,t){return Po(this,arguments,void 0,(function*(e,t,n=10,o=1,i=!1){let r=[],c=yield Ht(e),s=yield We(t),a=[],l=[];if(s.id>0){if(i){a=yield Lo(s.id,c.id,c.userId,n,o);for(let e=0;e<a.length;e++)l.push(a[e].ofTheConceptId)}else{a=yield Lt(s.id,c.id,c.userId,n,o);for(let e=0;e<a.length;e++)l.push(a[e].toTheConceptId)}r=yield le(l)}return r}))}class bo{constructor(e,t,n){this.value=new Map,this.connectionValue=new Map,this.key=e,t.id>0&&this.value.set(t.ghostId,t),n.id>0&&this.connectionValue.set(n.ghostId,n)}}class Do{constructor(e=0,t,n,o,i,r,c=999){this.isTemp=!1,this.applicationId=999,this.type=hn(),this.id=e,this.ofTheConceptId=t,this.toTheConceptId=n,this.typeId=o,this.ghostId=e,this.orderId=i,this.typeCharacter="",this.accessId=r,this.entryTimeStamp=D(new Date),this.terminationDateTime=new Date,this.localSyncTime=new Date,this.applicationId=c}}var $o=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Oo{static compositeKey(e,t,n=999){return("0000"+e.toString(16).toUpperCase()).slice(-4)+("0000"+t.toString(16).toUpperCase()).slice(-4)+("0000"+n.toString(16).toUpperCase()).slice(-4)}static waitForDataToLoad(){return $o(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isDataLoaded)return e("done");setTimeout(Oo.checkFlag,1e3,e)}static addConceptToTree(e,t,n=999){const o=this.compositeKey(t,n,e.applicationId),i=this.nodeMap.get(o);i?e.id>0&&i.value.set(e.ghostId,e):this.nodeMap.set(o,new bo(o,e,new Do(0,0,0,0,0,0)))}static addConnectionToTree(e,t,n=999){const o=this.compositeKey(t,n,e.applicationId),i=this.nodeMap.get(o);i?e.id>0&&i.connectionValue.set(e.ghostId,e):this.nodeMap.set(o,new bo(o,hn(),e))}static getNodeFromTree(e,t){return $o(this,arguments,void 0,(function*(e,t,n=999){var o;const i=this.compositeKey(e,t,n);return null!==(o=this.nodeMap.get(i))&&void 0!==o?o:null}))}static removeNodeFromTree(e){return $o(this,arguments,void 0,(function*(e,t=999,n=999){const o=this.compositeKey(e,t,n);this.nodeMap.delete(o)}))}static countNumberOfNodes(){return this.nodeMap.size}}Oo.nodeMap=new Map;var Vo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Mo(e,t){return Vo(this,arguments,void 0,(function*(e,t,n=999,o=999){var i;let r=yield Oo.getNodeFromTree(e,n,o),c=hn();return r&&(c=null!==(i=r.value.get(t))&&void 0!==i?i:c),c}))}function Ho(e,t){return Vo(this,arguments,void 0,(function*(e,t,n=999,o=999){var i;let r=yield Oo.getNodeFromTree(e,n,o),c=new Do(0,0,0,0,0,0);return r&&(c=null!==(i=r.connectionValue.get(t))&&void 0!==i?i:c),c}))}function jo(e,t){return Vo(this,arguments,void 0,(function*(e,t,n=999){Oo.addConceptToTree(e,t,n)}))}function Wo(e,t){return Vo(this,arguments,void 0,(function*(e,t,n=999){Oo.addConnectionToTree(e,t,n)}))}var Jo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function qo(e){return Jo(this,arguments,void 0,(function*(e,t=""){var o=yield z("application/json",t);const i=n.SearchLinkMultipleAllApiUrl(),r=JSON.stringify(e);try{const e=yield h(i,{method:"POST",headers:o,body:r});if(e.ok)return yield e.json();Q(e)}catch(e){throw e}}))}var zo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ko(e){return zo(this,arguments,void 0,(function*(e,t=""){let n=[],o=yield qo(e,t),i=e[0].composition;const r=o;let c=r.compositionIds,s=r.internalConnections,a=r.linkers,l=r.reverse;return n=yield qn(c,s),yield Qo(a,n,i,l)}))}function Qo(e,t,n){return zo(this,arguments,void 0,(function*(e,t,n,o=[]){let i={},r=yield Vn(e);for(let e=0;e<r.length;e++){let n=!1;if(o.includes(r[e].id)&&(n=!0),1==n){if(t[r[e].ofTheConceptId]&&t[r[e].toTheConceptId]){let n=t[r[e].toTheConceptId],o=yield Ht(r[e].typeId),i=null==n?void 0:n.data,c=Object.keys(i)[0];try{let n=o.characterValue+"_reverse";"string"==typeof i&&(i={}),Array.isArray(i[c][n])||("string"==typeof i[c]&&(i[c]={}),i[c][n]=[]),i[c][n].push(t[r[e].ofTheConceptId])}catch(e){}}}else if(t[r[e].ofTheConceptId]&&t[r[e].toTheConceptId]){let n=t[r[e].ofTheConceptId],o=yield Ht(r[e].typeId),i=null==n?void 0:n.data,c=Object.keys(i)[0];try{"string"==typeof i&&(i={}),Array.isArray(i[c][o.characterValue])||("string"==typeof i[c]&&(i[c]={}),i[c][o.characterValue]=[]),i[c][o.characterValue].push(t[r[e].toTheConceptId])}catch(e){}}}return i=t[n],i}))}var Yo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},Xo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Zo(e){return Xo(this,void 0,void 0,(function*(){var t;let o=yield function(e){return Yo(this,void 0,void 0,(function*(){let t=[];try{var o=yield q();const i=yield h(n.ViewInternalDataUrl(),{method:"POST",headers:o,body:JSON.stringify(e)});if(i.ok){let e=yield i.json(),n={};for(let o=0;o<e.length;o++){let i=e[o].concepts;t=e[o].connections;let r=e[o].id;yield le(i),n[r]=t}return n}return console.log("View Internal Data error",i.status),Q(i),t}catch(e){throw e instanceof Error?console.log(" This is the view internal data error message: ",e.message):console.log(" This is the view internal data unexpected error: ",e),e}}))}(e),i=[];for(let n=0;n<e.length;n++){let r=e[n],c=o[r];if(r&&c){let e=[],t={};for(let t=0;t<c.length;t++)e.includes(c[t].ofTheConceptId)||e.push(c[t].ofTheConceptId);let n=yield Be(r,c,e);t.data=n,t.id=r,i.push(t)}else{let e={};e.id=r;let n=yield Ht(r),o={};n.type&&(o[null===(t=null==n?void 0:n.type)||void 0===t?void 0:t.characterValue]=n.characterValue,e.data=o,i.push(e))}}return i}))}function ei(e){const t=b();return t.id=e.id,t.ghostId=e.ghostId,t.userId=e.userId,t.accessId=e.accessId,t.entryTimeStamp=e.entryTimeStamp,t.typeId=e.typeId,t.categoryId=e.categoryId,t.characterValue=e.characterValue,t}var ti=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},ni=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function oi(e){return ni(this,arguments,void 0,(function*(e,t=""){var o=yield function(e){return ti(this,arguments,void 0,(function*(e,t=""){var o,i,r,c,s,a,l=yield z("application/json",t);const d=new URLSearchParams({composition:String(null!==(o=e.composition)&&void 0!==o?o:""),search:String(null!==(i=e.search)&&void 0!==i?i:""),internalComposition:String(null!==(r=e.internalComposition)&&void 0!==r?r:""),type:String(null!==(c=e.type)&&void 0!==c?c:""),inpage:String(null!==(s=e.inpage)&&void 0!==s?s:""),page:String(null!==(a=e.page)&&void 0!==a?a:"")}),u=`${n.SearchInternalWithAuthenticatedCcsUrl()}?${d.toString()}`;try{const e=yield h(u,{method:"GET",headers:l});if(e.ok)return yield e.json();Q(e)}catch(e){throw e}}))}(e,t);return yield Zo(o)}))}var ii=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ri(e,t){return ii(this,void 0,void 0,(function*(){let n=!0,o=yield kn(e),i=yield At(t),r=[];for(let e=0;e<o.length;e++)for(let t=0;t<i.length;t++)o[e].typeId==i[t].id&&r.push(o[e].id);for(let e=0;e<r.length;e++){let t=yield Ot(r[e]);n=n&&t}return n}))}function ci(e,t){return ii(this,void 0,void 0,(function*(){let n=yield kn(e),o=yield At(t),i=[];for(let e=0;e<n.length;e++)for(let t=0;t<o.length;t++)n[e].typeId==o[t].id&&i.push(n[e].id);return i}))}class si{constructor(){this.compositionId=0,this.userId=999,this.sessionId=999,this.accessId=4,this.ofTheCompositionId=0,this.patchObject={}}}class ai{constructor(){this.id="0",this.remote_address="",this.server_port="",this.server_address="",this.server_name="",this.server_software="",this.http_user_agent="",this.self="",this.port="",this.userId="",this.email=""}}class li{constructor(){this.type="",this.search="",this.logicoperator="=",this.index=0,this.composition=!0,this.name="",this.operateon=""}}class di{constructor(){this.type="",this.search="",this.composition="",this.internalComposition="",this.userId=999,this.inpage=10,this.page=1}}function ui(e){if(Array.isArray(e))return e.filter((e=>"string"==typeof e&&""!==e.trim()));if("string"!=typeof e)return[];const t=e.trim();if(!t)return[];try{const e=JSON.parse(t);if(Array.isArray(e))return e.filter((e=>"string"==typeof e&&""!==e.trim()))}catch(e){}return t.split(",").map((e=>e.trim())).filter(Boolean)}class hi{constructor(e){var t;this.aiUrl="https://ai.freeschema.com",this.cacheServerUrl="",this.cacheServers=[],this.accessToken="",this.enableAi=!0,this.enableAccessControl=!1,e&&(Object.assign(this,e),this.cacheServers=ui(null!==(t=e.cacheServers)&&void 0!==t?t:e.cache_servers),this.cacheServerUrl=e.cacheServerUrl||e.cacheServer||this.cacheServerUrl)}hasOAuthCredentials(){return!(!this.clientId||!this.clientSecret)}hasAccessToken(){return""!==this.accessToken}getFlag(e,t=!1){var n,o;return null!==(o=null===(n=this.flags)||void 0===n?void 0:n[e])&&void 0!==o?o:t}getParameter(e,t=""){var n,o;return null!==(o=null===(n=this.parameters)||void 0===n?void 0:n[e])&&void 0!==o?o:t}setFlag(e,t){this.flags||(this.flags={}),this.flags[e]=t}setParameter(e,t){this.parameters||(this.parameters={}),this.parameters[e]=t}}var fi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class yi{constructor(){this.name="Connection Array"}static CheckContains(e){for(var t=!1,n=0;n<this.connectionArray.length;n++)this.connectionArray[n].id==e.id&&(t=!0);return t}static AddConnection(e){this.CheckContains(e)&&this.RemoveConnection(e),(0!=e.id||e.isTemp)&&k("localconnection",e),this.connectionArray.push(e)}static AddToDictionary(e){this.connectionDictionary[e.id]=e}static RemoveConnection(e){for(var t=0;t<this.connectionArray.length;t++)this.connectionArray[t].id==e.id&&this.connectionArray.splice(t,1);e.id}static GetConnection(e){var t;t=null;for(var n=0;n<this.connectionArray.length;n++)this.connectionArray[n].id==e&&(t=this.connectionArray[n]);return t}static waitForDataToLoad(){return fi(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isLocalConnectionLoaded)return e("done");setTimeout(yi.checkFlag,1e3,e)}static GetConnectionsOfCompositionLocal(e){return fi(this,void 0,void 0,(function*(){var t=[];try{for(var n=0;n<this.connectionArray.length;n++)this.connectionArray[n].typeId==e&&t.push(this.connectionArray[n]);return t}catch(e){return t}}))}getName(){return this.name}}yi.connectionArray=[],yi.connectionDictionary=[];var pi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function vi(){return pi(this,void 0,void 0,(function*(){yield function(){return pi(this,void 0,void 0,(function*(){var e=yield x("connection");if(Array.isArray(e))for(var t=0;t<e.length;t++)se.AddConnectionToMemory(e[t])}))}()}))}function gi(){return pi(this,void 0,void 0,(function*(){yield function(){return pi(this,void 0,void 0,(function*(){var e=yield R("localconnection");if(Array.isArray(e))for(var t=0;t<e.length;t++)yi.AddConnection(e[t])}))}()}))}class Ci{constructor(e,t,n,o){this.variants=[],this.height=1,this.key=e,this.value=t,this.leftNode=n,this.rightNode=o,this.currentNode=null}addCurrentNode(e,t){return null==t?t=e:(e.value.typeId!=t.value.typeId&&(t.currentNode=this.addCurrentNode(e,t.currentNode)),t)}addCurrentNodeType(e,t){if(null==t)return e;var n=!1;for(let o=0;o<t.variants.length;o++)t.variants[o].value.id==e.value.id&&(n=!0);return n||t.variants.push(e),t}addNode(e,t,n){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addNode(e,o,n);else{if(!(t.key<e.key))return t;t.rightNode=this.addNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}return t}addCharacterNode(e,t,n){if(""!=e.value.characterValue){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addCharacterNode(e,o,n);else{if(!(t.key<e.key))return t.key==e.key&&""!=t.key&&t.value.id!=e.value.id&&t.addCurrentNodeType(e,t),t;t.rightNode=this.addCharacterNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}}return t}addTypeNode(e,t,n){if(0!=e.value.typeId){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addTypeNode(e,o,n);else{if(!(t.key<e.key))return t.key==e.key&&0!=t.key&&t.value.id!=e.value.id&&t.addCurrentNodeType(e,t),t;t.rightNode=this.addTypeNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}}return t}rightRotate(e){if(e){let t=e.leftNode;if(t){let n=t.rightNode;return e.leftNode=n,t.rightNode=e,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}leftRotate(e){if(e){let t=e.rightNode;if(t){let n=t.leftNode;return t.leftNode=e,e.rightNode=n,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}getHeight(e){return e?e.height:0}getBalanceFactor(e){return null==e?0:this.getHeight(e.leftNode)-this.getHeight(e.rightNode)}getFromNode(e,t){return t?e==t.key?t:e<t.key?this.getFromNode(e,t.leftNode):e>t.key?this.getFromNode(e,t.rightNode):t:t}getCharacterFromNode(e,t){return t?e==t.key?t:e<t.key?this.getCharacterFromNode(e,t.leftNode):e>t.key?this.getCharacterFromNode(e,t.rightNode):t:t}getFromNodeWithCharacterAndType(e,t,n){if(e=`${e}`,n){if(e==n.key){if(e==n.value.characterValue&&t==n.value.typeId)return n;for(let e=0;e<n.variants.length;e++)if(n.variants[e].value.typeId==t)return n.variants[e]}else{if(e<n.key)return this.getFromNodeWithCharacterAndType(e,t,n.leftNode);if(e>n.key)return this.getFromNodeWithCharacterAndType(e,t,n.rightNode)}return null}return n}removeNode(e,t){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNode(e.leftNode,t),e;if(e.key<t)return e.rightNode=this.removeNode(e.rightNode,t),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var n=this.inOrderSuccessor(e.rightNode);return e.value=n.value,e.key=n.key,e.variants=n.variants,e.currentNode=n.currentNode,e.rightNode=this.removeNode(e.rightNode,n.key),e}removeNodeWithVariants(e,t,n){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNodeWithVariants(e.leftNode,t,n),e;if(e.key<t)return e.rightNode=this.removeNodeWithVariants(e.rightNode,t,n),e;if(e.variants.length>0)if(e.value.id==n){var o=e.variants[0];if(o)return e.value=o.value,e.key=o.key,e.currentNode=o.currentNode,e.variants.splice(0,1),e}else for(let t=0;t<e.variants.length;t++)if(n==e.variants[t].value.id)return e.variants.splice(t,1),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var i=this.inOrderSuccessor(e.rightNode);return e.value=i.value,e.key=i.key,e.variants=i.variants,e.currentNode=i.currentNode,e.rightNode=this.removeNodeWithVariants(e.rightNode,i.key,n),e}countNodeBelow(e){return null==e?0:1+this.countNodeBelow(e.leftNode)+this.countNodeBelow(e.rightNode)}inOrderSuccessor(e){for(;null!=e.leftNode;)e=e.leftNode;return e}}var mi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Ti{static addNodeToTree(e){if(null==this.root)return this.root=e,this.root;this.root=this.root.addNode(e,this.root,this.root.height)}static addConceptToTree(e){var t=new Ci(e.id,e,null,null);new Ci(e.characterValue,e,null,null),this.addNodeToTree(t)}static waitForDataToLoad(){return mi(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isLocalDataLoaded)return e("done");setTimeout(Ti.checkFlag,1e3,e)}static getNodeFromTree(e){return mi(this,void 0,void 0,(function*(){return this.root?this.root.getFromNode(e,this.root):null}))}static getCharacterAndTypeFromTree(e,t){return this.root?this.root.getFromNodeWithCharacterAndType(e,t,this.root):this.root}static removeNodeFromTree(e){return mi(this,void 0,void 0,(function*(){this.root&&(this.root=this.root.removeNode(this.root,e))}))}}Ti.root=null;var wi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Ii{static waitForDataToLoad(){return wi(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isLocalCharacterLoaded)return e("done");setTimeout(Ii.checkFlag,1e3,e)}static addNodeToTree(e){return wi(this,void 0,void 0,(function*(){return null==this.LocalCharacterRoot?(this.LocalCharacterRoot=e,this.LocalCharacterRoot):(this.LocalCharacterRoot=this.LocalCharacterRoot.addCharacterNode(e,this.LocalCharacterRoot,this.LocalCharacterRoot.height),this.LocalCharacterRoot)}))}static addConceptToTree(e){if(""!=e.characterValue){var t=new Ci(e.characterValue,e,null,null);this.addNodeToTree(t)}}static getNodeFromTree(e){return this.LocalCharacterRoot?this.LocalCharacterRoot.getCharacterFromNode(e,this.LocalCharacterRoot):this.LocalCharacterRoot}static getCharacterAndTypeFromTree(e,t){return wi(this,void 0,void 0,(function*(){return this.LocalCharacterRoot?this.LocalCharacterRoot.getFromNodeWithCharacterAndType(e,t,this.LocalCharacterRoot):this.LocalCharacterRoot}))}static removeConceptType(e,t){this.LocalCharacterRoot&&(this.LocalCharacterRoot=this.LocalCharacterRoot.removeNodeWithVariants(this.LocalCharacterRoot,e,t))}}Ii.LocalCharacterRoot=null;var Ni=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Ai{static addNodeToTree(e){return Ni(this,void 0,void 0,(function*(){return null==this.LocalTypeRoot?(this.LocalTypeRoot=e,this.LocalTypeRoot):(this.LocalTypeRoot=this.LocalTypeRoot.addTypeNode(e,this.LocalTypeRoot,this.LocalTypeRoot.height),this.LocalTypeRoot)}))}static addConceptToTree(e){if(0!=e.typeId){var t=new Ci(e.typeId,e,null,null);this.addNodeToTree(t)}}static removeConceptType(e,t){this.LocalTypeRoot&&(this.LocalTypeRoot=this.LocalTypeRoot.removeNodeWithVariants(this.LocalTypeRoot,e,t))}static getNodeFromTree(e){return this.LocalTypeRoot?this.LocalTypeRoot.getFromNode(e,this.LocalTypeRoot):this.LocalTypeRoot}static getTypeVariantsFromTree(e){var t=this.getNodeFromTree(e),n=[];if(t){n.push(null==t?void 0:t.value);for(let e=0;e<t.variants.length;e++)n.push(t.variants[e].value);return n}}static waitForDataToLoad(){return Ni(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isLocalTypeLoaded)return e("done");setTimeout(Ai.checkFlag,1e3,e)}static getTypeVariantsFromTreeWithUserId(e,t){return Ni(this,void 0,void 0,(function*(){var n=[],o=this.getNodeFromTree(e);if(o){o.value.userId==t&&n.push(null==o?void 0:o.value);for(let e=0;e<o.variants.length;e++)o.variants[e].value.userId==t&&n.push(o.variants[e].value)}return n}))}}Ai.LocalTypeRoot=null;var ki=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Si{constructor(){this.name="conceptsArray"}static AddConcept(e){e.id>0&&(k("localconcept",e),Ti.addConceptToTree(e),Ii.addConceptToTree(e),Ai.addConceptToTree(e),this.localconceptsArray.push(e))}static AddConceptToMemory(e){e.id>0&&(Ti.addConceptToTree(e),Ii.addConceptToTree(e),Ai.addConceptToTree(e))}static GetConcept(e){return ki(this,void 0,void 0,(function*(){var t=hn(),n=yield Ti.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConceptByCharacter(e){return ki(this,void 0,void 0,(function*(){var t=hn(),n=Ii.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterAndTypeLocal(e,t){return ki(this,void 0,void 0,(function*(){var n=hn(),o=yield Ii.getCharacterAndTypeFromTree(e,t);return o&&(n=o.value),n}))}static GetConceptsByTypeId(e){let t=[];for(var n=0;n<this.localconceptsArray.length;n++)this.localconceptsArray[n].typeId==e&&t.push(this.localconceptsArray[n]);return t}static GetConceptsByTypeIdAndUser(e,t){return ki(this,void 0,void 0,(function*(){let n=[];return n=yield Ai.getTypeVariantsFromTreeWithUserId(e,t),n}))}getName(){return this.name}}Si.localconceptsArray=[];var xi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function _i(){return xi(this,void 0,void 0,(function*(){var e=yield R("localconcept");if(Array.isArray(e))for(var t=0;t<e.length;t++){let n=e[t];Si.AddConceptToMemory(n)}}))}var Ri=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Ei{}Ei.isUpdated=!1,Ei.isOnlineSync=!1;var Ui=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Bi{constructor(){this.accessCache=new Map,this.accessIndex=new Map,this.entityIndex=new Map,this.setCounter=0}generateKey(e,t,n){return`${e}:${t.toLowerCase()}:${null!=n?n:0}`}get(e,t,n){const o=this.generateKey(e,t,n),i=this.accessCache.get(o);return void 0===i?null:Date.now()>i.expiresAt?(this.accessCache.delete(o),null):i.value}set(e,t,n,o){const i=this.generateKey(e,t,n);this.accessCache.set(i,{value:o,expiresAt:Date.now()+3e5}),this.accessIndex.has(e)||this.accessIndex.set(e,new Set),this.accessIndex.get(e).add(i);const r=null!=n?n:0;this.entityIndex.has(r)||this.entityIndex.set(r,new Set),this.entityIndex.get(r).add(i),this.setCounter++,this.setCounter>=100&&(this.setCounter=0,this.sweepExpired())}remove(e,t,n){const o=this.generateKey(e,t,n);this.accessCache.delete(o);const i=this.accessIndex.get(e);i&&i.delete(o);const r=null!=n?n:0,c=this.entityIndex.get(r);c&&c.delete(o)}clear(){this.accessCache.clear(),this.accessIndex.clear(),this.entityIndex.clear(),this.setCounter=0}sweepExpired(){const e=Date.now();for(const[t,n]of this.accessCache)if(e>n.expiresAt){this.accessCache.delete(t);const e=t.split(":"),n=parseInt(e[0]),o=parseInt(e[2]),i=this.accessIndex.get(n);i&&(i.delete(t),0===i.size&&this.accessIndex.delete(n));const r=this.entityIndex.get(o);r&&(r.delete(t),0===r.size&&this.entityIndex.delete(o))}for(const[t,n]of Bi.superAdminCache)e>n.expiresAt&&Bi.superAdminCache.delete(t)}getPermissionsByAccessAndEntity(e,t){const n=new Map,o=this.accessIndex.get(e),i=Date.now();if(o){const e=null!=t?t:0;for(const t of o){const o=this.accessCache.get(t);if(o&&i<=o.expiresAt){const i=t.split(":");parseInt(i[2])===e&&n.set(i[1],o.value)}}}return n}getPermissionsByAccess(e){const t=new Map,n=this.accessIndex.get(e),o=Date.now();if(n)for(const e of n){const n=this.accessCache.get(e);if(n&&o<=n.expiresAt){const o=e.split(":"),i=parseInt(o[2]),r=o[1];t.set(`${i}:${r}`,n.value)}}return t}getPermissionsByEntity(e){const t=new Map,n=this.entityIndex.get(e),o=Date.now();if(n)for(const e of n){const n=this.accessCache.get(e);if(n&&o<=n.expiresAt){const o=e.split(":"),i=parseInt(o[0]),r=o[1];t.set(`${i}:${r}`,n.value)}}return t}getSuperAdmin(e){const t=Bi.superAdminCache.get(e);return void 0===t?null:Date.now()>t.expiresAt?(Bi.superAdminCache.delete(e),null):t.value}setSuperAdmin(e,t){Bi.superAdminCache.set(e,{value:t,expiresAt:Date.now()+6e5})}clearSuperAdminCache(){Bi.superAdminCache.clear()}}Bi.superAdminCache=new Map;var Li,Pi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Gi{constructor(e){if(this.baseUrl=e||process.env.ACCESS_CONTROL_BASE_URL||"http://localhost:3000/api/access-control",!this.baseUrl)throw new Error("Access Control base URL is not configured")}getAsync(e){return Pi(this,void 0,void 0,(function*(){const t=yield fetch(`${this.baseUrl}/${e}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!t.ok)throw new Error(`GET '${e}' failed with status ${t.status}`);const n=yield t.json();if(null==n)throw new Error(`The response for GET '${e}' returned null.`);return n}))}postAsync(e,t){return Pi(this,void 0,void 0,(function*(){const n=yield fetch(`${this.baseUrl}/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`POST '${e}' failed with status ${n.status}`);const o=yield n.json();if(null==o)throw new Error(`The response for POST '${e}' returned null.`);return o}))}deleteAsync(e,t){return Pi(this,void 0,void 0,(function*(){const n={method:"DELETE",headers:{"Content-Type":"application/json"}};null!=t&&(n.body=JSON.stringify(t));const o=yield fetch(`${this.baseUrl}/${e}`,n);if(!o.ok)throw new Error(`DELETE '${e}' failed with status ${o.status}`);const i=yield o.json();if(null==i)throw new Error(`The response for DELETE '${e}' returned null.`);return i}))}assignAccessAsync(e){return Pi(this,void 0,void 0,(function*(){return this.postAsync("access/assign",e)}))}checkAccessAsync(e){return Pi(this,void 0,void 0,(function*(){return this.postAsync("access/check",e)}))}revokeAccessAsync(e){return Pi(this,void 0,void 0,(function*(){return this.deleteAsync("access/revoke",e)}))}assignAccessBulkAsync(e){return Pi(this,void 0,void 0,(function*(){return this.postAsync("access/assign/bulk",e)}))}revokeAccessBulkAsync(e){return Pi(this,void 0,void 0,(function*(){return this.deleteAsync("access/revoke/bulk",e)}))}checkAccessBulkAsync(e){return Pi(this,void 0,void 0,(function*(){return this.postAsync("access/check/bulk",e)}))}getAccessByIdAsync(e){return Pi(this,void 0,void 0,(function*(){return this.getAsync(`access/${e}`)}))}setAccessInheritanceAsync(e){return Pi(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance",e)}))}getAccessInheritanceStatusAsync(e){return Pi(this,arguments,void 0,(function*(e,t=999){return this.getAsync(`access/inheritance/status?accessId=${e}&connectionTypeId=${t}`)}))}assignSuperAdminAccessAsync(e){return Pi(this,void 0,void 0,(function*(){return this.postAsync("access/super-admin",e)}))}revokeSuperAdminAccessAsync(e){return Pi(this,void 0,void 0,(function*(){return this.deleteAsync("access/super-admin",e)}))}checkSuperAdminStatusAsync(e){return Pi(this,void 0,void 0,(function*(){return this.getAsync(`access/super-admin?accessId=${e}`)}))}setParentAccessInheritanceAsync(e){return Pi(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent",e)}))}removeParentAccessInheritanceAsync(e,t){return Pi(this,void 0,void 0,(function*(){let n=`access/inheritance/parent?accessId=${e}`;return null!=t&&(n+=`&parentAccessId=${t}`),this.deleteAsync(n)}))}hasParentAccessInheritanceAsync(e,t){return Pi(this,void 0,void 0,(function*(){let n=`access/inheritance/parent/status?accessId=${e}`;return null!=t&&(n+=`&parentAccessId=${t}`),this.getAsync(n)}))}getParentAccessIdAsync(e){return Pi(this,void 0,void 0,(function*(){return this.getAsync(`access/inheritance/parent?accessId=${e}`)}))}setParentAccessInheritanceByConceptAsync(e){return Pi(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent/concept",e)}))}setParentAccessInheritanceBulkByConceptAsync(e){return Pi(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent/concept/bulk",e)}))}removeParentAccessInheritanceByConceptAsync(e,t){return Pi(this,void 0,void 0,(function*(){let n=`access/inheritance/parent/concept?childConceptId=${e}`;return null!=t&&(n+=`&parentConceptId=${t}`),this.deleteAsync(n)}))}removeParentAccessInheritanceBulkByConceptAsync(e){return Pi(this,void 0,void 0,(function*(){return this.deleteAsync("access/inheritance/parent/concept/bulk",e)}))}hasParentAccessInheritanceByConceptAsync(e,t){return Pi(this,void 0,void 0,(function*(){let n=`access/inheritance/parent/concept/status?childConceptId=${e}`;return null!=t&&(n+=`&parentConceptId=${t}`),this.getAsync(n)}))}getParentAccessIdByConceptAsync(e){return Pi(this,void 0,void 0,(function*(){return this.getAsync(`access/inheritance/parent/concept?childConceptId=${e}`)}))}assignSuperAdminByConceptAsync(e){return Pi(this,void 0,void 0,(function*(){return this.postAsync("access/super-admin/concept",e)}))}revokeSuperAdminByConceptAsync(e){return Pi(this,void 0,void 0,(function*(){return this.deleteAsync("access/super-admin/concept",e)}))}checkSuperAdminByConceptAsync(e){return Pi(this,void 0,void 0,(function*(){return this.getAsync(`access/super-admin/concept?conceptId=${e}`)}))}setAccessInheritanceByConceptAsync(e){return Pi(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/concept",e)}))}getAccessInheritanceStatusByConceptAsync(e){return Pi(this,arguments,void 0,(function*(e,t=999){return this.getAsync(`access/inheritance/concept/status?conceptId=${e}&connectionTypeId=${t}`)}))}}!function(e){e[e.None=0]="None",e[e.Read=1]="Read",e[e.Write=2]="Write",e[e.Execute=4]="Execute",e[e.Delete=8]="Delete"}(Li||(Li={}));var Fi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class bi{static initialize(){console.log("AccessControlService initialized with access control disabled by default.")}static setEnabled(e){this.isAccessControlEnabled=e}static getEnabled(){return this.isAccessControlEnabled}static setBaseUrl(e){this.apiClient=new Gi(e)}static checkAccess(e,t,n){return Fi(this,void 0,void 0,(function*(){var o;if(t===Li.None)throw new Error("Permission is required");return null!==(o=(yield this.checkAccessBulk([e],t,n)).get(e))&&void 0!==o&&o}))}static checkAccessBulk(e,t,o){return Fi(this,void 0,void 0,(function*(){var i,r,c,s,a,l;if(t===Li.None)throw new Error("Permission is required");const d=this.permissionSetToString(t),u=new Map;if(!e||0===e.length)return u;if(!this.isAccessControlEnabled){for(const t of e)u.set(t,!0);return u}if(null!=o&&o>0)try{if(yield this.isSuperAdmin(o)){for(const t of e)u.set(t,!0);return u}}catch(e){}const f=[],y=new Set,p=new Map;let v=null;if(null!=o&&o>0)try{v=yield Ht(o)}catch(e){}let g=0;try{const e=yield function(){return e=this,t=void 0,i=function*(){let e=b();try{var t=yield q("application/x-www-form-urlencoded");const o=yield h(n.GetConceptByCharacterAndCategoryUrl(),{method:"POST",headers:t,body:"character_value=the_parent_access_inheritance"});return o.ok?(e=yield o.json(),M.AddConcept(e)):(console.log("This is the concept by category and character error",o.status),Q(o)),e}catch(e){throw e instanceof Error?console.log(" This is the concept by category and character error message: ",e.message):console.log(" This is the concept by category and character unexpected error: ",e),e}},new((o=void 0)||(o=Promise))((function(n,r){function c(e){try{a(i.next(e))}catch(e){r(e)}}function s(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(c,s)}a((i=i.apply(e,t||[])).next())}));var e,t,o,i}();e&&e.id&&(g=e.id)}catch(e){}const C=yield le(e),m=new Map;for(const e of C)m.set(e.id,e);const T=new Map;for(const t of e){const e=null!==(i=m.get(t))&&void 0!==i?i:yield Ht(t);if(!e||0===e.id){u.set(t,!1);continue}const n=null!==(r=e.accessId)&&void 0!==r?r:0,o=null!==(c=e.typeId)&&void 0!==c?c:0;if(v&&v.userId&&v.userId===e.userId){u.set(t,!0);continue}if(n<1e4){u.set(t,!0);continue}let a=0;if(o>0){let e=T.get(o);if(!e)try{e=yield Ht(o),T.set(o,e)}catch(e){}e&&(a=null!==(s=e.accessId)&&void 0!==s?s:0)}f.push({conceptId:t,accessId:n,typeAccessId:a}),n>0&&(y.add(n),p.set(n,t)),a>0&&y.add(a)}if(0===f.length)return u;const w=yield this.resolveBulkInheritanceGraph(y,g,p),I=[],N=new Set;for(const e of w.values())for(const t of e)N.has(t)||(N.add(t),I.push(t));const A=yield this.resolveSubjects(o),k=yield this.resolveBulkDecisions(I,d,A);for(const e of f){const t=null!==(a=w.get(e.accessId))&&void 0!==a?a:[e.accessId],n=e.typeAccessId>0?null!==(l=w.get(e.typeAccessId))&&void 0!==l?l:[e.typeAccessId]:[],o=this.hasAnyGrant(t,n,A,k);u.set(e.conceptId,o)}return u}))}static getConceptIdsWithPermission(e,t,n){return Fi(this,void 0,void 0,(function*(){if(e===Li.None)throw new Error("Permission is required");if(!t||0===t.length)return[];if(!this.isAccessControlEnabled)return t;const o=yield this.checkAccessBulk(t,e,n);return t.filter((e=>!0===o.get(e)))}))}static resolveBulkInheritanceGraph(e,t,n){return Fi(this,void 0,void 0,(function*(){var o;const i=new Map,r=new Set;let c=new Set(e),s=0;for(;c.size>0;){if(s>=10){console.warn("[AccessControl] BFS depth limit (10) reached. Stopping inheritance traversal.");break}s++;const e=new Set;for(const e of c)r.add(e);const a=Array.from(c);if(t>0)for(const t of a)try{const n=yield ci(t,["the_parent_access_inheritance"]);if(n&&n.length>0){const o=yield Vn(n);for(const n of o){const o=n.toTheConceptId;o&&o>0&&!r.has(o)&&(i.has(t)||i.set(t,[]),i.get(t).push(o),e.add(o))}}}catch(e){}for(const t of a)try{const n=yield this.apiClient.getParentAccessIdAsync(t);if(!0===(null==n?void 0:n.status)&&void 0!==n.data&&null!==n.data){const o=this.parseIntData(n);null!==o&&o>0&&!r.has(o)&&(i.has(t)||i.set(t,[]),i.get(t).push(o),e.add(o))}}catch(e){}for(const c of a)try{const s=yield this.apiClient.getAccessInheritanceStatusAsync(c);if(!this.parseBoolData(s))continue;const a=n.get(c);if(!a||0===a)continue;const l=yield kn(a);if(!l||0===l.length)continue;for(const s of l){if(s.ofTheConceptId!==a)continue;if(t>0&&s.typeId!==t)continue;const l=s.toTheConceptId;if(l&&0!==l)try{const t=yield Ht(l),s=null!==(o=null==t?void 0:t.accessId)&&void 0!==o?o:0;s>0&&!r.has(s)&&(i.has(c)||i.set(c,[]),i.get(c).push(s),n.set(s,l),e.add(s))}catch(e){}}}catch(e){}for(const t of r)e.delete(t);c=e}const a=new Map;for(const t of e){const e=[t],n=new Set([t]),o=[t];for(;o.length>0&&e.length<100;){const t=o.shift(),r=i.get(t);if(r)for(const t of r)n.has(t)||(n.add(t),e.push(t),o.push(t))}a.set(t,e)}return a}))}static resolveBulkDecisions(e,t,n){return Fi(this,void 0,void 0,(function*(){var o;const i=new Map,r=new Map;for(let o=0;o<n.length;o++){const c=n[o];for(const n of e){const e=this.cacheService.get(n,t,c),s=`${n}:${null!=c?c:0}`;null!==e?i.set(s,e):(r.has(o)||r.set(o,[]),r.get(o).push(n))}}for(const[e,c]of r){if(0===c.length)continue;const r=n[e];try{const e={accessIds:c,permission:t,entityId:r},n=yield this.apiClient.checkAccessBulkAsync(e);if(!0===(null==n?void 0:n.status)&&n.data&&Array.isArray(n.data)){const e=new Map;for(const t of n.data)e.set(t.accessId,t.hasAccess);for(const n of c){const c=null!==(o=e.get(n))&&void 0!==o&&o;this.cacheService.set(n,t,r,c),i.set(`${n}:${null!=r?r:0}`,c)}}else for(const e of c)this.cacheService.set(e,t,r,!1),i.set(`${e}:${null!=r?r:0}`,!1)}catch(e){for(const e of c)i.set(`${e}:${null!=r?r:0}`,!1)}}return i}))}static resolveSubjects(e){return Fi(this,void 0,void 0,(function*(){const t=[null];if(null!=e&&e>0){t.push(e);try{const n=yield ci(e,["the_entity_s_group"]);if(n&&n.length>0){const e=yield Vn(n);for(const n of e)n.toTheConceptId&&n.toTheConceptId>0&&t.push(n.toTheConceptId)}}catch(e){}}return t}))}static hasAnyGrant(e,t,n,o){for(const t of e)for(const e of n){const n=`${t}:${null!=e?e:0}`;if(!0===o.get(n))return!0}for(const e of t)for(const t of n){const n=`${e}:${null!=t?t:0}`;if(!0===o.get(n))return!0}return!1}static assignAccess(e,t,n){return Fi(this,void 0,void 0,(function*(){var o;if(t===Li.None)throw new Error("Permission is required");try{const i=null!==(o=(yield Ht(e)).accessId)&&void 0!==o?o:0,r=this.permissionSetToString(t),c=yield this.apiClient.assignAccessAsync({accessId:i,permission:r,entityId:n});if(!0===(null==c?void 0:c.status)&&c.data){const e=c.data;return this.cacheService.set(e.accessId,e.permission,e.entityId,e.hasAccess),!0}return!1}catch(o){throw new Error(`Error assigning access for conceptId ${e}, permission '${t}', entityId ${n}: ${o}`)}}))}static assignAccessBulk(e){return Fi(this,void 0,void 0,(function*(){var t;if(!e||!e.targets||0===e.targets.length)throw new Error("Request must contain at least one target");try{const n=yield this.apiClient.assignAccessBulkAsync(e);if(!0!==(null==n?void 0:n.status))throw new Error((null==n?void 0:n.message)||"Failed to assign bulk access");const o=[];for(const n of e.targets)for(const i of n.permissions){const r=null!==(t=e.accessId)&&void 0!==t?t:0;this.cacheService.set(r,i,n.entityId,!0),o.push({accessId:r,permission:i,entityId:n.entityId,hasAccess:!0})}return o}catch(e){throw console.error("Failed to assign bulk access:",e),e}}))}static revokeAccess(e,t,n){return Fi(this,void 0,void 0,(function*(){var o;try{const i=null!==(o=(yield Ht(e)).accessId)&&void 0!==o?o:0,r=this.permissionSetToString(t);if(0===i)throw new Error(`Concept with ID ${e} does not have a valid accessId`);const c=yield this.apiClient.revokeAccessAsync({accessId:i,permission:r,entityId:n}),s=!0===(null==c?void 0:c.status);return this.cacheService.set(i,r,n,!s),s}catch(o){throw new Error(`Error revoking access for concept ${e}, permission '${t}', entityId ${n}: ${o}`)}}))}static revokeAccessBulk(e){return Fi(this,void 0,void 0,(function*(){var t;if(!e||!e.targets||0===e.targets.length)throw new Error("Request must contain at least one target");try{yield this.apiClient.revokeAccessBulkAsync(e);const n=[];for(const o of e.targets)for(const i of o.permissions){const r=null!==(t=e.accessId)&&void 0!==t?t:0;this.cacheService.set(r,i,o.entityId,!1),n.push({accessId:r,permission:i,entityId:o.entityId,hasAccess:!1})}return n}catch(e){throw console.error("Failed to revoke bulk access:",e),e}}))}static setAccessInheritance(e){return Fi(this,void 0,void 0,(function*(){var t;try{const n=yield this.apiClient.setAccessInheritanceByConceptAsync({conceptId:e,connectionTypeId:999});return null!==(t=null==n?void 0:n.status)&&void 0!==t&&t}catch(t){throw new Error(`Error setting access inheritance for conceptId ${e}: ${t}`)}}))}static getAccessInheritanceStatus(e){return Fi(this,arguments,void 0,(function*(e,t=999){try{const n=yield this.apiClient.getAccessInheritanceStatusByConceptAsync(e,t);return this.parseBoolData(n)}catch(n){throw new Error(`Error getting access inheritance status for conceptId ${e}, connectionTypeId ${t}: ${n}`)}}))}static setAccessInheritanceStatus(e,t){return Fi(this,arguments,void 0,(function*(e,t,n=999){var o;try{const i=yield this.apiClient.setAccessInheritanceByConceptAsync({conceptId:e,enable:t,connectionTypeId:n});return null!==(o=null==i?void 0:i.status)&&void 0!==o&&o}catch(t){throw new Error(`Error setting access inheritance status for conceptId ${e}: ${t}`)}}))}static setParentAccessInheritance(e,t){return Fi(this,void 0,void 0,(function*(){try{const n=yield this.apiClient.setParentAccessInheritanceByConceptAsync({parentConceptId:t,childConceptId:e});if(!0===(null==n?void 0:n.status)){const e=this.parseIntData(n);if(null!==e&&e>0)return e}return 0}catch(t){throw new Error(`Error setting parent access inheritance for conceptId ${e}: ${t}`)}}))}static removeParentAccessInheritance(e,t){return Fi(this,void 0,void 0,(function*(){var n;try{const o=yield this.apiClient.removeParentAccessInheritanceByConceptAsync(e,t);return null!==(n=null==o?void 0:o.message)&&void 0!==n?n:"Parent access inheritance removal failed"}catch(t){throw new Error(`Error removing parent access inheritance for conceptId ${e}: ${t}`)}}))}static hasParentAccessInheritance(e,t){return Fi(this,void 0,void 0,(function*(){try{const n=yield this.apiClient.hasParentAccessInheritanceByConceptAsync(e,t);return this.parseBoolData(n)}catch(t){throw new Error(`Error checking parent access inheritance for conceptId ${e}: ${t}`)}}))}static getParentAccessId(e){return Fi(this,void 0,void 0,(function*(){try{const t=yield this.apiClient.getParentAccessIdByConceptAsync(e);return this.parseIntData(t)}catch(t){throw new Error(`Error getting parent access ID for conceptId ${e}: ${t}`)}}))}static setParentAccessInheritanceBulk(e,t){return Fi(this,void 0,void 0,(function*(){try{const n=yield this.apiClient.setParentAccessInheritanceBulkByConceptAsync({parentConceptId:t,childConceptIds:e});return!0===(null==n?void 0:n.status)&&Array.isArray(n.data)?n.data:[]}catch(e){throw new Error(`Error setting bulk parent access inheritance for parentConceptId ${t}: ${e}`)}}))}static removeParentAccessInheritanceBulk(e,t){return Fi(this,void 0,void 0,(function*(){try{const n=yield this.apiClient.removeParentAccessInheritanceBulkByConceptAsync({parentConceptId:null!=t?t:0,childConceptIds:e});return!0===(null==n?void 0:n.status)&&Array.isArray(n.data)?n.data:[]}catch(e){throw new Error(`Error removing bulk parent access inheritance: ${e}`)}}))}static isSuperAdmin(e){return Fi(this,void 0,void 0,(function*(){try{if(0===e)return!1;const t=this.cacheService.getSuperAdmin(e);if(null!==t)return t;const n=yield this.apiClient.checkSuperAdminByConceptAsync(e);if(!0===(null==n?void 0:n.status)&&void 0!==n.data){const t=this.parseBoolData(n);return this.cacheService.setSuperAdmin(e,t),t}return!1}catch(t){throw new Error(`Error checking super admin status for entityId ${e}: ${t}`)}}))}static assignSuperAdmin(e){return Fi(this,void 0,void 0,(function*(){try{const t=yield this.apiClient.assignSuperAdminByConceptAsync({conceptId:e});return!0===(null==t?void 0:t.status)&&void 0!==t.data?(this.cacheService.setSuperAdmin(e,!0),e):0}catch(t){throw new Error(`Failed to assign super admin for entityId ${e}: ${t}`)}}))}static revokeSuperAdmin(e){return Fi(this,void 0,void 0,(function*(){try{const t=yield this.apiClient.revokeSuperAdminByConceptAsync({conceptId:e});return!0===(null==t?void 0:t.status)&&t.message?(this.cacheService.setSuperAdmin(e,!1),t.message):"Super admin access deletion failed"}catch(t){throw new Error(`Failed to revoke super admin for entityId ${e}: ${t}`)}}))}static parseBoolData(e){if(!(null==e?void 0:e.status)||void 0===e.data||null===e.data)return!1;const t=e.data;if("boolean"==typeof t)return t;if("string"==typeof t)return"true"===t.toLowerCase();if("number"==typeof t)return 0!==t;if("object"==typeof t)for(const e of["enabled","Enabled","isEnabled","IsEnabled","status","Status","hasAccess","HasAccess"])if(e in t){const n=t[e];if("boolean"==typeof n)return n;if("string"==typeof n)return"true"===n.toLowerCase()}return!1}static parseIntData(e){if(!(null==e?void 0:e.status)||void 0===e.data||null===e.data)return null;const t=e.data;if("number"==typeof t)return t;if("string"==typeof t){const e=parseInt(t,10);return isNaN(e)?null:e}if("object"==typeof t)for(const e of["id","Id","accessId","AccessId","parentAccessId","ParentAccessId"])if(e in t){const n=t[e];if("number"==typeof n)return n;if("string"==typeof n){const e=parseInt(n,10);if(!isNaN(e))return e}}return null}static permissionSetToString(e){return function(e){const t=[];return e&Li.Read&&t.push("read"),e&Li.Write&&t.push("write"),e&Li.Execute&&t.push("execute"),e&Li.Delete&&t.push("delete"),t}(e)[0]||"read"}static clearCache(){this.cacheService.clear()}static clearSuperAdminCache(){this.cacheService.clearSuperAdminCache()}static updateAccessCache(e,t,n,o){this.cacheService.set(e,t,n,o)}static updateSuperAdminCache(e,t){this.cacheService.setSuperAdmin(e,t)}}bi.cacheService=new Bi,bi.apiClient=new Gi,bi.isAccessControlEnabled=!1,bi.initialize();var Di=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const $i=1,Oi=2,Vi=3,Mi=4,Hi=5,ji=6,Wi=7,Ji=8;class qi{constructor(){this.conceptId=0,this.connectionTypeId=0,this.connectionType="",this.count=0}}var zi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ki(e){return zi(this,void 0,void 0,(function*(){let t={};for(let n=0;n<e.length;n++){let o=yield me(e[n].connectionTypeId);e[n].connectionType=o.characterValue,t[e[n].conceptId]||(t[e[n].conceptId]=[]),t[e[n].conceptId].push(e[n])}return t}))}function Qi(e){const t=e.split("_");if(3===t.length){let e=new qi;return e.conceptId=Number(t[0]),e.connectionTypeId=Number(t[1]),e.count=Number(t[2]),e}throw new Error("Input string must contain exactly three parts separated by underscores.")}function Yi(e){return e.startsWith("the_")?e.slice(4):e}var Xi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Zi(e,t,n){if(e in t){const o=Array.isArray(t[e])?t[e]:[t[e]];for(const e of o)e&&(n[e.connectionType+"_count"]=e.count)}}var er=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},tr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function nr(e,t,n){return tr(this,void 0,void 0,(function*(){var o,i,r,c,s,a,l,d;let u=[];for(let t=0;t<e.length;t++)u.push(e[t].toTheConceptId),u.push(e[t].ofTheConceptId),u.push(e[t].typeId);for(let u=0;u<e.length;u++){let h=!1;n.includes(e[u].id)&&(h=!0);let f=yield Ht(e[u].ofTheConceptId),y=yield Ht(e[u].toTheConceptId);if(1==h){if(0!=f.id&&0!=y.id){let n,s=null!==(i=null===(o=y.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self";e[u].toTheConceptId in t?n=t[e[u].toTheConceptId]:(n={},n[s]={},t[e[u].toTheConceptId]=n);let a=yield Ht(e[u].typeId);try{let e=null!==(c=null===(r=null==f?void 0:f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",n=f.characterValue;a.characterValue,a.characterValue.includes("_s_")&&(f.id in t||(t[f.id]={}),t[f.id][e]=n),t[y.id]={}}catch(e){}}}else if(0!=f.id&&0!=y.id){let n,o=null!==(a=null===(s=f.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[u].ofTheConceptId in t?n=t[e[u].ofTheConceptId]:(n={},n[o]={},t[e[u].ofTheConceptId]=n);let i=yield Ht(e[u].typeId);try{let e=null!==(d=null===(l=null==y?void 0:y.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"none",n=y.characterValue;i.characterValue.includes("_s_")&&(y.id in t||(t[y.id]={}),t[y.id][e]=n),t[f.id]={}}catch(e){}}}return t}))}var or=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ir(e,t="DESC"){return"ASC"==t?e.sort((function(e,t){return e.id-t.id})):e.sort((function(e,t){return t.id-e.id})),e}var rr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};var cr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function sr(e,t){return cr(this,void 0,void 0,(function*(){let t=e.outputFormat;e.outputFormat=ji;let o,i=yield function(e){return Di(this,arguments,void 0,(function*(e,t=""){var o=yield z("application/json",t);const i=n.FreeschemaQueryUrl(),r=JSON.stringify(e);try{const e=yield h(i,{method:"POST",headers:o,body:r});if(e.ok)return yield e.json();Q(e)}catch(e){!function(e,t=""){if(e.status){let n=new K(e.message,!1,e.status,e.stack);throw n.setUrl(t),n}{let n=new K(e.message,!1,500,e.stack);throw n.setUrl(t),n}}(e,i)}}))}(e,""),r=i.conceptIds,c=(i.internalConnections,i.linkers),s=i.reverse,a=i.mainCompositionIds,l=i.countinfo,d=e.order,u=function(e=[]){let t=[];if(e.length>0)for(let n=0;n<(null==e?void 0:e.length);n++){let o=Qi(e[n]);t.push(o)}return t}(l);return o=t==Oi?yield function(e,t,n,o,i){return rr(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield Jn(e),s=yield Ki(i);c=ir(c,r);let a=[];a=yield function(e,t){return er(this,arguments,void 0,(function*(e,t,n=[]){var o,i,r,c,s,a,l,d;let u=[];for(let t=0;t<e.length;t++)u.push(e[t].toTheConceptId),u.push(e[t].ofTheConceptId),u.push(e[t].typeId);for(let u=0;u<e.length;u++){let h=!1,f=yield Ht(e[u].ofTheConceptId),y=yield Ht(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Ht(e[u].typeId),a=null!==(i=null===(o=y.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self";e[u].toTheConceptId in t?n=t[e[u].toTheConceptId]:(n={},n[a]={},t[e[u].toTheConceptId]=n);try{let e=null!==(c=null===(r=null==f?void 0:f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",n=f.characterValue;(s.characterValue+"_reverse").includes("_s_")&&(f.id in t||(t[f.id]={}),t[f.id][e]=n),t[y.id]={}}catch(e){}}}else if(0!=f.id&&0!=y.id){let n,o=yield Ht(e[u].typeId),i=null!==(a=null===(s=f.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[u].ofTheConceptId in t?n=t[e[u].ofTheConceptId]:(n={},n[i]={},t[e[u].ofTheConceptId]=n);try{let e=null!==(d=null===(l=null==y?void 0:y.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"none",n=y.characterValue;o.characterValue.includes("_s_")&&(y.id in t||(t[y.id]={}),t[y.id][e]=n),t[f.id]={}}catch(e){}}}return t}))}(c,a,o),a=yield function(e,t){return er(this,arguments,void 0,(function*(e,t,n=[]){var o,i,r,c,s,a,l,d;let u=[];for(let t=0;t<e.length;t++)u.push(e[t].toTheConceptId),u.push(e[t].ofTheConceptId),u.push(e[t].typeId);for(let u=0;u<e.length;u++){let h=!1,f=yield Ht(e[u].ofTheConceptId),y=yield Ht(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Ht(e[u].typeId),a=null!==(i=null===(o=y.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self";e[u].toTheConceptId in t?(n=t[e[u].toTheConceptId],a in n||(n[a]={})):(n={},n[a]={},t[e[u].toTheConceptId]=n);try{let e=null!==(c=null===(r=null==f?void 0:f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",t=f.characterValue,o=s.characterValue;""==o&&(o=e,o=Yi(o));let i={id:f.id,data:{[e]:t}},l=o+"_reverse";l.includes("_s_")||("string"==typeof n[a]&&(n[a]={}),n[a][l]=i)}catch(e){}}}else if(0!=f.id&&0!=y.id){let n,o=yield Ht(e[u].typeId),i=null!==(a=null===(s=f.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[u].ofTheConceptId in t?(n=t[e[u].ofTheConceptId],i in n||(n[i]={})):(n={},n[i]={},t[e[u].ofTheConceptId]=n);try{let e=null!==(d=null===(l=null==y?void 0:y.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"none",t=y.characterValue,r=o.characterValue,c=!1;""==r&&(r=e,r=Yi(r),c=!0);let s={id:y.id,data:{[e]:t}};isNaN(Number(r))?r.includes("_s_")||("string"==typeof n[i]&&(n[i]={}),n[i][r]=s):(Array.isArray(n[i])||(n[i]=[]),n[i].push(s))}catch(e){}}}return t}))}(c,a,o);let l=yield function(e,t,n,o){return er(this,arguments,void 0,(function*(e,t,n,o,i=[],r){var c,s,a,l,d,u,h;(new Date).getTime();let f=[],y=[];for(let t=0;t<e.length;t++)y.push(e[t].toTheConceptId),y.push(e[t].ofTheConceptId),y.push(e[t].typeId);for(let n=0;n<e.length;n++){let o=!1,f=yield Ht(e[n].ofTheConceptId),y=yield Ht(e[n].toTheConceptId);if(i.includes(e[n].id)&&(o=!0),1==o){if(0!=f.id&&0!=y.id&&y.id in t){let o,i=yield Ht(e[n].typeId),a=null!==(s=null===(c=y.type)||void 0===c?void 0:c.characterValue)&&void 0!==s?s:"self",l=!1;e[n].toTheConceptId in t&&(l=!0),e[n].toTheConceptId in t?(o=t[e[n].toTheConceptId],"string"==typeof o[a]&&(o[a]={})):(o={},o[a]={},t[e[n].toTheConceptId]=o),Zi(y.id,r,o);try{if(t[e[n].ofTheConceptId]){let r={id:f.id,data:t[e[n].ofTheConceptId],created_on:e[n].entryTimeStamp},c=i.characterValue+"_reverse";Array.isArray(o[a][c])?o[a][c].push(r):c.includes("_s_")?(o[a][c]=[],o[a][c].push(r)):o[a][c]=r}}catch(e){}}}else if(0!=f.id&&0!=y.id&&f.id in t){let o,i=yield Ht(e[n].typeId),c=null!==(l=null===(a=f.type)||void 0===a?void 0:a.characterValue)&&void 0!==l?l:"self",s=!1;e[n].toTheConceptId in t&&(s=!0),e[n].ofTheConceptId in t?(o=t[e[n].ofTheConceptId],"string"==typeof o[c]&&(o[c]={})):(o={},o[c]={},t[e[n].ofTheConceptId]=o),Zi(f.id,r,o);let p=!0,v=i.characterValue;""==v&&(v=y.characterValue,p=!0),""==v&&(v=null!==(u=null===(d=null==y?void 0:y.type)||void 0===d?void 0:d.characterValue)&&void 0!==u?u:"");try{null===(h=null==y?void 0:y.type)||void 0===h||h.characterValue;let s=t[e[n].toTheConceptId];if(s){let a={id:y.id,data:t[e[n].toTheConceptId],created_on:e[n].entryTimeStamp};Array.isArray(o[c])?o[c].push(s):Array.isArray(o[c][v])?o[c][i.characterValue].push(a):v.includes("_s_")?(o[c][v]=[],o[c][v].push(a)):o[c][v]=a,Zi(y.id,r,a)}}catch(e){}}}for(let e=0;e<o.length;e++){let n={};n.id=o[e];let i=yield Ht(n.id);n.data=t[o[e]],n.created_on=i.entryTimeStamp,f.push(n)}return f}))}(c,a,[],n,o,s);return l}))}(c,r,a,s,u,d):t==Vi?yield function(e,t,n,o,i){return rr(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield Jn(e),s=yield Ki(i);c=ir(c,r);let a=[];a=yield nr(c,a,o),a=yield function(e,t){return Xi(this,arguments,void 0,(function*(e,t,n=[]){var o,i,r,c,s,a,l,d;let u=[];for(let t=0;t<e.length;t++)u.push(e[t].toTheConceptId),u.push(e[t].ofTheConceptId),u.push(e[t].typeId);for(let u=0;u<e.length;u++){let h=!1,f=yield Ht(e[u].ofTheConceptId),y=yield Ht(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Ht(e[u].typeId),a=null!==(i=null===(o=y.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self";e[u].toTheConceptId in t?(n=t[e[u].toTheConceptId],a in n||(n[a]={})):(n={},n[a]={},t[e[u].toTheConceptId]=n);try{let e=null!==(c=null===(r=null==f?void 0:f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",t=f.characterValue,o=s.characterValue;""==o&&(o=e,o=Yi(o));let i={id:f.id,[e]:t},l=o+"_reverse";l.includes("_s_")||("string"==typeof n[a]&&(n[a]={}),n[a][l]=i)}catch(e){}}}else if(0!=f.id&&0!=y.id){let n,o=yield Ht(e[u].typeId),i=null!==(a=null===(s=f.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[u].ofTheConceptId in t?(n=t[e[u].ofTheConceptId],i in n||(n[i]={})):(n={},n[i]={},t[e[u].ofTheConceptId]=n);try{let t=null!==(d=null===(l=null==y?void 0:y.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"none",r=y.characterValue,c=o.characterValue,s=!1;""==c&&(c=t,c=Yi(c),s=!0);let a={};a[t]={id:y.id,data:r,created_on:e[u].entryTimeStamp},isNaN(Number(c))?c.includes("_s_")||("string"==typeof n[i]&&(n[i]={}),n[i][c]=s?a[t]:a):(Array.isArray(n[i])||(n[i]=[]),n[i].push(a[t]))}catch(e){}}}return t}))}(c,a,o);let l=yield function(e,t,n){return Xi(this,arguments,void 0,(function*(e,t,n,o=[],i){var r,c,s,a,l,d,u,h;(new Date).getTime();let f=[],y=[];for(let t=0;t<e.length;t++)y.push(e[t].toTheConceptId),y.push(e[t].ofTheConceptId),y.push(e[t].typeId);for(let n=0;n<e.length;n++){let f=!1,y=yield Ht(e[n].ofTheConceptId),p=yield Ht(e[n].toTheConceptId);if(o.includes(e[n].id)&&(f=!0),1==f){if(0!=y.id&&0!=p.id&&p.id in t){let o,i=yield Ht(e[n].typeId),s=null!==(c=null===(r=p.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"self",a=!1;e[n].toTheConceptId in t&&(a=!0),e[n].toTheConceptId in t?(o=t[e[n].toTheConceptId],"string"==typeof o[s]&&(o[s]={})):(o={},o[s]={},t[e[n].toTheConceptId]=o);try{if(t[e[n].ofTheConceptId]){let r=t[e[n].ofTheConceptId];r&&(r.id=y.id,r.created_on=y.entryTimeStamp);let c=i.characterValue+"_reverse";Array.isArray(o[s][c])?o[s][c].push(r):c.includes("_s_")?(o[s][c]=[],o[s][c].push(r)):o[s][c]=r}}catch(e){}}}else if(0!=y.id&&0!=p.id&&y.id in t){let o,r=yield Ht(e[n].typeId),c=null!==(a=null===(s=y.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self",f=!1;e[n].toTheConceptId in t&&(f=!0),e[n].ofTheConceptId in t?(o=t[e[n].ofTheConceptId],"string"==typeof o[c]&&(o[c]={})):(o={},o[c]={},t[e[n].ofTheConceptId]=o),Zi(y.id,i,o);let v=!1,g=r.characterValue;""==g&&(g=p.characterValue,v=!0),""==g&&(g=null!==(d=null===(l=null==p?void 0:p.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"");try{let r=null!==(h=null===(u=null==p?void 0:p.type)||void 0===u?void 0:u.characterValue)&&void 0!==h?h:"none",s=t[e[n].toTheConceptId];if(s){let t={};t[r]={data:s[r],id:p.id,created_on:e[n].entryTimeStamp},Array.isArray(o[c])?v?o[c].push(s[g]):o[c].push(s):Array.isArray(o[c][g])?o[c][g].push(t):g.includes("_s_")?(o[c][g]=[],v?o[c][g].push(t[r]):o[c][g].push(t)):o[c][g]=v?t[r]:t,Zi(p.id,i,t)}}catch(e){}}}for(let e=0;e<n.length;e++){let o={};o=t[n[e]],o&&(o.id=n[e]),f.push(o)}return f}))}(c,a,n,o,s);return l}))}(c,r,a,s,u,d):t==Ji?yield function(e,t,n,o,i){return rr(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield Jn(e),s=yield Ki(i);c=ir(c,r);let a={};a=yield function(e){return or(this,arguments,void 0,(function*(e,t={},n=[]){var o,i,r,c,s;for(const a of e){const e=n.includes(a.id),l=yield Ht(a.ofTheConceptId),d=yield Ht(a.toTheConceptId),u=yield Ht(a.typeId);if(0===l.id||0===d.id)continue;const h=e?d:l,f=e?l:d,y=null!==(i=null===(o=h.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self",p=null!==(c=null===(r=f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",v=f.characterValue,g=null===(s=u.characterValue)||void 0===s?void 0:s.includes("_s_");t[h.id]||(t[h.id]={}),t[h.id][y]||(t[h.id][y]={}),g&&(t[f.id]||(t[f.id]={}),t[f.id][p]=v)}return t}))}(c,a,o),a=yield function(e){return or(this,arguments,void 0,(function*(e,t={},n=[]){var o,i,r,c,s;for(const a of e){const e=n.includes(a.id),l=yield Ht(a.ofTheConceptId),d=yield Ht(a.toTheConceptId),u=yield Ht(a.typeId);if(0===l.id||0===d.id)continue;const h=e?d:l,f=e?l:d,y=null!==(i=null===(o=h.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self",p=null!==(c=null===(r=f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",v=f.characterValue,g=null!==(s=u.characterValue)&&void 0!==s?s:"";let C=""===g?Yi(p):g;const m=C.includes("_s_"),T=!isNaN(Number(C)),w={id:f.id,data:{[p]:v}};t[h.id]||(t[h.id]={}),y in t[h.id]&&"string"!=typeof t[h.id][y]||(t[h.id][y]=T?[]:{});try{if(m)continue;T?t[h.id][y].push(w):t[h.id][y][e?`${C}_reverse`:C]=w}catch(e){console.error("Error formatting concept data:",e)}}return t}))}(c,a,o);let l=yield function(e,t,n){return or(this,arguments,void 0,(function*(e,t,n,o=[],i){var r,c,s;const a=[];for(const n of e){const e=o.includes(n.id),a=yield Ht(n.ofTheConceptId),l=yield Ht(n.toTheConceptId),d=yield Ht(n.typeId);if(0===a.id||0===l.id)continue;const u=e?l:a,h=e?a:l,f=u.id,y=h.id,p=null!==(c=null===(r=u.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"self",v=d.characterValue+"_reverse",g=d.characterValue||h.characterValue||(null===(s=h.type)||void 0===s?void 0:s.characterValue)||"";if(t[f]){const o=t[f][p],r=t[y],c={id:h.id,data:r,created_on:n.entryTimeStamp};Zi(f,i,t[f]);try{e?Array.isArray(o[v])?o[v].push(c):o[v]=[c]:Array.isArray(o)?o.push(r):Array.isArray(o[g])?o[g].push(c):g.includes("_s_")?(o[g]=[],o[g].push(c)):o[g]=[c],Zi(y,i,c)}catch(e){console.error("Error processing connection:",e)}}}for(const e of n){const n=yield Ht(e);a.push({id:e,data:t[e],created_on:n.entryTimeStamp})}return a}))}(c,a,n,o,s);return l}))}(c,r,a,s,u,d):yield function(e,t,n,o){return rr(this,void 0,void 0,(function*(){let t=yield Jn(e);t=ir(t);let i=[];i=yield nr(t,i,o),i=yield function(e,t,n){return tr(this,void 0,void 0,(function*(){var o,i,r,c,s,a,l,d;let u=[];for(let t=0;t<e.length;t++)u.push(e[t].toTheConceptId),u.push(e[t].ofTheConceptId),u.push(e[t].typeId);e.sort((function(e,t){return t.id-e.id}));for(let u=0;u<e.length;u++){let h=!1;n.includes(e[u].id)&&(h=!0);let f=yield Ht(e[u].ofTheConceptId),y=yield Ht(e[u].toTheConceptId);if(1==h){if(0!=f.id&&0!=y.id){let n,s=null!==(i=null===(o=y.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self";e[u].toTheConceptId in t?(n=t[e[u].toTheConceptId],s in n||(n[s]={})):(n={},n[s]={},t[e[u].toTheConceptId]=n);let a=yield Ht(e[u].typeId);try{let e=null!==(c=null===(r=null==f?void 0:f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",t=f.characterValue,o=a.characterValue;""==o&&(o=e,o=Yi(o));let i={[e]:t},l=o+"_reverse";a.characterValue.includes("_s_")||("string"==typeof n[s]&&(n[s]={}),n[s][l]=i)}catch(e){}}}else if(0!=f.id&&0!=y.id){let n,o=null!==(a=null===(s=f.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[u].ofTheConceptId in t?(n=t[e[u].ofTheConceptId],o in n||(n[o]={})):(n={},n[o]={},t[e[u].ofTheConceptId]=n);let i=yield Ht(e[u].typeId);try{let e=null!==(d=null===(l=null==y?void 0:y.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"none",t=y.characterValue,r=i.characterValue,c=(i.characterValue,!1);""==r&&(r=e,r=Yi(r),c=!0);let s={[e]:t};isNaN(Number(r))?i.characterValue.includes("_s_")||("string"==typeof n[o]&&(n[o]={}),n[o][r]=c?t:s):(Array.isArray(n[o])||(n[o]=[]),n[o].push(t))}catch(e){}}}return t}))}(t,i,o);let r=yield function(){return tr(this,arguments,void 0,(function*(e=[],t=[],n=[],o,i=[]){var r,c,s,a,l,d;let u=[],h=[];for(let t=0;t<e.length;t++)h.push(e[t].toTheConceptId),h.push(e[t].ofTheConceptId),h.push(e[t].typeId);e.sort((function(e,t){return t.id-e.id}));for(let n=0;n<e.length;n++){let o=!1;i.includes(e[n].id)&&(o=!0);let u=yield Ht(e[n].ofTheConceptId),h=yield Ht(e[n].toTheConceptId);if(1==o){if(0!=u.id&&0!=h.id&&h.id in t){let o,i=null!==(c=null===(r=h.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"self";e[n].toTheConceptId in t?o=t[e[n].toTheConceptId]:(o={},o[i]={},t[e[n].toTheConceptId]=o);let s=yield Ht(e[n].typeId);try{let r=s.characterValue+"_reverse",c=t[e[n].ofTheConceptId];c&&(Array.isArray(o[i][r])?o[i][r].push(c):s.characterValue.includes("_s_")?(o[i][r]=[],o[i][r].push(c)):o[i][r]=c)}catch(e){}}}else if(0!=u.id&&0!=h.id&&u.id in t){let o,i=null!==(a=null===(s=u.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[n].ofTheConceptId in t?(o=t[e[n].ofTheConceptId],"string"==typeof o[i]&&(o[i]={})):(o={},o[i]={},t[e[n].ofTheConceptId]=o);let r=!1,c=(yield Ht(e[n].typeId)).characterValue;""==c&&(c=h.characterValue,r=!0),""==c&&(c=null!==(d=null===(l=null==h?void 0:h.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"");try{let s=t[e[n].toTheConceptId];s&&(Array.isArray(o[i])?r?o[i].push(s[c]):o[i].push(s):Array.isArray(o[i][c])?o[i][c].push(s):c.includes("_s_")?(o[i][c]=[],r?o[i][c].push(s[c]):o[i][c].push(s)):o[i][c]=r?s[c]:s)}catch(e){}}}for(let e=0;e<n.length;e++){let o=t[n[e]];o&&(o.id=n[e],u.push(o))}return u}))}(t,i,n,[],o);return r}))}(c,0,a,s),o}))}class ar{constructor(){this.type="",this.inpage=10,this.page=1,this.concepts=[],this.conceptIds=[],this.selectors=[],this.freeschemaQueries=[],this.filters=[],this.filterLogic="",this.typeConnection="",this.order="DESC",this.outputFormat=$i,this.name="",this.reverse=!1,this.limit=!1,this.filterAncestor="",this.includeInFilter=!1,this.isOldConnectionType=!1,this.usePipelineQuery=!1}}var lr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function dr(e,t){return lr(this,arguments,void 0,(function*(e,t,n=!1){let o=[];if(n){let n=yield xn(e),i=yield Ke(t);for(let e=0;e<n.length;e++)n[e].typeId==i.id&&o.push(n[e])}else{let n=yield kn(e);for(let e=0;e<n.length;e++)se.AddConnection(n[e]);let i=yield Ke(t);for(let e=0;e<n.length;e++)n[e].typeId==i.id&&o.push(n[e])}return o}))}function ur(e,t,n){return lr(this,arguments,void 0,(function*(e,t,n,o=!1){let i=[],r=[];if(i=o?yield dr(t,n,o):yield dr(e,n,o),o)for(let t=0;t<i.length;t++)i[t].ofTheConceptId==e&&r.push(i[t]);else for(let e=0;e<i.length;e++)i[e].toTheConceptId==t&&r.push(i[e]);return r}))}var hr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function fr(e){return hr(this,void 0,void 0,(function*(){try{const t=yield q(),o=yield h(n.GetConnectionsBetweenUrl(),{method:"POST",headers:t,body:JSON.stringify(e)});if(!o.ok)throw console.log("GetConnectionsBetweenApi error status: ",o.status),Q(o),new Error(`GetConnectionsBetweenApi error: ${o.status}`);return yield o.json()}catch(e){throw e instanceof Error?console.log("GetConnectionsBetweenApi error message: ",e.message):console.log("GetConnectionsBetweenApi unexpected error: ",e),e}}))}function yr(e){var t,n,o,i,r,c,s;return{ofTheConceptId:null!==(t=e.ofTheConceptId)&&void 0!==t?t:0,toTheConceptId:null!==(n=e.toTheConceptId)&&void 0!==n?n:0,typeId:null!==(o=e.typeId)&&void 0!==o?o:0,type:null!==(i=e.type)&&void 0!==i?i:"",oldType:null!==(r=e.oldType)&&void 0!==r?r:"",reverse:null!==(c=e.reverse)&&void 0!==c&&c,isComposition:null!==(s=e.isComposition)&&void 0!==s&&s,connectionIds:[]}}var pr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class vr{constructor(){this.actions={concepts:[],connections:[]},this.success=!0,this.pendingConnectionDeletions=[],this.transactionId=Math.random().toString().substring(5)}initialize(){return pr(this,void 0,void 0,(function*(){yield vt.initializeTransaction(this.transactionId)}))}markAction(){return pr(this,void 0,void 0,(function*(){yield vt.markTransactionActions(this.transactionId,this.actions)}))}rollbackTransaction(){return pr(this,void 0,void 0,(function*(){this.success=!1,this.actions={concepts:[],connections:[]},this.pendingConnectionDeletions=[],yield vt.rollbackTransaction(this.transactionId,this.actions)}))}commitTransaction(){return pr(this,void 0,void 0,(function*(){if(!this.success)throw Error("Query Transaction Expired");yield vt.SyncDataOnline(this.transactionId),this.pendingConnectionDeletions.length>0&&(yield Vt(this.pendingConnectionDeletions)),this.actions={concepts:[],connections:[]},this.pendingConnectionDeletions=[],this.success=!1}))}DeleteConnectionsBetween(e){return pr(this,void 0,void 0,(function*(){return this.DeleteConnectionsBetweenBulk([e])}))}DeleteConnectionsBetweenBulk(e){return pr(this,void 0,void 0,(function*(){try{if(!this.success)throw Error("Query Transaction Expired");const t=e.map(yr),n=yield fr(t),o=[];for(const e of n)o.push(...e.connectionIds);return this.pendingConnectionDeletions.push(...o),o}catch(e){throw console.log(e),this.success=!1,e}}))}MakeTheInstanceConcept(e,t){return pr(this,arguments,void 0,(function*(e,t,n=!1,o,i,r=999,c=0){try{if(!this.success)throw Error("Query Transaction Expired");const s=yield Rt(e,t,n,o,i,r,c,this.actions);return yield this.markAction(),s}catch(e){throw console.log(e),this.success=!1,e}}))}CreateTypeConcept(e,t){return pr(this,arguments,void 0,(function*(e,t,n=("number"==typeof e?999:e.userId),o=("number"==typeof e?4:e.accessId),i=999){try{if(!this.success)throw Error("Query Transaction Expired");return yield sn(e,t,n,o,i)}catch(e){throw console.log(e),this.success=!1,e}}))}CreateConnection(e,t,n){return pr(this,void 0,void 0,(function*(){try{if(!this.success)throw Error("Query Transaction Expired");const o=yield Tt(e,t,n,this.actions);return yield this.markAction(),o}catch(e){throw console.log(e),this.success=!1,e}}))}MakeTheTypeConcept(e,t,n,o){return pr(this,void 0,void 0,(function*(){try{if(!this.success)throw Error("Query Transaction Expired");const i=yield Nn(e,t,n,o,this.actions);return yield this.markAction(),i}catch(e){throw console.log(e),this.success=!1,e}}))}CreateTheConnectionGeneral(e,t,n,o,i,r,c){return pr(this,arguments,void 0,(function*(e,t,n,o,i,r,c,s=1,a=4,l=999){try{if(!this.success)throw Error("Query Transaction Expired");const d=yield mt(e,t,n,o,i,r,c,s,a,l,this.actions);return yield this.markAction(),d}catch(e){throw console.log(e),this.success=!1,e}}))}}var gr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Cr(e=""){o.BearerAccessToken=e}function mr(){return gr(this,arguments,void 0,(function*(e="",t="",i="CCSApp",c){var s,a;const l=c||new hi;bi.setBaseUrl(l.accessControlBaseUrl),bi.setEnabled(l.enableAccessControl),n.BASE_URL=e,n.AI_URL=l.aiUrl,t&&(n.NODE_URL=t);const d=l.cacheServers.length>0?l.cacheServers:ui(null!==(a=null===(s=l.parameters)||void 0===s?void 0:s.cacheServers)&&void 0!==a?a:l.getParameter("cacheServers",""));n.setCacheServers(d);const u=l.cacheServerUrl||l.getParameter("cacheServerUrl","");if(u?n.setNodeCacheUrl(u):0===d.length&&n.setNodeCacheUrl(""),l.hasOAuthCredentials()){const e=l.applicationName||i;o.setOAuthCredentials(l.clientId,l.clientSecret,e);const t=yield r(l.clientId,l.clientSecret,e,!0);if(!t.success)throw new Error(`OAuth token request failed: ${t.error||"unknown error"}`)}else l.hasAccessToken()&&(o.BearerAccessToken=l.accessToken);E.isDataLoaded=!1,E.isCharacterLoaded=!1,E.isTypeLoaded=!1,E.isLocalDataLoaded=!1,E.isLocalTypeLoaded=!1,E.isLocalCharacterLoaded=!1,E.isConnectionLoaded=!1,E.isConnectionTypeLoaded=!1,E.isLocalConnectionLoaded=!1,yield function(){return Ui(this,void 0,void 0,(function*(){return yield A("settings")[0]||new w(!0),yield function(){return Ri(this,void 0,void 0,(function*(){}))}(),!0}))}(),yield Promise.all([j().then((()=>{E.isDataLoaded=!0,E.isCharacterLoaded=!0,E.isTypeLoaded=!0})),_i().then((()=>{E.isLocalDataLoaded=!0,E.isLocalTypeLoaded=!0,E.isLocalCharacterLoaded=!0})),gi().then((()=>{E.isLocalConnectionLoaded=!0})),vi().then((()=>{E.isConnectionLoaded=!0,E.isConnectionTypeLoaded=!0}))])}))}module.exports=t})();
|
|
1
|
+
(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{ALLID:()=>Ki,AccessControlService:()=>Mi,AddGhostConcept:()=>Ko,AddGhostConnection:()=>Qo,BaseUrl:()=>n,BinaryTree:()=>G,CCSConfig:()=>gi,Composition:()=>yo,CompositionBinaryTree:()=>lo,CompositionNode:()=>so,Concept:()=>F,ConceptsData:()=>M,Connection:()=>ee,ConnectionData:()=>se,CreateComposition:()=>Bt,CreateConnection:()=>Tt,CreateConnectionBetweenTwoConcepts:()=>tn,CreateConnectionBetweenTwoConceptsGeneral:()=>on,CreateDefaultConcept:()=>b,CreateDefaultLConcept:()=>hn,CreateSession:()=>Po,CreateSessionVisit:()=>Fo,CreateTheCompositionWithCache:()=>vo,CreateTheConnectionGeneral:()=>mt,CreateTypeConcept:()=>sn,DATAID:()=>Wi,DATAIDDATE:()=>zi,DATAV2:()=>Yi,DeleteConceptById:()=>Pn,DeleteConnectionById:()=>Ot,DeleteConnectionByIdBulk:()=>Vt,DeleteConnectionByTypeBulk:()=>di,FilterSearch:()=>yi,FormatFromConnections:()=>ti,FreeSchemaResponse:()=>K,FreeschemaQuery:()=>fr,GetAllConnectionsOfComposition:()=>we,GetAllConnectionsOfCompositionBulk:()=>ve,GetAllTheConnectionsByTypeAndOfTheConcept:()=>pr,GetComposition:()=>Ae,GetCompositionBulk:()=>Hn,GetCompositionBulkWithDataId:()=>jn,GetCompositionFromConnectionsWithDataId:()=>Wn,GetCompositionFromConnectionsWithDataIdInObject:()=>zn,GetCompositionList:()=>$e,GetCompositionListWithId:()=>Oe,GetCompositionWithAllIds:()=>ke,GetCompositionWithCache:()=>Ro,GetCompositionWithDataIdBulk:()=>Uo,GetCompositionWithDataIdWithCache:()=>Bo,GetCompositionWithId:()=>Be,GetCompositionWithIdFromMemory:()=>xe,GetCompositionWithIdFromMemoryFromConnections:()=>Re,GetConceptBulk:()=>le,GetConceptByCharacter:()=>be,GetConceptByCharacterAndCategoryDirectApi:()=>He,GetConceptByCharacterAndType:()=>Nt,GetConceptByTypeBulk:()=>At,GetConnectionBulk:()=>Vn,GetConnectionById:()=>Dt,GetConnectionByTypeBulk:()=>ui,GetConnectionOfTheConcept:()=>Lt,GetConnectionsBetweenApi:()=>Co,GetLink:()=>ln,GetLinkRaw:()=>dn,GetLinkerConnectionFromConcepts:()=>Rn,GetLinkerConnectionToConcepts:()=>En,GetRelation:()=>Oo,GetRelationRaw:()=>Vo,GetRequestHeader:()=>z,GetRequestHeaderWithAuthorization:()=>q,GetTheConcept:()=>Ht,GetUserGhostConnectionId:()=>qo,GetUserGhostId:()=>zo,GiveConnection:()=>vr,HandleHttpError:()=>Q,HttpResponse:()=>l,JUSTDATA:()=>Ji,LConcept:()=>un,LConnection:()=>Ho,LISTNORMAL:()=>Qi,LoginToBackend:()=>Yn,MakeTheInstanceConcept:()=>Rt,MakeTheTimestamp:()=>Dn,MakeTheTypeConcept:()=>Nn,MakeTheTypeConceptApi:()=>Ke,NORMAL:()=>ji,PatcherStructure:()=>hi,PermissionSet:()=>Di,RAW:()=>qi,RecursiveSearchApi:()=>Kn,ReservedConnectionIds:()=>at,ReservedIds:()=>st,SchemaQueryListener:()=>hr,SearchAllConcepts:()=>ko,SearchLinkInternal:()=>ai,SearchLinkMultipleAll:()=>ei,SearchLinkMultipleApi:()=>Xo,SearchQuery:()=>$n,SearchStructure:()=>pi,SearchWithLinker:()=>xo,SessionData:()=>fi,Signin:()=>to,Signup:()=>Zn,SplitStrings:()=>W,SyncData:()=>vt,TokenRefreshError:()=>a,TokenStorage:()=>o,Transaction:()=>wo,TrashTheConcept:()=>Fn,UpdateComposition:()=>No,UserBinaryTree:()=>Wo,ViewInternalData:()=>ii,buildFetchConnection:()=>mo,convertFromLConceptToConcept:()=>ri,deleteWithRetry:()=>v,fetchWithCacheServerFallback:()=>T,fetchWithRetry:()=>h,getFromDatabaseWithType:()=>S,getFromDatabaseWithTypeOld:()=>x,getOAuthToken:()=>r,getWithRetry:()=>y,init:()=>mr,patchWithRetry:()=>g,postWithRetry:()=>f,putWithRetry:()=>p,recursiveFetch:()=>Ue,recursiveFetchNew:()=>ho,refreshOAuthToken:()=>c,requestWithRetry:()=>u,storeToDatabase:()=>k,updateAccessToken:()=>Cr});class n{static setNodeCacheUrl(e=""){this.NODE_CACHE_URL=e,this.isNearestCache=!0}static setCacheServers(e=[]){this.CACHE_SERVERS=e.filter((e=>"string"==typeof e&&""!==e.trim())),this.NODE_CACHE_URL=this.CACHE_SERVERS.length>0?this.CACHE_SERVERS[0]:"",this.isNearestCache=!0}static GetReadBaseUrl(){return this.NODE_CACHE_URL&&""!==this.NODE_CACHE_URL.trim()?this.NODE_CACHE_URL:this.BASE_URL}static GetNodeBaseUrl(){return this.NODE_URL&&""!==this.NODE_URL.trim()?this.NODE_URL:this.BASE_URL}static GetReadBaseUrlCandidates(){const e=[this.NODE_CACHE_URL,...this.CACHE_SERVERS,this.GetNodeBaseUrl(),this.BASE_URL].filter((e=>"string"==typeof e&&""!==e.trim())).map((e=>e.trim()));return Array.from(new Set(e))}static GetConceptUrl(){return this.BASE_URL+"/api/getConcept"}static GetConnectionUrl(){return this.BASE_URL+"/api/get-connection-by-id"}static GetConceptBulkUrl(){return this.GetNodeBaseUrl()+"/api/get_concept_bulk"}static GetConnectionBulkUrl(){return this.GetNodeBaseUrl()+"/api/get_connection_bulk"}static GetAllConceptsOfUserUrl(){return this.BASE_URL+"/api/get_all_concepts_of_user"}static GetAllConnectionsOfUserUrl(){return this.BASE_URL+"/api/get_all_connections_of_user"}static GetConnectionsBetweenUrl(){return this.BASE_URL+"/api/get-connection-between"}static GetAllConnectionsOfCompositionUrl(){return this.BASE_URL+"/api/get_all_connections_of_composition"}static GetAllConnectionsOfCompositionBulkUrl(){return this.BASE_URL+"/api/get_all_connections_of_composition_bulk"}static GetConceptByCharacterValueUrl(){return this.BASE_URL+"/api/get_concept_by_character_value"}static GetConceptByCharacterAndTypeUrl(){return this.BASE_URL+"/api/get_concept_by_character_and_type"}static GetConceptByCharacterAndCategoryUrl(){return this.BASE_URL+"/api/get_concept_by_character_and_category"}static GetConceptByCharacterAndCategoryDirectUrl(){return this.BASE_URL+"/api/get_concept_by_character_and_category_direct"}static GetCharacterByCharacterUrl(){return this.BASE_URL+"/api/get_character_by_character"}static GetAllConceptsByTypeUrl(){return this.BASE_URL+"/api/get_all_concepts_by_type"}static GetAllConnectionsOfConceptUrl(){return this.BASE_URL+"/api/get-link-connections"}static GetAllConnectionsToConceptUrl(){return this.BASE_URL+"/api/get-link-reverse-connections"}static GetAllAiData(){return this.BASE_URL+"/api/get-preloaded-concepts"}static GetAllPrefetchConnectionsUrl(){return this.BASE_URL+"/api/get_all_connections_of_user?inpage=500"}static GetAllLinkerConnectionOfConceptUrl(){return this.BASE_URL+"/api/get-all-linkers-from-concept"}static GetAllLinkerConnectionToConceptUrl(){return this.BASE_URL+"/api/get-all-linkers-to-concept"}static DeleteConceptUrl(){return this.BASE_URL+"/api/delete_concept"}static RecursiveSearchUrl(){return this.BASE_URL+"/api/recursivesearch-concept-connection"}static SearchLinkMultipleAllApiUrl(){return this.BASE_URL+"/api/Connection/search-link-multiple-all-ccs"}static MakeTheNameInBackendUrl(){return this.BASE_URL+"/api/make-name-from-frontend"}static LoginUrl(){return this.BASE_URL+"/api/auth/login"}static SignupUrl(){return this.BASE_URL+"/api/auth/signup"}static GetCompositionConnectionBetweenTwoConceptsUrl(){return this.BASE_URL+"/api/get-composition-connection-between-two-concepts"}static SearchCompositionsUrl(){return this.BASE_URL+"/api/search-compositions"}static SearchLinkMultipleAll(){return this.BASE_URL+"/api/Connection/search-link-multiple-all"}static CreateSessionId(){return this.BASE_URL+"/api/create-session-id-remote"}static CreateSessionVisitUrl(){return this.BASE_URL+"/api/create-remote-session-visit"}static ViewInternalDataUrl(){return this.BASE_URL+"/api/view-api-internal-data-ccs-id-bulk"}static SearchInternalWithAuthenticatedCcsUrl(){return this.BASE_URL+"/api/search-composition-internal-authenticated-ccs"}static GetReservedIdUrl(){return this.BASE_URL+"/api/get_reserved_ids"}static GetReservedConnectionIdUrl(){return this.BASE_URL+"/api/get_reserved_connection_ids"}static CreateTheTextDataUrl(){return this.BASE_URL+"/api/create_text_data"}static CreateTheCharacterDataUrl(){return this.BASE_URL+"/api/create_character_data"}static CreateTheConceptUrl(){return this.BASE_URL+"/api/create_the_concept"}static CreateTheConnectionUrl(){return this.BASE_URL+"/api/create_the_connection"}static CreateTheConnectionNewUrl(){return this.BASE_URL+"/api/create_the_connection_new"}static MakeTheTypeConceptUrl(){return this.BASE_URL+"/api/make_the_type_concept"}static CreateTypeConceptUrl(){return this.BASE_URL+"/api/create_type_concept"}static DeleteTheConnectionUrl(){return this.BASE_URL+"/api/delete_connection"}static DeleteTheConnectionBulkUrl(){return this.BASE_URL+"/api/delete_connection_bulk"}static FreeschemaQueryUrl(){return this.BASE_URL+"/api/freeschema-query"}static GetConceptConnectionByType(){return this.BASE_URL+"/api/get_type_concept_by_character_bulk"}static OAuthTokenUrl(){return this.BASE_URL+"/api/oauth/token"}static OAuthRefreshUrl(){return this.BASE_URL+"/api/oauth/refresh"}}n.BASE_URL="https://localhost:7053/",n.NODE_CACHE_URL="",n.CACHE_SERVERS=[],n.isNearestCache=!0,n.AI_URL="https://ai.freeschema.com",n.MQTT_URL="192.168.1.249",n.NODE_URL="";class o{static getAuthHeader(){return this.BearerAccessToken?{Authorization:`Bearer ${this.BearerAccessToken}`}:{}}static setToken(e,t){this.BearerAccessToken=e,this.TOKEN_EXPIRY=t&&t>0?Date.now()+1e3*t:Date.now()+36e5}static isTokenExpiredOrNearExpiry(){return!!this.TOKEN_EXPIRY&&Date.now()>=this.TOKEN_EXPIRY-this.EXPIRY_BUFFER_MS}static getTimeUntilExpiry(){if(!this.TOKEN_EXPIRY)return-1;const e=Date.now(),t=this.TOKEN_EXPIRY-e;return t>0?Math.floor(t/1e3):-1}static hasOAuthCredentials(){return!!(this.CLIENT_ID&&this.CLIENT_SECRET&&this.APPLICATION_NAME)}static setOAuthCredentials(e,t,n){this.CLIENT_ID=e,this.CLIENT_SECRET=t,this.APPLICATION_NAME=n}}o.BearerAccessToken="",o.CLIENT_ID="",o.CLIENT_SECRET="",o.APPLICATION_NAME="",o.TOKEN_EXPIRY=0,o.EXPIRY_BUFFER_MS=3e5;var i=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function r(e,t,r){return i(this,arguments,void 0,(function*(e,t,i,r=!0){try{const c=n.OAuthTokenUrl(),s=new URLSearchParams;s.append("client_id",e),s.append("client_secret",t),s.append("application_name",i);const a=yield fetch(c,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s.toString()});if(a.ok){let e="",t="Bearer",n=0;const i=a.headers.get("content-type");if(i&&i.includes("application/json"))try{const o=yield a.json();e=o.access_token||"",t=o.token_type||"Bearer",n=o.expires_in||0}catch(t){e=yield a.text()}else e=yield a.text();return e?(r&&o.setToken(e,n),{success:!0,access_token:e,token_type:t,expires_in:n}):{success:!1,error:"No access token in response"}}{const e=yield a.text();return{success:!1,error:`HTTP ${a.status}: ${e}`}}}catch(e){return e instanceof TypeError?{success:!1,error:`Network error: ${e.message}`}:{success:!1,error:`Unexpected error: ${e instanceof Error?e.message:String(e)}`}}}))}function c(e,t,r){return i(this,arguments,void 0,(function*(e,t,i,r=!0){try{const c=n.OAuthRefreshUrl(),s=new URLSearchParams;s.append("client_id",e),s.append("client_secret",t),s.append("refresh_token",i),s.append("grant_type","refresh_token");const a=yield fetch(c,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s.toString()});if(a.ok){let e="",t="Bearer",n=0;const i=a.headers.get("content-type");if(i&&i.includes("application/json"))try{const o=yield a.json();e=o.access_token||"",t=o.token_type||"Bearer",n=o.expires_in||0}catch(t){e=yield a.text()}else e=yield a.text();return e?(r&&o.setToken(e,n),{success:!0,access_token:e,token_type:t,expires_in:n}):{success:!1,error:"No access token in response"}}{const e=yield a.text();return{success:!1,error:`HTTP ${a.status}: ${e}`}}}catch(e){return e instanceof TypeError?{success:!1,error:`Network error: ${e.message}`}:{success:!1,error:`Unexpected error: ${e instanceof Error?e.message:String(e)}`}}}))}var s=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class a extends Error{constructor(e){super(e),this.name="TokenRefreshError"}}class l{constructor(e,t,n){this.status=e,this.body=t,this.headers=n}json(){return s(this,void 0,void 0,(function*(){return JSON.parse(this.body)}))}text(){return s(this,void 0,void 0,(function*(){return this.body}))}get ok(){return this.status>=200&&this.status<300}}function d(){return s(this,void 0,void 0,(function*(){if(!o.hasOAuthCredentials())return!1;try{return(yield r(o.CLIENT_ID,o.CLIENT_SECRET,o.APPLICATION_NAME,!0)).success}catch(e){return console.error("Token refresh failed:",e),!1}}))}function u(e,t,n,i){return s(this,arguments,void 0,(function*(e,t,n,i,r=1){var c,s;const u=Object.assign(Object.assign({},n),o.getAuthHeader()),h=["GET","HEAD","OPTIONS"].includes(e.toUpperCase());for(let n=0;n<=r;n++)try{const h={method:e,headers:u};void 0!==i&&("object"==typeof i?(u["Content-Type"]||u["content-type"]||(u["Content-Type"]="application/json"),(null===(c=u["Content-Type"])||void 0===c?void 0:c.includes("application/json"))||(null===(s=u["content-type"])||void 0===s?void 0:s.includes("application/json"))?h.body=JSON.stringify(i):h.body=i):h.body=i),h.headers=u;const f=yield fetch(t,h),y=yield f.text(),p={};if(f.headers.forEach(((e,t)=>{p[t]=e})),401!==f.status)return new l(f.status,y,p);if(n<r){if(yield d()){Object.assign(u,o.getAuthHeader());continue}throw new a("Token refresh failed. Please check OAuth credentials.")}return new l(f.status,y,p)}catch(e){if(e instanceof a)throw e;if(n>=r||!h)throw e;console.error(`Request failed (attempt ${n+1}/${r+1}):`,e)}throw new Error("Request failed after all retry attempts")}))}function h(e){return s(this,arguments,void 0,(function*(e,t={},n=1){return u(t.method||"GET",e,function(e){if(e){if(e instanceof Headers){const t={};return e.forEach(((e,n)=>{t[n]=e})),t}return Array.isArray(e)?e.reduce(((e,[t,n])=>(e[t]=n,e)),{}):e}}(t.headers),t.body,n)}))}function f(e,t,n){return s(this,void 0,void 0,(function*(){return u("POST",e,t,n)}))}function y(e,t,n){return s(this,void 0,void 0,(function*(){let o=e;if(n){const t=[];for(const e in n)n.hasOwnProperty(e)&&t.push(`${encodeURIComponent(e)}=${encodeURIComponent(String(n[e]))}`);t.length>0&&(o=`${e}?${t.join("&")}`)}return u("GET",o,t)}))}function p(e,t,n){return s(this,void 0,void 0,(function*(){return u("PUT",e,t,n)}))}function v(e,t){return s(this,void 0,void 0,(function*(){return u("DELETE",e,t)}))}function g(e,t,n){return s(this,void 0,void 0,(function*(){return u("PATCH",e,t,n)}))}var C=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function m(e,t){return`${e.replace(/\/+$/,"")}${t}`}function T(e){return C(this,arguments,void 0,(function*(e,t={},o=1){const i=n.GetReadBaseUrlCandidates();let r;for(const c of i){try{const i=yield h(m(c,e),t,o);if(c.replace(/\/+$/,"")===n.BASE_URL.replace(/\/+$/,""))return i;if(i.ok)return n.NODE_CACHE_URL=c,i;r=new Error(`Cache server ${c} returned status ${i.status}`)}catch(e){r=e}n.isNearestCache=!1}throw r instanceof Error?r:new Error("All cache servers failed")}))}class w{constructor(e){this.id=1,this.isOnlineSync=!1,this.isOnlineSync=e}}var I=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const N={};function A(e){return N[e]||(N[e]=[]),N[e]}function k(e,t){const n=A(e);if(t&&"number"==typeof t.id){const e=n.findIndex((e=>e&&e.id===t.id));if(e>=0)return void(n[e]=t)}n.push(t)}function S(e,t,n){return I(this,void 0,void 0,(function*(){return A(e).filter((e=>e&&e[t]===n))}))}function x(e){return I(this,void 0,void 0,(function*(){return A(e).slice()}))}function _(e,t){const n=A(e),o=n.findIndex((e=>e&&e.id===t));o>=0&&n.splice(o,1)}function R(e){return I(this,void 0,void 0,(function*(){return A(e).slice()}))}class E{}E.isTypeLoaded=!1,E.isCharacterLoaded=!1,E.isDataLoaded=!1,E.isLocalDataLoaded=!1,E.isLocalCharacterLoaded=!1,E.isLocalTypeLoaded=!1,E.isConnectionLoaded=!1,E.isConnectionTypeLoaded=!1,E.isLocalConnectionLoaded=!1;class B{constructor(e,t,n,o){this.variants=[],this.height=1,this.key=e,this.value=t,this.leftNode=n,this.rightNode=o,this.currentNode=null}addCurrentNode(e,t){return null==t?t=e:(e.value.typeId!=t.value.typeId&&(t.currentNode=this.addCurrentNode(e,t.currentNode)),t)}addCurrentNodeType(e,t){if(null==t)return e;var n=!1;for(let o=0;o<t.variants.length;o++)t.variants[o].value.id==e.value.id&&(n=!0);return n||t.variants.push(e),t}addNode(e,t,n){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addNode(e,o,n);else{if(!(t.key<e.key))return t;t.rightNode=this.addNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}return t}addCharacterNode(e,t,n){if(""!=e.value.characterValue){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addCharacterNode(e,o,n);else{if(!(t.key<e.key))return t.key==e.key&&""!=t.key&&t.value.id!=e.value.id&&t.addCurrentNodeType(e,t),t;t.rightNode=this.addCharacterNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}}return t}addTypeNode(e,t,n){if(0!=e.value.typeId){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addTypeNode(e,o,n);else{if(!(t.key<e.key))return t.key==e.key&&0!=t.key&&t.value.id!=e.value.id&&t.addCurrentNodeType(e,t),t;t.rightNode=this.addTypeNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}}return t}rightRotate(e){if(e){let t=e.leftNode;if(t){let n=t.rightNode;return e.leftNode=n,t.rightNode=e,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}leftRotate(e){if(e){let t=e.rightNode;if(t){let n=t.leftNode;return t.leftNode=e,e.rightNode=n,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}getHeight(e){return e?e.height:0}getBalanceFactor(e){return null==e?0:this.getHeight(e.leftNode)-this.getHeight(e.rightNode)}getFromNode(e,t){return t?e==t.key?t:e<t.key?this.getFromNode(e,t.leftNode):e>t.key?this.getFromNode(e,t.rightNode):t:t}getCharacterFromNode(e,t){return t?e==t.key?t:e<t.key?this.getCharacterFromNode(e,t.leftNode):e>t.key?this.getCharacterFromNode(e,t.rightNode):t:t}getCharacterFromNodeUpdated(e,t){var n;return t?e==t.key||51==(null===(n=t.value)||void 0===n?void 0:n.typeId)?t:e<t.key?this.getCharacterFromNode(e,t.leftNode):e>t.key?this.getCharacterFromNode(e,t.rightNode):t:t}getFromNodeWithCharacterAndType(e,t,n){if(e=`${e}`,n){if(e==n.key){if(e==n.value.characterValue&&t==n.value.typeId)return n;for(let e=0;e<n.variants.length;e++)if(n.variants[e].value.typeId==t)return n.variants[e]}else{if(e<n.key)return this.getFromNodeWithCharacterAndType(e,t,n.leftNode);if(e>n.key)return this.getFromNodeWithCharacterAndType(e,t,n.rightNode)}return null}return n}getFromNodeWithCharacterAndCategory(e,t,n){if(e=`${e}`,n){if(e==n.key){if(e==n.value.characterValue&&t==n.value.categoryId)return n;for(let e=0;e<n.variants.length;e++)if(n.variants[e].value.categoryId==t)return n.variants[e]}else{if(e<n.key)return this.getFromNodeWithCharacterAndCategory(e,t,n.leftNode);if(e>n.key)return this.getFromNodeWithCharacterAndCategory(e,t,n.rightNode)}return null}return n}removeNode(e,t){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNode(e.leftNode,t),e;if(e.key<t)return e.rightNode=this.removeNode(e.rightNode,t),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var n=this.inOrderSuccessor(e.rightNode);return e.value=n.value,e.key=n.key,e.variants=n.variants,e.currentNode=n.currentNode,e.rightNode=this.removeNode(e.rightNode,n.key),e}removeNodeWithVariants(e,t,n){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNodeWithVariants(e.leftNode,t,n),e;if(e.key<t)return e.rightNode=this.removeNodeWithVariants(e.rightNode,t,n),e;if(e.variants.length>0)if(e.value.id==n){var o=e.variants[0];if(o)return e.value=o.value,e.key=o.key,e.currentNode=o.currentNode,e.variants.splice(0,1),e}else for(let t=0;t<e.variants.length;t++)if(n==e.variants[t].value.id)return e.variants.splice(t,1),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var i=this.inOrderSuccessor(e.rightNode);return e.value=i.value,e.key=i.key,e.variants=i.variants,e.currentNode=i.currentNode,e.rightNode=this.removeNodeWithVariants(e.rightNode,i.key,n),e}countNodeBelow(e){return null==e?0:1+this.countNodeBelow(e.leftNode)+this.countNodeBelow(e.rightNode)}inOrderSuccessor(e){for(;null!=e.leftNode;)e=e.leftNode;return e}}var U=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class L{static waitForDataToLoad(){return U(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isCharacterLoaded)return e("done");setTimeout(L.checkFlag,1e3,e)}static addNodeToTree(e){return U(this,void 0,void 0,(function*(){return null==this.characterRoot?(this.characterRoot=e,this.characterRoot):(this.characterRoot=this.characterRoot.addCharacterNode(e,this.characterRoot,this.characterRoot.height),this.characterRoot)}))}static removeNodeByCharacter(e,t){return U(this,void 0,void 0,(function*(){this.characterRoot&&this.characterRoot.removeNodeWithVariants(this.characterRoot,e,t)}))}static countNumberOfNodes(){return this.characterRoot?this.characterRoot.countNodeBelow(this.characterRoot):0}static addConceptToTree(e){if(""!=e.characterValue){var t=new B(e.characterValue,e,null,null);this.addNodeToTree(t)}}static getNodeFromTree(e){return this.characterRoot?this.characterRoot.getCharacterFromNode(e,this.characterRoot):this.characterRoot}static getNodeFromTreeUpdated(e){return this.characterRoot?this.characterRoot.getCharacterFromNode(e,this.characterRoot):this.characterRoot}static getCharacterAndTypeFromTree(e,t){return U(this,void 0,void 0,(function*(){return this.characterRoot?this.characterRoot.getFromNodeWithCharacterAndType(e,t,this.characterRoot):this.characterRoot}))}static getCharacterAndCategoryFromTree(e,t){return U(this,void 0,void 0,(function*(){return this.characterRoot?this.characterRoot.getFromNodeWithCharacterAndCategory(e,t,this.characterRoot):this.characterRoot}))}static removeConceptCharacter(e){this.characterRoot&&(this.characterRoot=this.characterRoot.removeNode(this.characterRoot,e))}}L.characterRoot=null;var P=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class G{static addNodeToTree(e){if(null==this.root)return this.root=e,this.root;this.root=this.root.addNode(e,this.root,this.root.height)}static waitForDataToLoad(){return P(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isDataLoaded)return e("done");setTimeout(G.checkFlag,1e3,e)}static addConceptToTree(e){var t=new B(e.id,e,null,null),n=new B(e.characterValue,e,null,null);L.addNodeToTree(n),this.addNodeToTree(t)}static getNodeFromTree(e){return P(this,void 0,void 0,(function*(){return this.root?this.root.getFromNode(e,this.root):null}))}static removeNodeFromTree(e){return P(this,void 0,void 0,(function*(){this.root&&(this.root=this.root.removeNode(this.root,e))}))}static countNumberOfNodes(){return this.root?this.root.countNodeBelow(this.root):0}}G.root=null;class F{constructor(e,t,n,o,i,r,c,s,a,l,d,u,h,f,y,p=!1,v,g){this.referent=null,this.updateRecursion=!1,this.isTemp=!1,this.id=e,this.userId=t,this.typeId=n,this.typeUserId=o,this.ghostId=e,this.categoryId=i,this.categoryUserId=r,this.referentId=c,this.referentUserId=s,this.characterValue=`${a}`,this.securityId=l,this.securityUserId=d,this.accessId=u,this.accessUserId=h,this.sessionInformationId=f,this.sessionInformationUserId=y,this.x=0,this.y=0,this.type=null,this.isNew=p,this.entryTimeStamp=v,this.updatedTimeStamp=g}getType(){console.log(this.typeId)}}function b(){let e=D(new Date),t=D(new Date);return new F(0,0,0,0,0,0,0,0,"0",0,0,0,0,0,0,!1,e,t)}function D(e){const t=e.getMonth()+1,n=e.getDate(),o=e.getFullYear();let i=e.getHours();const r=e.getMinutes(),c=e.getSeconds(),s=i>=12?"PM":"AM";i%=12,i=i||12;const a=e=>e.toString().padStart(2,"0");return`${t}/${n}/${o} ${i}:${a(r)}:${a(c)} ${s}`}var $=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class O{static addNodeToTree(e){return $(this,void 0,void 0,(function*(){return null==this.typeRoot?(this.typeRoot=e,this.typeRoot):(this.typeRoot=this.typeRoot.addTypeNode(e,this.typeRoot,this.typeRoot.height),this.typeRoot)}))}static addConceptToTree(e){if(0!=e.typeId){var t=new B(e.typeId,e,null,null);this.addNodeToTree(t)}}static removeTypeConcept(e,t){this.typeRoot&&(this.typeRoot=this.typeRoot.removeNodeWithVariants(this.typeRoot,e,t))}static getNodeFromTree(e){return this.typeRoot?this.typeRoot.getFromNode(e,this.typeRoot):this.typeRoot}static getTypeVariantsFromTree(e){var t=this.getNodeFromTree(e),n=[];if(t){n.push(null==t?void 0:t.value);for(let e=0;e<t.variants.length;e++)n.push(t.variants[e].value);return n}}static waitForDataToLoad(){return $(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isTypeLoaded)return e("done");setTimeout(O.checkFlag,1e3,e)}static getTypeVariantsFromTreeWithUserId(e,t){return $(this,void 0,void 0,(function*(){var n=[],o=this.getNodeFromTree(e);if(o){o.value.userId==t&&n.push(null==o?void 0:o.value);for(let e=0;e<o.variants.length;e++)if(o.variants[e].value.userId==t){var i=!1;for(let t=0;t<n.length;t++)n[t].id==o.variants[e].value.id&&(i=!0);i||n.push(o.variants[e].value)}}return n}))}static getTypeVariantsWithCharacterValue(e,t){return $(this,void 0,void 0,(function*(){let n=b();var o=this.getNodeFromTree(t);if(o){o.value.characterValue==e&&(n=o.value);for(let t=0;t<o.variants.length;t++)o.variants[t].value.characterValue==e&&(n=o.variants[t].value)}return n}))}static countNumberOfNodes(){return this.typeRoot?this.typeRoot.countNodeBelow(this.typeRoot):0}}O.typeRoot=null;var V=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class M{constructor(){this.name="conceptsArray"}static RemoveExpiredNpc(e=Date.now()){this.NPC=this.NPC.filter((t=>{const n=this.NPCMeta.get(t);return n&&n.expiresAt>e}))}static CheckContains(e){for(var t=!1,n=0;n<this.conceptsArray.length;n++)this.conceptsArray[n].id==e.id&&(t=!0);return t}static AddNpc(e){var t;const n=Date.now();this.RemoveExpiredNpc(n),this.NPC.includes(e)||this.NPC.push(e);const o=this.NPCMeta.get(e),i=(null!==(t=null==o?void 0:o.attempts)&&void 0!==t?t:0)+1;this.NPCMeta.set(e,{attempts:i,expiresAt:n+i*this.NPC_BACKOFF_SECONDS*1e3})}static GetNpc(e){const t=Date.now();this.RemoveExpiredNpc(t);const n=this.NPCMeta.get(e);return!!(n&&n.expiresAt>t)}static AddConceptToStorage(e){e.id>0&&k("concept",e)}static AddConcept(e){e.id>0&&(k("concept",e),G.addConceptToTree(e),O.addConceptToTree(e),L.addConceptToTree(e))}static AddConceptToMemory(e){e.id>0&&(G.addConceptToTree(e),O.addConceptToTree(e),L.addConceptToTree(e))}static AddConceptTemporary(e){var t=this.CheckContains(e);this.conceptDictionary[e.id]=e,t&&this.RemoveConcept(e),this.conceptsArray.push(e)}static RemoveConcept(e){for(var t=0;t<this.conceptsArray.length;t++)this.conceptsArray[t].id==e.id&&this.conceptsArray.splice(t,1);G.removeNodeFromTree(e.id),_("concept",e.id)}static GetConcept(e){return V(this,void 0,void 0,(function*(){var t=b(),n=yield G.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConceptByCharacter(e){return V(this,void 0,void 0,(function*(){var t=b(),n=L.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterUpdated(e){return V(this,void 0,void 0,(function*(){var t=b(),n=L.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterAndTypeLocal(e,t){return V(this,void 0,void 0,(function*(){return b(),yield O.getTypeVariantsWithCharacterValue(e,t)}))}static GetConceptByCharacterAndCategoryLocal(e,t){return V(this,void 0,void 0,(function*(){var n=b(),o=yield L.getCharacterAndCategoryFromTree(e,t);return o&&(n=o.value),n}))}static GetConceptsByTypeId(e){let t=[];for(var n=0;n<this.conceptsArray.length;n++)this.conceptsArray[n].typeId==e&&t.push(this.conceptsArray[n]);return t}static GetConceptsByTypeIdAndUser(e,t){return V(this,void 0,void 0,(function*(){let n=[];return n=yield O.getTypeVariantsFromTreeWithUserId(e,t),n}))}static GetBinaryCharacterTree(){return L.characterRoot}getName(){return this.name}}M.conceptsArray=[],M.NPC=[],M.NPCMeta=new Map,M.NPC_BACKOFF_SECONDS=30,M.conceptDictionary=[];var H=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function j(){return H(this,void 0,void 0,(function*(){(new Date).getTime();var e=yield x("concept");if(Array.isArray(e))for(var t=0;t<e.length;t++){let n=e[t];M.AddConceptToMemory(n)}(new Date).getTime()}))}function W(e){const t=e.lastIndexOf("_");let n=[];return n=t>0?[e.substring(0,t),e.substring(t+1,e.length)]:[e],n}var J=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function z(){return J(this,arguments,void 0,(function*(e="application/json",t="application/json"){if(o.isTokenExpiredOrNearExpiry()&&o.hasOAuthCredentials()){const e=yield r(o.CLIENT_ID,o.CLIENT_SECRET,o.APPLICATION_NAME,!0);e.success||console.error("Failed to refresh token:",e.error)}return{"Content-Type":e,Authorization:"Bearer "+o.BearerAccessToken,Accept:t}}))}function q(){return J(this,arguments,void 0,(function*(e="application/json",t="",n="application/json"){if(""!==t)return{"Content-Type":e,Authorization:"Bearer "+t,Accept:n};if(o.isTokenExpiredOrNearExpiry()&&o.hasOAuthCredentials()){const e=yield r(o.CLIENT_ID,o.CLIENT_SECRET,o.APPLICATION_NAME,!0);e.success||console.error("Failed to refresh token:",e.error)}return{"Content-Type":e,Authorization:"Bearer "+o.BearerAccessToken,Accept:n}}))}class K{constructor(e,t,o,i){this.url=n.BASE_URL,this.message=e,this.ok=t,this.status=o,this.data=i}getMessage(){return this.message}setMessage(e){return this.message=e,this}getStatus(){return this.status}setStatus(e){return this.status=e,this}getData(){return this.data}setData(e){return this.data=e,this}getOk(){return this.ok}setOk(e){return this.ok=e,this}getUrl(){return this.url}setUrl(e){return this.url=e,this}}function Q(e){if(!e.ok){const t=e instanceof l,n=t?e.body||`HTTP error ${e.status}`:e.statusText||`HTTP error ${e.status}`;let o=new K(n,!1,e.status,"");throw o.setUrl(t?e.headers.url||"":e.url),o}}function Y(e){if(!e.ok){const t=e.body||`HTTP error ${e.status}`;let n=new K(t,!1,e.status,e.body);throw n.setUrl(e.headers.url||""),n}}var X=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Z(e,t){return X(this,void 0,void 0,(function*(){try{var o=new URLSearchParams;o.append("type",e),o.append("user_id",t.toString());var i=yield z("application/x-www-form-urlencoded");const c=yield h(n.GetAllConceptsByTypeUrl(),{method:"POST",headers:i,body:o});if(c.ok){const e=yield c.json();for(var r=0;r<e.length;r++)M.AddConcept(e[r])}console.log("GetAllConceptsByType error",c.status),Q(c)}catch(e){throw e instanceof Error?console.log("GetAllConceptsByType error message: ",e.message):console.log("GetAllConceptsByType unexpected error: ",e),e}}))}class ee{constructor(e=0,t,n,o,i,r,c,s,a,l,d,u,h,f,y,p){this.isTemp=!1,this.toUpdate=!1,this.type=b(),this.id=e,this.ofTheConceptId=t,this.toTheConceptId=n,this.ofTheConceptUserId=o,this.toTheConceptUserId=i,this.userId=r,this.typeId=c,this.ghostId=e,this.typeUserId=s,this.orderId=a,this.orderUserId=l,this.securityId=d,this.securityUserId=u,this.accessId=h,this.accessUserId=f,this.sessionInformationId=y,this.sessionInformationUserId=p,this.entryTimeStamp=D(new Date),this.terminationDateTime=new Date,this.localSyncTime=new Date}}class te{constructor(e,t,n,o){this.variants=[],this.height=1,this.key=e,this.value=t,this.leftNode=n,this.rightNode=o,this.currentNode=null}addCurrentNode(e,t){return null==t?t=e:(e.value.typeId!=t.value.typeId&&(t.currentNode=this.addCurrentNode(e,t.currentNode)),t)}addCurrentNodeType(e,t){if(null==t)return e;var n=!1;e.value.id==t.value.id&&(n=!0);for(let o=0;o<t.variants.length;o++)t.variants[o].value.id==e.value.id&&(n=!0);return n||t.variants.push(e),t}addNode(e,t,n){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addNode(e,o,n);else{if(!(t.key<e.key))return t;t.rightNode=this.addNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}return t}addTypeNode(e,t,n){if(0!=e.value.typeId){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addTypeNode(e,o,n);else{if(!(t.key<e.key))return t.key==e.key&&0!=t.key&&t.addCurrentNodeType(e,t),t;t.rightNode=this.addTypeNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}}return t}rightRotate(e){if(e){let t=e.leftNode;if(t){let n=t.rightNode;return e.leftNode=n,t.rightNode=e,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}leftRotate(e){if(e){let t=e.rightNode;if(t){let n=t.leftNode;return t.leftNode=e,e.rightNode=n,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}getHeight(e){return e?e.height:0}getBalanceFactor(e){return null==e?0:this.getHeight(e.leftNode)-this.getHeight(e.rightNode)}getFromNode(e,t){return t?e==t.key?t:e<t.key?this.getFromNode(e,t.leftNode):e>t.key?this.getFromNode(e,t.rightNode):t:t}getCharacterFromNode(e,t){return t?e==t.key?t:e<t.key?this.getCharacterFromNode(e,t.leftNode):e>t.key?this.getCharacterFromNode(e,t.rightNode):t:t}removeNode(e,t){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNode(e.leftNode,t),e;if(e.key<t)return e.rightNode=this.removeNode(e.rightNode,t),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var n=this.inOrderSuccessor(e.rightNode);return e.value=n.value,e.key=n.key,e.variants=n.variants,e.currentNode=n.currentNode,e.rightNode=this.removeNode(e.rightNode,n.key),e}removeNodeWithVariants(e,t,n){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNodeWithVariants(e.leftNode,t,n),e;if(e.key<t)return e.rightNode=this.removeNodeWithVariants(e.rightNode,t,n),e;if(e.variants.length>0)if(e.value.id==n){var o=e.variants[0];if(o)return e.value=o.value,e.key=o.key,e.currentNode=o.currentNode,e.variants.splice(0,1),e}else for(let t=0;t<e.variants.length;t++)if(n==e.variants[t].value.id)return e.variants.splice(t,1),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var i=this.inOrderSuccessor(e.rightNode);return e.value=i.value,e.key=i.key,e.variants=i.variants,e.currentNode=i.currentNode,e.rightNode=this.removeNodeWithVariants(e.rightNode,i.key,n),e}inOrderSuccessor(e){for(;null!=e.leftNode;)e=e.leftNode;return e}}var ne=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class oe{static addNodeToTree(e){if(null==this.connectionroot)return this.connectionroot=e,this.connectionroot;this.connectionroot=this.connectionroot.addNode(e,this.connectionroot,this.connectionroot.height)}static addConnectionToTree(e){var t=new te(e.id,e,null,null);this.addNodeToTree(t)}static waitForDataToLoad(){return ne(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isConnectionLoaded)return e("done");setTimeout(oe.checkFlag,1e3,e)}static removeNodeFromTree(e){return ne(this,void 0,void 0,(function*(){this.connectionroot&&(this.connectionroot=this.connectionroot.removeNode(this.connectionroot,e))}))}static getNodeFromTree(e){return ne(this,void 0,void 0,(function*(){return this.connectionroot?this.connectionroot.getFromNode(e,this.connectionroot):this.connectionroot}))}}oe.connectionroot=null;var ie=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class re{static addNodeToTree(e){return ie(this,void 0,void 0,(function*(){return null==this.connectionTypeRoot?(this.connectionTypeRoot=e,this.connectionTypeRoot):(this.connectionTypeRoot=this.connectionTypeRoot.addTypeNode(e,this.connectionTypeRoot,this.connectionTypeRoot.height),this.connectionTypeRoot)}))}static waitForDataToLoad(){return ie(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isConnectionTypeLoaded)return e("done");setTimeout(re.checkFlag,1e3,e)}static addConnectionToTree(e){if(0!=e.typeId){var t=new te(e.typeId,e,null,null);this.addNodeToTree(t)}}static removeTypeConcept(e,t){this.connectionTypeRoot&&(this.connectionTypeRoot=this.connectionTypeRoot.removeNodeWithVariants(this.connectionTypeRoot,e,t))}static getNodeFromTree(e){return this.connectionTypeRoot?this.connectionTypeRoot.getFromNode(e,this.connectionTypeRoot):this.connectionTypeRoot}static getTypeVariantsFromTree(e){return ie(this,void 0,void 0,(function*(){var t=[],n=this.getNodeFromTree(e);if(n){t.push(null==n?void 0:n.value);for(let e=0;e<n.variants.length;e++)t.push(n.variants[e].value);return t}}))}static getTypeVariantsFromTreeWithUserId(e,t){return ie(this,void 0,void 0,(function*(){var n=[],o=this.getNodeFromTree(e);if(o){o.value.userId==t&&n.push(null==o?void 0:o.value);for(let e=0;e<o.variants.length;e++)o.variants[e].value.userId==t&&n.push(o.variants[e].value)}return n}))}}re.connectionTypeRoot=null;var ce=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class se{constructor(){this.name="Connection Array"}static CheckContains(e){for(var t=!1,n=0;n<this.connectionArray.length;n++)this.connectionArray[n].id==e.id&&(t=!0);return t}static AddConnectionToStorage(e){k("connection",e)}static AddConnection(e){e.isTemp||(k("connection",e),oe.addConnectionToTree(e),re.addConnectionToTree(e))}static AddConnectionToMemory(e){e.isTemp||(oe.addConnectionToTree(e),re.addConnectionToTree(e))}static AddToDictionary(e){this.connectionDictionary[e.id]=e}static RemoveConnection(e){0!=e.id&&(_("connection",e.id),oe.removeNodeFromTree(e.id),re.removeTypeConcept(e.typeId,e.id))}static GetConnectionTree(){return oe.connectionroot}static GetConnectionTypeTree(){return re.connectionTypeRoot}static GetConnection(e){return ce(this,void 0,void 0,(function*(){var t=new ee(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),n=yield oe.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConnectionsOfCompositionLocal(e){return ce(this,void 0,void 0,(function*(){var t=[],n=yield re.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;if(o){let e=o;t.push(e);for(let e=0;e<n.variants.length;e++)t.push(n.variants[e].value)}}return t}))}getName(){return this.name}}se.connectionArray=[],se.connectionDictionary=[];var ae=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function le(e){return ae(this,void 0,void 0,(function*(){let t=[];try{var n=[];for(let o=0;o<e.length;o++){let i=yield M.GetConcept(e[o]);0==i.id?n.push(e[o]):t.push(i)}if(0==n.length)return t;{const e=JSON.stringify(n);var o=yield z();const i=yield T("/api/get_concept_bulk",{method:"POST",headers:o,body:e});if(console.log("[DEBUG] GetConceptBulk response:",{status:i.status,ok:i.ok}),i.ok){let e=yield i.json();if(e.length>0)for(let n=0;n<e.length;n++){let o=e[n];t.push(o),M.AddConcept(o)}}else console.log("Get Concept Bulk error",i.status),Q(i);return t}}catch(e){throw e instanceof Error?console.log("Get Concept Bulk error message: ",e.message):console.log("Get Concept Bulk unexpected error: ",e),e}}))}var de=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ue(){return de(this,arguments,void 0,(function*(e=[]){var t=[];if(e.length>0){for(let n=0;n<e.length;n++)t.includes(e[n].ofTheConceptId)||t.push(e[n].ofTheConceptId),t.includes(e[n].toTheConceptId)||t.push(e[n].toTheConceptId);yield le(t)}}))}var he=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function fe(){return he(this,arguments,void 0,(function*(e=[]){var t=[];for(let o=0;o<e.length;o++){var n=yield se.GetConnectionsOfCompositionLocal(e[o]);t.push(...n)}return t}))}function ye(e=[],t=[]){for(let n=0;n<t.length;n++)Array.isArray(e)&&(e.find((e=>e.id===t[n].id))||se.RemoveConnection(t[n]))}var pe=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ve(){return pe(this,arguments,void 0,(function*(e=[]){var t=[];if(e.length<=0)return t;var o=yield fe(e),i=yield function(){return pe(this,arguments,void 0,(function*(e=[]){var t=[];try{var o=yield z();const r=yield h(n.GetAllConnectionsOfCompositionBulkUrl(),{method:"POST",headers:o,body:JSON.stringify(e)});if(r.ok){const e=yield r.json();for(var i=0;i<e.length;i++)se.AddConnection(e[i]),t.push(e[i])}else console.log("Get all connections of composition bulk error message: ","Cannot get response"),Q(r);return t}catch(e){throw e instanceof Error?console.log("Get all connections of composition bulk error message: ",e.message):console.log("Get all connections of composition bulk unexpected error: ",e),e}}))}(e);return ye(t=i,o),yield ue(t),t}))}var ge=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const Ce=new Map;function me(e){return ge(this,void 0,void 0,(function*(){let t=b();if(Ce.has(e))return Ce.get(e)||t;const o=(()=>ge(this,void 0,void 0,(function*(){try{var o=yield M.GetConcept(e);let r=M.GetNpc(e);if(0!=o.id||r)return o;{var i=yield z("application/x-www-form-urlencoded");const o=n.GetConceptUrl();console.log("[DEBUG] GetConcept request:",{url:o,method:"POST",headers:i,conceptId:e});const r=yield h(n.GetConceptUrl(),{method:"POST",headers:i,body:`id=${e}`});return console.log("[DEBUG] GetConcept response:",{status:r.status,ok:r.ok,conceptId:e}),r.ok?(t=yield r.json(),t.id>0?M.AddConcept(t):M.AddNpc(e)):(console.log("Get the concept error",r.status,e),Q(r)),t}}catch(t){throw t instanceof Error?console.log("Get the concept error message: ",t.message,e):console.log("Get the concept unexpected error: ",t,e),t}finally{Ce.delete(e)}})))();return Ce.set(e,o),o}))}var Te=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function we(e){return Te(this,void 0,void 0,(function*(){var t=[];if(0==(t=yield se.GetConnectionsOfCompositionLocal(e)).length)t=yield Ie(e);else{var n=yield Ie(e);ye(n,t),t=n}return t}))}function Ie(e){return Te(this,void 0,void 0,(function*(){var t=[];try{var o=yield z("application/x-www-form-urlencoded");const r=yield h(n.GetAllConnectionsOfCompositionUrl(),{method:"POST",headers:o,body:`composition_id=${e}`});if(!r.ok)throw Q(r),new Error(`Error! status: ${r.status}`);const c=yield r.json();for(var i=0;i<c.length;i++)se.AddConnection(c[i]),t.push(c[i]);return t}catch(e){throw e instanceof Error?console.log("Get all connection of composition error : ",e.message):console.log("Get all connection of composition error : ",e),e}}))}var Ne=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ae(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield we(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Ue(e,o,r);return i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a,i}))}function ke(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield we(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Le(e,o,r);return i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a,i}))}function Se(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield se.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Ue(e,o,r);return i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a,i}))}function xe(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield se.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Ue(e,o,r);i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a;var l={};return l.created_at=s.entryTimeStamp,l.data=i,l.id=e,l}))}function _e(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield se.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Ue(e,o,r);i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a;var l={};return l.data=i,l.id=e,l.created_at=s.entryTimeStamp,l}))}function Re(e,t){return Ne(this,void 0,void 0,(function*(){for(var n,o,i={},r=[],c=0;c<t.length;c++)r.includes(t[c].ofTheConceptId)||r.push(t[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Ue(e,t,r);i[null!==(o=null===(n=null==s?void 0:s.type)||void 0===n?void 0:n.characterValue)&&void 0!==o?o:""]=a;var l={};return l.created_at=s.entryTimeStamp,l.data=i,l.id=e,l}))}function Ee(e,t){return Ne(this,arguments,void 0,(function*(e,t,n=[]){var o,i,r={},c=yield M.GetConcept(e);0==c.id&&null!=e&&null!=e&&(c=yield me(e));var s=yield Ue(e,t,n);r[null!==(i=null===(o=null==c?void 0:c.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:""]=s;var a={};return a.created_at=c.entryTimeStamp,a.data=r,a.id=e,a}))}function Be(e){return Ne(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield we(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield M.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield me(e));var a=yield Ue(e,o,r);i[null!==(n=null===(t=null==s?void 0:s.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=a;var l={};return l.data=i,l.id=e,l}))}function Ue(e,t,n){return Ne(this,arguments,void 0,(function*(e,t,n,o=[]){var i,r,c,s={},a=[];if(0==e)return null;var l=yield M.GetConcept(e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield me(e)),0!=l.id&&null==l.type){var d=l.typeId,u=yield M.GetConcept(d);l.type=u,null==u&&null!=d&&null!=d&&(u=yield me(d),l.type=u)}if(null===(i=null==l?void 0:l.type)||void 0===i?void 0:i.characterValue,!n.includes(e))return null==l?void 0:l.characterValue;if(o.includes(e))return"";o.push(e);for(var h=0;h<t.length;h++)if(t[h].ofTheConceptId==e){var f=t[h].toTheConceptId,y=yield M.GetConcept(f);null!=y&&0!=y.id||null==f||null==f||(y=yield me(f)),y&&null==(null==y?void 0:y.type)&&(d=y.typeId,u=yield M.GetConcept(d),y.type=u,null==u&&null!=d&&null!=d&&(u=yield me(d),y.type=u));var p=(null!==(c=null===(r=null==y?void 0:y.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"").replace("the_","");if(isNaN(Number(p))){if(p){const e=yield Ue(f,t,n,o);s[p]=e}}else{const e=yield Ue(f,t,n,o);a[p]=e,s=a}}return s}))}function Le(e,t,n){return Ne(this,arguments,void 0,(function*(e,t,n,o=[]){var i,r,c,s={},a=[];if(0==e)return null;var l=yield M.GetConcept(e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield me(e)),0!=l.id&&null==l.type){var d=l.typeId,u=yield M.GetConcept(d);l.type=u,null==u&&null!=d&&null!=d&&(u=yield me(d),l.type=u)}if(null===(i=null==l?void 0:l.type)||void 0===i?void 0:i.characterValue,!n.includes(e))return null==l?void 0:l.characterValue;if(o.includes(e))return"";o.push(e),s.id=e;for(var h=0;h<t.length;h++)if(t[h].ofTheConceptId==e){var f=t[h].toTheConceptId,y=yield M.GetConcept(f);null!=y&&0!=y.id||null==f||null==f||(y=yield me(f)),y&&null==(null==y?void 0:y.type)&&(d=y.typeId,u=yield M.GetConcept(d),y.type=u,null==u&&null!=d&&null!=d&&(u=yield me(d),y.type=u));var p=(null!==(c=null===(r=null==y?void 0:y.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"").replace("the_","");if(isNaN(Number(p))){if(p){const e=yield Le(f,t,n);s[p]=e}}else{const e=yield Le(f,t,n);a[p]=e,s=a}}return s}))}var Pe=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ge(e){return Pe(this,void 0,void 0,(function*(){let t=b();try{var o=yield z("application/x-www-form-urlencoded");const i=yield h(n.GetConceptByCharacterValueUrl(),{method:"POST",headers:o,body:`character_value=${e}`});return i.ok?(t=yield i.json(),t.id>0&&M.AddConcept(t)):(console.log("Error in Getting concept by character value Error",i.status),Q(i)),t}catch(e){throw e instanceof Error?console.log("Error in Getting concept by character value error message: ",e):console.log("Error in Getting concept by character value unexpected error: ",e),e}}))}var Fe=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function be(e){return Fe(this,void 0,void 0,(function*(){var t=yield M.GetConceptByCharacter(e),n=`${e}`;return null!=t&&0!=(null==t?void 0:t.id)||!n||(yield Ge(e),t=yield M.GetConceptByCharacter(e)),t}))}var De=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function $e(e,t){return De(this,arguments,void 0,(function*(e,t,n=10,o=1){var i=yield be(e),r=[];if(i){yield Z(e,t);for(var c=yield M.GetConceptsByTypeIdAndUser(i.id,t),s=n*(o-1),a=[],l=s;l<s+n;l++)c[l]&&a.push(c[l].id);for(yield ve(a),l=s;l<s+n;l++)if(c[l]){var d=yield Se(c[l].id);r.push(d)}}return r}))}function Oe(e,t){return De(this,arguments,void 0,(function*(e,t,n=10,o=1){var i=yield be(e),r=[];if(i){yield Z(e,t);for(var c=yield M.GetConceptsByTypeIdAndUser(i.id,t),s=n*(o-1),a=[],l=s;l<s+n;l++)c[l]&&a.push(c[l].id);for(yield ve(a),l=s;l<s+n;l++)if(c[l]){var d=yield xe(c[l].id);r.push(d)}}return r}))}var Ve=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const Me=new Map;function He(e,t){return Ve(this,void 0,void 0,(function*(){let o=b();if(Me.has(e+t))return Me.get(e+t)||o;const i=(()=>Ve(this,void 0,void 0,(function*(){try{var i=yield z("application/x-www-form-urlencoded");const r=yield h(n.GetConceptByCharacterAndCategoryDirectUrl(),{method:"POST",headers:i,body:`character_value=${e}&category_id=${t}`});if(r.ok){let e=yield r.json();o=e,M.AddConcept(o)}else console.log("This is the concept by category and character direct api error",r.status),Q(r);return o}catch(o){throw o instanceof Error?console.log(" This is the concept by category and character direct api error message: ",o.message,e,t,n.GetConceptByCharacterAndCategoryDirectUrl()):console.log(" This is the concept by category and character unexpected direct api error: ",o,e,t,n.GetConceptByCharacterAndCategoryDirectUrl()),o}finally{Me.delete(e+t)}})))();return Me.set(e+t,i),i}))}var je=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function We(e){return je(this,void 0,void 0,(function*(){let t=b();if("the"==e)return t.id=1,t.typeId=5,t.characterValue="the",t;let n=e.length;var o=W(e);if(o.length>1){let n=1,i=yield We(o[0]);0!=i.id&&(n=i.id),t=yield function(e,t){return je(this,void 0,void 0,(function*(){let n=yield M.GetConceptByCharacterAndCategoryLocal(e,t);return 0==n.id&&(n=yield He(e,t)),n}))}(e,n)}else o[0]==e&&1==n?t=yield function(e){return je(this,void 0,void 0,(function*(){var t=yield M.GetConceptByCharacterAndTypeLocal(e,49);return 0==t.id&&(t=yield Ge(e)),t}))}(e):o[0]==e&&(t=yield function(e){return je(this,void 0,void 0,(function*(){var t=yield M.GetConceptByCharacterAndTypeLocal(e,51);return 0==t.id&&(t=yield Ge(e)),t}))}(e));return t}))}var Je=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const ze=new Map,qe=new Map;function Ke(e,t){return Je(this,void 0,void 0,(function*(){let t=b();if(qe.has(e))return qe.get(e);if(ze.has(e))return ze.get(e)||t;const o=(()=>Je(this,void 0,void 0,(function*(){try{if(t=yield We(e),0==t.id||4==t.typeId){var o=yield z("application/x-www-form-urlencoded");const i=yield h(n.MakeTheTypeConceptUrl(),{method:"POST",headers:o,body:`type=${e}`});if(!i.ok)throw Q(i),new Error(`Error! status: ${i.status}`);let r=yield i.json();t=r,t.id>0&&M.AddConcept(t)}return t.id>0&&qe.set(e,t),t}catch(e){throw e instanceof Error?console.log("Make The Type Concept Api error : ",e.message):console.log("Make The Type Concept Api error : ",e),e}finally{ze.delete(e)}})))();return ze.set(e,o),o}))}var Qe=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};let Ye=!1,Xe=[];const Ze=()=>{Xe.length>0&&!Ye&&Xe.shift()()};function et(e){return Qe(this,void 0,void 0,(function*(){return new Promise(((t,o)=>{Xe.push((()=>Qe(this,void 0,void 0,(function*(){try{if(Ye)return;if(Ye=!0,!e&&at.connectionIds.length>10)return Ye=!1,Ze(),t();const o=e?`${n.GetReservedConnectionIdUrl()}?${new URLSearchParams({count:String(e)}).toString()}`:n.GetReservedConnectionIdUrl();var i=yield z("application/x-www-form-urlencoded");const c=yield h(o,{method:"GET",headers:i});if(!c.ok)throw Q(c),new Error(`Error! status: ${c.status}`);const s=yield c.json();for(var r=0;r<s.length;r++)at.AddId(s[r]);t()}catch(e){e instanceof Error?console.log("get reserved connection ids error message: ",e.message):console.log("get reserved connection ids unexpected error: ",e),o(e)}finally{Ye=!1,Ze()}})))),Ze()}))}))}var tt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};let nt=!1,ot=[];const it=()=>{ot.length>0&&!nt&&ot.shift()()};function rt(){return tt(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{ot.push((()=>tt(this,void 0,void 0,(function*(){try{if(nt)return;if(nt=!0,st.ids.length>10)return nt=!1,it(),e();var o=yield z("application/x-www-form-urlencoded");const t=yield h(n.GetReservedIdUrl(),{method:"GET",headers:o});if(!t.ok)throw Q(t),new Error(`Error! status: ${t.status}`);const r=yield t.json();for(var i=0;i<r.length;i++)st.AddId(r[i]);e()}catch(e){t(e)}finally{nt=!1,it()}})))),it()}))}))}var ct=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class st{static getId(){return ct(this,void 0,void 0,(function*(){for(this.ids.length<10&&!this.pendingFetch&&(this.pendingFetch=(()=>ct(this,void 0,void 0,(function*(){try{yield rt()}finally{this.pendingFetch=null}})))(),this.ids.length>0&&this.pendingFetch.catch((e=>console.error("Reserved ID refill failed:",e))));0===this.ids.length;)if(this.pendingFetch||(this.pendingFetch=(()=>ct(this,void 0,void 0,(function*(){try{yield rt()}finally{this.pendingFetch=null}})))()),yield this.pendingFetch,0===this.ids.length)throw new Error("No reserved concept IDs were returned by the backend.");return this.ids.shift()}))}static AddId(e){Number.isFinite(e)&&e>0&&!this.ids.includes(e)&&this.ids.push(e)}}st.ids=[],st.pendingFetch=null;class at{static getId(){return ct(this,void 0,void 0,(function*(){for(this.connectionIds.length<10&&!this.pendingFetch&&(this.pendingFetch=(()=>ct(this,void 0,void 0,(function*(){try{yield et()}finally{this.pendingFetch=null}})))());0===this.connectionIds.length;)if(this.pendingFetch||(this.pendingFetch=(()=>ct(this,void 0,void 0,(function*(){try{yield et()}finally{this.pendingFetch=null}})))()),yield this.pendingFetch,0===this.connectionIds.length)throw new Error("No reserved connection IDs were returned by the backend.");return this.connectionIds.shift()}))}static AddId(e){Number.isFinite(e)&&e>0&&!this.connectionIds.includes(e)&&this.connectionIds.push(e)}static warmUp(e){return ct(this,void 0,void 0,(function*(){const t=e-this.connectionIds.length;t<=0||(this.pendingFetch||(this.pendingFetch=(()=>ct(this,void 0,void 0,(function*(){try{yield et(t)}finally{this.pendingFetch=null}})))()),yield this.pendingFetch)}))}}at.connectionIds=[],at.pendingFetch=null;function lt(e){return{id:e.id,userId:e.userId,characterValue:e.characterValue,typeId:e.typeId,categoryId:e.categoryId,accessId:e.accessId,referentId:e.referentId,sessionInformationId:e.sessionInformationId}}function dt(e){return t=this,o=void 0,r=function*(){let t=b();try{var o=yield z();const i=function(e){return Array.isArray(e)?e.map((e=>lt(e))):lt(e)}(e),r=yield f(n.CreateTheConceptUrl(),o,i);if(!r.ok)throw Y(r),new Error(`Error! status: ${r.status}`);return t=yield r.json(),t}catch(e){throw e instanceof Error?console.log("Create the concept api error message: ",e):console.log("Create the concept api unexpected error: ",e),e}},new((i=void 0)||(i=Promise))((function(e,n){function c(e){try{a(r.next(e))}catch(e){n(e)}}function s(e){try{a(r.throw(e))}catch(e){n(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i((function(e){e(n)}))).then(c,s)}a((r=r.apply(t,o||[])).next())}));var t,o,i,r}function ut(e){return t=this,o=void 0,r=function*(){let t=new ee(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);try{var o=yield z();const i=function(e){return e.map((e=>function(e){return{id:e.id,ofTheConceptId:e.ofTheConceptId,toTheConceptId:e.toTheConceptId,ofTheConceptUserId:e.ofTheConceptUserId,toTheConceptUserId:e.toTheConceptUserId,typeId:e.typeId,userId:e.userId,orderId:e.orderId,accessId:e.accessId,sessionInformationId:e.sessionInformationId}}(e)))}(e),r=yield f(n.CreateTheConnectionUrl(),o,i);if(!r.ok)throw console.log("Create the connection error message: ",r),Y(r),new Error(`Error! status: ${r.status}`);return t=yield r.json(),t}catch(e){throw e instanceof Error?console.log("Create the connection error message: ",e.message):console.log(" Create the connection unexpected error: ",e),e}},new((i=void 0)||(i=Promise))((function(e,n){function c(e){try{a(r.next(e))}catch(e){n(e)}}function s(e){try{a(r.throw(e))}catch(e){n(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i((function(e){e(n)}))).then(c,s)}a((r=r.apply(t,o||[])).next())}));var t,o,i,r}var ht=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ft(e){return e?`[SyncData:${e}]`:"[SyncData]"}function yt(e,t){console.log(`${ft(t)} ${e}`)}function pt(e,t,n,o,i){o<100&&n!==o||n!==o&&1!==n&&n%100!=0||console.log(`${ft(i)} ${e} ${t}: ${n}/${o} done, ${o-n} remaining`)}class vt{static CheckContains(e){for(var t=!1,n=0;n<this.conceptsSyncArray.length;n++)this.conceptsSyncArray[n].id==e.id&&(t=!0);return t}static SyncDataDelete(e){for(var t=0;t<this.conceptsSyncArray.length;t++)e==this.conceptsSyncArray[t].id&&this.conceptsSyncArray.splice(t,1);for(t=0;t<this.connectionSyncArray.length;t++)this.connectionSyncArray[t].ofTheConceptId!=e&&this.connectionSyncArray[t].toTheConceptId!=e&&this.connectionSyncArray[t].typeId!=e||this.connectionSyncArray.splice(t,1)}static CheckContainsConnection(e){for(var t=!1,n=0;n<this.connectionSyncArray.length;n++)this.connectionSyncArray[n].id==e.id&&(t=!0);return t}static AddConcept(e){this.conceptsSyncArray.push(e)}static RemoveConcept(e){for(var t=0;t<this.conceptsSyncArray.length;t++)this.conceptsSyncArray[t].id==e.id&&this.conceptsSyncArray.splice(t,1)}static AddConnection(e){this.connectionSyncArray.push(e)}static RemoveConnection(e){for(var t=0;t<this.connectionSyncArray.length;t++)this.connectionSyncArray[t].id==e.id&&this.connectionSyncArray.splice(t,1)}static SyncDataOnline(e){return ht(this,void 0,void 0,(function*(){try{let t=[],n=[];if(e&&this.transactionCollections.some((t=>t.id==e))){const o=this.transactionCollections.find((t=>t.id==e));if(this.transactionCollections=this.transactionCollections.filter((t=>t.id==e||new Date(t.createdDate).getTime()>(new Date).getTime()-6048e5)),!o)return;t=o.data.concepts.slice(),n=o.data.connections.slice(),yt(`starting online sync with ${t.length} concepts and ${n.length} connections`,e),t.length>0&&(yt(`sending ${t.length} concepts to backend`,e),yield dt(t),pt("synced","concepts",t.length,t.length,e)),n.length>0&&(yt(`sending ${n.length} connections to backend`,e),yield ut(n),pt("synced","connections",n.length,n.length,e)),this.transactionCollections=this.transactionCollections.filter((t=>t.id!=e)),yt("online sync complete",e)}else{const e=this.conceptsSyncArray.length,o=this.connectionSyncArray.length;yt(`starting online sync with ${e} queued concepts and ${o} queued connections`);for(let t=0;t<this.conceptsSyncArray.length;t++)M.AddConcept(this.conceptsSyncArray[t]),pt("prepared local cache for","concepts",t+1,e);for(let e=0;e<this.connectionSyncArray.length;e++)se.AddConnection(this.connectionSyncArray[e]),pt("prepared local cache for","connections",e+1,o);this.conceptsSyncArray.length>0&&(t=this.conceptsSyncArray.slice(),yt(`sending ${t.length} concepts to backend`),yield dt(t),this.conceptsSyncArray=this.conceptsSyncArray.filter((e=>!t.some((t=>t.id===e.id)))),pt("synced","concepts",t.length,t.length)),this.connectionSyncArray.length>0&&(n=this.connectionSyncArray.slice(),yt(`sending ${n.length} connections to backend`),yield ut(n),this.connectionSyncArray=this.connectionSyncArray.filter((e=>!n.some((t=>t.id===e.id)))),pt("synced","connections",n.length,n.length)),yt(`online sync complete; ${this.conceptsSyncArray.length} concepts and ${this.connectionSyncArray.length} connections remain queued`)}return"done"}catch(e){throw e}}))}static initializeTransaction(e){return ht(this,void 0,void 0,(function*(){try{if(this.transactionCollections.some((t=>t.id==e)))return;this.transactionCollections.push({id:e,data:{concepts:[],connections:[]},createdDate:(new Date).toISOString()})}catch(e){console.log("error in initializeTransaction",e)}}))}static markTransactionActions(e,t){return ht(this,void 0,void 0,(function*(){try{this.transactionCollections=this.transactionCollections.map((n=>n.id==e?Object.assign(Object.assign({},n),{data:JSON.parse(JSON.stringify(t))}):n)),this.conceptsSyncArray=this.conceptsSyncArray.filter((e=>!t.concepts.some((t=>t.id==e.id||t.ghostId==e.id)))),this.connectionSyncArray=this.connectionSyncArray.filter((e=>!t.connections.some((t=>t.id==e.id||t.ghostId==e.id))))}catch(e){console.log("error in markTransactionActions",e)}}))}static rollbackTransaction(e,t){return ht(this,void 0,void 0,(function*(){try{if(!this.transactionCollections.some((t=>t.id==e)))return;this.transactionCollections=this.transactionCollections.filter((t=>t.id!=e))}catch(e){console.log("LocalSyncData, roll",e)}}))}static syncDataLocalDb(){return ht(this,void 0,void 0,(function*(){if(yt(`starting local sync with ${this.conceptsSyncArray.length} queued concepts and ${this.connectionSyncArray.length} queued connections`),this.conceptsSyncArray.length>0){const e=this.conceptsSyncArray.length;for(let t=0;t<this.conceptsSyncArray.length;t++)k("localconcept",this.conceptsSyncArray[t]),pt("stored locally","concepts",t+1,e);this.conceptsSyncArray=[]}if(this.connectionSyncArray.length>0){const e=this.connectionSyncArray.length;for(let t=0;t<this.connectionSyncArray.length;t++)k("localconnection",this.connectionSyncArray[t]),pt("stored locally","connections",t+1,e);this.connectionSyncArray=[]}return yt("local sync complete"),"done"}))}}function gt(e,t){const n=Number(e);if(!Number.isFinite(n)||n<=0)throw new Error(`Cannot create a connection: ${t} must be a positive finite number. Received ${JSON.stringify(e)}.`);return n}vt.conceptsSyncArray=[],vt.connectionSyncArray=[],vt.transactionCollections=[];var Ct=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function mt(e,t,n,o,i,r,c){return Ct(this,arguments,void 0,(function*(e,t,n,o,i,r,c,s=1,a=4,l=999,d={concepts:[],connections:[]}){const u=function(e,t){const n=gt(e,"ofTheConceptId"),o=gt(t,"toTheConceptId");if(n===o)throw new Error(`Cannot create a self-connection for concept ${n}.`);return{ofTheConceptId:n,toTheConceptId:o}}(e,n);e=u.ofTheConceptId,n=u.toTheConceptId;let h=t,f=t,y=t;999!=l&&(y=l);let p=t,v=t,g=yield at.getId(),C=new ee(g,e,n,t,o,y,i,f,s,h,0,p,a,v,r,c);return C.toUpdate=!0,C.isTemp=!1,vt.AddConnection(C),d.connections.push(C),C}))}function Tt(e,t,n){return Ct(this,arguments,void 0,(function*(e,t,n,o={concepts:[],connections:[]}){let i=yield Ke(n),r=e.userId;return yield mt(e.id,e.userId,t.id,t.userId,i.id,999,999,1e3,4,r,o)}))}var wt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const It=new Map;function Nt(e,t){return wt(this,void 0,void 0,(function*(){let o=yield M.GetConceptByCharacterAndTypeLocal(e,t),i=e+t;if(It.has(i))return It.get(i)||o;const r=(()=>wt(this,void 0,void 0,(function*(){try{if(null==o||0==o.id){var r={character_value:`${e}`,type_id:t},c=JSON.stringify(r),s=yield z();const i=yield h(n.GetConceptByCharacterAndTypeUrl(),{method:"POST",headers:s,body:c});if(i.ok){let e=yield i.json();o=e,M.AddConcept(o)}else console.log("This is the concept by type and character error",i.status),Q(i)}return o}catch(e){throw e instanceof Error?console.log(" This is the concept by type and character error message: ",e.message):console.log(" This is the concept by type and character unexpected error: ",e),e}finally{It.delete(i)}})))();return It.set(i,r),r}))}function At(e){return wt(this,void 0,void 0,(function*(){let t=[],o=JSON.stringify(e);var i=yield z();const r=yield h(n.GetConceptConnectionByType(),{method:"POST",headers:i,body:o});if(r.ok){let e=yield r.json();t=yield le(e)}else console.log("This is the concept by type and character error",r.status),Q(r);return t}))}var kt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function St(e,t,n,o,i,r,c,s,a,l,d,u,h,f){return kt(this,arguments,void 0,(function*(e,t,n,o,i,r,c,s,a,l,d,u,h,f,y={concepts:[],connections:[]}){var p=yield st.getId();let v=new Date,g=new Date;var C=new F(p,t,i,r,n,o,c,s,e,a,l,d,u,h,f,!0,v,g);return C.isTemp=!1,vt.AddConcept(C),y.concepts.push(C),C}))}function xt(e,t,n,o,i,r,c,s,a,l,d,u,h,f){return kt(this,arguments,void 0,(function*(e,t,n,o,i,r,c,s,a,l,d,u,h,f,y={concepts:[],connections:[]}){var p=yield st.getId();let v=new Date,g=new Date;var C=new F(p,t,i,r,n,o,c,s,e,a,l,d,u,h,f,!1,v,g);return M.AddConcept(C),C.updateRecursion=!0,vt.AddConcept(C),y.concepts.push(C),C}))}var _t=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Rt(e,t){return _t(this,arguments,void 0,(function*(e,t,n=!1,o,i,r=999,c=0,s={concepts:[],connections:[]}){let a,l=r,d=o=n?o:999,u=o,h=i,f=o,y=e.startsWith("the_")?e:"the_"+e,p=b();return n?(p=yield Ke(e),a=yield St(t,o,4,o,p.id,p.userId,c,999,999,d,h,f,l,u,s)):(p=yield Ke(y),a=yield Nt(t,p.id),0==a.id&&0==a.userId&&(a=yield xt(t,o,4,o,p.id,p.userId,c,999,999,d,h,f,l,u,s))),a.type=p,a}))}var Et=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Bt(e){return Et(this,arguments,void 0,(function*(e,t=null,n=null,o=null,i=null,r=null,c=null){var s=null!=i?i:999,a=null!=r?r:4,l=null!=c?c:999,d=null!=o?o:0,u=b();for(const o in e)if("string"!=typeof e[o]&&"number"!=typeof e[o])if(null==t&&null==n){var h=d;u=p=yield Rt(o,"",!0,s,a,l),h=p.id,d=p.id,yield Bt(e[o],p.id,p.userId,h,i,r,c)}else{var f=null!=t?t:999,y=null!=n?n:999;h=d,u=p=yield Rt(o,"",!0,s,a,l),yield mt(f,y,p.id,p.userId,h,l,p.userId),yield Bt(e[o],p.id,p.userId,h,i,r,c)}else{f=null!=t?t:999,y=null!=n?n:10267,h=d;var p=yield Rt(o,e[o].toString(),!1,s,a,l);yield mt(f,y,p.id,p.userId,h,l,p.userId)}return u}))}var Ut=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Lt(e,t,o){return Ut(this,arguments,void 0,(function*(e,t,o,i=10,r=1){let c=[];try{var s=new URLSearchParams;s.append("typeId",`${e}`),s.append("ofTheConceptId",`${t}`),s.append("userId",`${o}`),s.append("inpage",`${i}`),s.append("page",`${r}`);var a=yield z("application/x-www-form-urlencoded");const l=yield h(n.GetAllConnectionsOfConceptUrl(),{method:"POST",headers:a,body:s});return l.ok?c=yield l.json():(console.log("Get connection of concept error",l.status),Q(l)),c}catch(e){throw e instanceof Error?console.log("Get connection of concept error message: ",e.message):console.log("Get connection of concept unexpected error: ",e),e}}))}var Pt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},Gt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},Ft=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},bt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Dt(e){return bt(this,void 0,void 0,(function*(){var t=yield se.GetConnection(e);if((null==t||0==t.id)&&null!=e&&null!=e){var o=yield function(e){return Ft(this,void 0,void 0,(function*(){var t=yield se.GetConnection(e);try{if(0!=t.id)return t;{var o=yield z("application/x-www-form-urlencoded");const i=yield h(n.GetConnectionUrl(),{method:"POST",headers:o,body:`id=${e}`});return i.ok?(t=yield i.json(),se.AddConnection(t)):(console.log("Get Connection Error",i.status),Q(i)),t}}catch(e){throw e instanceof Error?console.log("Get Connection error message: ",e.message):console.log("Get Connection unexpected error: ",e),e}}))}(e);t=o}return t}))}var $t=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ot(e){return $t(this,arguments,void 0,(function*(e,t=""){let o=!1;var i=yield Dt(e);return o=yield function(e){return Gt(this,arguments,void 0,(function*(e,t=""){let o=!1;try{let i=yield yield q("",t),r=yield{Authorization:i.Authorization,Accept:"application/json"};const c=new URLSearchParams;c.append("id",e.toString()),c.append("apiKey","nodeserver");const s=yield h(n.DeleteTheConnectionUrl(),{method:"POST",headers:r,body:c,redirect:"follow"});s.ok?o=(yield s.json()).success:(console.log("Delete connection error status: ",s.status),Q(s))}catch(e){throw e instanceof Error?console.log("Delete connection error message: ",e.message):console.log("Delete connection unexpected error: ",e),e}return o}))}(e,t),_("connection",e),oe.removeNodeFromTree(e),re.removeTypeConcept(i.typeId,e),o}))}function Vt(e){return $t(this,void 0,void 0,(function*(){let t=yield function(e){return Pt(this,void 0,void 0,(function*(){let t=!1;try{let o=yield q();const i=yield h(n.DeleteTheConnectionBulkUrl(),{method:"POST",headers:o,body:JSON.stringify(e)});i.ok?t=(yield i.json()).success:(console.log("Delete connection Bulk Api error status: ",i.status),Q(i))}catch(e){e instanceof Error?console.log("Delete connection Bulk Api error message: ",e.message):console.log("Delete connection Bulk Api unexpected error: ",e)}return t}))}(e);if(t)for(let t=0;t<e.length;t++){let n=e[t];n>0&&oe.removeNodeFromTree(n)}return t}))}var Mt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ht(e){return Mt(this,arguments,void 0,(function*(e,t=999){var n=b();if(e<0)return ri(yield zo(t,e));if(null!=(n=yield M.GetConcept(e))&&0!=n.id||null==e||null==e||(n=yield me(e)),0!=n.id&&null==n.type&&null!=n.typeId&&null!=n.typeId){var o=yield M.GetConcept(n.typeId);if(0!=o.id)n.type=o;else{var i=yield me(n.typeId);0!=i.id&&(n.type=i)}}return n}))}var jt=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const Wt=999,Jt=4,zt=999,qt=999,Kt=1e3;function Qt(e){const t=`${null!=e?e:""}`.trim();if(0===t.length)throw new Error("Cannot create a typed connection without a linker name.");return t}function Yt(e,t){return jt(this,void 0,void 0,(function*(){var n,o,i;if(null==e||null==e.id||0===e.id)throw new Error(`Cannot create a typed connection: ${t} must be a persisted concept.`);const r=e.type;if(null===(n=null==r?void 0:r.characterValue)||void 0===n?void 0:n.trim())return r.characterValue.trim();const c=(yield Ht(e.id,e.userId)).type;if(null===(o=null==c?void 0:c.characterValue)||void 0===o?void 0:o.trim())return e.type=c,c.characterValue.trim();if(null!=e.typeId&&0!==e.typeId){const t=yield Ht(e.typeId,e.typeUserId);if(0!==t.id&&(null===(i=t.characterValue)||void 0===i?void 0:i.trim()))return e.type=t,t.characterValue.trim()}throw new Error(`Cannot create a typed connection: ${t} concept ${e.id} has no resolvable type.`)}))}function Xt(e){return jt(this,void 0,void 0,(function*(){return yield Rt("connection",e,!1,Wt,Wt,zt)}))}function Zt(e,t,n){return jt(this,void 0,void 0,(function*(){return yield mt(e.id,e.userId,t.id,t.userId,n.id,zt,qt,Kt,Jt)}))}function en(e,t,n){return jt(this,arguments,void 0,(function*(e,t,n,o=!1,i=!1){const r=Qt(n),c=e.userId;if(o){const n=yield function(e,t){return jt(this,void 0,void 0,(function*(){return`${yield Yt(e,"toTheConcept")}_s_${t}_by`}))}(t,r);i&&(yield nn(`${r}_by`,t,c));const o=yield Xt(n);yield Zt(t,e,o)}const s=yield function(e,t){return jt(this,void 0,void 0,(function*(){return`${yield Yt(e,"ofTheConcept")}_s_${t}_s`}))}(e,r);i&&(yield nn(`${r}_s`,e,c));const a=yield Xt(s);return yield Zt(e,t,a)}))}function tn(e,t,n){return jt(this,arguments,void 0,(function*(e,t,n,o=!1,i=!1){return yield en(e,t,n,o,i)}))}function nn(e,t){return jt(this,arguments,void 0,(function*(e,t,n=null){for(var o=t,i=null!=n?n:t.userId,r=999,c=Qt(e)+"_count",s=(yield Yt(t,"concept"))+"_s_"+c,a=yield Rt("connection",s,!1,i,4,r),l=yield Lt(a.id,t.id,i,10,1),d=[],u=b(),h=0;h<l.length;h++){let e=yield Ht(l[h].toTheConceptId);d.push(e)}if(d.length<1)u=yield Rt("count","1",!1,i,4,r);else{var f=d[0];let e=Number(f.characterValue),t=Number.isFinite(e)?e+1:1;u=yield Rt("count",t.toString(),!1,i,4,r);for(let e=0;e<l.length;e++)yield Ot(l[e].id)}yield mt(o.id,o.userId,u.id,u.userId,a.id,r,qt,Kt,4,i)}))}function on(e,t,n){return jt(this,arguments,void 0,(function*(e,t,n,o=!1,i=!1){return yield en(e,t,n,o,i)}))}var rn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function cn(e){return encodeURIComponent(String(e))}function sn(e,t){return rn(this,arguments,void 0,(function*(e,t,o=("number"==typeof e?999:e.userId),i=("number"==typeof e?4:e.accessId),r=999){const c="number"==typeof e?e:e.id,s="number"==typeof e?o:e.userId,a=yield z("application/x-www-form-urlencoded"),l=[`character_value=${cn(t)}`,`type_id=${cn(c)}`,`type_user_id=${cn(s)}`,`access_id=${cn(i)}`,`session_information_id=${cn(r)}`].join("&"),d=yield h(n.CreateTypeConceptUrl(),{method:"POST",headers:a,body:l});if(!d.ok)throw Q(d),new Error(`Error! status: ${d.status}`);const u=yield d.json();return"number"!=typeof e&&(u.type=e),M.AddConcept(u),u}))}var an=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ln(e,t){return an(this,arguments,void 0,(function*(e,t,n=10,o=1){var i,r=[],c=yield Ht(e),s=(null===(i=c.type)||void 0===i?void 0:i.characterValue)+"_s_"+t,a=yield Nt(s,16);if(a.id>0){for(var l=yield Lt(a.id,c.id,c.userId,n,o),d=[],u=0;u<l.length;u++)d.push(l[u].toTheConceptId);for(yield ve(d),u=0;u<l.length;u++){let e=l[u].toTheConceptId,t=yield Ht(e),n=yield _e(t.id);r.push(n)}}return r}))}function dn(e,t){return an(this,arguments,void 0,(function*(e,t,n=10,o=1){var i,r=[],c=yield Ht(e),s=(null===(i=c.type)||void 0===i?void 0:i.characterValue)+"_s_"+t,a=yield Nt(s,16);if(a.id>0){for(var l=yield Lt(a.id,c.id,c.userId,n,o),d=[],u=0;u<l.length;u++)d.push(l[u].toTheConceptId);for(u=0;u<l.length;u++){let e=l[u].toTheConceptId,t=yield Ht(e);r.push(t)}}return r}))}class un{constructor(e,t,n,o,i,r,c,s=!1,a,l,d,u=999){this.isComposition=!1,this.isTemp=!1,this.applicationId=999,this.id=e,this.userId=t,this.typeId=n,this.ghostId=e,this.categoryId=o,this.characterValue=r,this.accessId=i,this.type=null,this.isNew=s,this.typeCharacter=c,this.entryTimeStamp=a,this.updatedTimeStamp=l,this.referentId=d,this.applicationId=u}getType(){console.log(this.typeId)}}function hn(){let e=new Date,t=new Date;return new un(0,0,0,0,0,"0","0",!1,e,t,0)}class fn{constructor(e,t,n,o,i,r,c,s,a,l){this.id=0,this.isNew=!1,this.userId=e,this.data=`${t}`,this.securityId=n,this.securityUserId=o,this.accessId=i,this.accessUserId=r,this.sessionId=c,this.sessionUserId=s,this.isNew=l}}class yn{constructor(){this.name="character Repository"}static AddCharacter(e){this.characterData[e.id]=e}static GetCharacter(e){for(var t=new fn(0,"0",0,0,0,0,0,0,"0",!1),n=0;n<this.characterData.length;n++)this.characterData[n].data==e&&(t=this.characterData[n]);return t}}yn.characterData=[];class pn{constructor(e,t,n,o){this.id=e,this.userId=t,this.referentId=n,this.isNew=o}}var vn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},gn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Cn(e,t,o,i,r){return gn(this,void 0,void 0,(function*(){return new fn(t,e,o,t,i,t,r,t,"",!1),yield function(){return vn(this,void 0,void 0,(function*(){var e;try{if(0==(e=yn.GetCharacter(e.data)).id){var t=yield z();const i=yield h(n.CreateTheCharacterDataUrl(),{method:"POST",headers:t,body:JSON.stringify(e)});if(!i.ok)throw Q(i),new Error(`Error! status: ${i.status}`);const r=yield i.json();var o=new fn(r.userId,e.data,0,0,4,4,999,999,"",!1);return o.id=r.id,yn.AddCharacter(o),r}return new pn(e.id,e.userId,0,!1)}catch(e){throw e instanceof Error?console.log("create the character error message: ",e.message):console.log("create the character unexpected error: ",e),e}}))}()}))}var mn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Tn(e,t,n,o,i,r,c,s,a,l,d,u,h,f){return mn(this,void 0,void 0,(function*(){var y=yield Nt(e,i),p=y;return 0==p.id&&(p=y=yield St(e,t,n,o,i,r,c,s,a,l,d,u,h,f)),p}))}var wn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},In=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Nn(e,t,n,o){return In(this,arguments,void 0,(function*(e,t,n,o,i={concepts:[],connections:[]}){var r=yield be(e);if(r&&(0==r.id||0==r.userId)){var c=W(e);if(c.length>0)if(c[0]==e){var s=yield function(e,t,n,o,i,r){return wn(this,void 0,void 0,(function*(){var i,c=t,s=t;i=t;var a,l=t,d=t,u=t;if(1==e.length){var h=e.charCodeAt(0);yield Cn(e,t,n,o,r),a=yield Tn(e,t,4,c,49,l,h,u,n,s,o,i,r,d)}else{var f=yield Cn(e,t,n,o,r);f.isNew,a=yield Tn(e,t,4,c,51,l,f.id,f.userId,n,s,o,i,r,d)}return a}))}(e,o,999,999,0,t);r=s}else{var a=yield Nn(c[0],t,n,o,i),l=yield Nn(c[1],t,n,o,i);l&&(r=yield xt(e,o,a.id,o,l.id,o,999,o,999,o,999,o,t,o,i))}}return r}))}var An=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function kn(e){return An(this,void 0,void 0,(function*(){var t=[];try{(new Date).getTime();var o=yield z("application/x-www-form-urlencoded");const c=new URLSearchParams({conceptId:String(e)}),s=yield h(`${n.GetAllLinkerConnectionOfConceptUrl()}?${c.toString()}`,{method:"GET",headers:o});if(s.ok){const e=yield s.json();for(var i=0;i<e.length;i++){var r=e[i];t.push(r)}}else console.log("Get all linker connection from the concepts error","cannot get respone"),Q(s);return t}catch(e){throw e instanceof Error?console.log("Get all linker connection from the concepts error: ",e.message):console.log("Get all linker connection from the concepts error(Unexpected): ",e),e}}))}var Sn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function xn(e){return Sn(this,void 0,void 0,(function*(){var t=[];try{(new Date).getTime();var o=yield z("application/x-www-form-urlencoded");const c=new URLSearchParams({conceptId:String(e)}),s=yield h(`${n.GetAllLinkerConnectionToConceptUrl()}?${c.toString()}`,{method:"GET",headers:o});if(s.ok){const e=yield s.json();for(var i=0;i<e.length;i++){var r=e[i];t.push(r)}}else console.log("Get all linker connection To the concepts error","cannot get respone"),Q(s);return t}catch(e){throw e instanceof Error?console.log("Get all linker connection To the concepts error: ",e.message):console.log("Get all linker connection To the concepts error(Unexpected): ",e),e}}))}var _n=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Rn(e){return _n(this,void 0,void 0,(function*(){for(var t=yield kn(e),n=0;n<t.length;n++){let e=t[n];var o=e.typeId;let i=yield Ht(o);e.type=i}return t}))}function En(e){return _n(this,void 0,void 0,(function*(){for(var t=yield xn(e),n=0;n<t.length;n++){let e=t[n];var o=e.typeId;let i=yield Ht(o);e.type=i}return t}))}var Bn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},Un=function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n},Ln=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Pn(e){return Ln(this,arguments,void 0,(function*(e,t=""){var o=yield Ht(e);yield G.removeNodeFromTree(e);var i=o.typeId,r=o.characterValue;yield O.removeTypeConcept(i,e),yield L.removeNodeByCharacter(r,e),_("concept",e);let c=yield function(e){return Bn(this,arguments,void 0,(function*(e,t=""){let o=!1;try{let i=yield yield yield q("application/x-www-form-urlencoded",t);const r=new FormData;r.append("id",e.toString()),r.append("apiKey","nodeserver");const{"Content-Type":c}=i,s=Un(i,["Content-Type"]),a=yield h(n.DeleteConceptUrl(),{method:"POST",headers:s,body:r});if(!a.ok)throw Q(a),new Error(`Error! status: ${a.status}`);o=(yield a.json()).success}catch(e){throw e instanceof Error?console.log("Delete concept error message: ",e.message):console.log("Delete concept unexpected error: ",e),e}return o}))}(e,t);return c}))}var Gn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Fn(e,t){return Gn(this,void 0,void 0,(function*(){try{const o=new Headers;o.append("Authorization","Bearer "+t);const i=new FormData;i.append("id",e.toString());const r=yield h(n.DeleteConceptUrl(),{method:"POST",body:i,headers:o});if(!r.ok)throw Q(r),new Error(`Delete composition Error! status: ${r.status}`)}catch(e){throw e instanceof Error?console.log("Delete composition error message: ",e.message):console.log("Delete composition unexpected error: ",e),e}}))}var bn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Dn(e,t,n,o){return bn(this,arguments,void 0,(function*(e,t,n,o,i=999){var r,c=n,s=n,a=n,l=e.startsWith("the_"),d=b();return r=l?e:"the_"+e,d=yield Ke(r),yield Tn(t,n,4,n,d.id,d.userId,0,999,999,c,o,a,i,s)}))}class $n{constructor(){this.composition=0,this.type="",this.linker="",this.inpage=10,this.page=1,this.listLinkers=[],this.fullLinkers=[],this.textSearch="",this.logic="or",this.reverse=!1,this.doFilter=!1,this.filterSearches=[],this.selectors=[]}}var On=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Vn(){return On(this,arguments,void 0,(function*(e=[]){var t=[];try{var n=[];for(let o=0;o<e.length;o++){let i=yield se.GetConnection(e[o]);0==i.id?n.push(e[o]):t.push(i)}if(0==n.length)return t;{var o=yield z();const e=yield T("/api/get_connection_bulk",{method:"POST",headers:o,body:JSON.stringify(n)});if(e.ok){const n=yield e.json();if(n.length>0){for(let e=0;e<n.length;e++){let o=n[e];t.push(o),se.AddConnection(o)}yield ue(t)}}else console.log("Get Connection Bulk error",e.status),Q(e);return t}}catch(e){throw e instanceof Error?console.log("Get Connection Bulk error message: ",e.message):console.log("Get Connection Bulk unexpected error: ",e),e}}))}var Mn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Hn(){return Mn(this,arguments,void 0,(function*(e=[]){yield ve(e);var t=[];for(let o=0;o<e.length;o++){var n=yield Se(e[o]);t.push(n)}return t}))}function jn(){return Mn(this,arguments,void 0,(function*(e=[]){yield ve(e);var t=[];for(let o=0;o<e.length;o++){var n=yield xe(e[o]);t.push(n)}return t}))}function Wn(){return Mn(this,arguments,void 0,(function*(e=[],t=[]){yield Vn(t),function(e=[],t=[]){for(let n=0;n<t.length;n++)e.includes(t[n].id)||se.RemoveConnection(t[n])}(t,yield fe(e));var n=[];for(let t=0;t<e.length;t++){var o=yield xe(e[t]);n.push(o)}return n}))}function Jn(){return Mn(this,arguments,void 0,(function*(e=[]){let t=[],n=[],o={};for(let o=0;o<(null==e?void 0:e.length);o++){let i=yield se.GetConnection(e[o]);0==i.id?t.push(e[o]):n.push(i)}for(let n=0;n<t.length;n++)o[e[n]]=!1;let i=[],r=yield Vn(t);n=[...n,...r];for(let e=0;e<n.length;e++)i.push(n[e].ofTheConceptId),i.push(n[e].toTheConceptId),i.push(n[e].typeId);return yield le(i),n}))}function zn(){return Mn(this,arguments,void 0,(function*(e=[],t=[]){let n=[],o=[];for(let e=0;e<t.length;e++){let i=yield se.GetConnection(t[e]);0==i.id?n.push(t[e]):o.push(i)}let i=yield Vn(n);for(let e=0;e<i.length;e++)o.push(i[e]);let r={},c=[];for(var s=0;s<o.length;s++)c.includes(o[s].ofTheConceptId)||c.push(o[s].ofTheConceptId);for(let t=0;t<e.length;t++){let n=yield Ee(e[t],o,c);r[e[t]]=n}return r}))}var qn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Kn(){return qn(this,arguments,void 0,(function*(e=0,t=[],o="",i=[]){var r=[];try{var c=new $n;c.composition=e,c.listLinkers=t,c.textSearch=o,c.fullLinkers=i;var s=JSON.stringify(c),a=yield z();const u=yield h(n.RecursiveSearchUrl(),{method:"POST",headers:a,body:s});if(u.ok){const e=yield u.json();var l=e.compositionIds,d=e.internalConnections;e.externalConnections,r=yield Wn(l,d)}else console.log("recursive search error ",u.status),Q(u);return r}catch(e){throw e instanceof Error?console.log("recursive search error message: ",e.message):console.log("recursive search unexpected error: ",e),e}}))}var Qn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Yn(e,t){return Qn(this,void 0,void 0,(function*(){try{var i={email:e,password:t},r=new Headers;r.append("Content-Type","application/json");var c=JSON.stringify(i);const s=yield h(n.LoginUrl(),{method:"POST",headers:r,body:c});if(s.ok){const e=yield s.json();return o.BearerAccessToken=e.data.token,e}console.log("Login tsccs error message: ",s.status),Q(s)}catch(e){throw e instanceof Error?console.log("Login tsccs error message: ",e.message):console.log(" Login tsccs unexpected error: ",e),e}}))}var Xn=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Zn(e){return Xn(this,void 0,void 0,(function*(){const t=yield function(){return Xn(this,arguments,void 0,(function*(e="",t={}){let n={message:"success",status:!1,statusCode:200,data:""};try{const o=yield h(e,{method:"POST",mode:"cors",cache:"no-cache",credentials:"same-origin",headers:{"Content-Type":"application/json"},redirect:"follow",referrerPolicy:"no-referrer",body:JSON.stringify(t)}),i=yield o.json();return o.ok?n={message:"success",status:!0,statusCode:200,data:i}:Q(o),n}catch(e){throw console.log("Signup Error: ",e),e}}))}(n.SignupUrl(),e);return t}))}var eo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function to(e){return eo(this,void 0,void 0,(function*(){const t=JSON.stringify({email:e.email,password:e.password});let o={message:"success",status:!1,statusCode:200,data:""};const i=new Headers;i.append("Content-Type","application/json");const r=n.LoginUrl();try{const e=yield h(r,{method:"POST",headers:i,body:t,redirect:"follow"}),n=yield e.json();return e.ok?o={message:"success",status:!0,statusCode:200,data:null==n?void 0:n.data}:Q(e),o}catch(e){throw console.log("Sign in api error",e),e}}))}function no(e,t){return-1===e.indexOf(t)&&e.push(t),e}function oo(e=[],t){var n,o;let i=[],r=null===(n=t.type)||void 0===n?void 0:n.characterValue;if((null==r?void 0:r.startsWith("the_"))||(r="the_"+r),Array.isArray(e))for(let n=0;n<e.length;n++){let c=null===(o=e[n].type)||void 0===o?void 0:o.characterValue;(null==c?void 0:c.startsWith("the_"))||(c="the_"+c),t.typeId!=e[n].typeId&&r!=c||i.push(e[n])}return i}function io(e=[],t){let n=[];if(Array.isArray(e)){const o=e.find((e=>e.toTheConceptId==t));o&&n.push(o);const i=e.find((e=>e.ofTheConceptId==t));i&&n.push(i)}return n}function ro(e=[],t){Array.isArray(e)&&e.splice(e.findIndex((function(e){return e.id===t.id})),1)}function co(e=[],t){Array.isArray(e)&&e.splice(e.findIndex((function(e){return e.id===t.id})),1)}class so{constructor(e,t,n,o){this.expiryTime=new Date(Date.now()+6e5),this.height=1,this.key=e,this.value=t,this.leftNode=n,this.rightNode=o}isValid(){const e=new Date(Date.now());return!(this.expiryTime<e&&(lo.removeNodeFromTree(this.key),1))}saveToCache(e){this.value.cached=e}addNode(e,t,n){if(null==t)return e;const o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addNode(e,o,n);else{if(!(t.key<e.key))return this.isValid(),e;t.rightNode=this.addNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));const r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}return this.isValid(),t}rightRotate(e){if(e){const t=e.leftNode;if(t){const n=t.rightNode;return e.leftNode=n,t.rightNode=e,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}leftRotate(e){if(e){const t=e.rightNode;if(t){const n=t.leftNode;return t.leftNode=e,e.rightNode=n,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}getHeight(e){return e?e.height:0}getBalanceFactor(e){return null==e?0:this.getHeight(e.leftNode)-this.getHeight(e.rightNode)}getFromNode(e,t){return t?e==t.key&&t.isValid()?t:e<t.key?this.getFromNode(e,t.leftNode):e>t.key?this.getFromNode(e,t.rightNode):t:t}removeNode(e,t){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNode(e.leftNode,t),e;if(e.key<t)return e.rightNode=this.removeNode(e.rightNode,t),e;if(null==e.leftNode){const t=e.rightNode;return e=null,t}if(null==e.rightNode){const t=e.leftNode;return e=null,t}{const t=this.inOrderSuccessor(e.rightNode);return e.value=t.value,e.key=t.key,e.rightNode=this.removeNode(e.rightNode,t.key),e}}countNodeBelow(e){return null==e?0:1+this.countNodeBelow(e.leftNode)+this.countNodeBelow(e.rightNode)}inOrderSuccessor(e){for(;null!=e.leftNode;)e=e.leftNode;return e}}var ao=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class lo{static addNodeToTree(e){if(null==this.root)return this.root=e,this.root;this.root=this.root.addNode(e,this.root,this.root.height)}static addCompositionToTree(e){const t=new so(e.id,e,null,null);this.addNodeToTree(t)}static getNodeFromTree(e){return ao(this,void 0,void 0,(function*(){return this.root?this.root.getFromNode(e,this.root):null}))}static removeNodeFromTree(e){return ao(this,void 0,void 0,(function*(){this.root&&(this.root=this.root.removeNode(this.root,e))}))}static countNumberOfNodes(){return this.root?this.root.countNodeBelow(this.root):0}}lo.root=null;var uo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ho(e,t,n,o){return uo(this,arguments,void 0,(function*(e,t,n,o,i=[]){var r,c;let s={};const a=[];if(0==e)return"";let l=fo(n,e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield Ht(e)),0!=l.id&&null==l.type){const e=l.typeId;let t=fo(n,e);l.type=t,null==t&&null!=e&&null!=e&&(t=yield Ht(e),l.type=t)}if(!o.includes(e))return null==l?void 0:l.characterValue;if(i.includes(e))return"";i.push(e);for(let l=0;l<t.length;l++)if(t[l].ofTheConceptId==e){const d=t[l].toTheConceptId;if(o.includes(e)){let e=fo(n,d);if(null!=e&&0!=e.id||null==d||null==d||(e=yield Ht(d)),0!=e.id&&null==(null==e?void 0:e.type)){const t=e.typeId;let n=yield M.GetConcept(t);e.type=n,null==n&&null!=t&&null!=t&&(n=yield Ht(t),e.type=n)}const l="the_",u=(null!==(c=null===(r=null==e?void 0:e.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"").replace(l,"");if(isNaN(Number(u))){if(u){const e=yield ho(d,t,n,o,i);s[u]=e}}else{const e=yield ho(d,t,n,o,i);a[u]=e,s=a}}}return s}))}function fo(e,t){let n=b();for(let o=0;o<e.length;o++)if(t==e[o].id)return n=e[o],n;return n}class yo{constructor(){this.id=0,this.mainConcept=b(),this.connections=[],this.concepts=[],this.subcompositions=[],this.cached={}}updateCache(){return e=this,t=void 0,o=function*(){if(0==this.mainConcept.id)for(let e=0;e<this.concepts.length;e++)this.concepts[e].id==this.id&&(this.mainConcept=this.concepts[e]);this.cached=yield ho(this.id,this.connections,this.concepts,this.subcompositions,[])},new((n=void 0)||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}));var e,t,n,o}UpdateAcrossDistributedSystem(){var e,t;try{0!=this.id&&(t=null===(e=this.id)||void 0===e?void 0:e.toString(),n.MQTT_CONNECTION&&n.MQTT_CONNECTION.publish("compositionUpdate",t))}catch(e){console.log("Error while publishing message",e)}}isUpdating(){this.UpdateAcrossDistributedSystem()}GetDataCache(){var e,t,n;const o={};o[null!==(n=null===(t=null===(e=this.mainConcept)||void 0===e?void 0:e.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:""]=this.cached;const i={};return i.data=o,i.id=this.id,i}}var po=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function vo(e){return po(this,arguments,void 0,(function*(e,t=null,n=null,o=null,i=null,r=null,c=null,s=null){const a=null!=i?i:999,l=null!=r?r:4,d=null!=c?c:999;let u=null!=o?o:0,h=b();null==s&&(s=new yo);for(const o in e)if("object"==typeof e[o]||Array.isArray(e[o])){const f=yield Rt(o,"",!0,a,l,d);if(null==t&&null==n){let t=u;h=f,t=f.id,u=f.id,s.concepts.push(f),s.id=f.id,yield vo(e[o],f.id,f.userId,t,i,r,c,s)}else{const a=null!=t?t:999,l=null!=n?n:999,y=u;h=f,s.concepts.push(f);const p=yield mt(a,l,f.id,f.userId,y,d,f.userId);s.connections.push(p),yield vo(e[o],f.id,f.userId,y,i,r,c,s)}null!=e[o]&&null!=e[o]&&s.subcompositions.push(f.id)}else{const i=null!=t?t:999,r=null!=n?n:999,c=u,h=yield Rt(o,e[o],!1,a,l,d);s.concepts.push(h);const f=yield mt(i,r,h.id,h.userId,c,d,h.userId);s.connections.push(f)}return h}))}var go=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Co(e){return go(this,void 0,void 0,(function*(){try{const t=yield z(),o=yield h(n.GetConnectionsBetweenUrl(),{method:"POST",headers:t,body:JSON.stringify(e)});if(!o.ok)throw console.log("GetConnectionsBetweenApi error status: ",o.status),Q(o),new Error(`GetConnectionsBetweenApi error: ${o.status}`);return yield o.json()}catch(e){throw e instanceof Error?console.log("GetConnectionsBetweenApi error message: ",e.message):console.log("GetConnectionsBetweenApi unexpected error: ",e),e}}))}function mo(e){var t,n,o,i,r,c,s;return{ofTheConceptId:null!==(t=e.ofTheConceptId)&&void 0!==t?t:0,toTheConceptId:null!==(n=e.toTheConceptId)&&void 0!==n?n:0,typeId:null!==(o=e.typeId)&&void 0!==o?o:0,type:null!==(i=e.type)&&void 0!==i?i:"",oldType:null!==(r=e.oldType)&&void 0!==r?r:"",reverse:null!==(c=e.reverse)&&void 0!==c&&c,isComposition:null!==(s=e.isComposition)&&void 0!==s&&s,connectionIds:[]}}var To=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class wo{constructor(){this.actions={concepts:[],connections:[]},this.success=!0,this.pendingConnectionDeletions=[],this.transactionId=Math.random().toString().substring(5)}initialize(){return To(this,void 0,void 0,(function*(){yield vt.initializeTransaction(this.transactionId)}))}markAction(){return To(this,void 0,void 0,(function*(){yield vt.markTransactionActions(this.transactionId,this.actions)}))}rollbackTransaction(){return To(this,void 0,void 0,(function*(){this.success=!1,this.actions={concepts:[],connections:[]},this.pendingConnectionDeletions=[],yield vt.rollbackTransaction(this.transactionId,this.actions)}))}commitTransaction(){return To(this,void 0,void 0,(function*(){if(!this.success)throw Error("Query Transaction Expired");yield vt.SyncDataOnline(this.transactionId),this.pendingConnectionDeletions.length>0&&(yield Vt(this.pendingConnectionDeletions)),this.actions={concepts:[],connections:[]},this.pendingConnectionDeletions=[],this.success=!1}))}DeleteConnectionsBetween(e){return To(this,void 0,void 0,(function*(){return this.DeleteConnectionsBetweenBulk([e])}))}DeleteConnectionsBetweenBulk(e){return To(this,arguments,void 0,(function*(e,t=[]){try{if(!this.success)throw Error("Query Transaction Expired");const n=[...t];if(e.length>0){const t=e.map(mo),o=yield Co(t);for(const e of o)n.push(...e.connectionIds)}return this.pendingConnectionDeletions.push(...n),n}catch(e){throw console.log(e),this.success=!1,e}}))}MakeTheInstanceConcept(e,t){return To(this,arguments,void 0,(function*(e,t,n=!1,o,i,r=999,c=0){try{if(!this.success)throw Error("Query Transaction Expired");const s=yield Rt(e,t,n,o,i,r,c,this.actions);return yield this.markAction(),s}catch(e){throw console.log(e),this.success=!1,e}}))}CreateTypeConcept(e,t){return To(this,arguments,void 0,(function*(e,t,n=("number"==typeof e?999:e.userId),o=("number"==typeof e?4:e.accessId),i=999){try{if(!this.success)throw Error("Query Transaction Expired");return yield sn(e,t,n,o,i)}catch(e){throw console.log(e),this.success=!1,e}}))}CreateConnection(e,t,n){return To(this,void 0,void 0,(function*(){try{if(!this.success)throw Error("Query Transaction Expired");const o=yield Tt(e,t,n,this.actions);return yield this.markAction(),o}catch(e){throw console.log(e),this.success=!1,e}}))}MakeTheTypeConcept(e,t,n,o){return To(this,void 0,void 0,(function*(){try{if(!this.success)throw Error("Query Transaction Expired");const i=yield Nn(e,t,n,o,this.actions);return yield this.markAction(),i}catch(e){throw console.log(e),this.success=!1,e}}))}CreateTheConnectionGeneral(e,t,n,o,i,r,c){return To(this,arguments,void 0,(function*(e,t,n,o,i,r,c,s=1,a=4,l=999){try{if(!this.success)throw Error("Query Transaction Expired");const d=yield mt(e,t,n,o,i,r,c,s,a,l,this.actions);return yield this.markAction(),d}catch(e){throw console.log(e),this.success=!1,e}}))}}var Io=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function No(e){return Io(this,void 0,void 0,(function*(){const t=e.userId,n=e.sessionId,o=e.accessId;let i=[];const r=[];let c=b(),s=b();const a=[];let l=e.compositionId;const d=e.ofTheCompositionId;let u=[];if(l<0){let e=yield Ht(l,t);if(!(e.id>0))return null;l=e.id}const h=new wo;yield h.initialize();try{i=yield we(l);const f=[],y=new yo,p=[];y.id=l,y.isUpdating();let v=[];for(let e=0;e<i.length;e++)no(p,i[e].ofTheConceptId),no(f,i[e].ofTheConceptId),no(f,i[e].toTheConceptId),v.push(i[e].ofTheConceptId);y.subcompositions=p,y.connections=i;for(let e=0;e<f.length;e++){const t=yield Ht(f[e]);l==f[e]&&(c=t),d==f[e]&&(s=t),r.push(t)}const g=e.patchObject;for(const e in g){let i=b();const l=g[e];let d=c;if(s.id>0&&(d=s),Array.isArray(l)||"object"==typeof l){i=yield h.MakeTheInstanceConcept(e,"",!0,c.userId,4,999),y.subcompositions.push(i.id);const t=oo(r,i);for(let e=0;e<t.length;e++)if(t[e].id>0){const n=io(y.connections,t[e].id);u=u.concat(n),a.push(t[e])}yield vo(g[e],i.id,i.userId,c.id,c.userId,4,999,y)}else{i=yield h.MakeTheInstanceConcept(e,l,!1,t,o,n);const c=oo(r,i);for(let e=0;e<c.length;e++)if(c[e].id>0){const t=io(y.connections,c[e].id);u=u.concat(t),a.push(c[e])}}const f=yield h.CreateTheConnectionGeneral(d.id,d.userId,i.id,i.userId,c.id,n,t);r.push(i),y.connections.push(f)}for(let e=0;e<u.length;e++)co(y.connections,u[e]);u.length>0&&(yield h.DeleteConnectionsBetweenBulk([],u.map((e=>e.id))));for(let e=0;e<a.length;e++)ro(r,a[e]);return y.concepts=y.concepts.concat(r),y.mainConcept=c,y.id=c.id,yield h.commitTransaction(),yield y.updateCache(),lo.addCompositionToTree(y),y.GetDataCache()}catch(e){throw yield h.rollbackTransaction(),e}}))}var Ao=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ko(e,t,o,i){return Ao(this,arguments,void 0,(function*(e,t,o,i,r=10,c=1){var s=yield q("application/x-www-form-urlencoded",i),a=new URLSearchParams;a.append("type",e),a.append("search",t),a.append("composition",o),a.append("inpage",r.toString()),a.append("page",c.toString());const l=n.SearchCompositionsUrl()+"?"+a.toString();try{const e=yield h(l,{method:"GET",headers:s});if(e.ok)return yield e.json();Q(e)}catch(e){throw e}}))}var So=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function xo(e){return So(this,arguments,void 0,(function*(e,t=""){var o=yield q("application/json",t);const i=n.SearchLinkMultipleAll(),r=JSON.stringify(e);try{const e=yield h(i,{method:"POST",headers:o,body:r});if(e.ok)return yield e.json();Q(e)}catch(e){throw e}}))}var _o=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Ro(e){return _o(this,arguments,void 0,(function*(e,t=[]){var n,o;let i=[];const r=[];let c={},s={};const a=[];let l=yield M.GetConcept(e);0==l.id&&null!=e&&null!=e&&(l=yield me(e));let d=[];d=t.length>0?Eo(e,t):yield we(e),i=d;for(let e=0;e<i.length;e++)a.includes(i[e].ofTheConceptId)||(a.push(i[e].ofTheConceptId),r.push(i[e].ofTheConceptId)),r.includes(i[e].toTheConceptId)||r.push(i[e].toTheConceptId);return s=yield Ue(e,i,a,[]),c[null!==(o=null===(n=null==l?void 0:l.type)||void 0===n?void 0:n.characterValue)&&void 0!==o?o:""]=s,0==l.id?"":c}))}function Eo(e,t){const n=[];for(let o=0;o<t.length;o++)t[o].typeId==e&&n.push(t[o]);return n}function Bo(e){return _o(this,arguments,void 0,(function*(e,t=[]){var n,o;let i={},r=[];const c=[];let s;const a={},l=[];let d=yield M.GetConcept(e);0==d.id&&null!=e&&null!=e&&(d=yield me(e));let u=[];u=t.length>0?Eo(e,t):yield we(e),r=u;for(let e=0;e<r.length;e++)l.includes(r[e].ofTheConceptId)||(l.push(r[e].ofTheConceptId),c.push(r[e].ofTheConceptId)),c.includes(r[e].toTheConceptId)||c.push(r[e].toTheConceptId);return s=yield Ue(e,r,l),a[null!==(o=null===(n=null==d?void 0:d.type)||void 0===n?void 0:n.characterValue)&&void 0!==o?o:""]=s,i.created_at=d.entryTimeStamp,i.data=a,i.id=e,0==d.id?"":i}))}function Uo(e,t){return _o(this,void 0,void 0,(function*(){let n=[];const o=[];n=yield Vn(t);for(let t=0;t<e.length;t++){const i=yield Bo(e[t],n);i&&o.push(i)}return o}))}var Lo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Po(e){return Lo(this,void 0,void 0,(function*(){try{var t=yield z();const o=JSON.stringify(e),i=yield h(n.CreateSessionId(),{method:"POST",headers:t,body:o});return i.ok?i.json():(console.log("Creating session failed",yield i.json()),Q(i),null)}catch(e){throw console.log("Creating session failed",e),e}}))}var Go=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Fo(e,t){return Go(this,void 0,void 0,(function*(){try{var o=yield z("application/x-www-form-urlencoded");const i=new URLSearchParams;i.append("sessionId",e.toString()),i.append("url",t);const r=yield h(n.CreateSessionVisitUrl(),{method:"POST",headers:o,body:i});return r.ok?r.json():(console.log("Creating session url failed",yield r.json()),Q(r),null)}catch(e){throw console.log("Creating session url failed",e),e}}))}var bo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Do(e,t,o){return bo(this,arguments,void 0,(function*(e,t,o,i=10,r=1){let c=[];try{var s=new URLSearchParams;s.append("typeId",`${e}`),s.append("toTheConceptId",`${t}`),s.append("userId",`${o}`),s.append("inpage",`${i}`),s.append("page",`${r}`);var a=yield z("application/x-www-form-urlencoded");const l=yield h(n.GetAllConnectionsToConceptUrl(),{method:"POST",headers:a,body:s});return l.ok?c=yield l.json():(console.log("Get connection of concept error",l.status),Q(l)),c}catch(e){throw e instanceof Error?console.log("Get connection of concept error message: ",e.message):console.log("Get connection of concept unexpected error: ",e),e}}))}var $o=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Oo(e,t){return $o(this,arguments,void 0,(function*(e,t,n=10,o=1,i=!1){let r=[],c=yield Ht(e),s=yield We(t);if(s.id>0){let e=[],t=[];if(i){t=yield Do(s.id,c.id,c.userId,n,o);let e=[];for(let n=0;n<t.length;n++)e.push(t[n].ofTheConceptId);yield ve(e);for(let e=0;e<t.length;e++){let n=t[e].ofTheConceptId,o=yield Ht(n),i=yield _e(o.id);r.push(i)}}else{t=yield Lt(s.id,c.id,c.userId,n,o);for(let n=0;n<t.length;n++)e.push(t[n].toTheConceptId);yield ve(e);for(let e=0;e<t.length;e++){let n=t[e].toTheConceptId,o=yield Ht(n),i=yield _e(o.id);r.push(i)}}}return r}))}function Vo(e,t){return $o(this,arguments,void 0,(function*(e,t,n=10,o=1,i=!1){let r=[],c=yield Ht(e),s=yield We(t),a=[],l=[];if(s.id>0){if(i){a=yield Do(s.id,c.id,c.userId,n,o);for(let e=0;e<a.length;e++)l.push(a[e].ofTheConceptId)}else{a=yield Lt(s.id,c.id,c.userId,n,o);for(let e=0;e<a.length;e++)l.push(a[e].toTheConceptId)}r=yield le(l)}return r}))}class Mo{constructor(e,t,n){this.value=new Map,this.connectionValue=new Map,this.key=e,t.id>0&&this.value.set(t.ghostId,t),n.id>0&&this.connectionValue.set(n.ghostId,n)}}class Ho{constructor(e=0,t,n,o,i,r,c=999){this.isTemp=!1,this.applicationId=999,this.type=hn(),this.id=e,this.ofTheConceptId=t,this.toTheConceptId=n,this.typeId=o,this.ghostId=e,this.orderId=i,this.typeCharacter="",this.accessId=r,this.entryTimeStamp=D(new Date),this.terminationDateTime=new Date,this.localSyncTime=new Date,this.applicationId=c}}var jo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Wo{static compositeKey(e,t,n=999){return("0000"+e.toString(16).toUpperCase()).slice(-4)+("0000"+t.toString(16).toUpperCase()).slice(-4)+("0000"+n.toString(16).toUpperCase()).slice(-4)}static waitForDataToLoad(){return jo(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isDataLoaded)return e("done");setTimeout(Wo.checkFlag,1e3,e)}static addConceptToTree(e,t,n=999){const o=this.compositeKey(t,n,e.applicationId),i=this.nodeMap.get(o);i?e.id>0&&i.value.set(e.ghostId,e):this.nodeMap.set(o,new Mo(o,e,new Ho(0,0,0,0,0,0)))}static addConnectionToTree(e,t,n=999){const o=this.compositeKey(t,n,e.applicationId),i=this.nodeMap.get(o);i?e.id>0&&i.connectionValue.set(e.ghostId,e):this.nodeMap.set(o,new Mo(o,hn(),e))}static getNodeFromTree(e,t){return jo(this,arguments,void 0,(function*(e,t,n=999){var o;const i=this.compositeKey(e,t,n);return null!==(o=this.nodeMap.get(i))&&void 0!==o?o:null}))}static removeNodeFromTree(e){return jo(this,arguments,void 0,(function*(e,t=999,n=999){const o=this.compositeKey(e,t,n);this.nodeMap.delete(o)}))}static countNumberOfNodes(){return this.nodeMap.size}}Wo.nodeMap=new Map;var Jo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function zo(e,t){return Jo(this,arguments,void 0,(function*(e,t,n=999,o=999){var i;let r=yield Wo.getNodeFromTree(e,n,o),c=hn();return r&&(c=null!==(i=r.value.get(t))&&void 0!==i?i:c),c}))}function qo(e,t){return Jo(this,arguments,void 0,(function*(e,t,n=999,o=999){var i;let r=yield Wo.getNodeFromTree(e,n,o),c=new Ho(0,0,0,0,0,0);return r&&(c=null!==(i=r.connectionValue.get(t))&&void 0!==i?i:c),c}))}function Ko(e,t){return Jo(this,arguments,void 0,(function*(e,t,n=999){Wo.addConceptToTree(e,t,n)}))}function Qo(e,t){return Jo(this,arguments,void 0,(function*(e,t,n=999){Wo.addConnectionToTree(e,t,n)}))}var Yo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Xo(e){return Yo(this,arguments,void 0,(function*(e,t=""){var o=yield q("application/json",t);const i=n.SearchLinkMultipleAllApiUrl(),r=JSON.stringify(e);try{const e=yield h(i,{method:"POST",headers:o,body:r});if(e.ok)return yield e.json();Q(e)}catch(e){throw e}}))}var Zo=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ei(e){return Zo(this,arguments,void 0,(function*(e,t=""){let n=[],o=yield Xo(e,t),i=e[0].composition;const r=o;let c=r.compositionIds,s=r.internalConnections,a=r.linkers,l=r.reverse;return n=yield zn(c,s),yield ti(a,n,i,l)}))}function ti(e,t,n){return Zo(this,arguments,void 0,(function*(e,t,n,o=[]){let i={},r=yield Vn(e);for(let e=0;e<r.length;e++){let n=!1;if(o.includes(r[e].id)&&(n=!0),1==n){if(t[r[e].ofTheConceptId]&&t[r[e].toTheConceptId]){let n=t[r[e].toTheConceptId],o=yield Ht(r[e].typeId),i=null==n?void 0:n.data,c=Object.keys(i)[0];try{let n=o.characterValue+"_reverse";"string"==typeof i&&(i={}),Array.isArray(i[c][n])||("string"==typeof i[c]&&(i[c]={}),i[c][n]=[]),i[c][n].push(t[r[e].ofTheConceptId])}catch(e){}}}else if(t[r[e].ofTheConceptId]&&t[r[e].toTheConceptId]){let n=t[r[e].ofTheConceptId],o=yield Ht(r[e].typeId),i=null==n?void 0:n.data,c=Object.keys(i)[0];try{"string"==typeof i&&(i={}),Array.isArray(i[c][o.characterValue])||("string"==typeof i[c]&&(i[c]={}),i[c][o.characterValue]=[]),i[c][o.characterValue].push(t[r[e].toTheConceptId])}catch(e){}}}return i=t[n],i}))}var ni=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},oi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ii(e){return oi(this,void 0,void 0,(function*(){var t;let o=yield function(e){return ni(this,void 0,void 0,(function*(){let t=[];try{var o=yield z();const i=yield h(n.ViewInternalDataUrl(),{method:"POST",headers:o,body:JSON.stringify(e)});if(i.ok){let e=yield i.json(),n={};for(let o=0;o<e.length;o++){let i=e[o].concepts;t=e[o].connections;let r=e[o].id;yield le(i),n[r]=t}return n}return console.log("View Internal Data error",i.status),Q(i),t}catch(e){throw e instanceof Error?console.log(" This is the view internal data error message: ",e.message):console.log(" This is the view internal data unexpected error: ",e),e}}))}(e),i=[];for(let n=0;n<e.length;n++){let r=e[n],c=o[r];if(r&&c){let e=[],t={};for(let t=0;t<c.length;t++)e.includes(c[t].ofTheConceptId)||e.push(c[t].ofTheConceptId);let n=yield Ue(r,c,e);t.data=n,t.id=r,i.push(t)}else{let e={};e.id=r;let n=yield Ht(r),o={};n.type&&(o[null===(t=null==n?void 0:n.type)||void 0===t?void 0:t.characterValue]=n.characterValue,e.data=o,i.push(e))}}return i}))}function ri(e){const t=b();return t.id=e.id,t.ghostId=e.ghostId,t.userId=e.userId,t.accessId=e.accessId,t.entryTimeStamp=e.entryTimeStamp,t.typeId=e.typeId,t.categoryId=e.categoryId,t.characterValue=e.characterValue,t}var ci=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},si=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ai(e){return si(this,arguments,void 0,(function*(e,t=""){var o=yield function(e){return ci(this,arguments,void 0,(function*(e,t=""){var o,i,r,c,s,a,l=yield q("application/json",t);const d=new URLSearchParams({composition:String(null!==(o=e.composition)&&void 0!==o?o:""),search:String(null!==(i=e.search)&&void 0!==i?i:""),internalComposition:String(null!==(r=e.internalComposition)&&void 0!==r?r:""),type:String(null!==(c=e.type)&&void 0!==c?c:""),inpage:String(null!==(s=e.inpage)&&void 0!==s?s:""),page:String(null!==(a=e.page)&&void 0!==a?a:"")}),u=`${n.SearchInternalWithAuthenticatedCcsUrl()}?${d.toString()}`;try{const e=yield h(u,{method:"GET",headers:l});if(e.ok)return yield e.json();Q(e)}catch(e){throw e}}))}(e,t);return yield ii(o)}))}var li=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function di(e,t){return li(this,void 0,void 0,(function*(){let n=!0,o=yield kn(e),i=yield At(t),r=[];for(let e=0;e<o.length;e++)for(let t=0;t<i.length;t++)o[e].typeId==i[t].id&&r.push(o[e].id);for(let e=0;e<r.length;e++){let t=yield Ot(r[e]);n=n&&t}return n}))}function ui(e,t){return li(this,void 0,void 0,(function*(){let n=yield kn(e),o=yield At(t),i=[];for(let e=0;e<n.length;e++)for(let t=0;t<o.length;t++)n[e].typeId==o[t].id&&i.push(n[e].id);return i}))}class hi{constructor(){this.compositionId=0,this.userId=999,this.sessionId=999,this.accessId=4,this.ofTheCompositionId=0,this.patchObject={}}}class fi{constructor(){this.id="0",this.remote_address="",this.server_port="",this.server_address="",this.server_name="",this.server_software="",this.http_user_agent="",this.self="",this.port="",this.userId="",this.email=""}}class yi{constructor(){this.type="",this.search="",this.logicoperator="=",this.index=0,this.composition=!0,this.name="",this.operateon=""}}class pi{constructor(){this.type="",this.search="",this.composition="",this.internalComposition="",this.userId=999,this.inpage=10,this.page=1}}function vi(e){if(Array.isArray(e))return e.filter((e=>"string"==typeof e&&""!==e.trim()));if("string"!=typeof e)return[];const t=e.trim();if(!t)return[];try{const e=JSON.parse(t);if(Array.isArray(e))return e.filter((e=>"string"==typeof e&&""!==e.trim()))}catch(e){}return t.split(",").map((e=>e.trim())).filter(Boolean)}class gi{constructor(e){var t;this.aiUrl="https://ai.freeschema.com",this.cacheServerUrl="",this.cacheServers=[],this.accessToken="",this.enableAi=!0,this.enableAccessControl=!1,e&&(Object.assign(this,e),this.cacheServers=vi(null!==(t=e.cacheServers)&&void 0!==t?t:e.cache_servers),this.cacheServerUrl=e.cacheServerUrl||e.cacheServer||this.cacheServerUrl)}hasOAuthCredentials(){return!(!this.clientId||!this.clientSecret)}hasAccessToken(){return""!==this.accessToken}getFlag(e,t=!1){var n,o;return null!==(o=null===(n=this.flags)||void 0===n?void 0:n[e])&&void 0!==o?o:t}getParameter(e,t=""){var n,o;return null!==(o=null===(n=this.parameters)||void 0===n?void 0:n[e])&&void 0!==o?o:t}setFlag(e,t){this.flags||(this.flags={}),this.flags[e]=t}setParameter(e,t){this.parameters||(this.parameters={}),this.parameters[e]=t}}var Ci=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class mi{constructor(){this.name="Connection Array"}static CheckContains(e){for(var t=!1,n=0;n<this.connectionArray.length;n++)this.connectionArray[n].id==e.id&&(t=!0);return t}static AddConnection(e){this.CheckContains(e)&&this.RemoveConnection(e),(0!=e.id||e.isTemp)&&k("localconnection",e),this.connectionArray.push(e)}static AddToDictionary(e){this.connectionDictionary[e.id]=e}static RemoveConnection(e){for(var t=0;t<this.connectionArray.length;t++)this.connectionArray[t].id==e.id&&this.connectionArray.splice(t,1);e.id}static GetConnection(e){var t;t=null;for(var n=0;n<this.connectionArray.length;n++)this.connectionArray[n].id==e&&(t=this.connectionArray[n]);return t}static waitForDataToLoad(){return Ci(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isLocalConnectionLoaded)return e("done");setTimeout(mi.checkFlag,1e3,e)}static GetConnectionsOfCompositionLocal(e){return Ci(this,void 0,void 0,(function*(){var t=[];try{for(var n=0;n<this.connectionArray.length;n++)this.connectionArray[n].typeId==e&&t.push(this.connectionArray[n]);return t}catch(e){return t}}))}getName(){return this.name}}mi.connectionArray=[],mi.connectionDictionary=[];var Ti=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function wi(){return Ti(this,void 0,void 0,(function*(){yield function(){return Ti(this,void 0,void 0,(function*(){var e=yield x("connection");if(Array.isArray(e))for(var t=0;t<e.length;t++)se.AddConnectionToMemory(e[t])}))}()}))}function Ii(){return Ti(this,void 0,void 0,(function*(){yield function(){return Ti(this,void 0,void 0,(function*(){var e=yield R("localconnection");if(Array.isArray(e))for(var t=0;t<e.length;t++)mi.AddConnection(e[t])}))}()}))}class Ni{constructor(e,t,n,o){this.variants=[],this.height=1,this.key=e,this.value=t,this.leftNode=n,this.rightNode=o,this.currentNode=null}addCurrentNode(e,t){return null==t?t=e:(e.value.typeId!=t.value.typeId&&(t.currentNode=this.addCurrentNode(e,t.currentNode)),t)}addCurrentNodeType(e,t){if(null==t)return e;var n=!1;for(let o=0;o<t.variants.length;o++)t.variants[o].value.id==e.value.id&&(n=!0);return n||t.variants.push(e),t}addNode(e,t,n){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addNode(e,o,n);else{if(!(t.key<e.key))return t;t.rightNode=this.addNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}return t}addCharacterNode(e,t,n){if(""!=e.value.characterValue){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addCharacterNode(e,o,n);else{if(!(t.key<e.key))return t.key==e.key&&""!=t.key&&t.value.id!=e.value.id&&t.addCurrentNodeType(e,t),t;t.rightNode=this.addCharacterNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}}return t}addTypeNode(e,t,n){if(0!=e.value.typeId){if(null==t)return e;var o=t.leftNode,i=t.rightNode;if(t.key>e.key)t.leftNode=this.addTypeNode(e,o,n);else{if(!(t.key<e.key))return t.key==e.key&&0!=t.key&&t.value.id!=e.value.id&&t.addCurrentNodeType(e,t),t;t.rightNode=this.addTypeNode(e,i,n)}t.height=1+Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode));let r=this.getBalanceFactor(t);if(r>1&&t.leftNode){if(e.key<t.leftNode.key)return this.rightRotate(t);if(e.key>t.leftNode.key)return t.leftNode=this.leftRotate(t.leftNode),this.rightRotate(t)}if(r<-1&&t.rightNode){if(e.key>t.rightNode.key)return this.leftRotate(t);if(e.key<t.rightNode.key)return t.rightNode=this.rightRotate(t.rightNode),this.leftRotate(t)}}return t}rightRotate(e){if(e){let t=e.leftNode;if(t){let n=t.rightNode;return e.leftNode=n,t.rightNode=e,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}leftRotate(e){if(e){let t=e.rightNode;if(t){let n=t.leftNode;return t.leftNode=e,e.rightNode=n,e.height=Math.max(this.getHeight(e.leftNode),this.getHeight(e.rightNode))+1,t.height=Math.max(this.getHeight(t.leftNode),this.getHeight(t.rightNode))+1,t}}return e}getHeight(e){return e?e.height:0}getBalanceFactor(e){return null==e?0:this.getHeight(e.leftNode)-this.getHeight(e.rightNode)}getFromNode(e,t){return t?e==t.key?t:e<t.key?this.getFromNode(e,t.leftNode):e>t.key?this.getFromNode(e,t.rightNode):t:t}getCharacterFromNode(e,t){return t?e==t.key?t:e<t.key?this.getCharacterFromNode(e,t.leftNode):e>t.key?this.getCharacterFromNode(e,t.rightNode):t:t}getFromNodeWithCharacterAndType(e,t,n){if(e=`${e}`,n){if(e==n.key){if(e==n.value.characterValue&&t==n.value.typeId)return n;for(let e=0;e<n.variants.length;e++)if(n.variants[e].value.typeId==t)return n.variants[e]}else{if(e<n.key)return this.getFromNodeWithCharacterAndType(e,t,n.leftNode);if(e>n.key)return this.getFromNodeWithCharacterAndType(e,t,n.rightNode)}return null}return n}removeNode(e,t){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNode(e.leftNode,t),e;if(e.key<t)return e.rightNode=this.removeNode(e.rightNode,t),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var n=this.inOrderSuccessor(e.rightNode);return e.value=n.value,e.key=n.key,e.variants=n.variants,e.currentNode=n.currentNode,e.rightNode=this.removeNode(e.rightNode,n.key),e}removeNodeWithVariants(e,t,n){if(null==e)return e;if(e.key>t)return e.leftNode=this.removeNodeWithVariants(e.leftNode,t,n),e;if(e.key<t)return e.rightNode=this.removeNodeWithVariants(e.rightNode,t,n),e;if(e.variants.length>0)if(e.value.id==n){var o=e.variants[0];if(o)return e.value=o.value,e.key=o.key,e.currentNode=o.currentNode,e.variants.splice(0,1),e}else for(let t=0;t<e.variants.length;t++)if(n==e.variants[t].value.id)return e.variants.splice(t,1),e;if(null==e.leftNode){let t=e.rightNode;return e=null,t}if(null==e.rightNode){let t=e.leftNode;return e=null,t}var i=this.inOrderSuccessor(e.rightNode);return e.value=i.value,e.key=i.key,e.variants=i.variants,e.currentNode=i.currentNode,e.rightNode=this.removeNodeWithVariants(e.rightNode,i.key,n),e}countNodeBelow(e){return null==e?0:1+this.countNodeBelow(e.leftNode)+this.countNodeBelow(e.rightNode)}inOrderSuccessor(e){for(;null!=e.leftNode;)e=e.leftNode;return e}}var Ai=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class ki{static addNodeToTree(e){if(null==this.root)return this.root=e,this.root;this.root=this.root.addNode(e,this.root,this.root.height)}static addConceptToTree(e){var t=new Ni(e.id,e,null,null);new Ni(e.characterValue,e,null,null),this.addNodeToTree(t)}static waitForDataToLoad(){return Ai(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isLocalDataLoaded)return e("done");setTimeout(ki.checkFlag,1e3,e)}static getNodeFromTree(e){return Ai(this,void 0,void 0,(function*(){return this.root?this.root.getFromNode(e,this.root):null}))}static getCharacterAndTypeFromTree(e,t){return this.root?this.root.getFromNodeWithCharacterAndType(e,t,this.root):this.root}static removeNodeFromTree(e){return Ai(this,void 0,void 0,(function*(){this.root&&(this.root=this.root.removeNode(this.root,e))}))}}ki.root=null;var Si=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class xi{static waitForDataToLoad(){return Si(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isLocalCharacterLoaded)return e("done");setTimeout(xi.checkFlag,1e3,e)}static addNodeToTree(e){return Si(this,void 0,void 0,(function*(){return null==this.LocalCharacterRoot?(this.LocalCharacterRoot=e,this.LocalCharacterRoot):(this.LocalCharacterRoot=this.LocalCharacterRoot.addCharacterNode(e,this.LocalCharacterRoot,this.LocalCharacterRoot.height),this.LocalCharacterRoot)}))}static addConceptToTree(e){if(""!=e.characterValue){var t=new Ni(e.characterValue,e,null,null);this.addNodeToTree(t)}}static getNodeFromTree(e){return this.LocalCharacterRoot?this.LocalCharacterRoot.getCharacterFromNode(e,this.LocalCharacterRoot):this.LocalCharacterRoot}static getCharacterAndTypeFromTree(e,t){return Si(this,void 0,void 0,(function*(){return this.LocalCharacterRoot?this.LocalCharacterRoot.getFromNodeWithCharacterAndType(e,t,this.LocalCharacterRoot):this.LocalCharacterRoot}))}static removeConceptType(e,t){this.LocalCharacterRoot&&(this.LocalCharacterRoot=this.LocalCharacterRoot.removeNodeWithVariants(this.LocalCharacterRoot,e,t))}}xi.LocalCharacterRoot=null;var _i=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Ri{static addNodeToTree(e){return _i(this,void 0,void 0,(function*(){return null==this.LocalTypeRoot?(this.LocalTypeRoot=e,this.LocalTypeRoot):(this.LocalTypeRoot=this.LocalTypeRoot.addTypeNode(e,this.LocalTypeRoot,this.LocalTypeRoot.height),this.LocalTypeRoot)}))}static addConceptToTree(e){if(0!=e.typeId){var t=new Ni(e.typeId,e,null,null);this.addNodeToTree(t)}}static removeConceptType(e,t){this.LocalTypeRoot&&(this.LocalTypeRoot=this.LocalTypeRoot.removeNodeWithVariants(this.LocalTypeRoot,e,t))}static getNodeFromTree(e){return this.LocalTypeRoot?this.LocalTypeRoot.getFromNode(e,this.LocalTypeRoot):this.LocalTypeRoot}static getTypeVariantsFromTree(e){var t=this.getNodeFromTree(e),n=[];if(t){n.push(null==t?void 0:t.value);for(let e=0;e<t.variants.length;e++)n.push(t.variants[e].value);return n}}static waitForDataToLoad(){return _i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(E.isLocalTypeLoaded)return e("done");setTimeout(Ri.checkFlag,1e3,e)}static getTypeVariantsFromTreeWithUserId(e,t){return _i(this,void 0,void 0,(function*(){var n=[],o=this.getNodeFromTree(e);if(o){o.value.userId==t&&n.push(null==o?void 0:o.value);for(let e=0;e<o.variants.length;e++)o.variants[e].value.userId==t&&n.push(o.variants[e].value)}return n}))}}Ri.LocalTypeRoot=null;var Ei=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Bi{constructor(){this.name="conceptsArray"}static AddConcept(e){e.id>0&&(k("localconcept",e),ki.addConceptToTree(e),xi.addConceptToTree(e),Ri.addConceptToTree(e),this.localconceptsArray.push(e))}static AddConceptToMemory(e){e.id>0&&(ki.addConceptToTree(e),xi.addConceptToTree(e),Ri.addConceptToTree(e))}static GetConcept(e){return Ei(this,void 0,void 0,(function*(){var t=hn(),n=yield ki.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConceptByCharacter(e){return Ei(this,void 0,void 0,(function*(){var t=hn(),n=xi.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterAndTypeLocal(e,t){return Ei(this,void 0,void 0,(function*(){var n=hn(),o=yield xi.getCharacterAndTypeFromTree(e,t);return o&&(n=o.value),n}))}static GetConceptsByTypeId(e){let t=[];for(var n=0;n<this.localconceptsArray.length;n++)this.localconceptsArray[n].typeId==e&&t.push(this.localconceptsArray[n]);return t}static GetConceptsByTypeIdAndUser(e,t){return Ei(this,void 0,void 0,(function*(){let n=[];return n=yield Ri.getTypeVariantsFromTreeWithUserId(e,t),n}))}getName(){return this.name}}Bi.localconceptsArray=[];var Ui=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Li(){return Ui(this,void 0,void 0,(function*(){var e=yield R("localconcept");if(Array.isArray(e))for(var t=0;t<e.length;t++){let n=e[t];Bi.AddConceptToMemory(n)}}))}var Pi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Gi{}Gi.isUpdated=!1,Gi.isOnlineSync=!1;var Fi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class bi{constructor(){this.accessCache=new Map,this.accessIndex=new Map,this.entityIndex=new Map,this.setCounter=0}generateKey(e,t,n){return`${e}:${t.toLowerCase()}:${null!=n?n:0}`}get(e,t,n){const o=this.generateKey(e,t,n),i=this.accessCache.get(o);return void 0===i?null:Date.now()>i.expiresAt?(this.accessCache.delete(o),null):i.value}set(e,t,n,o){const i=this.generateKey(e,t,n);this.accessCache.set(i,{value:o,expiresAt:Date.now()+3e5}),this.accessIndex.has(e)||this.accessIndex.set(e,new Set),this.accessIndex.get(e).add(i);const r=null!=n?n:0;this.entityIndex.has(r)||this.entityIndex.set(r,new Set),this.entityIndex.get(r).add(i),this.setCounter++,this.setCounter>=100&&(this.setCounter=0,this.sweepExpired())}remove(e,t,n){const o=this.generateKey(e,t,n);this.accessCache.delete(o);const i=this.accessIndex.get(e);i&&i.delete(o);const r=null!=n?n:0,c=this.entityIndex.get(r);c&&c.delete(o)}clear(){this.accessCache.clear(),this.accessIndex.clear(),this.entityIndex.clear(),this.setCounter=0}sweepExpired(){const e=Date.now();for(const[t,n]of this.accessCache)if(e>n.expiresAt){this.accessCache.delete(t);const e=t.split(":"),n=parseInt(e[0]),o=parseInt(e[2]),i=this.accessIndex.get(n);i&&(i.delete(t),0===i.size&&this.accessIndex.delete(n));const r=this.entityIndex.get(o);r&&(r.delete(t),0===r.size&&this.entityIndex.delete(o))}for(const[t,n]of bi.superAdminCache)e>n.expiresAt&&bi.superAdminCache.delete(t)}getPermissionsByAccessAndEntity(e,t){const n=new Map,o=this.accessIndex.get(e),i=Date.now();if(o){const e=null!=t?t:0;for(const t of o){const o=this.accessCache.get(t);if(o&&i<=o.expiresAt){const i=t.split(":");parseInt(i[2])===e&&n.set(i[1],o.value)}}}return n}getPermissionsByAccess(e){const t=new Map,n=this.accessIndex.get(e),o=Date.now();if(n)for(const e of n){const n=this.accessCache.get(e);if(n&&o<=n.expiresAt){const o=e.split(":"),i=parseInt(o[2]),r=o[1];t.set(`${i}:${r}`,n.value)}}return t}getPermissionsByEntity(e){const t=new Map,n=this.entityIndex.get(e),o=Date.now();if(n)for(const e of n){const n=this.accessCache.get(e);if(n&&o<=n.expiresAt){const o=e.split(":"),i=parseInt(o[0]),r=o[1];t.set(`${i}:${r}`,n.value)}}return t}getSuperAdmin(e){const t=bi.superAdminCache.get(e);return void 0===t?null:Date.now()>t.expiresAt?(bi.superAdminCache.delete(e),null):t.value}setSuperAdmin(e,t){bi.superAdminCache.set(e,{value:t,expiresAt:Date.now()+6e5})}clearSuperAdminCache(){bi.superAdminCache.clear()}}bi.superAdminCache=new Map;var Di,$i=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Oi{constructor(e){if(this.baseUrl=e||process.env.ACCESS_CONTROL_BASE_URL||"http://localhost:3000/api/access-control",!this.baseUrl)throw new Error("Access Control base URL is not configured")}getAsync(e){return $i(this,void 0,void 0,(function*(){const t=yield fetch(`${this.baseUrl}/${e}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!t.ok)throw new Error(`GET '${e}' failed with status ${t.status}`);const n=yield t.json();if(null==n)throw new Error(`The response for GET '${e}' returned null.`);return n}))}postAsync(e,t){return $i(this,void 0,void 0,(function*(){const n=yield fetch(`${this.baseUrl}/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`POST '${e}' failed with status ${n.status}`);const o=yield n.json();if(null==o)throw new Error(`The response for POST '${e}' returned null.`);return o}))}deleteAsync(e,t){return $i(this,void 0,void 0,(function*(){const n={method:"DELETE",headers:{"Content-Type":"application/json"}};null!=t&&(n.body=JSON.stringify(t));const o=yield fetch(`${this.baseUrl}/${e}`,n);if(!o.ok)throw new Error(`DELETE '${e}' failed with status ${o.status}`);const i=yield o.json();if(null==i)throw new Error(`The response for DELETE '${e}' returned null.`);return i}))}assignAccessAsync(e){return $i(this,void 0,void 0,(function*(){return this.postAsync("access/assign",e)}))}checkAccessAsync(e){return $i(this,void 0,void 0,(function*(){return this.postAsync("access/check",e)}))}revokeAccessAsync(e){return $i(this,void 0,void 0,(function*(){return this.deleteAsync("access/revoke",e)}))}assignAccessBulkAsync(e){return $i(this,void 0,void 0,(function*(){return this.postAsync("access/assign/bulk",e)}))}revokeAccessBulkAsync(e){return $i(this,void 0,void 0,(function*(){return this.deleteAsync("access/revoke/bulk",e)}))}checkAccessBulkAsync(e){return $i(this,void 0,void 0,(function*(){return this.postAsync("access/check/bulk",e)}))}getAccessByIdAsync(e){return $i(this,void 0,void 0,(function*(){return this.getAsync(`access/${e}`)}))}setAccessInheritanceAsync(e){return $i(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance",e)}))}getAccessInheritanceStatusAsync(e){return $i(this,arguments,void 0,(function*(e,t=999){return this.getAsync(`access/inheritance/status?accessId=${e}&connectionTypeId=${t}`)}))}assignSuperAdminAccessAsync(e){return $i(this,void 0,void 0,(function*(){return this.postAsync("access/super-admin",e)}))}revokeSuperAdminAccessAsync(e){return $i(this,void 0,void 0,(function*(){return this.deleteAsync("access/super-admin",e)}))}checkSuperAdminStatusAsync(e){return $i(this,void 0,void 0,(function*(){return this.getAsync(`access/super-admin?accessId=${e}`)}))}setParentAccessInheritanceAsync(e){return $i(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent",e)}))}removeParentAccessInheritanceAsync(e,t){return $i(this,void 0,void 0,(function*(){let n=`access/inheritance/parent?accessId=${e}`;return null!=t&&(n+=`&parentAccessId=${t}`),this.deleteAsync(n)}))}hasParentAccessInheritanceAsync(e,t){return $i(this,void 0,void 0,(function*(){let n=`access/inheritance/parent/status?accessId=${e}`;return null!=t&&(n+=`&parentAccessId=${t}`),this.getAsync(n)}))}getParentAccessIdAsync(e){return $i(this,void 0,void 0,(function*(){return this.getAsync(`access/inheritance/parent?accessId=${e}`)}))}setParentAccessInheritanceByConceptAsync(e){return $i(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent/concept",e)}))}setParentAccessInheritanceBulkByConceptAsync(e){return $i(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent/concept/bulk",e)}))}removeParentAccessInheritanceByConceptAsync(e,t){return $i(this,void 0,void 0,(function*(){let n=`access/inheritance/parent/concept?childConceptId=${e}`;return null!=t&&(n+=`&parentConceptId=${t}`),this.deleteAsync(n)}))}removeParentAccessInheritanceBulkByConceptAsync(e){return $i(this,void 0,void 0,(function*(){return this.deleteAsync("access/inheritance/parent/concept/bulk",e)}))}hasParentAccessInheritanceByConceptAsync(e,t){return $i(this,void 0,void 0,(function*(){let n=`access/inheritance/parent/concept/status?childConceptId=${e}`;return null!=t&&(n+=`&parentConceptId=${t}`),this.getAsync(n)}))}getParentAccessIdByConceptAsync(e){return $i(this,void 0,void 0,(function*(){return this.getAsync(`access/inheritance/parent/concept?childConceptId=${e}`)}))}assignSuperAdminByConceptAsync(e){return $i(this,void 0,void 0,(function*(){return this.postAsync("access/super-admin/concept",e)}))}revokeSuperAdminByConceptAsync(e){return $i(this,void 0,void 0,(function*(){return this.deleteAsync("access/super-admin/concept",e)}))}checkSuperAdminByConceptAsync(e){return $i(this,void 0,void 0,(function*(){return this.getAsync(`access/super-admin/concept?conceptId=${e}`)}))}setAccessInheritanceByConceptAsync(e){return $i(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/concept",e)}))}getAccessInheritanceStatusByConceptAsync(e){return $i(this,arguments,void 0,(function*(e,t=999){return this.getAsync(`access/inheritance/concept/status?conceptId=${e}&connectionTypeId=${t}`)}))}}!function(e){e[e.None=0]="None",e[e.Read=1]="Read",e[e.Write=2]="Write",e[e.Execute=4]="Execute",e[e.Delete=8]="Delete"}(Di||(Di={}));var Vi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};class Mi{static initialize(){console.log("AccessControlService initialized with access control disabled by default.")}static setEnabled(e){this.isAccessControlEnabled=e}static getEnabled(){return this.isAccessControlEnabled}static setBaseUrl(e){this.apiClient=new Oi(e)}static checkAccess(e,t,n){return Vi(this,void 0,void 0,(function*(){var o;if(t===Di.None)throw new Error("Permission is required");return null!==(o=(yield this.checkAccessBulk([e],t,n)).get(e))&&void 0!==o&&o}))}static checkAccessBulk(e,t,o){return Vi(this,void 0,void 0,(function*(){var i,r,c,s,a,l;if(t===Di.None)throw new Error("Permission is required");const d=this.permissionSetToString(t),u=new Map;if(!e||0===e.length)return u;if(!this.isAccessControlEnabled){for(const t of e)u.set(t,!0);return u}if(null!=o&&o>0)try{if(yield this.isSuperAdmin(o)){for(const t of e)u.set(t,!0);return u}}catch(e){}const f=[],y=new Set,p=new Map;let v=null;if(null!=o&&o>0)try{v=yield Ht(o)}catch(e){}let g=0;try{const e=yield function(){return e=this,t=void 0,i=function*(){let e=b();try{var t=yield z("application/x-www-form-urlencoded");const o=yield h(n.GetConceptByCharacterAndCategoryUrl(),{method:"POST",headers:t,body:"character_value=the_parent_access_inheritance"});return o.ok?(e=yield o.json(),M.AddConcept(e)):(console.log("This is the concept by category and character error",o.status),Q(o)),e}catch(e){throw e instanceof Error?console.log(" This is the concept by category and character error message: ",e.message):console.log(" This is the concept by category and character unexpected error: ",e),e}},new((o=void 0)||(o=Promise))((function(n,r){function c(e){try{a(i.next(e))}catch(e){r(e)}}function s(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(c,s)}a((i=i.apply(e,t||[])).next())}));var e,t,o,i}();e&&e.id&&(g=e.id)}catch(e){}const C=yield le(e),m=new Map;for(const e of C)m.set(e.id,e);const T=new Map;for(const t of e){const e=null!==(i=m.get(t))&&void 0!==i?i:yield Ht(t);if(!e||0===e.id){u.set(t,!1);continue}const n=null!==(r=e.accessId)&&void 0!==r?r:0,o=null!==(c=e.typeId)&&void 0!==c?c:0;if(v&&v.userId&&v.userId===e.userId){u.set(t,!0);continue}if(n<1e4){u.set(t,!0);continue}let a=0;if(o>0){let e=T.get(o);if(!e)try{e=yield Ht(o),T.set(o,e)}catch(e){}e&&(a=null!==(s=e.accessId)&&void 0!==s?s:0)}f.push({conceptId:t,accessId:n,typeAccessId:a}),n>0&&(y.add(n),p.set(n,t)),a>0&&y.add(a)}if(0===f.length)return u;const w=yield this.resolveBulkInheritanceGraph(y,g,p),I=[],N=new Set;for(const e of w.values())for(const t of e)N.has(t)||(N.add(t),I.push(t));const A=yield this.resolveSubjects(o),k=yield this.resolveBulkDecisions(I,d,A);for(const e of f){const t=null!==(a=w.get(e.accessId))&&void 0!==a?a:[e.accessId],n=e.typeAccessId>0?null!==(l=w.get(e.typeAccessId))&&void 0!==l?l:[e.typeAccessId]:[],o=this.hasAnyGrant(t,n,A,k);u.set(e.conceptId,o)}return u}))}static getConceptIdsWithPermission(e,t,n){return Vi(this,void 0,void 0,(function*(){if(e===Di.None)throw new Error("Permission is required");if(!t||0===t.length)return[];if(!this.isAccessControlEnabled)return t;const o=yield this.checkAccessBulk(t,e,n);return t.filter((e=>!0===o.get(e)))}))}static resolveBulkInheritanceGraph(e,t,n){return Vi(this,void 0,void 0,(function*(){var o;const i=new Map,r=new Set;let c=new Set(e),s=0;for(;c.size>0;){if(s>=10){console.warn("[AccessControl] BFS depth limit (10) reached. Stopping inheritance traversal.");break}s++;const e=new Set;for(const e of c)r.add(e);const a=Array.from(c);if(t>0)for(const t of a)try{const n=yield ui(t,["the_parent_access_inheritance"]);if(n&&n.length>0){const o=yield Vn(n);for(const n of o){const o=n.toTheConceptId;o&&o>0&&!r.has(o)&&(i.has(t)||i.set(t,[]),i.get(t).push(o),e.add(o))}}}catch(e){}for(const t of a)try{const n=yield this.apiClient.getParentAccessIdAsync(t);if(!0===(null==n?void 0:n.status)&&void 0!==n.data&&null!==n.data){const o=this.parseIntData(n);null!==o&&o>0&&!r.has(o)&&(i.has(t)||i.set(t,[]),i.get(t).push(o),e.add(o))}}catch(e){}for(const c of a)try{const s=yield this.apiClient.getAccessInheritanceStatusAsync(c);if(!this.parseBoolData(s))continue;const a=n.get(c);if(!a||0===a)continue;const l=yield kn(a);if(!l||0===l.length)continue;for(const s of l){if(s.ofTheConceptId!==a)continue;if(t>0&&s.typeId!==t)continue;const l=s.toTheConceptId;if(l&&0!==l)try{const t=yield Ht(l),s=null!==(o=null==t?void 0:t.accessId)&&void 0!==o?o:0;s>0&&!r.has(s)&&(i.has(c)||i.set(c,[]),i.get(c).push(s),n.set(s,l),e.add(s))}catch(e){}}}catch(e){}for(const t of r)e.delete(t);c=e}const a=new Map;for(const t of e){const e=[t],n=new Set([t]),o=[t];for(;o.length>0&&e.length<100;){const t=o.shift(),r=i.get(t);if(r)for(const t of r)n.has(t)||(n.add(t),e.push(t),o.push(t))}a.set(t,e)}return a}))}static resolveBulkDecisions(e,t,n){return Vi(this,void 0,void 0,(function*(){var o;const i=new Map,r=new Map;for(let o=0;o<n.length;o++){const c=n[o];for(const n of e){const e=this.cacheService.get(n,t,c),s=`${n}:${null!=c?c:0}`;null!==e?i.set(s,e):(r.has(o)||r.set(o,[]),r.get(o).push(n))}}for(const[e,c]of r){if(0===c.length)continue;const r=n[e];try{const e={accessIds:c,permission:t,entityId:r},n=yield this.apiClient.checkAccessBulkAsync(e);if(!0===(null==n?void 0:n.status)&&n.data&&Array.isArray(n.data)){const e=new Map;for(const t of n.data)e.set(t.accessId,t.hasAccess);for(const n of c){const c=null!==(o=e.get(n))&&void 0!==o&&o;this.cacheService.set(n,t,r,c),i.set(`${n}:${null!=r?r:0}`,c)}}else for(const e of c)this.cacheService.set(e,t,r,!1),i.set(`${e}:${null!=r?r:0}`,!1)}catch(e){for(const e of c)i.set(`${e}:${null!=r?r:0}`,!1)}}return i}))}static resolveSubjects(e){return Vi(this,void 0,void 0,(function*(){const t=[null];if(null!=e&&e>0){t.push(e);try{const n=yield ui(e,["the_entity_s_group"]);if(n&&n.length>0){const e=yield Vn(n);for(const n of e)n.toTheConceptId&&n.toTheConceptId>0&&t.push(n.toTheConceptId)}}catch(e){}}return t}))}static hasAnyGrant(e,t,n,o){for(const t of e)for(const e of n){const n=`${t}:${null!=e?e:0}`;if(!0===o.get(n))return!0}for(const e of t)for(const t of n){const n=`${e}:${null!=t?t:0}`;if(!0===o.get(n))return!0}return!1}static assignAccess(e,t,n){return Vi(this,void 0,void 0,(function*(){var o;if(t===Di.None)throw new Error("Permission is required");try{const i=null!==(o=(yield Ht(e)).accessId)&&void 0!==o?o:0,r=this.permissionSetToString(t),c=yield this.apiClient.assignAccessAsync({accessId:i,permission:r,entityId:n});if(!0===(null==c?void 0:c.status)&&c.data){const e=c.data;return this.cacheService.set(e.accessId,e.permission,e.entityId,e.hasAccess),!0}return!1}catch(o){throw new Error(`Error assigning access for conceptId ${e}, permission '${t}', entityId ${n}: ${o}`)}}))}static assignAccessBulk(e){return Vi(this,void 0,void 0,(function*(){var t;if(!e||!e.targets||0===e.targets.length)throw new Error("Request must contain at least one target");try{const n=yield this.apiClient.assignAccessBulkAsync(e);if(!0!==(null==n?void 0:n.status))throw new Error((null==n?void 0:n.message)||"Failed to assign bulk access");const o=[];for(const n of e.targets)for(const i of n.permissions){const r=null!==(t=e.accessId)&&void 0!==t?t:0;this.cacheService.set(r,i,n.entityId,!0),o.push({accessId:r,permission:i,entityId:n.entityId,hasAccess:!0})}return o}catch(e){throw console.error("Failed to assign bulk access:",e),e}}))}static revokeAccess(e,t,n){return Vi(this,void 0,void 0,(function*(){var o;try{const i=null!==(o=(yield Ht(e)).accessId)&&void 0!==o?o:0,r=this.permissionSetToString(t);if(0===i)throw new Error(`Concept with ID ${e} does not have a valid accessId`);const c=yield this.apiClient.revokeAccessAsync({accessId:i,permission:r,entityId:n}),s=!0===(null==c?void 0:c.status);return this.cacheService.set(i,r,n,!s),s}catch(o){throw new Error(`Error revoking access for concept ${e}, permission '${t}', entityId ${n}: ${o}`)}}))}static revokeAccessBulk(e){return Vi(this,void 0,void 0,(function*(){var t;if(!e||!e.targets||0===e.targets.length)throw new Error("Request must contain at least one target");try{yield this.apiClient.revokeAccessBulkAsync(e);const n=[];for(const o of e.targets)for(const i of o.permissions){const r=null!==(t=e.accessId)&&void 0!==t?t:0;this.cacheService.set(r,i,o.entityId,!1),n.push({accessId:r,permission:i,entityId:o.entityId,hasAccess:!1})}return n}catch(e){throw console.error("Failed to revoke bulk access:",e),e}}))}static setAccessInheritance(e){return Vi(this,void 0,void 0,(function*(){var t;try{const n=yield this.apiClient.setAccessInheritanceByConceptAsync({conceptId:e,connectionTypeId:999});return null!==(t=null==n?void 0:n.status)&&void 0!==t&&t}catch(t){throw new Error(`Error setting access inheritance for conceptId ${e}: ${t}`)}}))}static getAccessInheritanceStatus(e){return Vi(this,arguments,void 0,(function*(e,t=999){try{const n=yield this.apiClient.getAccessInheritanceStatusByConceptAsync(e,t);return this.parseBoolData(n)}catch(n){throw new Error(`Error getting access inheritance status for conceptId ${e}, connectionTypeId ${t}: ${n}`)}}))}static setAccessInheritanceStatus(e,t){return Vi(this,arguments,void 0,(function*(e,t,n=999){var o;try{const i=yield this.apiClient.setAccessInheritanceByConceptAsync({conceptId:e,enable:t,connectionTypeId:n});return null!==(o=null==i?void 0:i.status)&&void 0!==o&&o}catch(t){throw new Error(`Error setting access inheritance status for conceptId ${e}: ${t}`)}}))}static setParentAccessInheritance(e,t){return Vi(this,void 0,void 0,(function*(){try{const n=yield this.apiClient.setParentAccessInheritanceByConceptAsync({parentConceptId:t,childConceptId:e});if(!0===(null==n?void 0:n.status)){const e=this.parseIntData(n);if(null!==e&&e>0)return e}return 0}catch(t){throw new Error(`Error setting parent access inheritance for conceptId ${e}: ${t}`)}}))}static removeParentAccessInheritance(e,t){return Vi(this,void 0,void 0,(function*(){var n;try{const o=yield this.apiClient.removeParentAccessInheritanceByConceptAsync(e,t);return null!==(n=null==o?void 0:o.message)&&void 0!==n?n:"Parent access inheritance removal failed"}catch(t){throw new Error(`Error removing parent access inheritance for conceptId ${e}: ${t}`)}}))}static hasParentAccessInheritance(e,t){return Vi(this,void 0,void 0,(function*(){try{const n=yield this.apiClient.hasParentAccessInheritanceByConceptAsync(e,t);return this.parseBoolData(n)}catch(t){throw new Error(`Error checking parent access inheritance for conceptId ${e}: ${t}`)}}))}static getParentAccessId(e){return Vi(this,void 0,void 0,(function*(){try{const t=yield this.apiClient.getParentAccessIdByConceptAsync(e);return this.parseIntData(t)}catch(t){throw new Error(`Error getting parent access ID for conceptId ${e}: ${t}`)}}))}static setParentAccessInheritanceBulk(e,t){return Vi(this,void 0,void 0,(function*(){try{const n=yield this.apiClient.setParentAccessInheritanceBulkByConceptAsync({parentConceptId:t,childConceptIds:e});return!0===(null==n?void 0:n.status)&&Array.isArray(n.data)?n.data:[]}catch(e){throw new Error(`Error setting bulk parent access inheritance for parentConceptId ${t}: ${e}`)}}))}static removeParentAccessInheritanceBulk(e,t){return Vi(this,void 0,void 0,(function*(){try{const n=yield this.apiClient.removeParentAccessInheritanceBulkByConceptAsync({parentConceptId:null!=t?t:0,childConceptIds:e});return!0===(null==n?void 0:n.status)&&Array.isArray(n.data)?n.data:[]}catch(e){throw new Error(`Error removing bulk parent access inheritance: ${e}`)}}))}static isSuperAdmin(e){return Vi(this,void 0,void 0,(function*(){try{if(0===e)return!1;const t=this.cacheService.getSuperAdmin(e);if(null!==t)return t;const n=yield this.apiClient.checkSuperAdminByConceptAsync(e);if(!0===(null==n?void 0:n.status)&&void 0!==n.data){const t=this.parseBoolData(n);return this.cacheService.setSuperAdmin(e,t),t}return!1}catch(t){throw new Error(`Error checking super admin status for entityId ${e}: ${t}`)}}))}static assignSuperAdmin(e){return Vi(this,void 0,void 0,(function*(){try{const t=yield this.apiClient.assignSuperAdminByConceptAsync({conceptId:e});return!0===(null==t?void 0:t.status)&&void 0!==t.data?(this.cacheService.setSuperAdmin(e,!0),e):0}catch(t){throw new Error(`Failed to assign super admin for entityId ${e}: ${t}`)}}))}static revokeSuperAdmin(e){return Vi(this,void 0,void 0,(function*(){try{const t=yield this.apiClient.revokeSuperAdminByConceptAsync({conceptId:e});return!0===(null==t?void 0:t.status)&&t.message?(this.cacheService.setSuperAdmin(e,!1),t.message):"Super admin access deletion failed"}catch(t){throw new Error(`Failed to revoke super admin for entityId ${e}: ${t}`)}}))}static parseBoolData(e){if(!(null==e?void 0:e.status)||void 0===e.data||null===e.data)return!1;const t=e.data;if("boolean"==typeof t)return t;if("string"==typeof t)return"true"===t.toLowerCase();if("number"==typeof t)return 0!==t;if("object"==typeof t)for(const e of["enabled","Enabled","isEnabled","IsEnabled","status","Status","hasAccess","HasAccess"])if(e in t){const n=t[e];if("boolean"==typeof n)return n;if("string"==typeof n)return"true"===n.toLowerCase()}return!1}static parseIntData(e){if(!(null==e?void 0:e.status)||void 0===e.data||null===e.data)return null;const t=e.data;if("number"==typeof t)return t;if("string"==typeof t){const e=parseInt(t,10);return isNaN(e)?null:e}if("object"==typeof t)for(const e of["id","Id","accessId","AccessId","parentAccessId","ParentAccessId"])if(e in t){const n=t[e];if("number"==typeof n)return n;if("string"==typeof n){const e=parseInt(n,10);if(!isNaN(e))return e}}return null}static permissionSetToString(e){return function(e){const t=[];return e&Di.Read&&t.push("read"),e&Di.Write&&t.push("write"),e&Di.Execute&&t.push("execute"),e&Di.Delete&&t.push("delete"),t}(e)[0]||"read"}static clearCache(){this.cacheService.clear()}static clearSuperAdminCache(){this.cacheService.clearSuperAdminCache()}static updateAccessCache(e,t,n,o){this.cacheService.set(e,t,n,o)}static updateSuperAdminCache(e,t){this.cacheService.setSuperAdmin(e,t)}}Mi.cacheService=new bi,Mi.apiClient=new Oi,Mi.isAccessControlEnabled=!1,Mi.initialize();var Hi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const ji=1,Wi=2,Ji=3,zi=4,qi=5,Ki=6,Qi=7,Yi=8;class Xi{constructor(){this.conceptId=0,this.connectionTypeId=0,this.connectionType="",this.count=0}}var Zi=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function er(e){return Zi(this,void 0,void 0,(function*(){let t={};for(let n=0;n<e.length;n++){let o=yield me(e[n].connectionTypeId);e[n].connectionType=o.characterValue,t[e[n].conceptId]||(t[e[n].conceptId]=[]),t[e[n].conceptId].push(e[n])}return t}))}function tr(e){const t=e.split("_");if(3===t.length){let e=new Xi;return e.conceptId=Number(t[0]),e.connectionTypeId=Number(t[1]),e.count=Number(t[2]),e}throw new Error("Input string must contain exactly three parts separated by underscores.")}function nr(e){return e.startsWith("the_")?e.slice(4):e}var or=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function ir(e,t,n){if(e in t){const o=Array.isArray(t[e])?t[e]:[t[e]];for(const e of o)e&&(n[e.connectionType+"_count"]=e.count)}}var rr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))},cr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function sr(e,t,n){return cr(this,void 0,void 0,(function*(){var o,i,r,c,s,a,l,d;let u=[];for(let t=0;t<e.length;t++)u.push(e[t].toTheConceptId),u.push(e[t].ofTheConceptId),u.push(e[t].typeId);for(let u=0;u<e.length;u++){let h=!1;n.includes(e[u].id)&&(h=!0);let f=yield Ht(e[u].ofTheConceptId),y=yield Ht(e[u].toTheConceptId);if(1==h){if(0!=f.id&&0!=y.id){let n,s=null!==(i=null===(o=y.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self";e[u].toTheConceptId in t?n=t[e[u].toTheConceptId]:(n={},n[s]={},t[e[u].toTheConceptId]=n);let a=yield Ht(e[u].typeId);try{let e=null!==(c=null===(r=null==f?void 0:f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",n=f.characterValue;a.characterValue,a.characterValue.includes("_s_")&&(f.id in t||(t[f.id]={}),t[f.id][e]=n),t[y.id]={}}catch(e){}}}else if(0!=f.id&&0!=y.id){let n,o=null!==(a=null===(s=f.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[u].ofTheConceptId in t?n=t[e[u].ofTheConceptId]:(n={},n[o]={},t[e[u].ofTheConceptId]=n);let i=yield Ht(e[u].typeId);try{let e=null!==(d=null===(l=null==y?void 0:y.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"none",n=y.characterValue;i.characterValue.includes("_s_")&&(y.id in t||(t[y.id]={}),t[y.id][e]=n),t[f.id]={}}catch(e){}}}return t}))}var ar=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function lr(e,t="DESC"){return"ASC"==t?e.sort((function(e,t){return e.id-t.id})):e.sort((function(e,t){return t.id-e.id})),e}var dr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};var ur=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function hr(e,t){return ur(this,void 0,void 0,(function*(){let o=e.outputFormat;e.outputFormat=Ki;let i,r=yield function(e){return Hi(this,arguments,void 0,(function*(e,t=""){var o=yield q("application/json",t);const i=n.FreeschemaQueryUrl(),r=JSON.stringify(e);try{const e=yield h(i,{method:"POST",headers:o,body:r});if(e.ok)return yield e.json();Q(e)}catch(e){!function(e,t=""){if(e.status){let n=new K(e.message,!1,e.status,e.stack);throw n.setUrl(t),n}{let n=new K(e.message,!1,500,e.stack);throw n.setUrl(t),n}}(e,i)}}))}(e,t),c=r.conceptIds,s=(r.internalConnections,r.linkers),a=r.reverse,l=r.mainCompositionIds,d=r.countinfo,u=e.order,f=function(e=[]){let t=[];if(e.length>0)for(let n=0;n<(null==e?void 0:e.length);n++){let o=tr(e[n]);t.push(o)}return t}(d);return i=o==Wi?yield function(e,t,n,o,i){return dr(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield Jn(e),s=yield er(i);c=lr(c,r);let a=[];a=yield function(e,t){return rr(this,arguments,void 0,(function*(e,t,n=[]){var o,i,r,c,s,a,l,d;let u=[];for(let t=0;t<e.length;t++)u.push(e[t].toTheConceptId),u.push(e[t].ofTheConceptId),u.push(e[t].typeId);for(let u=0;u<e.length;u++){let h=!1,f=yield Ht(e[u].ofTheConceptId),y=yield Ht(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Ht(e[u].typeId),a=null!==(i=null===(o=y.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self";e[u].toTheConceptId in t?n=t[e[u].toTheConceptId]:(n={},n[a]={},t[e[u].toTheConceptId]=n);try{let e=null!==(c=null===(r=null==f?void 0:f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",n=f.characterValue;(s.characterValue+"_reverse").includes("_s_")&&(f.id in t||(t[f.id]={}),t[f.id][e]=n),t[y.id]={}}catch(e){}}}else if(0!=f.id&&0!=y.id){let n,o=yield Ht(e[u].typeId),i=null!==(a=null===(s=f.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[u].ofTheConceptId in t?n=t[e[u].ofTheConceptId]:(n={},n[i]={},t[e[u].ofTheConceptId]=n);try{let e=null!==(d=null===(l=null==y?void 0:y.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"none",n=y.characterValue;o.characterValue.includes("_s_")&&(y.id in t||(t[y.id]={}),t[y.id][e]=n),t[f.id]={}}catch(e){}}}return t}))}(c,a,o),a=yield function(e,t){return rr(this,arguments,void 0,(function*(e,t,n=[]){var o,i,r,c,s,a,l,d;let u=[];for(let t=0;t<e.length;t++)u.push(e[t].toTheConceptId),u.push(e[t].ofTheConceptId),u.push(e[t].typeId);for(let u=0;u<e.length;u++){let h=!1,f=yield Ht(e[u].ofTheConceptId),y=yield Ht(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Ht(e[u].typeId),a=null!==(i=null===(o=y.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self";e[u].toTheConceptId in t?(n=t[e[u].toTheConceptId],a in n||(n[a]={})):(n={},n[a]={},t[e[u].toTheConceptId]=n);try{let e=null!==(c=null===(r=null==f?void 0:f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",t=f.characterValue,o=s.characterValue;""==o&&(o=e,o=nr(o));let i={id:f.id,data:{[e]:t}},l=o+"_reverse";l.includes("_s_")||("string"==typeof n[a]&&(n[a]={}),n[a][l]=i)}catch(e){}}}else if(0!=f.id&&0!=y.id){let n,o=yield Ht(e[u].typeId),i=null!==(a=null===(s=f.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[u].ofTheConceptId in t?(n=t[e[u].ofTheConceptId],i in n||(n[i]={})):(n={},n[i]={},t[e[u].ofTheConceptId]=n);try{let e=null!==(d=null===(l=null==y?void 0:y.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"none",t=y.characterValue,r=o.characterValue,c=!1;""==r&&(r=e,r=nr(r),c=!0);let s={id:y.id,data:{[e]:t}};isNaN(Number(r))?r.includes("_s_")||("string"==typeof n[i]&&(n[i]={}),n[i][r]=s):(Array.isArray(n[i])||(n[i]=[]),n[i].push(s))}catch(e){}}}return t}))}(c,a,o);let l=yield function(e,t,n,o){return rr(this,arguments,void 0,(function*(e,t,n,o,i=[],r){var c,s,a,l,d,u,h;(new Date).getTime();let f=[],y=[];for(let t=0;t<e.length;t++)y.push(e[t].toTheConceptId),y.push(e[t].ofTheConceptId),y.push(e[t].typeId);for(let n=0;n<e.length;n++){let o=!1,f=yield Ht(e[n].ofTheConceptId),y=yield Ht(e[n].toTheConceptId);if(i.includes(e[n].id)&&(o=!0),1==o){if(0!=f.id&&0!=y.id&&y.id in t){let o,i=yield Ht(e[n].typeId),a=null!==(s=null===(c=y.type)||void 0===c?void 0:c.characterValue)&&void 0!==s?s:"self",l=!1;e[n].toTheConceptId in t&&(l=!0),e[n].toTheConceptId in t?(o=t[e[n].toTheConceptId],"string"==typeof o[a]&&(o[a]={})):(o={},o[a]={},t[e[n].toTheConceptId]=o),ir(y.id,r,o);try{if(t[e[n].ofTheConceptId]){let r={id:f.id,data:t[e[n].ofTheConceptId],created_on:e[n].entryTimeStamp},c=i.characterValue+"_reverse";Array.isArray(o[a][c])?o[a][c].push(r):c.includes("_s_")?(o[a][c]=[],o[a][c].push(r)):o[a][c]=r}}catch(e){}}}else if(0!=f.id&&0!=y.id&&f.id in t){let o,i=yield Ht(e[n].typeId),c=null!==(l=null===(a=f.type)||void 0===a?void 0:a.characterValue)&&void 0!==l?l:"self",s=!1;e[n].toTheConceptId in t&&(s=!0),e[n].ofTheConceptId in t?(o=t[e[n].ofTheConceptId],"string"==typeof o[c]&&(o[c]={})):(o={},o[c]={},t[e[n].ofTheConceptId]=o),ir(f.id,r,o);let p=!0,v=i.characterValue;""==v&&(v=y.characterValue,p=!0),""==v&&(v=null!==(u=null===(d=null==y?void 0:y.type)||void 0===d?void 0:d.characterValue)&&void 0!==u?u:"");try{null===(h=null==y?void 0:y.type)||void 0===h||h.characterValue;let s=t[e[n].toTheConceptId];if(s){let a={id:y.id,data:t[e[n].toTheConceptId],created_on:e[n].entryTimeStamp};Array.isArray(o[c])?o[c].push(s):Array.isArray(o[c][v])?o[c][i.characterValue].push(a):v.includes("_s_")?(o[c][v]=[],o[c][v].push(a)):o[c][v]=a,ir(y.id,r,a)}}catch(e){}}}for(let e=0;e<o.length;e++){let n={};n.id=o[e];let i=yield Ht(n.id);n.data=t[o[e]],n.created_on=i.entryTimeStamp,f.push(n)}return f}))}(c,a,[],n,o,s);return l}))}(s,c,l,a,f,u):o==Ji?yield function(e,t,n,o,i){return dr(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield Jn(e),s=yield er(i);c=lr(c,r);let a=[];a=yield sr(c,a,o),a=yield function(e,t){return or(this,arguments,void 0,(function*(e,t,n=[]){var o,i,r,c,s,a,l,d;let u=[];for(let t=0;t<e.length;t++)u.push(e[t].toTheConceptId),u.push(e[t].ofTheConceptId),u.push(e[t].typeId);for(let u=0;u<e.length;u++){let h=!1,f=yield Ht(e[u].ofTheConceptId),y=yield Ht(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Ht(e[u].typeId),a=null!==(i=null===(o=y.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self";e[u].toTheConceptId in t?(n=t[e[u].toTheConceptId],a in n||(n[a]={})):(n={},n[a]={},t[e[u].toTheConceptId]=n);try{let e=null!==(c=null===(r=null==f?void 0:f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",t=f.characterValue,o=s.characterValue;""==o&&(o=e,o=nr(o));let i={id:f.id,[e]:t},l=o+"_reverse";l.includes("_s_")||("string"==typeof n[a]&&(n[a]={}),n[a][l]=i)}catch(e){}}}else if(0!=f.id&&0!=y.id){let n,o=yield Ht(e[u].typeId),i=null!==(a=null===(s=f.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[u].ofTheConceptId in t?(n=t[e[u].ofTheConceptId],i in n||(n[i]={})):(n={},n[i]={},t[e[u].ofTheConceptId]=n);try{let t=null!==(d=null===(l=null==y?void 0:y.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"none",r=y.characterValue,c=o.characterValue,s=!1;""==c&&(c=t,c=nr(c),s=!0);let a={};a[t]={id:y.id,data:r,created_on:e[u].entryTimeStamp},isNaN(Number(c))?c.includes("_s_")||("string"==typeof n[i]&&(n[i]={}),n[i][c]=s?a[t]:a):(Array.isArray(n[i])||(n[i]=[]),n[i].push(a[t]))}catch(e){}}}return t}))}(c,a,o);let l=yield function(e,t,n){return or(this,arguments,void 0,(function*(e,t,n,o=[],i){var r,c,s,a,l,d,u,h;(new Date).getTime();let f=[],y=[];for(let t=0;t<e.length;t++)y.push(e[t].toTheConceptId),y.push(e[t].ofTheConceptId),y.push(e[t].typeId);for(let n=0;n<e.length;n++){let f=!1,y=yield Ht(e[n].ofTheConceptId),p=yield Ht(e[n].toTheConceptId);if(o.includes(e[n].id)&&(f=!0),1==f){if(0!=y.id&&0!=p.id&&p.id in t){let o,i=yield Ht(e[n].typeId),s=null!==(c=null===(r=p.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"self",a=!1;e[n].toTheConceptId in t&&(a=!0),e[n].toTheConceptId in t?(o=t[e[n].toTheConceptId],"string"==typeof o[s]&&(o[s]={})):(o={},o[s]={},t[e[n].toTheConceptId]=o);try{if(t[e[n].ofTheConceptId]){let r=t[e[n].ofTheConceptId];r&&(r.id=y.id,r.created_on=y.entryTimeStamp);let c=i.characterValue+"_reverse";Array.isArray(o[s][c])?o[s][c].push(r):c.includes("_s_")?(o[s][c]=[],o[s][c].push(r)):o[s][c]=r}}catch(e){}}}else if(0!=y.id&&0!=p.id&&y.id in t){let o,r=yield Ht(e[n].typeId),c=null!==(a=null===(s=y.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self",f=!1;e[n].toTheConceptId in t&&(f=!0),e[n].ofTheConceptId in t?(o=t[e[n].ofTheConceptId],"string"==typeof o[c]&&(o[c]={})):(o={},o[c]={},t[e[n].ofTheConceptId]=o),ir(y.id,i,o);let v=!1,g=r.characterValue;""==g&&(g=p.characterValue,v=!0),""==g&&(g=null!==(d=null===(l=null==p?void 0:p.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"");try{let r=null!==(h=null===(u=null==p?void 0:p.type)||void 0===u?void 0:u.characterValue)&&void 0!==h?h:"none",s=t[e[n].toTheConceptId];if(s){let t={};t[r]={data:s[r],id:p.id,created_on:e[n].entryTimeStamp},Array.isArray(o[c])?v?o[c].push(s[g]):o[c].push(s):Array.isArray(o[c][g])?o[c][g].push(t):g.includes("_s_")?(o[c][g]=[],v?o[c][g].push(t[r]):o[c][g].push(t)):o[c][g]=v?t[r]:t,ir(p.id,i,t)}}catch(e){}}}for(let e=0;e<n.length;e++){let o={};o=t[n[e]],o&&(o.id=n[e]),f.push(o)}return f}))}(c,a,n,o,s);return l}))}(s,c,l,a,f,u):o==Yi?yield function(e,t,n,o,i){return dr(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield Jn(e),s=yield er(i);c=lr(c,r);let a={};a=yield function(e){return ar(this,arguments,void 0,(function*(e,t={},n=[]){var o,i,r,c,s;for(const a of e){const e=n.includes(a.id),l=yield Ht(a.ofTheConceptId),d=yield Ht(a.toTheConceptId),u=yield Ht(a.typeId);if(0===l.id||0===d.id)continue;const h=e?d:l,f=e?l:d,y=null!==(i=null===(o=h.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self",p=null!==(c=null===(r=f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",v=f.characterValue,g=null===(s=u.characterValue)||void 0===s?void 0:s.includes("_s_");t[h.id]||(t[h.id]={}),t[h.id][y]||(t[h.id][y]={}),g&&(t[f.id]||(t[f.id]={}),t[f.id][p]=v)}return t}))}(c,a,o),a=yield function(e){return ar(this,arguments,void 0,(function*(e,t={},n=[]){var o,i,r,c,s;for(const a of e){const e=n.includes(a.id),l=yield Ht(a.ofTheConceptId),d=yield Ht(a.toTheConceptId),u=yield Ht(a.typeId);if(0===l.id||0===d.id)continue;const h=e?d:l,f=e?l:d,y=null!==(i=null===(o=h.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self",p=null!==(c=null===(r=f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",v=f.characterValue,g=null!==(s=u.characterValue)&&void 0!==s?s:"";let C=""===g?nr(p):g;const m=C.includes("_s_"),T=!isNaN(Number(C)),w={id:f.id,data:{[p]:v}};t[h.id]||(t[h.id]={}),y in t[h.id]&&"string"!=typeof t[h.id][y]||(t[h.id][y]=T?[]:{});try{if(m)continue;T?t[h.id][y].push(w):t[h.id][y][e?`${C}_reverse`:C]=w}catch(e){console.error("Error formatting concept data:",e)}}return t}))}(c,a,o);let l=yield function(e,t,n){return ar(this,arguments,void 0,(function*(e,t,n,o=[],i){var r,c,s;const a=[];for(const n of e){const e=o.includes(n.id),a=yield Ht(n.ofTheConceptId),l=yield Ht(n.toTheConceptId),d=yield Ht(n.typeId);if(0===a.id||0===l.id)continue;const u=e?l:a,h=e?a:l,f=u.id,y=h.id,p=null!==(c=null===(r=u.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"self",v=d.characterValue+"_reverse",g=d.characterValue||h.characterValue||(null===(s=h.type)||void 0===s?void 0:s.characterValue)||"";if(t[f]){const o=t[f][p],r=t[y],c={id:h.id,data:r,created_on:n.entryTimeStamp};ir(f,i,t[f]);try{e?Array.isArray(o[v])?o[v].push(c):o[v]=[c]:Array.isArray(o)?o.push(r):Array.isArray(o[g])?o[g].push(c):g.includes("_s_")?(o[g]=[],o[g].push(c)):o[g]=[c],ir(y,i,c)}catch(e){console.error("Error processing connection:",e)}}}for(const e of n){const n=yield Ht(e);a.push({id:e,data:t[e],created_on:n.entryTimeStamp})}return a}))}(c,a,n,o,s);return l}))}(s,c,l,a,f,u):yield function(e,t,n,o){return dr(this,void 0,void 0,(function*(){let t=yield Jn(e);t=lr(t);let i=[];i=yield sr(t,i,o),i=yield function(e,t,n){return cr(this,void 0,void 0,(function*(){var o,i,r,c,s,a,l,d;let u=[];for(let t=0;t<e.length;t++)u.push(e[t].toTheConceptId),u.push(e[t].ofTheConceptId),u.push(e[t].typeId);e.sort((function(e,t){return t.id-e.id}));for(let u=0;u<e.length;u++){let h=!1;n.includes(e[u].id)&&(h=!0);let f=yield Ht(e[u].ofTheConceptId),y=yield Ht(e[u].toTheConceptId);if(1==h){if(0!=f.id&&0!=y.id){let n,s=null!==(i=null===(o=y.type)||void 0===o?void 0:o.characterValue)&&void 0!==i?i:"self";e[u].toTheConceptId in t?(n=t[e[u].toTheConceptId],s in n||(n[s]={})):(n={},n[s]={},t[e[u].toTheConceptId]=n);let a=yield Ht(e[u].typeId);try{let e=null!==(c=null===(r=null==f?void 0:f.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"none",t=f.characterValue,o=a.characterValue;""==o&&(o=e,o=nr(o));let i={[e]:t},l=o+"_reverse";a.characterValue.includes("_s_")||("string"==typeof n[s]&&(n[s]={}),n[s][l]=i)}catch(e){}}}else if(0!=f.id&&0!=y.id){let n,o=null!==(a=null===(s=f.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[u].ofTheConceptId in t?(n=t[e[u].ofTheConceptId],o in n||(n[o]={})):(n={},n[o]={},t[e[u].ofTheConceptId]=n);let i=yield Ht(e[u].typeId);try{let e=null!==(d=null===(l=null==y?void 0:y.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"none",t=y.characterValue,r=i.characterValue,c=(i.characterValue,!1);""==r&&(r=e,r=nr(r),c=!0);let s={[e]:t};isNaN(Number(r))?i.characterValue.includes("_s_")||("string"==typeof n[o]&&(n[o]={}),n[o][r]=c?t:s):(Array.isArray(n[o])||(n[o]=[]),n[o].push(t))}catch(e){}}}return t}))}(t,i,o);let r=yield function(){return cr(this,arguments,void 0,(function*(e=[],t=[],n=[],o,i=[]){var r,c,s,a,l,d;let u=[],h=[];for(let t=0;t<e.length;t++)h.push(e[t].toTheConceptId),h.push(e[t].ofTheConceptId),h.push(e[t].typeId);e.sort((function(e,t){return t.id-e.id}));for(let n=0;n<e.length;n++){let o=!1;i.includes(e[n].id)&&(o=!0);let u=yield Ht(e[n].ofTheConceptId),h=yield Ht(e[n].toTheConceptId);if(1==o){if(0!=u.id&&0!=h.id&&h.id in t){let o,i=null!==(c=null===(r=h.type)||void 0===r?void 0:r.characterValue)&&void 0!==c?c:"self";e[n].toTheConceptId in t?o=t[e[n].toTheConceptId]:(o={},o[i]={},t[e[n].toTheConceptId]=o);let s=yield Ht(e[n].typeId);try{let r=s.characterValue+"_reverse",c=t[e[n].ofTheConceptId];c&&(Array.isArray(o[i][r])?o[i][r].push(c):s.characterValue.includes("_s_")?(o[i][r]=[],o[i][r].push(c)):o[i][r]=c)}catch(e){}}}else if(0!=u.id&&0!=h.id&&u.id in t){let o,i=null!==(a=null===(s=u.type)||void 0===s?void 0:s.characterValue)&&void 0!==a?a:"self";e[n].ofTheConceptId in t?(o=t[e[n].ofTheConceptId],"string"==typeof o[i]&&(o[i]={})):(o={},o[i]={},t[e[n].ofTheConceptId]=o);let r=!1,c=(yield Ht(e[n].typeId)).characterValue;""==c&&(c=h.characterValue,r=!0),""==c&&(c=null!==(d=null===(l=null==h?void 0:h.type)||void 0===l?void 0:l.characterValue)&&void 0!==d?d:"");try{let s=t[e[n].toTheConceptId];s&&(Array.isArray(o[i])?r?o[i].push(s[c]):o[i].push(s):Array.isArray(o[i][c])?o[i][c].push(s):c.includes("_s_")?(o[i][c]=[],r?o[i][c].push(s[c]):o[i][c].push(s)):o[i][c]=r?s[c]:s)}catch(e){}}}for(let e=0;e<n.length;e++){let o=t[n[e]];o&&(o.id=n[e],u.push(o))}return u}))}(t,i,n,[],o);return r}))}(s,0,l,a),i}))}class fr{constructor(){this.type="",this.inpage=10,this.page=1,this.concepts=[],this.conceptIds=[],this.selectors=[],this.freeschemaQueries=[],this.filters=[],this.filterLogic="",this.typeConnection="",this.order="DESC",this.outputFormat=ji,this.name="",this.reverse=!1,this.limit=!1,this.filterAncestor="",this.includeInFilter=!1,this.isOldConnectionType=!1,this.usePipelineQuery=!1}}var yr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function pr(e,t){return yr(this,arguments,void 0,(function*(e,t,n=!1){let o=[];if(n){let n=yield xn(e),i=yield Ke(t);for(let e=0;e<n.length;e++)n[e].typeId==i.id&&o.push(n[e])}else{let n=yield kn(e);for(let e=0;e<n.length;e++)se.AddConnection(n[e]);let i=yield Ke(t);for(let e=0;e<n.length;e++)n[e].typeId==i.id&&o.push(n[e])}return o}))}function vr(e,t,n){return yr(this,arguments,void 0,(function*(e,t,n,o=!1){let i=[],r=[];if(i=o?yield pr(t,n,o):yield pr(e,n,o),o)for(let t=0;t<i.length;t++)i[t].ofTheConceptId==e&&r.push(i[t]);else for(let e=0;e<i.length;e++)i[e].toTheConceptId==t&&r.push(i[e]);return r}))}var gr=function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function c(e){try{a(o.next(e))}catch(e){r(e)}}function s(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};function Cr(e=""){o.BearerAccessToken=e}function mr(){return gr(this,arguments,void 0,(function*(e="",t="",i="CCSApp",c){var s,a;const l=c||new gi;Mi.setBaseUrl(l.accessControlBaseUrl),Mi.setEnabled(l.enableAccessControl),n.BASE_URL=e,n.AI_URL=l.aiUrl,t&&(n.NODE_URL=t);const d=l.cacheServers.length>0?l.cacheServers:vi(null!==(a=null===(s=l.parameters)||void 0===s?void 0:s.cacheServers)&&void 0!==a?a:l.getParameter("cacheServers",""));n.setCacheServers(d);const u=l.cacheServerUrl||l.getParameter("cacheServerUrl","");if(u?n.setNodeCacheUrl(u):0===d.length&&n.setNodeCacheUrl(""),l.hasOAuthCredentials()){const e=l.applicationName||i;o.setOAuthCredentials(l.clientId,l.clientSecret,e);const t=yield r(l.clientId,l.clientSecret,e,!0);if(!t.success)throw new Error(`OAuth token request failed: ${t.error||"unknown error"}`)}else l.hasAccessToken()&&(o.BearerAccessToken=l.accessToken);E.isDataLoaded=!1,E.isCharacterLoaded=!1,E.isTypeLoaded=!1,E.isLocalDataLoaded=!1,E.isLocalTypeLoaded=!1,E.isLocalCharacterLoaded=!1,E.isConnectionLoaded=!1,E.isConnectionTypeLoaded=!1,E.isLocalConnectionLoaded=!1,yield function(){return Fi(this,void 0,void 0,(function*(){return yield A("settings")[0]||new w(!0),yield function(){return Pi(this,void 0,void 0,(function*(){}))}(),!0}))}(),yield Promise.all([j().then((()=>{E.isDataLoaded=!0,E.isCharacterLoaded=!0,E.isTypeLoaded=!0})),Li().then((()=>{E.isLocalDataLoaded=!0,E.isLocalTypeLoaded=!0,E.isLocalCharacterLoaded=!0})),Ii().then((()=>{E.isLocalConnectionLoaded=!0})),wi().then((()=>{E.isConnectionLoaded=!0,E.isConnectionTypeLoaded=!0}))])}))}module.exports=t})();
|