mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 22:43:58 +00:00
apiCall POC
This commit is contained in:
@@ -197,7 +197,7 @@ module.exports = {
|
|||||||
async get({ conid }) {
|
async get({ conid }) {
|
||||||
if (portalConnections) return portalConnections.find(x => x._id == conid);
|
if (portalConnections) return portalConnections.find(x => x._id == conid);
|
||||||
const res = await this.datastore.find({ _id: conid });
|
const res = await this.datastore.find({ _id: conid });
|
||||||
return res[0];
|
return res[0] || null;
|
||||||
},
|
},
|
||||||
|
|
||||||
newSqliteDatabase_meta: true,
|
newSqliteDatabase_meta: true,
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ module.exports = {
|
|||||||
serverVersion_meta: true,
|
serverVersion_meta: true,
|
||||||
async serverVersion({ conid, database }) {
|
async serverVersion({ conid, database }) {
|
||||||
const opened = await this.ensureOpened(conid, database);
|
const opened = await this.ensureOpened(conid, database);
|
||||||
return opened.serverVersion;
|
return opened.serverVersion || null;
|
||||||
},
|
},
|
||||||
|
|
||||||
sqlPreview_meta: true,
|
sqlPreview_meta: true,
|
||||||
@@ -276,7 +276,10 @@ module.exports = {
|
|||||||
generateDeploySql_meta: true,
|
generateDeploySql_meta: true,
|
||||||
async generateDeploySql({ conid, database, archiveFolder }) {
|
async generateDeploySql({ conid, database, archiveFolder }) {
|
||||||
const opened = await this.ensureOpened(conid, database);
|
const opened = await this.ensureOpened(conid, database);
|
||||||
const res = await this.sendRequest(opened, { msgtype: 'generateDeploySql', modelFolder: resolveArchiveFolder(archiveFolder) });
|
const res = await this.sendRequest(opened, {
|
||||||
|
msgtype: 'generateDeploySql',
|
||||||
|
modelFolder: resolveArchiveFolder(archiveFolder),
|
||||||
|
});
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
// const connection = await connections.get({ conid });
|
// const connection = await connections.get({ conid });
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
import { shouldWaitForElectronInitialize } from './utility/getElectron';
|
import { shouldWaitForElectronInitialize } from './utility/getElectron';
|
||||||
import { subscribeConnectionPingers } from './utility/connectionsPinger';
|
import { subscribeConnectionPingers } from './utility/connectionsPinger';
|
||||||
import { subscribePermissionCompiler } from './utility/hasPermission';
|
import { subscribePermissionCompiler } from './utility/hasPermission';
|
||||||
|
import { apiCall } from './utility/api';
|
||||||
|
|
||||||
let loadedApi = false;
|
let loadedApi = false;
|
||||||
|
|
||||||
@@ -27,10 +28,10 @@
|
|||||||
try {
|
try {
|
||||||
// console.log('************** LOADING API');
|
// console.log('************** LOADING API');
|
||||||
|
|
||||||
const settings = await axiosInstance().get('config/get-settings');
|
const settings = await apiCall('config/get-settings');
|
||||||
const connections = await axiosInstance().get('connections/list');
|
const connections = await apiCall('connections/list');
|
||||||
const config = await axiosInstance().get('config/get');
|
const config = await apiCall('config/get');
|
||||||
loadedApi = settings?.data && connections?.data && config?.data;
|
loadedApi = settings && connections && config;
|
||||||
|
|
||||||
if (loadedApi) {
|
if (loadedApi) {
|
||||||
subscribeApiDependendStores();
|
subscribeApiDependendStores();
|
||||||
|
|||||||
@@ -14,14 +14,10 @@
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
loadingPackageName: installed.name,
|
loadingPackageName: installed.name,
|
||||||
});
|
});
|
||||||
const resp = await axiosInstance().request({
|
const resp = await apiCall('plugins/script', {
|
||||||
method: 'get',
|
packageName: installed.name,
|
||||||
url: 'plugins/script',
|
|
||||||
params: {
|
|
||||||
packageName: installed.name,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const module = eval(`${resp.data}; plugin`);
|
const module = eval(`${resp}; plugin`);
|
||||||
console.log('Loaded plugin', module);
|
console.log('Loaded plugin', module);
|
||||||
const moduleContent = module.__esModule ? module.default : module;
|
const moduleContent = module.__esModule ? module.default : module;
|
||||||
if (moduleContent.initialize) moduleContent.initialize(dbgateEnv);
|
if (moduleContent.initialize) moduleContent.initialize(dbgateEnv);
|
||||||
@@ -55,7 +51,6 @@
|
|||||||
};
|
};
|
||||||
return extensions;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -66,6 +61,7 @@
|
|||||||
import { buildFileFormats, buildQuickExports } from './fileformats';
|
import { buildFileFormats, buildQuickExports } from './fileformats';
|
||||||
import { buildThemes } from './themes';
|
import { buildThemes } from './themes';
|
||||||
import dbgateTools from 'dbgate-tools';
|
import dbgateTools from 'dbgate-tools';
|
||||||
|
import { apiCall } from '../utility/api';
|
||||||
|
|
||||||
let pluginsDict = {};
|
let pluginsDict = {};
|
||||||
const installedPlugins = useInstalledPlugins();
|
const installedPlugins = useInstalledPlugins();
|
||||||
@@ -87,5 +83,4 @@
|
|||||||
.filter(x => x.content);
|
.filter(x => x.content);
|
||||||
|
|
||||||
$: $extensions = buildExtensions(plugins);
|
$: $extensions = buildExtensions(plugins);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
18
packages/web/src/utility/api.ts
Normal file
18
packages/web/src/utility/api.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import resolveApi, { resolveApiHeaders } from './resolveApi';
|
||||||
|
|
||||||
|
export async function apiCall(route: string, args: {} = undefined) {
|
||||||
|
const resp = await fetch(`${resolveApi()}/${route}`, {
|
||||||
|
method: 'POST',
|
||||||
|
cache: 'no-cache',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...resolveApiHeaders(),
|
||||||
|
},
|
||||||
|
body: JSON.stringify(args),
|
||||||
|
});
|
||||||
|
return resp.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function apiOn(event: string, hander: Function) {}
|
||||||
|
|
||||||
|
export function apiOff(event: string, hander: Function) {}
|
||||||
@@ -9,6 +9,7 @@ import { DatabaseInfo } from 'dbgate-types';
|
|||||||
import { derived } from 'svelte/store';
|
import { derived } from 'svelte/store';
|
||||||
import { extendDatabaseInfo } from 'dbgate-tools';
|
import { extendDatabaseInfo } from 'dbgate-tools';
|
||||||
import { setLocalStorage } from '../utility/storageCache';
|
import { setLocalStorage } from '../utility/storageCache';
|
||||||
|
import { apiCall } from './api';
|
||||||
|
|
||||||
const databaseInfoLoader = ({ conid, database }) => ({
|
const databaseInfoLoader = ({ conid, database }) => ({
|
||||||
url: 'database-connections/structure',
|
url: 'database-connections/structure',
|
||||||
@@ -143,12 +144,8 @@ async function getCore(loader, args) {
|
|||||||
const key = stableStringify({ url, ...params });
|
const key = stableStringify({ url, ...params });
|
||||||
|
|
||||||
async function doLoad() {
|
async function doLoad() {
|
||||||
const resp = await axiosInstance().request({
|
const resp = await apiCall(url, params);
|
||||||
method: 'get',
|
const res = (transform || (x => x))(resp);
|
||||||
url,
|
|
||||||
params,
|
|
||||||
});
|
|
||||||
const res = (transform || (x => x))(resp.data);
|
|
||||||
if (onLoaded) onLoaded(res);
|
if (onLoaded) onLoaded(res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -169,12 +166,8 @@ function useCore(loader, args) {
|
|||||||
subscribe: onChange => {
|
subscribe: onChange => {
|
||||||
async function handleReload() {
|
async function handleReload() {
|
||||||
async function doLoad() {
|
async function doLoad() {
|
||||||
const resp = await axiosInstance().request({
|
const resp = await apiCall(url, params);
|
||||||
method: 'get',
|
const res = (transform || (x => x))(resp);
|
||||||
params,
|
|
||||||
url,
|
|
||||||
});
|
|
||||||
const res = (transform || (x => x))(resp.data);
|
|
||||||
if (onLoaded) onLoaded(res);
|
if (onLoaded) onLoaded(res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -189,7 +182,7 @@ function useCore(loader, args) {
|
|||||||
cacheSet(cacheKey, res, reloadTrigger);
|
cacheSet(cacheKey, res, reloadTrigger);
|
||||||
onChange(res);
|
onChange(res);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error when using cached promise', err);
|
console.error(`Error when using cached promise ${url}`, err);
|
||||||
cacheClean(cacheKey);
|
cacheClean(cacheKey);
|
||||||
const res = await doLoad();
|
const res = await doLoad();
|
||||||
cacheSet(cacheKey, res, reloadTrigger);
|
cacheSet(cacheKey, res, reloadTrigger);
|
||||||
|
|||||||
Reference in New Issue
Block a user