mftsccs-node 0.2.21 → 0.2.23

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/README.md CHANGED
@@ -125,12 +125,22 @@ Initialize the CCS system before performing any operations:
125
125
 
126
126
  ```typescript
127
127
  import { init, updateAccessToken } from 'mftsccs-node';
128
+ import { CCSConfig } from 'mftsccs-node';
129
+
130
+ // Access control is disabled by default (all access allowed).
131
+ // Enable it explicitly via CCSConfig when needed.
132
+ const config = new CCSConfig({
133
+ accessToken: 'your-bearer-access-token',
134
+ enableAccessControl: true,
135
+ accessControlBaseUrl: 'https://access.example.com/api/access-control'
136
+ });
128
137
 
129
- // Initialize with backend URLs and auth token
138
+ // Initialize with backend URLs and config
130
139
  init(
131
140
  'https://api.freeschema.com', // Base API URL
132
- 'https://ai.freeschema.com', // AI service URL
133
- 'your-bearer-access-token' // Authentication token
141
+ '', // Optional Node URL
142
+ 'MyApp', // Application name
143
+ config
134
144
  );
135
145
 
136
146
  // Update token later if needed
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:()=>Pi,AccessControlService:()=>or,AddGhostConcept:()=>Ko,AddGhostConnection:()=>qo,BaseUrl:()=>n,BinaryTree:()=>_,CCSConfig:()=>mi,Composition:()=>mo,CompositionBinaryTree:()=>po,CompositionNode:()=>fo,Concept:()=>R,ConceptsData:()=>G,Connection:()=>J,ConnectionData:()=>Z,CreateComposition:()=>Rt,CreateConnection:()=>Wt,CreateConnectionBetweenTwoConcepts:()=>tn,CreateConnectionBetweenTwoConceptsGeneral:()=>on,CreateDefaultConcept:()=>E,CreateDefaultLConcept:()=>$e,CreateSession:()=>Uo,CreateSessionVisit:()=>Fo,CreateTheCompositionLocal:()=>bt,CreateTheCompositionWithCache:()=>No,CreateTheConnection:()=>rt,CreateTheConnectionGeneral:()=>Ht,CreateTheConnectionLocal:()=>Pt,DATAID:()=>Si,DATAIDDATE:()=>Ri,DATAV2:()=>Bi,DeleteConceptById:()=>Dn,DeleteConnectionById:()=>Yt,DeleteConnectionByTypeBulk:()=>fi,FilterSearch:()=>gi,FormatFromConnections:()=>ei,FreeSchemaResponse:()=>$,FreeschemaQuery:()=>qi,GetAllConnectionsOfComposition:()=>fe,GetAllConnectionsOfCompositionBulk:()=>ae,GetAllTheConnectionsByTypeAndOfTheConcept:()=>Yi,GetComposition:()=>ve,GetCompositionBulk:()=>Jn,GetCompositionBulkWithDataId:()=>zn,GetCompositionFromConnectionsWithDataId:()=>Kn,GetCompositionFromConnectionsWithDataIdInObject:()=>Qn,GetCompositionList:()=>Pe,GetCompositionListLocal:()=>Ze,GetCompositionListLocalWithId:()=>et,GetCompositionListWithId:()=>Le,GetCompositionLocal:()=>ze,GetCompositionLocalWithId:()=>Ke,GetCompositionWithAllIds:()=>ge,GetCompositionWithCache:()=>Ro,GetCompositionWithDataIdBulk:()=>Lo,GetCompositionWithDataIdWithCache:()=>Po,GetCompositionWithId:()=>Ie,GetCompositionWithIdFromMemory:()=>me,GetCompositionWithIdFromMemoryFromConnections:()=>Ne,GetConceptBulk:()=>te,GetConceptByCharacter:()=>Re,GetConceptByCharacterAndCategoryDirectApi:()=>Nn,GetConceptByCharacterAndType:()=>lt,GetConceptByTypeBulk:()=>dt,GetConnectionBulk:()=>Hn,GetConnectionById:()=>qt,GetConnectionByTypeBulk:()=>yi,GetConnectionOfTheConcept:()=>Mt,GetLink:()=>cn,GetLinkRaw:()=>sn,GetLinkerConnectionFromConcepts:()=>Ln,GetLinkerConnectionToConcepts:()=>Bn,GetRelation:()=>bo,GetRelationRaw:()=>$o,GetRequestHeader:()=>O,GetRequestHeaderWithAuthorization:()=>b,GetTheConcept:()=>Zt,GetUserGhostConnectionId:()=>zo,GetUserGhostId:()=>Jo,GiveConnection:()=>Xi,HandleHttpError:()=>M,HttpResponse:()=>l,JUSTDATA:()=>_i,LConcept:()=>be,LConnection:()=>Et,LISTNORMAL:()=>Li,LoginToBackend:()=>eo,MakeTheInstanceConcept:()=>St,MakeTheInstanceConceptLocal:()=>Vt,MakeTheTimestamp:()=>$n,MakeTheTypeConcept:()=>Cn,MakeTheTypeConceptApi:()=>xn,NORMAL:()=>xi,PatcherStructure:()=>pi,PermissionSet:()=>er,RAW:()=>Ei,RecursiveSearchApi:()=>Xn,SchemaQueryListener:()=>Ki,SearchAllConcepts:()=>ko,SearchLinkInternal:()=>ui,SearchLinkMultipleAll:()=>Zo,SearchLinkMultipleApi:()=>Yo,SearchQuery:()=>Mn,SearchStructure:()=>Ci,SearchWithLinker:()=>So,SessionData:()=>vi,Signin:()=>io,Signup:()=>no,SplitStrings:()=>D,SyncData:()=>it,TokenRefreshError:()=>a,TokenStorage:()=>o,Transaction:()=>rr,TrashTheConcept:()=>On,UpdateComposition:()=>Io,UpdateCompositionLocal:()=>ri,UserBinaryTree:()=>Ho,ViewInternalData:()=>ai,convertFromLConceptToConcept:()=>ni,deleteWithRetry:()=>p,getFromDatabaseWithType:()=>T,getFromDatabaseWithTypeOld:()=>N,getOAuthToken:()=>r,getWithRetry:()=>f,init:()=>sr,patchWithRetry:()=>v,postWithRetry:()=>h,putWithRetry:()=>y,recursiveFetch:()=>Ae,recursiveFetchNew:()=>go,refreshOAuthToken:()=>c,requestWithRetry:()=>u,storeToDatabase:()=>m,updateAccessToken:()=>cr});class n{static GetConceptUrl(){return this.BASE_URL+"/api/getConcept"}static GetConnectionUrl(){return this.BASE_URL+"/api/get-connection-by-id"}static GetConceptBulkUrl(){return this.BASE_URL+"/api/get_concept_bulk"}static GetConnectionBulkUrl(){return this.BASE_URL+"/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 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 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.AI_URL="https://ai.freeschema.com",n.MQTT_URL="192.168.1.249",n.NODE_URL="http://localhost:5001/";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());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(console.log("Received 401 Unauthorized, attempting token refresh..."),yield d()){console.log("Token refreshed successfully, retrying request..."),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)throw e;console.error(`Request failed (attempt ${n+1}/${r+1}):`,e)}throw new Error("Request failed after all retry attempts")}))}function h(e,t,n){return s(this,void 0,void 0,(function*(){return u("POST",e,t,n)}))}function f(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 y(e,t,n){return s(this,void 0,void 0,(function*(){return u("PUT",e,t,n)}))}function p(e,t){return s(this,void 0,void 0,(function*(){return u("DELETE",e,t)}))}function v(e,t,n){return s(this,void 0,void 0,(function*(){return u("PATCH",e,t,n)}))}class g{constructor(e){this.id=1,this.isOnlineSync=!1,this.isOnlineSync=e}}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){}function T(e,t,n){return C(this,void 0,void 0,(function*(){}))}function N(e){return C(this,void 0,void 0,(function*(){}))}function w(e){return C(this,void 0,void 0,(function*(){}))}class I{}I.isTypeLoaded=!1,I.isCharacterLoaded=!1,I.isDataLoaded=!1,I.isLocalDataLoaded=!1,I.isLocalCharacterLoaded=!1,I.isLocalTypeLoaded=!1,I.isConnectionLoaded=!1,I.isConnectionTypeLoaded=!1,I.isLocalConnectionLoaded=!1;class A{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(e.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 k=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 x{static waitForDataToLoad(){return k(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(I.isCharacterLoaded)return e("done");setTimeout(x.checkFlag,1e3,e)}static addNodeToTree(e){return k(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 k(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 A(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 k(this,void 0,void 0,(function*(){return this.characterRoot?this.characterRoot.getFromNodeWithCharacterAndType(e,t,this.characterRoot):this.characterRoot}))}static getCharacterAndCategoryFromTree(e,t){return k(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))}}x.characterRoot=null;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 _{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 S(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(I.isDataLoaded)return e("done");setTimeout(_.checkFlag,1e3,e)}static addConceptToTree(e){var t=new A(e.id,e,null,null),n=new A(e.characterValue,e,null,null);x.addNodeToTree(n),this.addNodeToTree(t)}static getNodeFromTree(e){return S(this,void 0,void 0,(function*(){return this.root?this.root.getFromNode(e,this.root):null}))}static removeNodeFromTree(e){return S(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}}_.root=null;class R{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 E(){let e=P(new Date),t=P(new Date);return new R(0,0,0,0,0,0,0,0,"0",0,0,0,0,0,0,!1,e,t)}function P(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 L=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 B{static addNodeToTree(e){return L(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 A(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 L(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(I.isTypeLoaded)return e("done");setTimeout(B.checkFlag,1e3,e)}static getTypeVariantsFromTreeWithUserId(e,t){return L(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 L(this,void 0,void 0,(function*(){let n=E();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}}B.typeRoot=null;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 G{constructor(){this.name="conceptsArray"}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){this.NPC.includes(e)||(this.NPC.length>10&&(this.NPC=[]),this.NPC.push(e))}static GetNpc(e){return!!this.NPC.includes(e)}static AddConceptToStorage(e){e.id}static AddConcept(e){e.id>0&&(_.addConceptToTree(e),B.addConceptToTree(e),x.addConceptToTree(e))}static AddConceptToMemory(e){e.id>0&&(_.addConceptToTree(e),B.addConceptToTree(e),x.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);_.removeNodeFromTree(e.id),e.id}static GetConcept(e){return U(this,void 0,void 0,(function*(){var t=E(),n=yield _.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConceptByCharacter(e){return U(this,void 0,void 0,(function*(){var t=E(),n=x.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterUpdated(e){return U(this,void 0,void 0,(function*(){var t=E(),n=x.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterAndTypeLocal(e,t){return U(this,void 0,void 0,(function*(){return E(),yield B.getTypeVariantsWithCharacterValue(e,t)}))}static GetConceptByCharacterAndCategoryLocal(e,t){return U(this,void 0,void 0,(function*(){var n=E(),o=yield x.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 U(this,void 0,void 0,(function*(){let n=[];return n=yield B.getTypeVariantsFromTreeWithUserId(e,t),n}))}static GetBinaryCharacterTree(){return x.characterRoot}getName(){return this.name}}G.conceptsArray=[],G.NPC=[],G.conceptDictionary=[];var F=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 D(e){const t=e.lastIndexOf("_");let n=[];return n=t>0?[e.substring(0,t),e.substring(t+1,e.length)]:[e],n}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())}))};function O(){return V(this,arguments,void 0,(function*(e="application/json",t="application/json"){if(o.isTokenExpiredOrNearExpiry()&&o.hasOAuthCredentials()){console.log("Token expired or near expiry, refreshing...");const e=yield r(o.CLIENT_ID,o.CLIENT_SECRET,o.APPLICATION_NAME,!0);e.success?console.log("Token refreshed successfully"):console.error("Failed to refresh token:",e.error)}return{"Content-Type":e,Authorization:"Bearer "+o.BearerAccessToken,Accept:t}}))}function b(){return V(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()){console.log("Token expired or near expiry, refreshing...");const e=yield r(o.CLIENT_ID,o.CLIENT_SECRET,o.APPLICATION_NAME,!0);e.success?console.log("Token refreshed successfully"):console.error("Failed to refresh token:",e.error)}return{"Content-Type":e,Authorization:"Bearer "+o.BearerAccessToken,Accept:n}}))}class ${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 M(e){if(e.status>=400){let t=new $(e.statusText,!1,e.status,"");throw t.setUrl(e.url),t}}function j(e){if(401==e.status){let t=new $(e.body,!1,e.status,"");throw t.setUrl(e.headers.url),t}}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 W(e,t){return H(this,void 0,void 0,(function*(){try{var o=new URLSearchParams;o.append("type",e),o.append("user_id",t.toString());var i=yield O("application/x-www-form-urlencoded");const c=yield fetch(n.GetAllConceptsByTypeUrl(),{method:"POST",headers:i,body:o});if(c.ok){const e=yield c.json();for(var r=0;r<e.length;r++)G.AddConcept(e[r])}console.log("GetAllConceptsByType error",c.status),M(c)}catch(e){throw e instanceof Error?console.log("GetAllConceptsByType error message: ",e.message):console.log("GetAllConceptsByType unexpected error: ",e),e}}))}class J{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=E(),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=P(new Date),this.terminationDateTime=new Date,this.localSyncTime=new Date}}class z{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(e.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 K=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 q{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 z(e.id,e,null,null);this.addNodeToTree(t)}static waitForDataToLoad(){return K(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(I.isConnectionLoaded)return e("done");setTimeout(q.checkFlag,1e3,e)}static removeNodeFromTree(e){return K(this,void 0,void 0,(function*(){this.connectionroot&&(this.connectionroot=this.connectionroot.removeNode(this.connectionroot,e))}))}static getNodeFromTree(e){return K(this,void 0,void 0,(function*(){return this.connectionroot?this.connectionroot.getFromNode(e,this.connectionroot):this.connectionroot}))}}q.connectionroot=null;var Q=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 Y{static addNodeToTree(e){return Q(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 Q(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(I.isConnectionTypeLoaded)return e("done");setTimeout(Y.checkFlag,1e3,e)}static addConnectionToTree(e){if(0!=e.typeId){var t=new z(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 Q(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 Q(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}))}}Y.connectionTypeRoot=null;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())}))};class Z{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){}static AddConnection(e){e.isTemp||(q.addConnectionToTree(e),Y.addConnectionToTree(e))}static AddConnectionToMemory(e){e.isTemp||(q.addConnectionToTree(e),Y.addConnectionToTree(e))}static AddToDictionary(e){this.connectionDictionary[e.id]=e}static RemoveConnection(e){0!=e.id&&(e.id,q.removeNodeFromTree(e.id),Y.removeTypeConcept(e.typeId,e.id))}static GetConnectionTree(){return q.connectionroot}static GetConnectionTypeTree(){return Y.connectionTypeRoot}static GetConnection(e){return X(this,void 0,void 0,(function*(){var t=new J(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),n=yield q.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConnectionsOfCompositionLocal(e){return X(this,void 0,void 0,(function*(){var t=[],n=yield Y.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}}Z.connectionArray=[],Z.connectionDictionary=[];var ee=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 te(e){return ee(this,void 0,void 0,(function*(){let t=[];try{var o=[];for(let n=0;n<e.length;n++){let i=yield G.GetConcept(e[n]);0==i.id?o.push(e[n]):t.push(i)}if(0==o.length)return t;{var i=yield O();const e=yield fetch(n.GetConceptBulkUrl(),{method:"POST",headers:i,body:JSON.stringify(o)});if(e.ok){let n=yield e.json();if(n.length>0)for(let e=0;e<n.length;e++){let o=n[e];t.push(o),G.AddConcept(o)}}else console.log("Get Concept Bulk error",e.status),M(e);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 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 oe(){return ne(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 te(t)}}))}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())}))};function re(){return ie(this,arguments,void 0,(function*(e=[]){var t=[];for(let o=0;o<e.length;o++){var n=yield Z.GetConnectionsOfCompositionLocal(e[o]);t.push(...n)}return t}))}function ce(e=[],t=[]){for(let n=0;n<t.length;n++)Array.isArray(e)&&(e.find((e=>e.id===t[n].id))||Z.RemoveConnection(t[n]))}var se=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(){return se(this,arguments,void 0,(function*(e=[]){var t=[];if(e.length<=0)return t;var o=yield re(e),i=yield function(){return se(this,arguments,void 0,(function*(e=[]){var t=[];try{var o=yield O();const r=yield fetch(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++)Z.AddConnection(e[i]),t.push(e[i])}else console.log("Get all connections of composition bulk error message: ","Cannot get response"),M(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 ce(t=i,o),yield oe(t),t}))}var le=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 de=new Map;function ue(e){return le(this,void 0,void 0,(function*(){let t=E();if(de.has(e))return de.get(e)||t;const o=(()=>le(this,void 0,void 0,(function*(){try{var o=yield G.GetConcept(e);let r=G.GetNpc(e);if(0!=o.id||r)return o;{var i=yield O("application/x-www-form-urlencoded");const o=yield fetch(n.GetConceptUrl(),{method:"POST",headers:i,body:`id=${e}`});return o.ok?(t=yield o.json(),t.id>0?G.AddConcept(t):G.AddNpc(e)):(console.log("Get the concept error",o.status,e),M(o)),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{de.delete(e)}})))();return de.set(e,o),o}))}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(e){return he(this,void 0,void 0,(function*(){var t=[];if(0==(t=yield Z.GetConnectionsOfCompositionLocal(e)).length)t=yield ye(e);else{var n=yield ye(e);ce(n,t),t=n}return t}))}function ye(e){return he(this,void 0,void 0,(function*(){var t=[];try{var o=yield O("application/x-www-form-urlencoded");const r=yield fetch(n.GetAllConnectionsOfCompositionUrl(),{method:"POST",headers:o,body:`composition_id=${e}`});if(!r.ok)throw M(r),new Error(`Error! status: ${r.status}`);const c=yield r.json();for(var i=0;i<c.length;i++)Z.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 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(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield fe(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 ge(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield fe(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield ke(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 Ce(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield Z.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 me(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield Z.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 Te(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield Z.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 Ne(e,t){return pe(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 G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 we(e,t){return pe(this,arguments,void 0,(function*(e,t,n=[]){var o,i,r={},c=yield G.GetConcept(e);0==c.id&&null!=e&&null!=e&&(c=yield ue(e));var s=yield Ae(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 Ie(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield fe(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 Ae(e,t,n){return pe(this,arguments,void 0,(function*(e,t,n,o=[]){var i,r,c,s={},a=[];if(0==e)return null;var l=yield G.GetConcept(e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield ue(e)),0!=l.id&&null==l.type){var d=l.typeId,u=yield G.GetConcept(d);l.type=u,null==u&&null!=d&&null!=d&&(u=yield ue(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 G.GetConcept(f);null!=y&&0!=y.id||null==f||null==f||(y=yield ue(f)),y&&null==(null==y?void 0:y.type)&&(d=y.typeId,u=yield G.GetConcept(d),y.type=u,null==u&&null!=d&&null!=d&&(u=yield ue(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 Ae(f,t,n,o);s[p]=e}}else{const e=yield Ae(f,t,n,o);a[p]=e,s=a}}return s}))}function ke(e,t,n){return pe(this,arguments,void 0,(function*(e,t,n,o=[]){var i,r,c,s={},a=[];if(0==e)return null;var l=yield G.GetConcept(e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield ue(e)),0!=l.id&&null==l.type){var d=l.typeId,u=yield G.GetConcept(d);l.type=u,null==u&&null!=d&&null!=d&&(u=yield ue(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 G.GetConcept(f);null!=y&&0!=y.id||null==f||null==f||(y=yield ue(f)),y&&null==(null==y?void 0:y.type)&&(d=y.typeId,u=yield G.GetConcept(d),y.type=u,null==u&&null!=d&&null!=d&&(u=yield ue(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 ke(f,t,n);s[p]=e}}else{const e=yield ke(f,t,n);a[p]=e,s=a}}return s}))}var xe=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 Se(e){return xe(this,void 0,void 0,(function*(){let t=E();try{var o=yield O("application/x-www-form-urlencoded");const i=yield fetch(n.GetConceptByCharacterValueUrl(),{method:"POST",headers:o,body:`character_value=${e}`});return i.ok?(t=yield i.json(),t.id>0&&G.AddConcept(t)):(console.log("Error in Getting concept by character value Error",i.status),M(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 _e=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 Re(e){return _e(this,void 0,void 0,(function*(){var t=yield G.GetConceptByCharacter(e),n=`${e}`;return null!=t&&0!=(null==t?void 0:t.id)||!n||(yield Se(e),t=yield G.GetConceptByCharacter(e)),t}))}var Ee=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 Pe(e,t){return Ee(this,arguments,void 0,(function*(e,t,n=10,o=1){var i=yield Re(e),r=[];if(i){yield W(e,t);for(var c=yield G.GetConceptsByTypeIdAndUser(i.id,t),s=n*(o-1),a=[],l=s;l<s+n;l++)c[l]&&a.push(c[l].id);for(yield ae(a),l=s;l<s+n;l++)if(c[l]){var d=yield Ce(c[l].id);r.push(d)}}return r}))}function Le(e,t){return Ee(this,arguments,void 0,(function*(e,t,n=10,o=1){var i=yield Re(e),r=[];if(i){yield W(e,t);for(var c=yield G.GetConceptsByTypeIdAndUser(i.id,t),s=n*(o-1),a=[],l=s;l<s+n;l++)c[l]&&a.push(c[l].id);for(yield ae(a),l=s;l<s+n;l++)if(c[l]){var d=yield me(c[l].id);r.push(d)}}return r}))}class Be{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(e.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 Ue=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 Ge{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 Be(e.id,e,null,null);new Be(e.characterValue,e,null,null),this.addNodeToTree(t)}static waitForDataToLoad(){return Ue(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(I.isLocalDataLoaded)return e("done");setTimeout(Ge.checkFlag,1e3,e)}static getNodeFromTree(e){return Ue(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 Ue(this,void 0,void 0,(function*(){this.root&&(this.root=this.root.removeNode(this.root,e))}))}}Ge.root=null;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())}))};class De{static waitForDataToLoad(){return Fe(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(I.isLocalCharacterLoaded)return e("done");setTimeout(De.checkFlag,1e3,e)}static addNodeToTree(e){return Fe(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 Be(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 Fe(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))}}De.LocalCharacterRoot=null;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())}))};class Oe{static addNodeToTree(e){return Ve(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 Be(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 Ve(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(I.isLocalTypeLoaded)return e("done");setTimeout(Oe.checkFlag,1e3,e)}static getTypeVariantsFromTreeWithUserId(e,t){return Ve(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}))}}Oe.LocalTypeRoot=null;class be{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 $e(){let e=new Date,t=new Date;return new be(0,0,0,0,0,"0","0",!1,e,t,0)}var Me=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 je{constructor(){this.name="conceptsArray"}static AddConcept(e){e.id>0&&(Ge.addConceptToTree(e),De.addConceptToTree(e),Oe.addConceptToTree(e),this.localconceptsArray.push(e))}static AddConceptToMemory(e){e.id>0&&(Ge.addConceptToTree(e),De.addConceptToTree(e),Oe.addConceptToTree(e))}static GetConcept(e){return Me(this,void 0,void 0,(function*(){var t=$e(),n=yield Ge.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConceptByCharacter(e){return Me(this,void 0,void 0,(function*(){var t=$e(),n=De.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterAndTypeLocal(e,t){return Me(this,void 0,void 0,(function*(){var n=$e(),o=yield De.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 Me(this,void 0,void 0,(function*(){let n=[];return n=yield Oe.getTypeVariantsFromTreeWithUserId(e,t),n}))}getName(){return this.name}}je.localconceptsArray=[];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())}))};class We{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,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 He(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(I.isLocalConnectionLoaded)return e("done");setTimeout(We.checkFlag,1e3,e)}static GetConnectionsOfCompositionLocal(e){return He(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}}We.connectionArray=[],We.connectionDictionary=[];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 ze(e){return Je(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield We.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield je.GetConcept(e),a=yield qe(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:"top"]=a,i}))}function Ke(e){return Je(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield We.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield je.GetConcept(e);if(0!=s.id){var a=yield qe(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:"top"]=a;var l={}}return l.data=i,l.id=e,l}))}function qe(e,t,n){return Je(this,arguments,void 0,(function*(e,t,n,o=[]){var i,r,c,s={},a=[],l=yield je.GetConcept(e);if(0!=l.id&&null==l.type){var d=l.typeId,u=yield je.GetConcept(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 je.GetConcept(f);0!=y.id&&null==(null==y?void 0:y.type)&&(d=y.typeId,u=yield je.GetConcept(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:"top").replace("the_","");if(isNaN(Number(p))){if(p){const e=yield qe(f,t,n);s[p]=e}}else{const e=yield qe(f,t,n);a[p]=e,s=a}}return s}))}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())}))};function Ye(e){return Qe(this,void 0,void 0,(function*(){return yield je.GetConceptByCharacter(e)}))}var Xe=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 Ze(e,t){return Xe(this,void 0,void 0,(function*(){var n=yield Ye(e),o=[];if(n)for(var i=yield je.GetConceptsByTypeIdAndUser(n.id,t),r=0;r<i.length;r++){var c=yield ze(i[r].id);o.push(c)}return o}))}function et(e,t){return Xe(this,void 0,void 0,(function*(){var n=yield Ye(e),o=[];if(n)for(var i=yield je.GetConceptsByTypeIdAndUser(n.id,t),r=0;r<i.length;r++){var c=yield Ke(i[r].id);o.push(c)}return o}))}function tt(e){return t=this,o=void 0,r=function*(){let t=E();try{var o=yield O();const i=yield h(n.CreateTheConceptUrl(),o,JSON.stringify(e));if(!i.ok)throw j(i),new Error(`Error! status: ${i.status}`);return t=yield i.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 nt(e){return t=this,o=void 0,r=function*(){let t=new J(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);try{var o=yield O(),i=JSON.stringify(e);const r=yield h(n.CreateTheConnectionUrl(),o,i);return r.ok?yield r.json():(console.log("Create the connection error message: ",r),j(r)),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 ot=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 it{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 ot(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)),this.transactionCollections=this.transactionCollections.filter((e=>new Date(e.createdDate).getTime()>(new Date).getTime()-6048e5)),!o)return;t=o.data.concepts.slice(),n=o.data.connections.slice(),t.length>0&&(yield tt(t)),n.length>0&&(yield nt(n))}else{for(let e=0;e<this.conceptsSyncArray.length;e++)G.AddConcept(this.conceptsSyncArray[e]);for(let e=0;e<this.connectionSyncArray.length;e++)Z.AddConnection(this.connectionSyncArray[e]);this.conceptsSyncArray.length>0&&(t=this.conceptsSyncArray.slice(),this.conceptsSyncArray=[],yield tt(t)),this.connectionSyncArray.length>0&&(n=this.connectionSyncArray.slice(),this.connectionSyncArray=[],yield nt(n))}return"done"}catch(e){throw e}}))}static initializeTransaction(e){return ot(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 ot(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 ot(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 ot(this,void 0,void 0,(function*(){if(this.conceptsSyncArray.length>0){for(let e=0;e<this.conceptsSyncArray.length;e++)this.conceptsSyncArray[e];this.conceptsSyncArray=[]}if(this.connectionSyncArray.length>0){for(let e=0;e<this.connectionSyncArray.length;e++)this.connectionSyncArray[e];this.connectionSyncArray=[]}return"done"}))}}function rt(e,t,n,o,i,r,c){var s=new J(0,e,n,t,o,t,i,t,1,t,0,t,4,t,r,c);return e==n?(s.ofTheConceptId=0,s.toTheConceptId=1,s):(s.isTemp=!0,s.id=Math.floor(1e8*Math.random()),it.AddConnection(s),s)}it.conceptsSyncArray=[],it.connectionSyncArray=[],it.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())}))},st=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 at=new Map;function lt(e,t){return st(this,void 0,void 0,(function*(){let o=yield G.GetConceptByCharacterAndTypeLocal(e,t),i=e+t;if(at.has(i))return at.get(i)||o;const r=(()=>st(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 O();const i=yield fetch(n.GetConceptByCharacterAndTypeUrl(),{method:"POST",headers:s,body:c});if(i.ok){let e=yield i.json();o=e,G.AddConcept(o)}else console.log("This is the concept by type and character error",i.status),M(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{at.delete(i)}})))();return at.set(i,r),r}))}function dt(e){return st(this,void 0,void 0,(function*(){let t=[],o=JSON.stringify(e);var i=yield O();const r=yield fetch(n.GetConceptConnectionByType(),{method:"POST",headers:i,body:o});if(r.ok){let e=yield r.json();t=yield te(e)}else console.log("This is the concept by type and character error",r.status),M(r);return t}))}class ut{constructor(e,t,n,o,i,r,c,s,a,l){this.id=0,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.entryTimestamp=a,this.isNew=l}}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())}))};let ft=!1,yt=[];const pt=()=>{yt.length>0&&!ft&&yt.shift()()};var vt=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 gt=!1,Ct=[];const mt=()=>{Ct.length>0&&!gt&&Ct.shift()()};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())}))};class Nt{static getId(){return Tt(this,void 0,void 0,(function*(){this.ids.length<10&&(yield function(){return vt(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{console.log("trying to fetch more concepts"),Ct.push((()=>vt(this,void 0,void 0,(function*(){try{if(gt)return;if(gt=!0,Nt.ids.length>10)return console.log("Enough IDs available, skipping fetch."),gt=!1,mt(),e();var o=yield O("application/x-www-form-urlencoded");const t=yield fetch(n.GetReservedIdUrl(),{method:"GET",headers:o});if(!t.ok)throw M(t),new Error(`Error! status: ${t.status}`);const r=yield t.json();for(var i=0;i<r.length;i++)Nt.AddId(r[i]);console.log("Ids Fetch Success"),e()}catch(e){e instanceof Error?console.log("get reserved ids error message: ",e.message,n.GetReservedConnectionIdUrl()):console.log("get reserved ids unexpected error: ",e),t(e)}finally{gt=!1,mt()}})))),mt()}))}))}());var e=this.ids[0];return this.ids.shift(),e}))}static AddId(e){this.ids.includes(e)||this.ids.push(e)}}Nt.ids=[];class wt{static getId(){return Tt(this,void 0,void 0,(function*(){this.connectionIds.length<10&&(yield function(){return ht(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{yt.push((()=>ht(this,void 0,void 0,(function*(){try{if(ft)return;if(ft=!0,wt.connectionIds.length>10)return ft=!1,pt(),e();var o=yield O("application/x-www-form-urlencoded");const t=yield fetch(n.GetReservedConnectionIdUrl(),{method:"GET",headers:o});if(!t.ok)throw M(t),new Error(`Error! status: ${t.status}`);const r=yield t.json();for(var i=0;i<r.length;i++)wt.AddId(r[i]);e()}catch(e){e instanceof Error?console.log("get reserved connection ids error message: ",e.message):console.log("get reserved connection ids unexpected error: ",e),t(e)}finally{ft=!1,pt()}})))),pt()}))}))}());var e=this.connectionIds[0];return this.connectionIds.shift(),e}))}static AddId(e){this.connectionIds.includes(e)||this.connectionIds.push(e)}}wt.connectionIds=[];var It=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 At(e,t,n,o,i,r,c,s,a,l,d,u,h,f){return It(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 Nt.getId();let v=new Date,g=new Date;var C=new R(p,t,i,r,n,o,c,s,e,a,l,d,u,h,f,!0,v,g);return C.isTemp=!1,it.AddConcept(C),y.concepts.push(C),C}))}function kt(e,t,n,o,i,r,c,s,a,l,d,u,h,f){return It(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 Nt.getId();let v=new Date,g=new Date;var C=new R(p,t,i,r,n,o,c,s,e,a,l,d,u,h,f,!1,v,g);return G.AddConcept(C),C.updateRecursion=!0,it.AddConcept(C),y.concepts.push(C),C}))}var xt=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){return xt(this,arguments,void 0,(function*(e,t,o=!1,i,r,c=999,s=0,a={concepts:[],connections:[]}){let l,d=c,u=(i=o?i:999,999),h=i,f=i,y=r,p=i,v="",g=t.length,C=E();v=e.startsWith("the_")?e:"the_"+e;(new Date).getTime();if(o)C=yield xn(e),l=yield At(t,i,4,i,C.id,C.userId,s,999,u,h,y,p,d,f,a),(new Date).getTime();else if(g>255)C=yield xn(v),l=yield At(t,i,4,i,C.id,C.userId,s,999,u,h,y,p,d,f,a),function(e){ct(this,void 0,void 0,(function*(){try{var t=yield O();const o=yield fetch(n.CreateTheTextDataUrl(),{method:"POST",headers:t,body:JSON.stringify(e)});if(!o.ok)throw M(o),new Error(`Error! status: ${o.status}`);return yield o.json()}catch(e){throw e instanceof Error?console.log("Create the text error message: ",e.message):console.log("Create the text unexpected error: ",e),e}}))}(new ut(i,t,u,h,y,p,d,f,Date.now().toString(),!0)),(new Date).getTime();else{C=yield xn(v);let e=yield lt(t,C.id);l=e,0==e.id&&0==e.userId&&(l=yield kt(t,i,4,i,C.id,C.userId,12,12,u,h,y,p,d,f,a)),(new Date).getTime()}return l.type=C,l}))}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){return _t(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=E();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 St(o,"",!0,s,a,l),h=p.id,d=p.id,yield Rt(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 St(o,"",!0,s,a,l),yield rt(f,y,p.id,p.userId,h,l,p.userId),yield Rt(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 St(o,e[o].toString(),!1,s,a,l);yield rt(f,y,p.id,p.userId,h,l,p.userId)}return u}))}class Et{constructor(e=0,t,n,o,i,r,c=999){this.isTemp=!1,this.applicationId=999,this.type=$e(),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=P(new Date),this.terminationDateTime=new Date,this.localSyncTime=new Date,this.applicationId=c}}function Pt(e,t,n,o=1){Math.floor(1e8*Math.random());let i=0,r=0,c=0;i=e,r=t,c=n;let s=new Et(0,0,0,0,0,0);return e!=t&&(s=new Et(0,e,t,n,o,4),s.isTemp=!0,s.id=Math.floor(1e8*Math.random()),We.AddConnection(s)),s}var Lt=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,t,n,o,i,r){return Lt(this,arguments,void 0,(function*(e,t,n,o,i,r,c=0){var s=Math.floor(1e8*Math.random());let a=new Date,l=new Date;var d=new be(s,n,i,o,r,e,t,!0,a,l,c);return d.isTemp=!0,je.AddConcept(d),d}))}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())}))},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())}))};function Ft(e,t,n,o){return Gt(this,void 0,void 0,(function*(){var i=yield Ye(e);if(i&&(0==i.id||0==i.userId)){var r=D(e);if(r[0]==e){var c=yield function(e,t,n){return Ut(this,void 0,void 0,(function*(){var t=yield je.GetConceptByCharacterAndTypeLocal(e,51),o=t;return 0==o.id&&(o=t=yield Bt(e,"the",n,4,51,4)),o}))}(e,0,o);i=c}else{var s=yield Ft(r[0],t,n,o),a=yield Ft(r[1],t,n,o);a&&(i=c=yield Bt(e,r[1],o,s.id,a.id,4))}}return i}))}var Dt=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 Vt(e,t){return Dt(this,arguments,void 0,(function*(e,t,n=!1,o,i,r=999,c=0){var s,a,l,d=o=n?o:999,u=t.length;if(l=e.startsWith("the_")?e:"the_"+e,n)s=yield Ft(e,999,o,o),a=yield Bt(t,e,o,4,s.id,4,c);else if(u>255)s=yield Ft(l,999,d,o),a=yield Bt(t,l,o,4,s.id,4);else{s=yield Ft(l,999,d,o);var h=yield je.GetConceptByCharacterAndTypeLocal(t,s.id);a=h,0==h.id&&0==h.userId&&(a=yield Bt(t,l,o,4,s.id,4))}return a.type=s,a}))}var Ot=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 Ot(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:999,l=null!=c?c:4,d=null!=o?o:0,u=$e();for(const o in e)if("string"!=typeof e[o]&&"number"!=typeof e[o])if(null==t&&null==n){var h=d;u=y=yield Vt(o,"",!0,s,a,l),h=y.id,d=y.id,yield bt(e[o],y.id,y.userId,h,i,r,c)}else{var f=null!=t?t:999,y=(h=d,yield Vt(o,"",!0,s,a,l));yield Pt(f,y.id,h),yield bt(e[o],y.id,y.userId,h,i,r,c)}else f=null!=t?t:999,h=d,y=yield Vt(o,e[o].toString(),!1,s,a,l),yield Pt(f,y.id,h);return u}))}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 Mt(e,t,o){return $t(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 O("application/x-www-form-urlencoded");const l=yield fetch(n.GetAllConnectionsOfConceptUrl(),{method:"POST",headers:a,body:s});return l.ok?c=yield l.json():(console.log("Get connection of concept error",l.status),M(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 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())}))};function Ht(e,t,n,o,i,r,c){return jt(this,arguments,void 0,(function*(e,t,n,o,i,r,c,s=1,a=4,l=999,d={concepts:[],connections:[]}){let u=t,h=t,f=t;999!=l&&(f=l);let y=t,p=t,v=yield wt.getId(),g=new J(v,e,n,t,o,f,i,h,s,u,0,y,a,p,r,c);return e==n?(g.ofTheConceptId=0,g.toTheConceptId=1,g):(g.toUpdate=!0,g.isTemp=!1,it.AddConnection(g),d.connections.push(g),g)}))}function Wt(e,t,n){return jt(this,arguments,void 0,(function*(e,t,n,o={concepts:[],connections:[]}){let i=yield xn(n),r=e.userId;return yield Ht(e.id,e.userId,t.id,t.userId,i.id,999,999,1e3,4,r,o)}))}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())}))},zt=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())}))},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 qt(e){return Kt(this,void 0,void 0,(function*(){var t=yield Z.GetConnection(e);if((null==t||0==t.id)&&null!=e&&null!=e){var o=yield function(e){return zt(this,void 0,void 0,(function*(){var t=yield Z.GetConnection(e);try{if(0!=t.id)return t;{var o=yield O("application/x-www-form-urlencoded");const i=yield fetch(n.GetConnectionUrl(),{method:"POST",headers:o,body:`id=${e}`});return i.ok?(t=yield i.json(),Z.AddConnection(t)):(console.log("Get Connection Error",i.status),M(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 Qt=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 Yt(e){return Qt(this,arguments,void 0,(function*(e,t=""){let o=!1;var i=yield qt(e);return o=yield function(e){return Jt(this,arguments,void 0,(function*(e,t=""){let o=!1;try{const i=new FormData;let r={Authorization:(yield b("",t)).Authorization,Accept:"application/json"};i.append("id",e.toString()),i.append("apiKey","nodeserver");const c=yield fetch(n.DeleteTheConnectionUrl(),{method:"POST",headers:r,body:i,redirect:"follow"});c.ok?o=(yield c.json()).success:(console.log("Delete connection error status: ",c.status),M(c))}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),q.removeNodeFromTree(e),Y.removeTypeConcept(i.typeId,e),o}))}var Xt=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 Zt(e){return Xt(this,arguments,void 0,(function*(e,t=999){var n=E();if(e<0)return ni(yield Jo(t,e));if(null!=(n=yield G.GetConcept(e))&&0!=n.id||null==e||null==e||(n=yield ue(e)),0!=n.id&&null==n.type&&null==(yield G.GetConcept(n.typeId))&&null!=n.typeId&&null!=n.typeId){var o=yield ue(n.typeId);n.type=o}return n}))}var en=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){return en(this,arguments,void 0,(function*(e,t,n,o=!1,i=!1){var r,c,s=e.userId,a=s,l=s;if(o){let o=n+"_by",c=(null===(r=t.type)||void 0===r?void 0:r.characterValue)+"_s_"+o;i&&(yield nn(o,t,s));var d=yield St("connection",c,!1,999,999,999);let u=new J(0,t.id,e.id,t.userId,e.userId,t.userId,d.id,d.userId,1e3,s,999,a,4,l,999,999);it.AddConnection(u)}let u=n+"_s",h=(null===(c=e.type)||void 0===c?void 0:c.characterValue)+"_s_"+u;i&&(yield nn(u,e,s));var f=yield St("connection",h,!1,999,999,999);let y=new J(0,e.id,t.id,e.userId,t.userId,e.userId,f.id,f.userId,1e3,s,999,a,4,l,999,999);return it.AddConnection(y),y}))}function nn(e,t){return en(this,arguments,void 0,(function*(e,t,n=null){for(var o,i=t,r=null!=n?n:t.userId,c=r,s=r,a=999,l=e+"_count",d=(null===(o=t.type)||void 0===o?void 0:o.characterValue)+"_s_"+l,u=yield St("connection",d,!1,r,4,a),h=yield Mt(u.id,t.id,r,10,1),f=[],y=E(),p=0;p<h.length;p++){let e=yield Zt(h[p].toTheConceptId);f.push(e)}if(f.length<1)y=yield St("count","1",!1,r,4,a);else{var v=f[0];let e=0;try{e=Number(v.characterValue)}catch(t){e=0}e+=1,y=yield St("count",e.toString(),!1,r,4,a);for(let e=0;e<h.length;e++)Yt(h[e].id)}let g=new J(0,i.id,y.id,i.userId,y.userId,i.userId,u.id,u.userId,1e3,r,999,c,4,s,a,999);yield it.AddConnection(g)}))}function on(e,t,n){return en(this,arguments,void 0,(function*(e,t,n,o=!1,i=!1){var r,c,s=e.userId,a=s,l=s;if(o){let o=n+"_by",c=(null===(r=t.type)||void 0===r?void 0:r.characterValue)+"_s_"+o;i&&(yield nn(o,t,s));var d=yield St("connection",c,!1,999,999,999);let u=new J(0,t.id,e.id,t.userId,e.userId,t.userId,d.id,d.userId,1e3,s,999,a,4,l,999,999);it.AddConnection(u)}let u=n+"_s",h=(null===(c=e.type)||void 0===c?void 0:c.characterValue)+"_s_"+u;i&&(yield nn(u,e,s));var f=yield St("connection",h,!1,999,999,999);return yield Ht(e.id,e.userId,t.id,t.userId,f.id,999,999,1e3,4)}))}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,t){return rn(this,arguments,void 0,(function*(e,t,n=10,o=1){var i,r=[],c=yield Zt(e),s=(null===(i=c.type)||void 0===i?void 0:i.characterValue)+"_s_"+t,a=yield lt(s,16);if(a.id>0){for(var l=yield Mt(a.id,c.id,c.userId,n,o),d=[],u=0;u<l.length;u++)d.push(l[u].toTheConceptId);for(yield ae(d),u=0;u<l.length;u++){let e=l[u].toTheConceptId,t=yield Zt(e),n=yield Te(t.id);r.push(n)}}return r}))}function sn(e,t){return rn(this,arguments,void 0,(function*(e,t,n=10,o=1){var i,r=[],c=yield Zt(e),s=(null===(i=c.type)||void 0===i?void 0:i.characterValue)+"_s_"+t,a=yield lt(s,16);if(a.id>0){for(var l=yield Mt(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 Zt(e);r.push(t)}}return r}))}class an{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 ln{constructor(){this.name="character Repository"}static AddCharacter(e){this.characterData[e.id]=e}static GetCharacter(e){for(var t=new an(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}}ln.characterData=[];class dn{constructor(e,t,n,o){this.id=e,this.userId=t,this.referentId=n,this.isNew=o}}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())}))},hn=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,o,i,r){return hn(this,void 0,void 0,(function*(){return new an(t,e,o,t,i,t,r,t,"",!1),yield function(){return un(this,void 0,void 0,(function*(){var e;try{if(0==(e=ln.GetCharacter(e.data)).id){var t=yield O();const i=yield fetch(n.CreateTheCharacterDataUrl(),{method:"POST",headers:t,body:JSON.stringify(e)});if(!i.ok)throw M(i),new Error(`Error! status: ${i.status}`);const r=yield i.json();var o=new an(r.userId,e.data,0,0,4,4,999,999,"",!1);return o.id=r.id,ln.AddCharacter(o),r}return new dn(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 yn=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,t,n,o,i,r,c,s,a,l,d,u,h,f){return yn(this,void 0,void 0,(function*(){var y=yield lt(e,i),p=y;return 0==p.id&&(p=y=yield At(e,t,n,o,i,r,c,s,a,l,d,u,h,f)),p}))}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,n,o){return gn(this,arguments,void 0,(function*(e,t,n,o,i={concepts:[],connections:[]}){var r=yield Re(e);if(r&&(0==r.id||0==r.userId)){var c=D(e);if(c.length>0)if(console.log(c),c[0]==e){var s=yield function(e,t,n,o,i,r){return vn(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 fn(e,t,n,o,r),a=pn(e,t,4,c,h,u,49,l,n,s,o,i,r,d)}else{var f=yield fn(e,t,n,o,r);f.isNew,a=yield pn(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 Cn(c[0],t,n,o,i),l=yield Cn(c[1],t,n,o,i);l&&(r=yield kt(e,o,a.id,o,l.id,o,999,o,999,o,999,o,t,o,i))}}return r}))}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())}))};const Tn=new Map;function Nn(e,t){return mn(this,void 0,void 0,(function*(){let o=E();if(Tn.has(e+t))return Tn.get(e+t)||o;const i=(()=>mn(this,void 0,void 0,(function*(){try{var i=yield O("application/x-www-form-urlencoded");const r=yield fetch(n.GetConceptByCharacterAndCategoryDirectUrl(),{method:"POST",headers:i,body:`character_value=${e}&category_id=${t}`});if(r.ok){let e=yield r.json();o=e,G.AddConcept(o)}else console.log("This is the concept by category and character direct api error",r.status),M(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{Tn.delete(e+t)}})))();return Tn.set(e+t,i),i}))}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())}))};function In(e){return wn(this,void 0,void 0,(function*(){let t=E();if("the"==e)return t.id=1,t.typeId=5,t.characterValue="the",t;let n=e.length;var o=D(e);if(o.length>1){let n=1,i=yield In(o[0]);0!=i.id&&(n=i.id),t=yield function(e,t){return wn(this,void 0,void 0,(function*(){let n=yield G.GetConceptByCharacterAndCategoryLocal(e,t);return 0==n.id&&(n=yield Nn(e,t)),n}))}(e,n)}else o[0]==e&&1==n?t=yield function(e){return wn(this,void 0,void 0,(function*(){console.log("inside the character length function",e);var t=yield G.GetConceptByCharacterAndTypeLocal(e,49);return console.log("inside the character length function after",t),0==t.id&&(t=yield Se(e)),t}))}(e):o[0]==e&&(t=yield function(e){return wn(this,void 0,void 0,(function*(){var t=yield G.GetConceptByCharacterAndTypeLocal(e,51);return 0==t.id&&(t=yield Se(e)),t}))}(e));return t}))}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())}))};const kn=new Map;function xn(e,t){return An(this,void 0,void 0,(function*(){let t=E();if(kn.has(e))return kn.get(e)||t;const o=(()=>An(this,void 0,void 0,(function*(){try{if(t=yield In(e),0==t.id||4==t.typeId){var o=yield O("application/x-www-form-urlencoded");const i=yield fetch(n.MakeTheTypeConceptUrl(),{method:"POST",headers:o,body:`type=${e}`});if(!i.ok)throw M(i),new Error(`Error! status: ${i.status}`);let r=yield i.json();t=r,t.id>0&&G.AddConcept(t)}return 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{kn.delete(e)}})))();return kn.set(e,o),o}))}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 _n(e){return Sn(this,void 0,void 0,(function*(){var t=[];try{(new Date).getTime();var o=yield O("application/x-www-form-urlencoded");const c=yield fetch(n.GetAllLinkerConnectionOfConceptUrl()+`?conceptId=${e}`,{method:"GET",headers:o});if(c.ok){const e=yield c.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"),M(c);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 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 En(e){return Rn(this,void 0,void 0,(function*(){var t=[];try{(new Date).getTime();var o=yield O("application/x-www-form-urlencoded");const c=yield fetch(n.GetAllLinkerConnectionToConceptUrl()+`?conceptId=${e}`,{method:"GET",headers:o});if(c.ok){const e=yield c.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"),M(c);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 Pn=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){return Pn(this,void 0,void 0,(function*(){for(var t=yield _n(e),n=0;n<t.length;n++){let e=t[n];var o=e.typeId;let i=yield Zt(o);e.type=i}return t}))}function Bn(e){return Pn(this,void 0,void 0,(function*(){for(var t=yield En(e),n=0;n<t.length;n++){let e=t[n];var o=e.typeId;let i=yield Zt(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())}))},Gn=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},Fn=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){return Fn(this,arguments,void 0,(function*(e,t=""){var o=yield Zt(e);yield _.removeNodeFromTree(e);var i=o.typeId,r=o.characterValue;yield B.removeTypeConcept(i,e),yield x.removeNodeByCharacter(r,e);let c=yield function(e){return Un(this,arguments,void 0,(function*(e,t=""){let o=!1;try{let i=yield b("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=Gn(i,["Content-Type"]),a=yield fetch(n.DeleteConceptUrl(),{method:"POST",headers:s,body:r});if(!a.ok)throw M(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 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())}))};function On(e,t){return Vn(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 fetch(n.DeleteConceptUrl(),{method:"POST",body:i,headers:o});if(!r.ok)throw M(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 $n(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=E();return r=l?e:"the_"+e,d=yield xn(r),yield pn(t,n,4,n,d.id,d.userId,0,999,999,c,4,a,999,s)}))}class Mn{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 jn=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 jn(this,arguments,void 0,(function*(e=[]){var t=[];try{var o=[];for(let n=0;n<e.length;n++){let i=yield Z.GetConnection(e[n]);0==i.id?o.push(e[n]):t.push(i)}if(0==o.length)return t;{var i=yield O();const e=yield fetch(n.GetConnectionBulkUrl(),{method:"POST",headers:i,body:JSON.stringify(o)});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),Z.AddConnection(o)}yield oe(t)}}else console.log("Get Connection Bulk error",e.status),M(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 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())}))};function Jn(){return Wn(this,arguments,void 0,(function*(e=[]){yield ae(e);var t=[];for(let o=0;o<e.length;o++){var n=yield Ce(e[o]);t.push(n)}return t}))}function zn(){return Wn(this,arguments,void 0,(function*(e=[]){yield ae(e);var t=[];for(let o=0;o<e.length;o++){var n=yield me(e[o]);t.push(n)}return t}))}function Kn(){return Wn(this,arguments,void 0,(function*(e=[],t=[]){yield Hn(t),function(e=[],t=[]){for(let n=0;n<t.length;n++)e.includes(t[n].id)||Z.RemoveConnection(t[n])}(t,yield re(e));var n=[];for(let t=0;t<e.length;t++){var o=yield me(e[t]);n.push(o)}return n}))}function qn(){return Wn(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 Z.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 Hn(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 te(i),n}))}function Qn(){return Wn(this,arguments,void 0,(function*(e=[],t=[]){let n=[],o=[];for(let e=0;e<t.length;e++){let i=yield Z.GetConnection(t[e]);0==i.id?n.push(t[e]):o.push(i)}let i=yield Hn(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 we(e[t],o,c);r[e[t]]=n}return r}))}var Yn=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(){return Yn(this,arguments,void 0,(function*(e=0,t=[],o=""){var i=[];try{var r=new Mn;r.composition=e,r.listLinkers=t,r.textSearch=o;var c=JSON.stringify(r),s=yield O();const d=yield fetch(n.RecursiveSearchUrl(),{method:"POST",headers:s,body:c});if(d.ok){const e=yield d.json();var a=e.compositionIds,l=e.internalConnections;e.externalConnections,i=yield Kn(a,l)}else console.log("recursive search error ",d.status),M(d);return i}catch(e){throw e instanceof Error?console.log("recursive search error message: ",e.message):console.log("recursive search unexpected error: ",e),e}}))}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 eo(e,t){return Zn(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 fetch(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),M(s)}catch(e){throw e instanceof Error?console.log("Login tsccs error message: ",e.message):console.log(" Login tsccs unexpected error: ",e),e}}))}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())}))};function no(e){return to(this,void 0,void 0,(function*(){const t=yield function(){return to(this,arguments,void 0,(function*(e="",t={}){let n={message:"success",status:!1,statusCode:200,data:""};try{const o=yield fetch(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}:M(o),n}catch(e){throw console.log("Signup Error: ",e),e}}))}(n.SignupUrl(),e);return t}))}var oo=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 oo(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 fetch(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}:M(e),o}catch(e){throw console.log("Sign in api error",e),e}}))}function ro(e,t){return-1===e.indexOf(t)&&e.push(t),e}function co(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 so(e=[],t){let n=[],o=t.typeCharacter;if((null==o?void 0:o.startsWith("the_"))||(o="the_"+o),Array.isArray(e))for(let i=0;i<e.length;i++){let r=e[i].typeCharacter;(null==r?void 0:r.startsWith("the_"))||(r="the_"+r),t.typeId!=e[i].typeId&&o!=r||n.push(e[i])}return n}function ao(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 lo(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 uo(e=[],t){Array.isArray(e)&&e.splice(e.findIndex((function(e){return e.id===t.id})),1)}function ho(e=[],t){Array.isArray(e)&&e.splice(e.findIndex((function(e){return e.id===t.id})),1)}class fo{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&&(po.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(e.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 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())}))};class po{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 fo(e.id,e,null,null);this.addNodeToTree(t)}static getNodeFromTree(e){return yo(this,void 0,void 0,(function*(){return this.root?this.root.getFromNode(e,this.root):null}))}static removeNodeFromTree(e){return yo(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}}po.root=null;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 go(e,t,n,o){return vo(this,arguments,void 0,(function*(e,t,n,o,i=[]){var r,c;let s={};const a=[];if(0==e)return"";let l=Co(n,e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield Zt(e)),0!=l.id&&null==l.type){const e=l.typeId;let t=Co(n,e);l.type=t,null==t&&null!=e&&null!=e&&(t=yield Zt(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=Co(n,d);if(null!=e&&0!=e.id||null==d||null==d||(e=yield Zt(d)),0!=e.id&&null==(null==e?void 0:e.type)){const t=e.typeId;let n=yield G.GetConcept(t);e.type=n,null==n&&null!=t&&null!=t&&(n=yield Zt(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 go(d,t,n,o,i);s[u]=e}}else{const e=yield go(d,t,n,o,i);a[u]=e,s=a}}}return s}))}function Co(e,t){let n=E();for(let o=0;o<e.length;o++)if(t==e[o].id)return n=e[o],n;return n}class mo{constructor(){this.id=0,this.mainConcept=E(),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 go(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 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())}))};function No(e){return To(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=E();null==s&&(s=new mo);for(const o in e)if("object"==typeof e[o]||Array.isArray(e[o])){const f=yield St(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 No(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 rt(a,l,f.id,f.userId,y,d,f.userId);s.connections.push(p),yield No(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 St(o,e[o],!1,a,l,d);s.concepts.push(h);const f=yield rt(i,r,h.id,h.userId,c,d,h.userId);s.connections.push(f)}return h}))}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,void 0,void 0,(function*(){const t=e.userId,n=e.sessionId,o=e.accessId;let i=[];const r=[];let c=E(),s=E();const a=[];let l=e.compositionId;const d=e.ofTheCompositionId;let u=[];if(l<0){let e=yield Zt(l,t);if(!(e.id>0))return null;l=e.id}i=yield fe(l);const h=[],f=new mo,y=[];f.id=l,f.isUpdating();let p=[];for(let e=0;e<i.length;e++)ro(y,i[e].ofTheConceptId),ro(h,i[e].ofTheConceptId),ro(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 Zt(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=E();const l=v[e];let d=c;if(s.id>0&&(d=s),Array.isArray(l)||"object"==typeof l){i=yield St(e,"",!0,c.userId,4,999),f.subcompositions.push(i.id);const t=co(r,i);for(let e=0;e<t.length;e++)if(t[e].id>0){const n=ao(f.connections,t[e].id);u=u.concat(n),a.push(t[e])}yield No(v[e],i.id,i.userId,c.id,c.userId,4,999,f)}else{i=yield St(e,l,!1,t,o,n);const c=co(r,i);for(let e=0;e<c.length;e++)if(c[e].id>0){const t=ao(f.connections,c[e].id);u=u.concat(t),a.push(c[e])}}const h=yield rt(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++)ho(f.connections,u[e]),Yt(u[e].id);for(let e=0;e<a.length;e++)uo(r,a[e]);return f.concepts=f.concepts.concat(r),f.mainConcept=c,f.id=c.id,yield f.updateCache(),po.addCompositionToTree(f),yield it.SyncDataOnline(),f.GetDataCache()}))}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 b("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 fetch(l,{method:"GET",headers:s});return e.ok?yield e.json():(M(e),[])}catch(e){throw console.log("This is the searching error",e),e}}))}var 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 So(e){return xo(this,arguments,void 0,(function*(e,t=""){var o=yield b("application/json",t);const i=n.SearchLinkMultipleAll(),r=JSON.stringify(e);try{const e=yield fetch(i,{method:"POST",headers:o,body:r});return e.ok?yield e.json():(console.log("This is the searching error",e.status),M(e),[])}catch(e){throw console.log("This is the searching 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 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 G.GetConcept(e);0==l.id&&null!=e&&null!=e&&(l=yield ue(e));let d=[];d=t.length>0?Eo(e,t):yield fe(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 Ae(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 Po(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 G.GetConcept(e);0==d.id&&null!=e&&null!=e&&(d=yield ue(e));let u=[];u=t.length>0?Eo(e,t):yield fe(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 Ae(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 Lo(e,t){return _o(this,void 0,void 0,(function*(){let n=[];const o=[];n=yield Hn(t);for(let t=0;t<e.length;t++){const i=yield Po(e[t],n);i&&o.push(i)}return o}))}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 Uo(e){return Bo(this,void 0,void 0,(function*(){try{var t=yield O();const o=JSON.stringify(e),i=yield fetch(n.CreateSessionId(),{method:"POST",headers:t,body:o});return i.ok?i.json():(console.log("Creating session failed",yield i.json()),M(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 O("application/x-www-form-urlencoded");const i=new URLSearchParams;i.append("sessionId",e.toString()),i.append("url",t);const r=yield fetch(n.CreateSessionVisitUrl(),{method:"POST",headers:o,body:i});return r.ok?r.json():(console.log("Creating session url failed",yield r.json()),M(r),null)}catch(e){throw console.log("Creating session url failed",e),e}}))}var Do=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,t,o){return Do(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 O("application/x-www-form-urlencoded");const l=yield fetch(n.GetAllConnectionsToConceptUrl(),{method:"POST",headers:a,body:s});return l.ok?c=yield l.json():(console.log("Get connection of concept error",l.status),M(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 Oo=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 bo(e,t){return Oo(this,arguments,void 0,(function*(e,t,n=10,o=1,i=!1){let r=[],c=yield Zt(e),s=yield In(t);if(s.id>0){let e=[],t=[];if(i){t=yield Vo(s.id,c.id,c.userId,n,o);let e=[];for(let n=0;n<t.length;n++)e.push(t[n].ofTheConceptId);yield ae(e);for(let e=0;e<t.length;e++){let n=t[e].ofTheConceptId,o=yield Zt(n),i=yield Te(o.id);r.push(i)}}else{t=yield Mt(s.id,c.id,c.userId,n,o);for(let n=0;n<t.length;n++)e.push(t[n].toTheConceptId);yield ae(e);for(let e=0;e<t.length;e++){let n=t[e].toTheConceptId,o=yield Zt(n),i=yield Te(o.id);r.push(i)}}}return r}))}function $o(e,t){return Oo(this,arguments,void 0,(function*(e,t,n=10,o=1,i=!1){let r=[],c=yield Zt(e),s=yield In(t),a=[],l=[];if(s.id>0){if(i){a=yield Vo(s.id,c.id,c.userId,n,o);for(let e=0;e<a.length;e++)l.push(a[e].ofTheConceptId)}else{a=yield Mt(s.id,c.id,c.userId,n,o);for(let e=0;e<a.length;e++)l.push(a[e].toTheConceptId)}r=yield te(l)}return r}))}class Mo{constructor(e,t,n,o,i){this.connectionValue=[],this.value=[],this.height=1,this.key=e,t.id>0&&this.value.push(t),n.id>0&&this.connectionValue.push(n),this.leftNode=o,this.rightNode=i}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.value.push(...e.value),t.connectionValue.push(...e.connectionValue),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}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(e.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}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.rightNode=this.removeNode(e.rightNode,n.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 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 Ho{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 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 jo(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(I.isDataLoaded)return e("done");setTimeout(Ho.checkFlag,1e3,e)}static addConceptToTree(e,t,n=999){let o=this.compositeKey(t,n,e.applicationId),i=new Et(0,0,0,0,0,0);var r=new Mo(o,e,i,null,null);this.addNodeToTree(r)}static addConnectionToTree(e,t,n=999){let o=this.compositeKey(t,n,e.applicationId),i=$e();var r=new Mo(o,i,e,null,null);this.addNodeToTree(r)}static getNodeFromTree(e,t){return jo(this,arguments,void 0,(function*(e,t,n=999){let o=this.compositeKey(e,t,n);return this.root?this.root.getFromNode(o,this.root):null}))}static removeNodeFromTree(e){return jo(this,arguments,void 0,(function*(e,t=999,n=999){if(this.root){let o=this.compositeKey(e,t,n);this.root=this.root.removeNode(this.root,o)}}))}static countNumberOfNodes(){return this.root?this.root.countNodeBelow(this.root):0}}Ho.root=null;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 Jo(e,t){return Wo(this,arguments,void 0,(function*(e,t,n=999,o=999){let i=yield Ho.getNodeFromTree(e,n,o),r=$e();if(i)for(let e=0;e<i.value.length;e++){let n=i.value[e];n.ghostId==t&&(r=n)}return r}))}function zo(e,t){return Wo(this,arguments,void 0,(function*(e,t,n=999,o=999){let i=yield Ho.getNodeFromTree(e,n,o),r=new Et(0,0,0,0,0,0);if(i)for(let e=0;e<i.connectionValue.length;e++){let n=i.connectionValue[e];n.ghostId==t&&(r=n)}return r}))}function Ko(e,t){return Wo(this,arguments,void 0,(function*(e,t,n=999){Ho.addConceptToTree(e,t,n)}))}function qo(e,t){return Wo(this,arguments,void 0,(function*(e,t,n=999){Ho.addConnectionToTree(e,t,n)}))}var Qo=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 Yo(e){return Qo(this,arguments,void 0,(function*(e,t=""){var o=yield b("application/json",t);const i=n.SearchLinkMultipleAllApiUrl(),r=JSON.stringify(e);try{const e=yield fetch(i,{method:"POST",headers:o,body:r});return e.ok?yield e.json():(console.log("This is the searching multiple error",e.status),M(e),[])}catch(e){throw console.log("This is the searching multiple error",e),e}}))}var 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,arguments,void 0,(function*(e,t=""){let n=[],o=yield Yo(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 ei(a,n,i,l)}))}function ei(e,t,n){return Xo(this,arguments,void 0,(function*(e,t,n,o=[]){let i={},r=yield Hn(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 Zt(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){console.log("this is error",e)}}}else if(t[r[e].ofTheConceptId]&&t[r[e].toTheConceptId]){let n=t[r[e].ofTheConceptId],o=yield Zt(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){console.log("this is error",e)}}}return i=t[n],i}))}function ti(e){var t,n;const o=$e();return o.id=e.id,o.ghostId=e.ghostId,o.userId=e.userId,o.accessId=e.accessId,o.categoryId=e.categoryId,o.characterValue=e.characterValue,o.entryTimeStamp=e.entryTimeStamp,o.typeId=e.typeId,o.type=e.type,o.isTemp=!1,o.typeCharacter=null!==(n=null===(t=null==e?void 0:e.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:"",o}function ni(e){const t=E();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}function oi(e){const t=new Et(0,0,0,0,0,0);return t.id=e.id,t.ghostId=e.ghostId,t.accessId=e.accessId,t.ofTheConceptId=e.ofTheConceptId,t.toTheConceptId=e.toTheConceptId,t.entryTimeStamp=e.entryTimeStamp,t.typeId=e.typeId,t.isTemp=!1,t}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){return ii(this,void 0,void 0,(function*(){const t=e.userId,n=e.sessionId,o=e.accessId;let i=[];const r=[];let c=$e(),s=$e();const a=[],l=e.compositionId,d=e.ofTheCompositionId;let u=[],h=yield fe(l);for(let e=0;e<h.length;e++)i.push(oi(h[e]));const f=[],y=[];let p=[];for(let e=0;e<i.length;e++)ro(y,i[e].ofTheConceptId),ro(f,i[e].ofTheConceptId),ro(f,i[e].toTheConceptId),p.push(i[e].ofTheConceptId);for(let e=0;e<f.length;e++){const t=yield Zt(f[e]);l==f[e]&&(c=ti(t)),d==f[e]&&(s=ti(t)),r.push(ti(t))}const v=e.patchObject;for(const e in v){let l=$e();const d=v[e];let h=c;s.id>0&&(h=s),Array.isArray(d)||"object"==typeof d?(l=yield Vt(e,"",!0,c.userId,4,999),yield bt(v[e],l.id,l.userId,c.id,c.userId,4,999)):l=yield Vt(e,d,!1,t,o,n);const f=so(r,l);for(let e=0;e<f.length;e++)if(f[e].id>0){const t=lo(i,f[e].id);u=u.concat(t),a.push(f[e])}yield Pt(h.id,l.id,c.id,2),r.push(l)}for(let e=0;e<u.length;e++)Yt(u[e].id);it.SyncDataOnline()}))}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,void 0,void 0,(function*(){var t;let o=yield function(e){return ci(this,void 0,void 0,(function*(){let t=[];try{var o=yield O();const i=yield fetch(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;te(i),n[r]=t}return n}return console.log("View Internal Data error",i.status),M(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 Ae(r,c,e);t.data=n,t.id=r,i.push(t)}else{let e={};e.id=r;let n=yield Zt(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}))}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())}))},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())}))};function ui(e){return di(this,arguments,void 0,(function*(e,t=""){var o=yield function(e){return li(this,arguments,void 0,(function*(e,t=""){var o=yield b("application/json",t);let i=n.SearchInternalWithAuthenticatedCcsUrl();i=i+"?composition="+e.composition+"&search="+e.search+"&internalComposition="+e.internalComposition+"&type="+e.type+"&inpage="+e.inpage+"&page="+e.page;try{const e=yield fetch(i,{method:"GET",headers:o});return e.ok?yield e.json():(console.log("This is the searching internal error",e.status),M(e),[])}catch(e){throw console.log("This is the searching internal error",e),e}}))}(e,t);return yield ai(o)}))}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())}))};function fi(e,t){return hi(this,void 0,void 0,(function*(){let n=!0,o=yield _n(e),i=yield dt(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 Yt(r[e]);n=n&&t}return n}))}function yi(e,t){return hi(this,void 0,void 0,(function*(){let n=yield _n(e),o=yield dt(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 pi{constructor(){this.compositionId=0,this.userId=999,this.sessionId=999,this.accessId=4,this.ofTheCompositionId=0,this.patchObject={}}}class vi{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 gi{constructor(){this.type="",this.search="",this.logicoperator="=",this.index=0,this.composition=!0,this.name="",this.operateon=""}}class Ci{constructor(){this.type="",this.search="",this.composition="",this.internalComposition="",this.userId=999,this.inpage=10,this.page=1}}class mi{constructor(e){this.aiUrl="https://ai.freeschema.com",this.accessToken="",this.enableAi=!0,e&&Object.assign(this,e)}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 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())}))};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())}))},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{}Ii.isUpdated=!1,Ii.isOnlineSync=!1;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())}))};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())}))};const xi=1,Si=2,_i=3,Ri=4,Ei=5,Pi=6,Li=7,Bi=8;class Ui{constructor(){this.conceptId=0,this.connectionTypeId=0,this.connectionType="",this.count=0}}var Gi=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 Fi(e){return Gi(this,void 0,void 0,(function*(){let t={};for(let n=0;n<e.length;n++){let o=yield ue(e[n].connectionTypeId);e[n].connectionType=o.characterValue,t[e[n].conceptId]=e[n]}return t}))}function Di(e){const t=e.split("_");if(3===t.length){let e=new Ui;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 Vi(e){return e.startsWith("the_")?e.slice(4):e}var 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())}))},bi=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(e,t,n){return bi(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 Zt(e[u].ofTheConceptId),y=yield Zt(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 Zt(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){console.log("this is error",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 Zt(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){console.log("this is error",e)}}}return t}))}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())}))};function ji(e,t,n){if(e in t){let o=t[e];console.log("this is the count info",o),o&&(n[o.connectionType+"_count"]=o.count,console.log("this is the data updated",n))}}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())}))};function Wi(e,t="DESC"){return console.log("this is the order",t),"ASC"==t?e.sort((function(e,t){return e.id-t.id})):e.sort((function(e,t){return t.id-e.id})),e}var Ji=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 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,t){return zi(this,void 0,void 0,(function*(){let t=e.outputFormat;e.outputFormat=Pi;let o,i=yield function(e){return ki(this,arguments,void 0,(function*(e,t=""){var o=yield b("application/json",t);const i=n.FreeschemaQueryUrl(),r=JSON.stringify(e);try{const e=yield fetch(i,{method:"POST",headers:o,body:r});return e.ok?yield e.json():(M(e),console.log("This is the freeschema query error",e.status),[])}catch(e){console.log("This is the freeschema query error others",e),function(e,t=""){if(e.status){let n=new $(e.message,!1,e.status,e.stack);throw n.setUrl(t),n}{let n=new $(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=Di(e[n]);t.push(o)}return t}(l);return o=t==Si?yield function(e,t,n,o,i){return Ji(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield qn(e),s=yield Fi(i);c=Wi(c,r);let a=[];a=yield function(e,t){return Oi(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 Zt(e[u].ofTheConceptId),y=yield Zt(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Zt(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){console.log("this is error",e)}}}else if(0!=f.id&&0!=y.id){let n,o=yield Zt(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){console.log("this is error",e)}}}return t}))}(c,a,o),a=yield function(e,t){return Oi(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 Zt(e[u].ofTheConceptId),y=yield Zt(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Zt(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=Vi(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){console.log("this is error",e)}}}else if(0!=f.id&&0!=y.id){let n,o=yield Zt(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=Vi(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){console.log("this is error",e)}}}return t}))}(c,a,o);let l=yield function(e,t,n,o){return Oi(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,r=yield Zt(e[n].ofTheConceptId),f=yield Zt(e[n].toTheConceptId);if(i.includes(e[n].id)&&(o=!0),1==o){if(0!=r.id&&0!=f.id&&f.id in t){let o,i=yield Zt(e[n].typeId),a=null!==(s=null===(c=f.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);try{if(t[e[n].ofTheConceptId]){let c={id:r.id,data:t[e[n].ofTheConceptId],created_on:e[n].entryTimeStamp},s=i.characterValue+"_reverse";Array.isArray(o[a][s])?o[a][s].push(c):s.includes("_s_")?(o[a][s]=[],o[a][s].push(c)):o[a][s]=c}}catch(e){console.log("this is error",e)}}}else if(0!=r.id&&0!=f.id&&r.id in t){let o,i=yield Zt(e[n].typeId),c=null!==(l=null===(a=r.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);let y=!0,p=i.characterValue;""==p&&(p=f.characterValue,y=!0),""==p&&(p=null!==(u=null===(d=null==f?void 0:f.type)||void 0===d?void 0:d.characterValue)&&void 0!==u?u:"");try{null===(h=null==f?void 0:f.type)||void 0===h||h.characterValue;let r=t[e[n].toTheConceptId];if(r){let s={id:f.id,data:t[e[n].toTheConceptId],created_on:e[n].entryTimeStamp};Array.isArray(o[c])?o[c].push(r):Array.isArray(o[c][p])?o[c][i.characterValue].push(s):p.includes("_s_")?(o[c][p]=[],o[c][p].push(s)):o[c][p]=s}}catch(e){console.log("this is error",e)}}}for(let e=0;e<o.length;e++){let n={};n.id=o[e],n.data=t[o[e]],f.push(n)}return f}))}(c,a,[],n,o,s);return l}))}(c,r,a,s,u,d):t==_i?yield function(e,t,n,o,i){return Ji(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield qn(e),s=yield Fi(i);c=Wi(c,r);let a=[];a=yield $i(c,a,o),a=yield function(e,t){return Mi(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 Zt(e[u].ofTheConceptId),y=yield Zt(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Zt(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=Vi(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){console.log("this is error",e)}}}else if(0!=f.id&&0!=y.id){let n,o=yield Zt(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=Vi(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){console.log("this is error",e)}}}return t}))}(c,a,o);let l=yield function(e,t,n){return Mi(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 Zt(e[n].ofTheConceptId),p=yield Zt(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 Zt(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){console.log("this is error",e)}}}else if(0!=y.id&&0!=p.id&&y.id in t){let o,r=yield Zt(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),ji(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,ji(p.id,i,t)}}catch(e){console.log("this is error",e)}}}console.log("this is the main compositions",n);for(let e=0;e<n.length;e++){let o={};console.log("this is the main compositions DATA",t[n[e]]),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==Bi?yield function(e,t,n,o,i){return Ji(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield qn(e),s=yield Fi(i);c=Wi(c,r);let a={};a=yield function(e){return Hi(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 Zt(a.ofTheConceptId),d=yield Zt(a.toTheConceptId),u=yield Zt(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;null===(s=u.characterValue)||void 0===s||s.includes("_s_"),t[h.id]||(t[h.id]={}),t[h.id][y]||(t[h.id][y]={}),t[f.id]||(t[f.id]={}),t[f.id][p]=v}return t}))}(c,a,o),a=yield function(e){return Hi(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 Zt(a.ofTheConceptId),d=yield Zt(a.toTheConceptId),u=yield Zt(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?Vi(p):g;const m=C.includes("_s_"),T=!isNaN(Number(C)),N={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(N):t[h.id][y][e?`${C}_reverse`:C]=N}catch(e){console.error("Error formatting concept data:",e)}}return t}))}(c,a,o);let l=yield function(e,t,n){return Hi(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 Zt(n.ofTheConceptId),l=yield Zt(n.toTheConceptId),d=yield Zt(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};ji(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],ji(y,i,c)}catch(e){console.error("Error processing connection:",e)}}else console.log("This is the error in the source")}for(const e of n){const n=yield Zt(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 Ji(this,void 0,void 0,(function*(){let t=yield qn(e);t=Wi(t);let i=[];i=yield $i(t,i,o),i=yield function(e,t,n){return bi(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 Zt(e[u].ofTheConceptId),y=yield Zt(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 Zt(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=Vi(o));let i={[e]:t},l=o+"_reverse";a.characterValue.includes("_s_")||("string"==typeof n[s]&&(n[s]={}),n[s][l]=i)}catch(e){console.log("this is error",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 Zt(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=Vi(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){console.log("this is error",e)}}}return t}))}(t,i,o);let r=yield function(){return bi(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 Zt(e[n].ofTheConceptId),h=yield Zt(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 Zt(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){console.log("this is error",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 Zt(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){console.log("this is error",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 qi{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=xi,this.name="",this.reverse=!1,this.limit=!1,this.filterAncestor="",this.includeInFilter=!1,this.isOldConnectionType=!1}}var Qi=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 Yi(e,t){return Qi(this,arguments,void 0,(function*(e,t,n=!1){let o=[];if(n){let n=yield En(e),i=yield xn(t);for(let e=0;e<n.length;e++)n[e].typeId==i.id&&o.push(n[e])}else{let n=yield _n(e);for(let e=0;e<n.length;e++)Z.AddConnection(n[e]);let i=yield xn(t);for(let e=0;e<n.length;e++)n[e].typeId==i.id&&o.push(n[e])}return o}))}function Xi(e,t,n){return Qi(this,arguments,void 0,(function*(e,t,n,o=!1){let i=[],r=[];if(i=o?yield Yi(t,n,o):yield Yi(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}))}class Zi{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 Zi.superAdminCache)e>n.expiresAt&&Zi.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=Zi.superAdminCache.get(e);return void 0===t?null:Date.now()>t.expiresAt?(Zi.superAdminCache.delete(e),null):t.value}setSuperAdmin(e,t){Zi.superAdminCache.set(e,{value:t,expiresAt:Date.now()+6e5})}clearSuperAdminCache(){Zi.superAdminCache.clear()}}Zi.superAdminCache=new Map;var er,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(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"}(er||(er={}));var nr=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 or{static initialize(){console.log("AccessControlService initialized.")}static checkAccess(e,t,n){return nr(this,void 0,void 0,(function*(){var o;if(t===er.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 nr(this,void 0,void 0,(function*(){var i,r,c,s,a,l;if(t===er.None)throw new Error("Permission is required");const d=this.permissionSetToString(t),u=new Map;if(!e||0===e.length)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 h=[],f=new Set,y=new Map;let p=null;if(null!=o&&o>0)try{p=yield Zt(o)}catch(e){}let v=0;try{const e=yield function(){return e=this,t=void 0,i=function*(){let e=E();try{var t=yield O("application/x-www-form-urlencoded");const o=yield fetch(n.GetConceptByCharacterAndCategoryUrl(),{method:"POST",headers:t,body:"character_value=the_parent_access_inheritance"});return o.ok?(e=yield o.json(),G.AddConcept(e)):(console.log("This is the concept by category and character error",o.status),M(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&&(v=e.id)}catch(e){}const g=yield te(e),C=new Map;for(const e of g)C.set(e.id,e);const m=new Map;for(const t of e){const e=null!==(i=C.get(t))&&void 0!==i?i:yield Zt(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(p&&p.userId&&p.userId===e.userId){u.set(t,!0);continue}if(n<1e4){u.set(t,!0);continue}let a=0;if(o>0){let e=m.get(o);if(!e)try{e=yield Zt(o),m.set(o,e)}catch(e){}e&&(a=null!==(s=e.accessId)&&void 0!==s?s:0)}h.push({conceptId:t,accessId:n,typeAccessId:a}),n>0&&(f.add(n),y.set(n,t)),a>0&&f.add(a)}if(0===h.length)return u;const T=yield this.resolveBulkInheritanceGraph(f,v,y),N=[],w=new Set;for(const e of T.values())for(const t of e)w.has(t)||(w.add(t),N.push(t));const I=yield this.resolveSubjects(o),A=yield this.resolveBulkDecisions(N,d,I);for(const e of h){const t=null!==(a=T.get(e.accessId))&&void 0!==a?a:[e.accessId],n=e.typeAccessId>0?null!==(l=T.get(e.typeAccessId))&&void 0!==l?l:[e.typeAccessId]:[],o=this.hasAnyGrant(t,n,I,A);u.set(e.conceptId,o)}return u}))}static getConceptIdsWithPermission(e,t,n){return nr(this,void 0,void 0,(function*(){if(e===er.None)throw new Error("Permission is required");if(!t||0===t.length)return[];const o=yield this.checkAccessBulk(t,e,n);return t.filter((e=>!0===o.get(e)))}))}static resolveBulkInheritanceGraph(e,t,n){return nr(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 yi(t,["the_parent_access_inheritance"]);if(n&&n.length>0){const o=yield Hn(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 _n(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 Zt(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 nr(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 nr(this,void 0,void 0,(function*(){const t=[null];if(null!=e&&e>0){t.push(e);try{const n=yield yi(e,["the_entity_s_group"]);if(n&&n.length>0){const e=yield Hn(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 nr(this,void 0,void 0,(function*(){var o;if(t===er.None)throw new Error("Permission is required");try{const i=null!==(o=(yield Zt(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 nr(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 nr(this,void 0,void 0,(function*(){var o;try{const i=null!==(o=(yield Zt(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 nr(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 nr(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 nr(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 nr(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 nr(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 nr(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 nr(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 nr(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 nr(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 nr(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 nr(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 nr(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 nr(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&er.Read&&t.push("read"),e&er.Write&&t.push("write"),e&er.Execute&&t.push("execute"),e&er.Delete&&t.push("delete"),t}(e)[0]||"read"}static clearCache(){this.cacheService.clear()}static clearSuperAdminCache(){this.cacheService.clearSuperAdminCache()}}or.cacheService=new Zi,or.apiClient=new class{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 tr(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 tr(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 tr(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 tr(this,void 0,void 0,(function*(){return this.postAsync("access/assign",e)}))}checkAccessAsync(e){return tr(this,void 0,void 0,(function*(){return this.postAsync("access/check",e)}))}revokeAccessAsync(e){return tr(this,void 0,void 0,(function*(){return this.deleteAsync("access/revoke",e)}))}assignAccessBulkAsync(e){return tr(this,void 0,void 0,(function*(){return this.postAsync("access/assign/bulk",e)}))}revokeAccessBulkAsync(e){return tr(this,void 0,void 0,(function*(){return this.deleteAsync("access/revoke/bulk",e)}))}checkAccessBulkAsync(e){return tr(this,void 0,void 0,(function*(){return this.postAsync("access/check/bulk",e)}))}getAccessByIdAsync(e){return tr(this,void 0,void 0,(function*(){return this.getAsync(`access/${e}`)}))}setAccessInheritanceAsync(e){return tr(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance",e)}))}getAccessInheritanceStatusAsync(e){return tr(this,arguments,void 0,(function*(e,t=999){return this.getAsync(`access/inheritance/status?accessId=${e}&connectionTypeId=${t}`)}))}assignSuperAdminAccessAsync(e){return tr(this,void 0,void 0,(function*(){return this.postAsync("access/super-admin",e)}))}revokeSuperAdminAccessAsync(e){return tr(this,void 0,void 0,(function*(){return this.deleteAsync("access/super-admin",e)}))}checkSuperAdminStatusAsync(e){return tr(this,void 0,void 0,(function*(){return this.getAsync(`access/super-admin?accessId=${e}`)}))}setParentAccessInheritanceAsync(e){return tr(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent",e)}))}removeParentAccessInheritanceAsync(e,t){return tr(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 tr(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 tr(this,void 0,void 0,(function*(){return this.getAsync(`access/inheritance/parent?accessId=${e}`)}))}setParentAccessInheritanceByConceptAsync(e){return tr(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent/concept",e)}))}setParentAccessInheritanceBulkByConceptAsync(e){return tr(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent/concept/bulk",e)}))}removeParentAccessInheritanceByConceptAsync(e,t){return tr(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 tr(this,void 0,void 0,(function*(){return this.deleteAsync("access/inheritance/parent/concept/bulk",e)}))}hasParentAccessInheritanceByConceptAsync(e,t){return tr(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 tr(this,void 0,void 0,(function*(){return this.getAsync(`access/inheritance/parent/concept?childConceptId=${e}`)}))}assignSuperAdminByConceptAsync(e){return tr(this,void 0,void 0,(function*(){return this.postAsync("access/super-admin/concept",e)}))}revokeSuperAdminByConceptAsync(e){return tr(this,void 0,void 0,(function*(){return this.deleteAsync("access/super-admin/concept",e)}))}checkSuperAdminByConceptAsync(e){return tr(this,void 0,void 0,(function*(){return this.getAsync(`access/super-admin/concept?conceptId=${e}`)}))}setAccessInheritanceByConceptAsync(e){return tr(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/concept",e)}))}getAccessInheritanceStatusByConceptAsync(e){return tr(this,arguments,void 0,(function*(e,t=999){return this.getAsync(`access/inheritance/concept/status?conceptId=${e}&connectionTypeId=${t}`)}))}},or.initialize();var ir=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 rr{constructor(){this.actions={concepts:[],connections:[]},this.success=!0,this.transactionId=Math.random().toString().substring(5)}initialize(){return ir(this,void 0,void 0,(function*(){yield it.initializeTransaction(this.transactionId)}))}markAction(){return ir(this,void 0,void 0,(function*(){yield it.markTransactionActions(this.transactionId,this.actions)}))}rollbackTransaction(){return ir(this,void 0,void 0,(function*(){this.success=!1,this.actions={concepts:[],connections:[]},yield it.rollbackTransaction(this.transactionId,this.actions)}))}commitTransaction(){return ir(this,void 0,void 0,(function*(){if(!this.success)throw Error("Query Transaction Expired");yield it.SyncDataOnline(this.transactionId),this.actions={concepts:[],connections:[]},this.success=!1}))}MakeTheInstanceConcept(e,t){return ir(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 St(e,t,n,o,i,r,c,this.actions);return yield this.markAction(),s}catch(e){throw console.log(e),this.success=!1,e}}))}CreateConnection(e,t,n){return ir(this,void 0,void 0,(function*(){try{if(!this.success)throw Error("Query Transaction Expired");const o=yield Wt(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 ir(this,void 0,void 0,(function*(){try{if(!this.success)throw Error("Query Transaction Expired");const i=yield Cn(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 ir(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 Ht(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}}))}}function cr(e=""){o.BearerAccessToken=e}function sr(e="",t="",i="CCSApp",c){const s=c||new mi;if(n.BASE_URL=e,n.AI_URL=s.aiUrl,t&&(n.NODE_URL=t),console.log("This is the base url",n.BASE_URL),s.hasOAuthCredentials()){const e=s.applicationName||i;o.setOAuthCredentials(s.clientId,s.clientSecret,e),r(s.clientId,s.clientSecret,e,!0)}else s.hasAccessToken()&&(o.BearerAccessToken=s.accessToken);(function(){return Ai(this,void 0,void 0,(function*(){return yield new g(!0),yield function(){return wi(this,void 0,void 0,(function*(){}))}(),!0}))})().then((()=>{const e=(new Date).getTime();(function(){return F(this,void 0,void 0,(function*(){(new Date).getTime();var e=yield N();if(Array.isArray(e))for(var t=0;t<e.length;t++){let n=e[t];G.AddConceptToMemory(n)}(new Date).getTime()}))})().then((()=>{I.isDataLoaded=!0,I.isCharacterLoaded=!0,I.isTypeLoaded=!0;let t=(new Date).getTime()-e;console.log("The time taken to prepare concept data is ",t)})),function(){return Ni(this,void 0,void 0,(function*(){var e=yield w();if(Array.isArray(e))for(var t=0;t<e.length;t++){let n=e[t];je.AddConceptToMemory(n)}}))}().then((()=>{I.isLocalDataLoaded=!0,I.isLocalTypeLoaded=!0,I.isLocalCharacterLoaded=!0;let t=(new Date).getTime()-e;console.log("The time taken to prepare local concept ",t)})),function(){return Ti(this,void 0,void 0,(function*(){!function(){Ti(this,void 0,void 0,(function*(){var e=yield w();if(Array.isArray(e))for(var t=0;t<e.length;t++)We.AddConnection(e[t])}))}()}))}().then((()=>{I.isLocalConnectionLoaded=!0})),function(){return Ti(this,void 0,void 0,(function*(){!function(){Ti(this,void 0,void 0,(function*(){var e=yield N();if(Array.isArray(e))for(var t=0;t<e.length;t++)Z.AddConnectionToMemory(e[t])}))}()}))}().then((()=>{I.isConnectionLoaded=!0,I.isConnectionTypeLoaded=!0;let t=(new Date).getTime()-e;console.log("The time taken to prepare connections ",t)}))}))}var ar=exports;for(var lr in t)ar[lr]=t[lr];t.__esModule&&Object.defineProperty(ar,"__esModule",{value:!0})})();
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:()=>Di,AccessControlService:()=>Ei,AddGhostConcept:()=>qo,AddGhostConnection:()=>Ko,BaseUrl:()=>n,BinaryTree:()=>_,CCSConfig:()=>mi,Composition:()=>mo,CompositionBinaryTree:()=>po,CompositionNode:()=>fo,Concept:()=>R,ConceptsData:()=>G,Connection:()=>J,ConnectionData:()=>Z,CreateComposition:()=>Rt,CreateConnection:()=>Wt,CreateConnectionBetweenTwoConcepts:()=>tn,CreateConnectionBetweenTwoConceptsGeneral:()=>on,CreateDefaultConcept:()=>E,CreateDefaultLConcept:()=>$e,CreateSession:()=>Uo,CreateSessionVisit:()=>Fo,CreateTheCompositionLocal:()=>Ot,CreateTheCompositionWithCache:()=>No,CreateTheConnection:()=>rt,CreateTheConnectionGeneral:()=>Ht,CreateTheConnectionLocal:()=>Pt,DATAID:()=>Li,DATAIDDATE:()=>Gi,DATAV2:()=>Vi,DeleteConceptById:()=>Dn,DeleteConnectionById:()=>Yt,DeleteConnectionByTypeBulk:()=>fi,FilterSearch:()=>gi,FormatFromConnections:()=>ei,FreeSchemaResponse:()=>$,FreeschemaQuery:()=>tr,GetAllConnectionsOfComposition:()=>fe,GetAllConnectionsOfCompositionBulk:()=>ae,GetAllTheConnectionsByTypeAndOfTheConcept:()=>or,GetComposition:()=>ve,GetCompositionBulk:()=>Jn,GetCompositionBulkWithDataId:()=>zn,GetCompositionFromConnectionsWithDataId:()=>qn,GetCompositionFromConnectionsWithDataIdInObject:()=>Qn,GetCompositionList:()=>Pe,GetCompositionListLocal:()=>Ze,GetCompositionListLocalWithId:()=>et,GetCompositionListWithId:()=>Be,GetCompositionLocal:()=>ze,GetCompositionLocalWithId:()=>qe,GetCompositionWithAllIds:()=>ge,GetCompositionWithCache:()=>Ro,GetCompositionWithDataIdBulk:()=>Bo,GetCompositionWithDataIdWithCache:()=>Po,GetCompositionWithId:()=>we,GetCompositionWithIdFromMemory:()=>me,GetCompositionWithIdFromMemoryFromConnections:()=>Ne,GetConceptBulk:()=>te,GetConceptByCharacter:()=>Re,GetConceptByCharacterAndCategoryDirectApi:()=>Nn,GetConceptByCharacterAndType:()=>lt,GetConceptByTypeBulk:()=>dt,GetConnectionBulk:()=>Hn,GetConnectionById:()=>Kt,GetConnectionByTypeBulk:()=>yi,GetConnectionOfTheConcept:()=>Mt,GetLink:()=>cn,GetLinkRaw:()=>sn,GetLinkerConnectionFromConcepts:()=>Bn,GetLinkerConnectionToConcepts:()=>Ln,GetRelation:()=>Oo,GetRelationRaw:()=>$o,GetRequestHeader:()=>V,GetRequestHeaderWithAuthorization:()=>O,GetTheConcept:()=>Zt,GetUserGhostConnectionId:()=>zo,GetUserGhostId:()=>Jo,GiveConnection:()=>ir,HandleHttpError:()=>M,HttpResponse:()=>l,JUSTDATA:()=>Ui,LConcept:()=>Oe,LConnection:()=>Et,LISTNORMAL:()=>bi,LoginToBackend:()=>eo,MakeTheInstanceConcept:()=>St,MakeTheInstanceConceptLocal:()=>bt,MakeTheTimestamp:()=>$n,MakeTheTypeConcept:()=>Cn,MakeTheTypeConceptApi:()=>xn,NORMAL:()=>Bi,PatcherStructure:()=>pi,PermissionSet:()=>xi,RAW:()=>Fi,RecursiveSearchApi:()=>Xn,SchemaQueryListener:()=>er,SearchAllConcepts:()=>ko,SearchLinkInternal:()=>ui,SearchLinkMultipleAll:()=>Zo,SearchLinkMultipleApi:()=>Yo,SearchQuery:()=>Mn,SearchStructure:()=>Ci,SearchWithLinker:()=>So,SessionData:()=>vi,Signin:()=>io,Signup:()=>no,SplitStrings:()=>D,SyncData:()=>it,TokenRefreshError:()=>a,TokenStorage:()=>o,Transaction:()=>cr,TrashTheConcept:()=>Vn,UpdateComposition:()=>wo,UpdateCompositionLocal:()=>ri,UserBinaryTree:()=>Ho,ViewInternalData:()=>ai,convertFromLConceptToConcept:()=>ni,deleteWithRetry:()=>p,getFromDatabaseWithType:()=>T,getFromDatabaseWithTypeOld:()=>N,getOAuthToken:()=>r,getWithRetry:()=>f,init:()=>ar,patchWithRetry:()=>v,postWithRetry:()=>h,putWithRetry:()=>y,recursiveFetch:()=>Ae,recursiveFetchNew:()=>go,refreshOAuthToken:()=>c,requestWithRetry:()=>u,storeToDatabase:()=>m,updateAccessToken:()=>sr});class n{static GetConceptUrl(){return this.BASE_URL+"/api/getConcept"}static GetConnectionUrl(){return this.BASE_URL+"/api/get-connection-by-id"}static GetConceptBulkUrl(){return this.BASE_URL+"/api/get_concept_bulk"}static GetConnectionBulkUrl(){return this.BASE_URL+"/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 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 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.AI_URL="https://ai.freeschema.com",n.MQTT_URL="192.168.1.249",n.NODE_URL="http://localhost:5001/";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());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(console.log("Received 401 Unauthorized, attempting token refresh..."),yield d()){console.log("Token refreshed successfully, retrying request..."),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)throw e;console.error(`Request failed (attempt ${n+1}/${r+1}):`,e)}throw new Error("Request failed after all retry attempts")}))}function h(e,t,n){return s(this,void 0,void 0,(function*(){return u("POST",e,t,n)}))}function f(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 y(e,t,n){return s(this,void 0,void 0,(function*(){return u("PUT",e,t,n)}))}function p(e,t){return s(this,void 0,void 0,(function*(){return u("DELETE",e,t)}))}function v(e,t,n){return s(this,void 0,void 0,(function*(){return u("PATCH",e,t,n)}))}class g{constructor(e){this.id=1,this.isOnlineSync=!1,this.isOnlineSync=e}}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){}function T(e,t,n){return C(this,void 0,void 0,(function*(){}))}function N(e){return C(this,void 0,void 0,(function*(){}))}function I(e){return C(this,void 0,void 0,(function*(){}))}class w{}w.isTypeLoaded=!1,w.isCharacterLoaded=!1,w.isDataLoaded=!1,w.isLocalDataLoaded=!1,w.isLocalCharacterLoaded=!1,w.isLocalTypeLoaded=!1,w.isConnectionLoaded=!1,w.isConnectionTypeLoaded=!1,w.isLocalConnectionLoaded=!1;class A{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(e.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 k=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 x{static waitForDataToLoad(){return k(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(w.isCharacterLoaded)return e("done");setTimeout(x.checkFlag,1e3,e)}static addNodeToTree(e){return k(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 k(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 A(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 k(this,void 0,void 0,(function*(){return this.characterRoot?this.characterRoot.getFromNodeWithCharacterAndType(e,t,this.characterRoot):this.characterRoot}))}static getCharacterAndCategoryFromTree(e,t){return k(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))}}x.characterRoot=null;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 _{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 S(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(w.isDataLoaded)return e("done");setTimeout(_.checkFlag,1e3,e)}static addConceptToTree(e){var t=new A(e.id,e,null,null),n=new A(e.characterValue,e,null,null);x.addNodeToTree(n),this.addNodeToTree(t)}static getNodeFromTree(e){return S(this,void 0,void 0,(function*(){return this.root?this.root.getFromNode(e,this.root):null}))}static removeNodeFromTree(e){return S(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}}_.root=null;class R{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 E(){let e=P(new Date),t=P(new Date);return new R(0,0,0,0,0,0,0,0,"0",0,0,0,0,0,0,!1,e,t)}function P(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 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 addNodeToTree(e){return B(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 A(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 B(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(w.isTypeLoaded)return e("done");setTimeout(L.checkFlag,1e3,e)}static getTypeVariantsFromTreeWithUserId(e,t){return B(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 B(this,void 0,void 0,(function*(){let n=E();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}}L.typeRoot=null;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 G{constructor(){this.name="conceptsArray"}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){this.NPC.includes(e)||(this.NPC.length>10&&(this.NPC=[]),this.NPC.push(e))}static GetNpc(e){return!!this.NPC.includes(e)}static AddConceptToStorage(e){e.id}static AddConcept(e){e.id>0&&(_.addConceptToTree(e),L.addConceptToTree(e),x.addConceptToTree(e))}static AddConceptToMemory(e){e.id>0&&(_.addConceptToTree(e),L.addConceptToTree(e),x.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);_.removeNodeFromTree(e.id),e.id}static GetConcept(e){return U(this,void 0,void 0,(function*(){var t=E(),n=yield _.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConceptByCharacter(e){return U(this,void 0,void 0,(function*(){var t=E(),n=x.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterUpdated(e){return U(this,void 0,void 0,(function*(){var t=E(),n=x.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterAndTypeLocal(e,t){return U(this,void 0,void 0,(function*(){return E(),yield L.getTypeVariantsWithCharacterValue(e,t)}))}static GetConceptByCharacterAndCategoryLocal(e,t){return U(this,void 0,void 0,(function*(){var n=E(),o=yield x.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 U(this,void 0,void 0,(function*(){let n=[];return n=yield L.getTypeVariantsFromTreeWithUserId(e,t),n}))}static GetBinaryCharacterTree(){return x.characterRoot}getName(){return this.name}}G.conceptsArray=[],G.NPC=[],G.conceptDictionary=[];var F=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 D(e){const t=e.lastIndexOf("_");let n=[];return n=t>0?[e.substring(0,t),e.substring(t+1,e.length)]:[e],n}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())}))};function V(){return b(this,arguments,void 0,(function*(e="application/json",t="application/json"){if(o.isTokenExpiredOrNearExpiry()&&o.hasOAuthCredentials()){console.log("Token expired or near expiry, refreshing...");const e=yield r(o.CLIENT_ID,o.CLIENT_SECRET,o.APPLICATION_NAME,!0);e.success?console.log("Token refreshed successfully"):console.error("Failed to refresh token:",e.error)}return{"Content-Type":e,Authorization:"Bearer "+o.BearerAccessToken,Accept:t}}))}function O(){return b(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()){console.log("Token expired or near expiry, refreshing...");const e=yield r(o.CLIENT_ID,o.CLIENT_SECRET,o.APPLICATION_NAME,!0);e.success?console.log("Token refreshed successfully"):console.error("Failed to refresh token:",e.error)}return{"Content-Type":e,Authorization:"Bearer "+o.BearerAccessToken,Accept:n}}))}class ${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 M(e){if(e.status>=400){let t=new $(e.statusText,!1,e.status,"");throw t.setUrl(e.url),t}}function j(e){if(401==e.status){let t=new $(e.body,!1,e.status,"");throw t.setUrl(e.headers.url),t}}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 W(e,t){return H(this,void 0,void 0,(function*(){try{var o=new URLSearchParams;o.append("type",e),o.append("user_id",t.toString());var i=yield V("application/x-www-form-urlencoded");const c=yield fetch(n.GetAllConceptsByTypeUrl(),{method:"POST",headers:i,body:o});if(c.ok){const e=yield c.json();for(var r=0;r<e.length;r++)G.AddConcept(e[r])}console.log("GetAllConceptsByType error",c.status),M(c)}catch(e){throw e instanceof Error?console.log("GetAllConceptsByType error message: ",e.message):console.log("GetAllConceptsByType unexpected error: ",e),e}}))}class J{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=E(),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=P(new Date),this.terminationDateTime=new Date,this.localSyncTime=new Date}}class z{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(e.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 q=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 K{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 z(e.id,e,null,null);this.addNodeToTree(t)}static waitForDataToLoad(){return q(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(w.isConnectionLoaded)return e("done");setTimeout(K.checkFlag,1e3,e)}static removeNodeFromTree(e){return q(this,void 0,void 0,(function*(){this.connectionroot&&(this.connectionroot=this.connectionroot.removeNode(this.connectionroot,e))}))}static getNodeFromTree(e){return q(this,void 0,void 0,(function*(){return this.connectionroot?this.connectionroot.getFromNode(e,this.connectionroot):this.connectionroot}))}}K.connectionroot=null;var Q=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 Y{static addNodeToTree(e){return Q(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 Q(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(w.isConnectionTypeLoaded)return e("done");setTimeout(Y.checkFlag,1e3,e)}static addConnectionToTree(e){if(0!=e.typeId){var t=new z(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 Q(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 Q(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}))}}Y.connectionTypeRoot=null;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())}))};class Z{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){}static AddConnection(e){e.isTemp||(K.addConnectionToTree(e),Y.addConnectionToTree(e))}static AddConnectionToMemory(e){e.isTemp||(K.addConnectionToTree(e),Y.addConnectionToTree(e))}static AddToDictionary(e){this.connectionDictionary[e.id]=e}static RemoveConnection(e){0!=e.id&&(e.id,K.removeNodeFromTree(e.id),Y.removeTypeConcept(e.typeId,e.id))}static GetConnectionTree(){return K.connectionroot}static GetConnectionTypeTree(){return Y.connectionTypeRoot}static GetConnection(e){return X(this,void 0,void 0,(function*(){var t=new J(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),n=yield K.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConnectionsOfCompositionLocal(e){return X(this,void 0,void 0,(function*(){var t=[],n=yield Y.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}}Z.connectionArray=[],Z.connectionDictionary=[];var ee=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 te(e){return ee(this,void 0,void 0,(function*(){let t=[];try{var o=[];for(let n=0;n<e.length;n++){let i=yield G.GetConcept(e[n]);0==i.id?o.push(e[n]):t.push(i)}if(0==o.length)return t;{var i=yield V();const e=n.GetConceptBulkUrl(),r=JSON.stringify(o);console.log("[DEBUG] GetConceptBulk request:",{url:e,method:"POST",headers:i,bodyLength:o.length,conceptIds:o.slice(0,10)});const c=yield fetch(e,{method:"POST",headers:i,body:r});if(console.log("[DEBUG] GetConceptBulk response:",{status:c.status,ok:c.ok,statusText:c.statusText}),c.ok){let e=yield c.json();if(e.length>0)for(let n=0;n<e.length;n++){let o=e[n];t.push(o),G.AddConcept(o)}}else console.log("Get Concept Bulk error",c.status),M(c);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 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 oe(){return ne(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 te(t)}}))}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())}))};function re(){return ie(this,arguments,void 0,(function*(e=[]){var t=[];for(let o=0;o<e.length;o++){var n=yield Z.GetConnectionsOfCompositionLocal(e[o]);t.push(...n)}return t}))}function ce(e=[],t=[]){for(let n=0;n<t.length;n++)Array.isArray(e)&&(e.find((e=>e.id===t[n].id))||Z.RemoveConnection(t[n]))}var se=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(){return se(this,arguments,void 0,(function*(e=[]){var t=[];if(e.length<=0)return t;var o=yield re(e),i=yield function(){return se(this,arguments,void 0,(function*(e=[]){var t=[];try{var o=yield V();const r=yield fetch(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++)Z.AddConnection(e[i]),t.push(e[i])}else console.log("Get all connections of composition bulk error message: ","Cannot get response"),M(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 ce(t=i,o),yield oe(t),t}))}var le=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 de=new Map;function ue(e){return le(this,void 0,void 0,(function*(){let t=E();if(de.has(e))return de.get(e)||t;const o=(()=>le(this,void 0,void 0,(function*(){try{var o=yield G.GetConcept(e);let r=G.GetNpc(e);if(0!=o.id||r)return o;{var i=yield V("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 fetch(o,{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?G.AddConcept(t):G.AddNpc(e)):(console.log("Get the concept error",r.status,e),M(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{de.delete(e)}})))();return de.set(e,o),o}))}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(e){return he(this,void 0,void 0,(function*(){var t=[];if(0==(t=yield Z.GetConnectionsOfCompositionLocal(e)).length)t=yield ye(e);else{var n=yield ye(e);ce(n,t),t=n}return t}))}function ye(e){return he(this,void 0,void 0,(function*(){var t=[];try{var o=yield V("application/x-www-form-urlencoded");const r=yield fetch(n.GetAllConnectionsOfCompositionUrl(),{method:"POST",headers:o,body:`composition_id=${e}`});if(!r.ok)throw M(r),new Error(`Error! status: ${r.status}`);const c=yield r.json();for(var i=0;i<c.length;i++)Z.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 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(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield fe(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 ge(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield fe(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield ke(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 Ce(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield Z.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 me(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield Z.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 Te(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield Z.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 Ne(e,t){return pe(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 G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 Ie(e,t){return pe(this,arguments,void 0,(function*(e,t,n=[]){var o,i,r={},c=yield G.GetConcept(e);0==c.id&&null!=e&&null!=e&&(c=yield ue(e));var s=yield Ae(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 we(e){return pe(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield fe(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield G.GetConcept(e);0==s.id&&null!=e&&null!=e&&(s=yield ue(e));var a=yield Ae(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 Ae(e,t,n){return pe(this,arguments,void 0,(function*(e,t,n,o=[]){var i,r,c,s={},a=[];if(0==e)return null;var l=yield G.GetConcept(e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield ue(e)),0!=l.id&&null==l.type){var d=l.typeId,u=yield G.GetConcept(d);l.type=u,null==u&&null!=d&&null!=d&&(u=yield ue(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 G.GetConcept(f);null!=y&&0!=y.id||null==f||null==f||(y=yield ue(f)),y&&null==(null==y?void 0:y.type)&&(d=y.typeId,u=yield G.GetConcept(d),y.type=u,null==u&&null!=d&&null!=d&&(u=yield ue(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 Ae(f,t,n,o);s[p]=e}}else{const e=yield Ae(f,t,n,o);a[p]=e,s=a}}return s}))}function ke(e,t,n){return pe(this,arguments,void 0,(function*(e,t,n,o=[]){var i,r,c,s={},a=[];if(0==e)return null;var l=yield G.GetConcept(e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield ue(e)),0!=l.id&&null==l.type){var d=l.typeId,u=yield G.GetConcept(d);l.type=u,null==u&&null!=d&&null!=d&&(u=yield ue(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 G.GetConcept(f);null!=y&&0!=y.id||null==f||null==f||(y=yield ue(f)),y&&null==(null==y?void 0:y.type)&&(d=y.typeId,u=yield G.GetConcept(d),y.type=u,null==u&&null!=d&&null!=d&&(u=yield ue(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 ke(f,t,n);s[p]=e}}else{const e=yield ke(f,t,n);a[p]=e,s=a}}return s}))}var xe=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 Se(e){return xe(this,void 0,void 0,(function*(){let t=E();try{var o=yield V("application/x-www-form-urlencoded");const i=yield fetch(n.GetConceptByCharacterValueUrl(),{method:"POST",headers:o,body:`character_value=${e}`});return i.ok?(t=yield i.json(),t.id>0&&G.AddConcept(t)):(console.log("Error in Getting concept by character value Error",i.status),M(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 _e=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 Re(e){return _e(this,void 0,void 0,(function*(){var t=yield G.GetConceptByCharacter(e),n=`${e}`;return null!=t&&0!=(null==t?void 0:t.id)||!n||(yield Se(e),t=yield G.GetConceptByCharacter(e)),t}))}var Ee=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 Pe(e,t){return Ee(this,arguments,void 0,(function*(e,t,n=10,o=1){var i=yield Re(e),r=[];if(i){yield W(e,t);for(var c=yield G.GetConceptsByTypeIdAndUser(i.id,t),s=n*(o-1),a=[],l=s;l<s+n;l++)c[l]&&a.push(c[l].id);for(yield ae(a),l=s;l<s+n;l++)if(c[l]){var d=yield Ce(c[l].id);r.push(d)}}return r}))}function Be(e,t){return Ee(this,arguments,void 0,(function*(e,t,n=10,o=1){var i=yield Re(e),r=[];if(i){yield W(e,t);for(var c=yield G.GetConceptsByTypeIdAndUser(i.id,t),s=n*(o-1),a=[],l=s;l<s+n;l++)c[l]&&a.push(c[l].id);for(yield ae(a),l=s;l<s+n;l++)if(c[l]){var d=yield me(c[l].id);r.push(d)}}return r}))}class Le{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(e.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 Ue=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 Ge{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 Le(e.id,e,null,null);new Le(e.characterValue,e,null,null),this.addNodeToTree(t)}static waitForDataToLoad(){return Ue(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(w.isLocalDataLoaded)return e("done");setTimeout(Ge.checkFlag,1e3,e)}static getNodeFromTree(e){return Ue(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 Ue(this,void 0,void 0,(function*(){this.root&&(this.root=this.root.removeNode(this.root,e))}))}}Ge.root=null;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())}))};class De{static waitForDataToLoad(){return Fe(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(w.isLocalCharacterLoaded)return e("done");setTimeout(De.checkFlag,1e3,e)}static addNodeToTree(e){return Fe(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 Le(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 Fe(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))}}De.LocalCharacterRoot=null;var be=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 Ve{static addNodeToTree(e){return be(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 Le(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 be(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(w.isLocalTypeLoaded)return e("done");setTimeout(Ve.checkFlag,1e3,e)}static getTypeVariantsFromTreeWithUserId(e,t){return be(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}))}}Ve.LocalTypeRoot=null;class Oe{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 $e(){let e=new Date,t=new Date;return new Oe(0,0,0,0,0,"0","0",!1,e,t,0)}var Me=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 je{constructor(){this.name="conceptsArray"}static AddConcept(e){e.id>0&&(Ge.addConceptToTree(e),De.addConceptToTree(e),Ve.addConceptToTree(e),this.localconceptsArray.push(e))}static AddConceptToMemory(e){e.id>0&&(Ge.addConceptToTree(e),De.addConceptToTree(e),Ve.addConceptToTree(e))}static GetConcept(e){return Me(this,void 0,void 0,(function*(){var t=$e(),n=yield Ge.getNodeFromTree(e);if(null==n?void 0:n.value){var o=n.value;o&&(t=o)}return t}))}static GetConceptByCharacter(e){return Me(this,void 0,void 0,(function*(){var t=$e(),n=De.getNodeFromTree(e);return n&&(t=n.value),t}))}static GetConceptByCharacterAndTypeLocal(e,t){return Me(this,void 0,void 0,(function*(){var n=$e(),o=yield De.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 Me(this,void 0,void 0,(function*(){let n=[];return n=yield Ve.getTypeVariantsFromTreeWithUserId(e,t),n}))}getName(){return this.name}}je.localconceptsArray=[];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())}))};class We{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,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 He(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(w.isLocalConnectionLoaded)return e("done");setTimeout(We.checkFlag,1e3,e)}static GetConnectionsOfCompositionLocal(e){return He(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}}We.connectionArray=[],We.connectionDictionary=[];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 ze(e){return Je(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield We.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield je.GetConcept(e),a=yield Ke(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:"top"]=a,i}))}function qe(e){return Je(this,void 0,void 0,(function*(){var t,n,o,i={};o=yield We.GetConnectionsOfCompositionLocal(e);for(var r=[],c=0;c<o.length;c++)r.includes(o[c].ofTheConceptId)||r.push(o[c].ofTheConceptId);var s=yield je.GetConcept(e);if(0!=s.id){var a=yield Ke(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:"top"]=a;var l={}}return l.data=i,l.id=e,l}))}function Ke(e,t,n){return Je(this,arguments,void 0,(function*(e,t,n,o=[]){var i,r,c,s={},a=[],l=yield je.GetConcept(e);if(0!=l.id&&null==l.type){var d=l.typeId,u=yield je.GetConcept(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 je.GetConcept(f);0!=y.id&&null==(null==y?void 0:y.type)&&(d=y.typeId,u=yield je.GetConcept(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:"top").replace("the_","");if(isNaN(Number(p))){if(p){const e=yield Ke(f,t,n);s[p]=e}}else{const e=yield Ke(f,t,n);a[p]=e,s=a}}return s}))}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())}))};function Ye(e){return Qe(this,void 0,void 0,(function*(){return yield je.GetConceptByCharacter(e)}))}var Xe=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 Ze(e,t){return Xe(this,void 0,void 0,(function*(){var n=yield Ye(e),o=[];if(n)for(var i=yield je.GetConceptsByTypeIdAndUser(n.id,t),r=0;r<i.length;r++){var c=yield ze(i[r].id);o.push(c)}return o}))}function et(e,t){return Xe(this,void 0,void 0,(function*(){var n=yield Ye(e),o=[];if(n)for(var i=yield je.GetConceptsByTypeIdAndUser(n.id,t),r=0;r<i.length;r++){var c=yield qe(i[r].id);o.push(c)}return o}))}function tt(e){return t=this,o=void 0,r=function*(){let t=E();try{var o=yield V();const i=yield h(n.CreateTheConceptUrl(),o,JSON.stringify(e));if(!i.ok)throw j(i),new Error(`Error! status: ${i.status}`);return t=yield i.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 nt(e){return t=this,o=void 0,r=function*(){let t=new J(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);try{var o=yield V(),i=JSON.stringify(e);const r=yield h(n.CreateTheConnectionUrl(),o,i);return r.ok?yield r.json():(console.log("Create the connection error message: ",r),j(r)),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 ot=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 it{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 ot(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)),this.transactionCollections=this.transactionCollections.filter((e=>new Date(e.createdDate).getTime()>(new Date).getTime()-6048e5)),!o)return;t=o.data.concepts.slice(),n=o.data.connections.slice(),t.length>0&&(yield tt(t)),n.length>0&&(yield nt(n))}else{for(let e=0;e<this.conceptsSyncArray.length;e++)G.AddConcept(this.conceptsSyncArray[e]);for(let e=0;e<this.connectionSyncArray.length;e++)Z.AddConnection(this.connectionSyncArray[e]);this.conceptsSyncArray.length>0&&(t=this.conceptsSyncArray.slice(),this.conceptsSyncArray=[],yield tt(t)),this.connectionSyncArray.length>0&&(n=this.connectionSyncArray.slice(),this.connectionSyncArray=[],yield nt(n))}return"done"}catch(e){throw e}}))}static initializeTransaction(e){return ot(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 ot(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 ot(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 ot(this,void 0,void 0,(function*(){if(this.conceptsSyncArray.length>0){for(let e=0;e<this.conceptsSyncArray.length;e++)this.conceptsSyncArray[e];this.conceptsSyncArray=[]}if(this.connectionSyncArray.length>0){for(let e=0;e<this.connectionSyncArray.length;e++)this.connectionSyncArray[e];this.connectionSyncArray=[]}return"done"}))}}function rt(e,t,n,o,i,r,c){var s=new J(0,e,n,t,o,t,i,t,1,t,0,t,4,t,r,c);return e==n?(s.ofTheConceptId=0,s.toTheConceptId=1,s):(s.isTemp=!0,s.id=Math.floor(1e8*Math.random()),it.AddConnection(s),s)}it.conceptsSyncArray=[],it.connectionSyncArray=[],it.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())}))},st=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 at=new Map;function lt(e,t){return st(this,void 0,void 0,(function*(){let o=yield G.GetConceptByCharacterAndTypeLocal(e,t),i=e+t;if(at.has(i))return at.get(i)||o;const r=(()=>st(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 V();const i=yield fetch(n.GetConceptByCharacterAndTypeUrl(),{method:"POST",headers:s,body:c});if(i.ok){let e=yield i.json();o=e,G.AddConcept(o)}else console.log("This is the concept by type and character error",i.status),M(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{at.delete(i)}})))();return at.set(i,r),r}))}function dt(e){return st(this,void 0,void 0,(function*(){let t=[],o=JSON.stringify(e);var i=yield V();const r=yield fetch(n.GetConceptConnectionByType(),{method:"POST",headers:i,body:o});if(r.ok){let e=yield r.json();t=yield te(e)}else console.log("This is the concept by type and character error",r.status),M(r);return t}))}class ut{constructor(e,t,n,o,i,r,c,s,a,l){this.id=0,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.entryTimestamp=a,this.isNew=l}}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())}))};let ft=!1,yt=[];const pt=()=>{yt.length>0&&!ft&&yt.shift()()};var vt=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 gt=!1,Ct=[];const mt=()=>{Ct.length>0&&!gt&&Ct.shift()()};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())}))};class Nt{static getId(){return Tt(this,void 0,void 0,(function*(){this.ids.length<10&&(yield function(){return vt(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{console.log("trying to fetch more concepts"),Ct.push((()=>vt(this,void 0,void 0,(function*(){try{if(gt)return;if(gt=!0,Nt.ids.length>10)return console.log("Enough IDs available, skipping fetch."),gt=!1,mt(),e();var o=yield V("application/x-www-form-urlencoded");const t=yield fetch(n.GetReservedIdUrl(),{method:"GET",headers:o});if(!t.ok)throw M(t),new Error(`Error! status: ${t.status}`);const r=yield t.json();for(var i=0;i<r.length;i++)Nt.AddId(r[i]);console.log("Ids Fetch Success"),e()}catch(e){e instanceof Error?console.log("get reserved ids error message: ",e.message,n.GetReservedConnectionIdUrl()):console.log("get reserved ids unexpected error: ",e),t(e)}finally{gt=!1,mt()}})))),mt()}))}))}());var e=this.ids[0];return this.ids.shift(),e}))}static AddId(e){this.ids.includes(e)||this.ids.push(e)}}Nt.ids=[];class It{static getId(){return Tt(this,void 0,void 0,(function*(){this.connectionIds.length<10&&(yield function(){return ht(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{yt.push((()=>ht(this,void 0,void 0,(function*(){try{if(ft)return;if(ft=!0,It.connectionIds.length>10)return ft=!1,pt(),e();var o=yield V("application/x-www-form-urlencoded");const t=yield fetch(n.GetReservedConnectionIdUrl(),{method:"GET",headers:o});if(!t.ok)throw M(t),new Error(`Error! status: ${t.status}`);const r=yield t.json();for(var i=0;i<r.length;i++)It.AddId(r[i]);e()}catch(e){e instanceof Error?console.log("get reserved connection ids error message: ",e.message):console.log("get reserved connection ids unexpected error: ",e),t(e)}finally{ft=!1,pt()}})))),pt()}))}))}());var e=this.connectionIds[0];return this.connectionIds.shift(),e}))}static AddId(e){this.connectionIds.includes(e)||this.connectionIds.push(e)}}It.connectionIds=[];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())}))};function At(e,t,n,o,i,r,c,s,a,l,d,u,h,f){return wt(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 Nt.getId();let v=new Date,g=new Date;var C=new R(p,t,i,r,n,o,c,s,e,a,l,d,u,h,f,!0,v,g);return C.isTemp=!1,it.AddConcept(C),y.concepts.push(C),C}))}function kt(e,t,n,o,i,r,c,s,a,l,d,u,h,f){return wt(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 Nt.getId();let v=new Date,g=new Date;var C=new R(p,t,i,r,n,o,c,s,e,a,l,d,u,h,f,!1,v,g);return G.AddConcept(C),C.updateRecursion=!0,it.AddConcept(C),y.concepts.push(C),C}))}var xt=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){return xt(this,arguments,void 0,(function*(e,t,o=!1,i,r,c=999,s=0,a={concepts:[],connections:[]}){let l,d=c,u=(i=o?i:999,999),h=i,f=i,y=r,p=i,v="",g=t.length,C=E();v=e.startsWith("the_")?e:"the_"+e;(new Date).getTime();if(o)C=yield xn(e),l=yield At(t,i,4,i,C.id,C.userId,s,999,u,h,y,p,d,f,a),(new Date).getTime();else if(g>255)C=yield xn(v),l=yield At(t,i,4,i,C.id,C.userId,s,999,u,h,y,p,d,f,a),function(e){ct(this,void 0,void 0,(function*(){try{var t=yield V();const o=yield fetch(n.CreateTheTextDataUrl(),{method:"POST",headers:t,body:JSON.stringify(e)});if(!o.ok)throw M(o),new Error(`Error! status: ${o.status}`);return yield o.json()}catch(e){throw e instanceof Error?console.log("Create the text error message: ",e.message):console.log("Create the text unexpected error: ",e),e}}))}(new ut(i,t,u,h,y,p,d,f,Date.now().toString(),!0)),(new Date).getTime();else{C=yield xn(v);let e=yield lt(t,C.id);l=e,0==e.id&&0==e.userId&&(l=yield kt(t,i,4,i,C.id,C.userId,12,12,u,h,y,p,d,f,a)),(new Date).getTime()}return l.type=C,l}))}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){return _t(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=E();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 St(o,"",!0,s,a,l),h=p.id,d=p.id,yield Rt(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 St(o,"",!0,s,a,l),yield rt(f,y,p.id,p.userId,h,l,p.userId),yield Rt(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 St(o,e[o].toString(),!1,s,a,l);yield rt(f,y,p.id,p.userId,h,l,p.userId)}return u}))}class Et{constructor(e=0,t,n,o,i,r,c=999){this.isTemp=!1,this.applicationId=999,this.type=$e(),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=P(new Date),this.terminationDateTime=new Date,this.localSyncTime=new Date,this.applicationId=c}}function Pt(e,t,n,o=1){Math.floor(1e8*Math.random());let i=0,r=0,c=0;i=e,r=t,c=n;let s=new Et(0,0,0,0,0,0);return e!=t&&(s=new Et(0,e,t,n,o,4),s.isTemp=!0,s.id=Math.floor(1e8*Math.random()),We.AddConnection(s)),s}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,n,o,i,r){return Bt(this,arguments,void 0,(function*(e,t,n,o,i,r,c=0){var s=Math.floor(1e8*Math.random());let a=new Date,l=new Date;var d=new Oe(s,n,i,o,r,e,t,!0,a,l,c);return d.isTemp=!0,je.AddConcept(d),d}))}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())}))},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())}))};function Ft(e,t,n,o){return Gt(this,void 0,void 0,(function*(){var i=yield Ye(e);if(i&&(0==i.id||0==i.userId)){var r=D(e);if(r[0]==e){var c=yield function(e,t,n){return Ut(this,void 0,void 0,(function*(){var t=yield je.GetConceptByCharacterAndTypeLocal(e,51),o=t;return 0==o.id&&(o=t=yield Lt(e,"the",n,4,51,4)),o}))}(e,0,o);i=c}else{var s=yield Ft(r[0],t,n,o),a=yield Ft(r[1],t,n,o);a&&(i=c=yield Lt(e,r[1],o,s.id,a.id,4))}}return i}))}var Dt=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,t){return Dt(this,arguments,void 0,(function*(e,t,n=!1,o,i,r=999,c=0){var s,a,l,d=o=n?o:999,u=t.length;if(l=e.startsWith("the_")?e:"the_"+e,n)s=yield Ft(e,999,o,o),a=yield Lt(t,e,o,4,s.id,4,c);else if(u>255)s=yield Ft(l,999,d,o),a=yield Lt(t,l,o,4,s.id,4);else{s=yield Ft(l,999,d,o);var h=yield je.GetConceptByCharacterAndTypeLocal(t,s.id);a=h,0==h.id&&0==h.userId&&(a=yield Lt(t,l,o,4,s.id,4))}return a.type=s,a}))}var Vt=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 Vt(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:999,l=null!=c?c:4,d=null!=o?o:0,u=$e();for(const o in e)if("string"!=typeof e[o]&&"number"!=typeof e[o])if(null==t&&null==n){var h=d;u=y=yield bt(o,"",!0,s,a,l),h=y.id,d=y.id,yield Ot(e[o],y.id,y.userId,h,i,r,c)}else{var f=null!=t?t:999,y=(h=d,yield bt(o,"",!0,s,a,l));yield Pt(f,y.id,h),yield Ot(e[o],y.id,y.userId,h,i,r,c)}else f=null!=t?t:999,h=d,y=yield bt(o,e[o].toString(),!1,s,a,l),yield Pt(f,y.id,h);return u}))}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 Mt(e,t,o){return $t(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 V("application/x-www-form-urlencoded");const l=yield fetch(n.GetAllConnectionsOfConceptUrl(),{method:"POST",headers:a,body:s});return l.ok?c=yield l.json():(console.log("Get connection of concept error",l.status),M(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 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())}))};function Ht(e,t,n,o,i,r,c){return jt(this,arguments,void 0,(function*(e,t,n,o,i,r,c,s=1,a=4,l=999,d={concepts:[],connections:[]}){let u=t,h=t,f=t;999!=l&&(f=l);let y=t,p=t,v=yield It.getId(),g=new J(v,e,n,t,o,f,i,h,s,u,0,y,a,p,r,c);return e==n?(g.ofTheConceptId=0,g.toTheConceptId=1,g):(g.toUpdate=!0,g.isTemp=!1,it.AddConnection(g),d.connections.push(g),g)}))}function Wt(e,t,n){return jt(this,arguments,void 0,(function*(e,t,n,o={concepts:[],connections:[]}){let i=yield xn(n),r=e.userId;return yield Ht(e.id,e.userId,t.id,t.userId,i.id,999,999,1e3,4,r,o)}))}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())}))},zt=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())}))},qt=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 Kt(e){return qt(this,void 0,void 0,(function*(){var t=yield Z.GetConnection(e);if((null==t||0==t.id)&&null!=e&&null!=e){var o=yield function(e){return zt(this,void 0,void 0,(function*(){var t=yield Z.GetConnection(e);try{if(0!=t.id)return t;{var o=yield V("application/x-www-form-urlencoded");const i=yield fetch(n.GetConnectionUrl(),{method:"POST",headers:o,body:`id=${e}`});return i.ok?(t=yield i.json(),Z.AddConnection(t)):(console.log("Get Connection Error",i.status),M(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 Qt=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 Yt(e){return Qt(this,arguments,void 0,(function*(e,t=""){let o=!1;var i=yield Kt(e);return o=yield function(e){return Jt(this,arguments,void 0,(function*(e,t=""){let o=!1;try{const i=new FormData;let r={Authorization:(yield O("",t)).Authorization,Accept:"application/json"};i.append("id",e.toString()),i.append("apiKey","nodeserver");const c=yield fetch(n.DeleteTheConnectionUrl(),{method:"POST",headers:r,body:i,redirect:"follow"});c.ok?o=(yield c.json()).success:(console.log("Delete connection error status: ",c.status),M(c))}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),K.removeNodeFromTree(e),Y.removeTypeConcept(i.typeId,e),o}))}var Xt=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 Zt(e){return Xt(this,arguments,void 0,(function*(e,t=999){var n=E();if(e<0)return ni(yield Jo(t,e));if(null!=(n=yield G.GetConcept(e))&&0!=n.id||null==e||null==e||(n=yield ue(e)),0!=n.id&&null==n.type&&null==(yield G.GetConcept(n.typeId))&&null!=n.typeId&&null!=n.typeId){var o=yield ue(n.typeId);n.type=o}return n}))}var en=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){return en(this,arguments,void 0,(function*(e,t,n,o=!1,i=!1){var r,c,s=e.userId,a=s,l=s;if(o){let o=n+"_by",c=(null===(r=t.type)||void 0===r?void 0:r.characterValue)+"_s_"+o;i&&(yield nn(o,t,s));var d=yield St("connection",c,!1,999,999,999);let u=new J(0,t.id,e.id,t.userId,e.userId,t.userId,d.id,d.userId,1e3,s,999,a,4,l,999,999);it.AddConnection(u)}let u=n+"_s",h=(null===(c=e.type)||void 0===c?void 0:c.characterValue)+"_s_"+u;i&&(yield nn(u,e,s));var f=yield St("connection",h,!1,999,999,999);let y=new J(0,e.id,t.id,e.userId,t.userId,e.userId,f.id,f.userId,1e3,s,999,a,4,l,999,999);return it.AddConnection(y),y}))}function nn(e,t){return en(this,arguments,void 0,(function*(e,t,n=null){for(var o,i=t,r=null!=n?n:t.userId,c=r,s=r,a=999,l=e+"_count",d=(null===(o=t.type)||void 0===o?void 0:o.characterValue)+"_s_"+l,u=yield St("connection",d,!1,r,4,a),h=yield Mt(u.id,t.id,r,10,1),f=[],y=E(),p=0;p<h.length;p++){let e=yield Zt(h[p].toTheConceptId);f.push(e)}if(f.length<1)y=yield St("count","1",!1,r,4,a);else{var v=f[0];let e=0;try{e=Number(v.characterValue)}catch(t){e=0}e+=1,y=yield St("count",e.toString(),!1,r,4,a);for(let e=0;e<h.length;e++)Yt(h[e].id)}let g=new J(0,i.id,y.id,i.userId,y.userId,i.userId,u.id,u.userId,1e3,r,999,c,4,s,a,999);yield it.AddConnection(g)}))}function on(e,t,n){return en(this,arguments,void 0,(function*(e,t,n,o=!1,i=!1){var r,c,s=e.userId,a=s,l=s;if(o){let o=n+"_by",c=(null===(r=t.type)||void 0===r?void 0:r.characterValue)+"_s_"+o;i&&(yield nn(o,t,s));var d=yield St("connection",c,!1,999,999,999);let u=new J(0,t.id,e.id,t.userId,e.userId,t.userId,d.id,d.userId,1e3,s,999,a,4,l,999,999);it.AddConnection(u)}let u=n+"_s",h=(null===(c=e.type)||void 0===c?void 0:c.characterValue)+"_s_"+u;i&&(yield nn(u,e,s));var f=yield St("connection",h,!1,999,999,999);return yield Ht(e.id,e.userId,t.id,t.userId,f.id,999,999,1e3,4)}))}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,t){return rn(this,arguments,void 0,(function*(e,t,n=10,o=1){var i,r=[],c=yield Zt(e),s=(null===(i=c.type)||void 0===i?void 0:i.characterValue)+"_s_"+t,a=yield lt(s,16);if(a.id>0){for(var l=yield Mt(a.id,c.id,c.userId,n,o),d=[],u=0;u<l.length;u++)d.push(l[u].toTheConceptId);for(yield ae(d),u=0;u<l.length;u++){let e=l[u].toTheConceptId,t=yield Zt(e),n=yield Te(t.id);r.push(n)}}return r}))}function sn(e,t){return rn(this,arguments,void 0,(function*(e,t,n=10,o=1){var i,r=[],c=yield Zt(e),s=(null===(i=c.type)||void 0===i?void 0:i.characterValue)+"_s_"+t,a=yield lt(s,16);if(a.id>0){for(var l=yield Mt(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 Zt(e);r.push(t)}}return r}))}class an{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 ln{constructor(){this.name="character Repository"}static AddCharacter(e){this.characterData[e.id]=e}static GetCharacter(e){for(var t=new an(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}}ln.characterData=[];class dn{constructor(e,t,n,o){this.id=e,this.userId=t,this.referentId=n,this.isNew=o}}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())}))},hn=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,o,i,r){return hn(this,void 0,void 0,(function*(){return new an(t,e,o,t,i,t,r,t,"",!1),yield function(){return un(this,void 0,void 0,(function*(){var e;try{if(0==(e=ln.GetCharacter(e.data)).id){var t=yield V();const i=yield fetch(n.CreateTheCharacterDataUrl(),{method:"POST",headers:t,body:JSON.stringify(e)});if(!i.ok)throw M(i),new Error(`Error! status: ${i.status}`);const r=yield i.json();var o=new an(r.userId,e.data,0,0,4,4,999,999,"",!1);return o.id=r.id,ln.AddCharacter(o),r}return new dn(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 yn=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,t,n,o,i,r,c,s,a,l,d,u,h,f){return yn(this,void 0,void 0,(function*(){var y=yield lt(e,i),p=y;return 0==p.id&&(p=y=yield At(e,t,n,o,i,r,c,s,a,l,d,u,h,f)),p}))}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,n,o){return gn(this,arguments,void 0,(function*(e,t,n,o,i={concepts:[],connections:[]}){var r=yield Re(e);if(r&&(0==r.id||0==r.userId)){var c=D(e);if(c.length>0)if(console.log(c),c[0]==e){var s=yield function(e,t,n,o,i,r){return vn(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 fn(e,t,n,o,r),a=pn(e,t,4,c,h,u,49,l,n,s,o,i,r,d)}else{var f=yield fn(e,t,n,o,r);f.isNew,a=yield pn(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 Cn(c[0],t,n,o,i),l=yield Cn(c[1],t,n,o,i);l&&(r=yield kt(e,o,a.id,o,l.id,o,999,o,999,o,999,o,t,o,i))}}return r}))}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())}))};const Tn=new Map;function Nn(e,t){return mn(this,void 0,void 0,(function*(){let o=E();if(Tn.has(e+t))return Tn.get(e+t)||o;const i=(()=>mn(this,void 0,void 0,(function*(){try{var i=yield V("application/x-www-form-urlencoded");const r=yield fetch(n.GetConceptByCharacterAndCategoryDirectUrl(),{method:"POST",headers:i,body:`character_value=${e}&category_id=${t}`});if(r.ok){let e=yield r.json();o=e,G.AddConcept(o)}else console.log("This is the concept by category and character direct api error",r.status),M(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{Tn.delete(e+t)}})))();return Tn.set(e+t,i),i}))}var 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 wn(e){return In(this,void 0,void 0,(function*(){let t=E();if("the"==e)return t.id=1,t.typeId=5,t.characterValue="the",t;let n=e.length;var o=D(e);if(o.length>1){let n=1,i=yield wn(o[0]);0!=i.id&&(n=i.id),t=yield function(e,t){return In(this,void 0,void 0,(function*(){let n=yield G.GetConceptByCharacterAndCategoryLocal(e,t);return 0==n.id&&(n=yield Nn(e,t)),n}))}(e,n)}else o[0]==e&&1==n?t=yield function(e){return In(this,void 0,void 0,(function*(){console.log("inside the character length function",e);var t=yield G.GetConceptByCharacterAndTypeLocal(e,49);return console.log("inside the character length function after",t),0==t.id&&(t=yield Se(e)),t}))}(e):o[0]==e&&(t=yield function(e){return In(this,void 0,void 0,(function*(){var t=yield G.GetConceptByCharacterAndTypeLocal(e,51);return 0==t.id&&(t=yield Se(e)),t}))}(e));return t}))}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())}))};const kn=new Map;function xn(e,t){return An(this,void 0,void 0,(function*(){let t=E();if(kn.has(e))return kn.get(e)||t;const o=(()=>An(this,void 0,void 0,(function*(){try{if(t=yield wn(e),0==t.id||4==t.typeId){var o=yield V("application/x-www-form-urlencoded");const i=yield fetch(n.MakeTheTypeConceptUrl(),{method:"POST",headers:o,body:`type=${e}`});if(!i.ok)throw M(i),new Error(`Error! status: ${i.status}`);let r=yield i.json();t=r,t.id>0&&G.AddConcept(t)}return 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{kn.delete(e)}})))();return kn.set(e,o),o}))}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 _n(e){return Sn(this,void 0,void 0,(function*(){var t=[];try{(new Date).getTime();var o=yield V("application/x-www-form-urlencoded");const c=yield fetch(n.GetAllLinkerConnectionOfConceptUrl()+`?conceptId=${e}`,{method:"GET",headers:o});if(c.ok){const e=yield c.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"),M(c);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 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 En(e){return Rn(this,void 0,void 0,(function*(){var t=[];try{(new Date).getTime();var o=yield V("application/x-www-form-urlencoded");const c=yield fetch(n.GetAllLinkerConnectionToConceptUrl()+`?conceptId=${e}`,{method:"GET",headers:o});if(c.ok){const e=yield c.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"),M(c);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 Pn=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 Bn(e){return Pn(this,void 0,void 0,(function*(){for(var t=yield _n(e),n=0;n<t.length;n++){let e=t[n];var o=e.typeId;let i=yield Zt(o);e.type=i}return t}))}function Ln(e){return Pn(this,void 0,void 0,(function*(){for(var t=yield En(e),n=0;n<t.length;n++){let e=t[n];var o=e.typeId;let i=yield Zt(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())}))},Gn=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},Fn=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){return Fn(this,arguments,void 0,(function*(e,t=""){var o=yield Zt(e);yield _.removeNodeFromTree(e);var i=o.typeId,r=o.characterValue;yield L.removeTypeConcept(i,e),yield x.removeNodeByCharacter(r,e);let c=yield function(e){return Un(this,arguments,void 0,(function*(e,t=""){let o=!1;try{let i=yield O("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=Gn(i,["Content-Type"]),a=yield fetch(n.DeleteConceptUrl(),{method:"POST",headers:s,body:r});if(!a.ok)throw M(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 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 Vn(e,t){return bn(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 fetch(n.DeleteConceptUrl(),{method:"POST",body:i,headers:o});if(!r.ok)throw M(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 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 $n(e,t,n,o){return On(this,arguments,void 0,(function*(e,t,n,o,i=999){var r,c=n,s=n,a=n,l=e.startsWith("the_"),d=E();return r=l?e:"the_"+e,d=yield xn(r),yield pn(t,n,4,n,d.id,d.userId,0,999,999,c,4,a,999,s)}))}class Mn{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 jn=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 jn(this,arguments,void 0,(function*(e=[]){var t=[];try{var o=[];for(let n=0;n<e.length;n++){let i=yield Z.GetConnection(e[n]);0==i.id?o.push(e[n]):t.push(i)}if(0==o.length)return t;{var i=yield V();const e=yield fetch(n.GetConnectionBulkUrl(),{method:"POST",headers:i,body:JSON.stringify(o)});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),Z.AddConnection(o)}yield oe(t)}}else console.log("Get Connection Bulk error",e.status),M(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 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())}))};function Jn(){return Wn(this,arguments,void 0,(function*(e=[]){yield ae(e);var t=[];for(let o=0;o<e.length;o++){var n=yield Ce(e[o]);t.push(n)}return t}))}function zn(){return Wn(this,arguments,void 0,(function*(e=[]){yield ae(e);var t=[];for(let o=0;o<e.length;o++){var n=yield me(e[o]);t.push(n)}return t}))}function qn(){return Wn(this,arguments,void 0,(function*(e=[],t=[]){yield Hn(t),function(e=[],t=[]){for(let n=0;n<t.length;n++)e.includes(t[n].id)||Z.RemoveConnection(t[n])}(t,yield re(e));var n=[];for(let t=0;t<e.length;t++){var o=yield me(e[t]);n.push(o)}return n}))}function Kn(){return Wn(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 Z.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 Hn(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 te(i),n}))}function Qn(){return Wn(this,arguments,void 0,(function*(e=[],t=[]){let n=[],o=[];for(let e=0;e<t.length;e++){let i=yield Z.GetConnection(t[e]);0==i.id?n.push(t[e]):o.push(i)}let i=yield Hn(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 Ie(e[t],o,c);r[e[t]]=n}return r}))}var Yn=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(){return Yn(this,arguments,void 0,(function*(e=0,t=[],o=""){var i=[];try{var r=new Mn;r.composition=e,r.listLinkers=t,r.textSearch=o;var c=JSON.stringify(r),s=yield V();const d=yield fetch(n.RecursiveSearchUrl(),{method:"POST",headers:s,body:c});if(d.ok){const e=yield d.json();var a=e.compositionIds,l=e.internalConnections;e.externalConnections,i=yield qn(a,l)}else console.log("recursive search error ",d.status),M(d);return i}catch(e){throw e instanceof Error?console.log("recursive search error message: ",e.message):console.log("recursive search unexpected error: ",e),e}}))}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 eo(e,t){return Zn(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 fetch(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),M(s)}catch(e){throw e instanceof Error?console.log("Login tsccs error message: ",e.message):console.log(" Login tsccs unexpected error: ",e),e}}))}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())}))};function no(e){return to(this,void 0,void 0,(function*(){const t=yield function(){return to(this,arguments,void 0,(function*(e="",t={}){let n={message:"success",status:!1,statusCode:200,data:""};try{const o=yield fetch(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}:M(o),n}catch(e){throw console.log("Signup Error: ",e),e}}))}(n.SignupUrl(),e);return t}))}var oo=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 oo(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 fetch(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}:M(e),o}catch(e){throw console.log("Sign in api error",e),e}}))}function ro(e,t){return-1===e.indexOf(t)&&e.push(t),e}function co(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 so(e=[],t){let n=[],o=t.typeCharacter;if((null==o?void 0:o.startsWith("the_"))||(o="the_"+o),Array.isArray(e))for(let i=0;i<e.length;i++){let r=e[i].typeCharacter;(null==r?void 0:r.startsWith("the_"))||(r="the_"+r),t.typeId!=e[i].typeId&&o!=r||n.push(e[i])}return n}function ao(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 lo(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 uo(e=[],t){Array.isArray(e)&&e.splice(e.findIndex((function(e){return e.id===t.id})),1)}function ho(e=[],t){Array.isArray(e)&&e.splice(e.findIndex((function(e){return e.id===t.id})),1)}class fo{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&&(po.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(e.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 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())}))};class po{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 fo(e.id,e,null,null);this.addNodeToTree(t)}static getNodeFromTree(e){return yo(this,void 0,void 0,(function*(){return this.root?this.root.getFromNode(e,this.root):null}))}static removeNodeFromTree(e){return yo(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}}po.root=null;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 go(e,t,n,o){return vo(this,arguments,void 0,(function*(e,t,n,o,i=[]){var r,c;let s={};const a=[];if(0==e)return"";let l=Co(n,e);if(null!=l&&0!=l.id||null==e||null==e||(l=yield Zt(e)),0!=l.id&&null==l.type){const e=l.typeId;let t=Co(n,e);l.type=t,null==t&&null!=e&&null!=e&&(t=yield Zt(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=Co(n,d);if(null!=e&&0!=e.id||null==d||null==d||(e=yield Zt(d)),0!=e.id&&null==(null==e?void 0:e.type)){const t=e.typeId;let n=yield G.GetConcept(t);e.type=n,null==n&&null!=t&&null!=t&&(n=yield Zt(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 go(d,t,n,o,i);s[u]=e}}else{const e=yield go(d,t,n,o,i);a[u]=e,s=a}}}return s}))}function Co(e,t){let n=E();for(let o=0;o<e.length;o++)if(t==e[o].id)return n=e[o],n;return n}class mo{constructor(){this.id=0,this.mainConcept=E(),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 go(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 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())}))};function No(e){return To(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=E();null==s&&(s=new mo);for(const o in e)if("object"==typeof e[o]||Array.isArray(e[o])){const f=yield St(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 No(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 rt(a,l,f.id,f.userId,y,d,f.userId);s.connections.push(p),yield No(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 St(o,e[o],!1,a,l,d);s.concepts.push(h);const f=yield rt(i,r,h.id,h.userId,c,d,h.userId);s.connections.push(f)}return h}))}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 wo(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=E(),s=E();const a=[];let l=e.compositionId;const d=e.ofTheCompositionId;let u=[];if(l<0){let e=yield Zt(l,t);if(!(e.id>0))return null;l=e.id}i=yield fe(l);const h=[],f=new mo,y=[];f.id=l,f.isUpdating();let p=[];for(let e=0;e<i.length;e++)ro(y,i[e].ofTheConceptId),ro(h,i[e].ofTheConceptId),ro(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 Zt(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=E();const l=v[e];let d=c;if(s.id>0&&(d=s),Array.isArray(l)||"object"==typeof l){i=yield St(e,"",!0,c.userId,4,999),f.subcompositions.push(i.id);const t=co(r,i);for(let e=0;e<t.length;e++)if(t[e].id>0){const n=ao(f.connections,t[e].id);u=u.concat(n),a.push(t[e])}yield No(v[e],i.id,i.userId,c.id,c.userId,4,999,f)}else{i=yield St(e,l,!1,t,o,n);const c=co(r,i);for(let e=0;e<c.length;e++)if(c[e].id>0){const t=ao(f.connections,c[e].id);u=u.concat(t),a.push(c[e])}}const h=yield rt(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++)ho(f.connections,u[e]),Yt(u[e].id);for(let e=0;e<a.length;e++)uo(r,a[e]);return f.concepts=f.concepts.concat(r),f.mainConcept=c,f.id=c.id,yield f.updateCache(),po.addCompositionToTree(f),yield it.SyncDataOnline(),f.GetDataCache()}))}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 O("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 fetch(l,{method:"GET",headers:s});return e.ok?yield e.json():(M(e),[])}catch(e){throw console.log("This is the searching error",e),e}}))}var 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 So(e){return xo(this,arguments,void 0,(function*(e,t=""){var o=yield O("application/json",t);const i=n.SearchLinkMultipleAll(),r=JSON.stringify(e);try{const e=yield fetch(i,{method:"POST",headers:o,body:r});return e.ok?yield e.json():(console.log("This is the searching error",e.status),M(e),[])}catch(e){throw console.log("This is the searching 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 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 G.GetConcept(e);0==l.id&&null!=e&&null!=e&&(l=yield ue(e));let d=[];d=t.length>0?Eo(e,t):yield fe(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 Ae(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 Po(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 G.GetConcept(e);0==d.id&&null!=e&&null!=e&&(d=yield ue(e));let u=[];u=t.length>0?Eo(e,t):yield fe(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 Ae(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 Bo(e,t){return _o(this,void 0,void 0,(function*(){let n=[];const o=[];n=yield Hn(t);for(let t=0;t<e.length;t++){const i=yield Po(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 Uo(e){return Lo(this,void 0,void 0,(function*(){try{var t=yield V();const o=JSON.stringify(e),i=yield fetch(n.CreateSessionId(),{method:"POST",headers:t,body:o});return i.ok?i.json():(console.log("Creating session failed",yield i.json()),M(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 V("application/x-www-form-urlencoded");const i=new URLSearchParams;i.append("sessionId",e.toString()),i.append("url",t);const r=yield fetch(n.CreateSessionVisitUrl(),{method:"POST",headers:o,body:i});return r.ok?r.json():(console.log("Creating session url failed",yield r.json()),M(r),null)}catch(e){throw console.log("Creating session url failed",e),e}}))}var Do=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 bo(e,t,o){return Do(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 V("application/x-www-form-urlencoded");const l=yield fetch(n.GetAllConnectionsToConceptUrl(),{method:"POST",headers:a,body:s});return l.ok?c=yield l.json():(console.log("Get connection of concept error",l.status),M(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 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 Oo(e,t){return Vo(this,arguments,void 0,(function*(e,t,n=10,o=1,i=!1){let r=[],c=yield Zt(e),s=yield wn(t);if(s.id>0){let e=[],t=[];if(i){t=yield bo(s.id,c.id,c.userId,n,o);let e=[];for(let n=0;n<t.length;n++)e.push(t[n].ofTheConceptId);yield ae(e);for(let e=0;e<t.length;e++){let n=t[e].ofTheConceptId,o=yield Zt(n),i=yield Te(o.id);r.push(i)}}else{t=yield Mt(s.id,c.id,c.userId,n,o);for(let n=0;n<t.length;n++)e.push(t[n].toTheConceptId);yield ae(e);for(let e=0;e<t.length;e++){let n=t[e].toTheConceptId,o=yield Zt(n),i=yield Te(o.id);r.push(i)}}}return r}))}function $o(e,t){return Vo(this,arguments,void 0,(function*(e,t,n=10,o=1,i=!1){let r=[],c=yield Zt(e),s=yield wn(t),a=[],l=[];if(s.id>0){if(i){a=yield bo(s.id,c.id,c.userId,n,o);for(let e=0;e<a.length;e++)l.push(a[e].ofTheConceptId)}else{a=yield Mt(s.id,c.id,c.userId,n,o);for(let e=0;e<a.length;e++)l.push(a[e].toTheConceptId)}r=yield te(l)}return r}))}class Mo{constructor(e,t,n,o,i){this.connectionValue=[],this.value=[],this.height=1,this.key=e,t.id>0&&this.value.push(t),n.id>0&&this.connectionValue.push(n),this.leftNode=o,this.rightNode=i}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.value.push(...e.value),t.connectionValue.push(...e.connectionValue),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}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(e.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}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.rightNode=this.removeNode(e.rightNode,n.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 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 Ho{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 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 jo(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{this.checkFlag(e),setTimeout((()=>{t("not")}),25e3)}))}))}static checkFlag(e){if(w.isDataLoaded)return e("done");setTimeout(Ho.checkFlag,1e3,e)}static addConceptToTree(e,t,n=999){let o=this.compositeKey(t,n,e.applicationId),i=new Et(0,0,0,0,0,0);var r=new Mo(o,e,i,null,null);this.addNodeToTree(r)}static addConnectionToTree(e,t,n=999){let o=this.compositeKey(t,n,e.applicationId),i=$e();var r=new Mo(o,i,e,null,null);this.addNodeToTree(r)}static getNodeFromTree(e,t){return jo(this,arguments,void 0,(function*(e,t,n=999){let o=this.compositeKey(e,t,n);return this.root?this.root.getFromNode(o,this.root):null}))}static removeNodeFromTree(e){return jo(this,arguments,void 0,(function*(e,t=999,n=999){if(this.root){let o=this.compositeKey(e,t,n);this.root=this.root.removeNode(this.root,o)}}))}static countNumberOfNodes(){return this.root?this.root.countNodeBelow(this.root):0}}Ho.root=null;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 Jo(e,t){return Wo(this,arguments,void 0,(function*(e,t,n=999,o=999){let i=yield Ho.getNodeFromTree(e,n,o),r=$e();if(i)for(let e=0;e<i.value.length;e++){let n=i.value[e];n.ghostId==t&&(r=n)}return r}))}function zo(e,t){return Wo(this,arguments,void 0,(function*(e,t,n=999,o=999){let i=yield Ho.getNodeFromTree(e,n,o),r=new Et(0,0,0,0,0,0);if(i)for(let e=0;e<i.connectionValue.length;e++){let n=i.connectionValue[e];n.ghostId==t&&(r=n)}return r}))}function qo(e,t){return Wo(this,arguments,void 0,(function*(e,t,n=999){Ho.addConceptToTree(e,t,n)}))}function Ko(e,t){return Wo(this,arguments,void 0,(function*(e,t,n=999){Ho.addConnectionToTree(e,t,n)}))}var Qo=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 Yo(e){return Qo(this,arguments,void 0,(function*(e,t=""){var o=yield O("application/json",t);const i=n.SearchLinkMultipleAllApiUrl(),r=JSON.stringify(e);try{const e=yield fetch(i,{method:"POST",headers:o,body:r});return e.ok?yield e.json():(console.log("This is the searching multiple error",e.status),M(e),[])}catch(e){throw console.log("This is the searching multiple error",e),e}}))}var 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,arguments,void 0,(function*(e,t=""){let n=[],o=yield Yo(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 ei(a,n,i,l)}))}function ei(e,t,n){return Xo(this,arguments,void 0,(function*(e,t,n,o=[]){let i={},r=yield Hn(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 Zt(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){console.log("this is error",e)}}}else if(t[r[e].ofTheConceptId]&&t[r[e].toTheConceptId]){let n=t[r[e].ofTheConceptId],o=yield Zt(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){console.log("this is error",e)}}}return i=t[n],i}))}function ti(e){var t,n;const o=$e();return o.id=e.id,o.ghostId=e.ghostId,o.userId=e.userId,o.accessId=e.accessId,o.categoryId=e.categoryId,o.characterValue=e.characterValue,o.entryTimeStamp=e.entryTimeStamp,o.typeId=e.typeId,o.type=e.type,o.isTemp=!1,o.typeCharacter=null!==(n=null===(t=null==e?void 0:e.type)||void 0===t?void 0:t.characterValue)&&void 0!==n?n:"",o}function ni(e){const t=E();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}function oi(e){const t=new Et(0,0,0,0,0,0);return t.id=e.id,t.ghostId=e.ghostId,t.accessId=e.accessId,t.ofTheConceptId=e.ofTheConceptId,t.toTheConceptId=e.toTheConceptId,t.entryTimeStamp=e.entryTimeStamp,t.typeId=e.typeId,t.isTemp=!1,t}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){return ii(this,void 0,void 0,(function*(){const t=e.userId,n=e.sessionId,o=e.accessId;let i=[];const r=[];let c=$e(),s=$e();const a=[],l=e.compositionId,d=e.ofTheCompositionId;let u=[],h=yield fe(l);for(let e=0;e<h.length;e++)i.push(oi(h[e]));const f=[],y=[];let p=[];for(let e=0;e<i.length;e++)ro(y,i[e].ofTheConceptId),ro(f,i[e].ofTheConceptId),ro(f,i[e].toTheConceptId),p.push(i[e].ofTheConceptId);for(let e=0;e<f.length;e++){const t=yield Zt(f[e]);l==f[e]&&(c=ti(t)),d==f[e]&&(s=ti(t)),r.push(ti(t))}const v=e.patchObject;for(const e in v){let l=$e();const d=v[e];let h=c;s.id>0&&(h=s),Array.isArray(d)||"object"==typeof d?(l=yield bt(e,"",!0,c.userId,4,999),yield Ot(v[e],l.id,l.userId,c.id,c.userId,4,999)):l=yield bt(e,d,!1,t,o,n);const f=so(r,l);for(let e=0;e<f.length;e++)if(f[e].id>0){const t=lo(i,f[e].id);u=u.concat(t),a.push(f[e])}yield Pt(h.id,l.id,c.id,2),r.push(l)}for(let e=0;e<u.length;e++)Yt(u[e].id);it.SyncDataOnline()}))}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,void 0,void 0,(function*(){var t;let o=yield function(e){return ci(this,void 0,void 0,(function*(){let t=[];try{var o=yield V();const i=yield fetch(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;te(i),n[r]=t}return n}return console.log("View Internal Data error",i.status),M(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 Ae(r,c,e);t.data=n,t.id=r,i.push(t)}else{let e={};e.id=r;let n=yield Zt(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}))}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())}))},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())}))};function ui(e){return di(this,arguments,void 0,(function*(e,t=""){var o=yield function(e){return li(this,arguments,void 0,(function*(e,t=""){var o=yield O("application/json",t);let i=n.SearchInternalWithAuthenticatedCcsUrl();i=i+"?composition="+e.composition+"&search="+e.search+"&internalComposition="+e.internalComposition+"&type="+e.type+"&inpage="+e.inpage+"&page="+e.page;try{const e=yield fetch(i,{method:"GET",headers:o});return e.ok?yield e.json():(console.log("This is the searching internal error",e.status),M(e),[])}catch(e){throw console.log("This is the searching internal error",e),e}}))}(e,t);return yield ai(o)}))}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())}))};function fi(e,t){return hi(this,void 0,void 0,(function*(){let n=!0,o=yield _n(e),i=yield dt(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 Yt(r[e]);n=n&&t}return n}))}function yi(e,t){return hi(this,void 0,void 0,(function*(){let n=yield _n(e),o=yield dt(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 pi{constructor(){this.compositionId=0,this.userId=999,this.sessionId=999,this.accessId=4,this.ofTheCompositionId=0,this.patchObject={}}}class vi{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 gi{constructor(){this.type="",this.search="",this.logicoperator="=",this.index=0,this.composition=!0,this.name="",this.operateon=""}}class Ci{constructor(){this.type="",this.search="",this.composition="",this.internalComposition="",this.userId=999,this.inpage=10,this.page=1}}class mi{constructor(e){this.aiUrl="https://ai.freeschema.com",this.accessToken="",this.enableAi=!0,this.enableAccessControl=!1,e&&Object.assign(this,e)}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 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())}))};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())}))},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())}))};class wi{}wi.isUpdated=!1,wi.isOnlineSync=!1;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{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 ki.superAdminCache)e>n.expiresAt&&ki.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=ki.superAdminCache.get(e);return void 0===t?null:Date.now()>t.expiresAt?(ki.superAdminCache.delete(e),null):t.value}setSuperAdmin(e,t){ki.superAdminCache.set(e,{value:t,expiresAt:Date.now()+6e5})}clearSuperAdminCache(){ki.superAdminCache.clear()}}ki.superAdminCache=new Map;var xi,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 _i{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 Si(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 Si(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 Si(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 Si(this,void 0,void 0,(function*(){return this.postAsync("access/assign",e)}))}checkAccessAsync(e){return Si(this,void 0,void 0,(function*(){return this.postAsync("access/check",e)}))}revokeAccessAsync(e){return Si(this,void 0,void 0,(function*(){return this.deleteAsync("access/revoke",e)}))}assignAccessBulkAsync(e){return Si(this,void 0,void 0,(function*(){return this.postAsync("access/assign/bulk",e)}))}revokeAccessBulkAsync(e){return Si(this,void 0,void 0,(function*(){return this.deleteAsync("access/revoke/bulk",e)}))}checkAccessBulkAsync(e){return Si(this,void 0,void 0,(function*(){return this.postAsync("access/check/bulk",e)}))}getAccessByIdAsync(e){return Si(this,void 0,void 0,(function*(){return this.getAsync(`access/${e}`)}))}setAccessInheritanceAsync(e){return Si(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance",e)}))}getAccessInheritanceStatusAsync(e){return Si(this,arguments,void 0,(function*(e,t=999){return this.getAsync(`access/inheritance/status?accessId=${e}&connectionTypeId=${t}`)}))}assignSuperAdminAccessAsync(e){return Si(this,void 0,void 0,(function*(){return this.postAsync("access/super-admin",e)}))}revokeSuperAdminAccessAsync(e){return Si(this,void 0,void 0,(function*(){return this.deleteAsync("access/super-admin",e)}))}checkSuperAdminStatusAsync(e){return Si(this,void 0,void 0,(function*(){return this.getAsync(`access/super-admin?accessId=${e}`)}))}setParentAccessInheritanceAsync(e){return Si(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent",e)}))}removeParentAccessInheritanceAsync(e,t){return Si(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 Si(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 Si(this,void 0,void 0,(function*(){return this.getAsync(`access/inheritance/parent?accessId=${e}`)}))}setParentAccessInheritanceByConceptAsync(e){return Si(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent/concept",e)}))}setParentAccessInheritanceBulkByConceptAsync(e){return Si(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/parent/concept/bulk",e)}))}removeParentAccessInheritanceByConceptAsync(e,t){return Si(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 Si(this,void 0,void 0,(function*(){return this.deleteAsync("access/inheritance/parent/concept/bulk",e)}))}hasParentAccessInheritanceByConceptAsync(e,t){return Si(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 Si(this,void 0,void 0,(function*(){return this.getAsync(`access/inheritance/parent/concept?childConceptId=${e}`)}))}assignSuperAdminByConceptAsync(e){return Si(this,void 0,void 0,(function*(){return this.postAsync("access/super-admin/concept",e)}))}revokeSuperAdminByConceptAsync(e){return Si(this,void 0,void 0,(function*(){return this.deleteAsync("access/super-admin/concept",e)}))}checkSuperAdminByConceptAsync(e){return Si(this,void 0,void 0,(function*(){return this.getAsync(`access/super-admin/concept?conceptId=${e}`)}))}setAccessInheritanceByConceptAsync(e){return Si(this,void 0,void 0,(function*(){return this.postAsync("access/inheritance/concept",e)}))}getAccessInheritanceStatusByConceptAsync(e){return Si(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"}(xi||(xi={}));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{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 _i(e)}static checkAccess(e,t,n){return Ri(this,void 0,void 0,(function*(){var o;if(t===xi.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 Ri(this,void 0,void 0,(function*(){var i,r,c,s,a,l;if(t===xi.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 h=[],f=new Set,y=new Map;let p=null;if(null!=o&&o>0)try{p=yield Zt(o)}catch(e){}let v=0;try{const e=yield function(){return e=this,t=void 0,i=function*(){let e=E();try{var t=yield V("application/x-www-form-urlencoded");const o=yield fetch(n.GetConceptByCharacterAndCategoryUrl(),{method:"POST",headers:t,body:"character_value=the_parent_access_inheritance"});return o.ok?(e=yield o.json(),G.AddConcept(e)):(console.log("This is the concept by category and character error",o.status),M(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&&(v=e.id)}catch(e){}const g=yield te(e),C=new Map;for(const e of g)C.set(e.id,e);const m=new Map;for(const t of e){const e=null!==(i=C.get(t))&&void 0!==i?i:yield Zt(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(p&&p.userId&&p.userId===e.userId){u.set(t,!0);continue}if(n<1e4){u.set(t,!0);continue}let a=0;if(o>0){let e=m.get(o);if(!e)try{e=yield Zt(o),m.set(o,e)}catch(e){}e&&(a=null!==(s=e.accessId)&&void 0!==s?s:0)}h.push({conceptId:t,accessId:n,typeAccessId:a}),n>0&&(f.add(n),y.set(n,t)),a>0&&f.add(a)}if(0===h.length)return u;const T=yield this.resolveBulkInheritanceGraph(f,v,y),N=[],I=new Set;for(const e of T.values())for(const t of e)I.has(t)||(I.add(t),N.push(t));const w=yield this.resolveSubjects(o),A=yield this.resolveBulkDecisions(N,d,w);for(const e of h){const t=null!==(a=T.get(e.accessId))&&void 0!==a?a:[e.accessId],n=e.typeAccessId>0?null!==(l=T.get(e.typeAccessId))&&void 0!==l?l:[e.typeAccessId]:[],o=this.hasAnyGrant(t,n,w,A);u.set(e.conceptId,o)}return u}))}static getConceptIdsWithPermission(e,t,n){return Ri(this,void 0,void 0,(function*(){if(e===xi.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 Ri(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 yi(t,["the_parent_access_inheritance"]);if(n&&n.length>0){const o=yield Hn(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 _n(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 Zt(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 Ri(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 Ri(this,void 0,void 0,(function*(){const t=[null];if(null!=e&&e>0){t.push(e);try{const n=yield yi(e,["the_entity_s_group"]);if(n&&n.length>0){const e=yield Hn(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 Ri(this,void 0,void 0,(function*(){var o;if(t===xi.None)throw new Error("Permission is required");try{const i=null!==(o=(yield Zt(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 Ri(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 Ri(this,void 0,void 0,(function*(){var o;try{const i=null!==(o=(yield Zt(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 Ri(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 Ri(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 Ri(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 Ri(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 Ri(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 Ri(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 Ri(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 Ri(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 Ri(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 Ri(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 Ri(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 Ri(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 Ri(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&xi.Read&&t.push("read"),e&xi.Write&&t.push("write"),e&xi.Execute&&t.push("execute"),e&xi.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)}}Ei.cacheService=new ki,Ei.apiClient=new _i,Ei.isAccessControlEnabled=!1,Ei.initialize();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())}))};const Bi=1,Li=2,Ui=3,Gi=4,Fi=5,Di=6,bi=7,Vi=8;class Oi{constructor(){this.conceptId=0,this.connectionTypeId=0,this.connectionType="",this.count=0}}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 Mi(e){return $i(this,void 0,void 0,(function*(){let t={};for(let n=0;n<e.length;n++){let o=yield ue(e[n].connectionTypeId);e[n].connectionType=o.characterValue,t[e[n].conceptId]=e[n]}return t}))}function ji(e){const t=e.split("_");if(3===t.length){let e=new Oi;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 Hi(e){return e.startsWith("the_")?e.slice(4):e}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())}))},Ji=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){return Ji(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 Zt(e[u].ofTheConceptId),y=yield Zt(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 Zt(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){console.log("this is error",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 Zt(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){console.log("this is error",e)}}}return t}))}var qi=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,t,n){if(e in t){let o=t[e];console.log("this is the count info",o),o&&(n[o.connectionType+"_count"]=o.count,console.log("this is the data updated",n))}}var Qi=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 Yi(e,t="DESC"){return console.log("this is the order",t),"ASC"==t?e.sort((function(e,t){return e.id-t.id})):e.sort((function(e,t){return t.id-e.id})),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())}))};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,t){return Zi(this,void 0,void 0,(function*(){let t=e.outputFormat;e.outputFormat=Di;let o,i=yield function(e){return Pi(this,arguments,void 0,(function*(e,t=""){var o=yield O("application/json",t);const i=n.FreeschemaQueryUrl(),r=JSON.stringify(e);try{const e=yield fetch(i,{method:"POST",headers:o,body:r});return e.ok?yield e.json():(M(e),console.log("This is the freeschema query error",e.status),[])}catch(e){console.log("This is the freeschema query error others",e),function(e,t=""){if(e.status){let n=new $(e.message,!1,e.status,e.stack);throw n.setUrl(t),n}{let n=new $(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=ji(e[n]);t.push(o)}return t}(l);return o=t==Li?yield function(e,t,n,o,i){return Xi(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield Kn(e),s=yield Mi(i);c=Yi(c,r);let a=[];a=yield function(e,t){return Wi(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 Zt(e[u].ofTheConceptId),y=yield Zt(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Zt(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){console.log("this is error",e)}}}else if(0!=f.id&&0!=y.id){let n,o=yield Zt(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){console.log("this is error",e)}}}return t}))}(c,a,o),a=yield function(e,t){return Wi(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 Zt(e[u].ofTheConceptId),y=yield Zt(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Zt(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=Hi(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){console.log("this is error",e)}}}else if(0!=f.id&&0!=y.id){let n,o=yield Zt(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=Hi(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){console.log("this is error",e)}}}return t}))}(c,a,o);let l=yield function(e,t,n,o){return Wi(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,r=yield Zt(e[n].ofTheConceptId),f=yield Zt(e[n].toTheConceptId);if(i.includes(e[n].id)&&(o=!0),1==o){if(0!=r.id&&0!=f.id&&f.id in t){let o,i=yield Zt(e[n].typeId),a=null!==(s=null===(c=f.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);try{if(t[e[n].ofTheConceptId]){let c={id:r.id,data:t[e[n].ofTheConceptId],created_on:e[n].entryTimeStamp},s=i.characterValue+"_reverse";Array.isArray(o[a][s])?o[a][s].push(c):s.includes("_s_")?(o[a][s]=[],o[a][s].push(c)):o[a][s]=c}}catch(e){console.log("this is error",e)}}}else if(0!=r.id&&0!=f.id&&r.id in t){let o,i=yield Zt(e[n].typeId),c=null!==(l=null===(a=r.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);let y=!0,p=i.characterValue;""==p&&(p=f.characterValue,y=!0),""==p&&(p=null!==(u=null===(d=null==f?void 0:f.type)||void 0===d?void 0:d.characterValue)&&void 0!==u?u:"");try{null===(h=null==f?void 0:f.type)||void 0===h||h.characterValue;let r=t[e[n].toTheConceptId];if(r){let s={id:f.id,data:t[e[n].toTheConceptId],created_on:e[n].entryTimeStamp};Array.isArray(o[c])?o[c].push(r):Array.isArray(o[c][p])?o[c][i.characterValue].push(s):p.includes("_s_")?(o[c][p]=[],o[c][p].push(s)):o[c][p]=s}}catch(e){console.log("this is error",e)}}}for(let e=0;e<o.length;e++){let n={};n.id=o[e],n.data=t[o[e]],f.push(n)}return f}))}(c,a,[],n,o,s);return l}))}(c,r,a,s,u,d):t==Ui?yield function(e,t,n,o,i){return Xi(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield Kn(e),s=yield Mi(i);c=Yi(c,r);let a=[];a=yield zi(c,a,o),a=yield function(e,t){return qi(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 Zt(e[u].ofTheConceptId),y=yield Zt(e[u].toTheConceptId);if(n.includes(e[u].id)&&(h=!0),1==h){if(0!=f.id&&0!=y.id){let n,s=yield Zt(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=Hi(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){console.log("this is error",e)}}}else if(0!=f.id&&0!=y.id){let n,o=yield Zt(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=Hi(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){console.log("this is error",e)}}}return t}))}(c,a,o);let l=yield function(e,t,n){return qi(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 Zt(e[n].ofTheConceptId),p=yield Zt(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 Zt(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){console.log("this is error",e)}}}else if(0!=y.id&&0!=p.id&&y.id in t){let o,r=yield Zt(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),Ki(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,Ki(p.id,i,t)}}catch(e){console.log("this is error",e)}}}console.log("this is the main compositions",n);for(let e=0;e<n.length;e++){let o={};console.log("this is the main compositions DATA",t[n[e]]),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==Vi?yield function(e,t,n,o,i){return Xi(this,arguments,void 0,(function*(e,t,n,o,i,r="DESC"){let c=yield Kn(e),s=yield Mi(i);c=Yi(c,r);let a={};a=yield function(e){return Qi(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 Zt(a.ofTheConceptId),d=yield Zt(a.toTheConceptId),u=yield Zt(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;null===(s=u.characterValue)||void 0===s||s.includes("_s_"),t[h.id]||(t[h.id]={}),t[h.id][y]||(t[h.id][y]={}),t[f.id]||(t[f.id]={}),t[f.id][p]=v}return t}))}(c,a,o),a=yield function(e){return Qi(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 Zt(a.ofTheConceptId),d=yield Zt(a.toTheConceptId),u=yield Zt(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?Hi(p):g;const m=C.includes("_s_"),T=!isNaN(Number(C)),N={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(N):t[h.id][y][e?`${C}_reverse`:C]=N}catch(e){console.error("Error formatting concept data:",e)}}return t}))}(c,a,o);let l=yield function(e,t,n){return Qi(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 Zt(n.ofTheConceptId),l=yield Zt(n.toTheConceptId),d=yield Zt(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};Ki(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],Ki(y,i,c)}catch(e){console.error("Error processing connection:",e)}}else console.log("This is the error in the source")}for(const e of n){const n=yield Zt(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 Xi(this,void 0,void 0,(function*(){let t=yield Kn(e);t=Yi(t);let i=[];i=yield zi(t,i,o),i=yield function(e,t,n){return Ji(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 Zt(e[u].ofTheConceptId),y=yield Zt(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 Zt(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=Hi(o));let i={[e]:t},l=o+"_reverse";a.characterValue.includes("_s_")||("string"==typeof n[s]&&(n[s]={}),n[s][l]=i)}catch(e){console.log("this is error",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 Zt(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=Hi(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){console.log("this is error",e)}}}return t}))}(t,i,o);let r=yield function(){return Ji(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 Zt(e[n].ofTheConceptId),h=yield Zt(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 Zt(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){console.log("this is error",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 Zt(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){console.log("this is error",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 tr{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=Bi,this.name="",this.reverse=!1,this.limit=!1,this.filterAncestor="",this.includeInFilter=!1,this.isOldConnectionType=!1}}var nr=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 or(e,t){return nr(this,arguments,void 0,(function*(e,t,n=!1){let o=[];if(n){let n=yield En(e),i=yield xn(t);for(let e=0;e<n.length;e++)n[e].typeId==i.id&&o.push(n[e])}else{let n=yield _n(e);for(let e=0;e<n.length;e++)Z.AddConnection(n[e]);let i=yield xn(t);for(let e=0;e<n.length;e++)n[e].typeId==i.id&&o.push(n[e])}return o}))}function ir(e,t,n){return nr(this,arguments,void 0,(function*(e,t,n,o=!1){let i=[],r=[];if(i=o?yield or(t,n,o):yield or(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 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())}))};class cr{constructor(){this.actions={concepts:[],connections:[]},this.success=!0,this.transactionId=Math.random().toString().substring(5)}initialize(){return rr(this,void 0,void 0,(function*(){yield it.initializeTransaction(this.transactionId)}))}markAction(){return rr(this,void 0,void 0,(function*(){yield it.markTransactionActions(this.transactionId,this.actions)}))}rollbackTransaction(){return rr(this,void 0,void 0,(function*(){this.success=!1,this.actions={concepts:[],connections:[]},yield it.rollbackTransaction(this.transactionId,this.actions)}))}commitTransaction(){return rr(this,void 0,void 0,(function*(){if(!this.success)throw Error("Query Transaction Expired");yield it.SyncDataOnline(this.transactionId),this.actions={concepts:[],connections:[]},this.success=!1}))}MakeTheInstanceConcept(e,t){return rr(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 St(e,t,n,o,i,r,c,this.actions);return yield this.markAction(),s}catch(e){throw console.log(e),this.success=!1,e}}))}CreateConnection(e,t,n){return rr(this,void 0,void 0,(function*(){try{if(!this.success)throw Error("Query Transaction Expired");const o=yield Wt(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 rr(this,void 0,void 0,(function*(){try{if(!this.success)throw Error("Query Transaction Expired");const i=yield Cn(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 rr(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 Ht(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}}))}}function sr(e=""){o.BearerAccessToken=e}function ar(e="",t="",i="CCSApp",c){const s=c||new mi;if(Ei.setBaseUrl(s.accessControlBaseUrl),Ei.setEnabled(s.enableAccessControl),n.BASE_URL=e,n.AI_URL=s.aiUrl,t&&(n.NODE_URL=t),console.log("This is the base url",n.BASE_URL),s.hasOAuthCredentials()){const e=s.applicationName||i;o.setOAuthCredentials(s.clientId,s.clientSecret,e),r(s.clientId,s.clientSecret,e,!0)}else s.hasAccessToken()&&(o.BearerAccessToken=s.accessToken);(function(){return Ai(this,void 0,void 0,(function*(){return yield new g(!0),yield function(){return Ii(this,void 0,void 0,(function*(){}))}(),!0}))})().then((()=>{const e=(new Date).getTime();(function(){return F(this,void 0,void 0,(function*(){(new Date).getTime();var e=yield N();if(Array.isArray(e))for(var t=0;t<e.length;t++){let n=e[t];G.AddConceptToMemory(n)}(new Date).getTime()}))})().then((()=>{w.isDataLoaded=!0,w.isCharacterLoaded=!0,w.isTypeLoaded=!0;let t=(new Date).getTime()-e;console.log("The time taken to prepare concept data is ",t)})),function(){return Ni(this,void 0,void 0,(function*(){var e=yield I();if(Array.isArray(e))for(var t=0;t<e.length;t++){let n=e[t];je.AddConceptToMemory(n)}}))}().then((()=>{w.isLocalDataLoaded=!0,w.isLocalTypeLoaded=!0,w.isLocalCharacterLoaded=!0;let t=(new Date).getTime()-e;console.log("The time taken to prepare local concept ",t)})),function(){return Ti(this,void 0,void 0,(function*(){!function(){Ti(this,void 0,void 0,(function*(){var e=yield I();if(Array.isArray(e))for(var t=0;t<e.length;t++)We.AddConnection(e[t])}))}()}))}().then((()=>{w.isLocalConnectionLoaded=!0})),function(){return Ti(this,void 0,void 0,(function*(){!function(){Ti(this,void 0,void 0,(function*(){var e=yield N();if(Array.isArray(e))for(var t=0;t<e.length;t++)Z.AddConnectionToMemory(e[t])}))}()}))}().then((()=>{w.isConnectionLoaded=!0,w.isConnectionTypeLoaded=!0;let t=(new Date).getTime()-e;console.log("The time taken to prepare connections ",t)}))}))}var lr=exports;for(var dr in t)lr[dr]=t[dr];t.__esModule&&Object.defineProperty(lr,"__esModule",{value:!0})})();
@@ -47,6 +47,10 @@ export declare class CCSConfig {
47
47
  accessToken: string;
48
48
  /** Whether to enable AI features. Defaults to true */
49
49
  enableAi: boolean;
50
+ /** Whether to enable access control checks. Defaults to false (allow all access). */
51
+ enableAccessControl: boolean;
52
+ /** Base URL for Access Control API. Falls back to env/default when not provided. */
53
+ accessControlBaseUrl?: string;
50
54
  /**
51
55
  * Dictionary of feature flags for controlling CCS behavior.
52
56
  * Available flags:
@@ -86,6 +90,8 @@ export declare class CCSConfig {
86
90
  * const config = new CCSConfig({
87
91
  * aiUrl: "https://custom-ai.example.com",
88
92
  * enableAi: false,
93
+ * enableAccessControl: true,
94
+ * accessControlBaseUrl: "https://access.example.com/api/access-control",
89
95
  * clientId: "123456",
90
96
  * clientSecret: "secret",
91
97
  * flags: {
@@ -16,7 +16,21 @@ import { PermissionSet } from './PermissionSet';
16
16
  export declare class AccessControlService {
17
17
  private static cacheService;
18
18
  private static apiClient;
19
+ private static isAccessControlEnabled;
19
20
  private static initialize;
21
+ /**
22
+ * Enable or disable access control checks globally.
23
+ * When disabled, checkAccess/checkAccessBulk/getConceptIdsWithPermission allow all input concepts.
24
+ */
25
+ static setEnabled(isEnabled: boolean): void;
26
+ /**
27
+ * Returns whether access control checks are currently enabled.
28
+ */
29
+ static getEnabled(): boolean;
30
+ /**
31
+ * Set access-control API base URL. If omitted, APIClientService fallback order is used.
32
+ */
33
+ static setBaseUrl(baseUrl?: string): void;
20
34
  /**
21
35
  * Check whether a user/entity has the specified permission on a single concept.
22
36
  * Delegates to checkAccessBulk for full inheritance + group resolution.
@@ -228,4 +242,12 @@ export declare class AccessControlService {
228
242
  * Clear super admin cache
229
243
  */
230
244
  static clearSuperAdminCache(): void;
245
+ /**
246
+ * Update access cache entry (for MQTT-driven cache sync)
247
+ */
248
+ static updateAccessCache(accessId: number, permission: string, entityId: number | null | undefined, hasAccess: boolean): void;
249
+ /**
250
+ * Update super admin cache entry (for MQTT-driven cache sync)
251
+ */
252
+ static updateSuperAdminCache(entityId: number, isSuperAdmin: boolean): void;
231
253
  }
@@ -162,7 +162,9 @@ declare function updateAccessToken(accessToken?: string): void;
162
162
  * clientId: '101084838',
163
163
  * clientSecret: 'your-client-secret',
164
164
  * aiUrl: 'https://ai.freeschema.com',
165
- * enableAi: true
165
+ * enableAi: true,
166
+ * enableAccessControl: true,
167
+ * accessControlBaseUrl: 'https://access.example.com/api/access-control'
166
168
  * });
167
169
  * init('https://api.freeschema.com', '', 'MyApp', config);
168
170
  * ```
@@ -174,6 +176,8 @@ declare function updateAccessToken(accessToken?: string): void;
174
176
  * aiUrl: 'https://ai.example.com',
175
177
  * accessToken: 'token',
176
178
  * enableAi: true,
179
+ * enableAccessControl: true,
180
+ * accessControlBaseUrl: 'https://access.example.com/api/access-control',
177
181
  * flags: {
178
182
  * logApplication: true,
179
183
  * accessTracker: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mftsccs-node",
3
- "version": "0.2.21",
3
+ "version": "0.2.23",
4
4
  "environment": "production",
5
5
  "description": "Full Pack of concept and connection system",
6
6
  "main": "dist/bundle.js",