sqlite-executor 4.0.5 → 4.0.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.
@@ -56,218 +56,9 @@ __webpack_require__.d(__webpack_exports__, {
56
56
  }
57
57
  });
58
58
  var external_node_events_namespaceObject = require("node:events");
59
- function _check_private_redeclaration(obj, privateCollection) {
60
- if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
61
- }
62
- function _class_apply_descriptor_get(receiver, descriptor) {
63
- if (descriptor.get) return descriptor.get.call(receiver);
64
- return descriptor.value;
65
- }
66
- function _class_apply_descriptor_set(receiver, descriptor, value) {
67
- if (descriptor.set) descriptor.set.call(receiver, value);
68
- else {
69
- if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
70
- descriptor.value = value;
71
- }
72
- }
73
- function _class_call_check(instance, Constructor) {
74
- if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
75
- }
76
- function _class_extract_field_descriptor(receiver, privateMap, action) {
77
- if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
78
- return privateMap.get(receiver);
79
- }
80
- function _class_private_field_get(receiver, privateMap) {
81
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
82
- return _class_apply_descriptor_get(receiver, descriptor);
83
- }
84
- function _class_private_field_init(obj, privateMap, value) {
85
- _check_private_redeclaration(obj, privateMap);
86
- privateMap.set(obj, value);
87
- }
88
- function _class_private_field_set(receiver, privateMap, value) {
89
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
90
- _class_apply_descriptor_set(receiver, descriptor, value);
91
- return value;
92
- }
93
- function _defineProperties(target, props) {
94
- for(var i = 0; i < props.length; i++){
95
- var descriptor = props[i];
96
- descriptor.enumerable = descriptor.enumerable || false;
97
- descriptor.configurable = true;
98
- if ("value" in descriptor) descriptor.writable = true;
99
- Object.defineProperty(target, descriptor.key, descriptor);
100
- }
101
- }
102
- function _create_class(Constructor, protoProps, staticProps) {
103
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
104
- if (staticProps) _defineProperties(Constructor, staticProps);
105
- return Constructor;
106
- }
107
- var _maxSize = /*#__PURE__*/ new WeakMap(), _maxKeyLength = /*#__PURE__*/ new WeakMap(), _map = /*#__PURE__*/ new WeakMap();
108
- var lruCache_LRUCache = /*#__PURE__*/ function() {
109
- "use strict";
110
- function LRUCache() {
111
- var _ref = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, _ref_maxSize = _ref.maxSize, maxSize = void 0 === _ref_maxSize ? 256 : _ref_maxSize, _ref_maxKeyLength = _ref.maxKeyLength, maxKeyLength = void 0 === _ref_maxKeyLength ? 4096 : _ref_maxKeyLength;
112
- _class_call_check(this, LRUCache);
113
- _class_private_field_init(this, _maxSize, {
114
- writable: true,
115
- value: void 0
116
- });
117
- _class_private_field_init(this, _maxKeyLength, {
118
- writable: true,
119
- value: void 0
120
- });
121
- _class_private_field_init(this, _map, {
122
- writable: true,
123
- value: new Map()
124
- });
125
- _class_private_field_set(this, _maxSize, Math.max(1, maxSize));
126
- _class_private_field_set(this, _maxKeyLength, maxKeyLength);
127
- }
128
- _create_class(LRUCache, [
129
- {
130
- key: "get",
131
- value: function(key) {
132
- if ("string" != typeof key || key.length > _class_private_field_get(this, _maxKeyLength)) return;
133
- var value = _class_private_field_get(this, _map).get(key);
134
- if (void 0 === value) return;
135
- _class_private_field_get(this, _map)["delete"](key);
136
- _class_private_field_get(this, _map).set(key, value);
137
- return value;
138
- }
139
- },
140
- {
141
- key: "set",
142
- value: function(key, value) {
143
- if ("string" != typeof key || key.length > _class_private_field_get(this, _maxKeyLength)) return;
144
- if (_class_private_field_get(this, _map).size >= _class_private_field_get(this, _maxSize)) {
145
- var firstKey = _class_private_field_get(this, _map).keys().next().value;
146
- _class_private_field_get(this, _map)["delete"](firstKey);
147
- }
148
- _class_private_field_get(this, _map).set(key, value);
149
- }
150
- },
151
- {
152
- key: "size",
153
- get: function() {
154
- return _class_private_field_get(this, _map).size;
155
- }
156
- },
157
- {
158
- key: "clear",
159
- value: function() {
160
- _class_private_field_get(this, _map).clear();
161
- }
162
- }
163
- ]);
164
- return LRUCache;
165
- }();
166
- var CC_SINGLE_QUOTE = 39;
167
- var CC_DOUBLE_QUOTE = 34;
168
- var CC_DASH = 45;
169
- var CC_SLASH = 47;
170
- var CC_STAR = 42;
171
- var CC_NEWLINE = 10;
172
- var CC_QUESTION = 63;
173
- var CC_SEMICOLON = 59;
174
- var CC_SPACE = 32;
175
- var STATE_NORMAL = 0;
176
- var STATE_SINGLE_QUOTE = 1;
177
- var STATE_DOUBLE_QUOTE = 2;
178
- var STATE_LINE_COMMENT = 3;
179
- var STATE_BLOCK_COMMENT = 4;
180
- var _normBuf = new Uint16Array(1024);
181
- var _normDecoder = new TextDecoder("utf-16le");
182
- var _normCache = new lruCache_LRUCache({
183
- maxSize: 256,
184
- maxKeyLength: 4096
185
- });
186
- function normalizeSQL(sql) {
187
- var cached = _normCache.get(sql);
188
- if (void 0 !== cached) return cached;
189
- var len = sql.length;
190
- var needed = len + 1;
191
- if (_normBuf.length < needed) _normBuf = new Uint16Array(needed);
192
- var outCodes = _normBuf;
193
- var writePos = 0;
194
- var pendingSpace = false;
195
- var state = STATE_NORMAL;
196
- for(var i = 0; i < len; i++){
197
- var code = sql.charCodeAt(i);
198
- var nextCode = sql.charCodeAt(i + 1);
199
- if (state === STATE_BLOCK_COMMENT) {
200
- if (code === CC_STAR && nextCode === CC_SLASH) {
201
- state = STATE_NORMAL;
202
- i++;
203
- if (writePos > 0) pendingSpace = true;
204
- }
205
- continue;
206
- }
207
- if (state === STATE_LINE_COMMENT) {
208
- if (code === CC_NEWLINE) {
209
- state = STATE_NORMAL;
210
- if (writePos > 0) pendingSpace = true;
211
- }
212
- continue;
213
- }
214
- if (state === STATE_NORMAL) {
215
- if (code === CC_DASH && nextCode === CC_DASH) {
216
- state = STATE_LINE_COMMENT;
217
- i++;
218
- continue;
219
- }
220
- if (code === CC_SLASH && nextCode === CC_STAR) {
221
- state = STATE_BLOCK_COMMENT;
222
- i++;
223
- continue;
224
- }
225
- }
226
- if (32 === code || 9 === code || 10 === code || 11 === code || 12 === code || 13 === code) {
227
- if (writePos > 0) pendingSpace = true;
228
- continue;
229
- }
230
- if (pendingSpace && writePos > 0) {
231
- outCodes[writePos++] = CC_SPACE;
232
- pendingSpace = false;
233
- }
234
- outCodes[writePos++] = code;
235
- if (state === STATE_NORMAL) {
236
- if (code === CC_SINGLE_QUOTE) state = STATE_SINGLE_QUOTE;
237
- else if (code === CC_DOUBLE_QUOTE) state = STATE_DOUBLE_QUOTE;
238
- continue;
239
- }
240
- if (state === STATE_SINGLE_QUOTE) {
241
- if (code === CC_SINGLE_QUOTE && nextCode === CC_SINGLE_QUOTE) {
242
- outCodes[writePos++] = nextCode;
243
- i++;
244
- continue;
245
- }
246
- if (code === CC_SINGLE_QUOTE) state = STATE_NORMAL;
247
- continue;
248
- }
249
- if (state === STATE_DOUBLE_QUOTE) {
250
- if (code === CC_DOUBLE_QUOTE && nextCode === CC_DOUBLE_QUOTE) {
251
- outCodes[writePos++] = nextCode;
252
- i++;
253
- continue;
254
- }
255
- if (code === CC_DOUBLE_QUOTE) state = STATE_NORMAL;
256
- }
257
- }
258
- var result;
259
- if (0 === writePos) result = ";";
260
- else {
261
- while(writePos > 0 && outCodes[writePos - 1] === CC_SEMICOLON)writePos--;
262
- outCodes[writePos++] = CC_SEMICOLON;
263
- result = _normDecoder.decode(outCodes.subarray(0, writePos));
264
- }
265
- _normCache.set(sql, result);
266
- return result;
267
- }
268
59
  var DEFAULT_STATEMENT_TIMEOUT = 30000;
269
60
  function createTimeoutError(timeout, sql) {
270
- return new Error("SQLite statement timed out after ".concat(timeout, "ms: ").concat(normalizeSQL(sql)));
61
+ return new Error("SQLite statement timed out after ".concat(timeout, "ms: ").concat(sql));
271
62
  }
