sqlite-executor 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +46 -0
  2. package/README.md +312 -0
  3. package/dist/cjs/constants.d.cts +2 -0
  4. package/dist/cjs/core/classifier.d.cts +13 -0
  5. package/dist/cjs/core/executor.d.cts +94 -0
  6. package/dist/cjs/core/lruCache.d.cts +16 -0
  7. package/dist/cjs/core/metrics.d.cts +84 -0
  8. package/dist/cjs/core/parser.d.cts +55 -0
  9. package/dist/cjs/core/pipelineEngine.d.cts +91 -0
  10. package/dist/cjs/core/process.d.cts +38 -0
  11. package/dist/cjs/core/protocol.d.cts +23 -0
  12. package/dist/cjs/core/queue.d.cts +40 -0
  13. package/dist/cjs/core/readerPool.d.cts +40 -0
  14. package/dist/cjs/core/settleUtils.d.cts +36 -0
  15. package/dist/cjs/core/taskWorker.d.cts +50 -0
  16. package/dist/cjs/core/transactionScope.d.cts +83 -0
  17. package/dist/cjs/index.cjs +3939 -0
  18. package/dist/cjs/index.cjs.map +1 -0
  19. package/dist/cjs/index.d.cts +28 -0
  20. package/dist/cjs/stream/stream.d.cts +43 -0
  21. package/dist/cjs/transaction/transaction.d.cts +32 -0
  22. package/dist/cjs/utils/escape.d.cts +7 -0
  23. package/dist/cjs/utils/interpolate.d.cts +8 -0
  24. package/dist/cjs/utils/normalize.d.cts +7 -0
  25. package/dist/cjs/utils/timeout.d.cts +11 -0
  26. package/dist/cjs/utils/token.d.cts +7 -0
  27. package/dist/cjs/which.d.cts +8 -0
  28. package/dist/esm/constants.d.mts +2 -0
  29. package/dist/esm/core/classifier.d.mts +13 -0
  30. package/dist/esm/core/executor.d.mts +94 -0
  31. package/dist/esm/core/lruCache.d.mts +16 -0
  32. package/dist/esm/core/metrics.d.mts +84 -0
  33. package/dist/esm/core/parser.d.mts +55 -0
  34. package/dist/esm/core/pipelineEngine.d.mts +91 -0
  35. package/dist/esm/core/process.d.mts +38 -0
  36. package/dist/esm/core/protocol.d.mts +23 -0
  37. package/dist/esm/core/queue.d.mts +40 -0
  38. package/dist/esm/core/readerPool.d.mts +40 -0
  39. package/dist/esm/core/settleUtils.d.mts +36 -0
  40. package/dist/esm/core/taskWorker.d.mts +50 -0
  41. package/dist/esm/core/transactionScope.d.mts +83 -0
  42. package/dist/esm/index.d.mts +28 -0
  43. package/dist/esm/index.mjs +3865 -0
  44. package/dist/esm/index.mjs.map +1 -0
  45. package/dist/esm/stream/stream.d.mts +43 -0
  46. package/dist/esm/transaction/transaction.d.mts +32 -0
  47. package/dist/esm/utils/escape.d.mts +7 -0
  48. package/dist/esm/utils/interpolate.d.mts +8 -0
  49. package/dist/esm/utils/normalize.d.mts +7 -0
  50. package/dist/esm/utils/timeout.d.mts +11 -0
  51. package/dist/esm/utils/token.d.mts +7 -0
  52. package/dist/esm/which.d.mts +8 -0
  53. package/package.json +68 -0
