mssql 12.3.1 → 12.5.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.
@@ -6,6 +6,7 @@ const BaseConnectionPool = require('../base/connection-pool')
6
6
  const { IDS } = require('../utils')
7
7
  const shared = require('../shared')
8
8
  const ConnectionError = require('../error/connection-error')
9
+ const { CHANNELS, publish } = require('../diagnostics')
9
10
 
10
11
  class ConnectionPool extends BaseConnectionPool {
11
12
  _config () {
@@ -88,6 +89,12 @@ class ConnectionPool extends BaseConnectionPool {
88
89
 
89
90
  debug('connection(%d): established', IDS.get(tedious))
90
91
  this.collation = tedious.databaseCollation
92
+ publish(CHANNELS.CONNECTION_CREATE, () => ({
93
+ connectionId: IDS.get(tedious),
94
+ poolId: IDS.get(this),
95
+ server: this.config.server,
96
+ database: this.config.database
97
+ }))
91
98
  resolveOnce(tedious)
92
99
  })
93
100
  IDS.add(tedious, 'Connection')
@@ -156,6 +163,8 @@ class ConnectionPool extends BaseConnectionPool {
156
163
  return
157
164
  }
158
165
  debug('connection(%d): destroying', IDS.get(tedious))
166
+ const connectionId = IDS.get(tedious)
167
+ const poolId = IDS.get(this)
159
168
 
160
169
  if (tedious.closed) {
161
170
  debug('connection(%d): already closed', IDS.get(tedious))
@@ -163,6 +172,10 @@ class ConnectionPool extends BaseConnectionPool {
163
172
  } else {
164
173
  tedious.once('end', () => {
165
174
  debug('connection(%d): destroyed', IDS.get(tedious))
175
+ publish(CHANNELS.CONNECTION_DESTROY, () => ({
176
+ connectionId,
177
+ poolId
178
+ }))
166
179
  resolve()
167
180
  })
168
181
 
@@ -365,6 +365,9 @@ class Request extends BaseRequest {
365
365
 
366
366
  connection.execBulkLoad(bulk, table.rows)
367
367
  })
368
+ if (typeof this.overrides.requestTimeout === 'number') {
369
+ req.setTimeout(this.overrides.requestTimeout)
370
+ }
368
371
  this._setCurrentRequest(req)
369
372
 
370
373
  connection.execSqlBatch(req)
@@ -514,6 +517,10 @@ class Request extends BaseRequest {
514
517
  }
515
518
  })
516
519
 
520
+ if (typeof this.overrides.requestTimeout === 'number') {
521
+ req.setTimeout(this.overrides.requestTimeout)
522
+ }
523
+
517
524
  this._setCurrentRequest(req)
518
525
 
519
526
  req.on('columnMetadata', metadata => {
@@ -874,6 +881,10 @@ class Request extends BaseRequest {
874
881
  }
875
882
  })
876
883
 
884
+ if (typeof this.overrides.requestTimeout === 'number') {
885
+ req.setTimeout(this.overrides.requestTimeout)
886
+ }
887
+
877
888
  this._setCurrentRequest(req)
878
889
 
