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.
@@ -3,218 +3,9 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__ from "node:c
3
3
  import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
6
- function _check_private_redeclaration(obj, privateCollection) {
7
- if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
8
- }
9
- function _class_apply_descriptor_get(receiver, descriptor) {
10
- if (descriptor.get) return descriptor.get.call(receiver);
11
- return descriptor.value;
12
- }
13
- function _class_apply_descriptor_set(receiver, descriptor, value) {
14
- if (descriptor.set) descriptor.set.call(receiver, value);
15
- else {
16
- if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
17
- descriptor.value = value;
18
- }
19
- }
20
- function _class_call_check(instance, Constructor) {
21
- if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
22
- }
23
- function _class_extract_field_descriptor(receiver, privateMap, action) {
24
- if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
25
- return privateMap.get(receiver);
26
- }
27
- function _class_private_field_get(receiver, privateMap) {
28
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
29
- return _class_apply_descriptor_get(receiver, descriptor);
30
- }
31
- function _class_private_field_init(obj, privateMap, value) {
32
- _check_private_redeclaration(obj, privateMap);
33
- privateMap.set(obj, value);
34
- }
35
- function _class_private_field_set(receiver, privateMap, value) {
36
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
37
- _class_apply_descriptor_set(receiver, descriptor, value);
38
- return value;
39
- }
40
- function _defineProperties(target, props) {
41
- for(var i = 0; i < props.length; i++){
42
- var descriptor = props[i];
43
- descriptor.enumerable = descriptor.enumerable || false;
44
- descriptor.configurable = true;
45
- if ("value" in descriptor) descriptor.writable = true;
46
- Object.defineProperty(target, descriptor.key, descriptor);
47
- }
48
- }
49
- function _create_class(Constructor, protoProps, staticProps) {
50
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
51
- if (staticProps) _defineProperties(Constructor, staticProps);
52
- return Constructor;
53
- }
54
- var _maxSize = /*#__PURE__*/ new WeakMap(), _maxKeyLength = /*#__PURE__*/ new WeakMap(), _map = /*#__PURE__*/ new WeakMap();
55
- var lruCache_LRUCache = /*#__PURE__*/ function() {
56
- "use strict";
57
- function LRUCache() {
58
- 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;
59
- _class_call_check(this, LRUCache);
60
- _class_private_field_init(this, _maxSize, {
61
- writable: true,
62
- value: void 0
63
- });
64
- _class_private_field_init(this, _maxKeyLength, {
65
- writable: true,
66
- value: void 0
67
- });
68
- _class_private_field_init(this, _map, {
69
- writable: true,
70
- value: new Map()
71
- });
72
- _class_private_field_set(this, _maxSize, Math.max(1, maxSize));
73
- _class_private_field_set(this, _maxKeyLength, maxKeyLength);
74
- }
75
- _create_class(LRUCache, [
76
- {
77
- key: "get",
78
- value: function(key) {
79
- if ("string" != typeof key || key.length > _class_private_field_get(this, _maxKeyLength)) return;
80
- var value = _class_private_field_get(this, _map).get(key);
81
- if (void 0 === value) return;
82
- _class_private_field_get(this, _map)["delete"](key);
83
- _class_private_field_get(this, _map).set(key, value);
84
- return value;
85
- }
86
- },
87
- {
88
- key: "set",
89
- value: function(key, value) {
90
- if ("string" != typeof key || key.length > _class_private_field_get(this, _maxKeyLength)) return;
91
- if (_class_private_field_get(this, _map).size >= _class_private_field_get(this, _maxSize)) {
92
- var firstKey = _class_private_field_get(this, _map).keys().next().value;
93
- _class_private_field_get(this, _map)["delete"](firstKey);
94
- }
95
- _class_private_field_get(this, _map).set(key, value);
96
- }
97
- },
98
- {
99
- key: "size",
100
- get: function() {
101
- return _class_private_field_get(this, _map).size;
102
- }
103
- },
104
- {
105
- key: "clear",
106
- value: function() {
107
- _class_private_field_get(this, _map).clear();
108
- }
109
- }
110
- ]);
111
- return LRUCache;
112
- }();
113
- var CC_SINGLE_QUOTE = 39;
114
- var CC_DOUBLE_QUOTE = 34;
115
- var CC_DASH = 45;
116
- var CC_SLASH = 47;
117
- var CC_STAR = 42;
118
- var CC_NEWLINE = 10;
119
- var CC_QUESTION = 63;
120
- var CC_SEMICOLON = 59;
121
- var CC_SPACE = 32;
122
- var STATE_NORMAL = 0;
123
- var STATE_SINGLE_QUOTE = 1;
124
- var STATE_DOUBLE_QUOTE = 2;
125
- var STATE_LINE_COMMENT = 3;
126
- var STATE_BLOCK_COMMENT = 4;
127
- var _normBuf = new Uint16Array(1024);
128
- var _normDecoder = new TextDecoder("utf-16le");
129
- var _normCache = new lruCache_LRUCache({
130
- maxSize: 256,
131
- maxKeyLength: 4096
132
- });
133
- function normalizeSQL(sql) {
134
- var cached = _normCache.get(sql);
135
- if (void 0 !== cached) return cached;
136
- var len = sql.length;
137
- var needed = len + 1;
138
- if (_normBuf.length < needed) _normBuf = new Uint16Array(needed);
139
- var outCodes = _normBuf;
140
- var writePos = 0;
141
- var pendingSpace = false;
142
- var state = STATE_NORMAL;
143
- for(var i = 0; i < len; i++){
144
- var code = sql.charCodeAt(i);
145
- var nextCode = sql.charCodeAt(i + 1);
146
- if (state === STATE_BLOCK_COMMENT) {
147
- if (code === CC_STAR && nextCode === CC_SLASH) {
148
- state = STATE_NORMAL;
149
- i++;
150
- if (writePos > 0) pendingSpace = true;
151
- }
152
- continue;
153
- }
154
- if (state === STATE_LINE_COMMENT) {
155
- if (code === CC_NEWLINE) {
156
- state = STATE_NORMAL;
157
- if (writePos > 0) pendingSpace = true;
158
- }
159
- continue;
160
- }
161
- if (state === STATE_NORMAL) {
162
- if (code === CC_DASH && nextCode === CC_DASH) {
163
- state = STATE_LINE_COMMENT;
164
- i++;
165
- continue;
166
- }
167
- if (code === CC_SLASH && nextCode === CC_STAR) {
168
- state = STATE_BLOCK_COMMENT;
169
- i++;
170
- continue;
171
- }
172
- }
173
- if (32 === code || 9 === code || 10 === code || 11 === code || 12 === code || 13 === code) {
174
- if (writePos > 0) pendingSpace = true;
175
- continue;
176
- }
177
- if (pendingSpace && writePos > 0) {
178
- outCodes[writePos++] = CC_SPACE;
179
- pendingSpace = false;
180
- }
181
- outCodes[writePos++] = code;
182
- if (state === STATE_NORMAL) {
183
- if (code === CC_SINGLE_QUOTE) state = STATE_SINGLE_QUOTE;
184
- else if (code === CC_DOUBLE_QUOTE) state = STATE_DOUBLE_QUOTE;
185
- continue;
186
- }
187
- if (state === STATE_SINGLE_QUOTE) {
188
- if (code === CC_SINGLE_QUOTE && nextCode === CC_SINGLE_QUOTE) {
189
- outCodes[writePos++] = nextCode;
190
- i++;
191
- continue;
192
- }
193
- if (code === CC_SINGLE_QUOTE) state = STATE_NORMAL;
194
- continue;
195
- }
196
- if (state === STATE_DOUBLE_QUOTE) {
197
- if (code === CC_DOUBLE_QUOTE && nextCode === CC_DOUBLE_QUOTE) {
198
- outCodes[writePos++] = nextCode;
199
- i++;
200
- continue;
201
- }
202
- if (code === CC_DOUBLE_QUOTE) state = STATE_NORMAL;
203
- }
204
- }
205
- var result;
206
- if (0 === writePos) result = ";";
207
- else {
208
- while(writePos > 0 && outCodes[writePos - 1] === CC_SEMICOLON)writePos--;
209
- outCodes[writePos++] = CC_SEMICOLON;
210
- result = _normDecoder.decode(outCodes.subarray(0, writePos));
211
- }
212
- _normCache.set(sql, result);
213
- return result;
214
- }
215
6
  var DEFAULT_STATEMENT_TIMEOUT = 30000;
216
7
  function createTimeoutError(timeout, sql) {
217
- return new Error("SQLite statement timed out after ".concat(timeout, "ms: ").concat(normalizeSQL(sql)));
8
+ return new Error("SQLite statement timed out after ".concat(timeout, "ms: ").concat(sql));
218
9
  }
