????
Current Path : C:/inetpub/vhost/dbadm.gdtsolutions.vn/web/js/ |
Current File : C:/inetpub/vhost/dbadm.gdtsolutions.vn/web/js/plugin-sql-editor-511b5c90d623574ae817.js |
/*! For license information please see ../license.txt */ "use strict";(self.webpackChunk_cloudbeaver_product_default=self.webpackChunk_cloudbeaver_product_default||[]).push([[36821],{27929:(e,t,s)=>{s.d(t,{M:()=>i});const i=(0,s(44745).M)("sql-editor-state")},32720:(e,t,s)=>{s.d(t,{Jf:()=>l});var i=s(3065),r=s(92482);const n=i.Ik({tabId:i.Yj(),groupId:i.Yj(),indexInResultSet:i.ai(),presentationId:i.Yj(),valuePresentationId:i.me(i.Yj())}),o=i.Ik({tabId:i.Yj(),order:i.ai()}),a=i.Ik({groupId:i.Yj(),modelId:i.Yj(),order:i.ai(),nameOrder:i.ai(),query:i.Yj()}),c=i.Ik({id:i.Yj(),order:i.ai(),name:i.Yj(),icon:i.Yj()}),u=i.Ik({tabId:i.Yj(),order:i.ai(),query:i.Yj(),options:i.g1(i.bz()).optional()}),d=c.extend({selectedLogTypes:i.YO(i.k5(r.d))}),l=i.Ik({editorId:i.Yj(),datasourceKey:i.Yj(),source:i.Yj().optional(),order:i.ai(),currentTabId:i.Yj().optional(),tabs:i.YO(c),resultGroups:i.YO(a),resultTabs:i.YO(n),statisticsTabs:i.YO(o),executionPlanTabs:i.YO(u),outputLogsTab:d.optional(),currentModeId:i.Yj().optional(),modeState:i.YO(i.PV([i.Yj(),i.bz()]))})},22071:(e,t,s)=>{s.r(t),s.d(t,{LocaleService:()=>a});var i=s(1118),r=s(82103),n=s(5576),o=s(34227);let a=class LocaleService extends r.j{constructor(e){super(),this.localizationService=e}register(){this.localizationService.addProvider(this.provider.bind(this))}load(){}async provider(e){switch(e){case"ru":return(await Promise.all([s.e(92436),s.e(99181)]).then(s.bind(s,67253))).default;case"it":return(await Promise.all([s.e(32756),s.e(13419)]).then(s.bind(s,59417))).default;case"zh":return(await Promise.all([s.e(52041),s.e(35800)]).then(s.bind(s,29485))).default;case"fr":return(await Promise.all([s.e(29671),s.e(68657)]).then(s.bind(s,33130))).default;default:return(await Promise.all([s.e(41114),s.e(91038)]).then(s.bind(s,36035))).default}}};a=(0,i.Cg)([(0,n._)(),(0,i.Sn)("design:paramtypes",[o.LocalizationService])],a)},7905:(e,t,s)=>{s.r(t),s.d(t,{MenuBootstrap:()=>P});var i=s(1118),r=s(82103),n=s(5576),o=s(77480),a=s(8385),c=s(26160),u=s(25139),d=s(19697),l=s(48995),h=s(59262),p=s(2280),S=s(72877),g=s(79023),x=s(81604),v=s(75525),m=s(64756),b=s(98391),y=s(22247),f=s(95296),_=s(23653),q=s(47291),I=s(18174),C=s(65457),E=s(27145),w=s(94798),j=s(27929),T=s(80957),D=s(64486),R=s(85084),A=s(20038);let P=class MenuBootstrap extends r.j{constructor(e,t,s,i,r){super(),this.menuService=e,this.actionService=t,this.keyBindingService=s,this.sqlDataSourceService=i,this.windowEventsService=r}register(){this.windowEventsService.onFocusChange.addHandler((0,a.n)(this.focusChangeHandler.bind(this),3e5,!1)),this.actionService.addHandler({id:"sql-editor-base-handler",contexts:[j.M],actions:[c.t],isActionApplicable:(e,t)=>{const s=e.get(j.M),i=this.sqlDataSourceService.get(s.editorId);return t===c.t&&!1===i?.isAutoSaveEnabled},handler:async(e,t)=>{if(t===c.t){const t=e.get(j.M),s=this.sqlDataSourceService.get(t.editorId);if(!s)return;await s.save()}},isDisabled:(e,t)=>{if(t===c.t){const t=e.get(j.M),s=this.sqlDataSourceService.get(t.editorId);return!s||(s.isLoading()||s.isSaved||s.isReadonly())}return!1},getActionInfo:(e,t)=>t===c.t?{...t.info,label:""}:t.info}),this.menuService.addCreator({menus:[A.F],contexts:[j.M],isApplicable:e=>{const t=e.get(j.M),s=this.sqlDataSourceService.get(t.editorId);return!!s?.hasFeature(T.A.script)},getItems:(e,t)=>[...t,c.t]}),this.keyBindingService.addKeyBindingHandler({id:"sql-editor-save",binding:u.c,actions:[c.t],contexts:[j.M],handler:async e=>{const t=e.get(j.M),s=this.sqlDataSourceService.get(t.editorId);s&&await s.save()}}),this.actionService.addHandler({id:"sql-editor-actions",actions:[v.C,m.R,b._,y._,d.O,l.u,f.T,_.M],contexts:[R.j],isActionApplicable:(e,t)=>{const s=e.get(R.j);return(!s.readonly||![y._,d.O,l.u].includes(t))&&(!(!s.dataSource?.hasFeature(T.A.executable)&&[v.C,m.R,b._,f.T,_.M].includes(t))&&!(!s.dataSource?.hasFeature(T.A.query)&&[v.C,m.R,f.T].includes(t)))},isDisabled:(e,t)=>!e.has(R.j),handler:this.sqlEditorActionHandler.bind(this)}),this.keyBindingService.addKeyBindingHandler({id:"sql-editor-execute",binding:q.$,contexts:[R.j],isBindingApplicable:(e,t)=>t===v.C,handler:this.sqlEditorActionHandler.bind(this)}),this.keyBindingService.addKeyBindingHandler({id:"sql-editor-execute-new",binding:I.q,contexts:[R.j],isBindingApplicable:(e,t)=>t===m.R,handler:this.sqlEditorActionHandler.bind(this)}),this.keyBindingService.addKeyBindingHandler({id:"sql-editor-execute-script",binding:C.d,contexts:[R.j],isBindingApplicable:(e,t)=>{const s=e.get(R.j);return t===b._&&!0===s?.dataSource?.hasFeature(T.A.executable)},handler:this.sqlEditorActionHandler.bind(this)}),this.keyBindingService.addKeyBindingHandler({id:"sql-editor-format",binding:E.p,contexts:[R.j],isBindingApplicable:(e,t)=>t===y._,handler:this.sqlEditorActionHandler.bind(this)}),this.keyBindingService.addKeyBindingHandler({id:"sql-editor-redo",binding:h.V,contexts:[R.j],isBindingApplicable:(e,t)=>t===d.O,handler:this.sqlEditorActionHandler.bind(this)}),this.keyBindingService.addKeyBindingHandler({id:"sql-editor-undo",binding:p.t,contexts:[R.j],isBindingApplicable:(e,t)=>t===l.u,handler:this.sqlEditorActionHandler.bind(this)}),this.keyBindingService.addKeyBindingHandler({id:"sql-editor-show-execution-plan",binding:w.Q,contexts:[R.j],isBindingApplicable:(e,t)=>t===f.T,handler:this.sqlEditorActionHandler.bind(this)})}sqlEditorActionHandler(e,t){const s=e.get(R.j);switch(t){case v.C:s.executeQuery();break;case m.R:s.executeQueryNewTab();break;case b._:if(s.activeSegmentMode.activeSegmentMode)return;s.executeScript();break;case y._:if(s.activeSegmentMode.activeSegmentMode)return;s.formatScript();break;case l.u:s.dataSource?.history.undo();break;case d.O:s.dataSource?.history.redo();break;case f.T:s.showExecutionPlan()}}async focusChangeHandler(e){if(e){const e=this.sqlDataSourceService.dataSources.values();for(const[t,s]of e)s.markOutdated()}}};P=(0,i.Cg)([(0,n._)(),(0,i.Sn)("design:paramtypes",[S.MenuService,g.ActionService,x.KeyBindingService,D.SqlDataSourceService,o.WindowEventsService])],P)},85855:(e,t,s)=>{s.d(t,{E:()=>QueryDataSource});var i=s(94866),r=s(43974),n=s(35721),o=s(63641),a=s(78186),c=s(84941);class QueryDataSource extends o.b{get canCancel(){return this.currentTask?.cancellable||!1}get cancelled(){return this.currentTask?.cancelled||!1}constructor(e,t,s){super(e,t,s),this.serviceInjector=e,this.currentTask=null,this.requestInfo={originalQuery:"",requestDuration:0,requestMessage:"",requestFilter:"",source:null,query:""},(0,i.Gn)(this,{currentTask:i.sH.ref})}isLoadable(){return super.isLoadable()&&!!this.executionContext?.context}isReadonly(e){return super.isReadonly(e)||!1===this.getResult(e)?.data?.hasRowIdentifier}isDisabled(e){return!this.getResult(e)?.data&&null===this.error||!this.executionContext?.context}async cancel(){await super.cancel(),await(this.currentTask?.cancel())}async save(e){if(!this.options||!this.executionContext?.context)return e;try{for(const t of e){if(null===t.id)continue;const e=this.executionContext.context,s=this.options.connectionKey.projectId,i=this.options.connectionKey.connectionId,o=e.id,u={projectId:s,connectionId:i,contextId:o,resultsId:t.id};let d;t.dataFormat===r.fev.Resultset?d=this.actions.get(t,a.G):t.dataFormat===r.fev.Document&&(d=this.actions.get(t,c.q));let l=[];d instanceof a.G&&(l=d.getBlobsToUpload());for(const e of l){const t=(0,n.u)();await this.graphQLService.sdk.uploadBlobResultSet(t,e.blob),e.fileId=t}d&&d.fillBatch(u);const h=await this.graphQLService.sdk.updateResultsDataBatch(u);if(d){const s=this.transformResults(e,h.result.results,0).find((e=>e.id===t.id));s&&d.applyUpdate(s)}this.requestInfo={...this.requestInfo,requestDuration:h.result.duration,requestMessage:"Saved successfully",source:this.options.query}}this.clearError()}catch(e){throw this.error=e,e}return e}setOptions(e){return this.options=e,this}getResults(e,t,s){return this.requestInfo={originalQuery:t.fullQuery||this.options?.query||"",requestDuration:t.duration||0,requestMessage:t.statusMessage||"",requestFilter:t.filterText||"",source:this.options?.query||null,query:this.options?.query||""},t.results?this.transformResults(e,t.results,s):null}async request(e){const t=this.options,s=this.executionContext,i=this.executionContext?.context;if(!t||!s||!i)return e;const r=this.count;let n;1===e.length&&e[0].contextId===s.context.id&&e[0].connectionId===s.context?.connectionId&&null!==e[0].id&&this.requestInfo.query===this.options?.query&&(n=e[0].id);const o=this.asyncTaskInfoService.create((async()=>{const{taskInfo:e}=await this.graphQLService.sdk.asyncSqlExecuteQuery({projectId:i.projectId,connectionId:i.connectionId,contextId:i.id,query:t.query,resultId:n,filter:{offset:this.offset,limit:r,constraints:t.constraints,where:t.whereFilter||void 0},dataFormat:this.dataFormat,readLogs:t.readLogs});return e}));this.currentTask=s.run((async()=>{const e=await this.asyncTaskInfoService.run(o),{result:t}=await this.graphQLService.sdk.getSqlExecuteTaskResults({taskId:e.id});return t}),(()=>this.asyncTaskInfoService.cancel(o.id)),(()=>this.asyncTaskInfoService.remove(o.id)));try{const t=await this.currentTask,s=this.getResults(i,t,r);return this.clearError(),s||e}catch(e){throw this.error=e,e}}transformResults(e,t,s){return t.map(((t,i)=>({id:t.resultSet?.id||null,uniqueResultId:`${e.connectionId}_${e.id}_${i}`,projectId:e.projectId,connectionId:e.connectionId,contextId:e.id,dataFormat:t.dataFormat,updateRowCount:t.updateRowCount||0,loadedFully:(t.resultSet?.rowsWithMetaData?.length||0)<s,count:t.resultSet?.rowsWithMetaData?.length||0,totalCount:null,data:t.resultSet})))}}},16476:(e,t,s)=>{s.d(t,{m:()=>i});const i=(0,s(50420).j)((()=>Promise.all([s.e(11502),s.e(97493),s.e(67557),s.e(64435),s.e(73676),s.e(88273),s.e(63190),s.e(44134),s.e(36821),s.e(18682),s.e(62570),s.e(39037)]).then(s.bind(s,39356)).then((e=>e.SqlEditor))))},68842:(e,t,s)=>{s.d(t,{v:()=>h});var i=s(1118),r=s(94866),n=s(44017),o=s(42891),a=s(86233),c=s(99553),u=s(80957),d=s(94786);class SqlDataSourceHistory{constructor(){this.lastAddTime=0,this.state=(0,d.R)(),this.onNavigate=new n.H,(0,r.l_)(this,{onNavigate:!1})}add(e,t){this.state.history[this.state.historyIndex].value!==e&&(this.state.historyIndex+1<this.state.history.length&&(this.state.history.splice(this.state.historyIndex+1),this.lastAddTime=0),this.lastAddTime+1e3<Date.now()?(this.state.history.push({value:e,source:t}),this.state.historyIndex=this.state.history.length-1,this.lastAddTime=Date.now()):this.state.history[this.state.history.length-1]={value:e,source:t})}undo(){if(0===this.state.historyIndex)return;this.state.historyIndex--;const e=this.state.history[this.state.historyIndex].value;this.onNavigate.execute(e)}redo(){if(this.state.historyIndex+1>=this.state.history.length)return;this.state.historyIndex++;const e=this.state.history[this.state.historyIndex].value;this.onNavigate.execute(e)}restore(e){this.state=e}clear(){this.state=(0,d.R)()}}const l="history";let h=class BaseSqlDataSource{static{this.key="base"}get cursor(){return this.innerCursorState}get isIncomingChanges(){return void 0!==this.incomingScript||null!==this.incomingExecutionContext}get isAutoSaveEnabled(){return!0}get isScriptSaved(){return this.script===this.baseScript}get isExecutionContextSaved(){return(0,o.V)(this.baseExecutionContext?.connectionId,this.executionContext?.connectionId,void 0)&&(0,o.V)(this.baseExecutionContext?.defaultCatalog,this.executionContext?.defaultCatalog,void 0)&&(0,o.V)(this.baseExecutionContext?.defaultSchema,this.executionContext?.defaultSchema,void 0)}get isSaved(){return this.isScriptSaved&&this.isExecutionContextSaved}get sourceKey(){return Object.getPrototypeOf(this).constructor.key}get projectId(){return this.executionContext?.projectId??null}get features(){return[u.A.script,u.A.query,u.A.executable]}constructor(e="/icons/sql_script_m.svg"){this.icon=e,this.databaseModels=[],this.incomingScript=void 0,this.incomingExecutionContext=null,this.exception=void 0,this.message=void 0,this.outdated=!0,this.editing=!0,this.innerCursorState={begin:0,end:0},this.history=new SqlDataSourceHistory,this.onUpdate=new n.H,this.onSetScript=new n.H,this.onDatabaseModelUpdate=new n.H,this.onDatabaseModelUpdate.setInitialDataGetter((()=>this.databaseModels)),this.onSetScript.next(this.onUpdate),this.onSetScript.addHandler((({script:e,source:t})=>{t!==l&&this.history.add(e)})),this.history.onNavigate.addHandler((e=>this.setScript(e,l))),(0,r.Gn)(this,{isSaved:r.EW,isIncomingChanges:r.EW,isAutoSaveEnabled:r.EW,isScriptSaved:r.EW,isExecutionContextSaved:r.EW,setScript:r.XI,setIncomingScript:r.XI,setName:r.XI,setExecutionContext:r.XI,setIncomingExecutionContext:r.XI,markUpdated:r.XI,markOutdated:r.XI,setEditing:r.XI,setProject:r.XI,applyIncoming:r.XI,keepCurrent:r.XI,reset:r.XI,databaseModels:r.sH.ref,exception:r.sH.ref,outdated:r.sH.ref,message:r.sH.ref,editing:r.sH.ref,innerCursorState:r.sH.ref,incomingScript:r.sH.ref,incomingExecutionContext:r.sH.ref})}setScript(e,t){this.onSetScript.execute({script:e,source:t})}setIncomingScript(e){e!==this.baseScript?this.script===this.baseScript?(this.setBaseScript(e),this.setScript(e)):this.incomingScript=e:this.incomingScript=void 0}setName(e){this.onUpdate.execute()}setExecutionContext(e){this.onUpdate.execute()}setIncomingExecutionContext(e){e=(0,r.HO)(e),this.setBaseExecutionContext(e),this.setExecutionContext(e)}isOpened(){return!0}isError(){return(0,a.rp)(this.exception)}isEditing(){return this.editing}isReadonly(){return!0}isOutdated(){return this.outdated}markUpdated(){this.outdated=!1}markOutdated(){this.outdated=!0}isLoading(){return!1}isLoaded(){return!(Array.isArray(this.exception)?this.exception.some(Boolean):this.exception)}hasFeature(e){return this.features.includes(e)}setCursor(e,t=e){if(e>t)throw new Error("Cursor begin can not be greater than the end of it");const s=this.script.length;this.innerCursorState=Object.freeze({begin:Math.min(e,s),end:Math.min(t,s)}),this.onUpdate.execute()}setEditing(e){this.editing=e}setProject(e){this.onUpdate.execute()}keepCurrent(){void 0!==this.incomingScript&&(this.setBaseScript(this.incomingScript),this.incomingScript=void 0),null!==this.incomingExecutionContext&&(this.setBaseExecutionContext(this.incomingExecutionContext),this.incomingExecutionContext=null)}applyIncoming(){void 0!==this.incomingScript&&this.setBaseScript(this.incomingScript),null!==this.incomingExecutionContext&&this.setBaseExecutionContext(this.incomingExecutionContext),this.reset()}save(){this.markUpdated()}load(){this.markUpdated()}open(){this.markUpdated()}reset(){this.setScript(this.baseScript),this.setExecutionContext(this.baseExecutionContext),this.incomingScript=void 0,this.incomingExecutionContext=null}dispose(){}};h=(0,i.Cg)([(0,c.V)(),(0,i.Sn)("design:paramtypes",[Object])],h)},80957:(e,t,s)=>{var i;s.d(t,{A:()=>i}),function(e){e[e.script=0]="script",e[e.query=1]="query",e[e.executable=2]="executable",e[e.setName=3]="setName",e[e.setProject=4]="setProject"}(i||(i={}))},90620:(e,t,s)=>{s.d(t,{w:()=>LocalStorageSqlDataSource});var i=s(94866),r=s(68842),n=s(80957);class LocalStorageSqlDataSource extends r.v{get baseScript(){return this.state.script}get baseExecutionContext(){return this.state.executionContext}static{this.key="local-storage"}get name(){return this.state.name??null}get script(){return this.state.script}get executionContext(){return this.state.executionContext}get features(){return[n.A.script,n.A.query,n.A.executable,n.A.setName]}get isSaved(){return!0}get projectId(){return null}constructor(e){super(),this.bindState(e),(0,i.Gn)(this,{state:i.sH.ref,script:i.EW,executionContext:i.EW})}isReadonly(){return!1}setName(e){this.state.name=e??void 0,super.setName(e)}canRename(e){return!0}setScript(e){this.state.script=e,super.setScript(e)}setExecutionContext(e){this.state.executionContext=e,super.setExecutionContext(e)}bindState(e){this.state=e,this.outdated=!1,this.history.restore(e.history)}setBaseScript(e){this.state.script=e}setBaseExecutionContext(e){this.state.executionContext=e}}},17402:(e,t,s)=>{s.r(t),s.d(t,{LocalStorageSqlDataSourceBootstrap:()=>l});var i=s(1118),r=s(94866),n=s(82103),o=s(5576),a=s(1513),c=s(94786);function validateSqlDataSourceHistoryState(e){return"object"==typeof e&&function validateSqlDataSourceHistoryData(e){return Array.isArray(e)&&e.every((e=>"object"==typeof e&&null!==e&&"string"==typeof e.value&&["string","undefined"].includes(typeof e.source)))}(e.history)&&"number"==typeof e.historyIndex&&e.historyIndex>=0&&e.historyIndex<=e.history.length}var u=s(64486),d=s(90620);let l=class LocalStorageSqlDataSourceBootstrap extends n.j{constructor(e,t){super(),this.sqlDataSourceService=e,this.dataSourceStateState=new Map,this.dataSourceStateState=new Map,(0,r.Gn)(this,{createState:r.XI,dataSourceStateState:r.sH.deep}),t.registerSettings("local-storage-sql-data-source",this.dataSourceStateState,(()=>new Map),(e=>{try{for(const[t,s]of Array.from(e.entries()))"string"==typeof s.script&&["string","undefined","object"].includes(typeof s.name)&&["undefined","object"].includes(typeof s.executionContext)&&["string","undefined","object"].includes(typeof s.executionContext?.connectionId)&&["string","undefined","object"].includes(typeof s.executionContext?.id)&&["string","undefined","object"].includes(typeof s.executionContext?.defaultCatalog)&&["string","undefined","object"].includes(typeof s.executionContext?.defaultSchema)&&validateSqlDataSourceHistoryState(s.history)||e.delete(t)}catch(t){e.clear(),console.log(t)}return e}),this.bindState.bind(this),"indexed")}register(){this.sqlDataSourceService.register({key:d.w.key,getDataSource:(e,t)=>new d.w(this.createState(e,t)),onDestroy:(e,t)=>this.deleteState(t)})}load(){}createState(e,t){let s=this.dataSourceStateState.get(e);return s||(s=(0,r.sH)({name:t?.name,script:t?.script??"",executionContext:t?.executionContext,history:(0,c.R)(t?.script)}),this.dataSourceStateState.set(e,s)),s}bindState(){for(const[e,t]of this.sqlDataSourceService.dataSources)t instanceof d.w&&t.bindState(this.createState(e))}deleteState(e){this.dataSourceStateState.delete(e)}};l=(0,i.Cg)([(0,o._)(),(0,i.Sn)("design:paramtypes",[u.SqlDataSourceService,a.StorageService])],l)},60088:(e,t,s)=>{s.d(t,{N:()=>MemorySqlDataSource});var i=s(94866),r=s(68842),n=s(80957);class MemorySqlDataSource extends r.v{get baseScript(){return this._script}get baseExecutionContext(){return this._executionContext}static{this.key="memory"}get name(){return this._name}get script(){return this._script}get executionContext(){return this._executionContext}get features(){return[n.A.script,n.A.query,n.A.executable,n.A.setName]}get isSaved(){return!0}get projectId(){return null}constructor(e=null,t="",s){super(),this._name=e,this._script=t,this._executionContext=s,this.outdated=!1,(0,i.Gn)(this,{_script:i.sH,_executionContext:i.sH,script:i.EW,executionContext:i.EW})}isReadonly(){return!1}setScript(e){this._script=e,super.setScript(e)}setExecutionContext(e){this._executionContext=e,super.setExecutionContext(e)}setName(e){this._name=e,super.setName(e)}canRename(e){return!0}setBaseScript(e){this._script=e}setBaseExecutionContext(e){this._executionContext=e}}},94786:(e,t,s)=>{function createSqlDataSourceHistoryInitialState(e=""){return{history:[{value:e,source:"initial"}],historyIndex:0}}s.d(t,{R:()=>createSqlDataSourceHistoryInitialState})},64486:(e,t,s)=>{s.r(t),s.d(t,{SqlDataSourceService:()=>c});var i=s(1118),r=s(94866),n=s(5576),o=s(44017),a=s(60088);let c=class SqlDataSourceService{get dataSources(){return Array.from(this.providers.entries()).map((([e,t])=>[e,t.dataSource]))}constructor(){this.dataSourceProviders=new Map,this.providers=new Map,this.onCreate=new o.H,this.onUpdate=new o.H,this.onCreate.next(this.onUpdate,(([e])=>({editorId:e,datasource:this.get(e)}))),this.register({key:a.N.key,getDataSource:(e,t)=>new a.N(t?.name,t?.script,t?.executionContext)}),(0,r.Gn)(this,{dataSources:r.EW,providers:r.sH.shallow,create:r.XI,destroy:r.XI})}get(e){return this.providers.get(e)?.dataSource}create(e,t,s){const i=e.editorId,r=this.dataSourceProviders.get(t);if(!r)throw new Error(`SQL Data Source Provider with key (${t}) not found`);let n=this.providers.get(i);return n?.provider.key!==t&&(n&&this.destroyProvider(i,n),n={provider:r,dataSource:r.getDataSource(i,s),isActionActive:!1},n.dataSource.onUpdate.next(this.onUpdate,(()=>({editorId:i,datasource:n.dataSource}))),this.providers.set(i,n),e.datasourceKey=t,this.onCreate.execute([i,t])),n.dataSource}async executeAction(e,t,s){const i=this.providers.get(e);if(i){if(!i.isActionActive)try{return i.isActionActive=!0,await t(i.dataSource)}finally{i.isActionActive=!1}}else s()}async canDestroy(e){const t=this.providers.get(e);return await(t?.provider.canDestroy?.(t.dataSource,e))??!0}async destroySilent(e){const t=this.providers.get(e);t&&await this.destroyProvider(e,t)}async destroy(e){const t=this.providers.get(e);t&&await this.destroyProvider(e,t)}async unload(e){const t=this.providers.get(e);t&&await this.unloadProvider(e,t),this.providers.delete(e)}register(e){if(this.dataSourceProviders.has(e.key))throw new Error(`SQL Data Source with key (${e.key}) already registered`);this.dataSourceProviders.set(e.key,e)}async unloadProvider(e,t){await(t.provider.onUnload?.(t.dataSource,e)),await t.dataSource.dispose()}async destroyProvider(e,t){await(t.provider.onDestroy?.(t.dataSource,e)),await t.dataSource.dispose()}};c=(0,i.Cg)([(0,n._)(),(0,i.Sn)("design:paramtypes",[])],c)},56735:(e,t,s)=>{s.r(t),s.d(t,{SqlDialectInfoService:()=>a});var i=s(1118),r=s(927),n=s(5576),o=s(14452);let a=class SqlDialectInfoService{constructor(e,t){this.connectionDialectResource=e,this.notificationService=t}async formatScript(e,t){try{return await this.connectionDialectResource.formatScript(e,t)}catch(e){this.notificationService.logException(e,"Failed to format script")}return t}getDialectInfo(e){return this.connectionDialectResource.get(e)}async loadSqlDialectInfo(e){if(!this.connectionDialectResource.has(e))try{return this.connectionDialectResource.load(e)}catch(e){this.notificationService.logException(e,"Failed to load SqlDialectInfo")}return this.getDialectInfo(e)}};a=(0,i.Cg)([(0,n._)(),(0,i.Sn)("design:paramtypes",[r.ConnectionDialectResource,o.NotificationService])],a)},39356:(e,t,s)=>{s.r(t),s.d(t,{SqlEditor:()=>me});var i=s(41773),r=s(7838),n=s(64928),o=s(67590),a=s(69519),c=s(7167),u=s(51565),d=s(18662),l=s(16796),h=s(18699),p=s(82592),S=s(64486);const g={captureView:"captureView___lA4lh",pane:"pane___yKLVJ theme-typography--body2"};var x=s(38857);const v=(0,x.mC)((async function loader(){const{SqlEditor:e}=await Promise.all([s.e(11502),s.e(7542),s.e(97493),s.e(67557),s.e(89814),s.e(73676),s.e(36821),s.e(83524)]).then(s.bind(s,71778));return{SqlEditor:e}})),m=(0,r.PA)((function SqlEditorLoader(e){return(0,i.jsx)(x.CW,{loader:v,children:({SqlEditor:t})=>(0,i.jsx)(t,{...e})})}));var b=s(17675),y=s(53626),f=s(22481),_=s(13754),q=s(57916),I=s(36182),C=s(41049),E=s(68426),w=s(89232);const j=(0,r.PA)((function SqlEditorOpenOverlay({dataSource:e}){const t=(0,b.W)();return(0,i.jsxs)(y.h,{active:!e?.isOpened(),children:[(0,i.jsxs)(f.e,{children:[(0,i.jsx)(_.X,{icon:e?.icon}),(0,i.jsx)(q.Y,{children:t("plugin_sql_editor_action_overlay_title")})]}),(0,i.jsx)(I.W,{children:t("plugin_sql_editor_action_overlay_description")}),(0,i.jsxs)(C.M,{children:[(0,i.jsx)(E.S,{}),(0,i.jsx)(w.$,{type:"button",mod:["unelevated"],loading:e?.isLoading(),loader:!0,onClick:function openHandler(){e?.open()},children:t("ui_open")})]})]})}));var T=s(15993),D=s(84383),R=s(34685),A=s(28677),P=s(49690),M=s(74749),L=s(30606),k=s(14452),Q=s(86888);const N={overlayActions:"overlayActions___UsR65"};var O=s(20740);const G=(0,r.PA)((function SqlEditorOverlay({state:e}){const t=(0,n.d)(N),s=(0,b.W)(),r=(0,h.h)(O.SqlEditorService),o=(0,h.h)(S.SqlDataSourceService),a=(0,h.h)(k.NotificationService),u=o.get(e.editorId),d=u?.executionContext?.id,l=u?.executionContext,p=(0,D.q)(SqlEditorOverlay,P.ConnectionInfoResource,l?(0,P.createConnectionParam)(l.projectId,l.connectionId):null),g=(0,D.q)(SqlEditorOverlay,M.DBDriverResource,p.tryGetData?.driverId??null),x=(0,R.u)((()=>p.tryGetData?.connected??!1)),v=(0,D.q)(SqlEditorOverlay,L.ConnectionExecutionContextResource,(0,L.getRealExecutionContextId)(d),{active:x}),m=(0,R.u)((()=>p.isLoading()||v.isLoading())),E=(0,R.u)((()=>void 0===v.tryGetData&&void 0!==p.tryGetData&&!1===u?.isLoading()));async function init(){try{await r.initEditorConnection(e)}catch(e){a.logException(e)}}const j=(0,R.u)((()=>Q.n.concatSchemaAndCatalog(u?.executionContext?.defaultCatalog,u?.executionContext?.defaultSchema)));return(0,T.useEffect)((()=>{E&&x&&init()}),[x,E]),(0,i.jsxs)(y.h,{active:E&&!p.tryGetData?.connected,children:[(0,i.jsxs)(f.e,{children:[(0,i.jsx)(_.X,{icon:g.tryGetData?.icon}),(0,i.jsx)(q.Y,{children:p.tryGetData?.name}),j&&(0,i.jsx)(A.c,{children:j})]}),(0,i.jsx)(I.W,{children:s("sql_editor_restore_message")}),(0,i.jsxs)(C.M,{className:(0,c.s)(t,{overlayActions:!0}),children:[(0,i.jsx)(w.$,{type:"button",mod:["outlined"],loader:!0,onClick:async function cancelConnection(){await r.resetExecutionContext(e)},children:s("ui_processing_cancel")}),(0,i.jsx)(w.$,{type:"button",mod:["unelevated"],loading:m,loader:!0,onClick:init,children:s("sql_editor_restore")})]})]})})),H={loader:"loader___mNXPZ theme-background-surface theme-border-color-background"},V=(0,r.PA)((function SqlEditorStatusBar({dataSource:e}){const t=(0,n.d)(H);return(0,i.jsx)(a.a,{className:(0,c.s)(t,{loader:!0}),state:e,message:e?.message,inline:!0,inlineException:!0})}));var B=s(64742),F=s(14249),X=s(13720),W=s(20458),U=s(66891),$=s(98098),Y=s(22321),z=s(44451),K=s(12195),Z=s(80957);const J={wrapper:"wrapper___T7ASD",tabListNotExecutable:"tabListNotExecutable___VyDEr",tabOuter:"tabOuter___nBVJZ",textPlaceholder:"textPlaceholder___ZImXm"};var ee=s(50420);const te="resultPanel___ycQFv",se=(0,ee.j)((()=>Promise.all([s.e(11502),s.e(67557),s.e(36821),s.e(95860),s.e(16381)]).then(s.bind(s,53250)).then((e=>e.SqlExecutionPlanPanel)))),ie=(0,ee.j)((()=>Promise.all([s.e(11502),s.e(67557),s.e(36821),s.e(88761),s.e(38762)]).then(s.bind(s,68916)).then((e=>e.OutputLogsPanel)))),re=(0,ee.j)((()=>Promise.all([s.e(11502),s.e(63190),s.e(36821),s.e(50667)]).then(s.bind(s,66793)).then((e=>e.SqlResultSetPanel)))),ne=(0,ee.j)((()=>Promise.all([s.e(11502),s.e(36821),s.e(73048)]).then(s.bind(s,29297)).then((e=>e.SqlScriptStatisticsPanel)))),oe=(0,r.PA)((function SqlResultPanel({state:e,id:t}){const s=e.resultTabs.find((e=>e.tabId===t));if(s)return(0,i.jsx)("div",{className:te,children:(0,i.jsx)(re,{resultTab:s,state:e})});const r=e.executionPlanTabs.find((e=>e.tabId===t));if(r)return(0,i.jsx)("div",{className:te,children:(0,i.jsx)(se,{executionPlanTab:r})});const n=e.statisticsTabs.find((e=>e.tabId===t));return n?(0,i.jsx)("div",{className:te,children:(0,i.jsx)(ne,{tab:n})}):e.outputLogsTab?(0,i.jsx)("div",{className:te,children:(0,i.jsx)(ie,{sqlEditorTabState:e})}):null}));var ae=s(92674),ce=s(90398),ue=s(43659),de=s(48522),le=s(19259),he=s(91751),pe=s(10009);const Se=(0,r.PA)((function SqlResultTab({result:e,className:t,onClose:s}){const r=(0,T.useContext)(he.b),n=(0,ae.f)(r);return(0,ce.Z)(n,((t,s)=>{t.set(pe.Y,e,s)})),(0,i.jsxs)(ue.o,{tabId:e.id,title:e.name,menuContext:n,className:t,onClose:s,children:[(0,i.jsx)(de.$,{icon:e.icon}),(0,i.jsx)(le.I,{children:e.name})]},e.id)}));var ge=s(4222);const xe=[[W.A,{mode:"append",styles:[{tab:"tab___UtdS9 theme-ripple theme-background-surface theme-text-text-primary-on-light"}]}],[U.A,{mode:"append",styles:[{tabIcon:"tabIcon___wVO6a theme-text-surface"}]}],[$.A,{mode:"append",styles:[{tabList:"tabList___ZT5Vv theme-background-background theme-text-text-primary-on-light"}]}]],ve=(0,r.PA)((function SqlDataResult({state:e,onTabSelect:t,onTabClose:s}){const r=(0,n.d)(J),o=(0,b.W)(),a=(0,h.h)(ge.SqlResultTabsService),u=(0,h.h)(S.SqlDataSourceService),d=(0,R.u)((()=>u.get(e.editorId))),l=e.tabs.slice().sort(((t,s)=>{const i=e.resultTabs.find((e=>e.tabId===t.id)),r=e.resultTabs.find((e=>e.tabId===s.id));return i&&r&&t.order===s.order?i.indexInResultSet-r.indexInResultSet:t.order-s.order}));function handleCanClose(t){const s=e.resultTabs.find((e=>e.tabId===t.tabId));if(s){const t=e.resultGroups.find((e=>e.groupId===s.groupId));return!0!==d?.databaseModels.some((e=>e.id===t.modelId))}return!0}if(!e.tabs.length)return(0,i.jsx)(F.x,{className:(0,c.s)(r,{textPlaceholder:!0}),children:o(d?.emptyPlaceholder??"sql_editor_placeholder")});const p=d?.hasFeature(Z.A.executable),g=l.map((e=>e.id));return(0,i.jsx)("div",{className:(0,c.s)(r,{wrapper:!0}),children:(0,i.jsxs)(Y._,{currentTabId:e.currentTabId,tabList:g,canClose:handleCanClose,enabledBaseActions:!0,onChange:function handleSelect(s){a.selectResultTab(e,s.tabId),t?.(s.tabId)},onClose:function handleClose(t){handleCanClose(t)&&(a.removeResultTab(e,t.tabId),s?.(t.tabId))},children:[(0,i.jsx)(X.Z,{registry:xe,children:(0,i.jsx)(z.w,{className:(0,c.s)(r,{tabListNotExecutable:!p}),"aria-label":"SQL Results",children:l.map((e=>(0,i.jsx)(Se,{result:e},e.id)))})}),l.map((t=>(0,i.jsx)(K.K,{tabId:t.id,lazy:!0,children:(0,i.jsx)(oe,{state:e,id:t.id})},t.id)))]})})}));const me=(0,r.PA)((function SqlEditor({state:e}){const t=(0,n.d)(g),s=(0,h.h)(B.SqlEditorView),r=(0,h.h)(S.SqlDataSourceService).get(e.editorId);!function useDataSource(e){const t=(0,h.h)(O.SqlEditorService),s=e&&(e.isOutdated()||!e.isLoaded())&&!e.isLoading();(0,T.useEffect)((()=>{s&&(!e.exception||Array.isArray(e.exception)&&!e.exception.some(Boolean))&&(e?.isLoading()||e.load())}));const i=e?.executionContext?.id;(0,T.useEffect)((()=>()=>{void 0!==i&&e?.executionContext?.id!==i&&t.destroyContext({id:i,connectionId:"",projectId:""})}),[i,e])}(r);const x=(0,o.s)(`sql-editor-${r?.sourceKey??"default"}`),v=r?.isOpened()||!1;return(0,i.jsx)(a.a,{suspense:!0,children:(0,i.jsxs)(p.G,{className:(0,c.s)(t,{captureView:!0}),view:s,children:[(0,i.jsxs)(u.B,{...x,split:"horizontal",sticky:30,children:[(0,i.jsx)(d.Z,{className:(0,c.s)(t,{pane:!0}),basis:"50%",main:!0,children:(0,i.jsx)(m,{state:e})}),(0,i.jsx)(l.$,{}),(0,i.jsx)(d.Z,{className:(0,c.s)(t,{pane:!0}),children:(0,i.jsx)(a.a,{suspense:!0,children:(0,i.jsx)(ve,{state:e})})})]}),v&&(0,i.jsx)(G,{state:e}),!v&&(0,i.jsx)(j,{dataSource:r}),(0,i.jsx)(V,{dataSource:r})]})})}))},85084:(e,t,s)=>{s.d(t,{j:()=>i});const i=(0,s(44745).M)("sql-editor-data")},77978:(e,t,s)=>{s.d(t,{J:()=>i});const i=(0,s(85240).E)("sql-editor-actions","")},20038:(e,t,s)=>{s.d(t,{F:()=>i});const i=(0,s(85240).E)("sql-editor-tools","")},71778:(e,t,s)=>{s.d(t,{SqlEditor:()=>we});var i=s(41773),r=s(7838),n=s(15993),o=s(90264),a=s(64928),c=s(34685),u=s(13720),d=s(7167),l=s(18699),h=s(98098),p=s(20458),S=s(22321),g=s(52843),x=s(44451),v=s(31324),m=s(91668),b=s(97469),y=s(85084);const f={sqlEditor:"sqlEditor___Iwlpm",tabs:"tabs___KQGxC theme-background-secondary theme-text-on-secondary"},_={tab:"tab___h3D_0 theme-ripple theme-background-background theme-text-text-primary-on-light theme-typography--body2",sqlEditor:"sqlEditor___WzWl1"};var q=s(17675),I=s(43872),C=s(74508),E=s(80957);const w={container:"container___gUJk6 theme-border-color-background",actions:"actions___yEvgr"};var j=s(68768),T=s(26339),D=s(21252),R=s(12483),A=s(77978);const P={sqlActions:"sqlActions___hXqnv",menuBar:"menuBar___YoWeC"},M={toolsMenu:"toolsMenu___zvvws",menuBarItem:"menuBarItem___V3WF1",menuBarItemLabel:"menuBarItemLabel___Lhhiv"},L=[[j.A,{mode:"append",styles:[P]}],[T.A,{mode:"append",styles:[M]}]],k=(0,r.PA)((function SqlEditorActionsMenu({state:e,context:t,className:s}){const r=(0,a.d)(P,M,j.A,T.A),n=(0,R.b)({menu:A.J,context:t});return(0,i.jsx)(u.Z,{registry:L,children:(0,i.jsx)(D.R,{menu:n,className:(0,d.s)(r,{toolsMenu:!0,floating:!0,sqlActions:!0},s)})})}));var Q=s(13157);const N={tools:"tools___v4boB"};var O=s(90398),G=s(27929),H=s(20038);const V=[[j.A,{mode:"append",styles:[P]}],[T.A,{mode:"append",styles:[M]}]],B=(0,r.PA)((function SqlEditorToolsMenu({data:e,state:t,context:s,className:r}){const n=(0,a.d)(P,M,j.A,T.A),o=(0,R.b)({menu:H.F,context:s});return(0,O.Z)(o.context,((e,s)=>{e.set(G.M,t,s)})),(0,O.Z)(o.context,((t,s)=>{t.set(y.j,e,s)})),(0,i.jsx)(u.Z,{registry:V,children:(0,i.jsx)(D.R,{menu:o,className:(0,d.s)(n,{sqlActions:!0,floating:!0},r)})})}));var F=s(94866),X=s(28347),W=s(49690),U=s(71635),$=s(14452),Y=s(31793),z=s(36221),K=s(19617),Z=s(1302),J=s(64486),ee=s(14515),te=s(51477),se=s(62204),ie=s(92659),re=s(70500),ne=s(9428),oe=s(89232),ae=s(68426);const ce={footer:"footer___SYMZX",container:"container___sCJue"},ue=function ScriptImportDialog({resolveDialog:e,rejectDialog:t,className:s}){const r=(0,a.d)(ce);return(0,i.jsxs)(te.n,{size:"small",className:s,fixedWidth:!0,children:[(0,i.jsx)(se.D,{title:"ui_changes_might_be_lost",onReject:t}),(0,i.jsx)(ie.a,{children:(0,i.jsx)(re.H,{token:"sql_editor_upload_script_unsaved_changes_dialog_message"})}),(0,i.jsx)(ne.Z,{className:(0,d.s)(r,{footer:!0}),children:(0,i.jsxs)("div",{className:(0,d.s)(r,{container:!0}),children:[(0,i.jsx)(oe.$,{type:"button",mod:["outlined"],onClick:t,children:(0,i.jsx)(re.H,{token:"ui_processing_cancel"})}),(0,i.jsx)(ae.S,{}),(0,i.jsx)(oe.$,{type:"button",mod:["outlined"],onClick:()=>e(!1),children:(0,i.jsx)(re.H,{token:"ui_no"})}),(0,i.jsx)(oe.$,{type:"button",mod:["unelevated"],onClick:()=>e(!0),children:(0,i.jsx)(re.H,{token:"ui_yes"})})]})})]})};const de=(0,r.PA)((function SqlEditorTools({data:e,state:t,className:s}){const r=(0,q.W)(),n=(0,a.d)(N),o=function useTools(e){const t=(0,l.h)(U.CommonDialogService),s=(0,l.h)($.NotificationService),i=(0,l.h)(W.ConnectionInfoResource),r=(0,l.h)(ee.SqlEditorSettingsService),n=(0,l.h)(J.SqlDataSourceService);return(0,X.G)((()=>({async tryReadScript(e,t){if(!this.checkFileValidity(e))return null;if(t){const e=await this.commonDialogService.open(ue,null);if(e===U.DialogueStateResult.Rejected)return null;e!==U.DialogueStateResult.Resolved&&e&&this.downloadScript(t)}return this.readScript(e)},async readScript(e){let t=null;try{const s=(0,Y.N)(e);t=await s.promise}catch(e){this.notificationService.logException(e,"Uploading script error")}return t},checkFileValidity(e){const t=this.sqlEditorSettingsService.maxFileSize,s=Math.round(e.size/1024);return!(s>t&&(this.notificationService.logInfo({title:"sql_editor_upload_script_max_size_title",message:`Max size: ${t}KB\nFile size: ${s}KB`,autoClose:!1}),1))},downloadScript(e){if(!e.trim())return;const t=new Blob([e],{type:"application/sql"}),s=n.get(this.state.editorId),i=s?.executionContext;let r;i&&(r=this.connectionInfoResource.get((0,W.createConnectionParam)(i.projectId,i.connectionId)));const o=(0,Z.l)(this.state,s,r);(0,z.R)(t,`${(0,K.h)(o)}.sql`)}})),{tryReadScript:F.XI.bound,readScript:F.XI.bound,checkFileValidity:F.XI.bound,downloadScript:F.XI.bound},{commonDialogService:t,connectionInfoResource:i,notificationService:s,sqlEditorSettingsService:r,state:e})}(t),u=(0,c.u)((()=>0===e.value.length)),h=(0,c.u)((()=>e.isDisabled||e.isScriptEmpty)),p=(0,c.u)((()=>e.activeSegmentMode.activeSegmentMode));const S=e.dataSource?.hasFeature(E.A.script);return(0,i.jsxs)("div",{className:(0,d.s)(n,{tools:!0},s),onMouseDown:I.Z,children:[(0,i.jsx)(B,{state:t,data:e}),S&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(C.G,{name:"/icons/sql_format_sm.svg",disabled:h||e.readonly,title:r("sql_editor_sql_format_button_tooltip"),hidden:p,img:!0,onClick:e.formatScript}),(0,i.jsx)(C.G,{name:"/icons/export.svg",disabled:u,title:r("sql_editor_download_script_tooltip"),hidden:p,img:!0,onClick:async function downloadScriptHandler(){o.downloadScript(e.value.trim())}}),!p&&(0,i.jsx)(Q.L,{accept:".sql",title:r("sql_editor_upload_script_tooltip"),disabled:e.readonly,reset:!0,onChange:async function handleScriptUpload(t){const s=t.target.files?.[0];if(!s)throw new Error("File is not found");const i=e.value.trim(),r=await o.tryReadScript(s,i);r&&e.setScript(r)},children:(0,i.jsx)(C.G,{tag:"div",name:"/icons/import.svg",disabled:e.readonly,img:!0})})]})]})})),le=(0,r.PA)((function SQLEditorActions({data:e,state:t}){const s=(0,a.d)(w),r=(0,q.W)(),n=(0,c.u)((()=>e.activeSegmentMode.activeSegmentMode)),o=(0,c.u)((()=>e.isScriptEmpty||e.isDisabled)),u=e.dataSource?.hasFeature(E.A.query),l=e.dataSource?.hasFeature(E.A.executable);return(0,i.jsxs)("div",{className:(0,d.s)(s,{container:!0}),children:[(0,i.jsxs)("div",{className:(0,d.s)(s,{actions:!0}),onMouseDown:I.Z,children:[l&&(0,i.jsxs)(i.Fragment,{children:[u&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(C.G,{name:"/icons/sql_exec.svg",disabled:o,title:r("sql_editor_sql_execution_button_tooltip"),img:!0,onClick:e.executeQuery}),(0,i.jsx)(C.G,{name:"/icons/sql_exec_new.svg",disabled:o,title:r("sql_editor_sql_execution_new_tab_button_tooltip"),img:!0,onClick:e.executeQueryNewTab})]}),(0,i.jsx)(C.G,{name:"/icons/sql_script_exec.svg",disabled:o,hidden:n,title:r("sql_editor_sql_execution_script_button_tooltip"),img:!0,onClick:e.executeScript}),u&&e.dialect?.supportsExplainExecutionPlan&&(0,i.jsx)(C.G,{name:"/icons/sql_execution_plan.svg",disabled:o,hidden:n,title:r("sql_editor_execution_plan_button_tooltip"),img:!0,onClick:e.showExecutionPlan})]}),(0,i.jsx)(k,{state:t})]}),(0,i.jsx)(de,{data:e,state:t})]})}));var he=s(26533),pe=s(91184),Se=s(13225),ge=s(44017),xe=s(90639),ve=s(8385),me=s(69326),be=s(56735),ye=s(20740);class SQLParser{get scripts(){return this._scripts}get actualScript(){return this.script}constructor(){this._scripts=[],this.script="",(0,F.Gn)(this,{actualScript:F.EW,_scripts:F.sH.ref,script:F.sH.ref,getScriptSegment:F.XI,getSegment:F.XI,getQueryAtPos:F.XI,setScript:F.XI,setQueries:F.XI})}getScriptSegment(){const e=this.script||"";return{query:e,begin:0,end:e.length}}getSegment(e,t){return e===t?this.getQueryAtPos(e):(-1===t&&(t=e),{query:(this.script||"").substring(e,t),begin:e,end:t})}getQueryAtPos(e){const t=this._scripts.find((t=>t.begin<=e&&t.end>e));if(t)return t;const s=this._scripts.filter((t=>t.begin<=e));return s.length>0?s[s.length-1]:void 0}setScript(e){this.script=e}setQueries(e){return this._scripts=e.map((e=>({query:this.script.substring(e.start,e.end),begin:e.start,end:e.end}))),this}}var fe=s(32010),_e=s(8884),qe=s(79031),Ie=s(4222);const Ce=function SQLEditorModeContext(e,t){return{activeSegment:t.parser.getSegment(t.cursor.begin,t.cursor.end),activeSegmentMode:!1}};const Ee=[[h.A,{mode:"append",styles:[{tabList:"tabList____mU8p theme-background-secondary theme-text-on-secondary"}]}],[p.A,{mode:"append",styles:[_]}]],we=(0,r.PA)((function SqlEditor({state:e,className:t}){const s=(0,o.O)(),r=(0,a.d)(f,_),h=(0,l.h)(b.SqlEditorModeService),p=function useSqlEditor(e){const t=(0,l.h)(Se.ConnectionExecutionContextService),s=(0,l.h)(qe.SqlQueryService),i=(0,l.h)(be.SqlDialectInfoService),r=(0,l.h)(ye.SqlEditorService),o=(0,l.h)($.NotificationService),a=(0,l.h)(fe.SqlExecutionPlanService),c=(0,l.h)(Ie.SqlResultTabsService),u=(0,l.h)(U.CommonDialogService),d=(0,l.h)(J.SqlDataSourceService),h=(0,X.G)((()=>({get dataSource(){return d.get(this.state.editorId)},get dialect(){const e=this.dataSource?.executionContext;if(e)return this.sqlDialectInfoService.getDialectInfo((0,W.createConnectionParam)(e.projectId,e.connectionId))},activeSegmentMode:{activeSegment:void 0,activeSegmentMode:!1},get activeSegment(){return this.activeSegmentMode.activeSegment},get cursorSegment(){return this.parser.getSegment(this.cursor.begin,-1)},get readonly(){return this.executingScript||this.readonlyState||!!this.dataSource?.isOutdated()||!!this.dataSource?.isReadonly()||!this.editing},get editing(){return this.dataSource?.isEditing()??!1},get isScriptEmpty(){return""===this.value},get isDisabled(){if(!this.dataSource?.executionContext||!this.dataSource.isLoaded())return!0;const e=this.connectionExecutionContextService.get(this.dataSource.executionContext.id);return e?.executing||!1},get isIncomingChanges(){return this.dataSource?.isIncomingChanges??!1},get cursor(){return this.dataSource?.cursor??{begin:0,end:0}},get value(){return this.dataSource?.script??""},get incomingValue(){return this.dataSource?.incomingScript},onMode:new ge.H,onExecute:new ge.H,onSegmentExecute:new ge.H,onUpdate:new ge.H,parser:new SQLParser,readonlyState:!1,executingScript:!1,reactionDisposer:null,hintsLimitIsMet:!1,init(){this.reactionDisposer||(this.parser.setScript(this.value),this.reactionDisposer=(0,F.fm)((()=>{const e=this.dataSource?.executionContext;if(e){const t=this.connectionExecutionContextService.get(e.id)?.context;if(t){const e=(0,W.createConnectionParam)(t.projectId,t.connectionId);(0,F.O8)((()=>{this.sqlDialectInfoService.loadSqlDialectInfo(e).then((async()=>{try{await this.updateParserScriptsDebounced()}catch{}}))}))}}})))},destruct(){this.reactionDisposer?.()},setCursor(e,t=e){this.dataSource?.setCursor(e,t)},getLastAutocomplete:(0,xe.h)(),parseScript:(0,xe.h)(),getHintProposals:(0,ve.l)((async function getHintProposals(e,t){const s=this.dataSource?.executionContext;if(!s)return[];const i=await this.sqlEditorService.getAutocomplete(s.projectId,s.connectionId,s.id,this.value,e,200,t);return this.hintsLimitIsMet=i.length>=200,i}),300),async formatScript(){if(this.isDisabled||this.isScriptEmpty||!this.dataSource?.executionContext)return;await this.updateParserScripts();const e=this.value,t=this.getExecutingQuery(!1);if(t){this.onExecute.execute(!0);try{this.readonlyState=!0;const s=await this.sqlDialectInfoService.formatScript(this.dataSource.executionContext,t.query);this.setScript(e.substring(0,t.begin)+s+e.substring(t.end)),this.setCursor(t.begin+s.length)}finally{this.readonlyState=!1}}},async executeQuery(){const e=this.dataSource?.hasFeature(E.A.query),t=this.dataSource?.hasFeature(E.A.executable);if(!e||!t)return;await this.updateParserScripts();const s=this.getSubQuery();try{await this.executeQueryAction(await this.executeQueryAction(s,(()=>this.getResolvedSegment())),(e=>this.sqlQueryService.executeEditorQuery(this.state,e.query,!1)))}catch{}},async loadDatabaseDataModels(){const e=this.getExecutingQuery(!0);await this.executeQueryAction(e,(async()=>{this.dataSource?.databaseModels.length&&this.sqlQueryService.initDatabaseDataModels(this.state)}),!0,!0)},async executeQueryNewTab(){const e=this.dataSource?.hasFeature(E.A.query),t=this.dataSource?.hasFeature(E.A.executable);if(!e||!t)return;await this.updateParserScripts();const s=this.getSubQuery();try{await this.executeQueryAction(await this.executeQueryAction(s,(()=>this.getResolvedSegment())),(e=>this.sqlQueryService.executeEditorQuery(this.state,e.query,!0)))}catch{}},async showExecutionPlan(){const e=this.dataSource?.hasFeature(E.A.query),t=this.dataSource?.hasFeature(E.A.executable);if(!e||!t||!this.dialect?.supportsExplainExecutionPlan)return;await this.updateParserScripts();const s=this.getSubQuery();try{await this.executeQueryAction(await this.executeQueryAction(s,(()=>this.getResolvedSegment())),(e=>this.sqlExecutionPlanService.executeExecutionPlan(this.state,e.query)))}catch{}},async switchEditing(){this.dataSource?.setEditing(!this.dataSource.isEditing())},async executeScript(){const e=this.dataSource?.hasFeature(E.A.executable);if(!e||this.isDisabled||this.isScriptEmpty)return;const t=this.state.tabs.filter((e=>e.id!==_e.o));if(t.length>0){const e=await this.commonDialogService.open(he.K,{title:"sql_editor_close_result_tabs_dialog_title",message:`Do you want to close ${t.length} tabs before executing script?`,confirmActionText:"ui_yes",extraStatus:"no"});if(e===U.DialogueStateResult.Resolved){if(!await this.sqlResultTabsService.canCloseResultTabs(this.state))return;this.sqlResultTabsService.removeResultTabs(this.state,[_e.o])}else if(e===U.DialogueStateResult.Rejected)return}this.onExecute.execute(!0);try{this.executingScript=!0,await this.updateParserScripts();const e=this.parser.scripts;await this.sqlQueryService.executeQueries(this.state,e.map((e=>e.query)),{onQueryExecutionStart:(t,s)=>{const i=e[s];this.onSegmentExecute.execute({segment:i,type:"start"})},onQueryExecuted:(t,s,i)=>{const r=e[s];this.onSegmentExecute.execute({segment:r,type:"end"}),i||this.onSegmentExecute.execute({segment:r,type:"error"})}})}finally{this.executingScript=!1}},setScript(e){this.dataSource?.setScript(e)},updateParserScriptsDebounced:(0,me.A)((async function updateParserScriptsThrottle(){await h.updateParserScripts()}),2e3),async updateParserScripts(){if(!this.dataSource?.hasFeature(E.A.script))return;const e=this.dataSource.executionContext?.projectId,t=this.dataSource.executionContext?.connectionId,s=this.parser.actualScript;if(!e||!t||!s)return this.parser.setQueries([]),void this.onUpdate.execute();const{queries:i}=await this.parseScript([t,s],(async()=>{try{return await this.sqlEditorService.parseSQLScript(e,t,s)}catch(e){throw this.notificationService.logException(e,"Failed to parse SQL script"),e}}));this.parser.actualScript===s&&(this.parser.setQueries(i),this.onUpdate.execute())},async executeQueryAction(e,t,s,i){if(!(!e||this.isDisabled&&!i||!s&&this.isScriptEmpty)){this.onExecute.execute(!0);try{const s=setTimeout((()=>this.onSegmentExecute.execute({segment:e,type:"start"})),250),i=await t(e);return clearTimeout(s),this.onSegmentExecute.execute({segment:e,type:"end"}),i}catch(t){throw this.onSegmentExecute.execute({segment:e,type:"end"}),this.onSegmentExecute.execute({segment:e,type:"error"}),t}}},getExecutingQuery(e){return e?this.parser.getScriptSegment():this.activeSegment},async getResolvedSegment(){const e=this.dataSource?.executionContext?.projectId,t=this.dataSource?.executionContext?.connectionId;if(await h.updateParserScripts(),!e||!t||this.cursor.begin!==this.cursor.end)return this.getSubQuery();if(this.activeSegmentMode.activeSegmentMode)return this.activeSegment;const s=await this.sqlEditorService.parseSQLQuery(e,t,this.value,this.cursor.begin);return 0!==s.end||0!==s.start?this.parser.getSegment(s.start,s.end):void 0},getSubQuery(){const e=this.getExecutingQuery(!1);if(e)return e.query=e.query.trim(),e},setModeId(e){this.state.currentModeId=e,this.onUpdate.execute()}})),{getHintProposals:F.XI.bound,formatScript:F.XI.bound,executeQuery:F.XI.bound,executeQueryNewTab:F.XI.bound,showExecutionPlan:F.XI.bound,executeScript:F.XI.bound,switchEditing:F.XI.bound,dialect:F.EW,isDisabled:F.EW,value:F.EW,readonly:F.EW,cursor:F.EW,activeSegmentMode:F.sH.ref,hintsLimitIsMet:F.sH.ref,readonlyState:F.sH,executingScript:F.sH},{state:e,connectionExecutionContextService:t,sqlQueryService:s,sqlDialectInfoService:i,sqlEditorService:r,sqlExecutionPlanService:a,sqlResultTabsService:c,notificationService:o,commonDialogService:u});return(0,F.O8)((()=>h.init())),(0,pe.H)({executor:h.dataSource?.onSetScript,handlers:[function setScript({script:e}){h.setCursor(h.cursor.begin,h.cursor.end),h.parser.setScript(e),h.updateParserScriptsDebounced().catch((()=>{})),h.onUpdate.execute()}]}),(0,pe.H)({executor:h.dataSource?.onDatabaseModelUpdate,handlers:[function updateDatabaseModels(){h.loadDatabaseDataModels()}]}),(0,pe.H)({executor:h.onUpdate,handlers:[function updateActiveSegmentMode(){const e=h.onMode.execute(h);h.activeSegmentMode=e.getContext(Ce)}]}),(0,n.useEffect)((()=>(0,F.fm)((()=>{const e=h.onMode.execute(h).getContext(Ce);(0,F.h5)((()=>{h.activeSegmentMode=e}))}))),[h]),(0,n.useEffect)((()=>()=>h.destruct()),[]),h}(e),[q]=(0,n.useState)((()=>new v.C));(0,n.useMemo)((()=>{q.sync(e.modeState)}),[e]),(0,m.c)(((e,t)=>{e.set(y.j,p,t)}));const I=(0,c.u)((()=>h.tabsContainer.getDisplayed({state:e,data:p}).length)),C=0===I;return(0,n.useEffect)((()=>{C?s.state.setDisable(!0):s.state.disable&&s.state.setDisable(!1)}),[C]),(0,i.jsx)(S._,{currentTabId:e.currentModeId,container:h.tabsContainer,localState:q,state:e,data:p,lazy:!0,onChange:function handleModeSelect(e){p.setModeId(e.tabId)},children:(0,i.jsx)(u.Z,{registry:Ee,children:(0,i.jsxs)("div",{className:(0,d.s)(r,{sqlEditor:!0},t),children:[(0,i.jsx)(le,{data:p,state:e}),(0,i.jsx)(g.A,{}),I>1?(0,i.jsx)("div",{className:(0,d.s)(r,{tabs:!0}),children:(0,i.jsx)(x.w,{vertical:!0,rotated:!0})}):null]})})})}))},48679:(e,t,s)=>{s.r(t),s.d(t,{SqlEditorGroupTabsBootstrap:()=>g});var i=s(1118),r=s(82103),n=s(5576),o=s(69740),a=s(90590),c=s(77495),u=s(79023),d=s(72877);const l=(0,s(19102).V)("tab-close-sql-result-group",{label:"plugin_sql_editor_action_close_group",tooltip:"plugin_sql_editor_action_close_group"});var h=s(27929),p=s(10009),S=s(4222);let g=class SqlEditorGroupTabsBootstrap extends r.j{constructor(e,t,s){super(),this.actionService=e,this.menuService=t,this.sqlResultTabsService=s}register(){this.menuService.addCreator({menus:[o.Y],contexts:[p.Y,h.M],isApplicable:e=>{const t=e.get(a.m);return!!t?.enabledBaseActions},getItems:(e,t)=>[...t,l],orderItems:(e,t)=>{const s=(0,c.H)(t,[l]);return s.length>0&&t.push(...s),t}}),this.actionService.addHandler({id:"result-tabs-group-base-handler",actions:[l],menus:[o.Y],contexts:[p.Y,h.M,a.m],isActionApplicable:e=>{const t=e.get(p.Y),s=e.get(h.M),i=s?.resultTabs.find((e=>e.tabId===t.id))?.groupId;return s.resultTabs.filter((e=>e.groupId===i)).length>1},handler:async(e,t)=>{if(t===l)this.closeResultTabGroup(e)}})}async closeResultTabGroup(e){const t=e.get(p.Y),s=e.get(h.M),i=e.get(a.m),r=this.sqlResultTabsService.getResultTabs(s),n=r.find((e=>e.tabId===t.id)),o=r.filter((e=>e.groupId===n?.groupId));o.forEach((e=>{i.close(e.tabId)}))}};g=(0,i.Cg)([(0,n._)(),(0,i.Sn)("design:paramtypes",[u.ActionService,d.MenuService,S.SqlResultTabsService])],g)},97469:(e,t,s)=>{s.r(t),s.d(t,{SqlEditorModeService:()=>o});var i=s(1118),r=s(5576),n=s(68356);let o=class SqlEditorModeService{constructor(){this.tabsContainer=new n.a("SQL Editor Mode")}};o=(0,i.Cg)([(0,r._)(),(0,i.Sn)("design:paramtypes",[])],o)},20740:(e,t,s)=>{s.r(t),s.d(t,{SqlEditorService:()=>m});var i=s(1118),r=s(94866),n=s(49690),o=s(30606),a=s(34906),c=s(13225),u=s(5576),d=s(14452),l=s(40813),h=s(40601),p=s(83336),S=s(1302),g=s(80957),x=s(64486),v=s(14515);let m=class SqlEditorService{get autoSave(){return this.sqlEditorSettingsService.autoSave&&!this.serverConfigResource.isFeatureEnabled(h.FEATURE_GIT_ID,!0)}get insertTableAlias(){return this.sqlEditorSettingsService.insertTableAlias}constructor(e,t,s,i,r,n,o,a,c){this.graphQLService=e,this.connectionsManagerService=t,this.notificationService=s,this.connectionExecutionContextService=i,this.connectionExecutionContextResource=r,this.connectionInfoResource=n,this.sqlDataSourceService=o,this.sqlEditorSettingsService=a,this.serverConfigResource=c}getState(e,t,s,i){return(0,r.sH)({editorId:e,datasourceKey:t,source:i,order:s,tabs:(0,r.sH)([]),resultGroups:(0,r.sH)([]),resultTabs:(0,r.sH)([]),executionPlanTabs:(0,r.sH)([]),statisticsTabs:(0,r.sH)([]),outputLogsTab:void 0,currentModeId:void 0,modeState:(0,r.sH)([])})}async parseSQLScript(e,t,s){return(await this.graphQLService.sdk.parseSQLScript({projectId:e,connectionId:t,script:s})).scriptInfo}async parseSQLQuery(e,t,s,i){return(await this.graphQLService.sdk.parseSQLQuery({projectId:e,connectionId:t,script:s,position:i})).queryInfo}async getAutocomplete(e,t,s,i,r,n,o){const{proposals:a}=await this.graphQLService.sdk.querySqlCompletionProposals({projectId:e,connectionId:t,contextId:s,query:i,position:r,maxResults:n,simple:o});return a}getName(e){const t=this.sqlDataSourceService.get(e.editorId),s=t?.executionContext;let i;return s&&(i=this.connectionInfoResource.get((0,n.createConnectionParam)(s.projectId,s.connectionId))),(0,S.l)(e,t,i)}setName(e,t){const s=this.sqlDataSourceService.get(t.editorId);s&&s.hasFeature(g.A.setName)&&s.setName(e)}setScript(e,t){this.sqlDataSourceService.get(t.editorId).setScript(e)}async resetExecutionContext(e){const t=this.sqlDataSourceService.get(e.editorId);t?.executionContext&&(await this.destroyContext(t.executionContext),t.setExecutionContext(void 0))}async setConnection(e,t,s,i){try{const r=await this.initContext(t,s,i),n=this.sqlDataSourceService.get(e.editorId);if(!r?.context||!n)return!1;const o=n.executionContext;return n.setExecutionContext({...r.context}),o&&await this.destroyContext(o),!0}catch(e){return this.notificationService.logException(e,"Failed to change SQL-editor connection"),!1}}async initEditorConnection(e){return this.sqlDataSourceService.executeAction(e.editorId,(async t=>{const s=t?.executionContext;if(!s)return void console.error("executeEditorQuery executionContext is not provided");if(await this.connectionExecutionContextResource.load((0,o.ConnectionExecutionContextProjectKey)(s.projectId)),this.connectionExecutionContextResource.has(s.id))return this.connectionExecutionContextService.get(s.id);const i=await this.initContext((0,n.createConnectionParam)(s.projectId,s.connectionId),s.defaultCatalog,s.defaultSchema);if(i?.context)return t.setExecutionContext({...i.context}),i;await this.resetExecutionContext(e)}),(()=>{console.error("executeEditorQuery executionContext is not provided")}))}async canDestroy(e){return await this.sqlDataSourceService.canDestroy(e.editorId)}async destroy(e){await this.sqlDataSourceService.destroy(e.editorId)}async initContext(e,t,s){const i=await this.connectionsManagerService.requireConnection(e);if(!i)return null;try{return await this.connectionExecutionContextService.create(e,t,s)}catch(e){return this.notificationService.logException(e,`Failed to create context for ${i.name} connection`),null}}async destroyContext(e){await this.connectionExecutionContextResource.load(l.fZ);const t=this.connectionExecutionContextService.get(e.id);if(t)try{await t.destroy()}catch(e){this.notificationService.logException(e,`Failed to destroy SQL-context ${t.context?.id}`,"",!0)}}};m=(0,i.Cg)([(0,u._)(),(0,i.Sn)("design:paramtypes",[p.GraphQLService,a.ConnectionsManagerService,d.NotificationService,c.ConnectionExecutionContextService,o.ConnectionExecutionContextResource,n.ConnectionInfoResource,x.SqlDataSourceService,v.SqlEditorSettingsService,h.ServerConfigResource])],m)},14515:(e,t,s)=>{s.r(t),s.d(t,{SqlEditorSettingsService:()=>b});var i=s(1118),r=s(63716),n=s(5576),o=s(8674),a=s(76761),c=s(70446),u=s(83625),d=s(83916),l=s(80625),h=s(82607),p=s(3065),S=s(31038);const g=s(93424).P.createSubGroup("plugin_sql_editor_sql_editor_settings_group"),x=["NONE","PLAIN","EXTENDED"],v=[{value:"NONE",name:"ui_disable"},{value:"PLAIN",name:"my_table mt"},{value:"EXTENDED",name:"my_table AS mt"}],m=p.Ik({"plugin.sql-editor.maxFileSize":p.au.number().default(10240),"plugin.sql-editor.disabled":S.W.stringedBoolean().default(!1),"plugin.sql-editor.autoSave":S.W.stringedBoolean().default(!0),"sql.proposals.insert.table.alias":p.au.string().transform((e=>{switch(e){case"false":return"NONE";case"true":return"PLAIN";default:return e}})).pipe(p.k5(x)).default("PLAIN")});let b=class SqlEditorSettingsService extends r.O{get maxFileSize(){return this.settings.getValue("plugin.sql-editor.maxFileSize")}get disabled(){return this.settings.getValue("plugin.sql-editor.disabled")}get autoSave(){return this.settings.getValue("plugin.sql-editor.autoSave")}get insertTableAlias(){return this.settings.getValue("sql.proposals.insert.table.alias")}constructor(e,t,s,i){super(),this.settingsProviderService=e,this.settingsManagerService=t,this.settingsResolverService=s,this.serverSettingsManagerService=i,this.settings=this.settingsProviderService.createSettings(m),this.settingsResolverService.addResolver(a.T,(0,c.q)(this.settingsResolverService,this.settings,{"plugin.sql-editor.autoSave":"core.app.sqlEditor.autoSave","plugin.sql-editor.maxFileSize":"core.app.sqlEditor.maxFileSize","plugin.sql-editor.disabled":"core.app.sqlEditor.disabled"})),this.registerSettings()}registerSettings(){this.serverSettingsManagerService.setGroupOverride("editors/sqlEditor",g),this.serverSettingsManagerService.setSettingTransformer("sql.proposals.insert.table.alias",(e=>({...e,group:g,name:"sql_editor_settings_insert_table_aliases_name",description:"sql_editor_settings_insert_table_aliases_desc",options:[...e.options?.filter((e=>!x.includes(e.value)))||[],...v]}))),this.settingsManagerService.registerSettings(this.settings,(()=>{const e=[];return this.serverSettingsManagerService.providedSettings.has("sql.proposals.insert.table.alias")||e.push({key:"sql.proposals.insert.table.alias",access:{scope:["server","client"]},group:g,type:u.E.Select,name:"sql_editor_settings_insert_table_aliases_name",description:"sql_editor_settings_insert_table_aliases_desc",options:v}),e}))}};b=(0,i.Cg)([(0,n._)(),(0,i.Sn)("design:paramtypes",[d.SettingsProviderService,l.SettingsManagerService,h.SettingsResolverService,o.ServerSettingsManagerService])],b)},64742:(e,t,s)=>{s.r(t),s.d(t,{SqlEditorView:()=>x});var i=s(1118),r=s(5576),n=s(37136),o=s(48995),a=s(19697),c=s(26160),u=s(33901),d=s(75525),l=s(64756),h=s(98391),p=s(22247),S=s(95296),g=s(23653);let x=class SqlEditorView extends n.S{constructor(e){super(),this.navigationTabsService=e,this.registerAction(l.R,h._,d.C,p._,o.u,a.O,S.T,g.M,c.t)}getView(){return this.navigationTabsService.getView()}};x=(0,i.Cg)([(0,r._)(),(0,i.Sn)("design:paramtypes",[u.NavigationTabsService])],x)},10009:(e,t,s)=>{s.d(t,{Y:()=>i});const i=(0,s(44745).M)("sql-editor-result-id")},53250:(e,t,s)=>{s.r(t),s.d(t,{SqlExecutionPlanPanel:()=>B});var i=s(41773),r=s(7838),n=s(15993),o=s(64928),a=s(67590),c=s(69519),u=s(51565),d=s(18662),l=s(7167),h=s(16796),p=s(18699),S=s(17675),g=s(84349),x=s(74842),v=s(48286),m=s(85289),b=s(14249),y=s(76228);const f={pane:"pane___rclX9 theme-background-surface theme-text-on-surface",split:"split___T_bsX",resizerControls:"resizerControls___VBrr7",textarea:"textarea___QBGu_"};var _=s(38236),q=s(50453),I=s(15682),C=s(13676),E=s(84237);const w={icon:"icon___tK1Qa theme-text-on-surface",expanded:"expanded___DZDgt"},j=function Expand({expanded:e,className:t,onClick:s}){const r=(0,o.d)(w);return(0,i.jsx)(E.I,{className:(0,l.s)(r,{icon:!0,expanded:e},t),name:"arrow",viewBox:"0 0 16 16",onClick:s})};function getPropertyValue(e){const t=e.value;return t?null!==t&&"object"==typeof t?t.displayValue||t.fullName||"":t:""}const T="tableColumnValue___xLvnq",D="expandContainer___cccao",R="control___iQDtP",A=function NestedNode({columns:e,node:t,depth:s,className:r}){const[o,a]=(0,n.useState)(!0),c=(0,n.useCallback)((e=>{C.y.set(e,_.C),a((e=>!e))}),[]),u=t.children.length>0;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(q.O,{className:r,item:t.id,selectOnItem:!0,children:e.map(((e,r)=>{const n=t.properties.find((t=>t.id===e.id)),a=n?getPropertyValue(n):"";return(0,i.jsx)(I.E,{title:a||void 0,className:T,children:(0,i.jsxs)("div",{className:R,children:[0===r&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("span",{children:`${"\t".repeat(s)}`}),(0,i.jsx)("div",{className:D,children:u&&(0,i.jsx)(j,{expanded:o,onClick:c})})]}),a]})},`${n?.id}_${s}`)}))},`${t.id}_${s}`),o&&t.children.map((t=>(0,i.jsx)(NestedNode,{columns:e,node:t,depth:s+1},t.id)))]})};var P=s(94866),M=s(28347);function isVisibleProperty(e){return e.features.includes("viewable")}const L=(0,r.PA)((function ExecutionPlanTreeBlock({nodeList:e,query:t,onNodeSelect:s,className:r}){const n=(0,o.d)(f),c=(0,S.W)(),p=(0,a.s)("execution-plan-block"),_=function useExecutionPlanTreeState(e,t){return(0,M.G)((()=>({selectedNodes:new Map,get columns(){const e=[];for(const t of this.nodeList)for(const s of t.properties)s.id&&isVisibleProperty(s)&&!e.find((e=>e.id===s.id))&&e.push(s);return e},get nodes(){const e=new Map,t=this.nodeList.map(((t,s)=>(e.set(t.id,s),{...t,children:[]}))),s=[];for(const i of t)i.parentId?t[e.get(i.parentId)].children.push(i):s.push(i);return s},selectNode(e){this.selectedNodes.clear(),this.selectedNodes.set(e,!0),this.onNodeSelect(e)}})),{selectedNodes:P.sH,nodeList:P.sH.ref,columns:P.EW,nodes:P.EW},{nodeList:e,onNodeSelect:t},["selectNode"])}(e,s);return(0,i.jsxs)(u.B,{className:(0,l.s)(n,{split:!0},r),...p,sticky:30,split:"horizontal",keepRatio:!0,children:[(0,i.jsx)(d.Z,{className:n.pane,children:_.nodes.length&&_.columns.length?(0,i.jsxs)(g.X,{selectedItems:_.selectedNodes,onSelect:_.selectNode,children:[(0,i.jsx)(x.A,{fixed:!0,children:_.columns.map((e=>{const t=e.displayName,s=`${t} ${e.description?"("+e.description+")":""}`;return(0,i.jsx)(v.u,{title:s,children:t},e.id||e.order)}))}),(0,i.jsx)(m.B,{children:_.nodes.map((e=>(0,i.jsx)(A,{columns:_.columns,node:e,depth:0},e.id)))})]}):(0,i.jsx)(b.x,{children:c("sql_execution_plan_placeholder")})}),(0,i.jsx)(h.$,{className:n.resizerControls}),(0,i.jsx)(d.Z,{className:n.pane,basis:"30%",main:!0,children:(0,i.jsx)(y.T,{className:(0,l.s)(n,{textarea:!0},r),name:"value",rows:3,value:t,readOnly:!0,embedded:!0})})]})})),k="tableColumnValue___VGyWD",Q="control___xLwko",N="expandContainer___Ep_el",O=function PropertiesPanelItemsGroup({properties:e,name:t}){const[s,r]=(0,n.useState)(!0);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(q.O,{item:`${t}_root`,selectDisabled:!0,children:[(0,i.jsx)(I.E,{className:k,title:t,children:(0,i.jsxs)("div",{className:Q,children:[(0,i.jsx)("div",{className:N,children:(0,i.jsx)(j,{expanded:s,onClick:()=>r(!s)})}),t]})}),(0,i.jsx)(I.E,{className:k})]}),s&&e.map((e=>{const t=e.displayName,s=`${t} ${e.description?"("+e.description+")":""}`,r=getPropertyValue(e);return(0,i.jsxs)(q.O,{item:e.id,selectDisabled:!0,children:[(0,i.jsx)(I.E,{className:k,title:s,children:"\t\t"+t}),(0,i.jsx)(I.E,{className:k,title:r,children:r})]},e.id)}))]})},G=(0,r.PA)((function PropertiesPanel({selectedNode:e,nodeList:t,className:s}){const r=(0,S.W)(),{general:o,details:a}=(0,n.useMemo)((()=>(0,P.EW)((()=>{const s=[],i=[],r=t.find((t=>t.id===e));if(!r)return{general:s,details:i};for(const e of r.properties)isVisibleProperty(e)?s.push(e):i.push(e);return{general:s,details:i}}))),[e,t]).get();if(!o.length&&!a.length)return(0,i.jsx)(b.x,{children:r("sql_execution_plan_properties_panel_placeholder")});const c=r("sql_execution_plan_properties_panel_name"),u=r("sql_execution_plan_properties_panel_value");return(0,i.jsxs)(g.X,{className:s,children:[(0,i.jsxs)(x.A,{fixed:!0,children:[(0,i.jsx)(v.u,{title:c,children:c}),(0,i.jsx)(v.u,{title:u,children:u})]}),(0,i.jsxs)(m.B,{children:[!!o.length&&(0,i.jsx)(O,{properties:o,name:r("sql_execution_plan_properties_panel_general")}),!!a.length&&(0,i.jsx)(O,{properties:a,name:r("sql_execution_plan_properties_panel_details")})]})]})})),H={pane:"pane___yQIWM"};var V=s(32010);const B=(0,r.PA)((function SqlExecutionPlanPanel({executionPlanTab:e}){const t=(0,o.d)(H),s=(0,p.h)(V.SqlExecutionPlanService).data.get(e.tabId),[r,S]=(0,n.useState)(null),g=(0,a.s)("execution-plan");return s?.task.executing||!s?.executionPlan?(0,i.jsx)(c.a,{cancelDisabled:!s?.task.cancellable,onCancel:()=>s?.task.cancel()}):(0,i.jsxs)(u.B,{...g,mode:r?g.mode:"minimize",disable:!r,sticky:30,children:[(0,i.jsx)(d.Z,{className:(0,l.s)(t,{pane:!0}),children:(0,i.jsx)(L,{nodeList:s.executionPlan.nodes,query:s.executionPlan.query,onNodeSelect:S})}),(0,i.jsx)(h.$,{}),(0,i.jsx)(d.Z,{className:(0,l.s)(t,{pane:!0}),basis:"30%",main:!0,children:r&&(0,i.jsx)(G,{selectedNode:r,nodeList:s.executionPlan.nodes})})]})}))},32010:(e,t,s)=>{s.r(t),s.d(t,{SqlExecutionPlanService:()=>h});var i=s(1118),r=s(94866),n=s(13225),o=s(5576),a=s(14452),c=s(83336),u=s(45764),d=s(35721),l=s(64486);let h=class SqlExecutionPlanService{constructor(e,t,s,i,n){this.graphQLService=e,this.notificationService=t,this.asyncTaskInfoService=s,this.connectionExecutionContextService=i,this.sqlDataSourceService=n,this.data=new Map,(0,r.Gn)(this,{data:r.sH})}async executeExecutionPlan(e,t){const s=this.sqlDataSourceService.get(e.editorId),i=s?.executionContext,r=i&&this.connectionExecutionContextService.get(i.id);if(!i||!r)return void console.error("executeExecutionPlan executionContext is not provided");const n=this.createExecutionPlanTab(e,t);e.currentTabId=n;const o=this.asyncTaskInfoService.create((async()=>{const{taskInfo:e}=await this.graphQLService.sdk.asyncSqlExplainExecutionPlan({projectId:i.projectId,connectionId:i.connectionId,contextId:i.id,query:t,configuration:{}});return e})),a=r.run((async()=>{const e=await this.asyncTaskInfoService.run(o),{result:t}=await this.graphQLService.sdk.getSqlExecutionPlanResult({taskId:e.id});return t}),(()=>this.asyncTaskInfoService.cancel(o.id)),(()=>this.asyncTaskInfoService.remove(o.id)));this.data.set(n,{task:a,executionPlan:null});try{const t=await a;if(!e.tabs.find((e=>e.id===n)))return;this.data.set(n,{task:a,executionPlan:t})}catch(t){const s=a.cancelled,i=s?"Execution plan process has been canceled":void 0;if(this.notificationService.logException(t,"Execution plan Error",i),this.removeTab(e,n),!s)throw t}}removeTab(e,t){const s=e.tabs.find((e=>e.id===t));s&&e.tabs.splice(e.tabs.indexOf(s),1),this.removeExecutionPlanTab(e,t),e.tabs.length>0?e.currentTabId=e.tabs[0].id:e.currentTabId=""}removeExecutionPlanTab(e,t){const s=e.executionPlanTabs.find((e=>e.tabId===t));s&&e.executionPlanTabs.splice(e.executionPlanTabs.indexOf(s),1);const i=this.data.get(t);i&&i.task.cancel(),this.data.delete(t)}createExecutionPlanTab(e,t){if(!this.sqlDataSourceService.get(e.editorId))throw new Error("SQL Data Source is not provided");const s=(0,d.u)(),i=Math.max(0,...e.tabs.map((e=>e.order+1))),r=Math.max(1,...e.executionPlanTabs.map((e=>e.order+1)));return e.executionPlanTabs.push({tabId:s,order:r,query:t}),e.tabs.push({id:s,name:`Execution plan - ${r}`,icon:"execution-plan-tab",order:i}),s}};h=(0,i.Cg)([(0,o._)(),(0,i.Sn)("design:paramtypes",[c.GraphQLService,a.NotificationService,u.AsyncTaskInfoService,n.ConnectionExecutionContextService,l.SqlDataSourceService])],h)},92482:(e,t,s)=>{s.d(t,{d:()=>i});const i=["Debug","Log","Info","Notice","Warning","Error"]},37902:(e,t,s)=>{s.d(t,{M:()=>i});const i=(0,s(85240).E)("output_logs_menu","Output Logs")},8884:(e,t,s)=>{s.d(t,{o:()=>i});const i="output_logs"},25825:(e,t,s)=>{s.r(t),s.d(t,{OutputLogsEventHandler:()=>c});var i=s(1118),r=s(5576),n=s(21335),o=s(43974),a=s(60018);let c=class OutputLogsEventHandler extends n._{constructor(e){super(o.nKA.CbDatabaseOutputLog,e)}map(e){return e}};c=(0,i.Cg)([(0,r._)(),(0,i.Sn)("design:paramtypes",[a.SessionEventSource])],c)},68916:(e,t,s)=>{s.r(t),s.d(t,{OutputLogsPanel:()=>E});var i=s(41773),r=s(7838),n=s(84383),o=s(76652),a=s(16101),c=s(18699),u=s(94302),d=s(52285),l=s(21538),h=(s(15993),s(17675)),p=s(408),S=s(7167),g=s(90398),x=s(21252),v=s(26339),m=s(12483),b=s(27929),y=s(37902);const f={menuBar:"menuBar___JjxIU"},_=(0,r.PA)((function OutputLogsMenu({sqlEditorTabState:e}){const t=(0,m.b)({menu:y.M});return(0,g.Z)(t.context,((t,s)=>{t.set(b.M,e,s)})),(0,i.jsx)(x.R,{menu:t,nestedMenuSettings:{modal:!0,placement:"top-start"},className:(0,S.s)(f,{menuBar:!0},v.A.floating)})})),q=(0,r.PA)((function OutputLogsToolbar({state:e,sqlEditorTabState:t}){const s=(0,h.W)();return(0,i.jsxs)(o.m,{noWrap:!0,center:!0,gap:!0,dense:!0,keepSize:!0,children:[(0,i.jsx)(p.d,{value:e.searchValue,placeholder:s("sql_editor_output_logs_input_placeholder"),onChange:t=>e.setSearchValue(t.toString())}),(0,i.jsx)(o.m,{keepSize:!0,children:(0,i.jsx)(_,{sqlEditorTabState:t})})]})}));var I=s(94866),C=s(28347);const useOutputLogsPanelState=(e,t)=>(0,C.G)((()=>({searchValue:"",setSearchValue(e){this.searchValue=e},get filteredLogs(){const s=t.outputLogsTab?.selectedLogTypes;return s?.length?e.filter((e=>!(e.severity&&!s.includes(e.severity))&&!(e.message&&this.searchValue.length>0&&!e.message.toLowerCase().includes(this.searchValue.toLowerCase())))):[]},get resultValue(){return this.filteredLogs.map((e=>{let t="";return e.severity&&(t+=`[${e.severity}] `),e.message&&(t+=e.message),t})).join("\n")}})),{searchValue:I.sH.ref,setSearchValue:I.XI.bound,filteredLogs:I.EW,resultValue:I.EW},!1),E=(0,r.PA)((function SqlOutputLogsPanel({sqlEditorTabState:e}){const t=(0,c.h)(l.OutputLogsService),{data:s}=(0,n.q)(SqlOutputLogsPanel,d.OutputLogsResource,void 0),r=t.getOutputLogs(s,e),h=useOutputLogsPanelState(r,e);return(0,i.jsxs)(o.m,{className:"theme-background-secondary",overflow:!0,vertical:!0,noWrap:!0,dense:!0,parent:!0,gap:!0,children:[(0,i.jsx)(q,{state:h,sqlEditorTabState:e}),s&&(0,i.jsx)(a.Y,{box:!0,children:(0,i.jsx)(u.Z,{value:h.resultValue,foldGutter:!1,lineWrapping:t.settings.wrapMode,highlightActiveLine:!1,readonly:!0})})]})}))},52285:(e,t,s)=>{s.r(t),s.d(t,{OutputLogsResource:()=>u});var i=s(1118),r=s(30606),n=s(5576),o=s(20839),a=s(43974),c=s(25825);let u=class OutputLogsResource extends o.V{constructor(e,t){super((()=>[])),this.connectionExecutionContextResource=t,e.onEvent(a.OYz.CbDatabaseOutputLogUpdated,(e=>{this.collectMessagesFromEvent(e)}),void 0,this),this.useTracker.use(void 0),this.connectionExecutionContextResource.onItemDelete.addHandler((e=>{this.setData(this.data.filter((t=>t.contextId!==e)))}))}collectMessagesFromEvent(e){const t=e.messages.map((t=>({message:t.message,severity:t.severity,contextId:e.contextId,timestamp:e.eventTimestamp}))),s=(this.data||[]).concat(t);this.setData(s)}async loader(){return this.data}};u=(0,i.Cg)([(0,n._)(),(0,i.Sn)("design:paramtypes",[c.OutputLogsEventHandler,r.ConnectionExecutionContextResource])],u)},21538:(e,t,s)=>{s.r(t),s.d(t,{OutputLogsService:()=>u});var i=s(1118),r=s(50966),n=s(5576),o=s(64486),a=s(92482),c=s(8884);let u=class OutputLogsService{get settings(){return this.userDataService.getUserData("output_logs",getOutputLogsDefaultSettings)}constructor(e,t){this.sqlDataSourceService=e,this.userDataService=t}async showOutputLogs(e){this.createOutputLogsTab(e),e.currentTabId=c.o}removeOutputLogsTab(e,t){t===c.o&&(e.outputLogsTab=void 0)}toggleWrapMode(){this.settings.wrapMode=!this.settings.wrapMode}createOutputLogsTab(e){const t=Math.max(0,...e.tabs.map((e=>e.order+1)));if(e.tabs.find((e=>e.id===c.o)))return;const s={id:c.o,name:"Output",icon:"/icons/sql_output_logs.svg",order:t};e.outputLogsTab={...s,selectedLogTypes:[...a.d]},e.tabs.push({...s})}getOutputLogs(e,t){const s=this.sqlDataSourceService.get(t.editorId);return e.filter((e=>e.contextId===s?.executionContext?.id))}};function getOutputLogsDefaultSettings(){return{wrapMode:!0}}u=(0,i.Cg)([(0,n._)(),(0,i.Sn)("design:paramtypes",[o.SqlDataSourceService,r.UserDataService])],u)},61606:(e,t,s)=>{s.r(t),s.d(t,{OutputMenuBootstrap:()=>q});var i=s(1118),r=s(82103),n=s(5576),o=s(55511),a=s(79023),c=s(72877),u=s(81604),d=s(23653);const l=(0,s(45215).X)({id:"sql-editor-show-output",keys:"shift+ctrl+o",preventDefault:!0});var h=s(27929),p=s(80957),S=s(64486),g=s(77978);const x=(0,s(19102).V)("action-show_output_logs",{label:"sql_editor_output_logs_button_tooltip",icon:"/icons/sql_output_logs.svg",tooltip:"sql_editor_output_logs_button_tooltip"});var v=s(92482),m=s(85240);const b=(0,m.E)("output_logs_filter_menu","","filter","ui_filter");var y=s(37902);const f=(0,m.E)("output_logs_settings_menu","","/icons/settings_cog_sm.svg","ui_settings");var _=s(21538);let q=class OutputMenuBootstrap extends r.j{constructor(e,t,s,i,r){super(),this.actionService=e,this.menuService=t,this.outputLogsService=s,this.sqlDataSourceService=i,this.keyBindingService=r}register(){this.menuService.addCreator({menus:[y.M],getItems:(e,t)=>[...t,b,f]}),this.menuService.addCreator({menus:[b],getItems:(e,t)=>{const s=e.get(h.M);if(!s)return[];const i=s?.outputLogsTab,r=[];for(const e of v.d)r.push(new o.s({id:e,label:e,tooltip:e},{onSelect:()=>{if(i?.selectedLogTypes){if(i.selectedLogTypes.includes(e))return void(i.selectedLogTypes=i.selectedLogTypes.filter((t=>t!==e)));i.selectedLogTypes=[...i.selectedLogTypes,e]}}},{isChecked:()=>!!i?.selectedLogTypes.includes(e)}));return[...t,...r]}}),this.menuService.addCreator({menus:[f],getItems:(e,t)=>{if(!e.get(h.M))return[];return[...t,new o.s({id:"wrap-mode",label:"sql_editor_output_logs_wrap_mode",tooltip:"sql_editor_output_logs_wrap_mode"},{onSelect:()=>{this.outputLogsService.toggleWrapMode()}},{isChecked:()=>this.outputLogsService.settings.wrapMode})]}}),this.registerOutputLogsAction()}registerOutputLogsAction(){this.actionService.addHandler({id:"output-logs-handler",actions:[x],contexts:[h.M],isActionApplicable:e=>{const t=e.get(h.M),s=this.sqlDataSourceService.get(t.editorId),i=s?.hasFeature(p.A.query),r=s?.hasFeature(p.A.executable);return!!i&&!!r},handler:async(e,t)=>{const s=e.get(h.M);t===x&&this.outputLogsService.showOutputLogs(s)}}),this.menuService.addCreator({menus:[g.J],getItems:(e,t)=>[...t,x]}),this.keyBindingService.addKeyBindingHandler({id:"sql-editor-show-output",binding:l,actions:[d.M],contexts:[h.M],handler:(e,t)=>{const s=e.get(h.M);t===d.M&&this.outputLogsService.showOutputLogs(s)}})}};q=(0,i.Cg)([(0,n._)(),(0,i.Sn)("design:paramtypes",[a.ActionService,c.MenuService,_.OutputLogsService,S.SqlDataSourceService,u.KeyBindingService])],q)},37504:(e,t,s)=>{s.r(t),s.d(t,{SqlQueryResultService:()=>a});var i=s(1118),r=s(5576),n=s(35721),o=s(72286);let a=class SqlQueryResultService{constructor(e){this.tableViewerStorageService=e}getSelectedGroup(e){const t=e.tabs.find((t=>t.id===e.currentTabId)),s=e.resultTabs.find((e=>e.tabId===t?.id));return s&&e.resultGroups.find((e=>e.groupId===s.groupId))||null}getGroups(e){return e.resultGroups}getGroup(e,t){return e.resultGroups.find((e=>e.groupId===t))}getModelGroup(e,t){return e.resultGroups.find((e=>e.modelId===t))}updateGroupTabs(e,t,s,i,r){const n=this.getGroup(e,s);if(!n)return;this.createTabsForGroup(e,n,t,r);const o=e.resultTabs.filter((e=>e.groupId===s&&0!==e.indexInResultSet&&e.indexInResultSet>=t.source.results.length)).map((e=>e.tabId));e.tabs=e.tabs.filter((e=>!o.includes(e.id))),e.resultTabs=e.resultTabs.filter((e=>!o.includes(e.tabId))),i&&this.selectFirstResult(e,s)}createGroup(e,t,s,i){const r=(0,n.u)(),o=Math.max(0,...e.tabs.map((e=>e.order+1)));return e.resultGroups.push({groupId:r,modelId:t,order:o,nameOrder:i??this.getGroupNameOrder(e),query:s}),e.resultGroups.find((e=>e.groupId===r))}createStatisticsTab(e){const t=this.getGroupNameOrder(e),s=Math.max(0,...e.tabs.map((e=>e.order+1))),i=(0,n.u)();return e.statisticsTabs.push({tabId:i,order:t}),e.tabs.push({id:i,name:`Statistics - ${t}`,icon:"table-icon",order:s}),e.statisticsTabs.find((e=>e.tabId===i))}removeStatisticsTab(e,t){e.tabs=e.tabs.filter((e=>e.id!==t)),e.statisticsTabs=e.statisticsTabs.filter((e=>e.tabId!==t))}removeGroup(e,t){const s=this.getGroup(e,t);if(!s)return;const i=e.resultTabs.filter((e=>e.groupId===t)).map((e=>e.tabId));e.tabs=e.tabs.filter((e=>!i.includes(e.id))),e.resultGroups=e.resultGroups.filter((e=>e.groupId!==t)),e.resultTabs=e.resultTabs.filter((e=>e.groupId!==t)),e.currentTabId=e.tabs[0]?.id,this.tableViewerStorageService.remove(s.modelId)}getGroupNameOrder(e){return Math.max(1,...e.resultGroups.map((e=>e.nameOrder+1)),...e.statisticsTabs.map((e=>e.order+1)))}async canCloseResultTab(e,t){const s=e.resultTabs.find((e=>e.tabId===t)),i=e.resultGroups.find((e=>e.groupId===s?.groupId));if(s&&i){const e=this.tableViewerStorageService.get(i.modelId);if(e){let t=!1;try{await e.requestDataAction((()=>{t=!0}))}catch{}return t}}return!0}removeResultTab(e,t){const s=e.resultTabs.find((e=>e.tabId===t)),i=e.resultGroups.find((e=>e.groupId===s?.groupId));if(s&&i){e.resultTabs.splice(e.resultTabs.indexOf(s),1);const t=!e.resultTabs.some((e=>e.groupId===i.groupId));if(t){e.resultGroups.splice(e.resultGroups.indexOf(i),1);const t=this.tableViewerStorageService.get(i.modelId);t?.dispose(!0),this.tableViewerStorageService.remove(i.modelId)}}}selectResult(e,t,s){const i=e.resultTabs.filter((e=>e.groupId===t)).sort(((e,t)=>e.indexInResultSet===s?-1:e.indexInResultSet-t.indexInResultSet));e.currentTabId=i[0].tabId}selectFirstResult(e,t){const s=e.resultTabs.filter((e=>e.groupId===t)).sort(((e,t)=>e.indexInResultSet-t.indexInResultSet));e.currentTabId=s[0].tabId}createTabsForGroup(e,t,s,i){this.createResultTabForGroup(e,t,s,0,i);for(let r=1;r<s.source.results.length;r++)this.createResultTabForGroup(e,t,s,r,i)}createResultTabForGroup(e,t,s,i,r){const n=e.resultTabs.find((e=>e.groupId===t.groupId&&e.indexInResultSet===i));if(n){const o=e.tabs.find((e=>e.id===n.tabId));o&&(o.name=this.getTabNameForOrder(t.nameOrder,i,s.source.results.length,r))}else this.createResultTab(e,t,i,s.source.results.length,r)}updateResultTab(e,t,s){const i=e.resultTabs.findIndex((e=>e.tabId===t));-1!==i&&(e.resultTabs[i]={...e.resultTabs[i],...s})}createResultTab(e,t,s,i,r){const o=(0,n.u)();e.resultTabs.push({tabId:o,groupId:t.groupId,indexInResultSet:s,presentationId:"",valuePresentationId:null}),e.tabs.push({id:o,name:this.getTabNameForOrder(t.nameOrder,s,i,r),icon:"table-icon",order:t.order})}getTabNameForOrder(e,t,s,i){let r=`Result - ${e}`;return i&&(r+=` <${i}>`),s>1&&(r+=` (${t+1})`),r}};a=(0,i.Cg)([(0,r._)(),(0,i.Sn)("design:paramtypes",[o.TableViewerStorageService])],a)},79031:(e,t,s)=>{s.r(t),s.d(t,{SqlQueryService:()=>_});var i=s(1118),r=s(94866),n=s(49690),o=s(13225),a=s(5576),c=s(48138),u=s(14452),d=s(83336),l=s(45764),h=s(72078),p=s(93979),S=s(35173),g=s(72286),x=s(38799),v=s(93652),m=s(71423),b=s(85855),y=s(64486),f=s(37504);let _=class SqlQueryService{constructor(e,t,s,i,n,o,a,c,u,d,l,h){this.app=e,this.tableViewerStorageService=t,this.graphQLService=s,this.notificationService=i,this.connectionInfoResource=n,this.connectionExecutionContextService=o,this.sqlQueryResultService=a,this.asyncTaskInfoService=c,this.dataViewerDataChangeConfirmationService=u,this.dataViewerService=d,this.sqlDataSourceService=l,this.dataViewerSettingsService=h,this.statisticsMap=new Map,(0,r.Gn)(this,{statisticsMap:r.sH})}getStatistics(e){return this.statisticsMap.get(e)}initDatabaseDataModels(e){const t=this.sqlDataSourceService.get(e.editorId),s=t?.databaseModels;if(!s)return;const i=this.sqlQueryResultService.getGroups(e).filter((e=>!s.some((t=>t.id===e.modelId))));for(const t of i)this.sqlQueryResultService.removeGroup(e,t.groupId);let r=!0;for(const t of s){this.tableViewerStorageService.add(t),this.dataViewerDataChangeConfirmationService.trackTableDataUpdate(t.id);let s=this.sqlQueryResultService.getModelGroup(e,t.id);s||(s=this.sqlQueryResultService.createGroup(e,t.id,t.source.options?.query??""),this.switchTabToActiveRequest(e,s,t),this.sqlQueryResultService.updateGroupTabs(e,t,s.groupId,r),t.onRequest.addHandler((({type:t,model:s})=>{if("after"===t){const t=this.sqlQueryResultService.getModelGroup(e,s.id);t&&this.sqlQueryResultService.updateGroupTabs(e,s,t.groupId)}})),r=!1)}}async executeEditorQuery(e,t,s){const i=this.sqlDataSourceService.get(e.editorId),r=i?.executionContext,o=r&&this.connectionExecutionContextService.get(r.id);if(!r||!o)return void console.error("executeEditorQuery executionContext is not provided");let a,c,u=!1;const d=(0,n.createConnectionParam)(r.projectId,r.connectionId),l=await this.connectionInfoResource.load(d);let S=this.sqlQueryResultService.getSelectedGroup(e);s||!S?(a=new b.E(this.app.getServiceInjector(),this.graphQLService,this.asyncTaskInfoService),c=this.tableViewerStorageService.add(new h.j(a)),this.dataViewerDataChangeConfirmationService.trackTableDataUpdate(c.id),S=this.sqlQueryResultService.createGroup(e,c.id,t),this.switchTabToActiveRequest(e,S,c),u=!0):(c=this.tableViewerStorageService.get(S.modelId),a=c.source,S.query=t);const g=this.dataViewerService.isDataEditable(l),x=!!e.outputLogsTab;c.setAccess(g?p.J.Default:p.J.Readonly).setOptions({query:t,connectionKey:d,constraints:[],whereFilter:"",readLogs:x}).source.setExecutionContext(o).setSupportedDataFormats(l.supportedDataFormats),this.sqlQueryResultService.updateGroupTabs(e,c,S.groupId,!0);try{await c.setCountGain(this.dataViewerSettingsService.getDefaultRowsCount()).setSlice(0).request(),c.setName(this.sqlQueryResultService.getTabNameForOrder(S.nameOrder,0,c.getResults().length)),this.sqlQueryResultService.updateGroupTabs(e,c,S.groupId)}catch(t){if(a.currentTask?.cancelled&&u){this.sqlQueryResultService.removeGroup(e,S.groupId);const s="Query execution has been canceled";return void this.notificationService.logException(t,"Query execution Error",s)}throw t}}async executeQueries(e,t,s){const i=this.sqlDataSourceService.get(e.editorId),r=i?.executionContext,o=r&&this.connectionExecutionContextService.get(r.id);if(!r||!o)return void console.error("executeEditorQuery executionContext is not provided");const a=this.sqlQueryResultService.getGroupNameOrder(e),c=(0,n.createConnectionParam)(r.projectId,r.connectionId),u=await this.connectionInfoResource.load(c),d=this.sqlQueryResultService.createStatisticsTab(e);this.statisticsMap.set(d.tabId,{queries:t.length,executedQueries:0,executeTime:0,updatedRows:0,modelId:null}),e.currentTabId=d.tabId;const l=this.getStatistics(d.tabId);let S,g,x=0;for(let i=0;i<t.length;i++){const r=t[i];s?.onQueryExecutionStart?.(r,i),g&&S||(S=new b.E(this.app.getServiceInjector(),this.graphQLService,this.asyncTaskInfoService),g=this.tableViewerStorageService.add(new h.j(S)),this.dataViewerDataChangeConfirmationService.trackTableDataUpdate(g.id)),l.modelId=g.id;const n=this.dataViewerService.isDataEditable(u),d=!!e.outputLogsTab;g.setAccess(n?p.J.Default:p.J.Readonly).setOptions({query:r,connectionKey:c,constraints:[],whereFilter:"",readLogs:d}).source.setExecutionContext(o).setSupportedDataFormats(u.supportedDataFormats);try{await g.setCountGain(this.dataViewerSettingsService.getDefaultRowsCount()).setSlice(0).request();const t=g.source.cancelled;l.executedQueries++,l.executeTime+=S.requestInfo.requestDuration;for(const e of S.results)l.updatedRows+=e.updateRowCount;if(S.results.some((e=>e.data))){x+=1;const t=this.sqlQueryResultService.createGroup(e,g.id,r,a);g.setName(this.sqlQueryResultService.getTabNameForOrder(t.nameOrder,0,g.getResults().length,x)),this.switchTabToActiveRequest(e,t,g),this.sqlQueryResultService.updateGroupTabs(e,g,t.groupId,!1,x),g=S=void 0}if(s?.onQueryExecuted?.(r,i,!0),t)break}catch(t){if(g){const t=this.sqlQueryResultService.createGroup(e,g.id,r);this.sqlQueryResultService.updateGroupTabs(e,g,t.groupId,!0,x),g=S=void 0}s?.onQueryExecuted?.(r,i,!1);break}}l.modelId=null,g&&this.tableViewerStorageService.remove(g.id)}removeStatisticsTab(e,t){this.sqlQueryResultService.removeStatisticsTab(e,t),this.statisticsMap.delete(t)}switchTabToActiveRequest(e,t,s){s.onRequest.addPostHandler((({type:i})=>{if("on"===i){const i=this.sqlQueryResultService.getSelectedGroup(e)?.groupId;for(const r of s.getResults()){const n=s.source.getActionImplementation(r,S.M);if(n?.isEdited()&&s.source.executionContext?.context&&i!==t.groupId)return void this.sqlQueryResultService.selectResult(e,t.groupId,s.getResults().indexOf(r))}}}))}};_=(0,i.Cg)([(0,a._)(),(0,i.Sn)("design:paramtypes",[c.q,g.TableViewerStorageService,d.GraphQLService,u.NotificationService,n.ConnectionInfoResource,o.ConnectionExecutionContextService,f.SqlQueryResultService,l.AsyncTaskInfoService,x.DataViewerDataChangeConfirmationService,v.DataViewerService,y.SqlDataSourceService,m.DataViewerSettingsService])],_)},66793:(e,t,s)=>{s.r(t),s.d(t,{SqlResultSetPanel:()=>u});var i=s(41773),r=s(7838),n=s(18699),o=s(18861),a=s(37504);const c="tableViewerLoader___p5zr1",u=(0,r.PA)((function SqlResultSetPanel({state:e,resultTab:t}){const s=(0,n.h)(a.SqlQueryResultService),r=e.resultGroups.find((e=>e.groupId===t.groupId));if(!r)throw new Error("Result group not found");return(0,i.jsx)(o.U,{className:c,tableId:r.modelId,resultIndex:t.indexInResultSet,presentationId:t.presentationId,valuePresentationId:t.valuePresentationId,onPresentationChange:function onPresentationChange(i){s.updateResultTab(e,t.tabId,{presentationId:i})},onValuePresentationChange:function onValuePresentationChange(i){s.updateResultTab(e,t.tabId,{valuePresentationId:i})}})}))},4222:(e,t,s)=>{s.r(t),s.d(t,{SqlResultTabsService:()=>d});var i=s(1118),r=s(94866),n=s(5576),o=s(32010),a=s(21538),c=s(37504),u=s(79031);let d=class SqlResultTabsService{constructor(e,t,s,i){this.sqlQueryService=e,this.sqlQueryResultService=t,this.sqlExecutionPlanService=s,this.sqlOutputLogsService=i,(0,r.Gn)(this,{removeResultTabs:r.XI})}getResultTabs(e){return e.resultTabs}async canCloseResultTab(e,t){const s=e.tabs.find((e=>e.id===t));return!s||await this.sqlQueryResultService.canCloseResultTab(e,s.id)}selectResultTab(e,t){e.currentTabId=t}removeResultTab(e,t){const s=e.tabs.find((e=>e.id===t));s?this.removeTab(e,s):console.warn(`Unable to remove tab. Tab with id="${t}" was not found`)}async canCloseResultTabs(e){for(const t of e.tabs){if(!await this.sqlQueryResultService.canCloseResultTab(e,t.id))return!1}return!0}removeResultTabs(e,t){const s=e.tabs.slice();for(const i of s)t?.includes(i.id)||this.removeTab(e,i)}removeTab(e,t){e.tabs.splice(e.tabs.indexOf(t),1),this.sqlQueryService.removeStatisticsTab(e,t.id),this.sqlQueryResultService.removeResultTab(e,t.id),this.sqlExecutionPlanService.removeExecutionPlanTab(e,t.id),this.sqlOutputLogsService.removeOutputLogsTab(e,t.id),e.currentTabId===t.id&&(e.tabs.length>0?e.currentTabId=e.tabs[0].id:e.currentTabId="")}};d=(0,i.Cg)([(0,n._)(),(0,i.Sn)("design:paramtypes",[u.SqlQueryService,c.SqlQueryResultService,o.SqlExecutionPlanService,a.OutputLogsService])],d)},29297:(e,t,s)=>{s.r(t),s.d(t,{SqlScriptStatisticsPanel:()=>S});var i=s(41773),r=s(7838),n=s(17675),o=s(64928),a=s(14249),c=s(7167),u=s(69519),d=s(18699),l=s(72286),h=s(79031);const p={statistics:"statistics___xLnUn theme-typography--caption",query:"query___twjXA"},S=(0,r.PA)((function SqlScriptStatisticsPanel({tab:e}){const t=(0,d.h)(h.SqlQueryService),s=(0,d.h)(l.TableViewerStorageService),r=t.getStatistics(e.tabId),S=(0,n.W)(),g=(0,o.d)(p);if(!r)return(0,i.jsx)(a.x,{children:S("sql_editor_sql_statistics_unavailable")});const x=r.modelId?s.get(r.modelId)?.source:void 0;return(0,i.jsxs)("div",{className:(0,c.s)(g,{statistics:!0}),children:[S("sql_editor_sql_execution_executed_queries")," ",r.executedQueries," / ",r.queries,(0,i.jsx)("br",{}),S("data_viewer_statistics_duration")," ",r.executeTime," ms",(0,i.jsx)("br",{}),S("data_viewer_statistics_updated_rows")," ",r.updatedRows,(0,i.jsx)("br",{}),x&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(u.a,{message:"sql_editor_sql_execution_executing",cancelDisabled:!x.canCancel,inline:!0,onCancel:()=>x.cancel()}),(0,i.jsx)("pre",{className:(0,c.s)(g,{query:!0}),children:x.options?.query})]})]})}))},75525:(e,t,s)=>{s.d(t,{C:()=>i});const i=(0,s(19102).V)("sql-editor-execute",{icon:"/icons/sql_exec.svg",label:"sql_editor_sql_execution_button_tooltip"})},64756:(e,t,s)=>{s.d(t,{R:()=>i});const i=(0,s(19102).V)("sql-editor-execute-new",{icon:"/icons/sql_exec_new.svg",label:"sql_editor_sql_execution_new_tab_button_tooltip"})},98391:(e,t,s)=>{s.d(t,{_:()=>i});const i=(0,s(19102).V)("sql-editor-execute-script",{icon:"/icons/sql_script_exec.svg",label:"sql_editor_sql_execution_script_button_tooltip",tooltip:"sql_editor_sql_execution_script_button_tooltip"})},22247:(e,t,s)=>{s.d(t,{_:()=>i});const i=(0,s(19102).V)("sql-editor-format",{icon:"/icons/sql_exec.svg",label:"sql_editor_sql_execution_button_tooltip"})},95296:(e,t,s)=>{s.d(t,{T:()=>i});const i=(0,s(19102).V)("sql-editor-show-execution-plan",{icon:"/icons/sql_execution_plan.svg",label:"sql_editor_execution_plan_button_tooltip"})},23653:(e,t,s)=>{s.d(t,{M:()=>i});const i=(0,s(19102).V)("sql-editor-show-output",{icon:"/icons/sql_output.svg",label:"sql_editor_output_logs_button_tooltip"})},47291:(e,t,s)=>{s.d(t,{$:()=>i});const i=(0,s(45215).X)({id:"sql-editor-execute",keys:"ctrl+enter",preventDefault:!0})},18174:(e,t,s)=>{s.d(t,{q:()=>i});const i=(0,s(45215).X)({id:"sql-editor-execute-new",keys:["ctrl+\\","shift+ctrl+enter"],preventDefault:!0})},65457:(e,t,s)=>{s.d(t,{d:()=>i});const i=(0,s(45215).X)({id:"sql-editor-execute-script",keys:"alt+x",preventDefault:!0})},27145:(e,t,s)=>{s.d(t,{p:()=>i});const i=(0,s(45215).X)({id:"sql-editor-format",keys:"shift+ctrl+f",preventDefault:!0})},94798:(e,t,s)=>{s.d(t,{Q:()=>i});const i=(0,s(45215).X)({id:"sql-editor-show-execution-plan",keys:"shift+ctrl+e",preventDefault:!0})},1302:(e,t,s)=>{function getSqlEditorName(e,t,s){if(t?.name)return t.name;let i=`sql-${e.order}`;return s&&(i+=` (${s.name})`),i}s.d(t,{l:()=>getSqlEditorName})}}]);