272
63
  function toError(value) {
273
64
  return value instanceof Error ? value : new Error(String(value));
@@ -298,56 +89,65 @@ function createJsonValueParser(onValue) {
298
89
  feed: function(chunk) {
299
90
  this.buffer += chunk;
300
91
  var consumeUntil = 0;
301
- for(var index = this.readPos; index < this.buffer.length; index++){
302
- var code = this.buffer.charCodeAt(index);
303
- if (-1 === this.start) {
92
+ var buffer = this.buffer;
93
+ var start = this.start;
94
+ var nesting = this.nesting;
95
+ var inString = this.inString;
96
+ var escaped = this.escaped;
97
+ for(var index = this.readPos; index < buffer.length; index++){
98
+ var code = buffer.charCodeAt(index);
99
+ if (-1 === start) {
304
100
  if (isWhitespaceCode(code)) continue;
305
101
  if (code !== CHAR_OPEN_BRACKET && code !== CHAR_OPEN_BRACE) continue;
306
- this.start = index;
307
- this.nesting = 1;
308
- this.inString = false;
309
- this.escaped = false;
102
+ start = index;
103
+ nesting = 1;
104
+ inString = false;
105
+ escaped = false;
310
106
  continue;
311
107
  }
312
- if (this.inString) {
313
- if (this.escaped) this.escaped = false;
314
- else if (code === CHAR_BACKSLASH) this.escaped = true;
315
- else if (code === CHAR_QUOTE) this.inString = false;
108
+ if (inString) {
109
+ if (escaped) escaped = false;
110
+ else if (code === CHAR_BACKSLASH) escaped = true;
111
+ else if (code === CHAR_QUOTE) inString = false;
316
112
  continue;
317
113
  }
318
114
  if (code === CHAR_QUOTE) {
319
- this.inString = true;
115
+ inString = true;
320
116
  continue;
321
117
  }
322
118
  if (code === CHAR_OPEN_BRACKET || code === CHAR_OPEN_BRACE) {
323
- this.nesting++;
119
+ nesting++;
324
120
  continue;
325
121
  }
326
122
  if (code === CHAR_CLOSE_BRACKET || code === CHAR_CLOSE_BRACE) {
327
- this.nesting--;
328
- if (0 === this.nesting) {
329
- if (index === this.start + 1) {
330
- this.start = -1;
123
+ nesting--;
124
+ if (0 === nesting) {
125
+ if (index === start + 1) {
126
+ start = -1;
331
127
  consumeUntil = index + 1;
332
128
  continue;
333
129
  }
334
- var raw = this.buffer.slice(this.start, index + 1);
335
- this.start = -1;
130
+ var raw = buffer.slice(start, index + 1);
131
+ start = -1;
336
132
  onValue(raw);
337
133
  consumeUntil = index + 1;
338
134
  }
339
135
  }
340
136
  }
137
+ this.start = start;
138
+ this.nesting = nesting;
139
+ this.inString = inString;
140
+ this.escaped = escaped;
341
141
  if (consumeUntil > 0) {
342
142
  this._consumed = consumeUntil;
343
- this.readPos = -1 !== this.start ? this.buffer.length : this._consumed;
143
+ this.readPos = -1 !== this.start ? buffer.length : this._consumed;
344
144
  if (this._consumed > 65536) {
345
145
  if (-1 !== this.start) this.start -= this._consumed;
346
146
  this.buffer = this.buffer.slice(this._consumed);
347
147
  this.readPos = this.buffer.length;
348
148
  this._consumed = 0;
349
149
  }
350
- } else this.readPos = this.buffer.length;
150
+ } else this.readPos = buffer.length;
351
151
  },
352
152
  reset: function() {
353
153
  this.buffer = "";
@@ -375,10 +175,18 @@ function createRowStreamParser(onRow) {
375
175
  feed: function(chunk) {
376
176
  if (this.finished) return chunk;
377
177
  this.buffer += chunk;
178
+ var buffer = this.buffer;
179
+ var started = this.started;
180
+ var inString = this.inString;
181
+ var escaped = this.escaped;
182
+ var elementStart = this.elementStart;
183
+ var elementEnd = this.elementEnd;
184
+ var nesting = this.nesting;
185
+ var consumed = this._consumed;
378
186
  var index = this.readPos;
379
- while(index < this.buffer.length){
380
- var code = this.buffer.charCodeAt(index);
381
- if (!this.started) {
187
+ while(index < buffer.length){
188
+ var code = buffer.charCodeAt(index);
189
+ if (!started) {
382
190
  if (isWhitespaceCode(code)) {
383
191
  index++;
384
192
  continue;
@@ -387,74 +195,81 @@ function createRowStreamParser(onRow) {
387
195
  index++;
388
196
  continue;
389
197
  }
390
- this.started = true;
198
+ started = true;
391
199
  index++;
392
200
  continue;
393
201
  }
394
- if (this.inString) {
395
- if (this.escaped) this.escaped = false;
396
- else if (code === CHAR_BACKSLASH) this.escaped = true;
397
- else if (code === CHAR_QUOTE) this.inString = false;
202
+ if (inString) {
203
+ if (escaped) escaped = false;
204
+ else if (code === CHAR_BACKSLASH) escaped = true;
205
+ else if (code === CHAR_QUOTE) inString = false;
398
206
  index++;
399
207
  continue;
400
208
  }
401
- if (-1 === this.elementStart) {
209
+ if (-1 === elementStart) {
402
210
  if (isWhitespaceCode(code) || code === CHAR_COMMA) {
403
211
  index++;
404
212
  continue;
405
213
  }
406
214
  if (code === CHAR_CLOSE_BRACKET) {
407
215
  this.finished = true;
408
- var leftover = this.buffer.slice(index + 1);
409
- this.buffer = "";
410
216
  this.readPos = 0;
411
- return leftover;
217
+ this.buffer = "";
218
+ this.started = false;
219
+ return buffer.slice(index + 1);
412
220
  }
413
- this.elementStart = index;
414
- this.elementEnd = -1;
415
- this.nesting = code === CHAR_OPEN_BRACE || code === CHAR_OPEN_BRACKET ? 1 : 0;
416
- this.inString = code === CHAR_QUOTE;
221
+ elementStart = index;
222
+ elementEnd = -1;
223
+ nesting = code === CHAR_OPEN_BRACE || code === CHAR_OPEN_BRACKET ? 1 : 0;
224
+ inString = code === CHAR_QUOTE;
225
+ escaped = false;
417
226
  index++;
418
227
  continue;
419
228
  }
420
229
  if (code === CHAR_QUOTE) {
421
- this.inString = true;
230
+ inString = true;
422
231
  index++;
423
232
  continue;
424
233
  }
425
234
  if (code === CHAR_OPEN_BRACE || code === CHAR_OPEN_BRACKET) {
426
- this.nesting++;
235
+ nesting++;
427
236
  index++;
428
237
  continue;
429
238
  }
430
239
  if (code === CHAR_CLOSE_BRACE || code === CHAR_CLOSE_BRACKET) {
431
- this.nesting--;
432
- if (0 === this.nesting) this.elementEnd = index + 1;
240
+ nesting--;
241
+ if (0 === nesting) elementEnd = index + 1;
433
242
  }
434
- if (-1 !== this.elementEnd) {
243
+ if (-1 !== elementEnd) {
435
244
  var lookAhead = index + 1;
436
- while(lookAhead < this.buffer.length && isWhitespaceCode(this.buffer.charCodeAt(lookAhead)))lookAhead++;
437
- if (lookAhead < this.buffer.length) {
438
- var delimiter = this.buffer.charCodeAt(lookAhead);
245
+ while(lookAhead < buffer.length && isWhitespaceCode(buffer.charCodeAt(lookAhead)))lookAhead++;
246
+ if (lookAhead < buffer.length) {
247
+ var delimiter = buffer.charCodeAt(lookAhead);
439
248
  if (delimiter === CHAR_COMMA || delimiter === CHAR_CLOSE_BRACKET) {
440
- onRow(this.buffer.slice(this.elementStart, this.elementEnd));
441
- this._consumed = lookAhead + 1;
442
- this.elementStart = -1;
443
- this.elementEnd = -1;
444
- this.nesting = 0;
249
+ onRow(buffer.slice(elementStart, elementEnd));
250
+ consumed = lookAhead + 1;
251
+ elementStart = -1;
252
+ elementEnd = -1;
253
+ nesting = 0;
445
254
  if (delimiter === CHAR_CLOSE_BRACKET) {
446
255
  this.finished = true;
447
- var tail = this.buffer.slice(this._consumed);
448
256
  this.buffer = "";
257
+ this.started = false;
258
+ this.inString = false;
259
+ this.escaped = false;
260
+ this.elementStart = -1;
261
+ this.elementEnd = -1;
262
+ this.nesting = 0;
449
263
  this._consumed = 0;
450
264
  this.readPos = 0;
451
- return tail;
265
+ return buffer.slice(consumed);
452
266
  }
453
- index = this._consumed;
454
- if (this._consumed > 65536) {
455
- this.buffer = this.buffer.slice(this._consumed);
456
- index = 0;
267
+ index = consumed;
268
+ if (consumed > 65536) {
269
+ this.buffer = buffer.slice(consumed);
457
270
  this._consumed = 0;
271
+ index = 0;
272
+ consumed = 0;
458
273
  }
459
274
  continue;
460
275
  }
@@ -462,12 +277,19 @@ function createRowStreamParser(onRow) {
462
277
  }
463
278
  index++;
464
279
  }
465
- if (this._consumed > 0) {
466
- if (-1 !== this.elementStart) {
467
- this.elementStart -= this._consumed;
468
- if (-1 !== this.elementEnd) this.elementEnd -= this._consumed;
280
+ this.started = started;
281
+ this.inString = inString;
282
+ this.escaped = escaped;
283
+ this.elementStart = elementStart;
284
+ this.elementEnd = elementEnd;
285
+ this.nesting = nesting;
286
+ this._consumed = consumed;
287
+ if (consumed > 0) {
288
+ if (-1 !== elementStart) {
289
+ this.elementStart -= consumed;
290
+ if (-1 !== elementEnd) this.elementEnd -= consumed;
469
291
  }
470
- this.buffer = this.buffer.slice(this._consumed);
292
+ this.buffer = buffer.slice(consumed);
471
293
  this._consumed = 0;
472
294
  }
473
295
  if (this.elementStart > 0) {
@@ -495,14 +317,14 @@ function createRowStreamParser(onRow) {
495
317
  var TOKEN_COLUMN = "__sqlite_executor_token__";
496
318
  var DEFAULT_BATCH_SIZE = 10;
497
319
  var DEFAULT_MAX_INFLIGHT = 50;
498
- function stream_check_private_redeclaration(obj, privateCollection) {
320
+ function _check_private_redeclaration(obj, privateCollection) {
499
321
  if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
500
322
  }
501
- function stream_class_apply_descriptor_get(receiver, descriptor) {
323
+ function _class_apply_descriptor_get(receiver, descriptor) {
502
324
  if (descriptor.get) return descriptor.get.call(receiver);
503
325
  return descriptor.value;
504
326
  }
505
- function stream_class_apply_descriptor_set(receiver, descriptor, value) {
327
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
506
328
  if (descriptor.set) descriptor.set.call(receiver, value);
507
329
  else {
508
330
  if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
@@ -525,31 +347,31 @@ function _class_apply_descriptor_update(receiver, descriptor) {
525
347
  if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
526
348
  return descriptor;
527
349
  }
528
- function stream_class_call_check(instance, Constructor) {
350
+ function _class_call_check(instance, Constructor) {
529
351
  if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
530
352
  }
531
- function stream_class_extract_field_descriptor(receiver, privateMap, action) {
353
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
532
354
  if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
533
355
  return privateMap.get(receiver);
534
356
  }
535
- function stream_class_private_field_get(receiver, privateMap) {
536
- var descriptor = stream_class_extract_field_descriptor(receiver, privateMap, "get");
537
- return stream_class_apply_descriptor_get(receiver, descriptor);
357
+ function _class_private_field_get(receiver, privateMap) {
358
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
359
+ return _class_apply_descriptor_get(receiver, descriptor);
538
360
  }
539
- function stream_class_private_field_init(obj, privateMap, value) {
540
- stream_check_private_redeclaration(obj, privateMap);
361
+ function _class_private_field_init(obj, privateMap, value) {
362
+ _check_private_redeclaration(obj, privateMap);
541
363
  privateMap.set(obj, value);
542
364
  }
543
- function stream_class_private_field_set(receiver, privateMap, value) {
544
- var descriptor = stream_class_extract_field_descriptor(receiver, privateMap, "set");
545
- stream_class_apply_descriptor_set(receiver, descriptor, value);
365
+ function _class_private_field_set(receiver, privateMap, value) {
366
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
367
+ _class_apply_descriptor_set(receiver, descriptor, value);
546
368
  return value;
547
369
  }
548
370
  function _class_private_field_update(receiver, privateMap) {
549
- var descriptor = stream_class_extract_field_descriptor(receiver, privateMap, "update");
371
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "update");
550
372
  return _class_apply_descriptor_update(receiver, descriptor);
551
373
  }
552
- function stream_defineProperties(target, props) {
374
+ function _defineProperties(target, props) {
553
375
  for(var i = 0; i < props.length; i++){
554
376
  var descriptor = props[i];
555
377
  descriptor.enumerable = descriptor.enumerable || false;
@@ -558,9 +380,9 @@ function stream_defineProperties(target, props) {
558
380
  Object.defineProperty(target, descriptor.key, descriptor);
559
381
  }
560
382
  }
561
- function stream_create_class(Constructor, protoProps, staticProps) {
562
- if (protoProps) stream_defineProperties(Constructor.prototype, protoProps);
563
- if (staticProps) stream_defineProperties(Constructor, staticProps);
383
+ function _create_class(Constructor, protoProps, staticProps) {
384
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
385
+ if (staticProps) _defineProperties(Constructor, staticProps);
564
386
  return Constructor;
565
387
  }
566
388
  function _type_of(obj) {
@@ -590,50 +412,50 @@ var _computedKey1 = _computedKey;
590
412
  var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
591
413
  "use strict";
592
414
  function AsyncRowBuffer() {
593
- stream_class_call_check(this, AsyncRowBuffer);
594
- stream_class_private_field_init(this, _buffer, {
415
+ _class_call_check(this, AsyncRowBuffer);
416
+ _class_private_field_init(this, _buffer, {
595
417
  writable: true,
596
418
  value: []
597
419
  });
598
- stream_class_private_field_init(this, _index, {
420
+ _class_private_field_init(this, _index, {
599
421
  writable: true,
600
422
  value: 0
601
423
  });
602
- stream_class_private_field_init(this, _done, {
424
+ _class_private_field_init(this, _done, {
603
425
  writable: true,
604
426
  value: false
605
427
  });
606
- stream_class_private_field_init(this, _error, {
428
+ _class_private_field_init(this, _error, {
607
429
  writable: true,
608
430
  value: null
609
431
  });
610
- stream_class_private_field_init(this, _pending, {
432
+ _class_private_field_init(this, _pending, {
611
433
  writable: true,
612
434
  value: null
613
435
  });
614
436
  }
615
- stream_create_class(AsyncRowBuffer, [
437
+ _create_class(AsyncRowBuffer, [
616
438
  {
617
439
  key: "push",
618
440
  value: function(row) {
619
- if (stream_class_private_field_get(this, _done) || stream_class_private_field_get(this, _error)) return;
620
- if (stream_class_private_field_get(this, _pending)) {
621
- var resolve = stream_class_private_field_get(this, _pending).resolve;
622
- stream_class_private_field_set(this, _pending, null);
441
+ if (_class_private_field_get(this, _done) || _class_private_field_get(this, _error)) return;
442
+ if (_class_private_field_get(this, _pending)) {
443
+ var resolve = _class_private_field_get(this, _pending).resolve;
444
+ _class_private_field_set(this, _pending, null);
623
445
  resolve({
624
446
  value: row,
625
447
  done: false
626
448
  });
627
- } else stream_class_private_field_get(this, _buffer).push(row);
449
+ } else _class_private_field_get(this, _buffer).push(row);
628
450
  }
629
451
  },
630
452
  {
631
453
  key: "end",
632
454
  value: function() {
633
- stream_class_private_field_set(this, _done, true);
634
- if (stream_class_private_field_get(this, _pending)) {
635
- var resolve = stream_class_private_field_get(this, _pending).resolve;
636
- stream_class_private_field_set(this, _pending, null);
455
+ _class_private_field_set(this, _done, true);
456
+ if (_class_private_field_get(this, _pending)) {
457
+ var resolve = _class_private_field_get(this, _pending).resolve;
458
+ _class_private_field_set(this, _pending, null);
637
459
  resolve({
638
460
  value: void 0,
639
461
  done: true
@@ -644,10 +466,10 @@ var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
644
466
  {
645
467
  key: "error",
646
468
  value: function(err) {
647
- stream_class_private_field_set(this, _error, err);
648
- if (stream_class_private_field_get(this, _pending)) {
649
- var reject = stream_class_private_field_get(this, _pending).reject;
650
- stream_class_private_field_set(this, _pending, null);
469
+ _class_private_field_set(this, _error, err);
470
+ if (_class_private_field_get(this, _pending)) {
471
+ var reject = _class_private_field_get(this, _pending).reject;
472
+ _class_private_field_set(this, _pending, null);
651
473
  reject(err);
652
474
  }
653
475
  }
@@ -656,17 +478,17 @@ var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
656
478
  key: "next",
657
479
  value: function() {
658
480
  var _this = this;
659
- if (stream_class_private_field_get(this, _index) < stream_class_private_field_get(this, _buffer).length) return Promise.resolve({
660
- value: stream_class_private_field_get(this, _buffer)[_class_private_field_update(this, _index).value++],
481
+ if (_class_private_field_get(this, _index) < _class_private_field_get(this, _buffer).length) return Promise.resolve({
482
+ value: _class_private_field_get(this, _buffer)[_class_private_field_update(this, _index).value++],
661
483
  done: false
662
484
  });
663
- if (stream_class_private_field_get(this, _done)) return Promise.resolve({
485
+ if (_class_private_field_get(this, _done)) return Promise.resolve({
664
486
  value: void 0,
665
487
  done: true
666
488
  });
667
- if (stream_class_private_field_get(this, _error)) return Promise.reject(stream_class_private_field_get(this, _error));
489
+ if (_class_private_field_get(this, _error)) return Promise.reject(_class_private_field_get(this, _error));
668
490
  return new Promise(function(resolve, reject) {
669
- stream_class_private_field_set(_this, _pending, {
491
+ _class_private_field_set(_this, _pending, {
670
492
  resolve: resolve,
671
493
  reject: reject
672
494
  });
@@ -676,12 +498,12 @@ var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
676
498
  {
677
499
  key: "return",
678
500
  value: function() {
679
- stream_class_private_field_set(this, _done, true);
680
- stream_class_private_field_set(this, _buffer, []);
681
- stream_class_private_field_set(this, _index, 0);
682
- if (stream_class_private_field_get(this, _pending)) {
683
- var resolve = stream_class_private_field_get(this, _pending).resolve;
684
- stream_class_private_field_set(this, _pending, null);
501
+ _class_private_field_set(this, _done, true);
502
+ _class_private_field_set(this, _buffer, []);
503
+ _class_private_field_set(this, _index, 0);
504
+ if (_class_private_field_get(this, _pending)) {
505
+ var resolve = _class_private_field_get(this, _pending).resolve;
506
+ _class_private_field_set(this, _pending, null);
685
507
  resolve({
686
508
  value: void 0,
687
509
  done: true
@@ -1221,6 +1043,119 @@ function generateToken() {
1221
1043
  _counter = _counter + 1 >>> 0;
1222
1044
  return "".concat(_PREFIX).concat(_counter.toString(36), "_").concat(_PID36);
1223
1045
  }
1046
+ function lruCache_check_private_redeclaration(obj, privateCollection) {
1047
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
1048
+ }
1049
+ function lruCache_class_apply_descriptor_get(receiver, descriptor) {
1050
+ if (descriptor.get) return descriptor.get.call(receiver);
1051
+ return descriptor.value;
1052
+ }
1053
+ function lruCache_class_apply_descriptor_set(receiver, descriptor, value) {
1054
+ if (descriptor.set) descriptor.set.call(receiver, value);
1055
+ else {
1056
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
1057
+ descriptor.value = value;
1058
+ }
1059
+ }
1060
+ function lruCache_class_call_check(instance, Constructor) {
1061
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
1062
+ }
1063
+ function lruCache_class_extract_field_descriptor(receiver, privateMap, action) {
1064
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
1065
+ return privateMap.get(receiver);
1066
+ }
1067
+ function lruCache_class_private_field_get(receiver, privateMap) {
1068
+ var descriptor = lruCache_class_extract_field_descriptor(receiver, privateMap, "get");
1069
+ return lruCache_class_apply_descriptor_get(receiver, descriptor);
1070
+ }
1071
+ function lruCache_class_private_field_init(obj, privateMap, value) {
1072
+ lruCache_check_private_redeclaration(obj, privateMap);
1073
+ privateMap.set(obj, value);
1074
+ }
1075
+ function lruCache_class_private_field_set(receiver, privateMap, value) {
1076
+ var descriptor = lruCache_class_extract_field_descriptor(receiver, privateMap, "set");
1077
+ lruCache_class_apply_descriptor_set(receiver, descriptor, value);
1078
+ return value;
1079
+ }
1080
+ function lruCache_defineProperties(target, props) {
1081
+ for(var i = 0; i < props.length; i++){
1082
+ var descriptor = props[i];
1083
+ descriptor.enumerable = descriptor.enumerable || false;
1084
+ descriptor.configurable = true;
1085
+ if ("value" in descriptor) descriptor.writable = true;
1086
+ Object.defineProperty(target, descriptor.key, descriptor);
1087
+ }
1088
+ }
1089
+ function lruCache_create_class(Constructor, protoProps, staticProps) {
1090
+ if (protoProps) lruCache_defineProperties(Constructor.prototype, protoProps);
1091
+ if (staticProps) lruCache_defineProperties(Constructor, staticProps);
1092
+ return Constructor;
1093
+ }
1094
+ var _maxSize = /*#__PURE__*/ new WeakMap(), _maxKeyLength = /*#__PURE__*/ new WeakMap(), _maxValueLength = /*#__PURE__*/ new WeakMap(), _map = /*#__PURE__*/ new WeakMap();
1095
+ var lruCache_LRUCache = /*#__PURE__*/ function() {
1096
+ "use strict";
1097
+ function LRUCache() {
1098
+ var _ref = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, _ref_maxSize = _ref.maxSize, maxSize = void 0 === _ref_maxSize ? 256 : _ref_maxSize, _ref_maxKeyLength = _ref.maxKeyLength, maxKeyLength = void 0 === _ref_maxKeyLength ? 4096 : _ref_maxKeyLength, _ref_maxValueLength = _ref.maxValueLength, maxValueLength = void 0 === _ref_maxValueLength ? 1 / 0 : _ref_maxValueLength;
1099
+ lruCache_class_call_check(this, LRUCache);
1100
+ lruCache_class_private_field_init(this, _maxSize, {
1101
+ writable: true,
1102
+ value: void 0
1103
+ });
1104
+ lruCache_class_private_field_init(this, _maxKeyLength, {
1105
+ writable: true,
1106
+ value: void 0
1107
+ });
1108
+ lruCache_class_private_field_init(this, _maxValueLength, {
1109
+ writable: true,
1110
+ value: void 0
1111
+ });
1112
+ lruCache_class_private_field_init(this, _map, {
1113
+ writable: true,
1114
+ value: new Map()
1115
+ });
1116
+ lruCache_class_private_field_set(this, _maxSize, Math.max(1, maxSize));
1117
+ lruCache_class_private_field_set(this, _maxKeyLength, maxKeyLength);
1118
+ lruCache_class_private_field_set(this, _maxValueLength, maxValueLength);
1119
+ }
1120
+ lruCache_create_class(LRUCache, [
1121
+ {
1122
+ key: "get",
1123
+ value: function(key) {
1124
+ if ("string" != typeof key || key.length > lruCache_class_private_field_get(this, _maxKeyLength)) return;
1125
+ var value = lruCache_class_private_field_get(this, _map).get(key);
1126
+ if (void 0 === value) return;
1127
+ lruCache_class_private_field_get(this, _map)["delete"](key);
1128
+ lruCache_class_private_field_get(this, _map).set(key, value);
1129
+ return value;
1130
+ }
1131
+ },
1132
+ {
1133
+ key: "set",
1134
+ value: function(key, value) {
1135
+ if ("string" != typeof key || key.length > lruCache_class_private_field_get(this, _maxKeyLength)) return;
1136
+ if (value && value.length > lruCache_class_private_field_get(this, _maxValueLength)) return;
1137
+ if (lruCache_class_private_field_get(this, _map).size >= lruCache_class_private_field_get(this, _maxSize)) {
1138
+ var firstKey = lruCache_class_private_field_get(this, _map).keys().next().value;
1139
+ lruCache_class_private_field_get(this, _map)["delete"](firstKey);
1140
+ }
1141
+ lruCache_class_private_field_get(this, _map).set(key, value);
1142
+ }
1143
+ },
1144
+ {
1145
+ key: "size",
1146
+ get: function() {
1147
+ return lruCache_class_private_field_get(this, _map).size;
1148
+ }
1149
+ },
1150
+ {
1151
+ key: "clear",
1152
+ value: function() {
1153
+ lruCache_class_private_field_get(this, _map).clear();
1154
+ }
1155
+ }
1156
+ ]);
1157
+ return LRUCache;
1158
+ }();
1224
1159
  function escape_type_of(obj) {
1225
1160
  return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj;
1226
1161
  }
@@ -1232,110 +1167,168 @@ function escapeValue(value) {
1232
1167
  if (value instanceof Date) return "'".concat(value.toISOString(), "'");
1233
1168
  throw new TypeError("Unsupported parameter type: ".concat(void 0 === value ? "undefined" : escape_type_of(value)));
1234
1169
  }
1235
- var _interpCache = new lruCache_LRUCache({
1170
+ new lruCache_LRUCache({
1236
1171
  maxSize: 256,
1237
1172
  maxKeyLength: 4096
1238
1173
  });
1239
- function _parseTemplate(sql) {
1240
- var segments = [];
1241
- var segStart = 0;
1242
- var state = STATE_NORMAL;
1243
- var stateStartPos = -1;
1244
- for(var pos = 0; pos < sql.length; pos++){
1245
- var code = sql.charCodeAt(pos);
1246
- if (state === STATE_NORMAL) {
1247
- if (code === CC_SINGLE_QUOTE) {
1248
- state = STATE_SINGLE_QUOTE;
1249
- stateStartPos = pos;
1250
- continue;
1174
+ function interpolateFromTemplate(template, params) {
1175
+ var segments = template.segments, paramCount = template.paramCount;
1176
+ if (params.length < paramCount) throw new Error("Too few parameters provided");
1177
+ if (params.length > paramCount) throw new Error("Too many parameters provided");
1178
+ if (0 === paramCount) return segments[0];
1179
+ var parts = [
1180
+ segments[0]
1181
+ ];
1182
+ for(var i = 0; i < params.length; i++){
1183
+ parts.push(escapeValue(params[i]));
1184
+ parts.push(segments[i + 1]);
1185
+ }
1186
+ return parts.join("");
1187
+ }
1188
+ var constants_CC_SINGLE_QUOTE = 39;
1189
+ var constants_CC_DOUBLE_QUOTE = 34;
1190
+ var constants_CC_DASH = 45;
1191
+ var constants_CC_SLASH = 47;
1192
+ var constants_CC_STAR = 42;
1193
+ var constants_CC_NEWLINE = 10;
1194
+ var constants_CC_QUESTION = 63;
1195
+ var CC_SEMICOLON = 59;
1196
+ var CC_SPACE = 32;
1197
+ var constants_STATE_NORMAL = 0;
1198
+ var constants_STATE_SINGLE_QUOTE = 1;
1199
+ var constants_STATE_DOUBLE_QUOTE = 2;
1200
+ var constants_STATE_LINE_COMMENT = 3;
1201
+ var constants_STATE_BLOCK_COMMENT = 4;
1202
+ var _normDecoder = new TextDecoder("utf-16le");
1203
+ var _normCache = new lruCache_LRUCache({
1204
+ maxSize: 256,
1205
+ maxKeyLength: 4096
1206
+ });
1207
+ function _normalize(sql) {
1208
+ var len = sql.length;
1209
+ var needed = len + 1;
1210
+ var outCodes = new Uint16Array(needed);
1211
+ var writePos = 0;
1212
+ var pendingSpace = false;
1213
+ var state = constants_STATE_NORMAL;
1214
+ var questionPositions = [];
1215
+ for(var i = 0; i < len; i++){
1216
+ var code = sql.charCodeAt(i);
1217
+ var nextCode = sql.charCodeAt(i + 1);
1218
+ if (state === constants_STATE_BLOCK_COMMENT) {
1219
+ if (code === constants_CC_STAR && nextCode === constants_CC_SLASH) {
1220
+ state = constants_STATE_NORMAL;
1221
+ i++;
1222
+ if (writePos > 0) pendingSpace = true;
1251
1223
  }
1252
- if (code === CC_DOUBLE_QUOTE) {
1253
- state = STATE_DOUBLE_QUOTE;
1254
- stateStartPos = pos;
1255
- continue;
1224
+ continue;
1225
+ }
1226
+ if (state === constants_STATE_LINE_COMMENT) {
1227
+ if (code === constants_CC_NEWLINE) {
1228
+ state = constants_STATE_NORMAL;
1229
+ if (writePos > 0) pendingSpace = true;
1256
1230
  }
1257
- if (code === CC_DASH && sql.charCodeAt(pos + 1) === CC_DASH) {
1258
- state = STATE_LINE_COMMENT;
1259
- pos++;
1231
+ continue;
1232
+ }
1233
+ if (state === constants_STATE_NORMAL) {
1234
+ if (code === constants_CC_DASH && nextCode === constants_CC_DASH) {
1235
+ state = constants_STATE_LINE_COMMENT;
1236
+ i++;
1260
1237
  continue;
1261
1238
  }
1262
- if (code === CC_SLASH && sql.charCodeAt(pos + 1) === CC_STAR) {
1263
- state = STATE_BLOCK_COMMENT;
1264
- stateStartPos = pos;
1265
- pos++;
1239
+ if (code === constants_CC_SLASH && nextCode === constants_CC_STAR) {
1240
+ state = constants_STATE_BLOCK_COMMENT;
1241
+ i++;
1266
1242
  continue;
1267
1243
  }
1268
- if (code === CC_QUESTION) {
1269
- segments.push(sql.slice(segStart, pos));
1270
- segStart = pos + 1;
1271
- }
1272
- continue;
1273
1244
  }
1274
- if (state === STATE_SINGLE_QUOTE) {
1275
- if (code === CC_SINGLE_QUOTE) {
1276
- if (sql.charCodeAt(pos + 1) === CC_SINGLE_QUOTE) {
1277
- pos++;
1278
- continue;
1279
- }
1280
- state = STATE_NORMAL;
1281
- stateStartPos = -1;
1282
- }
1245
+ if (32 === code || 9 === code || 10 === code || 11 === code || 12 === code || 13 === code) {
1246
+ if (writePos > 0) pendingSpace = true;
1283
1247
  continue;
1284
1248
  }
1285
- if (state === STATE_DOUBLE_QUOTE) {
1286
- if (code === CC_DOUBLE_QUOTE) {
1287
- if (sql.charCodeAt(pos + 1) === CC_DOUBLE_QUOTE) {
1288
- pos++;
1289
- continue;
1290
- }
1291
- state = STATE_NORMAL;
1292
- stateStartPos = -1;
1293
- }
1249
+ if (pendingSpace && writePos > 0) {
1250
+ outCodes[writePos++] = CC_SPACE;
1251
+ pendingSpace = false;
1252
+ }
1253
+ if (code === constants_CC_QUESTION && state === constants_STATE_NORMAL) questionPositions.push(writePos);
1254
+ outCodes[writePos++] = code;
1255
+ if (state === constants_STATE_NORMAL) {
1256
+ if (code === constants_CC_SINGLE_QUOTE) state = constants_STATE_SINGLE_QUOTE;
1257
+ else if (code === constants_CC_DOUBLE_QUOTE) state = constants_STATE_DOUBLE_QUOTE;
1294
1258
  continue;
1295
1259
  }
1296
- if (state === STATE_LINE_COMMENT) {
1297
- if (code === CC_NEWLINE) state = STATE_NORMAL;
1260
+ if (state === constants_STATE_SINGLE_QUOTE) {
1261
+ if (code === constants_CC_SINGLE_QUOTE && nextCode === constants_CC_SINGLE_QUOTE) {
1262
+ outCodes[writePos++] = nextCode;
1263
+ i++;
1264
+ continue;
1265
+ }
1266
+ if (code === constants_CC_SINGLE_QUOTE) state = constants_STATE_NORMAL;
1298
1267
  continue;
1299
1268
  }
1300
- if (state === STATE_BLOCK_COMMENT) {
1301
- if (code === CC_STAR && sql.charCodeAt(pos + 1) === CC_SLASH) {
1302
- pos++;
1303
- state = STATE_NORMAL;
1304
- stateStartPos = -1;
1269
+ if (state === constants_STATE_DOUBLE_QUOTE) {
1270
+ if (code === constants_CC_DOUBLE_QUOTE && nextCode === constants_CC_DOUBLE_QUOTE) {
1271
+ outCodes[writePos++] = nextCode;
1272
+ i++;
1273
+ continue;
1305
1274
  }
1275
+ if (code === constants_CC_DOUBLE_QUOTE) state = constants_STATE_NORMAL;
1306
1276
  }
1307
1277
  }
1308
- if (state === STATE_SINGLE_QUOTE) throw new Error("Unterminated single-quoted string starting at position ".concat(stateStartPos + 1));
1309
- if (state === STATE_DOUBLE_QUOTE) throw new Error("Unterminated double-quoted identifier/string starting at position ".concat(stateStartPos + 1));
1310
- if (state === STATE_BLOCK_COMMENT) throw new Error("Unterminated block comment starting at position ".concat(stateStartPos + 1));
1311
- segments.push(sql.slice(segStart));
1278
+ var normalized;
1279
+ if (0 === writePos) normalized = ";";
1280
+ else {
1281
+ while(writePos > 0 && outCodes[writePos - 1] === CC_SEMICOLON)writePos--;
1282
+ outCodes[writePos++] = CC_SEMICOLON;
1283
+ normalized = _normDecoder.decode(outCodes.subarray(0, writePos));
1284
+ }
1285
+ var paramCount = questionPositions.length;
1286
+ if (0 === paramCount) return {
1287
+ normalized: normalized,
1288
+ segments: [
1289
+ normalized
1290
+ ],
1291
+ paramCount: 0
1292
+ };
1293
+ var segments = [];
1294
+ var segStart = 0;
1295
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1296
+ try {
1297
+ for(var _iterator = questionPositions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1298
+ var pos = _step.value;
1299
+ segments.push(normalized.slice(segStart, pos));
1300
+ segStart = pos + 1;
1301
+ }
1302
+ } catch (err) {
1303
+ _didIteratorError = true;
1304
+ _iteratorError = err;
1305
+ } finally{
1306
+ try {
1307
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
1308
+ } finally{
1309
+ if (_didIteratorError) throw _iteratorError;
1310
+ }
1311
+ }
1312
+ segments.push(normalized.slice(segStart));
1312
1313
  return {
1314
+ normalized: normalized,
1313
1315
  segments: segments,
1314
- paramCount: segments.length - 1
1316
+ paramCount: paramCount
1315
1317
  };
1316
1318
  }
1317
- function interpolateSQL(sql, params) {
1318
- if (!sql.includes("?")) {
1319
- if (params.length > 0) throw new Error("Too many parameters provided");
1320
- return sql;
1321
- }
1322
- var template = _interpCache.get(sql);
1323
- if (void 0 === template) {
1324
- template = _parseTemplate(sql);
1325
- _interpCache.set(sql, template);
1326
- }
1327
- var segments = template.segments, paramCount = template.paramCount;
1328
- if (params.length < paramCount) throw new Error("Too few parameters provided");
1329
- if (params.length > paramCount) throw new Error("Too many parameters provided");
1330
- if (0 === paramCount) return segments[0];
1331
- var parts = [
1332
- segments[0]
1333
- ];
1334
- for(var i = 0; i < params.length; i++){
1335
- parts.push(escapeValue(params[i]));
1336
- parts.push(segments[i + 1]);
1337
- }
1338
- return parts.join("");
1319
+ function normalizeSQL(sql) {
1320
+ var cached = _normCache.get(sql);
1321
+ if (void 0 !== cached) return cached.normalized;
1322
+ var result = _normalize(sql);
1323
+ _normCache.set(sql, result);
1324
+ return result.normalized;
1325
+ }
1326
+ function normalizeSQLTemplate(sql) {
1327
+ var cached = _normCache.get(sql);
1328
+ if (void 0 !== cached) return cached;
1329
+ var result = _normalize(sql);
1330
+ _normCache.set(sql, result);
1331
+ return result;
1339
1332
  }
1340
1333
  var READ_ONLY_KINDS = new Set([
1341
1334
  "SELECT",
@@ -1361,7 +1354,10 @@ function classifySQL(sql) {
1361
1354
  if (0 === trimmed.length) return "write";
1362
1355
  var result;
1363
1356
  if (trimmed.includes(";")) {
1364
- var stmts = trimmed.split(";");
1357
+ var stmts = trimmed.split(";").filter(function(s) {
1358
+ return s.trim().length > 0;
1359
+ });
1360
+ if (0 === stmts.length) return "write";
1365
1361
  result = "read";
1366
1362
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1367
1363
  try {
@@ -1782,8 +1778,11 @@ function buildPayload(sql, token) {
1782
1778
  return "".concat(normalized).concat(suffix, "\nSELECT '").concat(token, "' AS ").concat(TOKEN_COLUMN, ";\n");
1783
1779
  }
1784
1780
  function isTransactionControl(sql) {
1785
- var s = sql.toUpperCase();
1786
- return "BEGIN" === s || "BEGIN TRANSACTION" === s || "COMMIT" === s || "COMMIT TRANSACTION" === s || "ROLLBACK" === s || "ROLLBACK TRANSACTION" === s || s.startsWith("BEGIN ") || s.startsWith("COMMIT ") || s.startsWith("ROLLBACK ");
1781
+ var f = sql.charCodeAt(0);
1782
+ if (66 === f || 98 === f) return "BEGIN" === sql || "BEGIN;" === sql || sql.startsWith("BEGIN ") || sql.startsWith("BEGIN;");
1783
+ if (67 === f || 99 === f) return "COMMIT" === sql || "COMMIT;" === sql || sql.startsWith("COMMIT ") || sql.startsWith("COMMIT;");
1784
+ if (82 === f || 114 === f) return "ROLLBACK" === sql || "ROLLBACK;" === sql || sql.startsWith("ROLLBACK ") || sql.startsWith("ROLLBACK;");
1785
+ return false;
1787
1786
  }
1788
1787
  function buildBatchPayload(batch) {
1789
1788
  var useWalBatch = batch.length > 1 && batch.every(function(t) {
@@ -1850,43 +1849,20 @@ function buildBatchPayload(batch) {
1850
1849
  return parts1.join("");
1851
1850
  }
1852
1851
  var TC_FIRST_CHAR = TOKEN_COLUMN.charCodeAt(0);
1852
+ function buildSentinelStr(token) {
1853
+ return '[{"'.concat(TOKEN_COLUMN, '":"').concat(token, '"}]');
1854
+ }
1853
1855
  function isSentinelRaw(raw, token) {
1854
- return raw.charCodeAt(3) === TC_FIRST_CHAR && raw === '[{"'.concat(TOKEN_COLUMN, '":"').concat(token, '"}]');
1856
+ return raw.charCodeAt(3) === TC_FIRST_CHAR && raw === buildSentinelStr(token);
1855
1857
  }
1856
1858
  function isSentinelRow(value, token) {
1857
1859
  var _value_;
1858
1860
  return Array.isArray(value) && 1 === value.length && (null == (_value_ = value[0]) ? void 0 : _value_[TOKEN_COLUMN]) === token;
1859
1861
  }
1860
- function _array_like_to_array(arr, len) {
1861
- if (null == len || len > arr.length) len = arr.length;
1862
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1863
- return arr2;
1864
- }
1865
- function _array_without_holes(arr) {
1866
- if (Array.isArray(arr)) return _array_like_to_array(arr);
1867
- }
1868
- function _iterable_to_array(iter) {
1869
- if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
1870
- }
1871
- function _non_iterable_spread() {
1872
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1873
- }
1874
- function _to_consumable_array(arr) {
1875
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
1876
- }
1877
- function _unsupported_iterable_to_array(o, minLen) {
1878
- if (!o) return;
1879
- if ("string" == typeof o) return _array_like_to_array(o, minLen);
1880
- var n = Object.prototype.toString.call(o).slice(8, -1);
1881
- if ("Object" === n && o.constructor) n = o.constructor.name;
1882
- if ("Map" === n || "Set" === n) return Array.from(n);
1883
- if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1884
- }
1885
1862
  function collectQueryRows(task, parsed) {
1886
1863
  if (Array.isArray(parsed)) {
1887
- var _task_rows;
1888
1864
  if (!task.rows) task.rows = [];
1889
- (_task_rows = task.rows).push.apply(_task_rows, _to_consumable_array(parsed));
1865
+ for(var i = 0; i < parsed.length; i++)task.rows.push(parsed[i]);
1890
1866
  }
1891
1867
  }
1892
1868
  function processStreamRows(task, parsed) {
@@ -1968,13 +1944,13 @@ function prepareTaskTimeout(task, metrics) {
1968
1944
  null == metrics || metrics.incrementTasksTimeout();
1969
1945
  return createTimeoutError(task.timeout, task.sql);
1970
1946
  }
1971
- function taskWorker_array_like_to_array(arr, len) {
1947
+ function _array_like_to_array(arr, len) {
1972
1948
  if (null == len || len > arr.length) len = arr.length;
1973
1949
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1974
1950
  return arr2;
1975
1951
  }
1976
- function taskWorker_array_without_holes(arr) {
1977
- if (Array.isArray(arr)) return taskWorker_array_like_to_array(arr);
1952
+ function _array_without_holes(arr) {
1953
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
1978
1954
  }
1979
1955
  function taskWorker_check_private_redeclaration(obj, privateCollection) {
1980
1956
  if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -1990,6 +1966,22 @@ function taskWorker_class_apply_descriptor_set(receiver, descriptor, value) {
1990
1966
  descriptor.value = value;
1991
1967
  }
1992
1968
  }
1969
+ function taskWorker_class_apply_descriptor_update(receiver, descriptor) {
1970
+ if (descriptor.set) {
1971
+ if (!descriptor.get) throw new TypeError("attempted to read set only private field");
1972
+ if (!("__destrWrapper" in descriptor)) descriptor.__destrWrapper = {
1973
+ set value (v){
1974
+ descriptor.set.call(receiver, v);
1975
+ },
1976
+ get value () {
1977
+ return descriptor.get.call(receiver);
1978
+ }
1979
+ };
1980
+ return descriptor.__destrWrapper;
1981
+ }
1982
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
1983
+ return descriptor;
1984
+ }
1993
1985
  function taskWorker_class_call_check(instance, Constructor) {
1994
1986
  if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
1995
1987
  }
@@ -2010,6 +2002,10 @@ function taskWorker_class_private_field_set(receiver, privateMap, value) {
2010
2002
  taskWorker_class_apply_descriptor_set(receiver, descriptor, value);
2011
2003
  return value;
2012
2004
  }
2005
+ function taskWorker_class_private_field_update(receiver, privateMap) {
2006
+ var descriptor = taskWorker_class_extract_field_descriptor(receiver, privateMap, "update");
2007
+ return taskWorker_class_apply_descriptor_update(receiver, descriptor);
2008
+ }
2013
2009
  function taskWorker_class_private_method_get(receiver, privateSet, fn) {
2014
2010
  if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
2015
2011
  return fn;
@@ -2032,35 +2028,39 @@ function taskWorker_create_class(Constructor, protoProps, staticProps) {
2032
2028
  if (staticProps) taskWorker_defineProperties(Constructor, staticProps);
2033
2029
  return Constructor;
2034
2030
  }
2035
- function taskWorker_iterable_to_array(iter) {
2031
+ function _iterable_to_array(iter) {
2036
2032
  if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
2037
2033
  }
2038
- function taskWorker_non_iterable_spread() {
2034
+ function _non_iterable_spread() {
2039
2035
  throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2040
2036
  }
2041
- function taskWorker_to_consumable_array(arr) {
2042
- return taskWorker_array_without_holes(arr) || taskWorker_iterable_to_array(arr) || taskWorker_unsupported_iterable_to_array(arr) || taskWorker_non_iterable_spread();
2037
+ function _to_consumable_array(arr) {
2038
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
2043
2039
  }
2044
- function taskWorker_unsupported_iterable_to_array(o, minLen) {
2040
+ function _unsupported_iterable_to_array(o, minLen) {
2045
2041
  if (!o) return;
2046
- if ("string" == typeof o) return taskWorker_array_like_to_array(o, minLen);
2042
+ if ("string" == typeof o) return _array_like_to_array(o, minLen);
2047
2043
  var n = Object.prototype.toString.call(o).slice(8, -1);
2048
2044
  if ("Object" === n && o.constructor) n = o.constructor.name;
2049
2045
  if ("Map" === n || "Set" === n) return Array.from(n);
2050
- if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return taskWorker_array_like_to_array(o, minLen);
2046
+ if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
2051
2047
  }
2052
- var _processManager = /*#__PURE__*/ new WeakMap(), _pendingQueue = /*#__PURE__*/ new WeakMap(), _inflightTasks = /*#__PURE__*/ new WeakMap(), _pendingFinalizeTasks = /*#__PURE__*/ new WeakMap(), _scheduledFinalize = /*#__PURE__*/ new WeakMap(), _valueParser = /*#__PURE__*/ new WeakMap(), _statementTimeout = /*#__PURE__*/ new WeakMap(), _logger = /*#__PURE__*/ new WeakMap(), _name = /*#__PURE__*/ new WeakMap(), _batchSize = /*#__PURE__*/ new WeakMap(), _maxInflight = /*#__PURE__*/ new WeakMap(), _metrics = /*#__PURE__*/ new WeakMap(), _startProcess = /*#__PURE__*/ new WeakSet(), _pumpQueue = /*#__PURE__*/ new WeakSet(), _handleParsedValue = /*#__PURE__*/ new WeakSet(), _scheduleFinalizeCheck = /*#__PURE__*/ new WeakSet(), _handleStderrChunk = /*#__PURE__*/ new WeakSet(), _handleTaskTimeout = /*#__PURE__*/ new WeakSet(), _settleTask = /*#__PURE__*/ new WeakSet(), _rejectAll = /*#__PURE__*/ new WeakSet();
2048
+ var _processManager = /*#__PURE__*/ new WeakMap(), _pendingQueue = /*#__PURE__*/ new WeakMap(), _inflightTasks = /*#__PURE__*/ new WeakMap(), _inflightHead = /*#__PURE__*/ new WeakMap(), _pendingFinalizeTasks = /*#__PURE__*/ new WeakMap(), _scheduledFinalize = /*#__PURE__*/ new WeakMap(), _valueParser = /*#__PURE__*/ new WeakMap(), _statementTimeout = /*#__PURE__*/ new WeakMap(), _logger = /*#__PURE__*/ new WeakMap(), _name = /*#__PURE__*/ new WeakMap(), _batchSize = /*#__PURE__*/ new WeakMap(), _maxInflight = /*#__PURE__*/ new WeakMap(), _metrics = /*#__PURE__*/ new WeakMap(), _sweepTimer = /*#__PURE__*/ new WeakMap(), _sweepIntervalMs = /*#__PURE__*/ new WeakMap(), _startProcess = /*#__PURE__*/ new WeakSet(), _inflightCount = /*#__PURE__*/ new WeakSet(), _firstInflight = /*#__PURE__*/ new WeakSet(), _shiftInflight = /*#__PURE__*/ new WeakSet(), _pumpQueue = /*#__PURE__*/ new WeakSet(), _handleParsedValue = /*#__PURE__*/ new WeakSet(), _scheduleFinalizeCheck = /*#__PURE__*/ new WeakSet(), _handleStderrChunk = /*#__PURE__*/ new WeakSet(), _scheduleSweep = /*#__PURE__*/ new WeakSet(), _handleTaskTimeout = /*#__PURE__*/ new WeakSet(), _settleTask = /*#__PURE__*/ new WeakSet(), _rejectAll = /*#__PURE__*/ new WeakSet();
2053
2049
  var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2054
2050
  "use strict";
2055
2051
  function TaskWorker(param) {
2056
2052
  var _this = this;
2057
- var binary = param.binary, database = param.database, statementTimeout = param.statementTimeout, logger = param.logger, name = param.name, initMode = param.initMode, _param_batchSize = param.batchSize, batchSize = void 0 === _param_batchSize ? DEFAULT_BATCH_SIZE : _param_batchSize, _param_maxInflight = param.maxInflight, maxInflight = void 0 === _param_maxInflight ? DEFAULT_MAX_INFLIGHT : _param_maxInflight, metrics = param.metrics;
2053
+ var binary = param.binary, database = param.database, statementTimeout = param.statementTimeout, logger = param.logger, name = param.name, initMode = param.initMode, _param_batchSize = param.batchSize, batchSize = void 0 === _param_batchSize ? DEFAULT_BATCH_SIZE : _param_batchSize, _param_maxInflight = param.maxInflight, maxInflight = void 0 === _param_maxInflight ? DEFAULT_MAX_INFLIGHT : _param_maxInflight, metrics = param.metrics, _param_sweepInterval = param.sweepInterval, sweepInterval = void 0 === _param_sweepInterval ? 100 : _param_sweepInterval;
2058
2054
  taskWorker_class_call_check(this, TaskWorker);
2059
2055
  taskWorker_class_private_method_init(this, _startProcess);
2056
+ taskWorker_class_private_method_init(this, _inflightCount);
2057
+ taskWorker_class_private_method_init(this, _firstInflight);
2058
+ taskWorker_class_private_method_init(this, _shiftInflight);
2060
2059
  taskWorker_class_private_method_init(this, _pumpQueue);
2061
2060
  taskWorker_class_private_method_init(this, _handleParsedValue);
2062
2061
  taskWorker_class_private_method_init(this, _scheduleFinalizeCheck);
2063
2062
  taskWorker_class_private_method_init(this, _handleStderrChunk);
2063
+ taskWorker_class_private_method_init(this, _scheduleSweep);
2064
2064
  taskWorker_class_private_method_init(this, _handleTaskTimeout);
2065
2065
  taskWorker_class_private_method_init(this, _settleTask);
2066
2066
  taskWorker_class_private_method_init(this, _rejectAll);
@@ -2076,6 +2076,10 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2076
2076
  writable: true,
2077
2077
  value: []
2078
2078
  });
2079
+ taskWorker_class_private_field_init(this, _inflightHead, {
2080
+ writable: true,
2081
+ value: 0
2082
+ });
2079
2083
  taskWorker_class_private_field_init(this, _pendingFinalizeTasks, {
2080
2084
  writable: true,
2081
2085
  value: new Set()
@@ -2112,12 +2116,21 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2112
2116
  writable: true,
2113
2117
  value: void 0
2114
2118
  });
2119
+ taskWorker_class_private_field_init(this, _sweepTimer, {
2120
+ writable: true,
2121
+ value: null
2122
+ });
2123
+ taskWorker_class_private_field_init(this, _sweepIntervalMs, {
2124
+ writable: true,
2125
+ value: void 0
2126
+ });
2115
2127
  taskWorker_class_private_field_set(this, _name, null != name ? name : "worker");
2116
2128
  taskWorker_class_private_field_set(this, _statementTimeout, statementTimeout);
2117
2129
  taskWorker_class_private_field_set(this, _logger, logger);
2118
2130
  taskWorker_class_private_field_set(this, _batchSize, batchSize);
2119
2131
  taskWorker_class_private_field_set(this, _maxInflight, maxInflight);
2120
2132
  taskWorker_class_private_field_set(this, _metrics, metrics);
2133
+ taskWorker_class_private_field_set(this, _sweepIntervalMs, sweepInterval);
2121
2134
  taskWorker_class_private_field_set(this, _processManager, new process_ProcessManager({
2122
2135
  binary: binary,
2123
2136
  database: database,
@@ -2141,13 +2154,13 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2141
2154
  {
2142
2155
  key: "idle",
2143
2156
  get: function() {
2144
- return 0 === taskWorker_class_private_field_get(this, _inflightTasks).length && taskWorker_class_private_field_get(this, _pendingQueue).isEmpty() && 0 === taskWorker_class_private_field_get(this, _pendingFinalizeTasks).size;
2157
+ return taskWorker_class_private_field_get(this, _inflightTasks).length === taskWorker_class_private_field_get(this, _inflightHead) && taskWorker_class_private_field_get(this, _pendingQueue).isEmpty() && 0 === taskWorker_class_private_field_get(this, _pendingFinalizeTasks).size;
2145
2158
  }
2146
2159
  },
2147
2160
  {
2148
2161
  key: "pendingStatements",
2149
2162
  get: function() {
2150
- return taskWorker_class_private_field_get(this, _pendingQueue).size + taskWorker_class_private_field_get(this, _inflightTasks).length + taskWorker_class_private_field_get(this, _pendingFinalizeTasks).size;
2163
+ return taskWorker_class_private_field_get(this, _pendingQueue).size + (taskWorker_class_private_field_get(this, _inflightTasks).length - taskWorker_class_private_field_get(this, _inflightHead)) + taskWorker_class_private_field_get(this, _pendingFinalizeTasks).size;
2151
2164
  }
2152
2165
  },
2153
2166
  {
@@ -2167,8 +2180,6 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2167
2180
  consumerError: null,
2168
2181
  stderrText: "",
2169
2182
  settled: false,
2170
- errorScheduled: false,
2171
- timer: null,
2172
2183
  startTime: 0
2173
2184
  };
2174
2185
  null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _metrics)) || _$_class_private_field_get.incrementTasksTotal(config.kind);
@@ -2176,6 +2187,12 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2176
2187
  taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2177
2188
  }
2178
2189
  },
2190
+ {
2191
+ key: "_sweepTimer",
2192
+ get: function() {
2193
+ return taskWorker_class_private_field_get(this, _sweepTimer);
2194
+ }
2195
+ },
2179
2196
  {
2180
2197
  key: "_process",
2181
2198
  get: function() {
@@ -2185,6 +2202,8 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2185
2202
  {
2186
2203
  key: "kill",
2187
2204
  value: function() {
2205
+ clearTimeout(taskWorker_class_private_field_get(this, _sweepTimer));
2206
+ taskWorker_class_private_field_set(this, _sweepTimer, null);
2188
2207
  taskWorker_class_private_method_get(this, _rejectAll, taskWorker_rejectAll).call(this, new Error("".concat(taskWorker_class_private_field_get(this, _name), " is killed")));
2189
2208
  taskWorker_class_private_field_get(this, _processManager).kill();
2190
2209
  }
@@ -2213,15 +2232,33 @@ function startProcess() {
2213
2232
  taskWorker_class_private_method_get(_this, _rejectAll, taskWorker_rejectAll).call(_this, err);
2214
2233
  });
2215
2234
  }
2235
+ function inflightCount() {
2236
+ return taskWorker_class_private_field_get(this, _inflightTasks).length - taskWorker_class_private_field_get(this, _inflightHead);
2237
+ }
2238
+ function firstInflight() {
2239
+ return taskWorker_class_private_field_get(this, _inflightHead) < taskWorker_class_private_field_get(this, _inflightTasks).length ? taskWorker_class_private_field_get(this, _inflightTasks)[taskWorker_class_private_field_get(this, _inflightHead)] : null;
2240
+ }
2241
+ function shiftInflight() {
2242
+ var task = taskWorker_class_private_field_get(this, _inflightTasks)[taskWorker_class_private_field_get(this, _inflightHead)];
2243
+ taskWorker_class_private_field_get(this, _inflightTasks)[taskWorker_class_private_field_get(this, _inflightHead)] = null;
2244
+ taskWorker_class_private_field_update(this, _inflightHead).value++;
2245
+ if (taskWorker_class_private_field_get(this, _inflightHead) >= taskWorker_class_private_field_get(this, _inflightTasks).length) {
2246
+ taskWorker_class_private_field_set(this, _inflightTasks, []);
2247
+ taskWorker_class_private_field_set(this, _inflightHead, 0);
2248
+ } else if (taskWorker_class_private_field_get(this, _inflightHead) > 128) {
2249
+ taskWorker_class_private_field_set(this, _inflightTasks, taskWorker_class_private_field_get(this, _inflightTasks).slice(taskWorker_class_private_field_get(this, _inflightHead)));
2250
+ taskWorker_class_private_field_set(this, _inflightHead, 0);
2251
+ }
2252
+ return task;
2253
+ }
2216
2254
  function taskWorker_pumpQueue() {
2217
- var _this = this;
2218
2255
  var _$_class_private_field_get;
2219
2256
  if (taskWorker_class_private_field_get(this, _processManager).draining) return;
2220
- if (taskWorker_class_private_field_get(this, _inflightTasks).length >= taskWorker_class_private_field_get(this, _maxInflight)) return;
2257
+ if (taskWorker_class_private_method_get(this, _inflightCount, inflightCount).call(this) >= taskWorker_class_private_field_get(this, _maxInflight)) return;
2221
2258
  var batch = [];
2222
- while(batch.length < taskWorker_class_private_field_get(this, _batchSize) && !taskWorker_class_private_field_get(this, _pendingQueue).isEmpty() && taskWorker_class_private_field_get(this, _inflightTasks).length + batch.length < taskWorker_class_private_field_get(this, _maxInflight)){
2259
+ while(batch.length < taskWorker_class_private_field_get(this, _batchSize) && !taskWorker_class_private_field_get(this, _pendingQueue).isEmpty() && taskWorker_class_private_method_get(this, _inflightCount, inflightCount).call(this) + batch.length < taskWorker_class_private_field_get(this, _maxInflight)){
2223
2260
  var task = taskWorker_class_private_field_get(this, _pendingQueue).peek();
2224
- if ("stream" === task.kind && (batch.length > 0 || taskWorker_class_private_field_get(this, _inflightTasks).length > 0)) break;
2261
+ if ("stream" === task.kind && (batch.length > 0 || taskWorker_class_private_method_get(this, _inflightCount, inflightCount).call(this) > 0)) break;
2225
2262
  taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
2226
2263
  batch.push(task);
2227
2264
  }
@@ -2230,15 +2267,10 @@ function taskWorker_pumpQueue() {
2230
2267
  var payload = buildBatchPayload(batch);
2231
2268
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2232
2269
  try {
2233
- var _this1, _loop = function() {
2234
- var task = _step.value;
2235
- task.startTime = now;
2236
- var _task_timeout;
2237
- task.timer = setTimeout(function() {
2238
- return taskWorker_class_private_method_get(_this, _handleTaskTimeout, handleTaskTimeout).call(_this, task);
2239
- }, null != (_task_timeout = task.timeout) ? _task_timeout : taskWorker_class_private_field_get(_this1, _statementTimeout));
2240
- };
2241
- for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_this1 = this, _loop();
2270
+ for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2271
+ var task1 = _step.value;
2272
+ task1.startTime = now;
2273
+ }
2242
2274
  } catch (err) {
2243
2275
  _didIteratorError = true;
2244
2276
  _iteratorError = err;
@@ -2249,15 +2281,15 @@ function taskWorker_pumpQueue() {
2249
2281
  if (_didIteratorError) throw _iteratorError;
2250
2282
  }
2251
2283
  }
2252
- (_$_class_private_field_get = taskWorker_class_private_field_get(this, _inflightTasks)).push.apply(_$_class_private_field_get, taskWorker_to_consumable_array(batch));
2284
+ (_$_class_private_field_get = taskWorker_class_private_field_get(this, _inflightTasks)).push.apply(_$_class_private_field_get, _to_consumable_array(batch));
2285
+ taskWorker_class_private_method_get(this, _scheduleSweep, scheduleSweep).call(this);
2253
2286
  taskWorker_class_private_field_get(this, _processManager).write(payload);
2254
2287
  }
2255
2288
  function handleParsedValue(raw) {
2256
- var task = taskWorker_class_private_field_get(this, _inflightTasks)[0];
2289
+ var task = taskWorker_class_private_method_get(this, _firstInflight, firstInflight).call(this);
2257
2290
  if (!task) return;
2258
2291
  if (isSentinelRaw(raw, task.token)) {
2259
- clearTimeout(task.timer);
2260
- taskWorker_class_private_field_get(this, _inflightTasks).shift();
2292
+ taskWorker_class_private_method_get(this, _shiftInflight, shiftInflight).call(this);
2261
2293
  if (task.timedout) return void taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2262
2294
  if (task.stderrText) {
2263
2295
  taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, new Error(task.stderrText.trim()), void 0);
@@ -2283,8 +2315,7 @@ function handleParsedValue(raw) {
2283
2315
  return;
2284
2316
  }
2285
2317
  if (isSentinelRow(parsed, task.token)) {
2286
- clearTimeout(task.timer);
2287
- taskWorker_class_private_field_get(this, _inflightTasks).shift();
2318
+ taskWorker_class_private_method_get(this, _shiftInflight, shiftInflight).call(this);
2288
2319
  if (task.timedout) return void taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2289
2320
  if (task.stderrText) {
2290
2321
  taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, new Error(task.stderrText.trim()), void 0);
@@ -2301,6 +2332,7 @@ function handleParsedValue(raw) {
2301
2332
  taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2302
2333
  return;
2303
2334
  }
2335
+ if (task.timedout) return;
2304
2336
  if ("query" === task.kind) return void collectQueryRows(task, parsed);
2305
2337
  if ("stream" === task.kind) processStreamRows(task, parsed);
2306
2338
  }
@@ -2318,14 +2350,29 @@ function scheduleFinalizeCheck() {
2318
2350
  });
2319
2351
  }
2320
2352
  function taskWorker_handleStderrChunk(chunk) {
2321
- var _class_private_field_get_;
2322
- var task = null != (_class_private_field_get_ = taskWorker_class_private_field_get(this, _inflightTasks)[0]) ? _class_private_field_get_ : taskWorker_class_private_field_get(this, _pendingFinalizeTasks).values().next().value;
2353
+ var _class_private_field_get_values_next_value;
2354
+ var task = null != (_class_private_field_get_values_next_value = taskWorker_class_private_field_get(this, _pendingFinalizeTasks).values().next().value) ? _class_private_field_get_values_next_value : taskWorker_class_private_method_get(this, _firstInflight, firstInflight).call(this);
2323
2355
  if (!task) {
2324
2356
  var _class_private_field_get_error, _$_class_private_field_get;
2325
- null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _logger)) || null == (_class_private_field_get_error = _$_class_private_field_get.error) || _class_private_field_get_error.call(_$_class_private_field_get, String(chunk).trim());
2357
+ null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _logger)) || null == (_class_private_field_get_error = _$_class_private_field_get.error) || _class_private_field_get_error.call(_$_class_private_field_get, chunk.trim());
2326
2358
  return;
2327
2359
  }
2328
- task.stderrText += String(chunk);
2360
+ task.stderrText += chunk;
2361
+ }
2362
+ function scheduleSweep() {
2363
+ var _this = this;
2364
+ if (taskWorker_class_private_field_get(this, _sweepTimer)) return;
2365
+ taskWorker_class_private_field_set(this, _sweepTimer, setTimeout(function() {
2366
+ taskWorker_class_private_field_set(_this, _sweepTimer, null);
2367
+ var tasks = taskWorker_class_private_field_get(_this, _inflightTasks);
2368
+ var head = taskWorker_class_private_field_get(_this, _inflightHead);
2369
+ var now = performance.now();
2370
+ for(var i = head; i < tasks.length; i++){
2371
+ var task = tasks[i];
2372
+ if (now - task.startTime > task.timeout) taskWorker_class_private_method_get(_this, _handleTaskTimeout, handleTaskTimeout).call(_this, task);
2373
+ }
2374
+ if (taskWorker_class_private_method_get(_this, _inflightCount, inflightCount).call(_this) > 0) taskWorker_class_private_method_get(_this, _scheduleSweep, scheduleSweep).call(_this);
2375
+ }, taskWorker_class_private_field_get(this, _sweepIntervalMs)).unref());
2329
2376
  }
2330
2377
  function handleTaskTimeout(task) {
2331
2378
  var error = prepareTaskTimeout(task, taskWorker_class_private_field_get(this, _metrics));
@@ -2335,8 +2382,12 @@ function settleTask1(task, error, value) {
2335
2382
  settleTask(task, error, value, taskWorker_class_private_field_get(this, _metrics));
2336
2383
  }
2337
2384
  function taskWorker_rejectAll(error) {
2338
- var all = taskWorker_class_private_field_get(this, _inflightTasks);
2385
+ clearTimeout(taskWorker_class_private_field_get(this, _sweepTimer));
2386
+ taskWorker_class_private_field_set(this, _sweepTimer, null);
2387
+ var activeCount = taskWorker_class_private_field_get(this, _inflightTasks).length - taskWorker_class_private_field_get(this, _inflightHead);
2388
+ var all = activeCount > 0 ? taskWorker_class_private_field_get(this, _inflightTasks).slice(taskWorker_class_private_field_get(this, _inflightHead)) : [];
2339
2389
  taskWorker_class_private_field_set(this, _inflightTasks, []);
2390
+ taskWorker_class_private_field_set(this, _inflightHead, 0);
2340
2391
  var queued = taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
2341
2392
  while(queued){
2342
2393
  taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, queued, error, void 0);
@@ -2470,9 +2521,19 @@ var readerPool_ReaderPool = /*#__PURE__*/ function() {
2470
2521
  {
2471
2522
  key: "enqueue",
2472
2523
  value: function(task) {
2473
- var worker = readerPool_class_private_field_get(this, _workers)[readerPool_class_private_field_get(this, _rrIndex) % readerPool_class_private_field_get(this, _workers).length];
2524
+ var minLoad = 1 / 0;
2525
+ var candidates = [];
2526
+ for(var i = 0; i < readerPool_class_private_field_get(this, _workers).length; i++){
2527
+ var load = readerPool_class_private_field_get(this, _workers)[i].pendingStatements;
2528
+ if (load < minLoad) {
2529
+ minLoad = load;
2530
+ candidates.length = 0;
2531
+ candidates.push(i);
2532
+ } else if (load === minLoad) candidates.push(i);
2533
+ }
2534
+ var idx = candidates[readerPool_class_private_field_get(this, _rrIndex) % candidates.length];
2474
2535
  readerPool_class_private_field_set(this, _rrIndex, readerPool_class_private_field_get(this, _rrIndex) + 1 >>> 0);
2475
- worker.enqueue(task);
2536
+ readerPool_class_private_field_get(this, _workers)[idx].enqueue(task);
2476
2537
  }
2477
2538
  },
2478
2539
  {
@@ -2965,9 +3026,7 @@ var transactionScope_TransactionScope = /*#__PURE__*/ function() {
2965
3026
  release = resolve;
2966
3027
  });
2967
3028
  previous = transactionScope_class_private_field_get(_this, _scopeChain);
2968
- transactionScope_class_private_field_set(_this, _scopeChain, previous["catch"](function() {}).then(function() {
2969
- return gate;
2970
- }));
3029
+ transactionScope_class_private_field_set(_this, _scopeChain, gate);
2971
3030
  return [
2972
3031
  4,
2973
3032
  previous["catch"](function() {})
@@ -3034,6 +3093,22 @@ function pipelineEngine_class_apply_descriptor_set(receiver, descriptor, value)
3034
3093
  descriptor.value = value;
3035
3094
  }
3036
3095
  }
3096
+ function pipelineEngine_class_apply_descriptor_update(receiver, descriptor) {
3097
+ if (descriptor.set) {
3098
+ if (!descriptor.get) throw new TypeError("attempted to read set only private field");
3099
+ if (!("__destrWrapper" in descriptor)) descriptor.__destrWrapper = {
3100
+ set value (v){
3101
+ descriptor.set.call(receiver, v);
3102
+ },
3103
+ get value () {
3104
+ return descriptor.get.call(receiver);
3105
+ }
3106
+ };
3107
+ return descriptor.__destrWrapper;
3108
+ }
3109
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
3110
+ return descriptor;
3111
+ }
3037
3112
  function pipelineEngine_class_call_check(instance, Constructor) {
3038
3113
  if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
3039
3114
  }
@@ -3054,6 +3129,10 @@ function pipelineEngine_class_private_field_set(receiver, privateMap, value) {
3054
3129
  pipelineEngine_class_apply_descriptor_set(receiver, descriptor, value);
3055
3130
  return value;
3056
3131
  }
3132
+ function pipelineEngine_class_private_field_update(receiver, privateMap) {
3133
+ var descriptor = pipelineEngine_class_extract_field_descriptor(receiver, privateMap, "update");
3134
+ return pipelineEngine_class_apply_descriptor_update(receiver, descriptor);
3135
+ }
3057
3136
  function pipelineEngine_class_private_method_get(receiver, privateSet, fn) {
3058
3137
  if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
3059
3138
  return fn;
@@ -3093,17 +3172,20 @@ function pipelineEngine_unsupported_iterable_to_array(o, minLen) {
3093
3172
  if ("Map" === n || "Set" === n) return Array.from(n);
3094
3173
  if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return pipelineEngine_array_like_to_array(o, minLen);
3095
3174
  }
3096
- var _queue = /*#__PURE__*/ new WeakMap(), pipelineEngine_inflightTasks = /*#__PURE__*/ new WeakMap(), pipelineEngine_pendingFinalizeTasks = /*#__PURE__*/ new WeakMap(), pipelineEngine_scheduledFinalize = /*#__PURE__*/ new WeakMap(), _sharedValueParser = /*#__PURE__*/ new WeakMap(), pipelineEngine_processManager = /*#__PURE__*/ new WeakMap(), pipelineEngine_metrics = /*#__PURE__*/ new WeakMap(), pipelineEngine_statementTimeout = /*#__PURE__*/ new WeakMap(), pipelineEngine_logger = /*#__PURE__*/ new WeakMap(), pipelineEngine_batchSize = /*#__PURE__*/ new WeakMap(), pipelineEngine_maxInflight = /*#__PURE__*/ new WeakMap(), _onTaskTimeout = /*#__PURE__*/ new WeakMap(), _active = /*#__PURE__*/ new WeakMap(), _sweepTimer = /*#__PURE__*/ new WeakMap(), _sweepIntervalMs = /*#__PURE__*/ new WeakMap(), core_pipelineEngine_pumpQueue = /*#__PURE__*/ new WeakSet(), pipelineEngine_handleParsedValue = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_scheduleFinalizeCheck = /*#__PURE__*/ new WeakSet(), _scheduleSweep = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_handleTaskTimeout = /*#__PURE__*/ new WeakSet(), pipelineEngine_settleTask = /*#__PURE__*/ new WeakSet();
3175
+ var _queue = /*#__PURE__*/ new WeakMap(), pipelineEngine_inflightTasks = /*#__PURE__*/ new WeakMap(), pipelineEngine_inflightHead = /*#__PURE__*/ new WeakMap(), pipelineEngine_pendingFinalizeTasks = /*#__PURE__*/ new WeakMap(), pipelineEngine_scheduledFinalize = /*#__PURE__*/ new WeakMap(), _sharedValueParser = /*#__PURE__*/ new WeakMap(), pipelineEngine_processManager = /*#__PURE__*/ new WeakMap(), pipelineEngine_metrics = /*#__PURE__*/ new WeakMap(), pipelineEngine_statementTimeout = /*#__PURE__*/ new WeakMap(), pipelineEngine_logger = /*#__PURE__*/ new WeakMap(), pipelineEngine_batchSize = /*#__PURE__*/ new WeakMap(), pipelineEngine_maxInflight = /*#__PURE__*/ new WeakMap(), _onTaskTimeout = /*#__PURE__*/ new WeakMap(), _active = /*#__PURE__*/ new WeakMap(), pipelineEngine_sweepTimer = /*#__PURE__*/ new WeakMap(), pipelineEngine_sweepIntervalMs = /*#__PURE__*/ new WeakMap(), pipelineEngine_inflightCount = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_firstInflight = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_shiftInflight = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_pumpQueue = /*#__PURE__*/ new WeakSet(), pipelineEngine_handleParsedValue = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_scheduleFinalizeCheck = /*#__PURE__*/ new WeakSet(), pipelineEngine_scheduleSweep = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_handleTaskTimeout = /*#__PURE__*/ new WeakSet(), pipelineEngine_settleTask = /*#__PURE__*/ new WeakSet();
3097
3176
  var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3098
3177
  "use strict";
3099
3178
  function PipelineEngine(processManager, param) {
3100
3179
  var _this = this;
3101
3180
  var metrics = param.metrics, statementTimeout = param.statementTimeout, logger = param.logger, _param_batchSize = param.batchSize, batchSize = void 0 === _param_batchSize ? DEFAULT_BATCH_SIZE : _param_batchSize, _param_maxInflight = param.maxInflight, maxInflight = void 0 === _param_maxInflight ? DEFAULT_MAX_INFLIGHT : _param_maxInflight, onTaskTimeout = param.onTaskTimeout, _param_sweepInterval = param.sweepInterval, sweepInterval = void 0 === _param_sweepInterval ? 100 : _param_sweepInterval;
3102
3181
  pipelineEngine_class_call_check(this, PipelineEngine);
3182
+ pipelineEngine_class_private_method_init(this, pipelineEngine_inflightCount);
3183
+ pipelineEngine_class_private_method_init(this, core_pipelineEngine_firstInflight);
3184
+ pipelineEngine_class_private_method_init(this, core_pipelineEngine_shiftInflight);
3103
3185
  pipelineEngine_class_private_method_init(this, core_pipelineEngine_pumpQueue);
3104
3186
  pipelineEngine_class_private_method_init(this, pipelineEngine_handleParsedValue);
3105
3187
  pipelineEngine_class_private_method_init(this, core_pipelineEngine_scheduleFinalizeCheck);
3106
- pipelineEngine_class_private_method_init(this, _scheduleSweep);
3188
+ pipelineEngine_class_private_method_init(this, pipelineEngine_scheduleSweep);
3107
3189
  pipelineEngine_class_private_method_init(this, core_pipelineEngine_handleTaskTimeout);
3108
3190
  pipelineEngine_class_private_method_init(this, pipelineEngine_settleTask);
3109
3191
  pipelineEngine_class_private_field_init(this, _queue, {
@@ -3114,6 +3196,10 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3114
3196
  writable: true,
3115
3197
  value: []
3116
3198
  });
3199
+ pipelineEngine_class_private_field_init(this, pipelineEngine_inflightHead, {
3200
+ writable: true,
3201
+ value: 0
3202
+ });
3117
3203
  pipelineEngine_class_private_field_init(this, pipelineEngine_pendingFinalizeTasks, {
3118
3204
  writable: true,
3119
3205
  value: new Set()
@@ -3158,11 +3244,11 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3158
3244
  writable: true,
3159
3245
  value: false
3160
3246
  });
3161
- pipelineEngine_class_private_field_init(this, _sweepTimer, {
3247
+ pipelineEngine_class_private_field_init(this, pipelineEngine_sweepTimer, {
3162
3248
  writable: true,
3163
3249
  value: null
3164
3250
  });
3165
- pipelineEngine_class_private_field_init(this, _sweepIntervalMs, {
3251
+ pipelineEngine_class_private_field_init(this, pipelineEngine_sweepIntervalMs, {
3166
3252
  writable: true,
3167
3253
  value: void 0
3168
3254
  });
@@ -3179,13 +3265,13 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3179
3265
  pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).setOnDrainCallback(function() {
3180
3266
  return pipelineEngine_class_private_method_get(_this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(_this);
3181
3267
  });
3182
- pipelineEngine_class_private_field_set(this, _sweepIntervalMs, sweepInterval);
3268
+ pipelineEngine_class_private_field_set(this, pipelineEngine_sweepIntervalMs, sweepInterval);
3183
3269
  }
3184
3270
  pipelineEngine_create_class(PipelineEngine, [
3185
3271
  {
3186
3272
  key: "_sweepTimer",
3187
3273
  get: function() {
3188
- return pipelineEngine_class_private_field_get(this, _sweepTimer);
3274
+ return pipelineEngine_class_private_field_get(this, pipelineEngine_sweepTimer);
3189
3275
  }
3190
3276
  },
3191
3277
  {
@@ -3203,7 +3289,7 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3203
3289
  {
3204
3290
  key: "pendingStatements",
3205
3291
  get: function() {
3206
- return pipelineEngine_class_private_field_get(this, _queue).size + pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length + pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).size;
3292
+ return pipelineEngine_class_private_field_get(this, _queue).size + (pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length - pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead)) + pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).size;
3207
3293
  }
3208
3294
  },
3209
3295
  {
@@ -3236,7 +3322,7 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3236
3322
  {
3237
3323
  key: "handleStdoutChunk",
3238
3324
  value: function(chunk) {
3239
- var task = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[0];
3325
+ var task = pipelineEngine_class_private_method_get(this, core_pipelineEngine_firstInflight, pipelineEngine_firstInflight).call(this);
3240
3326
  if (!task) return;
3241
3327
  if ("stream" === task.kind && task.rowParser && !task.rowParser.finished && !task.timedout) {
3242
3328
  var leftover = task.rowParser.feed(chunk);
@@ -3250,21 +3336,23 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3250
3336
  key: "handleStderrChunk",
3251
3337
  value: function(chunk) {
3252
3338
  var _class_private_field_get_values_next_value;
3253
- var task = null != (_class_private_field_get_values_next_value = pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).values().next().value) ? _class_private_field_get_values_next_value : pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[0];
3339
+ var task = null != (_class_private_field_get_values_next_value = pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).values().next().value) ? _class_private_field_get_values_next_value : pipelineEngine_class_private_method_get(this, core_pipelineEngine_firstInflight, pipelineEngine_firstInflight).call(this);
3254
3340
  if (!task) {
3255
3341
  var _class_private_field_get_error, _$_class_private_field_get;
3256
- null == (_$_class_private_field_get = pipelineEngine_class_private_field_get(this, pipelineEngine_logger)) || null == (_class_private_field_get_error = _$_class_private_field_get.error) || _class_private_field_get_error.call(_$_class_private_field_get, String(chunk).trim());
3342
+ null == (_$_class_private_field_get = pipelineEngine_class_private_field_get(this, pipelineEngine_logger)) || null == (_class_private_field_get_error = _$_class_private_field_get.error) || _class_private_field_get_error.call(_$_class_private_field_get, chunk.trim());
3257
3343
  return;
3258
3344
  }
3259
- task.stderrText += String(chunk);
3345
+ task.stderrText += chunk;
3260
3346
  }
3261
3347
  },
3262
3348
  {
3263
3349
  key: "rejectAll",
3264
3350
  value: function(error) {
3265
3351
  pipelineEngine_class_private_field_get(this, _sharedValueParser).reset();
3266
- var all = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks);
3352
+ var activeCount = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length - pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead);
3353
+ var all = activeCount > 0 ? pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).slice(pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead)) : [];
3267
3354
  pipelineEngine_class_private_field_set(this, pipelineEngine_inflightTasks, []);
3355
+ pipelineEngine_class_private_field_set(this, pipelineEngine_inflightHead, 0);
3268
3356
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
3269
3357
  try {
3270
3358
  for(var _iterator = all[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -3309,23 +3397,42 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3309
3397
  key: "kill",
3310
3398
  value: function() {
3311
3399
  pipelineEngine_class_private_field_set(this, _active, false);
3312
- clearTimeout(pipelineEngine_class_private_field_get(this, _sweepTimer));
3313
- pipelineEngine_class_private_field_set(this, _sweepTimer, null);
3400
+ clearTimeout(pipelineEngine_class_private_field_get(this, pipelineEngine_sweepTimer));
3401
+ pipelineEngine_class_private_field_set(this, pipelineEngine_sweepTimer, null);
3314
3402
  this.rejectAll(new Error("PipelineEngine is killed"));
3315
3403
  }
3316
3404
  }
3317
3405
  ]);
3318
3406
  return PipelineEngine;
3319
3407
  }();
3408
+ function core_pipelineEngine_inflightCount() {
3409
+ return pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length - pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead);
3410
+ }
3411
+ function pipelineEngine_firstInflight() {
3412
+ return pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead) < pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length ? pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead)] : null;
3413
+ }
3414
+ function pipelineEngine_shiftInflight() {
3415
+ var task = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead)];
3416
+ pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead)] = null;
3417
+ pipelineEngine_class_private_field_update(this, pipelineEngine_inflightHead).value++;
3418
+ if (pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead) >= pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length) {
3419
+ pipelineEngine_class_private_field_set(this, pipelineEngine_inflightTasks, []);
3420
+ pipelineEngine_class_private_field_set(this, pipelineEngine_inflightHead, 0);
3421
+ } else if (pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead) > 128) {
3422
+ pipelineEngine_class_private_field_set(this, pipelineEngine_inflightTasks, pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).slice(pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead)));
3423
+ pipelineEngine_class_private_field_set(this, pipelineEngine_inflightHead, 0);
3424
+ }
3425
+ return task;
3426
+ }
3320
3427
  function pipelineEngine_pumpQueue() {
3321
3428
  var _$_class_private_field_get;
3322
3429
  if (!pipelineEngine_class_private_field_get(this, _active)) return;
3323
3430
  if (pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).draining) return;
3324
- if (pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length >= pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)) return;
3431
+ if (pipelineEngine_class_private_method_get(this, pipelineEngine_inflightCount, core_pipelineEngine_inflightCount).call(this) >= pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)) return;
3325
3432
  var batch = [];
3326
- while(batch.length < pipelineEngine_class_private_field_get(this, pipelineEngine_batchSize) && !pipelineEngine_class_private_field_get(this, _queue).isEmpty() && pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length + batch.length < pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)){
3433
+ while(batch.length < pipelineEngine_class_private_field_get(this, pipelineEngine_batchSize) && !pipelineEngine_class_private_field_get(this, _queue).isEmpty() && pipelineEngine_class_private_method_get(this, pipelineEngine_inflightCount, core_pipelineEngine_inflightCount).call(this) + batch.length < pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)){
3327
3434
  var task = pipelineEngine_class_private_field_get(this, _queue).peek();
3328
- if ("stream" === task.kind && (batch.length > 0 || pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length > 0)) break;
3435
+ if ("stream" === task.kind && (batch.length > 0 || pipelineEngine_class_private_method_get(this, pipelineEngine_inflightCount, core_pipelineEngine_inflightCount).call(this) > 0)) break;
3329
3436
  pipelineEngine_class_private_field_get(this, _queue).dequeue();
3330
3437
  batch.push(task);
3331
3438
  }
@@ -3349,14 +3456,14 @@ function pipelineEngine_pumpQueue() {
3349
3456
  }
3350
3457
  }
3351
3458
  (_$_class_private_field_get = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)).push.apply(_$_class_private_field_get, pipelineEngine_to_consumable_array(batch));
3352
- pipelineEngine_class_private_method_get(this, _scheduleSweep, scheduleSweep).call(this);
3459
+ pipelineEngine_class_private_method_get(this, pipelineEngine_scheduleSweep, core_pipelineEngine_scheduleSweep).call(this);
3353
3460
  pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).write(payload);
3354
3461
  }
3355
3462
  function core_pipelineEngine_handleParsedValue(raw) {
3356
- var task = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[0];
3463
+ var task = pipelineEngine_class_private_method_get(this, core_pipelineEngine_firstInflight, pipelineEngine_firstInflight).call(this);
3357
3464
  if (!task) return;
3358
3465
  if (isSentinelRaw(raw, task.token)) {
3359
- pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).shift();
3466
+ pipelineEngine_class_private_method_get(this, core_pipelineEngine_shiftInflight, pipelineEngine_shiftInflight).call(this);
3360
3467
  if (task.timedout) return void pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3361
3468
  if (task.consumerError) {
3362
3469
  pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, task.consumerError, void 0);
@@ -3377,7 +3484,7 @@ function core_pipelineEngine_handleParsedValue(raw) {
3377
3484
  return;
3378
3485
  }
3379
3486
  if (isSentinelRow(parsed, task.token)) {
3380
- pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).shift();
3487
+ pipelineEngine_class_private_method_get(this, core_pipelineEngine_shiftInflight, pipelineEngine_shiftInflight).call(this);
3381
3488
  if (task.timedout) return void pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3382
3489
  if (task.consumerError) {
3383
3490
  pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, task.consumerError, void 0);
@@ -3406,19 +3513,20 @@ function pipelineEngine_scheduleFinalizeCheck() {
3406
3513
  });
3407
3514
  });
3408
3515
  }
3409
- function scheduleSweep() {
3516
+ function core_pipelineEngine_scheduleSweep() {
3410
3517
  var _this = this;
3411
- if (pipelineEngine_class_private_field_get(this, _sweepTimer)) return;
3412
- pipelineEngine_class_private_field_set(this, _sweepTimer, setTimeout(function() {
3413
- pipelineEngine_class_private_field_set(_this, _sweepTimer, null);
3414
- var inflight = pipelineEngine_class_private_field_get(_this, pipelineEngine_inflightTasks);
3518
+ if (pipelineEngine_class_private_field_get(this, pipelineEngine_sweepTimer)) return;
3519
+ pipelineEngine_class_private_field_set(this, pipelineEngine_sweepTimer, setTimeout(function() {
3520
+ pipelineEngine_class_private_field_set(_this, pipelineEngine_sweepTimer, null);
3521
+ var tasks = pipelineEngine_class_private_field_get(_this, pipelineEngine_inflightTasks);
3522
+ var head = pipelineEngine_class_private_field_get(_this, pipelineEngine_inflightHead);
3415
3523
  var now = performance.now();
3416
- for(var i = 0; i < inflight.length; i++){
3417
- var task = inflight[i];
3524
+ for(var i = head; i < tasks.length; i++){
3525
+ var task = tasks[i];
3418
3526
  if (now - task.startTime > task.timeout) pipelineEngine_class_private_method_get(_this, core_pipelineEngine_handleTaskTimeout, pipelineEngine_handleTaskTimeout).call(_this, task);
3419
3527
  }
3420
- if (pipelineEngine_class_private_field_get(_this, pipelineEngine_inflightTasks).length > 0) pipelineEngine_class_private_method_get(_this, _scheduleSweep, scheduleSweep).call(_this);
3421
- }, pipelineEngine_class_private_field_get(this, _sweepIntervalMs)).unref());
3528
+ if (pipelineEngine_class_private_method_get(_this, pipelineEngine_inflightCount, core_pipelineEngine_inflightCount).call(_this) > 0) pipelineEngine_class_private_method_get(_this, pipelineEngine_scheduleSweep, core_pipelineEngine_scheduleSweep).call(_this);
3529
+ }, pipelineEngine_class_private_field_get(this, pipelineEngine_sweepIntervalMs)).unref());
3422
3530
  }
3423
3531
  function pipelineEngine_handleTaskTimeout(task) {
3424
3532
  var _this, _this1;
@@ -4028,20 +4136,18 @@ function executor_enqueue(kind, sql, params, options, scopeId) {
4028
4136
  var token = generateToken();
4029
4137
  var _options_onRow;
4030
4138
  var onRow = null != (_options_onRow = null == options ? void 0 : options.onRow) ? _options_onRow : null;
4031
- var normalized = normalizeSQL(sql);
4139
+ var template = normalizeSQLTemplate(sql);
4032
4140
  var formatted;
4033
- var sqlNormalized = true;
4034
- formatted = 0 !== params.length || normalized.includes("?") ? interpolateSQL(normalized, params) : normalized;
4035
- if (scopeId) return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, scopeId, sqlNormalized);
4141
+ formatted = 0 === params.length && 0 === template.paramCount ? template.normalized : interpolateFromTemplate(template, params);
4142
+ if (scopeId) return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, scopeId);
4036
4143
  if (executor_class_private_field_get(this, _readerPool)) {
4037
4144
  if ("stream" === kind || "query" === kind) return executor_class_private_method_get(this, _enqueueReader, enqueueReader).call(this, kind, formatted, timeout, token, onRow);
4038
- if ("execute" === kind && "read" === classifySQL(normalized)) return executor_class_private_method_get(this, _enqueueReader, enqueueReader).call(this, kind, formatted, timeout, token, onRow);
4145
+ if ("execute" === kind && "read" === classifySQL(template.normalized)) return executor_class_private_method_get(this, _enqueueReader, enqueueReader).call(this, kind, formatted, timeout, token, onRow);
4039
4146
  }
4040
- return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, null, sqlNormalized);
4147
+ return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, null);
4041
4148
  }
4042
4149
  function enqueueWriter(kind, sql, timeout, token, onRow, scopeId) {
4043
4150
  var _this = this;
4044
- var sqlNormalized = arguments.length > 6 && void 0 !== arguments[6] ? arguments[6] : false;
4045
4151
  executor_class_private_field_get(this, executor_metrics).incrementTasksTotal(kind);
4046
4152
  return new Promise(function(resolve, reject) {
4047
4153
  var task = {
@@ -4051,13 +4157,11 @@ function enqueueWriter(kind, sql, timeout, token, onRow, scopeId) {
4051
4157
  token: token,
4052
4158
  onRow: onRow,
4053
4159
  scopeId: scopeId,
4054
- sqlNormalized: sqlNormalized,
4055
4160
  resolve: resolve,
4056
4161
  reject: reject,
4057
4162
  consumerError: null,
4058
4163
  stderrText: "",
4059
4164
  settled: false,
4060
- timer: null,
4061
4165
  startTime: 0,
4062
4166
  rowParser: null,
4063
4167
  rows: "query" === kind ? [] : null