219
10
  function toError(value) {
220
11
  return value instanceof Error ? value : new Error(String(value));
@@ -245,56 +36,65 @@ function createJsonValueParser(onValue) {
245
36
  feed: function(chunk) {
246
37
  this.buffer += chunk;
247
38
  var consumeUntil = 0;
248
- for(var index = this.readPos; index < this.buffer.length; index++){
249
- var code = this.buffer.charCodeAt(index);
250
- if (-1 === this.start) {
39
+ var buffer = this.buffer;
40
+ var start = this.start;
41
+ var nesting = this.nesting;
42
+ var inString = this.inString;
43
+ var escaped = this.escaped;
44
+ for(var index = this.readPos; index < buffer.length; index++){
45
+ var code = buffer.charCodeAt(index);
46
+ if (-1 === start) {
251
47
  if (isWhitespaceCode(code)) continue;
252
48
  if (code !== CHAR_OPEN_BRACKET && code !== CHAR_OPEN_BRACE) continue;
253
- this.start = index;
254
- this.nesting = 1;
255
- this.inString = false;
256
- this.escaped = false;
49
+ start = index;
50
+ nesting = 1;
51
+ inString = false;
52
+ escaped = false;
257
53
  continue;
258
54
  }
259
- if (this.inString) {
260
- if (this.escaped) this.escaped = false;
261
- else if (code === CHAR_BACKSLASH) this.escaped = true;
262
- else if (code === CHAR_QUOTE) this.inString = false;
55
+ if (inString) {
56
+ if (escaped) escaped = false;
57
+ else if (code === CHAR_BACKSLASH) escaped = true;
58
+ else if (code === CHAR_QUOTE) inString = false;
263
59
  continue;
264
60
  }
265
61
  if (code === CHAR_QUOTE) {
266
- this.inString = true;
62
+ inString = true;
267
63
  continue;
268
64
  }
269
65
  if (code === CHAR_OPEN_BRACKET || code === CHAR_OPEN_BRACE) {
270
- this.nesting++;
66
+ nesting++;
271
67
  continue;
272
68
  }
273
69
  if (code === CHAR_CLOSE_BRACKET || code === CHAR_CLOSE_BRACE) {
274
- this.nesting--;
275
- if (0 === this.nesting) {
276
- if (index === this.start + 1) {
277
- this.start = -1;
70
+ nesting--;
71
+ if (0 === nesting) {
72
+ if (index === start + 1) {
73
+ start = -1;
278
74
  consumeUntil = index + 1;
279
75
  continue;
280
76
  }
281
- var raw = this.buffer.slice(this.start, index + 1);
282
- this.start = -1;
77
+ var raw = buffer.slice(start, index + 1);
78
+ start = -1;
283
79
  onValue(raw);
284
80
  consumeUntil = index + 1;
285
81
  }
286
82
  }
287
83
  }
84
+ this.start = start;
85
+ this.nesting = nesting;
86
+ this.inString = inString;
87
+ this.escaped = escaped;
288
88
  if (consumeUntil > 0) {
289
89
  this._consumed = consumeUntil;
290
- this.readPos = -1 !== this.start ? this.buffer.length : this._consumed;
90
+ this.readPos = -1 !== this.start ? buffer.length : this._consumed;
291
91
  if (this._consumed > 65536) {
292
92
  if (-1 !== this.start) this.start -= this._consumed;
293
93
  this.buffer = this.buffer.slice(this._consumed);
294
94
  this.readPos = this.buffer.length;
295
95
  this._consumed = 0;
296
96
  }
297
- } else this.readPos = this.buffer.length;
97
+ } else this.readPos = buffer.length;
298
98
  },
299
99
  reset: function() {
300
100
  this.buffer = "";
@@ -322,10 +122,18 @@ function createRowStreamParser(onRow) {
322
122
  feed: function(chunk) {
323
123
  if (this.finished) return chunk;
324
124
  this.buffer += chunk;
125
+ var buffer = this.buffer;
126
+ var started = this.started;
127
+ var inString = this.inString;
128
+ var escaped = this.escaped;
129
+ var elementStart = this.elementStart;
130
+ var elementEnd = this.elementEnd;
131
+ var nesting = this.nesting;
132
+ var consumed = this._consumed;
325
133
  var index = this.readPos;
326
- while(index < this.buffer.length){
327
- var code = this.buffer.charCodeAt(index);
328
- if (!this.started) {
134
+ while(index < buffer.length){
135
+ var code = buffer.charCodeAt(index);
136
+ if (!started) {
329
137
  if (isWhitespaceCode(code)) {
330
138
  index++;
331
139
  continue;
@@ -334,74 +142,81 @@ function createRowStreamParser(onRow) {
334
142
  index++;
335
143
  continue;
336
144
  }
337
- this.started = true;
145
+ started = true;
338
146
  index++;
339
147
  continue;
340
148
  }
341
- if (this.inString) {
342
- if (this.escaped) this.escaped = false;
343
- else if (code === CHAR_BACKSLASH) this.escaped = true;
344
- else if (code === CHAR_QUOTE) this.inString = false;
149
+ if (inString) {
150
+ if (escaped) escaped = false;
151
+ else if (code === CHAR_BACKSLASH) escaped = true;
152
+ else if (code === CHAR_QUOTE) inString = false;
345
153
  index++;
346
154
  continue;
347
155
  }
348
- if (-1 === this.elementStart) {
156
+ if (-1 === elementStart) {
349
157
  if (isWhitespaceCode(code) || code === CHAR_COMMA) {
350
158
  index++;
351
159
  continue;
352
160
  }
353
161
  if (code === CHAR_CLOSE_BRACKET) {
354
162
  this.finished = true;
355
- var leftover = this.buffer.slice(index + 1);
356
- this.buffer = "";
357
163
  this.readPos = 0;
358
- return leftover;
164
+ this.buffer = "";
165
+ this.started = false;
166
+ return buffer.slice(index + 1);
359
167
  }
360
- this.elementStart = index;
361
- this.elementEnd = -1;
362
- this.nesting = code === CHAR_OPEN_BRACE || code === CHAR_OPEN_BRACKET ? 1 : 0;
363
- this.inString = code === CHAR_QUOTE;
168
+ elementStart = index;
169
+ elementEnd = -1;
170
+ nesting = code === CHAR_OPEN_BRACE || code === CHAR_OPEN_BRACKET ? 1 : 0;
171
+ inString = code === CHAR_QUOTE;
172
+ escaped = false;
364
173
  index++;
365
174
  continue;
366
175
  }
367
176
  if (code === CHAR_QUOTE) {
368
- this.inString = true;
177
+ inString = true;
369
178
  index++;
370
179
  continue;
371
180
  }
372
181
  if (code === CHAR_OPEN_BRACE || code === CHAR_OPEN_BRACKET) {
373
- this.nesting++;
182
+ nesting++;
374
183
  index++;
375
184
  continue;
376
185
  }
377
186
  if (code === CHAR_CLOSE_BRACE || code === CHAR_CLOSE_BRACKET) {
378
- this.nesting--;
379
- if (0 === this.nesting) this.elementEnd = index + 1;
187
+ nesting--;
188
+ if (0 === nesting) elementEnd = index + 1;
380
189
  }
381
- if (-1 !== this.elementEnd) {
190
+ if (-1 !== elementEnd) {
382
191
  var lookAhead = index + 1;
383
- while(lookAhead < this.buffer.length && isWhitespaceCode(this.buffer.charCodeAt(lookAhead)))lookAhead++;
384
- if (lookAhead < this.buffer.length) {
385
- var delimiter = this.buffer.charCodeAt(lookAhead);
192
+ while(lookAhead < buffer.length && isWhitespaceCode(buffer.charCodeAt(lookAhead)))lookAhead++;
193
+ if (lookAhead < buffer.length) {
194
+ var delimiter = buffer.charCodeAt(lookAhead);
386
195
  if (delimiter === CHAR_COMMA || delimiter === CHAR_CLOSE_BRACKET) {
387
- onRow(this.buffer.slice(this.elementStart, this.elementEnd));
388
- this._consumed = lookAhead + 1;
389
- this.elementStart = -1;
390
- this.elementEnd = -1;
391
- this.nesting = 0;
196
+ onRow(buffer.slice(elementStart, elementEnd));
197
+ consumed = lookAhead + 1;
198
+ elementStart = -1;
199
+ elementEnd = -1;
200
+ nesting = 0;
392
201
  if (delimiter === CHAR_CLOSE_BRACKET) {
393
202
  this.finished = true;
394
- var tail = this.buffer.slice(this._consumed);
395
203
  this.buffer = "";
204
+ this.started = false;
205
+ this.inString = false;
206
+ this.escaped = false;
207
+ this.elementStart = -1;
208
+ this.elementEnd = -1;
209
+ this.nesting = 0;
396
210
  this._consumed = 0;
397
211
  this.readPos = 0;
398
- return tail;
212
+ return buffer.slice(consumed);
399
213
  }
400
- index = this._consumed;
401
- if (this._consumed > 65536) {
402
- this.buffer = this.buffer.slice(this._consumed);
403
- index = 0;
214
+ index = consumed;
215
+ if (consumed > 65536) {
216
+ this.buffer = buffer.slice(consumed);
404
217
  this._consumed = 0;
218
+ index = 0;
219
+ consumed = 0;
405
220
  }
406
221
  continue;
407
222
  }
@@ -409,12 +224,19 @@ function createRowStreamParser(onRow) {
409
224
  }
410
225
  index++;
411
226
  }
412
- if (this._consumed > 0) {
413
- if (-1 !== this.elementStart) {
414
- this.elementStart -= this._consumed;
415
- if (-1 !== this.elementEnd) this.elementEnd -= this._consumed;
227
+ this.started = started;
228
+ this.inString = inString;
229
+ this.escaped = escaped;
230
+ this.elementStart = elementStart;
231
+ this.elementEnd = elementEnd;
232
+ this.nesting = nesting;
233
+ this._consumed = consumed;
234
+ if (consumed > 0) {
235
+ if (-1 !== elementStart) {
236
+ this.elementStart -= consumed;
237
+ if (-1 !== elementEnd) this.elementEnd -= consumed;
416
238
  }
417
- this.buffer = this.buffer.slice(this._consumed);
239
+ this.buffer = buffer.slice(consumed);
418
240
  this._consumed = 0;
419
241
  }
420
242
  if (this.elementStart > 0) {
@@ -442,14 +264,14 @@ function createRowStreamParser(onRow) {
442
264
  var TOKEN_COLUMN = "__sqlite_executor_token__";
443
265
  var DEFAULT_BATCH_SIZE = 10;
444
266
  var DEFAULT_MAX_INFLIGHT = 50;
445
- function stream_check_private_redeclaration(obj, privateCollection) {
267
+ function _check_private_redeclaration(obj, privateCollection) {
446
268
  if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
447
269
  }
448
- function stream_class_apply_descriptor_get(receiver, descriptor) {
270
+ function _class_apply_descriptor_get(receiver, descriptor) {
449
271
  if (descriptor.get) return descriptor.get.call(receiver);
450
272
  return descriptor.value;
451
273
  }
452
- function stream_class_apply_descriptor_set(receiver, descriptor, value) {
274
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
453
275
  if (descriptor.set) descriptor.set.call(receiver, value);
454
276
  else {
455
277
  if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
@@ -472,31 +294,31 @@ function _class_apply_descriptor_update(receiver, descriptor) {
472
294
  if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
473
295
  return descriptor;
474
296
  }
475
- function stream_class_call_check(instance, Constructor) {
297
+ function _class_call_check(instance, Constructor) {
476
298
  if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
477
299
  }
478
- function stream_class_extract_field_descriptor(receiver, privateMap, action) {
300
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
479
301
  if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
480
302
  return privateMap.get(receiver);
481
303
  }
482
- function stream_class_private_field_get(receiver, privateMap) {
483
- var descriptor = stream_class_extract_field_descriptor(receiver, privateMap, "get");
484
- return stream_class_apply_descriptor_get(receiver, descriptor);
304
+ function _class_private_field_get(receiver, privateMap) {
305
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
306
+ return _class_apply_descriptor_get(receiver, descriptor);
485
307
  }
486
- function stream_class_private_field_init(obj, privateMap, value) {
487
- stream_check_private_redeclaration(obj, privateMap);
308
+ function _class_private_field_init(obj, privateMap, value) {
309
+ _check_private_redeclaration(obj, privateMap);
488
310
  privateMap.set(obj, value);
489
311
  }
490
- function stream_class_private_field_set(receiver, privateMap, value) {
491
- var descriptor = stream_class_extract_field_descriptor(receiver, privateMap, "set");
492
- stream_class_apply_descriptor_set(receiver, descriptor, value);
312
+ function _class_private_field_set(receiver, privateMap, value) {
313
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
314
+ _class_apply_descriptor_set(receiver, descriptor, value);
493
315
  return value;
494
316
  }
495
317
  function _class_private_field_update(receiver, privateMap) {
496
- var descriptor = stream_class_extract_field_descriptor(receiver, privateMap, "update");
318
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "update");
497
319
  return _class_apply_descriptor_update(receiver, descriptor);
498
320
  }
499
- function stream_defineProperties(target, props) {
321
+ function _defineProperties(target, props) {
500
322
  for(var i = 0; i < props.length; i++){
501
323
  var descriptor = props[i];
502
324
  descriptor.enumerable = descriptor.enumerable || false;
@@ -505,9 +327,9 @@ function stream_defineProperties(target, props) {
505
327
  Object.defineProperty(target, descriptor.key, descriptor);
506
328
  }
507
329
  }
508
- function stream_create_class(Constructor, protoProps, staticProps) {
509
- if (protoProps) stream_defineProperties(Constructor.prototype, protoProps);
510
- if (staticProps) stream_defineProperties(Constructor, staticProps);
330
+ function _create_class(Constructor, protoProps, staticProps) {
331
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
332
+ if (staticProps) _defineProperties(Constructor, staticProps);
511
333
  return Constructor;
512
334
  }
513
335
  function _type_of(obj) {
@@ -537,50 +359,50 @@ var _computedKey1 = _computedKey;
537
359
  var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
538
360
  "use strict";
539
361
  function AsyncRowBuffer() {
540
- stream_class_call_check(this, AsyncRowBuffer);
541
- stream_class_private_field_init(this, _buffer, {
362
+ _class_call_check(this, AsyncRowBuffer);
363
+ _class_private_field_init(this, _buffer, {
542
364
  writable: true,
543
365
  value: []
544
366
  });
545
- stream_class_private_field_init(this, _index, {
367
+ _class_private_field_init(this, _index, {
546
368
  writable: true,
547
369
  value: 0
548
370
  });
549
- stream_class_private_field_init(this, _done, {
371
+ _class_private_field_init(this, _done, {
550
372
  writable: true,
551
373
  value: false
552
374
  });
553
- stream_class_private_field_init(this, _error, {
375
+ _class_private_field_init(this, _error, {
554
376
  writable: true,
555
377
  value: null
556
378
  });
557
- stream_class_private_field_init(this, _pending, {
379
+ _class_private_field_init(this, _pending, {
558
380
  writable: true,
559
381
  value: null
560
382
  });
561
383
  }
562
- stream_create_class(AsyncRowBuffer, [
384
+ _create_class(AsyncRowBuffer, [
563
385
  {
564
386
  key: "push",
565
387
  value: function(row) {
566
- if (stream_class_private_field_get(this, _done) || stream_class_private_field_get(this, _error)) return;
567
- if (stream_class_private_field_get(this, _pending)) {
568
- var resolve = stream_class_private_field_get(this, _pending).resolve;
569
- stream_class_private_field_set(this, _pending, null);
388
+ if (_class_private_field_get(this, _done) || _class_private_field_get(this, _error)) return;
389
+ if (_class_private_field_get(this, _pending)) {
390
+ var resolve = _class_private_field_get(this, _pending).resolve;
391
+ _class_private_field_set(this, _pending, null);
570
392
  resolve({
571
393
  value: row,
572
394
  done: false
573
395
  });
574
- } else stream_class_private_field_get(this, _buffer).push(row);
396
+ } else _class_private_field_get(this, _buffer).push(row);
575
397
  }
576
398
  },
577
399
  {
578
400
  key: "end",
579
401
  value: function() {
580
- stream_class_private_field_set(this, _done, true);
581
- if (stream_class_private_field_get(this, _pending)) {
582
- var resolve = stream_class_private_field_get(this, _pending).resolve;
583
- stream_class_private_field_set(this, _pending, null);
402
+ _class_private_field_set(this, _done, true);
403
+ if (_class_private_field_get(this, _pending)) {
404
+ var resolve = _class_private_field_get(this, _pending).resolve;
405
+ _class_private_field_set(this, _pending, null);
584
406
  resolve({
585
407
  value: void 0,
586
408
  done: true
@@ -591,10 +413,10 @@ var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
591
413
  {
592
414
  key: "error",
593
415
  value: function(err) {
594
- stream_class_private_field_set(this, _error, err);
595
- if (stream_class_private_field_get(this, _pending)) {
596
- var reject = stream_class_private_field_get(this, _pending).reject;
597
- stream_class_private_field_set(this, _pending, null);
416
+ _class_private_field_set(this, _error, err);
417
+ if (_class_private_field_get(this, _pending)) {
418
+ var reject = _class_private_field_get(this, _pending).reject;
419
+ _class_private_field_set(this, _pending, null);
598
420
  reject(err);
599
421
  }
600
422
  }
@@ -603,17 +425,17 @@ var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
603
425
  key: "next",
604
426
  value: function() {
605
427
  var _this = this;
606
- if (stream_class_private_field_get(this, _index) < stream_class_private_field_get(this, _buffer).length) return Promise.resolve({
607
- value: stream_class_private_field_get(this, _buffer)[_class_private_field_update(this, _index).value++],
428
+ if (_class_private_field_get(this, _index) < _class_private_field_get(this, _buffer).length) return Promise.resolve({
429
+ value: _class_private_field_get(this, _buffer)[_class_private_field_update(this, _index).value++],
608
430
  done: false
609
431
  });
610
- if (stream_class_private_field_get(this, _done)) return Promise.resolve({
432
+ if (_class_private_field_get(this, _done)) return Promise.resolve({
611
433
  value: void 0,
612
434
  done: true
613
435
  });
614
- if (stream_class_private_field_get(this, _error)) return Promise.reject(stream_class_private_field_get(this, _error));
436
+ if (_class_private_field_get(this, _error)) return Promise.reject(_class_private_field_get(this, _error));
615
437
  return new Promise(function(resolve, reject) {
616
- stream_class_private_field_set(_this, _pending, {
438
+ _class_private_field_set(_this, _pending, {
617
439
  resolve: resolve,
618
440
  reject: reject
619
441
  });
@@ -623,12 +445,12 @@ var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
623
445
  {
624
446
  key: "return",
625
447
  value: function() {
626
- stream_class_private_field_set(this, _done, true);
627
- stream_class_private_field_set(this, _buffer, []);
628
- stream_class_private_field_set(this, _index, 0);
629
- if (stream_class_private_field_get(this, _pending)) {
630
- var resolve = stream_class_private_field_get(this, _pending).resolve;
631
- stream_class_private_field_set(this, _pending, null);
448
+ _class_private_field_set(this, _done, true);
449
+ _class_private_field_set(this, _buffer, []);
450
+ _class_private_field_set(this, _index, 0);
451
+ if (_class_private_field_get(this, _pending)) {
452
+ var resolve = _class_private_field_get(this, _pending).resolve;
453
+ _class_private_field_set(this, _pending, null);
632
454
  resolve({
633
455
  value: void 0,
634
456
  done: true
@@ -1161,6 +983,119 @@ function generateToken() {
1161
983
  _counter = _counter + 1 >>> 0;
1162
984
  return "".concat(_PREFIX).concat(_counter.toString(36), "_").concat(_PID36);
1163
985
  }
986
+ function lruCache_check_private_redeclaration(obj, privateCollection) {
987
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
988
+ }
989
+ function lruCache_class_apply_descriptor_get(receiver, descriptor) {
990
+ if (descriptor.get) return descriptor.get.call(receiver);
991
+ return descriptor.value;
992
+ }
993
+ function lruCache_class_apply_descriptor_set(receiver, descriptor, value) {
994
+ if (descriptor.set) descriptor.set.call(receiver, value);
995
+ else {
996
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
997
+ descriptor.value = value;
998
+ }
999
+ }
1000
+ function lruCache_class_call_check(instance, Constructor) {
1001
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
1002
+ }
1003
+ function lruCache_class_extract_field_descriptor(receiver, privateMap, action) {
1004
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
1005
+ return privateMap.get(receiver);
1006
+ }
1007
+ function lruCache_class_private_field_get(receiver, privateMap) {
1008
+ var descriptor = lruCache_class_extract_field_descriptor(receiver, privateMap, "get");
1009
+ return lruCache_class_apply_descriptor_get(receiver, descriptor);
1010
+ }
1011
+ function lruCache_class_private_field_init(obj, privateMap, value) {
1012
+ lruCache_check_private_redeclaration(obj, privateMap);
1013
+ privateMap.set(obj, value);
1014
+ }
1015
+ function lruCache_class_private_field_set(receiver, privateMap, value) {
1016
+ var descriptor = lruCache_class_extract_field_descriptor(receiver, privateMap, "set");
1017
+ lruCache_class_apply_descriptor_set(receiver, descriptor, value);
1018
+ return value;
1019
+ }
1020
+ function lruCache_defineProperties(target, props) {
1021
+ for(var i = 0; i < props.length; i++){
1022
+ var descriptor = props[i];
1023
+ descriptor.enumerable = descriptor.enumerable || false;
1024
+ descriptor.configurable = true;
1025
+ if ("value" in descriptor) descriptor.writable = true;
1026
+ Object.defineProperty(target, descriptor.key, descriptor);
1027
+ }
1028
+ }
1029
+ function lruCache_create_class(Constructor, protoProps, staticProps) {
1030
+ if (protoProps) lruCache_defineProperties(Constructor.prototype, protoProps);
1031
+ if (staticProps) lruCache_defineProperties(Constructor, staticProps);
1032
+ return Constructor;
1033
+ }
1034
+ var _maxSize = /*#__PURE__*/ new WeakMap(), _maxKeyLength = /*#__PURE__*/ new WeakMap(), _maxValueLength = /*#__PURE__*/ new WeakMap(), _map = /*#__PURE__*/ new WeakMap();
1035
+ var lruCache_LRUCache = /*#__PURE__*/ function() {
1036
+ "use strict";
1037
+ function LRUCache() {
1038
+ 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;
1039
+ lruCache_class_call_check(this, LRUCache);
1040
+ lruCache_class_private_field_init(this, _maxSize, {
1041
+ writable: true,
1042
+ value: void 0
1043
+ });
1044
+ lruCache_class_private_field_init(this, _maxKeyLength, {
1045
+ writable: true,
1046
+ value: void 0
1047
+ });
1048
+ lruCache_class_private_field_init(this, _maxValueLength, {
1049
+ writable: true,
1050
+ value: void 0
1051
+ });
1052
+ lruCache_class_private_field_init(this, _map, {
1053
+ writable: true,
1054
+ value: new Map()
1055
+ });
1056
+ lruCache_class_private_field_set(this, _maxSize, Math.max(1, maxSize));
1057
+ lruCache_class_private_field_set(this, _maxKeyLength, maxKeyLength);
1058
+ lruCache_class_private_field_set(this, _maxValueLength, maxValueLength);
1059
+ }
1060
+ lruCache_create_class(LRUCache, [
1061
+ {
1062
+ key: "get",
1063
+ value: function(key) {
1064
+ if ("string" != typeof key || key.length > lruCache_class_private_field_get(this, _maxKeyLength)) return;
1065
+ var value = lruCache_class_private_field_get(this, _map).get(key);
1066
+ if (void 0 === value) return;
1067
+ lruCache_class_private_field_get(this, _map)["delete"](key);
1068
+ lruCache_class_private_field_get(this, _map).set(key, value);
1069
+ return value;
1070
+ }
1071
+ },
1072
+ {
1073
+ key: "set",
1074
+ value: function(key, value) {
1075
+ if ("string" != typeof key || key.length > lruCache_class_private_field_get(this, _maxKeyLength)) return;
1076
+ if (value && value.length > lruCache_class_private_field_get(this, _maxValueLength)) return;
1077
+ if (lruCache_class_private_field_get(this, _map).size >= lruCache_class_private_field_get(this, _maxSize)) {
1078
+ var firstKey = lruCache_class_private_field_get(this, _map).keys().next().value;
1079
+ lruCache_class_private_field_get(this, _map)["delete"](firstKey);
1080
+ }
1081
+ lruCache_class_private_field_get(this, _map).set(key, value);
1082
+ }
1083
+ },
1084
+ {
1085
+ key: "size",
1086
+ get: function() {
1087
+ return lruCache_class_private_field_get(this, _map).size;
1088
+ }
1089
+ },
1090
+ {
1091
+ key: "clear",
1092
+ value: function() {
1093
+ lruCache_class_private_field_get(this, _map).clear();
1094
+ }
1095
+ }
1096
+ ]);
1097
+ return LRUCache;
1098
+ }();
1164
1099
  function escape_type_of(obj) {
1165
1100
  return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj;
1166
1101
  }
@@ -1172,110 +1107,168 @@ function escapeValue(value) {
1172
1107
  if (value instanceof Date) return "'".concat(value.toISOString(), "'");
1173
1108
  throw new TypeError("Unsupported parameter type: ".concat(void 0 === value ? "undefined" : escape_type_of(value)));
1174
1109
  }
1175
- var _interpCache = new lruCache_LRUCache({
1110
+ new lruCache_LRUCache({
1176
1111
  maxSize: 256,
1177
1112
  maxKeyLength: 4096
1178
1113
  });
1179
- function _parseTemplate(sql) {
1180
- var segments = [];
1181
- var segStart = 0;
1182
- var state = STATE_NORMAL;
1183
- var stateStartPos = -1;
1184
- for(var pos = 0; pos < sql.length; pos++){
1185
- var code = sql.charCodeAt(pos);
1186
- if (state === STATE_NORMAL) {
1187
- if (code === CC_SINGLE_QUOTE) {
1188
- state = STATE_SINGLE_QUOTE;
1189
- stateStartPos = pos;
1190
- continue;
1114
+ function interpolateFromTemplate(template, params) {
1115
+ var segments = template.segments, paramCount = template.paramCount;
1116
+ if (params.length < paramCount) throw new Error("Too few parameters provided");
1117
+ if (params.length > paramCount) throw new Error("Too many parameters provided");
1118
+ if (0 === paramCount) return segments[0];
1119
+ var parts = [
1120
+ segments[0]
1121
+ ];
1122
+ for(var i = 0; i < params.length; i++){
1123
+ parts.push(escapeValue(params[i]));
1124
+ parts.push(segments[i + 1]);
1125
+ }
1126
+ return parts.join("");
1127
+ }
1128
+ var constants_CC_SINGLE_QUOTE = 39;
1129
+ var constants_CC_DOUBLE_QUOTE = 34;
1130
+ var constants_CC_DASH = 45;
1131
+ var constants_CC_SLASH = 47;
1132
+ var constants_CC_STAR = 42;
1133
+ var constants_CC_NEWLINE = 10;
1134
+ var constants_CC_QUESTION = 63;
1135
+ var CC_SEMICOLON = 59;
1136
+ var CC_SPACE = 32;
1137
+ var constants_STATE_NORMAL = 0;
1138
+ var constants_STATE_SINGLE_QUOTE = 1;
1139
+ var constants_STATE_DOUBLE_QUOTE = 2;
1140
+ var constants_STATE_LINE_COMMENT = 3;
1141
+ var constants_STATE_BLOCK_COMMENT = 4;
1142
+ var _normDecoder = new TextDecoder("utf-16le");
1143
+ var _normCache = new lruCache_LRUCache({
1144
+ maxSize: 256,
1145
+ maxKeyLength: 4096
1146
+ });
1147
+ function _normalize(sql) {
1148
+ var len = sql.length;
1149
+ var needed = len + 1;
1150
+ var outCodes = new Uint16Array(needed);
1151
+ var writePos = 0;
1152
+ var pendingSpace = false;
1153
+ var state = constants_STATE_NORMAL;
1154
+ var questionPositions = [];
1155
+ for(var i = 0; i < len; i++){
1156
+ var code = sql.charCodeAt(i);
1157
+ var nextCode = sql.charCodeAt(i + 1);
1158
+ if (state === constants_STATE_BLOCK_COMMENT) {
1159
+ if (code === constants_CC_STAR && nextCode === constants_CC_SLASH) {
1160
+ state = constants_STATE_NORMAL;
1161
+ i++;
1162
+ if (writePos > 0) pendingSpace = true;
1191
1163
  }
1192
- if (code === CC_DOUBLE_QUOTE) {
1193
- state = STATE_DOUBLE_QUOTE;
1194
- stateStartPos = pos;
1195
- continue;
1164
+ continue;
1165
+ }
1166
+ if (state === constants_STATE_LINE_COMMENT) {
1167
+ if (code === constants_CC_NEWLINE) {
1168
+ state = constants_STATE_NORMAL;
1169
+ if (writePos > 0) pendingSpace = true;
1196
1170
  }
1197
- if (code === CC_DASH && sql.charCodeAt(pos + 1) === CC_DASH) {
1198
- state = STATE_LINE_COMMENT;
1199
- pos++;
1171
+ continue;
1172
+ }
1173
+ if (state === constants_STATE_NORMAL) {
1174
+ if (code === constants_CC_DASH && nextCode === constants_CC_DASH) {
1175
+ state = constants_STATE_LINE_COMMENT;
1176
+ i++;
1200
1177
  continue;
1201
1178
  }
1202
- if (code === CC_SLASH && sql.charCodeAt(pos + 1) === CC_STAR) {
1203
- state = STATE_BLOCK_COMMENT;
1204
- stateStartPos = pos;
1205
- pos++;
1179
+ if (code === constants_CC_SLASH && nextCode === constants_CC_STAR) {
1180
+ state = constants_STATE_BLOCK_COMMENT;
1181
+ i++;
1206
1182
  continue;
1207
1183
  }
1208
- if (code === CC_QUESTION) {
1209
- segments.push(sql.slice(segStart, pos));
1210
- segStart = pos + 1;
1211
- }
1212
- continue;
1213
1184
  }
1214
- if (state === STATE_SINGLE_QUOTE) {
1215
- if (code === CC_SINGLE_QUOTE) {
1216
- if (sql.charCodeAt(pos + 1) === CC_SINGLE_QUOTE) {
1217
- pos++;
1218
- continue;
1219
- }
1220
- state = STATE_NORMAL;
1221
- stateStartPos = -1;
1222
- }
1185
+ if (32 === code || 9 === code || 10 === code || 11 === code || 12 === code || 13 === code) {
1186
+ if (writePos > 0) pendingSpace = true;
1223
1187
  continue;
1224
1188
  }
1225
- if (state === STATE_DOUBLE_QUOTE) {
1226
- if (code === CC_DOUBLE_QUOTE) {
1227
- if (sql.charCodeAt(pos + 1) === CC_DOUBLE_QUOTE) {
1228
- pos++;
1229
- continue;
1230
- }
1231
- state = STATE_NORMAL;
1232
- stateStartPos = -1;
1233
- }
1189
+ if (pendingSpace && writePos > 0) {
1190
+ outCodes[writePos++] = CC_SPACE;
1191
+ pendingSpace = false;
1192
+ }
1193
+ if (code === constants_CC_QUESTION && state === constants_STATE_NORMAL) questionPositions.push(writePos);
1194
+ outCodes[writePos++] = code;
1195
+ if (state === constants_STATE_NORMAL) {
1196
+ if (code === constants_CC_SINGLE_QUOTE) state = constants_STATE_SINGLE_QUOTE;
1197
+ else if (code === constants_CC_DOUBLE_QUOTE) state = constants_STATE_DOUBLE_QUOTE;
1234
1198
  continue;
1235
1199
  }
1236
- if (state === STATE_LINE_COMMENT) {
1237
- if (code === CC_NEWLINE) state = STATE_NORMAL;
1200
+ if (state === constants_STATE_SINGLE_QUOTE) {
1201
+ if (code === constants_CC_SINGLE_QUOTE && nextCode === constants_CC_SINGLE_QUOTE) {
1202
+ outCodes[writePos++] = nextCode;
1203
+ i++;
1204
+ continue;
1205
+ }
1206
+ if (code === constants_CC_SINGLE_QUOTE) state = constants_STATE_NORMAL;
1238
1207
  continue;
1239
1208
  }
1240
- if (state === STATE_BLOCK_COMMENT) {
1241
- if (code === CC_STAR && sql.charCodeAt(pos + 1) === CC_SLASH) {
1242
- pos++;
1243
- state = STATE_NORMAL;
1244
- stateStartPos = -1;
1209
+ if (state === constants_STATE_DOUBLE_QUOTE) {
1210
+ if (code === constants_CC_DOUBLE_QUOTE && nextCode === constants_CC_DOUBLE_QUOTE) {
1211
+ outCodes[writePos++] = nextCode;
1212
+ i++;
1213
+ continue;
1245
1214
  }
1215
+ if (code === constants_CC_DOUBLE_QUOTE) state = constants_STATE_NORMAL;
1246
1216
  }
1247
1217
  }
1248
- if (state === STATE_SINGLE_QUOTE) throw new Error("Unterminated single-quoted string starting at position ".concat(stateStartPos + 1));
1249
- if (state === STATE_DOUBLE_QUOTE) throw new Error("Unterminated double-quoted identifier/string starting at position ".concat(stateStartPos + 1));
1250
- if (state === STATE_BLOCK_COMMENT) throw new Error("Unterminated block comment starting at position ".concat(stateStartPos + 1));
1251
- segments.push(sql.slice(segStart));
1218
+ var normalized;
1219
+ if (0 === writePos) normalized = ";";
1220
+ else {
1221
+ while(writePos > 0 && outCodes[writePos - 1] === CC_SEMICOLON)writePos--;
1222
+ outCodes[writePos++] = CC_SEMICOLON;
1223
+ normalized = _normDecoder.decode(outCodes.subarray(0, writePos));
1224
+ }
1225
+ var paramCount = questionPositions.length;
1226
+ if (0 === paramCount) return {
1227
+ normalized: normalized,
1228
+ segments: [
1229
+ normalized
1230
+ ],
1231
+ paramCount: 0
1232
+ };
1233
+ var segments = [];
1234
+ var segStart = 0;
1235
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1236
+ try {
1237
+ for(var _iterator = questionPositions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1238
+ var pos = _step.value;
1239
+ segments.push(normalized.slice(segStart, pos));
1240
+ segStart = pos + 1;
1241
+ }
1242
+ } catch (err) {
1243
+ _didIteratorError = true;
1244
+ _iteratorError = err;
1245
+ } finally{
1246
+ try {
1247
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
1248
+ } finally{
1249
+ if (_didIteratorError) throw _iteratorError;
1250
+ }
1251
+ }
1252
+ segments.push(normalized.slice(segStart));
1252
1253
  return {
1254
+ normalized: normalized,
1253
1255
  segments: segments,
1254
- paramCount: segments.length - 1
1256
+ paramCount: paramCount
1255
1257
  };
1256
1258
  }
1257
- function interpolateSQL(sql, params) {
1258
- if (!sql.includes("?")) {
1259
- if (params.length > 0) throw new Error("Too many parameters provided");
1260
- return sql;
1261
- }
1262
- var template = _interpCache.get(sql);
1263
- if (void 0 === template) {
1264
- template = _parseTemplate(sql);
1265
- _interpCache.set(sql, template);
1266
- }
1267
- var segments = template.segments, paramCount = template.paramCount;
1268
- if (params.length < paramCount) throw new Error("Too few parameters provided");
1269
- if (params.length > paramCount) throw new Error("Too many parameters provided");
1270
- if (0 === paramCount) return segments[0];
1271
- var parts = [
1272
- segments[0]
1273
- ];
1274
- for(var i = 0; i < params.length; i++){
1275
- parts.push(escapeValue(params[i]));
1276
- parts.push(segments[i + 1]);
1277
- }
1278
- return parts.join("");
1259
+ function normalizeSQL(sql) {
1260
+ var cached = _normCache.get(sql);
1261
+ if (void 0 !== cached) return cached.normalized;
1262
+ var result = _normalize(sql);
1263
+ _normCache.set(sql, result);
1264
+ return result.normalized;
1265
+ }
1266
+ function normalizeSQLTemplate(sql) {
1267
+ var cached = _normCache.get(sql);
1268
+ if (void 0 !== cached) return cached;
1269
+ var result = _normalize(sql);
1270
+ _normCache.set(sql, result);
1271
+ return result;
1279
1272
  }
1280
1273
  var READ_ONLY_KINDS = new Set([
1281
1274
  "SELECT",
@@ -1301,7 +1294,10 @@ function classifySQL(sql) {
1301
1294
  if (0 === trimmed.length) return "write";
1302
1295
  var result;
1303
1296
  if (trimmed.includes(";")) {
1304
- var stmts = trimmed.split(";");
1297
+ var stmts = trimmed.split(";").filter(function(s) {
1298
+ return s.trim().length > 0;
1299
+ });
1300
+ if (0 === stmts.length) return "write";
1305
1301
  result = "read";
1306
1302
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1307
1303
  try {
@@ -1722,8 +1718,11 @@ function buildPayload(sql, token) {
1722
1718
  return "".concat(normalized).concat(suffix, "\nSELECT '").concat(token, "' AS ").concat(TOKEN_COLUMN, ";\n");
1723
1719
  }
1724
1720
  function isTransactionControl(sql) {
1725
- var s = sql.toUpperCase();
1726
- 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 ");
1721
+ var f = sql.charCodeAt(0);
1722
+ if (66 === f || 98 === f) return "BEGIN" === sql || "BEGIN;" === sql || sql.startsWith("BEGIN ") || sql.startsWith("BEGIN;");
1723
+ if (67 === f || 99 === f) return "COMMIT" === sql || "COMMIT;" === sql || sql.startsWith("COMMIT ") || sql.startsWith("COMMIT;");
1724
+ if (82 === f || 114 === f) return "ROLLBACK" === sql || "ROLLBACK;" === sql || sql.startsWith("ROLLBACK ") || sql.startsWith("ROLLBACK;");
1725
+ return false;
1727
1726
  }
1728
1727
  function buildBatchPayload(batch) {
1729
1728
  var useWalBatch = batch.length > 1 && batch.every(function(t) {
@@ -1790,43 +1789,20 @@ function buildBatchPayload(batch) {
1790
1789
  return parts1.join("");
1791
1790
  }
1792
1791
  var TC_FIRST_CHAR = TOKEN_COLUMN.charCodeAt(0);
1792
+ function buildSentinelStr(token) {
1793
+ return '[{"'.concat(TOKEN_COLUMN, '":"').concat(token, '"}]');
1794
+ }
1793
1795
  function isSentinelRaw(raw, token) {
1794
- return raw.charCodeAt(3) === TC_FIRST_CHAR && raw === '[{"'.concat(TOKEN_COLUMN, '":"').concat(token, '"}]');
1796
+ return raw.charCodeAt(3) === TC_FIRST_CHAR && raw === buildSentinelStr(token);
1795
1797
  }
1796
1798
  function isSentinelRow(value, token) {
1797
1799
  var _value_;
1798
1800
  return Array.isArray(value) && 1 === value.length && (null == (_value_ = value[0]) ? void 0 : _value_[TOKEN_COLUMN]) === token;
1799
1801
  }
1800
- function _array_like_to_array(arr, len) {
1801
- if (null == len || len > arr.length) len = arr.length;
1802
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1803
- return arr2;
1804
- }
1805
- function _array_without_holes(arr) {
1806
- if (Array.isArray(arr)) return _array_like_to_array(arr);
1807
- }
1808
- function _iterable_to_array(iter) {
1809
- if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
1810
- }
1811
- function _non_iterable_spread() {
1812
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1813
- }
1814
- function _to_consumable_array(arr) {
1815
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
1816
- }
1817
- function _unsupported_iterable_to_array(o, minLen) {
1818
- if (!o) return;
1819
- if ("string" == typeof o) return _array_like_to_array(o, minLen);
1820
- var n = Object.prototype.toString.call(o).slice(8, -1);
1821
- if ("Object" === n && o.constructor) n = o.constructor.name;
1822
- if ("Map" === n || "Set" === n) return Array.from(n);
1823
- if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1824
- }
1825
1802
  function collectQueryRows(task, parsed) {
1826
1803
  if (Array.isArray(parsed)) {
1827
- var _task_rows;
1828
1804
  if (!task.rows) task.rows = [];
1829
- (_task_rows = task.rows).push.apply(_task_rows, _to_consumable_array(parsed));
1805
+ for(var i = 0; i < parsed.length; i++)task.rows.push(parsed[i]);
1830
1806
  }
1831
1807
  }
1832
1808
  function processStreamRows(task, parsed) {
@@ -1908,13 +1884,13 @@ function prepareTaskTimeout(task, metrics) {
1908
1884
  null == metrics || metrics.incrementTasksTimeout();
1909
1885
  return createTimeoutError(task.timeout, task.sql);
1910
1886
  }
1911
- function taskWorker_array_like_to_array(arr, len) {
1887
+ function _array_like_to_array(arr, len) {
1912
1888
  if (null == len || len > arr.length) len = arr.length;
1913
1889
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1914
1890
  return arr2;
1915
1891
  }
1916
- function taskWorker_array_without_holes(arr) {
1917
- if (Array.isArray(arr)) return taskWorker_array_like_to_array(arr);
1892
+ function _array_without_holes(arr) {
1893
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
1918
1894
  }
1919
1895
  function taskWorker_check_private_redeclaration(obj, privateCollection) {
1920
1896
  if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -1930,6 +1906,22 @@ function taskWorker_class_apply_descriptor_set(receiver, descriptor, value) {
1930
1906
  descriptor.value = value;
1931
1907
  }
1932
1908
  }
1909
+ function taskWorker_class_apply_descriptor_update(receiver, descriptor) {
1910
+ if (descriptor.set) {
1911
+ if (!descriptor.get) throw new TypeError("attempted to read set only private field");
1912
+ if (!("__destrWrapper" in descriptor)) descriptor.__destrWrapper = {
1913
+ set value (v){
1914
+ descriptor.set.call(receiver, v);
1915
+ },
1916
+ get value () {
1917
+ return descriptor.get.call(receiver);
1918
+ }
1919
+ };
1920
+ return descriptor.__destrWrapper;
1921
+ }
1922
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
1923
+ return descriptor;
1924
+ }
1933
1925
  function taskWorker_class_call_check(instance, Constructor) {
1934
1926
  if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
1935
1927
  }
@@ -1950,6 +1942,10 @@ function taskWorker_class_private_field_set(receiver, privateMap, value) {
1950
1942
  taskWorker_class_apply_descriptor_set(receiver, descriptor, value);
1951
1943
  return value;
1952
1944
  }
1945
+ function taskWorker_class_private_field_update(receiver, privateMap) {
1946
+ var descriptor = taskWorker_class_extract_field_descriptor(receiver, privateMap, "update");
1947
+ return taskWorker_class_apply_descriptor_update(receiver, descriptor);
1948
+ }
1953
1949
  function taskWorker_class_private_method_get(receiver, privateSet, fn) {
1954
1950
  if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
1955
1951
  return fn;
@@ -1972,35 +1968,39 @@ function taskWorker_create_class(Constructor, protoProps, staticProps) {
1972
1968
  if (staticProps) taskWorker_defineProperties(Constructor, staticProps);
1973
1969
  return Constructor;
1974
1970
  }
1975
- function taskWorker_iterable_to_array(iter) {
1971
+ function _iterable_to_array(iter) {
1976
1972
  if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
1977
1973
  }
1978
- function taskWorker_non_iterable_spread() {
1974
+ function _non_iterable_spread() {
1979
1975
  throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1980
1976
  }
1981
- function taskWorker_to_consumable_array(arr) {
1982
- return taskWorker_array_without_holes(arr) || taskWorker_iterable_to_array(arr) || taskWorker_unsupported_iterable_to_array(arr) || taskWorker_non_iterable_spread();
1977
+ function _to_consumable_array(arr) {
1978
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
1983
1979
  }
1984
- function taskWorker_unsupported_iterable_to_array(o, minLen) {
1980
+ function _unsupported_iterable_to_array(o, minLen) {
1985
1981
  if (!o) return;
1986
- if ("string" == typeof o) return taskWorker_array_like_to_array(o, minLen);
1982
+ if ("string" == typeof o) return _array_like_to_array(o, minLen);
1987
1983
  var n = Object.prototype.toString.call(o).slice(8, -1);
1988
1984
  if ("Object" === n && o.constructor) n = o.constructor.name;
1989
1985
  if ("Map" === n || "Set" === n) return Array.from(n);
1990
- if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return taskWorker_array_like_to_array(o, minLen);
1986
+ if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1991
1987
  }
1992
- 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();
1988
+ 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();
1993
1989
  var taskWorker_TaskWorker = /*#__PURE__*/ function() {
1994
1990
  "use strict";
1995
1991
  function TaskWorker(param) {
1996
1992
  var _this = this;
1997
- 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;
1993
+ 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;
1998
1994
  taskWorker_class_call_check(this, TaskWorker);
1999
1995
  taskWorker_class_private_method_init(this, _startProcess);
1996
+ taskWorker_class_private_method_init(this, _inflightCount);
1997
+ taskWorker_class_private_method_init(this, _firstInflight);
1998
+ taskWorker_class_private_method_init(this, _shiftInflight);
2000
1999
  taskWorker_class_private_method_init(this, _pumpQueue);
2001
2000
  taskWorker_class_private_method_init(this, _handleParsedValue);
2002
2001
  taskWorker_class_private_method_init(this, _scheduleFinalizeCheck);
2003
2002
  taskWorker_class_private_method_init(this, _handleStderrChunk);
2003
+ taskWorker_class_private_method_init(this, _scheduleSweep);
2004
2004
  taskWorker_class_private_method_init(this, _handleTaskTimeout);
2005
2005
  taskWorker_class_private_method_init(this, _settleTask);
2006
2006
  taskWorker_class_private_method_init(this, _rejectAll);
@@ -2016,6 +2016,10 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2016
2016
  writable: true,
2017
2017
  value: []
2018
2018
  });
2019
+ taskWorker_class_private_field_init(this, _inflightHead, {
2020
+ writable: true,
2021
+ value: 0
2022
+ });
2019
2023
  taskWorker_class_private_field_init(this, _pendingFinalizeTasks, {
2020
2024
  writable: true,
2021
2025
  value: new Set()
@@ -2052,12 +2056,21 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2052
2056
  writable: true,
2053
2057
  value: void 0
2054
2058
  });
2059
+ taskWorker_class_private_field_init(this, _sweepTimer, {
2060
+ writable: true,
2061
+ value: null
2062
+ });
2063
+ taskWorker_class_private_field_init(this, _sweepIntervalMs, {
2064
+ writable: true,
2065
+ value: void 0
2066
+ });
2055
2067
  taskWorker_class_private_field_set(this, _name, null != name ? name : "worker");
2056
2068
  taskWorker_class_private_field_set(this, _statementTimeout, statementTimeout);
2057
2069
  taskWorker_class_private_field_set(this, _logger, logger);
2058
2070
  taskWorker_class_private_field_set(this, _batchSize, batchSize);
2059
2071
  taskWorker_class_private_field_set(this, _maxInflight, maxInflight);
2060
2072
  taskWorker_class_private_field_set(this, _metrics, metrics);
2073
+ taskWorker_class_private_field_set(this, _sweepIntervalMs, sweepInterval);
2061
2074
  taskWorker_class_private_field_set(this, _processManager, new process_ProcessManager({
2062
2075
  binary: binary,
2063
2076
  database: database,
@@ -2081,13 +2094,13 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2081
2094
  {
2082
2095
  key: "idle",
2083
2096
  get: function() {
2084
- 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;
2097
+ 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;
2085
2098
  }
2086
2099
  },
2087
2100
  {
2088
2101
  key: "pendingStatements",
2089
2102
  get: function() {
2090
- 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;
2103
+ 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;
2091
2104
  }
2092
2105
  },
2093
2106
  {
@@ -2107,8 +2120,6 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2107
2120
  consumerError: null,
2108
2121
  stderrText: "",
2109
2122
  settled: false,
2110
- errorScheduled: false,
2111
- timer: null,
2112
2123
  startTime: 0
2113
2124
  };
2114
2125
  null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _metrics)) || _$_class_private_field_get.incrementTasksTotal(config.kind);
@@ -2116,6 +2127,12 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2116
2127
  taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2117
2128
  }
2118
2129
  },
2130
+ {
2131
+ key: "_sweepTimer",
2132
+ get: function() {
2133
+ return taskWorker_class_private_field_get(this, _sweepTimer);
2134
+ }
2135
+ },
2119
2136
  {
2120
2137
  key: "_process",
2121
2138
  get: function() {
@@ -2125,6 +2142,8 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2125
2142
  {
2126
2143
  key: "kill",
2127
2144
  value: function() {
2145
+ clearTimeout(taskWorker_class_private_field_get(this, _sweepTimer));
2146
+ taskWorker_class_private_field_set(this, _sweepTimer, null);
2128
2147
  taskWorker_class_private_method_get(this, _rejectAll, taskWorker_rejectAll).call(this, new Error("".concat(taskWorker_class_private_field_get(this, _name), " is killed")));
2129
2148
  taskWorker_class_private_field_get(this, _processManager).kill();
2130
2149
  }
@@ -2153,15 +2172,33 @@ function startProcess() {
2153
2172
  taskWorker_class_private_method_get(_this, _rejectAll, taskWorker_rejectAll).call(_this, err);
2154
2173
  });
2155
2174
  }
2175
+ function inflightCount() {
2176
+ return taskWorker_class_private_field_get(this, _inflightTasks).length - taskWorker_class_private_field_get(this, _inflightHead);
2177
+ }
2178
+ function firstInflight() {
2179
+ 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;
2180
+ }
2181
+ function shiftInflight() {
2182
+ var task = taskWorker_class_private_field_get(this, _inflightTasks)[taskWorker_class_private_field_get(this, _inflightHead)];
2183
+ taskWorker_class_private_field_get(this, _inflightTasks)[taskWorker_class_private_field_get(this, _inflightHead)] = null;
2184
+ taskWorker_class_private_field_update(this, _inflightHead).value++;
2185
+ if (taskWorker_class_private_field_get(this, _inflightHead) >= taskWorker_class_private_field_get(this, _inflightTasks).length) {
2186
+ taskWorker_class_private_field_set(this, _inflightTasks, []);
2187
+ taskWorker_class_private_field_set(this, _inflightHead, 0);
2188
+ } else if (taskWorker_class_private_field_get(this, _inflightHead) > 128) {
2189
+ taskWorker_class_private_field_set(this, _inflightTasks, taskWorker_class_private_field_get(this, _inflightTasks).slice(taskWorker_class_private_field_get(this, _inflightHead)));
2190
+ taskWorker_class_private_field_set(this, _inflightHead, 0);
2191
+ }
2192
+ return task;
2193
+ }
2156
2194
  function taskWorker_pumpQueue() {
2157
- var _this = this;
2158
2195
  var _$_class_private_field_get;
2159
2196
  if (taskWorker_class_private_field_get(this, _processManager).draining) return;
2160
- if (taskWorker_class_private_field_get(this, _inflightTasks).length >= taskWorker_class_private_field_get(this, _maxInflight)) return;
2197
+ if (taskWorker_class_private_method_get(this, _inflightCount, inflightCount).call(this) >= taskWorker_class_private_field_get(this, _maxInflight)) return;
2161
2198
  var batch = [];
2162
- 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)){
2199
+ 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)){
2163
2200
  var task = taskWorker_class_private_field_get(this, _pendingQueue).peek();
2164
- if ("stream" === task.kind && (batch.length > 0 || taskWorker_class_private_field_get(this, _inflightTasks).length > 0)) break;
2201
+ if ("stream" === task.kind && (batch.length > 0 || taskWorker_class_private_method_get(this, _inflightCount, inflightCount).call(this) > 0)) break;
2165
2202
  taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
2166
2203
  batch.push(task);
2167
2204
  }
@@ -2170,15 +2207,10 @@ function taskWorker_pumpQueue() {
2170
2207
  var payload = buildBatchPayload(batch);
2171
2208
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2172
2209
  try {
2173
- var _this1, _loop = function() {
2174
- var task = _step.value;
2175
- task.startTime = now;
2176
- var _task_timeout;
2177
- task.timer = setTimeout(function() {
2178
- return taskWorker_class_private_method_get(_this, _handleTaskTimeout, handleTaskTimeout).call(_this, task);
2179
- }, null != (_task_timeout = task.timeout) ? _task_timeout : taskWorker_class_private_field_get(_this1, _statementTimeout));
2180
- };
2181
- for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_this1 = this, _loop();
2210
+ for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2211
+ var task1 = _step.value;
2212
+ task1.startTime = now;
2213
+ }
2182
2214
  } catch (err) {
2183
2215
  _didIteratorError = true;
2184
2216
  _iteratorError = err;
@@ -2189,15 +2221,15 @@ function taskWorker_pumpQueue() {
2189
2221
  if (_didIteratorError) throw _iteratorError;
2190
2222
  }
2191
2223
  }
2192
- (_$_class_private_field_get = taskWorker_class_private_field_get(this, _inflightTasks)).push.apply(_$_class_private_field_get, taskWorker_to_consumable_array(batch));
2224
+ (_$_class_private_field_get = taskWorker_class_private_field_get(this, _inflightTasks)).push.apply(_$_class_private_field_get, _to_consumable_array(batch));
2225
+ taskWorker_class_private_method_get(this, _scheduleSweep, scheduleSweep).call(this);
2193
2226
  taskWorker_class_private_field_get(this, _processManager).write(payload);
2194
2227
  }
2195
2228
  function handleParsedValue(raw) {
2196
- var task = taskWorker_class_private_field_get(this, _inflightTasks)[0];
2229
+ var task = taskWorker_class_private_method_get(this, _firstInflight, firstInflight).call(this);
2197
2230
  if (!task) return;
2198
2231
  if (isSentinelRaw(raw, task.token)) {
2199
- clearTimeout(task.timer);
2200
- taskWorker_class_private_field_get(this, _inflightTasks).shift();
2232
+ taskWorker_class_private_method_get(this, _shiftInflight, shiftInflight).call(this);
2201
2233
  if (task.timedout) return void taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2202
2234
  if (task.stderrText) {
2203
2235
  taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, new Error(task.stderrText.trim()), void 0);
@@ -2223,8 +2255,7 @@ function handleParsedValue(raw) {
2223
2255
  return;
2224
2256
  }
2225
2257
  if (isSentinelRow(parsed, task.token)) {
2226
- clearTimeout(task.timer);
2227
- taskWorker_class_private_field_get(this, _inflightTasks).shift();
2258
+ taskWorker_class_private_method_get(this, _shiftInflight, shiftInflight).call(this);
2228
2259
  if (task.timedout) return void taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2229
2260
  if (task.stderrText) {
2230
2261
  taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, new Error(task.stderrText.trim()), void 0);
@@ -2241,6 +2272,7 @@ function handleParsedValue(raw) {
2241
2272
  taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2242
2273
  return;
2243
2274
  }
2275
+ if (task.timedout) return;
2244
2276
  if ("query" === task.kind) return void collectQueryRows(task, parsed);
2245
2277
  if ("stream" === task.kind) processStreamRows(task, parsed);
2246
2278
  }
@@ -2258,14 +2290,29 @@ function scheduleFinalizeCheck() {
2258
2290
  });
2259
2291
  }
2260
2292
  function taskWorker_handleStderrChunk(chunk) {
2261
- var _class_private_field_get_;
2262
- 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;
2293
+ var _class_private_field_get_values_next_value;
2294
+ 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);
2263
2295
  if (!task) {
2264
2296
  var _class_private_field_get_error, _$_class_private_field_get;
2265
- 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());
2297
+ 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());
2266
2298
  return;
2267
2299
  }
2268
- task.stderrText += String(chunk);
2300
+ task.stderrText += chunk;
2301
+ }
2302
+ function scheduleSweep() {
2303
+ var _this = this;
2304
+ if (taskWorker_class_private_field_get(this, _sweepTimer)) return;
2305
+ taskWorker_class_private_field_set(this, _sweepTimer, setTimeout(function() {
2306
+ taskWorker_class_private_field_set(_this, _sweepTimer, null);
2307
+ var tasks = taskWorker_class_private_field_get(_this, _inflightTasks);
2308
+ var head = taskWorker_class_private_field_get(_this, _inflightHead);
2309
+ var now = performance.now();
2310
+ for(var i = head; i < tasks.length; i++){
2311
+ var task = tasks[i];
2312
+ if (now - task.startTime > task.timeout) taskWorker_class_private_method_get(_this, _handleTaskTimeout, handleTaskTimeout).call(_this, task);
2313
+ }
2314
+ if (taskWorker_class_private_method_get(_this, _inflightCount, inflightCount).call(_this) > 0) taskWorker_class_private_method_get(_this, _scheduleSweep, scheduleSweep).call(_this);
2315
+ }, taskWorker_class_private_field_get(this, _sweepIntervalMs)).unref());
2269
2316
  }
2270
2317
  function handleTaskTimeout(task) {
2271
2318
  var error = prepareTaskTimeout(task, taskWorker_class_private_field_get(this, _metrics));
@@ -2275,8 +2322,12 @@ function settleTask1(task, error, value) {
2275
2322
  settleTask(task, error, value, taskWorker_class_private_field_get(this, _metrics));
2276
2323
  }
2277
2324
  function taskWorker_rejectAll(error) {
2278
- var all = taskWorker_class_private_field_get(this, _inflightTasks);
2325
+ clearTimeout(taskWorker_class_private_field_get(this, _sweepTimer));
2326
+ taskWorker_class_private_field_set(this, _sweepTimer, null);
2327
+ var activeCount = taskWorker_class_private_field_get(this, _inflightTasks).length - taskWorker_class_private_field_get(this, _inflightHead);
2328
+ var all = activeCount > 0 ? taskWorker_class_private_field_get(this, _inflightTasks).slice(taskWorker_class_private_field_get(this, _inflightHead)) : [];
2279
2329
  taskWorker_class_private_field_set(this, _inflightTasks, []);
2330
+ taskWorker_class_private_field_set(this, _inflightHead, 0);
2280
2331
  var queued = taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
2281
2332
  while(queued){
2282
2333
  taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, queued, error, void 0);
@@ -2410,9 +2461,19 @@ var readerPool_ReaderPool = /*#__PURE__*/ function() {
2410
2461
  {
2411
2462
  key: "enqueue",
2412
2463
  value: function(task) {
2413
- var worker = readerPool_class_private_field_get(this, _workers)[readerPool_class_private_field_get(this, _rrIndex) % readerPool_class_private_field_get(this, _workers).length];
2464
+ var minLoad = 1 / 0;
2465
+ var candidates = [];
2466
+ for(var i = 0; i < readerPool_class_private_field_get(this, _workers).length; i++){
2467
+ var load = readerPool_class_private_field_get(this, _workers)[i].pendingStatements;
2468
+ if (load < minLoad) {
2469
+ minLoad = load;
2470
+ candidates.length = 0;
2471
+ candidates.push(i);
2472
+ } else if (load === minLoad) candidates.push(i);
2473
+ }
2474
+ var idx = candidates[readerPool_class_private_field_get(this, _rrIndex) % candidates.length];
2414
2475
  readerPool_class_private_field_set(this, _rrIndex, readerPool_class_private_field_get(this, _rrIndex) + 1 >>> 0);
2415
- worker.enqueue(task);
2476
+ readerPool_class_private_field_get(this, _workers)[idx].enqueue(task);
2416
2477
  }
2417
2478
  },
2418
2479
  {
@@ -2905,9 +2966,7 @@ var transactionScope_TransactionScope = /*#__PURE__*/ function() {
2905
2966
  release = resolve;
2906
2967
  });
2907
2968
  previous = transactionScope_class_private_field_get(_this, _scopeChain);
2908
- transactionScope_class_private_field_set(_this, _scopeChain, previous["catch"](function() {}).then(function() {
2909
- return gate;
2910
- }));
2969
+ transactionScope_class_private_field_set(_this, _scopeChain, gate);
2911
2970
  return [
2912
2971
  4,
2913
2972
  previous["catch"](function() {})
@@ -2974,6 +3033,22 @@ function pipelineEngine_class_apply_descriptor_set(receiver, descriptor, value)
2974
3033
  descriptor.value = value;
2975
3034
  }
2976
3035
  }
3036
+ function pipelineEngine_class_apply_descriptor_update(receiver, descriptor) {
3037
+ if (descriptor.set) {
3038
+ if (!descriptor.get) throw new TypeError("attempted to read set only private field");
3039
+ if (!("__destrWrapper" in descriptor)) descriptor.__destrWrapper = {
3040
+ set value (v){
3041
+ descriptor.set.call(receiver, v);
3042
+ },
3043
+ get value () {
3044
+ return descriptor.get.call(receiver);
3045
+ }
3046
+ };
3047
+ return descriptor.__destrWrapper;
3048
+ }
3049
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
3050
+ return descriptor;
3051
+ }
2977
3052
  function pipelineEngine_class_call_check(instance, Constructor) {
2978
3053
  if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
2979
3054
  }
@@ -2994,6 +3069,10 @@ function pipelineEngine_class_private_field_set(receiver, privateMap, value) {
2994
3069
  pipelineEngine_class_apply_descriptor_set(receiver, descriptor, value);
2995
3070
  return value;
2996
3071
  }
3072
+ function pipelineEngine_class_private_field_update(receiver, privateMap) {
3073
+ var descriptor = pipelineEngine_class_extract_field_descriptor(receiver, privateMap, "update");
3074
+ return pipelineEngine_class_apply_descriptor_update(receiver, descriptor);
3075
+ }
2997
3076
  function pipelineEngine_class_private_method_get(receiver, privateSet, fn) {
2998
3077
  if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
2999
3078
  return fn;
@@ -3033,17 +3112,20 @@ function pipelineEngine_unsupported_iterable_to_array(o, minLen) {
3033
3112
  if ("Map" === n || "Set" === n) return Array.from(n);
3034
3113
  if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return pipelineEngine_array_like_to_array(o, minLen);
3035
3114
  }
3036
- 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();
3115
+ 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();
3037
3116
  var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3038
3117
  "use strict";
3039
3118
  function PipelineEngine(processManager, param) {
3040
3119
  var _this = this;
3041
3120
  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;
3042
3121
  pipelineEngine_class_call_check(this, PipelineEngine);
3122
+ pipelineEngine_class_private_method_init(this, pipelineEngine_inflightCount);
3123
+ pipelineEngine_class_private_method_init(this, core_pipelineEngine_firstInflight);
3124
+ pipelineEngine_class_private_method_init(this, core_pipelineEngine_shiftInflight);
3043
3125
  pipelineEngine_class_private_method_init(this, core_pipelineEngine_pumpQueue);
3044
3126
  pipelineEngine_class_private_method_init(this, pipelineEngine_handleParsedValue);
3045
3127
  pipelineEngine_class_private_method_init(this, core_pipelineEngine_scheduleFinalizeCheck);
3046
- pipelineEngine_class_private_method_init(this, _scheduleSweep);
3128
+ pipelineEngine_class_private_method_init(this, pipelineEngine_scheduleSweep);
3047
3129
  pipelineEngine_class_private_method_init(this, core_pipelineEngine_handleTaskTimeout);
3048
3130
  pipelineEngine_class_private_method_init(this, pipelineEngine_settleTask);
3049
3131
  pipelineEngine_class_private_field_init(this, _queue, {
@@ -3054,6 +3136,10 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3054
3136
  writable: true,
3055
3137
  value: []
3056
3138
  });
3139
+ pipelineEngine_class_private_field_init(this, pipelineEngine_inflightHead, {
3140
+ writable: true,
3141
+ value: 0
3142
+ });
3057
3143
  pipelineEngine_class_private_field_init(this, pipelineEngine_pendingFinalizeTasks, {
3058
3144
  writable: true,
3059
3145
  value: new Set()
@@ -3098,11 +3184,11 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3098
3184
  writable: true,
3099
3185
  value: false
3100
3186
  });
3101
- pipelineEngine_class_private_field_init(this, _sweepTimer, {
3187
+ pipelineEngine_class_private_field_init(this, pipelineEngine_sweepTimer, {
3102
3188
  writable: true,
3103
3189
  value: null
3104
3190
  });
3105
- pipelineEngine_class_private_field_init(this, _sweepIntervalMs, {
3191
+ pipelineEngine_class_private_field_init(this, pipelineEngine_sweepIntervalMs, {
3106
3192
  writable: true,
3107
3193
  value: void 0
3108
3194
  });
@@ -3119,13 +3205,13 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3119
3205
  pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).setOnDrainCallback(function() {
3120
3206
  return pipelineEngine_class_private_method_get(_this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(_this);
3121
3207
  });
3122
- pipelineEngine_class_private_field_set(this, _sweepIntervalMs, sweepInterval);
3208
+ pipelineEngine_class_private_field_set(this, pipelineEngine_sweepIntervalMs, sweepInterval);
3123
3209
  }
3124
3210
  pipelineEngine_create_class(PipelineEngine, [
3125
3211
  {
3126
3212
  key: "_sweepTimer",
3127
3213
  get: function() {
3128
- return pipelineEngine_class_private_field_get(this, _sweepTimer);
3214
+ return pipelineEngine_class_private_field_get(this, pipelineEngine_sweepTimer);
3129
3215
  }
3130
3216
  },
3131
3217
  {
@@ -3143,7 +3229,7 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3143
3229
  {
3144
3230
  key: "pendingStatements",
3145
3231
  get: function() {
3146
- 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;
3232
+ 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;
3147
3233
  }
3148
3234
  },
3149
3235
  {
@@ -3176,7 +3262,7 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3176
3262
  {
3177
3263
  key: "handleStdoutChunk",
3178
3264
  value: function(chunk) {
3179
- var task = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[0];
3265
+ var task = pipelineEngine_class_private_method_get(this, core_pipelineEngine_firstInflight, pipelineEngine_firstInflight).call(this);
3180
3266
  if (!task) return;
3181
3267
  if ("stream" === task.kind && task.rowParser && !task.rowParser.finished && !task.timedout) {
3182
3268
  var leftover = task.rowParser.feed(chunk);
@@ -3190,21 +3276,23 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3190
3276
  key: "handleStderrChunk",
3191
3277
  value: function(chunk) {
3192
3278
  var _class_private_field_get_values_next_value;
3193
- 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];
3279
+ 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);
3194
3280
  if (!task) {
3195
3281
  var _class_private_field_get_error, _$_class_private_field_get;
3196
- 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());
3282
+ 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());
3197
3283
  return;
3198
3284
  }
3199
- task.stderrText += String(chunk);
3285
+ task.stderrText += chunk;
3200
3286
  }
3201
3287
  },
3202
3288
  {
3203
3289
  key: "rejectAll",
3204
3290
  value: function(error) {
3205
3291
  pipelineEngine_class_private_field_get(this, _sharedValueParser).reset();
3206
- var all = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks);
3292
+ var activeCount = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length - pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead);
3293
+ var all = activeCount > 0 ? pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).slice(pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead)) : [];
3207
3294
  pipelineEngine_class_private_field_set(this, pipelineEngine_inflightTasks, []);
3295
+ pipelineEngine_class_private_field_set(this, pipelineEngine_inflightHead, 0);
3208
3296
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
3209
3297
  try {
3210
3298
  for(var _iterator = all[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -3249,23 +3337,42 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3249
3337
  key: "kill",
3250
3338
  value: function() {
3251
3339
  pipelineEngine_class_private_field_set(this, _active, false);
3252
- clearTimeout(pipelineEngine_class_private_field_get(this, _sweepTimer));
3253
- pipelineEngine_class_private_field_set(this, _sweepTimer, null);
3340
+ clearTimeout(pipelineEngine_class_private_field_get(this, pipelineEngine_sweepTimer));
3341
+ pipelineEngine_class_private_field_set(this, pipelineEngine_sweepTimer, null);
3254
3342
  this.rejectAll(new Error("PipelineEngine is killed"));
3255
3343
  }
3256
3344
  }
3257
3345
  ]);
3258
3346
  return PipelineEngine;
3259
3347
  }();
3348
+ function core_pipelineEngine_inflightCount() {
3349
+ return pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length - pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead);
3350
+ }
3351
+ function pipelineEngine_firstInflight() {
3352
+ 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;
3353
+ }
3354
+ function pipelineEngine_shiftInflight() {
3355
+ var task = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead)];
3356
+ pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead)] = null;
3357
+ pipelineEngine_class_private_field_update(this, pipelineEngine_inflightHead).value++;
3358
+ if (pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead) >= pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length) {
3359
+ pipelineEngine_class_private_field_set(this, pipelineEngine_inflightTasks, []);
3360
+ pipelineEngine_class_private_field_set(this, pipelineEngine_inflightHead, 0);
3361
+ } else if (pipelineEngine_class_private_field_get(this, pipelineEngine_inflightHead) > 128) {
3362
+ 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)));
3363
+ pipelineEngine_class_private_field_set(this, pipelineEngine_inflightHead, 0);
3364
+ }
3365
+ return task;
3366
+ }
3260
3367
  function pipelineEngine_pumpQueue() {
3261
3368
  var _$_class_private_field_get;
3262
3369
  if (!pipelineEngine_class_private_field_get(this, _active)) return;
3263
3370
  if (pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).draining) return;
3264
- if (pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length >= pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)) return;
3371
+ if (pipelineEngine_class_private_method_get(this, pipelineEngine_inflightCount, core_pipelineEngine_inflightCount).call(this) >= pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)) return;
3265
3372
  var batch = [];
3266
- 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)){
3373
+ 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)){
3267
3374
  var task = pipelineEngine_class_private_field_get(this, _queue).peek();
3268
- if ("stream" === task.kind && (batch.length > 0 || pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length > 0)) break;
3375
+ if ("stream" === task.kind && (batch.length > 0 || pipelineEngine_class_private_method_get(this, pipelineEngine_inflightCount, core_pipelineEngine_inflightCount).call(this) > 0)) break;
3269
3376
  pipelineEngine_class_private_field_get(this, _queue).dequeue();
3270
3377
  batch.push(task);
3271
3378
  }
@@ -3289,14 +3396,14 @@ function pipelineEngine_pumpQueue() {
3289
3396
  }
3290
3397
  }
3291
3398
  (_$_class_private_field_get = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)).push.apply(_$_class_private_field_get, pipelineEngine_to_consumable_array(batch));
3292
- pipelineEngine_class_private_method_get(this, _scheduleSweep, scheduleSweep).call(this);
3399
+ pipelineEngine_class_private_method_get(this, pipelineEngine_scheduleSweep, core_pipelineEngine_scheduleSweep).call(this);
3293
3400
  pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).write(payload);
3294
3401
  }
3295
3402
  function core_pipelineEngine_handleParsedValue(raw) {
3296
- var task = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[0];
3403
+ var task = pipelineEngine_class_private_method_get(this, core_pipelineEngine_firstInflight, pipelineEngine_firstInflight).call(this);
3297
3404
  if (!task) return;
3298
3405
  if (isSentinelRaw(raw, task.token)) {
3299
- pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).shift();
3406
+ pipelineEngine_class_private_method_get(this, core_pipelineEngine_shiftInflight, pipelineEngine_shiftInflight).call(this);
3300
3407
  if (task.timedout) return void pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3301
3408
  if (task.consumerError) {
3302
3409
  pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, task.consumerError, void 0);
@@ -3317,7 +3424,7 @@ function core_pipelineEngine_handleParsedValue(raw) {
3317
3424
  return;
3318
3425
  }
3319
3426
  if (isSentinelRow(parsed, task.token)) {
3320
- pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).shift();
3427
+ pipelineEngine_class_private_method_get(this, core_pipelineEngine_shiftInflight, pipelineEngine_shiftInflight).call(this);
3321
3428
  if (task.timedout) return void pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3322
3429
  if (task.consumerError) {
3323
3430
  pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, task.consumerError, void 0);
@@ -3346,19 +3453,20 @@ function pipelineEngine_scheduleFinalizeCheck() {
3346
3453
  });
3347
3454
  });
3348
3455
  }
3349
- function scheduleSweep() {
3456
+ function core_pipelineEngine_scheduleSweep() {
3350
3457
  var _this = this;
3351
- if (pipelineEngine_class_private_field_get(this, _sweepTimer)) return;
3352
- pipelineEngine_class_private_field_set(this, _sweepTimer, setTimeout(function() {
3353
- pipelineEngine_class_private_field_set(_this, _sweepTimer, null);
3354
- var inflight = pipelineEngine_class_private_field_get(_this, pipelineEngine_inflightTasks);
3458
+ if (pipelineEngine_class_private_field_get(this, pipelineEngine_sweepTimer)) return;
3459
+ pipelineEngine_class_private_field_set(this, pipelineEngine_sweepTimer, setTimeout(function() {
3460
+ pipelineEngine_class_private_field_set(_this, pipelineEngine_sweepTimer, null);
3461
+ var tasks = pipelineEngine_class_private_field_get(_this, pipelineEngine_inflightTasks);
3462
+ var head = pipelineEngine_class_private_field_get(_this, pipelineEngine_inflightHead);
3355
3463
  var now = performance.now();
3356
- for(var i = 0; i < inflight.length; i++){
3357
- var task = inflight[i];
3464
+ for(var i = head; i < tasks.length; i++){
3465
+ var task = tasks[i];
3358
3466
  if (now - task.startTime > task.timeout) pipelineEngine_class_private_method_get(_this, core_pipelineEngine_handleTaskTimeout, pipelineEngine_handleTaskTimeout).call(_this, task);
3359
3467
  }
3360
- if (pipelineEngine_class_private_field_get(_this, pipelineEngine_inflightTasks).length > 0) pipelineEngine_class_private_method_get(_this, _scheduleSweep, scheduleSweep).call(_this);
3361
- }, pipelineEngine_class_private_field_get(this, _sweepIntervalMs)).unref());
3468
+ 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);
3469
+ }, pipelineEngine_class_private_field_get(this, pipelineEngine_sweepIntervalMs)).unref());
3362
3470
  }
3363
3471
  function pipelineEngine_handleTaskTimeout(task) {
3364
3472
  var _this, _this1;
@@ -3968,20 +4076,18 @@ function executor_enqueue(kind, sql, params, options, scopeId) {
3968
4076
  var token = generateToken();
3969
4077
  var _options_onRow;
3970
4078
  var onRow = null != (_options_onRow = null == options ? void 0 : options.onRow) ? _options_onRow : null;
3971
- var normalized = normalizeSQL(sql);
4079
+ var template = normalizeSQLTemplate(sql);
3972
4080
  var formatted;
3973
- var sqlNormalized = true;
3974
- formatted = 0 !== params.length || normalized.includes("?") ? interpolateSQL(normalized, params) : normalized;
3975
- if (scopeId) return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, scopeId, sqlNormalized);
4081
+ formatted = 0 === params.length && 0 === template.paramCount ? template.normalized : interpolateFromTemplate(template, params);
4082
+ if (scopeId) return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, scopeId);
3976
4083
  if (executor_class_private_field_get(this, _readerPool)) {
3977
4084
  if ("stream" === kind || "query" === kind) return executor_class_private_method_get(this, _enqueueReader, enqueueReader).call(this, kind, formatted, timeout, token, onRow);
3978
- if ("execute" === kind && "read" === classifySQL(normalized)) return executor_class_private_method_get(this, _enqueueReader, enqueueReader).call(this, kind, formatted, timeout, token, onRow);
4085
+ if ("execute" === kind && "read" === classifySQL(template.normalized)) return executor_class_private_method_get(this, _enqueueReader, enqueueReader).call(this, kind, formatted, timeout, token, onRow);
3979
4086
  }
3980
- return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, null, sqlNormalized);
4087
+ return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, null);
3981
4088
  }
3982
4089
  function enqueueWriter(kind, sql, timeout, token, onRow, scopeId) {
3983
4090
  var _this = this;
3984
- var sqlNormalized = arguments.length > 6 && void 0 !== arguments[6] ? arguments[6] : false;
3985
4091
  executor_class_private_field_get(this, executor_metrics).incrementTasksTotal(kind);
3986
4092
  return new Promise(function(resolve, reject) {
3987
4093
  var task = {
@@ -3991,13 +4097,11 @@ function enqueueWriter(kind, sql, timeout, token, onRow, scopeId) {
3991
4097
  token: token,
3992
4098
  onRow: onRow,
3993
4099
  scopeId: scopeId,
3994
- sqlNormalized: sqlNormalized,
3995
4100
  resolve: resolve,
3996
4101
  reject: reject,
3997
4102
  consumerError: null,
3998
4103
  stderrText: "",
3999
4104
  settled: false,
4000
- timer: null,
4001
4105
  startTime: 0,
4002
4106
  rowParser: null,
4003
4107
  rows: "query" === kind ? [] : null