@@ -0,0 +1,3939 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ !function() {
4
+ __webpack_require__.n = function(module) {
5
+ var getter = module && module.__esModule ? function() {
6
+ return module['default'];
7
+ } : function() {
8
+ return module;
9
+ };
10
+ __webpack_require__.d(getter, {
11
+ a: getter
12
+ });
13
+ return getter;
14
+ };
15
+ }();
16
+ !function() {
17
+ __webpack_require__.d = function(exports1, definition) {
18
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
19
+ enumerable: true,
20
+ get: definition[key]
21
+ });
22
+ };
23
+ }();
24
+ !function() {
25
+ __webpack_require__.o = function(obj, prop) {
26
+ return Object.prototype.hasOwnProperty.call(obj, prop);
27
+ };
28
+ }();
29
+ !function() {
30
+ __webpack_require__.r = function(exports1) {
31
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
32
+ value: 'Module'
33
+ });
34
+ Object.defineProperty(exports1, '__esModule', {
35
+ value: true
36
+ });
37
+ };
38
+ }();
39
+ var __webpack_exports__ = {};
40
+ __webpack_require__.r(__webpack_exports__);
41
+ __webpack_require__.d(__webpack_exports__, {
42
+ createTimeoutError: function() {
43
+ return createTimeoutError;
44
+ },
45
+ SQLiteExecutor: function() {
46
+ return executor_SQLiteExecutor;
47
+ },
48
+ VALID_TRANSACTION_MODES: function() {
49
+ return VALID_TRANSACTION_MODES;
50
+ },
51
+ DEFAULT_STATEMENT_TIMEOUT: function() {
52
+ return DEFAULT_STATEMENT_TIMEOUT;
53
+ },
54
+ Metrics: function() {
55
+ return metrics_Metrics;
56
+ }
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(2 * 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
+ var DEFAULT_STATEMENT_TIMEOUT = 30000;
269
+ function createTimeoutError(timeout, sql) {
270
+ return new Error("SQLite statement timed out after ".concat(timeout, "ms: ").concat(normalizeSQL(sql)));
271
+ }
272
+ function toError(value) {
273
+ return value instanceof Error ? value : new Error(String(value));
274
+ }
275
+ var CHAR_QUOTE = 34;
276
+ var CHAR_BACKSLASH = 92;
277
+ var CHAR_OPEN_BRACKET = 91;
278
+ var CHAR_CLOSE_BRACKET = 93;
279
+ var CHAR_OPEN_BRACE = 123;
280
+ var CHAR_CLOSE_BRACE = 125;
281
+ var CHAR_COMMA = 44;
282
+ var CHAR_SPACE = 32;
283
+ var CHAR_TAB = 9;
284
+ var CHAR_LF = 10;
285
+ var CHAR_CR = 13;
286
+ function isWhitespaceCode(code) {
287
+ return code === CHAR_SPACE || code === CHAR_TAB || code === CHAR_LF || code === CHAR_CR;
288
+ }
289
+ function createJsonValueParser(onValue) {
290
+ return {
291
+ buffer: "",
292
+ start: -1,
293
+ readPos: 0,
294
+ nesting: 0,
295
+ inString: false,
296
+ escaped: false,
297
+ feed: function(chunk) {
298
+ this.buffer += chunk;
299
+ var consumeUntil = 0;
300
+ for(var index = this.readPos; index < this.buffer.length; index++){
301
+ var code = this.buffer.charCodeAt(index);
302
+ if (-1 === this.start) {
303
+ if (isWhitespaceCode(code)) continue;
304
+ if (code !== CHAR_OPEN_BRACKET && code !== CHAR_OPEN_BRACE) continue;
305
+ this.start = index;
306
+ this.nesting = 1;
307
+ this.inString = false;
308
+ this.escaped = false;
309
+ continue;
310
+ }
311
+ if (this.inString) {
312
+ if (this.escaped) this.escaped = false;
313
+ else if (code === CHAR_BACKSLASH) this.escaped = true;
314
+ else if (code === CHAR_QUOTE) this.inString = false;
315
+ continue;
316
+ }
317
+ if (code === CHAR_QUOTE) {
318
+ this.inString = true;
319
+ continue;
320
+ }
321
+ if (code === CHAR_OPEN_BRACKET || code === CHAR_OPEN_BRACE) {
322
+ this.nesting++;
323
+ continue;
324
+ }
325
+ if (code === CHAR_CLOSE_BRACKET || code === CHAR_CLOSE_BRACE) {
326
+ this.nesting--;
327
+ if (0 === this.nesting) {
328
+ var raw = this.buffer.slice(this.start, index + 1);
329
+ this.start = -1;
330
+ onValue(raw);
331
+ consumeUntil = index + 1;
332
+ }
333
+ }
334
+ }
335
+ if (consumeUntil > 0) {
336
+ this.buffer = this.buffer.slice(consumeUntil);
337
+ this.readPos = 0;
338
+ } else this.readPos = this.buffer.length;
339
+ },
340
+ reset: function() {
341
+ this.buffer = "";
342
+ this.start = -1;
343
+ this.readPos = 0;
344
+ this.nesting = 0;
345
+ this.inString = false;
346
+ this.escaped = false;
347
+ }
348
+ };
349
+ }
350
+ function createRowStreamParser(onRow) {
351
+ return {
352
+ buffer: "",
353
+ started: false,
354
+ finished: false,
355
+ inString: false,
356
+ escaped: false,
357
+ elementStart: -1,
358
+ elementEnd: -1,
359
+ nesting: 0,
360
+ readPos: 0,
361
+ feed: function(chunk) {
362
+ if (this.finished) return chunk;
363
+ this.buffer += chunk;
364
+ var index = this.readPos;
365
+ while(index < this.buffer.length){
366
+ var code = this.buffer.charCodeAt(index);
367
+ if (!this.started) {
368
+ if (isWhitespaceCode(code)) {
369
+ index++;
370
+ continue;
371
+ }
372
+ if (code !== CHAR_OPEN_BRACKET) {
373
+ index++;
374
+ continue;
375
+ }
376
+ this.started = true;
377
+ index++;
378
+ continue;
379
+ }
380
+ if (this.inString) {
381
+ if (this.escaped) this.escaped = false;
382
+ else if (code === CHAR_BACKSLASH) this.escaped = true;
383
+ else if (code === CHAR_QUOTE) this.inString = false;
384
+ index++;
385
+ continue;
386
+ }
387
+ if (-1 === this.elementStart) {
388
+ if (isWhitespaceCode(code) || code === CHAR_COMMA) {
389
+ index++;
390
+ continue;
391
+ }
392
+ if (code === CHAR_CLOSE_BRACKET) {
393
+ this.finished = true;
394
+ var leftover = this.buffer.slice(index + 1);
395
+ this.buffer = "";
396
+ this.readPos = 0;
397
+ return leftover;
398
+ }
399
+ this.elementStart = index;
400
+ this.elementEnd = -1;
401
+ this.nesting = code === CHAR_OPEN_BRACE || code === CHAR_OPEN_BRACKET ? 1 : 0;
402
+ this.inString = code === CHAR_QUOTE;
403
+ index++;
404
+ continue;
405
+ }
406
+ if (code === CHAR_QUOTE) {
407
+ this.inString = true;
408
+ index++;
409
+ continue;
410
+ }
411
+ if (code === CHAR_OPEN_BRACE || code === CHAR_OPEN_BRACKET) {
412
+ this.nesting++;
413
+ index++;
414
+ continue;
415
+ }
416
+ if (code === CHAR_CLOSE_BRACE || code === CHAR_CLOSE_BRACKET) {
417
+ this.nesting--;
418
+ if (0 === this.nesting) this.elementEnd = index + 1;
419
+ }
420
+ if (-1 !== this.elementEnd) {
421
+ var lookAhead = index + 1;
422
+ while(lookAhead < this.buffer.length && isWhitespaceCode(this.buffer.charCodeAt(lookAhead)))lookAhead++;
423
+ if (lookAhead < this.buffer.length) {
424
+ var delimiter = this.buffer.charCodeAt(lookAhead);
425
+ if (delimiter === CHAR_COMMA || delimiter === CHAR_CLOSE_BRACKET) {
426
+ onRow(this.buffer.slice(this.elementStart, this.elementEnd));
427
+ this.buffer = this.buffer.slice(lookAhead + 1);
428
+ this.elementStart = -1;
429
+ this.elementEnd = -1;
430
+ this.nesting = 0;
431
+ if (delimiter === CHAR_CLOSE_BRACKET) {
432
+ this.finished = true;
433
+ var tail = this.buffer;
434
+ this.buffer = "";
435
+ this.readPos = 0;
436
+ return tail;
437
+ }
438
+ index = 0;
439
+ continue;
440
+ }
441
+ }
442
+ }
443
+ index++;
444
+ }
445
+ if (this.elementStart > 0) {
446
+ this.buffer = this.buffer.slice(this.elementStart);
447
+ if (-1 !== this.elementEnd) this.elementEnd -= this.elementStart;
448
+ this.elementStart = 0;
449
+ }
450
+ this.readPos = 0 === this.elementStart ? this.buffer.length : 0;
451
+ return "";
452
+ },
453
+ reset: function() {
454
+ this.buffer = "";
455
+ this.started = false;
456
+ this.finished = false;
457
+ this.inString = false;
458
+ this.escaped = false;
459
+ this.elementStart = -1;
460
+ this.elementEnd = -1;
461
+ this.nesting = 0;
462
+ this.readPos = 0;
463
+ }
464
+ };
465
+ }
466
+ var TOKEN_COLUMN = "__sqlite_executor_token__";
467
+ var DEFAULT_BATCH_SIZE = 10;
468
+ function stream_check_private_redeclaration(obj, privateCollection) {
469
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
470
+ }
471
+ function stream_class_apply_descriptor_get(receiver, descriptor) {
472
+ if (descriptor.get) return descriptor.get.call(receiver);
473
+ return descriptor.value;
474
+ }
475
+ function stream_class_apply_descriptor_set(receiver, descriptor, value) {
476
+ if (descriptor.set) descriptor.set.call(receiver, value);
477
+ else {
478
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
479
+ descriptor.value = value;
480
+ }
481
+ }
482
+ function stream_class_call_check(instance, Constructor) {
483
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
484
+ }
485
+ function stream_class_extract_field_descriptor(receiver, privateMap, action) {
486
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
487
+ return privateMap.get(receiver);
488
+ }
489
+ function stream_class_private_field_get(receiver, privateMap) {
490
+ var descriptor = stream_class_extract_field_descriptor(receiver, privateMap, "get");
491
+ return stream_class_apply_descriptor_get(receiver, descriptor);
492
+ }
493
+ function stream_class_private_field_init(obj, privateMap, value) {
494
+ stream_check_private_redeclaration(obj, privateMap);
495
+ privateMap.set(obj, value);
496
+ }
497
+ function stream_class_private_field_set(receiver, privateMap, value) {
498
+ var descriptor = stream_class_extract_field_descriptor(receiver, privateMap, "set");
499
+ stream_class_apply_descriptor_set(receiver, descriptor, value);
500
+ return value;
501
+ }
502
+ function stream_defineProperties(target, props) {
503
+ for(var i = 0; i < props.length; i++){
504
+ var descriptor = props[i];
505
+ descriptor.enumerable = descriptor.enumerable || false;
506
+ descriptor.configurable = true;
507
+ if ("value" in descriptor) descriptor.writable = true;
508
+ Object.defineProperty(target, descriptor.key, descriptor);
509
+ }
510
+ }
511
+ function stream_create_class(Constructor, protoProps, staticProps) {
512
+ if (protoProps) stream_defineProperties(Constructor.prototype, protoProps);
513
+ if (staticProps) stream_defineProperties(Constructor, staticProps);
514
+ return Constructor;
515
+ }
516
+ function _type_of(obj) {
517
+ return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj;
518
+ }
519
+ var _computedKey;
520
+ function setupStreamParser(task) {
521
+ var valueParser = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {
522
+ feed: function() {}
523
+ };
524
+ if ("stream" !== task.kind) return null;
525
+ var parser = createRowStreamParser(function(rawRow) {
526
+ if (task.consumerError) return;
527
+ try {
528
+ var row = JSON.parse(rawRow);
529
+ if ((void 0 === row ? "undefined" : _type_of(row)) === "object" && null !== row && TOKEN_COLUMN in row) return void valueParser.feed("[".concat(rawRow, "]"));
530
+ task.onRow(row);
531
+ } catch (error) {
532
+ task.consumerError = toError(error);
533
+ }
534
+ });
535
+ return parser;
536
+ }
537
+ _computedKey = Symbol.asyncIterator;
538
+ var _buffer = /*#__PURE__*/ new WeakMap(), _done = /*#__PURE__*/ new WeakMap(), _error = /*#__PURE__*/ new WeakMap(), _pending = /*#__PURE__*/ new WeakMap();
539
+ var _computedKey1 = _computedKey;
540
+ var stream_AsyncRowBuffer = /*#__PURE__*/ function() {
541
+ "use strict";
542
+ function AsyncRowBuffer() {
543
+ stream_class_call_check(this, AsyncRowBuffer);
544
+ stream_class_private_field_init(this, _buffer, {
545
+ writable: true,
546
+ value: []
547
+ });
548
+ stream_class_private_field_init(this, _done, {
549
+ writable: true,
550
+ value: false
551
+ });
552
+ stream_class_private_field_init(this, _error, {
553
+ writable: true,
554
+ value: null
555
+ });
556
+ stream_class_private_field_init(this, _pending, {
557
+ writable: true,
558
+ value: null
559
+ });
560
+ }
561
+ stream_create_class(AsyncRowBuffer, [
562
+ {
563
+ key: "push",
564
+ value: function(row) {
565
+ if (stream_class_private_field_get(this, _pending)) {
566
+ var resolve = stream_class_private_field_get(this, _pending).resolve;
567
+ stream_class_private_field_set(this, _pending, null);
568
+ resolve({
569
+ value: row,
570
+ done: false
571
+ });
572
+ } else stream_class_private_field_get(this, _buffer).push(row);
573
+ }
574
+ },
575
+ {
576
+ key: "end",
577
+ value: function() {
578
+ stream_class_private_field_set(this, _done, true);
579
+ if (stream_class_private_field_get(this, _pending)) {
580
+ var resolve = stream_class_private_field_get(this, _pending).resolve;
581
+ stream_class_private_field_set(this, _pending, null);
582
+ resolve({
583
+ value: void 0,
584
+ done: true
585
+ });
586
+ }
587
+ }
588
+ },
589
+ {
590
+ key: "error",
591
+ value: function(err) {
592
+ stream_class_private_field_set(this, _error, err);
593
+ if (stream_class_private_field_get(this, _pending)) {
594
+ var reject = stream_class_private_field_get(this, _pending).reject;
595
+ stream_class_private_field_set(this, _pending, null);
596
+ reject(err);
597
+ }
598
+ }
599
+ },
600
+ {
601
+ key: "next",
602
+ value: function() {
603
+ var _this = this;
604
+ if (stream_class_private_field_get(this, _buffer).length > 0) return Promise.resolve({
605
+ value: stream_class_private_field_get(this, _buffer).shift(),
606
+ done: false
607
+ });
608
+ if (stream_class_private_field_get(this, _done)) return Promise.resolve({
609
+ value: void 0,
610
+ done: true
611
+ });
612
+ if (stream_class_private_field_get(this, _error)) return Promise.reject(stream_class_private_field_get(this, _error));
613
+ return new Promise(function(resolve, reject) {
614
+ stream_class_private_field_set(_this, _pending, {
615
+ resolve: resolve,
616
+ reject: reject
617
+ });
618
+ });
619
+ }
620
+ },
621
+ {
622
+ key: "return",
623
+ value: function() {
624
+ stream_class_private_field_set(this, _done, true);
625
+ if (stream_class_private_field_get(this, _pending)) {
626
+ var resolve = stream_class_private_field_get(this, _pending).resolve;
627
+ stream_class_private_field_set(this, _pending, null);
628
+ resolve({
629
+ value: void 0,
630
+ done: true
631
+ });
632
+ }
633
+ return Promise.resolve({
634
+ value: void 0,
635
+ done: true
636
+ });
637
+ }
638
+ },
639
+ {
640
+ key: _computedKey1,
641
+ value: function() {
642
+ return this;
643
+ }
644
+ }
645
+ ]);
646
+ return AsyncRowBuffer;
647
+ }();
648
+ function _define_property(obj, key, value) {
649
+ if (key in obj) Object.defineProperty(obj, key, {
650
+ value: value,
651
+ enumerable: true,
652
+ configurable: true,
653
+ writable: true
654
+ });
655
+ else obj[key] = value;
656
+ return obj;
657
+ }
658
+ function _object_spread(target) {
659
+ for(var i = 1; i < arguments.length; i++){
660
+ var source = null != arguments[i] ? arguments[i] : {};
661
+ var ownKeys = Object.keys(source);
662
+ if ("function" == typeof Object.getOwnPropertySymbols) ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
663
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
664
+ }));
665
+ ownKeys.forEach(function(key) {
666
+ _define_property(target, key, source[key]);
667
+ });
668
+ }
669
+ return target;
670
+ }
671
+ function transaction_ownKeys(object, enumerableOnly) {
672
+ var keys = Object.keys(object);
673
+ if (Object.getOwnPropertySymbols) {
674
+ var symbols = Object.getOwnPropertySymbols(object);
675
+ if (enumerableOnly) symbols = symbols.filter(function(sym) {
676
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
677
+ });
678
+ keys.push.apply(keys, symbols);
679
+ }
680
+ return keys;
681
+ }
682
+ function _object_spread_props(target, source) {
683
+ source = null != source ? source : {};
684
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
685
+ else transaction_ownKeys(Object(source)).forEach(function(key) {
686
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
687
+ });
688
+ return target;
689
+ }
690
+ var VALID_TRANSACTION_MODES = [
691
+ "DEFERRED",
692
+ "IMMEDIATE",
693
+ "EXCLUSIVE"
694
+ ];
695
+ function createTransactionHandle(scopeId, executor) {
696
+ var handle = {
697
+ execute: function(sql) {
698
+ var params = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : [], options = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
699
+ return executor.enqueue("execute", sql, params, options, scopeId);
700
+ },
701
+ query: function(sql) {
702
+ var params = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : [], options = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
703
+ return executor.enqueue("query", sql, params, options, scopeId);
704
+ },
705
+ stream: function(sql) {
706
+ var params = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : [], options = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
707
+ if (!Array.isArray(params)) throw new TypeError("params must be an array");
708
+ var buffer = new stream_AsyncRowBuffer();
709
+ executor.enqueue("stream", sql, params, _object_spread_props(_object_spread({}, options), {
710
+ onRow: function(row) {
711
+ return buffer.push(row);
712
+ }
713
+ }), scopeId).then(function() {
714
+ return buffer.end();
715
+ }, function(err) {
716
+ return buffer.error(err);
717
+ });
718
+ return buffer;
719
+ }
720
+ };
721
+ return handle;
722
+ }
723
+ var external_node_child_process_namespaceObject = require("node:child_process");
724
+ var external_node_fs_namespaceObject = require("node:fs");
725
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
726
+ var external_node_path_namespaceObject = require("node:path");
727
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
728
+ var external_node_os_namespaceObject = require("node:os");
729
+ var external_node_os_default = /*#__PURE__*/ __webpack_require__.n(external_node_os_namespaceObject);
730
+ var isWindows = "win32" === external_node_os_default().platform();
731
+ function isExecutable(filePath) {
732
+ try {
733
+ if (isWindows) return external_node_fs_default().statSync(filePath).isFile();
734
+ external_node_fs_default().accessSync(filePath, external_node_fs_default().constants.X_OK);
735
+ return true;
736
+ } catch (e) {
737
+ return false;
738
+ }
739
+ }
740
+ function getPathExts() {
741
+ if (!isWindows) return [
742
+ ""
743
+ ];
744
+ var ext = process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM;.PS1";
745
+ return ext.split(";").map(function(e) {
746
+ return e.toLowerCase();
747
+ });
748
+ }
749
+ function which(command) {
750
+ if (!command) return null;
751
+ var pathExts = getPathExts();
752
+ if (command.includes(external_node_path_default().sep)) {
753
+ var fullPath = external_node_path_default().resolve(command);
754
+ if (!isWindows) return isExecutable(fullPath) ? fullPath : null;
755
+ if (external_node_path_default().extname(fullPath)) return isExecutable(fullPath) ? fullPath : null;
756
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
757
+ try {
758
+ for(var _iterator = pathExts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
759
+ var ext = _step.value;
760
+ var file = fullPath + ext;
761
+ if (isExecutable(file)) return file;
762
+ }
763
+ } catch (err) {
764
+ _didIteratorError = true;
765
+ _iteratorError = err;
766
+ } finally{
767
+ try {
768
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
769
+ } finally{
770
+ if (_didIteratorError) throw _iteratorError;
771
+ }
772
+ }
773
+ return null;
774
+ }
775
+ var envPath = process.env.PATH || "";
776
+ var pathDirs = envPath.split(external_node_path_default().delimiter);
777
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
778
+ try {
779
+ for(var _iterator1 = pathDirs[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
780
+ var dir = _step1.value;
781
+ if (dir) if (isWindows) {
782
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
783
+ try {
784
+ for(var _iterator2 = pathExts[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
785
+ var ext1 = _step2.value;
786
+ var file1 = external_node_path_default().join(dir, command + ext1);
787
+ if (isExecutable(file1)) return file1;
788
+ }
789
+ } catch (err) {
790
+ _didIteratorError2 = true;
791
+ _iteratorError2 = err;
792
+ } finally{
793
+ try {
794
+ if (!_iteratorNormalCompletion2 && null != _iterator2["return"]) _iterator2["return"]();
795
+ } finally{
796
+ if (_didIteratorError2) throw _iteratorError2;
797
+ }
798
+ }
799
+ } else {
800
+ var file2 = external_node_path_default().join(dir, command);
801
+ if (isExecutable(file2)) return file2;
802
+ }
803
+ }
804
+ } catch (err) {
805
+ _didIteratorError1 = true;
806
+ _iteratorError1 = err;
807
+ } finally{
808
+ try {
809
+ if (!_iteratorNormalCompletion1 && null != _iterator1["return"]) _iterator1["return"]();
810
+ } finally{
811
+ if (_didIteratorError1) throw _iteratorError1;
812
+ }
813
+ }
814
+ return null;
815
+ }
816
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
817
+ try {
818
+ var info = gen[key](arg);
819
+ var value = info.value;
820
+ } catch (error) {
821
+ reject(error);
822
+ return;
823
+ }
824
+ if (info.done) resolve(value);
825
+ else Promise.resolve(value).then(_next, _throw);
826
+ }
827
+ function _async_to_generator(fn) {
828
+ return function() {
829
+ var self = this, args = arguments;
830
+ return new Promise(function(resolve, reject) {
831
+ var gen = fn.apply(self, args);
832
+ function _next(value) {
833
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
834
+ }
835
+ function _throw(err) {
836
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
837
+ }
838
+ _next(void 0);
839
+ });
840
+ };
841
+ }
842
+ function process_check_private_redeclaration(obj, privateCollection) {
843
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
844
+ }
845
+ function process_class_apply_descriptor_get(receiver, descriptor) {
846
+ if (descriptor.get) return descriptor.get.call(receiver);
847
+ return descriptor.value;
848
+ }
849
+ function process_class_apply_descriptor_set(receiver, descriptor, value) {
850
+ if (descriptor.set) descriptor.set.call(receiver, value);
851
+ else {
852
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
853
+ descriptor.value = value;
854
+ }
855
+ }
856
+ function process_class_call_check(instance, Constructor) {
857
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
858
+ }
859
+ function process_class_extract_field_descriptor(receiver, privateMap, action) {
860
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
861
+ return privateMap.get(receiver);
862
+ }
863
+ function process_class_private_field_get(receiver, privateMap) {
864
+ var descriptor = process_class_extract_field_descriptor(receiver, privateMap, "get");
865
+ return process_class_apply_descriptor_get(receiver, descriptor);
866
+ }
867
+ function process_class_private_field_init(obj, privateMap, value) {
868
+ process_check_private_redeclaration(obj, privateMap);
869
+ privateMap.set(obj, value);
870
+ }
871
+ function process_class_private_field_set(receiver, privateMap, value) {
872
+ var descriptor = process_class_extract_field_descriptor(receiver, privateMap, "set");
873
+ process_class_apply_descriptor_set(receiver, descriptor, value);
874
+ return value;
875
+ }
876
+ function process_defineProperties(target, props) {
877
+ for(var i = 0; i < props.length; i++){
878
+ var descriptor = props[i];
879
+ descriptor.enumerable = descriptor.enumerable || false;
880
+ descriptor.configurable = true;
881
+ if ("value" in descriptor) descriptor.writable = true;
882
+ Object.defineProperty(target, descriptor.key, descriptor);
883
+ }
884
+ }
885
+ function process_create_class(Constructor, protoProps, staticProps) {
886
+ if (protoProps) process_defineProperties(Constructor.prototype, protoProps);
887
+ if (staticProps) process_defineProperties(Constructor, staticProps);
888
+ return Constructor;
889
+ }
890
+ function _ts_generator(thisArg, body) {
891
+ var f, y, t, _ = {
892
+ label: 0,
893
+ sent: function() {
894
+ if (1 & t[0]) throw t[1];
895
+ return t[1];
896
+ },
897
+ trys: [],
898
+ ops: []
899
+ }, g = Object.create(("function" == typeof Iterator ? Iterator : Object).prototype);
900
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), "function" == typeof Symbol && (g[Symbol.iterator] = function() {
901
+ return this;
902
+ }), g;
903
+ function verb(n) {
904
+ return function(v1) {
905
+ return step([
906
+ n,
907
+ v1
908
+ ]);
909
+ };
910
+ }
911
+ function step(op) {
912
+ if (f) throw new TypeError("Generator is already executing.");
913
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
914
+ if (f = 1, y && (t = 2 & op[0] ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
915
+ if (y = 0, t) op = [
916
+ 2 & op[0],
917
+ t.value
918
+ ];
919
+ switch(op[0]){
920
+ case 0:
921
+ case 1:
922
+ t = op;
923
+ break;
924
+ case 4:
925
+ _.label++;
926
+ return {
927
+ value: op[1],
928
+ done: false
929
+ };
930
+ case 5:
931
+ _.label++;
932
+ y = op[1];
933
+ op = [
934
+ 0
935
+ ];
936
+ continue;
937
+ case 7:
938
+ op = _.ops.pop();
939
+ _.trys.pop();
940
+ continue;
941
+ default:
942
+ if (t = _.trys, !(t = t.length > 0 && t[t.length - 1]) && (6 === op[0] || 2 === op[0])) {
943
+ _ = 0;
944
+ continue;
945
+ }
946
+ if (3 === op[0] && (!t || op[1] > t[0] && op[1] < t[3])) {
947
+ _.label = op[1];
948
+ break;
949
+ }
950
+ if (6 === op[0] && _.label < t[1]) {
951
+ _.label = t[1];
952
+ t = op;
953
+ break;
954
+ }
955
+ if (t && _.label < t[2]) {
956
+ _.label = t[2];
957
+ _.ops.push(op);
958
+ break;
959
+ }
960
+ if (t[2]) _.ops.pop();
961
+ _.trys.pop();
962
+ continue;
963
+ }
964
+ op = body.call(thisArg, _);
965
+ } catch (e) {
966
+ op = [
967
+ 6,
968
+ e
969
+ ];
970
+ y = 0;
971
+ } finally{
972
+ f = t = 0;
973
+ }
974
+ if (5 & op[0]) throw op[1];
975
+ return {
976
+ value: op[0] ? op[1] : void 0,
977
+ done: true
978
+ };
979
+ }
980
+ }
981
+ var GRACEFUL_SHUTDOWN_TIMEOUT = 5000;
982
+ var _binary = /*#__PURE__*/ new WeakMap(), _database = /*#__PURE__*/ new WeakMap(), _proc = /*#__PURE__*/ new WeakMap(), _initMode = /*#__PURE__*/ new WeakMap(), _draining = /*#__PURE__*/ new WeakMap();
983
+ var process_ProcessManager = /*#__PURE__*/ function() {
984
+ "use strict";
985
+ function ProcessManager() {
986
+ 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;
987
+ process_class_call_check(this, ProcessManager);
988
+ process_class_private_field_init(this, _binary, {
989
+ writable: true,
990
+ value: void 0
991
+ });
992
+ process_class_private_field_init(this, _database, {
993
+ writable: true,
994
+ value: void 0
995
+ });
996
+ process_class_private_field_init(this, _proc, {
997
+ writable: true,
998
+ value: null
999
+ });
1000
+ process_class_private_field_init(this, _initMode, {
1001
+ writable: true,
1002
+ value: void 0
1003
+ });
1004
+ process_class_private_field_init(this, _draining, {
1005
+ writable: true,
1006
+ value: false
1007
+ });
1008
+ var _which;
1009
+ process_class_private_field_set(this, _binary, null != (_which = which(binary)) ? _which : binary);
1010
+ process_class_private_field_set(this, _database, database);
1011
+ process_class_private_field_set(this, _initMode, initMode);
1012
+ }
1013
+ process_create_class(ProcessManager, [
1014
+ {
1015
+ key: "binary",
1016
+ get: function() {
1017
+ return process_class_private_field_get(this, _binary);
1018
+ }
1019
+ },
1020
+ {
1021
+ key: "process",
1022
+ get: function() {
1023
+ return process_class_private_field_get(this, _proc);
1024
+ }
1025
+ },
1026
+ {
1027
+ key: "start",
1028
+ value: function() {
1029
+ var _proc_stdin, _proc_stdout, _proc_stderr;
1030
+ if (!process_class_private_field_get(this, _binary)) throw new Error("sqlite3 binary path is empty. Provide a valid --binary / binary option.");
1031
+ 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."));
1032
+ var args = [
1033
+ "-json"
1034
+ ];
1035
+ if (process_class_private_field_get(this, _database)) args.push(process_class_private_field_get(this, _database));
1036
+ if (process_class_private_field_get(this, _database) && ":memory:" !== process_class_private_field_get(this, _database) && "wal" === process_class_private_field_get(this, _initMode)) {
1037
+ args.push("-cmd", "PRAGMA journal_mode=WAL;");
1038
+ args.push("-cmd", "PRAGMA busy_timeout=5000;");
1039
+ }
1040
+ var proc = (0, external_node_child_process_namespaceObject.spawn)(process_class_private_field_get(this, _binary), args, {
1041
+ stdio: "pipe",
1042
+ shell: false,
1043
+ windowsHide: true
1044
+ });
1045
+ null == (_proc_stdin = proc.stdin) || _proc_stdin.setDefaultEncoding("utf-8");
1046
+ null == (_proc_stdout = proc.stdout) || _proc_stdout.setEncoding("utf-8");
1047
+ null == (_proc_stderr = proc.stderr) || _proc_stderr.setEncoding("utf-8");
1048
+ process_class_private_field_set(this, _proc, proc);
1049
+ return proc;
1050
+ }
1051
+ },
1052
+ {
1053
+ key: "write",
1054
+ value: function(data) {
1055
+ var _this = this;
1056
+ var _$_class_private_field_get;
1057
+ var stream = null == (_$_class_private_field_get = process_class_private_field_get(this, _proc)) ? void 0 : _$_class_private_field_get.stdin;
1058
+ if (!stream) return;
1059
+ if (!stream.write(data) && !process_class_private_field_get(this, _draining)) {
1060
+ process_class_private_field_set(this, _draining, true);
1061
+ stream.once("drain", function() {
1062
+ process_class_private_field_set(_this, _draining, false);
1063
+ });
1064
+ }
1065
+ }
1066
+ },
1067
+ {
1068
+ key: "gracefulShutdown",
1069
+ value: function() {
1070
+ var _this = this;
1071
+ return _async_to_generator(function() {
1072
+ var proc, timer, _proc_stdin;
1073
+ return _ts_generator(this, function(_state) {
1074
+ switch(_state.label){
1075
+ case 0:
1076
+ proc = process_class_private_field_get(_this, _proc);
1077
+ if (!proc) return [
1078
+ 2
1079
+ ];
1080
+ timer = setTimeout(function() {
1081
+ _this.kill();
1082
+ }, GRACEFUL_SHUTDOWN_TIMEOUT);
1083
+ _state.label = 1;
1084
+ case 1:
1085
+ _state.trys.push([
1086
+ 1,
1087
+ 3,
1088
+ 4,
1089
+ 5
1090
+ ]);
1091
+ null == (_proc_stdin = proc.stdin) || _proc_stdin.write(".quit\n");
1092
+ return [
1093
+ 4,
1094
+ (0, external_node_events_namespaceObject.once)(proc, "close")
1095
+ ];
1096
+ case 2:
1097
+ _state.sent();
1098
+ return [
1099
+ 3,
1100
+ 5
1101
+ ];
1102
+ case 3:
1103
+ _state.sent();
1104
+ return [
1105
+ 3,
1106
+ 5
1107
+ ];
1108
+ case 4:
1109
+ clearTimeout(timer);
1110
+ return [
1111
+ 7
1112
+ ];
1113
+ case 5:
1114
+ return [
1115
+ 2
1116
+ ];
1117
+ }
1118
+ });
1119
+ })();
1120
+ }
1121
+ },
1122
+ {
1123
+ key: "kill",
1124
+ value: function() {
1125
+ var _proc_stdout, _proc_stderr, _proc_stdin;
1126
+ var proc = process_class_private_field_get(this, _proc);
1127
+ if (!proc) return null;
1128
+ process_class_private_field_set(this, _proc, null);
1129
+ process_class_private_field_set(this, _draining, false);
1130
+ null == (_proc_stdout = proc.stdout) || _proc_stdout.removeAllListeners();
1131
+ null == (_proc_stderr = proc.stderr) || _proc_stderr.removeAllListeners();
1132
+ proc.removeAllListeners();
1133
+ null == (_proc_stdin = proc.stdin) || _proc_stdin.destroy();
1134
+ proc.kill();
1135
+ return proc;
1136
+ }
1137
+ }
1138
+ ]);
1139
+ return ProcessManager;
1140
+ }();
1141
+ var _counter = 0;
1142
+ var _PREFIX = "__executor_end__";
1143
+ var _PID36 = process.pid.toString(36);
1144
+ function generateToken() {
1145
+ return "".concat(_PREFIX).concat((_counter++).toString(36), "_").concat(_PID36);
1146
+ }
1147
+ function escape_type_of(obj) {
1148
+ return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj;
1149
+ }
1150
+ function escapeValue(value) {
1151
+ if ("string" == typeof value) return "'".concat(value.replace(/'/g, "''"), "'");
1152
+ if (null == value) return "NULL";
1153
+ if ("number" == typeof value || (void 0 === value ? "undefined" : escape_type_of(value)) === "bigint") return String(value);
1154
+ if ("boolean" == typeof value) return value ? "TRUE" : "FALSE";
1155
+ if (value instanceof Date) return "'".concat(value.toISOString(), "'");
1156
+ throw new TypeError("Unsupported parameter type: ".concat(void 0 === value ? "undefined" : escape_type_of(value)));
1157
+ }
1158
+ var _interpCache = new lruCache_LRUCache({
1159
+ maxSize: 256,
1160
+ maxKeyLength: 4096
1161
+ });
1162
+ function _parseTemplate(sql) {
1163
+ var segments = [];
1164
+ var segStart = 0;
1165
+ var state = STATE_NORMAL;
1166
+ var stateStartPos = -1;
1167
+ for(var pos = 0; pos < sql.length; pos++){
1168
+ var code = sql.charCodeAt(pos);
1169
+ if (state === STATE_NORMAL) {
1170
+ if (code === CC_SINGLE_QUOTE) {
1171
+ state = STATE_SINGLE_QUOTE;
1172
+ stateStartPos = pos;
1173
+ continue;
1174
+ }
1175
+ if (code === CC_DOUBLE_QUOTE) {
1176
+ state = STATE_DOUBLE_QUOTE;
1177
+ stateStartPos = pos;
1178
+ continue;
1179
+ }
1180
+ if (code === CC_DASH && sql.charCodeAt(pos + 1) === CC_DASH) {
1181
+ state = STATE_LINE_COMMENT;
1182
+ pos++;
1183
+ continue;
1184
+ }
1185
+ if (code === CC_SLASH && sql.charCodeAt(pos + 1) === CC_STAR) {
1186
+ state = STATE_BLOCK_COMMENT;
1187
+ stateStartPos = pos;
1188
+ pos++;
1189
+ continue;
1190
+ }
1191
+ if (code === CC_QUESTION) {
1192
+ segments.push(sql.slice(segStart, pos));
1193
+ segStart = pos + 1;
1194
+ }
1195
+ continue;
1196
+ }
1197
+ if (state === STATE_SINGLE_QUOTE) {
1198
+ if (code === CC_SINGLE_QUOTE) {
1199
+ if (sql.charCodeAt(pos + 1) === CC_SINGLE_QUOTE) {
1200
+ pos++;
1201
+ continue;
1202
+ }
1203
+ state = STATE_NORMAL;
1204
+ stateStartPos = -1;
1205
+ }
1206
+ continue;
1207
+ }
1208
+ if (state === STATE_DOUBLE_QUOTE) {
1209
+ if (code === CC_DOUBLE_QUOTE) {
1210
+ if (sql.charCodeAt(pos + 1) === CC_DOUBLE_QUOTE) {
1211
+ pos++;
1212
+ continue;
1213
+ }
1214
+ state = STATE_NORMAL;
1215
+ stateStartPos = -1;
1216
+ }
1217
+ continue;
1218
+ }
1219
+ if (state === STATE_LINE_COMMENT) {
1220
+ if (code === CC_NEWLINE) state = STATE_NORMAL;
1221
+ continue;
1222
+ }
1223
+ if (state === STATE_BLOCK_COMMENT) {
1224
+ if (code === CC_STAR && sql.charCodeAt(pos + 1) === CC_SLASH) {
1225
+ pos++;
1226
+ state = STATE_NORMAL;
1227
+ stateStartPos = -1;
1228
+ }
1229
+ }
1230
+ }
1231
+ if (state === STATE_SINGLE_QUOTE) throw new Error("Unterminated single-quoted string starting at position ".concat(stateStartPos + 1));
1232
+ if (state === STATE_DOUBLE_QUOTE) throw new Error("Unterminated double-quoted identifier/string starting at position ".concat(stateStartPos + 1));
1233
+ if (state === STATE_BLOCK_COMMENT) throw new Error("Unterminated block comment starting at position ".concat(stateStartPos + 1));
1234
+ segments.push(sql.slice(segStart));
1235
+ return {
1236
+ segments: segments,
1237
+ paramCount: segments.length - 1
1238
+ };
1239
+ }
1240
+ function interpolateSQL(sql, params) {
1241
+ if (!sql.includes("?")) {
1242
+ if (params.length > 0) throw new Error("Too many parameters provided");
1243
+ return sql;
1244
+ }
1245
+ var template = _interpCache.get(sql);
1246
+ if (void 0 === template) {
1247
+ template = _parseTemplate(sql);
1248
+ _interpCache.set(sql, template);
1249
+ }
1250
+ var segments = template.segments, paramCount = template.paramCount;
1251
+ if (params.length < paramCount) throw new Error("Too few parameters provided");
1252
+ if (params.length > paramCount) throw new Error("Too many parameters provided");
1253
+ if (0 === paramCount) return segments[0];
1254
+ var parts = [
1255
+ segments[0]
1256
+ ];
1257
+ for(var i = 0; i < params.length; i++){
1258
+ parts.push(escapeValue(params[i]));
1259
+ parts.push(segments[i + 1]);
1260
+ }
1261
+ return parts.join("");
1262
+ }
1263
+ var READ_ONLY_KINDS = new Set([
1264
+ "SELECT",
1265
+ "WITH",
1266
+ "VALUES",
1267
+ "EXPLAIN"
1268
+ ]);
1269
+ var _classifyCache = new lruCache_LRUCache({
1270
+ maxSize: 256,
1271
+ maxKeyLength: 4096
1272
+ });
1273
+ function classifySingle(stmt) {
1274
+ var trimmed = stmt.trim();
1275
+ if (0 === trimmed.length) return "write";
1276
+ var kind = trimmed.split(/\s+/)[0].toUpperCase();
1277
+ return READ_ONLY_KINDS.has(kind) ? "read" : "write";
1278
+ }
1279
+ function classifySQL(sql) {
1280
+ if ("string" != typeof sql || 0 === sql.trim().length) return "write";
1281
+ var cached = _classifyCache.get(sql);
1282
+ if (void 0 !== cached) return cached;
1283
+ var trimmed = sql.trim();
1284
+ var result;
1285
+ if (trimmed.includes(";")) {
1286
+ var stmts = trimmed.split(";");
1287
+ result = "read";
1288
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1289
+ try {
1290
+ for(var _iterator = stmts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1291
+ var stmt = _step.value;
1292
+ if ("write" === classifySingle(stmt)) {
1293
+ result = "write";
1294
+ break;
1295
+ }
1296
+ }
1297
+ } catch (err) {
1298
+ _didIteratorError = true;
1299
+ _iteratorError = err;
1300
+ } finally{
1301
+ try {
1302
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
1303
+ } finally{
1304
+ if (_didIteratorError) throw _iteratorError;
1305
+ }
1306
+ }
1307
+ } else result = classifySingle(trimmed);
1308
+ _classifyCache.set(sql, result);
1309
+ return result;
1310
+ }
1311
+ function queue_check_private_redeclaration(obj, privateCollection) {
1312
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
1313
+ }
1314
+ function queue_class_apply_descriptor_get(receiver, descriptor) {
1315
+ if (descriptor.get) return descriptor.get.call(receiver);
1316
+ return descriptor.value;
1317
+ }
1318
+ function queue_class_apply_descriptor_set(receiver, descriptor, value) {
1319
+ if (descriptor.set) descriptor.set.call(receiver, value);
1320
+ else {
1321
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
1322
+ descriptor.value = value;
1323
+ }
1324
+ }
1325
+ function _class_apply_descriptor_update(receiver, descriptor) {
1326
+ if (descriptor.set) {
1327
+ if (!descriptor.get) throw new TypeError("attempted to read set only private field");
1328
+ if (!("__destrWrapper" in descriptor)) descriptor.__destrWrapper = {
1329
+ set value (v){
1330
+ descriptor.set.call(receiver, v);
1331
+ },
1332
+ get value () {
1333
+ return descriptor.get.call(receiver);
1334
+ }
1335
+ };
1336
+ return descriptor.__destrWrapper;
1337
+ }
1338
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
1339
+ return descriptor;
1340
+ }
1341
+ function queue_class_call_check(instance, Constructor) {
1342
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
1343
+ }
1344
+ function queue_class_extract_field_descriptor(receiver, privateMap, action) {
1345
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
1346
+ return privateMap.get(receiver);
1347
+ }
1348
+ function queue_class_private_field_get(receiver, privateMap) {
1349
+ var descriptor = queue_class_extract_field_descriptor(receiver, privateMap, "get");
1350
+ return queue_class_apply_descriptor_get(receiver, descriptor);
1351
+ }
1352
+ function queue_class_private_field_init(obj, privateMap, value) {
1353
+ queue_check_private_redeclaration(obj, privateMap);
1354
+ privateMap.set(obj, value);
1355
+ }
1356
+ function queue_class_private_field_set(receiver, privateMap, value) {
1357
+ var descriptor = queue_class_extract_field_descriptor(receiver, privateMap, "set");
1358
+ queue_class_apply_descriptor_set(receiver, descriptor, value);
1359
+ return value;
1360
+ }
1361
+ function _class_private_field_update(receiver, privateMap) {
1362
+ var descriptor = queue_class_extract_field_descriptor(receiver, privateMap, "update");
1363
+ return _class_apply_descriptor_update(receiver, descriptor);
1364
+ }
1365
+ function _class_private_method_get(receiver, privateSet, fn) {
1366
+ if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
1367
+ return fn;
1368
+ }
1369
+ function _class_private_method_init(obj, privateSet) {
1370
+ queue_check_private_redeclaration(obj, privateSet);
1371
+ privateSet.add(obj);
1372
+ }
1373
+ function queue_defineProperties(target, props) {
1374
+ for(var i = 0; i < props.length; i++){
1375
+ var descriptor = props[i];
1376
+ descriptor.enumerable = descriptor.enumerable || false;
1377
+ descriptor.configurable = true;
1378
+ if ("value" in descriptor) descriptor.writable = true;
1379
+ Object.defineProperty(target, descriptor.key, descriptor);
1380
+ }
1381
+ }
1382
+ function queue_create_class(Constructor, protoProps, staticProps) {
1383
+ if (protoProps) queue_defineProperties(Constructor.prototype, protoProps);
1384
+ if (staticProps) queue_defineProperties(Constructor, staticProps);
1385
+ return Constructor;
1386
+ }
1387
+ function queue_ts_generator(thisArg, body) {
1388
+ var f, y, t, _ = {
1389
+ label: 0,
1390
+ sent: function() {
1391
+ if (1 & t[0]) throw t[1];
1392
+ return t[1];
1393
+ },
1394
+ trys: [],
1395
+ ops: []
1396
+ }, g = Object.create(("function" == typeof Iterator ? Iterator : Object).prototype);
1397
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), "function" == typeof Symbol && (g[Symbol.iterator] = function() {
1398
+ return this;
1399
+ }), g;
1400
+ function verb(n) {
1401
+ return function(v1) {
1402
+ return step([
1403
+ n,
1404
+ v1
1405
+ ]);
1406
+ };
1407
+ }
1408
+ function step(op) {
1409
+ if (f) throw new TypeError("Generator is already executing.");
1410
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
1411
+ if (f = 1, y && (t = 2 & op[0] ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1412
+ if (y = 0, t) op = [
1413
+ 2 & op[0],
1414
+ t.value
1415
+ ];
1416
+ switch(op[0]){
1417
+ case 0:
1418
+ case 1:
1419
+ t = op;
1420
+ break;
1421
+ case 4:
1422
+ _.label++;
1423
+ return {
1424
+ value: op[1],
1425
+ done: false
1426
+ };
1427
+ case 5:
1428
+ _.label++;
1429
+ y = op[1];
1430
+ op = [
1431
+ 0
1432
+ ];
1433
+ continue;
1434
+ case 7:
1435
+ op = _.ops.pop();
1436
+ _.trys.pop();
1437
+ continue;
1438
+ default:
1439
+ if (t = _.trys, !(t = t.length > 0 && t[t.length - 1]) && (6 === op[0] || 2 === op[0])) {
1440
+ _ = 0;
1441
+ continue;
1442
+ }
1443
+ if (3 === op[0] && (!t || op[1] > t[0] && op[1] < t[3])) {
1444
+ _.label = op[1];
1445
+ break;
1446
+ }
1447
+ if (6 === op[0] && _.label < t[1]) {
1448
+ _.label = t[1];
1449
+ t = op;
1450
+ break;
1451
+ }
1452
+ if (t && _.label < t[2]) {
1453
+ _.label = t[2];
1454
+ _.ops.push(op);
1455
+ break;
1456
+ }
1457
+ if (t[2]) _.ops.pop();
1458
+ _.trys.pop();
1459
+ continue;
1460
+ }
1461
+ op = body.call(thisArg, _);
1462
+ } catch (e) {
1463
+ op = [
1464
+ 6,
1465
+ e
1466
+ ];
1467
+ y = 0;
1468
+ } finally{
1469
+ f = t = 0;
1470
+ }
1471
+ if (5 & op[0]) throw op[1];
1472
+ return {
1473
+ value: op[0] ? op[1] : void 0,
1474
+ done: true
1475
+ };
1476
+ }
1477
+ }
1478
+ var queue_computedKey;
1479
+ var INITIAL_CAPACITY = 16;
1480
+ var SHRINK_THRESHOLD = 256;
1481
+ queue_computedKey = Symbol.iterator;
1482
+ var _items = /*#__PURE__*/ new WeakMap(), _head = /*#__PURE__*/ new WeakMap(), _tail = /*#__PURE__*/ new WeakMap(), _size = /*#__PURE__*/ new WeakMap(), _mask = /*#__PURE__*/ new WeakMap(), _grow = /*#__PURE__*/ new WeakSet(), _shrinkIfNeeded = /*#__PURE__*/ new WeakSet();
1483
+ var queue_computedKey1 = queue_computedKey;
1484
+ var queue_Queue = /*#__PURE__*/ function() {
1485
+ "use strict";
1486
+ function Queue() {
1487
+ queue_class_call_check(this, Queue);
1488
+ _class_private_method_init(this, _grow);
1489
+ _class_private_method_init(this, _shrinkIfNeeded);
1490
+ queue_class_private_field_init(this, _items, {
1491
+ writable: true,
1492
+ value: new Array(INITIAL_CAPACITY)
1493
+ });
1494
+ queue_class_private_field_init(this, _head, {
1495
+ writable: true,
1496
+ value: 0
1497
+ });
1498
+ queue_class_private_field_init(this, _tail, {
1499
+ writable: true,
1500
+ value: 0
1501
+ });
1502
+ queue_class_private_field_init(this, _size, {
1503
+ writable: true,
1504
+ value: 0
1505
+ });
1506
+ queue_class_private_field_init(this, _mask, {
1507
+ writable: true,
1508
+ value: INITIAL_CAPACITY - 1
1509
+ });
1510
+ }
1511
+ queue_create_class(Queue, [
1512
+ {
1513
+ key: "enqueue",
1514
+ value: function(value) {
1515
+ 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);
1516
+ queue_class_private_field_get(this, _items)[queue_class_private_field_get(this, _tail)] = value;
1517
+ queue_class_private_field_set(this, _tail, queue_class_private_field_get(this, _tail) + 1 & queue_class_private_field_get(this, _mask));
1518
+ _class_private_field_update(this, _size).value++;
1519
+ }
1520
+ },
1521
+ {
1522
+ key: "dequeue",
1523
+ value: function() {
1524
+ if (0 === queue_class_private_field_get(this, _size)) return null;
1525
+ var value = queue_class_private_field_get(this, _items)[queue_class_private_field_get(this, _head)];
1526
+ queue_class_private_field_get(this, _items)[queue_class_private_field_get(this, _head)] = void 0;
1527
+ queue_class_private_field_set(this, _head, queue_class_private_field_get(this, _head) + 1 & queue_class_private_field_get(this, _mask));
1528
+ _class_private_field_update(this, _size).value--;
1529
+ return value;
1530
+ }
1531
+ },
1532
+ {
1533
+ key: "clear",
1534
+ value: function() {
1535
+ queue_class_private_field_get(this, _items).fill(void 0);
1536
+ queue_class_private_field_set(this, _head, 0);
1537
+ queue_class_private_field_set(this, _tail, 0);
1538
+ queue_class_private_field_set(this, _size, 0);
1539
+ _class_private_method_get(this, _shrinkIfNeeded, shrinkIfNeeded).call(this);
1540
+ }
1541
+ },
1542
+ {
1543
+ key: "remove",
1544
+ value: function(value) {
1545
+ for(var i = 0; i < queue_class_private_field_get(this, _size); i++){
1546
+ var idx = queue_class_private_field_get(this, _head) + i & queue_class_private_field_get(this, _mask);
1547
+ if (queue_class_private_field_get(this, _items)[idx] === value) {
1548
+ for(var j = i; j < queue_class_private_field_get(this, _size) - 1; j++){
1549
+ var curr = queue_class_private_field_get(this, _head) + j & queue_class_private_field_get(this, _mask);
1550
+ var next = queue_class_private_field_get(this, _head) + j + 1 & queue_class_private_field_get(this, _mask);
1551
+ queue_class_private_field_get(this, _items)[curr] = queue_class_private_field_get(this, _items)[next];
1552
+ }
1553
+ queue_class_private_field_set(this, _tail, queue_class_private_field_get(this, _tail) - 1 & queue_class_private_field_get(this, _mask));
1554
+ queue_class_private_field_get(this, _items)[queue_class_private_field_get(this, _tail)] = void 0;
1555
+ _class_private_field_update(this, _size).value--;
1556
+ return true;
1557
+ }
1558
+ }
1559
+ return false;
1560
+ }
1561
+ },
1562
+ {
1563
+ key: "find",
1564
+ value: function(predicate) {
1565
+ for(var i = 0; i < queue_class_private_field_get(this, _size); i++){
1566
+ var value = queue_class_private_field_get(this, _items)[queue_class_private_field_get(this, _head) + i & queue_class_private_field_get(this, _mask)];
1567
+ if (predicate(value)) return value;
1568
+ }
1569
+ return null;
1570
+ }
1571
+ },
1572
+ {
1573
+ key: "toArray",
1574
+ value: function() {
1575
+ var result = new Array(queue_class_private_field_get(this, _size));
1576
+ for(var i = 0; i < queue_class_private_field_get(this, _size); i++)result[i] = queue_class_private_field_get(this, _items)[queue_class_private_field_get(this, _head) + i & queue_class_private_field_get(this, _mask)];
1577
+ return result;
1578
+ }
1579
+ },
1580
+ {
1581
+ key: "values",
1582
+ value: function() {
1583
+ var i;
1584
+ return queue_ts_generator(this, function(_state) {
1585
+ switch(_state.label){
1586
+ case 0:
1587
+ i = 0;
1588
+ _state.label = 1;
1589
+ case 1:
1590
+ if (!(i < queue_class_private_field_get(this, _size))) return [
1591
+ 3,
1592
+ 4
1593
+ ];
1594
+ return [
1595
+ 4,
1596
+ queue_class_private_field_get(this, _items)[queue_class_private_field_get(this, _head) + i & queue_class_private_field_get(this, _mask)]
1597
+ ];
1598
+ case 2:
1599
+ _state.sent();
1600
+ _state.label = 3;
1601
+ case 3:
1602
+ i++;
1603
+ return [
1604
+ 3,
1605
+ 1
1606
+ ];
1607
+ case 4:
1608
+ return [
1609
+ 2
1610
+ ];
1611
+ }
1612
+ });
1613
+ }
1614
+ },
1615
+ {
1616
+ key: "peek",
1617
+ value: function() {
1618
+ return queue_class_private_field_get(this, _size) > 0 ? queue_class_private_field_get(this, _items)[queue_class_private_field_get(this, _head)] : null;
1619
+ }
1620
+ },
1621
+ {
1622
+ key: "prependAll",
1623
+ value: function(other) {
1624
+ if (other.isEmpty()) return;
1625
+ if (0 === queue_class_private_field_get(this, _size)) {
1626
+ var tmpItems = queue_class_private_field_get(this, _items);
1627
+ var tmpMask = queue_class_private_field_get(this, _mask);
1628
+ queue_class_private_field_set(this, _items, queue_class_private_field_get(other, _items));
1629
+ queue_class_private_field_set(this, _head, queue_class_private_field_get(other, _head));
1630
+ queue_class_private_field_set(this, _tail, queue_class_private_field_get(other, _tail));
1631
+ queue_class_private_field_set(this, _size, queue_class_private_field_get(other, _size));
1632
+ queue_class_private_field_set(this, _mask, queue_class_private_field_get(other, _mask));
1633
+ queue_class_private_field_set(other, _items, tmpItems);
1634
+ queue_class_private_field_set(other, _head, 0);
1635
+ queue_class_private_field_set(other, _tail, 0);
1636
+ queue_class_private_field_set(other, _size, 0);
1637
+ queue_class_private_field_set(other, _mask, tmpMask);
1638
+ return;
1639
+ }
1640
+ var totalSize = queue_class_private_field_get(this, _size) + queue_class_private_field_get(other, _size);
1641
+ var newCap = queue_class_private_field_get(this, _items).length;
1642
+ while(newCap < totalSize)newCap *= 2;
1643
+ var newItems = new Array(newCap);
1644
+ var writeIdx = 0;
1645
+ for(var i = 0; i < queue_class_private_field_get(other, _size); i++)newItems[writeIdx++] = queue_class_private_field_get(other, _items)[queue_class_private_field_get(other, _head) + i & queue_class_private_field_get(other, _mask)];
1646
+ for(var i1 = 0; i1 < queue_class_private_field_get(this, _size); i1++)newItems[writeIdx++] = queue_class_private_field_get(this, _items)[queue_class_private_field_get(this, _head) + i1 & queue_class_private_field_get(this, _mask)];
1647
+ queue_class_private_field_set(this, _items, newItems);
1648
+ queue_class_private_field_set(this, _head, 0);
1649
+ queue_class_private_field_set(this, _tail, totalSize);
1650
+ queue_class_private_field_set(this, _size, totalSize);
1651
+ queue_class_private_field_set(this, _mask, newCap - 1);
1652
+ queue_class_private_field_get(other, _items).fill(void 0);
1653
+ queue_class_private_field_set(other, _head, 0);
1654
+ queue_class_private_field_set(other, _tail, 0);
1655
+ queue_class_private_field_set(other, _size, 0);
1656
+ }
1657
+ },
1658
+ {
1659
+ key: queue_computedKey1,
1660
+ value: function() {
1661
+ return this.values();
1662
+ }
1663
+ },
1664
+ {
1665
+ key: "size",
1666
+ get: function() {
1667
+ return queue_class_private_field_get(this, _size);
1668
+ }
1669
+ },
1670
+ {
1671
+ key: "isEmpty",
1672
+ value: function() {
1673
+ return 0 === queue_class_private_field_get(this, _size);
1674
+ }
1675
+ }
1676
+ ]);
1677
+ return Queue;
1678
+ }();
1679
+ function grow() {
1680
+ var oldMask = queue_class_private_field_get(this, _mask);
1681
+ var newCap = 2 * queue_class_private_field_get(this, _items).length;
1682
+ queue_class_private_field_set(this, _mask, newCap - 1);
1683
+ if (0 === queue_class_private_field_get(this, _head)) {
1684
+ queue_class_private_field_get(this, _items).length = newCap;
1685
+ queue_class_private_field_set(this, _tail, queue_class_private_field_get(this, _size));
1686
+ } else {
1687
+ var newItems = new Array(newCap);
1688
+ for(var i = 0; i < queue_class_private_field_get(this, _size); i++)newItems[i] = queue_class_private_field_get(this, _items)[queue_class_private_field_get(this, _head) + i & oldMask];
1689
+ queue_class_private_field_set(this, _items, newItems);
1690
+ queue_class_private_field_set(this, _head, 0);
1691
+ queue_class_private_field_set(this, _tail, queue_class_private_field_get(this, _size));
1692
+ }
1693
+ }
1694
+ function shrinkIfNeeded() {
1695
+ if (queue_class_private_field_get(this, _items).length >= SHRINK_THRESHOLD) {
1696
+ queue_class_private_field_set(this, _items, new Array(INITIAL_CAPACITY));
1697
+ queue_class_private_field_set(this, _mask, INITIAL_CAPACITY - 1);
1698
+ }
1699
+ }
1700
+ function buildPayload(sql, token) {
1701
+ var _ref = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, _ref_skipNormalize = _ref.skipNormalize, skipNormalize = void 0 === _ref_skipNormalize ? false : _ref_skipNormalize;
1702
+ var normalized = skipNormalize ? sql : normalizeSQL(sql);
1703
+ var suffix = normalized.endsWith(";") ? "" : ";";
1704
+ return "".concat(normalized).concat(suffix, "\nSELECT '").concat(token, "' AS ").concat(TOKEN_COLUMN, ";\n");
1705
+ }
1706
+ function buildBatchPayload(batch) {
1707
+ var useWalBatch = batch.length > 1 && batch.every(function(t) {
1708
+ return "execute" === t.kind;
1709
+ });
1710
+ if (useWalBatch) {
1711
+ var parts = [
1712
+ "BEGIN;\n"
1713
+ ];
1714
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1715
+ try {
1716
+ for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1717
+ var task = _step.value;
1718
+ parts.push(task.sql, "\n");
1719
+ }
1720
+ } catch (err) {
1721
+ _didIteratorError = true;
1722
+ _iteratorError = err;
1723
+ } finally{
1724
+ try {
1725
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
1726
+ } finally{
1727
+ if (_didIteratorError) throw _iteratorError;
1728
+ }
1729
+ }
1730
+ parts.push("COMMIT;\n");
1731
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
1732
+ try {
1733
+ for(var _iterator1 = batch[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
1734
+ var task1 = _step1.value;
1735
+ parts.push("SELECT '".concat(task1.token, "' AS ").concat(TOKEN_COLUMN, ";\n"));
1736
+ }
1737
+ } catch (err) {
1738
+ _didIteratorError1 = true;
1739
+ _iteratorError1 = err;
1740
+ } finally{
1741
+ try {
1742
+ if (!_iteratorNormalCompletion1 && null != _iterator1["return"]) _iterator1["return"]();
1743
+ } finally{
1744
+ if (_didIteratorError1) throw _iteratorError1;
1745
+ }
1746
+ }
1747
+ return parts.join("");
1748
+ }
1749
+ var parts1 = [];
1750
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
1751
+ try {
1752
+ for(var _iterator2 = batch[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
1753
+ var task2 = _step2.value;
1754
+ parts1.push(buildPayload(task2.sql, task2.token, {
1755
+ skipNormalize: true
1756
+ }));
1757
+ }
1758
+ } catch (err) {
1759
+ _didIteratorError2 = true;
1760
+ _iteratorError2 = err;
1761
+ } finally{
1762
+ try {
1763
+ if (!_iteratorNormalCompletion2 && null != _iterator2["return"]) _iterator2["return"]();
1764
+ } finally{
1765
+ if (_didIteratorError2) throw _iteratorError2;
1766
+ }
1767
+ }
1768
+ return parts1.join("");
1769
+ }
1770
+ function isSentinelRow(value, token) {
1771
+ var _value_;
1772
+ return Array.isArray(value) && 1 === value.length && (null == (_value_ = value[0]) ? void 0 : _value_[TOKEN_COLUMN]) === token;
1773
+ }
1774
+ function _array_like_to_array(arr, len) {
1775
+ if (null == len || len > arr.length) len = arr.length;
1776
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1777
+ return arr2;
1778
+ }
1779
+ function _array_without_holes(arr) {
1780
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
1781
+ }
1782
+ function _iterable_to_array(iter) {
1783
+ if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
1784
+ }
1785
+ function _non_iterable_spread() {
1786
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1787
+ }
1788
+ function _to_consumable_array(arr) {
1789
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
1790
+ }
1791
+ function _unsupported_iterable_to_array(o, minLen) {
1792
+ if (!o) return;
1793
+ if ("string" == typeof o) return _array_like_to_array(o, minLen);
1794
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1795
+ if ("Object" === n && o.constructor) n = o.constructor.name;
1796
+ if ("Map" === n || "Set" === n) return Array.from(n);
1797
+ if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1798
+ }
1799
+ function collectQueryRows(task, parsed) {
1800
+ if (Array.isArray(parsed)) {
1801
+ var _task_rows;
1802
+ if (!task.rows) task.rows = [];
1803
+ (_task_rows = task.rows).push.apply(_task_rows, _to_consumable_array(parsed));
1804
+ }
1805
+ }
1806
+ function processStreamRows(task, parsed) {
1807
+ if (!Array.isArray(parsed)) return;
1808
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
1809
+ try {
1810
+ for(var _iterator = parsed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1811
+ var row = _step.value;
1812
+ if (task.consumerError) break;
1813
+ try {
1814
+ task.onRow(row);
1815
+ } catch (error) {
1816
+ task.consumerError = toError(error);
1817
+ }
1818
+ }
1819
+ } catch (err) {
1820
+ _didIteratorError = true;
1821
+ _iteratorError = err;
1822
+ } finally{
1823
+ try {
1824
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
1825
+ } finally{
1826
+ if (_didIteratorError) throw _iteratorError;
1827
+ }
1828
+ }
1829
+ }
1830
+ function settleTask(task, error, value, metrics) {
1831
+ var _ref = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : {}, _ref_resetRowParser = _ref.resetRowParser, resetRowParser = void 0 === _ref_resetRowParser ? false : _ref_resetRowParser;
1832
+ clearTimeout(task.timer);
1833
+ if (resetRowParser) {
1834
+ var _task_rowParser_reset, _task_rowParser;
1835
+ null == (_task_rowParser = task.rowParser) || null == (_task_rowParser_reset = _task_rowParser.reset) || _task_rowParser_reset.call(_task_rowParser);
1836
+ }
1837
+ if (error) {
1838
+ null == metrics || metrics.incrementTasksFailed();
1839
+ task.reject(toError(error));
1840
+ return;
1841
+ }
1842
+ var duration = task.startTime > 0 ? performance.now() - task.startTime : 0;
1843
+ null == metrics || metrics.incrementTasksSuccess(duration);
1844
+ task.resolve(value);
1845
+ }
1846
+ function taskWorker_array_like_to_array(arr, len) {
1847
+ if (null == len || len > arr.length) len = arr.length;
1848
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
1849
+ return arr2;
1850
+ }
1851
+ function taskWorker_array_without_holes(arr) {
1852
+ if (Array.isArray(arr)) return taskWorker_array_like_to_array(arr);
1853
+ }
1854
+ function taskWorker_check_private_redeclaration(obj, privateCollection) {
1855
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
1856
+ }
1857
+ function taskWorker_class_apply_descriptor_get(receiver, descriptor) {
1858
+ if (descriptor.get) return descriptor.get.call(receiver);
1859
+ return descriptor.value;
1860
+ }
1861
+ function taskWorker_class_apply_descriptor_set(receiver, descriptor, value) {
1862
+ if (descriptor.set) descriptor.set.call(receiver, value);
1863
+ else {
1864
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
1865
+ descriptor.value = value;
1866
+ }
1867
+ }
1868
+ function taskWorker_class_call_check(instance, Constructor) {
1869
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
1870
+ }
1871
+ function taskWorker_class_extract_field_descriptor(receiver, privateMap, action) {
1872
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
1873
+ return privateMap.get(receiver);
1874
+ }
1875
+ function taskWorker_class_private_field_get(receiver, privateMap) {
1876
+ var descriptor = taskWorker_class_extract_field_descriptor(receiver, privateMap, "get");
1877
+ return taskWorker_class_apply_descriptor_get(receiver, descriptor);
1878
+ }
1879
+ function taskWorker_class_private_field_init(obj, privateMap, value) {
1880
+ taskWorker_check_private_redeclaration(obj, privateMap);
1881
+ privateMap.set(obj, value);
1882
+ }
1883
+ function taskWorker_class_private_field_set(receiver, privateMap, value) {
1884
+ var descriptor = taskWorker_class_extract_field_descriptor(receiver, privateMap, "set");
1885
+ taskWorker_class_apply_descriptor_set(receiver, descriptor, value);
1886
+ return value;
1887
+ }
1888
+ function taskWorker_class_private_method_get(receiver, privateSet, fn) {
1889
+ if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
1890
+ return fn;
1891
+ }
1892
+ function taskWorker_class_private_method_init(obj, privateSet) {
1893
+ taskWorker_check_private_redeclaration(obj, privateSet);
1894
+ privateSet.add(obj);
1895
+ }
1896
+ function taskWorker_defineProperties(target, props) {
1897
+ for(var i = 0; i < props.length; i++){
1898
+ var descriptor = props[i];
1899
+ descriptor.enumerable = descriptor.enumerable || false;
1900
+ descriptor.configurable = true;
1901
+ if ("value" in descriptor) descriptor.writable = true;
1902
+ Object.defineProperty(target, descriptor.key, descriptor);
1903
+ }
1904
+ }
1905
+ function taskWorker_create_class(Constructor, protoProps, staticProps) {
1906
+ if (protoProps) taskWorker_defineProperties(Constructor.prototype, protoProps);
1907
+ if (staticProps) taskWorker_defineProperties(Constructor, staticProps);
1908
+ return Constructor;
1909
+ }
1910
+ function taskWorker_iterable_to_array(iter) {
1911
+ if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
1912
+ }
1913
+ function taskWorker_non_iterable_spread() {
1914
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1915
+ }
1916
+ function taskWorker_to_consumable_array(arr) {
1917
+ return taskWorker_array_without_holes(arr) || taskWorker_iterable_to_array(arr) || taskWorker_unsupported_iterable_to_array(arr) || taskWorker_non_iterable_spread();
1918
+ }
1919
+ function taskWorker_unsupported_iterable_to_array(o, minLen) {
1920
+ if (!o) return;
1921
+ if ("string" == typeof o) return taskWorker_array_like_to_array(o, minLen);
1922
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1923
+ if ("Object" === n && o.constructor) n = o.constructor.name;
1924
+ if ("Map" === n || "Set" === n) return Array.from(n);
1925
+ if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return taskWorker_array_like_to_array(o, minLen);
1926
+ }
1927
+ 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(), _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();
1928
+ var taskWorker_TaskWorker = /*#__PURE__*/ function() {
1929
+ "use strict";
1930
+ function TaskWorker(param) {
1931
+ var _this = this;
1932
+ 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, metrics = param.metrics;
1933
+ taskWorker_class_call_check(this, TaskWorker);
1934
+ taskWorker_class_private_method_init(this, _startProcess);
1935
+ taskWorker_class_private_method_init(this, _pumpQueue);
1936
+ taskWorker_class_private_method_init(this, _handleParsedValue);
1937
+ taskWorker_class_private_method_init(this, _scheduleFinalizeCheck);
1938
+ taskWorker_class_private_method_init(this, _handleStderrChunk);
1939
+ taskWorker_class_private_method_init(this, _handleTaskTimeout);
1940
+ taskWorker_class_private_method_init(this, _settleTask);
1941
+ taskWorker_class_private_method_init(this, _rejectAll);
1942
+ taskWorker_class_private_field_init(this, _processManager, {
1943
+ writable: true,
1944
+ value: void 0
1945
+ });
1946
+ taskWorker_class_private_field_init(this, _pendingQueue, {
1947
+ writable: true,
1948
+ value: new queue_Queue()
1949
+ });
1950
+ taskWorker_class_private_field_init(this, _inflightTasks, {
1951
+ writable: true,
1952
+ value: []
1953
+ });
1954
+ taskWorker_class_private_field_init(this, _pendingFinalizeTasks, {
1955
+ writable: true,
1956
+ value: new Set()
1957
+ });
1958
+ taskWorker_class_private_field_init(this, _scheduledFinalize, {
1959
+ writable: true,
1960
+ value: false
1961
+ });
1962
+ taskWorker_class_private_field_init(this, _valueParser, {
1963
+ writable: true,
1964
+ value: void 0
1965
+ });
1966
+ taskWorker_class_private_field_init(this, _statementTimeout, {
1967
+ writable: true,
1968
+ value: void 0
1969
+ });
1970
+ taskWorker_class_private_field_init(this, _logger, {
1971
+ writable: true,
1972
+ value: void 0
1973
+ });
1974
+ taskWorker_class_private_field_init(this, _name, {
1975
+ writable: true,
1976
+ value: void 0
1977
+ });
1978
+ taskWorker_class_private_field_init(this, _batchSize, {
1979
+ writable: true,
1980
+ value: void 0
1981
+ });
1982
+ taskWorker_class_private_field_init(this, _metrics, {
1983
+ writable: true,
1984
+ value: void 0
1985
+ });
1986
+ taskWorker_class_private_field_set(this, _name, null != name ? name : "worker");
1987
+ taskWorker_class_private_field_set(this, _statementTimeout, statementTimeout);
1988
+ taskWorker_class_private_field_set(this, _logger, logger);
1989
+ taskWorker_class_private_field_set(this, _batchSize, batchSize);
1990
+ taskWorker_class_private_field_set(this, _metrics, metrics);
1991
+ taskWorker_class_private_field_set(this, _processManager, new process_ProcessManager({
1992
+ binary: binary,
1993
+ database: database,
1994
+ initMode: initMode
1995
+ }));
1996
+ taskWorker_class_private_field_set(this, _valueParser, createJsonValueParser(function(raw) {
1997
+ return taskWorker_class_private_method_get(_this, _handleParsedValue, handleParsedValue).call(_this, raw);
1998
+ }));
1999
+ taskWorker_class_private_method_get(this, _startProcess, startProcess).call(this);
2000
+ }
2001
+ taskWorker_create_class(TaskWorker, [
2002
+ {
2003
+ key: "name",
2004
+ get: function() {
2005
+ return taskWorker_class_private_field_get(this, _name);
2006
+ }
2007
+ },
2008
+ {
2009
+ key: "idle",
2010
+ get: function() {
2011
+ 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;
2012
+ }
2013
+ },
2014
+ {
2015
+ key: "pendingStatements",
2016
+ get: function() {
2017
+ 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;
2018
+ }
2019
+ },
2020
+ {
2021
+ key: "enqueue",
2022
+ value: function(config) {
2023
+ var _$_class_private_field_get;
2024
+ var _config_onRow;
2025
+ var task = {
2026
+ kind: config.kind,
2027
+ sql: config.sql,
2028
+ timeout: config.timeout,
2029
+ token: config.token,
2030
+ resolve: config.resolve,
2031
+ reject: config.reject,
2032
+ rows: "query" === config.kind ? [] : void 0,
2033
+ onRow: null != (_config_onRow = config.onRow) ? _config_onRow : null,
2034
+ consumerError: null,
2035
+ stderrText: "",
2036
+ errorScheduled: false,
2037
+ timer: null,
2038
+ startTime: 0
2039
+ };
2040
+ null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _metrics)) || _$_class_private_field_get.incrementTasksTotal(config.kind);
2041
+ taskWorker_class_private_field_get(this, _pendingQueue).enqueue(task);
2042
+ taskWorker_class_private_method_get(this, _pumpQueue, pumpQueue).call(this);
2043
+ }
2044
+ },
2045
+ {
2046
+ key: "kill",
2047
+ value: function() {
2048
+ taskWorker_class_private_method_get(this, _rejectAll, taskWorker_rejectAll).call(this, new Error("".concat(taskWorker_class_private_field_get(this, _name), " is killed")));
2049
+ taskWorker_class_private_field_get(this, _processManager).kill();
2050
+ }
2051
+ }
2052
+ ]);
2053
+ return TaskWorker;
2054
+ }();
2055
+ function startProcess() {
2056
+ var _this = this;
2057
+ var proc = taskWorker_class_private_field_get(this, _processManager).start();
2058
+ proc.stdout.on("data", function(chunk) {
2059
+ taskWorker_class_private_field_get(_this, _valueParser).feed(chunk);
2060
+ });
2061
+ proc.stderr.on("data", function(chunk) {
2062
+ taskWorker_class_private_method_get(_this, _handleStderrChunk, taskWorker_handleStderrChunk).call(_this, chunk);
2063
+ });
2064
+ proc.on("error", function(error) {
2065
+ var _class_private_field_get_error, _$_class_private_field_get;
2066
+ if (taskWorker_class_private_field_get(_this, _processManager).process !== proc) return;
2067
+ 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, "".concat(taskWorker_class_private_field_get(_this, _name), " process error"), error);
2068
+ taskWorker_class_private_method_get(_this, _rejectAll, taskWorker_rejectAll).call(_this, toError(error));
2069
+ });
2070
+ proc.on("close", function(code, signal) {
2071
+ if (taskWorker_class_private_field_get(_this, _processManager).process !== proc) return;
2072
+ var err = new Error("".concat(taskWorker_class_private_field_get(_this, _name), " exited unexpectedly (code=").concat(code, ", signal=").concat(null != signal ? signal : "none", ")"));
2073
+ taskWorker_class_private_method_get(_this, _rejectAll, taskWorker_rejectAll).call(_this, err);
2074
+ });
2075
+ }
2076
+ function pumpQueue() {
2077
+ var _this = this;
2078
+ var _$_class_private_field_get;
2079
+ var batch = [];
2080
+ while(batch.length < taskWorker_class_private_field_get(this, _batchSize) && !taskWorker_class_private_field_get(this, _pendingQueue).isEmpty()){
2081
+ var task = taskWorker_class_private_field_get(this, _pendingQueue).peek();
2082
+ if ("stream" === task.kind && (batch.length > 0 || taskWorker_class_private_field_get(this, _inflightTasks).length > 0)) break;
2083
+ taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
2084
+ batch.push(task);
2085
+ }
2086
+ if (0 === batch.length) return;
2087
+ var now = performance.now();
2088
+ var payload = buildBatchPayload(batch);
2089
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2090
+ try {
2091
+ var _this1, _loop = function() {
2092
+ var task = _step.value;
2093
+ task.startTime = now;
2094
+ var _task_timeout;
2095
+ task.timer = setTimeout(function() {
2096
+ return taskWorker_class_private_method_get(_this, _handleTaskTimeout, handleTaskTimeout).call(_this, task);
2097
+ }, null != (_task_timeout = task.timeout) ? _task_timeout : taskWorker_class_private_field_get(_this1, _statementTimeout));
2098
+ };
2099
+ for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_this1 = this, _loop();
2100
+ } catch (err) {
2101
+ _didIteratorError = true;
2102
+ _iteratorError = err;
2103
+ } finally{
2104
+ try {
2105
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2106
+ } finally{
2107
+ if (_didIteratorError) throw _iteratorError;
2108
+ }
2109
+ }
2110
+ (_$_class_private_field_get = taskWorker_class_private_field_get(this, _inflightTasks)).push.apply(_$_class_private_field_get, taskWorker_to_consumable_array(batch));
2111
+ taskWorker_class_private_field_get(this, _processManager).write(payload);
2112
+ }
2113
+ function handleParsedValue(raw) {
2114
+ var task = taskWorker_class_private_field_get(this, _inflightTasks)[0];
2115
+ if (!task) return;
2116
+ var parsed;
2117
+ try {
2118
+ parsed = JSON.parse(raw);
2119
+ } catch (error) {
2120
+ taskWorker_class_private_method_get(this, _rejectAll, taskWorker_rejectAll).call(this, new Error("Invalid JSON from sqlite3: ".concat(toError(error).message)));
2121
+ return;
2122
+ }
2123
+ if (isSentinelRow(parsed, task.token)) {
2124
+ clearTimeout(task.timer);
2125
+ taskWorker_class_private_field_get(this, _inflightTasks).shift();
2126
+ if (task.stderrText) {
2127
+ taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, new Error(task.stderrText.trim()), void 0);
2128
+ taskWorker_class_private_method_get(this, _pumpQueue, pumpQueue).call(this);
2129
+ return;
2130
+ }
2131
+ if (task.consumerError) {
2132
+ taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, task.consumerError, void 0);
2133
+ taskWorker_class_private_method_get(this, _pumpQueue, pumpQueue).call(this);
2134
+ return;
2135
+ }
2136
+ taskWorker_class_private_field_get(this, _pendingFinalizeTasks).add(task);
2137
+ taskWorker_class_private_method_get(this, _scheduleFinalizeCheck, scheduleFinalizeCheck).call(this);
2138
+ taskWorker_class_private_method_get(this, _pumpQueue, pumpQueue).call(this);
2139
+ return;
2140
+ }
2141
+ if ("query" === task.kind) return void collectQueryRows(task, parsed);
2142
+ if ("stream" === task.kind) processStreamRows(task, parsed);
2143
+ }
2144
+ function scheduleFinalizeCheck() {
2145
+ var _this = this;
2146
+ if (taskWorker_class_private_field_get(this, _scheduledFinalize)) return;
2147
+ taskWorker_class_private_field_set(this, _scheduledFinalize, true);
2148
+ setImmediate(function() {
2149
+ taskWorker_class_private_field_set(_this, _scheduledFinalize, false);
2150
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2151
+ try {
2152
+ for(var _iterator = taskWorker_class_private_field_get(_this, _pendingFinalizeTasks)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2153
+ var task = _step.value;
2154
+ if (task.stderrText) {
2155
+ taskWorker_class_private_method_get(_this, _settleTask, settleTask1).call(_this, task, new Error(task.stderrText.trim()), void 0);
2156
+ continue;
2157
+ }
2158
+ if (task.consumerError) {
2159
+ taskWorker_class_private_method_get(_this, _settleTask, settleTask1).call(_this, task, task.consumerError, void 0);
2160
+ continue;
2161
+ }
2162
+ if ("query" === task.kind) {
2163
+ taskWorker_class_private_method_get(_this, _settleTask, settleTask1).call(_this, task, null, task.rows);
2164
+ continue;
2165
+ }
2166
+ taskWorker_class_private_method_get(_this, _settleTask, settleTask1).call(_this, task, null, void 0);
2167
+ }
2168
+ } catch (err) {
2169
+ _didIteratorError = true;
2170
+ _iteratorError = err;
2171
+ } finally{
2172
+ try {
2173
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2174
+ } finally{
2175
+ if (_didIteratorError) throw _iteratorError;
2176
+ }
2177
+ }
2178
+ taskWorker_class_private_field_get(_this, _pendingFinalizeTasks).clear();
2179
+ taskWorker_class_private_method_get(_this, _pumpQueue, pumpQueue).call(_this);
2180
+ });
2181
+ }
2182
+ function taskWorker_handleStderrChunk(chunk) {
2183
+ var _class_private_field_get_;
2184
+ 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;
2185
+ if (!task) {
2186
+ var _class_private_field_get_error, _$_class_private_field_get;
2187
+ 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());
2188
+ return;
2189
+ }
2190
+ task.stderrText += String(chunk);
2191
+ }
2192
+ function handleTaskTimeout(task) {
2193
+ var _$_class_private_field_get;
2194
+ if (taskWorker_class_private_field_get(this, _inflightTasks)[0] !== task) return;
2195
+ null == (_$_class_private_field_get = taskWorker_class_private_field_get(this, _metrics)) || _$_class_private_field_get.incrementTasksTimeout();
2196
+ taskWorker_class_private_method_get(this, _rejectAll, taskWorker_rejectAll).call(this, createTimeoutError(task.timeout, task.sql));
2197
+ }
2198
+ function settleTask1(task, error, value) {
2199
+ settleTask(task, error, value, taskWorker_class_private_field_get(this, _metrics));
2200
+ }
2201
+ function taskWorker_rejectAll(error) {
2202
+ var all = taskWorker_class_private_field_get(this, _inflightTasks);
2203
+ taskWorker_class_private_field_set(this, _inflightTasks, []);
2204
+ var queued = taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
2205
+ while(queued){
2206
+ taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, queued, error, void 0);
2207
+ queued = taskWorker_class_private_field_get(this, _pendingQueue).dequeue();
2208
+ }
2209
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2210
+ try {
2211
+ for(var _iterator = all[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2212
+ var task = _step.value;
2213
+ taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task, error, void 0);
2214
+ }
2215
+ } catch (err) {
2216
+ _didIteratorError = true;
2217
+ _iteratorError = err;
2218
+ } finally{
2219
+ try {
2220
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2221
+ } finally{
2222
+ if (_didIteratorError) throw _iteratorError;
2223
+ }
2224
+ }
2225
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
2226
+ try {
2227
+ for(var _iterator1 = taskWorker_class_private_field_get(this, _pendingFinalizeTasks)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2228
+ var task1 = _step1.value;
2229
+ taskWorker_class_private_method_get(this, _settleTask, settleTask1).call(this, task1, error, void 0);
2230
+ }
2231
+ } catch (err) {
2232
+ _didIteratorError1 = true;
2233
+ _iteratorError1 = err;
2234
+ } finally{
2235
+ try {
2236
+ if (!_iteratorNormalCompletion1 && null != _iterator1["return"]) _iterator1["return"]();
2237
+ } finally{
2238
+ if (_didIteratorError1) throw _iteratorError1;
2239
+ }
2240
+ }
2241
+ taskWorker_class_private_field_get(this, _pendingFinalizeTasks).clear();
2242
+ }
2243
+ function readerPool_check_private_redeclaration(obj, privateCollection) {
2244
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
2245
+ }
2246
+ function readerPool_class_apply_descriptor_get(receiver, descriptor) {
2247
+ if (descriptor.get) return descriptor.get.call(receiver);
2248
+ return descriptor.value;
2249
+ }
2250
+ function readerPool_class_apply_descriptor_update(receiver, descriptor) {
2251
+ if (descriptor.set) {
2252
+ if (!descriptor.get) throw new TypeError("attempted to read set only private field");
2253
+ if (!("__destrWrapper" in descriptor)) descriptor.__destrWrapper = {
2254
+ set value (v){
2255
+ descriptor.set.call(receiver, v);
2256
+ },
2257
+ get value () {
2258
+ return descriptor.get.call(receiver);
2259
+ }
2260
+ };
2261
+ return descriptor.__destrWrapper;
2262
+ }
2263
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
2264
+ return descriptor;
2265
+ }
2266
+ function readerPool_class_call_check(instance, Constructor) {
2267
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
2268
+ }
2269
+ function readerPool_class_extract_field_descriptor(receiver, privateMap, action) {
2270
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
2271
+ return privateMap.get(receiver);
2272
+ }
2273
+ function readerPool_class_private_field_get(receiver, privateMap) {
2274
+ var descriptor = readerPool_class_extract_field_descriptor(receiver, privateMap, "get");
2275
+ return readerPool_class_apply_descriptor_get(receiver, descriptor);
2276
+ }
2277
+ function readerPool_class_private_field_init(obj, privateMap, value) {
2278
+ readerPool_check_private_redeclaration(obj, privateMap);
2279
+ privateMap.set(obj, value);
2280
+ }
2281
+ function readerPool_class_private_field_update(receiver, privateMap) {
2282
+ var descriptor = readerPool_class_extract_field_descriptor(receiver, privateMap, "update");
2283
+ return readerPool_class_apply_descriptor_update(receiver, descriptor);
2284
+ }
2285
+ function readerPool_defineProperties(target, props) {
2286
+ for(var i = 0; i < props.length; i++){
2287
+ var descriptor = props[i];
2288
+ descriptor.enumerable = descriptor.enumerable || false;
2289
+ descriptor.configurable = true;
2290
+ if ("value" in descriptor) descriptor.writable = true;
2291
+ Object.defineProperty(target, descriptor.key, descriptor);
2292
+ }
2293
+ }
2294
+ function readerPool_create_class(Constructor, protoProps, staticProps) {
2295
+ if (protoProps) readerPool_defineProperties(Constructor.prototype, protoProps);
2296
+ if (staticProps) readerPool_defineProperties(Constructor, staticProps);
2297
+ return Constructor;
2298
+ }
2299
+ var _workers = /*#__PURE__*/ new WeakMap(), _rrIndex = /*#__PURE__*/ new WeakMap();
2300
+ var readerPool_ReaderPool = /*#__PURE__*/ function() {
2301
+ "use strict";
2302
+ function ReaderPool(param) {
2303
+ var binary = param.binary, database = param.database, poolSize = param.poolSize, statementTimeout = param.statementTimeout, logger = param.logger, metrics = param.metrics;
2304
+ readerPool_class_call_check(this, ReaderPool);
2305
+ readerPool_class_private_field_init(this, _workers, {
2306
+ writable: true,
2307
+ value: []
2308
+ });
2309
+ readerPool_class_private_field_init(this, _rrIndex, {
2310
+ writable: true,
2311
+ value: 0
2312
+ });
2313
+ for(var i = 0; i < poolSize; i++){
2314
+ var worker = new taskWorker_TaskWorker({
2315
+ binary: binary,
2316
+ database: database,
2317
+ statementTimeout: statementTimeout,
2318
+ logger: logger,
2319
+ metrics: metrics,
2320
+ name: "reader-".concat(i),
2321
+ initMode: ":memory:" !== database ? "none" : "wal"
2322
+ });
2323
+ readerPool_class_private_field_get(this, _workers).push(worker);
2324
+ }
2325
+ }
2326
+ readerPool_create_class(ReaderPool, [
2327
+ {
2328
+ key: "size",
2329
+ get: function() {
2330
+ return readerPool_class_private_field_get(this, _workers).length;
2331
+ }
2332
+ },
2333
+ {
2334
+ key: "pendingStatements",
2335
+ get: function() {
2336
+ return readerPool_class_private_field_get(this, _workers).reduce(function(sum, w) {
2337
+ return sum + w.pendingStatements;
2338
+ }, 0);
2339
+ }
2340
+ },
2341
+ {
2342
+ key: "enqueue",
2343
+ value: function(task) {
2344
+ var worker = readerPool_class_private_field_get(this, _workers)[readerPool_class_private_field_get(this, _rrIndex) % readerPool_class_private_field_get(this, _workers).length];
2345
+ readerPool_class_private_field_update(this, _rrIndex).value++;
2346
+ worker.enqueue(task);
2347
+ }
2348
+ },
2349
+ {
2350
+ key: "kill",
2351
+ value: function() {
2352
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
2353
+ try {
2354
+ for(var _iterator = readerPool_class_private_field_get(this, _workers)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2355
+ var worker = _step.value;
2356
+ worker.kill();
2357
+ }
2358
+ } catch (err) {
2359
+ _didIteratorError = true;
2360
+ _iteratorError = err;
2361
+ } finally{
2362
+ try {
2363
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
2364
+ } finally{
2365
+ if (_didIteratorError) throw _iteratorError;
2366
+ }
2367
+ }
2368
+ }
2369
+ }
2370
+ ]);
2371
+ return ReaderPool;
2372
+ }();
2373
+ function metrics_check_private_redeclaration(obj, privateCollection) {
2374
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
2375
+ }
2376
+ function metrics_class_apply_descriptor_get(receiver, descriptor) {
2377
+ if (descriptor.get) return descriptor.get.call(receiver);
2378
+ return descriptor.value;
2379
+ }
2380
+ function metrics_class_apply_descriptor_set(receiver, descriptor, value) {
2381
+ if (descriptor.set) descriptor.set.call(receiver, value);
2382
+ else {
2383
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
2384
+ descriptor.value = value;
2385
+ }
2386
+ }
2387
+ function metrics_class_apply_descriptor_update(receiver, descriptor) {
2388
+ if (descriptor.set) {
2389
+ if (!descriptor.get) throw new TypeError("attempted to read set only private field");
2390
+ if (!("__destrWrapper" in descriptor)) descriptor.__destrWrapper = {
2391
+ set value (v){
2392
+ descriptor.set.call(receiver, v);
2393
+ },
2394
+ get value () {
2395
+ return descriptor.get.call(receiver);
2396
+ }
2397
+ };
2398
+ return descriptor.__destrWrapper;
2399
+ }
2400
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
2401
+ return descriptor;
2402
+ }
2403
+ function metrics_class_call_check(instance, Constructor) {
2404
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
2405
+ }
2406
+ function metrics_class_extract_field_descriptor(receiver, privateMap, action) {
2407
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
2408
+ return privateMap.get(receiver);
2409
+ }
2410
+ function metrics_class_private_field_get(receiver, privateMap) {
2411
+ var descriptor = metrics_class_extract_field_descriptor(receiver, privateMap, "get");
2412
+ return metrics_class_apply_descriptor_get(receiver, descriptor);
2413
+ }
2414
+ function metrics_class_private_field_init(obj, privateMap, value) {
2415
+ metrics_check_private_redeclaration(obj, privateMap);
2416
+ privateMap.set(obj, value);
2417
+ }
2418
+ function metrics_class_private_field_set(receiver, privateMap, value) {
2419
+ var descriptor = metrics_class_extract_field_descriptor(receiver, privateMap, "set");
2420
+ metrics_class_apply_descriptor_set(receiver, descriptor, value);
2421
+ return value;
2422
+ }
2423
+ function metrics_class_private_field_update(receiver, privateMap) {
2424
+ var descriptor = metrics_class_extract_field_descriptor(receiver, privateMap, "update");
2425
+ return metrics_class_apply_descriptor_update(receiver, descriptor);
2426
+ }
2427
+ function metrics_defineProperties(target, props) {
2428
+ for(var i = 0; i < props.length; i++){
2429
+ var descriptor = props[i];
2430
+ descriptor.enumerable = descriptor.enumerable || false;
2431
+ descriptor.configurable = true;
2432
+ if ("value" in descriptor) descriptor.writable = true;
2433
+ Object.defineProperty(target, descriptor.key, descriptor);
2434
+ }
2435
+ }
2436
+ function metrics_create_class(Constructor, protoProps, staticProps) {
2437
+ if (protoProps) metrics_defineProperties(Constructor.prototype, protoProps);
2438
+ if (staticProps) metrics_defineProperties(Constructor, staticProps);
2439
+ return Constructor;
2440
+ }
2441
+ var _tasksTotal = /*#__PURE__*/ new WeakMap(), _tasksSuccess = /*#__PURE__*/ new WeakMap(), _tasksFailed = /*#__PURE__*/ new WeakMap(), _tasksTimeout = /*#__PURE__*/ new WeakMap(), _processRestarts = /*#__PURE__*/ new WeakMap(), _executeCount = /*#__PURE__*/ new WeakMap(), _queryCount = /*#__PURE__*/ new WeakMap(), _streamCount = /*#__PURE__*/ new WeakMap(), _totalDuration = /*#__PURE__*/ new WeakMap(), _startTime = /*#__PURE__*/ new WeakMap();
2442
+ var metrics_Metrics = /*#__PURE__*/ function() {
2443
+ "use strict";
2444
+ function Metrics() {
2445
+ metrics_class_call_check(this, Metrics);
2446
+ metrics_class_private_field_init(this, _tasksTotal, {
2447
+ writable: true,
2448
+ value: 0
2449
+ });
2450
+ metrics_class_private_field_init(this, _tasksSuccess, {
2451
+ writable: true,
2452
+ value: 0
2453
+ });
2454
+ metrics_class_private_field_init(this, _tasksFailed, {
2455
+ writable: true,
2456
+ value: 0
2457
+ });
2458
+ metrics_class_private_field_init(this, _tasksTimeout, {
2459
+ writable: true,
2460
+ value: 0
2461
+ });
2462
+ metrics_class_private_field_init(this, _processRestarts, {
2463
+ writable: true,
2464
+ value: 0
2465
+ });
2466
+ metrics_class_private_field_init(this, _executeCount, {
2467
+ writable: true,
2468
+ value: 0
2469
+ });
2470
+ metrics_class_private_field_init(this, _queryCount, {
2471
+ writable: true,
2472
+ value: 0
2473
+ });
2474
+ metrics_class_private_field_init(this, _streamCount, {
2475
+ writable: true,
2476
+ value: 0
2477
+ });
2478
+ metrics_class_private_field_init(this, _totalDuration, {
2479
+ writable: true,
2480
+ value: 0
2481
+ });
2482
+ metrics_class_private_field_init(this, _startTime, {
2483
+ writable: true,
2484
+ value: Date.now()
2485
+ });
2486
+ }
2487
+ metrics_create_class(Metrics, [
2488
+ {
2489
+ key: "tasksTotal",
2490
+ get: function() {
2491
+ return metrics_class_private_field_get(this, _tasksTotal);
2492
+ }
2493
+ },
2494
+ {
2495
+ key: "tasksSuccess",
2496
+ get: function() {
2497
+ return metrics_class_private_field_get(this, _tasksSuccess);
2498
+ }
2499
+ },
2500
+ {
2501
+ key: "tasksFailed",
2502
+ get: function() {
2503
+ return metrics_class_private_field_get(this, _tasksFailed);
2504
+ }
2505
+ },
2506
+ {
2507
+ key: "tasksTimeout",
2508
+ get: function() {
2509
+ return metrics_class_private_field_get(this, _tasksTimeout);
2510
+ }
2511
+ },
2512
+ {
2513
+ key: "processRestarts",
2514
+ get: function() {
2515
+ return metrics_class_private_field_get(this, _processRestarts);
2516
+ }
2517
+ },
2518
+ {
2519
+ key: "executeCount",
2520
+ get: function() {
2521
+ return metrics_class_private_field_get(this, _executeCount);
2522
+ }
2523
+ },
2524
+ {
2525
+ key: "queryCount",
2526
+ get: function() {
2527
+ return metrics_class_private_field_get(this, _queryCount);
2528
+ }
2529
+ },
2530
+ {
2531
+ key: "streamCount",
2532
+ get: function() {
2533
+ return metrics_class_private_field_get(this, _streamCount);
2534
+ }
2535
+ },
2536
+ {
2537
+ key: "totalDuration",
2538
+ get: function() {
2539
+ return metrics_class_private_field_get(this, _totalDuration);
2540
+ }
2541
+ },
2542
+ {
2543
+ key: "startTime",
2544
+ get: function() {
2545
+ return metrics_class_private_field_get(this, _startTime);
2546
+ }
2547
+ },
2548
+ {
2549
+ key: "incrementTasksTotal",
2550
+ value: function(kind) {
2551
+ metrics_class_private_field_update(this, _tasksTotal).value++;
2552
+ if ("execute" === kind) metrics_class_private_field_update(this, _executeCount).value++;
2553
+ else if ("query" === kind) metrics_class_private_field_update(this, _queryCount).value++;
2554
+ else if ("stream" === kind) metrics_class_private_field_update(this, _streamCount).value++;
2555
+ }
2556
+ },
2557
+ {
2558
+ key: "incrementTasksSuccess",
2559
+ value: function(duration) {
2560
+ metrics_class_private_field_update(this, _tasksSuccess).value++;
2561
+ metrics_class_private_field_set(this, _totalDuration, metrics_class_private_field_get(this, _totalDuration) + duration);
2562
+ }
2563
+ },
2564
+ {
2565
+ key: "incrementTasksFailed",
2566
+ value: function() {
2567
+ metrics_class_private_field_update(this, _tasksFailed).value++;
2568
+ }
2569
+ },
2570
+ {
2571
+ key: "incrementTasksTimeout",
2572
+ value: function() {
2573
+ metrics_class_private_field_update(this, _tasksTimeout).value++;
2574
+ }
2575
+ },
2576
+ {
2577
+ key: "incrementProcessRestarts",
2578
+ value: function() {
2579
+ metrics_class_private_field_update(this, _processRestarts).value++;
2580
+ }
2581
+ },
2582
+ {
2583
+ key: "snapshot",
2584
+ value: function() {
2585
+ var elapsed = (Date.now() - metrics_class_private_field_get(this, _startTime)) / 1000;
2586
+ return {
2587
+ tasksTotal: metrics_class_private_field_get(this, _tasksTotal),
2588
+ tasksSuccess: metrics_class_private_field_get(this, _tasksSuccess),
2589
+ tasksFailed: metrics_class_private_field_get(this, _tasksFailed),
2590
+ tasksTimeout: metrics_class_private_field_get(this, _tasksTimeout),
2591
+ processRestarts: metrics_class_private_field_get(this, _processRestarts),
2592
+ executeCount: metrics_class_private_field_get(this, _executeCount),
2593
+ queryCount: metrics_class_private_field_get(this, _queryCount),
2594
+ streamCount: metrics_class_private_field_get(this, _streamCount),
2595
+ avgQueryTime: metrics_class_private_field_get(this, _tasksSuccess) > 0 ? metrics_class_private_field_get(this, _totalDuration) / metrics_class_private_field_get(this, _tasksSuccess) : 0,
2596
+ qps: elapsed > 0 ? metrics_class_private_field_get(this, _tasksTotal) / elapsed : 0,
2597
+ uptime: elapsed
2598
+ };
2599
+ }
2600
+ }
2601
+ ]);
2602
+ return Metrics;
2603
+ }();
2604
+ function transactionScope_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2605
+ try {
2606
+ var info = gen[key](arg);
2607
+ var value = info.value;
2608
+ } catch (error) {
2609
+ reject(error);
2610
+ return;
2611
+ }
2612
+ if (info.done) resolve(value);
2613
+ else Promise.resolve(value).then(_next, _throw);
2614
+ }
2615
+ function transactionScope_async_to_generator(fn) {
2616
+ return function() {
2617
+ var self = this, args = arguments;
2618
+ return new Promise(function(resolve, reject) {
2619
+ var gen = fn.apply(self, args);
2620
+ function _next(value) {
2621
+ transactionScope_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
2622
+ }
2623
+ function _throw(err) {
2624
+ transactionScope_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
2625
+ }
2626
+ _next(void 0);
2627
+ });
2628
+ };
2629
+ }
2630
+ function transactionScope_check_private_redeclaration(obj, privateCollection) {
2631
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
2632
+ }
2633
+ function transactionScope_class_apply_descriptor_get(receiver, descriptor) {
2634
+ if (descriptor.get) return descriptor.get.call(receiver);
2635
+ return descriptor.value;
2636
+ }
2637
+ function transactionScope_class_apply_descriptor_set(receiver, descriptor, value) {
2638
+ if (descriptor.set) descriptor.set.call(receiver, value);
2639
+ else {
2640
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
2641
+ descriptor.value = value;
2642
+ }
2643
+ }
2644
+ function transactionScope_class_call_check(instance, Constructor) {
2645
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
2646
+ }
2647
+ function transactionScope_class_extract_field_descriptor(receiver, privateMap, action) {
2648
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
2649
+ return privateMap.get(receiver);
2650
+ }
2651
+ function transactionScope_class_private_field_get(receiver, privateMap) {
2652
+ var descriptor = transactionScope_class_extract_field_descriptor(receiver, privateMap, "get");
2653
+ return transactionScope_class_apply_descriptor_get(receiver, descriptor);
2654
+ }
2655
+ function transactionScope_class_private_field_init(obj, privateMap, value) {
2656
+ transactionScope_check_private_redeclaration(obj, privateMap);
2657
+ privateMap.set(obj, value);
2658
+ }
2659
+ function transactionScope_class_private_field_set(receiver, privateMap, value) {
2660
+ var descriptor = transactionScope_class_extract_field_descriptor(receiver, privateMap, "set");
2661
+ transactionScope_class_apply_descriptor_set(receiver, descriptor, value);
2662
+ return value;
2663
+ }
2664
+ function transactionScope_defineProperties(target, props) {
2665
+ for(var i = 0; i < props.length; i++){
2666
+ var descriptor = props[i];
2667
+ descriptor.enumerable = descriptor.enumerable || false;
2668
+ descriptor.configurable = true;
2669
+ if ("value" in descriptor) descriptor.writable = true;
2670
+ Object.defineProperty(target, descriptor.key, descriptor);
2671
+ }
2672
+ }
2673
+ function transactionScope_create_class(Constructor, protoProps, staticProps) {
2674
+ if (protoProps) transactionScope_defineProperties(Constructor.prototype, protoProps);
2675
+ if (staticProps) transactionScope_defineProperties(Constructor, staticProps);
2676
+ return Constructor;
2677
+ }
2678
+ function transactionScope_ts_generator(thisArg, body) {
2679
+ var f, y, t, _ = {
2680
+ label: 0,
2681
+ sent: function() {
2682
+ if (1 & t[0]) throw t[1];
2683
+ return t[1];
2684
+ },
2685
+ trys: [],
2686
+ ops: []
2687
+ }, g = Object.create(("function" == typeof Iterator ? Iterator : Object).prototype);
2688
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), "function" == typeof Symbol && (g[Symbol.iterator] = function() {
2689
+ return this;
2690
+ }), g;
2691
+ function verb(n) {
2692
+ return function(v1) {
2693
+ return step([
2694
+ n,
2695
+ v1
2696
+ ]);
2697
+ };
2698
+ }
2699
+ function step(op) {
2700
+ if (f) throw new TypeError("Generator is already executing.");
2701
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
2702
+ if (f = 1, y && (t = 2 & op[0] ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
2703
+ if (y = 0, t) op = [
2704
+ 2 & op[0],
2705
+ t.value
2706
+ ];
2707
+ switch(op[0]){
2708
+ case 0:
2709
+ case 1:
2710
+ t = op;
2711
+ break;
2712
+ case 4:
2713
+ _.label++;
2714
+ return {
2715
+ value: op[1],
2716
+ done: false
2717
+ };
2718
+ case 5:
2719
+ _.label++;
2720
+ y = op[1];
2721
+ op = [
2722
+ 0
2723
+ ];
2724
+ continue;
2725
+ case 7:
2726
+ op = _.ops.pop();
2727
+ _.trys.pop();
2728
+ continue;
2729
+ default:
2730
+ if (t = _.trys, !(t = t.length > 0 && t[t.length - 1]) && (6 === op[0] || 2 === op[0])) {
2731
+ _ = 0;
2732
+ continue;
2733
+ }
2734
+ if (3 === op[0] && (!t || op[1] > t[0] && op[1] < t[3])) {
2735
+ _.label = op[1];
2736
+ break;
2737
+ }
2738
+ if (6 === op[0] && _.label < t[1]) {
2739
+ _.label = t[1];
2740
+ t = op;
2741
+ break;
2742
+ }
2743
+ if (t && _.label < t[2]) {
2744
+ _.label = t[2];
2745
+ _.ops.push(op);
2746
+ break;
2747
+ }
2748
+ if (t[2]) _.ops.pop();
2749
+ _.trys.pop();
2750
+ continue;
2751
+ }
2752
+ op = body.call(thisArg, _);
2753
+ } catch (e) {
2754
+ op = [
2755
+ 6,
2756
+ e
2757
+ ];
2758
+ y = 0;
2759
+ } finally{
2760
+ f = t = 0;
2761
+ }
2762
+ if (5 & op[0]) throw op[1];
2763
+ return {
2764
+ value: op[0] ? op[1] : void 0,
2765
+ done: true
2766
+ };
2767
+ }
2768
+ }
2769
+ var _deferredQueue = /*#__PURE__*/ new WeakMap(), _activeScopeId = /*#__PURE__*/ new WeakMap(), _scopeChain = /*#__PURE__*/ new WeakMap();
2770
+ var transactionScope_TransactionScope = /*#__PURE__*/ function() {
2771
+ "use strict";
2772
+ function TransactionScope() {
2773
+ transactionScope_class_call_check(this, TransactionScope);
2774
+ transactionScope_class_private_field_init(this, _deferredQueue, {
2775
+ writable: true,
2776
+ value: new queue_Queue()
2777
+ });
2778
+ transactionScope_class_private_field_init(this, _activeScopeId, {
2779
+ writable: true,
2780
+ value: null
2781
+ });
2782
+ transactionScope_class_private_field_init(this, _scopeChain, {
2783
+ writable: true,
2784
+ value: Promise.resolve()
2785
+ });
2786
+ }
2787
+ transactionScope_create_class(TransactionScope, [
2788
+ {
2789
+ key: "scopeId",
2790
+ get: function() {
2791
+ return transactionScope_class_private_field_get(this, _activeScopeId);
2792
+ }
2793
+ },
2794
+ {
2795
+ key: "active",
2796
+ get: function() {
2797
+ return null !== transactionScope_class_private_field_get(this, _activeScopeId);
2798
+ }
2799
+ },
2800
+ {
2801
+ key: "pendingStatements",
2802
+ get: function() {
2803
+ return transactionScope_class_private_field_get(this, _deferredQueue).size;
2804
+ }
2805
+ },
2806
+ {
2807
+ key: "isDeferred",
2808
+ value: function(scopeId) {
2809
+ return null !== transactionScope_class_private_field_get(this, _activeScopeId) && transactionScope_class_private_field_get(this, _activeScopeId) !== scopeId;
2810
+ }
2811
+ },
2812
+ {
2813
+ key: "defer",
2814
+ value: function(task) {
2815
+ transactionScope_class_private_field_get(this, _deferredQueue).enqueue(task);
2816
+ }
2817
+ },
2818
+ {
2819
+ key: "enter",
2820
+ value: function() {
2821
+ var _this = this;
2822
+ return transactionScope_async_to_generator(function() {
2823
+ var scopeId, release, gate, previous;
2824
+ return transactionScope_ts_generator(this, function(_state) {
2825
+ switch(_state.label){
2826
+ case 0:
2827
+ scopeId = Symbol("transaction");
2828
+ release = null;
2829
+ gate = new Promise(function(resolve) {
2830
+ release = resolve;
2831
+ });
2832
+ previous = transactionScope_class_private_field_get(_this, _scopeChain);
2833
+ transactionScope_class_private_field_set(_this, _scopeChain, previous["catch"](function() {}).then(function() {
2834
+ return gate;
2835
+ }));
2836
+ return [
2837
+ 4,
2838
+ previous["catch"](function() {})
2839
+ ];
2840
+ case 1:
2841
+ _state.sent();
2842
+ transactionScope_class_private_field_set(_this, _activeScopeId, scopeId);
2843
+ return [
2844
+ 2,
2845
+ {
2846
+ scopeId: scopeId,
2847
+ release: release
2848
+ }
2849
+ ];
2850
+ }
2851
+ });
2852
+ })();
2853
+ }
2854
+ },
2855
+ {
2856
+ key: "exit",
2857
+ value: function() {
2858
+ transactionScope_class_private_field_set(this, _activeScopeId, null);
2859
+ }
2860
+ },
2861
+ {
2862
+ key: "restoreDeferred",
2863
+ value: function(targetQueue) {
2864
+ targetQueue.prependAll(transactionScope_class_private_field_get(this, _deferredQueue));
2865
+ }
2866
+ },
2867
+ {
2868
+ key: "rejectAll",
2869
+ value: function(error) {
2870
+ var task = transactionScope_class_private_field_get(this, _deferredQueue).dequeue();
2871
+ while(task){
2872
+ settleTask(task, error, void 0, null);
2873
+ task = transactionScope_class_private_field_get(this, _deferredQueue).dequeue();
2874
+ }
2875
+ }
2876
+ }
2877
+ ]);
2878
+ return TransactionScope;
2879
+ }();
2880
+ function pipelineEngine_array_like_to_array(arr, len) {
2881
+ if (null == len || len > arr.length) len = arr.length;
2882
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
2883
+ return arr2;
2884
+ }
2885
+ function pipelineEngine_array_without_holes(arr) {
2886
+ if (Array.isArray(arr)) return pipelineEngine_array_like_to_array(arr);
2887
+ }
2888
+ function pipelineEngine_check_private_redeclaration(obj, privateCollection) {
2889
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
2890
+ }
2891
+ function pipelineEngine_class_apply_descriptor_get(receiver, descriptor) {
2892
+ if (descriptor.get) return descriptor.get.call(receiver);
2893
+ return descriptor.value;
2894
+ }
2895
+ function pipelineEngine_class_apply_descriptor_set(receiver, descriptor, value) {
2896
+ if (descriptor.set) descriptor.set.call(receiver, value);
2897
+ else {
2898
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
2899
+ descriptor.value = value;
2900
+ }
2901
+ }
2902
+ function pipelineEngine_class_call_check(instance, Constructor) {
2903
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
2904
+ }
2905
+ function pipelineEngine_class_extract_field_descriptor(receiver, privateMap, action) {
2906
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
2907
+ return privateMap.get(receiver);
2908
+ }
2909
+ function pipelineEngine_class_private_field_get(receiver, privateMap) {
2910
+ var descriptor = pipelineEngine_class_extract_field_descriptor(receiver, privateMap, "get");
2911
+ return pipelineEngine_class_apply_descriptor_get(receiver, descriptor);
2912
+ }
2913
+ function pipelineEngine_class_private_field_init(obj, privateMap, value) {
2914
+ pipelineEngine_check_private_redeclaration(obj, privateMap);
2915
+ privateMap.set(obj, value);
2916
+ }
2917
+ function pipelineEngine_class_private_field_set(receiver, privateMap, value) {
2918
+ var descriptor = pipelineEngine_class_extract_field_descriptor(receiver, privateMap, "set");
2919
+ pipelineEngine_class_apply_descriptor_set(receiver, descriptor, value);
2920
+ return value;
2921
+ }
2922
+ function pipelineEngine_class_private_method_get(receiver, privateSet, fn) {
2923
+ if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
2924
+ return fn;
2925
+ }
2926
+ function pipelineEngine_class_private_method_init(obj, privateSet) {
2927
+ pipelineEngine_check_private_redeclaration(obj, privateSet);
2928
+ privateSet.add(obj);
2929
+ }
2930
+ function pipelineEngine_defineProperties(target, props) {
2931
+ for(var i = 0; i < props.length; i++){
2932
+ var descriptor = props[i];
2933
+ descriptor.enumerable = descriptor.enumerable || false;
2934
+ descriptor.configurable = true;
2935
+ if ("value" in descriptor) descriptor.writable = true;
2936
+ Object.defineProperty(target, descriptor.key, descriptor);
2937
+ }
2938
+ }
2939
+ function pipelineEngine_create_class(Constructor, protoProps, staticProps) {
2940
+ if (protoProps) pipelineEngine_defineProperties(Constructor.prototype, protoProps);
2941
+ if (staticProps) pipelineEngine_defineProperties(Constructor, staticProps);
2942
+ return Constructor;
2943
+ }
2944
+ function pipelineEngine_iterable_to_array(iter) {
2945
+ if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
2946
+ }
2947
+ function pipelineEngine_non_iterable_spread() {
2948
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2949
+ }
2950
+ function pipelineEngine_to_consumable_array(arr) {
2951
+ return pipelineEngine_array_without_holes(arr) || pipelineEngine_iterable_to_array(arr) || pipelineEngine_unsupported_iterable_to_array(arr) || pipelineEngine_non_iterable_spread();
2952
+ }
2953
+ function pipelineEngine_unsupported_iterable_to_array(o, minLen) {
2954
+ if (!o) return;
2955
+ if ("string" == typeof o) return pipelineEngine_array_like_to_array(o, minLen);
2956
+ var n = Object.prototype.toString.call(o).slice(8, -1);
2957
+ if ("Object" === n && o.constructor) n = o.constructor.name;
2958
+ if ("Map" === n || "Set" === n) return Array.from(n);
2959
+ if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return pipelineEngine_array_like_to_array(o, minLen);
2960
+ }
2961
+ 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(), _onTaskTimeout = /*#__PURE__*/ new WeakMap(), _active = /*#__PURE__*/ new WeakMap(), core_pipelineEngine_pumpQueue = /*#__PURE__*/ new WeakSet(), pipelineEngine_handleParsedValue = /*#__PURE__*/ new WeakSet(), core_pipelineEngine_scheduleFinalizeCheck = /*#__PURE__*/ new WeakSet(), pipelineEngine_settleTask = /*#__PURE__*/ new WeakSet();
2962
+ var pipelineEngine_PipelineEngine = /*#__PURE__*/ function() {
2963
+ "use strict";
2964
+ function PipelineEngine(processManager, param) {
2965
+ var _this = this;
2966
+ var metrics = param.metrics, statementTimeout = param.statementTimeout, logger = param.logger, _param_batchSize = param.batchSize, batchSize = void 0 === _param_batchSize ? DEFAULT_BATCH_SIZE : _param_batchSize, onTaskTimeout = param.onTaskTimeout;
2967
+ pipelineEngine_class_call_check(this, PipelineEngine);
2968
+ pipelineEngine_class_private_method_init(this, core_pipelineEngine_pumpQueue);
2969
+ pipelineEngine_class_private_method_init(this, pipelineEngine_handleParsedValue);
2970
+ pipelineEngine_class_private_method_init(this, core_pipelineEngine_scheduleFinalizeCheck);
2971
+ pipelineEngine_class_private_method_init(this, pipelineEngine_settleTask);
2972
+ pipelineEngine_class_private_field_init(this, _queue, {
2973
+ writable: true,
2974
+ value: new queue_Queue()
2975
+ });
2976
+ pipelineEngine_class_private_field_init(this, pipelineEngine_inflightTasks, {
2977
+ writable: true,
2978
+ value: []
2979
+ });
2980
+ pipelineEngine_class_private_field_init(this, pipelineEngine_pendingFinalizeTasks, {
2981
+ writable: true,
2982
+ value: new Set()
2983
+ });
2984
+ pipelineEngine_class_private_field_init(this, pipelineEngine_scheduledFinalize, {
2985
+ writable: true,
2986
+ value: false
2987
+ });
2988
+ pipelineEngine_class_private_field_init(this, _sharedValueParser, {
2989
+ writable: true,
2990
+ value: void 0
2991
+ });
2992
+ pipelineEngine_class_private_field_init(this, pipelineEngine_processManager, {
2993
+ writable: true,
2994
+ value: void 0
2995
+ });
2996
+ pipelineEngine_class_private_field_init(this, pipelineEngine_metrics, {
2997
+ writable: true,
2998
+ value: void 0
2999
+ });
3000
+ pipelineEngine_class_private_field_init(this, pipelineEngine_statementTimeout, {
3001
+ writable: true,
3002
+ value: void 0
3003
+ });
3004
+ pipelineEngine_class_private_field_init(this, pipelineEngine_logger, {
3005
+ writable: true,
3006
+ value: void 0
3007
+ });
3008
+ pipelineEngine_class_private_field_init(this, pipelineEngine_batchSize, {
3009
+ writable: true,
3010
+ value: void 0
3011
+ });
3012
+ pipelineEngine_class_private_field_init(this, _onTaskTimeout, {
3013
+ writable: true,
3014
+ value: void 0
3015
+ });
3016
+ pipelineEngine_class_private_field_init(this, _active, {
3017
+ writable: true,
3018
+ value: false
3019
+ });
3020
+ pipelineEngine_class_private_field_set(this, pipelineEngine_processManager, processManager);
3021
+ pipelineEngine_class_private_field_set(this, pipelineEngine_metrics, metrics);
3022
+ pipelineEngine_class_private_field_set(this, pipelineEngine_statementTimeout, statementTimeout);
3023
+ pipelineEngine_class_private_field_set(this, pipelineEngine_logger, logger);
3024
+ pipelineEngine_class_private_field_set(this, pipelineEngine_batchSize, batchSize);
3025
+ pipelineEngine_class_private_field_set(this, _onTaskTimeout, null != onTaskTimeout ? onTaskTimeout : function() {});
3026
+ pipelineEngine_class_private_field_set(this, _sharedValueParser, createJsonValueParser(function(raw) {
3027
+ return pipelineEngine_class_private_method_get(_this, pipelineEngine_handleParsedValue, core_pipelineEngine_handleParsedValue).call(_this, raw);
3028
+ }));
3029
+ }
3030
+ pipelineEngine_create_class(PipelineEngine, [
3031
+ {
3032
+ key: "mainQueue",
3033
+ get: function() {
3034
+ return pipelineEngine_class_private_field_get(this, _queue);
3035
+ }
3036
+ },
3037
+ {
3038
+ key: "pump",
3039
+ value: function() {
3040
+ pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3041
+ }
3042
+ },
3043
+ {
3044
+ key: "pendingStatements",
3045
+ get: function() {
3046
+ 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;
3047
+ }
3048
+ },
3049
+ {
3050
+ key: "feed",
3051
+ value: function(raw) {
3052
+ pipelineEngine_class_private_field_get(this, _sharedValueParser).feed(raw);
3053
+ }
3054
+ },
3055
+ {
3056
+ key: "activate",
3057
+ value: function() {
3058
+ var _$_class_private_field_get;
3059
+ null == (_$_class_private_field_get = pipelineEngine_class_private_field_get(this, _sharedValueParser)) || _$_class_private_field_get.reset();
3060
+ pipelineEngine_class_private_field_set(this, _active, true);
3061
+ }
3062
+ },
3063
+ {
3064
+ key: "deactivate",
3065
+ value: function() {
3066
+ pipelineEngine_class_private_field_set(this, _active, false);
3067
+ }
3068
+ },
3069
+ {
3070
+ key: "enqueue",
3071
+ value: function(task) {
3072
+ pipelineEngine_class_private_field_get(this, _queue).enqueue(task);
3073
+ pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3074
+ }
3075
+ },
3076
+ {
3077
+ key: "handleStdoutChunk",
3078
+ value: function(chunk) {
3079
+ var task = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[0];
3080
+ if (!task) return;
3081
+ if ("stream" === task.kind && task.rowParser && !task.rowParser.finished) {
3082
+ var leftover = task.rowParser.feed(chunk);
3083
+ if (leftover) pipelineEngine_class_private_field_get(this, _sharedValueParser).feed(leftover);
3084
+ return;
3085
+ }
3086
+ pipelineEngine_class_private_field_get(this, _sharedValueParser).feed(chunk);
3087
+ }
3088
+ },
3089
+ {
3090
+ key: "handleStderrChunk",
3091
+ value: function(chunk) {
3092
+ var _class_private_field_get_values_next_value;
3093
+ 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];
3094
+ if (!task) {
3095
+ var _class_private_field_get_error, _$_class_private_field_get;
3096
+ 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());
3097
+ return;
3098
+ }
3099
+ task.stderrText += String(chunk);
3100
+ }
3101
+ },
3102
+ {
3103
+ key: "rejectAll",
3104
+ value: function(error) {
3105
+ var all = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks);
3106
+ pipelineEngine_class_private_field_set(this, pipelineEngine_inflightTasks, []);
3107
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
3108
+ try {
3109
+ for(var _iterator = all[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3110
+ var task = _step.value;
3111
+ pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, error, void 0);
3112
+ }
3113
+ } catch (err) {
3114
+ _didIteratorError = true;
3115
+ _iteratorError = err;
3116
+ } finally{
3117
+ try {
3118
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
3119
+ } finally{
3120
+ if (_didIteratorError) throw _iteratorError;
3121
+ }
3122
+ }
3123
+ var queued = pipelineEngine_class_private_field_get(this, _queue).dequeue();
3124
+ while(queued){
3125
+ pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, queued, error, void 0);
3126
+ queued = pipelineEngine_class_private_field_get(this, _queue).dequeue();
3127
+ }
3128
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
3129
+ try {
3130
+ for(var _iterator1 = pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
3131
+ var task1 = _step1.value;
3132
+ pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task1, error, void 0);
3133
+ }
3134
+ } catch (err) {
3135
+ _didIteratorError1 = true;
3136
+ _iteratorError1 = err;
3137
+ } finally{
3138
+ try {
3139
+ if (!_iteratorNormalCompletion1 && null != _iterator1["return"]) _iterator1["return"]();
3140
+ } finally{
3141
+ if (_didIteratorError1) throw _iteratorError1;
3142
+ }
3143
+ }
3144
+ pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).clear();
3145
+ }
3146
+ },
3147
+ {
3148
+ key: "kill",
3149
+ value: function() {
3150
+ pipelineEngine_class_private_field_set(this, _active, false);
3151
+ this.rejectAll(new Error("PipelineEngine is killed"));
3152
+ }
3153
+ }
3154
+ ]);
3155
+ return PipelineEngine;
3156
+ }();
3157
+ function pipelineEngine_pumpQueue() {
3158
+ var _this = this;
3159
+ var _$_class_private_field_get;
3160
+ if (!pipelineEngine_class_private_field_get(this, _active)) return;
3161
+ var batch = [];
3162
+ while(batch.length < pipelineEngine_class_private_field_get(this, pipelineEngine_batchSize) && !pipelineEngine_class_private_field_get(this, _queue).isEmpty()){
3163
+ var task = pipelineEngine_class_private_field_get(this, _queue).peek();
3164
+ if ("stream" === task.kind && (batch.length > 0 || pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).length > 0)) break;
3165
+ pipelineEngine_class_private_field_get(this, _queue).dequeue();
3166
+ batch.push(task);
3167
+ }
3168
+ if (0 === batch.length) return;
3169
+ var now = performance.now();
3170
+ var payload = buildBatchPayload(batch);
3171
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
3172
+ try {
3173
+ var _loop = function() {
3174
+ var task = _step.value;
3175
+ task.startTime = now;
3176
+ task.timer = setTimeout(function() {
3177
+ if (pipelineEngine_class_private_field_get(_this, pipelineEngine_inflightTasks)[0] !== task) return;
3178
+ pipelineEngine_class_private_field_get(_this, _onTaskTimeout).call(_this, task);
3179
+ }, task.timeout);
3180
+ };
3181
+ for(var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
3182
+ } catch (err) {
3183
+ _didIteratorError = true;
3184
+ _iteratorError = err;
3185
+ } finally{
3186
+ try {
3187
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
3188
+ } finally{
3189
+ if (_didIteratorError) throw _iteratorError;
3190
+ }
3191
+ }
3192
+ (_$_class_private_field_get = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)).push.apply(_$_class_private_field_get, pipelineEngine_to_consumable_array(batch));
3193
+ pipelineEngine_class_private_field_get(this, pipelineEngine_processManager).write(payload);
3194
+ }
3195
+ function core_pipelineEngine_handleParsedValue(raw) {
3196
+ var task = pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks)[0];
3197
+ if (!task) return;
3198
+ var parsed;
3199
+ try {
3200
+ parsed = JSON.parse(raw);
3201
+ } catch (error) {
3202
+ this.rejectAll(new Error("Invalid JSON from sqlite3: ".concat(toError(error).message)));
3203
+ return;
3204
+ }
3205
+ if (isSentinelRow(parsed, task.token)) {
3206
+ clearTimeout(task.timer);
3207
+ pipelineEngine_class_private_field_get(this, pipelineEngine_inflightTasks).shift();
3208
+ if (task.consumerError) {
3209
+ pipelineEngine_class_private_method_get(this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(this, task, task.consumerError, void 0);
3210
+ pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3211
+ return;
3212
+ }
3213
+ pipelineEngine_class_private_field_get(this, pipelineEngine_pendingFinalizeTasks).add(task);
3214
+ pipelineEngine_class_private_method_get(this, core_pipelineEngine_scheduleFinalizeCheck, pipelineEngine_scheduleFinalizeCheck).call(this);
3215
+ pipelineEngine_class_private_method_get(this, core_pipelineEngine_pumpQueue, pipelineEngine_pumpQueue).call(this);
3216
+ return;
3217
+ }
3218
+ if ("query" === task.kind) return void collectQueryRows(task, parsed);
3219
+ if ("stream" === task.kind) processStreamRows(task, parsed);
3220
+ }
3221
+ function pipelineEngine_scheduleFinalizeCheck() {
3222
+ var _this = this;
3223
+ if (pipelineEngine_class_private_field_get(this, pipelineEngine_scheduledFinalize)) return;
3224
+ pipelineEngine_class_private_field_set(this, pipelineEngine_scheduledFinalize, true);
3225
+ setImmediate(function() {
3226
+ pipelineEngine_class_private_field_set(_this, pipelineEngine_scheduledFinalize, false);
3227
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
3228
+ try {
3229
+ for(var _iterator = pipelineEngine_class_private_field_get(_this, pipelineEngine_pendingFinalizeTasks)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3230
+ var task = _step.value;
3231
+ if (task.stderrText) {
3232
+ pipelineEngine_class_private_method_get(_this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(_this, task, new Error(task.stderrText.trim()), void 0);
3233
+ continue;
3234
+ }
3235
+ if (task.consumerError) {
3236
+ pipelineEngine_class_private_method_get(_this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(_this, task, task.consumerError, void 0);
3237
+ continue;
3238
+ }
3239
+ if ("query" === task.kind) {
3240
+ pipelineEngine_class_private_method_get(_this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(_this, task, null, task.rows);
3241
+ continue;
3242
+ }
3243
+ pipelineEngine_class_private_method_get(_this, pipelineEngine_settleTask, pipelineEngine_settleTask1).call(_this, task, null, void 0);
3244
+ }
3245
+ } catch (err) {
3246
+ _didIteratorError = true;
3247
+ _iteratorError = err;
3248
+ } finally{
3249
+ try {
3250
+ if (!_iteratorNormalCompletion && null != _iterator["return"]) _iterator["return"]();
3251
+ } finally{
3252
+ if (_didIteratorError) throw _iteratorError;
3253
+ }
3254
+ }
3255
+ pipelineEngine_class_private_field_get(_this, pipelineEngine_pendingFinalizeTasks).clear();
3256
+ });
3257
+ }
3258
+ function pipelineEngine_settleTask1(task, error, value) {
3259
+ settleTask(task, error, value, pipelineEngine_class_private_field_get(this, pipelineEngine_metrics), {
3260
+ resetRowParser: true
3261
+ });
3262
+ }
3263
+ function executor_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
3264
+ try {
3265
+ var info = gen[key](arg);
3266
+ var value = info.value;
3267
+ } catch (error) {
3268
+ reject(error);
3269
+ return;
3270
+ }
3271
+ if (info.done) resolve(value);
3272
+ else Promise.resolve(value).then(_next, _throw);
3273
+ }
3274
+ function executor_async_to_generator(fn) {
3275
+ return function() {
3276
+ var self = this, args = arguments;
3277
+ return new Promise(function(resolve, reject) {
3278
+ var gen = fn.apply(self, args);
3279
+ function _next(value) {
3280
+ executor_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
3281
+ }
3282
+ function _throw(err) {
3283
+ executor_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
3284
+ }
3285
+ _next(void 0);
3286
+ });
3287
+ };
3288
+ }
3289
+ function executor_check_private_redeclaration(obj, privateCollection) {
3290
+ if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
3291
+ }
3292
+ function executor_class_apply_descriptor_get(receiver, descriptor) {
3293
+ if (descriptor.get) return descriptor.get.call(receiver);
3294
+ return descriptor.value;
3295
+ }
3296
+ function executor_class_apply_descriptor_set(receiver, descriptor, value) {
3297
+ if (descriptor.set) descriptor.set.call(receiver, value);
3298
+ else {
3299
+ if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
3300
+ descriptor.value = value;
3301
+ }
3302
+ }
3303
+ function executor_class_call_check(instance, Constructor) {
3304
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
3305
+ }
3306
+ function executor_class_extract_field_descriptor(receiver, privateMap, action) {
3307
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
3308
+ return privateMap.get(receiver);
3309
+ }
3310
+ function executor_class_private_field_get(receiver, privateMap) {
3311
+ var descriptor = executor_class_extract_field_descriptor(receiver, privateMap, "get");
3312
+ return executor_class_apply_descriptor_get(receiver, descriptor);
3313
+ }
3314
+ function executor_class_private_field_init(obj, privateMap, value) {
3315
+ executor_check_private_redeclaration(obj, privateMap);
3316
+ privateMap.set(obj, value);
3317
+ }
3318
+ function executor_class_private_field_set(receiver, privateMap, value) {
3319
+ var descriptor = executor_class_extract_field_descriptor(receiver, privateMap, "set");
3320
+ executor_class_apply_descriptor_set(receiver, descriptor, value);
3321
+ return value;
3322
+ }
3323
+ function executor_class_private_method_get(receiver, privateSet, fn) {
3324
+ if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
3325
+ return fn;
3326
+ }
3327
+ function executor_class_private_method_init(obj, privateSet) {
3328
+ executor_check_private_redeclaration(obj, privateSet);
3329
+ privateSet.add(obj);
3330
+ }
3331
+ function executor_defineProperties(target, props) {
3332
+ for(var i = 0; i < props.length; i++){
3333
+ var descriptor = props[i];
3334
+ descriptor.enumerable = descriptor.enumerable || false;
3335
+ descriptor.configurable = true;
3336
+ if ("value" in descriptor) descriptor.writable = true;
3337
+ Object.defineProperty(target, descriptor.key, descriptor);
3338
+ }
3339
+ }
3340
+ function executor_create_class(Constructor, protoProps, staticProps) {
3341
+ if (protoProps) executor_defineProperties(Constructor.prototype, protoProps);
3342
+ if (staticProps) executor_defineProperties(Constructor, staticProps);
3343
+ return Constructor;
3344
+ }
3345
+ function executor_define_property(obj, key, value) {
3346
+ if (key in obj) Object.defineProperty(obj, key, {
3347
+ value: value,
3348
+ enumerable: true,
3349
+ configurable: true,
3350
+ writable: true
3351
+ });
3352
+ else obj[key] = value;
3353
+ return obj;
3354
+ }
3355
+ function executor_object_spread(target) {
3356
+ for(var i = 1; i < arguments.length; i++){
3357
+ var source = null != arguments[i] ? arguments[i] : {};
3358
+ var ownKeys = Object.keys(source);
3359
+ if ("function" == typeof Object.getOwnPropertySymbols) ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
3360
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
3361
+ }));
3362
+ ownKeys.forEach(function(key) {
3363
+ executor_define_property(target, key, source[key]);
3364
+ });
3365
+ }
3366
+ return target;
3367
+ }
3368
+ function executor_ownKeys(object, enumerableOnly) {
3369
+ var keys = Object.keys(object);
3370
+ if (Object.getOwnPropertySymbols) {
3371
+ var symbols = Object.getOwnPropertySymbols(object);
3372
+ if (enumerableOnly) symbols = symbols.filter(function(sym) {
3373
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
3374
+ });
3375
+ keys.push.apply(keys, symbols);
3376
+ }
3377
+ return keys;
3378
+ }
3379
+ function executor_object_spread_props(target, source) {
3380
+ source = null != source ? source : {};
3381
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
3382
+ else executor_ownKeys(Object(source)).forEach(function(key) {
3383
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
3384
+ });
3385
+ return target;
3386
+ }
3387
+ function executor_ts_generator(thisArg, body) {
3388
+ var f, y, t, _ = {
3389
+ label: 0,
3390
+ sent: function() {
3391
+ if (1 & t[0]) throw t[1];
3392
+ return t[1];
3393
+ },
3394
+ trys: [],
3395
+ ops: []
3396
+ }, g = Object.create(("function" == typeof Iterator ? Iterator : Object).prototype);
3397
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), "function" == typeof Symbol && (g[Symbol.iterator] = function() {
3398
+ return this;
3399
+ }), g;
3400
+ function verb(n) {
3401
+ return function(v1) {
3402
+ return step([
3403
+ n,
3404
+ v1
3405
+ ]);
3406
+ };
3407
+ }
3408
+ function step(op) {
3409
+ if (f) throw new TypeError("Generator is already executing.");
3410
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
3411
+ if (f = 1, y && (t = 2 & op[0] ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
3412
+ if (y = 0, t) op = [
3413
+ 2 & op[0],
3414
+ t.value
3415
+ ];
3416
+ switch(op[0]){
3417
+ case 0:
3418
+ case 1:
3419
+ t = op;
3420
+ break;
3421
+ case 4:
3422
+ _.label++;
3423
+ return {
3424
+ value: op[1],
3425
+ done: false
3426
+ };
3427
+ case 5:
3428
+ _.label++;
3429
+ y = op[1];
3430
+ op = [
3431
+ 0
3432
+ ];
3433
+ continue;
3434
+ case 7:
3435
+ op = _.ops.pop();
3436
+ _.trys.pop();
3437
+ continue;
3438
+ default:
3439
+ if (t = _.trys, !(t = t.length > 0 && t[t.length - 1]) && (6 === op[0] || 2 === op[0])) {
3440
+ _ = 0;
3441
+ continue;
3442
+ }
3443
+ if (3 === op[0] && (!t || op[1] > t[0] && op[1] < t[3])) {
3444
+ _.label = op[1];
3445
+ break;
3446
+ }
3447
+ if (6 === op[0] && _.label < t[1]) {
3448
+ _.label = t[1];
3449
+ t = op;
3450
+ break;
3451
+ }
3452
+ if (t && _.label < t[2]) {
3453
+ _.label = t[2];
3454
+ _.ops.push(op);
3455
+ break;
3456
+ }
3457
+ if (t[2]) _.ops.pop();
3458
+ _.trys.pop();
3459
+ continue;
3460
+ }
3461
+ op = body.call(thisArg, _);
3462
+ } catch (e) {
3463
+ op = [
3464
+ 6,
3465
+ e
3466
+ ];
3467
+ y = 0;
3468
+ } finally{
3469
+ f = t = 0;
3470
+ }
3471
+ if (5 & op[0]) throw op[1];
3472
+ return {
3473
+ value: op[0] ? op[1] : void 0,
3474
+ done: true
3475
+ };
3476
+ }
3477
+ }
3478
+ var executor_computedKey;
3479
+ executor_computedKey = Symbol.asyncDispose;
3480
+ var _closed = /*#__PURE__*/ new WeakMap(), executor_proc = /*#__PURE__*/ new WeakMap(), executor_logger = /*#__PURE__*/ new WeakMap(), executor_statementTimeout = /*#__PURE__*/ new WeakMap(), _autoRestart = /*#__PURE__*/ new WeakMap(), _fatalError = /*#__PURE__*/ new WeakMap(), executor_processManager = /*#__PURE__*/ new WeakMap(), _readerPool = /*#__PURE__*/ new WeakMap(), _poolSize = /*#__PURE__*/ new WeakMap(), executor_binary = /*#__PURE__*/ new WeakMap(), executor_database = /*#__PURE__*/ new WeakMap(), executor_metrics = /*#__PURE__*/ new WeakMap(), _pipeline = /*#__PURE__*/ new WeakMap(), _txScope = /*#__PURE__*/ new WeakMap(), _normalizeTimeout = /*#__PURE__*/ new WeakSet(), executor_startProcess = /*#__PURE__*/ new WeakSet(), _enqueue = /*#__PURE__*/ new WeakSet(), _enqueueWriter = /*#__PURE__*/ new WeakSet(), _enqueueReader = /*#__PURE__*/ new WeakSet(), _handleProcessFailure = /*#__PURE__*/ new WeakSet();
3481
+ var _computedKey2 = executor_computedKey;
3482
+ var executor_SQLiteExecutor = /*#__PURE__*/ function() {
3483
+ "use strict";
3484
+ function SQLiteExecutor() {
3485
+ var _this = this;
3486
+ var _ref = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, _ref_binary = _ref.binary, binary = void 0 === _ref_binary ? "sqlite3" : _ref_binary, _ref_database = _ref.database, database = void 0 === _ref_database ? ":memory:" : _ref_database, logger = _ref.logger, _ref_statementTimeout = _ref.statementTimeout, statementTimeout = void 0 === _ref_statementTimeout ? DEFAULT_STATEMENT_TIMEOUT : _ref_statementTimeout, _ref_autoRestart = _ref.autoRestart, autoRestart = void 0 === _ref_autoRestart ? true : _ref_autoRestart, _ref_poolSize = _ref.poolSize, poolSize = void 0 === _ref_poolSize ? 0 : _ref_poolSize, metrics = _ref.metrics;
3487
+ executor_class_call_check(this, SQLiteExecutor);
3488
+ executor_class_private_method_init(this, _normalizeTimeout);
3489
+ executor_class_private_method_init(this, executor_startProcess);
3490
+ executor_class_private_method_init(this, _enqueue);
3491
+ executor_class_private_method_init(this, _enqueueWriter);
3492
+ executor_class_private_method_init(this, _enqueueReader);
3493
+ executor_class_private_method_init(this, _handleProcessFailure);
3494
+ executor_class_private_field_init(this, _closed, {
3495
+ writable: true,
3496
+ value: false
3497
+ });
3498
+ executor_class_private_field_init(this, executor_proc, {
3499
+ writable: true,
3500
+ value: null
3501
+ });
3502
+ executor_class_private_field_init(this, executor_logger, {
3503
+ writable: true,
3504
+ value: void 0
3505
+ });
3506
+ executor_class_private_field_init(this, executor_statementTimeout, {
3507
+ writable: true,
3508
+ value: void 0
3509
+ });
3510
+ executor_class_private_field_init(this, _autoRestart, {
3511
+ writable: true,
3512
+ value: void 0
3513
+ });
3514
+ executor_class_private_field_init(this, _fatalError, {
3515
+ writable: true,
3516
+ value: null
3517
+ });
3518
+ executor_class_private_field_init(this, executor_processManager, {
3519
+ writable: true,
3520
+ value: void 0
3521
+ });
3522
+ executor_class_private_field_init(this, _readerPool, {
3523
+ writable: true,
3524
+ value: null
3525
+ });
3526
+ executor_class_private_field_init(this, _poolSize, {
3527
+ writable: true,
3528
+ value: void 0
3529
+ });
3530
+ executor_class_private_field_init(this, executor_binary, {
3531
+ writable: true,
3532
+ value: void 0
3533
+ });
3534
+ executor_class_private_field_init(this, executor_database, {
3535
+ writable: true,
3536
+ value: void 0
3537
+ });
3538
+ executor_class_private_field_init(this, executor_metrics, {
3539
+ writable: true,
3540
+ value: void 0
3541
+ });
3542
+ executor_class_private_field_init(this, _pipeline, {
3543
+ writable: true,
3544
+ value: void 0
3545
+ });
3546
+ executor_class_private_field_init(this, _txScope, {
3547
+ writable: true,
3548
+ value: new transactionScope_TransactionScope()
3549
+ });
3550
+ executor_class_private_field_set(this, executor_logger, logger);
3551
+ executor_class_private_field_set(this, executor_statementTimeout, executor_class_private_method_get(this, _normalizeTimeout, normalizeTimeout).call(this, statementTimeout));
3552
+ executor_class_private_field_set(this, _autoRestart, false !== autoRestart);
3553
+ executor_class_private_field_set(this, executor_binary, binary);
3554
+ executor_class_private_field_set(this, executor_database, database);
3555
+ executor_class_private_field_set(this, _poolSize, poolSize);
3556
+ executor_class_private_field_set(this, executor_metrics, null != metrics ? metrics : new metrics_Metrics());
3557
+ executor_class_private_field_set(this, executor_processManager, new process_ProcessManager({
3558
+ binary: binary,
3559
+ database: database
3560
+ }));
3561
+ executor_class_private_field_set(this, _pipeline, new pipelineEngine_PipelineEngine(executor_class_private_field_get(this, executor_processManager), {
3562
+ metrics: executor_class_private_field_get(this, executor_metrics),
3563
+ statementTimeout: executor_class_private_field_get(this, executor_statementTimeout),
3564
+ logger: executor_class_private_field_get(this, executor_logger),
3565
+ onTaskTimeout: function(task) {
3566
+ executor_class_private_field_get(_this, executor_metrics).incrementTasksTimeout();
3567
+ executor_class_private_method_get(_this, _handleProcessFailure, handleProcessFailure).call(_this, createTimeoutError(task.timeout, task.sql));
3568
+ }
3569
+ }));
3570
+ executor_class_private_method_get(this, executor_startProcess, core_executor_startProcess).call(this);
3571
+ if (poolSize > 0 && ":memory:" !== database) executor_class_private_field_set(this, _readerPool, new readerPool_ReaderPool({
3572
+ binary: binary,
3573
+ database: database,
3574
+ poolSize: poolSize,
3575
+ statementTimeout: statementTimeout,
3576
+ logger: logger,
3577
+ metrics: executor_class_private_field_get(this, executor_metrics)
3578
+ }));
3579
+ }
3580
+ executor_create_class(SQLiteExecutor, [
3581
+ {
3582
+ key: "pendingStatements",
3583
+ get: function() {
3584
+ var _$_class_private_field_get;
3585
+ var _class_private_field_get_pendingStatements;
3586
+ return executor_class_private_field_get(this, _txScope).pendingStatements + executor_class_private_field_get(this, _pipeline).pendingStatements + (null != (_class_private_field_get_pendingStatements = null == (_$_class_private_field_get = executor_class_private_field_get(this, _readerPool)) ? void 0 : _$_class_private_field_get.pendingStatements) ? _class_private_field_get_pendingStatements : 0);
3587
+ }
3588
+ },
3589
+ {
3590
+ key: "readerPool",
3591
+ get: function() {
3592
+ return executor_class_private_field_get(this, _readerPool);
3593
+ }
3594
+ },
3595
+ {
3596
+ key: "metrics",
3597
+ get: function() {
3598
+ return executor_class_private_field_get(this, executor_metrics);
3599
+ }
3600
+ },
3601
+ {
3602
+ key: "execute",
3603
+ value: function(sql) {
3604
+ var params = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : [], options = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
3605
+ var _this = this;
3606
+ return executor_async_to_generator(function() {
3607
+ return executor_ts_generator(this, function(_state) {
3608
+ switch(_state.label){
3609
+ case 0:
3610
+ return [
3611
+ 4,
3612
+ executor_class_private_method_get(_this, _enqueue, executor_enqueue).call(_this, "execute", sql, params, options, null)
3613
+ ];
3614
+ case 1:
3615
+ _state.sent();
3616
+ return [
3617
+ 2
3618
+ ];
3619
+ }
3620
+ });
3621
+ })();
3622
+ }
3623
+ },
3624
+ {
3625
+ key: "query",
3626
+ value: function(sql) {
3627
+ var params = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : [], options = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
3628
+ return executor_class_private_method_get(this, _enqueue, executor_enqueue).call(this, "query", sql, params, options, null);
3629
+ }
3630
+ },
3631
+ {
3632
+ key: "stream",
3633
+ value: function(sql) {
3634
+ var params = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : [], options = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
3635
+ if (!Array.isArray(params)) throw new TypeError("params must be an array");
3636
+ var buffer = new stream_AsyncRowBuffer();
3637
+ executor_class_private_method_get(this, _enqueue, executor_enqueue).call(this, "stream", sql, params, executor_object_spread_props(executor_object_spread({}, options), {
3638
+ onRow: function(row) {
3639
+ return buffer.push(row);
3640
+ }
3641
+ }), null).then(function() {
3642
+ return buffer.end();
3643
+ }, function(err) {
3644
+ return buffer.error(err);
3645
+ });
3646
+ return buffer;
3647
+ }
3648
+ },
3649
+ {
3650
+ key: "transaction",
3651
+ value: function(fn) {
3652
+ var options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
3653
+ var _this = this;
3654
+ return executor_async_to_generator(function() {
3655
+ var _options_mode, mode, _ref, scopeId, release, tx, result, error;
3656
+ return executor_ts_generator(this, function(_state) {
3657
+ switch(_state.label){
3658
+ case 0:
3659
+ mode = null != (_options_mode = null == options ? void 0 : options.mode) ? _options_mode : "DEFERRED";
3660
+ if (!VALID_TRANSACTION_MODES.includes(mode)) throw new TypeError("transaction mode must be one of: ".concat(VALID_TRANSACTION_MODES.join(", ")));
3661
+ return [
3662
+ 4,
3663
+ executor_class_private_field_get(_this, _txScope).enter()
3664
+ ];
3665
+ case 1:
3666
+ _ref = _state.sent(), scopeId = _ref.scopeId, release = _ref.release;
3667
+ tx = createTransactionHandle(scopeId, {
3668
+ enqueue: function(kind, sql, params, options, sid) {
3669
+ return executor_class_private_method_get(_this, _enqueue, executor_enqueue).call(_this, kind, sql, params, options, sid);
3670
+ }
3671
+ });
3672
+ _state.label = 2;
3673
+ case 2:
3674
+ _state.trys.push([
3675
+ 2,
3676
+ ,
3677
+ 10,
3678
+ 11
3679
+ ]);
3680
+ return [
3681
+ 4,
3682
+ tx.execute("BEGIN ".concat(mode))
3683
+ ];
3684
+ case 3:
3685
+ _state.sent();
3686
+ _state.label = 4;
3687
+ case 4:
3688
+ _state.trys.push([
3689
+ 4,
3690
+ 7,
3691
+ ,
3692
+ 9
3693
+ ]);
3694
+ return [
3695
+ 4,
3696
+ fn(tx)
3697
+ ];
3698
+ case 5:
3699
+ result = _state.sent();
3700
+ return [
3701
+ 4,
3702
+ tx.execute("COMMIT")
3703
+ ];
3704
+ case 6:
3705
+ _state.sent();
3706
+ return [
3707
+ 2,
3708
+ result
3709
+ ];
3710
+ case 7:
3711
+ error = _state.sent();
3712
+ return [
3713
+ 4,
3714
+ tx.execute("ROLLBACK")["catch"](function() {})
3715
+ ];
3716
+ case 8:
3717
+ _state.sent();
3718
+ throw error;
3719
+ case 9:
3720
+ return [
3721
+ 3,
3722
+ 11
3723
+ ];
3724
+ case 10:
3725
+ executor_class_private_field_get(_this, _txScope).exit();
3726
+ executor_class_private_field_get(_this, _txScope).restoreDeferred(executor_class_private_field_get(_this, _pipeline).mainQueue);
3727
+ executor_class_private_field_get(_this, _pipeline).pump();
3728
+ release();
3729
+ return [
3730
+ 7
3731
+ ];
3732
+ case 11:
3733
+ return [
3734
+ 2
3735
+ ];
3736
+ }
3737
+ });
3738
+ })();
3739
+ }
3740
+ },
3741
+ {
3742
+ key: "close",
3743
+ value: function() {
3744
+ var _this = this;
3745
+ return executor_async_to_generator(function() {
3746
+ var _$_class_private_field_get;
3747
+ return executor_ts_generator(this, function(_state) {
3748
+ switch(_state.label){
3749
+ case 0:
3750
+ if (executor_class_private_field_get(_this, _closed)) return [
3751
+ 2
3752
+ ];
3753
+ executor_class_private_field_set(_this, _closed, true);
3754
+ executor_class_private_field_get(_this, _pipeline).kill();
3755
+ executor_class_private_field_get(_this, _txScope).rejectAll(new Error("SQLiteExecutor is closed"));
3756
+ null == (_$_class_private_field_get = executor_class_private_field_get(_this, _readerPool)) || _$_class_private_field_get.kill();
3757
+ return [
3758
+ 4,
3759
+ executor_class_private_field_get(_this, executor_processManager).gracefulShutdown()
3760
+ ];
3761
+ case 1:
3762
+ _state.sent();
3763
+ executor_class_private_field_get(_this, executor_processManager).kill();
3764
+ _state.label = 2;
3765
+ case 2:
3766
+ _state.trys.push([
3767
+ 2,
3768
+ 4,
3769
+ ,
3770
+ 5
3771
+ ]);
3772
+ return [
3773
+ 4,
3774
+ (0, external_node_events_namespaceObject.once)(executor_class_private_field_get(_this, executor_processManager).process, "close")
3775
+ ];
3776
+ case 3:
3777
+ _state.sent();
3778
+ return [
3779
+ 3,
3780
+ 5
3781
+ ];
3782
+ case 4:
3783
+ _state.sent();
3784
+ return [
3785
+ 3,
3786
+ 5
3787
+ ];
3788
+ case 5:
3789
+ return [
3790
+ 2
3791
+ ];
3792
+ }
3793
+ });
3794
+ })();
3795
+ }
3796
+ },
3797
+ {
3798
+ key: _computedKey2,
3799
+ value: function() {
3800
+ this.close();
3801
+ }
3802
+ }
3803
+ ]);
3804
+ return SQLiteExecutor;
3805
+ }();
3806
+ function normalizeTimeout(value) {
3807
+ if (!Number.isInteger(value) || value <= 0) throw new TypeError("statementTimeout must be a positive integer");
3808
+ return value;
3809
+ }
3810
+ function core_executor_startProcess() {
3811
+ var _this = this;
3812
+ var _proc_stderr;
3813
+ var proc;
3814
+ try {
3815
+ proc = executor_class_private_field_get(this, executor_processManager).start();
3816
+ } catch (error) {
3817
+ var _class_private_field_get_error, _$_class_private_field_get;
3818
+ executor_class_private_field_set(this, _fatalError, toError(error));
3819
+ null == (_$_class_private_field_get = executor_class_private_field_get(this, executor_logger)) || null == (_class_private_field_get_error = _$_class_private_field_get.error) || _class_private_field_get_error.call(_$_class_private_field_get, "failed to start sqlite3 process", executor_class_private_field_get(this, _fatalError));
3820
+ return;
3821
+ }
3822
+ if (!proc.stdout) {
3823
+ executor_class_private_field_set(this, _fatalError, new Error("Failed to spawn sqlite3 process: stdio unavailable (binary=".concat(executor_class_private_field_get(this, executor_binary), ")")));
3824
+ executor_class_private_field_get(this, executor_processManager).kill();
3825
+ return;
3826
+ }
3827
+ proc.stdout.on("data", function(chunk) {
3828
+ executor_class_private_field_get(_this, _pipeline).handleStdoutChunk(chunk);
3829
+ });
3830
+ null == (_proc_stderr = proc.stderr) || _proc_stderr.on("data", function(chunk) {
3831
+ executor_class_private_field_get(_this, _pipeline).handleStderrChunk(chunk);
3832
+ });
3833
+ proc.on("error", function(error) {
3834
+ var _class_private_field_get_error, _$_class_private_field_get;
3835
+ if (executor_class_private_field_get(_this, executor_proc) !== proc) return;
3836
+ null == (_$_class_private_field_get = executor_class_private_field_get(_this, executor_logger)) || null == (_class_private_field_get_error = _$_class_private_field_get.error) || _class_private_field_get_error.call(_$_class_private_field_get, "sqlite3 process error", error);
3837
+ executor_class_private_method_get(_this, _handleProcessFailure, handleProcessFailure).call(_this, error);
3838
+ });
3839
+ proc.on("close", function(code, signal) {
3840
+ if (executor_class_private_field_get(_this, executor_proc) !== proc) return;
3841
+ if (executor_class_private_field_get(_this, _closed)) return;
3842
+ executor_class_private_method_get(_this, _handleProcessFailure, handleProcessFailure).call(_this, new Error("sqlite3 process exited unexpectedly (code=".concat(code, ", signal=").concat(null != signal ? signal : "none", ")")));
3843
+ });
3844
+ executor_class_private_field_set(this, executor_proc, proc);
3845
+ executor_class_private_field_get(this, _pipeline).activate();
3846
+ }
3847
+ function executor_enqueue(kind, sql, params, options, scopeId) {
3848
+ if (executor_class_private_field_get(this, _closed)) return Promise.reject(new Error("SQLiteExecutor is closed"));
3849
+ if (executor_class_private_field_get(this, _fatalError)) return Promise.reject(executor_class_private_field_get(this, _fatalError));
3850
+ if (!Array.isArray(params)) return Promise.reject(new TypeError("params must be an array"));
3851
+ var _options_timeout;
3852
+ var timeout = null != (_options_timeout = null == options ? void 0 : options.timeout) ? _options_timeout : executor_class_private_field_get(this, executor_statementTimeout);
3853
+ var token = generateToken();
3854
+ var _options_onRow;
3855
+ var onRow = null != (_options_onRow = null == options ? void 0 : options.onRow) ? _options_onRow : null;
3856
+ var normalized = normalizeSQL(sql);
3857
+ var formatted;
3858
+ var sqlNormalized = true;
3859
+ formatted = 0 !== params.length || normalized.includes("?") ? interpolateSQL(normalized, params) : normalized;
3860
+ if (scopeId) return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, scopeId, sqlNormalized);
3861
+ if (executor_class_private_field_get(this, _readerPool)) {
3862
+ if ("stream" === kind || "query" === kind) return executor_class_private_method_get(this, _enqueueReader, enqueueReader).call(this, kind, formatted, timeout, token, onRow);
3863
+ if ("execute" === kind && "read" === classifySQL(normalized)) return executor_class_private_method_get(this, _enqueueReader, enqueueReader).call(this, kind, formatted, timeout, token, onRow);
3864
+ }
3865
+ return executor_class_private_method_get(this, _enqueueWriter, enqueueWriter).call(this, kind, formatted, timeout, token, onRow, null, sqlNormalized);
3866
+ }
3867
+ function enqueueWriter(kind, sql, timeout, token, onRow, scopeId) {
3868
+ var _this = this;
3869
+ var sqlNormalized = arguments.length > 6 && void 0 !== arguments[6] ? arguments[6] : false;
3870
+ executor_class_private_field_get(this, executor_metrics).incrementTasksTotal(kind);
3871
+ return new Promise(function(resolve, reject) {
3872
+ var task = {
3873
+ kind: kind,
3874
+ sql: sql,
3875
+ timeout: timeout,
3876
+ token: token,
3877
+ onRow: onRow,
3878
+ scopeId: scopeId,
3879
+ sqlNormalized: sqlNormalized,
3880
+ resolve: resolve,
3881
+ reject: reject,
3882
+ consumerError: null,
3883
+ stderrText: "",
3884
+ timer: null,
3885
+ startTime: 0,
3886
+ rowParser: null
3887
+ };
3888
+ if ("query" === kind) task.rows = [];
3889
+ if ("stream" === kind) task.rowParser = setupStreamParser(task, executor_class_private_field_get(_this, _pipeline));
3890
+ if (executor_class_private_field_get(_this, _txScope).isDeferred(scopeId)) executor_class_private_field_get(_this, _txScope).defer(task);
3891
+ else executor_class_private_field_get(_this, _pipeline).enqueue(task);
3892
+ });
3893
+ }
3894
+ function enqueueReader(kind, sql, timeout, token, onRow) {
3895
+ var _this = this;
3896
+ return new Promise(function(resolve, reject) {
3897
+ executor_class_private_field_get(_this, _readerPool).enqueue({
3898
+ kind: kind,
3899
+ sql: sql,
3900
+ timeout: timeout,
3901
+ token: token,
3902
+ onRow: onRow,
3903
+ resolve: resolve,
3904
+ reject: reject
3905
+ });
3906
+ });
3907
+ }
3908
+ function handleProcessFailure(error) {
3909
+ var failure = toError(error);
3910
+ executor_class_private_field_get(this, executor_processManager).kill();
3911
+ executor_class_private_field_set(this, executor_proc, null);
3912
+ executor_class_private_field_get(this, _pipeline).deactivate();
3913
+ executor_class_private_field_get(this, _pipeline).rejectAll(failure);
3914
+ executor_class_private_field_get(this, _txScope).rejectAll(failure);
3915
+ if (!executor_class_private_field_get(this, _closed) && executor_class_private_field_get(this, _autoRestart)) {
3916
+ executor_class_private_field_get(this, executor_metrics).incrementProcessRestarts();
3917
+ executor_class_private_method_get(this, executor_startProcess, core_executor_startProcess).call(this);
3918
+ return;
3919
+ }
3920
+ executor_class_private_field_set(this, _fatalError, failure);
3921
+ executor_class_private_field_set(this, _closed, true);
3922
+ }
3923
+ exports.DEFAULT_STATEMENT_TIMEOUT = __webpack_exports__.DEFAULT_STATEMENT_TIMEOUT;
3924
+ exports.Metrics = __webpack_exports__.Metrics;
3925
+ exports.SQLiteExecutor = __webpack_exports__.SQLiteExecutor;
3926
+ exports.VALID_TRANSACTION_MODES = __webpack_exports__.VALID_TRANSACTION_MODES;
3927
+ exports.createTimeoutError = __webpack_exports__.createTimeoutError;
3928
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
3929
+ "DEFAULT_STATEMENT_TIMEOUT",
3930
+ "Metrics",
3931
+ "SQLiteExecutor",
3932
+ "VALID_TRANSACTION_MODES",
3933
+ "createTimeoutError"
3934
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
3935
+ Object.defineProperty(exports, '__esModule', {
3936
+ value: true
3937
+ });
3938
+
3939
+ //# sourceMappingURL=index.cjs.map