@selentar/analitoly 0.1.1
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/LICENSE +21 -0
- package/README.md +93 -0
- package/api/dist/dashboards/dash_1775220041958_v1r8io.json +829 -0
- package/api/dist/dashboards/dash_1775222037264_1rrsrd.json +309 -0
- package/api/dist/src/agent/agent.controller.d.ts +26 -0
- package/api/dist/src/agent/agent.controller.js +124 -0
- package/api/dist/src/agent/agent.controller.js.map +1 -0
- package/api/dist/src/agent/agent.module.d.ts +2 -0
- package/api/dist/src/agent/agent.module.js +23 -0
- package/api/dist/src/agent/agent.module.js.map +1 -0
- package/api/dist/src/agent/agent.service.d.ts +39 -0
- package/api/dist/src/agent/agent.service.js +389 -0
- package/api/dist/src/agent/agent.service.js.map +1 -0
- package/api/dist/src/agent/mcp-config.d.ts +9 -0
- package/api/dist/src/agent/mcp-config.js +51 -0
- package/api/dist/src/agent/mcp-config.js.map +1 -0
- package/api/dist/src/app.module.d.ts +2 -0
- package/api/dist/src/app.module.js +52 -0
- package/api/dist/src/app.module.js.map +1 -0
- package/api/dist/src/chart/chart.controller.d.ts +8 -0
- package/api/dist/src/chart/chart.controller.js +38 -0
- package/api/dist/src/chart/chart.controller.js.map +1 -0
- package/api/dist/src/chart/chart.module.d.ts +2 -0
- package/api/dist/src/chart/chart.module.js +24 -0
- package/api/dist/src/chart/chart.module.js.map +1 -0
- package/api/dist/src/chart/chart.service.d.ts +32 -0
- package/api/dist/src/chart/chart.service.js +106 -0
- package/api/dist/src/chart/chart.service.js.map +1 -0
- package/api/dist/src/chat/chat.controller.d.ts +14 -0
- package/api/dist/src/chat/chat.controller.js +73 -0
- package/api/dist/src/chat/chat.controller.js.map +1 -0
- package/api/dist/src/chat/chat.module.d.ts +2 -0
- package/api/dist/src/chat/chat.module.js +22 -0
- package/api/dist/src/chat/chat.module.js.map +1 -0
- package/api/dist/src/chat/chat.service.d.ts +25 -0
- package/api/dist/src/chat/chat.service.js +168 -0
- package/api/dist/src/chat/chat.service.js.map +1 -0
- package/api/dist/src/connection/connection.controller.d.ts +46 -0
- package/api/dist/src/connection/connection.controller.js +189 -0
- package/api/dist/src/connection/connection.controller.js.map +1 -0
- package/api/dist/src/connection/connection.model.d.ts +116 -0
- package/api/dist/src/connection/connection.model.js +23 -0
- package/api/dist/src/connection/connection.model.js.map +1 -0
- package/api/dist/src/connection/connection.module.d.ts +2 -0
- package/api/dist/src/connection/connection.module.js +31 -0
- package/api/dist/src/connection/connection.module.js.map +1 -0
- package/api/dist/src/connection/connection.repository.d.ts +16 -0
- package/api/dist/src/connection/connection.repository.js +195 -0
- package/api/dist/src/connection/connection.repository.js.map +1 -0
- package/api/dist/src/connection/connection.service.d.ts +50 -0
- package/api/dist/src/connection/connection.service.js +343 -0
- package/api/dist/src/connection/connection.service.js.map +1 -0
- package/api/dist/src/context/context.controller.d.ts +13 -0
- package/api/dist/src/context/context.controller.js +86 -0
- package/api/dist/src/context/context.controller.js.map +1 -0
- package/api/dist/src/context/context.module.d.ts +2 -0
- package/api/dist/src/context/context.module.js +39 -0
- package/api/dist/src/context/context.module.js.map +1 -0
- package/api/dist/src/context/context.service.d.ts +32 -0
- package/api/dist/src/context/context.service.js +177 -0
- package/api/dist/src/context/context.service.js.map +1 -0
- package/api/dist/src/dashboard/dashboard.controller.d.ts +21 -0
- package/api/dist/src/dashboard/dashboard.controller.js +109 -0
- package/api/dist/src/dashboard/dashboard.controller.js.map +1 -0
- package/api/dist/src/dashboard/dashboard.model.d.ts +15 -0
- package/api/dist/src/dashboard/dashboard.model.js +3 -0
- package/api/dist/src/dashboard/dashboard.model.js.map +1 -0
- package/api/dist/src/dashboard/dashboard.module.d.ts +2 -0
- package/api/dist/src/dashboard/dashboard.module.js +24 -0
- package/api/dist/src/dashboard/dashboard.module.js.map +1 -0
- package/api/dist/src/dashboard/dashboard.repository.d.ts +9 -0
- package/api/dist/src/dashboard/dashboard.repository.js +72 -0
- package/api/dist/src/dashboard/dashboard.repository.js.map +1 -0
- package/api/dist/src/dashboard/dashboard.service.d.ts +14 -0
- package/api/dist/src/dashboard/dashboard.service.js +87 -0
- package/api/dist/src/dashboard/dashboard.service.js.map +1 -0
- package/api/dist/src/datasource/connectors/connector.interface.d.ts +6 -0
- package/api/dist/src/datasource/connectors/connector.interface.js +3 -0
- package/api/dist/src/datasource/connectors/connector.interface.js.map +1 -0
- package/api/dist/src/datasource/connectors/mongo.connector.d.ts +30 -0
- package/api/dist/src/datasource/connectors/mongo.connector.js +167 -0
- package/api/dist/src/datasource/connectors/mongo.connector.js.map +1 -0
- package/api/dist/src/datasource/connectors/mongo.connector.test.d.ts +1 -0
- package/api/dist/src/datasource/connectors/mongo.connector.test.js +179 -0
- package/api/dist/src/datasource/connectors/mongo.connector.test.js.map +1 -0
- package/api/dist/src/datasource/connectors/postgres.connector.d.ts +50 -0
- package/api/dist/src/datasource/connectors/postgres.connector.js +213 -0
- package/api/dist/src/datasource/connectors/postgres.connector.js.map +1 -0
- package/api/dist/src/datasource/connectors/postgres.connector.test.d.ts +1 -0
- package/api/dist/src/datasource/connectors/postgres.connector.test.js +197 -0
- package/api/dist/src/datasource/connectors/postgres.connector.test.js.map +1 -0
- package/api/dist/src/datasource/datasource.controller.d.ts +16 -0
- package/api/dist/src/datasource/datasource.controller.js +79 -0
- package/api/dist/src/datasource/datasource.controller.js.map +1 -0
- package/api/dist/src/datasource/datasource.model.d.ts +26 -0
- package/api/dist/src/datasource/datasource.model.js +3 -0
- package/api/dist/src/datasource/datasource.model.js.map +1 -0
- package/api/dist/src/datasource/datasource.module.d.ts +2 -0
- package/api/dist/src/datasource/datasource.module.js +31 -0
- package/api/dist/src/datasource/datasource.module.js.map +1 -0
- package/api/dist/src/datasource/datasource.repository.d.ts +11 -0
- package/api/dist/src/datasource/datasource.repository.js +61 -0
- package/api/dist/src/datasource/datasource.repository.js.map +1 -0
- package/api/dist/src/datasource/datasource.service.d.ts +28 -0
- package/api/dist/src/datasource/datasource.service.js +95 -0
- package/api/dist/src/datasource/datasource.service.js.map +1 -0
- package/api/dist/src/example/example.controller.d.ts +10 -0
- package/api/dist/src/example/example.controller.js +43 -0
- package/api/dist/src/example/example.controller.js.map +1 -0
- package/api/dist/src/example/example.model.d.ts +6 -0
- package/api/dist/src/example/example.model.js +3 -0
- package/api/dist/src/example/example.model.js.map +1 -0
- package/api/dist/src/example/example.module.d.ts +2 -0
- package/api/dist/src/example/example.module.js +23 -0
- package/api/dist/src/example/example.module.js.map +1 -0
- package/api/dist/src/example/example.repository.d.ts +6 -0
- package/api/dist/src/example/example.repository.js +30 -0
- package/api/dist/src/example/example.repository.js.map +1 -0
- package/api/dist/src/example/example.service.d.ts +10 -0
- package/api/dist/src/example/example.service.js +31 -0
- package/api/dist/src/example/example.service.js.map +1 -0
- package/api/dist/src/integration/integration.controller.d.ts +15 -0
- package/api/dist/src/integration/integration.controller.js +69 -0
- package/api/dist/src/integration/integration.controller.js.map +1 -0
- package/api/dist/src/integration/integration.model.d.ts +17 -0
- package/api/dist/src/integration/integration.model.js +3 -0
- package/api/dist/src/integration/integration.model.js.map +1 -0
- package/api/dist/src/integration/integration.module.d.ts +2 -0
- package/api/dist/src/integration/integration.module.js +24 -0
- package/api/dist/src/integration/integration.module.js.map +1 -0
- package/api/dist/src/integration/integration.repository.d.ts +6 -0
- package/api/dist/src/integration/integration.repository.js +45 -0
- package/api/dist/src/integration/integration.repository.js.map +1 -0
- package/api/dist/src/integration/integration.service.d.ts +12 -0
- package/api/dist/src/integration/integration.service.js +78 -0
- package/api/dist/src/integration/integration.service.js.map +1 -0
- package/api/dist/src/main.d.ts +1 -0
- package/api/dist/src/main.js +19 -0
- package/api/dist/src/main.js.map +1 -0
- package/api/dist/src/mcp/grafana.mcp.d.ts +1 -0
- package/api/dist/src/mcp/grafana.mcp.js +95 -0
- package/api/dist/src/mcp/grafana.mcp.js.map +1 -0
- package/api/dist/src/mcp/graylog.mcp.d.ts +1 -0
- package/api/dist/src/mcp/graylog.mcp.js +241 -0
- package/api/dist/src/mcp/graylog.mcp.js.map +1 -0
- package/api/dist/src/mcp/mcp-server.d.ts +1 -0
- package/api/dist/src/mcp/mcp-server.js +336 -0
- package/api/dist/src/mcp/mcp-server.js.map +1 -0
- package/api/dist/src/paths.d.ts +8 -0
- package/api/dist/src/paths.js +50 -0
- package/api/dist/src/paths.js.map +1 -0
- package/api/dist/src/paths.test.d.ts +1 -0
- package/api/dist/src/paths.test.js +60 -0
- package/api/dist/src/paths.test.js.map +1 -0
- package/api/dist/src/project/project.controller.d.ts +44 -0
- package/api/dist/src/project/project.controller.js +79 -0
- package/api/dist/src/project/project.controller.js.map +1 -0
- package/api/dist/src/project/project.model.d.ts +19 -0
- package/api/dist/src/project/project.model.js +3 -0
- package/api/dist/src/project/project.model.js.map +1 -0
- package/api/dist/src/project/project.module.d.ts +2 -0
- package/api/dist/src/project/project.module.js +24 -0
- package/api/dist/src/project/project.module.js.map +1 -0
- package/api/dist/src/project/project.repository.d.ts +6 -0
- package/api/dist/src/project/project.repository.js +52 -0
- package/api/dist/src/project/project.repository.js.map +1 -0
- package/api/dist/src/project/project.service.d.ts +17 -0
- package/api/dist/src/project/project.service.js +163 -0
- package/api/dist/src/project/project.service.js.map +1 -0
- package/api/dist/tsconfig.tsbuildinfo +1 -0
- package/api/dist/vitest.config.d.ts +2 -0
- package/api/dist/vitest.config.js +10 -0
- package/api/dist/vitest.config.js.map +1 -0
- package/api/public/dist/Analitoly.png +0 -0
- package/api/public/dist/AnalitolyShort.png +0 -0
- package/api/public/dist/Gitlab.png +0 -0
- package/api/public/dist/Grafana.png +0 -0
- package/api/public/dist/Graylog.png +0 -0
- package/api/public/dist/Mongodb.png +0 -0
- package/api/public/dist/PostgreSQL.png +0 -0
- package/api/public/dist/assets/index-BPB3ckw4.js +222 -0
- package/api/public/dist/assets/index-CSAGa0SG.js +227 -0
- package/api/public/dist/index.html +12 -0
- package/bin/analitoly-mcp.js +18 -0
- package/bin/analitoly.js +38 -0
- package/package.json +54 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const postgres_connector_1 = require("./postgres.connector");
|
|
5
|
+
const pg_1 = require("pg");
|
|
6
|
+
vitest_1.vi.mock('pg', () => {
|
|
7
|
+
const mockClient = {
|
|
8
|
+
query: vitest_1.vi.fn().mockResolvedValue({ rows: [] }),
|
|
9
|
+
release: vitest_1.vi.fn(),
|
|
10
|
+
};
|
|
11
|
+
const MockPool = vitest_1.vi.fn(function () {
|
|
12
|
+
return {
|
|
13
|
+
connect: vitest_1.vi.fn().mockResolvedValue(mockClient),
|
|
14
|
+
end: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
return { Pool: MockPool };
|
|
18
|
+
});
|
|
19
|
+
(0, vitest_1.describe)('validateReadOnly (via executeQuery)', () => {
|
|
20
|
+
let connector;
|
|
21
|
+
const config = { type: 'postgresql', host: 'localhost', port: 5432, database: 'test' };
|
|
22
|
+
(0, vitest_1.beforeEach)(() => {
|
|
23
|
+
connector = new postgres_connector_1.PostgresConnector();
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.it)('allows plain SELECT', async () => {
|
|
26
|
+
await (0, vitest_1.expect)(connector.executeQuery(config, 'SELECT 1')).resolves.not.toThrow();
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.it)('allows SELECT with WHERE', async () => {
|
|
29
|
+
await (0, vitest_1.expect)(connector.executeQuery(config, 'SELECT id FROM users WHERE active = true')).resolves.not.toThrow();
|
|
30
|
+
});
|
|
31
|
+
(0, vitest_1.it)('allows CTE (WITH ... SELECT)', async () => {
|
|
32
|
+
await (0, vitest_1.expect)(connector.executeQuery(config, 'WITH cte AS (SELECT 1 AS n) SELECT n FROM cte')).resolves.not.toThrow();
|
|
33
|
+
});
|
|
34
|
+
(0, vitest_1.it)('rejects INSERT', async () => {
|
|
35
|
+
await (0, vitest_1.expect)(connector.executeQuery(config, "INSERT INTO users VALUES (1)")).rejects.toThrow('Only SELECT queries are allowed');
|
|
36
|
+
});
|
|
37
|
+
(0, vitest_1.it)('rejects UPDATE', async () => {
|
|
38
|
+
await (0, vitest_1.expect)(connector.executeQuery(config, 'UPDATE users SET name = $1')).rejects.toThrow('Only SELECT queries are allowed');
|
|
39
|
+
});
|
|
40
|
+
(0, vitest_1.it)('rejects DELETE', async () => {
|
|
41
|
+
await (0, vitest_1.expect)(connector.executeQuery(config, 'DELETE FROM users')).rejects.toThrow('Only SELECT queries are allowed');
|
|
42
|
+
});
|
|
43
|
+
(0, vitest_1.it)('rejects DROP TABLE', async () => {
|
|
44
|
+
await (0, vitest_1.expect)(connector.executeQuery(config, 'DROP TABLE users')).rejects.toThrow('Only SELECT queries are allowed');
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.it)('rejects SELECT bypassed via block comment prefix', async () => {
|
|
47
|
+
await (0, vitest_1.expect)(connector.executeQuery(config, '/* trick */ DROP TABLE users')).rejects.toThrow('Only SELECT queries are allowed');
|
|
48
|
+
});
|
|
49
|
+
(0, vitest_1.it)('rejects invalid SQL', async () => {
|
|
50
|
+
await (0, vitest_1.expect)(connector.executeQuery(config, 'NOT VALID SQL !!!')).rejects.toThrow();
|
|
51
|
+
});
|
|
52
|
+
(0, vitest_1.it)('allows UNION ALL', async () => {
|
|
53
|
+
await (0, vitest_1.expect)(connector.executeQuery(config, 'SELECT 1 UNION ALL SELECT 2')).resolves.not.toThrow();
|
|
54
|
+
});
|
|
55
|
+
(0, vitest_1.it)('allows UNION', async () => {
|
|
56
|
+
await (0, vitest_1.expect)(connector.executeQuery(config, 'SELECT 1 UNION SELECT 2')).resolves.not.toThrow();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
(0, vitest_1.describe)('explainQuery', () => {
|
|
60
|
+
let connector;
|
|
61
|
+
const config = { type: 'postgresql', host: 'localhost', port: 5432, database: 'test' };
|
|
62
|
+
const fakePlan = [{ 'Plan': { 'Node Type': 'Seq Scan' } }];
|
|
63
|
+
(0, vitest_1.beforeEach)(() => {
|
|
64
|
+
connector = new postgres_connector_1.PostgresConnector();
|
|
65
|
+
vitest_1.vi.mocked(pg_1.Pool).mockImplementation(function () {
|
|
66
|
+
return {
|
|
67
|
+
query: vitest_1.vi.fn().mockResolvedValue({ rows: [{ 'QUERY PLAN': fakePlan }] }),
|
|
68
|
+
end: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
(0, vitest_1.it)('returns plan for a SELECT query without analyze', async () => {
|
|
73
|
+
const result = await connector.explainQuery(config, 'SELECT 1');
|
|
74
|
+
(0, vitest_1.expect)(result).toEqual({ plan: fakePlan });
|
|
75
|
+
});
|
|
76
|
+
(0, vitest_1.it)('uses EXPLAIN ANALYZE when analyze=true', async () => {
|
|
77
|
+
const mockQuery = vitest_1.vi.fn().mockResolvedValue({
|
|
78
|
+
rows: [{ 'QUERY PLAN': [{ ...fakePlan[0], 'Execution Time': 1.23 }] }],
|
|
79
|
+
});
|
|
80
|
+
vitest_1.vi.mocked(pg_1.Pool).mockImplementation(function () {
|
|
81
|
+
return {
|
|
82
|
+
query: mockQuery,
|
|
83
|
+
end: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
await connector.explainQuery(config, 'SELECT 1', true);
|
|
87
|
+
(0, vitest_1.expect)(mockQuery).toHaveBeenCalledWith(vitest_1.expect.stringContaining('ANALYZE'));
|
|
88
|
+
});
|
|
89
|
+
(0, vitest_1.it)('rejects non-SELECT in explain', async () => {
|
|
90
|
+
await (0, vitest_1.expect)(connector.explainQuery(config, 'DROP TABLE users')).rejects.toThrow('Only SELECT queries are allowed');
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
(0, vitest_1.describe)('getTopQueries', () => {
|
|
94
|
+
let connector;
|
|
95
|
+
const config = { type: 'postgresql', host: 'localhost', port: 5432, database: 'test' };
|
|
96
|
+
(0, vitest_1.beforeEach)(() => {
|
|
97
|
+
connector = new postgres_connector_1.PostgresConnector();
|
|
98
|
+
});
|
|
99
|
+
(0, vitest_1.it)('returns query rows on success', async () => {
|
|
100
|
+
const fakeRows = [{ query: 'SELECT 1', calls: 5, mean_exec_time: 10, total_exec_time: 50, rows: 5 }];
|
|
101
|
+
vitest_1.vi.mocked(pg_1.Pool).mockImplementation(function () {
|
|
102
|
+
return {
|
|
103
|
+
query: vitest_1.vi.fn().mockResolvedValue({ rows: fakeRows }),
|
|
104
|
+
end: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
const result = await connector.getTopQueries(config);
|
|
108
|
+
(0, vitest_1.expect)(result).toEqual(fakeRows);
|
|
109
|
+
});
|
|
110
|
+
(0, vitest_1.it)('returns error object when pg_stat_statements is not installed', async () => {
|
|
111
|
+
vitest_1.vi.mocked(pg_1.Pool).mockImplementation(function () {
|
|
112
|
+
return {
|
|
113
|
+
query: vitest_1.vi.fn().mockRejectedValue(Object.assign(new Error('relation "pg_stat_statements" does not exist'), { code: '42P01' })),
|
|
114
|
+
end: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
const result = await connector.getTopQueries(config);
|
|
118
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
119
|
+
error: 'pg_stat_statements not enabled. Run: CREATE EXTENSION pg_stat_statements',
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
(0, vitest_1.it)('uses mean_exec_time as default sort column', async () => {
|
|
123
|
+
const mockQuery = vitest_1.vi.fn().mockResolvedValue({ rows: [] });
|
|
124
|
+
vitest_1.vi.mocked(pg_1.Pool).mockImplementation(function () {
|
|
125
|
+
return {
|
|
126
|
+
query: mockQuery,
|
|
127
|
+
end: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
await connector.getTopQueries(config);
|
|
131
|
+
(0, vitest_1.expect)(mockQuery).toHaveBeenCalledWith(vitest_1.expect.stringContaining('mean_exec_time'));
|
|
132
|
+
});
|
|
133
|
+
(0, vitest_1.it)('respects custom limit and sortBy', async () => {
|
|
134
|
+
const mockQuery = vitest_1.vi.fn().mockResolvedValue({ rows: [] });
|
|
135
|
+
vitest_1.vi.mocked(pg_1.Pool).mockImplementation(function () {
|
|
136
|
+
return {
|
|
137
|
+
query: mockQuery,
|
|
138
|
+
end: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
await connector.getTopQueries(config, 5, 'calls');
|
|
142
|
+
const sql = mockQuery.mock.calls[0][0];
|
|
143
|
+
(0, vitest_1.expect)(sql).toContain('calls');
|
|
144
|
+
(0, vitest_1.expect)(sql).toContain('5');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
(0, vitest_1.describe)('getDbHealth', () => {
|
|
148
|
+
let connector;
|
|
149
|
+
const config = { type: 'postgresql', host: 'localhost', port: 5432, database: 'test' };
|
|
150
|
+
(0, vitest_1.it)('returns all 5 health check keys', async () => {
|
|
151
|
+
connector = new postgres_connector_1.PostgresConnector();
|
|
152
|
+
vitest_1.vi.mocked(pg_1.Pool).mockImplementation(function () {
|
|
153
|
+
return {
|
|
154
|
+
query: vitest_1.vi.fn().mockResolvedValue({ rows: [] }),
|
|
155
|
+
end: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
const result = await connector.getDbHealth(config);
|
|
159
|
+
(0, vitest_1.expect)(result).toHaveProperty('duplicateIndexes');
|
|
160
|
+
(0, vitest_1.expect)(result).toHaveProperty('unusedIndexes');
|
|
161
|
+
(0, vitest_1.expect)(result).toHaveProperty('connections');
|
|
162
|
+
(0, vitest_1.expect)(result).toHaveProperty('vacuumNeeded');
|
|
163
|
+
(0, vitest_1.expect)(result).toHaveProperty('invalidConstraints');
|
|
164
|
+
});
|
|
165
|
+
(0, vitest_1.it)('still returns other checks when one query throws', async () => {
|
|
166
|
+
connector = new postgres_connector_1.PostgresConnector();
|
|
167
|
+
let callCount = 0;
|
|
168
|
+
vitest_1.vi.mocked(pg_1.Pool).mockImplementation(function () {
|
|
169
|
+
return {
|
|
170
|
+
query: vitest_1.vi.fn().mockImplementation(() => {
|
|
171
|
+
callCount++;
|
|
172
|
+
if (callCount === 2)
|
|
173
|
+
throw new Error('permission denied');
|
|
174
|
+
return Promise.resolve({ rows: [] });
|
|
175
|
+
}),
|
|
176
|
+
end: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
const result = await connector.getDbHealth(config);
|
|
180
|
+
(0, vitest_1.expect)(result).toHaveProperty('duplicateIndexes');
|
|
181
|
+
(0, vitest_1.expect)(result).toHaveProperty('vacuumNeeded');
|
|
182
|
+
});
|
|
183
|
+
(0, vitest_1.it)('returns connection usage percentage', async () => {
|
|
184
|
+
connector = new postgres_connector_1.PostgresConnector();
|
|
185
|
+
vitest_1.vi.mocked(pg_1.Pool).mockImplementation(function () {
|
|
186
|
+
return {
|
|
187
|
+
query: vitest_1.vi.fn().mockResolvedValue({
|
|
188
|
+
rows: [{ active: '8', max: '100' }],
|
|
189
|
+
}),
|
|
190
|
+
end: vitest_1.vi.fn().mockResolvedValue(undefined),
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
const result = await connector.getDbHealth(config);
|
|
194
|
+
(0, vitest_1.expect)(result.connections.usagePct).toBe(8);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=postgres.connector.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.connector.test.js","sourceRoot":"","sources":["../../../../src/datasource/connectors/postgres.connector.test.ts"],"names":[],"mappings":";;AAA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,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACnD,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;QAClD,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,IAAA,WAAE,EAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;QACnD,SAAS,GAAG,IAAI,sCAAiB,EAAE,CAAC;QACpC,WAAE,CAAC,MAAM,CAAC,SAAI,CAAC,CAAC,kBAAkB,CAAC;YACjC,OAAO;gBACL,KAAK,EAAE,WAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;oBAC/B,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;iBACpC,CAAC;gBACF,GAAG,EAAE,WAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;aACnC,CAAC;QACX,CAAC,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACnD,IAAA,eAAM,EAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DataSourceService } from './datasource.service';
|
|
2
|
+
import { DataSourceConfig } from './datasource.model';
|
|
3
|
+
export declare class DataSourceController {
|
|
4
|
+
private readonly service;
|
|
5
|
+
constructor(service: DataSourceService);
|
|
6
|
+
save(type: string, body: Omit<DataSourceConfig, 'type'>): {
|
|
7
|
+
success: boolean;
|
|
8
|
+
};
|
|
9
|
+
find(type: string): Omit<DataSourceConfig, "password"> | {
|
|
10
|
+
configured: boolean;
|
|
11
|
+
};
|
|
12
|
+
test(type: string): Promise<{
|
|
13
|
+
connected: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
schema(type: string): Promise<import("./datasource.model").DatabaseSchema>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.DataSourceController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const datasource_service_1 = require("./datasource.service");
|
|
18
|
+
const VALID_TYPES = ['postgresql', 'mongodb'];
|
|
19
|
+
function validateType(type) {
|
|
20
|
+
if (!VALID_TYPES.includes(type)) {
|
|
21
|
+
throw new common_1.BadRequestException(`Invalid datasource type: ${type}. Must be one of: ${VALID_TYPES.join(', ')}`);
|
|
22
|
+
}
|
|
23
|
+
return type;
|
|
24
|
+
}
|
|
25
|
+
let DataSourceController = class DataSourceController {
|
|
26
|
+
constructor(service) {
|
|
27
|
+
this.service = service;
|
|
28
|
+
}
|
|
29
|
+
save(type, body) {
|
|
30
|
+
const validType = validateType(type);
|
|
31
|
+
this.service.save({ ...body, type: validType });
|
|
32
|
+
return { success: true };
|
|
33
|
+
}
|
|
34
|
+
find(type) {
|
|
35
|
+
return this.service.find(validateType(type)) ?? { configured: false };
|
|
36
|
+
}
|
|
37
|
+
async test(type) {
|
|
38
|
+
const connected = await this.service.testConnection(validateType(type));
|
|
39
|
+
return { connected };
|
|
40
|
+
}
|
|
41
|
+
async schema(type) {
|
|
42
|
+
return this.service.getSchema(validateType(type));
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.DataSourceController = DataSourceController;
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, common_1.Post)(':type'),
|
|
48
|
+
__param(0, (0, common_1.Param)('type')),
|
|
49
|
+
__param(1, (0, common_1.Body)()),
|
|
50
|
+
__metadata("design:type", Function),
|
|
51
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
52
|
+
__metadata("design:returntype", void 0)
|
|
53
|
+
], DataSourceController.prototype, "save", null);
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, common_1.Get)(':type'),
|
|
56
|
+
__param(0, (0, common_1.Param)('type')),
|
|
57
|
+
__metadata("design:type", Function),
|
|
58
|
+
__metadata("design:paramtypes", [String]),
|
|
59
|
+
__metadata("design:returntype", void 0)
|
|
60
|
+
], DataSourceController.prototype, "find", null);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, common_1.Post)(':type/test'),
|
|
63
|
+
__param(0, (0, common_1.Param)('type')),
|
|
64
|
+
__metadata("design:type", Function),
|
|
65
|
+
__metadata("design:paramtypes", [String]),
|
|
66
|
+
__metadata("design:returntype", Promise)
|
|
67
|
+
], DataSourceController.prototype, "test", null);
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, common_1.Get)(':type/schema'),
|
|
70
|
+
__param(0, (0, common_1.Param)('type')),
|
|
71
|
+
__metadata("design:type", Function),
|
|
72
|
+
__metadata("design:paramtypes", [String]),
|
|
73
|
+
__metadata("design:returntype", Promise)
|
|
74
|
+
], DataSourceController.prototype, "schema", null);
|
|
75
|
+
exports.DataSourceController = DataSourceController = __decorate([
|
|
76
|
+
(0, common_1.Controller)('datasource'),
|
|
77
|
+
__metadata("design:paramtypes", [datasource_service_1.DataSourceService])
|
|
78
|
+
], DataSourceController);
|
|
79
|
+
//# sourceMappingURL=datasource.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource.controller.js","sourceRoot":"","sources":["../../../src/datasource/datasource.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAyF;AACzF,6DAAyD;AAGzD,MAAM,WAAW,GAAqB,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;AAEhE,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAsB,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,4BAAmB,CAAC,4BAA4B,IAAI,qBAAqB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/G,CAAC;IACD,OAAO,IAAsB,CAAC;AAChC,CAAC;AAGM,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B,YAA6B,OAA0B;QAA1B,YAAO,GAAP,OAAO,CAAmB;IAAG,CAAC;IAG3D,IAAI,CAAgB,IAAY,EAAU,IAAoC;QAC5E,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IAGD,IAAI,CAAgB,IAAY;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IACxE,CAAC;IAGK,AAAN,KAAK,CAAC,IAAI,CAAgB,IAAY;QACpC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;QACxE,OAAO,EAAE,SAAS,EAAE,CAAC;IACvB,CAAC;IAGK,AAAN,KAAK,CAAC,MAAM,CAAgB,IAAY;QACtC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IACpD,CAAC;CACF,CAAA;AAzBY,oDAAoB;AAI/B;IADC,IAAA,aAAI,EAAC,OAAO,CAAC;IACR,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;IAAgB,WAAA,IAAA,aAAI,GAAE,CAAA;;;;gDAIxC;AAGD;IADC,IAAA,YAAG,EAAC,OAAO,CAAC;IACP,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;;;;gDAElB;AAGK;IADL,IAAA,aAAI,EAAC,YAAY,CAAC;IACP,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;;;;gDAGxB;AAGK;IADL,IAAA,YAAG,EAAC,cAAc,CAAC;IACN,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;;;;kDAE1B;+BAxBU,oBAAoB;IADhC,IAAA,mBAAU,EAAC,YAAY,CAAC;qCAEe,sCAAiB;GAD5C,oBAAoB,CAyBhC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type DataSourceType = 'postgresql' | 'mongodb';
|
|
2
|
+
export interface DataSourceConfig {
|
|
3
|
+
type: DataSourceType;
|
|
4
|
+
host: string;
|
|
5
|
+
port: number;
|
|
6
|
+
database: string;
|
|
7
|
+
username?: string;
|
|
8
|
+
password?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface DataSourcesFile {
|
|
11
|
+
postgresql?: DataSourceConfig;
|
|
12
|
+
mongodb?: DataSourceConfig;
|
|
13
|
+
}
|
|
14
|
+
export interface FieldSchema {
|
|
15
|
+
name: string;
|
|
16
|
+
type: string;
|
|
17
|
+
nullable: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface TableSchema {
|
|
20
|
+
name: string;
|
|
21
|
+
fields: FieldSchema[];
|
|
22
|
+
}
|
|
23
|
+
export interface DatabaseSchema {
|
|
24
|
+
type: DataSourceType;
|
|
25
|
+
tables: TableSchema[];
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource.model.js","sourceRoot":"","sources":["../../../src/datasource/datasource.model.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DataSourceModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const datasource_controller_1 = require("./datasource.controller");
|
|
12
|
+
const datasource_service_1 = require("./datasource.service");
|
|
13
|
+
const datasource_repository_1 = require("./datasource.repository");
|
|
14
|
+
const postgres_connector_1 = require("./connectors/postgres.connector");
|
|
15
|
+
const mongo_connector_1 = require("./connectors/mongo.connector");
|
|
16
|
+
let DataSourceModule = class DataSourceModule {
|
|
17
|
+
};
|
|
18
|
+
exports.DataSourceModule = DataSourceModule;
|
|
19
|
+
exports.DataSourceModule = DataSourceModule = __decorate([
|
|
20
|
+
(0, common_1.Module)({
|
|
21
|
+
controllers: [datasource_controller_1.DataSourceController],
|
|
22
|
+
providers: [
|
|
23
|
+
datasource_service_1.DataSourceService,
|
|
24
|
+
datasource_repository_1.DataSourceRepository,
|
|
25
|
+
postgres_connector_1.PostgresConnector,
|
|
26
|
+
mongo_connector_1.MongoConnector,
|
|
27
|
+
],
|
|
28
|
+
exports: [datasource_service_1.DataSourceService],
|
|
29
|
+
})
|
|
30
|
+
], DataSourceModule);
|
|
31
|
+
//# sourceMappingURL=datasource.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource.module.js","sourceRoot":"","sources":["../../../src/datasource/datasource.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,mEAA+D;AAC/D,6DAAyD;AACzD,mEAA+D;AAC/D,wEAAoE;AACpE,kEAA8D;AAYvD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,4CAAgB;2BAAhB,gBAAgB;IAV5B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,4CAAoB,CAAC;QACnC,SAAS,EAAE;YACT,sCAAiB;YACjB,4CAAoB;YACpB,sCAAiB;YACjB,gCAAc;SACf;QACD,OAAO,EAAE,CAAC,sCAAiB,CAAC;KAC7B,CAAC;GACW,gBAAgB,CAAG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DataSourceConfig, DataSourceType, DataSourcesFile } from './datasource.model';
|
|
2
|
+
export declare class DataSourceRepository {
|
|
3
|
+
save(config: DataSourceConfig): void;
|
|
4
|
+
find(type: DataSourceType, connectionName?: string): DataSourceConfig | undefined;
|
|
5
|
+
findAllForType(type: DataSourceType): Array<{
|
|
6
|
+
name: string;
|
|
7
|
+
config: DataSourceConfig;
|
|
8
|
+
}>;
|
|
9
|
+
findAll(): DataSourcesFile;
|
|
10
|
+
private normalize;
|
|
11
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DataSourceRepository = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const connection_repository_1 = require("../connection/connection.repository");
|
|
12
|
+
const connectionRepo = new connection_repository_1.ConnectionRepository();
|
|
13
|
+
let DataSourceRepository = class DataSourceRepository {
|
|
14
|
+
save(config) {
|
|
15
|
+
const existing = connectionRepo.findActive(config.type);
|
|
16
|
+
if (existing) {
|
|
17
|
+
const { type: _, ...cfg } = config;
|
|
18
|
+
connectionRepo.update(existing.id, { config: cfg });
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const { type: _, ...cfg } = config;
|
|
22
|
+
connectionRepo.create({ type: config.type, name: config.type, config: cfg });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
find(type, connectionName) {
|
|
26
|
+
const conn = connectionName
|
|
27
|
+
? connectionRepo.findByType(type).find((c) => c.active && c.name === connectionName)
|
|
28
|
+
: connectionRepo.findActive(type);
|
|
29
|
+
if (!conn)
|
|
30
|
+
return undefined;
|
|
31
|
+
return this.normalize(type, conn.config);
|
|
32
|
+
}
|
|
33
|
+
findAllForType(type) {
|
|
34
|
+
return connectionRepo
|
|
35
|
+
.findByType(type)
|
|
36
|
+
.filter((c) => c.active)
|
|
37
|
+
.map((c) => ({ name: c.name, config: this.normalize(type, c.config) }));
|
|
38
|
+
}
|
|
39
|
+
findAll() {
|
|
40
|
+
const result = {};
|
|
41
|
+
for (const type of ['postgresql', 'mongodb']) {
|
|
42
|
+
const cfg = this.find(type);
|
|
43
|
+
if (cfg)
|
|
44
|
+
result[type] = cfg;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
normalize(type, raw) {
|
|
49
|
+
const cfg = { ...raw };
|
|
50
|
+
if (cfg.user && !cfg.username) {
|
|
51
|
+
cfg.username = cfg.user;
|
|
52
|
+
delete cfg.user;
|
|
53
|
+
}
|
|
54
|
+
return { type, ...cfg };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.DataSourceRepository = DataSourceRepository;
|
|
58
|
+
exports.DataSourceRepository = DataSourceRepository = __decorate([
|
|
59
|
+
(0, common_1.Injectable)()
|
|
60
|
+
], DataSourceRepository);
|
|
61
|
+
//# sourceMappingURL=datasource.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource.repository.js","sourceRoot":"","sources":["../../../src/datasource/datasource.repository.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAE5C,+EAA2E;AAE3E,MAAM,cAAc,GAAG,IAAI,4CAAoB,EAAE,CAAC;AAG3C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B,IAAI,CAAC,MAAwB;QAC3B,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACxD,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,MAAM,CAAC;YACnC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QACtD,CAAC;aAAM,CAAC;YACN,MAAM,EAAE,IAAI,EAAE,CA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,GAAG,GAAG,CAAC;QAC9B,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,SAAS,CAAC,IAAoB,EAAE,GAAQ;QAC9C,MAAM,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;QACvB,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC9B,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAC;YACxB,OAAO,GAAG,CAAC,IAAI,CAAC;QAClB,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,GAAG,GAAG,EAAsB,CAAC;IAC9C,CAAC;CACF,CAAA;AA9CY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CA8ChC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DataSourceRepository } from './datasource.repository';
|
|
2
|
+
import { PostgresConnector, ExplainResult, TopQueriesResult, DbHealthResult } from './connectors/postgres.connector';
|
|
3
|
+
import { MongoConnector, MongoExplainResult, MongoCountResult, MongoStatsResult, MongoIndexResult } from './connectors/mongo.connector';
|
|
4
|
+
import { DataSourceConfig, DataSourceType, DatabaseSchema } from './datasource.model';
|
|
5
|
+
export declare class DataSourceService {
|
|
6
|
+
private readonly repository;
|
|
7
|
+
private readonly postgresConnector;
|
|
8
|
+
private readonly mongoConnector;
|
|
9
|
+
constructor(repository: DataSourceRepository, postgresConnector: PostgresConnector, mongoConnector: MongoConnector);
|
|
10
|
+
save(config: DataSourceConfig): void;
|
|
11
|
+
find(type: DataSourceType): Omit<DataSourceConfig, 'password'> | undefined;
|
|
12
|
+
testConnection(type: DataSourceType, connectionName?: string): Promise<boolean>;
|
|
13
|
+
getSchema(type: DataSourceType, connectionName?: string): Promise<DatabaseSchema>;
|
|
14
|
+
executeQuery(type: DataSourceType, query: string, connectionName?: string): Promise<unknown[]>;
|
|
15
|
+
explainQuery(sql: string, analyze?: boolean, connectionName?: string): Promise<ExplainResult>;
|
|
16
|
+
getTopQueries(limit?: number, sortBy?: string, connectionName?: string): Promise<TopQueriesResult>;
|
|
17
|
+
getDbHealth(connectionName?: string): Promise<DbHealthResult>;
|
|
18
|
+
mongoExplainQuery(collection: string, filter?: object, verbosity?: string, connectionName?: string): Promise<MongoExplainResult>;
|
|
19
|
+
mongoCountDocuments(collection: string, filter?: object, connectionName?: string): Promise<MongoCountResult>;
|
|
20
|
+
mongoGetStats(collection?: string, connectionName?: string): Promise<MongoStatsResult>;
|
|
21
|
+
mongoListIndexes(collection: string, connectionName?: string): Promise<MongoIndexResult[]>;
|
|
22
|
+
listConnections(type: DataSourceType): Array<{
|
|
23
|
+
name: string;
|
|
24
|
+
config: DataSourceConfig;
|
|
25
|
+
}>;
|
|
26
|
+
private getConfigOrThrow;
|
|
27
|
+
private getConnector;
|
|
28
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DataSourceService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const datasource_repository_1 = require("./datasource.repository");
|
|
15
|
+
const postgres_connector_1 = require("./connectors/postgres.connector");
|
|
16
|
+
const mongo_connector_1 = require("./connectors/mongo.connector");
|
|
17
|
+
let DataSourceService = class DataSourceService {
|
|
18
|
+
constructor(repository, postgresConnector, mongoConnector) {
|
|
19
|
+
this.repository = repository;
|
|
20
|
+
this.postgresConnector = postgresConnector;
|
|
21
|
+
this.mongoConnector = mongoConnector;
|
|
22
|
+
}
|
|
23
|
+
save(config) {
|
|
24
|
+
this.repository.save(config);
|
|
25
|
+
}
|
|
26
|
+
find(type) {
|
|
27
|
+
const config = this.repository.find(type);
|
|
28
|
+
if (!config)
|
|
29
|
+
return undefined;
|
|
30
|
+
const { password: _, ...rest } = config;
|
|
31
|
+
return rest;
|
|
32
|
+
}
|
|
33
|
+
async testConnection(type, connectionName) {
|
|
34
|
+
const config = this.getConfigOrThrow(type, connectionName);
|
|
35
|
+
return this.getConnector(type).testConnection(config);
|
|
36
|
+
}
|
|
37
|
+
async getSchema(type, connectionName) {
|
|
38
|
+
const config = this.getConfigOrThrow(type, connectionName);
|
|
39
|
+
return this.getConnector(type).getSchema(config);
|
|
40
|
+
}
|
|
41
|
+
async executeQuery(type, query, connectionName) {
|
|
42
|
+
const config = this.getConfigOrThrow(type, connectionName);
|
|
43
|
+
return this.getConnector(type).executeQuery(config, query);
|
|
44
|
+
}
|
|
45
|
+
async explainQuery(sql, analyze, connectionName) {
|
|
46
|
+
const config = this.getConfigOrThrow('postgresql', connectionName);
|
|
47
|
+
return this.postgresConnector.explainQuery(config, sql, analyze);
|
|
48
|
+
}
|
|
49
|
+
async getTopQueries(limit, sortBy, connectionName) {
|
|
50
|
+
const config = this.getConfigOrThrow('postgresql', connectionName);
|
|
51
|
+
return this.postgresConnector.getTopQueries(config, limit, sortBy);
|
|
52
|
+
}
|
|
53
|
+
async getDbHealth(connectionName) {
|
|
54
|
+
const config = this.getConfigOrThrow('postgresql', connectionName);
|
|
55
|
+
return this.postgresConnector.getDbHealth(config);
|
|
56
|
+
}
|
|
57
|
+
async mongoExplainQuery(collection, filter, verbosity, connectionName) {
|
|
58
|
+
const config = this.getConfigOrThrow('mongodb', connectionName);
|
|
59
|
+
return this.mongoConnector.explainQuery(config, collection, filter, verbosity);
|
|
60
|
+
}
|
|
61
|
+
async mongoCountDocuments(collection, filter, connectionName) {
|
|
62
|
+
const config = this.getConfigOrThrow('mongodb', connectionName);
|
|
63
|
+
return this.mongoConnector.countDocuments(config, collection, filter);
|
|
64
|
+
}
|
|
65
|
+
async mongoGetStats(collection, connectionName) {
|
|
66
|
+
const config = this.getConfigOrThrow('mongodb', connectionName);
|
|
67
|
+
return this.mongoConnector.getStats(config, collection);
|
|
68
|
+
}
|
|
69
|
+
async mongoListIndexes(collection, connectionName) {
|
|
70
|
+
const config = this.getConfigOrThrow('mongodb', connectionName);
|
|
71
|
+
return this.mongoConnector.listIndexes(config, collection);
|
|
72
|
+
}
|
|
73
|
+
listConnections(type) {
|
|
74
|
+
return this.repository.findAllForType(type);
|
|
75
|
+
}
|
|
76
|
+
getConfigOrThrow(type, connectionName) {
|
|
77
|
+
const config = this.repository.find(type, connectionName);
|
|
78
|
+
if (!config) {
|
|
79
|
+
const suffix = connectionName ? ` (connection: ${connectionName})` : '';
|
|
80
|
+
throw new common_1.NotFoundException(`No ${type} datasource configured${suffix}`);
|
|
81
|
+
}
|
|
82
|
+
return config;
|
|
83
|
+
}
|
|
84
|
+
getConnector(type) {
|
|
85
|
+
return type === 'postgresql' ? this.postgresConnector : this.mongoConnector;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
exports.DataSourceService = DataSourceService;
|
|
89
|
+
exports.DataSourceService = DataSourceService = __decorate([
|
|
90
|
+
(0, common_1.Injectable)(),
|
|
91
|
+
__metadata("design:paramtypes", [datasource_repository_1.DataSourceRepository,
|
|
92
|
+
postgres_connector_1.PostgresConnector,
|
|
93
|
+
mongo_connector_1.MongoConnector])
|
|
94
|
+
], DataSourceService);
|
|
95
|
+
//# sourceMappingURL=datasource.service.js.map
|
|
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AC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;IAC9E,CAAC;CACF,CAAA;AAnGY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAGoB,4CAAoB;QACb,sCAAiB;QACpB,gCAAc;GAJtC,iBAAiB,CAmG7B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExampleService } from './example.service';
|
|
2
|
+
import { Datasource } from './example.model';
|
|
3
|
+
export declare class ExampleController {
|
|
4
|
+
private readonly service;
|
|
5
|
+
constructor(service: ExampleService);
|
|
6
|
+
getHealth(): {
|
|
7
|
+
status: string;
|
|
8
|
+
};
|
|
9
|
+
getDatasources(): Datasource[];
|
|
10
|
+
}
|