tedious 6.4.0 → 6.6.2

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.
Files changed (86) hide show
  1. package/lib/bulk-load.js +17 -22
  2. package/lib/connection.js +363 -251
  3. package/lib/connector.js +3 -1
  4. package/lib/data-type.js +111 -109
  5. package/lib/data-types/bigint.js +19 -7
  6. package/lib/data-types/binary.js +19 -10
  7. package/lib/data-types/bit.js +14 -4
  8. package/lib/data-types/bitn.js +26 -3
  9. package/lib/data-types/char.js +26 -13
  10. package/lib/data-types/date.js +18 -9
  11. package/lib/data-types/datetime.js +23 -5
  12. package/lib/data-types/datetime2.js +10 -22
  13. package/lib/data-types/datetimen.js +26 -3
  14. package/lib/data-types/datetimeoffset.js +11 -22
  15. package/lib/data-types/decimal.js +14 -6
  16. package/lib/data-types/decimaln.js +26 -5
  17. package/lib/data-types/float.js +14 -4
  18. package/lib/data-types/floatn.js +26 -3
  19. package/lib/data-types/image.js +12 -5
  20. package/lib/data-types/int.js +14 -4
  21. package/lib/data-types/intn.js +26 -3
  22. package/lib/data-types/money.js +14 -4
  23. package/lib/data-types/moneyn.js +26 -3
  24. package/lib/data-types/nchar.js +17 -6
  25. package/lib/data-types/ntext.js +26 -5
  26. package/lib/data-types/null.js +27 -3
  27. package/lib/data-types/numeric.js +14 -6
  28. package/lib/data-types/numericn.js +26 -5
  29. package/lib/data-types/nvarchar.js +20 -11
  30. package/lib/data-types/real.js +14 -4
  31. package/lib/data-types/smalldatetime.js +14 -4
  32. package/lib/data-types/smallint.js +14 -4
  33. package/lib/data-types/smallmoney.js +14 -4
  34. package/lib/data-types/sql-variant.js +23 -4
  35. package/lib/data-types/text.js +13 -7
  36. package/lib/data-types/time.js +9 -21
  37. package/lib/data-types/tinyint.js +14 -4
  38. package/lib/data-types/tvp.js +12 -3
  39. package/lib/data-types/udt.js +26 -3
  40. package/lib/data-types/uniqueidentifier.js +12 -5
  41. package/lib/data-types/varbinary.js +18 -8
  42. package/lib/data-types/varchar.js +19 -10
  43. package/lib/data-types/xml.js +26 -3
  44. package/lib/debug.js +3 -1
  45. package/lib/guid-parser.js +6 -6
  46. package/lib/incoming-message-stream.js +10 -7
  47. package/lib/instance-lookup.js +12 -6
  48. package/lib/library.js +6 -1
  49. package/lib/login7-payload.js +2 -3
  50. package/lib/message-io.js +14 -3
  51. package/lib/message.js +2 -3
  52. package/lib/metadata-parser.js +259 -136
  53. package/lib/ntlm-payload.js +12 -21
  54. package/lib/outgoing-message-stream.js +7 -6
  55. package/lib/packet.js +4 -5
  56. package/lib/prelogin-payload.js +3 -4
  57. package/lib/request.js +11 -11
  58. package/lib/rpcrequest-payload.js +28 -22
  59. package/lib/sender.js +25 -11
  60. package/lib/special-stored-procedure.js +9 -2
  61. package/lib/tds-versions.js +8 -2
  62. package/lib/tedious.js +75 -9
  63. package/lib/token/colmetadata-token-parser.js +20 -10
  64. package/lib/token/done-token-parser.js +32 -25
  65. package/lib/token/env-change-token-parser.js +50 -20
  66. package/lib/token/feature-ext-ack-parser.js +19 -14
  67. package/lib/token/fedauth-info-parser.js +17 -11
  68. package/lib/token/infoerror-token-parser.js +14 -14
  69. package/lib/token/loginack-token-parser.js +21 -12
  70. package/lib/token/nbcrow-token-parser.js +35 -23
  71. package/lib/token/order-token-parser.js +14 -7
  72. package/lib/token/returnstatus-token-parser.js +14 -7
  73. package/lib/token/returnvalue-token-parser.js +22 -11
  74. package/lib/token/row-token-parser.js +34 -22
  75. package/lib/token/sspi-token-parser.js +14 -8
  76. package/lib/token/stream-parser.js +95 -36
  77. package/lib/token/token-stream-parser.js +16 -10
  78. package/lib/token/token.js +396 -2
  79. package/lib/tracking-buffer/writable-tracking-buffer.js +37 -5
  80. package/lib/transaction.js +25 -16
  81. package/lib/transient-error-lookup.js +6 -1
  82. package/lib/value-parser.js +412 -315
  83. package/package.json +24 -21
  84. package/pull_request_template.md +1 -1
  85. package/tsconfig.json +1 -1
  86. package/lib/tracking-buffer/bigint.js +0 -102
package/lib/connection.js CHANGED
@@ -1,67 +1,64 @@
1
1
  "use strict";
2
2
 
3
- const crypto = require('crypto');
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
4
7
 
5
- const os = require('os'); // $FlowFixMe
8
+ var _crypto = _interopRequireDefault(require("crypto"));
6
9
 
10
+ var _os = _interopRequireDefault(require("os"));
7
11
 
8
- const constants = require('constants');
12
+ var _constants = _interopRequireDefault(require("constants"));
9
13
 
10
- const _require = require('tls'),
11
- createSecureContext = _require.createSecureContext;
14
+ var _tls = require("tls");
12
15
 
13
- const _require2 = require('@azure/ms-rest-nodeauth'),
14
- loginWithUsernamePassword = _require2.loginWithUsernamePassword,
15
- loginWithVmMSI = _require2.loginWithVmMSI,
16
- loginWithAppServiceMSI = _require2.loginWithAppServiceMSI;
16
+ var _msRestNodeauth = require("@azure/ms-rest-nodeauth");
17
17
 
18
- const BulkLoad = require('./bulk-load');
18
+ var _bulkLoad = _interopRequireDefault(require("./bulk-load"));
19
19
 
20
- const Debug = require('./debug');
20
+ var _debug = _interopRequireDefault(require("./debug"));
21
21
 
22
- const EventEmitter = require('events').EventEmitter;
22
+ var _events = require("events");
23
23
 
24
- const InstanceLookup = require('./instance-lookup').InstanceLookup;
24
+ var _instanceLookup = require("./instance-lookup");
25
25
 
26
- const TransientErrorLookup = require('./transient-error-lookup.js').TransientErrorLookup;
26
+ var _transientErrorLookup = require("./transient-error-lookup");
27
27
 
28
- const TYPE = require('./packet').TYPE;
28
+ var _packet = require("./packet");
29
29
 
30
- const PreloginPayload = require('./prelogin-payload');
30
+ var _preloginPayload = _interopRequireDefault(require("./prelogin-payload"));
31
31
 
32
- const Login7Payload = require('./login7-payload');
32
+ var _login7Payload = _interopRequireDefault(require("./login7-payload"));
33
33
 
34
- const NTLMResponsePayload = require('./ntlm-payload');
34
+ var _ntlmPayload = _interopRequireDefault(require("./ntlm-payload"));
35
35
 
36
- const Request = require('./request');
36
+ var _request = _interopRequireDefault(require("./request"));
37
37
 
38
- const RpcRequestPayload = require('./rpcrequest-payload');
38
+ var _rpcrequestPayload = _interopRequireDefault(require("./rpcrequest-payload"));
39
39
 
40
- const SqlBatchPayload = require('./sqlbatch-payload');
40
+ var _sqlbatchPayload = _interopRequireDefault(require("./sqlbatch-payload"));
41
41
 
42
- const MessageIO = require('./message-io');
42
+ var _messageIo = _interopRequireDefault(require("./message-io"));
43
43
 
44
- const TokenStreamParser = require('./token/token-stream-parser').Parser;
44
+ var _tokenStreamParser = require("./token/token-stream-parser");
45
45
 
46
- const Transaction = require('./transaction').Transaction;
46
+ var _transaction = require("./transaction");
47
47
 
48
- const ISOLATION_LEVEL = require('./transaction').ISOLATION_LEVEL;
48
+ var _errors = require("./errors");
49
49
 
50
- const ConnectionError = require('./errors').ConnectionError;
50
+ var _connector = require("./connector");
51
51
 
52
- const RequestError = require('./errors').RequestError;
52
+ var _library = require("./library");
53
53
 
54
- const Connector = require('./connector').Connector;
54
+ var _tdsVersions = require("./tds-versions");
55
55
 
56
- const libraryName = require('./library').name;
56
+ var _ntlm = require("./ntlm");
57
57
 
58
- const versions = require('./tds-versions').versions;
58
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
59
59
 
60
- const _require3 = require('./ntlm'),
61
- createNTLMRequest = _require3.createNTLMRequest; // A rather basic state machine for managing a connection.
60
+ // A rather basic state machine for managing a connection.
62
61
  // Implements something approximating s3.2.1.
63
-
64
-
65
62
  const KEEP_ALIVE_INITIAL_DELAY = 30 * 1000;
66
63
  const DEFAULT_CONNECT_TIMEOUT = 15 * 1000;
67
64
  const DEFAULT_CLIENT_REQUEST_TIMEOUT = 15 * 1000;
@@ -74,8 +71,13 @@ const DEFAULT_PORT = 1433;
74
71
  const DEFAULT_TDS_VERSION = '7_4';
75
72
  const DEFAULT_LANGUAGE = 'us_english';
76
73
  const DEFAULT_DATEFORMAT = 'mdy';
74
+ const CLEANUP_TYPE = {
75
+ NORMAL: 0,
76
+ REDIRECT: 1,
77
+ RETRY: 2
78
+ };
77
79
 
