sqlite-executor 4.0.5 → 4.0.7

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.
@@ -55,219 +55,9 @@ __webpack_require__.d(__webpack_exports__, {
55
55
  return metrics_Metrics;
56
56
  }
57
57
  });
58
- var external_node_events_namespaceObject = require("node:events");
59
- function _check_private_redeclaration(obj, privateCollection) {
60
- if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
61
- }
62
- function _class_apply_descriptor_get(receiver, descriptor) {
63
- if (descriptor.get) return descriptor.get.call(receiver);
64
- return descriptor.value;
65
- }
66
- function _class_apply_descriptor_set(receiver, descriptor, value) {
67
- if (descriptor.set) descriptor.set.call(receiver, value);
68
- else {
69
- if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
70
- descriptor.value = value;
71
- }
72
- }
73
- function _class_call_check(instance, Constructor) {
74
- if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
75
- }
76
- function _class_extract_field_descriptor(receiver, privateMap, action) {
77
- if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
78
- return privateMap.get(receiver);
79
- }
80
- function _class_private_field_get(receiver, privateMap) {
81
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
82
- return _class_apply_descriptor_get(receiver, descriptor);
83
- }
84
- function _class_private_field_init(obj, privateMap, value) {
85
- _check_private_redeclaration(obj, privateMap);
86
- privateMap.set(obj, value);
87
- }
88
- function _class_private_field_set(receiver, privateMap, value) {
89
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
90
- _class_apply_descriptor_set(receiver, descriptor, value);
91
- return value;
92
- }
93
- function _defineProperties(target, props) {
94
- for(var i = 0; i < props.length; i++){
95
- var descriptor = props[i];
96
- descriptor.enumerable = descriptor.enumerable || false;
97
- descriptor.configurable = true;
98
- if ("value" in descriptor) descriptor.writable = true;
99
- Object.defineProperty(target, descriptor.key, descriptor);
100
- }
101
- }
102
- function _create_class(Constructor, protoProps, staticProps) {
103
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
104
- if (staticProps) _defineProperties(Constructor, staticProps);
105
- return Constructor;
106
- }
107
- var _maxSize = /*#__PURE__*/ new WeakMap(), _maxKeyLength = /*#__PURE__*/ new WeakMap(), _map = /*#__PURE__*/ new WeakMap();
108
- var lruCache_LRUCache = /*#__PURE__*/ function() {
109
- "use strict";
110
- function LRUCache() {
111
- var _ref = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, _ref_maxSize = _ref.maxSize, maxSize = void 0 === _ref_maxSize ? 256 : _ref_maxSize, _ref_maxKeyLength = _ref.maxKeyLength, maxKeyLength = void 0 === _ref_maxKeyLength ? 4096 : _ref_maxKeyLength;
112
- _class_call_check(this, LRUCache);
113
- _class_private_field_init(this, _maxSize, {
114
- writable: true,
115
- value: void 0
116
- });
117
- _class_private_field_init(this, _maxKeyLength, {
118
- writable: true,
119
- value: void 0
120
- });
121
- _class_private_field_init(this, _map, {
122
- writable: true,
123
- value: new Map()
124
- });
125
- _class_private_field_set(this, _maxSize, Math.max(1, maxSize));
126
- _class_private_field_set(this, _maxKeyLength, maxKeyLength);
127
- }
128
- _create_class(LRUCache, [
129
- {
130
- key: "get",
131
- value: function(key) {
132
- if ("string" != typeof key || key.length > _class_private_field_get(this, _maxKeyLength)) return;
133
- var value = _class_private_field_get(this, _map).get(key);
134
- if (void 0 === value) return;
135
- _class_private_field_get(this, _map)["delete"](key);
136
- _class_private_field_get(this, _map).set(key, value);
137
- return value;
138
- }
139
- },
140
- {
141
- key: "set",
142
- value: function(key, value) {
143
- if ("string" != typeof key || key.length > _class_private_field_get(this, _maxKeyLength)) return;
144
- if (_class_private_field_get(this, _map).size >= _class_private_field_get(this, _maxSize)) {
145
- var firstKey = _class_private_field_get(this, _map).keys().next().value;
146
- _class_private_field_get(this, _map)["delete"](firstKey);
147
- }
148
- _class_private_field_get(this, _map).set(key, value);
149
- }
150
- },
151
- {
152
- key: "size",
153
- get: function() {
154
- return _class_private_field_get(this, _map).size;
155
- }
156
- },
157
- {
158
- key: "clear",
159
- value: function() {
160
- _class_private_field_get(this, _map).clear();
161
- }
162
- }
163
- ]);
164
- return LRUCache;
165
- }();
166
- var CC_SINGLE_QUOTE = 39;
167
- var CC_DOUBLE_QUOTE = 34;
168
- var CC_DASH = 45;
169
- var CC_SLASH = 47;
170
- var CC_STAR = 42;
171
- var CC_NEWLINE = 10;
172
- var CC_QUESTION = 63;
173
- var CC_SEMICOLON = 59;
174
- var CC_SPACE = 32;
175
- var STATE_NORMAL = 0;
176
- var STATE_SINGLE_QUOTE = 1;
177
- var STATE_DOUBLE_QUOTE = 2;
178
- var STATE_LINE_COMMENT = 3;
179
- var STATE_BLOCK_COMMENT = 4;
180
- var _normBuf = new Uint16Array(1024);
181
- var _normDecoder = new TextDecoder("utf-16le");
182
- var _normCache = new lruCache_LRUCache({
183
- maxSize: 256,
184
- maxKeyLength: 4096
185
- });
186
- function normalizeSQL(sql) {
187
- var cached = _normCache.get(sql);
188
- if (void 0 !== cached) return cached;
189
- var len = sql.length;
190
- var needed = len + 1;
191
- if (_normBuf.length < needed) _normBuf = new Uint16Array(needed);
192
- var outCodes = _normBuf;
193
- var writePos = 0;
194
- var pendingSpace = false;
195
- var state = STATE_NORMAL;
196
- for(var i = 0; i < len; i++){
197
- var code = sql.charCodeAt(i);
198
- var nextCode = sql.charCodeAt(i + 1);
199
- if (state === STATE_BLOCK_COMMENT) {
200
- if (code === CC_STAR && nextCode === CC_SLASH) {
201
- state = STATE_NORMAL;
202
- i++;
203
- if (writePos > 0) pendingSpace = true;
204
- }
205
- continue;
206
- }
207
- if (state === STATE_LINE_COMMENT) {
208
- if (code === CC_NEWLINE) {
209
- state = STATE_NORMAL;
210
- if (writePos > 0) pendingSpace = true;
211
- }
212
- continue;
213
- }
214
- if (state === STATE_NORMAL) {
215
- if (code === CC_DASH && nextCode === CC_DASH) {
216
- state = STATE_LINE_COMMENT;
217
- i++;
218
- continue;
219
- }
220
- if (code === CC_SLASH && nextCode === CC_STAR) {
221
- state = STATE_BLOCK_COMMENT;
222
- i++;
223
- continue;
224
- }
225
- }
226
- if (32 === code || 9 === code || 10 === code || 11 === code || 12 === code || 13 === code) {
227
- if (writePos > 0) pendingSpace = true;
228
- continue;
229
- }
230
- if (pendingSpace && writePos > 0) {
231
- outCodes[writePos++] = CC_SPACE;
232
- pendingSpace = false;
233
- }
234
- outCodes[writePos++] = code;
235
- if (state === STATE_NORMAL) {
236
- if (code === CC_SINGLE_QUOTE) state = STATE_SINGLE_QUOTE;
237
- else if (code === CC_DOUBLE_QUOTE) state = STATE_DOUBLE_QUOTE;
238
- continue;
239
- }
240
- if (state === STATE_SINGLE_QUOTE) {
241
- if (code === CC_SINGLE_QUOTE && nextCode === CC_SINGLE_QUOTE) {
242
- outCodes[writePos++] = nextCode;
243
- i++;
244
- continue;
245
- }
246
- if (code === CC_SINGLE_QUOTE) state = STATE_NORMAL;
247
- continue;
248
- }
249
- if (state === STATE_DOUBLE_QUOTE) {
250
- if (code === CC_DOUBLE_QUOTE && nextCode === CC_DOUBLE_QUOTE) {
251
- outCodes[writePos++] = nextCode;
252
- i++;
253
- continue;
254
- }
255
- if (code === CC_DOUBLE_QUOTE) state = STATE_NORMAL;
256
- }
257
- }
258
- var result;
259
- if (0 === writePos) result = ";";
260
- else {
261
- while(writePos > 0 && outCodes[writePos - 1] === CC_SEMICOLON)writePos--;
262
- outCodes[writePos++] = CC_SEMICOLON;
263
- result = _normDecoder.decode(outCodes.subarray(0, writePos));
264
- }
265
- _normCache.set(sql, result);
266
- return result;
267
- }
268
58
  var DEFAULT_STATEMENT_TIMEOUT = 30000;
269
59
  function createTimeoutError(timeout, sql) {
270
- return new Error("SQLite statement timed out after ".concat(timeout, "ms: ").concat(normalizeSQL(sql)));
60
+ return new Error("SQLite statement timed out after ".concat(timeout, "ms: ").concat(sql));
271
61
  }
