@pi-r/mssql 0.6.1 → 0.6.3
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/README.md +2 -0
- package/client/index.js +30 -13
- package/package.json +4 -4
- package/types/index.d.ts +1 -3
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -111,6 +111,10 @@ function convertType(sql, type, value, options) {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
function getPoolKey(credential) {
|
|
114
|
+
const auth = credential.authentication?.options;
|
|
115
|
+
if (!credential.server || !(auth?.userName && auth.password)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
114
118
|
const tls = credential.options?.cryptoCredentialsDetails;
|
|
115
119
|
if (tls) {
|
|
116
120
|
if (!(0, types_1.isObject)(tls)) {
|
|
@@ -118,16 +122,21 @@ function getPoolKey(credential) {
|
|
|
118
122
|
}
|
|
119
123
|
else if (tls.ca || tls.cert || tls.key) {
|
|
120
124
|
credential = { ...credential };
|
|
125
|
+
if ('uuidKey' in credential) {
|
|
126
|
+
delete credential.uuidKey;
|
|
127
|
+
}
|
|
121
128
|
credential.options = { ...credential.options };
|
|
122
129
|
delete credential.options.cryptoCredentialsDetails;
|
|
123
130
|
return JSON.stringify(credential) + '_tls';
|
|
124
131
|
}
|
|
125
132
|
}
|
|
133
|
+
if ('uuidKey' in credential) {
|
|
134
|
+
credential = { ...credential };
|
|
135
|
+
delete credential.uuidKey;
|
|
136
|
+
}
|
|
126
137
|
return JSON.stringify(credential);
|
|
127
138
|
}
|
|
128
|
-
|
|
129
|
-
return (0, types_1.isPlainObject)(params) && Object.keys(params).length === 2 && 'input' in params && 'output' in params;
|
|
130
|
-
}
|
|
139
|
+
const isOutputParameters = (params) => (0, types_1.isPlainObject)(params) && Object.keys(params).length === 2 && 'input' in params && 'output' in params;
|
|
131
140
|
function setCredential(item) {
|
|
132
141
|
let credential = this.getCredential(item), hostname, username, password, port, database;
|
|
133
142
|
if (credential) {
|
|
@@ -195,18 +204,19 @@ function setCredential(item) {
|
|
|
195
204
|
}
|
|
196
205
|
let pool;
|
|
197
206
|
password = undefined;
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
pool
|
|
207
|
+
if ((0, types_1.isString)(usePool)) {
|
|
208
|
+
if (username = authOptions.userName) {
|
|
209
|
+
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
210
|
+
if (pool) {
|
|
211
|
+
pool.add(item, password);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (!password) {
|
|
216
|
+
item.usePool = '';
|
|
202
217
|
return;
|
|
203
218
|
}
|
|
204
219
|
}
|
|
205
|
-
const poolKey = getPoolKey(credential);
|
|
206
|
-
if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
|
|
207
|
-
pool.add(item);
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
220
|
const config = this.getPoolConfig("mssql" /* STRINGS.MODULE_NAME */, password);
|
|
211
221
|
const poolConfig = (0, types_1.isPlainObject)(item.usePool) ? item.usePool : {};
|
|
212
222
|
if (config) {
|
|
@@ -224,6 +234,11 @@ function setCredential(item) {
|
|
|
224
234
|
poolConfig.acquireTimeout ?? (poolConfig.acquireTimeout = queue_idle);
|
|
225
235
|
}
|
|
226
236
|
}
|
|
237
|
+
const poolKey = getPoolKey(credential);
|
|
238
|
+
if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
|
|
239
|
+
pool.add(item);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
227
242
|
new MSSQLPool(new TediousPool(poolConfig, credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
228
243
|
}
|
|
229
244
|
exports.setCredential = setCredential;
|
|
@@ -407,7 +422,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
407
422
|
if (isOutputParameters(params)) {
|
|
408
423
|
({ input: params, output: paramsOutput } = params);
|
|
409
424
|
}
|
|
410
|
-
|
|
425
|
+
if (params) {
|
|
426
|
+
convertParameters.call(request, tedious.TYPES, params, false);
|
|
427
|
+
}
|
|
411
428
|
if (paramsOutput) {
|
|
412
429
|
convertParameters.call(request, tedious.TYPES, paramsOutput, true);
|
|
413
430
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mssql",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "MSSQL client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
13
|
"directory": "src/db/mssql"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@e-mc/db": "^0.8.
|
|
25
|
-
"@e-mc/types": "^0.8.
|
|
24
|
+
"@e-mc/db": "^0.8.3",
|
|
25
|
+
"@e-mc/types": "^0.8.3",
|
|
26
26
|
"tedious": "^16.6.1",
|
|
27
27
|
"tedious-connection-pool2": "^2.1.0"
|
|
28
28
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -2,9 +2,7 @@ import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
|
2
2
|
|
|
3
3
|
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
4
|
|
|
5
|
-
// @ts-ignore
|
|
6
5
|
import type { ConnectionConfig, ParameterOptions, TediousType, TediousTypes } from 'tedious';
|
|
7
|
-
// @ts-ignore
|
|
8
6
|
import type { PoolConfig } from 'tedious-connection-pool';
|
|
9
7
|
|
|
10
8
|
export interface MSSQLDataSource extends DbDataSource<string, unknown, unknown, string | MSSQLCredential, string | PoolConfig>, ExecuteAction<MSSQLRequestParameters | MSSQLRequestWithOutputParameters> {
|
|
@@ -26,4 +24,4 @@ export interface MSSQLRequestParameterValue {
|
|
|
26
24
|
options?: ParameterOptions;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
export type MSSQLRequestParameters =
|
|
27
|
+
export type MSSQLRequestParameters = MSSQLRequestParameterValue[] | Record<string, Omit<MSSQLRequestParameterValue, "name">> | null;
|