879
890
  req.on('columnMetadata', metadata => {
@@ -4,10 +4,11 @@ const debug = require('debug')('mssql:tedi')
4
4
  const BaseTransaction = require('../base/transaction')
5
5
  const { IDS } = require('../utils')
6
6
  const TransactionError = require('../error/transaction-error')
7
+ const { CHANNELS, publish } = require('../diagnostics')
7
8
 
8
9
  class Transaction extends BaseTransaction {
9
- constructor (parent) {
10
- super(parent)
10
+ constructor (parent, overrides) {
11
+ super(parent, overrides)
11
12
 
12
13
  this._abort = () => {
13
14
  if (!this._rollbackRequested) {
@@ -23,6 +24,10 @@ class Transaction extends BaseTransaction {
23
24
  this._acquiredConfig = null
24
25
  this._aborted = true
25
26
 
27
+ publish(CHANNELS.TRANSACTION_ROLLBACK, () => ({
28
+ transactionId: IDS.get(this),
29
+ aborted: true
30
+ }))
26
31
  this.emit('rollback', true)
27
32
  }
28
33
  }
package/lib/udt.js CHANGED
@@ -44,6 +44,12 @@ const SEGMENT = {
44
44
  FIRST_ARC: 0x03
45
45
  }; */
46
46
 
47
+ const ensureBytes = (buffer, needed) => {
48
+ if (buffer.position + needed > buffer.length) {
49
+ throw new Error(`Corrupt or truncated spatial data: expected ${needed} bytes at position ${buffer.position}, but only ${buffer.length - buffer.position} bytes remain`)
50
+ }
51
+ }
52
+
47
53
  class Point {
48
54
  constructor () {
49
55
  this.x = 0
@@ -64,6 +70,8 @@ const parsePoints = (buffer, count, isGeometryPoint) => {
64
70
  return points
65
71
  }
66
72
 
73
+ ensureBytes(buffer, count * 16)
74
+
67
75
  if (isGeometryPoint) {
68
76
  // GEOMETRY POINT (s2.1.6): x then y.
69
77
  for (let i = 1; i <= count; i++) {
@@ -101,6 +109,8 @@ const parseZ = (buffer, points) => {
101
109
  return
102
110
  }
103
111
 
112
+ ensureBytes(buffer, points.length * 8)
113
+
104
114
  points.forEach(point => {
105
115
  point.z = buffer.readDoubleLE(buffer.position)
106
116
  buffer.position += 8
@@ -114,6 +124,8 @@ const parseM = (buffer, points) => {
114
124
  return
115
125
  }
116
126
 
127
+ ensureBytes(buffer, points.length * 8)
128
+
117
129
  points.forEach(point => {
118
130
  point.m = buffer.readDoubleLE(buffer.position)
119
131
  buffer.position += 8
@@ -139,6 +151,8 @@ const parseFigures = (buffer, count, properties) => {
139
151
  pointOffset: 0
140
152
  })
141
153
  } else {
154
+ ensureBytes(buffer, count * 5)
155
+
142
156
  for (let i = 1; i <= count; i++) {
143
157
  figures.push({
144
158
  attribute: buffer.readUInt8(buffer.position),
@@ -173,6 +187,8 @@ const parseShapes = (buffer, count, properties) => {
173
187
  type: 0x02
174
188
  })
175
189
  } else {
190
+ ensureBytes(buffer, count * 9)
191
+
176
192
  for (let i = 1; i <= count; i++) {
177
193
  shapes.push({
178
194
  parentOffset: buffer.readInt32LE(buffer.position),
@@ -195,6 +211,8 @@ const parseSegments = (buffer, count) => {
195
211
  return segments
196
212
  }
197
213
 
214
+ ensureBytes(buffer, count)
215
+
198
216
  for (let i = 1; i <= count; i++) {
199
217
  segments.push({ type: buffer.readUInt8(buffer.position) })
200
218
 
@@ -207,6 +225,8 @@ const parseSegments = (buffer, count) => {
207
225
  const parseGeography = (buffer, isUsingGeometryPoints) => {
208
226
  // s2.1.1 + s.2.1.2
209
227
 
228
+ ensureBytes(buffer, 6)
229
+
210
230
  const srid = buffer.readInt32LE(0)
211
231
  if (srid === -1) {
212
232
  return null
@@ -220,9 +240,6 @@ const parseGeography = (buffer, isUsingGeometryPoints) => {
220
240
  const flags = buffer.readUInt8(5)
221
241
  buffer.position = 6
222
242
 
223
- // console.log("srid", srid)
224
- // console.log("version", version)
225
-
226
243
  const properties = {
227
244
  Z: (flags & (1 << 0)) > 0,
228
245
  M: (flags & (1 << 1)) > 0,
@@ -232,23 +249,20 @@ const parseGeography = (buffer, isUsingGeometryPoints) => {
232
249
  }
233
250
 
234
251
  if (value.version === 2) {
235
- properties.H = (flags & (1 << 3)) > 0
252
+ properties.H = (flags & (1 << 5)) > 0
236
253
  }
237
254
 
238
- // console.log("properties", properties);
239
-
240
255
  let numberOfPoints
241
256
  if (properties.P) {
242
257
  numberOfPoints = 1
243
258
  } else if (properties.L) {
244
259
  numberOfPoints = 2
245
260
  } else {
261
+ ensureBytes(buffer, 4)
246
262
  numberOfPoints = buffer.readUInt32LE(buffer.position)
247
263
  buffer.position += 4
248
264
  }
249
265
 
250
- // console.log("numberOfPoints", numberOfPoints)
251
-
252
266
  value.points = parsePoints(buffer, numberOfPoints, isUsingGeometryPoints)
253
267
 
254
268
  if (properties.Z) {
@@ -259,49 +273,37 @@ const parseGeography = (buffer, isUsingGeometryPoints) => {
259
273
  parseM(buffer, value.points)
260
274
  }
261
275
 
262
- // console.log("points", points)
263
-
264
276
  let numberOfFigures
265
277
  if (properties.P) {
266
278
  numberOfFigures = 1
267
279
  } else if (properties.L) {
268
280
  numberOfFigures = 1
269
281
  } else {
282
+ ensureBytes(buffer, 4)
270
283
  numberOfFigures = buffer.readUInt32LE(buffer.position)
271
284
  buffer.position += 4
272
285
  }
273
286
 
274
- // console.log("numberOfFigures", numberOfFigures)
275
-
276
287
  value.figures = parseFigures(buffer, numberOfFigures, properties)
277
288
 
278
- // console.log("figures", figures)
279
-
280
289
  let numberOfShapes
281
290
  if (properties.P) {
282
291
  numberOfShapes = 1
283
292
  } else if (properties.L) {
284
293
  numberOfShapes = 1
285
294
  } else {
295
+ ensureBytes(buffer, 4)
286
296
  numberOfShapes = buffer.readUInt32LE(buffer.position)
287
297
  buffer.position += 4
288
298
  }
289
299
 
290
- // console.log("numberOfShapes", numberOfShapes)
291
-
292
300
  value.shapes = parseShapes(buffer, numberOfShapes, properties)
293
301
 
294
- // console.log( "shapes", shapes)
295
-
296
- if (value.version === 2 && buffer.position < buffer.length) {
302
+ if (value.version === 2 && buffer.position + 4 <= buffer.length) {
297
303
  const numberOfSegments = buffer.readUInt32LE(buffer.position)
298
304
  buffer.position += 4
299
305
 
300
- // console.log("numberOfSegments", numberOfSegments)
301
-
302
306
  value.segments = parseSegments(buffer, numberOfSegments)
303
-
304
- // console.log("segments", segments)
305
307
  } else {
306
308
  value.segments = []
307
309
  }
package/lib/utils.js CHANGED
@@ -9,6 +9,14 @@ const INCREMENT = {
9
9
  PreparedStatement: 1
10
10
  }
11
11
 
12
+ const getPoolId = (obj) => {
13
+ let parent = obj && obj.parent
14
+ while (parent && !parent.pool) {
15
+ parent = parent.parent
16
+ }
17
+ return parent ? IDS.get(parent) : undefined
18
+ }
19
+
12
20
  module.exports = {
13
21
  objectHasProperty: (object, property) => Object.prototype.hasOwnProperty.call(object, property),
14
22
  INCREMENT,
@@ -18,5 +26,6 @@ module.exports = {
18
26
  if (id) return IDS.set(object, id)
19
27
  IDS.set(object, INCREMENT[type]++)
20
28
  }
21
- }
29
+ },
30
+ getPoolId
22
31
  }
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "azure",
22
22
  "node-mssql"
23
23
  ],
24
- "version": "12.3.1",
24
+ "version": "12.5.0",
25
25
  "main": "index.js",
26
26
  "type": "commonjs",
27
27
  "repository": {
@@ -52,7 +52,7 @@
52
52
  "standard": "^17.0.0"
53
53
  },
54
54
  "engines": {
55
- "node": ">=18"
55
+ "node": ">=18.19.0"
56
56
  },
57
57
  "files": [
58
58
  "lib/",