@heyhru/business-dms-datasource 0.7.2 → 0.8.0
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/dist/datasources.model.d.ts +1 -1
- package/dist/datasources.model.d.ts.map +1 -1
- package/dist/datasources.service.d.ts +3 -1
- package/dist/datasources.service.d.ts.map +1 -1
- package/dist/datasources.sql.d.ts +1 -0
- package/dist/datasources.sql.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -4
- package/dist/index.mjs +17 -4
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function listDataSources(): Promise<Record<string, unknown>[]>;
|
|
1
|
+
export declare function listDataSources(testOnly?: boolean): Promise<Record<string, unknown>[]>;
|
|
2
2
|
export declare function getDataSourceById(id: string): Promise<Record<string, unknown> | undefined>;
|
|
3
3
|
export declare function getDataSourceRow(id: string): Promise<Record<string, unknown> | undefined>;
|
|
4
4
|
export declare function insertDataSource(data: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasources.model.d.ts","sourceRoot":"","sources":["../src/datasources.model.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,
|
|
1
|
+
{"version":3,"file":"datasources.model.d.ts","sourceRoot":"","sources":["../src/datasources.model.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,CAAC,QAAQ,UAAQ,sCAE/C;AAED,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,gDAE3C;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,gDAE1C;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE;IACJ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,EACD,iBAAiB,EAAE,MAAM,EACzB,SAAS,EAAE,MAAM,gDAelB;AAED,wBAAsB,gBAAgB,CACpC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,iBAAiB,CAAC,EAAE,MAAM,gDAoB3B;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM;;GAE1C"}
|
|
@@ -2,6 +2,7 @@ import { type FastifyRequest, type FastifyReply } from "fastify";
|
|
|
2
2
|
interface AuthenticatedRequest extends FastifyRequest {
|
|
3
3
|
user: {
|
|
4
4
|
id: string;
|
|
5
|
+
role: string;
|
|
5
6
|
};
|
|
6
7
|
}
|
|
7
8
|
import type { DbPool } from "@heyhru/server-plugin-mysql";
|
|
@@ -39,7 +40,8 @@ export interface DataSourceWithPassword {
|
|
|
39
40
|
pool_min: number;
|
|
40
41
|
pool_max: number;
|
|
41
42
|
}
|
|
42
|
-
export declare function datasourceList(
|
|
43
|
+
export declare function datasourceList(req: FastifyRequest, reply: FastifyReply): Promise<never>;
|
|
44
|
+
export declare function getDataSourceName(id: string): Promise<string | null>;
|
|
43
45
|
export declare function datasourceGet(req: FastifyRequest, reply: FastifyReply): Promise<never>;
|
|
44
46
|
export declare function datasourceCreate(encryptionKey: string): (req: AuthenticatedRequest, reply: FastifyReply) => Promise<never>;
|
|
45
47
|
export declare function datasourceUpdate(encryptionKey: string): (req: FastifyRequest, reply: FastifyReply) => Promise<never>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasources.service.d.ts","sourceRoot":"","sources":["../src/datasources.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjE,UAAU,oBAAqB,SAAQ,cAAc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Q,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAIxB;AAaD,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAID,wBAAsB,cAAc,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAI5E;AAED,wBAAsB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAG1E;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAK3E;AAED,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,IACtC,KAAK,oBAAoB,EAAE,OAAO,YAAY,oBAoB7D;AAED,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,IACtC,KAAK,cAAc,EAAE,OAAO,YAAY,oBAavD;AAED,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAK9E"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const LIST = "\nSELECT id, name, type, host, port, database, username, ssl, pool_min, pool_max, created_by, created_at\nFROM data_sources\nORDER BY created_at DESC";
|
|
2
|
+
export declare const LIST_TEST_ONLY = "\nSELECT id, name, type, host, port, database, username, ssl, pool_min, pool_max, created_by, created_at\nFROM data_sources\nWHERE name LIKE '%-test%'\nORDER BY created_at DESC";
|
|
2
3
|
export declare const FIND_BY_ID = "\nSELECT id, name, type, host, port, database, username, ssl, pool_min, pool_max, created_by, created_at\nFROM data_sources\nWHERE id = ?";
|
|
3
4
|
export declare const FIND_WITH_PASSWORD = "\nSELECT *\nFROM data_sources\nWHERE id = ?";
|
|
4
5
|
export declare const CREATE = "\nINSERT INTO data_sources (name, type, host, port, database, username, password_encrypted, ssl, pool_min, pool_max, created_by)\nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\nRETURNING id, name, type, host, port, database, username, ssl, pool_min, pool_max, created_by, created_at";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasources.sql.d.ts","sourceRoot":"","sources":["../src/datasources.sql.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,0JAGQ,CAAC;AAE1B,eAAO,MAAM,UAAU,8IAGV,CAAC;AAEd,eAAO,MAAM,kBAAkB,gDAGlB,CAAC;AAEd,eAAO,MAAM,MAAM,0RAGuF,CAAC;AAE3G,eAAO,MAAM,aAAa,UAA0F,CAAC;AAErH,eAAO,MAAM,MAAM,6CAEN,CAAC"}
|
|
1
|
+
{"version":3,"file":"datasources.sql.d.ts","sourceRoot":"","sources":["../src/datasources.sql.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,0JAGQ,CAAC;AAE1B,eAAO,MAAM,cAAc,qLAIF,CAAC;AAE1B,eAAO,MAAM,UAAU,8IAGV,CAAC;AAEd,eAAO,MAAM,kBAAkB,gDAGlB,CAAC;AAEd,eAAO,MAAM,MAAM,0RAGuF,CAAC;AAE3G,eAAO,MAAM,aAAa,UAA0F,CAAC;AAErH,eAAO,MAAM,MAAM,6CAEN,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { getPool, getDataSourceWithPassword, getPoolForDatabase, getPoolStats, datasourceList, datasourceGet, datasourceCreate, datasourceUpdate, datasourceDelete, } from "./datasources.service.js";
|
|
1
|
+
export { getPool, getDataSourceWithPassword, getDataSourceName, getPoolForDatabase, getPoolStats, datasourceList, datasourceGet, datasourceCreate, datasourceUpdate, datasourceDelete, } from "./datasources.service.js";
|
|
2
2
|
export type { DbPool, DataSourceWithPassword } from "./datasources.service.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,yBAAyB,EACzB,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAElC,YAAY,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,yBAAyB,EACzB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAElC,YAAY,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
datasourceGet: () => datasourceGet,
|
|
26
26
|
datasourceList: () => datasourceList,
|
|
27
27
|
datasourceUpdate: () => datasourceUpdate,
|
|
28
|
+
getDataSourceName: () => getDataSourceName,
|
|
28
29
|
getDataSourceWithPassword: () => getDataSourceWithPassword,
|
|
29
30
|
getPool: () => getPool,
|
|
30
31
|
getPoolForDatabase: () => getPoolForDatabase,
|
|
@@ -46,6 +47,11 @@ var LIST = `
|
|
|
46
47
|
SELECT id, name, type, host, port, database, username, ssl, pool_min, pool_max, created_by, created_at
|
|
47
48
|
FROM data_sources
|
|
48
49
|
ORDER BY created_at DESC`;
|
|
50
|
+
var LIST_TEST_ONLY = `
|
|
51
|
+
SELECT id, name, type, host, port, database, username, ssl, pool_min, pool_max, created_by, created_at
|
|
52
|
+
FROM data_sources
|
|
53
|
+
WHERE name LIKE '%-test%'
|
|
54
|
+
ORDER BY created_at DESC`;
|
|
49
55
|
var FIND_BY_ID = `
|
|
50
56
|
SELECT id, name, type, host, port, database, username, ssl, pool_min, pool_max, created_by, created_at
|
|
51
57
|
FROM data_sources
|
|
@@ -64,8 +70,8 @@ DELETE FROM data_sources
|
|
|
64
70
|
WHERE id = ?`;
|
|
65
71
|
|
|
66
72
|
// src/datasources.model.ts
|
|
67
|
-
function listDataSources() {
|
|
68
|
-
return (0, import_server_plugin_pg.getPgDb)().query(LIST);
|
|
73
|
+
function listDataSources(testOnly = false) {
|
|
74
|
+
return (0, import_server_plugin_pg.getPgDb)().query(testOnly ? LIST_TEST_ONLY : LIST);
|
|
69
75
|
}
|
|
70
76
|
function getDataSourceById(id) {
|
|
71
77
|
return (0, import_server_plugin_pg.getPgDb)().queryOne(FIND_BY_ID, [id]);
|
|
@@ -182,8 +188,15 @@ async function destroyPool(id) {
|
|
|
182
188
|
}
|
|
183
189
|
}
|
|
184
190
|
}
|
|
185
|
-
|
|
186
|
-
|
|
191
|
+
var RESTRICTED_DS_ROLES = /* @__PURE__ */ new Set(["developer", "viewer"]);
|
|
192
|
+
async function datasourceList(req, reply) {
|
|
193
|
+
const role = req.user.role;
|
|
194
|
+
const testOnly = RESTRICTED_DS_ROLES.has(role);
|
|
195
|
+
return reply.send(await listDataSources(testOnly));
|
|
196
|
+
}
|
|
197
|
+
async function getDataSourceName(id) {
|
|
198
|
+
const row = await getDataSourceById(id);
|
|
199
|
+
return row ? row.name : null;
|
|
187
200
|
}
|
|
188
201
|
async function datasourceGet(req, reply) {
|
|
189
202
|
const { id } = req.body ?? {};
|
|
@@ -226,6 +239,7 @@ async function datasourceDelete(req, reply) {
|
|
|
226
239
|
datasourceGet,
|
|
227
240
|
datasourceList,
|
|
228
241
|
datasourceUpdate,
|
|
242
|
+
getDataSourceName,
|
|
229
243
|
getDataSourceWithPassword,
|
|
230
244
|
getPool,
|
|
231
245
|
getPoolForDatabase,
|
package/dist/index.mjs
CHANGED
|
@@ -12,6 +12,11 @@ var LIST = `
|
|
|
12
12
|
SELECT id, name, type, host, port, database, username, ssl, pool_min, pool_max, created_by, created_at
|
|
13
13
|
FROM data_sources
|
|
14
14
|
ORDER BY created_at DESC`;
|
|
15
|
+
var LIST_TEST_ONLY = `
|
|
16
|
+
SELECT id, name, type, host, port, database, username, ssl, pool_min, pool_max, created_by, created_at
|
|
17
|
+
FROM data_sources
|
|
18
|
+
WHERE name LIKE '%-test%'
|
|
19
|
+
ORDER BY created_at DESC`;
|
|
15
20
|
var FIND_BY_ID = `
|
|
16
21
|
SELECT id, name, type, host, port, database, username, ssl, pool_min, pool_max, created_by, created_at
|
|
17
22
|
FROM data_sources
|
|
@@ -30,8 +35,8 @@ DELETE FROM data_sources
|
|
|
30
35
|
WHERE id = ?`;
|
|
31
36
|
|
|
32
37
|
// src/datasources.model.ts
|
|
33
|
-
function listDataSources() {
|
|
34
|
-
return getPgDb().query(LIST);
|
|
38
|
+
function listDataSources(testOnly = false) {
|
|
39
|
+
return getPgDb().query(testOnly ? LIST_TEST_ONLY : LIST);
|
|
35
40
|
}
|
|
36
41
|
function getDataSourceById(id) {
|
|
37
42
|
return getPgDb().queryOne(FIND_BY_ID, [id]);
|
|
@@ -148,8 +153,15 @@ async function destroyPool(id) {
|
|
|
148
153
|
}
|
|
149
154
|
}
|
|
150
155
|
}
|
|
151
|
-
|
|
152
|
-
|
|
156
|
+
var RESTRICTED_DS_ROLES = /* @__PURE__ */ new Set(["developer", "viewer"]);
|
|
157
|
+
async function datasourceList(req, reply) {
|
|
158
|
+
const role = req.user.role;
|
|
159
|
+
const testOnly = RESTRICTED_DS_ROLES.has(role);
|
|
160
|
+
return reply.send(await listDataSources(testOnly));
|
|
161
|
+
}
|
|
162
|
+
async function getDataSourceName(id) {
|
|
163
|
+
const row = await getDataSourceById(id);
|
|
164
|
+
return row ? row.name : null;
|
|
153
165
|
}
|
|
154
166
|
async function datasourceGet(req, reply) {
|
|
155
167
|
const { id } = req.body ?? {};
|
|
@@ -191,6 +203,7 @@ export {
|
|
|
191
203
|
datasourceGet,
|
|
192
204
|
datasourceList,
|
|
193
205
|
datasourceUpdate,
|
|
206
|
+
getDataSourceName,
|
|
194
207
|
getDataSourceWithPassword,
|
|
195
208
|
getPool,
|
|
196
209
|
getPoolForDatabase,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.8.0",
|
|
7
7
|
"description": "DMS data source domain logic: service, model, sql, pool management",
|
|
8
8
|
"main": "./dist/index.js",
|
|
9
9
|
"module": "./dist/index.mjs",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"typescript": "^6.0.2",
|
|
38
38
|
"vitest": "^4.1.4"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "bea932bfa6fd932a7a27a305d74b4b01c2e4ebe3"
|
|
41
41
|
}
|