@heyhru/business-dms-datasource 0.6.0 → 0.7.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/dist/datasources.service.d.ts +7 -0
- package/dist/datasources.service.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.mjs +11 -1
- package/package.json +4 -4
|
@@ -6,6 +6,13 @@ interface AuthenticatedRequest extends FastifyRequest {
|
|
|
6
6
|
}
|
|
7
7
|
import type { DbPool } from "@heyhru/server-plugin-mysql";
|
|
8
8
|
export type { DbPool };
|
|
9
|
+
export interface PoolStatEntry {
|
|
10
|
+
dataSourceId: string;
|
|
11
|
+
database: string | null;
|
|
12
|
+
active: number | null;
|
|
13
|
+
waiting: number | null;
|
|
14
|
+
}
|
|
15
|
+
export declare function getPoolStats(): PoolStatEntry[];
|
|
9
16
|
export declare function getPool(ds: {
|
|
10
17
|
id: string;
|
|
11
18
|
type: "mysql" | "postgres";
|
|
@@ -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;IACnD,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;CACtB;AAID,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAW1D,YAAY,EAAE,MAAM,EAAE,CAAC;
|
|
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;IACnD,IAAI,EAAE;QAAE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AE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAE7E;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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { getPool, getDataSourceWithPassword, getPoolForDatabase, datasourceList, datasourceGet, datasourceCreate, datasourceUpdate, datasourceDelete, } from "./datasources.service.js";
|
|
1
|
+
export { getPool, getDataSourceWithPassword, 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,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,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
|
@@ -27,7 +27,8 @@ __export(index_exports, {
|
|
|
27
27
|
datasourceUpdate: () => datasourceUpdate,
|
|
28
28
|
getDataSourceWithPassword: () => getDataSourceWithPassword,
|
|
29
29
|
getPool: () => getPool,
|
|
30
|
-
getPoolForDatabase: () => getPoolForDatabase
|
|
30
|
+
getPoolForDatabase: () => getPoolForDatabase,
|
|
31
|
+
getPoolStats: () => getPoolStats
|
|
31
32
|
});
|
|
32
33
|
module.exports = __toCommonJS(index_exports);
|
|
33
34
|
|
|
@@ -114,6 +115,15 @@ function removeDataSource(id) {
|
|
|
114
115
|
// src/datasources.service.ts
|
|
115
116
|
var logger = (0, import_common_util_logger.createLogger)({ name: "@heyhru/business-dms-datasource" });
|
|
116
117
|
var pools = /* @__PURE__ */ new Map();
|
|
118
|
+
function getPoolStats() {
|
|
119
|
+
return Array.from(pools.entries()).map(([key, pool]) => {
|
|
120
|
+
const colonIdx = key.indexOf(":");
|
|
121
|
+
const dataSourceId = colonIdx >= 0 ? key.slice(0, colonIdx) : key;
|
|
122
|
+
const database = colonIdx >= 0 ? key.slice(colonIdx + 1) : null;
|
|
123
|
+
const s = pool.stats();
|
|
124
|
+
return { dataSourceId, database, active: s?.active ?? null, waiting: s?.waiting ?? null };
|
|
125
|
+
});
|
|
126
|
+
}
|
|
117
127
|
function poolKey(id, database) {
|
|
118
128
|
return database ? `${id}:${database}` : id;
|
|
119
129
|
}
|
|
@@ -218,5 +228,6 @@ async function datasourceDelete(req, reply) {
|
|
|
218
228
|
datasourceUpdate,
|
|
219
229
|
getDataSourceWithPassword,
|
|
220
230
|
getPool,
|
|
221
|
-
getPoolForDatabase
|
|
231
|
+
getPoolForDatabase,
|
|
232
|
+
getPoolStats
|
|
222
233
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -81,6 +81,15 @@ function removeDataSource(id) {
|
|
|
81
81
|
// src/datasources.service.ts
|
|
82
82
|
var logger = createLogger({ name: "@heyhru/business-dms-datasource" });
|
|
83
83
|
var pools = /* @__PURE__ */ new Map();
|
|
84
|
+
function getPoolStats() {
|
|
85
|
+
return Array.from(pools.entries()).map(([key, pool]) => {
|
|
86
|
+
const colonIdx = key.indexOf(":");
|
|
87
|
+
const dataSourceId = colonIdx >= 0 ? key.slice(0, colonIdx) : key;
|
|
88
|
+
const database = colonIdx >= 0 ? key.slice(colonIdx + 1) : null;
|
|
89
|
+
const s = pool.stats();
|
|
90
|
+
return { dataSourceId, database, active: s?.active ?? null, waiting: s?.waiting ?? null };
|
|
91
|
+
});
|
|
92
|
+
}
|
|
84
93
|
function poolKey(id, database) {
|
|
85
94
|
return database ? `${id}:${database}` : id;
|
|
86
95
|
}
|
|
@@ -184,5 +193,6 @@ export {
|
|
|
184
193
|
datasourceUpdate,
|
|
185
194
|
getDataSourceWithPassword,
|
|
186
195
|
getPool,
|
|
187
|
-
getPoolForDatabase
|
|
196
|
+
getPoolForDatabase,
|
|
197
|
+
getPoolStats
|
|
188
198
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.7.1",
|
|
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",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@heyhru/common-util-logger": "0.6.0",
|
|
30
|
-
"@heyhru/server-plugin-mysql": "0.
|
|
31
|
-
"@heyhru/server-plugin-pg": "0.
|
|
30
|
+
"@heyhru/server-plugin-mysql": "0.7.0",
|
|
31
|
+
"@heyhru/server-plugin-pg": "0.7.0",
|
|
32
32
|
"@heyhru/server-util-crypto": "0.6.0",
|
|
33
33
|
"fastify": "^5.8.4"
|
|
34
34
|
},
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"typescript": "^6.0.2",
|
|
38
38
|
"vitest": "^4.1.4"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "b20e6c3e571bd4939fd32ece8f5bc6d8302a4c83"
|
|
41
41
|
}
|