@pi-r/mssql 0.6.4 → 0.6.6

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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2024 An Pham
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
- ### @pi-r/mssql
1
+ # @pi-r/mssql
2
2
 
3
- https://e-mc.readthedocs.io/en/latest/db/mssql.html
3
+ ## Documentation
4
4
 
5
- ### LICENSE
5
+ - [E-mc](https://e-mc.readthedocs.io/en/latest/db/mssql.html)
6
+ - [squared](https://squared.readthedocs.io)
7
+
8
+ ## LICENSE
6
9
 
7
10
  MIT
package/client/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = void 0;
4
3
  const tedious = require("tedious");
5
4
  const types_1 = require("@e-mc/types");
@@ -181,7 +180,7 @@ function setCredential(item) {
181
180
  errors.push('authentication.options.password');
182
181
  }
183
182
  if (errors.length) {
184
- throw (0, types_1.errorMessage)("mssql" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
183
+ throw (0, types_1.errorMessage)("mssql", 'Not defined - ' + errors.join(' | '));
185
184
  }
186
185
  const options = credential.options;
187
186
  if (options) {
@@ -217,7 +216,7 @@ function setCredential(item) {
217
216
  return;
218
217
  }
219
218
  }
220
- const config = this.getPoolConfig("mssql" /* STRINGS.MODULE_NAME */, password);
219
+ const config = this.getPoolConfig("mssql", password);
221
220
  const poolConfig = (0, types_1.isPlainObject)(item.usePool) ? item.usePool : {};
222
221
  if (config) {
223
222
  const { min, max, idle, queue_idle } = config;
@@ -271,17 +270,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
271
270
  if (!parallel) {
272
271
  outResult || (outResult = new Array(length));
273
272
  }
274
- const caching = this.hasCache("mssql" /* STRINGS.MODULE_NAME */, sessionKey);
273
+ const caching = this.hasCache("mssql", sessionKey);
275
274
  const tasks = new Array(length);
276
275
  const clients = [];
277
276
  const pools = [];
278
277
  let mssqlPool, mssqlClient, mssqlCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
279
278
  const getConnection = async (item, credential) => {
280
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
279
+ item.transactionState = 64;
281
280
  let client;
282
281
  if (mssqlPool) {
283
282
  pools.push(client = await mssqlPool.getConnection());
284
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
283
+ item.transactionState &= ~64;
285
284
  return client;
286
285
  }
287
286
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -333,7 +332,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
333
332
  }
334
333
  mssqlCredential = credential;
335
334
  }
336
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
335
+ item.transactionState &= ~64;
337
336
  return client;
338
337
  };
339
338
  if (this.host?.username) {
@@ -343,7 +342,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
343
342
  const item = batch[i];
344
343
  const { source, query, ignoreCache } = item;
345
344
  let credential = mssqlCredential || onceCredential, error;
346
- if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials" /* ERR_DB.CREDENTIALS */)) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query" /* ERR_DB.QUERY */))) {
345
+ if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials")) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query"))) {
347
346
  if (this.handleFail(error, item, { errorQuery })) {
348
347
  if (!parallel) {
349
348
  tasks.length = 0;
@@ -359,8 +358,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
359
358
  }
360
359
  continue;
361
360
  }
362
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
363
- const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mssql" /* STRINGS.MODULE_NAME */, 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
361
+ item.transactionState = 1;
362
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mssql", 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
364
363
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
365
364
  let params = item.params, queryString = '';
366
365
  if (caching && ignoreCache !== true && !streamRow) {
@@ -374,7 +373,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
374
373
  else {
375
374
  outResult[i] = result;
376
375
  }
377
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
376
+ this.add(item, 4 | 128);
378
377
  continue;
379
378
  }
380
379
  if (!ignoreCache && outCacheMiss) {
@@ -408,7 +407,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
408
407
  reject(error);
409
408
  }
410
409
  else {
411
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
410
+ this.add(item, 4);
412
411
  if (output) {
413
412
  output.__recordset__ = 0;
414
413
  output.__returnvalue__ = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mssql",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "MSSQL client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -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.4",
25
- "@e-mc/types": "^0.8.4",
24
+ "@e-mc/db": "^0.8.7",
25
+ "@e-mc/types": "^0.8.7",
26
26
  "tedious": "^16.7.1",
27
27
  "tedious-connection-pool2": "^2.1.0"
28
28
  }
package/types/index.d.ts CHANGED
@@ -2,7 +2,9 @@ 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
5
6
  import type { ConnectionConfig, ParameterOptions, TediousType, TediousTypes } from 'tedious';
7
+ // @ts-ignore
6
8
  import type { PoolConfig } from 'tedious-connection-pool';
7
9
 
8
10
  export interface MSSQLDataSource extends DbDataSource<string, unknown, unknown, string | MSSQLCredential, string | PoolConfig>, ExecuteAction<MSSQLRequestParameters | MSSQLRequestWithOutputParameters> {