@dataramen/cli 0.0.10 → 0.0.12
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/code/proxy.js +6 -6
- package/dist/package.json +1 -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
|
@@ -1,123 +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 queryUtils_1 = require("../../utils/queryUtils");
|
|
6
|
-
const httpError_1 = require("../../utils/httpError");
|
|
7
|
-
const db_1 = require("../../repository/db");
|
|
8
|
-
const files_1 = require("../../services/files");
|
|
9
|
-
exports.default = (0, createRouter_1.createRouter)((instance) => {
|
|
10
|
-
instance.get("/", async (request) => {
|
|
11
|
-
const { dsId, teamId, limit, orderBy } = (0, request_1.getRequestQuery)(request);
|
|
12
|
-
if (!dsId && !teamId) {
|
|
13
|
-
throw new httpError_1.HttpError(400, "Either dsId or teamId is required");
|
|
14
|
-
}
|
|
15
|
-
const workbooks = await db_1.WorkbookRepository.find({
|
|
16
|
-
where: {
|
|
17
|
-
team: {
|
|
18
|
-
id: teamId,
|
|
19
|
-
},
|
|
20
|
-
isTrash: false,
|
|
21
|
-
},
|
|
22
|
-
take: limit,
|
|
23
|
-
order: (0, queryUtils_1.parseOrderQueryParam)(orderBy, {
|
|
24
|
-
createdAt: "DESC",
|
|
25
|
-
})
|
|
26
|
-
});
|
|
27
|
-
return {
|
|
28
|
-
data: workbooks,
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
instance.get("/:id", async (request) => {
|
|
32
|
-
const { id } = (0, request_1.getRequestParams)(request);
|
|
33
|
-
const workbook = await db_1.WorkbookRepository.findOneBy({
|
|
34
|
-
id,
|
|
35
|
-
});
|
|
36
|
-
if (!workbook) {
|
|
37
|
-
return {
|
|
38
|
-
status: 404,
|
|
39
|
-
data: "Workbook not found",
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
data: workbook,
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
instance.post("/", async (request) => {
|
|
47
|
-
const payload = (0, request_1.getRequestPayload)(request);
|
|
48
|
-
const workbook = await db_1.WorkbookRepository.save(db_1.WorkbookRepository.create({
|
|
49
|
-
name: payload.name,
|
|
50
|
-
isTrash: false,
|
|
51
|
-
team: {
|
|
52
|
-
id: payload.teamId,
|
|
53
|
-
}
|
|
54
|
-
}));
|
|
55
|
-
return {
|
|
56
|
-
data: workbook,
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
// update workbook
|
|
60
|
-
instance.patch("/:id", async (request) => {
|
|
61
|
-
const { id } = (0, request_1.getRequestParams)(request);
|
|
62
|
-
const payload = (0, request_1.getRequestPayload)(request);
|
|
63
|
-
const result = await db_1.WorkbookRepository.update(id, payload);
|
|
64
|
-
if (!result.affected) {
|
|
65
|
-
throw new httpError_1.HttpError(404, "Workbook not found");
|
|
66
|
-
}
|
|
67
|
-
const workbook = await db_1.WorkbookRepository.findOneBy({
|
|
68
|
-
id,
|
|
69
|
-
});
|
|
70
|
-
return {
|
|
71
|
-
data: workbook,
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
// delete workbook
|
|
75
|
-
instance.delete("/:id", async (request) => {
|
|
76
|
-
const { id } = (0, request_1.getRequestParams)(request);
|
|
77
|
-
// todo: delete file
|
|
78
|
-
const result = await db_1.WorkbookRepository.delete({
|
|
79
|
-
id
|
|
80
|
-
});
|
|
81
|
-
if (!result.affected) {
|
|
82
|
-
return {
|
|
83
|
-
status: 404,
|
|
84
|
-
data: "Workbook not found",
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
instance.get("/:id/content", async (request) => {
|
|
89
|
-
const { id } = (0, request_1.getRequestParams)(request);
|
|
90
|
-
const workbook = await db_1.WorkbookRepository.findOneBy({
|
|
91
|
-
id,
|
|
92
|
-
});
|
|
93
|
-
if (!workbook) {
|
|
94
|
-
throw new httpError_1.HttpError(404, "Workbook not found");
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
const file = await (0, files_1.getFile)(workbook?.path);
|
|
98
|
-
if (file) {
|
|
99
|
-
return {
|
|
100
|
-
data: file,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
catch (e) { }
|
|
105
|
-
return {
|
|
106
|
-
data: "",
|
|
107
|
-
};
|
|
108
|
-
});
|
|
109
|
-
instance.patch("/:id/content", async (request) => {
|
|
110
|
-
const { id } = (0, request_1.getRequestParams)(request);
|
|
111
|
-
const body = (0, request_1.getRequestPayload)(request);
|
|
112
|
-
const workbook = await db_1.WorkbookRepository.findOneBy({
|
|
113
|
-
id,
|
|
114
|
-
});
|
|
115
|
-
if (!workbook?.path) {
|
|
116
|
-
throw new httpError_1.HttpError(404, "Workbook not found");
|
|
117
|
-
}
|
|
118
|
-
await (0, files_1.storeFile)(workbook?.path, body.content);
|
|
119
|
-
await db_1.WorkbookRepository.update(workbook.id, {
|
|
120
|
-
updatedAt: new Date()
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
package/dist/code/env.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const dotenv_1 = require("dotenv");
|
|
4
|
-
const node_path_1 = require("node:path");
|
|
5
|
-
const node_fs_1 = require("node:fs");
|
|
6
|
-
const packageJson = (() => {
|
|
7
|
-
try {
|
|
8
|
-
const file = (0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, "..", "package.json"), "utf8");
|
|
9
|
-
return JSON.parse(file);
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
return {
|
|
13
|
-
version: "0.0.0",
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
})();
|
|
17
|
-
(0, dotenv_1.config)({
|
|
18
|
-
path: [
|
|
19
|
-
(0, node_path_1.join)(__dirname, "..", "env", ".env"),
|
|
20
|
-
(0, node_path_1.join)(__dirname, "..", "env", ".env.default"),
|
|
21
|
-
],
|
|
22
|
-
});
|
|
23
|
-
(0, dotenv_1.populate)(process.env, {
|
|
24
|
-
SERVER_VERSION: packageJson.version,
|
|
25
|
-
});
|
package/dist/code/index.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
require("./env");
|
|
7
|
-
const fastify_1 = __importDefault(require("fastify"));
|
|
8
|
-
const cors_1 = __importDefault(require("@fastify/cors"));
|
|
9
|
-
const httpError_1 = require("./utils/httpError");
|
|
10
|
-
const db_1 = require("./repository/db");
|
|
11
|
-
const files_1 = require("./services/files");
|
|
12
|
-
const router_1 = __importDefault(require("./api/chat/router"));
|
|
13
|
-
const router_2 = __importDefault(require("./api/dataSources/router"));
|
|
14
|
-
const router_3 = __importDefault(require("./api/project/router"));
|
|
15
|
-
const router_4 = __importDefault(require("./api/queries/router"));
|
|
16
|
-
const router_5 = __importDefault(require("./api/runner/router"));
|
|
17
|
-
const router_6 = __importDefault(require("./api/status/router"));
|
|
18
|
-
const router_7 = __importDefault(require("./api/teams/router"));
|
|
19
|
-
const router_8 = __importDefault(require("./api/users/router"));
|
|
20
|
-
const router_9 = __importDefault(require("./api/userSettings/router"));
|
|
21
|
-
const router_10 = __importDefault(require("./api/workbooks/router"));
|
|
22
|
-
const server = (0, fastify_1.default)();
|
|
23
|
-
const PORT = process.env.PORT ? parseInt(process.env.PORT) : 4466;
|
|
24
|
-
function registerRouter(fn, prefix) {
|
|
25
|
-
server.register(fn, { prefix });
|
|
26
|
-
console.log("Registered " + prefix);
|
|
27
|
-
}
|
|
28
|
-
async function initialize() {
|
|
29
|
-
await (0, files_1.setupProjectFolders)(); // creates .dataramen/files
|
|
30
|
-
// const routers = glob.sync("./api/**/router.js", {
|
|
31
|
-
// cwd: __dirname,
|
|
32
|
-
// });
|
|
33
|
-
//
|
|
34
|
-
// routers.forEach((file) => {
|
|
35
|
-
// const apiName = file.split("/")[2];
|
|
36
|
-
// const prefix = "/api/" + folderNameToSnakeCase(apiName);
|
|
37
|
-
// server.register(require(file), { prefix });
|
|
38
|
-
// console.log(`${prefix} -> ${apiName} controller `);
|
|
39
|
-
// });
|
|
40
|
-
registerRouter(router_1.default, `/api/chat`);
|
|
41
|
-
registerRouter(router_2.default, `/api/data-sources`);
|
|
42
|
-
registerRouter(router_3.default, `/api/project`);
|
|
43
|
-
registerRouter(router_4.default, `/api/queries`);
|
|
44
|
-
registerRouter(router_5.default, `/api/runner`);
|
|
45
|
-
registerRouter(router_6.default, `/api/status`);
|
|
46
|
-
registerRouter(router_7.default, `/api/teams`);
|
|
47
|
-
registerRouter(router_8.default, `/api/users`);
|
|
48
|
-
registerRouter(router_9.default, `/api/user-settings`);
|
|
49
|
-
registerRouter(router_10.default, `/api/workbooks`);
|
|
50
|
-
server.register(cors_1.default, {
|
|
51
|
-
origin: "*",
|
|
52
|
-
methods: "*",
|
|
53
|
-
});
|
|
54
|
-
server.addHook("onResponse", async (request) => {
|
|
55
|
-
if (request.__connections) {
|
|
56
|
-
request.__connections.forEach((connection) => {
|
|
57
|
-
connection.close();
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
server.setErrorHandler((error, request, reply) => {
|
|
62
|
-
if (error instanceof httpError_1.HttpError) {
|
|
63
|
-
console.error(error);
|
|
64
|
-
reply.status(error.status).send({
|
|
65
|
-
error: error.message,
|
|
66
|
-
});
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
console.error(error);
|
|
71
|
-
reply.status(500).send({
|
|
72
|
-
error: "Internal Server Error",
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
await server.after();
|
|
77
|
-
await (0, db_1.init)();
|
|
78
|
-
server.listen({ port: PORT, host: '0.0.0.0' }, (err, address) => {
|
|
79
|
-
if (err) {
|
|
80
|
-
console.error(err);
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
console.log(`Server listening at ${address}`);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
initialize();
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.QueriesRepository = exports.WorkbookRepository = exports.UserSettingsRepository = exports.UserRepository = exports.TeamRepository = exports.DataSourceRepository = exports.DatabaseInspectionRepository = exports.init = exports.AppDataSource = void 0;
|
|
7
|
-
const typeorm_1 = require("typeorm");
|
|
8
|
-
const databaseInspection_1 = require("./tables/databaseInspection");
|
|
9
|
-
const teams_1 = require("./tables/teams");
|
|
10
|
-
const users_1 = require("./tables/users");
|
|
11
|
-
const userSettings_1 = require("./tables/userSettings");
|
|
12
|
-
const workbook_1 = require("./tables/workbook");
|
|
13
|
-
const datasource_1 = require("./tables/datasource");
|
|
14
|
-
const os_1 = __importDefault(require("os"));
|
|
15
|
-
const query_1 = require("./tables/query");
|
|
16
|
-
function getDatabaseValue() {
|
|
17
|
-
let value = process.env.TYPEORM_DATABASE;
|
|
18
|
-
if (!value) {
|
|
19
|
-
throw new Error("Bad value for TYPEORM_DATABASE. Please check your config!");
|
|
20
|
-
}
|
|
21
|
-
if (value.startsWith("<home>")) {
|
|
22
|
-
value = value.replace("<home>", os_1.default.homedir());
|
|
23
|
-
}
|
|
24
|
-
return value;
|
|
25
|
-
}
|
|
26
|
-
exports.AppDataSource = new typeorm_1.DataSource({
|
|
27
|
-
type: process.env.TYPEORM_CONNECTION,
|
|
28
|
-
database: getDatabaseValue(),
|
|
29
|
-
synchronize: process.env.TYPEORM_SYNCHRONIZE === 'true',
|
|
30
|
-
host: process.env.TYPEORM_HOST,
|
|
31
|
-
username: process.env.TYPEORM_USERNAME,
|
|
32
|
-
password: process.env.TYPEORM_PASSWORD,
|
|
33
|
-
port: process.env.TYPEORM_PORT ? parseInt(process.env.TYPEORM_PORT) : undefined,
|
|
34
|
-
logging: process.env.TYPEORM_LOGGING === 'true',
|
|
35
|
-
entities: [
|
|
36
|
-
databaseInspection_1.DatabaseInspection,
|
|
37
|
-
datasource_1.DataSource,
|
|
38
|
-
teams_1.Team,
|
|
39
|
-
users_1.User,
|
|
40
|
-
userSettings_1.UserSettings,
|
|
41
|
-
workbook_1.Workbook,
|
|
42
|
-
query_1.Query,
|
|
43
|
-
],
|
|
44
|
-
});
|
|
45
|
-
const init = async () => {
|
|
46
|
-
if (!exports.AppDataSource.isInitialized) {
|
|
47
|
-
return exports.AppDataSource.initialize();
|
|
48
|
-
}
|
|
49
|
-
throw new Error("Already initialized");
|
|
50
|
-
};
|
|
51
|
-
exports.init = init;
|
|
52
|
-
exports.DatabaseInspectionRepository = exports.AppDataSource.getRepository(databaseInspection_1.DatabaseInspection);
|
|
53
|
-
exports.DataSourceRepository = exports.AppDataSource.getRepository(datasource_1.DataSource);
|
|
54
|
-
exports.TeamRepository = exports.AppDataSource.getRepository(teams_1.Team);
|
|
55
|
-
exports.UserRepository = exports.AppDataSource.getRepository(users_1.User);
|
|
56
|
-
exports.UserSettingsRepository = exports.AppDataSource.getRepository(userSettings_1.UserSettings);
|
|
57
|
-
exports.WorkbookRepository = exports.AppDataSource.getRepository(workbook_1.Workbook);
|
|
58
|
-
exports.QueriesRepository = exports.AppDataSource.getRepository(query_1.Query);
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DatabaseInspection = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
exports.DatabaseInspection = new typeorm_1.EntitySchema({
|
|
6
|
-
name: "DatabaseInspection",
|
|
7
|
-
tableName: "db_inspection",
|
|
8
|
-
columns: {
|
|
9
|
-
id: {
|
|
10
|
-
type: String,
|
|
11
|
-
unique: true,
|
|
12
|
-
primary: true,
|
|
13
|
-
generated: "uuid",
|
|
14
|
-
},
|
|
15
|
-
tableName: {
|
|
16
|
-
nullable: true,
|
|
17
|
-
type: String,
|
|
18
|
-
},
|
|
19
|
-
columns: {
|
|
20
|
-
type: "json",
|
|
21
|
-
nullable: true,
|
|
22
|
-
},
|
|
23
|
-
createdAt: {
|
|
24
|
-
type: "datetime",
|
|
25
|
-
default: "CURRENT_TIMESTAMP",
|
|
26
|
-
},
|
|
27
|
-
updatedAt: {
|
|
28
|
-
type: "datetime",
|
|
29
|
-
default: "CURRENT_TIMESTAMP",
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
relations: {
|
|
33
|
-
datasource: {
|
|
34
|
-
target: () => "DataSource",
|
|
35
|
-
type: "many-to-one",
|
|
36
|
-
joinTable: false,
|
|
37
|
-
cascade: true,
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataSource = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
exports.DataSource = new typeorm_1.EntitySchema({
|
|
6
|
-
name: "DataSource",
|
|
7
|
-
tableName: "data_sources",
|
|
8
|
-
columns: {
|
|
9
|
-
id: {
|
|
10
|
-
type: "uuid",
|
|
11
|
-
primary: true,
|
|
12
|
-
generated: "uuid",
|
|
13
|
-
},
|
|
14
|
-
dbUrl: {
|
|
15
|
-
type: String,
|
|
16
|
-
},
|
|
17
|
-
dbPort: {
|
|
18
|
-
type: Number,
|
|
19
|
-
nullable: true,
|
|
20
|
-
},
|
|
21
|
-
dbUser: {
|
|
22
|
-
type: String,
|
|
23
|
-
},
|
|
24
|
-
dbPassword: {
|
|
25
|
-
type: String,
|
|
26
|
-
nullable: true,
|
|
27
|
-
},
|
|
28
|
-
dbType: {
|
|
29
|
-
type: String,
|
|
30
|
-
},
|
|
31
|
-
createdAt: {
|
|
32
|
-
type: "datetime",
|
|
33
|
-
default: () => "CURRENT_TIMESTAMP",
|
|
34
|
-
},
|
|
35
|
-
updatedAt: {
|
|
36
|
-
type: "datetime",
|
|
37
|
-
default: () => "CURRENT_TIMESTAMP",
|
|
38
|
-
},
|
|
39
|
-
name: {
|
|
40
|
-
type: String,
|
|
41
|
-
},
|
|
42
|
-
description: {
|
|
43
|
-
type: String,
|
|
44
|
-
nullable: true,
|
|
45
|
-
},
|
|
46
|
-
dbDatabase: {
|
|
47
|
-
type: String,
|
|
48
|
-
},
|
|
49
|
-
dbSchema: {
|
|
50
|
-
type: String,
|
|
51
|
-
nullable: true,
|
|
52
|
-
},
|
|
53
|
-
lastInspected: {
|
|
54
|
-
type: "datetime",
|
|
55
|
-
nullable: true,
|
|
56
|
-
default: () => null,
|
|
57
|
-
},
|
|
58
|
-
status: {
|
|
59
|
-
type: String,
|
|
60
|
-
nullable: true,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
relations: {
|
|
64
|
-
team: {
|
|
65
|
-
type: "many-to-one",
|
|
66
|
-
target: () => "Team",
|
|
67
|
-
inverseSide: "datasources",
|
|
68
|
-
joinColumn: true,
|
|
69
|
-
},
|
|
70
|
-
inspections: {
|
|
71
|
-
type: "one-to-many",
|
|
72
|
-
target: () => "DatabaseInspection",
|
|
73
|
-
inverseSide: "datasource",
|
|
74
|
-
},
|
|
75
|
-
queries: {
|
|
76
|
-
type: "one-to-many",
|
|
77
|
-
target: () => "Query",
|
|
78
|
-
inverseSide: "dataSource",
|
|
79
|
-
},
|
|
80
|
-
owner: {
|
|
81
|
-
type: "many-to-one",
|
|
82
|
-
target: () => "User",
|
|
83
|
-
joinColumn: true,
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Query = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
exports.Query = new typeorm_1.EntitySchema({
|
|
6
|
-
name: "Query",
|
|
7
|
-
tableName: "query",
|
|
8
|
-
columns: {
|
|
9
|
-
id: {
|
|
10
|
-
type: "uuid",
|
|
11
|
-
primary: true,
|
|
12
|
-
generated: "uuid",
|
|
13
|
-
},
|
|
14
|
-
name: {
|
|
15
|
-
type: String,
|
|
16
|
-
},
|
|
17
|
-
opts: {
|
|
18
|
-
type: "json",
|
|
19
|
-
default: "{}",
|
|
20
|
-
},
|
|
21
|
-
isTrash: {
|
|
22
|
-
type: Boolean,
|
|
23
|
-
default: false,
|
|
24
|
-
nullable: true,
|
|
25
|
-
},
|
|
26
|
-
createdAt: {
|
|
27
|
-
type: "datetime",
|
|
28
|
-
default: () => "CURRENT_TIMESTAMP",
|
|
29
|
-
},
|
|
30
|
-
updatedAt: {
|
|
31
|
-
type: "datetime",
|
|
32
|
-
default: () => "CURRENT_TIMESTAMP",
|
|
33
|
-
onUpdate: "CURRENT_TIMESTAMP",
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
relations: {
|
|
37
|
-
team: {
|
|
38
|
-
type: "many-to-one",
|
|
39
|
-
target: () => "Team",
|
|
40
|
-
inverseSide: "workbooks",
|
|
41
|
-
joinColumn: true,
|
|
42
|
-
},
|
|
43
|
-
dataSource: {
|
|
44
|
-
type: "many-to-one",
|
|
45
|
-
target: () => "DataSource",
|
|
46
|
-
inverseSide: "queries",
|
|
47
|
-
joinColumn: true,
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Team = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
exports.Team = new typeorm_1.EntitySchema({
|
|
6
|
-
name: "Team",
|
|
7
|
-
tableName: "teams",
|
|
8
|
-
columns: {
|
|
9
|
-
id: {
|
|
10
|
-
type: "uuid",
|
|
11
|
-
primary: true,
|
|
12
|
-
generated: "uuid",
|
|
13
|
-
},
|
|
14
|
-
name: {
|
|
15
|
-
type: String,
|
|
16
|
-
},
|
|
17
|
-
createdAt: {
|
|
18
|
-
type: "datetime",
|
|
19
|
-
default: () => "CURRENT_TIMESTAMP",
|
|
20
|
-
},
|
|
21
|
-
updatedAt: {
|
|
22
|
-
type: "datetime",
|
|
23
|
-
default: () => "CURRENT_TIMESTAMP",
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
relations: {
|
|
27
|
-
users: {
|
|
28
|
-
type: "many-to-many",
|
|
29
|
-
target: () => "User",
|
|
30
|
-
inverseSide: "teams",
|
|
31
|
-
},
|
|
32
|
-
workbooks: {
|
|
33
|
-
type: "one-to-many",
|
|
34
|
-
target: () => "Workbook",
|
|
35
|
-
inverseSide: "team",
|
|
36
|
-
},
|
|
37
|
-
queries: {
|
|
38
|
-
type: "one-to-many",
|
|
39
|
-
target: () => "Query",
|
|
40
|
-
inverseSide: "team",
|
|
41
|
-
},
|
|
42
|
-
datasources: {
|
|
43
|
-
type: "one-to-many",
|
|
44
|
-
target: () => "DataSource",
|
|
45
|
-
inverseSide: "team",
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserSettings = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
exports.UserSettings = new typeorm_1.EntitySchema({
|
|
6
|
-
name: "UserSettings",
|
|
7
|
-
tableName: "user_settings",
|
|
8
|
-
columns: {
|
|
9
|
-
id: {
|
|
10
|
-
type: "uuid",
|
|
11
|
-
primary: true,
|
|
12
|
-
generated: "uuid",
|
|
13
|
-
},
|
|
14
|
-
openAiToken: {
|
|
15
|
-
type: String,
|
|
16
|
-
nullable: true,
|
|
17
|
-
},
|
|
18
|
-
model: {
|
|
19
|
-
type: String,
|
|
20
|
-
default: "gpt-3.5-turbo",
|
|
21
|
-
},
|
|
22
|
-
createdAt: {
|
|
23
|
-
type: "datetime",
|
|
24
|
-
default: () => "CURRENT_TIMESTAMP",
|
|
25
|
-
},
|
|
26
|
-
updatedAt: {
|
|
27
|
-
type: "datetime",
|
|
28
|
-
default: () => "CURRENT_TIMESTAMP",
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
relations: {
|
|
32
|
-
user: {
|
|
33
|
-
type: "one-to-one",
|
|
34
|
-
target: () => "User",
|
|
35
|
-
inverseSide: "settings",
|
|
36
|
-
joinColumn: true,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.User = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
exports.User = new typeorm_1.EntitySchema({
|
|
6
|
-
name: "User",
|
|
7
|
-
tableName: "users",
|
|
8
|
-
columns: {
|
|
9
|
-
id: {
|
|
10
|
-
type: "uuid",
|
|
11
|
-
primary: true,
|
|
12
|
-
generated: "uuid",
|
|
13
|
-
},
|
|
14
|
-
createdAt: {
|
|
15
|
-
type: "datetime",
|
|
16
|
-
default: "CURRENT_TIMESTAMP",
|
|
17
|
-
},
|
|
18
|
-
updatedAt: {
|
|
19
|
-
type: "datetime",
|
|
20
|
-
default: "CURRENT_TIMESTAMP",
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
relations: {
|
|
24
|
-
teams: {
|
|
25
|
-
type: "many-to-many",
|
|
26
|
-
target: () => "Team",
|
|
27
|
-
inverseSide: "users",
|
|
28
|
-
joinTable: true,
|
|
29
|
-
},
|
|
30
|
-
settings: {
|
|
31
|
-
type: "one-to-one",
|
|
32
|
-
target: () => "UserSettings",
|
|
33
|
-
inverseSide: "user",
|
|
34
|
-
joinColumn: true,
|
|
35
|
-
},
|
|
36
|
-
currentTeam: {
|
|
37
|
-
type: "many-to-one",
|
|
38
|
-
target: () => "Team",
|
|
39
|
-
joinColumn: true,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Workbook = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
exports.Workbook = new typeorm_1.EntitySchema({
|
|
6
|
-
name: "Workbook",
|
|
7
|
-
tableName: "workbooks",
|
|
8
|
-
columns: {
|
|
9
|
-
id: {
|
|
10
|
-
type: "uuid",
|
|
11
|
-
primary: true,
|
|
12
|
-
generated: "uuid",
|
|
13
|
-
},
|
|
14
|
-
name: {
|
|
15
|
-
type: String,
|
|
16
|
-
},
|
|
17
|
-
path: {
|
|
18
|
-
type: "uuid",
|
|
19
|
-
generated: "uuid",
|
|
20
|
-
},
|
|
21
|
-
isTrash: {
|
|
22
|
-
type: "boolean",
|
|
23
|
-
default: false,
|
|
24
|
-
},
|
|
25
|
-
createdAt: {
|
|
26
|
-
type: "datetime",
|
|
27
|
-
default: () => "CURRENT_TIMESTAMP",
|
|
28
|
-
},
|
|
29
|
-
updatedAt: {
|
|
30
|
-
type: "datetime",
|
|
31
|
-
default: () => "CURRENT_TIMESTAMP",
|
|
32
|
-
onUpdate: "CURRENT_TIMESTAMP",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
relations: {
|
|
36
|
-
team: {
|
|
37
|
-
type: "many-to-one",
|
|
38
|
-
target: () => "Team",
|
|
39
|
-
inverseSide: "workbooks",
|
|
40
|
-
joinColumn: true,
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDynamicConnection = void 0;
|
|
4
|
-
const mysqlConnector_1 = require("../mysqlConnector");
|
|
5
|
-
const httpError_1 = require("../../utils/httpError");
|
|
6
|
-
const pgConnector_1 = require("../pgConnector");
|
|
7
|
-
const getDynamicConnection = async (datasource, req) => {
|
|
8
|
-
try {
|
|
9
|
-
let dbConnectionManager;
|
|
10
|
-
if (datasource.dbType === "mysql") {
|
|
11
|
-
dbConnectionManager = await (0, mysqlConnector_1.MySqlConnector)(datasource);
|
|
12
|
-
}
|
|
13
|
-
else if (datasource.dbType === "postgres") {
|
|
14
|
-
dbConnectionManager = await (0, pgConnector_1.PGSqlConnector)(datasource);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
throw new httpError_1.HttpError(500, `Connection manager for ${datasource.dbType} not found`);
|
|
18
|
-
}
|
|
19
|
-
if (!req.__connections) {
|
|
20
|
-
req.__connections = [dbConnectionManager];
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
req.__connections.push(dbConnectionManager);
|
|
24
|
-
}
|
|
25
|
-
return dbConnectionManager;
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
console.error(error);
|
|
29
|
-
if (error instanceof httpError_1.HttpError) {
|
|
30
|
-
throw error;
|
|
31
|
-
}
|
|
32
|
-
if (error?.code === "ECONNREFUSED") {
|
|
33
|
-
throw new httpError_1.HttpError(500, "Failed to connect to the database");
|
|
34
|
-
}
|
|
35
|
-
throw new httpError_1.HttpError(500, error.message);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
exports.getDynamicConnection = getDynamicConnection;
|