@dataramen/cli 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/run.js +2 -169
- package/dist/code/cli.js +2 -169
- package/dist/package.json +20 -1
- package/package.json +7 -2
- package/dist/code/api/chat/router.js +0 -55
- package/dist/code/api/dataSources/router.js +0 -147
- package/dist/code/api/dataSources/types.js +0 -2
- package/dist/code/api/dataSources/validators.js +0 -22
- package/dist/code/api/project/router.js +0 -100
- package/dist/code/api/queries/router.js +0 -122
- package/dist/code/api/runner/router.js +0 -22
- package/dist/code/api/status/router.js +0 -17
- package/dist/code/api/teams/router.js +0 -35
- package/dist/code/api/userSettings/router.js +0 -54
- package/dist/code/api/users/router.js +0 -91
- package/dist/code/api/workbooks/router.js +0 -123
- package/dist/code/api/workbooks/types.js +0 -2
- package/dist/code/env.js +0 -25
- package/dist/code/index.js +0 -86
- package/dist/code/repository/db.js +0 -58
- package/dist/code/repository/tables/databaseInspection.js +0 -40
- package/dist/code/repository/tables/datasource.js +0 -86
- package/dist/code/repository/tables/query.js +0 -50
- package/dist/code/repository/tables/teams.js +0 -48
- package/dist/code/repository/tables/userSettings.js +0 -39
- package/dist/code/repository/tables/users.js +0 -42
- package/dist/code/repository/tables/workbook.js +0 -43
- package/dist/code/services/connectorManager/index.js +0 -38
- package/dist/code/services/connectorManager/types.js +0 -2
- package/dist/code/services/files/index.js +0 -44
- package/dist/code/services/mysqlConnector/index.js +0 -180
- package/dist/code/services/oauthClient/oauth2Client.js +0 -10
- package/dist/code/services/openai/index.js +0 -20
- package/dist/code/services/openai/types.js +0 -2
- package/dist/code/services/pgConnector/index.js +0 -220
- package/dist/code/services/userSqlPromptRunner/index.js +0 -207
- package/dist/code/types/connectors.js +0 -2
- package/dist/code/utils/createRouter.js +0 -10
- package/dist/code/utils/httpError.js +0 -13
- package/dist/code/utils/prompts.js +0 -11
- package/dist/code/utils/queryUtils.js +0 -18
- package/dist/code/utils/rawSql.js +0 -32
- package/dist/code/utils/request.js +0 -35
- package/dist/code/utils/token.js +0 -8
package/bin/run.js
CHANGED
|
@@ -1,169 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const path = require("node:path");
|
|
4
|
-
const yargs = require("yargs");
|
|
5
|
-
const yargsHelpers = require("yargs/helpers");
|
|
6
|
-
const os = require('node:os');
|
|
7
|
-
const fs = require("fs-extra");
|
|
8
|
-
|
|
9
|
-
const processName = "@dataramen/local-server";
|
|
10
|
-
|
|
11
|
-
const homeDir = os.homedir();
|
|
12
|
-
const filesPath = path.join(homeDir, ".dataramen", ".runtime", "server");
|
|
13
|
-
|
|
14
|
-
const scriptPkg = useJson(path.join(__dirname, "..", "package.json"));
|
|
15
|
-
const serverPkg = useJson(path.join(filesPath, "package.json"));
|
|
16
|
-
|
|
17
|
-
const protocol = "dataramen://";
|
|
18
|
-
|
|
19
|
-
yargs()
|
|
20
|
-
.command("start", 'Default command, start/restart the server', () => {
|
|
21
|
-
const hasPm2 = checkPm2();
|
|
22
|
-
if (!hasPm2) {
|
|
23
|
-
installPm2();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
start();
|
|
27
|
-
})
|
|
28
|
-
.command(["logs"], 'Listen for logs', () => {
|
|
29
|
-
execSync(`pm2 logs ${processName}`, {
|
|
30
|
-
stdio: "inherit",
|
|
31
|
-
});
|
|
32
|
-
})
|
|
33
|
-
.command("stop", 'Stop the server', () => {
|
|
34
|
-
execSync(`pm2 stop ${processName}`, {
|
|
35
|
-
stdio: "inherit",
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
.command("unregister", "Unregister custom protocol handler", () => {
|
|
39
|
-
if (os.platform() === "win32") {
|
|
40
|
-
require(path.join(__dirname, "..", "dist", "code", "register.windows.js")).unregister();
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
.command(["version"], 'Show version', () => {
|
|
44
|
-
console.log(`Data ramen CLI version: ${scriptPkg().version}`);
|
|
45
|
-
console.log(`Data ramen local server version: ${serverPkg().version}`);
|
|
46
|
-
})
|
|
47
|
-
.parse(isBrowserStart() ? getBrowserArgs() : yargsHelpers.hideBin(process.argv));
|
|
48
|
-
|
|
49
|
-
function shouldInstall () {
|
|
50
|
-
try {
|
|
51
|
-
const installedProxyPkjJson = serverPkg();
|
|
52
|
-
|
|
53
|
-
if (!installedProxyPkjJson) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const thisProxyPkgJson = fs.readJsonSync(path.join(__dirname, '..', 'dist', "package.json"));
|
|
58
|
-
return installedProxyPkjJson.version !== thisProxyPkgJson.version; // version are different, install new code
|
|
59
|
-
} catch (e) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function isBrowserStart () {
|
|
65
|
-
return !!process.argv[2]?.startsWith(protocol);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function getBrowserArgs () {
|
|
69
|
-
const str = (process.argv[2] || '').replace(protocol, ''); // remove protocol
|
|
70
|
-
console.log("Browser args", str.split("/"));
|
|
71
|
-
return str.split("/");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function checkPm2 () {
|
|
75
|
-
try {
|
|
76
|
-
execSync(`pm2 -v`, {
|
|
77
|
-
stdio: "inherit"
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return true;
|
|
81
|
-
} catch (e) {
|
|
82
|
-
console.error("Library does not exist");
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function installPm2 () {
|
|
88
|
-
console.log("Install Pm2");
|
|
89
|
-
execSync(`npm i -g pm2`, {
|
|
90
|
-
stdio: "inherit"
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function stopExisting () {
|
|
95
|
-
try {
|
|
96
|
-
execSync(`pm2 stop "${processName}"`);
|
|
97
|
-
} catch (e) {}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// function registerServer () {
|
|
101
|
-
// try {
|
|
102
|
-
// if (os.platform() === "win32") {
|
|
103
|
-
// require(path.join(__dirname, "..", "dist", "code", "register.windows.js")).register();
|
|
104
|
-
// }
|
|
105
|
-
//
|
|
106
|
-
// console.log("Custom protocol handler registered");
|
|
107
|
-
// } catch (e) {
|
|
108
|
-
// console.log("Failed to register server", e);
|
|
109
|
-
// }
|
|
110
|
-
// }
|
|
111
|
-
|
|
112
|
-
function installServer () {
|
|
113
|
-
console.log("Installing Server");
|
|
114
|
-
// copy code
|
|
115
|
-
fs.copySync(path.join(__dirname, '..', 'dist', "code"), path.join(filesPath, "code"));
|
|
116
|
-
// copy default env (do not override existing .env)
|
|
117
|
-
fs.copySync(path.join(__dirname, '..', 'dist', "env", ".env.default"), path.join(filesPath, "env", ".env.default"));
|
|
118
|
-
// copy package.json
|
|
119
|
-
fs.copySync(path.join(__dirname, '..', 'dist', "package.json"), path.join(filesPath, "package.json"));
|
|
120
|
-
|
|
121
|
-
execSync(`npm i`, {
|
|
122
|
-
stdio: "inherit",
|
|
123
|
-
cwd: filesPath,
|
|
124
|
-
});
|
|
125
|
-
console.log("Server installed");
|
|
126
|
-
|
|
127
|
-
// registerServer();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function start () {
|
|
131
|
-
stopExisting();
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
if (shouldInstall()) {
|
|
135
|
-
installServer();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
console.log("Starting local server");
|
|
139
|
-
const appPkg = fs.readJsonSync(path.join(filesPath, "package.json"));
|
|
140
|
-
execSync(`pm2 start "${appPkg.main}" --name "${processName}" --no-autorestart`, {
|
|
141
|
-
stdio: "inherit",
|
|
142
|
-
cwd: filesPath,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
console.log(`Local server will be available in a couple of seconds`);
|
|
146
|
-
console.log(`You can close this window`);
|
|
147
|
-
console.log(`Visit https://app.dataramen.xyz`);
|
|
148
|
-
} catch (e) {
|
|
149
|
-
console.error(`Failed to start local server`, e);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function useJson (path) {
|
|
154
|
-
let file = undefined;
|
|
155
|
-
|
|
156
|
-
function get () {
|
|
157
|
-
try {
|
|
158
|
-
if (!file) {
|
|
159
|
-
file = fs.readJsonSync(path);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return file;
|
|
163
|
-
} catch (e) {
|
|
164
|
-
return undefined;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return get;
|
|
169
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var C=Object.create;var u=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var T=(o,r,n,d)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of I(r))!L.call(o,a)&&a!==n&&u(o,a,{get:()=>r[a],enumerable:!(d=$(r,a))||d.enumerable});return o};var l=(o,r,n)=>(n=o!=null?C(J(o)):{},T(r||!o||!o.__esModule?u(n,"default",{value:o,enumerable:!0}):n,o));var O=l(require("yargs")),w=require("yargs/helpers");var v=require("node:os"),P=require("node:path"),D=(0,v.homedir)();var s="@dataramen/local-server",t=(0,P.join)(D,".dataramen",".runtime","server");var j=require("node:path"),A=l(require("fs-extra")),f=require("node:child_process");var h=l(require("fs-extra")),g=require("node:path");function S(o){let r;function n(){try{return r||(r=h.readJsonSync(o)),r}catch{return}}return n}var y=S((0,g.join)(__dirname,"..","package.json")),p=S((0,g.join)(t,"package.json"));var i=l(require("fs-extra")),e=require("node:path"),c=require("node:child_process");function x(){try{let o=p();if(!o)return!0;let r=i.readJsonSync((0,e.join)(__dirname,"..","dist","package.json"));return o.version!==r.version}catch{return!0}}function _(){try{return(0,c.execSync)("pm2 -v",{stdio:"inherit"}),!0}catch{return console.error("Library does not exist"),!1}}function E(){console.log("Install Pm2"),(0,c.execSync)("npm i -g pm2",{stdio:"inherit"})}function k(){try{(0,c.execSync)(`pm2 stop "${s}"`)}catch{}}function R(){console.log("Installing Server"),i.copySync((0,e.join)(__dirname,"..","dist","code"),(0,e.join)(t,"code")),i.copySync((0,e.join)(__dirname,"..","dist","env",".env.default"),(0,e.join)(t,"env",".env.default")),i.copySync((0,e.join)(__dirname,"..","dist","package.json"),(0,e.join)(t,"package.json")),(0,c.execSync)("npm i",{stdio:"inherit",cwd:t}),console.log("Server installed")}function H(){_()||E(),k();try{x()&&R(),console.log("Starting local server");let r=A.readJsonSync((0,j.join)(t,"package.json"));(0,f.execSync)(`pm2 start "${r.main}" --name "${s}" --no-autorestart`,{stdio:"inherit",cwd:t}),console.log("Local server will be available in a couple of seconds"),console.log("You can close this window"),console.log("Visit https://app.dataramen.xyz")}catch(r){console.error("Failed to start local server",r)}}function V(){(0,f.execSync)(`pm2 logs ${s}`,{stdio:"inherit"})}function b(){(0,f.execSync)(`pm2 stop ${s}`,{stdio:"inherit"})}function B(){console.log(`Data ramen CLI version: ${y().version}`),console.log(`Data ramen local server version: ${p().version}`)}var m={start:H,logs:V,stop:b,version:B};(0,O.default)((0,w.hideBin)(process.argv)).command("start","Default command, start/restart the server",m.start).command(["logs"],"Listen for logs",m.logs).command("stop","Stop the server",m.stop).command(["version"],"Show version",m.version).parse();
|
package/dist/code/cli.js
CHANGED
|
@@ -1,169 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const path = require("node:path");
|
|
4
|
-
const yargs = require("yargs");
|
|
5
|
-
const yargsHelpers = require("yargs/helpers");
|
|
6
|
-
const os = require('node:os');
|
|
7
|
-
const fs = require("fs-extra");
|
|
8
|
-
|
|
9
|
-
const processName = "@dataramen/local-server";
|
|
10
|
-
|
|
11
|
-
const homeDir = os.homedir();
|
|
12
|
-
const filesPath = path.join(homeDir, ".dataramen", ".runtime", "server");
|
|
13
|
-
|
|
14
|
-
const scriptPkg = useJson(path.join(__dirname, "..", "package.json"));
|
|
15
|
-
const serverPkg = useJson(path.join(filesPath, "package.json"));
|
|
16
|
-
|
|
17
|
-
const protocol = "dataramen://";
|
|
18
|
-
|
|
19
|
-
yargs()
|
|
20
|
-
.command("start", 'Default command, start/restart the server', () => {
|
|
21
|
-
const hasPm2 = checkPm2();
|
|
22
|
-
if (!hasPm2) {
|
|
23
|
-
installPm2();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
start();
|
|
27
|
-
})
|
|
28
|
-
.command(["logs"], 'Listen for logs', () => {
|
|
29
|
-
execSync(`pm2 logs ${processName}`, {
|
|
30
|
-
stdio: "inherit",
|
|
31
|
-
});
|
|
32
|
-
})
|
|
33
|
-
.command("stop", 'Stop the server', () => {
|
|
34
|
-
execSync(`pm2 stop ${processName}`, {
|
|
35
|
-
stdio: "inherit",
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
.command("unregister", "Unregister custom protocol handler", () => {
|
|
39
|
-
if (os.platform() === "win32") {
|
|
40
|
-
require(path.join(__dirname, "..", "dist", "code", "register.windows.js")).unregister();
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
.command(["version"], 'Show version', () => {
|
|
44
|
-
console.log(`Data ramen CLI version: ${scriptPkg().version}`);
|
|
45
|
-
console.log(`Data ramen local server version: ${serverPkg().version}`);
|
|
46
|
-
})
|
|
47
|
-
.parse(isBrowserStart() ? getBrowserArgs() : yargsHelpers.hideBin(process.argv));
|
|
48
|
-
|
|
49
|
-
function shouldInstall () {
|
|
50
|
-
try {
|
|
51
|
-
const installedProxyPkjJson = serverPkg();
|
|
52
|
-
|
|
53
|
-
if (!installedProxyPkjJson) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const thisProxyPkgJson = fs.readJsonSync(path.join(__dirname, '..', 'dist', "package.json"));
|
|
58
|
-
return installedProxyPkjJson.version !== thisProxyPkgJson.version; // version are different, install new code
|
|
59
|
-
} catch (e) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function isBrowserStart () {
|
|
65
|
-
return !!process.argv[2]?.startsWith(protocol);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function getBrowserArgs () {
|
|
69
|
-
const str = (process.argv[2] || '').replace(protocol, ''); // remove protocol
|
|
70
|
-
console.log("Browser args", str.split("/"));
|
|
71
|
-
return str.split("/");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function checkPm2 () {
|
|
75
|
-
try {
|
|
76
|
-
execSync(`pm2 -v`, {
|
|
77
|
-
stdio: "inherit"
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return true;
|
|
81
|
-
} catch (e) {
|
|
82
|
-
console.error("Library does not exist");
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function installPm2 () {
|
|
88
|
-
console.log("Install Pm2");
|
|
89
|
-
execSync(`npm i -g pm2`, {
|
|
90
|
-
stdio: "inherit"
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function stopExisting () {
|
|
95
|
-
try {
|
|
96
|
-
execSync(`pm2 stop "${processName}"`);
|
|
97
|
-
} catch (e) {}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// function registerServer () {
|
|
101
|
-
// try {
|
|
102
|
-
// if (os.platform() === "win32") {
|
|
103
|
-
// require(path.join(__dirname, "..", "dist", "code", "register.windows.js")).register();
|
|
104
|
-
// }
|
|
105
|
-
//
|
|
106
|
-
// console.log("Custom protocol handler registered");
|
|
107
|
-
// } catch (e) {
|
|
108
|
-
// console.log("Failed to register server", e);
|
|
109
|
-
// }
|
|
110
|
-
// }
|
|
111
|
-
|
|
112
|
-
function installServer () {
|
|
113
|
-
console.log("Installing Server");
|
|
114
|
-
// copy code
|
|
115
|
-
fs.copySync(path.join(__dirname, '..', 'dist', "code"), path.join(filesPath, "code"));
|
|
116
|
-
// copy default env (do not override existing .env)
|
|
117
|
-
fs.copySync(path.join(__dirname, '..', 'dist', "env", ".env.default"), path.join(filesPath, "env", ".env.default"));
|
|
118
|
-
// copy package.json
|
|
119
|
-
fs.copySync(path.join(__dirname, '..', 'dist', "package.json"), path.join(filesPath, "package.json"));
|
|
120
|
-
|
|
121
|
-
execSync(`npm i`, {
|
|
122
|
-
stdio: "inherit",
|
|
123
|
-
cwd: filesPath,
|
|
124
|
-
});
|
|
125
|
-
console.log("Server installed");
|
|
126
|
-
|
|
127
|
-
// registerServer();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function start () {
|
|
131
|
-
stopExisting();
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
if (shouldInstall()) {
|
|
135
|
-
installServer();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
console.log("Starting local server");
|
|
139
|
-
const appPkg = fs.readJsonSync(path.join(filesPath, "package.json"));
|
|
140
|
-
execSync(`pm2 start "${appPkg.main}" --name "${processName}" --no-autorestart`, {
|
|
141
|
-
stdio: "inherit",
|
|
142
|
-
cwd: filesPath,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
console.log(`Local server will be available in a couple of seconds`);
|
|
146
|
-
console.log(`You can close this window`);
|
|
147
|
-
console.log(`Visit https://app.dataramen.xyz`);
|
|
148
|
-
} catch (e) {
|
|
149
|
-
console.error(`Failed to start local server`, e);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function useJson (path) {
|
|
154
|
-
let file = undefined;
|
|
155
|
-
|
|
156
|
-
function get () {
|
|
157
|
-
try {
|
|
158
|
-
if (!file) {
|
|
159
|
-
file = fs.readJsonSync(path);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return file;
|
|
163
|
-
} catch (e) {
|
|
164
|
-
return undefined;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return get;
|
|
169
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var C=Object.create;var u=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var T=(o,r,n,d)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of I(r))!L.call(o,a)&&a!==n&&u(o,a,{get:()=>r[a],enumerable:!(d=$(r,a))||d.enumerable});return o};var l=(o,r,n)=>(n=o!=null?C(J(o)):{},T(r||!o||!o.__esModule?u(n,"default",{value:o,enumerable:!0}):n,o));var O=l(require("yargs")),w=require("yargs/helpers");var v=require("node:os"),P=require("node:path"),D=(0,v.homedir)();var s="@dataramen/local-server",t=(0,P.join)(D,".dataramen",".runtime","server");var j=require("node:path"),A=l(require("fs-extra")),f=require("node:child_process");var h=l(require("fs-extra")),g=require("node:path");function S(o){let r;function n(){try{return r||(r=h.readJsonSync(o)),r}catch{return}}return n}var y=S((0,g.join)(__dirname,"..","package.json")),p=S((0,g.join)(t,"package.json"));var i=l(require("fs-extra")),e=require("node:path"),c=require("node:child_process");function x(){try{let o=p();if(!o)return!0;let r=i.readJsonSync((0,e.join)(__dirname,"..","dist","package.json"));return o.version!==r.version}catch{return!0}}function _(){try{return(0,c.execSync)("pm2 -v",{stdio:"inherit"}),!0}catch{return console.error("Library does not exist"),!1}}function E(){console.log("Install Pm2"),(0,c.execSync)("npm i -g pm2",{stdio:"inherit"})}function k(){try{(0,c.execSync)(`pm2 stop "${s}"`)}catch{}}function R(){console.log("Installing Server"),i.copySync((0,e.join)(__dirname,"..","dist","code"),(0,e.join)(t,"code")),i.copySync((0,e.join)(__dirname,"..","dist","env",".env.default"),(0,e.join)(t,"env",".env.default")),i.copySync((0,e.join)(__dirname,"..","dist","package.json"),(0,e.join)(t,"package.json")),(0,c.execSync)("npm i",{stdio:"inherit",cwd:t}),console.log("Server installed")}function H(){_()||E(),k();try{x()&&R(),console.log("Starting local server");let r=A.readJsonSync((0,j.join)(t,"package.json"));(0,f.execSync)(`pm2 start "${r.main}" --name "${s}" --no-autorestart`,{stdio:"inherit",cwd:t}),console.log("Local server will be available in a couple of seconds"),console.log("You can close this window"),console.log("Visit https://app.dataramen.xyz")}catch(r){console.error("Failed to start local server",r)}}function V(){(0,f.execSync)(`pm2 logs ${s}`,{stdio:"inherit"})}function b(){(0,f.execSync)(`pm2 stop ${s}`,{stdio:"inherit"})}function B(){console.log(`Data ramen CLI version: ${y().version}`),console.log(`Data ramen local server version: ${p().version}`)}var m={start:H,logs:V,stop:b,version:B};(0,O.default)((0,w.hideBin)(process.argv)).command("start","Default command, start/restart the server",m.start).command(["logs"],"Listen for logs",m.logs).command("stop","Stop the server",m.stop).command(["version"],"Show version",m.version).parse();
|
package/dist/package.json
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@dataramen/local-server",
|
|
3
|
+
"version": "0.0.35",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "code/proxy.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@fastify/cors": "^11.0.1",
|
|
8
|
+
"dotenv": "^16.5.0",
|
|
9
|
+
"fast-glob": "^3.3.3",
|
|
10
|
+
"fastify": "^5.3.2",
|
|
11
|
+
"mysql2": "^3.14.1",
|
|
12
|
+
"pg": "^8.15.6",
|
|
13
|
+
"sqlite3": "^5.1.7",
|
|
14
|
+
"typeorm": "^0.3.23"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"fs-extra": "^11.3.0",
|
|
18
|
+
"yargs": "^18.0.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataramen/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"dataramen": "bin/run.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "node build.
|
|
9
|
+
"build": "node build.mjs",
|
|
10
|
+
"package": "node package.mjs"
|
|
10
11
|
},
|
|
11
12
|
"dependencies": {
|
|
12
13
|
"fs-extra": "^11.3.0",
|
|
13
14
|
"yargs": "^18.0.0"
|
|
14
15
|
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"esbuild": "^0.25.5",
|
|
18
|
+
"@types/fs-extra": "^11.0.3"
|
|
19
|
+
},
|
|
15
20
|
"files": [
|
|
16
21
|
"dist/"
|
|
17
22
|
],
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const createRouter_1 = require("../../utils/createRouter");
|
|
4
|
-
const httpError_1 = require("../../utils/httpError");
|
|
5
|
-
const prompts_1 = require("../../utils/prompts");
|
|
6
|
-
const db_1 = require("../../repository/db");
|
|
7
|
-
async function getDbString(datastoreId) {
|
|
8
|
-
const inspections = await db_1.DatabaseInspectionRepository.findBy({
|
|
9
|
-
datasource: {
|
|
10
|
-
id: datastoreId,
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
return (0, prompts_1.buildDbString)(inspections);
|
|
14
|
-
}
|
|
15
|
-
async function getAiCallInfo(userId) {
|
|
16
|
-
const userSettings = await db_1.UserSettingsRepository.findOneBy({
|
|
17
|
-
id: userId,
|
|
18
|
-
});
|
|
19
|
-
const openAiToken = userSettings?.openAiToken;
|
|
20
|
-
if (!openAiToken) {
|
|
21
|
-
throw new httpError_1.HttpError(400, "API key not found. Please set API key in settings");
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
model: userSettings?.model || "gpt-4o",
|
|
25
|
-
token: openAiToken,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
exports.default = (0, createRouter_1.createRouter)((instance) => {
|
|
29
|
-
// workbook chat
|
|
30
|
-
instance.post("/workbook", async (request) => {
|
|
31
|
-
// const userId = getRequestUserId(request);
|
|
32
|
-
// const { messages, id } = getRequestPayload<{ messages: TOpenAiMessage[]; id: string; }>(request);
|
|
33
|
-
// const workbook = await Workbook.findByPk(id);
|
|
34
|
-
// if (!workbook) {
|
|
35
|
-
// throw new Error("Workbook not found");
|
|
36
|
-
// }
|
|
37
|
-
// const { model, token } = await getAiCallInfo(userId);
|
|
38
|
-
// const dbString = await getDbString(workbook.getDataValue("dataSourceId"));
|
|
39
|
-
// const { choices } = await executePrompt({
|
|
40
|
-
// openaiApiKey: token,
|
|
41
|
-
// temperature: 0.5,
|
|
42
|
-
// messages: [
|
|
43
|
-
// {
|
|
44
|
-
// role: "system",
|
|
45
|
-
// content: `You are a database administrator and your role is to assist the user while writing queries. This is the database schema:\n${dbString}.\n\nThe current workbook is:\n${workbook.getDataValue("text")}`,
|
|
46
|
-
// },
|
|
47
|
-
// ...messages
|
|
48
|
-
// ],
|
|
49
|
-
// model,
|
|
50
|
-
// });
|
|
51
|
-
return {
|
|
52
|
-
data: "", //choices[0].message,
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const createRouter_1 = require("../../utils/createRouter");
|
|
4
|
-
const request_1 = require("../../utils/request");
|
|
5
|
-
const validators_1 = require("./validators");
|
|
6
|
-
const httpError_1 = require("../../utils/httpError");
|
|
7
|
-
const connectorManager_1 = require("../../services/connectorManager");
|
|
8
|
-
const db_1 = require("../../repository/db");
|
|
9
|
-
exports.default = (0, createRouter_1.createRouter)((instance) => {
|
|
10
|
-
// get datasource by id
|
|
11
|
-
instance.get("/:id", async (request) => {
|
|
12
|
-
const { id } = (0, request_1.getRequestParams)(request);
|
|
13
|
-
const dataSource = await db_1.DataSourceRepository.findOne({
|
|
14
|
-
where: {
|
|
15
|
-
id,
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
if (!dataSource) {
|
|
19
|
-
throw new httpError_1.HttpError(404, "Data source not found");
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
data: dataSource,
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
instance.get("/", async (request) => {
|
|
26
|
-
const { teamId } = (0, request_1.getRequestQuery)(request);
|
|
27
|
-
const dataSources = await db_1.DataSourceRepository.find({
|
|
28
|
-
where: {
|
|
29
|
-
team: {
|
|
30
|
-
id: teamId,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
order: {
|
|
34
|
-
createdAt: "DESC",
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
return {
|
|
38
|
-
data: dataSources,
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
// create data source
|
|
42
|
-
instance.post("/", async (request, reply) => {
|
|
43
|
-
const { teamId, ownerId, ...proto } = (0, request_1.getRequestPayload)(request, validators_1.validateCreateDataSource);
|
|
44
|
-
const dataSource = db_1.DataSourceRepository.create({
|
|
45
|
-
...proto,
|
|
46
|
-
team: {
|
|
47
|
-
id: teamId,
|
|
48
|
-
},
|
|
49
|
-
owner: {
|
|
50
|
-
id: ownerId,
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const connection = await (0, connectorManager_1.getDynamicConnection)(dataSource, request);
|
|
54
|
-
try {
|
|
55
|
-
await connection.checkConnection();
|
|
56
|
-
}
|
|
57
|
-
catch (e) {
|
|
58
|
-
throw new httpError_1.HttpError(400, "Cannot connect to the database, please check datasource configuration");
|
|
59
|
-
}
|
|
60
|
-
const createdDataSource = await db_1.DataSourceRepository.save(dataSource);
|
|
61
|
-
return {
|
|
62
|
-
data: createdDataSource,
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
// update datasource
|
|
66
|
-
instance.put("/:id", async (request, reply) => {
|
|
67
|
-
const { id } = (0, request_1.getRequestParams)(request);
|
|
68
|
-
const payload = (0, request_1.getRequestPayload)(request);
|
|
69
|
-
const dataSource = await db_1.DataSourceRepository.findOneBy({
|
|
70
|
-
id,
|
|
71
|
-
});
|
|
72
|
-
if (!dataSource) {
|
|
73
|
-
throw new httpError_1.HttpError(404, "Data source not found");
|
|
74
|
-
}
|
|
75
|
-
const updated = db_1.DataSourceRepository.merge(dataSource, payload);
|
|
76
|
-
await db_1.DataSourceRepository.save(updated);
|
|
77
|
-
return {
|
|
78
|
-
data: updated,
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
// remove datasource
|
|
82
|
-
instance.delete("/:id", async (request, reply) => {
|
|
83
|
-
return db_1.AppDataSource.transaction(async () => {
|
|
84
|
-
const { id } = (0, request_1.getRequestParams)(request);
|
|
85
|
-
await Promise.all([
|
|
86
|
-
db_1.DatabaseInspectionRepository.delete({
|
|
87
|
-
datasource: {
|
|
88
|
-
id,
|
|
89
|
-
}
|
|
90
|
-
}),
|
|
91
|
-
db_1.QueriesRepository.delete({
|
|
92
|
-
dataSource: {
|
|
93
|
-
id,
|
|
94
|
-
},
|
|
95
|
-
}),
|
|
96
|
-
]);
|
|
97
|
-
await db_1.DataSourceRepository.delete({
|
|
98
|
-
id,
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
// inspect datasource
|
|
103
|
-
instance.post("/:id/inspect", async (request, reply) => {
|
|
104
|
-
const { id } = (0, request_1.getRequestParams)(request);
|
|
105
|
-
const dataSource = await db_1.DataSourceRepository.findOneBy({
|
|
106
|
-
id,
|
|
107
|
-
});
|
|
108
|
-
if (!dataSource) {
|
|
109
|
-
throw new Error("Data source not found");
|
|
110
|
-
}
|
|
111
|
-
dataSource.status = "INSPECTING";
|
|
112
|
-
await db_1.DataSourceRepository.save(dataSource);
|
|
113
|
-
const connection = await (0, connectorManager_1.getDynamicConnection)(dataSource, request);
|
|
114
|
-
// inspect dataSource
|
|
115
|
-
const inspection = await connection.inspectSchema();
|
|
116
|
-
// destroy previous inspections
|
|
117
|
-
await db_1.DatabaseInspectionRepository.delete({
|
|
118
|
-
datasource: {
|
|
119
|
-
id,
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
await db_1.DatabaseInspectionRepository.insert(inspection.sort().map((i) => db_1.DatabaseInspectionRepository.create({
|
|
123
|
-
tableName: i.tableName,
|
|
124
|
-
columns: i.columns,
|
|
125
|
-
datasource: {
|
|
126
|
-
id,
|
|
127
|
-
},
|
|
128
|
-
})));
|
|
129
|
-
// update datasource last inspected
|
|
130
|
-
dataSource.status = "READY";
|
|
131
|
-
dataSource.lastInspected = new Date();
|
|
132
|
-
await db_1.DataSourceRepository.save(dataSource);
|
|
133
|
-
});
|
|
134
|
-
instance.get("/:id/inspections", async (request, reply) => {
|
|
135
|
-
const { id } = (0, request_1.getRequestParams)(request);
|
|
136
|
-
const inspections = await db_1.DatabaseInspectionRepository.find({
|
|
137
|
-
where: {
|
|
138
|
-
datasource: {
|
|
139
|
-
id,
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
return {
|
|
144
|
-
data: inspections,
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateCreateDataSource = void 0;
|
|
4
|
-
const httpError_1 = require("../../utils/httpError");
|
|
5
|
-
const validateCreateDataSource = (dataSource) => {
|
|
6
|
-
if (!dataSource.dbUrl) {
|
|
7
|
-
throw new httpError_1.HttpError(400, "url is required");
|
|
8
|
-
}
|
|
9
|
-
if (!dataSource.dbUser) {
|
|
10
|
-
throw new httpError_1.HttpError(400, "user is required");
|
|
11
|
-
}
|
|
12
|
-
if (!dataSource.dbType) {
|
|
13
|
-
throw new httpError_1.HttpError(400, "type is required");
|
|
14
|
-
}
|
|
15
|
-
if (!dataSource.name) {
|
|
16
|
-
throw new httpError_1.HttpError(400, "name is required");
|
|
17
|
-
}
|
|
18
|
-
if (!dataSource.dbDatabase) {
|
|
19
|
-
throw new httpError_1.HttpError(400, "database is required");
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
exports.validateCreateDataSource = validateCreateDataSource;
|