import { IDatabaseModel , IOrgConnectionData , IAppModel } from "../components/helper_interfaces" ; import { NonSerializable , AppUtils } from "../components/appUtils" ; import { CONSTANTS , DATA_MEDIA_TYPE , SOURCE_TYPE } from "../components/statics" ; import "reflect-metadata" ; import "es6-shim" ; import { SObjectDescribe } from "./sobjectDescribe" ; /**
 * Represents  salesforce org
 */ export class Org implements IDatabaseModel , IAppModel { constructor ( init ? ) { if ( init ) { this . initialize ( init ) ; } } id : string ; orgName : string ; name : string = "" ; alias : string ; media : DATA_MEDIA_TYPE = DATA_MEDIA_TYPE . Unknown ; @ NonSerializable ( ) orgId : string ; @ NonSerializable ( ) instanceUrl : string ; @ NonSerializable ( ) accessToken : string ; @ NonSerializable ( ) sourceType : SOURCE_TYPE = SOURCE_TYPE . Unknown ; @ NonSerializable ( ) objectsMap : Map < string , SObjectDescribe > = new Map < string , SObjectDescribe > ( ) ; @ NonSerializable ( ) errorMessage : string ; get objects ( ) : SObjectDescribe [ ] { return [ ... this . objectsMap . values ( ) ] ; } get connectionData ( ) : IOrgConnectionData { return { instanceUrl : this . instanceUrl , accessToken : this . accessToken , apiVersion : CONSTANTS . DEFAULT_API_VERSION } ; } getConnection ( ) { return AppUtils . createOrgConnection ( this . connectionData ) ; } get isConnected ( ) : boolean { return ! ! this . accessToken || this . isFile ( ) ; } get aliasOrName ( ) : string { return this . alias || this . name ; } initialize ( init ? ) { if ( init ) { AppUtils . objectAssignSafe ( this , init ) ; } this . id = this . id || AppUtils . makeId ( ) ; } isValid ( ) { return this . media != DATA_MEDIA_TYPE . Unknown ; } isDescribed ( ) { return this . objectsMap . size > 0 ; } isOrg ( ) { return this . media == DATA_MEDIA_TYPE . Org ; } isFile ( ) { return this . media == DATA_MEDIA_TYPE . File ; } }