272
62
  function toError(value) {
273
63
  return value instanceof Error ? value : new Error(String(value));
@@ -298,56 +88,65 @@ function createJsonValueParser(onValue) {
298
88
  feed: function(chunk) {
299
89
  this.buffer += chunk;
300
90
  var consumeUntil = 0;
301
- for(var index = this.readPos; index < this.buffer.length; index++){
302
- var code = this.buffer.charCodeAt(index);
303
- if (-1 === this.start) {
91
+ var buffer = this.buffer;
92
+ var start = this.start;
93
+ var nesting = this.nesting;
94
+ var inString = this.inString;
95
+ var escaped = this.escaped;
96
+ for(var index = this.readPos; index < buffer.length; index++){
97
+ var code = buffer.charCodeAt(index);
98
+ if (-1 === start) {
304
99
  if (isWhitespaceCode(code)) continue;
305
100
  if (code !== CHAR_OPEN_BRACKET && code !== CHAR_OPEN_BRACE) continue;
306
- this.start = index;
307
- this.nesting = 1;
308
- this.inString = false;
309
- this.escaped = false;
101
+ start = index;
102
+ nesting = 1;
103
+ inString = false;
104
+ escaped = false;
310
105
  continue;
311
106
  }
312
- if (this.inString) {
313
- if (this.escaped) this.escaped = false;
314
- else if (code === CHAR_BACKSLASH) this.escaped = true;
315
- else if (code === CHAR_QUOTE) this.inString = false;
107
+ if (inString) {
108
+ if (escaped) escaped = false;
109
+ else if (code === CHAR_BACKSLASH) escaped = true;
110
+ else if (code === CHAR_QUOTE) inString = false;
316
111
  continue;
317
112
  }
318
113
  if (code === CHAR_QUOTE) {
319
- this.inString = true;
114
+ inString = true;
320
115
  continue;
321
116
  }
322
117
  if (code === CHAR_OPEN_BRACKET || code === CHAR_OPEN_BRACE) {
323
- this.nesting++;
118
+ nesting++;
324
119
  continue;
325
120
  }
326
121
  if (code === CHAR_CLOSE_BRACKET || code === CHAR_CLOSE_BRACE) {
327
- this.nesting--;
328
- if (0 === this.nesting) {
329
- if (index === this.start + 1) {
330
- this.start = -1;
122
+ nesting--;
123
+ if (0 === nesting) {
124
+ if (index === start + 1) {
125
+ start = -1;
331
126
  consumeUntil = index + 1;
332
127
  continue;
333
128
  }
334
- var raw = this.buffer.slice(this.start, index + 1);
335
- this.start = -1;
129
+ var raw = buffer.slice(start, index + 1);
130
+ start = -1;
336
131
  onValue(raw);
337
132
  consumeUntil = index + 1;
338
133
  }
339
134
  }
340
135
  }
136
+ this.start = start;
137
+ this.nesting = nesting;
138
+ this.inString = inString;
139
+ this.escaped = escaped;
341
140
  if (consumeUntil > 0) {
342
141
  this._consumed = consumeUntil;
343
- this.readPos = -1 !== this.start ? this.buffer.length : this._consumed;
142
+ this.readPos = -1 !== this.start ? buffer.length : this._consumed;
344
143
  if (this._consumed > 65536) {
345
144
  if (-1 !== this.start) this.start -= this._consumed;
346
145
  this.buffer = this.buffer.slice(this._consumed);
347
146
  this.readPos = this.buffer.length;
348
147
  this._consumed = 0;
349
148
  }
350
- } else this.readPos = this.buffer.length;
149
+ } else this.readPos = buffer.length;
351
150
  },
352
151
  reset: function() {
353
152
  this.buffer = "";
@@ -375,10 +174,18 @@ function createRowStreamParser(onRow) {
375
174
  feed: function(chunk) {
376
175
  if (this.finished) return chunk;
377
176
  this.buffer += chunk;
177
+ var buffer = this.buffer;
178
+ var started = this.started;
179
+ var inString = this.inString;
180
+ var escaped = this.escaped;
181
+ var elementStart = this.elementStart;
182
+ var elementEnd = this.elementEnd;
183
+ var nesting = this.nesting;
184
+ var consumed = this._consumed;
378
185
  var index = this.readPos;
379
- while(index < this.buffer.length){
380
- var code = this.buffer.charCodeAt(index);
381
- if (!this.started) {
186
+ while(index < buffer.length){
187
+ var code = buffer.charCodeAt(index);
188
+ if (!started) {
382
189
  if (isWhitespaceCode(code)) {
383
190
  index++;
384
191
  continue;
@@ -387,74 +194,82 @@ function createRowStreamParser(onRow) {
387
194
  index++;
388
195
  continue;
389
196
  }
390
- this.started = true;
197
+ started = true;
391
198
  index++;
392
199
  continue;
393
200
  }
394
- if (this.inString) {
395
- if (this.escaped) this.escaped = false;
396
- else if (code === CHAR_BACKSLASH) this.escaped = true;
397
- else if (code === CHAR_QUOTE) this.inString = false;
201
+ if (inString) {
202
+ if (escaped) escaped = false;
203
+ else if (code === CHAR_BACKSLASH) escaped = true;
204
+ else if (code === CHAR_QUOTE) inString = false;
398
205
  index++;
399
206
  continue;
400
207
  }
401
- if (-1 === this.elementStart) {
208
+ if (-1 === elementStart) {
402
209
  if (isWhitespaceCode(code) || code === CHAR_COMMA) {
403
210
  index++;
404
211
  continue;
405
212
  }
406
213
  if (code === CHAR_CLOSE_BRACKET) {
407
214
  this.finished = true;
408
- var leftover = this.buffer.slice(index + 1);
409
- this.buffer = "";
410
215
  this.readPos = 0;
411
- return leftover;
216
+ this.buffer = "";
217
+ this.started = false;
218
+ return buffer.slice(index + 1);
412
219
  }
413
- this.elementStart = index;
414
- this.elementEnd = -1;
415
- this.nesting = code === CHAR_OPEN_BRACE || code === CHAR_OPEN_BRACKET ? 1 : 0;
416
- this.inString = code === CHAR_QUOTE;
220
+ elementStart = index;
221
+ elementEnd = -1;
222
+ nesting = code === CHAR_OPEN_BRACE || code === CHAR_OPEN_BRACKET ? 1 : 0;
223
+ inString = code === CHAR_QUOTE;
224
+ escaped = false;
417
225
  index++;
418
226
  continue;
419
227
  }
420
228
  if (code === CHAR_QUOTE) {
421
- this.inString = true;
229
+ inString = true;
422
230
  index++;
423
231
  continue;
424
232
  }
425
233
  if (code === CHAR_OPEN_BRACE || code === CHAR_OPEN_BRACKET) {
426
- this.nesting++;
234
+ nesting++;
427
235
  index++;
428
236
  continue;
429
237
  }
430
238
  if (code === CHAR_CLOSE_BRACE || code === CHAR_CLOSE_BRACKET) {
431
- this.nesting--;
432
- if (0 === this.nesting) this.elementEnd = index + 1;
239
+ nesting--;
240
+ if (0 === nesting) elementEnd = index + 1;
433
241
  }
434
- if (-1 !== this.elementEnd) {
242
+ if (-1 !== elementEnd) {
435
243
  var lookAhead = index + 1;
436
- while(lookAhead < this.buffer.length && isWhitespaceCode(this.buffer.charCodeAt(lookAhead)))lookAhead++;
437
- if (lookAhead < this.buffer.length) {
438
- var delimiter = this.buffer.charCodeAt(lookAhead);
244
+ while(lookAhead < buffer.length && isWhitespaceCode(buffer.charCodeAt(lookAhead)))lookAhead++;
245
+ if (lookAhead < buffer.length) {
246
+ var delimiter = buffer.charCodeAt(lookAhead);
439
247
  if (delimiter === CHAR_COMMA || delimiter === CHAR_CLOSE_BRACKET) {
440
- onRow(this.buffer.slice(this.elementStart, this.elementEnd));
441
- this._consumed = lookAhead + 1;
442
- this.elementStart = -1;
443
- this.elementEnd = -1;
444
- this.nesting = 0;
248
+ onRow(buffer.slice(elementStart, elementEnd));
249
+ consumed = lookAhead + 1;
250
+ elementStart = -1;
251
+ elementEnd = -1;
252
+ nesting = 0;
445
253
  if (delimiter === CHAR_CLOSE_BRACKET) {
446
254
  this.finished = true;
447
- var tail = this.buffer.slice(this._consumed);
448
255
  this.buffer = "";
256
+ this.started = false;
257
+ this.inString = false;
258
+ this.escaped = false;
259
+ this.elementStart = -1;
260
+ this.elementEnd = -1;
261
+ this.nesting = 0;
449
262
  this._consumed = 0;
450
263
  this.readPos = 0;
451
- return tail;
264
+ return buffer.slice(consumed);
452
265
  }
453
- index = this._consumed;
454
- if (this._consumed > 65536) {
455
- this.buffer = this.buffer.slice(this._consumed);
456
- index = 0;
266
+ index = consumed;
267
+ if (consumed > 65536) {
268
+ buffer = buffer.slice(consumed);
269
+ this.buffer = buffer;
457
270
  this._consumed = 0;
271
+ index = 0;
272
+ consumed = 0;
458
273
  }
459
274
  continue;
460
275
  }
@@ -462,12 +277,19 @@ function createRowStreamParser(onRow) {
462
277
  }
463
278
  index++;
464
279
  }
465
- if (this._consumed > 0) {
466
- if (-1 !== this.elementStart) {
467
- this.elementStart -= this._consumed;
468
- if (-1 !== this.elementEnd) this.elementEnd -= this._consumed;
280
+ this.started = started;
281
+ this.inString = inString;
282
+ this.escaped = escaped;
283
+ this.elementStart = elementStart;
284
+ this.elementEnd = elementEnd;
285
+ this.nesting = nesting;
286
+ this._consumed = consumed;
287
+ if (consumed > 0) {
288
+ if (-1 !== elementStart) {
289
+ this.elementStart -= consumed;
290
+ if (-1 !== elementEnd) this.elementEnd -= consumed;
469
291
  }
470
- this.buffer = this.buffer.slice(this._consumed);
292
+ this.buffer = buffer.slice(consumed);
471
293
  this._consumed = 0;
472
294
  }
473
295
  if (this.elementStart > 0) {
@@ -495,14 +317,15 @@ function createRowStreamParser(onRow) {
495
317
  var TOKEN_COLUMN = "__sqlite_executor_token__";
496
318
  var DEFAULT_BATCH_SIZE = 10;
497
319
  var DEFAULT_MAX_INFLIGHT = 50;
498
- function stream_check_private_redeclaration(obj, privateCollection) {
320
+ var INFLIGHT_COMPACT_THRESHOLD = 128;
321
+ function _check_private_redeclaration(obj, privateCollection) {
499
322
  if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
500
323
  }
501
- function stream_class_apply_descriptor_get(receiver, descriptor) {
324
+ function _class_apply_descriptor_get(receiver, descriptor) {
502
325
  if (descriptor.get) return descriptor.get.call(receiver);
503
326
  return descriptor.value;
504
327
  }
505
- function stream_class_apply_descriptor_set(receiver, descriptor, value) {
328
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
506
329
  if (descriptor.set) descriptor.set.call(receiver, value);
507
330
  else {
508
331
  if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
@@ -525,31 +348,31 @@ function _class_apply_descriptor_update(receiver, descriptor) {
525
348
  if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
526
349
  return descriptor;
527
350
  }
528
- function stream_class_call_check(instance, Constructor) {
351
+ function _class_call_check(instance, Constructor) {
529
352
  if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
530
353
  }
531
- function stream_class_extract_field_descriptor(receiver, privateMap, action) {
354
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
532
355
  if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
533
356
  return privateMap.get(receiver);
534
357
  }
535
- function stream_class_private_field_get(receiver, privateMap) {
536
- var descriptor = stream_class_extract_field_descriptor(receiver, privateMap, "get");
537
- return stream_class_apply_descriptor_get(receiver, descriptor);
358
+ function _class_private_field_get(receiver, privateMap) {
359
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
360
+ return _class_apply_descriptor_get(receiver, descriptor);
538
361
  }
539
- function stream_class_private_field_init(obj, privateMap, value) {
540
- stream_check_private_redeclaration(obj, privateMap);
362
+ function _class_private_field_init(obj, privateMap, value) {
363
+ _check_private_redeclaration(obj, privateMap);
541
364
  privateMap.set(obj, value);
542
365
  }
543
- function stream_class_private_field_set(receiver, privateMap, value) {
544
- var descriptor = stream_class_extract_field_descriptor(receiver, privateMap, "set");
545
- stream_class_apply_descriptor_set(receiver, descriptor, value);
366
+ function _class_private_field_set(receiver, privateMap, value) {
367
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
368
+ _class_apply_descriptor_set(receiver, descriptor, value);
546
369
  return value;
547
370
  }
548
371
  function _class_private_field_update(receiver, privateMap) {
549
- var descriptor = stream_class_extract_field_descriptor(receiver, privateMap, "update");
372
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "update");
550
373
  return _class_apply_descriptor_update(receiver, descriptor);
551
374
  }
552
- function stream_defineProperties(target, props) {
375
+ function _defineProperties(target, props) {
553
376
  for(var i = 0; i < props.length; i++){
554
377
  var descriptor = props[i];
555
378
  descriptor.enumerable = descriptor.enumerable || false;
@@ -558,9 +381,9 @@ function stream_defineProperties(target, props) {
558
381
  Object.defineProperty(target, descriptor.key, descriptor);
559
382
  }
560
383
  }
561
- function stream_create_class(Constructor, protoProps, staticProps) {
562
- if (protoProps) stream_defineProperties(Constructor.prototype, protoProps);
563
- if (staticProps) stream_defineProperties(Constructor, staticProps);
384
+ function _create_class(Constructor, protoProps, staticProps) {
385
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
386
+ if (staticProps) _defineProperties(Constructor, staticProps);
564
387
  return Constructor;
565
388
  }
566
389
  function _type_of(obj) {
@@ -568,7 +391,7 @@ function _type_of(obj) {
568
391
  }
569
392
  var _computedKey;
570
393
  function setupStreamParser(task) {
571
- var valueParser = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {
394
+ var pipelineOrFeed = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {
572
395
  feed: function() {}
573
396
  };
574
397
  if ("stream" !== task.kind) return null;
@@ -576,7 +399,7 @@ function setupStreamParser(task) {
576
399
  if (task.consumerError) return;
577
400
  try {
578
401
  var row = JSON.parse(rawRow);
579
- if ((void 0 === row ? "undefined" : _type_of(row)) === "object" && null !== row && TOKEN_COLUMN in row) return void valueParser.feed("[".concat(rawRow, "]"));
402
+ if ((void 0 === row ? "undefined" : _type_of(row)) === "object" && null !== row && TOKEN_COLUMN in row) return void pipelineOrFeed.feed("[".concat(rawRow, "]"));
580
403
  task.onRow(row);
581
404
  } catch (error) {
582
405
  task.consumerError = toError(error);
@@ -590,50 +413,50 @@ var _computedKey1 = _computedKey;
590
413
  var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
591
414
  "use strict";
592
415
  function AsyncRowBuffer() {
593
- stream_class_call_check(this, AsyncRowBuffer);
594
- stream_class_private_field_init(this, _buffer, {
416
+ _class_call_check(this, AsyncRowBuffer);
417
+ _class_private_field_init(this, _buffer, {
595
418
  writable: true,
596
419
  value: []
597
420
  });
598
- stream_class_private_field_init(this, _index, {
421
+ _class_private_field_init(this, _index, {
599
422
  writable: true,
600
423
  value: 0
601
424
  });
602
- stream_class_private_field_init(this, _done, {
425
+ _class_private_field_init(this, _done, {
603
426
  writable: true,
604
427
  value: false
605
428
  });
606
- stream_class_private_field_init(this, _error, {
429
+ _class_private_field_init(this, _error, {
607
430
  writable: true,
608
431
  value: null
609
432
  });
610
- stream_class_private_field_init(this, _pending, {
433
+ _class_private_field_init(this, _pending, {
611
434
  writable: true,
612
435
  value: null
613
436
  });
614
437
  }
615
- stream_create_class(AsyncRowBuffer, [
438
+ _create_class(AsyncRowBuffer, [
616
439
  {
617
440
  key: "push",
618
441
  value: function(row) {
619
- if (stream_class_private_field_get(this, _done) || stream_class_private_field_get(this, _error)) return;
620
- if (stream_class_private_field_get(this, _pending)) {
621
- var resolve = stream_class_private_field_get(this, _pending).resolve;
622
- stream_class_private_field_set(this, _pending, null);
442
+ if (_class_private_field_get(this, _done) || _class_private_field_get(this, _error)) return;
443
+ if (_class_private_field_get(this, _pending)) {
444
+ var resolve = _class_private_field_get(this, _pending).resolve;
445
+ _class_private_field_set(this, _pending, null);
623
446
  resolve({
624
447
  value: row,
625
448
  done: false
626
449
  });
627
- } else stream_class_private_field_get(this, _buffer).push(row);
450
+ } else _class_private_field_get(this, _buffer).push(row);
628
451
  }
629
452
  },
630
453
  {
631
454
  key: "end",
632
455
  value: function() {
633
- stream_class_private_field_set(this, _done, true);
634
- if (stream_class_private_field_get(this, _pending)) {
635
- var resolve = stream_class_private_field_get(this, _pending).resolve;
636
- stream_class_private_field_set(this, _pending, null);
456
+ _class_private_field_set(this, _done, true);
457
+ if (_class_private_field_get(this, _pending)) {
458
+ var resolve = _class_private_field_get(this, _pending).resolve;
459
+ _class_private_field_set(this, _pending, null);
637
460
  resolve({
638
461
  value: void 0,
639
462
  done: true
@@ -644,10 +467,10 @@ var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
644
467
  {
645
468
  key: "error",
646
469
  value: function(err) {
647
- stream_class_private_field_set(this, _error, err);
648
- if (stream_class_private_field_get(this, _pending)) {
649
- var reject = stream_class_private_field_get(this, _pending).reject;
650
- stream_class_private_field_set(this, _pending, null);
470
+ _class_private_field_set(this, _error, err);
471
+ if (_class_private_field_get(this, _pending)) {
472
+ var reject = _class_private_field_get(this, _pending).reject;
473
+ _class_private_field_set(this, _pending, null);
651
474
  reject(err);
652
475
  }
653
476
  }
@@ -656,17 +479,17 @@ var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
656
479
  key: "next",
657
480
  value: function() {
658
481
  var _this = this;
659
- if (stream_class_private_field_get(this, _index) < stream_class_private_field_get(this, _buffer).length) return Promise.resolve({
660
- value: stream_class_private_field_get(this, _buffer)[_class_private_field_update(this, _index).value++],
482
+ if (_class_private_field_get(this, _index) < _class_private_field_get(this, _buffer).length) return Promise.resolve({
483
+ value: _class_private_field_get(this, _buffer)[_class_private_field_update(this, _index).value++],
661
484
  done: false
662
485
  });
663
- if (stream_class_private_field_get(this, _done)) return Promise.resolve({
486
+ if (_class_private_field_get(this, _done)) return Promise.resolve({
664
487
  value: void 0,
665
488
  done: true
666
489
  });
667
- if (stream_class_private_field_get(this, _error)) return Promise.reject(stream_class_private_field_get(this, _error));
490
+ if (_class_private_field_get(this, _error)) return Promise.reject(_class_private_field_get(this, _error));
668
491
  return new Promise(function(resolve, reject) {
669
- stream_class_private_field_set(_this, _pending, {
492
+ _class_private_field_set(_this, _pending, {
670
493
  resolve: resolve,
671
494
  reject: reject
672
495
  });
@@ -676,12 +499,12 @@ var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
676
499
  {
677
500
  key: "return",
678
501
  value: function() {
679
- stream_class_private_field_set(this, _done, true);
680
- stream_class_private_field_set(this, _buffer, []);
681
- stream_class_private_field_set(this, _index, 0);
682
- if (stream_class_private_field_get(this, _pending)) {
683
- var resolve = stream_class_private_field_get(this, _pending).resolve;
684
- stream_class_private_field_set(this, _pending, null);
502
+ _class_private_field_set(this, _done, true);
503
+ _class_private_field_set(this, _buffer, []);
504
+ _class_private_field_set(this, _index, 0);
505
+ if (_class_private_field_get(this, _pending)) {
506
+ var resolve = _class_private_field_get(this, _pending).resolve;
507
+ _class_private_field_set(this, _pending, null);
685
508
  resolve({
686
509
  value: void 0,
687
510
  done: true
@@ -778,16 +601,19 @@ function createTransactionHandle(scopeId, executor) {
778
601
  return handle;
779
602
  }
780
603
  var external_node_child_process_namespaceObject = require("node:child_process");
604
+ var external_node_events_namespaceObject = require("node:events");
781
605
  var external_node_fs_namespaceObject = require("node:fs");
782
606
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
783
607
  var external_node_path_namespaceObject = require("node:path");
784
608
  var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
785
609
  var external_node_os_namespaceObject = require("node:os");
786
610
  var external_node_os_default = /*#__PURE__*/ __webpack_require__.n(external_node_os_namespaceObject);
787
- var isWindows = "win32" === external_node_os_default().platform();
611
+ function isWindows() {
612
+ return "win32" === external_node_os_default().platform();
613
+ }
788
614
  function isExecutable(filePath) {
789
615
  try {
790
- if (isWindows) return external_node_fs_default().statSync(filePath).isFile();
616
+ if (isWindows()) return external_node_fs_default().statSync(filePath).isFile();
791
617
  external_node_fs_default().accessSync(filePath, external_node_fs_default().constants.X_OK);
792
618
  return true;
793
619
  } catch (e) {
@@ -795,7 +621,7 @@ function isExecutable(filePath) {
795
621
  }
796
622
  }
797
623
  function getPathExts() {
798
- if (!isWindows) return [
624
+ if (!isWindows()) return [
799
625
  ""
800
626
  ];
801
627
  var ext = process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM;.PS1";
@@ -808,7 +634,7 @@ function which(command) {
808
634
  var pathExts = getPathExts();
809
635
  if (command.includes(external_node_path_default().sep)) {
810
636
  var fullPath = external_node_path_default().resolve(command);
811
- if (!isWindows) return isExecutable(fullPath) ? fullPath : null;
637
+ if (!isWindows()) return isExecutable(fullPath) ? fullPath : null;
812
638
  if (external_node_path_default().extname(fullPath)) return isExecutable(fullPath) ? fullPath : null;
813
639
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
814
640
  try {
@@ -835,7 +661,7 @@ function which(command) {
835
661
  try {
836
662
  for(var _iterator1 = pathDirs[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
837
663
  var dir = _step1.value;
838
- if (dir) if (isWindows) {
664
+ if (dir) if (isWindows()) {
839
665
  var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
840
666
  try {
841
667
  for(var _iterator2 = pathExts[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
@@ -930,6 +756,14 @@ function process_class_private_field_set(receiver, privateMap, value) {
930
756
  process_class_apply_descriptor_set(receiver, descriptor, value);
931
757
  return value;
932
758
  }
759
+ function _class_private_method_get(receiver, privateSet, fn) {
760
+ if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
761
+ return fn;
762
+ }
763
+ function _class_private_method_init(obj, privateSet) {
764
+ process_check_private_redeclaration(obj, privateSet);
765
+ privateSet.add(obj);
766
+ }
933
767
  function process_defineProperties(target, props) {
934
768
  for(var i = 0; i < props.length; i++){
935
769
  var descriptor = props[i];
@@ -1036,12 +870,14 @@ function _ts_generator(thisArg, body) {
1036
870
  }
1037
871
  }
1038
872
  var GRACEFUL_SHUTDOWN_TIMEOUT = 5000;
1039
- var _binary = /*#__PURE__*/ new WeakMap(), _database = /*#__PURE__*/ new WeakMap(), _proc = /*#__PURE__*/ new WeakMap(), _initMode = /*#__PURE__*/ new WeakMap(), _draining = /*#__PURE__*/ new WeakMap(), _onDrain = /*#__PURE__*/ new WeakMap();
873
+ var _binary = /*#__PURE__*/ new WeakMap(), _database = /*#__PURE__*/ new WeakMap(), _proc = /*#__PURE__*/ new WeakMap(), _initMode = /*#__PURE__*/ new WeakMap(), _draining = /*#__PURE__*/ new WeakMap(), _writeBuffer = /*#__PURE__*/ new WeakMap(), _drainCallbacks = /*#__PURE__*/ new WeakMap(), _onDrain = /*#__PURE__*/ new WeakMap(), _flushBuffer = /*#__PURE__*/ new WeakSet(), _notifyIfDrained = /*#__PURE__*/ new WeakSet();
1040
874
  var process_ProcessManager = /*#__PURE__*/ function() {
1041
875
  "use strict";
1042
876
  function ProcessManager() {
1043
877
  var _ref = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, binary = _ref.binary, database = _ref.database, _ref_initMode = _ref.initMode, initMode = void 0 === _ref_initMode ? "wal" : _ref_initMode, onDrain = _ref.onDrain;
1044
878
  process_class_call_check(this, ProcessManager);
879
+ _class_private_method_init(this, _flushBuffer);
880
+ _class_private_method_init(this, _notifyIfDrained);
1045
881
  process_class_private_field_init(this, _binary, {
1046
882
  writable: true,
1047
883
  value: void 0
@@ -1062,6 +898,14 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1062
898
  writable: true,
1063
899
  value: false
1064
900
  });
901
+ process_class_private_field_init(this, _writeBuffer, {
902
+ writable: true,
903
+ value: []
904
+ });
905
+ process_class_private_field_init(this, _drainCallbacks, {
906
+ writable: true,
907
+ value: []
908
+ });
1065
909
  process_class_private_field_init(this, _onDrain, {
1066
910
  writable: true,
1067
911
  value: void 0
@@ -1085,6 +929,13 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1085
929
  process_class_private_field_set(this, _onDrain, fn);
1086
930
  }
1087
931
  },
932
+ {
933
+ key: "onDrained",
934
+ value: function(callback) {
935
+ if (!process_class_private_field_get(this, _draining) && 0 === process_class_private_field_get(this, _writeBuffer).length) return void callback();
936
+ process_class_private_field_get(this, _drainCallbacks).push(callback);
937
+ }
938
+ },
1088
939
  {
1089
940
  key: "binary",
1090
941
  get: function() {
@@ -1100,9 +951,9 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1100
951
  {
1101
952
  key: "start",
1102
953
  value: function() {
1103
- var _proc_stdin, _proc_stdout, _proc_stderr;
954
+ var _proc_stdin, _proc_stdout, _proc_stderr, _proc_stdin1;
1104
955
  if (!process_class_private_field_get(this, _binary)) throw new Error("sqlite3 binary path is empty. Provide a valid --binary / binary option.");
1105
- if (!external_node_fs_default().existsSync(process_class_private_field_get(this, _binary))) throw new Error("sqlite3 binary not found: ".concat(process_class_private_field_get(this, _binary), ". Make sure sqlite3 is installed or provide a valid --binary / binary option."));
956
+ if (external_node_path_default().isAbsolute(process_class_private_field_get(this, _binary)) && !external_node_fs_default().existsSync(process_class_private_field_get(this, _binary))) throw new Error("sqlite3 binary not found: ".concat(process_class_private_field_get(this, _binary), ". Make sure sqlite3 is installed or provide a valid --binary / binary option."));
1106
957
  var args = [
1107
958
  "-json"
1108
959
  ];
@@ -1119,6 +970,7 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1119
970
  null == (_proc_stdin = proc.stdin) || _proc_stdin.setDefaultEncoding("utf-8");
1120
971
  null == (_proc_stdout = proc.stdout) || _proc_stdout.setEncoding("utf-8");
1121
972
  null == (_proc_stderr = proc.stderr) || _proc_stderr.setEncoding("utf-8");
973
+ null == (_proc_stdin1 = proc.stdin) || _proc_stdin1.on("error", function() {});
1122
974
  process_class_private_field_set(this, _proc, proc);
1123
975
  return proc;
1124
976
  }
@@ -1130,11 +982,13 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1130
982
  var _$_class_private_field_get;
1131
983
  var stream = null == (_$_class_private_field_get = process_class_private_field_get(this, _proc)) ? void 0 : _$_class_private_field_get.stdin;
1132
984
  if (!stream) return;
1133
- if (process_class_private_field_get(this, _draining)) return;
985
+ if (process_class_private_field_get(this, _draining)) return void process_class_private_field_get(this, _writeBuffer).push(data);
1134
986
  if (!stream.write(data)) {
1135
987
  process_class_private_field_set(this, _draining, true);
1136
988
  stream.once("drain", function() {
1137
989
  process_class_private_field_set(_this, _draining, false);
990
+ _class_private_method_get(_this, _flushBuffer, flushBuffer).call(_this);
991
+ _class_private_method_get(_this, _notifyIfDrained, notifyIfDrained).call(_this);
1138
992
  process_class_private_field_get(_this, _onDrain).call(_this);
1139
993
  });
1140
994
  }
@@ -1153,40 +1007,58 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1153
1007
  if (!proc) return [
1154
1008
  2
1155
1009
  ];
1010
+ if (!(process_class_private_field_get(_this, _draining) || process_class_private_field_get(_this, _writeBuffer).length > 0)) return [
1011
+ 3,
1012
+ 2
1013
+ ];
1014
+ return [
1015
+ 4,
1016
+ new Promise(function(resolve) {
1017
+ var timer = setTimeout(resolve, GRACEFUL_SHUTDOWN_TIMEOUT);
1018
+ _this.onDrained(function() {
1019
+ clearTimeout(timer);
1020
+ resolve();
1021
+ });
1022
+ })
1023
+ ];
1024
+ case 1:
1025
+ _state.sent();
1026
+ _state.label = 2;
1027
+ case 2:
1156
1028
  timer = setTimeout(function() {
1157
1029
  proc.kill();
1158
- }, GRACEFUL_SHUTDOWN_TIMEOUT);
1159
- _state.label = 1;
1160
- case 1:
1030
+ }, GRACEFUL_SHUTDOWN_TIMEOUT).unref();
1031
+ _state.label = 3;
1032
+ case 3:
1161
1033
  _state.trys.push([
1162
- 1,
1163
1034
  3,
1164
- 4,
1165
- 5
1035
+ 5,
1036
+ 6,
1037
+ 7
1166
1038
  ]);
1167
1039
  null == (_proc_stdin = proc.stdin) || _proc_stdin.write(".quit\n");
1168
1040
  return [
1169
1041
  4,
1170
1042
  (0, external_node_events_namespaceObject.once)(proc, "close")
1171
1043
  ];
1172
- case 2:
1044
+ case 4:
1173
1045
  _state.sent();
1174
1046
  return [
1175
1047
  3,
1176
- 5
1048
+ 7
1177
1049
  ];
1178
- case 3:
1050
+ case 5:
1179
1051
  _state.sent();
1180
1052
  return [
1181
1053
  3,
1182
- 5
1054
+ 7
1183
1055
  ];
1184
- case 4:
1056
+ case 6:
1185
1057
  clearTimeout(timer);
1186
1058
  return [
1187
1059
  7
1188
1060
  ];
1189
- case 5:
1061
+ case 7:
1190
1062
  return [
1191
1063
  2
1192
1064
  ];
@@ -1203,6 +1075,8 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1203
1075
  if (!proc) return null;
1204
1076
  process_class_private_field_set(this, _proc, null);
1205
1077
  process_class_private_field_set(this, _draining, false);
1078
+ process_class_private_field_set(this, _writeBuffer, []);
1079
+ process_class_private_field_set(this, _drainCallbacks, []);
1206
1080
  null == (_proc_stdout = proc.stdout) || _proc_stdout.removeAllListeners();
1207
1081
  null == (_proc_stderr = proc.stderr) || _proc_stderr.removeAllListeners();
1208
1082
  proc.removeAllListeners();
@@ -1214,6 +1088,47 @@ var process_ProcessManager = /*#__PURE__*/ function() {
1214
1088
  ]);
1215
1089
  return ProcessManager;
1216
1090
  }();
1091
+ function flushBuffer() {
1092
+ var buffer = process_class_private_field_get(this, _writeBuffer);
1093
+ process_class_private_field_set(this, _writeBuffer, []);
1094
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1095
+ try {
1096
+ for(var _iterator = buffer[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1097
+ var data = _step.value;
1098
+ this.write(data);
1099
+ }
1100
+ } catch (err) {
1101
+ _didIteratorError = true;
1102
+ _iteratorError = err;
1103
+ } finally{
1104
+ try {
1105
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
1106
+ } finally{
1107
+ if (_didIteratorError) throw _iteratorError;
1108
+ }
1109
+ }
1110
+ }
1111
+ function notifyIfDrained() {
1112
+ if (process_class_private_field_get(this, _draining)) return;
1113
+ var callbacks = process_class_private_field_get(this, _drainCallbacks);
1114
+ process_class_private_field_set(this, _drainCallbacks, []);
1115
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1116
+ try {
1117
+ for(var _iterator = callbacks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1118
+ var cb = _step.value;
1119
+ cb();
1120
+ }
1121
+ } catch (err) {
1122
+ _didIteratorError = true;
1123
+ _iteratorError = err;
1124
+ } finally{
1125
+ try {
1126
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
1127
+ } finally{
1128
+ if (_didIteratorError) throw _iteratorError;
1129
+ }
1130
+ }
1131
+ }
1217
1132
  var _counter = 0;
1218
1133
  var _PREFIX = "__executor_end__";
1219
1134
  var _PID36 = process.pid.toString(36);
@@ -1221,121 +1136,305 @@ function generateToken() {
1221
1136
  _counter = _counter + 1 >>> 0;
1222
1137
  return "".concat(_PREFIX).concat(_counter.toString(36), "_").concat(_PID36);
1223
1138
  }
1224
- function escape_type_of(obj) {
1225
- return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj;
1139
+ function lruCache_check_private_redeclaration(obj, privateCollection) {
1140
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
1226
1141
  }
1227
- function escapeValue(value) {
1228
- if ("string" == typeof value) return value.includes("'") ? "'".concat(value.replace(/'/g, "''"), "'") : "'".concat(value, "'");
1229
- if (null == value) return "NULL";
1230
- if ("number" == typeof value || (void 0 === value ? "undefined" : escape_type_of(value)) === "bigint") return String(value);
1231
- if ("boolean" == typeof value) return value ? "TRUE" : "FALSE";
1232
- if (value instanceof Date) return "'".concat(value.toISOString(), "'");
1233
- throw new TypeError("Unsupported parameter type: ".concat(void 0 === value ? "undefined" : escape_type_of(value)));
1142
+ function lruCache_class_apply_descriptor_get(receiver, descriptor) {
1143
+ if (descriptor.get) return descriptor.get.call(receiver);
1144
+ return descriptor.value;
1234
1145
  }
1235
- var _interpCache = new lruCache_LRUCache({
1236
- maxSize: 256,
1237
- maxKeyLength: 4096
1238
- });
1239
- function _parseTemplate(sql) {
1240
- var segments = [];
1241
- var segStart = 0;
1242
- var state = STATE_NORMAL;
1243
- var stateStartPos = -1;
1244
- for(var pos = 0; pos < sql.length; pos++){
1245
- var code = sql.charCodeAt(pos);
1246
- if (state === STATE_NORMAL) {
1247
- if (code === CC_SINGLE_QUOTE) {
1248
- state = STATE_SINGLE_QUOTE;
1249
- stateStartPos = pos;
1250
- continue;
1146
+ function lruCache_class_apply_descriptor_set(receiver, descriptor, value) {
1147
+ if (descriptor.set) descriptor.set.call(receiver, value);
1148
+ else {
1149
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
1150
+ descriptor.value = value;
1151
+ }
1152
+ }
1153
+ function lruCache_class_call_check(instance, Constructor) {
1154
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
1155
+ }
1156
+ function lruCache_class_extract_field_descriptor(receiver, privateMap, action) {
1157
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
1158
+ return privateMap.get(receiver);
1159
+ }
1160
+ function lruCache_class_private_field_get(receiver, privateMap) {
1161
+ var descriptor = lruCache_class_extract_field_descriptor(receiver, privateMap, "get");
1162
+ return lruCache_class_apply_descriptor_get(receiver, descriptor);
1163
+ }
1164
+ function lruCache_class_private_field_init(obj, privateMap, value) {
1165
+ lruCache_check_private_redeclaration(obj, privateMap);
1166
+ privateMap.set(obj, value);
1167
+ }
1168
+ function lruCache_class_private_field_set(receiver, privateMap, value) {
1169
+ var descriptor = lruCache_class_extract_field_descriptor(receiver, privateMap, "set");
1170
+ lruCache_class_apply_descriptor_set(receiver, descriptor, value);
1171
+ return value;
1172
+ }
1173
+ function lruCache_defineProperties(target, props) {
1174
+ for(var i = 0; i < props.length; i++){
1175
+ var descriptor = props[i];
1176
+ descriptor.enumerable = descriptor.enumerable || false;
1177
+ descriptor.configurable = true;
1178
+ if ("value" in descriptor) descriptor.writable = true;
1179
+ Object.defineProperty(target, descriptor.key, descriptor);
1180
+ }
1181
+ }
1182
+ function lruCache_create_class(Constructor, protoProps, staticProps) {
1183
+ if (protoProps) lruCache_defineProperties(Constructor.prototype, protoProps);
1184
+ if (staticProps) lruCache_defineProperties(Constructor, staticProps);
1185
+ return Constructor;
1186
+ }
1187
+ var _maxSize = /*#__PURE__*/ new WeakMap(), _maxKeyLength = /*#__PURE__*/ new WeakMap(), _maxValueLength = /*#__PURE__*/ new WeakMap(), _map = /*#__PURE__*/ new WeakMap();
1188
+ var lruCache_LRUCache = /*#__PURE__*/ function() {
1189
+ "use strict";
1190
+ function LRUCache() {
1191
+ 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;
1192
+ lruCache_class_call_check(this, LRUCache);
1193
+ lruCache_class_private_field_init(this, _maxSize, {
1194
+ writable: true,
1195
+ value: void 0
1196
+ });
1197
+ lruCache_class_private_field_init(this, _maxKeyLength, {
1198
+ writable: true,
1199
+ value: void 0
1200
+ });
1201
+ lruCache_class_private_field_init(this, _maxValueLength, {
1202
+ writable: true,
1203
+ value: void 0
1204
+ });
1205
+ lruCache_class_private_field_init(this, _map, {
1206
+ writable: true,
1207
+ value: new Map()
1208
+ });
1209
+ lruCache_class_private_field_set(this, _maxSize, Math.max(1, maxSize));
1210
+ lruCache_class_private_field_set(this, _maxKeyLength, maxKeyLength);
1211
+ lruCache_class_private_field_set(this, _maxValueLength, maxValueLength);
1212
+ }
1213
+ lruCache_create_class(LRUCache, [
1214
+ {
1215
+ key: "get",
1216
+ value: function(key) {
1217
+ if ("string" != typeof key || key.length > lruCache_class_private_field_get(this, _maxKeyLength)) return;
1218
+ var value = lruCache_class_private_field_get(this, _map).get(key);
1219
+ if (void 0 === value) return;
1220
+ lruCache_class_private_field_get(this, _map)["delete"](key);
1221
+ lruCache_class_private_field_get(this, _map).set(key, value);
1222
+ return value;
1251
1223
  }
1252
- if (code === CC_DOUBLE_QUOTE) {
1253
- state = STATE_DOUBLE_QUOTE;
1254
- stateStartPos = pos;
1255
- continue;
1224
+ },
1225
+ {
1226
+ key: "set",
1227
+ value: function(key, value) {
1228
+ if ("string" != typeof key || key.length > lruCache_class_private_field_get(this, _maxKeyLength)) return;
1229
+ if ("string" == typeof value && value.length > lruCache_class_private_field_get(this, _maxValueLength)) return;
1230
+ if (Array.isArray(value) && value.length > lruCache_class_private_field_get(this, _maxValueLength)) return;
1231
+ if (lruCache_class_private_field_get(this, _map).size >= lruCache_class_private_field_get(this, _maxSize)) {
1232
+ var firstKey = lruCache_class_private_field_get(this, _map).keys().next().value;
1233
+ lruCache_class_private_field_get(this, _map)["delete"](firstKey);
1234
+ }
1235
+ lruCache_class_private_field_get(this, _map).set(key, value);
1256
1236
  }
1257
- if (code === CC_DASH && sql.charCodeAt(pos + 1) === CC_DASH) {
1258
- state = STATE_LINE_COMMENT;
1259
- pos++;
1260
- continue;
1237
+ },
1238
+ {
1239
+ key: "size",
1240
+ get: function() {
1241
+ return lruCache_class_private_field_get(this, _map).size;
1261
1242
  }
1262
- if (code === CC_SLASH && sql.charCodeAt(pos + 1) === CC_STAR) {
1263
- state = STATE_BLOCK_COMMENT;
1264
- stateStartPos = pos;
1265
- pos++;
1266
- continue;
1243
+ },
1244
+ {
1245
+ key: "clear",
1246
+ value: function() {
1247
+ lruCache_class_private_field_get(this, _map).clear();
1267
1248
  }
1268
- if (code === CC_QUESTION) {
1269
- segments.push(sql.slice(segStart, pos));
1270
- segStart = pos + 1;
1249
+ }
1250
+ ]);
1251
+ return LRUCache;
1252
+ }();
1253
+ function escape_type_of(obj) {
1254
+ return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj;
1255
+ }
1256
+ function escapeValue(value) {
1257
+ if ("string" == typeof value) return value.includes("'") ? "'".concat(value.replace(/'/g, "''"), "'") : "'".concat(value, "'");
1258
+ if (null == value) return "NULL";
1259
+ if ("number" == typeof value || (void 0 === value ? "undefined" : escape_type_of(value)) === "bigint") return String(value);
1260
+ if ("boolean" == typeof value) return value ? "TRUE" : "FALSE";
1261
+ if (value instanceof Date) return "'".concat(value.toISOString(), "'");
1262
+ throw new TypeError("Unsupported parameter type: ".concat(void 0 === value ? "undefined" : escape_type_of(value)));
1263
+ }
1264
+ new lruCache_LRUCache({
1265
+ maxSize: 256,
1266
+ maxKeyLength: 4096
1267
+ });
1268
+ function interpolateFromTemplate(template, params) {
1269
+ var segments = template.segments, paramCount = template.paramCount;
1270
+ if (params.length < paramCount) throw new Error("Too few parameters provided");
1271
+ if (params.length > paramCount) throw new Error("Too many parameters provided");
1272
+ if (0 === paramCount) return segments[0];
1273
+ var parts = [
1274
+ segments[0]
1275
+ ];
1276
+ for(var i = 0; i < params.length; i++){
1277
+ parts.push(escapeValue(params[i]));
1278
+ parts.push(segments[i + 1]);
1279
+ }
1280
+ return parts.join("");
1281
+ }
1282
+ var constants_CC_SINGLE_QUOTE = 39;
1283
+ var constants_CC_DOUBLE_QUOTE = 34;
1284
+ var constants_CC_DASH = 45;
1285
+ var constants_CC_SLASH = 47;
1286
+ var constants_CC_STAR = 42;
1287
+ var constants_CC_NEWLINE = 10;
1288
+ var constants_CC_QUESTION = 63;
1289
+ var CC_SEMICOLON = 59;
1290
+ var CC_SPACE = 32;
1291
+ var constants_STATE_NORMAL = 0;
1292
+ var constants_STATE_SINGLE_QUOTE = 1;
1293
+ var constants_STATE_DOUBLE_QUOTE = 2;
1294
+ var constants_STATE_LINE_COMMENT = 3;
1295
+ var constants_STATE_BLOCK_COMMENT = 4;
1296
+ function _decodeU16(codes) {
1297
+ var len = codes.length;
1298
+ if (0 === len) return "";
1299
+ var batchSize = 1024;
1300
+ if (len <= batchSize) return String.fromCharCode.apply(null, codes);
1301
+ var parts = new Array(Math.ceil(len / batchSize));
1302
+ for(var i = 0; i < parts.length; i++){
1303
+ var start = i * batchSize;
1304
+ var end = Math.min(start + batchSize, len);
1305
+ parts[i] = String.fromCharCode.apply(null, codes.subarray(start, end));
1306
+ }
1307
+ return parts.join("");
1308
+ }
1309
+ var _normCache = new lruCache_LRUCache({
1310
+ maxSize: 256,
1311
+ maxKeyLength: 4096
1312
+ });
1313
+ function _normalize(sql) {
1314
+ var len = sql.length;
1315
+ var needed = len + 1;
1316
+ var outCodes = new Uint16Array(needed);
1317
+ var writePos = 0;
1318
+ var pendingSpace = false;
1319
+ var state = constants_STATE_NORMAL;
1320
+ var questionPositions = [];
1321
+ for(var i = 0; i < len; i++){
1322
+ var code = sql.charCodeAt(i);
1323
+ var nextCode = sql.charCodeAt(i + 1);
1324
+ if (state === constants_STATE_BLOCK_COMMENT) {
1325
+ if (code === constants_CC_STAR && nextCode === constants_CC_SLASH) {
1326
+ state = constants_STATE_NORMAL;
1327
+ i++;
1328
+ if (writePos > 0) pendingSpace = true;
1271
1329
  }
1272
1330
  continue;
1273
1331
  }
1274
- if (state === STATE_SINGLE_QUOTE) {
1275
- if (code === CC_SINGLE_QUOTE) {
1276
- if (sql.charCodeAt(pos + 1) === CC_SINGLE_QUOTE) {
1277
- pos++;
1278
- continue;
1279
- }
1280
- state = STATE_NORMAL;
1281
- stateStartPos = -1;
1332
+ if (state === constants_STATE_LINE_COMMENT) {
1333
+ if (code === constants_CC_NEWLINE) {
1334
+ state = constants_STATE_NORMAL;
1335
+ if (writePos > 0) pendingSpace = true;
1282
1336
  }
1283
1337
  continue;
1284
1338
  }
1285
- if (state === STATE_DOUBLE_QUOTE) {
1286
- if (code === CC_DOUBLE_QUOTE) {
1287
- if (sql.charCodeAt(pos + 1) === CC_DOUBLE_QUOTE) {
1288
- pos++;
1289
- continue;
1290
- }
1291
- state = STATE_NORMAL;
1292
- stateStartPos = -1;
1339
+ if (state === constants_STATE_NORMAL) {
1340
+ if (code === constants_CC_DASH && nextCode === constants_CC_DASH) {
1341
+ state = constants_STATE_LINE_COMMENT;
1342
+ i++;
1343
+ continue;
1344
+ }
1345
+ if (code === constants_CC_SLASH && nextCode === constants_CC_STAR) {
1346
+ state = constants_STATE_BLOCK_COMMENT;
1347
+ i++;
1348
+ continue;
1293
1349
  }
1350
+ }
1351
+ if (32 === code || 9 === code || 10 === code || 11 === code || 12 === code || 13 === code) {
1352
+ if (writePos > 0) pendingSpace = true;
1353
+ continue;
1354
+ }
1355
+ if (pendingSpace && writePos > 0) {
1356
+ outCodes[writePos++] = CC_SPACE;
1357
+ pendingSpace = false;
1358
+ }
1359
+ if (code === constants_CC_QUESTION && state === constants_STATE_NORMAL) questionPositions.push(writePos);
1360
+ outCodes[writePos++] = code;
1361
+ if (state === constants_STATE_NORMAL) {
1362
+ if (code === constants_CC_SINGLE_QUOTE) state = constants_STATE_SINGLE_QUOTE;
1363
+ else if (code === constants_CC_DOUBLE_QUOTE) state = constants_STATE_DOUBLE_QUOTE;
1294
1364
  continue;
1295
1365
  }
1296
- if (state === STATE_LINE_COMMENT) {
1297
- if (code === CC_NEWLINE) state = STATE_NORMAL;
1366
+ if (state === constants_STATE_SINGLE_QUOTE) {
1367
+ if (code === constants_CC_SINGLE_QUOTE && nextCode === constants_CC_SINGLE_QUOTE) {
1368
+ outCodes[writePos++] = nextCode;
1369
+ i++;
1370
+ continue;
1371
+ }
1372
+ if (code === constants_CC_SINGLE_QUOTE) state = constants_STATE_NORMAL;
1298
1373
  continue;
1299
1374
  }
1300
- if (state === STATE_BLOCK_COMMENT) {
1301
- if (code === CC_STAR && sql.charCodeAt(pos + 1) === CC_SLASH) {
1302
- pos++;
1303
- state = STATE_NORMAL;
1304
- stateStartPos = -1;
1375
+ if (state === constants_STATE_DOUBLE_QUOTE) {
1376
+ if (code === constants_CC_DOUBLE_QUOTE && nextCode === constants_CC_DOUBLE_QUOTE) {
1377
+ outCodes[writePos++] = nextCode;
1378
+ i++;
1379
+ continue;
1305
1380
  }
1381
+ if (code === constants_CC_DOUBLE_QUOTE) state = constants_STATE_NORMAL;
1382
+ }
1383
+ }
1384
+ var normalized;
1385
+ if (0 === writePos) normalized = ";";
1386
+ else {
1387
+ while(writePos > 0 && outCodes[writePos - 1] === CC_SEMICOLON)writePos--;
1388
+ outCodes[writePos++] = CC_SEMICOLON;
1389
+ normalized = _decodeU16(outCodes.subarray(0, writePos));
1390
+ }
1391
+ var paramCount = questionPositions.length;
1392
+ if (0 === paramCount) return {
1393
+ normalized: normalized,
1394
+ segments: [
1395
+ normalized
1396
+ ],
1397
+ paramCount: 0
1398
+ };
1399
+ var segments = [];
1400
+ var segStart = 0;
1401
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1402
+ try {
1403
+ for(var _iterator = questionPositions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1404
+ var pos = _step.value;
1405
+ segments.push(normalized.slice(segStart, pos));
1406
+ segStart = pos + 1;
1407
+ }
1408
+ } catch (err) {
1409
+ _didIteratorError = true;
1410
+ _iteratorError = err;
1411
+ } finally{
1412
+ try {
1413
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
1414
+ } finally{
1415
+ if (_didIteratorError) throw _iteratorError;
1306
1416
  }
1307
1417
  }
1308
- if (state === STATE_SINGLE_QUOTE) throw new Error("Unterminated single-quoted string starting at position ".concat(stateStartPos + 1));
1309
- if (state === STATE_DOUBLE_QUOTE) throw new Error("Unterminated double-quoted identifier/string starting at position ".concat(stateStartPos + 1));
1310
- if (state === STATE_BLOCK_COMMENT) throw new Error("Unterminated block comment starting at position ".concat(stateStartPos + 1));
1311
- segments.push(sql.slice(segStart));
1418
+ segments.push(normalized.slice(segStart));
1312
1419
  return {
1420
+ normalized: normalized,
1313
1421
  segments: segments,
1314
- paramCount: segments.length - 1
1422
+ paramCount: paramCount
1315
1423
  };
1316
1424
  }
1317
- function interpolateSQL(sql, params) {
1318
- if (!sql.includes("?")) {
1319
- if (params.length > 0) throw new Error("Too many parameters provided");
1320
- return sql;
1321
- }
1322
- var template = _interpCache.get(sql);
1323
- if (void 0 === template) {
1324
- template = _parseTemplate(sql);
1325
- _interpCache.set(sql, template);
1326
- }
1327
- var segments = template.segments, paramCount = template.paramCount;
1328
- if (params.length < paramCount) throw new Error("Too few parameters provided");
1329
- if (params.length > paramCount) throw new Error("Too many parameters provided");
1330
- if (0 === paramCount) return segments[0];
1331
- var parts = [
1332
- segments[0]
1333
- ];
1334
- for(var i = 0; i < params.length; i++){
1335
- parts.push(escapeValue(params[i]));
1336
- parts.push(segments[i + 1]);
1337
- }
1338
- return parts.join("");
1425
+ function normalizeSQL(sql) {
1426
+ var cached = _normCache.get(sql);
1427
+ if (void 0 !== cached) return cached.normalized;
1428
+ var result = _normalize(sql);
1429
+ _normCache.set(sql, result);
1430
+ return result.normalized;
1431
+ }
1432
+ function normalizeSQLTemplate(sql) {
1433
+ var cached = _normCache.get(sql);
1434
+ if (void 0 !== cached) return cached;
1435
+ var result = _normalize(sql);
1436
+ _normCache.set(sql, result);
1437
+ return result;
1339
1438
  }
1340
1439
  var READ_ONLY_KINDS = new Set([
1341
1440
  "SELECT",
@@ -1349,8 +1448,8 @@ var _classifyCache = new lruCache_LRUCache({
1349
1448
  });
1350
1449
  function classifySingle(stmt) {
1351
1450
  var trimmed = stmt.trim();
1352
- if (0 === trimmed.length) return "write";
1353
- var kind = trimmed.split(/\s+/)[0].toUpperCase();
1451
+ var firstSpace = trimmed.indexOf(" ");
1452
+ var kind = (-1 === firstSpace ? trimmed : trimmed.slice(0, firstSpace)).toUpperCase();
1354
1453
  return READ_ONLY_KINDS.has(kind) ? "read" : "write";
1355
1454
  }
1356
1455
  function classifySQL(sql) {
@@ -1361,7 +1460,10 @@ function classifySQL(sql) {
1361
1460
  if (0 === trimmed.length) return "write";
1362
1461
  var result;
1363
1462
  if (trimmed.includes(";")) {
1364
- var stmts = trimmed.split(";");
1463
+ var stmts = trimmed.split(";").filter(function(s) {
1464
+ return s.trim().length > 0;
1465
+ });
1466
+ if (0 === stmts.length) return "write";
1365
1467
  result = "read";
1366
1468
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1367
1469
  try {
@@ -1440,11 +1542,11 @@ function queue_class_private_field_update(receiver, privateMap) {
1440
1542
  var descriptor = queue_class_extract_field_descriptor(receiver, privateMap, "update");
1441
1543
  return queue_class_apply_descriptor_update(receiver, descriptor);
1442
1544
  }
1443
- function _class_private_method_get(receiver, privateSet, fn) {
1545
+ function queue_class_private_method_get(receiver, privateSet, fn) {
1444
1546
  if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
1445
1547
  return fn;
1446
1548
  }
1447
- function _class_private_method_init(obj, privateSet) {
1549
+ function queue_class_private_method_init(obj, privateSet) {
1448
1550
  queue_check_private_redeclaration(obj, privateSet);
1449
1551
  privateSet.add(obj);
1450
1552
  }
@@ -1563,8 +1665,8 @@ var queue_Queue = /*#__PURE__*/ function() {
1563
1665
  "use strict";
1564
1666
  function Queue() {
1565
1667
  queue_class_call_check(this, Queue);
1566
- _class_private_method_init(this, _grow);
1567
- _class_private_method_init(this, _shrinkIfNeeded);
1668
+ queue_class_private_method_init(this, _grow);
1669
+ queue_class_private_method_init(this, _shrinkIfNeeded);
1568
1670
  queue_class_private_field_init(this, _items, {
1569
1671
  writable: true,
1570
1672
  value: new Array(INITIAL_CAPACITY)
@@ -1590,7 +1692,7 @@ var queue_Queue = /*#__PURE__*/ function() {
1590
1692
  {
1591
1693
  key: "enqueue",
1592
1694
  value: function(value) {
1593
- if (queue_class_private_field_get(this, _size) === queue_class_private_field_get(this, _items).length) _class_private_method_get(this, _grow, grow).call(this);
1695
+ if (queue_class_private_field_get(this, _size) === queue_class_private_field_get(this, _items).length) queue_class_private_method_get(this, _grow, grow).call(this);
1594
1696
  queue_class_private_field_get(this, _items)[queue_class_private_field_get(this, _tail)] = value;
1595
1697
  queue_class_private_field_set(this, _tail, queue_class_private_field_get(this, _tail) + 1 & queue_class_private_field_get(this, _mask));
1596
1698
  queue_class_private_field_update(this, _size).value++;
@@ -1614,7 +1716,7 @@ var queue_Queue = /*#__PURE__*/ function() {
1614
1716
  queue_class_private_field_set(this, _head, 0);
1615
1717
  queue_class_private_field_set(this, _tail, 0);
1616
1718
  queue_class_private_field_set(this, _size, 0);
1617
- _class_private_method_get(this, _shrinkIfNeeded, shrinkIfNeeded).call(this);
1719
+ queue_class_private_method_get(this, _shrinkIfNeeded, shrinkIfNeeded).call(this);
1618
1720
  }
1619
1721
  },
1620
1722
  {
@@ -1775,95 +1877,81 @@ function shrinkIfNeeded() {
1775
1877
  queue_class_private_field_set(this, _mask, INITIAL_CAPACITY - 1);
1776
1878
  }
1777
1879
  }
1778
- function buildPayload(sql, token) {
1779
- var _ref = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, _ref_skipNormalize = _ref.skipNormalize, skipNormalize = void 0 === _ref_skipNormalize ? false : _ref_skipNormalize;
1780
- var normalized = skipNormalize ? sql : normalizeSQL(sql);
1781
- var suffix = normalized.endsWith(";") ? "" : ";";
1782
- return "".concat(normalized).concat(suffix, "\nSELECT '").concat(token, "' AS ").concat(TOKEN_COLUMN, ";\n");
1880
+ function _array_like_to_array(arr, len) {
1881
+ if (null == len || len > arr.length) len = arr.length;
1882
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1883
+ return arr2;
1783
1884
  }
1784
- function isTransactionControl(sql) {
1785
- var s = sql.toUpperCase();
1786
- return "BEGIN" === s || "BEGIN TRANSACTION" === s || "COMMIT" === s || "COMMIT TRANSACTION" === s || "ROLLBACK" === s || "ROLLBACK TRANSACTION" === s || s.startsWith("BEGIN ") || s.startsWith("COMMIT ") || s.startsWith("ROLLBACK ");
1885
+ function _array_without_holes(arr) {
1886
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
1787
1887
  }
1788
- function buildBatchPayload(batch) {
1789
- var useWalBatch = batch.length > 1 && batch.every(function(t) {
1790
- return "execute" === t.kind && !isTransactionControl(t.sql);
1791
- });
1792
- if (useWalBatch) {
1793
- var parts = [
1794
- "BEGIN;\n"
1795
- ];
1796
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1797
- try {
1798
- for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1799
- var task = _step.value;
1800
- parts.push(task.sql, "\n");
1801
- }
1802
- } catch (err) {
1803
- _didIteratorError = true;
1804
- _iteratorError = err;
1805
- } finally{
1806
- try {
1807
- if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
1808
- } finally{
1809
- if (_didIteratorError) throw _iteratorError;
1810
- }
1811
- }
1812
- parts.push("COMMIT;\n");
1813
- var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
1814
- try {
1815
- for(var _iterator1 = batch[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
1816
- var task1 = _step1.value;
1817
- parts.push("SELECT '".concat(task1.token, "' AS ").concat(TOKEN_COLUMN, ";\n"));
1818
- }
1819
- } catch (err) {
1820
- _didIteratorError1 = true;
1821
- _iteratorError1 = err;
1822
- } finally{
1823
- try {
1824
- if (!_iteratorNormalCompletion1 && null != _iterator1["return"]) _iterator1["return"]();
1825
- } finally{
1826
- if (_didIteratorError1) throw _iteratorError1;
1827
- }
1828
- }
1829
- return parts.join("");
1888
+ function inflightTracker_check_private_redeclaration(obj, privateCollection) {
1889
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
1890
+ }
1891
+ function inflightTracker_class_apply_descriptor_get(receiver, descriptor) {
1892
+ if (descriptor.get) return descriptor.get.call(receiver);
1893
+ return descriptor.value;
1894
+ }
1895
+ function inflightTracker_class_apply_descriptor_set(receiver, descriptor, value) {
1896
+ if (descriptor.set) descriptor.set.call(receiver, value);
1897
+ else {
1898
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
1899
+ descriptor.value = value;
1830
1900
  }
1831
- var parts1 = [];
1832
- var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
1833
- try {
1834
- for(var _iterator2 = batch[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
1835
- var task2 = _step2.value;
1836
- parts1.push(buildPayload(task2.sql, task2.token, {
1837
- skipNormalize: true
1838
- }));
1839
- }
1840
- } catch (err) {
1841
- _didIteratorError2 = true;
1842
- _iteratorError2 = err;
1843
- } finally{
1844
- try {
1845
- if (!_iteratorNormalCompletion2 && null != _iterator2["return"]) _iterator2["return"]();
1846
- } finally{
1847
- if (_didIteratorError2) throw _iteratorError2;
1848
- }
1901
+ }
1902
+ function inflightTracker_class_apply_descriptor_update(receiver, descriptor) {
1903
+ if (descriptor.set) {
1904
+ if (!descriptor.get) throw new TypeError("attempted to read set only private field");
1905
+ if (!("__destrWrapper" in descriptor)) descriptor.__destrWrapper = {
1906
+ set value (v){
1907
+ descriptor.set.call(receiver, v);
1908
+ },
1909
+ get value () {
1910
+ return descriptor.get.call(receiver);
1911
+ }
1912
+ };
1913
+ return descriptor.__destrWrapper;
1849
1914
  }
1850
- return parts1.join("");
1915
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
1916
+ return descriptor;
1851
1917
  }
1852
- var TC_FIRST_CHAR = TOKEN_COLUMN.charCodeAt(0);
1853
- function isSentinelRaw(raw, token) {
1854
- return raw.charCodeAt(3) === TC_FIRST_CHAR && raw === '[{"'.concat(TOKEN_COLUMN, '":"').concat(token, '"}]');
1918
+ function inflightTracker_class_call_check(instance, Constructor) {
1919
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
1855
1920
  }
1856
- function isSentinelRow(value, token) {
1857
- var _value_;
1858
- return Array.isArray(value) && 1 === value.length && (null == (_value_ = value[0]) ? void 0 : _value_[TOKEN_COLUMN]) === token;
1921
+ function inflightTracker_class_extract_field_descriptor(receiver, privateMap, action) {
1922
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
1923
+ return privateMap.get(receiver);
1859
1924
  }
1860
- function _array_like_to_array(arr, len) {
1861
- if (null == len || len > arr.length) len = arr.length;
1862
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1863
- return arr2;
1925
+ function inflightTracker_class_private_field_get(receiver, privateMap) {
1926
+ var descriptor = inflightTracker_class_extract_field_descriptor(receiver, privateMap, "get");
1927
+ return inflightTracker_class_apply_descriptor_get(receiver, descriptor);
1864
1928
  }
1865
- function _array_without_holes(arr) {
1866
- if (Array.isArray(arr)) return _array_like_to_array(arr);
1929
+ function inflightTracker_class_private_field_init(obj, privateMap, value) {
1930
+ inflightTracker_check_private_redeclaration(obj, privateMap);
1931
+ privateMap.set(obj, value);
1932
+ }
1933
+ function inflightTracker_class_private_field_set(receiver, privateMap, value) {
1934
+ var descriptor = inflightTracker_class_extract_field_descriptor(receiver, privateMap, "set");
1935
+ inflightTracker_class_apply_descriptor_set(receiver, descriptor, value);
1936
+ return value;
1937
+ }
1938
+ function inflightTracker_class_private_field_update(receiver, privateMap) {
1939
+ var descriptor = inflightTracker_class_extract_field_descriptor(receiver, privateMap, "update");
1940
+ return inflightTracker_class_apply_descriptor_update(receiver, descriptor);
1941
+ }
1942
+ function inflightTracker_defineProperties(target, props) {
1943
+ for(var i = 0; i < props.length; i++){
1944
+ var descriptor = props[i];
1945
+ descriptor.enumerable = descriptor.enumerable || false;
1946
+ descriptor.configurable = true;
1947
+ if ("value" in descriptor) descriptor.writable = true;
1948
+ Object.defineProperty(target, descriptor.key, descriptor);
1949
+ }
1950
+ }
1951
+ function inflightTracker_create_class(Constructor, protoProps, staticProps) {
1952
+ if (protoProps) inflightTracker_defineProperties(Constructor.prototype, protoProps);
1953
+ if (staticProps) inflightTracker_defineProperties(Constructor, staticProps);
1954
+ return Constructor;
1867
1955
  }
1868
1956
  function _iterable_to_array(iter) {
1869
1957
  if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
@@ -1882,12 +1970,94 @@ function _unsupported_iterable_to_array(o, minLen) {
1882
1970
  if ("Map" === n || "Set" === n) return Array.from(n);
1883
1971
  if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1884
1972
  }
1885
- function collectQueryRows(task, parsed) {
1886
- if (Array.isArray(parsed)) {
1887
- var _task_rows;
1888
- if (!task.rows) task.rows = [];
1889
- (_task_rows = task.rows).push.apply(_task_rows, _to_consumable_array(parsed));
1973
+ var _tasks = /*#__PURE__*/ new WeakMap(), inflightTracker_head = /*#__PURE__*/ new WeakMap();
1974
+ var inflightTracker_InflightTracker = /*#__PURE__*/ function() {
1975
+ "use strict";
1976
+ function InflightTracker() {
1977
+ inflightTracker_class_call_check(this, InflightTracker);
1978
+ inflightTracker_class_private_field_init(this, _tasks, {
1979
+ writable: true,
1980
+ value: []
1981
+ });
1982
+ inflightTracker_class_private_field_init(this, inflightTracker_head, {
1983
+ writable: true,
1984
+ value: 0
1985
+ });
1890
1986
  }
1987
+ inflightTracker_create_class(InflightTracker, [
1988
+ {
1989
+ key: "count",
1990
+ get: function() {
1991
+ return inflightTracker_class_private_field_get(this, _tasks).length - inflightTracker_class_private_field_get(this, inflightTracker_head);
1992
+ }
1993
+ },
1994
+ {
1995
+ key: "first",
1996
+ get: function() {
1997
+ return inflightTracker_class_private_field_get(this, inflightTracker_head) < inflightTracker_class_private_field_get(this, _tasks).length ? inflightTracker_class_private_field_get(this, _tasks)[inflightTracker_class_private_field_get(this, inflightTracker_head)] : null;
1998
+ }
1999
+ },
2000
+ {
2001
+ key: "push",
2002
+ value: function() {
2003
+ for(var _len = arguments.length, items = new Array(_len), _key = 0; _key < _len; _key++)items[_key] = arguments[_key];
2004
+ var _$_class_private_field_get;
2005
+ (_$_class_private_field_get = inflightTracker_class_private_field_get(this, _tasks)).push.apply(_$_class_private_field_get, _to_consumable_array(items));
2006
+ }
2007
+ },
2008
+ {
2009
+ key: "shift",
2010
+ value: function() {
2011
+ if (inflightTracker_class_private_field_get(this, _tasks).length === inflightTracker_class_private_field_get(this, inflightTracker_head)) return null;
2012
+ var task = inflightTracker_class_private_field_get(this, _tasks)[inflightTracker_class_private_field_get(this, inflightTracker_head)];
2013
+ inflightTracker_class_private_field_get(this, _tasks)[inflightTracker_class_private_field_get(this, inflightTracker_head)] = null;
2014
+ inflightTracker_class_private_field_update(this, inflightTracker_head).value++;
2015
+ if (inflightTracker_class_private_field_get(this, inflightTracker_head) >= inflightTracker_class_private_field_get(this, _tasks).length) {
2016
+ inflightTracker_class_private_field_set(this, _tasks, []);
2017
+ inflightTracker_class_private_field_set(this, inflightTracker_head, 0);
2018
+ } else if (inflightTracker_class_private_field_get(this, inflightTracker_head) > INFLIGHT_COMPACT_THRESHOLD) {
2019
+ inflightTracker_class_private_field_set(this, _tasks, inflightTracker_class_private_field_get(this, _tasks).slice(inflightTracker_class_private_field_get(this, inflightTracker_head)));
2020
+ inflightTracker_class_private_field_set(this, inflightTracker_head, 0);
2021
+ }
2022
+ return task;
2023
+ }
2024
+ },
2025
+ {
2026
+ key: "clear",
2027
+ value: function() {
2028
+ inflightTracker_class_private_field_set(this, _tasks, []);
2029
+ inflightTracker_class_private_field_set(this, inflightTracker_head, 0);
2030
+ }
2031
+ },
2032
+ {
2033
+ key: "forEach",
2034
+ value: function(fn) {
2035
+ for(var i = inflightTracker_class_private_field_get(this, inflightTracker_head); i < inflightTracker_class_private_field_get(this, _tasks).length; i++)fn(inflightTracker_class_private_field_get(this, _tasks)[i]);
2036
+ }
2037
+ },
2038
+ {
2039
+ key: "toArray",
2040
+ value: function() {
2041
+ return inflightTracker_class_private_field_get(this, _tasks).slice(inflightTracker_class_private_field_get(this, inflightTracker_head));
2042
+ }
2043
+ },
2044
+ {
2045
+ key: "_tasksLength",
2046
+ get: function() {
2047
+ return inflightTracker_class_private_field_get(this, _tasks).length;
2048
+ }
2049
+ },
2050
+ {
2051
+ key: "_head",
2052
+ get: function() {
2053
+ return inflightTracker_class_private_field_get(this, inflightTracker_head);
2054
+ }
2055
+ }
2056
+ ]);
2057
+ return InflightTracker;
2058
+ }();
2059
+ function collectQueryRows(task, parsed) {
2060
+ if (Array.isArray(parsed)) for(var i = 0; i < parsed.length; i++)task.rows.push(parsed[i]);
1891
2061
  }
1892
2062
  function processStreamRows(task, parsed) {
1893
2063
  if (!Array.isArray(parsed)) return;
@@ -1913,7 +2083,7 @@ function processStreamRows(task, parsed) {
1913
2083
  }
1914
2084
  }
1915
2085
  }
1916
- function settleTask(task, error, value, metrics) {
2086
+ function settleUtils_settleTask(task, error, value, metrics) {
1917
2087
  var _ref = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : {}, _ref_resetRowParser = _ref.resetRowParser, resetRowParser = void 0 === _ref_resetRowParser ? false : _ref_resetRowParser;
1918
2088
  if (task.settled) return;
1919
2089
  task.settled = true;
@@ -1930,11 +2100,159 @@ function settleTask(task, error, value, metrics) {
1930
2100
  null == metrics || metrics.incrementTasksSuccess(duration);
1931
2101
  task.resolve(value);
1932
2102
  }
1933
- function finalizePendingTasks(tasks, settle, pumpQueue) {
1934
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2103
+ function buildPayload(sql, token) {
2104
+ var _ref = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, _ref_skipNormalize = _ref.skipNormalize, skipNormalize = void 0 === _ref_skipNormalize ? false : _ref_skipNormalize;
2105
+ var normalized = skipNormalize ? sql : normalizeSQL(sql);
2106
+ var suffix = normalized.endsWith(";") ? "" : ";";
2107
+ return "".concat(normalized).concat(suffix, "\nSELECT '").concat(token, "' AS ").concat(TOKEN_COLUMN, ";\n");
2108
+ }
2109
+ function isTransactionControl(sql) {
2110
+ var f = sql.charCodeAt(0);
2111
+ if (66 === f || 98 === f) return "BEGIN" === sql || "BEGIN;" === sql || sql.startsWith("BEGIN ") || sql.startsWith("BEGIN;");
2112
+ if (67 === f || 99 === f) return "COMMIT" === sql || "COMMIT;" === sql || sql.startsWith("COMMIT ") || sql.startsWith("COMMIT;");
2113
+ if (82 === f || 114 === f) return "ROLLBACK" === sql || "ROLLBACK;" === sql || sql.startsWith("ROLLBACK ") || sql.startsWith("ROLLBACK;");
2114
+ return false;
2115
+ }
2116
+ function buildBatchPayload(batch) {
2117
+ var useWalBatch = batch.length > 1 && batch.every(function(t) {
2118
+ return "execute" === t.kind && !isTransactionControl(t.sql);
2119
+ });
2120
+ if (useWalBatch) {
2121
+ var parts = [
2122
+ "BEGIN;\n"
2123
+ ];
2124
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2125
+ try {
2126
+ for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2127
+ var task = _step.value;
2128
+ parts.push(task.sql, "\n");
2129
+ }
2130
+ } catch (err) {
2131
+ _didIteratorError = true;
2132
+ _iteratorError = err;
2133
+ } finally{
2134
+ try {
2135
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2136
+ } finally{
2137
+ if (_didIteratorError) throw _iteratorError;
2138
+ }
2139
+ }
2140
+ parts.push("COMMIT;\n");
2141
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
2142
+ try {
2143
+ for(var _iterator1 = batch[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2144
+ var task1 = _step1.value;
2145
+ parts.push("SELECT '".concat(task1.token, "' AS ").concat(TOKEN_COLUMN, ";\n"));
2146
+ }
2147
+ } catch (err) {
2148
+ _didIteratorError1 = true;
2149
+ _iteratorError1 = err;
2150
+ } finally{
2151
+ try {
2152
+ if (!_iteratorNormalCompletion1 && null != _iterator1["return"]) _iterator1["return"]();
2153
+ } finally{
2154
+ if (_didIteratorError1) throw _iteratorError1;
2155
+ }
2156
+ }
2157
+ return parts.join("");
2158
+ }
2159
+ var parts1 = [];
2160
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
1935
2161
  try {
1936
- for(var _iterator = tasks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1937
- var task = _step.value;
2162
+ for(var _iterator2 = batch[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
2163
+ var task2 = _step2.value;
2164
+ parts1.push(buildPayload(task2.sql, task2.token, {
2165
+ skipNormalize: true
2166
+ }));
2167
+ }
2168
+ } catch (err) {
2169
+ _didIteratorError2 = true;
2170
+ _iteratorError2 = err;
2171
+ } finally{
2172
+ try {
2173
+ if (!_iteratorNormalCompletion2 && null != _iterator2["return"]) _iterator2["return"]();
2174
+ } finally{
2175
+ if (_didIteratorError2) throw _iteratorError2;
2176
+ }
2177
+ }
2178
+ return parts1.join("");
2179
+ }
2180
+ var TC_FIRST_CHAR = TOKEN_COLUMN.charCodeAt(0);
2181
+ function buildSentinelStr(token) {
2182
+ return '[{"'.concat(TOKEN_COLUMN, '":"').concat(token, '"}]');
2183
+ }
2184
+ function isSentinelRaw(raw, token) {
2185
+ return raw.charCodeAt(3) === TC_FIRST_CHAR && raw === buildSentinelStr(token);
2186
+ }
2187
+ function isSentinelRow(value, token) {
2188
+ var _value_;
2189
+ return Array.isArray(value) && 1 === value.length && (null == (_value_ = value[0]) ? void 0 : _value_[TOKEN_COLUMN]) === token;
2190
+ }
2191
+ function pipelineUtils_array_like_to_array(arr, len) {
2192
+ if (null == len || len > arr.length) len = arr.length;
2193
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
2194
+ return arr2;
2195
+ }
2196
+ function pipelineUtils_array_without_holes(arr) {
2197
+ if (Array.isArray(arr)) return pipelineUtils_array_like_to_array(arr);
2198
+ }
2199
+ function pipelineUtils_iterable_to_array(iter) {
2200
+ if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
2201
+ }
2202
+ function pipelineUtils_non_iterable_spread() {
2203
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2204
+ }
2205
+ function pipelineUtils_to_consumable_array(arr) {
2206
+ return pipelineUtils_array_without_holes(arr) || pipelineUtils_iterable_to_array(arr) || pipelineUtils_unsupported_iterable_to_array(arr) || pipelineUtils_non_iterable_spread();
2207
+ }
2208
+ function pipelineUtils_unsupported_iterable_to_array(o, minLen) {
2209
+ if (!o) return;
2210
+ if ("string" == typeof o) return pipelineUtils_array_like_to_array(o, minLen);
2211
+ var n = Object.prototype.toString.call(o).slice(8, -1);
2212
+ if ("Object" === n && o.constructor) n = o.constructor.name;
2213
+ if ("Map" === n || "Set" === n) return Array.from(n);
2214
+ if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return pipelineUtils_array_like_to_array(o, minLen);
2215
+ }
2216
+ function finalizePendingTasks(tasks, settle, pumpQueue, pendingStderr, inflight) {
2217
+ var hasStderrBuffer = pendingStderr && pendingStderr.length > 0;
2218
+ if (hasStderrBuffer) {
2219
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2220
+ try {
2221
+ for(var _iterator = pendingStderr[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2222
+ var chunk = _step.value;
2223
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
2224
+ try {
2225
+ for(var _iterator1 = tasks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2226
+ var t = _step1.value;
2227
+ if ("query" === t.kind && 0 === t.rows.length) t.stderrText += chunk;
2228
+ }
2229
+ } catch (err) {
2230
+ _didIteratorError1 = true;
2231
+ _iteratorError1 = err;
2232
+ } finally{
2233
+ try {
2234
+ if (!_iteratorNormalCompletion1 && null != _iterator1["return"]) _iterator1["return"]();
2235
+ } finally{
2236
+ if (_didIteratorError1) throw _iteratorError1;
2237
+ }
2238
+ }
2239
+ }
2240
+ } catch (err) {
2241
+ _didIteratorError = true;
2242
+ _iteratorError = err;
2243
+ } finally{
2244
+ try {
2245
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2246
+ } finally{
2247
+ if (_didIteratorError) throw _iteratorError;
2248
+ }
2249
+ }
2250
+ if (!inflight || 0 === inflight.count) pendingStderr.length = 0;
2251
+ }
2252
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
2253
+ try {
2254
+ for(var _iterator2 = tasks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
2255
+ var task = _step2.value;
1938
2256
  if (task.stderrText) {
1939
2257
  settle(task, new Error(task.stderrText.trim()), void 0);
1940
2258
  continue;
@@ -1950,13 +2268,13 @@ function finalizePendingTasks(tasks, settle, pumpQueue) {
1950
2268
  settle(task, null, void 0);
1951
2269
  }
1952
2270
  } catch (err) {
1953
- _didIteratorError = true;
1954
- _iteratorError = err;
2271
+ _didIteratorError2 = true;
2272
+ _iteratorError2 = err;
1955
2273
  } finally{
1956
2274
  try {
1957
- if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2275
+ if (!_iteratorNormalCompletion2 && null != _iterator2["return"]) _iterator2["return"]();
1958
2276
  } finally{
1959
- if (_didIteratorError) throw _iteratorError;
2277
+ if (_didIteratorError2) throw _iteratorError2;
1960
2278
  }
1961
2279
  }
1962
2280
  tasks.clear();
@@ -1968,13 +2286,292 @@ function prepareTaskTimeout(task, metrics) {
1968
2286
  null == metrics || metrics.incrementTasksTimeout();
1969
2287
  return createTimeoutError(task.timeout, task.sql);
1970
2288
  }
1971
- function taskWorker_array_like_to_array(arr, len) {
1972
- if (null == len || len > arr.length) len = arr.length;
1973
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1974
- return arr2;
2289
+ function createSweeper(param) {
2290
+ var inflight = param.inflight, sweepIntervalMs = param.sweepIntervalMs, handleTaskTimeout = param.handleTaskTimeout;
2291
+ var sweepTimer = null;
2292
+ var schedule = function() {
2293
+ if (sweepTimer) return;
2294
+ sweepTimer = setTimeout(function() {
2295
+ sweepTimer = null;
2296
+ var now = performance.now();
2297
+ inflight.forEach(function(task) {
2298
+ if (now - task.startTime > task.timeout) handleTaskTimeout(task);
2299
+ });
2300
+ if (inflight.count > 0) schedule();
2301
+ }, sweepIntervalMs).unref();
2302
+ };
2303
+ var clear = function() {
2304
+ clearTimeout(sweepTimer);
2305
+ sweepTimer = null;
2306
+ };
2307
+ return {
2308
+ schedule: schedule,
2309
+ clear: clear,
2310
+ getSweepTimer: function() {
2311
+ return sweepTimer;
2312
+ }
2313
+ };
2314
+ }
2315
+ function createFinalizeScheduler(param) {
2316
+ var pendingFinalizeTasks = param.pendingFinalizeTasks, settle = param.settleTask, pumpQueue = param.pumpQueue, pendingStderr = param.pendingStderr, inflight = param.inflight;
2317
+ var scheduled = false;
2318
+ var immediate = null;
2319
+ var cancelled = false;
2320
+ var cancel = function() {
2321
+ cancelled = true;
2322
+ if (immediate) {
2323
+ clearImmediate(immediate);
2324
+ immediate = null;
2325
+ }
2326
+ };
2327
+ var check = function() {
2328
+ if (cancelled) return;
2329
+ if (scheduled) return;
2330
+ if (0 === pendingFinalizeTasks.size) return;
2331
+ scheduled = true;
2332
+ immediate = setImmediate(function() {
2333
+ immediate = null;
2334
+ if (cancelled) return;
2335
+ finalizePendingTasks(pendingFinalizeTasks, settle, pumpQueue, pendingStderr, inflight);
2336
+ scheduled = false;
2337
+ });
2338
+ };
2339
+ check.cancel = cancel;
2340
+ return check;
2341
+ }
2342
+ function handleParsedValue(raw, inflight, param) {
2343
+ var afterSentinel = param.afterSentinel, rejectAll = param.rejectAll;
2344
+ var task = inflight.first;
2345
+ if (!task) return;
2346
+ if (isSentinelRaw(raw, task.token)) {
2347
+ inflight.shift();
2348
+ afterSentinel(task);
2349
+ return;
2350
+ }
2351
+ if ("[]" === raw) return;
2352
+ var parsed;
2353
+ try {
2354
+ parsed = JSON.parse(raw);
2355
+ } catch (error) {
2356
+ rejectAll(new Error("Invalid JSON from sqlite3: ".concat(toError(error).message)));
2357
+ return;
2358
+ }
2359
+ if (isSentinelRow(parsed, task.token)) {
2360
+ inflight.shift();
2361
+ afterSentinel(task);
2362
+ return;
2363
+ }
2364
+ if (task.timedout) return;
2365
+ if ("query" === task.kind) return void collectQueryRows(task, parsed);
2366
+ if ("stream" === task.kind) processStreamRows(task, parsed);
1975
2367
  }
1976
- function taskWorker_array_without_holes(arr) {
1977
- if (Array.isArray(arr)) return taskWorker_array_like_to_array(arr);
2368
+ function createPumpQueue(param) {
2369
+ var queue = param.queue, inflight = param.inflight, processManager = param.processManager, sweeper = param.sweeper, batchSize = param.batchSize, maxInflight = param.maxInflight;
2370
+ var nextBatchId = 1;
2371
+ return function pump() {
2372
+ var _inflight;
2373
+ if (processManager.draining) return void processManager.onDrained(function() {
2374
+ return pump();
2375
+ });
2376
+ if (inflight.count >= maxInflight) return;
2377
+ var batch = [];
2378
+ while(batch.length < batchSize && !queue.isEmpty() && inflight.count + batch.length < maxInflight){
2379
+ var task = queue.peek();
2380
+ if ("stream" === task.kind && (batch.length > 0 || inflight.count > 0)) break;
2381
+ queue.dequeue();
2382
+ batch.push(task);
2383
+ }
2384
+ if (0 === batch.length) return;
2385
+ var now = performance.now();
2386
+ var payload = buildBatchPayload(batch);
2387
+ var batchId = nextBatchId++;
2388
+ var useWalBatch = payload.startsWith("BEGIN;");
2389
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2390
+ try {
2391
+ for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2392
+ var task1 = _step.value;
2393
+ task1.startTime = now;
2394
+ task1.batchId = batchId;
2395
+ task1.walBatch = useWalBatch;
2396
+ }
2397
+ } catch (err) {
2398
+ _didIteratorError = true;
2399
+ _iteratorError = err;
2400
+ } finally{
2401
+ try {
2402
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2403
+ } finally{
2404
+ if (_didIteratorError) throw _iteratorError;
2405
+ }
2406
+ }
2407
+ (_inflight = inflight).push.apply(_inflight, pipelineUtils_to_consumable_array(batch));
2408
+ sweeper.schedule();
2409
+ processManager.write(payload);
2410
+ };
2411
+ }
2412
+ function handleSentinelTask(task, param) {
2413
+ var settleTask = param.settleTask, pendingFinalizeTasks = param.pendingFinalizeTasks, scheduleFinalizeCheck = param.scheduleFinalizeCheck, pumpQueue = param.pumpQueue;
2414
+ if (task.timedout) return void pumpQueue();
2415
+ if (task.consumerError) {
2416
+ settleTask(task, task.consumerError, void 0);
2417
+ pumpQueue();
2418
+ return;
2419
+ }
2420
+ pendingFinalizeTasks.add(task);
2421
+ scheduleFinalizeCheck();
2422
+ pumpQueue();
2423
+ }
2424
+ function handleStderrChunk(chunk, param) {
2425
+ var inflight = param.inflight, pendingFinalizeTasks = param.pendingFinalizeTasks, logger = param.logger, pendingStderr = param.pendingStderr;
2426
+ var inflightFirst = inflight.first;
2427
+ var firstPending = pendingFinalizeTasks.values().next().value;
2428
+ var zeroRowMatch = false;
2429
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2430
+ try {
2431
+ for(var _iterator = pendingFinalizeTasks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2432
+ var t = _step.value;
2433
+ if ("query" === t.kind && 0 === t.rows.length) {
2434
+ t.stderrText += chunk;
2435
+ zeroRowMatch = true;
2436
+ }
2437
+ }
2438
+ } catch (err) {
2439
+ _didIteratorError = true;
2440
+ _iteratorError = err;
2441
+ } finally{
2442
+ try {
2443
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2444
+ } finally{
2445
+ if (_didIteratorError) throw _iteratorError;
2446
+ }
2447
+ }
2448
+ if (zeroRowMatch) return;
2449
+ var task = null != inflightFirst ? inflightFirst : firstPending;
2450
+ if (!task) {
2451
+ var _logger_error;
2452
+ null == logger || null == (_logger_error = logger.error) || _logger_error.call(logger, chunk.trim());
2453
+ return;
2454
+ }
2455
+ if (null == task.batchId) {
2456
+ task.stderrText += chunk;
2457
+ return;
2458
+ }
2459
+ if (task.walBatch) {
2460
+ task.stderrText += chunk;
2461
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
2462
+ try {
2463
+ for(var _iterator1 = pendingFinalizeTasks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2464
+ var t1 = _step1.value;
2465
+ if (t1 !== task) t1.stderrText += chunk;
2466
+ }
2467
+ } catch (err) {
2468
+ _didIteratorError1 = true;
2469
+ _iteratorError1 = err;
2470
+ } finally{
2471
+ try {
2472
+ if (!_iteratorNormalCompletion1 && null != _iterator1["return"]) _iterator1["return"]();
2473
+ } finally{
2474
+ if (_didIteratorError1) throw _iteratorError1;
2475
+ }
2476
+ }
2477
+ inflight.forEach(function(t) {
2478
+ if (t !== task) t.stderrText += chunk;
2479
+ });
2480
+ return;
2481
+ }
2482
+ if (task === inflightFirst) {
2483
+ if (inflight.count > 1) null == pendingStderr || pendingStderr.push(chunk);
2484
+ else if (pendingFinalizeTasks.size > 0) {
2485
+ var hasZeroRowQuery = false;
2486
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
2487
+ try {
2488
+ for(var _iterator2 = pendingFinalizeTasks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
2489
+ var t2 = _step2.value;
2490
+ if ("query" === t2.kind && 0 === t2.rows.length) {
2491
+ hasZeroRowQuery = true;
2492
+ break;
2493
+ }
2494
+ }
2495
+ } catch (err) {
2496
+ _didIteratorError2 = true;
2497
+ _iteratorError2 = err;
2498
+ } finally{
2499
+ try {
2500
+ if (!_iteratorNormalCompletion2 && null != _iterator2["return"]) _iterator2["return"]();
2501
+ } finally{
2502
+ if (_didIteratorError2) throw _iteratorError2;
2503
+ }
2504
+ }
2505
+ if (hasZeroRowQuery) null == pendingStderr || pendingStderr.push(chunk);
2506
+ else if ("query" === task.kind && task.rows.length > 0) {
2507
+ var _logger_error1;
2508
+ null == logger || null == (_logger_error1 = logger.error) || _logger_error1.call(logger, chunk.trim());
2509
+ } else task.stderrText += chunk;
2510
+ } else if ("query" === task.kind && task.rows.length > 0) {
2511
+ var _logger_error2;
2512
+ null == logger || null == (_logger_error2 = logger.error) || _logger_error2.call(logger, chunk.trim());
2513
+ } else task.stderrText += chunk;
2514
+ return;
2515
+ }
2516
+ var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = void 0;
2517
+ try {
2518
+ for(var _iterator3 = pendingFinalizeTasks[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true){
2519
+ var t3 = _step3.value;
2520
+ t3.stderrText += chunk;
2521
+ }
2522
+ } catch (err) {
2523
+ _didIteratorError3 = true;
2524
+ _iteratorError3 = err;
2525
+ } finally{
2526
+ try {
2527
+ if (!_iteratorNormalCompletion3 && null != _iterator3["return"]) _iterator3["return"]();
2528
+ } finally{
2529
+ if (_didIteratorError3) throw _iteratorError3;
2530
+ }
2531
+ }
2532
+ }
2533
+ function rejectAllTasks(param) {
2534
+ var inflight = param.inflight, queue = param.queue, pendingFinalizeTasks = param.pendingFinalizeTasks, settleTask = param.settleTask, error = param.error;
2535
+ var all = inflight.toArray();
2536
+ inflight.clear();
2537
+ var queued = queue.dequeue();
2538
+ while(queued){
2539
+ settleTask(queued, error, void 0);
2540
+ queued = queue.dequeue();
2541
+ }
2542
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2543
+ try {
2544
+ for(var _iterator = all[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2545
+ var task = _step.value;
2546
+ settleTask(task, error, void 0);
2547
+ }
2548
+ } catch (err) {
2549
+ _didIteratorError = true;
2550
+ _iteratorError = err;
2551
+ } finally{
2552
+ try {
2553
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2554
+ } finally{
2555
+ if (_didIteratorError) throw _iteratorError;
2556
+ }
2557
+ }
2558
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
2559
+ try {
2560
+ for(var _iterator1 = pendingFinalizeTasks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2561
+ var task1 = _step1.value;
2562
+ settleTask(task1, error, void 0);
2563
+ }
2564
+ } catch (err) {
2565
+ _didIteratorError1 = true;
2566
+ _iteratorError1 = err;
2567
+ } finally{
2568
+ try {
2569
+ if (!_iteratorNormalCompletion1 && null != _iterator1["return"]) _iterator1["return"]();
2570
+ } finally{
2571
+ if (_didIteratorError1) throw _iteratorError1;
2572
+ }
2573
+ }
2574
+ pendingFinalizeTasks.clear();
1978
2575
  }
1979
2576
  function taskWorker_check_private_redeclaration(obj, privateCollection) {
1980
2577
  if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -2027,41 +2624,22 @@ function taskWorker_defineProperties(target, props) {
2027
2624
  Object.defineProperty(target, descriptor.key, descriptor);
2028
2625
  }
2029
2626
  }
2030
- function taskWorker_create_class(Constructor, protoProps, staticProps) {
2031
- if (protoProps) taskWorker_defineProperties(Constructor.prototype, protoProps);
2032
- if (staticProps) taskWorker_defineProperties(Constructor, staticProps);
2033
- return Constructor;
2034
- }
2035
- function taskWorker_iterable_to_array(iter) {
2036
- if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
2037
- }
2038
- function taskWorker_non_iterable_spread() {
2039
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2040
- }
2041
- function taskWorker_to_consumable_array(arr) {
2042
- return taskWorker_array_without_holes(arr) || taskWorker_iterable_to_array(arr) || taskWorker_unsupported_iterable_to_array(arr) || taskWorker_non_iterable_spread();
2043
- }
2044
- function taskWorker_unsupported_iterable_to_array(o, minLen) {
2045
- if (!o) return;
2046
- if ("string" == typeof o) return taskWorker_array_like_to_array(o, minLen);
2047
- var n = Object.prototype.toString.call(o).slice(8, -1);
2048
- if ("Object" === n && o.constructor) n = o.constructor.name;
2049
- if ("Map" === n || "Set" === n) return Array.from(n);
2050
- if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return taskWorker_array_like_to_array(o, minLen);
2051
- }
2052
- var _processManager = /*#__PURE__*/ new WeakMap(), _pendingQueue = /*#__PURE__*/ new WeakMap(), _inflightTasks = /*#__PURE__*/ new WeakMap(), _pendingFinalizeTasks = /*#__PURE__*/ new WeakMap(), _scheduledFinalize = /*#__PURE__*/ new WeakMap(), _valueParser = /*#__PURE__*/ new WeakMap(), _statementTimeout = /*#__PURE__*/ new WeakMap(), _logger = /*#__PURE__*/ new WeakMap(), _name = /*#__PURE__*/ new WeakMap(), _batchSize = /*#__PURE__*/ new WeakMap(), _maxInflight = /*#__PURE__*/ new WeakMap(), _metrics = /*#__PURE__*/ new WeakMap(), _startProcess = /*#__PURE__*/ new WeakSet(), _pumpQueue = /*#__PURE__*/ new WeakSet(), _handleParsedValue = /*#__PURE__*/ new WeakSet(), _scheduleFinalizeCheck = /*#__PURE__*/ new WeakSet(), _handleStderrChunk = /*#__PURE__*/ new WeakSet(), _handleTaskTimeout = /*#__PURE__*/ new WeakSet(), _settleTask = /*#__PURE__*/ new WeakSet(), _rejectAll = /*#__PURE__*/ new WeakSet();
2627
+ function taskWorker_create_class(Constructor, protoProps, staticProps) {
2628
+ if (protoProps) taskWorker_defineProperties(Constructor.prototype, protoProps);
2629
+ if (staticProps) taskWorker_defineProperties(Constructor, staticProps);
2630
+ return Constructor;
2631
+ }
2632
+ var _processManager = /*#__PURE__*/ new WeakMap(), _pendingQueue = /*#__PURE__*/ new WeakMap(), taskWorker_inflight = /*#__PURE__*/ new WeakMap(), _pendingFinalizeTasks = /*#__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(), _sweeper = /*#__PURE__*/ new WeakMap(), _scheduleFinalizeCheck = /*#__PURE__*/ new WeakMap(), _pump = /*#__PURE__*/ new WeakMap(), _pendingStderr = /*#__PURE__*/ new WeakMap(), _startProcess = /*#__PURE__*/ new WeakSet(), _pumpQueue = /*#__PURE__*/ new WeakSet(), _afterSentinel = /*#__PURE__*/ new WeakSet(), _handleStderrChunk = /*#__PURE__*/ new WeakSet(), _settleTask = /*#__PURE__*/ new WeakSet(), _rejectAll = /*#__PURE__*/ new WeakSet();
2053
2633
  var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2054
2634
  "use strict";
2055
2635
  function TaskWorker(param) {
2056
2636
  var _this = this;
2057
- var binary = param.binary, database = param.database, statementTimeout = param.statementTimeout, logger = param.logger, name = param.name, initMode = param.initMode, _param_batchSize = param.batchSize, batchSize = void 0 === _param_batchSize ? DEFAULT_BATCH_SIZE : _param_batchSize, _param_maxInflight = param.maxInflight, maxInflight = void 0 === _param_maxInflight ? DEFAULT_MAX_INFLIGHT : _param_maxInflight, metrics = param.metrics;
2637
+ var binary = param.binary, database = param.database, statementTimeout = param.statementTimeout, logger = param.logger, name = param.name, initMode = param.initMode, _param_batchSize = param.batchSize, batchSize = void 0 === _param_batchSize ? DEFAULT_BATCH_SIZE : _param_batchSize, _param_maxInflight = param.maxInflight, maxInflight = void 0 === _param_maxInflight ? DEFAULT_MAX_INFLIGHT : _param_maxInflight, metrics = param.metrics, _param_sweepInterval = param.sweepInterval, sweepInterval = void 0 === _param_sweepInterval ? 100 : _param_sweepInterval;
2058
2638
  taskWorker_class_call_check(this, TaskWorker);
2059
2639
  taskWorker_class_private_method_init(this, _startProcess);
2060
2640
  taskWorker_class_private_method_init(this, _pumpQueue);
2061
- taskWorker_class_private_method_init(this, _handleParsedValue);
2062
- taskWorker_class_private_method_init(this, _scheduleFinalizeCheck);
2641
+ taskWorker_class_private_method_init(this, _afterSentinel);
2063
2642
  taskWorker_class_private_method_init(this, _handleStderrChunk);
2064
- taskWorker_class_private_method_init(this, _handleTaskTimeout);
2065
2643
  taskWorker_class_private_method_init(this, _settleTask);
2066
2644
  taskWorker_class_private_method_init(this, _rejectAll);
2067
2645
  taskWorker_class_private_field_init(this, _processManager, {
@@ -2072,18 +2650,14 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2072
2650
  writable: true,
2073
2651
  value: new queue_Queue()
2074
2652
  });
2075
- taskWorker_class_private_field_init(this, _inflightTasks, {
2653
+ taskWorker_class_private_field_init(this, taskWorker_inflight, {
2076
2654
  writable: true,
2077
- value: []
2655
+ value: new inflightTracker_InflightTracker()
2078
2656
  });
2079
2657
  taskWorker_class_private_field_init(this, _pendingFinalizeTasks, {
2080
2658
  writable: true,
2081
2659
  value: new Set()
2082
2660
  });
2083
- taskWorker_class_private_field_init(this, _scheduledFinalize, {
2084
- writable: true,
2085
- value: false
2086
- });
2087
2661
  taskWorker_class_private_field_init(this, _valueParser, {
2088
2662
  writable: true,
2089
2663
  value: void 0
@@ -2112,6 +2686,22 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2112
2686
  writable: true,
2113
2687
  value: void 0
2114
2688
  });
2689
+ taskWorker_class_private_field_init(this, _sweeper, {
2690
+ writable: true,
2691
+ value: void 0
2692
+ });
2693
+ taskWorker_class_private_field_init(this, _scheduleFinalizeCheck, {
2694
+ writable: true,
2695
+ value: void 0
2696
+ });
2697
+ taskWorker_class_private_field_init(this, _pump, {
2698
+ writable: true,
2699
+ value: void 0
2700
+ });
2701
+ taskWorker_class_private_field_init(this, _pendingStderr, {
2702
+ writable: true,
2703
+ value: []
2704
+ });
2115
2705
  taskWorker_class_private_field_set(this, _name, null != name ? name : "worker");
2116
2706
  taskWorker_class_private_field_set(this, _statementTimeout, statementTimeout);
2117
2707
  taskWorker_class_private_field_set(this, _logger, logger);
@@ -2121,13 +2711,47 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2121
2711
  taskWorker_class_private_field_set(this, _processManager, new process_ProcessManager({
2122
2712
  binary: binary,
2123
2713
  database: database,
2124
- initMode: initMode,
2125
- onDrain: function() {
2126
- return taskWorker_class_private_method_get(_this, _pumpQueue, taskWorker_pumpQueue).call(_this);
2714
+ initMode: initMode
2715
+ }));
2716
+ taskWorker_class_private_field_get(this, _processManager).setOnDrainCallback(function() {
2717
+ return taskWorker_class_private_method_get(_this, _pumpQueue, taskWorker_pumpQueue).call(_this);
2718
+ });
2719
+ taskWorker_class_private_field_set(this, _sweeper, createSweeper({
2720
+ inflight: taskWorker_class_private_field_get(this, taskWorker_inflight),
2721
+ sweepIntervalMs: sweepInterval,
2722
+ handleTaskTimeout: function(task) {
2723
+ var error = prepareTaskTimeout(task, taskWorker_class_private_field_get(_this, _metrics));
2724
+ if (error) taskWorker_class_private_method_get(_this, _settleTask, settleTask1).call(_this, task, error, void 0);
2127
2725
  }
2128
2726
  }));
2727
+ taskWorker_class_private_field_set(this, _pump, createPumpQueue({
2728
+ queue: taskWorker_class_private_field_get(this, _pendingQueue),
2729
+ inflight: taskWorker_class_private_field_get(this, taskWorker_inflight),
2730
+ processManager: taskWorker_class_private_field_get(this, _processManager),
2731
+ sweeper: taskWorker_class_private_field_get(this, _sweeper),
2732
+ batchSize: taskWorker_class_private_field_get(this, _batchSize),
2733
+ maxInflight: taskWorker_class_private_field_get(this, _maxInflight)
2734
+ }));
2735
+ taskWorker_class_private_field_set(this, _scheduleFinalizeCheck, createFinalizeScheduler({
2736
+ pendingFinalizeTasks: taskWorker_class_private_field_get(this, _pendingFinalizeTasks),
2737
+ settleTask: function(t, e, v1) {
2738
+ return taskWorker_class_private_method_get(_this, _settleTask, settleTask1).call(_this, t, e, v1);
2739
+ },
2740
+ pumpQueue: function() {
2741
+ return taskWorker_class_private_method_get(_this, _pumpQueue, taskWorker_pumpQueue).call(_this);
2742
+ },
2743
+ pendingStderr: taskWorker_class_private_field_get(this, _pendingStderr),
2744
+ inflight: taskWorker_class_private_field_get(this, taskWorker_inflight)
2745
+ }));
2129
2746
  taskWorker_class_private_field_set(this, _valueParser, createJsonValueParser(function(raw) {
2130
- return taskWorker_class_private_method_get(_this, _handleParsedValue, handleParsedValue).call(_this, raw);
2747
+ handleParsedValue(raw, taskWorker_class_private_field_get(_this, taskWorker_inflight), {
2748
+ afterSentinel: function(task) {
2749
+ return taskWorker_class_private_method_get(_this, _afterSentinel, taskWorker_afterSentinel).call(_this, task);
2750
+ },
2751
+ rejectAll: function(error) {
2752
+ return taskWorker_class_private_method_get(_this, _rejectAll, taskWorker_rejectAll).call(_this, error);
2753
+ }
2754
+ });
2131
2755
  }));
2132
2756
  taskWorker_class_private_method_get(this, _startProcess, startProcess).call(this);
2133
2757
  }
@@ -2141,13 +2765,13 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2141
2765
  {
2142
2766
  key: "idle",
2143
2767
  get: function() {
2144
- return 0 === taskWorker_class_private_field_get(this, _inflightTasks).length && taskWorker_class_private_field_get(this, _pendingQueue).isEmpty() && 0 === taskWorker_class_private_field_get(this, _pendingFinalizeTasks).size;
2768
+ return 0 === taskWorker_class_private_field_get(this, taskWorker_inflight).count && taskWorker_class_private_field_get(this, _pendingQueue).isEmpty() && 0 === taskWorker_class_private_field_get(this, _pendingFinalizeTasks).size;
2145
2769
  }
2146
2770
  },
2147
2771
  {
2148
2772
  key: "pendingStatements",
2149
2773
  get: function() {
2150
- return taskWorker_class_private_field_get(this, _pendingQueue).size + taskWorker_class_private_field_get(this, _inflightTasks).length + taskWorker_class_private_field_get(this, _pendingFinalizeTasks).size;
2774
+ return taskWorker_class_private_field_get(this, _pendingQueue).size + taskWorker_class_private_field_get(this, taskWorker_inflight).count + taskWorker_class_private_field_get(this, _pendingFinalizeTasks).size;
2151
2775
  }
2152
2776
  },
2153
2777
  {
@@ -2167,8 +2791,6 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2167
2791
  consumerError: null,
2168
2792
  stderrText: "",
2169
2793
  settled: false,
2170
- errorScheduled: false,
2171
- timer: null,
2172
2794
  startTime: 0
2173
2795
  };
2174
2796
  null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _metrics)) || _$_class_private_field_get.incrementTasksTotal(config.kind);
@@ -2176,6 +2798,14 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2176
2798
  taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2177
2799
  }
2178
2800
  },
2801
+ {
2802
+ key: "_sweepTimer",
2803
+ get: function() {
2804
+ var _$_class_private_field_get;
2805
+ var _class_private_field_get_getSweepTimer;
2806
+ return null != (_class_private_field_get_getSweepTimer = null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _sweeper)) ? void 0 : _$_class_private_field_get.getSweepTimer()) ? _class_private_field_get_getSweepTimer : null;
2807
+ }
2808
+ },
2179
2809
  {
2180
2810
  key: "_process",
2181
2811
  get: function() {
@@ -2185,6 +2815,9 @@ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
2185
2815
  {
2186
2816
  key: "kill",
2187
2817
  value: function() {
2818
+ var _class_private_field_get_cancel, _$_class_private_field_get;
2819
+ taskWorker_class_private_field_get(this, _sweeper).clear();
2820
+ null == (_class_private_field_get_cancel = (_$_class_private_field_get = taskWorker_class_private_field_get(this, _scheduleFinalizeCheck)).cancel) || _class_private_field_get_cancel.call(_$_class_private_field_get);
2188
2821
  taskWorker_class_private_method_get(this, _rejectAll, taskWorker_rejectAll).call(this, new Error("".concat(taskWorker_class_private_field_get(this, _name), " is killed")));
2189
2822
  taskWorker_class_private_field_get(this, _processManager).kill();
2190
2823
  }
@@ -2199,7 +2832,7 @@ function startProcess() {
2199
2832
  taskWorker_class_private_field_get(_this, _valueParser).feed(chunk);
2200
2833
  });
2201
2834
  proc.stderr.on("data", function(chunk) {
2202
- taskWorker_class_private_method_get(_this, _handleStderrChunk, taskWorker_handleStderrChunk).call(_this, chunk);
2835
+ taskWorker_class_private_method_get(_this, _handleStderrChunk, taskWorker_handleStderrChunk1).call(_this, chunk);
2203
2836
  });
2204
2837
  proc.on("error", function(error) {
2205
2838
  var _class_private_field_get_error, _$_class_private_field_get;
@@ -2214,167 +2847,46 @@ function startProcess() {
2214
2847
  });
2215
2848
  }
2216
2849
  function taskWorker_pumpQueue() {
2217
- var _this = this;
2218
- var _$_class_private_field_get;
2219
- if (taskWorker_class_private_field_get(this, _processManager).draining) return;
2220
- if (taskWorker_class_private_field_get(this, _inflightTasks).length >= taskWorker_class_private_field_get(this, _maxInflight)) return;
2221
- var batch = [];
2222
- while(batch.length < taskWorker_class_private_field_get(this, _batchSize) && !taskWorker_class_private_field_get(this, _pendingQueue).isEmpty() && taskWorker_class_private_field_get(this, _inflightTasks).length + batch.length < taskWorker_class_private_field_get(this, _maxInflight)){
2223
- var task = taskWorker_class_private_field_get(this, _pendingQueue).peek();
2224
- if ("stream" === task.kind && (batch.length > 0 || taskWorker_class_private_field_get(this, _inflightTasks).length > 0)) break;
2225
- taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
2226
- batch.push(task);
2227
- }
2228
- if (0 === batch.length) return;
2229
- var now = performance.now();
2230
- var payload = buildBatchPayload(batch);
2231
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2232
- try {
2233
- var _this1, _loop = function() {
2234
- var task = _step.value;
2235
- task.startTime = now;
2236
- var _task_timeout;
2237
- task.timer = setTimeout(function() {
2238
- return taskWorker_class_private_method_get(_this, _handleTaskTimeout, handleTaskTimeout).call(_this, task);
2239
- }, null != (_task_timeout = task.timeout) ? _task_timeout : taskWorker_class_private_field_get(_this1, _statementTimeout));
2240
- };
2241
- for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_this1 = this, _loop();
2242
- } catch (err) {
2243
- _didIteratorError = true;
2244
- _iteratorError = err;
2245
- } finally{
2246
- try {
2247
- if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2248
- } finally{
2249
- if (_didIteratorError) throw _iteratorError;
2250
- }
2251
- }
2252
- (_$_class_private_field_get = taskWorker_class_private_field_get(this, _inflightTasks)).push.apply(_$_class_private_field_get, taskWorker_to_consumable_array(batch));
2253
- taskWorker_class_private_field_get(this, _processManager).write(payload);
2254
- }
2255
- function handleParsedValue(raw) {
2256
- var task = taskWorker_class_private_field_get(this, _inflightTasks)[0];
2257
- if (!task) return;
2258
- if (isSentinelRaw(raw, task.token)) {
2259
- clearTimeout(task.timer);
2260
- taskWorker_class_private_field_get(this, _inflightTasks).shift();
2261
- if (task.timedout) return void taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2262
- if (task.stderrText) {
2263
- taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, new Error(task.stderrText.trim()), void 0);
2264
- taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2265
- return;
2266
- }
2267
- if (task.consumerError) {
2268
- taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, task.consumerError, void 0);
2269
- taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2270
- return;
2271
- }
2272
- taskWorker_class_private_field_get(this, _pendingFinalizeTasks).add(task);
2273
- taskWorker_class_private_method_get(this, _scheduleFinalizeCheck, scheduleFinalizeCheck).call(this);
2274
- taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2275
- return;
2276
- }
2277
- if ("[]" === raw) return;
2278
- var parsed;
2279
- try {
2280
- parsed = JSON.parse(raw);
2281
- } catch (error) {
2282
- taskWorker_class_private_method_get(this, _rejectAll, taskWorker_rejectAll).call(this, new Error("Invalid JSON from sqlite3: ".concat(toError(error).message)));
2283
- return;
2284
- }
2285
- if (isSentinelRow(parsed, task.token)) {
2286
- clearTimeout(task.timer);
2287
- taskWorker_class_private_field_get(this, _inflightTasks).shift();
2288
- if (task.timedout) return void taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2289
- if (task.stderrText) {
2290
- taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, new Error(task.stderrText.trim()), void 0);
2291
- taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2292
- return;
2293
- }
2294
- if (task.consumerError) {
2295
- taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, task.consumerError, void 0);
2296
- taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2297
- return;
2298
- }
2299
- taskWorker_class_private_field_get(this, _pendingFinalizeTasks).add(task);
2300
- taskWorker_class_private_method_get(this, _scheduleFinalizeCheck, scheduleFinalizeCheck).call(this);
2301
- taskWorker_class_private_method_get(this, _pumpQueue, taskWorker_pumpQueue).call(this);
2302
- return;
2303
- }
2304
- if ("query" === task.kind) return void collectQueryRows(task, parsed);
2305
- if ("stream" === task.kind) processStreamRows(task, parsed);
2850
+ taskWorker_class_private_field_get(this, _pump).call(this);
2306
2851
  }
2307
- function scheduleFinalizeCheck() {
2852
+ function taskWorker_afterSentinel(task) {
2308
2853
  var _this = this;
2309
- if (taskWorker_class_private_field_get(this, _scheduledFinalize)) return;
2310
- taskWorker_class_private_field_set(this, _scheduledFinalize, true);
2311
- setImmediate(function() {
2312
- taskWorker_class_private_field_set(_this, _scheduledFinalize, false);
2313
- finalizePendingTasks(taskWorker_class_private_field_get(_this, _pendingFinalizeTasks), function(t, e, v1) {
2854
+ handleSentinelTask(task, {
2855
+ settleTask: function(t, e, v1) {
2314
2856
  return taskWorker_class_private_method_get(_this, _settleTask, settleTask1).call(_this, t, e, v1);
2315
- }, function() {
2857
+ },
2858
+ pendingFinalizeTasks: taskWorker_class_private_field_get(this, _pendingFinalizeTasks),
2859
+ scheduleFinalizeCheck: function() {
2860
+ return taskWorker_class_private_field_get(_this, _scheduleFinalizeCheck).call(_this);
2861
+ },
2862
+ pumpQueue: function() {
2316
2863
  return taskWorker_class_private_method_get(_this, _pumpQueue, taskWorker_pumpQueue).call(_this);
2317
- });
2864
+ }
2318
2865
  });
2319
2866
  }
2320
- function taskWorker_handleStderrChunk(chunk) {
2321
- var _class_private_field_get_;
2322
- var task = null != (_class_private_field_get_ = taskWorker_class_private_field_get(this, _inflightTasks)[0]) ? _class_private_field_get_ : taskWorker_class_private_field_get(this, _pendingFinalizeTasks).values().next().value;
2323
- if (!task) {
2324
- var _class_private_field_get_error, _$_class_private_field_get;
2325
- null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _logger)) || null == (_class_private_field_get_error = _$_class_private_field_get.error) || _class_private_field_get_error.call(_$_class_private_field_get, String(chunk).trim());
2326
- return;
2327
- }
2328
- task.stderrText += String(chunk);
2329
- }
2330
- function handleTaskTimeout(task) {
2331
- var error = prepareTaskTimeout(task, taskWorker_class_private_field_get(this, _metrics));
2332
- if (error) taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, error, void 0);
2867
+ function taskWorker_handleStderrChunk1(chunk) {
2868
+ handleStderrChunk(chunk, {
2869
+ inflight: taskWorker_class_private_field_get(this, taskWorker_inflight),
2870
+ pendingFinalizeTasks: taskWorker_class_private_field_get(this, _pendingFinalizeTasks),
2871
+ logger: taskWorker_class_private_field_get(this, _logger),
2872
+ pendingStderr: taskWorker_class_private_field_get(this, _pendingStderr)
2873
+ });
2333
2874
  }
2334
2875
  function settleTask1(task, error, value) {
2335
- settleTask(task, error, value, taskWorker_class_private_field_get(this, _metrics));
2876
+ settleUtils_settleTask(task, error, value, taskWorker_class_private_field_get(this, _metrics));
2336
2877
  }
2337
2878
  function taskWorker_rejectAll(error) {
2338
- var all = taskWorker_class_private_field_get(this, _inflightTasks);
2339
- taskWorker_class_private_field_set(this, _inflightTasks, []);
2340
- var queued = taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
2341
- while(queued){
2342
- taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, queued, error, void 0);
2343
- queued = taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
2344
- }
2345
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2346
- try {
2347
- for(var _iterator = all[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2348
- var task = _step.value;
2349
- taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, error, void 0);
2350
- }
2351
- } catch (err) {
2352
- _didIteratorError = true;
2353
- _iteratorError = err;
2354
- } finally{
2355
- try {
2356
- if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2357
- } finally{
2358
- if (_didIteratorError) throw _iteratorError;
2359
- }
2360
- }
2361
- var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
2362
- try {
2363
- for(var _iterator1 = taskWorker_class_private_field_get(this, _pendingFinalizeTasks)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2364
- var task1 = _step1.value;
2365
- taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task1, error, void 0);
2366
- }
2367
- } catch (err) {
2368
- _didIteratorError1 = true;
2369
- _iteratorError1 = err;
2370
- } finally{
2371
- try {
2372
- if (!_iteratorNormalCompletion1 && null != _iterator1["return"]) _iterator1["return"]();
2373
- } finally{
2374
- if (_didIteratorError1) throw _iteratorError1;
2375
- }
2376
- }
2377
- taskWorker_class_private_field_get(this, _pendingFinalizeTasks).clear();
2879
+ var _this = this;
2880
+ taskWorker_class_private_field_get(this, _sweeper).clear();
2881
+ rejectAllTasks({
2882
+ inflight: taskWorker_class_private_field_get(this, taskWorker_inflight),
2883
+ queue: taskWorker_class_private_field_get(this, _pendingQueue),
2884
+ pendingFinalizeTasks: taskWorker_class_private_field_get(this, _pendingFinalizeTasks),
2885
+ settleTask: function(t, e, v1) {
2886
+ return taskWorker_class_private_method_get(_this, _settleTask, settleTask1).call(_this, t, e, v1);
2887
+ },
2888
+ error: error
2889
+ });
2378
2890
  }
2379
2891
  function readerPool_check_private_redeclaration(obj, privateCollection) {
2380
2892
  if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -2447,7 +2959,7 @@ var readerPool_ReaderPool = /*#__PURE__*/ function() {
2447
2959
  logger: logger,
2448
2960
  metrics: metrics,
2449
2961
  name: "reader-".concat(i),
2450
- initMode: ":memory:" !== database ? "none" : "wal"
2962
+ initMode: ":memory:" !== database ? "none" : "none"
2451
2963
  });
2452
2964
  readerPool_class_private_field_get(this, _workers).push(worker);
2453
2965
  }
@@ -2470,9 +2982,19 @@ var readerPool_ReaderPool = /*#__PURE__*/ function() {
2470
2982
  {
2471
2983
  key: "enqueue",
2472
2984
  value: function(task) {
2473
- var worker = readerPool_class_private_field_get(this, _workers)[readerPool_class_private_field_get(this, _rrIndex) % readerPool_class_private_field_get(this, _workers).length];
2985
+ var minLoad = 1 / 0;
2986
+ var candidates = [];
2987
+ for(var i = 0; i < readerPool_class_private_field_get(this, _workers).length; i++){
2988
+ var load = readerPool_class_private_field_get(this, _workers)[i].pendingStatements;
2989
+ if (load < minLoad) {
2990
+ minLoad = load;
2991
+ candidates.length = 0;
2992
+ candidates.push(i);
2993
+ } else if (load === minLoad) candidates.push(i);
2994
+ }
2995
+ var idx = candidates[readerPool_class_private_field_get(this, _rrIndex) % candidates.length];
2474
2996
  readerPool_class_private_field_set(this, _rrIndex, readerPool_class_private_field_get(this, _rrIndex) + 1 >>> 0);
2475
- worker.enqueue(task);
2997
+ readerPool_class_private_field_get(this, _workers)[idx].enqueue(task);
2476
2998
  }
2477
2999
  },
2478
3000
  {
@@ -2718,6 +3240,10 @@ var metrics_Metrics = /*#__PURE__*/ function() {
2718
3240
  key: "snapshot",
2719
3241
  value: function() {
2720
3242
  var elapsed = (Date.now() - metrics_class_private_field_get(this, _startTime)) / 1000;
3243
+ var avgTaskDuration;
3244
+ avgTaskDuration = metrics_class_private_field_get(this, _tasksSuccess) > 0 ? metrics_class_private_field_get(this, _totalDuration) / metrics_class_private_field_get(this, _tasksSuccess) : 0;
3245
+ var throughput;
3246
+ throughput = elapsed > 0 ? metrics_class_private_field_get(this, _tasksTotal) / elapsed : 0;
2721
3247
  return {
2722
3248
  tasksTotal: metrics_class_private_field_get(this, _tasksTotal),
2723
3249
  tasksSuccess: metrics_class_private_field_get(this, _tasksSuccess),
@@ -2727,8 +3253,8 @@ var metrics_Metrics = /*#__PURE__*/ function() {
2727
3253
  executeCount: metrics_class_private_field_get(this, _executeCount),
2728
3254
  queryCount: metrics_class_private_field_get(this, _queryCount),
2729
3255
  streamCount: metrics_class_private_field_get(this, _streamCount),
2730
- avgQueryTime: metrics_class_private_field_get(this, _tasksSuccess) > 0 ? metrics_class_private_field_get(this, _totalDuration) / metrics_class_private_field_get(this, _tasksSuccess) : 0,
2731
- qps: elapsed > 0 ? metrics_class_private_field_get(this, _tasksTotal) / elapsed : 0,
3256
+ avgTaskDuration: avgTaskDuration,
3257
+ throughput: throughput,
2732
3258
  uptime: elapsed
2733
3259
  };
2734
3260
  }
@@ -2965,9 +3491,7 @@ var transactionScope_TransactionScope = /*#__PURE__*/ function() {
2965
3491
  release = resolve;
2966
3492
  });
2967
3493
  previous = transactionScope_class_private_field_get(_this, _scopeChain);
2968
- transactionScope_class_private_field_set(_this, _scopeChain, previous["catch"](function() {}).then(function() {
2969
- return gate;
2970
- }));
3494
+ transactionScope_class_private_field_set(_this, _scopeChain, gate);
2971
3495
  return [
2972
3496
  4,
2973
3497
  previous["catch"](function() {})
@@ -3004,7 +3528,7 @@ var transactionScope_TransactionScope = /*#__PURE__*/ function() {
3004
3528
  value: function(error) {
3005
3529
  var task = transactionScope_class_private_field_get(this, _deferredQueue).dequeue();
3006
3530
  while(task){
3007
- settleTask(task, error, void 0, null);
3531
+ settleUtils_settleTask(task, error, void 0, null);
3008
3532
  task = transactionScope_class_private_field_get(this, _deferredQueue).dequeue();
3009
3533
  }
3010
3534
  }
@@ -3012,14 +3536,6 @@ var transactionScope_TransactionScope = /*#__PURE__*/ function() {
3012
3536
  ]);
3013
3537
  return TransactionScope;
3014
3538
  }();
3015
- function pipelineEngine_array_like_to_array(arr, len) {
3016
- if (null == len || len > arr.length) len = arr.length;
3017
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
3018
- return arr2;
3019
- }
3020
- function pipelineEngine_array_without_holes(arr) {
3021
- if (Array.isArray(arr)) return pipelineEngine_array_like_to_array(arr);
3022
- }
3023
3539
  function pipelineEngine_check_private_redeclaration(obj, privateCollection) {
3024
3540
  if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
3025
3541
  }
@@ -3076,52 +3592,29 @@ function pipelineEngine_create_class(Constructor, protoProps, staticProps) {
3076
3592
  if (staticProps) pipelineEngine_defineProperties(Constructor, staticProps);
3077
3593
  return Constructor;
3078
3594
  }
3079
- function pipelineEngine_iterable_to_array(iter) {
3080
- if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
3081
- }
3082
- function pipelineEngine_non_iterable_spread() {
3083
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3084
- }
3085
- function pipelineEngine_to_consumable_array(arr) {
3086
- return pipelineEngine_array_without_holes(arr) || pipelineEngine_iterable_to_array(arr) || pipelineEngine_unsupported_iterable_to_array(arr) || pipelineEngine_non_iterable_spread();
3087
- }
3088
- function pipelineEngine_unsupported_iterable_to_array(o, minLen) {
3089
- if (!o) return;
3090
- if ("string" == typeof o) return pipelineEngine_array_like_to_array(o, minLen);
3091
- var n = Object.prototype.toString.call(o).slice(8, -1);
3092
- if ("Object" === n && o.constructor) n = o.constructor.name;
3093
- if ("Map" === n || "Set" === n) return Array.from(n);
3094
- if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return pipelineEngine_array_like_to_array(o, minLen);
3095
- }
3096
- var _queue = /*#__PURE__*/ new WeakMap(), pipelineEngine_inflightTasks = /*#__PURE__*/ new WeakMap(), pipelineEngine_pendingFinalizeTasks = /*#__PURE__*/ new WeakMap(), pipelineEngine_scheduledFinalize = /*#__PURE__*/ new WeakMap(), _sharedValueParser = /*#__PURE__*/ new WeakMap(), pipelineEngine_processManager = /*#__PURE__*/ new WeakMap(), pipelineEngine_metrics = /*#__PURE__*/ new WeakMap(), pipelineEngine_statementTimeout = /*#__PURE__*/ new WeakMap(), pipelineEngine_logger = /*#__PURE__*/ new WeakMap(), pipelineEngine_batchSize = /*#__PURE__*/ new WeakMap(), pipelineEngine_maxInflight = /*#__PURE__*/ new WeakMap(), _onTaskTimeout = /*#__PURE__*/ new WeakMap(), _active = /*#__PURE__*/ new WeakMap(), _sweepTimer = /*#__PURE__*/ new WeakMap(), _sweepIntervalMs = /*#__PURE__*/ new WeakMap(), core_pipelineEngine_pumpQueue = /*#__PURE__*/ new WeakSet(), pipelineEngine_handleParsedValue = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_scheduleFinalizeCheck = /*#__PURE__*/ new WeakSet(), _scheduleSweep = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_handleTaskTimeout = /*#__PURE__*/ new WeakSet(), pipelineEngine_settleTask = /*#__PURE__*/ new WeakSet();
3595
+ var _queue = /*#__PURE__*/ new WeakMap(), pipelineEngine_inflight = /*#__PURE__*/ new WeakMap(), pipelineEngine_pendingFinalizeTasks = /*#__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_sweeper = /*#__PURE__*/ new WeakMap(), pipelineEngine_scheduleFinalizeCheck = /*#__PURE__*/ new WeakMap(), pipelineEngine_pump = /*#__PURE__*/ new WeakMap(), pipelineEngine_pendingStderr = /*#__PURE__*/ new WeakMap(), core_pipelineEngine_pumpQueue = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_afterSentinel = /*#__PURE__*/ new WeakSet(), pipelineEngine_settleTask = /*#__PURE__*/ new WeakSet();
3097
3596
  var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3098
3597
  "use strict";
3099
3598
  function PipelineEngine(processManager, param) {
3100
3599
  var _this = this;
3101
3600
  var metrics = param.metrics, statementTimeout = param.statementTimeout, logger = param.logger, _param_batchSize = param.batchSize, batchSize = void 0 === _param_batchSize ? DEFAULT_BATCH_SIZE : _param_batchSize, _param_maxInflight = param.maxInflight, maxInflight = void 0 === _param_maxInflight ? DEFAULT_MAX_INFLIGHT : _param_maxInflight, onTaskTimeout = param.onTaskTimeout, _param_sweepInterval = param.sweepInterval, sweepInterval = void 0 === _param_sweepInterval ? 100 : _param_sweepInterval;
3102
3601
  pipelineEngine_class_call_check(this, PipelineEngine);
3602
+ var _this1, _this2;
3103
3603
  pipelineEngine_class_private_method_init(this, core_pipelineEngine_pumpQueue);
3104
- pipelineEngine_class_private_method_init(this, pipelineEngine_handleParsedValue);
3105
- pipelineEngine_class_private_method_init(this, core_pipelineEngine_scheduleFinalizeCheck);
3106
- pipelineEngine_class_private_method_init(this, _scheduleSweep);
3107
- pipelineEngine_class_private_method_init(this, core_pipelineEngine_handleTaskTimeout);
3604
+ pipelineEngine_class_private_method_init(this, core_pipelineEngine_afterSentinel);
3108
3605
  pipelineEngine_class_private_method_init(this, pipelineEngine_settleTask);
3109
3606
  pipelineEngine_class_private_field_init(this, _queue, {
3110
3607
  writable: true,
3111
3608
  value: new queue_Queue()
3112
3609
  });
3113
- pipelineEngine_class_private_field_init(this, pipelineEngine_inflightTasks, {
3610
+ pipelineEngine_class_private_field_init(this, pipelineEngine_inflight, {
3114
3611
  writable: true,
3115
- value: []
3612
+ value: new inflightTracker_InflightTracker()
3116
3613
  });
3117
3614
  pipelineEngine_class_private_field_init(this, pipelineEngine_pendingFinalizeTasks, {
3118
3615
  writable: true,
3119
3616
  value: new Set()
3120
3617
  });
3121
- pipelineEngine_class_private_field_init(this, pipelineEngine_scheduledFinalize, {
3122
- writable: true,
3123
- value: false
3124
- });
3125
3618
  pipelineEngine_class_private_field_init(this, _sharedValueParser, {
3126
3619
  writable: true,
3127
3620
  value: void 0
@@ -3158,14 +3651,22 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3158
3651
  writable: true,
3159
3652
  value: false
3160
3653
  });
3161
- pipelineEngine_class_private_field_init(this, _sweepTimer, {
3654
+ pipelineEngine_class_private_field_init(this, pipelineEngine_sweeper, {
3162
3655
  writable: true,
3163
- value: null
3656
+ value: void 0
3657
+ });
3658
+ pipelineEngine_class_private_field_init(this, pipelineEngine_scheduleFinalizeCheck, {
3659
+ writable: true,
3660
+ value: void 0
3164
3661
  });
3165
- pipelineEngine_class_private_field_init(this, _sweepIntervalMs, {
3662
+ pipelineEngine_class_private_field_init(this, pipelineEngine_pump, {
3166
3663
  writable: true,
3167
3664
  value: void 0
3168
3665
  });
3666
+ pipelineEngine_class_private_field_init(this, pipelineEngine_pendingStderr, {
3667
+ writable: true,
3668
+ value: []
3669
+ });
3169
3670
  pipelineEngine_class_private_field_set(this, pipelineEngine_processManager, processManager);
3170
3671
  pipelineEngine_class_private_field_set(this, pipelineEngine_metrics, metrics);
3171
3672
  pipelineEngine_class_private_field_set(this, pipelineEngine_statementTimeout, statementTimeout);
@@ -3173,19 +3674,57 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3173
3674
  pipelineEngine_class_private_field_set(this, pipelineEngine_batchSize, batchSize);
3174
3675
  pipelineEngine_class_private_field_set(this, pipelineEngine_maxInflight, maxInflight);
3175
3676
  pipelineEngine_class_private_field_set(this, _onTaskTimeout, null != onTaskTimeout ? onTaskTimeout : function() {});
3677
+ pipelineEngine_class_private_field_set(this, pipelineEngine_sweeper, createSweeper({
3678
+ inflight: pipelineEngine_class_private_field_get(this, pipelineEngine_inflight),
3679
+ sweepIntervalMs: sweepInterval,
3680
+ handleTaskTimeout: function(task) {
3681
+ var error = prepareTaskTimeout(task, pipelineEngine_class_private_field_get(_this, pipelineEngine_metrics));
3682
+ if (error) {
3683
+ pipelineEngine_class_private_method_get(_this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(_this, task, error, void 0);
3684
+ null == (_this1 = pipelineEngine_class_private_field_get(_this2 = _this, _onTaskTimeout)) || _this1.call(_this2, task);
3685
+ }
3686
+ }
3687
+ }));
3688
+ pipelineEngine_class_private_field_set(this, pipelineEngine_pump, createPumpQueue({
3689
+ queue: pipelineEngine_class_private_field_get(this, _queue),
3690
+ inflight: pipelineEngine_class_private_field_get(this, pipelineEngine_inflight),
3691
+ processManager: pipelineEngine_class_private_field_get(this, pipelineEngine_processManager),
3692
+ sweeper: pipelineEngine_class_private_field_get(this, pipelineEngine_sweeper),
3693
+ batchSize: pipelineEngine_class_private_field_get(this, pipelineEngine_batchSize),
3694
+ maxInflight: pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)
3695
+ }));
3696
+ pipelineEngine_class_private_field_set(this, pipelineEngine_scheduleFinalizeCheck, createFinalizeScheduler({
3697
+ pendingFinalizeTasks: pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks),
3698
+ settleTask: function(t, e, v1) {
3699
+ return pipelineEngine_class_private_method_get(_this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(_this, t, e, v1);
3700
+ },
3701
+ pumpQueue: function() {
3702
+ return pipelineEngine_class_private_method_get(_this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(_this);
3703
+ },
3704
+ pendingStderr: pipelineEngine_class_private_field_get(this, pipelineEngine_pendingStderr),
3705
+ inflight: pipelineEngine_class_private_field_get(this, pipelineEngine_inflight)
3706
+ }));
3176
3707
  pipelineEngine_class_private_field_set(this, _sharedValueParser, createJsonValueParser(function(raw) {
3177
- return pipelineEngine_class_private_method_get(_this, pipelineEngine_handleParsedValue, core_pipelineEngine_handleParsedValue).call(_this, raw);
3708
+ handleParsedValue(raw, pipelineEngine_class_private_field_get(_this, pipelineEngine_inflight), {
3709
+ afterSentinel: function(task) {
3710
+ return pipelineEngine_class_private_method_get(_this, core_pipelineEngine_afterSentinel, pipelineEngine_afterSentinel).call(_this, task);
3711
+ },
3712
+ rejectAll: function(error) {
3713
+ return _this.rejectAll(error);
3714
+ }
3715
+ });
3178
3716
  }));
3179
3717
  pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).setOnDrainCallback(function() {
3180
3718
  return pipelineEngine_class_private_method_get(_this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(_this);
3181
3719
  });
3182
- pipelineEngine_class_private_field_set(this, _sweepIntervalMs, sweepInterval);
3183
3720
  }
3184
3721
  pipelineEngine_create_class(PipelineEngine, [
3185
3722
  {
3186
3723
  key: "_sweepTimer",
3187
3724
  get: function() {
3188
- return pipelineEngine_class_private_field_get(this, _sweepTimer);
3725
+ var _$_class_private_field_get;
3726
+ var _class_private_field_get_getSweepTimer;
3727
+ return null != (_class_private_field_get_getSweepTimer = null == (_$_class_private_field_get = pipelineEngine_class_private_field_get(this, pipelineEngine_sweeper)) ? void 0 : _$_class_private_field_get.getSweepTimer()) ? _class_private_field_get_getSweepTimer : null;
3189
3728
  }
3190
3729
  },
3191
3730
  {
@@ -3203,7 +3742,7 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3203
3742
  {
3204
3743
  key: "pendingStatements",
3205
3744
  get: function() {
3206
- return pipelineEngine_class_private_field_get(this, _queue).size + pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length + pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).size;
3745
+ return pipelineEngine_class_private_field_get(this, _queue).size + pipelineEngine_class_private_field_get(this, pipelineEngine_inflight).count + pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).size;
3207
3746
  }
3208
3747
  },
3209
3748
  {
@@ -3236,7 +3775,7 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3236
3775
  {
3237
3776
  key: "handleStdoutChunk",
3238
3777
  value: function(chunk) {
3239
- var task = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[0];
3778
+ var task = pipelineEngine_class_private_field_get(this, pipelineEngine_inflight).first;
3240
3779
  if (!task) return;
3241
3780
  if ("stream" === task.kind && task.rowParser && !task.rowParser.finished && !task.timedout) {
3242
3781
  var leftover = task.rowParser.feed(chunk);
@@ -3249,68 +3788,37 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3249
3788
  {
3250
3789
  key: "handleStderrChunk",
3251
3790
  value: function(chunk) {
3252
- var _class_private_field_get_values_next_value;
3253
- var task = null != (_class_private_field_get_values_next_value = pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).values().next().value) ? _class_private_field_get_values_next_value : pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[0];
3254
- if (!task) {
3255
- var _class_private_field_get_error, _$_class_private_field_get;
3256
- null == (_$_class_private_field_get = pipelineEngine_class_private_field_get(this, pipelineEngine_logger)) || null == (_class_private_field_get_error = _$_class_private_field_get.error) || _class_private_field_get_error.call(_$_class_private_field_get, String(chunk).trim());
3257
- return;
3258
- }
3259
- task.stderrText += String(chunk);
3791
+ handleStderrChunk(chunk, {
3792
+ inflight: pipelineEngine_class_private_field_get(this, pipelineEngine_inflight),
3793
+ pendingFinalizeTasks: pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks),
3794
+ logger: pipelineEngine_class_private_field_get(this, pipelineEngine_logger),
3795
+ pendingStderr: pipelineEngine_class_private_field_get(this, pipelineEngine_pendingStderr)
3796
+ });
3260
3797
  }
3261
3798
  },
3262
3799
  {
3263
3800
  key: "rejectAll",
3264
3801
  value: function(error) {
3802
+ var _this = this;
3265
3803
  pipelineEngine_class_private_field_get(this, _sharedValueParser).reset();
3266
- var all = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks);
3267
- pipelineEngine_class_private_field_set(this, pipelineEngine_inflightTasks, []);
3268
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
3269
- try {
3270
- for(var _iterator = all[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3271
- var task = _step.value;
3272
- pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, error, void 0);
3273
- }
3274
- } catch (err) {
3275
- _didIteratorError = true;
3276
- _iteratorError = err;
3277
- } finally{
3278
- try {
3279
- if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
3280
- } finally{
3281
- if (_didIteratorError) throw _iteratorError;
3282
- }
3283
- }
3284
- var queued = pipelineEngine_class_private_field_get(this, _queue).dequeue();
3285
- while(queued){
3286
- pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, queued, error, void 0);
3287
- queued = pipelineEngine_class_private_field_get(this, _queue).dequeue();
3288
- }
3289
- var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
3290
- try {
3291
- for(var _iterator1 = pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
3292
- var task1 = _step1.value;
3293
- pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task1, error, void 0);
3294
- }
3295
- } catch (err) {
3296
- _didIteratorError1 = true;
3297
- _iteratorError1 = err;
3298
- } finally{
3299
- try {
3300
- if (!_iteratorNormalCompletion1 && null != _iterator1["return"]) _iterator1["return"]();
3301
- } finally{
3302
- if (_didIteratorError1) throw _iteratorError1;
3303
- }
3304
- }
3305
- pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).clear();
3804
+ rejectAllTasks({
3805
+ inflight: pipelineEngine_class_private_field_get(this, pipelineEngine_inflight),
3806
+ queue: pipelineEngine_class_private_field_get(this, _queue),
3807
+ pendingFinalizeTasks: pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks),
3808
+ settleTask: function(t, e, v1) {
3809
+ return pipelineEngine_class_private_method_get(_this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(_this, t, e, v1);
3810
+ },
3811
+ error: error
3812
+ });
3306
3813
  }
3307
3814
  },
3308
3815
  {
3309
3816
  key: "kill",
3310
3817
  value: function() {
3818
+ var _class_private_field_get_cancel, _$_class_private_field_get;
3311
3819
  pipelineEngine_class_private_field_set(this, _active, false);
3312
- clearTimeout(pipelineEngine_class_private_field_get(this, _sweepTimer));
3313
- pipelineEngine_class_private_field_set(this, _sweepTimer, null);
3820
+ pipelineEngine_class_private_field_get(this, pipelineEngine_sweeper).clear();
3821
+ null == (_class_private_field_get_cancel = (_$_class_private_field_get = pipelineEngine_class_private_field_get(this, pipelineEngine_scheduleFinalizeCheck)).cancel) || _class_private_field_get_cancel.call(_$_class_private_field_get);
3314
3822
  this.rejectAll(new Error("PipelineEngine is killed"));
3315
3823
  }
3316
3824
  }
@@ -3318,118 +3826,26 @@ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
3318
3826
  return PipelineEngine;
3319
3827
  }();
3320
3828
  function pipelineEngine_pumpQueue() {
3321
- var _$_class_private_field_get;
3322
3829
  if (!pipelineEngine_class_private_field_get(this, _active)) return;
3323
- if (pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).draining) return;
3324
- if (pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length >= pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)) return;
3325
- var batch = [];
3326
- while(batch.length < pipelineEngine_class_private_field_get(this, pipelineEngine_batchSize) && !pipelineEngine_class_private_field_get(this, _queue).isEmpty() && pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length + batch.length < pipelineEngine_class_private_field_get(this, pipelineEngine_maxInflight)){
3327
- var task = pipelineEngine_class_private_field_get(this, _queue).peek();
3328
- if ("stream" === task.kind && (batch.length > 0 || pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length > 0)) break;
3329
- pipelineEngine_class_private_field_get(this, _queue).dequeue();
3330
- batch.push(task);
3331
- }
3332
- if (0 === batch.length) return;
3333
- var now = performance.now();
3334
- var payload = buildBatchPayload(batch);
3335
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
3336
- try {
3337
- for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3338
- var task1 = _step.value;
3339
- task1.startTime = now;
3340
- }
3341
- } catch (err) {
3342
- _didIteratorError = true;
3343
- _iteratorError = err;
3344
- } finally{
3345
- try {
3346
- if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
3347
- } finally{
3348
- if (_didIteratorError) throw _iteratorError;
3349
- }
3350
- }
3351
- (_$_class_private_field_get = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)).push.apply(_$_class_private_field_get, pipelineEngine_to_consumable_array(batch));
3352
- pipelineEngine_class_private_method_get(this, _scheduleSweep, scheduleSweep).call(this);
3353
- pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).write(payload);
3354
- }
3355
- function core_pipelineEngine_handleParsedValue(raw) {
3356
- var task = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[0];
3357
- if (!task) return;
3358
- if (isSentinelRaw(raw, task.token)) {
3359
- pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).shift();
3360
- if (task.timedout) return void pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3361
- if (task.consumerError) {
3362
- pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, task.consumerError, void 0);
3363
- pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3364
- return;
3365
- }
3366
- pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).add(task);
3367
- pipelineEngine_class_private_method_get(this, core_pipelineEngine_scheduleFinalizeCheck, pipelineEngine_scheduleFinalizeCheck).call(this);
3368
- pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3369
- return;
3370
- }
3371
- if ("[]" === raw) return;
3372
- var parsed;
3373
- try {
3374
- parsed = JSON.parse(raw);
3375
- } catch (error) {
3376
- this.rejectAll(new Error("Invalid JSON from sqlite3: ".concat(toError(error).message)));
3377
- return;
3378
- }
3379
- if (isSentinelRow(parsed, task.token)) {
3380
- pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).shift();
3381
- if (task.timedout) return void pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3382
- if (task.consumerError) {
3383
- pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, task.consumerError, void 0);
3384
- pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3385
- return;
3386
- }
3387
- pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).add(task);
3388
- pipelineEngine_class_private_method_get(this, core_pipelineEngine_scheduleFinalizeCheck, pipelineEngine_scheduleFinalizeCheck).call(this);
3389
- pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3390
- return;
3391
- }
3392
- if (task.timedout) return;
3393
- if ("query" === task.kind) return void collectQueryRows(task, parsed);
3394
- if ("stream" === task.kind) processStreamRows(task, parsed);
3830
+ pipelineEngine_class_private_field_get(this, pipelineEngine_pump).call(this);
3395
3831
  }
3396
- function pipelineEngine_scheduleFinalizeCheck() {
3832
+ function pipelineEngine_afterSentinel(task) {
3397
3833
  var _this = this;
3398
- if (pipelineEngine_class_private_field_get(this, pipelineEngine_scheduledFinalize)) return;
3399
- pipelineEngine_class_private_field_set(this, pipelineEngine_scheduledFinalize, true);
3400
- setImmediate(function() {
3401
- pipelineEngine_class_private_field_set(_this, pipelineEngine_scheduledFinalize, false);
3402
- finalizePendingTasks(pipelineEngine_class_private_field_get(_this, pipelineEngine_pendingFinalizeTasks), function(t, e, v1) {
3834
+ handleSentinelTask(task, {
3835
+ settleTask: function(t, e, v1) {
3403
3836
  return pipelineEngine_class_private_method_get(_this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(_this, t, e, v1);
3404
- }, function() {
3837
+ },
3838
+ pendingFinalizeTasks: pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks),
3839
+ scheduleFinalizeCheck: function() {
3840
+ return pipelineEngine_class_private_field_get(_this, pipelineEngine_scheduleFinalizeCheck).call(_this);
3841
+ },
3842
+ pumpQueue: function() {
3405
3843
  return pipelineEngine_class_private_method_get(_this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(_this);
3406
- });
3407
- });
3408
- }
3409
- function scheduleSweep() {
3410
- var _this = this;
3411
- if (pipelineEngine_class_private_field_get(this, _sweepTimer)) return;
3412
- pipelineEngine_class_private_field_set(this, _sweepTimer, setTimeout(function() {
3413
- pipelineEngine_class_private_field_set(_this, _sweepTimer, null);
3414
- var inflight = pipelineEngine_class_private_field_get(_this, pipelineEngine_inflightTasks);
3415
- var now = performance.now();
3416
- for(var i = 0; i < inflight.length; i++){
3417
- var task = inflight[i];
3418
- if (now - task.startTime > task.timeout) pipelineEngine_class_private_method_get(_this, core_pipelineEngine_handleTaskTimeout, pipelineEngine_handleTaskTimeout).call(_this, task);
3419
3844
  }
3420
- if (pipelineEngine_class_private_field_get(_this, pipelineEngine_inflightTasks).length > 0) pipelineEngine_class_private_method_get(_this, _scheduleSweep, scheduleSweep).call(_this);
3421
- }, pipelineEngine_class_private_field_get(this, _sweepIntervalMs)).unref());
3422
- }
3423
- function pipelineEngine_handleTaskTimeout(task) {
3424
- var _this, _this1;
3425
- var error = prepareTaskTimeout(task, pipelineEngine_class_private_field_get(this, pipelineEngine_metrics));
3426
- if (error) {
3427
- pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, error, void 0);
3428
- null == (_this = pipelineEngine_class_private_field_get(_this1 = this, _onTaskTimeout)) || _this.call(_this1, task);
3429
- }
3845
+ });
3430
3846
  }
3431
3847
  function pipelineEngine_settleTask1(task, error, value) {
3432
- settleTask(task, error, value, pipelineEngine_class_private_field_get(this, pipelineEngine_metrics), {
3848
+ settleUtils_settleTask(task, error, value, pipelineEngine_class_private_field_get(this, pipelineEngine_metrics), {
3433
3849
  resetRowParser: true
3434
3850
  });
3435
3851
  }
@@ -3936,31 +4352,6 @@ var executor_SQLiteExecutor = /*#__PURE__*/ function() {
3936
4352
  case 1:
3937
4353
  _state.sent();
3938
4354
  executor_class_private_field_get(_this, executor_processManager).kill();
3939
- _state.label = 2;
3940
- case 2:
3941
- _state.trys.push([
3942
- 2,
3943
- 4,
3944
- ,
3945
- 5
3946
- ]);
3947
- return [
3948
- 4,
3949
- (0, external_node_events_namespaceObject.once)(executor_class_private_field_get(_this, executor_processManager).process, "close")
3950
- ];
3951
- case 3:
3952
- _state.sent();
3953
- return [
3954
- 3,
3955
- 5
3956
- ];
3957
- case 4:
3958
- _state.sent();
3959
- return [
3960
- 3,
3961
- 5
3962
- ];
3963
- case 5:
3964
4355
  return [
3965
4356
  2
3966
4357
  ];
@@ -4028,20 +4419,18 @@ function executor_enqueue(kind, sql, params, options, scopeId) {
4028
4419
  var token = generateToken();
4029
4420
  var _options_onRow;
4030
4421
  var onRow = null != (_options_onRow = null == options ? void 0 : options.onRow) ? _options_onRow : null;
4031
- var normalized = normalizeSQL(sql);
4422
+ var template = normalizeSQLTemplate(sql);
4032
4423
  var formatted;
4033
- var sqlNormalized = true;
4034
- formatted = 0 !== params.length || normalized.includes("?") ? interpolateSQL(normalized, params) : normalized;
4035
- if (scopeId) return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, scopeId, sqlNormalized);
4424
+ formatted = 0 === params.length && 0 === template.paramCount ? template.normalized : interpolateFromTemplate(template, params);
4425
+ if (scopeId) return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, scopeId);
4036
4426
  if (executor_class_private_field_get(this, _readerPool)) {
4037
4427
  if ("stream" === kind || "query" === kind) return executor_class_private_method_get(this, _enqueueReader, enqueueReader).call(this, kind, formatted, timeout, token, onRow);
4038
- if ("execute" === kind && "read" === classifySQL(normalized)) return executor_class_private_method_get(this, _enqueueReader, enqueueReader).call(this, kind, formatted, timeout, token, onRow);
4428
+ if ("execute" === kind && "read" === classifySQL(template.normalized)) return executor_class_private_method_get(this, _enqueueReader, enqueueReader).call(this, kind, formatted, timeout, token, onRow);
4039
4429
  }
4040
- return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, null, sqlNormalized);
4430
+ return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, null);
4041
4431
  }
4042
4432
  function enqueueWriter(kind, sql, timeout, token, onRow, scopeId) {
4043
4433
  var _this = this;
4044
- var sqlNormalized = arguments.length > 6 && void 0 !== arguments[6] ? arguments[6] : false;
4045
4434
  executor_class_private_field_get(this, executor_metrics).incrementTasksTotal(kind);
4046
4435
  return new Promise(function(resolve, reject) {
4047
4436
  var task = {
@@ -4051,13 +4440,11 @@ function enqueueWriter(kind, sql, timeout, token, onRow, scopeId) {
4051
4440
  token: token,
4052
4441
  onRow: onRow,
4053
4442
  scopeId: scopeId,
4054
- sqlNormalized: sqlNormalized,
4055
4443
  resolve: resolve,
4056
4444
  reject: reject,
4057
4445
  consumerError: null,
4058
4446
  stderrText: "",
4059
4447
  settled: false,
4060
- timer: null,
4061
4448
  startTime: 0,
4062
4449
  rowParser: null,
4063
4450
  rows: "query" === kind ? [] : null