@altipla/directus-extension-call-go
Version:
Directus extension to call a Go function inside an internal app directly from a flow.
2 lines (1 loc) • 37.2 kB
JavaScript
import{defineOperationApp as t,useApi as e,defineInterface as s}from"@directus/extensions-sdk";import{isRef as i,unref as r,hasInjectionContext as n,inject as a,ref as u,computed as o,reactive as c,watch as h,onScopeDispose as l,toRefs as d,readonly as f,getCurrentInstance as p,defineComponent as y,nextTick as m,resolveComponent as v,openBlock as g,createElementBlock as b,Fragment as O,createVNode as C,createBlock as Q,withCtx as w,createTextVNode as R,toDisplayString as S,createCommentVNode as q,createElementVNode as F}from"vue";var P=t({id:"call-go",name:"Go Function Call",icon:"function",description:"Call a Go function running inside an internal app.",overview:({fnname:t,server:e})=>[{label:"Function Name",text:t},{label:"Server",text:e}],options:[{field:"fnname",name:"Function Name",type:"string",meta:{width:"full",interface:"call-go-select-function"}},{field:"server",name:"Server",type:"string",meta:{hidden:!0}},{field:"payload",name:"Payload",type:"json",meta:{width:"full",interface:"input-code",options:{language:"json"}},schema:{default_value:"{}"}}]}),D=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.add(t),this.onSubscribe(),()=>{this.listeners.delete(t),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},E="undefined"==typeof window||"Deno"in globalThis;function I(){}function A(t){return"number"==typeof t&&t>=0&&t!==1/0}function T(t,e){return Math.max(t+(e||0)-Date.now(),0)}function x(t,e){return"function"==typeof t?t(e):t}function M(t,e){return"function"==typeof t?t(e):t}function U(t,e){const{type:s="all",exact:i,fetchStatus:r,predicate:n,queryKey:a,stale:u}=t;if(a)if(i){if(e.queryHash!==K(a,e.options))return!1}else if(!L(e.queryKey,a))return!1;if("all"!==s){const t=e.isActive();if("active"===s&&!t)return!1;if("inactive"===s&&t)return!1}return("boolean"!=typeof u||e.isStale()===u)&&((!r||r===e.state.fetchStatus)&&!(n&&!n(e)))}function j(t,e){const{exact:s,status:i,predicate:r,mutationKey:n}=t;if(n){if(!e.options.mutationKey)return!1;if(s){if(k(e.options.mutationKey)!==k(n))return!1}else if(!L(e.options.mutationKey,n))return!1}return(!i||e.state.status===i)&&!(r&&!r(e))}function K(t,e){return(e?.queryKeyHashFn||k)(t)}function k(t){return JSON.stringify(t,((t,e)=>$(e)?Object.keys(e).sort().reduce(((t,s)=>(t[s]=e[s],t)),{}):e))}function L(t,e){return t===e||typeof t==typeof e&&(!(!t||!e||"object"!=typeof t||"object"!=typeof e)&&!Object.keys(e).some((s=>!L(t[s],e[s]))))}function G(t,e){if(t===e)return t;const s=H(t)&&H(e);if(s||$(t)&&$(e)){const i=s?t:Object.keys(t),r=i.length,n=s?e:Object.keys(e),a=n.length,u=s?[]:{};let o=0;for(let r=0;r<a;r++){const a=s?r:n[r];(!s&&i.includes(a)||s)&&void 0===t[a]&&void 0===e[a]?(u[a]=void 0,o++):(u[a]=G(t[a],e[a]),u[a]===t[a]&&void 0!==t[a]&&o++)}return r===a&&o===r?t:u}return e}function _(t,e){if(!e||Object.keys(t).length!==Object.keys(e).length)return!1;for(const s in t)if(t[s]!==e[s])return!1;return!0}function H(t){return Array.isArray(t)&&t.length===Object.keys(t).length}function $(t){if(!N(t))return!1;const e=t.constructor;if(void 0===e)return!0;const s=e.prototype;return!!N(s)&&(!!s.hasOwnProperty("isPrototypeOf")&&Object.getPrototypeOf(t)===Object.prototype)}function N(t){return"[object Object]"===Object.prototype.toString.call(t)}function V(t,e,s){return"function"==typeof s.structuralSharing?s.structuralSharing(t,e):!1!==s.structuralSharing?G(t,e):e}function B(t,e,s=0){const i=[...t,e];return s&&i.length>s?i.slice(1):i}function W(t,e,s=0){const i=[e,...t];return s&&i.length>s?i.slice(0,-1):i}var z=Symbol(),J=(t,e)=>!t.queryFn&&e?.initialPromise?()=>e.initialPromise:t.queryFn&&t.queryFn!==z?t.queryFn:()=>Promise.reject(new Error(`Missing queryFn: '${t.queryHash}'`)),Y=new class extends D{#t;#e;#s;constructor(){super(),this.#s=t=>{if(!E&&window.addEventListener){const e=()=>t();return window.addEventListener("visibilitychange",e,!1),()=>{window.removeEventListener("visibilitychange",e)}}}}onSubscribe(){this.#e||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(t){this.#s=t,this.#e?.(),this.#e=t((t=>{"boolean"==typeof t?this.setFocused(t):this.onFocus()}))}setFocused(t){this.#t!==t&&(this.#t=t,this.onFocus())}onFocus(){const t=this.isFocused();this.listeners.forEach((e=>{e(t)}))}isFocused(){return"boolean"==typeof this.#t?this.#t:"hidden"!==globalThis.document?.visibilityState}},X=new class extends D{#i=!0;#e;#s;constructor(){super(),this.#s=t=>{if(!E&&window.addEventListener){const e=()=>t(!0),s=()=>t(!1);return window.addEventListener("online",e,!1),window.addEventListener("offline",s,!1),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",s)}}}}onSubscribe(){this.#e||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(t){this.#s=t,this.#e?.(),this.#e=t(this.setOnline.bind(this))}setOnline(t){this.#i!==t&&(this.#i=t,this.listeners.forEach((e=>{e(t)})))}isOnline(){return this.#i}};function Z(t){return Math.min(1e3*2**t,3e4)}function tt(t){return"online"!==(t??"online")||X.isOnline()}var et=class{constructor(t){this.revert=t?.revert,this.silent=t?.silent}};function st(t){return t instanceof et}function it(t){let e,s,i,r=!1,n=0,a=!1;const u=new Promise(((t,e)=>{s=t,i=e})),o=()=>Y.isFocused()&&("always"===t.networkMode||X.isOnline())&&t.canRun(),c=()=>tt(t.networkMode)&&t.canRun(),h=i=>{a||(a=!0,t.onSuccess?.(i),e?.(),s(i))},l=s=>{a||(a=!0,t.onError?.(s),e?.(),i(s))},d=()=>new Promise((s=>{e=t=>{(a||o())&&s(t)},t.onPause?.()})).then((()=>{e=void 0,a||t.onContinue?.()})),f=()=>{if(a)return;let e;const s=0===n?t.initialPromise:void 0;try{e=s??t.fn()}catch(t){e=Promise.reject(t)}Promise.resolve(e).then(h).catch((e=>{if(a)return;const s=t.retry??(E?0:3),i=t.retryDelay??Z,u="function"==typeof i?i(n,e):i,c=!0===s||"number"==typeof s&&n<s||"function"==typeof s&&s(n,e);var h;!r&&c?(n++,t.onFail?.(n,e),(h=u,new Promise((t=>{setTimeout(t,h)}))).then((()=>o()?void 0:d())).then((()=>{r?l(e):f()}))):l(e)}))};return{promise:u,cancel:e=>{a||(l(new et(e)),t.abort?.())},continue:()=>(e?.(),u),cancelRetry:()=>{r=!0},continueRetry:()=>{r=!1},canStart:c,start:()=>(c()?f():d().then(f),u)}}var rt=function(){let t=[],e=0,s=t=>{t()},i=t=>{t()},r=t=>setTimeout(t,0);const n=i=>{e?t.push(i):r((()=>{s(i)}))},a=()=>{const e=t;t=[],e.length&&r((()=>{i((()=>{e.forEach((t=>{s(t)}))}))}))};return{batch:t=>{let s;e++;try{s=t()}finally{e--,e||a()}return s},batchCalls:t=>(...e)=>{n((()=>{t(...e)}))},schedule:n,setNotifyFunction:t=>{s=t},setBatchNotifyFunction:t=>{i=t},setScheduler:t=>{r=t}}}(),nt=class{#r;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),A(this.gcTime)&&(this.#r=setTimeout((()=>{this.optionalRemove()}),this.gcTime))}updateGcTime(t){this.gcTime=Math.max(this.gcTime||0,t??(E?1/0:3e5))}clearGcTimeout(){this.#r&&(clearTimeout(this.#r),this.#r=void 0)}},at=class extends nt{#n;#a;#u;#o;#c;#h;constructor(t){super(),this.#h=!1,this.#c=t.defaultOptions,this.setOptions(t.options),this.observers=[],this.#u=t.cache,this.queryKey=t.queryKey,this.queryHash=t.queryHash,this.#n=t.state||function(t){const e="function"==typeof t.initialData?t.initialData():t.initialData,s=void 0!==e,i=s?"function"==typeof t.initialDataUpdatedAt?t.initialDataUpdatedAt():t.initialDataUpdatedAt:0;return{data:e,dataUpdateCount:0,dataUpdatedAt:s?i??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:s?"success":"pending",fetchStatus:"idle"}}(this.options),this.state=this.#n,this.scheduleGc()}get meta(){return this.options.meta}get promise(){return this.#o?.promise}setOptions(t){this.options={...this.#c,...t},this.updateGcTime(this.options.gcTime)}optionalRemove(){this.observers.length||"idle"!==this.state.fetchStatus||this.#u.remove(this)}setData(t,e){const s=V(this.state.data,t,this.options);return this.#l({data:s,type:"success",dataUpdatedAt:e?.updatedAt,manual:e?.manual}),s}setState(t,e){this.#l({type:"setState",state:t,setStateOptions:e})}cancel(t){const e=this.#o?.promise;return this.#o?.cancel(t),e?e.then(I).catch(I):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#n)}isActive(){return this.observers.some((t=>!1!==M(t.options.enabled,this)))}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return!!this.state.isInvalidated||(this.getObserversCount()>0?this.observers.some((t=>t.getCurrentResult().isStale)):void 0===this.state.data)}isStaleByTime(t=0){return this.state.isInvalidated||void 0===this.state.data||!T(this.state.dataUpdatedAt,t)}onFocus(){const t=this.observers.find((t=>t.shouldFetchOnWindowFocus()));t?.refetch({cancelRefetch:!1}),this.#o?.continue()}onOnline(){const t=this.observers.find((t=>t.shouldFetchOnReconnect()));t?.refetch({cancelRefetch:!1}),this.#o?.continue()}addObserver(t){this.observers.includes(t)||(this.observers.push(t),this.clearGcTimeout(),this.#u.notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.observers.includes(t)&&(this.observers=this.observers.filter((e=>e!==t)),this.observers.length||(this.#o&&(this.#h?this.#o.cancel({revert:!0}):this.#o.cancelRetry()),this.scheduleGc()),this.#u.notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#l({type:"invalidate"})}fetch(t,e){if("idle"!==this.state.fetchStatus)if(void 0!==this.state.data&&e?.cancelRefetch)this.cancel({silent:!0});else if(this.#o)return this.#o.continueRetry(),this.#o.promise;if(t&&this.setOptions(t),!this.options.queryFn){const t=this.observers.find((t=>t.options.queryFn));t&&this.setOptions(t.options)}const s=new AbortController,i=t=>{Object.defineProperty(t,"signal",{enumerable:!0,get:()=>(this.#h=!0,s.signal)})},r={fetchOptions:e,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:()=>{const t=J(this.options,e),s={queryKey:this.queryKey,meta:this.meta};return i(s),this.#h=!1,this.options.persister?this.options.persister(t,s,this):t(s)}};i(r),this.options.behavior?.onFetch(r,this),this.#a=this.state,"idle"!==this.state.fetchStatus&&this.state.fetchMeta===r.fetchOptions?.meta||this.#l({type:"fetch",meta:r.fetchOptions?.meta});const n=t=>{st(t)&&t.silent||this.#l({type:"error",error:t}),st(t)||(this.#u.config.onError?.(t,this),this.#u.config.onSettled?.(this.state.data,t,this)),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1};return this.#o=it({initialPromise:e?.initialPromise,fn:r.fetchFn,abort:s.abort.bind(s),onSuccess:t=>{void 0!==t?(this.setData(t),this.#u.config.onSuccess?.(t,this),this.#u.config.onSettled?.(t,this.state.error,this),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1):n(new Error(`${this.queryHash} data is undefined`))},onError:n,onFail:(t,e)=>{this.#l({type:"failed",failureCount:t,error:e})},onPause:()=>{this.#l({type:"pause"})},onContinue:()=>{this.#l({type:"continue"})},retry:r.options.retry,retryDelay:r.options.retryDelay,networkMode:r.options.networkMode,canRun:()=>!0}),this.#o.start()}#l(t){this.state=(e=>{switch(t.type){case"failed":return{...e,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...e,fetchStatus:"paused"};case"continue":return{...e,fetchStatus:"fetching"};case"fetch":return{...e,...ut(e.data,this.options),fetchMeta:t.meta??null};case"success":return{...e,data:t.data,dataUpdateCount:e.dataUpdateCount+1,dataUpdatedAt:t.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const s=t.error;return st(s)&&s.revert&&this.#a?{...this.#a,fetchStatus:"idle"}:{...e,error:s,errorUpdateCount:e.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:e.fetchFailureCount+1,fetchFailureReason:s,fetchStatus:"idle",status:"error"};case"invalidate":return{...e,isInvalidated:!0};case"setState":return{...e,...t.state}}})(this.state),rt.batch((()=>{this.observers.forEach((t=>{t.onQueryUpdate()})),this.#u.notify({query:this,type:"updated",action:t})}))}};function ut(t,e){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:tt(e.networkMode)?"fetching":"paused",...void 0===t&&{error:null,status:"pending"}}}var ot=class extends D{constructor(t={}){super(),this.config=t,this.#d=new Map}#d;build(t,e,s){const i=e.queryKey,r=e.queryHash??K(i,e);let n=this.get(r);return n||(n=new at({cache:this,queryKey:i,queryHash:r,options:t.defaultQueryOptions(e),state:s,defaultOptions:t.getQueryDefaults(i)}),this.add(n)),n}add(t){this.#d.has(t.queryHash)||(this.#d.set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const e=this.#d.get(t.queryHash);e&&(t.destroy(),e===t&&this.#d.delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){rt.batch((()=>{this.getAll().forEach((t=>{this.remove(t)}))}))}get(t){return this.#d.get(t)}getAll(){return[...this.#d.values()]}find(t){const e={exact:!0,...t};return this.getAll().find((t=>U(e,t)))}findAll(t={}){const e=this.getAll();return Object.keys(t).length>0?e.filter((e=>U(t,e))):e}notify(t){rt.batch((()=>{this.listeners.forEach((e=>{e(t)}))}))}onFocus(){rt.batch((()=>{this.getAll().forEach((t=>{t.onFocus()}))}))}onOnline(){rt.batch((()=>{this.getAll().forEach((t=>{t.onOnline()}))}))}},ct=class extends nt{#f;#p;#o;constructor(t){super(),this.mutationId=t.mutationId,this.#p=t.mutationCache,this.#f=[],this.state=t.state||{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0},this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){this.#f.includes(t)||(this.#f.push(t),this.clearGcTimeout(),this.#p.notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){this.#f=this.#f.filter((e=>e!==t)),this.scheduleGc(),this.#p.notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){this.#f.length||("pending"===this.state.status?this.scheduleGc():this.#p.remove(this))}continue(){return this.#o?.continue()??this.execute(this.state.variables)}async execute(t){this.#o=it({fn:()=>this.options.mutationFn?this.options.mutationFn(t):Promise.reject(new Error("No mutationFn found")),onFail:(t,e)=>{this.#l({type:"failed",failureCount:t,error:e})},onPause:()=>{this.#l({type:"pause"})},onContinue:()=>{this.#l({type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#p.canRun(this)});const e="pending"===this.state.status,s=!this.#o.canStart();try{if(!e){this.#l({type:"pending",variables:t,isPaused:s}),await(this.#p.config.onMutate?.(t,this));const e=await(this.options.onMutate?.(t));e!==this.state.context&&this.#l({type:"pending",context:e,variables:t,isPaused:s})}const i=await this.#o.start();return await(this.#p.config.onSuccess?.(i,t,this.state.context,this)),await(this.options.onSuccess?.(i,t,this.state.context)),await(this.#p.config.onSettled?.(i,null,this.state.variables,this.state.context,this)),await(this.options.onSettled?.(i,null,t,this.state.context)),this.#l({type:"success",data:i}),i}catch(e){try{throw await(this.#p.config.onError?.(e,t,this.state.context,this)),await(this.options.onError?.(e,t,this.state.context)),await(this.#p.config.onSettled?.(void 0,e,this.state.variables,this.state.context,this)),await(this.options.onSettled?.(void 0,e,t,this.state.context)),e}finally{this.#l({type:"error",error:e})}}finally{this.#p.runNext(this)}}#l(t){this.state=(e=>{switch(t.type){case"failed":return{...e,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...e,isPaused:!0};case"continue":return{...e,isPaused:!1};case"pending":return{...e,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...e,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...e,data:void 0,error:t.error,failureCount:e.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}})(this.state),rt.batch((()=>{this.#f.forEach((e=>{e.onMutationUpdate(t)})),this.#p.notify({mutation:this,type:"updated",action:t})}))}};var ht=class extends D{constructor(t={}){super(),this.config=t,this.#y=new Map,this.#m=Date.now()}#y;#m;build(t,e,s){const i=new ct({mutationCache:this,mutationId:++this.#m,options:t.defaultMutationOptions(e),state:s});return this.add(i),i}add(t){const e=lt(t),s=this.#y.get(e)??[];s.push(t),this.#y.set(e,s),this.notify({type:"added",mutation:t})}remove(t){const e=lt(t);if(this.#y.has(e)){const s=this.#y.get(e)?.filter((e=>e!==t));s&&(0===s.length?this.#y.delete(e):this.#y.set(e,s))}this.notify({type:"removed",mutation:t})}canRun(t){const e=this.#y.get(lt(t))?.find((t=>"pending"===t.state.status));return!e||e===t}runNext(t){const e=this.#y.get(lt(t))?.find((e=>e!==t&&e.state.isPaused));return e?.continue()??Promise.resolve()}clear(){rt.batch((()=>{this.getAll().forEach((t=>{this.remove(t)}))}))}getAll(){return[...this.#y.values()].flat()}find(t){const e={exact:!0,...t};return this.getAll().find((t=>j(e,t)))}findAll(t={}){return this.getAll().filter((e=>j(t,e)))}notify(t){rt.batch((()=>{this.listeners.forEach((e=>{e(t)}))}))}resumePausedMutations(){const t=this.getAll().filter((t=>t.state.isPaused));return rt.batch((()=>Promise.all(t.map((t=>t.continue().catch(I))))))}};function lt(t){return t.options.scope?.id??String(t.mutationId)}function dt(t){return{onFetch:(e,s)=>{const i=async()=>{const s=e.options,i=e.fetchOptions?.meta?.fetchMore?.direction,r=e.state.data?.pages||[],n=e.state.data?.pageParams||[],a={pages:[],pageParams:[]};let u=!1;const o=J(e.options,e.fetchOptions),c=async(t,s,i)=>{if(u)return Promise.reject();if(null==s&&t.pages.length)return Promise.resolve(t);const r={queryKey:e.queryKey,pageParam:s,direction:i?"backward":"forward",meta:e.options.meta};var n;n=r,Object.defineProperty(n,"signal",{enumerable:!0,get:()=>(e.signal.aborted?u=!0:e.signal.addEventListener("abort",(()=>{u=!0})),e.signal)});const a=await o(r),{maxPages:c}=e.options,h=i?W:B;return{pages:h(t.pages,a,c),pageParams:h(t.pageParams,s,c)}};let h;if(i&&r.length){const t="backward"===i,e={pages:r,pageParams:n},a=(t?pt:ft)(s,e);h=await c(e,a,t)}else{h=await c(a,n[0]??s.initialPageParam);const e=t??r.length;for(let t=1;t<e;t++){const t=ft(s,h);h=await c(h,t)}}return h};e.options.persister?e.fetchFn=()=>e.options.persister?.(i,{queryKey:e.queryKey,meta:e.options.meta,signal:e.signal},s):e.fetchFn=i}}}function ft(t,{pages:e,pageParams:s}){const i=e.length-1;return t.getNextPageParam(e[i],e,s[i],s)}function pt(t,{pages:e,pageParams:s}){return t.getPreviousPageParam?.(e[0],e,s[0],s)}var yt=class{#v;#p;#c;#g;#b;#O;#C;#Q;constructor(t={}){this.#v=t.queryCache||new ot,this.#p=t.mutationCache||new ht,this.#c=t.defaultOptions||{},this.#g=new Map,this.#b=new Map,this.#O=0}mount(){this.#O++,1===this.#O&&(this.#C=Y.subscribe((async t=>{t&&(await this.resumePausedMutations(),this.#v.onFocus())})),this.#Q=X.subscribe((async t=>{t&&(await this.resumePausedMutations(),this.#v.onOnline())})))}unmount(){this.#O--,0===this.#O&&(this.#C?.(),this.#C=void 0,this.#Q?.(),this.#Q=void 0)}isFetching(t){return this.#v.findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return this.#p.findAll({...t,status:"pending"}).length}getQueryData(t){const e=this.defaultQueryOptions({queryKey:t});return this.#v.get(e.queryHash)?.state.data}ensureQueryData(t){const e=this.getQueryData(t.queryKey);if(void 0===e)return this.fetchQuery(t);{const s=this.defaultQueryOptions(t),i=this.#v.build(this,s);return t.revalidateIfStale&&i.isStaleByTime(x(s.staleTime,i))&&this.prefetchQuery(s),Promise.resolve(e)}}getQueriesData(t){return this.#v.findAll(t).map((({queryKey:t,state:e})=>[t,e.data]))}setQueryData(t,e,s){const i=this.defaultQueryOptions({queryKey:t}),r=this.#v.get(i.queryHash),n=r?.state.data,a=function(t,e){return"function"==typeof t?t(e):t}(e,n);if(void 0!==a)return this.#v.build(this,i).setData(a,{...s,manual:!0})}setQueriesData(t,e,s){return rt.batch((()=>this.#v.findAll(t).map((({queryKey:t})=>[t,this.setQueryData(t,e,s)]))))}getQueryState(t){const e=this.defaultQueryOptions({queryKey:t});return this.#v.get(e.queryHash)?.state}removeQueries(t){const e=this.#v;rt.batch((()=>{e.findAll(t).forEach((t=>{e.remove(t)}))}))}resetQueries(t,e){const s=this.#v,i={type:"active",...t};return rt.batch((()=>(s.findAll(t).forEach((t=>{t.reset()})),this.refetchQueries(i,e))))}cancelQueries(t={},e={}){const s={revert:!0,...e},i=rt.batch((()=>this.#v.findAll(t).map((t=>t.cancel(s)))));return Promise.all(i).then(I).catch(I)}invalidateQueries(t={},e={}){return rt.batch((()=>{if(this.#v.findAll(t).forEach((t=>{t.invalidate()})),"none"===t.refetchType)return Promise.resolve();const s={...t,type:t.refetchType??t.type??"active"};return this.refetchQueries(s,e)}))}refetchQueries(t={},e){const s={...e,cancelRefetch:e?.cancelRefetch??!0},i=rt.batch((()=>this.#v.findAll(t).filter((t=>!t.isDisabled())).map((t=>{let e=t.fetch(void 0,s);return s.throwOnError||(e=e.catch(I)),"paused"===t.state.fetchStatus?Promise.resolve():e}))));return Promise.all(i).then(I)}fetchQuery(t){const e=this.defaultQueryOptions(t);void 0===e.retry&&(e.retry=!1);const s=this.#v.build(this,e);return s.isStaleByTime(x(e.staleTime,s))?s.fetch(e):Promise.resolve(s.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(I).catch(I)}fetchInfiniteQuery(t){return t.behavior=dt(t.pages),this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(I).catch(I)}resumePausedMutations(){return X.isOnline()?this.#p.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#v}getMutationCache(){return this.#p}getDefaultOptions(){return this.#c}setDefaultOptions(t){this.#c=t}setQueryDefaults(t,e){this.#g.set(k(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#g.values()];let s={};return e.forEach((e=>{L(t,e.queryKey)&&(s={...s,...e.defaultOptions})})),s}setMutationDefaults(t,e){this.#b.set(k(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#b.values()];let s={};return e.forEach((e=>{L(t,e.mutationKey)&&(s={...s,...e.defaultOptions})})),s}defaultQueryOptions(t){if(t._defaulted)return t;const e={...this.#c.queries,...this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=K(e.queryKey,e)),void 0===e.refetchOnReconnect&&(e.refetchOnReconnect="always"!==e.networkMode),void 0===e.throwOnError&&(e.throwOnError=!!e.suspense),!e.networkMode&&e.persister&&(e.networkMode="offlineFirst"),!0!==e.enabled&&e.queryFn===z&&(e.enabled=!1),e}defaultMutationOptions(t){return t?._defaulted?t:{...this.#c.mutations,...t?.mutationKey&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){this.#v.clear(),this.#p.clear()}},mt=class extends D{constructor(t,e){super(),this.options=e,this.#w=t,this.#R=null,this.bindMethods(),this.setOptions(e)}#w;#S=void 0;#q=void 0;#F=void 0;#P;#D;#R;#E;#I;#A;#T;#x;#M;#U=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){1===this.listeners.size&&(this.#S.addObserver(this),vt(this.#S,this.options)?this.#j():this.updateResult(),this.#K())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return gt(this.#S,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return gt(this.#S,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#k(),this.#L(),this.#S.removeObserver(this)}setOptions(t,e){const s=this.options,i=this.#S;if(this.options=this.#w.defaultQueryOptions(t),void 0!==this.options.enabled&&"boolean"!=typeof this.options.enabled&&"function"!=typeof this.options.enabled&&"boolean"!=typeof M(this.options.enabled,this.#S))throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#G(),this.#S.setOptions(this.options),s._defaulted&&!_(this.options,s)&&this.#w.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#S,observer:this});const r=this.hasListeners();r&&bt(this.#S,i,this.options,s)&&this.#j(),this.updateResult(e),!r||this.#S===i&&M(this.options.enabled,this.#S)===M(s.enabled,this.#S)&&x(this.options.staleTime,this.#S)===x(s.staleTime,this.#S)||this.#_();const n=this.#H();!r||this.#S===i&&M(this.options.enabled,this.#S)===M(s.enabled,this.#S)&&n===this.#M||this.#$(n)}getOptimisticResult(t){const e=this.#w.getQueryCache().build(this.#w,t),s=this.createResult(e,t);return function(t,e){if(!_(t.getCurrentResult(),e))return!0;return!1}(this,s)&&(this.#F=s,this.#D=this.options,this.#P=this.#S.state),s}getCurrentResult(){return this.#F}trackResult(t,e){const s={};return Object.keys(t).forEach((i=>{Object.defineProperty(s,i,{configurable:!1,enumerable:!0,get:()=>(this.trackProp(i),e?.(i),t[i])})})),s}trackProp(t){this.#U.add(t)}getCurrentQuery(){return this.#S}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const e=this.#w.defaultQueryOptions(t),s=this.#w.getQueryCache().build(this.#w,e);return s.isFetchingOptimistic=!0,s.fetch().then((()=>this.createResult(s,e)))}fetch(t){return this.#j({...t,cancelRefetch:t.cancelRefetch??!0}).then((()=>(this.updateResult(),this.#F)))}#j(t){this.#G();let e=this.#S.fetch(this.options,t);return t?.throwOnError||(e=e.catch(I)),e}#_(){this.#k();const t=x(this.options.staleTime,this.#S);if(E||this.#F.isStale||!A(t))return;const e=T(this.#F.dataUpdatedAt,t)+1;this.#T=setTimeout((()=>{this.#F.isStale||this.updateResult()}),e)}#H(){return("function"==typeof this.options.refetchInterval?this.options.refetchInterval(this.#S):this.options.refetchInterval)??!1}#$(t){this.#L(),this.#M=t,!E&&!1!==M(this.options.enabled,this.#S)&&A(this.#M)&&0!==this.#M&&(this.#x=setInterval((()=>{(this.options.refetchIntervalInBackground||Y.isFocused())&&this.#j()}),this.#M))}#K(){this.#_(),this.#$(this.#H())}#k(){this.#T&&(clearTimeout(this.#T),this.#T=void 0)}#L(){this.#x&&(clearInterval(this.#x),this.#x=void 0)}createResult(t,e){const s=this.#S,i=this.options,r=this.#F,n=this.#P,a=this.#D,u=t!==s?t.state:this.#q,{state:o}=t;let c,h={...o},l=!1;if(e._optimisticResults){const r=this.hasListeners(),n=!r&&vt(t,e),a=r&&bt(t,s,e,i);(n||a)&&(h={...h,...ut(o.data,t.options)}),"isRestoring"===e._optimisticResults&&(h.fetchStatus="idle")}let{error:d,errorUpdatedAt:f,status:p}=h;if(e.select&&void 0!==h.data)if(r&&h.data===n?.data&&e.select===this.#E)c=this.#I;else try{this.#E=e.select,c=e.select(h.data),c=V(r?.data,c,e),this.#I=c,this.#R=null}catch(t){this.#R=t}else c=h.data;if(void 0!==e.placeholderData&&void 0===c&&"pending"===p){let t;if(r?.isPlaceholderData&&e.placeholderData===a?.placeholderData)t=r.data;else if(t="function"==typeof e.placeholderData?e.placeholderData(this.#A?.state.data,this.#A):e.placeholderData,e.select&&void 0!==t)try{t=e.select(t),this.#R=null}catch(t){this.#R=t}void 0!==t&&(p="success",c=V(r?.data,t,e),l=!0)}this.#R&&(d=this.#R,c=this.#I,f=Date.now(),p="error");const y="fetching"===h.fetchStatus,m="pending"===p,v="error"===p,g=m&&y,b=void 0!==c;return{status:p,fetchStatus:h.fetchStatus,isPending:m,isSuccess:"success"===p,isError:v,isInitialLoading:g,isLoading:g,data:c,dataUpdatedAt:h.dataUpdatedAt,error:d,errorUpdatedAt:f,failureCount:h.fetchFailureCount,failureReason:h.fetchFailureReason,errorUpdateCount:h.errorUpdateCount,isFetched:h.dataUpdateCount>0||h.errorUpdateCount>0,isFetchedAfterMount:h.dataUpdateCount>u.dataUpdateCount||h.errorUpdateCount>u.errorUpdateCount,isFetching:y,isRefetching:y&&!m,isLoadingError:v&&!b,isPaused:"paused"===h.fetchStatus,isPlaceholderData:l,isRefetchError:v&&b,isStale:Ot(t,e),refetch:this.refetch}}updateResult(t){const e=this.#F,s=this.createResult(this.#S,this.options);if(this.#P=this.#S.state,this.#D=this.options,void 0!==this.#P.data&&(this.#A=this.#S),_(s,e))return;this.#F=s;const i={};!1!==t?.listeners&&(()=>{if(!e)return!0;const{notifyOnChangeProps:t}=this.options,s="function"==typeof t?t():t;if("all"===s||!s&&!this.#U.size)return!0;const i=new Set(s??this.#U);return this.options.throwOnError&&i.add("error"),Object.keys(this.#F).some((t=>{const s=t;return this.#F[s]!==e[s]&&i.has(s)}))})()&&(i.listeners=!0),this.#N({...i,...t})}#G(){const t=this.#w.getQueryCache().build(this.#w,this.options);if(t===this.#S)return;const e=this.#S;this.#S=t,this.#q=t.state,this.hasListeners()&&(e?.removeObserver(this),t.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#K()}#N(t){rt.batch((()=>{t.listeners&&this.listeners.forEach((t=>{t(this.#F)})),this.#w.getQueryCache().notify({query:this.#S,type:"observerResultsUpdated"})}))}};function vt(t,e){return function(t,e){return!1!==M(e.enabled,t)&&void 0===t.state.data&&!("error"===t.state.status&&!1===e.retryOnMount)}(t,e)||void 0!==t.state.data&>(t,e,e.refetchOnMount)}function gt(t,e,s){if(!1!==M(e.enabled,t)){const i="function"==typeof s?s(t):s;return"always"===i||!1!==i&&Ot(t,e)}return!1}function bt(t,e,s,i){return(t!==e||!1===M(i.enabled,t))&&(!s.suspense||"error"!==t.state.status)&&Ot(t,s)}function Ot(t,e){return!1!==M(e.enabled,t)&&t.isStaleByTime(x(e.staleTime,t))}var Ct="VUE_QUERY_CLIENT";function Qt(t){return`${Ct}${t?`:${t}`:""}`}function wt(t,e){Object.keys(t).forEach((s=>{t[s]=e[s]}))}function Rt(t,e,s="",r=0){if(e){const n=e(t,s,r);if(void 0===n&&i(t))return n;if(void 0!==n)return n}if(Array.isArray(t))return t.map(((t,s)=>Rt(t,e,String(s),r+1)));if("object"==typeof t&&function(t){if("[object Object]"!==Object.prototype.toString.call(t))return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}(t)){const s=Object.entries(t).map((([t,s])=>[t,Rt(s,e,t,r+1)]));return Object.fromEntries(s)}return t}function St(t,e=!1){return Rt(t,((t,s,n)=>1===n&&"queryKey"===s?St(t,!0):e&&"function"==typeof t?St(t(),e):i(t)?St(r(t),e):void 0))}function qt(t,e){return"function"==typeof t?t(...e):!!t}var Ft=class extends ot{find(t){return super.find(St(t))}findAll(t={}){return super.findAll(St(t))}},Pt=class extends ht{find(t){return super.find(St(t))}findAll(t={}){return super.findAll(St(t))}},Dt=class extends yt{constructor(t={}){super({defaultOptions:t.defaultOptions,queryCache:t.queryCache||new Ft,mutationCache:t.mutationCache||new Pt}),this.isRestoring=u(!1)}isFetching(t={}){return super.isFetching(St(t))}isMutating(t={}){return super.isMutating(St(t))}getQueryData(t){return super.getQueryData(St(t))}ensureQueryData(t){return super.ensureQueryData(St(t))}getQueriesData(t){return super.getQueriesData(St(t))}setQueryData(t,e,s={}){return super.setQueryData(St(t),e,St(s))}setQueriesData(t,e,s={}){return super.setQueriesData(St(t),e,St(s))}getQueryState(t){return super.getQueryState(St(t))}removeQueries(t={}){return super.removeQueries(St(t))}resetQueries(t={},e={}){return super.resetQueries(St(t),St(e))}cancelQueries(t={},e={}){return super.cancelQueries(St(t),St(e))}invalidateQueries(t={},e={}){return new Promise((s=>{setTimeout((async()=>{await super.invalidateQueries(St(t),St(e)),s()}),0)}))}refetchQueries(t={},e={}){return super.refetchQueries(St(t),St(e))}fetchQuery(t){return super.fetchQuery(St(t))}prefetchQuery(t){return super.prefetchQuery(St(t))}fetchInfiniteQuery(t){return super.fetchInfiniteQuery(St(t))}prefetchInfiniteQuery(t){return super.prefetchInfiniteQuery(St(t))}setDefaultOptions(t){super.setDefaultOptions(St(t))}setQueryDefaults(t,e){super.setQueryDefaults(St(t),St(e))}getQueryDefaults(t){return super.getQueryDefaults(St(t))}setMutationDefaults(t,e){super.setMutationDefaults(St(t),St(e))}getMutationDefaults(t){return super.getMutationDefaults(St(t))}},Et={install:(t,e={})=>{const s=Qt(e.queryClientKey);let i;if("queryClient"in e&&e.queryClient)i=e.queryClient;else{const t="queryClientConfig"in e?e.queryClientConfig:void 0;i=new Dt(t)}E||i.mount();let r=()=>{};if(e.clientPersister){i.isRestoring.value=!0;const[t,s]=e.clientPersister(i);r=t,s.then((()=>{i.isRestoring.value=!1,e.clientPersisterOnSuccess?.(i)}))}const n=()=>{i.unmount(),r()};if(t.onUnmount)t.onUnmount(n);else{const e=t.unmount;t.unmount=function(){n(),e()}}t.provide(s,i)}};function It(t,e,s){const i=s||function(t=""){if(!n())throw new Error("vue-query hooks can only be used inside setup() function or functions that support injection context.");const e=Qt(t),s=a(e);if(!s)throw new Error("No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library.");return s}(),r=o((()=>{const t=St(e);"function"==typeof t.enabled&&(t.enabled=t.enabled());const s=i.defaultQueryOptions(t);return s._optimisticResults=i.isRestoring.value?"isRestoring":"optimistic",s})),u=new t(i,r.value),p=c(u.getCurrentResult());let y=()=>{};h(i.isRestoring,(t=>{t||(y(),y=u.subscribe((t=>{wt(p,t)})))}),{immediate:!0});const m=()=>{u.setOptions(r.value),wt(p,u.getCurrentResult())};h(r,m),l((()=>{y()}));h((()=>p.error),(t=>{if(p.isError&&!p.isFetching&&qt(r.value.throwOnError,[t,u.getCurrentQuery()]))throw t}));const v=d(f(p));for(const t in p)"function"==typeof p[t]&&(v[t]=p[t]);return v.suspense=()=>new Promise(((t,e)=>{let s=()=>{};const i=()=>{if(!1!==r.value.enabled){u.setOptions(r.value);const i=u.getOptimisticResult(r.value);i.isStale?(s(),u.fetchOptimistic(r.value).then(t,(s=>{qt(r.value.throwOnError,[s,u.getCurrentQuery()])?e(s):t(u.getCurrentResult())}))):(s(),t(i))}};i(),s=h(r,i)})),v.refetch=(...t)=>(m(),p.refetch(...t)),v}function At(t,e){return It(mt,t,e)}var Tt=function(){function t(t){return t}function e(t){return"string"==typeof t?t.toLowerCase():t}function s(i,r){var n="function"==typeof this&&!this.firstBy&&this,a=function(s,i){if(i="object"==typeof i?i:{direction:i},"function"!=typeof s){var r=s;s=function(t){return t[r]?t[r]:""}}if(1===s.length){var n=s,a=i.ignoreCase?e:t,u=i.cmp||function(t,e){return t<e?-1:t>e?1:0};s=function(t,e){return u(a(n(t)),a(n(e)))}}return i.direction in{"-1":"",desc:""}?function(t,e){return-s(t,e)}:s}(i,r),u=n?function(t,e){return n(t,e)||a(t,e)}:a;return u.thenBy=s,u}return s.firstBy=s,s}();const xt=F("br",null,null,-1);var Mt=y({__name:"SelectFunction",props:{value:{type:String,default:null}},emits:["input","setFieldValue"],setup(t,{emit:s}){!function(){let t=window;t.$$pluginVueQuery||(p()?.appContext.app.use(Et),t.$$pluginVueQuery=!0)}();let n=t,c=s,l=a("values"),d=u(n.value?`${l.value.server}||${n.value}`:null);h(d,(()=>{if(d.value){let t=d.value.split("||");c("input",t[1]),m((()=>c("setFieldValue",{field:"server",value:t[0]})))}else c("input",null),m((()=>c("setFieldValue",{field:"server",value:null})))}));let f=e(),{data:y,isLoading:F,isError:P,error:D}=At({queryKey:["servers"],queryFn:async()=>(await f.get("/call-go/servers")).data}),{data:E,isLoading:I,isError:A,error:T}=At({queryKey:["functions",y.value?.join(",")],enabled:o((()=>!!y.value?.length)),retry:3,queryFn:async()=>{let t=(await Promise.all(y.value.map((async t=>{try{return(await f.get(`/call-go/functions?server=${t.alias}`)).data.map((e=>({text:y.value.length>1?`${t.alias} / ${e}`:e,value:`${t.alias}||${e}`})))}catch(e){let s=new Error(`Cannot load functions from server ${t.alias}`);throw s.cause=e,s}})))).flat();return t.sort(Tt.firstBy("text")),t}}),x=o((()=>F.value||I.value)),M=o((()=>P.value||A.value)),U=o((()=>D.value||T.value));return(t,e)=>{const s=v("VSelect"),n=v("VNotice");return g(),b(O,null,[C(s,{modelValue:r(d),"onUpdate:modelValue":e[0]||(e[0]=t=>i(d)?d.value=t:d=t),items:r(E)??[],placeholder:"Function Name",search:"",disabled:r(x)||r(M)},null,8,["modelValue","items","disabled"]),r(M)?(g(),Q(n,{key:0,type:"danger",class:"notice"},{default:w((()=>[R(S(r(U)),1),xt,R(" "+S(r(U)?.cause),1)])),_:1})):q("v-if",!0)],64)}}}),Ut=[],jt=[];!function(t,e){if(t&&"undefined"!=typeof document){var s,i=!0===e.prepend?"prepend":"append",r=!0===e.singleTag,n="string"==typeof e.container?document.querySelector(e.container):document.getElementsByTagName("head")[0];if(r){var a=Ut.indexOf(n);-1===a&&(a=Ut.push(n)-1,jt[a]={}),s=jt[a]&&jt[a][i]?jt[a][i]:jt[a][i]=u()}else s=u();65279===t.charCodeAt(0)&&(t=t.substring(1)),s.styleSheet?s.styleSheet.cssText+=t:s.appendChild(document.createTextNode(t))}function u(){var t=document.createElement("style");if(t.setAttribute("type","text/css"),e.attributes)for(var s=Object.keys(e.attributes),r=0;r<s.length;r++)t.setAttribute(s[r],e.attributes[s[r]]);var a="prepend"===i?"afterbegin":"beforeend";return n.insertAdjacentElement(a,t),t}}("\n.notice {\n\tmargin-top: 16px;\n}\n",{});const Kt=[s({id:"call-go-select-function",name:"Call Go Select Function",icon:"function",description:"Select a Call Go function.",component:((t,e)=>{const s=t.__vccOpts||t;for(const[t,i]of e)s[t]=i;return s})(Mt,[["__file","SelectFunction.vue"]]),options:null,types:["string"],system:!0})],kt=[],Lt=[],Gt=[],_t=[],Ht=[],$t=[P];export{kt as displays,Kt as interfaces,Lt as layouts,Gt as modules,$t as operations,_t as panels,Ht as themes};