78
- class Connection extends EventEmitter {
80
+ class Connection extends _events.EventEmitter {
79
81
  constructor(config) {
80
82
  super();
81
83
 
@@ -103,8 +105,8 @@ class Connection extends EventEmitter {
103
105
  throw new TypeError('The "config.authentication.type" property must be of type string.');
104
106
  }
105
107
 
106
- if (type !== 'default' && type !== 'ntlm' && type !== 'azure-active-directory-password' && type !== 'azure-active-directory-access-token' && type !== 'azure-active-directory-msi-vm' && type !== 'azure-active-directory-msi-app-service') {
107
- throw new TypeError('The "type" property must one of "default", "ntlm", "azure-active-directory-password", "azure-active-directory-access-token", "azure-active-directory-msi-vm" or "azure-active-directory-msi-app-service".');
108
+ if (type !== 'default' && type !== 'ntlm' && type !== 'azure-active-directory-password' && type !== 'azure-active-directory-access-token' && type !== 'azure-active-directory-msi-vm' && type !== 'azure-active-directory-msi-app-service' && type !== 'azure-active-directory-service-principal-secret') {
109
+ throw new TypeError('The "type" property must one of "default", "ntlm", "azure-active-directory-password", "azure-active-directory-access-token", "azure-active-directory-msi-vm" or "azure-active-directory-msi-app-service" or "azure-active-directory-service-principal-secret".');
108
110
  }
109
111
 
110
112
  if (typeof options !== 'object' || options === null) {
@@ -196,6 +198,27 @@ class Connection extends EventEmitter {
196
198
  msiSecret: options.msiSecret
197
199
  }
198
200
  };
201
+ } else if (type === 'azure-active-directory-service-principal-secret') {
202
+ if (typeof options.clientId !== 'string') {
203
+ throw new TypeError('The "config.authentication.options.clientId" property must be of type string.');
204
+ }
205
+
206
+ if (typeof options.clientSecret !== 'string') {
207
+ throw new TypeError('The "config.authentication.options.clientSecret" property must be of type string.');
208
+ }
209
+
210
+ if (typeof options.tenantId !== 'string') {
211
+ throw new TypeError('The "config.authentication.options.tenantId" property must be of type string.');
212
+ }
213
+
214
+ authentication = {
215
+ type: 'azure-active-directory-service-principal-secret',
216
+ options: {
217
+ clientId: options.clientId,
218
+ clientSecret: options.clientSecret,
219
+ tenantId: options.tenantId
220
+ }
221
+ };
199
222
  } else {
200
223
  if (options.userName !== undefined && typeof options.userName !== 'string') {
201
224
  throw new TypeError('The "config.authentication.options.userName" property must be of type string.');
@@ -234,7 +257,7 @@ class Connection extends EventEmitter {
234
257
  columnNameReplacer: undefined,
235
258
  connectionRetryInterval: DEFAULT_CONNECT_RETRY_INTERVAL,
236
259
  connectTimeout: DEFAULT_CONNECT_TIMEOUT,
237
- connectionIsolationLevel: ISOLATION_LEVEL.READ_COMMITTED,
260
+ connectionIsolationLevel: _transaction.ISOLATION_LEVEL.READ_COMMITTED,
238
261
  cryptoCredentialsDetails: {},
239
262
  database: undefined,
240
263
  datefirst: DEFAULT_DATEFIRST,
@@ -258,7 +281,7 @@ class Connection extends EventEmitter {
258
281
  encrypt: false,
259
282
  fallbackToDefaultDb: false,
260
283
  instanceName: undefined,
261
- isolationLevel: ISOLATION_LEVEL.READ_COMMITTED,
284
+ isolationLevel: _transaction.ISOLATION_LEVEL.READ_COMMITTED,
262
285
  language: DEFAULT_LANGUAGE,
263
286
  localAddress: undefined,
264
287
  maxRetriesOnTransientErrors: 3,
@@ -688,35 +711,30 @@ class Connection extends EventEmitter {
688
711
  // As BEAST is a browser specific exploit, we can just disable this option here.
689
712
  credentialsDetails = Object.create(credentialsDetails, {
690
713
  secureOptions: {
691
- value: constants.SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
714
+ value: _constants.default.SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
692
715
  }
693
716
  });
694
717
  }
695
718
 
696
- this.secureContext = createSecureContext(credentialsDetails);
697
- this.createDebug();
698
- this.createTokenStreamParser();
719
+ this.secureContext = (0, _tls.createSecureContext)(credentialsDetails);
720
+ this.debug = this.createDebug();
721
+ this.tokenStreamParser = this.createTokenStreamParser();
699
722
  this.inTransaction = false;
700
- this.transactionDescriptors = [Buffer.from([0, 0, 0, 0, 0, 0, 0, 0])];
701
- this.transitionTo(this.STATE.CONNECTING);
702
-
703
- if (this.config.options.tdsVersion < '7_2') {
704
- // 'beginTransaction', 'commitTransaction' and 'rollbackTransaction'
705
- // events are utilized to maintain inTransaction property state which in
706
- // turn is used in managing transactions. These events are only fired for
707
- // TDS version 7.2 and beyond. The properties below are used to emulate
708
- // equivalent behavior for TDS versions before 7.2.
709
- this.transactionDepth = 0;
710
- this.isSqlBatch = false;
711
- }
712
-
723
+ this.transactionDescriptors = [Buffer.from([0, 0, 0, 0, 0, 0, 0, 0])]; // 'beginTransaction', 'commitTransaction' and 'rollbackTransaction'
724
+ // events are utilized to maintain inTransaction property state which in
725
+ // turn is used in managing transactions. These events are only fired for
726
+ // TDS version 7.2 and beyond. The properties below are used to emulate
727
+ // equivalent behavior for TDS versions before 7.2.
728
+
729
+ this.transactionDepth = 0;
730
+ this.isSqlBatch = false;
731
+ this.closed = false;
732
+ this.loggedIn = false;
733
+ this.messageBuffer = Buffer.alloc(0);
713
734
  this.curTransientRetryCount = 0;
714
- this.transientErrorLookup = new TransientErrorLookup();
715
- this.cleanupTypeEnum = {
716
- NORMAL: 0,
717
- REDIRECT: 1,
718
- RETRY: 2
719
- };
735
+ this.transientErrorLookup = new _transientErrorLookup.TransientErrorLookup();
736
+ this.state = this.STATE.CONNECTING;
737
+ this.state.enter.call(this);
720
738
  }
721
739
 
722
740
  close() {
@@ -728,16 +746,16 @@ class Connection extends EventEmitter {
728
746
  this.createConnectTimer();
729
747
  }
730
748
 
731
- cleanupConnection(cleanupTypeEnum) {
749
+ cleanupConnection(cleanupType) {
732
750
  if (!this.closed) {
733
751
  this.clearConnectTimer();
734
752
  this.clearRequestTimer();
735
753
  this.clearRetryTimer();
736
754
  this.closeConnection();
737
755
 
738
- if (cleanupTypeEnum === this.cleanupTypeEnum.REDIRECT) {
756
+ if (cleanupType === CLEANUP_TYPE.REDIRECT) {
739
757
  this.emit('rerouting');
740
- } else if (cleanupTypeEnum !== this.cleanupTypeEnum.RETRY) {
758
+ } else if (cleanupType !== CLEANUP_TYPE.RETRY) {
741
759
  process.nextTick(() => {
742
760
  this.emit('end');
743
761
  });
@@ -746,7 +764,7 @@ class Connection extends EventEmitter {
746
764
  const request = this.request;
747
765
 
748
766
  if (request) {
749
- const err = RequestError('Connection closed before request completed.', 'ECLOSE');
767
+ const err = (0, _errors.RequestError)('Connection closed before request completed.', 'ECLOSE');
750
768
  request.callback(err);
751
769
  this.request = undefined;
752
770
  }
@@ -758,18 +776,19 @@ class Connection extends EventEmitter {
758
776
  }
759
777
 
760
778
  createDebug() {
761
- this.debug = new Debug(this.config.options.debug);
762
- this.debug.on('debug', message => {
779
+ const debug = new _debug.default(this.config.options.debug);
780
+ debug.on('debug', message => {
763
781
  this.emit('debug', message);
764
782
  });
783
+ return debug;
765
784
  }
766
785
 
767
786
  createTokenStreamParser() {
768
- this.tokenStreamParser = new TokenStreamParser(this.debug, undefined, this.config.options);
769
- this.tokenStreamParser.on('infoMessage', token => {
787
+ const tokenStreamParser = new _tokenStreamParser.Parser(this.debug, undefined, this.config.options);
788
+ tokenStreamParser.on('infoMessage', token => {
770
789
  this.emit('infoMessage', token);
771
790
  });
772
- this.tokenStreamParser.on('sspichallenge', token => {
791
+ tokenStreamParser.on('sspichallenge', token => {
773
792
  if (token.ntlmpacket) {
774
793
  this.ntlmpacket = token.ntlmpacket;
775
794
  this.ntlmpacketBuffer = token.ntlmpacketBuffer;
@@ -777,7 +796,7 @@ class Connection extends EventEmitter {
777
796
 
778
797
  this.emit('sspichallenge', token);
779
798
  });
780
- this.tokenStreamParser.on('errorMessage', token => {
799
+ tokenStreamParser.on('errorMessage', token => {
781
800
  this.emit('errorMessage', token);
782
801
 
783
802
  if (this.loggedIn) {
@@ -785,7 +804,7 @@ class Connection extends EventEmitter {
785
804
 
786
805
  if (request) {
787
806
  if (!request.canceled) {
788
- const error = new RequestError(token.message, 'EREQUEST');
807
+ const error = new _errors.RequestError(token.message, 'EREQUEST');
789
808
  error.number = token.number;
790
809
  error.state = token.state;
791
810
  error.class = token.class;
@@ -796,7 +815,7 @@ class Connection extends EventEmitter {
796
815
  }
797
816
  }
798
817
  } else {
799
- const error = ConnectionError(token.message, 'ELOGIN');
818
+ const error = (0, _errors.ConnectionError)(token.message, 'ELOGIN');
800
819
  const isLoginErrorTransient = this.transientErrorLookup.isTransientError(token.number);
801
820
 
802
821
  if (isLoginErrorTransient && this.curTransientRetryCount !== this.config.options.maxRetriesOnTransientErrors) {
@@ -806,32 +825,32 @@ class Connection extends EventEmitter {
806
825
  this.loginError = error;
807
826
  }
808
827
  });
809
- this.tokenStreamParser.on('databaseChange', token => {
828
+ tokenStreamParser.on('databaseChange', token => {
810
829
  this.emit('databaseChange', token.newValue);
811
830
  });
812
- this.tokenStreamParser.on('languageChange', token => {
831
+ tokenStreamParser.on('languageChange', token => {
813
832
  this.emit('languageChange', token.newValue);
814
833
  });
815
- this.tokenStreamParser.on('charsetChange', token => {
834
+ tokenStreamParser.on('charsetChange', token => {
816
835
  this.emit('charsetChange', token.newValue);
817
836
  });
818
- this.tokenStreamParser.on('fedAuthInfo', token => {
837
+ tokenStreamParser.on('fedAuthInfo', token => {
819
838
  this.dispatchEvent('fedAuthInfo', token);
820
839
  });
821
- this.tokenStreamParser.on('featureExtAck', token => {
840
+ tokenStreamParser.on('featureExtAck', token => {
822
841
  this.dispatchEvent('featureExtAck', token);
823
842
  });
824
- this.tokenStreamParser.on('loginack', token => {
843
+ tokenStreamParser.on('loginack', token => {
825
844
  if (!token.tdsVersion) {
826
845
  // unsupported TDS version
827
- this.loginError = ConnectionError('Server responded with unknown TDS version.', 'ETDS');
846
+ this.loginError = (0, _errors.ConnectionError)('Server responded with unknown TDS version.', 'ETDS');
828
847
  this.loggedIn = false;
829
848
  return;
830
849
  }
831
850
 
832
851
  if (!token.interface) {
833
852
  // unsupported interface
834
- this.loginError = ConnectionError('Server responded with unsupported interface.', 'EINTERFACENOTSUPP');
853
+ this.loginError = (0, _errors.ConnectionError)('Server responded with unsupported interface.', 'EINTERFACENOTSUPP');
835
854
  this.loggedIn = false;
836
855
  return;
837
856
  } // use negotiated version
@@ -840,43 +859,41 @@ class Connection extends EventEmitter {
840
859
  this.config.options.tdsVersion = token.tdsVersion;
841
860
  this.loggedIn = true;
842
861
  });
843
- this.tokenStreamParser.on('routingChange', token => {
862
+ tokenStreamParser.on('routingChange', token => {
844
863
  this.routingData = token.newValue;
845
864
  this.dispatchEvent('routingChange');
846
865
  });
847
- this.tokenStreamParser.on('packetSizeChange', token => {
866
+ tokenStreamParser.on('packetSizeChange', token => {
848
867
  this.messageIo.packetSize(token.newValue);
849
868
  }); // A new top-level transaction was started. This is not fired
850
869
  // for nested transactions.
851
870
 
852
- this.tokenStreamParser.on('beginTransaction', token => {
871
+ tokenStreamParser.on('beginTransaction', token => {
853
872
  this.transactionDescriptors.push(token.newValue);
854
873
  this.inTransaction = true;
855
874
  }); // A top-level transaction was committed. This is not fired
856
875
  // for nested transactions.
857
876
 
858
- this.tokenStreamParser.on('commitTransaction', () => {
877
+ tokenStreamParser.on('commitTransaction', () => {
859
878
  this.transactionDescriptors.length = 1;
860
879
  this.inTransaction = false;
861
880
  }); // A top-level transaction was rolled back. This is not fired
862
881
  // for nested transactions. This is also fired if a batch
863
882
  // aborting error happened that caused a rollback.
864
883
 
865
- this.tokenStreamParser.on('rollbackTransaction', () => {
884
+ tokenStreamParser.on('rollbackTransaction', () => {
866
885
  this.transactionDescriptors.length = 1; // An outermost transaction was rolled back. Reset the transaction counter
867
886
 
868
887
  this.inTransaction = false;
869
888
  this.emit('rollbackTransaction');
870
889
  });
871
- this.tokenStreamParser.on('columnMetadata', token => {
890
+ tokenStreamParser.on('columnMetadata', token => {
872
891
  const request = this.request;
873
892
 
874
893
  if (request) {
875
894
  if (!request.canceled) {
876
- let columns;
877
-
878
895
  if (this.config.options.useColumnNames) {
879
- columns = {};
896
+ const columns = {};
880
897
 
881
898
  for (let j = 0, len = token.columns.length; j < len; j++) {
882
899
  const col = token.columns[j];
@@ -885,18 +902,18 @@ class Connection extends EventEmitter {
885
902
  columns[col.colName] = col;
886
903
  }
887
904
  }
905
+
906
+ request.emit('columnMetadata', columns);
888
907
  } else {
889
- columns = token.columns;
908
+ request.emit('columnMetadata', token.columns);
890
909
  }
891
-
892
- request.emit('columnMetadata', columns);
893
910
  }
894
911
  } else {
895
912
  this.emit('error', new Error("Received 'columnMetadata' when no sqlRequest is in progress"));
896
913
  this.close();
897
914
  }
898
915
  });
899
- this.tokenStreamParser.on('order', token => {
916
+ tokenStreamParser.on('order', token => {
900
917
  const request = this.request;
901
918
 
902
919
  if (request) {
@@ -908,7 +925,7 @@ class Connection extends EventEmitter {
908
925
  this.close();
909
926
  }
910
927
  });
911
- this.tokenStreamParser.on('row', token => {
928
+ tokenStreamParser.on('row', token => {
912
929
  const request = this.request;
913
930
 
914
931
  if (request) {
@@ -930,7 +947,7 @@ class Connection extends EventEmitter {
930
947
  this.close();
931
948
  }
932
949
  });
933
- this.tokenStreamParser.on('returnStatus', token => {
950
+ tokenStreamParser.on('returnStatus', token => {
934
951
  const request = this.request;
935
952
 
936
953
  if (request) {
@@ -940,16 +957,16 @@ class Connection extends EventEmitter {
940
957
  }
941
958
  }
942
959
  });
943
- this.tokenStreamParser.on('returnValue', token => {
960
+ tokenStreamParser.on('returnValue', token => {
944
961
  const request = this.request;
945
962
 
946
963
  if (request) {
947
964
  if (!request.canceled) {
948
- this.request.emit('returnValue', token.paramName, token.value, token.metadata);
965
+ request.emit('returnValue', token.paramName, token.value, token.metadata);
949
966
  }
950
967
  }
951
968
  });
952
- this.tokenStreamParser.on('doneProc', token => {
969
+ tokenStreamParser.on('doneProc', token => {
953
970
  const request = this.request;
954
971
 
955
972
  if (request) {
@@ -967,7 +984,7 @@ class Connection extends EventEmitter {
967
984
  }
968
985
  }
969
986
  });
970
- this.tokenStreamParser.on('doneInProc', token => {
987
+ tokenStreamParser.on('doneInProc', token => {
971
988
  const request = this.request;
972
989
 
973
990
  if (request) {
@@ -984,7 +1001,7 @@ class Connection extends EventEmitter {
984
1001
  }
985
1002
  }
986
1003
  });
987
- this.tokenStreamParser.on('done', token => {
1004
+ tokenStreamParser.on('done', token => {
988
1005
  const request = this.request;
989
1006
 
990
1007
  if (request) {
@@ -997,12 +1014,12 @@ class Connection extends EventEmitter {
997
1014
  // We assume this is the indication that an in-flight request was canceled.
998
1015
  if (token.sqlError && !request.error) {
999
1016
  this.clearCancelTimer();
1000
- request.error = RequestError('Canceled.', 'ECANCEL');
1017
+ request.error = (0, _errors.RequestError)('Canceled.', 'ECANCEL');
1001
1018
  }
1002
1019
  } else {
1003
1020
  if (token.sqlError && !request.error) {
1004
1021
  // check if the DONE_ERROR flags was set, but an ERROR token was not sent.
1005
- request.error = RequestError('An unknown error has occurred.', 'UNKNOWN');
1022
+ request.error = (0, _errors.RequestError)('An unknown error has occurred.', 'UNKNOWN');
1006
1023
  }
1007
1024
 
1008
1025
  request.emit('done', token.rowCount, token.more, request.rst);
@@ -1017,31 +1034,28 @@ class Connection extends EventEmitter {
1017
1034
  }
1018
1035
  }
1019
1036
  });
1020
- this.tokenStreamParser.on('endOfMessage', () => {
1037
+ tokenStreamParser.on('endOfMessage', () => {
1021
1038
  // EOM pseudo token received
1022
1039
  if (this.state === this.STATE.SENT_CLIENT_REQUEST) {
1023
1040
  this.dispatchEvent('endOfMessageMarkerReceived');
1024
1041
  }
1025
1042
  });
1026
- this.tokenStreamParser.on('resetConnection', () => {
1043
+ tokenStreamParser.on('resetConnection', () => {
1027
1044
  this.emit('resetConnection');
1028
1045
  });
1029
- this.tokenStreamParser.on('tokenStreamError', error => {
1030
- this.emit('error', error);
1031
- this.close();
1032
- });
1033
- this.tokenStreamParser.on('drain', () => {
1046
+ tokenStreamParser.on('drain', () => {
1034
1047
  // Bridge the release of backpressure from the token stream parser
1035
1048
  // transform to the packet stream transform.
1036
1049
  this.messageIo.resume();
1037
1050
  });
1051
+ return tokenStreamParser;
1038
1052
  }
1039
1053
 
1040
1054
  connect() {
1041
1055
  if (this.config.options.port) {
1042
1056
  return this.connectOnPort(this.config.options.port, this.config.options.multiSubnetFailover);
1043
1057
  } else {
1044
- return new InstanceLookup().instanceLookup({
1058
+ return new _instanceLookup.InstanceLookup().instanceLookup({
1045
1059
  server: this.config.server,
1046
1060
  instanceName: this.config.options.instanceName,
1047
1061
  timeout: this.config.options.connectTimeout
@@ -1051,7 +1065,7 @@ class Connection extends EventEmitter {
1051
1065
  }
1052
1066
 
1053
1067
  if (message) {
1054
- this.emit('connect', ConnectionError(message, 'EINSTLOOKUP'));
1068
+ this.emit('connect', (0, _errors.ConnectionError)(message, 'EINSTLOOKUP'));
1055
1069
  } else {
1056
1070
  this.connectOnPort(port, this.config.options.multiSubnetFailover);
1057
1071
  }
@@ -1065,7 +1079,7 @@ class Connection extends EventEmitter {
1065
1079
  port: this.routingData ? this.routingData.port : port,
1066
1080
  localAddress: this.config.options.localAddress
1067
1081
  };
1068
- new Connector(connectOpts, multiSubnetFailover).execute((err, socket) => {
1082
+ new _connector.Connector(connectOpts, multiSubnetFailover).execute((err, socket) => {
1069
1083
  if (err) {
1070
1084
  return this.socketError(err);
1071
1085
  }
@@ -1075,17 +1089,17 @@ class Connection extends EventEmitter {
1075
1089
  return;
1076
1090
  }
1077
1091
 
1078
- this.socket = socket;
1079
- this.socket.on('error', error => {
1092
+ socket.on('error', error => {
1080
1093
  this.socketError(error);
1081
1094
  });
1082
- this.socket.on('close', () => {
1095
+ socket.on('close', () => {
1083
1096
  this.socketClose();
1084
1097
  });
1085
- this.socket.on('end', () => {
1098
+ socket.on('end', () => {
1086
1099
  this.socketEnd();
1087
1100
  });
1088
- this.messageIo = new MessageIO(this.socket, this.config.options.packetSize, this.debug);
1101
+ socket.setKeepAlive(true, KEEP_ALIVE_INITIAL_DELAY);
1102
+ this.messageIo = new _messageIo.default(socket, this.config.options.packetSize, this.debug);
1089
1103
  this.messageIo.on('data', data => {
1090
1104
  this.dispatchEvent('data', data);
1091
1105
  });
@@ -1095,6 +1109,7 @@ class Connection extends EventEmitter {
1095
1109
  this.messageIo.on('secure', cleartext => {
1096
1110
  this.emit('secure', cleartext);
1097
1111
  });
1112
+ this.socket = socket;
1098
1113
  this.socketConnect();
1099
1114
  });
1100
1115
  }
@@ -1145,7 +1160,7 @@ class Connection extends EventEmitter {
1145
1160
  connectTimeout() {
1146
1161
  const message = `Failed to connect to ${this.config.server}${this.config.options.port ? `:${this.config.options.port}` : `\\${this.config.options.instanceName}`} in ${this.config.options.connectTimeout}ms`;
1147
1162
  this.debug.log(message);
1148
- this.emit('connect', ConnectionError(message, 'ETIMEOUT'));
1163
+ this.emit('connect', (0, _errors.ConnectionError)(message, 'ETIMEOUT'));
1149
1164
  this.connectTimer = undefined;
1150
1165
  this.dispatchEvent('connectTimeout');
1151
1166
  }
@@ -1153,7 +1168,7 @@ class Connection extends EventEmitter {
1153
1168
  cancelTimeout() {
1154
1169
  const message = `Failed to cancel request in ${this.config.options.cancelTimeout}ms`;
1155
1170
  this.debug.log(message);
1156
- this.dispatchEvent('socketError', ConnectionError(message, 'ETIMEOUT'));
1171
+ this.dispatchEvent('socketError', (0, _errors.ConnectionError)(message, 'ETIMEOUT'));
1157
1172
  }
1158
1173
 
1159
1174
  requestTimeout() {
@@ -1162,7 +1177,7 @@ class Connection extends EventEmitter {
1162
1177
  request.cancel();
1163
1178
  const timeout = request.timeout !== undefined ? request.timeout : this.config.options.requestTimeout;
1164
1179
  const message = 'Timeout: Request failed to complete in ' + timeout + 'ms';
1165
- request.error = RequestError(message, 'ETIMEOUT');
1180
+ request.error = (0, _errors.RequestError)(message, 'ETIMEOUT');
1166
1181
  }
1167
1182
 
1168
1183
  retryTimeout() {
@@ -1215,9 +1230,21 @@ class Connection extends EventEmitter {
1215
1230
  }
1216
1231
  }
1217
1232
 
1233
+ getEventHandler(eventName) {
1234
+ const handler = this.state.events[eventName];
1235
+
1236
+ if (!handler) {
1237
+ throw new Error(`No event '${eventName}' in state '${this.state.name}'`);
1238
+ }
1239
+
1240
+ return handler;
1241
+ }
1242
+
1218
1243
  dispatchEvent(eventName, ...args) {
1219
- if (this.state.events[eventName]) {
1220
- this.state.events[eventName].apply(this, args);
1244
+ const handler = this.state.events[eventName];
1245
+
1246
+ if (handler) {
1247
+ handler.apply(this, args);
1221
1248
  } else {
1222
1249
  this.emit('error', new Error(`No event '${eventName}' in state '${this.state.name}'`));
1223
1250
  this.close();
@@ -1228,18 +1255,17 @@ class Connection extends EventEmitter {
1228
1255
  if (this.state === this.STATE.CONNECTING || this.state === this.STATE.SENT_TLSSSLNEGOTIATION) {
1229
1256
  const message = `Failed to connect to ${this.config.server}:${this.config.options.port} - ${error.message}`;
1230
1257
  this.debug.log(message);
1231
- this.emit('connect', ConnectionError(message, 'ESOCKET'));
1258
+ this.emit('connect', (0, _errors.ConnectionError)(message, 'ESOCKET'));
1232
1259
  } else {
1233
1260
  const message = `Connection lost - ${error.message}`;
1234
1261
  this.debug.log(message);
1235
- this.emit('error', ConnectionError(message, 'ESOCKET'));
1262
+ this.emit('error', (0, _errors.ConnectionError)(message, 'ESOCKET'));
1236
1263
  }
1237
1264
 
1238
1265
  this.dispatchEvent('socketError', error);
1239
1266
  }
1240
1267
 
1241
1268
  socketConnect() {
1242
- this.socket.setKeepAlive(true, KEEP_ALIVE_INITIAL_DELAY);
1243
1269
  this.closed = false;
1244
1270
  this.debug.log('connected to ' + this.config.server + ':' + this.config.options.port);
1245
1271
  this.dispatchEvent('socketConnect');
@@ -1262,7 +1288,7 @@ class Connection extends EventEmitter {
1262
1288
  this.debug.log('Rerouting to ' + this.routingData.server + ':' + this.routingData.port);
1263
1289
  this.dispatchEvent('reconnect');
1264
1290
  } else if (this.state === this.STATE.TRANSIENT_FAILURE_RETRY) {
1265
- const server = this.routingData ? this.routingData.server : this.server;
1291
+ const server = this.routingData ? this.routingData.server : this.config.server;
1266
1292
  const port = this.routingData ? this.routingData.port : this.config.options.port;
1267
1293
  this.debug.log('Retry after transient failure connecting to ' + server + ':' + port);
1268
1294
  this.dispatchEvent('retry');
@@ -1272,10 +1298,10 @@ class Connection extends EventEmitter {
1272
1298
  }
1273
1299
 
1274
1300
  sendPreLogin() {
1275
- const payload = new PreloginPayload({
1301
+ const payload = new _preloginPayload.default({
1276
1302
  encrypt: this.config.options.encrypt
1277
1303
  });
1278
- this.messageIo.sendMessage(TYPE.PRELOGIN, payload.data);
1304
+ this.messageIo.sendMessage(_packet.TYPE.PRELOGIN, payload.data);
1279
1305
  this.debug.payload(function () {
1280
1306
  return payload.toString(' ');
1281
1307
  });
@@ -1290,8 +1316,8 @@ class Connection extends EventEmitter {
1290
1316
  }
1291
1317
 
1292
1318
  sendLogin7Packet() {
1293
- const payload = new Login7Payload({
1294
- tdsVersion: versions[this.config.options.tdsVersion],
1319
+ const payload = new _login7Payload.default({
1320
+ tdsVersion: _tdsVersions.versions[this.config.options.tdsVersion],
1295
1321
  packetSize: this.config.options.packetSize,
1296
1322
  clientProgVer: 0,
1297
1323
  clientPid: process.pid,
@@ -1320,6 +1346,7 @@ class Connection extends EventEmitter {
1320
1346
 
1321
1347
  case 'azure-active-directory-msi-vm':
1322
1348
  case 'azure-active-directory-msi-app-service':
1349
+ case 'azure-active-directory-service-principal-secret':
1323
1350
  payload.fedAuth = {
1324
1351
  type: 'ADAL',
1325
1352
  echo: this.fedAuthRequired,
@@ -1328,7 +1355,7 @@ class Connection extends EventEmitter {
1328
1355
  break;
1329
1356
 
1330
1357
  case 'ntlm':
1331
- payload.sspi = createNTLMRequest({
1358
+ payload.sspi = (0, _ntlm.createNTLMRequest)({
1332
1359
  domain: authentication.options.domain
1333
1360
  });
1334
1361
  break;
@@ -1338,17 +1365,17 @@ class Connection extends EventEmitter {
1338
1365
  payload.password = authentication.options.password;
1339
1366
  }
1340
1367
 
1341
- payload.hostname = os.hostname();
1368
+ payload.hostname = _os.default.hostname();
1342
1369
  payload.serverName = this.routingData ? this.routingData.server : this.config.server;
1343
1370
  payload.appName = this.config.options.appName || 'Tedious';
1344
- payload.libraryName = libraryName;
1371
+ payload.libraryName = _library.name;
1345
1372
  payload.language = this.config.options.language;
1346
1373
  payload.database = this.config.options.database;
1347
1374
  payload.clientId = Buffer.from([1, 2, 3, 4, 5, 6]);
1348
1375
  payload.readOnlyIntent = this.config.options.readOnlyIntent;
1349
1376
  payload.initDbFatal = !this.config.options.fallbackToDefaultDb;
1350
1377
  this.routingData = undefined;
1351
- this.messageIo.sendMessage(TYPE.LOGIN7, payload.toBuffer());
1378
+ this.messageIo.sendMessage(_packet.TYPE.LOGIN7, payload.toBuffer());
1352
1379
  this.debug.payload(function () {
1353
1380
  return payload.toString(' ');
1354
1381
  });
@@ -1361,7 +1388,7 @@ class Connection extends EventEmitter {
1361
1388
  offset = data.writeUInt32LE(accessTokenLen + 4, offset);
1362
1389
  offset = data.writeUInt32LE(accessTokenLen, offset);
1363
1390
  data.write(token, offset, 'ucs2');
1364
- this.messageIo.sendMessage(TYPE.FEDAUTH_TOKEN, data); // sent the fedAuth token message, the rest is similar to standard login 7
1391
+ this.messageIo.sendMessage(_packet.TYPE.FEDAUTH_TOKEN, data); // sent the fedAuth token message, the rest is similar to standard login 7
1365
1392
 
1366
1393
  this.transitionTo(this.STATE.SENT_LOGIN7_WITH_STANDARD_LOGIN);
1367
1394
  } // Returns false to apply backpressure.
@@ -1394,9 +1421,9 @@ class Connection extends EventEmitter {
1394
1421
  }
1395
1422
 
1396
1423
  sendInitialSql() {
1397
- const payload = new SqlBatchPayload(this.getInitialSql(), this.currentTransactionDescriptor(), this.config.options);
1424
+ const payload = new _sqlbatchPayload.default(this.getInitialSql(), this.currentTransactionDescriptor(), this.config.options);
1398
1425
  payload.getData(data => {
1399
- return this.messageIo.sendMessage(TYPE.SQL_BATCH, data);
1426
+ return this.messageIo.sendMessage(_packet.TYPE.SQL_BATCH, data);
1400
1427
  });
1401
1428
  }
1402
1429
 
@@ -1498,7 +1525,7 @@ class Connection extends EventEmitter {
1498
1525
  }
1499
1526
 
1500
1527
  execSqlBatch(request) {
1501
- this.makeRequest(request, TYPE.SQL_BATCH, new SqlBatchPayload(request.sqlTextOrProcedure, this.currentTransactionDescriptor(), this.config.options));
1528
+ this.makeRequest(request, _packet.TYPE.SQL_BATCH, new _sqlbatchPayload.default(request.sqlTextOrProcedure, this.currentTransactionDescriptor(), this.config.options));
1502
1529
  }
1503
1530
 
1504
1531
  execSql(request) {
@@ -1513,7 +1540,7 @@ class Connection extends EventEmitter {
1513
1540
  return;
1514
1541
  }
1515
1542
 
1516
- this.makeRequest(request, TYPE.RPC_REQUEST, new RpcRequestPayload(request, this.currentTransactionDescriptor(), this.config.options));
1543
+ this.makeRequest(request, _packet.TYPE.RPC_REQUEST, new _rpcrequestPayload.default(request, this.currentTransactionDescriptor(), this.config.options));
1517
1544
  }
1518
1545
  /**
1519
1546
  @function newBulkLoad
@@ -1524,25 +1551,29 @@ class Connection extends EventEmitter {
1524
1551
  @param {boolean} [options.keepNulls=false] - Honors null value passed, ignores the default values set on table.
1525
1552
  @param {boolean} [options.tableLock=false] - Places a bulk update(BU) lock on table while performing bulk load. Uses row locks by default.
1526
1553
  @param {callback} callback - Function to call after BulkLoad executes.
1527
- */
1554
+ */
1555
+
1528
1556
 
1557
+ newBulkLoad(table, callbackOrOptions, callback) {
1558
+ let options;
1529
1559
 
1530
- newBulkLoad(table, options, callback) {
1531
1560
  if (callback === undefined) {
1532
- callback = options;
1561
+ callback = callbackOrOptions;
1533
1562
  options = {};
1563
+ } else {
1564
+ options = callbackOrOptions;
1534
1565
  }
1535
1566
 
1536
1567
  if (typeof options !== 'object') {
1537
1568
  throw new TypeError('"options" argument must be an object');
1538
1569
  }
1539
1570
 
1540
- return new BulkLoad(table, this.config.options, options, callback);
1571
+ return new _bulkLoad.default(table, this.config.options, options, callback);
1541
1572
  }
1542
1573
 
1543
1574
  execBulkLoad(bulkLoad) {
1544
1575
  bulkLoad.executionStarted = true;
1545
- const request = new Request(bulkLoad.getBulkInsertSql(), error => {
1576
+ const request = new _request.default(bulkLoad.getBulkInsertSql(), error => {
1546
1577
  if (error) {
1547
1578
  if (error.code === 'UNKNOWN') {
1548
1579
  error.message += ' This is likely because the schema of the BulkLoad does not match the schema of the table you are attempting to insert into.';
@@ -1553,7 +1584,7 @@ class Connection extends EventEmitter {
1553
1584
  return;
1554
1585
  }
1555
1586
 
1556
- this.makeRequest(bulkLoad, TYPE.BULK_LOAD, undefined);
1587
+ this.makeRequest(bulkLoad, _packet.TYPE.BULK_LOAD);
1557
1588
  });
1558
1589
  bulkLoad.once('cancel', () => {
1559
1590
  request.cancel();
@@ -1563,12 +1594,12 @@ class Connection extends EventEmitter {
1563
1594
 
1564
1595
  prepare(request) {
1565
1596
  request.transformIntoPrepareRpc();
1566
- this.makeRequest(request, TYPE.RPC_REQUEST, new RpcRequestPayload(request, this.currentTransactionDescriptor(), this.config.options));
1597
+ this.makeRequest(request, _packet.TYPE.RPC_REQUEST, new _rpcrequestPayload.default(request, this.currentTransactionDescriptor(), this.config.options));
1567
1598
  }
1568
1599
 
1569
1600
  unprepare(request) {
1570
1601
  request.transformIntoUnprepareRpc();
1571
- this.makeRequest(request, TYPE.RPC_REQUEST, new RpcRequestPayload(request, this.currentTransactionDescriptor(), this.config.options));
1602
+ this.makeRequest(request, _packet.TYPE.RPC_REQUEST, new _rpcrequestPayload.default(request, this.currentTransactionDescriptor(), this.config.options));
1572
1603
  }
1573
1604
 
1574
1605
  execute(request, parameters) {
@@ -1583,7 +1614,7 @@ class Connection extends EventEmitter {
1583
1614
  return;
1584
1615
  }
1585
1616
 
1586
- this.makeRequest(request, TYPE.RPC_REQUEST, new RpcRequestPayload(request, this.currentTransactionDescriptor(), this.config.options));
1617
+ this.makeRequest(request, _packet.TYPE.RPC_REQUEST, new _rpcrequestPayload.default(request, this.currentTransactionDescriptor(), this.config.options));
1587
1618
  }
1588
1619
 
1589
1620
  callProcedure(request) {
@@ -1598,81 +1629,80 @@ class Connection extends EventEmitter {
1598
1629
  return;
1599
1630
  }
1600
1631
 
1601
- this.makeRequest(request, TYPE.RPC_REQUEST, new RpcRequestPayload(request, this.currentTransactionDescriptor(), this.config.options));
1632
+ this.makeRequest(request, _packet.TYPE.RPC_REQUEST, new _rpcrequestPayload.default(request, this.currentTransactionDescriptor(), this.config.options));
1602
1633
  }
1603
1634
 
1604
- beginTransaction(callback, name, isolationLevel) {
1605
- isolationLevel || (isolationLevel = this.config.options.isolationLevel);
1606
- const transaction = new Transaction(name || '', isolationLevel);
1635
+ beginTransaction(callback, name = '', isolationLevel = this.config.options.isolationLevel) {
1636
+ const transaction = new _transaction.Transaction(name, isolationLevel);
1607
1637
 
1608
1638
  if (this.config.options.tdsVersion < '7_2') {
1609
- return this.execSqlBatch(new Request('SET TRANSACTION ISOLATION LEVEL ' + transaction.isolationLevelToTSQL() + ';BEGIN TRAN ' + transaction.name, (...args) => {
1639
+ return this.execSqlBatch(new _request.default('SET TRANSACTION ISOLATION LEVEL ' + transaction.isolationLevelToTSQL() + ';BEGIN TRAN ' + transaction.name, err => {
1610
1640
  this.transactionDepth++;
1611
1641
 
1612
1642
  if (this.transactionDepth === 1) {
1613
1643
  this.inTransaction = true;
1614
1644
  }
1615
1645
 
1616
- callback(...args);
1646
+ callback(err);
1617
1647
  }));
1618
1648
  }
1619
1649
 
1620
- const request = new Request(undefined, err => {
1650
+ const request = new _request.default(undefined, err => {
1621
1651
  return callback(err, this.currentTransactionDescriptor());
1622
1652
  });
1623
- return this.makeRequest(request, TYPE.TRANSACTION_MANAGER, transaction.beginPayload(this.currentTransactionDescriptor()));
1653
+ return this.makeRequest(request, _packet.TYPE.TRANSACTION_MANAGER, transaction.beginPayload(this.currentTransactionDescriptor()));
1624
1654
  }
1625
1655
 
1626
- commitTransaction(callback, name) {
1627
- const transaction = new Transaction(name || '');
1656
+ commitTransaction(callback, name = '') {
1657
+ const transaction = new _transaction.Transaction(name);
1628
1658
 
1629
1659
  if (this.config.options.tdsVersion < '7_2') {
1630
- return this.execSqlBatch(new Request('COMMIT TRAN ' + transaction.name, (...args) => {
1660
+ return this.execSqlBatch(new _request.default('COMMIT TRAN ' + transaction.name, err => {
1631
1661
  this.transactionDepth--;
1632
1662
 
1633
1663
  if (this.transactionDepth === 0) {
1634
1664
  this.inTransaction = false;
1635
1665
  }
1636
1666
 
1637
- callback(...args);
1667
+ callback(err);
1638
1668
  }));
1639
1669
  }
1640
1670
 
1641
- const request = new Request(undefined, callback);
1642
- return this.makeRequest(request, TYPE.TRANSACTION_MANAGER, transaction.commitPayload(this.currentTransactionDescriptor()));
1671
+ const request = new _request.default(undefined, callback);
1672
+ return this.makeRequest(request, _packet.TYPE.TRANSACTION_MANAGER, transaction.commitPayload(this.currentTransactionDescriptor()));
1643
1673
  }
1644
1674
 
1645
- rollbackTransaction(callback, name) {
1646
- const transaction = new Transaction(name || '');
1675
+ rollbackTransaction(callback, name = '') {
1676
+ const transaction = new _transaction.Transaction(name);
1647
1677
 
1648
1678
  if (this.config.options.tdsVersion < '7_2') {
1649
- return this.execSqlBatch(new Request('ROLLBACK TRAN ' + transaction.name, (...args) => {
1679
+ return this.execSqlBatch(new _request.default('ROLLBACK TRAN ' + transaction.name, err => {
1650
1680
  this.transactionDepth--;
1651
1681
 
1652
1682
  if (this.transactionDepth === 0) {
1653
1683
  this.inTransaction = false;
1654
1684
  }
1655
1685
 
1656
- callback(...args);
1686
+ callback(err);
1657
1687
  }));
1658
1688
  }
1659
1689
 
1660
- const request = new Request(undefined, callback);
1661
- return this.makeRequest(request, TYPE.TRANSACTION_MANAGER, transaction.rollbackPayload(this.currentTransactionDescriptor()));
1690
+ const request = new _request.default(undefined, callback);
1691
+ return this.makeRequest(request, _packet.TYPE.TRANSACTION_MANAGER, transaction.rollbackPayload(this.currentTransactionDescriptor()));
1662
1692
  }
1663
1693
 
1664
1694
  saveTransaction(callback, name) {
1665
- const transaction = new Transaction(name);
1695
+ const transaction = new _transaction.Transaction(name);
1666
1696
 
1667
1697
  if (this.config.options.tdsVersion < '7_2') {
1668
- return this.execSqlBatch(new Request('SAVE TRAN ' + transaction.name, (...args) => {
1698
+ return this.execSqlBatch(new _request.default('SAVE TRAN ' + transaction.name, err => {
1669
1699
  this.transactionDepth++;
1670
- callback(...args);
1700
+ callback(err);
1671
1701
  }));
1672
1702
  }
1673
1703
 
1674
- const request = new Request(undefined, callback);
1675
- return this.makeRequest(request, TYPE.TRANSACTION_MANAGER, transaction.savePayload(this.currentTransactionDescriptor()));
1704
+ const request = new _request.default(undefined, callback);
1705
+ return this.makeRequest(request, _packet.TYPE.TRANSACTION_MANAGER, transaction.savePayload(this.currentTransactionDescriptor()));
1676
1706
  }
1677
1707
 
1678
1708
  transaction(cb, isolationLevel) {
@@ -1681,7 +1711,8 @@ class Connection extends EventEmitter {
1681
1711
  }
1682
1712
 
1683
1713
  const useSavepoint = this.inTransaction;
1684
- const name = '_tedious_' + crypto.randomBytes(10).toString('hex');
1714
+
1715
+ const name = '_tedious_' + _crypto.default.randomBytes(10).toString('hex');
1685
1716
 
1686
1717
  const txDone = (err, done, ...args) => {
1687
1718
  if (err) {
@@ -1712,7 +1743,7 @@ class Connection extends EventEmitter {
1712
1743
  }
1713
1744
 
1714
1745
  if (isolationLevel) {
1715
- return this.execSqlBatch(new Request('SET transaction isolation level ' + this.getIsolationLevelText(isolationLevel), err => {
1746
+ return this.execSqlBatch(new _request.default('SET transaction isolation level ' + this.getIsolationLevelText(isolationLevel), err => {
1716
1747
  return cb(err, txDone);
1717
1748
  }));
1718
1749
  } else {
@@ -1734,25 +1765,25 @@ class Connection extends EventEmitter {
1734
1765
  if (this.state !== this.STATE.LOGGED_IN) {
1735
1766
  const message = 'Requests can only be made in the ' + this.STATE.LOGGED_IN.name + ' state, not the ' + this.state.name + ' state';
1736
1767
  this.debug.log(message);
1737
- request.callback(RequestError(message, 'EINVALIDSTATE'));
1768
+ request.callback((0, _errors.RequestError)(message, 'EINVALIDSTATE'));
1738
1769
  } else if (request.canceled) {
1739
1770
  process.nextTick(() => {
1740
- request.callback(RequestError('Canceled.', 'ECANCEL'));
1771
+ request.callback((0, _errors.RequestError)('Canceled.', 'ECANCEL'));
1741
1772
  });
1742
1773
  } else {
1743
- if (packetType === TYPE.SQL_BATCH) {
1774
+ if (packetType === _packet.TYPE.SQL_BATCH) {
1744
1775
  this.isSqlBatch = true;
1745
1776
  } else {
1746
1777
  this.isSqlBatch = false;
1747
1778
  }
1748
1779
 
1749
1780
  this.request = request;
1750
- this.request.connection = this;
1751
- this.request.rowCount = 0;
1752
- this.request.rows = [];
1753
- this.request.rst = [];
1781
+ request.connection = this;
1782
+ request.rowCount = 0;
1783
+ request.rows = [];
1784
+ request.rst = [];
1754
1785
  let message;
1755
- this.request.once('cancel', () => {
1786
+ request.once('cancel', () => {
1756
1787
  if (!this.isRequestActive(request)) {
1757
1788
  // Cancel was called on a request that is no longer active on this connection
1758
1789
  return;
@@ -1761,9 +1792,8 @@ class Connection extends EventEmitter {
1761
1792
 
1762
1793
  if (this.state === this.STATE.BUILDING_CLIENT_REQUEST) {
1763
1794
  // The request was cancelled before buffering finished
1764
- const sqlRequest = this.request;
1765
1795
  this.request = undefined;
1766
- sqlRequest.callback(RequestError('Canceled.', 'ECANCEL'));
1796
+ request.callback((0, _errors.RequestError)('Canceled.', 'ECANCEL'));
1767
1797
  this.transitionTo(this.STATE.LOGGED_IN);
1768
1798
  } else if (message.writable) {
1769
1799
  // - if the message is still writable, we'll set the ignore bit
@@ -1773,7 +1803,7 @@ class Connection extends EventEmitter {
1773
1803
  } else {
1774
1804
  // - but if the message has been ended (and thus has been fully sent off),
1775
1805
  // we need to send an `ATTENTION` message to the server
1776
- this.messageIo.sendMessage(TYPE.ATTENTION);
1806
+ this.messageIo.sendMessage(_packet.TYPE.ATTENTION);
1777
1807
  this.transitionTo(this.STATE.SENT_ATTENTION);
1778
1808
  }
1779
1809
 
@@ -1781,7 +1811,7 @@ class Connection extends EventEmitter {
1781
1811
  this.createCancelTimer();
1782
1812
  });
1783
1813
 
1784
- if (request instanceof BulkLoad) {
1814
+ if (request instanceof _bulkLoad.default) {
1785
1815
  message = request.getMessageStream(); // If the bulkload was not put into streaming mode by the user,
1786
1816
  // we end the rowToPacketTransform here for them.
1787
1817
  //
@@ -1842,7 +1872,7 @@ class Connection extends EventEmitter {
1842
1872
  }
1843
1873
 
1844
1874
  reset(callback) {
1845
- const request = new Request(this.getInitialSql(), err => {
1875
+ const request = new _request.default(this.getInitialSql(), err => {
1846
1876
  if (this.config.options.tdsVersion < '7_2') {
1847
1877
  this.inTransaction = false;
1848
1878
  }
@@ -1859,16 +1889,16 @@ class Connection extends EventEmitter {
1859
1889
 
1860
1890
  getIsolationLevelText(isolationLevel) {
1861
1891
  switch (isolationLevel) {
1862
- case ISOLATION_LEVEL.READ_UNCOMMITTED:
1892
+ case _transaction.ISOLATION_LEVEL.READ_UNCOMMITTED:
1863
1893
  return 'read uncommitted';
1864
1894
 
1865
- case ISOLATION_LEVEL.REPEATABLE_READ:
1895
+ case _transaction.ISOLATION_LEVEL.REPEATABLE_READ:
1866
1896
  return 'repeatable read';
1867
1897
 
1868
- case ISOLATION_LEVEL.SERIALIZABLE:
1898
+ case _transaction.ISOLATION_LEVEL.SERIALIZABLE:
1869
1899
  return 'serializable';
1870
1900
 
1871
- case ISOLATION_LEVEL.SNAPSHOT:
1901
+ case _transaction.ISOLATION_LEVEL.SNAPSHOT:
1872
1902
  return 'snapshot';
1873
1903
 
1874
1904
  default:
@@ -1878,6 +1908,8 @@ class Connection extends EventEmitter {
1878
1908
 
1879
1909
  }
1880
1910
 
1911
+ var _default = Connection;
1912
+ exports.default = _default;
1881
1913
  module.exports = Connection;
1882
1914
  Connection.prototype.STATE = {
1883
1915
  CONNECTING: {
@@ -1910,11 +1942,21 @@ Connection.prototype.STATE = {
1910
1942
  connectTimeout: function connectTimeout() {
1911
1943
  this.transitionTo(this.STATE.FINAL);
1912
1944
  },
1913
- data: function data(_data) {
1914
- this.addToMessageBuffer(_data);
1915
- },
1945
+ data: function (_data) {
1946
+ function data(_x) {
1947
+ return _data.apply(this, arguments);
1948
+ }
1949
+
1950
+ data.toString = function () {
1951
+ return _data.toString();
1952
+ };
1953
+
1954
+ return data;
1955
+ }(function (data) {
1956
+ this.addToMessageBuffer(data);
1957
+ }),
1916
1958
  message: function message() {
1917
- const preloginPayload = new PreloginPayload(this.messageBuffer);
1959
+ const preloginPayload = new _preloginPayload.default(this.messageBuffer);
1918
1960
  this.debug.payload(function () {
1919
1961
  return preloginPayload.toString(' ');
1920
1962
  });
@@ -1925,7 +1967,7 @@ Connection.prototype.STATE = {
1925
1967
 
1926
1968
  if (preloginPayload.encryptionString === 'ON' || preloginPayload.encryptionString === 'REQ') {
1927
1969
  if (!this.config.options.encrypt) {
1928
- this.emit('connect', ConnectionError("Server requires encryption, set 'encrypt' config option to true.", 'EENCRYPT'));
1970
+ this.emit('connect', (0, _errors.ConnectionError)("Server requires encryption, set 'encrypt' config option to true.", 'EENCRYPT'));
1929
1971
  return this.close();
1930
1972
  }
1931
1973
 
@@ -1947,7 +1989,7 @@ Connection.prototype.STATE = {
1947
1989
  REROUTING: {
1948
1990
  name: 'ReRouting',
1949
1991
  enter: function enter() {
1950
- this.cleanupConnection(this.cleanupTypeEnum.REDIRECT);
1992
+ this.cleanupConnection(CLEANUP_TYPE.REDIRECT);
1951
1993
  },
1952
1994
  events: {
1953
1995
  message: function message() {},
@@ -1966,7 +2008,7 @@ Connection.prototype.STATE = {
1966
2008
  name: 'TRANSIENT_FAILURE_RETRY',
1967
2009
  enter: function enter() {
1968
2010
  this.curTransientRetryCount++;
1969
- this.cleanupConnection(this.cleanupTypeEnum.RETRY);
2011
+ this.cleanupConnection(CLEANUP_TYPE.RETRY);
1970
2012
  },
1971
2013
  events: {
1972
2014
  message: function message() {},
@@ -1990,15 +2032,25 @@ Connection.prototype.STATE = {
1990
2032
  connectTimeout: function connectTimeout() {
1991
2033
  this.transitionTo(this.STATE.FINAL);
1992
2034
  },
1993
- data: function data(_data2) {
1994
- this.messageIo.tlsHandshakeData(_data2);
1995
- },
2035
+ data: function (_data2) {
2036
+ function data(_x2) {
2037
+ return _data2.apply(this, arguments);
2038
+ }
2039
+
2040
+ data.toString = function () {
2041
+ return _data2.toString();
2042
+ };
2043
+
2044
+ return data;
2045
+ }(function (data) {
2046
+ this.messageIo.tlsHandshakeData(data);
2047
+ }),
1996
2048
  message: function message() {
1997
2049
  if (this.messageIo.tlsNegotiationComplete) {
1998
2050
  this.sendLogin7Packet();
1999
2051
  const authentication = this.config.authentication;
2000
2052
 
2001
- if (authentication.type === 'azure-active-directory-password' || authentication.type === 'azure-active-directory-msi-vm' || authentication.type === 'azure-active-directory-msi-app-service') {
2053
+ if (authentication.type === 'azure-active-directory-password' || authentication.type === 'azure-active-directory-msi-vm' || authentication.type === 'azure-active-directory-msi-app-service' || authentication.type === 'azure-active-directory-service-principal-secret') {
2002
2054
  this.transitionTo(this.STATE.SENT_LOGIN7_WITH_FEDAUTH);
2003
2055
  } else if (authentication.type === 'ntlm') {
2004
2056
  this.transitionTo(this.STATE.SENT_LOGIN7_WITH_NTLM);
@@ -2018,28 +2070,38 @@ Connection.prototype.STATE = {
2018
2070
  connectTimeout: function connectTimeout() {
2019
2071
  this.transitionTo(this.STATE.FINAL);
2020
2072
  },
2021
- data: function data(_data3) {
2022
- this.sendDataToTokenStreamParser(_data3);
2023
- },
2073
+ data: function (_data3) {
2074
+ function data(_x3) {
2075
+ return _data3.apply(this, arguments);
2076
+ }
2077
+
2078
+ data.toString = function () {
2079
+ return _data3.toString();
2080
+ };
2081
+
2082
+ return data;
2083
+ }(function (data) {
2084
+ this.sendDataToTokenStreamParser(data);
2085
+ }),
2024
2086
  routingChange: function routingChange() {
2025
2087
  this.transitionTo(this.STATE.REROUTING);
2026
2088
  },
2027
2089
  featureExtAck: function featureExtAck(token) {
2028
2090
  const authentication = this.config.authentication;
2029
2091
 
2030
- if (authentication.type === 'azure-active-directory-password' || authentication.type === 'azure-active-directory-access-token' || authentication.type === 'azure-active-directory-msi-vm' || authentication.type === 'azure-active-directory-msi-app-service') {
2092
+ if (authentication.type === 'azure-active-directory-password' || authentication.type === 'azure-active-directory-access-token' || authentication.type === 'azure-active-directory-msi-vm' || authentication.type === 'azure-active-directory-msi-app-service' || authentication.type === 'azure-active-directory-service-principal-secret') {
2031
2093
  if (token.fedAuth === undefined) {
2032
- this.loginError = ConnectionError('Did not receive Active Directory authentication acknowledgement');
2094
+ this.loginError = (0, _errors.ConnectionError)('Did not receive Active Directory authentication acknowledgement');
2033
2095
  this.loggedIn = false;
2034
2096
  } else if (token.fedAuth.length !== 0) {
2035
- this.loginError = ConnectionError(`Active Directory authentication acknowledgment for ${authentication.type} authentication method includes extra data`);
2097
+ this.loginError = (0, _errors.ConnectionError)(`Active Directory authentication acknowledgment for ${authentication.type} authentication method includes extra data`);
2036
2098
  this.loggedIn = false;
2037
2099
  }
2038
2100
  } else if (token.fedAuth === undefined) {
2039
- this.loginError = ConnectionError('Received acknowledgement for unknown feature');
2101
+ this.loginError = (0, _errors.ConnectionError)('Received acknowledgement for unknown feature');
2040
2102
  this.loggedIn = false;
2041
2103
  } else {
2042
- this.loginError = ConnectionError('Did not request Active Directory authentication, but received the acknowledgment');
2104
+ this.loginError = (0, _errors.ConnectionError)('Did not request Active Directory authentication, but received the acknowledgment');
2043
2105
  this.loggedIn = false;
2044
2106
  }
2045
2107
  },
@@ -2055,7 +2117,7 @@ Connection.prototype.STATE = {
2055
2117
  this.transitionTo(this.STATE.FINAL);
2056
2118
  }
2057
2119
  } else {
2058
- this.emit('connect', ConnectionError('Login failed.', 'ELOGIN'));
2120
+ this.emit('connect', (0, _errors.ConnectionError)('Login failed.', 'ELOGIN'));
2059
2121
  this.transitionTo(this.STATE.FINAL);
2060
2122
  }
2061
2123
  }
@@ -2070,24 +2132,29 @@ Connection.prototype.STATE = {
2070
2132
  connectTimeout: function connectTimeout() {
2071
2133
  this.transitionTo(this.STATE.FINAL);
2072
2134
  },
2073
- data: function data(_data4) {
2074
- this.sendDataToTokenStreamParser(_data4);
2075
- },
2135
+ data: function (_data4) {
2136
+ function data(_x4) {
2137
+ return _data4.apply(this, arguments);
2138
+ }
2139
+
2140
+ data.toString = function () {
2141
+ return _data4.toString();
2142
+ };
2143
+
2144
+ return data;
2145
+ }(function (data) {
2146
+ this.sendDataToTokenStreamParser(data);
2147
+ }),
2076
2148
  message: function message() {
2077
2149
  if (this.ntlmpacket) {
2078
2150
  const authentication = this.config.authentication;
2079
- const payload = new NTLMResponsePayload({
2151
+ const payload = new _ntlmPayload.default({
2080
2152
  domain: authentication.options.domain,
2081
2153
  userName: authentication.options.userName,
2082
2154
  password: authentication.options.password,
2083
- database: this.config.options.database,
2084
- appName: this.config.options.appName,
2085
- packetSize: this.config.options.packetSize,
2086
- tdsVersion: this.config.options.tdsVersion,
2087
- ntlmpacket: this.ntlmpacket,
2088
- additional: this.additional
2155
+ ntlmpacket: this.ntlmpacket
2089
2156
  });
2090
- this.messageIo.sendMessage(TYPE.NTLMAUTH_PKT, payload.data);
2157
+ this.messageIo.sendMessage(_packet.TYPE.NTLMAUTH_PKT, payload.data);
2091
2158
  this.debug.payload(function () {
2092
2159
  return payload.toString(' ');
2093
2160
  });
@@ -2103,7 +2170,7 @@ Connection.prototype.STATE = {
2103
2170
  this.transitionTo(this.STATE.FINAL);
2104
2171
  }
2105
2172
  } else {
2106
- this.emit('connect', ConnectionError('Login failed.', 'ELOGIN'));
2173
+ this.emit('connect', (0, _errors.ConnectionError)('Login failed.', 'ELOGIN'));
2107
2174
  this.transitionTo(this.STATE.FINAL);
2108
2175
  }
2109
2176
  }
@@ -2118,9 +2185,19 @@ Connection.prototype.STATE = {
2118
2185
  connectTimeout: function connectTimeout() {
2119
2186
  this.transitionTo(this.STATE.FINAL);
2120
2187
  },
2121
- data: function data(_data5) {
2122
- this.sendDataToTokenStreamParser(_data5);
2123
- },
2188
+ data: function (_data5) {
2189
+ function data(_x5) {
2190
+ return _data5.apply(this, arguments);
2191
+ }
2192
+
2193
+ data.toString = function () {
2194
+ return _data5.toString();
2195
+ };
2196
+
2197
+ return data;
2198
+ }(function (data) {
2199
+ this.sendDataToTokenStreamParser(data);
2200
+ }),
2124
2201
  routingChange: function routingChange() {
2125
2202
  this.transitionTo(this.STATE.REROUTING);
2126
2203
  },
@@ -2128,7 +2205,9 @@ Connection.prototype.STATE = {
2128
2205
  this.fedAuthInfoToken = token;
2129
2206
  },
2130
2207
  message: function message() {
2131
- if (this.fedAuthInfoToken && this.fedAuthInfoToken.stsurl && this.fedAuthInfoToken.spn) {
2208
+ const fedAuthInfoToken = this.fedAuthInfoToken;
2209
+
2210
+ if (fedAuthInfoToken && fedAuthInfoToken.stsurl && fedAuthInfoToken.spn) {
2132
2211
  const authentication = this.config.authentication;
2133
2212
 
2134
2213
  const getToken = callback => {
@@ -2143,29 +2222,32 @@ Connection.prototype.STATE = {
2143
2222
  };
2144
2223
 
2145
2224
  if (authentication.type === 'azure-active-directory-password') {
2146
- loginWithUsernamePassword(authentication.options.userName, authentication.options.password, {
2225
+ (0, _msRestNodeauth.loginWithUsernamePassword)(authentication.options.userName, authentication.options.password, {
2147
2226
  clientId: '7f98cb04-cd1e-40df-9140-3bf7e2cea4db',
2148
- tokenAudience: this.fedAuthInfoToken.spn
2227
+ tokenAudience: fedAuthInfoToken.spn
2149
2228
  }, getTokenFromCredentials);
2150
2229
  } else if (authentication.type === 'azure-active-directory-msi-vm') {
2151
- loginWithVmMSI({
2230
+ (0, _msRestNodeauth.loginWithVmMSI)({
2152
2231
  clientId: authentication.options.clientId,
2153
2232
  msiEndpoint: authentication.options.msiEndpoint,
2154
- resource: this.fedAuthInfoToken.spn
2233
+ resource: fedAuthInfoToken.spn
2155
2234
  }, getTokenFromCredentials);
2156
2235
  } else if (authentication.type === 'azure-active-directory-msi-app-service') {
2157
- loginWithAppServiceMSI({
2158
- clientId: authentication.options.clientId,
2236
+ (0, _msRestNodeauth.loginWithAppServiceMSI)({
2159
2237
  msiEndpoint: authentication.options.msiEndpoint,
2160
2238
  msiSecret: authentication.options.msiSecret,
2161
- resource: this.fedAuthInfoToken.spn
2239
+ resource: fedAuthInfoToken.spn
2240
+ }, getTokenFromCredentials);
2241
+ } else if (authentication.type === 'azure-active-directory-service-principal-secret') {
2242
+ (0, _msRestNodeauth.loginWithServicePrincipalSecret)(authentication.options.clientId, authentication.options.clientSecret, authentication.options.tenantId, {
2243
+ tokenAudience: fedAuthInfoToken.spn
2162
2244
  }, getTokenFromCredentials);
2163
2245
  }
2164
2246
  };
2165
2247
 
2166
2248
  getToken((err, token) => {
2167
2249
  if (err) {
2168
- this.loginError = ConnectionError('Security token could not be authenticated or authorized.', 'EFEDAUTH');
2250
+ this.loginError = (0, _errors.ConnectionError)('Security token could not be authenticated or authorized.', 'EFEDAUTH');
2169
2251
  this.emit('connect', this.loginError);
2170
2252
  this.transitionTo(this.STATE.FINAL);
2171
2253
  return;
@@ -2182,7 +2264,7 @@ Connection.prototype.STATE = {
2182
2264
  this.transitionTo(this.STATE.FINAL);
2183
2265
  }
2184
2266
  } else {
2185
- this.emit('connect', ConnectionError('Login failed.', 'ELOGIN'));
2267
+ this.emit('connect', (0, _errors.ConnectionError)('Login failed.', 'ELOGIN'));
2186
2268
  this.transitionTo(this.STATE.FINAL);
2187
2269
  }
2188
2270
  }
@@ -2200,9 +2282,19 @@ Connection.prototype.STATE = {
2200
2282
  connectTimeout: function connectTimeout() {
2201
2283
  this.transitionTo(this.STATE.FINAL);
2202
2284
  },
2203
- data: function data(_data6) {
2204
- this.sendDataToTokenStreamParser(_data6);
2205
- },
2285
+ data: function (_data6) {
2286
+ function data(_x6) {
2287
+ return _data6.apply(this, arguments);
2288
+ }
2289
+
2290
+ data.toString = function () {
2291
+ return _data6.toString();
2292
+ };
2293
+
2294
+ return data;
2295
+ }(function (data) {
2296
+ this.sendDataToTokenStreamParser(data);
2297
+ }),
2206
2298
  message: function message() {
2207
2299
  this.transitionTo(this.STATE.LOGGED_IN);
2208
2300
  this.processedInitialSql();
@@ -2244,17 +2336,27 @@ Connection.prototype.STATE = {
2244
2336
  this.transitionTo(this.STATE.FINAL);
2245
2337
  sqlRequest.callback(err);
2246
2338
  },
2247
- data: function data(_data7) {
2339
+ data: function (_data7) {
2340
+ function data(_x7) {
2341
+ return _data7.apply(this, arguments);
2342
+ }
2343
+
2344
+ data.toString = function () {
2345
+ return _data7.toString();
2346
+ };
2347
+
2348
+ return data;
2349
+ }(function (data) {
2248
2350
  this.clearRequestTimer(); // request timer is stopped on first data package
2249
2351
 
2250
- const ret = this.sendDataToTokenStreamParser(_data7);
2352
+ const ret = this.sendDataToTokenStreamParser(data);
2251
2353
 
2252
2354
  if (ret === false) {
2253
2355
  // Bridge backpressure from the token stream parser transform to the
2254
2356
  // packet stream transform.
2255
2357
  this.messageIo.pause();
2256
2358
  }
2257
- },
2359
+ }),
2258
2360
  message: function message() {
2259
2361
  // We have to channel the 'message' (EOM) event through the token stream
2260
2362
  // parser transform, to keep it in line with the flow of the tokens, when
@@ -2286,9 +2388,19 @@ Connection.prototype.STATE = {
2286
2388
  this.transitionTo(this.STATE.FINAL);
2287
2389
  sqlRequest.callback(err);
2288
2390
  },
2289
- data: function data(_data8) {
2290
- this.sendDataToTokenStreamParser(_data8);
2291
- },
2391
+ data: function (_data8) {
2392
+ function data(_x8) {
2393
+ return _data8.apply(this, arguments);
2394
+ }
2395
+
2396
+ data.toString = function () {
2397
+ return _data8.toString();
2398
+ };
2399
+
2400
+ return data;
2401
+ }(function (data) {
2402
+ this.sendDataToTokenStreamParser(data);
2403
+ }),
2292
2404
  attention: function attention() {
2293
2405
  this.attentionReceived = true;
2294
2406
  },
@@ -2301,10 +2413,10 @@ Connection.prototype.STATE = {
2301
2413
  this.request = undefined;
2302
2414
  this.transitionTo(this.STATE.LOGGED_IN);
2303
2415
 
2304
- if (sqlRequest.error && sqlRequest.error instanceof RequestError && sqlRequest.error.code === 'ETIMEOUT') {
2416
+ if (sqlRequest.error && sqlRequest.error instanceof _errors.RequestError && sqlRequest.error.code === 'ETIMEOUT') {
2305
2417
  sqlRequest.callback(sqlRequest.error);
2306
2418
  } else {
2307
- sqlRequest.callback(RequestError('Canceled.', 'ECANCEL'));
2419
+ sqlRequest.callback((0, _errors.RequestError)('Canceled.', 'ECANCEL'));
2308
2420
  }
2309
2421
  }
2310
2422
  }
@@ -2313,7 +2425,7 @@ Connection.prototype.STATE = {
2313
2425
  FINAL: {
2314
2426
  name: 'Final',
2315
2427
  enter: function enter() {
2316
- this.cleanupConnection(this.cleanupTypeEnum.NORMAL);
2428
+ this.cleanupConnection(CLEANUP_TYPE.NORMAL);
2317
2429
  },
2318
2430
  events: {
2319
2431
  loginFailed: function loginFailed() {// Do nothing. The connection was probably closed by the client code.